Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
1da177e4 LT |
2 | * |
3 | * keyboard input driver for i2c IR remote controls | |
4 | * | |
5 | * Copyright (c) 2000-2003 Gerd Knorr <kraxel@bytesex.org> | |
6 | * modified for PixelView (BT878P+W/FM) by | |
7 | * Michal Kochanowicz <mkochano@pld.org.pl> | |
8 | * Christoph Bartelmus <lirc@bartelmus.de> | |
9 | * modified for KNC ONE TV Station/Anubis Typhoon TView Tuner by | |
10 | * Ulrich Mueller <ulrich.mueller42@web.de> | |
c365864f MR |
11 | * modified for em2820 based USB TV tuners by |
12 | * Markus Rechberger <mrechberger@gmail.com> | |
d54d6980 CZ |
13 | * modified for DViCO Fusion HDTV 5 RT GOLD by |
14 | * Chaogui Zhang <czhang1974@gmail.com> | |
ba340b40 BR |
15 | * modified for MSI TV@nywhere Plus by |
16 | * Henry Wong <henry@stuffedcow.net> | |
17 | * Mark Schultz <n9xmj@yahoo.com> | |
18 | * Brian Rogers <brian_rogers@comcast.net> | |
cb3bf504 OJ |
19 | * modified for AVerMedia Cardbus by |
20 | * Oldrich Jedlicka <oldium.pro@seznam.cz> | |
1da177e4 LT |
21 | * |
22 | * This program is free software; you can redistribute it and/or modify | |
23 | * it under the terms of the GNU General Public License as published by | |
24 | * the Free Software Foundation; either version 2 of the License, or | |
25 | * (at your option) any later version. | |
26 | * | |
27 | * This program is distributed in the hope that it will be useful, | |
28 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
29 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
30 | * GNU General Public License for more details. | |
31 | * | |
1da177e4 LT |
32 | */ |
33 | ||
00bb8207 | 34 | #include <asm/unaligned.h> |
1da177e4 | 35 | #include <linux/module.h> |
1da177e4 LT |
36 | #include <linux/init.h> |
37 | #include <linux/kernel.h> | |
1da177e4 LT |
38 | #include <linux/string.h> |
39 | #include <linux/timer.h> | |
40 | #include <linux/delay.h> | |
41 | #include <linux/errno.h> | |
42 | #include <linux/slab.h> | |
43 | #include <linux/i2c.h> | |
44 | #include <linux/workqueue.h> | |
674434c6 | 45 | |
6bda9644 | 46 | #include <media/rc-core.h> |
b5dcee22 | 47 | #include <media/i2c/ir-kbd-i2c.h> |
c365864f | 48 | |
1da177e4 | 49 | |
6d741bfe SY |
50 | static int get_key_haup_common(struct IR_i2c *ir, enum rc_proto *protocol, |
51 | u32 *scancode, u8 *ptoggle, int size) | |
1da177e4 | 52 | { |
39cf1e81 | 53 | unsigned char buf[6]; |
00bb8207 | 54 | int start, range, toggle, dev, code, ircode, vendor; |
1da177e4 LT |
55 | |
56 | /* poll IR chip */ | |
c668f32d | 57 | if (size != i2c_master_recv(ir->c, buf, size)) |
1da177e4 LT |
58 | return -EIO; |
59 | ||
00bb8207 SY |
60 | if (buf[0] & 0x80) { |
61 | int offset = (size == 6) ? 3 : 0; | |
1da177e4 | 62 | |
00bb8207 SY |
63 | /* split rc5 data block ... */ |
64 | start = (buf[offset] >> 7) & 1; | |
65 | range = (buf[offset] >> 6) & 1; | |
66 | toggle = (buf[offset] >> 5) & 1; | |
67 | dev = buf[offset] & 0x1f; | |
68 | code = (buf[offset+1] >> 2) & 0x3f; | |
4dd9bb91 | 69 | |
00bb8207 SY |
70 | /* rc5 has two start bits |
71 | * the first bit must be one | |
72 | * the second bit defines the command range: | |
73 | * 1 = 0-63, 0 = 64 - 127 | |
74 | */ | |
75 | if (!start) | |
76 | /* no key pressed */ | |
77 | return 0; | |
34c08029 | 78 | |
00bb8207 SY |
79 | /* filter out invalid key presses */ |
80 | ircode = (start << 12) | (toggle << 11) | (dev << 6) | code; | |
81 | if ((ircode & 0x1fff) == 0x1fff) | |
82 | return 0; | |
cc7093df | 83 | |
00bb8207 SY |
84 | if (!range) |
85 | code += 64; | |
1da177e4 | 86 | |
50a762b4 SY |
87 | dev_dbg(&ir->rc->dev, |
88 | "ir hauppauge (rc5): s%d r%d t%d dev=%d code=%d\n", | |
00bb8207 SY |
89 | start, range, toggle, dev, code); |
90 | ||
6d741bfe | 91 | *protocol = RC_PROTO_RC5; |
00bb8207 SY |
92 | *scancode = RC_SCANCODE_RC5(dev, code); |
93 | *ptoggle = toggle; | |
94 | ||
95 | return 1; | |
96 | } else if (size == 6 && (buf[0] & 0x40)) { | |
97 | code = buf[4]; | |
98 | dev = buf[3]; | |
99 | vendor = get_unaligned_be16(buf + 1); | |
100 | ||
101 | if (vendor == 0x800f) { | |
102 | *ptoggle = (dev & 0x80) != 0; | |
6d741bfe | 103 | *protocol = RC_PROTO_RC6_MCE; |
00bb8207 | 104 | dev &= 0x7f; |
50a762b4 SY |
105 | dev_dbg(&ir->rc->dev, |
106 | "ir hauppauge (rc6-mce): t%d vendor=%d dev=%d code=%d\n", | |
107 | *ptoggle, vendor, dev, code); | |
00bb8207 SY |
108 | } else { |
109 | *ptoggle = 0; | |
6d741bfe | 110 | *protocol = RC_PROTO_RC6_6A_32; |
50a762b4 SY |
111 | dev_dbg(&ir->rc->dev, |
112 | "ir hauppauge (rc6-6a-32): vendor=%d dev=%d code=%d\n", | |
113 | vendor, dev, code); | |
00bb8207 SY |
114 | } |
115 | ||
116 | *scancode = RC_SCANCODE_RC6_6A(vendor, dev, code); | |
117 | ||
118 | return 1; | |
119 | } | |
120 | ||
121 | return 0; | |
1da177e4 LT |
122 | } |
123 | ||
6d741bfe | 124 | static int get_key_haup(struct IR_i2c *ir, enum rc_proto *protocol, |
4dd9bb91 | 125 | u32 *scancode, u8 *toggle) |
39cf1e81 | 126 | { |
00bb8207 | 127 | return get_key_haup_common(ir, protocol, scancode, toggle, 3); |
39cf1e81 JF |
128 | } |
129 | ||
6d741bfe | 130 | static int get_key_haup_xvr(struct IR_i2c *ir, enum rc_proto *protocol, |
4dd9bb91 | 131 | u32 *scancode, u8 *toggle) |
39cf1e81 | 132 | { |
8df59918 JW |
133 | int ret; |
134 | unsigned char buf[1] = { 0 }; | |
135 | ||
136 | /* | |
137 | * This is the same apparent "are you ready?" poll command observed | |
138 | * watching Windows driver traffic and implemented in lirc_zilog. With | |
139 | * this added, we get far saner remote behavior with z8 chips on usb | |
140 | * connected devices, even with the default polling interval of 100ms. | |
141 | */ | |
142 | ret = i2c_master_send(ir->c, buf, 1); | |
143 | if (ret != 1) | |
144 | return (ret < 0) ? ret : -EINVAL; | |
145 | ||
00bb8207 | 146 | return get_key_haup_common(ir, protocol, scancode, toggle, 6); |
39cf1e81 JF |
147 | } |
148 | ||
6d741bfe | 149 | static int get_key_pixelview(struct IR_i2c *ir, enum rc_proto *protocol, |
4dd9bb91 | 150 | u32 *scancode, u8 *toggle) |
1da177e4 | 151 | { |
4ac97914 | 152 | unsigned char b; |
1da177e4 LT |
153 | |
154 | /* poll IR chip */ | |
c668f32d | 155 | if (1 != i2c_master_recv(ir->c, &b, 1)) { |
50a762b4 | 156 | dev_dbg(&ir->rc->dev, "read error\n"); |
1da177e4 LT |
157 | return -EIO; |
158 | } | |
4dd9bb91 | 159 | |
6d741bfe | 160 | *protocol = RC_PROTO_OTHER; |
4dd9bb91 DH |
161 | *scancode = b; |
162 | *toggle = 0; | |
1da177e4 LT |
163 | return 1; |
164 | } | |
165 | ||
6d741bfe | 166 | static int get_key_fusionhdtv(struct IR_i2c *ir, enum rc_proto *protocol, |
4dd9bb91 | 167 | u32 *scancode, u8 *toggle) |
d54d6980 CZ |
168 | { |
169 | unsigned char buf[4]; | |
170 | ||
171 | /* poll IR chip */ | |
c668f32d | 172 | if (4 != i2c_master_recv(ir->c, buf, 4)) { |
50a762b4 | 173 | dev_dbg(&ir->rc->dev, "read error\n"); |
d54d6980 CZ |
174 | return -EIO; |
175 | } | |
176 | ||
50a762b4 SY |
177 | if (buf[0] != 0 || buf[1] != 0 || buf[2] != 0 || buf[3] != 0) |
178 | dev_dbg(&ir->rc->dev, "%s: %*ph\n", __func__, 4, buf); | |
d54d6980 CZ |
179 | |
180 | /* no key pressed or signal from other ir remote */ | |
181 | if(buf[0] != 0x1 || buf[1] != 0xfe) | |
182 | return 0; | |
183 | ||
6d741bfe | 184 | *protocol = RC_PROTO_UNKNOWN; |
4dd9bb91 DH |
185 | *scancode = buf[2]; |
186 | *toggle = 0; | |
d54d6980 | 187 | return 1; |
d54d6980 CZ |
188 | } |
189 | ||
6d741bfe | 190 | static int get_key_knc1(struct IR_i2c *ir, enum rc_proto *protocol, |
4dd9bb91 | 191 | u32 *scancode, u8 *toggle) |
1da177e4 LT |
192 | { |
193 | unsigned char b; | |
194 | ||
195 | /* poll IR chip */ | |
c668f32d | 196 | if (1 != i2c_master_recv(ir->c, &b, 1)) { |
50a762b4 | 197 | dev_dbg(&ir->rc->dev, "read error\n"); |
1da177e4 LT |
198 | return -EIO; |
199 | } | |
200 | ||
201 | /* it seems that 0xFE indicates that a button is still hold | |
4f9c05aa MCC |
202 | down, while 0xff indicates that no button is hold |
203 | down. 0xfe sequences are sometimes interrupted by 0xFF */ | |
1da177e4 | 204 | |
50a762b4 | 205 | dev_dbg(&ir->rc->dev, "key %02x\n", b); |
1da177e4 | 206 | |
4f9c05aa | 207 | if (b == 0xff) |
1da177e4 LT |
208 | return 0; |
209 | ||
4f9c05aa | 210 | if (b == 0xfe) |
1da177e4 LT |
211 | /* keep old data */ |
212 | return 1; | |
213 | ||
6d741bfe | 214 | *protocol = RC_PROTO_UNKNOWN; |
4dd9bb91 DH |
215 | *scancode = b; |
216 | *toggle = 0; | |
1da177e4 LT |
217 | return 1; |
218 | } | |
219 | ||
6d741bfe | 220 | static int get_key_avermedia_cardbus(struct IR_i2c *ir, enum rc_proto *protocol, |
4dd9bb91 | 221 | u32 *scancode, u8 *toggle) |
cb3bf504 OJ |
222 | { |
223 | unsigned char subaddr, key, keygroup; | |
c668f32d | 224 | struct i2c_msg msg[] = { { .addr = ir->c->addr, .flags = 0, |
cb3bf504 | 225 | .buf = &subaddr, .len = 1}, |
c668f32d | 226 | { .addr = ir->c->addr, .flags = I2C_M_RD, |
cb3bf504 OJ |
227 | .buf = &key, .len = 1} }; |
228 | subaddr = 0x0d; | |
c668f32d | 229 | if (2 != i2c_transfer(ir->c->adapter, msg, 2)) { |
50a762b4 | 230 | dev_dbg(&ir->rc->dev, "read error\n"); |
cb3bf504 OJ |
231 | return -EIO; |
232 | } | |
233 | ||
234 | if (key == 0xff) | |
235 | return 0; | |
236 | ||
237 | subaddr = 0x0b; | |
238 | msg[1].buf = &keygroup; | |
c668f32d | 239 | if (2 != i2c_transfer(ir->c->adapter, msg, 2)) { |
50a762b4 | 240 | dev_dbg(&ir->rc->dev, "read error\n"); |
cb3bf504 OJ |
241 | return -EIO; |
242 | } | |
243 | ||
244 | if (keygroup == 0xff) | |
245 | return 0; | |
246 | ||
50a762b4 | 247 | dev_dbg(&ir->rc->dev, "read key 0x%02x/0x%02x\n", key, keygroup); |
34fe2784 | 248 | if (keygroup < 2 || keygroup > 4) { |
50a762b4 SY |
249 | dev_warn(&ir->rc->dev, "warning: invalid key group 0x%02x for key 0x%02x\n", |
250 | keygroup, key); | |
cb3bf504 OJ |
251 | } |
252 | key |= (keygroup & 1) << 6; | |
253 | ||
6d741bfe | 254 | *protocol = RC_PROTO_UNKNOWN; |
4dd9bb91 DH |
255 | *scancode = key; |
256 | if (ir->c->addr == 0x41) /* AVerMedia EM78P153 */ | |
257 | *scancode |= keygroup << 8; | |
258 | *toggle = 0; | |
cb3bf504 OJ |
259 | return 1; |
260 | } | |
261 | ||
1da177e4 LT |
262 | /* ----------------------------------------------------------------------- */ |
263 | ||
90bf3aab | 264 | static int ir_key_poll(struct IR_i2c *ir) |
1da177e4 | 265 | { |
6d741bfe | 266 | enum rc_proto protocol; |
4dd9bb91 DH |
267 | u32 scancode; |
268 | u8 toggle; | |
1da177e4 LT |
269 | int rc; |
270 | ||
50a762b4 | 271 | dev_dbg(&ir->rc->dev, "%s\n", __func__); |
4dd9bb91 | 272 | rc = ir->get_key(ir, &protocol, &scancode, &toggle); |
1da177e4 | 273 | if (rc < 0) { |
50a762b4 | 274 | dev_warn(&ir->rc->dev, "error %d\n", rc); |
90bf3aab | 275 | return rc; |
1da177e4 LT |
276 | } |
277 | ||
e6bcb2f3 | 278 | if (rc) { |
50a762b4 | 279 | dev_dbg(&ir->rc->dev, "%s: proto = 0x%04x, scancode = 0x%08x\n", |
120703f9 DH |
280 | __func__, protocol, scancode); |
281 | rc_keydown(ir->rc, protocol, scancode, toggle); | |
e6bcb2f3 | 282 | } |
90bf3aab | 283 | return 0; |
1da177e4 LT |
284 | } |
285 | ||
c4028958 | 286 | static void ir_work(struct work_struct *work) |
1da177e4 | 287 | { |
90bf3aab | 288 | int rc; |
c1089bdc | 289 | struct IR_i2c *ir = container_of(work, struct IR_i2c, work.work); |
8083c520 | 290 | |
90bf3aab MCC |
291 | rc = ir_key_poll(ir); |
292 | if (rc == -ENODEV) { | |
293 | rc_unregister_device(ir->rc); | |
294 | ir->rc = NULL; | |
295 | return; | |
296 | } | |
297 | ||
c72ba8e6 | 298 | schedule_delayed_work(&ir->work, msecs_to_jiffies(ir->polling_interval)); |
1da177e4 LT |
299 | } |
300 | ||
a6927d81 SY |
301 | static int ir_open(struct rc_dev *dev) |
302 | { | |
303 | struct IR_i2c *ir = dev->priv; | |
304 | ||
305 | schedule_delayed_work(&ir->work, 0); | |
306 | ||
307 | return 0; | |
308 | } | |
309 | ||
310 | static void ir_close(struct rc_dev *dev) | |
311 | { | |
312 | struct IR_i2c *ir = dev->priv; | |
313 | ||
314 | cancel_delayed_work_sync(&ir->work); | |
315 | } | |
316 | ||
1da177e4 LT |
317 | /* ----------------------------------------------------------------------- */ |
318 | ||
c668f32d | 319 | static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id) |
1da177e4 | 320 | { |
02858eed | 321 | char *ir_codes = NULL; |
9a4cc5ac | 322 | const char *name = NULL; |
6d741bfe | 323 | u64 rc_proto = RC_PROTO_BIT_UNKNOWN; |
afd1a0c9 | 324 | struct IR_i2c *ir; |
2eb25832 | 325 | struct rc_dev *rc = NULL; |
c668f32d JD |
326 | struct i2c_adapter *adap = client->adapter; |
327 | unsigned short addr = client->addr; | |
b07b4783 | 328 | int err; |
1da177e4 | 329 | |
c02b211d | 330 | ir = devm_kzalloc(&client->dev, sizeof(*ir), GFP_KERNEL); |
2eb25832 MCC |
331 | if (!ir) |
332 | return -ENOMEM; | |
b7df3910 | 333 | |
c668f32d | 334 | ir->c = client; |
c72ba8e6 | 335 | ir->polling_interval = DEFAULT_POLLING_INTERVAL; |
c668f32d | 336 | i2c_set_clientdata(client, ir); |
d21838dd | 337 | |
1da177e4 LT |
338 | switch(addr) { |
339 | case 0x64: | |
340 | name = "Pixelview"; | |
341 | ir->get_key = get_key_pixelview; | |
6d741bfe | 342 | rc_proto = RC_PROTO_BIT_OTHER; |
02858eed | 343 | ir_codes = RC_MAP_EMPTY; |
1da177e4 | 344 | break; |
1da177e4 | 345 | case 0x18: |
ca39d84d | 346 | case 0x1f: |
1da177e4 LT |
347 | case 0x1a: |
348 | name = "Hauppauge"; | |
349 | ir->get_key = get_key_haup; | |
6d741bfe | 350 | rc_proto = RC_PROTO_BIT_RC5; |
20624106 | 351 | ir_codes = RC_MAP_HAUPPAUGE; |
1da177e4 LT |
352 | break; |
353 | case 0x30: | |
d5e52653 MCC |
354 | name = "KNC One"; |
355 | ir->get_key = get_key_knc1; | |
6d741bfe | 356 | rc_proto = RC_PROTO_BIT_OTHER; |
02858eed | 357 | ir_codes = RC_MAP_EMPTY; |
1da177e4 | 358 | break; |
d54d6980 | 359 | case 0x6b: |
3c44358c MK |
360 | name = "FusionHDTV"; |
361 | ir->get_key = get_key_fusionhdtv; | |
6d741bfe | 362 | rc_proto = RC_PROTO_BIT_UNKNOWN; |
02858eed | 363 | ir_codes = RC_MAP_FUSIONHDTV_MCE; |
d54d6980 | 364 | break; |
cb3bf504 OJ |
365 | case 0x40: |
366 | name = "AVerMedia Cardbus remote"; | |
367 | ir->get_key = get_key_avermedia_cardbus; | |
6d741bfe | 368 | rc_proto = RC_PROTO_BIT_OTHER; |
02858eed | 369 | ir_codes = RC_MAP_AVERMEDIA_CARDBUS; |
cb3bf504 | 370 | break; |
34fe2784 OZ |
371 | case 0x41: |
372 | name = "AVerMedia EM78P153"; | |
373 | ir->get_key = get_key_avermedia_cardbus; | |
6d741bfe | 374 | rc_proto = RC_PROTO_BIT_OTHER; |
34fe2784 OZ |
375 | /* RM-KV remote, seems to be same as RM-K6 */ |
376 | ir_codes = RC_MAP_AVERMEDIA_M733A_RM_K6; | |
377 | break; | |
c69a4af6 AW |
378 | case 0x71: |
379 | name = "Hauppauge/Zilog Z8"; | |
380 | ir->get_key = get_key_haup_xvr; | |
6d741bfe SY |
381 | rc_proto = RC_PROTO_BIT_RC5 | RC_PROTO_BIT_RC6_MCE | |
382 | RC_PROTO_BIT_RC6_6A_32; | |
20624106 | 383 | ir_codes = RC_MAP_HAUPPAUGE; |
c69a4af6 | 384 | break; |
1da177e4 LT |
385 | } |
386 | ||
4d7a2d67 JD |
387 | /* Let the caller override settings */ |
388 | if (client->dev.platform_data) { | |
389 | const struct IR_i2c_init_data *init_data = | |
390 | client->dev.platform_data; | |
391 | ||
392 | ir_codes = init_data->ir_codes; | |
2eb25832 MCC |
393 | rc = init_data->rc_dev; |
394 | ||
4d7a2d67 | 395 | name = init_data->name; |
1b6e59e3 | 396 | if (init_data->type) |
6d741bfe | 397 | rc_proto = init_data->type; |
1b6e59e3 | 398 | |
c72ba8e6 MCC |
399 | if (init_data->polling_interval) |
400 | ir->polling_interval = init_data->polling_interval; | |
401 | ||
1b6e59e3 AW |
402 | switch (init_data->internal_get_key_func) { |
403 | case IR_KBD_GET_KEY_CUSTOM: | |
404 | /* The bridge driver provided us its own function */ | |
405 | ir->get_key = init_data->get_key; | |
406 | break; | |
407 | case IR_KBD_GET_KEY_PIXELVIEW: | |
408 | ir->get_key = get_key_pixelview; | |
409 | break; | |
1b6e59e3 AW |
410 | case IR_KBD_GET_KEY_HAUP: |
411 | ir->get_key = get_key_haup; | |
412 | break; | |
413 | case IR_KBD_GET_KEY_KNC1: | |
414 | ir->get_key = get_key_knc1; | |
415 | break; | |
416 | case IR_KBD_GET_KEY_FUSIONHDTV: | |
417 | ir->get_key = get_key_fusionhdtv; | |
418 | break; | |
419 | case IR_KBD_GET_KEY_HAUP_XVR: | |
420 | ir->get_key = get_key_haup_xvr; | |
421 | break; | |
422 | case IR_KBD_GET_KEY_AVERMEDIA_CARDBUS: | |
423 | ir->get_key = get_key_avermedia_cardbus; | |
424 | break; | |
425 | } | |
4d7a2d67 JD |
426 | } |
427 | ||
2eb25832 MCC |
428 | if (!rc) { |
429 | /* | |
39c1cb2b | 430 | * If platform_data doesn't specify rc_dev, initialize it |
2eb25832 MCC |
431 | * internally |
432 | */ | |
0f7499fd | 433 | rc = rc_allocate_device(RC_DRIVER_SCANCODE); |
c02b211d LP |
434 | if (!rc) |
435 | return -ENOMEM; | |
2eb25832 MCC |
436 | } |
437 | ir->rc = rc; | |
438 | ||
9a4cc5ac | 439 | /* Make sure we are all setup before going on */ |
6d741bfe | 440 | if (!name || !ir->get_key || !rc_proto || !ir_codes) { |
50a762b4 SY |
441 | dev_warn(&client->dev, "Unsupported device at address 0x%02x\n", |
442 | addr); | |
9a4cc5ac JD |
443 | err = -ENODEV; |
444 | goto err_out_free; | |
445 | } | |
446 | ||
b07b4783 | 447 | ir->ir_codes = ir_codes; |
d5e52653 | 448 | |
afc7f24c | 449 | snprintf(ir->phys, sizeof(ir->phys), "%s/%s", dev_name(&adap->dev), |
c668f32d | 450 | dev_name(&client->dev)); |
ac9cd976 | 451 | |
2eb25832 MCC |
452 | /* |
453 | * Initialize input_dev fields | |
454 | * It doesn't make sense to allow overriding them via platform_data | |
455 | */ | |
d8b4b582 | 456 | rc->input_id.bustype = BUS_I2C; |
d8b4b582 | 457 | rc->input_phys = ir->phys; |
afc7f24c SY |
458 | rc->device_name = name; |
459 | rc->dev.parent = &client->dev; | |
a6927d81 SY |
460 | rc->priv = ir; |
461 | rc->open = ir_open; | |
462 | rc->close = ir_close; | |
2eb25832 MCC |
463 | |
464 | /* | |
465 | * Initialize the other fields of rc_dev | |
466 | */ | |
467 | rc->map_name = ir->ir_codes; | |
6d741bfe | 468 | rc->allowed_protocols = rc_proto; |
2eb25832 | 469 | if (!rc->driver_name) |
50a762b4 | 470 | rc->driver_name = KBUILD_MODNAME; |
b7df3910 | 471 | |
a6927d81 SY |
472 | INIT_DELAYED_WORK(&ir->work, ir_work); |
473 | ||
d8b4b582 | 474 | err = rc_register_device(rc); |
b07b4783 | 475 | if (err) |
c668f32d | 476 | goto err_out_free; |
b07b4783 | 477 | |
1da177e4 | 478 | return 0; |
b07b4783 | 479 | |
b07b4783 | 480 | err_out_free: |
2eb25832 | 481 | /* Only frees rc if it were allocated internally */ |
d8b4b582 | 482 | rc_free_device(rc); |
b07b4783 | 483 | return err; |
1da177e4 LT |
484 | } |
485 | ||
c668f32d | 486 | static int ir_remove(struct i2c_client *client) |
1da177e4 | 487 | { |
4ac97914 | 488 | struct IR_i2c *ir = i2c_get_clientdata(client); |
1da177e4 LT |
489 | |
490 | /* kill outstanding polls */ | |
c1089bdc | 491 | cancel_delayed_work_sync(&ir->work); |
1da177e4 | 492 | |
c668f32d | 493 | /* unregister device */ |
8f1aeedf | 494 | rc_unregister_device(ir->rc); |
1da177e4 LT |
495 | |
496 | /* free memory */ | |
1da177e4 LT |
497 | return 0; |
498 | } | |
499 | ||
c668f32d JD |
500 | static const struct i2c_device_id ir_kbd_id[] = { |
501 | /* Generic entry for any IR receiver */ | |
502 | { "ir_video", 0 }, | |
f5d887ae | 503 | /* IR device specific entries should be added here */ |
ab5222ed SY |
504 | { "ir_z8f0811_haup", 0 }, |
505 | { "ir_z8f0811_hdpvr", 0 }, | |
c668f32d JD |
506 | { } |
507 | }; | |
cb3bf504 | 508 | |
c6e8d86f | 509 | static struct i2c_driver ir_kbd_driver = { |
c668f32d JD |
510 | .driver = { |
511 | .name = "ir-kbd-i2c", | |
512 | }, | |
513 | .probe = ir_probe, | |
514 | .remove = ir_remove, | |
515 | .id_table = ir_kbd_id, | |
516 | }; | |
1da177e4 | 517 | |
c6e8d86f AL |
518 | module_i2c_driver(ir_kbd_driver); |
519 | ||
1da177e4 LT |
520 | /* ----------------------------------------------------------------------- */ |
521 | ||
522 | MODULE_AUTHOR("Gerd Knorr, Michal Kochanowicz, Christoph Bartelmus, Ulrich Mueller"); | |
523 | MODULE_DESCRIPTION("input driver for i2c IR remote controls"); | |
524 | MODULE_LICENSE("GPL"); |