1 // SPDX-License-Identifier: GPL-2.0-only
3 * Rockchip Generic power domain support.
5 * Copyright (c) 2015 ROCKCHIP, Co. Ltd.
9 #include <linux/iopoll.h>
10 #include <linux/err.h>
11 #include <linux/mutex.h>
12 #include <linux/platform_device.h>
13 #include <linux/pm_clock.h>
14 #include <linux/pm_domain.h>
15 #include <linux/property.h>
17 #include <linux/of_address.h>
18 #include <linux/of_clk.h>
19 #include <linux/clk.h>
20 #include <linux/regmap.h>
21 #include <linux/mfd/syscon.h>
22 #include <soc/rockchip/pm_domains.h>
23 #include <dt-bindings/power/px30-power.h>
24 #include <dt-bindings/power/rockchip,rv1126-power.h>
25 #include <dt-bindings/power/rk3036-power.h>
26 #include <dt-bindings/power/rk3066-power.h>
27 #include <dt-bindings/power/rk3128-power.h>
28 #include <dt-bindings/power/rk3188-power.h>
29 #include <dt-bindings/power/rk3228-power.h>
30 #include <dt-bindings/power/rk3288-power.h>
31 #include <dt-bindings/power/rk3328-power.h>
32 #include <dt-bindings/power/rk3366-power.h>
33 #include <dt-bindings/power/rk3368-power.h>
34 #include <dt-bindings/power/rk3399-power.h>
35 #include <dt-bindings/power/rk3568-power.h>
36 #include <dt-bindings/power/rockchip,rk3576-power.h>
37 #include <dt-bindings/power/rk3588-power.h>
39 struct rockchip_domain_info
{
51 int repair_status_mask
;
57 struct rockchip_pmu_info
{
64 u32 chain_status_offset
;
65 u32 mem_status_offset
;
66 u32 repair_status_offset
;
67 u32 clk_ungate_offset
;
69 u32 core_pwrcnt_offset
;
70 u32 gpu_pwrcnt_offset
;
72 unsigned int core_power_transition_time
;
73 unsigned int gpu_power_transition_time
;
76 const struct rockchip_domain_info
*domain_info
;
79 #define MAX_QOS_REGS_NUM 5
80 #define QOS_PRIORITY 0x08
82 #define QOS_BANDWIDTH 0x10
83 #define QOS_SATURATION 0x14
84 #define QOS_EXTCONTROL 0x18
86 struct rockchip_pm_domain
{
87 struct generic_pm_domain genpd
;
88 const struct rockchip_domain_info
*info
;
89 struct rockchip_pmu
*pmu
;
91 struct regmap
**qos_regmap
;
92 u32
*qos_save_regs
[MAX_QOS_REGS_NUM
];
94 struct clk_bulk_data
*clks
;
99 struct regmap
*regmap
;
100 const struct rockchip_pmu_info
*info
;
101 struct mutex mutex
; /* mutex lock for pmu */
102 struct genpd_onecell_data genpd_data
;
103 struct generic_pm_domain
*domains
[];
106 #define to_rockchip_pd(gpd) container_of(gpd, struct rockchip_pm_domain, genpd)
108 #define DOMAIN(_name, pwr, status, req, idle, ack, wakeup) \
112 .status_mask = (status), \
114 .idle_mask = (idle), \
116 .active_wakeup = (wakeup), \
119 #define DOMAIN_M(_name, pwr, status, req, idle, ack, wakeup) \
122 .pwr_w_mask = (pwr) << 16, \
124 .status_mask = (status), \
125 .req_w_mask = (req) << 16, \
127 .idle_mask = (idle), \
129 .active_wakeup = wakeup, \
132 #define DOMAIN_M_O_R(_name, p_offset, pwr, status, m_offset, m_status, r_status, r_offset, req, idle, ack, wakeup) \
135 .pwr_offset = p_offset, \
136 .pwr_w_mask = (pwr) << 16, \
138 .status_mask = (status), \
139 .mem_offset = m_offset, \
140 .mem_status_mask = (m_status), \
141 .repair_status_mask = (r_status), \
142 .req_offset = r_offset, \
143 .req_w_mask = (req) << 16, \
145 .idle_mask = (idle), \
147 .active_wakeup = wakeup, \
150 #define DOMAIN_M_O_R_G(_name, p_offset, pwr, status, m_offset, m_status, r_status, r_offset, req, idle, ack, g_mask, wakeup) \
153 .pwr_offset = p_offset, \
154 .pwr_w_mask = (pwr) << 16, \
156 .status_mask = (status), \
157 .mem_offset = m_offset, \
158 .mem_status_mask = (m_status), \
159 .repair_status_mask = (r_status), \
160 .req_offset = r_offset, \
161 .req_w_mask = (req) << 16, \
163 .idle_mask = (idle), \
164 .clk_ungate_mask = (g_mask), \
166 .active_wakeup = wakeup, \
169 #define DOMAIN_RK3036(_name, req, ack, idle, wakeup) \
173 .req_w_mask = (req) << 16, \
175 .idle_mask = (idle), \
176 .active_wakeup = wakeup, \
179 #define DOMAIN_PX30(name, pwr, status, req, wakeup) \
180 DOMAIN_M(name, pwr, status, req, (req) << 16, req, wakeup)
182 #define DOMAIN_RV1126(name, pwr, req, idle, wakeup) \
183 DOMAIN_M(name, pwr, pwr, req, idle, idle, wakeup)
185 #define DOMAIN_RK3288(name, pwr, status, req, wakeup) \
186 DOMAIN(name, pwr, status, req, req, (req) << 16, wakeup)
188 #define DOMAIN_RK3328(name, pwr, status, req, wakeup) \
189 DOMAIN_M(name, pwr, pwr, req, (req) << 10, req, wakeup)
191 #define DOMAIN_RK3368(name, pwr, status, req, wakeup) \
192 DOMAIN(name, pwr, status, req, (req) << 16, req, wakeup)
194 #define DOMAIN_RK3399(name, pwr, status, req, wakeup) \
195 DOMAIN(name, pwr, status, req, req, req, wakeup)
197 #define DOMAIN_RK3568(name, pwr, req, wakeup) \
198 DOMAIN_M(name, pwr, pwr, req, req, req, wakeup)
200 #define DOMAIN_RK3576(name, p_offset, pwr, status, r_status, r_offset, req, idle, g_mask, wakeup) \
201 DOMAIN_M_O_R_G(name, p_offset, pwr, status, 0, r_status, r_status, r_offset, req, idle, idle, g_mask, wakeup)
204 * Dynamic Memory Controller may need to coordinate with us -- see
205 * rockchip_pmu_block().
207 * dmc_pmu_mutex protects registration-time races, so DMC driver doesn't try to
208 * block() while we're initializing the PMU.
210 static DEFINE_MUTEX(dmc_pmu_mutex
);
211 static struct rockchip_pmu
*dmc_pmu
;
214 * Block PMU transitions and make sure they don't interfere with ARM Trusted
215 * Firmware operations. There are two conflicts, noted in the comments below.
217 * Caller must unblock PMU transitions via rockchip_pmu_unblock().
219 int rockchip_pmu_block(void)
221 struct rockchip_pmu
*pmu
;
222 struct generic_pm_domain
*genpd
;
223 struct rockchip_pm_domain
*pd
;
226 mutex_lock(&dmc_pmu_mutex
);
228 /* No PMU (yet)? Then we just block rockchip_pmu_probe(). */
234 * mutex blocks all idle transitions: we can't touch the
235 * PMU_BUS_IDLE_REQ (our ".idle_offset") register while ARM Trusted
236 * Firmware might be using it.
238 mutex_lock(&pmu
->mutex
);
241 * Power domain clocks: Per Rockchip, we *must* keep certain clocks
242 * enabled for the duration of power-domain transitions. Most
243 * transitions are handled by this driver, but some cases (in
244 * particular, DRAM DVFS / memory-controller idle) must be handled by
245 * firmware. Firmware can handle most clock management via a special
246 * "ungate" register (PMU_CRU_GATEDIS_CON0), but unfortunately, this
247 * doesn't handle PLLs. We can assist this transition by doing the
248 * clock management on behalf of firmware.
250 for (i
= 0; i
< pmu
->genpd_data
.num_domains
; i
++) {
251 genpd
= pmu
->genpd_data
.domains
[i
];
253 pd
= to_rockchip_pd(genpd
);
254 ret
= clk_bulk_enable(pd
->num_clks
, pd
->clks
);
257 "failed to enable clks for domain '%s': %d\n",
267 for (i
= i
- 1; i
>= 0; i
--) {
268 genpd
= pmu
->genpd_data
.domains
[i
];
270 pd
= to_rockchip_pd(genpd
);
271 clk_bulk_disable(pd
->num_clks
, pd
->clks
);
274 mutex_unlock(&pmu
->mutex
);
275 mutex_unlock(&dmc_pmu_mutex
);
279 EXPORT_SYMBOL_GPL(rockchip_pmu_block
);
281 /* Unblock PMU transitions. */
282 void rockchip_pmu_unblock(void)
284 struct rockchip_pmu
*pmu
;
285 struct generic_pm_domain
*genpd
;
286 struct rockchip_pm_domain
*pd
;
291 for (i
= 0; i
< pmu
->genpd_data
.num_domains
; i
++) {
292 genpd
= pmu
->genpd_data
.domains
[i
];
294 pd
= to_rockchip_pd(genpd
);
295 clk_bulk_disable(pd
->num_clks
, pd
->clks
);
299 mutex_unlock(&pmu
->mutex
);
302 mutex_unlock(&dmc_pmu_mutex
);
304 EXPORT_SYMBOL_GPL(rockchip_pmu_unblock
);
306 #define DOMAIN_RK3588(name, p_offset, pwr, status, m_offset, m_status, r_status, r_offset, req, idle, wakeup) \
307 DOMAIN_M_O_R(name, p_offset, pwr, status, m_offset, m_status, r_status, r_offset, req, idle, idle, wakeup)
309 static bool rockchip_pmu_domain_is_idle(struct rockchip_pm_domain
*pd
)
311 struct rockchip_pmu
*pmu
= pd
->pmu
;
312 const struct rockchip_domain_info
*pd_info
= pd
->info
;
315 regmap_read(pmu
->regmap
, pmu
->info
->idle_offset
, &val
);
316 return (val
& pd_info
->idle_mask
) == pd_info
->idle_mask
;
319 static unsigned int rockchip_pmu_read_ack(struct rockchip_pmu
*pmu
)
323 regmap_read(pmu
->regmap
, pmu
->info
->ack_offset
, &val
);
327 static int rockchip_pmu_ungate_clk(struct rockchip_pm_domain
*pd
, bool ungate
)
329 const struct rockchip_domain_info
*pd_info
= pd
->info
;
330 struct rockchip_pmu
*pmu
= pd
->pmu
;
332 int clk_ungate_w_mask
= pd_info
->clk_ungate_mask
<< 16;
334 if (!pd_info
->clk_ungate_mask
)
337 if (!pmu
->info
->clk_ungate_offset
)
340 val
= ungate
? (pd_info
->clk_ungate_mask
| clk_ungate_w_mask
) :
342 regmap_write(pmu
->regmap
, pmu
->info
->clk_ungate_offset
, val
);
347 static int rockchip_pmu_set_idle_request(struct rockchip_pm_domain
*pd
,
350 const struct rockchip_domain_info
*pd_info
= pd
->info
;
351 struct generic_pm_domain
*genpd
= &pd
->genpd
;
352 struct rockchip_pmu
*pmu
= pd
->pmu
;
353 u32 pd_req_offset
= pd_info
->req_offset
;
354 unsigned int target_ack
;
359 if (pd_info
->req_mask
== 0)
361 else if (pd_info
->req_w_mask
)
362 regmap_write(pmu
->regmap
, pmu
->info
->req_offset
+ pd_req_offset
,
363 idle
? (pd_info
->req_mask
| pd_info
->req_w_mask
) :
364 pd_info
->req_w_mask
);
366 regmap_update_bits(pmu
->regmap
, pmu
->info
->req_offset
+ pd_req_offset
,
367 pd_info
->req_mask
, idle
? -1U : 0);
371 /* Wait util idle_ack = 1 */
372 target_ack
= idle
? pd_info
->ack_mask
: 0;
373 ret
= readx_poll_timeout_atomic(rockchip_pmu_read_ack
, pmu
, val
,
374 (val
& pd_info
->ack_mask
) == target_ack
,
378 "failed to get ack on domain '%s', val=0x%x\n",
383 ret
= readx_poll_timeout_atomic(rockchip_pmu_domain_is_idle
, pd
,
384 is_idle
, is_idle
== idle
, 0, 10000);
387 "failed to set idle on domain '%s', val=%d\n",
388 genpd
->name
, is_idle
);
395 static int rockchip_pmu_save_qos(struct rockchip_pm_domain
*pd
)
399 for (i
= 0; i
< pd
->num_qos
; i
++) {
400 regmap_read(pd
->qos_regmap
[i
],
402 &pd
->qos_save_regs
[0][i
]);
403 regmap_read(pd
->qos_regmap
[i
],
405 &pd
->qos_save_regs
[1][i
]);
406 regmap_read(pd
->qos_regmap
[i
],
408 &pd
->qos_save_regs
[2][i
]);
409 regmap_read(pd
->qos_regmap
[i
],
411 &pd
->qos_save_regs
[3][i
]);
412 regmap_read(pd
->qos_regmap
[i
],
414 &pd
->qos_save_regs
[4][i
]);
419 static int rockchip_pmu_restore_qos(struct rockchip_pm_domain
*pd
)
423 for (i
= 0; i
< pd
->num_qos
; i
++) {
424 regmap_write(pd
->qos_regmap
[i
],
426 pd
->qos_save_regs
[0][i
]);
427 regmap_write(pd
->qos_regmap
[i
],
429 pd
->qos_save_regs
[1][i
]);
430 regmap_write(pd
->qos_regmap
[i
],
432 pd
->qos_save_regs
[2][i
]);
433 regmap_write(pd
->qos_regmap
[i
],
435 pd
->qos_save_regs
[3][i
]);
436 regmap_write(pd
->qos_regmap
[i
],
438 pd
->qos_save_regs
[4][i
]);
444 static bool rockchip_pmu_domain_is_on(struct rockchip_pm_domain
*pd
)
446 struct rockchip_pmu
*pmu
= pd
->pmu
;
449 if (pd
->info
->repair_status_mask
) {
450 regmap_read(pmu
->regmap
, pmu
->info
->repair_status_offset
, &val
);
451 /* 1'b1: power on, 1'b0: power off */
452 return val
& pd
->info
->repair_status_mask
;
455 /* check idle status for idle-only domains */
456 if (pd
->info
->status_mask
== 0)
457 return !rockchip_pmu_domain_is_idle(pd
);
459 regmap_read(pmu
->regmap
, pmu
->info
->status_offset
, &val
);
461 /* 1'b0: power on, 1'b1: power off */
462 return !(val
& pd
->info
->status_mask
);
465 static bool rockchip_pmu_domain_is_mem_on(struct rockchip_pm_domain
*pd
)
467 struct rockchip_pmu
*pmu
= pd
->pmu
;
470 regmap_read(pmu
->regmap
,
471 pmu
->info
->mem_status_offset
+ pd
->info
->mem_offset
, &val
);
473 /* 1'b0: power on, 1'b1: power off */
474 return !(val
& pd
->info
->mem_status_mask
);
477 static bool rockchip_pmu_domain_is_chain_on(struct rockchip_pm_domain
*pd
)
479 struct rockchip_pmu
*pmu
= pd
->pmu
;
482 regmap_read(pmu
->regmap
,
483 pmu
->info
->chain_status_offset
+ pd
->info
->mem_offset
, &val
);
485 /* 1'b1: power on, 1'b0: power off */
486 return val
& pd
->info
->mem_status_mask
;
489 static int rockchip_pmu_domain_mem_reset(struct rockchip_pm_domain
*pd
)
491 struct rockchip_pmu
*pmu
= pd
->pmu
;
492 struct generic_pm_domain
*genpd
= &pd
->genpd
;
496 ret
= readx_poll_timeout_atomic(rockchip_pmu_domain_is_chain_on
, pd
, is_on
,
497 is_on
== true, 0, 10000);
500 "failed to get chain status '%s', target_on=1, val=%d\n",
507 regmap_write(pmu
->regmap
, pmu
->info
->mem_pwr_offset
+ pd
->info
->pwr_offset
,
508 (pd
->info
->pwr_mask
| pd
->info
->pwr_w_mask
));
511 ret
= readx_poll_timeout_atomic(rockchip_pmu_domain_is_mem_on
, pd
, is_on
,
512 is_on
== false, 0, 10000);
515 "failed to get mem status '%s', target_on=0, val=%d\n",
520 regmap_write(pmu
->regmap
, pmu
->info
->mem_pwr_offset
+ pd
->info
->pwr_offset
,
521 pd
->info
->pwr_w_mask
);
524 ret
= readx_poll_timeout_atomic(rockchip_pmu_domain_is_mem_on
, pd
, is_on
,
525 is_on
== true, 0, 10000);
528 "failed to get mem status '%s', target_on=1, val=%d\n",
536 static void rockchip_do_pmu_set_power_domain(struct rockchip_pm_domain
*pd
,
539 struct rockchip_pmu
*pmu
= pd
->pmu
;
540 struct generic_pm_domain
*genpd
= &pd
->genpd
;
541 u32 pd_pwr_offset
= pd
->info
->pwr_offset
;
542 bool is_on
, is_mem_on
= false;
544 if (pd
->info
->pwr_mask
== 0)
547 if (on
&& pd
->info
->mem_status_mask
)
548 is_mem_on
= rockchip_pmu_domain_is_mem_on(pd
);
550 if (pd
->info
->pwr_w_mask
)
551 regmap_write(pmu
->regmap
, pmu
->info
->pwr_offset
+ pd_pwr_offset
,
552 on
? pd
->info
->pwr_w_mask
:
553 (pd
->info
->pwr_mask
| pd
->info
->pwr_w_mask
));
555 regmap_update_bits(pmu
->regmap
, pmu
->info
->pwr_offset
+ pd_pwr_offset
,
556 pd
->info
->pwr_mask
, on
? 0 : -1U);
560 if (is_mem_on
&& rockchip_pmu_domain_mem_reset(pd
))
563 if (readx_poll_timeout_atomic(rockchip_pmu_domain_is_on
, pd
, is_on
,
564 is_on
== on
, 0, 10000)) {
566 "failed to set domain '%s', val=%d\n",
572 static int rockchip_pd_power(struct rockchip_pm_domain
*pd
, bool power_on
)
574 struct rockchip_pmu
*pmu
= pd
->pmu
;
577 mutex_lock(&pmu
->mutex
);
579 if (rockchip_pmu_domain_is_on(pd
) != power_on
) {
580 ret
= clk_bulk_enable(pd
->num_clks
, pd
->clks
);
582 dev_err(pmu
->dev
, "failed to enable clocks\n");
583 mutex_unlock(&pmu
->mutex
);
587 rockchip_pmu_ungate_clk(pd
, true);
590 rockchip_pmu_save_qos(pd
);
592 /* if powering down, idle request to NIU first */
593 rockchip_pmu_set_idle_request(pd
, true);
596 rockchip_do_pmu_set_power_domain(pd
, power_on
);
599 /* if powering up, leave idle mode */
600 rockchip_pmu_set_idle_request(pd
, false);
602 rockchip_pmu_restore_qos(pd
);
605 rockchip_pmu_ungate_clk(pd
, false);
606 clk_bulk_disable(pd
->num_clks
, pd
->clks
);
609 mutex_unlock(&pmu
->mutex
);
613 static int rockchip_pd_power_on(struct generic_pm_domain
*domain
)
615 struct rockchip_pm_domain
*pd
= to_rockchip_pd(domain
);
617 return rockchip_pd_power(pd
, true);
620 static int rockchip_pd_power_off(struct generic_pm_domain
*domain
)
622 struct rockchip_pm_domain
*pd
= to_rockchip_pd(domain
);
624 return rockchip_pd_power(pd
, false);
627 static int rockchip_pd_attach_dev(struct generic_pm_domain
*genpd
,
634 dev_dbg(dev
, "attaching to power domain '%s'\n", genpd
->name
);
636 error
= pm_clk_create(dev
);
638 dev_err(dev
, "pm_clk_create failed %d\n", error
);
643 while ((clk
= of_clk_get(dev
->of_node
, i
++)) && !IS_ERR(clk
)) {
644 dev_dbg(dev
, "adding clock '%pC' to list of PM clocks\n", clk
);
645 error
= pm_clk_add_clk(dev
, clk
);
647 dev_err(dev
, "pm_clk_add_clk failed %d\n", error
);
657 static void rockchip_pd_detach_dev(struct generic_pm_domain
*genpd
,
660 dev_dbg(dev
, "detaching from power domain '%s'\n", genpd
->name
);
665 static int rockchip_pm_add_one_domain(struct rockchip_pmu
*pmu
,
666 struct device_node
*node
)
668 const struct rockchip_domain_info
*pd_info
;
669 struct rockchip_pm_domain
*pd
;
670 struct device_node
*qos_node
;
675 error
= of_property_read_u32(node
, "reg", &id
);
678 "%pOFn: failed to retrieve domain id (reg): %d\n",
683 if (id
>= pmu
->info
->num_domains
) {
684 dev_err(pmu
->dev
, "%pOFn: invalid domain id %d\n",
688 /* RK3588 has domains with two parents (RKVDEC0/RKVDEC1) */
689 if (pmu
->genpd_data
.domains
[id
])
692 pd_info
= &pmu
->info
->domain_info
[id
];
694 dev_err(pmu
->dev
, "%pOFn: undefined domain id %d\n",
699 pd
= devm_kzalloc(pmu
->dev
, sizeof(*pd
), GFP_KERNEL
);
706 pd
->num_clks
= of_clk_get_parent_count(node
);
707 if (pd
->num_clks
> 0) {
708 pd
->clks
= devm_kcalloc(pmu
->dev
, pd
->num_clks
,
709 sizeof(*pd
->clks
), GFP_KERNEL
);
713 dev_dbg(pmu
->dev
, "%pOFn: doesn't have clocks: %d\n",
718 for (i
= 0; i
< pd
->num_clks
; i
++) {
719 pd
->clks
[i
].clk
= of_clk_get(node
, i
);
720 if (IS_ERR(pd
->clks
[i
].clk
)) {
721 error
= PTR_ERR(pd
->clks
[i
].clk
);
723 "%pOFn: failed to get clk at index %d: %d\n",
729 error
= clk_bulk_prepare(pd
->num_clks
, pd
->clks
);
733 pd
->num_qos
= of_count_phandle_with_args(node
, "pm_qos",
736 if (pd
->num_qos
> 0) {
737 pd
->qos_regmap
= devm_kcalloc(pmu
->dev
, pd
->num_qos
,
738 sizeof(*pd
->qos_regmap
),
740 if (!pd
->qos_regmap
) {
742 goto err_unprepare_clocks
;
745 for (j
= 0; j
< MAX_QOS_REGS_NUM
; j
++) {
746 pd
->qos_save_regs
[j
] = devm_kcalloc(pmu
->dev
,
750 if (!pd
->qos_save_regs
[j
]) {
752 goto err_unprepare_clocks
;
756 for (j
= 0; j
< pd
->num_qos
; j
++) {
757 qos_node
= of_parse_phandle(node
, "pm_qos", j
);
760 goto err_unprepare_clocks
;
762 pd
->qos_regmap
[j
] = syscon_node_to_regmap(qos_node
);
763 of_node_put(qos_node
);
764 if (IS_ERR(pd
->qos_regmap
[j
])) {
766 goto err_unprepare_clocks
;
772 pd
->genpd
.name
= pd
->info
->name
;
774 pd
->genpd
.name
= kbasename(node
->full_name
);
775 pd
->genpd
.power_off
= rockchip_pd_power_off
;
776 pd
->genpd
.power_on
= rockchip_pd_power_on
;
777 pd
->genpd
.attach_dev
= rockchip_pd_attach_dev
;
778 pd
->genpd
.detach_dev
= rockchip_pd_detach_dev
;
779 pd
->genpd
.flags
= GENPD_FLAG_PM_CLK
;
780 if (pd_info
->active_wakeup
)
781 pd
->genpd
.flags
|= GENPD_FLAG_ACTIVE_WAKEUP
;
782 pm_genpd_init(&pd
->genpd
, NULL
,
783 !rockchip_pmu_domain_is_on(pd
) ||
784 (pd
->info
->mem_status_mask
&& !rockchip_pmu_domain_is_mem_on(pd
)));
786 pmu
->genpd_data
.domains
[id
] = &pd
->genpd
;
789 err_unprepare_clocks
:
790 clk_bulk_unprepare(pd
->num_clks
, pd
->clks
);
792 clk_bulk_put(pd
->num_clks
, pd
->clks
);
796 static void rockchip_pm_remove_one_domain(struct rockchip_pm_domain
*pd
)
801 * We're in the error cleanup already, so we only complain,
802 * but won't emit another error on top of the original one.
804 ret
= pm_genpd_remove(&pd
->genpd
);
806 dev_err(pd
->pmu
->dev
, "failed to remove domain '%s' : %d - state may be inconsistent\n",
807 pd
->genpd
.name
, ret
);
809 clk_bulk_unprepare(pd
->num_clks
, pd
->clks
);
810 clk_bulk_put(pd
->num_clks
, pd
->clks
);
812 /* protect the zeroing of pm->num_clks */
813 mutex_lock(&pd
->pmu
->mutex
);
815 mutex_unlock(&pd
->pmu
->mutex
);
817 /* devm will free our memory */
820 static void rockchip_pm_domain_cleanup(struct rockchip_pmu
*pmu
)
822 struct generic_pm_domain
*genpd
;
823 struct rockchip_pm_domain
*pd
;
826 for (i
= 0; i
< pmu
->genpd_data
.num_domains
; i
++) {
827 genpd
= pmu
->genpd_data
.domains
[i
];
829 pd
= to_rockchip_pd(genpd
);
830 rockchip_pm_remove_one_domain(pd
);
834 /* devm will free our memory */
837 static void rockchip_configure_pd_cnt(struct rockchip_pmu
*pmu
,
838 u32 domain_reg_offset
,
841 /* First configure domain power down transition count ... */
842 regmap_write(pmu
->regmap
, domain_reg_offset
, count
);
843 /* ... and then power up count. */
844 regmap_write(pmu
->regmap
, domain_reg_offset
+ 4, count
);
847 static int rockchip_pm_add_subdomain(struct rockchip_pmu
*pmu
,
848 struct device_node
*parent
)
850 struct generic_pm_domain
*child_domain
, *parent_domain
;
853 for_each_child_of_node_scoped(parent
, np
) {
856 error
= of_property_read_u32(parent
, "reg", &idx
);
859 "%pOFn: failed to retrieve domain id (reg): %d\n",
863 parent_domain
= pmu
->genpd_data
.domains
[idx
];
865 error
= rockchip_pm_add_one_domain(pmu
, np
);
867 dev_err(pmu
->dev
, "failed to handle node %pOFn: %d\n",
872 error
= of_property_read_u32(np
, "reg", &idx
);
875 "%pOFn: failed to retrieve domain id (reg): %d\n",
879 child_domain
= pmu
->genpd_data
.domains
[idx
];
881 error
= pm_genpd_add_subdomain(parent_domain
, child_domain
);
883 dev_err(pmu
->dev
, "%s failed to add subdomain %s: %d\n",
884 parent_domain
->name
, child_domain
->name
, error
);
887 dev_dbg(pmu
->dev
, "%s add subdomain: %s\n",
888 parent_domain
->name
, child_domain
->name
);
891 rockchip_pm_add_subdomain(pmu
, np
);
897 static int rockchip_pm_domain_probe(struct platform_device
*pdev
)
899 struct device
*dev
= &pdev
->dev
;
900 struct device_node
*np
= dev
->of_node
;
901 struct device
*parent
;
902 struct rockchip_pmu
*pmu
;
903 const struct rockchip_pmu_info
*pmu_info
;
907 dev_err(dev
, "device tree node not found\n");
911 pmu_info
= device_get_match_data(dev
);
913 pmu
= devm_kzalloc(dev
,
914 struct_size(pmu
, domains
, pmu_info
->num_domains
),
919 pmu
->dev
= &pdev
->dev
;
920 mutex_init(&pmu
->mutex
);
922 pmu
->info
= pmu_info
;
924 pmu
->genpd_data
.domains
= pmu
->domains
;
925 pmu
->genpd_data
.num_domains
= pmu_info
->num_domains
;
927 parent
= dev
->parent
;
929 dev_err(dev
, "no parent for syscon devices\n");
933 pmu
->regmap
= syscon_node_to_regmap(parent
->of_node
);
934 if (IS_ERR(pmu
->regmap
)) {
935 dev_err(dev
, "no regmap available\n");
936 return PTR_ERR(pmu
->regmap
);
940 * Configure power up and down transition delays for CORE
943 if (pmu_info
->core_power_transition_time
)
944 rockchip_configure_pd_cnt(pmu
, pmu_info
->core_pwrcnt_offset
,
945 pmu_info
->core_power_transition_time
);
946 if (pmu_info
->gpu_pwrcnt_offset
)
947 rockchip_configure_pd_cnt(pmu
, pmu_info
->gpu_pwrcnt_offset
,
948 pmu_info
->gpu_power_transition_time
);
953 * Prevent any rockchip_pmu_block() from racing with the remainder of
954 * setup (clocks, register initialization).
956 guard(mutex
)(&dmc_pmu_mutex
);
958 for_each_available_child_of_node_scoped(np
, node
) {
959 error
= rockchip_pm_add_one_domain(pmu
, node
);
961 dev_err(dev
, "failed to handle node %pOFn: %d\n",
966 error
= rockchip_pm_add_subdomain(pmu
, node
);
968 dev_err(dev
, "failed to handle subdomain node %pOFn: %d\n",
975 dev_dbg(dev
, "no power domains defined\n");
979 error
= of_genpd_add_provider_onecell(np
, &pmu
->genpd_data
);
981 dev_err(dev
, "failed to add provider: %d\n", error
);
985 /* We only expect one PMU. */
986 if (!WARN_ON_ONCE(dmc_pmu
))
992 rockchip_pm_domain_cleanup(pmu
);
996 static const struct rockchip_domain_info px30_pm_domains
[] = {
997 [PX30_PD_USB
] = DOMAIN_PX30("usb", BIT(5), BIT(5), BIT(10), false),
998 [PX30_PD_SDCARD
] = DOMAIN_PX30("sdcard", BIT(8), BIT(8), BIT(9), false),
999 [PX30_PD_GMAC
] = DOMAIN_PX30("gmac", BIT(10), BIT(10), BIT(6), false),
1000 [PX30_PD_MMC_NAND
] = DOMAIN_PX30("mmc_nand", BIT(11), BIT(11), BIT(5), false),
1001 [PX30_PD_VPU
] = DOMAIN_PX30("vpu", BIT(12), BIT(12), BIT(14), false),
1002 [PX30_PD_VO
] = DOMAIN_PX30("vo", BIT(13), BIT(13), BIT(7), false),
1003 [PX30_PD_VI
] = DOMAIN_PX30("vi", BIT(14), BIT(14), BIT(8), false),
1004 [PX30_PD_GPU
] = DOMAIN_PX30("gpu", BIT(15), BIT(15), BIT(2), false),
1007 static const struct rockchip_domain_info rv1126_pm_domains
[] = {
1008 [RV1126_PD_VEPU
] = DOMAIN_RV1126("vepu", BIT(2), BIT(9), BIT(9), false),
1009 [RV1126_PD_VI
] = DOMAIN_RV1126("vi", BIT(4), BIT(6), BIT(6), false),
1010 [RV1126_PD_VO
] = DOMAIN_RV1126("vo", BIT(5), BIT(7), BIT(7), false),
1011 [RV1126_PD_ISPP
] = DOMAIN_RV1126("ispp", BIT(1), BIT(8), BIT(8), false),
1012 [RV1126_PD_VDPU
] = DOMAIN_RV1126("vdpu", BIT(3), BIT(10), BIT(10), false),
1013 [RV1126_PD_NVM
] = DOMAIN_RV1126("nvm", BIT(7), BIT(11), BIT(11), false),
1014 [RV1126_PD_SDIO
] = DOMAIN_RV1126("sdio", BIT(8), BIT(13), BIT(13), false),
1015 [RV1126_PD_USB
] = DOMAIN_RV1126("usb", BIT(9), BIT(15), BIT(15), false),
1018 static const struct rockchip_domain_info rk3036_pm_domains
[] = {
1019 [RK3036_PD_MSCH
] = DOMAIN_RK3036("msch", BIT(14), BIT(23), BIT(30), true),
1020 [RK3036_PD_CORE
] = DOMAIN_RK3036("core", BIT(13), BIT(17), BIT(24), false),
1021 [RK3036_PD_PERI
] = DOMAIN_RK3036("peri", BIT(12), BIT(18), BIT(25), false),
1022 [RK3036_PD_VIO
] = DOMAIN_RK3036("vio", BIT(11), BIT(19), BIT(26), false),
1023 [RK3036_PD_VPU
] = DOMAIN_RK3036("vpu", BIT(10), BIT(20), BIT(27), false),
1024 [RK3036_PD_GPU
] = DOMAIN_RK3036("gpu", BIT(9), BIT(21), BIT(28), false),
1025 [RK3036_PD_SYS
] = DOMAIN_RK3036("sys", BIT(8), BIT(22), BIT(29), false),
1028 static const struct rockchip_domain_info rk3066_pm_domains
[] = {
1029 [RK3066_PD_GPU
] = DOMAIN("gpu", BIT(9), BIT(9), BIT(3), BIT(24), BIT(29), false),
1030 [RK3066_PD_VIDEO
] = DOMAIN("video", BIT(8), BIT(8), BIT(4), BIT(23), BIT(28), false),
1031 [RK3066_PD_VIO
] = DOMAIN("vio", BIT(7), BIT(7), BIT(5), BIT(22), BIT(27), false),
1032 [RK3066_PD_PERI
] = DOMAIN("peri", BIT(6), BIT(6), BIT(2), BIT(25), BIT(30), false),
1033 [RK3066_PD_CPU
] = DOMAIN("cpu", 0, BIT(5), BIT(1), BIT(26), BIT(31), false),
1036 static const struct rockchip_domain_info rk3128_pm_domains
[] = {
1037 [RK3128_PD_CORE
] = DOMAIN_RK3288("core", BIT(0), BIT(0), BIT(4), false),
1038 [RK3128_PD_MSCH
] = DOMAIN_RK3288("msch", 0, 0, BIT(6), true),
1039 [RK3128_PD_VIO
] = DOMAIN_RK3288("vio", BIT(3), BIT(3), BIT(2), false),
1040 [RK3128_PD_VIDEO
] = DOMAIN_RK3288("video", BIT(2), BIT(2), BIT(1), false),
1041 [RK3128_PD_GPU
] = DOMAIN_RK3288("gpu", BIT(1), BIT(1), BIT(3), false),
1044 static const struct rockchip_domain_info rk3188_pm_domains
[] = {
1045 [RK3188_PD_GPU
] = DOMAIN("gpu", BIT(9), BIT(9), BIT(3), BIT(24), BIT(29), false),
1046 [RK3188_PD_VIDEO
] = DOMAIN("video", BIT(8), BIT(8), BIT(4), BIT(23), BIT(28), false),
1047 [RK3188_PD_VIO
] = DOMAIN("vio", BIT(7), BIT(7), BIT(5), BIT(22), BIT(27), false),
1048 [RK3188_PD_PERI
] = DOMAIN("peri", BIT(6), BIT(6), BIT(2), BIT(25), BIT(30), false),
1049 [RK3188_PD_CPU
] = DOMAIN("cpu", BIT(5), BIT(5), BIT(1), BIT(26), BIT(31), false),
1052 static const struct rockchip_domain_info rk3228_pm_domains
[] = {
1053 [RK3228_PD_CORE
] = DOMAIN_RK3036("core", BIT(0), BIT(0), BIT(16), true),
1054 [RK3228_PD_MSCH
] = DOMAIN_RK3036("msch", BIT(1), BIT(1), BIT(17), true),
1055 [RK3228_PD_BUS
] = DOMAIN_RK3036("bus", BIT(2), BIT(2), BIT(18), true),
1056 [RK3228_PD_SYS
] = DOMAIN_RK3036("sys", BIT(3), BIT(3), BIT(19), true),
1057 [RK3228_PD_VIO
] = DOMAIN_RK3036("vio", BIT(4), BIT(4), BIT(20), false),
1058 [RK3228_PD_VOP
] = DOMAIN_RK3036("vop", BIT(5), BIT(5), BIT(21), false),
1059 [RK3228_PD_VPU
] = DOMAIN_RK3036("vpu", BIT(6), BIT(6), BIT(22), false),
1060 [RK3228_PD_RKVDEC
] = DOMAIN_RK3036("vdec", BIT(7), BIT(7), BIT(23), false),
1061 [RK3228_PD_GPU
] = DOMAIN_RK3036("gpu", BIT(8), BIT(8), BIT(24), false),
1062 [RK3228_PD_PERI
] = DOMAIN_RK3036("peri", BIT(9), BIT(9), BIT(25), true),
1063 [RK3228_PD_GMAC
] = DOMAIN_RK3036("gmac", BIT(10), BIT(10), BIT(26), false),
1066 static const struct rockchip_domain_info rk3288_pm_domains
[] = {
1067 [RK3288_PD_VIO
] = DOMAIN_RK3288("vio", BIT(7), BIT(7), BIT(4), false),
1068 [RK3288_PD_HEVC
] = DOMAIN_RK3288("hevc", BIT(14), BIT(10), BIT(9), false),
1069 [RK3288_PD_VIDEO
] = DOMAIN_RK3288("video", BIT(8), BIT(8), BIT(3), false),
1070 [RK3288_PD_GPU
] = DOMAIN_RK3288("gpu", BIT(9), BIT(9), BIT(2), false),
1073 static const struct rockchip_domain_info rk3328_pm_domains
[] = {
1074 [RK3328_PD_CORE
] = DOMAIN_RK3328("core", 0, BIT(0), BIT(0), false),
1075 [RK3328_PD_GPU
] = DOMAIN_RK3328("gpu", 0, BIT(1), BIT(1), false),
1076 [RK3328_PD_BUS
] = DOMAIN_RK3328("bus", 0, BIT(2), BIT(2), true),
1077 [RK3328_PD_MSCH
] = DOMAIN_RK3328("msch", 0, BIT(3), BIT(3), true),
1078 [RK3328_PD_PERI
] = DOMAIN_RK3328("peri", 0, BIT(4), BIT(4), true),
1079 [RK3328_PD_VIDEO
] = DOMAIN_RK3328("video", 0, BIT(5), BIT(5), false),
1080 [RK3328_PD_HEVC
] = DOMAIN_RK3328("hevc", 0, BIT(6), BIT(6), false),
1081 [RK3328_PD_VIO
] = DOMAIN_RK3328("vio", 0, BIT(8), BIT(8), false),
1082 [RK3328_PD_VPU
] = DOMAIN_RK3328("vpu", 0, BIT(9), BIT(9), false),
1085 static const struct rockchip_domain_info rk3366_pm_domains
[] = {
1086 [RK3366_PD_PERI
] = DOMAIN_RK3368("peri", BIT(10), BIT(10), BIT(6), true),
1087 [RK3366_PD_VIO
] = DOMAIN_RK3368("vio", BIT(14), BIT(14), BIT(8), false),
1088 [RK3366_PD_VIDEO
] = DOMAIN_RK3368("video", BIT(13), BIT(13), BIT(7), false),
1089 [RK3366_PD_RKVDEC
] = DOMAIN_RK3368("vdec", BIT(11), BIT(11), BIT(7), false),
1090 [RK3366_PD_WIFIBT
] = DOMAIN_RK3368("wifibt", BIT(8), BIT(8), BIT(9), false),
1091 [RK3366_PD_VPU
] = DOMAIN_RK3368("vpu", BIT(12), BIT(12), BIT(7), false),
1092 [RK3366_PD_GPU
] = DOMAIN_RK3368("gpu", BIT(15), BIT(15), BIT(2), false),
1095 static const struct rockchip_domain_info rk3368_pm_domains
[] = {
1096 [RK3368_PD_PERI
] = DOMAIN_RK3368("peri", BIT(13), BIT(12), BIT(6), true),
1097 [RK3368_PD_VIO
] = DOMAIN_RK3368("vio", BIT(15), BIT(14), BIT(8), false),
1098 [RK3368_PD_VIDEO
] = DOMAIN_RK3368("video", BIT(14), BIT(13), BIT(7), false),
1099 [RK3368_PD_GPU_0
] = DOMAIN_RK3368("gpu_0", BIT(16), BIT(15), BIT(2), false),
1100 [RK3368_PD_GPU_1
] = DOMAIN_RK3368("gpu_1", BIT(17), BIT(16), BIT(2), false),
1103 static const struct rockchip_domain_info rk3399_pm_domains
[] = {
1104 [RK3399_PD_TCPD0
] = DOMAIN_RK3399("tcpd0", BIT(8), BIT(8), 0, false),
1105 [RK3399_PD_TCPD1
] = DOMAIN_RK3399("tcpd1", BIT(9), BIT(9), 0, false),
1106 [RK3399_PD_CCI
] = DOMAIN_RK3399("cci", BIT(10), BIT(10), 0, true),
1107 [RK3399_PD_CCI0
] = DOMAIN_RK3399("cci0", 0, 0, BIT(15), true),
1108 [RK3399_PD_CCI1
] = DOMAIN_RK3399("cci1", 0, 0, BIT(16), true),
1109 [RK3399_PD_PERILP
] = DOMAIN_RK3399("perilp", BIT(11), BIT(11), BIT(1), true),
1110 [RK3399_PD_PERIHP
] = DOMAIN_RK3399("perihp", BIT(12), BIT(12), BIT(2), true),
1111 [RK3399_PD_CENTER
] = DOMAIN_RK3399("center", BIT(13), BIT(13), BIT(14), true),
1112 [RK3399_PD_VIO
] = DOMAIN_RK3399("vio", BIT(14), BIT(14), BIT(17), false),
1113 [RK3399_PD_GPU
] = DOMAIN_RK3399("gpu", BIT(15), BIT(15), BIT(0), false),
1114 [RK3399_PD_VCODEC
] = DOMAIN_RK3399("vcodec", BIT(16), BIT(16), BIT(3), false),
1115 [RK3399_PD_VDU
] = DOMAIN_RK3399("vdu", BIT(17), BIT(17), BIT(4), false),
1116 [RK3399_PD_RGA
] = DOMAIN_RK3399("rga", BIT(18), BIT(18), BIT(5), false),
1117 [RK3399_PD_IEP
] = DOMAIN_RK3399("iep", BIT(19), BIT(19), BIT(6), false),
1118 [RK3399_PD_VO
] = DOMAIN_RK3399("vo", BIT(20), BIT(20), 0, false),
1119 [RK3399_PD_VOPB
] = DOMAIN_RK3399("vopb", 0, 0, BIT(7), false),
1120 [RK3399_PD_VOPL
] = DOMAIN_RK3399("vopl", 0, 0, BIT(8), false),
1121 [RK3399_PD_ISP0
] = DOMAIN_RK3399("isp0", BIT(22), BIT(22), BIT(9), false),
1122 [RK3399_PD_ISP1
] = DOMAIN_RK3399("isp1", BIT(23), BIT(23), BIT(10), false),
1123 [RK3399_PD_HDCP
] = DOMAIN_RK3399("hdcp", BIT(24), BIT(24), BIT(11), false),
1124 [RK3399_PD_GMAC
] = DOMAIN_RK3399("gmac", BIT(25), BIT(25), BIT(23), true),
1125 [RK3399_PD_EMMC
] = DOMAIN_RK3399("emmc", BIT(26), BIT(26), BIT(24), true),
1126 [RK3399_PD_USB3
] = DOMAIN_RK3399("usb3", BIT(27), BIT(27), BIT(12), true),
1127 [RK3399_PD_EDP
] = DOMAIN_RK3399("edp", BIT(28), BIT(28), BIT(22), false),
1128 [RK3399_PD_GIC
] = DOMAIN_RK3399("gic", BIT(29), BIT(29), BIT(27), true),
1129 [RK3399_PD_SD
] = DOMAIN_RK3399("sd", BIT(30), BIT(30), BIT(28), true),
1130 [RK3399_PD_SDIOAUDIO
] = DOMAIN_RK3399("sdioaudio", BIT(31), BIT(31), BIT(29), true),
1133 static const struct rockchip_domain_info rk3568_pm_domains
[] = {
1134 [RK3568_PD_NPU
] = DOMAIN_RK3568("npu", BIT(1), BIT(2), false),
1135 [RK3568_PD_GPU
] = DOMAIN_RK3568("gpu", BIT(0), BIT(1), false),
1136 [RK3568_PD_VI
] = DOMAIN_RK3568("vi", BIT(6), BIT(3), false),
1137 [RK3568_PD_VO
] = DOMAIN_RK3568("vo", BIT(7), BIT(4), false),
1138 [RK3568_PD_RGA
] = DOMAIN_RK3568("rga", BIT(5), BIT(5), false),
1139 [RK3568_PD_VPU
] = DOMAIN_RK3568("vpu", BIT(2), BIT(6), false),
1140 [RK3568_PD_RKVDEC
] = DOMAIN_RK3568("vdec", BIT(4), BIT(8), false),
1141 [RK3568_PD_RKVENC
] = DOMAIN_RK3568("venc", BIT(3), BIT(7), false),
1142 [RK3568_PD_PIPE
] = DOMAIN_RK3568("pipe", BIT(8), BIT(11), false),
1145 static const struct rockchip_domain_info rk3576_pm_domains
[] = {
1146 [RK3576_PD_NPU
] = DOMAIN_RK3576("npu", 0x0, BIT(0), BIT(0), 0, 0x0, 0, 0, 0, false),
1147 [RK3576_PD_NVM
] = DOMAIN_RK3576("nvm", 0x0, BIT(6), 0, BIT(6), 0x4, BIT(2), BIT(18), BIT(2), false),
1148 [RK3576_PD_SDGMAC
] = DOMAIN_RK3576("sdgmac", 0x0, BIT(7), 0, BIT(7), 0x4, BIT(1), BIT(17), 0x6, false),
1149 [RK3576_PD_AUDIO
] = DOMAIN_RK3576("audio", 0x0, BIT(8), 0, BIT(8), 0x4, BIT(0), BIT(16), BIT(0), false),
1150 [RK3576_PD_PHP
] = DOMAIN_RK3576("php", 0x0, BIT(9), 0, BIT(9), 0x0, BIT(15), BIT(15), BIT(15), false),
1151 [RK3576_PD_SUBPHP
] = DOMAIN_RK3576("subphp", 0x0, BIT(10), 0, BIT(10), 0x0, 0, 0, 0, false),
1152 [RK3576_PD_VOP
] = DOMAIN_RK3576("vop", 0x0, BIT(11), 0, BIT(11), 0x0, 0x6000, 0x6000, 0x6000, false),
1153 [RK3576_PD_VO1
] = DOMAIN_RK3576("vo1", 0x0, BIT(14), 0, BIT(14), 0x0, BIT(12), BIT(12), 0x7000, false),
1154 [RK3576_PD_VO0
] = DOMAIN_RK3576("vo0", 0x0, BIT(15), 0, BIT(15), 0x0, BIT(11), BIT(11), 0x6800, false),
1155 [RK3576_PD_USB
] = DOMAIN_RK3576("usb", 0x4, BIT(0), 0, BIT(16), 0x0, BIT(10), BIT(10), 0x6400, true),
1156 [RK3576_PD_VI
] = DOMAIN_RK3576("vi", 0x4, BIT(1), 0, BIT(17), 0x0, BIT(9), BIT(9), BIT(9), false),
1157 [RK3576_PD_VEPU0
] = DOMAIN_RK3576("vepu0", 0x4, BIT(2), 0, BIT(18), 0x0, BIT(7), BIT(7), 0x280, false),
1158 [RK3576_PD_VEPU1
] = DOMAIN_RK3576("vepu1", 0x4, BIT(3), 0, BIT(19), 0x0, BIT(8), BIT(8), BIT(8), false),
1159 [RK3576_PD_VDEC
] = DOMAIN_RK3576("vdec", 0x4, BIT(4), 0, BIT(20), 0x0, BIT(6), BIT(6), BIT(6), false),
1160 [RK3576_PD_VPU
] = DOMAIN_RK3576("vpu", 0x4, BIT(5), 0, BIT(21), 0x0, BIT(5), BIT(5), BIT(5), false),
1161 [RK3576_PD_NPUTOP
] = DOMAIN_RK3576("nputop", 0x4, BIT(6), 0, BIT(22), 0x0, 0x18, 0x18, 0x18, false),
1162 [RK3576_PD_NPU0
] = DOMAIN_RK3576("npu0", 0x4, BIT(7), 0, BIT(23), 0x0, BIT(1), BIT(1), 0x1a, false),
1163 [RK3576_PD_NPU1
] = DOMAIN_RK3576("npu1", 0x4, BIT(8), 0, BIT(24), 0x0, BIT(2), BIT(2), 0x1c, false),
1164 [RK3576_PD_GPU
] = DOMAIN_RK3576("gpu", 0x4, BIT(9), 0, BIT(25), 0x0, BIT(0), BIT(0), BIT(0), false),
1167 static const struct rockchip_domain_info rk3588_pm_domains
[] = {
1168 [RK3588_PD_GPU
] = DOMAIN_RK3588("gpu", 0x0, BIT(0), 0, 0x0, 0, BIT(1), 0x0, BIT(0), BIT(0), false),
1169 [RK3588_PD_NPU
] = DOMAIN_RK3588("npu", 0x0, BIT(1), BIT(1), 0x0, 0, 0, 0x0, 0, 0, false),
1170 [RK3588_PD_VCODEC
] = DOMAIN_RK3588("vcodec", 0x0, BIT(2), BIT(2), 0x0, 0, 0, 0x0, 0, 0, false),
1171 [RK3588_PD_NPUTOP
] = DOMAIN_RK3588("nputop", 0x0, BIT(3), 0, 0x0, BIT(11), BIT(2), 0x0, BIT(1), BIT(1), false),
1172 [RK3588_PD_NPU1
] = DOMAIN_RK3588("npu1", 0x0, BIT(4), 0, 0x0, BIT(12), BIT(3), 0x0, BIT(2), BIT(2), false),
1173 [RK3588_PD_NPU2
] = DOMAIN_RK3588("npu2", 0x0, BIT(5), 0, 0x0, BIT(13), BIT(4), 0x0, BIT(3), BIT(3), false),
1174 [RK3588_PD_VENC0
] = DOMAIN_RK3588("venc0", 0x0, BIT(6), 0, 0x0, BIT(14), BIT(5), 0x0, BIT(4), BIT(4), false),
1175 [RK3588_PD_VENC1
] = DOMAIN_RK3588("venc1", 0x0, BIT(7), 0, 0x0, BIT(15), BIT(6), 0x0, BIT(5), BIT(5), false),
1176 [RK3588_PD_RKVDEC0
] = DOMAIN_RK3588("rkvdec0", 0x0, BIT(8), 0, 0x0, BIT(16), BIT(7), 0x0, BIT(6), BIT(6), false),
1177 [RK3588_PD_RKVDEC1
] = DOMAIN_RK3588("rkvdec1", 0x0, BIT(9), 0, 0x0, BIT(17), BIT(8), 0x0, BIT(7), BIT(7), false),
1178 [RK3588_PD_VDPU
] = DOMAIN_RK3588("vdpu", 0x0, BIT(10), 0, 0x0, BIT(18), BIT(9), 0x0, BIT(8), BIT(8), false),
1179 [RK3588_PD_RGA30
] = DOMAIN_RK3588("rga30", 0x0, BIT(11), 0, 0x0, BIT(19), BIT(10), 0x0, 0, 0, false),
1180 [RK3588_PD_AV1
] = DOMAIN_RK3588("av1", 0x0, BIT(12), 0, 0x0, BIT(20), BIT(11), 0x0, BIT(9), BIT(9), false),
1181 [RK3588_PD_VI
] = DOMAIN_RK3588("vi", 0x0, BIT(13), 0, 0x0, BIT(21), BIT(12), 0x0, BIT(10), BIT(10), false),
1182 [RK3588_PD_FEC
] = DOMAIN_RK3588("fec", 0x0, BIT(14), 0, 0x0, BIT(22), BIT(13), 0x0, 0, 0, false),
1183 [RK3588_PD_ISP1
] = DOMAIN_RK3588("isp1", 0x0, BIT(15), 0, 0x0, BIT(23), BIT(14), 0x0, BIT(11), BIT(11), false),
1184 [RK3588_PD_RGA31
] = DOMAIN_RK3588("rga31", 0x4, BIT(0), 0, 0x0, BIT(24), BIT(15), 0x0, BIT(12), BIT(12), false),
1185 [RK3588_PD_VOP
] = DOMAIN_RK3588("vop", 0x4, BIT(1), 0, 0x0, BIT(25), BIT(16), 0x0, BIT(13) | BIT(14), BIT(13) | BIT(14), false),
1186 [RK3588_PD_VO0
] = DOMAIN_RK3588("vo0", 0x4, BIT(2), 0, 0x0, BIT(26), BIT(17), 0x0, BIT(15), BIT(15), false),
1187 [RK3588_PD_VO1
] = DOMAIN_RK3588("vo1", 0x4, BIT(3), 0, 0x0, BIT(27), BIT(18), 0x4, BIT(0), BIT(16), false),
1188 [RK3588_PD_AUDIO
] = DOMAIN_RK3588("audio", 0x4, BIT(4), 0, 0x0, BIT(28), BIT(19), 0x4, BIT(1), BIT(17), false),
1189 [RK3588_PD_PHP
] = DOMAIN_RK3588("php", 0x4, BIT(5), 0, 0x0, BIT(29), BIT(20), 0x4, BIT(5), BIT(21), false),
1190 [RK3588_PD_GMAC
] = DOMAIN_RK3588("gmac", 0x4, BIT(6), 0, 0x0, BIT(30), BIT(21), 0x0, 0, 0, false),
1191 [RK3588_PD_PCIE
] = DOMAIN_RK3588("pcie", 0x4, BIT(7), 0, 0x0, BIT(31), BIT(22), 0x0, 0, 0, true),
1192 [RK3588_PD_NVM
] = DOMAIN_RK3588("nvm", 0x4, BIT(8), BIT(24), 0x4, 0, 0, 0x4, BIT(2), BIT(18), false),
1193 [RK3588_PD_NVM0
] = DOMAIN_RK3588("nvm0", 0x4, BIT(9), 0, 0x4, BIT(1), BIT(23), 0x0, 0, 0, false),
1194 [RK3588_PD_SDIO
] = DOMAIN_RK3588("sdio", 0x4, BIT(10), 0, 0x4, BIT(2), BIT(24), 0x4, BIT(3), BIT(19), false),
1195 [RK3588_PD_USB
] = DOMAIN_RK3588("usb", 0x4, BIT(11), 0, 0x4, BIT(3), BIT(25), 0x4, BIT(4), BIT(20), true),
1196 [RK3588_PD_SDMMC
] = DOMAIN_RK3588("sdmmc", 0x4, BIT(13), 0, 0x4, BIT(5), BIT(26), 0x0, 0, 0, false),
1199 static const struct rockchip_pmu_info px30_pmu
= {
1201 .status_offset
= 0x20,
1203 .idle_offset
= 0x6c,
1206 .num_domains
= ARRAY_SIZE(px30_pm_domains
),
1207 .domain_info
= px30_pm_domains
,
1210 static const struct rockchip_pmu_info rk3036_pmu
= {
1211 .req_offset
= 0x148,
1212 .idle_offset
= 0x14c,
1213 .ack_offset
= 0x14c,
1215 .num_domains
= ARRAY_SIZE(rk3036_pm_domains
),
1216 .domain_info
= rk3036_pm_domains
,
1219 static const struct rockchip_pmu_info rk3066_pmu
= {
1221 .status_offset
= 0x0c,
1222 .req_offset
= 0x38, /* PMU_MISC_CON1 */
1223 .idle_offset
= 0x0c,
1226 .num_domains
= ARRAY_SIZE(rk3066_pm_domains
),
1227 .domain_info
= rk3066_pm_domains
,
1230 static const struct rockchip_pmu_info rk3128_pmu
= {
1232 .status_offset
= 0x08,
1234 .idle_offset
= 0x10,
1237 .num_domains
= ARRAY_SIZE(rk3128_pm_domains
),
1238 .domain_info
= rk3128_pm_domains
,
1241 static const struct rockchip_pmu_info rk3188_pmu
= {
1243 .status_offset
= 0x0c,
1244 .req_offset
= 0x38, /* PMU_MISC_CON1 */
1245 .idle_offset
= 0x0c,
1248 .num_domains
= ARRAY_SIZE(rk3188_pm_domains
),
1249 .domain_info
= rk3188_pm_domains
,
1252 static const struct rockchip_pmu_info rk3228_pmu
= {
1253 .req_offset
= 0x40c,
1254 .idle_offset
= 0x488,
1255 .ack_offset
= 0x488,
1257 .num_domains
= ARRAY_SIZE(rk3228_pm_domains
),
1258 .domain_info
= rk3228_pm_domains
,
1261 static const struct rockchip_pmu_info rk3288_pmu
= {
1263 .status_offset
= 0x0c,
1265 .idle_offset
= 0x14,
1268 .core_pwrcnt_offset
= 0x34,
1269 .gpu_pwrcnt_offset
= 0x3c,
1271 .core_power_transition_time
= 24, /* 1us */
1272 .gpu_power_transition_time
= 24, /* 1us */
1274 .num_domains
= ARRAY_SIZE(rk3288_pm_domains
),
1275 .domain_info
= rk3288_pm_domains
,
1278 static const struct rockchip_pmu_info rk3328_pmu
= {
1279 .req_offset
= 0x414,
1280 .idle_offset
= 0x484,
1281 .ack_offset
= 0x484,
1283 .num_domains
= ARRAY_SIZE(rk3328_pm_domains
),
1284 .domain_info
= rk3328_pm_domains
,
1287 static const struct rockchip_pmu_info rk3366_pmu
= {
1289 .status_offset
= 0x10,
1291 .idle_offset
= 0x40,
1294 .core_pwrcnt_offset
= 0x48,
1295 .gpu_pwrcnt_offset
= 0x50,
1297 .core_power_transition_time
= 24,
1298 .gpu_power_transition_time
= 24,
1300 .num_domains
= ARRAY_SIZE(rk3366_pm_domains
),
1301 .domain_info
= rk3366_pm_domains
,
1304 static const struct rockchip_pmu_info rk3368_pmu
= {
1306 .status_offset
= 0x10,
1308 .idle_offset
= 0x40,
1311 .core_pwrcnt_offset
= 0x48,
1312 .gpu_pwrcnt_offset
= 0x50,
1314 .core_power_transition_time
= 24,
1315 .gpu_power_transition_time
= 24,
1317 .num_domains
= ARRAY_SIZE(rk3368_pm_domains
),
1318 .domain_info
= rk3368_pm_domains
,
1321 static const struct rockchip_pmu_info rk3399_pmu
= {
1323 .status_offset
= 0x18,
1325 .idle_offset
= 0x64,
1328 /* ARM Trusted Firmware manages power transition times */
1330 .num_domains
= ARRAY_SIZE(rk3399_pm_domains
),
1331 .domain_info
= rk3399_pm_domains
,
1334 static const struct rockchip_pmu_info rk3568_pmu
= {
1336 .status_offset
= 0x98,
1338 .idle_offset
= 0x68,
1341 .num_domains
= ARRAY_SIZE(rk3568_pm_domains
),
1342 .domain_info
= rk3568_pm_domains
,
1345 static const struct rockchip_pmu_info rk3576_pmu
= {
1346 .pwr_offset
= 0x210,
1347 .status_offset
= 0x230,
1348 .chain_status_offset
= 0x248,
1349 .mem_status_offset
= 0x250,
1350 .mem_pwr_offset
= 0x300,
1351 .req_offset
= 0x110,
1352 .idle_offset
= 0x128,
1353 .ack_offset
= 0x120,
1354 .repair_status_offset
= 0x570,
1355 .clk_ungate_offset
= 0x140,
1357 .num_domains
= ARRAY_SIZE(rk3576_pm_domains
),
1358 .domain_info
= rk3576_pm_domains
,
1361 static const struct rockchip_pmu_info rk3588_pmu
= {
1362 .pwr_offset
= 0x14c,
1363 .status_offset
= 0x180,
1364 .req_offset
= 0x10c,
1365 .idle_offset
= 0x120,
1366 .ack_offset
= 0x118,
1367 .mem_pwr_offset
= 0x1a0,
1368 .chain_status_offset
= 0x1f0,
1369 .mem_status_offset
= 0x1f8,
1370 .repair_status_offset
= 0x290,
1372 .num_domains
= ARRAY_SIZE(rk3588_pm_domains
),
1373 .domain_info
= rk3588_pm_domains
,
1376 static const struct rockchip_pmu_info rv1126_pmu
= {
1377 .pwr_offset
= 0x110,
1378 .status_offset
= 0x108,
1380 .idle_offset
= 0xd8,
1383 .num_domains
= ARRAY_SIZE(rv1126_pm_domains
),
1384 .domain_info
= rv1126_pm_domains
,
1387 static const struct of_device_id rockchip_pm_domain_dt_match
[] = {
1389 .compatible
= "rockchip,px30-power-controller",
1390 .data
= (void *)&px30_pmu
,
1393 .compatible
= "rockchip,rk3036-power-controller",
1394 .data
= (void *)&rk3036_pmu
,
1397 .compatible
= "rockchip,rk3066-power-controller",
1398 .data
= (void *)&rk3066_pmu
,
1401 .compatible
= "rockchip,rk3128-power-controller",
1402 .data
= (void *)&rk3128_pmu
,
1405 .compatible
= "rockchip,rk3188-power-controller",
1406 .data
= (void *)&rk3188_pmu
,
1409 .compatible
= "rockchip,rk3228-power-controller",
1410 .data
= (void *)&rk3228_pmu
,
1413 .compatible
= "rockchip,rk3288-power-controller",
1414 .data
= (void *)&rk3288_pmu
,
1417 .compatible
= "rockchip,rk3328-power-controller",
1418 .data
= (void *)&rk3328_pmu
,
1421 .compatible
= "rockchip,rk3366-power-controller",
1422 .data
= (void *)&rk3366_pmu
,
1425 .compatible
= "rockchip,rk3368-power-controller",
1426 .data
= (void *)&rk3368_pmu
,
1429 .compatible
= "rockchip,rk3399-power-controller",
1430 .data
= (void *)&rk3399_pmu
,
1433 .compatible
= "rockchip,rk3568-power-controller",
1434 .data
= (void *)&rk3568_pmu
,
1437 .compatible
= "rockchip,rk3576-power-controller",
1438 .data
= (void *)&rk3576_pmu
,
1441 .compatible
= "rockchip,rk3588-power-controller",
1442 .data
= (void *)&rk3588_pmu
,
1445 .compatible
= "rockchip,rv1126-power-controller",
1446 .data
= (void *)&rv1126_pmu
,
1451 static struct platform_driver rockchip_pm_domain_driver
= {
1452 .probe
= rockchip_pm_domain_probe
,
1454 .name
= "rockchip-pm-domain",
1455 .of_match_table
= rockchip_pm_domain_dt_match
,
1457 * We can't forcibly eject devices from the power
1458 * domain, so we can't really remove power domains
1459 * once they were added.
1461 .suppress_bind_attrs
= true,
1465 static int __init
rockchip_pm_domain_drv_register(void)
1467 return platform_driver_register(&rockchip_pm_domain_driver
);
1469 postcore_initcall(rockchip_pm_domain_drv_register
);