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.
30 #include <soc/qcom/cmd-db.h>
32 #include <dt-bindings/soc/qcom,rpmh-rsc.h>
34 #include "rpmh-internal.h"
37 #include "trace-rpmh.h"
40 #define RSC_DRV_ID 0
42 #define MAJOR_VER_MASK 0xFF
44 #define MINOR_VER_MASK 0xFF
66 /* DRV HW Solver Configuration Information Register */
70 /* DRV TCS Configuration Information Register */
71 #define DRV_NUM_TCS_MASK 0x3F
73 #define DRV_NCPT_MASK 0x1F
77 #define RSC_DRV_CTL_TCS_DATA_HI 0x38
78 #define RSC_DRV_CTL_TCS_DATA_HI_MASK 0xFFFFFF
80 #define RSC_DRV_CTL_TCS_DATA_LO 0x40
81 #define RSC_DRV_CTL_TCS_DATA_LO_MASK 0xFFFFFFFF
98 * - The main rpmh-rsc address is the base of a register space that can
100 * (DRV_PRNT_CHLD_CONFIG). Also found within the rpmh-rsc register
102 * specified in the device tree by "qcom,tcs-offset" and used to
104 * - TCS blocks come one after another. Type, count, and order are
105 * specified by the device tree as "qcom,tcs-config".
106 * - Each TCS block has some registers, then space for up to 16 commands.
112 * +---------------------------------------------------+
117 * | +-----------------------------------------------+ |
123 * | | +------------------------------------------+ | |
125 * | | | ctrl | 0| 1| 2| 3| 4| 5| .| .| .| .|14|15| | |
127 * | | +------------------------------------------+ | |
128 * | | +------------------------------------------+ | |
130 * | | | ctrl | 0| 1| 2| 3| 4| 5| .| .| .| .|14|15| | |
132 * | | +------------------------------------------+ | |
133 * | | +------------------------------------------+ | |
135 * | | | ctrl | 0| 1| 2| 3| 4| 5| .| .| .| .|14|15| | |
137 * | | +------------------------------------------+ | |
139 * | +-----------------------------------------------+ |
140 * | +-----------------------------------------------+ |
143 * | +-----------------------------------------------+ |
145 * +---------------------------------------------------+
149 xloops_to_cycles((time_usecs) * 0x10C7UL)
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] = 0x10,
165 [RSC_DRV_CONTROL] = 0x14,
166 [RSC_DRV_STATUS] = 0x18,
167 [RSC_DRV_CMD_ENABLE] = 0x1C,
168 [RSC_DRV_CMD_MSGID] = 0x30,
169 [RSC_DRV_CMD_ADDR] = 0x34,
170 [RSC_DRV_CMD_DATA] = 0x38,
171 [RSC_DRV_CMD_STATUS] = 0x3C,
172 [RSC_DRV_CMD_RESP_DATA] = 0x40,
178 [DRV_SOLVER_CONFIG] = 0x04,
179 [DRV_PRNT_CHLD_CONFIG] = 0x0C,
180 [RSC_DRV_IRQ_ENABLE] = 0x00,
181 [RSC_DRV_IRQ_STATUS] = 0x04,
182 [RSC_DRV_IRQ_CLEAR] = 0x08,
183 [RSC_DRV_CMD_WAIT_FOR_CMPL] = 0x20,
184 [RSC_DRV_CONTROL] = 0x24,
185 [RSC_DRV_STATUS] = 0x28,
186 [RSC_DRV_CMD_ENABLE] = 0x2C,
187 [RSC_DRV_CMD_MSGID] = 0x34,
188 [RSC_DRV_CMD_ADDR] = 0x38,
189 [RSC_DRV_CMD_DATA] = 0x3C,
190 [RSC_DRV_CMD_STATUS] = 0x40,
191 [RSC_DRV_CMD_RESP_DATA] = 0x44,
195 tcs_reg_addr(const struct rsc_drv *drv, int reg, int tcs_id) in tcs_reg_addr() argument
197 return drv->tcs_base + drv->regs[RSC_DRV_TCS_OFFSET] * tcs_id + reg; in tcs_reg_addr()
201 tcs_cmd_addr(const struct rsc_drv *drv, int reg, int tcs_id, int cmd_id) in tcs_cmd_addr() argument
203 return tcs_reg_addr(drv, reg, tcs_id) + drv->regs[RSC_DRV_CMD_OFFSET] * cmd_id; in tcs_cmd_addr()
206 static u32 read_tcs_cmd(const struct rsc_drv *drv, int reg, int tcs_id, in read_tcs_cmd() argument
209 return readl_relaxed(tcs_cmd_addr(drv, reg, tcs_id, cmd_id)); in read_tcs_cmd()
212 static u32 read_tcs_reg(const struct rsc_drv *drv, int reg, int tcs_id) in read_tcs_reg() argument
214 return readl_relaxed(tcs_reg_addr(drv, reg, tcs_id)); in read_tcs_reg()
217 static void write_tcs_cmd(const struct rsc_drv *drv, int reg, int tcs_id, in write_tcs_cmd() argument
220 writel_relaxed(data, tcs_cmd_addr(drv, reg, tcs_id, cmd_id)); in write_tcs_cmd()
223 static void write_tcs_reg(const struct rsc_drv *drv, int reg, int tcs_id, in write_tcs_reg() argument
226 writel_relaxed(data, tcs_reg_addr(drv, reg, tcs_id)); in write_tcs_reg()
229 static void write_tcs_reg_sync(const struct rsc_drv *drv, int reg, int tcs_id, in write_tcs_reg_sync() argument
234 writel(data, tcs_reg_addr(drv, reg, tcs_id)); in write_tcs_reg_sync()
240 for (i = 0; i < USEC_PER_SEC; i++) { in write_tcs_reg_sync()
241 if (readl(tcs_reg_addr(drv, reg, tcs_id)) == data) in write_tcs_reg_sync()
245 pr_err("%s: error writing %#x to %d:%#x\n", drv->name, in write_tcs_reg_sync()
250 * tcs_invalidate() - Invalidate all TCSes of the given type (sleep or wake).
251 * @drv: The RSC controller.
261 static void tcs_invalidate(struct rsc_drv *drv, int type) in tcs_invalidate() argument
264 struct tcs_group *tcs = &drv->tcs[type]; in tcs_invalidate()
267 if (bitmap_empty(tcs->slots, MAX_TCS_SLOTS)) in tcs_invalidate()
270 for (m = tcs->offset; m < tcs->offset + tcs->num_tcs; m++) in tcs_invalidate()
271 write_tcs_reg_sync(drv, drv->regs[RSC_DRV_CMD_ENABLE], m, 0); in tcs_invalidate()
273 bitmap_zero(tcs->slots, MAX_TCS_SLOTS); in tcs_invalidate()
277 * rpmh_rsc_invalidate() - Invalidate sleep and wake TCSes.
278 * @drv: The RSC controller.
284 void rpmh_rsc_invalidate(struct rsc_drv *drv) in rpmh_rsc_invalidate() argument
286 tcs_invalidate(drv, SLEEP_TCS); in rpmh_rsc_invalidate()
287 tcs_invalidate(drv, WAKE_TCS); in rpmh_rsc_invalidate()
291 * get_tcs_for_msg() - Get the tcs_group used to send the given message.
292 * @drv: The RSC controller.
300 static struct tcs_group *get_tcs_for_msg(struct rsc_drv *drv, in get_tcs_for_msg() argument
306 switch (msg->state) { in get_tcs_for_msg()
317 return ERR_PTR(-EINVAL); in get_tcs_for_msg()
322 * dedicated TCS for active state use, then re-purpose a wake TCS to in get_tcs_for_msg()
323 * send active votes. This is safe because we ensure any active-only in get_tcs_for_msg()
327 tcs = &drv->tcs[type]; in get_tcs_for_msg()
328 if (msg->state == RPMH_ACTIVE_ONLY_STATE && !tcs->num_tcs) in get_tcs_for_msg()
329 tcs = &drv->tcs[WAKE_TCS]; in get_tcs_for_msg()
335 * get_req_from_tcs() - Get a stashed request that was xfering on the given TCS.
336 * @drv: The RSC controller.
350 static const struct tcs_request *get_req_from_tcs(struct rsc_drv *drv, in get_req_from_tcs() argument
356 for (i = 0; i < TCS_TYPE_NR; i++) { in get_req_from_tcs()
357 tcs = &drv->tcs[i]; in get_req_from_tcs()
358 if (tcs->mask & BIT(tcs_id)) in get_req_from_tcs()
359 return tcs->req[tcs_id - tcs->offset]; in get_req_from_tcs()
366 * __tcs_set_trigger() - Start xfer on a TCS or unset trigger on a borrowed TCS
367 * @drv: The controller.
372 * transfer. That will un-trigger/disable the TCS from the last transfer
375 * If we borrowed a wake TCS for an active-only transfer we'll also call
376 * this function with "trigger=false" to just do the un-trigger/disable
379 * Note that the AP is only in charge of triggering active-only transfers.
382 static void __tcs_set_trigger(struct rsc_drv *drv, int tcs_id, bool trigger) in __tcs_set_trigger() argument
385 u32 reg = drv->regs[RSC_DRV_CONTROL]; in __tcs_set_trigger()
392 enable = read_tcs_reg(drv, reg, tcs_id); in __tcs_set_trigger()
394 write_tcs_reg_sync(drv, reg, tcs_id, enable); in __tcs_set_trigger()
396 write_tcs_reg_sync(drv, reg, tcs_id, enable); in __tcs_set_trigger()
401 write_tcs_reg_sync(drv, reg, tcs_id, enable); in __tcs_set_trigger()
403 write_tcs_reg(drv, reg, tcs_id, enable); in __tcs_set_trigger()
408 * enable_tcs_irq() - Enable or disable interrupts on the given TCS.
409 * @drv: The controller.
413 * We only ever call this when we borrow a wake TCS for an active-only
414 * transfer. For active-only TCSes interrupts are always left enabled.
416 static void enable_tcs_irq(struct rsc_drv *drv, int tcs_id, bool enable) in enable_tcs_irq() argument
419 u32 reg = drv->regs[RSC_DRV_IRQ_ENABLE]; in enable_tcs_irq()
421 data = readl_relaxed(drv->tcs_base + reg); in enable_tcs_irq()
426 writel_relaxed(data, drv->tcs_base + reg); in enable_tcs_irq()
430 * tcs_tx_done() - TX Done interrupt handler.
441 struct rsc_drv *drv = p; in tcs_tx_done() local
446 irq_status = readl_relaxed(drv->tcs_base + drv->regs[RSC_DRV_IRQ_STATUS]); in tcs_tx_done()
449 req = get_req_from_tcs(drv, i); in tcs_tx_done()
453 trace_rpmh_tx_done(drv, i, req); in tcs_tx_done()
456 * If wake tcs was re-purposed for sending active in tcs_tx_done()
460 if (!drv->tcs[ACTIVE_TCS].num_tcs) in tcs_tx_done()
461 __tcs_set_trigger(drv, i, false); in tcs_tx_done()
464 write_tcs_reg(drv, drv->regs[RSC_DRV_CMD_ENABLE], i, 0); in tcs_tx_done()
465 writel_relaxed(BIT(i), drv->tcs_base + drv->regs[RSC_DRV_IRQ_CLEAR]); in tcs_tx_done()
466 spin_lock(&drv->lock); in tcs_tx_done()
467 clear_bit(i, drv->tcs_in_use); in tcs_tx_done()
473 if (!drv->tcs[ACTIVE_TCS].num_tcs) in tcs_tx_done()
474 enable_tcs_irq(drv, i, false); in tcs_tx_done()
475 spin_unlock(&drv->lock); in tcs_tx_done()
476 wake_up(&drv->tcs_wait); in tcs_tx_done()
485 * __tcs_buffer_write() - Write to TCS hardware from a request; don't trigger.
486 * @drv: The controller.
494 static void __tcs_buffer_write(struct rsc_drv *drv, int tcs_id, int cmd_id, in __tcs_buffer_write() argument
499 u32 cmd_enable = 0; in __tcs_buffer_write()
504 cmd_msgid |= msg->wait_for_compl ? CMD_MSGID_RESP_REQ : 0; in __tcs_buffer_write()
506 for (i = 0, j = cmd_id; i < msg->num_cmds; i++, j++) { in __tcs_buffer_write()
507 cmd = &msg->cmds[i]; in __tcs_buffer_write()
511 * Additionally, if the cmd->wait is set, make the command in __tcs_buffer_write()
512 * response reqd even if the overall request was fire-n-forget. in __tcs_buffer_write()
514 msgid |= cmd->wait ? CMD_MSGID_RESP_REQ : 0; in __tcs_buffer_write()
516 write_tcs_cmd(drv, drv->regs[RSC_DRV_CMD_MSGID], tcs_id, j, msgid); in __tcs_buffer_write()
517 write_tcs_cmd(drv, drv->regs[RSC_DRV_CMD_ADDR], tcs_id, j, cmd->addr); in __tcs_buffer_write()
518 write_tcs_cmd(drv, drv->regs[RSC_DRV_CMD_DATA], tcs_id, j, cmd->data); in __tcs_buffer_write()
519 trace_rpmh_send_msg(drv, tcs_id, msg->state, j, msgid, cmd); in __tcs_buffer_write()
522 cmd_enable |= read_tcs_reg(drv, drv->regs[RSC_DRV_CMD_ENABLE], tcs_id); in __tcs_buffer_write()
523 write_tcs_reg(drv, drv->regs[RSC_DRV_CMD_ENABLE], tcs_id, cmd_enable); in __tcs_buffer_write()
527 * check_for_req_inflight() - Look to see if conflicting cmds are in flight.
528 * @drv: The controller.
535 * one it'll return -EBUSY.
537 * Only for use for active-only transfers.
539 * Must be called with the drv->lock held since that protects tcs_in_use.
541 * Return: 0 if nothing in flight or -EBUSY if we should try again later.
542 * The caller must re-enable interrupts between tries since that's
546 static int check_for_req_inflight(struct rsc_drv *drv, struct tcs_group *tcs, in check_for_req_inflight() argument
552 int i = tcs->offset; in check_for_req_inflight()
554 for_each_set_bit_from(i, drv->tcs_in_use, tcs->offset + tcs->num_tcs) { in check_for_req_inflight()
555 curr_enabled = read_tcs_reg(drv, drv->regs[RSC_DRV_CMD_ENABLE], i); in check_for_req_inflight()
558 addr = read_tcs_cmd(drv, drv->regs[RSC_DRV_CMD_ADDR], i, j); in check_for_req_inflight()
559 for (k = 0; k < msg->num_cmds; k++) { in check_for_req_inflight()
560 if (addr == msg->cmds[k].addr) in check_for_req_inflight()
561 return -EBUSY; in check_for_req_inflight()
566 return 0; in check_for_req_inflight()
570 * find_free_tcs() - Find free tcs in the given tcs_group; only for active.
571 * @tcs: A pointer to the active-only tcs_group (or the wake tcs_group if
572 * we borrowed it because there are zero active-only ones).
574 * Must be called with the drv->lock held since that protects tcs_in_use.
576 * Return: The first tcs that's free or -EBUSY if all in use.
580 const struct rsc_drv *drv = tcs->drv; in find_free_tcs() local
582 unsigned long max = tcs->offset + tcs->num_tcs; in find_free_tcs()
584 i = find_next_zero_bit(drv->tcs_in_use, max, tcs->offset); in find_free_tcs()
586 return -EBUSY; in find_free_tcs()
592 * claim_tcs_for_req() - Claim a tcs in the given tcs_group; only for active.
593 * @drv: The controller.
600 * Context: Must be called with the drv->lock held since that protects
603 * Return: The id of the claimed tcs or -EBUSY if a matching msg is in flight
606 static int claim_tcs_for_req(struct rsc_drv *drv, struct tcs_group *tcs, in claim_tcs_for_req() argument
613 * when one is already in-flight or being processed. in claim_tcs_for_req()
615 ret = check_for_req_inflight(drv, tcs, msg); in claim_tcs_for_req()
623 * rpmh_rsc_send_data() - Write / trigger active-only message.
624 * @drv: The controller.
628 * - This is only used for "ACTIVE_ONLY" since the limitations of this
630 * - To do the transfer, we will grab a whole TCS for ourselves--we don't
633 * - This function will not wait for the commands to be finished, only for
636 * - This function must be called with interrupts enabled. If the hardware
642 * Return: 0 on success, -EINVAL on error.
644 int rpmh_rsc_send_data(struct rsc_drv *drv, const struct tcs_request *msg) in rpmh_rsc_send_data() argument
650 tcs = get_tcs_for_msg(drv, msg); in rpmh_rsc_send_data()
654 spin_lock_irqsave(&drv->lock, flags); in rpmh_rsc_send_data()
657 wait_event_lock_irq(drv->tcs_wait, in rpmh_rsc_send_data()
658 (tcs_id = claim_tcs_for_req(drv, tcs, msg)) >= 0, in rpmh_rsc_send_data()
659 drv->lock); in rpmh_rsc_send_data()
661 tcs->req[tcs_id - tcs->offset] = msg; in rpmh_rsc_send_data()
662 set_bit(tcs_id, drv->tcs_in_use); in rpmh_rsc_send_data()
663 if (msg->state == RPMH_ACTIVE_ONLY_STATE && tcs->type != ACTIVE_TCS) { in rpmh_rsc_send_data()
666 * repurposed TCS to avoid triggering them. tcs->slots will be in rpmh_rsc_send_data()
669 write_tcs_reg_sync(drv, drv->regs[RSC_DRV_CMD_ENABLE], tcs_id, 0); in rpmh_rsc_send_data()
670 enable_tcs_irq(drv, tcs_id, true); in rpmh_rsc_send_data()
672 spin_unlock_irqrestore(&drv->lock, flags); in rpmh_rsc_send_data()
676 * - We marked "tcs_in_use" under lock. in rpmh_rsc_send_data()
677 * - Once "tcs_in_use" has been marked nobody else could be writing in rpmh_rsc_send_data()
679 * - The interrupt can't go off until we trigger w/ the last line in rpmh_rsc_send_data()
682 __tcs_buffer_write(drv, tcs_id, 0, msg); in rpmh_rsc_send_data()
683 __tcs_set_trigger(drv, tcs_id, true); in rpmh_rsc_send_data()
685 return 0; in rpmh_rsc_send_data()
689 * find_slots() - Find a place to write the given message.
692 * @tcs_id: If we return 0 from the function, we return the global ID of the
694 * @cmd_id: If we return 0 from the function, we return the index of
699 * tcs->slots for.
701 * Return: -ENOMEM if there was no room, else 0.
707 int i = 0; in find_slots()
711 slot = bitmap_find_next_zero_area(tcs->slots, MAX_TCS_SLOTS, in find_slots()
712 i, msg->num_cmds, 0); in find_slots()
713 if (slot >= tcs->num_tcs * tcs->ncpt) in find_slots()
714 return -ENOMEM; in find_slots()
715 i += tcs->ncpt; in find_slots()
716 } while (slot + msg->num_cmds - 1 >= i); in find_slots()
718 bitmap_set(tcs->slots, slot, msg->num_cmds); in find_slots()
720 offset = slot / tcs->ncpt; in find_slots()
721 *tcs_id = offset + tcs->offset; in find_slots()
722 *cmd_id = slot % tcs->ncpt; in find_slots()
724 return 0; in find_slots()
728 * rpmh_rsc_write_ctrl_data() - Write request to controller but don't trigger.
729 * @drv: The controller.
732 * This should only be called for sleep/wake state, never active-only
738 * Return: 0 if no error; else -error.
740 int rpmh_rsc_write_ctrl_data(struct rsc_drv *drv, const struct tcs_request *msg) in rpmh_rsc_write_ctrl_data() argument
743 int tcs_id = 0, cmd_id = 0; in rpmh_rsc_write_ctrl_data()
746 tcs = get_tcs_for_msg(drv, msg); in rpmh_rsc_write_ctrl_data()
753 __tcs_buffer_write(drv, tcs_id, cmd_id, msg); in rpmh_rsc_write_ctrl_data()
759 * rpmh_rsc_ctrlr_is_busy() - Check if any of the AMCs are busy.
760 * @drv: The controller
767 * Context: Must be called with the drv->lock held.
770 * * False - AMCs are idle
771 * * True - AMCs are busy
773 static bool rpmh_rsc_ctrlr_is_busy(struct rsc_drv *drv) in rpmh_rsc_ctrlr_is_busy() argument
776 const struct tcs_group *tcs = &drv->tcs[ACTIVE_TCS]; in rpmh_rsc_ctrlr_is_busy()
781 * dedicated TCS for active state use, then re-purposed wake TCSes in rpmh_rsc_ctrlr_is_busy()
785 if (!tcs->num_tcs) in rpmh_rsc_ctrlr_is_busy()
786 tcs = &drv->tcs[WAKE_TCS]; in rpmh_rsc_ctrlr_is_busy()
788 max = tcs->offset + tcs->num_tcs; in rpmh_rsc_ctrlr_is_busy()
789 set = find_next_bit(drv->tcs_in_use, max, tcs->offset); in rpmh_rsc_ctrlr_is_busy()
795 * rpmh_rsc_write_next_wakeup() - Write next wakeup in CONTROL_TCS.
796 * @drv: The controller
801 void rpmh_rsc_write_next_wakeup(struct rsc_drv *drv) in rpmh_rsc_write_next_wakeup() argument
804 u64 wakeup_us, wakeup_cycles = ~0; in rpmh_rsc_write_next_wakeup()
807 if (!drv->tcs[CONTROL_TCS].num_tcs || !drv->genpd_nb.notifier_call) in rpmh_rsc_write_next_wakeup()
815 wakeup = dev_pm_genpd_get_next_hrtimer(drv->dev); in rpmh_rsc_write_next_wakeup()
832 writel_relaxed(lo, drv->base + RSC_DRV_CTL_TCS_DATA_LO); in rpmh_rsc_write_next_wakeup()
833 writel_relaxed(hi, drv->base + RSC_DRV_CTL_TCS_DATA_HI); in rpmh_rsc_write_next_wakeup()
837 * rpmh_rsc_cpu_pm_callback() - Check if any of the AMCs are busy.
856 struct rsc_drv *drv = container_of(nfb, struct rsc_drv, rsc_pm); in rpmh_rsc_cpu_pm_callback() local
862 cpus_in_pm = atomic_inc_return(&drv->cpus_in_pm); in rpmh_rsc_cpu_pm_callback()
869 * AND that CPU was not idle AND that CPU was the last non-idle in rpmh_rsc_cpu_pm_callback()
878 atomic_dec(&drv->cpus_in_pm); in rpmh_rsc_cpu_pm_callback()
885 * It's likely we're on the last CPU. Grab the drv->lock and write in rpmh_rsc_cpu_pm_callback()
896 if (spin_trylock(&drv->lock)) { in rpmh_rsc_cpu_pm_callback()
897 if (rpmh_rsc_ctrlr_is_busy(drv) || rpmh_flush(&drv->client)) in rpmh_rsc_cpu_pm_callback()
899 spin_unlock(&drv->lock); in rpmh_rsc_cpu_pm_callback()
906 /* Double-check if we're here because someone else is up */ in rpmh_rsc_cpu_pm_callback()
911 atomic_dec(&drv->cpus_in_pm); in rpmh_rsc_cpu_pm_callback()
918 * rpmh_rsc_pd_callback() - Check if any of the AMCs are busy.
924 * about when cluster-pd is going down. When cluster go down we know no more active
932 * * NOTIFY_OK - success
933 * * NOTIFY_BAD - failure
938 struct rsc_drv *drv = container_of(nfb, struct rsc_drv, genpd_nb); in rpmh_rsc_pd_callback() local
942 (rpmh_rsc_ctrlr_is_busy(drv) || rpmh_flush(&drv->client))) in rpmh_rsc_pd_callback()
948 static int rpmh_rsc_pd_attach(struct rsc_drv *drv, struct device *dev) in rpmh_rsc_pd_attach() argument
953 drv->genpd_nb.notifier_call = rpmh_rsc_pd_callback; in rpmh_rsc_pd_attach()
954 ret = dev_pm_genpd_add_notifier(dev, &drv->genpd_nb); in rpmh_rsc_pd_attach()
961 static int rpmh_probe_tcs_config(struct platform_device *pdev, struct rsc_drv *drv) in rpmh_probe_tcs_config() argument
966 } tcs_cfg[TCS_TYPE_NR] = { { 0 } }; in rpmh_probe_tcs_config()
967 struct device_node *dn = pdev->dev.of_node; in rpmh_probe_tcs_config()
969 int i, ret, n, st = 0; in rpmh_probe_tcs_config()
972 ret = of_property_read_u32(dn, "qcom,tcs-offset", &offset); in rpmh_probe_tcs_config()
975 drv->tcs_base = drv->base + offset; in rpmh_probe_tcs_config()
977 config = readl_relaxed(drv->base + drv->regs[DRV_PRNT_CHLD_CONFIG]); in rpmh_probe_tcs_config()
980 max_tcs &= DRV_NUM_TCS_MASK << (DRV_NUM_TCS_SHIFT * drv->id); in rpmh_probe_tcs_config()
981 max_tcs = max_tcs >> (DRV_NUM_TCS_SHIFT * drv->id); in rpmh_probe_tcs_config()
986 n = of_property_count_u32_elems(dn, "qcom,tcs-config"); in rpmh_probe_tcs_config()
988 return -EINVAL; in rpmh_probe_tcs_config()
990 for (i = 0; i < TCS_TYPE_NR; i++) { in rpmh_probe_tcs_config()
991 ret = of_property_read_u32_index(dn, "qcom,tcs-config", in rpmh_probe_tcs_config()
996 return -EINVAL; in rpmh_probe_tcs_config()
998 ret = of_property_read_u32_index(dn, "qcom,tcs-config", in rpmh_probe_tcs_config()
1003 return -EINVAL; in rpmh_probe_tcs_config()
1006 for (i = 0; i < TCS_TYPE_NR; i++) { in rpmh_probe_tcs_config()
1007 tcs = &drv->tcs[tcs_cfg[i].type]; in rpmh_probe_tcs_config()
1008 if (tcs->drv) in rpmh_probe_tcs_config()
1009 return -EINVAL; in rpmh_probe_tcs_config()
1010 tcs->drv = drv; in rpmh_probe_tcs_config()
1011 tcs->type = tcs_cfg[i].type; in rpmh_probe_tcs_config()
1012 tcs->num_tcs = tcs_cfg[i].n; in rpmh_probe_tcs_config()
1013 tcs->ncpt = ncpt; in rpmh_probe_tcs_config()
1015 if (!tcs->num_tcs || tcs->type == CONTROL_TCS) in rpmh_probe_tcs_config()
1018 if (st + tcs->num_tcs > max_tcs || in rpmh_probe_tcs_config()
1019 st + tcs->num_tcs >= BITS_PER_BYTE * sizeof(tcs->mask)) in rpmh_probe_tcs_config()
1020 return -EINVAL; in rpmh_probe_tcs_config()
1022 tcs->mask = ((1 << tcs->num_tcs) - 1) << st; in rpmh_probe_tcs_config()
1023 tcs->offset = st; in rpmh_probe_tcs_config()
1024 st += tcs->num_tcs; in rpmh_probe_tcs_config()
1027 drv->num_tcs = st; in rpmh_probe_tcs_config()
1029 return 0; in rpmh_probe_tcs_config()
1034 struct device_node *dn = pdev->dev.of_node; in rpmh_rsc_probe()
1035 struct rsc_drv *drv; in rpmh_rsc_probe() local
1036 char drv_id[10] = {0}; in rpmh_rsc_probe()
1042 * Even though RPMh doesn't directly use cmd-db, all of its children in rpmh_rsc_probe()
1047 if (ret != -EPROBE_DEFER) in rpmh_rsc_probe()
1048 dev_err(&pdev->dev, "Command DB not available (%d)\n", in rpmh_rsc_probe()
1053 drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL); in rpmh_rsc_probe()
1054 if (!drv) in rpmh_rsc_probe()
1055 return -ENOMEM; in rpmh_rsc_probe()
1057 ret = of_property_read_u32(dn, "qcom,drv-id", &drv->id); in rpmh_rsc_probe()
1061 drv->name = of_get_property(dn, "label", NULL); in rpmh_rsc_probe()
1062 if (!drv->name) in rpmh_rsc_probe()
1063 drv->name = dev_name(&pdev->dev); in rpmh_rsc_probe()
1065 snprintf(drv_id, ARRAY_SIZE(drv_id), "drv-%d", drv->id); in rpmh_rsc_probe()
1066 drv->base = devm_platform_ioremap_resource_byname(pdev, drv_id); in rpmh_rsc_probe()
1067 if (IS_ERR(drv->base)) in rpmh_rsc_probe()
1068 return PTR_ERR(drv->base); in rpmh_rsc_probe()
1070 rsc_id = readl_relaxed(drv->base + RSC_DRV_ID); in rpmh_rsc_probe()
1071 drv->ver.major = rsc_id & (MAJOR_VER_MASK << MAJOR_VER_SHIFT); in rpmh_rsc_probe()
1072 drv->ver.major >>= MAJOR_VER_SHIFT; in rpmh_rsc_probe()
1073 drv->ver.minor = rsc_id & (MINOR_VER_MASK << MINOR_VER_SHIFT); in rpmh_rsc_probe()
1074 drv->ver.minor >>= MINOR_VER_SHIFT; in rpmh_rsc_probe()
1076 if (drv->ver.major == 3) in rpmh_rsc_probe()
1077 drv->regs = rpmh_rsc_reg_offset_ver_3_0; in rpmh_rsc_probe()
1079 drv->regs = rpmh_rsc_reg_offset_ver_2_7; in rpmh_rsc_probe()
1081 ret = rpmh_probe_tcs_config(pdev, drv); in rpmh_rsc_probe()
1085 spin_lock_init(&drv->lock); in rpmh_rsc_probe()
1086 init_waitqueue_head(&drv->tcs_wait); in rpmh_rsc_probe()
1087 bitmap_zero(drv->tcs_in_use, MAX_TCS_NR); in rpmh_rsc_probe()
1089 irq = platform_get_irq(pdev, drv->id); in rpmh_rsc_probe()
1090 if (irq < 0) in rpmh_rsc_probe()
1093 ret = devm_request_irq(&pdev->dev, irq, tcs_tx_done, in rpmh_rsc_probe()
1095 drv->name, drv); in rpmh_rsc_probe()
1104 solver_config = readl_relaxed(drv->base + drv->regs[DRV_SOLVER_CONFIG]); in rpmh_rsc_probe()
1108 if (pdev->dev.pm_domain) { in rpmh_rsc_probe()
1109 ret = rpmh_rsc_pd_attach(drv, &pdev->dev); in rpmh_rsc_probe()
1113 drv->rsc_pm.notifier_call = rpmh_rsc_cpu_pm_callback; in rpmh_rsc_probe()
1114 cpu_pm_register_notifier(&drv->rsc_pm); in rpmh_rsc_probe()
1119 writel_relaxed(drv->tcs[ACTIVE_TCS].mask, in rpmh_rsc_probe()
1120 drv->tcs_base + drv->regs[RSC_DRV_IRQ_ENABLE]); in rpmh_rsc_probe()
1122 spin_lock_init(&drv->client.cache_lock); in rpmh_rsc_probe()
1123 INIT_LIST_HEAD(&drv->client.cache); in rpmh_rsc_probe()
1124 INIT_LIST_HEAD(&drv->client.batch_cache); in rpmh_rsc_probe()
1126 dev_set_drvdata(&pdev->dev, drv); in rpmh_rsc_probe()
1127 drv->dev = &pdev->dev; in rpmh_rsc_probe()
1129 ret = devm_of_platform_populate(&pdev->dev); in rpmh_rsc_probe()
1130 if (ret && pdev->dev.pm_domain) { in rpmh_rsc_probe()
1131 dev_pm_genpd_remove_notifier(&pdev->dev); in rpmh_rsc_probe()
1132 pm_runtime_disable(&pdev->dev); in rpmh_rsc_probe()
1139 { .compatible = "qcom,rpmh-rsc", },