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