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