diff options
author | Anssi Hannula <anssi.hannula@gmail.com> | 2006-07-19 01:41:09 -0400 |
---|---|---|
committer | Dmitry Torokhov <dtor@insightbb.com> | 2006-07-19 01:41:09 -0400 |
commit | ff462551235d8d7d843a005950bc90924fcedede (patch) | |
tree | 638ca70b8d1572b6f3738cfcb87355e34d006317 | |
parent | dc76c912145febae8b62746d6f93e5edae342c9d (diff) |
Input: uinput - switch to the new FF interface
The userspace interface of the force feedback part is changed and
documentation in uinput.h is updated accordingly. MODULE_VERSION
is also incremented to reflect the revision.
Signed-off-by: Anssi Hannula <anssi.hannula@gmail.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
-rw-r--r-- | drivers/input/misc/uinput.c | 67 | ||||
-rw-r--r-- | include/linux/uinput.h | 35 |
2 files changed, 74 insertions, 28 deletions
diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c index d723e9ad7c41..9516439b7c78 100644 --- a/drivers/input/misc/uinput.c +++ b/drivers/input/misc/uinput.c | |||
@@ -20,6 +20,9 @@ | |||
20 | * Author: Aristeu Sergio Rozanski Filho <aris@cathedrallabs.org> | 20 | * Author: Aristeu Sergio Rozanski Filho <aris@cathedrallabs.org> |
21 | * | 21 | * |
22 | * Changes/Revisions: | 22 | * Changes/Revisions: |
23 | * 0.3 09/04/2006 (Anssi Hannula <anssi.hannula@gmail.com>) | ||
24 | * - updated ff support for the changes in kernel interface | ||
25 | * - added MODULE_VERSION | ||
23 | * 0.2 16/10/2004 (Micah Dowty <micah@navi.cx>) | 26 | * 0.2 16/10/2004 (Micah Dowty <micah@navi.cx>) |
24 | * - added force feedback support | 27 | * - added force feedback support |
25 | * - added UI_SET_PHYS | 28 | * - added UI_SET_PHYS |
@@ -107,18 +110,31 @@ static int uinput_request_submit(struct input_dev *dev, struct uinput_request *r | |||
107 | return request->retval; | 110 | return request->retval; |
108 | } | 111 | } |
109 | 112 | ||
110 | static int uinput_dev_upload_effect(struct input_dev *dev, struct ff_effect *effect) | 113 | static void uinput_dev_set_gain(struct input_dev *dev, u16 gain) |
114 | { | ||
115 | uinput_dev_event(dev, EV_FF, FF_GAIN, gain); | ||
116 | } | ||
117 | |||
118 | static void uinput_dev_set_autocenter(struct input_dev *dev, u16 magnitude) | ||
119 | { | ||
120 | uinput_dev_event(dev, EV_FF, FF_AUTOCENTER, magnitude); | ||
121 | } | ||
122 | |||
123 | static int uinput_dev_playback(struct input_dev *dev, int effect_id, int value) | ||
124 | { | ||
125 | return uinput_dev_event(dev, EV_FF, effect_id, value); | ||
126 | } | ||
127 | |||
128 | static int uinput_dev_upload_effect(struct input_dev *dev, struct ff_effect *effect, struct ff_effect *old) | ||
111 | { | 129 | { |
112 | struct uinput_request request; | 130 | struct uinput_request request; |
113 | int retval; | 131 | int retval; |
114 | 132 | ||
115 | if (!test_bit(EV_FF, dev->evbit)) | ||
116 | return -ENOSYS; | ||
117 | |||
118 | request.id = -1; | 133 | request.id = -1; |
119 | init_completion(&request.done); | 134 | init_completion(&request.done); |
120 | request.code = UI_FF_UPLOAD; | 135 | request.code = UI_FF_UPLOAD; |
121 | request.u.effect = effect; | 136 | request.u.upload.effect = effect; |
137 | request.u.upload.old = old; | ||
122 | 138 | ||
123 | retval = uinput_request_reserve_slot(dev->private, &request); | 139 | retval = uinput_request_reserve_slot(dev->private, &request); |
124 | if (!retval) | 140 | if (!retval) |
@@ -168,6 +184,7 @@ static void uinput_destroy_device(struct uinput_device *udev) | |||
168 | 184 | ||
169 | static int uinput_create_device(struct uinput_device *udev) | 185 | static int uinput_create_device(struct uinput_device *udev) |
170 | { | 186 | { |
187 | struct input_dev *dev = udev->dev; | ||
171 | int error; | 188 | int error; |
172 | 189 | ||
173 | if (udev->state != UIST_SETUP_COMPLETE) { | 190 | if (udev->state != UIST_SETUP_COMPLETE) { |
@@ -175,15 +192,29 @@ static int uinput_create_device(struct uinput_device *udev) | |||
175 | return -EINVAL; | 192 | return -EINVAL; |
176 | } | 193 | } |
177 | 194 | ||
178 | error = input_register_device(udev->dev); | 195 | if (udev->ff_effects_max) { |
179 | if (error) { | 196 | error = input_ff_create(dev, udev->ff_effects_max); |
180 | uinput_destroy_device(udev); | 197 | if (error) |
181 | return error; | 198 | goto fail1; |
199 | |||
200 | dev->ff->upload = uinput_dev_upload_effect; | ||
201 | dev->ff->erase = uinput_dev_erase_effect; | ||
202 | dev->ff->playback = uinput_dev_playback; | ||
203 | dev->ff->set_gain = uinput_dev_set_gain; | ||
204 | dev->ff->set_autocenter = uinput_dev_set_autocenter; | ||
182 | } | 205 | } |
183 | 206 | ||
207 | error = input_register_device(udev->dev); | ||
208 | if (error) | ||
209 | goto fail2; | ||
210 | |||
184 | udev->state = UIST_CREATED; | 211 | udev->state = UIST_CREATED; |
185 | 212 | ||
186 | return 0; | 213 | return 0; |
214 | |||
215 | fail2: input_ff_destroy(dev); | ||
216 | fail1: uinput_destroy_device(udev); | ||
217 | return error; | ||
187 | } | 218 | } |
188 | 219 | ||
189 | static int uinput_open(struct inode *inode, struct file *file) | 220 | static int uinput_open(struct inode *inode, struct file *file) |
@@ -243,8 +274,6 @@ static int uinput_allocate_device(struct uinput_device *udev) | |||
243 | return -ENOMEM; | 274 | return -ENOMEM; |
244 | 275 | ||
245 | udev->dev->event = uinput_dev_event; | 276 | udev->dev->event = uinput_dev_event; |
246 | udev->dev->upload_effect = uinput_dev_upload_effect; | ||
247 | udev->dev->erase_effect = uinput_dev_erase_effect; | ||
248 | udev->dev->private = udev; | 277 | udev->dev->private = udev; |
249 | 278 | ||
250 | return 0; | 279 | return 0; |
@@ -278,6 +307,8 @@ static int uinput_setup_device(struct uinput_device *udev, const char __user *bu | |||
278 | goto exit; | 307 | goto exit; |
279 | } | 308 | } |
280 | 309 | ||
310 | udev->ff_effects_max = user_dev->ff_effects_max; | ||
311 | |||
281 | size = strnlen(user_dev->name, UINPUT_MAX_NAME_SIZE) + 1; | 312 | size = strnlen(user_dev->name, UINPUT_MAX_NAME_SIZE) + 1; |
282 | if (!size) { | 313 | if (!size) { |
283 | retval = -EINVAL; | 314 | retval = -EINVAL; |
@@ -296,7 +327,6 @@ static int uinput_setup_device(struct uinput_device *udev, const char __user *bu | |||
296 | dev->id.vendor = user_dev->id.vendor; | 327 | dev->id.vendor = user_dev->id.vendor; |
297 | dev->id.product = user_dev->id.product; | 328 | dev->id.product = user_dev->id.product; |
298 | dev->id.version = user_dev->id.version; | 329 | dev->id.version = user_dev->id.version; |
299 | dev->ff_effects_max = user_dev->ff_effects_max; | ||
300 | 330 | ||
301 | size = sizeof(int) * (ABS_MAX + 1); | 331 | size = sizeof(int) * (ABS_MAX + 1); |
302 | memcpy(dev->absmax, user_dev->absmax, size); | 332 | memcpy(dev->absmax, user_dev->absmax, size); |
@@ -525,12 +555,17 @@ static long uinput_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |||
525 | break; | 555 | break; |
526 | } | 556 | } |
527 | req = uinput_request_find(udev, ff_up.request_id); | 557 | req = uinput_request_find(udev, ff_up.request_id); |
528 | if (!(req && req->code == UI_FF_UPLOAD && req->u.effect)) { | 558 | if (!(req && req->code == UI_FF_UPLOAD && req->u.upload.effect)) { |
529 | retval = -EINVAL; | 559 | retval = -EINVAL; |
530 | break; | 560 | break; |
531 | } | 561 | } |
532 | ff_up.retval = 0; | 562 | ff_up.retval = 0; |
533 | memcpy(&ff_up.effect, req->u.effect, sizeof(struct ff_effect)); | 563 | memcpy(&ff_up.effect, req->u.upload.effect, sizeof(struct ff_effect)); |
564 | if (req->u.upload.old) | ||
565 | memcpy(&ff_up.old, req->u.upload.old, sizeof(struct ff_effect)); | ||
566 | else | ||
567 | memset(&ff_up.old, 0, sizeof(struct ff_effect)); | ||
568 | |||
534 | if (copy_to_user(p, &ff_up, sizeof(ff_up))) { | 569 | if (copy_to_user(p, &ff_up, sizeof(ff_up))) { |
535 | retval = -EFAULT; | 570 | retval = -EFAULT; |
536 | break; | 571 | break; |
@@ -561,12 +596,11 @@ static long uinput_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |||
561 | break; | 596 | break; |
562 | } | 597 | } |
563 | req = uinput_request_find(udev, ff_up.request_id); | 598 | req = uinput_request_find(udev, ff_up.request_id); |
564 | if (!(req && req->code == UI_FF_UPLOAD && req->u.effect)) { | 599 | if (!(req && req->code == UI_FF_UPLOAD && req->u.upload.effect)) { |
565 | retval = -EINVAL; | 600 | retval = -EINVAL; |
566 | break; | 601 | break; |
567 | } | 602 | } |
568 | req->retval = ff_up.retval; | 603 | req->retval = ff_up.retval; |
569 | memcpy(req->u.effect, &ff_up.effect, sizeof(struct ff_effect)); | ||
570 | uinput_request_done(udev, req); | 604 | uinput_request_done(udev, req); |
571 | break; | 605 | break; |
572 | 606 | ||
@@ -622,6 +656,7 @@ static void __exit uinput_exit(void) | |||
622 | MODULE_AUTHOR("Aristeu Sergio Rozanski Filho"); | 656 | MODULE_AUTHOR("Aristeu Sergio Rozanski Filho"); |
623 | MODULE_DESCRIPTION("User level driver support for input subsystem"); | 657 | MODULE_DESCRIPTION("User level driver support for input subsystem"); |
624 | MODULE_LICENSE("GPL"); | 658 | MODULE_LICENSE("GPL"); |
659 | MODULE_VERSION("0.3"); | ||
625 | 660 | ||
626 | module_init(uinput_init); | 661 | module_init(uinput_init); |
627 | module_exit(uinput_exit); | 662 | module_exit(uinput_exit); |
diff --git a/include/linux/uinput.h b/include/linux/uinput.h index 7168302f9844..1fd61eeed664 100644 --- a/include/linux/uinput.h +++ b/include/linux/uinput.h | |||
@@ -22,12 +22,18 @@ | |||
22 | * Author: Aristeu Sergio Rozanski Filho <aris@cathedrallabs.org> | 22 | * Author: Aristeu Sergio Rozanski Filho <aris@cathedrallabs.org> |
23 | * | 23 | * |
24 | * Changes/Revisions: | 24 | * Changes/Revisions: |
25 | * 0.3 24/05/2006 (Anssi Hannula <anssi.hannulagmail.com>) | ||
26 | * - update ff support for the changes in kernel interface | ||
27 | * - add UINPUT_VERSION | ||
25 | * 0.2 16/10/2004 (Micah Dowty <micah@navi.cx>) | 28 | * 0.2 16/10/2004 (Micah Dowty <micah@navi.cx>) |
26 | * - added force feedback support | 29 | * - added force feedback support |
27 | * - added UI_SET_PHYS | 30 | * - added UI_SET_PHYS |
28 | * 0.1 20/06/2002 | 31 | * 0.1 20/06/2002 |
29 | * - first public version | 32 | * - first public version |
30 | */ | 33 | */ |
34 | |||
35 | #define UINPUT_VERSION 3 | ||
36 | |||
31 | #ifdef __KERNEL__ | 37 | #ifdef __KERNEL__ |
32 | #define UINPUT_MINOR 223 | 38 | #define UINPUT_MINOR 223 |
33 | #define UINPUT_NAME "uinput" | 39 | #define UINPUT_NAME "uinput" |
@@ -45,7 +51,10 @@ struct uinput_request { | |||
45 | 51 | ||
46 | union { | 52 | union { |
47 | int effect_id; | 53 | int effect_id; |
48 | struct ff_effect* effect; | 54 | struct { |
55 | struct ff_effect *effect; | ||
56 | struct ff_effect *old; | ||
57 | } upload; | ||
49 | } u; | 58 | } u; |
50 | }; | 59 | }; |
51 | 60 | ||
@@ -58,6 +67,7 @@ struct uinput_device { | |||
58 | unsigned char head; | 67 | unsigned char head; |
59 | unsigned char tail; | 68 | unsigned char tail; |
60 | struct input_event buff[UINPUT_BUFFER_SIZE]; | 69 | struct input_event buff[UINPUT_BUFFER_SIZE]; |
70 | int ff_effects_max; | ||
61 | 71 | ||
62 | struct uinput_request *requests[UINPUT_NUM_REQUESTS]; | 72 | struct uinput_request *requests[UINPUT_NUM_REQUESTS]; |
63 | wait_queue_head_t requests_waitq; | 73 | wait_queue_head_t requests_waitq; |
@@ -69,6 +79,7 @@ struct uinput_ff_upload { | |||
69 | int request_id; | 79 | int request_id; |
70 | int retval; | 80 | int retval; |
71 | struct ff_effect effect; | 81 | struct ff_effect effect; |
82 | struct ff_effect old; | ||
72 | }; | 83 | }; |
73 | 84 | ||
74 | struct uinput_ff_erase { | 85 | struct uinput_ff_erase { |
@@ -98,33 +109,33 @@ struct uinput_ff_erase { | |||
98 | #define UI_BEGIN_FF_ERASE _IOWR(UINPUT_IOCTL_BASE, 202, struct uinput_ff_erase) | 109 | #define UI_BEGIN_FF_ERASE _IOWR(UINPUT_IOCTL_BASE, 202, struct uinput_ff_erase) |
99 | #define UI_END_FF_ERASE _IOW(UINPUT_IOCTL_BASE, 203, struct uinput_ff_erase) | 110 | #define UI_END_FF_ERASE _IOW(UINPUT_IOCTL_BASE, 203, struct uinput_ff_erase) |
100 | 111 | ||
101 | /* To write a force-feedback-capable driver, the upload_effect | 112 | /* |
113 | * To write a force-feedback-capable driver, the upload_effect | ||
102 | * and erase_effect callbacks in input_dev must be implemented. | 114 | * and erase_effect callbacks in input_dev must be implemented. |
103 | * The uinput driver will generate a fake input event when one of | 115 | * The uinput driver will generate a fake input event when one of |
104 | * these callbacks are invoked. The userspace code then uses | 116 | * these callbacks are invoked. The userspace code then uses |
105 | * ioctls to retrieve additional parameters and send the return code. | 117 | * ioctls to retrieve additional parameters and send the return code. |
106 | * The callback blocks until this return code is sent. | 118 | * The callback blocks until this return code is sent. |
107 | * | 119 | * |
108 | * The described callback mechanism is only used if EV_FF is set. | 120 | * The described callback mechanism is only used if ff_effects_max |
109 | * Otherwise, default implementations of upload_effect and erase_effect | 121 | * is set. |
110 | * are used. | ||
111 | * | 122 | * |
112 | * To implement upload_effect(): | 123 | * To implement upload_effect(): |
113 | * 1. Wait for an event with type==EV_UINPUT and code==UI_FF_UPLOAD. | 124 | * 1. Wait for an event with type == EV_UINPUT and code == UI_FF_UPLOAD. |
114 | * A request ID will be given in 'value'. | 125 | * A request ID will be given in 'value'. |
115 | * 2. Allocate a uinput_ff_upload struct, fill in request_id with | 126 | * 2. Allocate a uinput_ff_upload struct, fill in request_id with |
116 | * the 'value' from the EV_UINPUT event. | 127 | * the 'value' from the EV_UINPUT event. |
117 | * 3. Issue a UI_BEGIN_FF_UPLOAD ioctl, giving it the | 128 | * 3. Issue a UI_BEGIN_FF_UPLOAD ioctl, giving it the |
118 | * uinput_ff_upload struct. It will be filled in with the | 129 | * uinput_ff_upload struct. It will be filled in with the |
119 | * ff_effect passed to upload_effect(). | 130 | * ff_effects passed to upload_effect(). |
120 | * 4. Perform the effect upload, and place the modified ff_effect | 131 | * 4. Perform the effect upload, and place a return code back into |
121 | * and a return code back into the uinput_ff_upload struct. | 132 | the uinput_ff_upload struct. |
122 | * 5. Issue a UI_END_FF_UPLOAD ioctl, also giving it the | 133 | * 5. Issue a UI_END_FF_UPLOAD ioctl, also giving it the |
123 | * uinput_ff_upload_effect struct. This will complete execution | 134 | * uinput_ff_upload_effect struct. This will complete execution |
124 | * of our upload_effect() handler. | 135 | * of our upload_effect() handler. |
125 | * | 136 | * |
126 | * To implement erase_effect(): | 137 | * To implement erase_effect(): |
127 | * 1. Wait for an event with type==EV_UINPUT and code==UI_FF_ERASE. | 138 | * 1. Wait for an event with type == EV_UINPUT and code == UI_FF_ERASE. |
128 | * A request ID will be given in 'value'. | 139 | * A request ID will be given in 'value'. |
129 | * 2. Allocate a uinput_ff_erase struct, fill in request_id with | 140 | * 2. Allocate a uinput_ff_erase struct, fill in request_id with |
130 | * the 'value' from the EV_UINPUT event. | 141 | * the 'value' from the EV_UINPUT event. |
@@ -133,13 +144,13 @@ struct uinput_ff_erase { | |||
133 | * effect ID passed to erase_effect(). | 144 | * effect ID passed to erase_effect(). |
134 | * 4. Perform the effect erasure, and place a return code back | 145 | * 4. Perform the effect erasure, and place a return code back |
135 | * into the uinput_ff_erase struct. | 146 | * into the uinput_ff_erase struct. |
136 | * and a return code back into the uinput_ff_erase struct. | ||
137 | * 5. Issue a UI_END_FF_ERASE ioctl, also giving it the | 147 | * 5. Issue a UI_END_FF_ERASE ioctl, also giving it the |
138 | * uinput_ff_erase_effect struct. This will complete execution | 148 | * uinput_ff_erase_effect struct. This will complete execution |
139 | * of our erase_effect() handler. | 149 | * of our erase_effect() handler. |
140 | */ | 150 | */ |
141 | 151 | ||
142 | /* This is the new event type, used only by uinput. | 152 | /* |
153 | * This is the new event type, used only by uinput. | ||
143 | * 'code' is UI_FF_UPLOAD or UI_FF_ERASE, and 'value' | 154 | * 'code' is UI_FF_UPLOAD or UI_FF_ERASE, and 'value' |
144 | * is the unique request ID. This number was picked | 155 | * is the unique request ID. This number was picked |
145 | * arbitrarily, above EV_MAX (since the input system | 156 | * arbitrarily, above EV_MAX (since the input system |