Commit f4fdd4cb authored by Shawn Starr's avatar Shawn Starr Committed by Greg Kroah-Hartman

[PATCH] I2C: lm80 driver improvement

Description: Cleanup some cluttered macros, add error checking for fan divisor value set.
Signed-off-by: default avatarSytse Wielinga <s.b.wielinga@student.utwente.nl>
Signed-off-by: default avatarAurelien Jarno <aurelien@aurel32.net>
Signed-off-by: default avatarShawn Starr <shawn.starr@rogers.com>
Signed-off-by: default avatarGreg Kroah-Hartman <greg@kroah.com>
parent e86f8368
...@@ -99,10 +99,7 @@ static inline long TEMP_FROM_REG(u16 temp) ...@@ -99,10 +99,7 @@ static inline long TEMP_FROM_REG(u16 temp)
#define TEMP_LIMIT_TO_REG(val) SENSORS_LIMIT((val)<0?\ #define TEMP_LIMIT_TO_REG(val) SENSORS_LIMIT((val)<0?\
((val)-500)/1000:((val)+500)/1000,0,255) ((val)-500)/1000:((val)+500)/1000,0,255)
#define ALARMS_FROM_REG(val) (val)
#define DIV_FROM_REG(val) (1 << (val)) #define DIV_FROM_REG(val) (1 << (val))
#define DIV_TO_REG(val) ((val)==8?3:(val)==4?2:(val)==1?0:1)
/* /*
* Client data (each client gets its own) * Client data (each client gets its own)
...@@ -263,7 +260,17 @@ static ssize_t set_fan_div(struct device *dev, const char *buf, ...@@ -263,7 +260,17 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
DIV_FROM_REG(data->fan_div[nr])); DIV_FROM_REG(data->fan_div[nr]));
val = simple_strtoul(buf, NULL, 10); val = simple_strtoul(buf, NULL, 10);
data->fan_div[nr] = DIV_TO_REG(val);
switch (val) {
case 1: data->fan_div[nr] = 0; break;
case 2: data->fan_div[nr] = 1; break;
case 4: data->fan_div[nr] = 2; break;
case 8: data->fan_div[nr] = 3; break;
default:
dev_err(&client->dev, "fan_div value %ld not "
"supported. Choose one of 1, 2, 4 or 8!\n", val);
return -EINVAL;
}
reg = (lm80_read_value(client, LM80_REG_FANDIV) & ~(3 << (2 * (nr + 1)))) reg = (lm80_read_value(client, LM80_REG_FANDIV) & ~(3 << (2 * (nr + 1))))
| (data->fan_div[nr] << (2 * (nr + 1))); | (data->fan_div[nr] << (2 * (nr + 1)));
...@@ -321,7 +328,7 @@ set_temp(os_hyst, temp_os_hyst, LM80_REG_TEMP_OS_HYST); ...@@ -321,7 +328,7 @@ set_temp(os_hyst, temp_os_hyst, LM80_REG_TEMP_OS_HYST);
static ssize_t show_alarms(struct device *dev, char *buf) static ssize_t show_alarms(struct device *dev, char *buf)
{ {
struct lm80_data *data = lm80_update_device(dev); struct lm80_data *data = lm80_update_device(dev);
return sprintf(buf, "%d\n", ALARMS_FROM_REG(data->alarms)); return sprintf(buf, "%u\n", data->alarms);
} }
static DEVICE_ATTR(in0_min, S_IWUSR | S_IRUGO, show_in_min0, set_in_min0); static DEVICE_ATTR(in0_min, S_IWUSR | S_IRUGO, show_in_min0, set_in_min0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment