0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include <linux/device.h>
0013 #include <linux/hid.h>
0014 #include <linux/module.h>
0015
0016 #include "hid-ids.h"
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123 #define ICADE_MAX_USAGE 29
0124
0125 struct icade_key {
0126 u16 to;
0127 u8 press:1;
0128 };
0129
0130 static const struct icade_key icade_usage_table[30] = {
0131 [26] = { KEY_UP, 1 },
0132 [8] = { KEY_UP, 0 },
0133 [7] = { KEY_RIGHT, 1 },
0134 [6] = { KEY_RIGHT, 0 },
0135 [27] = { KEY_DOWN, 1 },
0136 [29] = { KEY_DOWN, 0 },
0137 [4] = { KEY_LEFT, 1 },
0138 [20] = { KEY_LEFT, 0 },
0139 [28] = { BTN_A, 1 },
0140 [23] = { BTN_A, 0 },
0141 [11] = { BTN_B, 1 },
0142 [21] = { BTN_B, 0 },
0143 [24] = { BTN_C, 1 },
0144 [9] = { BTN_C, 0 },
0145 [13] = { BTN_X, 1 },
0146 [17] = { BTN_X, 0 },
0147 [12] = { BTN_Y, 1 },
0148 [16] = { BTN_Y, 0 },
0149 [14] = { BTN_Z, 1 },
0150 [19] = { BTN_Z, 0 },
0151 [18] = { BTN_THUMBL, 1 },
0152 [10] = { BTN_THUMBL, 0 },
0153 [15] = { BTN_THUMBR, 1 },
0154 [25] = { BTN_THUMBR, 0 },
0155 };
0156
0157 static const struct icade_key *icade_find_translation(u16 from)
0158 {
0159 if (from > ICADE_MAX_USAGE)
0160 return NULL;
0161 return &icade_usage_table[from];
0162 }
0163
0164 static int icade_event(struct hid_device *hdev, struct hid_field *field,
0165 struct hid_usage *usage, __s32 value)
0166 {
0167 const struct icade_key *trans;
0168
0169 if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput ||
0170 !usage->type)
0171 return 0;
0172
0173
0174 if (!value)
0175 return 1;
0176
0177 trans = icade_find_translation(usage->hid & HID_USAGE);
0178
0179 if (!trans)
0180 return 1;
0181
0182 input_event(field->hidinput->input, usage->type,
0183 trans->to, trans->press);
0184
0185 return 1;
0186 }
0187
0188 static int icade_input_mapping(struct hid_device *hdev, struct hid_input *hi,
0189 struct hid_field *field, struct hid_usage *usage,
0190 unsigned long **bit, int *max)
0191 {
0192 const struct icade_key *trans;
0193
0194 if ((usage->hid & HID_USAGE_PAGE) == HID_UP_KEYBOARD) {
0195 trans = icade_find_translation(usage->hid & HID_USAGE);
0196
0197 if (!trans)
0198 return -1;
0199
0200 hid_map_usage(hi, usage, bit, max, EV_KEY, trans->to);
0201 set_bit(trans->to, hi->input->keybit);
0202
0203 return 1;
0204 }
0205
0206
0207 return -1;
0208
0209 }
0210
0211 static int icade_input_mapped(struct hid_device *hdev, struct hid_input *hi,
0212 struct hid_field *field, struct hid_usage *usage,
0213 unsigned long **bit, int *max)
0214 {
0215 if (usage->type == EV_KEY)
0216 set_bit(usage->type, hi->input->evbit);
0217
0218 return -1;
0219 }
0220
0221 static const struct hid_device_id icade_devices[] = {
0222 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ION, USB_DEVICE_ID_ICADE) },
0223
0224 { }
0225 };
0226 MODULE_DEVICE_TABLE(hid, icade_devices);
0227
0228 static struct hid_driver icade_driver = {
0229 .name = "icade",
0230 .id_table = icade_devices,
0231 .event = icade_event,
0232 .input_mapped = icade_input_mapped,
0233 .input_mapping = icade_input_mapping,
0234 };
0235 module_hid_driver(icade_driver);
0236
0237 MODULE_LICENSE("GPL");
0238 MODULE_AUTHOR("Bastien Nocera <hadess@hadess.net>");
0239 MODULE_DESCRIPTION("ION iCade input driver");