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> |
| 25 | #include <linux/moduleparam.h> |
| 26 | #include <linux/init.h> |
| 27 | #include <linux/delay.h> |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 28 | #include <linux/interrupt.h> |
| 29 | #include <linux/input.h> |
| 30 | #include <linux/usb.h> |
| 31 | |
Mauro Carvalho Chehab | f7abcd3 | 2005-11-08 21:38:25 -0800 | [diff] [blame] | 32 | #include "em28xx.h" |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 33 | |
| 34 | static unsigned int disable_ir = 0; |
| 35 | module_param(disable_ir, int, 0444); |
| 36 | MODULE_PARM_DESC(disable_ir,"disable infrared remote support"); |
| 37 | |
| 38 | static unsigned int ir_debug = 0; |
| 39 | module_param(ir_debug, int, 0644); |
| 40 | MODULE_PARM_DESC(ir_debug,"enable debug messages [IR]"); |
| 41 | |
| 42 | #define dprintk(fmt, arg...) if (ir_debug) \ |
| 43 | printk(KERN_DEBUG "%s/ir: " fmt, ir->c.name , ## arg) |
| 44 | |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 45 | /* ----------------------------------------------------------------------- */ |
| 46 | |
Markus Rechberger | e43f14a | 2005-11-08 21:37:35 -0800 | [diff] [blame] | 47 | static int get_key_terratec(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) |
| 48 | { |
| 49 | unsigned char b; |
| 50 | |
| 51 | /* poll IR chip */ |
| 52 | if (1 != i2c_master_recv(&ir->c,&b,1)) { |
| 53 | dprintk("read error\n"); |
| 54 | return -EIO; |
| 55 | } |
| 56 | |
| 57 | /* it seems that 0xFE indicates that a button is still hold |
Mauro Carvalho Chehab | 4f9c05a | 2005-11-08 21:37:36 -0800 | [diff] [blame] | 58 | down, while 0xff indicates that no button is hold |
| 59 | down. 0xfe sequences are sometimes interrupted by 0xFF */ |
Markus Rechberger | e43f14a | 2005-11-08 21:37:35 -0800 | [diff] [blame] | 60 | |
| 61 | dprintk("key %02x\n", b); |
| 62 | |
Mauro Carvalho Chehab | 4f9c05a | 2005-11-08 21:37:36 -0800 | [diff] [blame] | 63 | if (b == 0xff) |
Markus Rechberger | e43f14a | 2005-11-08 21:37:35 -0800 | [diff] [blame] | 64 | return 0; |
| 65 | |
Mauro Carvalho Chehab | 4f9c05a | 2005-11-08 21:37:36 -0800 | [diff] [blame] | 66 | if (b == 0xfe) |
Markus Rechberger | e43f14a | 2005-11-08 21:37:35 -0800 | [diff] [blame] | 67 | /* keep old data */ |
| 68 | return 1; |
| 69 | |
| 70 | *ir_key = b; |
| 71 | *ir_raw = b; |
| 72 | return 1; |
| 73 | } |
| 74 | |
| 75 | |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 76 | static int get_key_em_haup(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) |
| 77 | { |
| 78 | unsigned char buf[2]; |
| 79 | unsigned char code; |
| 80 | |
| 81 | /* poll IR chip */ |
| 82 | if (2 != i2c_master_recv(&ir->c,buf,2)) |
| 83 | return -EIO; |
| 84 | |
| 85 | /* Does eliminate repeated parity code */ |
| 86 | if (buf[1]==0xff) |
| 87 | return 0; |
| 88 | |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 89 | ir->old=buf[1]; |
| 90 | |
| 91 | /* Rearranges bits to the right order */ |
| 92 | code= ((buf[0]&0x01)<<5) | /* 0010 0000 */ |
| 93 | ((buf[0]&0x02)<<3) | /* 0001 0000 */ |
| 94 | ((buf[0]&0x04)<<1) | /* 0000 1000 */ |
| 95 | ((buf[0]&0x08)>>1) | /* 0000 0100 */ |
| 96 | ((buf[0]&0x10)>>3) | /* 0000 0010 */ |
| 97 | ((buf[0]&0x20)>>5); /* 0000 0001 */ |
| 98 | |
| 99 | dprintk("ir hauppauge (em2840): code=0x%02x (rcv=0x%02x)\n",code,buf[0]); |
| 100 | |
| 101 | /* return key */ |
| 102 | *ir_key = code; |
| 103 | *ir_raw = code; |
| 104 | return 1; |
| 105 | } |
| 106 | |
Sylvain Pasche | b93eedb | 2006-03-25 23:14:42 -0300 | [diff] [blame] | 107 | static int get_key_pinnacle_usb_grey(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) |
Markus Rechberger | 366cc64 | 2006-01-15 21:04:27 -0200 | [diff] [blame] | 108 | { |
| 109 | unsigned char buf[3]; |
| 110 | |
| 111 | /* poll IR chip */ |
| 112 | |
| 113 | if (3 != i2c_master_recv(&ir->c,buf,3)) { |
| 114 | dprintk("read error\n"); |
| 115 | return -EIO; |
| 116 | } |
| 117 | |
| 118 | dprintk("key %02x\n", buf[2]&0x3f); |
| 119 | if (buf[0]!=0x00){ |
| 120 | return 0; |
| 121 | } |
| 122 | |
| 123 | *ir_key = buf[2]&0x3f; |
| 124 | *ir_raw = buf[2]&0x3f; |
| 125 | |
| 126 | return 1; |
| 127 | } |
| 128 | |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 129 | /* ----------------------------------------------------------------------- */ |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 130 | void em28xx_set_ir(struct em28xx * dev,struct IR_i2c *ir) |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 131 | { |
Ricardo Cerqueira | ac9cd97 | 2005-11-08 21:37:56 -0800 | [diff] [blame] | 132 | if (disable_ir) { |
| 133 | ir->get_key=NULL; |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 134 | return ; |
Ricardo Cerqueira | ac9cd97 | 2005-11-08 21:37:56 -0800 | [diff] [blame] | 135 | } |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 136 | |
| 137 | /* detect & configure */ |
| 138 | switch (dev->model) { |
| 139 | case (EM2800_BOARD_UNKNOWN): |
| 140 | break; |
| 141 | case (EM2820_BOARD_UNKNOWN): |
| 142 | break; |
Sascha Sommer | 16f2e62 | 2005-11-08 21:37:37 -0800 | [diff] [blame] | 143 | case (EM2800_BOARD_TERRATEC_CINERGY_200): |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 144 | case (EM2820_BOARD_TERRATEC_CINERGY_250): |
Markus Rechberger | e43f14a | 2005-11-08 21:37:35 -0800 | [diff] [blame] | 145 | ir->ir_codes = ir_codes_em_terratec; |
| 146 | ir->get_key = get_key_terratec; |
Mauro Carvalho Chehab | 3acf280 | 2005-11-08 21:38:27 -0800 | [diff] [blame] | 147 | snprintf(ir->c.name, sizeof(ir->c.name), "i2c IR (EM28XX Terratec)"); |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 148 | break; |
| 149 | case (EM2820_BOARD_PINNACLE_USB_2): |
Sylvain Pasche | b93eedb | 2006-03-25 23:14:42 -0300 | [diff] [blame] | 150 | ir->ir_codes = ir_codes_pinnacle_grey; |
| 151 | ir->get_key = get_key_pinnacle_usb_grey; |
Markus Rechberger | 366cc64 | 2006-01-15 21:04:27 -0200 | [diff] [blame] | 152 | snprintf(ir->c.name, sizeof(ir->c.name), "i2c IR (EM28XX Pinnacle PCTV)"); |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 153 | break; |
| 154 | case (EM2820_BOARD_HAUPPAUGE_WINTV_USB_2): |
| 155 | ir->ir_codes = ir_codes_hauppauge_new; |
| 156 | ir->get_key = get_key_em_haup; |
Markus Rechberger | e43f14a | 2005-11-08 21:37:35 -0800 | [diff] [blame] | 157 | snprintf(ir->c.name, sizeof(ir->c.name), "i2c IR (EM2840 Hauppauge)"); |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 158 | break; |
| 159 | case (EM2820_BOARD_MSI_VOX_USB_2): |
| 160 | break; |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 161 | case (EM2800_BOARD_LEADTEK_WINFAST_USBII): |
| 162 | break; |
| 163 | case (EM2800_BOARD_KWORLD_USB2800): |
| 164 | break; |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | /* ---------------------------------------------------------------------- |
| 169 | * Local variables: |
| 170 | * c-basic-offset: 8 |
| 171 | * End: |
| 172 | */ |