Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Driver for the Conexant CX23885/7/8 PCIe bridge |
| 3 | * |
| 4 | * Infrared remote control input device |
| 5 | * |
| 6 | * Most of this file is |
| 7 | * |
Andy Walls | 6afdeaf | 2010-05-23 18:53:35 -0300 | [diff] [blame] | 8 | * Copyright (C) 2009 Andy Walls <awalls@md.metrocast.net> |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 9 | * |
| 10 | * However, the cx23885_input_{init,fini} functions contained herein are |
| 11 | * derived from Linux kernel files linux/media/video/.../...-input.c marked as: |
| 12 | * |
| 13 | * Copyright (C) 2008 <srinivasa.deevi at conexant dot com> |
| 14 | * Copyright (C) 2005 Ludovico Cavedon <cavedon@sssup.it> |
| 15 | * Markus Rechberger <mrechberger@gmail.com> |
| 16 | * Mauro Carvalho Chehab <mchehab@infradead.org> |
| 17 | * Sascha Sommer <saschasommer@freenet.de> |
| 18 | * Copyright (C) 2004, 2005 Chris Pascoe |
| 19 | * Copyright (C) 2003, 2004 Gerd Knorr |
| 20 | * Copyright (C) 2003 Pavel Machek |
| 21 | * |
| 22 | * This program is free software; you can redistribute it and/or |
| 23 | * modify it under the terms of the GNU General Public License |
| 24 | * as published by the Free Software Foundation; either version 2 |
| 25 | * of the License, or (at your option) any later version. |
| 26 | * |
| 27 | * This program is distributed in the hope that it will be useful, |
| 28 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 29 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 30 | * GNU General Public License for more details. |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 31 | */ |
| 32 | |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 33 | #include <linux/slab.h> |
Mauro Carvalho Chehab | 6bda964 | 2010-11-17 13:28:38 -0300 | [diff] [blame] | 34 | #include <media/rc-core.h> |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 35 | #include <media/v4l2-subdev.h> |
| 36 | |
| 37 | #include "cx23885.h" |
Mauro Carvalho Chehab | ada73ee | 2012-10-27 11:29:23 -0300 | [diff] [blame] | 38 | #include "cx23885-input.h" |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 39 | |
Mauro Carvalho Chehab | 727e625 | 2010-03-12 21:18:14 -0300 | [diff] [blame] | 40 | #define MODULE_NAME "cx23885" |
| 41 | |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 42 | static void cx23885_input_process_measurements(struct cx23885_dev *dev, |
| 43 | bool overrun) |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 44 | { |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 45 | struct cx23885_kernel_ir *kernel_ir = dev->kernel_ir; |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 46 | |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 47 | ssize_t num; |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 48 | int count, i; |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 49 | bool handle = false; |
Andy Walls | c02e0d1 | 2010-08-01 02:18:13 -0300 | [diff] [blame] | 50 | struct ir_raw_event ir_core_event[64]; |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 51 | |
| 52 | do { |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 53 | num = 0; |
Andy Walls | c02e0d1 | 2010-08-01 02:18:13 -0300 | [diff] [blame] | 54 | v4l2_subdev_call(dev->sd_ir, ir, rx_read, (u8 *) ir_core_event, |
| 55 | sizeof(ir_core_event), &num); |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 56 | |
Andy Walls | c02e0d1 | 2010-08-01 02:18:13 -0300 | [diff] [blame] | 57 | count = num / sizeof(struct ir_raw_event); |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 58 | |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 59 | for (i = 0; i < count; i++) { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 60 | ir_raw_event_store(kernel_ir->rc, |
Andy Walls | c02e0d1 | 2010-08-01 02:18:13 -0300 | [diff] [blame] | 61 | &ir_core_event[i]); |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 62 | handle = true; |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 63 | } |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 64 | } while (num != 0); |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 65 | |
| 66 | if (overrun) |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 67 | ir_raw_event_reset(kernel_ir->rc); |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 68 | else if (handle) |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 69 | ir_raw_event_handle(kernel_ir->rc); |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | void cx23885_input_rx_work_handler(struct cx23885_dev *dev, u32 events) |
| 73 | { |
| 74 | struct v4l2_subdev_ir_parameters params; |
| 75 | int overrun, data_available; |
| 76 | |
| 77 | if (dev->sd_ir == NULL || events == 0) |
| 78 | return; |
| 79 | |
| 80 | switch (dev->board) { |
Andy Walls | 9b3d8ec | 2011-06-08 21:24:25 -0300 | [diff] [blame] | 81 | case CX23885_BOARD_HAUPPAUGE_HVR1270: |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 82 | case CX23885_BOARD_HAUPPAUGE_HVR1850: |
Michael Krufky | 7fec6fe | 2009-11-11 15:46:09 -0300 | [diff] [blame] | 83 | case CX23885_BOARD_HAUPPAUGE_HVR1290: |
Djuri Baars | 076f0e3 | 2012-07-28 09:01:38 -0300 | [diff] [blame] | 84 | case CX23885_BOARD_TERRATEC_CINERGY_T_PCIE_DUAL: |
Andy Walls | 98d109f | 2010-07-19 00:41:41 -0300 | [diff] [blame] | 85 | case CX23885_BOARD_TEVII_S470: |
| 86 | case CX23885_BOARD_HAUPPAUGE_HVR1250: |
Alfredo Jesús Delaiti | e5f670b | 2012-11-08 15:50:25 -0300 | [diff] [blame] | 87 | case CX23885_BOARD_MYGICA_X8507: |
Luis Alves | e600148 | 2013-10-01 22:11:35 -0300 | [diff] [blame] | 88 | case CX23885_BOARD_TBS_6980: |
| 89 | case CX23885_BOARD_TBS_6981: |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 90 | /* |
Andy Walls | 98d109f | 2010-07-19 00:41:41 -0300 | [diff] [blame] | 91 | * The only boards we handle right now. However other boards |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 92 | * using the CX2388x integrated IR controller should be similar |
| 93 | */ |
| 94 | break; |
| 95 | default: |
| 96 | return; |
| 97 | } |
| 98 | |
| 99 | overrun = events & (V4L2_SUBDEV_IR_RX_SW_FIFO_OVERRUN | |
| 100 | V4L2_SUBDEV_IR_RX_HW_FIFO_OVERRUN); |
| 101 | |
| 102 | data_available = events & (V4L2_SUBDEV_IR_RX_END_OF_RX_DETECTED | |
| 103 | V4L2_SUBDEV_IR_RX_FIFO_SERVICE_REQ); |
| 104 | |
| 105 | if (overrun) { |
| 106 | /* If there was a FIFO overrun, stop the device */ |
| 107 | v4l2_subdev_call(dev->sd_ir, ir, rx_g_parameters, ¶ms); |
| 108 | params.enable = false; |
| 109 | /* Mitigate race with cx23885_input_ir_stop() */ |
| 110 | params.shutdown = atomic_read(&dev->ir_input_stopping); |
| 111 | v4l2_subdev_call(dev->sd_ir, ir, rx_s_parameters, ¶ms); |
| 112 | } |
| 113 | |
| 114 | if (data_available) |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 115 | cx23885_input_process_measurements(dev, overrun); |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 116 | |
| 117 | if (overrun) { |
| 118 | /* If there was a FIFO overrun, clear & restart the device */ |
| 119 | params.enable = true; |
| 120 | /* Mitigate race with cx23885_input_ir_stop() */ |
| 121 | params.shutdown = atomic_read(&dev->ir_input_stopping); |
| 122 | v4l2_subdev_call(dev->sd_ir, ir, rx_s_parameters, ¶ms); |
| 123 | } |
| 124 | } |
| 125 | |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 126 | static int cx23885_input_ir_start(struct cx23885_dev *dev) |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 127 | { |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 128 | struct v4l2_subdev_ir_parameters params; |
| 129 | |
| 130 | if (dev->sd_ir == NULL) |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 131 | return -ENODEV; |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 132 | |
| 133 | atomic_set(&dev->ir_input_stopping, 0); |
| 134 | |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 135 | v4l2_subdev_call(dev->sd_ir, ir, rx_g_parameters, ¶ms); |
| 136 | switch (dev->board) { |
Andy Walls | 9b3d8ec | 2011-06-08 21:24:25 -0300 | [diff] [blame] | 137 | case CX23885_BOARD_HAUPPAUGE_HVR1270: |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 138 | case CX23885_BOARD_HAUPPAUGE_HVR1850: |
Michael Krufky | 7fec6fe | 2009-11-11 15:46:09 -0300 | [diff] [blame] | 139 | case CX23885_BOARD_HAUPPAUGE_HVR1290: |
Andy Walls | 98d109f | 2010-07-19 00:41:41 -0300 | [diff] [blame] | 140 | case CX23885_BOARD_HAUPPAUGE_HVR1250: |
Alfredo Jesús Delaiti | e5f670b | 2012-11-08 15:50:25 -0300 | [diff] [blame] | 141 | case CX23885_BOARD_MYGICA_X8507: |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 142 | /* |
| 143 | * The IR controller on this board only returns pulse widths. |
| 144 | * Any other mode setting will fail to set up the device. |
| 145 | */ |
| 146 | params.mode = V4L2_SUBDEV_IR_MODE_PULSE_WIDTH; |
| 147 | params.enable = true; |
| 148 | params.interrupt_enable = true; |
| 149 | params.shutdown = false; |
| 150 | |
| 151 | /* Setup for baseband compatible with both RC-5 and RC-6A */ |
| 152 | params.modulation = false; |
| 153 | /* RC-5: 2,222,222 ns = 1/36 kHz * 32 cycles * 2 marks * 1.25*/ |
| 154 | /* RC-6A: 3,333,333 ns = 1/36 kHz * 16 cycles * 6 marks * 1.25*/ |
| 155 | params.max_pulse_width = 3333333; /* ns */ |
| 156 | /* RC-5: 666,667 ns = 1/36 kHz * 32 cycles * 1 mark * 0.75 */ |
| 157 | /* RC-6A: 333,333 ns = 1/36 kHz * 16 cycles * 1 mark * 0.75 */ |
| 158 | params.noise_filter_min_width = 333333; /* ns */ |
| 159 | /* |
| 160 | * This board has inverted receive sense: |
| 161 | * mark is received as low logic level; |
| 162 | * falling edges are detected as rising edges; etc. |
| 163 | */ |
Andy Walls | 5a28d9a | 2010-07-18 19:57:25 -0300 | [diff] [blame] | 164 | params.invert_level = true; |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 165 | break; |
Djuri Baars | 076f0e3 | 2012-07-28 09:01:38 -0300 | [diff] [blame] | 166 | case CX23885_BOARD_TERRATEC_CINERGY_T_PCIE_DUAL: |
Andy Walls | 98d109f | 2010-07-19 00:41:41 -0300 | [diff] [blame] | 167 | case CX23885_BOARD_TEVII_S470: |
Luis Alves | e600148 | 2013-10-01 22:11:35 -0300 | [diff] [blame] | 168 | case CX23885_BOARD_TBS_6980: |
| 169 | case CX23885_BOARD_TBS_6981: |
Andy Walls | 98d109f | 2010-07-19 00:41:41 -0300 | [diff] [blame] | 170 | /* |
| 171 | * The IR controller on this board only returns pulse widths. |
| 172 | * Any other mode setting will fail to set up the device. |
| 173 | */ |
| 174 | params.mode = V4L2_SUBDEV_IR_MODE_PULSE_WIDTH; |
| 175 | params.enable = true; |
| 176 | params.interrupt_enable = true; |
| 177 | params.shutdown = false; |
| 178 | |
| 179 | /* Setup for a standard NEC protocol */ |
| 180 | params.carrier_freq = 37917; /* Hz, 455 kHz/12 for NEC */ |
| 181 | params.carrier_range_lower = 33000; /* Hz */ |
| 182 | params.carrier_range_upper = 43000; /* Hz */ |
| 183 | params.duty_cycle = 33; /* percent, 33 percent for NEC */ |
| 184 | |
| 185 | /* |
| 186 | * NEC max pulse width: (64/3)/(455 kHz/12) * 16 nec_units |
| 187 | * (64/3)/(455 kHz/12) * 16 nec_units * 1.375 = 12378022 ns |
| 188 | */ |
| 189 | params.max_pulse_width = 12378022; /* ns */ |
| 190 | |
| 191 | /* |
| 192 | * NEC noise filter min width: (64/3)/(455 kHz/12) * 1 nec_unit |
| 193 | * (64/3)/(455 kHz/12) * 1 nec_units * 0.625 = 351648 ns |
| 194 | */ |
| 195 | params.noise_filter_min_width = 351648; /* ns */ |
| 196 | |
| 197 | params.modulation = false; |
| 198 | params.invert_level = true; |
| 199 | break; |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 200 | } |
| 201 | v4l2_subdev_call(dev->sd_ir, ir, rx_s_parameters, ¶ms); |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 202 | return 0; |
| 203 | } |
| 204 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 205 | static int cx23885_input_ir_open(struct rc_dev *rc) |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 206 | { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 207 | struct cx23885_kernel_ir *kernel_ir = rc->priv; |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 208 | |
| 209 | if (kernel_ir->cx == NULL) |
| 210 | return -ENODEV; |
| 211 | |
| 212 | return cx23885_input_ir_start(kernel_ir->cx); |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | static void cx23885_input_ir_stop(struct cx23885_dev *dev) |
| 216 | { |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 217 | struct v4l2_subdev_ir_parameters params; |
| 218 | |
| 219 | if (dev->sd_ir == NULL) |
| 220 | return; |
| 221 | |
| 222 | /* |
| 223 | * Stop the sd_ir subdevice from generating notifications and |
| 224 | * scheduling work. |
| 225 | * It is shutdown this way in order to mitigate a race with |
| 226 | * cx23885_input_rx_work_handler() in the overrun case, which could |
| 227 | * re-enable the subdevice. |
| 228 | */ |
| 229 | atomic_set(&dev->ir_input_stopping, 1); |
| 230 | v4l2_subdev_call(dev->sd_ir, ir, rx_g_parameters, ¶ms); |
| 231 | while (params.shutdown == false) { |
| 232 | params.enable = false; |
| 233 | params.interrupt_enable = false; |
| 234 | params.shutdown = true; |
| 235 | v4l2_subdev_call(dev->sd_ir, ir, rx_s_parameters, ¶ms); |
| 236 | v4l2_subdev_call(dev->sd_ir, ir, rx_g_parameters, ¶ms); |
| 237 | } |
Linus Torvalds | 0b8e74c | 2012-10-07 17:49:05 +0900 | [diff] [blame] | 238 | flush_work(&dev->cx25840_work); |
| 239 | flush_work(&dev->ir_rx_work); |
| 240 | flush_work(&dev->ir_tx_work); |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 241 | } |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 242 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 243 | static void cx23885_input_ir_close(struct rc_dev *rc) |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 244 | { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 245 | struct cx23885_kernel_ir *kernel_ir = rc->priv; |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 246 | |
| 247 | if (kernel_ir->cx != NULL) |
| 248 | cx23885_input_ir_stop(kernel_ir->cx); |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | int cx23885_input_init(struct cx23885_dev *dev) |
| 252 | { |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 253 | struct cx23885_kernel_ir *kernel_ir; |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 254 | struct rc_dev *rc; |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 255 | char *rc_map; |
| 256 | enum rc_driver_type driver_type; |
| 257 | unsigned long allowed_protos; |
| 258 | |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 259 | int ret; |
| 260 | |
| 261 | /* |
| 262 | * If the IR device (hardware registers, chip, GPIO lines, etc.) isn't |
| 263 | * encapsulated in a v4l2_subdev, then I'm not going to deal with it. |
| 264 | */ |
| 265 | if (dev->sd_ir == NULL) |
| 266 | return -ENODEV; |
| 267 | |
| 268 | switch (dev->board) { |
Andy Walls | 9b3d8ec | 2011-06-08 21:24:25 -0300 | [diff] [blame] | 269 | case CX23885_BOARD_HAUPPAUGE_HVR1270: |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 270 | case CX23885_BOARD_HAUPPAUGE_HVR1850: |
Michael Krufky | 7fec6fe | 2009-11-11 15:46:09 -0300 | [diff] [blame] | 271 | case CX23885_BOARD_HAUPPAUGE_HVR1290: |
Andy Walls | 98d109f | 2010-07-19 00:41:41 -0300 | [diff] [blame] | 272 | case CX23885_BOARD_HAUPPAUGE_HVR1250: |
| 273 | /* Integrated CX2388[58] IR controller */ |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 274 | driver_type = RC_DRIVER_IR_RAW; |
David Härdeman | c003ab1 | 2012-10-11 19:11:54 -0300 | [diff] [blame] | 275 | allowed_protos = RC_BIT_ALL; |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 276 | /* The grey Hauppauge RC-5 remote */ |
Mauro Carvalho Chehab | 15195d3 | 2011-01-24 12:18:47 -0300 | [diff] [blame] | 277 | rc_map = RC_MAP_HAUPPAUGE; |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 278 | break; |
Djuri Baars | 076f0e3 | 2012-07-28 09:01:38 -0300 | [diff] [blame] | 279 | case CX23885_BOARD_TERRATEC_CINERGY_T_PCIE_DUAL: |
| 280 | /* Integrated CX23885 IR controller */ |
| 281 | driver_type = RC_DRIVER_IR_RAW; |
David Härdeman | c003ab1 | 2012-10-11 19:11:54 -0300 | [diff] [blame] | 282 | allowed_protos = RC_BIT_NEC; |
Djuri Baars | 076f0e3 | 2012-07-28 09:01:38 -0300 | [diff] [blame] | 283 | /* The grey Terratec remote with orange buttons */ |
| 284 | rc_map = RC_MAP_NEC_TERRATEC_CINERGY_XS; |
| 285 | break; |
Andy Walls | 98d109f | 2010-07-19 00:41:41 -0300 | [diff] [blame] | 286 | case CX23885_BOARD_TEVII_S470: |
| 287 | /* Integrated CX23885 IR controller */ |
| 288 | driver_type = RC_DRIVER_IR_RAW; |
David Härdeman | c003ab1 | 2012-10-11 19:11:54 -0300 | [diff] [blame] | 289 | allowed_protos = RC_BIT_ALL; |
Andy Walls | 98d109f | 2010-07-19 00:41:41 -0300 | [diff] [blame] | 290 | /* A guess at the remote */ |
| 291 | rc_map = RC_MAP_TEVII_NEC; |
| 292 | break; |
Alfredo Jesús Delaiti | e5f670b | 2012-11-08 15:50:25 -0300 | [diff] [blame] | 293 | case CX23885_BOARD_MYGICA_X8507: |
| 294 | /* Integrated CX23885 IR controller */ |
| 295 | driver_type = RC_DRIVER_IR_RAW; |
| 296 | allowed_protos = RC_BIT_ALL; |
| 297 | /* A guess at the remote */ |
| 298 | rc_map = RC_MAP_TOTAL_MEDIA_IN_HAND_02; |
| 299 | break; |
Luis Alves | e600148 | 2013-10-01 22:11:35 -0300 | [diff] [blame] | 300 | case CX23885_BOARD_TBS_6980: |
| 301 | case CX23885_BOARD_TBS_6981: |
| 302 | /* Integrated CX23885 IR controller */ |
| 303 | driver_type = RC_DRIVER_IR_RAW; |
| 304 | allowed_protos = RC_BIT_ALL; |
| 305 | /* A guess at the remote */ |
| 306 | rc_map = RC_MAP_TBS_NEC; |
| 307 | break; |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 308 | default: |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 309 | return -ENODEV; |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 310 | } |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 311 | |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 312 | /* cx23885 board instance kernel IR state */ |
| 313 | kernel_ir = kzalloc(sizeof(struct cx23885_kernel_ir), GFP_KERNEL); |
| 314 | if (kernel_ir == NULL) |
| 315 | return -ENOMEM; |
| 316 | |
| 317 | kernel_ir->cx = dev; |
| 318 | kernel_ir->name = kasprintf(GFP_KERNEL, "cx23885 IR (%s)", |
| 319 | cx23885_boards[dev->board].name); |
| 320 | kernel_ir->phys = kasprintf(GFP_KERNEL, "pci-%s/ir0", |
| 321 | pci_name(dev->pci)); |
| 322 | |
| 323 | /* input device */ |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 324 | rc = rc_allocate_device(); |
| 325 | if (!rc) { |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 326 | ret = -ENOMEM; |
| 327 | goto err_out_free; |
| 328 | } |
| 329 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 330 | kernel_ir->rc = rc; |
| 331 | rc->input_name = kernel_ir->name; |
| 332 | rc->input_phys = kernel_ir->phys; |
| 333 | rc->input_id.bustype = BUS_PCI; |
| 334 | rc->input_id.version = 1; |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 335 | if (dev->pci->subsystem_vendor) { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 336 | rc->input_id.vendor = dev->pci->subsystem_vendor; |
| 337 | rc->input_id.product = dev->pci->subsystem_device; |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 338 | } else { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 339 | rc->input_id.vendor = dev->pci->vendor; |
| 340 | rc->input_id.product = dev->pci->device; |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 341 | } |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 342 | rc->dev.parent = &dev->pci->dev; |
| 343 | rc->driver_type = driver_type; |
David Härdeman | c5540fb | 2014-04-03 20:32:21 -0300 | [diff] [blame] | 344 | rc->allowed_protocols = allowed_protos; |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 345 | rc->priv = kernel_ir; |
| 346 | rc->open = cx23885_input_ir_open; |
| 347 | rc->close = cx23885_input_ir_close; |
| 348 | rc->map_name = rc_map; |
| 349 | rc->driver_name = MODULE_NAME; |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 350 | |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 351 | /* Go */ |
| 352 | dev->kernel_ir = kernel_ir; |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 353 | ret = rc_register_device(rc); |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 354 | if (ret) |
| 355 | goto err_out_stop; |
| 356 | |
| 357 | return 0; |
| 358 | |
| 359 | err_out_stop: |
| 360 | cx23885_input_ir_stop(dev); |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 361 | dev->kernel_ir = NULL; |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 362 | rc_free_device(rc); |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 363 | err_out_free: |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 364 | kfree(kernel_ir->phys); |
| 365 | kfree(kernel_ir->name); |
| 366 | kfree(kernel_ir); |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 367 | return ret; |
| 368 | } |
| 369 | |
| 370 | void cx23885_input_fini(struct cx23885_dev *dev) |
| 371 | { |
| 372 | /* Always stop the IR hardware from generating interrupts */ |
| 373 | cx23885_input_ir_stop(dev); |
| 374 | |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 375 | if (dev->kernel_ir == NULL) |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 376 | return; |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 377 | rc_unregister_device(dev->kernel_ir->rc); |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 378 | kfree(dev->kernel_ir->phys); |
| 379 | kfree(dev->kernel_ir->name); |
| 380 | kfree(dev->kernel_ir); |
| 381 | dev->kernel_ir = NULL; |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 382 | } |