diff options
Diffstat (limited to 'drivers/hwmon/sch5627.c')
-rw-r--r-- | drivers/hwmon/sch5627.c | 46 |
1 files changed, 41 insertions, 5 deletions
diff --git a/drivers/hwmon/sch5627.c b/drivers/hwmon/sch5627.c index 9a51dcca9b0..020c87273ea 100644 --- a/drivers/hwmon/sch5627.c +++ b/drivers/hwmon/sch5627.c @@ -52,6 +52,9 @@ #define SCH5627_COMPANY_ID 0x5c #define SCH5627_PRIMARY_ID 0xa0 +#define SCH5627_CMD_READ 0x02 +#define SCH5627_CMD_WRITE 0x03 + #define SCH5627_REG_BUILD_CODE 0x39 #define SCH5627_REG_BUILD_ID 0x3a #define SCH5627_REG_HWMON_ID 0x3c @@ -94,11 +97,13 @@ 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]; struct mutex update_lock; + unsigned long last_battery; /* In jiffies */ char valid; /* !=0 if following fields are valid */ unsigned long last_updated; /* In jiffies */ u16 temp[SCH5627_NO_TEMPS]; @@ -140,7 +145,7 @@ static inline void superio_exit(int base) release_region(base, 2); } -static int sch5627_read_virtual_reg(struct sch5627_data *data, u16 reg) +static int sch5627_send_cmd(struct sch5627_data *data, u8 cmd, u16 reg, u8 v) { u8 val; int i; @@ -163,10 +168,14 @@ static int sch5627_read_virtual_reg(struct sch5627_data *data, u16 reg) outb(0x80, data->addr + 3); /* Write Request Packet Header */ - outb(0x02, data->addr + 4); /* Access Type: VREG read */ + outb(cmd, data->addr + 4); /* VREG Access Type read:0x02 write:0x03 */ outb(0x01, data->addr + 5); /* # of Entries: 1 Byte (8-bit) */ outb(0x04, data->addr + 2); /* Mailbox AP to first data entry loc. */ + /* Write Value field */ + if (cmd == SCH5627_CMD_WRITE) + outb(v, data->addr + 4); + /* Write Address field */ outb(reg & 0xff, data->addr + 6); outb(reg >> 8, data->addr + 7); @@ -224,8 +233,22 @@ static int sch5627_read_virtual_reg(struct sch5627_data *data, u16 reg) * But if we do that things don't work, so let's not. */ - /* Read Data from Mailbox */ - return inb(data->addr + 4); + /* Read Value field */ + if (cmd == SCH5627_CMD_READ) + return inb(data->addr + 4); + + return 0; +} + +static int sch5627_read_virtual_reg(struct sch5627_data *data, u16 reg) +{ + return sch5627_send_cmd(data, SCH5627_CMD_READ, reg, 0); +} + +static int sch5627_write_virtual_reg(struct sch5627_data *data, + u16 reg, u8 val) +{ + return sch5627_send_cmd(data, SCH5627_CMD_WRITE, reg, val); } static int sch5627_read_virtual_reg16(struct sch5627_data *data, u16 reg) @@ -272,6 +295,13 @@ static struct sch5627_data *sch5627_update_device(struct device *dev) mutex_lock(&data->update_lock); + /* Trigger a Vbat voltage measurement every 5 minutes */ + if (time_after(jiffies, data->last_battery + 300 * HZ)) { + sch5627_write_virtual_reg(data, SCH5627_REG_CTRL, + data->control | 0x10); + data->last_battery = jiffies; + } + /* Cache the values for 1 second */ if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { for (i = 0; i < SCH5627_NO_TEMPS; i++) { @@ -696,11 +726,17 @@ 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); + data->last_battery = jiffies; /* * Read limits, we do this only once as reading a register on |