hwmon: (lm95245) Fix hysteresis temperatures
Guenter Roeck
maintainerPATCH 1/2 hwmon: (lm95245) Fix hysteresis temperatures
Hysteresis temperatures are defined as absolute temperatures, not as delta value from the critical temperatures.
--- drivers/hwmon/lm95245.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-)
drivers/hwmon/lm95245.c +21 -9
@@ -272,19 +272,31 @@ static ssize_t set_limit(struct device *dev, struct device_attribute *attr,return count; } +static ssize_t show_crit_hyst (struct device *dev,struct device_attribute *attr, +char *buf) +{ +struct lm95245_data *data =lm95245_update_device (dev); +int index =to_sensor_dev_attr (attr)->index; +int hyst = data->regs[index] - data->regs[8 ]; + +return snprintf (buf,PAGE_SIZE -1 ,"%d\n" , hyst *1000 ); +} +static ssize_t set_crit_hyst (struct device *dev,struct device_attribute *attr, -const char *buf,size_t count) +const char *buf,size_t count) { +struct lm95245_data *data =lm95245_update_device (dev);struct i2c_client *client =to_i2c_client (dev); -struct lm95245_data *data =i2c_get_clientdata (client); +int index =to_sensor_dev_attr (attr)->index;unsigned long val; +long hyst;if (kstrtoul (buf,10 , &val) <0 )return -EINVAL ; val /=1000 ; - - val =clamp_val (val,0 ,31 ); + hyst = data->regs[index] - val; + hyst =clamp_val (hyst,0 ,31 );mutex_lock (&data->update_lock);
@@ -292,7 +304,7 @@ static ssize_t set_crit_hyst(struct device *dev, struct device_attribute *attr,/* shared crit hysteresis */ i2c_smbus_write_byte_data (client,LM95245_REG_RW_COMMON_HYSTERESIS , - val); + val);mutex_unlock (&data->update_lock);
@@ -378,16 +390,16 @@ static ssize_t set_interval(struct device *dev, struct device_attribute *attr, static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_input, NULL, 0); static SENSOR_DEVICE_ATTR(temp1_crit, S_IWUSR | S_IRUGO, show_limit, set_limit, 6); -static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, show_limit, - set_crit_hyst, 8); +static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, show_crit_hyst, + set_crit_hyst, 6); static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, STATUS1_LOC); static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_input, NULL, 2); static SENSOR_DEVICE_ATTR(temp2_crit, S_IWUSR | S_IRUGO, show_limit, set_limit, 7); -static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IWUSR | S_IRUGO, show_limit, - set_crit_hyst, 8); +static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IWUSR | S_IRUGO, show_crit_hyst, + set_crit_hyst, 7); static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL, STATUS1_RTCRIT); static SENSOR_DEVICE_ATTR(temp2_type, S_IWUSR | S_IRUGO, show_type,
Signature · 7 lines
1.7.9.7 _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Hi Guenter,
Sorry for the late review.
Quoted 19 lines · Guenter Roeck
Hysteresis temperatures are defined as absolute temperatures, not as delta value from the critical temperatures.
Signed-off-by Guenter Roeck <[email protected]>--- drivers/hwmon/lm95245.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-)drivers/hwmon/lm95245.c +3
-0@@ -272,19 +272,31 @@ static ssize_t set_limit(struct device *dev, struct device_attribute *attr,return count; } +static ssize_t show_crit_hyst (struct device *dev,struct device_attribute *attr, +char *buf) +{
drivers/hwmon/lm95245.c static ssize_t set_limit(struct device *dev, struct device_attribute *attr, · line 286
Quoted 10 lines
drivers/hwmon/lm95245.c +8
-1+struct lm95245_data *data =lm95245_update_device (dev); +int index =to_sensor_dev_attr (attr)->index; +int hyst = data->regs[index] - data->regs[8 ]; + +return snprintf (buf,PAGE_SIZE -1 ,"%d\n" , hyst *1000 ); +} +static ssize_t set_crit_hyst (struct device *dev,struct device_attribute *attr, -const char *buf,size_t count) +const char *buf,size_t count)
These reindentations do not belong to this patch - if they are needed at all. The same style is used everywhere in the driver and while it's not my preferred one either, it's used quite consistently as far as I can tell. I would leave it as is. If it really bothers you then you should "fix" the whole driver with a separate patch.
drivers/hwmon/lm95245.c static ssize_t set_limit(struct device *dev, struct device_attribute *attr, · line 288
Quoted 2 lines
drivers/hwmon/lm95245.c +1
-0{ +struct lm95245_data *data =lm95245_update_device (dev);
Calling the update function in "set" callbacks is discouraged. Set functions are typically called at boot time. The update function can be quite slow as it reads a lot of registers over slow I2C/SMBus.
Admittedly the number of registers of this particular chip isn't too high so the effect is limited, but you should still consider the option of only reading the register value you need.
Quoted 34 lines
drivers/hwmon/lm95245.c +7
-6struct i2c_client *client =to_i2c_client (dev); -struct lm95245_data *data =i2c_get_clientdata (client); +int index =to_sensor_dev_attr (attr)->index;unsigned long val; +long hyst;if (kstrtoul (buf,10 , &val) <0 )return -EINVAL ; val /=1000 ; - - val =clamp_val (val,0 ,31 ); + hyst = data->regs[index] - val; + hyst =clamp_val (hyst,0 ,31 );mutex_lock (&data->update_lock);@@ -292,7 +304,7 @@ static ssize_t set_crit_hyst(struct device *dev, struct device_attribute *attr,/* shared crit hysteresis */ i2c_smbus_write_byte_data (client,LM95245_REG_RW_COMMON_HYSTERESIS , - val); + val);mutex_unlock (&data->update_lock);@@ -378,16 +390,16 @@ static ssize_t set_interval(struct device *dev, struct device_attribute *attr, static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_input, NULL, 0); static SENSOR_DEVICE_ATTR(temp1_crit, S_IWUSR | S_IRUGO, show_limit, set_limit, 6); -static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, show_limit, - set_crit_hyst, 8); +static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, show_crit_hyst, + set_crit_hyst, 6);
drivers/hwmon/lm95245.c static ssize_t set_interval(struct device *dev, struct device_attribute *attr, · line 402
Quoted 10 lines
drivers/hwmon/lm95245.c +2
-2static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, STATUS1_LOC); static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_input, NULL, 2); static SENSOR_DEVICE_ATTR(temp2_crit, S_IWUSR | S_IRUGO, show_limit, set_limit, 7); -static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IWUSR | S_IRUGO, show_limit, - set_crit_hyst, 8); +static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IWUSR | S_IRUGO, show_crit_hyst, + set_crit_hyst, 7);
This isn't directly related to your patch, however this isn't how we typically handle shared hysteresis registers. If you look at the lm90 driver, temp1_crit_hyst is writable but temp2_crit_hyst is read-only. This is how we let the user know that both values can't be set independently. Here the user can set both, and will then consider it a bug that temp1_crit_hyst isn't set to the right value.
As you are already fixing this interface, I think you should also turn temp2_crit_hyst to read-only, so that users don't have to change their configuration file twice.
drivers/hwmon/lm95245.c static ssize_t set_interval(struct device *dev, struct device_attribute *attr, · line 405
Quoted 3 lines
drivers/hwmon/lm95245.c +0
-0static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL, STATUS1_RTCRIT); static SENSOR_DEVICE_ATTR(temp2_type, S_IWUSR | S_IRUGO, show_type,
The code changes themselves look good to me, and are very needed.
Signature · 7 lines
Jean Delvare Suse L3 Support _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Guenter Roeck
maintainerHi Jean,
Quoted 4 lines · Jean Delvare
Hi Guenter,
Sorry for the late review.
As always, I appreciate your time.
Quoted 28 lines · Guenter Roeck
Quoted 27 lines
Hysteresis temperatures are defined as absolute temperatures, not as delta value from the critical temperatures.
Signed-off-by Guenter Roeck <[email protected]>--- drivers/hwmon/lm95245.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-)drivers/hwmon/lm95245.c +10
-0@@ -272,19 +272,31 @@ static ssize_t set_limit(struct device *dev, struct device_attribute *attr,return count; } +static ssize_t show_crit_hyst (struct device *dev,struct device_attribute *attr, +char *buf) +{ +struct lm95245_data *data =lm95245_update_device (dev); +int index =to_sensor_dev_attr (attr)->index; +int hyst = data->regs[index] - data->regs[8 ]; + +return snprintf (buf,PAGE_SIZE -1 ,"%d\n" , hyst *1000 ); +} + static ssize_t set_crit_hyst(struct device *dev, struct device_attribute *attr,
Quoted 9 lines
drivers/hwmon/lm95245.c static ssize_t set_limit(struct device *dev, struct device_attribute *attr, · line 286
Quoted 2 lines
drivers/hwmon/lm95245.c +1
-1- const char *buf, size_t count) + const char *buf, size_t count)These reindentations do not belong to this patch - if they are needed at all. The same style is used everywhere in the driver and while it's not my preferred one either, it's used quite consistently as far as I can tell. I would leave it as is. If it really bothers you then you should "fix" the whole driver with a separate patch.
Ok, I'll undo those.
Quoted 63 lines
drivers/hwmon/lm95245.c static ssize_t set_limit(struct device *dev, struct device_attribute *attr, · line 288
Quoted 2 lines
drivers/hwmon/lm95245.c +1
-0{ +struct lm95245_data *data =lm95245_update_device (dev);Calling the update function in "set" callbacks is discouraged. Set functions are typically called at boot time. The update function can be quite slow as it reads a lot of registers over slow I2C/SMBus.
Admittedly the number of registers of this particular chip isn't too high so the effect is limited, but you should still consider the option of only reading the register value you need.
Quoted 34 lines
drivers/hwmon/lm95245.c +7
-6struct i2c_client *client =to_i2c_client (dev); -struct lm95245_data *data =i2c_get_clientdata (client); +int index =to_sensor_dev_attr (attr)->index;unsigned long val; +long hyst;if (kstrtoul (buf,10 , &val) <0 )return -EINVAL ; val /=1000 ; - - val =clamp_val (val,0 ,31 ); + hyst = data->regs[index] - val; + hyst =clamp_val (hyst,0 ,31 );mutex_lock (&data->update_lock);@@ -292,7 +304,7 @@ static ssize_t set_crit_hyst(struct device *dev, struct device_attribute *attr,/* shared crit hysteresis */ i2c_smbus_write_byte_data (client,LM95245_REG_RW_COMMON_HYSTERESIS , - val); + val);mutex_unlock (&data->update_lock);@@ -378,16 +390,16 @@ static ssize_t set_interval(struct device *dev, struct device_attribute *attr, static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_input, NULL, 0); static SENSOR_DEVICE_ATTR(temp1_crit, S_IWUSR | S_IRUGO, show_limit, set_limit, 6); -static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, show_limit, - set_crit_hyst, 8); +static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, show_crit_hyst, + set_crit_hyst, 6);drivers/hwmon/lm95245.c static ssize_t set_interval(struct device *dev, struct device_attribute *attr, · line 402
Quoted 10 lines
drivers/hwmon/lm95245.c +2
-2static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, STATUS1_LOC); static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_input, NULL, 2); static SENSOR_DEVICE_ATTR(temp2_crit, S_IWUSR | S_IRUGO, show_limit, set_limit, 7); -static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IWUSR | S_IRUGO, show_limit, - set_crit_hyst, 8); +static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IWUSR | S_IRUGO, show_crit_hyst, + set_crit_hyst, 7);This isn't directly related to your patch, however this isn't how we typically handle shared hysteresis registers. If you look at the lm90 driver,
temp1_crit_hystis writable buttemp2_crit_hystis read-only. This is how we let the user know that both values can't be set independently. Here the user can set both, and will then consider it a bug thattemp1_crit_hystisn't set to the right value.
Quoted 4 lines
As you are already fixing this interface, I think you should also turn
temp2_crit_hystto read-only, so that users don't have to change their configuration file twice.
Makes sense. I'll do that, but in a separate patch.
Quoted 8 lines
drivers/hwmon/lm95245.c static ssize_t set_interval(struct device *dev, struct device_attribute *attr, · line 405
Quoted 3 lines
drivers/hwmon/lm95245.c +0
-0static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL, STATUS1_RTCRIT); static SENSOR_DEVICE_ATTR(temp2_type, S_IWUSR | S_IRUGO, show_type,The code changes themselves look good to me, and are very needed.
Reviewed-by Jean Delvare <[email protected]>
Thanks a lot for the review!
Guenter
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors