1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2018, The Linux Foundation. All rights reserved.*/
5 #include <linux/init.h>
6 #include <linux/kernel.h>
7 #include <linux/module.h>
8 #include <linux/mutex.h>
9 #include <linux/pm_domain.h>
10 #include <linux/slab.h>
12 #include <linux/platform_device.h>
13 #include <linux/pm_opp.h>
14 #include <soc/qcom/cmd-db.h>
15 #include <soc/qcom/rpmh.h>
16 #include <dt-bindings/power/qcom-rpmpd.h>
17 #include <dt-bindings/power/qcom,rpmhpd.h>
19 #define domain_to_rpmhpd(domain) container_of(domain, struct rpmhpd, pd)
21 #define RPMH_ARC_MAX_LEVELS 16
24 * struct rpmhpd - top level RPMh power domain resource data structure
25 * @dev: rpmh power domain controller device
26 * @pd: generic_pm_domain corresponding to the power domain
27 * @parent: generic_pm_domain corresponding to the parent's power domain
28 * @peer: A peer power domain in case Active only Voting is
30 * @active_only: True if it represents an Active only peer
31 * @corner: current corner
32 * @active_corner: current active corner
33 * @enable_corner: lowest non-zero corner
34 * @level: An array of level (vlvl) to corner (hlvl) mappings
36 * @level_count: Number of levels supported by the power domain. max
38 * @enabled: true if the power domain is enabled
39 * @res_name: Resource name used for cmd-db lookup
40 * @addr: Resource address as looped up using resource name from
42 * @state_synced: Indicator that sync_state has been invoked for the rpmhpd resource
46 struct generic_pm_domain pd;
47 struct generic_pm_domain *parent;
49 const bool active_only;
51 unsigned int active_corner;
52 unsigned int enable_corner;
53 u32 level[RPMH_ARC_MAX_LEVELS];
62 struct rpmhpd **rpmhpds;
66 static DEFINE_MUTEX(rpmhpd_lock);
68 /* RPMH powerdomains */
70 static struct rpmhpd cx_ao;
71 static struct rpmhpd mx;
72 static struct rpmhpd mx_ao;
73 static struct rpmhpd cx = {
74 .pd = { .name = "cx", },
79 static struct rpmhpd cx_ao = {
80 .pd = { .name = "cx_ao", },
86 static struct rpmhpd cx_ao_w_mx_parent;
87 static struct rpmhpd cx_w_mx_parent = {
88 .pd = { .name = "cx", },
89 .peer = &cx_ao_w_mx_parent,
94 static struct rpmhpd cx_ao_w_mx_parent = {
95 .pd = { .name = "cx_ao", },
97 .peer = &cx_w_mx_parent,
102 static struct rpmhpd ebi = {
103 .pd = { .name = "ebi", },
104 .res_name = "ebi.lvl",
107 static struct rpmhpd gfx = {
108 .pd = { .name = "gfx", },
109 .res_name = "gfx.lvl",
112 static struct rpmhpd lcx = {
113 .pd = { .name = "lcx", },
114 .res_name = "lcx.lvl",
117 static struct rpmhpd lmx = {
118 .pd = { .name = "lmx", },
119 .res_name = "lmx.lvl",
122 static struct rpmhpd mmcx_ao;
123 static struct rpmhpd mmcx = {
124 .pd = { .name = "mmcx", },
126 .res_name = "mmcx.lvl",
129 static struct rpmhpd mmcx_ao = {
130 .pd = { .name = "mmcx_ao", },
133 .res_name = "mmcx.lvl",
136 static struct rpmhpd mmcx_ao_w_cx_parent;
137 static struct rpmhpd mmcx_w_cx_parent = {
138 .pd = { .name = "mmcx", },
139 .peer = &mmcx_ao_w_cx_parent,
141 .res_name = "mmcx.lvl",
144 static struct rpmhpd mmcx_ao_w_cx_parent = {
145 .pd = { .name = "mmcx_ao", },
147 .peer = &mmcx_w_cx_parent,
149 .res_name = "mmcx.lvl",
152 static struct rpmhpd mss = {
153 .pd = { .name = "mss", },
154 .res_name = "mss.lvl",
157 static struct rpmhpd mx_ao;
158 static struct rpmhpd mx = {
159 .pd = { .name = "mx", },
161 .res_name = "mx.lvl",
164 static struct rpmhpd mx_ao = {
165 .pd = { .name = "mx_ao", },
168 .res_name = "mx.lvl",
171 static struct rpmhpd mxc_ao;
172 static struct rpmhpd mxc = {
173 .pd = { .name = "mxc", },
175 .res_name = "mxc.lvl",
178 static struct rpmhpd mxc_ao = {
179 .pd = { .name = "mxc_ao", },
182 .res_name = "mxc.lvl",
185 static struct rpmhpd nsp = {
186 .pd = { .name = "nsp", },
187 .res_name = "nsp.lvl",
190 static struct rpmhpd nsp0 = {
191 .pd = { .name = "nsp0", },
192 .res_name = "nsp0.lvl",
195 static struct rpmhpd nsp1 = {
196 .pd = { .name = "nsp1", },
197 .res_name = "nsp1.lvl",
200 static struct rpmhpd nsp2 = {
201 .pd = { .name = "nsp2", },
202 .res_name = "nsp2.lvl",
205 static struct rpmhpd qphy = {
206 .pd = { .name = "qphy", },
207 .res_name = "qphy.lvl",
210 static struct rpmhpd gmxc = {
211 .pd = { .name = "gmxc", },
212 .res_name = "gmxc.lvl",
215 /* SA8540P RPMH powerdomains */
216 static struct rpmhpd *sa8540p_rpmhpds[] = {
218 [SC8280XP_CX_AO] = &cx_ao,
219 [SC8280XP_EBI] = &ebi,
220 [SC8280XP_GFX] = &gfx,
221 [SC8280XP_LCX] = &lcx,
222 [SC8280XP_LMX] = &lmx,
223 [SC8280XP_MMCX] = &mmcx,
224 [SC8280XP_MMCX_AO] = &mmcx_ao,
226 [SC8280XP_MX_AO] = &mx_ao,
227 [SC8280XP_NSP] = &nsp,
230 static const struct rpmhpd_desc sa8540p_desc = {
231 .rpmhpds = sa8540p_rpmhpds,
232 .num_pds = ARRAY_SIZE(sa8540p_rpmhpds),
235 /* SA8775P RPMH power domains */
236 static struct rpmhpd *sa8775p_rpmhpds[] = {
238 [SA8775P_CX_AO] = &cx_ao,
239 [SA8775P_EBI] = &ebi,
240 [SA8775P_GFX] = &gfx,
241 [SA8775P_LCX] = &lcx,
242 [SA8775P_LMX] = &lmx,
243 [SA8775P_MMCX] = &mmcx,
244 [SA8775P_MMCX_AO] = &mmcx_ao,
245 [SA8775P_MXC] = &mxc,
246 [SA8775P_MXC_AO] = &mxc_ao,
248 [SA8775P_MX_AO] = &mx_ao,
249 [SA8775P_NSP0] = &nsp0,
250 [SA8775P_NSP1] = &nsp1,
253 static const struct rpmhpd_desc sa8775p_desc = {
254 .rpmhpds = sa8775p_rpmhpds,
255 .num_pds = ARRAY_SIZE(sa8775p_rpmhpds),
258 /* SDM670 RPMH powerdomains */
259 static struct rpmhpd *sdm670_rpmhpds[] = {
260 [SDM670_CX] = &cx_w_mx_parent,
261 [SDM670_CX_AO] = &cx_ao_w_mx_parent,
267 [SDM670_MX_AO] = &mx_ao,
270 static const struct rpmhpd_desc sdm670_desc = {
271 .rpmhpds = sdm670_rpmhpds,
272 .num_pds = ARRAY_SIZE(sdm670_rpmhpds),
275 /* SDM845 RPMH powerdomains */
276 static struct rpmhpd *sdm845_rpmhpds[] = {
277 [SDM845_CX] = &cx_w_mx_parent,
278 [SDM845_CX_AO] = &cx_ao_w_mx_parent,
285 [SDM845_MX_AO] = &mx_ao,
288 static const struct rpmhpd_desc sdm845_desc = {
289 .rpmhpds = sdm845_rpmhpds,
290 .num_pds = ARRAY_SIZE(sdm845_rpmhpds),
293 /* SDX55 RPMH powerdomains */
294 static struct rpmhpd *sdx55_rpmhpds[] = {
295 [SDX55_CX] = &cx_w_mx_parent,
300 static const struct rpmhpd_desc sdx55_desc = {
301 .rpmhpds = sdx55_rpmhpds,
302 .num_pds = ARRAY_SIZE(sdx55_rpmhpds),
305 /* SDX65 RPMH powerdomains */
306 static struct rpmhpd *sdx65_rpmhpds[] = {
307 [SDX65_CX] = &cx_w_mx_parent,
308 [SDX65_CX_AO] = &cx_ao_w_mx_parent,
311 [SDX65_MX_AO] = &mx_ao,
315 static const struct rpmhpd_desc sdx65_desc = {
316 .rpmhpds = sdx65_rpmhpds,
317 .num_pds = ARRAY_SIZE(sdx65_rpmhpds),
320 /* SDX75 RPMH powerdomains */
321 static struct rpmhpd *sdx75_rpmhpds[] = {
323 [RPMHPD_CX_AO] = &cx_ao,
326 [RPMHPD_MX_AO] = &mx_ao,
330 static const struct rpmhpd_desc sdx75_desc = {
331 .rpmhpds = sdx75_rpmhpds,
332 .num_pds = ARRAY_SIZE(sdx75_rpmhpds),
335 /* SM6350 RPMH powerdomains */
336 static struct rpmhpd *sm6350_rpmhpds[] = {
337 [SM6350_CX] = &cx_w_mx_parent,
345 static const struct rpmhpd_desc sm6350_desc = {
346 .rpmhpds = sm6350_rpmhpds,
347 .num_pds = ARRAY_SIZE(sm6350_rpmhpds),
350 /* SM7150 RPMH powerdomains */
351 static struct rpmhpd *sm7150_rpmhpds[] = {
352 [RPMHPD_CX] = &cx_w_mx_parent,
353 [RPMHPD_CX_AO] = &cx_ao_w_mx_parent,
358 [RPMHPD_MX_AO] = &mx_ao,
362 static const struct rpmhpd_desc sm7150_desc = {
363 .rpmhpds = sm7150_rpmhpds,
364 .num_pds = ARRAY_SIZE(sm7150_rpmhpds),
367 /* SM8150 RPMH powerdomains */
368 static struct rpmhpd *sm8150_rpmhpds[] = {
369 [SM8150_CX] = &cx_w_mx_parent,
370 [SM8150_CX_AO] = &cx_ao_w_mx_parent,
375 [SM8150_MMCX] = &mmcx,
376 [SM8150_MMCX_AO] = &mmcx_ao,
379 [SM8150_MX_AO] = &mx_ao,
382 static const struct rpmhpd_desc sm8150_desc = {
383 .rpmhpds = sm8150_rpmhpds,
384 .num_pds = ARRAY_SIZE(sm8150_rpmhpds),
387 static struct rpmhpd *sa8155p_rpmhpds[] = {
388 [SA8155P_CX] = &cx_w_mx_parent,
389 [SA8155P_CX_AO] = &cx_ao_w_mx_parent,
390 [SA8155P_EBI] = &ebi,
391 [SA8155P_GFX] = &gfx,
392 [SA8155P_MSS] = &mss,
394 [SA8155P_MX_AO] = &mx_ao,
397 static const struct rpmhpd_desc sa8155p_desc = {
398 .rpmhpds = sa8155p_rpmhpds,
399 .num_pds = ARRAY_SIZE(sa8155p_rpmhpds),
402 /* SM8250 RPMH powerdomains */
403 static struct rpmhpd *sm8250_rpmhpds[] = {
404 [RPMHPD_CX] = &cx_w_mx_parent,
405 [RPMHPD_CX_AO] = &cx_ao_w_mx_parent,
410 [RPMHPD_MMCX] = &mmcx,
411 [RPMHPD_MMCX_AO] = &mmcx_ao,
413 [RPMHPD_MX_AO] = &mx_ao,
416 static const struct rpmhpd_desc sm8250_desc = {
417 .rpmhpds = sm8250_rpmhpds,
418 .num_pds = ARRAY_SIZE(sm8250_rpmhpds),
421 /* SM8350 Power domains */
422 static struct rpmhpd *sm8350_rpmhpds[] = {
423 [RPMHPD_CX] = &cx_w_mx_parent,
424 [RPMHPD_CX_AO] = &cx_ao_w_mx_parent,
429 [RPMHPD_MMCX] = &mmcx,
430 [RPMHPD_MMCX_AO] = &mmcx_ao,
433 [RPMHPD_MX_AO] = &mx_ao,
435 [RPMHPD_MXC_AO] = &mxc_ao,
438 static const struct rpmhpd_desc sm8350_desc = {
439 .rpmhpds = sm8350_rpmhpds,
440 .num_pds = ARRAY_SIZE(sm8350_rpmhpds),
443 /* SM8450 RPMH powerdomains */
444 static struct rpmhpd *sm8450_rpmhpds[] = {
446 [RPMHPD_CX_AO] = &cx_ao,
451 [RPMHPD_MMCX] = &mmcx_w_cx_parent,
452 [RPMHPD_MMCX_AO] = &mmcx_ao_w_cx_parent,
455 [RPMHPD_MX_AO] = &mx_ao,
457 [RPMHPD_MXC_AO] = &mxc_ao,
460 static const struct rpmhpd_desc sm8450_desc = {
461 .rpmhpds = sm8450_rpmhpds,
462 .num_pds = ARRAY_SIZE(sm8450_rpmhpds),
465 /* SM8550 RPMH powerdomains */
466 static struct rpmhpd *sm8550_rpmhpds[] = {
468 [RPMHPD_CX_AO] = &cx_ao,
473 [RPMHPD_MMCX] = &mmcx_w_cx_parent,
474 [RPMHPD_MMCX_AO] = &mmcx_ao_w_cx_parent,
477 [RPMHPD_MX_AO] = &mx_ao,
479 [RPMHPD_MXC_AO] = &mxc_ao,
483 static const struct rpmhpd_desc sm8550_desc = {
484 .rpmhpds = sm8550_rpmhpds,
485 .num_pds = ARRAY_SIZE(sm8550_rpmhpds),
488 /* SM8650 RPMH powerdomains */
489 static struct rpmhpd *sm8650_rpmhpds[] = {
491 [RPMHPD_CX_AO] = &cx_ao,
496 [RPMHPD_MMCX] = &mmcx_w_cx_parent,
497 [RPMHPD_MMCX_AO] = &mmcx_ao_w_cx_parent,
500 [RPMHPD_MX_AO] = &mx_ao,
502 [RPMHPD_MXC_AO] = &mxc_ao,
504 [RPMHPD_NSP2] = &nsp2,
507 static const struct rpmhpd_desc sm8650_desc = {
508 .rpmhpds = sm8650_rpmhpds,
509 .num_pds = ARRAY_SIZE(sm8650_rpmhpds),
512 /* QDU1000/QRU1000 RPMH powerdomains */
513 static struct rpmhpd *qdu1000_rpmhpds[] = {
515 [QDU1000_EBI] = &ebi,
516 [QDU1000_MSS] = &mss,
520 static const struct rpmhpd_desc qdu1000_desc = {
521 .rpmhpds = qdu1000_rpmhpds,
522 .num_pds = ARRAY_SIZE(qdu1000_rpmhpds),
525 /* SC7180 RPMH powerdomains */
526 static struct rpmhpd *sc7180_rpmhpds[] = {
527 [SC7180_CX] = &cx_w_mx_parent,
528 [SC7180_CX_AO] = &cx_ao_w_mx_parent,
534 [SC7180_MX_AO] = &mx_ao,
537 static const struct rpmhpd_desc sc7180_desc = {
538 .rpmhpds = sc7180_rpmhpds,
539 .num_pds = ARRAY_SIZE(sc7180_rpmhpds),
542 /* SC7280 RPMH powerdomains */
543 static struct rpmhpd *sc7280_rpmhpds[] = {
545 [SC7280_CX_AO] = &cx_ao,
552 [SC7280_MX_AO] = &mx_ao,
555 static const struct rpmhpd_desc sc7280_desc = {
556 .rpmhpds = sc7280_rpmhpds,
557 .num_pds = ARRAY_SIZE(sc7280_rpmhpds),
560 /* SC8180x RPMH powerdomains */
561 static struct rpmhpd *sc8180x_rpmhpds[] = {
562 [SC8180X_CX] = &cx_w_mx_parent,
563 [SC8180X_CX_AO] = &cx_ao_w_mx_parent,
564 [SC8180X_EBI] = &ebi,
565 [SC8180X_GFX] = &gfx,
566 [SC8180X_LCX] = &lcx,
567 [SC8180X_LMX] = &lmx,
568 [SC8180X_MMCX] = &mmcx,
569 [SC8180X_MMCX_AO] = &mmcx_ao,
570 [SC8180X_MSS] = &mss,
572 [SC8180X_MX_AO] = &mx_ao,
575 static const struct rpmhpd_desc sc8180x_desc = {
576 .rpmhpds = sc8180x_rpmhpds,
577 .num_pds = ARRAY_SIZE(sc8180x_rpmhpds),
580 /* SC8280xp RPMH powerdomains */
581 static struct rpmhpd *sc8280xp_rpmhpds[] = {
583 [SC8280XP_CX_AO] = &cx_ao,
584 [SC8280XP_EBI] = &ebi,
585 [SC8280XP_GFX] = &gfx,
586 [SC8280XP_LCX] = &lcx,
587 [SC8280XP_LMX] = &lmx,
588 [SC8280XP_MMCX] = &mmcx,
589 [SC8280XP_MMCX_AO] = &mmcx_ao,
591 [SC8280XP_MX_AO] = &mx_ao,
592 [SC8280XP_NSP] = &nsp,
593 [SC8280XP_QPHY] = &qphy,
596 static const struct rpmhpd_desc sc8280xp_desc = {
597 .rpmhpds = sc8280xp_rpmhpds,
598 .num_pds = ARRAY_SIZE(sc8280xp_rpmhpds),
601 /* SC8380xp RPMH powerdomains */
602 static struct rpmhpd *sc8380xp_rpmhpds[] = {
604 [RPMHPD_CX_AO] = &cx_ao,
609 [RPMHPD_MMCX] = &mmcx,
610 [RPMHPD_MMCX_AO] = &mmcx_ao,
612 [RPMHPD_MX_AO] = &mx_ao,
615 [RPMHPD_GMXC] = &gmxc,
618 static const struct rpmhpd_desc sc8380xp_desc = {
619 .rpmhpds = sc8380xp_rpmhpds,
620 .num_pds = ARRAY_SIZE(sc8380xp_rpmhpds),
623 static const struct of_device_id rpmhpd_match_table[] = {
624 { .compatible = "qcom,qdu1000-rpmhpd", .data = &qdu1000_desc },
625 { .compatible = "qcom,sa8155p-rpmhpd", .data = &sa8155p_desc },
626 { .compatible = "qcom,sa8540p-rpmhpd", .data = &sa8540p_desc },
627 { .compatible = "qcom,sa8775p-rpmhpd", .data = &sa8775p_desc },
628 { .compatible = "qcom,sc7180-rpmhpd", .data = &sc7180_desc },
629 { .compatible = "qcom,sc7280-rpmhpd", .data = &sc7280_desc },
630 { .compatible = "qcom,sc8180x-rpmhpd", .data = &sc8180x_desc },
631 { .compatible = "qcom,sc8280xp-rpmhpd", .data = &sc8280xp_desc },
632 { .compatible = "qcom,sc8380xp-rpmhpd", .data = &sc8380xp_desc },
633 { .compatible = "qcom,sdm670-rpmhpd", .data = &sdm670_desc },
634 { .compatible = "qcom,sdm845-rpmhpd", .data = &sdm845_desc },
635 { .compatible = "qcom,sdx55-rpmhpd", .data = &sdx55_desc},
636 { .compatible = "qcom,sdx65-rpmhpd", .data = &sdx65_desc},
637 { .compatible = "qcom,sdx75-rpmhpd", .data = &sdx75_desc},
638 { .compatible = "qcom,sm6350-rpmhpd", .data = &sm6350_desc },
639 { .compatible = "qcom,sm7150-rpmhpd", .data = &sm7150_desc },
640 { .compatible = "qcom,sm8150-rpmhpd", .data = &sm8150_desc },
641 { .compatible = "qcom,sm8250-rpmhpd", .data = &sm8250_desc },
642 { .compatible = "qcom,sm8350-rpmhpd", .data = &sm8350_desc },
643 { .compatible = "qcom,sm8450-rpmhpd", .data = &sm8450_desc },
644 { .compatible = "qcom,sm8550-rpmhpd", .data = &sm8550_desc },
645 { .compatible = "qcom,sm8650-rpmhpd", .data = &sm8650_desc },
648 MODULE_DEVICE_TABLE(of, rpmhpd_match_table);
650 static int rpmhpd_send_corner(struct rpmhpd *pd, int state,
651 unsigned int corner, bool sync)
653 struct tcs_cmd cmd = {
659 * Wait for an ack only when we are increasing the
660 * perf state of the power domain
663 return rpmh_write(pd->dev, state, &cmd, 1);
665 return rpmh_write_async(pd->dev, state, &cmd, 1);
668 static void to_active_sleep(struct rpmhpd *pd, unsigned int corner,
669 unsigned int *active, unsigned int *sleep)
680 * This function is used to aggregate the votes across the active only
681 * resources and its peers. The aggregated votes are sent to RPMh as
682 * ACTIVE_ONLY votes (which take effect immediately), as WAKE_ONLY votes
683 * (applied by RPMh on system wakeup) and as SLEEP votes (applied by RPMh
685 * We send ACTIVE_ONLY votes for resources without any peers. For others,
686 * which have an active only peer, all 3 votes are sent.
688 static int rpmhpd_aggregate_corner(struct rpmhpd *pd, unsigned int corner)
691 struct rpmhpd *peer = pd->peer;
692 unsigned int active_corner, sleep_corner;
693 unsigned int this_active_corner = 0, this_sleep_corner = 0;
694 unsigned int peer_active_corner = 0, peer_sleep_corner = 0;
696 if (pd->state_synced) {
697 to_active_sleep(pd, corner, &this_active_corner, &this_sleep_corner);
699 /* Clamp to highest corner if sync_state hasn't happened */
700 this_active_corner = pd->level_count - 1;
701 this_sleep_corner = pd->level_count - 1;
704 if (peer && peer->enabled)
705 to_active_sleep(peer, peer->corner, &peer_active_corner,
708 active_corner = max(this_active_corner, peer_active_corner);
710 ret = rpmhpd_send_corner(pd, RPMH_ACTIVE_ONLY_STATE, active_corner,
711 active_corner > pd->active_corner);
715 pd->active_corner = active_corner;
718 peer->active_corner = active_corner;
720 ret = rpmhpd_send_corner(pd, RPMH_WAKE_ONLY_STATE,
721 active_corner, false);
725 sleep_corner = max(this_sleep_corner, peer_sleep_corner);
727 return rpmhpd_send_corner(pd, RPMH_SLEEP_STATE, sleep_corner,
734 static int rpmhpd_power_on(struct generic_pm_domain *domain)
736 struct rpmhpd *pd = domain_to_rpmhpd(domain);
740 mutex_lock(&rpmhpd_lock);
742 corner = max(pd->corner, pd->enable_corner);
743 ret = rpmhpd_aggregate_corner(pd, corner);
747 mutex_unlock(&rpmhpd_lock);
752 static int rpmhpd_power_off(struct generic_pm_domain *domain)
754 struct rpmhpd *pd = domain_to_rpmhpd(domain);
757 mutex_lock(&rpmhpd_lock);
759 ret = rpmhpd_aggregate_corner(pd, 0);
763 mutex_unlock(&rpmhpd_lock);
768 static int rpmhpd_set_performance_state(struct generic_pm_domain *domain,
771 struct rpmhpd *pd = domain_to_rpmhpd(domain);
774 mutex_lock(&rpmhpd_lock);
776 for (i = 0; i < pd->level_count; i++)
777 if (level <= pd->level[i])
781 * If the level requested is more than that supported by the
782 * max corner, just set it to max anyway.
784 if (i == pd->level_count)
788 /* Ensure that the domain isn't turn off */
789 if (i < pd->enable_corner)
790 i = pd->enable_corner;
792 ret = rpmhpd_aggregate_corner(pd, i);
799 mutex_unlock(&rpmhpd_lock);
804 static int rpmhpd_update_level_mapping(struct rpmhpd *rpmhpd)
809 buf = cmd_db_read_aux_data(rpmhpd->res_name, &rpmhpd->level_count);
813 /* 2 bytes used for each command DB aux data entry */
814 rpmhpd->level_count >>= 1;
816 if (rpmhpd->level_count > RPMH_ARC_MAX_LEVELS)
819 for (i = 0; i < rpmhpd->level_count; i++) {
820 rpmhpd->level[i] = buf[i];
822 /* Remember the first corner with non-zero level */
823 if (!rpmhpd->level[rpmhpd->enable_corner] && rpmhpd->level[i])
824 rpmhpd->enable_corner = i;
827 * The AUX data may be zero padded. These 0 valued entries at
828 * the end of the map must be ignored.
830 if (i > 0 && rpmhpd->level[i] == 0) {
831 rpmhpd->level_count = i;
834 pr_debug("%s: ARC hlvl=%2d --> vlvl=%4u\n", rpmhpd->res_name, i,
841 static int rpmhpd_probe(struct platform_device *pdev)
845 struct device *dev = &pdev->dev;
846 struct genpd_onecell_data *data;
847 struct rpmhpd **rpmhpds;
848 const struct rpmhpd_desc *desc;
850 desc = of_device_get_match_data(dev);
854 rpmhpds = desc->rpmhpds;
855 num_pds = desc->num_pds;
857 data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
861 data->domains = devm_kcalloc(dev, num_pds, sizeof(*data->domains),
866 data->num_domains = num_pds;
868 for (i = 0; i < num_pds; i++) {
872 rpmhpds[i]->dev = dev;
873 rpmhpds[i]->addr = cmd_db_read_addr(rpmhpds[i]->res_name);
874 if (!rpmhpds[i]->addr) {
875 dev_err(dev, "Could not find RPMh address for resource %s\n",
876 rpmhpds[i]->res_name);
880 ret = cmd_db_read_slave_id(rpmhpds[i]->res_name);
881 if (ret != CMD_DB_HW_ARC) {
882 dev_err(dev, "RPMh slave ID mismatch\n");
886 ret = rpmhpd_update_level_mapping(rpmhpds[i]);
890 rpmhpds[i]->pd.power_off = rpmhpd_power_off;
891 rpmhpds[i]->pd.power_on = rpmhpd_power_on;
892 rpmhpds[i]->pd.set_performance_state = rpmhpd_set_performance_state;
893 pm_genpd_init(&rpmhpds[i]->pd, NULL, true);
895 data->domains[i] = &rpmhpds[i]->pd;
899 for (i = 0; i < num_pds; i++) {
902 if (rpmhpds[i]->parent)
903 pm_genpd_add_subdomain(rpmhpds[i]->parent,
907 return of_genpd_add_provider_onecell(pdev->dev.of_node, data);
910 static void rpmhpd_sync_state(struct device *dev)
912 const struct rpmhpd_desc *desc = of_device_get_match_data(dev);
913 struct rpmhpd **rpmhpds = desc->rpmhpds;
919 mutex_lock(&rpmhpd_lock);
920 for (i = 0; i < desc->num_pds; i++) {
925 pd->state_synced = true;
927 corner = max(pd->corner, pd->enable_corner);
931 ret = rpmhpd_aggregate_corner(pd, corner);
933 dev_err(dev, "failed to sync %s\n", pd->res_name);
935 mutex_unlock(&rpmhpd_lock);
938 static struct platform_driver rpmhpd_driver = {
940 .name = "qcom-rpmhpd",
941 .of_match_table = rpmhpd_match_table,
942 .suppress_bind_attrs = true,
943 .sync_state = rpmhpd_sync_state,
945 .probe = rpmhpd_probe,
948 static int __init rpmhpd_init(void)
950 return platform_driver_register(&rpmhpd_driver);
952 core_initcall(rpmhpd_init);
954 MODULE_DESCRIPTION("Qualcomm Technologies, Inc. RPMh Power Domain Driver");
955 MODULE_LICENSE("GPL v2");