| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: sun50i_a64_ccu.c,v 1.13.2.1 2019/11/18 19:31:00 martin Exp $ */ | | 1 | /* $NetBSD: sun50i_a64_ccu.c,v 1.13.2.2 2019/11/18 19:36:03 martin 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.13.2.1 2019/11/18 19:31:00 martin Exp $"); | | 31 | __KERNEL_RCSID(1, "$NetBSD: sun50i_a64_ccu.c,v 1.13.2.2 2019/11/18 19:36:03 martin 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 |
| @@ -50,26 +50,28 @@ __KERNEL_RCSID(1, "$NetBSD: sun50i_a64_c | | | @@ -50,26 +50,28 @@ __KERNEL_RCSID(1, "$NetBSD: sun50i_a64_c |
50 | #define PLL_DE_CTRL_REG 0x048 | | 50 | #define PLL_DE_CTRL_REG 0x048 |
51 | #define AHB1_APB1_CFG_REG 0x054 | | 51 | #define AHB1_APB1_CFG_REG 0x054 |
52 | #define APB2_CFG_REG 0x058 | | 52 | #define APB2_CFG_REG 0x058 |
53 | #define AHB2_CFG_REG 0x05c | | 53 | #define AHB2_CFG_REG 0x05c |
54 | #define BUS_CLK_GATING_REG0 0x060 | | 54 | #define BUS_CLK_GATING_REG0 0x060 |
55 | #define BUS_CLK_GATING_REG1 0x064 | | 55 | #define BUS_CLK_GATING_REG1 0x064 |
56 | #define BUS_CLK_GATING_REG2 0x068 | | 56 | #define BUS_CLK_GATING_REG2 0x068 |
57 | #define BUS_CLK_GATING_REG3 0x06c | | 57 | #define BUS_CLK_GATING_REG3 0x06c |
58 | #define BUS_CLK_GATING_REG4 0x070 | | 58 | #define BUS_CLK_GATING_REG4 0x070 |
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 |
| | | 64 | #define SPI1_CLK_REG 0x0a4 |
63 | #define I2SPCM0_CLK_REG 0x0b0 | | 65 | #define I2SPCM0_CLK_REG 0x0b0 |
64 | #define I2SPCM1_CLK_REG 0x0b4 | | 66 | #define I2SPCM1_CLK_REG 0x0b4 |
65 | #define I2SPCM2_CLK_REG 0x0b8 | | 67 | #define I2SPCM2_CLK_REG 0x0b8 |
66 | #define USBPHY_CFG_REG 0x0cc | | 68 | #define USBPHY_CFG_REG 0x0cc |
67 | #define DRAM_CFG_REG 0x0f4 | | 69 | #define DRAM_CFG_REG 0x0f4 |
68 | #define MBUS_RST_REG 0x0fc | | 70 | #define MBUS_RST_REG 0x0fc |
69 | #define DE_CLK_REG 0x104 | | 71 | #define DE_CLK_REG 0x104 |
70 | #define TCON1_CLK_REG 0x11c | | 72 | #define TCON1_CLK_REG 0x11c |
71 | #define AC_DIG_CLK_REG 0x140 | | 73 | #define AC_DIG_CLK_REG 0x140 |
72 | #define HDMI_CLK_REG 0x150 | | 74 | #define HDMI_CLK_REG 0x150 |
73 | #define HDMI_SLOW_CLK_REG 0x154 | | 75 | #define HDMI_SLOW_CLK_REG 0x154 |
74 | #define GPU_CLK_REG 0x1a0 | | 76 | #define GPU_CLK_REG 0x1a0 |
75 | #define BUS_SOFT_RST_REG0 0x2c0 | | 77 | #define BUS_SOFT_RST_REG0 0x2c0 |
| @@ -148,26 +150,27 @@ static struct sunxi_ccu_reset sun50i_a64 | | | @@ -148,26 +150,27 @@ static struct sunxi_ccu_reset sun50i_a64 |
148 | SUNXI_CCU_RESET(A64_RST_BUS_UART2, BUS_SOFT_RST_REG4, 18), | | 150 | SUNXI_CCU_RESET(A64_RST_BUS_UART2, BUS_SOFT_RST_REG4, 18), |
149 | SUNXI_CCU_RESET(A64_RST_BUS_UART3, BUS_SOFT_RST_REG4, 19), | | 151 | SUNXI_CCU_RESET(A64_RST_BUS_UART3, BUS_SOFT_RST_REG4, 19), |
150 | }; | | 152 | }; |
151 | | | 153 | |
152 | static const char *ahb1_parents[] = { "losc", "hosc", "axi", "pll_periph0" }; | | 154 | static const char *ahb1_parents[] = { "losc", "hosc", "axi", "pll_periph0" }; |
153 | static const char *ahb2_parents[] = { "ahb1", "pll_periph0" }; | | 155 | static const char *ahb2_parents[] = { "ahb1", "pll_periph0" }; |
154 | static const char *apb1_parents[] = { "ahb1" }; | | 156 | static const char *apb1_parents[] = { "ahb1" }; |
155 | static const char *apb2_parents[] = { "losc", "hosc", "pll_periph0" }; | | 157 | static const char *apb2_parents[] = { "losc", "hosc", "pll_periph0" }; |
156 | static const char *mmc_parents[] = { "hosc", "pll_periph0_2x", "pll_periph1_2x" }; | | 158 | static const char *mmc_parents[] = { "hosc", "pll_periph0_2x", "pll_periph1_2x" }; |
157 | static const char *ths_parents[] = { "hosc", NULL, NULL, NULL }; | | 159 | static const char *ths_parents[] = { "hosc", NULL, NULL, NULL }; |
158 | static const char *de_parents[] = { "pll_periph0_2x", "pll_de" }; | | 160 | static const char *de_parents[] = { "pll_periph0_2x", "pll_de" }; |
159 | static const char *hdmi_parents[] = { "pll_video0", "pll_video1" }; | | 161 | static const char *hdmi_parents[] = { "pll_video0", "pll_video1" }; |
160 | static const char *i2s_parents[] = { "pll_audio_8x", "pll_audio_4x", "pll_audio_2x", "pll_audio" }; | | 162 | 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 }; |
161 | static const char *tcon1_parents[] = { "pll_video0", NULL, "pll_video1", NULL }; | | 164 | static const char *tcon1_parents[] = { "pll_video0", NULL, "pll_video1", NULL }; |
162 | static const char *gpu_parents[] = { "pll_gpu" }; | | 165 | static const char *gpu_parents[] = { "pll_gpu" }; |
163 | | | 166 | |
164 | static const struct sunxi_ccu_nkmp_tbl sun50i_a64_cpux_table[] = { | | 167 | static const struct sunxi_ccu_nkmp_tbl sun50i_a64_cpux_table[] = { |
165 | { 60000000, 9, 0, 0, 2 }, | | 168 | { 60000000, 9, 0, 0, 2 }, |
166 | { 66000000, 10, 0, 0, 2 }, | | 169 | { 66000000, 10, 0, 0, 2 }, |
167 | { 72000000, 11, 0, 0, 2 }, | | 170 | { 72000000, 11, 0, 0, 2 }, |
168 | { 78000000, 12, 0, 0, 2 }, | | 171 | { 78000000, 12, 0, 0, 2 }, |
169 | { 84000000, 13, 0, 0, 2 }, | | 172 | { 84000000, 13, 0, 0, 2 }, |
170 | { 90000000, 14, 0, 0, 2 }, | | 173 | { 90000000, 14, 0, 0, 2 }, |
171 | { 96000000, 15, 0, 0, 2 }, | | 174 | { 96000000, 15, 0, 0, 2 }, |
172 | { 102000000, 16, 0, 0, 2 }, | | 175 | { 102000000, 16, 0, 0, 2 }, |
173 | { 108000000, 17, 0, 0, 2 }, | | 176 | { 108000000, 17, 0, 0, 2 }, |
| @@ -250,26 +253,36 @@ static struct sunxi_ccu_clk sun50i_a64_c | | | @@ -250,26 +253,36 @@ static struct sunxi_ccu_clk sun50i_a64_c |
250 | sun50i_a64_cpux_table, /* table */ | | 253 | sun50i_a64_cpux_table, /* table */ |
251 | SUNXI_CCU_NKMP_SCALE_CLOCK | SUNXI_CCU_NKMP_FACTOR_P_POW2), | | 254 | SUNXI_CCU_NKMP_SCALE_CLOCK | SUNXI_CCU_NKMP_FACTOR_P_POW2), |
252 | | | 255 | |
253 | SUNXI_CCU_NKMP(A64_CLK_PLL_PERIPH0, "pll_periph0", "hosc", | | 256 | SUNXI_CCU_NKMP(A64_CLK_PLL_PERIPH0, "pll_periph0", "hosc", |
254 | PLL_PERIPH0_CTRL_REG, /* reg */ | | 257 | PLL_PERIPH0_CTRL_REG, /* reg */ |
255 | __BITS(12,8), /* n */ | | 258 | __BITS(12,8), /* n */ |
256 | __BITS(5,4), /* k */ | | 259 | __BITS(5,4), /* k */ |
257 | 0, /* m */ | | 260 | 0, /* m */ |
258 | __BITS(17,16), /* p */ | | 261 | __BITS(17,16), /* p */ |
259 | __BIT(31), /* enable */ | | 262 | __BIT(31), /* enable */ |
260 | SUNXI_CCU_NKMP_DIVIDE_BY_TWO), | | 263 | SUNXI_CCU_NKMP_DIVIDE_BY_TWO), |
261 | SUNXI_CCU_FIXED_FACTOR(A64_CLK_PLL_PERIPH0_2X, "pll_periph0_2x", "pll_periph0", 1, 2), | | 264 | SUNXI_CCU_FIXED_FACTOR(A64_CLK_PLL_PERIPH0_2X, "pll_periph0_2x", "pll_periph0", 1, 2), |
262 | | | 265 | |
| | | 266 | SUNXI_CCU_NKMP(A64_CLK_PLL_PERIPH1, "pll_periph1", "hosc", |
| | | 267 | PLL_PERIPH1_CTRL_REG, /* reg */ |
| | | 268 | __BITS(12,8), /* n */ |
| | | 269 | __BITS(5,4), /* k */ |
| | | 270 | 0, /* m */ |
| | | 271 | __BITS(17,16), /* p */ |
| | | 272 | __BIT(31), /* enable */ |
| | | 273 | SUNXI_CCU_NKMP_DIVIDE_BY_TWO), |
| | | 274 | SUNXI_CCU_FIXED_FACTOR(A64_CLK_PLL_PERIPH1_2X, "pll_periph1_2x", "pll_periph1", 1, 2), |
| | | 275 | |
263 | SUNXI_CCU_NKMP_TABLE(A64_CLK_PLL_AUDIO_BASE, "pll_audio_base", "hosc", | | 276 | SUNXI_CCU_NKMP_TABLE(A64_CLK_PLL_AUDIO_BASE, "pll_audio_base", "hosc", |
264 | PLL_AUDIO_CTRL_REG, /* reg */ | | 277 | PLL_AUDIO_CTRL_REG, /* reg */ |
265 | __BITS(14,8), /* n */ | | 278 | __BITS(14,8), /* n */ |
266 | 0, /* k */ | | 279 | 0, /* k */ |
267 | __BITS(4,0), /* m */ | | 280 | __BITS(4,0), /* m */ |
268 | __BITS(19,16), /* p */ | | 281 | __BITS(19,16), /* p */ |
269 | __BIT(31), /* enable */ | | 282 | __BIT(31), /* enable */ |
270 | __BIT(28), /* lock */ | | 283 | __BIT(28), /* lock */ |
271 | sun50i_a64_ac_dig_table, /* table */ | | 284 | sun50i_a64_ac_dig_table, /* table */ |
272 | 0), | | 285 | 0), |
273 | | | 286 | |
274 | SUNXI_CCU_FIXED_FACTOR(A64_CLK_PLL_AUDIO, "pll_audio", "pll_audio_base", 1, 1), | | 287 | SUNXI_CCU_FIXED_FACTOR(A64_CLK_PLL_AUDIO, "pll_audio", "pll_audio_base", 1, 1), |
275 | SUNXI_CCU_FIXED_FACTOR(A64_CLK_PLL_AUDIO_2X, "pll_audio_2x", "pll_audio_base", 1, 2), | | 288 | SUNXI_CCU_FIXED_FACTOR(A64_CLK_PLL_AUDIO_2X, "pll_audio_2x", "pll_audio_base", 1, 2), |
| @@ -420,26 +433,41 @@ static struct sunxi_ccu_clk sun50i_a64_c | | | @@ -420,26 +433,41 @@ static struct sunxi_ccu_clk sun50i_a64_c |
420 | SUNXI_CCU_DIV_GATE(A64_CLK_I2S1, "i2s1", i2s_parents, | | 433 | SUNXI_CCU_DIV_GATE(A64_CLK_I2S1, "i2s1", i2s_parents, |
421 | I2SPCM1_CLK_REG, /* reg */ | | 434 | I2SPCM1_CLK_REG, /* reg */ |
422 | 0, /* div */ | | 435 | 0, /* div */ |
423 | __BITS(17,16), /* sel */ | | 436 | __BITS(17,16), /* sel */ |
424 | __BIT(31), /* enable */ | | 437 | __BIT(31), /* enable */ |
425 | 0), | | 438 | 0), |
426 | SUNXI_CCU_DIV_GATE(A64_CLK_I2S2, "i2s2", i2s_parents, | | 439 | SUNXI_CCU_DIV_GATE(A64_CLK_I2S2, "i2s2", i2s_parents, |
427 | I2SPCM2_CLK_REG, /* reg */ | | 440 | I2SPCM2_CLK_REG, /* reg */ |
428 | 0, /* div */ | | 441 | 0, /* div */ |
429 | __BITS(17,16), /* sel */ | | 442 | __BITS(17,16), /* sel */ |
430 | __BIT(31), /* enable */ | | 443 | __BIT(31), /* enable */ |
431 | 0), | | 444 | 0), |
432 | | | 445 | |
| | | 446 | SUNXI_CCU_NM(A64_CLK_SPI0, "spi0", spi_parents, |
| | | 447 | SPI0_CLK_REG, /* reg */ |
| | | 448 | __BITS(17,16), /* n */ |
| | | 449 | __BITS(3,0), /* m */ |
| | | 450 | __BITS(25,24), /* sel */ |
| | | 451 | __BIT(31), /* enable */ |
| | | 452 | SUNXI_CCU_NM_POWER_OF_TWO|SUNXI_CCU_NM_ROUND_DOWN), |
| | | 453 | |
| | | 454 | SUNXI_CCU_NM(A64_CLK_SPI1, "spi1", spi_parents, |
| | | 455 | SPI1_CLK_REG, /* reg */ |
| | | 456 | __BITS(17,16), /* n */ |
| | | 457 | __BITS(3,0), /* m */ |
| | | 458 | __BITS(25,24), /* sel */ |
| | | 459 | __BIT(31), /* enable */ |
| | | 460 | SUNXI_CCU_NM_POWER_OF_TWO|SUNXI_CCU_NM_ROUND_DOWN), |
433 | | | 461 | |
434 | SUNXI_CCU_DIV_GATE(A64_CLK_TCON1, "tcon1", tcon1_parents, | | 462 | SUNXI_CCU_DIV_GATE(A64_CLK_TCON1, "tcon1", tcon1_parents, |
435 | TCON1_CLK_REG, /* reg */ | | 463 | TCON1_CLK_REG, /* reg */ |
436 | __BITS(3,0), /* div */ | | 464 | __BITS(3,0), /* div */ |
437 | __BITS(25,24), /* sel */ | | 465 | __BITS(25,24), /* sel */ |
438 | __BIT(31), /* enable */ | | 466 | __BIT(31), /* enable */ |
439 | 0), | | 467 | 0), |
440 | | | 468 | |
441 | SUNXI_CCU_DIV_GATE(A64_CLK_GPU, "gpu", gpu_parents, | | 469 | SUNXI_CCU_DIV_GATE(A64_CLK_GPU, "gpu", gpu_parents, |
442 | GPU_CLK_REG, /* reg */ | | 470 | GPU_CLK_REG, /* reg */ |
443 | __BITS(2,0), /* div */ | | 471 | __BITS(2,0), /* div */ |
444 | 0, /* sel */ | | 472 | 0, /* sel */ |
445 | __BIT(31), /* enable */ | | 473 | __BIT(31), /* enable */ |