* [PATCH 0/6] STM32F4 Add RTC & QSPI clocks
@ 2016-09-30 14:25 gabriel.fernandez-qxv4g6HH51o
[not found] ` <1475245509-6487-1-git-send-email-gabriel.fernandez-qxv4g6HH51o@public.gmane.org>
` (4 more replies)
0 siblings, 5 replies; 9+ messages in thread
From: gabriel.fernandez-qxv4g6HH51o @ 2016-09-30 14:25 UTC (permalink / raw)
To: Rob Herring, Mark Rutland, Russell King, Maxime Coquelin,
Alexandre Torgue, Michael Turquette, Stephen Boyd
Cc: devicetree-u79uwXL29TY76Z2rM5mHXA,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
linux-kernel-u79uwXL29TY76Z2rM5mHXA,
linux-clk-u79uwXL29TY76Z2rM5mHXA, gabriel.fernandez-qxv4g6HH51o,
ludovic.barre-qxv4g6HH51o, olivier.bideau-qxv4g6HH51o,
amelie.delaunay-qxv4g6HH51o
From: Gabriel Fernandez <gabriel.fernandez-qxv4g6HH51o@public.gmane.org>
This patch-set introduce RTC and QSPI clocks for STM32F4 socs
RTC clock has 3 parents clock oscillators (lsi/lse/hse_rtc)
example to use rtc clock:
rtc: rtc@40002800 {
compatible = "st,stm32-rtc";
reg = <0x40002800 0x400>;
...
clocks = <&rcc 1 CLK_RTC>;
assigned-clocks = <&rcc 1 CLK_RTC>;
assigned-clock-parents = <&rcc 1 CLK_LSE>;
...
};
Gabriel Fernandez (6):
clk: stm32f4: Add LSI & LSE clocks
ARM: dts: stm32f429: add LSI and LSE clocks
arm: stmf32: Enable SYSCON
clk: stm32f4: Add RTC clock
clk: stm32f469: Add QSPI clock
ARM: dts: stm32f429: Add QSPI clock
.../devicetree/bindings/clock/st,stm32-rcc.txt | 4 +-
arch/arm/boot/dts/stm32f429.dtsi | 18 +
arch/arm/boot/dts/stm32f469-disco.dts | 4 +
arch/arm/configs/stm32_defconfig | 1 +
drivers/clk/clk-stm32f4.c | 450 ++++++++++++++++++++-
5 files changed, 455 insertions(+), 22 deletions(-)
--
1.9.1
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 9+ messages in thread[parent not found: <1475245509-6487-1-git-send-email-gabriel.fernandez-qxv4g6HH51o@public.gmane.org>]
* [PATCH 1/6] clk: stm32f4: Add LSI & LSE clocks [not found] ` <1475245509-6487-1-git-send-email-gabriel.fernandez-qxv4g6HH51o@public.gmane.org> @ 2016-09-30 14:25 ` gabriel.fernandez-qxv4g6HH51o 2016-09-30 14:25 ` [PATCH 6/6] ARM: dts: stm32f429: Add QSPI clock gabriel.fernandez-qxv4g6HH51o 1 sibling, 0 replies; 9+ messages in thread From: gabriel.fernandez-qxv4g6HH51o @ 2016-09-30 14:25 UTC (permalink / raw) To: Rob Herring, Mark Rutland, Russell King, Maxime Coquelin, Alexandre Torgue, Michael Turquette, Stephen Boyd Cc: devicetree-u79uwXL29TY76Z2rM5mHXA, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, linux-kernel-u79uwXL29TY76Z2rM5mHXA, linux-clk-u79uwXL29TY76Z2rM5mHXA, gabriel.fernandez-qxv4g6HH51o, ludovic.barre-qxv4g6HH51o, olivier.bideau-qxv4g6HH51o, amelie.delaunay-qxv4g6HH51o From: Gabriel Fernandez <gabriel.fernandez-qxv4g6HH51o@public.gmane.org> This patch introduces the support of the LSI & LSE clocks. The clock drivers needs to disable the power domain write protection using syscon/regmap to enable these clocks. Signed-off-by: Gabriel Fernandez <gabriel.fernandez-qxv4g6HH51o@public.gmane.org> --- drivers/clk/clk-stm32f4.c | 146 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 142 insertions(+), 4 deletions(-) diff --git a/drivers/clk/clk-stm32f4.c b/drivers/clk/clk-stm32f4.c index 02d6810..f57e73c 100644 --- a/drivers/clk/clk-stm32f4.c +++ b/drivers/clk/clk-stm32f4.c @@ -19,10 +19,14 @@ #include <linux/clk-provider.h> #include <linux/err.h> #include <linux/io.h> +#include <linux/iopoll.h> +#include <linux/ioport.h> #include <linux/slab.h> #include <linux/spinlock.h> #include <linux/of.h> #include <linux/of_address.h> +#include <linux/regmap.h> +#include <linux/mfd/syscon.h> #define STM32F4_RCC_PLLCFGR 0x04 #define STM32F4_RCC_CFGR 0x08 @@ -31,6 +35,8 @@ #define STM32F4_RCC_AHB3ENR 0x38 #define STM32F4_RCC_APB1ENR 0x40 #define STM32F4_RCC_APB2ENR 0x44 +#define STM32F4_RCC_BDCR 0x70 +#define STM32F4_RCC_CSR 0x74 struct stm32f4_gate_data { u8 offset; @@ -39,6 +45,14 @@ struct stm32f4_gate_data { const char *parent_name; unsigned long flags; }; +struct stm32f4_rgate_data { + u8 offset; + u8 bit_idx; + u8 bit_rdy_idx; + const char *name; + const char *parent_name; + unsigned long flags; +}; static const struct stm32f4_gate_data stm32f4_gates[] __initconst = { { STM32F4_RCC_AHB1ENR, 0, "gpioa", "ahb_div" }, @@ -120,13 +134,13 @@ static const struct stm32f4_gate_data stm32f4_gates[] __initconst = { { STM32F4_RCC_APB2ENR, 26, "ltdc", "apb2_div" }, }; +enum { SYSTICK, FCLK, CLK_LSI, CLK_LSE, END_PRIMARY_CLK }; /* * MAX_CLKS is the maximum value in the enumeration below plus the combined * hweight of stm32f42xx_gate_map (plus one). */ -#define MAX_CLKS 74 +#define MAX_CLKS (71 + END_PRIMARY_CLK + 1) -enum { SYSTICK, FCLK }; /* * This bitmask tells us which bit offsets (0..192) on STM32F4[23]xxx @@ -259,7 +273,7 @@ static int stm32f4_rcc_lookup_clk_idx(u8 primary, u8 secondary) u64 table[ARRAY_SIZE(stm32f42xx_gate_map)]; if (primary == 1) { - if (WARN_ON(secondary > FCLK)) + if (WARN_ON(secondary >= END_PRIMARY_CLK)) return -EINVAL; return secondary; } @@ -276,7 +290,7 @@ static int stm32f4_rcc_lookup_clk_idx(u8 primary, u8 secondary) table[BIT_ULL_WORD(secondary)] &= GENMASK_ULL(secondary % BITS_PER_LONG_LONG, 0); - return FCLK + hweight64(table[0]) + + return END_PRIMARY_CLK - 1 + hweight64(table[0]) + (BIT_ULL_WORD(secondary) >= 1 ? hweight64(table[1]) : 0) + (BIT_ULL_WORD(secondary) >= 2 ? hweight64(table[2]) : 0); } @@ -292,8 +306,110 @@ stm32f4_rcc_lookup_clk(struct of_phandle_args *clkspec, void *data) return clks[i]; } +static struct regmap *pdrm; + +static inline void disable_power_domain_write_protection(void) +{ + regmap_update_bits(pdrm, 0x00, (1 << 8), (1 << 8)); +} + +static inline void enable_power_domain_write_protection(void) +{ + regmap_update_bits(pdrm, 0x00, (1 << 8), (0 << 8)); +} + +struct stm32_rgate { + struct clk_hw hw; + struct clk_gate gate; + u8 bit_rdy_idx; +}; + +#define RTC_TIMEOUT 1000000 + +#define to_rgclk(_hw) container_of(_hw, struct stm32_rgate, hw) + +static int rgclk_enable(struct clk_hw *hw) +{ + struct stm32_rgate *rgate = to_rgclk(hw); + struct clk_hw *gate_hw = &rgate->gate.hw; + struct clk_gate *gate = to_clk_gate(gate_hw); + u32 reg; + int ret; + + __clk_hw_set_clk(gate_hw, hw); + + disable_power_domain_write_protection(); + + clk_gate_ops.enable(gate_hw); + + ret = readl_relaxed_poll_timeout_atomic(gate->reg, reg, + reg & rgate->bit_rdy_idx, 1000, RTC_TIMEOUT); + + enable_power_domain_write_protection(); + + return ret; +} + +static void rgclk_disable(struct clk_hw *hw) +{ + clk_gate_ops.disable(hw); +} + +static int rgclk_is_enabled(struct clk_hw *hw) +{ + return clk_gate_ops.is_enabled(hw); +} + + +static const struct clk_ops rgclk_ops = { + .enable = rgclk_enable, + .disable = rgclk_disable, + .is_enabled = rgclk_is_enabled, +}; + +static struct clk_hw *clk_register_rgate(struct device *dev, const char *name, + const char *parent_name, unsigned long flags, + void __iomem *reg, u8 bit_idx, u8 bit_rdy_idx, + u8 clk_gate_flags, spinlock_t *lock) +{ + struct stm32_rgate *rgate; + struct clk_init_data init = { NULL }; + struct clk_hw *hw; + int ret; + + rgate = kzalloc(sizeof(*rgate), GFP_KERNEL); + if (!rgate) + return ERR_PTR(-ENOMEM); + + init.name = name; + init.ops = &rgclk_ops; + init.flags = flags | CLK_IS_BASIC; + init.parent_names = &parent_name; + init.num_parents = 1; + + rgate->hw.init = &init; + rgate->bit_rdy_idx = bit_rdy_idx; + + rgate->gate.lock = lock; + rgate->gate.reg = reg; + rgate->gate.bit_idx = bit_idx; + + hw = &rgate->hw; + ret = clk_hw_register(dev, hw); + if (ret) { + kfree(rgate); + hw = ERR_PTR(ret); + } + + return hw; +} + static const char *sys_parents[] __initdata = { "hsi", NULL, "pll" }; +const char *rtc_parents[4] = { + "no-clock", "lse", "lsi", "hse-rtc" +}; + static const struct clk_div_table ahb_div_table[] = { { 0x0, 1 }, { 0x1, 1 }, { 0x2, 1 }, { 0x3, 1 }, { 0x4, 1 }, { 0x5, 1 }, { 0x6, 1 }, { 0x7, 1 }, @@ -319,6 +435,12 @@ static void __init stm32f4_rcc_init(struct device_node *np) return; } + pdrm = syscon_regmap_lookup_by_phandle(np, "st,syscfg"); + if (IS_ERR(pdrm)) { + pr_err("%s: Unable to get syscfg\n", __func__); + goto fail; + } + hse_clk = of_clk_get_parent_name(np, 0); clk_register_fixed_rate_with_accuracy(NULL, "hsi", NULL, 0, @@ -371,6 +493,22 @@ static void __init stm32f4_rcc_init(struct device_node *np) } } + clks[CLK_LSI] = clk_register_rgate(NULL, "lsi", "clk-lsi", 0, + base + STM32F4_RCC_CSR, 0, 2, 0, &stm32f4_clk_lock); + + if (IS_ERR(clks[CLK_LSI])) { + pr_err("Unable to register lsi clock\n"); + goto fail; + } + + clks[CLK_LSE] = clk_register_rgate(NULL, "lse", "clk-lse", 0, + base + STM32F4_RCC_BDCR, 0, 2, 0, &stm32f4_clk_lock); + + if (IS_ERR(clks[CLK_LSE])) { + pr_err("Unable to register lse clock\n"); + goto fail; + } + of_clk_add_hw_provider(np, stm32f4_rcc_lookup_clk, NULL); return; fail: -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 6/6] ARM: dts: stm32f429: Add QSPI clock [not found] ` <1475245509-6487-1-git-send-email-gabriel.fernandez-qxv4g6HH51o@public.gmane.org> 2016-09-30 14:25 ` [PATCH 1/6] clk: stm32f4: Add LSI & LSE clocks gabriel.fernandez-qxv4g6HH51o @ 2016-09-30 14:25 ` gabriel.fernandez-qxv4g6HH51o 1 sibling, 0 replies; 9+ messages in thread From: gabriel.fernandez-qxv4g6HH51o @ 2016-09-30 14:25 UTC (permalink / raw) To: Rob Herring, Mark Rutland, Russell King, Maxime Coquelin, Alexandre Torgue, Michael Turquette, Stephen Boyd Cc: devicetree-u79uwXL29TY76Z2rM5mHXA, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, linux-kernel-u79uwXL29TY76Z2rM5mHXA, linux-clk-u79uwXL29TY76Z2rM5mHXA, gabriel.fernandez-qxv4g6HH51o, ludovic.barre-qxv4g6HH51o, olivier.bideau-qxv4g6HH51o, amelie.delaunay-qxv4g6HH51o From: Gabriel Fernandez <gabriel.fernandez-qxv4g6HH51o@public.gmane.org> This patch adds the QSPI clock for stm32f469 discovery board. Signed-off-by: Gabriel Fernandez <gabriel.fernandez-qxv4g6HH51o@public.gmane.org> --- arch/arm/boot/dts/stm32f469-disco.dts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/arm/boot/dts/stm32f469-disco.dts b/arch/arm/boot/dts/stm32f469-disco.dts index cb55ac8..80aecc0 100644 --- a/arch/arm/boot/dts/stm32f469-disco.dts +++ b/arch/arm/boot/dts/stm32f469-disco.dts @@ -66,6 +66,10 @@ }; }; +&rcc { + compatible = "st,stm32f46xx-rcc", "st,stm32-rcc"; +}; + &clk_hse { clock-frequency = <8000000>; }; -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/6] ARM: dts: stm32f429: add LSI and LSE clocks 2016-09-30 14:25 [PATCH 0/6] STM32F4 Add RTC & QSPI clocks gabriel.fernandez-qxv4g6HH51o [not found] ` <1475245509-6487-1-git-send-email-gabriel.fernandez-qxv4g6HH51o@public.gmane.org> @ 2016-09-30 14:25 ` gabriel.fernandez 2016-09-30 14:25 ` [PATCH 3/6] arm: stmf32: Enable SYSCON gabriel.fernandez ` (2 subsequent siblings) 4 siblings, 0 replies; 9+ messages in thread From: gabriel.fernandez @ 2016-09-30 14:25 UTC (permalink / raw) To: Rob Herring, Mark Rutland, Russell King, Maxime Coquelin, Alexandre Torgue, Michael Turquette, Stephen Boyd Cc: devicetree, linux-arm-kernel, linux-kernel, linux-clk, gabriel.fernandez, ludovic.barre, olivier.bideau, amelie.delaunay From: Gabriel Fernandez <gabriel.fernandez@st.com> This patch adds lsi / lse oscillators. These clocks can be use by RTC clocks. The clock drivers needs to disable the power domain write protection using syscon / regmap to enable these clocks. Signed-off-by: Gabriel Fernandez <gabriel.fernandez@st.com> --- arch/arm/boot/dts/stm32f429.dtsi | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/arch/arm/boot/dts/stm32f429.dtsi b/arch/arm/boot/dts/stm32f429.dtsi index 35df462..0979fb6 100644 --- a/arch/arm/boot/dts/stm32f429.dtsi +++ b/arch/arm/boot/dts/stm32f429.dtsi @@ -55,6 +55,18 @@ compatible = "fixed-clock"; clock-frequency = <0>; }; + + clk-lse { + #clock-cells = <0>; + compatible = "fixed-clock"; + clock-frequency = <32768>; + }; + + clk-lsi { + #clock-cells = <0>; + compatible = "fixed-clock"; + clock-frequency = <32000>; + }; }; soc { @@ -176,6 +188,11 @@ reg = <0x40013800 0x400>; }; + pwrcfg: power-config@40007000 { + compatible = "syscon"; + reg = <0x40007000 0x400>; + }; + pin-controller { #address-cells = <1>; #size-cells = <1>; @@ -330,6 +347,7 @@ compatible = "st,stm32f42xx-rcc", "st,stm32-rcc"; reg = <0x40023800 0x400>; clocks = <&clk_hse>; + st,syscfg = <&pwrcfg>; }; dma1: dma-controller@40026000 { -- 1.9.1 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 3/6] arm: stmf32: Enable SYSCON 2016-09-30 14:25 [PATCH 0/6] STM32F4 Add RTC & QSPI clocks gabriel.fernandez-qxv4g6HH51o [not found] ` <1475245509-6487-1-git-send-email-gabriel.fernandez-qxv4g6HH51o@public.gmane.org> 2016-09-30 14:25 ` [PATCH 2/6] ARM: dts: stm32f429: add LSI and LSE clocks gabriel.fernandez @ 2016-09-30 14:25 ` gabriel.fernandez 2016-09-30 14:25 ` [PATCH 4/6] clk: stm32f4: Add RTC clock gabriel.fernandez 2016-09-30 14:25 ` [PATCH 5/6] clk: stm32f469: Add QSPI clock gabriel.fernandez 4 siblings, 0 replies; 9+ messages in thread From: gabriel.fernandez @ 2016-09-30 14:25 UTC (permalink / raw) To: Rob Herring, Mark Rutland, Russell King, Maxime Coquelin, Alexandre Torgue, Michael Turquette, Stephen Boyd Cc: devicetree, linux-arm-kernel, linux-kernel, linux-clk, gabriel.fernandez, ludovic.barre, olivier.bideau, amelie.delaunay From: Gabriel Fernandez <gabriel.fernandez@st.com> The clock drivers needs to disable the power domain write protection using syscon/regmap to enable RTC clock. Signed-off-by: Gabriel Fernandez <gabriel.fernandez@st.com> --- arch/arm/configs/stm32_defconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm/configs/stm32_defconfig b/arch/arm/configs/stm32_defconfig index 08786d8..f3b1ea5 100644 --- a/arch/arm/configs/stm32_defconfig +++ b/arch/arm/configs/stm32_defconfig @@ -49,6 +49,7 @@ CONFIG_SERIAL_STM32=y CONFIG_SERIAL_STM32_CONSOLE=y # CONFIG_HW_RANDOM is not set # CONFIG_HWMON is not set +CONFIG_MFD_SYSCON=y # CONFIG_USB_SUPPORT is not set CONFIG_NEW_LEDS=y CONFIG_LEDS_CLASS=y -- 1.9.1 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 4/6] clk: stm32f4: Add RTC clock 2016-09-30 14:25 [PATCH 0/6] STM32F4 Add RTC & QSPI clocks gabriel.fernandez-qxv4g6HH51o ` (2 preceding siblings ...) 2016-09-30 14:25 ` [PATCH 3/6] arm: stmf32: Enable SYSCON gabriel.fernandez @ 2016-09-30 14:25 ` gabriel.fernandez 2016-09-30 14:25 ` [PATCH 5/6] clk: stm32f469: Add QSPI clock gabriel.fernandez 4 siblings, 0 replies; 9+ messages in thread From: gabriel.fernandez @ 2016-09-30 14:25 UTC (permalink / raw) To: Rob Herring, Mark Rutland, Russell King, Maxime Coquelin, Alexandre Torgue, Michael Turquette, Stephen Boyd Cc: devicetree, linux-arm-kernel, linux-kernel, linux-clk, gabriel.fernandez, ludovic.barre, olivier.bideau, amelie.delaunay From: Gabriel Fernandez <gabriel.fernandez@st.com> This patch introduces the support of the RTC clock. RTC clock can have 3 sources: lsi, lse and hse_rtc. Signed-off-by: Gabriel Fernandez <gabriel.fernandez@st.com> --- drivers/clk/clk-stm32f4.c | 135 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 134 insertions(+), 1 deletion(-) diff --git a/drivers/clk/clk-stm32f4.c b/drivers/clk/clk-stm32f4.c index f57e73c..6e26d39 100644 --- a/drivers/clk/clk-stm32f4.c +++ b/drivers/clk/clk-stm32f4.c @@ -134,7 +134,7 @@ static const struct stm32f4_gate_data stm32f4_gates[] __initconst = { { STM32F4_RCC_APB2ENR, 26, "ltdc", "apb2_div" }, }; -enum { SYSTICK, FCLK, CLK_LSI, CLK_LSE, END_PRIMARY_CLK }; +enum { SYSTICK, FCLK, CLK_LSI, CLK_LSE, CLK_HSE_RTC, CLK_RTC, END_PRIMARY_CLK }; /* * MAX_CLKS is the maximum value in the enumeration below plus the combined * hweight of stm32f42xx_gate_map (plus one). @@ -318,6 +318,15 @@ static inline void enable_power_domain_write_protection(void) regmap_update_bits(pdrm, 0x00, (1 << 8), (0 << 8)); } +static inline void sofware_reset_backup_domain(void) +{ + unsigned long val; + + val = readl(base + STM32F4_RCC_BDCR); + writel(val |= (1 << 16), base + STM32F4_RCC_BDCR); + writel(val & ~(1 << 16), base + STM32F4_RCC_BDCR); +} + struct stm32_rgate { struct clk_hw hw; struct clk_gate gate; @@ -404,6 +413,113 @@ static struct clk_hw *clk_register_rgate(struct device *dev, const char *name, return hw; } +static int cclk_gate_enable(struct clk_hw *hw) +{ + int ret; + + disable_power_domain_write_protection(); + + ret = clk_gate_ops.enable(hw); + + enable_power_domain_write_protection(); + + return ret; +} + +static void cclk_gate_disable(struct clk_hw *hw) +{ + disable_power_domain_write_protection(); + + clk_gate_ops.disable(hw); + + enable_power_domain_write_protection(); +} + +static int cclk_gate_is_enabled(struct clk_hw *hw) +{ + return clk_gate_ops.is_enabled(hw); +} + +static const struct clk_ops cclk_gate_ops = { + .enable = cclk_gate_enable, + .disable = cclk_gate_disable, + .is_enabled = cclk_gate_is_enabled, +}; + +static u8 cclk_mux_get_parent(struct clk_hw *hw) +{ + return clk_mux_ops.get_parent(hw); +} + + +static int cclk_mux_set_parent(struct clk_hw *hw, u8 index) +{ + int ret; + + disable_power_domain_write_protection(); + + sofware_reset_backup_domain(); + + ret = clk_mux_ops.set_parent(hw, index); + + enable_power_domain_write_protection(); + + return ret; +} + + +static const struct clk_ops cclk_mux_ops = { + .get_parent = cclk_mux_get_parent, + .set_parent = cclk_mux_set_parent, +}; + +static struct clk_hw *stm32_register_cclk(struct device *dev, const char *name, + const char * const *parent_names, int num_parents, + void __iomem *reg, u8 bit_idx, u8 shift, unsigned long flags, + spinlock_t *lock) +{ + struct clk_hw *hw; + struct clk_gate *gate; + struct clk_mux *mux; + + gate = kzalloc(sizeof(struct clk_gate), GFP_KERNEL); + if (!gate) { + hw = ERR_PTR(-EINVAL); + goto fail; + } + + mux = kzalloc(sizeof(struct clk_mux), GFP_KERNEL); + if (!mux) { + kfree(gate); + hw = ERR_PTR(-EINVAL); + goto fail; + } + + gate->reg = reg; + gate->bit_idx = bit_idx; + gate->flags = 0; + gate->lock = lock; + + mux->reg = reg; + mux->shift = shift; + mux->mask = 3; + mux->flags = 0; + + hw = clk_hw_register_composite(dev, name, parent_names, num_parents, + &mux->hw, &cclk_mux_ops, + NULL, NULL, + &gate->hw, &cclk_gate_ops, + flags); + + if (IS_ERR(hw)) { + kfree(gate); + kfree(mux); + } + +fail: + return hw; +} + static const char *sys_parents[] __initdata = { "hsi", NULL, "pll" }; const char *rtc_parents[4] = { @@ -509,6 +625,23 @@ static void __init stm32f4_rcc_init(struct device_node *np) goto fail; } + clks[CLK_HSE_RTC] = clk_hw_register_divider(NULL, "hse-rtc", "clk-hse", + 0, base + STM32F4_RCC_CFGR, 16, 5, 0, + &stm32f4_clk_lock); + + if (IS_ERR(clks[CLK_HSE_RTC])) { + pr_err("Unable to register hse-rtc clock\n"); + goto fail; + } + + clks[CLK_RTC] = stm32_register_cclk(NULL, "rtc", rtc_parents, 4, + base + STM32F4_RCC_BDCR, 15, 8, 0, &stm32f4_clk_lock); + + if (IS_ERR(clks[CLK_RTC])) { + pr_err("Unable to register rtc clock\n"); + goto fail; + } + of_clk_add_hw_provider(np, stm32f4_rcc_lookup_clk, NULL); return; fail: -- 1.9.1 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 5/6] clk: stm32f469: Add QSPI clock 2016-09-30 14:25 [PATCH 0/6] STM32F4 Add RTC & QSPI clocks gabriel.fernandez-qxv4g6HH51o ` (3 preceding siblings ...) 2016-09-30 14:25 ` [PATCH 4/6] clk: stm32f4: Add RTC clock gabriel.fernandez @ 2016-09-30 14:25 ` gabriel.fernandez 2016-10-08 20:50 ` Rob Herring 4 siblings, 1 reply; 9+ messages in thread From: gabriel.fernandez @ 2016-09-30 14:25 UTC (permalink / raw) To: Rob Herring, Mark Rutland, Russell King, Maxime Coquelin, Alexandre Torgue, Michael Turquette, Stephen Boyd Cc: devicetree, linux-arm-kernel, linux-kernel, linux-clk, gabriel.fernandez, ludovic.barre, olivier.bideau, amelie.delaunay From: Gabriel Fernandez <gabriel.fernandez@st.com> This patch adds the QSPI clock for stm32f469 discovery board. The gate mapping is a little bit different from stm32f429 soc. Signed-off-by: Gabriel Fernandez <gabriel.fernandez@st.com> --- .../devicetree/bindings/clock/st,stm32-rcc.txt | 4 +- drivers/clk/clk-stm32f4.c | 173 ++++++++++++++++++--- 2 files changed, 158 insertions(+), 19 deletions(-) diff --git a/Documentation/devicetree/bindings/clock/st,stm32-rcc.txt b/Documentation/devicetree/bindings/clock/st,stm32-rcc.txt index fee3205..eace3de 100644 --- a/Documentation/devicetree/bindings/clock/st,stm32-rcc.txt +++ b/Documentation/devicetree/bindings/clock/st,stm32-rcc.txt @@ -8,7 +8,9 @@ Please also refer to clock-bindings.txt in this directory for common clock controller binding usage. Required properties: -- compatible: Should be "st,stm32f42xx-rcc" +- compatible: Should be: + "st,stm32f42xx-rcc" + "st,stm32f46xx-rcc" - reg: should be register base and length as documented in the datasheet - #clock-cells: 2, device nodes should specify the clock in their "clocks" diff --git a/drivers/clk/clk-stm32f4.c b/drivers/clk/clk-stm32f4.c index 6e26d39..bc75d83 100644 --- a/drivers/clk/clk-stm32f4.c +++ b/drivers/clk/clk-stm32f4.c @@ -54,7 +54,7 @@ struct stm32f4_rgate_data { unsigned long flags; }; -static const struct stm32f4_gate_data stm32f4_gates[] __initconst = { +static const struct stm32f4_gate_data stm32f429_gates[] __initconst = { { STM32F4_RCC_AHB1ENR, 0, "gpioa", "ahb_div" }, { STM32F4_RCC_AHB1ENR, 1, "gpiob", "ahb_div" }, { STM32F4_RCC_AHB1ENR, 2, "gpioc", "ahb_div" }, @@ -134,23 +134,109 @@ static const struct stm32f4_gate_data stm32f4_gates[] __initconst = { { STM32F4_RCC_APB2ENR, 26, "ltdc", "apb2_div" }, }; +static const struct stm32f4_gate_data stm32f469_gates[] __initconst = { + { STM32F4_RCC_AHB1ENR, 0, "gpioa", "ahb_div" }, + { STM32F4_RCC_AHB1ENR, 1, "gpiob", "ahb_div" }, + { STM32F4_RCC_AHB1ENR, 2, "gpioc", "ahb_div" }, + { STM32F4_RCC_AHB1ENR, 3, "gpiod", "ahb_div" }, + { STM32F4_RCC_AHB1ENR, 4, "gpioe", "ahb_div" }, + { STM32F4_RCC_AHB1ENR, 5, "gpiof", "ahb_div" }, + { STM32F4_RCC_AHB1ENR, 6, "gpiog", "ahb_div" }, + { STM32F4_RCC_AHB1ENR, 7, "gpioh", "ahb_div" }, + { STM32F4_RCC_AHB1ENR, 8, "gpioi", "ahb_div" }, + { STM32F4_RCC_AHB1ENR, 9, "gpioj", "ahb_div" }, + { STM32F4_RCC_AHB1ENR, 10, "gpiok", "ahb_div" }, + { STM32F4_RCC_AHB1ENR, 12, "crc", "ahb_div" }, + { STM32F4_RCC_AHB1ENR, 18, "bkpsra", "ahb_div" }, + { STM32F4_RCC_AHB1ENR, 20, "ccmdatam", "ahb_div" }, + { STM32F4_RCC_AHB1ENR, 21, "dma1", "ahb_div" }, + { STM32F4_RCC_AHB1ENR, 22, "dma2", "ahb_div" }, + { STM32F4_RCC_AHB1ENR, 23, "dma2d", "ahb_div" }, + { STM32F4_RCC_AHB1ENR, 25, "ethmac", "ahb_div" }, + { STM32F4_RCC_AHB1ENR, 26, "ethmactx", "ahb_div" }, + { STM32F4_RCC_AHB1ENR, 27, "ethmacrx", "ahb_div" }, + { STM32F4_RCC_AHB1ENR, 28, "ethmacptp", "ahb_div" }, + { STM32F4_RCC_AHB1ENR, 29, "otghs", "ahb_div" }, + { STM32F4_RCC_AHB1ENR, 30, "otghsulpi", "ahb_div" }, + + { STM32F4_RCC_AHB2ENR, 0, "dcmi", "ahb_div" }, + { STM32F4_RCC_AHB2ENR, 4, "cryp", "ahb_div" }, + { STM32F4_RCC_AHB2ENR, 5, "hash", "ahb_div" }, + { STM32F4_RCC_AHB2ENR, 6, "rng", "pll48" }, + { STM32F4_RCC_AHB2ENR, 7, "otgfs", "pll48" }, + + { STM32F4_RCC_AHB3ENR, 0, "fmc", "ahb_div", + CLK_IGNORE_UNUSED }, + { STM32F4_RCC_AHB3ENR, 1, "qspi", "ahb_div", + CLK_IGNORE_UNUSED }, + + { STM32F4_RCC_APB1ENR, 0, "tim2", "apb1_mul" }, + { STM32F4_RCC_APB1ENR, 1, "tim3", "apb1_mul" }, + { STM32F4_RCC_APB1ENR, 2, "tim4", "apb1_mul" }, + { STM32F4_RCC_APB1ENR, 3, "tim5", "apb1_mul" }, + { STM32F4_RCC_APB1ENR, 4, "tim6", "apb1_mul" }, + { STM32F4_RCC_APB1ENR, 5, "tim7", "apb1_mul" }, + { STM32F4_RCC_APB1ENR, 6, "tim12", "apb1_mul" }, + { STM32F4_RCC_APB1ENR, 7, "tim13", "apb1_mul" }, + { STM32F4_RCC_APB1ENR, 8, "tim14", "apb1_mul" }, + { STM32F4_RCC_APB1ENR, 11, "wwdg", "apb1_div" }, + { STM32F4_RCC_APB1ENR, 14, "spi2", "apb1_div" }, + { STM32F4_RCC_APB1ENR, 15, "spi3", "apb1_div" }, + { STM32F4_RCC_APB1ENR, 17, "uart2", "apb1_div" }, + { STM32F4_RCC_APB1ENR, 18, "uart3", "apb1_div" }, + { STM32F4_RCC_APB1ENR, 19, "uart4", "apb1_div" }, + { STM32F4_RCC_APB1ENR, 20, "uart5", "apb1_div" }, + { STM32F4_RCC_APB1ENR, 21, "i2c1", "apb1_div" }, + { STM32F4_RCC_APB1ENR, 22, "i2c2", "apb1_div" }, + { STM32F4_RCC_APB1ENR, 23, "i2c3", "apb1_div" }, + { STM32F4_RCC_APB1ENR, 25, "can1", "apb1_div" }, + { STM32F4_RCC_APB1ENR, 26, "can2", "apb1_div" }, + { STM32F4_RCC_APB1ENR, 28, "pwr", "apb1_div" }, + { STM32F4_RCC_APB1ENR, 29, "dac", "apb1_div" }, + { STM32F4_RCC_APB1ENR, 30, "uart7", "apb1_div" }, + { STM32F4_RCC_APB1ENR, 31, "uart8", "apb1_div" }, + + { STM32F4_RCC_APB2ENR, 0, "tim1", "apb2_mul" }, + { STM32F4_RCC_APB2ENR, 1, "tim8", "apb2_mul" }, + { STM32F4_RCC_APB2ENR, 4, "usart1", "apb2_div" }, + { STM32F4_RCC_APB2ENR, 5, "usart6", "apb2_div" }, + { STM32F4_RCC_APB2ENR, 8, "adc1", "apb2_div" }, + { STM32F4_RCC_APB2ENR, 9, "adc2", "apb2_div" }, + { STM32F4_RCC_APB2ENR, 10, "adc3", "apb2_div" }, + { STM32F4_RCC_APB2ENR, 11, "sdio", "pll48" }, + { STM32F4_RCC_APB2ENR, 12, "spi1", "apb2_div" }, + { STM32F4_RCC_APB2ENR, 13, "spi4", "apb2_div" }, + { STM32F4_RCC_APB2ENR, 14, "syscfg", "apb2_div" }, + { STM32F4_RCC_APB2ENR, 16, "tim9", "apb2_mul" }, + { STM32F4_RCC_APB2ENR, 17, "tim10", "apb2_mul" }, + { STM32F4_RCC_APB2ENR, 18, "tim11", "apb2_mul" }, + { STM32F4_RCC_APB2ENR, 20, "spi5", "apb2_div" }, + { STM32F4_RCC_APB2ENR, 21, "spi6", "apb2_div" }, + { STM32F4_RCC_APB2ENR, 22, "sai1", "apb2_div" }, + { STM32F4_RCC_APB2ENR, 26, "ltdc", "apb2_div" }, +}; + enum { SYSTICK, FCLK, CLK_LSI, CLK_LSE, CLK_HSE_RTC, CLK_RTC, END_PRIMARY_CLK }; -/* - * MAX_CLKS is the maximum value in the enumeration below plus the combined - * hweight of stm32f42xx_gate_map (plus one). - */ -#define MAX_CLKS (71 + END_PRIMARY_CLK + 1) /* * This bitmask tells us which bit offsets (0..192) on STM32F4[23]xxx * have gate bits associated with them. Its combined hweight is 71. */ -static const u64 stm32f42xx_gate_map[] = { 0x000000f17ef417ffull, - 0x0000000000000001ull, - 0x04777f33f6fec9ffull }; +#define MAX_GATE_MAP 3 + +static const u64 stm32f42xx_gate_map[MAX_GATE_MAP] = { 0x000000f17ef417ffull, + 0x0000000000000001ull, + 0x04777f33f6fec9ffull }; + +static const u64 stm32f46xx_gate_map[MAX_GATE_MAP] = { 0x000000f17ef417ffull, + 0x0000000000000003ull, + 0x0c777f33f6fec9ffull }; + +const u64 *stm32f4_gate_map; + +static struct clk_hw **clks; -static struct clk_hw *clks[MAX_CLKS]; static DEFINE_SPINLOCK(stm32f4_clk_lock); static void __iomem *base; @@ -270,7 +356,7 @@ static void stm32f4_rcc_register_pll(const char *hse_clk, const char *hsi_clk) */ static int stm32f4_rcc_lookup_clk_idx(u8 primary, u8 secondary) { - u64 table[ARRAY_SIZE(stm32f42xx_gate_map)]; + u64 table[MAX_GATE_MAP]; if (primary == 1) { if (WARN_ON(secondary >= END_PRIMARY_CLK)) @@ -278,7 +364,7 @@ static int stm32f4_rcc_lookup_clk_idx(u8 primary, u8 secondary) return secondary; } - memcpy(table, stm32f42xx_gate_map, sizeof(table)); + memcpy(table, stm32f4_gate_map, sizeof(table)); /* only bits set in table can be used as indices */ if (WARN_ON(secondary >= BITS_PER_BYTE * sizeof(table) || @@ -540,10 +626,42 @@ static const struct clk_div_table apb_div_table[] = { { 0 }, }; +struct stm32f4_clk_data { + const struct stm32f4_gate_data *gates_data; + const u64 *gates_map; + int gates_num; +}; + +static const struct stm32f4_clk_data stm32f429_clk_data = { + .gates_data = stm32f429_gates, + .gates_map = stm32f42xx_gate_map, + .gates_num = ARRAY_SIZE(stm32f429_gates), +}; + +static const struct stm32f4_clk_data stm32f469_clk_data = { + .gates_data = stm32f469_gates, + .gates_map = stm32f46xx_gate_map, + .gates_num = ARRAY_SIZE(stm32f469_gates), +}; + +static const struct of_device_id stm32f4_of_match[] = { + { + .compatible = "st,stm32f42xx-rcc", + .data = &stm32f429_clk_data + }, + { + .compatible = "st,stm32f46xx-rcc", + .data = &stm32f469_clk_data + }, + {} +}; + static void __init stm32f4_rcc_init(struct device_node *np) { const char *hse_clk; int n; + const struct of_device_id *match; + const struct stm32f4_clk_data *data; base = of_iomap(np, 0); if (!base) { @@ -557,6 +675,19 @@ static void __init stm32f4_rcc_init(struct device_node *np) goto fail; } + match = of_match_node(stm32f4_of_match, np); + if (WARN_ON(!match)) + return; + + data = match->data; + + clks = kmalloc_array(data->gates_num + END_PRIMARY_CLK, + sizeof(struct clk_hw *), GFP_KERNEL); + if (!clks) + goto fail; + + stm32f4_gate_map = data->gates_map; + hse_clk = of_clk_get_parent_name(np, 0); clk_register_fixed_rate_with_accuracy(NULL, "hsi", NULL, 0, @@ -589,11 +720,15 @@ static void __init stm32f4_rcc_init(struct device_node *np) clks[FCLK] = clk_hw_register_fixed_factor(NULL, "fclk", "ahb_div", 0, 1, 1); - for (n = 0; n < ARRAY_SIZE(stm32f4_gates); n++) { - const struct stm32f4_gate_data *gd = &stm32f4_gates[n]; - unsigned int secondary = - 8 * (gd->offset - STM32F4_RCC_AHB1ENR) + gd->bit_idx; - int idx = stm32f4_rcc_lookup_clk_idx(0, secondary); + for (n = 0; n < data->gates_num; n++) { + const struct stm32f4_gate_data *gd; + unsigned int secondary; + int idx; + + gd = (struct stm32f4_gate_data *) &data->gates_data[n]; + secondary = 8 * (gd->offset - STM32F4_RCC_AHB1ENR) + + gd->bit_idx; + idx = stm32f4_rcc_lookup_clk_idx(0, secondary); if (idx < 0) goto fail; @@ -645,6 +780,8 @@ static void __init stm32f4_rcc_init(struct device_node *np) of_clk_add_hw_provider(np, stm32f4_rcc_lookup_clk, NULL); return; fail: + kfree(clks); iounmap(base); } -CLK_OF_DECLARE(stm32f4_rcc, "st,stm32f42xx-rcc", stm32f4_rcc_init); +CLK_OF_DECLARE(stm32f42xx_rcc, "st,stm32f42xx-rcc", stm32f4_rcc_init); +CLK_OF_DECLARE(stm32f46xx_rcc, "st,stm32f46xx-rcc", stm32f4_rcc_init); -- 1.9.1 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 5/6] clk: stm32f469: Add QSPI clock 2016-09-30 14:25 ` [PATCH 5/6] clk: stm32f469: Add QSPI clock gabriel.fernandez @ 2016-10-08 20:50 ` Rob Herring 2016-10-11 9:17 ` Gabriel Fernandez 0 siblings, 1 reply; 9+ messages in thread From: Rob Herring @ 2016-10-08 20:50 UTC (permalink / raw) To: gabriel.fernandez Cc: Mark Rutland, Russell King, Maxime Coquelin, Alexandre Torgue, Michael Turquette, Stephen Boyd, devicetree, linux-arm-kernel, linux-kernel, linux-clk, ludovic.barre, olivier.bideau, amelie.delaunay On Fri, Sep 30, 2016 at 04:25:08PM +0200, gabriel.fernandez@st.com wrote: > From: Gabriel Fernandez <gabriel.fernandez@st.com> > > This patch adds the QSPI clock for stm32f469 discovery board. > The gate mapping is a little bit different from stm32f429 soc. > > Signed-off-by: Gabriel Fernandez <gabriel.fernandez@st.com> > --- > .../devicetree/bindings/clock/st,stm32-rcc.txt | 4 +- > drivers/clk/clk-stm32f4.c | 173 ++++++++++++++++++--- > 2 files changed, 158 insertions(+), 19 deletions(-) > > diff --git a/Documentation/devicetree/bindings/clock/st,stm32-rcc.txt b/Documentation/devicetree/bindings/clock/st,stm32-rcc.txt > index fee3205..eace3de 100644 > --- a/Documentation/devicetree/bindings/clock/st,stm32-rcc.txt > +++ b/Documentation/devicetree/bindings/clock/st,stm32-rcc.txt > @@ -8,7 +8,9 @@ Please also refer to clock-bindings.txt in this directory for common clock > controller binding usage. > > Required properties: > -- compatible: Should be "st,stm32f42xx-rcc" > +- compatible: Should be: > + "st,stm32f42xx-rcc" > + "st,stm32f46xx-rcc" Generally, we don't use wildcards in compatible strings. I know there's lots of part numbers of stm32 parts which I guess are often same die with different fusing or package. Your compatible strings should be at least specific enough to identify parts that are really different die. > - reg: should be register base and length as documented in the > datasheet > - #clock-cells: 2, device nodes should specify the clock in their "clocks" ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 5/6] clk: stm32f469: Add QSPI clock 2016-10-08 20:50 ` Rob Herring @ 2016-10-11 9:17 ` Gabriel Fernandez 0 siblings, 0 replies; 9+ messages in thread From: Gabriel Fernandez @ 2016-10-11 9:17 UTC (permalink / raw) To: Rob Herring Cc: Mark Rutland, devicetree, amelie.delaunay, Alexandre Torgue, olivier.bideau, Michael Turquette, Stephen Boyd, Russell King, linux-kernel, ludovic.barre, Maxime Coquelin, linux-clk, linux-arm-kernel Hi Rob, Thanks for reviewing On 10/08/2016 10:50 PM, Rob Herring wrote: > On Fri, Sep 30, 2016 at 04:25:08PM +0200, gabriel.fernandez@st.com wrote: >> From: Gabriel Fernandez <gabriel.fernandez@st.com> >> >> This patch adds the QSPI clock for stm32f469 discovery board. >> The gate mapping is a little bit different from stm32f429 soc. >> >> Signed-off-by: Gabriel Fernandez <gabriel.fernandez@st.com> >> --- >> .../devicetree/bindings/clock/st,stm32-rcc.txt | 4 +- >> drivers/clk/clk-stm32f4.c | 173 ++++++++++++++++++--- >> 2 files changed, 158 insertions(+), 19 deletions(-) >> >> diff --git a/Documentation/devicetree/bindings/clock/st,stm32-rcc.txt b/Documentation/devicetree/bindings/clock/st,stm32-rcc.txt >> index fee3205..eace3de 100644 >> --- a/Documentation/devicetree/bindings/clock/st,stm32-rcc.txt >> +++ b/Documentation/devicetree/bindings/clock/st,stm32-rcc.txt >> @@ -8,7 +8,9 @@ Please also refer to clock-bindings.txt in this directory for common clock >> controller binding usage. >> >> Required properties: >> -- compatible: Should be "st,stm32f42xx-rcc" >> +- compatible: Should be: >> + "st,stm32f42xx-rcc" >> + "st,stm32f46xx-rcc" > Generally, we don't use wildcards in compatible strings. I know there's > lots of part numbers of stm32 parts which I guess are often same die > with different fusing or package. Your compatible strings should be at > least specific enough to identify parts that are really different die. okay i will propose "st,stm32f469-rcc" if no one is against. BR Gabriel > >> - reg: should be register base and length as documented in the >> datasheet >> - #clock-cells: 2, device nodes should specify the clock in their "clocks" ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2016-10-11 9:17 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-30 14:25 [PATCH 0/6] STM32F4 Add RTC & QSPI clocks gabriel.fernandez-qxv4g6HH51o
[not found] ` <1475245509-6487-1-git-send-email-gabriel.fernandez-qxv4g6HH51o@public.gmane.org>
2016-09-30 14:25 ` [PATCH 1/6] clk: stm32f4: Add LSI & LSE clocks gabriel.fernandez-qxv4g6HH51o
2016-09-30 14:25 ` [PATCH 6/6] ARM: dts: stm32f429: Add QSPI clock gabriel.fernandez-qxv4g6HH51o
2016-09-30 14:25 ` [PATCH 2/6] ARM: dts: stm32f429: add LSI and LSE clocks gabriel.fernandez
2016-09-30 14:25 ` [PATCH 3/6] arm: stmf32: Enable SYSCON gabriel.fernandez
2016-09-30 14:25 ` [PATCH 4/6] clk: stm32f4: Add RTC clock gabriel.fernandez
2016-09-30 14:25 ` [PATCH 5/6] clk: stm32f469: Add QSPI clock gabriel.fernandez
2016-10-08 20:50 ` Rob Herring
2016-10-11 9:17 ` Gabriel Fernandez
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).