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 |
| 10 | */ |
| 11 | |
| 12 | /* |
| 13 | * This program is free software; you can redistribute it and/or modify it |
| 14 | * under the terms of the GNU General Public License as published by the Free |
| 15 | * Software Foundation; either version 2 of the License, or (at your option) |
| 16 | * any later version. |
| 17 | */ |
| 18 | |
| 19 | #include <linux/device.h> |
| 20 | #include <linux/hid.h> |
| 21 | #include <linux/module.h> |
| 22 | |
| 23 | #include "hid-ids.h" |
| 24 | |
| 25 | /* |
| 26 | * Samsung IrDA remote controller (reports as Cypress USB Mouse). |
| 27 | * |
Robert Schedel | 0810b51 | 2009-06-23 11:26:48 +0200 | [diff] [blame] | 28 | * There are several variants for 0419:0001: |
| 29 | * |
| 30 | * 1. 184 byte report descriptor |
Jiri Slaby | 980a3da | 2008-06-25 22:31:48 +0200 | [diff] [blame] | 31 | * Vendor specific report #4 has a size of 48 bit, |
| 32 | * and therefore is not accepted when inspecting the descriptors. |
| 33 | * As a workaround we reinterpret the report as: |
| 34 | * Variable type, count 6, size 8 bit, log. maximum 255 |
| 35 | * The burden to reconstruct the data is moved into user space. |
Robert Schedel | 0810b51 | 2009-06-23 11:26:48 +0200 | [diff] [blame] | 36 | * |
| 37 | * 2. 203 byte report descriptor |
| 38 | * Report #4 has an array field with logical range 0..18 instead of 1..15. |
| 39 | * |
| 40 | * 3. 135 byte report descriptor |
| 41 | * Report #4 has an array field with logical range 0..17 instead of 1..14. |
Jiri Slaby | 980a3da | 2008-06-25 22:31:48 +0200 | [diff] [blame] | 42 | */ |
| 43 | static void samsung_report_fixup(struct hid_device *hdev, __u8 *rdesc, |
| 44 | unsigned int rsize) |
| 45 | { |
Robert Schedel | 0810b51 | 2009-06-23 11:26:48 +0200 | [diff] [blame] | 46 | if (rsize == 184 && rdesc[175] == 0x25 && rdesc[176] == 0x40 && |
Jiri Slaby | 980a3da | 2008-06-25 22:31:48 +0200 | [diff] [blame] | 47 | rdesc[177] == 0x75 && rdesc[178] == 0x30 && |
| 48 | rdesc[179] == 0x95 && rdesc[180] == 0x01 && |
| 49 | rdesc[182] == 0x40) { |
Robert Schedel | 0810b51 | 2009-06-23 11:26:48 +0200 | [diff] [blame] | 50 | dev_info(&hdev->dev, "fixing up Samsung IrDA %d byte report " |
| 51 | "descriptor\n", 184); |
Jiri Slaby | 980a3da | 2008-06-25 22:31:48 +0200 | [diff] [blame] | 52 | rdesc[176] = 0xff; |
| 53 | rdesc[178] = 0x08; |
| 54 | rdesc[180] = 0x06; |
| 55 | rdesc[182] = 0x42; |
Robert Schedel | 0810b51 | 2009-06-23 11:26:48 +0200 | [diff] [blame] | 56 | } else |
| 57 | if (rsize == 203 && rdesc[192] == 0x15 && rdesc[193] == 0x0 && |
| 58 | rdesc[194] == 0x25 && rdesc[195] == 0x12) { |
| 59 | dev_info(&hdev->dev, "fixing up Samsung IrDA %d byte report " |
| 60 | "descriptor\n", 203); |
| 61 | rdesc[193] = 0x1; |
| 62 | rdesc[195] = 0xf; |
| 63 | } else |
| 64 | if (rsize == 135 && rdesc[124] == 0x15 && rdesc[125] == 0x0 && |
| 65 | rdesc[126] == 0x25 && rdesc[127] == 0x11) { |
| 66 | dev_info(&hdev->dev, "fixing up Samsung IrDA %d byte report " |
| 67 | "descriptor\n", 135); |
| 68 | rdesc[125] = 0x1; |
| 69 | rdesc[127] = 0xe; |
Jiri Slaby | 980a3da | 2008-06-25 22:31:48 +0200 | [diff] [blame] | 70 | } |
| 71 | } |
| 72 | |
| 73 | static int samsung_probe(struct hid_device *hdev, |
| 74 | const struct hid_device_id *id) |
| 75 | { |
| 76 | int ret; |
Robert Schedel | 0810b51 | 2009-06-23 11:26:48 +0200 | [diff] [blame] | 77 | unsigned int cmask = HID_CONNECT_DEFAULT; |
Jiri Slaby | 980a3da | 2008-06-25 22:31:48 +0200 | [diff] [blame] | 78 | |
Jiri Slaby | 980a3da | 2008-06-25 22:31:48 +0200 | [diff] [blame] | 79 | ret = hid_parse(hdev); |
| 80 | if (ret) { |
| 81 | dev_err(&hdev->dev, "parse failed\n"); |
| 82 | goto err_free; |
| 83 | } |
| 84 | |
Robert Schedel | 0810b51 | 2009-06-23 11:26:48 +0200 | [diff] [blame] | 85 | if (hdev->rsize == 184) { |
| 86 | /* disable hidinput, force hiddev */ |
| 87 | cmask = (cmask & ~HID_CONNECT_HIDINPUT) | |
| 88 | HID_CONNECT_HIDDEV_FORCE; |
| 89 | } |
| 90 | |
| 91 | ret = hid_hw_start(hdev, cmask); |
Jiri Slaby | 980a3da | 2008-06-25 22:31:48 +0200 | [diff] [blame] | 92 | if (ret) { |
| 93 | dev_err(&hdev->dev, "hw start failed\n"); |
| 94 | goto err_free; |
| 95 | } |
| 96 | |
| 97 | return 0; |
| 98 | err_free: |
| 99 | return ret; |
| 100 | } |
| 101 | |
| 102 | static const struct hid_device_id samsung_devices[] = { |
| 103 | { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) }, |
| 104 | { } |
| 105 | }; |
| 106 | MODULE_DEVICE_TABLE(hid, samsung_devices); |
| 107 | |
| 108 | static struct hid_driver samsung_driver = { |
| 109 | .name = "samsung", |
| 110 | .id_table = samsung_devices, |
| 111 | .report_fixup = samsung_report_fixup, |
| 112 | .probe = samsung_probe, |
| 113 | }; |
| 114 | |
Peter Huewe | a24f423b | 2009-07-02 19:08:38 +0200 | [diff] [blame] | 115 | static int __init samsung_init(void) |
Jiri Slaby | 980a3da | 2008-06-25 22:31:48 +0200 | [diff] [blame] | 116 | { |
| 117 | return hid_register_driver(&samsung_driver); |
| 118 | } |
| 119 | |
Peter Huewe | a24f423b | 2009-07-02 19:08:38 +0200 | [diff] [blame] | 120 | static void __exit samsung_exit(void) |
Jiri Slaby | 980a3da | 2008-06-25 22:31:48 +0200 | [diff] [blame] | 121 | { |
| 122 | hid_unregister_driver(&samsung_driver); |
| 123 | } |
| 124 | |
| 125 | module_init(samsung_init); |
| 126 | module_exit(samsung_exit); |
| 127 | MODULE_LICENSE("GPL"); |