Lines Matching full:pd
135 static bool rockchip_pmu_domain_is_idle(struct rockchip_pm_domain *pd) in rockchip_pmu_domain_is_idle() argument
137 struct rockchip_pmu *pmu = pd->pmu; in rockchip_pmu_domain_is_idle()
138 const struct rockchip_domain_info *pd_info = pd->info; in rockchip_pmu_domain_is_idle()
153 static int rockchip_pmu_set_idle_request(struct rockchip_pm_domain *pd, in rockchip_pmu_set_idle_request() argument
156 const struct rockchip_domain_info *pd_info = pd->info; in rockchip_pmu_set_idle_request()
157 struct generic_pm_domain *genpd = &pd->genpd; in rockchip_pmu_set_idle_request()
158 struct rockchip_pmu *pmu = pd->pmu; in rockchip_pmu_set_idle_request()
188 ret = readx_poll_timeout_atomic(rockchip_pmu_domain_is_idle, pd, in rockchip_pmu_set_idle_request()
200 static int rockchip_pmu_save_qos(struct rockchip_pm_domain *pd) in rockchip_pmu_save_qos() argument
204 for (i = 0; i < pd->num_qos; i++) { in rockchip_pmu_save_qos()
205 regmap_read(pd->qos_regmap[i], in rockchip_pmu_save_qos()
207 &pd->qos_save_regs[0][i]); in rockchip_pmu_save_qos()
208 regmap_read(pd->qos_regmap[i], in rockchip_pmu_save_qos()
210 &pd->qos_save_regs[1][i]); in rockchip_pmu_save_qos()
211 regmap_read(pd->qos_regmap[i], in rockchip_pmu_save_qos()
213 &pd->qos_save_regs[2][i]); in rockchip_pmu_save_qos()
214 regmap_read(pd->qos_regmap[i], in rockchip_pmu_save_qos()
216 &pd->qos_save_regs[3][i]); in rockchip_pmu_save_qos()
217 regmap_read(pd->qos_regmap[i], in rockchip_pmu_save_qos()
219 &pd->qos_save_regs[4][i]); in rockchip_pmu_save_qos()
224 static int rockchip_pmu_restore_qos(struct rockchip_pm_domain *pd) in rockchip_pmu_restore_qos() argument
228 for (i = 0; i < pd->num_qos; i++) { in rockchip_pmu_restore_qos()
229 regmap_write(pd->qos_regmap[i], in rockchip_pmu_restore_qos()
231 pd->qos_save_regs[0][i]); in rockchip_pmu_restore_qos()
232 regmap_write(pd->qos_regmap[i], in rockchip_pmu_restore_qos()
234 pd->qos_save_regs[1][i]); in rockchip_pmu_restore_qos()
235 regmap_write(pd->qos_regmap[i], in rockchip_pmu_restore_qos()
237 pd->qos_save_regs[2][i]); in rockchip_pmu_restore_qos()
238 regmap_write(pd->qos_regmap[i], in rockchip_pmu_restore_qos()
240 pd->qos_save_regs[3][i]); in rockchip_pmu_restore_qos()
241 regmap_write(pd->qos_regmap[i], in rockchip_pmu_restore_qos()
243 pd->qos_save_regs[4][i]); in rockchip_pmu_restore_qos()
249 static bool rockchip_pmu_domain_is_on(struct rockchip_pm_domain *pd) in rockchip_pmu_domain_is_on() argument
251 struct rockchip_pmu *pmu = pd->pmu; in rockchip_pmu_domain_is_on()
255 if (pd->info->status_mask == 0) in rockchip_pmu_domain_is_on()
256 return !rockchip_pmu_domain_is_idle(pd); in rockchip_pmu_domain_is_on()
261 return !(val & pd->info->status_mask); in rockchip_pmu_domain_is_on()
264 static void rockchip_do_pmu_set_power_domain(struct rockchip_pm_domain *pd, in rockchip_do_pmu_set_power_domain() argument
267 struct rockchip_pmu *pmu = pd->pmu; in rockchip_do_pmu_set_power_domain()
268 struct generic_pm_domain *genpd = &pd->genpd; in rockchip_do_pmu_set_power_domain()
271 if (pd->info->pwr_mask == 0) in rockchip_do_pmu_set_power_domain()
273 else if (pd->info->pwr_w_mask) in rockchip_do_pmu_set_power_domain()
275 on ? pd->info->pwr_w_mask : in rockchip_do_pmu_set_power_domain()
276 (pd->info->pwr_mask | pd->info->pwr_w_mask)); in rockchip_do_pmu_set_power_domain()
279 pd->info->pwr_mask, on ? 0 : -1U); in rockchip_do_pmu_set_power_domain()
283 if (readx_poll_timeout_atomic(rockchip_pmu_domain_is_on, pd, is_on, in rockchip_do_pmu_set_power_domain()
292 static int rockchip_pd_power(struct rockchip_pm_domain *pd, bool power_on) in rockchip_pd_power() argument
294 struct rockchip_pmu *pmu = pd->pmu; in rockchip_pd_power()
299 if (rockchip_pmu_domain_is_on(pd) != power_on) { in rockchip_pd_power()
300 ret = clk_bulk_enable(pd->num_clks, pd->clks); in rockchip_pd_power()
308 rockchip_pmu_save_qos(pd); in rockchip_pd_power()
311 rockchip_pmu_set_idle_request(pd, true); in rockchip_pd_power()
314 rockchip_do_pmu_set_power_domain(pd, power_on); in rockchip_pd_power()
318 rockchip_pmu_set_idle_request(pd, false); in rockchip_pd_power()
320 rockchip_pmu_restore_qos(pd); in rockchip_pd_power()
323 clk_bulk_disable(pd->num_clks, pd->clks); in rockchip_pd_power()
332 struct rockchip_pm_domain *pd = to_rockchip_pd(domain); in rockchip_pd_power_on() local
334 return rockchip_pd_power(pd, true); in rockchip_pd_power_on()
339 struct rockchip_pm_domain *pd = to_rockchip_pd(domain); in rockchip_pd_power_off() local
341 return rockchip_pd_power(pd, false); in rockchip_pd_power_off()
386 struct rockchip_pm_domain *pd; in rockchip_pm_add_one_domain() local
413 pd = devm_kzalloc(pmu->dev, sizeof(*pd), GFP_KERNEL); in rockchip_pm_add_one_domain()
414 if (!pd) in rockchip_pm_add_one_domain()
417 pd->info = pd_info; in rockchip_pm_add_one_domain()
418 pd->pmu = pmu; in rockchip_pm_add_one_domain()
420 pd->num_clks = of_clk_get_parent_count(node); in rockchip_pm_add_one_domain()
421 if (pd->num_clks > 0) { in rockchip_pm_add_one_domain()
422 pd->clks = devm_kcalloc(pmu->dev, pd->num_clks, in rockchip_pm_add_one_domain()
423 sizeof(*pd->clks), GFP_KERNEL); in rockchip_pm_add_one_domain()
424 if (!pd->clks) in rockchip_pm_add_one_domain()
428 node->name, pd->num_clks); in rockchip_pm_add_one_domain()
429 pd->num_clks = 0; in rockchip_pm_add_one_domain()
432 for (i = 0; i < pd->num_clks; i++) { in rockchip_pm_add_one_domain()
433 pd->clks[i].clk = of_clk_get(node, i); in rockchip_pm_add_one_domain()
434 if (IS_ERR(pd->clks[i].clk)) { in rockchip_pm_add_one_domain()
435 error = PTR_ERR(pd->clks[i].clk); in rockchip_pm_add_one_domain()
443 error = clk_bulk_prepare(pd->num_clks, pd->clks); in rockchip_pm_add_one_domain()
447 pd->num_qos = of_count_phandle_with_args(node, "pm_qos", in rockchip_pm_add_one_domain()
450 if (pd->num_qos > 0) { in rockchip_pm_add_one_domain()
451 pd->qos_regmap = devm_kcalloc(pmu->dev, pd->num_qos, in rockchip_pm_add_one_domain()
452 sizeof(*pd->qos_regmap), in rockchip_pm_add_one_domain()
454 if (!pd->qos_regmap) { in rockchip_pm_add_one_domain()
460 pd->qos_save_regs[j] = devm_kcalloc(pmu->dev, in rockchip_pm_add_one_domain()
461 pd->num_qos, in rockchip_pm_add_one_domain()
464 if (!pd->qos_save_regs[j]) { in rockchip_pm_add_one_domain()
470 for (j = 0; j < pd->num_qos; j++) { in rockchip_pm_add_one_domain()
476 pd->qos_regmap[j] = syscon_node_to_regmap(qos_node); in rockchip_pm_add_one_domain()
477 if (IS_ERR(pd->qos_regmap[j])) { in rockchip_pm_add_one_domain()
486 error = rockchip_pd_power(pd, true); in rockchip_pm_add_one_domain()
494 pd->genpd.name = node->name; in rockchip_pm_add_one_domain()
495 pd->genpd.power_off = rockchip_pd_power_off; in rockchip_pm_add_one_domain()
496 pd->genpd.power_on = rockchip_pd_power_on; in rockchip_pm_add_one_domain()
497 pd->genpd.attach_dev = rockchip_pd_attach_dev; in rockchip_pm_add_one_domain()
498 pd->genpd.detach_dev = rockchip_pd_detach_dev; in rockchip_pm_add_one_domain()
499 pd->genpd.flags = GENPD_FLAG_PM_CLK; in rockchip_pm_add_one_domain()
501 pd->genpd.flags |= GENPD_FLAG_ACTIVE_WAKEUP; in rockchip_pm_add_one_domain()
502 pm_genpd_init(&pd->genpd, NULL, false); in rockchip_pm_add_one_domain()
504 pmu->genpd_data.domains[id] = &pd->genpd; in rockchip_pm_add_one_domain()
508 clk_bulk_unprepare(pd->num_clks, pd->clks); in rockchip_pm_add_one_domain()
510 clk_bulk_put(pd->num_clks, pd->clks); in rockchip_pm_add_one_domain()
514 static void rockchip_pm_remove_one_domain(struct rockchip_pm_domain *pd) in rockchip_pm_remove_one_domain() argument
522 ret = pm_genpd_remove(&pd->genpd); in rockchip_pm_remove_one_domain()
524 dev_err(pd->pmu->dev, "failed to remove domain '%s' : %d - state may be inconsistent\n", in rockchip_pm_remove_one_domain()
525 pd->genpd.name, ret); in rockchip_pm_remove_one_domain()
527 clk_bulk_unprepare(pd->num_clks, pd->clks); in rockchip_pm_remove_one_domain()
528 clk_bulk_put(pd->num_clks, pd->clks); in rockchip_pm_remove_one_domain()
531 mutex_lock(&pd->pmu->mutex); in rockchip_pm_remove_one_domain()
532 pd->num_clks = 0; in rockchip_pm_remove_one_domain()
533 mutex_unlock(&pd->pmu->mutex); in rockchip_pm_remove_one_domain()
541 struct rockchip_pm_domain *pd; in rockchip_pm_domain_cleanup() local
547 pd = to_rockchip_pd(genpd); in rockchip_pm_domain_cleanup()
548 rockchip_pm_remove_one_domain(pd); in rockchip_pm_domain_cleanup()