ipq806x: add support for RPM message RAM
[librecmc/librecmc.git] / target / linux / ipq806x / patches-4.4 / 006-mfd-qcom_rpm-Handle-message-RAM-clock.patch
1 From 3526403353c2a1b94c3181f900582626d23c339b Mon Sep 17 00:00:00 2001
2 From: Linus Walleij <linus.walleij@linaro.org>
3 Date: Thu, 18 Aug 2016 20:40:45 +0200
4 Subject: mfd: qcom_rpm: Handle message RAM clock
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 The MSM8660, APQ8060, IPQ806x and MSM8960 have a GCC clock
10 to the message RAM used by the RPM. This needs to be enabled
11 for messages to pass through. This is a crude solution that
12 simply prepare/enable at probe() and disable/unprepare
13 at remove(). More elaborate PM is probably possible to
14 add later.
15
16 The construction uses IS_ERR() to gracefully handle the
17 platforms that do not provide a message RAM clock. It will
18 bail out of probe only if the clock is hitting a probe
19 deferral situation.
20
21 Of course this requires the proper device tree set-up:
22
23 rpm: rpm@104000 {
24     compatible = "qcom,rpm-msm8660";
25     clocks = <&gcc RPM_MSG_RAM_H_CLK>;
26     clock-names = "ram";
27     ...
28 };
29
30 I have provided this in the MSM8660 device tree, and will
31 provide patches for the other targets.
32
33 Cc: Björn Andersson <bjorn.andersson@linaro.org>
34 Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
35 Signed-off-by: Lee Jones <lee.jones@linaro.org>
36 ---
37  drivers/mfd/qcom_rpm.c | 20 ++++++++++++++++++++
38  1 file changed, 20 insertions(+)
39
40 diff --git a/drivers/mfd/qcom_rpm.c b/drivers/mfd/qcom_rpm.c
41 index d330071..52fafea 100644
42 --- a/drivers/mfd/qcom_rpm.c
43 +++ b/drivers/mfd/qcom_rpm.c
44 @@ -21,6 +21,7 @@
45  #include <linux/mfd/qcom_rpm.h>
46  #include <linux/mfd/syscon.h>
47  #include <linux/regmap.h>
48 +#include <linux/clk.h>
49  
50  #include <dt-bindings/mfd/qcom-rpm.h>
51  
52 @@ -48,6 +49,7 @@ struct qcom_rpm {
53         struct regmap *ipc_regmap;
54         unsigned ipc_offset;
55         unsigned ipc_bit;
56 +       struct clk *ramclk;
57  
58         struct completion ack;
59         struct mutex lock;
60 @@ -552,6 +554,20 @@ static int qcom_rpm_probe(struct platform_device *pdev)
61         mutex_init(&rpm->lock);
62         init_completion(&rpm->ack);
63  
64 +       /* Enable message RAM clock */
65 +       rpm->ramclk = devm_clk_get(&pdev->dev, "ram");
66 +       if (IS_ERR(rpm->ramclk)) {
67 +               ret = PTR_ERR(rpm->ramclk);
68 +               if (ret == -EPROBE_DEFER)
69 +                       return ret;
70 +               /*
71 +                * Fall through in all other cases, as the clock is
72 +                * optional. (Does not exist on all platforms.)
73 +                */
74 +               rpm->ramclk = NULL;
75 +       }
76 +       clk_prepare_enable(rpm->ramclk); /* Accepts NULL */
77 +
78         irq_ack = platform_get_irq_byname(pdev, "ack");
79         if (irq_ack < 0) {
80                 dev_err(&pdev->dev, "required ack interrupt missing\n");
81 @@ -672,7 +688,11 @@ static int qcom_rpm_probe(struct platform_device *pdev)
82  
83  static int qcom_rpm_remove(struct platform_device *pdev)
84  {
85 +       struct qcom_rpm *rpm = dev_get_drvdata(&pdev->dev);
86 +
87         of_platform_depopulate(&pdev->dev);
88 +       clk_disable_unprepare(rpm->ramclk);
89 +
90         return 0;
91  }
92  
93 -- 
94 cgit v0.12