blob: 88f2e678f43cfcc9b80917f26c211049ebca6f9d [file] [log] [blame]
Julius Lehmann9930fca2024-09-11 19:13:09 +02001// SPDX-License-Identifier: BSD-3-Clause
2/*
3 * Clock drivers for Qualcomm SM8150
4 *
5 * Volodymyr Babchuk <volodymyr_babchuk@epam.com>
6 * Copyright (c) 2024 EPAM Systems.
7 *
8 * (C) Copyright 2024 Julius Lehmann <lehmanju@devpi.de>
9 *
10 * Based on U-Boot driver for SM8250. Constants are taken from the Linux driver.
11 */
12
13#include <clk-uclass.h>
14#include <dm.h>
15#include <errno.h>
16#include <asm/io.h>
17#include <linux/bitops.h>
18#include <dt-bindings/clock/qcom,gcc-sm8150.h>
19
20#include "clock-qcom.h"
21
22#define EMAC_RGMII_CLK_CMD_RCGR 0x601c
23#define QUPV3_WRAP0_S0_CLK_CMD_RCGR 0x18148
24#define USB30_PRIM_MASTER_CLK_CMD_RCGR 0xf01c
25#define USB30_PRIM_MOCK_UTMI_CLK_CMD_RCGR 0xf034
26#define USB30_PRIM_PHY_AUX_CLK_CMD_RCGR 0xf060
27#define USB30_SEC_MASTER_CLK_CMD_RCGR 0x1001c
28#define USB30_SEC_MOCK_UTMI_CLK_CMD_RCGR 0x10034
29#define USB30_SEC_PHY_AUX_CLK_CMD_RCGR 0x10060
30#define SDCC2_APPS_CLK_CMD_RCGR 0x1400c
31
32static struct pll_vote_clk gpll7_vote_clk = {
33 .status = 0x1a000,
34 .status_bit = BIT(31),
35 .ena_vote = 0x52000,
36 .vote_bit = BIT(7),
37};
38
39static const struct freq_tbl ftbl_gcc_qupv3_wrap0_s0_clk_src[] = {
40 F(7372800, CFG_CLK_SRC_GPLL0_EVEN, 1, 384, 15625),
41 F(14745600, CFG_CLK_SRC_GPLL0_EVEN, 1, 768, 15625),
42 F(19200000, CFG_CLK_SRC_CXO, 1, 0, 0),
43 F(29491200, CFG_CLK_SRC_GPLL0_EVEN, 1, 1536, 15625),
44 F(32000000, CFG_CLK_SRC_GPLL0_EVEN, 1, 8, 75),
45 F(48000000, CFG_CLK_SRC_GPLL0_EVEN, 1, 4, 25),
46 F(64000000, CFG_CLK_SRC_GPLL0_EVEN, 1, 16, 75),
47 F(80000000, CFG_CLK_SRC_GPLL0_EVEN, 1, 4, 15),
48 F(96000000, CFG_CLK_SRC_GPLL0_EVEN, 1, 8, 25),
49 F(100000000, CFG_CLK_SRC_GPLL0_EVEN, 3, 0, 0),
50 F(102400000, CFG_CLK_SRC_GPLL0_EVEN, 1, 128, 375),
51 F(112000000, CFG_CLK_SRC_GPLL0_EVEN, 1, 28, 75),
52 F(117964800, CFG_CLK_SRC_GPLL0_EVEN, 1, 6144, 15625),
53 F(120000000, CFG_CLK_SRC_GPLL0_EVEN, 2.5, 0, 0),
54 F(128000000, CFG_CLK_SRC_GPLL0, 1, 16, 75),
55 { }
56};
57
58static const struct freq_tbl ftbl_gcc_emac_rgmii_clk_src[] = {
59 F(2500000, CFG_CLK_SRC_CXO, 1, 25, 192),
60 F(5000000, CFG_CLK_SRC_CXO, 1, 25, 96),
61 F(19200000, CFG_CLK_SRC_CXO, 1, 0, 0),
62 F(25000000, CFG_CLK_SRC_GPLL0_EVEN, 12, 0, 0),
63 F(50000000, CFG_CLK_SRC_GPLL0_EVEN, 6, 0, 0),
64 F(125000000, CFG_CLK_SRC_GPLL7, 4, 0, 0),
65 F(250000000, CFG_CLK_SRC_GPLL7, 2, 0, 0),
66 { }
67};
68
69static const struct freq_tbl ftbl_gcc_usb30_prim_master_clk_src[] = {
70 F(33333333, CFG_CLK_SRC_GPLL0_EVEN, 9, 0, 0),
71 F(66666667, CFG_CLK_SRC_GPLL0_EVEN, 4.5, 0, 0),
72 F(133333333, CFG_CLK_SRC_GPLL0, 4.5, 0, 0),
73 F(200000000, CFG_CLK_SRC_GPLL0, 3, 0, 0),
74 F(240000000, CFG_CLK_SRC_GPLL0, 2.5, 0, 0),
75 { }
76};
77
78static const struct freq_tbl ftbl_gcc_usb30_prim_mock_utmi_clk_src[] = {
79 F(19200000, CFG_CLK_SRC_CXO, 1, 0, 0),
80 F(20000000, CFG_CLK_SRC_GPLL0_EVEN, 15, 0, 0),
81 F(60000000, CFG_CLK_SRC_GPLL0_EVEN, 5, 0, 0),
82 { }
83};
84
85static const struct freq_tbl ftbl_gcc_sdcc2_apps_clk_src[] = {
86 F(400000, CFG_CLK_SRC_CXO, 12, 1, 4),
87 F(9600000, CFG_CLK_SRC_CXO, 2, 0, 0),
88 F(19200000, CFG_CLK_SRC_CXO, 1, 0, 0),
89 F(25000000, CFG_CLK_SRC_GPLL0, 12, 1, 2),
90 F(50000000, CFG_CLK_SRC_GPLL0, 12, 0, 0),
91 F(100000000, CFG_CLK_SRC_GPLL0, 6, 0, 0),
92 F(202000000, CFG_CLK_SRC_GPLL0, 4, 0, 0),
93 { }
94};
95
96static ulong sm8150_clk_set_rate(struct clk *clk, ulong rate)
97{
98 struct msm_clk_priv *priv = dev_get_priv(clk->dev);
99 const struct freq_tbl *freq;
100
101 switch (clk->id) {
102 case GCC_QUPV3_WRAP1_S4_CLK: /* UART2 aka debug-uart */
103 freq = qcom_find_freq(ftbl_gcc_qupv3_wrap0_s0_clk_src, rate);
104 clk_rcg_set_rate_mnd(priv->base, QUPV3_WRAP0_S0_CLK_CMD_RCGR,
105 freq->pre_div, freq->m, freq->n, freq->src, 16);
106 return freq->freq;
107 case GCC_EMAC_RGMII_CLK:
108 freq = qcom_find_freq(ftbl_gcc_emac_rgmii_clk_src, rate);
109 clk_rcg_set_rate_mnd(priv->base, EMAC_RGMII_CLK_CMD_RCGR,
110 freq->pre_div, freq->m, freq->n, freq->src, 8);
111 return freq->freq;
112 case GCC_USB30_PRIM_MASTER_CLK:
113 freq = qcom_find_freq(ftbl_gcc_usb30_prim_master_clk_src, rate);
114 clk_rcg_set_rate_mnd(priv->base, USB30_PRIM_MASTER_CLK_CMD_RCGR,
115 freq->pre_div, freq->m, freq->n, freq->src, 8);
116 return freq->freq;
117 case GCC_USB30_PRIM_MOCK_UTMI_CLK:
118 freq = qcom_find_freq(ftbl_gcc_usb30_prim_mock_utmi_clk_src, rate);
119 clk_rcg_set_rate_mnd(priv->base, USB30_PRIM_MOCK_UTMI_CLK_CMD_RCGR,
120 freq->pre_div, freq->m, freq->n, freq->src, 0);
121 return freq->freq;
122 case GCC_USB3_PRIM_PHY_AUX_CLK_SRC:
123 freq = qcom_find_freq(ftbl_gcc_usb30_prim_mock_utmi_clk_src, rate);
124 clk_rcg_set_rate_mnd(priv->base, USB30_PRIM_PHY_AUX_CLK_CMD_RCGR,
125 freq->pre_div, freq->m, freq->n, freq->src, 0);
126 return freq->freq;
127 case GCC_USB30_SEC_MASTER_CLK:
128 freq = qcom_find_freq(ftbl_gcc_usb30_prim_master_clk_src, rate);
129 clk_rcg_set_rate_mnd(priv->base, USB30_SEC_MASTER_CLK_CMD_RCGR,
130 freq->pre_div, freq->m, freq->n, freq->src, 8);
131 return freq->freq;
132 case GCC_USB30_SEC_MOCK_UTMI_CLK:
133 freq = qcom_find_freq(ftbl_gcc_usb30_prim_mock_utmi_clk_src, rate);
134 clk_rcg_set_rate_mnd(priv->base, USB30_SEC_MOCK_UTMI_CLK_CMD_RCGR,
135 freq->pre_div, freq->m, freq->n, freq->src, 0);
136 return freq->freq;
137 case GCC_USB3_SEC_PHY_AUX_CLK_SRC:
138 freq = qcom_find_freq(ftbl_gcc_usb30_prim_mock_utmi_clk_src, rate);
139 clk_rcg_set_rate_mnd(priv->base, USB30_SEC_PHY_AUX_CLK_CMD_RCGR,
140 freq->pre_div, freq->m, freq->n, freq->src, 0);
141 return freq->freq;
142 case GCC_SDCC2_APPS_CLK:
143 freq = qcom_find_freq(ftbl_gcc_sdcc2_apps_clk_src, rate);
144 clk_rcg_set_rate_mnd(priv->base, SDCC2_APPS_CLK_CMD_RCGR,
145 freq->pre_div, freq->m, freq->n, freq->src, 8);
146 return freq->freq;
147 default:
148 return 0;
149 }
150}
151
152static const struct gate_clk sm8150_clks[] = {
153 GATE_CLK(GCC_AGGRE_UFS_CARD_AXI_CLK, 0x750c0, 0x00000001),
154 GATE_CLK(GCC_AGGRE_UFS_PHY_AXI_CLK, 0x770c0, 0x00000001),
155 GATE_CLK(GCC_AGGRE_USB3_PRIM_AXI_CLK, 0xf07c, 0x00000001),
156 GATE_CLK(GCC_AGGRE_USB3_SEC_AXI_CLK, 0x1007c, 0x00000001),
157 GATE_CLK(GCC_CFG_NOC_USB3_PRIM_AXI_CLK, 0xf078, 0x00000001),
158 GATE_CLK(GCC_CFG_NOC_USB3_SEC_AXI_CLK, 0x10078, 0x00000001),
159 GATE_CLK(GCC_QUPV3_WRAP0_S0_CLK, 0x5200c, 0x00000400),
160 GATE_CLK(GCC_QUPV3_WRAP0_S1_CLK, 0x5200c, 0x00000800),
161 GATE_CLK(GCC_QUPV3_WRAP0_S2_CLK, 0x5200c, 0x00001000),
162 GATE_CLK(GCC_QUPV3_WRAP0_S3_CLK, 0x5200c, 0x00002000),
163 GATE_CLK(GCC_QUPV3_WRAP0_S4_CLK, 0x5200c, 0x00004000),
164 GATE_CLK(GCC_QUPV3_WRAP0_S5_CLK, 0x5200c, 0x00008000),
165 GATE_CLK(GCC_QUPV3_WRAP1_S0_CLK, 0x5200c, 0x00400000),
166 GATE_CLK(GCC_QUPV3_WRAP1_S1_CLK, 0x5200c, 0x00800000),
167 GATE_CLK(GCC_QUPV3_WRAP1_S3_CLK, 0x5200c, 0x02000000),
168 GATE_CLK(GCC_QUPV3_WRAP1_S4_CLK, 0x5200c, 0x04000000),
169 GATE_CLK(GCC_QUPV3_WRAP1_S5_CLK, 0x5200c, 0x08000000),
170 GATE_CLK(GCC_QUPV3_WRAP_0_M_AHB_CLK, 0x5200c, 0x00000040),
171 GATE_CLK(GCC_QUPV3_WRAP_0_S_AHB_CLK, 0x5200c, 0x00000080),
172 GATE_CLK(GCC_QUPV3_WRAP_1_M_AHB_CLK, 0x5200c, 0x00100000),
173 GATE_CLK(GCC_QUPV3_WRAP_1_S_AHB_CLK, 0x5200c, 0x00200000),
174 GATE_CLK(GCC_SDCC2_AHB_CLK, 0x14008, 0x00000001),
175 GATE_CLK(GCC_SDCC2_APPS_CLK, 0x14004, 0x00000001),
176 GATE_CLK(GCC_SDCC4_AHB_CLK, 0x16008, 0x00000001),
177 GATE_CLK(GCC_SDCC4_APPS_CLK, 0x16004, 0x00000001),
178 GATE_CLK(GCC_UFS_CARD_AHB_CLK, 0x75014, 0x00000001),
179 GATE_CLK(GCC_UFS_CARD_AXI_CLK, 0x75010, 0x00000001),
180 GATE_CLK(GCC_UFS_CARD_CLKREF_CLK, 0x8c004, 0x00000001),
181 GATE_CLK(GCC_UFS_CARD_ICE_CORE_CLK, 0x7505c, 0x00000001),
182 GATE_CLK(GCC_UFS_CARD_PHY_AUX_CLK, 0x75090, 0x00000001),
183 GATE_CLK(GCC_UFS_CARD_RX_SYMBOL_0_CLK, 0x7501c, 0x00000001),
184 GATE_CLK(GCC_UFS_CARD_RX_SYMBOL_1_CLK, 0x750ac, 0x00000001),
185 GATE_CLK(GCC_UFS_CARD_TX_SYMBOL_0_CLK, 0x75018, 0x00000001),
186 GATE_CLK(GCC_UFS_CARD_UNIPRO_CORE_CLK, 0x75058, 0x00000001),
187 GATE_CLK(GCC_UFS_MEM_CLKREF_CLK, 0x8c000, 0x00000001),
188 GATE_CLK(GCC_UFS_PHY_AHB_CLK, 0x77014, 0x00000001),
189 GATE_CLK(GCC_UFS_PHY_AXI_CLK, 0x77010, 0x00000001),
190 GATE_CLK(GCC_UFS_PHY_ICE_CORE_CLK, 0x7705c, 0x00000001),
191 GATE_CLK(GCC_UFS_PHY_PHY_AUX_CLK, 0x77090, 0x00000001),
192 GATE_CLK(GCC_UFS_PHY_RX_SYMBOL_0_CLK, 0x7701c, 0x00000001),
193 GATE_CLK(GCC_UFS_PHY_RX_SYMBOL_1_CLK, 0x770ac, 0x00000001),
194 GATE_CLK(GCC_UFS_PHY_TX_SYMBOL_0_CLK, 0x77018, 0x00000001),
195 GATE_CLK(GCC_UFS_PHY_UNIPRO_CORE_CLK, 0x77058, 0x00000001),
196 GATE_CLK(GCC_USB30_PRIM_MASTER_CLK, 0x0f00c, 0x00000001),
197 GATE_CLK(GCC_USB30_PRIM_MOCK_UTMI_CLK, 0x0f014, 0x00000001),
198 GATE_CLK(GCC_USB30_PRIM_SLEEP_CLK, 0x0f010, 0x00000001),
199 GATE_CLK(GCC_USB30_SEC_MASTER_CLK, 0x1000c, 0x00000001),
200 GATE_CLK(GCC_USB30_SEC_MOCK_UTMI_CLK, 0x10014, 0x00000001),
201 GATE_CLK(GCC_USB30_SEC_SLEEP_CLK, 0x10010, 0x00000001),
202 GATE_CLK(GCC_USB3_PRIM_CLKREF_CLK, 0x8c008, 0x00000001),
203 GATE_CLK(GCC_USB3_PRIM_PHY_AUX_CLK, 0x0f04c, 0x00000001),
204 GATE_CLK(GCC_USB3_PRIM_PHY_COM_AUX_CLK, 0x0f050, 0x00000001),
205 GATE_CLK(GCC_USB3_PRIM_PHY_PIPE_CLK, 0x0f054, 0x00000001),
206 GATE_CLK(GCC_USB3_SEC_CLKREF_CLK, 0x8c028, 0x00000001),
207 GATE_CLK(GCC_USB3_SEC_PHY_AUX_CLK, 0x1004c, 0x00000001),
208 GATE_CLK(GCC_USB3_SEC_PHY_PIPE_CLK, 0x10054, 0x00000001),
209 GATE_CLK(GCC_USB3_SEC_PHY_COM_AUX_CLK, 0x10050, 0x00000001),
210 GATE_CLK(GCC_EMAC_AXI_CLK, 0x06010, 0x00000001),
211 GATE_CLK(GCC_EMAC_SLV_AHB_CLK, 0x06014, 0x00000001),
212 GATE_CLK(GCC_EMAC_PTP_CLK, 0x06034, 0x00000001),
213 GATE_CLK(GCC_EMAC_RGMII_CLK, 0x06018, 0x00000001),
214};
215
216static int sm8150_clk_enable(struct clk *clk)
217{
218 struct msm_clk_priv *priv = dev_get_priv(clk->dev);
219
220 if (priv->data->num_clks <= clk->id) {
221 debug("%s: unknown clk id %lu\n", __func__, clk->id);
222 return 0;
223 }
224
225 debug("%s: clk %s\n", __func__, sm8150_clks[clk->id].name);
226
227 switch (clk->id) {
228 case GCC_EMAC_RGMII_CLK:
229 clk_enable_gpll0(priv->base, &gpll7_vote_clk);
230 case GCC_AGGRE_USB3_PRIM_AXI_CLK:
231 qcom_gate_clk_en(priv, GCC_USB30_PRIM_MASTER_CLK);
232 fallthrough;
233 case GCC_USB30_PRIM_MASTER_CLK:
234 qcom_gate_clk_en(priv, GCC_USB3_PRIM_PHY_AUX_CLK);
235 qcom_gate_clk_en(priv, GCC_USB3_PRIM_PHY_COM_AUX_CLK);
236 break;
237 case GCC_AGGRE_USB3_SEC_AXI_CLK:
238 qcom_gate_clk_en(priv, GCC_USB30_SEC_MASTER_CLK);
239 fallthrough;
240 case GCC_USB30_SEC_MASTER_CLK:
241 qcom_gate_clk_en(priv, GCC_USB3_SEC_PHY_AUX_CLK);
242 qcom_gate_clk_en(priv, GCC_USB3_SEC_PHY_COM_AUX_CLK);
243 break;
244 };
245
246 qcom_gate_clk_en(priv, clk->id);
247
248 return 0;
249}
250
251static const struct qcom_reset_map sm8150_gcc_resets[] = {
252 [GCC_EMAC_BCR] = { 0x6000 },
253 [GCC_GPU_BCR] = { 0x71000 },
254 [GCC_MMSS_BCR] = { 0xb000 },
255 [GCC_NPU_BCR] = { 0x4d000 },
256 [GCC_PCIE_0_BCR] = { 0x6b000 },
257 [GCC_PCIE_0_PHY_BCR] = { 0x6c01c },
258 [GCC_PCIE_1_BCR] = { 0x8d000 },
259 [GCC_PCIE_1_PHY_BCR] = { 0x8e01c },
260 [GCC_PCIE_PHY_BCR] = { 0x6f000 },
261 [GCC_PDM_BCR] = { 0x33000 },
262 [GCC_PRNG_BCR] = { 0x34000 },
263 [GCC_QSPI_BCR] = { 0x24008 },
264 [GCC_QUPV3_WRAPPER_0_BCR] = { 0x17000 },
265 [GCC_QUPV3_WRAPPER_1_BCR] = { 0x18000 },
266 [GCC_QUPV3_WRAPPER_2_BCR] = { 0x1e000 },
267 [GCC_QUSB2PHY_PRIM_BCR] = { 0x12000 },
268 [GCC_QUSB2PHY_SEC_BCR] = { 0x12004 },
269 [GCC_USB3_PHY_PRIM_BCR] = { 0x50000 },
270 [GCC_USB3_DP_PHY_PRIM_BCR] = { 0x50008 },
271 [GCC_USB3_PHY_SEC_BCR] = { 0x5000c },
272 [GCC_USB3PHY_PHY_SEC_BCR] = { 0x50010 },
273 [GCC_SDCC2_BCR] = { 0x14000 },
274 [GCC_SDCC4_BCR] = { 0x16000 },
275 [GCC_TSIF_BCR] = { 0x36000 },
276 [GCC_UFS_CARD_BCR] = { 0x75000 },
277 [GCC_UFS_PHY_BCR] = { 0x77000 },
278 [GCC_USB30_PRIM_BCR] = { 0xf000 },
279 [GCC_USB30_SEC_BCR] = { 0x10000 },
280 [GCC_USB_PHY_CFG_AHB2PHY_BCR] = { 0x6a000 },
281};
282
283static const struct qcom_power_map sm8150_gcc_power_domains[] = {
284 [EMAC_GDSC] = { 0x6004 },
285 [PCIE_0_GDSC] = { 0x6b004 },
286 [PCIE_1_GDSC] = { 0x8d004 },
287 [UFS_CARD_GDSC] = { 0x75004 },
288 [UFS_PHY_GDSC] = { 0x77004 },
289 [USB30_PRIM_GDSC] = { 0xf004 },
290 [USB30_SEC_GDSC] = { 0x10004 },
291};
292
293static struct msm_clk_data sm8150_clk_data = {
294 .resets = sm8150_gcc_resets,
295 .num_resets = ARRAY_SIZE(sm8150_gcc_resets),
296 .clks = sm8150_clks,
297 .num_clks = ARRAY_SIZE(sm8150_clks),
298 .power_domains = sm8150_gcc_power_domains,
299 .num_power_domains = ARRAY_SIZE(sm8150_gcc_power_domains),
300
301 .enable = sm8150_clk_enable,
302 .set_rate = sm8150_clk_set_rate,
303};
304
305static const struct udevice_id gcc_sm8150_of_match[] = {
306 {
307 .compatible = "qcom,gcc-sm8150",
308 .data = (ulong)&sm8150_clk_data,
309 },
310 { }
311};
312
313U_BOOT_DRIVER(gcc_sm8150) = {
314 .name = "gcc_sm8150",
315 .id = UCLASS_NOP,
316 .of_match = gcc_sm8150_of_match,
317 .bind = qcom_cc_bind,
318 .flags = DM_FLAG_PRE_RELOC,
319};