Re: [PATCH 7/7] hwmon: (lm90) Read the channel's temperature offset from device-tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
> > 
> > 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@xxxxxxxxx>
> > ---
> >  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



[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]


  Powered by Linux