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 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 ?

Thanks,
Guenter

>  		break;
>  	default:
>  		err = -EOPNOTSUPP;
> @@ -2651,6 +2657,7 @@ static int lm90_probe_channel_from_dt(struct i2c_client *client,
>  				      struct lm90_data *data)
>  {
>  	u32 id;
> +	s32 val;
>  	int err;
>  	struct device *dev = &client->dev;
>  
> @@ -2674,6 +2681,21 @@ static int lm90_probe_channel_from_dt(struct i2c_client *client,
>  	if (data->channel_label[id])
>  		data->channel_config[id] |= HWMON_T_LABEL;
>  
> +	err = of_property_read_s32(child, "temperature-offset-millicelsius", &val);
> +	if (!err) {
> +		if (id == 0) {
> +			dev_err(dev, "offset can't be set for internal channel\n");
> +			return -EINVAL;
> +		}
> +
> +		err = lm90_set_temp_offset(data, id, val);
> +		if (err) {
> +			dev_err(dev, "can't set offset %d for channel %d (%d)\n",
> +				val, id, err);
> +			return err;
> +		}
> +	}
> +
>  	return 0;
>  }
>  



[Index of Archives]     [LM Sensors]     [Linux Sound]     [ALSA Users]     [ALSA Devel]     [Linux Audio Users]     [Linux Media]     [Kernel]     [Gimp]     [Yosemite News]     [Linux Media]

  Powered by Linux