Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Jiri Slaby | 949f8fe | 2008-07-24 23:35:13 +0200 | [diff] [blame] | 2 | /* |
| 3 | * HID driver for some gyration "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 |
Jiri Slaby | 949f8fe | 2008-07-24 23:35:13 +0200 | [diff] [blame] | 8 | * Copyright (c) 2008 Jiri Slaby |
Jiri Kosina | 1e09320 | 2008-10-17 11:52:23 +0200 | [diff] [blame] | 9 | * Copyright (c) 2006-2008 Jiri Kosina |
Jiri Slaby | 949f8fe | 2008-07-24 23:35:13 +0200 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | /* |
Jiri Slaby | 949f8fe | 2008-07-24 23:35:13 +0200 | [diff] [blame] | 13 | */ |
| 14 | |
| 15 | #include <linux/device.h> |
| 16 | #include <linux/input.h> |
| 17 | #include <linux/hid.h> |
| 18 | #include <linux/module.h> |
| 19 | |
| 20 | #include "hid-ids.h" |
| 21 | |
| 22 | #define gy_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \ |
| 23 | EV_KEY, (c)) |
| 24 | static int gyration_input_mapping(struct hid_device *hdev, struct hid_input *hi, |
| 25 | struct hid_field *field, struct hid_usage *usage, |
| 26 | unsigned long **bit, int *max) |
| 27 | { |
| 28 | if ((usage->hid & HID_USAGE_PAGE) != HID_UP_LOGIVENDOR) |
| 29 | return 0; |
| 30 | |
| 31 | set_bit(EV_REP, hi->input->evbit); |
| 32 | switch (usage->hid & HID_USAGE) { |
| 33 | /* Reported on Gyration MCE Remote */ |
| 34 | case 0x00d: gy_map_key_clear(KEY_HOME); break; |
| 35 | case 0x024: gy_map_key_clear(KEY_DVD); break; |
| 36 | case 0x025: gy_map_key_clear(KEY_PVR); break; |
| 37 | case 0x046: gy_map_key_clear(KEY_MEDIA); break; |
| 38 | case 0x047: gy_map_key_clear(KEY_MP3); break; |
Jiri Kosina | 1e09320 | 2008-10-17 11:52:23 +0200 | [diff] [blame] | 39 | case 0x048: gy_map_key_clear(KEY_MEDIA); break; |
Jiri Slaby | 949f8fe | 2008-07-24 23:35:13 +0200 | [diff] [blame] | 40 | case 0x049: gy_map_key_clear(KEY_CAMERA); break; |
| 41 | case 0x04a: gy_map_key_clear(KEY_VIDEO); break; |
Steffen Barszus | 6497dc3 | 2011-02-14 19:53:48 +0100 | [diff] [blame] | 42 | case 0x05a: gy_map_key_clear(KEY_TEXT); break; |
| 43 | case 0x05b: gy_map_key_clear(KEY_RED); break; |
| 44 | case 0x05c: gy_map_key_clear(KEY_GREEN); break; |
| 45 | case 0x05d: gy_map_key_clear(KEY_YELLOW); break; |
| 46 | case 0x05e: gy_map_key_clear(KEY_BLUE); break; |
Jiri Slaby | 949f8fe | 2008-07-24 23:35:13 +0200 | [diff] [blame] | 47 | |
| 48 | default: |
| 49 | return 0; |
| 50 | } |
| 51 | return 1; |
| 52 | } |
| 53 | |
| 54 | static int gyration_event(struct hid_device *hdev, struct hid_field *field, |
| 55 | struct hid_usage *usage, __s32 value) |
| 56 | { |
Jiri Kosina | d8e4ebf8b | 2010-03-23 16:32:37 +0100 | [diff] [blame] | 57 | |
| 58 | if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput) |
| 59 | return 0; |
Jiri Slaby | 949f8fe | 2008-07-24 23:35:13 +0200 | [diff] [blame] | 60 | |
| 61 | if ((usage->hid & HID_USAGE_PAGE) == HID_UP_GENDESK && |
| 62 | (usage->hid & 0xff) == 0x82) { |
Jiri Kosina | d8e4ebf8b | 2010-03-23 16:32:37 +0100 | [diff] [blame] | 63 | struct input_dev *input = field->hidinput->input; |
Jiri Slaby | 949f8fe | 2008-07-24 23:35:13 +0200 | [diff] [blame] | 64 | input_event(input, usage->type, usage->code, 1); |
| 65 | input_sync(input); |
| 66 | input_event(input, usage->type, usage->code, 0); |
| 67 | input_sync(input); |
| 68 | return 1; |
| 69 | } |
| 70 | |
| 71 | return 0; |
| 72 | } |
| 73 | |
| 74 | static const struct hid_device_id gyration_devices[] = { |
| 75 | { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE) }, |
Jiri Kosina | 1e09320 | 2008-10-17 11:52:23 +0200 | [diff] [blame] | 76 | { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_2) }, |
Cory Maccarrone | c2fd1a4 | 2010-05-22 13:00:28 -0700 | [diff] [blame] | 77 | { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_3) }, |
Jiri Slaby | 949f8fe | 2008-07-24 23:35:13 +0200 | [diff] [blame] | 78 | { } |
| 79 | }; |
| 80 | MODULE_DEVICE_TABLE(hid, gyration_devices); |
| 81 | |
| 82 | static struct hid_driver gyration_driver = { |
| 83 | .name = "gyration", |
| 84 | .id_table = gyration_devices, |
| 85 | .input_mapping = gyration_input_mapping, |
| 86 | .event = gyration_event, |
| 87 | }; |
H Hartley Sweeten | f425458 | 2012-12-17 15:28:26 -0700 | [diff] [blame] | 88 | module_hid_driver(gyration_driver); |
Jiri Slaby | 949f8fe | 2008-07-24 23:35:13 +0200 | [diff] [blame] | 89 | |
Jiri Slaby | 949f8fe | 2008-07-24 23:35:13 +0200 | [diff] [blame] | 90 | MODULE_LICENSE("GPL"); |