blob: 70a1f648e585920ff781362e65bd28e17aca62f3 [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
Sumit Garga4a9d9e2022-07-12 12:42:11 +05308#include <clk-uclass.h>
9#include <dm.h>
10#include <errno.h>
11#include <asm/io.h>
12#include <linux/bitops.h>
Konrad Dybcio3ead6612023-11-07 12:41:01 +000013#include <dt-bindings/clock/qcom,gcc-qcs404.h>
14
Caleb Connollya623c142023-11-07 12:40:59 +000015#include "clock-qcom.h"
Sumit Garga4a9d9e2022-07-12 12:42:11 +053016
Caleb Connolly37ea1342023-11-07 12:41:03 +000017/* Clocks: (from CLK_CTL_BASE) */
18#define GPLL0_STATUS (0x21000)
19#define GPLL1_STATUS (0x20000)
20#define APCS_GPLL_ENA_VOTE (0x45000)
21#define APCS_CLOCK_BRANCH_ENA_VOTE (0x45004)
22
23/* BLSP1 AHB clock (root clock for BLSP) */
24#define BLSP1_AHB_CBCR 0x1008
25
26/* Uart clock control registers */
27#define BLSP1_UART2_BCR (0x3028)
28#define BLSP1_UART2_APPS_CBCR (0x302C)
29#define BLSP1_UART2_APPS_CMD_RCGR (0x3034)
Caleb Connolly37ea1342023-11-07 12:41:03 +000030
31/* I2C controller clock control registerss */
32#define BLSP1_QUP0_I2C_APPS_CBCR (0x6028)
33#define BLSP1_QUP0_I2C_APPS_CMD_RCGR (0x602C)
Caleb Connolly37ea1342023-11-07 12:41:03 +000034#define BLSP1_QUP1_I2C_APPS_CBCR (0x2008)
35#define BLSP1_QUP1_I2C_APPS_CMD_RCGR (0x200C)
Caleb Connolly37ea1342023-11-07 12:41:03 +000036#define BLSP1_QUP2_I2C_APPS_CBCR (0x3010)
37#define BLSP1_QUP2_I2C_APPS_CMD_RCGR (0x3000)
Caleb Connolly37ea1342023-11-07 12:41:03 +000038#define BLSP1_QUP3_I2C_APPS_CBCR (0x4020)
39#define BLSP1_QUP3_I2C_APPS_CMD_RCGR (0x4000)
Caleb Connolly37ea1342023-11-07 12:41:03 +000040#define BLSP1_QUP4_I2C_APPS_CBCR (0x5020)
41#define BLSP1_QUP4_I2C_APPS_CMD_RCGR (0x5000)
Caleb Connolly37ea1342023-11-07 12:41:03 +000042
43/* SD controller clock control registers */
44#define SDCC_BCR(n) (((n) * 0x1000) + 0x41000)
Caleb Connollyd33d4e02024-04-03 14:07:40 +020045#define SDCC_CMD_RCGR(n) (((n + 1) * 0x1000) + 0x41004)
Caleb Connolly37ea1342023-11-07 12:41:03 +000046#define SDCC_APPS_CBCR(n) (((n) * 0x1000) + 0x41018)
47#define SDCC_AHB_CBCR(n) (((n) * 0x1000) + 0x4101C)
48
49/* USB-3.0 controller clock control registers */
50#define SYS_NOC_USB3_CBCR (0x26014)
51#define USB30_BCR (0x39000)
52#define USB3PHY_BCR (0x39008)
53#define USB30_MASTER_CBCR (0x3900C)
54#define USB30_SLEEP_CBCR (0x39010)
55#define USB30_MOCK_UTMI_CBCR (0x39014)
56#define USB30_MOCK_UTMI_CMD_RCGR (0x3901C)
57#define USB30_MOCK_UTMI_CFG_RCGR (0x39020)
58#define USB30_MASTER_CMD_RCGR (0x39028)
Caleb Connolly37ea1342023-11-07 12:41:03 +000059#define USB2A_PHY_SLEEP_CBCR (0x4102C)
60#define USB_HS_PHY_CFG_AHB_CBCR (0x41030)
61
62/* ETH controller clock control registers */
63#define ETH_PTP_CBCR (0x4e004)
64#define ETH_RGMII_CBCR (0x4e008)
65#define ETH_SLAVE_AHB_CBCR (0x4e00c)
66#define ETH_AXI_CBCR (0x4e010)
67#define EMAC_PTP_CMD_RCGR (0x4e014)
Caleb Connolly37ea1342023-11-07 12:41:03 +000068#define EMAC_CMD_RCGR (0x4e01c)
Caleb Connolly37ea1342023-11-07 12:41:03 +000069
Sumit Garga4a9d9e2022-07-12 12:42:11 +053070
71/* GPLL0 clock control registers */
72#define GPLL0_STATUS_ACTIVE BIT(31)
73
Sumit Garg71ffa232023-02-01 19:28:50 +053074#define CFG_CLK_SRC_GPLL1 BIT(8)
75#define GPLL1_STATUS_ACTIVE BIT(31)
76
Sumit Garga4a9d9e2022-07-12 12:42:11 +053077static struct vote_clk gcc_blsp1_ahb_clk = {
78 .cbcr_reg = BLSP1_AHB_CBCR,
79 .ena_vote = APCS_CLOCK_BRANCH_ENA_VOTE,
80 .vote_bit = BIT(10) | BIT(5) | BIT(4),
81};
82
Sumit Garga4a9d9e2022-07-12 12:42:11 +053083static struct pll_vote_clk gpll0_vote_clk = {
84 .status = GPLL0_STATUS,
85 .status_bit = GPLL0_STATUS_ACTIVE,
86 .ena_vote = APCS_GPLL_ENA_VOTE,
87 .vote_bit = BIT(0),
88};
89
Sumit Garg71ffa232023-02-01 19:28:50 +053090static struct pll_vote_clk gpll1_vote_clk = {
91 .status = GPLL1_STATUS,
92 .status_bit = GPLL1_STATUS_ACTIVE,
93 .ena_vote = APCS_GPLL_ENA_VOTE,
94 .vote_bit = BIT(1),
95};
96
Caleb Connolly37ea1342023-11-07 12:41:03 +000097static ulong qcs404_clk_set_rate(struct clk *clk, ulong rate)
Sumit Garga4a9d9e2022-07-12 12:42:11 +053098{
99 struct msm_clk_priv *priv = dev_get_priv(clk->dev);
100
101 switch (clk->id) {
102 case GCC_BLSP1_UART2_APPS_CLK:
Caleb Connolly641237b2024-02-26 17:26:10 +0000103 /* UART: 1843200Hz for a fixed 115200 baudrate (19200000 * (12/125)) */
Caleb Connollyd33d4e02024-04-03 14:07:40 +0200104 clk_rcg_set_rate_mnd(priv->base, BLSP1_UART2_APPS_CMD_RCGR, 0, 12, 125,
Caleb Connolly6acc4432023-11-07 12:41:04 +0000105 CFG_CLK_SRC_CXO, 16);
Sumit Garga4a9d9e2022-07-12 12:42:11 +0530106 clk_enable_cbc(priv->base + BLSP1_UART2_APPS_CBCR);
Caleb Connolly641237b2024-02-26 17:26:10 +0000107 return 1843200;
Sumit Garga4a9d9e2022-07-12 12:42:11 +0530108 case GCC_SDCC1_APPS_CLK:
109 /* SDCC1: 200MHz */
Caleb Connollyd33d4e02024-04-03 14:07:40 +0200110 clk_rcg_set_rate_mnd(priv->base, SDCC_CMD_RCGR(0), 7, 0, 0,
Caleb Connolly6acc4432023-11-07 12:41:04 +0000111 CFG_CLK_SRC_GPLL0, 8);
Sumit Garga4a9d9e2022-07-12 12:42:11 +0530112 clk_enable_gpll0(priv->base, &gpll0_vote_clk);
113 clk_enable_cbc(priv->base + SDCC_APPS_CBCR(1));
Caleb Connolly641237b2024-02-26 17:26:10 +0000114 return rate;
Sumit Garg71ffa232023-02-01 19:28:50 +0530115 case GCC_ETH_RGMII_CLK:
116 if (rate == 250000000)
Caleb Connollyd33d4e02024-04-03 14:07:40 +0200117 clk_rcg_set_rate_mnd(priv->base, EMAC_CMD_RCGR, 3, 0, 0,
Caleb Connolly6acc4432023-11-07 12:41:04 +0000118 CFG_CLK_SRC_GPLL1, 8);
Sumit Garg71ffa232023-02-01 19:28:50 +0530119 else if (rate == 125000000)
Caleb Connollyd33d4e02024-04-03 14:07:40 +0200120 clk_rcg_set_rate_mnd(priv->base, EMAC_CMD_RCGR, 7, 0, 0,
Caleb Connolly6acc4432023-11-07 12:41:04 +0000121 CFG_CLK_SRC_GPLL1, 8);
Sumit Garg71ffa232023-02-01 19:28:50 +0530122 else if (rate == 50000000)
Caleb Connollyd33d4e02024-04-03 14:07:40 +0200123 clk_rcg_set_rate_mnd(priv->base, EMAC_CMD_RCGR, 19, 0, 0,
Caleb Connolly6acc4432023-11-07 12:41:04 +0000124 CFG_CLK_SRC_GPLL1, 8);
Sumit Garg71ffa232023-02-01 19:28:50 +0530125 else if (rate == 5000000)
Caleb Connollyd33d4e02024-04-03 14:07:40 +0200126 clk_rcg_set_rate_mnd(priv->base, EMAC_CMD_RCGR, 3, 1, 50,
Caleb Connolly6acc4432023-11-07 12:41:04 +0000127 CFG_CLK_SRC_GPLL1, 8);
Caleb Connolly641237b2024-02-26 17:26:10 +0000128 return rate;
Sumit Garga4a9d9e2022-07-12 12:42:11 +0530129 }
130
Caleb Connolly641237b2024-02-26 17:26:10 +0000131 /* There is a bug only seeming to affect this board where the MMC driver somehow calls
132 * clk_set_rate() on a clock with id 0 which is associated with the qcom_clk device.
133 * The only clock with ID 0 is the xo_board clock which should not be associated with
134 * this device...
135 */
136 log_debug("Unknown clock id %ld\n", clk->id);
Sumit Garga4a9d9e2022-07-12 12:42:11 +0530137 return 0;
138}
Sumit Gargc9e384e2022-08-04 19:57:14 +0530139
Caleb Connolly37ea1342023-11-07 12:41:03 +0000140static int qcs404_clk_enable(struct clk *clk)
Sumit Gargc9e384e2022-08-04 19:57:14 +0530141{
Sumit Garg968597b2022-08-04 19:57:15 +0530142 struct msm_clk_priv *priv = dev_get_priv(clk->dev);
143
144 switch (clk->id) {
145 case GCC_USB30_MASTER_CLK:
146 clk_enable_cbc(priv->base + USB30_MASTER_CBCR);
Caleb Connollyd33d4e02024-04-03 14:07:40 +0200147 clk_rcg_set_rate_mnd(priv->base, USB30_MASTER_CMD_RCGR, 7, 0, 0,
Caleb Connolly6acc4432023-11-07 12:41:04 +0000148 CFG_CLK_SRC_GPLL0, 8);
Sumit Garg968597b2022-08-04 19:57:15 +0530149 break;
150 case GCC_SYS_NOC_USB3_CLK:
151 clk_enable_cbc(priv->base + SYS_NOC_USB3_CBCR);
152 break;
153 case GCC_USB30_SLEEP_CLK:
154 clk_enable_cbc(priv->base + USB30_SLEEP_CBCR);
155 break;
156 case GCC_USB30_MOCK_UTMI_CLK:
157 clk_enable_cbc(priv->base + USB30_MOCK_UTMI_CBCR);
158 break;
159 case GCC_USB_HS_PHY_CFG_AHB_CLK:
160 clk_enable_cbc(priv->base + USB_HS_PHY_CFG_AHB_CBCR);
161 break;
162 case GCC_USB2A_PHY_SLEEP_CLK:
163 clk_enable_cbc(priv->base + USB_HS_PHY_CFG_AHB_CBCR);
164 break;
Sumit Garg71ffa232023-02-01 19:28:50 +0530165 case GCC_ETH_PTP_CLK:
166 /* SPEED_1000: freq -> 250MHz */
167 clk_enable_cbc(priv->base + ETH_PTP_CBCR);
168 clk_enable_gpll0(priv->base, &gpll1_vote_clk);
Caleb Connollyd33d4e02024-04-03 14:07:40 +0200169 clk_rcg_set_rate_mnd(priv->base, EMAC_PTP_CMD_RCGR, 3, 0, 0,
Caleb Connolly6acc4432023-11-07 12:41:04 +0000170 CFG_CLK_SRC_GPLL1, 8);
Sumit Garg71ffa232023-02-01 19:28:50 +0530171 break;
172 case GCC_ETH_RGMII_CLK:
173 /* SPEED_1000: freq -> 250MHz */
174 clk_enable_cbc(priv->base + ETH_RGMII_CBCR);
175 clk_enable_gpll0(priv->base, &gpll1_vote_clk);
Caleb Connollyd33d4e02024-04-03 14:07:40 +0200176 clk_rcg_set_rate_mnd(priv->base, EMAC_CMD_RCGR, 3, 0, 0,
Caleb Connolly6acc4432023-11-07 12:41:04 +0000177 CFG_CLK_SRC_GPLL1, 8);
Sumit Garg71ffa232023-02-01 19:28:50 +0530178 break;
179 case GCC_ETH_SLAVE_AHB_CLK:
180 clk_enable_cbc(priv->base + ETH_SLAVE_AHB_CBCR);
181 break;
182 case GCC_ETH_AXI_CLK:
183 clk_enable_cbc(priv->base + ETH_AXI_CBCR);
184 break;
Sumit Gargb97487d2023-02-13 10:19:09 +0530185 case GCC_BLSP1_AHB_CLK:
186 clk_enable_vote_clk(priv->base, &gcc_blsp1_ahb_clk);
187 break;
188 case GCC_BLSP1_QUP0_I2C_APPS_CLK:
189 clk_enable_cbc(priv->base + BLSP1_QUP0_I2C_APPS_CBCR);
Caleb Connollyd33d4e02024-04-03 14:07:40 +0200190 clk_rcg_set_rate(priv->base, BLSP1_QUP0_I2C_APPS_CMD_RCGR, 0,
Sumit Gargb97487d2023-02-13 10:19:09 +0530191 CFG_CLK_SRC_CXO);
192 break;
193 case GCC_BLSP1_QUP1_I2C_APPS_CLK:
194 clk_enable_cbc(priv->base + BLSP1_QUP1_I2C_APPS_CBCR);
Caleb Connollyd33d4e02024-04-03 14:07:40 +0200195 clk_rcg_set_rate(priv->base, BLSP1_QUP1_I2C_APPS_CMD_RCGR, 0,
Sumit Gargb97487d2023-02-13 10:19:09 +0530196 CFG_CLK_SRC_CXO);
197 break;
198 case GCC_BLSP1_QUP2_I2C_APPS_CLK:
199 clk_enable_cbc(priv->base + BLSP1_QUP2_I2C_APPS_CBCR);
Caleb Connollyd33d4e02024-04-03 14:07:40 +0200200 clk_rcg_set_rate(priv->base, BLSP1_QUP2_I2C_APPS_CMD_RCGR, 0,
Sumit Gargb97487d2023-02-13 10:19:09 +0530201 CFG_CLK_SRC_CXO);
202 break;
203 case GCC_BLSP1_QUP3_I2C_APPS_CLK:
204 clk_enable_cbc(priv->base + BLSP1_QUP3_I2C_APPS_CBCR);
Caleb Connollyd33d4e02024-04-03 14:07:40 +0200205 clk_rcg_set_rate(priv->base, BLSP1_QUP3_I2C_APPS_CMD_RCGR, 0,
Sumit Gargb97487d2023-02-13 10:19:09 +0530206 CFG_CLK_SRC_CXO);
207 break;
208 case GCC_BLSP1_QUP4_I2C_APPS_CLK:
209 clk_enable_cbc(priv->base + BLSP1_QUP4_I2C_APPS_CBCR);
Caleb Connollyd33d4e02024-04-03 14:07:40 +0200210 clk_rcg_set_rate(priv->base, BLSP1_QUP4_I2C_APPS_CMD_RCGR, 0,
Sumit Gargb97487d2023-02-13 10:19:09 +0530211 CFG_CLK_SRC_CXO);
212 break;
Caleb Connolly641237b2024-02-26 17:26:10 +0000213 case GCC_SDCC1_AHB_CLK:
214 clk_enable_cbc(priv->base + SDCC_AHB_CBCR(1));
215 break;
Sumit Garg968597b2022-08-04 19:57:15 +0530216 default:
217 return 0;
218 }
219
Sumit Gargc9e384e2022-08-04 19:57:14 +0530220 return 0;
221}
Konrad Dybcio3ead6612023-11-07 12:41:01 +0000222
223static const struct qcom_reset_map qcs404_gcc_resets[] = {
224 [GCC_GENI_IR_BCR] = { 0x0F000 },
225 [GCC_CDSP_RESTART] = { 0x18000 },
226 [GCC_USB_HS_BCR] = { 0x41000 },
227 [GCC_USB2_HS_PHY_ONLY_BCR] = { 0x41034 },
228 [GCC_QUSB2_PHY_BCR] = { 0x4103c },
229 [GCC_USB_HS_PHY_CFG_AHB_BCR] = { 0x0000c, 1 },
230 [GCC_USB2A_PHY_BCR] = { 0x0000c, 0 },
231 [GCC_USB3_PHY_BCR] = { 0x39004 },
232 [GCC_USB_30_BCR] = { 0x39000 },
233 [GCC_USB3PHY_PHY_BCR] = { 0x39008 },
234 [GCC_PCIE_0_BCR] = { 0x3e000 },
235 [GCC_PCIE_0_PHY_BCR] = { 0x3e004 },
236 [GCC_PCIE_0_LINK_DOWN_BCR] = { 0x3e038 },
237 [GCC_PCIEPHY_0_PHY_BCR] = { 0x3e03c },
238 [GCC_PCIE_0_AXI_MASTER_STICKY_ARES] = { 0x3e040, 6},
239 [GCC_PCIE_0_AHB_ARES] = { 0x3e040, 5 },
240 [GCC_PCIE_0_AXI_SLAVE_ARES] = { 0x3e040, 4 },
241 [GCC_PCIE_0_AXI_MASTER_ARES] = { 0x3e040, 3 },
242 [GCC_PCIE_0_CORE_STICKY_ARES] = { 0x3e040, 2 },
243 [GCC_PCIE_0_SLEEP_ARES] = { 0x3e040, 1 },
244 [GCC_PCIE_0_PIPE_ARES] = { 0x3e040, 0 },
245 [GCC_EMAC_BCR] = { 0x4e000 },
246 [GCC_WDSP_RESTART] = {0x19000},
247};
248
Caleb Connolly37ea1342023-11-07 12:41:03 +0000249static const struct msm_clk_data qcs404_clk_gcc_data = {
Konrad Dybcio3ead6612023-11-07 12:41:01 +0000250 .resets = qcs404_gcc_resets,
251 .num_resets = ARRAY_SIZE(qcs404_gcc_resets),
Caleb Connolly37ea1342023-11-07 12:41:03 +0000252 .enable = qcs404_clk_enable,
253 .set_rate = qcs404_clk_set_rate,
Konrad Dybcio3ead6612023-11-07 12:41:01 +0000254};
255
256static const struct udevice_id gcc_qcs404_of_match[] = {
257 {
258 .compatible = "qcom,gcc-qcs404",
Caleb Connolly37ea1342023-11-07 12:41:03 +0000259 .data = (ulong)&qcs404_clk_gcc_data
Konrad Dybcio3ead6612023-11-07 12:41:01 +0000260 },
261 { }
262};
263
264U_BOOT_DRIVER(gcc_qcs404) = {
265 .name = "gcc_qcs404",
266 .id = UCLASS_NOP,
267 .of_match = gcc_qcs404_of_match,
268 .bind = qcom_cc_bind,
269 .flags = DM_FLAG_PRE_RELOC,
270};