21 #include <linux/kernel.h>
22 #include <linux/module.h>
23 #include <linux/list.h>
32 #include <asm/clkdev.h>
40 #define USE_PLL_LOCK_BITS 0
42 #define RST_DEVICES_L 0x004
43 #define RST_DEVICES_H 0x008
44 #define RST_DEVICES_U 0x00C
45 #define RST_DEVICES_V 0x358
46 #define RST_DEVICES_W 0x35C
47 #define RST_DEVICES_SET_L 0x300
48 #define RST_DEVICES_CLR_L 0x304
49 #define RST_DEVICES_SET_V 0x430
50 #define RST_DEVICES_CLR_V 0x434
51 #define RST_DEVICES_NUM 5
53 #define CLK_OUT_ENB_L 0x010
54 #define CLK_OUT_ENB_H 0x014
55 #define CLK_OUT_ENB_U 0x018
56 #define CLK_OUT_ENB_V 0x360
57 #define CLK_OUT_ENB_W 0x364
58 #define CLK_OUT_ENB_SET_L 0x320
59 #define CLK_OUT_ENB_CLR_L 0x324
60 #define CLK_OUT_ENB_SET_V 0x440
61 #define CLK_OUT_ENB_CLR_V 0x444
62 #define CLK_OUT_ENB_NUM 5
64 #define RST_DEVICES_V_SWR_CPULP_RST_DIS (0x1 << 1)
65 #define CLK_OUT_ENB_V_CLK_ENB_CPULP_EN (0x1 << 1)
67 #define PERIPH_CLK_TO_BIT(c) (1 << (c->u.periph.clk_num % 32))
68 #define PERIPH_CLK_TO_RST_REG(c) \
69 periph_clk_to_reg((c), RST_DEVICES_L, RST_DEVICES_V, 4)
70 #define PERIPH_CLK_TO_RST_SET_REG(c) \
71 periph_clk_to_reg((c), RST_DEVICES_SET_L, RST_DEVICES_SET_V, 8)
72 #define PERIPH_CLK_TO_RST_CLR_REG(c) \
73 periph_clk_to_reg((c), RST_DEVICES_CLR_L, RST_DEVICES_CLR_V, 8)
75 #define PERIPH_CLK_TO_ENB_REG(c) \
76 periph_clk_to_reg((c), CLK_OUT_ENB_L, CLK_OUT_ENB_V, 4)
77 #define PERIPH_CLK_TO_ENB_SET_REG(c) \
78 periph_clk_to_reg((c), CLK_OUT_ENB_SET_L, CLK_OUT_ENB_SET_V, 8)
79 #define PERIPH_CLK_TO_ENB_CLR_REG(c) \
80 periph_clk_to_reg((c), CLK_OUT_ENB_CLR_L, CLK_OUT_ENB_CLR_V, 8)
82 #define CLK_MASK_ARM 0x44
83 #define MISC_CLK_ENB 0x48
86 #define OSC_CTRL_OSC_FREQ_MASK (0xF<<28)
87 #define OSC_CTRL_OSC_FREQ_13MHZ (0x0<<28)
88 #define OSC_CTRL_OSC_FREQ_19_2MHZ (0x4<<28)
89 #define OSC_CTRL_OSC_FREQ_12MHZ (0x8<<28)
90 #define OSC_CTRL_OSC_FREQ_26MHZ (0xC<<28)
91 #define OSC_CTRL_OSC_FREQ_16_8MHZ (0x1<<28)
92 #define OSC_CTRL_OSC_FREQ_38_4MHZ (0x5<<28)
93 #define OSC_CTRL_OSC_FREQ_48MHZ (0x9<<28)
94 #define OSC_CTRL_MASK (0x3f2 | OSC_CTRL_OSC_FREQ_MASK)
96 #define OSC_CTRL_PLL_REF_DIV_MASK (3<<26)
97 #define OSC_CTRL_PLL_REF_DIV_1 (0<<26)
98 #define OSC_CTRL_PLL_REF_DIV_2 (1<<26)
99 #define OSC_CTRL_PLL_REF_DIV_4 (2<<26)
101 #define OSC_FREQ_DET 0x58
102 #define OSC_FREQ_DET_TRIG (1<<31)
104 #define OSC_FREQ_DET_STATUS 0x5C
105 #define OSC_FREQ_DET_BUSY (1<<31)
106 #define OSC_FREQ_DET_CNT_MASK 0xFFFF
108 #define PERIPH_CLK_SOURCE_I2S1 0x100
109 #define PERIPH_CLK_SOURCE_EMC 0x19c
110 #define PERIPH_CLK_SOURCE_OSC 0x1fc
111 #define PERIPH_CLK_SOURCE_NUM1 \
112 ((PERIPH_CLK_SOURCE_OSC - PERIPH_CLK_SOURCE_I2S1) / 4)
114 #define PERIPH_CLK_SOURCE_G3D2 0x3b0
115 #define PERIPH_CLK_SOURCE_SE 0x42c
116 #define PERIPH_CLK_SOURCE_NUM2 \
117 ((PERIPH_CLK_SOURCE_SE - PERIPH_CLK_SOURCE_G3D2) / 4 + 1)
119 #define AUDIO_DLY_CLK 0x49c
120 #define AUDIO_SYNC_CLK_SPDIF 0x4b4
121 #define PERIPH_CLK_SOURCE_NUM3 \
122 ((AUDIO_SYNC_CLK_SPDIF - AUDIO_DLY_CLK) / 4 + 1)
124 #define PERIPH_CLK_SOURCE_NUM (PERIPH_CLK_SOURCE_NUM1 + \
125 PERIPH_CLK_SOURCE_NUM2 + \
126 PERIPH_CLK_SOURCE_NUM3)
128 #define CPU_SOFTRST_CTRL 0x380
130 #define PERIPH_CLK_SOURCE_DIVU71_MASK 0xFF
131 #define PERIPH_CLK_SOURCE_DIVU16_MASK 0xFFFF
132 #define PERIPH_CLK_SOURCE_DIV_SHIFT 0
133 #define PERIPH_CLK_SOURCE_DIVIDLE_SHIFT 8
134 #define PERIPH_CLK_SOURCE_DIVIDLE_VAL 50
135 #define PERIPH_CLK_UART_DIV_ENB (1<<24)
136 #define PERIPH_CLK_VI_SEL_EX_SHIFT 24
137 #define PERIPH_CLK_VI_SEL_EX_MASK (0x3<<PERIPH_CLK_VI_SEL_EX_SHIFT)
138 #define PERIPH_CLK_NAND_DIV_EX_ENB (1<<8)
139 #define PERIPH_CLK_DTV_POLARITY_INV (1<<25)
141 #define AUDIO_SYNC_SOURCE_MASK 0x0F
142 #define AUDIO_SYNC_DISABLE_BIT 0x10
143 #define AUDIO_SYNC_TAP_NIBBLE_SHIFT(c) ((c->reg_shift - 24) * 4)
146 #define PLL_BASE_BYPASS (1<<31)
147 #define PLL_BASE_ENABLE (1<<30)
148 #define PLL_BASE_REF_ENABLE (1<<29)
149 #define PLL_BASE_OVERRIDE (1<<28)
150 #define PLL_BASE_LOCK (1<<27)
151 #define PLL_BASE_DIVP_MASK (0x7<<20)
152 #define PLL_BASE_DIVP_SHIFT 20
153 #define PLL_BASE_DIVN_MASK (0x3FF<<8)
154 #define PLL_BASE_DIVN_SHIFT 8
155 #define PLL_BASE_DIVM_MASK (0x1F)
156 #define PLL_BASE_DIVM_SHIFT 0
158 #define PLL_OUT_RATIO_MASK (0xFF<<8)
159 #define PLL_OUT_RATIO_SHIFT 8
160 #define PLL_OUT_OVERRIDE (1<<2)
161 #define PLL_OUT_CLKEN (1<<1)
162 #define PLL_OUT_RESET_DISABLE (1<<0)
164 #define PLL_MISC(c) \
165 (((c)->flags & PLL_ALT_MISC_REG) ? 0x4 : 0xc)
166 #define PLL_MISC_LOCK_ENABLE(c) \
167 (((c)->flags & (PLLU | PLLD)) ? (1<<22) : (1<<18))
169 #define PLL_MISC_DCCON_SHIFT 20
170 #define PLL_MISC_CPCON_SHIFT 8
171 #define PLL_MISC_CPCON_MASK (0xF<<PLL_MISC_CPCON_SHIFT)
172 #define PLL_MISC_LFCON_SHIFT 4
173 #define PLL_MISC_LFCON_MASK (0xF<<PLL_MISC_LFCON_SHIFT)
174 #define PLL_MISC_VCOCON_SHIFT 0
175 #define PLL_MISC_VCOCON_MASK (0xF<<PLL_MISC_VCOCON_SHIFT)
176 #define PLLD_MISC_CLKENABLE (1<<30)
178 #define PLLU_BASE_POST_DIV (1<<20)
180 #define PLLD_BASE_DSIB_MUX_SHIFT 25
181 #define PLLD_BASE_DSIB_MUX_MASK (1<<PLLD_BASE_DSIB_MUX_SHIFT)
182 #define PLLD_BASE_CSI_CLKENABLE (1<<26)
183 #define PLLD_MISC_DSI_CLKENABLE (1<<30)
184 #define PLLD_MISC_DIV_RST (1<<23)
185 #define PLLD_MISC_DCCON_SHIFT 12
187 #define PLLDU_LFCON_SET_DIVN 600
190 #define OUT_OF_TABLE_CPCON 0x8
192 #define SUPER_CLK_MUX 0x00
193 #define SUPER_STATE_SHIFT 28
194 #define SUPER_STATE_MASK (0xF << SUPER_STATE_SHIFT)
195 #define SUPER_STATE_STANDBY (0x0 << SUPER_STATE_SHIFT)
196 #define SUPER_STATE_IDLE (0x1 << SUPER_STATE_SHIFT)
197 #define SUPER_STATE_RUN (0x2 << SUPER_STATE_SHIFT)
198 #define SUPER_STATE_IRQ (0x3 << SUPER_STATE_SHIFT)
199 #define SUPER_STATE_FIQ (0x4 << SUPER_STATE_SHIFT)
200 #define SUPER_LP_DIV2_BYPASS (0x1 << 16)
201 #define SUPER_SOURCE_MASK 0xF
202 #define SUPER_FIQ_SOURCE_SHIFT 12
203 #define SUPER_IRQ_SOURCE_SHIFT 8
204 #define SUPER_RUN_SOURCE_SHIFT 4
205 #define SUPER_IDLE_SOURCE_SHIFT 0
207 #define SUPER_CLK_DIVIDER 0x04
208 #define SUPER_CLOCK_DIV_U71_SHIFT 16
209 #define SUPER_CLOCK_DIV_U71_MASK (0xff << SUPER_CLOCK_DIV_U71_SHIFT)
211 #define SUPER_CLOCK_DIV_U71_MIN 0x2
213 #define BUS_CLK_DISABLE (1<<3)
214 #define BUS_CLK_DIV_MASK 0x3
217 #define PMC_CTRL_BLINK_ENB (1 << 7)
219 #define PMC_DPD_PADS_ORIDE 0x1c
220 #define PMC_DPD_PADS_ORIDE_BLINK_ENB (1 << 20)
222 #define PMC_BLINK_TIMER_DATA_ON_SHIFT 0
223 #define PMC_BLINK_TIMER_DATA_ON_MASK 0x7fff
224 #define PMC_BLINK_TIMER_ENB (1 << 15)
225 #define PMC_BLINK_TIMER_DATA_OFF_SHIFT 16
226 #define PMC_BLINK_TIMER_DATA_OFF_MASK 0xffff
228 #define PMC_PLLP_WB0_OVERRIDE 0xf8
229 #define PMC_PLLP_WB0_OVERRIDE_PLLM_ENABLE (1 << 12)
231 #define UTMIP_PLL_CFG2 0x488
232 #define UTMIP_PLL_CFG2_STABLE_COUNT(x) (((x) & 0xfff) << 6)
233 #define UTMIP_PLL_CFG2_ACTIVE_DLY_COUNT(x) (((x) & 0x3f) << 18)
234 #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_A_POWERDOWN (1 << 0)
235 #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_B_POWERDOWN (1 << 2)
236 #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_C_POWERDOWN (1 << 4)
238 #define UTMIP_PLL_CFG1 0x484
239 #define UTMIP_PLL_CFG1_ENABLE_DLY_COUNT(x) (((x) & 0x1f) << 27)
240 #define UTMIP_PLL_CFG1_XTAL_FREQ_COUNT(x) (((x) & 0xfff) << 0)
241 #define UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERDOWN (1 << 14)
242 #define UTMIP_PLL_CFG1_FORCE_PLL_ACTIVE_POWERDOWN (1 << 12)
243 #define UTMIP_PLL_CFG1_FORCE_PLLU_POWERDOWN (1 << 16)
245 #define PLLE_BASE_CML_ENABLE (1<<31)
246 #define PLLE_BASE_ENABLE (1<<30)
247 #define PLLE_BASE_DIVCML_SHIFT 24
248 #define PLLE_BASE_DIVCML_MASK (0xf<<PLLE_BASE_DIVCML_SHIFT)
249 #define PLLE_BASE_DIVP_SHIFT 16
250 #define PLLE_BASE_DIVP_MASK (0x3f<<PLLE_BASE_DIVP_SHIFT)
251 #define PLLE_BASE_DIVN_SHIFT 8
252 #define PLLE_BASE_DIVN_MASK (0xFF<<PLLE_BASE_DIVN_SHIFT)
253 #define PLLE_BASE_DIVM_SHIFT 0
254 #define PLLE_BASE_DIVM_MASK (0xFF<<PLLE_BASE_DIVM_SHIFT)
255 #define PLLE_BASE_DIV_MASK \
256 (PLLE_BASE_DIVCML_MASK | PLLE_BASE_DIVP_MASK | \
257 PLLE_BASE_DIVN_MASK | PLLE_BASE_DIVM_MASK)
258 #define PLLE_BASE_DIV(m, n, p, cml) \
259 (((cml)<<PLLE_BASE_DIVCML_SHIFT) | ((p)<<PLLE_BASE_DIVP_SHIFT) | \
260 ((n)<<PLLE_BASE_DIVN_SHIFT) | ((m)<<PLLE_BASE_DIVM_SHIFT))
262 #define PLLE_MISC_SETUP_BASE_SHIFT 16
263 #define PLLE_MISC_SETUP_BASE_MASK (0xFFFF<<PLLE_MISC_SETUP_BASE_SHIFT)
264 #define PLLE_MISC_READY (1<<15)
265 #define PLLE_MISC_LOCK (1<<11)
266 #define PLLE_MISC_LOCK_ENABLE (1<<9)
267 #define PLLE_MISC_SETUP_EX_SHIFT 2
268 #define PLLE_MISC_SETUP_EX_MASK (0x3<<PLLE_MISC_SETUP_EX_SHIFT)
269 #define PLLE_MISC_SETUP_MASK \
270 (PLLE_MISC_SETUP_BASE_MASK | PLLE_MISC_SETUP_EX_MASK)
271 #define PLLE_MISC_SETUP_VALUE \
272 ((0x7<<PLLE_MISC_SETUP_BASE_SHIFT) | (0x0<<PLLE_MISC_SETUP_EX_SHIFT))
274 #define PLLE_SS_CTRL 0x68
275 #define PLLE_SS_INCINTRV_SHIFT 24
276 #define PLLE_SS_INCINTRV_MASK (0x3f<<PLLE_SS_INCINTRV_SHIFT)
277 #define PLLE_SS_INC_SHIFT 16
278 #define PLLE_SS_INC_MASK (0xff<<PLLE_SS_INC_SHIFT)
279 #define PLLE_SS_MAX_SHIFT 0
280 #define PLLE_SS_MAX_MASK (0x1ff<<PLLE_SS_MAX_SHIFT)
281 #define PLLE_SS_COEFFICIENTS_MASK \
282 (PLLE_SS_INCINTRV_MASK | PLLE_SS_INC_MASK | PLLE_SS_MAX_MASK)
283 #define PLLE_SS_COEFFICIENTS_12MHZ \
284 ((0x18<<PLLE_SS_INCINTRV_SHIFT) | (0x1<<PLLE_SS_INC_SHIFT) | \
285 (0x24<<PLLE_SS_MAX_SHIFT))
286 #define PLLE_SS_DISABLE ((1<<12) | (1<<11) | (1<<10))
288 #define PLLE_AUX 0x48c
289 #define PLLE_AUX_PLLP_SEL (1<<2)
290 #define PLLE_AUX_CML_SATA_ENABLE (1<<1)
291 #define PLLE_AUX_CML_PCIE_ENABLE (1<<0)
293 #define PMC_SATA_PWRGT 0x1ac
294 #define PMC_SATA_PWRGT_PLLE_IDDQ_VALUE (1<<5)
295 #define PMC_SATA_PWRGT_PLLE_IDDQ_SWCTL (1<<4)
297 #define ROUND_DIVIDER_UP 0
298 #define ROUND_DIVIDER_DOWN 1
301 #define PLL_POST_LOCK_DELAY 100
304 #define TEGRA_CLK_RST_CONTROLLER_CLK_CPU_CMPLX 0x4c
305 #define TEGRA_CLK_RST_CONTROLLER_RST_CPU_CMPLX_SET 0x340
306 #define TEGRA_CLK_RST_CONTROLLER_RST_CPU_CMPLX_CLR 0x344
307 #define TEGRA30_CLK_RST_CONTROLLER_CLK_CPU_CMPLX_CLR 0x34c
308 #define TEGRA30_CLK_RST_CONTROLLER_CPU_CMPLX_STATUS 0x470
310 #define CPU_CLOCK(cpu) (0x1 << (8 + cpu))
311 #define CPU_RESET(cpu) (0x1111ul << (cpu))
331 .osc_frequency = 13000000,
332 .enable_delay_count = 0x02,
333 .stable_count = 0x33,
334 .active_delay_count = 0x05,
335 .xtal_freq_count = 0x7F
338 .osc_frequency = 19200000,
339 .enable_delay_count = 0x03,
340 .stable_count = 0x4B,
341 .active_delay_count = 0x06,
342 .xtal_freq_count = 0xBB},
344 .osc_frequency = 12000000,
345 .enable_delay_count = 0x02,
346 .stable_count = 0x2F,
347 .active_delay_count = 0x04,
348 .xtal_freq_count = 0x76
351 .osc_frequency = 26000000,
352 .enable_delay_count = 0x04,
353 .stable_count = 0x66,
354 .active_delay_count = 0x09,
355 .xtal_freq_count = 0xFE
358 .osc_frequency = 16800000,
359 .enable_delay_count = 0x03,
360 .stable_count = 0x41,
361 .active_delay_count = 0x0A,
362 .xtal_freq_count = 0xA4
370 #define MISC_GP_HIDREV 0x804
378 #define clk_writel(value, reg) \
379 __raw_writel(value, reg_clk_base + (reg))
380 #define clk_readl(reg) \
381 __raw_readl(reg_clk_base + (reg))
382 #define pmc_writel(value, reg) \
383 __raw_writel(value, reg_pmc_base + (reg))
384 #define pmc_readl(reg) \
385 __raw_readl(reg_pmc_base + (reg))
386 #define chipid_readl() \
387 __raw_readl(misc_gp_hidrev_base + MISC_GP_HIDREV)
389 #define clk_writel_delay(value, reg) \
391 __raw_writel((value), reg_clk_base + (reg)); \
403 static inline u32 periph_clk_to_reg(
409 reg = reg_L + (reg *
offs);
411 reg = reg_V + ((reg - 3) * offs);
415 static unsigned long clk_measure_input_freq(
void)
417 u32 clock_autodetect;
421 if (clock_autodetect >= 732 - 3 && clock_autodetect <= 732 + 3) {
423 }
else if (clock_autodetect >= 794 - 3 && clock_autodetect <= 794 + 3) {
425 }
else if (clock_autodetect >= 1172 - 3 && clock_autodetect <= 1172 + 3) {
427 }
else if (clock_autodetect >= 1587 - 3 && clock_autodetect <= 1587 + 3) {
429 }
else if (clock_autodetect >= 1025 - 3 && clock_autodetect <= 1025 + 3) {
431 }
else if (clock_autodetect >= 2344 - 3 && clock_autodetect <= 2344 + 3) {
433 }
else if (clock_autodetect >= 2928 - 3 && clock_autodetect <= 2928 + 3) {
436 pr_err(
"%s: Unexpected clock autodetect value %d", __func__,
443 static int clk_div71_get_divider(
unsigned long parent_rate,
unsigned long rate,
446 s64 divider_u71 = parent_rate;
453 divider_u71 += rate - 1;
454 do_div(divider_u71, rate);
455 if (flags & DIV_U71_INT)
458 if (divider_u71 - 2 < 0)
461 if (divider_u71 - 2 > 255)
464 return divider_u71 - 2;
467 static int clk_div16_get_divider(
unsigned long parent_rate,
unsigned long rate)
471 divider_u16 = parent_rate;
474 divider_u16 += rate - 1;
475 do_div(divider_u16, rate);
477 if (divider_u16 - 1 < 0)
480 if (divider_u16 - 1 > 0xFFFF)
483 return divider_u16 - 1;
486 static unsigned long tegra30_clk_fixed_recalc_rate(
struct clk_hw *
hw,
487 unsigned long parent_rate)
493 .recalc_rate = tegra30_clk_fixed_recalc_rate,
497 static unsigned long tegra30_clk_m_recalc_rate(
struct clk_hw *
hw,
498 unsigned long parent_rate)
501 to_clk_tegra(hw)->fixed_rate = clk_measure_input_freq();
505 static void tegra30_clk_m_init(
struct clk_hw *hw)
541 pr_err(
"%s: Unexpected clock rate %ld", __func__,
549 .init = tegra30_clk_m_init,
550 .recalc_rate = tegra30_clk_m_recalc_rate,
553 static unsigned long tegra30_clk_m_div_recalc_rate(
struct clk_hw *hw,
554 unsigned long parent_rate)
557 u64 rate = parent_rate;
559 if (c->
mul != 0 && c->
div != 0) {
569 .recalc_rate = tegra30_clk_m_div_recalc_rate,
573 static unsigned long tegra30_pll_ref_recalc_rate(
struct clk_hw *hw,
574 unsigned long parent_rate)
577 unsigned long rate = parent_rate;
580 switch (pll_ref_div) {
591 pr_err(
"%s: Invalid pll ref divider %d", __func__, pll_ref_div);
596 if (c->
mul != 0 && c->
div != 0) {
606 .recalc_rate = tegra30_pll_ref_recalc_rate,
617 static void tegra30_super_clk_init(
struct clk_hw *hw)
636 static u8 tegra30_super_clk_get_parent(
struct clk_hw *hw)
655 static int tegra30_super_clk_set_parent(
struct clk_hw *hw,
u8 index)
709 static int tegra30_super_clk_set_rate(
struct clk_hw *hw,
unsigned long rate,
710 unsigned long parent_rate)
717 int div = clk_div71_get_divider(parent_rate,
730 static unsigned long tegra30_super_clk_recalc_rate(
struct clk_hw *hw,
731 unsigned long parent_rate)
734 u64 rate = parent_rate;
736 if (c->
mul != 0 && c->
div != 0) {
745 static long tegra30_super_clk_round_rate(
struct clk_hw *hw,
unsigned long rate,
746 unsigned long *
prate)
755 div = clk_div71_get_divider(*prate,
768 .init = tegra30_super_clk_init,
769 .set_parent = tegra30_super_clk_set_parent,
770 .get_parent = tegra30_super_clk_get_parent,
771 .recalc_rate = tegra30_super_clk_recalc_rate,
772 .round_rate = tegra30_super_clk_round_rate,
773 .set_rate = tegra30_super_clk_set_rate,
776 static unsigned long tegra30_twd_clk_recalc_rate(
struct clk_hw *hw,
777 unsigned long parent_rate)
780 u64 rate = parent_rate;
782 if (c->
mul != 0 && c->
div != 0) {
792 .recalc_rate = tegra30_twd_clk_recalc_rate,
796 static int tegra30_blink_clk_is_enabled(
struct clk_hw *hw)
806 static int tegra30_blink_clk_enable(
struct clk_hw *hw)
819 static void tegra30_blink_clk_disable(
struct clk_hw *hw)
830 static int tegra30_blink_clk_set_rate(
struct clk_hw *hw,
unsigned long rate,
831 unsigned long parent_rate)
835 if (rate >= parent_rate) {
857 static unsigned long tegra30_blink_clk_recalc_rate(
struct clk_hw *hw,
858 unsigned long parent_rate)
861 u64 rate = parent_rate;
882 if (mul != 0 && div != 0) {
890 static long tegra30_blink_clk_round_rate(
struct clk_hw *hw,
unsigned long rate,
891 unsigned long *prate)
895 long round_rate = *
prate;
899 if (rate >= *prate) {
907 round_rate += div - 1;
914 .is_enabled = tegra30_blink_clk_is_enabled,
915 .enable = tegra30_blink_clk_enable,
916 .disable = tegra30_blink_clk_disable,
917 .recalc_rate = tegra30_blink_clk_recalc_rate,
918 .round_rate = tegra30_blink_clk_round_rate,
919 .set_rate = tegra30_blink_clk_set_rate,
922 static void tegra30_utmi_param_configure(
struct clk_hw *hw)
924 unsigned long main_rate =
929 for (i = 0; i <
ARRAY_SIZE(utmi_parameters); i++) {
930 if (main_rate == utmi_parameters[i].osc_frequency)
935 pr_err(
"%s: Unexpected main rate %lu\n", __func__, main_rate);
945 utmi_parameters[i].stable_count);
950 utmi_parameters[i].active_delay_count);
964 utmi_parameters[i].enable_delay_count);
968 utmi_parameters[i].xtal_freq_count);
979 static int tegra30_pll_clk_wait_for_lock(
struct clk_tegra *c,
u32 lock_reg,
984 #if USE_PLL_LOCK_BITS
986 for (i = 0; i < c->
u.
pll.lock_delay; i++) {
993 pr_err(
"Timed out waiting for lock bit on pll %s",
1002 static int tegra30_pll_clk_is_enabled(
struct clk_hw *hw)
1011 static void tegra30_pll_clk_init(
struct clk_hw *hw)
1016 tegra30_utmi_param_configure(hw);
1019 static int tegra30_pll_clk_enable(
struct clk_hw *hw)
1025 #if USE_PLL_LOCK_BITS
1046 static void tegra30_pll_clk_disable(
struct clk_hw *hw)
1063 static int tegra30_pll_clk_set_rate(
struct clk_hw *hw,
unsigned long rate,
1064 unsigned long parent_rate)
1067 u32 val, p_div, old_base;
1068 unsigned long input_rate;
1074 if (rate != c->
u.
pll.fixed_rate) {
1075 pr_err(
"%s: Can not change %s fixed rate %lu to %lu\n",
1077 c->
u.
pll.fixed_rate, rate);
1085 pr_err(
"%s: Can not change memory %s rate in flight\n",
1092 input_rate = parent_rate;
1103 for (val = sel->
p; val > 1; val >>= 1)
1113 unsigned long cfreq;
1117 switch (input_rate) {
1120 cfreq = (rate <= 1000000 * 1000) ? 1000000 : 2000000;
1123 cfreq = (rate <= 1000000 * 1000) ? 1000000 : 2600000;
1127 cfreq = (rate <= 1200000 * 1000) ? 1200000 : 2400000;
1130 pr_err(
"%s: Unexpected reference rate %lu\n",
1131 __func__, input_rate);
1136 for (
cfg.output_rate = rate;
cfg.output_rate < 200 * cfreq;
1137 cfg.output_rate <<= 1)
1140 cfg.p = 0x1 << p_div;
1141 cfg.m = input_rate / cfreq;
1142 cfg.n =
cfg.output_rate / cfreq;
1148 (
cfg.output_rate > c->
u.
pll.vco_max)) {
1149 pr_err(
"%s: Failed to set %s out-of-table rate %lu\n",
1157 c->
div = sel->
m * sel->
p;
1164 if (val == old_base)
1168 tegra30_pll_clk_disable(hw);
1183 if (rate >= (c->
u.
pll.vco_max >> 1))
1190 tegra30_pll_clk_enable(hw);
1197 static long tegra30_pll_round_rate(
struct clk_hw *hw,
unsigned long rate,
1198 unsigned long *prate)
1201 unsigned long input_rate = *
prate;
1211 return c->
u.
pll.fixed_rate;
1226 for (val = sel->
p; val > 1; val >>= 1)
1235 unsigned long cfreq;
1239 switch (input_rate) {
1242 cfreq = (rate <= 1000000 * 1000) ? 1000000 : 2000000;
1245 cfreq = (rate <= 1000000 * 1000) ? 1000000 : 2600000;
1249 cfreq = (rate <= 1200000 * 1000) ? 1200000 : 2400000;
1252 pr_err(
"%s: Unexpected reference rate %lu\n",
1253 __func__, input_rate);
1258 for (
cfg.output_rate = rate;
cfg.output_rate < 200 * cfreq;
1259 cfg.output_rate <<= 1)
1262 cfg.p = 0x1 << p_div;
1263 cfg.m = input_rate / cfreq;
1264 cfg.n =
cfg.output_rate / cfreq;
1268 div = sel->
m * sel->
p;
1271 output_rate += div - 1;
1272 do_div(output_rate, div);
1277 static unsigned long tegra30_pll_recalc_rate(
struct clk_hw *hw,
1278 unsigned long parent_rate)
1281 u64 rate = parent_rate;
1290 c->
div = sel->
m * sel->
p;
1294 pr_err(
"Clock %s has unknown fixed frequency\n",
1310 if (c->
mul != 0 && c->
div != 0) {
1320 .is_enabled = tegra30_pll_clk_is_enabled,
1321 .init = tegra30_pll_clk_init,
1322 .enable = tegra30_pll_clk_enable,
1323 .disable = tegra30_pll_clk_disable,
1324 .recalc_rate = tegra30_pll_recalc_rate,
1325 .round_rate = tegra30_pll_round_rate,
1326 .set_rate = tegra30_pll_clk_set_rate,
1364 static int tegra30_plle_clk_is_enabled(
struct clk_hw *hw)
1374 static void tegra30_plle_clk_disable(
struct clk_hw *hw)
1384 static void tegra30_plle_training(
struct clk_tegra *c)
1407 static int tegra30_plle_configure(
struct clk_hw *hw,
bool force_training)
1414 unsigned long rate = c->
u.
pll.fixed_rate;
1426 tegra30_plle_clk_disable(hw);
1435 tegra30_plle_training(c);
1443 c->
div = sel->
m * sel->
p;
1464 static int tegra30_plle_clk_enable(
struct clk_hw *hw)
1468 return tegra30_plle_configure(hw, !c->
set);
1471 static unsigned long tegra30_plle_clk_recalc_rate(
struct clk_hw *hw,
1472 unsigned long parent_rate)
1475 unsigned long rate = parent_rate;
1483 if (c->
mul != 0 && c->
div != 0) {
1492 .is_enabled = tegra30_plle_clk_is_enabled,
1493 .enable = tegra30_plle_clk_enable,
1494 .disable = tegra30_plle_clk_disable,
1495 .recalc_rate = tegra30_plle_clk_recalc_rate,
1499 static int tegra30_pll_div_clk_is_enabled(
struct clk_hw *hw)
1515 static int tegra30_pll_div_clk_enable(
struct clk_hw *hw)
1539 static void tegra30_pll_div_clk_disable(
struct clk_hw *hw)
1559 static int tegra30_pll_div_clk_set_rate(
struct clk_hw *hw,
unsigned long rate,
1560 unsigned long parent_rate)
1568 divider_u71 = clk_div71_get_divider(
1570 if (divider_u71 >= 0) {
1582 c->
div = divider_u71 + 2;
1595 static unsigned long tegra30_pll_div_clk_recalc_rate(
struct clk_hw *hw,
1596 unsigned long parent_rate)
1599 u64 rate = parent_rate;
1607 c->
div = (divu71 + 2);
1619 if (c->
mul != 0 && c->
div != 0) {
1628 static long tegra30_pll_div_clk_round_rate(
struct clk_hw *hw,
1629 unsigned long rate,
unsigned long *prate)
1636 parent_rate = *
prate;
1639 divider = clk_div71_get_divider(
1653 .is_enabled = tegra30_pll_div_clk_is_enabled,
1654 .enable = tegra30_pll_div_clk_enable,
1655 .disable = tegra30_pll_div_clk_disable,
1656 .set_rate = tegra30_pll_div_clk_set_rate,
1657 .recalc_rate = tegra30_pll_div_clk_recalc_rate,
1658 .round_rate = tegra30_pll_div_clk_round_rate,
1662 static inline u32 periph_clk_source_mask(
struct clk_tegra *c)
1669 return 3 << (c->
u.
periph.clk_num + 4);
1676 static inline u32 periph_clk_source_shift(
struct clk_tegra *c)
1683 return c->
u.
periph.clk_num + 4;
1690 static int tegra30_periph_clk_is_enabled(
struct clk_hw *hw)
1703 static int tegra30_periph_clk_enable(
struct clk_hw *hw)
1707 tegra_periph_clk_enable_refcount[c->
u.
periph.clk_num]++;
1708 if (tegra_periph_clk_enable_refcount[c->
u.
periph.clk_num] > 1)
1724 static void tegra30_periph_clk_disable(
struct clk_hw *hw)
1729 tegra_periph_clk_enable_refcount[c->
u.
periph.clk_num]--;
1731 if (tegra_periph_clk_enable_refcount[c->
u.
periph.clk_num] > 0)
1765 static int tegra30_periph_clk_set_parent(
struct clk_hw *hw,
u8 index)
1771 return (index == 0) ? 0 : (-
EINVAL);
1774 val &= ~periph_clk_source_mask(c);
1775 val |= (index << periph_clk_source_shift(c));
1780 static u8 tegra30_periph_clk_get_parent(
struct clk_hw *hw)
1784 int source = (val & periph_clk_source_mask(c)) >>
1785 periph_clk_source_shift(c);
1793 static int tegra30_periph_clk_set_rate(
struct clk_hw *hw,
unsigned long rate,
1794 unsigned long parent_rate)
1801 divider = clk_div71_get_divider(
1814 c->
div = divider + 2;
1819 divider = clk_div16_get_divider(parent_rate, rate);
1825 c->
div = divider + 1;
1829 }
else if (parent_rate <= rate) {
1837 static long tegra30_periph_clk_round_rate(
struct clk_hw *hw,
unsigned long rate,
1838 unsigned long *prate)
1845 parent_rate = *
prate;
1848 divider = clk_div71_get_divider(
1855 divider = clk_div16_get_divider(parent_rate, rate);
1863 static unsigned long tegra30_periph_clk_recalc_rate(
struct clk_hw *hw,
1864 unsigned long parent_rate)
1867 u64 rate = parent_rate;
1877 val &= ~(PERIPH_CLK_SOURCE_DIVU71_MASK <<
1883 c->
div = divu71 + 2;
1887 c->
div = divu16 + 1;
1894 if (c->
mul != 0 && c->
div != 0) {
1903 .is_enabled = tegra30_periph_clk_is_enabled,
1904 .enable = tegra30_periph_clk_enable,
1905 .disable = tegra30_periph_clk_disable,
1906 .set_parent = tegra30_periph_clk_set_parent,
1907 .get_parent = tegra30_periph_clk_get_parent,
1908 .set_rate = tegra30_periph_clk_set_rate,
1909 .round_rate = tegra30_periph_clk_round_rate,
1910 .recalc_rate = tegra30_periph_clk_recalc_rate,
1913 static int tegra30_dsib_clk_set_parent(
struct clk_hw *hw,
u8 index)
1926 .is_enabled = tegra30_periph_clk_is_enabled,
1927 .enable = &tegra30_periph_clk_enable,
1928 .disable = &tegra30_periph_clk_disable,
1929 .set_parent = &tegra30_dsib_clk_set_parent,
1930 .get_parent = &tegra30_periph_clk_get_parent,
1931 .set_rate = &tegra30_periph_clk_set_rate,
1932 .round_rate = &tegra30_periph_clk_round_rate,
1933 .recalc_rate = &tegra30_periph_clk_recalc_rate,
1991 static int tegra30_clk_out_is_enabled(
struct clk_hw *hw)
2002 static int tegra30_clk_out_enable(
struct clk_hw *hw)
2006 unsigned long flags;
2010 val |= (0x1 << c->
u.
periph.clk_num);
2012 spin_unlock_irqrestore(&clk_out_lock, flags);
2017 static void tegra30_clk_out_disable(
struct clk_hw *hw)
2021 unsigned long flags;
2025 val &= ~(0x1 << c->
u.
periph.clk_num);
2027 spin_unlock_irqrestore(&clk_out_lock, flags);
2030 static int tegra30_clk_out_set_parent(
struct clk_hw *hw,
u8 index)
2034 unsigned long flags;
2038 val &= ~periph_clk_source_mask(c);
2039 val |= (index << periph_clk_source_shift(c));
2041 spin_unlock_irqrestore(&clk_out_lock, flags);
2046 static u8 tegra30_clk_out_get_parent(
struct clk_hw *hw)
2052 source = (val & periph_clk_source_mask(c)) >>
2053 periph_clk_source_shift(c);
2058 .is_enabled = tegra30_clk_out_is_enabled,
2059 .enable = tegra30_clk_out_enable,
2060 .disable = tegra30_clk_out_disable,
2061 .set_parent = tegra30_clk_out_set_parent,
2062 .get_parent = tegra30_clk_out_get_parent,
2063 .recalc_rate = tegra30_clk_fixed_recalc_rate,
2067 static int tegra30_clk_double_is_enabled(
struct clk_hw *hw)
2077 static int tegra30_clk_double_set_rate(
struct clk_hw *hw,
unsigned long rate,
2078 unsigned long parent_rate)
2083 if (rate == parent_rate) {
2089 }
else if (rate == 2 * parent_rate) {
2099 static unsigned long tegra30_clk_double_recalc_rate(
struct clk_hw *hw,
2100 unsigned long parent_rate)
2103 u64 rate = parent_rate;
2109 if (c->
mul != 0 && c->
div != 0) {
2118 static long tegra30_clk_double_round_rate(
struct clk_hw *hw,
unsigned long rate,
2119 unsigned long *prate)
2121 unsigned long output_rate = *
prate;
2128 .is_enabled = tegra30_clk_double_is_enabled,
2129 .enable = tegra30_periph_clk_enable,
2130 .disable = tegra30_periph_clk_disable,
2131 .recalc_rate = tegra30_clk_double_recalc_rate,
2132 .round_rate = tegra30_clk_double_round_rate,
2133 .set_rate = tegra30_clk_double_set_rate,
2138 .recalc_rate = tegra30_clk_fixed_recalc_rate,
2141 static int tegra30_audio_sync_clk_is_enabled(
struct clk_hw *hw)
2149 static int tegra30_audio_sync_clk_enable(
struct clk_hw *hw)
2157 static void tegra30_audio_sync_clk_disable(
struct clk_hw *hw)
2164 static int tegra30_audio_sync_clk_set_parent(
struct clk_hw *hw,
u8 index)
2177 static u8 tegra30_audio_sync_clk_get_parent(
struct clk_hw *hw)
2188 .is_enabled = tegra30_audio_sync_clk_is_enabled,
2189 .enable = tegra30_audio_sync_clk_enable,
2190 .disable = tegra30_audio_sync_clk_disable,
2191 .set_parent = tegra30_audio_sync_clk_set_parent,
2192 .get_parent = tegra30_audio_sync_clk_get_parent,
2193 .recalc_rate = tegra30_clk_fixed_recalc_rate,
2197 static int tegra30_cml_clk_is_enabled(
struct clk_hw *hw)
2205 static int tegra30_cml_clk_enable(
struct clk_hw *hw)
2210 val |= (0x1 << c->
u.
periph.clk_num);
2216 static void tegra30_cml_clk_disable(
struct clk_hw *hw)
2221 val &= ~(0x1 << c->
u.
periph.clk_num);
2226 .is_enabled = tegra30_cml_clk_is_enabled,
2227 .enable = tegra30_cml_clk_enable,
2228 .disable = tegra30_cml_clk_disable,
2229 .recalc_rate = tegra30_clk_fixed_recalc_rate,
2233 .recalc_rate = tegra30_clk_fixed_recalc_rate,
2237 static void tegra30_wait_cpu_in_reset(
u32 cpu)
2242 reg =
readl(reg_clk_base +
2245 }
while (!(reg & (1 << cpu)));
2250 static void tegra30_put_cpu_in_reset(
u32 cpu)
2257 static void tegra30_cpu_out_of_reset(
u32 cpu)
2264 static void tegra30_enable_cpu_clock(
u32 cpu)
2270 reg =
readl(reg_clk_base +
2274 static void tegra30_disable_cpu_clock(
u32 cpu)
2285 .wait_for_reset = tegra30_wait_cpu_in_reset,
2286 .put_in_reset = tegra30_put_cpu_in_reset,
2287 .out_of_reset = tegra30_cpu_out_of_reset,
2288 .enable_clock = tegra30_enable_cpu_clock,
2289 .disable_clock = tegra30_disable_cpu_clock,