blob: 903162a63c4f03288b0ba88cf359f1e2588d30d2 [file] [log] [blame]
Jiri Kosina10bd0652007-11-22 15:18:18 +01001/*
2 * HID-input usage mapping quirks
3 *
4 * This is used to handle HID-input mappings for devices violating
5 * HUT 1.12 specification.
6 *
Jiri Kosina85c985f2008-01-10 17:40:18 +01007 * Copyright (c) 2007-2008 Jiri Kosina
Jiri Kosina10bd0652007-11-22 15:18:18 +01008 */
9
10/*
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the Free
13 * Software Foundation; either version 2 of the License
14 */
15
16#include <linux/input.h>
17#include <linux/hid.h>
18
Jiri Slaby022e8c42008-05-16 11:49:18 +020019#define map_key_clear(c) hid_map_usage_clear(hidinput, usage, bit, \
20 max, EV_KEY, (c))
Jiri Kosina10bd0652007-11-22 15:18:18 +010021
Jiri Slaby022e8c42008-05-16 11:49:18 +020022static int quirk_gyration_remote(struct hid_usage *usage,
23 struct hid_input *hidinput, unsigned long **bit, int *max)
Daniel Walkera7f32692008-07-04 15:23:10 +020024{
25 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_LOGIVENDOR)
26 return 0;
27
Jiri Slaby022e8c42008-05-16 11:49:18 +020028 set_bit(EV_REP, hidinput->input->evbit);
Daniel Walkera7f32692008-07-04 15:23:10 +020029 switch(usage->hid & HID_USAGE) {
30 /* Reported on Gyration MCE Remote */
31 case 0x00d: map_key_clear(KEY_HOME); break;
32 case 0x024: map_key_clear(KEY_DVD); break;
33 case 0x025: map_key_clear(KEY_PVR); break;
34 case 0x046: map_key_clear(KEY_MEDIA); break;
35 case 0x047: map_key_clear(KEY_MP3); break;
36 case 0x049: map_key_clear(KEY_CAMERA); break;
37 case 0x04a: map_key_clear(KEY_VIDEO); break;
38
39 default:
40 return 0;
41 }
42 return 1;
43}
44
Jiri Slaby022e8c42008-05-16 11:49:18 +020045static int quirk_cherry_genius_29e(struct hid_usage *usage,
46 struct hid_input *hidinput, unsigned long **bit, int *max)
Jiri Kosina10bd0652007-11-22 15:18:18 +010047{
48 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
49 return 0;
50
51 switch (usage->hid & HID_USAGE) {
52 case 0x156: map_key_clear(KEY_WORDPROCESSOR); break;
53 case 0x157: map_key_clear(KEY_SPREADSHEET); break;
54 case 0x158: map_key_clear(KEY_PRESENTATION); break;
55 case 0x15c: map_key_clear(KEY_STOP); break;
56
57 default:
58 return 0;
59 }
60 return 1;
61}
62
Daniel Walkera7f32692008-07-04 15:23:10 +020063#define VENDOR_ID_GYRATION 0x0c16
64#define DEVICE_ID_GYRATION_REMOTE 0x0002
65
Jiri Kosina10bd0652007-11-22 15:18:18 +010066#define VENDOR_ID_MONTEREY 0x0566
67#define DEVICE_ID_GENIUS_KB29E 0x3004
68
Jiri Kosina10bd0652007-11-22 15:18:18 +010069static const struct hid_input_blacklist {
70 __u16 idVendor;
71 __u16 idProduct;
Jiri Slaby022e8c42008-05-16 11:49:18 +020072 int (*quirk)(struct hid_usage *, struct hid_input *, unsigned long **,
73 int *);
Jiri Kosina10bd0652007-11-22 15:18:18 +010074} hid_input_blacklist[] = {
Daniel Walkera7f32692008-07-04 15:23:10 +020075 { VENDOR_ID_GYRATION, DEVICE_ID_GYRATION_REMOTE, quirk_gyration_remote },
76
Jiri Kosina10bd0652007-11-22 15:18:18 +010077 { VENDOR_ID_MONTEREY, DEVICE_ID_GENIUS_KB29E, quirk_cherry_genius_29e },
78
Jiri Slaby282bfd42008-03-28 17:06:41 +010079 { 0, 0, NULL }
Jiri Kosina10bd0652007-11-22 15:18:18 +010080};
81
82int hidinput_mapping_quirks(struct hid_usage *usage,
Jiri Slaby022e8c42008-05-16 11:49:18 +020083 struct hid_input *hi, unsigned long **bit, int *max)
Jiri Kosina10bd0652007-11-22 15:18:18 +010084{
Jiri Slaby022e8c42008-05-16 11:49:18 +020085 struct hid_device *device = input_get_drvdata(hi->input);
Jiri Kosina10bd0652007-11-22 15:18:18 +010086 int i = 0;
87
88 while (hid_input_blacklist[i].quirk) {
89 if (hid_input_blacklist[i].idVendor == device->vendor &&
90 hid_input_blacklist[i].idProduct == device->product)
Jiri Slaby022e8c42008-05-16 11:49:18 +020091 return hid_input_blacklist[i].quirk(usage, hi, bit,
92 max);
Jiri Kosina10bd0652007-11-22 15:18:18 +010093 i++;
94 }
95 return 0;
96}
Jiri Kosina87bc2aa2007-11-23 13:16:02 +010097
Jiri Kosina68a1f2c2008-02-07 16:48:46 +010098int hidinput_event_quirks(struct hid_device *hid, struct hid_field *field, struct hid_usage *usage, __s32 value)
Jiri Kosina87bc2aa2007-11-23 13:16:02 +010099{
100 struct input_dev *input;
Jiri Kosina87bc2aa2007-11-23 13:16:02 +0100101
102 input = field->hidinput->input;
103
Jiri Kosina32146dc2008-07-04 15:22:53 +0200104 /* Gyration MCE remote "Sleep" key */
105 if (hid->vendor == VENDOR_ID_GYRATION &&
106 hid->product == DEVICE_ID_GYRATION_REMOTE &&
107 (usage->hid & HID_USAGE_PAGE) == HID_UP_GENDESK &&
108 (usage->hid & 0xff) == 0x82) {
109 input_event(input, usage->type, usage->code, 1);
110 input_sync(input);
111 input_event(input, usage->type, usage->code, 0);
112 input_sync(input);
113 return 1;
114 }
Jiri Kosina68a1f2c2008-02-07 16:48:46 +0100115 return 0;
Jiri Kosina87bc2aa2007-11-23 13:16:02 +0100116}
117
Jiri Kosina10bd0652007-11-22 15:18:18 +0100118