aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/sch5627.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon/sch5627.c')
-rw-r--r--drivers/hwmon/sch5627.c46
1 files changed, 41 insertions, 5 deletions
diff --git a/drivers/hwmon/sch5627.c b/drivers/hwmon/sch5627.c
index 9a51dcca9b0d..020c87273ea1 100644
--- a/drivers/hwmon/sch5627.c
+++ b/drivers/hwmon/sch5627.c
@@ -52,6 +52,9 @@
52#define SCH5627_COMPANY_ID 0x5c 52#define SCH5627_COMPANY_ID 0x5c
53#define SCH5627_PRIMARY_ID 0xa0 53#define SCH5627_PRIMARY_ID 0xa0
54 54
55#define SCH5627_CMD_READ 0x02
56#define SCH5627_CMD_WRITE 0x03
57
55#define SCH5627_REG_BUILD_CODE 0x39 58#define SCH5627_REG_BUILD_CODE 0x39
56#define SCH5627_REG_BUILD_ID 0x3a 59#define SCH5627_REG_BUILD_ID 0x3a
57#define SCH5627_REG_HWMON_ID 0x3c 60#define SCH5627_REG_HWMON_ID 0x3c
@@ -94,11 +97,13 @@ static const char * const SCH5627_IN_LABELS[SCH5627_NO_IN] = {
94struct sch5627_data { 97struct sch5627_data {
95 unsigned short addr; 98 unsigned short addr;
96 struct device *hwmon_dev; 99 struct device *hwmon_dev;
100 u8 control;
97 u8 temp_max[SCH5627_NO_TEMPS]; 101 u8 temp_max[SCH5627_NO_TEMPS];
98 u8 temp_crit[SCH5627_NO_TEMPS]; 102 u8 temp_crit[SCH5627_NO_TEMPS];
99 u16 fan_min[SCH5627_NO_FANS]; 103 u16 fan_min[SCH5627_NO_FANS];
100 104
101 struct mutex update_lock; 105 struct mutex update_lock;
106 unsigned long last_battery; /* In jiffies */
102 char valid; /* !=0 if following fields are valid */ 107 char valid; /* !=0 if following fields are valid */
103 unsigned long last_updated; /* In jiffies */ 108 unsigned long last_updated; /* In jiffies */
104 u16 temp[SCH5627_NO_TEMPS]; 109 u16 temp[SCH5627_NO_TEMPS];
@@ -140,7 +145,7 @@ static inline void superio_exit(int base)
140 release_region(base, 2); 145 release_region(base, 2);
141} 146}
142 147
143static int sch5627_read_virtual_reg(struct sch5627_data *data, u16 reg) 148static int sch5627_send_cmd(struct sch5627_data *data, u8 cmd, u16 reg, u8 v)
144{ 149{
145 u8 val; 150 u8 val;
146 int i; 151 int i;
@@ -163,10 +168,14 @@ static int sch5627_read_virtual_reg(struct sch5627_data *data, u16 reg)
163 outb(0x80, data->addr + 3); 168 outb(0x80, data->addr + 3);
164 169
165 /* Write Request Packet Header */ 170 /* Write Request Packet Header */
166 outb(0x02, data->addr + 4); /* Access Type: VREG read */ 171 outb(cmd, data->addr + 4); /* VREG Access Type read:0x02 write:0x03 */
167 outb(0x01, data->addr + 5); /* # of Entries: 1 Byte (8-bit) */ 172 outb(0x01, data->addr + 5); /* # of Entries: 1 Byte (8-bit) */
168 outb(0x04, data->addr + 2); /* Mailbox AP to first data entry loc. */ 173 outb(0x04, data->addr + 2); /* Mailbox AP to first data entry loc. */
169 174
175 /* Write Value field */
176 if (cmd == SCH5627_CMD_WRITE)
177 outb(v, data->addr + 4);
178
170 /* Write Address field */ 179 /* Write Address field */
171 outb(reg & 0xff, data->addr + 6); 180 outb(reg & 0xff, data->addr + 6);
172 outb(reg >> 8, data->addr + 7); 181 outb(reg >> 8, data->addr + 7);
@@ -224,8 +233,22 @@ static int sch5627_read_virtual_reg(struct sch5627_data *data, u16 reg)
224 * But if we do that things don't work, so let's not. 233 * But if we do that things don't work, so let's not.
225 */ 234 */
226 235
227 /* Read Data from Mailbox */ 236 /* Read Value field */
228 return inb(data->addr + 4); 237 if (cmd == SCH5627_CMD_READ)
238 return inb(data->addr + 4);
239
240 return 0;
241}
242
243static int sch5627_read_virtual_reg(struct sch5627_data *data, u16 reg)
244{
245 return sch5627_send_cmd(data, SCH5627_CMD_READ, reg, 0);
246}
247
248static 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);
229} 252}
230 253
231static int sch5627_read_virtual_reg16(struct sch5627_data *data, u16 reg) 254static 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)
272 295
273 mutex_lock(&data->update_lock); 296 mutex_lock(&data->update_lock);
274 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
275 /* Cache the values for 1 second */ 305 /* Cache the values for 1 second */
276 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { 306 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
277 for (i = 0; i < SCH5627_NO_TEMPS; i++) { 307 for (i = 0; i < SCH5627_NO_TEMPS; i++) {
@@ -696,11 +726,17 @@ static int __devinit sch5627_probe(struct platform_device *pdev)
696 err = val; 726 err = val;
697 goto error; 727 goto error;
698 } 728 }
699 if (!(val & 0x01)) { 729 data->control = val;
730 if (!(data->control & 0x01)) {
700 pr_err("hardware monitoring not enabled\n"); 731 pr_err("hardware monitoring not enabled\n");
701 err = -ENODEV; 732 err = -ENODEV;
702 goto error; 733 goto error;
703 } 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;
704 740
705 /* 741 /*
706 * 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