Lines Matching full:pd

142 static bool rockchip_pmu_domain_is_idle(struct rockchip_pm_domain *pd)  in rockchip_pmu_domain_is_idle()  argument
144 struct rockchip_pmu *pmu = pd->pmu; in rockchip_pmu_domain_is_idle()
145 const struct rockchip_domain_info *pd_info = pd->info; in rockchip_pmu_domain_is_idle()
160 static int rockchip_pmu_set_idle_request(struct rockchip_pm_domain *pd, in rockchip_pmu_set_idle_request() argument
163 const struct rockchip_domain_info *pd_info = pd->info; in rockchip_pmu_set_idle_request()
164 struct generic_pm_domain *genpd = &pd->genpd; in rockchip_pmu_set_idle_request()
165 struct rockchip_pmu *pmu = pd->pmu; in rockchip_pmu_set_idle_request()
195 ret = readx_poll_timeout_atomic(rockchip_pmu_domain_is_idle, pd, in rockchip_pmu_set_idle_request()
207 static int rockchip_pmu_save_qos(struct rockchip_pm_domain *pd) in rockchip_pmu_save_qos() argument
211 for (i = 0; i < pd->num_qos; i++) { in rockchip_pmu_save_qos()
212 regmap_read(pd->qos_regmap[i], in rockchip_pmu_save_qos()
214 &pd->qos_save_regs[0][i]); in rockchip_pmu_save_qos()
215 regmap_read(pd->qos_regmap[i], in rockchip_pmu_save_qos()
217 &pd->qos_save_regs[1][i]); in rockchip_pmu_save_qos()
218 regmap_read(pd->qos_regmap[i], in rockchip_pmu_save_qos()
220 &pd->qos_save_regs[2][i]); in rockchip_pmu_save_qos()
221 regmap_read(pd->qos_regmap[i], in rockchip_pmu_save_qos()
223 &pd->qos_save_regs[3][i]); in rockchip_pmu_save_qos()
224 regmap_read(pd->qos_regmap[i], in rockchip_pmu_save_qos()
226 &pd->qos_save_regs[4][i]); in rockchip_pmu_save_qos()
231 static int rockchip_pmu_restore_qos(struct rockchip_pm_domain *pd) in rockchip_pmu_restore_qos() argument
235 for (i = 0; i < pd->num_qos; i++) { in rockchip_pmu_restore_qos()
236 regmap_write(pd->qos_regmap[i], in rockchip_pmu_restore_qos()
238 pd->qos_save_regs[0][i]); in rockchip_pmu_restore_qos()
239 regmap_write(pd->qos_regmap[i], in rockchip_pmu_restore_qos()
241 pd->qos_save_regs[1][i]); in rockchip_pmu_restore_qos()
242 regmap_write(pd->qos_regmap[i], in rockchip_pmu_restore_qos()
244 pd->qos_save_regs[2][i]); in rockchip_pmu_restore_qos()
245 regmap_write(pd->qos_regmap[i], in rockchip_pmu_restore_qos()
247 pd->qos_save_regs[3][i]); in rockchip_pmu_restore_qos()
248 regmap_write(pd->qos_regmap[i], in rockchip_pmu_restore_qos()
250 pd->qos_save_regs[4][i]); in rockchip_pmu_restore_qos()
256 static bool rockchip_pmu_domain_is_on(struct rockchip_pm_domain *pd) in rockchip_pmu_domain_is_on() argument
258 struct rockchip_pmu *pmu = pd->pmu; in rockchip_pmu_domain_is_on()
262 if (pd->info->status_mask == 0) in rockchip_pmu_domain_is_on()
263 return !rockchip_pmu_domain_is_idle(pd); in rockchip_pmu_domain_is_on()
268 return !(val & pd->info->status_mask); in rockchip_pmu_domain_is_on()
271 static void rockchip_do_pmu_set_power_domain(struct rockchip_pm_domain *pd, in rockchip_do_pmu_set_power_domain() argument
274 struct rockchip_pmu *pmu = pd->pmu; in rockchip_do_pmu_set_power_domain()
275 struct generic_pm_domain *genpd = &pd->genpd; in rockchip_do_pmu_set_power_domain()
278 if (pd->info->pwr_mask == 0) in rockchip_do_pmu_set_power_domain()
280 else if (pd->info->pwr_w_mask) in rockchip_do_pmu_set_power_domain()
282 on ? pd->info->pwr_w_mask : in rockchip_do_pmu_set_power_domain()
283 (pd->info->pwr_mask | pd->info->pwr_w_mask)); in rockchip_do_pmu_set_power_domain()
286 pd->info->pwr_mask, on ? 0 : -1U); in rockchip_do_pmu_set_power_domain()
290 if (readx_poll_timeout_atomic(rockchip_pmu_domain_is_on, pd, is_on, in rockchip_do_pmu_set_power_domain()
299 static int rockchip_pd_power(struct rockchip_pm_domain *pd, bool power_on) in rockchip_pd_power() argument
301 struct rockchip_pmu *pmu = pd->pmu; in rockchip_pd_power()
306 if (rockchip_pmu_domain_is_on(pd) != power_on) { in rockchip_pd_power()
307 ret = clk_bulk_enable(pd->num_clks, pd->clks); in rockchip_pd_power()
315 rockchip_pmu_save_qos(pd); in rockchip_pd_power()
318 rockchip_pmu_set_idle_request(pd, true); in rockchip_pd_power()
321 rockchip_do_pmu_set_power_domain(pd, power_on); in rockchip_pd_power()
325 rockchip_pmu_set_idle_request(pd, false); in rockchip_pd_power()
327 rockchip_pmu_restore_qos(pd); in rockchip_pd_power()
330 clk_bulk_disable(pd->num_clks, pd->clks); in rockchip_pd_power()
339 struct rockchip_pm_domain *pd = to_rockchip_pd(domain); in rockchip_pd_power_on() local
341 return rockchip_pd_power(pd, true); in rockchip_pd_power_on()
346 struct rockchip_pm_domain *pd = to_rockchip_pd(domain); in rockchip_pd_power_off() local
348 return rockchip_pd_power(pd, false); in rockchip_pd_power_off()
393 struct rockchip_pm_domain *pd; in rockchip_pm_add_one_domain() local
420 pd = devm_kzalloc(pmu->dev, sizeof(*pd), GFP_KERNEL); in rockchip_pm_add_one_domain()
421 if (!pd) in rockchip_pm_add_one_domain()
424 pd->info = pd_info; in rockchip_pm_add_one_domain()
425 pd->pmu = pmu; in rockchip_pm_add_one_domain()
427 pd->num_clks = of_clk_get_parent_count(node); in rockchip_pm_add_one_domain()
428 if (pd->num_clks > 0) { in rockchip_pm_add_one_domain()
429 pd->clks = devm_kcalloc(pmu->dev, pd->num_clks, in rockchip_pm_add_one_domain()
430 sizeof(*pd->clks), GFP_KERNEL); in rockchip_pm_add_one_domain()
431 if (!pd->clks) in rockchip_pm_add_one_domain()
435 node, pd->num_clks); in rockchip_pm_add_one_domain()
436 pd->num_clks = 0; in rockchip_pm_add_one_domain()
439 for (i = 0; i < pd->num_clks; i++) { in rockchip_pm_add_one_domain()
440 pd->clks[i].clk = of_clk_get(node, i); in rockchip_pm_add_one_domain()
441 if (IS_ERR(pd->clks[i].clk)) { in rockchip_pm_add_one_domain()
442 error = PTR_ERR(pd->clks[i].clk); in rockchip_pm_add_one_domain()
450 error = clk_bulk_prepare(pd->num_clks, pd->clks); in rockchip_pm_add_one_domain()
454 pd->num_qos = of_count_phandle_with_args(node, "pm_qos", in rockchip_pm_add_one_domain()
457 if (pd->num_qos > 0) { in rockchip_pm_add_one_domain()
458 pd->qos_regmap = devm_kcalloc(pmu->dev, pd->num_qos, in rockchip_pm_add_one_domain()
459 sizeof(*pd->qos_regmap), in rockchip_pm_add_one_domain()
461 if (!pd->qos_regmap) { in rockchip_pm_add_one_domain()
467 pd->qos_save_regs[j] = devm_kcalloc(pmu->dev, in rockchip_pm_add_one_domain()
468 pd->num_qos, in rockchip_pm_add_one_domain()
471 if (!pd->qos_save_regs[j]) { in rockchip_pm_add_one_domain()
477 for (j = 0; j < pd->num_qos; j++) { in rockchip_pm_add_one_domain()
483 pd->qos_regmap[j] = syscon_node_to_regmap(qos_node); in rockchip_pm_add_one_domain()
484 if (IS_ERR(pd->qos_regmap[j])) { in rockchip_pm_add_one_domain()
493 error = rockchip_pd_power(pd, true); in rockchip_pm_add_one_domain()
501 if (pd->info->name) in rockchip_pm_add_one_domain()
502 pd->genpd.name = pd->info->name; in rockchip_pm_add_one_domain()
504 pd->genpd.name = kbasename(node->full_name); in rockchip_pm_add_one_domain()
505 pd->genpd.power_off = rockchip_pd_power_off; in rockchip_pm_add_one_domain()
506 pd->genpd.power_on = rockchip_pd_power_on; in rockchip_pm_add_one_domain()
507 pd->genpd.attach_dev = rockchip_pd_attach_dev; in rockchip_pm_add_one_domain()
508 pd->genpd.detach_dev = rockchip_pd_detach_dev; in rockchip_pm_add_one_domain()
509 pd->genpd.flags = GENPD_FLAG_PM_CLK; in rockchip_pm_add_one_domain()
511 pd->genpd.flags |= GENPD_FLAG_ACTIVE_WAKEUP; in rockchip_pm_add_one_domain()
512 pm_genpd_init(&pd->genpd, NULL, false); in rockchip_pm_add_one_domain()
514 pmu->genpd_data.domains[id] = &pd->genpd; in rockchip_pm_add_one_domain()
518 clk_bulk_unprepare(pd->num_clks, pd->clks); in rockchip_pm_add_one_domain()
520 clk_bulk_put(pd->num_clks, pd->clks); in rockchip_pm_add_one_domain()
524 static void rockchip_pm_remove_one_domain(struct rockchip_pm_domain *pd) in rockchip_pm_remove_one_domain() argument
532 ret = pm_genpd_remove(&pd->genpd); in rockchip_pm_remove_one_domain()
534 dev_err(pd->pmu->dev, "failed to remove domain '%s' : %d - state may be inconsistent\n", in rockchip_pm_remove_one_domain()
535 pd->genpd.name, ret); in rockchip_pm_remove_one_domain()
537 clk_bulk_unprepare(pd->num_clks, pd->clks); in rockchip_pm_remove_one_domain()
538 clk_bulk_put(pd->num_clks, pd->clks); in rockchip_pm_remove_one_domain()
541 mutex_lock(&pd->pmu->mutex); in rockchip_pm_remove_one_domain()
542 pd->num_clks = 0; in rockchip_pm_remove_one_domain()
543 mutex_unlock(&pd->pmu->mutex); in rockchip_pm_remove_one_domain()
551 struct rockchip_pm_domain *pd; in rockchip_pm_domain_cleanup() local
557 pd = to_rockchip_pd(genpd); in rockchip_pm_domain_cleanup()
558 rockchip_pm_remove_one_domain(pd); in rockchip_pm_domain_cleanup()