1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2018, The Linux Foundation. All rights reserved.*/
4 #include <linux/cleanup.h>
6 #include <linux/init.h>
7 #include <linux/kernel.h>
8 #include <linux/module.h>
9 #include <linux/mutex.h>
10 #include <linux/pm_domain.h>
11 #include <linux/slab.h>
13 #include <linux/platform_device.h>
14 #include <linux/pm_opp.h>
15 #include <soc/qcom/cmd-db.h>
16 #include <soc/qcom/rpmh.h>
17 #include <dt-bindings/power/qcom-rpmpd.h>
18 #include <dt-bindings/power/qcom,rpmhpd.h>
20 #define domain_to_rpmhpd(domain) container_of(domain, struct rpmhpd, pd)
22 #define RPMH_ARC_MAX_LEVELS 16
25 * struct rpmhpd - top level RPMh power domain resource data structure
26 * @dev: rpmh power domain controller device
27 * @pd: generic_pm_domain corresponding to the power domain
28 * @parent: generic_pm_domain corresponding to the parent's power domain
29 * @peer: A peer power domain in case Active only Voting is
31 * @active_only: True if it represents an Active only peer
32 * @corner: current corner
33 * @active_corner: current active corner
34 * @enable_corner: lowest non-zero corner
35 * @level: An array of level (vlvl) to corner (hlvl) mappings
37 * @level_count: Number of levels supported by the power domain. max
39 * @enabled: true if the power domain is enabled
40 * @res_name: Resource name used for cmd-db lookup
41 * @addr: Resource address as looped up using resource name from
43 * @state_synced: Indicator that sync_state has been invoked for the rpmhpd resource
44 * @skip_retention_level: Indicate that retention level should not be used for the power domain
48 struct generic_pm_domain pd;
49 struct generic_pm_domain *parent;
51 const bool active_only;
53 unsigned int active_corner;
54 unsigned int enable_corner;
55 u32 level[RPMH_ARC_MAX_LEVELS];
61 bool skip_retention_level;
65 struct rpmhpd **rpmhpds;
69 static DEFINE_MUTEX(rpmhpd_lock);
71 /* RPMH powerdomains */
73 static struct rpmhpd cx_ao;
74 static struct rpmhpd mx;
75 static struct rpmhpd mx_ao;
76 static struct rpmhpd cx = {
77 .pd = { .name = "cx", },
82 static struct rpmhpd cx_ao = {
83 .pd = { .name = "cx_ao", },
89 static struct rpmhpd cx_ao_w_mx_parent;
90 static struct rpmhpd cx_w_mx_parent = {
91 .pd = { .name = "cx", },
92 .peer = &cx_ao_w_mx_parent,
97 static struct rpmhpd cx_ao_w_mx_parent = {
98 .pd = { .name = "cx_ao", },
100 .peer = &cx_w_mx_parent,
102 .res_name = "cx.lvl",
105 static struct rpmhpd ebi = {
106 .pd = { .name = "ebi", },
107 .res_name = "ebi.lvl",
110 static struct rpmhpd gfx = {
111 .pd = { .name = "gfx", },
112 .res_name = "gfx.lvl",
115 static struct rpmhpd lcx = {
116 .pd = { .name = "lcx", },
117 .res_name = "lcx.lvl",
120 static struct rpmhpd lmx = {
121 .pd = { .name = "lmx", },
122 .res_name = "lmx.lvl",
125 static struct rpmhpd mmcx_ao;
126 static struct rpmhpd mmcx = {
127 .pd = { .name = "mmcx", },
129 .res_name = "mmcx.lvl",
132 static struct rpmhpd mmcx_ao = {
133 .pd = { .name = "mmcx_ao", },
136 .res_name = "mmcx.lvl",
139 static struct rpmhpd mmcx_ao_w_cx_parent;
140 static struct rpmhpd mmcx_w_cx_parent = {
141 .pd = { .name = "mmcx", },
142 .peer = &mmcx_ao_w_cx_parent,
144 .res_name = "mmcx.lvl",
147 static struct rpmhpd mmcx_ao_w_cx_parent = {
148 .pd = { .name = "mmcx_ao", },
150 .peer = &mmcx_w_cx_parent,
152 .res_name = "mmcx.lvl",
155 static struct rpmhpd mss = {
156 .pd = { .name = "mss", },
157 .res_name = "mss.lvl",
160 static struct rpmhpd mx_ao;
161 static struct rpmhpd mx = {
162 .pd = { .name = "mx", },
164 .res_name = "mx.lvl",
167 static struct rpmhpd mx_ao = {
168 .pd = { .name = "mx_ao", },
171 .res_name = "mx.lvl",
174 static struct rpmhpd mxc_ao;
175 static struct rpmhpd mxc = {
176 .pd = { .name = "mxc", },
178 .res_name = "mxc.lvl",
179 .skip_retention_level = true,
182 static struct rpmhpd mxc_ao = {
183 .pd = { .name = "mxc_ao", },
186 .res_name = "mxc.lvl",
187 .skip_retention_level = true,
190 static struct rpmhpd nsp = {
191 .pd = { .name = "nsp", },
192 .res_name = "nsp.lvl",
195 static struct rpmhpd nsp0 = {
196 .pd = { .name = "nsp0", },
197 .res_name = "nsp0.lvl",
200 static struct rpmhpd nsp1 = {
201 .pd = { .name = "nsp1", },
202 .res_name = "nsp1.lvl",
205 static struct rpmhpd nsp2 = {
206 .pd = { .name = "nsp2", },
207 .res_name = "nsp2.lvl",
210 static struct rpmhpd qphy = {
211 .pd = { .name = "qphy", },
212 .res_name = "qphy.lvl",
215 static struct rpmhpd gmxc = {
216 .pd = { .name = "gmxc", },
217 .res_name = "gmxc.lvl",
220 /* SA8540P RPMH powerdomains */
221 static struct rpmhpd *sa8540p_rpmhpds[] = {
223 [SC8280XP_CX_AO] = &cx_ao,
224 [SC8280XP_EBI] = &ebi,
225 [SC8280XP_LCX] = &lcx,
226 [SC8280XP_LMX] = &lmx,
227 [SC8280XP_MMCX] = &mmcx,
228 [SC8280XP_MMCX_AO] = &mmcx_ao,
230 [SC8280XP_MX_AO] = &mx_ao,
231 [SC8280XP_NSP] = &nsp,
234 static const struct rpmhpd_desc sa8540p_desc = {
235 .rpmhpds = sa8540p_rpmhpds,
236 .num_pds = ARRAY_SIZE(sa8540p_rpmhpds),
239 /* SA8775P RPMH power domains */
240 static struct rpmhpd *sa8775p_rpmhpds[] = {
242 [SA8775P_CX_AO] = &cx_ao,
243 [SA8775P_EBI] = &ebi,
244 [SA8775P_GFX] = &gfx,
245 [SA8775P_LCX] = &lcx,
246 [SA8775P_LMX] = &lmx,
247 [SA8775P_MMCX] = &mmcx,
248 [SA8775P_MMCX_AO] = &mmcx_ao,
249 [SA8775P_MXC] = &mxc,
250 [SA8775P_MXC_AO] = &mxc_ao,
252 [SA8775P_MX_AO] = &mx_ao,
253 [SA8775P_NSP0] = &nsp0,
254 [SA8775P_NSP1] = &nsp1,
257 static const struct rpmhpd_desc sa8775p_desc = {
258 .rpmhpds = sa8775p_rpmhpds,
259 .num_pds = ARRAY_SIZE(sa8775p_rpmhpds),
262 /* SDM670 RPMH powerdomains */
263 static struct rpmhpd *sdm670_rpmhpds[] = {
264 [SDM670_CX] = &cx_w_mx_parent,
265 [SDM670_CX_AO] = &cx_ao_w_mx_parent,
271 [SDM670_MX_AO] = &mx_ao,
274 static const struct rpmhpd_desc sdm670_desc = {
275 .rpmhpds = sdm670_rpmhpds,
276 .num_pds = ARRAY_SIZE(sdm670_rpmhpds),
279 /* SDM845 RPMH powerdomains */
280 static struct rpmhpd *sdm845_rpmhpds[] = {
281 [SDM845_CX] = &cx_w_mx_parent,
282 [SDM845_CX_AO] = &cx_ao_w_mx_parent,
289 [SDM845_MX_AO] = &mx_ao,
292 static const struct rpmhpd_desc sdm845_desc = {
293 .rpmhpds = sdm845_rpmhpds,
294 .num_pds = ARRAY_SIZE(sdm845_rpmhpds),
297 /* SDX55 RPMH powerdomains */
298 static struct rpmhpd *sdx55_rpmhpds[] = {
299 [SDX55_CX] = &cx_w_mx_parent,
304 static const struct rpmhpd_desc sdx55_desc = {
305 .rpmhpds = sdx55_rpmhpds,
306 .num_pds = ARRAY_SIZE(sdx55_rpmhpds),
309 /* SDX65 RPMH powerdomains */
310 static struct rpmhpd *sdx65_rpmhpds[] = {
311 [SDX65_CX] = &cx_w_mx_parent,
312 [SDX65_CX_AO] = &cx_ao_w_mx_parent,
315 [SDX65_MX_AO] = &mx_ao,
319 static const struct rpmhpd_desc sdx65_desc = {
320 .rpmhpds = sdx65_rpmhpds,
321 .num_pds = ARRAY_SIZE(sdx65_rpmhpds),
324 /* SDX75 RPMH powerdomains */
325 static struct rpmhpd *sdx75_rpmhpds[] = {
327 [RPMHPD_CX_AO] = &cx_ao,
330 [RPMHPD_MX_AO] = &mx_ao,
334 static const struct rpmhpd_desc sdx75_desc = {
335 .rpmhpds = sdx75_rpmhpds,
336 .num_pds = ARRAY_SIZE(sdx75_rpmhpds),
339 /* SM6350 RPMH powerdomains */
340 static struct rpmhpd *sm6350_rpmhpds[] = {
341 [SM6350_CX] = &cx_w_mx_parent,
349 static const struct rpmhpd_desc sm6350_desc = {
350 .rpmhpds = sm6350_rpmhpds,
351 .num_pds = ARRAY_SIZE(sm6350_rpmhpds),
354 /* SM7150 RPMH powerdomains */
355 static struct rpmhpd *sm7150_rpmhpds[] = {
356 [RPMHPD_CX] = &cx_w_mx_parent,
357 [RPMHPD_CX_AO] = &cx_ao_w_mx_parent,
362 [RPMHPD_MX_AO] = &mx_ao,
366 static const struct rpmhpd_desc sm7150_desc = {
367 .rpmhpds = sm7150_rpmhpds,
368 .num_pds = ARRAY_SIZE(sm7150_rpmhpds),
371 /* SM8150 RPMH powerdomains */
372 static struct rpmhpd *sm8150_rpmhpds[] = {
373 [SM8150_CX] = &cx_w_mx_parent,
374 [SM8150_CX_AO] = &cx_ao_w_mx_parent,
379 [SM8150_MMCX] = &mmcx,
380 [SM8150_MMCX_AO] = &mmcx_ao,
383 [SM8150_MX_AO] = &mx_ao,
386 static const struct rpmhpd_desc sm8150_desc = {
387 .rpmhpds = sm8150_rpmhpds,
388 .num_pds = ARRAY_SIZE(sm8150_rpmhpds),
391 static struct rpmhpd *sa8155p_rpmhpds[] = {
392 [SA8155P_CX] = &cx_w_mx_parent,
393 [SA8155P_CX_AO] = &cx_ao_w_mx_parent,
394 [SA8155P_EBI] = &ebi,
395 [SA8155P_GFX] = &gfx,
396 [SA8155P_MSS] = &mss,
398 [SA8155P_MX_AO] = &mx_ao,
401 static const struct rpmhpd_desc sa8155p_desc = {
402 .rpmhpds = sa8155p_rpmhpds,
403 .num_pds = ARRAY_SIZE(sa8155p_rpmhpds),
406 /* SM8250 RPMH powerdomains */
407 static struct rpmhpd *sm8250_rpmhpds[] = {
408 [RPMHPD_CX] = &cx_w_mx_parent,
409 [RPMHPD_CX_AO] = &cx_ao_w_mx_parent,
414 [RPMHPD_MMCX] = &mmcx,
415 [RPMHPD_MMCX_AO] = &mmcx_ao,
417 [RPMHPD_MX_AO] = &mx_ao,
420 static const struct rpmhpd_desc sm8250_desc = {
421 .rpmhpds = sm8250_rpmhpds,
422 .num_pds = ARRAY_SIZE(sm8250_rpmhpds),
425 /* SM8350 Power domains */
426 static struct rpmhpd *sm8350_rpmhpds[] = {
427 [RPMHPD_CX] = &cx_w_mx_parent,
428 [RPMHPD_CX_AO] = &cx_ao_w_mx_parent,
433 [RPMHPD_MMCX] = &mmcx,
434 [RPMHPD_MMCX_AO] = &mmcx_ao,
437 [RPMHPD_MX_AO] = &mx_ao,
439 [RPMHPD_MXC_AO] = &mxc_ao,
442 static const struct rpmhpd_desc sm8350_desc = {
443 .rpmhpds = sm8350_rpmhpds,
444 .num_pds = ARRAY_SIZE(sm8350_rpmhpds),
447 /* SM8450 RPMH powerdomains */
448 static struct rpmhpd *sm8450_rpmhpds[] = {
450 [RPMHPD_CX_AO] = &cx_ao,
455 [RPMHPD_MMCX] = &mmcx_w_cx_parent,
456 [RPMHPD_MMCX_AO] = &mmcx_ao_w_cx_parent,
459 [RPMHPD_MX_AO] = &mx_ao,
461 [RPMHPD_MXC_AO] = &mxc_ao,
464 static const struct rpmhpd_desc sm8450_desc = {
465 .rpmhpds = sm8450_rpmhpds,
466 .num_pds = ARRAY_SIZE(sm8450_rpmhpds),
469 /* SM8550 RPMH powerdomains */
470 static struct rpmhpd *sm8550_rpmhpds[] = {
472 [RPMHPD_CX_AO] = &cx_ao,
477 [RPMHPD_MMCX] = &mmcx_w_cx_parent,
478 [RPMHPD_MMCX_AO] = &mmcx_ao_w_cx_parent,
481 [RPMHPD_MX_AO] = &mx_ao,
483 [RPMHPD_MXC_AO] = &mxc_ao,
487 static const struct rpmhpd_desc sm8550_desc = {
488 .rpmhpds = sm8550_rpmhpds,
489 .num_pds = ARRAY_SIZE(sm8550_rpmhpds),
492 /* SM8650 RPMH powerdomains */
493 static struct rpmhpd *sm8650_rpmhpds[] = {
495 [RPMHPD_CX_AO] = &cx_ao,
500 [RPMHPD_MMCX] = &mmcx_w_cx_parent,
501 [RPMHPD_MMCX_AO] = &mmcx_ao_w_cx_parent,
504 [RPMHPD_MX_AO] = &mx_ao,
506 [RPMHPD_MXC_AO] = &mxc_ao,
508 [RPMHPD_NSP2] = &nsp2,
511 static const struct rpmhpd_desc sm8650_desc = {
512 .rpmhpds = sm8650_rpmhpds,
513 .num_pds = ARRAY_SIZE(sm8650_rpmhpds),
516 /* QDU1000/QRU1000 RPMH powerdomains */
517 static struct rpmhpd *qdu1000_rpmhpds[] = {
519 [QDU1000_EBI] = &ebi,
520 [QDU1000_MSS] = &mss,
524 static const struct rpmhpd_desc qdu1000_desc = {
525 .rpmhpds = qdu1000_rpmhpds,
526 .num_pds = ARRAY_SIZE(qdu1000_rpmhpds),
529 /* SC7180 RPMH powerdomains */
530 static struct rpmhpd *sc7180_rpmhpds[] = {
531 [SC7180_CX] = &cx_w_mx_parent,
532 [SC7180_CX_AO] = &cx_ao_w_mx_parent,
538 [SC7180_MX_AO] = &mx_ao,
541 static const struct rpmhpd_desc sc7180_desc = {
542 .rpmhpds = sc7180_rpmhpds,
543 .num_pds = ARRAY_SIZE(sc7180_rpmhpds),
546 /* SC7280 RPMH powerdomains */
547 static struct rpmhpd *sc7280_rpmhpds[] = {
549 [SC7280_CX_AO] = &cx_ao,
556 [SC7280_MX_AO] = &mx_ao,
559 static const struct rpmhpd_desc sc7280_desc = {
560 .rpmhpds = sc7280_rpmhpds,
561 .num_pds = ARRAY_SIZE(sc7280_rpmhpds),
564 /* SC8180x RPMH powerdomains */
565 static struct rpmhpd *sc8180x_rpmhpds[] = {
566 [SC8180X_CX] = &cx_w_mx_parent,
567 [SC8180X_CX_AO] = &cx_ao_w_mx_parent,
568 [SC8180X_EBI] = &ebi,
569 [SC8180X_GFX] = &gfx,
570 [SC8180X_LCX] = &lcx,
571 [SC8180X_LMX] = &lmx,
572 [SC8180X_MMCX] = &mmcx,
573 [SC8180X_MMCX_AO] = &mmcx_ao,
574 [SC8180X_MSS] = &mss,
576 [SC8180X_MX_AO] = &mx_ao,
579 static const struct rpmhpd_desc sc8180x_desc = {
580 .rpmhpds = sc8180x_rpmhpds,
581 .num_pds = ARRAY_SIZE(sc8180x_rpmhpds),
584 /* SC8280xp RPMH powerdomains */
585 static struct rpmhpd *sc8280xp_rpmhpds[] = {
587 [SC8280XP_CX_AO] = &cx_ao,
588 [SC8280XP_EBI] = &ebi,
589 [SC8280XP_GFX] = &gfx,
590 [SC8280XP_LCX] = &lcx,
591 [SC8280XP_LMX] = &lmx,
592 [SC8280XP_MMCX] = &mmcx,
593 [SC8280XP_MMCX_AO] = &mmcx_ao,
595 [SC8280XP_MX_AO] = &mx_ao,
596 [SC8280XP_NSP] = &nsp,
597 [SC8280XP_QPHY] = &qphy,
600 static const struct rpmhpd_desc sc8280xp_desc = {
601 .rpmhpds = sc8280xp_rpmhpds,
602 .num_pds = ARRAY_SIZE(sc8280xp_rpmhpds),
605 /* X1E80100 RPMH powerdomains */
606 static struct rpmhpd *x1e80100_rpmhpds[] = {
608 [RPMHPD_CX_AO] = &cx_ao,
613 [RPMHPD_MMCX] = &mmcx,
614 [RPMHPD_MMCX_AO] = &mmcx_ao,
616 [RPMHPD_MX_AO] = &mx_ao,
619 [RPMHPD_GMXC] = &gmxc,
622 static const struct rpmhpd_desc x1e80100_desc = {
623 .rpmhpds = x1e80100_rpmhpds,
624 .num_pds = ARRAY_SIZE(x1e80100_rpmhpds),
627 static const struct of_device_id rpmhpd_match_table[] = {
628 { .compatible = "qcom,qdu1000-rpmhpd", .data = &qdu1000_desc },
629 { .compatible = "qcom,sa8155p-rpmhpd", .data = &sa8155p_desc },
630 { .compatible = "qcom,sa8540p-rpmhpd", .data = &sa8540p_desc },
631 { .compatible = "qcom,sa8775p-rpmhpd", .data = &sa8775p_desc },
632 { .compatible = "qcom,sc7180-rpmhpd", .data = &sc7180_desc },
633 { .compatible = "qcom,sc7280-rpmhpd", .data = &sc7280_desc },
634 { .compatible = "qcom,sc8180x-rpmhpd", .data = &sc8180x_desc },
635 { .compatible = "qcom,sc8280xp-rpmhpd", .data = &sc8280xp_desc },
636 { .compatible = "qcom,sdm670-rpmhpd", .data = &sdm670_desc },
637 { .compatible = "qcom,sdm845-rpmhpd", .data = &sdm845_desc },
638 { .compatible = "qcom,sdx55-rpmhpd", .data = &sdx55_desc},
639 { .compatible = "qcom,sdx65-rpmhpd", .data = &sdx65_desc},
640 { .compatible = "qcom,sdx75-rpmhpd", .data = &sdx75_desc},
641 { .compatible = "qcom,sm6350-rpmhpd", .data = &sm6350_desc },
642 { .compatible = "qcom,sm7150-rpmhpd", .data = &sm7150_desc },
643 { .compatible = "qcom,sm8150-rpmhpd", .data = &sm8150_desc },
644 { .compatible = "qcom,sm8250-rpmhpd", .data = &sm8250_desc },
645 { .compatible = "qcom,sm8350-rpmhpd", .data = &sm8350_desc },
646 { .compatible = "qcom,sm8450-rpmhpd", .data = &sm8450_desc },
647 { .compatible = "qcom,sm8550-rpmhpd", .data = &sm8550_desc },
648 { .compatible = "qcom,sm8650-rpmhpd", .data = &sm8650_desc },
649 { .compatible = "qcom,x1e80100-rpmhpd", .data = &x1e80100_desc },
652 MODULE_DEVICE_TABLE(of, rpmhpd_match_table);
654 static int rpmhpd_send_corner(struct rpmhpd *pd, int state,
655 unsigned int corner, bool sync)
657 struct tcs_cmd cmd = {
663 * Wait for an ack only when we are increasing the
664 * perf state of the power domain
667 return rpmh_write(pd->dev, state, &cmd, 1);
669 return rpmh_write_async(pd->dev, state, &cmd, 1);
672 static void to_active_sleep(struct rpmhpd *pd, unsigned int corner,
673 unsigned int *active, unsigned int *sleep)
684 * This function is used to aggregate the votes across the active only
685 * resources and its peers. The aggregated votes are sent to RPMh as
686 * ACTIVE_ONLY votes (which take effect immediately), as WAKE_ONLY votes
687 * (applied by RPMh on system wakeup) and as SLEEP votes (applied by RPMh
689 * We send ACTIVE_ONLY votes for resources without any peers. For others,
690 * which have an active only peer, all 3 votes are sent.
692 static int rpmhpd_aggregate_corner(struct rpmhpd *pd, unsigned int corner)
695 struct rpmhpd *peer = pd->peer;
696 unsigned int active_corner, sleep_corner;
697 unsigned int this_active_corner = 0, this_sleep_corner = 0;
698 unsigned int peer_active_corner = 0, peer_sleep_corner = 0;
699 unsigned int peer_enabled_corner;
701 if (pd->state_synced) {
702 to_active_sleep(pd, corner, &this_active_corner, &this_sleep_corner);
704 /* Clamp to highest corner if sync_state hasn't happened */
705 this_active_corner = pd->level_count - 1;
706 this_sleep_corner = pd->level_count - 1;
709 if (peer && peer->enabled) {
710 peer_enabled_corner = max(peer->corner, peer->enable_corner);
711 to_active_sleep(peer, peer_enabled_corner, &peer_active_corner,
715 active_corner = max(this_active_corner, peer_active_corner);
717 ret = rpmhpd_send_corner(pd, RPMH_ACTIVE_ONLY_STATE, active_corner,
718 active_corner > pd->active_corner);
722 pd->active_corner = active_corner;
725 peer->active_corner = active_corner;
727 ret = rpmhpd_send_corner(pd, RPMH_WAKE_ONLY_STATE,
728 active_corner, false);
732 sleep_corner = max(this_sleep_corner, peer_sleep_corner);
734 return rpmhpd_send_corner(pd, RPMH_SLEEP_STATE, sleep_corner,
741 static int rpmhpd_power_on(struct generic_pm_domain *domain)
743 struct rpmhpd *pd = domain_to_rpmhpd(domain);
747 mutex_lock(&rpmhpd_lock);
749 corner = max(pd->corner, pd->enable_corner);
750 ret = rpmhpd_aggregate_corner(pd, corner);
754 mutex_unlock(&rpmhpd_lock);
759 static int rpmhpd_power_off(struct generic_pm_domain *domain)
761 struct rpmhpd *pd = domain_to_rpmhpd(domain);
764 mutex_lock(&rpmhpd_lock);
766 ret = rpmhpd_aggregate_corner(pd, 0);
770 mutex_unlock(&rpmhpd_lock);
775 static int rpmhpd_set_performance_state(struct generic_pm_domain *domain,
778 struct rpmhpd *pd = domain_to_rpmhpd(domain);
781 guard(mutex)(&rpmhpd_lock);
783 for (i = 0; i < pd->level_count; i++)
784 if (level <= pd->level[i])
788 * If the level requested is more than that supported by the
789 * max corner, just set it to max anyway.
791 if (i == pd->level_count)
795 /* Ensure that the domain isn't turn off */
796 if (i < pd->enable_corner)
797 i = pd->enable_corner;
799 ret = rpmhpd_aggregate_corner(pd, i);
809 static int rpmhpd_update_level_mapping(struct rpmhpd *rpmhpd)
814 buf = cmd_db_read_aux_data(rpmhpd->res_name, &rpmhpd->level_count);
818 /* 2 bytes used for each command DB aux data entry */
819 rpmhpd->level_count >>= 1;
821 if (rpmhpd->level_count > RPMH_ARC_MAX_LEVELS)
824 for (i = 0; i < rpmhpd->level_count; i++) {
825 if (rpmhpd->skip_retention_level && buf[i] == RPMH_REGULATOR_LEVEL_RETENTION)
828 rpmhpd->level[i] = buf[i];
830 /* Remember the first corner with non-zero level */
831 if (!rpmhpd->level[rpmhpd->enable_corner] && rpmhpd->level[i])
832 rpmhpd->enable_corner = i;
835 * The AUX data may be zero padded. These 0 valued entries at
836 * the end of the map must be ignored.
838 if (i > 0 && rpmhpd->level[i] == 0) {
839 rpmhpd->level_count = i;
842 pr_debug("%s: ARC hlvl=%2d --> vlvl=%4u\n", rpmhpd->res_name, i,
849 static int rpmhpd_probe(struct platform_device *pdev)
853 struct device *dev = &pdev->dev;
854 struct genpd_onecell_data *data;
855 struct rpmhpd **rpmhpds;
856 const struct rpmhpd_desc *desc;
858 desc = of_device_get_match_data(dev);
862 rpmhpds = desc->rpmhpds;
863 num_pds = desc->num_pds;
865 data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
869 data->domains = devm_kcalloc(dev, num_pds, sizeof(*data->domains),
874 data->num_domains = num_pds;
876 for (i = 0; i < num_pds; i++) {
880 rpmhpds[i]->dev = dev;
881 rpmhpds[i]->addr = cmd_db_read_addr(rpmhpds[i]->res_name);
882 if (!rpmhpds[i]->addr) {
883 dev_err(dev, "Could not find RPMh address for resource %s\n",
884 rpmhpds[i]->res_name);
888 ret = cmd_db_read_slave_id(rpmhpds[i]->res_name);
889 if (ret != CMD_DB_HW_ARC) {
890 dev_err(dev, "RPMh slave ID mismatch\n");
894 ret = rpmhpd_update_level_mapping(rpmhpds[i]);
898 rpmhpds[i]->pd.power_off = rpmhpd_power_off;
899 rpmhpds[i]->pd.power_on = rpmhpd_power_on;
900 rpmhpds[i]->pd.set_performance_state = rpmhpd_set_performance_state;
901 pm_genpd_init(&rpmhpds[i]->pd, NULL, true);
903 data->domains[i] = &rpmhpds[i]->pd;
907 for (i = 0; i < num_pds; i++) {
910 if (rpmhpds[i]->parent)
911 pm_genpd_add_subdomain(rpmhpds[i]->parent,
915 return of_genpd_add_provider_onecell(pdev->dev.of_node, data);
918 static void rpmhpd_sync_state(struct device *dev)
920 const struct rpmhpd_desc *desc = of_device_get_match_data(dev);
921 struct rpmhpd **rpmhpds = desc->rpmhpds;
927 mutex_lock(&rpmhpd_lock);
928 for (i = 0; i < desc->num_pds; i++) {
933 pd->state_synced = true;
935 corner = max(pd->corner, pd->enable_corner);
939 ret = rpmhpd_aggregate_corner(pd, corner);
941 dev_err(dev, "failed to sync %s\n", pd->res_name);
943 mutex_unlock(&rpmhpd_lock);
946 static struct platform_driver rpmhpd_driver = {
948 .name = "qcom-rpmhpd",
949 .of_match_table = rpmhpd_match_table,
950 .suppress_bind_attrs = true,
951 .sync_state = rpmhpd_sync_state,
953 .probe = rpmhpd_probe,
956 static int __init rpmhpd_init(void)
958 return platform_driver_register(&rpmhpd_driver);
960 core_initcall(rpmhpd_init);
962 MODULE_DESCRIPTION("Qualcomm Technologies, Inc. RPMh Power Domain Driver");
963 MODULE_LICENSE("GPL v2");