1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31#include <linux/device.h>
32#include <linux/usb.h>
33#include <linux/hid.h>
34#include <linux/module.h>
35
36#include "hid-ids.h"
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57static inline void samsung_irda_dev_trace(struct hid_device *hdev,
58 unsigned int rsize)
59{
60 hid_info(hdev, "fixing up Samsung IrDA %d byte report descriptor\n",
61 rsize);
62}
63
64static __u8 *samsung_irda_report_fixup(struct hid_device *hdev, __u8 *rdesc,
65 unsigned int *rsize)
66{
67 if (*rsize == 184 && rdesc[175] == 0x25 && rdesc[176] == 0x40 &&
68 rdesc[177] == 0x75 && rdesc[178] == 0x30 &&
69 rdesc[179] == 0x95 && rdesc[180] == 0x01 &&
70 rdesc[182] == 0x40) {
71 samsung_irda_dev_trace(hdev, 184);
72 rdesc[176] = 0xff;
73 rdesc[178] = 0x08;
74 rdesc[180] = 0x06;
75 rdesc[182] = 0x42;
76 } else
77 if (*rsize == 203 && rdesc[192] == 0x15 && rdesc[193] == 0x0 &&
78 rdesc[194] == 0x25 && rdesc[195] == 0x12) {
79 samsung_irda_dev_trace(hdev, 203);
80 rdesc[193] = 0x1;
81 rdesc[195] = 0xf;
82 } else
83 if (*rsize == 135 && rdesc[124] == 0x15 && rdesc[125] == 0x0 &&
84 rdesc[126] == 0x25 && rdesc[127] == 0x11) {
85 samsung_irda_dev_trace(hdev, 135);
86 rdesc[125] = 0x1;
87 rdesc[127] = 0xe;
88 } else
89 if (*rsize == 171 && rdesc[160] == 0x15 && rdesc[161] == 0x0 &&
90 rdesc[162] == 0x25 && rdesc[163] == 0x01) {
91 samsung_irda_dev_trace(hdev, 171);
92 rdesc[161] = 0x1;
93 rdesc[163] = 0x3;
94 }
95 return rdesc;
96}
97
98#define samsung_kbd_mouse_map_key_clear(c) \
99 hid_map_usage_clear(hi, usage, bit, max, EV_KEY, (c))
100
101static int samsung_kbd_mouse_input_mapping(struct hid_device *hdev,
102 struct hid_input *hi, struct hid_field *field, struct hid_usage *usage,
103 unsigned long **bit, int *max)
104{
105 struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
106 unsigned short ifnum = intf->cur_altsetting->desc.bInterfaceNumber;
107
108 if (1 != ifnum || HID_UP_CONSUMER != (usage->hid & HID_USAGE_PAGE))
109 return 0;
110
111 dbg_hid("samsung wireless keyboard/mouse input mapping event [0x%x]\n",
112 usage->hid & HID_USAGE);
113
114 switch (usage->hid & HID_USAGE) {
115
116 case 0x183: samsung_kbd_mouse_map_key_clear(KEY_MEDIA); break;
117 case 0x195: samsung_kbd_mouse_map_key_clear(KEY_EMAIL); break;
118 case 0x196: samsung_kbd_mouse_map_key_clear(KEY_CALC); break;
119 case 0x197: samsung_kbd_mouse_map_key_clear(KEY_COMPUTER); break;
120 case 0x22b: samsung_kbd_mouse_map_key_clear(KEY_SEARCH); break;
121 case 0x22c: samsung_kbd_mouse_map_key_clear(KEY_WWW); break;
122 case 0x22d: samsung_kbd_mouse_map_key_clear(KEY_BACK); break;
123 case 0x22e: samsung_kbd_mouse_map_key_clear(KEY_FORWARD); break;
124 case 0x22f: samsung_kbd_mouse_map_key_clear(KEY_FAVORITES); break;
125 case 0x230: samsung_kbd_mouse_map_key_clear(KEY_REFRESH); break;
126 case 0x231: samsung_kbd_mouse_map_key_clear(KEY_STOP); break;
127 default:
128 return 0;
129 }
130
131 return 1;
132}
133
134static __u8 *samsung_report_fixup(struct hid_device *hdev, __u8 *rdesc,
135 unsigned int *rsize)
136{
137 if (USB_DEVICE_ID_SAMSUNG_IR_REMOTE == hdev->product)
138 rdesc = samsung_irda_report_fixup(hdev, rdesc, rsize);
139 return rdesc;
140}
141
142static int samsung_input_mapping(struct hid_device *hdev, struct hid_input *hi,
143 struct hid_field *field, struct hid_usage *usage,
144 unsigned long **bit, int *max)
145{
146 int ret = 0;
147
148 if (USB_DEVICE_ID_SAMSUNG_WIRELESS_KBD_MOUSE == hdev->product)
149 ret = samsung_kbd_mouse_input_mapping(hdev,
150 hi, field, usage, bit, max);
151
152 return ret;
153}
154
155static int samsung_probe(struct hid_device *hdev,
156 const struct hid_device_id *id)
157{
158 int ret;
159 unsigned int cmask = HID_CONNECT_DEFAULT;
160
161 ret = hid_parse(hdev);
162 if (ret) {
163 hid_err(hdev, "parse failed\n");
164 goto err_free;
165 }
166
167 if (USB_DEVICE_ID_SAMSUNG_IR_REMOTE == hdev->product) {
168 if (hdev->rsize == 184) {
169
170 cmask = (cmask & ~HID_CONNECT_HIDINPUT) |
171 HID_CONNECT_HIDDEV_FORCE;
172 }
173 }
174
175 ret = hid_hw_start(hdev, cmask);
176 if (ret) {
177 hid_err(hdev, "hw start failed\n");
178 goto err_free;
179 }
180
181 return 0;
182err_free:
183 return ret;
184}
185
186static const struct hid_device_id samsung_devices[] = {
187 { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) },
188 { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_WIRELESS_KBD_MOUSE) },
189 { }
190};
191MODULE_DEVICE_TABLE(hid, samsung_devices);
192
193static struct hid_driver samsung_driver = {
194 .name = "samsung",
195 .id_table = samsung_devices,
196 .report_fixup = samsung_report_fixup,
197 .input_mapping = samsung_input_mapping,
198 .probe = samsung_probe,
199};
200
201static int __init samsung_init(void)
202{
203 return hid_register_driver(&samsung_driver);
204}
205
206static void __exit samsung_exit(void)
207{
208 hid_unregister_driver(&samsung_driver);
209}
210
211module_init(samsung_init);
212module_exit(samsung_exit);
213MODULE_LICENSE("GPL");
214