Re: [RFC PATCH v2 2/4] hwmon: (jc42) Convert to regmap's built-in caching
From: Guenter Roeck
Date: Thu Oct 20 2022 - 18:05:02 EST
On Thu, Oct 20, 2022 at 11:03:18PM +0200, Martin Blumenstingl wrote:
> Move over to regmap's built-in caching instead of adding a custom
> caching implementation. This works for JC42_REG_TEMP_UPPER,
> JC42_REG_TEMP_LOWER and JC42_REG_TEMP_CRITICAL as these values never
> change except when explicitly written. For JC42_REG_TEMP a cache
> variable is still kept as regmap cannot cache this register (because
> it's volatile, meaning it can change at any time).
>
Just drop that one as well, together with jc42_update_device(),
and read the temperature directly where needed. In practice
caching of 'hot' registers isn't really worth the trouble.
Thanks,
Guenter
> Signed-off-by: Martin Blumenstingl <martin.blumenstingl@xxxxxxxxxxxxxx>
> ---
> drivers/hwmon/jc42.c | 97 ++++++++++++++++++++++++--------------------
> 1 file changed, 54 insertions(+), 43 deletions(-)
>
> diff --git a/drivers/hwmon/jc42.c b/drivers/hwmon/jc42.c
> index 329a80264556..3f524ab5451c 100644
> --- a/drivers/hwmon/jc42.c
> +++ b/drivers/hwmon/jc42.c
> @@ -200,21 +200,6 @@ static struct jc42_chips jc42_chips[] = {
> { STM_MANID, STTS3000_DEVID, STTS3000_DEVID_MASK },
> };
>
> -enum temp_index {
> - t_input = 0,
> - t_crit,
> - t_min,
> - t_max,
> - t_num_temp
> -};
> -
> -static const u8 temp_regs[t_num_temp] = {
> - [t_input] = JC42_REG_TEMP,
> - [t_crit] = JC42_REG_TEMP_CRITICAL,
> - [t_min] = JC42_REG_TEMP_LOWER,
> - [t_max] = JC42_REG_TEMP_UPPER,
> -};
> -
> /* Each client has this additional data */
> struct jc42_data {
> struct regmap *regmap;
> @@ -224,7 +209,7 @@ struct jc42_data {
> unsigned long last_updated; /* In jiffies */
> u16 orig_config; /* original configuration */
> u16 config; /* current configuration */
> - u16 temp[t_num_temp];/* Temperatures */
> + u16 temp; /* Cached temperature register value */