Home | History | Annotate | Line # | Download | only in sunxi
sun9i_a80_ccu.c revision 1.2
      1 /* $NetBSD: sun9i_a80_ccu.c,v 1.2 2019/01/03 15:49:09 jmcneill Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 2017 Jared McNeill <jmcneill (at) invisible.ca>
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     21  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     23  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     24  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  * SUCH DAMAGE.
     27  */
     28 
     29 #include <sys/cdefs.h>
     30 
     31 __KERNEL_RCSID(1, "$NetBSD: sun9i_a80_ccu.c,v 1.2 2019/01/03 15:49:09 jmcneill Exp $");
     32 
     33 #include <sys/param.h>
     34 #include <sys/bus.h>
     35 #include <sys/device.h>
     36 #include <sys/systm.h>
     37 
     38 #include <dev/fdt/fdtvar.h>
     39 
     40 #include <arm/sunxi/sunxi_ccu.h>
     41 #include <arm/sunxi/sun9i_a80_ccu.h>
     42 
     43 /* CCU */
     44 #define	PLL_C0CPUX_CTRL_REG	0x000
     45 #define	PLL_C1CPUX_CTRL_REG	0x004
     46 #define	PLL_PERIPH0_CTRL_REG	0x00c
     47 #define	PLL_PERIPH1_CTRL_REG	0x02c
     48 #define	CPU_CLK_SRC_REG		0x050
     49 #define	 CPU_CLK_SRC_SELECT(cluster)	__BIT((cluster) * 8)
     50 #define	GTBUS_CLK_CFG_REG	0x05c
     51 #define	AHB0_CLK_CFG_REG	0x060
     52 #define	AHB1_CLK_CFG_REG	0x064
     53 #define	AHB2_CLK_CFG_REG	0x068
     54 #define	APB0_CLK_CFG_REG	0x070
     55 #define	APB1_CLK_CFG_REG	0x074
     56 #define	PLL_STABLE_STATUS_REG	0x09c
     57 
     58 /* CCU_SCLK */
     59 #define	SDMMC0_CLK_REG		0x410
     60 #define	SDMMC1_CLK_REG		0x414
     61 #define	SDMMC2_CLK_REG		0x418
     62 #define	BUS_CLK_GATING_REG0	0x580
     63 #define	BUS_CLK_GATING_REG1	0x584
     64 #define	BUS_CLK_GATING_REG2	0x588
     65 #define	BUS_CLK_GATING_REG3	0x590
     66 #define	BUS_CLK_GATING_REG4	0x594
     67 #define	BUS_SOFT_RST_REG0	0x5a0
     68 #define	BUS_SOFT_RST_REG1	0x5a4
     69 #define	BUS_SOFT_RST_REG2	0x5a8
     70 #define	BUS_SOFT_RST_REG3	0x5b0
     71 #define	BUS_SOFT_RST_REG4	0x5b4
     72 
     73 static int sun9i_a80_ccu_match(device_t, cfdata_t, void *);
     74 static void sun9i_a80_ccu_attach(device_t, device_t, void *);
     75 
     76 static const char * compatible[] = {
     77 	"allwinner,sun9i-a80-ccu",
     78 	NULL
     79 };
     80 
     81 CFATTACH_DECL_NEW(sunxi_a80_ccu, sizeof(struct sunxi_ccu_softc),
     82 	sun9i_a80_ccu_match, sun9i_a80_ccu_attach, NULL, NULL);
     83 
     84 static struct sunxi_ccu_reset sun9i_a80_ccu_resets[] = {
     85 	SUNXI_CCU_RESET(A80_RST_BUS_FD, BUS_SOFT_RST_REG0, 0),
     86 	SUNXI_CCU_RESET(A80_RST_BUS_GPU_CTRL, BUS_SOFT_RST_REG0, 3),
     87 	SUNXI_CCU_RESET(A80_RST_BUS_SS, BUS_SOFT_RST_REG0, 5),
     88 	SUNXI_CCU_RESET(A80_RST_BUS_MMC, BUS_SOFT_RST_REG0, 8),
     89 	SUNXI_CCU_RESET(A80_RST_BUS_NAND1, BUS_SOFT_RST_REG0, 12),
     90 	SUNXI_CCU_RESET(A80_RST_BUS_NAND0, BUS_SOFT_RST_REG0, 13),
     91 	SUNXI_CCU_RESET(A80_RST_BUS_TS, BUS_SOFT_RST_REG0, 18),
     92 	SUNXI_CCU_RESET(A80_RST_BUS_SPI0, BUS_SOFT_RST_REG0, 20),
     93 	SUNXI_CCU_RESET(A80_RST_BUS_SPI1, BUS_SOFT_RST_REG0, 21),
     94 	SUNXI_CCU_RESET(A80_RST_BUS_SPI2, BUS_SOFT_RST_REG0, 22),
     95 	SUNXI_CCU_RESET(A80_RST_BUS_SPI3, BUS_SOFT_RST_REG0, 23),
     96 
     97 	SUNXI_CCU_RESET(A80_RST_BUS_OTG_PHY, BUS_SOFT_RST_REG1, 1),
     98 	SUNXI_CCU_RESET(A80_RST_BUS_MSGBOX, BUS_SOFT_RST_REG1, 21),
     99 	SUNXI_CCU_RESET(A80_RST_BUS_SPINLOCK, BUS_SOFT_RST_REG1, 22),
    100 	SUNXI_CCU_RESET(A80_RST_BUS_HSTIMER, BUS_SOFT_RST_REG1, 23),
    101 	SUNXI_CCU_RESET(A80_RST_BUS_DMA, BUS_SOFT_RST_REG1, 24),
    102 
    103 	SUNXI_CCU_RESET(A80_RST_BUS_LCD0, BUS_SOFT_RST_REG2, 0),
    104 	SUNXI_CCU_RESET(A80_RST_BUS_LCD1, BUS_SOFT_RST_REG2, 1),
    105 	SUNXI_CCU_RESET(A80_RST_BUS_CSI, BUS_SOFT_RST_REG2, 4),
    106 	SUNXI_CCU_RESET(A80_RST_BUS_DE, BUS_SOFT_RST_REG2, 7),
    107 	SUNXI_CCU_RESET(A80_RST_BUS_MP, BUS_SOFT_RST_REG2, 8),
    108 	SUNXI_CCU_RESET(A80_RST_BUS_GPU, BUS_SOFT_RST_REG2, 9),
    109 
    110 	SUNXI_CCU_RESET(A80_RST_BUS_LRADC, BUS_SOFT_RST_REG3, 15),
    111 	SUNXI_CCU_RESET(A80_RST_BUS_GPADC, BUS_SOFT_RST_REG3, 17),
    112 
    113 	SUNXI_CCU_RESET(A80_RST_BUS_I2C0, BUS_SOFT_RST_REG4, 0),
    114 	SUNXI_CCU_RESET(A80_RST_BUS_I2C1, BUS_SOFT_RST_REG4, 1),
    115 	SUNXI_CCU_RESET(A80_RST_BUS_I2C2, BUS_SOFT_RST_REG4, 2),
    116 	SUNXI_CCU_RESET(A80_RST_BUS_I2C3, BUS_SOFT_RST_REG4, 3),
    117 	SUNXI_CCU_RESET(A80_RST_BUS_I2C4, BUS_SOFT_RST_REG4, 4),
    118 	SUNXI_CCU_RESET(A80_RST_BUS_UART0, BUS_SOFT_RST_REG4, 16),
    119 	SUNXI_CCU_RESET(A80_RST_BUS_UART1, BUS_SOFT_RST_REG4, 17),
    120 	SUNXI_CCU_RESET(A80_RST_BUS_UART2, BUS_SOFT_RST_REG4, 18),
    121 	SUNXI_CCU_RESET(A80_RST_BUS_UART3, BUS_SOFT_RST_REG4, 19),
    122 	SUNXI_CCU_RESET(A80_RST_BUS_UART4, BUS_SOFT_RST_REG4, 20),
    123 	SUNXI_CCU_RESET(A80_RST_BUS_UART5, BUS_SOFT_RST_REG4, 21),
    124 };
    125 
    126 static const char *gtbus_parents[] = { "hosc", "pll_periph0", "pll_periph1" };
    127 static const char *ahb0_parents[] = { "gtbus", "pll_periph0", "pll_periph1" };
    128 static const char *ahb1_parents[] = { "gtbus", "pll_periph0", "pll_periph1" };
    129 static const char *ahb2_parents[] = { "hosc", "pll_periph0", "pll_periph1" };
    130 static const char *apb_parents[] = { "hosc", "pll_periph0" };
    131 static const char *mmc_parents[] = { "hosc", "pll_periph0" };
    132 
    133 static kmutex_t cpux_axi_cfg_lock;
    134 
    135 static int
    136 sun9i_a80_ccu_cpux_set_rate(struct sunxi_ccu_softc *sc,
    137     struct sunxi_ccu_clk *clk, u_int rate)
    138 {
    139 	const int cluster = clk->u.nkmp.reg == PLL_C0CPUX_CTRL_REG ? 0 : 1;
    140 	struct sunxi_ccu_nkmp *nkmp = &clk->u.nkmp;
    141 	uint32_t val;
    142 	u_int n;
    143 
    144 	n = rate / 24000000;
    145 	if (n < 0x11 || n > 0xff)
    146 		return EINVAL;
    147 
    148 	/* Switch cluster to OSC24M clock */
    149 	mutex_enter(&cpux_axi_cfg_lock);
    150 	val = CCU_READ(sc, CPU_CLK_SRC_REG);
    151 	val &= ~CPU_CLK_SRC_SELECT(cluster);
    152 	CCU_WRITE(sc, CPU_CLK_SRC_REG, val);
    153 	mutex_exit(&cpux_axi_cfg_lock);
    154 
    155 	/* Set new PLL rate */
    156 	val = CCU_READ(sc, nkmp->reg);
    157 	val &= ~nkmp->n;
    158 	val |= __SHIFTIN(n, nkmp->n);
    159 	CCU_WRITE(sc, nkmp->reg, val);
    160 
    161 	/* Wait for PLL lock */
    162 	while ((CCU_READ(sc, PLL_STABLE_STATUS_REG) & nkmp->lock) == 0)
    163 		;
    164 
    165 	/* Switch cluster back to CPUX PLL */
    166 	mutex_enter(&cpux_axi_cfg_lock);
    167 	val = CCU_READ(sc, CPU_CLK_SRC_REG);
    168 	val |= CPU_CLK_SRC_SELECT(cluster);
    169 	CCU_WRITE(sc, CPU_CLK_SRC_SELECT(cluster), val);
    170 	mutex_exit(&cpux_axi_cfg_lock);
    171 
    172 	return 0;
    173 }
    174 
    175 static struct sunxi_ccu_clk sun9i_a80_ccu_clks[] = {
    176 	[A80_CLK_C0CPUX] = {
    177 		.type = SUNXI_CCU_NKMP,
    178 		.base.name = "pll_c0cpux",
    179 		.u.nkmp.reg = PLL_C0CPUX_CTRL_REG,
    180 		.u.nkmp.parent = "hosc",
    181 		.u.nkmp.n = __BITS(15,8),
    182 		.u.nkmp.k = 0,
    183 		.u.nkmp.m = __BITS(1,0),
    184 		.u.nkmp.p = __BIT(16),
    185 		.u.nkmp.enable = __BIT(31),
    186 		.u.nkmp.flags = SUNXI_CCU_NKMP_SCALE_CLOCK |
    187 			SUNXI_CCU_NKMP_FACTOR_N_EXACT |
    188 			SUNXI_CCU_NKMP_FACTOR_P_X4,
    189 		.u.nkmp.lock = __BIT(1),        /* PLL_STABLE_STATUS_REG */
    190 		.u.nkmp.table = NULL,
    191 		.enable = sunxi_ccu_nkmp_enable,
    192 		.get_rate = sunxi_ccu_nkmp_get_rate,
    193 		.set_rate = sun9i_a80_ccu_cpux_set_rate,
    194 		.get_parent = sunxi_ccu_nkmp_get_parent,
    195 	},
    196 
    197 	[A80_CLK_C1CPUX] = {
    198 		.type = SUNXI_CCU_NKMP,
    199 		.base.name = "pll_c1cpux",
    200 		.u.nkmp.reg = PLL_C1CPUX_CTRL_REG,
    201 		.u.nkmp.parent = "hosc",
    202 		.u.nkmp.n = __BITS(15,8),
    203 		.u.nkmp.k = 0,
    204 		.u.nkmp.m = __BITS(1,0),
    205 		.u.nkmp.p = __BIT(16),
    206 		.u.nkmp.enable = __BIT(31),
    207 		.u.nkmp.flags = SUNXI_CCU_NKMP_SCALE_CLOCK |
    208 			SUNXI_CCU_NKMP_FACTOR_N_EXACT |
    209 			SUNXI_CCU_NKMP_FACTOR_P_X4,
    210 		.u.nkmp.lock = __BIT(1),        /* PLL_STABLE_STATUS_REG */
    211 		.u.nkmp.table = NULL,
    212 		.enable = sunxi_ccu_nkmp_enable,
    213 		.get_rate = sunxi_ccu_nkmp_get_rate,
    214 		.set_rate = sun9i_a80_ccu_cpux_set_rate,
    215 		.get_parent = sunxi_ccu_nkmp_get_parent,
    216 	},
    217 
    218 	SUNXI_CCU_NKMP(A80_CLK_PLL_PERIPH0, "pll_periph0", "hosc",
    219 	    PLL_PERIPH0_CTRL_REG,	/* reg */
    220 	    __BITS(15,8),		/* n */
    221 	    __BIT(16), 			/* k */
    222 	    0,				/* m */
    223 	    __BIT(18),			/* p */
    224 	    __BIT(31),			/* enable */
    225 	    SUNXI_CCU_NKMP_FACTOR_N_EXACT),
    226 	SUNXI_CCU_NKMP(A80_CLK_PLL_PERIPH1, "pll_periph1", "hosc",
    227 	    PLL_PERIPH1_CTRL_REG,	/* reg */
    228 	    __BITS(15,8),		/* n */
    229 	    __BIT(16), 			/* k */
    230 	    0,				/* m */
    231 	    __BIT(18),			/* p */
    232 	    __BIT(31),			/* enable */
    233 	    SUNXI_CCU_NKMP_FACTOR_N_EXACT),
    234 
    235 	SUNXI_CCU_DIV(A80_CLK_GTBUS, "gtbus", gtbus_parents,
    236 	    GTBUS_CLK_CFG_REG,		/* reg */
    237 	    __BITS(1,0),		/* div */
    238 	    __BITS(25,24),		/* sel */
    239 	    0),
    240 
    241 	SUNXI_CCU_DIV(A80_CLK_AHB0, "ahb0", ahb0_parents,
    242 	    AHB0_CLK_CFG_REG,		/* reg */
    243 	    __BITS(1,0),		/* div */
    244 	    __BITS(25,24),		/* sel */
    245 	    SUNXI_CCU_DIV_POWER_OF_TWO),
    246 
    247 	SUNXI_CCU_DIV(A80_CLK_AHB1, "ahb1", ahb1_parents,
    248 	    AHB1_CLK_CFG_REG,		/* reg */
    249 	    __BITS(1,0),		/* div */
    250 	    __BITS(25,24),		/* sel */
    251 	    SUNXI_CCU_DIV_POWER_OF_TWO),
    252 
    253 	SUNXI_CCU_DIV(A80_CLK_AHB2, "ahb2", ahb2_parents,
    254 	    AHB2_CLK_CFG_REG,		/* reg */
    255 	    __BITS(1,0),		/* div */
    256 	    __BITS(25,24),		/* sel */
    257 	    SUNXI_CCU_DIV_POWER_OF_TWO),
    258 
    259 	SUNXI_CCU_DIV(A80_CLK_APB0, "apb0", apb_parents,
    260 	    APB0_CLK_CFG_REG,		/* reg */
    261 	    __BITS(1,0),		/* div */
    262 	    __BIT(24),			/* sel */
    263 	    SUNXI_CCU_DIV_POWER_OF_TWO),
    264 
    265 	SUNXI_CCU_NM(A80_CLK_APB1, "apb1", apb_parents,
    266 	    APB1_CLK_CFG_REG,		/* reg */
    267 	    __BITS(17,16),		/* n */
    268 	    __BITS(4,0),		/* m */
    269 	    __BIT(24),			/* sel */
    270 	    0,				/* enable */
    271 	    SUNXI_CCU_NM_POWER_OF_TWO),
    272 
    273 	SUNXI_CCU_NM(A80_CLK_MMC0, "mmc0", mmc_parents,
    274 	    SDMMC0_CLK_REG,		/* reg */
    275 	    __BITS(17,16),		/* n */
    276 	    __BITS(3,0),		/* m */
    277 	    __BITS(27,24),		/* sel */
    278 	    __BIT(31),			/* enable */
    279 	    SUNXI_CCU_NM_POWER_OF_TWO),
    280 	SUNXI_CCU_PHASE(A80_CLK_MMC0_SAMPLE, "mmc0_sample", "mmc0",
    281 	    SDMMC0_CLK_REG, __BITS(22,20)),
    282 	SUNXI_CCU_PHASE(A80_CLK_MMC0_OUTPUT, "mmc0_output", "mmc0",
    283 	    SDMMC0_CLK_REG, __BITS(10,8)),
    284 	SUNXI_CCU_NM(A80_CLK_MMC1, "mmc1", mmc_parents,
    285 	    SDMMC1_CLK_REG,		/* reg */
    286 	    __BITS(17,16),		/* n */
    287 	    __BITS(3,0),		/* m */
    288 	    __BITS(27,24),		/* sel */
    289 	    __BIT(31),			/* enable */
    290 	    SUNXI_CCU_NM_POWER_OF_TWO),
    291 	SUNXI_CCU_PHASE(A80_CLK_MMC1_SAMPLE, "mmc1_sample", "mmc1",
    292 	    SDMMC1_CLK_REG, __BITS(22,20)),
    293 	SUNXI_CCU_PHASE(A80_CLK_MMC1_OUTPUT, "mmc1_output", "mmc1",
    294 	    SDMMC1_CLK_REG, __BITS(10,8)),
    295 	SUNXI_CCU_NM(A80_CLK_MMC2, "mmc2", mmc_parents,
    296 	    SDMMC2_CLK_REG,		/* reg */
    297 	    __BITS(17,16),		/* n */
    298 	    __BITS(3,0),		/* m */
    299 	    __BITS(27,24),		/* sel */
    300 	    __BIT(31),			/* enable */
    301 	    SUNXI_CCU_NM_POWER_OF_TWO),
    302 	SUNXI_CCU_PHASE(A80_CLK_MMC2_SAMPLE, "mmc2_sample", "mmc2",
    303 	    SDMMC2_CLK_REG, __BITS(22,20)),
    304 	SUNXI_CCU_PHASE(A80_CLK_MMC2_OUTPUT, "mmc2_output", "mmc2",
    305 	    SDMMC2_CLK_REG, __BITS(10,8)),
    306 
    307 	SUNXI_CCU_GATE(A80_CLK_BUS_FD, "ahb0-fd", "ahb0",
    308 	    BUS_CLK_GATING_REG0, 0),
    309 	SUNXI_CCU_GATE(A80_CLK_BUS_GPU_CTRL, "ahb0-gpu-ctrl", "ahb0",
    310 	    BUS_CLK_GATING_REG0, 3),
    311 	SUNXI_CCU_GATE(A80_CLK_BUS_SS, "ahb0-ss", "ahb0",
    312 	    BUS_CLK_GATING_REG0, 5),
    313 	SUNXI_CCU_GATE(A80_CLK_BUS_MMC, "ahb0-mmc", "ahb0",
    314 	    BUS_CLK_GATING_REG0, 8),
    315 	SUNXI_CCU_GATE(A80_CLK_BUS_NAND1, "ahb0-nand1", "ahb0",
    316 	    BUS_CLK_GATING_REG0, 12),
    317 	SUNXI_CCU_GATE(A80_CLK_BUS_NAND0, "ahb0-nand0", "ahb0",
    318 	    BUS_CLK_GATING_REG0, 13),
    319 	SUNXI_CCU_GATE(A80_CLK_BUS_TS, "ahb0-ts", "ahb0",
    320 	    BUS_CLK_GATING_REG0, 18),
    321 	SUNXI_CCU_GATE(A80_CLK_BUS_SPI0, "ahb0-spi0", "ahb0",
    322 	    BUS_CLK_GATING_REG0, 20),
    323 	SUNXI_CCU_GATE(A80_CLK_BUS_SPI1, "ahb0-spi1", "ahb0",
    324 	    BUS_CLK_GATING_REG0, 21),
    325 	SUNXI_CCU_GATE(A80_CLK_BUS_SPI2, "ahb0-spi2", "ahb0",
    326 	    BUS_CLK_GATING_REG0, 22),
    327 	SUNXI_CCU_GATE(A80_CLK_BUS_SPI3, "ahb0-spi3", "ahb0",
    328 	    BUS_CLK_GATING_REG0, 23),
    329 
    330 	SUNXI_CCU_GATE(A80_CLK_BUS_USB, "ahb1-usb", "ahb1",
    331 	    BUS_CLK_GATING_REG1, 1),
    332 	SUNXI_CCU_GATE(A80_CLK_BUS_MSGBOX, "ahb1-msgbox", "ahb1",
    333 	    BUS_CLK_GATING_REG1, 21),
    334 	SUNXI_CCU_GATE(A80_CLK_BUS_SPINLOCK, "ahb1-spinlock", "ahb1",
    335 	    BUS_CLK_GATING_REG1, 22),
    336 	SUNXI_CCU_GATE(A80_CLK_BUS_HSTIMER, "ahb1-hstimer", "ahb1",
    337 	    BUS_CLK_GATING_REG1, 23),
    338 	SUNXI_CCU_GATE(A80_CLK_BUS_DMA, "ahb1-dma", "ahb1",
    339 	    BUS_CLK_GATING_REG1, 24),
    340 
    341 	SUNXI_CCU_GATE(A80_CLK_BUS_LCD0, "ahb2-lcd0", "ahb2",
    342 	    BUS_CLK_GATING_REG2, 0),
    343 	SUNXI_CCU_GATE(A80_CLK_BUS_LCD1, "ahb2-lcd1", "ahb2",
    344 	    BUS_CLK_GATING_REG2, 1),
    345 	SUNXI_CCU_GATE(A80_CLK_BUS_CSI, "ahb2-csi", "ahb2",
    346 	    BUS_CLK_GATING_REG2, 4),
    347 	SUNXI_CCU_GATE(A80_CLK_BUS_DE, "ahb2-de", "ahb2",
    348 	    BUS_CLK_GATING_REG2, 7),
    349 	SUNXI_CCU_GATE(A80_CLK_BUS_MP, "ahb2-mp", "ahb2",
    350 	    BUS_CLK_GATING_REG2, 8),
    351 
    352 	SUNXI_CCU_GATE(A80_CLK_BUS_PIO, "apb0-pio", "apb0",
    353 	    BUS_CLK_GATING_REG3, 5),
    354 	SUNXI_CCU_GATE(A80_CLK_BUS_LRADC, "apb0-lradc", "apb0",
    355 	    BUS_CLK_GATING_REG3, 15),
    356 	SUNXI_CCU_GATE(A80_CLK_BUS_GPADC, "apb0-gpadc", "apb0",
    357 	    BUS_CLK_GATING_REG3, 17),
    358 
    359 	SUNXI_CCU_GATE(A80_CLK_BUS_I2C0, "apb1-i2c0", "apb1",
    360 	    BUS_CLK_GATING_REG4, 0),
    361 	SUNXI_CCU_GATE(A80_CLK_BUS_I2C1, "apb1-i2c1", "apb1",
    362 	    BUS_CLK_GATING_REG4, 1),
    363 	SUNXI_CCU_GATE(A80_CLK_BUS_I2C2, "apb1-i2c2", "apb1",
    364 	    BUS_CLK_GATING_REG4, 2),
    365 	SUNXI_CCU_GATE(A80_CLK_BUS_I2C3, "apb1-i2c3", "apb1",
    366 	    BUS_CLK_GATING_REG4, 3),
    367 	SUNXI_CCU_GATE(A80_CLK_BUS_I2C4, "apb1-i2c4", "apb1",
    368 	    BUS_CLK_GATING_REG4, 4),
    369 	SUNXI_CCU_GATE(A80_CLK_BUS_UART0, "apb1-uart0", "apb1",
    370 	    BUS_CLK_GATING_REG4, 16),
    371 	SUNXI_CCU_GATE(A80_CLK_BUS_UART1, "apb1-uart1", "apb1",
    372 	    BUS_CLK_GATING_REG4, 17),
    373 	SUNXI_CCU_GATE(A80_CLK_BUS_UART2, "apb1-uart2", "apb1",
    374 	    BUS_CLK_GATING_REG4, 18),
    375 	SUNXI_CCU_GATE(A80_CLK_BUS_UART3, "apb1-uart3", "apb1",
    376 	    BUS_CLK_GATING_REG4, 19),
    377 	SUNXI_CCU_GATE(A80_CLK_BUS_UART4, "apb1-uart4", "apb1",
    378 	    BUS_CLK_GATING_REG4, 20),
    379 	SUNXI_CCU_GATE(A80_CLK_BUS_UART5, "apb1-uart5", "apb1",
    380 	    BUS_CLK_GATING_REG4, 21),
    381 };
    382 
    383 static int
    384 sun9i_a80_ccu_match(device_t parent, cfdata_t cf, void *aux)
    385 {
    386 	struct fdt_attach_args * const faa = aux;
    387 
    388 	return of_match_compatible(faa->faa_phandle, compatible);
    389 }
    390 
    391 static void
    392 sun9i_a80_ccu_attach(device_t parent, device_t self, void *aux)
    393 {
    394 	struct sunxi_ccu_softc * const sc = device_private(self);
    395 	struct fdt_attach_args * const faa = aux;
    396 
    397 	sc->sc_dev = self;
    398 	sc->sc_phandle = faa->faa_phandle;
    399 	sc->sc_bst = faa->faa_bst;
    400 
    401 	sc->sc_resets = sun9i_a80_ccu_resets;
    402 	sc->sc_nresets = __arraycount(sun9i_a80_ccu_resets);
    403 
    404 	sc->sc_clks = sun9i_a80_ccu_clks;
    405 	sc->sc_nclks = __arraycount(sun9i_a80_ccu_clks);
    406 
    407 	mutex_init(&cpux_axi_cfg_lock, MUTEX_DEFAULT, IPL_HIGH);
    408 
    409 	if (sunxi_ccu_attach(sc) != 0)
    410 		return;
    411 
    412 	aprint_naive("\n");
    413 	aprint_normal(": A80 CCU\n");
    414 
    415 	sunxi_ccu_print(sc);
    416 }
    417