38 #include <linux/module.h>
40 #include <linux/kernel.h>
41 #include <linux/string.h>
44 #include <linux/errno.h>
45 #include <linux/slab.h>
46 #include <linux/i2c.h>
59 #define MODULE_NAME "ir-kbd-i2c"
60 #define dprintk(level, fmt, arg...) if (debug >= level) \
61 printk(KERN_DEBUG MODULE_NAME ": " fmt , ## arg)
65 static int get_key_haup_common(
struct IR_i2c *
ir,
u32 *ir_key,
u32 *ir_raw,
76 start = (buf[
offset] >> 7) & 1;
77 range = (buf[
offset] >> 6) & 1;
78 toggle = (buf[
offset] >> 5) & 1;
80 code = (buf[offset+1] >> 2) & 0x3f;
99 ircode= (start << 12) | (toggle << 11) | (dev << 6) | code;
100 if ((ircode & 0x1fff)==0x1fff)
107 dprintk(1,
"ir hauppauge (rc5): s%d r%d t%d dev=%d code=%d\n",
108 start, range, toggle, dev, code);
111 *ir_key = (dev << 8) | code;
116 static int get_key_haup(
struct IR_i2c *
ir,
u32 *ir_key,
u32 *ir_raw)
118 return get_key_haup_common (ir, ir_key, ir_raw, 3, 0);
121 static int get_key_haup_xvr(
struct IR_i2c *
ir,
u32 *ir_key,
u32 *ir_raw)
124 unsigned char buf[1] = { 0 };
134 return (ret < 0) ? ret : -
EINVAL;
136 return get_key_haup_common (ir, ir_key, ir_raw, 6, 3);
139 static int get_key_pixelview(
struct IR_i2c *ir,
u32 *ir_key,
u32 *ir_raw)
153 static int get_key_fusionhdtv(
struct IR_i2c *ir,
u32 *ir_key,
u32 *ir_raw)
155 unsigned char buf[4];
163 if(buf[0] !=0 || buf[1] !=0 || buf[2] !=0 || buf[3] != 0)
164 dprintk(2,
"%s: 0x%2x 0x%2x 0x%2x 0x%2x\n", __func__,
165 buf[0], buf[1], buf[2], buf[3]);
168 if(buf[0] != 0x1 || buf[1] != 0xfe)
172 *ir_raw = (buf[2] << 8) | buf[3];
177 static int get_key_knc1(
struct IR_i2c *ir,
u32 *ir_key,
u32 *ir_raw)
205 static int get_key_avermedia_cardbus(
struct IR_i2c *ir,
208 unsigned char subaddr,
key, keygroup;
209 struct i2c_msg msg[] = { { .addr = ir->
c->addr, .flags = 0,
210 .buf = &subaddr, .len = 1},
211 { .addr = ir->
c->addr, .flags =
I2C_M_RD,
212 .buf = &
key, .len = 1} };
223 msg[1].
buf = &keygroup;
229 if (keygroup == 0xff)
232 dprintk(1,
"read key 0x%02x/0x%02x\n", key, keygroup);
233 if (keygroup < 2 || keygroup > 3) {
235 dprintk(1,
"warning: invalid key group 0x%02x for key 0x%02x\n",
238 key |= (keygroup & 1) << 6;
247 static int ir_key_poll(
struct IR_i2c *ir)
249 static u32 ir_key, ir_raw;
253 rc = ir->
get_key(ir, &ir_key, &ir_raw);
260 dprintk(1,
"%s: keycode = 0x%04x\n", __func__, ir_key);
271 rc = ir_key_poll(ir);
300 i2c_set_clientdata(client, ir);
305 ir->
get_key = get_key_pixelview;
325 ir->
get_key = get_key_fusionhdtv;
330 name =
"AVerMedia Cardbus remote";
331 ir->
get_key = get_key_avermedia_cardbus;
336 name =
"Hauppauge/Zilog Z8";
337 ir->
get_key = get_key_haup_xvr;
344 if (client->
dev.platform_data) {
346 client->
dev.platform_data;
351 name = init_data->
name;
353 rc_type = init_data->
type;
364 ir->
get_key = get_key_pixelview;
373 ir->
get_key = get_key_fusionhdtv;
376 ir->
get_key = get_key_haup_xvr;
379 ir->
get_key = get_key_avermedia_cardbus;
398 if (!name || !ir->
get_key || !rc_type || !ir_codes) {
399 dprintk(1,
": Unsupported device at address 0x%02x\n",
410 dev_name(&adap->
dev),
411 dev_name(&client->
dev));
449 static int ir_remove(
struct i2c_client *client)
451 struct IR_i2c *ir = i2c_get_clientdata(client);
469 {
"ir_rx_z8f0811_haup", 0 },
470 {
"ir_rx_z8f0811_hdpvr", 0 },
476 .name =
"ir-kbd-i2c",
480 .id_table = ir_kbd_id,
487 MODULE_AUTHOR(
"Gerd Knorr, Michal Kochanowicz, Christoph Bartelmus, Ulrich Mueller");