xref: /openbmc/linux/drivers/hid/hid-petalynx.c (revision baa7eb025ab14f3cba2e35c0a8648f9c9f01d24f)
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 */
26 static __u8 *pl_report_fixup(struct hid_device *hdev, __u8 *rdesc,
27 		unsigned int *rsize)
28 {
29 	if (*rsize >= 60 && rdesc[39] == 0x2a && rdesc[40] == 0xf5 &&
30 			rdesc[41] == 0x00 && rdesc[59] == 0x26 &&
31 			rdesc[60] == 0xf9 && rdesc[61] == 0x00) {
32 		dev_info(&hdev->dev, "fixing up Petalynx Maxter Remote report "
33 				"descriptor\n");
34 		rdesc[60] = 0xfa;
35 		rdesc[40] = 0xfa;
36 	}
37 	return rdesc;
38 }
39 
40 #define pl_map_key_clear(c)	hid_map_usage_clear(hi, usage, bit, max, \
41 					EV_KEY, (c))
42 static int pl_input_mapping(struct hid_device *hdev, struct hid_input *hi,
43 		struct hid_field *field, struct hid_usage *usage,
44 		unsigned long **bit, int *max)
45 {
46 	if ((usage->hid & HID_USAGE_PAGE) == HID_UP_LOGIVENDOR) {
47 		switch (usage->hid & HID_USAGE) {
48 		case 0x05a: pl_map_key_clear(KEY_TEXT);		break;
49 		case 0x05b: pl_map_key_clear(KEY_RED);		break;
50 		case 0x05c: pl_map_key_clear(KEY_GREEN);	break;
51 		case 0x05d: pl_map_key_clear(KEY_YELLOW);	break;
52 		case 0x05e: pl_map_key_clear(KEY_BLUE);		break;
53 		default:
54 			return 0;
55 		}
56 		return 1;
57 	}
58 
59 	if ((usage->hid & HID_USAGE_PAGE) == HID_UP_CONSUMER) {
60 		switch (usage->hid & HID_USAGE) {
61 		case 0x0f6: pl_map_key_clear(KEY_NEXT);		break;
62 		case 0x0fa: pl_map_key_clear(KEY_BACK);		break;
63 		default:
64 			return 0;
65 		}
66 		return 1;
67 	}
68 
69 	return 0;
70 }
71 
72 static int pl_probe(struct hid_device *hdev, const struct hid_device_id *id)
73 {
74 	int ret;
75 
76 	hdev->quirks |= HID_QUIRK_NOGET;
77 
78 	ret = hid_parse(hdev);
79 	if (ret) {
80 		dev_err(&hdev->dev, "parse failed\n");
81 		goto err_free;
82 	}
83 
84 	ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
85 	if (ret) {
86 		dev_err(&hdev->dev, "hw start failed\n");
87 		goto err_free;
88 	}
89 
90 	return 0;
91 err_free:
92 	return ret;
93 }
94 
95 static const struct hid_device_id pl_devices[] = {
96 	{ HID_USB_DEVICE(USB_VENDOR_ID_PETALYNX, USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE) },
97 	{ }
98 };
99 MODULE_DEVICE_TABLE(hid, pl_devices);
100 
101 static struct hid_driver pl_driver = {
102 	.name = "petalynx",
103 	.id_table = pl_devices,
104 	.report_fixup = pl_report_fixup,
105 	.input_mapping = pl_input_mapping,
106 	.probe = pl_probe,
107 };
108 
109 static int __init pl_init(void)
110 {
111 	return hid_register_driver(&pl_driver);
112 }
113 
114 static void __exit pl_exit(void)
115 {
116 	hid_unregister_driver(&pl_driver);
117 }
118 
119 module_init(pl_init);
120 module_exit(pl_exit);
121 MODULE_LICENSE("GPL");
122