12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later 2fcfacfd3SJiri Slaby /* 3fcfacfd3SJiri Slaby * HID driver for some chicony "special" devices 4fcfacfd3SJiri Slaby * 5fcfacfd3SJiri Slaby * Copyright (c) 1999 Andreas Gal 6fcfacfd3SJiri Slaby * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> 7fcfacfd3SJiri Slaby * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc 8fcfacfd3SJiri Slaby * Copyright (c) 2006-2007 Jiri Kosina 9fcfacfd3SJiri Slaby * Copyright (c) 2007 Paul Walmsley 10fcfacfd3SJiri Slaby * Copyright (c) 2008 Jiri Slaby 11fcfacfd3SJiri Slaby */ 12fcfacfd3SJiri Slaby 13fcfacfd3SJiri Slaby /* 14fcfacfd3SJiri Slaby */ 15fcfacfd3SJiri Slaby 16fcfacfd3SJiri Slaby #include <linux/device.h> 17fcfacfd3SJiri Slaby #include <linux/input.h> 18fcfacfd3SJiri Slaby #include <linux/hid.h> 19fcfacfd3SJiri Slaby #include <linux/module.h> 209a1d78a3SНиколай Кудрявцев #include <linux/usb.h> 21fcfacfd3SJiri Slaby 22fcfacfd3SJiri Slaby #include "hid-ids.h" 23fcfacfd3SJiri Slaby 24*859b510bSJian-Hong Pan #define CH_WIRELESS_CTL_REPORT_ID 0x11 25*859b510bSJian-Hong Pan 26*859b510bSJian-Hong Pan static int ch_report_wireless(struct hid_report *report, u8 *data, int size) 27*859b510bSJian-Hong Pan { 28*859b510bSJian-Hong Pan struct hid_device *hdev = report->device; 29*859b510bSJian-Hong Pan struct input_dev *input; 30*859b510bSJian-Hong Pan 31*859b510bSJian-Hong Pan if (report->id != CH_WIRELESS_CTL_REPORT_ID || report->maxfield != 1) 32*859b510bSJian-Hong Pan return 0; 33*859b510bSJian-Hong Pan 34*859b510bSJian-Hong Pan input = report->field[0]->hidinput->input; 35*859b510bSJian-Hong Pan if (!input) { 36*859b510bSJian-Hong Pan hid_warn(hdev, "can't find wireless radio control's input"); 37*859b510bSJian-Hong Pan return 0; 38*859b510bSJian-Hong Pan } 39*859b510bSJian-Hong Pan 40*859b510bSJian-Hong Pan input_report_key(input, KEY_RFKILL, 1); 41*859b510bSJian-Hong Pan input_sync(input); 42*859b510bSJian-Hong Pan input_report_key(input, KEY_RFKILL, 0); 43*859b510bSJian-Hong Pan input_sync(input); 44*859b510bSJian-Hong Pan 45*859b510bSJian-Hong Pan return 1; 46*859b510bSJian-Hong Pan } 47*859b510bSJian-Hong Pan 48*859b510bSJian-Hong Pan static int ch_raw_event(struct hid_device *hdev, 49*859b510bSJian-Hong Pan struct hid_report *report, u8 *data, int size) 50*859b510bSJian-Hong Pan { 51*859b510bSJian-Hong Pan if (report->application == HID_GD_WIRELESS_RADIO_CTLS) 52*859b510bSJian-Hong Pan return ch_report_wireless(report, data, size); 53*859b510bSJian-Hong Pan 54*859b510bSJian-Hong Pan return 0; 55*859b510bSJian-Hong Pan } 56*859b510bSJian-Hong Pan 57fcfacfd3SJiri Slaby #define ch_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \ 58fcfacfd3SJiri Slaby EV_KEY, (c)) 59fcfacfd3SJiri Slaby static int ch_input_mapping(struct hid_device *hdev, struct hid_input *hi, 60fcfacfd3SJiri Slaby struct hid_field *field, struct hid_usage *usage, 61fcfacfd3SJiri Slaby unsigned long **bit, int *max) 62fcfacfd3SJiri Slaby { 63fcfacfd3SJiri Slaby if ((usage->hid & HID_USAGE_PAGE) != HID_UP_MSVENDOR) 64fcfacfd3SJiri Slaby return 0; 65fcfacfd3SJiri Slaby 66fcfacfd3SJiri Slaby set_bit(EV_REP, hi->input->evbit); 67fcfacfd3SJiri Slaby switch (usage->hid & HID_USAGE) { 68fcfacfd3SJiri Slaby case 0xff01: ch_map_key_clear(BTN_1); break; 69fcfacfd3SJiri Slaby case 0xff02: ch_map_key_clear(BTN_2); break; 70fcfacfd3SJiri Slaby case 0xff03: ch_map_key_clear(BTN_3); break; 71fcfacfd3SJiri Slaby case 0xff04: ch_map_key_clear(BTN_4); break; 72fcfacfd3SJiri Slaby case 0xff05: ch_map_key_clear(BTN_5); break; 73fcfacfd3SJiri Slaby case 0xff06: ch_map_key_clear(BTN_6); break; 74fcfacfd3SJiri Slaby case 0xff07: ch_map_key_clear(BTN_7); break; 75fcfacfd3SJiri Slaby case 0xff08: ch_map_key_clear(BTN_8); break; 76fcfacfd3SJiri Slaby case 0xff09: ch_map_key_clear(BTN_9); break; 77fcfacfd3SJiri Slaby case 0xff0a: ch_map_key_clear(BTN_A); break; 78fcfacfd3SJiri Slaby case 0xff0b: ch_map_key_clear(BTN_B); break; 793596bb92SKeng-Yu Lin case 0x00f1: ch_map_key_clear(KEY_WLAN); break; 803596bb92SKeng-Yu Lin case 0x00f2: ch_map_key_clear(KEY_BRIGHTNESSDOWN); break; 813596bb92SKeng-Yu Lin case 0x00f3: ch_map_key_clear(KEY_BRIGHTNESSUP); break; 823596bb92SKeng-Yu Lin case 0x00f4: ch_map_key_clear(KEY_DISPLAY_OFF); break; 836c30d5a5SKeng-Yu Lin case 0x00f7: ch_map_key_clear(KEY_CAMERA); break; 846c30d5a5SKeng-Yu Lin case 0x00f8: ch_map_key_clear(KEY_PROG1); break; 85fcfacfd3SJiri Slaby default: 86fcfacfd3SJiri Slaby return 0; 87fcfacfd3SJiri Slaby } 88fcfacfd3SJiri Slaby return 1; 89fcfacfd3SJiri Slaby } 90fcfacfd3SJiri Slaby 919a1d78a3SНиколай Кудрявцев static __u8 *ch_switch12_report_fixup(struct hid_device *hdev, __u8 *rdesc, 929a1d78a3SНиколай Кудрявцев unsigned int *rsize) 939a1d78a3SНиколай Кудрявцев { 949a1d78a3SНиколай Кудрявцев struct usb_interface *intf = to_usb_interface(hdev->dev.parent); 959a1d78a3SНиколай Кудрявцев 969a1d78a3SНиколай Кудрявцев if (intf->cur_altsetting->desc.bInterfaceNumber == 1) { 979a1d78a3SНиколай Кудрявцев /* Change usage maximum and logical maximum from 0x7fff to 989a1d78a3SНиколай Кудрявцев * 0x2fff, so they don't exceed HID_MAX_USAGES */ 999a1d78a3SНиколай Кудрявцев switch (hdev->product) { 1009a1d78a3SНиколай Кудрявцев case USB_DEVICE_ID_CHICONY_ACER_SWITCH12: 1019a1d78a3SНиколай Кудрявцев if (*rsize >= 128 && rdesc[64] == 0xff && rdesc[65] == 0x7f 1029a1d78a3SНиколай Кудрявцев && rdesc[69] == 0xff && rdesc[70] == 0x7f) { 1039a1d78a3SНиколай Кудрявцев hid_info(hdev, "Fixing up report descriptor\n"); 1049a1d78a3SНиколай Кудрявцев rdesc[65] = rdesc[70] = 0x2f; 1059a1d78a3SНиколай Кудрявцев } 1069a1d78a3SНиколай Кудрявцев break; 1079a1d78a3SНиколай Кудрявцев } 1089a1d78a3SНиколай Кудрявцев 1099a1d78a3SНиколай Кудрявцев } 1109a1d78a3SНиколай Кудрявцев return rdesc; 1119a1d78a3SНиколай Кудрявцев } 1129a1d78a3SНиколай Кудрявцев 113*859b510bSJian-Hong Pan static int ch_probe(struct hid_device *hdev, const struct hid_device_id *id) 114*859b510bSJian-Hong Pan { 115*859b510bSJian-Hong Pan int ret; 116*859b510bSJian-Hong Pan 117*859b510bSJian-Hong Pan hdev->quirks |= HID_QUIRK_INPUT_PER_APP; 118*859b510bSJian-Hong Pan ret = hid_parse(hdev); 119*859b510bSJian-Hong Pan if (ret) { 120*859b510bSJian-Hong Pan hid_err(hdev, "Chicony hid parse failed: %d\n", ret); 121*859b510bSJian-Hong Pan return ret; 122*859b510bSJian-Hong Pan } 123*859b510bSJian-Hong Pan 124*859b510bSJian-Hong Pan ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); 125*859b510bSJian-Hong Pan if (ret) { 126*859b510bSJian-Hong Pan hid_err(hdev, "Chicony hw start failed: %d\n", ret); 127*859b510bSJian-Hong Pan return ret; 128*859b510bSJian-Hong Pan } 129*859b510bSJian-Hong Pan 130*859b510bSJian-Hong Pan return 0; 131*859b510bSJian-Hong Pan } 1329a1d78a3SНиколай Кудрявцев 133fcfacfd3SJiri Slaby static const struct hid_device_id ch_devices[] = { 134fcfacfd3SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_TACTICAL_PAD) }, 1353596bb92SKeng-Yu Lin { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS2) }, 136*859b510bSJian-Hong Pan { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS3) }, 1379a1d78a3SНиколай Кудрявцев { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_ACER_SWITCH12) }, 138fcfacfd3SJiri Slaby { } 139fcfacfd3SJiri Slaby }; 140fcfacfd3SJiri Slaby MODULE_DEVICE_TABLE(hid, ch_devices); 141fcfacfd3SJiri Slaby 142fcfacfd3SJiri Slaby static struct hid_driver ch_driver = { 143fcfacfd3SJiri Slaby .name = "chicony", 144fcfacfd3SJiri Slaby .id_table = ch_devices, 1459a1d78a3SНиколай Кудрявцев .report_fixup = ch_switch12_report_fixup, 146fcfacfd3SJiri Slaby .input_mapping = ch_input_mapping, 147*859b510bSJian-Hong Pan .probe = ch_probe, 148*859b510bSJian-Hong Pan .raw_event = ch_raw_event, 149fcfacfd3SJiri Slaby }; 150f425458eSH Hartley Sweeten module_hid_driver(ch_driver); 151fcfacfd3SJiri Slaby 152fcfacfd3SJiri Slaby MODULE_LICENSE("GPL"); 153