Re: [PATCH V2 13/15] cpufreq: mediatek: Link CCI device to CPU
From: Rex-BC Chen
Date: Mon Apr 11 2022 - 07:50:20 EST
On Fri, 2022-04-08 at 15:37 +0200, AngeloGioacchino Del Regno wrote:
> Il 08/04/22 06:59, Rex-BC Chen ha scritto:
> > From: Jia-Wei Chang <jia-wei.chang@xxxxxxxxxxxx>
> >
> > In some MediaTek SoCs, like MT8183, CPU and CCI share the same
> > power
> > supplies. Cpufreq needs to check if CCI devfreq exists and wait
> > until
> > CCI devfreq ready before scaling frequency.
> >
> > - Add is_ccifreq_ready() to link CCI device to CPI, and CPU will
> > start
> > DVFS when CCI is ready.
> > - Add platform data for MT8183.
> >
> > Signed-off-by: Jia-Wei Chang <jia-wei.chang@xxxxxxxxxxxx>
> > ---
> > drivers/cpufreq/mediatek-cpufreq.c | 69
> > +++++++++++++++++++++++++++++-
> > 1 file changed, 68 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/cpufreq/mediatek-cpufreq.c
> > b/drivers/cpufreq/mediatek-cpufreq.c
> > index b08ab7c14818..cebe5af2ef5d 100644
> > --- a/drivers/cpufreq/mediatek-cpufreq.c
> > +++ b/drivers/cpufreq/mediatek-cpufreq.c
> > @@ -22,6 +22,7 @@ struct mtk_cpufreq_platform_data {
> > int proc_max_volt;
> > int sram_min_volt;
> > int sram_max_volt;
> > + bool is_ccifreq_support;
>
> bool ccifreq_supported; looks better.
Hello Angelo,
Thanks for your review.
OK, I will modify this in next version.
>
> > };
> >
> > /*
> > @@ -38,6 +39,7 @@ struct mtk_cpufreq_platform_data {
> > struct mtk_cpu_dvfs_info {
> > struct cpumask cpus;
> > struct device *cpu_dev;
> > + struct device *cci_dev;
> > struct regulator *proc_reg;
> > struct regulator *sram_reg;
> > struct clk *cpu_clk;
> > @@ -52,6 +54,7 @@ struct mtk_cpu_dvfs_info {
> > int opp_cpu;
> > unsigned long opp_freq;
> > const struct mtk_cpufreq_platform_data *soc_data;
> > + bool is_ccifreq_bounded;
>
> bool ccifreq_bound; looks better.
>
OK, I will modify this in next version.
> > };
> >
> > static struct platform_device *cpufreq_pdev;
> > @@ -171,6 +174,29 @@ static int mtk_cpufreq_set_voltage(struct
> > mtk_cpu_dvfs_info *info, int vproc)
> > return ret;
> > }
> >
> > +static bool is_ccifreq_ready(struct mtk_cpu_dvfs_info *info)
> > +{
> > + struct device_link *sup_link;
> > +
> > + if (info->is_ccifreq_bounded)
> > + return true;
> > +
> > + sup_link = device_link_add(info->cpu_dev, info->cci_dev,
> > + DL_FLAG_AUTOREMOVE_CONSUMER);
> > + if (!sup_link) {
> > + dev_err(info->cpu_dev, "cpu%d: sup_link is NULL\n",
> > + info->opp_cpu);
>
> Please, don't break this line: 84 columns are ok.
>
OK, I will modify this in next version.
> > + return false;
> > + }
> > +
> > + if (sup_link->supplier->links.status != DL_DEV_DRIVER_BOUND)
> > + return false;
> > +
> > + info->is_ccifreq_bounded = true;
> > +
> > + return true;
> > +}
> > +
> > static int mtk_cpufreq_set_target(struct cpufreq_policy *policy,
> > unsigned int index)
> > {
> > @@ -183,6 +209,9 @@ static int mtk_cpufreq_set_target(struct
> > cpufreq_policy *policy,
> > long freq_hz, old_freq_hz;
> > int vproc, old_vproc, inter_vproc, target_vproc, ret;
> >
> > + if (info->soc_data->is_ccifreq_support &&
> > !is_ccifreq_ready(info))
> > + return 0;
>
> Honestly, I think that pretending that everything is alright and
> faking
> set_target success is *not* a good idea...
>
> You should return -EAGAIN here, not zero.
>
> Regards,
> Angelo
>
As metioneded by Kevin, I will review these three situations.
Thanks for your suggestion.
BRs,
Rex