3 * keyboard input driver for i2c IR remote controls
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>
11 * modified for em2820 based USB TV tuners by
12 * Markus Rechberger <mrechberger@gmail.com>
13 * modified for DViCO Fusion HDTV 5 RT GOLD by
14 * Chaogui Zhang <czhang1974@gmail.com>
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>
19 * modified for AVerMedia Cardbus by
20 * Oldrich Jedlicka <oldium.pro@seznam.cz>
21 * Zilog Transmitter portions/ideas were derived from GPLv2+ sources:
22 * - drivers/char/pctv_zilogir.[ch] from Hauppauge Broadway product
23 * Copyright 2011 Hauppauge Computer works
24 * - drivers/staging/media/lirc/lirc_zilog.c
25 * Copyright (c) 2000 Gerd Knorr <kraxel@goldbach.in-berlin.de>
26 * Michal Kochanowicz <mkochano@pld.org.pl>
27 * Christoph Bartelmus <lirc@bartelmus.de>
28 * Ulrich Mueller <ulrich.mueller42@web.de>
29 * Stefan Jahn <stefan@lkcc.org>
30 * Jerome Brock <jbrock@users.sourceforge.net>
31 * Thomas Reitmayr (treitmayr@yahoo.com)
32 * Mark Weaver <mark@npsl.co.uk>
33 * Jarod Wilson <jarod@redhat.com>
34 * Copyright (C) 2011 Andy Walls <awalls@md.metrocast.net>
36 * This program is free software; you can redistribute it and/or modify
37 * it under the terms of the GNU General Public License as published by
38 * the Free Software Foundation; either version 2 of the License, or
39 * (at your option) any later version.
41 * This program is distributed in the hope that it will be useful,
42 * but WITHOUT ANY WARRANTY; without even the implied warranty of
43 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44 * GNU General Public License for more details.
48 #include <asm/unaligned.h>
49 #include <linux/module.h>
50 #include <linux/init.h>
51 #include <linux/kernel.h>
52 #include <linux/string.h>
53 #include <linux/timer.h>
54 #include <linux/delay.h>
55 #include <linux/errno.h>
56 #include <linux/slab.h>
57 #include <linux/i2c.h>
58 #include <linux/workqueue.h>
60 #include <media/rc-core.h>
61 #include <media/i2c/ir-kbd-i2c.h>
66 static bool enable_hdpvr
;
67 module_param(enable_hdpvr
, bool, 0644);
69 static int get_key_haup_common(struct IR_i2c
*ir
, enum rc_proto
*protocol
,
70 u32
*scancode
, u8
*ptoggle
, int size
)
73 int start
, range
, toggle
, dev
, code
, ircode
, vendor
;
76 if (size
!= i2c_master_recv(ir
->c
, buf
, size
))
80 int offset
= (size
== 6) ? 3 : 0;
82 /* split rc5 data block ... */
83 start
= (buf
[offset
] >> 7) & 1;
84 range
= (buf
[offset
] >> 6) & 1;
85 toggle
= (buf
[offset
] >> 5) & 1;
86 dev
= buf
[offset
] & 0x1f;
87 code
= (buf
[offset
+1] >> 2) & 0x3f;
89 /* rc5 has two start bits
90 * the first bit must be one
91 * the second bit defines the command range:
92 * 1 = 0-63, 0 = 64 - 127
98 /* filter out invalid key presses */
99 ircode
= (start
<< 12) | (toggle
<< 11) | (dev
<< 6) | code
;
100 if ((ircode
& 0x1fff) == 0x1fff)
106 dev_dbg(&ir
->rc
->dev
,
107 "ir hauppauge (rc5): s%d r%d t%d dev=%d code=%d\n",
108 start
, range
, toggle
, dev
, code
);
110 *protocol
= RC_PROTO_RC5
;
111 *scancode
= RC_SCANCODE_RC5(dev
, code
);
115 } else if (size
== 6 && (buf
[0] & 0x40)) {
118 vendor
= get_unaligned_be16(buf
+ 1);
120 if (vendor
== 0x800f) {
121 *ptoggle
= (dev
& 0x80) != 0;
122 *protocol
= RC_PROTO_RC6_MCE
;
124 dev_dbg(&ir
->rc
->dev
,
125 "ir hauppauge (rc6-mce): t%d vendor=%d dev=%d code=%d\n",
126 *ptoggle
, vendor
, dev
, code
);
129 *protocol
= RC_PROTO_RC6_6A_32
;
130 dev_dbg(&ir
->rc
->dev
,
131 "ir hauppauge (rc6-6a-32): vendor=%d dev=%d code=%d\n",
135 *scancode
= RC_SCANCODE_RC6_6A(vendor
, dev
, code
);
143 static int get_key_haup(struct IR_i2c
*ir
, enum rc_proto
*protocol
,
144 u32
*scancode
, u8
*toggle
)
146 return get_key_haup_common(ir
, protocol
, scancode
, toggle
, 3);
149 static int get_key_haup_xvr(struct IR_i2c
*ir
, enum rc_proto
*protocol
,
150 u32
*scancode
, u8
*toggle
)
153 unsigned char buf
[1] = { 0 };
156 * This is the same apparent "are you ready?" poll command observed
157 * watching Windows driver traffic and implemented in lirc_zilog. With
158 * this added, we get far saner remote behavior with z8 chips on usb
159 * connected devices, even with the default polling interval of 100ms.
161 ret
= i2c_master_send(ir
->c
, buf
, 1);
163 return (ret
< 0) ? ret
: -EINVAL
;
165 return get_key_haup_common(ir
, protocol
, scancode
, toggle
, 6);
168 static int get_key_pixelview(struct IR_i2c
*ir
, enum rc_proto
*protocol
,
169 u32
*scancode
, u8
*toggle
)
174 if (1 != i2c_master_recv(ir
->c
, &b
, 1)) {
175 dev_dbg(&ir
->rc
->dev
, "read error\n");
179 *protocol
= RC_PROTO_OTHER
;
185 static int get_key_fusionhdtv(struct IR_i2c
*ir
, enum rc_proto
*protocol
,
186 u32
*scancode
, u8
*toggle
)
188 unsigned char buf
[4];
191 if (4 != i2c_master_recv(ir
->c
, buf
, 4)) {
192 dev_dbg(&ir
->rc
->dev
, "read error\n");
196 if (buf
[0] != 0 || buf
[1] != 0 || buf
[2] != 0 || buf
[3] != 0)
197 dev_dbg(&ir
->rc
->dev
, "%s: %*ph\n", __func__
, 4, buf
);
199 /* no key pressed or signal from other ir remote */
200 if(buf
[0] != 0x1 || buf
[1] != 0xfe)
203 *protocol
= RC_PROTO_UNKNOWN
;
209 static int get_key_knc1(struct IR_i2c
*ir
, enum rc_proto
*protocol
,
210 u32
*scancode
, u8
*toggle
)
215 if (1 != i2c_master_recv(ir
->c
, &b
, 1)) {
216 dev_dbg(&ir
->rc
->dev
, "read error\n");
220 /* it seems that 0xFE indicates that a button is still hold
221 down, while 0xff indicates that no button is hold
222 down. 0xfe sequences are sometimes interrupted by 0xFF */
224 dev_dbg(&ir
->rc
->dev
, "key %02x\n", b
);
233 *protocol
= RC_PROTO_UNKNOWN
;
239 static int get_key_avermedia_cardbus(struct IR_i2c
*ir
, enum rc_proto
*protocol
,
240 u32
*scancode
, u8
*toggle
)
242 unsigned char subaddr
, key
, keygroup
;
243 struct i2c_msg msg
[] = { { .addr
= ir
->c
->addr
, .flags
= 0,
244 .buf
= &subaddr
, .len
= 1},
245 { .addr
= ir
->c
->addr
, .flags
= I2C_M_RD
,
246 .buf
= &key
, .len
= 1} };
248 if (2 != i2c_transfer(ir
->c
->adapter
, msg
, 2)) {
249 dev_dbg(&ir
->rc
->dev
, "read error\n");
257 msg
[1].buf
= &keygroup
;
258 if (2 != i2c_transfer(ir
->c
->adapter
, msg
, 2)) {
259 dev_dbg(&ir
->rc
->dev
, "read error\n");
263 if (keygroup
== 0xff)
266 dev_dbg(&ir
->rc
->dev
, "read key 0x%02x/0x%02x\n", key
, keygroup
);
267 if (keygroup
< 2 || keygroup
> 4) {
268 dev_warn(&ir
->rc
->dev
, "warning: invalid key group 0x%02x for key 0x%02x\n",
271 key
|= (keygroup
& 1) << 6;
273 *protocol
= RC_PROTO_UNKNOWN
;
275 if (ir
->c
->addr
== 0x41) /* AVerMedia EM78P153 */
276 *scancode
|= keygroup
<< 8;
281 /* ----------------------------------------------------------------------- */
283 static int ir_key_poll(struct IR_i2c
*ir
)
285 enum rc_proto protocol
;
290 dev_dbg(&ir
->rc
->dev
, "%s\n", __func__
);
291 rc
= ir
->get_key(ir
, &protocol
, &scancode
, &toggle
);
293 dev_warn(&ir
->rc
->dev
, "error %d\n", rc
);
298 dev_dbg(&ir
->rc
->dev
, "%s: proto = 0x%04x, scancode = 0x%08x\n",
299 __func__
, protocol
, scancode
);
300 rc_keydown(ir
->rc
, protocol
, scancode
, toggle
);
305 static void ir_work(struct work_struct
*work
)
308 struct IR_i2c
*ir
= container_of(work
, struct IR_i2c
, work
.work
);
311 * If the transmit code is holding the lock, skip polling for
312 * IR, we'll get it to it next time round
314 if (mutex_trylock(&ir
->lock
)) {
315 rc
= ir_key_poll(ir
);
316 mutex_unlock(&ir
->lock
);
318 rc_unregister_device(ir
->rc
);
324 schedule_delayed_work(&ir
->work
, msecs_to_jiffies(ir
->polling_interval
));
327 static int ir_open(struct rc_dev
*dev
)
329 struct IR_i2c
*ir
= dev
->priv
;
331 schedule_delayed_work(&ir
->work
, 0);
336 static void ir_close(struct rc_dev
*dev
)
338 struct IR_i2c
*ir
= dev
->priv
;
340 cancel_delayed_work_sync(&ir
->work
);
343 /* Zilog Transmit Interface */
344 #define XTAL_FREQ 18432000
346 #define ZILOG_SEND 0x80
347 #define ZILOG_UIR_END 0x40
348 #define ZILOG_INIT_END 0x20
349 #define ZILOG_LIR_END 0x10
351 #define ZILOG_STATUS_OK 0x80
352 #define ZILOG_STATUS_TX 0x40
353 #define ZILOG_STATUS_SET 0x20
356 * As you can see here, very few different lengths of pulse and space
357 * can be encoded. This means that the hardware does not work well with
358 * recorded IR. It's best to work with generated IR, like from ir-ctl or
359 * the in-kernel encoders.
363 u16 pulse
[7]; /* not aligned */
366 u16 space
[8]; /* not aligned */
371 static int send_data_block(struct IR_i2c
*ir
, int cmd
,
372 struct code_block
*code_block
)
377 p
= &code_block
->length
;
378 for (i
= 0; p
< code_block
->csum
; i
++)
379 code_block
->csum
[i
& 1] ^= *p
++;
381 p
= &code_block
->length
;
383 for (i
= 0; i
< sizeof(*code_block
);) {
384 int tosend
= sizeof(*code_block
) - i
;
389 for (j
= 0; j
< tosend
; ++j
)
390 buf
[1 + j
] = p
[i
+ j
];
391 dev_dbg(&ir
->rc
->dev
, "%*ph", tosend
+ 1, buf
);
392 ret
= i2c_master_send(ir
->tx_c
, buf
, tosend
+ 1);
393 if (ret
!= tosend
+ 1) {
394 dev_dbg(&ir
->rc
->dev
,
395 "i2c_master_send failed with %d\n", ret
);
396 return ret
< 0 ? ret
: -EIO
;
403 ret
= i2c_master_send(ir
->tx_c
, buf
, 2);
405 dev_err(&ir
->rc
->dev
, "i2c_master_send failed with %d\n", ret
);
406 return ret
< 0 ? ret
: -EIO
;
409 usleep_range(2000, 5000);
411 ret
= i2c_master_send(ir
->tx_c
, buf
, 1);
413 dev_err(&ir
->rc
->dev
, "i2c_master_send failed with %d\n", ret
);
414 return ret
< 0 ? ret
: -EIO
;
420 static int zilog_init(struct IR_i2c
*ir
)
422 struct code_block code_block
= { .length
= sizeof(code_block
) };
426 put_unaligned_be16(0x1000, &code_block
.pulse
[3]);
428 ret
= send_data_block(ir
, ZILOG_INIT_END
, &code_block
);
432 ret
= i2c_master_recv(ir
->tx_c
, buf
, 4);
434 dev_err(&ir
->c
->dev
, "failed to retrieve firmware version: %d\n",
436 return ret
< 0 ? ret
: -EIO
;
439 dev_info(&ir
->c
->dev
, "Zilog/Hauppauge IR blaster firmware version %d.%d.%d\n",
440 buf
[1], buf
[2], buf
[3]);
446 * If the last slot for pulse is the same as the current slot for pulse,
447 * then use slot no 7.
449 static void copy_codes(u8
*dst
, u8
*src
, unsigned int count
)
455 if ((c
& 0xf0) == last
) {
456 *dst
++ = 0x70 | (c
& 0xf);
465 * When looking for repeats, we don't care about the trailing space. This
466 * is set to the shortest possible anyway.
468 static int cmp_no_trail(u8
*a
, u8
*b
, unsigned int count
)
475 return (*a
& 0xf0) - (*b
& 0xf0);
478 static int find_slot(u16
*array
, unsigned int size
, u16 val
)
482 for (i
= 0; i
< size
; i
++) {
483 if (get_unaligned_be16(&array
[i
]) == val
) {
485 } else if (!array
[i
]) {
486 put_unaligned_be16(val
, &array
[i
]);
494 static int zilog_ir_format(struct rc_dev
*rcdev
, unsigned int *txbuf
,
495 unsigned int count
, struct code_block
*code_block
)
497 struct IR_i2c
*ir
= rcdev
->priv
;
498 int rep
, i
, l
, p
= 0, s
, c
= 0;
502 code_block
->carrier_pulse
= DIV_ROUND_CLOSEST(
503 ir
->duty_cycle
* XTAL_FREQ
/ 1000, ir
->carrier
);
504 code_block
->carrier_space
= DIV_ROUND_CLOSEST(
505 (100 - ir
->duty_cycle
) * XTAL_FREQ
/ 1000, ir
->carrier
);
507 for (i
= 0; i
< count
; i
++) {
508 if (c
>= ARRAY_SIZE(codes
) - 1) {
509 dev_warn(&rcdev
->dev
, "IR too long, cannot transmit\n");
514 * Lengths more than 142220us cannot be encoded; also
515 * this checks for multiply overflow
517 if (txbuf
[i
] > 142220)
520 l
= DIV_ROUND_CLOSEST((XTAL_FREQ
/ 1000) * txbuf
[i
], 40000);
523 s
= find_slot(code_block
->space
,
524 ARRAY_SIZE(code_block
->space
), l
);
526 dev_warn(&rcdev
->dev
, "Too many different lengths spaces, cannot transmit");
530 /* We have a pulse and space */
531 codes
[c
++] = (p
<< 4) | s
;
533 p
= find_slot(code_block
->pulse
,
534 ARRAY_SIZE(code_block
->pulse
), l
);
536 dev_warn(&rcdev
->dev
, "Too many different lengths pulses, cannot transmit");
542 /* We have to encode the trailing pulse. Find the shortest space */
544 for (i
= 1; i
< ARRAY_SIZE(code_block
->space
); i
++) {
545 u16 d
= get_unaligned_be16(&code_block
->space
[i
]);
547 if (get_unaligned_be16(&code_block
->space
[s
]) > d
)
551 codes
[c
++] = (p
<< 4) | s
;
553 dev_dbg(&rcdev
->dev
, "generated %d codes\n", c
);
556 * Are the last N codes (so pulse + space) repeating 3 times?
557 * if so we can shorten the codes list and use code 0xc0 to repeat
562 for (rep
= c
/ 3; rep
>= 1; rep
--) {
563 if (!memcmp(&codes
[c
- rep
* 3], &codes
[c
- rep
* 2], rep
) &&
564 !cmp_no_trail(&codes
[c
- rep
], &codes
[c
- rep
* 2], rep
)) {
571 /* first copy any leading non-repeating */
572 int leading
= c
- rep
* 3;
574 if (leading
+ rep
>= ARRAY_SIZE(code_block
->codes
) - 3) {
575 dev_warn(&rcdev
->dev
, "IR too long, cannot transmit\n");
579 dev_dbg(&rcdev
->dev
, "found trailing %d repeat\n", rep
);
580 copy_codes(code_block
->codes
, codes
, leading
);
581 code_block
->codes
[leading
] = 0x82;
582 copy_codes(code_block
->codes
+ leading
+ 1, codes
+ leading
,
584 c
= leading
+ 1 + rep
;
585 code_block
->codes
[c
++] = 0xc0;
587 if (c
>= ARRAY_SIZE(code_block
->codes
) - 3) {
588 dev_warn(&rcdev
->dev
, "IR too long, cannot transmit\n");
592 dev_dbg(&rcdev
->dev
, "found no trailing repeat\n");
593 code_block
->codes
[0] = 0x82;
594 copy_codes(code_block
->codes
+ 1, codes
, c
);
596 code_block
->codes
[c
++] = 0xc4;
599 while (c
< ARRAY_SIZE(code_block
->codes
))
600 code_block
->codes
[c
++] = 0x83;
605 static int zilog_tx(struct rc_dev
*rcdev
, unsigned int *txbuf
,
608 struct IR_i2c
*ir
= rcdev
->priv
;
609 struct code_block code_block
= { .length
= sizeof(code_block
) };
613 ret
= zilog_ir_format(rcdev
, txbuf
, count
, &code_block
);
617 ret
= mutex_lock_interruptible(&ir
->lock
);
621 ret
= send_data_block(ir
, ZILOG_UIR_END
, &code_block
);
625 ret
= i2c_master_recv(ir
->tx_c
, buf
, 1);
627 dev_err(&ir
->rc
->dev
, "i2c_master_recv failed with %d\n", ret
);
631 dev_dbg(&ir
->rc
->dev
, "code set status: %02x\n", buf
[0]);
633 if (buf
[0] != (ZILOG_STATUS_OK
| ZILOG_STATUS_SET
)) {
634 dev_err(&ir
->rc
->dev
, "unexpected IR TX response %02x\n",
643 ret
= i2c_master_send(ir
->tx_c
, buf
, 2);
645 dev_err(&ir
->rc
->dev
, "i2c_master_send failed with %d\n", ret
);
651 dev_dbg(&ir
->rc
->dev
, "send command sent\n");
654 * This bit NAKs until the device is ready, so we retry it
655 * sleeping a bit each time. This seems to be what the windows
656 * driver does, approximately.
659 for (i
= 0; i
< 20; ++i
) {
660 set_current_state(TASK_UNINTERRUPTIBLE
);
661 schedule_timeout(msecs_to_jiffies(50));
662 ret
= i2c_master_send(ir
->tx_c
, buf
, 1);
665 dev_dbg(&ir
->rc
->dev
,
666 "NAK expected: i2c_master_send failed with %d (try %d)\n",
671 dev_err(&ir
->rc
->dev
,
672 "IR TX chip never got ready: last i2c_master_send failed with %d\n",
679 i
= i2c_master_recv(ir
->tx_c
, buf
, 1);
681 dev_err(&ir
->rc
->dev
, "i2c_master_recv failed with %d\n", ret
);
684 } else if (buf
[0] != ZILOG_STATUS_OK
) {
685 dev_err(&ir
->rc
->dev
, "unexpected IR TX response #2: %02x\n",
690 dev_dbg(&ir
->rc
->dev
, "transmit complete\n");
692 /* Oh good, it worked */
695 mutex_unlock(&ir
->lock
);
700 static int zilog_tx_carrier(struct rc_dev
*dev
, u32 carrier
)
702 struct IR_i2c
*ir
= dev
->priv
;
704 if (carrier
> 500000 || carrier
< 20000)
707 ir
->carrier
= carrier
;
712 static int zilog_tx_duty_cycle(struct rc_dev
*dev
, u32 duty_cycle
)
714 struct IR_i2c
*ir
= dev
->priv
;
716 ir
->duty_cycle
= duty_cycle
;
721 static int ir_probe(struct i2c_client
*client
, const struct i2c_device_id
*id
)
723 char *ir_codes
= NULL
;
724 const char *name
= NULL
;
725 u64 rc_proto
= RC_PROTO_BIT_UNKNOWN
;
727 struct rc_dev
*rc
= NULL
;
728 struct i2c_adapter
*adap
= client
->adapter
;
729 unsigned short addr
= client
->addr
;
732 if ((id
->driver_data
& FLAG_HDPVR
) && !enable_hdpvr
) {
733 dev_err(&client
->dev
, "IR for HDPVR is known to cause problems during recording, use enable_hdpvr modparam to enable\n");
737 ir
= devm_kzalloc(&client
->dev
, sizeof(*ir
), GFP_KERNEL
);
742 ir
->polling_interval
= DEFAULT_POLLING_INTERVAL
;
743 i2c_set_clientdata(client
, ir
);
748 ir
->get_key
= get_key_pixelview
;
749 rc_proto
= RC_PROTO_BIT_OTHER
;
750 ir_codes
= RC_MAP_EMPTY
;
756 ir
->get_key
= get_key_haup
;
757 rc_proto
= RC_PROTO_BIT_RC5
;
758 ir_codes
= RC_MAP_HAUPPAUGE
;
762 ir
->get_key
= get_key_knc1
;
763 rc_proto
= RC_PROTO_BIT_OTHER
;
764 ir_codes
= RC_MAP_EMPTY
;
768 ir
->get_key
= get_key_fusionhdtv
;
769 rc_proto
= RC_PROTO_BIT_UNKNOWN
;
770 ir_codes
= RC_MAP_FUSIONHDTV_MCE
;
773 name
= "AVerMedia Cardbus remote";
774 ir
->get_key
= get_key_avermedia_cardbus
;
775 rc_proto
= RC_PROTO_BIT_OTHER
;
776 ir_codes
= RC_MAP_AVERMEDIA_CARDBUS
;
779 name
= "AVerMedia EM78P153";
780 ir
->get_key
= get_key_avermedia_cardbus
;
781 rc_proto
= RC_PROTO_BIT_OTHER
;
782 /* RM-KV remote, seems to be same as RM-K6 */
783 ir_codes
= RC_MAP_AVERMEDIA_M733A_RM_K6
;
786 name
= "Hauppauge/Zilog Z8";
787 ir
->get_key
= get_key_haup_xvr
;
788 rc_proto
= RC_PROTO_BIT_RC5
| RC_PROTO_BIT_RC6_MCE
|
789 RC_PROTO_BIT_RC6_6A_32
;
790 ir_codes
= RC_MAP_HAUPPAUGE
;
794 /* Let the caller override settings */
795 if (client
->dev
.platform_data
) {
796 const struct IR_i2c_init_data
*init_data
=
797 client
->dev
.platform_data
;
799 ir_codes
= init_data
->ir_codes
;
800 rc
= init_data
->rc_dev
;
802 name
= init_data
->name
;
804 rc_proto
= init_data
->type
;
806 if (init_data
->polling_interval
)
807 ir
->polling_interval
= init_data
->polling_interval
;
809 switch (init_data
->internal_get_key_func
) {
810 case IR_KBD_GET_KEY_CUSTOM
:
811 /* The bridge driver provided us its own function */
812 ir
->get_key
= init_data
->get_key
;
814 case IR_KBD_GET_KEY_PIXELVIEW
:
815 ir
->get_key
= get_key_pixelview
;
817 case IR_KBD_GET_KEY_HAUP
:
818 ir
->get_key
= get_key_haup
;
820 case IR_KBD_GET_KEY_KNC1
:
821 ir
->get_key
= get_key_knc1
;
823 case IR_KBD_GET_KEY_FUSIONHDTV
:
824 ir
->get_key
= get_key_fusionhdtv
;
826 case IR_KBD_GET_KEY_HAUP_XVR
:
827 ir
->get_key
= get_key_haup_xvr
;
829 case IR_KBD_GET_KEY_AVERMEDIA_CARDBUS
:
830 ir
->get_key
= get_key_avermedia_cardbus
;
837 * If platform_data doesn't specify rc_dev, initialize it
840 rc
= rc_allocate_device(RC_DRIVER_SCANCODE
);
846 /* Make sure we are all setup before going on */
847 if (!name
|| !ir
->get_key
|| !rc_proto
|| !ir_codes
) {
848 dev_warn(&client
->dev
, "Unsupported device at address 0x%02x\n",
854 ir
->ir_codes
= ir_codes
;
856 snprintf(ir
->phys
, sizeof(ir
->phys
), "%s/%s", dev_name(&adap
->dev
),
857 dev_name(&client
->dev
));
860 * Initialize input_dev fields
861 * It doesn't make sense to allow overriding them via platform_data
863 rc
->input_id
.bustype
= BUS_I2C
;
864 rc
->input_phys
= ir
->phys
;
865 rc
->device_name
= name
;
866 rc
->dev
.parent
= &client
->dev
;
869 rc
->close
= ir_close
;
872 * Initialize the other fields of rc_dev
874 rc
->map_name
= ir
->ir_codes
;
875 rc
->allowed_protocols
= rc_proto
;
876 if (!rc
->driver_name
)
877 rc
->driver_name
= KBUILD_MODNAME
;
879 mutex_init(&ir
->lock
);
881 INIT_DELAYED_WORK(&ir
->work
, ir_work
);
883 if (id
->driver_data
& FLAG_TX
) {
884 ir
->tx_c
= i2c_new_dummy(client
->adapter
, 0x70);
886 dev_err(&client
->dev
, "failed to setup tx i2c address");
887 } else if (!zilog_init(ir
)) {
890 rc
->tx_ir
= zilog_tx
;
891 rc
->s_tx_carrier
= zilog_tx_carrier
;
892 rc
->s_tx_duty_cycle
= zilog_tx_duty_cycle
;
896 err
= rc_register_device(rc
);
904 i2c_unregister_device(ir
->tx_c
);
906 /* Only frees rc if it were allocated internally */
911 static int ir_remove(struct i2c_client
*client
)
913 struct IR_i2c
*ir
= i2c_get_clientdata(client
);
915 /* kill outstanding polls */
916 cancel_delayed_work_sync(&ir
->work
);
919 i2c_unregister_device(ir
->tx_c
);
921 /* unregister device */
922 rc_unregister_device(ir
->rc
);
928 static const struct i2c_device_id ir_kbd_id
[] = {
929 /* Generic entry for any IR receiver */
931 /* IR device specific entries should be added here */
932 { "ir_z8f0811_haup", FLAG_TX
},
933 { "ir_z8f0811_hdpvr", FLAG_TX
| FLAG_HDPVR
},
936 MODULE_DEVICE_TABLE(i2c
, ir_kbd_id
);
938 static struct i2c_driver ir_kbd_driver
= {
940 .name
= "ir-kbd-i2c",
944 .id_table
= ir_kbd_id
,
947 module_i2c_driver(ir_kbd_driver
);
949 /* ----------------------------------------------------------------------- */
951 MODULE_AUTHOR("Gerd Knorr, Michal Kochanowicz, Christoph Bartelmus, Ulrich Mueller");
952 MODULE_DESCRIPTION("input driver for i2c IR remote controls");
953 MODULE_LICENSE("GPL");