• Home
  • Raw
  • Download

Lines Matching +full:drv +full:- +full:0

1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.
24 #include <soc/qcom/cmd-db.h>
26 #include <dt-bindings/soc/qcom,rpmh-rsc.h>
28 #include "rpmh-internal.h"
31 #include "trace-rpmh.h"
36 /* DRV HW Solver Configuration Information Register */
37 #define DRV_SOLVER_CONFIG 0x04
41 /* DRV TCS Configuration Information Register */
42 #define DRV_PRNT_CHLD_CONFIG 0x0C
43 #define DRV_NUM_TCS_MASK 0x3F
45 #define DRV_NCPT_MASK 0x1F
49 #define RSC_DRV_IRQ_ENABLE 0x00
50 #define RSC_DRV_IRQ_STATUS 0x04
51 #define RSC_DRV_IRQ_CLEAR 0x08 /* w/o; write 1 to clear */
56 * TCSes start at 0x10 from tcs_base and are stored one after another.
60 #define RSC_DRV_CMD_WAIT_FOR_CMPL 0x10 /* 1 bit per command */
61 #define RSC_DRV_CONTROL 0x14
62 #define RSC_DRV_STATUS 0x18 /* zero if tcs is busy */
63 #define RSC_DRV_CMD_ENABLE 0x1C /* 1 bit per command */
68 * Commands (up to 16) start at 0x30 in a TCS; multiply command index
71 #define RSC_DRV_CMD_MSGID 0x30
72 #define RSC_DRV_CMD_ADDR 0x34
73 #define RSC_DRV_CMD_DATA 0x38
74 #define RSC_DRV_CMD_STATUS 0x3C
75 #define RSC_DRV_CMD_RESP_DATA 0x40
91 * - The main rpmh-rsc address is the base of a register space that can
93 * (DRV_PRNT_CHLD_CONFIG). Also found within the rpmh-rsc register
95 * specified in the device tree by "qcom,tcs-offset" and used to
97 * - TCS blocks come one after another. Type, count, and order are
98 * specified by the device tree as "qcom,tcs-config".
99 * - Each TCS block has some registers, then space for up to 16 commands.
105 * +---------------------------------------------------+
110 * | +-----------------------------------------------+ |
116 * | | +------------------------------------------+ | |
118 * | | | ctrl | 0| 1| 2| 3| 4| 5| .| .| .| .|14|15| | |
120 * | | +------------------------------------------+ | |
121 * | | +------------------------------------------+ | |
123 * | | | ctrl | 0| 1| 2| 3| 4| 5| .| .| .| .|14|15| | |
125 * | | +------------------------------------------+ | |
126 * | | +------------------------------------------+ | |
128 * | | | ctrl | 0| 1| 2| 3| 4| 5| .| .| .| .|14|15| | |
130 * | | +------------------------------------------+ | |
132 * | +-----------------------------------------------+ |
133 * | +-----------------------------------------------+ |
136 * | +-----------------------------------------------+ |
138 * +---------------------------------------------------+
142 tcs_reg_addr(const struct rsc_drv *drv, int reg, int tcs_id) in tcs_reg_addr() argument
144 return drv->tcs_base + RSC_DRV_TCS_OFFSET * tcs_id + reg; in tcs_reg_addr()
148 tcs_cmd_addr(const struct rsc_drv *drv, int reg, int tcs_id, int cmd_id) in tcs_cmd_addr() argument
150 return tcs_reg_addr(drv, reg, tcs_id) + RSC_DRV_CMD_OFFSET * cmd_id; in tcs_cmd_addr()
153 static u32 read_tcs_cmd(const struct rsc_drv *drv, int reg, int tcs_id, in read_tcs_cmd() argument
156 return readl_relaxed(tcs_cmd_addr(drv, reg, tcs_id, cmd_id)); in read_tcs_cmd()
159 static u32 read_tcs_reg(const struct rsc_drv *drv, int reg, int tcs_id) in read_tcs_reg() argument
161 return readl_relaxed(tcs_reg_addr(drv, reg, tcs_id)); in read_tcs_reg()
164 static void write_tcs_cmd(const struct rsc_drv *drv, int reg, int tcs_id, in write_tcs_cmd() argument
167 writel_relaxed(data, tcs_cmd_addr(drv, reg, tcs_id, cmd_id)); in write_tcs_cmd()
170 static void write_tcs_reg(const struct rsc_drv *drv, int reg, int tcs_id, in write_tcs_reg() argument
173 writel_relaxed(data, tcs_reg_addr(drv, reg, tcs_id)); in write_tcs_reg()
176 static void write_tcs_reg_sync(const struct rsc_drv *drv, int reg, int tcs_id, in write_tcs_reg_sync() argument
181 writel(data, tcs_reg_addr(drv, reg, tcs_id)); in write_tcs_reg_sync()
187 for (i = 0; i < USEC_PER_SEC; i++) { in write_tcs_reg_sync()
188 if (readl(tcs_reg_addr(drv, reg, tcs_id)) == data) in write_tcs_reg_sync()
192 pr_err("%s: error writing %#x to %d:%#x\n", drv->name, in write_tcs_reg_sync()
197 * tcs_is_free() - Return if a TCS is totally free.
198 * @drv: The RSC controller.
203 * Context: Must be called with the drv->lock held.
207 static bool tcs_is_free(struct rsc_drv *drv, int tcs_id) in tcs_is_free() argument
209 return !test_bit(tcs_id, drv->tcs_in_use); in tcs_is_free()
213 * tcs_invalidate() - Invalidate all TCSes of the given type (sleep or wake).
214 * @drv: The RSC controller.
224 static void tcs_invalidate(struct rsc_drv *drv, int type) in tcs_invalidate() argument
227 struct tcs_group *tcs = &drv->tcs[type]; in tcs_invalidate()
230 if (bitmap_empty(tcs->slots, MAX_TCS_SLOTS)) in tcs_invalidate()
233 for (m = tcs->offset; m < tcs->offset + tcs->num_tcs; m++) { in tcs_invalidate()
234 write_tcs_reg_sync(drv, RSC_DRV_CMD_ENABLE, m, 0); in tcs_invalidate()
235 write_tcs_reg_sync(drv, RSC_DRV_CMD_WAIT_FOR_CMPL, m, 0); in tcs_invalidate()
237 bitmap_zero(tcs->slots, MAX_TCS_SLOTS); in tcs_invalidate()
241 * rpmh_rsc_invalidate() - Invalidate sleep and wake TCSes.
242 * @drv: The RSC controller.
248 void rpmh_rsc_invalidate(struct rsc_drv *drv) in rpmh_rsc_invalidate() argument
250 tcs_invalidate(drv, SLEEP_TCS); in rpmh_rsc_invalidate()
251 tcs_invalidate(drv, WAKE_TCS); in rpmh_rsc_invalidate()
255 * get_tcs_for_msg() - Get the tcs_group used to send the given message.
256 * @drv: The RSC controller.
264 static struct tcs_group *get_tcs_for_msg(struct rsc_drv *drv, in get_tcs_for_msg() argument
270 switch (msg->state) { in get_tcs_for_msg()
281 return ERR_PTR(-EINVAL); in get_tcs_for_msg()
286 * dedicated TCS for active state use, then re-purpose a wake TCS to in get_tcs_for_msg()
287 * send active votes. This is safe because we ensure any active-only in get_tcs_for_msg()
291 tcs = &drv->tcs[type]; in get_tcs_for_msg()
292 if (msg->state == RPMH_ACTIVE_ONLY_STATE && !tcs->num_tcs) in get_tcs_for_msg()
293 tcs = &drv->tcs[WAKE_TCS]; in get_tcs_for_msg()
299 * get_req_from_tcs() - Get a stashed request that was xfering on the given TCS.
300 * @drv: The RSC controller.
314 static const struct tcs_request *get_req_from_tcs(struct rsc_drv *drv, in get_req_from_tcs() argument
320 for (i = 0; i < TCS_TYPE_NR; i++) { in get_req_from_tcs()
321 tcs = &drv->tcs[i]; in get_req_from_tcs()
322 if (tcs->mask & BIT(tcs_id)) in get_req_from_tcs()
323 return tcs->req[tcs_id - tcs->offset]; in get_req_from_tcs()
330 * __tcs_set_trigger() - Start xfer on a TCS or unset trigger on a borrowed TCS
331 * @drv: The controller.
336 * transfer. That will un-trigger/disable the TCS from the last transfer
339 * If we borrowed a wake TCS for an active-only transfer we'll also call
340 * this function with "trigger=false" to just do the un-trigger/disable
343 * Note that the AP is only in charge of triggering active-only transfers.
346 static void __tcs_set_trigger(struct rsc_drv *drv, int tcs_id, bool trigger) in __tcs_set_trigger() argument
355 enable = read_tcs_reg(drv, RSC_DRV_CONTROL, tcs_id); in __tcs_set_trigger()
357 write_tcs_reg_sync(drv, RSC_DRV_CONTROL, tcs_id, enable); in __tcs_set_trigger()
359 write_tcs_reg_sync(drv, RSC_DRV_CONTROL, tcs_id, enable); in __tcs_set_trigger()
364 write_tcs_reg_sync(drv, RSC_DRV_CONTROL, tcs_id, enable); in __tcs_set_trigger()
366 write_tcs_reg_sync(drv, RSC_DRV_CONTROL, tcs_id, enable); in __tcs_set_trigger()
371 * enable_tcs_irq() - Enable or disable interrupts on the given TCS.
372 * @drv: The controller.
376 * We only ever call this when we borrow a wake TCS for an active-only
377 * transfer. For active-only TCSes interrupts are always left enabled.
379 static void enable_tcs_irq(struct rsc_drv *drv, int tcs_id, bool enable) in enable_tcs_irq() argument
383 data = readl_relaxed(drv->tcs_base + RSC_DRV_IRQ_ENABLE); in enable_tcs_irq()
388 writel_relaxed(data, drv->tcs_base + RSC_DRV_IRQ_ENABLE); in enable_tcs_irq()
392 * tcs_tx_done() - TX Done interrupt handler.
403 struct rsc_drv *drv = p; in tcs_tx_done() local
404 int i, j, err = 0; in tcs_tx_done()
409 irq_status = readl_relaxed(drv->tcs_base + RSC_DRV_IRQ_STATUS); in tcs_tx_done()
412 req = get_req_from_tcs(drv, i); in tcs_tx_done()
418 err = 0; in tcs_tx_done()
419 for (j = 0; j < req->num_cmds; j++) { in tcs_tx_done()
422 cmd = &req->cmds[j]; in tcs_tx_done()
423 sts = read_tcs_cmd(drv, RSC_DRV_CMD_STATUS, i, j); in tcs_tx_done()
425 ((req->wait_for_compl || cmd->wait) && in tcs_tx_done()
428 drv->name, cmd->addr, cmd->data); in tcs_tx_done()
429 err = -EIO; in tcs_tx_done()
433 trace_rpmh_tx_done(drv, i, req, err); in tcs_tx_done()
436 * If wake tcs was re-purposed for sending active in tcs_tx_done()
440 if (!drv->tcs[ACTIVE_TCS].num_tcs) in tcs_tx_done()
441 __tcs_set_trigger(drv, i, false); in tcs_tx_done()
444 write_tcs_reg(drv, RSC_DRV_CMD_ENABLE, i, 0); in tcs_tx_done()
445 write_tcs_reg(drv, RSC_DRV_CMD_WAIT_FOR_CMPL, i, 0); in tcs_tx_done()
446 writel_relaxed(BIT(i), drv->tcs_base + RSC_DRV_IRQ_CLEAR); in tcs_tx_done()
447 spin_lock(&drv->lock); in tcs_tx_done()
448 clear_bit(i, drv->tcs_in_use); in tcs_tx_done()
454 if (!drv->tcs[ACTIVE_TCS].num_tcs) in tcs_tx_done()
455 enable_tcs_irq(drv, i, false); in tcs_tx_done()
456 spin_unlock(&drv->lock); in tcs_tx_done()
457 wake_up(&drv->tcs_wait); in tcs_tx_done()
466 * __tcs_buffer_write() - Write to TCS hardware from a request; don't trigger.
467 * @drv: The controller.
475 static void __tcs_buffer_write(struct rsc_drv *drv, int tcs_id, int cmd_id, in __tcs_buffer_write() argument
479 u32 cmd_enable = 0; in __tcs_buffer_write()
485 cmd_msgid |= msg->wait_for_compl ? CMD_MSGID_RESP_REQ : 0; in __tcs_buffer_write()
488 cmd_complete = read_tcs_reg(drv, RSC_DRV_CMD_WAIT_FOR_CMPL, tcs_id); in __tcs_buffer_write()
490 for (i = 0, j = cmd_id; i < msg->num_cmds; i++, j++) { in __tcs_buffer_write()
491 cmd = &msg->cmds[i]; in __tcs_buffer_write()
493 cmd_complete |= cmd->wait << j; in __tcs_buffer_write()
495 msgid |= cmd->wait ? CMD_MSGID_RESP_REQ : 0; in __tcs_buffer_write()
497 write_tcs_cmd(drv, RSC_DRV_CMD_MSGID, tcs_id, j, msgid); in __tcs_buffer_write()
498 write_tcs_cmd(drv, RSC_DRV_CMD_ADDR, tcs_id, j, cmd->addr); in __tcs_buffer_write()
499 write_tcs_cmd(drv, RSC_DRV_CMD_DATA, tcs_id, j, cmd->data); in __tcs_buffer_write()
500 trace_rpmh_send_msg_rcuidle(drv, tcs_id, j, msgid, cmd); in __tcs_buffer_write()
503 write_tcs_reg(drv, RSC_DRV_CMD_WAIT_FOR_CMPL, tcs_id, cmd_complete); in __tcs_buffer_write()
504 cmd_enable |= read_tcs_reg(drv, RSC_DRV_CMD_ENABLE, tcs_id); in __tcs_buffer_write()
505 write_tcs_reg(drv, RSC_DRV_CMD_ENABLE, tcs_id, cmd_enable); in __tcs_buffer_write()
509 * check_for_req_inflight() - Look to see if conflicting cmds are in flight.
510 * @drv: The controller.
517 * one it'll return -EBUSY.
519 * Only for use for active-only transfers.
521 * Must be called with the drv->lock held since that protects tcs_in_use.
523 * Return: 0 if nothing in flight or -EBUSY if we should try again later.
524 * The caller must re-enable interrupts between tries since that's
528 static int check_for_req_inflight(struct rsc_drv *drv, struct tcs_group *tcs, in check_for_req_inflight() argument
534 int tcs_id = tcs->offset; in check_for_req_inflight()
536 for (i = 0; i < tcs->num_tcs; i++, tcs_id++) { in check_for_req_inflight()
537 if (tcs_is_free(drv, tcs_id)) in check_for_req_inflight()
540 curr_enabled = read_tcs_reg(drv, RSC_DRV_CMD_ENABLE, tcs_id); in check_for_req_inflight()
543 addr = read_tcs_cmd(drv, RSC_DRV_CMD_ADDR, tcs_id, j); in check_for_req_inflight()
544 for (k = 0; k < msg->num_cmds; k++) { in check_for_req_inflight()
545 if (addr == msg->cmds[k].addr) in check_for_req_inflight()
546 return -EBUSY; in check_for_req_inflight()
551 return 0; in check_for_req_inflight()
555 * find_free_tcs() - Find free tcs in the given tcs_group; only for active.
556 * @tcs: A pointer to the active-only tcs_group (or the wake tcs_group if
557 * we borrowed it because there are zero active-only ones).
559 * Must be called with the drv->lock held since that protects tcs_in_use.
567 for (i = 0; i < tcs->num_tcs; i++) { in find_free_tcs()
568 if (tcs_is_free(tcs->drv, tcs->offset + i)) in find_free_tcs()
569 return tcs->offset + i; in find_free_tcs()
572 return -EBUSY; in find_free_tcs()
576 * claim_tcs_for_req() - Claim a tcs in the given tcs_group; only for active.
577 * @drv: The controller.
584 * Context: Must be called with the drv->lock held since that protects
587 * Return: The id of the claimed tcs or -EBUSY if a matching msg is in flight
590 static int claim_tcs_for_req(struct rsc_drv *drv, struct tcs_group *tcs, in claim_tcs_for_req() argument
597 * when one is already in-flight or being processed. in claim_tcs_for_req()
599 ret = check_for_req_inflight(drv, tcs, msg); in claim_tcs_for_req()
607 * rpmh_rsc_send_data() - Write / trigger active-only message.
608 * @drv: The controller.
612 * - This is only used for "ACTIVE_ONLY" since the limitations of this
614 * - To do the transfer, we will grab a whole TCS for ourselves--we don't
617 * - This function will not wait for the commands to be finished, only for
620 * - This function must be called with interrupts enabled. If the hardware
626 * Return: 0 on success, -EINVAL on error.
628 int rpmh_rsc_send_data(struct rsc_drv *drv, const struct tcs_request *msg) in rpmh_rsc_send_data() argument
634 tcs = get_tcs_for_msg(drv, msg); in rpmh_rsc_send_data()
638 spin_lock_irqsave(&drv->lock, flags); in rpmh_rsc_send_data()
641 wait_event_lock_irq(drv->tcs_wait, in rpmh_rsc_send_data()
642 (tcs_id = claim_tcs_for_req(drv, tcs, msg)) >= 0, in rpmh_rsc_send_data()
643 drv->lock); in rpmh_rsc_send_data()
645 tcs->req[tcs_id - tcs->offset] = msg; in rpmh_rsc_send_data()
646 set_bit(tcs_id, drv->tcs_in_use); in rpmh_rsc_send_data()
647 if (msg->state == RPMH_ACTIVE_ONLY_STATE && tcs->type != ACTIVE_TCS) { in rpmh_rsc_send_data()
650 * repurposed TCS to avoid triggering them. tcs->slots will be in rpmh_rsc_send_data()
653 write_tcs_reg_sync(drv, RSC_DRV_CMD_ENABLE, tcs_id, 0); in rpmh_rsc_send_data()
654 write_tcs_reg_sync(drv, RSC_DRV_CMD_WAIT_FOR_CMPL, tcs_id, 0); in rpmh_rsc_send_data()
655 enable_tcs_irq(drv, tcs_id, true); in rpmh_rsc_send_data()
657 spin_unlock_irqrestore(&drv->lock, flags); in rpmh_rsc_send_data()
661 * - We marked "tcs_in_use" under lock. in rpmh_rsc_send_data()
662 * - Once "tcs_in_use" has been marked nobody else could be writing in rpmh_rsc_send_data()
664 * - The interrupt can't go off until we trigger w/ the last line in rpmh_rsc_send_data()
667 __tcs_buffer_write(drv, tcs_id, 0, msg); in rpmh_rsc_send_data()
668 __tcs_set_trigger(drv, tcs_id, true); in rpmh_rsc_send_data()
670 return 0; in rpmh_rsc_send_data()
674 * find_slots() - Find a place to write the given message.
677 * @tcs_id: If we return 0 from the function, we return the global ID of the
679 * @cmd_id: If we return 0 from the function, we return the index of
684 * tcs->slots for.
686 * Return: -ENOMEM if there was no room, else 0.
692 int i = 0; in find_slots()
696 slot = bitmap_find_next_zero_area(tcs->slots, MAX_TCS_SLOTS, in find_slots()
697 i, msg->num_cmds, 0); in find_slots()
698 if (slot >= tcs->num_tcs * tcs->ncpt) in find_slots()
699 return -ENOMEM; in find_slots()
700 i += tcs->ncpt; in find_slots()
701 } while (slot + msg->num_cmds - 1 >= i); in find_slots()
703 bitmap_set(tcs->slots, slot, msg->num_cmds); in find_slots()
705 offset = slot / tcs->ncpt; in find_slots()
706 *tcs_id = offset + tcs->offset; in find_slots()
707 *cmd_id = slot % tcs->ncpt; in find_slots()
709 return 0; in find_slots()
713 * rpmh_rsc_write_ctrl_data() - Write request to controller but don't trigger.
714 * @drv: The controller.
717 * This should only be called for for sleep/wake state, never active-only
723 * Return: 0 if no error; else -error.
725 int rpmh_rsc_write_ctrl_data(struct rsc_drv *drv, const struct tcs_request *msg) in rpmh_rsc_write_ctrl_data() argument
728 int tcs_id = 0, cmd_id = 0; in rpmh_rsc_write_ctrl_data()
731 tcs = get_tcs_for_msg(drv, msg); in rpmh_rsc_write_ctrl_data()
738 __tcs_buffer_write(drv, tcs_id, cmd_id, msg); in rpmh_rsc_write_ctrl_data()
744 * rpmh_rsc_ctrlr_is_busy() - Check if any of the AMCs are busy.
745 * @drv: The controller
752 * Context: Must be called with the drv->lock held.
755 * * False - AMCs are idle
756 * * True - AMCs are busy
758 static bool rpmh_rsc_ctrlr_is_busy(struct rsc_drv *drv) in rpmh_rsc_ctrlr_is_busy() argument
761 struct tcs_group *tcs = &drv->tcs[ACTIVE_TCS]; in rpmh_rsc_ctrlr_is_busy()
765 * dedicated TCS for active state use, then re-purposed wake TCSes in rpmh_rsc_ctrlr_is_busy()
769 if (!tcs->num_tcs) in rpmh_rsc_ctrlr_is_busy()
770 tcs = &drv->tcs[WAKE_TCS]; in rpmh_rsc_ctrlr_is_busy()
772 for (m = tcs->offset; m < tcs->offset + tcs->num_tcs; m++) { in rpmh_rsc_ctrlr_is_busy()
773 if (!tcs_is_free(drv, m)) in rpmh_rsc_ctrlr_is_busy()
781 * rpmh_rsc_cpu_pm_callback() - Check if any of the AMCs are busy.
800 struct rsc_drv *drv = container_of(nfb, struct rsc_drv, rsc_pm); in rpmh_rsc_cpu_pm_callback() local
806 cpus_in_pm = atomic_inc_return(&drv->cpus_in_pm); in rpmh_rsc_cpu_pm_callback()
813 * AND that CPU was not idle AND that CPU was the last non-idle in rpmh_rsc_cpu_pm_callback()
822 atomic_dec(&drv->cpus_in_pm); in rpmh_rsc_cpu_pm_callback()
829 * It's likely we're on the last CPU. Grab the drv->lock and write in rpmh_rsc_cpu_pm_callback()
840 if (spin_trylock(&drv->lock)) { in rpmh_rsc_cpu_pm_callback()
841 if (rpmh_rsc_ctrlr_is_busy(drv) || rpmh_flush(&drv->client)) in rpmh_rsc_cpu_pm_callback()
843 spin_unlock(&drv->lock); in rpmh_rsc_cpu_pm_callback()
850 /* Double-check if we're here because someone else is up */ in rpmh_rsc_cpu_pm_callback()
855 atomic_dec(&drv->cpus_in_pm); in rpmh_rsc_cpu_pm_callback()
862 struct rsc_drv *drv, void __iomem *base) in rpmh_probe_tcs_config() argument
867 } tcs_cfg[TCS_TYPE_NR] = { { 0 } }; in rpmh_probe_tcs_config()
868 struct device_node *dn = pdev->dev.of_node; in rpmh_probe_tcs_config()
870 int i, ret, n, st = 0; in rpmh_probe_tcs_config()
873 ret = of_property_read_u32(dn, "qcom,tcs-offset", &offset); in rpmh_probe_tcs_config()
876 drv->tcs_base = base + offset; in rpmh_probe_tcs_config()
881 max_tcs &= DRV_NUM_TCS_MASK << (DRV_NUM_TCS_SHIFT * drv->id); in rpmh_probe_tcs_config()
882 max_tcs = max_tcs >> (DRV_NUM_TCS_SHIFT * drv->id); in rpmh_probe_tcs_config()
887 n = of_property_count_u32_elems(dn, "qcom,tcs-config"); in rpmh_probe_tcs_config()
889 return -EINVAL; in rpmh_probe_tcs_config()
891 for (i = 0; i < TCS_TYPE_NR; i++) { in rpmh_probe_tcs_config()
892 ret = of_property_read_u32_index(dn, "qcom,tcs-config", in rpmh_probe_tcs_config()
897 return -EINVAL; in rpmh_probe_tcs_config()
899 ret = of_property_read_u32_index(dn, "qcom,tcs-config", in rpmh_probe_tcs_config()
904 return -EINVAL; in rpmh_probe_tcs_config()
907 for (i = 0; i < TCS_TYPE_NR; i++) { in rpmh_probe_tcs_config()
908 tcs = &drv->tcs[tcs_cfg[i].type]; in rpmh_probe_tcs_config()
909 if (tcs->drv) in rpmh_probe_tcs_config()
910 return -EINVAL; in rpmh_probe_tcs_config()
911 tcs->drv = drv; in rpmh_probe_tcs_config()
912 tcs->type = tcs_cfg[i].type; in rpmh_probe_tcs_config()
913 tcs->num_tcs = tcs_cfg[i].n; in rpmh_probe_tcs_config()
914 tcs->ncpt = ncpt; in rpmh_probe_tcs_config()
916 if (!tcs->num_tcs || tcs->type == CONTROL_TCS) in rpmh_probe_tcs_config()
919 if (st + tcs->num_tcs > max_tcs || in rpmh_probe_tcs_config()
920 st + tcs->num_tcs >= BITS_PER_BYTE * sizeof(tcs->mask)) in rpmh_probe_tcs_config()
921 return -EINVAL; in rpmh_probe_tcs_config()
923 tcs->mask = ((1 << tcs->num_tcs) - 1) << st; in rpmh_probe_tcs_config()
924 tcs->offset = st; in rpmh_probe_tcs_config()
925 st += tcs->num_tcs; in rpmh_probe_tcs_config()
928 drv->num_tcs = st; in rpmh_probe_tcs_config()
930 return 0; in rpmh_probe_tcs_config()
935 struct device_node *dn = pdev->dev.of_node; in rpmh_rsc_probe()
936 struct rsc_drv *drv; in rpmh_rsc_probe() local
938 char drv_id[10] = {0}; in rpmh_rsc_probe()
944 * Even though RPMh doesn't directly use cmd-db, all of its children in rpmh_rsc_probe()
949 if (ret != -EPROBE_DEFER) in rpmh_rsc_probe()
950 dev_err(&pdev->dev, "Command DB not available (%d)\n", in rpmh_rsc_probe()
955 drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL); in rpmh_rsc_probe()
956 if (!drv) in rpmh_rsc_probe()
957 return -ENOMEM; in rpmh_rsc_probe()
959 ret = of_property_read_u32(dn, "qcom,drv-id", &drv->id); in rpmh_rsc_probe()
963 drv->name = of_get_property(dn, "label", NULL); in rpmh_rsc_probe()
964 if (!drv->name) in rpmh_rsc_probe()
965 drv->name = dev_name(&pdev->dev); in rpmh_rsc_probe()
967 snprintf(drv_id, ARRAY_SIZE(drv_id), "drv-%d", drv->id); in rpmh_rsc_probe()
969 base = devm_ioremap_resource(&pdev->dev, res); in rpmh_rsc_probe()
973 ret = rpmh_probe_tcs_config(pdev, drv, base); in rpmh_rsc_probe()
977 spin_lock_init(&drv->lock); in rpmh_rsc_probe()
978 init_waitqueue_head(&drv->tcs_wait); in rpmh_rsc_probe()
979 bitmap_zero(drv->tcs_in_use, MAX_TCS_NR); in rpmh_rsc_probe()
981 irq = platform_get_irq(pdev, drv->id); in rpmh_rsc_probe()
982 if (irq < 0) in rpmh_rsc_probe()
985 ret = devm_request_irq(&pdev->dev, irq, tcs_tx_done, in rpmh_rsc_probe()
987 drv->name, drv); in rpmh_rsc_probe()
1000 drv->rsc_pm.notifier_call = rpmh_rsc_cpu_pm_callback; in rpmh_rsc_probe()
1001 cpu_pm_register_notifier(&drv->rsc_pm); in rpmh_rsc_probe()
1005 writel_relaxed(drv->tcs[ACTIVE_TCS].mask, in rpmh_rsc_probe()
1006 drv->tcs_base + RSC_DRV_IRQ_ENABLE); in rpmh_rsc_probe()
1008 spin_lock_init(&drv->client.cache_lock); in rpmh_rsc_probe()
1009 INIT_LIST_HEAD(&drv->client.cache); in rpmh_rsc_probe()
1010 INIT_LIST_HEAD(&drv->client.batch_cache); in rpmh_rsc_probe()
1012 dev_set_drvdata(&pdev->dev, drv); in rpmh_rsc_probe()
1014 return devm_of_platform_populate(&pdev->dev); in rpmh_rsc_probe()
1018 { .compatible = "qcom,rpmh-rsc", },