| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: sun4i_a10_ccu.c,v 1.10 2019/01/22 23:06:49 jmcneill Exp $ */ | | 1 | /* $NetBSD: sun4i_a10_ccu.c,v 1.10.4.1 2020/05/07 17:05:07 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: sun4i_a10_ccu.c,v 1.10 2019/01/22 23:06:49 jmcneill Exp $"); | | 31 | __KERNEL_RCSID(1, "$NetBSD: sun4i_a10_ccu.c,v 1.10.4.1 2020/05/07 17:05:07 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/sun4i_a10_ccu.h> | | 41 | #include <arm/sunxi/sun4i_a10_ccu.h> |
42 | #include <arm/sunxi/sun7i_a20_ccu.h> | | 42 | #include <arm/sunxi/sun7i_a20_ccu.h> |
43 | | | 43 | |
44 | #define PLL1_CFG_REG 0x000 | | 44 | #define PLL1_CFG_REG 0x000 |
| @@ -68,26 +68,28 @@ __KERNEL_RCSID(1, "$NetBSD: sun4i_a10_cc | | | @@ -68,26 +68,28 @@ __KERNEL_RCSID(1, "$NetBSD: sun4i_a10_cc |
68 | #define FE1_CFG_REG 0x110 | | 68 | #define FE1_CFG_REG 0x110 |
69 | #define MP_CFG_REG 0x114 | | 69 | #define MP_CFG_REG 0x114 |
70 | #define LCD0CH0_CFG_REG 0x118 | | 70 | #define LCD0CH0_CFG_REG 0x118 |
71 | #define LCD1CH0_CFG_REG 0x11c | | 71 | #define LCD1CH0_CFG_REG 0x11c |
72 | #define LCD0CH1_CFG_REG 0x12c | | 72 | #define LCD0CH1_CFG_REG 0x12c |
73 | #define LCD1CH1_CFG_REG 0x130 | | 73 | #define LCD1CH1_CFG_REG 0x130 |
74 | #define CSI_CFG_REG 0x134 | | 74 | #define CSI_CFG_REG 0x134 |
75 | #define VE_CFG_REG 0x13c | | 75 | #define VE_CFG_REG 0x13c |
76 | #define AUDIO_CODEC_SCLK_CFG_REG 0x140 | | 76 | #define AUDIO_CODEC_SCLK_CFG_REG 0x140 |
77 | #define LVDS_CFG_REG 0x14c | | 77 | #define LVDS_CFG_REG 0x14c |
78 | #define HDMI_CLOCK_CFG_REG 0x150 | | 78 | #define HDMI_CLOCK_CFG_REG 0x150 |
79 | #define MALI_CLOCK_CFG_REG 0x154 | | 79 | #define MALI_CLOCK_CFG_REG 0x154 |
80 | #define IEP_SCLK_CFG_REG 0x160 | | 80 | #define IEP_SCLK_CFG_REG 0x160 |
| | | 81 | #define CLK_OUTA_REG 0x1f0 |
| | | 82 | #define CLK_OUTB_REG 0x1f4 |
81 | | | 83 | |
82 | static int sun4i_a10_ccu_match(device_t, cfdata_t, void *); | | 84 | static int sun4i_a10_ccu_match(device_t, cfdata_t, void *); |
83 | static void sun4i_a10_ccu_attach(device_t, device_t, void *); | | 85 | static void sun4i_a10_ccu_attach(device_t, device_t, void *); |
84 | | | 86 | |
85 | enum sun4i_a10_ccu_type { | | 87 | enum sun4i_a10_ccu_type { |
86 | CCU_A10 = 1, | | 88 | CCU_A10 = 1, |
87 | CCU_A20, | | 89 | CCU_A20, |
88 | }; | | 90 | }; |
89 | | | 91 | |
90 | static const struct of_compat_data compat_data[] = { | | 92 | static const struct of_compat_data compat_data[] = { |
91 | { "allwinner,sun4i-a10-ccu", CCU_A10 }, | | 93 | { "allwinner,sun4i-a10-ccu", CCU_A10 }, |
92 | { "allwinner,sun7i-a20-ccu", CCU_A20 }, | | 94 | { "allwinner,sun7i-a20-ccu", CCU_A20 }, |
93 | { NULL } | | 95 | { NULL } |
| @@ -109,26 +111,27 @@ static struct sunxi_ccu_reset sun4i_a10_ | | | @@ -109,26 +111,27 @@ static struct sunxi_ccu_reset sun4i_a10_ |
109 | SUNXI_CCU_RESET(A10_RST_TCON1, LCD1CH0_CFG_REG, 30), | | 111 | SUNXI_CCU_RESET(A10_RST_TCON1, LCD1CH0_CFG_REG, 30), |
110 | SUNXI_CCU_RESET(A10_RST_LVDS, LVDS_CFG_REG, 0), | | 112 | SUNXI_CCU_RESET(A10_RST_LVDS, LVDS_CFG_REG, 0), |
111 | }; | | 113 | }; |
112 | | | 114 | |
113 | static const char *cpu_parents[] = { "losc", "osc24m", "pll_core", "pll_periph" }; | | 115 | static const char *cpu_parents[] = { "losc", "osc24m", "pll_core", "pll_periph" }; |
114 | static const char *axi_parents[] = { "cpu" }; | | 116 | static const char *axi_parents[] = { "cpu" }; |
115 | static const char *ahb_parents[] = { "axi", "pll_periph", "pll_periph_base" }; | | 117 | static const char *ahb_parents[] = { "axi", "pll_periph", "pll_periph_base" }; |
116 | static const char *apb0_parents[] = { "ahb" }; | | 118 | static const char *apb0_parents[] = { "ahb" }; |
117 | static const char *apb1_parents[] = { "osc24m", "pll_periph", "losc" }; | | 119 | static const char *apb1_parents[] = { "osc24m", "pll_periph", "losc" }; |
118 | static const char *mod_parents[] = { "osc24m", "pll_periph", "pll_ddr_other" }; | | 120 | static const char *mod_parents[] = { "osc24m", "pll_periph", "pll_ddr_other" }; |
119 | static const char *sata_parents[] = { "pll6_periph_sata", "external" }; | | 121 | static const char *sata_parents[] = { "pll6_periph_sata", "external" }; |
120 | static const char *de_parents[] = { "pll_video0", "pll_video1", "pll_ddr_other" }; | | 122 | static const char *de_parents[] = { "pll_video0", "pll_video1", "pll_ddr_other" }; |
121 | static const char *lcd_parents[] = { "pll_video0", "pll_video1", "pll_video0x2", "pll_video1x2" }; | | 123 | static const char *lcd_parents[] = { "pll_video0", "pll_video1", "pll_video0x2", "pll_video1x2" }; |
| | | 124 | static const char *out_parents[] = { "losc" /* really OSC24MHz/750 */, "losc", "osc24m" }; |
122 | | | 125 | |
123 | static const struct sunxi_ccu_nkmp_tbl sun4i_a10_pll1_table[] = { | | 126 | static const struct sunxi_ccu_nkmp_tbl sun4i_a10_pll1_table[] = { |
124 | { 1008000000, 21, 1, 0, 0 }, | | 127 | { 1008000000, 21, 1, 0, 0 }, |
125 | { 960000000, 20, 1, 0, 0 }, | | 128 | { 960000000, 20, 1, 0, 0 }, |
126 | { 912000000, 19, 1, 0, 0 }, | | 129 | { 912000000, 19, 1, 0, 0 }, |
127 | { 864000000, 18, 1, 0, 0 }, | | 130 | { 864000000, 18, 1, 0, 0 }, |
128 | { 720000000, 30, 0, 0, 0 }, | | 131 | { 720000000, 30, 0, 0, 0 }, |
129 | { 624000000, 26, 0, 0, 0 }, | | 132 | { 624000000, 26, 0, 0, 0 }, |
130 | { 528000000, 22, 0, 0, 0 }, | | 133 | { 528000000, 22, 0, 0, 0 }, |
131 | { 312000000, 13, 0, 0, 0 }, | | 134 | { 312000000, 13, 0, 0, 0 }, |
132 | { 144000000, 12, 0, 0, 1 }, | | 135 | { 144000000, 12, 0, 0, 1 }, |
133 | { 0 } | | 136 | { 0 } |
134 | }; | | 137 | }; |
| @@ -438,26 +441,43 @@ static struct sunxi_ccu_clk sun4i_a10_cc | | | @@ -438,26 +441,43 @@ static struct sunxi_ccu_clk sun4i_a10_cc |
438 | .get_rate = sunxi_ccu_div_get_rate, | | 441 | .get_rate = sunxi_ccu_div_get_rate, |
439 | .set_rate = sun4i_a10_ccu_lcd1ch1_set_rate, | | 442 | .set_rate = sun4i_a10_ccu_lcd1ch1_set_rate, |
440 | .set_parent = sunxi_ccu_div_set_parent, | | 443 | .set_parent = sunxi_ccu_div_set_parent, |
441 | .get_parent = sunxi_ccu_div_get_parent, | | 444 | .get_parent = sunxi_ccu_div_get_parent, |
442 | }, | | 445 | }, |
443 | SUNXI_CCU_DIV_GATE(A10_CLK_HDMI, "hdmi-mod", lcd_parents, | | 446 | SUNXI_CCU_DIV_GATE(A10_CLK_HDMI, "hdmi-mod", lcd_parents, |
444 | HDMI_CLOCK_CFG_REG, /* reg */ | | 447 | HDMI_CLOCK_CFG_REG, /* reg */ |
445 | __BITS(3,0), /* div */ | | 448 | __BITS(3,0), /* div */ |
446 | __BITS(25,24), /* sel */ | | 449 | __BITS(25,24), /* sel */ |
447 | __BIT(31), /* enable */ | | 450 | __BIT(31), /* enable */ |
448 | 0 /* flags */ | | 451 | 0 /* flags */ |
449 | ), | | 452 | ), |
450 | | | 453 | |
| | | 454 | /* A20 specific */ |
| | | 455 | SUNXI_CCU_NM(A20_CLK_OUT_A, "outa", out_parents, |
| | | 456 | CLK_OUTA_REG, /* reg */ |
| | | 457 | __BITS(21,20), /* n */ |
| | | 458 | __BITS(12,8), /* m */ |
| | | 459 | __BITS(25,24), /* sel */ |
| | | 460 | __BIT(31), /* enable */ |
| | | 461 | SUNXI_CCU_NM_POWER_OF_TWO), |
| | | 462 | |
| | | 463 | SUNXI_CCU_NM(A20_CLK_OUT_B, "outb", out_parents, |
| | | 464 | CLK_OUTB_REG, /* reg */ |
| | | 465 | __BITS(21,20), /* n */ |
| | | 466 | __BITS(12,8), /* m */ |
| | | 467 | __BITS(25,24), /* sel */ |
| | | 468 | __BIT(31), /* enable */ |
| | | 469 | SUNXI_CCU_NM_POWER_OF_TWO), |
| | | 470 | |
451 | /* AHB_GATING_REG0 */ | | 471 | /* AHB_GATING_REG0 */ |
452 | SUNXI_CCU_GATE(A10_CLK_AHB_OTG, "ahb-otg", "ahb", | | 472 | SUNXI_CCU_GATE(A10_CLK_AHB_OTG, "ahb-otg", "ahb", |
453 | AHB_GATING_REG0, 0), | | 473 | AHB_GATING_REG0, 0), |
454 | SUNXI_CCU_GATE(A10_CLK_AHB_EHCI0, "ahb-ehci0", "ahb", | | 474 | SUNXI_CCU_GATE(A10_CLK_AHB_EHCI0, "ahb-ehci0", "ahb", |
455 | AHB_GATING_REG0, 1), | | 475 | AHB_GATING_REG0, 1), |
456 | SUNXI_CCU_GATE(A10_CLK_AHB_OHCI0, "ahb-ohci0", "ahb", | | 476 | SUNXI_CCU_GATE(A10_CLK_AHB_OHCI0, "ahb-ohci0", "ahb", |
457 | AHB_GATING_REG0, 2), | | 477 | AHB_GATING_REG0, 2), |
458 | SUNXI_CCU_GATE(A10_CLK_AHB_EHCI1, "ahb-ehci1", "ahb", | | 478 | SUNXI_CCU_GATE(A10_CLK_AHB_EHCI1, "ahb-ehci1", "ahb", |
459 | AHB_GATING_REG0, 3), | | 479 | AHB_GATING_REG0, 3), |
460 | SUNXI_CCU_GATE(A10_CLK_AHB_OHCI1, "ahb-ohci1", "ahb", | | 480 | SUNXI_CCU_GATE(A10_CLK_AHB_OHCI1, "ahb-ohci1", "ahb", |
461 | AHB_GATING_REG0, 4), | | 481 | AHB_GATING_REG0, 4), |
462 | SUNXI_CCU_GATE(A10_CLK_AHB_SS, "ahb-ss", "ahb", | | 482 | SUNXI_CCU_GATE(A10_CLK_AHB_SS, "ahb-ss", "ahb", |
463 | AHB_GATING_REG0, 5), | | 483 | AHB_GATING_REG0, 5), |