1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * keyboard input driver for i2c IR remote controls
6 * Copyright (c) 2000-2003 Gerd Knorr <kraxel@bytesex.org>
7 * modified for PixelView (BT878P+W/FM) by
8 * Michal Kochanowicz <mkochano@pld.org.pl>
9 * Christoph Bartelmus <lirc@bartelmus.de>
10 * modified for KNC ONE TV Station/Anubis Typhoon TView Tuner by
11 * Ulrich Mueller <ulrich.mueller42@web.de>
12 * modified for em2820 based USB TV tuners by
13 * Markus Rechberger <mrechberger@gmail.com>
14 * modified for DViCO Fusion HDTV 5 RT GOLD by
15 * Chaogui Zhang <czhang1974@gmail.com>
16 * modified for MSI TV@nywhere Plus by
17 * Henry Wong <henry@stuffedcow.net>
18 * Mark Schultz <n9xmj@yahoo.com>
19 * Brian Rogers <brian_rogers@comcast.net>
20 * modified for AVerMedia Cardbus by
21 * Oldrich Jedlicka <oldium.pro@seznam.cz>
22 * Zilog Transmitter portions/ideas were derived from GPLv2+ sources:
23 * - drivers/char/pctv_zilogir.[ch] from Hauppauge Broadway product
24 * Copyright 2011 Hauppauge Computer works
25 * - drivers/staging/media/lirc/lirc_zilog.c
26 * Copyright (c) 2000 Gerd Knorr <kraxel@goldbach.in-berlin.de>
27 * Michal Kochanowicz <mkochano@pld.org.pl>
28 * Christoph Bartelmus <lirc@bartelmus.de>
29 * Ulrich Mueller <ulrich.mueller42@web.de>
30 * Stefan Jahn <stefan@lkcc.org>
31 * Jerome Brock <jbrock@users.sourceforge.net>
32 * Thomas Reitmayr (treitmayr@yahoo.com)
33 * Mark Weaver <mark@npsl.co.uk>
34 * Jarod Wilson <jarod@redhat.com>
35 * Copyright (C) 2011 Andy Walls <awalls@md.metrocast.net>
38 #include <asm/unaligned.h>
39 #include <linux/module.h>
40 #include <linux/init.h>
41 #include <linux/kernel.h>
42 #include <linux/string.h>
43 #include <linux/timer.h>
44 #include <linux/delay.h>
45 #include <linux/errno.h>
46 #include <linux/slab.h>
47 #include <linux/i2c.h>
48 #include <linux/workqueue.h>
50 #include <media/rc-core.h>
51 #include <media/i2c/ir-kbd-i2c.h>
56 static bool enable_hdpvr
;
57 module_param(enable_hdpvr
, bool, 0644);
59 static int get_key_haup_common(struct IR_i2c
*ir
, enum rc_proto
*protocol
,
60 u32
*scancode
, u8
*ptoggle
, int size
)
63 int start
, range
, toggle
, dev
, code
, ircode
, vendor
;
66 if (size
!= i2c_master_recv(ir
->c
, buf
, size
))
70 int offset
= (size
== 6) ? 3 : 0;
72 /* split rc5 data block ... */
73 start
= (buf
[offset
] >> 7) & 1;
74 range
= (buf
[offset
] >> 6) & 1;
75 toggle
= (buf
[offset
] >> 5) & 1;
76 dev
= buf
[offset
] & 0x1f;
77 code
= (buf
[offset
+1] >> 2) & 0x3f;
79 /* rc5 has two start bits
80 * the first bit must be one
81 * the second bit defines the command range:
82 * 1 = 0-63, 0 = 64 - 127
88 /* filter out invalid key presses */
89 ircode
= (start
<< 12) | (toggle
<< 11) | (dev
<< 6) | code
;
90 if ((ircode
& 0x1fff) == 0x1fff)
97 "ir hauppauge (rc5): s%d r%d t%d dev=%d code=%d\n",
98 start
, range
, toggle
, dev
, code
);
100 *protocol
= RC_PROTO_RC5
;
101 *scancode
= RC_SCANCODE_RC5(dev
, code
);
105 } else if (size
== 6 && (buf
[0] & 0x40)) {
108 vendor
= get_unaligned_be16(buf
+ 1);
110 if (vendor
== 0x800f) {
111 *ptoggle
= (dev
& 0x80) != 0;
112 *protocol
= RC_PROTO_RC6_MCE
;
114 dev_dbg(&ir
->rc
->dev
,
115 "ir hauppauge (rc6-mce): t%d vendor=%d dev=%d code=%d\n",
116 *ptoggle
, vendor
, dev
, code
);
119 *protocol
= RC_PROTO_RC6_6A_32
;
120 dev_dbg(&ir
->rc
->dev
,
121 "ir hauppauge (rc6-6a-32): vendor=%d dev=%d code=%d\n",
125 *scancode
= RC_SCANCODE_RC6_6A(vendor
, dev
, code
);
133 static int get_key_haup(struct IR_i2c
*ir
, enum rc_proto
*protocol
,
134 u32
*scancode
, u8
*toggle
)
136 return get_key_haup_common(ir
, protocol
, scancode
, toggle
, 3);
139 static int get_key_haup_xvr(struct IR_i2c
*ir
, enum rc_proto
*protocol
,
140 u32
*scancode
, u8
*toggle
)
143 unsigned char buf
[1] = { 0 };
146 * This is the same apparent "are you ready?" poll command observed
147 * watching Windows driver traffic and implemented in lirc_zilog. With
148 * this added, we get far saner remote behavior with z8 chips on usb
149 * connected devices, even with the default polling interval of 100ms.
151 ret
= i2c_master_send(ir
->c
, buf
, 1);
153 return (ret
< 0) ? ret
: -EINVAL
;
155 return get_key_haup_common(ir
, protocol
, scancode
, toggle
, 6);
158 static int get_key_pixelview(struct IR_i2c
*ir
, enum rc_proto
*protocol
,
159 u32
*scancode
, u8
*toggle
)
165 rc
= i2c_master_recv(ir
->c
, &b
, 1);
167 dev_dbg(&ir
->rc
->dev
, "read error\n");
173 *protocol
= RC_PROTO_OTHER
;
179 static int get_key_fusionhdtv(struct IR_i2c
*ir
, enum rc_proto
*protocol
,
180 u32
*scancode
, u8
*toggle
)
183 unsigned char buf
[4];
186 rc
= i2c_master_recv(ir
->c
, buf
, 4);
188 dev_dbg(&ir
->rc
->dev
, "read error\n");
194 if (buf
[0] != 0 || buf
[1] != 0 || buf
[2] != 0 || buf
[3] != 0)
195 dev_dbg(&ir
->rc
->dev
, "%s: %*ph\n", __func__
, 4, buf
);
197 /* no key pressed or signal from other ir remote */
198 if(buf
[0] != 0x1 || buf
[1] != 0xfe)
201 *protocol
= RC_PROTO_UNKNOWN
;
207 static int get_key_knc1(struct IR_i2c
*ir
, enum rc_proto
*protocol
,
208 u32
*scancode
, u8
*toggle
)
214 rc
= i2c_master_recv(ir
->c
, &b
, 1);
216 dev_dbg(&ir
->rc
->dev
, "read error\n");
222 /* it seems that 0xFE indicates that a button is still hold
223 down, while 0xff indicates that no button is hold
224 down. 0xfe sequences are sometimes interrupted by 0xFF */
226 dev_dbg(&ir
->rc
->dev
, "key %02x\n", b
);
235 *protocol
= RC_PROTO_UNKNOWN
;
241 static int get_key_avermedia_cardbus(struct IR_i2c
*ir
, enum rc_proto
*protocol
,
242 u32
*scancode
, u8
*toggle
)
244 unsigned char subaddr
, key
, keygroup
;
245 struct i2c_msg msg
[] = { { .addr
= ir
->c
->addr
, .flags
= 0,
246 .buf
= &subaddr
, .len
= 1},
247 { .addr
= ir
->c
->addr
, .flags
= I2C_M_RD
,
248 .buf
= &key
, .len
= 1} };
250 if (2 != i2c_transfer(ir
->c
->adapter
, msg
, 2)) {
251 dev_dbg(&ir
->rc
->dev
, "read error\n");
259 msg
[1].buf
= &keygroup
;
260 if (2 != i2c_transfer(ir
->c
->adapter
, msg
, 2)) {
261 dev_dbg(&ir
->rc
->dev
, "read error\n");
265 if (keygroup
== 0xff)
268 dev_dbg(&ir
->rc
->dev
, "read key 0x%02x/0x%02x\n", key
, keygroup
);
269 if (keygroup
< 2 || keygroup
> 4) {
270 dev_warn(&ir
->rc
->dev
, "warning: invalid key group 0x%02x for key 0x%02x\n",
273 key
|= (keygroup
& 1) << 6;
275 *protocol
= RC_PROTO_UNKNOWN
;
277 if (ir
->c
->addr
== 0x41) /* AVerMedia EM78P153 */
278 *scancode
|= keygroup
<< 8;
283 /* ----------------------------------------------------------------------- */
285 static int ir_key_poll(struct IR_i2c
*ir
)
287 enum rc_proto protocol
;
292 dev_dbg(&ir
->rc
->dev
, "%s\n", __func__
);
293 rc
= ir
->get_key(ir
, &protocol
, &scancode
, &toggle
);
295 dev_warn(&ir
->rc
->dev
, "error %d\n", rc
);
300 dev_dbg(&ir
->rc
->dev
, "%s: proto = 0x%04x, scancode = 0x%08x\n",
301 __func__
, protocol
, scancode
);
302 rc_keydown(ir
->rc
, protocol
, scancode
, toggle
);
307 static void ir_work(struct work_struct
*work
)
310 struct IR_i2c
*ir
= container_of(work
, struct IR_i2c
, work
.work
);
313 * If the transmit code is holding the lock, skip polling for
314 * IR, we'll get it to it next time round
316 if (mutex_trylock(&ir
->lock
)) {
317 rc
= ir_key_poll(ir
);
318 mutex_unlock(&ir
->lock
);
320 rc_unregister_device(ir
->rc
);
326 schedule_delayed_work(&ir
->work
, msecs_to_jiffies(ir
->polling_interval
));
329 static int ir_open(struct rc_dev
*dev
)
331 struct IR_i2c
*ir
= dev
->priv
;
333 schedule_delayed_work(&ir
->work
, 0);
338 static void ir_close(struct rc_dev
*dev
)
340 struct IR_i2c
*ir
= dev
->priv
;
342 cancel_delayed_work_sync(&ir
->work
);
345 /* Zilog Transmit Interface */
346 #define XTAL_FREQ 18432000
348 #define ZILOG_SEND 0x80
349 #define ZILOG_UIR_END 0x40
350 #define ZILOG_INIT_END 0x20
351 #define ZILOG_LIR_END 0x10
353 #define ZILOG_STATUS_OK 0x80
354 #define ZILOG_STATUS_TX 0x40
355 #define ZILOG_STATUS_SET 0x20
358 * As you can see here, very few different lengths of pulse and space
359 * can be encoded. This means that the hardware does not work well with
360 * recorded IR. It's best to work with generated IR, like from ir-ctl or
361 * the in-kernel encoders.
365 u16 pulse
[7]; /* not aligned */
368 u16 space
[8]; /* not aligned */
373 static int send_data_block(struct IR_i2c
*ir
, int cmd
,
374 struct code_block
*code_block
)
379 p
= &code_block
->length
;
380 for (i
= 0; p
< code_block
->csum
; i
++)
381 code_block
->csum
[i
& 1] ^= *p
++;
383 p
= &code_block
->length
;
385 for (i
= 0; i
< sizeof(*code_block
);) {
386 int tosend
= sizeof(*code_block
) - i
;
391 for (j
= 0; j
< tosend
; ++j
)
392 buf
[1 + j
] = p
[i
+ j
];
393 dev_dbg(&ir
->rc
->dev
, "%*ph", tosend
+ 1, buf
);
394 ret
= i2c_master_send(ir
->tx_c
, buf
, tosend
+ 1);
395 if (ret
!= tosend
+ 1) {
396 dev_dbg(&ir
->rc
->dev
,
397 "i2c_master_send failed with %d\n", ret
);
398 return ret
< 0 ? ret
: -EIO
;
405 ret
= i2c_master_send(ir
->tx_c
, buf
, 2);
407 dev_err(&ir
->rc
->dev
, "i2c_master_send failed with %d\n", ret
);
408 return ret
< 0 ? ret
: -EIO
;
411 usleep_range(2000, 5000);
413 ret
= i2c_master_send(ir
->tx_c
, buf
, 1);
415 dev_err(&ir
->rc
->dev
, "i2c_master_send failed with %d\n", ret
);
416 return ret
< 0 ? ret
: -EIO
;
422 static int zilog_init(struct IR_i2c
*ir
)
424 struct code_block code_block
= { .length
= sizeof(code_block
) };
428 put_unaligned_be16(0x1000, &code_block
.pulse
[3]);
430 ret
= send_data_block(ir
, ZILOG_INIT_END
, &code_block
);
434 ret
= i2c_master_recv(ir
->tx_c
, buf
, 4);
436 dev_err(&ir
->c
->dev
, "failed to retrieve firmware version: %d\n",
438 return ret
< 0 ? ret
: -EIO
;
441 dev_info(&ir
->c
->dev
, "Zilog/Hauppauge IR blaster firmware version %d.%d.%d\n",
442 buf
[1], buf
[2], buf
[3]);
448 * If the last slot for pulse is the same as the current slot for pulse,
449 * then use slot no 7.
451 static void copy_codes(u8
*dst
, u8
*src
, unsigned int count
)
457 if ((c
& 0xf0) == last
) {
458 *dst
++ = 0x70 | (c
& 0xf);
467 * When looking for repeats, we don't care about the trailing space. This
468 * is set to the shortest possible anyway.
470 static int cmp_no_trail(u8
*a
, u8
*b
, unsigned int count
)
477 return (*a
& 0xf0) - (*b
& 0xf0);
480 static int find_slot(u16
*array
, unsigned int size
, u16 val
)
484 for (i
= 0; i
< size
; i
++) {
485 if (get_unaligned_be16(&array
[i
]) == val
) {
487 } else if (!array
[i
]) {
488 put_unaligned_be16(val
, &array
[i
]);
496 static int zilog_ir_format(struct rc_dev
*rcdev
, unsigned int *txbuf
,
497 unsigned int count
, struct code_block
*code_block
)
499 struct IR_i2c
*ir
= rcdev
->priv
;
500 int rep
, i
, l
, p
= 0, s
, c
= 0;
504 code_block
->carrier_pulse
= DIV_ROUND_CLOSEST(
505 ir
->duty_cycle
* XTAL_FREQ
/ 1000, ir
->carrier
);
506 code_block
->carrier_space
= DIV_ROUND_CLOSEST(
507 (100 - ir
->duty_cycle
) * XTAL_FREQ
/ 1000, ir
->carrier
);
509 for (i
= 0; i
< count
; i
++) {
510 if (c
>= ARRAY_SIZE(codes
) - 1) {
511 dev_warn(&rcdev
->dev
, "IR too long, cannot transmit\n");
516 * Lengths more than 142220us cannot be encoded; also
517 * this checks for multiply overflow
519 if (txbuf
[i
] > 142220)
522 l
= DIV_ROUND_CLOSEST((XTAL_FREQ
/ 1000) * txbuf
[i
], 40000);
525 s
= find_slot(code_block
->space
,
526 ARRAY_SIZE(code_block
->space
), l
);
528 dev_warn(&rcdev
->dev
, "Too many different lengths spaces, cannot transmit");
532 /* We have a pulse and space */
533 codes
[c
++] = (p
<< 4) | s
;
535 p
= find_slot(code_block
->pulse
,
536 ARRAY_SIZE(code_block
->pulse
), l
);
538 dev_warn(&rcdev
->dev
, "Too many different lengths pulses, cannot transmit");
544 /* We have to encode the trailing pulse. Find the shortest space */
546 for (i
= 1; i
< ARRAY_SIZE(code_block
->space
); i
++) {
547 u16 d
= get_unaligned_be16(&code_block
->space
[i
]);
549 if (get_unaligned_be16(&code_block
->space
[s
]) > d
)
553 codes
[c
++] = (p
<< 4) | s
;
555 dev_dbg(&rcdev
->dev
, "generated %d codes\n", c
);
558 * Are the last N codes (so pulse + space) repeating 3 times?
559 * if so we can shorten the codes list and use code 0xc0 to repeat
564 for (rep
= c
/ 3; rep
>= 1; rep
--) {
565 if (!memcmp(&codes
[c
- rep
* 3], &codes
[c
- rep
* 2], rep
) &&
566 !cmp_no_trail(&codes
[c
- rep
], &codes
[c
- rep
* 2], rep
)) {
573 /* first copy any leading non-repeating */
574 int leading
= c
- rep
* 3;
576 if (leading
>= ARRAY_SIZE(code_block
->codes
) - 3 - rep
) {
577 dev_warn(&rcdev
->dev
, "IR too long, cannot transmit\n");
581 dev_dbg(&rcdev
->dev
, "found trailing %d repeat\n", rep
);
582 copy_codes(code_block
->codes
, codes
, leading
);
583 code_block
->codes
[leading
] = 0x82;
584 copy_codes(code_block
->codes
+ leading
+ 1, codes
+ leading
,
586 c
= leading
+ 1 + rep
;
587 code_block
->codes
[c
++] = 0xc0;
589 if (c
>= ARRAY_SIZE(code_block
->codes
) - 3) {
590 dev_warn(&rcdev
->dev
, "IR too long, cannot transmit\n");
594 dev_dbg(&rcdev
->dev
, "found no trailing repeat\n");
595 code_block
->codes
[0] = 0x82;
596 copy_codes(code_block
->codes
+ 1, codes
, c
);
598 code_block
->codes
[c
++] = 0xc4;
601 while (c
< ARRAY_SIZE(code_block
->codes
))
602 code_block
->codes
[c
++] = 0x83;
607 static int zilog_tx(struct rc_dev
*rcdev
, unsigned int *txbuf
,
610 struct IR_i2c
*ir
= rcdev
->priv
;
611 struct code_block code_block
= { .length
= sizeof(code_block
) };
615 ret
= zilog_ir_format(rcdev
, txbuf
, count
, &code_block
);
619 ret
= mutex_lock_interruptible(&ir
->lock
);
623 ret
= send_data_block(ir
, ZILOG_UIR_END
, &code_block
);
627 ret
= i2c_master_recv(ir
->tx_c
, buf
, 1);
629 dev_err(&ir
->rc
->dev
, "i2c_master_recv failed with %d\n", ret
);
633 dev_dbg(&ir
->rc
->dev
, "code set status: %02x\n", buf
[0]);
635 if (buf
[0] != (ZILOG_STATUS_OK
| ZILOG_STATUS_SET
)) {
636 dev_err(&ir
->rc
->dev
, "unexpected IR TX response %02x\n",
645 ret
= i2c_master_send(ir
->tx_c
, buf
, 2);
647 dev_err(&ir
->rc
->dev
, "i2c_master_send failed with %d\n", ret
);
653 dev_dbg(&ir
->rc
->dev
, "send command sent\n");
656 * This bit NAKs until the device is ready, so we retry it
657 * sleeping a bit each time. This seems to be what the windows
658 * driver does, approximately.
661 for (i
= 0; i
< 20; ++i
) {
662 set_current_state(TASK_UNINTERRUPTIBLE
);
663 schedule_timeout(msecs_to_jiffies(50));
664 ret
= i2c_master_send(ir
->tx_c
, buf
, 1);
667 dev_dbg(&ir
->rc
->dev
,
668 "NAK expected: i2c_master_send failed with %d (try %d)\n",
673 dev_err(&ir
->rc
->dev
,
674 "IR TX chip never got ready: last i2c_master_send failed with %d\n",
681 i
= i2c_master_recv(ir
->tx_c
, buf
, 1);
683 dev_err(&ir
->rc
->dev
, "i2c_master_recv failed with %d\n", ret
);
686 } else if (buf
[0] != ZILOG_STATUS_OK
) {
687 dev_err(&ir
->rc
->dev
, "unexpected IR TX response #2: %02x\n",
692 dev_dbg(&ir
->rc
->dev
, "transmit complete\n");
694 /* Oh good, it worked */
697 mutex_unlock(&ir
->lock
);
702 static int zilog_tx_carrier(struct rc_dev
*dev
, u32 carrier
)
704 struct IR_i2c
*ir
= dev
->priv
;
706 if (carrier
> 500000 || carrier
< 20000)
709 ir
->carrier
= carrier
;
714 static int zilog_tx_duty_cycle(struct rc_dev
*dev
, u32 duty_cycle
)
716 struct IR_i2c
*ir
= dev
->priv
;
718 ir
->duty_cycle
= duty_cycle
;
723 static int ir_probe(struct i2c_client
*client
, const struct i2c_device_id
*id
)
725 char *ir_codes
= NULL
;
726 const char *name
= NULL
;
727 u64 rc_proto
= RC_PROTO_BIT_UNKNOWN
;
729 struct rc_dev
*rc
= NULL
;
730 struct i2c_adapter
*adap
= client
->adapter
;
731 unsigned short addr
= client
->addr
;
732 bool probe_tx
= (id
->driver_data
& FLAG_TX
) != 0;
735 if ((id
->driver_data
& FLAG_HDPVR
) && !enable_hdpvr
) {
736 dev_err(&client
->dev
, "IR for HDPVR is known to cause problems during recording, use enable_hdpvr modparam to enable\n");
740 ir
= devm_kzalloc(&client
->dev
, sizeof(*ir
), GFP_KERNEL
);
745 ir
->polling_interval
= DEFAULT_POLLING_INTERVAL
;
746 i2c_set_clientdata(client
, ir
);
751 ir
->get_key
= get_key_pixelview
;
752 rc_proto
= RC_PROTO_BIT_OTHER
;
753 ir_codes
= RC_MAP_EMPTY
;
759 ir
->get_key
= get_key_haup
;
760 rc_proto
= RC_PROTO_BIT_RC5
;
761 ir_codes
= RC_MAP_HAUPPAUGE
;
765 ir
->get_key
= get_key_knc1
;
766 rc_proto
= RC_PROTO_BIT_OTHER
;
767 ir_codes
= RC_MAP_EMPTY
;
771 ir
->get_key
= get_key_fusionhdtv
;
772 rc_proto
= RC_PROTO_BIT_UNKNOWN
;
773 ir_codes
= RC_MAP_FUSIONHDTV_MCE
;
776 name
= "AVerMedia Cardbus remote";
777 ir
->get_key
= get_key_avermedia_cardbus
;
778 rc_proto
= RC_PROTO_BIT_OTHER
;
779 ir_codes
= RC_MAP_AVERMEDIA_CARDBUS
;
782 name
= "AVerMedia EM78P153";
783 ir
->get_key
= get_key_avermedia_cardbus
;
784 rc_proto
= RC_PROTO_BIT_OTHER
;
785 /* RM-KV remote, seems to be same as RM-K6 */
786 ir_codes
= RC_MAP_AVERMEDIA_M733A_RM_K6
;
789 name
= "Hauppauge/Zilog Z8";
790 ir
->get_key
= get_key_haup_xvr
;
791 rc_proto
= RC_PROTO_BIT_RC5
| RC_PROTO_BIT_RC6_MCE
|
792 RC_PROTO_BIT_RC6_6A_32
;
793 ir_codes
= RC_MAP_HAUPPAUGE
;
798 /* Let the caller override settings */
799 if (client
->dev
.platform_data
) {
800 const struct IR_i2c_init_data
*init_data
=
801 client
->dev
.platform_data
;
803 ir_codes
= init_data
->ir_codes
;
804 rc
= init_data
->rc_dev
;
806 name
= init_data
->name
;
808 rc_proto
= init_data
->type
;
810 if (init_data
->polling_interval
)
811 ir
->polling_interval
= init_data
->polling_interval
;
813 switch (init_data
->internal_get_key_func
) {
814 case IR_KBD_GET_KEY_CUSTOM
:
815 /* The bridge driver provided us its own function */
816 ir
->get_key
= init_data
->get_key
;
818 case IR_KBD_GET_KEY_PIXELVIEW
:
819 ir
->get_key
= get_key_pixelview
;
821 case IR_KBD_GET_KEY_HAUP
:
822 ir
->get_key
= get_key_haup
;
824 case IR_KBD_GET_KEY_KNC1
:
825 ir
->get_key
= get_key_knc1
;
827 case IR_KBD_GET_KEY_FUSIONHDTV
:
828 ir
->get_key
= get_key_fusionhdtv
;
830 case IR_KBD_GET_KEY_HAUP_XVR
:
831 ir
->get_key
= get_key_haup_xvr
;
833 case IR_KBD_GET_KEY_AVERMEDIA_CARDBUS
:
834 ir
->get_key
= get_key_avermedia_cardbus
;
841 * If platform_data doesn't specify rc_dev, initialize it
844 rc
= rc_allocate_device(RC_DRIVER_SCANCODE
);
850 /* Make sure we are all setup before going on */
851 if (!name
|| !ir
->get_key
|| !rc_proto
|| !ir_codes
) {
852 dev_warn(&client
->dev
, "Unsupported device at address 0x%02x\n",
858 ir
->ir_codes
= ir_codes
;
860 snprintf(ir
->phys
, sizeof(ir
->phys
), "%s/%s", dev_name(&adap
->dev
),
861 dev_name(&client
->dev
));
864 * Initialize input_dev fields
865 * It doesn't make sense to allow overriding them via platform_data
867 rc
->input_id
.bustype
= BUS_I2C
;
868 rc
->input_phys
= ir
->phys
;
869 rc
->device_name
= name
;
870 rc
->dev
.parent
= &client
->dev
;
873 rc
->close
= ir_close
;
876 * Initialize the other fields of rc_dev
878 rc
->map_name
= ir
->ir_codes
;
879 rc
->allowed_protocols
= rc_proto
;
880 if (!rc
->driver_name
)
881 rc
->driver_name
= KBUILD_MODNAME
;
883 mutex_init(&ir
->lock
);
885 INIT_DELAYED_WORK(&ir
->work
, ir_work
);
888 ir
->tx_c
= i2c_new_dummy_device(client
->adapter
, 0x70);
889 if (IS_ERR(ir
->tx_c
)) {
890 dev_err(&client
->dev
, "failed to setup tx i2c address");
891 err
= PTR_ERR(ir
->tx_c
);
893 } else if (!zilog_init(ir
)) {
896 rc
->tx_ir
= zilog_tx
;
897 rc
->s_tx_carrier
= zilog_tx_carrier
;
898 rc
->s_tx_duty_cycle
= zilog_tx_duty_cycle
;
902 err
= rc_register_device(rc
);
909 if (!IS_ERR(ir
->tx_c
))
910 i2c_unregister_device(ir
->tx_c
);
912 /* Only frees rc if it were allocated internally */
917 static int ir_remove(struct i2c_client
*client
)
919 struct IR_i2c
*ir
= i2c_get_clientdata(client
);
921 cancel_delayed_work_sync(&ir
->work
);
923 i2c_unregister_device(ir
->tx_c
);
925 rc_unregister_device(ir
->rc
);
930 static const struct i2c_device_id ir_kbd_id
[] = {
931 /* Generic entry for any IR receiver */
933 /* IR device specific entries should be added here */
934 { "ir_z8f0811_haup", FLAG_TX
},
935 { "ir_z8f0811_hdpvr", FLAG_TX
| FLAG_HDPVR
},
938 MODULE_DEVICE_TABLE(i2c
, ir_kbd_id
);
940 static struct i2c_driver ir_kbd_driver
= {
942 .name
= "ir-kbd-i2c",
946 .id_table
= ir_kbd_id
,
949 module_i2c_driver(ir_kbd_driver
);
951 /* ----------------------------------------------------------------------- */
953 MODULE_AUTHOR("Gerd Knorr, Michal Kochanowicz, Christoph Bartelmus, Ulrich Mueller");
954 MODULE_DESCRIPTION("input driver for i2c IR remote controls");
955 MODULE_LICENSE("GPL");