blob: 7cbb067d4a9e399f62b57b54830d384956037cbc [file] [log] [blame]
Jiri Slaby980a3da2008-06-25 22:31:48 +02001/*
2 * HID driver for some samsung "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
Jiri Slaby980a3da2008-06-25 22:31:48 +02008 * Copyright (c) 2008 Jiri Slaby
Don Princeb3558502010-05-17 11:42:39 +01009 * Copyright (c) 2010 Don Prince <dhprince.devel@yahoo.co.uk>
10 *
11 *
12 * 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.
20 *
Jiri Slaby980a3da2008-06-25 22:31:48 +020021 */
22
23/*
24 * This program is free software; you can redistribute it and/or modify it
25 * under the terms of the GNU General Public License as published by the Free
26 * Software Foundation; either version 2 of the License, or (at your option)
27 * any later version.
28 */
29
30#include <linux/device.h>
Don Princeb3558502010-05-17 11:42:39 +010031#include <linux/usb.h>
Jiri Slaby980a3da2008-06-25 22:31:48 +020032#include <linux/hid.h>
33#include <linux/module.h>
34
35#include "hid-ids.h"
36
37/*
Robert Schedel0810b512009-06-23 11:26:48 +020038 * There are several variants for 0419:0001:
39 *
40 * 1. 184 byte report descriptor
Jiri Slaby980a3da2008-06-25 22:31:48 +020041 * Vendor specific report #4 has a size of 48 bit,
42 * and therefore is not accepted when inspecting the descriptors.
43 * As a workaround we reinterpret the report as:
44 * Variable type, count 6, size 8 bit, log. maximum 255
45 * The burden to reconstruct the data is moved into user space.
Robert Schedel0810b512009-06-23 11:26:48 +020046 *
47 * 2. 203 byte report descriptor
48 * Report #4 has an array field with logical range 0..18 instead of 1..15.
49 *
50 * 3. 135 byte report descriptor
51 * Report #4 has an array field with logical range 0..17 instead of 1..14.
Robert Schedel3975bc52009-12-11 00:37:11 +010052 *
53 * 4. 171 byte report descriptor
54 * Report #3 has an array field with logical range 0..1 instead of 1..3.
Jiri Slaby980a3da2008-06-25 22:31:48 +020055 */
Don Princeb3558502010-05-17 11:42:39 +010056static inline void samsung_irda_dev_trace(struct hid_device *hdev,
Robert Schedel3975bc52009-12-11 00:37:11 +010057 unsigned int rsize)
58{
Joe Perches4291ee32010-12-09 19:29:03 -080059 hid_info(hdev, "fixing up Samsung IrDA %d byte report descriptor\n",
60 rsize);
Robert Schedel3975bc52009-12-11 00:37:11 +010061}
62
Nikolai Kondrashov73e40082010-08-06 23:03:06 +040063static __u8 *samsung_irda_report_fixup(struct hid_device *hdev, __u8 *rdesc,
64 unsigned int *rsize)
Jiri Slaby980a3da2008-06-25 22:31:48 +020065{
Nikolai Kondrashov73e40082010-08-06 23:03:06 +040066 if (*rsize == 184 && rdesc[175] == 0x25 && rdesc[176] == 0x40 &&
Jiri Slaby980a3da2008-06-25 22:31:48 +020067 rdesc[177] == 0x75 && rdesc[178] == 0x30 &&
68 rdesc[179] == 0x95 && rdesc[180] == 0x01 &&
69 rdesc[182] == 0x40) {
Don Princeb3558502010-05-17 11:42:39 +010070 samsung_irda_dev_trace(hdev, 184);
Jiri Slaby980a3da2008-06-25 22:31:48 +020071 rdesc[176] = 0xff;
72 rdesc[178] = 0x08;
73 rdesc[180] = 0x06;
74 rdesc[182] = 0x42;
Robert Schedel0810b512009-06-23 11:26:48 +020075 } else
Nikolai Kondrashov73e40082010-08-06 23:03:06 +040076 if (*rsize == 203 && rdesc[192] == 0x15 && rdesc[193] == 0x0 &&
Robert Schedel0810b512009-06-23 11:26:48 +020077 rdesc[194] == 0x25 && rdesc[195] == 0x12) {
Don Princeb3558502010-05-17 11:42:39 +010078 samsung_irda_dev_trace(hdev, 203);
Robert Schedel0810b512009-06-23 11:26:48 +020079 rdesc[193] = 0x1;
80 rdesc[195] = 0xf;
81 } else
Nikolai Kondrashov73e40082010-08-06 23:03:06 +040082 if (*rsize == 135 && rdesc[124] == 0x15 && rdesc[125] == 0x0 &&
Robert Schedel0810b512009-06-23 11:26:48 +020083 rdesc[126] == 0x25 && rdesc[127] == 0x11) {
Don Princeb3558502010-05-17 11:42:39 +010084 samsung_irda_dev_trace(hdev, 135);
Robert Schedel0810b512009-06-23 11:26:48 +020085 rdesc[125] = 0x1;
86 rdesc[127] = 0xe;
Robert Schedel3975bc52009-12-11 00:37:11 +010087 } else
Nikolai Kondrashov73e40082010-08-06 23:03:06 +040088 if (*rsize == 171 && rdesc[160] == 0x15 && rdesc[161] == 0x0 &&
Robert Schedel3975bc52009-12-11 00:37:11 +010089 rdesc[162] == 0x25 && rdesc[163] == 0x01) {
Don Princeb3558502010-05-17 11:42:39 +010090 samsung_irda_dev_trace(hdev, 171);
Robert Schedel3975bc52009-12-11 00:37:11 +010091 rdesc[161] = 0x1;
92 rdesc[163] = 0x3;
Jiri Slaby980a3da2008-06-25 22:31:48 +020093 }
Nikolai Kondrashov73e40082010-08-06 23:03:06 +040094 return rdesc;
Jiri Slaby980a3da2008-06-25 22:31:48 +020095}
96
Don Princeb3558502010-05-17 11:42:39 +010097#define samsung_kbd_mouse_map_key_clear(c) \
98 hid_map_usage_clear(hi, usage, bit, max, EV_KEY, (c))
99
100static int samsung_kbd_mouse_input_mapping(struct hid_device *hdev,
101 struct hid_input *hi, struct hid_field *field, struct hid_usage *usage,
102 unsigned long **bit, int *max)
103{
104 struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
105 unsigned short ifnum = intf->cur_altsetting->desc.bInterfaceNumber;
106
107 if (1 != ifnum || HID_UP_CONSUMER != (usage->hid & HID_USAGE_PAGE))
108 return 0;
109
110 dbg_hid("samsung wireless keyboard/mouse input mapping event [0x%x]\n",
111 usage->hid & HID_USAGE);
112
113 switch (usage->hid & HID_USAGE) {
114 /* report 2 */
Don Princeb3558502010-05-17 11:42:39 +0100115 case 0x183: samsung_kbd_mouse_map_key_clear(KEY_MEDIA); break;
116 case 0x195: samsung_kbd_mouse_map_key_clear(KEY_EMAIL); break;
117 case 0x196: samsung_kbd_mouse_map_key_clear(KEY_CALC); break;
118 case 0x197: samsung_kbd_mouse_map_key_clear(KEY_COMPUTER); break;
119 case 0x22b: samsung_kbd_mouse_map_key_clear(KEY_SEARCH); break;
120 case 0x22c: samsung_kbd_mouse_map_key_clear(KEY_WWW); break;
121 case 0x22d: samsung_kbd_mouse_map_key_clear(KEY_BACK); break;
122 case 0x22e: samsung_kbd_mouse_map_key_clear(KEY_FORWARD); break;
123 case 0x22f: samsung_kbd_mouse_map_key_clear(KEY_FAVORITES); break;
124 case 0x230: samsung_kbd_mouse_map_key_clear(KEY_REFRESH); break;
125 case 0x231: samsung_kbd_mouse_map_key_clear(KEY_STOP); break;
126 default:
127 return 0;
128 }
129
130 return 1;
131}
132
Nikolai Kondrashov73e40082010-08-06 23:03:06 +0400133static __u8 *samsung_report_fixup(struct hid_device *hdev, __u8 *rdesc,
134 unsigned int *rsize)
Don Princeb3558502010-05-17 11:42:39 +0100135{
136 if (USB_DEVICE_ID_SAMSUNG_IR_REMOTE == hdev->product)
Nikolai Kondrashov73e40082010-08-06 23:03:06 +0400137 rdesc = samsung_irda_report_fixup(hdev, rdesc, rsize);
138 return rdesc;
Don Princeb3558502010-05-17 11:42:39 +0100139}
140
141static int samsung_input_mapping(struct hid_device *hdev, struct hid_input *hi,
142 struct hid_field *field, struct hid_usage *usage,
143 unsigned long **bit, int *max)
144{
145 int ret = 0;
146
147 if (USB_DEVICE_ID_SAMSUNG_WIRELESS_KBD_MOUSE == hdev->product)
148 ret = samsung_kbd_mouse_input_mapping(hdev,
149 hi, field, usage, bit, max);
150
151 return ret;
152}
153
Jiri Slaby980a3da2008-06-25 22:31:48 +0200154static int samsung_probe(struct hid_device *hdev,
155 const struct hid_device_id *id)
156{
157 int ret;
Robert Schedel0810b512009-06-23 11:26:48 +0200158 unsigned int cmask = HID_CONNECT_DEFAULT;
Jiri Slaby980a3da2008-06-25 22:31:48 +0200159
Jiri Slaby980a3da2008-06-25 22:31:48 +0200160 ret = hid_parse(hdev);
161 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -0800162 hid_err(hdev, "parse failed\n");
Jiri Slaby980a3da2008-06-25 22:31:48 +0200163 goto err_free;
164 }
165
Don Princeb3558502010-05-17 11:42:39 +0100166 if (USB_DEVICE_ID_SAMSUNG_IR_REMOTE == hdev->product) {
167 if (hdev->rsize == 184) {
168 /* disable hidinput, force hiddev */
169 cmask = (cmask & ~HID_CONNECT_HIDINPUT) |
170 HID_CONNECT_HIDDEV_FORCE;
171 }
Robert Schedel0810b512009-06-23 11:26:48 +0200172 }
173
174 ret = hid_hw_start(hdev, cmask);
Jiri Slaby980a3da2008-06-25 22:31:48 +0200175 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -0800176 hid_err(hdev, "hw start failed\n");
Jiri Slaby980a3da2008-06-25 22:31:48 +0200177 goto err_free;
178 }
179
180 return 0;
181err_free:
182 return ret;
183}
184
185static const struct hid_device_id samsung_devices[] = {
186 { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) },
Don Princeb3558502010-05-17 11:42:39 +0100187 { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_WIRELESS_KBD_MOUSE) },
Jiri Slaby980a3da2008-06-25 22:31:48 +0200188 { }
189};
190MODULE_DEVICE_TABLE(hid, samsung_devices);
191
192static struct hid_driver samsung_driver = {
193 .name = "samsung",
194 .id_table = samsung_devices,
195 .report_fixup = samsung_report_fixup,
Don Princeb3558502010-05-17 11:42:39 +0100196 .input_mapping = samsung_input_mapping,
Jiri Slaby980a3da2008-06-25 22:31:48 +0200197 .probe = samsung_probe,
198};
H Hartley Sweetenf4254582012-12-17 15:28:26 -0700199module_hid_driver(samsung_driver);
Jiri Slaby980a3da2008-06-25 22:31:48 +0200200
Jiri Slaby980a3da2008-06-25 22:31:48 +0200201MODULE_LICENSE("GPL");