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