aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/hdaps.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon/hdaps.c')
-rw-r--r--drivers/hwmon/hdaps.c38
1 files changed, 20 insertions, 18 deletions
diff --git a/drivers/hwmon/hdaps.c b/drivers/hwmon/hdaps.c
index bf759ea545ac..f82fa2d23f95 100644
--- a/drivers/hwmon/hdaps.c
+++ b/drivers/hwmon/hdaps.c
@@ -30,10 +30,12 @@
30#include <linux/platform_device.h> 30#include <linux/platform_device.h>
31#include <linux/input.h> 31#include <linux/input.h>
32#include <linux/kernel.h> 32#include <linux/kernel.h>
33#include <linux/mutex.h>
33#include <linux/module.h> 34#include <linux/module.h>
34#include <linux/timer.h> 35#include <linux/timer.h>
35#include <linux/dmi.h> 36#include <linux/dmi.h>
36#include <linux/jiffies.h> 37#include <linux/jiffies.h>
38
37#include <asm/io.h> 39#include <asm/io.h>
38 40
39#define HDAPS_LOW_PORT 0x1600 /* first port used by hdaps */ 41#define HDAPS_LOW_PORT 0x1600 /* first port used by hdaps */
@@ -71,10 +73,10 @@ static u8 km_activity;
71static int rest_x; 73static int rest_x;
72static int rest_y; 74static int rest_y;
73 75
74static DECLARE_MUTEX(hdaps_sem); 76static DEFINE_MUTEX(hdaps_mtx);
75 77
76/* 78/*
77 * __get_latch - Get the value from a given port. Callers must hold hdaps_sem. 79 * __get_latch - Get the value from a given port. Callers must hold hdaps_mtx.
78 */ 80 */
79static inline u8 __get_latch(u16 port) 81static inline u8 __get_latch(u16 port)
80{ 82{
@@ -83,7 +85,7 @@ static inline u8 __get_latch(u16 port)
83 85
84/* 86/*
85 * __check_latch - Check a port latch for a given value. Returns zero if the 87 * __check_latch - Check a port latch for a given value. Returns zero if the
86 * port contains the given value. Callers must hold hdaps_sem. 88 * port contains the given value. Callers must hold hdaps_mtx.
87 */ 89 */
88static inline int __check_latch(u16 port, u8 val) 90static inline int __check_latch(u16 port, u8 val)
89{ 91{
@@ -94,7 +96,7 @@ static inline int __check_latch(u16 port, u8 val)
94 96
95/* 97/*
96 * __wait_latch - Wait up to 100us for a port latch to get a certain value, 98 * __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_sem. 99 * returning zero if the value is obtained. Callers must hold hdaps_mtx.
98 */ 100 */
99static int __wait_latch(u16 port, u8 val) 101static int __wait_latch(u16 port, u8 val)
100{ 102{
@@ -111,7 +113,7 @@ static int __wait_latch(u16 port, u8 val)
111 113
112/* 114/*
113 * __device_refresh - request a refresh from the accelerometer. Does not wait 115 * __device_refresh - request a refresh from the accelerometer. Does not wait
114 * for refresh to complete. Callers must hold hdaps_sem. 116 * for refresh to complete. Callers must hold hdaps_mtx.
115 */ 117 */
116static void __device_refresh(void) 118static void __device_refresh(void)
117{ 119{
@@ -125,7 +127,7 @@ static void __device_refresh(void)
125/* 127/*
126 * __device_refresh_sync - request a synchronous refresh from the 128 * __device_refresh_sync - request a synchronous refresh from the
127 * accelerometer. We wait for the refresh to complete. Returns zero if 129 * accelerometer. We wait for the refresh to complete. Returns zero if
128 * successful and nonzero on error. Callers must hold hdaps_sem. 130 * successful and nonzero on error. Callers must hold hdaps_mtx.
129 */ 131 */
130static int __device_refresh_sync(void) 132static int __device_refresh_sync(void)
131{ 133{
@@ -135,7 +137,7 @@ static int __device_refresh_sync(void)
135 137
136/* 138/*
137 * __device_complete - indicate to the accelerometer that we are done reading 139 * __device_complete - indicate to the accelerometer that we are done reading
138 * data, and then initiate an async refresh. Callers must hold hdaps_sem. 140 * data, and then initiate an async refresh. Callers must hold hdaps_mtx.
139 */ 141 */
140static inline void __device_complete(void) 142static inline void __device_complete(void)
141{ 143{
@@ -153,7 +155,7 @@ static int hdaps_readb_one(unsigned int port, u8 *val)
153{ 155{
154 int ret; 156 int ret;
155 157
156 down(&hdaps_sem); 158 mutex_lock(&hdaps_mtx);
157 159
158 /* do a sync refresh -- we need to be sure that we read fresh data */ 160 /* do a sync refresh -- we need to be sure that we read fresh data */
159 ret = __device_refresh_sync(); 161 ret = __device_refresh_sync();
@@ -164,7 +166,7 @@ static int hdaps_readb_one(unsigned int port, u8 *val)
164 __device_complete(); 166 __device_complete();
165 167
166out: 168out:
167 up(&hdaps_sem); 169 mutex_unlock(&hdaps_mtx);
168 return ret; 170 return ret;
169} 171}
170 172
@@ -199,9 +201,9 @@ static int hdaps_read_pair(unsigned int port1, unsigned int port2,
199{ 201{
200 int ret; 202 int ret;
201 203
202 down(&hdaps_sem); 204 mutex_lock(&hdaps_mtx);
203 ret = __hdaps_read_pair(port1, port2, val1, val2); 205 ret = __hdaps_read_pair(port1, port2, val1, val2);
204 up(&hdaps_sem); 206 mutex_unlock(&hdaps_mtx);
205 207
206 return ret; 208 return ret;
207} 209}
@@ -214,7 +216,7 @@ static int hdaps_device_init(void)
214{ 216{
215 int total, ret = -ENXIO; 217 int total, ret = -ENXIO;
216 218
217 down(&hdaps_sem); 219 mutex_lock(&hdaps_mtx);
218 220
219 outb(0x13, 0x1610); 221 outb(0x13, 0x1610);
220 outb(0x01, 0x161f); 222 outb(0x01, 0x161f);
@@ -280,7 +282,7 @@ static int hdaps_device_init(void)
280 } 282 }
281 283
282out: 284out:
283 up(&hdaps_sem); 285 mutex_unlock(&hdaps_mtx);
284 return ret; 286 return ret;
285} 287}
286 288
@@ -314,7 +316,7 @@ static struct platform_driver hdaps_driver = {
314}; 316};
315 317
316/* 318/*
317 * hdaps_calibrate - Set our "resting" values. Callers must hold hdaps_sem. 319 * hdaps_calibrate - Set our "resting" values. Callers must hold hdaps_mtx.
318 */ 320 */
319static void hdaps_calibrate(void) 321static void hdaps_calibrate(void)
320{ 322{
@@ -326,7 +328,7 @@ static void hdaps_mousedev_poll(unsigned long unused)
326 int x, y; 328 int x, y;
327 329
328 /* Cannot sleep. Try nonblockingly. If we fail, try again later. */ 330 /* Cannot sleep. Try nonblockingly. If we fail, try again later. */
329 if (down_trylock(&hdaps_sem)) { 331 if (mutex_trylock(&hdaps_mtx)) {
330 mod_timer(&hdaps_timer,jiffies + HDAPS_POLL_PERIOD); 332 mod_timer(&hdaps_timer,jiffies + HDAPS_POLL_PERIOD);
331 return; 333 return;
332 } 334 }
@@ -341,7 +343,7 @@ static void hdaps_mousedev_poll(unsigned long unused)
341 mod_timer(&hdaps_timer, jiffies + HDAPS_POLL_PERIOD); 343 mod_timer(&hdaps_timer, jiffies + HDAPS_POLL_PERIOD);
342 344
343out: 345out:
344 up(&hdaps_sem); 346 mutex_unlock(&hdaps_mtx);
345} 347}
346 348
347 349
@@ -421,9 +423,9 @@ static ssize_t hdaps_calibrate_store(struct device *dev,
421 struct device_attribute *attr, 423 struct device_attribute *attr,
422 const char *buf, size_t count) 424 const char *buf, size_t count)
423{ 425{
424 down(&hdaps_sem); 426 mutex_lock(&hdaps_mtx);
425 hdaps_calibrate(); 427 hdaps_calibrate();
426 up(&hdaps_sem); 428 mutex_unlock(&hdaps_mtx);
427 429
428 return count; 430 return count;
429} 431}