1 From 05cae664e29e510111cf24f2beb1c31cba09bcce Mon Sep 17 00:00:00 2001
2 From: Phil Elwell <phil@raspberrypi.org>
3 Date: Mon, 13 Feb 2017 17:20:08 +0000
4 Subject: [PATCH] clk-bcm2835: Add claim-clocks property
6 The claim-clocks property can be used to prevent PLLs and dividers
7 from being marked as critical. It contains a vector of clock IDs,
8 as defined by dt-bindings/clock/bcm2835.h.
10 Use this mechanism to claim PLLD_DSI0, PLLD_DSI1, PLLH_AUX and
11 PLLH_PIX for the vc4_kms_v3d driver.
13 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
15 drivers/clk/bcm/clk-bcm2835.c | 45 ++++++++++++++++++++++++++++++++---
16 1 file changed, 42 insertions(+), 3 deletions(-)
18 --- a/drivers/clk/bcm/clk-bcm2835.c
19 +++ b/drivers/clk/bcm/clk-bcm2835.c
20 @@ -1312,6 +1312,8 @@ static const struct clk_ops bcm2835_vpu_
21 .debug_init = bcm2835_clock_debug_init,
24 +static bool bcm2835_clk_is_claimed(const char *name);
26 static struct clk_hw *bcm2835_register_pll(struct bcm2835_cprman *cprman,
29 @@ -1329,6 +1331,9 @@ static struct clk_hw *bcm2835_register_p
30 init.ops = &bcm2835_pll_clk_ops;
31 init.flags = pll_data->flags | CLK_IGNORE_UNUSED;
33 + if (!bcm2835_clk_is_claimed(pll_data->name))
34 + init.flags |= CLK_IS_CRITICAL;
36 pll = kzalloc(sizeof(*pll), GFP_KERNEL);
39 @@ -1384,9 +1389,11 @@ bcm2835_register_pll_divider(struct bcm2
40 divider->div.hw.init = &init;
41 divider->div.table = NULL;
43 - if (!(cprman_read(cprman, data->cm_reg) & data->hold_mask)) {
44 - init.flags |= CLK_IS_CRITICAL;
45 - divider->div.flags |= CLK_IS_CRITICAL;
46 + if (!(cprman_read(cprman, divider_data->cm_reg) & divider_data->hold_mask)) {
47 + if (!bcm2835_clk_is_claimed(divider_data->source_pll))
48 + init.flags |= CLK_IS_CRITICAL;
49 + if (!bcm2835_clk_is_claimed(divider_data->name))
50 + divider->div.flags |= CLK_IS_CRITICAL;
53 divider->cprman = cprman;
54 @@ -1443,6 +1450,15 @@ static struct clk_hw *bcm2835_register_c
55 init.flags = clock_data->flags | CLK_IGNORE_UNUSED;
58 + * Some GPIO clocks for ethernet/wifi PLLs are marked as
59 + * critical (since some platforms use them), but if the
60 + * firmware didn't have them turned on then they clearly
61 + * aren't actually critical.
63 + if ((cprman_read(cprman, clock_data->ctl_reg) & CM_ENABLE) == 0)
64 + init.flags &= ~CLK_IS_CRITICAL;
67 * Pass the CLK_SET_RATE_PARENT flag if we are allowed to propagate
68 * rate changes on at least of the parents.
70 @@ -2221,6 +2237,8 @@ static const struct bcm2835_clk_desc clk
71 .ctl_reg = CM_PERIICTL),
74 +static bool bcm2835_clk_claimed[ARRAY_SIZE(clk_desc_array)];
77 * Permanently take a reference on the parent of the SDRAM clock.
79 @@ -2240,6 +2258,19 @@ static int bcm2835_mark_sdc_parent_criti
80 return clk_prepare_enable(parent);
83 +static bool bcm2835_clk_is_claimed(const char *name)
87 + for (i = 0; i < ARRAY_SIZE(clk_desc_array); i++) {
88 + const char *clk_name = *(const char **)(clk_desc_array[i].data);
89 + if (!strcmp(name, clk_name))
90 + return bcm2835_clk_claimed[i];
96 static int bcm2835_clk_probe(struct platform_device *pdev)
98 struct device *dev = &pdev->dev;
99 @@ -2249,6 +2280,7 @@ static int bcm2835_clk_probe(struct plat
100 const size_t asize = ARRAY_SIZE(clk_desc_array);
101 const struct cprman_plat_data *pdata;
106 pdata = of_device_get_match_data(&pdev->dev);
107 @@ -2267,6 +2299,13 @@ static int bcm2835_clk_probe(struct plat
108 if (IS_ERR(cprman->regs))
109 return PTR_ERR(cprman->regs);
111 + memset(bcm2835_clk_claimed, 0, sizeof(bcm2835_clk_claimed));
113 + !of_property_read_u32_index(pdev->dev.of_node, "claim-clocks",
116 + bcm2835_clk_claimed[clk_id]= true;
118 memcpy(cprman->real_parent_names, cprman_parent_names,
119 sizeof(cprman_parent_names));
120 of_clk_parent_fill(dev->of_node, cprman->real_parent_names,