blob: 25ca67e537d112dda236837d3d3984f9b666365e [file] [log] [blame]
Konrad Dybcio6c0b8442023-11-07 12:41:01 +00001// SPDX-License-Identifier: BSD-3-Clause AND GPL-2.0
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +01002/*
Konrad Dybcio6c0b8442023-11-07 12:41:01 +00003 * Clock and reset drivers for Qualcomm platforms Global Clock
4 * Controller (GCC).
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +01005 *
6 * (C) Copyright 2015 Mateusz Kulikowski <mateusz.kulikowski@gmail.com>
Konrad Dybcio6c0b8442023-11-07 12:41:01 +00007 * (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-Ortiz92c1eff2018-01-10 11:33:49 +010011 *
12 * Based on Little Kernel driver, simplified
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +010013 */
14
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +010015#include <clk-uclass.h>
Caleb Connolly86d28392024-08-19 21:34:17 +020016#include <linux/clk-provider.h>
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +010017#include <dm.h>
Konrad Dybcio6c0b8442023-11-07 12:41:01 +000018#include <dm/device-internal.h>
19#include <dm/lists.h>
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +010020#include <errno.h>
21#include <asm/io.h>
Caleb Connolly397c84f2023-11-07 12:41:05 +000022#include <linux/bug.h>
23#include <linux/delay.h>
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +010024#include <linux/bitops.h>
Volodymyr Babchukaae46492024-03-11 21:33:45 +000025#include <linux/iopoll.h>
Konrad Dybcio6c0b8442023-11-07 12:41:01 +000026#include <reset-uclass.h>
Volodymyr Babchukaae46492024-03-11 21:33:45 +000027#include <power-domain-uclass.h>
Konrad Dybcio6c0b8442023-11-07 12:41:01 +000028
Caleb Connolly878b26a2023-11-07 12:40:59 +000029#include "clock-qcom.h"
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +010030
31/* CBCR register fields */
32#define CBCR_BRANCH_ENABLE_BIT BIT(0)
33#define CBCR_BRANCH_OFF_BIT BIT(31)
34
Volodymyr Babchukaae46492024-03-11 21:33:45 +000035#define GDSC_SW_COLLAPSE_MASK BIT(0)
36#define GDSC_POWER_DOWN_COMPLETE BIT(15)
37#define GDSC_POWER_UP_COMPLETE BIT(16)
38#define GDSC_PWR_ON_MASK BIT(31)
39#define CFG_GDSCR_OFFSET 0x4
40#define GDSC_STATUS_POLL_TIMEOUT_US 1500
41
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +010042/* Enable clock controlled by CBC soft macro */
43void clk_enable_cbc(phys_addr_t cbcr)
44{
45 setbits_le32(cbcr, CBCR_BRANCH_ENABLE_BIT);
46
47 while (readl(cbcr) & CBCR_BRANCH_OFF_BIT)
48 ;
49}
50
Ramon Friedae299772018-05-16 12:13:39 +030051void clk_enable_gpll0(phys_addr_t base, const struct pll_vote_clk *gpll0)
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +010052{
53 if (readl(base + gpll0->status) & gpll0->status_bit)
54 return; /* clock already enabled */
55
56 setbits_le32(base + gpll0->ena_vote, gpll0->vote_bit);
57
58 while ((readl(base + gpll0->status) & gpll0->status_bit) == 0)
59 ;
60}
61
Ramon Friedae299772018-05-16 12:13:39 +030062#define BRANCH_ON_VAL (0)
63#define BRANCH_NOC_FSM_ON_VAL BIT(29)
64#define BRANCH_CHECK_MASK GENMASK(31, 28)
65
66void clk_enable_vote_clk(phys_addr_t base, const struct vote_clk *vclk)
67{
68 u32 val;
69
70 setbits_le32(base + vclk->ena_vote, vclk->vote_bit);
71 do {
72 val = readl(base + vclk->cbcr_reg);
73 val &= BRANCH_CHECK_MASK;
74 } while ((val != BRANCH_ON_VAL) && (val != BRANCH_NOC_FSM_ON_VAL));
75}
76
Sheep Sun49fee7b2021-06-20 10:34:35 +080077#define APPS_CMD_RCGR_UPDATE BIT(0)
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +010078
Sheep Sun49fee7b2021-06-20 10:34:35 +080079/* Update clock command via CMD_RCGR */
80void clk_bcr_update(phys_addr_t apps_cmd_rcgr)
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +010081{
Caleb Connolly397c84f2023-11-07 12:41:05 +000082 u32 count;
Sheep Sun49fee7b2021-06-20 10:34:35 +080083 setbits_le32(apps_cmd_rcgr, APPS_CMD_RCGR_UPDATE);
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +010084
85 /* Wait for frequency to be updated. */
Caleb Connolly397c84f2023-11-07 12:41:05 +000086 for (count = 0; count < 50000; count++) {
87 if (!(readl(apps_cmd_rcgr) & APPS_CMD_RCGR_UPDATE))
88 break;
89 udelay(1);
90 }
91 WARN(count == 50000, "WARNING: RCG @ %#llx [%#010x] stuck at off\n",
92 apps_cmd_rcgr, readl(apps_cmd_rcgr));
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +010093}
94
Caleb Connolly397c84f2023-11-07 12:41:05 +000095#define CFG_SRC_DIV_MASK 0b11111
96#define CFG_SRC_SEL_SHIFT 8
97#define CFG_SRC_SEL_MASK (0x7 << CFG_SRC_SEL_SHIFT)
98#define CFG_MODE_SHIFT 12
99#define CFG_MODE_MASK (0x3 << CFG_MODE_SHIFT)
100#define CFG_MODE_DUAL_EDGE (0x2 << CFG_MODE_SHIFT)
101#define CFG_HW_CLK_CTRL_MASK BIT(20)
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +0100102
Caleb Connolly397c84f2023-11-07 12:41:05 +0000103/*
104 * root set rate for clocks with half integer and MND divider
105 * div should be pre-calculated ((div * 2) - 1)
106 */
Caleb Connollycbdad442024-04-03 14:07:40 +0200107void clk_rcg_set_rate_mnd(phys_addr_t base, uint32_t cmd_rcgr,
Caleb Connollyfbacc672023-11-07 12:41:04 +0000108 int div, int m, int n, int source, u8 mnd_width)
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +0100109{
110 u32 cfg;
111 /* M value for MND divider. */
112 u32 m_val = m;
Caleb Connolly397c84f2023-11-07 12:41:05 +0000113 u32 n_minus_m = n - m;
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +0100114 /* NOT(N-M) value for MND divider. */
Caleb Connolly397c84f2023-11-07 12:41:05 +0000115 u32 n_val = ~n_minus_m * !!(n);
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +0100116 /* NOT 2D value for MND divider. */
Caleb Connolly397c84f2023-11-07 12:41:05 +0000117 u32 d_val = ~(clamp_t(u32, n, m, n_minus_m));
Caleb Connollyfbacc672023-11-07 12:41:04 +0000118 u32 mask = BIT(mnd_width) - 1;
119
120 debug("m %#x n %#x d %#x div %#x mask %#x\n", m_val, n_val, d_val, div, mask);
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +0100121
122 /* Program MND values */
Caleb Connollycbdad442024-04-03 14:07:40 +0200123 writel(m_val & mask, base + cmd_rcgr + RCG_M_REG);
124 writel(n_val & mask, base + cmd_rcgr + RCG_N_REG);
125 writel(d_val & mask, base + cmd_rcgr + RCG_D_REG);
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +0100126
127 /* setup src select and divider */
Caleb Connollycbdad442024-04-03 14:07:40 +0200128 cfg = readl(base + cmd_rcgr + RCG_CFG_REG);
Volodymyr Babchuk8eca2612024-03-11 21:33:45 +0000129 cfg &= ~(CFG_SRC_SEL_MASK | CFG_MODE_MASK | CFG_HW_CLK_CTRL_MASK |
130 CFG_SRC_DIV_MASK);
Caleb Connolly397c84f2023-11-07 12:41:05 +0000131 cfg |= source & CFG_SRC_SEL_MASK; /* Select clock source */
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +0100132
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +0100133 if (div)
Caleb Connolly397c84f2023-11-07 12:41:05 +0000134 cfg |= div & CFG_SRC_DIV_MASK;
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +0100135
Caleb Connolly397c84f2023-11-07 12:41:05 +0000136 if (n && n != m)
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +0100137 cfg |= CFG_MODE_DUAL_EDGE;
138
Caleb Connollycbdad442024-04-03 14:07:40 +0200139 writel(cfg, base + cmd_rcgr + RCG_CFG_REG); /* Write new clock configuration */
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +0100140
141 /* Inform h/w to start using the new config. */
Caleb Connollycbdad442024-04-03 14:07:40 +0200142 clk_bcr_update(base + cmd_rcgr);
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +0100143}
144
Sumit Garga3e804d2023-02-01 19:28:57 +0530145/* root set rate for clocks with half integer and mnd_width=0 */
Caleb Connollycbdad442024-04-03 14:07:40 +0200146void clk_rcg_set_rate(phys_addr_t base, uint32_t cmd_rcgr, int div,
Sumit Garga3e804d2023-02-01 19:28:57 +0530147 int source)
148{
149 u32 cfg;
150
151 /* setup src select and divider */
Caleb Connollycbdad442024-04-03 14:07:40 +0200152 cfg = readl(base + cmd_rcgr + RCG_CFG_REG);
Caleb Connolly397c84f2023-11-07 12:41:05 +0000153 cfg &= ~(CFG_SRC_SEL_MASK | CFG_MODE_MASK | CFG_HW_CLK_CTRL_MASK);
Sumit Garga3e804d2023-02-01 19:28:57 +0530154 cfg |= source & CFG_CLK_SRC_MASK; /* Select clock source */
155
156 /*
157 * Set the divider; HW permits fraction dividers (+0.5), but
158 * for simplicity, we will support integers only
159 */
160 if (div)
Caleb Connolly397c84f2023-11-07 12:41:05 +0000161 cfg |= (2 * div - 1) & CFG_SRC_DIV_MASK;
Sumit Garga3e804d2023-02-01 19:28:57 +0530162
Caleb Connollycbdad442024-04-03 14:07:40 +0200163 writel(cfg, base + cmd_rcgr + RCG_CFG_REG); /* Write new clock configuration */
Sumit Garga3e804d2023-02-01 19:28:57 +0530164
165 /* Inform h/w to start using the new config. */
Caleb Connollycbdad442024-04-03 14:07:40 +0200166 clk_bcr_update(base + cmd_rcgr);
Sumit Garga3e804d2023-02-01 19:28:57 +0530167}
168
Caleb Connolly397c84f2023-11-07 12:41:05 +0000169const struct freq_tbl *qcom_find_freq(const struct freq_tbl *f, uint rate)
170{
171 if (!f)
172 return NULL;
173
174 if (!f->freq)
175 return f;
176
177 for (; f->freq; f++)
178 if (rate <= f->freq)
179 return f;
180
181 /* Default to our fastest rate */
182 return f - 1;
183}
184
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +0100185static int msm_clk_probe(struct udevice *dev)
186{
Konrad Dybcio6c0b8442023-11-07 12:41:01 +0000187 struct msm_clk_data *data = (struct msm_clk_data *)dev_get_driver_data(dev);
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +0100188 struct msm_clk_priv *priv = dev_get_priv(dev);
189
Masahiro Yamadaa89b4de2020-07-17 14:36:48 +0900190 priv->base = dev_read_addr(dev);
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +0100191 if (priv->base == FDT_ADDR_T_NONE)
192 return -EINVAL;
193
Konrad Dybcio6c0b8442023-11-07 12:41:01 +0000194 priv->data = data;
195
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +0100196 return 0;
197}
198
199static ulong msm_clk_set_rate(struct clk *clk, ulong rate)
200{
Caleb Connolly10a0abb2023-11-07 12:41:03 +0000201 struct msm_clk_data *data = (struct msm_clk_data *)dev_get_driver_data(clk->dev);
202
203 if (data->set_rate)
204 return data->set_rate(clk, rate);
205
206 return 0;
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +0100207}
208
Sumit Garg1d1ca6e2022-08-04 19:57:14 +0530209static int msm_clk_enable(struct clk *clk)
210{
Caleb Connolly10a0abb2023-11-07 12:41:03 +0000211 struct msm_clk_data *data = (struct msm_clk_data *)dev_get_driver_data(clk->dev);
212
213 if (data->enable)
214 return data->enable(clk);
215
216 return 0;
Sumit Garg1d1ca6e2022-08-04 19:57:14 +0530217}
218
Caleb Connolly86d28392024-08-19 21:34:17 +0200219static void dump_gplls(struct udevice *dev, phys_addr_t base)
220{
221 struct msm_clk_data *data = (struct msm_clk_data *)dev_get_driver_data(dev);
222 u32 i;
223 bool locked;
224 u64 l, a, xo_rate = 19200000;
225 struct clk *clk = NULL;
226 struct udevice *xodev;
227 const phys_addr_t *gplls = data->dbg_pll_addrs;
228
229 uclass_foreach_dev_probe(UCLASS_CLK, xodev) {
230 if (!strcmp(xodev->name, "xo-board") || !strcmp(xodev->name, "xo_board")) {
231 clk = dev_get_clk_ptr(xodev);
232 break;
233 }
234 }
235
236 if (clk) {
237 xo_rate = clk_get_rate(clk);
238
239 /* On SDM845 this needs to be divided by 2 for some reason */
240 if (xo_rate && of_machine_is_compatible("qcom,sdm845"))
241 xo_rate /= 2;
242 } else {
243 printf("Can't find XO clock, XO_BOARD rate may be wrong\n");
244 }
245
246 printf("GPLL clocks:\n");
247 printf("| GPLL | LOCKED | XO_BOARD | PLL_L | ALPHA |\n");
248 printf("+--------+--------+-----------+------------+----------------+\n");
249 for (i = 0; i < data->num_plls; i++) {
250 locked = !!(readl(gplls[i]) & BIT(31));
251 l = readl(gplls[i] + 4) & (BIT(16) - 1);
252 a = readq(gplls[i] + 40) & (BIT(16) - 1);
253 printf("| GPLL%-2d | %-6s | %9llu * (%#-9llx + %#-13llx * 2 ** -40 ) / 1000000\n",
254 i, locked ? "X" : "", xo_rate, l, a);
255 }
256}
257
258static void dump_rcgs(struct udevice *dev)
259{
260 struct msm_clk_data *data = (struct msm_clk_data *)dev_get_driver_data(dev);
261 int i;
262 u32 cmd;
263 u32 cfg;
264 u32 not_n_minus_m;
265 u32 src, m, n, div;
266 bool root_on, d_odd;
267
268 printf("\nRCGs:\n");
269
270 /*
271 * Which GPLL SRC corresponds to depends on the parent map, see gcc-<soc>.c in Linux
272 * and find the parent map associated with the clock. Note that often there are multiple
273 * outputs from a single GPLL where one is actually half the rate of the other (_EVEN).
274 * intput_freq = associated GPLL output freq (potentially divided depending on SRC).
275 */
276 printf("| NAME | ON | SRC | OUT_FREQ = input_freq * (m/n) * (1/d) | [CMD REG ] |\n");
277 printf("+----------------------------------+----+-----+---------------------------------------+--------------+\n");
278 for (i = 0; i < data->num_rcgs; i++) {
279 cmd = readl(data->dbg_rcg_addrs[i]);
280 cfg = readl(data->dbg_rcg_addrs[i] + 0x4);
281 m = readl(data->dbg_rcg_addrs[i] + 0x8);
282 n = 0;
283 not_n_minus_m = readl(data->dbg_rcg_addrs[i] + 0xc);
284
285 root_on = !(cmd & BIT(31)); // ROOT_OFF
286 src = (cfg >> 8) & 7;
287
288 if (not_n_minus_m) {
289 n = (~not_n_minus_m & 0xffff);
290
291 /* A clumsy assumption that this is an 8-bit MND RCG */
292 if ((n & 0xff00) == 0xff00)
293 n = n & 0xff;
294
295 n += m;
296 }
297
298 div = ((cfg & 0b11111) + 1) / 2;
299 d_odd = ((cfg & 0b11111) + 1) % 2 == 1;
300 printf("%-34s | %-2s | %3d | input_freq * (%4d/%5d) * (1/%1d%-2s) | [%#010x]\n",
301 data->dbg_rcg_names[i], root_on ? "X" : "", src,
302 m ?: 1, n ?: 1, div, d_odd ? ".5" : "", cmd);
303 }
304
305 printf("\n");
306}
307
308static void __maybe_unused msm_dump_clks(struct udevice *dev)
309{
310 struct msm_clk_data *data = (struct msm_clk_data *)dev_get_driver_data(dev);
311 struct msm_clk_priv *priv = dev_get_priv(dev);
312 const struct gate_clk *sclk;
313 int val, i;
314
315 if (!data->clks) {
316 printf("No clocks\n");
317 return;
318 }
319
320 printf("Gate Clocks:\n");
321 for (i = 0; i < data->num_clks; i++) {
322 sclk = &data->clks[i];
323 if (!sclk->name)
324 continue;
325 printf("%-32s: ", sclk->name);
326 val = readl(priv->base + sclk->reg) & sclk->en_val;
327 printf("%s\n", val ? "ON" : "");
328 }
329
330 dump_gplls(dev, priv->base);
331 dump_rcgs(dev);
332}
333
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +0100334static struct clk_ops msm_clk_ops = {
335 .set_rate = msm_clk_set_rate,
Sumit Garg1d1ca6e2022-08-04 19:57:14 +0530336 .enable = msm_clk_enable,
Caleb Connolly86d28392024-08-19 21:34:17 +0200337#if IS_ENABLED(CONFIG_CMD_CLK)
338 .dump = msm_dump_clks,
339#endif
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +0100340};
341
Konrad Dybcio6c0b8442023-11-07 12:41:01 +0000342U_BOOT_DRIVER(qcom_clk) = {
343 .name = "qcom_clk",
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +0100344 .id = UCLASS_CLK,
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +0100345 .ops = &msm_clk_ops,
Simon Glass8a2b47f2020-12-03 16:55:17 -0700346 .priv_auto = sizeof(struct msm_clk_priv),
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +0100347 .probe = msm_clk_probe,
Caleb Connollye07ce562024-04-03 14:07:39 +0200348 .flags = DM_FLAG_PRE_RELOC | DM_FLAG_DEFAULT_PD_CTRL_OFF,
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +0100349};
Konrad Dybcio6c0b8442023-11-07 12:41:01 +0000350
351int qcom_cc_bind(struct udevice *parent)
352{
353 struct msm_clk_data *data = (struct msm_clk_data *)dev_get_driver_data(parent);
Volodymyr Babchukaae46492024-03-11 21:33:45 +0000354 struct udevice *clkdev = NULL, *rstdev = NULL, *pwrdev;
Konrad Dybcio6c0b8442023-11-07 12:41:01 +0000355 struct driver *drv;
356 int ret;
357
358 /* Get a handle to the common clk handler */
359 drv = lists_driver_lookup_name("qcom_clk");
360 if (!drv)
361 return -ENOENT;
362
363 /* Register the clock controller */
364 ret = device_bind_with_driver_data(parent, drv, "qcom_clk", (ulong)data,
365 dev_ofnode(parent), &clkdev);
366 if (ret)
367 return ret;
368
Volodymyr Babchukaae46492024-03-11 21:33:45 +0000369 if (data->resets) {
370 /* Get a handle to the common reset handler */
371 drv = lists_driver_lookup_name("qcom_reset");
372 if (!drv) {
373 ret = -ENOENT;
374 goto unbind_clkdev;
375 }
Konrad Dybcio6c0b8442023-11-07 12:41:01 +0000376
Volodymyr Babchukaae46492024-03-11 21:33:45 +0000377 /* Register the reset controller */
378 ret = device_bind_with_driver_data(parent, drv, "qcom_reset", (ulong)data,
379 dev_ofnode(parent), &rstdev);
380 if (ret)
381 goto unbind_clkdev;
382 }
Konrad Dybcio6c0b8442023-11-07 12:41:01 +0000383
Volodymyr Babchukaae46492024-03-11 21:33:45 +0000384 if (data->power_domains) {
385 /* Get a handle to the common power domain handler */
386 drv = lists_driver_lookup_name("qcom_power");
387 if (!drv) {
388 ret = -ENOENT;
389 goto unbind_rstdev;
390 }
391 /* Register the power domain controller */
392 ret = device_bind_with_driver_data(parent, drv, "qcom_power", (ulong)data,
393 dev_ofnode(parent), &pwrdev);
394 if (ret)
395 goto unbind_rstdev;
396 }
397
398 return 0;
399
400unbind_rstdev:
401 device_unbind(rstdev);
402unbind_clkdev:
403 device_unbind(clkdev);
Konrad Dybcio6c0b8442023-11-07 12:41:01 +0000404
405 return ret;
406}
407
408static int qcom_reset_set(struct reset_ctl *rst, bool assert)
409{
410 struct msm_clk_data *data = (struct msm_clk_data *)dev_get_driver_data(rst->dev);
411 void __iomem *base = dev_get_priv(rst->dev);
412 const struct qcom_reset_map *map;
413 u32 value;
414
415 map = &data->resets[rst->id];
416
417 value = readl(base + map->reg);
418
419 if (assert)
420 value |= BIT(map->bit);
421 else
422 value &= ~BIT(map->bit);
423
424 writel(value, base + map->reg);
425
426 return 0;
427}
428
429static int qcom_reset_assert(struct reset_ctl *rst)
430{
431 return qcom_reset_set(rst, true);
432}
433
434static int qcom_reset_deassert(struct reset_ctl *rst)
435{
436 return qcom_reset_set(rst, false);
437}
438
439static const struct reset_ops qcom_reset_ops = {
440 .rst_assert = qcom_reset_assert,
441 .rst_deassert = qcom_reset_deassert,
442};
443
444static int qcom_reset_probe(struct udevice *dev)
445{
446 /* Set our priv pointer to the base address */
447 dev_set_priv(dev, (void *)dev_read_addr(dev));
448
449 return 0;
450}
451
452U_BOOT_DRIVER(qcom_reset) = {
453 .name = "qcom_reset",
454 .id = UCLASS_RESET,
455 .ops = &qcom_reset_ops,
456 .probe = qcom_reset_probe,
457};
Volodymyr Babchukaae46492024-03-11 21:33:45 +0000458
459static int qcom_power_set(struct power_domain *pwr, bool on)
460{
461 struct msm_clk_data *data = (struct msm_clk_data *)dev_get_driver_data(pwr->dev);
462 void __iomem *base = dev_get_priv(pwr->dev);
463 const struct qcom_power_map *map;
464 u32 value;
465 int ret;
466
467 if (pwr->id >= data->num_power_domains)
468 return -ENODEV;
469
470 map = &data->power_domains[pwr->id];
471
472 if (!map->reg)
473 return -ENODEV;
474
475 value = readl(base + map->reg);
476
477 if (on)
478 value &= ~GDSC_SW_COLLAPSE_MASK;
479 else
480 value |= GDSC_SW_COLLAPSE_MASK;
481
482 writel(value, base + map->reg);
483
484 if (on)
485 ret = readl_poll_timeout(base + map->reg + CFG_GDSCR_OFFSET,
486 value,
487 (value & GDSC_POWER_UP_COMPLETE) ||
488 (value & GDSC_PWR_ON_MASK),
489 GDSC_STATUS_POLL_TIMEOUT_US);
490
491 else
492 ret = readl_poll_timeout(base + map->reg + CFG_GDSCR_OFFSET,
493 value,
494 (value & GDSC_POWER_DOWN_COMPLETE) ||
495 !(value & GDSC_PWR_ON_MASK),
496 GDSC_STATUS_POLL_TIMEOUT_US);
497
Volodymyr Babchukaae46492024-03-11 21:33:45 +0000498 if (ret == -ETIMEDOUT)
499 printf("WARNING: GDSC %lu is stuck during power on/off\n",
500 pwr->id);
501 return ret;
502}
503
504static int qcom_power_on(struct power_domain *pwr)
505{
506 return qcom_power_set(pwr, true);
507}
508
509static int qcom_power_off(struct power_domain *pwr)
510{
511 return qcom_power_set(pwr, false);
512}
513
514static const struct power_domain_ops qcom_power_ops = {
515 .on = qcom_power_on,
516 .off = qcom_power_off,
517};
518
519static int qcom_power_probe(struct udevice *dev)
520{
521 /* Set our priv pointer to the base address */
522 dev_set_priv(dev, (void *)dev_read_addr(dev));
523
524 return 0;
525}
526
527U_BOOT_DRIVER(qcom_power) = {
528 .name = "qcom_power",
529 .id = UCLASS_POWER_DOMAIN,
530 .ops = &qcom_power_ops,
531 .probe = qcom_power_probe,
Caleb Connollye07ce562024-04-03 14:07:39 +0200532 .flags = DM_FLAG_PRE_RELOC,
Volodymyr Babchukaae46492024-03-11 21:33:45 +0000533};