brcm2708: add kernel 4.14 support
[openwrt/staging/chunkeey.git] / target / linux / brcm2708 / patches-4.14 / 950-0027-clk-bcm2835-Add-claim-clocks-property.patch
1 From 7a4c12de72b705c93482f3dd28b230ced588052f 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 027/454] clk-bcm2835: Add claim-clocks property
5
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.
9
10 Use this mechanism to claim PLLD_DSI0, PLLD_DSI1, PLLH_AUX and
11 PLLH_PIX for the vc4_kms_v3d driver.
12
13 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
14 ---
15 drivers/clk/bcm/clk-bcm2835.c | 34 ++++++++++++++++++++++++++++++++--
16 1 file changed, 32 insertions(+), 2 deletions(-)
17
18 --- a/drivers/clk/bcm/clk-bcm2835.c
19 +++ b/drivers/clk/bcm/clk-bcm2835.c
20 @@ -1329,6 +1329,8 @@ static const struct clk_ops bcm2835_vpu_
21 .debug_init = bcm2835_clock_debug_init,
22 };
23
24 +static bool bcm2835_clk_is_claimed(const char *name);
25 +
26 static struct clk_hw *bcm2835_register_pll(struct bcm2835_cprman *cprman,
27 const struct bcm2835_pll_data *data)
28 {
29 @@ -1345,6 +1347,9 @@ static struct clk_hw *bcm2835_register_p
30 init.ops = &bcm2835_pll_clk_ops;
31 init.flags = CLK_IGNORE_UNUSED;
32
33 + if (!bcm2835_clk_is_claimed(data->name))
34 + init.flags |= CLK_IS_CRITICAL;
35 +
36 pll = kzalloc(sizeof(*pll), GFP_KERNEL);
37 if (!pll)
38 return NULL;
39 @@ -1398,8 +1403,10 @@ bcm2835_register_pll_divider(struct bcm2
40 divider->div.table = NULL;
41
42 if (!(cprman_read(cprman, data->cm_reg) & data->hold_mask)) {
43 - init.flags |= CLK_IS_CRITICAL;
44 - divider->div.flags |= CLK_IS_CRITICAL;
45 + if (!bcm2835_clk_is_claimed(data->source_pll))
46 + init.flags |= CLK_IS_CRITICAL;
47 + if (!bcm2835_clk_is_claimed(data->name))
48 + divider->div.flags |= CLK_IS_CRITICAL;
49 }
50
51 divider->cprman = cprman;
52 @@ -2152,6 +2159,8 @@ static const struct bcm2835_clk_desc clk
53 .ctl_reg = CM_PERIICTL),
54 };
55
56 +static bool bcm2835_clk_claimed[ARRAY_SIZE(clk_desc_array)];
57 +
58 /*
59 * Permanently take a reference on the parent of the SDRAM clock.
60 *
61 @@ -2171,6 +2180,19 @@ static int bcm2835_mark_sdc_parent_criti
62 return clk_prepare_enable(parent);
63 }
64
65 +static bool bcm2835_clk_is_claimed(const char *name)
66 +{
67 + int i;
68 +
69 + for (i = 0; i < ARRAY_SIZE(clk_desc_array); i++) {
70 + const char *clk_name = *(const char **)(clk_desc_array[i].data);
71 + if (!strcmp(name, clk_name))
72 + return bcm2835_clk_claimed[i];
73 + }
74 +
75 + return false;
76 +}
77 +
78 static int bcm2835_clk_probe(struct platform_device *pdev)
79 {
80 struct device *dev = &pdev->dev;
81 @@ -2180,6 +2202,7 @@ static int bcm2835_clk_probe(struct plat
82 const struct bcm2835_clk_desc *desc;
83 const size_t asize = ARRAY_SIZE(clk_desc_array);
84 size_t i;
85 + u32 clk_id;
86 int ret;
87
88 cprman = devm_kzalloc(dev, sizeof(*cprman) +
89 @@ -2195,6 +2218,13 @@ static int bcm2835_clk_probe(struct plat
90 if (IS_ERR(cprman->regs))
91 return PTR_ERR(cprman->regs);
92
93 + memset(bcm2835_clk_claimed, 0, sizeof(bcm2835_clk_claimed));
94 + for (i = 0;
95 + !of_property_read_u32_index(pdev->dev.of_node, "claim-clocks",
96 + i, &clk_id);
97 + i++)
98 + bcm2835_clk_claimed[clk_id]= true;
99 +
100 memcpy(cprman->real_parent_names, cprman_parent_names,
101 sizeof(cprman_parent_names));
102 of_clk_parent_fill(dev->of_node, cprman->real_parent_names,