ipq806x: update clk-qcom patches
[openwrt/staging/yousong.git] / target / linux / ipq806x / patches-4.4 / 001-add-API-register-brd-clks-bckwrds-cmptblt.patch
1 From ee15faffef11309219aa87a24efc86f6dd13f7cb Mon Sep 17 00:00:00 2001
2 From: Stephen Boyd <sboyd@codeaurora.org>
3 Date: Mon, 26 Oct 2015 17:11:32 -0700
4 Subject: clk: qcom: common: Add API to register board clocks backwards
5 compatibly
6
7 We want to put the XO board clocks into the dt files, but we also
8 need to be backwards compatible with an older dtb. Add an API to
9 the common code to do this. This also makes a place for us to
10 handle the case when the RPM clock driver is enabled and we don't
11 want to register the fixed factor clock.
12
13 Cc: Georgi Djakov <georgi.djakov@linaro.org>
14 Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
15 ---
16 drivers/clk/qcom/common.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++
17 drivers/clk/qcom/common.h | 4 +++
18 2 files changed, 91 insertions(+)
19
20 --- a/drivers/clk/qcom/common.c
21 +++ b/drivers/clk/qcom/common.c
22 @@ -17,6 +17,7 @@
23 #include <linux/platform_device.h>
24 #include <linux/clk-provider.h>
25 #include <linux/reset-controller.h>
26 +#include <linux/of.h>
27
28 #include "common.h"
29 #include "clk-rcg.h"
30 @@ -88,6 +89,92 @@ static void qcom_cc_gdsc_unregister(void
31 gdsc_unregister(data);
32 }
33
34 +/*
35 + * Backwards compatibility with old DTs. Register a pass-through factor 1/1
36 + * clock to translate 'path' clk into 'name' clk and regsiter the 'path'
37 + * clk as a fixed rate clock if it isn't present.
38 + */
39 +static int _qcom_cc_register_board_clk(struct device *dev, const char *path,
40 + const char *name, unsigned long rate,
41 + bool add_factor)
42 +{
43 + struct device_node *node = NULL;
44 + struct device_node *clocks_node;
45 + struct clk_fixed_factor *factor;
46 + struct clk_fixed_rate *fixed;
47 + struct clk *clk;
48 + struct clk_init_data init_data = { };
49 +
50 + clocks_node = of_find_node_by_path("/clocks");
51 + if (clocks_node)
52 + node = of_find_node_by_name(clocks_node, path);
53 + of_node_put(clocks_node);
54 +
55 + if (!node) {
56 + fixed = devm_kzalloc(dev, sizeof(*fixed), GFP_KERNEL);
57 + if (!fixed)
58 + return -EINVAL;
59 +
60 + fixed->fixed_rate = rate;
61 + fixed->hw.init = &init_data;
62 +
63 + init_data.name = path;
64 + init_data.flags = CLK_IS_ROOT;
65 + init_data.ops = &clk_fixed_rate_ops;
66 +
67 + clk = devm_clk_register(dev, &fixed->hw);
68 + if (IS_ERR(clk))
69 + return PTR_ERR(clk);
70 + }
71 + of_node_put(node);
72 +
73 + if (add_factor) {
74 + factor = devm_kzalloc(dev, sizeof(*factor), GFP_KERNEL);
75 + if (!factor)
76 + return -EINVAL;
77 +
78 + factor->mult = factor->div = 1;
79 + factor->hw.init = &init_data;
80 +
81 + init_data.name = name;
82 + init_data.parent_names = &path;
83 + init_data.num_parents = 1;
84 + init_data.flags = 0;
85 + init_data.ops = &clk_fixed_factor_ops;
86 +
87 + clk = devm_clk_register(dev, &factor->hw);
88 + if (IS_ERR(clk))
89 + return PTR_ERR(clk);
90 + }
91 +
92 + return 0;
93 +}
94 +
95 +int qcom_cc_register_board_clk(struct device *dev, const char *path,
96 + const char *name, unsigned long rate)
97 +{
98 + bool add_factor = true;
99 + struct device_node *node;
100 +
101 + /* The RPM clock driver will add the factor clock if present */
102 + if (IS_ENABLED(CONFIG_QCOM_RPMCC)) {
103 + node = of_find_compatible_node(NULL, NULL, "qcom,rpmcc");
104 + if (of_device_is_available(node))
105 + add_factor = false;
106 + of_node_put(node);
107 + }
108 +
109 + return _qcom_cc_register_board_clk(dev, path, name, rate, add_factor);
110 +}
111 +EXPORT_SYMBOL_GPL(qcom_cc_register_board_clk);
112 +
113 +int qcom_cc_register_sleep_clk(struct device *dev)
114 +{
115 + return _qcom_cc_register_board_clk(dev, "sleep_clk", "sleep_clk_src",
116 + 32768, true);
117 +}
118 +EXPORT_SYMBOL_GPL(qcom_cc_register_sleep_clk);
119 +
120 int qcom_cc_really_probe(struct platform_device *pdev,
121 const struct qcom_cc_desc *desc, struct regmap *regmap)
122 {
123 --- a/drivers/clk/qcom/common.h
124 +++ b/drivers/clk/qcom/common.h
125 @@ -37,6 +37,10 @@ extern const struct freq_tbl *qcom_find_
126 extern int qcom_find_src_index(struct clk_hw *hw, const struct parent_map *map,
127 u8 src);
128
129 +extern int qcom_cc_register_board_clk(struct device *dev, const char *path,
130 + const char *name, unsigned long rate);
131 +extern int qcom_cc_register_sleep_clk(struct device *dev);
132 +
133 extern struct regmap *qcom_cc_map(struct platform_device *pdev,
134 const struct qcom_cc_desc *desc);
135 extern int qcom_cc_really_probe(struct platform_device *pdev,