blob: 4442c30ef531d33182e4ad6461ad8f309727e99e [file] [log] [blame]
Jiri Slaby949f8fe2008-07-24 23:35:13 +02001/*
2 * HID driver for some gyration "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
Jiri Slaby949f8fe2008-07-24 23:35:13 +02007 * Copyright (c) 2008 Jiri Slaby
Jiri Kosina1e093202008-10-17 11:52:23 +02008 * Copyright (c) 2006-2008 Jiri Kosina
Jiri Slaby949f8fe2008-07-24 23:35:13 +02009 */
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/input.h>
20#include <linux/hid.h>
21#include <linux/module.h>
22
23#include "hid-ids.h"
24
25#define gy_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \
26 EV_KEY, (c))
27static int gyration_input_mapping(struct hid_device *hdev, struct hid_input *hi,
28 struct hid_field *field, struct hid_usage *usage,
29 unsigned long **bit, int *max)
30{
31 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_LOGIVENDOR)
32 return 0;
33
34 set_bit(EV_REP, hi->input->evbit);
35 switch (usage->hid & HID_USAGE) {
36 /* Reported on Gyration MCE Remote */
37 case 0x00d: gy_map_key_clear(KEY_HOME); break;
38 case 0x024: gy_map_key_clear(KEY_DVD); break;
39 case 0x025: gy_map_key_clear(KEY_PVR); break;
40 case 0x046: gy_map_key_clear(KEY_MEDIA); break;
41 case 0x047: gy_map_key_clear(KEY_MP3); break;
Jiri Kosina1e093202008-10-17 11:52:23 +020042 case 0x048: gy_map_key_clear(KEY_MEDIA); break;
Jiri Slaby949f8fe2008-07-24 23:35:13 +020043 case 0x049: gy_map_key_clear(KEY_CAMERA); break;
44 case 0x04a: gy_map_key_clear(KEY_VIDEO); break;
Steffen Barszus6497dc32011-02-14 19:53:48 +010045 case 0x05a: gy_map_key_clear(KEY_TEXT); break;
46 case 0x05b: gy_map_key_clear(KEY_RED); break;
47 case 0x05c: gy_map_key_clear(KEY_GREEN); break;
48 case 0x05d: gy_map_key_clear(KEY_YELLOW); break;
49 case 0x05e: gy_map_key_clear(KEY_BLUE); break;
Jiri Slaby949f8fe2008-07-24 23:35:13 +020050
51 default:
52 return 0;
53 }
54 return 1;
55}
56
57static int gyration_event(struct hid_device *hdev, struct hid_field *field,
58 struct hid_usage *usage, __s32 value)
59{
Jiri Kosinad8e4ebf2010-03-23 16:32:37 +010060
61 if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput)
62 return 0;
Jiri Slaby949f8fe2008-07-24 23:35:13 +020063
64 if ((usage->hid & HID_USAGE_PAGE) == HID_UP_GENDESK &&
65 (usage->hid & 0xff) == 0x82) {
Jiri Kosinad8e4ebf2010-03-23 16:32:37 +010066 struct input_dev *input = field->hidinput->input;
Jiri Slaby949f8fe2008-07-24 23:35:13 +020067 input_event(input, usage->type, usage->code, 1);
68 input_sync(input);
69 input_event(input, usage->type, usage->code, 0);
70 input_sync(input);
71 return 1;
72 }
73
74 return 0;
75}
76
77static const struct hid_device_id gyration_devices[] = {
78 { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE) },
Jiri Kosina1e093202008-10-17 11:52:23 +020079 { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_2) },
Cory Maccarronec2fd1a42010-05-22 13:00:28 -070080 { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_3) },
Jiri Slaby949f8fe2008-07-24 23:35:13 +020081 { }
82};
83MODULE_DEVICE_TABLE(hid, gyration_devices);
84
85static struct hid_driver gyration_driver = {
86 .name = "gyration",
87 .id_table = gyration_devices,
88 .input_mapping = gyration_input_mapping,
89 .event = gyration_event,
90};
91
Peter Huewea24f423b2009-07-02 19:08:38 +020092static int __init gyration_init(void)
Jiri Slaby949f8fe2008-07-24 23:35:13 +020093{
94 return hid_register_driver(&gyration_driver);
95}
96
Peter Huewea24f423b2009-07-02 19:08:38 +020097static void __exit gyration_exit(void)
Jiri Slaby949f8fe2008-07-24 23:35:13 +020098{
99 hid_unregister_driver(&gyration_driver);
100}
101
102module_init(gyration_init);
103module_exit(gyration_exit);
104MODULE_LICENSE("GPL");