blob: 61fb2e6955871b2849fd867661b27e756b82886b [file] [log] [blame]
Caleb Connolly90ff5812024-07-15 12:08:02 +02001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.
4 * Copyright (c) 2023-2024, Qualcomm Innovation Center, Inc. All rights reserved.
5 */
6
7#define pr_fmt(fmt) "%s " fmt, KBUILD_MODNAME
8
Caleb Connollybdc5a792024-07-15 12:08:08 +02009#include <dm.h>
10#include <dm/device_compat.h>
11#include <dm/devres.h>
12#include <dm/lists.h>
13#include <dm/ofnode.h>
14#include <linux/bitmap.h>
Caleb Connolly90ff5812024-07-15 12:08:02 +020015#include <linux/delay.h>
Caleb Connollybdc5a792024-07-15 12:08:08 +020016#include <linux/err.h>
17#include <linux/types.h>
18#include <asm/bitops.h>
19#include <asm/io.h>
Caleb Connolly90ff5812024-07-15 12:08:02 +020020
Caleb Connollybdc5a792024-07-15 12:08:08 +020021#include <log.h>
22
Caleb Connolly90ff5812024-07-15 12:08:02 +020023#include <soc/qcom/tcs.h>
24#include <dt-bindings/soc/qcom,rpmh-rsc.h>
25
26#include "rpmh-internal.h"
27
Caleb Connolly90ff5812024-07-15 12:08:02 +020028
29#define RSC_DRV_ID 0
30
31#define MAJOR_VER_MASK 0xFF
32#define MAJOR_VER_SHIFT 16
33#define MINOR_VER_MASK 0xFF
34#define MINOR_VER_SHIFT 8
35
36enum {
37 RSC_DRV_TCS_OFFSET,
38 RSC_DRV_CMD_OFFSET,
39 DRV_SOLVER_CONFIG,
40 DRV_PRNT_CHLD_CONFIG,
41 RSC_DRV_IRQ_ENABLE,
42 RSC_DRV_IRQ_STATUS,
43 RSC_DRV_IRQ_CLEAR,
44 RSC_DRV_CMD_WAIT_FOR_CMPL,
45 RSC_DRV_CONTROL,
46 RSC_DRV_STATUS,
47 RSC_DRV_CMD_ENABLE,
48 RSC_DRV_CMD_MSGID,
49 RSC_DRV_CMD_ADDR,
50 RSC_DRV_CMD_DATA,
51 RSC_DRV_CMD_STATUS,
52 RSC_DRV_CMD_RESP_DATA,
53};
54
55/* DRV HW Solver Configuration Information Register */
56#define DRV_HW_SOLVER_MASK 1
57#define DRV_HW_SOLVER_SHIFT 24
58
59/* DRV TCS Configuration Information Register */
60#define DRV_NUM_TCS_MASK 0x3F
61#define DRV_NUM_TCS_SHIFT 6
62#define DRV_NCPT_MASK 0x1F
63#define DRV_NCPT_SHIFT 27
64
65/* Offsets for CONTROL TCS Registers */
66#define RSC_DRV_CTL_TCS_DATA_HI 0x38
67#define RSC_DRV_CTL_TCS_DATA_HI_MASK 0xFFFFFF
68#define RSC_DRV_CTL_TCS_DATA_HI_VALID BIT(31)
69#define RSC_DRV_CTL_TCS_DATA_LO 0x40
70#define RSC_DRV_CTL_TCS_DATA_LO_MASK 0xFFFFFFFF
71#define RSC_DRV_CTL_TCS_DATA_SIZE 32
72
73#define TCS_AMC_MODE_ENABLE BIT(16)
74#define TCS_AMC_MODE_TRIGGER BIT(24)
75
76/* TCS CMD register bit mask */
77#define CMD_MSGID_LEN 8
78#define CMD_MSGID_RESP_REQ BIT(8)
79#define CMD_MSGID_WRITE BIT(16)
80#define CMD_STATUS_ISSUED BIT(8)
81#define CMD_STATUS_COMPL BIT(16)
82
83/*
84 * Here's a high level overview of how all the registers in RPMH work
85 * together:
86 *
87 * - The main rpmh-rsc address is the base of a register space that can
88 * be used to find overall configuration of the hardware
89 * (DRV_PRNT_CHLD_CONFIG). Also found within the rpmh-rsc register
90 * space are all the TCS blocks. The offset of the TCS blocks is
91 * specified in the device tree by "qcom,tcs-offset" and used to
92 * compute tcs_base.
93 * - TCS blocks come one after another. Type, count, and order are
94 * specified by the device tree as "qcom,tcs-config".
95 * - Each TCS block has some registers, then space for up to 16 commands.
96 * Note that though address space is reserved for 16 commands, fewer
97 * might be present. See ncpt (num cmds per TCS).
98 *
99 * Here's a picture:
100 *
101 * +---------------------------------------------------+
102 * |RSC |
103 * | ctrl |
104 * | |
105 * | Drvs: |
106 * | +-----------------------------------------------+ |
107 * | |DRV0 | |
108 * | | ctrl/config | |
109 * | | IRQ | |
110 * | | | |
111 * | | TCSes: | |
112 * | | +------------------------------------------+ | |
113 * | | |TCS0 | | | | | | | | | | | | | | |
114 * | | | ctrl | 0| 1| 2| 3| 4| 5| .| .| .| .|14|15| | |
115 * | | | | | | | | | | | | | | | | | |
116 * | | +------------------------------------------+ | |
117 * | | +------------------------------------------+ | |
118 * | | |TCS1 | | | | | | | | | | | | | | |
119 * | | | ctrl | 0| 1| 2| 3| 4| 5| .| .| .| .|14|15| | |
120 * | | | | | | | | | | | | | | | | | |
121 * | | +------------------------------------------+ | |
122 * | | +------------------------------------------+ | |
123 * | | |TCS2 | | | | | | | | | | | | | | |
124 * | | | ctrl | 0| 1| 2| 3| 4| 5| .| .| .| .|14|15| | |
125 * | | | | | | | | | | | | | | | | | |
126 * | | +------------------------------------------+ | |
127 * | | ...... | |
128 * | +-----------------------------------------------+ |
129 * | +-----------------------------------------------+ |
130 * | |DRV1 | |
131 * | | (same as DRV0) | |
132 * | +-----------------------------------------------+ |
133 * | ...... |
134 * +---------------------------------------------------+
135 */
136
Caleb Connolly90ff5812024-07-15 12:08:02 +0200137static u32 rpmh_rsc_reg_offset_ver_2_7[] = {
138 [RSC_DRV_TCS_OFFSET] = 672,
139 [RSC_DRV_CMD_OFFSET] = 20,
140 [DRV_SOLVER_CONFIG] = 0x04,
141 [DRV_PRNT_CHLD_CONFIG] = 0x0C,
142 [RSC_DRV_IRQ_ENABLE] = 0x00,
143 [RSC_DRV_IRQ_STATUS] = 0x04,
144 [RSC_DRV_IRQ_CLEAR] = 0x08,
145 [RSC_DRV_CMD_WAIT_FOR_CMPL] = 0x10,
146 [RSC_DRV_CONTROL] = 0x14,
147 [RSC_DRV_STATUS] = 0x18,
148 [RSC_DRV_CMD_ENABLE] = 0x1C,
149 [RSC_DRV_CMD_MSGID] = 0x30,
150 [RSC_DRV_CMD_ADDR] = 0x34,
151 [RSC_DRV_CMD_DATA] = 0x38,
152 [RSC_DRV_CMD_STATUS] = 0x3C,
153 [RSC_DRV_CMD_RESP_DATA] = 0x40,
154};
155
156static u32 rpmh_rsc_reg_offset_ver_3_0[] = {
157 [RSC_DRV_TCS_OFFSET] = 672,
158 [RSC_DRV_CMD_OFFSET] = 24,
159 [DRV_SOLVER_CONFIG] = 0x04,
160 [DRV_PRNT_CHLD_CONFIG] = 0x0C,
161 [RSC_DRV_IRQ_ENABLE] = 0x00,
162 [RSC_DRV_IRQ_STATUS] = 0x04,
163 [RSC_DRV_IRQ_CLEAR] = 0x08,
164 [RSC_DRV_CMD_WAIT_FOR_CMPL] = 0x20,
165 [RSC_DRV_CONTROL] = 0x24,
166 [RSC_DRV_STATUS] = 0x28,
167 [RSC_DRV_CMD_ENABLE] = 0x2C,
168 [RSC_DRV_CMD_MSGID] = 0x34,
169 [RSC_DRV_CMD_ADDR] = 0x38,
170 [RSC_DRV_CMD_DATA] = 0x3C,
171 [RSC_DRV_CMD_STATUS] = 0x40,
172 [RSC_DRV_CMD_RESP_DATA] = 0x44,
173};
174
175static inline void __iomem *
176tcs_reg_addr(const struct rsc_drv *drv, int reg, int tcs_id)
177{
178 return drv->tcs_base + drv->regs[RSC_DRV_TCS_OFFSET] * tcs_id + reg;
179}
180
181static inline void __iomem *
182tcs_cmd_addr(const struct rsc_drv *drv, int reg, int tcs_id, int cmd_id)
183{
184 return tcs_reg_addr(drv, reg, tcs_id) + drv->regs[RSC_DRV_CMD_OFFSET] * cmd_id;
185}
186
187static u32 read_tcs_cmd(const struct rsc_drv *drv, int reg, int tcs_id,
188 int cmd_id)
189{
190 return readl_relaxed(tcs_cmd_addr(drv, reg, tcs_id, cmd_id));
191}
192
193static u32 read_tcs_reg(const struct rsc_drv *drv, int reg, int tcs_id)
194{
195 return readl_relaxed(tcs_reg_addr(drv, reg, tcs_id));
196}
197
198static void write_tcs_cmd(const struct rsc_drv *drv, int reg, int tcs_id,
199 int cmd_id, u32 data)
200{
201 writel_relaxed(data, tcs_cmd_addr(drv, reg, tcs_id, cmd_id));
202}
203
204static void write_tcs_reg(const struct rsc_drv *drv, int reg, int tcs_id,
205 u32 data)
206{
207 writel_relaxed(data, tcs_reg_addr(drv, reg, tcs_id));
208}
209
210static void write_tcs_reg_sync(const struct rsc_drv *drv, int reg, int tcs_id,
211 u32 data)
212{
213 int i;
214
215 writel(data, tcs_reg_addr(drv, reg, tcs_id));
216
217 /*
218 * Wait until we read back the same value. Use a counter rather than
219 * ktime for timeout since this may be called after timekeeping stops.
220 */
221 for (i = 0; i < USEC_PER_SEC; i++) {
222 if (readl(tcs_reg_addr(drv, reg, tcs_id)) == data)
223 return;
224 udelay(1);
225 }
226 pr_err("%s: error writing %#x to %d:%#x\n", drv->name,
227 data, tcs_id, reg);
228}
229
230/**
Caleb Connolly90ff5812024-07-15 12:08:02 +0200231 * get_tcs_for_msg() - Get the tcs_group used to send the given message.
232 * @drv: The RSC controller.
233 * @msg: The message we want to send.
234 *
235 * This is normally pretty straightforward except if we are trying to send
236 * an ACTIVE_ONLY message but don't have any active_only TCSes.
237 *
238 * Return: A pointer to a tcs_group or an ERR_PTR.
239 */
240static struct tcs_group *get_tcs_for_msg(struct rsc_drv *drv,
241 const struct tcs_request *msg)
242{
Caleb Connolly90ff5812024-07-15 12:08:02 +0200243 /*
Caleb Connolly974e7432024-07-15 12:08:10 +0200244 * U-Boot: since we're single threaded and running synchronously we can
245 * just always used the first active TCS.
Caleb Connolly90ff5812024-07-15 12:08:02 +0200246 */
Caleb Connolly974e7432024-07-15 12:08:10 +0200247 if (msg->state != RPMH_ACTIVE_ONLY_STATE) {
248 log_err("WARN: only ACTIVE_ONLY state supported\n");
249 return ERR_PTR(-EINVAL);
250 }
Caleb Connolly90ff5812024-07-15 12:08:02 +0200251
Caleb Connolly974e7432024-07-15 12:08:10 +0200252 return &drv->tcs[ACTIVE_TCS];
Caleb Connolly90ff5812024-07-15 12:08:02 +0200253}
254
255/**
Caleb Connolly90ff5812024-07-15 12:08:02 +0200256 * __tcs_buffer_write() - Write to TCS hardware from a request; don't trigger.
257 * @drv: The controller.
258 * @tcs_id: The global ID of this TCS.
259 * @cmd_id: The index within the TCS to start writing.
260 * @msg: The message we want to send, which will contain several addr/data
261 * pairs to program (but few enough that they all fit in one TCS).
262 *
263 * This is used for all types of transfers (active, sleep, and wake).
264 */
265static void __tcs_buffer_write(struct rsc_drv *drv, int tcs_id, int cmd_id,
266 const struct tcs_request *msg)
267{
268 u32 msgid;
269 u32 cmd_msgid = CMD_MSGID_LEN | CMD_MSGID_WRITE;
270 u32 cmd_enable = 0;
271 struct tcs_cmd *cmd;
272 int i, j;
273
Caleb Connolly90ff5812024-07-15 12:08:02 +0200274 for (i = 0, j = cmd_id; i < msg->num_cmds; i++, j++) {
275 cmd = &msg->cmds[i];
276 cmd_enable |= BIT(j);
277 msgid = cmd_msgid;
278 /*
279 * Additionally, if the cmd->wait is set, make the command
280 * response reqd even if the overall request was fire-n-forget.
281 */
282 msgid |= cmd->wait ? CMD_MSGID_RESP_REQ : 0;
283
284 write_tcs_cmd(drv, drv->regs[RSC_DRV_CMD_MSGID], tcs_id, j, msgid);
285 write_tcs_cmd(drv, drv->regs[RSC_DRV_CMD_ADDR], tcs_id, j, cmd->addr);
286 write_tcs_cmd(drv, drv->regs[RSC_DRV_CMD_DATA], tcs_id, j, cmd->data);
Caleb Connolly974e7432024-07-15 12:08:10 +0200287 debug("tcs(m): %d [%s] cmd(n): %d msgid: %#x addr: %#x data: %#x complete: %d\n",
288 tcs_id, msg->state == RPMH_ACTIVE_ONLY_STATE ? "active" : "?", j, msgid,
289 cmd->addr, cmd->data, cmd->wait);
Caleb Connolly90ff5812024-07-15 12:08:02 +0200290 }
291
292 cmd_enable |= read_tcs_reg(drv, drv->regs[RSC_DRV_CMD_ENABLE], tcs_id);
293 write_tcs_reg(drv, drv->regs[RSC_DRV_CMD_ENABLE], tcs_id, cmd_enable);
294}
295
296/**
Caleb Connolly90ff5812024-07-15 12:08:02 +0200297 * rpmh_rsc_send_data() - Write / trigger active-only message.
298 * @drv: The controller.
299 * @msg: The data to be sent.
300 *
301 * NOTES:
302 * - This is only used for "ACTIVE_ONLY" since the limitations of this
303 * function don't make sense for sleep/wake cases.
304 * - To do the transfer, we will grab a whole TCS for ourselves--we don't
305 * try to share. If there are none available we'll wait indefinitely
306 * for a free one.
307 * - This function will not wait for the commands to be finished, only for
308 * data to be programmed into the RPMh. See rpmh_tx_done() which will
309 * be called when the transfer is fully complete.
310 * - This function must be called with interrupts enabled. If the hardware
311 * is busy doing someone else's transfer we need that transfer to fully
312 * finish so that we can have the hardware, and to fully finish it needs
313 * the interrupt handler to run. If the interrupts is set to run on the
314 * active CPU this can never happen if interrupts are disabled.
315 *
316 * Return: 0 on success, -EINVAL on error.
317 */
318int rpmh_rsc_send_data(struct rsc_drv *drv, const struct tcs_request *msg)
319{
320 struct tcs_group *tcs;
Caleb Connolly974e7432024-07-15 12:08:10 +0200321 int tcs_id, i;
322 u32 addr;
Caleb Connolly90ff5812024-07-15 12:08:02 +0200323
324 tcs = get_tcs_for_msg(drv, msg);
325 if (IS_ERR(tcs))
326 return PTR_ERR(tcs);
327
Caleb Connolly974e7432024-07-15 12:08:10 +0200328 /* u-boot is single-threaded, always use the first TCS as we'll never conflict */
329 tcs_id = tcs->offset;
Caleb Connolly90ff5812024-07-15 12:08:02 +0200330
331 tcs->req[tcs_id - tcs->offset] = msg;
Caleb Connolly974e7432024-07-15 12:08:10 +0200332 generic_set_bit(tcs_id, drv->tcs_in_use);
Caleb Connolly90ff5812024-07-15 12:08:02 +0200333 if (msg->state == RPMH_ACTIVE_ONLY_STATE && tcs->type != ACTIVE_TCS) {
334 /*
335 * Clear previously programmed WAKE commands in selected
336 * repurposed TCS to avoid triggering them. tcs->slots will be
337 * cleaned from rpmh_flush() by invoking rpmh_rsc_invalidate()
338 */
339 write_tcs_reg_sync(drv, drv->regs[RSC_DRV_CMD_ENABLE], tcs_id, 0);
Caleb Connolly90ff5812024-07-15 12:08:02 +0200340 }
Caleb Connolly90ff5812024-07-15 12:08:02 +0200341
342 /*
343 * These two can be done after the lock is released because:
344 * - We marked "tcs_in_use" under lock.
345 * - Once "tcs_in_use" has been marked nobody else could be writing
346 * to these registers until the interrupt goes off.
347 * - The interrupt can't go off until we trigger w/ the last line
348 * of __tcs_set_trigger() below.
349 */
350 __tcs_buffer_write(drv, tcs_id, 0, msg);
Caleb Connolly90ff5812024-07-15 12:08:02 +0200351
Caleb Connolly974e7432024-07-15 12:08:10 +0200352 /* U-Boot: Now wait for the TCS to be cleared, indicating that we're done */
353 for (i = 0; i < USEC_PER_SEC; i++) {
354 addr = read_tcs_cmd(drv, drv->regs[RSC_DRV_CMD_ADDR], i, 0);
355 if (addr != msg->cmds[0].addr)
356 break;
357 udelay(1);
358 }
359
360 if (i == USEC_PER_SEC) {
361 log_err("%s: error writing %#x to %d:%#x\n", drv->name,
362 msg->cmds[0].addr, tcs_id, drv->regs[RSC_DRV_CMD_ADDR]);
363 return -EINVAL;
364 }
365
Caleb Connolly90ff5812024-07-15 12:08:02 +0200366 return 0;
367}
368
Caleb Connolly8a540102024-07-15 12:08:09 +0200369static int rpmh_probe_tcs_config(struct udevice *dev, struct rsc_drv *drv)
Caleb Connolly90ff5812024-07-15 12:08:02 +0200370{
371 struct tcs_type_config {
372 u32 type;
373 u32 n;
374 } tcs_cfg[TCS_TYPE_NR] = { { 0 } };
Caleb Connolly8a540102024-07-15 12:08:09 +0200375 ofnode dn = dev_ofnode(dev);
Caleb Connolly90ff5812024-07-15 12:08:02 +0200376 u32 config, max_tcs, ncpt, offset;
377 int i, ret, n, st = 0;
378 struct tcs_group *tcs;
379
Caleb Connolly8a540102024-07-15 12:08:09 +0200380 ret = ofnode_read_u32(dn, "qcom,tcs-offset", &offset);
Caleb Connolly90ff5812024-07-15 12:08:02 +0200381 if (ret)
382 return ret;
383 drv->tcs_base = drv->base + offset;
384
385 config = readl_relaxed(drv->base + drv->regs[DRV_PRNT_CHLD_CONFIG]);
386
387 max_tcs = config;
388 max_tcs &= DRV_NUM_TCS_MASK << (DRV_NUM_TCS_SHIFT * drv->id);
389 max_tcs = max_tcs >> (DRV_NUM_TCS_SHIFT * drv->id);
390
391 ncpt = config & (DRV_NCPT_MASK << DRV_NCPT_SHIFT);
392 ncpt = ncpt >> DRV_NCPT_SHIFT;
393
Caleb Connolly8a540102024-07-15 12:08:09 +0200394 n = ofnode_read_u32_array(dn, "qcom,tcs-config", (u32 *)tcs_cfg, 2 * TCS_TYPE_NR);
395 if (n < 0) {
396 log_err("RPMh: %s: error reading qcom,tcs-config %d\n", dev->name, n);
397 return n;
398 }
Caleb Connolly90ff5812024-07-15 12:08:02 +0200399
400 for (i = 0; i < TCS_TYPE_NR; i++) {
Caleb Connolly90ff5812024-07-15 12:08:02 +0200401 if (tcs_cfg[i].n > MAX_TCS_PER_TYPE)
402 return -EINVAL;
403 }
404
405 for (i = 0; i < TCS_TYPE_NR; i++) {
406 tcs = &drv->tcs[tcs_cfg[i].type];
407 if (tcs->drv)
408 return -EINVAL;
409 tcs->drv = drv;
410 tcs->type = tcs_cfg[i].type;
411 tcs->num_tcs = tcs_cfg[i].n;
412 tcs->ncpt = ncpt;
413
414 if (!tcs->num_tcs || tcs->type == CONTROL_TCS)
415 continue;
416
417 if (st + tcs->num_tcs > max_tcs ||
418 st + tcs->num_tcs >= BITS_PER_BYTE * sizeof(tcs->mask))
419 return -EINVAL;
420
421 tcs->mask = ((1 << tcs->num_tcs) - 1) << st;
422 tcs->offset = st;
423 st += tcs->num_tcs;
424 }
425
426 drv->num_tcs = st;
427
428 return 0;
429}
430
Caleb Connolly8a540102024-07-15 12:08:09 +0200431static int rpmh_rsc_probe(struct udevice *dev)
Caleb Connolly90ff5812024-07-15 12:08:02 +0200432{
Caleb Connolly8a540102024-07-15 12:08:09 +0200433 ofnode dn = dev_ofnode(dev);
Caleb Connolly90ff5812024-07-15 12:08:02 +0200434 struct rsc_drv *drv;
435 char drv_id[10] = {0};
Caleb Connolly8a540102024-07-15 12:08:09 +0200436 int ret;
Caleb Connolly90ff5812024-07-15 12:08:02 +0200437 u32 rsc_id;
438
Caleb Connolly8a540102024-07-15 12:08:09 +0200439 drv = dev_get_priv(dev);
Caleb Connolly90ff5812024-07-15 12:08:02 +0200440
Caleb Connolly8a540102024-07-15 12:08:09 +0200441 ret = ofnode_read_u32(dn, "qcom,drv-id", &drv->id);
Caleb Connolly90ff5812024-07-15 12:08:02 +0200442 if (ret)
443 return ret;
444
Caleb Connolly8a540102024-07-15 12:08:09 +0200445 drv->name = ofnode_get_property(dn, "label", NULL);
Caleb Connolly90ff5812024-07-15 12:08:02 +0200446 if (!drv->name)
Caleb Connolly8a540102024-07-15 12:08:09 +0200447 drv->name = dev->name;
Caleb Connolly90ff5812024-07-15 12:08:02 +0200448
449 snprintf(drv_id, ARRAY_SIZE(drv_id), "drv-%d", drv->id);
Caleb Connolly8a540102024-07-15 12:08:09 +0200450 drv->base = (void __iomem *)dev_read_addr_name(dev, drv_id);
Caleb Connolly90ff5812024-07-15 12:08:02 +0200451 if (IS_ERR(drv->base))
452 return PTR_ERR(drv->base);
453
454 rsc_id = readl_relaxed(drv->base + RSC_DRV_ID);
455 drv->ver.major = rsc_id & (MAJOR_VER_MASK << MAJOR_VER_SHIFT);
456 drv->ver.major >>= MAJOR_VER_SHIFT;
457 drv->ver.minor = rsc_id & (MINOR_VER_MASK << MINOR_VER_SHIFT);
458 drv->ver.minor >>= MINOR_VER_SHIFT;
459
460 if (drv->ver.major == 3)
461 drv->regs = rpmh_rsc_reg_offset_ver_3_0;
462 else
463 drv->regs = rpmh_rsc_reg_offset_ver_2_7;
464
Caleb Connolly8a540102024-07-15 12:08:09 +0200465 ret = rpmh_probe_tcs_config(dev, drv);
Caleb Connolly90ff5812024-07-15 12:08:02 +0200466 if (ret)
467 return ret;
468
469 spin_lock_init(&drv->lock);
470 init_waitqueue_head(&drv->tcs_wait);
471 bitmap_zero(drv->tcs_in_use, MAX_TCS_NR);
472
Caleb Connolly90ff5812024-07-15 12:08:02 +0200473 /* Enable the active TCS to send requests immediately */
474 writel_relaxed(drv->tcs[ACTIVE_TCS].mask,
475 drv->tcs_base + drv->regs[RSC_DRV_IRQ_ENABLE]);
476
477 spin_lock_init(&drv->client.cache_lock);
478 INIT_LIST_HEAD(&drv->client.cache);
479 INIT_LIST_HEAD(&drv->client.batch_cache);
480
Caleb Connolly8a540102024-07-15 12:08:09 +0200481 dev_set_drvdata(dev, drv);
482 drv->dev = dev;
Caleb Connolly90ff5812024-07-15 12:08:02 +0200483
Caleb Connolly8a540102024-07-15 12:08:09 +0200484 log_debug("RPMh: %s: v%d.%d\n", dev->name, drv->ver.major, drv->ver.minor);
Caleb Connolly90ff5812024-07-15 12:08:02 +0200485
486 return ret;
487}
488
Caleb Connolly8a540102024-07-15 12:08:09 +0200489static const struct udevice_id qcom_rpmh_ids[] = {
490 { .compatible = "qcom,rpmh-rsc" },
Caleb Connolly90ff5812024-07-15 12:08:02 +0200491 { }
492};
Caleb Connolly90ff5812024-07-15 12:08:02 +0200493
Caleb Connolly8a540102024-07-15 12:08:09 +0200494U_BOOT_DRIVER(qcom_rpmh_rsc) = {
495 .name = "qcom_rpmh_rsc",
496 .id = UCLASS_MISC,
497 .priv_auto = sizeof(struct rsc_drv),
498 .probe = rpmh_rsc_probe,
499 .of_match = qcom_rpmh_ids,
500 /* rpmh is under CLUSTER_PD which we don't support, so skip trying to enable PDs */
501 .flags = DM_FLAG_DEFAULT_PD_CTRL_OFF,
Caleb Connolly90ff5812024-07-15 12:08:02 +0200502};
503
Caleb Connolly90ff5812024-07-15 12:08:02 +0200504MODULE_DESCRIPTION("Qualcomm Technologies, Inc. RPMh Driver");
505MODULE_LICENSE("GPL v2");