1 // SPDX-License-Identifier: GPL-2.0
3 * PLL clock driver for TI Davinci SoCs
5 * Copyright (C) 2018 David Lechner <david@lechnology.com>
7 * Based on arch/arm/mach-davinci/clock.c
8 * Copyright (C) 2006-2007 Texas Instruments.
9 * Copyright (C) 2008-2009 Deep Root Systems, LLC
12 #include <linux/clk-provider.h>
13 #include <linux/clk.h>
14 #include <linux/clk/davinci.h>
15 #include <linux/delay.h>
16 #include <linux/err.h>
18 #include <linux/kernel.h>
19 #include <linux/mfd/syscon.h>
20 #include <linux/notifier.h>
21 #include <linux/of_address.h>
22 #include <linux/of_device.h>
24 #include <linux/platform_data/clk-davinci-pll.h>
25 #include <linux/platform_device.h>
26 #include <linux/regmap.h>
27 #include <linux/slab.h>
28 #include <linux/types.h>
32 #define MAX_NAME_SIZE 20
33 #define OSCIN_CLK_NAME "oscin"
38 #define PLLSECCTL 0x108
61 #define PLLCTL_PLLEN BIT(0)
62 #define PLLCTL_PLLPWRDN BIT(1)
63 #define PLLCTL_PLLRST BIT(3)
64 #define PLLCTL_PLLDIS BIT(4)
65 #define PLLCTL_PLLENSRC BIT(5)
66 #define PLLCTL_CLKMODE BIT(8)
68 /* shared by most *DIV registers */
69 #define DIV_RATIO_SHIFT 0
70 #define DIV_RATIO_WIDTH 5
71 #define DIV_ENABLE_SHIFT 15
73 #define PLLCMD_GOSET BIT(0)
74 #define PLLSTAT_GOSTAT BIT(0)
76 #define CKEN_OBSCLK_SHIFT 1
77 #define CKEN_AUXEN_SHIFT 0
80 * OMAP-L138 system reference guide recommends a wait for 4 OSCIN/CLKIN
81 * cycles to ensure that the PLLC has switched to bypass mode. Delay of 1us
82 * ensures we are good for all > 4MHz OSCIN/CLKIN inputs. Typically the input
83 * is ~25MHz. Units are micro seconds.
85 #define PLL_BYPASS_TIME 1
87 /* From OMAP-L138 datasheet table 6-4. Units are micro seconds */
88 #define PLL_RESET_TIME 1
91 * From OMAP-L138 datasheet table 6-4; assuming prediv = 1, sqrt(pllm) = 4
92 * Units are micro seconds.
94 #define PLL_LOCK_TIME 20
97 * struct davinci_pll_clk - Main PLL clock (aka PLLOUT)
98 * @hw: clk_hw for the pll
99 * @base: Base memory address
100 * @pllm_min: The minimum allowable PLLM[PLLM] value
101 * @pllm_max: The maxiumum allowable PLLM[PLLM] value
102 * @pllm_mask: Bitmask for PLLM[PLLM] value
104 struct davinci_pll_clk
{
112 #define to_davinci_pll_clk(_hw) \
113 container_of((_hw), struct davinci_pll_clk, hw)
115 static unsigned long davinci_pll_recalc_rate(struct clk_hw
*hw
,
116 unsigned long parent_rate
)
118 struct davinci_pll_clk
*pll
= to_davinci_pll_clk(hw
);
119 unsigned long rate
= parent_rate
;
122 mult
= readl(pll
->base
+ PLLM
) & pll
->pllm_mask
;
128 static int davinci_pll_determine_rate(struct clk_hw
*hw
,
129 struct clk_rate_request
*req
)
131 struct davinci_pll_clk
*pll
= to_davinci_pll_clk(hw
);
132 struct clk_hw
*parent
= req
->best_parent_hw
;
133 unsigned long parent_rate
= req
->best_parent_rate
;
134 unsigned long rate
= req
->rate
;
135 unsigned long best_rate
, r
;
138 /* there is a limited range of valid outputs (see datasheet) */
139 if (rate
< req
->min_rate
)
142 rate
= min(rate
, req
->max_rate
);
143 mult
= rate
/ parent_rate
;
144 best_rate
= parent_rate
* mult
;
146 /* easy case when there is no PREDIV */
147 if (!(clk_hw_get_flags(hw
) & CLK_SET_RATE_PARENT
)) {
148 if (best_rate
< req
->min_rate
)
151 if (mult
< pll
->pllm_min
|| mult
> pll
->pllm_max
)
154 req
->rate
= best_rate
;
159 /* see if the PREDIV clock can help us */
162 for (mult
= pll
->pllm_min
; mult
<= pll
->pllm_max
; mult
++) {
163 parent_rate
= clk_hw_round_rate(parent
, rate
/ mult
);
164 r
= parent_rate
* mult
;
165 if (r
< req
->min_rate
)
167 if (r
> rate
|| r
> req
->max_rate
)
171 req
->rate
= best_rate
;
172 req
->best_parent_rate
= parent_rate
;
173 if (best_rate
== rate
)
181 static int davinci_pll_set_rate(struct clk_hw
*hw
, unsigned long rate
,
182 unsigned long parent_rate
)
184 struct davinci_pll_clk
*pll
= to_davinci_pll_clk(hw
);
187 mult
= rate
/ parent_rate
;
188 writel(mult
- 1, pll
->base
+ PLLM
);
193 #ifdef CONFIG_DEBUG_FS
194 static void davinci_pll_debug_init(struct clk_hw
*hw
, struct dentry
*dentry
);
196 #define davinci_pll_debug_init NULL
199 static const struct clk_ops davinci_pll_ops
= {
200 .recalc_rate
= davinci_pll_recalc_rate
,
201 .determine_rate
= davinci_pll_determine_rate
,
202 .set_rate
= davinci_pll_set_rate
,
203 .debug_init
= davinci_pll_debug_init
,
206 /* PLLM works differently on DM365 */
207 static unsigned long dm365_pll_recalc_rate(struct clk_hw
*hw
,
208 unsigned long parent_rate
)
210 struct davinci_pll_clk
*pll
= to_davinci_pll_clk(hw
);
211 unsigned long rate
= parent_rate
;
214 mult
= readl(pll
->base
+ PLLM
) & pll
->pllm_mask
;
220 static const struct clk_ops dm365_pll_ops
= {
221 .recalc_rate
= dm365_pll_recalc_rate
,
222 .debug_init
= davinci_pll_debug_init
,
226 * davinci_pll_div_register - common *DIV clock implementation
227 * @dev: The PLL platform device or NULL
228 * @name: the clock name
229 * @parent_name: the parent clock name
230 * @reg: the *DIV register
231 * @fixed: if true, the divider is a fixed value
232 * @flags: bitmap of CLK_* flags from clock-provider.h
234 static struct clk
*davinci_pll_div_register(struct device
*dev
,
236 const char *parent_name
,
238 bool fixed
, u32 flags
)
240 const char * const *parent_names
= parent_name
? &parent_name
: NULL
;
241 int num_parents
= parent_name
? 1 : 0;
242 const struct clk_ops
*divider_ops
= &clk_divider_ops
;
243 struct clk_gate
*gate
;
244 struct clk_divider
*divider
;
248 gate
= kzalloc(sizeof(*gate
), GFP_KERNEL
);
250 return ERR_PTR(-ENOMEM
);
253 gate
->bit_idx
= DIV_ENABLE_SHIFT
;
255 divider
= kzalloc(sizeof(*divider
), GFP_KERNEL
);
262 divider
->shift
= DIV_RATIO_SHIFT
;
263 divider
->width
= DIV_RATIO_WIDTH
;
266 divider
->flags
|= CLK_DIVIDER_READ_ONLY
;
267 divider_ops
= &clk_divider_ro_ops
;
270 clk
= clk_register_composite(dev
, name
, parent_names
, num_parents
,
271 NULL
, NULL
, ÷r
->hw
, divider_ops
,
272 &gate
->hw
, &clk_gate_ops
, flags
);
275 goto err_free_divider
;
288 struct davinci_pllen_clk
{
293 #define to_davinci_pllen_clk(_hw) \
294 container_of((_hw), struct davinci_pllen_clk, hw)
296 static const struct clk_ops davinci_pllen_ops
= {
297 /* this clocks just uses the clock notification feature */
301 * The PLL has to be switched into bypass mode while we are chaning the rate,
302 * so we do that on the PLLEN clock since it is the end of the line. This will
303 * switch to bypass before any of the parent clocks (PREDIV, PLL, POSTDIV) are
304 * changed and will switch back to the PLL after the changes have been made.
306 static int davinci_pllen_rate_change(struct notifier_block
*nb
,
307 unsigned long flags
, void *data
)
309 struct clk_notifier_data
*cnd
= data
;
310 struct clk_hw
*hw
= __clk_get_hw(cnd
->clk
);
311 struct davinci_pllen_clk
*pll
= to_davinci_pllen_clk(hw
);
314 ctrl
= readl(pll
->base
+ PLLCTL
);
316 if (flags
== PRE_RATE_CHANGE
) {
317 /* Switch the PLL to bypass mode */
318 ctrl
&= ~(PLLCTL_PLLENSRC
| PLLCTL_PLLEN
);
319 writel(ctrl
, pll
->base
+ PLLCTL
);
321 udelay(PLL_BYPASS_TIME
);
323 /* Reset and enable PLL */
324 ctrl
&= ~(PLLCTL_PLLRST
| PLLCTL_PLLDIS
);
325 writel(ctrl
, pll
->base
+ PLLCTL
);
327 udelay(PLL_RESET_TIME
);
329 /* Bring PLL out of reset */
330 ctrl
|= PLLCTL_PLLRST
;
331 writel(ctrl
, pll
->base
+ PLLCTL
);
333 udelay(PLL_LOCK_TIME
);
335 /* Remove PLL from bypass mode */
336 ctrl
|= PLLCTL_PLLEN
;
337 writel(ctrl
, pll
->base
+ PLLCTL
);
343 static struct notifier_block davinci_pllen_notifier
= {
344 .notifier_call
= davinci_pllen_rate_change
,
348 * davinci_pll_clk_register - Register a PLL clock
349 * @dev: The PLL platform device or NULL
350 * @info: The device-specific clock info
351 * @parent_name: The parent clock name
352 * @base: The PLL's memory region
353 * @cfgchip: CFGCHIP syscon regmap for info->unlock_reg or NULL
355 * This creates a series of clocks that represent the PLL.
357 * OSCIN > [PREDIV >] PLL > [POSTDIV >] PLLEN
359 * - OSCIN is the parent clock (on secondary PLL, may come from primary PLL)
360 * - PREDIV and POSTDIV are optional (depends on the PLL controller)
361 * - PLL is the PLL output (aka PLLOUT)
362 * - PLLEN is the bypass multiplexer
364 * Returns: The PLLOUT clock or a negative error code.
366 struct clk
*davinci_pll_clk_register(struct device
*dev
,
367 const struct davinci_pll_clk_info
*info
,
368 const char *parent_name
,
370 struct regmap
*cfgchip
)
372 char prediv_name
[MAX_NAME_SIZE
];
373 char pllout_name
[MAX_NAME_SIZE
];
374 char postdiv_name
[MAX_NAME_SIZE
];
375 char pllen_name
[MAX_NAME_SIZE
];
376 struct clk_init_data init
;
377 struct davinci_pll_clk
*pllout
;
378 struct davinci_pllen_clk
*pllen
;
379 struct clk
*oscin_clk
= NULL
;
380 struct clk
*prediv_clk
= NULL
;
381 struct clk
*pllout_clk
;
382 struct clk
*postdiv_clk
= NULL
;
383 struct clk
*pllen_clk
;
386 if (info
->flags
& PLL_HAS_CLKMODE
) {
388 * If a PLL has PLLCTL[CLKMODE], then it is the primary PLL.
389 * We register a clock named "oscin" that serves as the internal
390 * "input clock" domain shared by both PLLs (if there are 2)
391 * and will be the parent clock to the AUXCLK, SYSCLKBP and
392 * OBSCLK domains. NB: The various TRMs use "OSCIN" to mean
393 * a number of different things. In this driver we use it to
394 * mean the signal after the PLLCTL[CLKMODE] switch.
396 oscin_clk
= clk_register_fixed_factor(dev
, OSCIN_CLK_NAME
,
397 parent_name
, 0, 1, 1);
398 if (IS_ERR(oscin_clk
))
401 parent_name
= OSCIN_CLK_NAME
;
404 if (info
->flags
& PLL_HAS_PREDIV
) {
405 bool fixed
= info
->flags
& PLL_PREDIV_FIXED_DIV
;
408 snprintf(prediv_name
, MAX_NAME_SIZE
, "%s_prediv", info
->name
);
410 if (info
->flags
& PLL_PREDIV_ALWAYS_ENABLED
)
411 flags
|= CLK_IS_CRITICAL
;
413 /* Some? DM355 chips don't correctly report the PREDIV value */
414 if (info
->flags
& PLL_PREDIV_FIXED8
)
415 prediv_clk
= clk_register_fixed_factor(dev
, prediv_name
,
416 parent_name
, flags
, 1, 8);
418 prediv_clk
= davinci_pll_div_register(dev
, prediv_name
,
419 parent_name
, base
+ PREDIV
, fixed
, flags
);
420 if (IS_ERR(prediv_clk
)) {
421 ret
= PTR_ERR(prediv_clk
);
422 goto err_unregister_oscin
;
425 parent_name
= prediv_name
;
428 /* Unlock writing to PLL registers */
429 if (info
->unlock_reg
) {
430 if (IS_ERR_OR_NULL(cfgchip
))
431 dev_warn(dev
, "Failed to get CFGCHIP (%ld)\n",
434 regmap_write_bits(cfgchip
, info
->unlock_reg
,
435 info
->unlock_mask
, 0);
438 pllout
= kzalloc(sizeof(*pllout
), GFP_KERNEL
);
441 goto err_unregister_prediv
;
444 snprintf(pllout_name
, MAX_NAME_SIZE
, "%s_pllout", info
->name
);
446 init
.name
= pllout_name
;
447 if (info
->flags
& PLL_PLLM_2X
)
448 init
.ops
= &dm365_pll_ops
;
450 init
.ops
= &davinci_pll_ops
;
451 init
.parent_names
= &parent_name
;
452 init
.num_parents
= 1;
455 if (info
->flags
& PLL_HAS_PREDIV
)
456 init
.flags
|= CLK_SET_RATE_PARENT
;
458 pllout
->hw
.init
= &init
;
460 pllout
->pllm_mask
= info
->pllm_mask
;
461 pllout
->pllm_min
= info
->pllm_min
;
462 pllout
->pllm_max
= info
->pllm_max
;
464 pllout_clk
= clk_register(dev
, &pllout
->hw
);
465 if (IS_ERR(pllout_clk
)) {
466 ret
= PTR_ERR(pllout_clk
);
467 goto err_free_pllout
;
470 clk_hw_set_rate_range(&pllout
->hw
, info
->pllout_min_rate
,
471 info
->pllout_max_rate
);
473 parent_name
= pllout_name
;
475 if (info
->flags
& PLL_HAS_POSTDIV
) {
476 bool fixed
= info
->flags
& PLL_POSTDIV_FIXED_DIV
;
477 u32 flags
= CLK_SET_RATE_PARENT
;
479 snprintf(postdiv_name
, MAX_NAME_SIZE
, "%s_postdiv", info
->name
);
481 if (info
->flags
& PLL_POSTDIV_ALWAYS_ENABLED
)
482 flags
|= CLK_IS_CRITICAL
;
484 postdiv_clk
= davinci_pll_div_register(dev
, postdiv_name
,
485 parent_name
, base
+ POSTDIV
, fixed
, flags
);
486 if (IS_ERR(postdiv_clk
)) {
487 ret
= PTR_ERR(postdiv_clk
);
488 goto err_unregister_pllout
;
491 parent_name
= postdiv_name
;
494 pllen
= kzalloc(sizeof(*pllen
), GFP_KERNEL
);
497 goto err_unregister_postdiv
;
500 snprintf(pllen_name
, MAX_NAME_SIZE
, "%s_pllen", info
->name
);
502 init
.name
= pllen_name
;
503 init
.ops
= &davinci_pllen_ops
;
504 init
.parent_names
= &parent_name
;
505 init
.num_parents
= 1;
506 init
.flags
= CLK_SET_RATE_PARENT
;
508 pllen
->hw
.init
= &init
;
511 pllen_clk
= clk_register(dev
, &pllen
->hw
);
512 if (IS_ERR(pllen_clk
)) {
513 ret
= PTR_ERR(pllen_clk
);
517 clk_notifier_register(pllen_clk
, &davinci_pllen_notifier
);
523 err_unregister_postdiv
:
524 clk_unregister(postdiv_clk
);
525 err_unregister_pllout
:
526 clk_unregister(pllout_clk
);
529 err_unregister_prediv
:
530 clk_unregister(prediv_clk
);
531 err_unregister_oscin
:
532 clk_unregister(oscin_clk
);
538 * davinci_pll_auxclk_register - Register bypass clock (AUXCLK)
539 * @dev: The PLL platform device or NULL
540 * @name: The clock name
541 * @base: The PLL memory region
543 struct clk
*davinci_pll_auxclk_register(struct device
*dev
,
547 return clk_register_gate(dev
, name
, OSCIN_CLK_NAME
, 0, base
+ CKEN
,
548 CKEN_AUXEN_SHIFT
, 0, NULL
);
552 * davinci_pll_sysclkbp_clk_register - Register bypass divider clock (SYSCLKBP)
553 * @dev: The PLL platform device or NULL
554 * @name: The clock name
555 * @base: The PLL memory region
557 struct clk
*davinci_pll_sysclkbp_clk_register(struct device
*dev
,
561 return clk_register_divider(dev
, name
, OSCIN_CLK_NAME
, 0, base
+ BPDIV
,
562 DIV_RATIO_SHIFT
, DIV_RATIO_WIDTH
,
563 CLK_DIVIDER_READ_ONLY
, NULL
);
567 * davinci_pll_obsclk_register - Register oscillator divider clock (OBSCLK)
568 * @dev: The PLL platform device or NULL
569 * @info: The clock info
570 * @base: The PLL memory region
573 davinci_pll_obsclk_register(struct device
*dev
,
574 const struct davinci_pll_obsclk_info
*info
,
578 struct clk_gate
*gate
;
579 struct clk_divider
*divider
;
584 mux
= kzalloc(sizeof(*mux
), GFP_KERNEL
);
586 return ERR_PTR(-ENOMEM
);
588 mux
->reg
= base
+ OCSEL
;
589 mux
->table
= info
->table
;
590 mux
->mask
= info
->ocsrc_mask
;
592 gate
= kzalloc(sizeof(*gate
), GFP_KERNEL
);
598 gate
->reg
= base
+ CKEN
;
599 gate
->bit_idx
= CKEN_OBSCLK_SHIFT
;
601 divider
= kzalloc(sizeof(*divider
), GFP_KERNEL
);
607 divider
->reg
= base
+ OSCDIV
;
608 divider
->shift
= DIV_RATIO_SHIFT
;
609 divider
->width
= DIV_RATIO_WIDTH
;
611 /* make sure divider is enabled just in case bootloader disabled it */
612 oscdiv
= readl(base
+ OSCDIV
);
613 oscdiv
|= BIT(DIV_ENABLE_SHIFT
);
614 writel(oscdiv
, base
+ OSCDIV
);
616 clk
= clk_register_composite(dev
, info
->name
, info
->parent_names
,
618 &mux
->hw
, &clk_mux_ops
,
619 ÷r
->hw
, &clk_divider_ops
,
620 &gate
->hw
, &clk_gate_ops
, 0);
624 goto err_free_divider
;
639 /* The PLL SYSCLKn clocks have a mechanism for synchronizing rate changes. */
640 static int davinci_pll_sysclk_rate_change(struct notifier_block
*nb
,
641 unsigned long flags
, void *data
)
643 struct clk_notifier_data
*cnd
= data
;
644 struct clk_hw
*hw
= __clk_get_hw(clk_get_parent(cnd
->clk
));
645 struct davinci_pllen_clk
*pll
= to_davinci_pllen_clk(hw
);
649 case POST_RATE_CHANGE
:
650 /* apply the changes */
651 pllcmd
= readl(pll
->base
+ PLLCMD
);
652 pllcmd
|= PLLCMD_GOSET
;
653 writel(pllcmd
, pll
->base
+ PLLCMD
);
655 case PRE_RATE_CHANGE
:
656 /* Wait until for outstanding changes to take effect */
658 pllstat
= readl(pll
->base
+ PLLSTAT
);
659 } while (pllstat
& PLLSTAT_GOSTAT
);
666 static struct notifier_block davinci_pll_sysclk_notifier
= {
667 .notifier_call
= davinci_pll_sysclk_rate_change
,
671 * davinci_pll_sysclk_register - Register divider clocks (SYSCLKn)
672 * @dev: The PLL platform device or NULL
673 * @info: The clock info
674 * @base: The PLL memory region
677 davinci_pll_sysclk_register(struct device
*dev
,
678 const struct davinci_pll_sysclk_info
*info
,
681 const struct clk_ops
*divider_ops
= &clk_divider_ops
;
682 struct clk_gate
*gate
;
683 struct clk_divider
*divider
;
689 /* PLLDIVn registers are not entirely consecutive */
691 reg
= PLLDIV1
+ 4 * (info
->id
- 1);
693 reg
= PLLDIV4
+ 4 * (info
->id
- 4);
695 gate
= kzalloc(sizeof(*gate
), GFP_KERNEL
);
697 return ERR_PTR(-ENOMEM
);
699 gate
->reg
= base
+ reg
;
700 gate
->bit_idx
= DIV_ENABLE_SHIFT
;
702 divider
= kzalloc(sizeof(*divider
), GFP_KERNEL
);
708 divider
->reg
= base
+ reg
;
709 divider
->shift
= DIV_RATIO_SHIFT
;
710 divider
->width
= info
->ratio_width
;
713 if (info
->flags
& SYSCLK_FIXED_DIV
) {
714 divider
->flags
|= CLK_DIVIDER_READ_ONLY
;
715 divider_ops
= &clk_divider_ro_ops
;
718 /* Only the ARM clock can change the parent PLL rate */
719 if (info
->flags
& SYSCLK_ARM_RATE
)
720 flags
|= CLK_SET_RATE_PARENT
;
722 if (info
->flags
& SYSCLK_ALWAYS_ENABLED
)
723 flags
|= CLK_IS_CRITICAL
;
725 clk
= clk_register_composite(dev
, info
->name
, &info
->parent_name
, 1,
726 NULL
, NULL
, ÷r
->hw
, divider_ops
,
727 &gate
->hw
, &clk_gate_ops
, flags
);
730 goto err_free_divider
;
733 clk_notifier_register(clk
, &davinci_pll_sysclk_notifier
);
745 int of_davinci_pll_init(struct device
*dev
, struct device_node
*node
,
746 const struct davinci_pll_clk_info
*info
,
747 const struct davinci_pll_obsclk_info
*obsclk_info
,
748 const struct davinci_pll_sysclk_info
**div_info
,
751 struct regmap
*cfgchip
)
753 struct device_node
*child
;
754 const char *parent_name
;
757 if (info
->flags
& PLL_HAS_CLKMODE
)
758 parent_name
= of_clk_get_parent_name(node
, 0);
760 parent_name
= OSCIN_CLK_NAME
;
762 clk
= davinci_pll_clk_register(dev
, info
, parent_name
, base
, cfgchip
);
764 dev_err(dev
, "failed to register %s\n", info
->name
);
768 child
= of_get_child_by_name(node
, "pllout");
769 if (of_device_is_available(child
))
770 of_clk_add_provider(child
, of_clk_src_simple_get
, clk
);
773 child
= of_get_child_by_name(node
, "sysclk");
774 if (of_device_is_available(child
)) {
775 struct clk_onecell_data
*clk_data
;
777 int n_clks
= max_sysclk_id
+ 1;
780 clk_data
= kzalloc(sizeof(*clk_data
), GFP_KERNEL
);
786 clks
= kmalloc_array(n_clks
, sizeof(*clks
), GFP_KERNEL
);
793 clk_data
->clks
= clks
;
794 clk_data
->clk_num
= n_clks
;
796 for (i
= 0; i
< n_clks
; i
++)
797 clks
[i
] = ERR_PTR(-ENOENT
);
799 for (; *div_info
; div_info
++) {
800 clk
= davinci_pll_sysclk_register(dev
, *div_info
, base
);
802 dev_warn(dev
, "failed to register %s (%ld)\n",
803 (*div_info
)->name
, PTR_ERR(clk
));
805 clks
[(*div_info
)->id
] = clk
;
807 of_clk_add_provider(child
, of_clk_src_onecell_get
, clk_data
);
811 child
= of_get_child_by_name(node
, "auxclk");
812 if (of_device_is_available(child
)) {
813 char child_name
[MAX_NAME_SIZE
];
815 snprintf(child_name
, MAX_NAME_SIZE
, "%s_auxclk", info
->name
);
817 clk
= davinci_pll_auxclk_register(dev
, child_name
, base
);
819 dev_warn(dev
, "failed to register %s (%ld)\n",
820 child_name
, PTR_ERR(clk
));
822 of_clk_add_provider(child
, of_clk_src_simple_get
, clk
);
826 child
= of_get_child_by_name(node
, "obsclk");
827 if (of_device_is_available(child
)) {
829 clk
= davinci_pll_obsclk_register(dev
, obsclk_info
, base
);
831 clk
= ERR_PTR(-EINVAL
);
834 dev_warn(dev
, "failed to register obsclk (%ld)\n",
837 of_clk_add_provider(child
, of_clk_src_simple_get
, clk
);
844 static struct davinci_pll_platform_data
*davinci_pll_get_pdata(struct device
*dev
)
846 struct davinci_pll_platform_data
*pdata
= dev_get_platdata(dev
);
849 * Platform data is optional, so allocate a new struct if one was not
850 * provided. For device tree, this will always be the case.
853 pdata
= devm_kzalloc(dev
, sizeof(*pdata
), GFP_KERNEL
);
857 /* for device tree, we need to fill in the struct */
860 syscon_regmap_lookup_by_compatible("ti,da830-cfgchip");
865 /* needed in early boot for clocksource/clockevent */
866 #ifdef CONFIG_ARCH_DAVINCI_DA850
867 CLK_OF_DECLARE(da850_pll0
, "ti,da850-pll0", of_da850_pll0_init
);
870 static const struct of_device_id davinci_pll_of_match
[] = {
871 #ifdef CONFIG_ARCH_DAVINCI_DA850
872 { .compatible
= "ti,da850-pll1", .data
= of_da850_pll1_init
},
877 static const struct platform_device_id davinci_pll_id_table
[] = {
878 #ifdef CONFIG_ARCH_DAVINCI_DA830
879 { .name
= "da830-pll", .driver_data
= (kernel_ulong_t
)da830_pll_init
},
881 #ifdef CONFIG_ARCH_DAVINCI_DA850
882 { .name
= "da850-pll0", .driver_data
= (kernel_ulong_t
)da850_pll0_init
},
883 { .name
= "da850-pll1", .driver_data
= (kernel_ulong_t
)da850_pll1_init
},
885 #ifdef CONFIG_ARCH_DAVINCI_DM355
886 { .name
= "dm355-pll1", .driver_data
= (kernel_ulong_t
)dm355_pll1_init
},
887 { .name
= "dm355-pll2", .driver_data
= (kernel_ulong_t
)dm355_pll2_init
},
889 #ifdef CONFIG_ARCH_DAVINCI_DM365
890 { .name
= "dm365-pll1", .driver_data
= (kernel_ulong_t
)dm365_pll1_init
},
891 { .name
= "dm365-pll2", .driver_data
= (kernel_ulong_t
)dm365_pll2_init
},
893 #ifdef CONFIG_ARCH_DAVINCI_DM644x
894 { .name
= "dm644x-pll1", .driver_data
= (kernel_ulong_t
)dm644x_pll1_init
},
895 { .name
= "dm644x-pll2", .driver_data
= (kernel_ulong_t
)dm644x_pll2_init
},
897 #ifdef CONFIG_ARCH_DAVINCI_DM646x
898 { .name
= "dm646x-pll1", .driver_data
= (kernel_ulong_t
)dm646x_pll1_init
},
899 { .name
= "dm646x-pll2", .driver_data
= (kernel_ulong_t
)dm646x_pll2_init
},
904 typedef int (*davinci_pll_init
)(struct device
*dev
, void __iomem
*base
,
905 struct regmap
*cfgchip
);
907 static int davinci_pll_probe(struct platform_device
*pdev
)
909 struct device
*dev
= &pdev
->dev
;
910 struct davinci_pll_platform_data
*pdata
;
911 const struct of_device_id
*of_id
;
912 davinci_pll_init pll_init
= NULL
;
915 of_id
= of_match_device(davinci_pll_of_match
, dev
);
917 pll_init
= of_id
->data
;
918 else if (pdev
->id_entry
)
919 pll_init
= (void *)pdev
->id_entry
->driver_data
;
922 dev_err(dev
, "unable to find driver data\n");
926 pdata
= davinci_pll_get_pdata(dev
);
928 dev_err(dev
, "missing platform data\n");
932 base
= devm_platform_ioremap_resource(pdev
, 0);
934 return PTR_ERR(base
);
936 return pll_init(dev
, base
, pdata
->cfgchip
);
939 static struct platform_driver davinci_pll_driver
= {
940 .probe
= davinci_pll_probe
,
942 .name
= "davinci-pll-clk",
943 .of_match_table
= davinci_pll_of_match
,
945 .id_table
= davinci_pll_id_table
,
948 static int __init
davinci_pll_driver_init(void)
950 return platform_driver_register(&davinci_pll_driver
);
953 /* has to be postcore_initcall because PSC devices depend on PLL parent clocks */
954 postcore_initcall(davinci_pll_driver_init
);
956 #ifdef CONFIG_DEBUG_FS
957 #include <linux/debugfs.h>
959 #define DEBUG_REG(n) \
965 static const struct debugfs_reg32 davinci_pll_regs
[] = {
969 DEBUG_REG(PLLSECCTL
),
993 static void davinci_pll_debug_init(struct clk_hw
*hw
, struct dentry
*dentry
)
995 struct davinci_pll_clk
*pll
= to_davinci_pll_clk(hw
);
996 struct debugfs_regset32
*regset
;
998 regset
= kzalloc(sizeof(*regset
), GFP_KERNEL
);
1002 regset
->regs
= davinci_pll_regs
;
1003 regset
->nregs
= ARRAY_SIZE(davinci_pll_regs
);
1004 regset
->base
= pll
->base
;
1006 debugfs_create_regset32("registers", 0400, dentry
, regset
);