1*2874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
2949f8fefSJiri Slaby /*
3949f8fefSJiri Slaby * HID driver for some gyration "special" devices
4949f8fefSJiri Slaby *
5949f8fefSJiri Slaby * Copyright (c) 1999 Andreas Gal
6949f8fefSJiri Slaby * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
7949f8fefSJiri Slaby * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
8949f8fefSJiri Slaby * Copyright (c) 2008 Jiri Slaby
91e093206SJiri Kosina * Copyright (c) 2006-2008 Jiri Kosina
10949f8fefSJiri Slaby */
11949f8fefSJiri Slaby
12949f8fefSJiri Slaby /*
13949f8fefSJiri Slaby */
14949f8fefSJiri Slaby
15949f8fefSJiri Slaby #include <linux/device.h>
16949f8fefSJiri Slaby #include <linux/input.h>
17949f8fefSJiri Slaby #include <linux/hid.h>
18949f8fefSJiri Slaby #include <linux/module.h>
19949f8fefSJiri Slaby
20949f8fefSJiri Slaby #include "hid-ids.h"
21949f8fefSJiri Slaby
22949f8fefSJiri Slaby #define gy_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \
23949f8fefSJiri Slaby EV_KEY, (c))
gyration_input_mapping(struct hid_device * hdev,struct hid_input * hi,struct hid_field * field,struct hid_usage * usage,unsigned long ** bit,int * max)24949f8fefSJiri Slaby static int gyration_input_mapping(struct hid_device *hdev, struct hid_input *hi,
25949f8fefSJiri Slaby struct hid_field *field, struct hid_usage *usage,
26949f8fefSJiri Slaby unsigned long **bit, int *max)
27949f8fefSJiri Slaby {
28949f8fefSJiri Slaby if ((usage->hid & HID_USAGE_PAGE) != HID_UP_LOGIVENDOR)
29949f8fefSJiri Slaby return 0;
30949f8fefSJiri Slaby
31949f8fefSJiri Slaby set_bit(EV_REP, hi->input->evbit);
32949f8fefSJiri Slaby switch (usage->hid & HID_USAGE) {
33949f8fefSJiri Slaby /* Reported on Gyration MCE Remote */
34949f8fefSJiri Slaby case 0x00d: gy_map_key_clear(KEY_HOME); break;
35949f8fefSJiri Slaby case 0x024: gy_map_key_clear(KEY_DVD); break;
36949f8fefSJiri Slaby case 0x025: gy_map_key_clear(KEY_PVR); break;
37949f8fefSJiri Slaby case 0x046: gy_map_key_clear(KEY_MEDIA); break;
38949f8fefSJiri Slaby case 0x047: gy_map_key_clear(KEY_MP3); break;
391e093206SJiri Kosina case 0x048: gy_map_key_clear(KEY_MEDIA); break;
40949f8fefSJiri Slaby case 0x049: gy_map_key_clear(KEY_CAMERA); break;
41949f8fefSJiri Slaby case 0x04a: gy_map_key_clear(KEY_VIDEO); break;
426497dc3aSSteffen Barszus case 0x05a: gy_map_key_clear(KEY_TEXT); break;
436497dc3aSSteffen Barszus case 0x05b: gy_map_key_clear(KEY_RED); break;
446497dc3aSSteffen Barszus case 0x05c: gy_map_key_clear(KEY_GREEN); break;
456497dc3aSSteffen Barszus case 0x05d: gy_map_key_clear(KEY_YELLOW); break;
466497dc3aSSteffen Barszus case 0x05e: gy_map_key_clear(KEY_BLUE); break;
47949f8fefSJiri Slaby
48949f8fefSJiri Slaby default:
49949f8fefSJiri Slaby return 0;
50949f8fefSJiri Slaby }
51949f8fefSJiri Slaby return 1;
52949f8fefSJiri Slaby }
53949f8fefSJiri Slaby
gyration_event(struct hid_device * hdev,struct hid_field * field,struct hid_usage * usage,__s32 value)54949f8fefSJiri Slaby static int gyration_event(struct hid_device *hdev, struct hid_field *field,
55949f8fefSJiri Slaby struct hid_usage *usage, __s32 value)
56949f8fefSJiri Slaby {
57d8e4ebf8SJiri Kosina
58d8e4ebf8SJiri Kosina if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput)
59d8e4ebf8SJiri Kosina return 0;
60949f8fefSJiri Slaby
61949f8fefSJiri Slaby if ((usage->hid & HID_USAGE_PAGE) == HID_UP_GENDESK &&
62949f8fefSJiri Slaby (usage->hid & 0xff) == 0x82) {
63d8e4ebf8SJiri Kosina struct input_dev *input = field->hidinput->input;
64949f8fefSJiri Slaby input_event(input, usage->type, usage->code, 1);
65949f8fefSJiri Slaby input_sync(input);
66949f8fefSJiri Slaby input_event(input, usage->type, usage->code, 0);
67949f8fefSJiri Slaby input_sync(input);
68949f8fefSJiri Slaby return 1;
69949f8fefSJiri Slaby }
70949f8fefSJiri Slaby
71949f8fefSJiri Slaby return 0;
72949f8fefSJiri Slaby }
73949f8fefSJiri Slaby
74949f8fefSJiri Slaby static const struct hid_device_id gyration_devices[] = {
75949f8fefSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE) },
761e093206SJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_2) },
77c2fd1a4eSCory Maccarrone { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_3) },
78949f8fefSJiri Slaby { }
79949f8fefSJiri Slaby };
80949f8fefSJiri Slaby MODULE_DEVICE_TABLE(hid, gyration_devices);
81949f8fefSJiri Slaby
82949f8fefSJiri Slaby static struct hid_driver gyration_driver = {
83949f8fefSJiri Slaby .name = "gyration",
84949f8fefSJiri Slaby .id_table = gyration_devices,
85949f8fefSJiri Slaby .input_mapping = gyration_input_mapping,
86949f8fefSJiri Slaby .event = gyration_event,
87949f8fefSJiri Slaby };
88f425458eSH Hartley Sweeten module_hid_driver(gyration_driver);
89949f8fefSJiri Slaby
90949f8fefSJiri Slaby MODULE_LICENSE("GPL");
91