Lines Matching +full:report +full:- +full:speed +full:- +full:hz
1 // SPDX-License-Identifier: GPL-2.0-or-later
21 #include "hid-ids.h"
27 static int middle_button_start = -350;
37 unsigned long speed; in param_set_scroll_speed() local
38 if (!val || kstrtoul(val, 0, &speed) || speed > 63) in param_set_scroll_speed()
39 return -EINVAL; in param_set_scroll_speed()
40 scroll_speed = speed; in param_set_scroll_speed()
44 MODULE_PARM_DESC(scroll_speed, "Scroll speed, value from 0 (slow) to 63 (fast)");
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.
116 * @input: Input device through which we report events.
118 * @ntouches: Number of touches in most recent touch report.
152 int touch = -1; in magicmouse_firm_touch()
158 for (ii = 0; ii < msc->ntouches; ii++) { in magicmouse_firm_touch()
159 int idx = msc->tracking_ids[ii]; in magicmouse_firm_touch()
160 if (msc->touches[idx].size < 8) { in magicmouse_firm_touch()
163 touch = -1; in magicmouse_firm_touch()
175 int last_state = test_bit(BTN_LEFT, msc->input->key) << 0 | in magicmouse_emit_buttons()
176 test_bit(BTN_RIGHT, msc->input->key) << 1 | in magicmouse_emit_buttons()
177 test_bit(BTN_MIDDLE, msc->input->key) << 2; in magicmouse_emit_buttons()
191 int x = msc->touches[id].x; in magicmouse_emit_buttons()
200 input_report_key(msc->input, BTN_MIDDLE, state & 4); in magicmouse_emit_buttons()
203 input_report_key(msc->input, BTN_LEFT, state & 1); in magicmouse_emit_buttons()
204 input_report_key(msc->input, BTN_RIGHT, state & 2); in magicmouse_emit_buttons()
207 msc->scroll_accel = SCROLL_ACCEL_DEFAULT; in magicmouse_emit_buttons()
212 struct input_dev *input = msc->input; in magicmouse_emit_touch()
216 if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE || in magicmouse_emit_touch()
217 input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2) { in magicmouse_emit_touch()
220 y = -((tdata[2] << 24 | tdata[1] << 16) >> 20); in magicmouse_emit_touch()
222 orientation = (tdata[6] >> 2) - 32; in magicmouse_emit_touch()
227 } else if (input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 || in magicmouse_emit_touch()
228 input->id.product == in magicmouse_emit_touch()
232 y = -((tdata[3] << 30 | tdata[2] << 22 | tdata[1] << 14) >> 19); in magicmouse_emit_touch()
234 orientation = (tdata[8] >> 5) - 4; in magicmouse_emit_touch()
243 y = -((tdata[3] << 30 | tdata[2] << 22 | tdata[1] << 14) >> 19); in magicmouse_emit_touch()
245 orientation = (tdata[7] >> 2) - 32; in magicmouse_emit_touch()
253 msc->tracking_ids[raw_id] = id; in magicmouse_emit_touch()
254 msc->touches[id].x = x; in magicmouse_emit_touch()
255 msc->touches[id].y = y; in magicmouse_emit_touch()
256 msc->touches[id].size = size; in magicmouse_emit_touch()
262 input->id.product != USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 && in magicmouse_emit_touch()
263 input->id.product != USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC) { 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()
362 if (input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 || in magicmouse_emit_touch()
363 input->id.product == in magicmouse_emit_touch()
368 if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE || in magicmouse_emit_touch()
369 input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2) in magicmouse_emit_touch()
371 else if (input->id.product != in magicmouse_emit_touch()
373 input->id.product != in magicmouse_emit_touch()
381 struct hid_report *report, u8 *data, int size) in magicmouse_raw_event() argument
384 struct input_dev *input = msc->input; in magicmouse_raw_event()
391 if (size < 4 || ((size - 4) % 9) != 0) in magicmouse_raw_event()
393 npoints = (size - 4) / 9; in magicmouse_raw_event()
399 msc->ntouches = 0; in magicmouse_raw_event()
413 if (size < 12 || ((size - 12) % 9) != 0) in magicmouse_raw_event()
415 npoints = (size - 12) / 9; in magicmouse_raw_event()
421 msc->ntouches = 0; in magicmouse_raw_event()
429 if (size < 6 || ((size - 6) % 8) != 0) in magicmouse_raw_event()
431 npoints = (size - 6) / 8; in magicmouse_raw_event()
437 msc->ntouches = 0; in magicmouse_raw_event()
441 /* When emulating three-button mode, it is important in magicmouse_raw_event()
457 if (size != 8 && (size < 14 || (size - 14) % 8 != 0)) in magicmouse_raw_event()
459 npoints = (size - 14) / 8; in magicmouse_raw_event()
465 msc->ntouches = 0; in magicmouse_raw_event()
469 /* When emulating three-button mode, it is important in magicmouse_raw_event()
487 magicmouse_raw_event(hdev, report, data + 2, data[1]); in magicmouse_raw_event()
488 magicmouse_raw_event(hdev, report, data + 2 + data[1], in magicmouse_raw_event()
489 size - 2 - data[1]); in magicmouse_raw_event()
495 if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE || in magicmouse_raw_event()
496 input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2) { in magicmouse_raw_event()
500 } else if (input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 || in magicmouse_raw_event()
501 input->id.product == in magicmouse_raw_event()
518 if (msc->input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 && in magicmouse_event()
519 field->report->id == MOUSE2_REPORT_ID) { in magicmouse_event()
536 __set_bit(EV_KEY, input->evbit); in magicmouse_setup_input()
538 if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE || in magicmouse_setup_input()
539 input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2) { in magicmouse_setup_input()
540 __set_bit(BTN_LEFT, input->keybit); in magicmouse_setup_input()
541 __set_bit(BTN_RIGHT, input->keybit); in magicmouse_setup_input()
543 __set_bit(BTN_MIDDLE, input->keybit); in magicmouse_setup_input()
545 __set_bit(EV_REL, input->evbit); in magicmouse_setup_input()
546 __set_bit(REL_X, input->relbit); in magicmouse_setup_input()
547 __set_bit(REL_Y, input->relbit); in magicmouse_setup_input()
549 __set_bit(REL_WHEEL, input->relbit); in magicmouse_setup_input()
550 __set_bit(REL_HWHEEL, input->relbit); in magicmouse_setup_input()
551 __set_bit(REL_WHEEL_HI_RES, input->relbit); in magicmouse_setup_input()
552 __set_bit(REL_HWHEEL_HI_RES, input->relbit); in magicmouse_setup_input()
554 } else if (input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 || in magicmouse_setup_input()
555 input->id.product == in magicmouse_setup_input()
565 if (hdev->vendor == BT_VENDOR_ID_APPLE) { in magicmouse_setup_input()
566 if (input->id.version == TRACKPAD2_2021_BT_VERSION) in magicmouse_setup_input()
567 input->name = "Apple Inc. Magic Trackpad"; in magicmouse_setup_input()
569 input->name = "Apple Inc. Magic Trackpad 2"; in magicmouse_setup_input()
571 input->name = hdev->name; in magicmouse_setup_input()
574 __clear_bit(EV_MSC, input->evbit); in magicmouse_setup_input()
575 __clear_bit(BTN_0, input->keybit); in magicmouse_setup_input()
576 __clear_bit(BTN_RIGHT, input->keybit); in magicmouse_setup_input()
577 __clear_bit(BTN_MIDDLE, input->keybit); in magicmouse_setup_input()
578 __set_bit(BTN_MOUSE, input->keybit); in magicmouse_setup_input()
579 __set_bit(INPUT_PROP_BUTTONPAD, input->propbit); in magicmouse_setup_input()
580 __set_bit(BTN_TOOL_FINGER, input->keybit); in magicmouse_setup_input()
585 /* input->keybit is initialized with incorrect button info in magicmouse_setup_input()
590 __clear_bit(BTN_RIGHT, input->keybit); in magicmouse_setup_input()
591 __clear_bit(BTN_MIDDLE, input->keybit); in magicmouse_setup_input()
592 __set_bit(BTN_MOUSE, input->keybit); in magicmouse_setup_input()
593 __set_bit(BTN_TOOL_FINGER, input->keybit); in magicmouse_setup_input()
594 __set_bit(BTN_TOOL_DOUBLETAP, input->keybit); in magicmouse_setup_input()
595 __set_bit(BTN_TOOL_TRIPLETAP, input->keybit); in magicmouse_setup_input()
596 __set_bit(BTN_TOOL_QUADTAP, input->keybit); in magicmouse_setup_input()
597 __set_bit(BTN_TOOL_QUINTTAP, input->keybit); in magicmouse_setup_input()
598 __set_bit(BTN_TOUCH, input->keybit); in magicmouse_setup_input()
599 __set_bit(INPUT_PROP_POINTER, input->propbit); in magicmouse_setup_input()
600 __set_bit(INPUT_PROP_BUTTONPAD, input->propbit); in magicmouse_setup_input()
604 __set_bit(EV_ABS, input->evbit); in magicmouse_setup_input()
620 if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE || in magicmouse_setup_input()
621 input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2) { in magicmouse_setup_input()
622 input_set_abs_params(input, ABS_MT_ORIENTATION, -31, 32, 1, 0); in magicmouse_setup_input()
632 } else if (input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 || in magicmouse_setup_input()
633 input->id.product == in magicmouse_setup_input()
637 input_set_abs_params(input, ABS_MT_ORIENTATION, -3, 4, 0, 0); in magicmouse_setup_input()
652 input_set_abs_params(input, ABS_MT_ORIENTATION, -31, 32, 1, 0); in magicmouse_setup_input()
673 input->id.product != USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 && in magicmouse_setup_input()
674 input->id.product != USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC) { in magicmouse_setup_input()
675 __set_bit(EV_MSC, input->evbit); in magicmouse_setup_input()
676 __set_bit(MSC_RAW, input->mscbit); in magicmouse_setup_input()
680 * hid-input may mark device as using autorepeat, but neither in magicmouse_setup_input()
683 __clear_bit(EV_REP, input->evbit); in magicmouse_setup_input()
694 if (!msc->input) in magicmouse_input_mapping()
695 msc->input = hi->input; in magicmouse_input_mapping()
698 if ((hi->input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD || in magicmouse_input_mapping()
699 hi->input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 || in magicmouse_input_mapping()
700 hi->input->id.product == in magicmouse_input_mapping()
702 field->flags & HID_MAIN_ITEM_RELATIVE) in magicmouse_input_mapping()
703 return -1; in magicmouse_input_mapping()
715 ret = magicmouse_setup_input(msc->input, hdev); in magicmouse_input_configured()
718 /* clean msc->input to notify probe() of the failure */ in magicmouse_input_configured()
719 msc->input = NULL; in magicmouse_input_configured()
737 if (hdev->product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 || in magicmouse_enable_multitouch()
738 hdev->product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC) { in magicmouse_enable_multitouch()
739 if (hdev->vendor == BT_VENDOR_ID_APPLE) { in magicmouse_enable_multitouch()
746 } else if (hdev->product == USB_DEVICE_ID_APPLE_MAGICMOUSE2) { in magicmouse_enable_multitouch()
756 return -ENOMEM; in magicmouse_enable_multitouch()
770 ret = magicmouse_enable_multitouch(msc->hdev); in magicmouse_enable_mt_work()
772 hid_err(msc->hdev, "unable to request touch data (%d)\n", ret); in magicmouse_enable_mt_work()
779 struct hid_report *report; in magicmouse_fetch_battery() local
781 if (!hdev->battery || hdev->vendor != USB_VENDOR_ID_APPLE || in magicmouse_fetch_battery()
782 (hdev->product != USB_DEVICE_ID_APPLE_MAGICMOUSE2 && in magicmouse_fetch_battery()
783 hdev->product != USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 && in magicmouse_fetch_battery()
784 hdev->product != USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC)) in magicmouse_fetch_battery()
785 return -1; in magicmouse_fetch_battery()
787 report_enum = &hdev->report_enum[hdev->battery_report_type]; in magicmouse_fetch_battery()
788 report = report_enum->report_id_hash[hdev->battery_report_id]; in magicmouse_fetch_battery()
790 if (!report || report->maxfield < 1) in magicmouse_fetch_battery()
791 return -1; in magicmouse_fetch_battery()
793 if (hdev->battery_capacity == hdev->battery_max) in magicmouse_fetch_battery()
794 return -1; in magicmouse_fetch_battery()
796 hid_hw_request(hdev, report, HID_REQ_GET_REPORT); in magicmouse_fetch_battery()
799 return -1; in magicmouse_fetch_battery()
806 struct hid_device *hdev = msc->hdev; in magicmouse_battery_timer_tick()
809 mod_timer(&msc->battery_timer, in magicmouse_battery_timer_tick()
818 struct hid_report *report; in magicmouse_probe() local
821 msc = devm_kzalloc(&hdev->dev, sizeof(*msc), GFP_KERNEL); in magicmouse_probe()
824 return -ENOMEM; in magicmouse_probe()
827 msc->scroll_accel = SCROLL_ACCEL_DEFAULT; in magicmouse_probe()
828 msc->hdev = hdev; in magicmouse_probe()
829 INIT_DEFERRABLE_WORK(&msc->work, magicmouse_enable_mt_work); in magicmouse_probe()
831 msc->quirks = id->driver_data; in magicmouse_probe()
846 timer_setup(&msc->battery_timer, magicmouse_battery_timer_tick, 0); in magicmouse_probe()
847 mod_timer(&msc->battery_timer, in magicmouse_probe()
851 if (id->vendor == USB_VENDOR_ID_APPLE && in magicmouse_probe()
852 (id->product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 || in magicmouse_probe()
853 ((id->product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 || in magicmouse_probe()
854 id->product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC) && in magicmouse_probe()
855 hdev->type != HID_TYPE_USBMOUSE))) in magicmouse_probe()
858 if (!msc->input) { in magicmouse_probe()
860 ret = -ENOMEM; in magicmouse_probe()
864 if (id->product == USB_DEVICE_ID_APPLE_MAGICMOUSE) in magicmouse_probe()
865 report = hid_register_report(hdev, HID_INPUT_REPORT, in magicmouse_probe()
867 else if (id->product == USB_DEVICE_ID_APPLE_MAGICMOUSE2) in magicmouse_probe()
868 report = hid_register_report(hdev, HID_INPUT_REPORT, in magicmouse_probe()
870 else if (id->product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 || in magicmouse_probe()
871 id->product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC) { in magicmouse_probe()
872 if (id->vendor == BT_VENDOR_ID_APPLE) in magicmouse_probe()
873 report = hid_register_report(hdev, HID_INPUT_REPORT, in magicmouse_probe()
876 report = hid_register_report(hdev, HID_INPUT_REPORT, in magicmouse_probe()
879 report = hid_register_report(hdev, HID_INPUT_REPORT, in magicmouse_probe()
881 report = hid_register_report(hdev, HID_INPUT_REPORT, in magicmouse_probe()
885 if (!report) { in magicmouse_probe()
886 hid_err(hdev, "unable to register touch report\n"); in magicmouse_probe()
887 ret = -ENOMEM; in magicmouse_probe()
890 report->size = 6; in magicmouse_probe()
893 * Some devices repond with 'invalid report id' when feature in magicmouse_probe()
894 * report switching it into multitouch mode is sent to it. in magicmouse_probe()
896 * This results in -EIO from the _raw low-level transport callback, in magicmouse_probe()
898 * Thus the super-ugly hacky success check below. in magicmouse_probe()
901 if (ret != -EIO && ret < 0) { in magicmouse_probe()
905 if (ret == -EIO && id->product == USB_DEVICE_ID_APPLE_MAGICMOUSE2) { in magicmouse_probe()
906 schedule_delayed_work(&msc->work, msecs_to_jiffies(500)); in magicmouse_probe()
911 del_timer_sync(&msc->battery_timer); in magicmouse_probe()
921 cancel_delayed_work_sync(&msc->work); in magicmouse_remove()
922 del_timer_sync(&msc->battery_timer); in magicmouse_remove()
939 if (hdev->vendor == USB_VENDOR_ID_APPLE && in magicmouse_report_fixup()
940 (hdev->product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 || in magicmouse_report_fixup()
941 hdev->product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 || in magicmouse_report_fixup()
942 hdev->product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC) && in magicmouse_report_fixup()
945 "fixing up magicmouse battery report descriptor\n"); in magicmouse_report_fixup()
946 *rsize = *rsize - 1; in magicmouse_report_fixup()