blob: 65823944e79a816f52cee48947fb227ba4c80349 [file] [log] [blame]
Sumit Garga4a9d9e2022-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 Dybciod9935732023-11-07 12:41:01 +000014#include <dt-bindings/clock/qcom,gcc-qcs404.h>
15
Caleb Connolly5bb0df62023-11-07 12:40:59 +000016#include "clock-qcom.h"
Sumit Garga4a9d9e2022-07-12 12:42:11 +053017
Caleb Connollyc94f9e92023-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)
Caleb Connollyc94f9e92023-11-07 12:41:03 +000031
32/* I2C controller clock control registerss */
33#define BLSP1_QUP0_I2C_APPS_CBCR (0x6028)
34#define BLSP1_QUP0_I2C_APPS_CMD_RCGR (0x602C)
Caleb Connollyc94f9e92023-11-07 12:41:03 +000035#define BLSP1_QUP1_I2C_APPS_CBCR (0x2008)
36#define BLSP1_QUP1_I2C_APPS_CMD_RCGR (0x200C)
Caleb Connollyc94f9e92023-11-07 12:41:03 +000037#define BLSP1_QUP2_I2C_APPS_CBCR (0x3010)
38#define BLSP1_QUP2_I2C_APPS_CMD_RCGR (0x3000)
Caleb Connollyc94f9e92023-11-07 12:41:03 +000039#define BLSP1_QUP3_I2C_APPS_CBCR (0x4020)
40#define BLSP1_QUP3_I2C_APPS_CMD_RCGR (0x4000)
Caleb Connollyc94f9e92023-11-07 12:41:03 +000041#define BLSP1_QUP4_I2C_APPS_CBCR (0x5020)
42#define BLSP1_QUP4_I2C_APPS_CMD_RCGR (0x5000)
Caleb Connollyc94f9e92023-11-07 12:41:03 +000043
44/* SD controller clock control registers */
45#define SDCC_BCR(n) (((n) * 0x1000) + 0x41000)
Caleb Connolly422b74b2023-11-21 17:55:53 +000046#define SDCC_CMD_RCGR(n) (((n + 1) * 0x1000) + 0x41004)
Caleb Connollyc94f9e92023-11-07 12:41:03 +000047#define SDCC_APPS_CBCR(n) (((n) * 0x1000) + 0x41018)
48#define SDCC_AHB_CBCR(n) (((n) * 0x1000) + 0x4101C)
49
50/* USB-3.0 controller clock control registers */
51#define SYS_NOC_USB3_CBCR (0x26014)
52#define USB30_BCR (0x39000)
53#define USB3PHY_BCR (0x39008)
54#define USB30_MASTER_CBCR (0x3900C)
55#define USB30_SLEEP_CBCR (0x39010)
56#define USB30_MOCK_UTMI_CBCR (0x39014)
57#define USB30_MOCK_UTMI_CMD_RCGR (0x3901C)
58#define USB30_MOCK_UTMI_CFG_RCGR (0x39020)
59#define USB30_MASTER_CMD_RCGR (0x39028)
Caleb Connollyc94f9e92023-11-07 12:41:03 +000060#define USB2A_PHY_SLEEP_CBCR (0x4102C)
61#define USB_HS_PHY_CFG_AHB_CBCR (0x41030)
62
63/* ETH controller clock control registers */
64#define ETH_PTP_CBCR (0x4e004)
65#define ETH_RGMII_CBCR (0x4e008)
66#define ETH_SLAVE_AHB_CBCR (0x4e00c)
67#define ETH_AXI_CBCR (0x4e010)
68#define EMAC_PTP_CMD_RCGR (0x4e014)
69#define EMAC_PTP_CFG_RCGR (0x4e018)
70#define EMAC_CMD_RCGR (0x4e01c)
Caleb Connollyc94f9e92023-11-07 12:41:03 +000071
Sumit Garga4a9d9e2022-07-12 12:42:11 +053072
73/* GPLL0 clock control registers */
74#define GPLL0_STATUS_ACTIVE BIT(31)
75
Sumit Garg71ffa232023-02-01 19:28:50 +053076#define CFG_CLK_SRC_GPLL1 BIT(8)
77#define GPLL1_STATUS_ACTIVE BIT(31)
78
Sumit Garga4a9d9e2022-07-12 12:42:11 +053079static struct vote_clk gcc_blsp1_ahb_clk = {
80 .cbcr_reg = BLSP1_AHB_CBCR,
81 .ena_vote = APCS_CLOCK_BRANCH_ENA_VOTE,
82 .vote_bit = BIT(10) | BIT(5) | BIT(4),
83};
84
Sumit Garga4a9d9e2022-07-12 12:42:11 +053085static struct pll_vote_clk gpll0_vote_clk = {
86 .status = GPLL0_STATUS,
87 .status_bit = GPLL0_STATUS_ACTIVE,
88 .ena_vote = APCS_GPLL_ENA_VOTE,
89 .vote_bit = BIT(0),
90};
91
Sumit Garg71ffa232023-02-01 19:28:50 +053092static struct pll_vote_clk gpll1_vote_clk = {
93 .status = GPLL1_STATUS,
94 .status_bit = GPLL1_STATUS_ACTIVE,
95 .ena_vote = APCS_GPLL_ENA_VOTE,
96 .vote_bit = BIT(1),
97};
98
Caleb Connollyc94f9e92023-11-07 12:41:03 +000099static ulong qcs404_clk_set_rate(struct clk *clk, ulong rate)
Sumit Garga4a9d9e2022-07-12 12:42:11 +0530100{
101 struct msm_clk_priv *priv = dev_get_priv(clk->dev);
102
103 switch (clk->id) {
104 case GCC_BLSP1_UART2_APPS_CLK:
105 /* UART: 115200 */
Caleb Connolly422b74b2023-11-21 17:55:53 +0000106 clk_rcg_set_rate_mnd(priv->base, BLSP1_UART2_APPS_CMD_RCGR, 0, 12, 125,
Caleb Connolly97d7ed32023-11-07 12:41:04 +0000107 CFG_CLK_SRC_CXO, 16);
Sumit Garga4a9d9e2022-07-12 12:42:11 +0530108 clk_enable_cbc(priv->base + BLSP1_UART2_APPS_CBCR);
109 break;
110 case GCC_BLSP1_AHB_CLK:
111 clk_enable_vote_clk(priv->base, &gcc_blsp1_ahb_clk);
112 break;
113 case GCC_SDCC1_APPS_CLK:
114 /* SDCC1: 200MHz */
Caleb Connolly422b74b2023-11-21 17:55:53 +0000115 clk_rcg_set_rate_mnd(priv->base, SDCC_CMD_RCGR(0), 7, 0, 0,
Caleb Connolly97d7ed32023-11-07 12:41:04 +0000116 CFG_CLK_SRC_GPLL0, 8);
Sumit Garga4a9d9e2022-07-12 12:42:11 +0530117 clk_enable_gpll0(priv->base, &gpll0_vote_clk);
118 clk_enable_cbc(priv->base + SDCC_APPS_CBCR(1));
119 break;
120 case GCC_SDCC1_AHB_CLK:
121 clk_enable_cbc(priv->base + SDCC_AHB_CBCR(1));
122 break;
Sumit Garg71ffa232023-02-01 19:28:50 +0530123 case GCC_ETH_RGMII_CLK:
124 if (rate == 250000000)
Caleb Connolly422b74b2023-11-21 17:55:53 +0000125 clk_rcg_set_rate_mnd(priv->base, EMAC_CMD_RCGR, 3, 0, 0,
Caleb Connolly97d7ed32023-11-07 12:41:04 +0000126 CFG_CLK_SRC_GPLL1, 8);
Sumit Garg71ffa232023-02-01 19:28:50 +0530127 else if (rate == 125000000)
Caleb Connolly422b74b2023-11-21 17:55:53 +0000128 clk_rcg_set_rate_mnd(priv->base, EMAC_CMD_RCGR, 7, 0, 0,
Caleb Connolly97d7ed32023-11-07 12:41:04 +0000129 CFG_CLK_SRC_GPLL1, 8);
Sumit Garg71ffa232023-02-01 19:28:50 +0530130 else if (rate == 50000000)
Caleb Connolly422b74b2023-11-21 17:55:53 +0000131 clk_rcg_set_rate_mnd(priv->base, EMAC_CMD_RCGR, 19, 0, 0,
Caleb Connolly97d7ed32023-11-07 12:41:04 +0000132 CFG_CLK_SRC_GPLL1, 8);
Sumit Garg71ffa232023-02-01 19:28:50 +0530133 else if (rate == 5000000)
Caleb Connolly422b74b2023-11-21 17:55:53 +0000134 clk_rcg_set_rate_mnd(priv->base, EMAC_CMD_RCGR, 3, 1, 50,
Caleb Connolly97d7ed32023-11-07 12:41:04 +0000135 CFG_CLK_SRC_GPLL1, 8);
Sumit Garg71ffa232023-02-01 19:28:50 +0530136 break;
Sumit Garga4a9d9e2022-07-12 12:42:11 +0530137 default:
138 return 0;
139 }
140
141 return 0;
142}
Sumit Gargc9e384e2022-08-04 19:57:14 +0530143
Caleb Connollyc94f9e92023-11-07 12:41:03 +0000144static int qcs404_clk_enable(struct clk *clk)
Sumit Gargc9e384e2022-08-04 19:57:14 +0530145{
Sumit Garg968597b2022-08-04 19:57:15 +0530146 struct msm_clk_priv *priv = dev_get_priv(clk->dev);
147
148 switch (clk->id) {
149 case GCC_USB30_MASTER_CLK:
150 clk_enable_cbc(priv->base + USB30_MASTER_CBCR);
Caleb Connolly422b74b2023-11-21 17:55:53 +0000151 clk_rcg_set_rate_mnd(priv->base, USB30_MASTER_CMD_RCGR, 7, 0, 0,
Caleb Connolly97d7ed32023-11-07 12:41:04 +0000152 CFG_CLK_SRC_GPLL0, 8);
Sumit Garg968597b2022-08-04 19:57:15 +0530153 break;
154 case GCC_SYS_NOC_USB3_CLK:
155 clk_enable_cbc(priv->base + SYS_NOC_USB3_CBCR);
156 break;
157 case GCC_USB30_SLEEP_CLK:
158 clk_enable_cbc(priv->base + USB30_SLEEP_CBCR);
159 break;
160 case GCC_USB30_MOCK_UTMI_CLK:
161 clk_enable_cbc(priv->base + USB30_MOCK_UTMI_CBCR);
162 break;
163 case GCC_USB_HS_PHY_CFG_AHB_CLK:
164 clk_enable_cbc(priv->base + USB_HS_PHY_CFG_AHB_CBCR);
165 break;
166 case GCC_USB2A_PHY_SLEEP_CLK:
167 clk_enable_cbc(priv->base + USB_HS_PHY_CFG_AHB_CBCR);
168 break;
Sumit Garg71ffa232023-02-01 19:28:50 +0530169 case GCC_ETH_PTP_CLK:
170 /* SPEED_1000: freq -> 250MHz */
171 clk_enable_cbc(priv->base + ETH_PTP_CBCR);
172 clk_enable_gpll0(priv->base, &gpll1_vote_clk);
Caleb Connolly422b74b2023-11-21 17:55:53 +0000173 clk_rcg_set_rate_mnd(priv->base, EMAC_PTP_CMD_RCGR, 3, 0, 0,
Caleb Connolly97d7ed32023-11-07 12:41:04 +0000174 CFG_CLK_SRC_GPLL1, 8);
Sumit Garg71ffa232023-02-01 19:28:50 +0530175 break;
176 case GCC_ETH_RGMII_CLK:
177 /* SPEED_1000: freq -> 250MHz */
178 clk_enable_cbc(priv->base + ETH_RGMII_CBCR);
179 clk_enable_gpll0(priv->base, &gpll1_vote_clk);
Caleb Connolly422b74b2023-11-21 17:55:53 +0000180 clk_rcg_set_rate_mnd(priv->base, EMAC_CMD_RCGR, 3, 0, 0,
Caleb Connolly97d7ed32023-11-07 12:41:04 +0000181 CFG_CLK_SRC_GPLL1, 8);
Sumit Garg71ffa232023-02-01 19:28:50 +0530182 break;
183 case GCC_ETH_SLAVE_AHB_CLK:
184 clk_enable_cbc(priv->base + ETH_SLAVE_AHB_CBCR);
185 break;
186 case GCC_ETH_AXI_CLK:
187 clk_enable_cbc(priv->base + ETH_AXI_CBCR);
188 break;
Sumit Gargb97487d2023-02-13 10:19:09 +0530189 case GCC_BLSP1_AHB_CLK:
190 clk_enable_vote_clk(priv->base, &gcc_blsp1_ahb_clk);
191 break;
192 case GCC_BLSP1_QUP0_I2C_APPS_CLK:
193 clk_enable_cbc(priv->base + BLSP1_QUP0_I2C_APPS_CBCR);
Caleb Connolly422b74b2023-11-21 17:55:53 +0000194 clk_rcg_set_rate(priv->base, BLSP1_QUP0_I2C_APPS_CMD_RCGR, 0,
Sumit Gargb97487d2023-02-13 10:19:09 +0530195 CFG_CLK_SRC_CXO);
196 break;
197 case GCC_BLSP1_QUP1_I2C_APPS_CLK:
198 clk_enable_cbc(priv->base + BLSP1_QUP1_I2C_APPS_CBCR);
Caleb Connolly422b74b2023-11-21 17:55:53 +0000199 clk_rcg_set_rate(priv->base, BLSP1_QUP1_I2C_APPS_CMD_RCGR, 0,
Sumit Gargb97487d2023-02-13 10:19:09 +0530200 CFG_CLK_SRC_CXO);
201 break;
202 case GCC_BLSP1_QUP2_I2C_APPS_CLK:
203 clk_enable_cbc(priv->base + BLSP1_QUP2_I2C_APPS_CBCR);
Caleb Connolly422b74b2023-11-21 17:55:53 +0000204 clk_rcg_set_rate(priv->base, BLSP1_QUP2_I2C_APPS_CMD_RCGR, 0,
Sumit Gargb97487d2023-02-13 10:19:09 +0530205 CFG_CLK_SRC_CXO);
206 break;
207 case GCC_BLSP1_QUP3_I2C_APPS_CLK:
208 clk_enable_cbc(priv->base + BLSP1_QUP3_I2C_APPS_CBCR);
Caleb Connolly422b74b2023-11-21 17:55:53 +0000209 clk_rcg_set_rate(priv->base, BLSP1_QUP3_I2C_APPS_CMD_RCGR, 0,
Sumit Gargb97487d2023-02-13 10:19:09 +0530210 CFG_CLK_SRC_CXO);
211 break;
212 case GCC_BLSP1_QUP4_I2C_APPS_CLK:
213 clk_enable_cbc(priv->base + BLSP1_QUP4_I2C_APPS_CBCR);
Caleb Connolly422b74b2023-11-21 17:55:53 +0000214 clk_rcg_set_rate(priv->base, BLSP1_QUP4_I2C_APPS_CMD_RCGR, 0,
Sumit Gargb97487d2023-02-13 10:19:09 +0530215 CFG_CLK_SRC_CXO);
216 break;
Sumit Garg968597b2022-08-04 19:57:15 +0530217 default:
218 return 0;
219 }
220
Sumit Gargc9e384e2022-08-04 19:57:14 +0530221 return 0;
222}
Konrad Dybciod9935732023-11-07 12:41:01 +0000223
224static const struct qcom_reset_map qcs404_gcc_resets[] = {
225 [GCC_GENI_IR_BCR] = { 0x0F000 },
226 [GCC_CDSP_RESTART] = { 0x18000 },
227 [GCC_USB_HS_BCR] = { 0x41000 },
228 [GCC_USB2_HS_PHY_ONLY_BCR] = { 0x41034 },
229 [GCC_QUSB2_PHY_BCR] = { 0x4103c },
230 [GCC_USB_HS_PHY_CFG_AHB_BCR] = { 0x0000c, 1 },
231 [GCC_USB2A_PHY_BCR] = { 0x0000c, 0 },
232 [GCC_USB3_PHY_BCR] = { 0x39004 },
233 [GCC_USB_30_BCR] = { 0x39000 },
234 [GCC_USB3PHY_PHY_BCR] = { 0x39008 },
235 [GCC_PCIE_0_BCR] = { 0x3e000 },
236 [GCC_PCIE_0_PHY_BCR] = { 0x3e004 },
237 [GCC_PCIE_0_LINK_DOWN_BCR] = { 0x3e038 },
238 [GCC_PCIEPHY_0_PHY_BCR] = { 0x3e03c },
239 [GCC_PCIE_0_AXI_MASTER_STICKY_ARES] = { 0x3e040, 6},
240 [GCC_PCIE_0_AHB_ARES] = { 0x3e040, 5 },
241 [GCC_PCIE_0_AXI_SLAVE_ARES] = { 0x3e040, 4 },
242 [GCC_PCIE_0_AXI_MASTER_ARES] = { 0x3e040, 3 },
243 [GCC_PCIE_0_CORE_STICKY_ARES] = { 0x3e040, 2 },
244 [GCC_PCIE_0_SLEEP_ARES] = { 0x3e040, 1 },
245 [GCC_PCIE_0_PIPE_ARES] = { 0x3e040, 0 },
246 [GCC_EMAC_BCR] = { 0x4e000 },
247 [GCC_WDSP_RESTART] = {0x19000},
248};
249
Caleb Connollyc94f9e92023-11-07 12:41:03 +0000250static const struct msm_clk_data qcs404_clk_gcc_data = {
Konrad Dybciod9935732023-11-07 12:41:01 +0000251 .resets = qcs404_gcc_resets,
252 .num_resets = ARRAY_SIZE(qcs404_gcc_resets),
Caleb Connollyc94f9e92023-11-07 12:41:03 +0000253 .enable = qcs404_clk_enable,
254 .set_rate = qcs404_clk_set_rate,
Konrad Dybciod9935732023-11-07 12:41:01 +0000255};
256
257static const struct udevice_id gcc_qcs404_of_match[] = {
258 {
259 .compatible = "qcom,gcc-qcs404",
Caleb Connollyc94f9e92023-11-07 12:41:03 +0000260 .data = (ulong)&qcs404_clk_gcc_data
Konrad Dybciod9935732023-11-07 12:41:01 +0000261 },
262 { }
263};
264
265U_BOOT_DRIVER(gcc_qcs404) = {
266 .name = "gcc_qcs404",
267 .id = UCLASS_NOP,
268 .of_match = gcc_qcs404_of_match,
269 .bind = qcom_cc_bind,
270 .flags = DM_FLAG_PRE_RELOC,
271};