blob: 37624e16cf04d454eebfa9318ac2bace1779e1c1 [file] [log] [blame]
Tero Kristof38b0dd2013-06-12 16:04:34 +03001/*
2 * OMAP DPLL clock support
3 *
4 * Copyright (C) 2013 Texas Instruments, Inc.
5 *
6 * Tero Kristo <t-kristo@ti.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
13 * kind, whether express or implied; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */
17
Stephen Boyd1b29e602015-06-19 15:00:46 -070018#include <linux/clk.h>
Tero Kristof38b0dd2013-06-12 16:04:34 +030019#include <linux/clk-provider.h>
20#include <linux/slab.h>
21#include <linux/err.h>
22#include <linux/of.h>
23#include <linux/of_address.h>
24#include <linux/clk/ti.h>
Tero Kristoed405a22015-01-29 22:24:28 +020025#include "clock.h"
Tero Kristof38b0dd2013-06-12 16:04:34 +030026
27#undef pr_fmt
28#define pr_fmt(fmt) "%s: " fmt, __func__
29
Tero Kristof38b0dd2013-06-12 16:04:34 +030030#if defined(CONFIG_ARCH_OMAP4) || defined(CONFIG_SOC_OMAP5) || \
31 defined(CONFIG_SOC_DRA7XX)
32static const struct clk_ops dpll_m4xen_ck_ops = {
33 .enable = &omap3_noncore_dpll_enable,
34 .disable = &omap3_noncore_dpll_disable,
35 .recalc_rate = &omap4_dpll_regm4xen_recalc,
36 .round_rate = &omap4_dpll_regm4xen_round_rate,
37 .set_rate = &omap3_noncore_dpll_set_rate,
Tero Kristo2e1a7b02014-10-03 16:57:14 +030038 .set_parent = &omap3_noncore_dpll_set_parent,
39 .set_rate_and_parent = &omap3_noncore_dpll_set_rate_and_parent,
40 .determine_rate = &omap4_dpll_regm4xen_determine_rate,
Tero Kristof38b0dd2013-06-12 16:04:34 +030041 .get_parent = &omap2_init_dpll_parent,
42};
Tero Kristoaa76fcf2014-02-21 17:36:21 +020043#else
44static const struct clk_ops dpll_m4xen_ck_ops = {};
Tero Kristof38b0dd2013-06-12 16:04:34 +030045#endif
46
Tero Kristoaa76fcf2014-02-21 17:36:21 +020047#if defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4) || \
48 defined(CONFIG_SOC_OMAP5) || defined(CONFIG_SOC_DRA7XX) || \
49 defined(CONFIG_SOC_AM33XX) || defined(CONFIG_SOC_AM43XX)
Tero Kristof38b0dd2013-06-12 16:04:34 +030050static const struct clk_ops dpll_core_ck_ops = {
51 .recalc_rate = &omap3_dpll_recalc,
52 .get_parent = &omap2_init_dpll_parent,
53};
54
Tero Kristof38b0dd2013-06-12 16:04:34 +030055static const struct clk_ops dpll_ck_ops = {
56 .enable = &omap3_noncore_dpll_enable,
57 .disable = &omap3_noncore_dpll_disable,
58 .recalc_rate = &omap3_dpll_recalc,
59 .round_rate = &omap2_dpll_round_rate,
60 .set_rate = &omap3_noncore_dpll_set_rate,
Tero Kristo2e1a7b02014-10-03 16:57:14 +030061 .set_parent = &omap3_noncore_dpll_set_parent,
62 .set_rate_and_parent = &omap3_noncore_dpll_set_rate_and_parent,
63 .determine_rate = &omap3_noncore_dpll_determine_rate,
Tero Kristof38b0dd2013-06-12 16:04:34 +030064 .get_parent = &omap2_init_dpll_parent,
65};
66
67static const struct clk_ops dpll_no_gate_ck_ops = {
68 .recalc_rate = &omap3_dpll_recalc,
69 .get_parent = &omap2_init_dpll_parent,
70 .round_rate = &omap2_dpll_round_rate,
71 .set_rate = &omap3_noncore_dpll_set_rate,
Tero Kristo2e1a7b02014-10-03 16:57:14 +030072 .set_parent = &omap3_noncore_dpll_set_parent,
73 .set_rate_and_parent = &omap3_noncore_dpll_set_rate_and_parent,
74 .determine_rate = &omap3_noncore_dpll_determine_rate,
Tero Kristof38b0dd2013-06-12 16:04:34 +030075};
Tero Kristoaa76fcf2014-02-21 17:36:21 +020076#else
77static const struct clk_ops dpll_core_ck_ops = {};
78static const struct clk_ops dpll_ck_ops = {};
79static const struct clk_ops dpll_no_gate_ck_ops = {};
80const struct clk_hw_omap_ops clkhwops_omap3_dpll = {};
81#endif
82
83#ifdef CONFIG_ARCH_OMAP2
84static const struct clk_ops omap2_dpll_core_ck_ops = {
85 .get_parent = &omap2_init_dpll_parent,
86 .recalc_rate = &omap2_dpllcore_recalc,
87 .round_rate = &omap2_dpll_round_rate,
88 .set_rate = &omap2_reprogram_dpllcore,
89};
90#else
91static const struct clk_ops omap2_dpll_core_ck_ops = {};
92#endif
93
94#ifdef CONFIG_ARCH_OMAP3
95static const struct clk_ops omap3_dpll_core_ck_ops = {
96 .get_parent = &omap2_init_dpll_parent,
97 .recalc_rate = &omap3_dpll_recalc,
98 .round_rate = &omap2_dpll_round_rate,
99};
100#else
101static const struct clk_ops omap3_dpll_core_ck_ops = {};
102#endif
Tero Kristof38b0dd2013-06-12 16:04:34 +0300103
104#ifdef CONFIG_ARCH_OMAP3
105static const struct clk_ops omap3_dpll_ck_ops = {
106 .enable = &omap3_noncore_dpll_enable,
107 .disable = &omap3_noncore_dpll_disable,
108 .get_parent = &omap2_init_dpll_parent,
109 .recalc_rate = &omap3_dpll_recalc,
110 .set_rate = &omap3_noncore_dpll_set_rate,
Tero Kristo2e1a7b02014-10-03 16:57:14 +0300111 .set_parent = &omap3_noncore_dpll_set_parent,
112 .set_rate_and_parent = &omap3_noncore_dpll_set_rate_and_parent,
113 .determine_rate = &omap3_noncore_dpll_determine_rate,
Tero Kristof38b0dd2013-06-12 16:04:34 +0300114 .round_rate = &omap2_dpll_round_rate,
115};
116
Richard Watts035cd482016-12-02 23:14:38 +0200117static const struct clk_ops omap3_dpll5_ck_ops = {
118 .enable = &omap3_noncore_dpll_enable,
119 .disable = &omap3_noncore_dpll_disable,
120 .get_parent = &omap2_init_dpll_parent,
121 .recalc_rate = &omap3_dpll_recalc,
122 .set_rate = &omap3_dpll5_set_rate,
123 .set_parent = &omap3_noncore_dpll_set_parent,
124 .set_rate_and_parent = &omap3_noncore_dpll_set_rate_and_parent,
125 .determine_rate = &omap3_noncore_dpll_determine_rate,
126 .round_rate = &omap2_dpll_round_rate,
127};
128
Tero Kristof38b0dd2013-06-12 16:04:34 +0300129static const struct clk_ops omap3_dpll_per_ck_ops = {
130 .enable = &omap3_noncore_dpll_enable,
131 .disable = &omap3_noncore_dpll_disable,
132 .get_parent = &omap2_init_dpll_parent,
133 .recalc_rate = &omap3_dpll_recalc,
134 .set_rate = &omap3_dpll4_set_rate,
Tero Kristo2e1a7b02014-10-03 16:57:14 +0300135 .set_parent = &omap3_noncore_dpll_set_parent,
136 .set_rate_and_parent = &omap3_dpll4_set_rate_and_parent,
137 .determine_rate = &omap3_noncore_dpll_determine_rate,
Tero Kristof38b0dd2013-06-12 16:04:34 +0300138 .round_rate = &omap2_dpll_round_rate,
139};
140#endif
141
142static const struct clk_ops dpll_x2_ck_ops = {
143 .recalc_rate = &omap3_clkoutx2_recalc,
144};
145
146/**
Tero Kristoed405a22015-01-29 22:24:28 +0200147 * _register_dpll - low level registration of a DPLL clock
Tero Kristof38b0dd2013-06-12 16:04:34 +0300148 * @hw: hardware clock definition for the clock
149 * @node: device node for the clock
150 *
151 * Finalizes DPLL registration process. In case a failure (clk-ref or
152 * clk-bypass is missing), the clock is added to retry list and
153 * the initialization is retried on later stage.
154 */
Tero Kristoed405a22015-01-29 22:24:28 +0200155static void __init _register_dpll(struct clk_hw *hw,
156 struct device_node *node)
Tero Kristof38b0dd2013-06-12 16:04:34 +0300157{
158 struct clk_hw_omap *clk_hw = to_clk_hw_omap(hw);
159 struct dpll_data *dd = clk_hw->dpll_data;
160 struct clk *clk;
161
Tero Kristob6f51282016-02-20 13:24:26 +0200162 clk = of_clk_get(node, 0);
163 if (IS_ERR(clk)) {
164 pr_debug("clk-ref missing for %s, retry later\n",
Tero Kristof38b0dd2013-06-12 16:04:34 +0300165 node->name);
Tero Kristoed405a22015-01-29 22:24:28 +0200166 if (!ti_clk_retry_init(node, hw, _register_dpll))
Tero Kristof38b0dd2013-06-12 16:04:34 +0300167 return;
168
169 goto cleanup;
170 }
171
Tero Kristob6f51282016-02-20 13:24:26 +0200172 dd->clk_ref = __clk_get_hw(clk);
173
174 clk = of_clk_get(node, 1);
175
176 if (IS_ERR(clk)) {
177 pr_debug("clk-bypass missing for %s, retry later\n",
178 node->name);
179 if (!ti_clk_retry_init(node, hw, _register_dpll))
180 return;
181
182 goto cleanup;
183 }
184
185 dd->clk_bypass = __clk_get_hw(clk);
186
Tero Kristof38b0dd2013-06-12 16:04:34 +0300187 /* register the clock */
Tero Kristo1ae79c42016-09-29 12:06:40 +0300188 clk = ti_clk_register(NULL, &clk_hw->hw, node->name);
Tero Kristof38b0dd2013-06-12 16:04:34 +0300189
190 if (!IS_ERR(clk)) {
Stephen Boyd98d8a602015-06-29 16:56:30 -0700191 omap2_init_clk_hw_omap_clocks(&clk_hw->hw);
Tero Kristof38b0dd2013-06-12 16:04:34 +0300192 of_clk_add_provider(node, of_clk_src_simple_get, clk);
193 kfree(clk_hw->hw.init->parent_names);
194 kfree(clk_hw->hw.init);
195 return;
196 }
197
198cleanup:
199 kfree(clk_hw->dpll_data);
200 kfree(clk_hw->hw.init->parent_names);
201 kfree(clk_hw->hw.init);
202 kfree(clk_hw);
203}
204
Arnd Bergmann6793a30a2015-02-03 17:59:32 +0100205#if defined(CONFIG_ARCH_OMAP3) && defined(CONFIG_ATAGS)
Stephen Boyd412d6b42015-05-01 12:59:32 -0700206static void __iomem *_get_reg(u8 module, u16 offset)
Tero Kristoed405a22015-01-29 22:24:28 +0200207{
208 u32 reg;
209 struct clk_omap_reg *reg_setup;
210
211 reg_setup = (struct clk_omap_reg *)&reg;
212
213 reg_setup->index = module;
214 reg_setup->offset = offset;
215
216 return (void __iomem *)reg;
217}
218
219struct clk *ti_clk_register_dpll(struct ti_clk *setup)
220{
221 struct clk_hw_omap *clk_hw;
222 struct clk_init_data init = { NULL };
223 struct dpll_data *dd;
224 struct clk *clk;
225 struct ti_clk_dpll *dpll;
226 const struct clk_ops *ops = &omap3_dpll_ck_ops;
227 struct clk *clk_ref;
228 struct clk *clk_bypass;
229
230 dpll = setup->data;
231
232 if (dpll->num_parents < 2)
233 return ERR_PTR(-EINVAL);
234
235 clk_ref = clk_get_sys(NULL, dpll->parents[0]);
236 clk_bypass = clk_get_sys(NULL, dpll->parents[1]);
237
238 if (IS_ERR_OR_NULL(clk_ref) || IS_ERR_OR_NULL(clk_bypass))
239 return ERR_PTR(-EAGAIN);
240
241 dd = kzalloc(sizeof(*dd), GFP_KERNEL);
242 clk_hw = kzalloc(sizeof(*clk_hw), GFP_KERNEL);
243 if (!dd || !clk_hw) {
244 clk = ERR_PTR(-ENOMEM);
245 goto cleanup;
246 }
247
248 clk_hw->dpll_data = dd;
249 clk_hw->ops = &clkhwops_omap3_dpll;
250 clk_hw->hw.init = &init;
251 clk_hw->flags = MEMMAP_ADDRESSING;
252
253 init.name = setup->name;
254 init.ops = ops;
255
256 init.num_parents = dpll->num_parents;
257 init.parent_names = dpll->parents;
258
259 dd->control_reg = _get_reg(dpll->module, dpll->control_reg);
260 dd->idlest_reg = _get_reg(dpll->module, dpll->idlest_reg);
261 dd->mult_div1_reg = _get_reg(dpll->module, dpll->mult_div1_reg);
262 dd->autoidle_reg = _get_reg(dpll->module, dpll->autoidle_reg);
263
264 dd->modes = dpll->modes;
265 dd->div1_mask = dpll->div1_mask;
266 dd->idlest_mask = dpll->idlest_mask;
267 dd->mult_mask = dpll->mult_mask;
268 dd->autoidle_mask = dpll->autoidle_mask;
269 dd->enable_mask = dpll->enable_mask;
270 dd->sddiv_mask = dpll->sddiv_mask;
271 dd->dco_mask = dpll->dco_mask;
272 dd->max_divider = dpll->max_divider;
273 dd->min_divider = dpll->min_divider;
274 dd->max_multiplier = dpll->max_multiplier;
275 dd->auto_recal_bit = dpll->auto_recal_bit;
276 dd->recal_en_bit = dpll->recal_en_bit;
277 dd->recal_st_bit = dpll->recal_st_bit;
278
Tero Kristob6f51282016-02-20 13:24:26 +0200279 dd->clk_ref = __clk_get_hw(clk_ref);
280 dd->clk_bypass = __clk_get_hw(clk_bypass);
Tero Kristoed405a22015-01-29 22:24:28 +0200281
282 if (dpll->flags & CLKF_CORE)
283 ops = &omap3_dpll_core_ck_ops;
284
285 if (dpll->flags & CLKF_PER)
286 ops = &omap3_dpll_per_ck_ops;
287
288 if (dpll->flags & CLKF_J_TYPE)
289 dd->flags |= DPLL_J_TYPE;
290
Tero Kristo1ae79c42016-09-29 12:06:40 +0300291 clk = ti_clk_register(NULL, &clk_hw->hw, setup->name);
Tero Kristoed405a22015-01-29 22:24:28 +0200292
293 if (!IS_ERR(clk))
294 return clk;
295
296cleanup:
297 kfree(dd);
298 kfree(clk_hw);
299 return clk;
300}
Arnd Bergmann6793a30a2015-02-03 17:59:32 +0100301#endif
Tero Kristoed405a22015-01-29 22:24:28 +0200302
Tero Kristof38b0dd2013-06-12 16:04:34 +0300303#if defined(CONFIG_ARCH_OMAP4) || defined(CONFIG_SOC_OMAP5) || \
Roger Quadros4332ec12014-06-17 17:03:24 +0300304 defined(CONFIG_SOC_DRA7XX) || defined(CONFIG_SOC_AM33XX) || \
305 defined(CONFIG_SOC_AM43XX)
Tero Kristof38b0dd2013-06-12 16:04:34 +0300306/**
Tero Kristoed405a22015-01-29 22:24:28 +0200307 * _register_dpll_x2 - Registers a DPLLx2 clock
Tero Kristof38b0dd2013-06-12 16:04:34 +0300308 * @node: device node for this clock
309 * @ops: clk_ops for this clock
310 * @hw_ops: clk_hw_ops for this clock
311 *
312 * Initializes a DPLL x 2 clock from device tree data.
313 */
Tero Kristoed405a22015-01-29 22:24:28 +0200314static void _register_dpll_x2(struct device_node *node,
315 const struct clk_ops *ops,
316 const struct clk_hw_omap_ops *hw_ops)
Tero Kristof38b0dd2013-06-12 16:04:34 +0300317{
318 struct clk *clk;
319 struct clk_init_data init = { NULL };
320 struct clk_hw_omap *clk_hw;
321 const char *name = node->name;
322 const char *parent_name;
323
324 parent_name = of_clk_get_parent_name(node, 0);
325 if (!parent_name) {
326 pr_err("%s must have parent\n", node->name);
327 return;
328 }
329
330 clk_hw = kzalloc(sizeof(*clk_hw), GFP_KERNEL);
331 if (!clk_hw)
332 return;
333
334 clk_hw->ops = hw_ops;
335 clk_hw->hw.init = &init;
336
337 init.name = name;
338 init.ops = ops;
339 init.parent_names = &parent_name;
340 init.num_parents = 1;
341
342 /* register the clock */
Tero Kristo1ae79c42016-09-29 12:06:40 +0300343 clk = ti_clk_register(NULL, &clk_hw->hw, name);
Tero Kristof38b0dd2013-06-12 16:04:34 +0300344
345 if (IS_ERR(clk)) {
346 kfree(clk_hw);
347 } else {
Stephen Boyd98d8a602015-06-29 16:56:30 -0700348 omap2_init_clk_hw_omap_clocks(&clk_hw->hw);
Tero Kristof38b0dd2013-06-12 16:04:34 +0300349 of_clk_add_provider(node, of_clk_src_simple_get, clk);
350 }
351}
352#endif
353
354/**
355 * of_ti_dpll_setup - Setup function for OMAP DPLL clocks
356 * @node: device node containing the DPLL info
357 * @ops: ops for the DPLL
358 * @ddt: DPLL data template to use
Tero Kristof38b0dd2013-06-12 16:04:34 +0300359 *
360 * Initializes a DPLL clock from device tree data.
361 */
362static void __init of_ti_dpll_setup(struct device_node *node,
363 const struct clk_ops *ops,
Tero Kristoa6fe3772014-02-21 17:22:32 +0200364 const struct dpll_data *ddt)
Tero Kristof38b0dd2013-06-12 16:04:34 +0300365{
366 struct clk_hw_omap *clk_hw = NULL;
367 struct clk_init_data *init = NULL;
368 const char **parent_names = NULL;
369 struct dpll_data *dd = NULL;
Tero Kristof38b0dd2013-06-12 16:04:34 +0300370 u8 dpll_mode = 0;
371
372 dd = kzalloc(sizeof(*dd), GFP_KERNEL);
373 clk_hw = kzalloc(sizeof(*clk_hw), GFP_KERNEL);
374 init = kzalloc(sizeof(*init), GFP_KERNEL);
375 if (!dd || !clk_hw || !init)
376 goto cleanup;
377
378 memcpy(dd, ddt, sizeof(*dd));
379
380 clk_hw->dpll_data = dd;
381 clk_hw->ops = &clkhwops_omap3_dpll;
382 clk_hw->hw.init = init;
383 clk_hw->flags = MEMMAP_ADDRESSING;
384
385 init->name = node->name;
386 init->ops = ops;
387
388 init->num_parents = of_clk_get_parent_count(node);
Stephen Boyd921bacf2016-02-19 17:49:23 -0800389 if (!init->num_parents) {
Tero Kristof38b0dd2013-06-12 16:04:34 +0300390 pr_err("%s must have parent(s)\n", node->name);
391 goto cleanup;
392 }
393
394 parent_names = kzalloc(sizeof(char *) * init->num_parents, GFP_KERNEL);
395 if (!parent_names)
396 goto cleanup;
397
Dinh Nguyen9da9e762015-07-06 22:59:06 -0500398 of_clk_parent_fill(node, parent_names, init->num_parents);
Tero Kristof38b0dd2013-06-12 16:04:34 +0300399
400 init->parent_names = parent_names;
401
402 dd->control_reg = ti_clk_get_reg_addr(node, 0);
Tero Kristof38b0dd2013-06-12 16:04:34 +0300403
Tero Kristoaa76fcf2014-02-21 17:36:21 +0200404 /*
405 * Special case for OMAP2 DPLL, register order is different due to
406 * missing idlest_reg, also clkhwops is different. Detected from
407 * missing idlest_mask.
408 */
409 if (!dd->idlest_mask) {
410 dd->mult_div1_reg = ti_clk_get_reg_addr(node, 1);
411#ifdef CONFIG_ARCH_OMAP2
412 clk_hw->ops = &clkhwops_omap2xxx_dpll;
413 omap2xxx_clkt_dpllcore_init(&clk_hw->hw);
414#endif
415 } else {
416 dd->idlest_reg = ti_clk_get_reg_addr(node, 1);
Tero Kristoc807dbe2015-02-23 21:06:08 +0200417 if (IS_ERR(dd->idlest_reg))
Tero Kristoaa76fcf2014-02-21 17:36:21 +0200418 goto cleanup;
419
420 dd->mult_div1_reg = ti_clk_get_reg_addr(node, 2);
421 }
422
Tero Kristoc807dbe2015-02-23 21:06:08 +0200423 if (IS_ERR(dd->control_reg) || IS_ERR(dd->mult_div1_reg))
Tero Kristof38b0dd2013-06-12 16:04:34 +0300424 goto cleanup;
425
Tero Kristoa6fe3772014-02-21 17:22:32 +0200426 if (dd->autoidle_mask) {
Tero Kristof38b0dd2013-06-12 16:04:34 +0300427 dd->autoidle_reg = ti_clk_get_reg_addr(node, 3);
Tero Kristoc807dbe2015-02-23 21:06:08 +0200428 if (IS_ERR(dd->autoidle_reg))
Tero Kristof38b0dd2013-06-12 16:04:34 +0300429 goto cleanup;
430 }
431
432 if (of_property_read_bool(node, "ti,low-power-stop"))
433 dpll_mode |= 1 << DPLL_LOW_POWER_STOP;
434
435 if (of_property_read_bool(node, "ti,low-power-bypass"))
436 dpll_mode |= 1 << DPLL_LOW_POWER_BYPASS;
437
438 if (of_property_read_bool(node, "ti,lock"))
439 dpll_mode |= 1 << DPLL_LOCKED;
440
441 if (dpll_mode)
442 dd->modes = dpll_mode;
443
Tero Kristoed405a22015-01-29 22:24:28 +0200444 _register_dpll(&clk_hw->hw, node);
Tero Kristof38b0dd2013-06-12 16:04:34 +0300445 return;
446
447cleanup:
448 kfree(dd);
449 kfree(parent_names);
450 kfree(init);
451 kfree(clk_hw);
452}
453
454#if defined(CONFIG_ARCH_OMAP4) || defined(CONFIG_SOC_OMAP5) || \
455 defined(CONFIG_SOC_DRA7XX)
456static void __init of_ti_omap4_dpll_x2_setup(struct device_node *node)
457{
Tero Kristoed405a22015-01-29 22:24:28 +0200458 _register_dpll_x2(node, &dpll_x2_ck_ops, &clkhwops_omap4_dpllmx);
Tero Kristof38b0dd2013-06-12 16:04:34 +0300459}
460CLK_OF_DECLARE(ti_omap4_dpll_x2_clock, "ti,omap4-dpll-x2-clock",
461 of_ti_omap4_dpll_x2_setup);
462#endif
463
Roger Quadros4332ec12014-06-17 17:03:24 +0300464#if defined(CONFIG_SOC_AM33XX) || defined(CONFIG_SOC_AM43XX)
Tero Kristof38b0dd2013-06-12 16:04:34 +0300465static void __init of_ti_am3_dpll_x2_setup(struct device_node *node)
466{
Tero Kristoed405a22015-01-29 22:24:28 +0200467 _register_dpll_x2(node, &dpll_x2_ck_ops, NULL);
Tero Kristof38b0dd2013-06-12 16:04:34 +0300468}
469CLK_OF_DECLARE(ti_am3_dpll_x2_clock, "ti,am3-dpll-x2-clock",
470 of_ti_am3_dpll_x2_setup);
471#endif
472
473#ifdef CONFIG_ARCH_OMAP3
474static void __init of_ti_omap3_dpll_setup(struct device_node *node)
475{
476 const struct dpll_data dd = {
477 .idlest_mask = 0x1,
478 .enable_mask = 0x7,
479 .autoidle_mask = 0x7,
480 .mult_mask = 0x7ff << 8,
481 .div1_mask = 0x7f,
482 .max_multiplier = 2047,
483 .max_divider = 128,
484 .min_divider = 1,
485 .freqsel_mask = 0xf0,
486 .modes = (1 << DPLL_LOW_POWER_BYPASS) | (1 << DPLL_LOCKED),
487 };
488
Richard Watts035cd482016-12-02 23:14:38 +0200489 if ((of_machine_is_compatible("ti,omap3630") ||
490 of_machine_is_compatible("ti,omap36xx")) &&
491 !strcmp(node->name, "dpll5_ck"))
492 of_ti_dpll_setup(node, &omap3_dpll5_ck_ops, &dd);
493 else
494 of_ti_dpll_setup(node, &omap3_dpll_ck_ops, &dd);
Tero Kristof38b0dd2013-06-12 16:04:34 +0300495}
496CLK_OF_DECLARE(ti_omap3_dpll_clock, "ti,omap3-dpll-clock",
497 of_ti_omap3_dpll_setup);
498
499static void __init of_ti_omap3_core_dpll_setup(struct device_node *node)
500{
501 const struct dpll_data dd = {
502 .idlest_mask = 0x1,
503 .enable_mask = 0x7,
504 .autoidle_mask = 0x7,
505 .mult_mask = 0x7ff << 16,
506 .div1_mask = 0x7f << 8,
507 .max_multiplier = 2047,
508 .max_divider = 128,
509 .min_divider = 1,
510 .freqsel_mask = 0xf0,
511 };
512
Tero Kristoa6fe3772014-02-21 17:22:32 +0200513 of_ti_dpll_setup(node, &omap3_dpll_core_ck_ops, &dd);
Tero Kristof38b0dd2013-06-12 16:04:34 +0300514}
515CLK_OF_DECLARE(ti_omap3_core_dpll_clock, "ti,omap3-dpll-core-clock",
516 of_ti_omap3_core_dpll_setup);
517
518static void __init of_ti_omap3_per_dpll_setup(struct device_node *node)
519{
520 const struct dpll_data dd = {
521 .idlest_mask = 0x1 << 1,
522 .enable_mask = 0x7 << 16,
523 .autoidle_mask = 0x7 << 3,
524 .mult_mask = 0x7ff << 8,
525 .div1_mask = 0x7f,
526 .max_multiplier = 2047,
527 .max_divider = 128,
528 .min_divider = 1,
529 .freqsel_mask = 0xf00000,
530 .modes = (1 << DPLL_LOW_POWER_STOP) | (1 << DPLL_LOCKED),
531 };
532
Tero Kristoa6fe3772014-02-21 17:22:32 +0200533 of_ti_dpll_setup(node, &omap3_dpll_per_ck_ops, &dd);
Tero Kristof38b0dd2013-06-12 16:04:34 +0300534}
535CLK_OF_DECLARE(ti_omap3_per_dpll_clock, "ti,omap3-dpll-per-clock",
536 of_ti_omap3_per_dpll_setup);
537
538static void __init of_ti_omap3_per_jtype_dpll_setup(struct device_node *node)
539{
540 const struct dpll_data dd = {
541 .idlest_mask = 0x1 << 1,
542 .enable_mask = 0x7 << 16,
543 .autoidle_mask = 0x7 << 3,
544 .mult_mask = 0xfff << 8,
545 .div1_mask = 0x7f,
546 .max_multiplier = 4095,
547 .max_divider = 128,
548 .min_divider = 1,
549 .sddiv_mask = 0xff << 24,
550 .dco_mask = 0xe << 20,
551 .flags = DPLL_J_TYPE,
552 .modes = (1 << DPLL_LOW_POWER_STOP) | (1 << DPLL_LOCKED),
553 };
554
Tero Kristoa6fe3772014-02-21 17:22:32 +0200555 of_ti_dpll_setup(node, &omap3_dpll_per_ck_ops, &dd);
Tero Kristof38b0dd2013-06-12 16:04:34 +0300556}
557CLK_OF_DECLARE(ti_omap3_per_jtype_dpll_clock, "ti,omap3-dpll-per-j-type-clock",
558 of_ti_omap3_per_jtype_dpll_setup);
559#endif
560
561static void __init of_ti_omap4_dpll_setup(struct device_node *node)
562{
563 const struct dpll_data dd = {
564 .idlest_mask = 0x1,
565 .enable_mask = 0x7,
566 .autoidle_mask = 0x7,
567 .mult_mask = 0x7ff << 8,
568 .div1_mask = 0x7f,
569 .max_multiplier = 2047,
570 .max_divider = 128,
571 .min_divider = 1,
572 .modes = (1 << DPLL_LOW_POWER_BYPASS) | (1 << DPLL_LOCKED),
573 };
574
Tero Kristoa6fe3772014-02-21 17:22:32 +0200575 of_ti_dpll_setup(node, &dpll_ck_ops, &dd);
Tero Kristof38b0dd2013-06-12 16:04:34 +0300576}
577CLK_OF_DECLARE(ti_omap4_dpll_clock, "ti,omap4-dpll-clock",
578 of_ti_omap4_dpll_setup);
579
Nishanth Menonb4be0182014-05-16 05:45:59 -0500580static void __init of_ti_omap5_mpu_dpll_setup(struct device_node *node)
581{
582 const struct dpll_data dd = {
583 .idlest_mask = 0x1,
584 .enable_mask = 0x7,
585 .autoidle_mask = 0x7,
586 .mult_mask = 0x7ff << 8,
587 .div1_mask = 0x7f,
588 .max_multiplier = 2047,
589 .max_divider = 128,
590 .dcc_mask = BIT(22),
591 .dcc_rate = 1400000000, /* DCC beyond 1.4GHz */
592 .min_divider = 1,
593 .modes = (1 << DPLL_LOW_POWER_BYPASS) | (1 << DPLL_LOCKED),
594 };
595
596 of_ti_dpll_setup(node, &dpll_ck_ops, &dd);
597}
598CLK_OF_DECLARE(of_ti_omap5_mpu_dpll_clock, "ti,omap5-mpu-dpll-clock",
599 of_ti_omap5_mpu_dpll_setup);
600
Tero Kristof38b0dd2013-06-12 16:04:34 +0300601static void __init of_ti_omap4_core_dpll_setup(struct device_node *node)
602{
603 const struct dpll_data dd = {
604 .idlest_mask = 0x1,
605 .enable_mask = 0x7,
606 .autoidle_mask = 0x7,
607 .mult_mask = 0x7ff << 8,
608 .div1_mask = 0x7f,
609 .max_multiplier = 2047,
610 .max_divider = 128,
611 .min_divider = 1,
612 .modes = (1 << DPLL_LOW_POWER_BYPASS) | (1 << DPLL_LOCKED),
613 };
614
Tero Kristoa6fe3772014-02-21 17:22:32 +0200615 of_ti_dpll_setup(node, &dpll_core_ck_ops, &dd);
Tero Kristof38b0dd2013-06-12 16:04:34 +0300616}
617CLK_OF_DECLARE(ti_omap4_core_dpll_clock, "ti,omap4-dpll-core-clock",
618 of_ti_omap4_core_dpll_setup);
619
620#if defined(CONFIG_ARCH_OMAP4) || defined(CONFIG_SOC_OMAP5) || \
621 defined(CONFIG_SOC_DRA7XX)
622static void __init of_ti_omap4_m4xen_dpll_setup(struct device_node *node)
623{
624 const struct dpll_data dd = {
625 .idlest_mask = 0x1,
626 .enable_mask = 0x7,
627 .autoidle_mask = 0x7,
628 .mult_mask = 0x7ff << 8,
629 .div1_mask = 0x7f,
630 .max_multiplier = 2047,
631 .max_divider = 128,
632 .min_divider = 1,
633 .m4xen_mask = 0x800,
634 .lpmode_mask = 1 << 10,
635 .modes = (1 << DPLL_LOW_POWER_BYPASS) | (1 << DPLL_LOCKED),
636 };
637
Tero Kristoa6fe3772014-02-21 17:22:32 +0200638 of_ti_dpll_setup(node, &dpll_m4xen_ck_ops, &dd);
Tero Kristof38b0dd2013-06-12 16:04:34 +0300639}
640CLK_OF_DECLARE(ti_omap4_m4xen_dpll_clock, "ti,omap4-dpll-m4xen-clock",
641 of_ti_omap4_m4xen_dpll_setup);
642
643static void __init of_ti_omap4_jtype_dpll_setup(struct device_node *node)
644{
645 const struct dpll_data dd = {
646 .idlest_mask = 0x1,
647 .enable_mask = 0x7,
648 .autoidle_mask = 0x7,
649 .mult_mask = 0xfff << 8,
650 .div1_mask = 0xff,
651 .max_multiplier = 4095,
652 .max_divider = 256,
653 .min_divider = 1,
654 .sddiv_mask = 0xff << 24,
655 .flags = DPLL_J_TYPE,
656 .modes = (1 << DPLL_LOW_POWER_BYPASS) | (1 << DPLL_LOCKED),
657 };
658
Tero Kristoa6fe3772014-02-21 17:22:32 +0200659 of_ti_dpll_setup(node, &dpll_m4xen_ck_ops, &dd);
Tero Kristof38b0dd2013-06-12 16:04:34 +0300660}
661CLK_OF_DECLARE(ti_omap4_jtype_dpll_clock, "ti,omap4-dpll-j-type-clock",
662 of_ti_omap4_jtype_dpll_setup);
663#endif
664
665static void __init of_ti_am3_no_gate_dpll_setup(struct device_node *node)
666{
667 const struct dpll_data dd = {
668 .idlest_mask = 0x1,
669 .enable_mask = 0x7,
Tero Kristof38b0dd2013-06-12 16:04:34 +0300670 .mult_mask = 0x7ff << 8,
671 .div1_mask = 0x7f,
672 .max_multiplier = 2047,
673 .max_divider = 128,
674 .min_divider = 1,
Tero Kristo3db5ca22016-03-16 21:54:56 +0200675 .max_rate = 1000000000,
Tero Kristof38b0dd2013-06-12 16:04:34 +0300676 .modes = (1 << DPLL_LOW_POWER_BYPASS) | (1 << DPLL_LOCKED),
677 };
678
Tero Kristoa6fe3772014-02-21 17:22:32 +0200679 of_ti_dpll_setup(node, &dpll_no_gate_ck_ops, &dd);
Tero Kristof38b0dd2013-06-12 16:04:34 +0300680}
681CLK_OF_DECLARE(ti_am3_no_gate_dpll_clock, "ti,am3-dpll-no-gate-clock",
682 of_ti_am3_no_gate_dpll_setup);
683
684static void __init of_ti_am3_jtype_dpll_setup(struct device_node *node)
685{
686 const struct dpll_data dd = {
687 .idlest_mask = 0x1,
688 .enable_mask = 0x7,
Tero Kristof38b0dd2013-06-12 16:04:34 +0300689 .mult_mask = 0x7ff << 8,
690 .div1_mask = 0x7f,
691 .max_multiplier = 4095,
692 .max_divider = 256,
693 .min_divider = 2,
694 .flags = DPLL_J_TYPE,
Tero Kristo3db5ca22016-03-16 21:54:56 +0200695 .max_rate = 2000000000,
Tero Kristof38b0dd2013-06-12 16:04:34 +0300696 .modes = (1 << DPLL_LOW_POWER_BYPASS) | (1 << DPLL_LOCKED),
697 };
698
Tero Kristoa6fe3772014-02-21 17:22:32 +0200699 of_ti_dpll_setup(node, &dpll_ck_ops, &dd);
Tero Kristof38b0dd2013-06-12 16:04:34 +0300700}
701CLK_OF_DECLARE(ti_am3_jtype_dpll_clock, "ti,am3-dpll-j-type-clock",
702 of_ti_am3_jtype_dpll_setup);
703
704static void __init of_ti_am3_no_gate_jtype_dpll_setup(struct device_node *node)
705{
706 const struct dpll_data dd = {
707 .idlest_mask = 0x1,
708 .enable_mask = 0x7,
Tero Kristof38b0dd2013-06-12 16:04:34 +0300709 .mult_mask = 0x7ff << 8,
710 .div1_mask = 0x7f,
711 .max_multiplier = 2047,
712 .max_divider = 128,
713 .min_divider = 1,
Tero Kristo3db5ca22016-03-16 21:54:56 +0200714 .max_rate = 2000000000,
Tero Kristof38b0dd2013-06-12 16:04:34 +0300715 .flags = DPLL_J_TYPE,
716 .modes = (1 << DPLL_LOW_POWER_BYPASS) | (1 << DPLL_LOCKED),
717 };
718
Tero Kristoa6fe3772014-02-21 17:22:32 +0200719 of_ti_dpll_setup(node, &dpll_no_gate_ck_ops, &dd);
Tero Kristof38b0dd2013-06-12 16:04:34 +0300720}
721CLK_OF_DECLARE(ti_am3_no_gate_jtype_dpll_clock,
722 "ti,am3-dpll-no-gate-j-type-clock",
723 of_ti_am3_no_gate_jtype_dpll_setup);
724
725static void __init of_ti_am3_dpll_setup(struct device_node *node)
726{
727 const struct dpll_data dd = {
728 .idlest_mask = 0x1,
729 .enable_mask = 0x7,
Tero Kristof38b0dd2013-06-12 16:04:34 +0300730 .mult_mask = 0x7ff << 8,
731 .div1_mask = 0x7f,
732 .max_multiplier = 2047,
733 .max_divider = 128,
734 .min_divider = 1,
Tero Kristo3db5ca22016-03-16 21:54:56 +0200735 .max_rate = 1000000000,
Tero Kristof38b0dd2013-06-12 16:04:34 +0300736 .modes = (1 << DPLL_LOW_POWER_BYPASS) | (1 << DPLL_LOCKED),
737 };
738
Tero Kristoa6fe3772014-02-21 17:22:32 +0200739 of_ti_dpll_setup(node, &dpll_ck_ops, &dd);
Tero Kristof38b0dd2013-06-12 16:04:34 +0300740}
741CLK_OF_DECLARE(ti_am3_dpll_clock, "ti,am3-dpll-clock", of_ti_am3_dpll_setup);
742
743static void __init of_ti_am3_core_dpll_setup(struct device_node *node)
744{
745 const struct dpll_data dd = {
746 .idlest_mask = 0x1,
747 .enable_mask = 0x7,
Tero Kristof38b0dd2013-06-12 16:04:34 +0300748 .mult_mask = 0x7ff << 8,
749 .div1_mask = 0x7f,
750 .max_multiplier = 2047,
751 .max_divider = 128,
752 .min_divider = 1,
Tero Kristo3db5ca22016-03-16 21:54:56 +0200753 .max_rate = 1000000000,
Tero Kristof38b0dd2013-06-12 16:04:34 +0300754 .modes = (1 << DPLL_LOW_POWER_BYPASS) | (1 << DPLL_LOCKED),
755 };
756
Tero Kristoa6fe3772014-02-21 17:22:32 +0200757 of_ti_dpll_setup(node, &dpll_core_ck_ops, &dd);
Tero Kristof38b0dd2013-06-12 16:04:34 +0300758}
759CLK_OF_DECLARE(ti_am3_core_dpll_clock, "ti,am3-dpll-core-clock",
760 of_ti_am3_core_dpll_setup);
Tero Kristoaa76fcf2014-02-21 17:36:21 +0200761
762static void __init of_ti_omap2_core_dpll_setup(struct device_node *node)
763{
764 const struct dpll_data dd = {
765 .enable_mask = 0x3,
766 .mult_mask = 0x3ff << 12,
767 .div1_mask = 0xf << 8,
768 .max_divider = 16,
769 .min_divider = 1,
770 };
771
772 of_ti_dpll_setup(node, &omap2_dpll_core_ck_ops, &dd);
773}
774CLK_OF_DECLARE(ti_omap2_core_dpll_clock, "ti,omap2-dpll-core-clock",
775 of_ti_omap2_core_dpll_setup);