| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: sun50i_a64_ccu.c,v 1.11 2019/01/30 01:24:00 jmcneill Exp $ */ | | 1 | /* $NetBSD: sun50i_a64_ccu.c,v 1.12 2019/06/27 14:51:33 jmcneill Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2017 Jared McNeill <jmcneill@invisible.ca> | | 4 | * Copyright (c) 2017 Jared McNeill <jmcneill@invisible.ca> |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -18,65 +18,67 @@ | | | @@ -18,65 +18,67 @@ |
18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | | 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | | 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | | 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
21 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | | 21 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | | 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
23 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | | 23 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 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 | | 25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
26 | * SUCH DAMAGE. | | 26 | * SUCH DAMAGE. |
27 | */ | | 27 | */ |
28 | | | 28 | |
29 | #include <sys/cdefs.h> | | 29 | #include <sys/cdefs.h> |
30 | | | 30 | |
31 | __KERNEL_RCSID(1, "$NetBSD: sun50i_a64_ccu.c,v 1.11 2019/01/30 01:24:00 jmcneill Exp $"); | | 31 | __KERNEL_RCSID(1, "$NetBSD: sun50i_a64_ccu.c,v 1.12 2019/06/27 14:51:33 jmcneill Exp $"); |
32 | | | 32 | |
33 | #include <sys/param.h> | | 33 | #include <sys/param.h> |
34 | #include <sys/bus.h> | | 34 | #include <sys/bus.h> |
35 | #include <sys/device.h> | | 35 | #include <sys/device.h> |
36 | #include <sys/systm.h> | | 36 | #include <sys/systm.h> |
37 | | | 37 | |
38 | #include <dev/fdt/fdtvar.h> | | 38 | #include <dev/fdt/fdtvar.h> |
39 | | | 39 | |
40 | #include <arm/sunxi/sunxi_ccu.h> | | 40 | #include <arm/sunxi/sunxi_ccu.h> |
41 | #include <arm/sunxi/sun50i_a64_ccu.h> | | 41 | #include <arm/sunxi/sun50i_a64_ccu.h> |
42 | | | 42 | |
43 | #define PLL_CPUX_CTRL_REG 0x000 | | 43 | #define PLL_CPUX_CTRL_REG 0x000 |
44 | #define PLL_AUDIO_CTRL_REG 0x008 | | 44 | #define PLL_AUDIO_CTRL_REG 0x008 |
45 | #define PLL_VIDEO0_CTRL_REG 0x010 | | 45 | #define PLL_VIDEO0_CTRL_REG 0x010 |
46 | #define PLL_PERIPH0_CTRL_REG 0x028 | | 46 | #define PLL_PERIPH0_CTRL_REG 0x028 |
47 | #define PLL_PERIPH1_CTRL_REG 0x02c | | 47 | #define PLL_PERIPH1_CTRL_REG 0x02c |
48 | #define PLL_VIDEO1_CTRL_REG 0x030 | | 48 | #define PLL_VIDEO1_CTRL_REG 0x030 |
| | | 49 | #define PLL_GPU_CTRL_REG 0x038 |
49 | #define PLL_DE_CTRL_REG 0x048 | | 50 | #define PLL_DE_CTRL_REG 0x048 |
50 | #define AHB1_APB1_CFG_REG 0x054 | | 51 | #define AHB1_APB1_CFG_REG 0x054 |
51 | #define APB2_CFG_REG 0x058 | | 52 | #define APB2_CFG_REG 0x058 |
52 | #define AHB2_CFG_REG 0x05c | | 53 | #define AHB2_CFG_REG 0x05c |
53 | #define BUS_CLK_GATING_REG0 0x060 | | 54 | #define BUS_CLK_GATING_REG0 0x060 |
54 | #define BUS_CLK_GATING_REG1 0x064 | | 55 | #define BUS_CLK_GATING_REG1 0x064 |
55 | #define BUS_CLK_GATING_REG2 0x068 | | 56 | #define BUS_CLK_GATING_REG2 0x068 |
56 | #define BUS_CLK_GATING_REG3 0x06c | | 57 | #define BUS_CLK_GATING_REG3 0x06c |
57 | #define BUS_CLK_GATING_REG4 0x070 | | 58 | #define BUS_CLK_GATING_REG4 0x070 |
58 | #define THS_CLK_REG 0x074 | | 59 | #define THS_CLK_REG 0x074 |
59 | #define SDMMC0_CLK_REG 0x088 | | 60 | #define SDMMC0_CLK_REG 0x088 |
60 | #define SDMMC1_CLK_REG 0x08c | | 61 | #define SDMMC1_CLK_REG 0x08c |
61 | #define SDMMC2_CLK_REG 0x090 | | 62 | #define SDMMC2_CLK_REG 0x090 |
62 | #define USBPHY_CFG_REG 0x0cc | | 63 | #define USBPHY_CFG_REG 0x0cc |
63 | #define DRAM_CFG_REG 0x0f4 | | 64 | #define DRAM_CFG_REG 0x0f4 |
64 | #define MBUS_RST_REG 0x0fc | | 65 | #define MBUS_RST_REG 0x0fc |
65 | #define DE_CLK_REG 0x104 | | 66 | #define DE_CLK_REG 0x104 |
66 | #define TCON1_CLK_REG 0x11c | | 67 | #define TCON1_CLK_REG 0x11c |
67 | #define AC_DIG_CLK_REG 0x140 | | 68 | #define AC_DIG_CLK_REG 0x140 |
68 | #define HDMI_CLK_REG 0x150 | | 69 | #define HDMI_CLK_REG 0x150 |
69 | #define HDMI_SLOW_CLK_REG 0x154 | | 70 | #define HDMI_SLOW_CLK_REG 0x154 |
| | | 71 | #define GPU_CLK_REG 0x1a0 |
70 | #define BUS_SOFT_RST_REG0 0x2c0 | | 72 | #define BUS_SOFT_RST_REG0 0x2c0 |
71 | #define BUS_SOFT_RST_REG1 0x2c4 | | 73 | #define BUS_SOFT_RST_REG1 0x2c4 |
72 | #define BUS_SOFT_RST_REG2 0x2c8 | | 74 | #define BUS_SOFT_RST_REG2 0x2c8 |
73 | #define BUS_SOFT_RST_REG3 0x2d0 | | 75 | #define BUS_SOFT_RST_REG3 0x2d0 |
74 | #define BUS_SOFT_RST_REG4 0x2d8 | | 76 | #define BUS_SOFT_RST_REG4 0x2d8 |
75 | | | 77 | |
76 | static int sun50i_a64_ccu_match(device_t, cfdata_t, void *); | | 78 | static int sun50i_a64_ccu_match(device_t, cfdata_t, void *); |
77 | static void sun50i_a64_ccu_attach(device_t, device_t, void *); | | 79 | static void sun50i_a64_ccu_attach(device_t, device_t, void *); |
78 | | | 80 | |
79 | static const char * const compatible[] = { | | 81 | static const char * const compatible[] = { |
80 | "allwinner,sun50i-a64-ccu", | | 82 | "allwinner,sun50i-a64-ccu", |
81 | NULL | | 83 | NULL |
82 | }; | | 84 | }; |
| @@ -143,26 +145,27 @@ static struct sunxi_ccu_reset sun50i_a64 | | | @@ -143,26 +145,27 @@ static struct sunxi_ccu_reset sun50i_a64 |
143 | SUNXI_CCU_RESET(A64_RST_BUS_UART2, BUS_SOFT_RST_REG4, 18), | | 145 | SUNXI_CCU_RESET(A64_RST_BUS_UART2, BUS_SOFT_RST_REG4, 18), |
144 | SUNXI_CCU_RESET(A64_RST_BUS_UART3, BUS_SOFT_RST_REG4, 19), | | 146 | SUNXI_CCU_RESET(A64_RST_BUS_UART3, BUS_SOFT_RST_REG4, 19), |
145 | }; | | 147 | }; |
146 | | | 148 | |
147 | static const char *ahb1_parents[] = { "losc", "hosc", "axi", "pll_periph0" }; | | 149 | static const char *ahb1_parents[] = { "losc", "hosc", "axi", "pll_periph0" }; |
148 | static const char *ahb2_parents[] = { "ahb1", "pll_periph0" }; | | 150 | static const char *ahb2_parents[] = { "ahb1", "pll_periph0" }; |
149 | static const char *apb1_parents[] = { "ahb1" }; | | 151 | static const char *apb1_parents[] = { "ahb1" }; |
150 | static const char *apb2_parents[] = { "losc", "hosc", "pll_periph0" }; | | 152 | static const char *apb2_parents[] = { "losc", "hosc", "pll_periph0" }; |
151 | static const char *mmc_parents[] = { "hosc", "pll_periph0_2x", "pll_periph1_2x" }; | | 153 | static const char *mmc_parents[] = { "hosc", "pll_periph0_2x", "pll_periph1_2x" }; |
152 | static const char *ths_parents[] = { "hosc", NULL, NULL, NULL }; | | 154 | static const char *ths_parents[] = { "hosc", NULL, NULL, NULL }; |
153 | static const char *de_parents[] = { "pll_periph0_2x", "pll_de" }; | | 155 | static const char *de_parents[] = { "pll_periph0_2x", "pll_de" }; |
154 | static const char *hdmi_parents[] = { "pll_video0", "pll_video1" }; | | 156 | static const char *hdmi_parents[] = { "pll_video0", "pll_video1" }; |
155 | static const char *tcon1_parents[] = { "pll_video0", NULL, "pll_video1", NULL }; | | 157 | static const char *tcon1_parents[] = { "pll_video0", NULL, "pll_video1", NULL }; |
| | | 158 | static const char *gpu_parents[] = { "gpu" }; |
156 | | | 159 | |
157 | static const struct sunxi_ccu_nkmp_tbl sun50i_a64_cpux_table[] = { | | 160 | static const struct sunxi_ccu_nkmp_tbl sun50i_a64_cpux_table[] = { |
158 | { 60000000, 9, 0, 0, 2 }, | | 161 | { 60000000, 9, 0, 0, 2 }, |
159 | { 66000000, 10, 0, 0, 2 }, | | 162 | { 66000000, 10, 0, 0, 2 }, |
160 | { 72000000, 11, 0, 0, 2 }, | | 163 | { 72000000, 11, 0, 0, 2 }, |
161 | { 78000000, 12, 0, 0, 2 }, | | 164 | { 78000000, 12, 0, 0, 2 }, |
162 | { 84000000, 13, 0, 0, 2 }, | | 165 | { 84000000, 13, 0, 0, 2 }, |
163 | { 90000000, 14, 0, 0, 2 }, | | 166 | { 90000000, 14, 0, 0, 2 }, |
164 | { 96000000, 15, 0, 0, 2 }, | | 167 | { 96000000, 15, 0, 0, 2 }, |
165 | { 102000000, 16, 0, 0, 2 }, | | 168 | { 102000000, 16, 0, 0, 2 }, |
166 | { 108000000, 17, 0, 0, 2 }, | | 169 | { 108000000, 17, 0, 0, 2 }, |
167 | { 114000000, 18, 0, 0, 2 }, | | 170 | { 114000000, 18, 0, 0, 2 }, |
168 | { 120000000, 9, 0, 0, 1 }, | | 171 | { 120000000, 9, 0, 0, 1 }, |
| @@ -300,26 +303,39 @@ static struct sunxi_ccu_clk sun50i_a64_c | | | @@ -300,26 +303,39 @@ static struct sunxi_ccu_clk sun50i_a64_c |
300 | SUNXI_CCU_FRACTIONAL(A64_CLK_PLL_DE, "pll_de", "hosc", | | 303 | SUNXI_CCU_FRACTIONAL(A64_CLK_PLL_DE, "pll_de", "hosc", |
301 | PLL_DE_CTRL_REG, /* reg */ | | 304 | PLL_DE_CTRL_REG, /* reg */ |
302 | __BITS(14,8), /* m */ | | 305 | __BITS(14,8), /* m */ |
303 | 16, /* m_min */ | | 306 | 16, /* m_min */ |
304 | 50, /* m_max */ | | 307 | 50, /* m_max */ |
305 | __BIT(24), /* div_en */ | | 308 | __BIT(24), /* div_en */ |
306 | __BIT(25), /* frac_sel */ | | 309 | __BIT(25), /* frac_sel */ |
307 | 270000000, 297000000, /* frac values */ | | 310 | 270000000, 297000000, /* frac values */ |
308 | __BITS(3,0), /* prediv */ | | 311 | __BITS(3,0), /* prediv */ |
309 | 2, /* prediv_val */ | | 312 | 2, /* prediv_val */ |
310 | __BIT(31), /* enable */ | | 313 | __BIT(31), /* enable */ |
311 | SUNXI_CCU_FRACTIONAL_PLUSONE | SUNXI_CCU_FRACTIONAL_SET_ENABLE), | | 314 | SUNXI_CCU_FRACTIONAL_PLUSONE | SUNXI_CCU_FRACTIONAL_SET_ENABLE), |
312 | | | 315 | |
| | | 316 | SUNXI_CCU_FRACTIONAL(A64_CLK_PLL_GPU, "pll_gpu", "hosc", |
| | | 317 | PLL_GPU_CTRL_REG, /* reg */ |
| | | 318 | __BITS(14,8), /* m */ |
| | | 319 | 1, /* m_min */ |
| | | 320 | 128, /* m_max */ |
| | | 321 | __BIT(24), /* div_en */ |
| | | 322 | __BIT(25), /* frac_sel */ |
| | | 323 | 270000000, 297000000, /* frac values */ |
| | | 324 | __BITS(3,0), /* prediv */ |
| | | 325 | 4, /* prediv_val */ |
| | | 326 | __BIT(31), /* enable */ |
| | | 327 | SUNXI_CCU_FRACTIONAL_PLUSONE | SUNXI_CCU_FRACTIONAL_SET_ENABLE), |
| | | 328 | |
313 | SUNXI_CCU_PREDIV(A64_CLK_AHB1, "ahb1", ahb1_parents, | | 329 | SUNXI_CCU_PREDIV(A64_CLK_AHB1, "ahb1", ahb1_parents, |
314 | AHB1_APB1_CFG_REG, /* reg */ | | 330 | AHB1_APB1_CFG_REG, /* reg */ |
315 | __BITS(7,6), /* prediv */ | | 331 | __BITS(7,6), /* prediv */ |
316 | __BIT(3), /* prediv_sel */ | | 332 | __BIT(3), /* prediv_sel */ |
317 | __BITS(5,4), /* div */ | | 333 | __BITS(5,4), /* div */ |
318 | __BITS(13,12), /* sel */ | | 334 | __BITS(13,12), /* sel */ |
319 | SUNXI_CCU_PREDIV_POWER_OF_TWO), | | 335 | SUNXI_CCU_PREDIV_POWER_OF_TWO), |
320 | | | 336 | |
321 | SUNXI_CCU_PREDIV(A64_CLK_AHB2, "ahb2", ahb2_parents, | | 337 | SUNXI_CCU_PREDIV(A64_CLK_AHB2, "ahb2", ahb2_parents, |
322 | AHB2_CFG_REG, /* reg */ | | 338 | AHB2_CFG_REG, /* reg */ |
323 | 0, /* prediv */ | | 339 | 0, /* prediv */ |
324 | __BIT(1), /* prediv_sel */ | | 340 | __BIT(1), /* prediv_sel */ |
325 | 0, /* div */ | | 341 | 0, /* div */ |
| @@ -388,26 +404,33 @@ static struct sunxi_ccu_clk sun50i_a64_c | | | @@ -388,26 +404,33 @@ static struct sunxi_ccu_clk sun50i_a64_c |
388 | __BIT(31), /* enable */ | | 404 | __BIT(31), /* enable */ |
389 | 0), | | 405 | 0), |
390 | | | 406 | |
391 | SUNXI_CCU_GATE(A64_CLK_HDMI_DDC, "hdmi-ddc", "hosc", | | 407 | SUNXI_CCU_GATE(A64_CLK_HDMI_DDC, "hdmi-ddc", "hosc", |
392 | HDMI_SLOW_CLK_REG, 31), | | 408 | HDMI_SLOW_CLK_REG, 31), |
393 | | | 409 | |
394 | SUNXI_CCU_DIV_GATE(A64_CLK_TCON1, "tcon1", tcon1_parents, | | 410 | SUNXI_CCU_DIV_GATE(A64_CLK_TCON1, "tcon1", tcon1_parents, |
395 | TCON1_CLK_REG, /* reg */ | | 411 | TCON1_CLK_REG, /* reg */ |
396 | __BITS(3,0), /* div */ | | 412 | __BITS(3,0), /* div */ |
397 | __BITS(25,24), /* sel */ | | 413 | __BITS(25,24), /* sel */ |
398 | __BIT(31), /* enable */ | | 414 | __BIT(31), /* enable */ |
399 | 0), | | 415 | 0), |
400 | | | 416 | |
| | | 417 | SUNXI_CCU_DIV_GATE(A64_CLK_GPU, "gpu", gpu_parents, |
| | | 418 | GPU_CLK_REG, /* reg */ |
| | | 419 | __BITS(2,0), /* div */ |
| | | 420 | 0, /* sel */ |
| | | 421 | __BIT(31), /* enable */ |
| | | 422 | 0), |
| | | 423 | |
401 | SUNXI_CCU_GATE(A64_CLK_BUS_MIPI_DSI, "bus-mipi-dsi", "ahb1", | | 424 | SUNXI_CCU_GATE(A64_CLK_BUS_MIPI_DSI, "bus-mipi-dsi", "ahb1", |
402 | BUS_CLK_GATING_REG0, 1), | | 425 | BUS_CLK_GATING_REG0, 1), |
403 | SUNXI_CCU_GATE(A64_CLK_BUS_CE, "bus-ce", "ahb1", | | 426 | SUNXI_CCU_GATE(A64_CLK_BUS_CE, "bus-ce", "ahb1", |
404 | BUS_CLK_GATING_REG0, 5), | | 427 | BUS_CLK_GATING_REG0, 5), |
405 | SUNXI_CCU_GATE(A64_CLK_BUS_DMA, "bus-dma", "ahb1", | | 428 | SUNXI_CCU_GATE(A64_CLK_BUS_DMA, "bus-dma", "ahb1", |
406 | BUS_CLK_GATING_REG0, 6), | | 429 | BUS_CLK_GATING_REG0, 6), |
407 | SUNXI_CCU_GATE(A64_CLK_BUS_MMC0, "bus-mmc0", "ahb1", | | 430 | SUNXI_CCU_GATE(A64_CLK_BUS_MMC0, "bus-mmc0", "ahb1", |
408 | BUS_CLK_GATING_REG0, 8), | | 431 | BUS_CLK_GATING_REG0, 8), |
409 | SUNXI_CCU_GATE(A64_CLK_BUS_MMC1, "bus-mmc1", "ahb1", | | 432 | SUNXI_CCU_GATE(A64_CLK_BUS_MMC1, "bus-mmc1", "ahb1", |
410 | BUS_CLK_GATING_REG0, 9), | | 433 | BUS_CLK_GATING_REG0, 9), |
411 | SUNXI_CCU_GATE(A64_CLK_BUS_MMC2, "bus-mmc2", "ahb1", | | 434 | SUNXI_CCU_GATE(A64_CLK_BUS_MMC2, "bus-mmc2", "ahb1", |
412 | BUS_CLK_GATING_REG0, 10), | | 435 | BUS_CLK_GATING_REG0, 10), |
413 | SUNXI_CCU_GATE(A64_CLK_BUS_NAND, "bus-nand", "ahb1", | | 436 | SUNXI_CCU_GATE(A64_CLK_BUS_NAND, "bus-nand", "ahb1", |