Sam Protsenko | df5a2b9 | 2024-01-10 21:09:04 -0600 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Samsung Exynos850 clock driver. |
| 4 | * Copyright (c) 2023 Linaro Ltd. |
| 5 | * Author: Sam Protsenko <semen.protsenko@linaro.org> |
| 6 | */ |
| 7 | |
| 8 | #include <dm.h> |
| 9 | #include <asm/io.h> |
| 10 | #include <dt-bindings/clock/exynos850.h> |
| 11 | #include "clk.h" |
| 12 | |
| 13 | /* ---- CMU_TOP ------------------------------------------------------------- */ |
| 14 | |
| 15 | /* Register Offset definitions for CMU_TOP (0x120e0000) */ |
| 16 | #define PLL_CON0_PLL_MMC 0x0100 |
| 17 | #define PLL_CON3_PLL_MMC 0x010c |
| 18 | #define PLL_CON0_PLL_SHARED0 0x0140 |
| 19 | #define PLL_CON3_PLL_SHARED0 0x014c |
| 20 | #define PLL_CON0_PLL_SHARED1 0x0180 |
| 21 | #define PLL_CON3_PLL_SHARED1 0x018c |
| 22 | #define CLK_CON_MUX_MUX_CLKCMU_PERI_BUS 0x1070 |
| 23 | #define CLK_CON_MUX_MUX_CLKCMU_PERI_IP 0x1074 |
| 24 | #define CLK_CON_MUX_MUX_CLKCMU_PERI_UART 0x1078 |
| 25 | #define CLK_CON_DIV_CLKCMU_PERI_BUS 0x187c |
| 26 | #define CLK_CON_DIV_CLKCMU_PERI_IP 0x1880 |
| 27 | #define CLK_CON_DIV_CLKCMU_PERI_UART 0x1884 |
| 28 | #define CLK_CON_DIV_PLL_SHARED0_DIV2 0x188c |
| 29 | #define CLK_CON_DIV_PLL_SHARED0_DIV3 0x1890 |
| 30 | #define CLK_CON_DIV_PLL_SHARED0_DIV4 0x1894 |
| 31 | #define CLK_CON_DIV_PLL_SHARED1_DIV2 0x1898 |
| 32 | #define CLK_CON_DIV_PLL_SHARED1_DIV3 0x189c |
| 33 | #define CLK_CON_DIV_PLL_SHARED1_DIV4 0x18a0 |
| 34 | #define CLK_CON_GAT_GATE_CLKCMU_PERI_BUS 0x2080 |
| 35 | #define CLK_CON_GAT_GATE_CLKCMU_PERI_IP 0x2084 |
| 36 | #define CLK_CON_GAT_GATE_CLKCMU_PERI_UART 0x2088 |
| 37 | |
Sam Protsenko | ce65a50 | 2024-03-07 20:18:55 -0600 | [diff] [blame^] | 38 | /* List of parent clocks for Muxes in CMU_TOP: for PURECLKCOMP */ |
Sam Protsenko | df5a2b9 | 2024-01-10 21:09:04 -0600 | [diff] [blame] | 39 | PNAME(mout_shared0_pll_p) = { "clock-oscclk", "fout_shared0_pll" }; |
| 40 | PNAME(mout_shared1_pll_p) = { "clock-oscclk", "fout_shared1_pll" }; |
| 41 | PNAME(mout_mmc_pll_p) = { "clock-oscclk", "fout_mmc_pll" }; |
| 42 | /* List of parent clocks for Muxes in CMU_TOP: for CMU_PERI */ |
| 43 | PNAME(mout_peri_bus_p) = { "dout_shared0_div4", "dout_shared1_div4" }; |
| 44 | PNAME(mout_peri_uart_p) = { "clock-oscclk", "dout_shared0_div4", |
| 45 | "dout_shared1_div4", "clock-oscclk" }; |
| 46 | PNAME(mout_peri_ip_p) = { "clock-oscclk", "dout_shared0_div4", |
| 47 | "dout_shared1_div4", "clock-oscclk" }; |
| 48 | |
Sam Protsenko | ce65a50 | 2024-03-07 20:18:55 -0600 | [diff] [blame^] | 49 | /* PURECLKCOMP */ |
| 50 | |
| 51 | static const struct samsung_pll_clock top_pure_pll_clks[] = { |
| 52 | PLL(pll_0822x, CLK_FOUT_SHARED0_PLL, "fout_shared0_pll", "clock-oscclk", |
| 53 | PLL_CON3_PLL_SHARED0), |
| 54 | PLL(pll_0822x, CLK_FOUT_SHARED1_PLL, "fout_shared1_pll", "clock-oscclk", |
| 55 | PLL_CON3_PLL_SHARED1), |
| 56 | PLL(pll_0831x, CLK_FOUT_MMC_PLL, "fout_mmc_pll", "clock-oscclk", |
| 57 | PLL_CON3_PLL_MMC), |
| 58 | }; |
| 59 | |
Sam Protsenko | df5a2b9 | 2024-01-10 21:09:04 -0600 | [diff] [blame] | 60 | static const struct samsung_mux_clock top_pure_mux_clks[] = { |
| 61 | MUX(CLK_MOUT_SHARED0_PLL, "mout_shared0_pll", mout_shared0_pll_p, |
| 62 | PLL_CON0_PLL_SHARED0, 4, 1), |
| 63 | MUX(CLK_MOUT_SHARED1_PLL, "mout_shared1_pll", mout_shared1_pll_p, |
| 64 | PLL_CON0_PLL_SHARED1, 4, 1), |
| 65 | MUX(CLK_MOUT_MMC_PLL, "mout_mmc_pll", mout_mmc_pll_p, |
| 66 | PLL_CON0_PLL_MMC, 4, 1), |
| 67 | }; |
| 68 | |
Sam Protsenko | df5a2b9 | 2024-01-10 21:09:04 -0600 | [diff] [blame] | 69 | static const struct samsung_div_clock top_pure_div_clks[] = { |
| 70 | DIV(CLK_DOUT_SHARED0_DIV3, "dout_shared0_div3", "mout_shared0_pll", |
| 71 | CLK_CON_DIV_PLL_SHARED0_DIV3, 0, 2), |
| 72 | DIV(CLK_DOUT_SHARED0_DIV2, "dout_shared0_div2", "mout_shared0_pll", |
| 73 | CLK_CON_DIV_PLL_SHARED0_DIV2, 0, 1), |
| 74 | DIV(CLK_DOUT_SHARED1_DIV3, "dout_shared1_div3", "mout_shared1_pll", |
| 75 | CLK_CON_DIV_PLL_SHARED1_DIV3, 0, 2), |
| 76 | DIV(CLK_DOUT_SHARED1_DIV2, "dout_shared1_div2", "mout_shared1_pll", |
| 77 | CLK_CON_DIV_PLL_SHARED1_DIV2, 0, 1), |
| 78 | DIV(CLK_DOUT_SHARED0_DIV4, "dout_shared0_div4", "dout_shared0_div2", |
| 79 | CLK_CON_DIV_PLL_SHARED0_DIV4, 0, 1), |
| 80 | DIV(CLK_DOUT_SHARED1_DIV4, "dout_shared1_div4", "dout_shared1_div2", |
| 81 | CLK_CON_DIV_PLL_SHARED1_DIV4, 0, 1), |
| 82 | }; |
| 83 | |
Sam Protsenko | ce65a50 | 2024-03-07 20:18:55 -0600 | [diff] [blame^] | 84 | /* PERI */ |
| 85 | |
| 86 | static const struct samsung_mux_clock top_peri_mux_clks[] = { |
| 87 | MUX(CLK_MOUT_PERI_BUS, "mout_peri_bus", mout_peri_bus_p, |
| 88 | CLK_CON_MUX_MUX_CLKCMU_PERI_BUS, 0, 1), |
| 89 | MUX(CLK_MOUT_PERI_UART, "mout_peri_uart", mout_peri_uart_p, |
| 90 | CLK_CON_MUX_MUX_CLKCMU_PERI_UART, 0, 2), |
| 91 | MUX(CLK_MOUT_PERI_IP, "mout_peri_ip", mout_peri_ip_p, |
| 92 | CLK_CON_MUX_MUX_CLKCMU_PERI_IP, 0, 2), |
Sam Protsenko | df5a2b9 | 2024-01-10 21:09:04 -0600 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | static const struct samsung_gate_clock top_peri_gate_clks[] = { |
| 96 | GATE(CLK_GOUT_PERI_BUS, "gout_peri_bus", "mout_peri_bus", |
| 97 | CLK_CON_GAT_GATE_CLKCMU_PERI_BUS, 21, 0, 0), |
| 98 | GATE(CLK_GOUT_PERI_UART, "gout_peri_uart", "mout_peri_uart", |
| 99 | CLK_CON_GAT_GATE_CLKCMU_PERI_UART, 21, 0, 0), |
| 100 | GATE(CLK_GOUT_PERI_IP, "gout_peri_ip", "mout_peri_ip", |
| 101 | CLK_CON_GAT_GATE_CLKCMU_PERI_IP, 21, 0, 0), |
| 102 | }; |
| 103 | |
Sam Protsenko | ce65a50 | 2024-03-07 20:18:55 -0600 | [diff] [blame^] | 104 | static const struct samsung_div_clock top_peri_div_clks[] = { |
| 105 | DIV(CLK_DOUT_PERI_BUS, "dout_peri_bus", "gout_peri_bus", |
| 106 | CLK_CON_DIV_CLKCMU_PERI_BUS, 0, 4), |
| 107 | DIV(CLK_DOUT_PERI_UART, "dout_peri_uart", "gout_peri_uart", |
| 108 | CLK_CON_DIV_CLKCMU_PERI_UART, 0, 4), |
| 109 | DIV(CLK_DOUT_PERI_IP, "dout_peri_ip", "gout_peri_ip", |
| 110 | CLK_CON_DIV_CLKCMU_PERI_IP, 0, 4), |
| 111 | }; |
| 112 | |
Sam Protsenko | df5a2b9 | 2024-01-10 21:09:04 -0600 | [diff] [blame] | 113 | static const struct samsung_clk_group top_cmu_clks[] = { |
| 114 | /* CMU_TOP_PURECLKCOMP */ |
| 115 | { S_CLK_PLL, top_pure_pll_clks, ARRAY_SIZE(top_pure_pll_clks) }, |
| 116 | { S_CLK_MUX, top_pure_mux_clks, ARRAY_SIZE(top_pure_mux_clks) }, |
| 117 | { S_CLK_DIV, top_pure_div_clks, ARRAY_SIZE(top_pure_div_clks) }, |
| 118 | |
| 119 | /* CMU_TOP clocks for CMU_PERI */ |
| 120 | { S_CLK_MUX, top_peri_mux_clks, ARRAY_SIZE(top_peri_mux_clks) }, |
| 121 | { S_CLK_GATE, top_peri_gate_clks, ARRAY_SIZE(top_peri_gate_clks) }, |
| 122 | { S_CLK_DIV, top_peri_div_clks, ARRAY_SIZE(top_peri_div_clks) }, |
| 123 | }; |
| 124 | |
| 125 | static int exynos850_cmu_top_probe(struct udevice *dev) |
| 126 | { |
| 127 | return samsung_cmu_register_one(dev, top_cmu_clks, |
| 128 | ARRAY_SIZE(top_cmu_clks)); |
| 129 | } |
| 130 | |
| 131 | static const struct udevice_id exynos850_cmu_top_ids[] = { |
| 132 | { .compatible = "samsung,exynos850-cmu-top" }, |
| 133 | { } |
| 134 | }; |
| 135 | |
| 136 | U_BOOT_DRIVER(exynos850_cmu_top) = { |
| 137 | .name = "exynos850-cmu-top", |
| 138 | .id = UCLASS_CLK, |
| 139 | .of_match = exynos850_cmu_top_ids, |
| 140 | .ops = &ccf_clk_ops, |
| 141 | .probe = exynos850_cmu_top_probe, |
| 142 | .flags = DM_FLAG_PRE_RELOC, |
| 143 | }; |
| 144 | |
| 145 | /* ---- CMU_PERI ------------------------------------------------------------ */ |
| 146 | |
| 147 | /* Register Offset definitions for CMU_PERI (0x10030000) */ |
| 148 | #define PLL_CON0_MUX_CLKCMU_PERI_BUS_USER 0x0600 |
| 149 | #define PLL_CON0_MUX_CLKCMU_PERI_UART_USER 0x0630 |
| 150 | #define CLK_CON_GAT_GOUT_PERI_UART_IPCLK 0x20a8 |
| 151 | #define CLK_CON_GAT_GOUT_PERI_UART_PCLK 0x20ac |
| 152 | |
| 153 | /* List of parent clocks for Muxes in CMU_PERI */ |
| 154 | PNAME(mout_peri_bus_user_p) = { "clock-oscclk", "dout_peri_bus" }; |
| 155 | PNAME(mout_peri_uart_user_p) = { "clock-oscclk", "dout_peri_uart" }; |
| 156 | |
| 157 | static const struct samsung_mux_clock peri_mux_clks[] = { |
| 158 | MUX(CLK_MOUT_PERI_BUS_USER, "mout_peri_bus_user", mout_peri_bus_user_p, |
| 159 | PLL_CON0_MUX_CLKCMU_PERI_BUS_USER, 4, 1), |
| 160 | MUX(CLK_MOUT_PERI_UART_USER, "mout_peri_uart_user", |
| 161 | mout_peri_uart_user_p, PLL_CON0_MUX_CLKCMU_PERI_UART_USER, 4, 1), |
| 162 | }; |
| 163 | |
| 164 | static const struct samsung_gate_clock peri_gate_clks[] = { |
| 165 | GATE(CLK_GOUT_UART_IPCLK, "gout_uart_ipclk", "mout_peri_uart_user", |
| 166 | CLK_CON_GAT_GOUT_PERI_UART_IPCLK, 21, 0, 0), |
| 167 | GATE(CLK_GOUT_UART_PCLK, "gout_uart_pclk", "mout_peri_bus_user", |
| 168 | CLK_CON_GAT_GOUT_PERI_UART_PCLK, 21, 0, 0), |
| 169 | }; |
| 170 | |
| 171 | static const struct samsung_clk_group peri_cmu_clks[] = { |
| 172 | { S_CLK_MUX, peri_mux_clks, ARRAY_SIZE(peri_mux_clks) }, |
| 173 | { S_CLK_GATE, peri_gate_clks, ARRAY_SIZE(peri_gate_clks) }, |
| 174 | }; |
| 175 | |
| 176 | static int exynos850_cmu_peri_probe(struct udevice *dev) |
| 177 | { |
| 178 | return samsung_register_cmu(dev, peri_cmu_clks, exynos850_cmu_top); |
| 179 | } |
| 180 | |
| 181 | static const struct udevice_id exynos850_cmu_peri_ids[] = { |
| 182 | { .compatible = "samsung,exynos850-cmu-peri" }, |
| 183 | { } |
| 184 | }; |
| 185 | |
| 186 | U_BOOT_DRIVER(exynos850_cmu_peri) = { |
| 187 | .name = "exynos850-cmu-peri", |
| 188 | .id = UCLASS_CLK, |
| 189 | .of_match = exynos850_cmu_peri_ids, |
| 190 | .ops = &ccf_clk_ops, |
| 191 | .probe = exynos850_cmu_peri_probe, |
| 192 | .flags = DM_FLAG_PRE_RELOC, |
| 193 | }; |