dm writecache: fix incorrect flush sequence when doing SSD mode commit
[linux/fpc-iii.git] / drivers / clk / ingenic / jz4780-cgu.c
blobea905ff72bf03492b2dc5201509d42cbf2711d61
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Ingenic JZ4780 SoC CGU driver
5 * Copyright (c) 2013-2015 Imagination Technologies
6 * Author: Paul Burton <paul.burton@mips.com>
7 */
9 #include <linux/clk-provider.h>
10 #include <linux/delay.h>
11 #include <linux/io.h>
12 #include <linux/of.h>
13 #include <dt-bindings/clock/jz4780-cgu.h>
14 #include "cgu.h"
15 #include "pm.h"
17 /* CGU register offsets */
18 #define CGU_REG_CLOCKCONTROL 0x00
19 #define CGU_REG_PLLCONTROL 0x0c
20 #define CGU_REG_APLL 0x10
21 #define CGU_REG_MPLL 0x14
22 #define CGU_REG_EPLL 0x18
23 #define CGU_REG_VPLL 0x1c
24 #define CGU_REG_CLKGR0 0x20
25 #define CGU_REG_OPCR 0x24
26 #define CGU_REG_CLKGR1 0x28
27 #define CGU_REG_DDRCDR 0x2c
28 #define CGU_REG_VPUCDR 0x30
29 #define CGU_REG_USBPCR 0x3c
30 #define CGU_REG_USBRDT 0x40
31 #define CGU_REG_USBVBFIL 0x44
32 #define CGU_REG_USBPCR1 0x48
33 #define CGU_REG_LP0CDR 0x54
34 #define CGU_REG_I2SCDR 0x60
35 #define CGU_REG_LP1CDR 0x64
36 #define CGU_REG_MSC0CDR 0x68
37 #define CGU_REG_UHCCDR 0x6c
38 #define CGU_REG_SSICDR 0x74
39 #define CGU_REG_CIMCDR 0x7c
40 #define CGU_REG_PCMCDR 0x84
41 #define CGU_REG_GPUCDR 0x88
42 #define CGU_REG_HDMICDR 0x8c
43 #define CGU_REG_MSC1CDR 0xa4
44 #define CGU_REG_MSC2CDR 0xa8
45 #define CGU_REG_BCHCDR 0xac
46 #define CGU_REG_CLOCKSTATUS 0xd4
48 /* bits within the OPCR register */
49 #define OPCR_SPENDN0 (1 << 7)
50 #define OPCR_SPENDN1 (1 << 6)
52 /* bits within the USBPCR register */
53 #define USBPCR_USB_MODE BIT(31)
54 #define USBPCR_IDPULLUP_MASK (0x3 << 28)
55 #define USBPCR_COMMONONN BIT(25)
56 #define USBPCR_VBUSVLDEXT BIT(24)
57 #define USBPCR_VBUSVLDEXTSEL BIT(23)
58 #define USBPCR_POR BIT(22)
59 #define USBPCR_OTG_DISABLE BIT(20)
60 #define USBPCR_COMPDISTUNE_MASK (0x7 << 17)
61 #define USBPCR_OTGTUNE_MASK (0x7 << 14)
62 #define USBPCR_SQRXTUNE_MASK (0x7 << 11)
63 #define USBPCR_TXFSLSTUNE_MASK (0xf << 7)
64 #define USBPCR_TXPREEMPHTUNE BIT(6)
65 #define USBPCR_TXHSXVTUNE_MASK (0x3 << 4)
66 #define USBPCR_TXVREFTUNE_MASK 0xf
68 /* bits within the USBPCR1 register */
69 #define USBPCR1_REFCLKSEL_SHIFT 26
70 #define USBPCR1_REFCLKSEL_MASK (0x3 << USBPCR1_REFCLKSEL_SHIFT)
71 #define USBPCR1_REFCLKSEL_CORE (0x2 << USBPCR1_REFCLKSEL_SHIFT)
72 #define USBPCR1_REFCLKDIV_SHIFT 24
73 #define USBPCR1_REFCLKDIV_MASK (0x3 << USBPCR1_REFCLKDIV_SHIFT)
74 #define USBPCR1_REFCLKDIV_19_2 (0x3 << USBPCR1_REFCLKDIV_SHIFT)
75 #define USBPCR1_REFCLKDIV_48 (0x2 << USBPCR1_REFCLKDIV_SHIFT)
76 #define USBPCR1_REFCLKDIV_24 (0x1 << USBPCR1_REFCLKDIV_SHIFT)
77 #define USBPCR1_REFCLKDIV_12 (0x0 << USBPCR1_REFCLKDIV_SHIFT)
78 #define USBPCR1_USB_SEL BIT(28)
79 #define USBPCR1_WORD_IF0 BIT(19)
80 #define USBPCR1_WORD_IF1 BIT(18)
82 /* bits within the USBRDT register */
83 #define USBRDT_VBFIL_LD_EN BIT(25)
84 #define USBRDT_USBRDT_MASK 0x7fffff
86 /* bits within the USBVBFIL register */
87 #define USBVBFIL_IDDIGFIL_SHIFT 16
88 #define USBVBFIL_IDDIGFIL_MASK (0xffff << USBVBFIL_IDDIGFIL_SHIFT)
89 #define USBVBFIL_USBVBFIL_MASK (0xffff)
91 static struct ingenic_cgu *cgu;
93 static u8 jz4780_otg_phy_get_parent(struct clk_hw *hw)
95 /* we only use CLKCORE, revisit if that ever changes */
96 return 0;
99 static int jz4780_otg_phy_set_parent(struct clk_hw *hw, u8 idx)
101 unsigned long flags;
102 u32 usbpcr1;
104 if (idx > 0)
105 return -EINVAL;
107 spin_lock_irqsave(&cgu->lock, flags);
109 usbpcr1 = readl(cgu->base + CGU_REG_USBPCR1);
110 usbpcr1 &= ~USBPCR1_REFCLKSEL_MASK;
111 /* we only use CLKCORE */
112 usbpcr1 |= USBPCR1_REFCLKSEL_CORE;
113 writel(usbpcr1, cgu->base + CGU_REG_USBPCR1);
115 spin_unlock_irqrestore(&cgu->lock, flags);
116 return 0;
119 static unsigned long jz4780_otg_phy_recalc_rate(struct clk_hw *hw,
120 unsigned long parent_rate)
122 u32 usbpcr1;
123 unsigned refclk_div;
125 usbpcr1 = readl(cgu->base + CGU_REG_USBPCR1);
126 refclk_div = usbpcr1 & USBPCR1_REFCLKDIV_MASK;
128 switch (refclk_div) {
129 case USBPCR1_REFCLKDIV_12:
130 return 12000000;
132 case USBPCR1_REFCLKDIV_24:
133 return 24000000;
135 case USBPCR1_REFCLKDIV_48:
136 return 48000000;
138 case USBPCR1_REFCLKDIV_19_2:
139 return 19200000;
142 BUG();
143 return parent_rate;
146 static long jz4780_otg_phy_round_rate(struct clk_hw *hw, unsigned long req_rate,
147 unsigned long *parent_rate)
149 if (req_rate < 15600000)
150 return 12000000;
152 if (req_rate < 21600000)
153 return 19200000;
155 if (req_rate < 36000000)
156 return 24000000;
158 return 48000000;
161 static int jz4780_otg_phy_set_rate(struct clk_hw *hw, unsigned long req_rate,
162 unsigned long parent_rate)
164 unsigned long flags;
165 u32 usbpcr1, div_bits;
167 switch (req_rate) {
168 case 12000000:
169 div_bits = USBPCR1_REFCLKDIV_12;
170 break;
172 case 19200000:
173 div_bits = USBPCR1_REFCLKDIV_19_2;
174 break;
176 case 24000000:
177 div_bits = USBPCR1_REFCLKDIV_24;
178 break;
180 case 48000000:
181 div_bits = USBPCR1_REFCLKDIV_48;
182 break;
184 default:
185 return -EINVAL;
188 spin_lock_irqsave(&cgu->lock, flags);
190 usbpcr1 = readl(cgu->base + CGU_REG_USBPCR1);
191 usbpcr1 &= ~USBPCR1_REFCLKDIV_MASK;
192 usbpcr1 |= div_bits;
193 writel(usbpcr1, cgu->base + CGU_REG_USBPCR1);
195 spin_unlock_irqrestore(&cgu->lock, flags);
196 return 0;
199 static const struct clk_ops jz4780_otg_phy_ops = {
200 .get_parent = jz4780_otg_phy_get_parent,
201 .set_parent = jz4780_otg_phy_set_parent,
203 .recalc_rate = jz4780_otg_phy_recalc_rate,
204 .round_rate = jz4780_otg_phy_round_rate,
205 .set_rate = jz4780_otg_phy_set_rate,
208 static const s8 pll_od_encoding[16] = {
209 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
210 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf,
213 static const struct ingenic_cgu_clk_info jz4780_cgu_clocks[] = {
215 /* External clocks */
217 [JZ4780_CLK_EXCLK] = { "ext", CGU_CLK_EXT },
218 [JZ4780_CLK_RTCLK] = { "rtc", CGU_CLK_EXT },
220 /* PLLs */
222 #define DEF_PLL(name) { \
223 .reg = CGU_REG_ ## name, \
224 .m_shift = 19, \
225 .m_bits = 13, \
226 .m_offset = 1, \
227 .n_shift = 13, \
228 .n_bits = 6, \
229 .n_offset = 1, \
230 .od_shift = 9, \
231 .od_bits = 4, \
232 .od_max = 16, \
233 .od_encoding = pll_od_encoding, \
234 .stable_bit = 6, \
235 .bypass_bit = 1, \
236 .enable_bit = 0, \
239 [JZ4780_CLK_APLL] = {
240 "apll", CGU_CLK_PLL,
241 .parents = { JZ4780_CLK_EXCLK, -1, -1, -1 },
242 .pll = DEF_PLL(APLL),
245 [JZ4780_CLK_MPLL] = {
246 "mpll", CGU_CLK_PLL,
247 .parents = { JZ4780_CLK_EXCLK, -1, -1, -1 },
248 .pll = DEF_PLL(MPLL),
251 [JZ4780_CLK_EPLL] = {
252 "epll", CGU_CLK_PLL,
253 .parents = { JZ4780_CLK_EXCLK, -1, -1, -1 },
254 .pll = DEF_PLL(EPLL),
257 [JZ4780_CLK_VPLL] = {
258 "vpll", CGU_CLK_PLL,
259 .parents = { JZ4780_CLK_EXCLK, -1, -1, -1 },
260 .pll = DEF_PLL(VPLL),
263 #undef DEF_PLL
265 /* Custom (SoC-specific) OTG PHY */
267 [JZ4780_CLK_OTGPHY] = {
268 "otg_phy", CGU_CLK_CUSTOM,
269 .parents = { -1, -1, JZ4780_CLK_EXCLK, -1 },
270 .custom = { &jz4780_otg_phy_ops },
273 /* Muxes & dividers */
275 [JZ4780_CLK_SCLKA] = {
276 "sclk_a", CGU_CLK_MUX,
277 .parents = { -1, JZ4780_CLK_APLL, JZ4780_CLK_EXCLK,
278 JZ4780_CLK_RTCLK },
279 .mux = { CGU_REG_CLOCKCONTROL, 30, 2 },
282 [JZ4780_CLK_CPUMUX] = {
283 "cpumux", CGU_CLK_MUX,
284 .parents = { -1, JZ4780_CLK_SCLKA, JZ4780_CLK_MPLL,
285 JZ4780_CLK_EPLL },
286 .mux = { CGU_REG_CLOCKCONTROL, 28, 2 },
289 [JZ4780_CLK_CPU] = {
290 "cpu", CGU_CLK_DIV,
291 .parents = { JZ4780_CLK_CPUMUX, -1, -1, -1 },
292 .div = { CGU_REG_CLOCKCONTROL, 0, 1, 4, 22, -1, -1 },
295 [JZ4780_CLK_L2CACHE] = {
296 "l2cache", CGU_CLK_DIV,
297 .parents = { JZ4780_CLK_CPUMUX, -1, -1, -1 },
298 .div = { CGU_REG_CLOCKCONTROL, 4, 1, 4, -1, -1, -1 },
301 [JZ4780_CLK_AHB0] = {
302 "ahb0", CGU_CLK_MUX | CGU_CLK_DIV,
303 .parents = { -1, JZ4780_CLK_SCLKA, JZ4780_CLK_MPLL,
304 JZ4780_CLK_EPLL },
305 .mux = { CGU_REG_CLOCKCONTROL, 26, 2 },
306 .div = { CGU_REG_CLOCKCONTROL, 8, 1, 4, 21, -1, -1 },
309 [JZ4780_CLK_AHB2PMUX] = {
310 "ahb2_apb_mux", CGU_CLK_MUX,
311 .parents = { -1, JZ4780_CLK_SCLKA, JZ4780_CLK_MPLL,
312 JZ4780_CLK_RTCLK },
313 .mux = { CGU_REG_CLOCKCONTROL, 24, 2 },
316 [JZ4780_CLK_AHB2] = {
317 "ahb2", CGU_CLK_DIV,
318 .parents = { JZ4780_CLK_AHB2PMUX, -1, -1, -1 },
319 .div = { CGU_REG_CLOCKCONTROL, 12, 1, 4, 20, -1, -1 },
322 [JZ4780_CLK_PCLK] = {
323 "pclk", CGU_CLK_DIV,
324 .parents = { JZ4780_CLK_AHB2PMUX, -1, -1, -1 },
325 .div = { CGU_REG_CLOCKCONTROL, 16, 1, 4, 20, -1, -1 },
328 [JZ4780_CLK_DDR] = {
329 "ddr", CGU_CLK_MUX | CGU_CLK_DIV,
330 .parents = { -1, JZ4780_CLK_SCLKA, JZ4780_CLK_MPLL, -1 },
331 .mux = { CGU_REG_DDRCDR, 30, 2 },
332 .div = { CGU_REG_DDRCDR, 0, 1, 4, 29, 28, 27 },
335 [JZ4780_CLK_VPU] = {
336 "vpu", CGU_CLK_MUX | CGU_CLK_DIV | CGU_CLK_GATE,
337 .parents = { JZ4780_CLK_SCLKA, JZ4780_CLK_MPLL,
338 JZ4780_CLK_EPLL, -1 },
339 .mux = { CGU_REG_VPUCDR, 30, 2 },
340 .div = { CGU_REG_VPUCDR, 0, 1, 4, 29, 28, 27 },
341 .gate = { CGU_REG_CLKGR1, 2 },
344 [JZ4780_CLK_I2SPLL] = {
345 "i2s_pll", CGU_CLK_MUX | CGU_CLK_DIV,
346 .parents = { JZ4780_CLK_SCLKA, JZ4780_CLK_EPLL, -1, -1 },
347 .mux = { CGU_REG_I2SCDR, 30, 1 },
348 .div = { CGU_REG_I2SCDR, 0, 1, 8, 29, 28, 27 },
351 [JZ4780_CLK_I2S] = {
352 "i2s", CGU_CLK_MUX,
353 .parents = { JZ4780_CLK_EXCLK, JZ4780_CLK_I2SPLL, -1, -1 },
354 .mux = { CGU_REG_I2SCDR, 31, 1 },
357 [JZ4780_CLK_LCD0PIXCLK] = {
358 "lcd0pixclk", CGU_CLK_MUX | CGU_CLK_DIV,
359 .parents = { JZ4780_CLK_SCLKA, JZ4780_CLK_MPLL,
360 JZ4780_CLK_VPLL, -1 },
361 .mux = { CGU_REG_LP0CDR, 30, 2 },
362 .div = { CGU_REG_LP0CDR, 0, 1, 8, 28, 27, 26 },
365 [JZ4780_CLK_LCD1PIXCLK] = {
366 "lcd1pixclk", CGU_CLK_MUX | CGU_CLK_DIV,
367 .parents = { JZ4780_CLK_SCLKA, JZ4780_CLK_MPLL,
368 JZ4780_CLK_VPLL, -1 },
369 .mux = { CGU_REG_LP1CDR, 30, 2 },
370 .div = { CGU_REG_LP1CDR, 0, 1, 8, 28, 27, 26 },
373 [JZ4780_CLK_MSCMUX] = {
374 "msc_mux", CGU_CLK_MUX,
375 .parents = { -1, JZ4780_CLK_SCLKA, JZ4780_CLK_MPLL, -1 },
376 .mux = { CGU_REG_MSC0CDR, 30, 2 },
379 [JZ4780_CLK_MSC0] = {
380 "msc0", CGU_CLK_DIV | CGU_CLK_GATE,
381 .parents = { JZ4780_CLK_MSCMUX, -1, -1, -1 },
382 .div = { CGU_REG_MSC0CDR, 0, 2, 8, 29, 28, 27 },
383 .gate = { CGU_REG_CLKGR0, 3 },
386 [JZ4780_CLK_MSC1] = {
387 "msc1", CGU_CLK_DIV | CGU_CLK_GATE,
388 .parents = { JZ4780_CLK_MSCMUX, -1, -1, -1 },
389 .div = { CGU_REG_MSC1CDR, 0, 2, 8, 29, 28, 27 },
390 .gate = { CGU_REG_CLKGR0, 11 },
393 [JZ4780_CLK_MSC2] = {
394 "msc2", CGU_CLK_DIV | CGU_CLK_GATE,
395 .parents = { JZ4780_CLK_MSCMUX, -1, -1, -1 },
396 .div = { CGU_REG_MSC2CDR, 0, 2, 8, 29, 28, 27 },
397 .gate = { CGU_REG_CLKGR0, 12 },
400 [JZ4780_CLK_UHC] = {
401 "uhc", CGU_CLK_MUX | CGU_CLK_DIV | CGU_CLK_GATE,
402 .parents = { JZ4780_CLK_SCLKA, JZ4780_CLK_MPLL,
403 JZ4780_CLK_EPLL, JZ4780_CLK_OTGPHY },
404 .mux = { CGU_REG_UHCCDR, 30, 2 },
405 .div = { CGU_REG_UHCCDR, 0, 1, 8, 29, 28, 27 },
406 .gate = { CGU_REG_CLKGR0, 24 },
409 [JZ4780_CLK_SSIPLL] = {
410 "ssi_pll", CGU_CLK_MUX | CGU_CLK_DIV,
411 .parents = { JZ4780_CLK_SCLKA, JZ4780_CLK_MPLL, -1, -1 },
412 .mux = { CGU_REG_SSICDR, 30, 1 },
413 .div = { CGU_REG_SSICDR, 0, 1, 8, 29, 28, 27 },
416 [JZ4780_CLK_SSI] = {
417 "ssi", CGU_CLK_MUX,
418 .parents = { JZ4780_CLK_EXCLK, JZ4780_CLK_SSIPLL, -1, -1 },
419 .mux = { CGU_REG_SSICDR, 31, 1 },
422 [JZ4780_CLK_CIMMCLK] = {
423 "cim_mclk", CGU_CLK_MUX | CGU_CLK_DIV,
424 .parents = { JZ4780_CLK_SCLKA, JZ4780_CLK_MPLL, -1, -1 },
425 .mux = { CGU_REG_CIMCDR, 31, 1 },
426 .div = { CGU_REG_CIMCDR, 0, 1, 8, 30, 29, 28 },
429 [JZ4780_CLK_PCMPLL] = {
430 "pcm_pll", CGU_CLK_MUX | CGU_CLK_DIV,
431 .parents = { JZ4780_CLK_SCLKA, JZ4780_CLK_MPLL,
432 JZ4780_CLK_EPLL, JZ4780_CLK_VPLL },
433 .mux = { CGU_REG_PCMCDR, 29, 2 },
434 .div = { CGU_REG_PCMCDR, 0, 1, 8, 28, 27, 26 },
437 [JZ4780_CLK_PCM] = {
438 "pcm", CGU_CLK_MUX | CGU_CLK_GATE,
439 .parents = { JZ4780_CLK_EXCLK, JZ4780_CLK_PCMPLL, -1, -1 },
440 .mux = { CGU_REG_PCMCDR, 31, 1 },
441 .gate = { CGU_REG_CLKGR1, 3 },
444 [JZ4780_CLK_GPU] = {
445 "gpu", CGU_CLK_MUX | CGU_CLK_DIV | CGU_CLK_GATE,
446 .parents = { -1, JZ4780_CLK_SCLKA, JZ4780_CLK_MPLL,
447 JZ4780_CLK_EPLL },
448 .mux = { CGU_REG_GPUCDR, 30, 2 },
449 .div = { CGU_REG_GPUCDR, 0, 1, 4, 29, 28, 27 },
450 .gate = { CGU_REG_CLKGR1, 4 },
453 [JZ4780_CLK_HDMI] = {
454 "hdmi", CGU_CLK_MUX | CGU_CLK_DIV | CGU_CLK_GATE,
455 .parents = { JZ4780_CLK_SCLKA, JZ4780_CLK_MPLL,
456 JZ4780_CLK_VPLL, -1 },
457 .mux = { CGU_REG_HDMICDR, 30, 2 },
458 .div = { CGU_REG_HDMICDR, 0, 1, 8, 29, 28, 26 },
459 .gate = { CGU_REG_CLKGR1, 9 },
462 [JZ4780_CLK_BCH] = {
463 "bch", CGU_CLK_MUX | CGU_CLK_DIV | CGU_CLK_GATE,
464 .parents = { -1, JZ4780_CLK_SCLKA, JZ4780_CLK_MPLL,
465 JZ4780_CLK_EPLL },
466 .mux = { CGU_REG_BCHCDR, 30, 2 },
467 .div = { CGU_REG_BCHCDR, 0, 1, 4, 29, 28, 27 },
468 .gate = { CGU_REG_CLKGR0, 1 },
471 /* Gate-only clocks */
473 [JZ4780_CLK_NEMC] = {
474 "nemc", CGU_CLK_GATE,
475 .parents = { JZ4780_CLK_AHB2, -1, -1, -1 },
476 .gate = { CGU_REG_CLKGR0, 0 },
479 [JZ4780_CLK_OTG0] = {
480 "otg0", CGU_CLK_GATE,
481 .parents = { JZ4780_CLK_EXCLK, -1, -1, -1 },
482 .gate = { CGU_REG_CLKGR0, 2 },
485 [JZ4780_CLK_SSI0] = {
486 "ssi0", CGU_CLK_GATE,
487 .parents = { JZ4780_CLK_SSI, -1, -1, -1 },
488 .gate = { CGU_REG_CLKGR0, 4 },
491 [JZ4780_CLK_SMB0] = {
492 "smb0", CGU_CLK_GATE,
493 .parents = { JZ4780_CLK_PCLK, -1, -1, -1 },
494 .gate = { CGU_REG_CLKGR0, 5 },
497 [JZ4780_CLK_SMB1] = {
498 "smb1", CGU_CLK_GATE,
499 .parents = { JZ4780_CLK_PCLK, -1, -1, -1 },
500 .gate = { CGU_REG_CLKGR0, 6 },
503 [JZ4780_CLK_SCC] = {
504 "scc", CGU_CLK_GATE,
505 .parents = { JZ4780_CLK_EXCLK, -1, -1, -1 },
506 .gate = { CGU_REG_CLKGR0, 7 },
509 [JZ4780_CLK_AIC] = {
510 "aic", CGU_CLK_GATE,
511 .parents = { JZ4780_CLK_EXCLK, -1, -1, -1 },
512 .gate = { CGU_REG_CLKGR0, 8 },
515 [JZ4780_CLK_TSSI0] = {
516 "tssi0", CGU_CLK_GATE,
517 .parents = { JZ4780_CLK_EXCLK, -1, -1, -1 },
518 .gate = { CGU_REG_CLKGR0, 9 },
521 [JZ4780_CLK_OWI] = {
522 "owi", CGU_CLK_GATE,
523 .parents = { JZ4780_CLK_EXCLK, -1, -1, -1 },
524 .gate = { CGU_REG_CLKGR0, 10 },
527 [JZ4780_CLK_KBC] = {
528 "kbc", CGU_CLK_GATE,
529 .parents = { JZ4780_CLK_EXCLK, -1, -1, -1 },
530 .gate = { CGU_REG_CLKGR0, 13 },
533 [JZ4780_CLK_SADC] = {
534 "sadc", CGU_CLK_GATE,
535 .parents = { JZ4780_CLK_EXCLK, -1, -1, -1 },
536 .gate = { CGU_REG_CLKGR0, 14 },
539 [JZ4780_CLK_UART0] = {
540 "uart0", CGU_CLK_GATE,
541 .parents = { JZ4780_CLK_EXCLK, -1, -1, -1 },
542 .gate = { CGU_REG_CLKGR0, 15 },
545 [JZ4780_CLK_UART1] = {
546 "uart1", CGU_CLK_GATE,
547 .parents = { JZ4780_CLK_EXCLK, -1, -1, -1 },
548 .gate = { CGU_REG_CLKGR0, 16 },
551 [JZ4780_CLK_UART2] = {
552 "uart2", CGU_CLK_GATE,
553 .parents = { JZ4780_CLK_EXCLK, -1, -1, -1 },
554 .gate = { CGU_REG_CLKGR0, 17 },
557 [JZ4780_CLK_UART3] = {
558 "uart3", CGU_CLK_GATE,
559 .parents = { JZ4780_CLK_EXCLK, -1, -1, -1 },
560 .gate = { CGU_REG_CLKGR0, 18 },
563 [JZ4780_CLK_SSI1] = {
564 "ssi1", CGU_CLK_GATE,
565 .parents = { JZ4780_CLK_SSI, -1, -1, -1 },
566 .gate = { CGU_REG_CLKGR0, 19 },
569 [JZ4780_CLK_SSI2] = {
570 "ssi2", CGU_CLK_GATE,
571 .parents = { JZ4780_CLK_SSI, -1, -1, -1 },
572 .gate = { CGU_REG_CLKGR0, 20 },
575 [JZ4780_CLK_PDMA] = {
576 "pdma", CGU_CLK_GATE,
577 .parents = { JZ4780_CLK_EXCLK, -1, -1, -1 },
578 .gate = { CGU_REG_CLKGR0, 21 },
581 [JZ4780_CLK_GPS] = {
582 "gps", CGU_CLK_GATE,
583 .parents = { JZ4780_CLK_EXCLK, -1, -1, -1 },
584 .gate = { CGU_REG_CLKGR0, 22 },
587 [JZ4780_CLK_MAC] = {
588 "mac", CGU_CLK_GATE,
589 .parents = { JZ4780_CLK_EXCLK, -1, -1, -1 },
590 .gate = { CGU_REG_CLKGR0, 23 },
593 [JZ4780_CLK_SMB2] = {
594 "smb2", CGU_CLK_GATE,
595 .parents = { JZ4780_CLK_PCLK, -1, -1, -1 },
596 .gate = { CGU_REG_CLKGR0, 24 },
599 [JZ4780_CLK_CIM] = {
600 "cim", CGU_CLK_GATE,
601 .parents = { JZ4780_CLK_EXCLK, -1, -1, -1 },
602 .gate = { CGU_REG_CLKGR0, 26 },
605 [JZ4780_CLK_LCD] = {
606 "lcd", CGU_CLK_GATE,
607 .parents = { JZ4780_CLK_EXCLK, -1, -1, -1 },
608 .gate = { CGU_REG_CLKGR0, 28 },
611 [JZ4780_CLK_TVE] = {
612 "tve", CGU_CLK_GATE,
613 .parents = { JZ4780_CLK_LCD, -1, -1, -1 },
614 .gate = { CGU_REG_CLKGR0, 27 },
617 [JZ4780_CLK_IPU] = {
618 "ipu", CGU_CLK_GATE,
619 .parents = { JZ4780_CLK_EXCLK, -1, -1, -1 },
620 .gate = { CGU_REG_CLKGR0, 29 },
623 [JZ4780_CLK_DDR0] = {
624 "ddr0", CGU_CLK_GATE,
625 .parents = { JZ4780_CLK_DDR, -1, -1, -1 },
626 .gate = { CGU_REG_CLKGR0, 30 },
629 [JZ4780_CLK_DDR1] = {
630 "ddr1", CGU_CLK_GATE,
631 .parents = { JZ4780_CLK_DDR, -1, -1, -1 },
632 .gate = { CGU_REG_CLKGR0, 31 },
635 [JZ4780_CLK_SMB3] = {
636 "smb3", CGU_CLK_GATE,
637 .parents = { JZ4780_CLK_PCLK, -1, -1, -1 },
638 .gate = { CGU_REG_CLKGR1, 0 },
641 [JZ4780_CLK_TSSI1] = {
642 "tssi1", CGU_CLK_GATE,
643 .parents = { JZ4780_CLK_EXCLK, -1, -1, -1 },
644 .gate = { CGU_REG_CLKGR1, 1 },
647 [JZ4780_CLK_COMPRESS] = {
648 "compress", CGU_CLK_GATE,
649 .parents = { JZ4780_CLK_EXCLK, -1, -1, -1 },
650 .gate = { CGU_REG_CLKGR1, 5 },
653 [JZ4780_CLK_AIC1] = {
654 "aic1", CGU_CLK_GATE,
655 .parents = { JZ4780_CLK_EXCLK, -1, -1, -1 },
656 .gate = { CGU_REG_CLKGR1, 6 },
659 [JZ4780_CLK_GPVLC] = {
660 "gpvlc", CGU_CLK_GATE,
661 .parents = { JZ4780_CLK_EXCLK, -1, -1, -1 },
662 .gate = { CGU_REG_CLKGR1, 7 },
665 [JZ4780_CLK_OTG1] = {
666 "otg1", CGU_CLK_GATE,
667 .parents = { JZ4780_CLK_EXCLK, -1, -1, -1 },
668 .gate = { CGU_REG_CLKGR1, 8 },
671 [JZ4780_CLK_UART4] = {
672 "uart4", CGU_CLK_GATE,
673 .parents = { JZ4780_CLK_EXCLK, -1, -1, -1 },
674 .gate = { CGU_REG_CLKGR1, 10 },
677 [JZ4780_CLK_AHBMON] = {
678 "ahb_mon", CGU_CLK_GATE,
679 .parents = { JZ4780_CLK_EXCLK, -1, -1, -1 },
680 .gate = { CGU_REG_CLKGR1, 11 },
683 [JZ4780_CLK_SMB4] = {
684 "smb4", CGU_CLK_GATE,
685 .parents = { JZ4780_CLK_PCLK, -1, -1, -1 },
686 .gate = { CGU_REG_CLKGR1, 12 },
689 [JZ4780_CLK_DES] = {
690 "des", CGU_CLK_GATE,
691 .parents = { JZ4780_CLK_EXCLK, -1, -1, -1 },
692 .gate = { CGU_REG_CLKGR1, 13 },
695 [JZ4780_CLK_X2D] = {
696 "x2d", CGU_CLK_GATE,
697 .parents = { JZ4780_CLK_EXCLK, -1, -1, -1 },
698 .gate = { CGU_REG_CLKGR1, 14 },
701 [JZ4780_CLK_CORE1] = {
702 "core1", CGU_CLK_GATE,
703 .parents = { JZ4780_CLK_CPU, -1, -1, -1 },
704 .gate = { CGU_REG_CLKGR1, 15 },
709 static void __init jz4780_cgu_init(struct device_node *np)
711 int retval;
713 cgu = ingenic_cgu_new(jz4780_cgu_clocks,
714 ARRAY_SIZE(jz4780_cgu_clocks), np);
715 if (!cgu) {
716 pr_err("%s: failed to initialise CGU\n", __func__);
717 return;
720 retval = ingenic_cgu_register_clocks(cgu);
721 if (retval) {
722 pr_err("%s: failed to register CGU Clocks\n", __func__);
723 return;
726 ingenic_cgu_register_syscore_ops(cgu);
728 CLK_OF_DECLARE_DRIVER(jz4780_cgu, "ingenic,jz4780-cgu", jz4780_cgu_init);