diff options
Diffstat (limited to 'drivers/hid/hid-ntrig.c')
| -rw-r--r-- | drivers/hid/hid-ntrig.c | 212 |
1 files changed, 147 insertions, 65 deletions
diff --git a/drivers/hid/hid-ntrig.c b/drivers/hid/hid-ntrig.c index 49ce69d7bba7..3234c729a895 100644 --- a/drivers/hid/hid-ntrig.c +++ b/drivers/hid/hid-ntrig.c | |||
| @@ -25,11 +25,16 @@ | |||
| 25 | EV_KEY, (c)) | 25 | EV_KEY, (c)) |
| 26 | 26 | ||
| 27 | struct ntrig_data { | 27 | struct ntrig_data { |
| 28 | __s32 x, y, id, w, h; | 28 | /* Incoming raw values for a single contact */ |
| 29 | char reading_a_point, found_contact_id; | 29 | __u16 x, y, w, h; |
| 30 | char pen_active; | 30 | __u16 id; |
| 31 | char finger_active; | 31 | __u8 confidence; |
| 32 | char inverted; | 32 | |
| 33 | bool reading_mt; | ||
| 34 | __u8 first_contact_confidence; | ||
| 35 | |||
| 36 | __u8 mt_footer[4]; | ||
| 37 | __u8 mt_foot_count; | ||
| 33 | }; | 38 | }; |
| 34 | 39 | ||
| 35 | /* | 40 | /* |
| @@ -42,8 +47,11 @@ static int ntrig_input_mapping(struct hid_device *hdev, struct hid_input *hi, | |||
| 42 | struct hid_field *field, struct hid_usage *usage, | 47 | struct hid_field *field, struct hid_usage *usage, |
| 43 | unsigned long **bit, int *max) | 48 | unsigned long **bit, int *max) |
| 44 | { | 49 | { |
| 45 | switch (usage->hid & HID_USAGE_PAGE) { | 50 | /* No special mappings needed for the pen and single touch */ |
| 51 | if (field->physical) | ||
| 52 | return 0; | ||
| 46 | 53 | ||
| 54 | switch (usage->hid & HID_USAGE_PAGE) { | ||
| 47 | case HID_UP_GENDESK: | 55 | case HID_UP_GENDESK: |
| 48 | switch (usage->hid) { | 56 | switch (usage->hid) { |
| 49 | case HID_GD_X: | 57 | case HID_GD_X: |
| @@ -66,18 +74,12 @@ static int ntrig_input_mapping(struct hid_device *hdev, struct hid_input *hi, | |||
| 66 | case HID_UP_DIGITIZER: | 74 | case HID_UP_DIGITIZER: |
| 67 | switch (usage->hid) { | 75 | switch (usage->hid) { |
| 68 | /* we do not want to map these for now */ | 76 | /* we do not want to map these for now */ |
| 69 | case HID_DG_CONTACTID: /* value is useless */ | 77 | case HID_DG_CONTACTID: /* Not trustworthy, squelch for now */ |
| 70 | case HID_DG_INPUTMODE: | 78 | case HID_DG_INPUTMODE: |
| 71 | case HID_DG_DEVICEINDEX: | 79 | case HID_DG_DEVICEINDEX: |
| 72 | case HID_DG_CONTACTCOUNT: | ||
| 73 | case HID_DG_CONTACTMAX: | 80 | case HID_DG_CONTACTMAX: |
| 74 | return -1; | 81 | return -1; |
| 75 | 82 | ||
| 76 | /* original mapping by Rafi Rubin */ | ||
| 77 | case HID_DG_CONFIDENCE: | ||
| 78 | nt_map_key_clear(BTN_TOOL_DOUBLETAP); | ||
| 79 | return 1; | ||
| 80 | |||
| 81 | /* width/height mapped on TouchMajor/TouchMinor/Orientation */ | 83 | /* width/height mapped on TouchMajor/TouchMinor/Orientation */ |
| 82 | case HID_DG_WIDTH: | 84 | case HID_DG_WIDTH: |
| 83 | hid_map_usage(hi, usage, bit, max, | 85 | hid_map_usage(hi, usage, bit, max, |
| @@ -104,6 +106,10 @@ static int ntrig_input_mapped(struct hid_device *hdev, struct hid_input *hi, | |||
| 104 | struct hid_field *field, struct hid_usage *usage, | 106 | struct hid_field *field, struct hid_usage *usage, |
| 105 | unsigned long **bit, int *max) | 107 | unsigned long **bit, int *max) |
| 106 | { | 108 | { |
| 109 | /* No special mappings needed for the pen and single touch */ | ||
| 110 | if (field->physical) | ||
| 111 | return 0; | ||
| 112 | |||
| 107 | if (usage->type == EV_KEY || usage->type == EV_REL | 113 | if (usage->type == EV_KEY || usage->type == EV_REL |
| 108 | || usage->type == EV_ABS) | 114 | || usage->type == EV_ABS) |
| 109 | clear_bit(usage->code, *bit); | 115 | clear_bit(usage->code, *bit); |
| @@ -123,31 +129,30 @@ static int ntrig_event (struct hid_device *hid, struct hid_field *field, | |||
| 123 | struct input_dev *input = field->hidinput->input; | 129 | struct input_dev *input = field->hidinput->input; |
| 124 | struct ntrig_data *nd = hid_get_drvdata(hid); | 130 | struct ntrig_data *nd = hid_get_drvdata(hid); |
| 125 | 131 | ||
| 132 | /* No special handling needed for the pen */ | ||
| 133 | if (field->application == HID_DG_PEN) | ||
| 134 | return 0; | ||
| 135 | |||
| 126 | if (hid->claimed & HID_CLAIMED_INPUT) { | 136 | if (hid->claimed & HID_CLAIMED_INPUT) { |
| 127 | switch (usage->hid) { | 137 | switch (usage->hid) { |
| 128 | 138 | case 0xff000001: | |
| 129 | case HID_DG_INRANGE: | 139 | /* Tag indicating the start of a multitouch group */ |
| 130 | if (field->application & 0x3) | 140 | nd->reading_mt = 1; |
| 131 | nd->pen_active = (value != 0); | 141 | nd->first_contact_confidence = 0; |
| 132 | else | 142 | break; |
| 133 | nd->finger_active = (value != 0); | 143 | case HID_DG_CONFIDENCE: |
| 134 | return 0; | 144 | nd->confidence = value; |
| 135 | 145 | break; | |
| 136 | case HID_DG_INVERT: | ||
| 137 | nd->inverted = value; | ||
| 138 | return 0; | ||
| 139 | |||
| 140 | case HID_GD_X: | 146 | case HID_GD_X: |
| 141 | nd->x = value; | 147 | nd->x = value; |
| 142 | nd->reading_a_point = 1; | 148 | /* Clear the contact footer */ |
| 149 | nd->mt_foot_count = 0; | ||
| 143 | break; | 150 | break; |
| 144 | case HID_GD_Y: | 151 | case HID_GD_Y: |
| 145 | nd->y = value; | 152 | nd->y = value; |
| 146 | break; | 153 | break; |
| 147 | case HID_DG_CONTACTID: | 154 | case HID_DG_CONTACTID: |
| 148 | nd->id = value; | 155 | nd->id = value; |
| 149 | /* we receive this only when in multitouch mode */ | ||
| 150 | nd->found_contact_id = 1; | ||
| 151 | break; | 156 | break; |
| 152 | case HID_DG_WIDTH: | 157 | case HID_DG_WIDTH: |
| 153 | nd->w = value; | 158 | nd->w = value; |
| @@ -159,35 +164,13 @@ static int ntrig_event (struct hid_device *hid, struct hid_field *field, | |||
| 159 | * report received in a finger event. We want | 164 | * report received in a finger event. We want |
| 160 | * to emit a normal (X, Y) position | 165 | * to emit a normal (X, Y) position |
| 161 | */ | 166 | */ |
| 162 | if (!nd->found_contact_id) { | 167 | if (!nd->reading_mt) { |
| 163 | if (nd->pen_active && nd->finger_active) { | 168 | input_report_key(input, BTN_TOOL_DOUBLETAP, |
| 164 | input_report_key(input, BTN_TOOL_DOUBLETAP, 0); | 169 | (nd->confidence != 0)); |
| 165 | input_report_key(input, BTN_TOOL_DOUBLETAP, 1); | ||
| 166 | } | ||
| 167 | input_event(input, EV_ABS, ABS_X, nd->x); | 170 | input_event(input, EV_ABS, ABS_X, nd->x); |
| 168 | input_event(input, EV_ABS, ABS_Y, nd->y); | 171 | input_event(input, EV_ABS, ABS_Y, nd->y); |
| 169 | } | 172 | } |
| 170 | break; | 173 | break; |
| 171 | case HID_DG_TIPPRESSURE: | ||
| 172 | /* | ||
| 173 | * when in single touch mode, this is the last | ||
| 174 | * report received in a pen event. We want | ||
| 175 | * to emit a normal (X, Y) position | ||
| 176 | */ | ||
| 177 | if (! nd->found_contact_id) { | ||
| 178 | if (nd->pen_active && nd->finger_active) { | ||
| 179 | input_report_key(input, | ||
| 180 | nd->inverted ? BTN_TOOL_RUBBER : BTN_TOOL_PEN | ||
| 181 | , 0); | ||
| 182 | input_report_key(input, | ||
| 183 | nd->inverted ? BTN_TOOL_RUBBER : BTN_TOOL_PEN | ||
| 184 | , 1); | ||
| 185 | } | ||
| 186 | input_event(input, EV_ABS, ABS_X, nd->x); | ||
| 187 | input_event(input, EV_ABS, ABS_Y, nd->y); | ||
| 188 | input_event(input, EV_ABS, ABS_PRESSURE, value); | ||
| 189 | } | ||
| 190 | break; | ||
| 191 | case 0xff000002: | 174 | case 0xff000002: |
| 192 | /* | 175 | /* |
| 193 | * we receive this when the device is in multitouch | 176 | * we receive this when the device is in multitouch |
| @@ -195,10 +178,34 @@ static int ntrig_event (struct hid_device *hid, struct hid_field *field, | |||
| 195 | * this usage tells if the contact point is real | 178 | * this usage tells if the contact point is real |
| 196 | * or a placeholder | 179 | * or a placeholder |
| 197 | */ | 180 | */ |
| 198 | if (!nd->reading_a_point || value != 1) | 181 | |
| 182 | /* Shouldn't get more than 4 footer packets, so skip */ | ||
| 183 | if (nd->mt_foot_count >= 4) | ||
| 199 | break; | 184 | break; |
| 185 | |||
| 186 | nd->mt_footer[nd->mt_foot_count++] = value; | ||
| 187 | |||
| 188 | /* if the footer isn't complete break */ | ||
| 189 | if (nd->mt_foot_count != 4) | ||
| 190 | break; | ||
| 191 | |||
| 192 | /* Pen activity signal, trigger end of touch. */ | ||
| 193 | if (nd->mt_footer[2]) { | ||
| 194 | nd->confidence = 0; | ||
| 195 | break; | ||
| 196 | } | ||
| 197 | |||
| 198 | /* If the contact was invalid */ | ||
| 199 | if (!(nd->confidence && nd->mt_footer[0]) | ||
| 200 | || nd->w <= 250 | ||
| 201 | || nd->h <= 190) { | ||
| 202 | nd->confidence = 0; | ||
| 203 | break; | ||
| 204 | } | ||
| 205 | |||
| 200 | /* emit a normal (X, Y) for the first point only */ | 206 | /* emit a normal (X, Y) for the first point only */ |
| 201 | if (nd->id == 0) { | 207 | if (nd->id == 0) { |
| 208 | nd->first_contact_confidence = nd->confidence; | ||
| 202 | input_event(input, EV_ABS, ABS_X, nd->x); | 209 | input_event(input, EV_ABS, ABS_X, nd->x); |
| 203 | input_event(input, EV_ABS, ABS_Y, nd->y); | 210 | input_event(input, EV_ABS, ABS_Y, nd->y); |
| 204 | } | 211 | } |
| @@ -220,8 +227,39 @@ static int ntrig_event (struct hid_device *hid, struct hid_field *field, | |||
| 220 | ABS_MT_TOUCH_MINOR, nd->w); | 227 | ABS_MT_TOUCH_MINOR, nd->w); |
| 221 | } | 228 | } |
| 222 | input_mt_sync(field->hidinput->input); | 229 | input_mt_sync(field->hidinput->input); |
| 223 | nd->reading_a_point = 0; | 230 | break; |
| 224 | nd->found_contact_id = 0; | 231 | |
| 232 | case HID_DG_CONTACTCOUNT: /* End of a multitouch group */ | ||
| 233 | if (!nd->reading_mt) | ||
| 234 | break; | ||
| 235 | |||
| 236 | nd->reading_mt = 0; | ||
| 237 | |||
| 238 | if (nd->first_contact_confidence) { | ||
| 239 | switch (value) { | ||
| 240 | case 0: /* for single touch devices */ | ||
| 241 | case 1: | ||
| 242 | input_report_key(input, | ||
| 243 | BTN_TOOL_DOUBLETAP, 1); | ||
| 244 | break; | ||
| 245 | case 2: | ||
| 246 | input_report_key(input, | ||
| 247 | BTN_TOOL_TRIPLETAP, 1); | ||
| 248 | break; | ||
| 249 | case 3: | ||
| 250 | default: | ||
| 251 | input_report_key(input, | ||
| 252 | BTN_TOOL_QUADTAP, 1); | ||
| 253 | } | ||
| 254 | input_report_key(input, BTN_TOUCH, 1); | ||
| 255 | } else { | ||
| 256 | input_report_key(input, | ||
| 257 | BTN_TOOL_DOUBLETAP, 0); | ||
| 258 | input_report_key(input, | ||
| 259 | BTN_TOOL_TRIPLETAP, 0); | ||
| 260 | input_report_key(input, | ||
| 261 | BTN_TOOL_QUADTAP, 0); | ||
| 262 | } | ||
| 225 | break; | 263 | break; |
| 226 | 264 | ||
| 227 | default: | 265 | default: |
| @@ -231,8 +269,8 @@ static int ntrig_event (struct hid_device *hid, struct hid_field *field, | |||
| 231 | } | 269 | } |
| 232 | 270 | ||
| 233 | /* we have handled the hidinput part, now remains hiddev */ | 271 | /* we have handled the hidinput part, now remains hiddev */ |
| 234 | if (hid->claimed & HID_CLAIMED_HIDDEV && hid->hiddev_hid_event) | 272 | if ((hid->claimed & HID_CLAIMED_HIDDEV) && hid->hiddev_hid_event) |
| 235 | hid->hiddev_hid_event(hid, field, usage, value); | 273 | hid->hiddev_hid_event(hid, field, usage, value); |
| 236 | 274 | ||
| 237 | return 1; | 275 | return 1; |
| 238 | } | 276 | } |
| @@ -241,23 +279,67 @@ static int ntrig_probe(struct hid_device *hdev, const struct hid_device_id *id) | |||
| 241 | { | 279 | { |
| 242 | int ret; | 280 | int ret; |
| 243 | struct ntrig_data *nd; | 281 | struct ntrig_data *nd; |
| 282 | struct hid_input *hidinput; | ||
| 283 | struct input_dev *input; | ||
| 284 | |||
| 285 | if (id->driver_data) | ||
| 286 | hdev->quirks |= HID_QUIRK_MULTI_INPUT; | ||
| 244 | 287 | ||
| 245 | nd = kmalloc(sizeof(struct ntrig_data), GFP_KERNEL); | 288 | nd = kmalloc(sizeof(struct ntrig_data), GFP_KERNEL); |
| 246 | if (!nd) { | 289 | if (!nd) { |
| 247 | dev_err(&hdev->dev, "cannot allocate N-Trig data\n"); | 290 | dev_err(&hdev->dev, "cannot allocate N-Trig data\n"); |
| 248 | return -ENOMEM; | 291 | return -ENOMEM; |
| 249 | } | 292 | } |
| 250 | nd->reading_a_point = 0; | 293 | |
| 251 | nd->found_contact_id = 0; | 294 | nd->reading_mt = 0; |
| 252 | hid_set_drvdata(hdev, nd); | 295 | hid_set_drvdata(hdev, nd); |
| 253 | 296 | ||
| 254 | ret = hid_parse(hdev); | 297 | ret = hid_parse(hdev); |
| 255 | if (!ret) | 298 | if (ret) { |
| 256 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); | 299 | dev_err(&hdev->dev, "parse failed\n"); |
| 300 | goto err_free; | ||
| 301 | } | ||
| 302 | |||
| 303 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF); | ||
| 304 | if (ret) { | ||
| 305 | dev_err(&hdev->dev, "hw start failed\n"); | ||
| 306 | goto err_free; | ||
| 307 | } | ||
| 257 | 308 | ||
| 258 | if (ret) | ||
| 259 | kfree (nd); | ||
| 260 | 309 | ||
| 310 | list_for_each_entry(hidinput, &hdev->inputs, list) { | ||
| 311 | input = hidinput->input; | ||
| 312 | switch (hidinput->report->field[0]->application) { | ||
| 313 | case HID_DG_PEN: | ||
| 314 | input->name = "N-Trig Pen"; | ||
| 315 | break; | ||
| 316 | case HID_DG_TOUCHSCREEN: | ||
| 317 | __clear_bit(BTN_TOOL_PEN, input->keybit); | ||
| 318 | /* | ||
| 319 | * A little something special to enable | ||
| 320 | * two and three finger taps. | ||
| 321 | */ | ||
| 322 | __set_bit(BTN_TOOL_DOUBLETAP, input->keybit); | ||
| 323 | __set_bit(BTN_TOOL_TRIPLETAP, input->keybit); | ||
| 324 | __set_bit(BTN_TOOL_QUADTAP, input->keybit); | ||
| 325 | /* | ||
| 326 | * The physical touchscreen (single touch) | ||
| 327 | * input has a value for physical, whereas | ||
| 328 | * the multitouch only has logical input | ||
| 329 | * fields. | ||
| 330 | */ | ||
| 331 | input->name = | ||
| 332 | (hidinput->report->field[0] | ||
| 333 | ->physical) ? | ||
| 334 | "N-Trig Touchscreen" : | ||
| 335 | "N-Trig MultiTouch"; | ||
| 336 | break; | ||
| 337 | } | ||
| 338 | } | ||
| 339 | |||
| 340 | return 0; | ||
| 341 | err_free: | ||
| 342 | kfree(nd); | ||
| 261 | return ret; | 343 | return ret; |
| 262 | } | 344 | } |
| 263 | 345 | ||
| @@ -276,7 +358,7 @@ MODULE_DEVICE_TABLE(hid, ntrig_devices); | |||
| 276 | 358 | ||
| 277 | static const struct hid_usage_id ntrig_grabbed_usages[] = { | 359 | static const struct hid_usage_id ntrig_grabbed_usages[] = { |
| 278 | { HID_ANY_ID, HID_ANY_ID, HID_ANY_ID }, | 360 | { HID_ANY_ID, HID_ANY_ID, HID_ANY_ID }, |
| 279 | { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1} | 361 | { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1 } |
| 280 | }; | 362 | }; |
| 281 | 363 | ||
| 282 | static struct hid_driver ntrig_driver = { | 364 | static struct hid_driver ntrig_driver = { |
