ARM: OMAP4: Add function table for non-M4X dplls
[deliverable/linux.git] / arch / arm / mach-omap2 / clock.h
CommitLineData
543d9378
PW
1/*
2 * linux/arch/arm/mach-omap2/clock.h
3 *
d8a94458 4 * Copyright (C) 2005-2009 Texas Instruments, Inc.
530e544f 5 * Copyright (C) 2004-2011 Nokia Corporation
543d9378 6 *
a16e9703
TL
7 * Contacts:
8 * Richard Woodruff <r-woodruff2@ti.com>
543d9378
PW
9 * Paul Walmsley
10 *
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.
14 */
15
16#ifndef __ARCH_ARM_MACH_OMAP2_CLOCK_H
17#define __ARCH_ARM_MACH_OMAP2_CLOCK_H
18
12706c54 19#include <linux/kernel.h>
a135eaae
PW
20#include <linux/list.h>
21
e10dd62f 22#include <linux/clkdev.h>
f9ae32a7 23#include <linux/clk-provider.h>
e10dd62f
PW
24
25struct omap_clk {
26 u16 cpu;
27 struct clk_lookup lk;
28};
29
30#define CLK(dev, con, ck, cp) \
31 { \
32 .cpu = cp, \
33 .lk = { \
34 .dev_id = dev, \
35 .con_id = con, \
36 .clk = ck, \
37 }, \
38 }
39
40/* Platform flags for the clkdev-OMAP integration code */
41#define CK_242X (1 << 0)
42#define CK_243X (1 << 1) /* 243x, 253x */
43#define CK_3430ES1 (1 << 2) /* 34xxES1 only */
44#define CK_3430ES2PLUS (1 << 3) /* 34xxES2, ES3, non-Sitara 35xx only */
45#define CK_AM35XX (1 << 4) /* Sitara AM35xx */
46#define CK_36XX (1 << 5) /* 36xx/37xx-specific clocks */
47#define CK_443X (1 << 6)
48#define CK_TI816X (1 << 7)
49#define CK_446X (1 << 8)
50#define CK_AM33XX (1 << 9) /* AM33xx specific clocks */
51
52
53#define CK_34XX (CK_3430ES1 | CK_3430ES2PLUS)
54#define CK_3XXX (CK_34XX | CK_AM35XX | CK_36XX)
55
b5a2366c
RN
56struct clockdomain;
57#define to_clk_hw_omap(_hw) container_of(_hw, struct clk_hw_omap, hw)
58
8c725dcd
PW
59#define DEFINE_STRUCT_CLK(_name, _parent_array_name, _clkops_name) \
60 static struct clk _name = { \
61 .name = #_name, \
62 .hw = &_name##_hw.hw, \
63 .parent_names = _parent_array_name, \
64 .num_parents = ARRAY_SIZE(_parent_array_name), \
65 .ops = &_clkops_name, \
66 };
67
68#define DEFINE_STRUCT_CLK_HW_OMAP(_name, _clkdm_name) \
69 static struct clk_hw_omap _name##_hw = { \
70 .hw = { \
71 .clk = &_name, \
72 }, \
73 .clkdm_name = _clkdm_name, \
74 };
75
76#define DEFINE_CLK_OMAP_MUX(_name, _clkdm_name, _clksel, \
77 _clksel_reg, _clksel_mask, \
78 _parent_names, _ops) \
79 static struct clk _name; \
80 static struct clk_hw_omap _name##_hw = { \
81 .hw = { \
82 .clk = &_name, \
83 }, \
84 .clksel = _clksel, \
85 .clksel_reg = _clksel_reg, \
86 .clksel_mask = _clksel_mask, \
87 .clkdm_name = _clkdm_name, \
88 }; \
89 DEFINE_STRUCT_CLK(_name, _parent_names, _ops);
90
91#define DEFINE_CLK_OMAP_MUX_GATE(_name, _clkdm_name, _clksel, \
92 _clksel_reg, _clksel_mask, \
93 _enable_reg, _enable_bit, \
94 _hwops, _parent_names, _ops) \
95 static struct clk _name; \
96 static struct clk_hw_omap _name##_hw = { \
97 .hw = { \
98 .clk = &_name, \
99 }, \
100 .ops = _hwops, \
101 .enable_reg = _enable_reg, \
102 .enable_bit = _enable_bit, \
103 .clksel = _clksel, \
104 .clksel_reg = _clksel_reg, \
105 .clksel_mask = _clksel_mask, \
106 .clkdm_name = _clkdm_name, \
107 }; \
108 DEFINE_STRUCT_CLK(_name, _parent_names, _ops);
109
110#define DEFINE_CLK_OMAP_HSDIVIDER(_name, _parent_name, \
111 _parent_ptr, _flags, \
112 _clksel_reg, _clksel_mask) \
113 static const struct clksel _name##_div[] = { \
114 { \
115 .parent = _parent_ptr, \
116 .rates = div31_1to31_rates \
117 }, \
118 { .parent = NULL }, \
119 }; \
120 static struct clk _name; \
121 static const char *_name##_parent_names[] = { \
122 _parent_name, \
123 }; \
124 static struct clk_hw_omap _name##_hw = { \
125 .hw = { \
126 .clk = &_name, \
127 }, \
128 .clksel = _name##_div, \
129 .clksel_reg = _clksel_reg, \
130 .clksel_mask = _clksel_mask, \
131 .ops = &clkhwops_omap4_dpllmx, \
132 }; \
133 DEFINE_STRUCT_CLK(_name, _name##_parent_names, omap_hsdivider_ops);
134
a135eaae
PW
135/* struct clksel_rate.flags possibilities */
136#define RATE_IN_242X (1 << 0)
137#define RATE_IN_243X (1 << 1)
138#define RATE_IN_3430ES1 (1 << 2) /* 3430ES1 rates only */
139#define RATE_IN_3430ES2PLUS (1 << 3) /* 3430 ES >= 2 rates only */
140#define RATE_IN_36XX (1 << 4)
141#define RATE_IN_4430 (1 << 5)
142#define RATE_IN_TI816X (1 << 6)
143#define RATE_IN_4460 (1 << 7)
144#define RATE_IN_AM33XX (1 << 8)
145#define RATE_IN_TI814X (1 << 9)
146
147#define RATE_IN_24XX (RATE_IN_242X | RATE_IN_243X)
148#define RATE_IN_34XX (RATE_IN_3430ES1 | RATE_IN_3430ES2PLUS)
149#define RATE_IN_3XXX (RATE_IN_34XX | RATE_IN_36XX)
150#define RATE_IN_44XX (RATE_IN_4430 | RATE_IN_4460)
151
152/* RATE_IN_3430ES2PLUS_36XX includes 34xx/35xx with ES >=2, and all 36xx/37xx */
153#define RATE_IN_3430ES2PLUS_36XX (RATE_IN_3430ES2PLUS | RATE_IN_36XX)
154
155
156/**
157 * struct clksel_rate - register bitfield values corresponding to clk divisors
158 * @val: register bitfield value (shifted to bit 0)
159 * @div: clock divisor corresponding to @val
160 * @flags: (see "struct clksel_rate.flags possibilities" above)
161 *
162 * @val should match the value of a read from struct clk.clksel_reg
163 * AND'ed with struct clk.clksel_mask, shifted right to bit 0.
164 *
165 * @div is the divisor that should be applied to the parent clock's rate
166 * to produce the current clock's rate.
167 */
168struct clksel_rate {
169 u32 val;
170 u8 div;
171 u16 flags;
172};
173
174/**
175 * struct clksel - available parent clocks, and a pointer to their divisors
176 * @parent: struct clk * to a possible parent clock
177 * @rates: available divisors for this parent clock
178 *
179 * A struct clksel is always associated with one or more struct clks
180 * and one or more struct clksel_rates.
181 */
182struct clksel {
183 struct clk *parent;
184 const struct clksel_rate *rates;
185};
186
187/**
188 * struct dpll_data - DPLL registers and integration data
189 * @mult_div1_reg: register containing the DPLL M and N bitfields
190 * @mult_mask: mask of the DPLL M bitfield in @mult_div1_reg
191 * @div1_mask: mask of the DPLL N bitfield in @mult_div1_reg
192 * @clk_bypass: struct clk pointer to the clock's bypass clock input
193 * @clk_ref: struct clk pointer to the clock's reference clock input
194 * @control_reg: register containing the DPLL mode bitfield
195 * @enable_mask: mask of the DPLL mode bitfield in @control_reg
196 * @last_rounded_rate: cache of the last rate result of omap2_dpll_round_rate()
197 * @last_rounded_m: cache of the last M result of omap2_dpll_round_rate()
198 * @max_multiplier: maximum valid non-bypass multiplier value (actual)
199 * @last_rounded_n: cache of the last N result of omap2_dpll_round_rate()
200 * @min_divider: minimum valid non-bypass divider value (actual)
201 * @max_divider: maximum valid non-bypass divider value (actual)
202 * @modes: possible values of @enable_mask
203 * @autoidle_reg: register containing the DPLL autoidle mode bitfield
204 * @idlest_reg: register containing the DPLL idle status bitfield
205 * @autoidle_mask: mask of the DPLL autoidle mode bitfield in @autoidle_reg
206 * @freqsel_mask: mask of the DPLL jitter correction bitfield in @control_reg
207 * @idlest_mask: mask of the DPLL idle status bitfield in @idlest_reg
208 * @auto_recal_bit: bitshift of the driftguard enable bit in @control_reg
209 * @recal_en_bit: bitshift of the PRM_IRQENABLE_* bit for recalibration IRQs
210 * @recal_st_bit: bitshift of the PRM_IRQSTATUS_* bit for recalibration IRQs
211 * @flags: DPLL type/features (see below)
212 *
213 * Possible values for @flags:
214 * DPLL_J_TYPE: "J-type DPLL" (only some 36xx, 4xxx DPLLs)
215 *
216 * @freqsel_mask is only used on the OMAP34xx family and AM35xx.
217 *
218 * XXX Some DPLLs have multiple bypass inputs, so it's not technically
219 * correct to only have one @clk_bypass pointer.
220 *
221 * XXX The runtime-variable fields (@last_rounded_rate, @last_rounded_m,
222 * @last_rounded_n) should be separated from the runtime-fixed fields
223 * and placed into a different structure, so that the runtime-fixed data
224 * can be placed into read-only space.
225 */
226struct dpll_data {
227 void __iomem *mult_div1_reg;
228 u32 mult_mask;
229 u32 div1_mask;
230 struct clk *clk_bypass;
231 struct clk *clk_ref;
232 void __iomem *control_reg;
233 u32 enable_mask;
234 unsigned long last_rounded_rate;
235 u16 last_rounded_m;
236 u16 max_multiplier;
237 u8 last_rounded_n;
238 u8 min_divider;
239 u16 max_divider;
240 u8 modes;
241 void __iomem *autoidle_reg;
242 void __iomem *idlest_reg;
243 u32 autoidle_mask;
244 u32 freqsel_mask;
245 u32 idlest_mask;
246 u32 dco_mask;
247 u32 sddiv_mask;
248 u8 auto_recal_bit;
249 u8 recal_en_bit;
250 u8 recal_st_bit;
251 u8 flags;
252};
253
254/*
255 * struct clk.flags possibilities
256 *
257 * XXX document the rest of the clock flags here
258 *
259 * CLOCK_CLKOUTX2: (OMAP4 only) DPLL CLKOUT and CLKOUTX2 GATE_CTRL
260 * bits share the same register. This flag allows the
261 * omap4_dpllmx*() code to determine which GATE_CTRL bit field
262 * should be used. This is a temporary solution - a better approach
263 * would be to associate clock type-specific data with the clock,
264 * similar to the struct dpll_data approach.
265 */
266#define ENABLE_REG_32BIT (1 << 0) /* Use 32-bit access */
267#define CLOCK_IDLE_CONTROL (1 << 1)
268#define CLOCK_NO_IDLE_PARENT (1 << 2)
269#define ENABLE_ON_INIT (1 << 3) /* Enable upon framework init */
270#define INVERT_ENABLE (1 << 4) /* 0 enables, 1 disables */
271#define CLOCK_CLKOUTX2 (1 << 5)
272
b5a2366c
RN
273/**
274 * struct clk_hw_omap - OMAP struct clk
275 * @node: list_head connecting this clock into the full clock list
276 * @enable_reg: register to write to enable the clock (see @enable_bit)
277 * @enable_bit: bitshift to write to enable/disable the clock (see @enable_reg)
278 * @flags: see "struct clk.flags possibilities" above
279 * @clksel_reg: for clksel clks, register va containing src/divisor select
280 * @clksel_mask: bitmask in @clksel_reg for the src/divisor selector
281 * @clksel: for clksel clks, pointer to struct clksel for this clock
282 * @dpll_data: for DPLLs, pointer to struct dpll_data for this clock
283 * @clkdm_name: clockdomain name that this clock is contained in
284 * @clkdm: pointer to struct clockdomain, resolved from @clkdm_name at runtime
285 * @rate_offset: bitshift for rate selection bitfield (OMAP1 only)
286 * @src_offset: bitshift for source selection bitfield (OMAP1 only)
287 *
288 * XXX @rate_offset, @src_offset should probably be removed and OMAP1
289 * clock code converted to use clksel.
290 *
291 */
292
293struct clk_hw_omap_ops;
294
295struct clk_hw_omap {
296 struct clk_hw hw;
297 struct list_head node;
298 unsigned long fixed_rate;
299 u8 fixed_div;
300 void __iomem *enable_reg;
301 u8 enable_bit;
302 u8 flags;
303 void __iomem *clksel_reg;
304 u32 clksel_mask;
305 const struct clksel *clksel;
306 struct dpll_data *dpll_data;
307 const char *clkdm_name;
308 struct clockdomain *clkdm;
309 const struct clk_hw_omap_ops *ops;
310};
311
312struct clk_hw_omap_ops {
313 void (*find_idlest)(struct clk_hw_omap *oclk,
314 void __iomem **idlest_reg,
315 u8 *idlest_bit, u8 *idlest_val);
316 void (*find_companion)(struct clk_hw_omap *oclk,
317 void __iomem **other_reg,
318 u8 *other_bit);
319 void (*allow_idle)(struct clk_hw_omap *oclk);
320 void (*deny_idle)(struct clk_hw_omap *oclk);
321};
322
323unsigned long omap_fixed_divisor_recalc(struct clk_hw *hw,
324 unsigned long parent_rate);
543d9378 325
c0bf3132
RK
326/* CM_CLKSEL2_PLL.CORE_CLK_SRC bits (2XXX) */
327#define CORE_CLK_SRC_32K 0x0
328#define CORE_CLK_SRC_DPLL 0x1
329#define CORE_CLK_SRC_DPLL_X2 0x2
330
331/* OMAP2xxx CM_CLKEN_PLL.EN_DPLL bits - for omap2_get_dpll_rate() */
332#define OMAP2XXX_EN_DPLL_LPBYPASS 0x1
333#define OMAP2XXX_EN_DPLL_FRBYPASS 0x2
334#define OMAP2XXX_EN_DPLL_LOCKED 0x3
335
336/* OMAP3xxx CM_CLKEN_PLL*.EN_*_DPLL bits - for omap2_get_dpll_rate() */
337#define OMAP3XXX_EN_DPLL_LPBYPASS 0x5
338#define OMAP3XXX_EN_DPLL_FRBYPASS 0x6
339#define OMAP3XXX_EN_DPLL_LOCKED 0x7
340
16975a79
RN
341/* OMAP4xxx CM_CLKMODE_DPLL*.EN_*_DPLL bits - for omap2_get_dpll_rate() */
342#define OMAP4XXX_EN_DPLL_MNBYPASS 0x4
343#define OMAP4XXX_EN_DPLL_LPBYPASS 0x5
344#define OMAP4XXX_EN_DPLL_FRBYPASS 0x6
345#define OMAP4XXX_EN_DPLL_LOCKED 0x7
346
a1391d27
RN
347/* CM_CLKEN_PLL*.EN* bit values - not all are available for every DPLL */
348#define DPLL_LOW_POWER_STOP 0x1
349#define DPLL_LOW_POWER_BYPASS 0x5
350#define DPLL_LOCKED 0x7
351
358965d7
RW
352/* DPLL Type and DCO Selection Flags */
353#define DPLL_J_TYPE 0x1
358965d7 354
32cc0021
MT
355long omap2_dpll_round_rate(struct clk_hw *hw, unsigned long target_rate,
356 unsigned long *parent_rate);
357unsigned long omap3_dpll_recalc(struct clk_hw *hw, unsigned long parent_rate);
358int omap3_noncore_dpll_enable(struct clk_hw *hw);
359void omap3_noncore_dpll_disable(struct clk_hw *hw);
360int omap3_noncore_dpll_set_rate(struct clk_hw *hw, unsigned long rate,
361 unsigned long parent_rate);
362u32 omap3_dpll_autoidle_read(struct clk_hw_omap *clk);
363void omap3_dpll_allow_idle(struct clk_hw_omap *clk);
364void omap3_dpll_deny_idle(struct clk_hw_omap *clk);
365unsigned long omap3_clkoutx2_recalc(struct clk_hw *hw,
366 unsigned long parent_rate);
367int omap4_dpllmx_gatectrl_read(struct clk_hw_omap *clk);
368void omap4_dpllmx_allow_gatectrl(struct clk_hw_omap *clk);
369void omap4_dpllmx_deny_gatectrl(struct clk_hw_omap *clk);
370unsigned long omap4_dpll_regm4xen_recalc(struct clk_hw *hw,
371 unsigned long parent_rate);
372long omap4_dpll_regm4xen_round_rate(struct clk_hw *hw,
373 unsigned long target_rate,
374 unsigned long *parent_rate);
543d9378 375
32cc0021 376void omap2_init_clk_clkdm(struct clk_hw *clk);
12706c54 377void __init omap2_clk_disable_clkdm_control(void);
435699db
PW
378
379/* clkt_clksel.c public functions */
32cc0021
MT
380u32 omap2_clksel_round_rate_div(struct clk_hw_omap *clk,
381 unsigned long target_rate,
382 u32 *new_div);
383u8 omap2_clksel_find_parent_index(struct clk_hw *hw);
384unsigned long omap2_clksel_recalc(struct clk_hw *hw, unsigned long parent_rate);
385long omap2_clksel_round_rate(struct clk_hw *hw, unsigned long target_rate,
386 unsigned long *parent_rate);
387int omap2_clksel_set_rate(struct clk_hw *hw, unsigned long rate,
388 unsigned long parent_rate);
389int omap2_clksel_set_parent(struct clk_hw *hw, u8 field_val);
435699db 390
530e544f 391/* clkt_iclk.c public functions */
b4777a21
RN
392extern void omap2_clkt_iclk_allow_idle(struct clk_hw_omap *clk);
393extern void omap2_clkt_iclk_deny_idle(struct clk_hw_omap *clk);
530e544f 394
32cc0021
MT
395u8 omap2_init_dpll_parent(struct clk_hw *hw);
396unsigned long omap2_get_dpll_rate(struct clk_hw_omap *clk);
435699db 397
32cc0021
MT
398int omap2_dflt_clk_enable(struct clk_hw *hw);
399void omap2_dflt_clk_disable(struct clk_hw *hw);
400int omap2_dflt_clk_is_enabled(struct clk_hw *hw);
401void omap2_clk_dflt_find_companion(struct clk_hw_omap *clk,
402 void __iomem **other_reg,
403 u8 *other_bit);
404void omap2_clk_dflt_find_idlest(struct clk_hw_omap *clk,
405 void __iomem **idlest_reg,
406 u8 *idlest_bit, u8 *idlest_val);
23fb8ba3
RN
407void omap2_init_clk_hw_omap_clocks(struct clk *clk);
408int omap2_clk_enable_autoidle_all(void);
409int omap2_clk_disable_autoidle_all(void);
8577413c 410void omap2_clk_enable_init_clocks(const char **clk_names, u8 num_clocks);
4d30e82c
PW
411int omap2_clk_switch_mpurate_at_boot(const char *mpurate_ck_name);
412void omap2_clk_print_new_rates(const char *hfclkin_ck_name,
413 const char *core_ck_name,
414 const char *mpu_ck_name);
543d9378 415
99541195 416extern u16 cpu_mask;
d8a94458 417
b36ee724 418extern const struct clkops clkops_omap2_dflt_wait;
7c43d547 419extern const struct clkops clkops_dummy;
bc51da4e 420extern const struct clkops clkops_omap2_dflt;
b36ee724 421
82e9bd58
PW
422extern struct clk_functions omap2_clk_functions;
423
d8a94458
PW
424extern const struct clksel_rate gpt_32k_rates[];
425extern const struct clksel_rate gpt_sys_rates[];
426extern const struct clksel_rate gfx_l3_rates[];
22411396 427extern const struct clksel_rate dsp_ick_rates[];
cb26867e 428extern struct clk dummy_ck;
543d9378 429
32cc0021
MT
430extern const struct clk_hw_omap_ops clkhwops_omap3_dpll;
431extern const struct clk_hw_omap_ops clkhwops_iclk_wait;
432extern const struct clk_hw_omap_ops clkhwops_wait;
433extern const struct clk_hw_omap_ops clkhwops_omap4_dpllmx;
b4777a21
RN
434extern const struct clk_hw_omap_ops clkhwops_iclk;
435extern const struct clk_hw_omap_ops clkhwops_omap3430es2_ssi_wait;
436extern const struct clk_hw_omap_ops clkhwops_omap3430es2_iclk_ssi_wait;
437extern const struct clk_hw_omap_ops clkhwops_omap3430es2_dss_usbhost_wait;
438extern const struct clk_hw_omap_ops clkhwops_omap3430es2_iclk_dss_usbhost_wait;
439extern const struct clk_hw_omap_ops clkhwops_omap3430es2_iclk_hsotgusb_wait;
440extern const struct clk_hw_omap_ops clkhwops_omap3430es2_hsotgusb_wait;
441extern const struct clk_hw_omap_ops clkhwops_am35xx_ipss_module_wait;
442extern const struct clk_hw_omap_ops clkhwops_am35xx_ipss_wait;
443extern const struct clk_hw_omap_ops clkhwops_apll54;
444extern const struct clk_hw_omap_ops clkhwops_apll96;
445extern const struct clk_hw_omap_ops clkhwops_omap2xxx_dpll;
446extern const struct clk_hw_omap_ops clkhwops_omap2430_i2chs_wait;
657ebfad 447
571efa0d
PW
448/* clksel_rate blocks shared between OMAP44xx and AM33xx */
449extern const struct clksel_rate div_1_0_rates[];
cb26867e 450extern const struct clksel_rate div3_1to4_rates[];
571efa0d
PW
451extern const struct clksel_rate div_1_1_rates[];
452extern const struct clksel_rate div_1_2_rates[];
453extern const struct clksel_rate div_1_3_rates[];
454extern const struct clksel_rate div_1_4_rates[];
455extern const struct clksel_rate div31_1to31_rates[];
456
e30384ab
VH
457extern int am33xx_clk_init(void);
458
32cc0021
MT
459extern int omap2_clkops_enable_clkdm(struct clk_hw *hw);
460extern void omap2_clkops_disable_clkdm(struct clk_hw *hw);
32cc0021 461
543d9378 462#endif
This page took 0.291184 seconds and 5 git commands to generate.