STM32F4 Add RTC & QSPI clocks
Subsystems (3)
v3 cover STM32F4 Add RTC & QSPI clocks
From: Gabriel Fernandez <[email protected]>
v3:
- remove arm & DT patches from this patch-set
- solve issue of dependency with DT
- remove clk_hw from struct stm32_rgate (use hw of clk_gate)
- suppress CLK_IS_BASIC flags of clk_register_rgate()
- cosmetic changes
v2:
- rename compatible property "st,stm32f46xx-rcc" into "st,stm32f469-rcc"
- cosmetic: remove bad copy/paste
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 at 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 (3):
clk: stm32f4: Add LSI & LSE clocks
clk: stm32f4: Add RTC clock
clk: stm32f469: Add QSPI clock
.../devicetree/bindings/clock/st,stm32-rcc.txt | 4 +- drivers/clk/clk-stm32f4.c | 435 ++++++++++++++++++++- 2 files changed, 417 insertions(+), 22 deletions(-)
Signature · 1 line
1.9.1
PATCH v3 1/3 clk: stm32f4: Add LSI & LSE clocks
From: Gabriel Fernandez <[email protected]>
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.
--- drivers/clk/clk-stm32f4.c | 131 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 126 insertions(+), 5 deletions(-)
drivers/clk/clk-stm32f4.c +126 -5
@@ -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 0x74struct stm32f4_gate_data {u8 offset;
@@ -120,13 +126,12 @@ struct stm32f4_gate_data { { 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 - -enum {SYSTICK ,FCLK }; +#define MAX_CLKS (71 + END_PRIMARY_CLK + 1)/* * This bitmask tells us which bit offsets (0..192) on STM32F4[23]xxx
@@ -140,6 +145,8 @@ struct stm32f4_gate_data {static DEFINE_SPINLOCK (stm32f4_clk_lock);static void __iomem *base; +static struct regmap *pdrm; +/* * "Multiplier" device for APBx clocks. *
@@ -259,7 +266,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 +283,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,6 +299,98 @@ static int stm32f4_rcc_lookup_clk_idx(u8 primary, u8 secondary)return clks[i]; } +#define to_rgclk (_rgate) container_of(_rgate, struct stm32_rgate, gate) + +static inline void disable_power_domain_write_protection (void ) +{ +if (pdrm) +regmap_update_bits (pdrm,0x00 , (1 <<8 ), (1 <<8 )); +} + +static inline void enable_power_domain_write_protection (void ) +{ +if (pdrm) +regmap_update_bits (pdrm,0x00 , (1 <<8 ), (0 <<8 )); +} + +struct stm32_rgate { +struct clk_gate gate; +u8 bit_rdy_idx; +}; + +#define RTC_TIMEOUT 1000000 + +static int rgclk_enable (struct clk_hw *hw) +{ +struct clk_gate *gate =to_clk_gate (hw); +struct stm32_rgate *rgate =to_rgclk (gate); +u32 reg; +int ret; + +disable_power_domain_write_protection (); + + clk_gate_ops.enable (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; + init.parent_names = &parent_name; + init.num_parents =1 ; + + rgate->bit_rdy_idx = bit_rdy_idx; + + rgate->gate.lock = lock; + rgate->gate.reg = reg; + rgate->gate.bit_idx = bit_idx; + rgate->gate.hw.init = &init; + + hw = &rgate->gate.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" };static const struct clk_div_table ahb_div_table[] = {
@@ -319,6 +418,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)) { + pdrm =NULL ; +pr_warn ("%s: Unable to get syscfg\n" , __func__); + } + hse_clk =of_clk_get_parent_name (np,0 ); clk_register_fixed_rate_with_accuracy(NULL, "hsi", NULL, 0,
@@ -371,6 +476,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:
Signature · 1 line
1.9.1
Stephen Boyd
AppliedRe: [PATCH v3 1/3] clk: stm32f4: Add LSI & LSE clocks
Quoted 8 lines · gabriel.fernandez at st.com
From: Gabriel Fernandez <[email protected]>
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 <[email protected]>---
Applied to clk-next +
drivers/clk/clk-stm32f4.c +1 -1
@@ -224,7 +224,7 @@ static const u64 stm32f46xx_gate_map[MAX_GATE_MAP] = { 0x000000f17ef417ffull,0x0000000000000003ull , 0x0c777f33f6fec9ffull }; -const u64 *stm32f4_gate_map; +static const u64 *stm32f4_gate_map;static struct clk_hw **clks;
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
PATCH v3 2/3 clk: stm32f4: Add RTC clock
In reply to [email protected]From: Gabriel Fernandez <[email protected]>
This patch introduces the support of the RTC clock. RTC clock can have 3 sources: lsi, lse and hse_rtc.
--- drivers/clk/clk-stm32f4.c | 137 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 136 insertions(+), 1 deletion(-)
drivers/clk/clk-stm32f4.c +136 -1
@@ -126,7 +126,7 @@ struct stm32f4_gate_data { { 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).
@@ -313,6 +313,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 |BIT (16 ), base +STM32F4_RCC_BDCR ); +writel (val & ~BIT (16 ), base +STM32F4_RCC_BDCR ); +} +struct stm32_rgate {struct clk_gate gate;u8 bit_rdy_idx;
@@ -391,6 +400,111 @@ 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 (*gate),GFP_KERNEL ); +if (!gate) { + hw =ERR_PTR (-EINVAL ); + goto fail; + } + + mux =kzalloc (sizeof (*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" };static const struct clk_div_table ahb_div_table[] = {
@@ -407,6 +521,10 @@ static struct clk_hw *clk_register_rgate(struct device *dev, const char *name, { 0 }, }; +static const char *rtc_parents[4 ] = { +"no-clock" ,"lse" ,"lsi" ,"hse-rtc" +}; +static void __init stm32f4_rcc_init (struct device_node *np) {const char *hse_clk;
@@ -492,6 +610,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:
Signature · 1 line
1.9.1
Stephen Boyd
AppliedRe: [PATCH v3 2/3] clk: stm32f4: Add RTC clock
Quoted 7 lines · gabriel.fernandez at st.com
From: Gabriel Fernandez <[email protected]>
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 <[email protected]>---
Applied to clk-next
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
PATCH v3 3/3 clk: stm32f469: Add QSPI clock
In reply to [email protected]From: Gabriel Fernandez <[email protected]>
This patch adds the QSPI clock for stm32f469 discovery board. The gate mapping is a little bit different from stm32f429 soc.
--- .../devicetree/bindings/clock/st,stm32-rcc.txt | 4 +- drivers/clk/clk-stm32f4.c | 173 ++++++++++++++++++--- 2 files changed, 158 insertions(+), 19 deletions(-)
Documentation/devicetree/bindings/clock/st,stm32-rcc.txt +3 -1
@@ -7,7 +7,9 @@ Please refer to clock-bindings.txt for common clock controller binding usage. Please also refer to reset.txt for common reset controller binding usage. Required properties: -- compatible: Should be "st,stm32f42xx-rcc" +- compatible: Should be: + "st,stm32f42xx-rcc" + "st,stm32f469-rcc" - reg: should be register base and length as documented in the datasheet - #reset-cells: 1, see below
drivers/clk/clk-stm32f4.c +155 -18
231 lines not on this page · raw message
Signature · 1 line
1.9.1
Stephen Boyd
AppliedRe: [PATCH v3 3/3] clk: stm32f469: Add QSPI clock
Quoted 7 lines · gabriel.fernandez at st.com
From: Gabriel Fernandez <[email protected]>
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 <[email protected]>---
Applied to clk-next + added Rob's ack from v2.
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project