blob: cf94a3e1b6467480dede3dc751ede58451440ed9 [file] [log] [blame]
Sam Protsenkodf5a2b92024-01-10 21:09:04 -06001// 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
38static const struct samsung_pll_clock top_pure_pll_clks[] = {
39 PLL(pll_0822x, CLK_FOUT_SHARED0_PLL, "fout_shared0_pll", "clock-oscclk",
40 PLL_CON3_PLL_SHARED0),
41 PLL(pll_0822x, CLK_FOUT_SHARED1_PLL, "fout_shared1_pll", "clock-oscclk",
42 PLL_CON3_PLL_SHARED1),
43 PLL(pll_0831x, CLK_FOUT_MMC_PLL, "fout_mmc_pll", "clock-oscclk",
44 PLL_CON3_PLL_MMC),
45};
46
47/* List of parent clocks for Muxes in CMU_TOP */
48PNAME(mout_shared0_pll_p) = { "clock-oscclk", "fout_shared0_pll" };
49PNAME(mout_shared1_pll_p) = { "clock-oscclk", "fout_shared1_pll" };
50PNAME(mout_mmc_pll_p) = { "clock-oscclk", "fout_mmc_pll" };
51/* List of parent clocks for Muxes in CMU_TOP: for CMU_PERI */
52PNAME(mout_peri_bus_p) = { "dout_shared0_div4", "dout_shared1_div4" };
53PNAME(mout_peri_uart_p) = { "clock-oscclk", "dout_shared0_div4",
54 "dout_shared1_div4", "clock-oscclk" };
55PNAME(mout_peri_ip_p) = { "clock-oscclk", "dout_shared0_div4",
56 "dout_shared1_div4", "clock-oscclk" };
57
58static const struct samsung_mux_clock top_pure_mux_clks[] = {
59 MUX(CLK_MOUT_SHARED0_PLL, "mout_shared0_pll", mout_shared0_pll_p,
60 PLL_CON0_PLL_SHARED0, 4, 1),
61 MUX(CLK_MOUT_SHARED1_PLL, "mout_shared1_pll", mout_shared1_pll_p,
62 PLL_CON0_PLL_SHARED1, 4, 1),
63 MUX(CLK_MOUT_MMC_PLL, "mout_mmc_pll", mout_mmc_pll_p,
64 PLL_CON0_PLL_MMC, 4, 1),
65};
66
67static const struct samsung_mux_clock top_peri_mux_clks[] = {
68 MUX(CLK_MOUT_PERI_BUS, "mout_peri_bus", mout_peri_bus_p,
69 CLK_CON_MUX_MUX_CLKCMU_PERI_BUS, 0, 1),
70 MUX(CLK_MOUT_PERI_UART, "mout_peri_uart", mout_peri_uart_p,
71 CLK_CON_MUX_MUX_CLKCMU_PERI_UART, 0, 2),
72 MUX(CLK_MOUT_PERI_IP, "mout_peri_ip", mout_peri_ip_p,
73 CLK_CON_MUX_MUX_CLKCMU_PERI_IP, 0, 2),
74};
75
76static const struct samsung_div_clock top_pure_div_clks[] = {
77 DIV(CLK_DOUT_SHARED0_DIV3, "dout_shared0_div3", "mout_shared0_pll",
78 CLK_CON_DIV_PLL_SHARED0_DIV3, 0, 2),
79 DIV(CLK_DOUT_SHARED0_DIV2, "dout_shared0_div2", "mout_shared0_pll",
80 CLK_CON_DIV_PLL_SHARED0_DIV2, 0, 1),
81 DIV(CLK_DOUT_SHARED1_DIV3, "dout_shared1_div3", "mout_shared1_pll",
82 CLK_CON_DIV_PLL_SHARED1_DIV3, 0, 2),
83 DIV(CLK_DOUT_SHARED1_DIV2, "dout_shared1_div2", "mout_shared1_pll",
84 CLK_CON_DIV_PLL_SHARED1_DIV2, 0, 1),
85 DIV(CLK_DOUT_SHARED0_DIV4, "dout_shared0_div4", "dout_shared0_div2",
86 CLK_CON_DIV_PLL_SHARED0_DIV4, 0, 1),
87 DIV(CLK_DOUT_SHARED1_DIV4, "dout_shared1_div4", "dout_shared1_div2",
88 CLK_CON_DIV_PLL_SHARED1_DIV4, 0, 1),
89};
90
91static const struct samsung_div_clock top_peri_div_clks[] = {
92 DIV(CLK_DOUT_PERI_BUS, "dout_peri_bus", "gout_peri_bus",
93 CLK_CON_DIV_CLKCMU_PERI_BUS, 0, 4),
94 DIV(CLK_DOUT_PERI_UART, "dout_peri_uart", "gout_peri_uart",
95 CLK_CON_DIV_CLKCMU_PERI_UART, 0, 4),
96 DIV(CLK_DOUT_PERI_IP, "dout_peri_ip", "gout_peri_ip",
97 CLK_CON_DIV_CLKCMU_PERI_IP, 0, 4),
98};
99
100static const struct samsung_gate_clock top_peri_gate_clks[] = {
101 GATE(CLK_GOUT_PERI_BUS, "gout_peri_bus", "mout_peri_bus",
102 CLK_CON_GAT_GATE_CLKCMU_PERI_BUS, 21, 0, 0),
103 GATE(CLK_GOUT_PERI_UART, "gout_peri_uart", "mout_peri_uart",
104 CLK_CON_GAT_GATE_CLKCMU_PERI_UART, 21, 0, 0),
105 GATE(CLK_GOUT_PERI_IP, "gout_peri_ip", "mout_peri_ip",
106 CLK_CON_GAT_GATE_CLKCMU_PERI_IP, 21, 0, 0),
107};
108
109static const struct samsung_clk_group top_cmu_clks[] = {
110 /* CMU_TOP_PURECLKCOMP */
111 { S_CLK_PLL, top_pure_pll_clks, ARRAY_SIZE(top_pure_pll_clks) },
112 { S_CLK_MUX, top_pure_mux_clks, ARRAY_SIZE(top_pure_mux_clks) },
113 { S_CLK_DIV, top_pure_div_clks, ARRAY_SIZE(top_pure_div_clks) },
114
115 /* CMU_TOP clocks for CMU_PERI */
116 { S_CLK_MUX, top_peri_mux_clks, ARRAY_SIZE(top_peri_mux_clks) },
117 { S_CLK_GATE, top_peri_gate_clks, ARRAY_SIZE(top_peri_gate_clks) },
118 { S_CLK_DIV, top_peri_div_clks, ARRAY_SIZE(top_peri_div_clks) },
119};
120
121static int exynos850_cmu_top_probe(struct udevice *dev)
122{
123 return samsung_cmu_register_one(dev, top_cmu_clks,
124 ARRAY_SIZE(top_cmu_clks));
125}
126
127static const struct udevice_id exynos850_cmu_top_ids[] = {
128 { .compatible = "samsung,exynos850-cmu-top" },
129 { }
130};
131
132U_BOOT_DRIVER(exynos850_cmu_top) = {
133 .name = "exynos850-cmu-top",
134 .id = UCLASS_CLK,
135 .of_match = exynos850_cmu_top_ids,
136 .ops = &ccf_clk_ops,
137 .probe = exynos850_cmu_top_probe,
138 .flags = DM_FLAG_PRE_RELOC,
139};
140
141/* ---- CMU_PERI ------------------------------------------------------------ */
142
143/* Register Offset definitions for CMU_PERI (0x10030000) */
144#define PLL_CON0_MUX_CLKCMU_PERI_BUS_USER 0x0600
145#define PLL_CON0_MUX_CLKCMU_PERI_UART_USER 0x0630
146#define CLK_CON_GAT_GOUT_PERI_UART_IPCLK 0x20a8
147#define CLK_CON_GAT_GOUT_PERI_UART_PCLK 0x20ac
148
149/* List of parent clocks for Muxes in CMU_PERI */
150PNAME(mout_peri_bus_user_p) = { "clock-oscclk", "dout_peri_bus" };
151PNAME(mout_peri_uart_user_p) = { "clock-oscclk", "dout_peri_uart" };
152
153static const struct samsung_mux_clock peri_mux_clks[] = {
154 MUX(CLK_MOUT_PERI_BUS_USER, "mout_peri_bus_user", mout_peri_bus_user_p,
155 PLL_CON0_MUX_CLKCMU_PERI_BUS_USER, 4, 1),
156 MUX(CLK_MOUT_PERI_UART_USER, "mout_peri_uart_user",
157 mout_peri_uart_user_p, PLL_CON0_MUX_CLKCMU_PERI_UART_USER, 4, 1),
158};
159
160static const struct samsung_gate_clock peri_gate_clks[] = {
161 GATE(CLK_GOUT_UART_IPCLK, "gout_uart_ipclk", "mout_peri_uart_user",
162 CLK_CON_GAT_GOUT_PERI_UART_IPCLK, 21, 0, 0),
163 GATE(CLK_GOUT_UART_PCLK, "gout_uart_pclk", "mout_peri_bus_user",
164 CLK_CON_GAT_GOUT_PERI_UART_PCLK, 21, 0, 0),
165};
166
167static const struct samsung_clk_group peri_cmu_clks[] = {
168 { S_CLK_MUX, peri_mux_clks, ARRAY_SIZE(peri_mux_clks) },
169 { S_CLK_GATE, peri_gate_clks, ARRAY_SIZE(peri_gate_clks) },
170};
171
172static int exynos850_cmu_peri_probe(struct udevice *dev)
173{
174 return samsung_register_cmu(dev, peri_cmu_clks, exynos850_cmu_top);
175}
176
177static const struct udevice_id exynos850_cmu_peri_ids[] = {
178 { .compatible = "samsung,exynos850-cmu-peri" },
179 { }
180};
181
182U_BOOT_DRIVER(exynos850_cmu_peri) = {
183 .name = "exynos850-cmu-peri",
184 .id = UCLASS_CLK,
185 .of_match = exynos850_cmu_peri_ids,
186 .ops = &ccf_clk_ops,
187 .probe = exynos850_cmu_peri_probe,
188 .flags = DM_FLAG_PRE_RELOC,
189};