blob: f234ab5d654143ec3b3a5969fbd1448a72dada0d [file] [log] [blame]
Sumit Garge6a488b2022-07-12 12:42:11 +05301// SPDX-License-Identifier: BSD-3-Clause
2/*
3 * Clock drivers for Qualcomm QCS404
4 *
5 * (C) Copyright 2022 Sumit Garg <sumit.garg@linaro.org>
6 */
7
8#include <common.h>
9#include <clk-uclass.h>
10#include <dm.h>
11#include <errno.h>
12#include <asm/io.h>
13#include <linux/bitops.h>
Konrad Dybcio6c0b8442023-11-07 12:41:01 +000014#include <dt-bindings/clock/qcom,gcc-qcs404.h>
15
Caleb Connolly878b26a2023-11-07 12:40:59 +000016#include "clock-qcom.h"
Sumit Garge6a488b2022-07-12 12:42:11 +053017
Caleb Connolly10a0abb2023-11-07 12:41:03 +000018/* Clocks: (from CLK_CTL_BASE) */
19#define GPLL0_STATUS (0x21000)
20#define GPLL1_STATUS (0x20000)
21#define APCS_GPLL_ENA_VOTE (0x45000)
22#define APCS_CLOCK_BRANCH_ENA_VOTE (0x45004)
23
24/* BLSP1 AHB clock (root clock for BLSP) */
25#define BLSP1_AHB_CBCR 0x1008
26
27/* Uart clock control registers */
28#define BLSP1_UART2_BCR (0x3028)
29#define BLSP1_UART2_APPS_CBCR (0x302C)
30#define BLSP1_UART2_APPS_CMD_RCGR (0x3034)
31#define BLSP1_UART2_APPS_CFG_RCGR (0x3038)
32#define BLSP1_UART2_APPS_M (0x303C)
33#define BLSP1_UART2_APPS_N (0x3040)
34#define BLSP1_UART2_APPS_D (0x3044)
35
36/* I2C controller clock control registerss */
37#define BLSP1_QUP0_I2C_APPS_CBCR (0x6028)
38#define BLSP1_QUP0_I2C_APPS_CMD_RCGR (0x602C)
39#define BLSP1_QUP0_I2C_APPS_CFG_RCGR (0x6030)
40#define BLSP1_QUP1_I2C_APPS_CBCR (0x2008)
41#define BLSP1_QUP1_I2C_APPS_CMD_RCGR (0x200C)
42#define BLSP1_QUP1_I2C_APPS_CFG_RCGR (0x2010)
43#define BLSP1_QUP2_I2C_APPS_CBCR (0x3010)
44#define BLSP1_QUP2_I2C_APPS_CMD_RCGR (0x3000)
45#define BLSP1_QUP2_I2C_APPS_CFG_RCGR (0x3004)
46#define BLSP1_QUP3_I2C_APPS_CBCR (0x4020)
47#define BLSP1_QUP3_I2C_APPS_CMD_RCGR (0x4000)
48#define BLSP1_QUP3_I2C_APPS_CFG_RCGR (0x4004)
49#define BLSP1_QUP4_I2C_APPS_CBCR (0x5020)
50#define BLSP1_QUP4_I2C_APPS_CMD_RCGR (0x5000)
51#define BLSP1_QUP4_I2C_APPS_CFG_RCGR (0x5004)
52
53/* SD controller clock control registers */
54#define SDCC_BCR(n) (((n) * 0x1000) + 0x41000)
55#define SDCC_CMD_RCGR(n) (((n) * 0x1000) + 0x41004)
56#define SDCC_CFG_RCGR(n) (((n) * 0x1000) + 0x41008)
57#define SDCC_M(n) (((n) * 0x1000) + 0x4100C)
58#define SDCC_N(n) (((n) * 0x1000) + 0x41010)
59#define SDCC_D(n) (((n) * 0x1000) + 0x41014)
60#define SDCC_APPS_CBCR(n) (((n) * 0x1000) + 0x41018)
61#define SDCC_AHB_CBCR(n) (((n) * 0x1000) + 0x4101C)
62
63/* USB-3.0 controller clock control registers */
64#define SYS_NOC_USB3_CBCR (0x26014)
65#define USB30_BCR (0x39000)
66#define USB3PHY_BCR (0x39008)
67#define USB30_MASTER_CBCR (0x3900C)
68#define USB30_SLEEP_CBCR (0x39010)
69#define USB30_MOCK_UTMI_CBCR (0x39014)
70#define USB30_MOCK_UTMI_CMD_RCGR (0x3901C)
71#define USB30_MOCK_UTMI_CFG_RCGR (0x39020)
72#define USB30_MASTER_CMD_RCGR (0x39028)
73#define USB30_MASTER_CFG_RCGR (0x3902C)
74#define USB30_MASTER_M (0x39030)
75#define USB30_MASTER_N (0x39034)
76#define USB30_MASTER_D (0x39038)
77#define USB2A_PHY_SLEEP_CBCR (0x4102C)
78#define USB_HS_PHY_CFG_AHB_CBCR (0x41030)
79
80/* ETH controller clock control registers */
81#define ETH_PTP_CBCR (0x4e004)
82#define ETH_RGMII_CBCR (0x4e008)
83#define ETH_SLAVE_AHB_CBCR (0x4e00c)
84#define ETH_AXI_CBCR (0x4e010)
85#define EMAC_PTP_CMD_RCGR (0x4e014)
86#define EMAC_PTP_CFG_RCGR (0x4e018)
87#define EMAC_CMD_RCGR (0x4e01c)
88#define EMAC_CFG_RCGR (0x4e020)
89#define EMAC_M (0x4e024)
90#define EMAC_N (0x4e028)
91#define EMAC_D (0x4e02c)
92
Sumit Garge6a488b2022-07-12 12:42:11 +053093
94/* GPLL0 clock control registers */
95#define GPLL0_STATUS_ACTIVE BIT(31)
96
Sumit Garge9e62342023-02-01 19:28:50 +053097#define CFG_CLK_SRC_GPLL1 BIT(8)
98#define GPLL1_STATUS_ACTIVE BIT(31)
99
Sumit Garge6a488b2022-07-12 12:42:11 +0530100static struct vote_clk gcc_blsp1_ahb_clk = {
101 .cbcr_reg = BLSP1_AHB_CBCR,
102 .ena_vote = APCS_CLOCK_BRANCH_ENA_VOTE,
103 .vote_bit = BIT(10) | BIT(5) | BIT(4),
104};
105
106static const struct bcr_regs uart2_regs = {
107 .cfg_rcgr = BLSP1_UART2_APPS_CFG_RCGR,
108 .cmd_rcgr = BLSP1_UART2_APPS_CMD_RCGR,
109 .M = BLSP1_UART2_APPS_M,
110 .N = BLSP1_UART2_APPS_N,
111 .D = BLSP1_UART2_APPS_D,
112};
113
114static const struct bcr_regs sdc_regs = {
115 .cfg_rcgr = SDCC_CFG_RCGR(1),
116 .cmd_rcgr = SDCC_CMD_RCGR(1),
117 .M = SDCC_M(1),
118 .N = SDCC_N(1),
119 .D = SDCC_D(1),
120};
121
122static struct pll_vote_clk gpll0_vote_clk = {
123 .status = GPLL0_STATUS,
124 .status_bit = GPLL0_STATUS_ACTIVE,
125 .ena_vote = APCS_GPLL_ENA_VOTE,
126 .vote_bit = BIT(0),
127};
128
Sumit Garge9e62342023-02-01 19:28:50 +0530129static struct pll_vote_clk gpll1_vote_clk = {
130 .status = GPLL1_STATUS,
131 .status_bit = GPLL1_STATUS_ACTIVE,
132 .ena_vote = APCS_GPLL_ENA_VOTE,
133 .vote_bit = BIT(1),
134};
135
Sumit Garg3018e522022-08-04 19:57:15 +0530136static const struct bcr_regs usb30_master_regs = {
137 .cfg_rcgr = USB30_MASTER_CFG_RCGR,
138 .cmd_rcgr = USB30_MASTER_CMD_RCGR,
139 .M = USB30_MASTER_M,
140 .N = USB30_MASTER_N,
141 .D = USB30_MASTER_D,
142};
143
Sumit Garge9e62342023-02-01 19:28:50 +0530144static const struct bcr_regs emac_regs = {
145 .cfg_rcgr = EMAC_CFG_RCGR,
146 .cmd_rcgr = EMAC_CMD_RCGR,
147 .M = EMAC_M,
148 .N = EMAC_N,
149 .D = EMAC_D,
150};
151
152static const struct bcr_regs emac_ptp_regs = {
153 .cfg_rcgr = EMAC_PTP_CFG_RCGR,
154 .cmd_rcgr = EMAC_PTP_CMD_RCGR,
155 .M = EMAC_M,
156 .N = EMAC_N,
157 .D = EMAC_D,
158};
159
Sumit Garg89e0dff2023-02-13 10:19:09 +0530160static const struct bcr_regs blsp1_qup0_i2c_apps_regs = {
161 .cmd_rcgr = BLSP1_QUP0_I2C_APPS_CMD_RCGR,
162 .cfg_rcgr = BLSP1_QUP0_I2C_APPS_CFG_RCGR,
163 /* mnd_width = 0 */
164};
165
166static const struct bcr_regs blsp1_qup1_i2c_apps_regs = {
167 .cmd_rcgr = BLSP1_QUP1_I2C_APPS_CMD_RCGR,
168 .cfg_rcgr = BLSP1_QUP1_I2C_APPS_CFG_RCGR,
169 /* mnd_width = 0 */
170};
171
172static const struct bcr_regs blsp1_qup2_i2c_apps_regs = {
173 .cmd_rcgr = BLSP1_QUP2_I2C_APPS_CMD_RCGR,
174 .cfg_rcgr = BLSP1_QUP2_I2C_APPS_CFG_RCGR,
175 /* mnd_width = 0 */
176};
177
178static const struct bcr_regs blsp1_qup3_i2c_apps_regs = {
179 .cmd_rcgr = BLSP1_QUP3_I2C_APPS_CMD_RCGR,
180 .cfg_rcgr = BLSP1_QUP3_I2C_APPS_CFG_RCGR,
181 /* mnd_width = 0 */
182};
183
184static const struct bcr_regs blsp1_qup4_i2c_apps_regs = {
185 .cmd_rcgr = BLSP1_QUP4_I2C_APPS_CMD_RCGR,
186 .cfg_rcgr = BLSP1_QUP4_I2C_APPS_CFG_RCGR,
187 /* mnd_width = 0 */
188};
189
Caleb Connolly10a0abb2023-11-07 12:41:03 +0000190static ulong qcs404_clk_set_rate(struct clk *clk, ulong rate)
Sumit Garge6a488b2022-07-12 12:42:11 +0530191{
192 struct msm_clk_priv *priv = dev_get_priv(clk->dev);
193
194 switch (clk->id) {
195 case GCC_BLSP1_UART2_APPS_CLK:
196 /* UART: 115200 */
197 clk_rcg_set_rate_mnd(priv->base, &uart2_regs, 0, 12, 125,
Caleb Connollyfbacc672023-11-07 12:41:04 +0000198 CFG_CLK_SRC_CXO, 16);
Sumit Garge6a488b2022-07-12 12:42:11 +0530199 clk_enable_cbc(priv->base + BLSP1_UART2_APPS_CBCR);
200 break;
201 case GCC_BLSP1_AHB_CLK:
202 clk_enable_vote_clk(priv->base, &gcc_blsp1_ahb_clk);
203 break;
204 case GCC_SDCC1_APPS_CLK:
205 /* SDCC1: 200MHz */
206 clk_rcg_set_rate_mnd(priv->base, &sdc_regs, 4, 0, 0,
Caleb Connollyfbacc672023-11-07 12:41:04 +0000207 CFG_CLK_SRC_GPLL0, 8);
Sumit Garge6a488b2022-07-12 12:42:11 +0530208 clk_enable_gpll0(priv->base, &gpll0_vote_clk);
209 clk_enable_cbc(priv->base + SDCC_APPS_CBCR(1));
210 break;
211 case GCC_SDCC1_AHB_CLK:
212 clk_enable_cbc(priv->base + SDCC_AHB_CBCR(1));
213 break;
Sumit Garge9e62342023-02-01 19:28:50 +0530214 case GCC_ETH_RGMII_CLK:
215 if (rate == 250000000)
216 clk_rcg_set_rate_mnd(priv->base, &emac_regs, 2, 0, 0,
Caleb Connollyfbacc672023-11-07 12:41:04 +0000217 CFG_CLK_SRC_GPLL1, 8);
Sumit Garge9e62342023-02-01 19:28:50 +0530218 else if (rate == 125000000)
219 clk_rcg_set_rate_mnd(priv->base, &emac_regs, 4, 0, 0,
Caleb Connollyfbacc672023-11-07 12:41:04 +0000220 CFG_CLK_SRC_GPLL1, 8);
Sumit Garge9e62342023-02-01 19:28:50 +0530221 else if (rate == 50000000)
222 clk_rcg_set_rate_mnd(priv->base, &emac_regs, 10, 0, 0,
Caleb Connollyfbacc672023-11-07 12:41:04 +0000223 CFG_CLK_SRC_GPLL1, 8);
Sumit Garge9e62342023-02-01 19:28:50 +0530224 else if (rate == 5000000)
225 clk_rcg_set_rate_mnd(priv->base, &emac_regs, 2, 1, 50,
Caleb Connollyfbacc672023-11-07 12:41:04 +0000226 CFG_CLK_SRC_GPLL1, 8);
Sumit Garge9e62342023-02-01 19:28:50 +0530227 break;
Sumit Garge6a488b2022-07-12 12:42:11 +0530228 default:
229 return 0;
230 }
231
232 return 0;
233}
Sumit Garg1d1ca6e2022-08-04 19:57:14 +0530234
Caleb Connolly10a0abb2023-11-07 12:41:03 +0000235static int qcs404_clk_enable(struct clk *clk)
Sumit Garg1d1ca6e2022-08-04 19:57:14 +0530236{
Sumit Garg3018e522022-08-04 19:57:15 +0530237 struct msm_clk_priv *priv = dev_get_priv(clk->dev);
238
239 switch (clk->id) {
240 case GCC_USB30_MASTER_CLK:
241 clk_enable_cbc(priv->base + USB30_MASTER_CBCR);
242 clk_rcg_set_rate_mnd(priv->base, &usb30_master_regs, 4, 0, 0,
Caleb Connollyfbacc672023-11-07 12:41:04 +0000243 CFG_CLK_SRC_GPLL0, 8);
Sumit Garg3018e522022-08-04 19:57:15 +0530244 break;
245 case GCC_SYS_NOC_USB3_CLK:
246 clk_enable_cbc(priv->base + SYS_NOC_USB3_CBCR);
247 break;
248 case GCC_USB30_SLEEP_CLK:
249 clk_enable_cbc(priv->base + USB30_SLEEP_CBCR);
250 break;
251 case GCC_USB30_MOCK_UTMI_CLK:
252 clk_enable_cbc(priv->base + USB30_MOCK_UTMI_CBCR);
253 break;
254 case GCC_USB_HS_PHY_CFG_AHB_CLK:
255 clk_enable_cbc(priv->base + USB_HS_PHY_CFG_AHB_CBCR);
256 break;
257 case GCC_USB2A_PHY_SLEEP_CLK:
258 clk_enable_cbc(priv->base + USB_HS_PHY_CFG_AHB_CBCR);
259 break;
Sumit Garge9e62342023-02-01 19:28:50 +0530260 case GCC_ETH_PTP_CLK:
261 /* SPEED_1000: freq -> 250MHz */
262 clk_enable_cbc(priv->base + ETH_PTP_CBCR);
263 clk_enable_gpll0(priv->base, &gpll1_vote_clk);
264 clk_rcg_set_rate_mnd(priv->base, &emac_ptp_regs, 2, 0, 0,
Caleb Connollyfbacc672023-11-07 12:41:04 +0000265 CFG_CLK_SRC_GPLL1, 8);
Sumit Garge9e62342023-02-01 19:28:50 +0530266 break;
267 case GCC_ETH_RGMII_CLK:
268 /* SPEED_1000: freq -> 250MHz */
269 clk_enable_cbc(priv->base + ETH_RGMII_CBCR);
270 clk_enable_gpll0(priv->base, &gpll1_vote_clk);
271 clk_rcg_set_rate_mnd(priv->base, &emac_regs, 2, 0, 0,
Caleb Connollyfbacc672023-11-07 12:41:04 +0000272 CFG_CLK_SRC_GPLL1, 8);
Sumit Garge9e62342023-02-01 19:28:50 +0530273 break;
274 case GCC_ETH_SLAVE_AHB_CLK:
275 clk_enable_cbc(priv->base + ETH_SLAVE_AHB_CBCR);
276 break;
277 case GCC_ETH_AXI_CLK:
278 clk_enable_cbc(priv->base + ETH_AXI_CBCR);
279 break;
Sumit Garg89e0dff2023-02-13 10:19:09 +0530280 case GCC_BLSP1_AHB_CLK:
281 clk_enable_vote_clk(priv->base, &gcc_blsp1_ahb_clk);
282 break;
283 case GCC_BLSP1_QUP0_I2C_APPS_CLK:
284 clk_enable_cbc(priv->base + BLSP1_QUP0_I2C_APPS_CBCR);
285 clk_rcg_set_rate(priv->base, &blsp1_qup0_i2c_apps_regs, 0,
286 CFG_CLK_SRC_CXO);
287 break;
288 case GCC_BLSP1_QUP1_I2C_APPS_CLK:
289 clk_enable_cbc(priv->base + BLSP1_QUP1_I2C_APPS_CBCR);
290 clk_rcg_set_rate(priv->base, &blsp1_qup1_i2c_apps_regs, 0,
291 CFG_CLK_SRC_CXO);
292 break;
293 case GCC_BLSP1_QUP2_I2C_APPS_CLK:
294 clk_enable_cbc(priv->base + BLSP1_QUP2_I2C_APPS_CBCR);
295 clk_rcg_set_rate(priv->base, &blsp1_qup2_i2c_apps_regs, 0,
296 CFG_CLK_SRC_CXO);
297 break;
298 case GCC_BLSP1_QUP3_I2C_APPS_CLK:
299 clk_enable_cbc(priv->base + BLSP1_QUP3_I2C_APPS_CBCR);
300 clk_rcg_set_rate(priv->base, &blsp1_qup3_i2c_apps_regs, 0,
301 CFG_CLK_SRC_CXO);
302 break;
303 case GCC_BLSP1_QUP4_I2C_APPS_CLK:
304 clk_enable_cbc(priv->base + BLSP1_QUP4_I2C_APPS_CBCR);
305 clk_rcg_set_rate(priv->base, &blsp1_qup4_i2c_apps_regs, 0,
306 CFG_CLK_SRC_CXO);
307 break;
Sumit Garg3018e522022-08-04 19:57:15 +0530308 default:
309 return 0;
310 }
311
Sumit Garg1d1ca6e2022-08-04 19:57:14 +0530312 return 0;
313}
Konrad Dybcio6c0b8442023-11-07 12:41:01 +0000314
315static const struct qcom_reset_map qcs404_gcc_resets[] = {
316 [GCC_GENI_IR_BCR] = { 0x0F000 },
317 [GCC_CDSP_RESTART] = { 0x18000 },
318 [GCC_USB_HS_BCR] = { 0x41000 },
319 [GCC_USB2_HS_PHY_ONLY_BCR] = { 0x41034 },
320 [GCC_QUSB2_PHY_BCR] = { 0x4103c },
321 [GCC_USB_HS_PHY_CFG_AHB_BCR] = { 0x0000c, 1 },
322 [GCC_USB2A_PHY_BCR] = { 0x0000c, 0 },
323 [GCC_USB3_PHY_BCR] = { 0x39004 },
324 [GCC_USB_30_BCR] = { 0x39000 },
325 [GCC_USB3PHY_PHY_BCR] = { 0x39008 },
326 [GCC_PCIE_0_BCR] = { 0x3e000 },
327 [GCC_PCIE_0_PHY_BCR] = { 0x3e004 },
328 [GCC_PCIE_0_LINK_DOWN_BCR] = { 0x3e038 },
329 [GCC_PCIEPHY_0_PHY_BCR] = { 0x3e03c },
330 [GCC_PCIE_0_AXI_MASTER_STICKY_ARES] = { 0x3e040, 6},
331 [GCC_PCIE_0_AHB_ARES] = { 0x3e040, 5 },
332 [GCC_PCIE_0_AXI_SLAVE_ARES] = { 0x3e040, 4 },
333 [GCC_PCIE_0_AXI_MASTER_ARES] = { 0x3e040, 3 },
334 [GCC_PCIE_0_CORE_STICKY_ARES] = { 0x3e040, 2 },
335 [GCC_PCIE_0_SLEEP_ARES] = { 0x3e040, 1 },
336 [GCC_PCIE_0_PIPE_ARES] = { 0x3e040, 0 },
337 [GCC_EMAC_BCR] = { 0x4e000 },
338 [GCC_WDSP_RESTART] = {0x19000},
339};
340
Caleb Connolly10a0abb2023-11-07 12:41:03 +0000341static const struct msm_clk_data qcs404_clk_gcc_data = {
Konrad Dybcio6c0b8442023-11-07 12:41:01 +0000342 .resets = qcs404_gcc_resets,
343 .num_resets = ARRAY_SIZE(qcs404_gcc_resets),
Caleb Connolly10a0abb2023-11-07 12:41:03 +0000344 .enable = qcs404_clk_enable,
345 .set_rate = qcs404_clk_set_rate,
Konrad Dybcio6c0b8442023-11-07 12:41:01 +0000346};
347
348static const struct udevice_id gcc_qcs404_of_match[] = {
349 {
350 .compatible = "qcom,gcc-qcs404",
Caleb Connolly10a0abb2023-11-07 12:41:03 +0000351 .data = (ulong)&qcs404_clk_gcc_data
Konrad Dybcio6c0b8442023-11-07 12:41:01 +0000352 },
353 { }
354};
355
356U_BOOT_DRIVER(gcc_qcs404) = {
357 .name = "gcc_qcs404",
358 .id = UCLASS_NOP,
359 .of_match = gcc_qcs404_of_match,
360 .bind = qcom_cc_bind,
361 .flags = DM_FLAG_PRE_RELOC,
362};