sun50i_a64_ccu.c revision 1.5 1 1.5 jmcneill /* $NetBSD: sun50i_a64_ccu.c,v 1.5 2018/05/08 22:07:02 jmcneill Exp $ */
2 1.1 jmcneill
3 1.1 jmcneill /*-
4 1.1 jmcneill * Copyright (c) 2017 Jared McNeill <jmcneill (at) invisible.ca>
5 1.1 jmcneill * All rights reserved.
6 1.1 jmcneill *
7 1.1 jmcneill * Redistribution and use in source and binary forms, with or without
8 1.1 jmcneill * modification, are permitted provided that the following conditions
9 1.1 jmcneill * are met:
10 1.1 jmcneill * 1. Redistributions of source code must retain the above copyright
11 1.1 jmcneill * notice, this list of conditions and the following disclaimer.
12 1.1 jmcneill * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 jmcneill * notice, this list of conditions and the following disclaimer in the
14 1.1 jmcneill * documentation and/or other materials provided with the distribution.
15 1.1 jmcneill *
16 1.1 jmcneill * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.1 jmcneill * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.1 jmcneill * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.1 jmcneill * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.1 jmcneill * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 1.1 jmcneill * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 1.1 jmcneill * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 1.1 jmcneill * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 1.1 jmcneill * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.1 jmcneill * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.1 jmcneill * SUCH DAMAGE.
27 1.1 jmcneill */
28 1.1 jmcneill
29 1.1 jmcneill #include <sys/cdefs.h>
30 1.1 jmcneill
31 1.5 jmcneill __KERNEL_RCSID(1, "$NetBSD: sun50i_a64_ccu.c,v 1.5 2018/05/08 22:07:02 jmcneill Exp $");
32 1.1 jmcneill
33 1.1 jmcneill #include <sys/param.h>
34 1.1 jmcneill #include <sys/bus.h>
35 1.1 jmcneill #include <sys/device.h>
36 1.1 jmcneill #include <sys/systm.h>
37 1.1 jmcneill
38 1.1 jmcneill #include <dev/fdt/fdtvar.h>
39 1.1 jmcneill
40 1.1 jmcneill #include <arm/sunxi/sunxi_ccu.h>
41 1.1 jmcneill #include <arm/sunxi/sun50i_a64_ccu.h>
42 1.1 jmcneill
43 1.1 jmcneill #define PLL_CPUX_CTRL_REG 0x000
44 1.1 jmcneill #define PLL_AUDIO_CTRL_REG 0x008
45 1.1 jmcneill #define PLL_PERIPH0_CTRL_REG 0x028
46 1.1 jmcneill #define PLL_PERIPH1_CTRL_REG 0x02c
47 1.1 jmcneill #define AHB1_APB1_CFG_REG 0x054
48 1.1 jmcneill #define APB2_CFG_REG 0x058
49 1.1 jmcneill #define AHB2_CFG_REG 0x05c
50 1.1 jmcneill #define BUS_CLK_GATING_REG0 0x060
51 1.1 jmcneill #define BUS_CLK_GATING_REG1 0x064
52 1.1 jmcneill #define BUS_CLK_GATING_REG2 0x068
53 1.1 jmcneill #define BUS_CLK_GATING_REG3 0x06c
54 1.1 jmcneill #define BUS_CLK_GATING_REG4 0x070
55 1.4 jmcneill #define THS_CLK_REG 0x074
56 1.1 jmcneill #define SDMMC0_CLK_REG 0x088
57 1.1 jmcneill #define SDMMC1_CLK_REG 0x08c
58 1.1 jmcneill #define SDMMC2_CLK_REG 0x090
59 1.1 jmcneill #define USBPHY_CFG_REG 0x0cc
60 1.1 jmcneill #define DRAM_CFG_REG 0x0f4
61 1.1 jmcneill #define MBUS_RST_REG 0x0fc
62 1.1 jmcneill #define AC_DIG_CLK_REG 0x140
63 1.1 jmcneill #define BUS_SOFT_RST_REG0 0x2c0
64 1.1 jmcneill #define BUS_SOFT_RST_REG1 0x2c4
65 1.1 jmcneill #define BUS_SOFT_RST_REG2 0x2c8
66 1.1 jmcneill #define BUS_SOFT_RST_REG3 0x2d0
67 1.1 jmcneill #define BUS_SOFT_RST_REG4 0x2d8
68 1.1 jmcneill
69 1.1 jmcneill static int sun50i_a64_ccu_match(device_t, cfdata_t, void *);
70 1.1 jmcneill static void sun50i_a64_ccu_attach(device_t, device_t, void *);
71 1.1 jmcneill
72 1.1 jmcneill static const char * const compatible[] = {
73 1.1 jmcneill "allwinner,sun50i-a64-ccu",
74 1.1 jmcneill NULL
75 1.1 jmcneill };
76 1.1 jmcneill
77 1.1 jmcneill CFATTACH_DECL_NEW(sunxi_a64_ccu, sizeof(struct sunxi_ccu_softc),
78 1.1 jmcneill sun50i_a64_ccu_match, sun50i_a64_ccu_attach, NULL, NULL);
79 1.1 jmcneill
80 1.1 jmcneill static struct sunxi_ccu_reset sun50i_a64_ccu_resets[] = {
81 1.1 jmcneill SUNXI_CCU_RESET(A64_RST_USB_PHY0, USBPHY_CFG_REG, 0),
82 1.1 jmcneill SUNXI_CCU_RESET(A64_RST_USB_PHY1, USBPHY_CFG_REG, 1),
83 1.1 jmcneill SUNXI_CCU_RESET(A64_RST_USB_HSIC, USBPHY_CFG_REG, 2),
84 1.1 jmcneill
85 1.1 jmcneill SUNXI_CCU_RESET(A64_RST_DRAM, DRAM_CFG_REG, 31),
86 1.1 jmcneill
87 1.1 jmcneill SUNXI_CCU_RESET(A64_RST_MBUS, MBUS_RST_REG, 31),
88 1.1 jmcneill
89 1.1 jmcneill SUNXI_CCU_RESET(A64_RST_BUS_MIPI_DSI, BUS_SOFT_RST_REG0, 1),
90 1.1 jmcneill SUNXI_CCU_RESET(A64_RST_BUS_CE, BUS_SOFT_RST_REG0, 5),
91 1.1 jmcneill SUNXI_CCU_RESET(A64_RST_BUS_DMA, BUS_SOFT_RST_REG0, 6),
92 1.1 jmcneill SUNXI_CCU_RESET(A64_RST_BUS_MMC0, BUS_SOFT_RST_REG0, 8),
93 1.1 jmcneill SUNXI_CCU_RESET(A64_RST_BUS_MMC1, BUS_SOFT_RST_REG0, 9),
94 1.1 jmcneill SUNXI_CCU_RESET(A64_RST_BUS_MMC2, BUS_SOFT_RST_REG0, 10),
95 1.1 jmcneill SUNXI_CCU_RESET(A64_RST_BUS_NAND, BUS_SOFT_RST_REG0, 13),
96 1.1 jmcneill SUNXI_CCU_RESET(A64_RST_BUS_DRAM, BUS_SOFT_RST_REG0, 14),
97 1.1 jmcneill SUNXI_CCU_RESET(A64_RST_BUS_EMAC, BUS_SOFT_RST_REG0, 17),
98 1.1 jmcneill SUNXI_CCU_RESET(A64_RST_BUS_TS, BUS_SOFT_RST_REG0, 18),
99 1.1 jmcneill SUNXI_CCU_RESET(A64_RST_BUS_HSTIMER, BUS_SOFT_RST_REG0, 19),
100 1.1 jmcneill SUNXI_CCU_RESET(A64_RST_BUS_SPI0, BUS_SOFT_RST_REG0, 20),
101 1.1 jmcneill SUNXI_CCU_RESET(A64_RST_BUS_SPI1, BUS_SOFT_RST_REG0, 21),
102 1.1 jmcneill SUNXI_CCU_RESET(A64_RST_BUS_OTG, BUS_SOFT_RST_REG0, 23),
103 1.1 jmcneill SUNXI_CCU_RESET(A64_RST_BUS_EHCI0, BUS_SOFT_RST_REG0, 24),
104 1.1 jmcneill SUNXI_CCU_RESET(A64_RST_BUS_EHCI1, BUS_SOFT_RST_REG0, 25),
105 1.2 jmcneill SUNXI_CCU_RESET(A64_RST_BUS_OHCI0, BUS_SOFT_RST_REG0, 28),
106 1.2 jmcneill SUNXI_CCU_RESET(A64_RST_BUS_OHCI1, BUS_SOFT_RST_REG0, 29),
107 1.1 jmcneill
108 1.1 jmcneill SUNXI_CCU_RESET(A64_RST_BUS_VE, BUS_SOFT_RST_REG1, 0),
109 1.1 jmcneill SUNXI_CCU_RESET(A64_RST_BUS_TCON0, BUS_SOFT_RST_REG1, 3),
110 1.1 jmcneill SUNXI_CCU_RESET(A64_RST_BUS_TCON1, BUS_SOFT_RST_REG1, 4),
111 1.1 jmcneill SUNXI_CCU_RESET(A64_RST_BUS_DEINTERLACE, BUS_SOFT_RST_REG1, 5),
112 1.1 jmcneill SUNXI_CCU_RESET(A64_RST_BUS_CSI, BUS_SOFT_RST_REG1, 8),
113 1.1 jmcneill SUNXI_CCU_RESET(A64_RST_BUS_HDMI0, BUS_SOFT_RST_REG1, 10),
114 1.1 jmcneill SUNXI_CCU_RESET(A64_RST_BUS_HDMI1, BUS_SOFT_RST_REG1, 11),
115 1.1 jmcneill SUNXI_CCU_RESET(A64_RST_BUS_DE, BUS_SOFT_RST_REG1, 12),
116 1.1 jmcneill SUNXI_CCU_RESET(A64_RST_BUS_GPU, BUS_SOFT_RST_REG1, 20),
117 1.1 jmcneill SUNXI_CCU_RESET(A64_RST_BUS_MSGBOX, BUS_SOFT_RST_REG1, 21),
118 1.1 jmcneill SUNXI_CCU_RESET(A64_RST_BUS_SPINLOCK, BUS_SOFT_RST_REG1, 22),
119 1.1 jmcneill SUNXI_CCU_RESET(A64_RST_BUS_DBG, BUS_SOFT_RST_REG1, 31),
120 1.1 jmcneill
121 1.1 jmcneill SUNXI_CCU_RESET(A64_RST_BUS_LVDS, BUS_SOFT_RST_REG2, 0),
122 1.1 jmcneill
123 1.1 jmcneill SUNXI_CCU_RESET(A64_RST_BUS_CODEC, BUS_SOFT_RST_REG3, 0),
124 1.1 jmcneill SUNXI_CCU_RESET(A64_RST_BUS_SPDIF, BUS_SOFT_RST_REG3, 1),
125 1.1 jmcneill SUNXI_CCU_RESET(A64_RST_BUS_THS, BUS_SOFT_RST_REG3, 8),
126 1.1 jmcneill SUNXI_CCU_RESET(A64_RST_BUS_I2S0, BUS_SOFT_RST_REG3, 12),
127 1.1 jmcneill SUNXI_CCU_RESET(A64_RST_BUS_I2S1, BUS_SOFT_RST_REG3, 13),
128 1.1 jmcneill SUNXI_CCU_RESET(A64_RST_BUS_I2S2, BUS_SOFT_RST_REG3, 14),
129 1.1 jmcneill
130 1.1 jmcneill SUNXI_CCU_RESET(A64_RST_BUS_I2C0, BUS_SOFT_RST_REG4, 0),
131 1.1 jmcneill SUNXI_CCU_RESET(A64_RST_BUS_I2C1, BUS_SOFT_RST_REG4, 1),
132 1.1 jmcneill SUNXI_CCU_RESET(A64_RST_BUS_I2C2, BUS_SOFT_RST_REG4, 2),
133 1.1 jmcneill SUNXI_CCU_RESET(A64_RST_BUS_SCR, BUS_SOFT_RST_REG4, 5),
134 1.1 jmcneill SUNXI_CCU_RESET(A64_RST_BUS_UART0, BUS_SOFT_RST_REG4, 16),
135 1.1 jmcneill SUNXI_CCU_RESET(A64_RST_BUS_UART1, BUS_SOFT_RST_REG4, 17),
136 1.1 jmcneill SUNXI_CCU_RESET(A64_RST_BUS_UART2, BUS_SOFT_RST_REG4, 18),
137 1.1 jmcneill SUNXI_CCU_RESET(A64_RST_BUS_UART3, BUS_SOFT_RST_REG4, 19),
138 1.1 jmcneill };
139 1.1 jmcneill
140 1.1 jmcneill static const char *ahb1_parents[] = { "losc", "hosc", "axi", "pll_periph0" };
141 1.1 jmcneill static const char *ahb2_parents[] = { "ahb1", "pll_periph0" };
142 1.1 jmcneill static const char *apb1_parents[] = { "ahb1" };
143 1.1 jmcneill static const char *apb2_parents[] = { "losc", "hosc", "pll_periph0" };
144 1.1 jmcneill static const char *mod_parents[] = { "hosc", "pll_periph0", "pll_periph1" };
145 1.4 jmcneill static const char *ths_parents[] = { "hosc", NULL, NULL, NULL };
146 1.1 jmcneill
147 1.5 jmcneill static const struct sunxi_ccu_nkmp_tbl sun50i_a64_ac_dig_table[] = {
148 1.5 jmcneill { 24576000, 0x55, 0, 0x14, 0x3 },
149 1.5 jmcneill { 0 }
150 1.5 jmcneill };
151 1.5 jmcneill
152 1.1 jmcneill static struct sunxi_ccu_clk sun50i_a64_ccu_clks[] = {
153 1.1 jmcneill SUNXI_CCU_NKMP(A64_CLK_PLL_PERIPH0, "pll_periph0", "hosc",
154 1.1 jmcneill PLL_PERIPH0_CTRL_REG, /* reg */
155 1.1 jmcneill __BITS(12,8), /* n */
156 1.1 jmcneill __BITS(5,4), /* k */
157 1.1 jmcneill 0, /* m */
158 1.1 jmcneill __BITS(17,16), /* p */
159 1.1 jmcneill __BIT(31), /* enable */
160 1.1 jmcneill SUNXI_CCU_NKMP_DIVIDE_BY_TWO),
161 1.1 jmcneill
162 1.5 jmcneill SUNXI_CCU_NKMP_TABLE(A64_CLK_PLL_AUDIO_BASE, "pll_audio_base", "hosc",
163 1.5 jmcneill PLL_AUDIO_CTRL_REG, /* reg */
164 1.5 jmcneill __BITS(14,8), /* n */
165 1.5 jmcneill 0, /* k */
166 1.5 jmcneill __BITS(4,0), /* m */
167 1.5 jmcneill __BITS(19,16), /* p */
168 1.5 jmcneill __BIT(31), /* enable */
169 1.5 jmcneill __BIT(28), /* lock */
170 1.5 jmcneill sun50i_a64_ac_dig_table, /* table */
171 1.5 jmcneill 0),
172 1.5 jmcneill
173 1.5 jmcneill SUNXI_CCU_FIXED_FACTOR(A64_CLK_PLL_AUDIO, "pll_audio", "pll_audio_base", 1, 1),
174 1.5 jmcneill SUNXI_CCU_FIXED_FACTOR(A64_CLK_PLL_AUDIO_2X, "pll_audio_2x", "pll_audio_base", 1, 2),
175 1.5 jmcneill SUNXI_CCU_FIXED_FACTOR(A64_CLK_PLL_AUDIO_4X, "pll_audio_4x", "pll_audio_base", 1, 4),
176 1.5 jmcneill SUNXI_CCU_FIXED_FACTOR(A64_CLK_PLL_AUDIO_8X, "pll_audio_8x", "pll_audio_base", 1, 8),
177 1.5 jmcneill
178 1.1 jmcneill SUNXI_CCU_PREDIV(A64_CLK_AHB1, "ahb1", ahb1_parents,
179 1.1 jmcneill AHB1_APB1_CFG_REG, /* reg */
180 1.1 jmcneill __BITS(7,6), /* prediv */
181 1.1 jmcneill __BIT(3), /* prediv_sel */
182 1.1 jmcneill __BITS(5,4), /* div */
183 1.1 jmcneill __BITS(13,12), /* sel */
184 1.1 jmcneill SUNXI_CCU_PREDIV_POWER_OF_TWO),
185 1.1 jmcneill
186 1.1 jmcneill SUNXI_CCU_PREDIV(A64_CLK_AHB2, "ahb2", ahb2_parents,
187 1.1 jmcneill AHB2_CFG_REG, /* reg */
188 1.1 jmcneill 0, /* prediv */
189 1.1 jmcneill __BIT(1), /* prediv_sel */
190 1.1 jmcneill 0, /* div */
191 1.1 jmcneill __BITS(1,0), /* sel */
192 1.1 jmcneill SUNXI_CCU_PREDIV_DIVIDE_BY_TWO),
193 1.1 jmcneill
194 1.1 jmcneill SUNXI_CCU_DIV(A64_CLK_APB1, "apb1", apb1_parents,
195 1.1 jmcneill AHB1_APB1_CFG_REG, /* reg */
196 1.1 jmcneill __BITS(9,8), /* div */
197 1.1 jmcneill 0, /* sel */
198 1.1 jmcneill SUNXI_CCU_DIV_POWER_OF_TWO|SUNXI_CCU_DIV_ZERO_IS_ONE),
199 1.1 jmcneill
200 1.1 jmcneill SUNXI_CCU_NM(A64_CLK_APB2, "apb2", apb2_parents,
201 1.1 jmcneill APB2_CFG_REG, /* reg */
202 1.1 jmcneill __BITS(17,16), /* n */
203 1.1 jmcneill __BITS(4,0), /* m */
204 1.1 jmcneill __BITS(25,24), /* sel */
205 1.1 jmcneill 0, /* enable */
206 1.1 jmcneill SUNXI_CCU_NM_POWER_OF_TWO),
207 1.1 jmcneill
208 1.1 jmcneill SUNXI_CCU_NM(A64_CLK_MMC0, "mmc0", mod_parents,
209 1.1 jmcneill SDMMC0_CLK_REG, __BITS(17, 16), __BITS(3,0), __BITS(25, 24), __BIT(31),
210 1.1 jmcneill SUNXI_CCU_NM_POWER_OF_TWO|SUNXI_CCU_NM_ROUND_DOWN),
211 1.1 jmcneill SUNXI_CCU_NM(A64_CLK_MMC1, "mmc1", mod_parents,
212 1.1 jmcneill SDMMC1_CLK_REG, __BITS(17, 16), __BITS(3,0), __BITS(25, 24), __BIT(31),
213 1.1 jmcneill SUNXI_CCU_NM_POWER_OF_TWO|SUNXI_CCU_NM_ROUND_DOWN),
214 1.1 jmcneill SUNXI_CCU_NM(A64_CLK_MMC2, "mmc2", mod_parents,
215 1.1 jmcneill SDMMC2_CLK_REG, __BITS(17, 16), __BITS(3,0), __BITS(25, 24), __BIT(31),
216 1.1 jmcneill SUNXI_CCU_NM_POWER_OF_TWO|SUNXI_CCU_NM_ROUND_DOWN),
217 1.1 jmcneill
218 1.4 jmcneill SUNXI_CCU_DIV_GATE(A64_CLK_THS, "ths", ths_parents,
219 1.4 jmcneill THS_CLK_REG, /* reg */
220 1.4 jmcneill __BITS(1,0), /* div */
221 1.4 jmcneill __BITS(25,24), /* sel */
222 1.4 jmcneill __BIT(31), /* enable */
223 1.4 jmcneill SUNXI_CCU_DIV_TIMES_TWO),
224 1.4 jmcneill
225 1.5 jmcneill SUNXI_CCU_GATE(A64_CLK_AC_DIG, "ac-dig", "pll_audio",
226 1.5 jmcneill AC_DIG_CLK_REG, 31),
227 1.5 jmcneill SUNXI_CCU_GATE(A64_CLK_AC_DIG_4X, "ac-dig-4x", "pll_audio_4x",
228 1.5 jmcneill AC_DIG_CLK_REG, 30),
229 1.5 jmcneill
230 1.1 jmcneill SUNXI_CCU_GATE(A64_CLK_BUS_MIPI_DSI, "bus-mipi-dsi", "ahb1",
231 1.1 jmcneill BUS_CLK_GATING_REG0, 1),
232 1.1 jmcneill SUNXI_CCU_GATE(A64_CLK_BUS_CE, "bus-ce", "ahb1",
233 1.1 jmcneill BUS_CLK_GATING_REG0, 5),
234 1.1 jmcneill SUNXI_CCU_GATE(A64_CLK_BUS_DMA, "bus-dma", "ahb1",
235 1.1 jmcneill BUS_CLK_GATING_REG0, 6),
236 1.1 jmcneill SUNXI_CCU_GATE(A64_CLK_BUS_MMC0, "bus-mmc0", "ahb1",
237 1.1 jmcneill BUS_CLK_GATING_REG0, 8),
238 1.1 jmcneill SUNXI_CCU_GATE(A64_CLK_BUS_MMC1, "bus-mmc1", "ahb1",
239 1.1 jmcneill BUS_CLK_GATING_REG0, 9),
240 1.1 jmcneill SUNXI_CCU_GATE(A64_CLK_BUS_MMC2, "bus-mmc2", "ahb1",
241 1.1 jmcneill BUS_CLK_GATING_REG0, 10),
242 1.1 jmcneill SUNXI_CCU_GATE(A64_CLK_BUS_NAND, "bus-nand", "ahb1",
243 1.1 jmcneill BUS_CLK_GATING_REG0, 13),
244 1.1 jmcneill SUNXI_CCU_GATE(A64_CLK_BUS_DRAM, "bus-dram", "ahb1",
245 1.1 jmcneill BUS_CLK_GATING_REG0, 14),
246 1.1 jmcneill SUNXI_CCU_GATE(A64_CLK_BUS_EMAC, "bus-emac", "ahb2",
247 1.1 jmcneill BUS_CLK_GATING_REG0, 17),
248 1.1 jmcneill SUNXI_CCU_GATE(A64_CLK_BUS_TS, "bus-ts", "ahb1",
249 1.1 jmcneill BUS_CLK_GATING_REG0, 18),
250 1.1 jmcneill SUNXI_CCU_GATE(A64_CLK_BUS_HSTIMER, "bus-hstimer", "ahb1",
251 1.1 jmcneill BUS_CLK_GATING_REG0, 19),
252 1.1 jmcneill SUNXI_CCU_GATE(A64_CLK_BUS_SPI0, "bus-spi0", "ahb1",
253 1.1 jmcneill BUS_CLK_GATING_REG0, 20),
254 1.1 jmcneill SUNXI_CCU_GATE(A64_CLK_BUS_SPI1, "bus-spi1", "ahb1",
255 1.1 jmcneill BUS_CLK_GATING_REG0, 21),
256 1.1 jmcneill SUNXI_CCU_GATE(A64_CLK_BUS_OTG, "bus-otg", "ahb1",
257 1.1 jmcneill BUS_CLK_GATING_REG0, 23),
258 1.1 jmcneill SUNXI_CCU_GATE(A64_CLK_BUS_EHCI0, "bus-ehci0", "ahb1",
259 1.1 jmcneill BUS_CLK_GATING_REG0, 24),
260 1.1 jmcneill SUNXI_CCU_GATE(A64_CLK_BUS_EHCI1, "bus-ehci1", "ahb2",
261 1.1 jmcneill BUS_CLK_GATING_REG0, 25),
262 1.1 jmcneill SUNXI_CCU_GATE(A64_CLK_BUS_OHCI0, "bus-ohci0", "ahb1",
263 1.2 jmcneill BUS_CLK_GATING_REG0, 28),
264 1.1 jmcneill SUNXI_CCU_GATE(A64_CLK_BUS_OHCI1, "bus-ohci1", "ahb2",
265 1.2 jmcneill BUS_CLK_GATING_REG0, 29),
266 1.1 jmcneill
267 1.1 jmcneill SUNXI_CCU_GATE(A64_CLK_BUS_VE, "bus-ve", "ahb1",
268 1.1 jmcneill BUS_CLK_GATING_REG1, 0),
269 1.1 jmcneill SUNXI_CCU_GATE(A64_CLK_BUS_TCON0, "bus-tcon0", "ahb1",
270 1.1 jmcneill BUS_CLK_GATING_REG1, 3),
271 1.1 jmcneill SUNXI_CCU_GATE(A64_CLK_BUS_TCON1, "bus-tcon1", "ahb1",
272 1.1 jmcneill BUS_CLK_GATING_REG1, 4),
273 1.1 jmcneill SUNXI_CCU_GATE(A64_CLK_BUS_DEINTERLACE, "bus-deinterlace", "ahb1",
274 1.1 jmcneill BUS_CLK_GATING_REG1, 5),
275 1.1 jmcneill SUNXI_CCU_GATE(A64_CLK_BUS_CSI, "bus-csi", "ahb1",
276 1.1 jmcneill BUS_CLK_GATING_REG1, 8),
277 1.1 jmcneill SUNXI_CCU_GATE(A64_CLK_BUS_HDMI, "bus-hdmi", "ahb1",
278 1.1 jmcneill BUS_CLK_GATING_REG1, 10),
279 1.1 jmcneill SUNXI_CCU_GATE(A64_CLK_BUS_DE, "bus-de", "ahb1",
280 1.1 jmcneill BUS_CLK_GATING_REG1, 12),
281 1.1 jmcneill SUNXI_CCU_GATE(A64_CLK_BUS_GPU, "bus-gpu", "ahb1",
282 1.1 jmcneill BUS_CLK_GATING_REG1, 20),
283 1.1 jmcneill SUNXI_CCU_GATE(A64_CLK_BUS_MSGBOX, "bus-msgbox", "ahb1",
284 1.1 jmcneill BUS_CLK_GATING_REG1, 21),
285 1.1 jmcneill SUNXI_CCU_GATE(A64_CLK_BUS_SPINLOCK, "bus-spinlock", "ahb1",
286 1.1 jmcneill BUS_CLK_GATING_REG1, 22),
287 1.1 jmcneill
288 1.4 jmcneill SUNXI_CCU_GATE(A64_CLK_BUS_THS, "bus-ths", "apb1",
289 1.4 jmcneill BUS_CLK_GATING_REG2, 8),
290 1.1 jmcneill
291 1.1 jmcneill SUNXI_CCU_GATE(A64_CLK_BUS_CODEC, "bus-codec", "apb1",
292 1.1 jmcneill BUS_CLK_GATING_REG3, 0),
293 1.1 jmcneill SUNXI_CCU_GATE(A64_CLK_BUS_SPDIF, "bus-spdif", "apb1",
294 1.1 jmcneill BUS_CLK_GATING_REG3, 1),
295 1.1 jmcneill SUNXI_CCU_GATE(A64_CLK_BUS_PIO, "bus-pio", "apb1",
296 1.1 jmcneill BUS_CLK_GATING_REG3, 5),
297 1.1 jmcneill SUNXI_CCU_GATE(A64_CLK_BUS_I2S0, "bus-i2s0", "apb1",
298 1.1 jmcneill BUS_CLK_GATING_REG3, 12),
299 1.1 jmcneill SUNXI_CCU_GATE(A64_CLK_BUS_I2S1, "bus-i2s1", "apb1",
300 1.1 jmcneill BUS_CLK_GATING_REG3, 13),
301 1.1 jmcneill SUNXI_CCU_GATE(A64_CLK_BUS_I2S2, "bus-i2s2", "apb1",
302 1.1 jmcneill BUS_CLK_GATING_REG3, 14),
303 1.1 jmcneill
304 1.1 jmcneill SUNXI_CCU_GATE(A64_CLK_BUS_I2C0, "bus-i2c0", "apb2",
305 1.1 jmcneill BUS_CLK_GATING_REG4, 0),
306 1.1 jmcneill SUNXI_CCU_GATE(A64_CLK_BUS_I2C1, "bus-i2c1", "apb2",
307 1.1 jmcneill BUS_CLK_GATING_REG4, 1),
308 1.1 jmcneill SUNXI_CCU_GATE(A64_CLK_BUS_I2C2, "bus-i2c2", "apb2",
309 1.1 jmcneill BUS_CLK_GATING_REG4, 2),
310 1.1 jmcneill SUNXI_CCU_GATE(A64_CLK_BUS_SCR, "bus-scr", "apb2",
311 1.1 jmcneill BUS_CLK_GATING_REG4, 5),
312 1.1 jmcneill SUNXI_CCU_GATE(A64_CLK_BUS_UART0, "bus-uart0", "apb2",
313 1.1 jmcneill BUS_CLK_GATING_REG4, 16),
314 1.1 jmcneill SUNXI_CCU_GATE(A64_CLK_BUS_UART1, "bus-uart1", "apb2",
315 1.1 jmcneill BUS_CLK_GATING_REG4, 17),
316 1.1 jmcneill SUNXI_CCU_GATE(A64_CLK_BUS_UART2, "bus-uart2", "apb2",
317 1.1 jmcneill BUS_CLK_GATING_REG4, 18),
318 1.1 jmcneill SUNXI_CCU_GATE(A64_CLK_BUS_UART3, "bus-uart3", "apb2",
319 1.1 jmcneill BUS_CLK_GATING_REG4, 19),
320 1.1 jmcneill SUNXI_CCU_GATE(A64_CLK_BUS_UART4, "bus-uart4", "apb2",
321 1.1 jmcneill BUS_CLK_GATING_REG4, 20),
322 1.1 jmcneill
323 1.1 jmcneill SUNXI_CCU_GATE(A64_CLK_USB_PHY0, "usb-phy0", "hosc",
324 1.1 jmcneill USBPHY_CFG_REG, 8),
325 1.1 jmcneill SUNXI_CCU_GATE(A64_CLK_USB_PHY1, "usb-phy1", "hosc",
326 1.1 jmcneill USBPHY_CFG_REG, 9),
327 1.1 jmcneill SUNXI_CCU_GATE(A64_CLK_USB_HSIC, "usb-hsic", "hosc",
328 1.1 jmcneill USBPHY_CFG_REG, 10),
329 1.1 jmcneill SUNXI_CCU_GATE(A64_CLK_USB_HSIC_12M, "usb-hsic-12m", "hosc",
330 1.1 jmcneill USBPHY_CFG_REG, 11),
331 1.1 jmcneill SUNXI_CCU_GATE(A64_CLK_USB_OHCI0, "usb-ohci0", "hosc",
332 1.1 jmcneill USBPHY_CFG_REG, 16),
333 1.1 jmcneill SUNXI_CCU_GATE(A64_CLK_USB_OHCI1, "usb-ohci1", "usb-ohci0",
334 1.1 jmcneill USBPHY_CFG_REG, 17),
335 1.1 jmcneill };
336 1.1 jmcneill
337 1.1 jmcneill static int
338 1.1 jmcneill sun50i_a64_ccu_match(device_t parent, cfdata_t cf, void *aux)
339 1.1 jmcneill {
340 1.1 jmcneill struct fdt_attach_args * const faa = aux;
341 1.1 jmcneill
342 1.1 jmcneill return of_match_compatible(faa->faa_phandle, compatible);
343 1.1 jmcneill }
344 1.1 jmcneill
345 1.1 jmcneill static void
346 1.1 jmcneill sun50i_a64_ccu_attach(device_t parent, device_t self, void *aux)
347 1.1 jmcneill {
348 1.1 jmcneill struct sunxi_ccu_softc * const sc = device_private(self);
349 1.1 jmcneill struct fdt_attach_args * const faa = aux;
350 1.1 jmcneill
351 1.1 jmcneill sc->sc_dev = self;
352 1.1 jmcneill sc->sc_phandle = faa->faa_phandle;
353 1.1 jmcneill sc->sc_bst = faa->faa_bst;
354 1.1 jmcneill
355 1.1 jmcneill sc->sc_resets = sun50i_a64_ccu_resets;
356 1.1 jmcneill sc->sc_nresets = __arraycount(sun50i_a64_ccu_resets);
357 1.1 jmcneill
358 1.1 jmcneill sc->sc_clks = sun50i_a64_ccu_clks;
359 1.1 jmcneill sc->sc_nclks = __arraycount(sun50i_a64_ccu_clks);
360 1.1 jmcneill
361 1.1 jmcneill if (sunxi_ccu_attach(sc) != 0)
362 1.1 jmcneill return;
363 1.1 jmcneill
364 1.1 jmcneill aprint_naive("\n");
365 1.1 jmcneill aprint_normal(": A64 CCU\n");
366 1.1 jmcneill
367 1.1 jmcneill sunxi_ccu_print(sc);
368 1.1 jmcneill }
369