hwmon/sch5627: Trigger Vbat
Hi Hans,
Quoted 30 lines · Hans de Goede
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 <[email protected]>--- drivers/hwmon/sch5627.c | 17 ++++++++++++++++- 1 files changed, 16 insertions(+), 1 deletions(-)drivers/hwmon/sch5627.c +2
-0@@ -94,6 +94,7 @@ static const char * const SCH5627_IN_LABELS[SCH5627_NO_IN] = {struct sch5627_data {unsigned short addr;struct device *hwmon_dev; +u8 control;u8 temp_max[SCH5627_NO_TEMPS ];u8 temp_crit[SCH5627_NO_TEMPS ];u16 fan_min[SCH5627_NO_FANS ];@@ -101,6 +102,7 @@ struct sch5627_data {struct mutex update_lock;char valid;/* !=0 if following fields are valid */ unsigned long last_updated;/* In jiffies */ +unsigned long last_battery;/* In jiffies */ u16 temp[SCH5627_NO_TEMPS ];u16 fan[SCH5627_NO_FANS ];u16 in[SCH5627_NO_IN ];
drivers/hwmon/sch5627.c static struct sch5627_data *sch5627_update_device(struct device *dev) · line 334
Quoted 6 lines
drivers/hwmon/sch5627.c +3
-0@@ -327,6 +329,14 @@ static struct sch5627_data *sch5627_update_device(struct device *dev) } data->last_updated = jiffies; + } + +/* Trigger a Vbat voltage measurement every minute */
I would even have gone for longer than this, at least 5 minutes if not even 1 hour. AFAIK monitoring drains the battery's power, and the battery isn't used during run-time so monitoring it in real-time is not critical.
drivers/hwmon/sch5627.c static struct sch5627_data *sch5627_update_device(struct device *dev) · line 341
Quoted 7 lines
drivers/hwmon/sch5627.c +5
-0+if (time_after (jiffies, data->last_battery +60 *HZ ) || + !data->valid) { +sch5627_write_virtual_reg (data,SCH5627_REG_CTRL , + data->control |0x10 ); + data->last_battery = jiffies; data->valid =1 ; }
This is confusing. What is data->valid supposed to represent now?
I don't think you should mess up with data->valid here. You already enabled one sampling of Vbat during probe, so you should have set data->last_battery when you did, and only use data->last_battery after that.
Furthermore, wouldn't it make more sense to do that _before_ reading the samples from the chip? With some luck it may let you get a fresh reading for Vbat, instead of possibly hours old one. I understand there is no guarantee, but I see no reason to not at least take our chance.
Quoted 19 lines
drivers/hwmon/sch5627.c +6
-1abort:@@ -714,11 +724,16 @@ static int __devinit sch5627_probe(struct platform_device *pdev) err = val; goto error; } -if (!(val &0x01 )) { + data->control = val; +if (!(data->control &0x01 )) {pr_err ("hardware monitoring not enabled\n" ); err = -ENODEV ; goto error; } +/* Trigger a Vbat voltage measurement, so that we get a valid reading +the first time we read Vbat */ +sch5627_write_virtual_reg (data,SCH5627_REG_CTRL , + data->control |0x10 );/* * Read limits, we do this only once as reading a register on
Signature · 6 lines
Jean Delvare _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Hi,
Quoted 35 lines · Jean Delvare
Hi Hans,
Quoted 32 lines · Hans de Goede
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<[email protected]>--- drivers/hwmon/sch5627.c | 17 ++++++++++++++++- 1 files changed, 16 insertions(+), 1 deletions(-)drivers/hwmon/sch5627.c +2
-0@@ -94,6 +94,7 @@ static const char * const SCH5627_IN_LABELS[SCH5627_NO_IN] = {struct sch5627_data {unsigned short addr;struct device *hwmon_dev; +u8 control;u8 temp_max[SCH5627_NO_TEMPS ];u8 temp_crit[SCH5627_NO_TEMPS ];u16 fan_min[SCH5627_NO_FANS ];@@ -101,6 +102,7 @@ struct sch5627_data {struct mutex update_lock;char valid;/* !=0 if following fields are valid */ unsigned long last_updated;/* In jiffies */ +unsigned long last_battery;/* In jiffies */ u16 temp[SCH5627_NO_TEMPS ];u16 fan[SCH5627_NO_FANS ];u16 in[SCH5627_NO_IN ];@@ -327,6 +329,14 @@ static struct sch5627_data *sch5627_update_device(struct device *dev) }
Quoted 10 lines
drivers/hwmon/sch5627.c static struct sch5627_data *sch5627_update_device(struct device *dev) · line 334
Quoted 4 lines
drivers/hwmon/sch5627.c +3
-0data->last_updated = jiffies; + } + +/* Trigger a Vbat voltage measurement every minute */ I would even have gone for longer than this, at least 5 minutes if not even 1 hour. AFAIK monitoring drains the battery's power, and the battery isn't used during run-time so monitoring it in real-time is not critical.
Ok, will make it 5 minutes in the next revision.
Quoted 15 lines
drivers/hwmon/sch5627.c static struct sch5627_data *sch5627_update_device(struct device *dev) · line 341
Quoted 7 lines
drivers/hwmon/sch5627.c +5
-0+if (time_after (jiffies, data->last_battery +60 *HZ ) || + !data->valid) { +sch5627_write_virtual_reg (data,SCH5627_REG_CTRL , + data->control |0x10 ); + data->last_battery = jiffies; data->valid =1 ; }This is confusing. What is
data->validsupposed to represent now?I don't think you should mess up with
data->validhere. You already enabled one sampling of Vbat during probe, so you should have setdata->last_batterywhen you did, and only usedata->last_batteryafter that.
Quoted 5 lines
Furthermore, wouldn't it make more sense to do that _before_ reading the samples from the chip? With some luck it may let you get a fresh reading for Vbat, instead of possibly hours old one. I understand there is no guarantee, but I see no reason to not at least take our chance.
Ah, I should have read better before saying I had a question about this in my previous mail. I'll take over your suggestions and do a new version of this patch set tomorrow.
Regards,
Hans
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Hi Hans,
Quoted 3 lines · Hans de Goede
Ah, I should have read better before saying I had a question about this in my previous mail. I'll take over your suggestions and do a new version of this patch set tomorrow.
Kernel 2.6.39 final is probably not too far away by now, if you want this fix in, please send updated patches quickly.
Signature · 6 lines
Jean Delvare _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Jean Delvare
AppliedQuoted 8 lines · Hans de Goede
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 <[email protected]>--- drivers/hwmon/sch5627.c | 23 ++++++++++++++++++++++- 1 files changed, 22 insertions(+), 1 deletions(-)
Applied, thanks.
Signature · 6 lines
Jean Delvare _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors