4 #include <linux/types.h>
5 #include <linux/kernel.h>
13 if (sizeof(x) == sizeof(long)) { \
15 ret = (__x < 0) ? -__x : __x; \
18 ret = (__x < 0) ? -__x : __x; \
25 #define do_div(a, b) (a /= b)
32 #define EVCLKFAULT 14 /* Bad address */
35 #define EVCLKTIMEOUT 110
37 #define MASK_OF_TYPE 0x0F000000
38 #define MASK_OF_SUBTYPE 0x00FF0000
39 #define MASK_OF_ID 0x0000FFFF
40 #define FIXED_RATE_TYPE 0x01000000
41 #define FIXED_FACTOR_TYPE 0x02000000
42 #define PLL_TYPE 0x03000000
43 #define MUX_TYPE 0x04000000
44 #define USER_MUX_TYPE 0x04010000
45 #define CONST_MUX_TYPE 0x04020000
46 #define DIV_TYPE 0x05000000
47 #define CONST_DIV_TYPE 0x05020000
48 #define GATE_TYPE 0x06000000
49 #define GATE_ROOT_TYPE 0x06010000
50 #define QCH_TYPE 0x07000000
51 #define SFR_BLOCK_TYPE 0x08000000
52 #define SFR_TYPE 0x09000000
53 #define SFR_ACCESS_TYPE 0x0A000000
54 #define VCLK_TYPE 0x0B000000
55 #define COMMON_VCLK_TYPE 0x0B010000
56 #define DFS_VCLK_TYPE 0x0B020000
57 #define GATE_VCLK_TYPE 0x0B030000
58 #define ACPM_VCLK_TYPE 0x0B040000
59 #define OPTION_TYPE 0x0C000000
60 #define CLKOUT_TYPE 0x0D000000
61 #define INVALID_CLK_ID MASK_OF_ID
62 #define EMPTY_CLK_ID MASK_OF_ID
63 #define EMPTY_CAL_ID MASK_OF_ID
66 * struct vclk_lut - Virtual clock Look-Up-Table
67 * @rate: virtual clock rate
68 * @params: clks setting parameters, number of params is num_clks
76 * struct vclk_seq - Virtual clock sequence
77 * @idx: index of struct vclk_clks
78 * @opt: option : TRANS_HIGH, TRANS_LOW, TRANS_FORCE
86 * struct vclk_switch - switching lut info
87 * @switch_rate: switch_rate
88 * @mux_value: mux value about source
89 * @div_value: div value about mout
93 unsigned int mux_value
;
94 unsigned int div_value
;
98 * struct vclk_switch - Virtual clock switching PLL info
99 * @switch_mux: switching MUX id
100 * @src_mux: switching PLL source MUX id
101 * @src_div: switching PLL source Divider id
102 * @lut: switch PLL Look-Up-Table pointer
105 unsigned int switch_mux
;
106 unsigned int src_mux
;
107 unsigned int src_div
;
108 unsigned int src_gate
;
109 unsigned int src_umux
;
110 struct switch_lut
*lut
;
111 unsigned int num_switches
;
115 * struct vclk - Virtual clock
118 * @vrate: vclk virtual clock frequency
119 * @lut: Look-Up-Table pointer
120 * @seq: clock setting sequnce pointer
121 * @clk_list: clock list pointer
122 * @num_rates: number of lut rates
123 * @num_clks: number of clks and seq
129 struct vclk_lut
*lut
;
131 struct vclk_seq
*seq
;
132 unsigned int num_rates
;
133 unsigned int num_list
;
134 unsigned int max_freq
;
135 unsigned int min_freq
;
136 unsigned int boot_freq
;
137 unsigned int resume_freq
;
139 struct vclk_switch
*switch_info
;
140 struct vclk_trans_ops
*ops
;
141 #ifdef CONFIG_DEBUG_FS
142 struct dentry
*dentry
;
188 #define IS_FIXED_RATE(_id) ((_id & MASK_OF_TYPE) == FIXED_RATE_TYPE)
189 #define IS_FIXED_FACTOR(_id) ((_id & MASK_OF_TYPE) == FIXED_FACTOR_TYPE)
190 #define IS_PLL(_id) ((_id & MASK_OF_TYPE) == PLL_TYPE)
191 #define IS_MUX(_id) ((_id & MASK_OF_TYPE) == MUX_TYPE)
192 #define IS_USER_MUX(_id) ((_id & (MASK_OF_TYPE | MASK_OF_SUBTYPE)) == USER_MUX_TYPE)
193 #define IS_CONST_MUX(_id) ((_id & (MASK_OF_TYPE | MASK_OF_SUBTYPE)) == CONST_MUX_TYPE)
194 #define IS_DIV(_id) ((_id & MASK_OF_TYPE) == DIV_TYPE)
195 #define IS_CONST_DIV(_id) ((_id & MASK_OF_TYPE | MASK_OF_SUBTYPE) == CONST_DIV_TYPE)
196 #define IS_GATE(_id) ((_id & MASK_OF_TYPE) == GATE_TYPE)
197 #define IS_QCH(_id) ((_id & MASK_OF_TYPE) == QCH_TYPE)
198 #define IS_OPTION(_id) ((_id & MASK_OF_TYPE) == OPTION_TYPE)
200 #define IS_VCLK(_id) ((_id & MASK_OF_TYPE) == VCLK_TYPE)
201 #define IS_DFS_VCLK(_id) ((_id & (MASK_OF_TYPE | MASK_OF_SUBTYPE)) == DFS_VCLK_TYPE)
202 #define IS_COMMON_VCLK(_id) ((_id & (MASK_OF_TYPE | MASK_OF_SUBTYPE)) == COMMON_VCLK_TYPE)
203 #define IS_GATE_VCLK(_id) ((_id & (MASK_OF_TYPE | MASK_OF_SUBTYPE)) == GATE_VCLK_TYPE)
204 #define IS_ACPM_VCLK(_id) ((_id & (MASK_OF_TYPE | MASK_OF_SUBTYPE)) == ACPM_VCLK_TYPE)
206 #define GET_TYPE(_id) (_id & MASK_OF_TYPE)
207 #define GET_IDX(_id) (_id & MASK_OF_ID)
209 * struct sfr_block - SFR block
210 * @id: id of sfr_block
211 * @name: name of sfr_block
212 * @pa: physical address
213 * @va: virtual address
214 * @size: sfr block size, 2 ^ n
228 * @offset: offset from block
229 * @block: index of block
239 * struct sfr_access - SFR field
241 * @name: sfr field name
242 * @shift: shift value of field
243 * @width: width value of field
255 * struct cmucal_clk - CMUCAL Clock node
256 * @id: id of clock node
257 * @paddr: physical addr of clock node
258 * @pid: parent id of clock node
259 * @name: name of clock node
260 * @offset_idx: index of offset
261 * @status_idx: index of status
262 * @enable_idx: index of enable
263 * @offset: offset address
264 * @status: status address, or lock_offset of pll
265 * @enable: enable address
266 * @shift: shift of offset
267 * @width: width of offset
268 * @s_shift: shift of status
269 * @s_width: width of status
270 * @e_shift: shift of enable
271 * @e_width: width of enable
279 void __iomem
*offset
;
281 unsigned long offset_idx
;
284 void __iomem
*enable
;
285 void __iomem
*pll_con0
;
286 unsigned long enable_idx
;
289 void __iomem
*status
;
290 void __iomem
*pll_con1
;
291 unsigned long status_idx
;
295 unsigned char s_shift
;
296 unsigned char s_width
;
297 unsigned char e_shift
;
298 unsigned char e_width
;
303 * @p,m,s,k min/max value
304 * @fref, fvco, fout min/max value
307 unsigned int pdiv_min
;
308 unsigned int pdiv_max
;
309 unsigned int mdiv_min
;
310 unsigned int mdiv_max
;
311 unsigned int sdiv_min
;
312 unsigned int sdiv_max
;
313 signed short kdiv_min
;
314 signed short kdiv_max
;
315 unsigned long long fref_min
;
316 unsigned long long fref_max
;
317 unsigned long long fvco_min
;
318 unsigned long long fvco_max
;
319 unsigned long long fout_min
;
320 unsigned long long fout_max
;
321 unsigned int lock_time
;
322 unsigned int flock_time
;
326 * struct cmucal_pll_table
328 * @pdiv, @mdiv, @sdiv, @kdiv: for rate
330 struct cmucal_pll_table
{
340 * @clk: cmucal_rate structure
342 * @rate_table: rate table
343 * @rate_count: number of rate_table
344 * @lock_time: integer PLL locktime
345 * @flock_time: fractional PLL locktime
348 struct cmucal_clk clk
;
351 struct cmucal_pll_table
*rate_table
;
352 unsigned int rate_count
;
353 unsigned int lock_time
;
354 unsigned int flock_time
;
355 unsigned int p_idx
, m_idx
, s_idx
, k_idx
;
356 unsigned char p_shift
, m_shift
, s_shift
, k_shift
;
357 unsigned char p_width
, m_width
, s_width
, k_width
;
360 struct cmucal_clk_fixed_rate
{
361 struct cmucal_clk clk
;
362 unsigned int fixed_rate
;
365 struct cmucal_clk_fixed_factor
{
366 struct cmucal_clk clk
;
367 unsigned short ratio
;
371 struct cmucal_clk clk
;
373 unsigned char num_parents
;
377 struct cmucal_clk clk
;
381 struct cmucal_clk clk
;
385 struct cmucal_clk clk
;
387 void __iomem
*ignore
;
388 unsigned long ignore_idx
;
390 unsigned char ig_shift
;
391 unsigned char ig_width
;
394 struct cmucal_option
{
395 struct cmucal_clk clk
;
398 struct cmucal_clkout
{
399 struct cmucal_clk clk
;
404 #define CMUCAL_VCLK(_id, _lut, _list, _seq, _switch) \
405 [_id & MASK_OF_ID] = { \
411 .num_rates = (sizeof(_lut) / sizeof((_lut)[0])), \
412 .num_list = (sizeof(_list) / sizeof((_list)[0])), \
413 .switch_info = _switch, \
417 #define CMUCAL_VCLK_NULL(_id, _lut, _list, _seq, _switch) \
418 [_id & MASK_OF_ID] = { \
425 .num_list = (sizeof(_list) / sizeof((_list)[0])), \
426 .switch_info = _switch, \
430 #define CMUCAL_ACPM_VCLK(_id, _lut, _list, _seq, _switch, _margin_id) \
431 [_id & MASK_OF_ID] = { \
439 .switch_info = _switch, \
441 .margin_id = _margin_id, \
444 #define SFR_BLOCK(_id, _pa, _size) \
445 [_id & MASK_OF_ID] = { \
451 #define SFR(_id, _offset, _block) \
452 [_id & MASK_OF_ID] = { \
458 #define SFR_ACCESS(_id, _shift, _width, _sfr) \
459 [_id & MASK_OF_ID] = { \
466 #define CLK_PLL(_typ, _id, _pid, _lock, _enable, _stable, \
468 _rtable, _time, _ftime) \
469 [_id & MASK_OF_ID] = { \
471 .clk.pid = EMPTY_CLK_ID, \
473 .clk.offset_idx = _lock, \
474 .clk.enable_idx = _enable, \
475 .clk.status_idx = _stable, \
482 .rate_table = _rtable, \
483 .rate_count = (sizeof(_rtable) / sizeof((_rtable)[0])), \
484 .lock_time = _time, \
485 .flock_time = _ftime, \
488 #define CLK_MUX(_id, _pids, _o, _so, _eo) \
489 [_id & MASK_OF_ID] = { \
492 .clk.offset_idx = _o, \
493 .clk.status_idx = _so, \
494 .clk.enable_idx = _eo, \
496 .num_parents = (sizeof(_pids) / sizeof((_pids)[0])), \
499 #define CLK_MUX_NULL(_id, _pids, _o, _so, _eo) \
500 [_id & MASK_OF_ID] = { \
503 .clk.offset_idx = _o, \
504 .clk.status_idx = _so, \
505 .clk.enable_idx = _eo, \
510 #define CLK_DIV(_id, _pid, _o, _so, _eo) \
511 [_id & MASK_OF_ID] = { \
515 .clk.offset_idx = _o, \
516 .clk.status_idx = _so, \
517 .clk.enable_idx = _eo, \
520 #define CLK_GATE(_id, _pid, _o, _so, _eo) \
521 [_id & MASK_OF_ID] = { \
525 .clk.offset_idx = _o, \
526 .clk.status_idx = _so, \
527 .clk.enable_idx = _eo, \
529 #ifdef CONFIG_CMUCAL_QCH_IGNORE_SUPPORT
530 #define CLK_QCH(_id, _o, _so, _eo, _ig) \
531 [_id & MASK_OF_ID] = { \
534 .clk.pid = EMPTY_CLK_ID, \
535 .clk.offset_idx = _o, \
536 .clk.status_idx = _so, \
537 .clk.enable_idx = _eo, \
541 #define CLK_QCH(_id, _o, _so, _eo) \
542 [_id & MASK_OF_ID] = { \
545 .clk.pid = EMPTY_CLK_ID, \
546 .clk.offset_idx = _o, \
547 .clk.status_idx = _so, \
548 .clk.enable_idx = _eo, \
551 #define CLK_OPTION(_id, _o, _eo) \
552 [_id & MASK_OF_ID] = { \
555 .clk.pid = EMPTY_CLK_ID, \
556 .clk.offset_idx = _o, \
557 .clk.enable_idx = _eo, \
560 #define FIXEDRATE(_id, _frate, _eo) \
561 [_id & MASK_OF_ID] = { \
563 .clk.pid = EMPTY_CLK_ID, \
565 .clk.enable_idx = _eo, \
566 .fixed_rate = _frate, \
569 #define FIXEDFACTOR(_id, _pid, _ratio, _eo) \
570 [_id & MASK_OF_ID] = { \
574 .clk.enable_idx = _eo, \
578 #define CLKOUT(_id, _o, _s, _w, _sel, _es, _ew, _en) \
579 [_id & MASK_OF_ID] = { \
582 .clk.offset_idx = _o, \
585 .clk.e_shift = _es, \
586 .clk.e_width = _ew, \
591 #define PLL_RATE_MPS(_rate, _m, _p, _s) \
600 #define PLL_RATE_MPSK(_rate, _m, _p, _s, _k) \
609 #define to_fixed_rate_clk(_clk) container_of(_clk, struct cmucal_clk_fixed_rate, clk)
610 #define to_fixed_factor_clk(_clk) container_of(_clk, struct cmucal_clk_fixed_factor, clk)
611 #define to_pll_clk(_clk) container_of(_clk, struct cmucal_pll, clk)
612 #define to_mux_clk(_clk) container_of(_clk, struct cmucal_mux, clk)
613 #define to_div_clk(_clk) container_of(_clk, struct cmucal_div, clk)
614 #define to_gate_clk(_clk) container_of(_clk, struct cmucal_gate, clk)
615 #define to_clkout(_clk) container_of(_clk, struct cmucal_clkout, clk)
616 #define to_qch(_clk) container_of(_clk, struct cmucal_qch, clk)
618 extern unsigned int cmucal_get_list_size(unsigned int type
);
619 extern void *cmucal_get_node(unsigned int id
);
620 extern void *cmucal_get_sfr_node(unsigned int id
);
621 extern unsigned int cmucal_get_id(char *name
);
622 extern unsigned int cmucal_get_id_by_addr(unsigned int addr
);
623 extern void (*cal_data_init
)(void);