Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * handle saa7134 IR remotes via linux kernel input layer. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 | * |
| 19 | */ |
| 20 | |
| 21 | #include <linux/module.h> |
| 22 | #include <linux/moduleparam.h> |
| 23 | #include <linux/init.h> |
| 24 | #include <linux/delay.h> |
| 25 | #include <linux/sched.h> |
| 26 | #include <linux/interrupt.h> |
| 27 | #include <linux/input.h> |
| 28 | #include <linux/usb.h> |
| 29 | |
| 30 | #include "em2820.h" |
| 31 | |
| 32 | static unsigned int disable_ir = 0; |
| 33 | module_param(disable_ir, int, 0444); |
| 34 | MODULE_PARM_DESC(disable_ir,"disable infrared remote support"); |
| 35 | |
| 36 | static unsigned int ir_debug = 0; |
| 37 | module_param(ir_debug, int, 0644); |
| 38 | MODULE_PARM_DESC(ir_debug,"enable debug messages [IR]"); |
| 39 | |
| 40 | #define dprintk(fmt, arg...) if (ir_debug) \ |
| 41 | printk(KERN_DEBUG "%s/ir: " fmt, ir->c.name , ## arg) |
| 42 | |
| 43 | /* ---------------------------------------------------------------------- */ |
| 44 | |
Markus Rechberger | e43f14a | 2005-11-08 21:37:35 -0800 | [diff] [blame] | 45 | static IR_KEYTAB_TYPE ir_codes_em_terratec[IR_KEYTAB_SIZE] = { |
| 46 | [ 0x01 ] = KEY_CHANNEL, |
| 47 | [ 0x02 ] = KEY_SELECT, |
| 48 | [ 0x03 ] = KEY_MUTE, |
| 49 | [ 0x04 ] = KEY_POWER, |
| 50 | [ 0x05 ] = KEY_KP1, |
| 51 | [ 0x06 ] = KEY_KP2, |
| 52 | [ 0x07 ] = KEY_KP3, |
| 53 | [ 0x08 ] = KEY_CHANNELUP, |
| 54 | [ 0x09 ] = KEY_KP4, |
| 55 | [ 0x0a ] = KEY_KP5, |
| 56 | [ 0x0b ] = KEY_KP6, |
| 57 | [ 0x0c ] = KEY_CHANNELDOWN, |
| 58 | [ 0x0d ] = KEY_KP7, |
| 59 | [ 0x0e ] = KEY_KP8, |
| 60 | [ 0x0f ] = KEY_KP9, |
| 61 | [ 0x10 ] = KEY_VOLUMEUP, |
| 62 | [ 0x11 ] = KEY_KP0, |
| 63 | [ 0x12 ] = KEY_MENU, |
| 64 | [ 0x13 ] = KEY_PRINT, |
| 65 | [ 0x14 ] = KEY_VOLUMEDOWN, |
| 66 | [ 0x16 ] = KEY_PAUSE, |
| 67 | [ 0x18 ] = KEY_RECORD, |
| 68 | [ 0x19 ] = KEY_REWIND, |
| 69 | [ 0x1a ] = KEY_PLAY, |
| 70 | [ 0x1b ] = KEY_FORWARD, |
| 71 | [ 0x1c ] = KEY_BACKSPACE, |
| 72 | [ 0x1e ] = KEY_STOP, |
| 73 | [ 0x40 ] = KEY_ZOOM, |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | /* ----------------------------------------------------------------------- */ |
| 77 | |
Markus Rechberger | e43f14a | 2005-11-08 21:37:35 -0800 | [diff] [blame] | 78 | static int get_key_terratec(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) |
| 79 | { |
| 80 | unsigned char b; |
| 81 | |
| 82 | /* poll IR chip */ |
| 83 | if (1 != i2c_master_recv(&ir->c,&b,1)) { |
| 84 | dprintk("read error\n"); |
| 85 | return -EIO; |
| 86 | } |
| 87 | |
| 88 | /* it seems that 0xFE indicates that a button is still hold |
Mauro Carvalho Chehab | 4f9c05a | 2005-11-08 21:37:36 -0800 | [diff] [blame^] | 89 | down, while 0xff indicates that no button is hold |
| 90 | down. 0xfe sequences are sometimes interrupted by 0xFF */ |
Markus Rechberger | e43f14a | 2005-11-08 21:37:35 -0800 | [diff] [blame] | 91 | |
| 92 | dprintk("key %02x\n", b); |
| 93 | |
Mauro Carvalho Chehab | 4f9c05a | 2005-11-08 21:37:36 -0800 | [diff] [blame^] | 94 | if (b == 0xff) |
Markus Rechberger | e43f14a | 2005-11-08 21:37:35 -0800 | [diff] [blame] | 95 | return 0; |
| 96 | |
Mauro Carvalho Chehab | 4f9c05a | 2005-11-08 21:37:36 -0800 | [diff] [blame^] | 97 | if (b == 0xfe) |
Markus Rechberger | e43f14a | 2005-11-08 21:37:35 -0800 | [diff] [blame] | 98 | /* keep old data */ |
| 99 | return 1; |
| 100 | |
| 101 | *ir_key = b; |
| 102 | *ir_raw = b; |
| 103 | return 1; |
| 104 | } |
| 105 | |
| 106 | |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 107 | static int get_key_em_haup(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) |
| 108 | { |
| 109 | unsigned char buf[2]; |
| 110 | unsigned char code; |
| 111 | |
| 112 | /* poll IR chip */ |
| 113 | if (2 != i2c_master_recv(&ir->c,buf,2)) |
| 114 | return -EIO; |
| 115 | |
| 116 | /* Does eliminate repeated parity code */ |
| 117 | if (buf[1]==0xff) |
| 118 | return 0; |
| 119 | |
| 120 | /* avoid fast reapeating */ |
| 121 | if (buf[1]==ir->old) |
| 122 | return 0; |
| 123 | ir->old=buf[1]; |
| 124 | |
| 125 | /* Rearranges bits to the right order */ |
| 126 | code= ((buf[0]&0x01)<<5) | /* 0010 0000 */ |
| 127 | ((buf[0]&0x02)<<3) | /* 0001 0000 */ |
| 128 | ((buf[0]&0x04)<<1) | /* 0000 1000 */ |
| 129 | ((buf[0]&0x08)>>1) | /* 0000 0100 */ |
| 130 | ((buf[0]&0x10)>>3) | /* 0000 0010 */ |
| 131 | ((buf[0]&0x20)>>5); /* 0000 0001 */ |
| 132 | |
| 133 | dprintk("ir hauppauge (em2840): code=0x%02x (rcv=0x%02x)\n",code,buf[0]); |
| 134 | |
| 135 | /* return key */ |
| 136 | *ir_key = code; |
| 137 | *ir_raw = code; |
| 138 | return 1; |
| 139 | } |
| 140 | |
| 141 | /* ----------------------------------------------------------------------- */ |
| 142 | void em2820_set_ir(struct em2820 * dev,struct IR_i2c *ir) |
| 143 | { |
| 144 | if (disable_ir) |
| 145 | return ; |
| 146 | |
| 147 | /* detect & configure */ |
| 148 | switch (dev->model) { |
| 149 | case (EM2800_BOARD_UNKNOWN): |
| 150 | break; |
| 151 | case (EM2820_BOARD_UNKNOWN): |
| 152 | break; |
| 153 | case (EM2820_BOARD_TERRATEC_CINERGY_250): |
Markus Rechberger | e43f14a | 2005-11-08 21:37:35 -0800 | [diff] [blame] | 154 | ir->ir_codes = ir_codes_em_terratec; |
| 155 | ir->get_key = get_key_terratec; |
| 156 | snprintf(ir->c.name, sizeof(ir->c.name), "i2c IR (EM2820 Terratec)"); |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 157 | break; |
| 158 | case (EM2820_BOARD_PINNACLE_USB_2): |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 159 | break; |
| 160 | case (EM2820_BOARD_HAUPPAUGE_WINTV_USB_2): |
| 161 | ir->ir_codes = ir_codes_hauppauge_new; |
| 162 | ir->get_key = get_key_em_haup; |
Markus Rechberger | e43f14a | 2005-11-08 21:37:35 -0800 | [diff] [blame] | 163 | 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] | 164 | break; |
| 165 | case (EM2820_BOARD_MSI_VOX_USB_2): |
| 166 | break; |
| 167 | case (EM2800_BOARD_TERRATEC_CINERGY_200): |
| 168 | break; |
| 169 | case (EM2800_BOARD_LEADTEK_WINFAST_USBII): |
| 170 | break; |
| 171 | case (EM2800_BOARD_KWORLD_USB2800): |
| 172 | break; |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | /* ---------------------------------------------------------------------- |
| 177 | * Local variables: |
| 178 | * c-basic-offset: 8 |
| 179 | * End: |
| 180 | */ |