aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorStephane Chatty <chatty@lii-enac.fr>2009-12-22 17:04:17 -0500
committerJiri Kosina <jkosina@suse.cz>2009-12-22 19:28:37 -0500
commitb6353f4f36f03a12edaf3fa5365b475a28106035 (patch)
treeddc9805f66cc095edb1b4614c774b5af13bb457c /drivers
parent3067e02f8f3ae2f3f02ba76400d03b8bcb4942b0 (diff)
HID: Support for 3M multitouch panel
Add support for 3M multitouch panels. Signed-off-by: Stephane Chatty <chatty@enac.fr> [jkosina@suse.cz: fix build failure because of inconsistent 3M/MMM defines] Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/hid/Kconfig7
-rw-r--r--drivers/hid/Makefile1
-rw-r--r--drivers/hid/hid-3m-pct.c291
-rw-r--r--drivers/hid/hid-core.c1
-rw-r--r--drivers/hid/hid-ids.h3
5 files changed, 303 insertions, 0 deletions
diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
index 24d90ea246ce..a05133f645bc 100644
--- a/drivers/hid/Kconfig
+++ b/drivers/hid/Kconfig
@@ -55,6 +55,13 @@ source "drivers/hid/usbhid/Kconfig"
55menu "Special HID drivers" 55menu "Special HID drivers"
56 depends on HID 56 depends on HID
57 57
58config HID_3M_PCT
59 tristate "3M PCT" if EMBEDDED
60 depends on USB_HID
61 default !EMBEDDED
62 ---help---
63 Support for 3M PCT touch screens.
64
58config HID_A4TECH 65config HID_A4TECH
59 tristate "A4 tech" if EMBEDDED 66 tristate "A4 tech" if EMBEDDED
60 depends on USB_HID 67 depends on USB_HID
diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile
index 0de2dff5542c..1bdfb97910f1 100644
--- a/drivers/hid/Makefile
+++ b/drivers/hid/Makefile
@@ -19,6 +19,7 @@ ifdef CONFIG_LOGIRUMBLEPAD2_FF
19 hid-logitech-objs += hid-lg2ff.o 19 hid-logitech-objs += hid-lg2ff.o
20endif 20endif
21 21
22obj-$(CONFIG_HID_3M_PCT) += hid-3m-pct.o
22obj-$(CONFIG_HID_A4TECH) += hid-a4tech.o 23obj-$(CONFIG_HID_A4TECH) += hid-a4tech.o
23obj-$(CONFIG_HID_APPLE) += hid-apple.o 24obj-$(CONFIG_HID_APPLE) += hid-apple.o
24obj-$(CONFIG_HID_BELKIN) += hid-belkin.o 25obj-$(CONFIG_HID_BELKIN) += hid-belkin.o
diff --git a/drivers/hid/hid-3m-pct.c b/drivers/hid/hid-3m-pct.c
new file mode 100644
index 000000000000..6d11e3dbbbff
--- /dev/null
+++ b/drivers/hid/hid-3m-pct.c
@@ -0,0 +1,291 @@
1/*
2 * HID driver for 3M PCT multitouch panels
3 *
4 * Copyright (c) 2009 Stephane Chatty <chatty@enac.fr>
5 *
6 */
7
8/*
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the Free
11 * Software Foundation; either version 2 of the License, or (at your option)
12 * any later version.
13 */
14
15#include <linux/device.h>
16#include <linux/hid.h>
17#include <linux/module.h>
18#include <linux/usb.h>
19
20MODULE_VERSION("0.6");
21MODULE_AUTHOR("Stephane Chatty <chatty@enac.fr>");
22MODULE_DESCRIPTION("3M PCT multitouch panels");
23MODULE_LICENSE("GPL");
24
25#include "hid-ids.h"
26
27struct mmm_finger {
28 __s32 x, y;
29 __u8 rank;
30 bool touch, valid;
31};
32
33struct mmm_data {
34 struct mmm_finger f[10];
35 __u8 curid, num;
36 bool touch, valid;
37};
38
39static int mmm_input_mapping(struct hid_device *hdev, struct hid_input *hi,
40 struct hid_field *field, struct hid_usage *usage,
41 unsigned long **bit, int *max)
42{
43 switch (usage->hid & HID_USAGE_PAGE) {
44
45 case HID_UP_BUTTON:
46 return -1;
47
48 case HID_UP_GENDESK:
49 switch (usage->hid) {
50 case HID_GD_X:
51 hid_map_usage(hi, usage, bit, max,
52 EV_ABS, ABS_MT_POSITION_X);
53 /* touchscreen emulation */
54 input_set_abs_params(hi->input, ABS_X,
55 field->logical_minimum,
56 field->logical_maximum, 0, 0);
57 return 1;
58 case HID_GD_Y:
59 hid_map_usage(hi, usage, bit, max,
60 EV_ABS, ABS_MT_POSITION_Y);
61 /* touchscreen emulation */
62 input_set_abs_params(hi->input, ABS_Y,
63 field->logical_minimum,
64 field->logical_maximum, 0, 0);
65 return 1;
66 }
67 return 0;
68
69 case HID_UP_DIGITIZER:
70 switch (usage->hid) {
71 /* we do not want to map these: no input-oriented meaning */
72 case 0x14:
73 case 0x23:
74 case HID_DG_INPUTMODE:
75 case HID_DG_DEVICEINDEX:
76 case HID_DG_CONTACTCOUNT:
77 case HID_DG_CONTACTMAX:
78 case HID_DG_INRANGE:
79 case HID_DG_CONFIDENCE:
80 return -1;
81 case HID_DG_TIPSWITCH:
82 /* touchscreen emulation */
83 hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_TOUCH);
84 return 1;
85 case HID_DG_CONTACTID:
86 hid_map_usage(hi, usage, bit, max,
87 EV_ABS, ABS_MT_TRACKING_ID);
88 return 1;
89 }
90 /* let hid-input decide for the others */
91 return 0;
92
93 case 0xff000000:
94 /* we do not want to map these: no input-oriented meaning */
95 return -1;
96 }
97
98 return 0;
99}
100
101static int mmm_input_mapped(struct hid_device *hdev, struct hid_input *hi,
102 struct hid_field *field, struct hid_usage *usage,
103 unsigned long **bit, int *max)
104{
105 if (usage->type == EV_KEY || usage->type == EV_ABS)
106 clear_bit(usage->code, *bit);
107
108 return 0;
109}
110
111/*
112 * this function is called when a whole packet has been received and processed,
113 * so that it can decide what to send to the input layer.
114 */
115static void mmm_filter_event(struct mmm_data *md, struct input_dev *input)
116{
117 struct mmm_finger *oldest = 0;
118 bool pressed = false, released = false;
119 int i;
120
121 /*
122 * we need to iterate on all fingers to decide if we have a press
123 * or a release event in our touchscreen emulation.
124 */
125 for (i = 0; i < 10; ++i) {
126 struct mmm_finger *f = &md->f[i];
127 if (!f->valid) {
128 /* this finger is just placeholder data, ignore */
129 } else if (f->touch) {
130 /* this finger is on the screen */
131 input_event(input, EV_ABS, ABS_MT_TRACKING_ID, i);
132 input_event(input, EV_ABS, ABS_MT_POSITION_X, f->x);
133 input_event(input, EV_ABS, ABS_MT_POSITION_Y, f->y);
134 input_mt_sync(input);
135 /*
136 * touchscreen emulation: maintain the age rank
137 * of this finger, decide if we have a press
138 */
139 if (f->rank == 0) {
140 f->rank = ++(md->num);
141 if (f->rank == 1)
142 pressed = true;
143 }
144 if (f->rank == 1)
145 oldest = f;
146 } else {
147 /* this finger took off the screen */
148 /* touchscreen emulation: maintain age rank of others */
149 int j;
150
151 for (j = 0; j < 10; ++j) {
152 struct mmm_finger *g = &md->f[j];
153 if (g->rank > f->rank) {
154 g->rank--;
155 if (g->rank == 1)
156 oldest = g;
157 }
158 }
159 f->rank = 0;
160 --(md->num);
161 if (md->num == 0)
162 released = true;
163 }
164 f->valid = 0;
165 }
166
167 /* touchscreen emulation */
168 if (oldest) {
169 if (pressed)
170 input_event(input, EV_KEY, BTN_TOUCH, 1);
171 input_event(input, EV_ABS, ABS_X, oldest->x);
172 input_event(input, EV_ABS, ABS_Y, oldest->y);
173 } else if (released) {
174 input_event(input, EV_KEY, BTN_TOUCH, 0);
175 }
176}
177
178/*
179 * this function is called upon all reports
180 * so that we can accumulate contact point information,
181 * and call input_mt_sync after each point.
182 */
183static int mmm_event(struct hid_device *hid, struct hid_field *field,
184 struct hid_usage *usage, __s32 value)
185{
186 struct mmm_data *md = hid_get_drvdata(hid);
187 /*
188 * strangely, this function can be called before
189 * field->hidinput is initialized!
190 */
191 if (hid->claimed & HID_CLAIMED_INPUT) {
192 struct input_dev *input = field->hidinput->input;
193 switch (usage->hid) {
194 case HID_DG_TIPSWITCH:
195 md->touch = value;
196 break;
197 case HID_DG_CONFIDENCE:
198 md->valid = value;
199 break;
200 case HID_DG_CONTACTID:
201 if (md->valid) {
202 md->curid = value;
203 md->f[value].touch = md->touch;
204 md->f[value].valid = 1;
205 }
206 break;
207 case HID_GD_X:
208 if (md->valid)
209 md->f[md->curid].x = value;
210 break;
211 case HID_GD_Y:
212 if (md->valid)
213 md->f[md->curid].y = value;
214 break;
215 case HID_DG_CONTACTCOUNT:
216 mmm_filter_event(md, input);
217 break;
218 }
219 }
220
221 /* we have handled the hidinput part, now remains hiddev */
222 if (hid->claimed & HID_CLAIMED_HIDDEV && hid->hiddev_hid_event)
223 hid->hiddev_hid_event(hid, field, usage, value);
224
225 return 1;
226}
227
228static int mmm_probe(struct hid_device *hdev, const struct hid_device_id *id)
229{
230 int ret;
231 struct mmm_data *md;
232
233 md = kzalloc(sizeof(struct mmm_data), GFP_KERNEL);
234 if (!md) {
235 dev_err(&hdev->dev, "cannot allocate 3M data\n");
236 return -ENOMEM;
237 }
238 hid_set_drvdata(hdev, md);
239
240 ret = hid_parse(hdev);
241 if (!ret)
242 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
243
244 if (ret)
245 kfree(md);
246 return ret;
247}
248
249static void mmm_remove(struct hid_device *hdev)
250{
251 hid_hw_stop(hdev);
252 kfree(hid_get_drvdata(hdev));
253 hid_set_drvdata(hdev, NULL);
254}
255
256static const struct hid_device_id mmm_devices[] = {
257 { HID_USB_DEVICE(USB_VENDOR_ID_3M, USB_DEVICE_ID_3M1968) },
258 { }
259};
260MODULE_DEVICE_TABLE(hid, mmm_devices);
261
262static const struct hid_usage_id mmm_grabbed_usages[] = {
263 { HID_ANY_ID, HID_ANY_ID, HID_ANY_ID },
264 { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1}
265};
266
267static struct hid_driver mmm_driver = {
268 .name = "3m-pct",
269 .id_table = mmm_devices,
270 .probe = mmm_probe,
271 .remove = mmm_remove,
272 .input_mapping = mmm_input_mapping,
273 .input_mapped = mmm_input_mapped,
274 .usage_table = mmm_grabbed_usages,
275 .event = mmm_event,
276};
277
278static int __init mmm_init(void)
279{
280 return hid_register_driver(&mmm_driver);
281}
282
283static void __exit mmm_exit(void)
284{
285 hid_unregister_driver(&mmm_driver);
286}
287
288module_init(mmm_init);
289module_exit(mmm_exit);
290MODULE_LICENSE("GPL");
291
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 80792d38d25c..70c25a056205 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -1248,6 +1248,7 @@ EXPORT_SYMBOL_GPL(hid_disconnect);
1248 1248
1249/* a list of devices for which there is a specialized driver on HID bus */ 1249/* a list of devices for which there is a specialized driver on HID bus */
1250static const struct hid_device_id hid_blacklist[] = { 1250static const struct hid_device_id hid_blacklist[] = {
1251 { HID_USB_DEVICE(USB_VENDOR_ID_3M, USB_DEVICE_ID_3M1968) },
1251 { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU) }, 1252 { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU) },
1252 { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_X5_005D) }, 1253 { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_X5_005D) },
1253 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ATV_IRCONTROL) }, 1254 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ATV_IRCONTROL) },
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 3839340e293a..3d55f983dbaf 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -18,6 +18,9 @@
18#ifndef HID_IDS_H_FILE 18#ifndef HID_IDS_H_FILE
19#define HID_IDS_H_FILE 19#define HID_IDS_H_FILE
20 20
21#define USB_VENDOR_ID_3M 0x0596
22#define USB_DEVICE_ID_3M1968 0x0500
23
21#define USB_VENDOR_ID_A4TECH 0x09da 24#define USB_VENDOR_ID_A4TECH 0x09da
22#define USB_DEVICE_ID_A4TECH_WCP32PU 0x0006 25#define USB_DEVICE_ID_A4TECH_WCP32PU 0x0006
23#define USB_DEVICE_ID_A4TECH_X5_005D 0x000a 26#define USB_DEVICE_ID_A4TECH_X5_005D 0x000a