clk: bcm: prerequisite and bus clock support
Subsystems (5)
v3 cover clk: bcm: prerequisite and bus clock support
Currently only peripheral clocks are supported for Broadcom platforms that use Kona style CCUs for clocking. This series adds support for bus clocks as well.
One motivation for doing this is that there exist peripheral clocks that cannot be configured without having first initialized a related bus clock. Adding bus clock support allows such peripheral clocks to be usable.
This also imposes a new requirement, however--that the bus clock be initialized *before* the clock that depends on it. For this, we define the notion of a "prerequisite" clock. If a clock has a prerequisite specified, that prequisite clock will be initialized first. For now this only affects startup-time initialization.
These patches are based on Mike Turquette's current "clk-next" branch.
4c8f806 Merge branch 'clk-fixes' into clk-next
They are available here:
http://git.linaro.org/landing-teams/working/broadcom/kernel.git
Branch review/bcm-bus-clk-v3
-Alex
Version history:
v3: - Deleted unused clk_lookup field from struct kona_clk
- Now use term "initialized" rather than "enabled"
v2: - Added field "p" to the previously unnamed prereq union.
Alex Elder (5):
clk: bcm281xx: add an initialized flag
clk: bcm281xx: implement prerequisite clocks
clk: bcm281xx: add bus clock support
clk: bcm281xx: define a bus clock
ARM: dts: add bus clock bsc3_apb for bcm281xx
arch/arm/boot/dts/bcm11351.dtsi | 3 +- drivers/clk/bcm/clk-bcm281xx.c | 13 +++- drivers/clk/bcm/clk-kona-setup.c | 96 +++++++++++++++++++++++++++- drivers/clk/bcm/clk-kona.c | 120 ++++++++++++++++++++++++++++++++++- drivers/clk/bcm/clk-kona.h | 34 +++++++++- include/dt-bindings/clock/bcm281xx.h | 3 +- 6 files changed, 258 insertions(+), 11 deletions(-)
Signature · 1 line
1.9.1
PATCH v3 1/5 clk: bcm281xx: add an initialized flag
Add 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 | 17 +++++++++++++++-- drivers/clk/bcm/clk-kona.h | 7 +++++++ 2 files changed, 22 insertions(+), 2 deletions(-)
drivers/clk/bcm/clk-kona.c +15 -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 */
@@ -1246,13 +1249,23 @@ static bool __peri_clk_init(struct kona_clk *bcm_clk)static bool __kona_clk_init (struct kona_clk *bcm_clk) { +bool ret; + +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 : + ret = false;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.9.1
PATCH v3 2/5 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.
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.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ drivers/clk/bcm/clk-kona.h | 19 ++++++++++++++++--- 2 files changed, 61 insertions(+), 3 deletions(-)
drivers/clk/bcm/clk-kona.c +45 -0
@@ -1247,6 +1247,48 @@ static bool __peri_clk_init(struct kona_clk *bcm_clk)return true; } +static bool __kona_clk_init (struct kona_clk *bcm_clk); +static bool __kona_prereq_init (struct kona_clk *bcm_clk) +{ +struct clk *clk; +struct clk_hw *hw; +struct kona_clk *prereq; + +BUG_ON (clk_is_initialized (bcm_clk)); + +if (!bcm_clk->p.prereq) +return true; + + clk =clk_get (NULL , bcm_clk->p.prereq); +if (IS_ERR (clk)) { +pr_err ("%s: unable to get prereq clock %s for %s\n" , + __func__, bcm_clk->p.prereq, bcm_clk->init_data.name); +return false; + } + hw =__clk_get_hw (clk); +if (!hw) { +pr_err ("%s: null hw pointer for clock %s\n" , __func__, + bcm_clk->init_data.name); +return false; + } + prereq =to_kona_clk (hw); +if (prereq->ccu != bcm_clk->ccu) { +pr_err ("%s: prereq clock %s CCU different for clock %s\n" , + __func__, bcm_clk->p.prereq, bcm_clk->init_data.name); +return false; + } + +/* Initialize the prerequisite clock first */ +if (!__kona_clk_init (prereq)) { +pr_err ("%s: failed to init prereq %s for clock %s\n" , + __func__, bcm_clk->p.prereq, bcm_clk->init_data.name); +return false; + } + bcm_clk->p.prereq_clk = clk; + +return true; +} +static bool __kona_clk_init (struct kona_clk *bcm_clk) {bool ret;
@@ -1254,6 +1296,9 @@ static bool __kona_clk_init(struct kona_clk *bcm_clk)if (clk_is_initialized (bcm_clk))return true; +if (!__kona_prereq_init (bcm_clk)) +return false; +switch (bcm_clk->type) {case bcm_clk_peri: ret =__peri_clk_init (bcm_clk);
drivers/clk/bcm/clk-kona.h +16 -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
@@ -408,6 +410,10 @@ struct kona_clk {enum bcm_clk_type type;u32 flags;/* BCM_CLK_KONA_FLAGS_* below */ union { +const char *prereq; +struct clk *prereq_clk; + } p; +union {void *data;struct peri_clk_data *peri; } u;
@@ -422,15 +428,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, \ - .u.data = &_clk_name ## _data, \ + .u.data = &_clk_name ## _data +#define KONA_CLK_PREREQ (_ccu_name, _clk_name, _type, _prereq) \ + { \ + .p.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.9.1
PATCH v3 3/5 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->u.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->u.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;
@@ -397,6 +445,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->u.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)
@@ -494,6 +559,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;
@@ -664,6 +733,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) {
@@ -687,6 +770,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) {switch (bcm_clk->type) { +case bcm_clk_bus: +bus_clk_teardown (bcm_clk->u.data, &bcm_clk->init_data); +break ;case bcm_clk_peri:peri_clk_teardown (bcm_clk->u.data, &bcm_clk->init_data);break ;
@@ -722,6 +808,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->u.data, init_data)) +return NULL ; +break ;case bcm_clk_peri:if (peri_clk_setup (bcm_clk->u.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;
@@ -415,6 +421,7 @@ struct kona_clk { } p;union {void *data; +struct bus_clk_data *bus;struct peri_clk_data *peri; } u; };
@@ -519,6 +526,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.9.1
PATCH v3 4/5 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
@@ -309,8 +309,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),
@@ -329,9 +338,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
@@ -72,6 +72,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.9.1
PATCH v3 5/5 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.9.1