blob: d52f976dc875f2986556fa493a1a8c433450110f [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Linus Walleij91b87a42012-06-11 17:29:54 +02002/*
3 * Driver for the ICST307 VCO clock found in the ARM Reference designs.
4 * We wrap the custom interface from <asm/hardware/icst.h> into the generic
5 * clock framework.
6 *
Linus Walleijd4308192015-10-13 14:29:54 +02007 * Copyright (C) 2012-2015 Linus Walleij
Linus Walleij401301c2012-11-20 22:39:31 +01008 *
Linus Walleij91b87a42012-06-11 17:29:54 +02009 * TODO: when all ARM reference designs are migrated to generic clocks, the
10 * ICST clock code from the ARM tree should probably be merged into this
11 * file.
12 */
Stephen Boyd6d31e3b22015-06-19 15:00:46 -070013#include <linux/kernel.h>
14#include <linux/slab.h>
15#include <linux/export.h>
Linus Walleij91b87a42012-06-11 17:29:54 +020016#include <linux/err.h>
17#include <linux/clk-provider.h>
Linus Walleij7a9ad672012-11-20 23:01:04 +010018#include <linux/io.h>
Linus Walleij179c8fb2015-10-12 15:52:50 +020019#include <linux/regmap.h>
Linus Walleij384d9772015-10-12 16:14:28 +020020#include <linux/mfd/syscon.h>
Linus Walleij91b87a42012-06-11 17:29:54 +020021
Linus Walleijba3fae02017-02-01 10:41:43 +010022#include "icst.h"
Linus Walleij91b87a42012-06-11 17:29:54 +020023#include "clk-icst.h"
24
Linus Walleij179c8fb2015-10-12 15:52:50 +020025/* Magic unlocking token used on all Versatile boards */
26#define VERSATILE_LOCK_VAL 0xA05F
27
Linus Walleij5e23c592016-08-22 11:19:33 +020028#define VERSATILE_AUX_OSC_BITS 0x7FFFF
29#define INTEGRATOR_AP_CM_BITS 0xFF
Linus Walleijfa62e102016-08-27 14:01:19 +020030#define INTEGRATOR_AP_SYS_BITS 0xFF
Linus Walleij5e23c592016-08-22 11:19:33 +020031#define INTEGRATOR_CP_CM_CORE_BITS 0x7FF
32#define INTEGRATOR_CP_CM_MEM_BITS 0x7FF000
33
Linus Walleijfa62e102016-08-27 14:01:19 +020034#define INTEGRATOR_AP_PCI_25_33_MHZ BIT(8)
35
Linus Walleij5e23c592016-08-22 11:19:33 +020036/**
Linus Walleij91b87a42012-06-11 17:29:54 +020037 * struct clk_icst - ICST VCO clock wrapper
38 * @hw: corresponding clock hardware entry
Lee Jones0c1d46d2021-01-20 09:30:39 +000039 * @map: register map
40 * @vcoreg_off: VCO register address
41 * @lockreg_off: VCO lock register address
Linus Walleij91b87a42012-06-11 17:29:54 +020042 * @params: parameters for this ICST instance
43 * @rate: current rate
Linus Walleij5e23c592016-08-22 11:19:33 +020044 * @ctype: the type of control register for the ICST
Linus Walleij91b87a42012-06-11 17:29:54 +020045 */
46struct clk_icst {
47 struct clk_hw hw;
Linus Walleij179c8fb2015-10-12 15:52:50 +020048 struct regmap *map;
49 u32 vcoreg_off;
50 u32 lockreg_off;
Linus Walleija183da62014-01-20 21:46:46 +010051 struct icst_params *params;
Linus Walleij91b87a42012-06-11 17:29:54 +020052 unsigned long rate;
Linus Walleij5e23c592016-08-22 11:19:33 +020053 enum icst_control_type ctype;
Linus Walleij91b87a42012-06-11 17:29:54 +020054};
55
56#define to_icst(_hw) container_of(_hw, struct clk_icst, hw)
57
Linus Walleij7a9ad672012-11-20 23:01:04 +010058/**
Linus Walleij179c8fb2015-10-12 15:52:50 +020059 * vco_get() - get ICST VCO settings from a certain ICST
60 * @icst: the ICST clock to get
61 * @vco: the VCO struct to return the value in
Linus Walleij7a9ad672012-11-20 23:01:04 +010062 */
Linus Walleij179c8fb2015-10-12 15:52:50 +020063static int vco_get(struct clk_icst *icst, struct icst_vco *vco)
Linus Walleij7a9ad672012-11-20 23:01:04 +010064{
65 u32 val;
Linus Walleij179c8fb2015-10-12 15:52:50 +020066 int ret;
Linus Walleij7a9ad672012-11-20 23:01:04 +010067
Linus Walleij179c8fb2015-10-12 15:52:50 +020068 ret = regmap_read(icst->map, icst->vcoreg_off, &val);
69 if (ret)
70 return ret;
Linus Walleij5e23c592016-08-22 11:19:33 +020071
72 /*
73 * The Integrator/AP core clock can only access the low eight
74 * bits of the v PLL divider. Bit 8 is tied low and always zero,
75 * r is hardwired to 22 and output divider s is hardwired to 1
76 * (divide by 2) according to the document
77 * "Integrator CM926EJ-S, CM946E-S, CM966E-S, CM1026EJ-S and
78 * CM1136JF-S User Guide" ARM DUI 0138E, page 3-13 thru 3-14.
79 */
80 if (icst->ctype == ICST_INTEGRATOR_AP_CM) {
81 vco->v = val & INTEGRATOR_AP_CM_BITS;
82 vco->r = 22;
83 vco->s = 1;
84 return 0;
85 }
86
87 /*
Linus Walleijfa62e102016-08-27 14:01:19 +020088 * The Integrator/AP system clock on the base board can only
89 * access the low eight bits of the v PLL divider. Bit 8 is tied low
90 * and always zero, r is hardwired to 46, and the output divider is
91 * hardwired to 3 (divide by 4) according to the document
92 * "Integrator AP ASIC Development Motherboard" ARM DUI 0098B,
93 * page 3-16.
94 */
95 if (icst->ctype == ICST_INTEGRATOR_AP_SYS) {
96 vco->v = val & INTEGRATOR_AP_SYS_BITS;
97 vco->r = 46;
98 vco->s = 3;
99 return 0;
100 }
101
102 /*
103 * The Integrator/AP PCI clock is using an odd pattern to create
104 * the child clock, basically a single bit called DIVX/Y is used
105 * to select between two different hardwired values: setting the
106 * bit to 0 yields v = 17, r = 22 and OD = 1, whereas setting the
107 * bit to 1 yields v = 14, r = 14 and OD = 1 giving the frequencies
108 * 33 or 25 MHz respectively.
109 */
110 if (icst->ctype == ICST_INTEGRATOR_AP_PCI) {
111 bool divxy = !!(val & INTEGRATOR_AP_PCI_25_33_MHZ);
112
113 vco->v = divxy ? 17 : 14;
114 vco->r = divxy ? 22 : 14;
115 vco->s = 1;
116 return 0;
117 }
118
119 /*
Linus Walleij5e23c592016-08-22 11:19:33 +0200120 * The Integrator/CP core clock can access the low eight bits
121 * of the v PLL divider. Bit 8 is tied low and always zero,
122 * r is hardwired to 22 and the output divider s is accessible
123 * in bits 8 thru 10 according to the document
124 * "Integrator/CM940T, CM920T, CM740T, and CM720T User Guide"
125 * ARM DUI 0157A, page 3-20 thru 3-23 and 4-10.
126 */
127 if (icst->ctype == ICST_INTEGRATOR_CP_CM_CORE) {
128 vco->v = val & 0xFF;
129 vco->r = 22;
130 vco->s = (val >> 8) & 7;
131 return 0;
132 }
133
134 if (icst->ctype == ICST_INTEGRATOR_CP_CM_MEM) {
135 vco->v = (val >> 12) & 0xFF;
136 vco->r = 22;
137 vco->s = (val >> 20) & 7;
138 return 0;
139 }
140
Linus Walleij179c8fb2015-10-12 15:52:50 +0200141 vco->v = val & 0x1ff;
142 vco->r = (val >> 9) & 0x7f;
143 vco->s = (val >> 16) & 03;
144 return 0;
Linus Walleij7a9ad672012-11-20 23:01:04 +0100145}
146
147/**
148 * vco_set() - commit changes to an ICST VCO
Linus Walleij179c8fb2015-10-12 15:52:50 +0200149 * @icst: the ICST clock to set
150 * @vco: the VCO struct to set the changes from
Linus Walleij7a9ad672012-11-20 23:01:04 +0100151 */
Linus Walleij179c8fb2015-10-12 15:52:50 +0200152static int vco_set(struct clk_icst *icst, struct icst_vco vco)
Linus Walleij7a9ad672012-11-20 23:01:04 +0100153{
Linus Walleij5e23c592016-08-22 11:19:33 +0200154 u32 mask;
Linus Walleij7a9ad672012-11-20 23:01:04 +0100155 u32 val;
Linus Walleij179c8fb2015-10-12 15:52:50 +0200156 int ret;
Linus Walleij7a9ad672012-11-20 23:01:04 +0100157
Linus Walleij5e23c592016-08-22 11:19:33 +0200158 /* Mask the bits used by the VCO */
159 switch (icst->ctype) {
160 case ICST_INTEGRATOR_AP_CM:
161 mask = INTEGRATOR_AP_CM_BITS;
162 val = vco.v & 0xFF;
163 if (vco.v & 0x100)
164 pr_err("ICST error: tried to set bit 8 of VDW\n");
165 if (vco.s != 1)
166 pr_err("ICST error: tried to use VOD != 1\n");
167 if (vco.r != 22)
168 pr_err("ICST error: tried to use RDW != 22\n");
169 break;
Linus Walleijfa62e102016-08-27 14:01:19 +0200170 case ICST_INTEGRATOR_AP_SYS:
171 mask = INTEGRATOR_AP_SYS_BITS;
172 val = vco.v & 0xFF;
173 if (vco.v & 0x100)
174 pr_err("ICST error: tried to set bit 8 of VDW\n");
175 if (vco.s != 3)
176 pr_err("ICST error: tried to use VOD != 1\n");
177 if (vco.r != 46)
178 pr_err("ICST error: tried to use RDW != 22\n");
179 break;
Linus Walleij5e23c592016-08-22 11:19:33 +0200180 case ICST_INTEGRATOR_CP_CM_CORE:
181 mask = INTEGRATOR_CP_CM_CORE_BITS; /* Uses 12 bits */
182 val = (vco.v & 0xFF) | vco.s << 8;
183 if (vco.v & 0x100)
184 pr_err("ICST error: tried to set bit 8 of VDW\n");
185 if (vco.r != 22)
186 pr_err("ICST error: tried to use RDW != 22\n");
187 break;
188 case ICST_INTEGRATOR_CP_CM_MEM:
189 mask = INTEGRATOR_CP_CM_MEM_BITS; /* Uses 12 bits */
190 val = ((vco.v & 0xFF) << 12) | (vco.s << 20);
191 if (vco.v & 0x100)
192 pr_err("ICST error: tried to set bit 8 of VDW\n");
193 if (vco.r != 22)
194 pr_err("ICST error: tried to use RDW != 22\n");
195 break;
196 default:
197 /* Regular auxilary oscillator */
198 mask = VERSATILE_AUX_OSC_BITS;
199 val = vco.v | (vco.r << 9) | (vco.s << 16);
200 break;
201 }
Linus Walleijdf9cd562016-02-03 14:47:08 +0100202
Linus Walleij5e23c592016-08-22 11:19:33 +0200203 pr_debug("ICST: new val = 0x%08x\n", val);
Linus Walleij7a9ad672012-11-20 23:01:04 +0100204
205 /* This magic unlocks the VCO so it can be controlled */
Linus Walleij179c8fb2015-10-12 15:52:50 +0200206 ret = regmap_write(icst->map, icst->lockreg_off, VERSATILE_LOCK_VAL);
207 if (ret)
208 return ret;
Linus Walleij5e23c592016-08-22 11:19:33 +0200209 ret = regmap_update_bits(icst->map, icst->vcoreg_off, mask, val);
Linus Walleij179c8fb2015-10-12 15:52:50 +0200210 if (ret)
211 return ret;
Linus Walleij7a9ad672012-11-20 23:01:04 +0100212 /* This locks the VCO again */
Linus Walleij179c8fb2015-10-12 15:52:50 +0200213 ret = regmap_write(icst->map, icst->lockreg_off, 0);
214 if (ret)
215 return ret;
216 return 0;
Linus Walleij7a9ad672012-11-20 23:01:04 +0100217}
218
Linus Walleij91b87a42012-06-11 17:29:54 +0200219static unsigned long icst_recalc_rate(struct clk_hw *hw,
220 unsigned long parent_rate)
221{
222 struct clk_icst *icst = to_icst(hw);
223 struct icst_vco vco;
Linus Walleij179c8fb2015-10-12 15:52:50 +0200224 int ret;
Linus Walleij91b87a42012-06-11 17:29:54 +0200225
Linus Walleija183da62014-01-20 21:46:46 +0100226 if (parent_rate)
227 icst->params->ref = parent_rate;
Linus Walleij179c8fb2015-10-12 15:52:50 +0200228 ret = vco_get(icst, &vco);
229 if (ret) {
230 pr_err("ICST: could not get VCO setting\n");
231 return 0;
232 }
Linus Walleij91b87a42012-06-11 17:29:54 +0200233 icst->rate = icst_hz(icst->params, vco);
234 return icst->rate;
235}
236
237static long icst_round_rate(struct clk_hw *hw, unsigned long rate,
238 unsigned long *prate)
239{
240 struct clk_icst *icst = to_icst(hw);
241 struct icst_vco vco;
242
Linus Walleij5e23c592016-08-22 11:19:33 +0200243 if (icst->ctype == ICST_INTEGRATOR_AP_CM ||
244 icst->ctype == ICST_INTEGRATOR_CP_CM_CORE) {
245 if (rate <= 12000000)
246 return 12000000;
247 if (rate >= 160000000)
248 return 160000000;
249 /* Slam to closest megahertz */
250 return DIV_ROUND_CLOSEST(rate, 1000000) * 1000000;
251 }
252
253 if (icst->ctype == ICST_INTEGRATOR_CP_CM_MEM) {
254 if (rate <= 6000000)
255 return 6000000;
256 if (rate >= 66000000)
257 return 66000000;
258 /* Slam to closest 0.5 megahertz */
259 return DIV_ROUND_CLOSEST(rate, 500000) * 500000;
260 }
261
Linus Walleijfa62e102016-08-27 14:01:19 +0200262 if (icst->ctype == ICST_INTEGRATOR_AP_SYS) {
263 /* Divides between 3 and 50 MHz in steps of 0.25 MHz */
264 if (rate <= 3000000)
265 return 3000000;
266 if (rate >= 50000000)
267 return 5000000;
268 /* Slam to closest 0.25 MHz */
269 return DIV_ROUND_CLOSEST(rate, 250000) * 250000;
270 }
271
272 if (icst->ctype == ICST_INTEGRATOR_AP_PCI) {
273 /*
274 * If we're below or less than halfway from 25 to 33 MHz
275 * select 25 MHz
276 */
277 if (rate <= 25000000 || rate < 29000000)
278 return 25000000;
279 /* Else just return the default frequency */
280 return 33000000;
281 }
282
Linus Walleij91b87a42012-06-11 17:29:54 +0200283 vco = icst_hz_to_vco(icst->params, rate);
284 return icst_hz(icst->params, vco);
285}
286
287static int icst_set_rate(struct clk_hw *hw, unsigned long rate,
288 unsigned long parent_rate)
289{
290 struct clk_icst *icst = to_icst(hw);
291 struct icst_vco vco;
292
Linus Walleijfa62e102016-08-27 14:01:19 +0200293 if (icst->ctype == ICST_INTEGRATOR_AP_PCI) {
294 /* This clock is especially primitive */
295 unsigned int val;
296 int ret;
297
298 if (rate == 25000000) {
299 val = 0;
300 } else if (rate == 33000000) {
301 val = INTEGRATOR_AP_PCI_25_33_MHZ;
302 } else {
303 pr_err("ICST: cannot set PCI frequency %lu\n",
304 rate);
305 return -EINVAL;
306 }
307 ret = regmap_write(icst->map, icst->lockreg_off,
308 VERSATILE_LOCK_VAL);
309 if (ret)
310 return ret;
311 ret = regmap_update_bits(icst->map, icst->vcoreg_off,
312 INTEGRATOR_AP_PCI_25_33_MHZ,
313 val);
314 if (ret)
315 return ret;
316 /* This locks the VCO again */
317 ret = regmap_write(icst->map, icst->lockreg_off, 0);
318 if (ret)
319 return ret;
320 return 0;
321 }
322
Linus Walleija183da62014-01-20 21:46:46 +0100323 if (parent_rate)
324 icst->params->ref = parent_rate;
Linus Walleij91b87a42012-06-11 17:29:54 +0200325 vco = icst_hz_to_vco(icst->params, rate);
326 icst->rate = icst_hz(icst->params, vco);
Linus Walleij179c8fb2015-10-12 15:52:50 +0200327 return vco_set(icst, vco);
Linus Walleij91b87a42012-06-11 17:29:54 +0200328}
329
330static const struct clk_ops icst_ops = {
331 .recalc_rate = icst_recalc_rate,
332 .round_rate = icst_round_rate,
333 .set_rate = icst_set_rate,
334};
335
Linus Walleijeb9d6422020-02-19 11:33:25 +0100336struct clk *icst_clk_setup(struct device *dev,
337 const struct clk_icst_desc *desc,
338 const char *name,
339 const char *parent_name,
340 struct regmap *map,
341 enum icst_control_type ctype)
Linus Walleij91b87a42012-06-11 17:29:54 +0200342{
343 struct clk *clk;
344 struct clk_icst *icst;
345 struct clk_init_data init;
Linus Walleija183da62014-01-20 21:46:46 +0100346 struct icst_params *pclone;
Linus Walleij91b87a42012-06-11 17:29:54 +0200347
Markus Elfringa72da432017-09-27 21:24:43 +0200348 icst = kzalloc(sizeof(*icst), GFP_KERNEL);
Markus Elfringe343b812017-09-27 21:21:23 +0200349 if (!icst)
Linus Walleij91b87a42012-06-11 17:29:54 +0200350 return ERR_PTR(-ENOMEM);
Linus Walleija183da62014-01-20 21:46:46 +0100351
352 pclone = kmemdup(desc->params, sizeof(*pclone), GFP_KERNEL);
353 if (!pclone) {
Colin Ian Kingab7ad352014-04-12 18:59:14 +0100354 kfree(icst);
Linus Walleija183da62014-01-20 21:46:46 +0100355 return ERR_PTR(-ENOMEM);
356 }
357
Linus Walleijae6e6942013-11-22 11:30:05 +0100358 init.name = name;
Linus Walleij91b87a42012-06-11 17:29:54 +0200359 init.ops = &icst_ops;
Stephen Boydac82a8b2016-03-01 11:00:05 -0800360 init.flags = 0;
Linus Walleija183da62014-01-20 21:46:46 +0100361 init.parent_names = (parent_name ? &parent_name : NULL);
362 init.num_parents = (parent_name ? 1 : 0);
Linus Walleij384d9772015-10-12 16:14:28 +0200363 icst->map = map;
Linus Walleij91b87a42012-06-11 17:29:54 +0200364 icst->hw.init = &init;
Linus Walleija183da62014-01-20 21:46:46 +0100365 icst->params = pclone;
Linus Walleij179c8fb2015-10-12 15:52:50 +0200366 icst->vcoreg_off = desc->vco_offset;
367 icst->lockreg_off = desc->lock_offset;
Linus Walleij5e23c592016-08-22 11:19:33 +0200368 icst->ctype = ctype;
Linus Walleij91b87a42012-06-11 17:29:54 +0200369
370 clk = clk_register(dev, &icst->hw);
Linus Walleij7bdccef2015-10-23 11:36:01 +0200371 if (IS_ERR(clk)) {
372 kfree(pclone);
Linus Walleij91b87a42012-06-11 17:29:54 +0200373 kfree(icst);
Linus Walleij7bdccef2015-10-23 11:36:01 +0200374 }
Linus Walleij91b87a42012-06-11 17:29:54 +0200375
376 return clk;
377}
Linus Walleijeb9d6422020-02-19 11:33:25 +0100378EXPORT_SYMBOL_GPL(icst_clk_setup);
Linus Walleij384d9772015-10-12 16:14:28 +0200379
380struct clk *icst_clk_register(struct device *dev,
381 const struct clk_icst_desc *desc,
382 const char *name,
383 const char *parent_name,
384 void __iomem *base)
385{
386 struct regmap_config icst_regmap_conf = {
387 .reg_bits = 32,
388 .val_bits = 32,
389 .reg_stride = 4,
390 };
391 struct regmap *map;
392
393 map = regmap_init_mmio(dev, base, &icst_regmap_conf);
394 if (IS_ERR(map)) {
395 pr_err("could not initialize ICST regmap\n");
396 return ERR_CAST(map);
397 }
Linus Walleij5e23c592016-08-22 11:19:33 +0200398 return icst_clk_setup(dev, desc, name, parent_name, map,
399 ICST_VERSATILE);
Linus Walleij384d9772015-10-12 16:14:28 +0200400}
Arnd Bergmanna218d7f2014-05-08 16:56:16 +0200401EXPORT_SYMBOL_GPL(icst_clk_register);
Linus Walleijd4308192015-10-13 14:29:54 +0200402
403#ifdef CONFIG_OF
404/*
405 * In a device tree, an memory-mapped ICST clock appear as a child
406 * of a syscon node. Assume this and probe it only as a child of a
407 * syscon.
408 */
409
410static const struct icst_params icst525_params = {
411 .vco_max = ICST525_VCO_MAX_5V,
412 .vco_min = ICST525_VCO_MIN,
413 .vd_min = 8,
414 .vd_max = 263,
415 .rd_min = 3,
416 .rd_max = 65,
417 .s2div = icst525_s2div,
418 .idx2s = icst525_idx2s,
419};
420
421static const struct icst_params icst307_params = {
422 .vco_max = ICST307_VCO_MAX,
423 .vco_min = ICST307_VCO_MIN,
424 .vd_min = 4 + 8,
425 .vd_max = 511 + 8,
426 .rd_min = 1 + 2,
427 .rd_max = 127 + 2,
428 .s2div = icst307_s2div,
429 .idx2s = icst307_idx2s,
430};
431
Lee Jones0c1d46d2021-01-20 09:30:39 +0000432/*
Linus Walleij5e23c592016-08-22 11:19:33 +0200433 * The core modules on the Integrator/AP and Integrator/CP have
434 * especially crippled ICST525 control.
435 */
436static const struct icst_params icst525_apcp_cm_params = {
437 .vco_max = ICST525_VCO_MAX_5V,
438 .vco_min = ICST525_VCO_MIN,
439 /* Minimum 12 MHz, VDW = 4 */
440 .vd_min = 12,
441 /*
442 * Maximum 160 MHz, VDW = 152 for all core modules, but
443 * CM926EJ-S, CM1026EJ-S and CM1136JF-S can actually
444 * go to 200 MHz (max VDW = 192).
445 */
446 .vd_max = 192,
447 /* r is hardcoded to 22 and this is the actual divisor, +2 */
448 .rd_min = 24,
449 .rd_max = 24,
450 .s2div = icst525_s2div,
451 .idx2s = icst525_idx2s,
452};
453
Linus Walleijfa62e102016-08-27 14:01:19 +0200454static const struct icst_params icst525_ap_sys_params = {
455 .vco_max = ICST525_VCO_MAX_5V,
456 .vco_min = ICST525_VCO_MIN,
457 /* Minimum 3 MHz, VDW = 4 */
458 .vd_min = 3,
459 /* Maximum 50 MHz, VDW = 192 */
460 .vd_max = 50,
461 /* r is hardcoded to 46 and this is the actual divisor, +2 */
462 .rd_min = 48,
463 .rd_max = 48,
464 .s2div = icst525_s2div,
465 .idx2s = icst525_idx2s,
466};
467
468static const struct icst_params icst525_ap_pci_params = {
469 .vco_max = ICST525_VCO_MAX_5V,
470 .vco_min = ICST525_VCO_MIN,
471 /* Minimum 25 MHz */
472 .vd_min = 25,
473 /* Maximum 33 MHz */
474 .vd_max = 33,
475 /* r is hardcoded to 14 or 22 and this is the actual divisors +2 */
476 .rd_min = 16,
477 .rd_max = 24,
478 .s2div = icst525_s2div,
479 .idx2s = icst525_idx2s,
480};
481
Linus Walleijd4308192015-10-13 14:29:54 +0200482static void __init of_syscon_icst_setup(struct device_node *np)
483{
484 struct device_node *parent;
485 struct regmap *map;
486 struct clk_icst_desc icst_desc;
Rob Herring1b2189f2021-11-09 10:46:50 -0600487 const char *name;
Linus Walleijd4308192015-10-13 14:29:54 +0200488 const char *parent_name;
489 struct clk *regclk;
Linus Walleij5e23c592016-08-22 11:19:33 +0200490 enum icst_control_type ctype;
Linus Walleijd4308192015-10-13 14:29:54 +0200491
492 /* We do not release this reference, we are using it perpetually */
493 parent = of_get_parent(np);
494 if (!parent) {
495 pr_err("no parent node for syscon ICST clock\n");
496 return;
497 }
498 map = syscon_node_to_regmap(parent);
499 if (IS_ERR(map)) {
500 pr_err("no regmap for syscon ICST clock parent\n");
501 return;
502 }
503
Rob Herring69bfe082021-09-13 14:28:13 -0500504 if (of_property_read_u32(np, "reg", &icst_desc.vco_offset) &&
505 of_property_read_u32(np, "vco-offset", &icst_desc.vco_offset)) {
Linus Walleijd4308192015-10-13 14:29:54 +0200506 pr_err("no VCO register offset for ICST clock\n");
507 return;
508 }
509 if (of_property_read_u32(np, "lock-offset", &icst_desc.lock_offset)) {
510 pr_err("no lock register offset for ICST clock\n");
511 return;
512 }
513
Linus Walleij5e23c592016-08-22 11:19:33 +0200514 if (of_device_is_compatible(np, "arm,syscon-icst525")) {
Linus Walleijd4308192015-10-13 14:29:54 +0200515 icst_desc.params = &icst525_params;
Linus Walleij5e23c592016-08-22 11:19:33 +0200516 ctype = ICST_VERSATILE;
517 } else if (of_device_is_compatible(np, "arm,syscon-icst307")) {
Linus Walleijd4308192015-10-13 14:29:54 +0200518 icst_desc.params = &icst307_params;
Linus Walleij5e23c592016-08-22 11:19:33 +0200519 ctype = ICST_VERSATILE;
520 } else if (of_device_is_compatible(np, "arm,syscon-icst525-integratorap-cm")) {
521 icst_desc.params = &icst525_apcp_cm_params;
522 ctype = ICST_INTEGRATOR_AP_CM;
Linus Walleijfa62e102016-08-27 14:01:19 +0200523 } else if (of_device_is_compatible(np, "arm,syscon-icst525-integratorap-sys")) {
524 icst_desc.params = &icst525_ap_sys_params;
525 ctype = ICST_INTEGRATOR_AP_SYS;
526 } else if (of_device_is_compatible(np, "arm,syscon-icst525-integratorap-pci")) {
527 icst_desc.params = &icst525_ap_pci_params;
528 ctype = ICST_INTEGRATOR_AP_PCI;
Linus Walleij5e23c592016-08-22 11:19:33 +0200529 } else if (of_device_is_compatible(np, "arm,syscon-icst525-integratorcp-cm-core")) {
530 icst_desc.params = &icst525_apcp_cm_params;
531 ctype = ICST_INTEGRATOR_CP_CM_CORE;
532 } else if (of_device_is_compatible(np, "arm,syscon-icst525-integratorcp-cm-mem")) {
533 icst_desc.params = &icst525_apcp_cm_params;
534 ctype = ICST_INTEGRATOR_CP_CM_MEM;
535 } else {
Rob Herring1b2189f2021-11-09 10:46:50 -0600536 pr_err("unknown ICST clock %pOF\n", np);
Linus Walleijd4308192015-10-13 14:29:54 +0200537 return;
538 }
539
540 /* Parent clock name is not the same as node parent */
541 parent_name = of_clk_get_parent_name(np, 0);
Rob Herring1b2189f2021-11-09 10:46:50 -0600542 name = kasprintf(GFP_KERNEL, "%pOFP", np);
Linus Walleijd4308192015-10-13 14:29:54 +0200543
Linus Walleij5e23c592016-08-22 11:19:33 +0200544 regclk = icst_clk_setup(NULL, &icst_desc, name, parent_name, map, ctype);
Linus Walleijd4308192015-10-13 14:29:54 +0200545 if (IS_ERR(regclk)) {
Rob Herring1b2189f2021-11-09 10:46:50 -0600546 kfree(name);
Linus Walleijd4308192015-10-13 14:29:54 +0200547 pr_err("error setting up syscon ICST clock %s\n", name);
548 return;
549 }
550 of_clk_add_provider(np, of_clk_src_simple_get, regclk);
551 pr_debug("registered syscon ICST clock %s\n", name);
552}
553
554CLK_OF_DECLARE(arm_syscon_icst525_clk,
555 "arm,syscon-icst525", of_syscon_icst_setup);
556CLK_OF_DECLARE(arm_syscon_icst307_clk,
557 "arm,syscon-icst307", of_syscon_icst_setup);
Linus Walleij5e23c592016-08-22 11:19:33 +0200558CLK_OF_DECLARE(arm_syscon_integratorap_cm_clk,
559 "arm,syscon-icst525-integratorap-cm", of_syscon_icst_setup);
Linus Walleijfa62e102016-08-27 14:01:19 +0200560CLK_OF_DECLARE(arm_syscon_integratorap_sys_clk,
561 "arm,syscon-icst525-integratorap-sys", of_syscon_icst_setup);
562CLK_OF_DECLARE(arm_syscon_integratorap_pci_clk,
563 "arm,syscon-icst525-integratorap-pci", of_syscon_icst_setup);
Linus Walleij5e23c592016-08-22 11:19:33 +0200564CLK_OF_DECLARE(arm_syscon_integratorcp_cm_core_clk,
565 "arm,syscon-icst525-integratorcp-cm-core", of_syscon_icst_setup);
566CLK_OF_DECLARE(arm_syscon_integratorcp_cm_mem_clk,
567 "arm,syscon-icst525-integratorcp-cm-mem", of_syscon_icst_setup);
Linus Walleijd4308192015-10-13 14:29:54 +0200568#endif