Lines Matching +full:devfreq +full:- +full:event

1 // SPDX-License-Identifier: GPL-2.0-only
7 #include <linux/devfreq.h>
25 struct devfreq *devfreq; member
41 const struct mtk_ccifreq_platform_data *soc_data = drv->soc_data; in mtk_ccifreq_set_voltage()
42 struct device *dev = drv->dev; in mtk_ccifreq_set_voltage()
44 int retry_max = drv->vtrack_max; in mtk_ccifreq_set_voltage()
46 if (!drv->sram_reg) { in mtk_ccifreq_set_voltage()
47 ret = regulator_set_voltage(drv->proc_reg, new_voltage, in mtk_ccifreq_set_voltage()
48 drv->soc_data->proc_max_volt); in mtk_ccifreq_set_voltage()
52 pre_voltage = regulator_get_voltage(drv->proc_reg); in mtk_ccifreq_set_voltage()
58 pre_vsram = regulator_get_voltage(drv->sram_reg); in mtk_ccifreq_set_voltage()
64 new_vsram = clamp(new_voltage + soc_data->min_volt_shift, in mtk_ccifreq_set_voltage()
65 soc_data->sram_min_volt, soc_data->sram_max_volt); in mtk_ccifreq_set_voltage()
69 vsram = clamp(pre_voltage + soc_data->max_volt_shift, in mtk_ccifreq_set_voltage()
70 soc_data->sram_min_volt, new_vsram); in mtk_ccifreq_set_voltage()
71 ret = regulator_set_voltage(drv->sram_reg, vsram, in mtk_ccifreq_set_voltage()
72 soc_data->sram_max_volt); in mtk_ccifreq_set_voltage()
76 if (vsram == soc_data->sram_max_volt || in mtk_ccifreq_set_voltage()
77 new_vsram == soc_data->sram_min_volt) in mtk_ccifreq_set_voltage()
80 voltage = vsram - soc_data->min_volt_shift; in mtk_ccifreq_set_voltage()
82 ret = regulator_set_voltage(drv->proc_reg, voltage, in mtk_ccifreq_set_voltage()
83 soc_data->proc_max_volt); in mtk_ccifreq_set_voltage()
85 regulator_set_voltage(drv->sram_reg, pre_vsram, in mtk_ccifreq_set_voltage()
86 soc_data->sram_max_volt); in mtk_ccifreq_set_voltage()
91 pre_vsram - soc_data->max_volt_shift); in mtk_ccifreq_set_voltage()
92 ret = regulator_set_voltage(drv->proc_reg, voltage, in mtk_ccifreq_set_voltage()
93 soc_data->proc_max_volt); in mtk_ccifreq_set_voltage()
101 voltage + soc_data->min_volt_shift); in mtk_ccifreq_set_voltage()
103 ret = regulator_set_voltage(drv->sram_reg, vsram, in mtk_ccifreq_set_voltage()
104 soc_data->sram_max_volt); in mtk_ccifreq_set_voltage()
106 regulator_set_voltage(drv->proc_reg, pre_voltage, in mtk_ccifreq_set_voltage()
107 soc_data->proc_max_volt); in mtk_ccifreq_set_voltage()
115 if (--retry_max < 0) { in mtk_ccifreq_set_voltage()
118 return -EINVAL; in mtk_ccifreq_set_voltage()
135 return -EINVAL; in mtk_ccifreq_target()
137 if (drv->pre_freq == *freq) in mtk_ccifreq_target()
140 mutex_lock(&drv->reg_lock); in mtk_ccifreq_target()
142 inter_voltage = drv->inter_voltage; in mtk_ccifreq_target()
143 cci_pll = clk_get_parent(drv->cci_clk); in mtk_ccifreq_target()
156 pre_voltage = regulator_get_voltage(drv->proc_reg); in mtk_ccifreq_target()
174 ret = clk_set_parent(drv->cci_clk, drv->inter_clk); in mtk_ccifreq_target()
176 dev_err(dev, "failed to re-parent cci clock\n"); in mtk_ccifreq_target()
184 clk_set_parent(drv->cci_clk, cci_pll); in mtk_ccifreq_target()
189 ret = clk_set_parent(drv->cci_clk, cci_pll); in mtk_ccifreq_target()
191 dev_err(dev, "failed to re-parent cci clock\n"); in mtk_ccifreq_target()
208 drv->pre_freq = *freq; in mtk_ccifreq_target()
209 mutex_unlock(&drv->reg_lock); in mtk_ccifreq_target()
217 mutex_unlock(&drv->reg_lock); in mtk_ccifreq_target()
222 unsigned long event, void *data) in mtk_ccifreq_opp_notifier() argument
230 if (event == OPP_EVENT_ADJUST_VOLTAGE) { in mtk_ccifreq_opp_notifier()
231 mutex_lock(&drv->reg_lock); in mtk_ccifreq_opp_notifier()
235 if (freq == drv->pre_freq) { in mtk_ccifreq_opp_notifier()
239 mutex_unlock(&drv->reg_lock); in mtk_ccifreq_opp_notifier()
251 struct device *dev = &pdev->dev; in mtk_ccifreq_probe()
260 return -ENOMEM; in mtk_ccifreq_probe()
262 drv->dev = dev; in mtk_ccifreq_probe()
263 drv->soc_data = (const struct mtk_ccifreq_platform_data *) in mtk_ccifreq_probe()
264 of_device_get_match_data(&pdev->dev); in mtk_ccifreq_probe()
265 mutex_init(&drv->reg_lock); in mtk_ccifreq_probe()
268 drv->cci_clk = devm_clk_get(dev, "cci"); in mtk_ccifreq_probe()
269 if (IS_ERR(drv->cci_clk)) { in mtk_ccifreq_probe()
270 ret = PTR_ERR(drv->cci_clk); in mtk_ccifreq_probe()
274 drv->inter_clk = devm_clk_get(dev, "intermediate"); in mtk_ccifreq_probe()
275 if (IS_ERR(drv->inter_clk)) { in mtk_ccifreq_probe()
276 ret = PTR_ERR(drv->inter_clk); in mtk_ccifreq_probe()
281 drv->proc_reg = devm_regulator_get_optional(dev, "proc"); in mtk_ccifreq_probe()
282 if (IS_ERR(drv->proc_reg)) { in mtk_ccifreq_probe()
283 ret = PTR_ERR(drv->proc_reg); in mtk_ccifreq_probe()
288 ret = regulator_enable(drv->proc_reg); in mtk_ccifreq_probe()
294 drv->sram_reg = devm_regulator_get_optional(dev, "sram"); in mtk_ccifreq_probe()
295 if (IS_ERR(drv->sram_reg)) { in mtk_ccifreq_probe()
296 ret = PTR_ERR(drv->sram_reg); in mtk_ccifreq_probe()
297 if (ret == -EPROBE_DEFER) in mtk_ccifreq_probe()
300 drv->sram_reg = NULL; in mtk_ccifreq_probe()
302 ret = regulator_enable(drv->sram_reg); in mtk_ccifreq_probe()
314 drv->vtrack_max = 3 * DIV_ROUND_UP(max(drv->soc_data->sram_max_volt, in mtk_ccifreq_probe()
315 drv->soc_data->proc_max_volt), in mtk_ccifreq_probe()
316 drv->soc_data->min_volt_shift); in mtk_ccifreq_probe()
318 ret = clk_prepare_enable(drv->cci_clk); in mtk_ccifreq_probe()
328 rate = clk_get_rate(drv->inter_clk); in mtk_ccifreq_probe()
335 drv->inter_voltage = dev_pm_opp_get_voltage(opp); in mtk_ccifreq_probe()
339 opp = dev_pm_opp_find_freq_floor(drv->dev, &rate); in mtk_ccifreq_probe()
357 ret = -ENOMEM; in mtk_ccifreq_probe()
361 passive_data->parent_type = CPUFREQ_PARENT_DEV; in mtk_ccifreq_probe()
362 drv->devfreq = devm_devfreq_add_device(dev, &mtk_ccifreq_profile, in mtk_ccifreq_probe()
365 if (IS_ERR(drv->devfreq)) { in mtk_ccifreq_probe()
366 ret = -EPROBE_DEFER; in mtk_ccifreq_probe()
367 dev_err(dev, "failed to add devfreq device: %ld\n", in mtk_ccifreq_probe()
368 PTR_ERR(drv->devfreq)); in mtk_ccifreq_probe()
372 drv->opp_nb.notifier_call = mtk_ccifreq_opp_notifier; in mtk_ccifreq_probe()
373 ret = dev_pm_opp_register_notifier(dev, &drv->opp_nb); in mtk_ccifreq_probe()
384 clk_disable_unprepare(drv->cci_clk); in mtk_ccifreq_probe()
387 if (regulator_is_enabled(drv->proc_reg)) in mtk_ccifreq_probe()
388 regulator_disable(drv->proc_reg); in mtk_ccifreq_probe()
389 if (drv->sram_reg && regulator_is_enabled(drv->sram_reg)) in mtk_ccifreq_probe()
390 regulator_disable(drv->sram_reg); in mtk_ccifreq_probe()
397 struct device *dev = &pdev->dev; in mtk_ccifreq_remove()
402 dev_pm_opp_unregister_notifier(dev, &drv->opp_nb); in mtk_ccifreq_remove()
404 clk_disable_unprepare(drv->cci_clk); in mtk_ccifreq_remove()
405 regulator_disable(drv->proc_reg); in mtk_ccifreq_remove()
406 if (drv->sram_reg) in mtk_ccifreq_remove()
407 regulator_disable(drv->sram_reg); in mtk_ccifreq_remove()
425 { .compatible = "mediatek,mt8183-cci", .data = &mt8183_platform_data },
426 { .compatible = "mediatek,mt8186-cci", .data = &mt8186_platform_data },
435 .name = "mtk-ccifreq",
441 MODULE_DESCRIPTION("MediaTek CCI devfreq driver");
442 MODULE_AUTHOR("Jia-Wei Chang <jia-wei.chang@mediatek.com>");