Commit 03c2cbb3 authored by Jean Delvare's avatar Jean Delvare Committed by Greg Kroah-Hartman

hwmon/w83627hf: Don't assume bank 0

Already in Linus' tree:
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;h=d58df9cd788e6fb4962e1c8d5ba7b8b95d639a44

The bank switching code assumes that the bank selector is set to 0
when the driver is loaded. This might not be the case. This is exactly
the same bug as was fixed in the w83627ehf driver two months ago:
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=0956895aa6f8dc6a33210967252fd7787652537d

In practice, this bug was causing the sensor thermal types to be
improperly reported for my W83627THF the first time I was loading the
w83627hf driver. From the driver history, I'd say that it has been
broken since September 2005 (when we stopped resetting the chip by
default at driver load.)
Signed-off-by: default avatarJean Delvare <khali@linux-fr.org>
Signed-off-by: default avatarMark M. Hoffman <mhoffman@lightlink.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent a228ddd5
...@@ -1335,6 +1335,24 @@ static int __devexit w83627hf_remove(struct platform_device *pdev) ...@@ -1335,6 +1335,24 @@ static int __devexit w83627hf_remove(struct platform_device *pdev)
} }
/* Registers 0x50-0x5f are banked */
static inline void w83627hf_set_bank(struct w83627hf_data *data, u16 reg)
{
if ((reg & 0x00f0) == 0x50) {
outb_p(W83781D_REG_BANK, data->addr + W83781D_ADDR_REG_OFFSET);
outb_p(reg >> 8, data->addr + W83781D_DATA_REG_OFFSET);
}
}
/* Not strictly necessary, but play it safe for now */
static inline void w83627hf_reset_bank(struct w83627hf_data *data, u16 reg)
{
if (reg & 0xff00) {
outb_p(W83781D_REG_BANK, data->addr + W83781D_ADDR_REG_OFFSET);
outb_p(0, data->addr + W83781D_DATA_REG_OFFSET);
}
}
static int w83627hf_read_value(struct w83627hf_data *data, u16 reg) static int w83627hf_read_value(struct w83627hf_data *data, u16 reg)
{ {
int res, word_sized; int res, word_sized;
...@@ -1345,12 +1363,7 @@ static int w83627hf_read_value(struct w83627hf_data *data, u16 reg) ...@@ -1345,12 +1363,7 @@ static int w83627hf_read_value(struct w83627hf_data *data, u16 reg)
&& (((reg & 0x00ff) == 0x50) && (((reg & 0x00ff) == 0x50)
|| ((reg & 0x00ff) == 0x53) || ((reg & 0x00ff) == 0x53)
|| ((reg & 0x00ff) == 0x55)); || ((reg & 0x00ff) == 0x55));
if (reg & 0xff00) { w83627hf_set_bank(data, reg);
outb_p(W83781D_REG_BANK,
data->addr + W83781D_ADDR_REG_OFFSET);
outb_p(reg >> 8,
data->addr + W83781D_DATA_REG_OFFSET);
}
outb_p(reg & 0xff, data->addr + W83781D_ADDR_REG_OFFSET); outb_p(reg & 0xff, data->addr + W83781D_ADDR_REG_OFFSET);
res = inb_p(data->addr + W83781D_DATA_REG_OFFSET); res = inb_p(data->addr + W83781D_DATA_REG_OFFSET);
if (word_sized) { if (word_sized) {
...@@ -1360,11 +1373,7 @@ static int w83627hf_read_value(struct w83627hf_data *data, u16 reg) ...@@ -1360,11 +1373,7 @@ static int w83627hf_read_value(struct w83627hf_data *data, u16 reg)
(res << 8) + inb_p(data->addr + (res << 8) + inb_p(data->addr +
W83781D_DATA_REG_OFFSET); W83781D_DATA_REG_OFFSET);
} }
if (reg & 0xff00) { w83627hf_reset_bank(data, reg);
outb_p(W83781D_REG_BANK,
data->addr + W83781D_ADDR_REG_OFFSET);
outb_p(0, data->addr + W83781D_DATA_REG_OFFSET);
}
mutex_unlock(&data->lock); mutex_unlock(&data->lock);
return res; return res;
} }
...@@ -1435,12 +1444,7 @@ static int w83627hf_write_value(struct w83627hf_data *data, u16 reg, u16 value) ...@@ -1435,12 +1444,7 @@ static int w83627hf_write_value(struct w83627hf_data *data, u16 reg, u16 value)
|| ((reg & 0xff00) == 0x200)) || ((reg & 0xff00) == 0x200))
&& (((reg & 0x00ff) == 0x53) && (((reg & 0x00ff) == 0x53)
|| ((reg & 0x00ff) == 0x55)); || ((reg & 0x00ff) == 0x55));
if (reg & 0xff00) { w83627hf_set_bank(data, reg);
outb_p(W83781D_REG_BANK,
data->addr + W83781D_ADDR_REG_OFFSET);
outb_p(reg >> 8,
data->addr + W83781D_DATA_REG_OFFSET);
}
outb_p(reg & 0xff, data->addr + W83781D_ADDR_REG_OFFSET); outb_p(reg & 0xff, data->addr + W83781D_ADDR_REG_OFFSET);
if (word_sized) { if (word_sized) {
outb_p(value >> 8, outb_p(value >> 8,
...@@ -1450,11 +1454,7 @@ static int w83627hf_write_value(struct w83627hf_data *data, u16 reg, u16 value) ...@@ -1450,11 +1454,7 @@ static int w83627hf_write_value(struct w83627hf_data *data, u16 reg, u16 value)
} }
outb_p(value & 0xff, outb_p(value & 0xff,
data->addr + W83781D_DATA_REG_OFFSET); data->addr + W83781D_DATA_REG_OFFSET);
if (reg & 0xff00) { w83627hf_reset_bank(data, reg);
outb_p(W83781D_REG_BANK,
data->addr + W83781D_ADDR_REG_OFFSET);
outb_p(0, data->addr + W83781D_DATA_REG_OFFSET);
}
mutex_unlock(&data->lock); mutex_unlock(&data->lock);
return 0; return 0;
} }
......
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