spi-topcliff-pch: Fix issue for transmitting over 4KByte
[zen-stable.git] / arch / arm / mach-imx / clock-imx6q.c
blob2d88f8b9a454994bee6841cda4828d81286bac5e
1 /*
2 * Copyright 2011 Freescale Semiconductor, Inc.
3 * Copyright 2011 Linaro Ltd.
5 * The code contained herein is licensed under the GNU General Public
6 * License. You may obtain a copy of the GNU General Public License
7 * Version 2 or later at the following locations:
9 * http://www.opensource.org/licenses/gpl-license.html
10 * http://www.gnu.org/copyleft/gpl.html
13 #include <linux/init.h>
14 #include <linux/types.h>
15 #include <linux/clk.h>
16 #include <linux/clkdev.h>
17 #include <linux/io.h>
18 #include <linux/of.h>
19 #include <linux/of_address.h>
20 #include <linux/of_irq.h>
21 #include <asm/div64.h>
22 #include <asm/mach/map.h>
23 #include <mach/clock.h>
24 #include <mach/common.h>
25 #include <mach/hardware.h>
27 #define PLL_BASE IMX_IO_ADDRESS(MX6Q_ANATOP_BASE_ADDR)
28 #define PLL1_SYS (PLL_BASE + 0x000)
29 #define PLL2_BUS (PLL_BASE + 0x030)
30 #define PLL3_USB_OTG (PLL_BASE + 0x010)
31 #define PLL4_AUDIO (PLL_BASE + 0x070)
32 #define PLL5_VIDEO (PLL_BASE + 0x0a0)
33 #define PLL6_MLB (PLL_BASE + 0x0d0)
34 #define PLL7_USB_HOST (PLL_BASE + 0x020)
35 #define PLL8_ENET (PLL_BASE + 0x0e0)
36 #define PFD_480 (PLL_BASE + 0x0f0)
37 #define PFD_528 (PLL_BASE + 0x100)
38 #define PLL_NUM_OFFSET 0x010
39 #define PLL_DENOM_OFFSET 0x020
41 #define PFD0 7
42 #define PFD1 15
43 #define PFD2 23
44 #define PFD3 31
45 #define PFD_FRAC_MASK 0x3f
47 #define BM_PLL_BYPASS (0x1 << 16)
48 #define BM_PLL_ENABLE (0x1 << 13)
49 #define BM_PLL_POWER_DOWN (0x1 << 12)
50 #define BM_PLL_LOCK (0x1 << 31)
51 #define BP_PLL_SYS_DIV_SELECT 0
52 #define BM_PLL_SYS_DIV_SELECT (0x7f << 0)
53 #define BP_PLL_BUS_DIV_SELECT 0
54 #define BM_PLL_BUS_DIV_SELECT (0x1 << 0)
55 #define BP_PLL_USB_DIV_SELECT 0
56 #define BM_PLL_USB_DIV_SELECT (0x3 << 0)
57 #define BP_PLL_AV_DIV_SELECT 0
58 #define BM_PLL_AV_DIV_SELECT (0x7f << 0)
59 #define BP_PLL_ENET_DIV_SELECT 0
60 #define BM_PLL_ENET_DIV_SELECT (0x3 << 0)
61 #define BM_PLL_ENET_EN_PCIE (0x1 << 19)
62 #define BM_PLL_ENET_EN_SATA (0x1 << 20)
64 #define CCM_BASE IMX_IO_ADDRESS(MX6Q_CCM_BASE_ADDR)
65 #define CCR (CCM_BASE + 0x00)
66 #define CCDR (CCM_BASE + 0x04)
67 #define CSR (CCM_BASE + 0x08)
68 #define CCSR (CCM_BASE + 0x0c)
69 #define CACRR (CCM_BASE + 0x10)
70 #define CBCDR (CCM_BASE + 0x14)
71 #define CBCMR (CCM_BASE + 0x18)
72 #define CSCMR1 (CCM_BASE + 0x1c)
73 #define CSCMR2 (CCM_BASE + 0x20)
74 #define CSCDR1 (CCM_BASE + 0x24)
75 #define CS1CDR (CCM_BASE + 0x28)
76 #define CS2CDR (CCM_BASE + 0x2c)
77 #define CDCDR (CCM_BASE + 0x30)
78 #define CHSCCDR (CCM_BASE + 0x34)
79 #define CSCDR2 (CCM_BASE + 0x38)
80 #define CSCDR3 (CCM_BASE + 0x3c)
81 #define CSCDR4 (CCM_BASE + 0x40)
82 #define CWDR (CCM_BASE + 0x44)
83 #define CDHIPR (CCM_BASE + 0x48)
84 #define CDCR (CCM_BASE + 0x4c)
85 #define CTOR (CCM_BASE + 0x50)
86 #define CLPCR (CCM_BASE + 0x54)
87 #define CISR (CCM_BASE + 0x58)
88 #define CIMR (CCM_BASE + 0x5c)
89 #define CCOSR (CCM_BASE + 0x60)
90 #define CGPR (CCM_BASE + 0x64)
91 #define CCGR0 (CCM_BASE + 0x68)
92 #define CCGR1 (CCM_BASE + 0x6c)
93 #define CCGR2 (CCM_BASE + 0x70)
94 #define CCGR3 (CCM_BASE + 0x74)
95 #define CCGR4 (CCM_BASE + 0x78)
96 #define CCGR5 (CCM_BASE + 0x7c)
97 #define CCGR6 (CCM_BASE + 0x80)
98 #define CCGR7 (CCM_BASE + 0x84)
99 #define CMEOR (CCM_BASE + 0x88)
101 #define CG0 0
102 #define CG1 2
103 #define CG2 4
104 #define CG3 6
105 #define CG4 8
106 #define CG5 10
107 #define CG6 12
108 #define CG7 14
109 #define CG8 16
110 #define CG9 18
111 #define CG10 20
112 #define CG11 22
113 #define CG12 24
114 #define CG13 26
115 #define CG14 28
116 #define CG15 30
118 #define BM_CCSR_PLL1_SW_SEL (0x1 << 2)
119 #define BM_CCSR_STEP_SEL (0x1 << 8)
121 #define BP_CACRR_ARM_PODF 0
122 #define BM_CACRR_ARM_PODF (0x7 << 0)
124 #define BP_CBCDR_PERIPH2_CLK2_PODF 0
125 #define BM_CBCDR_PERIPH2_CLK2_PODF (0x7 << 0)
126 #define BP_CBCDR_MMDC_CH1_AXI_PODF 3
127 #define BM_CBCDR_MMDC_CH1_AXI_PODF (0x7 << 3)
128 #define BP_CBCDR_AXI_SEL 6
129 #define BM_CBCDR_AXI_SEL (0x3 << 6)
130 #define BP_CBCDR_IPG_PODF 8
131 #define BM_CBCDR_IPG_PODF (0x3 << 8)
132 #define BP_CBCDR_AHB_PODF 10
133 #define BM_CBCDR_AHB_PODF (0x7 << 10)
134 #define BP_CBCDR_AXI_PODF 16
135 #define BM_CBCDR_AXI_PODF (0x7 << 16)
136 #define BP_CBCDR_MMDC_CH0_AXI_PODF 19
137 #define BM_CBCDR_MMDC_CH0_AXI_PODF (0x7 << 19)
138 #define BP_CBCDR_PERIPH_CLK_SEL 25
139 #define BM_CBCDR_PERIPH_CLK_SEL (0x1 << 25)
140 #define BP_CBCDR_PERIPH2_CLK_SEL 26
141 #define BM_CBCDR_PERIPH2_CLK_SEL (0x1 << 26)
142 #define BP_CBCDR_PERIPH_CLK2_PODF 27
143 #define BM_CBCDR_PERIPH_CLK2_PODF (0x7 << 27)
145 #define BP_CBCMR_GPU2D_AXI_SEL 0
146 #define BM_CBCMR_GPU2D_AXI_SEL (0x1 << 0)
147 #define BP_CBCMR_GPU3D_AXI_SEL 1
148 #define BM_CBCMR_GPU3D_AXI_SEL (0x1 << 1)
149 #define BP_CBCMR_GPU3D_CORE_SEL 4
150 #define BM_CBCMR_GPU3D_CORE_SEL (0x3 << 4)
151 #define BP_CBCMR_GPU3D_SHADER_SEL 8
152 #define BM_CBCMR_GPU3D_SHADER_SEL (0x3 << 8)
153 #define BP_CBCMR_PCIE_AXI_SEL 10
154 #define BM_CBCMR_PCIE_AXI_SEL (0x1 << 10)
155 #define BP_CBCMR_VDO_AXI_SEL 11
156 #define BM_CBCMR_VDO_AXI_SEL (0x1 << 11)
157 #define BP_CBCMR_PERIPH_CLK2_SEL 12
158 #define BM_CBCMR_PERIPH_CLK2_SEL (0x3 << 12)
159 #define BP_CBCMR_VPU_AXI_SEL 14
160 #define BM_CBCMR_VPU_AXI_SEL (0x3 << 14)
161 #define BP_CBCMR_GPU2D_CORE_SEL 16
162 #define BM_CBCMR_GPU2D_CORE_SEL (0x3 << 16)
163 #define BP_CBCMR_PRE_PERIPH_CLK_SEL 18
164 #define BM_CBCMR_PRE_PERIPH_CLK_SEL (0x3 << 18)
165 #define BP_CBCMR_PERIPH2_CLK2_SEL 20
166 #define BM_CBCMR_PERIPH2_CLK2_SEL (0x1 << 20)
167 #define BP_CBCMR_PRE_PERIPH2_CLK_SEL 21
168 #define BM_CBCMR_PRE_PERIPH2_CLK_SEL (0x3 << 21)
169 #define BP_CBCMR_GPU2D_CORE_PODF 23
170 #define BM_CBCMR_GPU2D_CORE_PODF (0x7 << 23)
171 #define BP_CBCMR_GPU3D_CORE_PODF 26
172 #define BM_CBCMR_GPU3D_CORE_PODF (0x7 << 26)
173 #define BP_CBCMR_GPU3D_SHADER_PODF 29
174 #define BM_CBCMR_GPU3D_SHADER_PODF (0x7 << 29)
176 #define BP_CSCMR1_PERCLK_PODF 0
177 #define BM_CSCMR1_PERCLK_PODF (0x3f << 0)
178 #define BP_CSCMR1_SSI1_SEL 10
179 #define BM_CSCMR1_SSI1_SEL (0x3 << 10)
180 #define BP_CSCMR1_SSI2_SEL 12
181 #define BM_CSCMR1_SSI2_SEL (0x3 << 12)
182 #define BP_CSCMR1_SSI3_SEL 14
183 #define BM_CSCMR1_SSI3_SEL (0x3 << 14)
184 #define BP_CSCMR1_USDHC1_SEL 16
185 #define BM_CSCMR1_USDHC1_SEL (0x1 << 16)
186 #define BP_CSCMR1_USDHC2_SEL 17
187 #define BM_CSCMR1_USDHC2_SEL (0x1 << 17)
188 #define BP_CSCMR1_USDHC3_SEL 18
189 #define BM_CSCMR1_USDHC3_SEL (0x1 << 18)
190 #define BP_CSCMR1_USDHC4_SEL 19
191 #define BM_CSCMR1_USDHC4_SEL (0x1 << 19)
192 #define BP_CSCMR1_EMI_PODF 20
193 #define BM_CSCMR1_EMI_PODF (0x7 << 20)
194 #define BP_CSCMR1_EMI_SLOW_PODF 23
195 #define BM_CSCMR1_EMI_SLOW_PODF (0x7 << 23)
196 #define BP_CSCMR1_EMI_SEL 27
197 #define BM_CSCMR1_EMI_SEL (0x3 << 27)
198 #define BP_CSCMR1_EMI_SLOW_SEL 29
199 #define BM_CSCMR1_EMI_SLOW_SEL (0x3 << 29)
201 #define BP_CSCMR2_CAN_PODF 2
202 #define BM_CSCMR2_CAN_PODF (0x3f << 2)
203 #define BM_CSCMR2_LDB_DI0_IPU_DIV (0x1 << 10)
204 #define BM_CSCMR2_LDB_DI1_IPU_DIV (0x1 << 11)
205 #define BP_CSCMR2_ESAI_SEL 19
206 #define BM_CSCMR2_ESAI_SEL (0x3 << 19)
208 #define BP_CSCDR1_UART_PODF 0
209 #define BM_CSCDR1_UART_PODF (0x3f << 0)
210 #define BP_CSCDR1_USDHC1_PODF 11
211 #define BM_CSCDR1_USDHC1_PODF (0x7 << 11)
212 #define BP_CSCDR1_USDHC2_PODF 16
213 #define BM_CSCDR1_USDHC2_PODF (0x7 << 16)
214 #define BP_CSCDR1_USDHC3_PODF 19
215 #define BM_CSCDR1_USDHC3_PODF (0x7 << 19)
216 #define BP_CSCDR1_USDHC4_PODF 22
217 #define BM_CSCDR1_USDHC4_PODF (0x7 << 22)
218 #define BP_CSCDR1_VPU_AXI_PODF 25
219 #define BM_CSCDR1_VPU_AXI_PODF (0x7 << 25)
221 #define BP_CS1CDR_SSI1_PODF 0
222 #define BM_CS1CDR_SSI1_PODF (0x3f << 0)
223 #define BP_CS1CDR_SSI1_PRED 6
224 #define BM_CS1CDR_SSI1_PRED (0x7 << 6)
225 #define BP_CS1CDR_ESAI_PRED 9
226 #define BM_CS1CDR_ESAI_PRED (0x7 << 9)
227 #define BP_CS1CDR_SSI3_PODF 16
228 #define BM_CS1CDR_SSI3_PODF (0x3f << 16)
229 #define BP_CS1CDR_SSI3_PRED 22
230 #define BM_CS1CDR_SSI3_PRED (0x7 << 22)
231 #define BP_CS1CDR_ESAI_PODF 25
232 #define BM_CS1CDR_ESAI_PODF (0x7 << 25)
234 #define BP_CS2CDR_SSI2_PODF 0
235 #define BM_CS2CDR_SSI2_PODF (0x3f << 0)
236 #define BP_CS2CDR_SSI2_PRED 6
237 #define BM_CS2CDR_SSI2_PRED (0x7 << 6)
238 #define BP_CS2CDR_LDB_DI0_SEL 9
239 #define BM_CS2CDR_LDB_DI0_SEL (0x7 << 9)
240 #define BP_CS2CDR_LDB_DI1_SEL 12
241 #define BM_CS2CDR_LDB_DI1_SEL (0x7 << 12)
242 #define BP_CS2CDR_ENFC_SEL 16
243 #define BM_CS2CDR_ENFC_SEL (0x3 << 16)
244 #define BP_CS2CDR_ENFC_PRED 18
245 #define BM_CS2CDR_ENFC_PRED (0x7 << 18)
246 #define BP_CS2CDR_ENFC_PODF 21
247 #define BM_CS2CDR_ENFC_PODF (0x3f << 21)
249 #define BP_CDCDR_ASRC_SERIAL_SEL 7
250 #define BM_CDCDR_ASRC_SERIAL_SEL (0x3 << 7)
251 #define BP_CDCDR_ASRC_SERIAL_PODF 9
252 #define BM_CDCDR_ASRC_SERIAL_PODF (0x7 << 9)
253 #define BP_CDCDR_ASRC_SERIAL_PRED 12
254 #define BM_CDCDR_ASRC_SERIAL_PRED (0x7 << 12)
255 #define BP_CDCDR_SPDIF_SEL 20
256 #define BM_CDCDR_SPDIF_SEL (0x3 << 20)
257 #define BP_CDCDR_SPDIF_PODF 22
258 #define BM_CDCDR_SPDIF_PODF (0x7 << 22)
259 #define BP_CDCDR_SPDIF_PRED 25
260 #define BM_CDCDR_SPDIF_PRED (0x7 << 25)
261 #define BP_CDCDR_HSI_TX_PODF 29
262 #define BM_CDCDR_HSI_TX_PODF (0x7 << 29)
263 #define BP_CDCDR_HSI_TX_SEL 28
264 #define BM_CDCDR_HSI_TX_SEL (0x1 << 28)
266 #define BP_CHSCCDR_IPU1_DI0_SEL 0
267 #define BM_CHSCCDR_IPU1_DI0_SEL (0x7 << 0)
268 #define BP_CHSCCDR_IPU1_DI0_PRE_PODF 3
269 #define BM_CHSCCDR_IPU1_DI0_PRE_PODF (0x7 << 3)
270 #define BP_CHSCCDR_IPU1_DI0_PRE_SEL 6
271 #define BM_CHSCCDR_IPU1_DI0_PRE_SEL (0x7 << 6)
272 #define BP_CHSCCDR_IPU1_DI1_SEL 9
273 #define BM_CHSCCDR_IPU1_DI1_SEL (0x7 << 9)
274 #define BP_CHSCCDR_IPU1_DI1_PRE_PODF 12
275 #define BM_CHSCCDR_IPU1_DI1_PRE_PODF (0x7 << 12)
276 #define BP_CHSCCDR_IPU1_DI1_PRE_SEL 15
277 #define BM_CHSCCDR_IPU1_DI1_PRE_SEL (0x7 << 15)
279 #define BP_CSCDR2_IPU2_DI0_SEL 0
280 #define BM_CSCDR2_IPU2_DI0_SEL (0x7)
281 #define BP_CSCDR2_IPU2_DI0_PRE_PODF 3
282 #define BM_CSCDR2_IPU2_DI0_PRE_PODF (0x7 << 3)
283 #define BP_CSCDR2_IPU2_DI0_PRE_SEL 6
284 #define BM_CSCDR2_IPU2_DI0_PRE_SEL (0x7 << 6)
285 #define BP_CSCDR2_IPU2_DI1_SEL 9
286 #define BM_CSCDR2_IPU2_DI1_SEL (0x7 << 9)
287 #define BP_CSCDR2_IPU2_DI1_PRE_PODF 12
288 #define BM_CSCDR2_IPU2_DI1_PRE_PODF (0x7 << 12)
289 #define BP_CSCDR2_IPU2_DI1_PRE_SEL 15
290 #define BM_CSCDR2_IPU2_DI1_PRE_SEL (0x7 << 15)
291 #define BP_CSCDR2_ECSPI_CLK_PODF 19
292 #define BM_CSCDR2_ECSPI_CLK_PODF (0x3f << 19)
294 #define BP_CSCDR3_IPU1_HSP_SEL 9
295 #define BM_CSCDR3_IPU1_HSP_SEL (0x3 << 9)
296 #define BP_CSCDR3_IPU1_HSP_PODF 11
297 #define BM_CSCDR3_IPU1_HSP_PODF (0x7 << 11)
298 #define BP_CSCDR3_IPU2_HSP_SEL 14
299 #define BM_CSCDR3_IPU2_HSP_SEL (0x3 << 14)
300 #define BP_CSCDR3_IPU2_HSP_PODF 16
301 #define BM_CSCDR3_IPU2_HSP_PODF (0x7 << 16)
303 #define BM_CDHIPR_AXI_PODF_BUSY (0x1 << 0)
304 #define BM_CDHIPR_AHB_PODF_BUSY (0x1 << 1)
305 #define BM_CDHIPR_MMDC_CH1_PODF_BUSY (0x1 << 2)
306 #define BM_CDHIPR_PERIPH2_SEL_BUSY (0x1 << 3)
307 #define BM_CDHIPR_MMDC_CH0_PODF_BUSY (0x1 << 4)
308 #define BM_CDHIPR_PERIPH_SEL_BUSY (0x1 << 5)
309 #define BM_CDHIPR_ARM_PODF_BUSY (0x1 << 16)
311 #define BP_CLPCR_LPM 0
312 #define BM_CLPCR_LPM (0x3 << 0)
313 #define BM_CLPCR_BYPASS_PMIC_READY (0x1 << 2)
314 #define BM_CLPCR_ARM_CLK_DIS_ON_LPM (0x1 << 5)
315 #define BM_CLPCR_SBYOS (0x1 << 6)
316 #define BM_CLPCR_DIS_REF_OSC (0x1 << 7)
317 #define BM_CLPCR_VSTBY (0x1 << 8)
318 #define BP_CLPCR_STBY_COUNT 9
319 #define BM_CLPCR_STBY_COUNT (0x3 << 9)
320 #define BM_CLPCR_COSC_PWRDOWN (0x1 << 11)
321 #define BM_CLPCR_WB_PER_AT_LPM (0x1 << 16)
322 #define BM_CLPCR_WB_CORE_AT_LPM (0x1 << 17)
323 #define BM_CLPCR_BYP_MMDC_CH0_LPM_HS (0x1 << 19)
324 #define BM_CLPCR_BYP_MMDC_CH1_LPM_HS (0x1 << 21)
325 #define BM_CLPCR_MASK_CORE0_WFI (0x1 << 22)
326 #define BM_CLPCR_MASK_CORE1_WFI (0x1 << 23)
327 #define BM_CLPCR_MASK_CORE2_WFI (0x1 << 24)
328 #define BM_CLPCR_MASK_CORE3_WFI (0x1 << 25)
329 #define BM_CLPCR_MASK_SCU_IDLE (0x1 << 26)
330 #define BM_CLPCR_MASK_L2CC_IDLE (0x1 << 27)
332 #define FREQ_480M 480000000
333 #define FREQ_528M 528000000
334 #define FREQ_594M 594000000
335 #define FREQ_650M 650000000
336 #define FREQ_1300M 1300000000
338 static struct clk pll1_sys;
339 static struct clk pll2_bus;
340 static struct clk pll3_usb_otg;
341 static struct clk pll4_audio;
342 static struct clk pll5_video;
343 static struct clk pll6_mlb;
344 static struct clk pll7_usb_host;
345 static struct clk pll8_enet;
346 static struct clk apbh_dma_clk;
347 static struct clk arm_clk;
348 static struct clk ipg_clk;
349 static struct clk ahb_clk;
350 static struct clk axi_clk;
351 static struct clk mmdc_ch0_axi_clk;
352 static struct clk mmdc_ch1_axi_clk;
353 static struct clk periph_clk;
354 static struct clk periph_pre_clk;
355 static struct clk periph_clk2_clk;
356 static struct clk periph2_clk;
357 static struct clk periph2_pre_clk;
358 static struct clk periph2_clk2_clk;
359 static struct clk gpu2d_core_clk;
360 static struct clk gpu3d_core_clk;
361 static struct clk gpu3d_shader_clk;
362 static struct clk ipg_perclk;
363 static struct clk emi_clk;
364 static struct clk emi_slow_clk;
365 static struct clk can1_clk;
366 static struct clk uart_clk;
367 static struct clk usdhc1_clk;
368 static struct clk usdhc2_clk;
369 static struct clk usdhc3_clk;
370 static struct clk usdhc4_clk;
371 static struct clk vpu_clk;
372 static struct clk hsi_tx_clk;
373 static struct clk ipu1_di0_pre_clk;
374 static struct clk ipu1_di1_pre_clk;
375 static struct clk ipu2_di0_pre_clk;
376 static struct clk ipu2_di1_pre_clk;
377 static struct clk ipu1_clk;
378 static struct clk ipu2_clk;
379 static struct clk ssi1_clk;
380 static struct clk ssi3_clk;
381 static struct clk esai_clk;
382 static struct clk ssi2_clk;
383 static struct clk spdif_clk;
384 static struct clk asrc_serial_clk;
385 static struct clk gpu2d_axi_clk;
386 static struct clk gpu3d_axi_clk;
387 static struct clk pcie_clk;
388 static struct clk vdo_axi_clk;
389 static struct clk ldb_di0_clk;
390 static struct clk ldb_di1_clk;
391 static struct clk ipu1_di0_clk;
392 static struct clk ipu1_di1_clk;
393 static struct clk ipu2_di0_clk;
394 static struct clk ipu2_di1_clk;
395 static struct clk enfc_clk;
396 static struct clk dummy_clk = {};
398 static unsigned long external_high_reference;
399 static unsigned long external_low_reference;
400 static unsigned long oscillator_reference;
402 static unsigned long get_oscillator_reference_clock_rate(struct clk *clk)
404 return oscillator_reference;
407 static unsigned long get_high_reference_clock_rate(struct clk *clk)
409 return external_high_reference;
412 static unsigned long get_low_reference_clock_rate(struct clk *clk)
414 return external_low_reference;
417 static struct clk ckil_clk = {
418 .get_rate = get_low_reference_clock_rate,
421 static struct clk ckih_clk = {
422 .get_rate = get_high_reference_clock_rate,
425 static struct clk osc_clk = {
426 .get_rate = get_oscillator_reference_clock_rate,
429 static inline void __iomem *pll_get_reg_addr(struct clk *pll)
431 if (pll == &pll1_sys)
432 return PLL1_SYS;
433 else if (pll == &pll2_bus)
434 return PLL2_BUS;
435 else if (pll == &pll3_usb_otg)
436 return PLL3_USB_OTG;
437 else if (pll == &pll4_audio)
438 return PLL4_AUDIO;
439 else if (pll == &pll5_video)
440 return PLL5_VIDEO;
441 else if (pll == &pll6_mlb)
442 return PLL6_MLB;
443 else if (pll == &pll7_usb_host)
444 return PLL7_USB_HOST;
445 else if (pll == &pll8_enet)
446 return PLL8_ENET;
447 else
448 BUG();
450 return NULL;
453 static int pll_enable(struct clk *clk)
455 int timeout = 0x100000;
456 void __iomem *reg;
457 u32 val;
459 reg = pll_get_reg_addr(clk);
460 val = readl_relaxed(reg);
461 val &= ~BM_PLL_BYPASS;
462 val &= ~BM_PLL_POWER_DOWN;
463 /* 480MHz PLLs have the opposite definition for power bit */
464 if (clk == &pll3_usb_otg || clk == &pll7_usb_host)
465 val |= BM_PLL_POWER_DOWN;
466 writel_relaxed(val, reg);
468 /* Wait for PLL to lock */
469 while (!(readl_relaxed(reg) & BM_PLL_LOCK) && --timeout)
470 cpu_relax();
472 if (unlikely(!timeout))
473 return -EBUSY;
475 /* Enable the PLL output now */
476 val = readl_relaxed(reg);
477 val |= BM_PLL_ENABLE;
478 writel_relaxed(val, reg);
480 return 0;
483 static void pll_disable(struct clk *clk)
485 void __iomem *reg;
486 u32 val;
488 reg = pll_get_reg_addr(clk);
489 val = readl_relaxed(reg);
490 val &= ~BM_PLL_ENABLE;
491 val |= BM_PLL_BYPASS;
492 val |= BM_PLL_POWER_DOWN;
493 if (clk == &pll3_usb_otg || clk == &pll7_usb_host)
494 val &= ~BM_PLL_POWER_DOWN;
495 writel_relaxed(val, reg);
498 static unsigned long pll1_sys_get_rate(struct clk *clk)
500 u32 div = (readl_relaxed(PLL1_SYS) & BM_PLL_SYS_DIV_SELECT) >>
501 BP_PLL_SYS_DIV_SELECT;
503 return clk_get_rate(clk->parent) * div / 2;
506 static int pll1_sys_set_rate(struct clk *clk, unsigned long rate)
508 u32 val, div;
510 if (rate < FREQ_650M || rate > FREQ_1300M)
511 return -EINVAL;
513 div = rate * 2 / clk_get_rate(clk->parent);
514 val = readl_relaxed(PLL1_SYS);
515 val &= ~BM_PLL_SYS_DIV_SELECT;
516 val |= div << BP_PLL_SYS_DIV_SELECT;
517 writel_relaxed(val, PLL1_SYS);
519 return 0;
522 static unsigned long pll8_enet_get_rate(struct clk *clk)
524 u32 div = (readl_relaxed(PLL8_ENET) & BM_PLL_ENET_DIV_SELECT) >>
525 BP_PLL_ENET_DIV_SELECT;
527 switch (div) {
528 case 0:
529 return 25000000;
530 case 1:
531 return 50000000;
532 case 2:
533 return 100000000;
534 case 3:
535 return 125000000;
538 return 0;
541 static int pll8_enet_set_rate(struct clk *clk, unsigned long rate)
543 u32 val, div;
545 switch (rate) {
546 case 25000000:
547 div = 0;
548 break;
549 case 50000000:
550 div = 1;
551 break;
552 case 100000000:
553 div = 2;
554 break;
555 case 125000000:
556 div = 3;
557 break;
558 default:
559 return -EINVAL;
562 val = readl_relaxed(PLL8_ENET);
563 val &= ~BM_PLL_ENET_DIV_SELECT;
564 val |= div << BP_PLL_ENET_DIV_SELECT;
565 writel_relaxed(val, PLL8_ENET);
567 return 0;
570 static unsigned long pll_av_get_rate(struct clk *clk)
572 void __iomem *reg = (clk == &pll4_audio) ? PLL4_AUDIO : PLL5_VIDEO;
573 unsigned long parent_rate = clk_get_rate(clk->parent);
574 u32 mfn = readl_relaxed(reg + PLL_NUM_OFFSET);
575 u32 mfd = readl_relaxed(reg + PLL_DENOM_OFFSET);
576 u32 div = (readl_relaxed(reg) & BM_PLL_AV_DIV_SELECT) >>
577 BP_PLL_AV_DIV_SELECT;
579 return (parent_rate * div) + ((parent_rate / mfd) * mfn);
582 static int pll_av_set_rate(struct clk *clk, unsigned long rate)
584 void __iomem *reg = (clk == &pll4_audio) ? PLL4_AUDIO : PLL5_VIDEO;
585 unsigned int parent_rate = clk_get_rate(clk->parent);
586 u32 val, div;
587 u32 mfn, mfd = 1000000;
588 s64 temp64;
590 if (rate < FREQ_650M || rate > FREQ_1300M)
591 return -EINVAL;
593 div = rate / parent_rate;
594 temp64 = (u64) (rate - div * parent_rate);
595 temp64 *= mfd;
596 do_div(temp64, parent_rate);
597 mfn = temp64;
599 val = readl_relaxed(reg);
600 val &= ~BM_PLL_AV_DIV_SELECT;
601 val |= div << BP_PLL_AV_DIV_SELECT;
602 writel_relaxed(val, reg);
603 writel_relaxed(mfn, reg + PLL_NUM_OFFSET);
604 writel_relaxed(mfd, reg + PLL_DENOM_OFFSET);
606 return 0;
609 static void __iomem *pll_get_div_reg_bit(struct clk *clk, u32 *bp, u32 *bm)
611 void __iomem *reg;
613 if (clk == &pll2_bus) {
614 reg = PLL2_BUS;
615 *bp = BP_PLL_BUS_DIV_SELECT;
616 *bm = BM_PLL_BUS_DIV_SELECT;
617 } else if (clk == &pll3_usb_otg) {
618 reg = PLL3_USB_OTG;
619 *bp = BP_PLL_USB_DIV_SELECT;
620 *bm = BM_PLL_USB_DIV_SELECT;
621 } else if (clk == &pll7_usb_host) {
622 reg = PLL7_USB_HOST;
623 *bp = BP_PLL_USB_DIV_SELECT;
624 *bm = BM_PLL_USB_DIV_SELECT;
625 } else {
626 BUG();
629 return reg;
632 static unsigned long pll_get_rate(struct clk *clk)
634 void __iomem *reg;
635 u32 div, bp, bm;
637 reg = pll_get_div_reg_bit(clk, &bp, &bm);
638 div = (readl_relaxed(reg) & bm) >> bp;
640 return (div == 1) ? clk_get_rate(clk->parent) * 22 :
641 clk_get_rate(clk->parent) * 20;
644 static int pll_set_rate(struct clk *clk, unsigned long rate)
646 void __iomem *reg;
647 u32 val, div, bp, bm;
649 if (rate == FREQ_528M)
650 div = 1;
651 else if (rate == FREQ_480M)
652 div = 0;
653 else
654 return -EINVAL;
656 reg = pll_get_div_reg_bit(clk, &bp, &bm);
657 val = readl_relaxed(reg);
658 val &= ~bm;
659 val |= div << bp;
660 writel_relaxed(val, reg);
662 return 0;
665 #define pll2_bus_get_rate pll_get_rate
666 #define pll2_bus_set_rate pll_set_rate
667 #define pll3_usb_otg_get_rate pll_get_rate
668 #define pll3_usb_otg_set_rate pll_set_rate
669 #define pll7_usb_host_get_rate pll_get_rate
670 #define pll7_usb_host_set_rate pll_set_rate
671 #define pll4_audio_get_rate pll_av_get_rate
672 #define pll4_audio_set_rate pll_av_set_rate
673 #define pll5_video_get_rate pll_av_get_rate
674 #define pll5_video_set_rate pll_av_set_rate
675 #define pll6_mlb_get_rate NULL
676 #define pll6_mlb_set_rate NULL
678 #define DEF_PLL(name) \
679 static struct clk name = { \
680 .enable = pll_enable, \
681 .disable = pll_disable, \
682 .get_rate = name##_get_rate, \
683 .set_rate = name##_set_rate, \
684 .parent = &osc_clk, \
687 DEF_PLL(pll1_sys);
688 DEF_PLL(pll2_bus);
689 DEF_PLL(pll3_usb_otg);
690 DEF_PLL(pll4_audio);
691 DEF_PLL(pll5_video);
692 DEF_PLL(pll6_mlb);
693 DEF_PLL(pll7_usb_host);
694 DEF_PLL(pll8_enet);
696 static unsigned long pfd_get_rate(struct clk *clk)
698 u64 tmp = (u64) clk_get_rate(clk->parent) * 18;
699 u32 frac, bp_frac;
701 if (apbh_dma_clk.usecount == 0)
702 apbh_dma_clk.enable(&apbh_dma_clk);
704 bp_frac = clk->enable_shift - 7;
705 frac = readl_relaxed(clk->enable_reg) >> bp_frac & PFD_FRAC_MASK;
706 do_div(tmp, frac);
708 return tmp;
711 static int pfd_set_rate(struct clk *clk, unsigned long rate)
713 u32 val, frac, bp_frac;
714 u64 tmp = (u64) clk_get_rate(clk->parent) * 18;
716 if (apbh_dma_clk.usecount == 0)
717 apbh_dma_clk.enable(&apbh_dma_clk);
720 * Round up the divider so that we don't set a rate
721 * higher than what is requested
723 tmp += rate / 2;
724 do_div(tmp, rate);
725 frac = tmp;
726 frac = (frac < 12) ? 12 : frac;
727 frac = (frac > 35) ? 35 : frac;
730 * The frac field always starts from 7 bits lower
731 * position of enable bit
733 bp_frac = clk->enable_shift - 7;
734 val = readl_relaxed(clk->enable_reg);
735 val &= ~(PFD_FRAC_MASK << bp_frac);
736 val |= frac << bp_frac;
737 writel_relaxed(val, clk->enable_reg);
739 tmp = (u64) clk_get_rate(clk->parent) * 18;
740 do_div(tmp, frac);
742 if (apbh_dma_clk.usecount == 0)
743 apbh_dma_clk.disable(&apbh_dma_clk);
745 return 0;
748 static unsigned long pfd_round_rate(struct clk *clk, unsigned long rate)
750 u32 frac;
751 u64 tmp;
753 tmp = (u64) clk_get_rate(clk->parent) * 18;
754 tmp += rate / 2;
755 do_div(tmp, rate);
756 frac = tmp;
757 frac = (frac < 12) ? 12 : frac;
758 frac = (frac > 35) ? 35 : frac;
759 tmp = (u64) clk_get_rate(clk->parent) * 18;
760 do_div(tmp, frac);
762 return tmp;
765 static int pfd_enable(struct clk *clk)
767 u32 val;
769 if (apbh_dma_clk.usecount == 0)
770 apbh_dma_clk.enable(&apbh_dma_clk);
772 val = readl_relaxed(clk->enable_reg);
773 val &= ~(1 << clk->enable_shift);
774 writel_relaxed(val, clk->enable_reg);
776 if (apbh_dma_clk.usecount == 0)
777 apbh_dma_clk.disable(&apbh_dma_clk);
779 return 0;
782 static void pfd_disable(struct clk *clk)
784 u32 val;
786 if (apbh_dma_clk.usecount == 0)
787 apbh_dma_clk.enable(&apbh_dma_clk);
789 val = readl_relaxed(clk->enable_reg);
790 val |= 1 << clk->enable_shift;
791 writel_relaxed(val, clk->enable_reg);
793 if (apbh_dma_clk.usecount == 0)
794 apbh_dma_clk.disable(&apbh_dma_clk);
797 #define DEF_PFD(name, er, es, p) \
798 static struct clk name = { \
799 .enable_reg = er, \
800 .enable_shift = es, \
801 .enable = pfd_enable, \
802 .disable = pfd_disable, \
803 .get_rate = pfd_get_rate, \
804 .set_rate = pfd_set_rate, \
805 .round_rate = pfd_round_rate, \
806 .parent = p, \
809 DEF_PFD(pll2_pfd_352m, PFD_528, PFD0, &pll2_bus);
810 DEF_PFD(pll2_pfd_594m, PFD_528, PFD1, &pll2_bus);
811 DEF_PFD(pll2_pfd_400m, PFD_528, PFD2, &pll2_bus);
812 DEF_PFD(pll3_pfd_720m, PFD_480, PFD0, &pll3_usb_otg);
813 DEF_PFD(pll3_pfd_540m, PFD_480, PFD1, &pll3_usb_otg);
814 DEF_PFD(pll3_pfd_508m, PFD_480, PFD2, &pll3_usb_otg);
815 DEF_PFD(pll3_pfd_454m, PFD_480, PFD3, &pll3_usb_otg);
817 static unsigned long twd_clk_get_rate(struct clk *clk)
819 return clk_get_rate(clk->parent) / 2;
822 static struct clk twd_clk = {
823 .parent = &arm_clk,
824 .get_rate = twd_clk_get_rate,
827 static unsigned long pll2_200m_get_rate(struct clk *clk)
829 return clk_get_rate(clk->parent) / 2;
832 static struct clk pll2_200m = {
833 .parent = &pll2_pfd_400m,
834 .get_rate = pll2_200m_get_rate,
837 static unsigned long pll3_120m_get_rate(struct clk *clk)
839 return clk_get_rate(clk->parent) / 4;
842 static struct clk pll3_120m = {
843 .parent = &pll3_usb_otg,
844 .get_rate = pll3_120m_get_rate,
847 static unsigned long pll3_80m_get_rate(struct clk *clk)
849 return clk_get_rate(clk->parent) / 6;
852 static struct clk pll3_80m = {
853 .parent = &pll3_usb_otg,
854 .get_rate = pll3_80m_get_rate,
857 static unsigned long pll3_60m_get_rate(struct clk *clk)
859 return clk_get_rate(clk->parent) / 8;
862 static struct clk pll3_60m = {
863 .parent = &pll3_usb_otg,
864 .get_rate = pll3_60m_get_rate,
867 static int pll1_sw_clk_set_parent(struct clk *clk, struct clk *parent)
869 u32 val = readl_relaxed(CCSR);
871 if (parent == &pll1_sys) {
872 val &= ~BM_CCSR_PLL1_SW_SEL;
873 val &= ~BM_CCSR_STEP_SEL;
874 } else if (parent == &osc_clk) {
875 val |= BM_CCSR_PLL1_SW_SEL;
876 val &= ~BM_CCSR_STEP_SEL;
877 } else if (parent == &pll2_pfd_400m) {
878 val |= BM_CCSR_PLL1_SW_SEL;
879 val |= BM_CCSR_STEP_SEL;
880 } else {
881 return -EINVAL;
884 writel_relaxed(val, CCSR);
886 return 0;
889 static struct clk pll1_sw_clk = {
890 .parent = &pll1_sys,
891 .set_parent = pll1_sw_clk_set_parent,
894 static void calc_pred_podf_dividers(u32 div, u32 *pred, u32 *podf)
896 u32 min_pred, temp_pred, old_err, err;
898 if (div >= 512) {
899 *pred = 8;
900 *podf = 64;
901 } else if (div >= 8) {
902 min_pred = (div - 1) / 64 + 1;
903 old_err = 8;
904 for (temp_pred = 8; temp_pred >= min_pred; temp_pred--) {
905 err = div % temp_pred;
906 if (err == 0) {
907 *pred = temp_pred;
908 break;
910 err = temp_pred - err;
911 if (err < old_err) {
912 old_err = err;
913 *pred = temp_pred;
916 *podf = (div + *pred - 1) / *pred;
917 } else if (div < 8) {
918 *pred = div;
919 *podf = 1;
923 static int _clk_enable(struct clk *clk)
925 u32 reg;
926 reg = readl_relaxed(clk->enable_reg);
927 reg |= 0x3 << clk->enable_shift;
928 writel_relaxed(reg, clk->enable_reg);
930 return 0;
933 static void _clk_disable(struct clk *clk)
935 u32 reg;
936 reg = readl_relaxed(clk->enable_reg);
937 reg &= ~(0x3 << clk->enable_shift);
938 writel_relaxed(reg, clk->enable_reg);
941 struct divider {
942 struct clk *clk;
943 void __iomem *reg;
944 u32 bp_pred;
945 u32 bm_pred;
946 u32 bp_podf;
947 u32 bm_podf;
950 #define DEF_CLK_DIV1(d, c, r, b) \
951 static struct divider d = { \
952 .clk = c, \
953 .reg = r, \
954 .bp_podf = BP_##r##_##b##_PODF, \
955 .bm_podf = BM_##r##_##b##_PODF, \
958 DEF_CLK_DIV1(arm_div, &arm_clk, CACRR, ARM);
959 DEF_CLK_DIV1(ipg_div, &ipg_clk, CBCDR, IPG);
960 DEF_CLK_DIV1(ahb_div, &ahb_clk, CBCDR, AHB);
961 DEF_CLK_DIV1(axi_div, &axi_clk, CBCDR, AXI);
962 DEF_CLK_DIV1(mmdc_ch0_axi_div, &mmdc_ch0_axi_clk, CBCDR, MMDC_CH0_AXI);
963 DEF_CLK_DIV1(mmdc_ch1_axi_div, &mmdc_ch1_axi_clk, CBCDR, MMDC_CH1_AXI);
964 DEF_CLK_DIV1(periph_clk2_div, &periph_clk2_clk, CBCDR, PERIPH_CLK2);
965 DEF_CLK_DIV1(periph2_clk2_div, &periph2_clk2_clk, CBCDR, PERIPH2_CLK2);
966 DEF_CLK_DIV1(gpu2d_core_div, &gpu2d_core_clk, CBCMR, GPU2D_CORE);
967 DEF_CLK_DIV1(gpu3d_core_div, &gpu3d_core_clk, CBCMR, GPU3D_CORE);
968 DEF_CLK_DIV1(gpu3d_shader_div, &gpu3d_shader_clk, CBCMR, GPU3D_SHADER);
969 DEF_CLK_DIV1(ipg_perclk_div, &ipg_perclk, CSCMR1, PERCLK);
970 DEF_CLK_DIV1(emi_div, &emi_clk, CSCMR1, EMI);
971 DEF_CLK_DIV1(emi_slow_div, &emi_slow_clk, CSCMR1, EMI_SLOW);
972 DEF_CLK_DIV1(can_div, &can1_clk, CSCMR2, CAN);
973 DEF_CLK_DIV1(uart_div, &uart_clk, CSCDR1, UART);
974 DEF_CLK_DIV1(usdhc1_div, &usdhc1_clk, CSCDR1, USDHC1);
975 DEF_CLK_DIV1(usdhc2_div, &usdhc2_clk, CSCDR1, USDHC2);
976 DEF_CLK_DIV1(usdhc3_div, &usdhc3_clk, CSCDR1, USDHC3);
977 DEF_CLK_DIV1(usdhc4_div, &usdhc4_clk, CSCDR1, USDHC4);
978 DEF_CLK_DIV1(vpu_div, &vpu_clk, CSCDR1, VPU_AXI);
979 DEF_CLK_DIV1(hsi_tx_div, &hsi_tx_clk, CDCDR, HSI_TX);
980 DEF_CLK_DIV1(ipu1_di0_pre_div, &ipu1_di0_pre_clk, CHSCCDR, IPU1_DI0_PRE);
981 DEF_CLK_DIV1(ipu1_di1_pre_div, &ipu1_di1_pre_clk, CHSCCDR, IPU1_DI1_PRE);
982 DEF_CLK_DIV1(ipu2_di0_pre_div, &ipu2_di0_pre_clk, CSCDR2, IPU2_DI0_PRE);
983 DEF_CLK_DIV1(ipu2_di1_pre_div, &ipu2_di1_pre_clk, CSCDR2, IPU2_DI1_PRE);
984 DEF_CLK_DIV1(ipu1_div, &ipu1_clk, CSCDR3, IPU1_HSP);
985 DEF_CLK_DIV1(ipu2_div, &ipu2_clk, CSCDR3, IPU2_HSP);
987 #define DEF_CLK_DIV2(d, c, r, b) \
988 static struct divider d = { \
989 .clk = c, \
990 .reg = r, \
991 .bp_pred = BP_##r##_##b##_PRED, \
992 .bm_pred = BM_##r##_##b##_PRED, \
993 .bp_podf = BP_##r##_##b##_PODF, \
994 .bm_podf = BM_##r##_##b##_PODF, \
997 DEF_CLK_DIV2(ssi1_div, &ssi1_clk, CS1CDR, SSI1);
998 DEF_CLK_DIV2(ssi3_div, &ssi3_clk, CS1CDR, SSI3);
999 DEF_CLK_DIV2(esai_div, &esai_clk, CS1CDR, ESAI);
1000 DEF_CLK_DIV2(ssi2_div, &ssi2_clk, CS2CDR, SSI2);
1001 DEF_CLK_DIV2(enfc_div, &enfc_clk, CS2CDR, ENFC);
1002 DEF_CLK_DIV2(spdif_div, &spdif_clk, CDCDR, SPDIF);
1003 DEF_CLK_DIV2(asrc_serial_div, &asrc_serial_clk, CDCDR, ASRC_SERIAL);
1005 static struct divider *dividers[] = {
1006 &arm_div,
1007 &ipg_div,
1008 &ahb_div,
1009 &axi_div,
1010 &mmdc_ch0_axi_div,
1011 &mmdc_ch1_axi_div,
1012 &periph_clk2_div,
1013 &periph2_clk2_div,
1014 &gpu2d_core_div,
1015 &gpu3d_core_div,
1016 &gpu3d_shader_div,
1017 &ipg_perclk_div,
1018 &emi_div,
1019 &emi_slow_div,
1020 &can_div,
1021 &uart_div,
1022 &usdhc1_div,
1023 &usdhc2_div,
1024 &usdhc3_div,
1025 &usdhc4_div,
1026 &vpu_div,
1027 &hsi_tx_div,
1028 &ipu1_di0_pre_div,
1029 &ipu1_di1_pre_div,
1030 &ipu2_di0_pre_div,
1031 &ipu2_di1_pre_div,
1032 &ipu1_div,
1033 &ipu2_div,
1034 &ssi1_div,
1035 &ssi3_div,
1036 &esai_div,
1037 &ssi2_div,
1038 &enfc_div,
1039 &spdif_div,
1040 &asrc_serial_div,
1043 static unsigned long ldb_di_clk_get_rate(struct clk *clk)
1045 u32 val = readl_relaxed(CSCMR2);
1047 val &= (clk == &ldb_di0_clk) ? BM_CSCMR2_LDB_DI0_IPU_DIV :
1048 BM_CSCMR2_LDB_DI1_IPU_DIV;
1049 if (val)
1050 return clk_get_rate(clk->parent) / 7;
1051 else
1052 return clk_get_rate(clk->parent) * 2 / 7;
1055 static int ldb_di_clk_set_rate(struct clk *clk, unsigned long rate)
1057 unsigned long parent_rate = clk_get_rate(clk->parent);
1058 u32 val = readl_relaxed(CSCMR2);
1060 if (rate * 7 <= parent_rate + parent_rate / 20)
1061 val |= BM_CSCMR2_LDB_DI0_IPU_DIV;
1062 else
1063 val &= ~BM_CSCMR2_LDB_DI0_IPU_DIV;
1065 writel_relaxed(val, CSCMR2);
1067 return 0;
1070 static unsigned long ldb_di_clk_round_rate(struct clk *clk, unsigned long rate)
1072 unsigned long parent_rate = clk_get_rate(clk->parent);
1074 if (rate * 7 <= parent_rate + parent_rate / 20)
1075 return parent_rate / 7;
1076 else
1077 return 2 * parent_rate / 7;
1080 static unsigned long _clk_get_rate(struct clk *clk)
1082 struct divider *d;
1083 u32 val, pred, podf;
1084 int i, num;
1086 if (clk == &ldb_di0_clk || clk == &ldb_di1_clk)
1087 return ldb_di_clk_get_rate(clk);
1089 num = ARRAY_SIZE(dividers);
1090 for (i = 0; i < num; i++)
1091 if (dividers[i]->clk == clk) {
1092 d = dividers[i];
1093 break;
1095 if (i == num)
1096 return clk_get_rate(clk->parent);
1098 val = readl_relaxed(d->reg);
1099 pred = ((val & d->bm_pred) >> d->bp_pred) + 1;
1100 podf = ((val & d->bm_podf) >> d->bp_podf) + 1;
1102 return clk_get_rate(clk->parent) / (pred * podf);
1105 static int clk_busy_wait(struct clk *clk)
1107 int timeout = 0x100000;
1108 u32 bm;
1110 if (clk == &axi_clk)
1111 bm = BM_CDHIPR_AXI_PODF_BUSY;
1112 else if (clk == &ahb_clk)
1113 bm = BM_CDHIPR_AHB_PODF_BUSY;
1114 else if (clk == &mmdc_ch0_axi_clk)
1115 bm = BM_CDHIPR_MMDC_CH0_PODF_BUSY;
1116 else if (clk == &periph_clk)
1117 bm = BM_CDHIPR_PERIPH_SEL_BUSY;
1118 else if (clk == &arm_clk)
1119 bm = BM_CDHIPR_ARM_PODF_BUSY;
1120 else
1121 return -EINVAL;
1123 while ((readl_relaxed(CDHIPR) & bm) && --timeout)
1124 cpu_relax();
1126 if (unlikely(!timeout))
1127 return -EBUSY;
1129 return 0;
1132 static int _clk_set_rate(struct clk *clk, unsigned long rate)
1134 unsigned long parent_rate = clk_get_rate(clk->parent);
1135 struct divider *d;
1136 u32 val, div, max_div, pred = 0, podf;
1137 int i, num;
1139 if (clk == &ldb_di0_clk || clk == &ldb_di1_clk)
1140 return ldb_di_clk_set_rate(clk, rate);
1142 num = ARRAY_SIZE(dividers);
1143 for (i = 0; i < num; i++)
1144 if (dividers[i]->clk == clk) {
1145 d = dividers[i];
1146 break;
1148 if (i == num)
1149 return -EINVAL;
1151 max_div = ((d->bm_pred >> d->bp_pred) + 1) *
1152 ((d->bm_podf >> d->bp_podf) + 1);
1154 div = parent_rate / rate;
1155 if (div == 0)
1156 div++;
1158 if ((parent_rate / div != rate) || div > max_div)
1159 return -EINVAL;
1161 if (d->bm_pred) {
1162 calc_pred_podf_dividers(div, &pred, &podf);
1163 } else {
1164 pred = 1;
1165 podf = div;
1168 val = readl_relaxed(d->reg);
1169 val &= ~(d->bm_pred | d->bm_podf);
1170 val |= (pred - 1) << d->bp_pred | (podf - 1) << d->bp_podf;
1171 writel_relaxed(val, d->reg);
1173 if (clk == &axi_clk || clk == &ahb_clk ||
1174 clk == &mmdc_ch0_axi_clk || clk == &arm_clk)
1175 return clk_busy_wait(clk);
1177 return 0;
1180 static unsigned long _clk_round_rate(struct clk *clk, unsigned long rate)
1182 unsigned long parent_rate = clk_get_rate(clk->parent);
1183 u32 div = parent_rate / rate;
1184 u32 div_max, pred = 0, podf;
1185 struct divider *d;
1186 int i, num;
1188 if (clk == &ldb_di0_clk || clk == &ldb_di1_clk)
1189 return ldb_di_clk_round_rate(clk, rate);
1191 num = ARRAY_SIZE(dividers);
1192 for (i = 0; i < num; i++)
1193 if (dividers[i]->clk == clk) {
1194 d = dividers[i];
1195 break;
1197 if (i == num)
1198 return -EINVAL;
1200 if (div == 0 || parent_rate % rate)
1201 div++;
1203 if (d->bm_pred) {
1204 calc_pred_podf_dividers(div, &pred, &podf);
1205 div = pred * podf;
1206 } else {
1207 div_max = (d->bm_podf >> d->bp_podf) + 1;
1208 if (div > div_max)
1209 div = div_max;
1212 return parent_rate / div;
1215 struct multiplexer {
1216 struct clk *clk;
1217 void __iomem *reg;
1218 u32 bp;
1219 u32 bm;
1220 int pnum;
1221 struct clk *parents[];
1224 static struct multiplexer axi_mux = {
1225 .clk = &axi_clk,
1226 .reg = CBCDR,
1227 .bp = BP_CBCDR_AXI_SEL,
1228 .bm = BM_CBCDR_AXI_SEL,
1229 .parents = {
1230 &periph_clk,
1231 &pll2_pfd_400m,
1232 &pll3_pfd_540m,
1233 NULL
1237 static struct multiplexer periph_mux = {
1238 .clk = &periph_clk,
1239 .reg = CBCDR,
1240 .bp = BP_CBCDR_PERIPH_CLK_SEL,
1241 .bm = BM_CBCDR_PERIPH_CLK_SEL,
1242 .parents = {
1243 &periph_pre_clk,
1244 &periph_clk2_clk,
1245 NULL
1249 static struct multiplexer periph_pre_mux = {
1250 .clk = &periph_pre_clk,
1251 .reg = CBCMR,
1252 .bp = BP_CBCMR_PRE_PERIPH_CLK_SEL,
1253 .bm = BM_CBCMR_PRE_PERIPH_CLK_SEL,
1254 .parents = {
1255 &pll2_bus,
1256 &pll2_pfd_400m,
1257 &pll2_pfd_352m,
1258 &pll2_200m,
1259 NULL
1263 static struct multiplexer periph_clk2_mux = {
1264 .clk = &periph_clk2_clk,
1265 .reg = CBCMR,
1266 .bp = BP_CBCMR_PERIPH_CLK2_SEL,
1267 .bm = BM_CBCMR_PERIPH_CLK2_SEL,
1268 .parents = {
1269 &pll3_usb_otg,
1270 &osc_clk,
1271 NULL
1275 static struct multiplexer periph2_mux = {
1276 .clk = &periph2_clk,
1277 .reg = CBCDR,
1278 .bp = BP_CBCDR_PERIPH2_CLK_SEL,
1279 .bm = BM_CBCDR_PERIPH2_CLK_SEL,
1280 .parents = {
1281 &periph2_pre_clk,
1282 &periph2_clk2_clk,
1283 NULL
1287 static struct multiplexer periph2_pre_mux = {
1288 .clk = &periph2_pre_clk,
1289 .reg = CBCMR,
1290 .bp = BP_CBCMR_PRE_PERIPH2_CLK_SEL,
1291 .bm = BM_CBCMR_PRE_PERIPH2_CLK_SEL,
1292 .parents = {
1293 &pll2_bus,
1294 &pll2_pfd_400m,
1295 &pll2_pfd_352m,
1296 &pll2_200m,
1297 NULL
1301 static struct multiplexer periph2_clk2_mux = {
1302 .clk = &periph2_clk2_clk,
1303 .reg = CBCMR,
1304 .bp = BP_CBCMR_PERIPH2_CLK2_SEL,
1305 .bm = BM_CBCMR_PERIPH2_CLK2_SEL,
1306 .parents = {
1307 &pll3_usb_otg,
1308 &osc_clk,
1309 NULL
1313 static struct multiplexer gpu2d_axi_mux = {
1314 .clk = &gpu2d_axi_clk,
1315 .reg = CBCMR,
1316 .bp = BP_CBCMR_GPU2D_AXI_SEL,
1317 .bm = BM_CBCMR_GPU2D_AXI_SEL,
1318 .parents = {
1319 &axi_clk,
1320 &ahb_clk,
1321 NULL
1325 static struct multiplexer gpu3d_axi_mux = {
1326 .clk = &gpu3d_axi_clk,
1327 .reg = CBCMR,
1328 .bp = BP_CBCMR_GPU3D_AXI_SEL,
1329 .bm = BM_CBCMR_GPU3D_AXI_SEL,
1330 .parents = {
1331 &axi_clk,
1332 &ahb_clk,
1333 NULL
1337 static struct multiplexer gpu3d_core_mux = {
1338 .clk = &gpu3d_core_clk,
1339 .reg = CBCMR,
1340 .bp = BP_CBCMR_GPU3D_CORE_SEL,
1341 .bm = BM_CBCMR_GPU3D_CORE_SEL,
1342 .parents = {
1343 &mmdc_ch0_axi_clk,
1344 &pll3_usb_otg,
1345 &pll2_pfd_594m,
1346 &pll2_pfd_400m,
1347 NULL
1351 static struct multiplexer gpu3d_shader_mux = {
1352 .clk = &gpu3d_shader_clk,
1353 .reg = CBCMR,
1354 .bp = BP_CBCMR_GPU3D_SHADER_SEL,
1355 .bm = BM_CBCMR_GPU3D_SHADER_SEL,
1356 .parents = {
1357 &mmdc_ch0_axi_clk,
1358 &pll3_usb_otg,
1359 &pll2_pfd_594m,
1360 &pll3_pfd_720m,
1361 NULL
1365 static struct multiplexer pcie_axi_mux = {
1366 .clk = &pcie_clk,
1367 .reg = CBCMR,
1368 .bp = BP_CBCMR_PCIE_AXI_SEL,
1369 .bm = BM_CBCMR_PCIE_AXI_SEL,
1370 .parents = {
1371 &axi_clk,
1372 &ahb_clk,
1373 NULL
1377 static struct multiplexer vdo_axi_mux = {
1378 .clk = &vdo_axi_clk,
1379 .reg = CBCMR,
1380 .bp = BP_CBCMR_VDO_AXI_SEL,
1381 .bm = BM_CBCMR_VDO_AXI_SEL,
1382 .parents = {
1383 &axi_clk,
1384 &ahb_clk,
1385 NULL
1389 static struct multiplexer vpu_axi_mux = {
1390 .clk = &vpu_clk,
1391 .reg = CBCMR,
1392 .bp = BP_CBCMR_VPU_AXI_SEL,
1393 .bm = BM_CBCMR_VPU_AXI_SEL,
1394 .parents = {
1395 &axi_clk,
1396 &pll2_pfd_400m,
1397 &pll2_pfd_352m,
1398 NULL
1402 static struct multiplexer gpu2d_core_mux = {
1403 .clk = &gpu2d_core_clk,
1404 .reg = CBCMR,
1405 .bp = BP_CBCMR_GPU2D_CORE_SEL,
1406 .bm = BM_CBCMR_GPU2D_CORE_SEL,
1407 .parents = {
1408 &axi_clk,
1409 &pll3_usb_otg,
1410 &pll2_pfd_352m,
1411 &pll2_pfd_400m,
1412 NULL
1416 #define DEF_SSI_MUX(id) \
1417 static struct multiplexer ssi##id##_mux = { \
1418 .clk = &ssi##id##_clk, \
1419 .reg = CSCMR1, \
1420 .bp = BP_CSCMR1_SSI##id##_SEL, \
1421 .bm = BM_CSCMR1_SSI##id##_SEL, \
1422 .parents = { \
1423 &pll3_pfd_508m, \
1424 &pll3_pfd_454m, \
1425 &pll4_audio, \
1426 NULL \
1427 }, \
1430 DEF_SSI_MUX(1);
1431 DEF_SSI_MUX(2);
1432 DEF_SSI_MUX(3);
1434 #define DEF_USDHC_MUX(id) \
1435 static struct multiplexer usdhc##id##_mux = { \
1436 .clk = &usdhc##id##_clk, \
1437 .reg = CSCMR1, \
1438 .bp = BP_CSCMR1_USDHC##id##_SEL, \
1439 .bm = BM_CSCMR1_USDHC##id##_SEL, \
1440 .parents = { \
1441 &pll2_pfd_400m, \
1442 &pll2_pfd_352m, \
1443 NULL \
1444 }, \
1447 DEF_USDHC_MUX(1);
1448 DEF_USDHC_MUX(2);
1449 DEF_USDHC_MUX(3);
1450 DEF_USDHC_MUX(4);
1452 static struct multiplexer emi_mux = {
1453 .clk = &emi_clk,
1454 .reg = CSCMR1,
1455 .bp = BP_CSCMR1_EMI_SEL,
1456 .bm = BM_CSCMR1_EMI_SEL,
1457 .parents = {
1458 &axi_clk,
1459 &pll3_usb_otg,
1460 &pll2_pfd_400m,
1461 &pll2_pfd_352m,
1462 NULL
1466 static struct multiplexer emi_slow_mux = {
1467 .clk = &emi_slow_clk,
1468 .reg = CSCMR1,
1469 .bp = BP_CSCMR1_EMI_SLOW_SEL,
1470 .bm = BM_CSCMR1_EMI_SLOW_SEL,
1471 .parents = {
1472 &axi_clk,
1473 &pll3_usb_otg,
1474 &pll2_pfd_400m,
1475 &pll2_pfd_352m,
1476 NULL
1480 static struct multiplexer esai_mux = {
1481 .clk = &esai_clk,
1482 .reg = CSCMR2,
1483 .bp = BP_CSCMR2_ESAI_SEL,
1484 .bm = BM_CSCMR2_ESAI_SEL,
1485 .parents = {
1486 &pll4_audio,
1487 &pll3_pfd_508m,
1488 &pll3_pfd_454m,
1489 &pll3_usb_otg,
1490 NULL
1494 #define DEF_LDB_DI_MUX(id) \
1495 static struct multiplexer ldb_di##id##_mux = { \
1496 .clk = &ldb_di##id##_clk, \
1497 .reg = CS2CDR, \
1498 .bp = BP_CS2CDR_LDB_DI##id##_SEL, \
1499 .bm = BM_CS2CDR_LDB_DI##id##_SEL, \
1500 .parents = { \
1501 &pll5_video, \
1502 &pll2_pfd_352m, \
1503 &pll2_pfd_400m, \
1504 &pll3_pfd_540m, \
1505 &pll3_usb_otg, \
1506 NULL \
1507 }, \
1510 DEF_LDB_DI_MUX(0);
1511 DEF_LDB_DI_MUX(1);
1513 static struct multiplexer enfc_mux = {
1514 .clk = &enfc_clk,
1515 .reg = CS2CDR,
1516 .bp = BP_CS2CDR_ENFC_SEL,
1517 .bm = BM_CS2CDR_ENFC_SEL,
1518 .parents = {
1519 &pll2_pfd_352m,
1520 &pll2_bus,
1521 &pll3_usb_otg,
1522 &pll2_pfd_400m,
1523 NULL
1527 static struct multiplexer spdif_mux = {
1528 .clk = &spdif_clk,
1529 .reg = CDCDR,
1530 .bp = BP_CDCDR_SPDIF_SEL,
1531 .bm = BM_CDCDR_SPDIF_SEL,
1532 .parents = {
1533 &pll4_audio,
1534 &pll3_pfd_508m,
1535 &pll3_pfd_454m,
1536 &pll3_usb_otg,
1537 NULL
1541 static struct multiplexer asrc_serial_mux = {
1542 .clk = &asrc_serial_clk,
1543 .reg = CDCDR,
1544 .bp = BP_CDCDR_ASRC_SERIAL_SEL,
1545 .bm = BM_CDCDR_ASRC_SERIAL_SEL,
1546 .parents = {
1547 &pll4_audio,
1548 &pll3_pfd_508m,
1549 &pll3_pfd_454m,
1550 &pll3_usb_otg,
1551 NULL
1555 static struct multiplexer hsi_tx_mux = {
1556 .clk = &hsi_tx_clk,
1557 .reg = CDCDR,
1558 .bp = BP_CDCDR_HSI_TX_SEL,
1559 .bm = BM_CDCDR_HSI_TX_SEL,
1560 .parents = {
1561 &pll3_120m,
1562 &pll2_pfd_400m,
1563 NULL
1567 #define DEF_IPU_DI_PRE_MUX(r, i, d) \
1568 static struct multiplexer ipu##i##_di##d##_pre_mux = { \
1569 .clk = &ipu##i##_di##d##_pre_clk, \
1570 .reg = r, \
1571 .bp = BP_##r##_IPU##i##_DI##d##_PRE_SEL, \
1572 .bm = BM_##r##_IPU##i##_DI##d##_PRE_SEL, \
1573 .parents = { \
1574 &mmdc_ch0_axi_clk, \
1575 &pll3_usb_otg, \
1576 &pll5_video, \
1577 &pll2_pfd_352m, \
1578 &pll2_pfd_400m, \
1579 &pll3_pfd_540m, \
1580 NULL \
1581 }, \
1584 DEF_IPU_DI_PRE_MUX(CHSCCDR, 1, 0);
1585 DEF_IPU_DI_PRE_MUX(CHSCCDR, 1, 1);
1586 DEF_IPU_DI_PRE_MUX(CSCDR2, 2, 0);
1587 DEF_IPU_DI_PRE_MUX(CSCDR2, 2, 1);
1589 #define DEF_IPU_DI_MUX(r, i, d) \
1590 static struct multiplexer ipu##i##_di##d##_mux = { \
1591 .clk = &ipu##i##_di##d##_clk, \
1592 .reg = r, \
1593 .bp = BP_##r##_IPU##i##_DI##d##_SEL, \
1594 .bm = BM_##r##_IPU##i##_DI##d##_SEL, \
1595 .parents = { \
1596 &ipu##i##_di##d##_pre_clk, \
1597 &dummy_clk, \
1598 &dummy_clk, \
1599 &ldb_di0_clk, \
1600 &ldb_di1_clk, \
1601 NULL \
1602 }, \
1605 DEF_IPU_DI_MUX(CHSCCDR, 1, 0);
1606 DEF_IPU_DI_MUX(CHSCCDR, 1, 1);
1607 DEF_IPU_DI_MUX(CSCDR2, 2, 0);
1608 DEF_IPU_DI_MUX(CSCDR2, 2, 1);
1610 #define DEF_IPU_MUX(id) \
1611 static struct multiplexer ipu##id##_mux = { \
1612 .clk = &ipu##id##_clk, \
1613 .reg = CSCDR3, \
1614 .bp = BP_CSCDR3_IPU##id##_HSP_SEL, \
1615 .bm = BM_CSCDR3_IPU##id##_HSP_SEL, \
1616 .parents = { \
1617 &mmdc_ch0_axi_clk, \
1618 &pll2_pfd_400m, \
1619 &pll3_120m, \
1620 &pll3_pfd_540m, \
1621 NULL \
1622 }, \
1625 DEF_IPU_MUX(1);
1626 DEF_IPU_MUX(2);
1628 static struct multiplexer *multiplexers[] = {
1629 &axi_mux,
1630 &periph_mux,
1631 &periph_pre_mux,
1632 &periph_clk2_mux,
1633 &periph2_mux,
1634 &periph2_pre_mux,
1635 &periph2_clk2_mux,
1636 &gpu2d_axi_mux,
1637 &gpu3d_axi_mux,
1638 &gpu3d_core_mux,
1639 &gpu3d_shader_mux,
1640 &pcie_axi_mux,
1641 &vdo_axi_mux,
1642 &vpu_axi_mux,
1643 &gpu2d_core_mux,
1644 &ssi1_mux,
1645 &ssi2_mux,
1646 &ssi3_mux,
1647 &usdhc1_mux,
1648 &usdhc2_mux,
1649 &usdhc3_mux,
1650 &usdhc4_mux,
1651 &emi_mux,
1652 &emi_slow_mux,
1653 &esai_mux,
1654 &ldb_di0_mux,
1655 &ldb_di1_mux,
1656 &enfc_mux,
1657 &spdif_mux,
1658 &asrc_serial_mux,
1659 &hsi_tx_mux,
1660 &ipu1_di0_pre_mux,
1661 &ipu1_di0_mux,
1662 &ipu1_di1_pre_mux,
1663 &ipu1_di1_mux,
1664 &ipu2_di0_pre_mux,
1665 &ipu2_di0_mux,
1666 &ipu2_di1_pre_mux,
1667 &ipu2_di1_mux,
1668 &ipu1_mux,
1669 &ipu2_mux,
1672 static int _clk_set_parent(struct clk *clk, struct clk *parent)
1674 struct multiplexer *m;
1675 int i, num;
1676 u32 val;
1678 num = ARRAY_SIZE(multiplexers);
1679 for (i = 0; i < num; i++)
1680 if (multiplexers[i]->clk == clk) {
1681 m = multiplexers[i];
1682 break;
1684 if (i == num)
1685 return -EINVAL;
1687 i = 0;
1688 while (m->parents[i]) {
1689 if (parent == m->parents[i])
1690 break;
1691 i++;
1693 if (!m->parents[i])
1694 return -EINVAL;
1696 val = readl_relaxed(m->reg);
1697 val &= ~m->bm;
1698 val |= i << m->bp;
1699 writel_relaxed(val, m->reg);
1701 if (clk == &periph_clk)
1702 return clk_busy_wait(clk);
1704 return 0;
1707 #define DEF_NG_CLK(name, p) \
1708 static struct clk name = { \
1709 .get_rate = _clk_get_rate, \
1710 .set_rate = _clk_set_rate, \
1711 .round_rate = _clk_round_rate, \
1712 .set_parent = _clk_set_parent, \
1713 .parent = p, \
1716 DEF_NG_CLK(periph_clk2_clk, &osc_clk);
1717 DEF_NG_CLK(periph_pre_clk, &pll2_bus);
1718 DEF_NG_CLK(periph_clk, &periph_pre_clk);
1719 DEF_NG_CLK(periph2_clk2_clk, &osc_clk);
1720 DEF_NG_CLK(periph2_pre_clk, &pll2_bus);
1721 DEF_NG_CLK(periph2_clk, &periph2_pre_clk);
1722 DEF_NG_CLK(axi_clk, &periph_clk);
1723 DEF_NG_CLK(emi_clk, &axi_clk);
1724 DEF_NG_CLK(arm_clk, &pll1_sw_clk);
1725 DEF_NG_CLK(ahb_clk, &periph_clk);
1726 DEF_NG_CLK(ipg_clk, &ahb_clk);
1727 DEF_NG_CLK(ipg_perclk, &ipg_clk);
1728 DEF_NG_CLK(ipu1_di0_pre_clk, &pll3_pfd_540m);
1729 DEF_NG_CLK(ipu1_di1_pre_clk, &pll3_pfd_540m);
1730 DEF_NG_CLK(ipu2_di0_pre_clk, &pll3_pfd_540m);
1731 DEF_NG_CLK(ipu2_di1_pre_clk, &pll3_pfd_540m);
1732 DEF_NG_CLK(asrc_serial_clk, &pll3_usb_otg);
1734 #define DEF_CLK(name, er, es, p, s) \
1735 static struct clk name = { \
1736 .enable_reg = er, \
1737 .enable_shift = es, \
1738 .enable = _clk_enable, \
1739 .disable = _clk_disable, \
1740 .get_rate = _clk_get_rate, \
1741 .set_rate = _clk_set_rate, \
1742 .round_rate = _clk_round_rate, \
1743 .set_parent = _clk_set_parent, \
1744 .parent = p, \
1745 .secondary = s, \
1748 DEF_CLK(aips_tz1_clk, CCGR0, CG0, &ahb_clk, NULL);
1749 DEF_CLK(aips_tz2_clk, CCGR0, CG1, &ahb_clk, NULL);
1750 DEF_CLK(apbh_dma_clk, CCGR0, CG2, &ahb_clk, NULL);
1751 DEF_CLK(asrc_clk, CCGR0, CG3, &pll4_audio, NULL);
1752 DEF_CLK(can1_serial_clk, CCGR0, CG8, &pll3_usb_otg, NULL);
1753 DEF_CLK(can1_clk, CCGR0, CG7, &pll3_usb_otg, &can1_serial_clk);
1754 DEF_CLK(can2_serial_clk, CCGR0, CG10, &pll3_usb_otg, NULL);
1755 DEF_CLK(can2_clk, CCGR0, CG9, &pll3_usb_otg, &can2_serial_clk);
1756 DEF_CLK(ecspi1_clk, CCGR1, CG0, &pll3_60m, NULL);
1757 DEF_CLK(ecspi2_clk, CCGR1, CG1, &pll3_60m, NULL);
1758 DEF_CLK(ecspi3_clk, CCGR1, CG2, &pll3_60m, NULL);
1759 DEF_CLK(ecspi4_clk, CCGR1, CG3, &pll3_60m, NULL);
1760 DEF_CLK(ecspi5_clk, CCGR1, CG4, &pll3_60m, NULL);
1761 DEF_CLK(enet_clk, CCGR1, CG5, &ipg_clk, NULL);
1762 DEF_CLK(esai_clk, CCGR1, CG8, &pll3_usb_otg, NULL);
1763 DEF_CLK(gpt_serial_clk, CCGR1, CG11, &ipg_perclk, NULL);
1764 DEF_CLK(gpt_clk, CCGR1, CG10, &ipg_perclk, &gpt_serial_clk);
1765 DEF_CLK(gpu2d_core_clk, CCGR1, CG12, &pll2_pfd_352m, &gpu2d_axi_clk);
1766 DEF_CLK(gpu3d_core_clk, CCGR1, CG13, &pll2_pfd_594m, &gpu3d_axi_clk);
1767 DEF_CLK(gpu3d_shader_clk, CCGR1, CG13, &pll3_pfd_720m, &gpu3d_axi_clk);
1768 DEF_CLK(hdmi_iahb_clk, CCGR2, CG0, &ahb_clk, NULL);
1769 DEF_CLK(hdmi_isfr_clk, CCGR2, CG2, &pll3_pfd_540m, &hdmi_iahb_clk);
1770 DEF_CLK(i2c1_clk, CCGR2, CG3, &ipg_perclk, NULL);
1771 DEF_CLK(i2c2_clk, CCGR2, CG4, &ipg_perclk, NULL);
1772 DEF_CLK(i2c3_clk, CCGR2, CG5, &ipg_perclk, NULL);
1773 DEF_CLK(iim_clk, CCGR2, CG6, &ipg_clk, NULL);
1774 DEF_CLK(enfc_clk, CCGR2, CG7, &pll2_pfd_352m, NULL);
1775 DEF_CLK(ipu1_clk, CCGR3, CG0, &mmdc_ch0_axi_clk, NULL);
1776 DEF_CLK(ipu1_di0_clk, CCGR3, CG1, &ipu1_di0_pre_clk, NULL);
1777 DEF_CLK(ipu1_di1_clk, CCGR3, CG2, &ipu1_di1_pre_clk, NULL);
1778 DEF_CLK(ipu2_clk, CCGR3, CG3, &mmdc_ch0_axi_clk, NULL);
1779 DEF_CLK(ipu2_di0_clk, CCGR3, CG4, &ipu2_di0_pre_clk, NULL);
1780 DEF_CLK(ipu2_di1_clk, CCGR3, CG5, &ipu2_di1_pre_clk, NULL);
1781 DEF_CLK(ldb_di0_clk, CCGR3, CG6, &pll3_pfd_540m, NULL);
1782 DEF_CLK(ldb_di1_clk, CCGR3, CG7, &pll3_pfd_540m, NULL);
1783 DEF_CLK(hsi_tx_clk, CCGR3, CG8, &pll2_pfd_400m, NULL);
1784 DEF_CLK(mlb_clk, CCGR3, CG9, &pll6_mlb, NULL);
1785 DEF_CLK(mmdc_ch0_ipg_clk, CCGR3, CG12, &ipg_clk, NULL);
1786 DEF_CLK(mmdc_ch0_axi_clk, CCGR3, CG10, &periph_clk, &mmdc_ch0_ipg_clk);
1787 DEF_CLK(mmdc_ch1_ipg_clk, CCGR3, CG13, &ipg_clk, NULL);
1788 DEF_CLK(mmdc_ch1_axi_clk, CCGR3, CG11, &periph2_clk, &mmdc_ch1_ipg_clk);
1789 DEF_CLK(openvg_axi_clk, CCGR3, CG13, &axi_clk, NULL);
1790 DEF_CLK(pwm1_clk, CCGR4, CG8, &ipg_perclk, NULL);
1791 DEF_CLK(pwm2_clk, CCGR4, CG9, &ipg_perclk, NULL);
1792 DEF_CLK(pwm3_clk, CCGR4, CG10, &ipg_perclk, NULL);
1793 DEF_CLK(pwm4_clk, CCGR4, CG11, &ipg_perclk, NULL);
1794 DEF_CLK(gpmi_bch_apb_clk, CCGR4, CG12, &usdhc3_clk, NULL);
1795 DEF_CLK(gpmi_bch_clk, CCGR4, CG13, &usdhc4_clk, &gpmi_bch_apb_clk);
1796 DEF_CLK(gpmi_apb_clk, CCGR4, CG15, &usdhc3_clk, &gpmi_bch_clk);
1797 DEF_CLK(gpmi_io_clk, CCGR4, CG14, &enfc_clk, &gpmi_apb_clk);
1798 DEF_CLK(sdma_clk, CCGR5, CG3, &ahb_clk, NULL);
1799 DEF_CLK(spba_clk, CCGR5, CG6, &ipg_clk, NULL);
1800 DEF_CLK(spdif_clk, CCGR5, CG7, &pll3_usb_otg, &spba_clk);
1801 DEF_CLK(ssi1_clk, CCGR5, CG9, &pll3_pfd_508m, NULL);
1802 DEF_CLK(ssi2_clk, CCGR5, CG10, &pll3_pfd_508m, NULL);
1803 DEF_CLK(ssi3_clk, CCGR5, CG11, &pll3_pfd_508m, NULL);
1804 DEF_CLK(uart_serial_clk, CCGR5, CG13, &pll3_usb_otg, NULL);
1805 DEF_CLK(uart_clk, CCGR5, CG12, &pll3_80m, &uart_serial_clk);
1806 DEF_CLK(usboh3_clk, CCGR6, CG0, &ipg_clk, NULL);
1807 DEF_CLK(usdhc1_clk, CCGR6, CG1, &pll2_pfd_400m, NULL);
1808 DEF_CLK(usdhc2_clk, CCGR6, CG2, &pll2_pfd_400m, NULL);
1809 DEF_CLK(usdhc3_clk, CCGR6, CG3, &pll2_pfd_400m, NULL);
1810 DEF_CLK(usdhc4_clk, CCGR6, CG4, &pll2_pfd_400m, NULL);
1811 DEF_CLK(emi_slow_clk, CCGR6, CG5, &axi_clk, NULL);
1812 DEF_CLK(vdo_axi_clk, CCGR6, CG6, &axi_clk, NULL);
1813 DEF_CLK(vpu_clk, CCGR6, CG7, &axi_clk, NULL);
1815 static int pcie_clk_enable(struct clk *clk)
1817 u32 val;
1819 val = readl_relaxed(PLL8_ENET);
1820 val |= BM_PLL_ENET_EN_PCIE;
1821 writel_relaxed(val, PLL8_ENET);
1823 return _clk_enable(clk);
1826 static void pcie_clk_disable(struct clk *clk)
1828 u32 val;
1830 _clk_disable(clk);
1832 val = readl_relaxed(PLL8_ENET);
1833 val &= BM_PLL_ENET_EN_PCIE;
1834 writel_relaxed(val, PLL8_ENET);
1837 static struct clk pcie_clk = {
1838 .enable_reg = CCGR4,
1839 .enable_shift = CG0,
1840 .enable = pcie_clk_enable,
1841 .disable = pcie_clk_disable,
1842 .set_parent = _clk_set_parent,
1843 .parent = &axi_clk,
1844 .secondary = &pll8_enet,
1847 static int sata_clk_enable(struct clk *clk)
1849 u32 val;
1851 val = readl_relaxed(PLL8_ENET);
1852 val |= BM_PLL_ENET_EN_SATA;
1853 writel_relaxed(val, PLL8_ENET);
1855 return _clk_enable(clk);
1858 static void sata_clk_disable(struct clk *clk)
1860 u32 val;
1862 _clk_disable(clk);
1864 val = readl_relaxed(PLL8_ENET);
1865 val &= BM_PLL_ENET_EN_SATA;
1866 writel_relaxed(val, PLL8_ENET);
1869 static struct clk sata_clk = {
1870 .enable_reg = CCGR5,
1871 .enable_shift = CG2,
1872 .enable = sata_clk_enable,
1873 .disable = sata_clk_disable,
1874 .parent = &ipg_clk,
1875 .secondary = &pll8_enet,
1878 #define _REGISTER_CLOCK(d, n, c) \
1880 .dev_id = d, \
1881 .con_id = n, \
1882 .clk = &c, \
1885 static struct clk_lookup lookups[] = {
1886 _REGISTER_CLOCK("2020000.uart", NULL, uart_clk),
1887 _REGISTER_CLOCK("21e8000.uart", NULL, uart_clk),
1888 _REGISTER_CLOCK("21ec000.uart", NULL, uart_clk),
1889 _REGISTER_CLOCK("21f0000.uart", NULL, uart_clk),
1890 _REGISTER_CLOCK("21f4000.uart", NULL, uart_clk),
1891 _REGISTER_CLOCK("2188000.enet", NULL, enet_clk),
1892 _REGISTER_CLOCK("2190000.usdhc", NULL, usdhc1_clk),
1893 _REGISTER_CLOCK("2194000.usdhc", NULL, usdhc2_clk),
1894 _REGISTER_CLOCK("2198000.usdhc", NULL, usdhc3_clk),
1895 _REGISTER_CLOCK("219c000.usdhc", NULL, usdhc4_clk),
1896 _REGISTER_CLOCK("21a0000.i2c", NULL, i2c1_clk),
1897 _REGISTER_CLOCK("21a4000.i2c", NULL, i2c2_clk),
1898 _REGISTER_CLOCK("21a8000.i2c", NULL, i2c3_clk),
1899 _REGISTER_CLOCK("2008000.ecspi", NULL, ecspi1_clk),
1900 _REGISTER_CLOCK("200c000.ecspi", NULL, ecspi2_clk),
1901 _REGISTER_CLOCK("2010000.ecspi", NULL, ecspi3_clk),
1902 _REGISTER_CLOCK("2014000.ecspi", NULL, ecspi4_clk),
1903 _REGISTER_CLOCK("2018000.ecspi", NULL, ecspi5_clk),
1904 _REGISTER_CLOCK("20ec000.sdma", NULL, sdma_clk),
1905 _REGISTER_CLOCK("20bc000.wdog", NULL, dummy_clk),
1906 _REGISTER_CLOCK("20c0000.wdog", NULL, dummy_clk),
1907 _REGISTER_CLOCK("smp_twd", NULL, twd_clk),
1908 _REGISTER_CLOCK(NULL, "ckih", ckih_clk),
1909 _REGISTER_CLOCK(NULL, "ckil_clk", ckil_clk),
1910 _REGISTER_CLOCK(NULL, "aips_tz1_clk", aips_tz1_clk),
1911 _REGISTER_CLOCK(NULL, "aips_tz2_clk", aips_tz2_clk),
1912 _REGISTER_CLOCK(NULL, "asrc_clk", asrc_clk),
1913 _REGISTER_CLOCK(NULL, "can2_clk", can2_clk),
1914 _REGISTER_CLOCK(NULL, "hdmi_isfr_clk", hdmi_isfr_clk),
1915 _REGISTER_CLOCK(NULL, "iim_clk", iim_clk),
1916 _REGISTER_CLOCK(NULL, "mlb_clk", mlb_clk),
1917 _REGISTER_CLOCK(NULL, "openvg_axi_clk", openvg_axi_clk),
1918 _REGISTER_CLOCK(NULL, "pwm1_clk", pwm1_clk),
1919 _REGISTER_CLOCK(NULL, "pwm2_clk", pwm2_clk),
1920 _REGISTER_CLOCK(NULL, "pwm3_clk", pwm3_clk),
1921 _REGISTER_CLOCK(NULL, "pwm4_clk", pwm4_clk),
1922 _REGISTER_CLOCK(NULL, "gpmi_io_clk", gpmi_io_clk),
1923 _REGISTER_CLOCK(NULL, "usboh3_clk", usboh3_clk),
1924 _REGISTER_CLOCK(NULL, "sata_clk", sata_clk),
1927 int imx6q_set_lpm(enum mxc_cpu_pwr_mode mode)
1929 u32 val = readl_relaxed(CLPCR);
1931 val &= ~BM_CLPCR_LPM;
1932 switch (mode) {
1933 case WAIT_CLOCKED:
1934 break;
1935 case WAIT_UNCLOCKED:
1936 val |= 0x1 << BP_CLPCR_LPM;
1937 break;
1938 case STOP_POWER_ON:
1939 val |= 0x2 << BP_CLPCR_LPM;
1940 break;
1941 case WAIT_UNCLOCKED_POWER_OFF:
1942 val |= 0x1 << BP_CLPCR_LPM;
1943 val &= ~BM_CLPCR_VSTBY;
1944 val &= ~BM_CLPCR_SBYOS;
1945 break;
1946 case STOP_POWER_OFF:
1947 val |= 0x2 << BP_CLPCR_LPM;
1948 val |= 0x3 << BP_CLPCR_STBY_COUNT;
1949 val |= BM_CLPCR_VSTBY;
1950 val |= BM_CLPCR_SBYOS;
1951 break;
1952 default:
1953 return -EINVAL;
1955 writel_relaxed(val, CLPCR);
1957 return 0;
1960 static struct map_desc imx6q_clock_desc[] = {
1961 imx_map_entry(MX6Q, CCM, MT_DEVICE),
1962 imx_map_entry(MX6Q, ANATOP, MT_DEVICE),
1965 void __init imx6q_clock_map_io(void)
1967 iotable_init(imx6q_clock_desc, ARRAY_SIZE(imx6q_clock_desc));
1970 int __init mx6q_clocks_init(void)
1972 struct device_node *np;
1973 void __iomem *base;
1974 int i, irq;
1976 /* retrieve the freqency of fixed clocks from device tree */
1977 for_each_compatible_node(np, NULL, "fixed-clock") {
1978 u32 rate;
1979 if (of_property_read_u32(np, "clock-frequency", &rate))
1980 continue;
1982 if (of_device_is_compatible(np, "fsl,imx-ckil"))
1983 external_low_reference = rate;
1984 else if (of_device_is_compatible(np, "fsl,imx-ckih1"))
1985 external_high_reference = rate;
1986 else if (of_device_is_compatible(np, "fsl,imx-osc"))
1987 oscillator_reference = rate;
1990 for (i = 0; i < ARRAY_SIZE(lookups); i++)
1991 clkdev_add(&lookups[i]);
1993 /* only keep necessary clocks on */
1994 writel_relaxed(0x3 << CG0 | 0x3 << CG1 | 0x3 << CG2, CCGR0);
1995 writel_relaxed(0x3 << CG8 | 0x3 << CG9 | 0x3 << CG10, CCGR2);
1996 writel_relaxed(0x3 << CG10 | 0x3 << CG12, CCGR3);
1997 writel_relaxed(0x3 << CG4 | 0x3 << CG6 | 0x3 << CG7, CCGR4);
1998 writel_relaxed(0x3 << CG0, CCGR5);
1999 writel_relaxed(0, CCGR6);
2000 writel_relaxed(0, CCGR7);
2002 clk_enable(&uart_clk);
2003 clk_enable(&mmdc_ch0_axi_clk);
2005 clk_set_rate(&pll4_audio, FREQ_650M);
2006 clk_set_rate(&pll5_video, FREQ_650M);
2007 clk_set_parent(&ipu1_di0_clk, &ipu1_di0_pre_clk);
2008 clk_set_parent(&ipu1_di0_pre_clk, &pll5_video);
2009 clk_set_parent(&gpu3d_shader_clk, &pll2_pfd_594m);
2010 clk_set_rate(&gpu3d_shader_clk, FREQ_594M);
2011 clk_set_parent(&gpu3d_core_clk, &mmdc_ch0_axi_clk);
2012 clk_set_rate(&gpu3d_core_clk, FREQ_528M);
2013 clk_set_parent(&asrc_serial_clk, &pll3_usb_otg);
2014 clk_set_rate(&asrc_serial_clk, 1500000);
2015 clk_set_rate(&enfc_clk, 11000000);
2018 * Before pinctrl API is available, we have to rely on the pad
2019 * configuration set up by bootloader. For usdhc example here,
2020 * u-boot sets up the pads for 49.5 MHz case, and we have to lower
2021 * the usdhc clock from 198 to 49.5 MHz to match the pad configuration.
2023 * FIXME: This is should be removed after pinctrl API is available.
2024 * At that time, usdhc driver can call pinctrl API to change pad
2025 * configuration dynamically per different usdhc clock settings.
2027 clk_set_rate(&usdhc1_clk, 49500000);
2028 clk_set_rate(&usdhc2_clk, 49500000);
2029 clk_set_rate(&usdhc3_clk, 49500000);
2030 clk_set_rate(&usdhc4_clk, 49500000);
2032 np = of_find_compatible_node(NULL, NULL, "fsl,imx6q-gpt");
2033 base = of_iomap(np, 0);
2034 WARN_ON(!base);
2035 irq = irq_of_parse_and_map(np, 0);
2036 mxc_timer_init(&gpt_clk, base, irq);
2038 return 0;