2 * HID driver for 3M PCT multitouch panels
4 * Copyright (c) 2009-2010 Stephane Chatty <chatty@enac.fr>
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)
15 #include <linux/device.h>
16 #include <linux/hid.h>
17 #include <linux/module.h>
18 #include <linux/slab.h>
19 #include <linux/usb.h>
21 MODULE_AUTHOR("Stephane Chatty <chatty@enac.fr>");
22 MODULE_DESCRIPTION("3M PCT multitouch panels");
23 MODULE_LICENSE("GPL");
34 struct mmm_finger f
[10];
39 static 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
)
43 switch (usage
->hid
& HID_USAGE_PAGE
) {
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);
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);
69 case HID_UP_DIGITIZER
:
71 /* we do not want to map these: no input-oriented meaning */
74 case HID_DG_INPUTMODE
:
75 case HID_DG_DEVICEINDEX
:
76 case HID_DG_CONTACTCOUNT
:
77 case HID_DG_CONTACTMAX
:
79 case HID_DG_CONFIDENCE
:
81 case HID_DG_TIPSWITCH
:
82 /* touchscreen emulation */
83 hid_map_usage(hi
, usage
, bit
, max
, EV_KEY
, BTN_TOUCH
);
86 hid_map_usage(hi
, usage
, bit
, max
,
87 EV_ABS
, ABS_MT_TOUCH_MAJOR
);
90 hid_map_usage(hi
, usage
, bit
, max
,
91 EV_ABS
, ABS_MT_TOUCH_MINOR
);
92 input_set_abs_params(hi
->input
, ABS_MT_ORIENTATION
,
95 case HID_DG_CONTACTID
:
96 field
->logical_maximum
= 59;
97 hid_map_usage(hi
, usage
, bit
, max
,
98 EV_ABS
, ABS_MT_TRACKING_ID
);
101 /* let hid-input decide for the others */
105 /* we do not want to map these: no input-oriented meaning */
112 static int mmm_input_mapped(struct hid_device
*hdev
, struct hid_input
*hi
,
113 struct hid_field
*field
, struct hid_usage
*usage
,
114 unsigned long **bit
, int *max
)
116 if (usage
->type
== EV_KEY
|| usage
->type
== EV_ABS
)
117 clear_bit(usage
->code
, *bit
);
123 * this function is called when a whole packet has been received and processed,
124 * so that it can decide what to send to the input layer.
126 static void mmm_filter_event(struct mmm_data
*md
, struct input_dev
*input
)
128 struct mmm_finger
*oldest
= 0;
129 bool pressed
= false, released
= false;
133 * we need to iterate on all fingers to decide if we have a press
134 * or a release event in our touchscreen emulation.
136 for (i
= 0; i
< 10; ++i
) {
137 struct mmm_finger
*f
= &md
->f
[i
];
139 /* this finger is just placeholder data, ignore */
140 } else if (f
->touch
) {
141 /* this finger is on the screen */
142 int wide
= (f
->w
> f
->h
);
143 input_event(input
, EV_ABS
, ABS_MT_TRACKING_ID
, i
);
144 input_event(input
, EV_ABS
, ABS_MT_POSITION_X
, f
->x
);
145 input_event(input
, EV_ABS
, ABS_MT_POSITION_Y
, f
->y
);
146 input_event(input
, EV_ABS
, ABS_MT_ORIENTATION
, wide
);
147 input_event(input
, EV_ABS
, ABS_MT_TOUCH_MAJOR
,
149 input_event(input
, EV_ABS
, ABS_MT_TOUCH_MINOR
,
151 input_mt_sync(input
);
153 * touchscreen emulation: maintain the age rank
154 * of this finger, decide if we have a press
157 f
->rank
= ++(md
->num
);
164 /* this finger took off the screen */
165 /* touchscreen emulation: maintain age rank of others */
168 for (j
= 0; j
< 10; ++j
) {
169 struct mmm_finger
*g
= &md
->f
[j
];
170 if (g
->rank
> f
->rank
) {
184 /* touchscreen emulation */
187 input_event(input
, EV_KEY
, BTN_TOUCH
, 1);
188 input_event(input
, EV_ABS
, ABS_X
, oldest
->x
);
189 input_event(input
, EV_ABS
, ABS_Y
, oldest
->y
);
190 } else if (released
) {
191 input_event(input
, EV_KEY
, BTN_TOUCH
, 0);
196 * this function is called upon all reports
197 * so that we can accumulate contact point information,
198 * and call input_mt_sync after each point.
200 static int mmm_event(struct hid_device
*hid
, struct hid_field
*field
,
201 struct hid_usage
*usage
, __s32 value
)
203 struct mmm_data
*md
= hid_get_drvdata(hid
);
205 * strangely, this function can be called before
206 * field->hidinput is initialized!
208 if (hid
->claimed
& HID_CLAIMED_INPUT
) {
209 struct input_dev
*input
= field
->hidinput
->input
;
210 switch (usage
->hid
) {
211 case HID_DG_TIPSWITCH
:
214 case HID_DG_CONFIDENCE
:
219 md
->f
[md
->curid
].w
= value
;
223 md
->f
[md
->curid
].h
= value
;
225 case HID_DG_CONTACTID
:
228 md
->f
[value
].touch
= md
->touch
;
229 md
->f
[value
].valid
= 1;
234 md
->f
[md
->curid
].x
= value
;
238 md
->f
[md
->curid
].y
= value
;
240 case HID_DG_CONTACTCOUNT
:
241 mmm_filter_event(md
, input
);
246 /* we have handled the hidinput part, now remains hiddev */
247 if (hid
->claimed
& HID_CLAIMED_HIDDEV
&& hid
->hiddev_hid_event
)
248 hid
->hiddev_hid_event(hid
, field
, usage
, value
);
253 static int mmm_probe(struct hid_device
*hdev
, const struct hid_device_id
*id
)
258 md
= kzalloc(sizeof(struct mmm_data
), GFP_KERNEL
);
260 dev_err(&hdev
->dev
, "cannot allocate 3M data\n");
263 hid_set_drvdata(hdev
, md
);
265 ret
= hid_parse(hdev
);
267 ret
= hid_hw_start(hdev
, HID_CONNECT_DEFAULT
);
274 static void mmm_remove(struct hid_device
*hdev
)
277 kfree(hid_get_drvdata(hdev
));
278 hid_set_drvdata(hdev
, NULL
);
281 static const struct hid_device_id mmm_devices
[] = {
282 { HID_USB_DEVICE(USB_VENDOR_ID_3M
, USB_DEVICE_ID_3M1968
) },
283 { HID_USB_DEVICE(USB_VENDOR_ID_3M
, USB_DEVICE_ID_3M2256
) },
286 MODULE_DEVICE_TABLE(hid
, mmm_devices
);
288 static const struct hid_usage_id mmm_grabbed_usages
[] = {
289 { HID_ANY_ID
, HID_ANY_ID
, HID_ANY_ID
},
290 { HID_ANY_ID
- 1, HID_ANY_ID
- 1, HID_ANY_ID
- 1}
293 static struct hid_driver mmm_driver
= {
295 .id_table
= mmm_devices
,
297 .remove
= mmm_remove
,
298 .input_mapping
= mmm_input_mapping
,
299 .input_mapped
= mmm_input_mapped
,
300 .usage_table
= mmm_grabbed_usages
,
304 static int __init
mmm_init(void)
306 return hid_register_driver(&mmm_driver
);
309 static void __exit
mmm_exit(void)
311 hid_unregister_driver(&mmm_driver
);
314 module_init(mmm_init
);
315 module_exit(mmm_exit
);