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>
22 #include <linux/platform_data/clk-davinci-pll.h>
23 #include <linux/platform_device.h>
24 #include <linux/property.h>
25 #include <linux/regmap.h>
26 #include <linux/slab.h>
27 #include <linux/types.h>
31 #define MAX_NAME_SIZE 20
32 #define OSCIN_CLK_NAME "oscin"
37 #define PLLSECCTL 0x108
60 #define PLLCTL_PLLEN BIT(0)
61 #define PLLCTL_PLLPWRDN BIT(1)
62 #define PLLCTL_PLLRST BIT(3)
63 #define PLLCTL_PLLDIS BIT(4)
64 #define PLLCTL_PLLENSRC BIT(5)
65 #define PLLCTL_CLKMODE BIT(8)
67 /* shared by most *DIV registers */
68 #define DIV_RATIO_SHIFT 0
69 #define DIV_RATIO_WIDTH 5
70 #define DIV_ENABLE_SHIFT 15
72 #define PLLCMD_GOSET BIT(0)
73 #define PLLSTAT_GOSTAT BIT(0)
75 #define CKEN_OBSCLK_SHIFT 1
76 #define CKEN_AUXEN_SHIFT 0
79 * OMAP-L138 system reference guide recommends a wait for 4 OSCIN/CLKIN
80 * cycles to ensure that the PLLC has switched to bypass mode. Delay of 1us
81 * ensures we are good for all > 4MHz OSCIN/CLKIN inputs. Typically the input
82 * is ~25MHz. Units are micro seconds.
84 #define PLL_BYPASS_TIME 1
86 /* From OMAP-L138 datasheet table 6-4. Units are micro seconds */
87 #define PLL_RESET_TIME 1
90 * From OMAP-L138 datasheet table 6-4; assuming prediv = 1, sqrt(pllm) = 4
91 * Units are micro seconds.
93 #define PLL_LOCK_TIME 20
96 * struct davinci_pll_clk - Main PLL clock (aka PLLOUT)
97 * @hw: clk_hw for the pll
98 * @base: Base memory address
99 * @pllm_min: The minimum allowable PLLM[PLLM] value
100 * @pllm_max: The maximum allowable PLLM[PLLM] value
101 * @pllm_mask: Bitmask for PLLM[PLLM] value
103 struct davinci_pll_clk
{
111 #define to_davinci_pll_clk(_hw) \
112 container_of((_hw), struct davinci_pll_clk, hw)
114 static unsigned long davinci_pll_recalc_rate(struct clk_hw
*hw
,
115 unsigned long parent_rate
)
117 struct davinci_pll_clk
*pll
= to_davinci_pll_clk(hw
);
118 unsigned long rate
= parent_rate
;
121 mult
= readl(pll
->base
+ PLLM
) & pll
->pllm_mask
;
127 static int davinci_pll_determine_rate(struct clk_hw
*hw
,
128 struct clk_rate_request
*req
)
130 struct davinci_pll_clk
*pll
= to_davinci_pll_clk(hw
);
131 struct clk_hw
*parent
= req
->best_parent_hw
;
132 unsigned long parent_rate
= req
->best_parent_rate
;
133 unsigned long rate
= req
->rate
;
134 unsigned long best_rate
, r
;
137 /* there is a limited range of valid outputs (see datasheet) */
138 if (rate
< req
->min_rate
)
141 rate
= min(rate
, req
->max_rate
);
142 mult
= rate
/ parent_rate
;
143 best_rate
= parent_rate
* mult
;
145 /* easy case when there is no PREDIV */
146 if (!(clk_hw_get_flags(hw
) & CLK_SET_RATE_PARENT
)) {
147 if (best_rate
< req
->min_rate
)
150 if (mult
< pll
->pllm_min
|| mult
> pll
->pllm_max
)
153 req
->rate
= best_rate
;
158 /* see if the PREDIV clock can help us */
161 for (mult
= pll
->pllm_min
; mult
<= pll
->pllm_max
; mult
++) {
162 parent_rate
= clk_hw_round_rate(parent
, rate
/ mult
);
163 r
= parent_rate
* mult
;
164 if (r
< req
->min_rate
)
166 if (r
> rate
|| r
> req
->max_rate
)
170 req
->rate
= best_rate
;
171 req
->best_parent_rate
= parent_rate
;
172 if (best_rate
== rate
)
180 static int davinci_pll_set_rate(struct clk_hw
*hw
, unsigned long rate
,
181 unsigned long parent_rate
)
183 struct davinci_pll_clk
*pll
= to_davinci_pll_clk(hw
);
186 mult
= rate
/ parent_rate
;
187 writel(mult
- 1, pll
->base
+ PLLM
);
192 #ifdef CONFIG_DEBUG_FS
193 static void davinci_pll_debug_init(struct clk_hw
*hw
, struct dentry
*dentry
);
195 #define davinci_pll_debug_init NULL
198 static const struct clk_ops davinci_pll_ops
= {
199 .recalc_rate
= davinci_pll_recalc_rate
,
200 .determine_rate
= davinci_pll_determine_rate
,
201 .set_rate
= davinci_pll_set_rate
,
202 .debug_init
= davinci_pll_debug_init
,
205 /* PLLM works differently on DM365 */
206 static unsigned long dm365_pll_recalc_rate(struct clk_hw
*hw
,
207 unsigned long parent_rate
)
209 struct davinci_pll_clk
*pll
= to_davinci_pll_clk(hw
);
210 unsigned long rate
= parent_rate
;
213 mult
= readl(pll
->base
+ PLLM
) & pll
->pllm_mask
;
219 static const struct clk_ops dm365_pll_ops
= {
220 .recalc_rate
= dm365_pll_recalc_rate
,
221 .debug_init
= davinci_pll_debug_init
,
225 * davinci_pll_div_register - common *DIV clock implementation
226 * @dev: The PLL platform device or NULL
227 * @name: the clock name
228 * @parent_name: the parent clock name
229 * @reg: the *DIV register
230 * @fixed: if true, the divider is a fixed value
231 * @flags: bitmap of CLK_* flags from clock-provider.h
233 static struct clk
*davinci_pll_div_register(struct device
*dev
,
235 const char *parent_name
,
237 bool fixed
, u32 flags
)
239 const char * const *parent_names
= parent_name
? &parent_name
: NULL
;
240 int num_parents
= parent_name
? 1 : 0;
241 const struct clk_ops
*divider_ops
= &clk_divider_ops
;
242 struct clk_gate
*gate
;
243 struct clk_divider
*divider
;
247 gate
= kzalloc(sizeof(*gate
), GFP_KERNEL
);
249 return ERR_PTR(-ENOMEM
);
252 gate
->bit_idx
= DIV_ENABLE_SHIFT
;
254 divider
= kzalloc(sizeof(*divider
), GFP_KERNEL
);
261 divider
->shift
= DIV_RATIO_SHIFT
;
262 divider
->width
= DIV_RATIO_WIDTH
;
265 divider
->flags
|= CLK_DIVIDER_READ_ONLY
;
266 divider_ops
= &clk_divider_ro_ops
;
269 clk
= clk_register_composite(dev
, name
, parent_names
, num_parents
,
270 NULL
, NULL
, ÷r
->hw
, divider_ops
,
271 &gate
->hw
, &clk_gate_ops
, flags
);
274 goto err_free_divider
;
287 struct davinci_pllen_clk
{
292 #define to_davinci_pllen_clk(_hw) \
293 container_of((_hw), struct davinci_pllen_clk, hw)
295 static const struct clk_ops davinci_pllen_ops
= {
296 /* this clocks just uses the clock notification feature */
300 * The PLL has to be switched into bypass mode while we are chaning the rate,
301 * so we do that on the PLLEN clock since it is the end of the line. This will
302 * switch to bypass before any of the parent clocks (PREDIV, PLL, POSTDIV) are
303 * changed and will switch back to the PLL after the changes have been made.
305 static int davinci_pllen_rate_change(struct notifier_block
*nb
,
306 unsigned long flags
, void *data
)
308 struct clk_notifier_data
*cnd
= data
;
309 struct clk_hw
*hw
= __clk_get_hw(cnd
->clk
);
310 struct davinci_pllen_clk
*pll
= to_davinci_pllen_clk(hw
);
313 ctrl
= readl(pll
->base
+ PLLCTL
);
315 if (flags
== PRE_RATE_CHANGE
) {
316 /* Switch the PLL to bypass mode */
317 ctrl
&= ~(PLLCTL_PLLENSRC
| PLLCTL_PLLEN
);
318 writel(ctrl
, pll
->base
+ PLLCTL
);
320 udelay(PLL_BYPASS_TIME
);
322 /* Reset and enable PLL */
323 ctrl
&= ~(PLLCTL_PLLRST
| PLLCTL_PLLDIS
);
324 writel(ctrl
, pll
->base
+ PLLCTL
);
326 udelay(PLL_RESET_TIME
);
328 /* Bring PLL out of reset */
329 ctrl
|= PLLCTL_PLLRST
;
330 writel(ctrl
, pll
->base
+ PLLCTL
);
332 udelay(PLL_LOCK_TIME
);
334 /* Remove PLL from bypass mode */
335 ctrl
|= PLLCTL_PLLEN
;
336 writel(ctrl
, pll
->base
+ PLLCTL
);
342 static struct notifier_block davinci_pllen_notifier
= {
343 .notifier_call
= davinci_pllen_rate_change
,
347 * davinci_pll_clk_register - Register a PLL clock
348 * @dev: The PLL platform device or NULL
349 * @info: The device-specific clock info
350 * @parent_name: The parent clock name
351 * @base: The PLL's memory region
352 * @cfgchip: CFGCHIP syscon regmap for info->unlock_reg or NULL
354 * This creates a series of clocks that represent the PLL.
356 * OSCIN > [PREDIV >] PLL > [POSTDIV >] PLLEN
358 * - OSCIN is the parent clock (on secondary PLL, may come from primary PLL)
359 * - PREDIV and POSTDIV are optional (depends on the PLL controller)
360 * - PLL is the PLL output (aka PLLOUT)
361 * - PLLEN is the bypass multiplexer
363 * Returns: The PLLOUT clock or a negative error code.
365 struct clk
*davinci_pll_clk_register(struct device
*dev
,
366 const struct davinci_pll_clk_info
*info
,
367 const char *parent_name
,
369 struct regmap
*cfgchip
)
371 char prediv_name
[MAX_NAME_SIZE
];
372 char pllout_name
[MAX_NAME_SIZE
];
373 char postdiv_name
[MAX_NAME_SIZE
];
374 char pllen_name
[MAX_NAME_SIZE
];
375 struct clk_init_data init
;
376 struct davinci_pll_clk
*pllout
;
377 struct davinci_pllen_clk
*pllen
;
378 struct clk
*oscin_clk
= NULL
;
379 struct clk
*prediv_clk
= NULL
;
380 struct clk
*pllout_clk
;
381 struct clk
*postdiv_clk
= NULL
;
382 struct clk
*pllen_clk
;
385 if (info
->flags
& PLL_HAS_CLKMODE
) {
387 * If a PLL has PLLCTL[CLKMODE], then it is the primary PLL.
388 * We register a clock named "oscin" that serves as the internal
389 * "input clock" domain shared by both PLLs (if there are 2)
390 * and will be the parent clock to the AUXCLK, SYSCLKBP and
391 * OBSCLK domains. NB: The various TRMs use "OSCIN" to mean
392 * a number of different things. In this driver we use it to
393 * mean the signal after the PLLCTL[CLKMODE] switch.
395 oscin_clk
= clk_register_fixed_factor(dev
, OSCIN_CLK_NAME
,
396 parent_name
, 0, 1, 1);
397 if (IS_ERR(oscin_clk
))
400 parent_name
= OSCIN_CLK_NAME
;
403 if (info
->flags
& PLL_HAS_PREDIV
) {
404 bool fixed
= info
->flags
& PLL_PREDIV_FIXED_DIV
;
407 snprintf(prediv_name
, MAX_NAME_SIZE
, "%s_prediv", info
->name
);
409 if (info
->flags
& PLL_PREDIV_ALWAYS_ENABLED
)
410 flags
|= CLK_IS_CRITICAL
;
412 /* Some? DM355 chips don't correctly report the PREDIV value */
413 if (info
->flags
& PLL_PREDIV_FIXED8
)
414 prediv_clk
= clk_register_fixed_factor(dev
, prediv_name
,
415 parent_name
, flags
, 1, 8);
417 prediv_clk
= davinci_pll_div_register(dev
, prediv_name
,
418 parent_name
, base
+ PREDIV
, fixed
, flags
);
419 if (IS_ERR(prediv_clk
)) {
420 ret
= PTR_ERR(prediv_clk
);
421 goto err_unregister_oscin
;
424 parent_name
= prediv_name
;
427 /* Unlock writing to PLL registers */
428 if (info
->unlock_reg
) {
429 if (IS_ERR_OR_NULL(cfgchip
))
430 dev_warn(dev
, "Failed to get CFGCHIP (%ld)\n",
433 regmap_write_bits(cfgchip
, info
->unlock_reg
,
434 info
->unlock_mask
, 0);
437 pllout
= kzalloc(sizeof(*pllout
), GFP_KERNEL
);
440 goto err_unregister_prediv
;
443 snprintf(pllout_name
, MAX_NAME_SIZE
, "%s_pllout", info
->name
);
445 init
.name
= pllout_name
;
446 if (info
->flags
& PLL_PLLM_2X
)
447 init
.ops
= &dm365_pll_ops
;
449 init
.ops
= &davinci_pll_ops
;
450 init
.parent_names
= &parent_name
;
451 init
.num_parents
= 1;
454 if (info
->flags
& PLL_HAS_PREDIV
)
455 init
.flags
|= CLK_SET_RATE_PARENT
;
457 pllout
->hw
.init
= &init
;
459 pllout
->pllm_mask
= info
->pllm_mask
;
460 pllout
->pllm_min
= info
->pllm_min
;
461 pllout
->pllm_max
= info
->pllm_max
;
463 pllout_clk
= clk_register(dev
, &pllout
->hw
);
464 if (IS_ERR(pllout_clk
)) {
465 ret
= PTR_ERR(pllout_clk
);
466 goto err_free_pllout
;
469 clk_hw_set_rate_range(&pllout
->hw
, info
->pllout_min_rate
,
470 info
->pllout_max_rate
);
472 parent_name
= pllout_name
;
474 if (info
->flags
& PLL_HAS_POSTDIV
) {
475 bool fixed
= info
->flags
& PLL_POSTDIV_FIXED_DIV
;
476 u32 flags
= CLK_SET_RATE_PARENT
;
478 snprintf(postdiv_name
, MAX_NAME_SIZE
, "%s_postdiv", info
->name
);
480 if (info
->flags
& PLL_POSTDIV_ALWAYS_ENABLED
)
481 flags
|= CLK_IS_CRITICAL
;
483 postdiv_clk
= davinci_pll_div_register(dev
, postdiv_name
,
484 parent_name
, base
+ POSTDIV
, fixed
, flags
);
485 if (IS_ERR(postdiv_clk
)) {
486 ret
= PTR_ERR(postdiv_clk
);
487 goto err_unregister_pllout
;
490 parent_name
= postdiv_name
;
493 pllen
= kzalloc(sizeof(*pllen
), GFP_KERNEL
);
496 goto err_unregister_postdiv
;
499 snprintf(pllen_name
, MAX_NAME_SIZE
, "%s_pllen", info
->name
);
501 init
.name
= pllen_name
;
502 init
.ops
= &davinci_pllen_ops
;
503 init
.parent_names
= &parent_name
;
504 init
.num_parents
= 1;
505 init
.flags
= CLK_SET_RATE_PARENT
;
507 pllen
->hw
.init
= &init
;
510 pllen_clk
= clk_register(dev
, &pllen
->hw
);
511 if (IS_ERR(pllen_clk
)) {
512 ret
= PTR_ERR(pllen_clk
);
516 clk_notifier_register(pllen_clk
, &davinci_pllen_notifier
);
522 err_unregister_postdiv
:
523 clk_unregister(postdiv_clk
);
524 err_unregister_pllout
:
525 clk_unregister(pllout_clk
);
528 err_unregister_prediv
:
529 clk_unregister(prediv_clk
);
530 err_unregister_oscin
:
531 clk_unregister(oscin_clk
);
537 * davinci_pll_auxclk_register - Register bypass clock (AUXCLK)
538 * @dev: The PLL platform device or NULL
539 * @name: The clock name
540 * @base: The PLL memory region
542 struct clk
*davinci_pll_auxclk_register(struct device
*dev
,
546 return clk_register_gate(dev
, name
, OSCIN_CLK_NAME
, 0, base
+ CKEN
,
547 CKEN_AUXEN_SHIFT
, 0, NULL
);
551 * davinci_pll_sysclkbp_clk_register - Register bypass divider clock (SYSCLKBP)
552 * @dev: The PLL platform device or NULL
553 * @name: The clock name
554 * @base: The PLL memory region
556 struct clk
*davinci_pll_sysclkbp_clk_register(struct device
*dev
,
560 return clk_register_divider(dev
, name
, OSCIN_CLK_NAME
, 0, base
+ BPDIV
,
561 DIV_RATIO_SHIFT
, DIV_RATIO_WIDTH
,
562 CLK_DIVIDER_READ_ONLY
, NULL
);
566 * davinci_pll_obsclk_register - Register oscillator divider clock (OBSCLK)
567 * @dev: The PLL platform device or NULL
568 * @info: The clock info
569 * @base: The PLL memory region
572 davinci_pll_obsclk_register(struct device
*dev
,
573 const struct davinci_pll_obsclk_info
*info
,
577 struct clk_gate
*gate
;
578 struct clk_divider
*divider
;
583 mux
= kzalloc(sizeof(*mux
), GFP_KERNEL
);
585 return ERR_PTR(-ENOMEM
);
587 mux
->reg
= base
+ OCSEL
;
588 mux
->table
= info
->table
;
589 mux
->mask
= info
->ocsrc_mask
;
591 gate
= kzalloc(sizeof(*gate
), GFP_KERNEL
);
597 gate
->reg
= base
+ CKEN
;
598 gate
->bit_idx
= CKEN_OBSCLK_SHIFT
;
600 divider
= kzalloc(sizeof(*divider
), GFP_KERNEL
);
606 divider
->reg
= base
+ OSCDIV
;
607 divider
->shift
= DIV_RATIO_SHIFT
;
608 divider
->width
= DIV_RATIO_WIDTH
;
610 /* make sure divider is enabled just in case bootloader disabled it */
611 oscdiv
= readl(base
+ OSCDIV
);
612 oscdiv
|= BIT(DIV_ENABLE_SHIFT
);
613 writel(oscdiv
, base
+ OSCDIV
);
615 clk
= clk_register_composite(dev
, info
->name
, info
->parent_names
,
617 &mux
->hw
, &clk_mux_ops
,
618 ÷r
->hw
, &clk_divider_ops
,
619 &gate
->hw
, &clk_gate_ops
, 0);
623 goto err_free_divider
;
638 /* The PLL SYSCLKn clocks have a mechanism for synchronizing rate changes. */
639 static int davinci_pll_sysclk_rate_change(struct notifier_block
*nb
,
640 unsigned long flags
, void *data
)
642 struct clk_notifier_data
*cnd
= data
;
643 struct clk_hw
*hw
= __clk_get_hw(clk_get_parent(cnd
->clk
));
644 struct davinci_pllen_clk
*pll
= to_davinci_pllen_clk(hw
);
648 case POST_RATE_CHANGE
:
649 /* apply the changes */
650 pllcmd
= readl(pll
->base
+ PLLCMD
);
651 pllcmd
|= PLLCMD_GOSET
;
652 writel(pllcmd
, pll
->base
+ PLLCMD
);
654 case PRE_RATE_CHANGE
:
655 /* Wait until for outstanding changes to take effect */
657 pllstat
= readl(pll
->base
+ PLLSTAT
);
658 } while (pllstat
& PLLSTAT_GOSTAT
);
665 static struct notifier_block davinci_pll_sysclk_notifier
= {
666 .notifier_call
= davinci_pll_sysclk_rate_change
,
670 * davinci_pll_sysclk_register - Register divider clocks (SYSCLKn)
671 * @dev: The PLL platform device or NULL
672 * @info: The clock info
673 * @base: The PLL memory region
676 davinci_pll_sysclk_register(struct device
*dev
,
677 const struct davinci_pll_sysclk_info
*info
,
680 const struct clk_ops
*divider_ops
= &clk_divider_ops
;
681 struct clk_gate
*gate
;
682 struct clk_divider
*divider
;
688 /* PLLDIVn registers are not entirely consecutive */
690 reg
= PLLDIV1
+ 4 * (info
->id
- 1);
692 reg
= PLLDIV4
+ 4 * (info
->id
- 4);
694 gate
= kzalloc(sizeof(*gate
), GFP_KERNEL
);
696 return ERR_PTR(-ENOMEM
);
698 gate
->reg
= base
+ reg
;
699 gate
->bit_idx
= DIV_ENABLE_SHIFT
;
701 divider
= kzalloc(sizeof(*divider
), GFP_KERNEL
);
707 divider
->reg
= base
+ reg
;
708 divider
->shift
= DIV_RATIO_SHIFT
;
709 divider
->width
= info
->ratio_width
;
712 if (info
->flags
& SYSCLK_FIXED_DIV
) {
713 divider
->flags
|= CLK_DIVIDER_READ_ONLY
;
714 divider_ops
= &clk_divider_ro_ops
;
717 /* Only the ARM clock can change the parent PLL rate */
718 if (info
->flags
& SYSCLK_ARM_RATE
)
719 flags
|= CLK_SET_RATE_PARENT
;
721 if (info
->flags
& SYSCLK_ALWAYS_ENABLED
)
722 flags
|= CLK_IS_CRITICAL
;
724 clk
= clk_register_composite(dev
, info
->name
, &info
->parent_name
, 1,
725 NULL
, NULL
, ÷r
->hw
, divider_ops
,
726 &gate
->hw
, &clk_gate_ops
, flags
);
729 goto err_free_divider
;
732 clk_notifier_register(clk
, &davinci_pll_sysclk_notifier
);
744 int of_davinci_pll_init(struct device
*dev
, struct device_node
*node
,
745 const struct davinci_pll_clk_info
*info
,
746 const struct davinci_pll_obsclk_info
*obsclk_info
,
747 const struct davinci_pll_sysclk_info
**div_info
,
750 struct regmap
*cfgchip
)
752 struct device_node
*child
;
753 const char *parent_name
;
756 if (info
->flags
& PLL_HAS_CLKMODE
)
757 parent_name
= of_clk_get_parent_name(node
, 0);
759 parent_name
= OSCIN_CLK_NAME
;
761 clk
= davinci_pll_clk_register(dev
, info
, parent_name
, base
, cfgchip
);
763 dev_err(dev
, "failed to register %s\n", info
->name
);
767 child
= of_get_child_by_name(node
, "pllout");
768 if (of_device_is_available(child
))
769 of_clk_add_provider(child
, of_clk_src_simple_get
, clk
);
772 child
= of_get_child_by_name(node
, "sysclk");
773 if (of_device_is_available(child
)) {
774 struct clk_onecell_data
*clk_data
;
776 int n_clks
= max_sysclk_id
+ 1;
779 clk_data
= kzalloc(sizeof(*clk_data
), GFP_KERNEL
);
785 clks
= kmalloc_array(n_clks
, sizeof(*clks
), GFP_KERNEL
);
792 clk_data
->clks
= clks
;
793 clk_data
->clk_num
= n_clks
;
795 for (i
= 0; i
< n_clks
; i
++)
796 clks
[i
] = ERR_PTR(-ENOENT
);
798 for (; *div_info
; div_info
++) {
799 clk
= davinci_pll_sysclk_register(dev
, *div_info
, base
);
801 dev_warn(dev
, "failed to register %s (%ld)\n",
802 (*div_info
)->name
, PTR_ERR(clk
));
804 clks
[(*div_info
)->id
] = clk
;
806 of_clk_add_provider(child
, of_clk_src_onecell_get
, clk_data
);
810 child
= of_get_child_by_name(node
, "auxclk");
811 if (of_device_is_available(child
)) {
812 char child_name
[MAX_NAME_SIZE
];
814 snprintf(child_name
, MAX_NAME_SIZE
, "%s_auxclk", info
->name
);
816 clk
= davinci_pll_auxclk_register(dev
, child_name
, base
);
818 dev_warn(dev
, "failed to register %s (%ld)\n",
819 child_name
, PTR_ERR(clk
));
821 of_clk_add_provider(child
, of_clk_src_simple_get
, clk
);
825 child
= of_get_child_by_name(node
, "obsclk");
826 if (of_device_is_available(child
)) {
828 clk
= davinci_pll_obsclk_register(dev
, obsclk_info
, base
);
830 clk
= ERR_PTR(-EINVAL
);
833 dev_warn(dev
, "failed to register obsclk (%ld)\n",
836 of_clk_add_provider(child
, of_clk_src_simple_get
, clk
);
843 static struct davinci_pll_platform_data
*davinci_pll_get_pdata(struct device
*dev
)
845 struct davinci_pll_platform_data
*pdata
= dev_get_platdata(dev
);
848 * Platform data is optional, so allocate a new struct if one was not
849 * provided. For device tree, this will always be the case.
852 pdata
= devm_kzalloc(dev
, sizeof(*pdata
), GFP_KERNEL
);
856 /* for device tree, we need to fill in the struct */
859 syscon_regmap_lookup_by_compatible("ti,da830-cfgchip");
864 /* needed in early boot for clocksource/clockevent */
865 #ifdef CONFIG_ARCH_DAVINCI_DA850
866 CLK_OF_DECLARE(da850_pll0
, "ti,da850-pll0", of_da850_pll0_init
);
869 static const struct of_device_id davinci_pll_of_match
[] = {
870 #ifdef CONFIG_ARCH_DAVINCI_DA850
871 { .compatible
= "ti,da850-pll1", .data
= of_da850_pll1_init
},
876 static const struct platform_device_id davinci_pll_id_table
[] = {
877 #ifdef CONFIG_ARCH_DAVINCI_DA830
878 { .name
= "da830-pll", .driver_data
= (kernel_ulong_t
)da830_pll_init
},
880 #ifdef CONFIG_ARCH_DAVINCI_DA850
881 { .name
= "da850-pll0", .driver_data
= (kernel_ulong_t
)da850_pll0_init
},
882 { .name
= "da850-pll1", .driver_data
= (kernel_ulong_t
)da850_pll1_init
},
887 typedef int (*davinci_pll_init
)(struct device
*dev
, void __iomem
*base
,
888 struct regmap
*cfgchip
);
890 static int davinci_pll_probe(struct platform_device
*pdev
)
892 struct device
*dev
= &pdev
->dev
;
893 struct davinci_pll_platform_data
*pdata
;
894 davinci_pll_init pll_init
= NULL
;
897 pll_init
= device_get_match_data(dev
);
898 if (!pll_init
&& pdev
->id_entry
)
899 pll_init
= (void *)pdev
->id_entry
->driver_data
;
902 dev_err(dev
, "unable to find driver data\n");
906 pdata
= davinci_pll_get_pdata(dev
);
908 dev_err(dev
, "missing platform data\n");
912 base
= devm_platform_ioremap_resource(pdev
, 0);
914 return PTR_ERR(base
);
916 return pll_init(dev
, base
, pdata
->cfgchip
);
919 static struct platform_driver davinci_pll_driver
= {
920 .probe
= davinci_pll_probe
,
922 .name
= "davinci-pll-clk",
923 .of_match_table
= davinci_pll_of_match
,
925 .id_table
= davinci_pll_id_table
,
928 static int __init
davinci_pll_driver_init(void)
930 return platform_driver_register(&davinci_pll_driver
);
933 /* has to be postcore_initcall because PSC devices depend on PLL parent clocks */
934 postcore_initcall(davinci_pll_driver_init
);
936 #ifdef CONFIG_DEBUG_FS
937 #include <linux/debugfs.h>
939 #define DEBUG_REG(n) \
945 static const struct debugfs_reg32 davinci_pll_regs
[] = {
949 DEBUG_REG(PLLSECCTL
),
973 static void davinci_pll_debug_init(struct clk_hw
*hw
, struct dentry
*dentry
)
975 struct davinci_pll_clk
*pll
= to_davinci_pll_clk(hw
);
976 struct debugfs_regset32
*regset
;
978 regset
= kzalloc(sizeof(*regset
), GFP_KERNEL
);
982 regset
->regs
= davinci_pll_regs
;
983 regset
->nregs
= ARRAY_SIZE(davinci_pll_regs
);
984 regset
->base
= pll
->base
;
986 debugfs_create_regset32("registers", 0400, dentry
, regset
);