Konrad Dybcio | d993573 | 2023-11-07 12:41:01 +0000 | [diff] [blame] | 1 | // SPDX-License-Identifier: BSD-3-Clause AND GPL-2.0 |
Jorge Ramirez-Ortiz | 7c75f7f | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 2 | /* |
Konrad Dybcio | d993573 | 2023-11-07 12:41:01 +0000 | [diff] [blame] | 3 | * Clock and reset drivers for Qualcomm platforms Global Clock |
| 4 | * Controller (GCC). |
Jorge Ramirez-Ortiz | 7c75f7f | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 5 | * |
| 6 | * (C) Copyright 2015 Mateusz Kulikowski <mateusz.kulikowski@gmail.com> |
Konrad Dybcio | d993573 | 2023-11-07 12:41:01 +0000 | [diff] [blame] | 7 | * (C) Copyright 2020 Sartura Ltd. (reset driver) |
| 8 | * Author: Robert Marko <robert.marko@sartura.hr> |
| 9 | * (C) Copyright 2022 Linaro Ltd. (reset driver) |
| 10 | * Author: Sumit Garg <sumit.garg@linaro.org> |
Jorge Ramirez-Ortiz | 7c75f7f | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 11 | * |
| 12 | * Based on Little Kernel driver, simplified |
Jorge Ramirez-Ortiz | 7c75f7f | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 13 | */ |
| 14 | |
| 15 | #include <common.h> |
| 16 | #include <clk-uclass.h> |
| 17 | #include <dm.h> |
Konrad Dybcio | d993573 | 2023-11-07 12:41:01 +0000 | [diff] [blame] | 18 | #include <dm/device-internal.h> |
| 19 | #include <dm/lists.h> |
Jorge Ramirez-Ortiz | 7c75f7f | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 20 | #include <errno.h> |
| 21 | #include <asm/io.h> |
Caleb Connolly | be20d62 | 2023-11-07 12:41:05 +0000 | [diff] [blame] | 22 | #include <linux/bug.h> |
| 23 | #include <linux/delay.h> |
Jorge Ramirez-Ortiz | 7c75f7f | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 24 | #include <linux/bitops.h> |
Konrad Dybcio | d993573 | 2023-11-07 12:41:01 +0000 | [diff] [blame] | 25 | #include <reset-uclass.h> |
| 26 | |
Caleb Connolly | 5bb0df6 | 2023-11-07 12:40:59 +0000 | [diff] [blame] | 27 | #include "clock-qcom.h" |
Jorge Ramirez-Ortiz | 7c75f7f | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 28 | |
| 29 | /* CBCR register fields */ |
| 30 | #define CBCR_BRANCH_ENABLE_BIT BIT(0) |
| 31 | #define CBCR_BRANCH_OFF_BIT BIT(31) |
| 32 | |
Jorge Ramirez-Ortiz | 7c75f7f | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 33 | /* Enable clock controlled by CBC soft macro */ |
| 34 | void clk_enable_cbc(phys_addr_t cbcr) |
| 35 | { |
| 36 | setbits_le32(cbcr, CBCR_BRANCH_ENABLE_BIT); |
| 37 | |
| 38 | while (readl(cbcr) & CBCR_BRANCH_OFF_BIT) |
| 39 | ; |
| 40 | } |
| 41 | |
Caleb Connolly | 4b31c6f | 2023-11-21 18:09:15 +0000 | [diff] [blame^] | 42 | void gdsc_enable(phys_addr_t gdscr) |
| 43 | { |
| 44 | uint32_t count; |
| 45 | clrbits_le32(gdscr, GDSC_SW_COLLAPSE); |
| 46 | for (count = 0; count < 1500; count++) { |
| 47 | if (readl(gdscr) & GDSC_PWR_ON) |
| 48 | break; |
| 49 | udelay(1); |
| 50 | } |
| 51 | WARN(count == 1500, "WARNING: GDSC @ %#llx stuck at off\n", gdscr); |
| 52 | } |
| 53 | |
Ramon Fried | 640dc34 | 2018-05-16 12:13:39 +0300 | [diff] [blame] | 54 | void clk_enable_gpll0(phys_addr_t base, const struct pll_vote_clk *gpll0) |
Jorge Ramirez-Ortiz | 7c75f7f | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 55 | { |
| 56 | if (readl(base + gpll0->status) & gpll0->status_bit) |
| 57 | return; /* clock already enabled */ |
| 58 | |
| 59 | setbits_le32(base + gpll0->ena_vote, gpll0->vote_bit); |
| 60 | |
| 61 | while ((readl(base + gpll0->status) & gpll0->status_bit) == 0) |
| 62 | ; |
| 63 | } |
| 64 | |
Ramon Fried | 640dc34 | 2018-05-16 12:13:39 +0300 | [diff] [blame] | 65 | #define BRANCH_ON_VAL (0) |
| 66 | #define BRANCH_NOC_FSM_ON_VAL BIT(29) |
| 67 | #define BRANCH_CHECK_MASK GENMASK(31, 28) |
| 68 | |
| 69 | void clk_enable_vote_clk(phys_addr_t base, const struct vote_clk *vclk) |
| 70 | { |
| 71 | u32 val; |
| 72 | |
| 73 | setbits_le32(base + vclk->ena_vote, vclk->vote_bit); |
| 74 | do { |
| 75 | val = readl(base + vclk->cbcr_reg); |
| 76 | val &= BRANCH_CHECK_MASK; |
| 77 | } while ((val != BRANCH_ON_VAL) && (val != BRANCH_NOC_FSM_ON_VAL)); |
| 78 | } |
| 79 | |
Sheep Sun | 6d430e1 | 2021-06-20 10:34:35 +0800 | [diff] [blame] | 80 | #define APPS_CMD_RCGR_UPDATE BIT(0) |
Jorge Ramirez-Ortiz | 7c75f7f | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 81 | |
Sheep Sun | 6d430e1 | 2021-06-20 10:34:35 +0800 | [diff] [blame] | 82 | /* Update clock command via CMD_RCGR */ |
| 83 | void clk_bcr_update(phys_addr_t apps_cmd_rcgr) |
Jorge Ramirez-Ortiz | 7c75f7f | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 84 | { |
Caleb Connolly | be20d62 | 2023-11-07 12:41:05 +0000 | [diff] [blame] | 85 | u32 count; |
Sheep Sun | 6d430e1 | 2021-06-20 10:34:35 +0800 | [diff] [blame] | 86 | setbits_le32(apps_cmd_rcgr, APPS_CMD_RCGR_UPDATE); |
Jorge Ramirez-Ortiz | 7c75f7f | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 87 | |
| 88 | /* Wait for frequency to be updated. */ |
Caleb Connolly | be20d62 | 2023-11-07 12:41:05 +0000 | [diff] [blame] | 89 | for (count = 0; count < 50000; count++) { |
| 90 | if (!(readl(apps_cmd_rcgr) & APPS_CMD_RCGR_UPDATE)) |
| 91 | break; |
| 92 | udelay(1); |
| 93 | } |
| 94 | WARN(count == 50000, "WARNING: RCG @ %#llx [%#010x] stuck at off\n", |
| 95 | apps_cmd_rcgr, readl(apps_cmd_rcgr)); |
Jorge Ramirez-Ortiz | 7c75f7f | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 96 | } |
| 97 | |
Caleb Connolly | be20d62 | 2023-11-07 12:41:05 +0000 | [diff] [blame] | 98 | #define CFG_SRC_DIV_MASK 0b11111 |
| 99 | #define CFG_SRC_SEL_SHIFT 8 |
| 100 | #define CFG_SRC_SEL_MASK (0x7 << CFG_SRC_SEL_SHIFT) |
| 101 | #define CFG_MODE_SHIFT 12 |
| 102 | #define CFG_MODE_MASK (0x3 << CFG_MODE_SHIFT) |
| 103 | #define CFG_MODE_DUAL_EDGE (0x2 << CFG_MODE_SHIFT) |
| 104 | #define CFG_HW_CLK_CTRL_MASK BIT(20) |
Jorge Ramirez-Ortiz | 7c75f7f | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 105 | |
Caleb Connolly | be20d62 | 2023-11-07 12:41:05 +0000 | [diff] [blame] | 106 | /* |
| 107 | * root set rate for clocks with half integer and MND divider |
| 108 | * div should be pre-calculated ((div * 2) - 1) |
| 109 | */ |
Caleb Connolly | 422b74b | 2023-11-21 17:55:53 +0000 | [diff] [blame] | 110 | void clk_rcg_set_rate_mnd(phys_addr_t base, uint32_t cmd_rcgr, |
Caleb Connolly | 97d7ed3 | 2023-11-07 12:41:04 +0000 | [diff] [blame] | 111 | int div, int m, int n, int source, u8 mnd_width) |
Jorge Ramirez-Ortiz | 7c75f7f | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 112 | { |
| 113 | u32 cfg; |
| 114 | /* M value for MND divider. */ |
| 115 | u32 m_val = m; |
Caleb Connolly | be20d62 | 2023-11-07 12:41:05 +0000 | [diff] [blame] | 116 | u32 n_minus_m = n - m; |
Jorge Ramirez-Ortiz | 7c75f7f | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 117 | /* NOT(N-M) value for MND divider. */ |
Caleb Connolly | be20d62 | 2023-11-07 12:41:05 +0000 | [diff] [blame] | 118 | u32 n_val = ~n_minus_m * !!(n); |
Jorge Ramirez-Ortiz | 7c75f7f | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 119 | /* NOT 2D value for MND divider. */ |
Caleb Connolly | be20d62 | 2023-11-07 12:41:05 +0000 | [diff] [blame] | 120 | u32 d_val = ~(clamp_t(u32, n, m, n_minus_m)); |
Caleb Connolly | 97d7ed3 | 2023-11-07 12:41:04 +0000 | [diff] [blame] | 121 | u32 mask = BIT(mnd_width) - 1; |
| 122 | |
| 123 | debug("m %#x n %#x d %#x div %#x mask %#x\n", m_val, n_val, d_val, div, mask); |
Jorge Ramirez-Ortiz | 7c75f7f | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 124 | |
| 125 | /* Program MND values */ |
Caleb Connolly | 422b74b | 2023-11-21 17:55:53 +0000 | [diff] [blame] | 126 | writel(m_val & mask, base + cmd_rcgr + RCG_M_REG); |
| 127 | writel(n_val & mask, base + cmd_rcgr + RCG_N_REG); |
| 128 | writel(d_val & mask, base + cmd_rcgr + RCG_D_REG); |
Jorge Ramirez-Ortiz | 7c75f7f | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 129 | |
| 130 | /* setup src select and divider */ |
Caleb Connolly | 422b74b | 2023-11-21 17:55:53 +0000 | [diff] [blame] | 131 | cfg = readl(base + cmd_rcgr + RCG_CFG_REG); |
Caleb Connolly | be20d62 | 2023-11-07 12:41:05 +0000 | [diff] [blame] | 132 | cfg &= ~(CFG_SRC_SEL_MASK | CFG_MODE_MASK | CFG_HW_CLK_CTRL_MASK); |
| 133 | cfg |= source & CFG_SRC_SEL_MASK; /* Select clock source */ |
Jorge Ramirez-Ortiz | 7c75f7f | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 134 | |
Jorge Ramirez-Ortiz | 7c75f7f | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 135 | if (div) |
Caleb Connolly | be20d62 | 2023-11-07 12:41:05 +0000 | [diff] [blame] | 136 | cfg |= div & CFG_SRC_DIV_MASK; |
Jorge Ramirez-Ortiz | 7c75f7f | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 137 | |
Caleb Connolly | be20d62 | 2023-11-07 12:41:05 +0000 | [diff] [blame] | 138 | if (n && n != m) |
Jorge Ramirez-Ortiz | 7c75f7f | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 139 | cfg |= CFG_MODE_DUAL_EDGE; |
| 140 | |
Caleb Connolly | 422b74b | 2023-11-21 17:55:53 +0000 | [diff] [blame] | 141 | writel(cfg, base + cmd_rcgr + RCG_CFG_REG); /* Write new clock configuration */ |
Jorge Ramirez-Ortiz | 7c75f7f | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 142 | |
| 143 | /* Inform h/w to start using the new config. */ |
Caleb Connolly | 422b74b | 2023-11-21 17:55:53 +0000 | [diff] [blame] | 144 | clk_bcr_update(base + cmd_rcgr); |
Jorge Ramirez-Ortiz | 7c75f7f | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 145 | } |
| 146 | |
Sumit Garg | 22d3fcd | 2023-02-01 19:28:57 +0530 | [diff] [blame] | 147 | /* root set rate for clocks with half integer and mnd_width=0 */ |
Caleb Connolly | 422b74b | 2023-11-21 17:55:53 +0000 | [diff] [blame] | 148 | void clk_rcg_set_rate(phys_addr_t base, uint32_t cmd_rcgr, int div, |
Sumit Garg | 22d3fcd | 2023-02-01 19:28:57 +0530 | [diff] [blame] | 149 | int source) |
| 150 | { |
| 151 | u32 cfg; |
| 152 | |
| 153 | /* setup src select and divider */ |
Caleb Connolly | 422b74b | 2023-11-21 17:55:53 +0000 | [diff] [blame] | 154 | cfg = readl(base + cmd_rcgr + RCG_CFG_REG); |
Caleb Connolly | be20d62 | 2023-11-07 12:41:05 +0000 | [diff] [blame] | 155 | cfg &= ~(CFG_SRC_SEL_MASK | CFG_MODE_MASK | CFG_HW_CLK_CTRL_MASK); |
Sumit Garg | 22d3fcd | 2023-02-01 19:28:57 +0530 | [diff] [blame] | 156 | cfg |= source & CFG_CLK_SRC_MASK; /* Select clock source */ |
| 157 | |
| 158 | /* |
| 159 | * Set the divider; HW permits fraction dividers (+0.5), but |
| 160 | * for simplicity, we will support integers only |
| 161 | */ |
| 162 | if (div) |
Caleb Connolly | be20d62 | 2023-11-07 12:41:05 +0000 | [diff] [blame] | 163 | cfg |= (2 * div - 1) & CFG_SRC_DIV_MASK; |
Sumit Garg | 22d3fcd | 2023-02-01 19:28:57 +0530 | [diff] [blame] | 164 | |
Caleb Connolly | 422b74b | 2023-11-21 17:55:53 +0000 | [diff] [blame] | 165 | writel(cfg, base + cmd_rcgr + RCG_CFG_REG); /* Write new clock configuration */ |
Sumit Garg | 22d3fcd | 2023-02-01 19:28:57 +0530 | [diff] [blame] | 166 | |
| 167 | /* Inform h/w to start using the new config. */ |
Caleb Connolly | 422b74b | 2023-11-21 17:55:53 +0000 | [diff] [blame] | 168 | clk_bcr_update(base + cmd_rcgr); |
Sumit Garg | 22d3fcd | 2023-02-01 19:28:57 +0530 | [diff] [blame] | 169 | } |
| 170 | |
Caleb Connolly | be20d62 | 2023-11-07 12:41:05 +0000 | [diff] [blame] | 171 | const struct freq_tbl *qcom_find_freq(const struct freq_tbl *f, uint rate) |
| 172 | { |
| 173 | if (!f) |
| 174 | return NULL; |
| 175 | |
| 176 | if (!f->freq) |
| 177 | return f; |
| 178 | |
| 179 | for (; f->freq; f++) |
| 180 | if (rate <= f->freq) |
| 181 | return f; |
| 182 | |
| 183 | /* Default to our fastest rate */ |
| 184 | return f - 1; |
| 185 | } |
| 186 | |
Jorge Ramirez-Ortiz | 7c75f7f | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 187 | static int msm_clk_probe(struct udevice *dev) |
| 188 | { |
Konrad Dybcio | d993573 | 2023-11-07 12:41:01 +0000 | [diff] [blame] | 189 | struct msm_clk_data *data = (struct msm_clk_data *)dev_get_driver_data(dev); |
Jorge Ramirez-Ortiz | 7c75f7f | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 190 | struct msm_clk_priv *priv = dev_get_priv(dev); |
| 191 | |
Masahiro Yamada | 2548493 | 2020-07-17 14:36:48 +0900 | [diff] [blame] | 192 | priv->base = dev_read_addr(dev); |
Jorge Ramirez-Ortiz | 7c75f7f | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 193 | if (priv->base == FDT_ADDR_T_NONE) |
| 194 | return -EINVAL; |
| 195 | |
Konrad Dybcio | d993573 | 2023-11-07 12:41:01 +0000 | [diff] [blame] | 196 | priv->data = data; |
| 197 | |
Jorge Ramirez-Ortiz | 7c75f7f | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 198 | return 0; |
| 199 | } |
| 200 | |
| 201 | static ulong msm_clk_set_rate(struct clk *clk, ulong rate) |
| 202 | { |
Caleb Connolly | c94f9e9 | 2023-11-07 12:41:03 +0000 | [diff] [blame] | 203 | struct msm_clk_data *data = (struct msm_clk_data *)dev_get_driver_data(clk->dev); |
| 204 | |
| 205 | if (data->set_rate) |
| 206 | return data->set_rate(clk, rate); |
| 207 | |
| 208 | return 0; |
Jorge Ramirez-Ortiz | 7c75f7f | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 209 | } |
| 210 | |
Sumit Garg | c9e384e | 2022-08-04 19:57:14 +0530 | [diff] [blame] | 211 | static int msm_clk_enable(struct clk *clk) |
| 212 | { |
Caleb Connolly | c94f9e9 | 2023-11-07 12:41:03 +0000 | [diff] [blame] | 213 | struct msm_clk_data *data = (struct msm_clk_data *)dev_get_driver_data(clk->dev); |
| 214 | |
| 215 | if (data->enable) |
| 216 | return data->enable(clk); |
| 217 | |
| 218 | return 0; |
Sumit Garg | c9e384e | 2022-08-04 19:57:14 +0530 | [diff] [blame] | 219 | } |
| 220 | |
Caleb Connolly | d388899 | 2023-10-02 16:56:21 +0100 | [diff] [blame] | 221 | static void dump_gplls(struct udevice *dev, phys_addr_t base) { |
| 222 | static phys_addr_t gplls[] = { |
| 223 | 0x00100000, |
| 224 | 0x00101000, |
| 225 | 0x00102000, |
| 226 | 0x00103000, |
| 227 | 0x00176000, |
| 228 | 0x00174000, |
| 229 | 0x00113000, |
| 230 | 0x0011a000, |
| 231 | 0x0011b000, |
| 232 | 0x0011c000, |
| 233 | 0x0011d000, |
| 234 | 0x0014a000, |
| 235 | }; |
| 236 | uint32_t i; |
| 237 | bool locked; |
| 238 | uint64_t l, a, xo_rate = 19200000; |
| 239 | struct clk clk; |
| 240 | int ret; |
| 241 | u32 pll_branch = readl(0x00152018); |
| 242 | |
| 243 | ret = clk_get_by_name(dev, "xo_board", &clk); |
| 244 | if (ret < 0) { |
| 245 | ret = clk_get_by_name(dev, "xo-board", &clk); |
| 246 | if (ret < 0) |
| 247 | printf("Can't find XO clock, XO_BOARD rate may be wrong\n"); |
| 248 | } |
| 249 | |
| 250 | if (ret >= 0) |
| 251 | xo_rate = clk_get_rate(&clk); |
| 252 | |
| 253 | printf("| GPLL | LOCKED | GATE | XO_BOARD | PLL_L | ALPHA |\n"); |
| 254 | printf("+--------+--------+------+-----------+------------+----------------+\n"); |
| 255 | for (i = 0; i < ARRAY_SIZE(gplls); i++) { |
| 256 | locked = !!(readl(gplls[i]) & BIT(31)); |
| 257 | l = readl(gplls[i] + 4) & (BIT(16)-1); |
| 258 | a = readq(gplls[i] + 40) & (BIT(16)-1); |
| 259 | printf("| GPLL%-2d | %-6s | %-4s | %9llu * (%#-9llx + %#-13llx * 2 ** -40 ) / 1000000\n", |
| 260 | i, locked ? "X" : "", pll_branch & BIT(i) ? "X" : "", xo_rate, l, a); |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | static void dump_rcgs(void) { |
| 265 | static phys_addr_t rcgs[] = { |
| 266 | // 0x0010f018, // RB2 |
| 267 | // 0x0010f030, |
| 268 | // 0x0010f05c, |
| 269 | |
| 270 | // RB5 |
| 271 | // 0x00175024, // GCC_UFS_CARD_AXI_CMD_RCGR |
| 272 | // 0x0017506c, // GCC_UFS_CARD_ICE_CORE_CMD_RCGR |
| 273 | // 0x00175084, // GCC_UFS_CARD_UNIPRO_CORE_CMD_RCGR |
| 274 | // 0x001750a0, // GCC_UFS_CARD_PHY_AUX_CMD_RCGR |
| 275 | // 0x00177024, // GCC_UFS_PHY_AXI_CMD_RCGR |
| 276 | // 0x0017706c, // GCC_UFS_PHY_ICE_CORE_CMD_RCGR |
| 277 | // 0x00177084, // GCC_UFS_PHY_UNIPRO_CORE_CMD_RCGR |
| 278 | // 0x001770a0, // GCC_UFS_PHY_PHY_AUX_CMD_RCGR |
| 279 | 0x0011400c, // GCC_SDCC2_APPS_CMD_RCGR |
| 280 | //0x001184D0 |
| 281 | |
| 282 | // RB3 |
| 283 | //0x00118148 |
| 284 | }; |
| 285 | static const char * const rcg_names[] = { |
| 286 | // "USB30_PRIM_MASTER", // RB2 |
| 287 | // "USB30_PRIM_MOCK_UTMI", |
| 288 | // "USB3_PRIM_PHY_AUX", |
| 289 | |
| 290 | // RB5 |
| 291 | // "GCC_UFS_CARD_AXI_CMD_RCGR", |
| 292 | // "GCC_UFS_CARD_ICE_CORE_CMD_RCGR", |
| 293 | // "GCC_UFS_CARD_UNIPRO_CORE_CMD_RCGR", |
| 294 | // "GCC_UFS_CARD_PHY_AUX_CMD_RCGR", |
| 295 | // "GCC_UFS_PHY_AXI_CMD_RCGR", |
| 296 | // "GCC_UFS_PHY_ICE_CORE_CMD_RCGR", |
| 297 | // "GCC_UFS_PHY_UNIPRO_CORE_CMD_RCGR", |
| 298 | // "GCC_UFS_PHY_PHY_AUX_CMD_RCGR", |
| 299 | "GCC_SDCC2_APPS_CMD_RCGR", |
| 300 | //"UART", |
| 301 | }; |
| 302 | int i; |
| 303 | uint32_t cmd; |
| 304 | uint32_t cfg; |
| 305 | uint32_t not_n_minus_m; |
| 306 | uint32_t src, m, n, div; |
| 307 | bool root_on, d_odd; |
| 308 | printf("\nRCGs:\n"); |
| 309 | |
| 310 | for (i = 0; i < ARRAY_SIZE(rcgs); i++) { |
| 311 | cmd = readl(rcgs[i]); |
| 312 | cfg = readl(rcgs[i] + 0x4); |
| 313 | m = readl(rcgs[i] + 0x8); |
| 314 | not_n_minus_m = readl(rcgs[i] + 0xc); |
| 315 | |
| 316 | root_on = !(cmd & BIT(31)); // ROOT_OFF |
| 317 | src = (cfg >> 8) & 7; |
| 318 | |
| 319 | if (not_n_minus_m) |
| 320 | n = (~not_n_minus_m & 0xffff) + m; |
| 321 | else |
| 322 | n = 0; |
| 323 | |
| 324 | div = ((cfg & 0b11111) + 1) / 2; |
| 325 | d_odd = ((cfg & 0b11111) + 1) % 2 == 1; |
| 326 | printf("%#010x %#010x %#010x %#010x %#010x\n", cmd, cfg, m, not_n_minus_m, readl(rcgs[i] + 0x10)); |
| 327 | printf("%-32s: %-1s src %d | input_freq * (%#x/%#x) * (1/%d%s)", |
| 328 | rcg_names[i], root_on ? "X" : "", src, m ?: 1, n ?: 1, div, d_odd ? ".5" : ""); |
| 329 | printf(" [%#010X]\n", cmd); |
| 330 | } |
| 331 | |
| 332 | printf("\n"); |
| 333 | } |
| 334 | |
| 335 | static void msm_dump_clks(struct udevice *dev) |
| 336 | { |
| 337 | struct msm_clk_data *data = (struct msm_clk_data *)dev_get_driver_data(dev); |
| 338 | struct msm_clk_priv *priv = dev_get_priv(dev); |
| 339 | const struct gate_clk *sclk; |
| 340 | const struct qcom_reset_map *rst; |
| 341 | int val, i; |
| 342 | |
| 343 | if (!data->clks) { |
| 344 | printf("No clocks\n"); |
| 345 | return; |
| 346 | } |
| 347 | |
| 348 | for (i = 0; i < data->num_clks; i++) { |
| 349 | sclk = &data->clks[i]; |
| 350 | if (!sclk->name) |
| 351 | continue; |
| 352 | printf("%-32s: ", sclk->name); |
| 353 | val = readl(priv->base + sclk->reg) & sclk->en_val; |
| 354 | printf("%s\n", val ? "ON" : ""); |
| 355 | } |
| 356 | |
| 357 | for (i = 0; i < data->num_resets; i++) { |
| 358 | rst = &data->resets[i]; |
| 359 | printf("%#05x: ", rst->reg); |
| 360 | val = readl(priv->base + rst->reg); |
| 361 | printf("%s\n", val > 0 ? "ON" : ""); |
| 362 | } |
| 363 | |
| 364 | dump_gplls(dev, priv->base); |
| 365 | dump_rcgs(); |
| 366 | } |
| 367 | |
Jorge Ramirez-Ortiz | 7c75f7f | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 368 | static struct clk_ops msm_clk_ops = { |
| 369 | .set_rate = msm_clk_set_rate, |
Sumit Garg | c9e384e | 2022-08-04 19:57:14 +0530 | [diff] [blame] | 370 | .enable = msm_clk_enable, |
Caleb Connolly | d388899 | 2023-10-02 16:56:21 +0100 | [diff] [blame] | 371 | .dump_clks = msm_dump_clks, |
Jorge Ramirez-Ortiz | 7c75f7f | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 372 | }; |
| 373 | |
Konrad Dybcio | d993573 | 2023-11-07 12:41:01 +0000 | [diff] [blame] | 374 | U_BOOT_DRIVER(qcom_clk) = { |
| 375 | .name = "qcom_clk", |
Jorge Ramirez-Ortiz | 7c75f7f | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 376 | .id = UCLASS_CLK, |
Jorge Ramirez-Ortiz | 7c75f7f | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 377 | .ops = &msm_clk_ops, |
Simon Glass | 41575d8 | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 378 | .priv_auto = sizeof(struct msm_clk_priv), |
Jorge Ramirez-Ortiz | 7c75f7f | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 379 | .probe = msm_clk_probe, |
| 380 | }; |
Konrad Dybcio | d993573 | 2023-11-07 12:41:01 +0000 | [diff] [blame] | 381 | |
| 382 | int qcom_cc_bind(struct udevice *parent) |
| 383 | { |
| 384 | struct msm_clk_data *data = (struct msm_clk_data *)dev_get_driver_data(parent); |
| 385 | struct udevice *clkdev, *rstdev; |
| 386 | struct driver *drv; |
| 387 | int ret; |
| 388 | |
| 389 | /* Get a handle to the common clk handler */ |
| 390 | drv = lists_driver_lookup_name("qcom_clk"); |
| 391 | if (!drv) |
| 392 | return -ENOENT; |
| 393 | |
| 394 | /* Register the clock controller */ |
| 395 | ret = device_bind_with_driver_data(parent, drv, "qcom_clk", (ulong)data, |
| 396 | dev_ofnode(parent), &clkdev); |
| 397 | if (ret) |
| 398 | return ret; |
| 399 | |
| 400 | /* Bail out early if resets are not specified for this platform */ |
| 401 | if (!data->resets) |
| 402 | return ret; |
| 403 | |
| 404 | /* Get a handle to the common reset handler */ |
| 405 | drv = lists_driver_lookup_name("qcom_reset"); |
| 406 | if (!drv) |
| 407 | return -ENOENT; |
| 408 | |
| 409 | /* Register the reset controller */ |
| 410 | ret = device_bind_with_driver_data(parent, drv, "qcom_reset", (ulong)data, |
| 411 | dev_ofnode(parent), &rstdev); |
| 412 | if (ret) |
| 413 | device_unbind(clkdev); |
| 414 | |
| 415 | return ret; |
| 416 | } |
| 417 | |
| 418 | static int qcom_reset_set(struct reset_ctl *rst, bool assert) |
| 419 | { |
| 420 | struct msm_clk_data *data = (struct msm_clk_data *)dev_get_driver_data(rst->dev); |
| 421 | void __iomem *base = dev_get_priv(rst->dev); |
| 422 | const struct qcom_reset_map *map; |
| 423 | u32 value; |
| 424 | |
| 425 | map = &data->resets[rst->id]; |
| 426 | |
| 427 | value = readl(base + map->reg); |
| 428 | |
| 429 | if (assert) |
| 430 | value |= BIT(map->bit); |
| 431 | else |
| 432 | value &= ~BIT(map->bit); |
| 433 | |
| 434 | writel(value, base + map->reg); |
| 435 | |
| 436 | return 0; |
| 437 | } |
| 438 | |
| 439 | static int qcom_reset_assert(struct reset_ctl *rst) |
| 440 | { |
| 441 | return qcom_reset_set(rst, true); |
| 442 | } |
| 443 | |
| 444 | static int qcom_reset_deassert(struct reset_ctl *rst) |
| 445 | { |
| 446 | return qcom_reset_set(rst, false); |
| 447 | } |
| 448 | |
| 449 | static const struct reset_ops qcom_reset_ops = { |
| 450 | .rst_assert = qcom_reset_assert, |
| 451 | .rst_deassert = qcom_reset_deassert, |
| 452 | }; |
| 453 | |
| 454 | static int qcom_reset_probe(struct udevice *dev) |
| 455 | { |
| 456 | /* Set our priv pointer to the base address */ |
| 457 | dev_set_priv(dev, (void *)dev_read_addr(dev)); |
| 458 | |
| 459 | return 0; |
| 460 | } |
| 461 | |
| 462 | U_BOOT_DRIVER(qcom_reset) = { |
| 463 | .name = "qcom_reset", |
| 464 | .id = UCLASS_RESET, |
| 465 | .ops = &qcom_reset_ops, |
| 466 | .probe = qcom_reset_probe, |
| 467 | }; |