blob: 778bc90955b9209106bda1276a7ddcd0a847de9c [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;
Tero Kristoed405a22015-01-29 22:24:28 +0200251
252 init.name = setup->name;
253 init.ops = ops;
254
255 init.num_parents = dpll->num_parents;
256 init.parent_names = dpll->parents;
257
258 dd->control_reg = _get_reg(dpll->module, dpll->control_reg);
259 dd->idlest_reg = _get_reg(dpll->module, dpll->idlest_reg);
260 dd->mult_div1_reg = _get_reg(dpll->module, dpll->mult_div1_reg);
261 dd->autoidle_reg = _get_reg(dpll->module, dpll->autoidle_reg);
262
263 dd->modes = dpll->modes;
264 dd->div1_mask = dpll->div1_mask;
265 dd->idlest_mask = dpll->idlest_mask;
266 dd->mult_mask = dpll->mult_mask;
267 dd->autoidle_mask = dpll->autoidle_mask;
268 dd->enable_mask = dpll->enable_mask;
269 dd->sddiv_mask = dpll->sddiv_mask;
270 dd->dco_mask = dpll->dco_mask;
271 dd->max_divider = dpll->max_divider;
272 dd->min_divider = dpll->min_divider;
273 dd->max_multiplier = dpll->max_multiplier;
274 dd->auto_recal_bit = dpll->auto_recal_bit;
275 dd->recal_en_bit = dpll->recal_en_bit;
276 dd->recal_st_bit = dpll->recal_st_bit;
277
Tero Kristob6f51282016-02-20 13:24:26 +0200278 dd->clk_ref = __clk_get_hw(clk_ref);
279 dd->clk_bypass = __clk_get_hw(clk_bypass);
Tero Kristoed405a22015-01-29 22:24:28 +0200280
281 if (dpll->flags & CLKF_CORE)
282 ops = &omap3_dpll_core_ck_ops;
283
284 if (dpll->flags & CLKF_PER)
285 ops = &omap3_dpll_per_ck_ops;
286
287 if (dpll->flags & CLKF_J_TYPE)
288 dd->flags |= DPLL_J_TYPE;
289
Tero Kristo1ae79c42016-09-29 12:06:40 +0300290 clk = ti_clk_register(NULL, &clk_hw->hw, setup->name);
Tero Kristoed405a22015-01-29 22:24:28 +0200291
292 if (!IS_ERR(clk))
293 return clk;
294
295cleanup:
296 kfree(dd);
297 kfree(clk_hw);
298 return clk;
299}
Arnd Bergmann6793a30a2015-02-03 17:59:32 +0100300#endif
Tero Kristoed405a22015-01-29 22:24:28 +0200301
Tero Kristof38b0dd2013-06-12 16:04:34 +0300302#if defined(CONFIG_ARCH_OMAP4) || defined(CONFIG_SOC_OMAP5) || \
Roger Quadros4332ec12014-06-17 17:03:24 +0300303 defined(CONFIG_SOC_DRA7XX) || defined(CONFIG_SOC_AM33XX) || \
304 defined(CONFIG_SOC_AM43XX)
Tero Kristof38b0dd2013-06-12 16:04:34 +0300305/**
Tero Kristoed405a22015-01-29 22:24:28 +0200306 * _register_dpll_x2 - Registers a DPLLx2 clock
Tero Kristof38b0dd2013-06-12 16:04:34 +0300307 * @node: device node for this clock
308 * @ops: clk_ops for this clock
309 * @hw_ops: clk_hw_ops for this clock
310 *
311 * Initializes a DPLL x 2 clock from device tree data.
312 */
Tero Kristoed405a22015-01-29 22:24:28 +0200313static void _register_dpll_x2(struct device_node *node,
314 const struct clk_ops *ops,
315 const struct clk_hw_omap_ops *hw_ops)
Tero Kristof38b0dd2013-06-12 16:04:34 +0300316{
317 struct clk *clk;
318 struct clk_init_data init = { NULL };
319 struct clk_hw_omap *clk_hw;
320 const char *name = node->name;
321 const char *parent_name;
Tero Kristo473adbf2017-02-09 11:25:28 +0200322 int ret;
Tero Kristof38b0dd2013-06-12 16:04:34 +0300323
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
Tero Kristo473adbf2017-02-09 11:25:28 +0200342 if (hw_ops == &clkhwops_omap4_dpllmx) {
343 /* Check if register defined, if not, drop hw-ops */
344 ret = of_property_count_elems_of_size(node, "reg", 1);
345 if (ret <= 0) {
346 hw_ops = NULL;
347 } else {
348 clk_hw->clksel_reg = ti_clk_get_reg_addr(node, 0);
349 if (IS_ERR(clk_hw->clksel_reg)) {
350 kfree(clk_hw);
351 return;
352 }
353 }
354 }
355
Tero Kristof38b0dd2013-06-12 16:04:34 +0300356 /* register the clock */
Tero Kristo1ae79c42016-09-29 12:06:40 +0300357 clk = ti_clk_register(NULL, &clk_hw->hw, name);
Tero Kristof38b0dd2013-06-12 16:04:34 +0300358
359 if (IS_ERR(clk)) {
360 kfree(clk_hw);
361 } else {
Stephen Boyd98d8a602015-06-29 16:56:30 -0700362 omap2_init_clk_hw_omap_clocks(&clk_hw->hw);
Tero Kristof38b0dd2013-06-12 16:04:34 +0300363 of_clk_add_provider(node, of_clk_src_simple_get, clk);
364 }
365}
366#endif
367
368/**
369 * of_ti_dpll_setup - Setup function for OMAP DPLL clocks
370 * @node: device node containing the DPLL info
371 * @ops: ops for the DPLL
372 * @ddt: DPLL data template to use
Tero Kristof38b0dd2013-06-12 16:04:34 +0300373 *
374 * Initializes a DPLL clock from device tree data.
375 */
376static void __init of_ti_dpll_setup(struct device_node *node,
377 const struct clk_ops *ops,
Tero Kristoa6fe3772014-02-21 17:22:32 +0200378 const struct dpll_data *ddt)
Tero Kristof38b0dd2013-06-12 16:04:34 +0300379{
380 struct clk_hw_omap *clk_hw = NULL;
381 struct clk_init_data *init = NULL;
382 const char **parent_names = NULL;
383 struct dpll_data *dd = NULL;
Tero Kristof38b0dd2013-06-12 16:04:34 +0300384 u8 dpll_mode = 0;
385
386 dd = kzalloc(sizeof(*dd), GFP_KERNEL);
387 clk_hw = kzalloc(sizeof(*clk_hw), GFP_KERNEL);
388 init = kzalloc(sizeof(*init), GFP_KERNEL);
389 if (!dd || !clk_hw || !init)
390 goto cleanup;
391
392 memcpy(dd, ddt, sizeof(*dd));
393
394 clk_hw->dpll_data = dd;
395 clk_hw->ops = &clkhwops_omap3_dpll;
396 clk_hw->hw.init = init;
Tero Kristof38b0dd2013-06-12 16:04:34 +0300397
398 init->name = node->name;
399 init->ops = ops;
400
401 init->num_parents = of_clk_get_parent_count(node);
Stephen Boyd921bacf2016-02-19 17:49:23 -0800402 if (!init->num_parents) {
Tero Kristof38b0dd2013-06-12 16:04:34 +0300403 pr_err("%s must have parent(s)\n", node->name);
404 goto cleanup;
405 }
406
407 parent_names = kzalloc(sizeof(char *) * init->num_parents, GFP_KERNEL);
408 if (!parent_names)
409 goto cleanup;
410
Dinh Nguyen9da9e762015-07-06 22:59:06 -0500411 of_clk_parent_fill(node, parent_names, init->num_parents);
Tero Kristof38b0dd2013-06-12 16:04:34 +0300412
413 init->parent_names = parent_names;
414
415 dd->control_reg = ti_clk_get_reg_addr(node, 0);
Tero Kristof38b0dd2013-06-12 16:04:34 +0300416
Tero Kristoaa76fcf2014-02-21 17:36:21 +0200417 /*
418 * Special case for OMAP2 DPLL, register order is different due to
419 * missing idlest_reg, also clkhwops is different. Detected from
420 * missing idlest_mask.
421 */
422 if (!dd->idlest_mask) {
423 dd->mult_div1_reg = ti_clk_get_reg_addr(node, 1);
424#ifdef CONFIG_ARCH_OMAP2
425 clk_hw->ops = &clkhwops_omap2xxx_dpll;
426 omap2xxx_clkt_dpllcore_init(&clk_hw->hw);
427#endif
428 } else {
429 dd->idlest_reg = ti_clk_get_reg_addr(node, 1);
Tero Kristoc807dbe2015-02-23 21:06:08 +0200430 if (IS_ERR(dd->idlest_reg))
Tero Kristoaa76fcf2014-02-21 17:36:21 +0200431 goto cleanup;
432
433 dd->mult_div1_reg = ti_clk_get_reg_addr(node, 2);
434 }
435
Tero Kristoc807dbe2015-02-23 21:06:08 +0200436 if (IS_ERR(dd->control_reg) || IS_ERR(dd->mult_div1_reg))
Tero Kristof38b0dd2013-06-12 16:04:34 +0300437 goto cleanup;
438
Tero Kristoa6fe3772014-02-21 17:22:32 +0200439 if (dd->autoidle_mask) {
Tero Kristof38b0dd2013-06-12 16:04:34 +0300440 dd->autoidle_reg = ti_clk_get_reg_addr(node, 3);
Tero Kristoc807dbe2015-02-23 21:06:08 +0200441 if (IS_ERR(dd->autoidle_reg))
Tero Kristof38b0dd2013-06-12 16:04:34 +0300442 goto cleanup;
443 }
444
445 if (of_property_read_bool(node, "ti,low-power-stop"))
446 dpll_mode |= 1 << DPLL_LOW_POWER_STOP;
447
448 if (of_property_read_bool(node, "ti,low-power-bypass"))
449 dpll_mode |= 1 << DPLL_LOW_POWER_BYPASS;
450
451 if (of_property_read_bool(node, "ti,lock"))
452 dpll_mode |= 1 << DPLL_LOCKED;
453
454 if (dpll_mode)
455 dd->modes = dpll_mode;
456
Tero Kristoed405a22015-01-29 22:24:28 +0200457 _register_dpll(&clk_hw->hw, node);
Tero Kristof38b0dd2013-06-12 16:04:34 +0300458 return;
459
460cleanup:
461 kfree(dd);
462 kfree(parent_names);
463 kfree(init);
464 kfree(clk_hw);
465}
466
467#if defined(CONFIG_ARCH_OMAP4) || defined(CONFIG_SOC_OMAP5) || \
468 defined(CONFIG_SOC_DRA7XX)
469static void __init of_ti_omap4_dpll_x2_setup(struct device_node *node)
470{
Tero Kristoed405a22015-01-29 22:24:28 +0200471 _register_dpll_x2(node, &dpll_x2_ck_ops, &clkhwops_omap4_dpllmx);
Tero Kristof38b0dd2013-06-12 16:04:34 +0300472}
473CLK_OF_DECLARE(ti_omap4_dpll_x2_clock, "ti,omap4-dpll-x2-clock",
474 of_ti_omap4_dpll_x2_setup);
475#endif
476
Roger Quadros4332ec12014-06-17 17:03:24 +0300477#if defined(CONFIG_SOC_AM33XX) || defined(CONFIG_SOC_AM43XX)
Tero Kristof38b0dd2013-06-12 16:04:34 +0300478static void __init of_ti_am3_dpll_x2_setup(struct device_node *node)
479{
Tero Kristoed405a22015-01-29 22:24:28 +0200480 _register_dpll_x2(node, &dpll_x2_ck_ops, NULL);
Tero Kristof38b0dd2013-06-12 16:04:34 +0300481}
482CLK_OF_DECLARE(ti_am3_dpll_x2_clock, "ti,am3-dpll-x2-clock",
483 of_ti_am3_dpll_x2_setup);
484#endif
485
486#ifdef CONFIG_ARCH_OMAP3
487static void __init of_ti_omap3_dpll_setup(struct device_node *node)
488{
489 const struct dpll_data dd = {
490 .idlest_mask = 0x1,
491 .enable_mask = 0x7,
492 .autoidle_mask = 0x7,
493 .mult_mask = 0x7ff << 8,
494 .div1_mask = 0x7f,
495 .max_multiplier = 2047,
496 .max_divider = 128,
497 .min_divider = 1,
498 .freqsel_mask = 0xf0,
499 .modes = (1 << DPLL_LOW_POWER_BYPASS) | (1 << DPLL_LOCKED),
500 };
501
Richard Watts035cd482016-12-02 23:14:38 +0200502 if ((of_machine_is_compatible("ti,omap3630") ||
503 of_machine_is_compatible("ti,omap36xx")) &&
504 !strcmp(node->name, "dpll5_ck"))
505 of_ti_dpll_setup(node, &omap3_dpll5_ck_ops, &dd);
506 else
507 of_ti_dpll_setup(node, &omap3_dpll_ck_ops, &dd);
Tero Kristof38b0dd2013-06-12 16:04:34 +0300508}
509CLK_OF_DECLARE(ti_omap3_dpll_clock, "ti,omap3-dpll-clock",
510 of_ti_omap3_dpll_setup);
511
512static void __init of_ti_omap3_core_dpll_setup(struct device_node *node)
513{
514 const struct dpll_data dd = {
515 .idlest_mask = 0x1,
516 .enable_mask = 0x7,
517 .autoidle_mask = 0x7,
518 .mult_mask = 0x7ff << 16,
519 .div1_mask = 0x7f << 8,
520 .max_multiplier = 2047,
521 .max_divider = 128,
522 .min_divider = 1,
523 .freqsel_mask = 0xf0,
524 };
525
Tero Kristoa6fe3772014-02-21 17:22:32 +0200526 of_ti_dpll_setup(node, &omap3_dpll_core_ck_ops, &dd);
Tero Kristof38b0dd2013-06-12 16:04:34 +0300527}
528CLK_OF_DECLARE(ti_omap3_core_dpll_clock, "ti,omap3-dpll-core-clock",
529 of_ti_omap3_core_dpll_setup);
530
531static void __init of_ti_omap3_per_dpll_setup(struct device_node *node)
532{
533 const struct dpll_data dd = {
534 .idlest_mask = 0x1 << 1,
535 .enable_mask = 0x7 << 16,
536 .autoidle_mask = 0x7 << 3,
537 .mult_mask = 0x7ff << 8,
538 .div1_mask = 0x7f,
539 .max_multiplier = 2047,
540 .max_divider = 128,
541 .min_divider = 1,
542 .freqsel_mask = 0xf00000,
543 .modes = (1 << DPLL_LOW_POWER_STOP) | (1 << DPLL_LOCKED),
544 };
545
Tero Kristoa6fe3772014-02-21 17:22:32 +0200546 of_ti_dpll_setup(node, &omap3_dpll_per_ck_ops, &dd);
Tero Kristof38b0dd2013-06-12 16:04:34 +0300547}
548CLK_OF_DECLARE(ti_omap3_per_dpll_clock, "ti,omap3-dpll-per-clock",
549 of_ti_omap3_per_dpll_setup);
550
551static void __init of_ti_omap3_per_jtype_dpll_setup(struct device_node *node)
552{
553 const struct dpll_data dd = {
554 .idlest_mask = 0x1 << 1,
555 .enable_mask = 0x7 << 16,
556 .autoidle_mask = 0x7 << 3,
557 .mult_mask = 0xfff << 8,
558 .div1_mask = 0x7f,
559 .max_multiplier = 4095,
560 .max_divider = 128,
561 .min_divider = 1,
562 .sddiv_mask = 0xff << 24,
563 .dco_mask = 0xe << 20,
564 .flags = DPLL_J_TYPE,
565 .modes = (1 << DPLL_LOW_POWER_STOP) | (1 << DPLL_LOCKED),
566 };
567
Tero Kristoa6fe3772014-02-21 17:22:32 +0200568 of_ti_dpll_setup(node, &omap3_dpll_per_ck_ops, &dd);
Tero Kristof38b0dd2013-06-12 16:04:34 +0300569}
570CLK_OF_DECLARE(ti_omap3_per_jtype_dpll_clock, "ti,omap3-dpll-per-j-type-clock",
571 of_ti_omap3_per_jtype_dpll_setup);
572#endif
573
574static void __init of_ti_omap4_dpll_setup(struct device_node *node)
575{
576 const struct dpll_data dd = {
577 .idlest_mask = 0x1,
578 .enable_mask = 0x7,
579 .autoidle_mask = 0x7,
580 .mult_mask = 0x7ff << 8,
581 .div1_mask = 0x7f,
582 .max_multiplier = 2047,
583 .max_divider = 128,
584 .min_divider = 1,
585 .modes = (1 << DPLL_LOW_POWER_BYPASS) | (1 << DPLL_LOCKED),
586 };
587
Tero Kristoa6fe3772014-02-21 17:22:32 +0200588 of_ti_dpll_setup(node, &dpll_ck_ops, &dd);
Tero Kristof38b0dd2013-06-12 16:04:34 +0300589}
590CLK_OF_DECLARE(ti_omap4_dpll_clock, "ti,omap4-dpll-clock",
591 of_ti_omap4_dpll_setup);
592
Nishanth Menonb4be0182014-05-16 05:45:59 -0500593static void __init of_ti_omap5_mpu_dpll_setup(struct device_node *node)
594{
595 const struct dpll_data dd = {
596 .idlest_mask = 0x1,
597 .enable_mask = 0x7,
598 .autoidle_mask = 0x7,
599 .mult_mask = 0x7ff << 8,
600 .div1_mask = 0x7f,
601 .max_multiplier = 2047,
602 .max_divider = 128,
603 .dcc_mask = BIT(22),
604 .dcc_rate = 1400000000, /* DCC beyond 1.4GHz */
605 .min_divider = 1,
606 .modes = (1 << DPLL_LOW_POWER_BYPASS) | (1 << DPLL_LOCKED),
607 };
608
609 of_ti_dpll_setup(node, &dpll_ck_ops, &dd);
610}
611CLK_OF_DECLARE(of_ti_omap5_mpu_dpll_clock, "ti,omap5-mpu-dpll-clock",
612 of_ti_omap5_mpu_dpll_setup);
613
Tero Kristof38b0dd2013-06-12 16:04:34 +0300614static void __init of_ti_omap4_core_dpll_setup(struct device_node *node)
615{
616 const struct dpll_data dd = {
617 .idlest_mask = 0x1,
618 .enable_mask = 0x7,
619 .autoidle_mask = 0x7,
620 .mult_mask = 0x7ff << 8,
621 .div1_mask = 0x7f,
622 .max_multiplier = 2047,
623 .max_divider = 128,
624 .min_divider = 1,
625 .modes = (1 << DPLL_LOW_POWER_BYPASS) | (1 << DPLL_LOCKED),
626 };
627
Tero Kristoa6fe3772014-02-21 17:22:32 +0200628 of_ti_dpll_setup(node, &dpll_core_ck_ops, &dd);
Tero Kristof38b0dd2013-06-12 16:04:34 +0300629}
630CLK_OF_DECLARE(ti_omap4_core_dpll_clock, "ti,omap4-dpll-core-clock",
631 of_ti_omap4_core_dpll_setup);
632
633#if defined(CONFIG_ARCH_OMAP4) || defined(CONFIG_SOC_OMAP5) || \
634 defined(CONFIG_SOC_DRA7XX)
635static void __init of_ti_omap4_m4xen_dpll_setup(struct device_node *node)
636{
637 const struct dpll_data dd = {
638 .idlest_mask = 0x1,
639 .enable_mask = 0x7,
640 .autoidle_mask = 0x7,
641 .mult_mask = 0x7ff << 8,
642 .div1_mask = 0x7f,
643 .max_multiplier = 2047,
644 .max_divider = 128,
645 .min_divider = 1,
646 .m4xen_mask = 0x800,
647 .lpmode_mask = 1 << 10,
648 .modes = (1 << DPLL_LOW_POWER_BYPASS) | (1 << DPLL_LOCKED),
649 };
650
Tero Kristoa6fe3772014-02-21 17:22:32 +0200651 of_ti_dpll_setup(node, &dpll_m4xen_ck_ops, &dd);
Tero Kristof38b0dd2013-06-12 16:04:34 +0300652}
653CLK_OF_DECLARE(ti_omap4_m4xen_dpll_clock, "ti,omap4-dpll-m4xen-clock",
654 of_ti_omap4_m4xen_dpll_setup);
655
656static void __init of_ti_omap4_jtype_dpll_setup(struct device_node *node)
657{
658 const struct dpll_data dd = {
659 .idlest_mask = 0x1,
660 .enable_mask = 0x7,
661 .autoidle_mask = 0x7,
662 .mult_mask = 0xfff << 8,
663 .div1_mask = 0xff,
664 .max_multiplier = 4095,
665 .max_divider = 256,
666 .min_divider = 1,
667 .sddiv_mask = 0xff << 24,
668 .flags = DPLL_J_TYPE,
669 .modes = (1 << DPLL_LOW_POWER_BYPASS) | (1 << DPLL_LOCKED),
670 };
671
Tero Kristoa6fe3772014-02-21 17:22:32 +0200672 of_ti_dpll_setup(node, &dpll_m4xen_ck_ops, &dd);
Tero Kristof38b0dd2013-06-12 16:04:34 +0300673}
674CLK_OF_DECLARE(ti_omap4_jtype_dpll_clock, "ti,omap4-dpll-j-type-clock",
675 of_ti_omap4_jtype_dpll_setup);
676#endif
677
678static void __init of_ti_am3_no_gate_dpll_setup(struct device_node *node)
679{
680 const struct dpll_data dd = {
681 .idlest_mask = 0x1,
682 .enable_mask = 0x7,
Tero Kristof38b0dd2013-06-12 16:04:34 +0300683 .mult_mask = 0x7ff << 8,
684 .div1_mask = 0x7f,
685 .max_multiplier = 2047,
686 .max_divider = 128,
687 .min_divider = 1,
Tero Kristo3db5ca22016-03-16 21:54:56 +0200688 .max_rate = 1000000000,
Tero Kristof38b0dd2013-06-12 16:04:34 +0300689 .modes = (1 << DPLL_LOW_POWER_BYPASS) | (1 << DPLL_LOCKED),
690 };
691
Tero Kristoa6fe3772014-02-21 17:22:32 +0200692 of_ti_dpll_setup(node, &dpll_no_gate_ck_ops, &dd);
Tero Kristof38b0dd2013-06-12 16:04:34 +0300693}
694CLK_OF_DECLARE(ti_am3_no_gate_dpll_clock, "ti,am3-dpll-no-gate-clock",
695 of_ti_am3_no_gate_dpll_setup);
696
697static void __init of_ti_am3_jtype_dpll_setup(struct device_node *node)
698{
699 const struct dpll_data dd = {
700 .idlest_mask = 0x1,
701 .enable_mask = 0x7,
Tero Kristof38b0dd2013-06-12 16:04:34 +0300702 .mult_mask = 0x7ff << 8,
703 .div1_mask = 0x7f,
704 .max_multiplier = 4095,
705 .max_divider = 256,
706 .min_divider = 2,
707 .flags = DPLL_J_TYPE,
Tero Kristo3db5ca22016-03-16 21:54:56 +0200708 .max_rate = 2000000000,
Tero Kristof38b0dd2013-06-12 16:04:34 +0300709 .modes = (1 << DPLL_LOW_POWER_BYPASS) | (1 << DPLL_LOCKED),
710 };
711
Tero Kristoa6fe3772014-02-21 17:22:32 +0200712 of_ti_dpll_setup(node, &dpll_ck_ops, &dd);
Tero Kristof38b0dd2013-06-12 16:04:34 +0300713}
714CLK_OF_DECLARE(ti_am3_jtype_dpll_clock, "ti,am3-dpll-j-type-clock",
715 of_ti_am3_jtype_dpll_setup);
716
717static void __init of_ti_am3_no_gate_jtype_dpll_setup(struct device_node *node)
718{
719 const struct dpll_data dd = {
720 .idlest_mask = 0x1,
721 .enable_mask = 0x7,
Tero Kristof38b0dd2013-06-12 16:04:34 +0300722 .mult_mask = 0x7ff << 8,
723 .div1_mask = 0x7f,
724 .max_multiplier = 2047,
725 .max_divider = 128,
726 .min_divider = 1,
Tero Kristo3db5ca22016-03-16 21:54:56 +0200727 .max_rate = 2000000000,
Tero Kristof38b0dd2013-06-12 16:04:34 +0300728 .flags = DPLL_J_TYPE,
729 .modes = (1 << DPLL_LOW_POWER_BYPASS) | (1 << DPLL_LOCKED),
730 };
731
Tero Kristoa6fe3772014-02-21 17:22:32 +0200732 of_ti_dpll_setup(node, &dpll_no_gate_ck_ops, &dd);
Tero Kristof38b0dd2013-06-12 16:04:34 +0300733}
734CLK_OF_DECLARE(ti_am3_no_gate_jtype_dpll_clock,
735 "ti,am3-dpll-no-gate-j-type-clock",
736 of_ti_am3_no_gate_jtype_dpll_setup);
737
738static void __init of_ti_am3_dpll_setup(struct device_node *node)
739{
740 const struct dpll_data dd = {
741 .idlest_mask = 0x1,
742 .enable_mask = 0x7,
Tero Kristof38b0dd2013-06-12 16:04:34 +0300743 .mult_mask = 0x7ff << 8,
744 .div1_mask = 0x7f,
745 .max_multiplier = 2047,
746 .max_divider = 128,
747 .min_divider = 1,
Tero Kristo3db5ca22016-03-16 21:54:56 +0200748 .max_rate = 1000000000,
Tero Kristof38b0dd2013-06-12 16:04:34 +0300749 .modes = (1 << DPLL_LOW_POWER_BYPASS) | (1 << DPLL_LOCKED),
750 };
751
Tero Kristoa6fe3772014-02-21 17:22:32 +0200752 of_ti_dpll_setup(node, &dpll_ck_ops, &dd);
Tero Kristof38b0dd2013-06-12 16:04:34 +0300753}
754CLK_OF_DECLARE(ti_am3_dpll_clock, "ti,am3-dpll-clock", of_ti_am3_dpll_setup);
755
756static void __init of_ti_am3_core_dpll_setup(struct device_node *node)
757{
758 const struct dpll_data dd = {
759 .idlest_mask = 0x1,
760 .enable_mask = 0x7,
Tero Kristof38b0dd2013-06-12 16:04:34 +0300761 .mult_mask = 0x7ff << 8,
762 .div1_mask = 0x7f,
763 .max_multiplier = 2047,
764 .max_divider = 128,
765 .min_divider = 1,
Tero Kristo3db5ca22016-03-16 21:54:56 +0200766 .max_rate = 1000000000,
Tero Kristof38b0dd2013-06-12 16:04:34 +0300767 .modes = (1 << DPLL_LOW_POWER_BYPASS) | (1 << DPLL_LOCKED),
768 };
769
Tero Kristoa6fe3772014-02-21 17:22:32 +0200770 of_ti_dpll_setup(node, &dpll_core_ck_ops, &dd);
Tero Kristof38b0dd2013-06-12 16:04:34 +0300771}
772CLK_OF_DECLARE(ti_am3_core_dpll_clock, "ti,am3-dpll-core-clock",
773 of_ti_am3_core_dpll_setup);
Tero Kristoaa76fcf2014-02-21 17:36:21 +0200774
775static void __init of_ti_omap2_core_dpll_setup(struct device_node *node)
776{
777 const struct dpll_data dd = {
778 .enable_mask = 0x3,
779 .mult_mask = 0x3ff << 12,
780 .div1_mask = 0xf << 8,
781 .max_divider = 16,
782 .min_divider = 1,
783 };
784
785 of_ti_dpll_setup(node, &omap2_dpll_core_ck_ops, &dd);
786}
787CLK_OF_DECLARE(ti_omap2_core_dpll_clock, "ti,omap2-dpll-core-clock",
788 of_ti_omap2_core_dpll_setup);