60ad59dec881915b69b3d6c4722e59e4404232f8
[openwrt/staging/chunkeey.git] / target / linux / brcm2708 / patches-4.4 / 0431-clk-bcm2835-Mark-the-CM-SDRAM-clock-s-parent-as-crit.patch
1 From 3dbdbeedb865d12700dae53b59e259ea083e6186 Mon Sep 17 00:00:00 2001
2 From: Eric Anholt <eric@anholt.net>
3 Date: Wed, 1 Jun 2016 12:05:35 -0700
4 Subject: [PATCH] clk: bcm2835: Mark the CM SDRAM clock's parent as critical
5
6 While the SDRAM is being driven by its dedicated PLL most of the time,
7 there is a little loop running in the firmware that periodically turns
8 on the CM SDRAM clock (using its pre-initialized parent) and switches
9 SDRAM to using the CM clock to do PVT recalibration.
10
11 This avoids system hangs if we choose SDRAM's parent for some other
12 clock, then disable that clock.
13
14 Signed-off-by: Eric Anholt <eric@anholt.net>
15 ---
16 drivers/clk/bcm/clk-bcm2835.c | 25 +++++++++++++++++++++++++
17 1 file changed, 25 insertions(+)
18
19 --- a/drivers/clk/bcm/clk-bcm2835.c
20 +++ b/drivers/clk/bcm/clk-bcm2835.c
21 @@ -36,6 +36,7 @@
22
23 #include <linux/clk-provider.h>
24 #include <linux/clkdev.h>
25 +#include <linux/clk.h>
26 #include <linux/clk/bcm2835.h>
27 #include <linux/debugfs.h>
28 #include <linux/module.h>
29 @@ -1839,6 +1840,25 @@ static const struct bcm2835_clk_desc clk
30 .ctl_reg = CM_PERIICTL),
31 };
32
33 +/*
34 + * Permanently take a reference on the parent of the SDRAM clock.
35 + *
36 + * While the SDRAM is being driven by its dedicated PLL most of the
37 + * time, there is a little loop running in the firmware that
38 + * periodically switches the SDRAM to using our CM clock to do PVT
39 + * recalibration, with the assumption that the previously configured
40 + * SDRAM parent is still enabled and running.
41 + */
42 +static int bcm2835_mark_sdc_parent_critical(struct clk *sdc)
43 +{
44 + struct clk *parent = clk_get_parent(sdc);
45 +
46 + if (IS_ERR(parent))
47 + return PTR_ERR(parent);
48 +
49 + return clk_prepare_enable(parent);
50 +}
51 +
52 static int bcm2835_clk_probe(struct platform_device *pdev)
53 {
54 struct device *dev = &pdev->dev;
55 @@ -1848,6 +1868,7 @@ static int bcm2835_clk_probe(struct plat
56 const struct bcm2835_clk_desc *desc;
57 const size_t asize = ARRAY_SIZE(clk_desc_array);
58 size_t i;
59 + int ret;
60
61 cprman = devm_kzalloc(dev,
62 sizeof(*cprman) + asize * sizeof(*clks),
63 @@ -1878,6 +1899,10 @@ static int bcm2835_clk_probe(struct plat
64 clks[i] = desc->clk_register(cprman, desc->data);
65 }
66
67 + ret = bcm2835_mark_sdc_parent_critical(clks[BCM2835_CLOCK_SDRAM]);
68 + if (ret)
69 + return ret;
70 +
71 return of_clk_add_provider(dev->of_node, of_clk_src_onecell_get,
72 &cprman->onecell);
73 }