Jiri Slaby | 1e76253 | 2008-06-24 23:46:21 +0200 | [diff] [blame] | 1 | /* |
| 2 | * HID driver for some petalynx "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 | /* Petalynx Maxter Remote has maximum for consumer page set too low */ |
Nikolai Kondrashov | 73e4008 | 2010-08-06 23:03:06 +0400 | [diff] [blame] | 26 | static __u8 *pl_report_fixup(struct hid_device *hdev, __u8 *rdesc, |
| 27 | unsigned int *rsize) |
Jiri Slaby | 1e76253 | 2008-06-24 23:46:21 +0200 | [diff] [blame] | 28 | { |
Nikolai Kondrashov | 73e4008 | 2010-08-06 23:03:06 +0400 | [diff] [blame] | 29 | if (*rsize >= 60 && rdesc[39] == 0x2a && rdesc[40] == 0xf5 && |
Jiri Slaby | 1e76253 | 2008-06-24 23:46:21 +0200 | [diff] [blame] | 30 | rdesc[41] == 0x00 && rdesc[59] == 0x26 && |
| 31 | rdesc[60] == 0xf9 && rdesc[61] == 0x00) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 32 | hid_info(hdev, "fixing up Petalynx Maxter Remote report descriptor\n"); |
Jiri Slaby | 1e76253 | 2008-06-24 23:46:21 +0200 | [diff] [blame] | 33 | rdesc[60] = 0xfa; |
| 34 | rdesc[40] = 0xfa; |
| 35 | } |
Nikolai Kondrashov | 73e4008 | 2010-08-06 23:03:06 +0400 | [diff] [blame] | 36 | return rdesc; |
Jiri Slaby | 1e76253 | 2008-06-24 23:46:21 +0200 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | #define pl_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \ |
| 40 | EV_KEY, (c)) |
| 41 | static int pl_input_mapping(struct hid_device *hdev, struct hid_input *hi, |
| 42 | struct hid_field *field, struct hid_usage *usage, |
| 43 | unsigned long **bit, int *max) |
| 44 | { |
| 45 | if ((usage->hid & HID_USAGE_PAGE) == HID_UP_LOGIVENDOR) { |
| 46 | switch (usage->hid & HID_USAGE) { |
| 47 | case 0x05a: pl_map_key_clear(KEY_TEXT); break; |
| 48 | case 0x05b: pl_map_key_clear(KEY_RED); break; |
| 49 | case 0x05c: pl_map_key_clear(KEY_GREEN); break; |
| 50 | case 0x05d: pl_map_key_clear(KEY_YELLOW); break; |
| 51 | case 0x05e: pl_map_key_clear(KEY_BLUE); break; |
| 52 | default: |
| 53 | return 0; |
| 54 | } |
| 55 | return 1; |
| 56 | } |
| 57 | |
| 58 | if ((usage->hid & HID_USAGE_PAGE) == HID_UP_CONSUMER) { |
| 59 | switch (usage->hid & HID_USAGE) { |
| 60 | case 0x0f6: pl_map_key_clear(KEY_NEXT); break; |
| 61 | case 0x0fa: pl_map_key_clear(KEY_BACK); break; |
| 62 | default: |
| 63 | return 0; |
| 64 | } |
| 65 | return 1; |
| 66 | } |
| 67 | |
| 68 | return 0; |
| 69 | } |
| 70 | |
| 71 | static int pl_probe(struct hid_device *hdev, const struct hid_device_id *id) |
| 72 | { |
| 73 | int ret; |
| 74 | |
| 75 | hdev->quirks |= HID_QUIRK_NOGET; |
| 76 | |
| 77 | ret = hid_parse(hdev); |
| 78 | if (ret) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 79 | hid_err(hdev, "parse failed\n"); |
Jiri Slaby | 1e76253 | 2008-06-24 23:46:21 +0200 | [diff] [blame] | 80 | goto err_free; |
| 81 | } |
| 82 | |
Jiri Slaby | 93c1013 | 2008-06-27 00:04:24 +0200 | [diff] [blame] | 83 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); |
Jiri Slaby | 1e76253 | 2008-06-24 23:46:21 +0200 | [diff] [blame] | 84 | if (ret) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 85 | hid_err(hdev, "hw start failed\n"); |
Jiri Slaby | 1e76253 | 2008-06-24 23:46:21 +0200 | [diff] [blame] | 86 | goto err_free; |
| 87 | } |
| 88 | |
| 89 | return 0; |
| 90 | err_free: |
| 91 | return ret; |
| 92 | } |
| 93 | |
| 94 | static const struct hid_device_id pl_devices[] = { |
| 95 | { HID_USB_DEVICE(USB_VENDOR_ID_PETALYNX, USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE) }, |
| 96 | { } |
| 97 | }; |
| 98 | MODULE_DEVICE_TABLE(hid, pl_devices); |
| 99 | |
| 100 | static struct hid_driver pl_driver = { |
| 101 | .name = "petalynx", |
| 102 | .id_table = pl_devices, |
| 103 | .report_fixup = pl_report_fixup, |
| 104 | .input_mapping = pl_input_mapping, |
| 105 | .probe = pl_probe, |
| 106 | }; |
| 107 | |
Peter Huewe | a24f423 | 2009-07-02 19:08:38 +0200 | [diff] [blame] | 108 | static int __init pl_init(void) |
Jiri Slaby | 1e76253 | 2008-06-24 23:46:21 +0200 | [diff] [blame] | 109 | { |
| 110 | return hid_register_driver(&pl_driver); |
| 111 | } |
| 112 | |
Peter Huewe | a24f423 | 2009-07-02 19:08:38 +0200 | [diff] [blame] | 113 | static void __exit pl_exit(void) |
Jiri Slaby | 1e76253 | 2008-06-24 23:46:21 +0200 | [diff] [blame] | 114 | { |
| 115 | hid_unregister_driver(&pl_driver); |
| 116 | } |
| 117 | |
| 118 | module_init(pl_init); |
| 119 | module_exit(pl_exit); |
| 120 | MODULE_LICENSE("GPL"); |