1*6c4affb9Sjmcneill /* $NetBSD: sun8i_v3s_ccu.c,v 1.1 2021/05/05 10:24:04 jmcneill Exp $ */
2*6c4affb9Sjmcneill
3*6c4affb9Sjmcneill /*-
4*6c4affb9Sjmcneill * Copyright (c) 2021 Rui-Xiang Guo
5*6c4affb9Sjmcneill * Copyright (c) 2017 Jared McNeill <jmcneill@invisible.ca>
6*6c4affb9Sjmcneill * Copyright (c) 2017 Emmanuel Vadot <manu@freebsd.org>
7*6c4affb9Sjmcneill * All rights reserved.
8*6c4affb9Sjmcneill *
9*6c4affb9Sjmcneill * Redistribution and use in source and binary forms, with or without
10*6c4affb9Sjmcneill * modification, are permitted provided that the following conditions
11*6c4affb9Sjmcneill * are met:
12*6c4affb9Sjmcneill * 1. Redistributions of source code must retain the above copyright
13*6c4affb9Sjmcneill * notice, this list of conditions and the following disclaimer.
14*6c4affb9Sjmcneill * 2. Redistributions in binary form must reproduce the above copyright
15*6c4affb9Sjmcneill * notice, this list of conditions and the following disclaimer in the
16*6c4affb9Sjmcneill * documentation and/or other materials provided with the distribution.
17*6c4affb9Sjmcneill *
18*6c4affb9Sjmcneill * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19*6c4affb9Sjmcneill * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20*6c4affb9Sjmcneill * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21*6c4affb9Sjmcneill * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22*6c4affb9Sjmcneill * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23*6c4affb9Sjmcneill * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24*6c4affb9Sjmcneill * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25*6c4affb9Sjmcneill * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26*6c4affb9Sjmcneill * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27*6c4affb9Sjmcneill * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28*6c4affb9Sjmcneill * SUCH DAMAGE.
29*6c4affb9Sjmcneill */
30*6c4affb9Sjmcneill
31*6c4affb9Sjmcneill #include <sys/cdefs.h>
32*6c4affb9Sjmcneill
33*6c4affb9Sjmcneill __KERNEL_RCSID(1, "$NetBSD: sun8i_v3s_ccu.c,v 1.1 2021/05/05 10:24:04 jmcneill Exp $");
34*6c4affb9Sjmcneill
35*6c4affb9Sjmcneill #include <sys/param.h>
36*6c4affb9Sjmcneill #include <sys/bus.h>
37*6c4affb9Sjmcneill #include <sys/device.h>
38*6c4affb9Sjmcneill #include <sys/systm.h>
39*6c4affb9Sjmcneill
40*6c4affb9Sjmcneill #include <dev/fdt/fdtvar.h>
41*6c4affb9Sjmcneill
42*6c4affb9Sjmcneill #include <arm/sunxi/sunxi_ccu.h>
43*6c4affb9Sjmcneill #include <arm/sunxi/sun8i_v3s_ccu.h>
44*6c4affb9Sjmcneill
45*6c4affb9Sjmcneill #define PLL_CPU_CTRL_REG 0x000
46*6c4affb9Sjmcneill #define PLL_AUDIO_CTRL_REG 0x008
47*6c4affb9Sjmcneill #define PLL_VIDEO_CTRL_REG 0x010
48*6c4affb9Sjmcneill #define PLL_PERIPH0_CTRL_REG 0x028
49*6c4affb9Sjmcneill #define AHB1_APB1_CFG_REG 0x054
50*6c4affb9Sjmcneill #define APB2_CFG_REG 0x058
51*6c4affb9Sjmcneill #define AHB2_CFG_REG 0x05c
52*6c4affb9Sjmcneill #define AHB2_CLK_CFG __BITS(1,0)
53*6c4affb9Sjmcneill #define AHB2_CLK_CFG_PLL_PERIPH0_2 1
54*6c4affb9Sjmcneill #define BUS_CLK_GATING_REG0 0x060
55*6c4affb9Sjmcneill #define BUS_CLK_GATING_REG1 0x064
56*6c4affb9Sjmcneill #define BUS_CLK_GATING_REG2 0x068
57*6c4affb9Sjmcneill #define BUS_CLK_GATING_REG3 0x06c
58*6c4affb9Sjmcneill #define BUS_CLK_GATING_REG4 0x070
59*6c4affb9Sjmcneill #define SDMMC0_CLK_REG 0x088
60*6c4affb9Sjmcneill #define SDMMC1_CLK_REG 0x08c
61*6c4affb9Sjmcneill #define SDMMC2_CLK_REG 0x090
62*6c4affb9Sjmcneill #define SPI_CLK_REG 0x0a0
63*6c4affb9Sjmcneill #define USBPHY_CFG_REG 0x0cc
64*6c4affb9Sjmcneill #define MBUS_RST_REG 0x0fc
65*6c4affb9Sjmcneill #define DE_CLK_REG 0x104
66*6c4affb9Sjmcneill #define TCON_CLK_REG 0x118
67*6c4affb9Sjmcneill #define AC_DIG_CLK_REG 0x140
68*6c4affb9Sjmcneill #define BUS_SOFT_RST_REG0 0x2c0
69*6c4affb9Sjmcneill #define BUS_SOFT_RST_REG1 0x2c4
70*6c4affb9Sjmcneill #define BUS_SOFT_RST_REG2 0x2c8
71*6c4affb9Sjmcneill #define BUS_SOFT_RST_REG3 0x2d0
72*6c4affb9Sjmcneill #define BUS_SOFT_RST_REG4 0x2d8
73*6c4affb9Sjmcneill
74*6c4affb9Sjmcneill static int sun8i_v3s_ccu_match(device_t, cfdata_t, void *);
75*6c4affb9Sjmcneill static void sun8i_v3s_ccu_attach(device_t, device_t, void *);
76*6c4affb9Sjmcneill
77*6c4affb9Sjmcneill static const struct device_compatible_entry compat_data[] = {
78*6c4affb9Sjmcneill { .compat = "allwinner,sun8i-v3s-ccu" },
79*6c4affb9Sjmcneill DEVICE_COMPAT_EOL
80*6c4affb9Sjmcneill };
81*6c4affb9Sjmcneill
82*6c4affb9Sjmcneill CFATTACH_DECL_NEW(sunxi_v3s_ccu, sizeof(struct sunxi_ccu_softc),
83*6c4affb9Sjmcneill sun8i_v3s_ccu_match, sun8i_v3s_ccu_attach, NULL, NULL);
84*6c4affb9Sjmcneill
85*6c4affb9Sjmcneill static struct sunxi_ccu_reset sun8i_v3s_ccu_resets[] = {
86*6c4affb9Sjmcneill SUNXI_CCU_RESET(V3S_RST_USBPHY, USBPHY_CFG_REG, 0),
87*6c4affb9Sjmcneill
88*6c4affb9Sjmcneill SUNXI_CCU_RESET(V3S_RST_MBUS, MBUS_RST_REG, 31),
89*6c4affb9Sjmcneill
90*6c4affb9Sjmcneill SUNXI_CCU_RESET(V3S_RST_BUS_CE, BUS_SOFT_RST_REG0, 5),
91*6c4affb9Sjmcneill SUNXI_CCU_RESET(V3S_RST_BUS_DMA, BUS_SOFT_RST_REG0, 6),
92*6c4affb9Sjmcneill SUNXI_CCU_RESET(V3S_RST_BUS_MMC0, BUS_SOFT_RST_REG0, 8),
93*6c4affb9Sjmcneill SUNXI_CCU_RESET(V3S_RST_BUS_MMC1, BUS_SOFT_RST_REG0, 9),
94*6c4affb9Sjmcneill SUNXI_CCU_RESET(V3S_RST_BUS_MMC2, BUS_SOFT_RST_REG0, 10),
95*6c4affb9Sjmcneill SUNXI_CCU_RESET(V3S_RST_BUS_DRAM, BUS_SOFT_RST_REG0, 14),
96*6c4affb9Sjmcneill SUNXI_CCU_RESET(V3S_RST_BUS_EMAC, BUS_SOFT_RST_REG0, 17),
97*6c4affb9Sjmcneill SUNXI_CCU_RESET(V3S_RST_BUS_HSTIMER, BUS_SOFT_RST_REG0, 19),
98*6c4affb9Sjmcneill SUNXI_CCU_RESET(V3S_RST_BUS_SPI, BUS_SOFT_RST_REG0, 20),
99*6c4affb9Sjmcneill SUNXI_CCU_RESET(V3S_RST_BUS_OTG, BUS_SOFT_RST_REG0, 24),
100*6c4affb9Sjmcneill SUNXI_CCU_RESET(V3S_RST_BUS_EHCI, BUS_SOFT_RST_REG0, 26),
101*6c4affb9Sjmcneill SUNXI_CCU_RESET(V3S_RST_BUS_OHCI, BUS_SOFT_RST_REG0, 29),
102*6c4affb9Sjmcneill
103*6c4affb9Sjmcneill SUNXI_CCU_RESET(V3S_RST_BUS_VE, BUS_SOFT_RST_REG1, 0),
104*6c4affb9Sjmcneill SUNXI_CCU_RESET(V3S_RST_BUS_TCON, BUS_SOFT_RST_REG1, 4),
105*6c4affb9Sjmcneill SUNXI_CCU_RESET(V3S_RST_BUS_CSI, BUS_SOFT_RST_REG1, 8),
106*6c4affb9Sjmcneill SUNXI_CCU_RESET(V3S_RST_BUS_DE, BUS_SOFT_RST_REG1, 12),
107*6c4affb9Sjmcneill SUNXI_CCU_RESET(V3S_RST_BUS_DBG, BUS_SOFT_RST_REG1, 31),
108*6c4affb9Sjmcneill
109*6c4affb9Sjmcneill SUNXI_CCU_RESET(V3S_RST_BUS_EPHY, BUS_SOFT_RST_REG2, 2),
110*6c4affb9Sjmcneill
111*6c4affb9Sjmcneill SUNXI_CCU_RESET(V3S_RST_BUS_CODEC, BUS_SOFT_RST_REG3, 0),
112*6c4affb9Sjmcneill
113*6c4affb9Sjmcneill SUNXI_CCU_RESET(V3S_RST_BUS_I2C0, BUS_SOFT_RST_REG4, 0),
114*6c4affb9Sjmcneill SUNXI_CCU_RESET(V3S_RST_BUS_I2C1, BUS_SOFT_RST_REG4, 1),
115*6c4affb9Sjmcneill SUNXI_CCU_RESET(V3S_RST_BUS_UART0, BUS_SOFT_RST_REG4, 16),
116*6c4affb9Sjmcneill SUNXI_CCU_RESET(V3S_RST_BUS_UART1, BUS_SOFT_RST_REG4, 17),
117*6c4affb9Sjmcneill SUNXI_CCU_RESET(V3S_RST_BUS_UART2, BUS_SOFT_RST_REG4, 18),
118*6c4affb9Sjmcneill };
119*6c4affb9Sjmcneill
120*6c4affb9Sjmcneill static const char *ahb1_parents[] = { "losc", "hosc", "axi", "pll_periph0" };
121*6c4affb9Sjmcneill static const char *ahb2_parents[] = { "ahb1", "pll_periph0" };
122*6c4affb9Sjmcneill static const char *apb1_parents[] = { "ahb1" };
123*6c4affb9Sjmcneill static const char *apb2_parents[] = { "losc", "hosc", "pll_periph0" };
124*6c4affb9Sjmcneill static const char *mod_parents[] = { "hosc", "pll_periph0", "pll_periph1" };
125*6c4affb9Sjmcneill static const char *tcon_parents[] = { "pll_video" };
126*6c4affb9Sjmcneill
127*6c4affb9Sjmcneill static const struct sunxi_ccu_nkmp_tbl sun8i_v3s_cpu_table[] = {
128*6c4affb9Sjmcneill { 60000000, 9, 0, 0, 2 },
129*6c4affb9Sjmcneill { 66000000, 10, 0, 0, 2 },
130*6c4affb9Sjmcneill { 72000000, 11, 0, 0, 2 },
131*6c4affb9Sjmcneill { 78000000, 12, 0, 0, 2 },
132*6c4affb9Sjmcneill { 84000000, 13, 0, 0, 2 },
133*6c4affb9Sjmcneill { 90000000, 14, 0, 0, 2 },
134*6c4affb9Sjmcneill { 96000000, 15, 0, 0, 2 },
135*6c4affb9Sjmcneill { 102000000, 16, 0, 0, 2 },
136*6c4affb9Sjmcneill { 108000000, 17, 0, 0, 2 },
137*6c4affb9Sjmcneill { 114000000, 18, 0, 0, 2 },
138*6c4affb9Sjmcneill { 120000000, 9, 0, 0, 1 },
139*6c4affb9Sjmcneill { 132000000, 10, 0, 0, 1 },
140*6c4affb9Sjmcneill { 144000000, 11, 0, 0, 1 },
141*6c4affb9Sjmcneill { 156000000, 12, 0, 0, 1 },
142*6c4affb9Sjmcneill { 168000000, 13, 0, 0, 1 },
143*6c4affb9Sjmcneill { 180000000, 14, 0, 0, 1 },
144*6c4affb9Sjmcneill { 192000000, 15, 0, 0, 1 },
145*6c4affb9Sjmcneill { 204000000, 16, 0, 0, 1 },
146*6c4affb9Sjmcneill { 216000000, 17, 0, 0, 1 },
147*6c4affb9Sjmcneill { 228000000, 18, 0, 0, 1 },
148*6c4affb9Sjmcneill { 240000000, 9, 0, 0, 0 },
149*6c4affb9Sjmcneill { 264000000, 10, 0, 0, 0 },
150*6c4affb9Sjmcneill { 288000000, 11, 0, 0, 0 },
151*6c4affb9Sjmcneill { 312000000, 12, 0, 0, 0 },
152*6c4affb9Sjmcneill { 336000000, 13, 0, 0, 0 },
153*6c4affb9Sjmcneill { 360000000, 14, 0, 0, 0 },
154*6c4affb9Sjmcneill { 384000000, 15, 0, 0, 0 },
155*6c4affb9Sjmcneill { 408000000, 16, 0, 0, 0 },
156*6c4affb9Sjmcneill { 432000000, 17, 0, 0, 0 },
157*6c4affb9Sjmcneill { 456000000, 18, 0, 0, 0 },
158*6c4affb9Sjmcneill { 480000000, 19, 0, 0, 0 },
159*6c4affb9Sjmcneill { 504000000, 20, 0, 0, 0 },
160*6c4affb9Sjmcneill { 528000000, 21, 0, 0, 0 },
161*6c4affb9Sjmcneill { 552000000, 22, 0, 0, 0 },
162*6c4affb9Sjmcneill { 576000000, 23, 0, 0, 0 },
163*6c4affb9Sjmcneill { 600000000, 24, 0, 0, 0 },
164*6c4affb9Sjmcneill { 624000000, 25, 0, 0, 0 },
165*6c4affb9Sjmcneill { 648000000, 26, 0, 0, 0 },
166*6c4affb9Sjmcneill { 672000000, 27, 0, 0, 0 },
167*6c4affb9Sjmcneill { 696000000, 28, 0, 0, 0 },
168*6c4affb9Sjmcneill { 720000000, 29, 0, 0, 0 },
169*6c4affb9Sjmcneill { 768000000, 15, 1, 0, 0 },
170*6c4affb9Sjmcneill { 792000000, 10, 2, 0, 0 },
171*6c4affb9Sjmcneill { 816000000, 16, 1, 0, 0 },
172*6c4affb9Sjmcneill { 864000000, 17, 1, 0, 0 },
173*6c4affb9Sjmcneill { 912000000, 18, 1, 0, 0 },
174*6c4affb9Sjmcneill { 936000000, 12, 2, 0, 0 },
175*6c4affb9Sjmcneill { 960000000, 19, 1, 0, 0 },
176*6c4affb9Sjmcneill { 1008000000, 20, 1, 0, 0 },
177*6c4affb9Sjmcneill { 1056000000, 21, 1, 0, 0 },
178*6c4affb9Sjmcneill { 1080000000, 14, 2, 0, 0 },
179*6c4affb9Sjmcneill { 1104000000, 22, 1, 0, 0 },
180*6c4affb9Sjmcneill { 1152000000, 23, 1, 0, 0 },
181*6c4affb9Sjmcneill { 1200000000, 24, 1, 0, 0 },
182*6c4affb9Sjmcneill { 1224000000, 16, 2, 0, 0 },
183*6c4affb9Sjmcneill { 1248000000, 25, 1, 0, 0 },
184*6c4affb9Sjmcneill { 1296000000, 26, 1, 0, 0 },
185*6c4affb9Sjmcneill { 1344000000, 27, 1, 0, 0 },
186*6c4affb9Sjmcneill { 1368000000, 18, 2, 0, 0 },
187*6c4affb9Sjmcneill { 1392000000, 28, 1, 0, 0 },
188*6c4affb9Sjmcneill { 1440000000, 29, 1, 0, 0 },
189*6c4affb9Sjmcneill { 1512000000, 20, 2, 0, 0 },
190*6c4affb9Sjmcneill { 1536000000, 15, 3, 0, 0 },
191*6c4affb9Sjmcneill { 1584000000, 21, 2, 0, 0 },
192*6c4affb9Sjmcneill { 1632000000, 16, 3, 0, 0 },
193*6c4affb9Sjmcneill { 1656000000, 22, 2, 0, 0 },
194*6c4affb9Sjmcneill { 1728000000, 23, 2, 0, 0 },
195*6c4affb9Sjmcneill { 1800000000, 24, 2, 0, 0 },
196*6c4affb9Sjmcneill { 1824000000, 18, 3, 0, 0 },
197*6c4affb9Sjmcneill { 1872000000, 25, 2, 0, 0 },
198*6c4affb9Sjmcneill { 0 }
199*6c4affb9Sjmcneill };
200*6c4affb9Sjmcneill
201*6c4affb9Sjmcneill static const struct sunxi_ccu_nkmp_tbl sun8i_v3s_ac_dig_table[] = {
202*6c4affb9Sjmcneill { 24576000, 13, 0, 0, 13 },
203*6c4affb9Sjmcneill { 0 }
204*6c4affb9Sjmcneill };
205*6c4affb9Sjmcneill
206*6c4affb9Sjmcneill static struct sunxi_ccu_clk sun8i_v3s_ccu_clks[] = {
207*6c4affb9Sjmcneill SUNXI_CCU_NKMP_TABLE(V3S_CLK_CPU, "pll_cpu", "hosc",
208*6c4affb9Sjmcneill PLL_CPU_CTRL_REG, /* reg */
209*6c4affb9Sjmcneill __BITS(12,8), /* n */
210*6c4affb9Sjmcneill __BITS(5,4), /* k */
211*6c4affb9Sjmcneill __BITS(1,0), /* m */
212*6c4affb9Sjmcneill __BITS(17,16), /* p */
213*6c4affb9Sjmcneill __BIT(31), /* enable */
214*6c4affb9Sjmcneill __BIT(28), /* lock */
215*6c4affb9Sjmcneill sun8i_v3s_cpu_table, /* table */
216*6c4affb9Sjmcneill SUNXI_CCU_NKMP_SCALE_CLOCK | SUNXI_CCU_NKMP_FACTOR_P_POW2),
217*6c4affb9Sjmcneill
218*6c4affb9Sjmcneill SUNXI_CCU_NKMP(V3S_CLK_PLL_PERIPH0, "pll_periph0", "hosc",
219*6c4affb9Sjmcneill PLL_PERIPH0_CTRL_REG, /* reg */
220*6c4affb9Sjmcneill __BITS(12,8), /* n */
221*6c4affb9Sjmcneill __BITS(5,4), /* k */
222*6c4affb9Sjmcneill 0, /* m */
223*6c4affb9Sjmcneill __BITS(17,16), /* p */
224*6c4affb9Sjmcneill __BIT(31), /* enable */
225*6c4affb9Sjmcneill SUNXI_CCU_NKMP_DIVIDE_BY_TWO),
226*6c4affb9Sjmcneill
227*6c4affb9Sjmcneill SUNXI_CCU_FIXED_FACTOR(V3S_CLK_PLL_PERIPH0_2X, "pll_periph0_2x", "pll_periph0", 1, 2),
228*6c4affb9Sjmcneill
229*6c4affb9Sjmcneill SUNXI_CCU_FRACTIONAL(V3S_CLK_PLL_VIDEO, "pll_video", "hosc",
230*6c4affb9Sjmcneill PLL_VIDEO_CTRL_REG, /* reg */
231*6c4affb9Sjmcneill __BITS(14,8), /* m */
232*6c4affb9Sjmcneill 16, /* m_min */
233*6c4affb9Sjmcneill 50, /* m_max */
234*6c4affb9Sjmcneill __BIT(24), /* div_en */
235*6c4affb9Sjmcneill __BIT(25), /* frac_sel */
236*6c4affb9Sjmcneill 270000000, 297000000, /* frac values */
237*6c4affb9Sjmcneill __BITS(3,0), /* prediv */
238*6c4affb9Sjmcneill 4, /* prediv_val */
239*6c4affb9Sjmcneill __BIT(31), /* enable */
240*6c4affb9Sjmcneill SUNXI_CCU_FRACTIONAL_PLUSONE | SUNXI_CCU_FRACTIONAL_SET_ENABLE),
241*6c4affb9Sjmcneill
242*6c4affb9Sjmcneill SUNXI_CCU_NKMP_TABLE(V3S_CLK_PLL_AUDIO_BASE, "pll_audio", "hosc",
243*6c4affb9Sjmcneill PLL_AUDIO_CTRL_REG, /* reg */
244*6c4affb9Sjmcneill __BITS(14,8), /* n */
245*6c4affb9Sjmcneill 0, /* k */
246*6c4affb9Sjmcneill __BITS(4,0), /* m */
247*6c4affb9Sjmcneill __BITS(19,16), /* p */
248*6c4affb9Sjmcneill __BIT(31), /* enable */
249*6c4affb9Sjmcneill __BIT(28), /* lock */
250*6c4affb9Sjmcneill sun8i_v3s_ac_dig_table, /* table */
251*6c4affb9Sjmcneill 0),
252*6c4affb9Sjmcneill
253*6c4affb9Sjmcneill SUNXI_CCU_PREDIV(V3S_CLK_AHB1, "ahb1", ahb1_parents,
254*6c4affb9Sjmcneill AHB1_APB1_CFG_REG, /* reg */
255*6c4affb9Sjmcneill __BITS(7,6), /* prediv */
256*6c4affb9Sjmcneill __BIT(3), /* prediv_sel */
257*6c4affb9Sjmcneill __BITS(5,4), /* div */
258*6c4affb9Sjmcneill __BITS(13,12), /* sel */
259*6c4affb9Sjmcneill SUNXI_CCU_PREDIV_POWER_OF_TWO),
260*6c4affb9Sjmcneill
261*6c4affb9Sjmcneill SUNXI_CCU_PREDIV(V3S_CLK_AHB2, "ahb2", ahb2_parents,
262*6c4affb9Sjmcneill AHB2_CFG_REG, /* reg */
263*6c4affb9Sjmcneill 0, /* prediv */
264*6c4affb9Sjmcneill __BIT(1), /* prediv_sel */
265*6c4affb9Sjmcneill 0, /* div */
266*6c4affb9Sjmcneill __BITS(1,0), /* sel */
267*6c4affb9Sjmcneill SUNXI_CCU_PREDIV_DIVIDE_BY_TWO),
268*6c4affb9Sjmcneill
269*6c4affb9Sjmcneill SUNXI_CCU_DIV(V3S_CLK_APB1, "apb1", apb1_parents,
270*6c4affb9Sjmcneill AHB1_APB1_CFG_REG, /* reg */
271*6c4affb9Sjmcneill __BITS(9,8), /* div */
272*6c4affb9Sjmcneill 0, /* sel */
273*6c4affb9Sjmcneill SUNXI_CCU_DIV_POWER_OF_TWO|SUNXI_CCU_DIV_ZERO_IS_ONE),
274*6c4affb9Sjmcneill
275*6c4affb9Sjmcneill SUNXI_CCU_NM(V3S_CLK_APB2, "apb2", apb2_parents,
276*6c4affb9Sjmcneill APB2_CFG_REG, /* reg */
277*6c4affb9Sjmcneill __BITS(17,16), /* n */
278*6c4affb9Sjmcneill __BITS(4,0), /* m */
279*6c4affb9Sjmcneill __BITS(25,24), /* sel */
280*6c4affb9Sjmcneill 0, /* enable */
281*6c4affb9Sjmcneill SUNXI_CCU_NM_POWER_OF_TWO),
282*6c4affb9Sjmcneill
283*6c4affb9Sjmcneill SUNXI_CCU_NM(V3S_CLK_MMC0, "mmc0", mod_parents,
284*6c4affb9Sjmcneill SDMMC0_CLK_REG, __BITS(17, 16), __BITS(3,0), __BITS(25, 24), __BIT(31),
285*6c4affb9Sjmcneill SUNXI_CCU_NM_POWER_OF_TWO|SUNXI_CCU_NM_ROUND_DOWN),
286*6c4affb9Sjmcneill SUNXI_CCU_PHASE(V3S_CLK_MMC0_SAMPLE, "mmc0_sample", "mmc0",
287*6c4affb9Sjmcneill SDMMC0_CLK_REG, __BITS(22,20)),
288*6c4affb9Sjmcneill SUNXI_CCU_PHASE(V3S_CLK_MMC0_OUTPUT, "mmc0_output", "mmc0",
289*6c4affb9Sjmcneill SDMMC0_CLK_REG, __BITS(10,8)),
290*6c4affb9Sjmcneill SUNXI_CCU_NM(V3S_CLK_MMC1, "mmc1", mod_parents,
291*6c4affb9Sjmcneill SDMMC1_CLK_REG, __BITS(17, 16), __BITS(3,0), __BITS(25, 24), __BIT(31),
292*6c4affb9Sjmcneill SUNXI_CCU_NM_POWER_OF_TWO|SUNXI_CCU_NM_ROUND_DOWN),
293*6c4affb9Sjmcneill SUNXI_CCU_PHASE(V3S_CLK_MMC1_SAMPLE, "mmc1_sample", "mmc1",
294*6c4affb9Sjmcneill SDMMC1_CLK_REG, __BITS(22,20)),
295*6c4affb9Sjmcneill SUNXI_CCU_PHASE(V3S_CLK_MMC1_OUTPUT, "mmc1_output", "mmc1",
296*6c4affb9Sjmcneill SDMMC1_CLK_REG, __BITS(10,8)),
297*6c4affb9Sjmcneill SUNXI_CCU_NM(V3S_CLK_MMC2, "mmc2", mod_parents,
298*6c4affb9Sjmcneill SDMMC2_CLK_REG, __BITS(17, 16), __BITS(3,0), __BITS(25, 24), __BIT(31),
299*6c4affb9Sjmcneill SUNXI_CCU_NM_POWER_OF_TWO|SUNXI_CCU_NM_ROUND_DOWN),
300*6c4affb9Sjmcneill SUNXI_CCU_PHASE(V3S_CLK_MMC2_SAMPLE, "mmc2_sample", "mmc2",
301*6c4affb9Sjmcneill SDMMC2_CLK_REG, __BITS(22,20)),
302*6c4affb9Sjmcneill SUNXI_CCU_PHASE(V3S_CLK_MMC2_OUTPUT, "mmc2_output", "mmc2",
303*6c4affb9Sjmcneill SDMMC2_CLK_REG, __BITS(10,8)),
304*6c4affb9Sjmcneill
305*6c4affb9Sjmcneill SUNXI_CCU_NM(V3S_CLK_SPI, "spi", mod_parents,
306*6c4affb9Sjmcneill SPI_CLK_REG, /* reg */
307*6c4affb9Sjmcneill __BITS(17,16), /* n */
308*6c4affb9Sjmcneill __BITS(3,0), /* m */
309*6c4affb9Sjmcneill __BITS(25,24), /* sel */
310*6c4affb9Sjmcneill __BIT(31), /* enable */
311*6c4affb9Sjmcneill SUNXI_CCU_NM_ROUND_DOWN),
312*6c4affb9Sjmcneill
313*6c4affb9Sjmcneill SUNXI_CCU_GATE(V3S_CLK_AC_DIG, "ac_dig", "pll_audio",
314*6c4affb9Sjmcneill AC_DIG_CLK_REG, 31),
315*6c4affb9Sjmcneill
316*6c4affb9Sjmcneill SUNXI_CCU_DIV_GATE(V3S_CLK_TCON, "tcon", tcon_parents,
317*6c4affb9Sjmcneill TCON_CLK_REG, /* reg */
318*6c4affb9Sjmcneill __BITS(3,0), /* div */
319*6c4affb9Sjmcneill __BITS(26,24), /* sel */
320*6c4affb9Sjmcneill __BIT(31), /* enable */
321*6c4affb9Sjmcneill 0),
322*6c4affb9Sjmcneill
323*6c4affb9Sjmcneill SUNXI_CCU_GATE(V3S_CLK_BUS_DMA, "bus-dma", "ahb1",
324*6c4affb9Sjmcneill BUS_CLK_GATING_REG0, 6),
325*6c4affb9Sjmcneill SUNXI_CCU_GATE(V3S_CLK_BUS_MMC0, "bus-mmc0", "ahb1",
326*6c4affb9Sjmcneill BUS_CLK_GATING_REG0, 8),
327*6c4affb9Sjmcneill SUNXI_CCU_GATE(V3S_CLK_BUS_MMC1, "bus-mmc1", "ahb1",
328*6c4affb9Sjmcneill BUS_CLK_GATING_REG0, 9),
329*6c4affb9Sjmcneill SUNXI_CCU_GATE(V3S_CLK_BUS_MMC2, "bus-mmc2", "ahb1",
330*6c4affb9Sjmcneill BUS_CLK_GATING_REG0, 10),
331*6c4affb9Sjmcneill SUNXI_CCU_GATE(V3S_CLK_BUS_EMAC, "bus-emac", "ahb2",
332*6c4affb9Sjmcneill BUS_CLK_GATING_REG0, 17),
333*6c4affb9Sjmcneill SUNXI_CCU_GATE(V3S_CLK_BUS_SPI, "bus-spi", "ahb1",
334*6c4affb9Sjmcneill BUS_CLK_GATING_REG0, 20),
335*6c4affb9Sjmcneill SUNXI_CCU_GATE(V3S_CLK_BUS_OTG, "bus-otg", "ahb1",
336*6c4affb9Sjmcneill BUS_CLK_GATING_REG0, 24),
337*6c4affb9Sjmcneill SUNXI_CCU_GATE(V3S_CLK_BUS_EHCI, "bus-ehci", "ahb1",
338*6c4affb9Sjmcneill BUS_CLK_GATING_REG0, 26),
339*6c4affb9Sjmcneill SUNXI_CCU_GATE(V3S_CLK_BUS_OHCI, "bus-ohci", "ahb1",
340*6c4affb9Sjmcneill BUS_CLK_GATING_REG0, 29),
341*6c4affb9Sjmcneill
342*6c4affb9Sjmcneill SUNXI_CCU_GATE(V3S_CLK_BUS_TCON, "bus-tcon", "ahb1",
343*6c4affb9Sjmcneill BUS_CLK_GATING_REG1, 4),
344*6c4affb9Sjmcneill SUNXI_CCU_GATE(V3S_CLK_BUS_DE, "bus-de", "ahb1",
345*6c4affb9Sjmcneill BUS_CLK_GATING_REG1, 12),
346*6c4affb9Sjmcneill
347*6c4affb9Sjmcneill SUNXI_CCU_GATE(V3S_CLK_BUS_CODEC, "bus-codec", "apb1",
348*6c4affb9Sjmcneill BUS_CLK_GATING_REG2, 0),
349*6c4affb9Sjmcneill SUNXI_CCU_GATE(V3S_CLK_BUS_PIO, "bus-pio", "apb1",
350*6c4affb9Sjmcneill BUS_CLK_GATING_REG2, 5),
351*6c4affb9Sjmcneill
352*6c4affb9Sjmcneill SUNXI_CCU_GATE(V3S_CLK_BUS_I2C0, "bus-i2c0", "apb2",
353*6c4affb9Sjmcneill BUS_CLK_GATING_REG3, 0),
354*6c4affb9Sjmcneill SUNXI_CCU_GATE(V3S_CLK_BUS_I2C1, "bus-i2c1", "apb2",
355*6c4affb9Sjmcneill BUS_CLK_GATING_REG3, 1),
356*6c4affb9Sjmcneill SUNXI_CCU_GATE(V3S_CLK_BUS_UART0, "bus-uart0", "apb2",
357*6c4affb9Sjmcneill BUS_CLK_GATING_REG3, 16),
358*6c4affb9Sjmcneill SUNXI_CCU_GATE(V3S_CLK_BUS_UART1, "bus-uart1", "apb2",
359*6c4affb9Sjmcneill BUS_CLK_GATING_REG3, 17),
360*6c4affb9Sjmcneill SUNXI_CCU_GATE(V3S_CLK_BUS_UART2, "bus-uart2", "apb2",
361*6c4affb9Sjmcneill BUS_CLK_GATING_REG3, 18),
362*6c4affb9Sjmcneill
363*6c4affb9Sjmcneill SUNXI_CCU_GATE(V3S_CLK_BUS_EPHY, "bus-ephy", "ahb1",
364*6c4affb9Sjmcneill BUS_CLK_GATING_REG4, 0),
365*6c4affb9Sjmcneill
366*6c4affb9Sjmcneill SUNXI_CCU_GATE(V3S_CLK_USBPHY, "usb-phy", "hosc",
367*6c4affb9Sjmcneill USBPHY_CFG_REG, 8),
368*6c4affb9Sjmcneill SUNXI_CCU_GATE(V3S_CLK_USBOHCI, "usb-ohci", "hosc",
369*6c4affb9Sjmcneill USBPHY_CFG_REG, 16),
370*6c4affb9Sjmcneill };
371*6c4affb9Sjmcneill
372*6c4affb9Sjmcneill static void
sun8i_v3s_ccu_init(struct sunxi_ccu_softc * sc)373*6c4affb9Sjmcneill sun8i_v3s_ccu_init(struct sunxi_ccu_softc *sc)
374*6c4affb9Sjmcneill {
375*6c4affb9Sjmcneill uint32_t val;
376*6c4affb9Sjmcneill
377*6c4affb9Sjmcneill /* Set AHB2 source to PLL_PERIPH/2 */
378*6c4affb9Sjmcneill val = CCU_READ(sc, AHB2_CFG_REG);
379*6c4affb9Sjmcneill val &= ~AHB2_CLK_CFG;
380*6c4affb9Sjmcneill val |= __SHIFTIN(AHB2_CLK_CFG_PLL_PERIPH0_2, AHB2_CLK_CFG);
381*6c4affb9Sjmcneill CCU_WRITE(sc, AHB2_CFG_REG, val);
382*6c4affb9Sjmcneill }
383*6c4affb9Sjmcneill
384*6c4affb9Sjmcneill static int
sun8i_v3s_ccu_match(device_t parent,cfdata_t cf,void * aux)385*6c4affb9Sjmcneill sun8i_v3s_ccu_match(device_t parent, cfdata_t cf, void *aux)
386*6c4affb9Sjmcneill {
387*6c4affb9Sjmcneill struct fdt_attach_args * const faa = aux;
388*6c4affb9Sjmcneill
389*6c4affb9Sjmcneill return of_compatible_match(faa->faa_phandle, compat_data);
390*6c4affb9Sjmcneill }
391*6c4affb9Sjmcneill
392*6c4affb9Sjmcneill static void
sun8i_v3s_ccu_attach(device_t parent,device_t self,void * aux)393*6c4affb9Sjmcneill sun8i_v3s_ccu_attach(device_t parent, device_t self, void *aux)
394*6c4affb9Sjmcneill {
395*6c4affb9Sjmcneill struct sunxi_ccu_softc * const sc = device_private(self);
396*6c4affb9Sjmcneill struct fdt_attach_args * const faa = aux;
397*6c4affb9Sjmcneill
398*6c4affb9Sjmcneill sc->sc_dev = self;
399*6c4affb9Sjmcneill sc->sc_phandle = faa->faa_phandle;
400*6c4affb9Sjmcneill sc->sc_bst = faa->faa_bst;
401*6c4affb9Sjmcneill
402*6c4affb9Sjmcneill sc->sc_resets = sun8i_v3s_ccu_resets;
403*6c4affb9Sjmcneill sc->sc_nresets = __arraycount(sun8i_v3s_ccu_resets);
404*6c4affb9Sjmcneill
405*6c4affb9Sjmcneill sc->sc_clks = sun8i_v3s_ccu_clks;
406*6c4affb9Sjmcneill sc->sc_nclks = __arraycount(sun8i_v3s_ccu_clks);
407*6c4affb9Sjmcneill
408*6c4affb9Sjmcneill if (sunxi_ccu_attach(sc) != 0)
409*6c4affb9Sjmcneill return;
410*6c4affb9Sjmcneill
411*6c4affb9Sjmcneill aprint_naive("\n");
412*6c4affb9Sjmcneill aprint_normal(": V3s CCU\n");
413*6c4affb9Sjmcneill
414*6c4affb9Sjmcneill sun8i_v3s_ccu_init(sc);
415*6c4affb9Sjmcneill
416*6c4affb9Sjmcneill sunxi_ccu_print(sc);
417*6c4affb9Sjmcneill }
418