aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/lis3lv02d.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon/lis3lv02d.c')
-rw-r--r--drivers/hwmon/lis3lv02d.c74
1 files changed, 24 insertions, 50 deletions
diff --git a/drivers/hwmon/lis3lv02d.c b/drivers/hwmon/lis3lv02d.c
index df3f58613f7b..366190609c73 100644
--- a/drivers/hwmon/lis3lv02d.c
+++ b/drivers/hwmon/lis3lv02d.c
@@ -27,9 +27,7 @@
27#include <linux/types.h> 27#include <linux/types.h>
28#include <linux/platform_device.h> 28#include <linux/platform_device.h>
29#include <linux/interrupt.h> 29#include <linux/interrupt.h>
30#include <linux/input.h> 30#include <linux/input-polldev.h>
31#include <linux/kthread.h>
32#include <linux/semaphore.h>
33#include <linux/delay.h> 31#include <linux/delay.h>
34#include <linux/wait.h> 32#include <linux/wait.h>
35#include <linux/poll.h> 33#include <linux/poll.h>
@@ -270,43 +268,16 @@ static struct miscdevice lis3lv02d_misc_device = {
270 .fops = &lis3lv02d_misc_fops, 268 .fops = &lis3lv02d_misc_fops,
271}; 269};
272 270
273/** 271static void lis3lv02d_joystick_poll(struct input_polled_dev *pidev)
274 * lis3lv02d_joystick_kthread - Kthread polling function
275 * @data: unused - here to conform to threadfn prototype
276 */
277static int lis3lv02d_joystick_kthread(void *data)
278{ 272{
279 int x, y, z; 273 int x, y, z;
280 274
281 while (!kthread_should_stop()) { 275 lis3lv02d_get_xyz(&lis3_dev, &x, &y, &z);
282 lis3lv02d_get_xyz(&lis3_dev, &x, &y, &z); 276 input_report_abs(pidev->input, ABS_X, x - lis3_dev.xcalib);
283 input_report_abs(lis3_dev.idev, ABS_X, x - lis3_dev.xcalib); 277 input_report_abs(pidev->input, ABS_Y, y - lis3_dev.ycalib);
284 input_report_abs(lis3_dev.idev, ABS_Y, y - lis3_dev.ycalib); 278 input_report_abs(pidev->input, ABS_Z, z - lis3_dev.zcalib);
285 input_report_abs(lis3_dev.idev, ABS_Z, z - lis3_dev.zcalib);
286
287 input_sync(lis3_dev.idev);
288
289 try_to_freeze();
290 msleep_interruptible(MDPS_POLL_INTERVAL);
291 }
292
293 return 0;
294}
295
296static int lis3lv02d_joystick_open(struct input_dev *input)
297{
298 lis3_dev.kthread = kthread_run(lis3lv02d_joystick_kthread, NULL, "klis3lv02d");
299 if (IS_ERR(lis3_dev.kthread)) {
300 return PTR_ERR(lis3_dev.kthread);
301 }
302
303 return 0;
304} 279}
305 280
306static void lis3lv02d_joystick_close(struct input_dev *input)
307{
308 kthread_stop(lis3_dev.kthread);
309}
310 281
311static inline void lis3lv02d_calibrate_joystick(void) 282static inline void lis3lv02d_calibrate_joystick(void)
312{ 283{
@@ -316,33 +287,36 @@ static inline void lis3lv02d_calibrate_joystick(void)
316 287
317int lis3lv02d_joystick_enable(void) 288int lis3lv02d_joystick_enable(void)
318{ 289{
290 struct input_dev *input_dev;
319 int err; 291 int err;
320 292
321 if (lis3_dev.idev) 293 if (lis3_dev.idev)
322 return -EINVAL; 294 return -EINVAL;
323 295
324 lis3_dev.idev = input_allocate_device(); 296 lis3_dev.idev = input_allocate_polled_device();
325 if (!lis3_dev.idev) 297 if (!lis3_dev.idev)
326 return -ENOMEM; 298 return -ENOMEM;
327 299
300 lis3_dev.idev->poll = lis3lv02d_joystick_poll;
301 lis3_dev.idev->poll_interval = MDPS_POLL_INTERVAL;
302 input_dev = lis3_dev.idev->input;
303
328 lis3lv02d_calibrate_joystick(); 304 lis3lv02d_calibrate_joystick();
329 305
330 lis3_dev.idev->name = "ST LIS3LV02DL Accelerometer"; 306 input_dev->name = "ST LIS3LV02DL Accelerometer";
331 lis3_dev.idev->phys = DRIVER_NAME "/input0"; 307 input_dev->phys = DRIVER_NAME "/input0";
332 lis3_dev.idev->id.bustype = BUS_HOST; 308 input_dev->id.bustype = BUS_HOST;
333 lis3_dev.idev->id.vendor = 0; 309 input_dev->id.vendor = 0;
334 lis3_dev.idev->dev.parent = &lis3_dev.pdev->dev; 310 input_dev->dev.parent = &lis3_dev.pdev->dev;
335 lis3_dev.idev->open = lis3lv02d_joystick_open;
336 lis3_dev.idev->close = lis3lv02d_joystick_close;
337 311
338 set_bit(EV_ABS, lis3_dev.idev->evbit); 312 set_bit(EV_ABS, input_dev->evbit);
339 input_set_abs_params(lis3_dev.idev, ABS_X, -lis3_dev.mdps_max_val, lis3_dev.mdps_max_val, 3, 3); 313 input_set_abs_params(input_dev, ABS_X, -lis3_dev.mdps_max_val, lis3_dev.mdps_max_val, 3, 3);
340 input_set_abs_params(lis3_dev.idev, ABS_Y, -lis3_dev.mdps_max_val, lis3_dev.mdps_max_val, 3, 3); 314 input_set_abs_params(input_dev, ABS_Y, -lis3_dev.mdps_max_val, lis3_dev.mdps_max_val, 3, 3);
341 input_set_abs_params(lis3_dev.idev, ABS_Z, -lis3_dev.mdps_max_val, lis3_dev.mdps_max_val, 3, 3); 315 input_set_abs_params(input_dev, ABS_Z, -lis3_dev.mdps_max_val, lis3_dev.mdps_max_val, 3, 3);
342 316
343 err = input_register_device(lis3_dev.idev); 317 err = input_register_polled_device(lis3_dev.idev);
344 if (err) { 318 if (err) {
345 input_free_device(lis3_dev.idev); 319 input_free_polled_device(lis3_dev.idev);
346 lis3_dev.idev = NULL; 320 lis3_dev.idev = NULL;
347 } 321 }
348 322
@@ -357,7 +331,7 @@ void lis3lv02d_joystick_disable(void)
357 331
358 if (lis3_dev.irq) 332 if (lis3_dev.irq)
359 misc_deregister(&lis3lv02d_misc_device); 333 misc_deregister(&lis3lv02d_misc_device);
360 input_unregister_device(lis3_dev.idev); 334 input_unregister_polled_device(lis3_dev.idev);
361 lis3_dev.idev = NULL; 335 lis3_dev.idev = NULL;
362} 336}
363EXPORT_SYMBOL_GPL(lis3lv02d_joystick_disable); 337EXPORT_SYMBOL_GPL(lis3lv02d_joystick_disable);