1cb7a01acSMauro Carvalho Chehab /* 2cb7a01acSMauro Carvalho Chehab * 3cb7a01acSMauro Carvalho Chehab * keyboard input driver for i2c IR remote controls 4cb7a01acSMauro Carvalho Chehab * 5cb7a01acSMauro Carvalho Chehab * Copyright (c) 2000-2003 Gerd Knorr <kraxel@bytesex.org> 6cb7a01acSMauro Carvalho Chehab * modified for PixelView (BT878P+W/FM) by 7cb7a01acSMauro Carvalho Chehab * Michal Kochanowicz <mkochano@pld.org.pl> 8cb7a01acSMauro Carvalho Chehab * Christoph Bartelmus <lirc@bartelmus.de> 9cb7a01acSMauro Carvalho Chehab * modified for KNC ONE TV Station/Anubis Typhoon TView Tuner by 10cb7a01acSMauro Carvalho Chehab * Ulrich Mueller <ulrich.mueller42@web.de> 11cb7a01acSMauro Carvalho Chehab * modified for em2820 based USB TV tuners by 12cb7a01acSMauro Carvalho Chehab * Markus Rechberger <mrechberger@gmail.com> 13cb7a01acSMauro Carvalho Chehab * modified for DViCO Fusion HDTV 5 RT GOLD by 14cb7a01acSMauro Carvalho Chehab * Chaogui Zhang <czhang1974@gmail.com> 15cb7a01acSMauro Carvalho Chehab * modified for MSI TV@nywhere Plus by 16cb7a01acSMauro Carvalho Chehab * Henry Wong <henry@stuffedcow.net> 17cb7a01acSMauro Carvalho Chehab * Mark Schultz <n9xmj@yahoo.com> 18cb7a01acSMauro Carvalho Chehab * Brian Rogers <brian_rogers@comcast.net> 19cb7a01acSMauro Carvalho Chehab * modified for AVerMedia Cardbus by 20cb7a01acSMauro Carvalho Chehab * Oldrich Jedlicka <oldium.pro@seznam.cz> 21cb7a01acSMauro Carvalho Chehab * 22cb7a01acSMauro Carvalho Chehab * This program is free software; you can redistribute it and/or modify 23cb7a01acSMauro Carvalho Chehab * it under the terms of the GNU General Public License as published by 24cb7a01acSMauro Carvalho Chehab * the Free Software Foundation; either version 2 of the License, or 25cb7a01acSMauro Carvalho Chehab * (at your option) any later version. 26cb7a01acSMauro Carvalho Chehab * 27cb7a01acSMauro Carvalho Chehab * This program is distributed in the hope that it will be useful, 28cb7a01acSMauro Carvalho Chehab * but WITHOUT ANY WARRANTY; without even the implied warranty of 29cb7a01acSMauro Carvalho Chehab * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 30cb7a01acSMauro Carvalho Chehab * GNU General Public License for more details. 31cb7a01acSMauro Carvalho Chehab * 32cb7a01acSMauro Carvalho Chehab * You should have received a copy of the GNU General Public License 33cb7a01acSMauro Carvalho Chehab * along with this program; if not, write to the Free Software 34cb7a01acSMauro Carvalho Chehab * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 35cb7a01acSMauro Carvalho Chehab * 36cb7a01acSMauro Carvalho Chehab */ 37cb7a01acSMauro Carvalho Chehab 38cb7a01acSMauro Carvalho Chehab #include <linux/module.h> 39cb7a01acSMauro Carvalho Chehab #include <linux/init.h> 40cb7a01acSMauro Carvalho Chehab #include <linux/kernel.h> 41cb7a01acSMauro Carvalho Chehab #include <linux/string.h> 42cb7a01acSMauro Carvalho Chehab #include <linux/timer.h> 43cb7a01acSMauro Carvalho Chehab #include <linux/delay.h> 44cb7a01acSMauro Carvalho Chehab #include <linux/errno.h> 45cb7a01acSMauro Carvalho Chehab #include <linux/slab.h> 46cb7a01acSMauro Carvalho Chehab #include <linux/i2c.h> 47cb7a01acSMauro Carvalho Chehab #include <linux/workqueue.h> 48cb7a01acSMauro Carvalho Chehab 49cb7a01acSMauro Carvalho Chehab #include <media/rc-core.h> 50cb7a01acSMauro Carvalho Chehab #include <media/ir-kbd-i2c.h> 51cb7a01acSMauro Carvalho Chehab 52cb7a01acSMauro Carvalho Chehab /* ----------------------------------------------------------------------- */ 53cb7a01acSMauro Carvalho Chehab /* insmod parameters */ 54cb7a01acSMauro Carvalho Chehab 55cb7a01acSMauro Carvalho Chehab static int debug; 56cb7a01acSMauro Carvalho Chehab module_param(debug, int, 0644); /* debug level (0,1,2) */ 57cb7a01acSMauro Carvalho Chehab 58cb7a01acSMauro Carvalho Chehab 59cb7a01acSMauro Carvalho Chehab #define MODULE_NAME "ir-kbd-i2c" 60cb7a01acSMauro Carvalho Chehab #define dprintk(level, fmt, arg...) if (debug >= level) \ 61cb7a01acSMauro Carvalho Chehab printk(KERN_DEBUG MODULE_NAME ": " fmt , ## arg) 62cb7a01acSMauro Carvalho Chehab 63cb7a01acSMauro Carvalho Chehab /* ----------------------------------------------------------------------- */ 64cb7a01acSMauro Carvalho Chehab 654dd9bb91SDavid Härdeman static int get_key_haup_common(struct IR_i2c *ir, enum rc_type *protocol, 664dd9bb91SDavid Härdeman u32 *scancode, u8 *ptoggle, int size, int offset) 67cb7a01acSMauro Carvalho Chehab { 68cb7a01acSMauro Carvalho Chehab unsigned char buf[6]; 69cb7a01acSMauro Carvalho Chehab int start, range, toggle, dev, code, ircode; 70cb7a01acSMauro Carvalho Chehab 71cb7a01acSMauro Carvalho Chehab /* poll IR chip */ 72cb7a01acSMauro Carvalho Chehab if (size != i2c_master_recv(ir->c, buf, size)) 73cb7a01acSMauro Carvalho Chehab return -EIO; 74cb7a01acSMauro Carvalho Chehab 75cb7a01acSMauro Carvalho Chehab /* split rc5 data block ... */ 76cb7a01acSMauro Carvalho Chehab start = (buf[offset] >> 7) & 1; 77cb7a01acSMauro Carvalho Chehab range = (buf[offset] >> 6) & 1; 78cb7a01acSMauro Carvalho Chehab toggle = (buf[offset] >> 5) & 1; 79cb7a01acSMauro Carvalho Chehab dev = buf[offset] & 0x1f; 80cb7a01acSMauro Carvalho Chehab code = (buf[offset+1] >> 2) & 0x3f; 81cb7a01acSMauro Carvalho Chehab 82cb7a01acSMauro Carvalho Chehab /* rc5 has two start bits 83cb7a01acSMauro Carvalho Chehab * the first bit must be one 84cb7a01acSMauro Carvalho Chehab * the second bit defines the command range (1 = 0-63, 0 = 64 - 127) 85cb7a01acSMauro Carvalho Chehab */ 86cb7a01acSMauro Carvalho Chehab if (!start) 87cb7a01acSMauro Carvalho Chehab /* no key pressed */ 88cb7a01acSMauro Carvalho Chehab return 0; 894dd9bb91SDavid Härdeman 904dd9bb91SDavid Härdeman /* filter out invalid key presses */ 91cb7a01acSMauro Carvalho Chehab ircode = (start << 12) | (toggle << 11) | (dev << 6) | code; 92cb7a01acSMauro Carvalho Chehab if ((ircode & 0x1fff) == 0x1fff) 93cb7a01acSMauro Carvalho Chehab return 0; 94cb7a01acSMauro Carvalho Chehab 95cb7a01acSMauro Carvalho Chehab if (!range) 96cb7a01acSMauro Carvalho Chehab code += 64; 97cb7a01acSMauro Carvalho Chehab 98cb7a01acSMauro Carvalho Chehab dprintk(1,"ir hauppauge (rc5): s%d r%d t%d dev=%d code=%d\n", 99cb7a01acSMauro Carvalho Chehab start, range, toggle, dev, code); 100cb7a01acSMauro Carvalho Chehab 1014dd9bb91SDavid Härdeman *protocol = RC_TYPE_RC5; 1024dd9bb91SDavid Härdeman *scancode = RC_SCANCODE_RC5(dev, code); 1034dd9bb91SDavid Härdeman *ptoggle = toggle; 104cb7a01acSMauro Carvalho Chehab return 1; 105cb7a01acSMauro Carvalho Chehab } 106cb7a01acSMauro Carvalho Chehab 1074dd9bb91SDavid Härdeman static int get_key_haup(struct IR_i2c *ir, enum rc_type *protocol, 1084dd9bb91SDavid Härdeman u32 *scancode, u8 *toggle) 109cb7a01acSMauro Carvalho Chehab { 1104dd9bb91SDavid Härdeman return get_key_haup_common (ir, protocol, scancode, toggle, 3, 0); 111cb7a01acSMauro Carvalho Chehab } 112cb7a01acSMauro Carvalho Chehab 1134dd9bb91SDavid Härdeman static int get_key_haup_xvr(struct IR_i2c *ir, enum rc_type *protocol, 1144dd9bb91SDavid Härdeman u32 *scancode, u8 *toggle) 115cb7a01acSMauro Carvalho Chehab { 116cb7a01acSMauro Carvalho Chehab int ret; 117cb7a01acSMauro Carvalho Chehab unsigned char buf[1] = { 0 }; 118cb7a01acSMauro Carvalho Chehab 119cb7a01acSMauro Carvalho Chehab /* 120cb7a01acSMauro Carvalho Chehab * This is the same apparent "are you ready?" poll command observed 121cb7a01acSMauro Carvalho Chehab * watching Windows driver traffic and implemented in lirc_zilog. With 122cb7a01acSMauro Carvalho Chehab * this added, we get far saner remote behavior with z8 chips on usb 123cb7a01acSMauro Carvalho Chehab * connected devices, even with the default polling interval of 100ms. 124cb7a01acSMauro Carvalho Chehab */ 125cb7a01acSMauro Carvalho Chehab ret = i2c_master_send(ir->c, buf, 1); 126cb7a01acSMauro Carvalho Chehab if (ret != 1) 127cb7a01acSMauro Carvalho Chehab return (ret < 0) ? ret : -EINVAL; 128cb7a01acSMauro Carvalho Chehab 1294dd9bb91SDavid Härdeman return get_key_haup_common(ir, protocol, scancode, toggle, 6, 3); 130cb7a01acSMauro Carvalho Chehab } 131cb7a01acSMauro Carvalho Chehab 1324dd9bb91SDavid Härdeman static int get_key_pixelview(struct IR_i2c *ir, enum rc_type *protocol, 1334dd9bb91SDavid Härdeman u32 *scancode, u8 *toggle) 134cb7a01acSMauro Carvalho Chehab { 135cb7a01acSMauro Carvalho Chehab unsigned char b; 136cb7a01acSMauro Carvalho Chehab 137cb7a01acSMauro Carvalho Chehab /* poll IR chip */ 138cb7a01acSMauro Carvalho Chehab if (1 != i2c_master_recv(ir->c, &b, 1)) { 139cb7a01acSMauro Carvalho Chehab dprintk(1,"read error\n"); 140cb7a01acSMauro Carvalho Chehab return -EIO; 141cb7a01acSMauro Carvalho Chehab } 1424dd9bb91SDavid Härdeman 1434dd9bb91SDavid Härdeman *protocol = RC_TYPE_OTHER; 1444dd9bb91SDavid Härdeman *scancode = b; 1454dd9bb91SDavid Härdeman *toggle = 0; 146cb7a01acSMauro Carvalho Chehab return 1; 147cb7a01acSMauro Carvalho Chehab } 148cb7a01acSMauro Carvalho Chehab 1494dd9bb91SDavid Härdeman static int get_key_fusionhdtv(struct IR_i2c *ir, enum rc_type *protocol, 1504dd9bb91SDavid Härdeman u32 *scancode, u8 *toggle) 151cb7a01acSMauro Carvalho Chehab { 152cb7a01acSMauro Carvalho Chehab unsigned char buf[4]; 153cb7a01acSMauro Carvalho Chehab 154cb7a01acSMauro Carvalho Chehab /* poll IR chip */ 155cb7a01acSMauro Carvalho Chehab if (4 != i2c_master_recv(ir->c, buf, 4)) { 156cb7a01acSMauro Carvalho Chehab dprintk(1,"read error\n"); 157cb7a01acSMauro Carvalho Chehab return -EIO; 158cb7a01acSMauro Carvalho Chehab } 159cb7a01acSMauro Carvalho Chehab 160cb7a01acSMauro Carvalho Chehab if(buf[0] !=0 || buf[1] !=0 || buf[2] !=0 || buf[3] != 0) 161cb7a01acSMauro Carvalho Chehab dprintk(2, "%s: 0x%2x 0x%2x 0x%2x 0x%2x\n", __func__, 162cb7a01acSMauro Carvalho Chehab buf[0], buf[1], buf[2], buf[3]); 163cb7a01acSMauro Carvalho Chehab 164cb7a01acSMauro Carvalho Chehab /* no key pressed or signal from other ir remote */ 165cb7a01acSMauro Carvalho Chehab if(buf[0] != 0x1 || buf[1] != 0xfe) 166cb7a01acSMauro Carvalho Chehab return 0; 167cb7a01acSMauro Carvalho Chehab 1684dd9bb91SDavid Härdeman *protocol = RC_TYPE_UNKNOWN; 1694dd9bb91SDavid Härdeman *scancode = buf[2]; 1704dd9bb91SDavid Härdeman *toggle = 0; 171cb7a01acSMauro Carvalho Chehab return 1; 172cb7a01acSMauro Carvalho Chehab } 173cb7a01acSMauro Carvalho Chehab 1744dd9bb91SDavid Härdeman static int get_key_knc1(struct IR_i2c *ir, enum rc_type *protocol, 1754dd9bb91SDavid Härdeman u32 *scancode, u8 *toggle) 176cb7a01acSMauro Carvalho Chehab { 177cb7a01acSMauro Carvalho Chehab unsigned char b; 178cb7a01acSMauro Carvalho Chehab 179cb7a01acSMauro Carvalho Chehab /* poll IR chip */ 180cb7a01acSMauro Carvalho Chehab if (1 != i2c_master_recv(ir->c, &b, 1)) { 181cb7a01acSMauro Carvalho Chehab dprintk(1,"read error\n"); 182cb7a01acSMauro Carvalho Chehab return -EIO; 183cb7a01acSMauro Carvalho Chehab } 184cb7a01acSMauro Carvalho Chehab 185cb7a01acSMauro Carvalho Chehab /* it seems that 0xFE indicates that a button is still hold 186cb7a01acSMauro Carvalho Chehab down, while 0xff indicates that no button is hold 187cb7a01acSMauro Carvalho Chehab down. 0xfe sequences are sometimes interrupted by 0xFF */ 188cb7a01acSMauro Carvalho Chehab 189cb7a01acSMauro Carvalho Chehab dprintk(2,"key %02x\n", b); 190cb7a01acSMauro Carvalho Chehab 191cb7a01acSMauro Carvalho Chehab if (b == 0xff) 192cb7a01acSMauro Carvalho Chehab return 0; 193cb7a01acSMauro Carvalho Chehab 194cb7a01acSMauro Carvalho Chehab if (b == 0xfe) 195cb7a01acSMauro Carvalho Chehab /* keep old data */ 196cb7a01acSMauro Carvalho Chehab return 1; 197cb7a01acSMauro Carvalho Chehab 1984dd9bb91SDavid Härdeman *protocol = RC_TYPE_UNKNOWN; 1994dd9bb91SDavid Härdeman *scancode = b; 2004dd9bb91SDavid Härdeman *toggle = 0; 201cb7a01acSMauro Carvalho Chehab return 1; 202cb7a01acSMauro Carvalho Chehab } 203cb7a01acSMauro Carvalho Chehab 2044dd9bb91SDavid Härdeman static int get_key_avermedia_cardbus(struct IR_i2c *ir, enum rc_type *protocol, 2054dd9bb91SDavid Härdeman u32 *scancode, u8 *toggle) 206cb7a01acSMauro Carvalho Chehab { 207cb7a01acSMauro Carvalho Chehab unsigned char subaddr, key, keygroup; 208cb7a01acSMauro Carvalho Chehab struct i2c_msg msg[] = { { .addr = ir->c->addr, .flags = 0, 209cb7a01acSMauro Carvalho Chehab .buf = &subaddr, .len = 1}, 210cb7a01acSMauro Carvalho Chehab { .addr = ir->c->addr, .flags = I2C_M_RD, 211cb7a01acSMauro Carvalho Chehab .buf = &key, .len = 1} }; 212cb7a01acSMauro Carvalho Chehab subaddr = 0x0d; 213cb7a01acSMauro Carvalho Chehab if (2 != i2c_transfer(ir->c->adapter, msg, 2)) { 214cb7a01acSMauro Carvalho Chehab dprintk(1, "read error\n"); 215cb7a01acSMauro Carvalho Chehab return -EIO; 216cb7a01acSMauro Carvalho Chehab } 217cb7a01acSMauro Carvalho Chehab 218cb7a01acSMauro Carvalho Chehab if (key == 0xff) 219cb7a01acSMauro Carvalho Chehab return 0; 220cb7a01acSMauro Carvalho Chehab 221cb7a01acSMauro Carvalho Chehab subaddr = 0x0b; 222cb7a01acSMauro Carvalho Chehab msg[1].buf = &keygroup; 223cb7a01acSMauro Carvalho Chehab if (2 != i2c_transfer(ir->c->adapter, msg, 2)) { 224cb7a01acSMauro Carvalho Chehab dprintk(1, "read error\n"); 225cb7a01acSMauro Carvalho Chehab return -EIO; 226cb7a01acSMauro Carvalho Chehab } 227cb7a01acSMauro Carvalho Chehab 228cb7a01acSMauro Carvalho Chehab if (keygroup == 0xff) 229cb7a01acSMauro Carvalho Chehab return 0; 230cb7a01acSMauro Carvalho Chehab 231cb7a01acSMauro Carvalho Chehab dprintk(1, "read key 0x%02x/0x%02x\n", key, keygroup); 23234fe2784SOndrej Zary if (keygroup < 2 || keygroup > 4) { 233cb7a01acSMauro Carvalho Chehab /* Only a warning */ 234cb7a01acSMauro Carvalho Chehab dprintk(1, "warning: invalid key group 0x%02x for key 0x%02x\n", 235cb7a01acSMauro Carvalho Chehab keygroup, key); 236cb7a01acSMauro Carvalho Chehab } 237cb7a01acSMauro Carvalho Chehab key |= (keygroup & 1) << 6; 238cb7a01acSMauro Carvalho Chehab 2394dd9bb91SDavid Härdeman *protocol = RC_TYPE_UNKNOWN; 2404dd9bb91SDavid Härdeman *scancode = key; 2414dd9bb91SDavid Härdeman if (ir->c->addr == 0x41) /* AVerMedia EM78P153 */ 2424dd9bb91SDavid Härdeman *scancode |= keygroup << 8; 2434dd9bb91SDavid Härdeman *toggle = 0; 244cb7a01acSMauro Carvalho Chehab return 1; 245cb7a01acSMauro Carvalho Chehab } 246cb7a01acSMauro Carvalho Chehab 247cb7a01acSMauro Carvalho Chehab /* ----------------------------------------------------------------------- */ 248cb7a01acSMauro Carvalho Chehab 249cb7a01acSMauro Carvalho Chehab static int ir_key_poll(struct IR_i2c *ir) 250cb7a01acSMauro Carvalho Chehab { 2514dd9bb91SDavid Härdeman enum rc_type protocol; 2524dd9bb91SDavid Härdeman u32 scancode; 2534dd9bb91SDavid Härdeman u8 toggle; 254cb7a01acSMauro Carvalho Chehab int rc; 255cb7a01acSMauro Carvalho Chehab 256cb7a01acSMauro Carvalho Chehab dprintk(3, "%s\n", __func__); 2574dd9bb91SDavid Härdeman rc = ir->get_key(ir, &protocol, &scancode, &toggle); 258cb7a01acSMauro Carvalho Chehab if (rc < 0) { 259cb7a01acSMauro Carvalho Chehab dprintk(2,"error\n"); 260cb7a01acSMauro Carvalho Chehab return rc; 261cb7a01acSMauro Carvalho Chehab } 262cb7a01acSMauro Carvalho Chehab 263cb7a01acSMauro Carvalho Chehab if (rc) { 264*120703f9SDavid Härdeman dprintk(1, "%s: proto = 0x%04x, scancode = 0x%08x\n", 265*120703f9SDavid Härdeman __func__, protocol, scancode); 266*120703f9SDavid Härdeman rc_keydown(ir->rc, protocol, scancode, toggle); 267cb7a01acSMauro Carvalho Chehab } 268cb7a01acSMauro Carvalho Chehab return 0; 269cb7a01acSMauro Carvalho Chehab } 270cb7a01acSMauro Carvalho Chehab 271cb7a01acSMauro Carvalho Chehab static void ir_work(struct work_struct *work) 272cb7a01acSMauro Carvalho Chehab { 273cb7a01acSMauro Carvalho Chehab int rc; 274cb7a01acSMauro Carvalho Chehab struct IR_i2c *ir = container_of(work, struct IR_i2c, work.work); 275cb7a01acSMauro Carvalho Chehab 276cb7a01acSMauro Carvalho Chehab rc = ir_key_poll(ir); 277cb7a01acSMauro Carvalho Chehab if (rc == -ENODEV) { 278cb7a01acSMauro Carvalho Chehab rc_unregister_device(ir->rc); 279cb7a01acSMauro Carvalho Chehab ir->rc = NULL; 280cb7a01acSMauro Carvalho Chehab return; 281cb7a01acSMauro Carvalho Chehab } 282cb7a01acSMauro Carvalho Chehab 283cb7a01acSMauro Carvalho Chehab schedule_delayed_work(&ir->work, msecs_to_jiffies(ir->polling_interval)); 284cb7a01acSMauro Carvalho Chehab } 285cb7a01acSMauro Carvalho Chehab 286cb7a01acSMauro Carvalho Chehab /* ----------------------------------------------------------------------- */ 287cb7a01acSMauro Carvalho Chehab 288cb7a01acSMauro Carvalho Chehab static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id) 289cb7a01acSMauro Carvalho Chehab { 290cb7a01acSMauro Carvalho Chehab char *ir_codes = NULL; 291cb7a01acSMauro Carvalho Chehab const char *name = NULL; 292c003ab1bSDavid Härdeman u64 rc_type = RC_BIT_UNKNOWN; 293cb7a01acSMauro Carvalho Chehab struct IR_i2c *ir; 294cb7a01acSMauro Carvalho Chehab struct rc_dev *rc = NULL; 295cb7a01acSMauro Carvalho Chehab struct i2c_adapter *adap = client->adapter; 296cb7a01acSMauro Carvalho Chehab unsigned short addr = client->addr; 297cb7a01acSMauro Carvalho Chehab int err; 298cb7a01acSMauro Carvalho Chehab 299c02b211dSLaurent Pinchart ir = devm_kzalloc(&client->dev, sizeof(*ir), GFP_KERNEL); 300cb7a01acSMauro Carvalho Chehab if (!ir) 301cb7a01acSMauro Carvalho Chehab return -ENOMEM; 302cb7a01acSMauro Carvalho Chehab 303cb7a01acSMauro Carvalho Chehab ir->c = client; 304cb7a01acSMauro Carvalho Chehab ir->polling_interval = DEFAULT_POLLING_INTERVAL; 305cb7a01acSMauro Carvalho Chehab i2c_set_clientdata(client, ir); 306cb7a01acSMauro Carvalho Chehab 307cb7a01acSMauro Carvalho Chehab switch(addr) { 308cb7a01acSMauro Carvalho Chehab case 0x64: 309cb7a01acSMauro Carvalho Chehab name = "Pixelview"; 310cb7a01acSMauro Carvalho Chehab ir->get_key = get_key_pixelview; 311c003ab1bSDavid Härdeman rc_type = RC_BIT_OTHER; 312cb7a01acSMauro Carvalho Chehab ir_codes = RC_MAP_EMPTY; 313cb7a01acSMauro Carvalho Chehab break; 314cb7a01acSMauro Carvalho Chehab case 0x18: 315cb7a01acSMauro Carvalho Chehab case 0x1f: 316cb7a01acSMauro Carvalho Chehab case 0x1a: 317cb7a01acSMauro Carvalho Chehab name = "Hauppauge"; 318cb7a01acSMauro Carvalho Chehab ir->get_key = get_key_haup; 319c003ab1bSDavid Härdeman rc_type = RC_BIT_RC5; 320cb7a01acSMauro Carvalho Chehab ir_codes = RC_MAP_HAUPPAUGE; 321cb7a01acSMauro Carvalho Chehab break; 322cb7a01acSMauro Carvalho Chehab case 0x30: 323cb7a01acSMauro Carvalho Chehab name = "KNC One"; 324cb7a01acSMauro Carvalho Chehab ir->get_key = get_key_knc1; 325c003ab1bSDavid Härdeman rc_type = RC_BIT_OTHER; 326cb7a01acSMauro Carvalho Chehab ir_codes = RC_MAP_EMPTY; 327cb7a01acSMauro Carvalho Chehab break; 328cb7a01acSMauro Carvalho Chehab case 0x6b: 329cb7a01acSMauro Carvalho Chehab name = "FusionHDTV"; 330cb7a01acSMauro Carvalho Chehab ir->get_key = get_key_fusionhdtv; 3314dd9bb91SDavid Härdeman rc_type = RC_BIT_UNKNOWN; 332cb7a01acSMauro Carvalho Chehab ir_codes = RC_MAP_FUSIONHDTV_MCE; 333cb7a01acSMauro Carvalho Chehab break; 334cb7a01acSMauro Carvalho Chehab case 0x40: 335cb7a01acSMauro Carvalho Chehab name = "AVerMedia Cardbus remote"; 336cb7a01acSMauro Carvalho Chehab ir->get_key = get_key_avermedia_cardbus; 337c003ab1bSDavid Härdeman rc_type = RC_BIT_OTHER; 338cb7a01acSMauro Carvalho Chehab ir_codes = RC_MAP_AVERMEDIA_CARDBUS; 339cb7a01acSMauro Carvalho Chehab break; 34034fe2784SOndrej Zary case 0x41: 34134fe2784SOndrej Zary name = "AVerMedia EM78P153"; 34234fe2784SOndrej Zary ir->get_key = get_key_avermedia_cardbus; 34334fe2784SOndrej Zary rc_type = RC_BIT_OTHER; 34434fe2784SOndrej Zary /* RM-KV remote, seems to be same as RM-K6 */ 34534fe2784SOndrej Zary ir_codes = RC_MAP_AVERMEDIA_M733A_RM_K6; 34634fe2784SOndrej Zary break; 347cb7a01acSMauro Carvalho Chehab case 0x71: 348cb7a01acSMauro Carvalho Chehab name = "Hauppauge/Zilog Z8"; 349cb7a01acSMauro Carvalho Chehab ir->get_key = get_key_haup_xvr; 350c003ab1bSDavid Härdeman rc_type = RC_BIT_RC5; 351cb7a01acSMauro Carvalho Chehab ir_codes = RC_MAP_HAUPPAUGE; 352cb7a01acSMauro Carvalho Chehab break; 353cb7a01acSMauro Carvalho Chehab } 354cb7a01acSMauro Carvalho Chehab 355cb7a01acSMauro Carvalho Chehab /* Let the caller override settings */ 356cb7a01acSMauro Carvalho Chehab if (client->dev.platform_data) { 357cb7a01acSMauro Carvalho Chehab const struct IR_i2c_init_data *init_data = 358cb7a01acSMauro Carvalho Chehab client->dev.platform_data; 359cb7a01acSMauro Carvalho Chehab 360cb7a01acSMauro Carvalho Chehab ir_codes = init_data->ir_codes; 361cb7a01acSMauro Carvalho Chehab rc = init_data->rc_dev; 362cb7a01acSMauro Carvalho Chehab 363cb7a01acSMauro Carvalho Chehab name = init_data->name; 364cb7a01acSMauro Carvalho Chehab if (init_data->type) 365cb7a01acSMauro Carvalho Chehab rc_type = init_data->type; 366cb7a01acSMauro Carvalho Chehab 367cb7a01acSMauro Carvalho Chehab if (init_data->polling_interval) 368cb7a01acSMauro Carvalho Chehab ir->polling_interval = init_data->polling_interval; 369cb7a01acSMauro Carvalho Chehab 370cb7a01acSMauro Carvalho Chehab switch (init_data->internal_get_key_func) { 371cb7a01acSMauro Carvalho Chehab case IR_KBD_GET_KEY_CUSTOM: 372cb7a01acSMauro Carvalho Chehab /* The bridge driver provided us its own function */ 373cb7a01acSMauro Carvalho Chehab ir->get_key = init_data->get_key; 374cb7a01acSMauro Carvalho Chehab break; 375cb7a01acSMauro Carvalho Chehab case IR_KBD_GET_KEY_PIXELVIEW: 376cb7a01acSMauro Carvalho Chehab ir->get_key = get_key_pixelview; 377cb7a01acSMauro Carvalho Chehab break; 378cb7a01acSMauro Carvalho Chehab case IR_KBD_GET_KEY_HAUP: 379cb7a01acSMauro Carvalho Chehab ir->get_key = get_key_haup; 380cb7a01acSMauro Carvalho Chehab break; 381cb7a01acSMauro Carvalho Chehab case IR_KBD_GET_KEY_KNC1: 382cb7a01acSMauro Carvalho Chehab ir->get_key = get_key_knc1; 383cb7a01acSMauro Carvalho Chehab break; 384cb7a01acSMauro Carvalho Chehab case IR_KBD_GET_KEY_FUSIONHDTV: 385cb7a01acSMauro Carvalho Chehab ir->get_key = get_key_fusionhdtv; 386cb7a01acSMauro Carvalho Chehab break; 387cb7a01acSMauro Carvalho Chehab case IR_KBD_GET_KEY_HAUP_XVR: 388cb7a01acSMauro Carvalho Chehab ir->get_key = get_key_haup_xvr; 389cb7a01acSMauro Carvalho Chehab break; 390cb7a01acSMauro Carvalho Chehab case IR_KBD_GET_KEY_AVERMEDIA_CARDBUS: 391cb7a01acSMauro Carvalho Chehab ir->get_key = get_key_avermedia_cardbus; 392cb7a01acSMauro Carvalho Chehab break; 393cb7a01acSMauro Carvalho Chehab } 394cb7a01acSMauro Carvalho Chehab } 395cb7a01acSMauro Carvalho Chehab 396cb7a01acSMauro Carvalho Chehab if (!rc) { 397cb7a01acSMauro Carvalho Chehab /* 39839c1cb2bSJonathan McCrohan * If platform_data doesn't specify rc_dev, initialize it 399cb7a01acSMauro Carvalho Chehab * internally 400cb7a01acSMauro Carvalho Chehab */ 401cb7a01acSMauro Carvalho Chehab rc = rc_allocate_device(); 402c02b211dSLaurent Pinchart if (!rc) 403c02b211dSLaurent Pinchart return -ENOMEM; 404cb7a01acSMauro Carvalho Chehab } 405cb7a01acSMauro Carvalho Chehab ir->rc = rc; 406cb7a01acSMauro Carvalho Chehab 407cb7a01acSMauro Carvalho Chehab /* Make sure we are all setup before going on */ 408cb7a01acSMauro Carvalho Chehab if (!name || !ir->get_key || !rc_type || !ir_codes) { 409cb7a01acSMauro Carvalho Chehab dprintk(1, ": Unsupported device at address 0x%02x\n", 410cb7a01acSMauro Carvalho Chehab addr); 411cb7a01acSMauro Carvalho Chehab err = -ENODEV; 412cb7a01acSMauro Carvalho Chehab goto err_out_free; 413cb7a01acSMauro Carvalho Chehab } 414cb7a01acSMauro Carvalho Chehab 415cb7a01acSMauro Carvalho Chehab /* Sets name */ 416cb7a01acSMauro Carvalho Chehab snprintf(ir->name, sizeof(ir->name), "i2c IR (%s)", name); 417cb7a01acSMauro Carvalho Chehab ir->ir_codes = ir_codes; 418cb7a01acSMauro Carvalho Chehab 419cb7a01acSMauro Carvalho Chehab snprintf(ir->phys, sizeof(ir->phys), "%s/%s/ir0", 420cb7a01acSMauro Carvalho Chehab dev_name(&adap->dev), 421cb7a01acSMauro Carvalho Chehab dev_name(&client->dev)); 422cb7a01acSMauro Carvalho Chehab 423cb7a01acSMauro Carvalho Chehab /* 424cb7a01acSMauro Carvalho Chehab * Initialize input_dev fields 425cb7a01acSMauro Carvalho Chehab * It doesn't make sense to allow overriding them via platform_data 426cb7a01acSMauro Carvalho Chehab */ 427cb7a01acSMauro Carvalho Chehab rc->input_id.bustype = BUS_I2C; 428cb7a01acSMauro Carvalho Chehab rc->input_phys = ir->phys; 429cb7a01acSMauro Carvalho Chehab rc->input_name = ir->name; 430cb7a01acSMauro Carvalho Chehab 431cb7a01acSMauro Carvalho Chehab /* 432cb7a01acSMauro Carvalho Chehab * Initialize the other fields of rc_dev 433cb7a01acSMauro Carvalho Chehab */ 434cb7a01acSMauro Carvalho Chehab rc->map_name = ir->ir_codes; 4351a1934faSJames Hogan rc_set_allowed_protocols(rc, rc_type); 4361a1934faSJames Hogan rc_set_enabled_protocols(rc, rc_type); 437cb7a01acSMauro Carvalho Chehab if (!rc->driver_name) 438cb7a01acSMauro Carvalho Chehab rc->driver_name = MODULE_NAME; 439cb7a01acSMauro Carvalho Chehab 440cb7a01acSMauro Carvalho Chehab err = rc_register_device(rc); 441cb7a01acSMauro Carvalho Chehab if (err) 442cb7a01acSMauro Carvalho Chehab goto err_out_free; 443cb7a01acSMauro Carvalho Chehab 444cb7a01acSMauro Carvalho Chehab printk(MODULE_NAME ": %s detected at %s [%s]\n", 445cb7a01acSMauro Carvalho Chehab ir->name, ir->phys, adap->name); 446cb7a01acSMauro Carvalho Chehab 447cb7a01acSMauro Carvalho Chehab /* start polling via eventd */ 448cb7a01acSMauro Carvalho Chehab INIT_DELAYED_WORK(&ir->work, ir_work); 449cb7a01acSMauro Carvalho Chehab schedule_delayed_work(&ir->work, 0); 450cb7a01acSMauro Carvalho Chehab 451cb7a01acSMauro Carvalho Chehab return 0; 452cb7a01acSMauro Carvalho Chehab 453cb7a01acSMauro Carvalho Chehab err_out_free: 454cb7a01acSMauro Carvalho Chehab /* Only frees rc if it were allocated internally */ 455cb7a01acSMauro Carvalho Chehab rc_free_device(rc); 456cb7a01acSMauro Carvalho Chehab return err; 457cb7a01acSMauro Carvalho Chehab } 458cb7a01acSMauro Carvalho Chehab 459cb7a01acSMauro Carvalho Chehab static int ir_remove(struct i2c_client *client) 460cb7a01acSMauro Carvalho Chehab { 461cb7a01acSMauro Carvalho Chehab struct IR_i2c *ir = i2c_get_clientdata(client); 462cb7a01acSMauro Carvalho Chehab 463cb7a01acSMauro Carvalho Chehab /* kill outstanding polls */ 464cb7a01acSMauro Carvalho Chehab cancel_delayed_work_sync(&ir->work); 465cb7a01acSMauro Carvalho Chehab 466cb7a01acSMauro Carvalho Chehab /* unregister device */ 467cb7a01acSMauro Carvalho Chehab if (ir->rc) 468cb7a01acSMauro Carvalho Chehab rc_unregister_device(ir->rc); 469cb7a01acSMauro Carvalho Chehab 470cb7a01acSMauro Carvalho Chehab /* free memory */ 471cb7a01acSMauro Carvalho Chehab return 0; 472cb7a01acSMauro Carvalho Chehab } 473cb7a01acSMauro Carvalho Chehab 474cb7a01acSMauro Carvalho Chehab static const struct i2c_device_id ir_kbd_id[] = { 475cb7a01acSMauro Carvalho Chehab /* Generic entry for any IR receiver */ 476cb7a01acSMauro Carvalho Chehab { "ir_video", 0 }, 477cb7a01acSMauro Carvalho Chehab /* IR device specific entries should be added here */ 478cb7a01acSMauro Carvalho Chehab { "ir_rx_z8f0811_haup", 0 }, 479cb7a01acSMauro Carvalho Chehab { "ir_rx_z8f0811_hdpvr", 0 }, 480cb7a01acSMauro Carvalho Chehab { } 481cb7a01acSMauro Carvalho Chehab }; 482cb7a01acSMauro Carvalho Chehab 483cb7a01acSMauro Carvalho Chehab static struct i2c_driver ir_kbd_driver = { 484cb7a01acSMauro Carvalho Chehab .driver = { 485cb7a01acSMauro Carvalho Chehab .name = "ir-kbd-i2c", 486cb7a01acSMauro Carvalho Chehab }, 487cb7a01acSMauro Carvalho Chehab .probe = ir_probe, 488cb7a01acSMauro Carvalho Chehab .remove = ir_remove, 489cb7a01acSMauro Carvalho Chehab .id_table = ir_kbd_id, 490cb7a01acSMauro Carvalho Chehab }; 491cb7a01acSMauro Carvalho Chehab 492cb7a01acSMauro Carvalho Chehab module_i2c_driver(ir_kbd_driver); 493cb7a01acSMauro Carvalho Chehab 494cb7a01acSMauro Carvalho Chehab /* ----------------------------------------------------------------------- */ 495cb7a01acSMauro Carvalho Chehab 496cb7a01acSMauro Carvalho Chehab MODULE_AUTHOR("Gerd Knorr, Michal Kochanowicz, Christoph Bartelmus, Ulrich Mueller"); 497cb7a01acSMauro Carvalho Chehab MODULE_DESCRIPTION("input driver for i2c IR remote controls"); 498cb7a01acSMauro Carvalho Chehab MODULE_LICENSE("GPL"); 499