diff options
author | Hans de Goede <hdegoede@redhat.com> | 2011-05-25 14:43:33 -0400 |
---|---|---|
committer | Jean Delvare <khali@endymion.delvare> | 2011-05-25 14:43:33 -0400 |
commit | 357b9dc6c2dbb01e835415355b70d6b47c43a102 (patch) | |
tree | f725c3b76bbe530aa409018dd4bec8b34c1f6b32 /drivers/hwmon | |
parent | 709046a62293a14fda3986a52818ec01fc11bf75 (diff) |
hwmon: (sch5627) Trigger Vbat measurements
The sch5627 needs to be explicitly told to start an adc conversion
for Vbat, once in a while. Without this Vbat may read 0, and will never
get updated.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r-- | drivers/hwmon/sch5627.c | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/drivers/hwmon/sch5627.c b/drivers/hwmon/sch5627.c index d785a2c5431f..020c87273ea1 100644 --- a/drivers/hwmon/sch5627.c +++ b/drivers/hwmon/sch5627.c | |||
@@ -97,11 +97,13 @@ static const char * const SCH5627_IN_LABELS[SCH5627_NO_IN] = { | |||
97 | struct sch5627_data { | 97 | struct sch5627_data { |
98 | unsigned short addr; | 98 | unsigned short addr; |
99 | struct device *hwmon_dev; | 99 | struct device *hwmon_dev; |
100 | u8 control; | ||
100 | u8 temp_max[SCH5627_NO_TEMPS]; | 101 | u8 temp_max[SCH5627_NO_TEMPS]; |
101 | u8 temp_crit[SCH5627_NO_TEMPS]; | 102 | u8 temp_crit[SCH5627_NO_TEMPS]; |
102 | u16 fan_min[SCH5627_NO_FANS]; | 103 | u16 fan_min[SCH5627_NO_FANS]; |
103 | 104 | ||
104 | struct mutex update_lock; | 105 | struct mutex update_lock; |
106 | unsigned long last_battery; /* In jiffies */ | ||
105 | char valid; /* !=0 if following fields are valid */ | 107 | char valid; /* !=0 if following fields are valid */ |
106 | unsigned long last_updated; /* In jiffies */ | 108 | unsigned long last_updated; /* In jiffies */ |
107 | u16 temp[SCH5627_NO_TEMPS]; | 109 | u16 temp[SCH5627_NO_TEMPS]; |
@@ -243,6 +245,12 @@ static int sch5627_read_virtual_reg(struct sch5627_data *data, u16 reg) | |||
243 | return sch5627_send_cmd(data, SCH5627_CMD_READ, reg, 0); | 245 | return sch5627_send_cmd(data, SCH5627_CMD_READ, reg, 0); |
244 | } | 246 | } |
245 | 247 | ||
248 | static int sch5627_write_virtual_reg(struct sch5627_data *data, | ||
249 | u16 reg, u8 val) | ||
250 | { | ||
251 | return sch5627_send_cmd(data, SCH5627_CMD_WRITE, reg, val); | ||
252 | } | ||
253 | |||
246 | static int sch5627_read_virtual_reg16(struct sch5627_data *data, u16 reg) | 254 | static int sch5627_read_virtual_reg16(struct sch5627_data *data, u16 reg) |
247 | { | 255 | { |
248 | int lsb, msb; | 256 | int lsb, msb; |
@@ -287,6 +295,13 @@ static struct sch5627_data *sch5627_update_device(struct device *dev) | |||
287 | 295 | ||
288 | mutex_lock(&data->update_lock); | 296 | mutex_lock(&data->update_lock); |
289 | 297 | ||
298 | /* Trigger a Vbat voltage measurement every 5 minutes */ | ||
299 | if (time_after(jiffies, data->last_battery + 300 * HZ)) { | ||
300 | sch5627_write_virtual_reg(data, SCH5627_REG_CTRL, | ||
301 | data->control | 0x10); | ||
302 | data->last_battery = jiffies; | ||
303 | } | ||
304 | |||
290 | /* Cache the values for 1 second */ | 305 | /* Cache the values for 1 second */ |
291 | if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { | 306 | if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { |
292 | for (i = 0; i < SCH5627_NO_TEMPS; i++) { | 307 | for (i = 0; i < SCH5627_NO_TEMPS; i++) { |
@@ -711,11 +726,17 @@ static int __devinit sch5627_probe(struct platform_device *pdev) | |||
711 | err = val; | 726 | err = val; |
712 | goto error; | 727 | goto error; |
713 | } | 728 | } |
714 | if (!(val & 0x01)) { | 729 | data->control = val; |
730 | if (!(data->control & 0x01)) { | ||
715 | pr_err("hardware monitoring not enabled\n"); | 731 | pr_err("hardware monitoring not enabled\n"); |
716 | err = -ENODEV; | 732 | err = -ENODEV; |
717 | goto error; | 733 | goto error; |
718 | } | 734 | } |
735 | /* Trigger a Vbat voltage measurement, so that we get a valid reading | ||
736 | the first time we read Vbat */ | ||
737 | sch5627_write_virtual_reg(data, SCH5627_REG_CTRL, | ||
738 | data->control | 0x10); | ||
739 | data->last_battery = jiffies; | ||
719 | 740 | ||
720 | /* | 741 | /* |
721 | * Read limits, we do this only once as reading a register on | 742 | * Read limits, we do this only once as reading a register on |