aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/oxnas/patches-4.14/100-oxnas-clk-plla-pllb.patch
blob: d3bf9a9e43f9611b50fa5237088608d4b65e4ca4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
--- a/drivers/clk/clk-oxnas.c
+++ b/drivers/clk/clk-oxnas.c
@@ -16,19 +16,42 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <linux/clk.h>
+#include <linux/clkdev.h>
 #include <linux/clk-provider.h>
 #include <linux/kernel.h>
 #include <linux/init.h>
+#include <linux/delay.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
 #include <linux/platform_device.h>
 #include <linux/stringify.h>
 #include <linux/regmap.h>
 #include <linux/mfd/syscon.h>
+#include <linux/reset.h>
 
 #include <dt-bindings/clock/oxsemi,ox810se.h>
 #include <dt-bindings/clock/oxsemi,ox820.h>
 
+#define REF300_DIV_INT_SHIFT		8
+#define REF300_DIV_FRAC_SHIFT		0
+#define REF300_DIV_INT(val)		((val) << REF300_DIV_INT_SHIFT)
+#define REF300_DIV_FRAC(val)		((val) << REF300_DIV_FRAC_SHIFT)
+
+#define PLLB_BYPASS			1
+#define PLLB_ENSAT			3
+#define PLLB_OUTDIV			4
+#define PLLB_REFDIV			8
+#define PLLB_DIV_INT_SHIFT		8
+#define PLLB_DIV_FRAC_SHIFT		0
+#define PLLB_DIV_INT(val)		((val) << PLLB_DIV_INT_SHIFT)
+#define PLLB_DIV_FRAC(val)		((val) << PLLB_DIV_FRAC_SHIFT)
+
+#define PLLA_REFDIV_MASK		0x3F
+#define PLLA_REFDIV_SHIFT		8
+#define PLLA_OUTDIV_MASK		0x7
+#define PLLA_OUTDIV_SHIFT		4
+
 /* Standard regmap gate clocks */
 struct clk_oxnas_gate {
 	struct clk_hw hw;
@@ -47,6 +70,135 @@ struct oxnas_stdclk_data {
 #define CLK_SET_REGOFFSET	0x2c
 #define CLK_CLR_REGOFFSET	0x30
 
+#define PLLA_CTRL0_REGOFFSET	0x1f0
+#define PLLA_CTRL1_REGOFFSET	0x1f4
+#define PLLB_CTRL0_REGOFFSET	0x1001f0
+#define MHZ (1000 * 1000)
+
+struct clk_oxnas_pll {
+	struct clk_hw hw;
+	struct device_node *devnode;
+	struct reset_control *rstc;
+	struct regmap *syscon;
+};
+
+#define to_clk_oxnas_pll(_hw) container_of(_hw, struct clk_oxnas_pll, hw)
+
+static unsigned long plla_clk_recalc_rate(struct clk_hw *hw,
+	unsigned long parent_rate)
+{
+	struct clk_oxnas_pll *plla = to_clk_oxnas_pll(hw);
+	unsigned long fin = parent_rate;
+	unsigned long refdiv, outdiv;
+	unsigned int pll0, fbdiv;
+
+	BUG_ON(regmap_read(plla->syscon, PLLA_CTRL0_REGOFFSET, &pll0));
+
+	refdiv = (pll0 >> PLLA_REFDIV_SHIFT) & PLLA_REFDIV_MASK;
+	refdiv += 1;
+	outdiv = (pll0 >> PLLA_OUTDIV_SHIFT) & PLLA_OUTDIV_MASK;
+	outdiv += 1;
+
+	BUG_ON(regmap_read(plla->syscon, PLLA_CTRL1_REGOFFSET, &fbdiv));
+	/* seems we will not be here when pll is bypassed, so ignore this
+	 * case */
+
+	return fin / MHZ * fbdiv / (refdiv * outdiv) / 32768 * MHZ;
+}
+
+static const char *pll_clk_parents[] = {
+	"oscillator",
+};
+
+static struct clk_ops plla_ops = {
+	.recalc_rate = plla_clk_recalc_rate,
+};
+
+static struct clk_init_data clk_plla_init = {
+	.name = "plla",
+	.ops = &plla_ops,
+	.parent_names = pll_clk_parents,
+	.num_parents = ARRAY_SIZE(pll_clk_parents),
+};
+
+static int pllb_clk_is_prepared(struct clk_hw *hw)
+{
+	struct clk_oxnas_pll *pllb = to_clk_oxnas_pll(hw);
+
+	return !!pllb->rstc;
+}
+
+static int pllb_clk_prepare(struct clk_hw *hw)
+{
+	struct clk_oxnas_pll *pllb = to_clk_oxnas_pll(hw);
+
+	pllb->rstc = of_reset_control_get(pllb->devnode, NULL);
+
+	return IS_ERR(pllb->rstc) ? PTR_ERR(pllb->rstc) : 0;
+}
+
+static void pllb_clk_unprepare(struct clk_hw *hw)
+{
+	struct clk_oxnas_pll *pllb = to_clk_oxnas_pll(hw);
+
+	BUG_ON(IS_ERR(pllb->rstc));
+
+	reset_control_put(pllb->rstc);
+	pllb->rstc = NULL;
+}
+
+static int pllb_clk_enable(struct clk_hw *hw)
+{
+	struct clk_oxnas_pll *pllb = to_clk_oxnas_pll(hw);
+
+	BUG_ON(IS_ERR(pllb->rstc));
+
+	/* put PLL into bypass */
+	regmap_update_bits(pllb->syscon, PLLB_CTRL0_REGOFFSET, BIT(PLLB_BYPASS), BIT(PLLB_BYPASS));
+	wmb();
+	udelay(10);
+	reset_control_assert(pllb->rstc);
+	udelay(10);
+	/* set PLL B control information */
+	regmap_write_bits(pllb->syscon, PLLB_CTRL0_REGOFFSET, 0xffff,
+			  (1 << PLLB_ENSAT) | (1 << PLLB_OUTDIV) | (2 << PLLB_REFDIV));
+	reset_control_deassert(pllb->rstc);
+	udelay(100);
+	regmap_update_bits(pllb->syscon, PLLB_CTRL0_REGOFFSET, BIT(PLLB_BYPASS), 0);
+
+	return 0;
+}
+
+static void pllb_clk_disable(struct clk_hw *hw)
+{
+	struct clk_oxnas_pll *pllb = to_clk_oxnas_pll(hw);
+
+	BUG_ON(IS_ERR(pllb->rstc));
+
+	/* put PLL into bypass */
+	regmap_update_bits(pllb->syscon, PLLB_CTRL0_REGOFFSET, BIT(PLLB_BYPASS), BIT(PLLB_BYPASS));
+
+	wmb();
+	udelay(10);
+
+	reset_control_assert(pllb->rstc);
+}
+
+static struct clk_ops pllb_ops = {
+	.prepare = pllb_clk_prepare,
+	.unprepare = pllb_clk_unprepare,
+	.is_prepared = pllb_clk_is_prepared,
+	.enable = pllb_clk_enable,
+	.disable = pllb_clk_disable,
+};
+
+static struct clk_init_data clk_pllb_init = {
+	.name = "pllb",
+	.ops = &pllb_ops,
+	.parent_names = pll_clk_parents,
+	.num_parents = ARRAY_SIZE(pll_clk_parents),
+};
+
 static inline struct clk_oxnas_gate *to_clk_oxnas_gate(struct clk_hw *hw)
 {
 	return container_of(hw, struct clk_oxnas_gate, hw);
@@ -260,3 +412,42 @@ static struct platform_driver oxnas_stdc
 	},
 };
 builtin_platform_driver(oxnas_stdclk_driver);
+
+void __init oxnas_init_plla(struct device_node *np)
+{
+	struct clk *clk;
+	struct clk_oxnas_pll *plla;
+
+	plla = kmalloc(sizeof(*plla), GFP_KERNEL);
+	BUG_ON(!plla);
+
+	plla->syscon = syscon_node_to_regmap(of_get_parent(np));
+	plla->hw.init = &clk_plla_init;
+	plla->devnode = np;
+	plla->rstc = NULL;
+	clk = clk_register(NULL, &plla->hw);
+	BUG_ON(IS_ERR(clk));
+	/* mark it as enabled */
+	clk_prepare_enable(clk);
+	of_clk_add_provider(np, of_clk_src_simple_get, clk);
+}
+CLK_OF_DECLARE(oxnas_plla, "plxtech,nas782x-plla", oxnas_init_plla);
+
+void __init oxnas_init_pllb(struct device_node *np)
+{
+	struct clk *clk;
+	struct clk_oxnas_pll *pllb;
+
+	pllb = kmalloc(sizeof(*pllb), GFP_KERNEL);
+	BUG_ON(!pllb);
+
+	pllb->syscon = syscon_node_to_regmap(of_get_parent(np));
+	pllb->hw.init = &clk_pllb_init;
+	pllb->devnode = np;
+	pllb->rstc = NULL;
+
+	clk = clk_register(NULL, &pllb->hw);
+	BUG_ON(IS_ERR(clk));
+	of_clk_add_provider(np, of_clk_src_simple_get, clk);
+}
+CLK_OF_DECLARE(oxnas_pllb, "plxtech,nas782x-pllb", oxnas_init_pllb);
--- a/arch/arm/boot/dts/ox820.dtsi
+++ b/arch/arm/boot/dts/ox820.dtsi
@@ -60,12 +60,6 @@
 			clocks = <&osc>;
 		};
 
-		plla: plla {
-			compatible = "fixed-clock";
-			#clock-cells = <0>;
-			clock-frequency = <850000000>;
-		};
-
 		armclk: armclk {
 			compatible = "fixed-factor-clock";
 			#clock-cells = <0>;
@@ -265,6 +259,19 @@
 					compatible = "oxsemi,ox820-stdclk", "oxsemi,ox810se-stdclk";
 					#clock-cells = <1>;
 				};
+
+				plla: plla {
+					compatible = "plxtech,nas782x-plla";
+					#clock-cells = <0>;
+					clocks = <&osc>;
+				};
+
+				pllb: pllb {
+					compatible = "plxtech,nas782x-pllb";
+					#clock-cells = <0>;
+					clocks = <&osc>;
+					resets = <&reset RESET_PLLB>;
+				};
 			};
 		};
 
@@ -286,6 +293,13 @@
 				clocks = <&armclk>;
 			};
 
+			watchdog@620 {
+				compatible = "mpcore_wdt";
+				reg = <0x620 0x20>;
+				interrupts = <GIC_PPI 14 (GIC_CPU_MASK_RAW(3)|IRQ_TYPE_LEVEL_HIGH)>;
+				clocks = <&armclk>;
+			};
+
 			gic: gic@1000 {
 				compatible = "arm,arm11mp-gic";
 				interrupt-controller;