IPVS: fix netns if reading ip_vs_* procfs entries
[linux-2.6/linux-mips.git] / drivers / hid / hid-stantum.c
blobb2be1d11916b79aa5f600dedd06fdfe917041707
1 /*
2 * HID driver for Stantum multitouch panels
4 * Copyright (c) 2009 Stephane Chatty <chatty@enac.fr>
6 */
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.
15 #include <linux/device.h>
16 #include <linux/hid.h>
17 #include <linux/module.h>
18 #include <linux/slab.h>
20 MODULE_AUTHOR("Stephane Chatty <chatty@enac.fr>");
21 MODULE_DESCRIPTION("Stantum HID multitouch panels");
22 MODULE_LICENSE("GPL");
24 #include "hid-ids.h"
26 struct stantum_data {
27 __s32 x, y, z, w, h; /* x, y, pressure, width, height */
28 __u16 id; /* touch id */
29 bool valid; /* valid finger data, or just placeholder? */
30 bool first; /* first finger in the HID packet? */
31 bool activity; /* at least one active finger so far? */
34 static int stantum_input_mapping(struct hid_device *hdev, struct hid_input *hi,
35 struct hid_field *field, struct hid_usage *usage,
36 unsigned long **bit, int *max)
38 switch (usage->hid & HID_USAGE_PAGE) {
40 case HID_UP_GENDESK:
41 switch (usage->hid) {
42 case HID_GD_X:
43 hid_map_usage(hi, usage, bit, max,
44 EV_ABS, ABS_MT_POSITION_X);
45 /* touchscreen emulation */
46 input_set_abs_params(hi->input, ABS_X,
47 field->logical_minimum,
48 field->logical_maximum, 0, 0);
49 return 1;
50 case HID_GD_Y:
51 hid_map_usage(hi, usage, bit, max,
52 EV_ABS, ABS_MT_POSITION_Y);
53 /* touchscreen emulation */
54 input_set_abs_params(hi->input, ABS_Y,
55 field->logical_minimum,
56 field->logical_maximum, 0, 0);
57 return 1;
59 return 0;
61 case HID_UP_DIGITIZER:
62 switch (usage->hid) {
63 case HID_DG_INRANGE:
64 case HID_DG_CONFIDENCE:
65 case HID_DG_INPUTMODE:
66 case HID_DG_DEVICEINDEX:
67 case HID_DG_CONTACTCOUNT:
68 case HID_DG_CONTACTMAX:
69 return -1;
71 case HID_DG_TIPSWITCH:
72 /* touchscreen emulation */
73 hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_TOUCH);
74 return 1;
76 case HID_DG_WIDTH:
77 hid_map_usage(hi, usage, bit, max,
78 EV_ABS, ABS_MT_TOUCH_MAJOR);
79 return 1;
80 case HID_DG_HEIGHT:
81 hid_map_usage(hi, usage, bit, max,
82 EV_ABS, ABS_MT_TOUCH_MINOR);
83 input_set_abs_params(hi->input, ABS_MT_ORIENTATION,
84 1, 1, 0, 0);
85 return 1;
86 case HID_DG_TIPPRESSURE:
87 hid_map_usage(hi, usage, bit, max,
88 EV_ABS, ABS_MT_PRESSURE);
89 return 1;
91 case HID_DG_CONTACTID:
92 hid_map_usage(hi, usage, bit, max,
93 EV_ABS, ABS_MT_TRACKING_ID);
94 return 1;
97 return 0;
99 case 0xff000000:
100 /* no input-oriented meaning */
101 return -1;
104 return 0;
107 static int stantum_input_mapped(struct hid_device *hdev, struct hid_input *hi,
108 struct hid_field *field, struct hid_usage *usage,
109 unsigned long **bit, int *max)
111 if (usage->type == EV_KEY || usage->type == EV_ABS)
112 clear_bit(usage->code, *bit);
114 return 0;
118 * this function is called when a whole finger has been parsed,
119 * so that it can decide what to send to the input layer.
121 static void stantum_filter_event(struct stantum_data *sd,
122 struct input_dev *input)
124 bool wide;
126 if (!sd->valid) {
128 * touchscreen emulation: if the first finger is not valid and
129 * there previously was finger activity, this is a release
131 if (sd->first && sd->activity) {
132 input_event(input, EV_KEY, BTN_TOUCH, 0);
133 sd->activity = false;
135 return;
138 input_event(input, EV_ABS, ABS_MT_TRACKING_ID, sd->id);
139 input_event(input, EV_ABS, ABS_MT_POSITION_X, sd->x);
140 input_event(input, EV_ABS, ABS_MT_POSITION_Y, sd->y);
142 wide = (sd->w > sd->h);
143 input_event(input, EV_ABS, ABS_MT_ORIENTATION, wide);
144 input_event(input, EV_ABS, ABS_MT_TOUCH_MAJOR, wide ? sd->w : sd->h);
145 input_event(input, EV_ABS, ABS_MT_TOUCH_MINOR, wide ? sd->h : sd->w);
147 input_event(input, EV_ABS, ABS_MT_PRESSURE, sd->z);
149 input_mt_sync(input);
150 sd->valid = false;
152 /* touchscreen emulation */
153 if (sd->first) {
154 if (!sd->activity) {
155 input_event(input, EV_KEY, BTN_TOUCH, 1);
156 sd->activity = true;
158 input_event(input, EV_ABS, ABS_X, sd->x);
159 input_event(input, EV_ABS, ABS_Y, sd->y);
161 sd->first = false;
165 static int stantum_event(struct hid_device *hid, struct hid_field *field,
166 struct hid_usage *usage, __s32 value)
168 struct stantum_data *sd = hid_get_drvdata(hid);
170 if (hid->claimed & HID_CLAIMED_INPUT) {
171 struct input_dev *input = field->hidinput->input;
173 switch (usage->hid) {
174 case HID_DG_INRANGE:
175 /* this is the last field in a finger */
176 stantum_filter_event(sd, input);
177 break;
178 case HID_DG_WIDTH:
179 sd->w = value;
180 break;
181 case HID_DG_HEIGHT:
182 sd->h = value;
183 break;
184 case HID_GD_X:
185 sd->x = value;
186 break;
187 case HID_GD_Y:
188 sd->y = value;
189 break;
190 case HID_DG_TIPPRESSURE:
191 sd->z = value;
192 break;
193 case HID_DG_CONTACTID:
194 sd->id = value;
195 break;
196 case HID_DG_CONFIDENCE:
197 sd->valid = !!value;
198 break;
199 case 0xff000002:
200 /* this comes only before the first finger */
201 sd->first = true;
202 break;
204 default:
205 /* ignore the others */
206 return 1;
210 /* we have handled the hidinput part, now remains hiddev */
211 if (hid->claimed & HID_CLAIMED_HIDDEV && hid->hiddev_hid_event)
212 hid->hiddev_hid_event(hid, field, usage, value);
214 return 1;
217 static int stantum_probe(struct hid_device *hdev,
218 const struct hid_device_id *id)
220 int ret;
221 struct stantum_data *sd;
223 sd = kmalloc(sizeof(struct stantum_data), GFP_KERNEL);
224 if (!sd) {
225 hid_err(hdev, "cannot allocate Stantum data\n");
226 return -ENOMEM;
228 sd->valid = false;
229 sd->first = false;
230 sd->activity = false;
231 hid_set_drvdata(hdev, sd);
233 ret = hid_parse(hdev);
234 if (!ret)
235 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
237 if (ret)
238 kfree(sd);
240 return ret;
243 static void stantum_remove(struct hid_device *hdev)
245 hid_hw_stop(hdev);
246 kfree(hid_get_drvdata(hdev));
247 hid_set_drvdata(hdev, NULL);
250 static const struct hid_device_id stantum_devices[] = {
251 { HID_USB_DEVICE(USB_VENDOR_ID_STANTUM, USB_DEVICE_ID_MTP) },
252 { HID_USB_DEVICE(USB_VENDOR_ID_STANTUM_STM, USB_DEVICE_ID_MTP_STM) },
253 { HID_USB_DEVICE(USB_VENDOR_ID_STANTUM_SITRONIX, USB_DEVICE_ID_MTP_SITRONIX) },
256 MODULE_DEVICE_TABLE(hid, stantum_devices);
258 static const struct hid_usage_id stantum_grabbed_usages[] = {
259 { HID_ANY_ID, HID_ANY_ID, HID_ANY_ID },
260 { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1}
263 static struct hid_driver stantum_driver = {
264 .name = "stantum",
265 .id_table = stantum_devices,
266 .probe = stantum_probe,
267 .remove = stantum_remove,
268 .input_mapping = stantum_input_mapping,
269 .input_mapped = stantum_input_mapped,
270 .usage_table = stantum_grabbed_usages,
271 .event = stantum_event,
274 static int __init stantum_init(void)
276 return hid_register_driver(&stantum_driver);
279 static void __exit stantum_exit(void)
281 hid_unregister_driver(&stantum_driver);
284 module_init(stantum_init);
285 module_exit(stantum_exit);