Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Jiri Slaby | 1e76253 | 2008-06-24 23:46:21 +0200 | [diff] [blame] | 2 | /* |
| 3 | * HID driver for some petalynx "special" devices |
| 4 | * |
| 5 | * Copyright (c) 1999 Andreas Gal |
| 6 | * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> |
| 7 | * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc |
| 8 | * Copyright (c) 2006-2007 Jiri Kosina |
Jiri Slaby | 1e76253 | 2008-06-24 23:46:21 +0200 | [diff] [blame] | 9 | * Copyright (c) 2008 Jiri Slaby |
| 10 | */ |
| 11 | |
| 12 | /* |
Jiri Slaby | 1e76253 | 2008-06-24 23:46:21 +0200 | [diff] [blame] | 13 | */ |
| 14 | |
| 15 | #include <linux/device.h> |
| 16 | #include <linux/hid.h> |
| 17 | #include <linux/module.h> |
| 18 | |
| 19 | #include "hid-ids.h" |
| 20 | |
| 21 | /* Petalynx Maxter Remote has maximum for consumer page set too low */ |
Nikolai Kondrashov | 73e4008 | 2010-08-06 23:03:06 +0400 | [diff] [blame] | 22 | static __u8 *pl_report_fixup(struct hid_device *hdev, __u8 *rdesc, |
| 23 | unsigned int *rsize) |
Jiri Slaby | 1e76253 | 2008-06-24 23:46:21 +0200 | [diff] [blame] | 24 | { |
Jiri Kosina | 4ab2578 | 2014-08-21 09:57:48 -0500 | [diff] [blame] | 25 | if (*rsize >= 62 && rdesc[39] == 0x2a && rdesc[40] == 0xf5 && |
Jiri Slaby | 1e76253 | 2008-06-24 23:46:21 +0200 | [diff] [blame] | 26 | rdesc[41] == 0x00 && rdesc[59] == 0x26 && |
| 27 | rdesc[60] == 0xf9 && rdesc[61] == 0x00) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 28 | hid_info(hdev, "fixing up Petalynx Maxter Remote report descriptor\n"); |
Jiri Slaby | 1e76253 | 2008-06-24 23:46:21 +0200 | [diff] [blame] | 29 | rdesc[60] = 0xfa; |
| 30 | rdesc[40] = 0xfa; |
| 31 | } |
Nikolai Kondrashov | 73e4008 | 2010-08-06 23:03:06 +0400 | [diff] [blame] | 32 | return rdesc; |
Jiri Slaby | 1e76253 | 2008-06-24 23:46:21 +0200 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | #define pl_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \ |
| 36 | EV_KEY, (c)) |
| 37 | static int pl_input_mapping(struct hid_device *hdev, struct hid_input *hi, |
| 38 | struct hid_field *field, struct hid_usage *usage, |
| 39 | unsigned long **bit, int *max) |
| 40 | { |
| 41 | if ((usage->hid & HID_USAGE_PAGE) == HID_UP_LOGIVENDOR) { |
| 42 | switch (usage->hid & HID_USAGE) { |
| 43 | case 0x05a: pl_map_key_clear(KEY_TEXT); break; |
| 44 | case 0x05b: pl_map_key_clear(KEY_RED); break; |
| 45 | case 0x05c: pl_map_key_clear(KEY_GREEN); break; |
| 46 | case 0x05d: pl_map_key_clear(KEY_YELLOW); break; |
| 47 | case 0x05e: pl_map_key_clear(KEY_BLUE); break; |
| 48 | default: |
| 49 | return 0; |
| 50 | } |
| 51 | return 1; |
| 52 | } |
| 53 | |
| 54 | if ((usage->hid & HID_USAGE_PAGE) == HID_UP_CONSUMER) { |
| 55 | switch (usage->hid & HID_USAGE) { |
| 56 | case 0x0f6: pl_map_key_clear(KEY_NEXT); break; |
| 57 | case 0x0fa: pl_map_key_clear(KEY_BACK); break; |
| 58 | default: |
| 59 | return 0; |
| 60 | } |
| 61 | return 1; |
| 62 | } |
| 63 | |
| 64 | return 0; |
| 65 | } |
| 66 | |
| 67 | static int pl_probe(struct hid_device *hdev, const struct hid_device_id *id) |
| 68 | { |
| 69 | int ret; |
| 70 | |
| 71 | hdev->quirks |= HID_QUIRK_NOGET; |
| 72 | |
| 73 | ret = hid_parse(hdev); |
| 74 | if (ret) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 75 | hid_err(hdev, "parse failed\n"); |
Jiri Slaby | 1e76253 | 2008-06-24 23:46:21 +0200 | [diff] [blame] | 76 | goto err_free; |
| 77 | } |
| 78 | |
Jiri Slaby | 93c1013 | 2008-06-27 00:04:24 +0200 | [diff] [blame] | 79 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); |
Jiri Slaby | 1e76253 | 2008-06-24 23:46:21 +0200 | [diff] [blame] | 80 | if (ret) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 81 | hid_err(hdev, "hw start failed\n"); |
Jiri Slaby | 1e76253 | 2008-06-24 23:46:21 +0200 | [diff] [blame] | 82 | goto err_free; |
| 83 | } |
| 84 | |
| 85 | return 0; |
| 86 | err_free: |
| 87 | return ret; |
| 88 | } |
| 89 | |
| 90 | static const struct hid_device_id pl_devices[] = { |
| 91 | { HID_USB_DEVICE(USB_VENDOR_ID_PETALYNX, USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE) }, |
| 92 | { } |
| 93 | }; |
| 94 | MODULE_DEVICE_TABLE(hid, pl_devices); |
| 95 | |
| 96 | static struct hid_driver pl_driver = { |
| 97 | .name = "petalynx", |
| 98 | .id_table = pl_devices, |
| 99 | .report_fixup = pl_report_fixup, |
| 100 | .input_mapping = pl_input_mapping, |
| 101 | .probe = pl_probe, |
| 102 | }; |
H Hartley Sweeten | f425458 | 2012-12-17 15:28:26 -0700 | [diff] [blame] | 103 | module_hid_driver(pl_driver); |
Jiri Slaby | 1e76253 | 2008-06-24 23:46:21 +0200 | [diff] [blame] | 104 | |
Jiri Slaby | 1e76253 | 2008-06-24 23:46:21 +0200 | [diff] [blame] | 105 | MODULE_LICENSE("GPL"); |