Lines Matching +full:event +full:- +full:touch
1 // SPDX-License-Identifier: GPL-2.0-or-later
20 #include "hid-ids.h"
26 static int middle_button_start = -350;
38 return -EINVAL; in param_set_scroll_speed()
51 …ARM_DESC(report_undeciphered, "Report undeciphered multi-touch state field using a MSC_RAW event");
59 * 0x03 seem to indicate the aspect ratio of the touch, bits 0x70 seem
60 * to be some kind of bit mask -- 0x20 may be a near-field reading,
71 /* Touch surface information. Dimension is in hundredths of a mm, min and max
74 #define MOUSE_MIN_X -1100
76 #define MOUSE_RES_X ((MOUSE_MAX_X - MOUSE_MIN_X) / (MOUSE_DIMENSION_X / 100))
78 #define MOUSE_MIN_Y -1589
80 #define MOUSE_RES_Y ((MOUSE_MAX_Y - MOUSE_MIN_Y) / (MOUSE_DIMENSION_Y / 100))
83 #define TRACKPAD_MIN_X -2909
86 ((TRACKPAD_MAX_X - TRACKPAD_MIN_X) / (TRACKPAD_DIMENSION_X / 100))
88 #define TRACKPAD_MIN_Y -2456
91 ((TRACKPAD_MAX_Y - TRACKPAD_MIN_Y) / (TRACKPAD_DIMENSION_Y / 100))
94 #define TRACKPAD2_MIN_X -3678
97 ((TRACKPAD2_MAX_X - TRACKPAD2_MIN_X) / (TRACKPAD2_DIMENSION_X / 100))
99 #define TRACKPAD2_MIN_Y -2478
102 ((TRACKPAD2_MAX_Y - TRACKPAD2_MIN_Y) / (TRACKPAD2_DIMENSION_Y / 100))
105 * struct magicmouse_sc - Tracks Magic Mouse-specific data.
108 * @ntouches: Number of touches in most recent touch report.
111 * @touches: Most recent data for a touch, indexed by tracking ID.
112 * @tracking_ids: Mapping of current touch input data to @touches.
134 int touch = -1; in magicmouse_firm_touch() local
137 /* If there is only one "firm" touch, set touch to its in magicmouse_firm_touch()
140 for (ii = 0; ii < msc->ntouches; ii++) { in magicmouse_firm_touch()
141 int idx = msc->tracking_ids[ii]; in magicmouse_firm_touch()
142 if (msc->touches[idx].size < 8) { in magicmouse_firm_touch()
143 /* Ignore this touch. */ in magicmouse_firm_touch()
144 } else if (touch >= 0) { in magicmouse_firm_touch()
145 touch = -1; in magicmouse_firm_touch()
148 touch = idx; in magicmouse_firm_touch()
152 return touch; in magicmouse_firm_touch()
157 int last_state = test_bit(BTN_LEFT, msc->input->key) << 0 | in magicmouse_emit_buttons()
158 test_bit(BTN_RIGHT, msc->input->key) << 1 | in magicmouse_emit_buttons()
159 test_bit(BTN_MIDDLE, msc->input->key) << 2; in magicmouse_emit_buttons()
166 * touch, use that to override the mouse's guess. in magicmouse_emit_buttons()
173 int x = msc->touches[id].x; in magicmouse_emit_buttons()
182 input_report_key(msc->input, BTN_MIDDLE, state & 4); in magicmouse_emit_buttons()
185 input_report_key(msc->input, BTN_LEFT, state & 1); in magicmouse_emit_buttons()
186 input_report_key(msc->input, BTN_RIGHT, state & 2); in magicmouse_emit_buttons()
189 msc->scroll_accel = SCROLL_ACCEL_DEFAULT; in magicmouse_emit_buttons()
194 struct input_dev *input = msc->input; in magicmouse_emit_touch()
198 if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE) { in magicmouse_emit_touch()
201 y = -((tdata[2] << 24 | tdata[1] << 16) >> 20); in magicmouse_emit_touch()
203 orientation = (tdata[6] >> 2) - 32; in magicmouse_emit_touch()
208 } else if (input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2) { in magicmouse_emit_touch()
211 y = -((tdata[3] << 30 | tdata[2] << 22 | tdata[1] << 14) >> 19); in magicmouse_emit_touch()
213 orientation = (tdata[8] >> 5) - 4; in magicmouse_emit_touch()
222 y = -((tdata[3] << 30 | tdata[2] << 22 | tdata[1] << 14) >> 19); in magicmouse_emit_touch()
224 orientation = (tdata[7] >> 2) - 32; in magicmouse_emit_touch()
232 msc->tracking_ids[raw_id] = id; in magicmouse_emit_touch()
233 msc->touches[id].x = x; in magicmouse_emit_touch()
234 msc->touches[id].y = y; in magicmouse_emit_touch()
235 msc->touches[id].size = size; in magicmouse_emit_touch()
238 * vertical touch motions. in magicmouse_emit_touch()
240 if (emulate_scroll_wheel && (input->id.product != in magicmouse_emit_touch()
243 int step_x = msc->touches[id].scroll_x - x; in magicmouse_emit_touch()
244 int step_y = msc->touches[id].scroll_y - y; in magicmouse_emit_touch()
249 msc->touches[id].scroll_x = x; in magicmouse_emit_touch()
250 msc->touches[id].scroll_y = y; in magicmouse_emit_touch()
254 msc->scroll_jiffies + HZ / 2)) in magicmouse_emit_touch()
255 msc->scroll_accel = max_t(int, in magicmouse_emit_touch()
256 msc->scroll_accel - 1, 1); in magicmouse_emit_touch()
258 msc->scroll_accel = SCROLL_ACCEL_DEFAULT; in magicmouse_emit_touch()
262 step_x /= (64 - (int)scroll_speed) * msc->scroll_accel; in magicmouse_emit_touch()
264 msc->touches[id].scroll_x -= step_x * in magicmouse_emit_touch()
265 (64 - scroll_speed) * msc->scroll_accel; in magicmouse_emit_touch()
266 msc->scroll_jiffies = now; in magicmouse_emit_touch()
267 input_report_rel(input, REL_HWHEEL, -step_x); in magicmouse_emit_touch()
270 step_y /= (64 - (int)scroll_speed) * msc->scroll_accel; in magicmouse_emit_touch()
272 msc->touches[id].scroll_y -= step_y * in magicmouse_emit_touch()
273 (64 - scroll_speed) * msc->scroll_accel; in magicmouse_emit_touch()
274 msc->scroll_jiffies = now; in magicmouse_emit_touch()
282 msc->ntouches++; in magicmouse_emit_touch()
287 /* Generate the input events for this touch. */ in magicmouse_emit_touch()
291 input_report_abs(input, ABS_MT_ORIENTATION, -orientation); in magicmouse_emit_touch()
295 if (input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2) in magicmouse_emit_touch()
299 if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE) in magicmouse_emit_touch()
301 else if (input->id.product != in magicmouse_emit_touch()
312 struct input_dev *input = msc->input; in magicmouse_raw_event()
318 /* Expect four bytes of prefix, and N*9 bytes of touch data. */ in magicmouse_raw_event()
319 if (size < 4 || ((size - 4) % 9) != 0) in magicmouse_raw_event()
321 npoints = (size - 4) / 9; in magicmouse_raw_event()
327 msc->ntouches = 0; in magicmouse_raw_event()
340 /* Expect twelve bytes of prefix and N*9 bytes of touch data. */ in magicmouse_raw_event()
341 if (size < 12 || ((size - 12) % 9) != 0) in magicmouse_raw_event()
343 npoints = (size - 12) / 9; in magicmouse_raw_event()
349 msc->ntouches = 0; in magicmouse_raw_event()
356 /* Expect six bytes of prefix, and N*8 bytes of touch data. */ in magicmouse_raw_event()
357 if (size < 6 || ((size - 6) % 8) != 0) in magicmouse_raw_event()
359 npoints = (size - 6) / 8; in magicmouse_raw_event()
365 msc->ntouches = 0; in magicmouse_raw_event()
369 /* When emulating three-button mode, it is important in magicmouse_raw_event()
370 * to have the current touch information before in magicmouse_raw_event()
371 * generating a click event. in magicmouse_raw_event()
384 /* Sometimes the trackpad sends two touch reports in one in magicmouse_raw_event()
389 size - 2 - data[1]); in magicmouse_raw_event()
395 if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE) { in magicmouse_raw_event()
399 } else if (input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2) { in magicmouse_raw_event()
416 __set_bit(EV_KEY, input->evbit); in magicmouse_setup_input()
418 if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE) { in magicmouse_setup_input()
419 __set_bit(BTN_LEFT, input->keybit); in magicmouse_setup_input()
420 __set_bit(BTN_RIGHT, input->keybit); in magicmouse_setup_input()
422 __set_bit(BTN_MIDDLE, input->keybit); in magicmouse_setup_input()
424 __set_bit(EV_REL, input->evbit); in magicmouse_setup_input()
425 __set_bit(REL_X, input->relbit); in magicmouse_setup_input()
426 __set_bit(REL_Y, input->relbit); in magicmouse_setup_input()
428 __set_bit(REL_WHEEL, input->relbit); in magicmouse_setup_input()
429 __set_bit(REL_HWHEEL, input->relbit); in magicmouse_setup_input()
431 } else if (input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2) { in magicmouse_setup_input()
435 input->name = "Apple Inc. Magic Trackpad 2"; in magicmouse_setup_input()
437 __clear_bit(EV_MSC, input->evbit); in magicmouse_setup_input()
438 __clear_bit(BTN_0, input->keybit); in magicmouse_setup_input()
439 __clear_bit(BTN_RIGHT, input->keybit); in magicmouse_setup_input()
440 __clear_bit(BTN_MIDDLE, input->keybit); in magicmouse_setup_input()
441 __set_bit(BTN_MOUSE, input->keybit); in magicmouse_setup_input()
442 __set_bit(INPUT_PROP_BUTTONPAD, input->propbit); in magicmouse_setup_input()
443 __set_bit(BTN_TOOL_FINGER, input->keybit); in magicmouse_setup_input()
448 /* input->keybit is initialized with incorrect button info in magicmouse_setup_input()
453 __clear_bit(BTN_RIGHT, input->keybit); in magicmouse_setup_input()
454 __clear_bit(BTN_MIDDLE, input->keybit); in magicmouse_setup_input()
455 __set_bit(BTN_MOUSE, input->keybit); in magicmouse_setup_input()
456 __set_bit(BTN_TOOL_FINGER, input->keybit); in magicmouse_setup_input()
457 __set_bit(BTN_TOOL_DOUBLETAP, input->keybit); in magicmouse_setup_input()
458 __set_bit(BTN_TOOL_TRIPLETAP, input->keybit); in magicmouse_setup_input()
459 __set_bit(BTN_TOOL_QUADTAP, input->keybit); in magicmouse_setup_input()
460 __set_bit(BTN_TOOL_QUINTTAP, input->keybit); in magicmouse_setup_input()
461 __set_bit(BTN_TOUCH, input->keybit); in magicmouse_setup_input()
462 __set_bit(INPUT_PROP_POINTER, input->propbit); in magicmouse_setup_input()
463 __set_bit(INPUT_PROP_BUTTONPAD, input->propbit); in magicmouse_setup_input()
467 __set_bit(EV_ABS, input->evbit); in magicmouse_setup_input()
477 /* Note: Touch Y position from the device is inverted relative in magicmouse_setup_input()
483 if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE) { in magicmouse_setup_input()
484 input_set_abs_params(input, ABS_MT_ORIENTATION, -31, 32, 1, 0); in magicmouse_setup_input()
494 } else if (input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2) { in magicmouse_setup_input()
497 input_set_abs_params(input, ABS_MT_ORIENTATION, -3, 4, 0, 0); in magicmouse_setup_input()
512 input_set_abs_params(input, ABS_MT_ORIENTATION, -31, 32, 1, 0); in magicmouse_setup_input()
533 input->id.product != USB_DEVICE_ID_APPLE_MAGICTRACKPAD2) { in magicmouse_setup_input()
534 __set_bit(EV_MSC, input->evbit); in magicmouse_setup_input()
535 __set_bit(MSC_RAW, input->mscbit); in magicmouse_setup_input()
539 * hid-input may mark device as using autorepeat, but neither in magicmouse_setup_input()
542 __clear_bit(EV_REP, input->evbit); in magicmouse_setup_input()
553 if (!msc->input) in magicmouse_input_mapping()
554 msc->input = hi->input; in magicmouse_input_mapping()
557 if ((hi->input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD || in magicmouse_input_mapping()
558 hi->input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2) && in magicmouse_input_mapping()
559 field->flags & HID_MAIN_ITEM_RELATIVE) in magicmouse_input_mapping()
560 return -1; in magicmouse_input_mapping()
572 ret = magicmouse_setup_input(msc->input, hdev); in magicmouse_input_configured()
575 /* clean msc->input to notify probe() of the failure */ in magicmouse_input_configured()
576 msc->input = NULL; in magicmouse_input_configured()
597 if (id->vendor == USB_VENDOR_ID_APPLE && in magicmouse_probe()
598 id->product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 && in magicmouse_probe()
599 hdev->type != HID_TYPE_USBMOUSE) in magicmouse_probe()
602 msc = devm_kzalloc(&hdev->dev, sizeof(*msc), GFP_KERNEL); in magicmouse_probe()
605 return -ENOMEM; in magicmouse_probe()
608 msc->scroll_accel = SCROLL_ACCEL_DEFAULT; in magicmouse_probe()
610 msc->quirks = id->driver_data; in magicmouse_probe()
625 if (!msc->input) { in magicmouse_probe()
627 ret = -ENOMEM; in magicmouse_probe()
631 if (id->product == USB_DEVICE_ID_APPLE_MAGICMOUSE) in magicmouse_probe()
634 else if (id->product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2) { in magicmouse_probe()
635 if (id->vendor == BT_VENDOR_ID_APPLE) in magicmouse_probe()
649 hid_err(hdev, "unable to register touch report\n"); in magicmouse_probe()
650 ret = -ENOMEM; in magicmouse_probe()
653 report->size = 6; in magicmouse_probe()
655 if (id->product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2) { in magicmouse_probe()
656 if (id->vendor == BT_VENDOR_ID_APPLE) { in magicmouse_probe()
670 ret = -ENOMEM; in magicmouse_probe()
678 * This results in -EIO from the _raw low-level transport callback, in magicmouse_probe()
680 * Thus the super-ugly hacky success check below. in magicmouse_probe()
685 if (ret != -EIO && ret != feature_size) { in magicmouse_probe()
686 hid_err(hdev, "unable to request touch data (%d)\n", ret); in magicmouse_probe()