blob: 6aca4f2554bf4d748df6fc629276704e740ea40e [file] [log] [blame]
Jiri Slaby1e762532008-06-24 23:46:21 +02001/*
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
Jiri Slaby1e762532008-06-24 23:46:21 +02008 * Copyright (c) 2008 Jiri Slaby
9 */
10
11/*
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the Free
14 * Software Foundation; either version 2 of the License, or (at your option)
15 * any later version.
16 */
17
18#include <linux/device.h>
19#include <linux/hid.h>
20#include <linux/module.h>
21
22#include "hid-ids.h"
23
24/* Petalynx Maxter Remote has maximum for consumer page set too low */
Nikolai Kondrashov73e40082010-08-06 23:03:06 +040025static __u8 *pl_report_fixup(struct hid_device *hdev, __u8 *rdesc,
26 unsigned int *rsize)
Jiri Slaby1e762532008-06-24 23:46:21 +020027{
Jiri Kosina4ab25782014-08-21 09:57:48 -050028 if (*rsize >= 62 && rdesc[39] == 0x2a && rdesc[40] == 0xf5 &&
Jiri Slaby1e762532008-06-24 23:46:21 +020029 rdesc[41] == 0x00 && rdesc[59] == 0x26 &&
30 rdesc[60] == 0xf9 && rdesc[61] == 0x00) {
Joe Perches4291ee32010-12-09 19:29:03 -080031 hid_info(hdev, "fixing up Petalynx Maxter Remote report descriptor\n");
Jiri Slaby1e762532008-06-24 23:46:21 +020032 rdesc[60] = 0xfa;
33 rdesc[40] = 0xfa;
34 }
Nikolai Kondrashov73e40082010-08-06 23:03:06 +040035 return rdesc;
Jiri Slaby1e762532008-06-24 23:46:21 +020036}
37
38#define pl_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \
39 EV_KEY, (c))
40static int pl_input_mapping(struct hid_device *hdev, struct hid_input *hi,
41 struct hid_field *field, struct hid_usage *usage,
42 unsigned long **bit, int *max)
43{
44 if ((usage->hid & HID_USAGE_PAGE) == HID_UP_LOGIVENDOR) {
45 switch (usage->hid & HID_USAGE) {
46 case 0x05a: pl_map_key_clear(KEY_TEXT); break;
47 case 0x05b: pl_map_key_clear(KEY_RED); break;
48 case 0x05c: pl_map_key_clear(KEY_GREEN); break;
49 case 0x05d: pl_map_key_clear(KEY_YELLOW); break;
50 case 0x05e: pl_map_key_clear(KEY_BLUE); break;
51 default:
52 return 0;
53 }
54 return 1;
55 }
56
57 if ((usage->hid & HID_USAGE_PAGE) == HID_UP_CONSUMER) {
58 switch (usage->hid & HID_USAGE) {
59 case 0x0f6: pl_map_key_clear(KEY_NEXT); break;
60 case 0x0fa: pl_map_key_clear(KEY_BACK); break;
61 default:
62 return 0;
63 }
64 return 1;
65 }
66
67 return 0;
68}
69
70static int pl_probe(struct hid_device *hdev, const struct hid_device_id *id)
71{
72 int ret;
73
74 hdev->quirks |= HID_QUIRK_NOGET;
75
76 ret = hid_parse(hdev);
77 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -080078 hid_err(hdev, "parse failed\n");
Jiri Slaby1e762532008-06-24 23:46:21 +020079 goto err_free;
80 }
81
Jiri Slaby93c10132008-06-27 00:04:24 +020082 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
Jiri Slaby1e762532008-06-24 23:46:21 +020083 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -080084 hid_err(hdev, "hw start failed\n");
Jiri Slaby1e762532008-06-24 23:46:21 +020085 goto err_free;
86 }
87
88 return 0;
89err_free:
90 return ret;
91}
92
93static const struct hid_device_id pl_devices[] = {
94 { HID_USB_DEVICE(USB_VENDOR_ID_PETALYNX, USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE) },
95 { }
96};
97MODULE_DEVICE_TABLE(hid, pl_devices);
98
99static struct hid_driver pl_driver = {
100 .name = "petalynx",
101 .id_table = pl_devices,
102 .report_fixup = pl_report_fixup,
103 .input_mapping = pl_input_mapping,
104 .probe = pl_probe,
105};
H Hartley Sweetenf4254582012-12-17 15:28:26 -0700106module_hid_driver(pl_driver);
Jiri Slaby1e762532008-06-24 23:46:21 +0200107
Jiri Slaby1e762532008-06-24 23:46:21 +0200108MODULE_LICENSE("GPL");