Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Jiri Slaby | fcfacfd | 2008-06-24 22:48:52 +0200 | [diff] [blame] | 2 | /* |
| 3 | * HID driver for some chicony "special" devices |
| 4 | * |
| 5 | * Copyright (c) 1999 Andreas Gal |
| 6 | * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> |
| 7 | * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc |
| 8 | * Copyright (c) 2006-2007 Jiri Kosina |
| 9 | * Copyright (c) 2007 Paul Walmsley |
| 10 | * Copyright (c) 2008 Jiri Slaby |
| 11 | */ |
| 12 | |
| 13 | /* |
Jiri Slaby | fcfacfd | 2008-06-24 22:48:52 +0200 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <linux/device.h> |
| 17 | #include <linux/input.h> |
| 18 | #include <linux/hid.h> |
| 19 | #include <linux/module.h> |
Николай Кудрявцев | 9a1d78a | 2015-07-21 13:31:52 +0300 | [diff] [blame] | 20 | #include <linux/usb.h> |
Jiri Slaby | fcfacfd | 2008-06-24 22:48:52 +0200 | [diff] [blame] | 21 | |
| 22 | #include "hid-ids.h" |
| 23 | |
Jian-Hong Pan | 859b510 | 2020-12-23 13:55:41 +0800 | [diff] [blame] | 24 | #define CH_WIRELESS_CTL_REPORT_ID 0x11 |
| 25 | |
| 26 | static int ch_report_wireless(struct hid_report *report, u8 *data, int size) |
| 27 | { |
| 28 | struct hid_device *hdev = report->device; |
| 29 | struct input_dev *input; |
| 30 | |
| 31 | if (report->id != CH_WIRELESS_CTL_REPORT_ID || report->maxfield != 1) |
| 32 | return 0; |
| 33 | |
| 34 | input = report->field[0]->hidinput->input; |
| 35 | if (!input) { |
| 36 | hid_warn(hdev, "can't find wireless radio control's input"); |
| 37 | return 0; |
| 38 | } |
| 39 | |
| 40 | input_report_key(input, KEY_RFKILL, 1); |
| 41 | input_sync(input); |
| 42 | input_report_key(input, KEY_RFKILL, 0); |
| 43 | input_sync(input); |
| 44 | |
| 45 | return 1; |
| 46 | } |
| 47 | |
| 48 | static int ch_raw_event(struct hid_device *hdev, |
| 49 | struct hid_report *report, u8 *data, int size) |
| 50 | { |
| 51 | if (report->application == HID_GD_WIRELESS_RADIO_CTLS) |
| 52 | return ch_report_wireless(report, data, size); |
| 53 | |
| 54 | return 0; |
| 55 | } |
| 56 | |
Jiri Slaby | fcfacfd | 2008-06-24 22:48:52 +0200 | [diff] [blame] | 57 | #define ch_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \ |
| 58 | EV_KEY, (c)) |
| 59 | static int ch_input_mapping(struct hid_device *hdev, struct hid_input *hi, |
| 60 | struct hid_field *field, struct hid_usage *usage, |
| 61 | unsigned long **bit, int *max) |
| 62 | { |
| 63 | if ((usage->hid & HID_USAGE_PAGE) != HID_UP_MSVENDOR) |
| 64 | return 0; |
| 65 | |
| 66 | set_bit(EV_REP, hi->input->evbit); |
| 67 | switch (usage->hid & HID_USAGE) { |
| 68 | case 0xff01: ch_map_key_clear(BTN_1); break; |
| 69 | case 0xff02: ch_map_key_clear(BTN_2); break; |
| 70 | case 0xff03: ch_map_key_clear(BTN_3); break; |
| 71 | case 0xff04: ch_map_key_clear(BTN_4); break; |
| 72 | case 0xff05: ch_map_key_clear(BTN_5); break; |
| 73 | case 0xff06: ch_map_key_clear(BTN_6); break; |
| 74 | case 0xff07: ch_map_key_clear(BTN_7); break; |
| 75 | case 0xff08: ch_map_key_clear(BTN_8); break; |
| 76 | case 0xff09: ch_map_key_clear(BTN_9); break; |
| 77 | case 0xff0a: ch_map_key_clear(BTN_A); break; |
| 78 | case 0xff0b: ch_map_key_clear(BTN_B); break; |
Keng-Yu Lin | 3596bb9 | 2012-02-02 10:31:26 +0100 | [diff] [blame] | 79 | case 0x00f1: ch_map_key_clear(KEY_WLAN); break; |
| 80 | case 0x00f2: ch_map_key_clear(KEY_BRIGHTNESSDOWN); break; |
| 81 | case 0x00f3: ch_map_key_clear(KEY_BRIGHTNESSUP); break; |
| 82 | case 0x00f4: ch_map_key_clear(KEY_DISPLAY_OFF); break; |
Keng-Yu Lin | 6c30d5a | 2012-01-30 14:25:45 +0800 | [diff] [blame] | 83 | case 0x00f7: ch_map_key_clear(KEY_CAMERA); break; |
| 84 | case 0x00f8: ch_map_key_clear(KEY_PROG1); break; |
Jiri Slaby | fcfacfd | 2008-06-24 22:48:52 +0200 | [diff] [blame] | 85 | default: |
| 86 | return 0; |
| 87 | } |
| 88 | return 1; |
| 89 | } |
| 90 | |
Николай Кудрявцев | 9a1d78a | 2015-07-21 13:31:52 +0300 | [diff] [blame] | 91 | static __u8 *ch_switch12_report_fixup(struct hid_device *hdev, __u8 *rdesc, |
| 92 | unsigned int *rsize) |
| 93 | { |
| 94 | struct usb_interface *intf = to_usb_interface(hdev->dev.parent); |
| 95 | |
| 96 | if (intf->cur_altsetting->desc.bInterfaceNumber == 1) { |
| 97 | /* Change usage maximum and logical maximum from 0x7fff to |
| 98 | * 0x2fff, so they don't exceed HID_MAX_USAGES */ |
| 99 | switch (hdev->product) { |
| 100 | case USB_DEVICE_ID_CHICONY_ACER_SWITCH12: |
| 101 | if (*rsize >= 128 && rdesc[64] == 0xff && rdesc[65] == 0x7f |
| 102 | && rdesc[69] == 0xff && rdesc[70] == 0x7f) { |
| 103 | hid_info(hdev, "Fixing up report descriptor\n"); |
| 104 | rdesc[65] = rdesc[70] = 0x2f; |
| 105 | } |
| 106 | break; |
| 107 | } |
| 108 | |
| 109 | } |
| 110 | return rdesc; |
| 111 | } |
| 112 | |
Jian-Hong Pan | 859b510 | 2020-12-23 13:55:41 +0800 | [diff] [blame] | 113 | static int ch_probe(struct hid_device *hdev, const struct hid_device_id *id) |
| 114 | { |
| 115 | int ret; |
| 116 | |
Greg Kroah-Hartman | 9302095 | 2021-12-01 19:35:03 +0100 | [diff] [blame] | 117 | if (!hid_is_usb(hdev)) |
| 118 | return -EINVAL; |
| 119 | |
Jian-Hong Pan | 859b510 | 2020-12-23 13:55:41 +0800 | [diff] [blame] | 120 | hdev->quirks |= HID_QUIRK_INPUT_PER_APP; |
| 121 | ret = hid_parse(hdev); |
| 122 | if (ret) { |
| 123 | hid_err(hdev, "Chicony hid parse failed: %d\n", ret); |
| 124 | return ret; |
| 125 | } |
| 126 | |
| 127 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); |
| 128 | if (ret) { |
| 129 | hid_err(hdev, "Chicony hw start failed: %d\n", ret); |
| 130 | return ret; |
| 131 | } |
| 132 | |
| 133 | return 0; |
| 134 | } |
Николай Кудрявцев | 9a1d78a | 2015-07-21 13:31:52 +0300 | [diff] [blame] | 135 | |
Jiri Slaby | fcfacfd | 2008-06-24 22:48:52 +0200 | [diff] [blame] | 136 | static const struct hid_device_id ch_devices[] = { |
| 137 | { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_TACTICAL_PAD) }, |
Keng-Yu Lin | 3596bb9 | 2012-02-02 10:31:26 +0100 | [diff] [blame] | 138 | { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS2) }, |
Jian-Hong Pan | 859b510 | 2020-12-23 13:55:41 +0800 | [diff] [blame] | 139 | { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS3) }, |
Николай Кудрявцев | 9a1d78a | 2015-07-21 13:31:52 +0300 | [diff] [blame] | 140 | { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_ACER_SWITCH12) }, |
Jiri Slaby | fcfacfd | 2008-06-24 22:48:52 +0200 | [diff] [blame] | 141 | { } |
| 142 | }; |
| 143 | MODULE_DEVICE_TABLE(hid, ch_devices); |
| 144 | |
| 145 | static struct hid_driver ch_driver = { |
| 146 | .name = "chicony", |
| 147 | .id_table = ch_devices, |
Николай Кудрявцев | 9a1d78a | 2015-07-21 13:31:52 +0300 | [diff] [blame] | 148 | .report_fixup = ch_switch12_report_fixup, |
Jiri Slaby | fcfacfd | 2008-06-24 22:48:52 +0200 | [diff] [blame] | 149 | .input_mapping = ch_input_mapping, |
Jian-Hong Pan | 859b510 | 2020-12-23 13:55:41 +0800 | [diff] [blame] | 150 | .probe = ch_probe, |
| 151 | .raw_event = ch_raw_event, |
Jiri Slaby | fcfacfd | 2008-06-24 22:48:52 +0200 | [diff] [blame] | 152 | }; |
H Hartley Sweeten | f425458 | 2012-12-17 15:28:26 -0700 | [diff] [blame] | 153 | module_hid_driver(ch_driver); |
Jiri Slaby | fcfacfd | 2008-06-24 22:48:52 +0200 | [diff] [blame] | 154 | |
Jiri Slaby | fcfacfd | 2008-06-24 22:48:52 +0200 | [diff] [blame] | 155 | MODULE_LICENSE("GPL"); |