Jiri Slaby | fcfacfd | 2008-06-24 22:48:52 +0200 | [diff] [blame] | 1 | /* |
| 2 | * HID driver for some chicony "special" devices |
| 3 | * |
| 4 | * Copyright (c) 1999 Andreas Gal |
| 5 | * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> |
| 6 | * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc |
| 7 | * Copyright (c) 2006-2007 Jiri Kosina |
| 8 | * Copyright (c) 2007 Paul Walmsley |
| 9 | * Copyright (c) 2008 Jiri Slaby |
| 10 | */ |
| 11 | |
| 12 | /* |
| 13 | * This program is free software; you can redistribute it and/or modify it |
| 14 | * under the terms of the GNU General Public License as published by the Free |
| 15 | * Software Foundation; either version 2 of the License, or (at your option) |
| 16 | * any later version. |
| 17 | */ |
| 18 | |
| 19 | #include <linux/device.h> |
| 20 | #include <linux/input.h> |
| 21 | #include <linux/hid.h> |
| 22 | #include <linux/module.h> |
Николай Кудрявцев | 9a1d78a | 2015-07-21 13:31:52 +0300 | [diff] [blame^] | 23 | #include <linux/usb.h> |
Jiri Slaby | fcfacfd | 2008-06-24 22:48:52 +0200 | [diff] [blame] | 24 | |
| 25 | #include "hid-ids.h" |
| 26 | |
| 27 | #define ch_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \ |
| 28 | EV_KEY, (c)) |
| 29 | static int ch_input_mapping(struct hid_device *hdev, struct hid_input *hi, |
| 30 | struct hid_field *field, struct hid_usage *usage, |
| 31 | unsigned long **bit, int *max) |
| 32 | { |
| 33 | if ((usage->hid & HID_USAGE_PAGE) != HID_UP_MSVENDOR) |
| 34 | return 0; |
| 35 | |
| 36 | set_bit(EV_REP, hi->input->evbit); |
| 37 | switch (usage->hid & HID_USAGE) { |
| 38 | case 0xff01: ch_map_key_clear(BTN_1); break; |
| 39 | case 0xff02: ch_map_key_clear(BTN_2); break; |
| 40 | case 0xff03: ch_map_key_clear(BTN_3); break; |
| 41 | case 0xff04: ch_map_key_clear(BTN_4); break; |
| 42 | case 0xff05: ch_map_key_clear(BTN_5); break; |
| 43 | case 0xff06: ch_map_key_clear(BTN_6); break; |
| 44 | case 0xff07: ch_map_key_clear(BTN_7); break; |
| 45 | case 0xff08: ch_map_key_clear(BTN_8); break; |
| 46 | case 0xff09: ch_map_key_clear(BTN_9); break; |
| 47 | case 0xff0a: ch_map_key_clear(BTN_A); break; |
| 48 | case 0xff0b: ch_map_key_clear(BTN_B); break; |
Keng-Yu Lin | 3596bb9 | 2012-02-02 10:31:26 +0100 | [diff] [blame] | 49 | case 0x00f1: ch_map_key_clear(KEY_WLAN); break; |
| 50 | case 0x00f2: ch_map_key_clear(KEY_BRIGHTNESSDOWN); break; |
| 51 | case 0x00f3: ch_map_key_clear(KEY_BRIGHTNESSUP); break; |
| 52 | case 0x00f4: ch_map_key_clear(KEY_DISPLAY_OFF); break; |
Keng-Yu Lin | 6c30d5a | 2012-01-30 14:25:45 +0800 | [diff] [blame] | 53 | case 0x00f7: ch_map_key_clear(KEY_CAMERA); break; |
| 54 | case 0x00f8: ch_map_key_clear(KEY_PROG1); break; |
Jiri Slaby | fcfacfd | 2008-06-24 22:48:52 +0200 | [diff] [blame] | 55 | default: |
| 56 | return 0; |
| 57 | } |
| 58 | return 1; |
| 59 | } |
| 60 | |
Николай Кудрявцев | 9a1d78a | 2015-07-21 13:31:52 +0300 | [diff] [blame^] | 61 | static __u8 *ch_switch12_report_fixup(struct hid_device *hdev, __u8 *rdesc, |
| 62 | unsigned int *rsize) |
| 63 | { |
| 64 | struct usb_interface *intf = to_usb_interface(hdev->dev.parent); |
| 65 | |
| 66 | if (intf->cur_altsetting->desc.bInterfaceNumber == 1) { |
| 67 | /* Change usage maximum and logical maximum from 0x7fff to |
| 68 | * 0x2fff, so they don't exceed HID_MAX_USAGES */ |
| 69 | switch (hdev->product) { |
| 70 | case USB_DEVICE_ID_CHICONY_ACER_SWITCH12: |
| 71 | if (*rsize >= 128 && rdesc[64] == 0xff && rdesc[65] == 0x7f |
| 72 | && rdesc[69] == 0xff && rdesc[70] == 0x7f) { |
| 73 | hid_info(hdev, "Fixing up report descriptor\n"); |
| 74 | rdesc[65] = rdesc[70] = 0x2f; |
| 75 | } |
| 76 | break; |
| 77 | } |
| 78 | |
| 79 | } |
| 80 | return rdesc; |
| 81 | } |
| 82 | |
| 83 | |
Jiri Slaby | fcfacfd | 2008-06-24 22:48:52 +0200 | [diff] [blame] | 84 | static const struct hid_device_id ch_devices[] = { |
| 85 | { 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] | 86 | { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS2) }, |
Cyrus Lien | 2d8767b | 2012-07-23 17:11:51 +0800 | [diff] [blame] | 87 | { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_AK1D) }, |
Николай Кудрявцев | 9a1d78a | 2015-07-21 13:31:52 +0300 | [diff] [blame^] | 88 | { 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] | 89 | { } |
| 90 | }; |
| 91 | MODULE_DEVICE_TABLE(hid, ch_devices); |
| 92 | |
| 93 | static struct hid_driver ch_driver = { |
| 94 | .name = "chicony", |
| 95 | .id_table = ch_devices, |
Николай Кудрявцев | 9a1d78a | 2015-07-21 13:31:52 +0300 | [diff] [blame^] | 96 | .report_fixup = ch_switch12_report_fixup, |
Jiri Slaby | fcfacfd | 2008-06-24 22:48:52 +0200 | [diff] [blame] | 97 | .input_mapping = ch_input_mapping, |
| 98 | }; |
H Hartley Sweeten | f425458 | 2012-12-17 15:28:26 -0700 | [diff] [blame] | 99 | module_hid_driver(ch_driver); |
Jiri Slaby | fcfacfd | 2008-06-24 22:48:52 +0200 | [diff] [blame] | 100 | |
Jiri Slaby | fcfacfd | 2008-06-24 22:48:52 +0200 | [diff] [blame] | 101 | MODULE_LICENSE("GPL"); |