Lines Matching +full:riscv +full:- +full:sbi
1 // SPDX-License-Identifier: GPL-2.0-only
3 * RISC-V SBI CPU idle driver.
9 #define pr_fmt(fmt) "cpuidle-riscv-sbi: " fmt
25 #include <asm/sbi.h>
52 data->available = true; in sbi_set_domain_state()
53 data->state = state; in sbi_set_domain_state()
60 return data->state; in sbi_get_domain_state()
67 data->available = false; in sbi_clear_domain_state()
74 return data->available; in sbi_is_domain_state_available()
95 u32 *states = data->states; in __sbi_enter_domain_idle_state()
96 struct device *pd_dev = data->dev; in __sbi_enter_domain_idle_state()
102 return -1; in __sbi_enter_domain_idle_state()
117 ret = riscv_sbi_hart_suspend(state) ? -1 : idx; in __sbi_enter_domain_idle_state()
177 "cpuidle/sbi:online", in sbi_idle_init_cpuhp()
185 { .compatible = "riscv,idle-state",
192 int err = of_property_read_u32(np, "riscv,sbi-suspend-param", state); in sbi_dt_parse_state_node()
195 pr_warn("%pOF missing riscv,sbi-suspend-param property\n", np); in sbi_dt_parse_state_node()
200 pr_warn("Invalid SBI suspend state %#x\n", *state); in sbi_dt_parse_state_node()
201 return -EINVAL; in sbi_dt_parse_state_node()
215 data->dev = dt_idle_attach_cpu(cpu, "sbi"); in sbi_dt_cpu_init_topology()
216 if (IS_ERR_OR_NULL(data->dev)) in sbi_dt_cpu_init_topology()
217 return PTR_ERR_OR_ZERO(data->dev); in sbi_dt_cpu_init_topology()
224 drv->states[state_count - 1].flags |= CPUIDLE_FLAG_RCU_IDLE; in sbi_dt_cpu_init_topology()
225 drv->states[state_count - 1].enter = sbi_enter_domain_idle_state; in sbi_dt_cpu_init_topology()
226 drv->states[state_count - 1].enter_s2idle = in sbi_dt_cpu_init_topology()
245 return -ENODEV; in sbi_cpuidle_dt_init_states()
249 return -ENOMEM; in sbi_cpuidle_dt_init_states()
251 /* Parse SBI specific details from state DT nodes */ in sbi_cpuidle_dt_init_states()
253 state_node = of_get_cpu_state_node(cpu_node, i - 1); in sbi_cpuidle_dt_init_states()
263 pr_debug("sbi-state %#x index %d\n", states[i], i); in sbi_cpuidle_dt_init_states()
266 return -ENODEV; in sbi_cpuidle_dt_init_states()
273 /* Store states in the per-cpu struct. */ in sbi_cpuidle_dt_init_states()
274 data->states = states; in sbi_cpuidle_dt_init_states()
283 dt_idle_detach_cpu(data->dev); in sbi_cpuidle_deinit_cpu()
295 return -ENOMEM; in sbi_cpuidle_init_cpu()
297 drv->name = "sbi_cpuidle"; in sbi_cpuidle_init_cpu()
298 drv->owner = THIS_MODULE; in sbi_cpuidle_init_cpu()
299 drv->cpumask = (struct cpumask *)cpumask_of(cpu); in sbi_cpuidle_init_cpu()
301 /* RISC-V architectural WFI to be represented as state index 0. */ in sbi_cpuidle_init_cpu()
302 drv->states[0].enter = sbi_cpuidle_enter_state; in sbi_cpuidle_init_cpu()
303 drv->states[0].exit_latency = 1; in sbi_cpuidle_init_cpu()
304 drv->states[0].target_residency = 1; in sbi_cpuidle_init_cpu()
305 drv->states[0].power_usage = UINT_MAX; in sbi_cpuidle_init_cpu()
306 strcpy(drv->states[0].name, "WFI"); in sbi_cpuidle_init_cpu()
307 strcpy(drv->states[0].desc, "RISC-V WFI"); in sbi_cpuidle_init_cpu()
313 * default archictectural back-end already executes wfi in sbi_cpuidle_init_cpu()
320 return ret ? : -ENODEV; in sbi_cpuidle_init_cpu()
357 struct genpd_power_state *state = &pd->states[pd->state_idx]; in sbi_cpuidle_pd_power_off()
360 if (!state->data) in sbi_cpuidle_pd_power_off()
364 return -EBUSY; in sbi_cpuidle_pd_power_off()
367 pd_state = state->data; in sbi_cpuidle_pd_power_off()
385 int ret = -ENOMEM; in sbi_pd_init()
395 pd->flags |= GENPD_FLAG_IRQ_SAFE | GENPD_FLAG_CPU_DOMAIN; in sbi_pd_init()
399 pd->power_off = sbi_cpuidle_pd_power_off; in sbi_pd_init()
401 pd->flags |= GENPD_FLAG_ALWAYS_ON; in sbi_pd_init()
404 pd_gov = pd->states ? &pm_domain_cpu_gov : NULL; in sbi_pd_init()
414 pd_provider->node = of_node_get(np); in sbi_pd_init()
415 list_add(&pd_provider->link, &sbi_pd_providers); in sbi_pd_init()
417 pr_debug("init PM domain %s\n", pd->name); in sbi_pd_init()
437 of_genpd_del_provider(pd_provider->node); in sbi_pd_remove()
439 genpd = of_genpd_remove_last(pd_provider->node); in sbi_pd_remove()
443 of_node_put(pd_provider->node); in sbi_pd_remove()
444 list_del(&pd_provider->link); in sbi_pd_remove()
454 return -ENODEV; in sbi_genpd_probe()
457 * Parse child nodes for the "#power-domain-cells" property and in sbi_genpd_probe()
458 * initialize a genpd/genpd-of-provider pair when it's found. in sbi_genpd_probe()
461 if (!of_property_present(node, "#power-domain-cells")) in sbi_genpd_probe()
510 of_property_present(np, "power-domains") && in sbi_cpuidle_probe()
511 of_property_present(np, "power-domain-names")) { in sbi_cpuidle_probe()
520 pds_node = of_find_node_by_path("/cpus/power-domains"); in sbi_cpuidle_probe()
530 ret = sbi_cpuidle_init_cpu(&pdev->dev, cpu); in sbi_cpuidle_probe()
546 while (--cpu >= 0) { in sbi_cpuidle_probe()
559 .name = "sbi-cpuidle",
576 pdev = platform_device_register_simple("sbi-cpuidle", in sbi_cpuidle_init()
577 -1, NULL, 0); in sbi_cpuidle_init()