Lines Matching +full:button +full:- +full:191

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * HID driver for Asus notebook built-in keyboard.
12 * This module based on hid-ortek by
29 #include <linux/platform_data/x86/asus-wmi.h>
35 #include "hid-ids.h"
195 struct input_dev *input = drvdat->input; in asus_report_contact_down()
199 y = drvdat->tp->max_y - ((data[0] & CONTACT_Y_MSB_MASK) << 8 | data[2]); in asus_report_contact_down()
204 if (drvdat->tp->contact_size < 5) in asus_report_contact_down()
222 struct input_mt *mt = drvdat->input->mt; in asus_report_tool_width()
226 if (drvdat->tp->contact_size < 5) in asus_report_tool_width()
230 oldid = mt->trkid; in asus_report_tool_width()
232 for (i = 0; i < mt->num_slots; ++i) { in asus_report_tool_width()
233 struct input_mt_slot *ps = &mt->slots[i]; in asus_report_tool_width()
238 if ((id - oldid) & TRKID_SGN) { in asus_report_tool_width()
245 input_report_abs(drvdat->input, ABS_TOOL_WIDTH, in asus_report_tool_width()
255 if (size != drvdat->tp->report_size) in asus_report_input()
258 for (i = 0; i < drvdat->tp->max_contacts; i++) { in asus_report_input()
261 if (drvdat->tp->contact_size >= 5) in asus_report_input()
265 input_mt_slot(drvdat->input, i); in asus_report_input()
266 input_mt_report_slot_state(drvdat->input, toolType, down); in asus_report_input()
270 contactData += drvdat->tp->contact_size; in asus_report_input()
274 input_report_key(drvdat->input, BTN_LEFT, data[1] & BTN_LEFT_MASK); in asus_report_input()
277 input_mt_sync_frame(drvdat->input); in asus_report_input()
278 input_sync(drvdat->input); in asus_report_input()
289 if (!drvdat->tp && in asus_e1239t_event()
291 input_report_key(drvdat->input, KEY_MUTE, 1); in asus_e1239t_event()
292 input_sync(drvdat->input); in asus_e1239t_event()
293 input_report_key(drvdat->input, KEY_MUTE, 0); in asus_e1239t_event()
294 input_sync(drvdat->input); in asus_e1239t_event()
299 if (drvdat->tp_kbd_input && in asus_e1239t_event()
301 input_report_key(drvdat->tp_kbd_input, KEY_F21, 1); in asus_e1239t_event()
302 input_sync(drvdat->tp_kbd_input); in asus_e1239t_event()
303 input_report_key(drvdat->tp_kbd_input, KEY_F21, 0); in asus_e1239t_event()
304 input_sync(drvdat->tp_kbd_input); in asus_e1239t_event()
314 if ((usage->hid & HID_USAGE_PAGE) == 0xff310000 && in asus_event()
315 (usage->hid & HID_USAGE) != 0x00 && in asus_event()
316 (usage->hid & HID_USAGE) != 0xff && !usage->type) { in asus_event()
318 usage->hid & HID_USAGE); in asus_event()
329 if (drvdata->battery && data[0] == BATTERY_REPORT_ID) in asus_raw_event()
332 if (drvdata->tp && data[0] == INPUT_REPORT_ID) in asus_raw_event()
335 if (drvdata->quirks & QUIRK_MEDION_E1239T) in asus_raw_event()
342 if (report->id == FEATURE_KBD_LED_REPORT_ID1 || report->id == FEATURE_KBD_LED_REPORT_ID2) in asus_raw_event()
343 return -1; in asus_raw_event()
344 if (drvdata->quirks & QUIRK_ROG_NKEY_KEYBOARD) { in asus_raw_event()
350 return -1; in asus_raw_event()
354 if (drvdata->quirks & QUIRK_ROG_CLAYMORE_II_KEYBOARD) { in asus_raw_event()
361 return -1; in asus_raw_event()
375 return -ENOMEM; in asus_kbd_set_report()
418 return -ENOMEM; in asus_kbd_get_functions()
439 spin_lock_irqsave(&led->lock, flags); in asus_schedule_work()
440 if (!led->removed) in asus_schedule_work()
441 schedule_work(&led->work); in asus_schedule_work()
442 spin_unlock_irqrestore(&led->lock, flags); in asus_schedule_work()
452 spin_lock_irqsave(&led->lock, flags); in asus_kbd_backlight_set()
453 led->brightness = brightness; in asus_kbd_backlight_set()
454 spin_unlock_irqrestore(&led->lock, flags); in asus_kbd_backlight_set()
466 spin_lock_irqsave(&led->lock, flags); in asus_kbd_backlight_get()
467 brightness = led->brightness; in asus_kbd_backlight_get()
468 spin_unlock_irqrestore(&led->lock, flags); in asus_kbd_backlight_get()
480 spin_lock_irqsave(&led->lock, flags); in asus_kbd_backlight_work()
481 buf[4] = led->brightness; in asus_kbd_backlight_work()
482 spin_unlock_irqrestore(&led->lock, flags); in asus_kbd_backlight_work()
484 ret = asus_kbd_set_report(led->hdev, buf, sizeof(buf)); in asus_kbd_backlight_work()
486 hid_err(led->hdev, "Asus failed to set keyboard backlight: %d\n", ret); in asus_kbd_backlight_work()
489 /* WMI-based keyboard backlight LED control (via asus-wmi driver) takes
490 * precedence. We only activate HID-based backlight control when the
502 if (drvdata->quirks & QUIRK_ROG_NKEY_KEYBOARD && in asus_kbd_wmi_led_control_present()
523 if (drvdata->quirks & QUIRK_ROG_NKEY_KEYBOARD) { in asus_kbd_register_leds()
550 return -ENODEV; in asus_kbd_register_leds()
553 drvdata->kbd_backlight = devm_kzalloc(&hdev->dev, in asus_kbd_register_leds()
556 if (!drvdata->kbd_backlight) in asus_kbd_register_leds()
557 return -ENOMEM; in asus_kbd_register_leds()
559 drvdata->kbd_backlight->removed = false; in asus_kbd_register_leds()
560 drvdata->kbd_backlight->brightness = 0; in asus_kbd_register_leds()
561 drvdata->kbd_backlight->hdev = hdev; in asus_kbd_register_leds()
562 drvdata->kbd_backlight->cdev.name = "asus::kbd_backlight"; in asus_kbd_register_leds()
563 drvdata->kbd_backlight->cdev.max_brightness = 3; in asus_kbd_register_leds()
564 drvdata->kbd_backlight->cdev.brightness_set = asus_kbd_backlight_set; in asus_kbd_register_leds()
565 drvdata->kbd_backlight->cdev.brightness_get = asus_kbd_backlight_get; in asus_kbd_register_leds()
566 INIT_WORK(&drvdata->kbd_backlight->work, asus_kbd_backlight_work); in asus_kbd_register_leds()
567 spin_lock_init(&drvdata->kbd_backlight->lock); in asus_kbd_register_leds()
569 ret = devm_led_classdev_register(&hdev->dev, &drvdata->kbd_backlight->cdev); in asus_kbd_register_leds()
572 devm_kfree(&hdev->dev, drvdata->kbd_backlight); in asus_kbd_register_leds()
596 drvdata->battery_capacity = ((int)lvl * 100) / (int)BATTERY_LEVEL_MAX; in asus_parse_battery()
610 drvdata->battery_stat = val; in asus_parse_battery()
618 if ((drvdata->battery_in_query == false) && in asus_report_battery()
620 power_supply_changed(drvdata->battery); in asus_report_battery()
632 return -ENOMEM; in asus_battery_query()
634 drvdata->battery_in_query = true; in asus_battery_query()
635 ret = hid_hw_raw_request(drvdata->hdev, BATTERY_REPORT_ID, in asus_battery_query()
638 drvdata->battery_in_query = false; in asus_battery_query()
642 ret = -ENODATA; in asus_battery_query()
669 if (time_before(drvdata->battery_next_query, jiffies)) { in asus_battery_get_property()
670 drvdata->battery_next_query = in asus_battery_get_property()
677 val->intval = drvdata->battery_stat; in asus_battery_get_property()
679 val->intval = drvdata->battery_capacity; in asus_battery_get_property()
682 val->intval = 1; in asus_battery_get_property()
685 val->intval = POWER_SUPPLY_SCOPE_DEVICE; in asus_battery_get_property()
688 val->strval = drvdata->hdev->name; in asus_battery_get_property()
691 ret = -EINVAL; in asus_battery_get_property()
704 drvdata->battery_capacity = 0; in asus_battery_probe()
705 drvdata->battery_stat = POWER_SUPPLY_STATUS_UNKNOWN; in asus_battery_probe()
706 drvdata->battery_in_query = false; in asus_battery_probe()
708 drvdata->battery_desc.properties = asus_battery_props; in asus_battery_probe()
709 drvdata->battery_desc.num_properties = ARRAY_SIZE(asus_battery_props); in asus_battery_probe()
710 drvdata->battery_desc.get_property = asus_battery_get_property; in asus_battery_probe()
711 drvdata->battery_desc.type = POWER_SUPPLY_TYPE_BATTERY; in asus_battery_probe()
712 drvdata->battery_desc.use_for_apm = 0; in asus_battery_probe()
713 drvdata->battery_desc.name = devm_kasprintf(&hdev->dev, GFP_KERNEL, in asus_battery_probe()
714 "asus-keyboard-%s-battery", in asus_battery_probe()
715 strlen(hdev->uniq) ? in asus_battery_probe()
716 hdev->uniq : dev_name(&hdev->dev)); in asus_battery_probe()
717 if (!drvdata->battery_desc.name) in asus_battery_probe()
718 return -ENOMEM; in asus_battery_probe()
720 drvdata->battery_next_query = jiffies; in asus_battery_probe()
722 drvdata->battery = devm_power_supply_register(&hdev->dev, in asus_battery_probe()
723 &(drvdata->battery_desc), &pscfg); in asus_battery_probe()
724 if (IS_ERR(drvdata->battery)) { in asus_battery_probe()
725 ret = PTR_ERR(drvdata->battery); in asus_battery_probe()
726 drvdata->battery = NULL; in asus_battery_probe()
731 power_supply_powers(drvdata->battery, &hdev->dev); in asus_battery_probe()
738 struct input_dev *input = hi->input; in asus_input_configured()
742 if (drvdata->quirks & QUIRK_T100CHI && in asus_input_configured()
743 hi->report->id != T100CHI_MOUSE_REPORT_ID) in asus_input_configured()
747 if (drvdata->tp && (drvdata->quirks & QUIRK_MEDION_E1239T)) { in asus_input_configured()
748 switch (hi->report->id) { in asus_input_configured()
751 input->name = "Asus Touchpad Keys"; in asus_input_configured()
752 drvdata->tp_kbd_input = input; in asus_input_configured()
761 if (drvdata->tp) { in asus_input_configured()
765 drvdata->tp->max_x, 0, 0); in asus_input_configured()
767 drvdata->tp->max_y, 0, 0); in asus_input_configured()
768 input_abs_set_res(input, ABS_MT_POSITION_X, drvdata->tp->res_x); in asus_input_configured()
769 input_abs_set_res(input, ABS_MT_POSITION_Y, drvdata->tp->res_y); in asus_input_configured()
771 if (drvdata->tp->contact_size >= 5) { in asus_input_configured()
780 __set_bit(BTN_LEFT, input->keybit); in asus_input_configured()
781 __set_bit(INPUT_PROP_BUTTONPAD, input->propbit); in asus_input_configured()
783 ret = input_mt_init_slots(input, drvdata->tp->max_contacts, in asus_input_configured()
792 drvdata->input = input; in asus_input_configured()
794 if (drvdata->enable_backlight && in asus_input_configured()
811 if (drvdata->quirks & QUIRK_SKIP_INPUT_MAPPING) { in asus_input_mapping()
815 return -1; in asus_input_mapping()
820 * This avoids a bunch of non-functional hid_input devices getting in asus_input_mapping()
823 if ((drvdata->quirks & (QUIRK_T100CHI | QUIRK_T90CHI)) && in asus_input_mapping()
824 (field->application == (HID_UP_GENDESK | 0x0080) || in asus_input_mapping()
825 field->application == HID_GD_MOUSE || in asus_input_mapping()
826 usage->hid == (HID_UP_GENDEVCTRLS | 0x0024) || in asus_input_mapping()
827 usage->hid == (HID_UP_GENDEVCTRLS | 0x0025) || in asus_input_mapping()
828 usage->hid == (HID_UP_GENDEVCTRLS | 0x0026))) in asus_input_mapping()
829 return -1; in asus_input_mapping()
831 /* ASUS-specific keyboard hotkeys and led backlight */ in asus_input_mapping()
832 if ((usage->hid & HID_USAGE_PAGE) == HID_UP_ASUSVENDOR) { in asus_input_mapping()
833 switch (usage->hid & HID_USAGE) { in asus_input_mapping()
856 case 0x4b: asus_map_key_clear(KEY_F14); break; /* Arrows/Pg-Up/Dn toggle */ in asus_input_mapping()
858 case 0xa6: asus_map_key_clear(KEY_F16); break; /* ROG Ally QAM button */ in asus_input_mapping()
859 case 0xa7: asus_map_key_clear(KEY_F17); break; /* ROG Ally ROG long-press */ in asus_input_mapping()
860 case 0xa8: asus_map_key_clear(KEY_F18); break; /* ROG Ally ROG long-press-release */ in asus_input_mapping()
865 return -1; in asus_input_mapping()
874 if (drvdata->quirks & QUIRK_USE_KBD_BACKLIGHT) in asus_input_mapping()
875 drvdata->enable_backlight = true; in asus_input_mapping()
877 set_bit(EV_REP, hi->input->evbit); in asus_input_mapping()
881 if ((usage->hid & HID_USAGE_PAGE) == HID_UP_MSVENDOR) { in asus_input_mapping()
882 switch (usage->hid & HID_USAGE) { in asus_input_mapping()
904 set_bit(EV_REP, hi->input->evbit); in asus_input_mapping()
908 if (drvdata->quirks & QUIRK_NO_CONSUMER_USAGES && in asus_input_mapping()
909 (usage->hid & HID_USAGE_PAGE) == HID_UP_CONSUMER) { in asus_input_mapping()
910 switch (usage->hid & HID_USAGE) { in asus_input_mapping()
919 return -1; in asus_input_mapping()
924 * The mute button is broken and only sends press events, we in asus_input_mapping()
927 if ((drvdata->quirks & QUIRK_MEDION_E1239T) && in asus_input_mapping()
928 usage->hid == (HID_UP_CONSUMER | 0xe2)) { in asus_input_mapping()
929 input_set_capability(hi->input, EV_KEY, KEY_MUTE); in asus_input_mapping()
930 return -1; in asus_input_mapping()
945 ret = -ENOMEM; in asus_start_multitouch()
967 if (drvdata->kbd_backlight) { in asus_resume()
969 drvdata->kbd_backlight->cdev.brightness }; in asus_resume()
985 if (drvdata->tp) in asus_reset_resume()
996 drvdata = devm_kzalloc(&hdev->dev, sizeof(*drvdata), GFP_KERNEL); in asus_probe()
999 return -ENOMEM; in asus_probe()
1004 drvdata->quirks = id->driver_data; in asus_probe()
1010 if (strstr(hdev->name, "T90CHI")) { in asus_probe()
1011 drvdata->quirks &= ~QUIRK_T100CHI; in asus_probe()
1012 drvdata->quirks |= QUIRK_T90CHI; in asus_probe()
1015 if (drvdata->quirks & QUIRK_IS_MULTITOUCH) in asus_probe()
1016 drvdata->tp = &asus_i2c_tp; in asus_probe()
1018 if ((drvdata->quirks & QUIRK_T100_KEYBOARD) && hid_is_usb(hdev)) { in asus_probe()
1019 struct usb_interface *intf = to_usb_interface(hdev->dev.parent); in asus_probe()
1021 if (intf->altsetting->desc.bInterfaceNumber == T100_TPAD_INTF) { in asus_probe()
1022 drvdata->quirks = QUIRK_SKIP_INPUT_MAPPING; in asus_probe()
1024 * The T100HA uses the same USB-ids as the T100TAF and in asus_probe()
1025 * the T200TA uses the same USB-ids as the T100TA, while in asus_probe()
1029 drvdata->tp = &asus_t100ha_tp; in asus_probe()
1031 drvdata->tp = &asus_t200ta_tp; in asus_probe()
1033 drvdata->tp = &asus_t100ta_tp; in asus_probe()
1037 if (drvdata->quirks & QUIRK_T100CHI) { in asus_probe()
1042 hdev->quirks |= HID_QUIRK_MULTI_INPUT; in asus_probe()
1043 drvdata->tp = &asus_t100chi_tp; in asus_probe()
1046 if ((drvdata->quirks & QUIRK_MEDION_E1239T) && hid_is_usb(hdev)) { in asus_probe()
1048 to_usb_interface(hdev->dev.parent)->altsetting; in asus_probe()
1050 if (alt->desc.bInterfaceNumber == MEDION_E1239T_TPAD_INTF) { in asus_probe()
1051 /* For separate input-devs for tp and tp toggle key */ in asus_probe()
1052 hdev->quirks |= HID_QUIRK_MULTI_INPUT; in asus_probe()
1053 drvdata->quirks |= QUIRK_SKIP_INPUT_MAPPING; in asus_probe()
1054 drvdata->tp = &medion_e1239t_tp; in asus_probe()
1058 if (drvdata->quirks & QUIRK_NO_INIT_REPORTS) in asus_probe()
1059 hdev->quirks |= HID_QUIRK_NO_INIT_REPORTS; in asus_probe()
1061 drvdata->hdev = hdev; in asus_probe()
1063 if (drvdata->quirks & (QUIRK_T100CHI | QUIRK_T90CHI)) { in asus_probe()
1084 if (!drvdata->input) { in asus_probe()
1086 ret = -ENOMEM; in asus_probe()
1090 if (drvdata->tp) { in asus_probe()
1091 drvdata->input->name = "Asus TouchPad"; in asus_probe()
1093 drvdata->input->name = "Asus Keyboard"; in asus_probe()
1096 if (drvdata->tp) { in asus_probe()
1113 if (drvdata->kbd_backlight) { in asus_remove()
1114 spin_lock_irqsave(&drvdata->kbd_backlight->lock, flags); in asus_remove()
1115 drvdata->kbd_backlight->removed = true; in asus_remove()
1116 spin_unlock_irqrestore(&drvdata->kbd_backlight->lock, flags); in asus_remove()
1118 cancel_work_sync(&drvdata->kbd_backlight->work); in asus_remove()
1134 if (drvdata->quirks & QUIRK_FIX_NOTEBOOK_REPORT && in asus_report_fixup()
1140 if (drvdata->quirks & QUIRK_T100_KEYBOARD && in asus_report_fixup()
1147 if (drvdata->quirks & (QUIRK_T100CHI | QUIRK_T90CHI)) { in asus_report_fixup()
1151 if (drvdata->quirks & QUIRK_T100CHI) { in asus_report_fixup()
1173 drvdata->quirks & QUIRK_T100CHI ? in asus_report_fixup()
1184 if (drvdata->quirks & QUIRK_G752_KEYBOARD && in asus_report_fixup()
1190 new_rdesc = devm_kzalloc(&hdev->dev, new_size, GFP_KERNEL); in asus_report_fixup()
1200 memcpy(new_rdesc + 61 + sizeof(asus_g752_fixed_rdesc), rdesc + 61, *rsize - 61); in asus_report_fixup()
1206 if (drvdata->quirks & QUIRK_ROG_NKEY_KEYBOARD && in asus_report_fixup()
1207 *rsize == 331 && rdesc[190] == 0x85 && rdesc[191] == 0x5a && in asus_report_fixup()
1209 hid_info(hdev, "Fixing up Asus N-KEY keyb report descriptor\n"); in asus_report_fixup()
1213 /* match many more n-key devices */ in asus_report_fixup()
1214 if (drvdata->quirks & QUIRK_ROG_NKEY_KEYBOARD && *rsize > 15) { in asus_report_fixup()
1215 for (int i = 0; i < *rsize - 15; i++) { in asus_report_fixup()
1219 hid_info(hdev, "Fixing up Asus N-Key report descriptor\n"); in asus_report_fixup()
1279 * part, while letting hid-multitouch.c handle the touchpad.