1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17#ifndef __TEGRA_CLK_H
18#define __TEGRA_CLK_H
19
20#include <linux/clk-provider.h>
21#include <linux/clkdev.h>
22
23
24
25
26
27
28
29
30struct tegra_clk_sync_source {
31 struct clk_hw hw;
32 unsigned long rate;
33 unsigned long max_rate;
34};
35
36#define to_clk_sync_source(_hw) \
37 container_of(_hw, struct tegra_clk_sync_source, hw)
38
39extern const struct clk_ops tegra_clk_sync_source_ops;
40struct clk *tegra_clk_register_sync_source(const char *name,
41 unsigned long fixed_rate, unsigned long max_rate);
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65struct tegra_clk_frac_div {
66 struct clk_hw hw;
67 void __iomem *reg;
68 u8 flags;
69 u8 shift;
70 u8 width;
71 u8 frac_width;
72 spinlock_t *lock;
73};
74
75#define to_clk_frac_div(_hw) container_of(_hw, struct tegra_clk_frac_div, hw)
76
77#define TEGRA_DIVIDER_ROUND_UP BIT(0)
78#define TEGRA_DIVIDER_FIXED BIT(1)
79#define TEGRA_DIVIDER_INT BIT(2)
80#define TEGRA_DIVIDER_UART BIT(3)
81
82extern const struct clk_ops tegra_clk_frac_div_ops;
83struct clk *tegra_clk_register_divider(const char *name,
84 const char *parent_name, void __iomem *reg,
85 unsigned long flags, u8 clk_divider_flags, u8 shift, u8 width,
86 u8 frac_width, spinlock_t *lock);
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110struct tegra_clk_pll_freq_table {
111 unsigned long input_rate;
112 unsigned long output_rate;
113 u16 n;
114 u16 m;
115 u8 p;
116 u8 cpcon;
117};
118
119
120
121
122
123
124
125struct pdiv_map {
126 u8 pdiv;
127 u8 hw_val;
128};
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146struct tegra_clk_pll_params {
147 unsigned long input_min;
148 unsigned long input_max;
149 unsigned long cf_min;
150 unsigned long cf_max;
151 unsigned long vco_min;
152 unsigned long vco_max;
153
154 u32 base_reg;
155 u32 misc_reg;
156 u32 lock_reg;
157 u32 lock_mask;
158 u32 lock_enable_bit_idx;
159 u32 iddq_reg;
160 u32 iddq_bit_idx;
161 u32 aux_reg;
162 u32 dyn_ramp_reg;
163 u32 ext_misc_reg[3];
164 int stepa_shift;
165 int stepb_shift;
166 int lock_delay;
167 int max_p;
168 struct pdiv_map *pdiv_tohw;
169};
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210struct tegra_clk_pll {
211 struct clk_hw hw;
212 void __iomem *clk_base;
213 void __iomem *pmc;
214 u32 flags;
215 unsigned long fixed_rate;
216 spinlock_t *lock;
217 u8 divn_shift;
218 u8 divn_width;
219 u8 divm_shift;
220 u8 divm_width;
221 u8 divp_shift;
222 u8 divp_width;
223 struct tegra_clk_pll_freq_table *freq_table;
224 struct tegra_clk_pll_params *params;
225};
226
227#define to_clk_pll(_hw) container_of(_hw, struct tegra_clk_pll, hw)
228
229#define TEGRA_PLL_USE_LOCK BIT(0)
230#define TEGRA_PLL_HAS_CPCON BIT(1)
231#define TEGRA_PLL_SET_LFCON BIT(2)
232#define TEGRA_PLL_SET_DCCON BIT(3)
233#define TEGRA_PLLU BIT(4)
234#define TEGRA_PLLM BIT(5)
235#define TEGRA_PLL_FIXED BIT(6)
236#define TEGRA_PLLE_CONFIGURE BIT(7)
237#define TEGRA_PLL_LOCK_MISC BIT(8)
238#define TEGRA_PLL_BYPASS BIT(9)
239#define TEGRA_PLL_HAS_LOCK_ENABLE BIT(10)
240
241extern const struct clk_ops tegra_clk_pll_ops;
242extern const struct clk_ops tegra_clk_plle_ops;
243struct clk *tegra_clk_register_pll(const char *name, const char *parent_name,
244 void __iomem *clk_base, void __iomem *pmc,
245 unsigned long flags, unsigned long fixed_rate,
246 struct tegra_clk_pll_params *pll_params, u32 pll_flags,
247 struct tegra_clk_pll_freq_table *freq_table, spinlock_t *lock);
248
249struct clk *tegra_clk_register_plle(const char *name, const char *parent_name,
250 void __iomem *clk_base, void __iomem *pmc,
251 unsigned long flags, unsigned long fixed_rate,
252 struct tegra_clk_pll_params *pll_params, u32 pll_flags,
253 struct tegra_clk_pll_freq_table *freq_table, spinlock_t *lock);
254
255struct clk *tegra_clk_register_pllxc(const char *name, const char *parent_name,
256 void __iomem *clk_base, void __iomem *pmc,
257 unsigned long flags, unsigned long fixed_rate,
258 struct tegra_clk_pll_params *pll_params,
259 u32 pll_flags,
260 struct tegra_clk_pll_freq_table *freq_table,
261 spinlock_t *lock);
262
263struct clk *tegra_clk_register_pllm(const char *name, const char *parent_name,
264 void __iomem *clk_base, void __iomem *pmc,
265 unsigned long flags, unsigned long fixed_rate,
266 struct tegra_clk_pll_params *pll_params,
267 u32 pll_flags,
268 struct tegra_clk_pll_freq_table *freq_table,
269 spinlock_t *lock);
270
271struct clk *tegra_clk_register_pllc(const char *name, const char *parent_name,
272 void __iomem *clk_base, void __iomem *pmc,
273 unsigned long flags, unsigned long fixed_rate,
274 struct tegra_clk_pll_params *pll_params,
275 u32 pll_flags,
276 struct tegra_clk_pll_freq_table *freq_table,
277 spinlock_t *lock);
278
279struct clk *tegra_clk_register_pllre(const char *name, const char *parent_name,
280 void __iomem *clk_base, void __iomem *pmc,
281 unsigned long flags, unsigned long fixed_rate,
282 struct tegra_clk_pll_params *pll_params,
283 u32 pll_flags,
284 struct tegra_clk_pll_freq_table *freq_table,
285 spinlock_t *lock, unsigned long parent_rate);
286
287struct clk *tegra_clk_register_plle_tegra114(const char *name,
288 const char *parent_name,
289 void __iomem *clk_base, unsigned long flags,
290 unsigned long fixed_rate,
291 struct tegra_clk_pll_params *pll_params,
292 struct tegra_clk_pll_freq_table *freq_table,
293 spinlock_t *lock);
294
295
296
297
298
299
300
301
302
303
304
305struct tegra_clk_pll_out {
306 struct clk_hw hw;
307 void __iomem *reg;
308 u8 enb_bit_idx;
309 u8 rst_bit_idx;
310 spinlock_t *lock;
311 u8 flags;
312};
313
314#define to_clk_pll_out(_hw) container_of(_hw, struct tegra_clk_pll_out, hw)
315
316extern const struct clk_ops tegra_clk_pll_out_ops;
317struct clk *tegra_clk_register_pll_out(const char *name,
318 const char *parent_name, void __iomem *reg, u8 enb_bit_idx,
319 u8 rst_bit_idx, unsigned long flags, u8 pll_div_flags,
320 spinlock_t *lock);
321
322
323
324
325
326
327
328
329
330
331
332struct tegra_clk_periph_regs {
333 u32 enb_reg;
334 u32 enb_set_reg;
335 u32 enb_clr_reg;
336 u32 rst_reg;
337 u32 rst_set_reg;
338 u32 rst_clr_reg;
339};
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363struct tegra_clk_periph_gate {
364 u32 magic;
365 struct clk_hw hw;
366 void __iomem *clk_base;
367 u8 flags;
368 int clk_num;
369 int *enable_refcnt;
370 struct tegra_clk_periph_regs *regs;
371};
372
373#define to_clk_periph_gate(_hw) \
374 container_of(_hw, struct tegra_clk_periph_gate, hw)
375
376#define TEGRA_CLK_PERIPH_GATE_MAGIC 0x17760309
377
378#define TEGRA_PERIPH_NO_RESET BIT(0)
379#define TEGRA_PERIPH_MANUAL_RESET BIT(1)
380#define TEGRA_PERIPH_ON_APB BIT(2)
381#define TEGRA_PERIPH_WAR_1005168 BIT(3)
382
383void tegra_periph_reset(struct tegra_clk_periph_gate *gate, bool assert);
384extern const struct clk_ops tegra_clk_periph_gate_ops;
385struct clk *tegra_clk_register_periph_gate(const char *name,
386 const char *parent_name, u8 gate_flags, void __iomem *clk_base,
387 unsigned long flags, int clk_num,
388 struct tegra_clk_periph_regs *pregs, int *enable_refcnt);
389
390
391
392
393
394
395
396
397
398
399
400
401
402struct tegra_clk_periph {
403 u32 magic;
404 struct clk_hw hw;
405 struct clk_mux mux;
406 struct tegra_clk_frac_div divider;
407 struct tegra_clk_periph_gate gate;
408
409 const struct clk_ops *mux_ops;
410 const struct clk_ops *div_ops;
411 const struct clk_ops *gate_ops;
412};
413
414#define to_clk_periph(_hw) container_of(_hw, struct tegra_clk_periph, hw)
415
416#define TEGRA_CLK_PERIPH_MAGIC 0x18221223
417
418extern const struct clk_ops tegra_clk_periph_ops;
419struct clk *tegra_clk_register_periph(const char *name,
420 const char **parent_names, int num_parents,
421 struct tegra_clk_periph *periph, void __iomem *clk_base,
422 u32 offset, unsigned long flags);
423struct clk *tegra_clk_register_periph_nodiv(const char *name,
424 const char **parent_names, int num_parents,
425 struct tegra_clk_periph *periph, void __iomem *clk_base,
426 u32 offset);
427
428#define TEGRA_CLK_PERIPH(_mux_shift, _mux_mask, _mux_flags, \
429 _div_shift, _div_width, _div_frac_width, \
430 _div_flags, _clk_num, _enb_refcnt, _regs, \
431 _gate_flags, _table) \
432 { \
433 .mux = { \
434 .flags = _mux_flags, \
435 .shift = _mux_shift, \
436 .mask = _mux_mask, \
437 .table = _table, \
438 }, \
439 .divider = { \
440 .flags = _div_flags, \
441 .shift = _div_shift, \
442 .width = _div_width, \
443 .frac_width = _div_frac_width, \
444 }, \
445 .gate = { \
446 .flags = _gate_flags, \
447 .clk_num = _clk_num, \
448 .enable_refcnt = _enb_refcnt, \
449 .regs = _regs, \
450 }, \
451 .mux_ops = &clk_mux_ops, \
452 .div_ops = &tegra_clk_frac_div_ops, \
453 .gate_ops = &tegra_clk_periph_gate_ops, \
454 }
455
456struct tegra_periph_init_data {
457 const char *name;
458 int clk_id;
459 const char **parent_names;
460 int num_parents;
461 struct tegra_clk_periph periph;
462 u32 offset;
463 const char *con_id;
464 const char *dev_id;
465 unsigned long flags;
466};
467
468#define TEGRA_INIT_DATA_TABLE(_name, _con_id, _dev_id, _parent_names, _offset,\
469 _mux_shift, _mux_mask, _mux_flags, _div_shift, \
470 _div_width, _div_frac_width, _div_flags, _regs, \
471 _clk_num, _enb_refcnt, _gate_flags, _clk_id, _table,\
472 _flags) \
473 { \
474 .name = _name, \
475 .clk_id = _clk_id, \
476 .parent_names = _parent_names, \
477 .num_parents = ARRAY_SIZE(_parent_names), \
478 .periph = TEGRA_CLK_PERIPH(_mux_shift, _mux_mask, \
479 _mux_flags, _div_shift, \
480 _div_width, _div_frac_width, \
481 _div_flags, _clk_num, \
482 _enb_refcnt, _regs, \
483 _gate_flags, _table), \
484 .offset = _offset, \
485 .con_id = _con_id, \
486 .dev_id = _dev_id, \
487 .flags = _flags \
488 }
489
490#define TEGRA_INIT_DATA(_name, _con_id, _dev_id, _parent_names, _offset,\
491 _mux_shift, _mux_width, _mux_flags, _div_shift, \
492 _div_width, _div_frac_width, _div_flags, _regs, \
493 _clk_num, _enb_refcnt, _gate_flags, _clk_id) \
494 TEGRA_INIT_DATA_TABLE(_name, _con_id, _dev_id, _parent_names, _offset,\
495 _mux_shift, BIT(_mux_width) - 1, _mux_flags, \
496 _div_shift, _div_width, _div_frac_width, _div_flags, \
497 _regs, _clk_num, _enb_refcnt, _gate_flags, _clk_id,\
498 NULL, 0)
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515struct tegra_clk_super_mux {
516 struct clk_hw hw;
517 void __iomem *reg;
518 u8 width;
519 u8 flags;
520 u8 div2_index;
521 u8 pllx_index;
522 spinlock_t *lock;
523};
524
525#define to_clk_super_mux(_hw) container_of(_hw, struct tegra_clk_super_mux, hw)
526
527#define TEGRA_DIVIDER_2 BIT(0)
528
529extern const struct clk_ops tegra_clk_super_ops;
530struct clk *tegra_clk_register_super_mux(const char *name,
531 const char **parent_names, u8 num_parents,
532 unsigned long flags, void __iomem *reg, u8 clk_super_flags,
533 u8 width, u8 pllx_index, u8 div2_index, spinlock_t *lock);
534
535
536
537
538
539
540
541
542struct tegra_clk_init_table {
543 unsigned int clk_id;
544 unsigned int parent_id;
545 unsigned long rate;
546 int state;
547};
548
549
550
551
552
553
554struct tegra_clk_duplicate {
555 int clk_id;
556 struct clk_lookup lookup;
557};
558
559#define TEGRA_CLK_DUPLICATE(_clk_id, _dev, _con) \
560 { \
561 .clk_id = _clk_id, \
562 .lookup = { \
563 .dev_id = _dev, \
564 .con_id = _con, \
565 }, \
566 }
567
568void tegra_init_from_table(struct tegra_clk_init_table *tbl,
569 struct clk *clks[], int clk_max);
570
571void tegra_init_dup_clks(struct tegra_clk_duplicate *dup_list,
572 struct clk *clks[], int clk_max);
573
574#ifdef CONFIG_ARCH_TEGRA_2x_SOC
575void tegra20_clock_init(struct device_node *np);
576#else
577static inline void tegra20_clock_init(struct device_node *np) {}
578#endif
579
580#ifdef CONFIG_ARCH_TEGRA_3x_SOC
581void tegra30_clock_init(struct device_node *np);
582#else
583static inline void tegra30_clock_init(struct device_node *np) {}
584#endif
585
586#ifdef CONFIG_ARCH_TEGRA_114_SOC
587void tegra114_clock_init(struct device_node *np);
588#else
589static inline void tegra114_clock_init(struct device_node *np) {}
590#endif
591
592typedef void (*tegra_clk_apply_init_table_func)(void);
593extern tegra_clk_apply_init_table_func tegra_clk_apply_init_table;
594
595#endif
596