blob: 8b11de03a7d9935a06fc0a4b85d025a450cbfe3c [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
Sumit Garge6a488b2022-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 Dybcio6c0b8442023-11-07 12:41:01 +000013#include <dt-bindings/clock/qcom,gcc-qcs404.h>
14
Caleb Connolly878b26a2023-11-07 12:40:59 +000015#include "clock-qcom.h"
Sumit Garge6a488b2022-07-12 12:42:11 +053016
Caleb Connolly10a0abb2023-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 Connolly10a0abb2023-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 Connolly10a0abb2023-11-07 12:41:03 +000034#define BLSP1_QUP1_I2C_APPS_CBCR (0x2008)
35#define BLSP1_QUP1_I2C_APPS_CMD_RCGR (0x200C)
Caleb Connolly10a0abb2023-11-07 12:41:03 +000036#define BLSP1_QUP2_I2C_APPS_CBCR (0x3010)
37#define BLSP1_QUP2_I2C_APPS_CMD_RCGR (0x3000)
Caleb Connolly10a0abb2023-11-07 12:41:03 +000038#define BLSP1_QUP3_I2C_APPS_CBCR (0x4020)
39#define BLSP1_QUP3_I2C_APPS_CMD_RCGR (0x4000)
Caleb Connolly10a0abb2023-11-07 12:41:03 +000040#define BLSP1_QUP4_I2C_APPS_CBCR (0x5020)
41#define BLSP1_QUP4_I2C_APPS_CMD_RCGR (0x5000)
Caleb Connolly10a0abb2023-11-07 12:41:03 +000042
43/* SD controller clock control registers */
44#define SDCC_BCR(n) (((n) * 0x1000) + 0x41000)
Caleb Connollycbdad442024-04-03 14:07:40 +020045#define SDCC_CMD_RCGR(n) (((n + 1) * 0x1000) + 0x41004)
Caleb Connolly10a0abb2023-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 Connolly10a0abb2023-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 Connolly10a0abb2023-11-07 12:41:03 +000068#define EMAC_CMD_RCGR (0x4e01c)
Caleb Connolly10a0abb2023-11-07 12:41:03 +000069
Sumit Garge6a488b2022-07-12 12:42:11 +053070/* GPLL0 clock control registers */
71#define GPLL0_STATUS_ACTIVE BIT(31)
72
Sumit Garge9e62342023-02-01 19:28:50 +053073#define CFG_CLK_SRC_GPLL1 BIT(8)
74#define GPLL1_STATUS_ACTIVE BIT(31)
75
Sumit Garge6a488b2022-07-12 12:42:11 +053076static struct vote_clk gcc_blsp1_ahb_clk = {
77 .cbcr_reg = BLSP1_AHB_CBCR,
78 .ena_vote = APCS_CLOCK_BRANCH_ENA_VOTE,
79 .vote_bit = BIT(10) | BIT(5) | BIT(4),
80};
81
Sumit Garge6a488b2022-07-12 12:42:11 +053082static struct pll_vote_clk gpll0_vote_clk = {
83 .status = GPLL0_STATUS,
84 .status_bit = GPLL0_STATUS_ACTIVE,
85 .ena_vote = APCS_GPLL_ENA_VOTE,
86 .vote_bit = BIT(0),
87};
88
Sumit Garge9e62342023-02-01 19:28:50 +053089static struct pll_vote_clk gpll1_vote_clk = {
90 .status = GPLL1_STATUS,
91 .status_bit = GPLL1_STATUS_ACTIVE,
92 .ena_vote = APCS_GPLL_ENA_VOTE,
93 .vote_bit = BIT(1),
94};
95
Caleb Connolly10a0abb2023-11-07 12:41:03 +000096static ulong qcs404_clk_set_rate(struct clk *clk, ulong rate)
Sumit Garge6a488b2022-07-12 12:42:11 +053097{
98 struct msm_clk_priv *priv = dev_get_priv(clk->dev);
99
100 switch (clk->id) {
101 case GCC_BLSP1_UART2_APPS_CLK:
Caleb Connollyd718e3e2024-02-26 17:26:10 +0000102 /* UART: 1843200Hz for a fixed 115200 baudrate (19200000 * (12/125)) */
Caleb Connollycbdad442024-04-03 14:07:40 +0200103 clk_rcg_set_rate_mnd(priv->base, BLSP1_UART2_APPS_CMD_RCGR, 0, 12, 125,
Caleb Connollyfbacc672023-11-07 12:41:04 +0000104 CFG_CLK_SRC_CXO, 16);
Sumit Garge6a488b2022-07-12 12:42:11 +0530105 clk_enable_cbc(priv->base + BLSP1_UART2_APPS_CBCR);
Caleb Connollyd718e3e2024-02-26 17:26:10 +0000106 return 1843200;
Sumit Garge6a488b2022-07-12 12:42:11 +0530107 case GCC_SDCC1_APPS_CLK:
108 /* SDCC1: 200MHz */
Caleb Connollycbdad442024-04-03 14:07:40 +0200109 clk_rcg_set_rate_mnd(priv->base, SDCC_CMD_RCGR(0), 7, 0, 0,
Caleb Connollyfbacc672023-11-07 12:41:04 +0000110 CFG_CLK_SRC_GPLL0, 8);
Sumit Garge6a488b2022-07-12 12:42:11 +0530111 clk_enable_gpll0(priv->base, &gpll0_vote_clk);
112 clk_enable_cbc(priv->base + SDCC_APPS_CBCR(1));
Caleb Connollyd718e3e2024-02-26 17:26:10 +0000113 return rate;
Sumit Garge9e62342023-02-01 19:28:50 +0530114 case GCC_ETH_RGMII_CLK:
115 if (rate == 250000000)
Caleb Connollycbdad442024-04-03 14:07:40 +0200116 clk_rcg_set_rate_mnd(priv->base, EMAC_CMD_RCGR, 3, 0, 0,
Caleb Connollyfbacc672023-11-07 12:41:04 +0000117 CFG_CLK_SRC_GPLL1, 8);
Sumit Garge9e62342023-02-01 19:28:50 +0530118 else if (rate == 125000000)
Caleb Connollycbdad442024-04-03 14:07:40 +0200119 clk_rcg_set_rate_mnd(priv->base, EMAC_CMD_RCGR, 7, 0, 0,
Caleb Connollyfbacc672023-11-07 12:41:04 +0000120 CFG_CLK_SRC_GPLL1, 8);
Sumit Garge9e62342023-02-01 19:28:50 +0530121 else if (rate == 50000000)
Caleb Connollycbdad442024-04-03 14:07:40 +0200122 clk_rcg_set_rate_mnd(priv->base, EMAC_CMD_RCGR, 19, 0, 0,
Caleb Connollyfbacc672023-11-07 12:41:04 +0000123 CFG_CLK_SRC_GPLL1, 8);
Sumit Garge9e62342023-02-01 19:28:50 +0530124 else if (rate == 5000000)
Caleb Connollycbdad442024-04-03 14:07:40 +0200125 clk_rcg_set_rate_mnd(priv->base, EMAC_CMD_RCGR, 3, 1, 50,
Caleb Connollyfbacc672023-11-07 12:41:04 +0000126 CFG_CLK_SRC_GPLL1, 8);
Caleb Connollyd718e3e2024-02-26 17:26:10 +0000127 return rate;
Sumit Garge6a488b2022-07-12 12:42:11 +0530128 }
129
Caleb Connollyd718e3e2024-02-26 17:26:10 +0000130 /* There is a bug only seeming to affect this board where the MMC driver somehow calls
131 * clk_set_rate() on a clock with id 0 which is associated with the qcom_clk device.
132 * The only clock with ID 0 is the xo_board clock which should not be associated with
133 * this device...
134 */
135 log_debug("Unknown clock id %ld\n", clk->id);
Sumit Garge6a488b2022-07-12 12:42:11 +0530136 return 0;
137}
Sumit Garg1d1ca6e2022-08-04 19:57:14 +0530138
Caleb Connolly10a0abb2023-11-07 12:41:03 +0000139static int qcs404_clk_enable(struct clk *clk)
Sumit Garg1d1ca6e2022-08-04 19:57:14 +0530140{
Sumit Garg3018e522022-08-04 19:57:15 +0530141 struct msm_clk_priv *priv = dev_get_priv(clk->dev);
142
143 switch (clk->id) {
144 case GCC_USB30_MASTER_CLK:
145 clk_enable_cbc(priv->base + USB30_MASTER_CBCR);
Caleb Connollycbdad442024-04-03 14:07:40 +0200146 clk_rcg_set_rate_mnd(priv->base, USB30_MASTER_CMD_RCGR, 7, 0, 0,
Caleb Connollyfbacc672023-11-07 12:41:04 +0000147 CFG_CLK_SRC_GPLL0, 8);
Sumit Garg3018e522022-08-04 19:57:15 +0530148 break;
149 case GCC_SYS_NOC_USB3_CLK:
150 clk_enable_cbc(priv->base + SYS_NOC_USB3_CBCR);
151 break;
152 case GCC_USB30_SLEEP_CLK:
153 clk_enable_cbc(priv->base + USB30_SLEEP_CBCR);
154 break;
155 case GCC_USB30_MOCK_UTMI_CLK:
156 clk_enable_cbc(priv->base + USB30_MOCK_UTMI_CBCR);
157 break;
158 case GCC_USB_HS_PHY_CFG_AHB_CLK:
159 clk_enable_cbc(priv->base + USB_HS_PHY_CFG_AHB_CBCR);
160 break;
161 case GCC_USB2A_PHY_SLEEP_CLK:
162 clk_enable_cbc(priv->base + USB_HS_PHY_CFG_AHB_CBCR);
163 break;
Sumit Garge9e62342023-02-01 19:28:50 +0530164 case GCC_ETH_PTP_CLK:
165 /* SPEED_1000: freq -> 250MHz */
166 clk_enable_cbc(priv->base + ETH_PTP_CBCR);
167 clk_enable_gpll0(priv->base, &gpll1_vote_clk);
Caleb Connollycbdad442024-04-03 14:07:40 +0200168 clk_rcg_set_rate_mnd(priv->base, EMAC_PTP_CMD_RCGR, 3, 0, 0,
Caleb Connollyfbacc672023-11-07 12:41:04 +0000169 CFG_CLK_SRC_GPLL1, 8);
Sumit Garge9e62342023-02-01 19:28:50 +0530170 break;
171 case GCC_ETH_RGMII_CLK:
172 /* SPEED_1000: freq -> 250MHz */
173 clk_enable_cbc(priv->base + ETH_RGMII_CBCR);
174 clk_enable_gpll0(priv->base, &gpll1_vote_clk);
Caleb Connollycbdad442024-04-03 14:07:40 +0200175 clk_rcg_set_rate_mnd(priv->base, EMAC_CMD_RCGR, 3, 0, 0,
Caleb Connollyfbacc672023-11-07 12:41:04 +0000176 CFG_CLK_SRC_GPLL1, 8);
Sumit Garge9e62342023-02-01 19:28:50 +0530177 break;
178 case GCC_ETH_SLAVE_AHB_CLK:
179 clk_enable_cbc(priv->base + ETH_SLAVE_AHB_CBCR);
180 break;
181 case GCC_ETH_AXI_CLK:
182 clk_enable_cbc(priv->base + ETH_AXI_CBCR);
183 break;
Sumit Garg89e0dff2023-02-13 10:19:09 +0530184 case GCC_BLSP1_AHB_CLK:
185 clk_enable_vote_clk(priv->base, &gcc_blsp1_ahb_clk);
186 break;
187 case GCC_BLSP1_QUP0_I2C_APPS_CLK:
188 clk_enable_cbc(priv->base + BLSP1_QUP0_I2C_APPS_CBCR);
Caleb Connollycbdad442024-04-03 14:07:40 +0200189 clk_rcg_set_rate(priv->base, BLSP1_QUP0_I2C_APPS_CMD_RCGR, 0,
Sumit Garg89e0dff2023-02-13 10:19:09 +0530190 CFG_CLK_SRC_CXO);
191 break;
192 case GCC_BLSP1_QUP1_I2C_APPS_CLK:
193 clk_enable_cbc(priv->base + BLSP1_QUP1_I2C_APPS_CBCR);
Caleb Connollycbdad442024-04-03 14:07:40 +0200194 clk_rcg_set_rate(priv->base, BLSP1_QUP1_I2C_APPS_CMD_RCGR, 0,
Sumit Garg89e0dff2023-02-13 10:19:09 +0530195 CFG_CLK_SRC_CXO);
196 break;
197 case GCC_BLSP1_QUP2_I2C_APPS_CLK:
198 clk_enable_cbc(priv->base + BLSP1_QUP2_I2C_APPS_CBCR);
Caleb Connollycbdad442024-04-03 14:07:40 +0200199 clk_rcg_set_rate(priv->base, BLSP1_QUP2_I2C_APPS_CMD_RCGR, 0,
Sumit Garg89e0dff2023-02-13 10:19:09 +0530200 CFG_CLK_SRC_CXO);
201 break;
202 case GCC_BLSP1_QUP3_I2C_APPS_CLK:
203 clk_enable_cbc(priv->base + BLSP1_QUP3_I2C_APPS_CBCR);
Caleb Connollycbdad442024-04-03 14:07:40 +0200204 clk_rcg_set_rate(priv->base, BLSP1_QUP3_I2C_APPS_CMD_RCGR, 0,
Sumit Garg89e0dff2023-02-13 10:19:09 +0530205 CFG_CLK_SRC_CXO);
206 break;
207 case GCC_BLSP1_QUP4_I2C_APPS_CLK:
208 clk_enable_cbc(priv->base + BLSP1_QUP4_I2C_APPS_CBCR);
Caleb Connollycbdad442024-04-03 14:07:40 +0200209 clk_rcg_set_rate(priv->base, BLSP1_QUP4_I2C_APPS_CMD_RCGR, 0,
Sumit Garg89e0dff2023-02-13 10:19:09 +0530210 CFG_CLK_SRC_CXO);
211 break;
Caleb Connollyd718e3e2024-02-26 17:26:10 +0000212 case GCC_SDCC1_AHB_CLK:
213 clk_enable_cbc(priv->base + SDCC_AHB_CBCR(1));
214 break;
Sumit Garg3018e522022-08-04 19:57:15 +0530215 default:
216 return 0;
217 }
218
Sumit Garg1d1ca6e2022-08-04 19:57:14 +0530219 return 0;
220}
Konrad Dybcio6c0b8442023-11-07 12:41:01 +0000221
222static const struct qcom_reset_map qcs404_gcc_resets[] = {
223 [GCC_GENI_IR_BCR] = { 0x0F000 },
224 [GCC_CDSP_RESTART] = { 0x18000 },
225 [GCC_USB_HS_BCR] = { 0x41000 },
226 [GCC_USB2_HS_PHY_ONLY_BCR] = { 0x41034 },
227 [GCC_QUSB2_PHY_BCR] = { 0x4103c },
228 [GCC_USB_HS_PHY_CFG_AHB_BCR] = { 0x0000c, 1 },
229 [GCC_USB2A_PHY_BCR] = { 0x0000c, 0 },
230 [GCC_USB3_PHY_BCR] = { 0x39004 },
231 [GCC_USB_30_BCR] = { 0x39000 },
232 [GCC_USB3PHY_PHY_BCR] = { 0x39008 },
233 [GCC_PCIE_0_BCR] = { 0x3e000 },
234 [GCC_PCIE_0_PHY_BCR] = { 0x3e004 },
235 [GCC_PCIE_0_LINK_DOWN_BCR] = { 0x3e038 },
236 [GCC_PCIEPHY_0_PHY_BCR] = { 0x3e03c },
237 [GCC_PCIE_0_AXI_MASTER_STICKY_ARES] = { 0x3e040, 6},
238 [GCC_PCIE_0_AHB_ARES] = { 0x3e040, 5 },
239 [GCC_PCIE_0_AXI_SLAVE_ARES] = { 0x3e040, 4 },
240 [GCC_PCIE_0_AXI_MASTER_ARES] = { 0x3e040, 3 },
241 [GCC_PCIE_0_CORE_STICKY_ARES] = { 0x3e040, 2 },
242 [GCC_PCIE_0_SLEEP_ARES] = { 0x3e040, 1 },
243 [GCC_PCIE_0_PIPE_ARES] = { 0x3e040, 0 },
244 [GCC_EMAC_BCR] = { 0x4e000 },
245 [GCC_WDSP_RESTART] = {0x19000},
246};
247
Caleb Connolly10a0abb2023-11-07 12:41:03 +0000248static const struct msm_clk_data qcs404_clk_gcc_data = {
Konrad Dybcio6c0b8442023-11-07 12:41:01 +0000249 .resets = qcs404_gcc_resets,
250 .num_resets = ARRAY_SIZE(qcs404_gcc_resets),
Caleb Connolly10a0abb2023-11-07 12:41:03 +0000251 .enable = qcs404_clk_enable,
252 .set_rate = qcs404_clk_set_rate,
Konrad Dybcio6c0b8442023-11-07 12:41:01 +0000253};
254
255static const struct udevice_id gcc_qcs404_of_match[] = {
256 {
257 .compatible = "qcom,gcc-qcs404",
Caleb Connolly10a0abb2023-11-07 12:41:03 +0000258 .data = (ulong)&qcs404_clk_gcc_data
Konrad Dybcio6c0b8442023-11-07 12:41:01 +0000259 },
260 { }
261};
262
263U_BOOT_DRIVER(gcc_qcs404) = {
264 .name = "gcc_qcs404",
265 .id = UCLASS_NOP,
266 .of_match = gcc_qcs404_of_match,
267 .bind = qcom_cc_bind,
268 .flags = DM_FLAG_PRE_RELOC,
269};