Jiri Slaby | 980a3da | 2008-06-25 22:31:48 +0200 | [diff] [blame] | 1 | /* |
| 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 |
| 8 | * Copyright (c) 2007 Paul Walmsley |
| 9 | * Copyright (c) 2008 Jiri Slaby |
Don Prince | b355850 | 2010-05-17 11:42:39 +0100 | [diff] [blame] | 10 | * Copyright (c) 2010 Don Prince <dhprince.devel@yahoo.co.uk> |
| 11 | * |
| 12 | * |
| 13 | * This driver supports several HID devices: |
| 14 | * |
| 15 | * [0419:0001] Samsung IrDA remote controller (reports as Cypress USB Mouse). |
| 16 | * various hid report fixups for different variants. |
| 17 | * |
| 18 | * [0419:0600] Creative Desktop Wireless 6000 keyboard/mouse combo |
| 19 | * several key mappings used from the consumer usage page |
| 20 | * deviate from the USB HUT 1.12 standard. |
| 21 | * |
Jiri Slaby | 980a3da | 2008-06-25 22:31:48 +0200 | [diff] [blame] | 22 | */ |
| 23 | |
| 24 | /* |
| 25 | * This program is free software; you can redistribute it and/or modify it |
| 26 | * under the terms of the GNU General Public License as published by the Free |
| 27 | * Software Foundation; either version 2 of the License, or (at your option) |
| 28 | * any later version. |
| 29 | */ |
| 30 | |
| 31 | #include <linux/device.h> |
Don Prince | b355850 | 2010-05-17 11:42:39 +0100 | [diff] [blame] | 32 | #include <linux/usb.h> |
Jiri Slaby | 980a3da | 2008-06-25 22:31:48 +0200 | [diff] [blame] | 33 | #include <linux/hid.h> |
| 34 | #include <linux/module.h> |
| 35 | |
| 36 | #include "hid-ids.h" |
| 37 | |
| 38 | /* |
Robert Schedel | 0810b51 | 2009-06-23 11:26:48 +0200 | [diff] [blame] | 39 | * There are several variants for 0419:0001: |
| 40 | * |
| 41 | * 1. 184 byte report descriptor |
Jiri Slaby | 980a3da | 2008-06-25 22:31:48 +0200 | [diff] [blame] | 42 | * Vendor specific report #4 has a size of 48 bit, |
| 43 | * and therefore is not accepted when inspecting the descriptors. |
| 44 | * As a workaround we reinterpret the report as: |
| 45 | * Variable type, count 6, size 8 bit, log. maximum 255 |
| 46 | * The burden to reconstruct the data is moved into user space. |
Robert Schedel | 0810b51 | 2009-06-23 11:26:48 +0200 | [diff] [blame] | 47 | * |
| 48 | * 2. 203 byte report descriptor |
| 49 | * Report #4 has an array field with logical range 0..18 instead of 1..15. |
| 50 | * |
| 51 | * 3. 135 byte report descriptor |
| 52 | * Report #4 has an array field with logical range 0..17 instead of 1..14. |
Robert Schedel | 3975bc5 | 2009-12-11 00:37:11 +0100 | [diff] [blame] | 53 | * |
| 54 | * 4. 171 byte report descriptor |
| 55 | * Report #3 has an array field with logical range 0..1 instead of 1..3. |
Jiri Slaby | 980a3da | 2008-06-25 22:31:48 +0200 | [diff] [blame] | 56 | */ |
Don Prince | b355850 | 2010-05-17 11:42:39 +0100 | [diff] [blame] | 57 | static inline void samsung_irda_dev_trace(struct hid_device *hdev, |
Robert Schedel | 3975bc5 | 2009-12-11 00:37:11 +0100 | [diff] [blame] | 58 | unsigned int rsize) |
| 59 | { |
| 60 | dev_info(&hdev->dev, "fixing up Samsung IrDA %d byte report " |
| 61 | "descriptor\n", rsize); |
| 62 | } |
| 63 | |
Don Prince | b355850 | 2010-05-17 11:42:39 +0100 | [diff] [blame] | 64 | static void samsung_irda_report_fixup(struct hid_device *hdev, __u8 *rdesc, |
Jiri Slaby | 980a3da | 2008-06-25 22:31:48 +0200 | [diff] [blame] | 65 | unsigned int rsize) |
| 66 | { |
Robert Schedel | 0810b51 | 2009-06-23 11:26:48 +0200 | [diff] [blame] | 67 | if (rsize == 184 && rdesc[175] == 0x25 && rdesc[176] == 0x40 && |
Jiri Slaby | 980a3da | 2008-06-25 22:31:48 +0200 | [diff] [blame] | 68 | rdesc[177] == 0x75 && rdesc[178] == 0x30 && |
| 69 | rdesc[179] == 0x95 && rdesc[180] == 0x01 && |
| 70 | rdesc[182] == 0x40) { |
Don Prince | b355850 | 2010-05-17 11:42:39 +0100 | [diff] [blame] | 71 | samsung_irda_dev_trace(hdev, 184); |
Jiri Slaby | 980a3da | 2008-06-25 22:31:48 +0200 | [diff] [blame] | 72 | rdesc[176] = 0xff; |
| 73 | rdesc[178] = 0x08; |
| 74 | rdesc[180] = 0x06; |
| 75 | rdesc[182] = 0x42; |
Robert Schedel | 0810b51 | 2009-06-23 11:26:48 +0200 | [diff] [blame] | 76 | } else |
| 77 | if (rsize == 203 && rdesc[192] == 0x15 && rdesc[193] == 0x0 && |
| 78 | rdesc[194] == 0x25 && rdesc[195] == 0x12) { |
Don Prince | b355850 | 2010-05-17 11:42:39 +0100 | [diff] [blame] | 79 | samsung_irda_dev_trace(hdev, 203); |
Robert Schedel | 0810b51 | 2009-06-23 11:26:48 +0200 | [diff] [blame] | 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) { |
Don Prince | b355850 | 2010-05-17 11:42:39 +0100 | [diff] [blame] | 85 | samsung_irda_dev_trace(hdev, 135); |
Robert Schedel | 0810b51 | 2009-06-23 11:26:48 +0200 | [diff] [blame] | 86 | rdesc[125] = 0x1; |
| 87 | rdesc[127] = 0xe; |
Robert Schedel | 3975bc5 | 2009-12-11 00:37:11 +0100 | [diff] [blame] | 88 | } else |
| 89 | if (rsize == 171 && rdesc[160] == 0x15 && rdesc[161] == 0x0 && |
| 90 | rdesc[162] == 0x25 && rdesc[163] == 0x01) { |
Don Prince | b355850 | 2010-05-17 11:42:39 +0100 | [diff] [blame] | 91 | samsung_irda_dev_trace(hdev, 171); |
Robert Schedel | 3975bc5 | 2009-12-11 00:37:11 +0100 | [diff] [blame] | 92 | rdesc[161] = 0x1; |
| 93 | rdesc[163] = 0x3; |
Jiri Slaby | 980a3da | 2008-06-25 22:31:48 +0200 | [diff] [blame] | 94 | } |
| 95 | } |
| 96 | |
Don Prince | b355850 | 2010-05-17 11:42:39 +0100 | [diff] [blame] | 97 | #define samsung_kbd_mouse_map_key_clear(c) \ |
| 98 | hid_map_usage_clear(hi, usage, bit, max, EV_KEY, (c)) |
| 99 | |
| 100 | static 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 Prince | b355850 | 2010-05-17 11:42:39 +0100 | [diff] [blame] | 115 | 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 | |
| 133 | static void samsung_report_fixup(struct hid_device *hdev, __u8 *rdesc, |
| 134 | unsigned int rsize) |
| 135 | { |
| 136 | if (USB_DEVICE_ID_SAMSUNG_IR_REMOTE == hdev->product) |
| 137 | samsung_irda_report_fixup(hdev, rdesc, rsize); |
| 138 | } |
| 139 | |
| 140 | static int samsung_input_mapping(struct hid_device *hdev, struct hid_input *hi, |
| 141 | struct hid_field *field, struct hid_usage *usage, |
| 142 | unsigned long **bit, int *max) |
| 143 | { |
| 144 | int ret = 0; |
| 145 | |
| 146 | if (USB_DEVICE_ID_SAMSUNG_WIRELESS_KBD_MOUSE == hdev->product) |
| 147 | ret = samsung_kbd_mouse_input_mapping(hdev, |
| 148 | hi, field, usage, bit, max); |
| 149 | |
| 150 | return ret; |
| 151 | } |
| 152 | |
Jiri Slaby | 980a3da | 2008-06-25 22:31:48 +0200 | [diff] [blame] | 153 | static int samsung_probe(struct hid_device *hdev, |
| 154 | const struct hid_device_id *id) |
| 155 | { |
| 156 | int ret; |
Robert Schedel | 0810b51 | 2009-06-23 11:26:48 +0200 | [diff] [blame] | 157 | unsigned int cmask = HID_CONNECT_DEFAULT; |
Jiri Slaby | 980a3da | 2008-06-25 22:31:48 +0200 | [diff] [blame] | 158 | |
Jiri Slaby | 980a3da | 2008-06-25 22:31:48 +0200 | [diff] [blame] | 159 | ret = hid_parse(hdev); |
| 160 | if (ret) { |
| 161 | dev_err(&hdev->dev, "parse failed\n"); |
| 162 | goto err_free; |
| 163 | } |
| 164 | |
Don Prince | b355850 | 2010-05-17 11:42:39 +0100 | [diff] [blame] | 165 | if (USB_DEVICE_ID_SAMSUNG_IR_REMOTE == hdev->product) { |
| 166 | if (hdev->rsize == 184) { |
| 167 | /* disable hidinput, force hiddev */ |
| 168 | cmask = (cmask & ~HID_CONNECT_HIDINPUT) | |
| 169 | HID_CONNECT_HIDDEV_FORCE; |
| 170 | } |
Robert Schedel | 0810b51 | 2009-06-23 11:26:48 +0200 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | ret = hid_hw_start(hdev, cmask); |
Jiri Slaby | 980a3da | 2008-06-25 22:31:48 +0200 | [diff] [blame] | 174 | if (ret) { |
| 175 | dev_err(&hdev->dev, "hw start failed\n"); |
| 176 | goto err_free; |
| 177 | } |
| 178 | |
| 179 | return 0; |
| 180 | err_free: |
| 181 | return ret; |
| 182 | } |
| 183 | |
| 184 | static const struct hid_device_id samsung_devices[] = { |
| 185 | { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) }, |
Don Prince | b355850 | 2010-05-17 11:42:39 +0100 | [diff] [blame] | 186 | { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_WIRELESS_KBD_MOUSE) }, |
Jiri Slaby | 980a3da | 2008-06-25 22:31:48 +0200 | [diff] [blame] | 187 | { } |
| 188 | }; |
| 189 | MODULE_DEVICE_TABLE(hid, samsung_devices); |
| 190 | |
| 191 | static struct hid_driver samsung_driver = { |
| 192 | .name = "samsung", |
| 193 | .id_table = samsung_devices, |
| 194 | .report_fixup = samsung_report_fixup, |
Don Prince | b355850 | 2010-05-17 11:42:39 +0100 | [diff] [blame] | 195 | .input_mapping = samsung_input_mapping, |
Jiri Slaby | 980a3da | 2008-06-25 22:31:48 +0200 | [diff] [blame] | 196 | .probe = samsung_probe, |
| 197 | }; |
| 198 | |
Peter Huewe | a24f423b | 2009-07-02 19:08:38 +0200 | [diff] [blame] | 199 | static int __init samsung_init(void) |
Jiri Slaby | 980a3da | 2008-06-25 22:31:48 +0200 | [diff] [blame] | 200 | { |
| 201 | return hid_register_driver(&samsung_driver); |
| 202 | } |
| 203 | |
Peter Huewe | a24f423b | 2009-07-02 19:08:38 +0200 | [diff] [blame] | 204 | static void __exit samsung_exit(void) |
Jiri Slaby | 980a3da | 2008-06-25 22:31:48 +0200 | [diff] [blame] | 205 | { |
| 206 | hid_unregister_driver(&samsung_driver); |
| 207 | } |
| 208 | |
| 209 | module_init(samsung_init); |
| 210 | module_exit(samsung_exit); |
| 211 | MODULE_LICENSE("GPL"); |