Re: [PATCH V4 05/14] cpufreq: mediatek: Add opp notification support

From: Viresh Kumar
Date: Mon Apr 25 2022 - 01:20:35 EST


On 22-04-22, 15:52, Rex-BC Chen wrote:
> From: "Andrew-sh.Cheng" <andrew-sh.cheng@xxxxxxxxxxxx>
>
> >From this opp notifier, cpufreq should listen to opp notification and do

Why the extra ">" here ?

> proper actions when receiving events of disable and voltage adjustment.
>
> One of the user for this opp notifier is MediaTek SVS.
> The MediaTek Smart Voltage Scaling (SVS) is a hardware which calculates
> suitable SVS bank voltages to OPP voltage table.
>
> Signed-off-by: Andrew-sh.Cheng <andrew-sh.cheng@xxxxxxxxxxxx>
> Signed-off-by: Jia-Wei Chang <jia-wei.chang@xxxxxxxxxxxx>
> Signed-off-by: Rex-BC Chen <rex-bc.chen@xxxxxxxxxxxx>
> Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@xxxxxxxxxxxxx>
> ---
> drivers/cpufreq/mediatek-cpufreq.c | 92 +++++++++++++++++++++++++++---
> 1 file changed, 84 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/cpufreq/mediatek-cpufreq.c b/drivers/cpufreq/mediatek-cpufreq.c
> +static int mtk_cpufreq_opp_notifier(struct notifier_block *nb,
> + unsigned long event, void *data)
> +{
> + struct dev_pm_opp *opp = data;
> + struct dev_pm_opp *new_opp;
> + struct mtk_cpu_dvfs_info *info;
> + unsigned long freq, volt;
> + struct cpufreq_policy *policy;
> + int ret = 0;
> +
> + info = container_of(nb, struct mtk_cpu_dvfs_info, opp_nb);
> +
> + if (event == OPP_EVENT_ADJUST_VOLTAGE) {

I don't see any call to dev_pm_opp_adjust_voltage() for your platform, how is
this ever going to get called ?

> + freq = dev_pm_opp_get_freq(opp);
> +
> + mutex_lock(&info->reg_lock);
> + if (info->opp_freq == freq) {
> + volt = dev_pm_opp_get_voltage(opp);
> + ret = mtk_cpufreq_set_voltage(info, volt);
> + if (ret)
> + dev_err(info->cpu_dev,
> + "failed to scale voltage: %d\n", ret);
> + }
> + mutex_unlock(&info->reg_lock);
> + } else if (event == OPP_EVENT_DISABLE) {
> + freq = dev_pm_opp_get_freq(opp);
> +
> + /* case of current opp item is disabled */
> + if (info->opp_freq == freq) {
> + freq = 1;
> + new_opp = dev_pm_opp_find_freq_ceil(info->cpu_dev,
> + &freq);
> + if (IS_ERR(new_opp)) {
> + dev_err(info->cpu_dev,
> + "all opp items are disabled\n");
> + ret = PTR_ERR(new_opp);
> + return notifier_from_errno(ret);
> + }
> +
> + dev_pm_opp_put(new_opp);
> + policy = cpufreq_cpu_get(info->opp_cpu);
> + if (policy) {
> + cpufreq_driver_target(policy, freq / 1000,
> + CPUFREQ_RELATION_L);
> + cpufreq_cpu_put(policy);

IIUC, then you are trying to change the frequency if a currently used OPP is
getting removed ? In that case, this problem is generic enough not to be fixed
in a end driver. This should be fixed in core somehow.

--
viresh