blob: b2a332cf8985706574f89acc4d46d8fe17f2166c [file] [log] [blame]
Gabriel FERNANDEZb9b8e612014-02-27 16:24:15 +01001/*
2 * Copyright (C) 2014 STMicroelectronics (R&D) Limited
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 */
10
11/*
12 * Authors:
13 * Stephen Gallimore <stephen.gallimore@st.com>,
14 * Pankaj Dev <pankaj.dev@st.com>.
15 */
16
17#include <linux/slab.h>
18#include <linux/of_address.h>
Stephen Boydd5f728a2015-06-19 15:00:46 -070019#include <linux/clk.h>
Gabriel FERNANDEZb9b8e612014-02-27 16:24:15 +010020#include <linux/clk-provider.h>
21
22#include "clkgen.h"
23
24static DEFINE_SPINLOCK(clkgena_c32_odf_lock);
25
26/*
27 * Common PLL configuration register bits for PLL800 and PLL1600 C65
28 */
29#define C65_MDIV_PLL800_MASK (0xff)
30#define C65_MDIV_PLL1600_MASK (0x7)
31#define C65_NDIV_MASK (0xff)
32#define C65_PDIV_MASK (0x7)
33
34/*
35 * PLL configuration register bits for PLL3200 C32
36 */
37#define C32_NDIV_MASK (0xff)
38#define C32_IDF_MASK (0x7)
39#define C32_ODF_MASK (0x3f)
40#define C32_LDF_MASK (0x7f)
41
42#define C32_MAX_ODFS (4)
43
44struct clkgen_pll_data {
45 struct clkgen_field pdn_status;
46 struct clkgen_field locked_status;
47 struct clkgen_field mdiv;
48 struct clkgen_field ndiv;
49 struct clkgen_field pdiv;
50 struct clkgen_field idf;
51 struct clkgen_field ldf;
52 unsigned int num_odfs;
53 struct clkgen_field odf[C32_MAX_ODFS];
54 struct clkgen_field odf_gate[C32_MAX_ODFS];
55 const struct clk_ops *ops;
56};
57
58static const struct clk_ops st_pll1600c65_ops;
59static const struct clk_ops st_pll800c65_ops;
60static const struct clk_ops stm_pll3200c32_ops;
61static const struct clk_ops st_pll1200c32_ops;
62
Gabriel FERNANDEZdc4febe2014-07-15 17:20:19 +020063static const struct clkgen_pll_data st_pll1600c65_ax = {
Gabriel FERNANDEZb9b8e612014-02-27 16:24:15 +010064 .pdn_status = CLKGEN_FIELD(0x0, 0x1, 19),
65 .locked_status = CLKGEN_FIELD(0x0, 0x1, 31),
66 .mdiv = CLKGEN_FIELD(0x0, C65_MDIV_PLL1600_MASK, 0),
67 .ndiv = CLKGEN_FIELD(0x0, C65_NDIV_MASK, 8),
68 .ops = &st_pll1600c65_ops
69};
70
Gabriel FERNANDEZdc4febe2014-07-15 17:20:19 +020071static const struct clkgen_pll_data st_pll800c65_ax = {
Gabriel FERNANDEZb9b8e612014-02-27 16:24:15 +010072 .pdn_status = CLKGEN_FIELD(0x0, 0x1, 19),
73 .locked_status = CLKGEN_FIELD(0x0, 0x1, 31),
74 .mdiv = CLKGEN_FIELD(0x0, C65_MDIV_PLL800_MASK, 0),
75 .ndiv = CLKGEN_FIELD(0x0, C65_NDIV_MASK, 8),
76 .pdiv = CLKGEN_FIELD(0x0, C65_PDIV_MASK, 16),
77 .ops = &st_pll800c65_ops
78};
79
Gabriel FERNANDEZdc4febe2014-07-15 17:20:19 +020080static const struct clkgen_pll_data st_pll3200c32_a1x_0 = {
Gabriel FERNANDEZb9b8e612014-02-27 16:24:15 +010081 .pdn_status = CLKGEN_FIELD(0x0, 0x1, 31),
82 .locked_status = CLKGEN_FIELD(0x4, 0x1, 31),
83 .ndiv = CLKGEN_FIELD(0x0, C32_NDIV_MASK, 0x0),
84 .idf = CLKGEN_FIELD(0x4, C32_IDF_MASK, 0x0),
85 .num_odfs = 4,
86 .odf = { CLKGEN_FIELD(0x54, C32_ODF_MASK, 4),
87 CLKGEN_FIELD(0x54, C32_ODF_MASK, 10),
88 CLKGEN_FIELD(0x54, C32_ODF_MASK, 16),
89 CLKGEN_FIELD(0x54, C32_ODF_MASK, 22) },
90 .odf_gate = { CLKGEN_FIELD(0x54, 0x1, 0),
91 CLKGEN_FIELD(0x54, 0x1, 1),
92 CLKGEN_FIELD(0x54, 0x1, 2),
93 CLKGEN_FIELD(0x54, 0x1, 3) },
94 .ops = &stm_pll3200c32_ops,
95};
96
Gabriel FERNANDEZdc4febe2014-07-15 17:20:19 +020097static const struct clkgen_pll_data st_pll3200c32_a1x_1 = {
Gabriel FERNANDEZb9b8e612014-02-27 16:24:15 +010098 .pdn_status = CLKGEN_FIELD(0xC, 0x1, 31),
99 .locked_status = CLKGEN_FIELD(0x10, 0x1, 31),
100 .ndiv = CLKGEN_FIELD(0xC, C32_NDIV_MASK, 0x0),
101 .idf = CLKGEN_FIELD(0x10, C32_IDF_MASK, 0x0),
102 .num_odfs = 4,
103 .odf = { CLKGEN_FIELD(0x58, C32_ODF_MASK, 4),
104 CLKGEN_FIELD(0x58, C32_ODF_MASK, 10),
105 CLKGEN_FIELD(0x58, C32_ODF_MASK, 16),
106 CLKGEN_FIELD(0x58, C32_ODF_MASK, 22) },
107 .odf_gate = { CLKGEN_FIELD(0x58, 0x1, 0),
108 CLKGEN_FIELD(0x58, 0x1, 1),
109 CLKGEN_FIELD(0x58, 0x1, 2),
110 CLKGEN_FIELD(0x58, 0x1, 3) },
111 .ops = &stm_pll3200c32_ops,
112};
113
Gabriel FERNANDEZec8d27b2014-02-27 16:24:18 +0100114/* 415 specific */
Gabriel FERNANDEZdc4febe2014-07-15 17:20:19 +0200115static const struct clkgen_pll_data st_pll3200c32_a9_415 = {
Gabriel FERNANDEZec8d27b2014-02-27 16:24:18 +0100116 .pdn_status = CLKGEN_FIELD(0x0, 0x1, 0),
117 .locked_status = CLKGEN_FIELD(0x6C, 0x1, 0),
118 .ndiv = CLKGEN_FIELD(0x0, C32_NDIV_MASK, 9),
119 .idf = CLKGEN_FIELD(0x0, C32_IDF_MASK, 22),
120 .num_odfs = 1,
121 .odf = { CLKGEN_FIELD(0x0, C32_ODF_MASK, 3) },
122 .odf_gate = { CLKGEN_FIELD(0x0, 0x1, 28) },
123 .ops = &stm_pll3200c32_ops,
124};
125
Gabriel FERNANDEZdc4febe2014-07-15 17:20:19 +0200126static const struct clkgen_pll_data st_pll3200c32_ddr_415 = {
Gabriel FERNANDEZec8d27b2014-02-27 16:24:18 +0100127 .pdn_status = CLKGEN_FIELD(0x0, 0x1, 0),
128 .locked_status = CLKGEN_FIELD(0x100, 0x1, 0),
129 .ndiv = CLKGEN_FIELD(0x8, C32_NDIV_MASK, 0),
130 .idf = CLKGEN_FIELD(0x0, C32_IDF_MASK, 25),
131 .num_odfs = 2,
132 .odf = { CLKGEN_FIELD(0x8, C32_ODF_MASK, 8),
133 CLKGEN_FIELD(0x8, C32_ODF_MASK, 14) },
134 .odf_gate = { CLKGEN_FIELD(0x4, 0x1, 28),
135 CLKGEN_FIELD(0x4, 0x1, 29) },
136 .ops = &stm_pll3200c32_ops,
137};
138
Gabriel FERNANDEZdc4febe2014-07-15 17:20:19 +0200139static const struct clkgen_pll_data st_pll1200c32_gpu_415 = {
Gabriel FERNANDEZec8d27b2014-02-27 16:24:18 +0100140 .pdn_status = CLKGEN_FIELD(0x144, 0x1, 3),
141 .locked_status = CLKGEN_FIELD(0x168, 0x1, 0),
142 .ldf = CLKGEN_FIELD(0x0, C32_LDF_MASK, 3),
143 .idf = CLKGEN_FIELD(0x0, C32_IDF_MASK, 0),
144 .num_odfs = 0,
145 .odf = { CLKGEN_FIELD(0x0, C32_ODF_MASK, 10) },
146 .ops = &st_pll1200c32_ops,
147};
148
149/* 416 specific */
Gabriel FERNANDEZdc4febe2014-07-15 17:20:19 +0200150static const struct clkgen_pll_data st_pll3200c32_a9_416 = {
Gabriel FERNANDEZec8d27b2014-02-27 16:24:18 +0100151 .pdn_status = CLKGEN_FIELD(0x0, 0x1, 0),
152 .locked_status = CLKGEN_FIELD(0x6C, 0x1, 0),
153 .ndiv = CLKGEN_FIELD(0x8, C32_NDIV_MASK, 0),
154 .idf = CLKGEN_FIELD(0x0, C32_IDF_MASK, 25),
155 .num_odfs = 1,
156 .odf = { CLKGEN_FIELD(0x8, C32_ODF_MASK, 8) },
157 .odf_gate = { CLKGEN_FIELD(0x4, 0x1, 28) },
158 .ops = &stm_pll3200c32_ops,
159};
160
Gabriel FERNANDEZdc4febe2014-07-15 17:20:19 +0200161static const struct clkgen_pll_data st_pll3200c32_ddr_416 = {
Gabriel FERNANDEZec8d27b2014-02-27 16:24:18 +0100162 .pdn_status = CLKGEN_FIELD(0x0, 0x1, 0),
163 .locked_status = CLKGEN_FIELD(0x10C, 0x1, 0),
164 .ndiv = CLKGEN_FIELD(0x8, C32_NDIV_MASK, 0),
165 .idf = CLKGEN_FIELD(0x0, C32_IDF_MASK, 25),
166 .num_odfs = 2,
167 .odf = { CLKGEN_FIELD(0x8, C32_ODF_MASK, 8),
168 CLKGEN_FIELD(0x8, C32_ODF_MASK, 14) },
169 .odf_gate = { CLKGEN_FIELD(0x4, 0x1, 28),
170 CLKGEN_FIELD(0x4, 0x1, 29) },
171 .ops = &stm_pll3200c32_ops,
172};
173
Gabriel FERNANDEZdc4febe2014-07-15 17:20:19 +0200174static const struct clkgen_pll_data st_pll1200c32_gpu_416 = {
Gabriel FERNANDEZec8d27b2014-02-27 16:24:18 +0100175 .pdn_status = CLKGEN_FIELD(0x8E4, 0x1, 3),
176 .locked_status = CLKGEN_FIELD(0x90C, 0x1, 0),
177 .ldf = CLKGEN_FIELD(0x0, C32_LDF_MASK, 3),
178 .idf = CLKGEN_FIELD(0x0, C32_IDF_MASK, 0),
179 .num_odfs = 0,
180 .odf = { CLKGEN_FIELD(0x0, C32_ODF_MASK, 10) },
181 .ops = &st_pll1200c32_ops,
182};
183
Gabriel FERNANDEZeee8f782014-07-15 17:20:24 +0200184static const struct clkgen_pll_data st_pll3200c32_407_a0 = {
185 /* 407 A0 */
186 .pdn_status = CLKGEN_FIELD(0x2a0, 0x1, 8),
187 .locked_status = CLKGEN_FIELD(0x2a0, 0x1, 24),
188 .ndiv = CLKGEN_FIELD(0x2a4, C32_NDIV_MASK, 16),
189 .idf = CLKGEN_FIELD(0x2a4, C32_IDF_MASK, 0x0),
190 .num_odfs = 1,
191 .odf = { CLKGEN_FIELD(0x2b4, C32_ODF_MASK, 0) },
192 .odf_gate = { CLKGEN_FIELD(0x2b4, 0x1, 6) },
193 .ops = &stm_pll3200c32_ops,
194};
195
Gabriel Fernandezd34e2102015-09-16 09:42:59 +0200196static const struct clkgen_pll_data st_pll3200c32_cx_0 = {
Gabriel FERNANDEZ51306d52014-07-15 17:20:27 +0200197 /* 407 C0 PLL0 */
198 .pdn_status = CLKGEN_FIELD(0x2a0, 0x1, 8),
199 .locked_status = CLKGEN_FIELD(0x2a0, 0x1, 24),
200 .ndiv = CLKGEN_FIELD(0x2a4, C32_NDIV_MASK, 16),
201 .idf = CLKGEN_FIELD(0x2a4, C32_IDF_MASK, 0x0),
202 .num_odfs = 1,
203 .odf = { CLKGEN_FIELD(0x2b4, C32_ODF_MASK, 0) },
204 .odf_gate = { CLKGEN_FIELD(0x2b4, 0x1, 6) },
205 .ops = &stm_pll3200c32_ops,
206};
207
Gabriel Fernandezd34e2102015-09-16 09:42:59 +0200208static const struct clkgen_pll_data st_pll3200c32_cx_1 = {
Gabriel FERNANDEZ51306d52014-07-15 17:20:27 +0200209 /* 407 C0 PLL1 */
210 .pdn_status = CLKGEN_FIELD(0x2c8, 0x1, 8),
211 .locked_status = CLKGEN_FIELD(0x2c8, 0x1, 24),
212 .ndiv = CLKGEN_FIELD(0x2cc, C32_NDIV_MASK, 16),
213 .idf = CLKGEN_FIELD(0x2cc, C32_IDF_MASK, 0x0),
214 .num_odfs = 1,
215 .odf = { CLKGEN_FIELD(0x2dc, C32_ODF_MASK, 0) },
216 .odf_gate = { CLKGEN_FIELD(0x2dc, 0x1, 6) },
217 .ops = &stm_pll3200c32_ops,
218};
219
Gabriel FERNANDEZaaa65d72014-07-15 17:20:29 +0200220static const struct clkgen_pll_data st_pll3200c32_407_a9 = {
221 /* 407 A9 */
222 .pdn_status = CLKGEN_FIELD(0x1a8, 0x1, 0),
223 .locked_status = CLKGEN_FIELD(0x87c, 0x1, 0),
224 .ndiv = CLKGEN_FIELD(0x1b0, C32_NDIV_MASK, 0),
225 .idf = CLKGEN_FIELD(0x1a8, C32_IDF_MASK, 25),
226 .num_odfs = 1,
227 .odf = { CLKGEN_FIELD(0x1b0, C32_ODF_MASK, 8) },
228 .odf_gate = { CLKGEN_FIELD(0x1ac, 0x1, 28) },
229 .ops = &stm_pll3200c32_ops,
230};
231
Gabriel FERNANDEZb9b8e612014-02-27 16:24:15 +0100232/**
233 * DOC: Clock Generated by PLL, rate set and enabled by bootloader
234 *
235 * Traits of this clock:
236 * prepare - clk_(un)prepare only ensures parent is (un)prepared
237 * enable - clk_enable/disable only ensures parent is enabled
238 * rate - rate is fixed. No clk_set_rate support
239 * parent - fixed parent. No clk_set_parent support
240 */
241
242/**
243 * PLL clock that is integrated in the ClockGenA instances on the STiH415
244 * and STiH416.
245 *
246 * @hw: handle between common and hardware-specific interfaces.
247 * @type: PLL instance type.
248 * @regs_base: base of the PLL configuration register(s).
249 *
250 */
251struct clkgen_pll {
252 struct clk_hw hw;
253 struct clkgen_pll_data *data;
254 void __iomem *regs_base;
255};
256
257#define to_clkgen_pll(_hw) container_of(_hw, struct clkgen_pll, hw)
258
259static int clkgen_pll_is_locked(struct clk_hw *hw)
260{
261 struct clkgen_pll *pll = to_clkgen_pll(hw);
262 u32 locked = CLKGEN_READ(pll, locked_status);
263
264 return !!locked;
265}
266
267static int clkgen_pll_is_enabled(struct clk_hw *hw)
268{
269 struct clkgen_pll *pll = to_clkgen_pll(hw);
270 u32 poweroff = CLKGEN_READ(pll, pdn_status);
271 return !poweroff;
272}
273
Stephen Boyd8e6dd772015-05-01 12:45:53 -0700274static unsigned long recalc_stm_pll800c65(struct clk_hw *hw,
Gabriel FERNANDEZb9b8e612014-02-27 16:24:15 +0100275 unsigned long parent_rate)
276{
277 struct clkgen_pll *pll = to_clkgen_pll(hw);
278 unsigned long mdiv, ndiv, pdiv;
279 unsigned long rate;
280 uint64_t res;
281
282 if (!clkgen_pll_is_enabled(hw) || !clkgen_pll_is_locked(hw))
283 return 0;
284
285 pdiv = CLKGEN_READ(pll, pdiv);
286 mdiv = CLKGEN_READ(pll, mdiv);
287 ndiv = CLKGEN_READ(pll, ndiv);
288
289 if (!mdiv)
290 mdiv++; /* mdiv=0 or 1 => MDIV=1 */
291
292 res = (uint64_t)2 * (uint64_t)parent_rate * (uint64_t)ndiv;
293 rate = (unsigned long)div64_u64(res, mdiv * (1 << pdiv));
294
Stephen Boyd836ee0f2015-08-12 11:42:23 -0700295 pr_debug("%s:%s rate %lu\n", clk_hw_get_name(hw), __func__, rate);
Gabriel FERNANDEZb9b8e612014-02-27 16:24:15 +0100296
297 return rate;
298
299}
300
Stephen Boyd8e6dd772015-05-01 12:45:53 -0700301static unsigned long recalc_stm_pll1600c65(struct clk_hw *hw,
Gabriel FERNANDEZb9b8e612014-02-27 16:24:15 +0100302 unsigned long parent_rate)
303{
304 struct clkgen_pll *pll = to_clkgen_pll(hw);
305 unsigned long mdiv, ndiv;
306 unsigned long rate;
307
308 if (!clkgen_pll_is_enabled(hw) || !clkgen_pll_is_locked(hw))
309 return 0;
310
311 mdiv = CLKGEN_READ(pll, mdiv);
312 ndiv = CLKGEN_READ(pll, ndiv);
313
314 if (!mdiv)
315 mdiv = 1;
316
317 /* Note: input is divided by 1000 to avoid overflow */
318 rate = ((2 * (parent_rate / 1000) * ndiv) / mdiv) * 1000;
319
Stephen Boyd836ee0f2015-08-12 11:42:23 -0700320 pr_debug("%s:%s rate %lu\n", clk_hw_get_name(hw), __func__, rate);
Gabriel FERNANDEZb9b8e612014-02-27 16:24:15 +0100321
322 return rate;
323}
324
Stephen Boyd8e6dd772015-05-01 12:45:53 -0700325static unsigned long recalc_stm_pll3200c32(struct clk_hw *hw,
Gabriel FERNANDEZb9b8e612014-02-27 16:24:15 +0100326 unsigned long parent_rate)
327{
328 struct clkgen_pll *pll = to_clkgen_pll(hw);
329 unsigned long ndiv, idf;
330 unsigned long rate = 0;
331
332 if (!clkgen_pll_is_enabled(hw) || !clkgen_pll_is_locked(hw))
333 return 0;
334
335 ndiv = CLKGEN_READ(pll, ndiv);
336 idf = CLKGEN_READ(pll, idf);
337
338 if (idf)
339 /* Note: input is divided to avoid overflow */
340 rate = ((2 * (parent_rate/1000) * ndiv) / idf) * 1000;
341
Stephen Boyd836ee0f2015-08-12 11:42:23 -0700342 pr_debug("%s:%s rate %lu\n", clk_hw_get_name(hw), __func__, rate);
Gabriel FERNANDEZb9b8e612014-02-27 16:24:15 +0100343
344 return rate;
345}
346
Stephen Boyd8e6dd772015-05-01 12:45:53 -0700347static unsigned long recalc_stm_pll1200c32(struct clk_hw *hw,
Gabriel FERNANDEZb9b8e612014-02-27 16:24:15 +0100348 unsigned long parent_rate)
349{
350 struct clkgen_pll *pll = to_clkgen_pll(hw);
351 unsigned long odf, ldf, idf;
352 unsigned long rate;
353
354 if (!clkgen_pll_is_enabled(hw) || !clkgen_pll_is_locked(hw))
355 return 0;
356
357 odf = CLKGEN_READ(pll, odf[0]);
358 ldf = CLKGEN_READ(pll, ldf);
359 idf = CLKGEN_READ(pll, idf);
360
361 if (!idf) /* idf==0 means 1 */
362 idf = 1;
363 if (!odf) /* odf==0 means 1 */
364 odf = 1;
365
366 /* Note: input is divided by 1000 to avoid overflow */
367 rate = (((parent_rate / 1000) * ldf) / (odf * idf)) * 1000;
368
Stephen Boyd836ee0f2015-08-12 11:42:23 -0700369 pr_debug("%s:%s rate %lu\n", clk_hw_get_name(hw), __func__, rate);
Gabriel FERNANDEZb9b8e612014-02-27 16:24:15 +0100370
371 return rate;
372}
373
374static const struct clk_ops st_pll1600c65_ops = {
375 .is_enabled = clkgen_pll_is_enabled,
376 .recalc_rate = recalc_stm_pll1600c65,
377};
378
379static const struct clk_ops st_pll800c65_ops = {
380 .is_enabled = clkgen_pll_is_enabled,
381 .recalc_rate = recalc_stm_pll800c65,
382};
383
384static const struct clk_ops stm_pll3200c32_ops = {
385 .is_enabled = clkgen_pll_is_enabled,
386 .recalc_rate = recalc_stm_pll3200c32,
387};
388
389static const struct clk_ops st_pll1200c32_ops = {
390 .is_enabled = clkgen_pll_is_enabled,
391 .recalc_rate = recalc_stm_pll1200c32,
392};
393
394static struct clk * __init clkgen_pll_register(const char *parent_name,
395 struct clkgen_pll_data *pll_data,
396 void __iomem *reg,
397 const char *clk_name)
398{
399 struct clkgen_pll *pll;
400 struct clk *clk;
401 struct clk_init_data init;
402
403 pll = kzalloc(sizeof(*pll), GFP_KERNEL);
404 if (!pll)
405 return ERR_PTR(-ENOMEM);
406
407 init.name = clk_name;
408 init.ops = pll_data->ops;
409
Pankaj Dev18fee452015-06-23 16:09:24 +0200410 init.flags = CLK_IS_BASIC | CLK_GET_RATE_NOCACHE;
Gabriel FERNANDEZb9b8e612014-02-27 16:24:15 +0100411 init.parent_names = &parent_name;
412 init.num_parents = 1;
413
414 pll->data = pll_data;
415 pll->regs_base = reg;
416 pll->hw.init = &init;
417
418 clk = clk_register(NULL, &pll->hw);
419 if (IS_ERR(clk)) {
420 kfree(pll);
421 return clk;
422 }
423
424 pr_debug("%s: parent %s rate %lu\n",
425 __clk_get_name(clk),
426 __clk_get_name(clk_get_parent(clk)),
427 clk_get_rate(clk));
428
429 return clk;
430}
431
432static struct clk * __init clkgen_c65_lsdiv_register(const char *parent_name,
433 const char *clk_name)
434{
435 struct clk *clk;
436
437 clk = clk_register_fixed_factor(NULL, clk_name, parent_name, 0, 1, 2);
438 if (IS_ERR(clk))
439 return clk;
440
441 pr_debug("%s: parent %s rate %lu\n",
442 __clk_get_name(clk),
443 __clk_get_name(clk_get_parent(clk)),
444 clk_get_rate(clk));
445 return clk;
446}
447
448static void __iomem * __init clkgen_get_register_base(
449 struct device_node *np)
450{
451 struct device_node *pnode;
452 void __iomem *reg = NULL;
453
454 pnode = of_get_parent(np);
455 if (!pnode)
456 return NULL;
457
458 reg = of_iomap(pnode, 0);
459
460 of_node_put(pnode);
461 return reg;
462}
463
464#define CLKGENAx_PLL0_OFFSET 0x0
465#define CLKGENAx_PLL1_OFFSET 0x4
466
467static void __init clkgena_c65_pll_setup(struct device_node *np)
468{
469 const int num_pll_outputs = 3;
470 struct clk_onecell_data *clk_data;
471 const char *parent_name;
472 void __iomem *reg;
473 const char *clk_name;
474
475 parent_name = of_clk_get_parent_name(np, 0);
476 if (!parent_name)
477 return;
478
479 reg = clkgen_get_register_base(np);
480 if (!reg)
481 return;
482
483 clk_data = kzalloc(sizeof(*clk_data), GFP_KERNEL);
484 if (!clk_data)
485 return;
486
487 clk_data->clk_num = num_pll_outputs;
488 clk_data->clks = kzalloc(clk_data->clk_num * sizeof(struct clk *),
489 GFP_KERNEL);
490
491 if (!clk_data->clks)
492 goto err;
493
494 if (of_property_read_string_index(np, "clock-output-names",
495 0, &clk_name))
496 goto err;
497
498 /*
499 * PLL0 HS (high speed) output
500 */
501 clk_data->clks[0] = clkgen_pll_register(parent_name,
Gabriel FERNANDEZdc4febe2014-07-15 17:20:19 +0200502 (struct clkgen_pll_data *) &st_pll1600c65_ax,
503 reg + CLKGENAx_PLL0_OFFSET, clk_name);
Gabriel FERNANDEZb9b8e612014-02-27 16:24:15 +0100504
505 if (IS_ERR(clk_data->clks[0]))
506 goto err;
507
508 if (of_property_read_string_index(np, "clock-output-names",
509 1, &clk_name))
510 goto err;
511
512 /*
513 * PLL0 LS (low speed) output, which is a fixed divide by 2 of the
514 * high speed output.
515 */
516 clk_data->clks[1] = clkgen_c65_lsdiv_register(__clk_get_name
517 (clk_data->clks[0]),
518 clk_name);
519
520 if (IS_ERR(clk_data->clks[1]))
521 goto err;
522
523 if (of_property_read_string_index(np, "clock-output-names",
524 2, &clk_name))
525 goto err;
526
527 /*
528 * PLL1 output
529 */
530 clk_data->clks[2] = clkgen_pll_register(parent_name,
Gabriel FERNANDEZdc4febe2014-07-15 17:20:19 +0200531 (struct clkgen_pll_data *) &st_pll800c65_ax,
532 reg + CLKGENAx_PLL1_OFFSET, clk_name);
Gabriel FERNANDEZb9b8e612014-02-27 16:24:15 +0100533
534 if (IS_ERR(clk_data->clks[2]))
535 goto err;
536
537 of_clk_add_provider(np, of_clk_src_onecell_get, clk_data);
538 return;
539
540err:
541 kfree(clk_data->clks);
542 kfree(clk_data);
543}
544CLK_OF_DECLARE(clkgena_c65_plls,
545 "st,clkgena-plls-c65", clkgena_c65_pll_setup);
546
547static struct clk * __init clkgen_odf_register(const char *parent_name,
Stephen Boyd8e6dd772015-05-01 12:45:53 -0700548 void __iomem *reg,
Gabriel FERNANDEZb9b8e612014-02-27 16:24:15 +0100549 struct clkgen_pll_data *pll_data,
550 int odf,
551 spinlock_t *odf_lock,
552 const char *odf_name)
553{
554 struct clk *clk;
555 unsigned long flags;
556 struct clk_gate *gate;
557 struct clk_divider *div;
558
559 flags = CLK_GET_RATE_NOCACHE | CLK_SET_RATE_GATE;
560
561 gate = kzalloc(sizeof(*gate), GFP_KERNEL);
562 if (!gate)
563 return ERR_PTR(-ENOMEM);
564
565 gate->flags = CLK_GATE_SET_TO_DISABLE;
566 gate->reg = reg + pll_data->odf_gate[odf].offset;
567 gate->bit_idx = pll_data->odf_gate[odf].shift;
568 gate->lock = odf_lock;
569
570 div = kzalloc(sizeof(*div), GFP_KERNEL);
Valentin Ilie72b1c2c2014-04-22 16:15:54 +0300571 if (!div) {
572 kfree(gate);
Gabriel FERNANDEZb9b8e612014-02-27 16:24:15 +0100573 return ERR_PTR(-ENOMEM);
Valentin Ilie72b1c2c2014-04-22 16:15:54 +0300574 }
Gabriel FERNANDEZb9b8e612014-02-27 16:24:15 +0100575
576 div->flags = CLK_DIVIDER_ONE_BASED | CLK_DIVIDER_ALLOW_ZERO;
577 div->reg = reg + pll_data->odf[odf].offset;
578 div->shift = pll_data->odf[odf].shift;
579 div->width = fls(pll_data->odf[odf].mask);
580 div->lock = odf_lock;
581
582 clk = clk_register_composite(NULL, odf_name, &parent_name, 1,
583 NULL, NULL,
584 &div->hw, &clk_divider_ops,
585 &gate->hw, &clk_gate_ops,
586 flags);
587 if (IS_ERR(clk))
588 return clk;
589
590 pr_debug("%s: parent %s rate %lu\n",
591 __clk_get_name(clk),
592 __clk_get_name(clk_get_parent(clk)),
593 clk_get_rate(clk));
594 return clk;
595}
596
Fabian Frederickf3755732015-03-31 20:50:42 +0200597static const struct of_device_id c32_pll_of_match[] = {
Gabriel FERNANDEZb9b8e612014-02-27 16:24:15 +0100598 {
599 .compatible = "st,plls-c32-a1x-0",
600 .data = &st_pll3200c32_a1x_0,
601 },
602 {
603 .compatible = "st,plls-c32-a1x-1",
604 .data = &st_pll3200c32_a1x_1,
605 },
Gabriel FERNANDEZec8d27b2014-02-27 16:24:18 +0100606 {
607 .compatible = "st,stih415-plls-c32-a9",
608 .data = &st_pll3200c32_a9_415,
609 },
610 {
611 .compatible = "st,stih415-plls-c32-ddr",
612 .data = &st_pll3200c32_ddr_415,
613 },
614 {
615 .compatible = "st,stih416-plls-c32-a9",
616 .data = &st_pll3200c32_a9_416,
617 },
618 {
619 .compatible = "st,stih416-plls-c32-ddr",
620 .data = &st_pll3200c32_ddr_416,
621 },
Gabriel FERNANDEZeee8f782014-07-15 17:20:24 +0200622 {
623 .compatible = "st,stih407-plls-c32-a0",
624 .data = &st_pll3200c32_407_a0,
625 },
Gabriel FERNANDEZ51306d52014-07-15 17:20:27 +0200626 {
Gabriel Fernandezd34e2102015-09-16 09:42:59 +0200627 .compatible = "st,plls-c32-cx_0",
628 .data = &st_pll3200c32_cx_0,
Gabriel FERNANDEZ51306d52014-07-15 17:20:27 +0200629 },
630 {
Gabriel Fernandezd34e2102015-09-16 09:42:59 +0200631 .compatible = "st,plls-c32-cx_1",
632 .data = &st_pll3200c32_cx_1,
Gabriel FERNANDEZ51306d52014-07-15 17:20:27 +0200633 },
Gabriel FERNANDEZaaa65d72014-07-15 17:20:29 +0200634 {
635 .compatible = "st,stih407-plls-c32-a9",
636 .data = &st_pll3200c32_407_a9,
637 },
Gabriel FERNANDEZb9b8e612014-02-27 16:24:15 +0100638 {}
639};
640
641static void __init clkgen_c32_pll_setup(struct device_node *np)
642{
643 const struct of_device_id *match;
644 struct clk *clk;
645 const char *parent_name, *pll_name;
646 void __iomem *pll_base;
647 int num_odfs, odf;
648 struct clk_onecell_data *clk_data;
649 struct clkgen_pll_data *data;
650
651 match = of_match_node(c32_pll_of_match, np);
652 if (!match) {
653 pr_err("%s: No matching data\n", __func__);
654 return;
655 }
656
657 data = (struct clkgen_pll_data *) match->data;
658
659 parent_name = of_clk_get_parent_name(np, 0);
660 if (!parent_name)
661 return;
662
663 pll_base = clkgen_get_register_base(np);
664 if (!pll_base)
665 return;
666
667 clk = clkgen_pll_register(parent_name, data, pll_base, np->name);
668 if (IS_ERR(clk))
669 return;
670
671 pll_name = __clk_get_name(clk);
672
673 num_odfs = data->num_odfs;
674
675 clk_data = kzalloc(sizeof(*clk_data), GFP_KERNEL);
676 if (!clk_data)
677 return;
678
679 clk_data->clk_num = num_odfs;
680 clk_data->clks = kzalloc(clk_data->clk_num * sizeof(struct clk *),
681 GFP_KERNEL);
682
683 if (!clk_data->clks)
684 goto err;
685
686 for (odf = 0; odf < num_odfs; odf++) {
687 struct clk *clk;
688 const char *clk_name;
689
690 if (of_property_read_string_index(np, "clock-output-names",
691 odf, &clk_name))
692 return;
693
694 clk = clkgen_odf_register(pll_name, pll_base, data,
695 odf, &clkgena_c32_odf_lock, clk_name);
696 if (IS_ERR(clk))
697 goto err;
698
699 clk_data->clks[odf] = clk;
700 }
701
702 of_clk_add_provider(np, of_clk_src_onecell_get, clk_data);
703 return;
704
705err:
706 kfree(pll_name);
707 kfree(clk_data->clks);
708 kfree(clk_data);
709}
710CLK_OF_DECLARE(clkgen_c32_pll, "st,clkgen-plls-c32", clkgen_c32_pll_setup);
Gabriel FERNANDEZec8d27b2014-02-27 16:24:18 +0100711
Fabian Frederickf3755732015-03-31 20:50:42 +0200712static const struct of_device_id c32_gpu_pll_of_match[] = {
Gabriel FERNANDEZec8d27b2014-02-27 16:24:18 +0100713 {
714 .compatible = "st,stih415-gpu-pll-c32",
715 .data = &st_pll1200c32_gpu_415,
716 },
717 {
718 .compatible = "st,stih416-gpu-pll-c32",
719 .data = &st_pll1200c32_gpu_416,
720 },
Stephen Boyd70040b32014-05-23 17:16:50 -0700721 {}
Gabriel FERNANDEZec8d27b2014-02-27 16:24:18 +0100722};
723
724static void __init clkgengpu_c32_pll_setup(struct device_node *np)
725{
726 const struct of_device_id *match;
727 struct clk *clk;
728 const char *parent_name;
729 void __iomem *reg;
730 const char *clk_name;
731 struct clkgen_pll_data *data;
732
733 match = of_match_node(c32_gpu_pll_of_match, np);
734 if (!match) {
735 pr_err("%s: No matching data\n", __func__);
736 return;
737 }
738
739 data = (struct clkgen_pll_data *)match->data;
740
741 parent_name = of_clk_get_parent_name(np, 0);
742 if (!parent_name)
743 return;
744
745 reg = clkgen_get_register_base(np);
746 if (!reg)
747 return;
748
749 if (of_property_read_string_index(np, "clock-output-names",
750 0, &clk_name))
751 return;
752
753 /*
754 * PLL 1200MHz output
755 */
756 clk = clkgen_pll_register(parent_name, data, reg, clk_name);
757
758 if (!IS_ERR(clk))
759 of_clk_add_provider(np, of_clk_src_simple_get, clk);
760
761 return;
762}
763CLK_OF_DECLARE(clkgengpu_c32_pll,
764 "st,clkgengpu-pll-c32", clkgengpu_c32_pll_setup);