Re: [PATCH V2 2/2] cpufreq: Add Loongson-3 CPUFreq driver support

From: Viresh Kumar
Date: Wed Jul 03 2024 - 23:15:46 EST


On 03-07-24, 22:37, Huacai Chen wrote:
> On Wed, Jul 3, 2024 at 6:18 PM Viresh Kumar <viresh.kumar@xxxxxxxxxx> wrote:
> > > +static int loongson3_cpufreq_target(struct cpufreq_policy *policy, unsigned int index)
> > > +{
> > > + /* setting the cpu frequency */
> > > + return loongson3_cpufreq_set(policy, index);
> >
> > Why use a separate function for calling do_service_request() ? Just
> > open code it here.
> Hmm, there is a loongson3_cpufreq_get() function, so I make a
> loongson3_cpufreq_set() function, too.

The counterpart of _get is _target and so a separate set function
isn't required at all. Just get rid of it.

> > > +static int loongson3_cpufreq_get_freq_table(int cpu)
> > > +{
> > > + int i, ret, boost_level, max_level, freq_level;
> > > + struct cpufreq_frequency_table *table;
> > > +
> > > + if (per_cpu(freq_table, cpu))
> > > + return 0;
> > > +
> > > + ret = do_service_request(cpu, 0, CMD_GET_FREQ_LEVEL_NUM, 0, 0);
> > > + if (ret < 0)
> > > + return ret;
> > > + max_level = ret;
> > > +
> > > + ret = do_service_request(cpu, 0, CMD_GET_FREQ_BOOST_LEVEL, 0, 0);
> > > + if (ret < 0)
> > > + return ret;
> > > + boost_level = ret;
> > > +
> > > + freq_level = min(max_level, FREQ_MAX_LEVEL);
> > > + table = kzalloc(sizeof(struct cpufreq_frequency_table) * (freq_level + 1), GFP_KERNEL);
> >
> > devm_kcalloc(pdev, ...) instead ?
> I remember you told me this in V1, but devm_kalloc() needs a pdev
> instance, which doesn't exist here, so I keep kzalloc().

See how drivers/cpufreq/brcmstb-avs-cpufreq.c stores the pdev in
cpufreq_driver's driver_data and reuses later on.

--
viresh