Lines Matching +full:trackpad +full:- +full:3 +full:x
1 // SPDX-License-Identifier: GPL-2.0-or-later
21 #include "hid-ids.h"
27 static int middle_button_start = -350;
39 return -EINVAL; in param_set_scroll_speed()
52 MODULE_PARM_DESC(report_undeciphered, "Report undeciphered multi-touch state field using a MSC_RAW …
66 * to be some kind of bit mask -- 0x20 may be a near-field reading,
75 /* Number of high-resolution events for each low-resolution detent. */
84 #define MOUSE_MIN_X -1100
86 #define MOUSE_RES_X ((MOUSE_MAX_X - MOUSE_MIN_X) / (MOUSE_DIMENSION_X / 100))
88 #define MOUSE_MIN_Y -1589
90 #define MOUSE_RES_Y ((MOUSE_MAX_Y - MOUSE_MIN_Y) / (MOUSE_DIMENSION_Y / 100))
93 #define TRACKPAD_MIN_X -2909
96 ((TRACKPAD_MAX_X - TRACKPAD_MIN_X) / (TRACKPAD_DIMENSION_X / 100))
98 #define TRACKPAD_MIN_Y -2456
101 ((TRACKPAD_MAX_Y - TRACKPAD_MIN_Y) / (TRACKPAD_DIMENSION_Y / 100))
104 #define TRACKPAD2_MIN_X -3678
107 ((TRACKPAD2_MAX_X - TRACKPAD2_MIN_X) / (TRACKPAD2_DIMENSION_X / 100))
109 #define TRACKPAD2_MIN_Y -2478
112 ((TRACKPAD2_MAX_Y - TRACKPAD2_MIN_Y) / (TRACKPAD2_DIMENSION_Y / 100))
115 * struct magicmouse_sc - Tracks Magic Mouse-specific data.
136 short x; member
155 int touch = -1; in magicmouse_firm_touch()
161 for (ii = 0; ii < msc->ntouches; ii++) { in magicmouse_firm_touch()
162 int idx = msc->tracking_ids[ii]; in magicmouse_firm_touch()
163 if (msc->touches[idx].size < 8) { in magicmouse_firm_touch()
166 touch = -1; in magicmouse_firm_touch()
178 int last_state = test_bit(BTN_LEFT, msc->input->key) << 0 | in magicmouse_emit_buttons()
179 test_bit(BTN_RIGHT, msc->input->key) << 1 | in magicmouse_emit_buttons()
180 test_bit(BTN_MIDDLE, msc->input->key) << 2; in magicmouse_emit_buttons()
194 int x = msc->touches[id].x; in magicmouse_emit_buttons() local
195 if (x < middle_button_start) in magicmouse_emit_buttons()
197 else if (x > middle_button_stop) in magicmouse_emit_buttons()
203 input_report_key(msc->input, BTN_MIDDLE, state & 4); in magicmouse_emit_buttons()
206 input_report_key(msc->input, BTN_LEFT, state & 1); in magicmouse_emit_buttons()
207 input_report_key(msc->input, BTN_RIGHT, state & 2); in magicmouse_emit_buttons()
210 msc->scroll_accel = SCROLL_ACCEL_DEFAULT; in magicmouse_emit_buttons()
215 struct input_dev *input = msc->input; in magicmouse_emit_touch()
216 int id, x, y, size, orientation, touch_major, touch_minor, state, down; in magicmouse_emit_touch() local
219 if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE || in magicmouse_emit_touch()
220 input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2) { in magicmouse_emit_touch()
222 x = (tdata[1] << 28 | tdata[0] << 20) >> 20; in magicmouse_emit_touch()
223 y = -((tdata[2] << 24 | tdata[1] << 16) >> 20); in magicmouse_emit_touch()
225 orientation = (tdata[6] >> 2) - 32; in magicmouse_emit_touch()
226 touch_major = tdata[3]; in magicmouse_emit_touch()
230 } else if (input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2) { in magicmouse_emit_touch()
232 x = (tdata[1] << 27 | tdata[0] << 19) >> 19; in magicmouse_emit_touch()
233 y = -((tdata[3] << 30 | tdata[2] << 22 | tdata[1] << 14) >> 19); in magicmouse_emit_touch()
235 orientation = (tdata[8] >> 5) - 4; in magicmouse_emit_touch()
239 state = tdata[3] & 0xC0; in magicmouse_emit_touch()
243 x = (tdata[1] << 27 | tdata[0] << 19) >> 19; in magicmouse_emit_touch()
244 y = -((tdata[3] << 30 | tdata[2] << 22 | tdata[1] << 14) >> 19); in magicmouse_emit_touch()
246 orientation = (tdata[7] >> 2) - 32; in magicmouse_emit_touch()
254 msc->tracking_ids[raw_id] = id; in magicmouse_emit_touch()
255 msc->touches[id].x = x; in magicmouse_emit_touch()
256 msc->touches[id].y = y; in magicmouse_emit_touch()
257 msc->touches[id].size = size; in magicmouse_emit_touch()
262 if (emulate_scroll_wheel && (input->id.product != in magicmouse_emit_touch()
265 int step_x = msc->touches[id].scroll_x - x; in magicmouse_emit_touch()
266 int step_y = msc->touches[id].scroll_y - y; in magicmouse_emit_touch()
269 ((64 - (int)scroll_speed) * msc->scroll_accel) / in magicmouse_emit_touch()
272 int step_x_hr = msc->touches[id].scroll_x_hr - x; in magicmouse_emit_touch()
273 int step_y_hr = msc->touches[id].scroll_y_hr - y; in magicmouse_emit_touch()
278 msc->touches[id].scroll_x = x; in magicmouse_emit_touch()
279 msc->touches[id].scroll_y = y; in magicmouse_emit_touch()
280 msc->touches[id].scroll_x_hr = x; in magicmouse_emit_touch()
281 msc->touches[id].scroll_y_hr = y; in magicmouse_emit_touch()
282 msc->touches[id].scroll_x_active = false; in magicmouse_emit_touch()
283 msc->touches[id].scroll_y_active = false; in magicmouse_emit_touch()
287 msc->scroll_jiffies + HZ / 2)) in magicmouse_emit_touch()
288 msc->scroll_accel = max_t(int, in magicmouse_emit_touch()
289 msc->scroll_accel - 1, 1); in magicmouse_emit_touch()
291 msc->scroll_accel = SCROLL_ACCEL_DEFAULT; in magicmouse_emit_touch()
295 step_x /= (64 - (int)scroll_speed) * msc->scroll_accel; in magicmouse_emit_touch()
297 msc->touches[id].scroll_x -= step_x * in magicmouse_emit_touch()
298 (64 - scroll_speed) * msc->scroll_accel; in magicmouse_emit_touch()
299 msc->scroll_jiffies = now; in magicmouse_emit_touch()
300 input_report_rel(input, REL_HWHEEL, -step_x); in magicmouse_emit_touch()
303 step_y /= (64 - (int)scroll_speed) * msc->scroll_accel; in magicmouse_emit_touch()
305 msc->touches[id].scroll_y -= step_y * in magicmouse_emit_touch()
306 (64 - scroll_speed) * msc->scroll_accel; in magicmouse_emit_touch()
307 msc->scroll_jiffies = now; in magicmouse_emit_touch()
311 if (!msc->touches[id].scroll_x_active && in magicmouse_emit_touch()
313 msc->touches[id].scroll_x_active = true; in magicmouse_emit_touch()
314 msc->touches[id].scroll_x_hr = x; in magicmouse_emit_touch()
320 msc->touches[id].scroll_x_active) { in magicmouse_emit_touch()
321 msc->touches[id].scroll_x_hr -= step_x_hr * in magicmouse_emit_touch()
325 -step_x_hr * SCROLL_HR_MULT); in magicmouse_emit_touch()
328 if (!msc->touches[id].scroll_y_active && in magicmouse_emit_touch()
330 msc->touches[id].scroll_y_active = true; in magicmouse_emit_touch()
331 msc->touches[id].scroll_y_hr = y; in magicmouse_emit_touch()
337 msc->touches[id].scroll_y_active) { in magicmouse_emit_touch()
338 msc->touches[id].scroll_y_hr -= step_y_hr * in magicmouse_emit_touch()
349 msc->ntouches++; in magicmouse_emit_touch()
358 input_report_abs(input, ABS_MT_ORIENTATION, -orientation); in magicmouse_emit_touch()
359 input_report_abs(input, ABS_MT_POSITION_X, x); in magicmouse_emit_touch()
362 if (input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2) in magicmouse_emit_touch()
366 if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE || in magicmouse_emit_touch()
367 input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2) in magicmouse_emit_touch()
369 else if (input->id.product != in magicmouse_emit_touch()
380 struct input_dev *input = msc->input; in magicmouse_raw_event()
381 int x = 0, y = 0, ii, clicks = 0, npoints; in magicmouse_raw_event() local
387 if (size < 4 || ((size - 4) % 9) != 0) in magicmouse_raw_event()
389 npoints = (size - 4) / 9; in magicmouse_raw_event()
395 msc->ntouches = 0; in magicmouse_raw_event()
404 * ts = data[1] >> 6 | data[2] << 2 | data[3] << 10; in magicmouse_raw_event()
409 if (size < 12 || ((size - 12) % 9) != 0) in magicmouse_raw_event()
411 npoints = (size - 12) / 9; in magicmouse_raw_event()
417 msc->ntouches = 0; in magicmouse_raw_event()
425 if (size < 6 || ((size - 6) % 8) != 0) in magicmouse_raw_event()
427 npoints = (size - 6) / 8; in magicmouse_raw_event()
433 msc->ntouches = 0; in magicmouse_raw_event()
437 /* When emulating three-button mode, it is important in magicmouse_raw_event()
441 x = (int)(((data[3] & 0x0c) << 28) | (data[1] << 22)) >> 22; in magicmouse_raw_event()
442 y = (int)(((data[3] & 0x30) << 26) | (data[2] << 22)) >> 22; in magicmouse_raw_event()
443 clicks = data[3]; in magicmouse_raw_event()
448 * ts = data[3] >> 6 | data[4] << 2 | data[5] << 10; in magicmouse_raw_event()
453 if (size != 8 && (size < 14 || (size - 14) % 8 != 0)) in magicmouse_raw_event()
455 npoints = (size - 14) / 8; in magicmouse_raw_event()
461 msc->ntouches = 0; in magicmouse_raw_event()
465 /* When emulating three-button mode, it is important in magicmouse_raw_event()
469 x = (int)((data[3] << 24) | (data[2] << 16)) >> 16; in magicmouse_raw_event()
480 /* Sometimes the trackpad sends two touch reports in one in magicmouse_raw_event()
485 size - 2 - data[1]); in magicmouse_raw_event()
491 if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE || in magicmouse_raw_event()
492 input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2) { in magicmouse_raw_event()
493 magicmouse_emit_buttons(msc, clicks & 3); in magicmouse_raw_event()
494 input_report_rel(input, REL_X, x); in magicmouse_raw_event()
496 } else if (input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2) { in magicmouse_raw_event()
512 if (msc->input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 && in magicmouse_event()
513 field->report->id == MOUSE2_REPORT_ID) { in magicmouse_event()
530 __set_bit(EV_KEY, input->evbit); in magicmouse_setup_input()
532 if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE || in magicmouse_setup_input()
533 input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2) { in magicmouse_setup_input()
534 __set_bit(BTN_LEFT, input->keybit); in magicmouse_setup_input()
535 __set_bit(BTN_RIGHT, input->keybit); in magicmouse_setup_input()
537 __set_bit(BTN_MIDDLE, input->keybit); in magicmouse_setup_input()
539 __set_bit(EV_REL, input->evbit); in magicmouse_setup_input()
540 __set_bit(REL_X, input->relbit); in magicmouse_setup_input()
541 __set_bit(REL_Y, input->relbit); in magicmouse_setup_input()
543 __set_bit(REL_WHEEL, input->relbit); in magicmouse_setup_input()
544 __set_bit(REL_HWHEEL, input->relbit); in magicmouse_setup_input()
545 __set_bit(REL_WHEEL_HI_RES, input->relbit); in magicmouse_setup_input()
546 __set_bit(REL_HWHEEL_HI_RES, input->relbit); in magicmouse_setup_input()
548 } else if (input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2) { in magicmouse_setup_input()
549 /* If the trackpad has been connected to a Mac, the name is in magicmouse_setup_input()
550 * automatically personalized, e.g., "José Expósito's Trackpad". in magicmouse_setup_input()
557 if (hdev->vendor == BT_VENDOR_ID_APPLE) { in magicmouse_setup_input()
558 if (input->id.version == TRACKPAD2_2021_BT_VERSION) in magicmouse_setup_input()
559 input->name = "Apple Inc. Magic Trackpad"; in magicmouse_setup_input()
561 input->name = "Apple Inc. Magic Trackpad 2"; in magicmouse_setup_input()
563 input->name = hdev->name; in magicmouse_setup_input()
566 __clear_bit(EV_MSC, input->evbit); in magicmouse_setup_input()
567 __clear_bit(BTN_0, input->keybit); in magicmouse_setup_input()
568 __clear_bit(BTN_RIGHT, input->keybit); in magicmouse_setup_input()
569 __clear_bit(BTN_MIDDLE, input->keybit); in magicmouse_setup_input()
570 __set_bit(BTN_MOUSE, input->keybit); in magicmouse_setup_input()
571 __set_bit(INPUT_PROP_BUTTONPAD, input->propbit); in magicmouse_setup_input()
572 __set_bit(BTN_TOOL_FINGER, input->keybit); in magicmouse_setup_input()
577 /* input->keybit is initialized with incorrect button info in magicmouse_setup_input()
578 * for Magic Trackpad. There really is only one physical in magicmouse_setup_input()
582 __clear_bit(BTN_RIGHT, input->keybit); in magicmouse_setup_input()
583 __clear_bit(BTN_MIDDLE, input->keybit); in magicmouse_setup_input()
584 __set_bit(BTN_MOUSE, input->keybit); in magicmouse_setup_input()
585 __set_bit(BTN_TOOL_FINGER, input->keybit); in magicmouse_setup_input()
586 __set_bit(BTN_TOOL_DOUBLETAP, input->keybit); in magicmouse_setup_input()
587 __set_bit(BTN_TOOL_TRIPLETAP, input->keybit); in magicmouse_setup_input()
588 __set_bit(BTN_TOOL_QUADTAP, input->keybit); in magicmouse_setup_input()
589 __set_bit(BTN_TOOL_QUINTTAP, input->keybit); in magicmouse_setup_input()
590 __set_bit(BTN_TOUCH, input->keybit); in magicmouse_setup_input()
591 __set_bit(INPUT_PROP_POINTER, input->propbit); in magicmouse_setup_input()
592 __set_bit(INPUT_PROP_BUTTONPAD, input->propbit); in magicmouse_setup_input()
596 __set_bit(EV_ABS, input->evbit); in magicmouse_setup_input()
612 if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE || in magicmouse_setup_input()
613 input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2) { in magicmouse_setup_input()
614 input_set_abs_params(input, ABS_MT_ORIENTATION, -31, 32, 1, 0); in magicmouse_setup_input()
624 } else if (input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2) { in magicmouse_setup_input()
627 input_set_abs_params(input, ABS_MT_ORIENTATION, -3, 4, 0, 0); in magicmouse_setup_input()
642 input_set_abs_params(input, ABS_MT_ORIENTATION, -31, 32, 1, 0); in magicmouse_setup_input()
663 input->id.product != USB_DEVICE_ID_APPLE_MAGICTRACKPAD2) { in magicmouse_setup_input()
664 __set_bit(EV_MSC, input->evbit); in magicmouse_setup_input()
665 __set_bit(MSC_RAW, input->mscbit); in magicmouse_setup_input()
669 * hid-input may mark device as using autorepeat, but neither in magicmouse_setup_input()
670 * the trackpad, nor the mouse actually want it. in magicmouse_setup_input()
672 __clear_bit(EV_REP, input->evbit); in magicmouse_setup_input()
683 if (!msc->input) in magicmouse_input_mapping()
684 msc->input = hi->input; in magicmouse_input_mapping()
686 /* Magic Trackpad does not give relative data after switching to MT */ in magicmouse_input_mapping()
687 if ((hi->input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD || in magicmouse_input_mapping()
688 hi->input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2) && in magicmouse_input_mapping()
689 field->flags & HID_MAIN_ITEM_RELATIVE) in magicmouse_input_mapping()
690 return -1; in magicmouse_input_mapping()
702 ret = magicmouse_setup_input(msc->input, hdev); in magicmouse_input_configured()
705 /* clean msc->input to notify probe() of the failure */ in magicmouse_input_configured()
706 msc->input = NULL; in magicmouse_input_configured()
724 if (hdev->product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2) { in magicmouse_enable_multitouch()
725 if (hdev->vendor == BT_VENDOR_ID_APPLE) { in magicmouse_enable_multitouch()
732 } else if (hdev->product == USB_DEVICE_ID_APPLE_MAGICMOUSE2) { in magicmouse_enable_multitouch()
742 return -ENOMEM; in magicmouse_enable_multitouch()
756 ret = magicmouse_enable_multitouch(msc->hdev); in magicmouse_enable_mt_work()
758 hid_err(msc->hdev, "unable to request touch data (%d)\n", ret); in magicmouse_enable_mt_work()
767 if (!hdev->battery || hdev->vendor != USB_VENDOR_ID_APPLE || in magicmouse_fetch_battery()
768 (hdev->product != USB_DEVICE_ID_APPLE_MAGICMOUSE2 && in magicmouse_fetch_battery()
769 hdev->product != USB_DEVICE_ID_APPLE_MAGICTRACKPAD2)) in magicmouse_fetch_battery()
770 return -1; in magicmouse_fetch_battery()
772 report_enum = &hdev->report_enum[hdev->battery_report_type]; in magicmouse_fetch_battery()
773 report = report_enum->report_id_hash[hdev->battery_report_id]; in magicmouse_fetch_battery()
775 if (!report || report->maxfield < 1) in magicmouse_fetch_battery()
776 return -1; in magicmouse_fetch_battery()
778 if (hdev->battery_capacity == hdev->battery_max) in magicmouse_fetch_battery()
779 return -1; in magicmouse_fetch_battery()
784 return -1; in magicmouse_fetch_battery()
791 struct hid_device *hdev = msc->hdev; in magicmouse_battery_timer_tick()
794 mod_timer(&msc->battery_timer, in magicmouse_battery_timer_tick()
806 msc = devm_kzalloc(&hdev->dev, sizeof(*msc), GFP_KERNEL); in magicmouse_probe()
809 return -ENOMEM; in magicmouse_probe()
812 msc->scroll_accel = SCROLL_ACCEL_DEFAULT; in magicmouse_probe()
813 msc->hdev = hdev; in magicmouse_probe()
814 INIT_DEFERRABLE_WORK(&msc->work, magicmouse_enable_mt_work); in magicmouse_probe()
816 msc->quirks = id->driver_data; in magicmouse_probe()
831 timer_setup(&msc->battery_timer, magicmouse_battery_timer_tick, 0); in magicmouse_probe()
832 mod_timer(&msc->battery_timer, in magicmouse_probe()
836 if (id->vendor == USB_VENDOR_ID_APPLE && in magicmouse_probe()
837 (id->product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 || in magicmouse_probe()
838 (id->product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 && hdev->type != HID_TYPE_USBMOUSE))) in magicmouse_probe()
841 if (!msc->input) { in magicmouse_probe()
843 ret = -ENOMEM; in magicmouse_probe()
847 if (id->product == USB_DEVICE_ID_APPLE_MAGICMOUSE) in magicmouse_probe()
850 else if (id->product == USB_DEVICE_ID_APPLE_MAGICMOUSE2) in magicmouse_probe()
853 else if (id->product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2) { in magicmouse_probe()
854 if (id->vendor == BT_VENDOR_ID_APPLE) in magicmouse_probe()
869 ret = -ENOMEM; in magicmouse_probe()
872 report->size = 6; in magicmouse_probe()
878 * This results in -EIO from the _raw low-level transport callback, in magicmouse_probe()
880 * Thus the super-ugly hacky success check below. in magicmouse_probe()
883 if (ret != -EIO && ret < 0) { in magicmouse_probe()
887 if (ret == -EIO && id->product == USB_DEVICE_ID_APPLE_MAGICMOUSE2) { in magicmouse_probe()
888 schedule_delayed_work(&msc->work, msecs_to_jiffies(500)); in magicmouse_probe()
893 del_timer_sync(&msc->battery_timer); in magicmouse_probe()
903 cancel_delayed_work_sync(&msc->work); in magicmouse_remove()
904 del_timer_sync(&msc->battery_timer); in magicmouse_remove()
916 * 0x09, 0x0b, // Usage (Vendor Usage 0x0b) 3 in magicmouse_report_fixup()
921 if (hdev->vendor == USB_VENDOR_ID_APPLE && in magicmouse_report_fixup()
922 (hdev->product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 || in magicmouse_report_fixup()
923 hdev->product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2) && in magicmouse_report_fixup()
927 *rsize = *rsize - 1; in magicmouse_report_fixup()
935 rdesc[3] = 0x02; in magicmouse_report_fixup()