devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Slawomir Stepien <sst@poczta.fm>
Cc: linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org,
	jdelvare@suse.com, robh+dt@kernel.org,
	krzysztof.kozlowski+dt@linaro.org, przemyslaw.cencner@nokia.com,
	krzysztof.adamski@nokia.com, alexander.sverdlin@nokia.com,
	slawomir.stepien@nokia.com
Subject: Re: [PATCH 4/7] hwmon: (lm90) Add support for 2nd remote channel's offset register
Date: Sun, 5 Jun 2022 11:03:10 -0700	[thread overview]
Message-ID: <20220605180310.GA3151289@roeck-us.net> (raw)
In-Reply-To: <20220525073657.573327-5-sst@poczta.fm>

On Wed, May 25, 2022 at 09:36:54AM +0200, Slawomir Stepien wrote:
> From: Slawomir Stepien <slawomir.stepien@nokia.com>
> 
> The ADT7461 supports offset register for both remote channels it has.

ADT7481

> Both registers have the same bit width (resolution).
> 
> In the code, this device has LM90_HAVE_TEMP3 and LM90_HAVE_OFFSET flags,
> but the support of second remote channel's offset is missing. Add that
> implementation.
> 
> Signed-off-by: Slawomir Stepien <slawomir.stepien@nokia.com>
> ---
>  drivers/hwmon/lm90.c | 37 ++++++++++++++++++++++++++++++++-----
>  1 file changed, 32 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c
> index 02b211a4e571..d226f1dea2ba 100644
> --- a/drivers/hwmon/lm90.c
> +++ b/drivers/hwmon/lm90.c
> @@ -153,6 +153,8 @@ enum chips { adm1023, adm1032, adt7461, adt7461a, adt7481,
>  #define LM90_REG_REMOTE_TEMPL		0x10
>  #define LM90_REG_REMOTE_OFFSH		0x11
>  #define LM90_REG_REMOTE_OFFSL		0x12
> +#define LM90_REG_REMOTE2_OFFSH		0x34
> +#define LM90_REG_REMOTE2_OFFSL		0x35

I don't think those are needed.

>  #define LM90_REG_REMOTE_HIGHH		0x07
>  #define LM90_REG_REMOTE_HIGHL		0x13
>  #define LM90_REG_REMOTE_LOWH		0x08
> @@ -669,6 +671,7 @@ enum lm90_temp_reg_index {
>  	REMOTE2_TEMP,	/* max6695/96 only */
>  	REMOTE2_LOW,	/* max6695/96 only */
>  	REMOTE2_HIGH,	/* max6695/96 only */
> +	REMOTE2_OFFSET,
>  
>  	TEMP_REG_NUM
>  };
> @@ -1024,6 +1027,14 @@ static int lm90_update_limits(struct device *dev)
>  			return val;
>  		data->temp[REMOTE2_HIGH] = val << 8;
>  
> +		if (data->flags & LM90_HAVE_OFFSET) {
> +			val = lm90_read16(client, LM90_REG_REMOTE2_OFFSH,
> +					  LM90_REG_REMOTE2_OFFSL, false);

Why not use LM90_REG_REMOTE_OFFSH and LM90_REG_REMOTE_OFFSL ?
The remove channel is selected here, after all.

> +			if (val < 0)
> +				return val;
> +			data->temp[REMOTE2_OFFSET] = val;
> +		}
> +
>  		lm90_select_remote_channel(data, false);
>  	}
>  
> @@ -1294,6 +1305,7 @@ static int lm90_temp_get_resolution(struct lm90_data *data, int index)
>  			return data->resolution;
>  		return 8;
>  	case REMOTE_OFFSET:
> +	case REMOTE2_OFFSET:
>  	case REMOTE2_TEMP:
>  		return data->resolution;
>  	case LOCAL_TEMP:
> @@ -1515,8 +1527,13 @@ static int lm90_temp_read(struct device *dev, u32 attr, int channel, long *val)
>  		*val = lm90_get_temphyst(data, lm90_temp_emerg_index[channel], channel);
>  		break;
>  	case hwmon_temp_offset:
> -		*val = lm90_temp_from_reg(0, data->temp[REMOTE_OFFSET],
> -					  lm90_temp_get_resolution(data, REMOTE_OFFSET));
> +		/* Both offset registers have the same resolution */
> +		int res = lm90_temp_get_resolution(data, REMOTE_OFFSET);
> +
> +		if (channel == 1)
> +			*val = lm90_temp_from_reg(0, data->temp[REMOTE_OFFSET], res);
> +		else
> +			*val = lm90_temp_from_reg(0, data->temp[REMOTE2_OFFSET], res);

I would prefer the use of lm90_temp_offset_index[] as implemented for the
other attributes.

>  		break;
>  	default:
>  		return -EOPNOTSUPP;
> @@ -1556,11 +1573,19 @@ static int lm90_temp_write(struct device *dev, u32 attr, int channel, long val)
>  				    channel, val);
>  		break;
>  	case hwmon_temp_offset:
> +		/* Both offset registers have the same resolution */
>  		val = lm90_temp_to_reg(0, val,
>  				       lm90_temp_get_resolution(data, REMOTE_OFFSET));
> -		data->temp[REMOTE_OFFSET] = val;
> -		err = lm90_write16(data->client, LM90_REG_REMOTE_OFFSH,
> -				   LM90_REG_REMOTE_OFFSL, val);
> +
> +		if (channel == 1) {
> +			data->temp[REMOTE_OFFSET] = val;
> +			err = lm90_write16(data->client, LM90_REG_REMOTE_OFFSH,
> +					   LM90_REG_REMOTE_OFFSL, val);
> +		} else {
> +			data->temp[REMOTE2_OFFSET] = val;
> +			err = lm90_write16(data->client, LM90_REG_REMOTE2_OFFSH,
> +					   LM90_REG_REMOTE2_OFFSL, val);
> +		}

Same as above.

Thanks,
Guenter

>  		break;
>  	default:
>  		err = -EOPNOTSUPP;
> @@ -2733,6 +2758,8 @@ static int lm90_probe(struct i2c_client *client)
>  		}
>  		if (data->flags & LM90_HAVE_EMERGENCY_ALARM)
>  			data->channel_config[2] |= HWMON_T_EMERGENCY_ALARM;
> +		if (data->flags & LM90_HAVE_OFFSET)
> +			data->channel_config[2] |= HWMON_T_OFFSET;
>  	}
>  
>  	data->faultqueue_mask = lm90_params[data->kind].faultqueue_mask;

  reply	other threads:[~2022-06-05 18:03 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-25  7:36 Extend the device-tree binding for lm90 Slawomir Stepien
2022-05-25  7:36 ` [PATCH 1/7] dt-bindings: hwmon: Add compatible string for ADT7481 in lm90 Slawomir Stepien
2022-05-26  1:54   ` Rob Herring
2022-06-05 17:52   ` Guenter Roeck
2022-05-25  7:36 ` [PATCH 2/7] dt-bindings: hwmon: Allow specifying channels for lm90 Slawomir Stepien
2022-05-26  1:55   ` Rob Herring
2022-06-05 17:53   ` Guenter Roeck
2022-05-25  7:36 ` [PATCH 3/7] hwmon: (lm90) Add compatible entry for adt7481 Slawomir Stepien
2022-06-05 17:54   ` Guenter Roeck
2022-05-25  7:36 ` [PATCH 4/7] hwmon: (lm90) Add support for 2nd remote channel's offset register Slawomir Stepien
2022-06-05 18:03   ` Guenter Roeck [this message]
2022-06-06  6:30     ` Slawomir Stepien
2022-06-06  6:50       ` Guenter Roeck
2022-06-06  6:56         ` Slawomir Stepien
2022-06-06 12:14         ` Slawomir Stepien
2022-06-06 14:15           ` Guenter Roeck
2022-05-25  7:36 ` [PATCH 5/7] hwmon: (lm90) Define maximum number of channels that are supported Slawomir Stepien
2022-06-05 18:05   ` Guenter Roeck
2022-05-25  7:36 ` [PATCH 6/7] hwmon: (lm90) Read the channel's label from device-tree Slawomir Stepien
2022-06-05 18:06   ` Guenter Roeck
2022-05-25  7:36 ` [PATCH 7/7] hwmon: (lm90) Read the channel's temperature offset " Slawomir Stepien
2022-06-05 18:10   ` Guenter Roeck
2022-06-06  6:32     ` Slawomir Stepien

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220605180310.GA3151289@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=alexander.sverdlin@nokia.com \
    --cc=devicetree@vger.kernel.org \
    --cc=jdelvare@suse.com \
    --cc=krzysztof.adamski@nokia.com \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=przemyslaw.cencner@nokia.com \
    --cc=robh+dt@kernel.org \
    --cc=slawomir.stepien@nokia.com \
    --cc=sst@poczta.fm \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).