Lines Matching +full:over +full:- +full:volt
1 // SPDX-License-Identifier: GPL-2.0-only
4 * Author: Pi-Cheng Chen <pi-cheng.chen@linaro.org>
33 * 100mV < Vsram - Vproc < 200mV
71 if (cpumask_test_cpu(cpu, &info->cpus)) in mtk_cpu_dvfs_info_lookup()
81 const struct mtk_cpufreq_platform_data *soc_data = info->soc_data; in mtk_cpufreq_voltage_tracking()
82 struct regulator *proc_reg = info->proc_reg; in mtk_cpufreq_voltage_tracking()
83 struct regulator *sram_reg = info->sram_reg; in mtk_cpufreq_voltage_tracking()
85 int retry = info->vtrack_max; in mtk_cpufreq_voltage_tracking()
89 dev_err(info->cpu_dev, in mtk_cpufreq_voltage_tracking()
96 dev_err(info->cpu_dev, "invalid Vsram value: %d\n", pre_vsram); in mtk_cpufreq_voltage_tracking()
100 new_vsram = clamp(new_vproc + soc_data->min_volt_shift, in mtk_cpufreq_voltage_tracking()
101 soc_data->sram_min_volt, soc_data->sram_max_volt); in mtk_cpufreq_voltage_tracking()
105 vsram = clamp(pre_vproc + soc_data->max_volt_shift, in mtk_cpufreq_voltage_tracking()
106 soc_data->sram_min_volt, new_vsram); in mtk_cpufreq_voltage_tracking()
108 soc_data->sram_max_volt); in mtk_cpufreq_voltage_tracking()
113 if (vsram == soc_data->sram_max_volt || in mtk_cpufreq_voltage_tracking()
114 new_vsram == soc_data->sram_min_volt) in mtk_cpufreq_voltage_tracking()
117 vproc = vsram - soc_data->min_volt_shift; in mtk_cpufreq_voltage_tracking()
120 soc_data->proc_max_volt); in mtk_cpufreq_voltage_tracking()
123 soc_data->sram_max_volt); in mtk_cpufreq_voltage_tracking()
128 pre_vsram - soc_data->max_volt_shift); in mtk_cpufreq_voltage_tracking()
130 soc_data->proc_max_volt); in mtk_cpufreq_voltage_tracking()
138 vproc + soc_data->min_volt_shift); in mtk_cpufreq_voltage_tracking()
141 soc_data->sram_max_volt); in mtk_cpufreq_voltage_tracking()
144 soc_data->proc_max_volt); in mtk_cpufreq_voltage_tracking()
152 if (--retry < 0) { in mtk_cpufreq_voltage_tracking()
153 dev_err(info->cpu_dev, in mtk_cpufreq_voltage_tracking()
154 "over loop count, failed to set voltage\n"); in mtk_cpufreq_voltage_tracking()
155 return -EINVAL; in mtk_cpufreq_voltage_tracking()
164 const struct mtk_cpufreq_platform_data *soc_data = info->soc_data; in mtk_cpufreq_set_voltage()
167 if (info->need_voltage_tracking) in mtk_cpufreq_set_voltage()
170 ret = regulator_set_voltage(info->proc_reg, vproc, in mtk_cpufreq_set_voltage()
171 soc_data->proc_max_volt); in mtk_cpufreq_set_voltage()
173 info->pre_vproc = vproc; in mtk_cpufreq_set_voltage()
182 if (info->ccifreq_bound) in is_ccifreq_ready()
185 sup_link = device_link_add(info->cpu_dev, info->cci_dev, in is_ccifreq_ready()
188 dev_err(info->cpu_dev, "cpu%d: sup_link is NULL\n", info->opp_cpu); in is_ccifreq_ready()
192 if (sup_link->supplier->links.status != DL_DEV_DRIVER_BOUND) in is_ccifreq_ready()
195 info->ccifreq_bound = true; in is_ccifreq_ready()
203 struct cpufreq_frequency_table *freq_table = policy->freq_table; in mtk_cpufreq_set_target()
204 struct clk *cpu_clk = policy->clk; in mtk_cpufreq_set_target()
206 struct mtk_cpu_dvfs_info *info = policy->driver_data; in mtk_cpufreq_set_target()
207 struct device *cpu_dev = info->cpu_dev; in mtk_cpufreq_set_target()
212 inter_vproc = info->intermediate_voltage; in mtk_cpufreq_set_target()
216 mutex_lock(&info->reg_lock); in mtk_cpufreq_set_target()
218 if (unlikely(info->pre_vproc <= 0)) in mtk_cpufreq_set_target()
219 pre_vproc = regulator_get_voltage(info->proc_reg); in mtk_cpufreq_set_target()
221 pre_vproc = info->pre_vproc; in mtk_cpufreq_set_target()
234 policy->cpu, freq_hz); in mtk_cpufreq_set_target()
246 if (info->soc_data->ccifreq_supported && !is_ccifreq_ready(info)) in mtk_cpufreq_set_target()
247 vproc = max(vproc, info->vproc_on_boot); in mtk_cpufreq_set_target()
258 "cpu%d: failed to scale up voltage!\n", policy->cpu); in mtk_cpufreq_set_target()
265 ret = clk_set_parent(cpu_clk, info->inter_clk); in mtk_cpufreq_set_target()
268 "cpu%d: failed to re-parent cpu clock!\n", policy->cpu); in mtk_cpufreq_set_target()
277 "cpu%d: failed to scale cpu clock rate!\n", policy->cpu); in mtk_cpufreq_set_target()
287 "cpu%d: failed to re-parent cpu clock!\n", policy->cpu); in mtk_cpufreq_set_target()
300 "cpu%d: failed to scale down voltage!\n", policy->cpu); in mtk_cpufreq_set_target()
301 clk_set_parent(cpu_clk, info->inter_clk); in mtk_cpufreq_set_target()
308 info->current_freq = freq_hz; in mtk_cpufreq_set_target()
311 mutex_unlock(&info->reg_lock); in mtk_cpufreq_set_target()
322 unsigned long freq, volt; in mtk_cpufreq_opp_notifier() local
331 mutex_lock(&info->reg_lock); in mtk_cpufreq_opp_notifier()
332 if (info->current_freq == freq) { in mtk_cpufreq_opp_notifier()
333 volt = dev_pm_opp_get_voltage(opp); in mtk_cpufreq_opp_notifier()
334 ret = mtk_cpufreq_set_voltage(info, volt); in mtk_cpufreq_opp_notifier()
336 dev_err(info->cpu_dev, in mtk_cpufreq_opp_notifier()
339 mutex_unlock(&info->reg_lock); in mtk_cpufreq_opp_notifier()
344 if (info->current_freq == freq) { in mtk_cpufreq_opp_notifier()
346 new_opp = dev_pm_opp_find_freq_ceil(info->cpu_dev, in mtk_cpufreq_opp_notifier()
349 dev_err(info->cpu_dev, in mtk_cpufreq_opp_notifier()
356 policy = cpufreq_cpu_get(info->opp_cpu); in mtk_cpufreq_opp_notifier()
373 np = of_parse_phandle(cpu_dev->of_node, "mediatek,cci", 0); in of_get_cci()
375 return ERR_PTR(-ENODEV); in of_get_cci()
380 return ERR_PTR(-ENODEV); in of_get_cci()
382 return &pdev->dev; in of_get_cci()
394 return dev_err_probe(cpu_dev, -ENODEV, "failed to get cpu%d device\n", cpu); in mtk_cpu_dvfs_info_init()
395 info->cpu_dev = cpu_dev; in mtk_cpu_dvfs_info_init()
397 info->ccifreq_bound = false; in mtk_cpu_dvfs_info_init()
398 if (info->soc_data->ccifreq_supported) { in mtk_cpu_dvfs_info_init()
399 info->cci_dev = of_get_cci(info->cpu_dev); in mtk_cpu_dvfs_info_init()
400 if (IS_ERR(info->cci_dev)) in mtk_cpu_dvfs_info_init()
401 return dev_err_probe(cpu_dev, PTR_ERR(info->cci_dev), in mtk_cpu_dvfs_info_init()
406 info->cpu_clk = clk_get(cpu_dev, "cpu"); in mtk_cpu_dvfs_info_init()
407 if (IS_ERR(info->cpu_clk)) in mtk_cpu_dvfs_info_init()
408 return dev_err_probe(cpu_dev, PTR_ERR(info->cpu_clk), in mtk_cpu_dvfs_info_init()
411 info->inter_clk = clk_get(cpu_dev, "intermediate"); in mtk_cpu_dvfs_info_init()
412 if (IS_ERR(info->inter_clk)) { in mtk_cpu_dvfs_info_init()
413 ret = PTR_ERR(info->inter_clk); in mtk_cpu_dvfs_info_init()
419 info->proc_reg = regulator_get_optional(cpu_dev, "proc"); in mtk_cpu_dvfs_info_init()
420 if (IS_ERR(info->proc_reg)) { in mtk_cpu_dvfs_info_init()
421 ret = PTR_ERR(info->proc_reg); in mtk_cpu_dvfs_info_init()
427 ret = regulator_enable(info->proc_reg); in mtk_cpu_dvfs_info_init()
434 info->sram_reg = regulator_get_optional(cpu_dev, "sram"); in mtk_cpu_dvfs_info_init()
435 if (IS_ERR(info->sram_reg)) { in mtk_cpu_dvfs_info_init()
436 ret = PTR_ERR(info->sram_reg); in mtk_cpu_dvfs_info_init()
437 if (ret == -EPROBE_DEFER) { in mtk_cpu_dvfs_info_init()
443 info->sram_reg = NULL; in mtk_cpu_dvfs_info_init()
445 ret = regulator_enable(info->sram_reg); in mtk_cpu_dvfs_info_init()
452 /* Get OPP-sharing information from "operating-points-v2" bindings */ in mtk_cpu_dvfs_info_init()
453 ret = dev_pm_opp_of_get_sharing_cpus(cpu_dev, &info->cpus); in mtk_cpu_dvfs_info_init()
456 "cpu%d: failed to get OPP-sharing information\n", cpu); in mtk_cpu_dvfs_info_init()
460 ret = dev_pm_opp_of_cpumask_add_table(&info->cpus); in mtk_cpu_dvfs_info_init()
466 ret = clk_prepare_enable(info->cpu_clk); in mtk_cpu_dvfs_info_init()
472 ret = clk_prepare_enable(info->inter_clk); in mtk_cpu_dvfs_info_init()
478 if (info->soc_data->ccifreq_supported) { in mtk_cpu_dvfs_info_init()
479 info->vproc_on_boot = regulator_get_voltage(info->proc_reg); in mtk_cpu_dvfs_info_init()
480 if (info->vproc_on_boot < 0) { in mtk_cpu_dvfs_info_init()
481 ret = dev_err_probe(info->cpu_dev, info->vproc_on_boot, in mtk_cpu_dvfs_info_init()
488 rate = clk_get_rate(info->inter_clk); in mtk_cpu_dvfs_info_init()
495 info->intermediate_voltage = dev_pm_opp_get_voltage(opp); in mtk_cpu_dvfs_info_init()
498 mutex_init(&info->reg_lock); in mtk_cpu_dvfs_info_init()
499 info->current_freq = clk_get_rate(info->cpu_clk); in mtk_cpu_dvfs_info_init()
501 info->opp_cpu = cpu; in mtk_cpu_dvfs_info_init()
502 info->opp_nb.notifier_call = mtk_cpufreq_opp_notifier; in mtk_cpu_dvfs_info_init()
503 ret = dev_pm_opp_register_notifier(cpu_dev, &info->opp_nb); in mtk_cpu_dvfs_info_init()
513 info->need_voltage_tracking = (info->sram_reg != NULL); in mtk_cpu_dvfs_info_init()
520 info->vtrack_max = 3 * DIV_ROUND_UP(max(info->soc_data->sram_max_volt, in mtk_cpu_dvfs_info_init()
521 info->soc_data->proc_max_volt), in mtk_cpu_dvfs_info_init()
522 info->soc_data->min_volt_shift); in mtk_cpu_dvfs_info_init()
527 clk_disable_unprepare(info->inter_clk); in mtk_cpu_dvfs_info_init()
530 clk_disable_unprepare(info->cpu_clk); in mtk_cpu_dvfs_info_init()
533 dev_pm_opp_of_cpumask_remove_table(&info->cpus); in mtk_cpu_dvfs_info_init()
536 if (info->sram_reg) in mtk_cpu_dvfs_info_init()
537 regulator_disable(info->sram_reg); in mtk_cpu_dvfs_info_init()
540 if (info->sram_reg) in mtk_cpu_dvfs_info_init()
541 regulator_put(info->sram_reg); in mtk_cpu_dvfs_info_init()
544 regulator_disable(info->proc_reg); in mtk_cpu_dvfs_info_init()
547 regulator_put(info->proc_reg); in mtk_cpu_dvfs_info_init()
550 clk_put(info->inter_clk); in mtk_cpu_dvfs_info_init()
553 clk_put(info->cpu_clk); in mtk_cpu_dvfs_info_init()
560 regulator_disable(info->proc_reg); in mtk_cpu_dvfs_info_release()
561 regulator_put(info->proc_reg); in mtk_cpu_dvfs_info_release()
562 if (info->sram_reg) { in mtk_cpu_dvfs_info_release()
563 regulator_disable(info->sram_reg); in mtk_cpu_dvfs_info_release()
564 regulator_put(info->sram_reg); in mtk_cpu_dvfs_info_release()
566 clk_disable_unprepare(info->cpu_clk); in mtk_cpu_dvfs_info_release()
567 clk_put(info->cpu_clk); in mtk_cpu_dvfs_info_release()
568 clk_disable_unprepare(info->inter_clk); in mtk_cpu_dvfs_info_release()
569 clk_put(info->inter_clk); in mtk_cpu_dvfs_info_release()
570 dev_pm_opp_of_cpumask_remove_table(&info->cpus); in mtk_cpu_dvfs_info_release()
571 dev_pm_opp_unregister_notifier(info->cpu_dev, &info->opp_nb); in mtk_cpu_dvfs_info_release()
580 info = mtk_cpu_dvfs_info_lookup(policy->cpu); in mtk_cpufreq_init()
583 policy->cpu); in mtk_cpufreq_init()
584 return -EINVAL; in mtk_cpufreq_init()
587 ret = dev_pm_opp_init_cpufreq_table(info->cpu_dev, &freq_table); in mtk_cpufreq_init()
589 dev_err(info->cpu_dev, in mtk_cpufreq_init()
591 policy->cpu, ret); in mtk_cpufreq_init()
595 cpumask_copy(policy->cpus, &info->cpus); in mtk_cpufreq_init()
596 policy->freq_table = freq_table; in mtk_cpufreq_init()
597 policy->driver_data = info; in mtk_cpufreq_init()
598 policy->clk = info->cpu_clk; in mtk_cpufreq_init()
605 struct mtk_cpu_dvfs_info *info = policy->driver_data; in mtk_cpufreq_exit()
607 dev_pm_opp_free_cpufreq_table(info->cpu_dev, &policy->freq_table); in mtk_cpufreq_exit()
620 .name = "mtk-cpufreq",
630 data = dev_get_platdata(&pdev->dev); in mtk_cpufreq_probe()
632 return dev_err_probe(&pdev->dev, -ENODEV, in mtk_cpufreq_probe()
640 info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); in mtk_cpufreq_probe()
642 ret = dev_err_probe(&pdev->dev, -ENOMEM, in mtk_cpufreq_probe()
647 info->soc_data = data; in mtk_cpufreq_probe()
652 list_add(&info->list_head, &dvfs_info_list); in mtk_cpufreq_probe()
657 dev_err_probe(&pdev->dev, ret, "failed to register mtk cpufreq driver\n"); in mtk_cpufreq_probe()
666 list_del(&info->list_head); in mtk_cpufreq_probe()
674 .name = "mtk-cpufreq",
768 return -ENODEV; in mtk_cpufreq_driver_init()
773 pr_debug("Machine is not compatible with mtk-cpufreq\n"); in mtk_cpufreq_driver_init()
774 return -ENODEV; in mtk_cpufreq_driver_init()
776 data = match->data; in mtk_cpufreq_driver_init()
788 cpufreq_pdev = platform_device_register_data(NULL, "mtk-cpufreq", -1, in mtk_cpufreq_driver_init()
791 pr_err("failed to register mtk-cpufreq platform device\n"); in mtk_cpufreq_driver_init()
808 MODULE_AUTHOR("Pi-Cheng Chen <pi-cheng.chen@linaro.org>");