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