Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * |
| 3 | * Device driver for GPIO attached remote control interfaces |
| 4 | * on Conexant 2388x based TV/DVB cards. |
| 5 | * |
| 6 | * Copyright (c) 2003 Pavel Machek |
| 7 | * Copyright (c) 2004 Gerd Knorr |
Chris Pascoe | fc40b26 | 2006-01-09 15:25:35 -0200 | [diff] [blame] | 8 | * Copyright (c) 2004, 2005 Chris Pascoe |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 23 | */ |
| 24 | |
| 25 | #include <linux/init.h> |
| 26 | #include <linux/delay.h> |
| 27 | #include <linux/input.h> |
| 28 | #include <linux/pci.h> |
| 29 | #include <linux/module.h> |
| 30 | #include <linux/moduleparam.h> |
| 31 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include "cx88.h" |
Mauro Carvalho Chehab | d21838d | 2006-01-09 15:25:21 -0200 | [diff] [blame] | 33 | #include <media/ir-common.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
| 35 | /* ---------------------------------------------------------------------- */ |
| 36 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | struct cx88_IR { |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 38 | struct cx88_core *core; |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 39 | struct input_dev *input; |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 40 | struct ir_input_state ir; |
| 41 | char name[32]; |
| 42 | char phys[32]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
| 44 | /* sample from gpio pin 16 */ |
Chris Pascoe | fc40b26 | 2006-01-09 15:25:35 -0200 | [diff] [blame] | 45 | u32 sampling; |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 46 | u32 samples[16]; |
| 47 | int scount; |
| 48 | unsigned long release; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
| 50 | /* poll external decoder */ |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 51 | int polling; |
| 52 | struct work_struct work; |
| 53 | struct timer_list timer; |
| 54 | u32 gpio_addr; |
| 55 | u32 last_gpio; |
| 56 | u32 mask_keycode; |
| 57 | u32 mask_keydown; |
| 58 | u32 mask_keyup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | static int ir_debug = 0; |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 62 | module_param(ir_debug, int, 0644); /* debug level [IR] */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | MODULE_PARM_DESC(ir_debug, "enable debug messages [IR]"); |
| 64 | |
| 65 | #define ir_dprintk(fmt, arg...) if (ir_debug) \ |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 66 | printk(KERN_DEBUG "%s IR: " fmt , ir->core->name , ##arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
| 68 | /* ---------------------------------------------------------------------- */ |
| 69 | |
| 70 | static void cx88_ir_handle_key(struct cx88_IR *ir) |
| 71 | { |
| 72 | struct cx88_core *core = ir->core; |
Ricardo Cerqueira | 680543c | 2006-05-22 07:44:02 -0300 | [diff] [blame] | 73 | u32 gpio, data, auxgpio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | |
| 75 | /* read gpio value */ |
| 76 | gpio = cx_read(ir->gpio_addr); |
Ricardo Cerqueira | be4f451 | 2006-06-08 17:36:17 -0300 | [diff] [blame] | 77 | if (core->board == CX88_BOARD_NPGTECH_REALTV_TOP10FM) { |
Ricardo Cerqueira | 680543c | 2006-05-22 07:44:02 -0300 | [diff] [blame] | 78 | /* This board apparently uses a combination of 2 GPIO |
| 79 | to represent the keys. Additionally, the second GPIO |
| 80 | can be used for parity. |
| 81 | |
| 82 | Example: |
| 83 | |
| 84 | for key "5" |
| 85 | gpio = 0x758, auxgpio = 0xe5 or 0xf5 |
| 86 | for key "Power" |
| 87 | gpio = 0x758, auxgpio = 0xed or 0xfd |
| 88 | */ |
| 89 | |
| 90 | auxgpio = cx_read(MO_GP1_IO); |
| 91 | /* Take out the parity part */ |
Ricardo Cerqueira | a62c61d | 2006-07-17 16:34:27 -0300 | [diff] [blame] | 92 | gpio=(gpio & 0x7fd) + (auxgpio & 0xef); |
Edgar Pisani | e7d11ec | 2007-06-25 14:46:05 -0300 | [diff] [blame^] | 93 | } else if (core->board == CX88_BOARD_WINFAST_DTV1000) { |
| 94 | gpio = (gpio & 0x6ff) | ((cx_read(MO_GP1_IO) << 8) & 0x900); |
| 95 | auxgpio = gpio; |
Ricardo Cerqueira | 680543c | 2006-05-22 07:44:02 -0300 | [diff] [blame] | 96 | } else |
| 97 | auxgpio = gpio; |
| 98 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | if (ir->polling) { |
Ricardo Cerqueira | 680543c | 2006-05-22 07:44:02 -0300 | [diff] [blame] | 100 | if (ir->last_gpio == auxgpio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | return; |
Ricardo Cerqueira | 680543c | 2006-05-22 07:44:02 -0300 | [diff] [blame] | 102 | ir->last_gpio = auxgpio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | /* extract data */ |
| 106 | data = ir_extract_bits(gpio, ir->mask_keycode); |
| 107 | ir_dprintk("irq gpio=0x%x code=%d | %s%s%s\n", |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 108 | gpio, data, |
| 109 | ir->polling ? "poll" : "irq", |
| 110 | (gpio & ir->mask_keydown) ? " down" : "", |
| 111 | (gpio & ir->mask_keyup) ? " up" : ""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | |
Peter Naulls | d1009bd | 2006-08-08 09:10:05 -0300 | [diff] [blame] | 113 | if (ir->core->board == CX88_BOARD_NORWOOD_MICRO) { |
| 114 | u32 gpio_key = cx_read(MO_GP0_IO); |
| 115 | |
| 116 | data = (data << 4) | ((gpio_key & 0xf0) >> 4); |
| 117 | |
| 118 | ir_input_keydown(ir->input, &ir->ir, data, data); |
| 119 | ir_input_nokey(ir->input, &ir->ir); |
| 120 | |
| 121 | } else if (ir->mask_keydown) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | /* bit set on keydown */ |
| 123 | if (gpio & ir->mask_keydown) { |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 124 | ir_input_keydown(ir->input, &ir->ir, data, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | } else { |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 126 | ir_input_nokey(ir->input, &ir->ir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | } else if (ir->mask_keyup) { |
| 130 | /* bit cleared on keydown */ |
| 131 | if (0 == (gpio & ir->mask_keyup)) { |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 132 | ir_input_keydown(ir->input, &ir->ir, data, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | } else { |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 134 | ir_input_nokey(ir->input, &ir->ir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | } else { |
| 138 | /* can't distinguish keydown/up :-/ */ |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 139 | ir_input_keydown(ir->input, &ir->ir, data, data); |
| 140 | ir_input_nokey(ir->input, &ir->ir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | } |
| 142 | } |
| 143 | |
| 144 | static void ir_timer(unsigned long data) |
| 145 | { |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 146 | struct cx88_IR *ir = (struct cx88_IR *)data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | |
| 148 | schedule_work(&ir->work); |
| 149 | } |
| 150 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 151 | static void cx88_ir_work(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 153 | struct cx88_IR *ir = container_of(work, struct cx88_IR, work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | |
| 155 | cx88_ir_handle_key(ir); |
Dmitry Torokhov | 749823a | 2007-05-21 11:48:11 -0300 | [diff] [blame] | 156 | mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | } |
| 158 | |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 159 | static void cx88_ir_start(struct cx88_core *core, struct cx88_IR *ir) |
| 160 | { |
| 161 | if (ir->polling) { |
Dmitry Torokhov | 749823a | 2007-05-21 11:48:11 -0300 | [diff] [blame] | 162 | setup_timer(&ir->timer, ir_timer, (unsigned long)ir); |
Mauro Carvalho Chehab | 67952e8 | 2006-12-10 00:14:21 -0200 | [diff] [blame] | 163 | INIT_WORK(&ir->work, cx88_ir_work); |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 164 | schedule_work(&ir->work); |
| 165 | } |
| 166 | if (ir->sampling) { |
| 167 | core->pci_irqmask |= (1 << 18); /* IR_SMP_INT */ |
| 168 | cx_write(MO_DDS_IO, 0xa80a80); /* 4 kHz sample rate */ |
| 169 | cx_write(MO_DDSCFG_IO, 0x5); /* enable */ |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | static void cx88_ir_stop(struct cx88_core *core, struct cx88_IR *ir) |
| 174 | { |
| 175 | if (ir->sampling) { |
| 176 | cx_write(MO_DDSCFG_IO, 0x0); |
| 177 | core->pci_irqmask &= ~(1 << 18); |
| 178 | } |
| 179 | |
| 180 | if (ir->polling) { |
| 181 | del_timer_sync(&ir->timer); |
| 182 | flush_scheduled_work(); |
| 183 | } |
| 184 | } |
| 185 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | /* ---------------------------------------------------------------------- */ |
| 187 | |
| 188 | int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci) |
| 189 | { |
| 190 | struct cx88_IR *ir; |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 191 | struct input_dev *input_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | IR_KEYTAB_TYPE *ir_codes = NULL; |
| 193 | int ir_type = IR_TYPE_OTHER; |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 194 | int err = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 196 | ir = kzalloc(sizeof(*ir), GFP_KERNEL); |
| 197 | input_dev = input_allocate_device(); |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 198 | if (!ir || !input_dev) |
| 199 | goto err_out_free; |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 200 | |
| 201 | ir->input = input_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | |
| 203 | /* detect & configure */ |
| 204 | switch (core->board) { |
| 205 | case CX88_BOARD_DNTV_LIVE_DVB_T: |
Mauro Carvalho Chehab | b45009b | 2005-06-23 22:05:03 -0700 | [diff] [blame] | 206 | case CX88_BOARD_KWORLD_DVB_T: |
Marco Manenti | 28ecc44 | 2006-02-07 06:45:33 -0200 | [diff] [blame] | 207 | case CX88_BOARD_KWORLD_DVB_T_CX22702: |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 208 | ir_codes = ir_codes_dntv_live_dvb_t; |
| 209 | ir->gpio_addr = MO_GP1_IO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | ir->mask_keycode = 0x1f; |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 211 | ir->mask_keyup = 0x60; |
| 212 | ir->polling = 50; /* ms */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | break; |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 214 | case CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1: |
| 215 | ir_codes = ir_codes_cinergy_1400; |
| 216 | ir_type = IR_TYPE_PD; |
Chris Pascoe | fc40b26 | 2006-01-09 15:25:35 -0200 | [diff] [blame] | 217 | ir->sampling = 0xeb04; /* address */ |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 218 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | case CX88_BOARD_HAUPPAUGE: |
| 220 | case CX88_BOARD_HAUPPAUGE_DVB_T1: |
Steven Toth | fb56cb6 | 2006-01-09 15:25:02 -0200 | [diff] [blame] | 221 | case CX88_BOARD_HAUPPAUGE_NOVASE2_S1: |
| 222 | case CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1: |
Steven Toth | 611900c | 2006-01-09 15:25:12 -0200 | [diff] [blame] | 223 | case CX88_BOARD_HAUPPAUGE_HVR1100: |
Steven Toth | 76dc82a | 2006-09-30 00:43:58 -0300 | [diff] [blame] | 224 | case CX88_BOARD_HAUPPAUGE_HVR3000: |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 225 | ir_codes = ir_codes_hauppauge_new; |
| 226 | ir_type = IR_TYPE_RC5; |
| 227 | ir->sampling = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | break; |
Malcolm Valentine | 2de873e | 2006-05-29 13:56:24 -0300 | [diff] [blame] | 229 | case CX88_BOARD_WINFAST_DTV2000H: |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 230 | ir_codes = ir_codes_winfast; |
| 231 | ir->gpio_addr = MO_GP0_IO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | ir->mask_keycode = 0x8f8; |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 233 | ir->mask_keyup = 0x100; |
Malcolm Valentine | 2de873e | 2006-05-29 13:56:24 -0300 | [diff] [blame] | 234 | ir->polling = 50; /* ms */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | break; |
Hermann Pitton | ff97d93 | 2006-11-03 10:45:52 -0300 | [diff] [blame] | 236 | case CX88_BOARD_WINFAST2000XP_EXPERT: |
Edgar Pisani | e7d11ec | 2007-06-25 14:46:05 -0300 | [diff] [blame^] | 237 | case CX88_BOARD_WINFAST_DTV1000: |
Hermann Pitton | ff97d93 | 2006-11-03 10:45:52 -0300 | [diff] [blame] | 238 | ir_codes = ir_codes_winfast; |
| 239 | ir->gpio_addr = MO_GP0_IO; |
| 240 | ir->mask_keycode = 0x8f8; |
| 241 | ir->mask_keyup = 0x100; |
| 242 | ir->polling = 1; /* ms */ |
| 243 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | case CX88_BOARD_IODATA_GVBCTV7E: |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 245 | ir_codes = ir_codes_iodata_bctv7e; |
| 246 | ir->gpio_addr = MO_GP0_IO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | ir->mask_keycode = 0xfd; |
| 248 | ir->mask_keydown = 0x02; |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 249 | ir->polling = 5; /* ms */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | break; |
Hermann Pitton | ff97d93 | 2006-11-03 10:45:52 -0300 | [diff] [blame] | 251 | case CX88_BOARD_PROLINK_PLAYTVPVR: |
Manuel Capinha | 239df2e | 2005-06-23 22:04:53 -0700 | [diff] [blame] | 252 | case CX88_BOARD_PIXELVIEW_PLAYTV_ULTRA_PRO: |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 253 | ir_codes = ir_codes_pixelview; |
| 254 | ir->gpio_addr = MO_GP1_IO; |
Manuel Capinha | 239df2e | 2005-06-23 22:04:53 -0700 | [diff] [blame] | 255 | ir->mask_keycode = 0x1f; |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 256 | ir->mask_keyup = 0x80; |
| 257 | ir->polling = 1; /* ms */ |
Manuel Capinha | 239df2e | 2005-06-23 22:04:53 -0700 | [diff] [blame] | 258 | break; |
Nickolay V. Shmyrev | b639f9d | 2006-01-23 09:44:10 -0200 | [diff] [blame] | 259 | case CX88_BOARD_KWORLD_LTV883: |
| 260 | ir_codes = ir_codes_pixelview; |
| 261 | ir->gpio_addr = MO_GP1_IO; |
| 262 | ir->mask_keycode = 0x1f; |
| 263 | ir->mask_keyup = 0x60; |
| 264 | ir->polling = 1; /* ms */ |
| 265 | break; |
Mauro Carvalho Chehab | a82decf | 2005-07-07 17:58:36 -0700 | [diff] [blame] | 266 | case CX88_BOARD_ADSTECH_DVB_T_PCI: |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 267 | ir_codes = ir_codes_adstech_dvb_t_pci; |
| 268 | ir->gpio_addr = MO_GP1_IO; |
Mauro Carvalho Chehab | a82decf | 2005-07-07 17:58:36 -0700 | [diff] [blame] | 269 | ir->mask_keycode = 0xbf; |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 270 | ir->mask_keyup = 0x40; |
| 271 | ir->polling = 50; /* ms */ |
Mauro Carvalho Chehab | a82decf | 2005-07-07 17:58:36 -0700 | [diff] [blame] | 272 | break; |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 273 | case CX88_BOARD_MSI_TVANYWHERE_MASTER: |
| 274 | ir_codes = ir_codes_msi_tvanywhere; |
| 275 | ir->gpio_addr = MO_GP1_IO; |
| 276 | ir->mask_keycode = 0x1f; |
| 277 | ir->mask_keyup = 0x40; |
| 278 | ir->polling = 1; /* ms */ |
| 279 | break; |
George Gazurkoff | 899ad11 | 2006-01-09 15:25:19 -0200 | [diff] [blame] | 280 | case CX88_BOARD_AVERTV_303: |
George Gazurkoff | 565f494 | 2006-01-09 15:32:46 -0200 | [diff] [blame] | 281 | case CX88_BOARD_AVERTV_STUDIO_303: |
George Gazurkoff | 899ad11 | 2006-01-09 15:25:19 -0200 | [diff] [blame] | 282 | ir_codes = ir_codes_avertv_303; |
| 283 | ir->gpio_addr = MO_GP2_IO; |
| 284 | ir->mask_keycode = 0xfb; |
| 285 | ir->mask_keydown = 0x02; |
| 286 | ir->polling = 50; /* ms */ |
| 287 | break; |
Chris Pascoe | fc40b26 | 2006-01-09 15:25:35 -0200 | [diff] [blame] | 288 | case CX88_BOARD_DNTV_LIVE_DVB_T_PRO: |
| 289 | ir_codes = ir_codes_dntv_live_dvbt_pro; |
| 290 | ir_type = IR_TYPE_PD; |
| 291 | ir->sampling = 0xff00; /* address */ |
| 292 | break; |
Peter Naulls | d1009bd | 2006-08-08 09:10:05 -0300 | [diff] [blame] | 293 | case CX88_BOARD_NORWOOD_MICRO: |
| 294 | ir_codes = ir_codes_norwood; |
| 295 | ir->gpio_addr = MO_GP1_IO; |
| 296 | ir->mask_keycode = 0x0e; |
| 297 | ir->mask_keyup = 0x80; |
| 298 | ir->polling = 50; /* ms */ |
| 299 | break; |
Ricardo Cerqueira | be4f451 | 2006-06-08 17:36:17 -0300 | [diff] [blame] | 300 | case CX88_BOARD_NPGTECH_REALTV_TOP10FM: |
Ricardo Cerqueira | 680543c | 2006-05-22 07:44:02 -0300 | [diff] [blame] | 301 | ir_codes = ir_codes_npgtech; |
| 302 | ir->gpio_addr = MO_GP0_IO; |
| 303 | ir->mask_keycode = 0xfa; |
| 304 | ir->polling = 50; /* ms */ |
| 305 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | } |
Mauro Carvalho Chehab | b45009b | 2005-06-23 22:05:03 -0700 | [diff] [blame] | 307 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | if (NULL == ir_codes) { |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 309 | err = -ENODEV; |
| 310 | goto err_out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | /* init input device */ |
| 314 | snprintf(ir->name, sizeof(ir->name), "cx88 IR (%s)", |
| 315 | cx88_boards[core->board].name); |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 316 | snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0", pci_name(pci)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 318 | ir_input_init(input_dev, &ir->ir, ir_type, ir_codes); |
| 319 | input_dev->name = ir->name; |
| 320 | input_dev->phys = ir->phys; |
| 321 | input_dev->id.bustype = BUS_PCI; |
| 322 | input_dev->id.version = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | if (pci->subsystem_vendor) { |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 324 | input_dev->id.vendor = pci->subsystem_vendor; |
| 325 | input_dev->id.product = pci->subsystem_device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | } else { |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 327 | input_dev->id.vendor = pci->vendor; |
| 328 | input_dev->id.product = pci->device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | } |
Dmitry Torokhov | 2c8a3a3 | 2007-07-16 09:28:15 -0300 | [diff] [blame] | 330 | input_dev->dev.parent = &pci->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | /* record handles to ourself */ |
| 332 | ir->core = core; |
| 333 | core->ir = ir; |
| 334 | |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 335 | cx88_ir_start(core, ir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | |
| 337 | /* all done */ |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 338 | err = input_register_device(ir->input); |
| 339 | if (err) |
| 340 | goto err_out_stop; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | |
| 342 | return 0; |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 343 | |
| 344 | err_out_stop: |
| 345 | cx88_ir_stop(core, ir); |
| 346 | core->ir = NULL; |
| 347 | err_out_free: |
| 348 | input_free_device(input_dev); |
| 349 | kfree(ir); |
| 350 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | int cx88_ir_fini(struct cx88_core *core) |
| 354 | { |
| 355 | struct cx88_IR *ir = core->ir; |
| 356 | |
| 357 | /* skip detach on non attached boards */ |
| 358 | if (NULL == ir) |
| 359 | return 0; |
| 360 | |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 361 | cx88_ir_stop(core, ir); |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 362 | input_unregister_device(ir->input); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | kfree(ir); |
| 364 | |
| 365 | /* done */ |
| 366 | core->ir = NULL; |
| 367 | return 0; |
| 368 | } |
| 369 | |
| 370 | /* ---------------------------------------------------------------------- */ |
| 371 | |
| 372 | void cx88_ir_irq(struct cx88_core *core) |
| 373 | { |
| 374 | struct cx88_IR *ir = core->ir; |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 375 | u32 samples, ircode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | int i; |
| 377 | |
| 378 | if (NULL == ir) |
| 379 | return; |
| 380 | if (!ir->sampling) |
| 381 | return; |
| 382 | |
| 383 | samples = cx_read(MO_SAMPLE_IO); |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 384 | if (0 != samples && 0xffffffff != samples) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | /* record sample data */ |
| 386 | if (ir->scount < ARRAY_SIZE(ir->samples)) |
| 387 | ir->samples[ir->scount++] = samples; |
| 388 | return; |
| 389 | } |
| 390 | if (!ir->scount) { |
| 391 | /* nothing to sample */ |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 392 | if (ir->ir.keypressed && time_after(jiffies, ir->release)) |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 393 | ir_input_nokey(ir->input, &ir->ir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | return; |
| 395 | } |
| 396 | |
| 397 | /* have a complete sample */ |
| 398 | if (ir->scount < ARRAY_SIZE(ir->samples)) |
| 399 | ir->samples[ir->scount++] = samples; |
| 400 | for (i = 0; i < ir->scount; i++) |
| 401 | ir->samples[i] = ~ir->samples[i]; |
| 402 | if (ir_debug) |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 403 | ir_dump_samples(ir->samples, ir->scount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | |
| 405 | /* decode it */ |
| 406 | switch (core->board) { |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 407 | case CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1: |
Chris Pascoe | fc40b26 | 2006-01-09 15:25:35 -0200 | [diff] [blame] | 408 | case CX88_BOARD_DNTV_LIVE_DVB_T_PRO: |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 409 | ircode = ir_decode_pulsedistance(ir->samples, ir->scount, 1, 4); |
| 410 | |
| 411 | if (ircode == 0xffffffff) { /* decoding error */ |
| 412 | ir_dprintk("pulse distance decoding error\n"); |
| 413 | break; |
| 414 | } |
| 415 | |
| 416 | ir_dprintk("pulse distance decoded: %x\n", ircode); |
| 417 | |
| 418 | if (ircode == 0) { /* key still pressed */ |
| 419 | ir_dprintk("pulse distance decoded repeat code\n"); |
| 420 | ir->release = jiffies + msecs_to_jiffies(120); |
| 421 | break; |
| 422 | } |
| 423 | |
Chris Pascoe | fc40b26 | 2006-01-09 15:25:35 -0200 | [diff] [blame] | 424 | if ((ircode & 0xffff) != (ir->sampling & 0xffff)) { /* wrong address */ |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 425 | ir_dprintk("pulse distance decoded wrong address\n"); |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 426 | break; |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | if (((~ircode >> 24) & 0xff) != ((ircode >> 16) & 0xff)) { /* wrong checksum */ |
| 430 | ir_dprintk("pulse distance decoded wrong check sum\n"); |
| 431 | break; |
| 432 | } |
| 433 | |
| 434 | ir_dprintk("Key Code: %x\n", (ircode >> 16) & 0x7f); |
| 435 | |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 436 | ir_input_keydown(ir->input, &ir->ir, (ircode >> 16) & 0x7f, (ircode >> 16) & 0xff); |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 437 | ir->release = jiffies + msecs_to_jiffies(120); |
| 438 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | case CX88_BOARD_HAUPPAUGE: |
| 440 | case CX88_BOARD_HAUPPAUGE_DVB_T1: |
Steven Toth | fb56cb6 | 2006-01-09 15:25:02 -0200 | [diff] [blame] | 441 | case CX88_BOARD_HAUPPAUGE_NOVASE2_S1: |
| 442 | case CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1: |
Chris Pascoe | 30367bf | 2006-01-11 19:40:01 -0200 | [diff] [blame] | 443 | case CX88_BOARD_HAUPPAUGE_HVR1100: |
Steven Toth | 76dc82a | 2006-09-30 00:43:58 -0300 | [diff] [blame] | 444 | case CX88_BOARD_HAUPPAUGE_HVR3000: |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 445 | ircode = ir_decode_biphase(ir->samples, ir->scount, 5, 7); |
| 446 | ir_dprintk("biphase decoded: %x\n", ircode); |
| 447 | if ((ircode & 0xfffff000) != 0x3000) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | break; |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 449 | ir_input_keydown(ir->input, &ir->ir, ircode & 0x3f, ircode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | ir->release = jiffies + msecs_to_jiffies(120); |
| 451 | break; |
| 452 | } |
| 453 | |
| 454 | ir->scount = 0; |
| 455 | return; |
| 456 | } |
| 457 | |
| 458 | /* ---------------------------------------------------------------------- */ |
| 459 | |
| 460 | MODULE_AUTHOR("Gerd Knorr, Pavel Machek, Chris Pascoe"); |
| 461 | MODULE_DESCRIPTION("input driver for cx88 GPIO-based IR remote controls"); |
| 462 | MODULE_LICENSE("GPL"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | /* |
| 464 | * Local variables: |
| 465 | * c-basic-offset: 8 |
| 466 | * End: |
| 467 | */ |