blob: 3f0ed6a95223499e14cf7f85608676945af5474b [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Jiri Slabyfcfacfd2008-06-24 22:48:52 +02002/*
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 Slabyfcfacfd2008-06-24 22:48:52 +020014 */
15
16#include <linux/device.h>
17#include <linux/input.h>
18#include <linux/hid.h>
19#include <linux/module.h>
Николай Кудрявцев9a1d78a2015-07-21 13:31:52 +030020#include <linux/usb.h>
Jiri Slabyfcfacfd2008-06-24 22:48:52 +020021
22#include "hid-ids.h"
23
24#define ch_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \
25 EV_KEY, (c))
26static int ch_input_mapping(struct hid_device *hdev, struct hid_input *hi,
27 struct hid_field *field, struct hid_usage *usage,
28 unsigned long **bit, int *max)
29{
30 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_MSVENDOR)
31 return 0;
32
33 set_bit(EV_REP, hi->input->evbit);
34 switch (usage->hid & HID_USAGE) {
35 case 0xff01: ch_map_key_clear(BTN_1); break;
36 case 0xff02: ch_map_key_clear(BTN_2); break;
37 case 0xff03: ch_map_key_clear(BTN_3); break;
38 case 0xff04: ch_map_key_clear(BTN_4); break;
39 case 0xff05: ch_map_key_clear(BTN_5); break;
40 case 0xff06: ch_map_key_clear(BTN_6); break;
41 case 0xff07: ch_map_key_clear(BTN_7); break;
42 case 0xff08: ch_map_key_clear(BTN_8); break;
43 case 0xff09: ch_map_key_clear(BTN_9); break;
44 case 0xff0a: ch_map_key_clear(BTN_A); break;
45 case 0xff0b: ch_map_key_clear(BTN_B); break;
Keng-Yu Lin3596bb92012-02-02 10:31:26 +010046 case 0x00f1: ch_map_key_clear(KEY_WLAN); break;
47 case 0x00f2: ch_map_key_clear(KEY_BRIGHTNESSDOWN); break;
48 case 0x00f3: ch_map_key_clear(KEY_BRIGHTNESSUP); break;
49 case 0x00f4: ch_map_key_clear(KEY_DISPLAY_OFF); break;
Keng-Yu Lin6c30d5a2012-01-30 14:25:45 +080050 case 0x00f7: ch_map_key_clear(KEY_CAMERA); break;
51 case 0x00f8: ch_map_key_clear(KEY_PROG1); break;
Jiri Slabyfcfacfd2008-06-24 22:48:52 +020052 default:
53 return 0;
54 }
55 return 1;
56}
57
Николай Кудрявцев9a1d78a2015-07-21 13:31:52 +030058static __u8 *ch_switch12_report_fixup(struct hid_device *hdev, __u8 *rdesc,
59 unsigned int *rsize)
60{
61 struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
62
63 if (intf->cur_altsetting->desc.bInterfaceNumber == 1) {
64 /* Change usage maximum and logical maximum from 0x7fff to
65 * 0x2fff, so they don't exceed HID_MAX_USAGES */
66 switch (hdev->product) {
67 case USB_DEVICE_ID_CHICONY_ACER_SWITCH12:
68 if (*rsize >= 128 && rdesc[64] == 0xff && rdesc[65] == 0x7f
69 && rdesc[69] == 0xff && rdesc[70] == 0x7f) {
70 hid_info(hdev, "Fixing up report descriptor\n");
71 rdesc[65] = rdesc[70] = 0x2f;
72 }
73 break;
74 }
75
76 }
77 return rdesc;
78}
79
80
Jiri Slabyfcfacfd2008-06-24 22:48:52 +020081static const struct hid_device_id ch_devices[] = {
82 { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_TACTICAL_PAD) },
Keng-Yu Lin3596bb92012-02-02 10:31:26 +010083 { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS2) },
Николай Кудрявцев9a1d78a2015-07-21 13:31:52 +030084 { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_ACER_SWITCH12) },
Jiri Slabyfcfacfd2008-06-24 22:48:52 +020085 { }
86};
87MODULE_DEVICE_TABLE(hid, ch_devices);
88
89static struct hid_driver ch_driver = {
90 .name = "chicony",
91 .id_table = ch_devices,
Николай Кудрявцев9a1d78a2015-07-21 13:31:52 +030092 .report_fixup = ch_switch12_report_fixup,
Jiri Slabyfcfacfd2008-06-24 22:48:52 +020093 .input_mapping = ch_input_mapping,
94};
H Hartley Sweetenf4254582012-12-17 15:28:26 -070095module_hid_driver(ch_driver);
Jiri Slabyfcfacfd2008-06-24 22:48:52 +020096
Jiri Slabyfcfacfd2008-06-24 22:48:52 +020097MODULE_LICENSE("GPL");