You've already forked linux-rockchip
mirror of
https://github.com/armbian/linux-rockchip.git
synced 2026-01-06 11:08:10 -08:00
clk: stm32: Introduce STM32MP13 RCC drivers (Reset Clock Controller)
This driver manages Reset and Clock of STM32MP13 soc. It uses a clk-stm32-core module to manage stm32 gate, mux and divider for STM32MP13 and for new future soc. All gates, muxes, dividers are identify by an index and information are stored in array (register address, shift, with, flags...) This is useful when we have two clocks with the same gate or when one mux manages two output clocks. Signed-off-by: Gabriel Fernandez <gabriel.fernandez@foss.st.com> Link: https://lore.kernel.org/r/20220516070600.7692-3-gabriel.fernandez@foss.st.com Signed-off-by: Stephen Boyd <sboyd@kernel.org>
This commit is contained in:
committed by
Stephen Boyd
parent
722dc8a1d5
commit
637cee5ffc
@@ -368,6 +368,11 @@ config COMMON_CLK_VC5
|
||||
This driver supports the IDT VersaClock 5 and VersaClock 6
|
||||
programmable clock generators.
|
||||
|
||||
config COMMON_CLK_STM32MP135
|
||||
def_bool COMMON_CLK && MACH_STM32MP13
|
||||
help
|
||||
Support for stm32mp135 SoC family clocks
|
||||
|
||||
config COMMON_CLK_STM32MP157
|
||||
def_bool COMMON_CLK && MACH_STM32MP157
|
||||
help
|
||||
|
||||
@@ -115,6 +115,7 @@ obj-y += socfpga/
|
||||
obj-$(CONFIG_PLAT_SPEAR) += spear/
|
||||
obj-y += sprd/
|
||||
obj-$(CONFIG_ARCH_STI) += st/
|
||||
obj-$(CONFIG_ARCH_STM32) += stm32/
|
||||
obj-$(CONFIG_SOC_STARFIVE) += starfive/
|
||||
obj-$(CONFIG_ARCH_SUNXI) += sunxi/
|
||||
obj-y += sunxi-ng/
|
||||
|
||||
1
drivers/clk/stm32/Makefile
Normal file
1
drivers/clk/stm32/Makefile
Normal file
@@ -0,0 +1 @@
|
||||
obj-$(CONFIG_COMMON_CLK_STM32MP135) += clk-stm32mp13.o clk-stm32-core.o reset-stm32.o
|
||||
93
drivers/clk/stm32/clk-stm32-core.c
Normal file
93
drivers/clk/stm32/clk-stm32-core.c
Normal file
@@ -0,0 +1,93 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
/*
|
||||
* Copyright (C) STMicroelectronics 2022 - All Rights Reserved
|
||||
* Author: Gabriel Fernandez <gabriel.fernandez@foss.st.com> for STMicroelectronics.
|
||||
*/
|
||||
|
||||
#include <linux/clk.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/device.h>
|
||||
#include <linux/err.h>
|
||||
#include <linux/io.h>
|
||||
#include <linux/of.h>
|
||||
#include <linux/of_address.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/spinlock.h>
|
||||
|
||||
#include "clk-stm32-core.h"
|
||||
#include "reset-stm32.h"
|
||||
|
||||
static DEFINE_SPINLOCK(rlock);
|
||||
|
||||
static int stm32_rcc_clock_init(struct device *dev,
|
||||
const struct of_device_id *match,
|
||||
void __iomem *base)
|
||||
{
|
||||
const struct stm32_rcc_match_data *data = match->data;
|
||||
struct clk_hw_onecell_data *clk_data = data->hw_clks;
|
||||
struct device_node *np = dev_of_node(dev);
|
||||
struct clk_hw **hws;
|
||||
int n, max_binding;
|
||||
|
||||
max_binding = data->maxbinding;
|
||||
|
||||
clk_data = devm_kzalloc(dev, struct_size(clk_data, hws, max_binding), GFP_KERNEL);
|
||||
if (!clk_data)
|
||||
return -ENOMEM;
|
||||
|
||||
clk_data->num = max_binding;
|
||||
|
||||
hws = clk_data->hws;
|
||||
|
||||
for (n = 0; n < max_binding; n++)
|
||||
hws[n] = ERR_PTR(-ENOENT);
|
||||
|
||||
for (n = 0; n < data->num_clocks; n++) {
|
||||
const struct clock_config *cfg_clock = &data->tab_clocks[n];
|
||||
struct clk_hw *hw = ERR_PTR(-ENOENT);
|
||||
|
||||
if (cfg_clock->func)
|
||||
hw = (*cfg_clock->func)(dev, data, base, &rlock,
|
||||
cfg_clock);
|
||||
|
||||
if (IS_ERR(hw)) {
|
||||
dev_err(dev, "Can't register clk %d: %ld\n", n,
|
||||
PTR_ERR(hw));
|
||||
return PTR_ERR(hw);
|
||||
}
|
||||
|
||||
if (cfg_clock->id != NO_ID)
|
||||
hws[cfg_clock->id] = hw;
|
||||
}
|
||||
|
||||
return of_clk_add_hw_provider(np, of_clk_hw_onecell_get, clk_data);
|
||||
}
|
||||
|
||||
int stm32_rcc_init(struct device *dev, const struct of_device_id *match_data,
|
||||
void __iomem *base)
|
||||
{
|
||||
const struct of_device_id *match;
|
||||
int err;
|
||||
|
||||
match = of_match_node(match_data, dev_of_node(dev));
|
||||
if (!match) {
|
||||
dev_err(dev, "match data not found\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
/* RCC Reset Configuration */
|
||||
err = stm32_rcc_reset_init(dev, match, base);
|
||||
if (err) {
|
||||
pr_err("stm32 reset failed to initialize\n");
|
||||
return err;
|
||||
}
|
||||
|
||||
/* RCC Clock Configuration */
|
||||
err = stm32_rcc_clock_init(dev, match, base);
|
||||
if (err) {
|
||||
pr_err("stm32 clock failed to initialize\n");
|
||||
return err;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
92
drivers/clk/stm32/clk-stm32-core.h
Normal file
92
drivers/clk/stm32/clk-stm32-core.h
Normal file
@@ -0,0 +1,92 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
/*
|
||||
* Copyright (C) STMicroelectronics 2022 - All Rights Reserved
|
||||
* Author: Gabriel Fernandez <gabriel.fernandez@foss.st.com> for STMicroelectronics.
|
||||
*/
|
||||
|
||||
#include <linux/clk-provider.h>
|
||||
|
||||
struct stm32_rcc_match_data;
|
||||
|
||||
struct stm32_mux_cfg {
|
||||
u16 offset;
|
||||
u8 shift;
|
||||
u8 width;
|
||||
u8 flags;
|
||||
u32 *table;
|
||||
u8 ready;
|
||||
};
|
||||
|
||||
struct stm32_gate_cfg {
|
||||
u16 offset;
|
||||
u8 bit_idx;
|
||||
u8 set_clr;
|
||||
};
|
||||
|
||||
struct stm32_div_cfg {
|
||||
u16 offset;
|
||||
u8 shift;
|
||||
u8 width;
|
||||
u8 flags;
|
||||
u8 ready;
|
||||
const struct clk_div_table *table;
|
||||
};
|
||||
|
||||
struct stm32_composite_cfg {
|
||||
int mux;
|
||||
int gate;
|
||||
int div;
|
||||
};
|
||||
|
||||
#define NO_ID 0xFFFFFFFF
|
||||
|
||||
#define NO_STM32_MUX 0xFFFF
|
||||
#define NO_STM32_DIV 0xFFFF
|
||||
#define NO_STM32_GATE 0xFFFF
|
||||
|
||||
struct clock_config {
|
||||
unsigned long id;
|
||||
void *clock_cfg;
|
||||
|
||||
struct clk_hw *(*func)(struct device *dev,
|
||||
const struct stm32_rcc_match_data *data,
|
||||
void __iomem *base,
|
||||
spinlock_t *lock,
|
||||
const struct clock_config *cfg);
|
||||
};
|
||||
|
||||
struct clk_stm32_clock_data {
|
||||
u16 *gate_cpt;
|
||||
const struct stm32_gate_cfg *gates;
|
||||
const struct stm32_mux_cfg *muxes;
|
||||
const struct stm32_div_cfg *dividers;
|
||||
};
|
||||
|
||||
struct stm32_rcc_match_data {
|
||||
struct clk_hw_onecell_data *hw_clks;
|
||||
unsigned int num_clocks;
|
||||
const struct clock_config *tab_clocks;
|
||||
unsigned int maxbinding;
|
||||
struct clk_stm32_clock_data *clock_data;
|
||||
u32 clear_offset;
|
||||
};
|
||||
|
||||
int stm32_rcc_reset_init(struct device *dev, const struct of_device_id *match,
|
||||
void __iomem *base);
|
||||
|
||||
int stm32_rcc_init(struct device *dev, const struct of_device_id *match_data,
|
||||
void __iomem *base);
|
||||
|
||||
/* MUX define */
|
||||
#define MUX_NO_RDY 0xFF
|
||||
|
||||
/* DIV define */
|
||||
#define DIV_NO_RDY 0xFF
|
||||
|
||||
/* Clock registering */
|
||||
#define STM32_CLOCK_CFG(_binding, _clk, _struct, _register)\
|
||||
{\
|
||||
.id = (_binding),\
|
||||
.clock_cfg = (_struct) {_clk},\
|
||||
.func = (_register),\
|
||||
}
|
||||
520
drivers/clk/stm32/clk-stm32mp13.c
Normal file
520
drivers/clk/stm32/clk-stm32mp13.c
Normal file
File diff suppressed because it is too large
Load Diff
122
drivers/clk/stm32/reset-stm32.c
Normal file
122
drivers/clk/stm32/reset-stm32.c
Normal file
@@ -0,0 +1,122 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
/*
|
||||
* Copyright (C) STMicroelectronics 2022 - All Rights Reserved
|
||||
* Author: Gabriel Fernandez <gabriel.fernandez@foss.st.com> for STMicroelectronics.
|
||||
*/
|
||||
|
||||
#include <linux/of.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/regmap.h>
|
||||
#include <linux/reset-controller.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/spinlock.h>
|
||||
|
||||
#include "clk-stm32-core.h"
|
||||
|
||||
#define STM32_RESET_ID_MASK GENMASK(15, 0)
|
||||
|
||||
struct stm32_reset_data {
|
||||
/* reset lock */
|
||||
spinlock_t lock;
|
||||
struct reset_controller_dev rcdev;
|
||||
void __iomem *membase;
|
||||
u32 clear_offset;
|
||||
};
|
||||
|
||||
static inline struct stm32_reset_data *
|
||||
to_stm32_reset_data(struct reset_controller_dev *rcdev)
|
||||
{
|
||||
return container_of(rcdev, struct stm32_reset_data, rcdev);
|
||||
}
|
||||
|
||||
static int stm32_reset_update(struct reset_controller_dev *rcdev,
|
||||
unsigned long id, bool assert)
|
||||
{
|
||||
struct stm32_reset_data *data = to_stm32_reset_data(rcdev);
|
||||
int reg_width = sizeof(u32);
|
||||
int bank = id / (reg_width * BITS_PER_BYTE);
|
||||
int offset = id % (reg_width * BITS_PER_BYTE);
|
||||
|
||||
if (data->clear_offset) {
|
||||
void __iomem *addr;
|
||||
|
||||
addr = data->membase + (bank * reg_width);
|
||||
if (!assert)
|
||||
addr += data->clear_offset;
|
||||
|
||||
writel(BIT(offset), addr);
|
||||
|
||||
} else {
|
||||
unsigned long flags;
|
||||
u32 reg;
|
||||
|
||||
spin_lock_irqsave(&data->lock, flags);
|
||||
|
||||
reg = readl(data->membase + (bank * reg_width));
|
||||
|
||||
if (assert)
|
||||
reg |= BIT(offset);
|
||||
else
|
||||
reg &= ~BIT(offset);
|
||||
|
||||
writel(reg, data->membase + (bank * reg_width));
|
||||
|
||||
spin_unlock_irqrestore(&data->lock, flags);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int stm32_reset_assert(struct reset_controller_dev *rcdev,
|
||||
unsigned long id)
|
||||
{
|
||||
return stm32_reset_update(rcdev, id, true);
|
||||
}
|
||||
|
||||
static int stm32_reset_deassert(struct reset_controller_dev *rcdev,
|
||||
unsigned long id)
|
||||
{
|
||||
return stm32_reset_update(rcdev, id, false);
|
||||
}
|
||||
|
||||
static int stm32_reset_status(struct reset_controller_dev *rcdev,
|
||||
unsigned long id)
|
||||
{
|
||||
struct stm32_reset_data *data = to_stm32_reset_data(rcdev);
|
||||
int reg_width = sizeof(u32);
|
||||
int bank = id / (reg_width * BITS_PER_BYTE);
|
||||
int offset = id % (reg_width * BITS_PER_BYTE);
|
||||
u32 reg;
|
||||
|
||||
reg = readl(data->membase + (bank * reg_width));
|
||||
|
||||
return !!(reg & BIT(offset));
|
||||
}
|
||||
|
||||
static const struct reset_control_ops stm32_reset_ops = {
|
||||
.assert = stm32_reset_assert,
|
||||
.deassert = stm32_reset_deassert,
|
||||
.status = stm32_reset_status,
|
||||
};
|
||||
|
||||
int stm32_rcc_reset_init(struct device *dev, const struct of_device_id *match,
|
||||
void __iomem *base)
|
||||
{
|
||||
const struct stm32_rcc_match_data *data = match->data;
|
||||
struct stm32_reset_data *reset_data = NULL;
|
||||
|
||||
data = match->data;
|
||||
|
||||
reset_data = kzalloc(sizeof(*reset_data), GFP_KERNEL);
|
||||
if (!reset_data)
|
||||
return -ENOMEM;
|
||||
|
||||
reset_data->membase = base;
|
||||
reset_data->rcdev.owner = THIS_MODULE;
|
||||
reset_data->rcdev.ops = &stm32_reset_ops;
|
||||
reset_data->rcdev.of_node = dev_of_node(dev);
|
||||
reset_data->rcdev.nr_resets = STM32_RESET_ID_MASK;
|
||||
reset_data->clear_offset = data->clear_offset;
|
||||
|
||||
return reset_controller_register(&reset_data->rcdev);
|
||||
}
|
||||
8
drivers/clk/stm32/reset-stm32.h
Normal file
8
drivers/clk/stm32/reset-stm32.h
Normal file
@@ -0,0 +1,8 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
/*
|
||||
* Copyright (C) STMicroelectronics 2022 - All Rights Reserved
|
||||
* Author: Gabriel Fernandez <gabriel.fernandez@foss.st.com> for STMicroelectronics.
|
||||
*/
|
||||
|
||||
int stm32_rcc_reset_init(struct device *dev, const struct of_device_id *match,
|
||||
void __iomem *base);
|
||||
1748
drivers/clk/stm32/stm32mp13_rcc.h
Normal file
1748
drivers/clk/stm32/stm32mp13_rcc.h
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user