xref: /openbmc/linux/drivers/clk/ingenic/x1830-cgu.c (revision ce1d86dc92496af8edf58b0870fd24980d63748e)
1*ce1d86dcS周琰杰 (Zhou Yanjie) // SPDX-License-Identifier: GPL-2.0
2*ce1d86dcS周琰杰 (Zhou Yanjie) /*
3*ce1d86dcS周琰杰 (Zhou Yanjie)  * X1830 SoC CGU driver
4*ce1d86dcS周琰杰 (Zhou Yanjie)  * Copyright (c) 2019 周琰杰 (Zhou Yanjie) <zhouyanjie@wanyeetech.com>
5*ce1d86dcS周琰杰 (Zhou Yanjie)  */
6*ce1d86dcS周琰杰 (Zhou Yanjie) 
7*ce1d86dcS周琰杰 (Zhou Yanjie) #include <linux/clk-provider.h>
8*ce1d86dcS周琰杰 (Zhou Yanjie) #include <linux/delay.h>
9*ce1d86dcS周琰杰 (Zhou Yanjie) #include <linux/io.h>
10*ce1d86dcS周琰杰 (Zhou Yanjie) #include <linux/of.h>
11*ce1d86dcS周琰杰 (Zhou Yanjie) 
12*ce1d86dcS周琰杰 (Zhou Yanjie) #include <dt-bindings/clock/x1830-cgu.h>
13*ce1d86dcS周琰杰 (Zhou Yanjie) 
14*ce1d86dcS周琰杰 (Zhou Yanjie) #include "cgu.h"
15*ce1d86dcS周琰杰 (Zhou Yanjie) #include "pm.h"
16*ce1d86dcS周琰杰 (Zhou Yanjie) 
17*ce1d86dcS周琰杰 (Zhou Yanjie) /* CGU register offsets */
18*ce1d86dcS周琰杰 (Zhou Yanjie) #define CGU_REG_CPCCR		0x00
19*ce1d86dcS周琰杰 (Zhou Yanjie) #define CGU_REG_CPPCR		0x0c
20*ce1d86dcS周琰杰 (Zhou Yanjie) #define CGU_REG_APLL		0x10
21*ce1d86dcS周琰杰 (Zhou Yanjie) #define CGU_REG_MPLL		0x14
22*ce1d86dcS周琰杰 (Zhou Yanjie) #define CGU_REG_CLKGR0		0x20
23*ce1d86dcS周琰杰 (Zhou Yanjie) #define CGU_REG_OPCR		0x24
24*ce1d86dcS周琰杰 (Zhou Yanjie) #define CGU_REG_CLKGR1		0x28
25*ce1d86dcS周琰杰 (Zhou Yanjie) #define CGU_REG_DDRCDR		0x2c
26*ce1d86dcS周琰杰 (Zhou Yanjie) #define CGU_REG_USBPCR		0x3c
27*ce1d86dcS周琰杰 (Zhou Yanjie) #define CGU_REG_USBRDT		0x40
28*ce1d86dcS周琰杰 (Zhou Yanjie) #define CGU_REG_USBVBFIL	0x44
29*ce1d86dcS周琰杰 (Zhou Yanjie) #define CGU_REG_USBPCR1		0x48
30*ce1d86dcS周琰杰 (Zhou Yanjie) #define CGU_REG_MACCDR		0x54
31*ce1d86dcS周琰杰 (Zhou Yanjie) #define CGU_REG_EPLL		0x58
32*ce1d86dcS周琰杰 (Zhou Yanjie) #define CGU_REG_I2SCDR		0x60
33*ce1d86dcS周琰杰 (Zhou Yanjie) #define CGU_REG_LPCDR		0x64
34*ce1d86dcS周琰杰 (Zhou Yanjie) #define CGU_REG_MSC0CDR		0x68
35*ce1d86dcS周琰杰 (Zhou Yanjie) #define CGU_REG_I2SCDR1		0x70
36*ce1d86dcS周琰杰 (Zhou Yanjie) #define CGU_REG_SSICDR		0x74
37*ce1d86dcS周琰杰 (Zhou Yanjie) #define CGU_REG_CIMCDR		0x7c
38*ce1d86dcS周琰杰 (Zhou Yanjie) #define CGU_REG_MSC1CDR		0xa4
39*ce1d86dcS周琰杰 (Zhou Yanjie) #define CGU_REG_CMP_INTR	0xb0
40*ce1d86dcS周琰杰 (Zhou Yanjie) #define CGU_REG_CMP_INTRE	0xb4
41*ce1d86dcS周琰杰 (Zhou Yanjie) #define CGU_REG_DRCG		0xd0
42*ce1d86dcS周琰杰 (Zhou Yanjie) #define CGU_REG_CPCSR		0xd4
43*ce1d86dcS周琰杰 (Zhou Yanjie) #define CGU_REG_VPLL		0xe0
44*ce1d86dcS周琰杰 (Zhou Yanjie) #define CGU_REG_MACPHYC		0xe8
45*ce1d86dcS周琰杰 (Zhou Yanjie) 
46*ce1d86dcS周琰杰 (Zhou Yanjie) /* bits within the OPCR register */
47*ce1d86dcS周琰杰 (Zhou Yanjie) #define OPCR_GATE_USBPHYCLK	BIT(23)
48*ce1d86dcS周琰杰 (Zhou Yanjie) #define OPCR_SPENDN0		BIT(7)
49*ce1d86dcS周琰杰 (Zhou Yanjie) #define OPCR_SPENDN1		BIT(6)
50*ce1d86dcS周琰杰 (Zhou Yanjie) 
51*ce1d86dcS周琰杰 (Zhou Yanjie) /* bits within the USBPCR register */
52*ce1d86dcS周琰杰 (Zhou Yanjie) #define USBPCR_SIDDQ		BIT(21)
53*ce1d86dcS周琰杰 (Zhou Yanjie) #define USBPCR_OTG_DISABLE	BIT(20)
54*ce1d86dcS周琰杰 (Zhou Yanjie) 
55*ce1d86dcS周琰杰 (Zhou Yanjie) static struct ingenic_cgu *cgu;
56*ce1d86dcS周琰杰 (Zhou Yanjie) 
57*ce1d86dcS周琰杰 (Zhou Yanjie) static int x1830_usb_phy_enable(struct clk_hw *hw)
58*ce1d86dcS周琰杰 (Zhou Yanjie) {
59*ce1d86dcS周琰杰 (Zhou Yanjie) 	void __iomem *reg_opcr		= cgu->base + CGU_REG_OPCR;
60*ce1d86dcS周琰杰 (Zhou Yanjie) 	void __iomem *reg_usbpcr	= cgu->base + CGU_REG_USBPCR;
61*ce1d86dcS周琰杰 (Zhou Yanjie) 
62*ce1d86dcS周琰杰 (Zhou Yanjie) 	writel((readl(reg_opcr) | OPCR_SPENDN0) & ~OPCR_GATE_USBPHYCLK, reg_opcr);
63*ce1d86dcS周琰杰 (Zhou Yanjie) 	writel(readl(reg_usbpcr) & ~USBPCR_OTG_DISABLE & ~USBPCR_SIDDQ, reg_usbpcr);
64*ce1d86dcS周琰杰 (Zhou Yanjie) 	return 0;
65*ce1d86dcS周琰杰 (Zhou Yanjie) }
66*ce1d86dcS周琰杰 (Zhou Yanjie) 
67*ce1d86dcS周琰杰 (Zhou Yanjie) static void x1830_usb_phy_disable(struct clk_hw *hw)
68*ce1d86dcS周琰杰 (Zhou Yanjie) {
69*ce1d86dcS周琰杰 (Zhou Yanjie) 	void __iomem *reg_opcr		= cgu->base + CGU_REG_OPCR;
70*ce1d86dcS周琰杰 (Zhou Yanjie) 	void __iomem *reg_usbpcr	= cgu->base + CGU_REG_USBPCR;
71*ce1d86dcS周琰杰 (Zhou Yanjie) 
72*ce1d86dcS周琰杰 (Zhou Yanjie) 	writel((readl(reg_opcr) & ~OPCR_SPENDN0) | OPCR_GATE_USBPHYCLK, reg_opcr);
73*ce1d86dcS周琰杰 (Zhou Yanjie) 	writel(readl(reg_usbpcr) | USBPCR_OTG_DISABLE | USBPCR_SIDDQ, reg_usbpcr);
74*ce1d86dcS周琰杰 (Zhou Yanjie) }
75*ce1d86dcS周琰杰 (Zhou Yanjie) 
76*ce1d86dcS周琰杰 (Zhou Yanjie) static int x1830_usb_phy_is_enabled(struct clk_hw *hw)
77*ce1d86dcS周琰杰 (Zhou Yanjie) {
78*ce1d86dcS周琰杰 (Zhou Yanjie) 	void __iomem *reg_opcr		= cgu->base + CGU_REG_OPCR;
79*ce1d86dcS周琰杰 (Zhou Yanjie) 	void __iomem *reg_usbpcr	= cgu->base + CGU_REG_USBPCR;
80*ce1d86dcS周琰杰 (Zhou Yanjie) 
81*ce1d86dcS周琰杰 (Zhou Yanjie) 	return (readl(reg_opcr) & OPCR_SPENDN0) &&
82*ce1d86dcS周琰杰 (Zhou Yanjie) 		!(readl(reg_usbpcr) & USBPCR_SIDDQ) &&
83*ce1d86dcS周琰杰 (Zhou Yanjie) 		!(readl(reg_usbpcr) & USBPCR_OTG_DISABLE);
84*ce1d86dcS周琰杰 (Zhou Yanjie) }
85*ce1d86dcS周琰杰 (Zhou Yanjie) 
86*ce1d86dcS周琰杰 (Zhou Yanjie) static const struct clk_ops x1830_otg_phy_ops = {
87*ce1d86dcS周琰杰 (Zhou Yanjie) 	.enable		= x1830_usb_phy_enable,
88*ce1d86dcS周琰杰 (Zhou Yanjie) 	.disable	= x1830_usb_phy_disable,
89*ce1d86dcS周琰杰 (Zhou Yanjie) 	.is_enabled	= x1830_usb_phy_is_enabled,
90*ce1d86dcS周琰杰 (Zhou Yanjie) };
91*ce1d86dcS周琰杰 (Zhou Yanjie) 
92*ce1d86dcS周琰杰 (Zhou Yanjie) static const s8 pll_od_encoding[64] = {
93*ce1d86dcS周琰杰 (Zhou Yanjie) 	0x0, 0x1,  -1, 0x2,  -1,  -1,  -1, 0x3,
94*ce1d86dcS周琰杰 (Zhou Yanjie) 	 -1,  -1,  -1,  -1,  -1,  -1,  -1, 0x4,
95*ce1d86dcS周琰杰 (Zhou Yanjie) 	 -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,
96*ce1d86dcS周琰杰 (Zhou Yanjie) 	 -1,  -1,  -1,  -1,  -1,  -1,  -1, 0x5,
97*ce1d86dcS周琰杰 (Zhou Yanjie) 	 -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,
98*ce1d86dcS周琰杰 (Zhou Yanjie) 	 -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,
99*ce1d86dcS周琰杰 (Zhou Yanjie) 	 -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,
100*ce1d86dcS周琰杰 (Zhou Yanjie) 	 -1,  -1,  -1,  -1,  -1,  -1,  -1, 0x6,
101*ce1d86dcS周琰杰 (Zhou Yanjie) };
102*ce1d86dcS周琰杰 (Zhou Yanjie) 
103*ce1d86dcS周琰杰 (Zhou Yanjie) static const struct ingenic_cgu_clk_info x1830_cgu_clocks[] = {
104*ce1d86dcS周琰杰 (Zhou Yanjie) 
105*ce1d86dcS周琰杰 (Zhou Yanjie) 	/* External clocks */
106*ce1d86dcS周琰杰 (Zhou Yanjie) 
107*ce1d86dcS周琰杰 (Zhou Yanjie) 	[X1830_CLK_EXCLK] = { "ext", CGU_CLK_EXT },
108*ce1d86dcS周琰杰 (Zhou Yanjie) 	[X1830_CLK_RTCLK] = { "rtc", CGU_CLK_EXT },
109*ce1d86dcS周琰杰 (Zhou Yanjie) 
110*ce1d86dcS周琰杰 (Zhou Yanjie) 	/* PLLs */
111*ce1d86dcS周琰杰 (Zhou Yanjie) 
112*ce1d86dcS周琰杰 (Zhou Yanjie) 	[X1830_CLK_APLL] = {
113*ce1d86dcS周琰杰 (Zhou Yanjie) 		"apll", CGU_CLK_PLL,
114*ce1d86dcS周琰杰 (Zhou Yanjie) 		.parents = { X1830_CLK_EXCLK, -1, -1, -1 },
115*ce1d86dcS周琰杰 (Zhou Yanjie) 		.pll = {
116*ce1d86dcS周琰杰 (Zhou Yanjie) 			.reg = CGU_REG_APLL,
117*ce1d86dcS周琰杰 (Zhou Yanjie) 			.rate_multiplier = 2,
118*ce1d86dcS周琰杰 (Zhou Yanjie) 			.m_shift = 20,
119*ce1d86dcS周琰杰 (Zhou Yanjie) 			.m_bits = 9,
120*ce1d86dcS周琰杰 (Zhou Yanjie) 			.m_offset = 1,
121*ce1d86dcS周琰杰 (Zhou Yanjie) 			.n_shift = 14,
122*ce1d86dcS周琰杰 (Zhou Yanjie) 			.n_bits = 6,
123*ce1d86dcS周琰杰 (Zhou Yanjie) 			.n_offset = 1,
124*ce1d86dcS周琰杰 (Zhou Yanjie) 			.od_shift = 11,
125*ce1d86dcS周琰杰 (Zhou Yanjie) 			.od_bits = 3,
126*ce1d86dcS周琰杰 (Zhou Yanjie) 			.od_max = 64,
127*ce1d86dcS周琰杰 (Zhou Yanjie) 			.od_encoding = pll_od_encoding,
128*ce1d86dcS周琰杰 (Zhou Yanjie) 			.bypass_reg = CGU_REG_CPPCR,
129*ce1d86dcS周琰杰 (Zhou Yanjie) 			.bypass_bit = 30,
130*ce1d86dcS周琰杰 (Zhou Yanjie) 			.enable_bit = 0,
131*ce1d86dcS周琰杰 (Zhou Yanjie) 			.stable_bit = 3,
132*ce1d86dcS周琰杰 (Zhou Yanjie) 		},
133*ce1d86dcS周琰杰 (Zhou Yanjie) 	},
134*ce1d86dcS周琰杰 (Zhou Yanjie) 
135*ce1d86dcS周琰杰 (Zhou Yanjie) 	[X1830_CLK_MPLL] = {
136*ce1d86dcS周琰杰 (Zhou Yanjie) 		"mpll", CGU_CLK_PLL,
137*ce1d86dcS周琰杰 (Zhou Yanjie) 		.parents = { X1830_CLK_EXCLK, -1, -1, -1 },
138*ce1d86dcS周琰杰 (Zhou Yanjie) 		.pll = {
139*ce1d86dcS周琰杰 (Zhou Yanjie) 			.reg = CGU_REG_MPLL,
140*ce1d86dcS周琰杰 (Zhou Yanjie) 			.rate_multiplier = 2,
141*ce1d86dcS周琰杰 (Zhou Yanjie) 			.m_shift = 20,
142*ce1d86dcS周琰杰 (Zhou Yanjie) 			.m_bits = 9,
143*ce1d86dcS周琰杰 (Zhou Yanjie) 			.m_offset = 1,
144*ce1d86dcS周琰杰 (Zhou Yanjie) 			.n_shift = 14,
145*ce1d86dcS周琰杰 (Zhou Yanjie) 			.n_bits = 6,
146*ce1d86dcS周琰杰 (Zhou Yanjie) 			.n_offset = 1,
147*ce1d86dcS周琰杰 (Zhou Yanjie) 			.od_shift = 11,
148*ce1d86dcS周琰杰 (Zhou Yanjie) 			.od_bits = 3,
149*ce1d86dcS周琰杰 (Zhou Yanjie) 			.od_max = 64,
150*ce1d86dcS周琰杰 (Zhou Yanjie) 			.od_encoding = pll_od_encoding,
151*ce1d86dcS周琰杰 (Zhou Yanjie) 			.bypass_reg = CGU_REG_CPPCR,
152*ce1d86dcS周琰杰 (Zhou Yanjie) 			.bypass_bit = 28,
153*ce1d86dcS周琰杰 (Zhou Yanjie) 			.enable_bit = 0,
154*ce1d86dcS周琰杰 (Zhou Yanjie) 			.stable_bit = 3,
155*ce1d86dcS周琰杰 (Zhou Yanjie) 		},
156*ce1d86dcS周琰杰 (Zhou Yanjie) 	},
157*ce1d86dcS周琰杰 (Zhou Yanjie) 
158*ce1d86dcS周琰杰 (Zhou Yanjie) 	[X1830_CLK_EPLL] = {
159*ce1d86dcS周琰杰 (Zhou Yanjie) 		"epll", CGU_CLK_PLL,
160*ce1d86dcS周琰杰 (Zhou Yanjie) 		.parents = { X1830_CLK_EXCLK, -1, -1, -1 },
161*ce1d86dcS周琰杰 (Zhou Yanjie) 		.pll = {
162*ce1d86dcS周琰杰 (Zhou Yanjie) 			.reg = CGU_REG_EPLL,
163*ce1d86dcS周琰杰 (Zhou Yanjie) 			.rate_multiplier = 2,
164*ce1d86dcS周琰杰 (Zhou Yanjie) 			.m_shift = 20,
165*ce1d86dcS周琰杰 (Zhou Yanjie) 			.m_bits = 9,
166*ce1d86dcS周琰杰 (Zhou Yanjie) 			.m_offset = 1,
167*ce1d86dcS周琰杰 (Zhou Yanjie) 			.n_shift = 14,
168*ce1d86dcS周琰杰 (Zhou Yanjie) 			.n_bits = 6,
169*ce1d86dcS周琰杰 (Zhou Yanjie) 			.n_offset = 1,
170*ce1d86dcS周琰杰 (Zhou Yanjie) 			.od_shift = 11,
171*ce1d86dcS周琰杰 (Zhou Yanjie) 			.od_bits = 3,
172*ce1d86dcS周琰杰 (Zhou Yanjie) 			.od_max = 64,
173*ce1d86dcS周琰杰 (Zhou Yanjie) 			.od_encoding = pll_od_encoding,
174*ce1d86dcS周琰杰 (Zhou Yanjie) 			.bypass_reg = CGU_REG_CPPCR,
175*ce1d86dcS周琰杰 (Zhou Yanjie) 			.bypass_bit = 24,
176*ce1d86dcS周琰杰 (Zhou Yanjie) 			.enable_bit = 0,
177*ce1d86dcS周琰杰 (Zhou Yanjie) 			.stable_bit = 3,
178*ce1d86dcS周琰杰 (Zhou Yanjie) 		},
179*ce1d86dcS周琰杰 (Zhou Yanjie) 	},
180*ce1d86dcS周琰杰 (Zhou Yanjie) 
181*ce1d86dcS周琰杰 (Zhou Yanjie) 	[X1830_CLK_VPLL] = {
182*ce1d86dcS周琰杰 (Zhou Yanjie) 		"vpll", CGU_CLK_PLL,
183*ce1d86dcS周琰杰 (Zhou Yanjie) 		.parents = { X1830_CLK_EXCLK, -1, -1, -1 },
184*ce1d86dcS周琰杰 (Zhou Yanjie) 		.pll = {
185*ce1d86dcS周琰杰 (Zhou Yanjie) 			.reg = CGU_REG_VPLL,
186*ce1d86dcS周琰杰 (Zhou Yanjie) 			.rate_multiplier = 2,
187*ce1d86dcS周琰杰 (Zhou Yanjie) 			.m_shift = 20,
188*ce1d86dcS周琰杰 (Zhou Yanjie) 			.m_bits = 9,
189*ce1d86dcS周琰杰 (Zhou Yanjie) 			.m_offset = 1,
190*ce1d86dcS周琰杰 (Zhou Yanjie) 			.n_shift = 14,
191*ce1d86dcS周琰杰 (Zhou Yanjie) 			.n_bits = 6,
192*ce1d86dcS周琰杰 (Zhou Yanjie) 			.n_offset = 1,
193*ce1d86dcS周琰杰 (Zhou Yanjie) 			.od_shift = 11,
194*ce1d86dcS周琰杰 (Zhou Yanjie) 			.od_bits = 3,
195*ce1d86dcS周琰杰 (Zhou Yanjie) 			.od_max = 64,
196*ce1d86dcS周琰杰 (Zhou Yanjie) 			.od_encoding = pll_od_encoding,
197*ce1d86dcS周琰杰 (Zhou Yanjie) 			.bypass_reg = CGU_REG_CPPCR,
198*ce1d86dcS周琰杰 (Zhou Yanjie) 			.bypass_bit = 26,
199*ce1d86dcS周琰杰 (Zhou Yanjie) 			.enable_bit = 0,
200*ce1d86dcS周琰杰 (Zhou Yanjie) 			.stable_bit = 3,
201*ce1d86dcS周琰杰 (Zhou Yanjie) 		},
202*ce1d86dcS周琰杰 (Zhou Yanjie) 	},
203*ce1d86dcS周琰杰 (Zhou Yanjie) 
204*ce1d86dcS周琰杰 (Zhou Yanjie) 	/* Custom (SoC-specific) OTG PHY */
205*ce1d86dcS周琰杰 (Zhou Yanjie) 
206*ce1d86dcS周琰杰 (Zhou Yanjie) 	[X1830_CLK_OTGPHY] = {
207*ce1d86dcS周琰杰 (Zhou Yanjie) 		"otg_phy", CGU_CLK_CUSTOM,
208*ce1d86dcS周琰杰 (Zhou Yanjie) 		.parents = { X1830_CLK_EXCLK, -1, -1, -1 },
209*ce1d86dcS周琰杰 (Zhou Yanjie) 		.custom = { &x1830_otg_phy_ops },
210*ce1d86dcS周琰杰 (Zhou Yanjie) 	},
211*ce1d86dcS周琰杰 (Zhou Yanjie) 
212*ce1d86dcS周琰杰 (Zhou Yanjie) 	/* Muxes & dividers */
213*ce1d86dcS周琰杰 (Zhou Yanjie) 
214*ce1d86dcS周琰杰 (Zhou Yanjie) 	[X1830_CLK_SCLKA] = {
215*ce1d86dcS周琰杰 (Zhou Yanjie) 		"sclk_a", CGU_CLK_MUX,
216*ce1d86dcS周琰杰 (Zhou Yanjie) 		.parents = { -1, X1830_CLK_EXCLK, X1830_CLK_APLL, -1 },
217*ce1d86dcS周琰杰 (Zhou Yanjie) 		.mux = { CGU_REG_CPCCR, 30, 2 },
218*ce1d86dcS周琰杰 (Zhou Yanjie) 	},
219*ce1d86dcS周琰杰 (Zhou Yanjie) 
220*ce1d86dcS周琰杰 (Zhou Yanjie) 	[X1830_CLK_CPUMUX] = {
221*ce1d86dcS周琰杰 (Zhou Yanjie) 		"cpu_mux", CGU_CLK_MUX,
222*ce1d86dcS周琰杰 (Zhou Yanjie) 		.parents = { -1, X1830_CLK_SCLKA, X1830_CLK_MPLL, -1 },
223*ce1d86dcS周琰杰 (Zhou Yanjie) 		.mux = { CGU_REG_CPCCR, 28, 2 },
224*ce1d86dcS周琰杰 (Zhou Yanjie) 	},
225*ce1d86dcS周琰杰 (Zhou Yanjie) 
226*ce1d86dcS周琰杰 (Zhou Yanjie) 	[X1830_CLK_CPU] = {
227*ce1d86dcS周琰杰 (Zhou Yanjie) 		"cpu", CGU_CLK_DIV | CGU_CLK_GATE,
228*ce1d86dcS周琰杰 (Zhou Yanjie) 		.parents = { X1830_CLK_CPUMUX, -1, -1, -1 },
229*ce1d86dcS周琰杰 (Zhou Yanjie) 		.div = { CGU_REG_CPCCR, 0, 1, 4, 22, -1, -1 },
230*ce1d86dcS周琰杰 (Zhou Yanjie) 		.gate = { CGU_REG_CLKGR1, 15 },
231*ce1d86dcS周琰杰 (Zhou Yanjie) 	},
232*ce1d86dcS周琰杰 (Zhou Yanjie) 
233*ce1d86dcS周琰杰 (Zhou Yanjie) 	[X1830_CLK_L2CACHE] = {
234*ce1d86dcS周琰杰 (Zhou Yanjie) 		"l2cache", CGU_CLK_DIV,
235*ce1d86dcS周琰杰 (Zhou Yanjie) 		.parents = { X1830_CLK_CPUMUX, -1, -1, -1 },
236*ce1d86dcS周琰杰 (Zhou Yanjie) 		.div = { CGU_REG_CPCCR, 4, 1, 4, 22, -1, -1 },
237*ce1d86dcS周琰杰 (Zhou Yanjie) 	},
238*ce1d86dcS周琰杰 (Zhou Yanjie) 
239*ce1d86dcS周琰杰 (Zhou Yanjie) 	[X1830_CLK_AHB0] = {
240*ce1d86dcS周琰杰 (Zhou Yanjie) 		"ahb0", CGU_CLK_MUX | CGU_CLK_DIV,
241*ce1d86dcS周琰杰 (Zhou Yanjie) 		.parents = { -1, X1830_CLK_SCLKA, X1830_CLK_MPLL, -1 },
242*ce1d86dcS周琰杰 (Zhou Yanjie) 		.mux = { CGU_REG_CPCCR, 26, 2 },
243*ce1d86dcS周琰杰 (Zhou Yanjie) 		.div = { CGU_REG_CPCCR, 8, 1, 4, 21, -1, -1 },
244*ce1d86dcS周琰杰 (Zhou Yanjie) 	},
245*ce1d86dcS周琰杰 (Zhou Yanjie) 
246*ce1d86dcS周琰杰 (Zhou Yanjie) 	[X1830_CLK_AHB2PMUX] = {
247*ce1d86dcS周琰杰 (Zhou Yanjie) 		"ahb2_apb_mux", CGU_CLK_MUX,
248*ce1d86dcS周琰杰 (Zhou Yanjie) 		.parents = { -1, X1830_CLK_SCLKA, X1830_CLK_MPLL, -1 },
249*ce1d86dcS周琰杰 (Zhou Yanjie) 		.mux = { CGU_REG_CPCCR, 24, 2 },
250*ce1d86dcS周琰杰 (Zhou Yanjie) 	},
251*ce1d86dcS周琰杰 (Zhou Yanjie) 
252*ce1d86dcS周琰杰 (Zhou Yanjie) 	[X1830_CLK_AHB2] = {
253*ce1d86dcS周琰杰 (Zhou Yanjie) 		"ahb2", CGU_CLK_DIV,
254*ce1d86dcS周琰杰 (Zhou Yanjie) 		.parents = { X1830_CLK_AHB2PMUX, -1, -1, -1 },
255*ce1d86dcS周琰杰 (Zhou Yanjie) 		.div = { CGU_REG_CPCCR, 12, 1, 4, 20, -1, -1 },
256*ce1d86dcS周琰杰 (Zhou Yanjie) 	},
257*ce1d86dcS周琰杰 (Zhou Yanjie) 
258*ce1d86dcS周琰杰 (Zhou Yanjie) 	[X1830_CLK_PCLK] = {
259*ce1d86dcS周琰杰 (Zhou Yanjie) 		"pclk", CGU_CLK_DIV | CGU_CLK_GATE,
260*ce1d86dcS周琰杰 (Zhou Yanjie) 		.parents = { X1830_CLK_AHB2PMUX, -1, -1, -1 },
261*ce1d86dcS周琰杰 (Zhou Yanjie) 		.div = { CGU_REG_CPCCR, 16, 1, 4, 20, -1, -1 },
262*ce1d86dcS周琰杰 (Zhou Yanjie) 		.gate = { CGU_REG_CLKGR1, 14 },
263*ce1d86dcS周琰杰 (Zhou Yanjie) 	},
264*ce1d86dcS周琰杰 (Zhou Yanjie) 
265*ce1d86dcS周琰杰 (Zhou Yanjie) 	[X1830_CLK_DDR] = {
266*ce1d86dcS周琰杰 (Zhou Yanjie) 		"ddr", CGU_CLK_MUX | CGU_CLK_DIV | CGU_CLK_GATE,
267*ce1d86dcS周琰杰 (Zhou Yanjie) 		.parents = { -1, X1830_CLK_SCLKA, X1830_CLK_MPLL, -1 },
268*ce1d86dcS周琰杰 (Zhou Yanjie) 		.mux = { CGU_REG_DDRCDR, 30, 2 },
269*ce1d86dcS周琰杰 (Zhou Yanjie) 		.div = { CGU_REG_DDRCDR, 0, 1, 4, 29, 28, 27 },
270*ce1d86dcS周琰杰 (Zhou Yanjie) 		.gate = { CGU_REG_CLKGR0, 31 },
271*ce1d86dcS周琰杰 (Zhou Yanjie) 	},
272*ce1d86dcS周琰杰 (Zhou Yanjie) 
273*ce1d86dcS周琰杰 (Zhou Yanjie) 	[X1830_CLK_MAC] = {
274*ce1d86dcS周琰杰 (Zhou Yanjie) 		"mac", CGU_CLK_MUX | CGU_CLK_DIV | CGU_CLK_GATE,
275*ce1d86dcS周琰杰 (Zhou Yanjie) 		.parents = { X1830_CLK_SCLKA, X1830_CLK_MPLL,
276*ce1d86dcS周琰杰 (Zhou Yanjie) 					 X1830_CLK_VPLL, X1830_CLK_EPLL },
277*ce1d86dcS周琰杰 (Zhou Yanjie) 		.mux = { CGU_REG_MACCDR, 30, 2 },
278*ce1d86dcS周琰杰 (Zhou Yanjie) 		.div = { CGU_REG_MACCDR, 0, 1, 8, 29, 28, 27 },
279*ce1d86dcS周琰杰 (Zhou Yanjie) 		.gate = { CGU_REG_CLKGR1, 4 },
280*ce1d86dcS周琰杰 (Zhou Yanjie) 	},
281*ce1d86dcS周琰杰 (Zhou Yanjie) 
282*ce1d86dcS周琰杰 (Zhou Yanjie) 	[X1830_CLK_LCD] = {
283*ce1d86dcS周琰杰 (Zhou Yanjie) 		"lcd", CGU_CLK_MUX | CGU_CLK_DIV | CGU_CLK_GATE,
284*ce1d86dcS周琰杰 (Zhou Yanjie) 		.parents = { X1830_CLK_SCLKA, X1830_CLK_MPLL,
285*ce1d86dcS周琰杰 (Zhou Yanjie) 					 X1830_CLK_VPLL, X1830_CLK_EPLL },
286*ce1d86dcS周琰杰 (Zhou Yanjie) 		.mux = { CGU_REG_LPCDR, 30, 2 },
287*ce1d86dcS周琰杰 (Zhou Yanjie) 		.div = { CGU_REG_LPCDR, 0, 1, 8, 28, 27, 26 },
288*ce1d86dcS周琰杰 (Zhou Yanjie) 		.gate = { CGU_REG_CLKGR1, 9 },
289*ce1d86dcS周琰杰 (Zhou Yanjie) 	},
290*ce1d86dcS周琰杰 (Zhou Yanjie) 
291*ce1d86dcS周琰杰 (Zhou Yanjie) 	[X1830_CLK_MSCMUX] = {
292*ce1d86dcS周琰杰 (Zhou Yanjie) 		"msc_mux", CGU_CLK_MUX,
293*ce1d86dcS周琰杰 (Zhou Yanjie) 		.parents = { X1830_CLK_SCLKA, X1830_CLK_MPLL,
294*ce1d86dcS周琰杰 (Zhou Yanjie) 					 X1830_CLK_VPLL, X1830_CLK_EPLL },
295*ce1d86dcS周琰杰 (Zhou Yanjie) 		.mux = { CGU_REG_MSC0CDR, 30, 2 },
296*ce1d86dcS周琰杰 (Zhou Yanjie) 	},
297*ce1d86dcS周琰杰 (Zhou Yanjie) 
298*ce1d86dcS周琰杰 (Zhou Yanjie) 	[X1830_CLK_MSC0] = {
299*ce1d86dcS周琰杰 (Zhou Yanjie) 		"msc0", CGU_CLK_DIV | CGU_CLK_GATE,
300*ce1d86dcS周琰杰 (Zhou Yanjie) 		.parents = { X1830_CLK_MSCMUX, -1, -1, -1 },
301*ce1d86dcS周琰杰 (Zhou Yanjie) 		.div = { CGU_REG_MSC0CDR, 0, 2, 8, 29, 28, 27 },
302*ce1d86dcS周琰杰 (Zhou Yanjie) 		.gate = { CGU_REG_CLKGR0, 4 },
303*ce1d86dcS周琰杰 (Zhou Yanjie) 	},
304*ce1d86dcS周琰杰 (Zhou Yanjie) 
305*ce1d86dcS周琰杰 (Zhou Yanjie) 	[X1830_CLK_MSC1] = {
306*ce1d86dcS周琰杰 (Zhou Yanjie) 		"msc1", CGU_CLK_DIV | CGU_CLK_GATE,
307*ce1d86dcS周琰杰 (Zhou Yanjie) 		.parents = { X1830_CLK_MSCMUX, -1, -1, -1 },
308*ce1d86dcS周琰杰 (Zhou Yanjie) 		.div = { CGU_REG_MSC1CDR, 0, 2, 8, 29, 28, 27 },
309*ce1d86dcS周琰杰 (Zhou Yanjie) 		.gate = { CGU_REG_CLKGR0, 5 },
310*ce1d86dcS周琰杰 (Zhou Yanjie) 	},
311*ce1d86dcS周琰杰 (Zhou Yanjie) 
312*ce1d86dcS周琰杰 (Zhou Yanjie) 	[X1830_CLK_SSIPLL] = {
313*ce1d86dcS周琰杰 (Zhou Yanjie) 		"ssi_pll", CGU_CLK_MUX | CGU_CLK_DIV,
314*ce1d86dcS周琰杰 (Zhou Yanjie) 		.parents = { X1830_CLK_SCLKA, X1830_CLK_MPLL,
315*ce1d86dcS周琰杰 (Zhou Yanjie) 					 X1830_CLK_VPLL, X1830_CLK_EPLL },
316*ce1d86dcS周琰杰 (Zhou Yanjie) 		.mux = { CGU_REG_SSICDR, 30, 2 },
317*ce1d86dcS周琰杰 (Zhou Yanjie) 		.div = { CGU_REG_SSICDR, 0, 1, 8, 28, 27, 26 },
318*ce1d86dcS周琰杰 (Zhou Yanjie) 	},
319*ce1d86dcS周琰杰 (Zhou Yanjie) 
320*ce1d86dcS周琰杰 (Zhou Yanjie) 	[X1830_CLK_SSIPLL_DIV2] = {
321*ce1d86dcS周琰杰 (Zhou Yanjie) 		"ssi_pll_div2", CGU_CLK_FIXDIV,
322*ce1d86dcS周琰杰 (Zhou Yanjie) 		.parents = { X1830_CLK_SSIPLL },
323*ce1d86dcS周琰杰 (Zhou Yanjie) 		.fixdiv = { 2 },
324*ce1d86dcS周琰杰 (Zhou Yanjie) 	},
325*ce1d86dcS周琰杰 (Zhou Yanjie) 
326*ce1d86dcS周琰杰 (Zhou Yanjie) 	[X1830_CLK_SSIMUX] = {
327*ce1d86dcS周琰杰 (Zhou Yanjie) 		"ssi_mux", CGU_CLK_MUX,
328*ce1d86dcS周琰杰 (Zhou Yanjie) 		.parents = { X1830_CLK_EXCLK, X1830_CLK_SSIPLL_DIV2, -1, -1 },
329*ce1d86dcS周琰杰 (Zhou Yanjie) 		.mux = { CGU_REG_SSICDR, 29, 1 },
330*ce1d86dcS周琰杰 (Zhou Yanjie) 	},
331*ce1d86dcS周琰杰 (Zhou Yanjie) 
332*ce1d86dcS周琰杰 (Zhou Yanjie) 	/* Gate-only clocks */
333*ce1d86dcS周琰杰 (Zhou Yanjie) 
334*ce1d86dcS周琰杰 (Zhou Yanjie) 	[X1830_CLK_EMC] = {
335*ce1d86dcS周琰杰 (Zhou Yanjie) 		"emc", CGU_CLK_GATE,
336*ce1d86dcS周琰杰 (Zhou Yanjie) 		.parents = { X1830_CLK_AHB2, -1, -1, -1 },
337*ce1d86dcS周琰杰 (Zhou Yanjie) 		.gate = { CGU_REG_CLKGR0, 0 },
338*ce1d86dcS周琰杰 (Zhou Yanjie) 	},
339*ce1d86dcS周琰杰 (Zhou Yanjie) 
340*ce1d86dcS周琰杰 (Zhou Yanjie) 	[X1830_CLK_EFUSE] = {
341*ce1d86dcS周琰杰 (Zhou Yanjie) 		"efuse", CGU_CLK_GATE,
342*ce1d86dcS周琰杰 (Zhou Yanjie) 		.parents = { X1830_CLK_AHB2, -1, -1, -1 },
343*ce1d86dcS周琰杰 (Zhou Yanjie) 		.gate = { CGU_REG_CLKGR0, 1 },
344*ce1d86dcS周琰杰 (Zhou Yanjie) 	},
345*ce1d86dcS周琰杰 (Zhou Yanjie) 
346*ce1d86dcS周琰杰 (Zhou Yanjie) 	[X1830_CLK_OTG] = {
347*ce1d86dcS周琰杰 (Zhou Yanjie) 		"otg", CGU_CLK_GATE,
348*ce1d86dcS周琰杰 (Zhou Yanjie) 		.parents = { X1830_CLK_EXCLK, -1, -1, -1 },
349*ce1d86dcS周琰杰 (Zhou Yanjie) 		.gate = { CGU_REG_CLKGR0, 3 },
350*ce1d86dcS周琰杰 (Zhou Yanjie) 	},
351*ce1d86dcS周琰杰 (Zhou Yanjie) 
352*ce1d86dcS周琰杰 (Zhou Yanjie) 	[X1830_CLK_SSI0] = {
353*ce1d86dcS周琰杰 (Zhou Yanjie) 		"ssi0", CGU_CLK_GATE,
354*ce1d86dcS周琰杰 (Zhou Yanjie) 		.parents = { X1830_CLK_SSIMUX, -1, -1, -1 },
355*ce1d86dcS周琰杰 (Zhou Yanjie) 		.gate = { CGU_REG_CLKGR0, 6 },
356*ce1d86dcS周琰杰 (Zhou Yanjie) 	},
357*ce1d86dcS周琰杰 (Zhou Yanjie) 
358*ce1d86dcS周琰杰 (Zhou Yanjie) 	[X1830_CLK_SMB0] = {
359*ce1d86dcS周琰杰 (Zhou Yanjie) 		"smb0", CGU_CLK_GATE,
360*ce1d86dcS周琰杰 (Zhou Yanjie) 		.parents = { X1830_CLK_PCLK, -1, -1, -1 },
361*ce1d86dcS周琰杰 (Zhou Yanjie) 		.gate = { CGU_REG_CLKGR0, 7 },
362*ce1d86dcS周琰杰 (Zhou Yanjie) 	},
363*ce1d86dcS周琰杰 (Zhou Yanjie) 
364*ce1d86dcS周琰杰 (Zhou Yanjie) 	[X1830_CLK_SMB1] = {
365*ce1d86dcS周琰杰 (Zhou Yanjie) 		"smb1", CGU_CLK_GATE,
366*ce1d86dcS周琰杰 (Zhou Yanjie) 		.parents = { X1830_CLK_PCLK, -1, -1, -1 },
367*ce1d86dcS周琰杰 (Zhou Yanjie) 		.gate = { CGU_REG_CLKGR0, 8 },
368*ce1d86dcS周琰杰 (Zhou Yanjie) 	},
369*ce1d86dcS周琰杰 (Zhou Yanjie) 
370*ce1d86dcS周琰杰 (Zhou Yanjie) 	[X1830_CLK_SMB2] = {
371*ce1d86dcS周琰杰 (Zhou Yanjie) 		"smb2", CGU_CLK_GATE,
372*ce1d86dcS周琰杰 (Zhou Yanjie) 		.parents = { X1830_CLK_PCLK, -1, -1, -1 },
373*ce1d86dcS周琰杰 (Zhou Yanjie) 		.gate = { CGU_REG_CLKGR0, 9 },
374*ce1d86dcS周琰杰 (Zhou Yanjie) 	},
375*ce1d86dcS周琰杰 (Zhou Yanjie) 
376*ce1d86dcS周琰杰 (Zhou Yanjie) 	[X1830_CLK_UART0] = {
377*ce1d86dcS周琰杰 (Zhou Yanjie) 		"uart0", CGU_CLK_GATE,
378*ce1d86dcS周琰杰 (Zhou Yanjie) 		.parents = { X1830_CLK_EXCLK, -1, -1, -1 },
379*ce1d86dcS周琰杰 (Zhou Yanjie) 		.gate = { CGU_REG_CLKGR0, 14 },
380*ce1d86dcS周琰杰 (Zhou Yanjie) 	},
381*ce1d86dcS周琰杰 (Zhou Yanjie) 
382*ce1d86dcS周琰杰 (Zhou Yanjie) 	[X1830_CLK_UART1] = {
383*ce1d86dcS周琰杰 (Zhou Yanjie) 		"uart1", CGU_CLK_GATE,
384*ce1d86dcS周琰杰 (Zhou Yanjie) 		.parents = { X1830_CLK_EXCLK, -1, -1, -1 },
385*ce1d86dcS周琰杰 (Zhou Yanjie) 		.gate = { CGU_REG_CLKGR0, 15 },
386*ce1d86dcS周琰杰 (Zhou Yanjie) 	},
387*ce1d86dcS周琰杰 (Zhou Yanjie) 
388*ce1d86dcS周琰杰 (Zhou Yanjie) 	[X1830_CLK_SSI1] = {
389*ce1d86dcS周琰杰 (Zhou Yanjie) 		"ssi1", CGU_CLK_GATE,
390*ce1d86dcS周琰杰 (Zhou Yanjie) 		.parents = { X1830_CLK_SSIMUX, -1, -1, -1 },
391*ce1d86dcS周琰杰 (Zhou Yanjie) 		.gate = { CGU_REG_CLKGR0, 19 },
392*ce1d86dcS周琰杰 (Zhou Yanjie) 	},
393*ce1d86dcS周琰杰 (Zhou Yanjie) 
394*ce1d86dcS周琰杰 (Zhou Yanjie) 	[X1830_CLK_SFC] = {
395*ce1d86dcS周琰杰 (Zhou Yanjie) 		"sfc", CGU_CLK_GATE,
396*ce1d86dcS周琰杰 (Zhou Yanjie) 		.parents = { X1830_CLK_SSIPLL, -1, -1, -1 },
397*ce1d86dcS周琰杰 (Zhou Yanjie) 		.gate = { CGU_REG_CLKGR0, 20 },
398*ce1d86dcS周琰杰 (Zhou Yanjie) 	},
399*ce1d86dcS周琰杰 (Zhou Yanjie) 
400*ce1d86dcS周琰杰 (Zhou Yanjie) 	[X1830_CLK_PDMA] = {
401*ce1d86dcS周琰杰 (Zhou Yanjie) 		"pdma", CGU_CLK_GATE,
402*ce1d86dcS周琰杰 (Zhou Yanjie) 		.parents = { X1830_CLK_EXCLK, -1, -1, -1 },
403*ce1d86dcS周琰杰 (Zhou Yanjie) 		.gate = { CGU_REG_CLKGR0, 21 },
404*ce1d86dcS周琰杰 (Zhou Yanjie) 	},
405*ce1d86dcS周琰杰 (Zhou Yanjie) 
406*ce1d86dcS周琰杰 (Zhou Yanjie) 	[X1830_CLK_TCU] = {
407*ce1d86dcS周琰杰 (Zhou Yanjie) 		"tcu", CGU_CLK_GATE,
408*ce1d86dcS周琰杰 (Zhou Yanjie) 		.parents = { X1830_CLK_EXCLK, -1, -1, -1 },
409*ce1d86dcS周琰杰 (Zhou Yanjie) 		.gate = { CGU_REG_CLKGR0, 30 },
410*ce1d86dcS周琰杰 (Zhou Yanjie) 	},
411*ce1d86dcS周琰杰 (Zhou Yanjie) 
412*ce1d86dcS周琰杰 (Zhou Yanjie) 	[X1830_CLK_DTRNG] = {
413*ce1d86dcS周琰杰 (Zhou Yanjie) 		"dtrng", CGU_CLK_GATE,
414*ce1d86dcS周琰杰 (Zhou Yanjie) 		.parents = { X1830_CLK_PCLK, -1, -1, -1 },
415*ce1d86dcS周琰杰 (Zhou Yanjie) 		.gate = { CGU_REG_CLKGR1, 1 },
416*ce1d86dcS周琰杰 (Zhou Yanjie) 	},
417*ce1d86dcS周琰杰 (Zhou Yanjie) 
418*ce1d86dcS周琰杰 (Zhou Yanjie) 	[X1830_CLK_OST] = {
419*ce1d86dcS周琰杰 (Zhou Yanjie) 		"ost", CGU_CLK_GATE,
420*ce1d86dcS周琰杰 (Zhou Yanjie) 		.parents = { X1830_CLK_EXCLK, -1, -1, -1 },
421*ce1d86dcS周琰杰 (Zhou Yanjie) 		.gate = { CGU_REG_CLKGR1, 11 },
422*ce1d86dcS周琰杰 (Zhou Yanjie) 	},
423*ce1d86dcS周琰杰 (Zhou Yanjie) };
424*ce1d86dcS周琰杰 (Zhou Yanjie) 
425*ce1d86dcS周琰杰 (Zhou Yanjie) static void __init x1830_cgu_init(struct device_node *np)
426*ce1d86dcS周琰杰 (Zhou Yanjie) {
427*ce1d86dcS周琰杰 (Zhou Yanjie) 	int retval;
428*ce1d86dcS周琰杰 (Zhou Yanjie) 
429*ce1d86dcS周琰杰 (Zhou Yanjie) 	cgu = ingenic_cgu_new(x1830_cgu_clocks,
430*ce1d86dcS周琰杰 (Zhou Yanjie) 			      ARRAY_SIZE(x1830_cgu_clocks), np);
431*ce1d86dcS周琰杰 (Zhou Yanjie) 	if (!cgu) {
432*ce1d86dcS周琰杰 (Zhou Yanjie) 		pr_err("%s: failed to initialise CGU\n", __func__);
433*ce1d86dcS周琰杰 (Zhou Yanjie) 		return;
434*ce1d86dcS周琰杰 (Zhou Yanjie) 	}
435*ce1d86dcS周琰杰 (Zhou Yanjie) 
436*ce1d86dcS周琰杰 (Zhou Yanjie) 	retval = ingenic_cgu_register_clocks(cgu);
437*ce1d86dcS周琰杰 (Zhou Yanjie) 	if (retval) {
438*ce1d86dcS周琰杰 (Zhou Yanjie) 		pr_err("%s: failed to register CGU Clocks\n", __func__);
439*ce1d86dcS周琰杰 (Zhou Yanjie) 		return;
440*ce1d86dcS周琰杰 (Zhou Yanjie) 	}
441*ce1d86dcS周琰杰 (Zhou Yanjie) 
442*ce1d86dcS周琰杰 (Zhou Yanjie) 	ingenic_cgu_register_syscore_ops(cgu);
443*ce1d86dcS周琰杰 (Zhou Yanjie) }
444*ce1d86dcS周琰杰 (Zhou Yanjie) /*
445*ce1d86dcS周琰杰 (Zhou Yanjie)  * CGU has some children devices, this is useful for probing children devices
446*ce1d86dcS周琰杰 (Zhou Yanjie)  * in the case where the device node is compatible with "simple-mfd".
447*ce1d86dcS周琰杰 (Zhou Yanjie)  */
448*ce1d86dcS周琰杰 (Zhou Yanjie) CLK_OF_DECLARE_DRIVER(x1830_cgu, "ingenic,x1830-cgu", x1830_cgu_init);
449