diff options
author | Nat Gurumoorthy <natg@google.com> | 2011-05-25 14:43:33 -0400 |
---|---|---|
committer | Jean Delvare <khali@endymion.delvare> | 2011-05-25 14:43:33 -0400 |
commit | 5b0380c94a2e888b7858fbec6fc3ac623bc9b05a (patch) | |
tree | 25bfaf2ab49a7b5284dd0bb04f5d6b100fe65282 /drivers/hwmon/it87.c | |
parent | 357b9dc6c2dbb01e835415355b70d6b47c43a102 (diff) |
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: Nat Gurumoorthy <natg@google.com>
Acked-by: Guenter Roeck <guenter.roeck@ericsson.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'drivers/hwmon/it87.c')
-rw-r--r-- | drivers/hwmon/it87.c | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c index 316b64823f7b..bb6405b92007 100644 --- a/drivers/hwmon/it87.c +++ b/drivers/hwmon/it87.c | |||
@@ -77,15 +77,13 @@ static struct platform_device *pdev; | |||
77 | #define DEVID 0x20 /* Register: Device ID */ | 77 | #define DEVID 0x20 /* Register: Device ID */ |
78 | #define DEVREV 0x22 /* Register: Device Revision */ | 78 | #define DEVREV 0x22 /* Register: Device Revision */ |
79 | 79 | ||
80 | static inline int | 80 | static inline int superio_inb(int reg) |
81 | superio_inb(int reg) | ||
82 | { | 81 | { |
83 | outb(reg, REG); | 82 | outb(reg, REG); |
84 | return inb(VAL); | 83 | return inb(VAL); |
85 | } | 84 | } |
86 | 85 | ||
87 | static inline void | 86 | static inline void superio_outb(int reg, int val) |
88 | superio_outb(int reg, int val) | ||
89 | { | 87 | { |
90 | outb(reg, REG); | 88 | outb(reg, REG); |
91 | outb(val, VAL); | 89 | outb(val, VAL); |
@@ -101,27 +99,32 @@ static int superio_inw(int reg) | |||
101 | return val; | 99 | return val; |
102 | } | 100 | } |
103 | 101 | ||
104 | static inline void | 102 | static inline void superio_select(int ldn) |
105 | superio_select(int ldn) | ||
106 | { | 103 | { |
107 | outb(DEV, REG); | 104 | outb(DEV, REG); |
108 | outb(ldn, VAL); | 105 | outb(ldn, VAL); |
109 | } | 106 | } |
110 | 107 | ||
111 | static inline void | 108 | static inline int superio_enter(void) |
112 | superio_enter(void) | ||
113 | { | 109 | { |
110 | /* | ||
111 | * Try to reserve REG and REG + 1 for exclusive access. | ||
112 | */ | ||
113 | if (!request_muxed_region(REG, 2, DRVNAME)) | ||
114 | return -EBUSY; | ||
115 | |||
114 | outb(0x87, REG); | 116 | outb(0x87, REG); |
115 | outb(0x01, REG); | 117 | outb(0x01, REG); |
116 | outb(0x55, REG); | 118 | outb(0x55, REG); |
117 | outb(0x55, REG); | 119 | outb(0x55, REG); |
120 | return 0; | ||
118 | } | 121 | } |
119 | 122 | ||
120 | static inline void | 123 | static inline void superio_exit(void) |
121 | superio_exit(void) | ||
122 | { | 124 | { |
123 | outb(0x02, REG); | 125 | outb(0x02, REG); |
124 | outb(0x02, VAL); | 126 | outb(0x02, VAL); |
127 | release_region(REG, 2); | ||
125 | } | 128 | } |
126 | 129 | ||
127 | /* Logical device 4 registers */ | 130 | /* Logical device 4 registers */ |
@@ -1542,11 +1545,15 @@ static const struct attribute_group it87_group_label = { | |||
1542 | static int __init it87_find(unsigned short *address, | 1545 | static int __init it87_find(unsigned short *address, |
1543 | struct it87_sio_data *sio_data) | 1546 | struct it87_sio_data *sio_data) |
1544 | { | 1547 | { |
1545 | int err = -ENODEV; | 1548 | int err; |
1546 | u16 chip_type; | 1549 | u16 chip_type; |
1547 | const char *board_vendor, *board_name; | 1550 | const char *board_vendor, *board_name; |
1548 | 1551 | ||
1549 | superio_enter(); | 1552 | err = superio_enter(); |
1553 | if (err) | ||
1554 | return err; | ||
1555 | |||
1556 | err = -ENODEV; | ||
1550 | chip_type = force_id ? force_id : superio_inw(DEVID); | 1557 | chip_type = force_id ? force_id : superio_inw(DEVID); |
1551 | 1558 | ||
1552 | switch (chip_type) { | 1559 | switch (chip_type) { |