Commit 5b0380c94a2e888b7858fbec6fc3ac623bc9b05a
Committed by
Jean Delvare
1 parent
357b9dc6c2
Exists in
master
and in
39 other branches
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>
Showing 1 changed file with 19 additions and 12 deletions Side-by-side Diff
drivers/hwmon/it87.c
... | ... | @@ -77,15 +77,13 @@ |
77 | 77 | #define DEVID 0x20 /* Register: Device ID */ |
78 | 78 | #define DEVREV 0x22 /* Register: Device Revision */ |
79 | 79 | |
80 | -static inline int | |
81 | -superio_inb(int reg) | |
80 | +static inline int superio_inb(int reg) | |
82 | 81 | { |
83 | 82 | outb(reg, REG); |
84 | 83 | return inb(VAL); |
85 | 84 | } |
86 | 85 | |
87 | -static inline void | |
88 | -superio_outb(int reg, int val) | |
86 | +static inline void superio_outb(int reg, int val) | |
89 | 87 | { |
90 | 88 | outb(reg, REG); |
91 | 89 | outb(val, VAL); |
92 | 90 | |
93 | 91 | |
94 | 92 | |
95 | 93 | |
96 | 94 | |
... | ... | @@ -101,27 +99,32 @@ |
101 | 99 | return val; |
102 | 100 | } |
103 | 101 | |
104 | -static inline void | |
105 | -superio_select(int ldn) | |
102 | +static inline void superio_select(int ldn) | |
106 | 103 | { |
107 | 104 | outb(DEV, REG); |
108 | 105 | outb(ldn, VAL); |
109 | 106 | } |
110 | 107 | |
111 | -static inline void | |
112 | -superio_enter(void) | |
108 | +static inline int 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 | 116 | outb(0x87, REG); |
115 | 117 | outb(0x01, REG); |
116 | 118 | outb(0x55, REG); |
117 | 119 | outb(0x55, REG); |
120 | + return 0; | |
118 | 121 | } |
119 | 122 | |
120 | -static inline void | |
121 | -superio_exit(void) | |
123 | +static inline void superio_exit(void) | |
122 | 124 | { |
123 | 125 | outb(0x02, REG); |
124 | 126 | outb(0x02, VAL); |
127 | + release_region(REG, 2); | |
125 | 128 | } |
126 | 129 | |
127 | 130 | /* Logical device 4 registers */ |
128 | 131 | |
... | ... | @@ -1542,11 +1545,15 @@ |
1542 | 1545 | static int __init it87_find(unsigned short *address, |
1543 | 1546 | struct it87_sio_data *sio_data) |
1544 | 1547 | { |
1545 | - int err = -ENODEV; | |
1548 | + int err; | |
1546 | 1549 | u16 chip_type; |
1547 | 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 | 1557 | chip_type = force_id ? force_id : superio_inw(DEVID); |
1551 | 1558 | |
1552 | 1559 | switch (chip_type) { |