Re: [hwmon PATCH v3 6/6] hwmon: (adt7470) Use cached PWM frequency value

From: Luiz Angelo Daros de Luca

Date: Mon Jul 27 2026 - 14:47:23 EST


Em seg., 27 de jul. de 2026 às 11:33, Guenter Roeck
<linux@xxxxxxxxxxxx> escreveu:
>
> On 7/26/26 20:34, Luiz Angelo Daros de Luca wrote:
> > adt7470_pwm_read() currently ignores failures returned by
> > pwm1_freq_get(). If the register read fails, the negative error code is
> > returned through *val while the function itself reports success,
> > potentially exposing a negative PWM frequency through sysfs.
> >
> > Fix this by using the cached PWM frequency maintained by the driver,
> > eliminating the register access from the read path.
> >
> > Apart from the corrected error propagation and using the cached value,
> > no functional change is intended.
> >
>
> An alternative might be to use regmap for caching and drop all driver-internal
> caching. I have done that for other drivers; typically it simplifies the code,
> sometimes significantly, since the update_device() function is no longer needed.
> Something to consider for later, maybe.

That definitely sounds like a nice upgrade to consider!

I haven't used regmap's caching feature before, so I'm not entirely
sure how cache expiration is typically handled. In adt7470, caching is
mainly used for volatile readings because hardware access over
SMBus/I2C is quite slow. On my device (which might be an extreme
case), reading all registers can take over a second.

What would be the recommended strategy here? Would it be caching all
registers and periodically calling regcache_drop_region() (or mark
them volatile) to force a refresh?

Regards,

Luiz