Commit 5b0380c9 authored by Nat Gurumoorthy's avatar Nat Gurumoorthy Committed by Jean Delvare

hwmon: (it87) Use request_muxed_region

Serialize access to the hardware by using "request_muxed_region" macro
defined by Alan Cox. Call to this macro will hold off the requestor if
the resource is currently busy. "superio_enter" will return an error
if call to "request_muxed_region" fails. Rest of the code change is to
ripple an error return from superio_enter to the top level.
Signed-off-by: default avatarNat Gurumoorthy <natg@google.com>
Acked-by: default avatarGuenter Roeck <guenter.roeck@ericsson.com>
Signed-off-by: default avatarJean Delvare <khali@linux-fr.org>
parent 357b9dc6
...@@ -77,15 +77,13 @@ static struct platform_device *pdev; ...@@ -77,15 +77,13 @@ static struct platform_device *pdev;
#define DEVID 0x20 /* Register: Device ID */ #define DEVID 0x20 /* Register: Device ID */
#define DEVREV 0x22 /* Register: Device Revision */ #define DEVREV 0x22 /* Register: Device Revision */
static inline int static inline int superio_inb(int reg)
superio_inb(int reg)
{ {
outb(reg, REG); outb(reg, REG);
return inb(VAL); return inb(VAL);
} }
static inline void static inline void superio_outb(int reg, int val)
superio_outb(int reg, int val)
{ {
outb(reg, REG); outb(reg, REG);
outb(val, VAL); outb(val, VAL);
...@@ -101,27 +99,32 @@ static int superio_inw(int reg) ...@@ -101,27 +99,32 @@ static int superio_inw(int reg)
return val; return val;
} }
static inline void static inline void superio_select(int ldn)
superio_select(int ldn)
{ {
outb(DEV, REG); outb(DEV, REG);
outb(ldn, VAL); outb(ldn, VAL);
} }
static inline void static inline int superio_enter(void)
superio_enter(void)
{ {
/*
* Try to reserve REG and REG + 1 for exclusive access.
*/
if (!request_muxed_region(REG, 2, DRVNAME))
return -EBUSY;
outb(0x87, REG); outb(0x87, REG);
outb(0x01, REG); outb(0x01, REG);
outb(0x55, REG); outb(0x55, REG);
outb(0x55, REG); outb(0x55, REG);
return 0;
} }
static inline void static inline void superio_exit(void)
superio_exit(void)
{ {
outb(0x02, REG); outb(0x02, REG);
outb(0x02, VAL); outb(0x02, VAL);
release_region(REG, 2);
} }
/* Logical device 4 registers */ /* Logical device 4 registers */
...@@ -1542,11 +1545,15 @@ static const struct attribute_group it87_group_label = { ...@@ -1542,11 +1545,15 @@ static const struct attribute_group it87_group_label = {
static int __init it87_find(unsigned short *address, static int __init it87_find(unsigned short *address,
struct it87_sio_data *sio_data) struct it87_sio_data *sio_data)
{ {
int err = -ENODEV; int err;
u16 chip_type; u16 chip_type;
const char *board_vendor, *board_name; const char *board_vendor, *board_name;
superio_enter(); err = superio_enter();
if (err)
return err;
err = -ENODEV;
chip_type = force_id ? force_id : superio_inw(DEVID); chip_type = force_id ? force_id : superio_inw(DEVID);
switch (chip_type) { switch (chip_type) {
......
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