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