2 * linux/arch/arm/mach-omap2/clock.h
4 * Copyright (C) 2005-2009 Texas Instruments, Inc.
5 * Copyright (C) 2004-2011 Nokia Corporation
8 * Richard Woodruff <r-woodruff2@ti.com>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
16 #ifndef __ARCH_ARM_MACH_OMAP2_CLOCK_H
17 #define __ARCH_ARM_MACH_OMAP2_CLOCK_H
19 #include <linux/kernel.h>
20 #include <linux/list.h>
22 #include <linux/clkdev.h>
29 #define CLK(dev, con, ck, cp) \
39 /* Platform flags for the clkdev-OMAP integration code */
40 #define CK_242X (1 << 0)
41 #define CK_243X (1 << 1) /* 243x, 253x */
42 #define CK_3430ES1 (1 << 2) /* 34xxES1 only */
43 #define CK_3430ES2PLUS (1 << 3) /* 34xxES2, ES3, non-Sitara 35xx only */
44 #define CK_AM35XX (1 << 4) /* Sitara AM35xx */
45 #define CK_36XX (1 << 5) /* 36xx/37xx-specific clocks */
46 #define CK_443X (1 << 6)
47 #define CK_TI816X (1 << 7)
48 #define CK_446X (1 << 8)
49 #define CK_AM33XX (1 << 9) /* AM33xx specific clocks */
52 #define CK_34XX (CK_3430ES1 | CK_3430ES2PLUS)
53 #define CK_3XXX (CK_34XX | CK_AM35XX | CK_36XX)
55 #ifdef CONFIG_COMMON_CLK
56 #include <linux/clk-provider.h>
59 #define to_clk_hw_omap(_hw) container_of(_hw, struct clk_hw_omap, hw)
67 /* Temporary, needed during the common clock framework conversion */
68 #define __clk_get_name(clk) (clk->name)
69 #define __clk_get_parent(clk) (clk->parent)
70 #define __clk_get_rate(clk) (clk->rate)
73 * struct clkops - some clock function pointers
74 * @enable: fn ptr that enables the current clock in hardware
75 * @disable: fn ptr that enables the current clock in hardware
76 * @find_idlest: function returning the IDLEST register for the clock's IP blk
77 * @find_companion: function returning the "companion" clk reg for the clock
78 * @allow_idle: fn ptr that enables autoidle for the current clock in hardware
79 * @deny_idle: fn ptr that disables autoidle for the current clock in hardware
81 * A "companion" clk is an accompanying clock to the one being queried
82 * that must be enabled for the IP module connected to the clock to
83 * become accessible by the hardware. Neither @find_idlest nor
84 * @find_companion should be needed; that information is IP
85 * block-specific; the hwmod code has been created to handle this, but
86 * until hwmod data is ready and drivers have been converted to use PM
87 * runtime calls in place of clk_enable()/clk_disable(), @find_idlest and
88 * @find_companion must, unfortunately, remain.
91 int (*enable
)(struct clk
*);
92 void (*disable
)(struct clk
*);
93 void (*find_idlest
)(struct clk
*, void __iomem
**,
95 void (*find_companion
)(struct clk
*, void __iomem
**,
97 void (*allow_idle
)(struct clk
*);
98 void (*deny_idle
)(struct clk
*);
102 /* struct clksel_rate.flags possibilities */
103 #define RATE_IN_242X (1 << 0)
104 #define RATE_IN_243X (1 << 1)
105 #define RATE_IN_3430ES1 (1 << 2) /* 3430ES1 rates only */
106 #define RATE_IN_3430ES2PLUS (1 << 3) /* 3430 ES >= 2 rates only */
107 #define RATE_IN_36XX (1 << 4)
108 #define RATE_IN_4430 (1 << 5)
109 #define RATE_IN_TI816X (1 << 6)
110 #define RATE_IN_4460 (1 << 7)
111 #define RATE_IN_AM33XX (1 << 8)
112 #define RATE_IN_TI814X (1 << 9)
114 #define RATE_IN_24XX (RATE_IN_242X | RATE_IN_243X)
115 #define RATE_IN_34XX (RATE_IN_3430ES1 | RATE_IN_3430ES2PLUS)
116 #define RATE_IN_3XXX (RATE_IN_34XX | RATE_IN_36XX)
117 #define RATE_IN_44XX (RATE_IN_4430 | RATE_IN_4460)
119 /* RATE_IN_3430ES2PLUS_36XX includes 34xx/35xx with ES >=2, and all 36xx/37xx */
120 #define RATE_IN_3430ES2PLUS_36XX (RATE_IN_3430ES2PLUS | RATE_IN_36XX)
124 * struct clksel_rate - register bitfield values corresponding to clk divisors
125 * @val: register bitfield value (shifted to bit 0)
126 * @div: clock divisor corresponding to @val
127 * @flags: (see "struct clksel_rate.flags possibilities" above)
129 * @val should match the value of a read from struct clk.clksel_reg
130 * AND'ed with struct clk.clksel_mask, shifted right to bit 0.
132 * @div is the divisor that should be applied to the parent clock's rate
133 * to produce the current clock's rate.
142 * struct clksel - available parent clocks, and a pointer to their divisors
143 * @parent: struct clk * to a possible parent clock
144 * @rates: available divisors for this parent clock
146 * A struct clksel is always associated with one or more struct clks
147 * and one or more struct clksel_rates.
151 const struct clksel_rate
*rates
;
155 * struct dpll_data - DPLL registers and integration data
156 * @mult_div1_reg: register containing the DPLL M and N bitfields
157 * @mult_mask: mask of the DPLL M bitfield in @mult_div1_reg
158 * @div1_mask: mask of the DPLL N bitfield in @mult_div1_reg
159 * @clk_bypass: struct clk pointer to the clock's bypass clock input
160 * @clk_ref: struct clk pointer to the clock's reference clock input
161 * @control_reg: register containing the DPLL mode bitfield
162 * @enable_mask: mask of the DPLL mode bitfield in @control_reg
163 * @last_rounded_rate: cache of the last rate result of omap2_dpll_round_rate()
164 * @last_rounded_m: cache of the last M result of omap2_dpll_round_rate()
165 * @max_multiplier: maximum valid non-bypass multiplier value (actual)
166 * @last_rounded_n: cache of the last N result of omap2_dpll_round_rate()
167 * @min_divider: minimum valid non-bypass divider value (actual)
168 * @max_divider: maximum valid non-bypass divider value (actual)
169 * @modes: possible values of @enable_mask
170 * @autoidle_reg: register containing the DPLL autoidle mode bitfield
171 * @idlest_reg: register containing the DPLL idle status bitfield
172 * @autoidle_mask: mask of the DPLL autoidle mode bitfield in @autoidle_reg
173 * @freqsel_mask: mask of the DPLL jitter correction bitfield in @control_reg
174 * @idlest_mask: mask of the DPLL idle status bitfield in @idlest_reg
175 * @auto_recal_bit: bitshift of the driftguard enable bit in @control_reg
176 * @recal_en_bit: bitshift of the PRM_IRQENABLE_* bit for recalibration IRQs
177 * @recal_st_bit: bitshift of the PRM_IRQSTATUS_* bit for recalibration IRQs
178 * @flags: DPLL type/features (see below)
180 * Possible values for @flags:
181 * DPLL_J_TYPE: "J-type DPLL" (only some 36xx, 4xxx DPLLs)
183 * @freqsel_mask is only used on the OMAP34xx family and AM35xx.
185 * XXX Some DPLLs have multiple bypass inputs, so it's not technically
186 * correct to only have one @clk_bypass pointer.
188 * XXX The runtime-variable fields (@last_rounded_rate, @last_rounded_m,
189 * @last_rounded_n) should be separated from the runtime-fixed fields
190 * and placed into a different structure, so that the runtime-fixed data
191 * can be placed into read-only space.
194 void __iomem
*mult_div1_reg
;
197 struct clk
*clk_bypass
;
199 void __iomem
*control_reg
;
201 unsigned long last_rounded_rate
;
208 void __iomem
*autoidle_reg
;
209 void __iomem
*idlest_reg
;
222 * struct clk.flags possibilities
224 * XXX document the rest of the clock flags here
226 * CLOCK_CLKOUTX2: (OMAP4 only) DPLL CLKOUT and CLKOUTX2 GATE_CTRL
227 * bits share the same register. This flag allows the
228 * omap4_dpllmx*() code to determine which GATE_CTRL bit field
229 * should be used. This is a temporary solution - a better approach
230 * would be to associate clock type-specific data with the clock,
231 * similar to the struct dpll_data approach.
233 #define ENABLE_REG_32BIT (1 << 0) /* Use 32-bit access */
234 #define CLOCK_IDLE_CONTROL (1 << 1)
235 #define CLOCK_NO_IDLE_PARENT (1 << 2)
236 #define ENABLE_ON_INIT (1 << 3) /* Enable upon framework init */
237 #define INVERT_ENABLE (1 << 4) /* 0 enables, 1 disables */
238 #define CLOCK_CLKOUTX2 (1 << 5)
240 #ifdef CONFIG_COMMON_CLK
242 * struct clk_hw_omap - OMAP struct clk
243 * @node: list_head connecting this clock into the full clock list
244 * @enable_reg: register to write to enable the clock (see @enable_bit)
245 * @enable_bit: bitshift to write to enable/disable the clock (see @enable_reg)
246 * @flags: see "struct clk.flags possibilities" above
247 * @clksel_reg: for clksel clks, register va containing src/divisor select
248 * @clksel_mask: bitmask in @clksel_reg for the src/divisor selector
249 * @clksel: for clksel clks, pointer to struct clksel for this clock
250 * @dpll_data: for DPLLs, pointer to struct dpll_data for this clock
251 * @clkdm_name: clockdomain name that this clock is contained in
252 * @clkdm: pointer to struct clockdomain, resolved from @clkdm_name at runtime
253 * @rate_offset: bitshift for rate selection bitfield (OMAP1 only)
254 * @src_offset: bitshift for source selection bitfield (OMAP1 only)
256 * XXX @rate_offset, @src_offset should probably be removed and OMAP1
257 * clock code converted to use clksel.
261 struct clk_hw_omap_ops
;
265 struct list_head node
;
266 unsigned long fixed_rate
;
268 void __iomem
*enable_reg
;
271 void __iomem
*clksel_reg
;
273 const struct clksel
*clksel
;
274 struct dpll_data
*dpll_data
;
275 const char *clkdm_name
;
276 struct clockdomain
*clkdm
;
277 const struct clk_hw_omap_ops
*ops
;
280 struct clk_hw_omap_ops
{
281 void (*find_idlest
)(struct clk_hw_omap
*oclk
,
282 void __iomem
**idlest_reg
,
283 u8
*idlest_bit
, u8
*idlest_val
);
284 void (*find_companion
)(struct clk_hw_omap
*oclk
,
285 void __iomem
**other_reg
,
287 void (*allow_idle
)(struct clk_hw_omap
*oclk
);
288 void (*deny_idle
)(struct clk_hw_omap
*oclk
);
291 unsigned long omap_fixed_divisor_recalc(struct clk_hw
*hw
,
292 unsigned long parent_rate
);
295 * struct clk - OMAP struct clk
296 * @node: list_head connecting this clock into the full clock list
297 * @ops: struct clkops * for this clock
298 * @name: the name of the clock in the hardware (used in hwmod data and debug)
299 * @parent: pointer to this clock's parent struct clk
300 * @children: list_head connecting to the child clks' @sibling list_heads
301 * @sibling: list_head connecting this clk to its parent clk's @children
302 * @rate: current clock rate
303 * @enable_reg: register to write to enable the clock (see @enable_bit)
304 * @recalc: fn ptr that returns the clock's current rate
305 * @set_rate: fn ptr that can change the clock's current rate
306 * @round_rate: fn ptr that can round the clock's current rate
307 * @init: fn ptr to do clock-specific initialization
308 * @enable_bit: bitshift to write to enable/disable the clock (see @enable_reg)
309 * @usecount: number of users that have requested this clock to be enabled
310 * @fixed_div: when > 0, this clock's rate is its parent's rate / @fixed_div
311 * @flags: see "struct clk.flags possibilities" above
312 * @clksel_reg: for clksel clks, register va containing src/divisor select
313 * @clksel_mask: bitmask in @clksel_reg for the src/divisor selector
314 * @clksel: for clksel clks, pointer to struct clksel for this clock
315 * @dpll_data: for DPLLs, pointer to struct dpll_data for this clock
316 * @clkdm_name: clockdomain name that this clock is contained in
317 * @clkdm: pointer to struct clockdomain, resolved from @clkdm_name at runtime
318 * @rate_offset: bitshift for rate selection bitfield (OMAP1 only)
319 * @src_offset: bitshift for source selection bitfield (OMAP1 only)
321 * XXX @rate_offset, @src_offset should probably be removed and OMAP1
322 * clock code converted to use clksel.
324 * XXX @usecount is poorly named. It should be "enable_count" or
325 * something similar. "users" in the description refers to kernel
326 * code (core code or drivers) that have called clk_enable() and not
327 * yet called clk_disable(); the usecount of parent clocks is also
328 * incremented by the clock code when clk_enable() is called on child
329 * clocks and decremented by the clock code when clk_disable() is
330 * called on child clocks.
332 * XXX @clkdm, @usecount, @children, @sibling should be marked for
335 * @children and @sibling are used to optimize parent-to-child clock
336 * tree traversals. (child-to-parent traversals use @parent.)
338 * XXX The notion of the clock's current rate probably needs to be
339 * separated from the clock's target rate.
342 struct list_head node
;
343 const struct clkops
*ops
;
346 struct list_head children
;
347 struct list_head sibling
; /* node for children */
349 void __iomem
*enable_reg
;
350 unsigned long (*recalc
)(struct clk
*);
351 int (*set_rate
)(struct clk
*, unsigned long);
352 long (*round_rate
)(struct clk
*, unsigned long);
353 void (*init
)(struct clk
*);
358 void __iomem
*clksel_reg
;
360 const struct clksel
*clksel
;
361 struct dpll_data
*dpll_data
;
362 const char *clkdm_name
;
363 struct clockdomain
*clkdm
;
364 #if defined(CONFIG_PM_DEBUG) && defined(CONFIG_DEBUG_FS)
365 struct dentry
*dent
; /* For visible tree hierarchy */
369 struct clk_functions
{
370 int (*clk_enable
)(struct clk
*clk
);
371 void (*clk_disable
)(struct clk
*clk
);
372 long (*clk_round_rate
)(struct clk
*clk
, unsigned long rate
);
373 int (*clk_set_rate
)(struct clk
*clk
, unsigned long rate
);
374 int (*clk_set_parent
)(struct clk
*clk
, struct clk
*parent
);
375 void (*clk_allow_idle
)(struct clk
*clk
);
376 void (*clk_deny_idle
)(struct clk
*clk
);
377 void (*clk_disable_unused
)(struct clk
*clk
);
382 extern int clk_init(struct clk_functions
*custom_clocks
);
383 extern void clk_preinit(struct clk
*clk
);
384 extern int clk_register(struct clk
*clk
);
385 extern void clk_reparent(struct clk
*child
, struct clk
*parent
);
386 extern void clk_unregister(struct clk
*clk
);
387 extern void propagate_rate(struct clk
*clk
);
388 extern void recalculate_root_clocks(void);
389 extern unsigned long followparent_recalc(struct clk
*clk
);
390 extern void clk_enable_init_clocks(void);
391 unsigned long omap_fixed_divisor_recalc(struct clk
*clk
);
392 extern struct clk
*omap_clk_get_by_name(const char *name
);
393 extern int omap_clk_enable_autoidle_all(void);
394 extern int omap_clk_disable_autoidle_all(void);
396 extern const struct clkops clkops_null
;
398 extern struct clk dummy_ck
;
401 /* CM_CLKSEL2_PLL.CORE_CLK_SRC bits (2XXX) */
402 #define CORE_CLK_SRC_32K 0x0
403 #define CORE_CLK_SRC_DPLL 0x1
404 #define CORE_CLK_SRC_DPLL_X2 0x2
406 /* OMAP2xxx CM_CLKEN_PLL.EN_DPLL bits - for omap2_get_dpll_rate() */
407 #define OMAP2XXX_EN_DPLL_LPBYPASS 0x1
408 #define OMAP2XXX_EN_DPLL_FRBYPASS 0x2
409 #define OMAP2XXX_EN_DPLL_LOCKED 0x3
411 /* OMAP3xxx CM_CLKEN_PLL*.EN_*_DPLL bits - for omap2_get_dpll_rate() */
412 #define OMAP3XXX_EN_DPLL_LPBYPASS 0x5
413 #define OMAP3XXX_EN_DPLL_FRBYPASS 0x6
414 #define OMAP3XXX_EN_DPLL_LOCKED 0x7
416 /* OMAP4xxx CM_CLKMODE_DPLL*.EN_*_DPLL bits - for omap2_get_dpll_rate() */
417 #define OMAP4XXX_EN_DPLL_MNBYPASS 0x4
418 #define OMAP4XXX_EN_DPLL_LPBYPASS 0x5
419 #define OMAP4XXX_EN_DPLL_FRBYPASS 0x6
420 #define OMAP4XXX_EN_DPLL_LOCKED 0x7
422 /* CM_CLKEN_PLL*.EN* bit values - not all are available for every DPLL */
423 #define DPLL_LOW_POWER_STOP 0x1
424 #define DPLL_LOW_POWER_BYPASS 0x5
425 #define DPLL_LOCKED 0x7
427 /* DPLL Type and DCO Selection Flags */
428 #define DPLL_J_TYPE 0x1
430 int omap2_clk_enable(struct clk
*clk
);
431 void omap2_clk_disable(struct clk
*clk
);
432 long omap2_clk_round_rate(struct clk
*clk
, unsigned long rate
);
433 int omap2_clk_set_rate(struct clk
*clk
, unsigned long rate
);
434 int omap2_clk_set_parent(struct clk
*clk
, struct clk
*new_parent
);
435 long omap2_dpll_round_rate(struct clk
*clk
, unsigned long target_rate
);
436 unsigned long omap3_dpll_recalc(struct clk
*clk
);
437 unsigned long omap3_clkoutx2_recalc(struct clk
*clk
);
438 void omap3_dpll_allow_idle(struct clk
*clk
);
439 void omap3_dpll_deny_idle(struct clk
*clk
);
440 u32
omap3_dpll_autoidle_read(struct clk
*clk
);
441 int omap3_noncore_dpll_set_rate(struct clk
*clk
, unsigned long rate
);
442 int omap3_noncore_dpll_enable(struct clk
*clk
);
443 void omap3_noncore_dpll_disable(struct clk
*clk
);
444 int omap4_dpllmx_gatectrl_read(struct clk
*clk
);
445 void omap4_dpllmx_allow_gatectrl(struct clk
*clk
);
446 void omap4_dpllmx_deny_gatectrl(struct clk
*clk
);
447 long omap4_dpll_regm4xen_round_rate(struct clk
*clk
, unsigned long target_rate
);
448 unsigned long omap4_dpll_regm4xen_recalc(struct clk
*clk
);
450 #ifdef CONFIG_OMAP_RESET_CLOCKS
451 void omap2_clk_disable_unused(struct clk
*clk
);
453 #define omap2_clk_disable_unused NULL
456 void omap2_init_clk_clkdm(struct clk
*clk
);
457 void __init
omap2_clk_disable_clkdm_control(void);
459 /* clkt_clksel.c public functions */
460 u32
omap2_clksel_round_rate_div(struct clk
*clk
, unsigned long target_rate
,
462 void omap2_init_clksel_parent(struct clk
*clk
);
463 unsigned long omap2_clksel_recalc(struct clk
*clk
);
464 long omap2_clksel_round_rate(struct clk
*clk
, unsigned long target_rate
);
465 int omap2_clksel_set_rate(struct clk
*clk
, unsigned long rate
);
466 int omap2_clksel_set_parent(struct clk
*clk
, struct clk
*new_parent
);
468 /* clkt_iclk.c public functions */
469 extern void omap2_clkt_iclk_allow_idle(struct clk
*clk
);
470 extern void omap2_clkt_iclk_deny_idle(struct clk
*clk
);
472 u32
omap2_get_dpll_rate(struct clk
*clk
);
473 void omap2_init_dpll_parent(struct clk
*clk
);
475 int omap2_dflt_clk_enable(struct clk
*clk
);
476 void omap2_dflt_clk_disable(struct clk
*clk
);
477 void omap2_clk_dflt_find_companion(struct clk
*clk
, void __iomem
**other_reg
,
479 void omap2_clk_dflt_find_idlest(struct clk
*clk
, void __iomem
**idlest_reg
,
480 u8
*idlest_bit
, u8
*idlest_val
);
481 int omap2_clk_switch_mpurate_at_boot(const char *mpurate_ck_name
);
482 void omap2_clk_print_new_rates(const char *hfclkin_ck_name
,
483 const char *core_ck_name
,
484 const char *mpu_ck_name
);
488 extern const struct clkops clkops_omap2_dflt_wait
;
489 extern const struct clkops clkops_dummy
;
490 extern const struct clkops clkops_omap2_dflt
;
492 extern struct clk_functions omap2_clk_functions
;
494 extern const struct clksel_rate gpt_32k_rates
[];
495 extern const struct clksel_rate gpt_sys_rates
[];
496 extern const struct clksel_rate gfx_l3_rates
[];
497 extern const struct clksel_rate dsp_ick_rates
[];
499 extern const struct clkops clkops_omap2_iclk_dflt_wait
;
500 extern const struct clkops clkops_omap2_iclk_dflt
;
501 extern const struct clkops clkops_omap2_iclk_idle_only
;
502 extern const struct clkops clkops_omap2_mdmclk_dflt_wait
;
503 extern const struct clkops clkops_omap2xxx_dpll_ops
;
504 extern const struct clkops clkops_omap3_noncore_dpll_ops
;
505 extern const struct clkops clkops_omap3_core_dpll_ops
;
506 extern const struct clkops clkops_omap4_dpllmx_ops
;
508 /* clksel_rate blocks shared between OMAP44xx and AM33xx */
509 extern const struct clksel_rate div_1_0_rates
[];
510 extern const struct clksel_rate div_1_1_rates
[];
511 extern const struct clksel_rate div_1_2_rates
[];
512 extern const struct clksel_rate div_1_3_rates
[];
513 extern const struct clksel_rate div_1_4_rates
[];
514 extern const struct clksel_rate div31_1to31_rates
[];
516 /* clocks shared between various OMAP SoCs */
517 extern struct clk virt_19200000_ck
;
518 extern struct clk virt_26000000_ck
;
520 extern int am33xx_clk_init(void);
522 #endif /* CONFIG_COMMON_CLK */