Lines Matching full:pd
230 struct rockchip_pm_domain *pd; in rockchip_pmu_block() local
260 pd = to_rockchip_pd(genpd); in rockchip_pmu_block()
261 ret = clk_bulk_enable(pd->num_clks, pd->clks); in rockchip_pmu_block()
277 pd = to_rockchip_pd(genpd); in rockchip_pmu_block()
278 clk_bulk_disable(pd->num_clks, pd->clks); in rockchip_pmu_block()
293 struct rockchip_pm_domain *pd; in rockchip_pmu_unblock() local
301 pd = to_rockchip_pd(genpd); in rockchip_pmu_unblock()
302 clk_bulk_disable(pd->num_clks, pd->clks); in rockchip_pmu_unblock()
316 static bool rockchip_pmu_domain_is_idle(struct rockchip_pm_domain *pd) in rockchip_pmu_domain_is_idle() argument
318 struct rockchip_pmu *pmu = pd->pmu; in rockchip_pmu_domain_is_idle()
319 const struct rockchip_domain_info *pd_info = pd->info; in rockchip_pmu_domain_is_idle()
334 static int rockchip_pmu_ungate_clk(struct rockchip_pm_domain *pd, bool ungate) in rockchip_pmu_ungate_clk() argument
336 const struct rockchip_domain_info *pd_info = pd->info; in rockchip_pmu_ungate_clk()
337 struct rockchip_pmu *pmu = pd->pmu; in rockchip_pmu_ungate_clk()
354 static int rockchip_pmu_set_idle_request(struct rockchip_pm_domain *pd, in rockchip_pmu_set_idle_request() argument
357 const struct rockchip_domain_info *pd_info = pd->info; in rockchip_pmu_set_idle_request()
358 struct generic_pm_domain *genpd = &pd->genpd; in rockchip_pmu_set_idle_request()
359 struct rockchip_pmu *pmu = pd->pmu; in rockchip_pmu_set_idle_request()
390 ret = readx_poll_timeout_atomic(rockchip_pmu_domain_is_idle, pd, in rockchip_pmu_set_idle_request()
402 static int rockchip_pmu_save_qos(struct rockchip_pm_domain *pd) in rockchip_pmu_save_qos() argument
406 for (i = 0; i < pd->num_qos; i++) { in rockchip_pmu_save_qos()
407 regmap_read(pd->qos_regmap[i], in rockchip_pmu_save_qos()
409 &pd->qos_save_regs[0][i]); in rockchip_pmu_save_qos()
410 regmap_read(pd->qos_regmap[i], in rockchip_pmu_save_qos()
412 &pd->qos_save_regs[1][i]); in rockchip_pmu_save_qos()
413 regmap_read(pd->qos_regmap[i], in rockchip_pmu_save_qos()
415 &pd->qos_save_regs[2][i]); in rockchip_pmu_save_qos()
416 regmap_read(pd->qos_regmap[i], in rockchip_pmu_save_qos()
418 &pd->qos_save_regs[3][i]); in rockchip_pmu_save_qos()
419 regmap_read(pd->qos_regmap[i], in rockchip_pmu_save_qos()
421 &pd->qos_save_regs[4][i]); in rockchip_pmu_save_qos()
426 static int rockchip_pmu_restore_qos(struct rockchip_pm_domain *pd) in rockchip_pmu_restore_qos() argument
430 for (i = 0; i < pd->num_qos; i++) { in rockchip_pmu_restore_qos()
431 regmap_write(pd->qos_regmap[i], in rockchip_pmu_restore_qos()
433 pd->qos_save_regs[0][i]); in rockchip_pmu_restore_qos()
434 regmap_write(pd->qos_regmap[i], in rockchip_pmu_restore_qos()
436 pd->qos_save_regs[1][i]); in rockchip_pmu_restore_qos()
437 regmap_write(pd->qos_regmap[i], in rockchip_pmu_restore_qos()
439 pd->qos_save_regs[2][i]); in rockchip_pmu_restore_qos()
440 regmap_write(pd->qos_regmap[i], in rockchip_pmu_restore_qos()
442 pd->qos_save_regs[3][i]); in rockchip_pmu_restore_qos()
443 regmap_write(pd->qos_regmap[i], in rockchip_pmu_restore_qos()
445 pd->qos_save_regs[4][i]); in rockchip_pmu_restore_qos()
451 static bool rockchip_pmu_domain_is_on(struct rockchip_pm_domain *pd) in rockchip_pmu_domain_is_on() argument
453 struct rockchip_pmu *pmu = pd->pmu; in rockchip_pmu_domain_is_on()
456 if (pd->info->repair_status_mask) { in rockchip_pmu_domain_is_on()
459 return val & pd->info->repair_status_mask; in rockchip_pmu_domain_is_on()
463 if (pd->info->status_mask == 0) in rockchip_pmu_domain_is_on()
464 return !rockchip_pmu_domain_is_idle(pd); in rockchip_pmu_domain_is_on()
469 return !(val & pd->info->status_mask); in rockchip_pmu_domain_is_on()
472 static bool rockchip_pmu_domain_is_mem_on(struct rockchip_pm_domain *pd) in rockchip_pmu_domain_is_mem_on() argument
474 struct rockchip_pmu *pmu = pd->pmu; in rockchip_pmu_domain_is_mem_on()
478 pmu->info->mem_status_offset + pd->info->mem_offset, &val); in rockchip_pmu_domain_is_mem_on()
481 return !(val & pd->info->mem_status_mask); in rockchip_pmu_domain_is_mem_on()
484 static bool rockchip_pmu_domain_is_chain_on(struct rockchip_pm_domain *pd) in rockchip_pmu_domain_is_chain_on() argument
486 struct rockchip_pmu *pmu = pd->pmu; in rockchip_pmu_domain_is_chain_on()
490 pmu->info->chain_status_offset + pd->info->mem_offset, &val); in rockchip_pmu_domain_is_chain_on()
493 return val & pd->info->mem_status_mask; in rockchip_pmu_domain_is_chain_on()
496 static int rockchip_pmu_domain_mem_reset(struct rockchip_pm_domain *pd) in rockchip_pmu_domain_mem_reset() argument
498 struct rockchip_pmu *pmu = pd->pmu; in rockchip_pmu_domain_mem_reset()
499 struct generic_pm_domain *genpd = &pd->genpd; in rockchip_pmu_domain_mem_reset()
503 ret = readx_poll_timeout_atomic(rockchip_pmu_domain_is_chain_on, pd, is_on, in rockchip_pmu_domain_mem_reset()
514 regmap_write(pmu->regmap, pmu->info->mem_pwr_offset + pd->info->pwr_offset, in rockchip_pmu_domain_mem_reset()
515 (pd->info->pwr_mask | pd->info->pwr_w_mask)); in rockchip_pmu_domain_mem_reset()
518 ret = readx_poll_timeout_atomic(rockchip_pmu_domain_is_mem_on, pd, is_on, in rockchip_pmu_domain_mem_reset()
527 regmap_write(pmu->regmap, pmu->info->mem_pwr_offset + pd->info->pwr_offset, in rockchip_pmu_domain_mem_reset()
528 pd->info->pwr_w_mask); in rockchip_pmu_domain_mem_reset()
531 ret = readx_poll_timeout_atomic(rockchip_pmu_domain_is_mem_on, pd, is_on, in rockchip_pmu_domain_mem_reset()
543 static int rockchip_do_pmu_set_power_domain(struct rockchip_pm_domain *pd, in rockchip_do_pmu_set_power_domain() argument
546 struct rockchip_pmu *pmu = pd->pmu; in rockchip_do_pmu_set_power_domain()
547 struct generic_pm_domain *genpd = &pd->genpd; in rockchip_do_pmu_set_power_domain()
548 u32 pd_pwr_offset = pd->info->pwr_offset; in rockchip_do_pmu_set_power_domain()
553 if (pd->info->pwr_mask == 0) in rockchip_do_pmu_set_power_domain()
556 if (on && pd->info->mem_status_mask) in rockchip_do_pmu_set_power_domain()
557 is_mem_on = rockchip_pmu_domain_is_mem_on(pd); in rockchip_do_pmu_set_power_domain()
559 if (pd->info->pwr_w_mask) in rockchip_do_pmu_set_power_domain()
561 on ? pd->info->pwr_w_mask : in rockchip_do_pmu_set_power_domain()
562 (pd->info->pwr_mask | pd->info->pwr_w_mask)); in rockchip_do_pmu_set_power_domain()
565 pd->info->pwr_mask, on ? 0 : -1U); in rockchip_do_pmu_set_power_domain()
570 ret = rockchip_pmu_domain_mem_reset(pd); in rockchip_do_pmu_set_power_domain()
576 ret = readx_poll_timeout_atomic(rockchip_pmu_domain_is_on, pd, is_on, in rockchip_do_pmu_set_power_domain()
584 /* Inform firmware to keep this pd on or off */ in rockchip_do_pmu_set_power_domain()
588 pd->info->pwr_mask, on, 0, 0, 0, &res); in rockchip_do_pmu_set_power_domain()
593 static int rockchip_pd_power(struct rockchip_pm_domain *pd, bool power_on) in rockchip_pd_power() argument
595 struct rockchip_pmu *pmu = pd->pmu; in rockchip_pd_power()
600 if (rockchip_pmu_domain_is_on(pd) == power_on) in rockchip_pd_power()
603 ret = clk_bulk_enable(pd->num_clks, pd->clks); in rockchip_pd_power()
609 rockchip_pmu_ungate_clk(pd, true); in rockchip_pd_power()
612 rockchip_pmu_save_qos(pd); in rockchip_pd_power()
615 ret = rockchip_pmu_set_idle_request(pd, true); in rockchip_pd_power()
620 ret = rockchip_do_pmu_set_power_domain(pd, power_on); in rockchip_pd_power()
626 ret = rockchip_pmu_set_idle_request(pd, false); in rockchip_pd_power()
630 rockchip_pmu_restore_qos(pd); in rockchip_pd_power()
634 rockchip_pmu_ungate_clk(pd, false); in rockchip_pd_power()
635 clk_bulk_disable(pd->num_clks, pd->clks); in rockchip_pd_power()
640 static int rockchip_pd_regulator_disable(struct rockchip_pm_domain *pd) in rockchip_pd_regulator_disable() argument
642 return IS_ERR_OR_NULL(pd->supply) ? 0 : regulator_disable(pd->supply); in rockchip_pd_regulator_disable()
645 static int rockchip_pd_regulator_enable(struct rockchip_pm_domain *pd) in rockchip_pd_regulator_enable() argument
647 struct rockchip_pmu *pmu = pd->pmu; in rockchip_pd_regulator_enable()
649 if (!pd->info->need_regulator) in rockchip_pd_regulator_enable()
652 if (IS_ERR_OR_NULL(pd->supply)) { in rockchip_pd_regulator_enable()
653 pd->supply = devm_of_regulator_get(pmu->dev, pd->node, "domain"); in rockchip_pd_regulator_enable()
655 if (IS_ERR(pd->supply)) in rockchip_pd_regulator_enable()
656 return PTR_ERR(pd->supply); in rockchip_pd_regulator_enable()
659 return regulator_enable(pd->supply); in rockchip_pd_regulator_enable()
664 struct rockchip_pm_domain *pd = to_rockchip_pd(domain); in rockchip_pd_power_on() local
667 ret = rockchip_pd_regulator_enable(pd); in rockchip_pd_power_on()
669 dev_err(pd->pmu->dev, "Failed to enable supply: %d\n", ret); in rockchip_pd_power_on()
673 ret = rockchip_pd_power(pd, true); in rockchip_pd_power_on()
675 rockchip_pd_regulator_disable(pd); in rockchip_pd_power_on()
682 struct rockchip_pm_domain *pd = to_rockchip_pd(domain); in rockchip_pd_power_off() local
685 ret = rockchip_pd_power(pd, false); in rockchip_pd_power_off()
689 rockchip_pd_regulator_disable(pd); in rockchip_pd_power_off()
735 struct rockchip_pm_domain *pd; in rockchip_pm_add_one_domain() local
765 pd = devm_kzalloc(pmu->dev, sizeof(*pd), GFP_KERNEL); in rockchip_pm_add_one_domain()
766 if (!pd) in rockchip_pm_add_one_domain()
769 pd->info = pd_info; in rockchip_pm_add_one_domain()
770 pd->pmu = pmu; in rockchip_pm_add_one_domain()
771 pd->node = node; in rockchip_pm_add_one_domain()
773 pd->num_clks = of_clk_get_parent_count(node); in rockchip_pm_add_one_domain()
774 if (pd->num_clks > 0) { in rockchip_pm_add_one_domain()
775 pd->clks = devm_kcalloc(pmu->dev, pd->num_clks, in rockchip_pm_add_one_domain()
776 sizeof(*pd->clks), GFP_KERNEL); in rockchip_pm_add_one_domain()
777 if (!pd->clks) in rockchip_pm_add_one_domain()
781 node, pd->num_clks); in rockchip_pm_add_one_domain()
782 pd->num_clks = 0; in rockchip_pm_add_one_domain()
785 for (i = 0; i < pd->num_clks; i++) { in rockchip_pm_add_one_domain()
786 pd->clks[i].clk = of_clk_get(node, i); in rockchip_pm_add_one_domain()
787 if (IS_ERR(pd->clks[i].clk)) { in rockchip_pm_add_one_domain()
788 error = PTR_ERR(pd->clks[i].clk); in rockchip_pm_add_one_domain()
796 error = clk_bulk_prepare(pd->num_clks, pd->clks); in rockchip_pm_add_one_domain()
800 pd->num_qos = of_count_phandle_with_args(node, "pm_qos", in rockchip_pm_add_one_domain()
803 if (pd->num_qos > 0) { in rockchip_pm_add_one_domain()
804 pd->qos_regmap = devm_kcalloc(pmu->dev, pd->num_qos, in rockchip_pm_add_one_domain()
805 sizeof(*pd->qos_regmap), in rockchip_pm_add_one_domain()
807 if (!pd->qos_regmap) { in rockchip_pm_add_one_domain()
813 pd->qos_save_regs[j] = devm_kcalloc(pmu->dev, in rockchip_pm_add_one_domain()
814 pd->num_qos, in rockchip_pm_add_one_domain()
817 if (!pd->qos_save_regs[j]) { in rockchip_pm_add_one_domain()
823 for (j = 0; j < pd->num_qos; j++) { in rockchip_pm_add_one_domain()
829 pd->qos_regmap[j] = syscon_node_to_regmap(qos_node); in rockchip_pm_add_one_domain()
831 if (IS_ERR(pd->qos_regmap[j])) { in rockchip_pm_add_one_domain()
838 if (pd->info->name) in rockchip_pm_add_one_domain()
839 pd->genpd.name = pd->info->name; in rockchip_pm_add_one_domain()
841 pd->genpd.name = kbasename(node->full_name); in rockchip_pm_add_one_domain()
842 pd->genpd.power_off = rockchip_pd_power_off; in rockchip_pm_add_one_domain()
843 pd->genpd.power_on = rockchip_pd_power_on; in rockchip_pm_add_one_domain()
844 pd->genpd.attach_dev = rockchip_pd_attach_dev; in rockchip_pm_add_one_domain()
845 pd->genpd.detach_dev = rockchip_pd_detach_dev; in rockchip_pm_add_one_domain()
846 pd->genpd.flags = GENPD_FLAG_PM_CLK; in rockchip_pm_add_one_domain()
848 pd->genpd.flags |= GENPD_FLAG_ACTIVE_WAKEUP; in rockchip_pm_add_one_domain()
849 pm_genpd_init(&pd->genpd, NULL, in rockchip_pm_add_one_domain()
850 !rockchip_pmu_domain_is_on(pd) || in rockchip_pm_add_one_domain()
851 (pd->info->mem_status_mask && !rockchip_pmu_domain_is_mem_on(pd))); in rockchip_pm_add_one_domain()
853 pmu->genpd_data.domains[id] = &pd->genpd; in rockchip_pm_add_one_domain()
857 clk_bulk_unprepare(pd->num_clks, pd->clks); in rockchip_pm_add_one_domain()
859 clk_bulk_put(pd->num_clks, pd->clks); in rockchip_pm_add_one_domain()
863 static void rockchip_pm_remove_one_domain(struct rockchip_pm_domain *pd) in rockchip_pm_remove_one_domain() argument
871 ret = pm_genpd_remove(&pd->genpd); in rockchip_pm_remove_one_domain()
873 dev_err(pd->pmu->dev, "failed to remove domain '%s' : %d - state may be inconsistent\n", in rockchip_pm_remove_one_domain()
874 pd->genpd.name, ret); in rockchip_pm_remove_one_domain()
876 clk_bulk_unprepare(pd->num_clks, pd->clks); in rockchip_pm_remove_one_domain()
877 clk_bulk_put(pd->num_clks, pd->clks); in rockchip_pm_remove_one_domain()
880 mutex_lock(&pd->pmu->mutex); in rockchip_pm_remove_one_domain()
881 pd->num_clks = 0; in rockchip_pm_remove_one_domain()
882 mutex_unlock(&pd->pmu->mutex); in rockchip_pm_remove_one_domain()
890 struct rockchip_pm_domain *pd; in rockchip_pm_domain_cleanup() local
896 pd = to_rockchip_pd(genpd); in rockchip_pm_domain_cleanup()
897 rockchip_pm_remove_one_domain(pd); in rockchip_pm_domain_cleanup()