Lines Matching +full:tcs +full:- +full:wait
1 // SPDX-License-Identifier: GPL-2.0
7 #include <linux/interconnect-provider.h>
14 #include <soc/qcom/tcs.h>
16 #include "bcm-voter.h"
17 #include "icc-rpmh.h"
23 * struct bcm_voter - Bus Clock Manager voter
30 * @tcs_wait: mask for which buckets require TCS completion
49 if (bcm_a->aux_data.vcd < bcm_b->aux_data.vcd) in cmp_vcd()
50 return -1; in cmp_vcd()
51 else if (bcm_a->aux_data.vcd == bcm_b->aux_data.vcd) in cmp_vcd()
77 for (i = 0; i < bcm->num_nodes; i++) { in bcm_aggregate()
78 node = bcm->nodes[i]; in bcm_aggregate()
79 temp = bcm_div(node->sum_avg[bucket] * bcm->aux_data.width, in bcm_aggregate()
80 node->buswidth * node->channels); in bcm_aggregate()
83 temp = bcm_div(node->max_peak[bucket] * bcm->aux_data.width, in bcm_aggregate()
84 node->buswidth); in bcm_aggregate()
88 temp = agg_avg[bucket] * bcm->vote_scale; in bcm_aggregate()
89 bcm->vote_x[bucket] = bcm_div(temp, bcm->aux_data.unit); in bcm_aggregate()
91 temp = agg_peak[bucket] * bcm->vote_scale; in bcm_aggregate()
92 bcm->vote_y[bucket] = bcm_div(temp, bcm->aux_data.unit); in bcm_aggregate()
95 if (bcm->keepalive && bcm->vote_x[QCOM_ICC_BUCKET_AMC] == 0 && in bcm_aggregate()
96 bcm->vote_y[QCOM_ICC_BUCKET_AMC] == 0) { in bcm_aggregate()
97 bcm->vote_x[QCOM_ICC_BUCKET_AMC] = 1; in bcm_aggregate()
98 bcm->vote_x[QCOM_ICC_BUCKET_WAKE] = 1; in bcm_aggregate()
99 bcm->vote_y[QCOM_ICC_BUCKET_AMC] = 1; in bcm_aggregate()
100 bcm->vote_y[QCOM_ICC_BUCKET_WAKE] = 1; in bcm_aggregate()
105 u32 addr, bool commit, bool wait) in tcs_cmd_gen() argument
123 cmd->addr = addr; in tcs_cmd_gen()
124 cmd->data = BCM_TCS_CMD(commit, valid, vote_x, vote_y); in tcs_cmd_gen()
127 * Set the wait for completion flag on command that need to be completed in tcs_cmd_gen()
130 cmd->wait = wait; in tcs_cmd_gen()
137 struct list_head *bcm_list = &voter->commit_list; in tcs_list_gen()
139 bool commit, wait; in tcs_list_gen() local
147 if ((list_is_last(&bcm->list, bcm_list)) || in tcs_list_gen()
148 bcm->aux_data.vcd != list_next_entry(bcm, list)->aux_data.vcd) { in tcs_list_gen()
153 wait = commit && (voter->tcs_wait & BIT(bucket)); in tcs_list_gen()
155 tcs_cmd_gen(&tcs_list[idx], bcm->vote_x[bucket], in tcs_list_gen()
156 bcm->vote_y[bucket], bcm->addr, commit, wait); in tcs_list_gen()
167 n[batch] -= cur_vcd_size; in tcs_list_gen()
176 * of_bcm_voter_get - gets a bcm voter handle from DT node
188 struct bcm_voter *voter = ERR_PTR(-EPROBE_DEFER); in of_bcm_voter_get()
193 if (!dev || !dev->of_node) in of_bcm_voter_get()
194 return ERR_PTR(-ENODEV); in of_bcm_voter_get()
196 np = dev->of_node; in of_bcm_voter_get()
199 idx = of_property_match_string(np, "qcom,bcm-voter-names", name); in of_bcm_voter_get()
204 node = of_parse_phandle(np, "qcom,bcm-voters", idx); in of_bcm_voter_get()
208 if (temp->np == node) { in of_bcm_voter_get()
220 * qcom_icc_bcm_voter_add - queues up the bcm nodes that require updates
229 mutex_lock(&voter->lock); in qcom_icc_bcm_voter_add()
230 if (list_empty(&bcm->list)) in qcom_icc_bcm_voter_add()
231 list_add_tail(&bcm->list, &voter->commit_list); in qcom_icc_bcm_voter_add()
233 if (list_empty(&bcm->ws_list)) in qcom_icc_bcm_voter_add()
234 list_add_tail(&bcm->ws_list, &voter->ws_list); in qcom_icc_bcm_voter_add()
236 mutex_unlock(&voter->lock); in qcom_icc_bcm_voter_add()
241 * qcom_icc_bcm_voter_commit - generates and commits tcs cmds based on bcms
263 mutex_lock(&voter->lock); in qcom_icc_bcm_voter_commit()
264 list_for_each_entry(bcm, &voter->commit_list, list) in qcom_icc_bcm_voter_commit()
275 list_sort(NULL, &voter->commit_list, cmp_vcd); in qcom_icc_bcm_voter_commit()
285 rpmh_invalidate(voter->dev); in qcom_icc_bcm_voter_commit()
287 ret = rpmh_write_batch(voter->dev, RPMH_ACTIVE_ONLY_STATE, in qcom_icc_bcm_voter_commit()
294 list_for_each_entry_safe(bcm, bcm_tmp, &voter->commit_list, list) in qcom_icc_bcm_voter_commit()
295 list_del_init(&bcm->list); in qcom_icc_bcm_voter_commit()
297 list_for_each_entry_safe(bcm, bcm_tmp, &voter->ws_list, ws_list) { in qcom_icc_bcm_voter_commit()
303 if (bcm->vote_x[QCOM_ICC_BUCKET_WAKE] != in qcom_icc_bcm_voter_commit()
304 bcm->vote_x[QCOM_ICC_BUCKET_SLEEP] || in qcom_icc_bcm_voter_commit()
305 bcm->vote_y[QCOM_ICC_BUCKET_WAKE] != in qcom_icc_bcm_voter_commit()
306 bcm->vote_y[QCOM_ICC_BUCKET_SLEEP]) in qcom_icc_bcm_voter_commit()
307 list_add_tail(&bcm->list, &voter->commit_list); in qcom_icc_bcm_voter_commit()
309 list_del_init(&bcm->ws_list); in qcom_icc_bcm_voter_commit()
312 if (list_empty(&voter->commit_list)) in qcom_icc_bcm_voter_commit()
315 list_sort(NULL, &voter->commit_list, cmp_vcd); in qcom_icc_bcm_voter_commit()
319 ret = rpmh_write_batch(voter->dev, RPMH_WAKE_ONLY_STATE, cmds, commit_idx); in qcom_icc_bcm_voter_commit()
327 ret = rpmh_write_batch(voter->dev, RPMH_SLEEP_STATE, cmds, commit_idx); in qcom_icc_bcm_voter_commit()
334 list_for_each_entry_safe(bcm, bcm_tmp, &voter->commit_list, list) in qcom_icc_bcm_voter_commit()
335 list_del_init(&bcm->list); in qcom_icc_bcm_voter_commit()
337 mutex_unlock(&voter->lock); in qcom_icc_bcm_voter_commit()
344 struct device_node *np = pdev->dev.of_node; in qcom_icc_bcm_voter_probe()
347 voter = devm_kzalloc(&pdev->dev, sizeof(*voter), GFP_KERNEL); in qcom_icc_bcm_voter_probe()
349 return -ENOMEM; in qcom_icc_bcm_voter_probe()
351 voter->dev = &pdev->dev; in qcom_icc_bcm_voter_probe()
352 voter->np = np; in qcom_icc_bcm_voter_probe()
354 if (of_property_read_u32(np, "qcom,tcs-wait", &voter->tcs_wait)) in qcom_icc_bcm_voter_probe()
355 voter->tcs_wait = QCOM_ICC_TAG_ACTIVE_ONLY; in qcom_icc_bcm_voter_probe()
357 mutex_init(&voter->lock); in qcom_icc_bcm_voter_probe()
358 INIT_LIST_HEAD(&voter->commit_list); in qcom_icc_bcm_voter_probe()
359 INIT_LIST_HEAD(&voter->ws_list); in qcom_icc_bcm_voter_probe()
362 list_add_tail(&voter->voter_node, &bcm_voters); in qcom_icc_bcm_voter_probe()
369 { .compatible = "qcom,bcm-voter" },