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