blob: cf5992e97094003628a4aaacbded99a9f3603a10 [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Jiri Slaby980a3da2008-06-25 22:31:48 +02002/*
3 * HID driver for some samsung "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
Jiri Slaby980a3da2008-06-25 22:31:48 +02009 * Copyright (c) 2008 Jiri Slaby
Don Princeb3558502010-05-17 11:42:39 +010010 * Copyright (c) 2010 Don Prince <dhprince.devel@yahoo.co.uk>
11 *
Don Princeb3558502010-05-17 11:42:39 +010012 * This driver supports several HID devices:
13 *
14 * [0419:0001] Samsung IrDA remote controller (reports as Cypress USB Mouse).
15 * various hid report fixups for different variants.
16 *
17 * [0419:0600] Creative Desktop Wireless 6000 keyboard/mouse combo
18 * several key mappings used from the consumer usage page
19 * deviate from the USB HUT 1.12 standard.
Jiri Slaby980a3da2008-06-25 22:31:48 +020020 */
21
22/*
Jiri Slaby980a3da2008-06-25 22:31:48 +020023 */
24
25#include <linux/device.h>
Don Princeb3558502010-05-17 11:42:39 +010026#include <linux/usb.h>
Jiri Slaby980a3da2008-06-25 22:31:48 +020027#include <linux/hid.h>
28#include <linux/module.h>
29
30#include "hid-ids.h"
31
32/*
Robert Schedel0810b512009-06-23 11:26:48 +020033 * There are several variants for 0419:0001:
34 *
35 * 1. 184 byte report descriptor
Jiri Slaby980a3da2008-06-25 22:31:48 +020036 * Vendor specific report #4 has a size of 48 bit,
37 * and therefore is not accepted when inspecting the descriptors.
38 * As a workaround we reinterpret the report as:
39 * Variable type, count 6, size 8 bit, log. maximum 255
40 * The burden to reconstruct the data is moved into user space.
Robert Schedel0810b512009-06-23 11:26:48 +020041 *
42 * 2. 203 byte report descriptor
43 * Report #4 has an array field with logical range 0..18 instead of 1..15.
44 *
45 * 3. 135 byte report descriptor
46 * Report #4 has an array field with logical range 0..17 instead of 1..14.
Robert Schedel3975bc52009-12-11 00:37:11 +010047 *
48 * 4. 171 byte report descriptor
49 * Report #3 has an array field with logical range 0..1 instead of 1..3.
Jiri Slaby980a3da2008-06-25 22:31:48 +020050 */
Don Princeb3558502010-05-17 11:42:39 +010051static inline void samsung_irda_dev_trace(struct hid_device *hdev,
Robert Schedel3975bc52009-12-11 00:37:11 +010052 unsigned int rsize)
53{
Joe Perches4291ee32010-12-09 19:29:03 -080054 hid_info(hdev, "fixing up Samsung IrDA %d byte report descriptor\n",
55 rsize);
Robert Schedel3975bc52009-12-11 00:37:11 +010056}
57
Nikolai Kondrashov73e40082010-08-06 23:03:06 +040058static __u8 *samsung_irda_report_fixup(struct hid_device *hdev, __u8 *rdesc,
59 unsigned int *rsize)
Jiri Slaby980a3da2008-06-25 22:31:48 +020060{
Nikolai Kondrashov73e40082010-08-06 23:03:06 +040061 if (*rsize == 184 && rdesc[175] == 0x25 && rdesc[176] == 0x40 &&
Jiri Slaby980a3da2008-06-25 22:31:48 +020062 rdesc[177] == 0x75 && rdesc[178] == 0x30 &&
63 rdesc[179] == 0x95 && rdesc[180] == 0x01 &&
64 rdesc[182] == 0x40) {
Don Princeb3558502010-05-17 11:42:39 +010065 samsung_irda_dev_trace(hdev, 184);
Jiri Slaby980a3da2008-06-25 22:31:48 +020066 rdesc[176] = 0xff;
67 rdesc[178] = 0x08;
68 rdesc[180] = 0x06;
69 rdesc[182] = 0x42;
Robert Schedel0810b512009-06-23 11:26:48 +020070 } else
Nikolai Kondrashov73e40082010-08-06 23:03:06 +040071 if (*rsize == 203 && rdesc[192] == 0x15 && rdesc[193] == 0x0 &&
Robert Schedel0810b512009-06-23 11:26:48 +020072 rdesc[194] == 0x25 && rdesc[195] == 0x12) {
Don Princeb3558502010-05-17 11:42:39 +010073 samsung_irda_dev_trace(hdev, 203);
Robert Schedel0810b512009-06-23 11:26:48 +020074 rdesc[193] = 0x1;
75 rdesc[195] = 0xf;
76 } else
Nikolai Kondrashov73e40082010-08-06 23:03:06 +040077 if (*rsize == 135 && rdesc[124] == 0x15 && rdesc[125] == 0x0 &&
Robert Schedel0810b512009-06-23 11:26:48 +020078 rdesc[126] == 0x25 && rdesc[127] == 0x11) {
Don Princeb3558502010-05-17 11:42:39 +010079 samsung_irda_dev_trace(hdev, 135);
Robert Schedel0810b512009-06-23 11:26:48 +020080 rdesc[125] = 0x1;
81 rdesc[127] = 0xe;
Robert Schedel3975bc52009-12-11 00:37:11 +010082 } else
Nikolai Kondrashov73e40082010-08-06 23:03:06 +040083 if (*rsize == 171 && rdesc[160] == 0x15 && rdesc[161] == 0x0 &&
Robert Schedel3975bc52009-12-11 00:37:11 +010084 rdesc[162] == 0x25 && rdesc[163] == 0x01) {
Don Princeb3558502010-05-17 11:42:39 +010085 samsung_irda_dev_trace(hdev, 171);
Robert Schedel3975bc52009-12-11 00:37:11 +010086 rdesc[161] = 0x1;
87 rdesc[163] = 0x3;
Jiri Slaby980a3da2008-06-25 22:31:48 +020088 }
Nikolai Kondrashov73e40082010-08-06 23:03:06 +040089 return rdesc;
Jiri Slaby980a3da2008-06-25 22:31:48 +020090}
91
Don Princeb3558502010-05-17 11:42:39 +010092#define samsung_kbd_mouse_map_key_clear(c) \
93 hid_map_usage_clear(hi, usage, bit, max, EV_KEY, (c))
94
95static int samsung_kbd_mouse_input_mapping(struct hid_device *hdev,
96 struct hid_input *hi, struct hid_field *field, struct hid_usage *usage,
97 unsigned long **bit, int *max)
98{
99 struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
100 unsigned short ifnum = intf->cur_altsetting->desc.bInterfaceNumber;
101
102 if (1 != ifnum || HID_UP_CONSUMER != (usage->hid & HID_USAGE_PAGE))
103 return 0;
104
105 dbg_hid("samsung wireless keyboard/mouse input mapping event [0x%x]\n",
106 usage->hid & HID_USAGE);
107
108 switch (usage->hid & HID_USAGE) {
109 /* report 2 */
Don Princeb3558502010-05-17 11:42:39 +0100110 case 0x183: samsung_kbd_mouse_map_key_clear(KEY_MEDIA); break;
111 case 0x195: samsung_kbd_mouse_map_key_clear(KEY_EMAIL); break;
112 case 0x196: samsung_kbd_mouse_map_key_clear(KEY_CALC); break;
113 case 0x197: samsung_kbd_mouse_map_key_clear(KEY_COMPUTER); break;
114 case 0x22b: samsung_kbd_mouse_map_key_clear(KEY_SEARCH); break;
115 case 0x22c: samsung_kbd_mouse_map_key_clear(KEY_WWW); break;
116 case 0x22d: samsung_kbd_mouse_map_key_clear(KEY_BACK); break;
117 case 0x22e: samsung_kbd_mouse_map_key_clear(KEY_FORWARD); break;
118 case 0x22f: samsung_kbd_mouse_map_key_clear(KEY_FAVORITES); break;
119 case 0x230: samsung_kbd_mouse_map_key_clear(KEY_REFRESH); break;
120 case 0x231: samsung_kbd_mouse_map_key_clear(KEY_STOP); break;
121 default:
122 return 0;
123 }
124
125 return 1;
126}
127
Nikolai Kondrashov73e40082010-08-06 23:03:06 +0400128static __u8 *samsung_report_fixup(struct hid_device *hdev, __u8 *rdesc,
129 unsigned int *rsize)
Don Princeb3558502010-05-17 11:42:39 +0100130{
131 if (USB_DEVICE_ID_SAMSUNG_IR_REMOTE == hdev->product)
Nikolai Kondrashov73e40082010-08-06 23:03:06 +0400132 rdesc = samsung_irda_report_fixup(hdev, rdesc, rsize);
133 return rdesc;
Don Princeb3558502010-05-17 11:42:39 +0100134}
135
136static int samsung_input_mapping(struct hid_device *hdev, struct hid_input *hi,
137 struct hid_field *field, struct hid_usage *usage,
138 unsigned long **bit, int *max)
139{
140 int ret = 0;
141
142 if (USB_DEVICE_ID_SAMSUNG_WIRELESS_KBD_MOUSE == hdev->product)
143 ret = samsung_kbd_mouse_input_mapping(hdev,
144 hi, field, usage, bit, max);
145
146 return ret;
147}
148
Jiri Slaby980a3da2008-06-25 22:31:48 +0200149static int samsung_probe(struct hid_device *hdev,
150 const struct hid_device_id *id)
151{
152 int ret;
Robert Schedel0810b512009-06-23 11:26:48 +0200153 unsigned int cmask = HID_CONNECT_DEFAULT;
Jiri Slaby980a3da2008-06-25 22:31:48 +0200154
Greg Kroah-Hartman93020952021-12-01 19:35:03 +0100155 if (!hid_is_usb(hdev))
156 return -EINVAL;
157
Jiri Slaby980a3da2008-06-25 22:31:48 +0200158 ret = hid_parse(hdev);
159 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -0800160 hid_err(hdev, "parse failed\n");
Jiri Slaby980a3da2008-06-25 22:31:48 +0200161 goto err_free;
162 }
163
Don Princeb3558502010-05-17 11:42:39 +0100164 if (USB_DEVICE_ID_SAMSUNG_IR_REMOTE == hdev->product) {
165 if (hdev->rsize == 184) {
166 /* disable hidinput, force hiddev */
167 cmask = (cmask & ~HID_CONNECT_HIDINPUT) |
168 HID_CONNECT_HIDDEV_FORCE;
169 }
Robert Schedel0810b512009-06-23 11:26:48 +0200170 }
171
172 ret = hid_hw_start(hdev, cmask);
Jiri Slaby980a3da2008-06-25 22:31:48 +0200173 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -0800174 hid_err(hdev, "hw start failed\n");
Jiri Slaby980a3da2008-06-25 22:31:48 +0200175 goto err_free;
176 }
177
178 return 0;
179err_free:
180 return ret;
181}
182
183static const struct hid_device_id samsung_devices[] = {
184 { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) },
Don Princeb3558502010-05-17 11:42:39 +0100185 { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_WIRELESS_KBD_MOUSE) },
Jiri Slaby980a3da2008-06-25 22:31:48 +0200186 { }
187};
188MODULE_DEVICE_TABLE(hid, samsung_devices);
189
190static struct hid_driver samsung_driver = {
191 .name = "samsung",
192 .id_table = samsung_devices,
193 .report_fixup = samsung_report_fixup,
Don Princeb3558502010-05-17 11:42:39 +0100194 .input_mapping = samsung_input_mapping,
Jiri Slaby980a3da2008-06-25 22:31:48 +0200195 .probe = samsung_probe,
196};
H Hartley Sweetenf4254582012-12-17 15:28:26 -0700197module_hid_driver(samsung_driver);
Jiri Slaby980a3da2008-06-25 22:31:48 +0200198
Jiri Slaby980a3da2008-06-25 22:31:48 +0200199MODULE_LICENSE("GPL");