aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/ams
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon/ams')
-rw-r--r--drivers/hwmon/ams/ams-input.c76
-rw-r--r--drivers/hwmon/ams/ams.h5
2 files changed, 34 insertions, 47 deletions
diff --git a/drivers/hwmon/ams/ams-input.c b/drivers/hwmon/ams/ams-input.c
index ca7095d96ad0..7b81e0c2c2d9 100644
--- a/drivers/hwmon/ams/ams-input.c
+++ b/drivers/hwmon/ams/ams-input.c
@@ -27,47 +27,32 @@ static unsigned int invert;
27module_param(invert, bool, 0644); 27module_param(invert, bool, 0644);
28MODULE_PARM_DESC(invert, "Invert input data on X and Y axis"); 28MODULE_PARM_DESC(invert, "Invert input data on X and Y axis");
29 29
30static int ams_input_kthread(void *data) 30static void ams_idev_poll(struct input_polled_dev *dev)
31{ 31{
32 struct input_dev *idev = dev->input;
32 s8 x, y, z; 33 s8 x, y, z;
33 34
34 while (!kthread_should_stop()) { 35 mutex_lock(&ams_info.lock);
35 mutex_lock(&ams_info.lock);
36
37 ams_sensors(&x, &y, &z);
38
39 x -= ams_info.xcalib;
40 y -= ams_info.ycalib;
41 z -= ams_info.zcalib;
42
43 input_report_abs(ams_info.idev, ABS_X, invert ? -x : x);
44 input_report_abs(ams_info.idev, ABS_Y, invert ? -y : y);
45 input_report_abs(ams_info.idev, ABS_Z, z);
46 36
47 input_sync(ams_info.idev); 37 ams_sensors(&x, &y, &z);
48 38
49 mutex_unlock(&ams_info.lock); 39 x -= ams_info.xcalib;
40 y -= ams_info.ycalib;
41 z -= ams_info.zcalib;
50 42
51 msleep(25); 43 input_report_abs(idev, ABS_X, invert ? -x : x);
52 } 44 input_report_abs(idev, ABS_Y, invert ? -y : y);
45 input_report_abs(idev, ABS_Z, z);
53 46
54 return 0; 47 input_sync(idev);
55}
56 48
57static int ams_input_open(struct input_dev *dev) 49 mutex_unlock(&ams_info.lock);
58{
59 ams_info.kthread = kthread_run(ams_input_kthread, NULL, "kams");
60 return IS_ERR(ams_info.kthread) ? PTR_ERR(ams_info.kthread) : 0;
61}
62
63static void ams_input_close(struct input_dev *dev)
64{
65 kthread_stop(ams_info.kthread);
66} 50}
67 51
68/* Call with ams_info.lock held! */ 52/* Call with ams_info.lock held! */
69static void ams_input_enable(void) 53static void ams_input_enable(void)
70{ 54{
55 struct input_dev *input;
71 s8 x, y, z; 56 s8 x, y, z;
72 57
73 if (ams_info.idev) 58 if (ams_info.idev)
@@ -78,27 +63,29 @@ static void ams_input_enable(void)
78 ams_info.ycalib = y; 63 ams_info.ycalib = y;
79 ams_info.zcalib = z; 64 ams_info.zcalib = z;
80 65
81 ams_info.idev = input_allocate_device(); 66 ams_info.idev = input_allocate_polled_device();
82 if (!ams_info.idev) 67 if (!ams_info.idev)
83 return; 68 return;
84 69
85 ams_info.idev->name = "Apple Motion Sensor"; 70 ams_info.idev->poll = ams_idev_poll;
86 ams_info.idev->id.bustype = ams_info.bustype; 71 ams_info.idev->poll_interval = 25;
87 ams_info.idev->id.vendor = 0; 72
88 ams_info.idev->open = ams_input_open; 73 input = ams_info.idev->input;
89 ams_info.idev->close = ams_input_close; 74 input->name = "Apple Motion Sensor";
90 ams_info.idev->dev.parent = &ams_info.of_dev->dev; 75 input->id.bustype = ams_info.bustype;
76 input->id.vendor = 0;
77 input->dev.parent = &ams_info.of_dev->dev;
91 78
92 input_set_abs_params(ams_info.idev, ABS_X, -50, 50, 3, 0); 79 input_set_abs_params(input, ABS_X, -50, 50, 3, 0);
93 input_set_abs_params(ams_info.idev, ABS_Y, -50, 50, 3, 0); 80 input_set_abs_params(input, ABS_Y, -50, 50, 3, 0);
94 input_set_abs_params(ams_info.idev, ABS_Z, -50, 50, 3, 0); 81 input_set_abs_params(input, ABS_Z, -50, 50, 3, 0);
95 82
96 set_bit(EV_ABS, ams_info.idev->evbit); 83 set_bit(EV_ABS, input->evbit);
97 set_bit(EV_KEY, ams_info.idev->evbit); 84 set_bit(EV_KEY, input->evbit);
98 set_bit(BTN_TOUCH, ams_info.idev->keybit); 85 set_bit(BTN_TOUCH, input->keybit);
99 86
100 if (input_register_device(ams_info.idev)) { 87 if (input_register_polled_device(ams_info.idev)) {
101 input_free_device(ams_info.idev); 88 input_free_polled_device(ams_info.idev);
102 ams_info.idev = NULL; 89 ams_info.idev = NULL;
103 return; 90 return;
104 } 91 }
@@ -108,7 +95,8 @@ static void ams_input_enable(void)
108static void ams_input_disable(void) 95static void ams_input_disable(void)
109{ 96{
110 if (ams_info.idev) { 97 if (ams_info.idev) {
111 input_unregister_device(ams_info.idev); 98 input_unregister_polled_device(ams_info.idev);
99 input_free_polled_device(ams_info.idev);
112 ams_info.idev = NULL; 100 ams_info.idev = NULL;
113 } 101 }
114} 102}
diff --git a/drivers/hwmon/ams/ams.h b/drivers/hwmon/ams/ams.h
index 240730e6bcde..a6221e5dd984 100644
--- a/drivers/hwmon/ams/ams.h
+++ b/drivers/hwmon/ams/ams.h
@@ -1,5 +1,5 @@
1#include <linux/i2c.h> 1#include <linux/i2c.h>
2#include <linux/input.h> 2#include <linux/input-polldev.h>
3#include <linux/kthread.h> 3#include <linux/kthread.h>
4#include <linux/mutex.h> 4#include <linux/mutex.h>
5#include <linux/spinlock.h> 5#include <linux/spinlock.h>
@@ -52,8 +52,7 @@ struct ams {
52#endif 52#endif
53 53
54 /* Joystick emulation */ 54 /* Joystick emulation */
55 struct task_struct *kthread; 55 struct input_polled_dev *idev;
56 struct input_dev *idev;
57 __u16 bustype; 56 __u16 bustype;
58 57
59 /* calibrated null values */ 58 /* calibrated null values */