clk: bcm281xx: updates for 3.15
Subsystems (5)
v2 cover clk: bcm281xx: updates for 3.15
This series includes updates for the bcm281xx clock code for 3.15. I had held off posting this until the code on which this is based was queued for 3.14, and it now has been:
https://github.com/broadcom/mach-bcm/
Branch armsoc/for-3.15/drivers
clk: bcm281xx: don't disable unused peripheral clocks
clk: bcm281xx: add initial clock framework support
followed by:
(same repository)
Branch armsoc/for-3.15/dt
ARM: dts: bcm281xx: define real clocks
The patches in this series are available here:
http://git.linaro.org/landing-teams/working/broadcom/kernel.git
Branch review/bcm-clk-next-v2
I've grouped them, and offer a little explanation of each of the groups below.
Note: The final (DT) patch *must* be committed last.
The first version of this series had a patch from the middle of the series that shouldn't have been there, and it has been removed in this version (that patch affected mach-bcm, not clk). I also split the final patch into two, with the second one isolating the change to a device tree file.
-Alex
Alex Elder (12):
clk: bcm281xx: warn if ccu_wait_bit() fails
clk: bcm281xx: use init_data.name for clock name
clk: bcm281xx: change some symbol names
Three small code improvements.
clk: bcm281xx: initialize CCU structures statically
clk: bcm281xx: define CCU clock data statically
Rearrange the way CCUs and the clocks they provide are defined, so that they're defined statically to the extent possible rather than allocating and initializing things at runtime.
clk: bcm281xx: add clock policy support
clk: bcm281xx: add clock hysteresis support
clk: bcm281xx: add an initialized flag
clk: bcm281xx: implement prerequisite clocks
clk: bcm281xx: add bus clock support
clk: bcm281xx: define a bus clock
Add a few new features, ultimately for the purpose of adding support for another type of Kona clock. Currently only peripheral clocks are supported; this adds the ability to define and control bus clocks. In addition, support is added for clocks to identify a prerequisite clock; a clock won't be initialized until after its prerequisite has been.
ARM: dts: add bus clock bsc3_apb for bcm281xx
Add the new bus clock to the device tree.
arch/arm/boot/dts/bcm11351.dtsi | 3 +- drivers/clk/bcm/clk-bcm281xx.c | 254 ++++++++++++-------------- drivers/clk/bcm/clk-kona-setup.c | 331 +++++++++++++++++++++++++++------- drivers/clk/bcm/clk-kona.c | 331 ++++++++++++++++++++++++++++++++-- drivers/clk/bcm/clk-kona.h | 189 ++++++++++++++++--- include/dt-bindings/clock/bcm281xx.h | 3 +- 6 files changed, 872 insertions(+), 239 deletions(-)
Signature · 1 line
1.7.9.5
PATCH v2 1/12 clk: bcm281xx: warn if ccu_wait_bit() fails
Don't let a failure of ccu_wait_bit() go unnoticed.
--- drivers/clk/bcm/clk-kona.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/clk/bcm/clk-kona.c +3 -0
@@ -207,6 +207,9 @@ __ccu_wait_bit(struct ccu_data *ccu, u32 reg_offset, u32 bit, bool want)return true;udelay (1 ); } +pr_warn ("%s: %s/0x%04x bit %u was never %s\n" , __func__, + ccu->name, reg_offset, bit, want ?"set" :"clear" ); +return false; }
Signature · 1 line
1.7.9.5
PATCH v2 2/12 clk: bcm281xx: use init_data.name for clock name
In reply to Alex ElderUse the init_data.name field to hold the name of a Kona clock rather than duplicating it.
--- drivers/clk/bcm/clk-kona-setup.c | 6 +++--- drivers/clk/bcm/clk-kona.c | 17 ++++++++++------- drivers/clk/bcm/clk-kona.h | 3 +-- 3 files changed, 14 insertions(+), 12 deletions(-)
drivers/clk/bcm/clk-kona-setup.c +3 -3
@@ -64,7 +64,7 @@ static bool peri_clk_data_offsets_valid(struct kona_clk *bcm_clk)BUG_ON (bcm_clk->type != bcm_clk_peri); peri = bcm_clk->peri; - name = bcm_clk->name; + name = bcm_clk->init_data.name; range = bcm_clk->ccu->range; limit = range -sizeof (u32);
@@ -329,7 +329,7 @@ peri_clk_data_valid(struct kona_clk *bcm_clk)return false; peri = bcm_clk->peri; - name = bcm_clk->name; + name = bcm_clk->init_data.name; gate = &peri->gate;if (gate_exists (gate) && !gate_valid (gate,"gate" , name))return false;
@@ -630,7 +630,7 @@ struct clk *kona_clk_setup(struct ccu_data *ccu, const char *name,return NULL ; } bcm_clk->ccu = ccu; - bcm_clk->name = name; + bcm_clk->init_data.name = name; init_data = &bcm_clk->init_data; init_data->name = name;
drivers/clk/bcm/clk-kona.c +10 -7
@@ -807,7 +807,7 @@ static int kona_peri_clk_enable(struct clk_hw *hw)struct kona_clk *bcm_clk =to_kona_clk (hw);struct bcm_clk_gate *gate = &bcm_clk->peri->gate; -return clk_gate (bcm_clk->ccu, bcm_clk->name, gate, true); +return clk_gate (bcm_clk->ccu, bcm_clk->init_data.name, gate, true); }static void kona_peri_clk_disable (struct clk_hw *hw)
@@ -815,7 +815,7 @@ static void kona_peri_clk_disable(struct clk_hw *hw)struct kona_clk *bcm_clk =to_kona_clk (hw);struct bcm_clk_gate *gate = &bcm_clk->peri->gate; - (void )clk_gate (bcm_clk->ccu, bcm_clk->name, gate, false); + (void )clk_gate (bcm_clk->ccu, bcm_clk->init_data.name, gate, false); }static int kona_peri_clk_is_enabled (struct clk_hw *hw)
@@ -873,12 +873,13 @@ static int kona_peri_clk_set_parent(struct clk_hw *hw, u8 index) ret =selector_write (bcm_clk->ccu, &data->gate, sel, trig, index);if (ret == -ENXIO ) { -pr_err ("%s: gating failure for %s\n" , __func__, bcm_clk->name); +pr_err ("%s: gating failure for %s\n" , __func__, + bcm_clk->init_data.name); ret = -EIO ;/* Don't proliferate weird errors */ }else if (ret == -EIO ) {pr_err ("%s: %strigger failed for %s\n" , __func__, trig == &data->pre_trig ?"pre-" :"" , - bcm_clk->name); + bcm_clk->init_data.name); }return ret;
@@ -937,10 +938,12 @@ static int kona_peri_clk_set_rate(struct clk_hw *hw, unsigned long rate, ret =divider_write (bcm_clk->ccu, &data->gate, &data->div, &data->trig, scaled_div);if (ret == -ENXIO ) { -pr_err ("%s: gating failure for %s\n" , __func__, bcm_clk->name); +pr_err ("%s: gating failure for %s\n" , __func__, + bcm_clk->init_data.name); ret = -EIO ;/* Don't proliferate weird errors */ }else if (ret == -EIO ) { -pr_err ("%s: trigger failed for %s\n" , __func__, bcm_clk->name); +pr_err ("%s: trigger failed for %s\n" , __func__, + bcm_clk->init_data.name); }return ret;
@@ -962,7 +965,7 @@ static bool __peri_clk_init(struct kona_clk *bcm_clk) {struct ccu_data *ccu = bcm_clk->ccu;struct peri_clk_data *peri = bcm_clk->peri; -const char *name = bcm_clk->name; +const char *name = bcm_clk->init_data.name;struct bcm_clk_trig *trig;BUG_ON (bcm_clk->type != bcm_clk_peri);
drivers/clk/bcm/clk-kona.h +1 -2
@@ -373,8 +373,7 @@ struct peri_clk_data {struct kona_clk {struct clk_hw hw; -struct clk_init_data init_data; -const char *name;/* name of this clock */ +struct clk_init_data init_data;/* includes name of this clock */ struct ccu_data *ccu;/* ccu this clock is associated with */ enum bcm_clk_type type;union {
Signature · 1 line
1.7.9.5
PATCH v2 3/12 clk: bcm281xx: change some symbol names
In reply to Alex ElderAs I developed the bcm281xx clock code I understood there were restrictions on device tree "compatible" strings names, and as a result "bcm11351" was used in places despite the part family being more properly called "bcm281xx". This can be a little confusing.
In some cases I went to far and things using "bcm11351" when that was not necessary.
This patch remedies this. It renames the symbol used to define the "compatible" string (but not its value) so it uses "BCM281XX". Similarly, the name names provided to the CLK_OF_DECLARE() macro are changed, hoping to minimize the number of places that the confusing "11351" string is used.
--- drivers/clk/bcm/clk-bcm281xx.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-)
drivers/clk/bcm/clk-bcm281xx.c +16 -11
@@ -15,12 +15,17 @@#include "clk-kona.h" #include "dt-bindings/clock/bcm281xx.h" -/* bcm11351 CCU device tree "compatible" strings */ -#define BCM11351_DT_ROOT_CCU_COMPAT "brcm,bcm11351-root-ccu" -#define BCM11351_DT_AON_CCU_COMPAT "brcm,bcm11351-aon-ccu" -#define BCM11351_DT_HUB_CCU_COMPAT "brcm,bcm11351-hub-ccu" -#define BCM11351_DT_MASTER_CCU_COMPAT "brcm,bcm11351-master-ccu" -#define BCM11351_DT_SLAVE_CCU_COMPAT "brcm,bcm11351-slave-ccu" +/* +* These are the bcm281xx CCU device tree "compatible" strings. +* We're stuck with using "bcm11351" in the string because wild +* cards aren't allowed, and that name was the first one defined +* in this family of devices. +*/ +#define BCM281XX_DT_ROOT_CCU_COMPAT "brcm,bcm11351-root-ccu" +#define BCM281XX_DT_AON_CCU_COMPAT "brcm,bcm11351-aon-ccu" +#define BCM281XX_DT_HUB_CCU_COMPAT "brcm,bcm11351-hub-ccu" +#define BCM281XX_DT_MASTER_CCU_COMPAT "brcm,bcm11351-master-ccu" +#define BCM281XX_DT_SLAVE_CCU_COMPAT "brcm,bcm11351-slave-ccu"/* Root CCU clocks */
@@ -404,13 +409,13 @@ static void __init kona_dt_slave_ccu_setup(struct device_node *node)kona_dt_ccu_setup (node, bcm281xx_slave_ccu_clks_setup); } -CLK_OF_DECLARE (bcm11351_root_ccu,BCM11351_DT_ROOT_CCU_COMPAT , +CLK_OF_DECLARE (bcm281xx_root_ccu,BCM281XX_DT_ROOT_CCU_COMPAT , kona_dt_root_ccu_setup); -CLK_OF_DECLARE (bcm11351_aon_ccu,BCM11351_DT_AON_CCU_COMPAT , +CLK_OF_DECLARE (bcm281xx_aon_ccu,BCM281XX_DT_AON_CCU_COMPAT , kona_dt_aon_ccu_setup); -CLK_OF_DECLARE (bcm11351_hub_ccu,BCM11351_DT_HUB_CCU_COMPAT , +CLK_OF_DECLARE (bcm281xx_hub_ccu,BCM281XX_DT_HUB_CCU_COMPAT , kona_dt_hub_ccu_setup); -CLK_OF_DECLARE (bcm11351_master_ccu,BCM11351_DT_MASTER_CCU_COMPAT , +CLK_OF_DECLARE (bcm281xx_master_ccu,BCM281XX_DT_MASTER_CCU_COMPAT , kona_dt_master_ccu_setup); -CLK_OF_DECLARE (bcm11351_slave_ccu,BCM11351_DT_SLAVE_CCU_COMPAT , +CLK_OF_DECLARE (bcm281xx_slave_ccu,BCM281XX_DT_SLAVE_CCU_COMPAT , kona_dt_slave_ccu_setup);
Signature · 1 line
1.7.9.5
PATCH v2 4/12 clk: bcm281xx: initialize CCU structures statically
In reply to Alex ElderWe know up front how many CCU's we'll support, so there's no need to allocate their data structures dynamically. Define a macro KONA_CCU_COMMON() to simplify the initialization of many of the fields in a ccu_data structure. Pass the address of a statically defined CCU structure to kona_dt_ccu_setup() rather than having that function allocate one.
We also know at build time how many clocks a given CCU will provide, though the number of of them for each CCU is different. Record the number of clocks we need in the CCU's clk_onecell_data struct (which is used when we register the CCU with the common clock code as a clock provider). Rename that struct field "clk_data" (because "data" alone gets a little confusing).
Use the known clock count to move the allocation of each CCU's clocks array into ccu_clks_setup() rather than having each CCU's setup callback function do it.
(The real motivation behind all of this is that we'll be doing some static initialization of some additional CCU-specific data soon.)
--- drivers/clk/bcm/clk-bcm281xx.c | 144 +++++++++++++++----------------------- drivers/clk/bcm/clk-kona-setup.c | 47 ++++++------- drivers/clk/bcm/clk-kona.c | 4 +- drivers/clk/bcm/clk-kona.h | 21 ++++-- 4 files changed, 97 insertions(+), 119 deletions(-)
drivers/clk/bcm/clk-bcm281xx.c +57 -87
@@ -15,6 +15,9 @@#include "clk-kona.h" #include "dt-bindings/clock/bcm281xx.h" +#define BCM281XX_CCU_COMMON (_name, _ucase_name) \ + KONA_CCU_COMMON(BCM281XX, _name, _ucase_name) +/* * These are the bcm281xx CCU device tree "compatible" strings. * We're stuck with using "bcm11351" in the string because wild
@@ -27,7 +30,7 @@#define BCM281XX_DT_MASTER_CCU_COMPAT "brcm,bcm11351-master-ccu"#define BCM281XX_DT_SLAVE_CCU_COMPAT "brcm,bcm11351-slave-ccu" -/* Root CCU clocks */ +/* Root CCU */ static struct peri_clk_data frac_1m_data = { .gate =HW_SW_GATE (0x214 ,16 ,0 ,1 ),
@@ -36,7 +39,11 @@ static struct peri_clk_data frac_1m_data = { .clocks = CLOCKS("ref_crystal"), }; -/* AON CCU clocks */ +static struct ccu_data root_ccu_data = { +BCM281XX_CCU_COMMON (root,ROOT ), +}; + +/* AON CCU */ static struct peri_clk_data hub_timer_data = { .gate =HW_SW_GATE (0x0414 ,16 ,0 ,1 ),
@@ -65,7 +72,11 @@ static struct peri_clk_data pmu_bsc_var_data = { .trig = TRIGGER(0x0a40, 2), }; -/* Hub CCU clocks */ +static struct ccu_data aon_ccu_data = { +BCM281XX_CCU_COMMON (aon,AON ), +}; + +/* Hub CCU */ static struct peri_clk_data tmon_1m_data = { .gate =HW_SW_GATE (0x04a4 ,18 ,2 ,3 ),
@@ -75,7 +86,11 @@ static struct peri_clk_data tmon_1m_data = { .trig = TRIGGER(0x0e84, 1), }; -/* Master CCU clocks */ +static struct ccu_data hub_ccu_data = { +BCM281XX_CCU_COMMON (hub,HUB ), +}; + +/* Master CCU */ static struct peri_clk_data sdio1_data = { .gate =HW_SW_GATE (0x0358 ,18 ,2 ,3 ),
@@ -158,7 +173,11 @@ static struct peri_clk_data hsic2_12m_data = { .trig = TRIGGER(0x0afc, 5), }; -/* Slave CCU clocks */ +static struct ccu_data master_ccu_data = { +BCM281XX_CCU_COMMON (master,MASTER ), +}; + +/* Slave CCU */ static struct peri_clk_data uartb_data = { .gate =HW_SW_GATE (0x0400 ,18 ,2 ,3 ),
@@ -266,6 +285,10 @@ static struct peri_clk_data pwm_data = { .trig = TRIGGER(0x0afc, 15), }; +static struct ccu_data slave_ccu_data = { +BCM281XX_CCU_COMMON (slave,SLAVE ), +}; +/* * CCU setup routines *
@@ -277,107 +300,52 @@ static struct peri_clk_data pwm_data = {*/ static int __init bcm281xx_root_ccu_clks_setup (struct ccu_data *ccu) { -struct clk **clks; -size_t count =BCM281XX_ROOT_CCU_CLOCK_COUNT ; - - clks =kzalloc (count *sizeof (*clks),GFP_KERNEL ); -if (!clks) { -pr_err ("%s: failed to allocate root clocks\n" , __func__); -return -ENOMEM ; - } - ccu->data.clks = clks; - ccu->data.clk_num = count; - -PERI_CLK_SETUP (clks, ccu,BCM281XX_ROOT_CCU_FRAC_1M , frac_1m); +PERI_CLK_SETUP (ccu,BCM281XX_ROOT_CCU_FRAC_1M , frac_1m);return 0 ; }static int __init bcm281xx_aon_ccu_clks_setup (struct ccu_data *ccu) { -struct clk **clks; -size_t count =BCM281XX_AON_CCU_CLOCK_COUNT ; - - clks =kzalloc (count *sizeof (*clks),GFP_KERNEL ); -if (!clks) { -pr_err ("%s: failed to allocate aon clocks\n" , __func__); -return -ENOMEM ; - } - ccu->data.clks = clks; - ccu->data.clk_num = count; - -PERI_CLK_SETUP (clks, ccu,BCM281XX_AON_CCU_HUB_TIMER , hub_timer); -PERI_CLK_SETUP (clks, ccu,BCM281XX_AON_CCU_PMU_BSC , pmu_bsc); -PERI_CLK_SETUP (clks, ccu,BCM281XX_AON_CCU_PMU_BSC_VAR , pmu_bsc_var); +PERI_CLK_SETUP (ccu,BCM281XX_AON_CCU_HUB_TIMER , hub_timer); +PERI_CLK_SETUP (ccu,BCM281XX_AON_CCU_PMU_BSC , pmu_bsc); +PERI_CLK_SETUP (ccu,BCM281XX_AON_CCU_PMU_BSC_VAR , pmu_bsc_var);return 0 ; }static int __init bcm281xx_hub_ccu_clks_setup (struct ccu_data *ccu) { -struct clk **clks; -size_t count =BCM281XX_HUB_CCU_CLOCK_COUNT ; - - clks =kzalloc (count *sizeof (*clks),GFP_KERNEL ); -if (!clks) { -pr_err ("%s: failed to allocate hub clocks\n" , __func__); -return -ENOMEM ; - } - ccu->data.clks = clks; - ccu->data.clk_num = count; - -PERI_CLK_SETUP (clks, ccu,BCM281XX_HUB_CCU_TMON_1M , tmon_1m); +PERI_CLK_SETUP (ccu,BCM281XX_HUB_CCU_TMON_1M , tmon_1m);return 0 ; }static int __init bcm281xx_master_ccu_clks_setup (struct ccu_data *ccu) { -struct clk **clks; -size_t count =BCM281XX_MASTER_CCU_CLOCK_COUNT ; - - clks =kzalloc (count *sizeof (*clks),GFP_KERNEL ); -if (!clks) { -pr_err ("%s: failed to allocate master clocks\n" , __func__); -return -ENOMEM ; - } - ccu->data.clks = clks; - ccu->data.clk_num = count; - -PERI_CLK_SETUP (clks, ccu,BCM281XX_MASTER_CCU_SDIO1 , sdio1); -PERI_CLK_SETUP (clks, ccu,BCM281XX_MASTER_CCU_SDIO2 , sdio2); -PERI_CLK_SETUP (clks, ccu,BCM281XX_MASTER_CCU_SDIO3 , sdio3); -PERI_CLK_SETUP (clks, ccu,BCM281XX_MASTER_CCU_SDIO4 , sdio4); -PERI_CLK_SETUP (clks, ccu,BCM281XX_MASTER_CCU_USB_IC , usb_ic); -PERI_CLK_SETUP (clks, ccu,BCM281XX_MASTER_CCU_HSIC2_48M , hsic2_48m); -PERI_CLK_SETUP (clks, ccu,BCM281XX_MASTER_CCU_HSIC2_12M , hsic2_12m); +PERI_CLK_SETUP (ccu,BCM281XX_MASTER_CCU_SDIO1 , sdio1); +PERI_CLK_SETUP (ccu,BCM281XX_MASTER_CCU_SDIO2 , sdio2); +PERI_CLK_SETUP (ccu,BCM281XX_MASTER_CCU_SDIO3 , sdio3); +PERI_CLK_SETUP (ccu,BCM281XX_MASTER_CCU_SDIO4 , sdio4); +PERI_CLK_SETUP (ccu,BCM281XX_MASTER_CCU_USB_IC , usb_ic); +PERI_CLK_SETUP (ccu,BCM281XX_MASTER_CCU_HSIC2_48M , hsic2_48m); +PERI_CLK_SETUP (ccu,BCM281XX_MASTER_CCU_HSIC2_12M , hsic2_12m);return 0 ; }static int __init bcm281xx_slave_ccu_clks_setup (struct ccu_data *ccu) { -struct clk **clks; -size_t count =BCM281XX_SLAVE_CCU_CLOCK_COUNT ; - - clks =kzalloc (count *sizeof (*clks),GFP_KERNEL ); -if (!clks) { -pr_err ("%s: failed to allocate slave clocks\n" , __func__); -return -ENOMEM ; - } - ccu->data.clks = clks; - ccu->data.clk_num = count; - -PERI_CLK_SETUP (clks, ccu,BCM281XX_SLAVE_CCU_UARTB , uartb); -PERI_CLK_SETUP (clks, ccu,BCM281XX_SLAVE_CCU_UARTB2 , uartb2); -PERI_CLK_SETUP (clks, ccu,BCM281XX_SLAVE_CCU_UARTB3 , uartb3); -PERI_CLK_SETUP (clks, ccu,BCM281XX_SLAVE_CCU_UARTB4 , uartb4); -PERI_CLK_SETUP (clks, ccu,BCM281XX_SLAVE_CCU_SSP0 , ssp0); -PERI_CLK_SETUP (clks, ccu,BCM281XX_SLAVE_CCU_SSP2 , ssp2); -PERI_CLK_SETUP (clks, ccu,BCM281XX_SLAVE_CCU_BSC1 , bsc1); -PERI_CLK_SETUP (clks, ccu,BCM281XX_SLAVE_CCU_BSC2 , bsc2); -PERI_CLK_SETUP (clks, ccu,BCM281XX_SLAVE_CCU_BSC3 , bsc3); -PERI_CLK_SETUP (clks, ccu,BCM281XX_SLAVE_CCU_PWM , pwm); +PERI_CLK_SETUP (ccu,BCM281XX_SLAVE_CCU_UARTB , uartb); +PERI_CLK_SETUP (ccu,BCM281XX_SLAVE_CCU_UARTB2 , uartb2); +PERI_CLK_SETUP (ccu,BCM281XX_SLAVE_CCU_UARTB3 , uartb3); +PERI_CLK_SETUP (ccu,BCM281XX_SLAVE_CCU_UARTB4 , uartb4); +PERI_CLK_SETUP (ccu,BCM281XX_SLAVE_CCU_SSP0 , ssp0); +PERI_CLK_SETUP (ccu,BCM281XX_SLAVE_CCU_SSP2 , ssp2); +PERI_CLK_SETUP (ccu,BCM281XX_SLAVE_CCU_BSC1 , bsc1); +PERI_CLK_SETUP (ccu,BCM281XX_SLAVE_CCU_BSC2 , bsc2); +PERI_CLK_SETUP (ccu,BCM281XX_SLAVE_CCU_BSC3 , bsc3); +PERI_CLK_SETUP (ccu,BCM281XX_SLAVE_CCU_PWM , pwm);return 0 ; }
@@ -386,27 +354,29 @@ static int __init bcm281xx_slave_ccu_clks_setup(struct ccu_data *ccu)static void __init kona_dt_root_ccu_setup (struct device_node *node) { -kona_dt_ccu_setup (node, bcm281xx_root_ccu_clks_setup); +kona_dt_ccu_setup (&root_ccu_data, node, bcm281xx_root_ccu_clks_setup); }static void __init kona_dt_aon_ccu_setup (struct device_node *node) { -kona_dt_ccu_setup (node, bcm281xx_aon_ccu_clks_setup); +kona_dt_ccu_setup (&aon_ccu_data, node, bcm281xx_aon_ccu_clks_setup); }static void __init kona_dt_hub_ccu_setup (struct device_node *node) { -kona_dt_ccu_setup (node, bcm281xx_hub_ccu_clks_setup); +kona_dt_ccu_setup (&hub_ccu_data, node, bcm281xx_hub_ccu_clks_setup); }static void __init kona_dt_master_ccu_setup (struct device_node *node) { -kona_dt_ccu_setup (node, bcm281xx_master_ccu_clks_setup); +kona_dt_ccu_setup (&master_ccu_data, node, + bcm281xx_master_ccu_clks_setup); }static void __init kona_dt_slave_ccu_setup (struct device_node *node) { -kona_dt_ccu_setup (node, bcm281xx_slave_ccu_clks_setup); +kona_dt_ccu_setup (&slave_ccu_data, node, + bcm281xx_slave_ccu_clks_setup); } CLK_OF_DECLARE(bcm281xx_root_ccu, BCM281XX_DT_ROOT_CCU_COMPAT,
drivers/clk/bcm/clk-kona-setup.c +21 -26
89 lines not on this page · raw message
drivers/clk/bcm/clk-kona.c +2 -2
@@ -1018,13 +1018,13 @@ bool __init kona_ccu_init(struct ccu_data *ccu) {unsigned long flags;unsigned int which; -struct clk **clks = ccu->data.clks; +struct clk **clks = ccu->clk_data.clks;bool success = true; flags =ccu_lock (ccu);__ccu_write_enable (ccu); -for (which =0 ; which < ccu->data.clk_num; which++) { +for (which =0 ; which < ccu->clk_data.clk_num; which++) {struct kona_clk *bcm_clk;if (!clks[which])
drivers/clk/bcm/clk-kona.h +17 -4
@@ -85,11 +85,20 @@ struct ccu_data {bool write_enabled;/* write access is currently enabled */ struct list_head links;/* for ccu_list */ struct device_node *node; -struct clk_onecell_data data; +struct clk_onecell_data clk_data;const char *name;u32 range;/* byte range of address space */ }; +/* Initialization for common fields in a Kona ccu_data structure */ +#define KONA_CCU_COMMON (_prefix, _name, _ucase_name) \ + .name = #_name "_ccu", \ + .lock = __SPIN_LOCK_UNLOCKED(_name ## _ccu_data.lock), \ + .links = LIST_HEAD_INIT(_name ## _ccu_data.links), \ + .clk_data = { \ + .clk_num = _prefix ## _ ## _ucase_name ## _CCU_CLOCK_COUNT, \ + } +/* * Gating control and status is managed by a 32-bit gate register. *
@@ -390,8 +399,11 @@ extern struct clk_ops kona_peri_clk_ops;/* Help functions */ -#define PERI_CLK_SETUP (clks, ccu, id, name) \ - clks[id] = kona_clk_setup(ccu, #name, bcm_clk_peri, &name ## _data) +#define KONA_CLK_SETUP (_ccu, _type, _name) \ + kona_clk_setup((_ccu), #_name, bcm_clk_## _type, &_name ## _data) + +#define PERI_CLK_SETUP (_ccu, _id, _name) \ + (_ccu)->clk_data.clks[_id] = KONA_CLK_SETUP((_ccu), peri, _name)/* Externally visible functions */
@@ -402,7 +414,8 @@ extern u64 scaled_div_build(struct bcm_clk_div *div, u32 div_value,extern struct clk *kona_clk_setup (struct ccu_data *ccu,const char *name,enum bcm_clk_type type,void *data); -extern void __init kona_dt_ccu_setup (struct device_node *node, +extern void __init kona_dt_ccu_setup (struct ccu_data *ccu, +struct device_node *node,int (*ccu_clks_setup)(struct ccu_data *));extern bool __init kona_ccu_init (struct ccu_data *ccu);
Signature · 1 line
1.7.9.5
PATCH v2 5/12 clk: bcm281xx: define CCU clock data statically
In reply to Alex ElderRather than "manually" setting up each CCU's clock entries at run time, define a flexible array of generic Kona clock structures within the CCU structure itself. Each of these entries contains generic kona clock information (like its CCU pointer and clock framework initialization data). Each also has a pointer to a structure contianing clock type-dependent initialization data (like register definitions).
Since we'll iterate over these arrays we need to be sure they have slots for all potential clock index values. (E.g. for the root CCU we must have at least BCM281XX_ROOT_CCU_CLOCK_COUNT slots.) To ensure this we always define an extra entry and fill it using the special initializer LAST_KONA_CLK.
Just about everything we need to know about a clock can be defined statically. As a result, kona_clk_setup() can be changed to take just a kona_clk structure as its argument, and peri_clk_setup() can be simplified. With the information pre-defined we are also able to handle most clock setup genericially. We can do away with the CCU-specific callback functions that previously were needed to set up the entries in CCU's clock array.
Move the definition of the ccu_data structure down in "clk-kona.h" to avoid a forward dependency.
--- drivers/clk/bcm/clk-bcm281xx.c | 132 ++++++++++++++++++-------------------- drivers/clk/bcm/clk-kona-setup.c | 60 ++++++++--------- drivers/clk/bcm/clk-kona.h | 86 +++++++++++++------------ 3 files changed, 134 insertions(+), 144 deletions(-)
drivers/clk/bcm/clk-bcm281xx.c +64 -68
@@ -41,6 +41,11 @@ static struct peri_clk_data frac_1m_data = {static struct ccu_data root_ccu_data = {BCM281XX_CCU_COMMON (root,ROOT ), + .kona_clks = { + [BCM281XX_ROOT_CCU_FRAC_1M ] = +KONA_CLK (root, frac_1m, peri), + [BCM281XX_ROOT_CCU_CLOCK_COUNT ] =LAST_KONA_CLK , + }, };/* AON CCU */
@@ -74,6 +79,15 @@ static struct peri_clk_data pmu_bsc_var_data = {static struct ccu_data aon_ccu_data = {BCM281XX_CCU_COMMON (aon,AON ), + .kona_clks = { + [BCM281XX_AON_CCU_HUB_TIMER ] = +KONA_CLK (aon, hub_timer, peri), + [BCM281XX_AON_CCU_PMU_BSC ] = +KONA_CLK (aon, pmu_bsc, peri), + [BCM281XX_AON_CCU_PMU_BSC_VAR ] = +KONA_CLK (aon, pmu_bsc_var, peri), + [BCM281XX_AON_CCU_CLOCK_COUNT ] =LAST_KONA_CLK , + }, };/* Hub CCU */
@@ -88,6 +102,11 @@ static struct peri_clk_data tmon_1m_data = {static struct ccu_data hub_ccu_data = {BCM281XX_CCU_COMMON (hub,HUB ), + .kona_clks = { + [BCM281XX_HUB_CCU_TMON_1M ] = +KONA_CLK (hub, tmon_1m, peri), + [BCM281XX_HUB_CCU_CLOCK_COUNT ] =LAST_KONA_CLK , + }, };/* Master CCU */
@@ -175,6 +194,23 @@ static struct peri_clk_data hsic2_12m_data = {static struct ccu_data master_ccu_data = {BCM281XX_CCU_COMMON (master,MASTER ), + .kona_clks = { + [BCM281XX_MASTER_CCU_SDIO1 ] = +KONA_CLK (master, sdio1, peri), + [BCM281XX_MASTER_CCU_SDIO2 ] = +KONA_CLK (master, sdio2, peri), + [BCM281XX_MASTER_CCU_SDIO3 ] = +KONA_CLK (master, sdio3, peri), + [BCM281XX_MASTER_CCU_SDIO4 ] = +KONA_CLK (master, sdio4, peri), + [BCM281XX_MASTER_CCU_USB_IC ] = +KONA_CLK (master, usb_ic, peri), + [BCM281XX_MASTER_CCU_HSIC2_48M ] = +KONA_CLK (master, hsic2_48m, peri), + [BCM281XX_MASTER_CCU_HSIC2_12M ] = +KONA_CLK (master, hsic2_12m, peri), + [BCM281XX_MASTER_CCU_CLOCK_COUNT ] =LAST_KONA_CLK , + }, };/* Slave CCU */
@@ -287,96 +323,56 @@ static struct peri_clk_data pwm_data = {static struct ccu_data slave_ccu_data = {BCM281XX_CCU_COMMON (slave,SLAVE ), + .kona_clks = { + [BCM281XX_SLAVE_CCU_UARTB ] = +KONA_CLK (slave, uartb, peri), + [BCM281XX_SLAVE_CCU_UARTB2 ] = +KONA_CLK (slave, uartb2, peri), + [BCM281XX_SLAVE_CCU_UARTB3 ] = +KONA_CLK (slave, uartb3, peri), + [BCM281XX_SLAVE_CCU_UARTB4 ] = +KONA_CLK (slave, uartb4, peri), + [BCM281XX_SLAVE_CCU_SSP0 ] = +KONA_CLK (slave, ssp0, peri), + [BCM281XX_SLAVE_CCU_SSP2 ] = +KONA_CLK (slave, ssp2, peri), + [BCM281XX_SLAVE_CCU_BSC1 ] = +KONA_CLK (slave, bsc1, peri), + [BCM281XX_SLAVE_CCU_BSC2 ] = +KONA_CLK (slave, bsc2, peri), + [BCM281XX_SLAVE_CCU_BSC3 ] = +KONA_CLK (slave, bsc3, peri), + [BCM281XX_SLAVE_CCU_PWM ] = +KONA_CLK (slave, pwm, peri), + [BCM281XX_SLAVE_CCU_CLOCK_COUNT ] =LAST_KONA_CLK , + }, }; -/* -* CCU setup routines -* -* These are called from kona_dt_ccu_setup() to initialize the array -* of clocks provided by the CCU. Once allocated, the entries in -* the array are initialized by calling kona_clk_setup() with the -* initialization data for each clock. They return 0 if successful -* or an error code otherwise. -*/ -static int __init bcm281xx_root_ccu_clks_setup (struct ccu_data *ccu) -{ -PERI_CLK_SETUP (ccu,BCM281XX_ROOT_CCU_FRAC_1M , frac_1m); - -return 0 ; -} - -static int __init bcm281xx_aon_ccu_clks_setup (struct ccu_data *ccu) -{ -PERI_CLK_SETUP (ccu,BCM281XX_AON_CCU_HUB_TIMER , hub_timer); -PERI_CLK_SETUP (ccu,BCM281XX_AON_CCU_PMU_BSC , pmu_bsc); -PERI_CLK_SETUP (ccu,BCM281XX_AON_CCU_PMU_BSC_VAR , pmu_bsc_var); - -return 0 ; -} - -static int __init bcm281xx_hub_ccu_clks_setup (struct ccu_data *ccu) -{ -PERI_CLK_SETUP (ccu,BCM281XX_HUB_CCU_TMON_1M , tmon_1m); - -return 0 ; -} - -static int __init bcm281xx_master_ccu_clks_setup (struct ccu_data *ccu) -{ -PERI_CLK_SETUP (ccu,BCM281XX_MASTER_CCU_SDIO1 , sdio1); -PERI_CLK_SETUP (ccu,BCM281XX_MASTER_CCU_SDIO2 , sdio2); -PERI_CLK_SETUP (ccu,BCM281XX_MASTER_CCU_SDIO3 , sdio3); -PERI_CLK_SETUP (ccu,BCM281XX_MASTER_CCU_SDIO4 , sdio4); -PERI_CLK_SETUP (ccu,BCM281XX_MASTER_CCU_USB_IC , usb_ic); -PERI_CLK_SETUP (ccu,BCM281XX_MASTER_CCU_HSIC2_48M , hsic2_48m); -PERI_CLK_SETUP (ccu,BCM281XX_MASTER_CCU_HSIC2_12M , hsic2_12m); - -return 0 ; -} - -static int __init bcm281xx_slave_ccu_clks_setup (struct ccu_data *ccu) -{ -PERI_CLK_SETUP (ccu,BCM281XX_SLAVE_CCU_UARTB , uartb); -PERI_CLK_SETUP (ccu,BCM281XX_SLAVE_CCU_UARTB2 , uartb2); -PERI_CLK_SETUP (ccu,BCM281XX_SLAVE_CCU_UARTB3 , uartb3); -PERI_CLK_SETUP (ccu,BCM281XX_SLAVE_CCU_UARTB4 , uartb4); -PERI_CLK_SETUP (ccu,BCM281XX_SLAVE_CCU_SSP0 , ssp0); -PERI_CLK_SETUP (ccu,BCM281XX_SLAVE_CCU_SSP2 , ssp2); -PERI_CLK_SETUP (ccu,BCM281XX_SLAVE_CCU_BSC1 , bsc1); -PERI_CLK_SETUP (ccu,BCM281XX_SLAVE_CCU_BSC2 , bsc2); -PERI_CLK_SETUP (ccu,BCM281XX_SLAVE_CCU_BSC3 , bsc3); -PERI_CLK_SETUP (ccu,BCM281XX_SLAVE_CCU_PWM , pwm); - -return 0 ; -} -/* Device tree match table callback functions */ static void __init kona_dt_root_ccu_setup (struct device_node *node) { -kona_dt_ccu_setup (&root_ccu_data, node, bcm281xx_root_ccu_clks_setup); +kona_dt_ccu_setup (&root_ccu_data, node); }static void __init kona_dt_aon_ccu_setup (struct device_node *node) { -kona_dt_ccu_setup (&aon_ccu_data, node, bcm281xx_aon_ccu_clks_setup); +kona_dt_ccu_setup (&aon_ccu_data, node); }static void __init kona_dt_hub_ccu_setup (struct device_node *node) { -kona_dt_ccu_setup (&hub_ccu_data, node, bcm281xx_hub_ccu_clks_setup); +kona_dt_ccu_setup (&hub_ccu_data, node); }static void __init kona_dt_master_ccu_setup (struct device_node *node) { -kona_dt_ccu_setup (&master_ccu_data, node, - bcm281xx_master_ccu_clks_setup); +kona_dt_ccu_setup (&master_ccu_data, node); }static void __init kona_dt_slave_ccu_setup (struct device_node *node) { -kona_dt_ccu_setup (&slave_ccu_data, node, - bcm281xx_slave_ccu_clks_setup); +kona_dt_ccu_setup (&slave_ccu_data, node); } CLK_OF_DECLARE(bcm281xx_root_ccu, BCM281XX_DT_ROOT_CCU_COMPAT,
drivers/clk/bcm/clk-kona-setup.c +25 -35
116 lines not on this page · raw message
drivers/clk/bcm/clk-kona.h +45 -41
109 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH v2 6/12 clk: bcm281xx: add clock policy support
In reply to Alex ElderAdd support for CCU policy engine control, and also for setting the mask bits for bus clocks that require a policy change to get activated. This includes adding validity checking framework for CCUs, to validate the policy fields if defined.
--- drivers/clk/bcm/clk-kona-setup.c | 92 ++++++++++++++++++++++ drivers/clk/bcm/clk-kona.c | 155 ++++++++++++++++++++++++++++++++++++++ drivers/clk/bcm/clk-kona.h | 71 +++++++++++++++++ 3 files changed, 318 insertions(+)
drivers/clk/bcm/clk-kona-setup.c +92 -0
@@ -25,6 +25,31 @@ LIST_HEAD(ccu_list); /* The list of set up CCUs *//* Validity checking */ +static bool ccu_data_offsets_valid (struct ccu_data *ccu) +{ +struct ccu_policy *ccu_policy = &ccu->policy; +u32 limit; + + limit = ccu->range -sizeof (u32); + limit =round_down (limit,sizeof (u32)); +if (ccu_policy_exists (ccu_policy)) { +if (ccu_policy->enable.offset > limit) { +pr_err ("%s: bad policy enable offset for %s " +"(%u > %u)\n" , __func__, + ccu->name, ccu_policy->enable.offset, limit); +return false; + } +if (ccu_policy->control.offset > limit) { +pr_err ("%s: bad policy control offset for %s " +"(%u > %u)\n" , __func__, + ccu->name, ccu_policy->control.offset, limit); +return false; + } + } + +return true; +} +static bool clk_requires_trigger (struct kona_clk *bcm_clk) {struct peri_clk_data *peri = bcm_clk->peri;
@@ -54,6 +79,7 @@ static bool clk_requires_trigger(struct kona_clk *bcm_clk)static bool peri_clk_data_offsets_valid (struct kona_clk *bcm_clk) {struct peri_clk_data *peri; +struct bcm_clk_policy *policy;struct bcm_clk_gate *gate;struct bcm_clk_div *div;struct bcm_clk_sel *sel;
@@ -70,6 +96,15 @@ static bool peri_clk_data_offsets_valid(struct kona_clk *bcm_clk) limit = range -sizeof (u32); limit =round_down (limit,sizeof (u32)); + policy = &peri->policy; +if (policy_exists (policy)) { +if (policy->offset > limit) { +pr_err ("%s: bad policy offset for %s (%u > %u)\n" , + __func__, name, policy->offset, limit); +return false; + } + } + gate = &peri->gate;if (gate_exists (gate)) {if (gate->offset > limit) {
@@ -167,6 +202,36 @@ static bool bitfield_valid(u32 shift, u32 width, const char *field_name,return true; } +static bool +ccu_policy_valid (struct ccu_policy *ccu_policy,const char *ccu_name) +{ +struct bcm_lvm_en *enable = &ccu_policy->enable; +struct bcm_policy_ctl *control; + +if (!bit_posn_valid (enable->bit,"policy enable" , ccu_name)) +return false; + + control = &ccu_policy->control; +if (!bit_posn_valid (control->go_bit,"policy control GO" , ccu_name)) +return false; + +if (!bit_posn_valid (control->atl_bit,"policy control ATL" , ccu_name)) +return false; + +if (!bit_posn_valid (control->ac_bit,"policy control AC" , ccu_name)) +return false; + +return true; +} + +static bool policy_valid (struct bcm_clk_policy *policy,const char *clock_name) +{ +if (!bit_posn_valid (policy->bit,"policy" , clock_name)) +return false; + +return true; +} +/* * All gates, if defined, have a status bit, and for hardware-only * gates, that's it. Gates that can be software controlled also
@@ -311,6 +376,7 @@ static bool peri_clk_data_valid(struct kona_clk *bcm_clk) {struct peri_clk_data *peri; +struct bcm_clk_policy *policy;struct bcm_clk_gate *gate;struct bcm_clk_sel *sel;struct bcm_clk_div *div;
@@ -330,6 +396,11 @@ peri_clk_data_valid(struct kona_clk *bcm_clk) peri = bcm_clk->peri; name = bcm_clk->init_data.name; + + policy = &peri->policy; +if (policy_exists (policy) && !policy_valid (policy, name)) +return false; + gate = &peri->gate;if (gate_exists (gate) && !gate_valid (gate,"gate" , name))return false;
@@ -678,6 +749,21 @@ static void kona_ccu_teardown(struct ccu_data *ccu) ccu->base =NULL ; } +static bool ccu_data_valid (struct ccu_data *ccu) +{ +struct ccu_policy *ccu_policy; + +if (!ccu_data_offsets_valid (ccu)) +return false; + + ccu_policy = &ccu->policy; +if (ccu_policy_exists (ccu_policy)) +if (!ccu_policy_valid (ccu_policy, ccu->name)) +return false; + +return true; +} +/* * Set up a CCU. Call the provided ccu_clks_setup callback to * initialize the array of clocks provided by the CCU.
@@ -717,6 +803,12 @@ void __init kona_dt_ccu_setup(struct ccu_data *ccu, } ccu->range = (u32 )range; + +if (!ccu_data_valid (ccu)) { +pr_err ("%s: ccu data not valid for %s\n" , __func__, node->name); + goto out_err; + } + ccu->base =ioremap (res.start, ccu->range);if (!ccu->base) { pr_err("%s: unable to map CCU registers for %s\n", __func__,
drivers/clk/bcm/clk-kona.c +155 -0
173 lines not on this page · raw message
drivers/clk/bcm/clk-kona.h +71 -0
109 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH v2 7/12 clk: bcm281xx: add clock hysteresis support
In reply to Alex ElderAdd support for clock gate hysteresis control. For now, if it's defined for a clock, it's enabled.
--- drivers/clk/bcm/clk-kona-setup.c | 30 ++++++++++++++++++++++++++++++ drivers/clk/bcm/clk-kona.c | 33 +++++++++++++++++++++++++++++++++ drivers/clk/bcm/clk-kona.h | 19 +++++++++++++++++++ 3 files changed, 82 insertions(+)
drivers/clk/bcm/clk-kona-setup.c +30 -0
@@ -81,6 +81,7 @@ static bool peri_clk_data_offsets_valid(struct kona_clk *bcm_clk)struct peri_clk_data *peri;struct bcm_clk_policy *policy;struct bcm_clk_gate *gate; +struct bcm_clk_hyst *hyst;struct bcm_clk_div *div;struct bcm_clk_sel *sel;struct bcm_clk_trig *trig;
@@ -106,12 +107,25 @@ static bool peri_clk_data_offsets_valid(struct kona_clk *bcm_clk) } gate = &peri->gate; + hyst = &peri->hyst;if (gate_exists (gate)) {if (gate->offset > limit) {pr_err ("%s: bad gate offset for %s (%u > %u)\n" , __func__, name, gate->offset, limit);return false; } + +if (hyst_exists (hyst)) { +if (hyst->offset > limit) { +pr_err ("%s: bad hysteresis offset for %s " +"(%u > %u)\n" , __func__, + name, hyst->offset, limit); +return false; + } + } + }else if (hyst_exists (hyst)) { +pr_err ("%s: hysteresis but no gate for %s\n" , __func__, name); +return false; } div = &peri->div;
@@ -261,6 +275,17 @@ static bool gate_valid(struct bcm_clk_gate *gate, const char *field_name,return true; } +static bool hyst_valid (struct bcm_clk_hyst *hyst,const char *clock_name) +{ +if (!bit_posn_valid (hyst->en_bit,"hysteresis enable" , clock_name)) +return false; + +if (!bit_posn_valid (hyst->val_bit,"hysteresis value" , clock_name)) +return false; + +return true; +} +/* * A selector bitfield must be valid. Its parent_sel array must * also be reasonable for the field.
@@ -378,6 +403,7 @@ peri_clk_data_valid(struct kona_clk *bcm_clk)struct peri_clk_data *peri;struct bcm_clk_policy *policy;struct bcm_clk_gate *gate; +struct bcm_clk_hyst *hyst;struct bcm_clk_sel *sel;struct bcm_clk_div *div;struct bcm_clk_div *pre_div;
@@ -405,6 +431,10 @@ peri_clk_data_valid(struct kona_clk *bcm_clk)if (gate_exists (gate) && !gate_valid (gate,"gate" , name))return false; + hyst = &peri->hyst; +if (hyst_exists (hyst) && !hyst_valid (hyst, name)) +return false; + sel = &peri->sel;if (selector_exists (sel)) {if (!sel_valid (sel,"selector" , name))
drivers/clk/bcm/clk-kona.c +33 -0
@@ -527,6 +527,35 @@ static int clk_gate(struct ccu_data *ccu, const char *name,return -EIO ; } +/* Hysteresis operations */ + +/* +* If a clock gate requires a turn-off delay it will have +* "hysteresis" register bits defined. The first, if set, enables +* the delay; and if enabled, the second bit determines whether the +* delay is "low" or "high" (1 means high). For now, if it's +* defined for a clock, we set it. +*/ +static bool hyst_init (struct ccu_data *ccu,struct bcm_clk_hyst *hyst) +{ +u32 offset; +u32 reg_val; +u32 mask; + +if (!hyst_exists (hyst)) +return true; + + offset = hyst->offset; + mask = (u32 )1 << hyst->en_bit; + mask |= (u32 )1 << hyst->val_bit; + + reg_val =__ccu_read (ccu, offset); + reg_val |= mask; +__ccu_write (ccu, offset, reg_val); + +return true; +} +/* Trigger operations */ /*
@@ -1129,6 +1158,10 @@ static bool __peri_clk_init(struct kona_clk *bcm_clk)pr_err ("%s: error initializing gate for %s\n" , __func__, name);return false; } +if (!hyst_init (ccu, &peri->hyst)) { +pr_err ("%s: error initializing hyst for %s\n" , __func__, name); +return false; + }if (!div_init (ccu, &peri->gate, &peri->div, &peri->trig)) {pr_err ("%s: error initializing divider for %s\n" , __func__, name);
drivers/clk/bcm/clk-kona.h +19 -0
@@ -60,6 +60,8 @@#define gate_flip_enabled (gate) FLAG_FLIP(gate, GATE, ENABLED) +#define hyst_exists (hyst) ((hyst)->offset != 0) +#define divider_exists (div) FLAG_TEST(div, DIV, EXISTS)#define divider_is_fixed (div) FLAG_TEST(div, DIV, FIXED)#define divider_has_fraction (div) (!divider_is_fixed(div) && \
@@ -205,6 +207,22 @@ struct bcm_clk_gate { .flags = FLAG(GATE, HW)|FLAG(GATE, EXISTS), \ } +/* Gate hysteresis for clocks */ +struct bcm_clk_hyst { +u32 offset;/* hyst register offset (normally CLKGATE) */ +u32 en_bit;/* bit used to enable hysteresis */ +u32 val_bit;/* if enabled: 0 = low delay; 1 = high delay */ +}; + +/* Hysteresis initialization macro */ + +#define HYST (_offset, _en_bit, _val_bit) \ + { \ + .offset = (_offset), \ + .en_bit = (_en_bit), \ + .val_bit = (_val_bit), \ + } +/* * Each clock can have zero, one, or two dividers which change the * output rate of the clock. Each divider can be either fixed or
@@ -372,6 +390,7 @@ struct bcm_clk_trig {struct peri_clk_data {struct bcm_clk_policy policy;struct bcm_clk_gate gate; +struct bcm_clk_hyst hyst;struct bcm_clk_trig pre_trig;struct bcm_clk_div pre_div;struct bcm_clk_trig trig;
Signature · 1 line
1.7.9.5
PATCH v2 8/12 clk: bcm281xx: add an initialized flag
In reply to Alex ElderAdd a flag that tracks whether a clock has already been initialized. This will be used by the next patch to avoid initializing a clock more than once when it's listed as a prerequisite.
--- drivers/clk/bcm/clk-kona.c | 16 ++++++++++++++-- drivers/clk/bcm/clk-kona.h | 7 +++++++ 2 files changed, 21 insertions(+), 2 deletions(-)
drivers/clk/bcm/clk-kona.c +14 -2
@@ -27,6 +27,9 @@#define CCU_ACCESS_PASSWORD 0xA5A500#define CLK_GATE_DELAY_LOOP 2000 +#define clk_is_initialized (_clk) FLAG_TEST((_clk), KONA, INITIALIZED) +#define clk_set_initialized (_clk) FLAG_SET((_clk), KONA, INITIALIZED) +/* Bitfield operations */ /* Produces a mask of set bits covering a range of a 32-bit value */
@@ -1192,13 +1195,22 @@ static bool __peri_clk_init(struct kona_clk *bcm_clk)static bool __kona_clk_init (struct kona_clk *bcm_clk) { +bool ret = false; + +if (clk_is_initialized (bcm_clk)) +return true; +switch (bcm_clk->type) {case bcm_clk_peri: -return __peri_clk_init (bcm_clk); + ret =__peri_clk_init (bcm_clk); +break ;default :BUG (); } -return -EINVAL ; +if (ret) +clk_set_initialized (bcm_clk); + +return ret; }/* Set a CCU and all its clocks into their desired initial state */
drivers/clk/bcm/clk-kona.h +7 -0
@@ -406,6 +406,7 @@ struct kona_clk {struct clk_init_data init_data;/* includes name of this clock */ struct ccu_data *ccu;/* ccu this clock is associated with */ enum bcm_clk_type type; +u32 flags;/* BCM_CLK_KONA_FLAGS_* below */ union {void *data;struct peri_clk_data *peri;
@@ -414,6 +415,12 @@ struct kona_clk {#define to_kona_clk (_hw) \ container_of(_hw, struct kona_clk, hw) +/* +* Kona clock flags: +* INITIALIZED clock has been initialized already +*/ +#define BCM_CLK_KONA_FLAGS_INITIALIZED ((u32)1 << 0)/* Clock initialized */ +/* Initialization macro for an entry in a CCU's kona_clks[] array. */ #define KONA_CLK (_ccu_name, _clk_name, _type) \ { \
Signature · 1 line
1.7.9.5
PATCH v2 9/12 clk: bcm281xx: implement prerequisite clocks
In reply to Alex ElderAllow a clock to specify a "prerequisite" clock. The prerequisite clock must be initialized before the clock that depends on it. A prerequisite clock is defined initially by its name; as that clock gets initialized the name gets replaced with a pointer to its clock structure pointer. In order to allow getting a reference to a clock by its name we call clkdev_add() for each clock as it gets set up. A new clk_lookup structure is added to the kona_clk type for this purpose.
Rework the KONA_CLK() macro, and define a new KONA_CLK_PREREQ() variant that allows a prerequisite clock to be specified.
There exist clocks that could specify more than one prequisite, but almost all clocks only ever use one. We can add support for more than one if we find we need it at some point.
--- drivers/clk/bcm/clk-kona-setup.c | 16 ++++++++++---- drivers/clk/bcm/clk-kona.c | 45 ++++++++++++++++++++++++++++++++++++++ drivers/clk/bcm/clk-kona.h | 20 ++++++++++++++--- 3 files changed, 74 insertions(+), 7 deletions(-)
drivers/clk/bcm/clk-kona-setup.c +12 -4
@@ -685,6 +685,9 @@ peri_clk_setup(struct peri_clk_data *data, struct clk_init_data *init_data)static void bcm_clk_teardown (struct kona_clk *bcm_clk) { +/* There is no function defined for this (yet) */ +/* clkdev_remove(&bcm_clk->cl); */ +switch (bcm_clk->type) {case bcm_clk_peri:peri_clk_teardown (bcm_clk->data, &bcm_clk->init_data);
@@ -718,6 +721,7 @@ static void kona_clk_teardown(struct clk *clk)struct clk *kona_clk_setup (struct kona_clk *bcm_clk) {struct clk_init_data *init_data = &bcm_clk->init_data; +const char *name = init_data->name;struct clk *clk =NULL ;switch (bcm_clk->type) {
@@ -727,14 +731,13 @@ struct clk *kona_clk_setup(struct kona_clk *bcm_clk)break ;default :pr_err ("%s: clock type %d invalid for %s\n" , __func__, - (int )bcm_clk->type, init_data->name); + (int )bcm_clk->type, name);return NULL ; }/* Make sure everything makes sense before we set it up */ if (!kona_clk_valid (bcm_clk)) { -pr_err ("%s: clock data invalid for %s\n" , __func__, - init_data->name); +pr_err ("%s: clock data invalid for %s\n" , __func__, name); goto out_teardown; }
@@ -742,11 +745,16 @@ struct clk *kona_clk_setup(struct kona_clk *bcm_clk) clk =clk_register (NULL , &bcm_clk->hw);if (IS_ERR (clk)) {pr_err ("%s: error registering clock %s (%ld)\n" , __func__, - init_data->name,PTR_ERR (clk)); + name,PTR_ERR (clk)); goto out_teardown; }BUG_ON (!clk); +/* Make it so we can look the clock up using clk_find() */ + bcm_clk->cl.con_id = name; + bcm_clk->cl.clk = clk; +clkdev_add (&bcm_clk->cl); +return clk; out_teardown:bcm_clk_teardown (bcm_clk);
drivers/clk/bcm/clk-kona.c +45 -0
57 lines not on this page · raw message
drivers/clk/bcm/clk-kona.h +17 -3
@@ -22,6 +22,8 @@#include <linux/device.h> #include <linux/of.h> #include <linux/clk-provider.h> +#include <linux/clkdev.h> +#include <linux/debugfs.h> #define BILLION 1000000000
@@ -407,6 +409,11 @@ struct kona_clk {struct ccu_data *ccu;/* ccu this clock is associated with */ enum bcm_clk_type type;u32 flags;/* BCM_CLK_KONA_FLAGS_* below */ +struct clk_lookup cl; +union { +const char *prereq; +struct clk *prereq_clk; + };union {void *data;struct peri_clk_data *peri;
@@ -422,15 +429,22 @@ struct kona_clk {#define BCM_CLK_KONA_FLAGS_INITIALIZED ((u32)1 << 0)/* Clock initialized */ /* Initialization macro for an entry in a CCU's kona_clks[] array. */ -#define KONA_CLK (_ccu_name, _clk_name, _type) \ - { \ +#define ___KONA_CLK_COMMON (_ccu_name, _clk_name, _type) \ .init_data = { \ .name = #_clk_name, \ .ops = &kona_ ## _type ## _clk_ops, \ }, \ .ccu = &_ccu_name ## _ccu_data, \ .type = bcm_clk_ ## _type, \ - .data = &_clk_name ## _data, \ + .data = &_clk_name ## _data +#define KONA_CLK_PREREQ (_ccu_name, _clk_name, _type, _prereq) \ + { \ + .prereq = #_prereq, \ + ___KONA_CLK_COMMON(_ccu_name, _clk_name, _type), \ + } +#define KONA_CLK (_ccu_name, _clk_name, _type) \ + { \ + ___KONA_CLK_COMMON(_ccu_name, _clk_name, _type), \ }#define LAST_KONA_CLK { .type = bcm_clk_none }
Signature · 1 line
1.7.9.5
PATCH v2 10/12 clk: bcm281xx: add bus clock support
In reply to Alex ElderAdd bus clock support. A bus clock has a subset of the components present in a peripheral clock (again, all optional): a gate; CCU policy management bits; and if needed, bits to control hysteresis.
--- drivers/clk/bcm/clk-kona-setup.c | 96 ++++++++++++++++++++++++++++++++++++-- drivers/clk/bcm/clk-kona.c | 58 +++++++++++++++++++++++ drivers/clk/bcm/clk-kona.h | 8 ++++ 3 files changed, 159 insertions(+), 3 deletions(-)
drivers/clk/bcm/clk-kona-setup.c +93 -3
@@ -76,6 +76,56 @@ static bool clk_requires_trigger(struct kona_clk *bcm_clk)return divider_exists (div) && !divider_is_fixed (div); } +static bool bus_clk_data_offsets_valid (struct kona_clk *bcm_clk) +{ +struct bus_clk_data *bus; +struct bcm_clk_policy *policy; +struct bcm_clk_gate *gate; +struct bcm_clk_hyst *hyst; +const char *name; +u32 limit; + +BUG_ON (bcm_clk->type != bcm_clk_bus); + bus = bcm_clk->bus; + name = bcm_clk->init_data.name; + + limit = bcm_clk->ccu->range -sizeof (u32); + limit =round_down (limit,sizeof (u32)); + + policy = &bus->policy; +if (policy_exists (policy)) { +if (policy->offset > limit) { +pr_err ("%s: bad policy offset for %s (%u > %u)\n" , + __func__, name, policy->offset, limit); +return false; + } + } + + gate = &bus->gate; + hyst = &bus->hyst; +if (gate_exists (gate)) { +if (gate->offset > limit) { +pr_err ("%s: bad gate offset for %s (%u > %u)\n" , + __func__, name, gate->offset, limit); +return false; + } +if (hyst_exists (hyst)) { +if (hyst->offset > limit) { +pr_err ("%s: bad hysteresis offset for %s " +"(%u > %u)\n" , __func__, + name, hyst->offset, limit); +return false; + } + } + }else if (hyst_exists (hyst)) { +pr_err ("%s: hysteresis but no gate for %s\n" , __func__, name); +return false; + } + + +return true; +} +static bool peri_clk_data_offsets_valid (struct kona_clk *bcm_clk) {struct peri_clk_data *peri;
@@ -86,15 +136,13 @@ static bool peri_clk_data_offsets_valid(struct kona_clk *bcm_clk)struct bcm_clk_sel *sel;struct bcm_clk_trig *trig;const char *name; -u32 range;u32 limit;BUG_ON (bcm_clk->type != bcm_clk_peri); peri = bcm_clk->peri; name = bcm_clk->init_data.name; - range = bcm_clk->ccu->range; - limit = range -sizeof (u32); + limit = bcm_clk->ccu->range -sizeof (u32); limit =round_down (limit,sizeof (u32)); policy = &peri->policy;
@@ -396,6 +444,23 @@ static bool trig_valid(struct bcm_clk_trig *trig, const char *field_name,return bit_posn_valid (trig->bit, field_name, clock_name); } +/* Determine whether the set of bus clock registers are valid. */ +static bool +bus_clk_data_valid (struct kona_clk *bcm_clk) +{ +struct bcm_clk_gate *gate; + +BUG_ON (bcm_clk->type != bcm_clk_bus); +if (!bus_clk_data_offsets_valid (bcm_clk)) +return false; + + gate = &bcm_clk->bus->gate; +if (!gate_exists (gate)) +return true; + +return gate_valid (gate,"gate" , bcm_clk->init_data.name); +} +/* Determine whether the set of peripheral clock registers are valid. */ static bool peri_clk_data_valid (struct kona_clk *bcm_clk)
@@ -493,6 +558,10 @@ peri_clk_data_valid(struct kona_clk *bcm_clk)static bool kona_clk_valid (struct kona_clk *bcm_clk) {switch (bcm_clk->type) { +case bcm_clk_bus: +if (!bus_clk_data_valid (bcm_clk)) +return false; +break ;case bcm_clk_peri:if (!peri_clk_data_valid (bcm_clk))return false;
@@ -663,6 +732,20 @@ static void clk_sel_teardown(struct bcm_clk_sel *sel, init_data->parent_names =NULL ; } +static void bus_clk_teardown (struct bus_clk_data *data, +struct clk_init_data *init_data) +{ +/* Nothing to do */ +} + +static int +bus_clk_setup (struct bus_clk_data *data,struct clk_init_data *init_data) +{ + init_data->flags =CLK_IGNORE_UNUSED ; + +return 0 ; +} +static void peri_clk_teardown (struct peri_clk_data *data,struct clk_init_data *init_data) {
@@ -689,6 +772,9 @@ static void bcm_clk_teardown(struct kona_clk *bcm_clk)/* clkdev_remove(&bcm_clk->cl); */ switch (bcm_clk->type) { +case bcm_clk_bus: +bus_clk_teardown (bcm_clk->data, &bcm_clk->init_data); +break ;case bcm_clk_peri:peri_clk_teardown (bcm_clk->data, &bcm_clk->init_data);break ;
@@ -725,6 +811,10 @@ struct clk *kona_clk_setup(struct kona_clk *bcm_clk)struct clk *clk =NULL ;switch (bcm_clk->type) { +case bcm_clk_bus: +if (bus_clk_setup (bcm_clk->data, init_data)) +return NULL ; +break ;case bcm_clk_peri:if (peri_clk_setup (bcm_clk->data, init_data))return NULL ;
drivers/clk/bcm/clk-kona.c +58 -0
76 lines not on this page · raw message
drivers/clk/bcm/clk-kona.h +8 -0
@@ -389,6 +389,12 @@ struct bcm_clk_trig { .flags = FLAG(TRIG, EXISTS), \ } +struct bus_clk_data { +struct bcm_clk_policy policy; +struct bcm_clk_gate gate; +struct bcm_clk_hyst hyst; +}; +struct peri_clk_data {struct bcm_clk_policy policy;struct bcm_clk_gate gate;
@@ -416,6 +422,7 @@ struct kona_clk { };union {void *data; +struct bus_clk_data *bus;struct peri_clk_data *peri; }; };
@@ -520,6 +527,7 @@ struct ccu_data {/* Exported globals */ +extern struct clk_ops kona_bus_clk_ops;extern struct clk_ops kona_peri_clk_ops;/* Externally visible functions */
Signature · 1 line
1.7.9.5
PATCH v2 11/12 clk: bcm281xx: define a bus clock
In reply to Alex ElderDefine the bus clock "bsc3_apb". This bus clock has to be managed using the CCU policy mechanism, so add the definitions required for that to the clock and its CCU.
This one bus clock in particular is defined because it is needed by peripheral clock "bsc3". Our boot loader does not properly activate "bsc3_apb", and as a result, "bsc3" isn't able to function properly. With "bsc3_apb" specified as a prerequisite clock for "bsc3", the latter works correctly.
For now only this one bus clock is defined, because it allows correct operation of "bsc3". Others can be added later as needed (and this patch serves to show how that's done).
--- drivers/clk/bcm/clk-bcm281xx.c | 13 ++++++++++++- include/dt-bindings/clock/bcm281xx.h | 3 ++- 2 files changed, 14 insertions(+), 2 deletions(-)
drivers/clk/bcm/clk-bcm281xx.c +12 -1
@@ -321,8 +321,17 @@ static struct peri_clk_data pwm_data = { .trig = TRIGGER(0x0afc, 15), }; +static struct bus_clk_data bsc3_apb_data = { + .policy =POLICY (0x0048 ,4 ), + .gate =HW_SW_GATE (0x0484 ,16 ,0 ,1 ), +}; +static struct ccu_data slave_ccu_data = {BCM281XX_CCU_COMMON (slave,SLAVE ), + .policy = { + .enable =CCU_LVM_EN (0x0034 ,0 ), + .control =CCU_POLICY_CTL (0x000c ,0 ,1 ,2 ), + }, .kona_clks = { [BCM281XX_SLAVE_CCU_UARTB ] =KONA_CLK (slave, uartb, peri),
@@ -341,9 +350,11 @@ static struct ccu_data slave_ccu_data = { [BCM281XX_SLAVE_CCU_BSC2] = KONA_CLK(slave, bsc2, peri), [BCM281XX_SLAVE_CCU_BSC3 ] = - KONA_CLK(slave, bsc3, peri), + KONA_CLK_PREREQ(slave, bsc3, peri, bsc3_apb), [BCM281XX_SLAVE_CCU_PWM ] = KONA_CLK(slave, pwm, peri), + [BCM281XX_SLAVE_CCU_BSC3_APB ] = + KONA_CLK(slave, bsc3_apb, bus), [BCM281XX_SLAVE_CCU_CLOCK_COUNT] = LAST_KONA_CLK, }, };
include/dt-bindings/clock/bcm281xx.h +2 -1
@@ -60,6 +60,7 @@#define BCM281XX_SLAVE_CCU_BSC2 7#define BCM281XX_SLAVE_CCU_BSC3 8#define BCM281XX_SLAVE_CCU_PWM 9 -#define BCM281XX_SLAVE_CCU_CLOCK_COUNT 10 +#define BCM281XX_SLAVE_CCU_BSC3_APB 10 +#define BCM281XX_SLAVE_CCU_CLOCK_COUNT 11#endif /* _CLOCK_BCM281XX_H */
Signature · 1 line
1.7.9.5
PATCH v2 12/12 ARM: dts: add bus clock bsc3_apb for bcm281xx
In reply to Alex ElderAdd the bus clock named "bsc3_apb" to the list of those provided by the slave CCU.
--- arch/arm/boot/dts/bcm11351.dtsi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm/boot/dts/bcm11351.dtsi +2 -1
@@ -247,7 +247,8 @@ "bsc1", "bsc2", "bsc3", - "pwm"; + "pwm", + "bsc3_apb"; }; ref_1m_clk: ref_1m {
Signature · 1 line
1.7.9.5
Mike, I've given up on getting these in for 3.15, but I want to be sure they're considered ASAP for 3.16.
You indicated you had questions about the prerequisite clocks I proposed. What I'd like to do is resend only the first 7 patches of this series, leaving the patches that implement prerequisite clock functionality to work out separately.
In that case there is no special device tree dependency that would require the patches be taken through arm-soc.
They do, however, still depend on the previous work that was queued through arm-soc, so they don't apply on your current clk-next branch.
How would you like me to handle this?
Thanks.
-Alex
http://git.linaro.org/landing-teams/working/broadcom/kernel.git
Branch review/bcm-clk-next-v2
bc38518 clk: bcm281xx: add clock hysteresis support 84f8738 clk: bcm281xx: add clock policy support 825179f clk: bcm281xx: define CCU clock data statically 1d2fbb7 clk: bcm281xx: initialize CCU structures statically d362801 clk: bcm281xx: change some symbol names bcacfe5 clk: bcm281xx: use init_data.name for clock name 270dc8f clk: bcm281xx: warn if ccu_wait_bit() fails
(based on)
c771cfb ARM: dts: bcm281xx: define real clocks 14a091d clk: bcm281xx: don't disable unused peripheral clocks 44bc5c4 clk: bcm281xx: add initial clock framework support dcb99fd Linux 3.14-rc7
Quoted 66 lines · Alex Elder
This series includes updates for the bcm281xx clock code for 3.15. I had held off posting this until the code on which this is based was queued for 3.14, and it now has been:
https://github.com/broadcom/mach-bcm/
Branch armsoc/for-3.15/drivers
clk: bcm281xx: don't disable unused peripheral clocks
clk: bcm281xx: add initial clock framework support
followed by:
(same repository)
Branch armsoc/for-3.15/dt
ARM: dts: bcm281xx: define real clocksThe patches in this series are available here:
http://git.linaro.org/landing-teams/working/broadcom/kernel.git
Branch review/bcm-clk-next-v2I've grouped them, and offer a little explanation of each of the groups below.
Note: The final (DT) patch *must* be committed last.
The first version of this series had a patch from the middle of the series that shouldn't have been there, and it has been removed in this version (that patch affected mach-bcm, not clk). I also split the final patch into two, with the second one isolating the change to a device tree file.
-Alex
Alex Elder (12):
clk: bcm281xx: warn ifccu_wait_bit()fails
clk: bcm281xx: use init_data.name for clock name
clk: bcm281xx: change some symbol names
Three small code improvements.clk: bcm281xx: initialize CCU structures statically
clk: bcm281xx: define CCU clock data statically
Rearrange the way CCUs and the clocks they provide are defined, so that they're defined statically to the extent possible rather than allocating and initializing things at runtime.clk: bcm281xx: add clock policy support
clk: bcm281xx: add clock hysteresis support
clk: bcm281xx: add an initialized flag
clk: bcm281xx: implement prerequisite clocks
clk: bcm281xx: add bus clock support
clk: bcm281xx: define a bus clock
Add a few new features, ultimately for the purpose of adding support for another type of Kona clock. Currently only peripheral clocks are supported; this adds the ability to define and control bus clocks. In addition, support is added for clocks to identify a prerequisite clock; a clock won't be initialized until after its prerequisite has been.ARM: dts: add bus clock
bsc3_apbfor bcm281xx
Add the new bus clock to the device tree.arch/arm/boot/dts/bcm11351.dtsi | 3 +- drivers/clk/bcm/clk-bcm281xx.c | 254 ++++++++++++-------------- drivers/clk/bcm/clk-kona-setup.c | 331 +++++++++++++++++++++++++++------- drivers/clk/bcm/clk-kona.c | 331 ++++++++++++++++++++++++++++++++-- drivers/clk/bcm/clk-kona.h | 189 ++++++++++++++++--- include/dt-bindings/clock/bcm281xx.h | 3 +- 6 files changed, 872 insertions(+), 239 deletions(-)