devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Slawomir Stepien <sst@poczta.fm>
To: Guenter Roeck <linux@roeck-us.net>
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 7/7] hwmon: (lm90) Read the channel's temperature offset from device-tree
Date: Mon, 6 Jun 2022 08:32:29 +0200	[thread overview]
Message-ID: <Yp2fffZCISn7eRO/@t480s.localdomain> (raw)
In-Reply-To: <20220605181005.GA3151885@roeck-us.net>

On cze 05, 2022 11:10, Guenter Roeck wrote:
> On Wed, May 25, 2022 at 09:36:57AM +0200, Slawomir Stepien wrote:
> > From: Slawomir Stepien <slawomir.stepien@nokia.com>
> > 
> > Try to read the channel's temperature offset from device-tree. Having
> > offset in device-tree node is not mandatory. The offset can only be set
> > for remote channels.
> > 
> > Signed-off-by: Slawomir Stepien <slawomir.stepien@nokia.com>
> > ---
> >  drivers/hwmon/lm90.c | 48 ++++++++++++++++++++++++++++++++------------
> >  1 file changed, 35 insertions(+), 13 deletions(-)
> > 
> > diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c
> > index 3837c4ab5833..12e8e874f1b9 100644
> > --- a/drivers/hwmon/lm90.c
> > +++ b/drivers/hwmon/lm90.c
> > @@ -1440,6 +1440,24 @@ static int lm90_set_temphyst(struct lm90_data *data, long val)
> >  	return lm90_write_reg(data->client, LM90_REG_TCRIT_HYST, data->temp_hyst);
> >  }
> >  
> > +static int lm90_set_temp_offset(struct lm90_data *data, int channel, long val)
> > +{
> > +	/* Both offset registers have the same resolution */
> > +	int res = lm90_temp_get_resolution(data, REMOTE_OFFSET);
> > +
> > +	val = lm90_temp_to_reg(0, val, res);
> > +
> > +	if (channel == 1) {
> > +		data->temp[REMOTE_OFFSET] = val;
> > +		return lm90_write16(data->client, LM90_REG_REMOTE_OFFSH,
> > +				    LM90_REG_REMOTE_OFFSL, val);
> > +	}
> > +
> > +	data->temp[REMOTE2_OFFSET] = val;
> > +	return lm90_write16(data->client, LM90_REG_REMOTE2_OFFSH,
> > +			    LM90_REG_REMOTE2_OFFSL, val);
> > +}
> > +
> >  static const u8 lm90_temp_index[MAX_CHANNELS] = {
> >  	LOCAL_TEMP, REMOTE_TEMP, REMOTE2_TEMP
> >  };
> > @@ -1577,19 +1595,7 @@ 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));
> > -
> > -		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);
> > -		}
> > +		err = lm90_set_temp_offset(data, channel, val);
> 
> Any chance to come up with more unified handling of both channels ?

I will give it a try.

-- 
Slawomir Stepien

      reply	other threads:[~2022-06-06  6:32 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
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 [this message]

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=Yp2fffZCISn7eRO/@t480s.localdomain \
    --to=sst@poczta.fm \
    --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=linux@roeck-us.net \
    --cc=przemyslaw.cencner@nokia.com \
    --cc=robh+dt@kernel.org \
    --cc=slawomir.stepien@nokia.com \
    /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).