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/usb.h>
20 MODULE_AUTHOR("Stephane Chatty <chatty@enac.fr>");
21 MODULE_DESCRIPTION("3M PCT multitouch panels");
22 MODULE_LICENSE("GPL");
33 struct mmm_finger f
[10];
38 static int mmm_input_mapping(struct hid_device
*hdev
, struct hid_input
*hi
,
39 struct hid_field
*field
, struct hid_usage
*usage
,
40 unsigned long **bit
, int *max
)
42 switch (usage
->hid
& HID_USAGE_PAGE
) {
50 hid_map_usage(hi
, usage
, bit
, max
,
51 EV_ABS
, ABS_MT_POSITION_X
);
52 /* touchscreen emulation */
53 input_set_abs_params(hi
->input
, ABS_X
,
54 field
->logical_minimum
,
55 field
->logical_maximum
, 0, 0);
58 hid_map_usage(hi
, usage
, bit
, max
,
59 EV_ABS
, ABS_MT_POSITION_Y
);
60 /* touchscreen emulation */
61 input_set_abs_params(hi
->input
, ABS_Y
,
62 field
->logical_minimum
,
63 field
->logical_maximum
, 0, 0);
68 case HID_UP_DIGITIZER
:
70 /* we do not want to map these: no input-oriented meaning */
73 case HID_DG_INPUTMODE
:
74 case HID_DG_DEVICEINDEX
:
75 case HID_DG_CONTACTCOUNT
:
76 case HID_DG_CONTACTMAX
:
78 case HID_DG_CONFIDENCE
:
80 case HID_DG_TIPSWITCH
:
81 /* touchscreen emulation */
82 hid_map_usage(hi
, usage
, bit
, max
, EV_KEY
, BTN_TOUCH
);
85 hid_map_usage(hi
, usage
, bit
, max
,
86 EV_ABS
, ABS_MT_TOUCH_MAJOR
);
89 hid_map_usage(hi
, usage
, bit
, max
,
90 EV_ABS
, ABS_MT_TOUCH_MINOR
);
91 input_set_abs_params(hi
->input
, ABS_MT_ORIENTATION
,
94 case HID_DG_CONTACTID
:
95 field
->logical_maximum
= 59;
96 hid_map_usage(hi
, usage
, bit
, max
,
97 EV_ABS
, ABS_MT_TRACKING_ID
);
100 /* let hid-input decide for the others */
104 /* we do not want to map these: no input-oriented meaning */
111 static int mmm_input_mapped(struct hid_device
*hdev
, struct hid_input
*hi
,
112 struct hid_field
*field
, struct hid_usage
*usage
,
113 unsigned long **bit
, int *max
)
115 if (usage
->type
== EV_KEY
|| usage
->type
== EV_ABS
)
116 clear_bit(usage
->code
, *bit
);
122 * this function is called when a whole packet has been received and processed,
123 * so that it can decide what to send to the input layer.
125 static void mmm_filter_event(struct mmm_data
*md
, struct input_dev
*input
)
127 struct mmm_finger
*oldest
= 0;
128 bool pressed
= false, released
= false;
132 * we need to iterate on all fingers to decide if we have a press
133 * or a release event in our touchscreen emulation.
135 for (i
= 0; i
< 10; ++i
) {
136 struct mmm_finger
*f
= &md
->f
[i
];
138 /* this finger is just placeholder data, ignore */
139 } else if (f
->touch
) {
140 /* this finger is on the screen */
141 int wide
= (f
->w
> f
->h
);
142 input_event(input
, EV_ABS
, ABS_MT_TRACKING_ID
, i
);
143 input_event(input
, EV_ABS
, ABS_MT_POSITION_X
, f
->x
);
144 input_event(input
, EV_ABS
, ABS_MT_POSITION_Y
, f
->y
);
145 input_event(input
, EV_ABS
, ABS_MT_ORIENTATION
, wide
);
146 input_event(input
, EV_ABS
, ABS_MT_TOUCH_MAJOR
,
148 input_event(input
, EV_ABS
, ABS_MT_TOUCH_MINOR
,
150 input_mt_sync(input
);
152 * touchscreen emulation: maintain the age rank
153 * of this finger, decide if we have a press
156 f
->rank
= ++(md
->num
);
163 /* this finger took off the screen */
164 /* touchscreen emulation: maintain age rank of others */
167 for (j
= 0; j
< 10; ++j
) {
168 struct mmm_finger
*g
= &md
->f
[j
];
169 if (g
->rank
> f
->rank
) {
183 /* touchscreen emulation */
186 input_event(input
, EV_KEY
, BTN_TOUCH
, 1);
187 input_event(input
, EV_ABS
, ABS_X
, oldest
->x
);
188 input_event(input
, EV_ABS
, ABS_Y
, oldest
->y
);
189 } else if (released
) {
190 input_event(input
, EV_KEY
, BTN_TOUCH
, 0);
195 * this function is called upon all reports
196 * so that we can accumulate contact point information,
197 * and call input_mt_sync after each point.
199 static int mmm_event(struct hid_device
*hid
, struct hid_field
*field
,
200 struct hid_usage
*usage
, __s32 value
)
202 struct mmm_data
*md
= hid_get_drvdata(hid
);
204 * strangely, this function can be called before
205 * field->hidinput is initialized!
207 if (hid
->claimed
& HID_CLAIMED_INPUT
) {
208 struct input_dev
*input
= field
->hidinput
->input
;
209 switch (usage
->hid
) {
210 case HID_DG_TIPSWITCH
:
213 case HID_DG_CONFIDENCE
:
218 md
->f
[md
->curid
].w
= value
;
222 md
->f
[md
->curid
].h
= value
;
224 case HID_DG_CONTACTID
:
227 md
->f
[value
].touch
= md
->touch
;
228 md
->f
[value
].valid
= 1;
233 md
->f
[md
->curid
].x
= value
;
237 md
->f
[md
->curid
].y
= value
;
239 case HID_DG_CONTACTCOUNT
:
240 mmm_filter_event(md
, input
);
245 /* we have handled the hidinput part, now remains hiddev */
246 if (hid
->claimed
& HID_CLAIMED_HIDDEV
&& hid
->hiddev_hid_event
)
247 hid
->hiddev_hid_event(hid
, field
, usage
, value
);
252 static int mmm_probe(struct hid_device
*hdev
, const struct hid_device_id
*id
)
257 md
= kzalloc(sizeof(struct mmm_data
), GFP_KERNEL
);
259 dev_err(&hdev
->dev
, "cannot allocate 3M data\n");
262 hid_set_drvdata(hdev
, md
);
264 ret
= hid_parse(hdev
);
266 ret
= hid_hw_start(hdev
, HID_CONNECT_DEFAULT
);
273 static void mmm_remove(struct hid_device
*hdev
)
276 kfree(hid_get_drvdata(hdev
));
277 hid_set_drvdata(hdev
, NULL
);
280 static const struct hid_device_id mmm_devices
[] = {
281 { HID_USB_DEVICE(USB_VENDOR_ID_3M
, USB_DEVICE_ID_3M1968
) },
282 { HID_USB_DEVICE(USB_VENDOR_ID_3M
, USB_DEVICE_ID_3M2256
) },
285 MODULE_DEVICE_TABLE(hid
, mmm_devices
);
287 static const struct hid_usage_id mmm_grabbed_usages
[] = {
288 { HID_ANY_ID
, HID_ANY_ID
, HID_ANY_ID
},
289 { HID_ANY_ID
- 1, HID_ANY_ID
- 1, HID_ANY_ID
- 1}
292 static struct hid_driver mmm_driver
= {
294 .id_table
= mmm_devices
,
296 .remove
= mmm_remove
,
297 .input_mapping
= mmm_input_mapping
,
298 .input_mapped
= mmm_input_mapped
,
299 .usage_table
= mmm_grabbed_usages
,
303 static int __init
mmm_init(void)
305 return hid_register_driver(&mmm_driver
);
308 static void __exit
mmm_exit(void)
310 hid_unregister_driver(&mmm_driver
);
313 module_init(mmm_init
);
314 module_exit(mmm_exit
);