| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: sun50i_a64_ccu.c,v 1.16 2019/11/22 19:46:38 jmcneill Exp $ */ | | 1 | /* $NetBSD: sun50i_a64_ccu.c,v 1.17 2019/11/23 12:29:20 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,27 +18,27 @@ | | | @@ -18,27 +18,27 @@ |
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.16 2019/11/22 19:46:38 jmcneill Exp $"); | | 31 | __KERNEL_RCSID(1, "$NetBSD: sun50i_a64_ccu.c,v 1.17 2019/11/23 12:29:20 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 |
| @@ -59,26 +59,27 @@ __KERNEL_RCSID(1, "$NetBSD: sun50i_a64_c | | | @@ -59,26 +59,27 @@ __KERNEL_RCSID(1, "$NetBSD: sun50i_a64_c |
59 | #define THS_CLK_REG 0x074 | | 59 | #define THS_CLK_REG 0x074 |
60 | #define SDMMC0_CLK_REG 0x088 | | 60 | #define SDMMC0_CLK_REG 0x088 |
61 | #define SDMMC1_CLK_REG 0x08c | | 61 | #define SDMMC1_CLK_REG 0x08c |
62 | #define SDMMC2_CLK_REG 0x090 | | 62 | #define SDMMC2_CLK_REG 0x090 |
63 | #define SPI0_CLK_REG 0x0a0 | | 63 | #define SPI0_CLK_REG 0x0a0 |
64 | #define SPI1_CLK_REG 0x0a4 | | 64 | #define SPI1_CLK_REG 0x0a4 |
65 | #define I2SPCM0_CLK_REG 0x0b0 | | 65 | #define I2SPCM0_CLK_REG 0x0b0 |
66 | #define I2SPCM1_CLK_REG 0x0b4 | | 66 | #define I2SPCM1_CLK_REG 0x0b4 |
67 | #define I2SPCM2_CLK_REG 0x0b8 | | 67 | #define I2SPCM2_CLK_REG 0x0b8 |
68 | #define USBPHY_CFG_REG 0x0cc | | 68 | #define USBPHY_CFG_REG 0x0cc |
69 | #define DRAM_CFG_REG 0x0f4 | | 69 | #define DRAM_CFG_REG 0x0f4 |
70 | #define MBUS_RST_REG 0x0fc | | 70 | #define MBUS_RST_REG 0x0fc |
71 | #define DE_CLK_REG 0x104 | | 71 | #define DE_CLK_REG 0x104 |
| | | 72 | #define TCON0_CLK_REG 0x118 |
72 | #define TCON1_CLK_REG 0x11c | | 73 | #define TCON1_CLK_REG 0x11c |
73 | #define AC_DIG_CLK_REG 0x140 | | 74 | #define AC_DIG_CLK_REG 0x140 |
74 | #define HDMI_CLK_REG 0x150 | | 75 | #define HDMI_CLK_REG 0x150 |
75 | #define HDMI_SLOW_CLK_REG 0x154 | | 76 | #define HDMI_SLOW_CLK_REG 0x154 |
76 | #define GPU_CLK_REG 0x1a0 | | 77 | #define GPU_CLK_REG 0x1a0 |
77 | #define BUS_SOFT_RST_REG0 0x2c0 | | 78 | #define BUS_SOFT_RST_REG0 0x2c0 |
78 | #define BUS_SOFT_RST_REG1 0x2c4 | | 79 | #define BUS_SOFT_RST_REG1 0x2c4 |
79 | #define BUS_SOFT_RST_REG2 0x2c8 | | 80 | #define BUS_SOFT_RST_REG2 0x2c8 |
80 | #define BUS_SOFT_RST_REG3 0x2d0 | | 81 | #define BUS_SOFT_RST_REG3 0x2d0 |
81 | #define BUS_SOFT_RST_REG4 0x2d8 | | 82 | #define BUS_SOFT_RST_REG4 0x2d8 |
82 | | | 83 | |
83 | static int sun50i_a64_ccu_match(device_t, cfdata_t, void *); | | 84 | static int sun50i_a64_ccu_match(device_t, cfdata_t, void *); |
84 | static void sun50i_a64_ccu_attach(device_t, device_t, void *); | | 85 | static void sun50i_a64_ccu_attach(device_t, device_t, void *); |
| @@ -151,26 +152,27 @@ static struct sunxi_ccu_reset sun50i_a64 | | | @@ -151,26 +152,27 @@ static struct sunxi_ccu_reset sun50i_a64 |
151 | SUNXI_CCU_RESET(A64_RST_BUS_UART3, BUS_SOFT_RST_REG4, 19), | | 152 | SUNXI_CCU_RESET(A64_RST_BUS_UART3, BUS_SOFT_RST_REG4, 19), |
152 | }; | | 153 | }; |
153 | | | 154 | |
154 | static const char *ahb1_parents[] = { "losc", "hosc", "axi", "pll_periph0" }; | | 155 | static const char *ahb1_parents[] = { "losc", "hosc", "axi", "pll_periph0" }; |
155 | static const char *ahb2_parents[] = { "ahb1", "pll_periph0" }; | | 156 | static const char *ahb2_parents[] = { "ahb1", "pll_periph0" }; |
156 | static const char *apb1_parents[] = { "ahb1" }; | | 157 | static const char *apb1_parents[] = { "ahb1" }; |
157 | static const char *apb2_parents[] = { "losc", "hosc", "pll_periph0" }; | | 158 | static const char *apb2_parents[] = { "losc", "hosc", "pll_periph0" }; |
158 | static const char *mmc_parents[] = { "hosc", "pll_periph0_2x", "pll_periph1_2x" }; | | 159 | static const char *mmc_parents[] = { "hosc", "pll_periph0_2x", "pll_periph1_2x" }; |
159 | static const char *ths_parents[] = { "hosc", NULL, NULL, NULL }; | | 160 | static const char *ths_parents[] = { "hosc", NULL, NULL, NULL }; |
160 | static const char *de_parents[] = { "pll_periph0_2x", "pll_de" }; | | 161 | static const char *de_parents[] = { "pll_periph0_2x", "pll_de" }; |
161 | static const char *hdmi_parents[] = { "pll_video0", "pll_video1" }; | | 162 | static const char *hdmi_parents[] = { "pll_video0", "pll_video1" }; |
162 | static const char *i2s_parents[] = { "pll_audio_8x", "pll_audio_4x", "pll_audio_2x", "pll_audio" }; | | 163 | static const char *i2s_parents[] = { "pll_audio_8x", "pll_audio_4x", "pll_audio_2x", "pll_audio" }; |
163 | static const char *spi_parents[] = { "hosc", "pll_periph0", "pll_periph1", NULL }; | | 164 | static const char *spi_parents[] = { "hosc", "pll_periph0", "pll_periph1", NULL }; |
| | | 165 | static const char *tcon0_parents[] = { "pll_mipi", NULL, "pll_video0_2x", NULL }; |
164 | static const char *tcon1_parents[] = { "pll_video0", NULL, "pll_video1", NULL }; | | 166 | static const char *tcon1_parents[] = { "pll_video0", NULL, "pll_video1", NULL }; |
165 | static const char *gpu_parents[] = { "pll_gpu" }; | | 167 | static const char *gpu_parents[] = { "pll_gpu" }; |
166 | | | 168 | |
167 | static const struct sunxi_ccu_nkmp_tbl sun50i_a64_cpux_table[] = { | | 169 | static const struct sunxi_ccu_nkmp_tbl sun50i_a64_cpux_table[] = { |
168 | { 60000000, 9, 0, 0, 2 }, | | 170 | { 60000000, 9, 0, 0, 2 }, |
169 | { 66000000, 10, 0, 0, 2 }, | | 171 | { 66000000, 10, 0, 0, 2 }, |
170 | { 72000000, 11, 0, 0, 2 }, | | 172 | { 72000000, 11, 0, 0, 2 }, |
171 | { 78000000, 12, 0, 0, 2 }, | | 173 | { 78000000, 12, 0, 0, 2 }, |
172 | { 84000000, 13, 0, 0, 2 }, | | 174 | { 84000000, 13, 0, 0, 2 }, |
173 | { 90000000, 14, 0, 0, 2 }, | | 175 | { 90000000, 14, 0, 0, 2 }, |
174 | { 96000000, 15, 0, 0, 2 }, | | 176 | { 96000000, 15, 0, 0, 2 }, |
175 | { 102000000, 16, 0, 0, 2 }, | | 177 | { 102000000, 16, 0, 0, 2 }, |
176 | { 108000000, 17, 0, 0, 2 }, | | 178 | { 108000000, 17, 0, 0, 2 }, |
| @@ -449,26 +451,33 @@ static struct sunxi_ccu_clk sun50i_a64_c | | | @@ -449,26 +451,33 @@ static struct sunxi_ccu_clk sun50i_a64_c |
449 | __BITS(3,0), /* m */ | | 451 | __BITS(3,0), /* m */ |
450 | __BITS(25,24), /* sel */ | | 452 | __BITS(25,24), /* sel */ |
451 | __BIT(31), /* enable */ | | 453 | __BIT(31), /* enable */ |
452 | SUNXI_CCU_NM_POWER_OF_TWO|SUNXI_CCU_NM_ROUND_DOWN), | | 454 | SUNXI_CCU_NM_POWER_OF_TWO|SUNXI_CCU_NM_ROUND_DOWN), |
453 | | | 455 | |
454 | SUNXI_CCU_NM(A64_CLK_SPI1, "spi1", spi_parents, | | 456 | SUNXI_CCU_NM(A64_CLK_SPI1, "spi1", spi_parents, |
455 | SPI1_CLK_REG, /* reg */ | | 457 | SPI1_CLK_REG, /* reg */ |
456 | __BITS(17,16), /* n */ | | 458 | __BITS(17,16), /* n */ |
457 | __BITS(3,0), /* m */ | | 459 | __BITS(3,0), /* m */ |
458 | __BITS(25,24), /* sel */ | | 460 | __BITS(25,24), /* sel */ |
459 | __BIT(31), /* enable */ | | 461 | __BIT(31), /* enable */ |
460 | SUNXI_CCU_NM_POWER_OF_TWO|SUNXI_CCU_NM_ROUND_DOWN), | | 462 | SUNXI_CCU_NM_POWER_OF_TWO|SUNXI_CCU_NM_ROUND_DOWN), |
461 | | | 463 | |
| | | 464 | SUNXI_CCU_DIV_GATE(A64_CLK_TCON0, "tcon0", tcon0_parents, |
| | | 465 | TCON0_CLK_REG, /* reg */ |
| | | 466 | 0, /* div */ |
| | | 467 | __BITS(26,24), /* sel */ |
| | | 468 | __BIT(31), /* enable */ |
| | | 469 | 0), |
| | | 470 | |
462 | SUNXI_CCU_DIV_GATE(A64_CLK_TCON1, "tcon1", tcon1_parents, | | 471 | SUNXI_CCU_DIV_GATE(A64_CLK_TCON1, "tcon1", tcon1_parents, |
463 | TCON1_CLK_REG, /* reg */ | | 472 | TCON1_CLK_REG, /* reg */ |
464 | __BITS(3,0), /* div */ | | 473 | __BITS(3,0), /* div */ |
465 | __BITS(25,24), /* sel */ | | 474 | __BITS(25,24), /* sel */ |
466 | __BIT(31), /* enable */ | | 475 | __BIT(31), /* enable */ |
467 | 0), | | 476 | 0), |
468 | | | 477 | |
469 | SUNXI_CCU_DIV_GATE(A64_CLK_GPU, "gpu", gpu_parents, | | 478 | SUNXI_CCU_DIV_GATE(A64_CLK_GPU, "gpu", gpu_parents, |
470 | GPU_CLK_REG, /* reg */ | | 479 | GPU_CLK_REG, /* reg */ |
471 | __BITS(2,0), /* div */ | | 480 | __BITS(2,0), /* div */ |
472 | 0, /* sel */ | | 481 | 0, /* sel */ |
473 | __BIT(31), /* enable */ | | 482 | __BIT(31), /* enable */ |
474 | 0), | | 483 | 0), |