2 * HID driver for 3M PCT multitouch panels
4 * Copyright (c) 2009 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
);
85 case HID_DG_CONTACTID
:
86 hid_map_usage(hi
, usage
, bit
, max
,
87 EV_ABS
, ABS_MT_TRACKING_ID
);
90 /* let hid-input decide for the others */
94 /* we do not want to map these: no input-oriented meaning */
101 static 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
)
105 if (usage
->type
== EV_KEY
|| usage
->type
== EV_ABS
)
106 clear_bit(usage
->code
, *bit
);
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.
115 static void mmm_filter_event(struct mmm_data
*md
, struct input_dev
*input
)
117 struct mmm_finger
*oldest
= 0;
118 bool pressed
= false, released
= false;
122 * we need to iterate on all fingers to decide if we have a press
123 * or a release event in our touchscreen emulation.
125 for (i
= 0; i
< 10; ++i
) {
126 struct mmm_finger
*f
= &md
->f
[i
];
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
);
136 * touchscreen emulation: maintain the age rank
137 * of this finger, decide if we have a press
140 f
->rank
= ++(md
->num
);
147 /* this finger took off the screen */
148 /* touchscreen emulation: maintain age rank of others */
151 for (j
= 0; j
< 10; ++j
) {
152 struct mmm_finger
*g
= &md
->f
[j
];
153 if (g
->rank
> f
->rank
) {
167 /* touchscreen emulation */
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);
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.
183 static int mmm_event(struct hid_device
*hid
, struct hid_field
*field
,
184 struct hid_usage
*usage
, __s32 value
)
186 struct mmm_data
*md
= hid_get_drvdata(hid
);
188 * strangely, this function can be called before
189 * field->hidinput is initialized!
191 if (hid
->claimed
& HID_CLAIMED_INPUT
) {
192 struct input_dev
*input
= field
->hidinput
->input
;
193 switch (usage
->hid
) {
194 case HID_DG_TIPSWITCH
:
197 case HID_DG_CONFIDENCE
:
200 case HID_DG_CONTACTID
:
203 md
->f
[value
].touch
= md
->touch
;
204 md
->f
[value
].valid
= 1;
209 md
->f
[md
->curid
].x
= value
;
213 md
->f
[md
->curid
].y
= value
;
215 case HID_DG_CONTACTCOUNT
:
216 mmm_filter_event(md
, input
);
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
);
228 static int mmm_probe(struct hid_device
*hdev
, const struct hid_device_id
*id
)
233 md
= kzalloc(sizeof(struct mmm_data
), GFP_KERNEL
);
235 dev_err(&hdev
->dev
, "cannot allocate 3M data\n");
238 hid_set_drvdata(hdev
, md
);
240 ret
= hid_parse(hdev
);
242 ret
= hid_hw_start(hdev
, HID_CONNECT_DEFAULT
);
249 static void mmm_remove(struct hid_device
*hdev
)
252 kfree(hid_get_drvdata(hdev
));
253 hid_set_drvdata(hdev
, NULL
);
256 static const struct hid_device_id mmm_devices
[] = {
257 { HID_USB_DEVICE(USB_VENDOR_ID_3M
, USB_DEVICE_ID_3M1968
) },
260 MODULE_DEVICE_TABLE(hid
, mmm_devices
);
262 static 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}
267 static struct hid_driver mmm_driver
= {
269 .id_table
= mmm_devices
,
271 .remove
= mmm_remove
,
272 .input_mapping
= mmm_input_mapping
,
273 .input_mapped
= mmm_input_mapped
,
274 .usage_table
= mmm_grabbed_usages
,
278 static int __init
mmm_init(void)
280 return hid_register_driver(&mmm_driver
);
283 static void __exit
mmm_exit(void)
285 hid_unregister_driver(&mmm_driver
);
288 module_init(mmm_init
);
289 module_exit(mmm_exit
);
290 MODULE_LICENSE("GPL");