diff options
-rw-r--r-- | drivers/hwmon/hdaps.c | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/drivers/hwmon/hdaps.c b/drivers/hwmon/hdaps.c index 7636c1a58f9c..23a9e1ea8e32 100644 --- a/drivers/hwmon/hdaps.c +++ b/drivers/hwmon/hdaps.c | |||
@@ -33,7 +33,6 @@ | |||
33 | #include <linux/module.h> | 33 | #include <linux/module.h> |
34 | #include <linux/timer.h> | 34 | #include <linux/timer.h> |
35 | #include <linux/dmi.h> | 35 | #include <linux/dmi.h> |
36 | #include <linux/mutex.h> | ||
37 | #include <asm/io.h> | 36 | #include <asm/io.h> |
38 | 37 | ||
39 | #define HDAPS_LOW_PORT 0x1600 /* first port used by hdaps */ | 38 | #define HDAPS_LOW_PORT 0x1600 /* first port used by hdaps */ |
@@ -71,10 +70,10 @@ static u8 km_activity; | |||
71 | static int rest_x; | 70 | static int rest_x; |
72 | static int rest_y; | 71 | static int rest_y; |
73 | 72 | ||
74 | static DEFINE_MUTEX(hdaps_mutex); | 73 | static DECLARE_MUTEX(hdaps_sem); |
75 | 74 | ||
76 | /* | 75 | /* |
77 | * __get_latch - Get the value from a given port. Callers must hold hdaps_mutex. | 76 | * __get_latch - Get the value from a given port. Callers must hold hdaps_sem. |
78 | */ | 77 | */ |
79 | static inline u8 __get_latch(u16 port) | 78 | static inline u8 __get_latch(u16 port) |
80 | { | 79 | { |
@@ -83,7 +82,7 @@ static inline u8 __get_latch(u16 port) | |||
83 | 82 | ||
84 | /* | 83 | /* |
85 | * __check_latch - Check a port latch for a given value. Returns zero if the | 84 | * __check_latch - Check a port latch for a given value. Returns zero if the |
86 | * port contains the given value. Callers must hold hdaps_mutex. | 85 | * port contains the given value. Callers must hold hdaps_sem. |
87 | */ | 86 | */ |
88 | static inline int __check_latch(u16 port, u8 val) | 87 | static inline int __check_latch(u16 port, u8 val) |
89 | { | 88 | { |
@@ -94,7 +93,7 @@ static inline int __check_latch(u16 port, u8 val) | |||
94 | 93 | ||
95 | /* | 94 | /* |
96 | * __wait_latch - Wait up to 100us for a port latch to get a certain value, | 95 | * __wait_latch - Wait up to 100us for a port latch to get a certain value, |
97 | * returning zero if the value is obtained. Callers must hold hdaps_mutex. | 96 | * returning zero if the value is obtained. Callers must hold hdaps_sem. |
98 | */ | 97 | */ |
99 | static int __wait_latch(u16 port, u8 val) | 98 | static int __wait_latch(u16 port, u8 val) |
100 | { | 99 | { |
@@ -111,7 +110,7 @@ static int __wait_latch(u16 port, u8 val) | |||
111 | 110 | ||
112 | /* | 111 | /* |
113 | * __device_refresh - request a refresh from the accelerometer. Does not wait | 112 | * __device_refresh - request a refresh from the accelerometer. Does not wait |
114 | * for refresh to complete. Callers must hold hdaps_mutex. | 113 | * for refresh to complete. Callers must hold hdaps_sem. |
115 | */ | 114 | */ |
116 | static void __device_refresh(void) | 115 | static void __device_refresh(void) |
117 | { | 116 | { |
@@ -125,7 +124,7 @@ static void __device_refresh(void) | |||
125 | /* | 124 | /* |
126 | * __device_refresh_sync - request a synchronous refresh from the | 125 | * __device_refresh_sync - request a synchronous refresh from the |
127 | * accelerometer. We wait for the refresh to complete. Returns zero if | 126 | * accelerometer. We wait for the refresh to complete. Returns zero if |
128 | * successful and nonzero on error. Callers must hold hdaps_mutex. | 127 | * successful and nonzero on error. Callers must hold hdaps_sem. |
129 | */ | 128 | */ |
130 | static int __device_refresh_sync(void) | 129 | static int __device_refresh_sync(void) |
131 | { | 130 | { |
@@ -135,7 +134,7 @@ static int __device_refresh_sync(void) | |||
135 | 134 | ||
136 | /* | 135 | /* |
137 | * __device_complete - indicate to the accelerometer that we are done reading | 136 | * __device_complete - indicate to the accelerometer that we are done reading |
138 | * data, and then initiate an async refresh. Callers must hold hdaps_mutex. | 137 | * data, and then initiate an async refresh. Callers must hold hdaps_sem. |
139 | */ | 138 | */ |
140 | static inline void __device_complete(void) | 139 | static inline void __device_complete(void) |
141 | { | 140 | { |
@@ -153,7 +152,7 @@ static int hdaps_readb_one(unsigned int port, u8 *val) | |||
153 | { | 152 | { |
154 | int ret; | 153 | int ret; |
155 | 154 | ||
156 | mutex_lock(&hdaps_mutex); | 155 | down(&hdaps_sem); |
157 | 156 | ||
158 | /* do a sync refresh -- we need to be sure that we read fresh data */ | 157 | /* do a sync refresh -- we need to be sure that we read fresh data */ |
159 | ret = __device_refresh_sync(); | 158 | ret = __device_refresh_sync(); |
@@ -164,7 +163,7 @@ static int hdaps_readb_one(unsigned int port, u8 *val) | |||
164 | __device_complete(); | 163 | __device_complete(); |
165 | 164 | ||
166 | out: | 165 | out: |
167 | mutex_unlock(&hdaps_mutex); | 166 | up(&hdaps_sem); |
168 | return ret; | 167 | return ret; |
169 | } | 168 | } |
170 | 169 | ||
@@ -199,9 +198,9 @@ static int hdaps_read_pair(unsigned int port1, unsigned int port2, | |||
199 | { | 198 | { |
200 | int ret; | 199 | int ret; |
201 | 200 | ||
202 | mutex_lock(&hdaps_mutex); | 201 | down(&hdaps_sem); |
203 | ret = __hdaps_read_pair(port1, port2, val1, val2); | 202 | ret = __hdaps_read_pair(port1, port2, val1, val2); |
204 | mutex_unlock(&hdaps_mutex); | 203 | up(&hdaps_sem); |
205 | 204 | ||
206 | return ret; | 205 | return ret; |
207 | } | 206 | } |
@@ -214,7 +213,7 @@ static int hdaps_device_init(void) | |||
214 | { | 213 | { |
215 | int total, ret = -ENXIO; | 214 | int total, ret = -ENXIO; |
216 | 215 | ||
217 | mutex_lock(&hdaps_mutex); | 216 | down(&hdaps_sem); |
218 | 217 | ||
219 | outb(0x13, 0x1610); | 218 | outb(0x13, 0x1610); |
220 | outb(0x01, 0x161f); | 219 | outb(0x01, 0x161f); |
@@ -280,7 +279,7 @@ static int hdaps_device_init(void) | |||
280 | } | 279 | } |
281 | 280 | ||
282 | out: | 281 | out: |
283 | mutex_unlock(&hdaps_mutex); | 282 | up(&hdaps_sem); |
284 | return ret; | 283 | return ret; |
285 | } | 284 | } |
286 | 285 | ||
@@ -314,7 +313,7 @@ static struct platform_driver hdaps_driver = { | |||
314 | }; | 313 | }; |
315 | 314 | ||
316 | /* | 315 | /* |
317 | * hdaps_calibrate - Set our "resting" values. Callers must hold hdaps_mutex. | 316 | * hdaps_calibrate - Set our "resting" values. Callers must hold hdaps_sem. |
318 | */ | 317 | */ |
319 | static void hdaps_calibrate(void) | 318 | static void hdaps_calibrate(void) |
320 | { | 319 | { |
@@ -326,7 +325,7 @@ static void hdaps_mousedev_poll(unsigned long unused) | |||
326 | int x, y; | 325 | int x, y; |
327 | 326 | ||
328 | /* Cannot sleep. Try nonblockingly. If we fail, try again later. */ | 327 | /* Cannot sleep. Try nonblockingly. If we fail, try again later. */ |
329 | if (!mutex_trylock(&hdaps_mutex)) { | 328 | if (down_trylock(&hdaps_sem)) { |
330 | mod_timer(&hdaps_timer,jiffies + HDAPS_POLL_PERIOD); | 329 | mod_timer(&hdaps_timer,jiffies + HDAPS_POLL_PERIOD); |
331 | return; | 330 | return; |
332 | } | 331 | } |
@@ -341,7 +340,7 @@ static void hdaps_mousedev_poll(unsigned long unused) | |||
341 | mod_timer(&hdaps_timer, jiffies + HDAPS_POLL_PERIOD); | 340 | mod_timer(&hdaps_timer, jiffies + HDAPS_POLL_PERIOD); |
342 | 341 | ||
343 | out: | 342 | out: |
344 | mutex_unlock(&hdaps_mutex); | 343 | up(&hdaps_sem); |
345 | } | 344 | } |
346 | 345 | ||
347 | 346 | ||
@@ -421,9 +420,9 @@ static ssize_t hdaps_calibrate_store(struct device *dev, | |||
421 | struct device_attribute *attr, | 420 | struct device_attribute *attr, |
422 | const char *buf, size_t count) | 421 | const char *buf, size_t count) |
423 | { | 422 | { |
424 | mutex_lock(&hdaps_mutex); | 423 | down(&hdaps_sem); |
425 | hdaps_calibrate(); | 424 | hdaps_calibrate(); |
426 | mutex_unlock(&hdaps_mutex); | 425 | up(&hdaps_sem); |
427 | 426 | ||
428 | return count; | 427 | return count; |
429 | } | 428 | } |