Jiri Slaby | 949f8fe | 2008-07-24 23:35:13 +0200 | [diff] [blame] | 1 | /* |
| 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 Slaby | 949f8fe | 2008-07-24 23:35:13 +0200 | [diff] [blame] | 7 | * Copyright (c) 2007 Paul Walmsley |
| 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 | /* |
| 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/input.h> |
| 21 | #include <linux/hid.h> |
| 22 | #include <linux/module.h> |
| 23 | |
| 24 | #include "hid-ids.h" |
| 25 | |
| 26 | #define gy_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \ |
| 27 | EV_KEY, (c)) |
| 28 | static int gyration_input_mapping(struct hid_device *hdev, struct hid_input *hi, |
| 29 | struct hid_field *field, struct hid_usage *usage, |
| 30 | unsigned long **bit, int *max) |
| 31 | { |
| 32 | if ((usage->hid & HID_USAGE_PAGE) != HID_UP_LOGIVENDOR) |
| 33 | return 0; |
| 34 | |
| 35 | set_bit(EV_REP, hi->input->evbit); |
| 36 | switch (usage->hid & HID_USAGE) { |
| 37 | /* Reported on Gyration MCE Remote */ |
| 38 | case 0x00d: gy_map_key_clear(KEY_HOME); break; |
| 39 | case 0x024: gy_map_key_clear(KEY_DVD); break; |
| 40 | case 0x025: gy_map_key_clear(KEY_PVR); break; |
| 41 | case 0x046: gy_map_key_clear(KEY_MEDIA); break; |
| 42 | case 0x047: gy_map_key_clear(KEY_MP3); break; |
Jiri Kosina | 1e09320 | 2008-10-17 11:52:23 +0200 | [diff] [blame] | 43 | case 0x048: gy_map_key_clear(KEY_MEDIA); break; |
Jiri Slaby | 949f8fe | 2008-07-24 23:35:13 +0200 | [diff] [blame] | 44 | case 0x049: gy_map_key_clear(KEY_CAMERA); break; |
| 45 | case 0x04a: gy_map_key_clear(KEY_VIDEO); break; |
Steffen Barszus | 6497dc3 | 2011-02-14 19:53:48 +0100 | [diff] [blame] | 46 | case 0x05a: gy_map_key_clear(KEY_TEXT); break; |
| 47 | case 0x05b: gy_map_key_clear(KEY_RED); break; |
| 48 | case 0x05c: gy_map_key_clear(KEY_GREEN); break; |
| 49 | case 0x05d: gy_map_key_clear(KEY_YELLOW); break; |
| 50 | case 0x05e: gy_map_key_clear(KEY_BLUE); break; |
Jiri Slaby | 949f8fe | 2008-07-24 23:35:13 +0200 | [diff] [blame] | 51 | |
| 52 | default: |
| 53 | return 0; |
| 54 | } |
| 55 | return 1; |
| 56 | } |
| 57 | |
| 58 | static int gyration_event(struct hid_device *hdev, struct hid_field *field, |
| 59 | struct hid_usage *usage, __s32 value) |
| 60 | { |
Jiri Kosina | d8e4ebf | 2010-03-23 16:32:37 +0100 | [diff] [blame] | 61 | |
| 62 | if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput) |
| 63 | return 0; |
Jiri Slaby | 949f8fe | 2008-07-24 23:35:13 +0200 | [diff] [blame] | 64 | |
| 65 | if ((usage->hid & HID_USAGE_PAGE) == HID_UP_GENDESK && |
| 66 | (usage->hid & 0xff) == 0x82) { |
Jiri Kosina | d8e4ebf | 2010-03-23 16:32:37 +0100 | [diff] [blame] | 67 | struct input_dev *input = field->hidinput->input; |
Jiri Slaby | 949f8fe | 2008-07-24 23:35:13 +0200 | [diff] [blame] | 68 | input_event(input, usage->type, usage->code, 1); |
| 69 | input_sync(input); |
| 70 | input_event(input, usage->type, usage->code, 0); |
| 71 | input_sync(input); |
| 72 | return 1; |
| 73 | } |
| 74 | |
| 75 | return 0; |
| 76 | } |
| 77 | |
| 78 | static const struct hid_device_id gyration_devices[] = { |
| 79 | { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE) }, |
Jiri Kosina | 1e09320 | 2008-10-17 11:52:23 +0200 | [diff] [blame] | 80 | { 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] | 81 | { 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] | 82 | { } |
| 83 | }; |
| 84 | MODULE_DEVICE_TABLE(hid, gyration_devices); |
| 85 | |
| 86 | static struct hid_driver gyration_driver = { |
| 87 | .name = "gyration", |
| 88 | .id_table = gyration_devices, |
| 89 | .input_mapping = gyration_input_mapping, |
| 90 | .event = gyration_event, |
| 91 | }; |
| 92 | |
Peter Huewe | a24f423 | 2009-07-02 19:08:38 +0200 | [diff] [blame] | 93 | static int __init gyration_init(void) |
Jiri Slaby | 949f8fe | 2008-07-24 23:35:13 +0200 | [diff] [blame] | 94 | { |
| 95 | return hid_register_driver(&gyration_driver); |
| 96 | } |
| 97 | |
Peter Huewe | a24f423 | 2009-07-02 19:08:38 +0200 | [diff] [blame] | 98 | static void __exit gyration_exit(void) |
Jiri Slaby | 949f8fe | 2008-07-24 23:35:13 +0200 | [diff] [blame] | 99 | { |
| 100 | hid_unregister_driver(&gyration_driver); |
| 101 | } |
| 102 | |
| 103 | module_init(gyration_init); |
| 104 | module_exit(gyration_exit); |
| 105 | MODULE_LICENSE("GPL"); |