Loading...
1/*
2 * HID driver for the apple ir device
3 *
4 * Original driver written by James McKenzie
5 * Ported to recent 2.6 kernel versions by Greg Kroah-Hartman <gregkh@suse.de>
6 * Updated to support newer remotes by Bastien Nocera <hadess@hadess.net>
7 * Ported to HID subsystem by Benjamin Tissoires <benjamin.tissoires@gmail.com>
8 *
9 * Copyright (C) 2006 James McKenzie
10 * Copyright (C) 2008 Greg Kroah-Hartman <greg@kroah.com>
11 * Copyright (C) 2008 Novell Inc.
12 * Copyright (C) 2010, 2012 Bastien Nocera <hadess@hadess.net>
13 * Copyright (C) 2013 Benjamin Tissoires <benjamin.tissoires@gmail.com>
14 * Copyright (C) 2013 Red Hat Inc. All Rights Reserved
15 *
16 * This software is licensed under the terms of the GNU General Public
17 * License version 2, as published by the Free Software Foundation, and
18 * may be copied, distributed, and modified under those terms.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 */
25
26#include <linux/device.h>
27#include <linux/hid.h>
28#include <linux/module.h>
29#include "hid-ids.h"
30
31MODULE_AUTHOR("James McKenzie");
32MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@redhat.com>");
33MODULE_DESCRIPTION("HID Apple IR remote controls");
34MODULE_LICENSE("GPL");
35
36#define KEY_MASK 0x0F
37#define TWO_PACKETS_MASK 0x40
38
39/*
40 * James McKenzie has two devices both of which report the following
41 * 25 87 ee 83 0a +
42 * 25 87 ee 83 0c -
43 * 25 87 ee 83 09 <<
44 * 25 87 ee 83 06 >>
45 * 25 87 ee 83 05 >"
46 * 25 87 ee 83 03 menu
47 * 26 00 00 00 00 for key repeat
48 */
49
50/*
51 * Thomas Glanzmann reports the following responses
52 * 25 87 ee ca 0b +
53 * 25 87 ee ca 0d -
54 * 25 87 ee ca 08 <<
55 * 25 87 ee ca 07 >>
56 * 25 87 ee ca 04 >"
57 * 25 87 ee ca 02 menu
58 * 26 00 00 00 00 for key repeat
59 *
60 * He also observes the following event sometimes
61 * sent after a key is release, which I interpret
62 * as a flat battery message
63 * 25 87 e0 ca 06 flat battery
64 */
65
66/*
67 * Alexandre Karpenko reports the following responses for Device ID 0x8242
68 * 25 87 ee 47 0b +
69 * 25 87 ee 47 0d -
70 * 25 87 ee 47 08 <<
71 * 25 87 ee 47 07 >>
72 * 25 87 ee 47 04 >"
73 * 25 87 ee 47 02 menu
74 * 26 87 ee 47 ** for key repeat (** is the code of the key being held)
75 */
76
77/*
78 * Bastien Nocera's remote
79 * 25 87 ee 91 5f followed by
80 * 25 87 ee 91 05 gives you >"
81 *
82 * 25 87 ee 91 5c followed by
83 * 25 87 ee 91 05 gives you the middle button
84 */
85
86/*
87 * Fabien Andre's remote
88 * 25 87 ee a3 5e followed by
89 * 25 87 ee a3 04 gives you >"
90 *
91 * 25 87 ee a3 5d followed by
92 * 25 87 ee a3 04 gives you the middle button
93 */
94
95static const unsigned short appleir_key_table[] = {
96 KEY_RESERVED,
97 KEY_MENU,
98 KEY_PLAYPAUSE,
99 KEY_FORWARD,
100 KEY_BACK,
101 KEY_VOLUMEUP,
102 KEY_VOLUMEDOWN,
103 KEY_RESERVED,
104 KEY_RESERVED,
105 KEY_RESERVED,
106 KEY_RESERVED,
107 KEY_RESERVED,
108 KEY_RESERVED,
109 KEY_RESERVED,
110 KEY_ENTER,
111 KEY_PLAYPAUSE,
112 KEY_RESERVED,
113};
114
115struct appleir {
116 struct input_dev *input_dev;
117 struct hid_device *hid;
118 unsigned short keymap[ARRAY_SIZE(appleir_key_table)];
119 struct timer_list key_up_timer; /* timer for key up */
120 spinlock_t lock; /* protects .current_key */
121 int current_key; /* the currently pressed key */
122 int prev_key_idx; /* key index in a 2 packets message */
123};
124
125static int get_key(int data)
126{
127 /*
128 * The key is coded accross bits 2..9:
129 *
130 * 0x00 or 0x01 ( ) key: 0 -> KEY_RESERVED
131 * 0x02 or 0x03 ( menu ) key: 1 -> KEY_MENU
132 * 0x04 or 0x05 ( >" ) key: 2 -> KEY_PLAYPAUSE
133 * 0x06 or 0x07 ( >> ) key: 3 -> KEY_FORWARD
134 * 0x08 or 0x09 ( << ) key: 4 -> KEY_BACK
135 * 0x0a or 0x0b ( + ) key: 5 -> KEY_VOLUMEUP
136 * 0x0c or 0x0d ( - ) key: 6 -> KEY_VOLUMEDOWN
137 * 0x0e or 0x0f ( ) key: 7 -> KEY_RESERVED
138 * 0x50 or 0x51 ( ) key: 8 -> KEY_RESERVED
139 * 0x52 or 0x53 ( ) key: 9 -> KEY_RESERVED
140 * 0x54 or 0x55 ( ) key: 10 -> KEY_RESERVED
141 * 0x56 or 0x57 ( ) key: 11 -> KEY_RESERVED
142 * 0x58 or 0x59 ( ) key: 12 -> KEY_RESERVED
143 * 0x5a or 0x5b ( ) key: 13 -> KEY_RESERVED
144 * 0x5c or 0x5d ( middle ) key: 14 -> KEY_ENTER
145 * 0x5e or 0x5f ( >" ) key: 15 -> KEY_PLAYPAUSE
146 *
147 * Packets starting with 0x5 are part of a two-packets message,
148 * we notify the caller by sending a negative value.
149 */
150 int key = (data >> 1) & KEY_MASK;
151
152 if ((data & TWO_PACKETS_MASK))
153 /* Part of a 2 packets-command */
154 key = -key;
155
156 return key;
157}
158
159static void key_up(struct hid_device *hid, struct appleir *appleir, int key)
160{
161 input_report_key(appleir->input_dev, key, 0);
162 input_sync(appleir->input_dev);
163}
164
165static void key_down(struct hid_device *hid, struct appleir *appleir, int key)
166{
167 input_report_key(appleir->input_dev, key, 1);
168 input_sync(appleir->input_dev);
169}
170
171static void battery_flat(struct appleir *appleir)
172{
173 dev_err(&appleir->input_dev->dev, "possible flat battery?\n");
174}
175
176static void key_up_tick(unsigned long data)
177{
178 struct appleir *appleir = (struct appleir *)data;
179 struct hid_device *hid = appleir->hid;
180 unsigned long flags;
181
182 spin_lock_irqsave(&appleir->lock, flags);
183 if (appleir->current_key) {
184 key_up(hid, appleir, appleir->current_key);
185 appleir->current_key = 0;
186 }
187 spin_unlock_irqrestore(&appleir->lock, flags);
188}
189
190static int appleir_raw_event(struct hid_device *hid, struct hid_report *report,
191 u8 *data, int len)
192{
193 struct appleir *appleir = hid_get_drvdata(hid);
194 static const u8 keydown[] = { 0x25, 0x87, 0xee };
195 static const u8 keyrepeat[] = { 0x26, };
196 static const u8 flatbattery[] = { 0x25, 0x87, 0xe0 };
197 unsigned long flags;
198
199 if (len != 5)
200 goto out;
201
202 if (!memcmp(data, keydown, sizeof(keydown))) {
203 int index;
204
205 spin_lock_irqsave(&appleir->lock, flags);
206 /*
207 * If we already have a key down, take it up before marking
208 * this one down
209 */
210 if (appleir->current_key)
211 key_up(hid, appleir, appleir->current_key);
212
213 /* Handle dual packet commands */
214 if (appleir->prev_key_idx > 0)
215 index = appleir->prev_key_idx;
216 else
217 index = get_key(data[4]);
218
219 if (index >= 0) {
220 appleir->current_key = appleir->keymap[index];
221
222 key_down(hid, appleir, appleir->current_key);
223 /*
224 * Remote doesn't do key up, either pull them up, in
225 * the test above, or here set a timer which pulls
226 * them up after 1/8 s
227 */
228 mod_timer(&appleir->key_up_timer, jiffies + HZ / 8);
229 appleir->prev_key_idx = 0;
230 } else
231 /* Remember key for next packet */
232 appleir->prev_key_idx = -index;
233 spin_unlock_irqrestore(&appleir->lock, flags);
234 goto out;
235 }
236
237 appleir->prev_key_idx = 0;
238
239 if (!memcmp(data, keyrepeat, sizeof(keyrepeat))) {
240 key_down(hid, appleir, appleir->current_key);
241 /*
242 * Remote doesn't do key up, either pull them up, in the test
243 * above, or here set a timer which pulls them up after 1/8 s
244 */
245 mod_timer(&appleir->key_up_timer, jiffies + HZ / 8);
246 goto out;
247 }
248
249 if (!memcmp(data, flatbattery, sizeof(flatbattery))) {
250 battery_flat(appleir);
251 /* Fall through */
252 }
253
254out:
255 /* let hidraw and hiddev handle the report */
256 return 0;
257}
258
259static void appleir_input_configured(struct hid_device *hid,
260 struct hid_input *hidinput)
261{
262 struct input_dev *input_dev = hidinput->input;
263 struct appleir *appleir = hid_get_drvdata(hid);
264 int i;
265
266 appleir->input_dev = input_dev;
267
268 input_dev->keycode = appleir->keymap;
269 input_dev->keycodesize = sizeof(unsigned short);
270 input_dev->keycodemax = ARRAY_SIZE(appleir->keymap);
271
272 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
273
274 memcpy(appleir->keymap, appleir_key_table, sizeof(appleir->keymap));
275 for (i = 0; i < ARRAY_SIZE(appleir_key_table); i++)
276 set_bit(appleir->keymap[i], input_dev->keybit);
277 clear_bit(KEY_RESERVED, input_dev->keybit);
278}
279
280static int appleir_input_mapping(struct hid_device *hid,
281 struct hid_input *hi, struct hid_field *field,
282 struct hid_usage *usage, unsigned long **bit, int *max)
283{
284 return -1;
285}
286
287static int appleir_probe(struct hid_device *hid, const struct hid_device_id *id)
288{
289 int ret;
290 struct appleir *appleir;
291
292 appleir = kzalloc(sizeof(struct appleir), GFP_KERNEL);
293 if (!appleir) {
294 ret = -ENOMEM;
295 goto allocfail;
296 }
297
298 appleir->hid = hid;
299
300 /* force input as some remotes bypass the input registration */
301 hid->quirks |= HID_QUIRK_HIDINPUT_FORCE;
302
303 spin_lock_init(&appleir->lock);
304 setup_timer(&appleir->key_up_timer,
305 key_up_tick, (unsigned long) appleir);
306
307 hid_set_drvdata(hid, appleir);
308
309 ret = hid_parse(hid);
310 if (ret) {
311 hid_err(hid, "parse failed\n");
312 goto fail;
313 }
314
315 ret = hid_hw_start(hid, HID_CONNECT_DEFAULT | HID_CONNECT_HIDDEV_FORCE);
316 if (ret) {
317 hid_err(hid, "hw start failed\n");
318 goto fail;
319 }
320
321 return 0;
322fail:
323 kfree(appleir);
324allocfail:
325 return ret;
326}
327
328static void appleir_remove(struct hid_device *hid)
329{
330 struct appleir *appleir = hid_get_drvdata(hid);
331 hid_hw_stop(hid);
332 del_timer_sync(&appleir->key_up_timer);
333 kfree(appleir);
334}
335
336static const struct hid_device_id appleir_devices[] = {
337 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL) },
338 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL2) },
339 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL3) },
340 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL4) },
341 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL5) },
342 { }
343};
344MODULE_DEVICE_TABLE(hid, appleir_devices);
345
346static struct hid_driver appleir_driver = {
347 .name = "appleir",
348 .id_table = appleir_devices,
349 .raw_event = appleir_raw_event,
350 .input_configured = appleir_input_configured,
351 .probe = appleir_probe,
352 .remove = appleir_remove,
353 .input_mapping = appleir_input_mapping,
354};
355module_hid_driver(appleir_driver);
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * HID driver for the apple ir device
4 *
5 * Original driver written by James McKenzie
6 * Ported to recent 2.6 kernel versions by Greg Kroah-Hartman <gregkh@suse.de>
7 * Updated to support newer remotes by Bastien Nocera <hadess@hadess.net>
8 * Ported to HID subsystem by Benjamin Tissoires <benjamin.tissoires@gmail.com>
9 *
10 * Copyright (C) 2006 James McKenzie
11 * Copyright (C) 2008 Greg Kroah-Hartman <greg@kroah.com>
12 * Copyright (C) 2008 Novell Inc.
13 * Copyright (C) 2010, 2012 Bastien Nocera <hadess@hadess.net>
14 * Copyright (C) 2013 Benjamin Tissoires <benjamin.tissoires@gmail.com>
15 * Copyright (C) 2013 Red Hat Inc. All Rights Reserved
16 */
17
18#include <linux/device.h>
19#include <linux/hid.h>
20#include <linux/module.h>
21#include "hid-ids.h"
22
23MODULE_AUTHOR("James McKenzie");
24MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@redhat.com>");
25MODULE_DESCRIPTION("HID Apple IR remote controls");
26MODULE_LICENSE("GPL");
27
28#define KEY_MASK 0x0F
29#define TWO_PACKETS_MASK 0x40
30
31/*
32 * James McKenzie has two devices both of which report the following
33 * 25 87 ee 83 0a +
34 * 25 87 ee 83 0c -
35 * 25 87 ee 83 09 <<
36 * 25 87 ee 83 06 >>
37 * 25 87 ee 83 05 >"
38 * 25 87 ee 83 03 menu
39 * 26 00 00 00 00 for key repeat
40 */
41
42/*
43 * Thomas Glanzmann reports the following responses
44 * 25 87 ee ca 0b +
45 * 25 87 ee ca 0d -
46 * 25 87 ee ca 08 <<
47 * 25 87 ee ca 07 >>
48 * 25 87 ee ca 04 >"
49 * 25 87 ee ca 02 menu
50 * 26 00 00 00 00 for key repeat
51 *
52 * He also observes the following event sometimes
53 * sent after a key is release, which I interpret
54 * as a flat battery message
55 * 25 87 e0 ca 06 flat battery
56 */
57
58/*
59 * Alexandre Karpenko reports the following responses for Device ID 0x8242
60 * 25 87 ee 47 0b +
61 * 25 87 ee 47 0d -
62 * 25 87 ee 47 08 <<
63 * 25 87 ee 47 07 >>
64 * 25 87 ee 47 04 >"
65 * 25 87 ee 47 02 menu
66 * 26 87 ee 47 ** for key repeat (** is the code of the key being held)
67 */
68
69/*
70 * Bastien Nocera's remote
71 * 25 87 ee 91 5f followed by
72 * 25 87 ee 91 05 gives you >"
73 *
74 * 25 87 ee 91 5c followed by
75 * 25 87 ee 91 05 gives you the middle button
76 */
77
78/*
79 * Fabien Andre's remote
80 * 25 87 ee a3 5e followed by
81 * 25 87 ee a3 04 gives you >"
82 *
83 * 25 87 ee a3 5d followed by
84 * 25 87 ee a3 04 gives you the middle button
85 */
86
87static const unsigned short appleir_key_table[] = {
88 KEY_RESERVED,
89 KEY_MENU,
90 KEY_PLAYPAUSE,
91 KEY_FORWARD,
92 KEY_BACK,
93 KEY_VOLUMEUP,
94 KEY_VOLUMEDOWN,
95 KEY_RESERVED,
96 KEY_RESERVED,
97 KEY_RESERVED,
98 KEY_RESERVED,
99 KEY_RESERVED,
100 KEY_RESERVED,
101 KEY_RESERVED,
102 KEY_ENTER,
103 KEY_PLAYPAUSE,
104 KEY_RESERVED,
105};
106
107struct appleir {
108 struct input_dev *input_dev;
109 struct hid_device *hid;
110 unsigned short keymap[ARRAY_SIZE(appleir_key_table)];
111 struct timer_list key_up_timer; /* timer for key up */
112 spinlock_t lock; /* protects .current_key */
113 int current_key; /* the currently pressed key */
114 int prev_key_idx; /* key index in a 2 packets message */
115};
116
117static int get_key(int data)
118{
119 /*
120 * The key is coded accross bits 2..9:
121 *
122 * 0x00 or 0x01 ( ) key: 0 -> KEY_RESERVED
123 * 0x02 or 0x03 ( menu ) key: 1 -> KEY_MENU
124 * 0x04 or 0x05 ( >" ) key: 2 -> KEY_PLAYPAUSE
125 * 0x06 or 0x07 ( >> ) key: 3 -> KEY_FORWARD
126 * 0x08 or 0x09 ( << ) key: 4 -> KEY_BACK
127 * 0x0a or 0x0b ( + ) key: 5 -> KEY_VOLUMEUP
128 * 0x0c or 0x0d ( - ) key: 6 -> KEY_VOLUMEDOWN
129 * 0x0e or 0x0f ( ) key: 7 -> KEY_RESERVED
130 * 0x50 or 0x51 ( ) key: 8 -> KEY_RESERVED
131 * 0x52 or 0x53 ( ) key: 9 -> KEY_RESERVED
132 * 0x54 or 0x55 ( ) key: 10 -> KEY_RESERVED
133 * 0x56 or 0x57 ( ) key: 11 -> KEY_RESERVED
134 * 0x58 or 0x59 ( ) key: 12 -> KEY_RESERVED
135 * 0x5a or 0x5b ( ) key: 13 -> KEY_RESERVED
136 * 0x5c or 0x5d ( middle ) key: 14 -> KEY_ENTER
137 * 0x5e or 0x5f ( >" ) key: 15 -> KEY_PLAYPAUSE
138 *
139 * Packets starting with 0x5 are part of a two-packets message,
140 * we notify the caller by sending a negative value.
141 */
142 int key = (data >> 1) & KEY_MASK;
143
144 if ((data & TWO_PACKETS_MASK))
145 /* Part of a 2 packets-command */
146 key = -key;
147
148 return key;
149}
150
151static void key_up(struct hid_device *hid, struct appleir *appleir, int key)
152{
153 input_report_key(appleir->input_dev, key, 0);
154 input_sync(appleir->input_dev);
155}
156
157static void key_down(struct hid_device *hid, struct appleir *appleir, int key)
158{
159 input_report_key(appleir->input_dev, key, 1);
160 input_sync(appleir->input_dev);
161}
162
163static void battery_flat(struct appleir *appleir)
164{
165 dev_err(&appleir->input_dev->dev, "possible flat battery?\n");
166}
167
168static void key_up_tick(struct timer_list *t)
169{
170 struct appleir *appleir = from_timer(appleir, t, key_up_timer);
171 struct hid_device *hid = appleir->hid;
172 unsigned long flags;
173
174 spin_lock_irqsave(&appleir->lock, flags);
175 if (appleir->current_key) {
176 key_up(hid, appleir, appleir->current_key);
177 appleir->current_key = 0;
178 }
179 spin_unlock_irqrestore(&appleir->lock, flags);
180}
181
182static int appleir_raw_event(struct hid_device *hid, struct hid_report *report,
183 u8 *data, int len)
184{
185 struct appleir *appleir = hid_get_drvdata(hid);
186 static const u8 keydown[] = { 0x25, 0x87, 0xee };
187 static const u8 keyrepeat[] = { 0x26, };
188 static const u8 flatbattery[] = { 0x25, 0x87, 0xe0 };
189 unsigned long flags;
190
191 if (len != 5 || !(hid->claimed & HID_CLAIMED_INPUT))
192 goto out;
193
194 if (!memcmp(data, keydown, sizeof(keydown))) {
195 int index;
196
197 spin_lock_irqsave(&appleir->lock, flags);
198 /*
199 * If we already have a key down, take it up before marking
200 * this one down
201 */
202 if (appleir->current_key)
203 key_up(hid, appleir, appleir->current_key);
204
205 /* Handle dual packet commands */
206 if (appleir->prev_key_idx > 0)
207 index = appleir->prev_key_idx;
208 else
209 index = get_key(data[4]);
210
211 if (index >= 0) {
212 appleir->current_key = appleir->keymap[index];
213
214 key_down(hid, appleir, appleir->current_key);
215 /*
216 * Remote doesn't do key up, either pull them up, in
217 * the test above, or here set a timer which pulls
218 * them up after 1/8 s
219 */
220 mod_timer(&appleir->key_up_timer, jiffies + HZ / 8);
221 appleir->prev_key_idx = 0;
222 } else
223 /* Remember key for next packet */
224 appleir->prev_key_idx = -index;
225 spin_unlock_irqrestore(&appleir->lock, flags);
226 goto out;
227 }
228
229 appleir->prev_key_idx = 0;
230
231 if (!memcmp(data, keyrepeat, sizeof(keyrepeat))) {
232 key_down(hid, appleir, appleir->current_key);
233 /*
234 * Remote doesn't do key up, either pull them up, in the test
235 * above, or here set a timer which pulls them up after 1/8 s
236 */
237 mod_timer(&appleir->key_up_timer, jiffies + HZ / 8);
238 goto out;
239 }
240
241 if (!memcmp(data, flatbattery, sizeof(flatbattery))) {
242 battery_flat(appleir);
243 /* Fall through */
244 }
245
246out:
247 /* let hidraw and hiddev handle the report */
248 return 0;
249}
250
251static int appleir_input_configured(struct hid_device *hid,
252 struct hid_input *hidinput)
253{
254 struct input_dev *input_dev = hidinput->input;
255 struct appleir *appleir = hid_get_drvdata(hid);
256 int i;
257
258 appleir->input_dev = input_dev;
259
260 input_dev->keycode = appleir->keymap;
261 input_dev->keycodesize = sizeof(unsigned short);
262 input_dev->keycodemax = ARRAY_SIZE(appleir->keymap);
263
264 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
265
266 memcpy(appleir->keymap, appleir_key_table, sizeof(appleir->keymap));
267 for (i = 0; i < ARRAY_SIZE(appleir_key_table); i++)
268 set_bit(appleir->keymap[i], input_dev->keybit);
269 clear_bit(KEY_RESERVED, input_dev->keybit);
270
271 return 0;
272}
273
274static int appleir_input_mapping(struct hid_device *hid,
275 struct hid_input *hi, struct hid_field *field,
276 struct hid_usage *usage, unsigned long **bit, int *max)
277{
278 return -1;
279}
280
281static int appleir_probe(struct hid_device *hid, const struct hid_device_id *id)
282{
283 int ret;
284 struct appleir *appleir;
285
286 appleir = devm_kzalloc(&hid->dev, sizeof(struct appleir), GFP_KERNEL);
287 if (!appleir)
288 return -ENOMEM;
289
290 appleir->hid = hid;
291
292 /* force input as some remotes bypass the input registration */
293 hid->quirks |= HID_QUIRK_HIDINPUT_FORCE;
294
295 spin_lock_init(&appleir->lock);
296 timer_setup(&appleir->key_up_timer, key_up_tick, 0);
297
298 hid_set_drvdata(hid, appleir);
299
300 ret = hid_parse(hid);
301 if (ret) {
302 hid_err(hid, "parse failed\n");
303 goto fail;
304 }
305
306 ret = hid_hw_start(hid, HID_CONNECT_DEFAULT | HID_CONNECT_HIDDEV_FORCE);
307 if (ret) {
308 hid_err(hid, "hw start failed\n");
309 goto fail;
310 }
311
312 return 0;
313fail:
314 devm_kfree(&hid->dev, appleir);
315 return ret;
316}
317
318static void appleir_remove(struct hid_device *hid)
319{
320 struct appleir *appleir = hid_get_drvdata(hid);
321 hid_hw_stop(hid);
322 del_timer_sync(&appleir->key_up_timer);
323}
324
325static const struct hid_device_id appleir_devices[] = {
326 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL) },
327 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL2) },
328 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL3) },
329 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL4) },
330 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL5) },
331 { }
332};
333MODULE_DEVICE_TABLE(hid, appleir_devices);
334
335static struct hid_driver appleir_driver = {
336 .name = "appleir",
337 .id_table = appleir_devices,
338 .raw_event = appleir_raw_event,
339 .input_configured = appleir_input_configured,
340 .probe = appleir_probe,
341 .remove = appleir_remove,
342 .input_mapping = appleir_input_mapping,
343};
344module_hid_driver(appleir_driver);