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
)
175 rc
= i2c_master_recv(ir
->c
, &b
, 1);
177 dev_dbg(&ir
->rc
->dev
, "read error\n");
183 *protocol
= RC_PROTO_OTHER
;
189 static int get_key_fusionhdtv(struct IR_i2c
*ir
, enum rc_proto
*protocol
,
190 u32
*scancode
, u8
*toggle
)
193 unsigned char buf
[4];
196 rc
= i2c_master_recv(ir
->c
, buf
, 4);
198 dev_dbg(&ir
->rc
->dev
, "read error\n");
204 if (buf
[0] != 0 || buf
[1] != 0 || buf
[2] != 0 || buf
[3] != 0)
205 dev_dbg(&ir
->rc
->dev
, "%s: %*ph\n", __func__
, 4, buf
);
207 /* no key pressed or signal from other ir remote */
208 if(buf
[0] != 0x1 || buf
[1] != 0xfe)
211 *protocol
= RC_PROTO_UNKNOWN
;
217 static int get_key_knc1(struct IR_i2c
*ir
, enum rc_proto
*protocol
,
218 u32
*scancode
, u8
*toggle
)
224 rc
= i2c_master_recv(ir
->c
, &b
, 1);
226 dev_dbg(&ir
->rc
->dev
, "read error\n");
232 /* it seems that 0xFE indicates that a button is still hold
233 down, while 0xff indicates that no button is hold
234 down. 0xfe sequences are sometimes interrupted by 0xFF */
236 dev_dbg(&ir
->rc
->dev
, "key %02x\n", b
);
245 *protocol
= RC_PROTO_UNKNOWN
;
251 static int get_key_avermedia_cardbus(struct IR_i2c
*ir
, enum rc_proto
*protocol
,
252 u32
*scancode
, u8
*toggle
)
254 unsigned char subaddr
, key
, keygroup
;
255 struct i2c_msg msg
[] = { { .addr
= ir
->c
->addr
, .flags
= 0,
256 .buf
= &subaddr
, .len
= 1},
257 { .addr
= ir
->c
->addr
, .flags
= I2C_M_RD
,
258 .buf
= &key
, .len
= 1} };
260 if (2 != i2c_transfer(ir
->c
->adapter
, msg
, 2)) {
261 dev_dbg(&ir
->rc
->dev
, "read error\n");
269 msg
[1].buf
= &keygroup
;
270 if (2 != i2c_transfer(ir
->c
->adapter
, msg
, 2)) {
271 dev_dbg(&ir
->rc
->dev
, "read error\n");
275 if (keygroup
== 0xff)
278 dev_dbg(&ir
->rc
->dev
, "read key 0x%02x/0x%02x\n", key
, keygroup
);
279 if (keygroup
< 2 || keygroup
> 4) {
280 dev_warn(&ir
->rc
->dev
, "warning: invalid key group 0x%02x for key 0x%02x\n",
283 key
|= (keygroup
& 1) << 6;
285 *protocol
= RC_PROTO_UNKNOWN
;
287 if (ir
->c
->addr
== 0x41) /* AVerMedia EM78P153 */
288 *scancode
|= keygroup
<< 8;
293 /* ----------------------------------------------------------------------- */
295 static int ir_key_poll(struct IR_i2c
*ir
)
297 enum rc_proto protocol
;
302 dev_dbg(&ir
->rc
->dev
, "%s\n", __func__
);
303 rc
= ir
->get_key(ir
, &protocol
, &scancode
, &toggle
);
305 dev_warn(&ir
->rc
->dev
, "error %d\n", rc
);
310 dev_dbg(&ir
->rc
->dev
, "%s: proto = 0x%04x, scancode = 0x%08x\n",
311 __func__
, protocol
, scancode
);
312 rc_keydown(ir
->rc
, protocol
, scancode
, toggle
);
317 static void ir_work(struct work_struct
*work
)
320 struct IR_i2c
*ir
= container_of(work
, struct IR_i2c
, work
.work
);
323 * If the transmit code is holding the lock, skip polling for
324 * IR, we'll get it to it next time round
326 if (mutex_trylock(&ir
->lock
)) {
327 rc
= ir_key_poll(ir
);
328 mutex_unlock(&ir
->lock
);
330 rc_unregister_device(ir
->rc
);
336 schedule_delayed_work(&ir
->work
, msecs_to_jiffies(ir
->polling_interval
));
339 static int ir_open(struct rc_dev
*dev
)
341 struct IR_i2c
*ir
= dev
->priv
;
343 schedule_delayed_work(&ir
->work
, 0);
348 static void ir_close(struct rc_dev
*dev
)
350 struct IR_i2c
*ir
= dev
->priv
;
352 cancel_delayed_work_sync(&ir
->work
);
355 /* Zilog Transmit Interface */
356 #define XTAL_FREQ 18432000
358 #define ZILOG_SEND 0x80
359 #define ZILOG_UIR_END 0x40
360 #define ZILOG_INIT_END 0x20
361 #define ZILOG_LIR_END 0x10
363 #define ZILOG_STATUS_OK 0x80
364 #define ZILOG_STATUS_TX 0x40
365 #define ZILOG_STATUS_SET 0x20
368 * As you can see here, very few different lengths of pulse and space
369 * can be encoded. This means that the hardware does not work well with
370 * recorded IR. It's best to work with generated IR, like from ir-ctl or
371 * the in-kernel encoders.
375 u16 pulse
[7]; /* not aligned */
378 u16 space
[8]; /* not aligned */
383 static int send_data_block(struct IR_i2c
*ir
, int cmd
,
384 struct code_block
*code_block
)
389 p
= &code_block
->length
;
390 for (i
= 0; p
< code_block
->csum
; i
++)
391 code_block
->csum
[i
& 1] ^= *p
++;
393 p
= &code_block
->length
;
395 for (i
= 0; i
< sizeof(*code_block
);) {
396 int tosend
= sizeof(*code_block
) - i
;
401 for (j
= 0; j
< tosend
; ++j
)
402 buf
[1 + j
] = p
[i
+ j
];
403 dev_dbg(&ir
->rc
->dev
, "%*ph", tosend
+ 1, buf
);
404 ret
= i2c_master_send(ir
->tx_c
, buf
, tosend
+ 1);
405 if (ret
!= tosend
+ 1) {
406 dev_dbg(&ir
->rc
->dev
,
407 "i2c_master_send failed with %d\n", ret
);
408 return ret
< 0 ? ret
: -EIO
;
415 ret
= i2c_master_send(ir
->tx_c
, buf
, 2);
417 dev_err(&ir
->rc
->dev
, "i2c_master_send failed with %d\n", ret
);
418 return ret
< 0 ? ret
: -EIO
;
421 usleep_range(2000, 5000);
423 ret
= i2c_master_send(ir
->tx_c
, buf
, 1);
425 dev_err(&ir
->rc
->dev
, "i2c_master_send failed with %d\n", ret
);
426 return ret
< 0 ? ret
: -EIO
;
432 static int zilog_init(struct IR_i2c
*ir
)
434 struct code_block code_block
= { .length
= sizeof(code_block
) };
438 put_unaligned_be16(0x1000, &code_block
.pulse
[3]);
440 ret
= send_data_block(ir
, ZILOG_INIT_END
, &code_block
);
444 ret
= i2c_master_recv(ir
->tx_c
, buf
, 4);
446 dev_err(&ir
->c
->dev
, "failed to retrieve firmware version: %d\n",
448 return ret
< 0 ? ret
: -EIO
;
451 dev_info(&ir
->c
->dev
, "Zilog/Hauppauge IR blaster firmware version %d.%d.%d\n",
452 buf
[1], buf
[2], buf
[3]);
458 * If the last slot for pulse is the same as the current slot for pulse,
459 * then use slot no 7.
461 static void copy_codes(u8
*dst
, u8
*src
, unsigned int count
)
467 if ((c
& 0xf0) == last
) {
468 *dst
++ = 0x70 | (c
& 0xf);
477 * When looking for repeats, we don't care about the trailing space. This
478 * is set to the shortest possible anyway.
480 static int cmp_no_trail(u8
*a
, u8
*b
, unsigned int count
)
487 return (*a
& 0xf0) - (*b
& 0xf0);
490 static int find_slot(u16
*array
, unsigned int size
, u16 val
)
494 for (i
= 0; i
< size
; i
++) {
495 if (get_unaligned_be16(&array
[i
]) == val
) {
497 } else if (!array
[i
]) {
498 put_unaligned_be16(val
, &array
[i
]);
506 static int zilog_ir_format(struct rc_dev
*rcdev
, unsigned int *txbuf
,
507 unsigned int count
, struct code_block
*code_block
)
509 struct IR_i2c
*ir
= rcdev
->priv
;
510 int rep
, i
, l
, p
= 0, s
, c
= 0;
514 code_block
->carrier_pulse
= DIV_ROUND_CLOSEST(
515 ir
->duty_cycle
* XTAL_FREQ
/ 1000, ir
->carrier
);
516 code_block
->carrier_space
= DIV_ROUND_CLOSEST(
517 (100 - ir
->duty_cycle
) * XTAL_FREQ
/ 1000, ir
->carrier
);
519 for (i
= 0; i
< count
; i
++) {
520 if (c
>= ARRAY_SIZE(codes
) - 1) {
521 dev_warn(&rcdev
->dev
, "IR too long, cannot transmit\n");
526 * Lengths more than 142220us cannot be encoded; also
527 * this checks for multiply overflow
529 if (txbuf
[i
] > 142220)
532 l
= DIV_ROUND_CLOSEST((XTAL_FREQ
/ 1000) * txbuf
[i
], 40000);
535 s
= find_slot(code_block
->space
,
536 ARRAY_SIZE(code_block
->space
), l
);
538 dev_warn(&rcdev
->dev
, "Too many different lengths spaces, cannot transmit");
542 /* We have a pulse and space */
543 codes
[c
++] = (p
<< 4) | s
;
545 p
= find_slot(code_block
->pulse
,
546 ARRAY_SIZE(code_block
->pulse
), l
);
548 dev_warn(&rcdev
->dev
, "Too many different lengths pulses, cannot transmit");
554 /* We have to encode the trailing pulse. Find the shortest space */
556 for (i
= 1; i
< ARRAY_SIZE(code_block
->space
); i
++) {
557 u16 d
= get_unaligned_be16(&code_block
->space
[i
]);
559 if (get_unaligned_be16(&code_block
->space
[s
]) > d
)
563 codes
[c
++] = (p
<< 4) | s
;
565 dev_dbg(&rcdev
->dev
, "generated %d codes\n", c
);
568 * Are the last N codes (so pulse + space) repeating 3 times?
569 * if so we can shorten the codes list and use code 0xc0 to repeat
574 for (rep
= c
/ 3; rep
>= 1; rep
--) {
575 if (!memcmp(&codes
[c
- rep
* 3], &codes
[c
- rep
* 2], rep
) &&
576 !cmp_no_trail(&codes
[c
- rep
], &codes
[c
- rep
* 2], rep
)) {
583 /* first copy any leading non-repeating */
584 int leading
= c
- rep
* 3;
586 if (leading
>= ARRAY_SIZE(code_block
->codes
) - 3 - rep
) {
587 dev_warn(&rcdev
->dev
, "IR too long, cannot transmit\n");
591 dev_dbg(&rcdev
->dev
, "found trailing %d repeat\n", rep
);
592 copy_codes(code_block
->codes
, codes
, leading
);
593 code_block
->codes
[leading
] = 0x82;
594 copy_codes(code_block
->codes
+ leading
+ 1, codes
+ leading
,
596 c
= leading
+ 1 + rep
;
597 code_block
->codes
[c
++] = 0xc0;
599 if (c
>= ARRAY_SIZE(code_block
->codes
) - 3) {
600 dev_warn(&rcdev
->dev
, "IR too long, cannot transmit\n");
604 dev_dbg(&rcdev
->dev
, "found no trailing repeat\n");
605 code_block
->codes
[0] = 0x82;
606 copy_codes(code_block
->codes
+ 1, codes
, c
);
608 code_block
->codes
[c
++] = 0xc4;
611 while (c
< ARRAY_SIZE(code_block
->codes
))
612 code_block
->codes
[c
++] = 0x83;
617 static int zilog_tx(struct rc_dev
*rcdev
, unsigned int *txbuf
,
620 struct IR_i2c
*ir
= rcdev
->priv
;
621 struct code_block code_block
= { .length
= sizeof(code_block
) };
625 ret
= zilog_ir_format(rcdev
, txbuf
, count
, &code_block
);
629 ret
= mutex_lock_interruptible(&ir
->lock
);
633 ret
= send_data_block(ir
, ZILOG_UIR_END
, &code_block
);
637 ret
= i2c_master_recv(ir
->tx_c
, buf
, 1);
639 dev_err(&ir
->rc
->dev
, "i2c_master_recv failed with %d\n", ret
);
643 dev_dbg(&ir
->rc
->dev
, "code set status: %02x\n", buf
[0]);
645 if (buf
[0] != (ZILOG_STATUS_OK
| ZILOG_STATUS_SET
)) {
646 dev_err(&ir
->rc
->dev
, "unexpected IR TX response %02x\n",
655 ret
= i2c_master_send(ir
->tx_c
, buf
, 2);
657 dev_err(&ir
->rc
->dev
, "i2c_master_send failed with %d\n", ret
);
663 dev_dbg(&ir
->rc
->dev
, "send command sent\n");
666 * This bit NAKs until the device is ready, so we retry it
667 * sleeping a bit each time. This seems to be what the windows
668 * driver does, approximately.
671 for (i
= 0; i
< 20; ++i
) {
672 set_current_state(TASK_UNINTERRUPTIBLE
);
673 schedule_timeout(msecs_to_jiffies(50));
674 ret
= i2c_master_send(ir
->tx_c
, buf
, 1);
677 dev_dbg(&ir
->rc
->dev
,
678 "NAK expected: i2c_master_send failed with %d (try %d)\n",
683 dev_err(&ir
->rc
->dev
,
684 "IR TX chip never got ready: last i2c_master_send failed with %d\n",
691 i
= i2c_master_recv(ir
->tx_c
, buf
, 1);
693 dev_err(&ir
->rc
->dev
, "i2c_master_recv failed with %d\n", ret
);
696 } else if (buf
[0] != ZILOG_STATUS_OK
) {
697 dev_err(&ir
->rc
->dev
, "unexpected IR TX response #2: %02x\n",
702 dev_dbg(&ir
->rc
->dev
, "transmit complete\n");
704 /* Oh good, it worked */
707 mutex_unlock(&ir
->lock
);
712 static int zilog_tx_carrier(struct rc_dev
*dev
, u32 carrier
)
714 struct IR_i2c
*ir
= dev
->priv
;
716 if (carrier
> 500000 || carrier
< 20000)
719 ir
->carrier
= carrier
;
724 static int zilog_tx_duty_cycle(struct rc_dev
*dev
, u32 duty_cycle
)
726 struct IR_i2c
*ir
= dev
->priv
;
728 ir
->duty_cycle
= duty_cycle
;
733 static int ir_probe(struct i2c_client
*client
, const struct i2c_device_id
*id
)
735 char *ir_codes
= NULL
;
736 const char *name
= NULL
;
737 u64 rc_proto
= RC_PROTO_BIT_UNKNOWN
;
739 struct rc_dev
*rc
= NULL
;
740 struct i2c_adapter
*adap
= client
->adapter
;
741 unsigned short addr
= client
->addr
;
742 bool probe_tx
= (id
->driver_data
& FLAG_TX
) != 0;
745 if ((id
->driver_data
& FLAG_HDPVR
) && !enable_hdpvr
) {
746 dev_err(&client
->dev
, "IR for HDPVR is known to cause problems during recording, use enable_hdpvr modparam to enable\n");
750 ir
= devm_kzalloc(&client
->dev
, sizeof(*ir
), GFP_KERNEL
);
755 ir
->polling_interval
= DEFAULT_POLLING_INTERVAL
;
756 i2c_set_clientdata(client
, ir
);
761 ir
->get_key
= get_key_pixelview
;
762 rc_proto
= RC_PROTO_BIT_OTHER
;
763 ir_codes
= RC_MAP_EMPTY
;
769 ir
->get_key
= get_key_haup
;
770 rc_proto
= RC_PROTO_BIT_RC5
;
771 ir_codes
= RC_MAP_HAUPPAUGE
;
775 ir
->get_key
= get_key_knc1
;
776 rc_proto
= RC_PROTO_BIT_OTHER
;
777 ir_codes
= RC_MAP_EMPTY
;
781 ir
->get_key
= get_key_fusionhdtv
;
782 rc_proto
= RC_PROTO_BIT_UNKNOWN
;
783 ir_codes
= RC_MAP_FUSIONHDTV_MCE
;
786 name
= "AVerMedia Cardbus remote";
787 ir
->get_key
= get_key_avermedia_cardbus
;
788 rc_proto
= RC_PROTO_BIT_OTHER
;
789 ir_codes
= RC_MAP_AVERMEDIA_CARDBUS
;
792 name
= "AVerMedia EM78P153";
793 ir
->get_key
= get_key_avermedia_cardbus
;
794 rc_proto
= RC_PROTO_BIT_OTHER
;
795 /* RM-KV remote, seems to be same as RM-K6 */
796 ir_codes
= RC_MAP_AVERMEDIA_M733A_RM_K6
;
799 name
= "Hauppauge/Zilog Z8";
800 ir
->get_key
= get_key_haup_xvr
;
801 rc_proto
= RC_PROTO_BIT_RC5
| RC_PROTO_BIT_RC6_MCE
|
802 RC_PROTO_BIT_RC6_6A_32
;
803 ir_codes
= RC_MAP_HAUPPAUGE
;
808 /* Let the caller override settings */
809 if (client
->dev
.platform_data
) {
810 const struct IR_i2c_init_data
*init_data
=
811 client
->dev
.platform_data
;
813 ir_codes
= init_data
->ir_codes
;
814 rc
= init_data
->rc_dev
;
816 name
= init_data
->name
;
818 rc_proto
= init_data
->type
;
820 if (init_data
->polling_interval
)
821 ir
->polling_interval
= init_data
->polling_interval
;
823 switch (init_data
->internal_get_key_func
) {
824 case IR_KBD_GET_KEY_CUSTOM
:
825 /* The bridge driver provided us its own function */
826 ir
->get_key
= init_data
->get_key
;
828 case IR_KBD_GET_KEY_PIXELVIEW
:
829 ir
->get_key
= get_key_pixelview
;
831 case IR_KBD_GET_KEY_HAUP
:
832 ir
->get_key
= get_key_haup
;
834 case IR_KBD_GET_KEY_KNC1
:
835 ir
->get_key
= get_key_knc1
;
837 case IR_KBD_GET_KEY_FUSIONHDTV
:
838 ir
->get_key
= get_key_fusionhdtv
;
840 case IR_KBD_GET_KEY_HAUP_XVR
:
841 ir
->get_key
= get_key_haup_xvr
;
843 case IR_KBD_GET_KEY_AVERMEDIA_CARDBUS
:
844 ir
->get_key
= get_key_avermedia_cardbus
;
851 * If platform_data doesn't specify rc_dev, initialize it
854 rc
= rc_allocate_device(RC_DRIVER_SCANCODE
);
860 /* Make sure we are all setup before going on */
861 if (!name
|| !ir
->get_key
|| !rc_proto
|| !ir_codes
) {
862 dev_warn(&client
->dev
, "Unsupported device at address 0x%02x\n",
868 ir
->ir_codes
= ir_codes
;
870 snprintf(ir
->phys
, sizeof(ir
->phys
), "%s/%s", dev_name(&adap
->dev
),
871 dev_name(&client
->dev
));
874 * Initialize input_dev fields
875 * It doesn't make sense to allow overriding them via platform_data
877 rc
->input_id
.bustype
= BUS_I2C
;
878 rc
->input_phys
= ir
->phys
;
879 rc
->device_name
= name
;
880 rc
->dev
.parent
= &client
->dev
;
883 rc
->close
= ir_close
;
886 * Initialize the other fields of rc_dev
888 rc
->map_name
= ir
->ir_codes
;
889 rc
->allowed_protocols
= rc_proto
;
890 if (!rc
->driver_name
)
891 rc
->driver_name
= KBUILD_MODNAME
;
893 mutex_init(&ir
->lock
);
895 INIT_DELAYED_WORK(&ir
->work
, ir_work
);
898 ir
->tx_c
= i2c_new_dummy(client
->adapter
, 0x70);
900 dev_err(&client
->dev
, "failed to setup tx i2c address");
901 } else if (!zilog_init(ir
)) {
904 rc
->tx_ir
= zilog_tx
;
905 rc
->s_tx_carrier
= zilog_tx_carrier
;
906 rc
->s_tx_duty_cycle
= zilog_tx_duty_cycle
;
910 err
= rc_register_device(rc
);
918 i2c_unregister_device(ir
->tx_c
);
920 /* Only frees rc if it were allocated internally */
925 static int ir_remove(struct i2c_client
*client
)
927 struct IR_i2c
*ir
= i2c_get_clientdata(client
);
929 /* kill outstanding polls */
930 cancel_delayed_work_sync(&ir
->work
);
933 i2c_unregister_device(ir
->tx_c
);
935 /* unregister device */
936 rc_unregister_device(ir
->rc
);
942 static const struct i2c_device_id ir_kbd_id
[] = {
943 /* Generic entry for any IR receiver */
945 /* IR device specific entries should be added here */
946 { "ir_z8f0811_haup", FLAG_TX
},
947 { "ir_z8f0811_hdpvr", FLAG_TX
| FLAG_HDPVR
},
950 MODULE_DEVICE_TABLE(i2c
, ir_kbd_id
);
952 static struct i2c_driver ir_kbd_driver
= {
954 .name
= "ir-kbd-i2c",
958 .id_table
= ir_kbd_id
,
961 module_i2c_driver(ir_kbd_driver
);
963 /* ----------------------------------------------------------------------- */
965 MODULE_AUTHOR("Gerd Knorr, Michal Kochanowicz, Christoph Bartelmus, Ulrich Mueller");
966 MODULE_DESCRIPTION("input driver for i2c IR remote controls");
967 MODULE_LICENSE("GPL");