Re: [PATCH 3/3] scsi: ufs: core: Report the current clock frequency to devfreq

From: Stanley Jhu

Date: Mon Aug 31 2026 - 21:43:40 EST


On Mon, 31 Aug 2026 15:01:29 +0200, Bean Huo wrote:
> + /*
> + * target_freq stays 0 until something scales the controller for the
> + * first time. Report nothing rather than 0 so devfreq falls back to
> + * the frequency it last set.
> + */
> + if (!cur_freq)
> + return -EINVAL;

If ufshcd_devfreq_get_cur_freq() returns -EINVAL here, devfreq falls back
to devfreq->previous_freq. However, because UFS does not set
devfreq_profile.initial_freq, previous_freq is also 0 at boot. On platforms
with use_pm_opp=true, the initial sysfs read or the first transition before
scaling still ends up seeing 0 Hz.

Would it be cleaner to initialize hba->clk_scaling.target_freq and
devfreq_profile.initial_freq to the max frequency in ufshcd_devfreq_init()?
That way, cur_freq is valid from the start and we wouldn't need to handle
the !cur_freq case here.

Thanks,
Stanley Jhu