Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 1 | /* |
Mauro Carvalho Chehab | f7abcd3 | 2005-11-08 21:38:25 -0800 | [diff] [blame] | 2 | handle em28xx IR remotes via linux kernel input layer. |
| 3 | |
| 4 | Copyright (C) 2005 Ludovico Cavedon <cavedon@sssup.it> |
| 5 | Markus Rechberger <mrechberger@gmail.com> |
Mauro Carvalho Chehab | 2e7c6dc | 2006-04-03 07:53:40 -0300 | [diff] [blame] | 6 | Mauro Carvalho Chehab <mchehab@infradead.org> |
Mauro Carvalho Chehab | f7abcd3 | 2005-11-08 21:38:25 -0800 | [diff] [blame] | 7 | Sascha Sommer <saschasommer@freenet.de> |
| 8 | |
| 9 | This program is free software; you can redistribute it and/or modify |
| 10 | it under the terms of the GNU General Public License as published by |
| 11 | the Free Software Foundation; either version 2 of the License, or |
| 12 | (at your option) any later version. |
| 13 | |
| 14 | This program is distributed in the hope that it will be useful, |
| 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | GNU General Public License for more details. |
| 18 | |
| 19 | You should have received a copy of the GNU General Public License |
| 20 | along with this program; if not, write to the Free Software |
| 21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 22 | */ |
| 23 | |
| 24 | #include <linux/module.h> |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 25 | #include <linux/init.h> |
| 26 | #include <linux/delay.h> |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 27 | #include <linux/interrupt.h> |
| 28 | #include <linux/input.h> |
| 29 | #include <linux/usb.h> |
| 30 | |
Mauro Carvalho Chehab | f7abcd3 | 2005-11-08 21:38:25 -0800 | [diff] [blame] | 31 | #include "em28xx.h" |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 32 | |
Mauro Carvalho Chehab | c8793b0 | 2008-01-13 15:42:17 -0300 | [diff] [blame] | 33 | static unsigned int ir_debug; |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 34 | module_param(ir_debug, int, 0644); |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 35 | MODULE_PARM_DESC(ir_debug, "enable debug messages [IR]"); |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 36 | |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 37 | #define dprintk(fmt, arg...) \ |
| 38 | if (ir_debug) { \ |
| 39 | printk(KERN_DEBUG "%s/ir: " fmt, ir->c.name , ## arg); \ |
| 40 | } |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 41 | |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 42 | /* ----------------------------------------------------------------------- */ |
| 43 | |
Mauro Carvalho Chehab | c8793b0 | 2008-01-13 15:42:17 -0300 | [diff] [blame] | 44 | int em28xx_get_key_terratec(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) |
Markus Rechberger | e43f14a | 2005-11-08 21:37:35 -0800 | [diff] [blame] | 45 | { |
| 46 | unsigned char b; |
| 47 | |
| 48 | /* poll IR chip */ |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 49 | if (1 != i2c_master_recv(&ir->c, &b, 1)) { |
Markus Rechberger | e43f14a | 2005-11-08 21:37:35 -0800 | [diff] [blame] | 50 | dprintk("read error\n"); |
| 51 | return -EIO; |
| 52 | } |
| 53 | |
| 54 | /* it seems that 0xFE indicates that a button is still hold |
Mauro Carvalho Chehab | 4f9c05a | 2005-11-08 21:37:36 -0800 | [diff] [blame] | 55 | down, while 0xff indicates that no button is hold |
| 56 | down. 0xfe sequences are sometimes interrupted by 0xFF */ |
Markus Rechberger | e43f14a | 2005-11-08 21:37:35 -0800 | [diff] [blame] | 57 | |
| 58 | dprintk("key %02x\n", b); |
| 59 | |
Mauro Carvalho Chehab | 4f9c05a | 2005-11-08 21:37:36 -0800 | [diff] [blame] | 60 | if (b == 0xff) |
Markus Rechberger | e43f14a | 2005-11-08 21:37:35 -0800 | [diff] [blame] | 61 | return 0; |
| 62 | |
Mauro Carvalho Chehab | 4f9c05a | 2005-11-08 21:37:36 -0800 | [diff] [blame] | 63 | if (b == 0xfe) |
Markus Rechberger | e43f14a | 2005-11-08 21:37:35 -0800 | [diff] [blame] | 64 | /* keep old data */ |
| 65 | return 1; |
| 66 | |
| 67 | *ir_key = b; |
| 68 | *ir_raw = b; |
| 69 | return 1; |
| 70 | } |
| 71 | |
| 72 | |
Mauro Carvalho Chehab | c8793b0 | 2008-01-13 15:42:17 -0300 | [diff] [blame] | 73 | int em28xx_get_key_em_haup(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 74 | { |
| 75 | unsigned char buf[2]; |
| 76 | unsigned char code; |
| 77 | |
| 78 | /* poll IR chip */ |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 79 | if (2 != i2c_master_recv(&ir->c, buf, 2)) |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 80 | return -EIO; |
| 81 | |
| 82 | /* Does eliminate repeated parity code */ |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 83 | if (buf[1] == 0xff) |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 84 | return 0; |
| 85 | |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 86 | ir->old = buf[1]; |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 87 | |
| 88 | /* Rearranges bits to the right order */ |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 89 | code = ((buf[0]&0x01)<<5) | /* 0010 0000 */ |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 90 | ((buf[0]&0x02)<<3) | /* 0001 0000 */ |
| 91 | ((buf[0]&0x04)<<1) | /* 0000 1000 */ |
| 92 | ((buf[0]&0x08)>>1) | /* 0000 0100 */ |
| 93 | ((buf[0]&0x10)>>3) | /* 0000 0010 */ |
| 94 | ((buf[0]&0x20)>>5); /* 0000 0001 */ |
| 95 | |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 96 | dprintk("ir hauppauge (em2840): code=0x%02x (rcv=0x%02x)\n", |
| 97 | code, buf[0]); |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 98 | |
| 99 | /* return key */ |
| 100 | *ir_key = code; |
| 101 | *ir_raw = code; |
| 102 | return 1; |
| 103 | } |
| 104 | |
Mauro Carvalho Chehab | c8793b0 | 2008-01-13 15:42:17 -0300 | [diff] [blame] | 105 | int em28xx_get_key_pinnacle_usb_grey(struct IR_i2c *ir, u32 *ir_key, |
| 106 | u32 *ir_raw) |
Markus Rechberger | 366cc64 | 2006-01-15 21:04:27 -0200 | [diff] [blame] | 107 | { |
| 108 | unsigned char buf[3]; |
| 109 | |
| 110 | /* poll IR chip */ |
| 111 | |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 112 | if (3 != i2c_master_recv(&ir->c, buf, 3)) { |
Markus Rechberger | 366cc64 | 2006-01-15 21:04:27 -0200 | [diff] [blame] | 113 | dprintk("read error\n"); |
| 114 | return -EIO; |
| 115 | } |
| 116 | |
| 117 | dprintk("key %02x\n", buf[2]&0x3f); |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 118 | if (buf[0] != 0x00) |
Markus Rechberger | 366cc64 | 2006-01-15 21:04:27 -0200 | [diff] [blame] | 119 | return 0; |
Markus Rechberger | 366cc64 | 2006-01-15 21:04:27 -0200 | [diff] [blame] | 120 | |
| 121 | *ir_key = buf[2]&0x3f; |
| 122 | *ir_raw = buf[2]&0x3f; |
| 123 | |
| 124 | return 1; |
| 125 | } |
| 126 | |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 127 | /* ---------------------------------------------------------------------- |
| 128 | * Local variables: |
| 129 | * c-basic-offset: 8 |
| 130 | * End: |
| 131 | */ |