Caleb Connolly | 652a16b | 2023-10-03 11:52:55 +0100 | [diff] [blame^] | 1 | // SPDX-License-Identifier: BSD-3-Clause |
| 2 | /* |
| 3 | * Clock drivers for Qualcomm sm8250 |
| 4 | * |
| 5 | * (C) Copyright 2023 Linaro Ltd. |
| 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <clk-uclass.h> |
| 10 | #include <dm.h> |
| 11 | #include <linux/delay.h> |
| 12 | #include <errno.h> |
| 13 | #include <asm/io.h> |
| 14 | #include <linux/bug.h> |
| 15 | #include <linux/bitops.h> |
| 16 | #include <dt-bindings/clock/qcom,gcc-sm8250.h> |
| 17 | |
| 18 | #include "clock-qcom.h" |
| 19 | |
| 20 | #define GCC_SE12_UART_RCG_REG 0x184D0 |
| 21 | #define GCC_SDCC2_APPS_CLK_SRC_REG 0x1400c |
| 22 | |
| 23 | #define APCS_GPLL0_ENA_VOTE 0x79000 |
| 24 | #define APCS_GPLL9_STATUS 0x1c000 |
| 25 | #define APCS_GPLLX_ENA_REG 0x52018 |
| 26 | |
| 27 | #define USB30_SEC_GDSCR 0x10004 |
| 28 | |
| 29 | static const struct freq_tbl ftbl_gcc_qupv3_wrap1_s4_clk_src[] = { |
| 30 | F(7372800, CFG_CLK_SRC_GPLL0_EVEN, 1, 384, 15625), |
| 31 | F(14745600, CFG_CLK_SRC_GPLL0_EVEN, 1, 768, 15625), |
| 32 | F(19200000, CFG_CLK_SRC_CXO, 1, 0, 0), |
| 33 | F(29491200, CFG_CLK_SRC_GPLL0_EVEN, 1, 1536, 15625), |
| 34 | F(32000000, CFG_CLK_SRC_GPLL0_EVEN, 1, 8, 75), |
| 35 | F(48000000, CFG_CLK_SRC_GPLL0_EVEN, 1, 4, 25), |
| 36 | F(50000000, CFG_CLK_SRC_GPLL0_EVEN, 6, 0, 0), |
| 37 | F(64000000, CFG_CLK_SRC_GPLL0_EVEN, 1, 16, 75), |
| 38 | F(75000000, CFG_CLK_SRC_GPLL0_EVEN, 4, 0, 0), |
| 39 | F(80000000, CFG_CLK_SRC_GPLL0_EVEN, 1, 4, 15), |
| 40 | F(96000000, CFG_CLK_SRC_GPLL0_EVEN, 1, 8, 25), |
| 41 | F(100000000, CFG_CLK_SRC_GPLL0, 6, 0, 0), |
| 42 | { } |
| 43 | }; |
| 44 | |
| 45 | static const struct freq_tbl ftbl_gcc_sdcc2_apps_clk_src[] = { |
| 46 | F(400000, CFG_CLK_SRC_CXO, 12, 1, 4), |
| 47 | F(19200000, CFG_CLK_SRC_CXO, 1, 0, 0), |
| 48 | F(25000000, CFG_CLK_SRC_GPLL0_EVEN, 12, 0, 0), |
| 49 | F(50000000, CFG_CLK_SRC_GPLL0_EVEN, 6, 0, 0), |
| 50 | F(100000000, CFG_CLK_SRC_GPLL0, 6, 0, 0), |
| 51 | F(202000000, CFG_CLK_SRC_GPLL9, 4, 0, 0), |
| 52 | { } |
| 53 | }; |
| 54 | |
| 55 | static struct pll_vote_clk gpll9_vote_clk = { |
| 56 | .status = APCS_GPLL9_STATUS, |
| 57 | .status_bit = BIT(31), |
| 58 | .ena_vote = APCS_GPLLX_ENA_REG, |
| 59 | .vote_bit = BIT(9), |
| 60 | }; |
| 61 | |
| 62 | static ulong sm8250_set_rate(struct clk *clk, ulong rate) |
| 63 | { |
| 64 | struct msm_clk_priv *priv = dev_get_priv(clk->dev); |
| 65 | const struct freq_tbl *freq; |
| 66 | |
| 67 | if (clk->id < priv->data->num_clks) |
| 68 | debug("%s: %s, requested rate=%ld\n", __func__, priv->data->clks[clk->id].name, rate); |
| 69 | |
| 70 | switch (clk->id) { |
| 71 | case GCC_QUPV3_WRAP1_S4_CLK: /*UART2*/ |
| 72 | freq = qcom_find_freq(ftbl_gcc_qupv3_wrap1_s4_clk_src, rate); |
| 73 | clk_rcg_set_rate_mnd(priv->base, GCC_SE12_UART_RCG_REG, |
| 74 | freq->pre_div, freq->m, freq->n, freq->src, 16); |
| 75 | |
| 76 | return freq->freq; |
| 77 | case GCC_SDCC2_APPS_CLK: |
| 78 | /* Enable GPLL9 so that we can point SDCC2_APPS_CLK_SRC at it */ |
| 79 | clk_enable_gpll0(priv->base, &gpll9_vote_clk); |
| 80 | freq = qcom_find_freq(ftbl_gcc_sdcc2_apps_clk_src, rate); |
| 81 | printf("%s: got freq %u\n", __func__, freq->freq); |
| 82 | WARN(freq->src != CFG_CLK_SRC_GPLL9, "SDCC2_APPS_CLK_SRC not set to GPLL9, requested rate %lu\n", rate); |
| 83 | clk_rcg_set_rate_mnd(priv->base, GCC_SDCC2_APPS_CLK_SRC_REG, |
| 84 | freq->pre_div, freq->m, freq->n, CFG_CLK_SRC_GPLL9, 8); |
| 85 | |
| 86 | return rate; |
| 87 | default: |
| 88 | return 0; |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | static const struct gate_clk sm8250_clks[] = { |
| 93 | GATE_CLK(GCC_AGGRE_UFS_CARD_AXI_CLK, 0x750cc, 0x00000001), |
| 94 | GATE_CLK(GCC_AGGRE_UFS_PHY_AXI_CLK, 0x770cc, 0x00000001), |
| 95 | GATE_CLK(GCC_AGGRE_USB3_PRIM_AXI_CLK, 0x0f080, 0x00000001), |
| 96 | GATE_CLK(GCC_AGGRE_USB3_SEC_AXI_CLK, 0x10080, 0x00000001), |
| 97 | GATE_CLK(GCC_CFG_NOC_USB3_PRIM_AXI_CLK, 0x0f07c, 0x00000001), |
| 98 | GATE_CLK(GCC_CFG_NOC_USB3_SEC_AXI_CLK, 0x1007c, 0x00000001), |
| 99 | GATE_CLK(GCC_QMIP_CAMERA_NRT_AHB_CLK, 0x0b018, 0x00000001), |
| 100 | GATE_CLK(GCC_QMIP_CAMERA_RT_AHB_CLK, 0x0b01c, 0x00000001), |
| 101 | GATE_CLK(GCC_QMIP_DISP_AHB_CLK, 0x0b020, 0x00000001), |
| 102 | GATE_CLK(GCC_QMIP_VIDEO_CVP_AHB_CLK, 0x0b010, 0x00000001), |
| 103 | GATE_CLK(GCC_QMIP_VIDEO_VCODEC_AHB_CLK, 0x0b014, 0x00000001), |
| 104 | GATE_CLK(GCC_QUPV3_WRAP0_CORE_2X_CLK, 0x52008, 0x00000200), |
| 105 | GATE_CLK(GCC_QUPV3_WRAP0_CORE_CLK, 0x52008, 0x00000100), |
| 106 | GATE_CLK(GCC_QUPV3_WRAP0_S0_CLK, 0x52008, 0x00000400), |
| 107 | GATE_CLK(GCC_QUPV3_WRAP0_S1_CLK, 0x52008, 0x00000800), |
| 108 | GATE_CLK(GCC_QUPV3_WRAP0_S2_CLK, 0x52008, 0x00001000), |
| 109 | GATE_CLK(GCC_QUPV3_WRAP0_S3_CLK, 0x52008, 0x00002000), |
| 110 | GATE_CLK(GCC_QUPV3_WRAP0_S4_CLK, 0x52008, 0x00004000), |
| 111 | GATE_CLK(GCC_QUPV3_WRAP0_S5_CLK, 0x52008, 0x00008000), |
| 112 | GATE_CLK(GCC_QUPV3_WRAP0_S6_CLK, 0x52008, 0x00010000), |
| 113 | GATE_CLK(GCC_QUPV3_WRAP0_S7_CLK, 0x52008, 0x00020000), |
| 114 | GATE_CLK(GCC_QUPV3_WRAP1_CORE_2X_CLK, 0x52008, 0x00040000), |
| 115 | GATE_CLK(GCC_QUPV3_WRAP1_CORE_CLK, 0x52008, 0x00080000), |
| 116 | GATE_CLK(GCC_QUPV3_WRAP1_S0_CLK, 0x52008, 0x00400000), |
| 117 | GATE_CLK(GCC_QUPV3_WRAP1_S1_CLK, 0x52008, 0x00800000), |
| 118 | GATE_CLK(GCC_QUPV3_WRAP1_S2_CLK, 0x52008, 0x01000000), |
| 119 | GATE_CLK(GCC_QUPV3_WRAP1_S3_CLK, 0x52008, 0x02000000), |
| 120 | GATE_CLK(GCC_QUPV3_WRAP1_S4_CLK, 0x52008, 0x04000000), |
| 121 | GATE_CLK(GCC_QUPV3_WRAP1_S5_CLK, 0x52008, 0x08000000), |
| 122 | GATE_CLK(GCC_QUPV3_WRAP2_CORE_2X_CLK, 0x52010, 0x00000008), |
| 123 | GATE_CLK(GCC_QUPV3_WRAP2_CORE_CLK, 0x52010, 0x00000001), |
| 124 | GATE_CLK(GCC_QUPV3_WRAP2_S0_CLK, 0x52010, 0x00000010), |
| 125 | GATE_CLK(GCC_QUPV3_WRAP2_S1_CLK, 0x52010, 0x00000020), |
| 126 | GATE_CLK(GCC_QUPV3_WRAP2_S2_CLK, 0x52010, 0x00000040), |
| 127 | GATE_CLK(GCC_QUPV3_WRAP2_S3_CLK, 0x52010, 0x00000080), |
| 128 | GATE_CLK(GCC_QUPV3_WRAP2_S4_CLK, 0x52010, 0x00000100), |
| 129 | GATE_CLK(GCC_QUPV3_WRAP2_S5_CLK, 0x52010, 0x00000200), |
| 130 | GATE_CLK(GCC_QUPV3_WRAP_0_M_AHB_CLK, 0x52008, 0x00000040), |
| 131 | GATE_CLK(GCC_QUPV3_WRAP_0_S_AHB_CLK, 0x52008, 0x00000080), |
| 132 | GATE_CLK(GCC_QUPV3_WRAP_1_M_AHB_CLK, 0x52008, 0x00100000), |
| 133 | GATE_CLK(GCC_QUPV3_WRAP_1_S_AHB_CLK, 0x52008, 0x00200000), |
| 134 | GATE_CLK(GCC_QUPV3_WRAP_2_M_AHB_CLK, 0x52010, 0x00000004), |
| 135 | GATE_CLK(GCC_QUPV3_WRAP_2_S_AHB_CLK, 0x52010, 0x00000002), |
| 136 | GATE_CLK(GCC_SDCC2_AHB_CLK, 0x14008, 0x00000001), |
| 137 | GATE_CLK(GCC_SDCC2_APPS_CLK, 0x14004, 0x00000001), |
| 138 | GATE_CLK(GCC_SDCC4_AHB_CLK, 0x16008, 0x00000001), |
| 139 | GATE_CLK(GCC_SDCC4_APPS_CLK, 0x16004, 0x00000001), |
| 140 | GATE_CLK(GCC_UFS_CARD_AHB_CLK, 0x75018, 0x00000001), |
| 141 | GATE_CLK(GCC_UFS_CARD_AXI_CLK, 0x75010, 0x00000001), |
| 142 | GATE_CLK(GCC_UFS_CARD_ICE_CORE_CLK, 0x75064, 0x00000001), |
| 143 | GATE_CLK(GCC_UFS_CARD_PHY_AUX_CLK, 0x7509c, 0x00000001), |
| 144 | GATE_CLK(GCC_UFS_CARD_RX_SYMBOL_0_CLK, 0x75020, 0x00000001), |
| 145 | GATE_CLK(GCC_UFS_CARD_RX_SYMBOL_1_CLK, 0x750b8, 0x00000001), |
| 146 | GATE_CLK(GCC_UFS_CARD_TX_SYMBOL_0_CLK, 0x7501c, 0x00000001), |
| 147 | GATE_CLK(GCC_UFS_CARD_UNIPRO_CORE_CLK, 0x7505c, 0x00000001), |
| 148 | GATE_CLK(GCC_UFS_PHY_AHB_CLK, 0x77018, 0x00000001), |
| 149 | GATE_CLK(GCC_UFS_PHY_AXI_CLK, 0x77010, 0x00000001), |
| 150 | GATE_CLK(GCC_UFS_PHY_ICE_CORE_CLK, 0x77064, 0x00000001), |
| 151 | GATE_CLK(GCC_UFS_PHY_PHY_AUX_CLK, 0x7709c, 0x00000001), |
| 152 | GATE_CLK(GCC_UFS_PHY_RX_SYMBOL_0_CLK, 0x77020, 0x00000001), |
| 153 | GATE_CLK(GCC_UFS_PHY_RX_SYMBOL_1_CLK, 0x770b8, 0x00000001), |
| 154 | GATE_CLK(GCC_UFS_PHY_TX_SYMBOL_0_CLK, 0x7701c, 0x00000001), |
| 155 | GATE_CLK(GCC_UFS_PHY_UNIPRO_CORE_CLK, 0x7705c, 0x00000001), |
| 156 | GATE_CLK(GCC_USB30_PRIM_MASTER_CLK, 0x0f010, 0x00000001), |
| 157 | GATE_CLK(GCC_USB30_PRIM_MOCK_UTMI_CLK, 0x0f01c, 0x00000001), |
| 158 | GATE_CLK(GCC_USB30_PRIM_SLEEP_CLK, 0x0f018, 0x00000001), |
| 159 | GATE_CLK(GCC_USB30_SEC_MASTER_CLK, 0x10010, 0x00000001), |
| 160 | GATE_CLK(GCC_USB30_SEC_MOCK_UTMI_CLK, 0x1001c, 0x00000001), |
| 161 | GATE_CLK(GCC_USB30_SEC_SLEEP_CLK, 0x10018, 0x00000001), |
| 162 | GATE_CLK(GCC_USB3_PRIM_PHY_AUX_CLK, 0x0f054, 0x00000001), |
| 163 | GATE_CLK(GCC_USB3_PRIM_PHY_COM_AUX_CLK, 0x0f058, 0x00000001), |
| 164 | GATE_CLK(GCC_USB3_PRIM_PHY_PIPE_CLK, 0x0f05c, 0x00000001), |
| 165 | GATE_CLK(GCC_USB3_SEC_CLKREF_EN, 0x8c010, 0x00000001), |
| 166 | GATE_CLK(GCC_USB3_SEC_PHY_AUX_CLK, 0x10054, 0x00000001), |
| 167 | GATE_CLK(GCC_USB3_SEC_PHY_COM_AUX_CLK, 0x10058, 0x00000001), |
| 168 | GATE_CLK(GCC_USB3_SEC_PHY_PIPE_CLK, 0x1005c, 0x00000001), |
| 169 | }; |
| 170 | |
| 171 | static int sm8250_enable(struct clk *clk) |
| 172 | { |
| 173 | struct msm_clk_priv *priv = dev_get_priv(clk->dev); |
| 174 | |
| 175 | if (priv->data->num_clks < clk->id) { |
| 176 | debug("%s: unknown clk id %lu\n", __func__, clk->id); |
| 177 | return 0; |
| 178 | } |
| 179 | |
| 180 | debug("%s: clk %s\n", __func__, sm8250_clks[clk->id].name); |
| 181 | |
| 182 | switch (clk->id) { |
| 183 | case GCC_USB30_SEC_MASTER_CLK: |
| 184 | gdsc_enable(priv->base + USB30_SEC_GDSCR); |
| 185 | qcom_gate_clk_en(priv, GCC_USB3_SEC_PHY_AUX_CLK); |
| 186 | qcom_gate_clk_en(priv, GCC_USB3_SEC_PHY_COM_AUX_CLK); |
| 187 | break; |
| 188 | } |
| 189 | |
| 190 | qcom_gate_clk_en(priv, clk->id); |
| 191 | |
| 192 | return 0; |
| 193 | } |
| 194 | |
| 195 | static const struct qcom_reset_map sm8250_gcc_resets[] = { |
| 196 | [GCC_GPU_BCR] = { 0x71000 }, |
| 197 | [GCC_MMSS_BCR] = { 0xb000 }, |
| 198 | [GCC_NPU_BWMON_BCR] = { 0x73000 }, |
| 199 | [GCC_NPU_BCR] = { 0x4d000 }, |
| 200 | [GCC_PCIE_0_BCR] = { 0x6b000 }, |
| 201 | [GCC_PCIE_0_LINK_DOWN_BCR] = { 0x6c014 }, |
| 202 | [GCC_PCIE_0_NOCSR_COM_PHY_BCR] = { 0x6c020 }, |
| 203 | [GCC_PCIE_0_PHY_BCR] = { 0x6c01c }, |
| 204 | [GCC_PCIE_0_PHY_NOCSR_COM_PHY_BCR] = { 0x6c028 }, |
| 205 | [GCC_PCIE_1_BCR] = { 0x8d000 }, |
| 206 | [GCC_PCIE_1_LINK_DOWN_BCR] = { 0x8e014 }, |
| 207 | [GCC_PCIE_1_NOCSR_COM_PHY_BCR] = { 0x8e020 }, |
| 208 | [GCC_PCIE_1_PHY_BCR] = { 0x8e01c }, |
| 209 | [GCC_PCIE_1_PHY_NOCSR_COM_PHY_BCR] = { 0x8e000 }, |
| 210 | [GCC_PCIE_2_BCR] = { 0x6000 }, |
| 211 | [GCC_PCIE_2_LINK_DOWN_BCR] = { 0x1f014 }, |
| 212 | [GCC_PCIE_2_NOCSR_COM_PHY_BCR] = { 0x1f020 }, |
| 213 | [GCC_PCIE_2_PHY_BCR] = { 0x1f01c }, |
| 214 | [GCC_PCIE_2_PHY_NOCSR_COM_PHY_BCR] = { 0x1f028 }, |
| 215 | [GCC_PCIE_PHY_BCR] = { 0x6f000 }, |
| 216 | [GCC_PCIE_PHY_CFG_AHB_BCR] = { 0x6f00c }, |
| 217 | [GCC_PCIE_PHY_COM_BCR] = { 0x6f010 }, |
| 218 | [GCC_PDM_BCR] = { 0x33000 }, |
| 219 | [GCC_PRNG_BCR] = { 0x34000 }, |
| 220 | [GCC_QUPV3_WRAPPER_0_BCR] = { 0x17000 }, |
| 221 | [GCC_QUPV3_WRAPPER_1_BCR] = { 0x18000 }, |
| 222 | [GCC_QUPV3_WRAPPER_2_BCR] = { 0x1e000 }, |
| 223 | [GCC_QUSB2PHY_PRIM_BCR] = { 0x12000 }, |
| 224 | [GCC_QUSB2PHY_SEC_BCR] = { 0x12004 }, |
| 225 | [GCC_SDCC2_BCR] = { 0x14000 }, |
| 226 | [GCC_SDCC4_BCR] = { 0x16000 }, |
| 227 | [GCC_TSIF_BCR] = { 0x36000 }, |
| 228 | [GCC_UFS_CARD_BCR] = { 0x75000 }, |
| 229 | [GCC_UFS_PHY_BCR] = { 0x77000 }, |
| 230 | [GCC_USB30_PRIM_BCR] = { 0xf000 }, |
| 231 | [GCC_USB30_SEC_BCR] = { 0x10000 }, |
| 232 | [GCC_USB3_DP_PHY_PRIM_BCR] = { 0x50008 }, |
| 233 | [GCC_USB3_DP_PHY_SEC_BCR] = { 0x50014 }, |
| 234 | [GCC_USB3_PHY_PRIM_BCR] = { 0x50000 }, |
| 235 | [GCC_USB3_PHY_SEC_BCR] = { 0x5000c }, |
| 236 | [GCC_USB3PHY_PHY_PRIM_BCR] = { 0x50004 }, |
| 237 | [GCC_USB3PHY_PHY_SEC_BCR] = { 0x50010 }, |
| 238 | [GCC_USB_PHY_CFG_AHB2PHY_BCR] = { 0x6a000 }, |
| 239 | }; |
| 240 | |
| 241 | static struct msm_clk_data qcs404_gcc_data = { |
| 242 | .resets = sm8250_gcc_resets, |
| 243 | .num_resets = ARRAY_SIZE(sm8250_gcc_resets), |
| 244 | .clks = sm8250_clks, |
| 245 | .num_clks = ARRAY_SIZE(sm8250_clks), |
| 246 | |
| 247 | .enable = sm8250_enable, |
| 248 | .set_rate = sm8250_set_rate, |
| 249 | }; |
| 250 | |
| 251 | |
| 252 | static const struct udevice_id gcc_sm8250_of_match[] = { |
| 253 | { |
| 254 | .compatible = "qcom,gcc-sm8250", |
| 255 | .data = (ulong)&qcs404_gcc_data, |
| 256 | }, |
| 257 | { } |
| 258 | }; |
| 259 | |
| 260 | U_BOOT_DRIVER(gcc_sm8250) = { |
| 261 | .name = "gcc_sm8250", |
| 262 | .id = UCLASS_NOP, |
| 263 | .of_match = gcc_sm8250_of_match, |
| 264 | .bind = qcom_cc_bind, |
| 265 | .flags = DM_FLAG_PRE_RELOC, |
| 266 | }; |