xref: /linux/drivers/pmdomain/rockchip/pm-domains.c (revision e2ad626f8f409899baf1bf192d0533a851128b19)
1*e2ad626fSUlf Hansson // SPDX-License-Identifier: GPL-2.0-only
2*e2ad626fSUlf Hansson /*
3*e2ad626fSUlf Hansson  * Rockchip Generic power domain support.
4*e2ad626fSUlf Hansson  *
5*e2ad626fSUlf Hansson  * Copyright (c) 2015 ROCKCHIP, Co. Ltd.
6*e2ad626fSUlf Hansson  */
7*e2ad626fSUlf Hansson 
8*e2ad626fSUlf Hansson #include <linux/io.h>
9*e2ad626fSUlf Hansson #include <linux/iopoll.h>
10*e2ad626fSUlf Hansson #include <linux/err.h>
11*e2ad626fSUlf Hansson #include <linux/mutex.h>
12*e2ad626fSUlf Hansson #include <linux/pm_clock.h>
13*e2ad626fSUlf Hansson #include <linux/pm_domain.h>
14*e2ad626fSUlf Hansson #include <linux/of_address.h>
15*e2ad626fSUlf Hansson #include <linux/of_clk.h>
16*e2ad626fSUlf Hansson #include <linux/of_platform.h>
17*e2ad626fSUlf Hansson #include <linux/clk.h>
18*e2ad626fSUlf Hansson #include <linux/regmap.h>
19*e2ad626fSUlf Hansson #include <linux/mfd/syscon.h>
20*e2ad626fSUlf Hansson #include <soc/rockchip/pm_domains.h>
21*e2ad626fSUlf Hansson #include <dt-bindings/power/px30-power.h>
22*e2ad626fSUlf Hansson #include <dt-bindings/power/rockchip,rv1126-power.h>
23*e2ad626fSUlf Hansson #include <dt-bindings/power/rk3036-power.h>
24*e2ad626fSUlf Hansson #include <dt-bindings/power/rk3066-power.h>
25*e2ad626fSUlf Hansson #include <dt-bindings/power/rk3128-power.h>
26*e2ad626fSUlf Hansson #include <dt-bindings/power/rk3188-power.h>
27*e2ad626fSUlf Hansson #include <dt-bindings/power/rk3228-power.h>
28*e2ad626fSUlf Hansson #include <dt-bindings/power/rk3288-power.h>
29*e2ad626fSUlf Hansson #include <dt-bindings/power/rk3328-power.h>
30*e2ad626fSUlf Hansson #include <dt-bindings/power/rk3366-power.h>
31*e2ad626fSUlf Hansson #include <dt-bindings/power/rk3368-power.h>
32*e2ad626fSUlf Hansson #include <dt-bindings/power/rk3399-power.h>
33*e2ad626fSUlf Hansson #include <dt-bindings/power/rk3568-power.h>
34*e2ad626fSUlf Hansson #include <dt-bindings/power/rk3588-power.h>
35*e2ad626fSUlf Hansson 
36*e2ad626fSUlf Hansson struct rockchip_domain_info {
37*e2ad626fSUlf Hansson 	const char *name;
38*e2ad626fSUlf Hansson 	int pwr_mask;
39*e2ad626fSUlf Hansson 	int status_mask;
40*e2ad626fSUlf Hansson 	int req_mask;
41*e2ad626fSUlf Hansson 	int idle_mask;
42*e2ad626fSUlf Hansson 	int ack_mask;
43*e2ad626fSUlf Hansson 	bool active_wakeup;
44*e2ad626fSUlf Hansson 	int pwr_w_mask;
45*e2ad626fSUlf Hansson 	int req_w_mask;
46*e2ad626fSUlf Hansson 	int mem_status_mask;
47*e2ad626fSUlf Hansson 	int repair_status_mask;
48*e2ad626fSUlf Hansson 	u32 pwr_offset;
49*e2ad626fSUlf Hansson 	u32 mem_offset;
50*e2ad626fSUlf Hansson 	u32 req_offset;
51*e2ad626fSUlf Hansson };
52*e2ad626fSUlf Hansson 
53*e2ad626fSUlf Hansson struct rockchip_pmu_info {
54*e2ad626fSUlf Hansson 	u32 pwr_offset;
55*e2ad626fSUlf Hansson 	u32 status_offset;
56*e2ad626fSUlf Hansson 	u32 req_offset;
57*e2ad626fSUlf Hansson 	u32 idle_offset;
58*e2ad626fSUlf Hansson 	u32 ack_offset;
59*e2ad626fSUlf Hansson 	u32 mem_pwr_offset;
60*e2ad626fSUlf Hansson 	u32 chain_status_offset;
61*e2ad626fSUlf Hansson 	u32 mem_status_offset;
62*e2ad626fSUlf Hansson 	u32 repair_status_offset;
63*e2ad626fSUlf Hansson 
64*e2ad626fSUlf Hansson 	u32 core_pwrcnt_offset;
65*e2ad626fSUlf Hansson 	u32 gpu_pwrcnt_offset;
66*e2ad626fSUlf Hansson 
67*e2ad626fSUlf Hansson 	unsigned int core_power_transition_time;
68*e2ad626fSUlf Hansson 	unsigned int gpu_power_transition_time;
69*e2ad626fSUlf Hansson 
70*e2ad626fSUlf Hansson 	int num_domains;
71*e2ad626fSUlf Hansson 	const struct rockchip_domain_info *domain_info;
72*e2ad626fSUlf Hansson };
73*e2ad626fSUlf Hansson 
74*e2ad626fSUlf Hansson #define MAX_QOS_REGS_NUM	5
75*e2ad626fSUlf Hansson #define QOS_PRIORITY		0x08
76*e2ad626fSUlf Hansson #define QOS_MODE		0x0c
77*e2ad626fSUlf Hansson #define QOS_BANDWIDTH		0x10
78*e2ad626fSUlf Hansson #define QOS_SATURATION		0x14
79*e2ad626fSUlf Hansson #define QOS_EXTCONTROL		0x18
80*e2ad626fSUlf Hansson 
81*e2ad626fSUlf Hansson struct rockchip_pm_domain {
82*e2ad626fSUlf Hansson 	struct generic_pm_domain genpd;
83*e2ad626fSUlf Hansson 	const struct rockchip_domain_info *info;
84*e2ad626fSUlf Hansson 	struct rockchip_pmu *pmu;
85*e2ad626fSUlf Hansson 	int num_qos;
86*e2ad626fSUlf Hansson 	struct regmap **qos_regmap;
87*e2ad626fSUlf Hansson 	u32 *qos_save_regs[MAX_QOS_REGS_NUM];
88*e2ad626fSUlf Hansson 	int num_clks;
89*e2ad626fSUlf Hansson 	struct clk_bulk_data *clks;
90*e2ad626fSUlf Hansson };
91*e2ad626fSUlf Hansson 
92*e2ad626fSUlf Hansson struct rockchip_pmu {
93*e2ad626fSUlf Hansson 	struct device *dev;
94*e2ad626fSUlf Hansson 	struct regmap *regmap;
95*e2ad626fSUlf Hansson 	const struct rockchip_pmu_info *info;
96*e2ad626fSUlf Hansson 	struct mutex mutex; /* mutex lock for pmu */
97*e2ad626fSUlf Hansson 	struct genpd_onecell_data genpd_data;
98*e2ad626fSUlf Hansson 	struct generic_pm_domain *domains[];
99*e2ad626fSUlf Hansson };
100*e2ad626fSUlf Hansson 
101*e2ad626fSUlf Hansson #define to_rockchip_pd(gpd) container_of(gpd, struct rockchip_pm_domain, genpd)
102*e2ad626fSUlf Hansson 
103*e2ad626fSUlf Hansson #define DOMAIN(_name, pwr, status, req, idle, ack, wakeup)	\
104*e2ad626fSUlf Hansson {							\
105*e2ad626fSUlf Hansson 	.name = _name,				\
106*e2ad626fSUlf Hansson 	.pwr_mask = (pwr),				\
107*e2ad626fSUlf Hansson 	.status_mask = (status),			\
108*e2ad626fSUlf Hansson 	.req_mask = (req),				\
109*e2ad626fSUlf Hansson 	.idle_mask = (idle),				\
110*e2ad626fSUlf Hansson 	.ack_mask = (ack),				\
111*e2ad626fSUlf Hansson 	.active_wakeup = (wakeup),			\
112*e2ad626fSUlf Hansson }
113*e2ad626fSUlf Hansson 
114*e2ad626fSUlf Hansson #define DOMAIN_M(_name, pwr, status, req, idle, ack, wakeup)	\
115*e2ad626fSUlf Hansson {							\
116*e2ad626fSUlf Hansson 	.name = _name,				\
117*e2ad626fSUlf Hansson 	.pwr_w_mask = (pwr) << 16,			\
118*e2ad626fSUlf Hansson 	.pwr_mask = (pwr),				\
119*e2ad626fSUlf Hansson 	.status_mask = (status),			\
120*e2ad626fSUlf Hansson 	.req_w_mask = (req) << 16,			\
121*e2ad626fSUlf Hansson 	.req_mask = (req),				\
122*e2ad626fSUlf Hansson 	.idle_mask = (idle),				\
123*e2ad626fSUlf Hansson 	.ack_mask = (ack),				\
124*e2ad626fSUlf Hansson 	.active_wakeup = wakeup,			\
125*e2ad626fSUlf Hansson }
126*e2ad626fSUlf Hansson 
127*e2ad626fSUlf Hansson #define DOMAIN_M_O_R(_name, p_offset, pwr, status, m_offset, m_status, r_status, r_offset, req, idle, ack, wakeup)	\
128*e2ad626fSUlf Hansson {							\
129*e2ad626fSUlf Hansson 	.name = _name,					\
130*e2ad626fSUlf Hansson 	.pwr_offset = p_offset,				\
131*e2ad626fSUlf Hansson 	.pwr_w_mask = (pwr) << 16,			\
132*e2ad626fSUlf Hansson 	.pwr_mask = (pwr),				\
133*e2ad626fSUlf Hansson 	.status_mask = (status),			\
134*e2ad626fSUlf Hansson 	.mem_offset = m_offset,				\
135*e2ad626fSUlf Hansson 	.mem_status_mask = (m_status),			\
136*e2ad626fSUlf Hansson 	.repair_status_mask = (r_status),		\
137*e2ad626fSUlf Hansson 	.req_offset = r_offset,				\
138*e2ad626fSUlf Hansson 	.req_w_mask = (req) << 16,			\
139*e2ad626fSUlf Hansson 	.req_mask = (req),				\
140*e2ad626fSUlf Hansson 	.idle_mask = (idle),				\
141*e2ad626fSUlf Hansson 	.ack_mask = (ack),				\
142*e2ad626fSUlf Hansson 	.active_wakeup = wakeup,			\
143*e2ad626fSUlf Hansson }
144*e2ad626fSUlf Hansson 
145*e2ad626fSUlf Hansson #define DOMAIN_RK3036(_name, req, ack, idle, wakeup)		\
146*e2ad626fSUlf Hansson {							\
147*e2ad626fSUlf Hansson 	.name = _name,				\
148*e2ad626fSUlf Hansson 	.req_mask = (req),				\
149*e2ad626fSUlf Hansson 	.req_w_mask = (req) << 16,			\
150*e2ad626fSUlf Hansson 	.ack_mask = (ack),				\
151*e2ad626fSUlf Hansson 	.idle_mask = (idle),				\
152*e2ad626fSUlf Hansson 	.active_wakeup = wakeup,			\
153*e2ad626fSUlf Hansson }
154*e2ad626fSUlf Hansson 
155*e2ad626fSUlf Hansson #define DOMAIN_PX30(name, pwr, status, req, wakeup)		\
156*e2ad626fSUlf Hansson 	DOMAIN_M(name, pwr, status, req, (req) << 16, req, wakeup)
157*e2ad626fSUlf Hansson 
158*e2ad626fSUlf Hansson #define DOMAIN_RV1126(name, pwr, req, idle, wakeup)		\
159*e2ad626fSUlf Hansson 	DOMAIN_M(name, pwr, pwr, req, idle, idle, wakeup)
160*e2ad626fSUlf Hansson 
161*e2ad626fSUlf Hansson #define DOMAIN_RK3288(name, pwr, status, req, wakeup)		\
162*e2ad626fSUlf Hansson 	DOMAIN(name, pwr, status, req, req, (req) << 16, wakeup)
163*e2ad626fSUlf Hansson 
164*e2ad626fSUlf Hansson #define DOMAIN_RK3328(name, pwr, status, req, wakeup)		\
165*e2ad626fSUlf Hansson 	DOMAIN_M(name, pwr, pwr, req, (req) << 10, req, wakeup)
166*e2ad626fSUlf Hansson 
167*e2ad626fSUlf Hansson #define DOMAIN_RK3368(name, pwr, status, req, wakeup)		\
168*e2ad626fSUlf Hansson 	DOMAIN(name, pwr, status, req, (req) << 16, req, wakeup)
169*e2ad626fSUlf Hansson 
170*e2ad626fSUlf Hansson #define DOMAIN_RK3399(name, pwr, status, req, wakeup)		\
171*e2ad626fSUlf Hansson 	DOMAIN(name, pwr, status, req, req, req, wakeup)
172*e2ad626fSUlf Hansson 
173*e2ad626fSUlf Hansson #define DOMAIN_RK3568(name, pwr, req, wakeup)		\
174*e2ad626fSUlf Hansson 	DOMAIN_M(name, pwr, pwr, req, req, req, wakeup)
175*e2ad626fSUlf Hansson 
176*e2ad626fSUlf Hansson /*
177*e2ad626fSUlf Hansson  * Dynamic Memory Controller may need to coordinate with us -- see
178*e2ad626fSUlf Hansson  * rockchip_pmu_block().
179*e2ad626fSUlf Hansson  *
180*e2ad626fSUlf Hansson  * dmc_pmu_mutex protects registration-time races, so DMC driver doesn't try to
181*e2ad626fSUlf Hansson  * block() while we're initializing the PMU.
182*e2ad626fSUlf Hansson  */
183*e2ad626fSUlf Hansson static DEFINE_MUTEX(dmc_pmu_mutex);
184*e2ad626fSUlf Hansson static struct rockchip_pmu *dmc_pmu;
185*e2ad626fSUlf Hansson 
186*e2ad626fSUlf Hansson /*
187*e2ad626fSUlf Hansson  * Block PMU transitions and make sure they don't interfere with ARM Trusted
188*e2ad626fSUlf Hansson  * Firmware operations. There are two conflicts, noted in the comments below.
189*e2ad626fSUlf Hansson  *
190*e2ad626fSUlf Hansson  * Caller must unblock PMU transitions via rockchip_pmu_unblock().
191*e2ad626fSUlf Hansson  */
192*e2ad626fSUlf Hansson int rockchip_pmu_block(void)
193*e2ad626fSUlf Hansson {
194*e2ad626fSUlf Hansson 	struct rockchip_pmu *pmu;
195*e2ad626fSUlf Hansson 	struct generic_pm_domain *genpd;
196*e2ad626fSUlf Hansson 	struct rockchip_pm_domain *pd;
197*e2ad626fSUlf Hansson 	int i, ret;
198*e2ad626fSUlf Hansson 
199*e2ad626fSUlf Hansson 	mutex_lock(&dmc_pmu_mutex);
200*e2ad626fSUlf Hansson 
201*e2ad626fSUlf Hansson 	/* No PMU (yet)? Then we just block rockchip_pmu_probe(). */
202*e2ad626fSUlf Hansson 	if (!dmc_pmu)
203*e2ad626fSUlf Hansson 		return 0;
204*e2ad626fSUlf Hansson 	pmu = dmc_pmu;
205*e2ad626fSUlf Hansson 
206*e2ad626fSUlf Hansson 	/*
207*e2ad626fSUlf Hansson 	 * mutex blocks all idle transitions: we can't touch the
208*e2ad626fSUlf Hansson 	 * PMU_BUS_IDLE_REQ (our ".idle_offset") register while ARM Trusted
209*e2ad626fSUlf Hansson 	 * Firmware might be using it.
210*e2ad626fSUlf Hansson 	 */
211*e2ad626fSUlf Hansson 	mutex_lock(&pmu->mutex);
212*e2ad626fSUlf Hansson 
213*e2ad626fSUlf Hansson 	/*
214*e2ad626fSUlf Hansson 	 * Power domain clocks: Per Rockchip, we *must* keep certain clocks
215*e2ad626fSUlf Hansson 	 * enabled for the duration of power-domain transitions. Most
216*e2ad626fSUlf Hansson 	 * transitions are handled by this driver, but some cases (in
217*e2ad626fSUlf Hansson 	 * particular, DRAM DVFS / memory-controller idle) must be handled by
218*e2ad626fSUlf Hansson 	 * firmware. Firmware can handle most clock management via a special
219*e2ad626fSUlf Hansson 	 * "ungate" register (PMU_CRU_GATEDIS_CON0), but unfortunately, this
220*e2ad626fSUlf Hansson 	 * doesn't handle PLLs. We can assist this transition by doing the
221*e2ad626fSUlf Hansson 	 * clock management on behalf of firmware.
222*e2ad626fSUlf Hansson 	 */
223*e2ad626fSUlf Hansson 	for (i = 0; i < pmu->genpd_data.num_domains; i++) {
224*e2ad626fSUlf Hansson 		genpd = pmu->genpd_data.domains[i];
225*e2ad626fSUlf Hansson 		if (genpd) {
226*e2ad626fSUlf Hansson 			pd = to_rockchip_pd(genpd);
227*e2ad626fSUlf Hansson 			ret = clk_bulk_enable(pd->num_clks, pd->clks);
228*e2ad626fSUlf Hansson 			if (ret < 0) {
229*e2ad626fSUlf Hansson 				dev_err(pmu->dev,
230*e2ad626fSUlf Hansson 					"failed to enable clks for domain '%s': %d\n",
231*e2ad626fSUlf Hansson 					genpd->name, ret);
232*e2ad626fSUlf Hansson 				goto err;
233*e2ad626fSUlf Hansson 			}
234*e2ad626fSUlf Hansson 		}
235*e2ad626fSUlf Hansson 	}
236*e2ad626fSUlf Hansson 
237*e2ad626fSUlf Hansson 	return 0;
238*e2ad626fSUlf Hansson 
239*e2ad626fSUlf Hansson err:
240*e2ad626fSUlf Hansson 	for (i = i - 1; i >= 0; i--) {
241*e2ad626fSUlf Hansson 		genpd = pmu->genpd_data.domains[i];
242*e2ad626fSUlf Hansson 		if (genpd) {
243*e2ad626fSUlf Hansson 			pd = to_rockchip_pd(genpd);
244*e2ad626fSUlf Hansson 			clk_bulk_disable(pd->num_clks, pd->clks);
245*e2ad626fSUlf Hansson 		}
246*e2ad626fSUlf Hansson 	}
247*e2ad626fSUlf Hansson 	mutex_unlock(&pmu->mutex);
248*e2ad626fSUlf Hansson 	mutex_unlock(&dmc_pmu_mutex);
249*e2ad626fSUlf Hansson 
250*e2ad626fSUlf Hansson 	return ret;
251*e2ad626fSUlf Hansson }
252*e2ad626fSUlf Hansson EXPORT_SYMBOL_GPL(rockchip_pmu_block);
253*e2ad626fSUlf Hansson 
254*e2ad626fSUlf Hansson /* Unblock PMU transitions. */
255*e2ad626fSUlf Hansson void rockchip_pmu_unblock(void)
256*e2ad626fSUlf Hansson {
257*e2ad626fSUlf Hansson 	struct rockchip_pmu *pmu;
258*e2ad626fSUlf Hansson 	struct generic_pm_domain *genpd;
259*e2ad626fSUlf Hansson 	struct rockchip_pm_domain *pd;
260*e2ad626fSUlf Hansson 	int i;
261*e2ad626fSUlf Hansson 
262*e2ad626fSUlf Hansson 	if (dmc_pmu) {
263*e2ad626fSUlf Hansson 		pmu = dmc_pmu;
264*e2ad626fSUlf Hansson 		for (i = 0; i < pmu->genpd_data.num_domains; i++) {
265*e2ad626fSUlf Hansson 			genpd = pmu->genpd_data.domains[i];
266*e2ad626fSUlf Hansson 			if (genpd) {
267*e2ad626fSUlf Hansson 				pd = to_rockchip_pd(genpd);
268*e2ad626fSUlf Hansson 				clk_bulk_disable(pd->num_clks, pd->clks);
269*e2ad626fSUlf Hansson 			}
270*e2ad626fSUlf Hansson 		}
271*e2ad626fSUlf Hansson 
272*e2ad626fSUlf Hansson 		mutex_unlock(&pmu->mutex);
273*e2ad626fSUlf Hansson 	}
274*e2ad626fSUlf Hansson 
275*e2ad626fSUlf Hansson 	mutex_unlock(&dmc_pmu_mutex);
276*e2ad626fSUlf Hansson }
277*e2ad626fSUlf Hansson EXPORT_SYMBOL_GPL(rockchip_pmu_unblock);
278*e2ad626fSUlf Hansson 
279*e2ad626fSUlf Hansson #define DOMAIN_RK3588(name, p_offset, pwr, status, m_offset, m_status, r_status, r_offset, req, idle, wakeup)	\
280*e2ad626fSUlf Hansson 	DOMAIN_M_O_R(name, p_offset, pwr, status, m_offset, m_status, r_status, r_offset, req, idle, idle, wakeup)
281*e2ad626fSUlf Hansson 
282*e2ad626fSUlf Hansson static bool rockchip_pmu_domain_is_idle(struct rockchip_pm_domain *pd)
283*e2ad626fSUlf Hansson {
284*e2ad626fSUlf Hansson 	struct rockchip_pmu *pmu = pd->pmu;
285*e2ad626fSUlf Hansson 	const struct rockchip_domain_info *pd_info = pd->info;
286*e2ad626fSUlf Hansson 	unsigned int val;
287*e2ad626fSUlf Hansson 
288*e2ad626fSUlf Hansson 	regmap_read(pmu->regmap, pmu->info->idle_offset, &val);
289*e2ad626fSUlf Hansson 	return (val & pd_info->idle_mask) == pd_info->idle_mask;
290*e2ad626fSUlf Hansson }
291*e2ad626fSUlf Hansson 
292*e2ad626fSUlf Hansson static unsigned int rockchip_pmu_read_ack(struct rockchip_pmu *pmu)
293*e2ad626fSUlf Hansson {
294*e2ad626fSUlf Hansson 	unsigned int val;
295*e2ad626fSUlf Hansson 
296*e2ad626fSUlf Hansson 	regmap_read(pmu->regmap, pmu->info->ack_offset, &val);
297*e2ad626fSUlf Hansson 	return val;
298*e2ad626fSUlf Hansson }
299*e2ad626fSUlf Hansson 
300*e2ad626fSUlf Hansson static int rockchip_pmu_set_idle_request(struct rockchip_pm_domain *pd,
301*e2ad626fSUlf Hansson 					 bool idle)
302*e2ad626fSUlf Hansson {
303*e2ad626fSUlf Hansson 	const struct rockchip_domain_info *pd_info = pd->info;
304*e2ad626fSUlf Hansson 	struct generic_pm_domain *genpd = &pd->genpd;
305*e2ad626fSUlf Hansson 	struct rockchip_pmu *pmu = pd->pmu;
306*e2ad626fSUlf Hansson 	u32 pd_req_offset = pd_info->req_offset;
307*e2ad626fSUlf Hansson 	unsigned int target_ack;
308*e2ad626fSUlf Hansson 	unsigned int val;
309*e2ad626fSUlf Hansson 	bool is_idle;
310*e2ad626fSUlf Hansson 	int ret;
311*e2ad626fSUlf Hansson 
312*e2ad626fSUlf Hansson 	if (pd_info->req_mask == 0)
313*e2ad626fSUlf Hansson 		return 0;
314*e2ad626fSUlf Hansson 	else if (pd_info->req_w_mask)
315*e2ad626fSUlf Hansson 		regmap_write(pmu->regmap, pmu->info->req_offset + pd_req_offset,
316*e2ad626fSUlf Hansson 			     idle ? (pd_info->req_mask | pd_info->req_w_mask) :
317*e2ad626fSUlf Hansson 			     pd_info->req_w_mask);
318*e2ad626fSUlf Hansson 	else
319*e2ad626fSUlf Hansson 		regmap_update_bits(pmu->regmap, pmu->info->req_offset + pd_req_offset,
320*e2ad626fSUlf Hansson 				   pd_info->req_mask, idle ? -1U : 0);
321*e2ad626fSUlf Hansson 
322*e2ad626fSUlf Hansson 	wmb();
323*e2ad626fSUlf Hansson 
324*e2ad626fSUlf Hansson 	/* Wait util idle_ack = 1 */
325*e2ad626fSUlf Hansson 	target_ack = idle ? pd_info->ack_mask : 0;
326*e2ad626fSUlf Hansson 	ret = readx_poll_timeout_atomic(rockchip_pmu_read_ack, pmu, val,
327*e2ad626fSUlf Hansson 					(val & pd_info->ack_mask) == target_ack,
328*e2ad626fSUlf Hansson 					0, 10000);
329*e2ad626fSUlf Hansson 	if (ret) {
330*e2ad626fSUlf Hansson 		dev_err(pmu->dev,
331*e2ad626fSUlf Hansson 			"failed to get ack on domain '%s', val=0x%x\n",
332*e2ad626fSUlf Hansson 			genpd->name, val);
333*e2ad626fSUlf Hansson 		return ret;
334*e2ad626fSUlf Hansson 	}
335*e2ad626fSUlf Hansson 
336*e2ad626fSUlf Hansson 	ret = readx_poll_timeout_atomic(rockchip_pmu_domain_is_idle, pd,
337*e2ad626fSUlf Hansson 					is_idle, is_idle == idle, 0, 10000);
338*e2ad626fSUlf Hansson 	if (ret) {
339*e2ad626fSUlf Hansson 		dev_err(pmu->dev,
340*e2ad626fSUlf Hansson 			"failed to set idle on domain '%s', val=%d\n",
341*e2ad626fSUlf Hansson 			genpd->name, is_idle);
342*e2ad626fSUlf Hansson 		return ret;
343*e2ad626fSUlf Hansson 	}
344*e2ad626fSUlf Hansson 
345*e2ad626fSUlf Hansson 	return 0;
346*e2ad626fSUlf Hansson }
347*e2ad626fSUlf Hansson 
348*e2ad626fSUlf Hansson static int rockchip_pmu_save_qos(struct rockchip_pm_domain *pd)
349*e2ad626fSUlf Hansson {
350*e2ad626fSUlf Hansson 	int i;
351*e2ad626fSUlf Hansson 
352*e2ad626fSUlf Hansson 	for (i = 0; i < pd->num_qos; i++) {
353*e2ad626fSUlf Hansson 		regmap_read(pd->qos_regmap[i],
354*e2ad626fSUlf Hansson 			    QOS_PRIORITY,
355*e2ad626fSUlf Hansson 			    &pd->qos_save_regs[0][i]);
356*e2ad626fSUlf Hansson 		regmap_read(pd->qos_regmap[i],
357*e2ad626fSUlf Hansson 			    QOS_MODE,
358*e2ad626fSUlf Hansson 			    &pd->qos_save_regs[1][i]);
359*e2ad626fSUlf Hansson 		regmap_read(pd->qos_regmap[i],
360*e2ad626fSUlf Hansson 			    QOS_BANDWIDTH,
361*e2ad626fSUlf Hansson 			    &pd->qos_save_regs[2][i]);
362*e2ad626fSUlf Hansson 		regmap_read(pd->qos_regmap[i],
363*e2ad626fSUlf Hansson 			    QOS_SATURATION,
364*e2ad626fSUlf Hansson 			    &pd->qos_save_regs[3][i]);
365*e2ad626fSUlf Hansson 		regmap_read(pd->qos_regmap[i],
366*e2ad626fSUlf Hansson 			    QOS_EXTCONTROL,
367*e2ad626fSUlf Hansson 			    &pd->qos_save_regs[4][i]);
368*e2ad626fSUlf Hansson 	}
369*e2ad626fSUlf Hansson 	return 0;
370*e2ad626fSUlf Hansson }
371*e2ad626fSUlf Hansson 
372*e2ad626fSUlf Hansson static int rockchip_pmu_restore_qos(struct rockchip_pm_domain *pd)
373*e2ad626fSUlf Hansson {
374*e2ad626fSUlf Hansson 	int i;
375*e2ad626fSUlf Hansson 
376*e2ad626fSUlf Hansson 	for (i = 0; i < pd->num_qos; i++) {
377*e2ad626fSUlf Hansson 		regmap_write(pd->qos_regmap[i],
378*e2ad626fSUlf Hansson 			     QOS_PRIORITY,
379*e2ad626fSUlf Hansson 			     pd->qos_save_regs[0][i]);
380*e2ad626fSUlf Hansson 		regmap_write(pd->qos_regmap[i],
381*e2ad626fSUlf Hansson 			     QOS_MODE,
382*e2ad626fSUlf Hansson 			     pd->qos_save_regs[1][i]);
383*e2ad626fSUlf Hansson 		regmap_write(pd->qos_regmap[i],
384*e2ad626fSUlf Hansson 			     QOS_BANDWIDTH,
385*e2ad626fSUlf Hansson 			     pd->qos_save_regs[2][i]);
386*e2ad626fSUlf Hansson 		regmap_write(pd->qos_regmap[i],
387*e2ad626fSUlf Hansson 			     QOS_SATURATION,
388*e2ad626fSUlf Hansson 			     pd->qos_save_regs[3][i]);
389*e2ad626fSUlf Hansson 		regmap_write(pd->qos_regmap[i],
390*e2ad626fSUlf Hansson 			     QOS_EXTCONTROL,
391*e2ad626fSUlf Hansson 			     pd->qos_save_regs[4][i]);
392*e2ad626fSUlf Hansson 	}
393*e2ad626fSUlf Hansson 
394*e2ad626fSUlf Hansson 	return 0;
395*e2ad626fSUlf Hansson }
396*e2ad626fSUlf Hansson 
397*e2ad626fSUlf Hansson static bool rockchip_pmu_domain_is_on(struct rockchip_pm_domain *pd)
398*e2ad626fSUlf Hansson {
399*e2ad626fSUlf Hansson 	struct rockchip_pmu *pmu = pd->pmu;
400*e2ad626fSUlf Hansson 	unsigned int val;
401*e2ad626fSUlf Hansson 
402*e2ad626fSUlf Hansson 	if (pd->info->repair_status_mask) {
403*e2ad626fSUlf Hansson 		regmap_read(pmu->regmap, pmu->info->repair_status_offset, &val);
404*e2ad626fSUlf Hansson 		/* 1'b1: power on, 1'b0: power off */
405*e2ad626fSUlf Hansson 		return val & pd->info->repair_status_mask;
406*e2ad626fSUlf Hansson 	}
407*e2ad626fSUlf Hansson 
408*e2ad626fSUlf Hansson 	/* check idle status for idle-only domains */
409*e2ad626fSUlf Hansson 	if (pd->info->status_mask == 0)
410*e2ad626fSUlf Hansson 		return !rockchip_pmu_domain_is_idle(pd);
411*e2ad626fSUlf Hansson 
412*e2ad626fSUlf Hansson 	regmap_read(pmu->regmap, pmu->info->status_offset, &val);
413*e2ad626fSUlf Hansson 
414*e2ad626fSUlf Hansson 	/* 1'b0: power on, 1'b1: power off */
415*e2ad626fSUlf Hansson 	return !(val & pd->info->status_mask);
416*e2ad626fSUlf Hansson }
417*e2ad626fSUlf Hansson 
418*e2ad626fSUlf Hansson static bool rockchip_pmu_domain_is_mem_on(struct rockchip_pm_domain *pd)
419*e2ad626fSUlf Hansson {
420*e2ad626fSUlf Hansson 	struct rockchip_pmu *pmu = pd->pmu;
421*e2ad626fSUlf Hansson 	unsigned int val;
422*e2ad626fSUlf Hansson 
423*e2ad626fSUlf Hansson 	regmap_read(pmu->regmap,
424*e2ad626fSUlf Hansson 		    pmu->info->mem_status_offset + pd->info->mem_offset, &val);
425*e2ad626fSUlf Hansson 
426*e2ad626fSUlf Hansson 	/* 1'b0: power on, 1'b1: power off */
427*e2ad626fSUlf Hansson 	return !(val & pd->info->mem_status_mask);
428*e2ad626fSUlf Hansson }
429*e2ad626fSUlf Hansson 
430*e2ad626fSUlf Hansson static bool rockchip_pmu_domain_is_chain_on(struct rockchip_pm_domain *pd)
431*e2ad626fSUlf Hansson {
432*e2ad626fSUlf Hansson 	struct rockchip_pmu *pmu = pd->pmu;
433*e2ad626fSUlf Hansson 	unsigned int val;
434*e2ad626fSUlf Hansson 
435*e2ad626fSUlf Hansson 	regmap_read(pmu->regmap,
436*e2ad626fSUlf Hansson 		    pmu->info->chain_status_offset + pd->info->mem_offset, &val);
437*e2ad626fSUlf Hansson 
438*e2ad626fSUlf Hansson 	/* 1'b1: power on, 1'b0: power off */
439*e2ad626fSUlf Hansson 	return val & pd->info->mem_status_mask;
440*e2ad626fSUlf Hansson }
441*e2ad626fSUlf Hansson 
442*e2ad626fSUlf Hansson static int rockchip_pmu_domain_mem_reset(struct rockchip_pm_domain *pd)
443*e2ad626fSUlf Hansson {
444*e2ad626fSUlf Hansson 	struct rockchip_pmu *pmu = pd->pmu;
445*e2ad626fSUlf Hansson 	struct generic_pm_domain *genpd = &pd->genpd;
446*e2ad626fSUlf Hansson 	bool is_on;
447*e2ad626fSUlf Hansson 	int ret = 0;
448*e2ad626fSUlf Hansson 
449*e2ad626fSUlf Hansson 	ret = readx_poll_timeout_atomic(rockchip_pmu_domain_is_chain_on, pd, is_on,
450*e2ad626fSUlf Hansson 					is_on == true, 0, 10000);
451*e2ad626fSUlf Hansson 	if (ret) {
452*e2ad626fSUlf Hansson 		dev_err(pmu->dev,
453*e2ad626fSUlf Hansson 			"failed to get chain status '%s', target_on=1, val=%d\n",
454*e2ad626fSUlf Hansson 			genpd->name, is_on);
455*e2ad626fSUlf Hansson 		goto error;
456*e2ad626fSUlf Hansson 	}
457*e2ad626fSUlf Hansson 
458*e2ad626fSUlf Hansson 	udelay(20);
459*e2ad626fSUlf Hansson 
460*e2ad626fSUlf Hansson 	regmap_write(pmu->regmap, pmu->info->mem_pwr_offset + pd->info->pwr_offset,
461*e2ad626fSUlf Hansson 		     (pd->info->pwr_mask | pd->info->pwr_w_mask));
462*e2ad626fSUlf Hansson 	wmb();
463*e2ad626fSUlf Hansson 
464*e2ad626fSUlf Hansson 	ret = readx_poll_timeout_atomic(rockchip_pmu_domain_is_mem_on, pd, is_on,
465*e2ad626fSUlf Hansson 					is_on == false, 0, 10000);
466*e2ad626fSUlf Hansson 	if (ret) {
467*e2ad626fSUlf Hansson 		dev_err(pmu->dev,
468*e2ad626fSUlf Hansson 			"failed to get mem status '%s', target_on=0, val=%d\n",
469*e2ad626fSUlf Hansson 			genpd->name, is_on);
470*e2ad626fSUlf Hansson 		goto error;
471*e2ad626fSUlf Hansson 	}
472*e2ad626fSUlf Hansson 
473*e2ad626fSUlf Hansson 	regmap_write(pmu->regmap, pmu->info->mem_pwr_offset + pd->info->pwr_offset,
474*e2ad626fSUlf Hansson 		     pd->info->pwr_w_mask);
475*e2ad626fSUlf Hansson 	wmb();
476*e2ad626fSUlf Hansson 
477*e2ad626fSUlf Hansson 	ret = readx_poll_timeout_atomic(rockchip_pmu_domain_is_mem_on, pd, is_on,
478*e2ad626fSUlf Hansson 					is_on == true, 0, 10000);
479*e2ad626fSUlf Hansson 	if (ret) {
480*e2ad626fSUlf Hansson 		dev_err(pmu->dev,
481*e2ad626fSUlf Hansson 			"failed to get mem status '%s', target_on=1, val=%d\n",
482*e2ad626fSUlf Hansson 			genpd->name, is_on);
483*e2ad626fSUlf Hansson 	}
484*e2ad626fSUlf Hansson 
485*e2ad626fSUlf Hansson error:
486*e2ad626fSUlf Hansson 	return ret;
487*e2ad626fSUlf Hansson }
488*e2ad626fSUlf Hansson 
489*e2ad626fSUlf Hansson static void rockchip_do_pmu_set_power_domain(struct rockchip_pm_domain *pd,
490*e2ad626fSUlf Hansson 					     bool on)
491*e2ad626fSUlf Hansson {
492*e2ad626fSUlf Hansson 	struct rockchip_pmu *pmu = pd->pmu;
493*e2ad626fSUlf Hansson 	struct generic_pm_domain *genpd = &pd->genpd;
494*e2ad626fSUlf Hansson 	u32 pd_pwr_offset = pd->info->pwr_offset;
495*e2ad626fSUlf Hansson 	bool is_on, is_mem_on = false;
496*e2ad626fSUlf Hansson 
497*e2ad626fSUlf Hansson 	if (pd->info->pwr_mask == 0)
498*e2ad626fSUlf Hansson 		return;
499*e2ad626fSUlf Hansson 
500*e2ad626fSUlf Hansson 	if (on && pd->info->mem_status_mask)
501*e2ad626fSUlf Hansson 		is_mem_on = rockchip_pmu_domain_is_mem_on(pd);
502*e2ad626fSUlf Hansson 
503*e2ad626fSUlf Hansson 	if (pd->info->pwr_w_mask)
504*e2ad626fSUlf Hansson 		regmap_write(pmu->regmap, pmu->info->pwr_offset + pd_pwr_offset,
505*e2ad626fSUlf Hansson 			     on ? pd->info->pwr_w_mask :
506*e2ad626fSUlf Hansson 			     (pd->info->pwr_mask | pd->info->pwr_w_mask));
507*e2ad626fSUlf Hansson 	else
508*e2ad626fSUlf Hansson 		regmap_update_bits(pmu->regmap, pmu->info->pwr_offset + pd_pwr_offset,
509*e2ad626fSUlf Hansson 				   pd->info->pwr_mask, on ? 0 : -1U);
510*e2ad626fSUlf Hansson 
511*e2ad626fSUlf Hansson 	wmb();
512*e2ad626fSUlf Hansson 
513*e2ad626fSUlf Hansson 	if (is_mem_on && rockchip_pmu_domain_mem_reset(pd))
514*e2ad626fSUlf Hansson 		return;
515*e2ad626fSUlf Hansson 
516*e2ad626fSUlf Hansson 	if (readx_poll_timeout_atomic(rockchip_pmu_domain_is_on, pd, is_on,
517*e2ad626fSUlf Hansson 				      is_on == on, 0, 10000)) {
518*e2ad626fSUlf Hansson 		dev_err(pmu->dev,
519*e2ad626fSUlf Hansson 			"failed to set domain '%s', val=%d\n",
520*e2ad626fSUlf Hansson 			genpd->name, is_on);
521*e2ad626fSUlf Hansson 		return;
522*e2ad626fSUlf Hansson 	}
523*e2ad626fSUlf Hansson }
524*e2ad626fSUlf Hansson 
525*e2ad626fSUlf Hansson static int rockchip_pd_power(struct rockchip_pm_domain *pd, bool power_on)
526*e2ad626fSUlf Hansson {
527*e2ad626fSUlf Hansson 	struct rockchip_pmu *pmu = pd->pmu;
528*e2ad626fSUlf Hansson 	int ret;
529*e2ad626fSUlf Hansson 
530*e2ad626fSUlf Hansson 	mutex_lock(&pmu->mutex);
531*e2ad626fSUlf Hansson 
532*e2ad626fSUlf Hansson 	if (rockchip_pmu_domain_is_on(pd) != power_on) {
533*e2ad626fSUlf Hansson 		ret = clk_bulk_enable(pd->num_clks, pd->clks);
534*e2ad626fSUlf Hansson 		if (ret < 0) {
535*e2ad626fSUlf Hansson 			dev_err(pmu->dev, "failed to enable clocks\n");
536*e2ad626fSUlf Hansson 			mutex_unlock(&pmu->mutex);
537*e2ad626fSUlf Hansson 			return ret;
538*e2ad626fSUlf Hansson 		}
539*e2ad626fSUlf Hansson 
540*e2ad626fSUlf Hansson 		if (!power_on) {
541*e2ad626fSUlf Hansson 			rockchip_pmu_save_qos(pd);
542*e2ad626fSUlf Hansson 
543*e2ad626fSUlf Hansson 			/* if powering down, idle request to NIU first */
544*e2ad626fSUlf Hansson 			rockchip_pmu_set_idle_request(pd, true);
545*e2ad626fSUlf Hansson 		}
546*e2ad626fSUlf Hansson 
547*e2ad626fSUlf Hansson 		rockchip_do_pmu_set_power_domain(pd, power_on);
548*e2ad626fSUlf Hansson 
549*e2ad626fSUlf Hansson 		if (power_on) {
550*e2ad626fSUlf Hansson 			/* if powering up, leave idle mode */
551*e2ad626fSUlf Hansson 			rockchip_pmu_set_idle_request(pd, false);
552*e2ad626fSUlf Hansson 
553*e2ad626fSUlf Hansson 			rockchip_pmu_restore_qos(pd);
554*e2ad626fSUlf Hansson 		}
555*e2ad626fSUlf Hansson 
556*e2ad626fSUlf Hansson 		clk_bulk_disable(pd->num_clks, pd->clks);
557*e2ad626fSUlf Hansson 	}
558*e2ad626fSUlf Hansson 
559*e2ad626fSUlf Hansson 	mutex_unlock(&pmu->mutex);
560*e2ad626fSUlf Hansson 	return 0;
561*e2ad626fSUlf Hansson }
562*e2ad626fSUlf Hansson 
563*e2ad626fSUlf Hansson static int rockchip_pd_power_on(struct generic_pm_domain *domain)
564*e2ad626fSUlf Hansson {
565*e2ad626fSUlf Hansson 	struct rockchip_pm_domain *pd = to_rockchip_pd(domain);
566*e2ad626fSUlf Hansson 
567*e2ad626fSUlf Hansson 	return rockchip_pd_power(pd, true);
568*e2ad626fSUlf Hansson }
569*e2ad626fSUlf Hansson 
570*e2ad626fSUlf Hansson static int rockchip_pd_power_off(struct generic_pm_domain *domain)
571*e2ad626fSUlf Hansson {
572*e2ad626fSUlf Hansson 	struct rockchip_pm_domain *pd = to_rockchip_pd(domain);
573*e2ad626fSUlf Hansson 
574*e2ad626fSUlf Hansson 	return rockchip_pd_power(pd, false);
575*e2ad626fSUlf Hansson }
576*e2ad626fSUlf Hansson 
577*e2ad626fSUlf Hansson static int rockchip_pd_attach_dev(struct generic_pm_domain *genpd,
578*e2ad626fSUlf Hansson 				  struct device *dev)
579*e2ad626fSUlf Hansson {
580*e2ad626fSUlf Hansson 	struct clk *clk;
581*e2ad626fSUlf Hansson 	int i;
582*e2ad626fSUlf Hansson 	int error;
583*e2ad626fSUlf Hansson 
584*e2ad626fSUlf Hansson 	dev_dbg(dev, "attaching to power domain '%s'\n", genpd->name);
585*e2ad626fSUlf Hansson 
586*e2ad626fSUlf Hansson 	error = pm_clk_create(dev);
587*e2ad626fSUlf Hansson 	if (error) {
588*e2ad626fSUlf Hansson 		dev_err(dev, "pm_clk_create failed %d\n", error);
589*e2ad626fSUlf Hansson 		return error;
590*e2ad626fSUlf Hansson 	}
591*e2ad626fSUlf Hansson 
592*e2ad626fSUlf Hansson 	i = 0;
593*e2ad626fSUlf Hansson 	while ((clk = of_clk_get(dev->of_node, i++)) && !IS_ERR(clk)) {
594*e2ad626fSUlf Hansson 		dev_dbg(dev, "adding clock '%pC' to list of PM clocks\n", clk);
595*e2ad626fSUlf Hansson 		error = pm_clk_add_clk(dev, clk);
596*e2ad626fSUlf Hansson 		if (error) {
597*e2ad626fSUlf Hansson 			dev_err(dev, "pm_clk_add_clk failed %d\n", error);
598*e2ad626fSUlf Hansson 			clk_put(clk);
599*e2ad626fSUlf Hansson 			pm_clk_destroy(dev);
600*e2ad626fSUlf Hansson 			return error;
601*e2ad626fSUlf Hansson 		}
602*e2ad626fSUlf Hansson 	}
603*e2ad626fSUlf Hansson 
604*e2ad626fSUlf Hansson 	return 0;
605*e2ad626fSUlf Hansson }
606*e2ad626fSUlf Hansson 
607*e2ad626fSUlf Hansson static void rockchip_pd_detach_dev(struct generic_pm_domain *genpd,
608*e2ad626fSUlf Hansson 				   struct device *dev)
609*e2ad626fSUlf Hansson {
610*e2ad626fSUlf Hansson 	dev_dbg(dev, "detaching from power domain '%s'\n", genpd->name);
611*e2ad626fSUlf Hansson 
612*e2ad626fSUlf Hansson 	pm_clk_destroy(dev);
613*e2ad626fSUlf Hansson }
614*e2ad626fSUlf Hansson 
615*e2ad626fSUlf Hansson static int rockchip_pm_add_one_domain(struct rockchip_pmu *pmu,
616*e2ad626fSUlf Hansson 				      struct device_node *node)
617*e2ad626fSUlf Hansson {
618*e2ad626fSUlf Hansson 	const struct rockchip_domain_info *pd_info;
619*e2ad626fSUlf Hansson 	struct rockchip_pm_domain *pd;
620*e2ad626fSUlf Hansson 	struct device_node *qos_node;
621*e2ad626fSUlf Hansson 	int i, j;
622*e2ad626fSUlf Hansson 	u32 id;
623*e2ad626fSUlf Hansson 	int error;
624*e2ad626fSUlf Hansson 
625*e2ad626fSUlf Hansson 	error = of_property_read_u32(node, "reg", &id);
626*e2ad626fSUlf Hansson 	if (error) {
627*e2ad626fSUlf Hansson 		dev_err(pmu->dev,
628*e2ad626fSUlf Hansson 			"%pOFn: failed to retrieve domain id (reg): %d\n",
629*e2ad626fSUlf Hansson 			node, error);
630*e2ad626fSUlf Hansson 		return -EINVAL;
631*e2ad626fSUlf Hansson 	}
632*e2ad626fSUlf Hansson 
633*e2ad626fSUlf Hansson 	if (id >= pmu->info->num_domains) {
634*e2ad626fSUlf Hansson 		dev_err(pmu->dev, "%pOFn: invalid domain id %d\n",
635*e2ad626fSUlf Hansson 			node, id);
636*e2ad626fSUlf Hansson 		return -EINVAL;
637*e2ad626fSUlf Hansson 	}
638*e2ad626fSUlf Hansson 	/* RK3588 has domains with two parents (RKVDEC0/RKVDEC1) */
639*e2ad626fSUlf Hansson 	if (pmu->genpd_data.domains[id])
640*e2ad626fSUlf Hansson 		return 0;
641*e2ad626fSUlf Hansson 
642*e2ad626fSUlf Hansson 	pd_info = &pmu->info->domain_info[id];
643*e2ad626fSUlf Hansson 	if (!pd_info) {
644*e2ad626fSUlf Hansson 		dev_err(pmu->dev, "%pOFn: undefined domain id %d\n",
645*e2ad626fSUlf Hansson 			node, id);
646*e2ad626fSUlf Hansson 		return -EINVAL;
647*e2ad626fSUlf Hansson 	}
648*e2ad626fSUlf Hansson 
649*e2ad626fSUlf Hansson 	pd = devm_kzalloc(pmu->dev, sizeof(*pd), GFP_KERNEL);
650*e2ad626fSUlf Hansson 	if (!pd)
651*e2ad626fSUlf Hansson 		return -ENOMEM;
652*e2ad626fSUlf Hansson 
653*e2ad626fSUlf Hansson 	pd->info = pd_info;
654*e2ad626fSUlf Hansson 	pd->pmu = pmu;
655*e2ad626fSUlf Hansson 
656*e2ad626fSUlf Hansson 	pd->num_clks = of_clk_get_parent_count(node);
657*e2ad626fSUlf Hansson 	if (pd->num_clks > 0) {
658*e2ad626fSUlf Hansson 		pd->clks = devm_kcalloc(pmu->dev, pd->num_clks,
659*e2ad626fSUlf Hansson 					sizeof(*pd->clks), GFP_KERNEL);
660*e2ad626fSUlf Hansson 		if (!pd->clks)
661*e2ad626fSUlf Hansson 			return -ENOMEM;
662*e2ad626fSUlf Hansson 	} else {
663*e2ad626fSUlf Hansson 		dev_dbg(pmu->dev, "%pOFn: doesn't have clocks: %d\n",
664*e2ad626fSUlf Hansson 			node, pd->num_clks);
665*e2ad626fSUlf Hansson 		pd->num_clks = 0;
666*e2ad626fSUlf Hansson 	}
667*e2ad626fSUlf Hansson 
668*e2ad626fSUlf Hansson 	for (i = 0; i < pd->num_clks; i++) {
669*e2ad626fSUlf Hansson 		pd->clks[i].clk = of_clk_get(node, i);
670*e2ad626fSUlf Hansson 		if (IS_ERR(pd->clks[i].clk)) {
671*e2ad626fSUlf Hansson 			error = PTR_ERR(pd->clks[i].clk);
672*e2ad626fSUlf Hansson 			dev_err(pmu->dev,
673*e2ad626fSUlf Hansson 				"%pOFn: failed to get clk at index %d: %d\n",
674*e2ad626fSUlf Hansson 				node, i, error);
675*e2ad626fSUlf Hansson 			return error;
676*e2ad626fSUlf Hansson 		}
677*e2ad626fSUlf Hansson 	}
678*e2ad626fSUlf Hansson 
679*e2ad626fSUlf Hansson 	error = clk_bulk_prepare(pd->num_clks, pd->clks);
680*e2ad626fSUlf Hansson 	if (error)
681*e2ad626fSUlf Hansson 		goto err_put_clocks;
682*e2ad626fSUlf Hansson 
683*e2ad626fSUlf Hansson 	pd->num_qos = of_count_phandle_with_args(node, "pm_qos",
684*e2ad626fSUlf Hansson 						 NULL);
685*e2ad626fSUlf Hansson 
686*e2ad626fSUlf Hansson 	if (pd->num_qos > 0) {
687*e2ad626fSUlf Hansson 		pd->qos_regmap = devm_kcalloc(pmu->dev, pd->num_qos,
688*e2ad626fSUlf Hansson 					      sizeof(*pd->qos_regmap),
689*e2ad626fSUlf Hansson 					      GFP_KERNEL);
690*e2ad626fSUlf Hansson 		if (!pd->qos_regmap) {
691*e2ad626fSUlf Hansson 			error = -ENOMEM;
692*e2ad626fSUlf Hansson 			goto err_unprepare_clocks;
693*e2ad626fSUlf Hansson 		}
694*e2ad626fSUlf Hansson 
695*e2ad626fSUlf Hansson 		for (j = 0; j < MAX_QOS_REGS_NUM; j++) {
696*e2ad626fSUlf Hansson 			pd->qos_save_regs[j] = devm_kcalloc(pmu->dev,
697*e2ad626fSUlf Hansson 							    pd->num_qos,
698*e2ad626fSUlf Hansson 							    sizeof(u32),
699*e2ad626fSUlf Hansson 							    GFP_KERNEL);
700*e2ad626fSUlf Hansson 			if (!pd->qos_save_regs[j]) {
701*e2ad626fSUlf Hansson 				error = -ENOMEM;
702*e2ad626fSUlf Hansson 				goto err_unprepare_clocks;
703*e2ad626fSUlf Hansson 			}
704*e2ad626fSUlf Hansson 		}
705*e2ad626fSUlf Hansson 
706*e2ad626fSUlf Hansson 		for (j = 0; j < pd->num_qos; j++) {
707*e2ad626fSUlf Hansson 			qos_node = of_parse_phandle(node, "pm_qos", j);
708*e2ad626fSUlf Hansson 			if (!qos_node) {
709*e2ad626fSUlf Hansson 				error = -ENODEV;
710*e2ad626fSUlf Hansson 				goto err_unprepare_clocks;
711*e2ad626fSUlf Hansson 			}
712*e2ad626fSUlf Hansson 			pd->qos_regmap[j] = syscon_node_to_regmap(qos_node);
713*e2ad626fSUlf Hansson 			if (IS_ERR(pd->qos_regmap[j])) {
714*e2ad626fSUlf Hansson 				error = -ENODEV;
715*e2ad626fSUlf Hansson 				of_node_put(qos_node);
716*e2ad626fSUlf Hansson 				goto err_unprepare_clocks;
717*e2ad626fSUlf Hansson 			}
718*e2ad626fSUlf Hansson 			of_node_put(qos_node);
719*e2ad626fSUlf Hansson 		}
720*e2ad626fSUlf Hansson 	}
721*e2ad626fSUlf Hansson 
722*e2ad626fSUlf Hansson 	if (pd->info->name)
723*e2ad626fSUlf Hansson 		pd->genpd.name = pd->info->name;
724*e2ad626fSUlf Hansson 	else
725*e2ad626fSUlf Hansson 		pd->genpd.name = kbasename(node->full_name);
726*e2ad626fSUlf Hansson 	pd->genpd.power_off = rockchip_pd_power_off;
727*e2ad626fSUlf Hansson 	pd->genpd.power_on = rockchip_pd_power_on;
728*e2ad626fSUlf Hansson 	pd->genpd.attach_dev = rockchip_pd_attach_dev;
729*e2ad626fSUlf Hansson 	pd->genpd.detach_dev = rockchip_pd_detach_dev;
730*e2ad626fSUlf Hansson 	pd->genpd.flags = GENPD_FLAG_PM_CLK;
731*e2ad626fSUlf Hansson 	if (pd_info->active_wakeup)
732*e2ad626fSUlf Hansson 		pd->genpd.flags |= GENPD_FLAG_ACTIVE_WAKEUP;
733*e2ad626fSUlf Hansson 	pm_genpd_init(&pd->genpd, NULL,
734*e2ad626fSUlf Hansson 		      !rockchip_pmu_domain_is_on(pd) ||
735*e2ad626fSUlf Hansson 		      (pd->info->mem_status_mask && !rockchip_pmu_domain_is_mem_on(pd)));
736*e2ad626fSUlf Hansson 
737*e2ad626fSUlf Hansson 	pmu->genpd_data.domains[id] = &pd->genpd;
738*e2ad626fSUlf Hansson 	return 0;
739*e2ad626fSUlf Hansson 
740*e2ad626fSUlf Hansson err_unprepare_clocks:
741*e2ad626fSUlf Hansson 	clk_bulk_unprepare(pd->num_clks, pd->clks);
742*e2ad626fSUlf Hansson err_put_clocks:
743*e2ad626fSUlf Hansson 	clk_bulk_put(pd->num_clks, pd->clks);
744*e2ad626fSUlf Hansson 	return error;
745*e2ad626fSUlf Hansson }
746*e2ad626fSUlf Hansson 
747*e2ad626fSUlf Hansson static void rockchip_pm_remove_one_domain(struct rockchip_pm_domain *pd)
748*e2ad626fSUlf Hansson {
749*e2ad626fSUlf Hansson 	int ret;
750*e2ad626fSUlf Hansson 
751*e2ad626fSUlf Hansson 	/*
752*e2ad626fSUlf Hansson 	 * We're in the error cleanup already, so we only complain,
753*e2ad626fSUlf Hansson 	 * but won't emit another error on top of the original one.
754*e2ad626fSUlf Hansson 	 */
755*e2ad626fSUlf Hansson 	ret = pm_genpd_remove(&pd->genpd);
756*e2ad626fSUlf Hansson 	if (ret < 0)
757*e2ad626fSUlf Hansson 		dev_err(pd->pmu->dev, "failed to remove domain '%s' : %d - state may be inconsistent\n",
758*e2ad626fSUlf Hansson 			pd->genpd.name, ret);
759*e2ad626fSUlf Hansson 
760*e2ad626fSUlf Hansson 	clk_bulk_unprepare(pd->num_clks, pd->clks);
761*e2ad626fSUlf Hansson 	clk_bulk_put(pd->num_clks, pd->clks);
762*e2ad626fSUlf Hansson 
763*e2ad626fSUlf Hansson 	/* protect the zeroing of pm->num_clks */
764*e2ad626fSUlf Hansson 	mutex_lock(&pd->pmu->mutex);
765*e2ad626fSUlf Hansson 	pd->num_clks = 0;
766*e2ad626fSUlf Hansson 	mutex_unlock(&pd->pmu->mutex);
767*e2ad626fSUlf Hansson 
768*e2ad626fSUlf Hansson 	/* devm will free our memory */
769*e2ad626fSUlf Hansson }
770*e2ad626fSUlf Hansson 
771*e2ad626fSUlf Hansson static void rockchip_pm_domain_cleanup(struct rockchip_pmu *pmu)
772*e2ad626fSUlf Hansson {
773*e2ad626fSUlf Hansson 	struct generic_pm_domain *genpd;
774*e2ad626fSUlf Hansson 	struct rockchip_pm_domain *pd;
775*e2ad626fSUlf Hansson 	int i;
776*e2ad626fSUlf Hansson 
777*e2ad626fSUlf Hansson 	for (i = 0; i < pmu->genpd_data.num_domains; i++) {
778*e2ad626fSUlf Hansson 		genpd = pmu->genpd_data.domains[i];
779*e2ad626fSUlf Hansson 		if (genpd) {
780*e2ad626fSUlf Hansson 			pd = to_rockchip_pd(genpd);
781*e2ad626fSUlf Hansson 			rockchip_pm_remove_one_domain(pd);
782*e2ad626fSUlf Hansson 		}
783*e2ad626fSUlf Hansson 	}
784*e2ad626fSUlf Hansson 
785*e2ad626fSUlf Hansson 	/* devm will free our memory */
786*e2ad626fSUlf Hansson }
787*e2ad626fSUlf Hansson 
788*e2ad626fSUlf Hansson static void rockchip_configure_pd_cnt(struct rockchip_pmu *pmu,
789*e2ad626fSUlf Hansson 				      u32 domain_reg_offset,
790*e2ad626fSUlf Hansson 				      unsigned int count)
791*e2ad626fSUlf Hansson {
792*e2ad626fSUlf Hansson 	/* First configure domain power down transition count ... */
793*e2ad626fSUlf Hansson 	regmap_write(pmu->regmap, domain_reg_offset, count);
794*e2ad626fSUlf Hansson 	/* ... and then power up count. */
795*e2ad626fSUlf Hansson 	regmap_write(pmu->regmap, domain_reg_offset + 4, count);
796*e2ad626fSUlf Hansson }
797*e2ad626fSUlf Hansson 
798*e2ad626fSUlf Hansson static int rockchip_pm_add_subdomain(struct rockchip_pmu *pmu,
799*e2ad626fSUlf Hansson 				     struct device_node *parent)
800*e2ad626fSUlf Hansson {
801*e2ad626fSUlf Hansson 	struct device_node *np;
802*e2ad626fSUlf Hansson 	struct generic_pm_domain *child_domain, *parent_domain;
803*e2ad626fSUlf Hansson 	int error;
804*e2ad626fSUlf Hansson 
805*e2ad626fSUlf Hansson 	for_each_child_of_node(parent, np) {
806*e2ad626fSUlf Hansson 		u32 idx;
807*e2ad626fSUlf Hansson 
808*e2ad626fSUlf Hansson 		error = of_property_read_u32(parent, "reg", &idx);
809*e2ad626fSUlf Hansson 		if (error) {
810*e2ad626fSUlf Hansson 			dev_err(pmu->dev,
811*e2ad626fSUlf Hansson 				"%pOFn: failed to retrieve domain id (reg): %d\n",
812*e2ad626fSUlf Hansson 				parent, error);
813*e2ad626fSUlf Hansson 			goto err_out;
814*e2ad626fSUlf Hansson 		}
815*e2ad626fSUlf Hansson 		parent_domain = pmu->genpd_data.domains[idx];
816*e2ad626fSUlf Hansson 
817*e2ad626fSUlf Hansson 		error = rockchip_pm_add_one_domain(pmu, np);
818*e2ad626fSUlf Hansson 		if (error) {
819*e2ad626fSUlf Hansson 			dev_err(pmu->dev, "failed to handle node %pOFn: %d\n",
820*e2ad626fSUlf Hansson 				np, error);
821*e2ad626fSUlf Hansson 			goto err_out;
822*e2ad626fSUlf Hansson 		}
823*e2ad626fSUlf Hansson 
824*e2ad626fSUlf Hansson 		error = of_property_read_u32(np, "reg", &idx);
825*e2ad626fSUlf Hansson 		if (error) {
826*e2ad626fSUlf Hansson 			dev_err(pmu->dev,
827*e2ad626fSUlf Hansson 				"%pOFn: failed to retrieve domain id (reg): %d\n",
828*e2ad626fSUlf Hansson 				np, error);
829*e2ad626fSUlf Hansson 			goto err_out;
830*e2ad626fSUlf Hansson 		}
831*e2ad626fSUlf Hansson 		child_domain = pmu->genpd_data.domains[idx];
832*e2ad626fSUlf Hansson 
833*e2ad626fSUlf Hansson 		error = pm_genpd_add_subdomain(parent_domain, child_domain);
834*e2ad626fSUlf Hansson 		if (error) {
835*e2ad626fSUlf Hansson 			dev_err(pmu->dev, "%s failed to add subdomain %s: %d\n",
836*e2ad626fSUlf Hansson 				parent_domain->name, child_domain->name, error);
837*e2ad626fSUlf Hansson 			goto err_out;
838*e2ad626fSUlf Hansson 		} else {
839*e2ad626fSUlf Hansson 			dev_dbg(pmu->dev, "%s add subdomain: %s\n",
840*e2ad626fSUlf Hansson 				parent_domain->name, child_domain->name);
841*e2ad626fSUlf Hansson 		}
842*e2ad626fSUlf Hansson 
843*e2ad626fSUlf Hansson 		rockchip_pm_add_subdomain(pmu, np);
844*e2ad626fSUlf Hansson 	}
845*e2ad626fSUlf Hansson 
846*e2ad626fSUlf Hansson 	return 0;
847*e2ad626fSUlf Hansson 
848*e2ad626fSUlf Hansson err_out:
849*e2ad626fSUlf Hansson 	of_node_put(np);
850*e2ad626fSUlf Hansson 	return error;
851*e2ad626fSUlf Hansson }
852*e2ad626fSUlf Hansson 
853*e2ad626fSUlf Hansson static int rockchip_pm_domain_probe(struct platform_device *pdev)
854*e2ad626fSUlf Hansson {
855*e2ad626fSUlf Hansson 	struct device *dev = &pdev->dev;
856*e2ad626fSUlf Hansson 	struct device_node *np = dev->of_node;
857*e2ad626fSUlf Hansson 	struct device_node *node;
858*e2ad626fSUlf Hansson 	struct device *parent;
859*e2ad626fSUlf Hansson 	struct rockchip_pmu *pmu;
860*e2ad626fSUlf Hansson 	const struct of_device_id *match;
861*e2ad626fSUlf Hansson 	const struct rockchip_pmu_info *pmu_info;
862*e2ad626fSUlf Hansson 	int error;
863*e2ad626fSUlf Hansson 
864*e2ad626fSUlf Hansson 	if (!np) {
865*e2ad626fSUlf Hansson 		dev_err(dev, "device tree node not found\n");
866*e2ad626fSUlf Hansson 		return -ENODEV;
867*e2ad626fSUlf Hansson 	}
868*e2ad626fSUlf Hansson 
869*e2ad626fSUlf Hansson 	match = of_match_device(dev->driver->of_match_table, dev);
870*e2ad626fSUlf Hansson 	if (!match || !match->data) {
871*e2ad626fSUlf Hansson 		dev_err(dev, "missing pmu data\n");
872*e2ad626fSUlf Hansson 		return -EINVAL;
873*e2ad626fSUlf Hansson 	}
874*e2ad626fSUlf Hansson 
875*e2ad626fSUlf Hansson 	pmu_info = match->data;
876*e2ad626fSUlf Hansson 
877*e2ad626fSUlf Hansson 	pmu = devm_kzalloc(dev,
878*e2ad626fSUlf Hansson 			   struct_size(pmu, domains, pmu_info->num_domains),
879*e2ad626fSUlf Hansson 			   GFP_KERNEL);
880*e2ad626fSUlf Hansson 	if (!pmu)
881*e2ad626fSUlf Hansson 		return -ENOMEM;
882*e2ad626fSUlf Hansson 
883*e2ad626fSUlf Hansson 	pmu->dev = &pdev->dev;
884*e2ad626fSUlf Hansson 	mutex_init(&pmu->mutex);
885*e2ad626fSUlf Hansson 
886*e2ad626fSUlf Hansson 	pmu->info = pmu_info;
887*e2ad626fSUlf Hansson 
888*e2ad626fSUlf Hansson 	pmu->genpd_data.domains = pmu->domains;
889*e2ad626fSUlf Hansson 	pmu->genpd_data.num_domains = pmu_info->num_domains;
890*e2ad626fSUlf Hansson 
891*e2ad626fSUlf Hansson 	parent = dev->parent;
892*e2ad626fSUlf Hansson 	if (!parent) {
893*e2ad626fSUlf Hansson 		dev_err(dev, "no parent for syscon devices\n");
894*e2ad626fSUlf Hansson 		return -ENODEV;
895*e2ad626fSUlf Hansson 	}
896*e2ad626fSUlf Hansson 
897*e2ad626fSUlf Hansson 	pmu->regmap = syscon_node_to_regmap(parent->of_node);
898*e2ad626fSUlf Hansson 	if (IS_ERR(pmu->regmap)) {
899*e2ad626fSUlf Hansson 		dev_err(dev, "no regmap available\n");
900*e2ad626fSUlf Hansson 		return PTR_ERR(pmu->regmap);
901*e2ad626fSUlf Hansson 	}
902*e2ad626fSUlf Hansson 
903*e2ad626fSUlf Hansson 	/*
904*e2ad626fSUlf Hansson 	 * Configure power up and down transition delays for CORE
905*e2ad626fSUlf Hansson 	 * and GPU domains.
906*e2ad626fSUlf Hansson 	 */
907*e2ad626fSUlf Hansson 	if (pmu_info->core_power_transition_time)
908*e2ad626fSUlf Hansson 		rockchip_configure_pd_cnt(pmu, pmu_info->core_pwrcnt_offset,
909*e2ad626fSUlf Hansson 					pmu_info->core_power_transition_time);
910*e2ad626fSUlf Hansson 	if (pmu_info->gpu_pwrcnt_offset)
911*e2ad626fSUlf Hansson 		rockchip_configure_pd_cnt(pmu, pmu_info->gpu_pwrcnt_offset,
912*e2ad626fSUlf Hansson 					pmu_info->gpu_power_transition_time);
913*e2ad626fSUlf Hansson 
914*e2ad626fSUlf Hansson 	error = -ENODEV;
915*e2ad626fSUlf Hansson 
916*e2ad626fSUlf Hansson 	/*
917*e2ad626fSUlf Hansson 	 * Prevent any rockchip_pmu_block() from racing with the remainder of
918*e2ad626fSUlf Hansson 	 * setup (clocks, register initialization).
919*e2ad626fSUlf Hansson 	 */
920*e2ad626fSUlf Hansson 	mutex_lock(&dmc_pmu_mutex);
921*e2ad626fSUlf Hansson 
922*e2ad626fSUlf Hansson 	for_each_available_child_of_node(np, node) {
923*e2ad626fSUlf Hansson 		error = rockchip_pm_add_one_domain(pmu, node);
924*e2ad626fSUlf Hansson 		if (error) {
925*e2ad626fSUlf Hansson 			dev_err(dev, "failed to handle node %pOFn: %d\n",
926*e2ad626fSUlf Hansson 				node, error);
927*e2ad626fSUlf Hansson 			of_node_put(node);
928*e2ad626fSUlf Hansson 			goto err_out;
929*e2ad626fSUlf Hansson 		}
930*e2ad626fSUlf Hansson 
931*e2ad626fSUlf Hansson 		error = rockchip_pm_add_subdomain(pmu, node);
932*e2ad626fSUlf Hansson 		if (error < 0) {
933*e2ad626fSUlf Hansson 			dev_err(dev, "failed to handle subdomain node %pOFn: %d\n",
934*e2ad626fSUlf Hansson 				node, error);
935*e2ad626fSUlf Hansson 			of_node_put(node);
936*e2ad626fSUlf Hansson 			goto err_out;
937*e2ad626fSUlf Hansson 		}
938*e2ad626fSUlf Hansson 	}
939*e2ad626fSUlf Hansson 
940*e2ad626fSUlf Hansson 	if (error) {
941*e2ad626fSUlf Hansson 		dev_dbg(dev, "no power domains defined\n");
942*e2ad626fSUlf Hansson 		goto err_out;
943*e2ad626fSUlf Hansson 	}
944*e2ad626fSUlf Hansson 
945*e2ad626fSUlf Hansson 	error = of_genpd_add_provider_onecell(np, &pmu->genpd_data);
946*e2ad626fSUlf Hansson 	if (error) {
947*e2ad626fSUlf Hansson 		dev_err(dev, "failed to add provider: %d\n", error);
948*e2ad626fSUlf Hansson 		goto err_out;
949*e2ad626fSUlf Hansson 	}
950*e2ad626fSUlf Hansson 
951*e2ad626fSUlf Hansson 	/* We only expect one PMU. */
952*e2ad626fSUlf Hansson 	if (!WARN_ON_ONCE(dmc_pmu))
953*e2ad626fSUlf Hansson 		dmc_pmu = pmu;
954*e2ad626fSUlf Hansson 
955*e2ad626fSUlf Hansson 	mutex_unlock(&dmc_pmu_mutex);
956*e2ad626fSUlf Hansson 
957*e2ad626fSUlf Hansson 	return 0;
958*e2ad626fSUlf Hansson 
959*e2ad626fSUlf Hansson err_out:
960*e2ad626fSUlf Hansson 	rockchip_pm_domain_cleanup(pmu);
961*e2ad626fSUlf Hansson 	mutex_unlock(&dmc_pmu_mutex);
962*e2ad626fSUlf Hansson 	return error;
963*e2ad626fSUlf Hansson }
964*e2ad626fSUlf Hansson 
965*e2ad626fSUlf Hansson static const struct rockchip_domain_info px30_pm_domains[] = {
966*e2ad626fSUlf Hansson 	[PX30_PD_USB]		= DOMAIN_PX30("usb",      BIT(5),  BIT(5),  BIT(10), false),
967*e2ad626fSUlf Hansson 	[PX30_PD_SDCARD]	= DOMAIN_PX30("sdcard",   BIT(8),  BIT(8),  BIT(9),  false),
968*e2ad626fSUlf Hansson 	[PX30_PD_GMAC]		= DOMAIN_PX30("gmac",     BIT(10), BIT(10), BIT(6),  false),
969*e2ad626fSUlf Hansson 	[PX30_PD_MMC_NAND]	= DOMAIN_PX30("mmc_nand", BIT(11), BIT(11), BIT(5),  false),
970*e2ad626fSUlf Hansson 	[PX30_PD_VPU]		= DOMAIN_PX30("vpu",      BIT(12), BIT(12), BIT(14), false),
971*e2ad626fSUlf Hansson 	[PX30_PD_VO]		= DOMAIN_PX30("vo",       BIT(13), BIT(13), BIT(7),  false),
972*e2ad626fSUlf Hansson 	[PX30_PD_VI]		= DOMAIN_PX30("vi",       BIT(14), BIT(14), BIT(8),  false),
973*e2ad626fSUlf Hansson 	[PX30_PD_GPU]		= DOMAIN_PX30("gpu",      BIT(15), BIT(15), BIT(2),  false),
974*e2ad626fSUlf Hansson };
975*e2ad626fSUlf Hansson 
976*e2ad626fSUlf Hansson static const struct rockchip_domain_info rv1126_pm_domains[] = {
977*e2ad626fSUlf Hansson 	[RV1126_PD_VEPU]	= DOMAIN_RV1126("vepu", BIT(2),  BIT(9),  BIT(9), false),
978*e2ad626fSUlf Hansson 	[RV1126_PD_VI]		= DOMAIN_RV1126("vi", BIT(4),  BIT(6),  BIT(6),  false),
979*e2ad626fSUlf Hansson 	[RV1126_PD_VO]		= DOMAIN_RV1126("vo", BIT(5),  BIT(7),  BIT(7),  false),
980*e2ad626fSUlf Hansson 	[RV1126_PD_ISPP]	= DOMAIN_RV1126("ispp", BIT(1), BIT(8), BIT(8),  false),
981*e2ad626fSUlf Hansson 	[RV1126_PD_VDPU]	= DOMAIN_RV1126("vdpu", BIT(3), BIT(10), BIT(10), false),
982*e2ad626fSUlf Hansson 	[RV1126_PD_NVM]		= DOMAIN_RV1126("nvm", BIT(7), BIT(11), BIT(11),  false),
983*e2ad626fSUlf Hansson 	[RV1126_PD_SDIO]	= DOMAIN_RV1126("sdio", BIT(8), BIT(13), BIT(13),  false),
984*e2ad626fSUlf Hansson 	[RV1126_PD_USB]		= DOMAIN_RV1126("usb", BIT(9), BIT(15), BIT(15),  false),
985*e2ad626fSUlf Hansson };
986*e2ad626fSUlf Hansson 
987*e2ad626fSUlf Hansson static const struct rockchip_domain_info rk3036_pm_domains[] = {
988*e2ad626fSUlf Hansson 	[RK3036_PD_MSCH]	= DOMAIN_RK3036("msch", BIT(14), BIT(23), BIT(30), true),
989*e2ad626fSUlf Hansson 	[RK3036_PD_CORE]	= DOMAIN_RK3036("core", BIT(13), BIT(17), BIT(24), false),
990*e2ad626fSUlf Hansson 	[RK3036_PD_PERI]	= DOMAIN_RK3036("peri", BIT(12), BIT(18), BIT(25), false),
991*e2ad626fSUlf Hansson 	[RK3036_PD_VIO]		= DOMAIN_RK3036("vio",  BIT(11), BIT(19), BIT(26), false),
992*e2ad626fSUlf Hansson 	[RK3036_PD_VPU]		= DOMAIN_RK3036("vpu",  BIT(10), BIT(20), BIT(27), false),
993*e2ad626fSUlf Hansson 	[RK3036_PD_GPU]		= DOMAIN_RK3036("gpu",  BIT(9),  BIT(21), BIT(28), false),
994*e2ad626fSUlf Hansson 	[RK3036_PD_SYS]		= DOMAIN_RK3036("sys",  BIT(8),  BIT(22), BIT(29), false),
995*e2ad626fSUlf Hansson };
996*e2ad626fSUlf Hansson 
997*e2ad626fSUlf Hansson static const struct rockchip_domain_info rk3066_pm_domains[] = {
998*e2ad626fSUlf Hansson 	[RK3066_PD_GPU]		= DOMAIN("gpu",   BIT(9), BIT(9), BIT(3), BIT(24), BIT(29), false),
999*e2ad626fSUlf Hansson 	[RK3066_PD_VIDEO]	= DOMAIN("video", BIT(8), BIT(8), BIT(4), BIT(23), BIT(28), false),
1000*e2ad626fSUlf Hansson 	[RK3066_PD_VIO]		= DOMAIN("vio",   BIT(7), BIT(7), BIT(5), BIT(22), BIT(27), false),
1001*e2ad626fSUlf Hansson 	[RK3066_PD_PERI]	= DOMAIN("peri",  BIT(6), BIT(6), BIT(2), BIT(25), BIT(30), false),
1002*e2ad626fSUlf Hansson 	[RK3066_PD_CPU]		= DOMAIN("cpu",   0,      BIT(5), BIT(1), BIT(26), BIT(31), false),
1003*e2ad626fSUlf Hansson };
1004*e2ad626fSUlf Hansson 
1005*e2ad626fSUlf Hansson static const struct rockchip_domain_info rk3128_pm_domains[] = {
1006*e2ad626fSUlf Hansson 	[RK3128_PD_CORE]	= DOMAIN_RK3288("core",  BIT(0), BIT(0), BIT(4), false),
1007*e2ad626fSUlf Hansson 	[RK3128_PD_MSCH]	= DOMAIN_RK3288("msch",  0,      0,      BIT(6), true),
1008*e2ad626fSUlf Hansson 	[RK3128_PD_VIO]		= DOMAIN_RK3288("vio",   BIT(3), BIT(3), BIT(2), false),
1009*e2ad626fSUlf Hansson 	[RK3128_PD_VIDEO]	= DOMAIN_RK3288("video", BIT(2), BIT(2), BIT(1), false),
1010*e2ad626fSUlf Hansson 	[RK3128_PD_GPU]		= DOMAIN_RK3288("gpu",   BIT(1), BIT(1), BIT(3), false),
1011*e2ad626fSUlf Hansson };
1012*e2ad626fSUlf Hansson 
1013*e2ad626fSUlf Hansson static const struct rockchip_domain_info rk3188_pm_domains[] = {
1014*e2ad626fSUlf Hansson 	[RK3188_PD_GPU]		= DOMAIN("gpu",   BIT(9), BIT(9), BIT(3), BIT(24), BIT(29), false),
1015*e2ad626fSUlf Hansson 	[RK3188_PD_VIDEO]	= DOMAIN("video", BIT(8), BIT(8), BIT(4), BIT(23), BIT(28), false),
1016*e2ad626fSUlf Hansson 	[RK3188_PD_VIO]		= DOMAIN("vio",   BIT(7), BIT(7), BIT(5), BIT(22), BIT(27), false),
1017*e2ad626fSUlf Hansson 	[RK3188_PD_PERI]	= DOMAIN("peri",  BIT(6), BIT(6), BIT(2), BIT(25), BIT(30), false),
1018*e2ad626fSUlf Hansson 	[RK3188_PD_CPU]		= DOMAIN("cpu",   BIT(5), BIT(5), BIT(1), BIT(26), BIT(31), false),
1019*e2ad626fSUlf Hansson };
1020*e2ad626fSUlf Hansson 
1021*e2ad626fSUlf Hansson static const struct rockchip_domain_info rk3228_pm_domains[] = {
1022*e2ad626fSUlf Hansson 	[RK3228_PD_CORE]	= DOMAIN_RK3036("core", BIT(0),  BIT(0),  BIT(16), true),
1023*e2ad626fSUlf Hansson 	[RK3228_PD_MSCH]	= DOMAIN_RK3036("msch", BIT(1),  BIT(1),  BIT(17), true),
1024*e2ad626fSUlf Hansson 	[RK3228_PD_BUS]		= DOMAIN_RK3036("bus",  BIT(2),  BIT(2),  BIT(18), true),
1025*e2ad626fSUlf Hansson 	[RK3228_PD_SYS]		= DOMAIN_RK3036("sys",  BIT(3),  BIT(3),  BIT(19), true),
1026*e2ad626fSUlf Hansson 	[RK3228_PD_VIO]		= DOMAIN_RK3036("vio",  BIT(4),  BIT(4),  BIT(20), false),
1027*e2ad626fSUlf Hansson 	[RK3228_PD_VOP]		= DOMAIN_RK3036("vop",  BIT(5),  BIT(5),  BIT(21), false),
1028*e2ad626fSUlf Hansson 	[RK3228_PD_VPU]		= DOMAIN_RK3036("vpu",  BIT(6),  BIT(6),  BIT(22), false),
1029*e2ad626fSUlf Hansson 	[RK3228_PD_RKVDEC]	= DOMAIN_RK3036("vdec", BIT(7),  BIT(7),  BIT(23), false),
1030*e2ad626fSUlf Hansson 	[RK3228_PD_GPU]		= DOMAIN_RK3036("gpu",  BIT(8),  BIT(8),  BIT(24), false),
1031*e2ad626fSUlf Hansson 	[RK3228_PD_PERI]	= DOMAIN_RK3036("peri", BIT(9),  BIT(9),  BIT(25), true),
1032*e2ad626fSUlf Hansson 	[RK3228_PD_GMAC]	= DOMAIN_RK3036("gmac", BIT(10), BIT(10), BIT(26), false),
1033*e2ad626fSUlf Hansson };
1034*e2ad626fSUlf Hansson 
1035*e2ad626fSUlf Hansson static const struct rockchip_domain_info rk3288_pm_domains[] = {
1036*e2ad626fSUlf Hansson 	[RK3288_PD_VIO]		= DOMAIN_RK3288("vio",   BIT(7),  BIT(7),  BIT(4), false),
1037*e2ad626fSUlf Hansson 	[RK3288_PD_HEVC]	= DOMAIN_RK3288("hevc",  BIT(14), BIT(10), BIT(9), false),
1038*e2ad626fSUlf Hansson 	[RK3288_PD_VIDEO]	= DOMAIN_RK3288("video", BIT(8),  BIT(8),  BIT(3), false),
1039*e2ad626fSUlf Hansson 	[RK3288_PD_GPU]		= DOMAIN_RK3288("gpu",   BIT(9),  BIT(9),  BIT(2), false),
1040*e2ad626fSUlf Hansson };
1041*e2ad626fSUlf Hansson 
1042*e2ad626fSUlf Hansson static const struct rockchip_domain_info rk3328_pm_domains[] = {
1043*e2ad626fSUlf Hansson 	[RK3328_PD_CORE]	= DOMAIN_RK3328("core",  0, BIT(0), BIT(0), false),
1044*e2ad626fSUlf Hansson 	[RK3328_PD_GPU]		= DOMAIN_RK3328("gpu",   0, BIT(1), BIT(1), false),
1045*e2ad626fSUlf Hansson 	[RK3328_PD_BUS]		= DOMAIN_RK3328("bus",   0, BIT(2), BIT(2), true),
1046*e2ad626fSUlf Hansson 	[RK3328_PD_MSCH]	= DOMAIN_RK3328("msch",  0, BIT(3), BIT(3), true),
1047*e2ad626fSUlf Hansson 	[RK3328_PD_PERI]	= DOMAIN_RK3328("peri",  0, BIT(4), BIT(4), true),
1048*e2ad626fSUlf Hansson 	[RK3328_PD_VIDEO]	= DOMAIN_RK3328("video", 0, BIT(5), BIT(5), false),
1049*e2ad626fSUlf Hansson 	[RK3328_PD_HEVC]	= DOMAIN_RK3328("hevc",  0, BIT(6), BIT(6), false),
1050*e2ad626fSUlf Hansson 	[RK3328_PD_VIO]		= DOMAIN_RK3328("vio",   0, BIT(8), BIT(8), false),
1051*e2ad626fSUlf Hansson 	[RK3328_PD_VPU]		= DOMAIN_RK3328("vpu",   0, BIT(9), BIT(9), false),
1052*e2ad626fSUlf Hansson };
1053*e2ad626fSUlf Hansson 
1054*e2ad626fSUlf Hansson static const struct rockchip_domain_info rk3366_pm_domains[] = {
1055*e2ad626fSUlf Hansson 	[RK3366_PD_PERI]	= DOMAIN_RK3368("peri",   BIT(10), BIT(10), BIT(6), true),
1056*e2ad626fSUlf Hansson 	[RK3366_PD_VIO]		= DOMAIN_RK3368("vio",    BIT(14), BIT(14), BIT(8), false),
1057*e2ad626fSUlf Hansson 	[RK3366_PD_VIDEO]	= DOMAIN_RK3368("video",  BIT(13), BIT(13), BIT(7), false),
1058*e2ad626fSUlf Hansson 	[RK3366_PD_RKVDEC]	= DOMAIN_RK3368("vdec",   BIT(11), BIT(11), BIT(7), false),
1059*e2ad626fSUlf Hansson 	[RK3366_PD_WIFIBT]	= DOMAIN_RK3368("wifibt", BIT(8),  BIT(8),  BIT(9), false),
1060*e2ad626fSUlf Hansson 	[RK3366_PD_VPU]		= DOMAIN_RK3368("vpu",    BIT(12), BIT(12), BIT(7), false),
1061*e2ad626fSUlf Hansson 	[RK3366_PD_GPU]		= DOMAIN_RK3368("gpu",    BIT(15), BIT(15), BIT(2), false),
1062*e2ad626fSUlf Hansson };
1063*e2ad626fSUlf Hansson 
1064*e2ad626fSUlf Hansson static const struct rockchip_domain_info rk3368_pm_domains[] = {
1065*e2ad626fSUlf Hansson 	[RK3368_PD_PERI]	= DOMAIN_RK3368("peri",  BIT(13), BIT(12), BIT(6), true),
1066*e2ad626fSUlf Hansson 	[RK3368_PD_VIO]		= DOMAIN_RK3368("vio",   BIT(15), BIT(14), BIT(8), false),
1067*e2ad626fSUlf Hansson 	[RK3368_PD_VIDEO]	= DOMAIN_RK3368("video", BIT(14), BIT(13), BIT(7), false),
1068*e2ad626fSUlf Hansson 	[RK3368_PD_GPU_0]	= DOMAIN_RK3368("gpu_0", BIT(16), BIT(15), BIT(2), false),
1069*e2ad626fSUlf Hansson 	[RK3368_PD_GPU_1]	= DOMAIN_RK3368("gpu_1", BIT(17), BIT(16), BIT(2), false),
1070*e2ad626fSUlf Hansson };
1071*e2ad626fSUlf Hansson 
1072*e2ad626fSUlf Hansson static const struct rockchip_domain_info rk3399_pm_domains[] = {
1073*e2ad626fSUlf Hansson 	[RK3399_PD_TCPD0]	= DOMAIN_RK3399("tcpd0",     BIT(8),  BIT(8),  0,       false),
1074*e2ad626fSUlf Hansson 	[RK3399_PD_TCPD1]	= DOMAIN_RK3399("tcpd1",     BIT(9),  BIT(9),  0,       false),
1075*e2ad626fSUlf Hansson 	[RK3399_PD_CCI]		= DOMAIN_RK3399("cci",       BIT(10), BIT(10), 0,       true),
1076*e2ad626fSUlf Hansson 	[RK3399_PD_CCI0]	= DOMAIN_RK3399("cci0",      0,       0,       BIT(15), true),
1077*e2ad626fSUlf Hansson 	[RK3399_PD_CCI1]	= DOMAIN_RK3399("cci1",      0,       0,       BIT(16), true),
1078*e2ad626fSUlf Hansson 	[RK3399_PD_PERILP]	= DOMAIN_RK3399("perilp",    BIT(11), BIT(11), BIT(1),  true),
1079*e2ad626fSUlf Hansson 	[RK3399_PD_PERIHP]	= DOMAIN_RK3399("perihp",    BIT(12), BIT(12), BIT(2),  true),
1080*e2ad626fSUlf Hansson 	[RK3399_PD_CENTER]	= DOMAIN_RK3399("center",    BIT(13), BIT(13), BIT(14), true),
1081*e2ad626fSUlf Hansson 	[RK3399_PD_VIO]		= DOMAIN_RK3399("vio",       BIT(14), BIT(14), BIT(17), false),
1082*e2ad626fSUlf Hansson 	[RK3399_PD_GPU]		= DOMAIN_RK3399("gpu",       BIT(15), BIT(15), BIT(0),  false),
1083*e2ad626fSUlf Hansson 	[RK3399_PD_VCODEC]	= DOMAIN_RK3399("vcodec",    BIT(16), BIT(16), BIT(3),  false),
1084*e2ad626fSUlf Hansson 	[RK3399_PD_VDU]		= DOMAIN_RK3399("vdu",       BIT(17), BIT(17), BIT(4),  false),
1085*e2ad626fSUlf Hansson 	[RK3399_PD_RGA]		= DOMAIN_RK3399("rga",       BIT(18), BIT(18), BIT(5),  false),
1086*e2ad626fSUlf Hansson 	[RK3399_PD_IEP]		= DOMAIN_RK3399("iep",       BIT(19), BIT(19), BIT(6),  false),
1087*e2ad626fSUlf Hansson 	[RK3399_PD_VO]		= DOMAIN_RK3399("vo",        BIT(20), BIT(20), 0,       false),
1088*e2ad626fSUlf Hansson 	[RK3399_PD_VOPB]	= DOMAIN_RK3399("vopb",      0,       0,       BIT(7),  false),
1089*e2ad626fSUlf Hansson 	[RK3399_PD_VOPL]	= DOMAIN_RK3399("vopl",      0,       0,       BIT(8),  false),
1090*e2ad626fSUlf Hansson 	[RK3399_PD_ISP0]	= DOMAIN_RK3399("isp0",      BIT(22), BIT(22), BIT(9),  false),
1091*e2ad626fSUlf Hansson 	[RK3399_PD_ISP1]	= DOMAIN_RK3399("isp1",      BIT(23), BIT(23), BIT(10), false),
1092*e2ad626fSUlf Hansson 	[RK3399_PD_HDCP]	= DOMAIN_RK3399("hdcp",      BIT(24), BIT(24), BIT(11), false),
1093*e2ad626fSUlf Hansson 	[RK3399_PD_GMAC]	= DOMAIN_RK3399("gmac",      BIT(25), BIT(25), BIT(23), true),
1094*e2ad626fSUlf Hansson 	[RK3399_PD_EMMC]	= DOMAIN_RK3399("emmc",      BIT(26), BIT(26), BIT(24), true),
1095*e2ad626fSUlf Hansson 	[RK3399_PD_USB3]	= DOMAIN_RK3399("usb3",      BIT(27), BIT(27), BIT(12), true),
1096*e2ad626fSUlf Hansson 	[RK3399_PD_EDP]		= DOMAIN_RK3399("edp",       BIT(28), BIT(28), BIT(22), false),
1097*e2ad626fSUlf Hansson 	[RK3399_PD_GIC]		= DOMAIN_RK3399("gic",       BIT(29), BIT(29), BIT(27), true),
1098*e2ad626fSUlf Hansson 	[RK3399_PD_SD]		= DOMAIN_RK3399("sd",        BIT(30), BIT(30), BIT(28), true),
1099*e2ad626fSUlf Hansson 	[RK3399_PD_SDIOAUDIO]	= DOMAIN_RK3399("sdioaudio", BIT(31), BIT(31), BIT(29), true),
1100*e2ad626fSUlf Hansson };
1101*e2ad626fSUlf Hansson 
1102*e2ad626fSUlf Hansson static const struct rockchip_domain_info rk3568_pm_domains[] = {
1103*e2ad626fSUlf Hansson 	[RK3568_PD_NPU]		= DOMAIN_RK3568("npu",  BIT(1), BIT(2),  false),
1104*e2ad626fSUlf Hansson 	[RK3568_PD_GPU]		= DOMAIN_RK3568("gpu",  BIT(0), BIT(1),  false),
1105*e2ad626fSUlf Hansson 	[RK3568_PD_VI]		= DOMAIN_RK3568("vi",   BIT(6), BIT(3),  false),
1106*e2ad626fSUlf Hansson 	[RK3568_PD_VO]		= DOMAIN_RK3568("vo",   BIT(7), BIT(4),  false),
1107*e2ad626fSUlf Hansson 	[RK3568_PD_RGA]		= DOMAIN_RK3568("rga",  BIT(5), BIT(5),  false),
1108*e2ad626fSUlf Hansson 	[RK3568_PD_VPU]		= DOMAIN_RK3568("vpu",  BIT(2), BIT(6),  false),
1109*e2ad626fSUlf Hansson 	[RK3568_PD_RKVDEC]	= DOMAIN_RK3568("vdec", BIT(4), BIT(8),  false),
1110*e2ad626fSUlf Hansson 	[RK3568_PD_RKVENC]	= DOMAIN_RK3568("venc", BIT(3), BIT(7),  false),
1111*e2ad626fSUlf Hansson 	[RK3568_PD_PIPE]	= DOMAIN_RK3568("pipe", BIT(8), BIT(11), false),
1112*e2ad626fSUlf Hansson };
1113*e2ad626fSUlf Hansson 
1114*e2ad626fSUlf Hansson static const struct rockchip_domain_info rk3588_pm_domains[] = {
1115*e2ad626fSUlf Hansson 	[RK3588_PD_GPU]		= DOMAIN_RK3588("gpu",     0x0, BIT(0),  0,       0x0, 0,       BIT(1),  0x0, BIT(0),  BIT(0),  false),
1116*e2ad626fSUlf Hansson 	[RK3588_PD_NPU]		= DOMAIN_RK3588("npu",     0x0, BIT(1),  BIT(1),  0x0, 0,       0,       0x0, 0,       0,       false),
1117*e2ad626fSUlf Hansson 	[RK3588_PD_VCODEC]	= DOMAIN_RK3588("vcodec",  0x0, BIT(2),  BIT(2),  0x0, 0,       0,       0x0, 0,       0,       false),
1118*e2ad626fSUlf Hansson 	[RK3588_PD_NPUTOP]	= DOMAIN_RK3588("nputop",  0x0, BIT(3),  0,       0x0, BIT(11), BIT(2),  0x0, BIT(1),  BIT(1),  false),
1119*e2ad626fSUlf Hansson 	[RK3588_PD_NPU1]	= DOMAIN_RK3588("npu1",    0x0, BIT(4),  0,       0x0, BIT(12), BIT(3),  0x0, BIT(2),  BIT(2),  false),
1120*e2ad626fSUlf Hansson 	[RK3588_PD_NPU2]	= DOMAIN_RK3588("npu2",    0x0, BIT(5),  0,       0x0, BIT(13), BIT(4),  0x0, BIT(3),  BIT(3),  false),
1121*e2ad626fSUlf Hansson 	[RK3588_PD_VENC0]	= DOMAIN_RK3588("venc0",   0x0, BIT(6),  0,       0x0, BIT(14), BIT(5),  0x0, BIT(4),  BIT(4),  false),
1122*e2ad626fSUlf Hansson 	[RK3588_PD_VENC1]	= DOMAIN_RK3588("venc1",   0x0, BIT(7),  0,       0x0, BIT(15), BIT(6),  0x0, BIT(5),  BIT(5),  false),
1123*e2ad626fSUlf Hansson 	[RK3588_PD_RKVDEC0]	= DOMAIN_RK3588("rkvdec0", 0x0, BIT(8),  0,       0x0, BIT(16), BIT(7),  0x0, BIT(6),  BIT(6),  false),
1124*e2ad626fSUlf Hansson 	[RK3588_PD_RKVDEC1]	= DOMAIN_RK3588("rkvdec1", 0x0, BIT(9),  0,       0x0, BIT(17), BIT(8),  0x0, BIT(7),  BIT(7),  false),
1125*e2ad626fSUlf Hansson 	[RK3588_PD_VDPU]	= DOMAIN_RK3588("vdpu",    0x0, BIT(10), 0,       0x0, BIT(18), BIT(9),  0x0, BIT(8),  BIT(8),  false),
1126*e2ad626fSUlf Hansson 	[RK3588_PD_RGA30]	= DOMAIN_RK3588("rga30",   0x0, BIT(11), 0,       0x0, BIT(19), BIT(10), 0x0, 0,       0,       false),
1127*e2ad626fSUlf Hansson 	[RK3588_PD_AV1]		= DOMAIN_RK3588("av1",     0x0, BIT(12), 0,       0x0, BIT(20), BIT(11), 0x0, BIT(9),  BIT(9),  false),
1128*e2ad626fSUlf Hansson 	[RK3588_PD_VI]		= DOMAIN_RK3588("vi",      0x0, BIT(13), 0,       0x0, BIT(21), BIT(12), 0x0, BIT(10), BIT(10), false),
1129*e2ad626fSUlf Hansson 	[RK3588_PD_FEC]		= DOMAIN_RK3588("fec",     0x0, BIT(14), 0,       0x0, BIT(22), BIT(13), 0x0, 0,       0,       false),
1130*e2ad626fSUlf Hansson 	[RK3588_PD_ISP1]	= DOMAIN_RK3588("isp1",    0x0, BIT(15), 0,       0x0, BIT(23), BIT(14), 0x0, BIT(11), BIT(11), false),
1131*e2ad626fSUlf Hansson 	[RK3588_PD_RGA31]	= DOMAIN_RK3588("rga31",   0x4, BIT(0),  0,       0x0, BIT(24), BIT(15), 0x0, BIT(12), BIT(12), false),
1132*e2ad626fSUlf Hansson 	[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),
1133*e2ad626fSUlf Hansson 	[RK3588_PD_VO0]		= DOMAIN_RK3588("vo0",     0x4, BIT(2),  0,       0x0, BIT(26), BIT(17), 0x0, BIT(15), BIT(15), false),
1134*e2ad626fSUlf Hansson 	[RK3588_PD_VO1]		= DOMAIN_RK3588("vo1",     0x4, BIT(3),  0,       0x0, BIT(27), BIT(18), 0x4, BIT(0),  BIT(16), false),
1135*e2ad626fSUlf Hansson 	[RK3588_PD_AUDIO]	= DOMAIN_RK3588("audio",   0x4, BIT(4),  0,       0x0, BIT(28), BIT(19), 0x4, BIT(1),  BIT(17), false),
1136*e2ad626fSUlf Hansson 	[RK3588_PD_PHP]		= DOMAIN_RK3588("php",     0x4, BIT(5),  0,       0x0, BIT(29), BIT(20), 0x4, BIT(5),  BIT(21), false),
1137*e2ad626fSUlf Hansson 	[RK3588_PD_GMAC]	= DOMAIN_RK3588("gmac",    0x4, BIT(6),  0,       0x0, BIT(30), BIT(21), 0x0, 0,       0,       false),
1138*e2ad626fSUlf Hansson 	[RK3588_PD_PCIE]	= DOMAIN_RK3588("pcie",    0x4, BIT(7),  0,       0x0, BIT(31), BIT(22), 0x0, 0,       0,       true),
1139*e2ad626fSUlf Hansson 	[RK3588_PD_NVM]		= DOMAIN_RK3588("nvm",     0x4, BIT(8),  BIT(24), 0x4, 0,       0,       0x4, BIT(2),  BIT(18), false),
1140*e2ad626fSUlf Hansson 	[RK3588_PD_NVM0]	= DOMAIN_RK3588("nvm0",    0x4, BIT(9),  0,       0x4, BIT(1),  BIT(23), 0x0, 0,       0,       false),
1141*e2ad626fSUlf Hansson 	[RK3588_PD_SDIO]	= DOMAIN_RK3588("sdio",    0x4, BIT(10), 0,       0x4, BIT(2),  BIT(24), 0x4, BIT(3),  BIT(19), false),
1142*e2ad626fSUlf Hansson 	[RK3588_PD_USB]		= DOMAIN_RK3588("usb",     0x4, BIT(11), 0,       0x4, BIT(3),  BIT(25), 0x4, BIT(4),  BIT(20), true),
1143*e2ad626fSUlf Hansson 	[RK3588_PD_SDMMC]	= DOMAIN_RK3588("sdmmc",   0x4, BIT(13), 0,       0x4, BIT(5),  BIT(26), 0x0, 0,       0,       false),
1144*e2ad626fSUlf Hansson };
1145*e2ad626fSUlf Hansson 
1146*e2ad626fSUlf Hansson static const struct rockchip_pmu_info px30_pmu = {
1147*e2ad626fSUlf Hansson 	.pwr_offset = 0x18,
1148*e2ad626fSUlf Hansson 	.status_offset = 0x20,
1149*e2ad626fSUlf Hansson 	.req_offset = 0x64,
1150*e2ad626fSUlf Hansson 	.idle_offset = 0x6c,
1151*e2ad626fSUlf Hansson 	.ack_offset = 0x6c,
1152*e2ad626fSUlf Hansson 
1153*e2ad626fSUlf Hansson 	.num_domains = ARRAY_SIZE(px30_pm_domains),
1154*e2ad626fSUlf Hansson 	.domain_info = px30_pm_domains,
1155*e2ad626fSUlf Hansson };
1156*e2ad626fSUlf Hansson 
1157*e2ad626fSUlf Hansson static const struct rockchip_pmu_info rk3036_pmu = {
1158*e2ad626fSUlf Hansson 	.req_offset = 0x148,
1159*e2ad626fSUlf Hansson 	.idle_offset = 0x14c,
1160*e2ad626fSUlf Hansson 	.ack_offset = 0x14c,
1161*e2ad626fSUlf Hansson 
1162*e2ad626fSUlf Hansson 	.num_domains = ARRAY_SIZE(rk3036_pm_domains),
1163*e2ad626fSUlf Hansson 	.domain_info = rk3036_pm_domains,
1164*e2ad626fSUlf Hansson };
1165*e2ad626fSUlf Hansson 
1166*e2ad626fSUlf Hansson static const struct rockchip_pmu_info rk3066_pmu = {
1167*e2ad626fSUlf Hansson 	.pwr_offset = 0x08,
1168*e2ad626fSUlf Hansson 	.status_offset = 0x0c,
1169*e2ad626fSUlf Hansson 	.req_offset = 0x38, /* PMU_MISC_CON1 */
1170*e2ad626fSUlf Hansson 	.idle_offset = 0x0c,
1171*e2ad626fSUlf Hansson 	.ack_offset = 0x0c,
1172*e2ad626fSUlf Hansson 
1173*e2ad626fSUlf Hansson 	.num_domains = ARRAY_SIZE(rk3066_pm_domains),
1174*e2ad626fSUlf Hansson 	.domain_info = rk3066_pm_domains,
1175*e2ad626fSUlf Hansson };
1176*e2ad626fSUlf Hansson 
1177*e2ad626fSUlf Hansson static const struct rockchip_pmu_info rk3128_pmu = {
1178*e2ad626fSUlf Hansson 	.pwr_offset = 0x04,
1179*e2ad626fSUlf Hansson 	.status_offset = 0x08,
1180*e2ad626fSUlf Hansson 	.req_offset = 0x0c,
1181*e2ad626fSUlf Hansson 	.idle_offset = 0x10,
1182*e2ad626fSUlf Hansson 	.ack_offset = 0x10,
1183*e2ad626fSUlf Hansson 
1184*e2ad626fSUlf Hansson 	.num_domains = ARRAY_SIZE(rk3128_pm_domains),
1185*e2ad626fSUlf Hansson 	.domain_info = rk3128_pm_domains,
1186*e2ad626fSUlf Hansson };
1187*e2ad626fSUlf Hansson 
1188*e2ad626fSUlf Hansson static const struct rockchip_pmu_info rk3188_pmu = {
1189*e2ad626fSUlf Hansson 	.pwr_offset = 0x08,
1190*e2ad626fSUlf Hansson 	.status_offset = 0x0c,
1191*e2ad626fSUlf Hansson 	.req_offset = 0x38, /* PMU_MISC_CON1 */
1192*e2ad626fSUlf Hansson 	.idle_offset = 0x0c,
1193*e2ad626fSUlf Hansson 	.ack_offset = 0x0c,
1194*e2ad626fSUlf Hansson 
1195*e2ad626fSUlf Hansson 	.num_domains = ARRAY_SIZE(rk3188_pm_domains),
1196*e2ad626fSUlf Hansson 	.domain_info = rk3188_pm_domains,
1197*e2ad626fSUlf Hansson };
1198*e2ad626fSUlf Hansson 
1199*e2ad626fSUlf Hansson static const struct rockchip_pmu_info rk3228_pmu = {
1200*e2ad626fSUlf Hansson 	.req_offset = 0x40c,
1201*e2ad626fSUlf Hansson 	.idle_offset = 0x488,
1202*e2ad626fSUlf Hansson 	.ack_offset = 0x488,
1203*e2ad626fSUlf Hansson 
1204*e2ad626fSUlf Hansson 	.num_domains = ARRAY_SIZE(rk3228_pm_domains),
1205*e2ad626fSUlf Hansson 	.domain_info = rk3228_pm_domains,
1206*e2ad626fSUlf Hansson };
1207*e2ad626fSUlf Hansson 
1208*e2ad626fSUlf Hansson static const struct rockchip_pmu_info rk3288_pmu = {
1209*e2ad626fSUlf Hansson 	.pwr_offset = 0x08,
1210*e2ad626fSUlf Hansson 	.status_offset = 0x0c,
1211*e2ad626fSUlf Hansson 	.req_offset = 0x10,
1212*e2ad626fSUlf Hansson 	.idle_offset = 0x14,
1213*e2ad626fSUlf Hansson 	.ack_offset = 0x14,
1214*e2ad626fSUlf Hansson 
1215*e2ad626fSUlf Hansson 	.core_pwrcnt_offset = 0x34,
1216*e2ad626fSUlf Hansson 	.gpu_pwrcnt_offset = 0x3c,
1217*e2ad626fSUlf Hansson 
1218*e2ad626fSUlf Hansson 	.core_power_transition_time = 24, /* 1us */
1219*e2ad626fSUlf Hansson 	.gpu_power_transition_time = 24, /* 1us */
1220*e2ad626fSUlf Hansson 
1221*e2ad626fSUlf Hansson 	.num_domains = ARRAY_SIZE(rk3288_pm_domains),
1222*e2ad626fSUlf Hansson 	.domain_info = rk3288_pm_domains,
1223*e2ad626fSUlf Hansson };
1224*e2ad626fSUlf Hansson 
1225*e2ad626fSUlf Hansson static const struct rockchip_pmu_info rk3328_pmu = {
1226*e2ad626fSUlf Hansson 	.req_offset = 0x414,
1227*e2ad626fSUlf Hansson 	.idle_offset = 0x484,
1228*e2ad626fSUlf Hansson 	.ack_offset = 0x484,
1229*e2ad626fSUlf Hansson 
1230*e2ad626fSUlf Hansson 	.num_domains = ARRAY_SIZE(rk3328_pm_domains),
1231*e2ad626fSUlf Hansson 	.domain_info = rk3328_pm_domains,
1232*e2ad626fSUlf Hansson };
1233*e2ad626fSUlf Hansson 
1234*e2ad626fSUlf Hansson static const struct rockchip_pmu_info rk3366_pmu = {
1235*e2ad626fSUlf Hansson 	.pwr_offset = 0x0c,
1236*e2ad626fSUlf Hansson 	.status_offset = 0x10,
1237*e2ad626fSUlf Hansson 	.req_offset = 0x3c,
1238*e2ad626fSUlf Hansson 	.idle_offset = 0x40,
1239*e2ad626fSUlf Hansson 	.ack_offset = 0x40,
1240*e2ad626fSUlf Hansson 
1241*e2ad626fSUlf Hansson 	.core_pwrcnt_offset = 0x48,
1242*e2ad626fSUlf Hansson 	.gpu_pwrcnt_offset = 0x50,
1243*e2ad626fSUlf Hansson 
1244*e2ad626fSUlf Hansson 	.core_power_transition_time = 24,
1245*e2ad626fSUlf Hansson 	.gpu_power_transition_time = 24,
1246*e2ad626fSUlf Hansson 
1247*e2ad626fSUlf Hansson 	.num_domains = ARRAY_SIZE(rk3366_pm_domains),
1248*e2ad626fSUlf Hansson 	.domain_info = rk3366_pm_domains,
1249*e2ad626fSUlf Hansson };
1250*e2ad626fSUlf Hansson 
1251*e2ad626fSUlf Hansson static const struct rockchip_pmu_info rk3368_pmu = {
1252*e2ad626fSUlf Hansson 	.pwr_offset = 0x0c,
1253*e2ad626fSUlf Hansson 	.status_offset = 0x10,
1254*e2ad626fSUlf Hansson 	.req_offset = 0x3c,
1255*e2ad626fSUlf Hansson 	.idle_offset = 0x40,
1256*e2ad626fSUlf Hansson 	.ack_offset = 0x40,
1257*e2ad626fSUlf Hansson 
1258*e2ad626fSUlf Hansson 	.core_pwrcnt_offset = 0x48,
1259*e2ad626fSUlf Hansson 	.gpu_pwrcnt_offset = 0x50,
1260*e2ad626fSUlf Hansson 
1261*e2ad626fSUlf Hansson 	.core_power_transition_time = 24,
1262*e2ad626fSUlf Hansson 	.gpu_power_transition_time = 24,
1263*e2ad626fSUlf Hansson 
1264*e2ad626fSUlf Hansson 	.num_domains = ARRAY_SIZE(rk3368_pm_domains),
1265*e2ad626fSUlf Hansson 	.domain_info = rk3368_pm_domains,
1266*e2ad626fSUlf Hansson };
1267*e2ad626fSUlf Hansson 
1268*e2ad626fSUlf Hansson static const struct rockchip_pmu_info rk3399_pmu = {
1269*e2ad626fSUlf Hansson 	.pwr_offset = 0x14,
1270*e2ad626fSUlf Hansson 	.status_offset = 0x18,
1271*e2ad626fSUlf Hansson 	.req_offset = 0x60,
1272*e2ad626fSUlf Hansson 	.idle_offset = 0x64,
1273*e2ad626fSUlf Hansson 	.ack_offset = 0x68,
1274*e2ad626fSUlf Hansson 
1275*e2ad626fSUlf Hansson 	/* ARM Trusted Firmware manages power transition times */
1276*e2ad626fSUlf Hansson 
1277*e2ad626fSUlf Hansson 	.num_domains = ARRAY_SIZE(rk3399_pm_domains),
1278*e2ad626fSUlf Hansson 	.domain_info = rk3399_pm_domains,
1279*e2ad626fSUlf Hansson };
1280*e2ad626fSUlf Hansson 
1281*e2ad626fSUlf Hansson static const struct rockchip_pmu_info rk3568_pmu = {
1282*e2ad626fSUlf Hansson 	.pwr_offset = 0xa0,
1283*e2ad626fSUlf Hansson 	.status_offset = 0x98,
1284*e2ad626fSUlf Hansson 	.req_offset = 0x50,
1285*e2ad626fSUlf Hansson 	.idle_offset = 0x68,
1286*e2ad626fSUlf Hansson 	.ack_offset = 0x60,
1287*e2ad626fSUlf Hansson 
1288*e2ad626fSUlf Hansson 	.num_domains = ARRAY_SIZE(rk3568_pm_domains),
1289*e2ad626fSUlf Hansson 	.domain_info = rk3568_pm_domains,
1290*e2ad626fSUlf Hansson };
1291*e2ad626fSUlf Hansson 
1292*e2ad626fSUlf Hansson static const struct rockchip_pmu_info rk3588_pmu = {
1293*e2ad626fSUlf Hansson 	.pwr_offset = 0x14c,
1294*e2ad626fSUlf Hansson 	.status_offset = 0x180,
1295*e2ad626fSUlf Hansson 	.req_offset = 0x10c,
1296*e2ad626fSUlf Hansson 	.idle_offset = 0x120,
1297*e2ad626fSUlf Hansson 	.ack_offset = 0x118,
1298*e2ad626fSUlf Hansson 	.mem_pwr_offset = 0x1a0,
1299*e2ad626fSUlf Hansson 	.chain_status_offset = 0x1f0,
1300*e2ad626fSUlf Hansson 	.mem_status_offset = 0x1f8,
1301*e2ad626fSUlf Hansson 	.repair_status_offset = 0x290,
1302*e2ad626fSUlf Hansson 
1303*e2ad626fSUlf Hansson 	.num_domains = ARRAY_SIZE(rk3588_pm_domains),
1304*e2ad626fSUlf Hansson 	.domain_info = rk3588_pm_domains,
1305*e2ad626fSUlf Hansson };
1306*e2ad626fSUlf Hansson 
1307*e2ad626fSUlf Hansson static const struct rockchip_pmu_info rv1126_pmu = {
1308*e2ad626fSUlf Hansson 	.pwr_offset = 0x110,
1309*e2ad626fSUlf Hansson 	.status_offset = 0x108,
1310*e2ad626fSUlf Hansson 	.req_offset = 0xc0,
1311*e2ad626fSUlf Hansson 	.idle_offset = 0xd8,
1312*e2ad626fSUlf Hansson 	.ack_offset = 0xd0,
1313*e2ad626fSUlf Hansson 
1314*e2ad626fSUlf Hansson 	.num_domains = ARRAY_SIZE(rv1126_pm_domains),
1315*e2ad626fSUlf Hansson 	.domain_info = rv1126_pm_domains,
1316*e2ad626fSUlf Hansson };
1317*e2ad626fSUlf Hansson 
1318*e2ad626fSUlf Hansson static const struct of_device_id rockchip_pm_domain_dt_match[] = {
1319*e2ad626fSUlf Hansson 	{
1320*e2ad626fSUlf Hansson 		.compatible = "rockchip,px30-power-controller",
1321*e2ad626fSUlf Hansson 		.data = (void *)&px30_pmu,
1322*e2ad626fSUlf Hansson 	},
1323*e2ad626fSUlf Hansson 	{
1324*e2ad626fSUlf Hansson 		.compatible = "rockchip,rk3036-power-controller",
1325*e2ad626fSUlf Hansson 		.data = (void *)&rk3036_pmu,
1326*e2ad626fSUlf Hansson 	},
1327*e2ad626fSUlf Hansson 	{
1328*e2ad626fSUlf Hansson 		.compatible = "rockchip,rk3066-power-controller",
1329*e2ad626fSUlf Hansson 		.data = (void *)&rk3066_pmu,
1330*e2ad626fSUlf Hansson 	},
1331*e2ad626fSUlf Hansson 	{
1332*e2ad626fSUlf Hansson 		.compatible = "rockchip,rk3128-power-controller",
1333*e2ad626fSUlf Hansson 		.data = (void *)&rk3128_pmu,
1334*e2ad626fSUlf Hansson 	},
1335*e2ad626fSUlf Hansson 	{
1336*e2ad626fSUlf Hansson 		.compatible = "rockchip,rk3188-power-controller",
1337*e2ad626fSUlf Hansson 		.data = (void *)&rk3188_pmu,
1338*e2ad626fSUlf Hansson 	},
1339*e2ad626fSUlf Hansson 	{
1340*e2ad626fSUlf Hansson 		.compatible = "rockchip,rk3228-power-controller",
1341*e2ad626fSUlf Hansson 		.data = (void *)&rk3228_pmu,
1342*e2ad626fSUlf Hansson 	},
1343*e2ad626fSUlf Hansson 	{
1344*e2ad626fSUlf Hansson 		.compatible = "rockchip,rk3288-power-controller",
1345*e2ad626fSUlf Hansson 		.data = (void *)&rk3288_pmu,
1346*e2ad626fSUlf Hansson 	},
1347*e2ad626fSUlf Hansson 	{
1348*e2ad626fSUlf Hansson 		.compatible = "rockchip,rk3328-power-controller",
1349*e2ad626fSUlf Hansson 		.data = (void *)&rk3328_pmu,
1350*e2ad626fSUlf Hansson 	},
1351*e2ad626fSUlf Hansson 	{
1352*e2ad626fSUlf Hansson 		.compatible = "rockchip,rk3366-power-controller",
1353*e2ad626fSUlf Hansson 		.data = (void *)&rk3366_pmu,
1354*e2ad626fSUlf Hansson 	},
1355*e2ad626fSUlf Hansson 	{
1356*e2ad626fSUlf Hansson 		.compatible = "rockchip,rk3368-power-controller",
1357*e2ad626fSUlf Hansson 		.data = (void *)&rk3368_pmu,
1358*e2ad626fSUlf Hansson 	},
1359*e2ad626fSUlf Hansson 	{
1360*e2ad626fSUlf Hansson 		.compatible = "rockchip,rk3399-power-controller",
1361*e2ad626fSUlf Hansson 		.data = (void *)&rk3399_pmu,
1362*e2ad626fSUlf Hansson 	},
1363*e2ad626fSUlf Hansson 	{
1364*e2ad626fSUlf Hansson 		.compatible = "rockchip,rk3568-power-controller",
1365*e2ad626fSUlf Hansson 		.data = (void *)&rk3568_pmu,
1366*e2ad626fSUlf Hansson 	},
1367*e2ad626fSUlf Hansson 	{
1368*e2ad626fSUlf Hansson 		.compatible = "rockchip,rk3588-power-controller",
1369*e2ad626fSUlf Hansson 		.data = (void *)&rk3588_pmu,
1370*e2ad626fSUlf Hansson 	},
1371*e2ad626fSUlf Hansson 	{
1372*e2ad626fSUlf Hansson 		.compatible = "rockchip,rv1126-power-controller",
1373*e2ad626fSUlf Hansson 		.data = (void *)&rv1126_pmu,
1374*e2ad626fSUlf Hansson 	},
1375*e2ad626fSUlf Hansson 	{ /* sentinel */ },
1376*e2ad626fSUlf Hansson };
1377*e2ad626fSUlf Hansson 
1378*e2ad626fSUlf Hansson static struct platform_driver rockchip_pm_domain_driver = {
1379*e2ad626fSUlf Hansson 	.probe = rockchip_pm_domain_probe,
1380*e2ad626fSUlf Hansson 	.driver = {
1381*e2ad626fSUlf Hansson 		.name   = "rockchip-pm-domain",
1382*e2ad626fSUlf Hansson 		.of_match_table = rockchip_pm_domain_dt_match,
1383*e2ad626fSUlf Hansson 		/*
1384*e2ad626fSUlf Hansson 		 * We can't forcibly eject devices from the power
1385*e2ad626fSUlf Hansson 		 * domain, so we can't really remove power domains
1386*e2ad626fSUlf Hansson 		 * once they were added.
1387*e2ad626fSUlf Hansson 		 */
1388*e2ad626fSUlf Hansson 		.suppress_bind_attrs = true,
1389*e2ad626fSUlf Hansson 	},
1390*e2ad626fSUlf Hansson };
1391*e2ad626fSUlf Hansson 
1392*e2ad626fSUlf Hansson static int __init rockchip_pm_domain_drv_register(void)
1393*e2ad626fSUlf Hansson {
1394*e2ad626fSUlf Hansson 	return platform_driver_register(&rockchip_pm_domain_driver);
1395*e2ad626fSUlf Hansson }
1396*e2ad626fSUlf Hansson postcore_initcall(rockchip_pm_domain_drv_register);
1397