Lines Matching full:pd

198 	struct rockchip_pm_domain *pd;  in rockchip_pmu_block()  local
228 pd = to_rockchip_pd(genpd); in rockchip_pmu_block()
229 ret = clk_bulk_enable(pd->num_clks, pd->clks); in rockchip_pmu_block()
245 pd = to_rockchip_pd(genpd); in rockchip_pmu_block()
246 clk_bulk_disable(pd->num_clks, pd->clks); in rockchip_pmu_block()
261 struct rockchip_pm_domain *pd; in rockchip_pmu_unblock() local
269 pd = to_rockchip_pd(genpd); in rockchip_pmu_unblock()
270 clk_bulk_disable(pd->num_clks, pd->clks); in rockchip_pmu_unblock()
284 static bool rockchip_pmu_domain_is_idle(struct rockchip_pm_domain *pd) in rockchip_pmu_domain_is_idle() argument
286 struct rockchip_pmu *pmu = pd->pmu; in rockchip_pmu_domain_is_idle()
287 const struct rockchip_domain_info *pd_info = pd->info; in rockchip_pmu_domain_is_idle()
302 static int rockchip_pmu_set_idle_request(struct rockchip_pm_domain *pd, in rockchip_pmu_set_idle_request() argument
305 const struct rockchip_domain_info *pd_info = pd->info; in rockchip_pmu_set_idle_request()
306 struct generic_pm_domain *genpd = &pd->genpd; in rockchip_pmu_set_idle_request()
307 struct rockchip_pmu *pmu = pd->pmu; in rockchip_pmu_set_idle_request()
338 ret = readx_poll_timeout_atomic(rockchip_pmu_domain_is_idle, pd, in rockchip_pmu_set_idle_request()
350 static int rockchip_pmu_save_qos(struct rockchip_pm_domain *pd) in rockchip_pmu_save_qos() argument
354 for (i = 0; i < pd->num_qos; i++) { in rockchip_pmu_save_qos()
355 regmap_read(pd->qos_regmap[i], in rockchip_pmu_save_qos()
357 &pd->qos_save_regs[0][i]); in rockchip_pmu_save_qos()
358 regmap_read(pd->qos_regmap[i], in rockchip_pmu_save_qos()
360 &pd->qos_save_regs[1][i]); in rockchip_pmu_save_qos()
361 regmap_read(pd->qos_regmap[i], in rockchip_pmu_save_qos()
363 &pd->qos_save_regs[2][i]); in rockchip_pmu_save_qos()
364 regmap_read(pd->qos_regmap[i], in rockchip_pmu_save_qos()
366 &pd->qos_save_regs[3][i]); in rockchip_pmu_save_qos()
367 regmap_read(pd->qos_regmap[i], in rockchip_pmu_save_qos()
369 &pd->qos_save_regs[4][i]); in rockchip_pmu_save_qos()
374 static int rockchip_pmu_restore_qos(struct rockchip_pm_domain *pd) in rockchip_pmu_restore_qos() argument
378 for (i = 0; i < pd->num_qos; i++) { in rockchip_pmu_restore_qos()
379 regmap_write(pd->qos_regmap[i], in rockchip_pmu_restore_qos()
381 pd->qos_save_regs[0][i]); in rockchip_pmu_restore_qos()
382 regmap_write(pd->qos_regmap[i], in rockchip_pmu_restore_qos()
384 pd->qos_save_regs[1][i]); in rockchip_pmu_restore_qos()
385 regmap_write(pd->qos_regmap[i], in rockchip_pmu_restore_qos()
387 pd->qos_save_regs[2][i]); in rockchip_pmu_restore_qos()
388 regmap_write(pd->qos_regmap[i], in rockchip_pmu_restore_qos()
390 pd->qos_save_regs[3][i]); in rockchip_pmu_restore_qos()
391 regmap_write(pd->qos_regmap[i], in rockchip_pmu_restore_qos()
393 pd->qos_save_regs[4][i]); in rockchip_pmu_restore_qos()
399 static bool rockchip_pmu_domain_is_on(struct rockchip_pm_domain *pd) in rockchip_pmu_domain_is_on() argument
401 struct rockchip_pmu *pmu = pd->pmu; in rockchip_pmu_domain_is_on()
404 if (pd->info->repair_status_mask) { in rockchip_pmu_domain_is_on()
407 return val & pd->info->repair_status_mask; in rockchip_pmu_domain_is_on()
411 if (pd->info->status_mask == 0) in rockchip_pmu_domain_is_on()
412 return !rockchip_pmu_domain_is_idle(pd); in rockchip_pmu_domain_is_on()
417 return !(val & pd->info->status_mask); in rockchip_pmu_domain_is_on()
420 static bool rockchip_pmu_domain_is_mem_on(struct rockchip_pm_domain *pd) in rockchip_pmu_domain_is_mem_on() argument
422 struct rockchip_pmu *pmu = pd->pmu; in rockchip_pmu_domain_is_mem_on()
426 pmu->info->mem_status_offset + pd->info->mem_offset, &val); in rockchip_pmu_domain_is_mem_on()
429 return !(val & pd->info->mem_status_mask); in rockchip_pmu_domain_is_mem_on()
432 static bool rockchip_pmu_domain_is_chain_on(struct rockchip_pm_domain *pd) in rockchip_pmu_domain_is_chain_on() argument
434 struct rockchip_pmu *pmu = pd->pmu; in rockchip_pmu_domain_is_chain_on()
438 pmu->info->chain_status_offset + pd->info->mem_offset, &val); in rockchip_pmu_domain_is_chain_on()
441 return val & pd->info->mem_status_mask; in rockchip_pmu_domain_is_chain_on()
444 static int rockchip_pmu_domain_mem_reset(struct rockchip_pm_domain *pd) in rockchip_pmu_domain_mem_reset() argument
446 struct rockchip_pmu *pmu = pd->pmu; in rockchip_pmu_domain_mem_reset()
447 struct generic_pm_domain *genpd = &pd->genpd; in rockchip_pmu_domain_mem_reset()
451 ret = readx_poll_timeout_atomic(rockchip_pmu_domain_is_chain_on, pd, is_on, in rockchip_pmu_domain_mem_reset()
462 regmap_write(pmu->regmap, pmu->info->mem_pwr_offset + pd->info->pwr_offset, in rockchip_pmu_domain_mem_reset()
463 (pd->info->pwr_mask | pd->info->pwr_w_mask)); in rockchip_pmu_domain_mem_reset()
466 ret = readx_poll_timeout_atomic(rockchip_pmu_domain_is_mem_on, pd, is_on, in rockchip_pmu_domain_mem_reset()
475 regmap_write(pmu->regmap, pmu->info->mem_pwr_offset + pd->info->pwr_offset, in rockchip_pmu_domain_mem_reset()
476 pd->info->pwr_w_mask); in rockchip_pmu_domain_mem_reset()
479 ret = readx_poll_timeout_atomic(rockchip_pmu_domain_is_mem_on, pd, is_on, in rockchip_pmu_domain_mem_reset()
491 static void rockchip_do_pmu_set_power_domain(struct rockchip_pm_domain *pd, in rockchip_do_pmu_set_power_domain() argument
494 struct rockchip_pmu *pmu = pd->pmu; in rockchip_do_pmu_set_power_domain()
495 struct generic_pm_domain *genpd = &pd->genpd; in rockchip_do_pmu_set_power_domain()
496 u32 pd_pwr_offset = pd->info->pwr_offset; in rockchip_do_pmu_set_power_domain()
499 if (pd->info->pwr_mask == 0) in rockchip_do_pmu_set_power_domain()
502 if (on && pd->info->mem_status_mask) in rockchip_do_pmu_set_power_domain()
503 is_mem_on = rockchip_pmu_domain_is_mem_on(pd); in rockchip_do_pmu_set_power_domain()
505 if (pd->info->pwr_w_mask) in rockchip_do_pmu_set_power_domain()
507 on ? pd->info->pwr_w_mask : in rockchip_do_pmu_set_power_domain()
508 (pd->info->pwr_mask | pd->info->pwr_w_mask)); in rockchip_do_pmu_set_power_domain()
511 pd->info->pwr_mask, on ? 0 : -1U); in rockchip_do_pmu_set_power_domain()
515 if (is_mem_on && rockchip_pmu_domain_mem_reset(pd)) in rockchip_do_pmu_set_power_domain()
518 if (readx_poll_timeout_atomic(rockchip_pmu_domain_is_on, pd, is_on, in rockchip_do_pmu_set_power_domain()
527 static int rockchip_pd_power(struct rockchip_pm_domain *pd, bool power_on) in rockchip_pd_power() argument
529 struct rockchip_pmu *pmu = pd->pmu; in rockchip_pd_power()
534 if (rockchip_pmu_domain_is_on(pd) != power_on) { in rockchip_pd_power()
535 ret = clk_bulk_enable(pd->num_clks, pd->clks); in rockchip_pd_power()
543 rockchip_pmu_save_qos(pd); in rockchip_pd_power()
546 rockchip_pmu_set_idle_request(pd, true); in rockchip_pd_power()
549 rockchip_do_pmu_set_power_domain(pd, power_on); in rockchip_pd_power()
553 rockchip_pmu_set_idle_request(pd, false); in rockchip_pd_power()
555 rockchip_pmu_restore_qos(pd); in rockchip_pd_power()
558 clk_bulk_disable(pd->num_clks, pd->clks); in rockchip_pd_power()
567 struct rockchip_pm_domain *pd = to_rockchip_pd(domain); in rockchip_pd_power_on() local
569 return rockchip_pd_power(pd, true); in rockchip_pd_power_on()
574 struct rockchip_pm_domain *pd = to_rockchip_pd(domain); in rockchip_pd_power_off() local
576 return rockchip_pd_power(pd, false); in rockchip_pd_power_off()
621 struct rockchip_pm_domain *pd; in rockchip_pm_add_one_domain() local
651 pd = devm_kzalloc(pmu->dev, sizeof(*pd), GFP_KERNEL); in rockchip_pm_add_one_domain()
652 if (!pd) in rockchip_pm_add_one_domain()
655 pd->info = pd_info; in rockchip_pm_add_one_domain()
656 pd->pmu = pmu; in rockchip_pm_add_one_domain()
658 pd->num_clks = of_clk_get_parent_count(node); in rockchip_pm_add_one_domain()
659 if (pd->num_clks > 0) { in rockchip_pm_add_one_domain()
660 pd->clks = devm_kcalloc(pmu->dev, pd->num_clks, in rockchip_pm_add_one_domain()
661 sizeof(*pd->clks), GFP_KERNEL); in rockchip_pm_add_one_domain()
662 if (!pd->clks) in rockchip_pm_add_one_domain()
666 node, pd->num_clks); in rockchip_pm_add_one_domain()
667 pd->num_clks = 0; in rockchip_pm_add_one_domain()
670 for (i = 0; i < pd->num_clks; i++) { in rockchip_pm_add_one_domain()
671 pd->clks[i].clk = of_clk_get(node, i); in rockchip_pm_add_one_domain()
672 if (IS_ERR(pd->clks[i].clk)) { in rockchip_pm_add_one_domain()
673 error = PTR_ERR(pd->clks[i].clk); in rockchip_pm_add_one_domain()
681 error = clk_bulk_prepare(pd->num_clks, pd->clks); in rockchip_pm_add_one_domain()
685 pd->num_qos = of_count_phandle_with_args(node, "pm_qos", in rockchip_pm_add_one_domain()
688 if (pd->num_qos > 0) { in rockchip_pm_add_one_domain()
689 pd->qos_regmap = devm_kcalloc(pmu->dev, pd->num_qos, in rockchip_pm_add_one_domain()
690 sizeof(*pd->qos_regmap), in rockchip_pm_add_one_domain()
692 if (!pd->qos_regmap) { in rockchip_pm_add_one_domain()
698 pd->qos_save_regs[j] = devm_kcalloc(pmu->dev, in rockchip_pm_add_one_domain()
699 pd->num_qos, in rockchip_pm_add_one_domain()
702 if (!pd->qos_save_regs[j]) { in rockchip_pm_add_one_domain()
708 for (j = 0; j < pd->num_qos; j++) { in rockchip_pm_add_one_domain()
714 pd->qos_regmap[j] = syscon_node_to_regmap(qos_node); in rockchip_pm_add_one_domain()
715 if (IS_ERR(pd->qos_regmap[j])) { in rockchip_pm_add_one_domain()
724 if (pd->info->name) in rockchip_pm_add_one_domain()
725 pd->genpd.name = pd->info->name; in rockchip_pm_add_one_domain()
727 pd->genpd.name = kbasename(node->full_name); in rockchip_pm_add_one_domain()
728 pd->genpd.power_off = rockchip_pd_power_off; in rockchip_pm_add_one_domain()
729 pd->genpd.power_on = rockchip_pd_power_on; in rockchip_pm_add_one_domain()
730 pd->genpd.attach_dev = rockchip_pd_attach_dev; in rockchip_pm_add_one_domain()
731 pd->genpd.detach_dev = rockchip_pd_detach_dev; in rockchip_pm_add_one_domain()
732 pd->genpd.flags = GENPD_FLAG_PM_CLK; in rockchip_pm_add_one_domain()
734 pd->genpd.flags |= GENPD_FLAG_ACTIVE_WAKEUP; in rockchip_pm_add_one_domain()
735 pm_genpd_init(&pd->genpd, NULL, in rockchip_pm_add_one_domain()
736 !rockchip_pmu_domain_is_on(pd) || in rockchip_pm_add_one_domain()
737 (pd->info->mem_status_mask && !rockchip_pmu_domain_is_mem_on(pd))); in rockchip_pm_add_one_domain()
739 pmu->genpd_data.domains[id] = &pd->genpd; in rockchip_pm_add_one_domain()
743 clk_bulk_unprepare(pd->num_clks, pd->clks); in rockchip_pm_add_one_domain()
745 clk_bulk_put(pd->num_clks, pd->clks); in rockchip_pm_add_one_domain()
749 static void rockchip_pm_remove_one_domain(struct rockchip_pm_domain *pd) in rockchip_pm_remove_one_domain() argument
757 ret = pm_genpd_remove(&pd->genpd); in rockchip_pm_remove_one_domain()
759 dev_err(pd->pmu->dev, "failed to remove domain '%s' : %d - state may be inconsistent\n", in rockchip_pm_remove_one_domain()
760 pd->genpd.name, ret); in rockchip_pm_remove_one_domain()
762 clk_bulk_unprepare(pd->num_clks, pd->clks); in rockchip_pm_remove_one_domain()
763 clk_bulk_put(pd->num_clks, pd->clks); in rockchip_pm_remove_one_domain()
766 mutex_lock(&pd->pmu->mutex); in rockchip_pm_remove_one_domain()
767 pd->num_clks = 0; in rockchip_pm_remove_one_domain()
768 mutex_unlock(&pd->pmu->mutex); in rockchip_pm_remove_one_domain()
776 struct rockchip_pm_domain *pd; in rockchip_pm_domain_cleanup() local
782 pd = to_rockchip_pd(genpd); in rockchip_pm_domain_cleanup()
783 rockchip_pm_remove_one_domain(pd); in rockchip_pm_domain_cleanup()