Commit e95fd518 authored by Guenter Roeck's avatar Guenter Roeck

hwmon: (w83627hf) Use request_muxed_region for Super-IO accesses

Super-IO accesses may fail on a system with no or unmapped LPC bus.

Also, other drivers may attempt to access the LPC bus at the same time,
resulting in undefined behavior.

Use request_muxed_region() to ensure that IO access on the requested
address space is supported, and to ensure that access by multiple drivers
is synchronized.

Fixes: b72656db ("hwmon: (w83627hf) Stop using globals for I/O port numbers")
Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
parent d6410408
...@@ -130,17 +130,23 @@ superio_select(struct w83627hf_sio_data *sio, int ld) ...@@ -130,17 +130,23 @@ superio_select(struct w83627hf_sio_data *sio, int ld)
outb(ld, sio->sioaddr + 1); outb(ld, sio->sioaddr + 1);
} }
static inline void static inline int
superio_enter(struct w83627hf_sio_data *sio) superio_enter(struct w83627hf_sio_data *sio)
{ {
if (!request_muxed_region(sio->sioaddr, 2, DRVNAME))
return -EBUSY;
outb(0x87, sio->sioaddr); outb(0x87, sio->sioaddr);
outb(0x87, sio->sioaddr); outb(0x87, sio->sioaddr);
return 0;
} }
static inline void static inline void
superio_exit(struct w83627hf_sio_data *sio) superio_exit(struct w83627hf_sio_data *sio)
{ {
outb(0xAA, sio->sioaddr); outb(0xAA, sio->sioaddr);
release_region(sio->sioaddr, 2);
} }
#define W627_DEVID 0x52 #define W627_DEVID 0x52
...@@ -1254,7 +1260,7 @@ static DEVICE_ATTR_RO(name); ...@@ -1254,7 +1260,7 @@ static DEVICE_ATTR_RO(name);
static int __init w83627hf_find(int sioaddr, unsigned short *addr, static int __init w83627hf_find(int sioaddr, unsigned short *addr,
struct w83627hf_sio_data *sio_data) struct w83627hf_sio_data *sio_data)
{ {
int err = -ENODEV; int err;
u16 val; u16 val;
static __initconst char *const names[] = { static __initconst char *const names[] = {
...@@ -1266,7 +1272,11 @@ static int __init w83627hf_find(int sioaddr, unsigned short *addr, ...@@ -1266,7 +1272,11 @@ static int __init w83627hf_find(int sioaddr, unsigned short *addr,
}; };
sio_data->sioaddr = sioaddr; sio_data->sioaddr = sioaddr;
superio_enter(sio_data); err = superio_enter(sio_data);
if (err)
return err;
err = -ENODEV;
val = force_id ? force_id : superio_inb(sio_data, DEVID); val = force_id ? force_id : superio_inb(sio_data, DEVID);
switch (val) { switch (val) {
case W627_DEVID: case W627_DEVID:
...@@ -1619,9 +1629,21 @@ static int w83627thf_read_gpio5(struct platform_device *pdev) ...@@ -1619,9 +1629,21 @@ static int w83627thf_read_gpio5(struct platform_device *pdev)
struct w83627hf_sio_data *sio_data = dev_get_platdata(&pdev->dev); struct w83627hf_sio_data *sio_data = dev_get_platdata(&pdev->dev);
int res = 0xff, sel; int res = 0xff, sel;
superio_enter(sio_data); if (superio_enter(sio_data)) {
/*
* Some other driver reserved the address space for itself.
* We don't want to fail driver instantiation because of that,
* so display a warning and keep going.
*/
dev_warn(&pdev->dev,
"Can not read VID data: Failed to enable SuperIO access\n");
return res;
}
superio_select(sio_data, W83627HF_LD_GPIO5); superio_select(sio_data, W83627HF_LD_GPIO5);
res = 0xff;
/* Make sure these GPIO pins are enabled */ /* Make sure these GPIO pins are enabled */
if (!(superio_inb(sio_data, W83627THF_GPIO5_EN) & (1<<3))) { if (!(superio_inb(sio_data, W83627THF_GPIO5_EN) & (1<<3))) {
dev_dbg(&pdev->dev, "GPIO5 disabled, no VID function\n"); dev_dbg(&pdev->dev, "GPIO5 disabled, no VID function\n");
...@@ -1652,7 +1674,17 @@ static int w83687thf_read_vid(struct platform_device *pdev) ...@@ -1652,7 +1674,17 @@ static int w83687thf_read_vid(struct platform_device *pdev)
struct w83627hf_sio_data *sio_data = dev_get_platdata(&pdev->dev); struct w83627hf_sio_data *sio_data = dev_get_platdata(&pdev->dev);
int res = 0xff; int res = 0xff;
superio_enter(sio_data); if (superio_enter(sio_data)) {
/*
* Some other driver reserved the address space for itself.
* We don't want to fail driver instantiation because of that,
* so display a warning and keep going.
*/
dev_warn(&pdev->dev,
"Can not read VID data: Failed to enable SuperIO access\n");
return res;
}
superio_select(sio_data, W83627HF_LD_HWM); superio_select(sio_data, W83627HF_LD_HWM);
/* Make sure these GPIO pins are enabled */ /* Make sure these GPIO pins are enabled */
......
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