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