blob: 29fc0c2ed49c1cb512732c94fc9907fea13ba063 [file] [log] [blame]
Caleb Connollyceb92622023-09-26 17:12:13 +01001/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Copyright (c) 2016-2018, 2020, The Linux Foundation. All rights reserved.
4 * Copyright (c) 2023, Linaro Ltd.
5 */
6
7#include <common.h>
8#include <linux/err.h>
9#include <linux/types.h>
10#include <dm.h>
11#include <dm/ofnode.h>
12#include <dm/devres.h>
13#include <dm/device_compat.h>
14#include <linux/delay.h>
15#include <dm/lists.h>
16#include <errno.h>
17#include <asm/io.h>
18#include <asm/bitops.h>
19#include <linux/bitmap.h>
20#include <log.h>
21
22#include <dt-bindings/soc/qcom,rpmh-rsc.h>
23#include "rpmh-internal.h"
24
25#include <soc/qcom/rpmh.h>
26#include <soc/qcom/cmd-db.h>
27
28#define RSC_DRV_ID 0
29
30#define MAJOR_VER_MASK 0xFF
31#define MAJOR_VER_SHIFT 16
32#define MINOR_VER_MASK 0xFF
33#define MINOR_VER_SHIFT 8
34
35enum {
36 RSC_DRV_TCS_OFFSET,
37 RSC_DRV_CMD_OFFSET,
38 DRV_SOLVER_CONFIG,
39 DRV_PRNT_CHLD_CONFIG,
40 RSC_DRV_IRQ_ENABLE,
41 RSC_DRV_IRQ_STATUS,
42 RSC_DRV_IRQ_CLEAR,
43 RSC_DRV_CMD_WAIT_FOR_CMPL,
44 RSC_DRV_CONTROL,
45 RSC_DRV_STATUS,
46 RSC_DRV_CMD_ENABLE,
47 RSC_DRV_CMD_MSGID,
48 RSC_DRV_CMD_ADDR,
49 RSC_DRV_CMD_DATA,
50 RSC_DRV_CMD_STATUS,
51 RSC_DRV_CMD_RESP_DATA,
52};
53
54/* DRV HW Solver Configuration Information Register */
55#define DRV_HW_SOLVER_MASK 1
56#define DRV_HW_SOLVER_SHIFT 24
57
58/* DRV TCS Configuration Information Register */
59#define DRV_NUM_TCS_MASK 0x3F
60#define DRV_NUM_TCS_SHIFT 6
61#define DRV_NCPT_MASK 0x1F
62#define DRV_NCPT_SHIFT 27
63
64/* Offsets for CONTROL TCS Registers */
65#define RSC_DRV_CTL_TCS_DATA_HI 0x38
66#define RSC_DRV_CTL_TCS_DATA_HI_MASK 0xFFFFFF
67#define RSC_DRV_CTL_TCS_DATA_HI_VALID BIT(31)
68#define RSC_DRV_CTL_TCS_DATA_LO 0x40
69#define RSC_DRV_CTL_TCS_DATA_LO_MASK 0xFFFFFFFF
70#define RSC_DRV_CTL_TCS_DATA_SIZE 32
71
72#define TCS_AMC_MODE_ENABLE BIT(16)
73#define TCS_AMC_MODE_TRIGGER BIT(24)
74
75/* TCS CMD register bit mask */
76#define CMD_MSGID_LEN 8
77#define CMD_MSGID_RESP_REQ BIT(8)
78#define CMD_MSGID_WRITE BIT(16)
79#define CMD_STATUS_ISSUED BIT(8)
80#define CMD_STATUS_COMPL BIT(16)
81
82/*
83 * Here's a high level overview of how all the registers in RPMH work
84 * together:
85 *
86 * - The main rpmh-rsc address is the base of a register space that can
87 * be used to find overall configuration of the hardware
88 * (DRV_PRNT_CHLD_CONFIG). Also found within the rpmh-rsc register
89 * space are all the TCS blocks. The offset of the TCS blocks is
90 * specified in the device tree by "qcom,tcs-offset" and used to
91 * compute tcs_base.
92 * - TCS blocks come one after another. Type, count, and order are
93 * specified by the device tree as "qcom,tcs-config".
94 * - Each TCS block has some registers, then space for up to 16 commands.
95 * Note that though address space is reserved for 16 commands, fewer
96 * might be present. See ncpt (num cmds per TCS).
97 *
98 * Here's a picture:
99 *
100 * +---------------------------------------------------+
101 * |RSC |
102 * | ctrl |
103 * | |
104 * | Drvs: |
105 * | +-----------------------------------------------+ |
106 * | |DRV0 | |
107 * | | ctrl/config | |
108 * | | IRQ | |
109 * | | | |
110 * | | TCSes: | |
111 * | | +------------------------------------------+ | |
112 * | | |TCS0 | | | | | | | | | | | | | | |
113 * | | | ctrl | 0| 1| 2| 3| 4| 5| .| .| .| .|14|15| | |
114 * | | | | | | | | | | | | | | | | | |
115 * | | +------------------------------------------+ | |
116 * | | +------------------------------------------+ | |
117 * | | |TCS1 | | | | | | | | | | | | | | |
118 * | | | ctrl | 0| 1| 2| 3| 4| 5| .| .| .| .|14|15| | |
119 * | | | | | | | | | | | | | | | | | |
120 * | | +------------------------------------------+ | |
121 * | | +------------------------------------------+ | |
122 * | | |TCS2 | | | | | | | | | | | | | | |
123 * | | | ctrl | 0| 1| 2| 3| 4| 5| .| .| .| .|14|15| | |
124 * | | | | | | | | | | | | | | | | | |
125 * | | +------------------------------------------+ | |
126 * | | ...... | |
127 * | +-----------------------------------------------+ |
128 * | +-----------------------------------------------+ |
129 * | |DRV1 | |
130 * | | (same as DRV0) | |
131 * | +-----------------------------------------------+ |
132 * | ...... |
133 * +---------------------------------------------------+
134 */
135
136static u32 rpmh_rsc_reg_offset_ver_2_7[] = {
137 [RSC_DRV_TCS_OFFSET] = 672,
138 [RSC_DRV_CMD_OFFSET] = 20,
139 [DRV_SOLVER_CONFIG] = 0x04,
140 [DRV_PRNT_CHLD_CONFIG] = 0x0C,
141 [RSC_DRV_IRQ_ENABLE] = 0x00,
142 [RSC_DRV_IRQ_STATUS] = 0x04,
143 [RSC_DRV_IRQ_CLEAR] = 0x08,
144 [RSC_DRV_CMD_WAIT_FOR_CMPL] = 0x10,
145 [RSC_DRV_CONTROL] = 0x14,
146 [RSC_DRV_STATUS] = 0x18,
147 [RSC_DRV_CMD_ENABLE] = 0x1C,
148 [RSC_DRV_CMD_MSGID] = 0x30,
149 [RSC_DRV_CMD_ADDR] = 0x34,
150 [RSC_DRV_CMD_DATA] = 0x38,
151 [RSC_DRV_CMD_STATUS] = 0x3C,
152 [RSC_DRV_CMD_RESP_DATA] = 0x40,
153};
154
155
156static inline void __iomem *
157tcs_reg_addr(const struct rsc_drv *drv, int reg, int tcs_id)
158{
159 return drv->tcs_base + drv->regs[RSC_DRV_TCS_OFFSET] * tcs_id + reg;
160}
161
162static inline void __iomem *
163tcs_cmd_addr(const struct rsc_drv *drv, int reg, int tcs_id, int cmd_id)
164{
165 return tcs_reg_addr(drv, reg, tcs_id) + drv->regs[RSC_DRV_CMD_OFFSET] * cmd_id;
166}
167
168static u32 read_tcs_reg(const struct rsc_drv *drv, int reg, int tcs_id)
169{
170 return readl_relaxed(tcs_reg_addr(drv, reg, tcs_id));
171}
172
173static void write_tcs_cmd(const struct rsc_drv *drv, int reg, int tcs_id,
174 int cmd_id, u32 data)
175{
176 void __iomem *addr = tcs_cmd_addr(drv, reg, tcs_id, cmd_id);
177 debug("%s: tcs(m): %d cmd(n): %d addr: %#x data: %#x\n", drv->name,
178 tcs_id, cmd_id, reg, data);
179 writel_relaxed(data, addr);
180}
181
182static void write_tcs_reg(const struct rsc_drv *drv, int reg, int tcs_id,
183 u32 data)
184{
185 void __iomem *addr = tcs_reg_addr(drv, reg, tcs_id);
186 debug("%s: tcs(m): %d addr: %#x data: %#x\n", drv->name,
187 tcs_id, reg, data);
188 writel_relaxed(data, addr);
189}
190
191static void write_tcs_reg_sync(const struct rsc_drv *drv, int reg, int tcs_id,
192 u32 data)
193{
194 int i;
195 void __iomem *addr = tcs_reg_addr(drv, reg, tcs_id);
196
197 debug("%s: tcs(m): %d addr: %#x data: %#x\n", drv->name,
198 tcs_id, reg, data);
199
200 writel(data, addr);
201
202 /*
203 * Wait until we read back the same value. Use a counter rather than
204 * ktime for timeout since this may be called after timekeeping stops.
205 */
206 for (i = 0; i < USEC_PER_SEC; i++) {
207 if (readl(addr) == data)
208 return;
209 udelay(1);
210 }
211 pr_err("%s: error writing %#x to %d:%#x\n", drv->name,
212 data, tcs_id, reg);
213}
214
215/**
216 * tcs_invalidate() - Invalidate all TCSes of the given type (sleep or wake).
217 * @drv: The RSC controller.
218 * @type: SLEEP_TCS or WAKE_TCS
219 *
220 * This will clear the "slots" variable of the given tcs_group and also
221 * tell the hardware to forget about all entries.
222 *
223 * The caller must ensure that no other RPMH actions are happening when this
224 * function is called, since otherwise the device may immediately become
225 * used again even before this function exits.
226 */
227static void tcs_invalidate(struct rsc_drv *drv, int type)
228{
229 int m;
230 struct tcs_group *tcs = &drv->tcs[type];
231
232 /* Caller ensures nobody else is running so no lock */
233 if (bitmap_empty(tcs->slots, MAX_TCS_SLOTS))
234 return;
235
236 for (m = tcs->offset; m < tcs->offset + tcs->num_tcs; m++)
237 write_tcs_reg_sync(drv, drv->regs[RSC_DRV_CMD_ENABLE], m, 0);
238
239 bitmap_zero(tcs->slots, MAX_TCS_SLOTS);
240}
241
242/**
243 * rpmh_rsc_invalidate() - Invalidate sleep and wake TCSes.
244 * @drv: The RSC controller.
245 *
246 * The caller must ensure that no other RPMH actions are happening when this
247 * function is called, since otherwise the device may immediately become
248 * used again even before this function exits.
249 */
250void rpmh_rsc_invalidate(struct rsc_drv *drv)
251{
252 tcs_invalidate(drv, SLEEP_TCS);
253 tcs_invalidate(drv, WAKE_TCS);
254}
255
256/**
257 * rpmh_rsc_wait_for_resp() - Spin until we get a response from the rpmh
258 * @drv: The controller.
259 * @tcs_id: The global ID of this TCS.
260 *
261 * This is for ACTIVE_ONLY transfers (which are the only ones we support in
262 * u-boot). As we don't support interrupts, we just spin on the IRQ_STATUS
263 * register until the bit is set to confirm that the TCS TX is done.
264 */
265int rpmh_rsc_wait_for_resp(struct rsc_drv *drv, int tcs_id)
266{
267 u32 reg;
268 int i;
269
270 reg = drv->regs[RSC_DRV_IRQ_STATUS];
271
272 debug("%s: waiting for response on tcs %d\n", __func__, tcs_id);
273
274 for (i = 0; i < 5 * USEC_PER_SEC; i++) {
275 if (readl(tcs_reg_addr(drv, reg, tcs_id)) & BIT(tcs_id))
276 break;
277 udelay(1);
278 }
279
280 if (i == 5 * USEC_PER_SEC) {
281 printf("%s: timeout waiting for response\n", drv->name);
282 return -ETIMEDOUT;
283 }
284
285 writel_relaxed(BIT(tcs_id), drv->tcs_base + drv->regs[RSC_DRV_IRQ_CLEAR]);
286
287 return 0;
288}
289
290/**
291 * __tcs_buffer_write() - Write to TCS hardware from a request; don't trigger.
292 * @drv: The controller.
293 * @tcs_id: The global ID of this TCS.
294 * @cmd_id: The index within the TCS to start writing.
295 * @msg: The message we want to send, which will contain several addr/data
296 * pairs to program (but few enough that they all fit in one TCS).
297 *
298 * This is used for all types of transfers (active, sleep, and wake).
299 */
300static void __tcs_buffer_write(struct rsc_drv *drv, int tcs_id, int cmd_id,
301 const struct tcs_request *msg)
302{
303 u32 msgid;
304 u32 cmd_msgid = CMD_MSGID_LEN | CMD_MSGID_WRITE;
305 u32 cmd_enable = 0;
306 struct tcs_cmd *cmd;
307 int i, j;
308
309 /* u-boot: get a response to ensure everything is golden before continuing */
310 cmd_msgid |= CMD_MSGID_RESP_REQ;
311
312 for (i = 0, j = cmd_id; i < msg->num_cmds; i++, j++) {
313 cmd = &msg->cmds[i];
314 cmd_enable |= BIT(j);
315 msgid = cmd_msgid;
316 /*
317 * Additionally, if the cmd->wait is set, make the command
318 * response reqd even if the overall request was fire-n-forget.
319 */
320 msgid |= cmd->wait ? CMD_MSGID_RESP_REQ : 0;
321
322 write_tcs_cmd(drv, drv->regs[RSC_DRV_CMD_MSGID], tcs_id, j, msgid);
323 write_tcs_cmd(drv, drv->regs[RSC_DRV_CMD_ADDR], tcs_id, j, cmd->addr);
324 write_tcs_cmd(drv, drv->regs[RSC_DRV_CMD_DATA], tcs_id, j, cmd->data);
325 debug("%s: tcs(m): %d [%s] cmd(n): %d msgid: %#x addr: %#x data: %#x complete: %d\n",
326 drv->name, tcs_id, msg->state == RPMH_ACTIVE_ONLY_STATE ? "active" : "?", j, msgid,
327 cmd->addr, cmd->data, cmd->wait);
328 }
329
330 cmd_enable |= read_tcs_reg(drv, drv->regs[RSC_DRV_CMD_ENABLE], tcs_id);
331 write_tcs_reg(drv, drv->regs[RSC_DRV_CMD_ENABLE], tcs_id, cmd_enable);
332}
333
334
335/**
336 * __tcs_set_trigger() - Start xfer on a TCS or unset trigger on a borrowed TCS
337 * @drv: The controller.
338 * @tcs_id: The global ID of this TCS.
339 * @trigger: If true then untrigger/retrigger. If false then just untrigger.
340 *
341 * In the normal case we only ever call with "trigger=true" to start a
342 * transfer. That will un-trigger/disable the TCS from the last transfer
343 * then trigger/enable for this transfer.
344 *
345 * If we borrowed a wake TCS for an active-only transfer we'll also call
346 * this function with "trigger=false" to just do the un-trigger/disable
347 * before using the TCS for wake purposes again.
348 *
349 * Note that the AP is only in charge of triggering active-only transfers.
350 * The AP never triggers sleep/wake values using this function.
351 */
352static void __tcs_set_trigger(struct rsc_drv *drv, int tcs_id, bool trigger)
353{
354 u32 enable;
355 u32 reg = drv->regs[RSC_DRV_CONTROL];
356
357 /*
358 * HW req: Clear the DRV_CONTROL and enable TCS again
359 * While clearing ensure that the AMC mode trigger is cleared
360 * and then the mode enable is cleared.
361 */
362 enable = read_tcs_reg(drv, reg, tcs_id);
363 enable &= ~TCS_AMC_MODE_TRIGGER;
364 write_tcs_reg_sync(drv, reg, tcs_id, enable);
365 enable &= ~TCS_AMC_MODE_ENABLE;
366 write_tcs_reg_sync(drv, reg, tcs_id, enable);
367
368 if (trigger) {
369 /* Enable the AMC mode on the TCS and then trigger the TCS */
370 enable = TCS_AMC_MODE_ENABLE;
371 write_tcs_reg_sync(drv, reg, tcs_id, enable);
372 enable |= TCS_AMC_MODE_TRIGGER;
373 write_tcs_reg(drv, reg, tcs_id, enable);
374 }
375}
376
377/**
378 * get_tcs_for_msg() - Get the tcs_group used to send the given message.
379 * @drv: The RSC controller.
380 * @msg: The message we want to send.
381 *
382 * This is normally pretty straightforward except if we are trying to send
383 * an ACTIVE_ONLY message but don't have any active_only TCSes.
384 *
385 * Return: A pointer to a tcs_group or an ERR_PTR.
386 */
387static struct tcs_group *get_tcs_for_msg(struct rsc_drv *drv,
388 const struct tcs_request *msg)
389{
390 if (msg->state != RPMH_ACTIVE_ONLY_STATE) {
391 printf("WARN: only ACTIVE_ONLY state supported\n");
392 return ERR_PTR(-EINVAL);
393 }
394
395 return &drv->tcs[ACTIVE_TCS];
396}
397
398/**
399 * rpmh_rsc_send_data() - Write / trigger active-only message.
400 * @drv: The controller.
401 * @msg: The data to be sent.
402 *
403 * NOTES:
404 * - This is only used for "ACTIVE_ONLY" since the limitations of this
405 * function don't make sense for sleep/wake cases.
406 * - To do the transfer, we will grab a whole TCS for ourselves--we don't
407 * try to share. If there are none available we'll wait indefinitely
408 * for a free one.
409 * - This function will not wait for the commands to be finished, only for
410 * data to be programmed into the RPMh. See rpmh_tx_done() which will
411 * be called when the transfer is fully complete.
412 * - This function must be called with interrupts enabled. If the hardware
413 * is busy doing someone else's transfer we need that transfer to fully
414 * finish so that we can have the hardware, and to fully finish it needs
415 * the interrupt handler to run. If the interrupts is set to run on the
416 * active CPU this can never happen if interrupts are disabled.
417 *
418 * Return: 0 on success, -EINVAL on error.
419 */
420int rpmh_rsc_send_data(struct rsc_drv *drv, const struct tcs_request *msg)
421{
422 struct tcs_group *tcs;
423 int tcs_id;
424 unsigned long flags;
425
426 tcs = get_tcs_for_msg(drv, msg);
427 if (IS_ERR(tcs))
428 return PTR_ERR(tcs);
429
430 spin_lock_irqsave(&drv->lock, flags);
431
432 /* u-boot is single-threaded, always use the first TCS as we'll never conflict */
433 tcs_id = tcs->offset;
434
435 tcs->req[tcs_id - tcs->offset] = msg;
436 generic_set_bit(tcs_id, drv->tcs_in_use);
437 if (msg->state == RPMH_ACTIVE_ONLY_STATE && tcs->type != ACTIVE_TCS) {
438 /*
439 * Clear previously programmed WAKE commands in selected
440 * repurposed TCS to avoid triggering them. tcs->slots will be
441 * cleaned from rpmh_flush() by invoking rpmh_rsc_invalidate()
442 */
443 write_tcs_reg_sync(drv, drv->regs[RSC_DRV_CMD_ENABLE], tcs_id, 0);
444 //enable_tcs_irq(drv, tcs_id, true);
445 }
446 spin_unlock_irqrestore(&drv->lock, flags);
447
448 /*
449 * These two can be done after the lock is released because:
450 * - We marked "tcs_in_use" under lock.
451 * - Once "tcs_in_use" has been marked nobody else could be writing
452 * to these registers until the interrupt goes off.
453 * - The interrupt can't go off until we trigger w/ the last line
454 * of __tcs_set_trigger() below.
455 */
456 __tcs_buffer_write(drv, tcs_id, 0, msg);
457 __tcs_set_trigger(drv, tcs_id, true);
458
459 rpmh_rsc_wait_for_resp(drv, tcs_id);
460
461 return 0;
462}
463
464
465static int rpmh_probe_tcs_config(struct udevice *dev, struct rsc_drv *drv)
466{
467 struct tcs_type_config {
468 u32 type;
469 u32 n;
470 } tcs_cfg[TCS_TYPE_NR] = { { 0 } };
471 ofnode dn = dev_ofnode(dev);
472 u32 config, max_tcs, ncpt, offset;
473 int i, ret, n, st = 0;
474 struct tcs_group *tcs;
475
476 ret = ofnode_read_u32(dn, "qcom,tcs-offset", &offset);
477 if (ret)
478 return ret;
479 drv->tcs_base = drv->base + offset;
480
481 config = readl_relaxed(drv->base + drv->regs[DRV_PRNT_CHLD_CONFIG]);
482
483 max_tcs = config;
484 max_tcs &= DRV_NUM_TCS_MASK << (DRV_NUM_TCS_SHIFT * drv->id);
485 max_tcs = max_tcs >> (DRV_NUM_TCS_SHIFT * drv->id);
486
487 ncpt = config & (DRV_NCPT_MASK << DRV_NCPT_SHIFT);
488 ncpt = ncpt >> DRV_NCPT_SHIFT;
489
490 n = ofnode_read_u32_array(dn, "qcom,tcs-config", (u32*)tcs_cfg, 2 * TCS_TYPE_NR);
491 if (n < 0) {
492 printf("RPMh: %s: error reading qcom,tcs-config %d\n", dev->name, n);
493 return n;
494 }
495
496 for (i = 0; i < TCS_TYPE_NR; i++) {
497 if (tcs_cfg[i].n > MAX_TCS_PER_TYPE)
498 return -EINVAL;
499 }
500
501 for (i = 0; i < TCS_TYPE_NR; i++) {
502 tcs = &drv->tcs[tcs_cfg[i].type];
503 if (tcs->drv)
504 return -EINVAL;
505 tcs->drv = drv;
506 tcs->type = tcs_cfg[i].type;
507 tcs->num_tcs = tcs_cfg[i].n;
508 tcs->ncpt = ncpt;
509
510 if (!tcs->num_tcs || tcs->type == CONTROL_TCS)
511 continue;
512
513 if (st + tcs->num_tcs > max_tcs ||
514 st + tcs->num_tcs >= BITS_PER_BYTE * sizeof(tcs->mask))
515 return -EINVAL;
516
517 tcs->mask = ((1 << tcs->num_tcs) - 1) << st;
518 tcs->offset = st;
519 st += tcs->num_tcs;
520 }
521
522 drv->num_tcs = st;
523
524 return 0;
525}
526
527static int rpmh_rsc_probe(struct udevice *dev)
528{
529 ofnode dn = dev_ofnode(dev);
530 ofnode rmem, node;
531 struct rsc_drv *drv;
532 char drv_id[10] = {0};
533 int ret;
534 u32 rsc_id;
535
536 /*
537 * Even though RPMh doesn't directly use cmd-db, all of its children
538 * do. To avoid adding this check to our children we'll do it now.
539 */
540 rmem = ofnode_path("/reserved-memory");
541 ofnode_for_each_subnode(node, rmem) {
542 if (ofnode_device_is_compatible(node, "qcom,cmd-db"))
543 goto found;
544 }
545
546 printf("Couldn't find qcom,cmd-db node!\n");
547 return -ENODEV;
548found:
549 ret = cmd_db_init(node);
550 if (ret < 0) {
551 printf("Couldn't init cmd-db!\n");
552 return ret;
553 }
554
555 drv = dev_get_priv(dev);
556
557 ret = ofnode_read_u32(dn, "qcom,drv-id", &drv->id);
558 if (ret)
559 return ret;
560
561 drv->name = ofnode_get_property(dn, "label", NULL);
562 if (!drv->name)
563 drv->name = dev->name;
564
565 snprintf(drv_id, ARRAY_SIZE(drv_id), "drv-%d", drv->id);
566 drv->base = (void __iomem*)dev_read_addr_name(dev, drv_id);
567 if (IS_ERR(drv->base))
568 return PTR_ERR(drv->base);
569
570 rsc_id = readl_relaxed(drv->base + RSC_DRV_ID);
571 drv->ver.major = rsc_id & (MAJOR_VER_MASK << MAJOR_VER_SHIFT);
572 drv->ver.major >>= MAJOR_VER_SHIFT;
573 drv->ver.minor = rsc_id & (MINOR_VER_MASK << MINOR_VER_SHIFT);
574 drv->ver.minor >>= MINOR_VER_SHIFT;
575
576 if (drv->ver.major == 3) {
577 printf("RPMh v3 not supported\n");
578 return -ENOTSUPP;
579 } else
580 drv->regs = rpmh_rsc_reg_offset_ver_2_7;
581
582 ret = rpmh_probe_tcs_config(dev, drv);
583 if (ret)
584 return ret;
585
586 spin_lock_init(&drv->lock);
587 init_waitqueue_head(&drv->tcs_wait);
588 bitmap_zero(drv->tcs_in_use, MAX_TCS_NR);
589
590 /* Enable the active TCS to send requests immediately */
591 writel_relaxed(drv->tcs[ACTIVE_TCS].mask,
592 drv->tcs_base + drv->regs[RSC_DRV_IRQ_ENABLE]);
593
594 spin_lock_init(&drv->client.cache_lock);
595 INIT_LIST_HEAD(&drv->client.cache);
596 INIT_LIST_HEAD(&drv->client.batch_cache);
597
598 dev_set_drvdata(dev, drv);
599 drv->dev = dev;
600
601 printf("RPMh: %s: v%d.%d (priv %p)\n", dev->name, drv->ver.major, drv->ver.minor, dev_get_priv(dev));
602
603 return ret;
604}
605
606// static int rpmh_rsc_of_bind(struct udevice *parent)
607// {
608// lists_bind_drivers(parent, false);
609
610// return 0;
611// }
612
613static const struct udevice_id qcom_rpmh_ids[] = {
614 { .compatible = "qcom,rpmh-rsc" },
615 { }
616};
617
618U_BOOT_DRIVER(qcom_rpmh_rsc) = {
619 .name = "qcom_rpmh_rsc",
620 .id = UCLASS_MISC,
621 .priv_auto = sizeof(struct rsc_drv),
622 .probe = rpmh_rsc_probe,
623 //.bind = rpmh_rsc_of_bind,
624 .of_match = qcom_rpmh_ids,
625};