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. |
| 31 | * |
| 32 | * You should have received a copy of the GNU General Public License |
| 33 | * along with this program; if not, write to the Free Software |
| 34 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 35 | * 02110-1301, USA. |
| 36 | */ |
| 37 | |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 38 | #include <linux/slab.h> |
Mauro Carvalho Chehab | 6bda964 | 2010-11-17 13:28:38 -0300 | [diff] [blame] | 39 | #include <media/rc-core.h> |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 40 | #include <media/v4l2-subdev.h> |
| 41 | |
| 42 | #include "cx23885.h" |
| 43 | |
Mauro Carvalho Chehab | 727e625 | 2010-03-12 21:18:14 -0300 | [diff] [blame] | 44 | #define MODULE_NAME "cx23885" |
| 45 | |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 46 | static void cx23885_input_process_measurements(struct cx23885_dev *dev, |
| 47 | bool overrun) |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 48 | { |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 49 | struct cx23885_kernel_ir *kernel_ir = dev->kernel_ir; |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 50 | |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 51 | ssize_t num; |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 52 | int count, i; |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 53 | bool handle = false; |
Andy Walls | c02e0d1 | 2010-08-01 02:18:13 -0300 | [diff] [blame] | 54 | struct ir_raw_event ir_core_event[64]; |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 55 | |
| 56 | do { |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 57 | num = 0; |
Andy Walls | c02e0d1 | 2010-08-01 02:18:13 -0300 | [diff] [blame] | 58 | v4l2_subdev_call(dev->sd_ir, ir, rx_read, (u8 *) ir_core_event, |
| 59 | sizeof(ir_core_event), &num); |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 60 | |
Andy Walls | c02e0d1 | 2010-08-01 02:18:13 -0300 | [diff] [blame] | 61 | count = num / sizeof(struct ir_raw_event); |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 62 | |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 63 | for (i = 0; i < count; i++) { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 64 | ir_raw_event_store(kernel_ir->rc, |
Andy Walls | c02e0d1 | 2010-08-01 02:18:13 -0300 | [diff] [blame] | 65 | &ir_core_event[i]); |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 66 | handle = true; |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 67 | } |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 68 | } while (num != 0); |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 69 | |
| 70 | if (overrun) |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 71 | ir_raw_event_reset(kernel_ir->rc); |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 72 | else if (handle) |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 73 | ir_raw_event_handle(kernel_ir->rc); |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | void cx23885_input_rx_work_handler(struct cx23885_dev *dev, u32 events) |
| 77 | { |
| 78 | struct v4l2_subdev_ir_parameters params; |
| 79 | int overrun, data_available; |
| 80 | |
| 81 | if (dev->sd_ir == NULL || events == 0) |
| 82 | return; |
| 83 | |
| 84 | switch (dev->board) { |
| 85 | case CX23885_BOARD_HAUPPAUGE_HVR1850: |
Michael Krufky | 7fec6fe | 2009-11-11 15:46:09 -0300 | [diff] [blame] | 86 | case CX23885_BOARD_HAUPPAUGE_HVR1290: |
Andy Walls | 98d109f | 2010-07-19 00:41:41 -0300 | [diff] [blame] | 87 | case CX23885_BOARD_TEVII_S470: |
| 88 | case CX23885_BOARD_HAUPPAUGE_HVR1250: |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 89 | /* |
Andy Walls | 98d109f | 2010-07-19 00:41:41 -0300 | [diff] [blame] | 90 | * The only boards we handle right now. However other boards |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 91 | * using the CX2388x integrated IR controller should be similar |
| 92 | */ |
| 93 | break; |
| 94 | default: |
| 95 | return; |
| 96 | } |
| 97 | |
| 98 | overrun = events & (V4L2_SUBDEV_IR_RX_SW_FIFO_OVERRUN | |
| 99 | V4L2_SUBDEV_IR_RX_HW_FIFO_OVERRUN); |
| 100 | |
| 101 | data_available = events & (V4L2_SUBDEV_IR_RX_END_OF_RX_DETECTED | |
| 102 | V4L2_SUBDEV_IR_RX_FIFO_SERVICE_REQ); |
| 103 | |
| 104 | if (overrun) { |
| 105 | /* If there was a FIFO overrun, stop the device */ |
| 106 | v4l2_subdev_call(dev->sd_ir, ir, rx_g_parameters, ¶ms); |
| 107 | params.enable = false; |
| 108 | /* Mitigate race with cx23885_input_ir_stop() */ |
| 109 | params.shutdown = atomic_read(&dev->ir_input_stopping); |
| 110 | v4l2_subdev_call(dev->sd_ir, ir, rx_s_parameters, ¶ms); |
| 111 | } |
| 112 | |
| 113 | if (data_available) |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 114 | cx23885_input_process_measurements(dev, overrun); |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 115 | |
| 116 | if (overrun) { |
| 117 | /* If there was a FIFO overrun, clear & restart the device */ |
| 118 | params.enable = true; |
| 119 | /* Mitigate race with cx23885_input_ir_stop() */ |
| 120 | params.shutdown = atomic_read(&dev->ir_input_stopping); |
| 121 | v4l2_subdev_call(dev->sd_ir, ir, rx_s_parameters, ¶ms); |
| 122 | } |
| 123 | } |
| 124 | |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 125 | static int cx23885_input_ir_start(struct cx23885_dev *dev) |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 126 | { |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 127 | struct v4l2_subdev_ir_parameters params; |
| 128 | |
| 129 | if (dev->sd_ir == NULL) |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 130 | return -ENODEV; |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 131 | |
| 132 | atomic_set(&dev->ir_input_stopping, 0); |
| 133 | |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 134 | v4l2_subdev_call(dev->sd_ir, ir, rx_g_parameters, ¶ms); |
| 135 | switch (dev->board) { |
| 136 | case CX23885_BOARD_HAUPPAUGE_HVR1850: |
Michael Krufky | 7fec6fe | 2009-11-11 15:46:09 -0300 | [diff] [blame] | 137 | case CX23885_BOARD_HAUPPAUGE_HVR1290: |
Andy Walls | 98d109f | 2010-07-19 00:41:41 -0300 | [diff] [blame] | 138 | case CX23885_BOARD_HAUPPAUGE_HVR1250: |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 139 | /* |
| 140 | * The IR controller on this board only returns pulse widths. |
| 141 | * Any other mode setting will fail to set up the device. |
| 142 | */ |
| 143 | params.mode = V4L2_SUBDEV_IR_MODE_PULSE_WIDTH; |
| 144 | params.enable = true; |
| 145 | params.interrupt_enable = true; |
| 146 | params.shutdown = false; |
| 147 | |
| 148 | /* Setup for baseband compatible with both RC-5 and RC-6A */ |
| 149 | params.modulation = false; |
| 150 | /* RC-5: 2,222,222 ns = 1/36 kHz * 32 cycles * 2 marks * 1.25*/ |
| 151 | /* RC-6A: 3,333,333 ns = 1/36 kHz * 16 cycles * 6 marks * 1.25*/ |
| 152 | params.max_pulse_width = 3333333; /* ns */ |
| 153 | /* RC-5: 666,667 ns = 1/36 kHz * 32 cycles * 1 mark * 0.75 */ |
| 154 | /* RC-6A: 333,333 ns = 1/36 kHz * 16 cycles * 1 mark * 0.75 */ |
| 155 | params.noise_filter_min_width = 333333; /* ns */ |
| 156 | /* |
| 157 | * This board has inverted receive sense: |
| 158 | * mark is received as low logic level; |
| 159 | * falling edges are detected as rising edges; etc. |
| 160 | */ |
Andy Walls | 5a28d9a | 2010-07-18 19:57:25 -0300 | [diff] [blame] | 161 | params.invert_level = true; |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 162 | break; |
Andy Walls | 98d109f | 2010-07-19 00:41:41 -0300 | [diff] [blame] | 163 | case CX23885_BOARD_TEVII_S470: |
| 164 | /* |
| 165 | * The IR controller on this board only returns pulse widths. |
| 166 | * Any other mode setting will fail to set up the device. |
| 167 | */ |
| 168 | params.mode = V4L2_SUBDEV_IR_MODE_PULSE_WIDTH; |
| 169 | params.enable = true; |
| 170 | params.interrupt_enable = true; |
| 171 | params.shutdown = false; |
| 172 | |
| 173 | /* Setup for a standard NEC protocol */ |
| 174 | params.carrier_freq = 37917; /* Hz, 455 kHz/12 for NEC */ |
| 175 | params.carrier_range_lower = 33000; /* Hz */ |
| 176 | params.carrier_range_upper = 43000; /* Hz */ |
| 177 | params.duty_cycle = 33; /* percent, 33 percent for NEC */ |
| 178 | |
| 179 | /* |
| 180 | * NEC max pulse width: (64/3)/(455 kHz/12) * 16 nec_units |
| 181 | * (64/3)/(455 kHz/12) * 16 nec_units * 1.375 = 12378022 ns |
| 182 | */ |
| 183 | params.max_pulse_width = 12378022; /* ns */ |
| 184 | |
| 185 | /* |
| 186 | * NEC noise filter min width: (64/3)/(455 kHz/12) * 1 nec_unit |
| 187 | * (64/3)/(455 kHz/12) * 1 nec_units * 0.625 = 351648 ns |
| 188 | */ |
| 189 | params.noise_filter_min_width = 351648; /* ns */ |
| 190 | |
| 191 | params.modulation = false; |
| 192 | params.invert_level = true; |
| 193 | break; |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 194 | } |
| 195 | v4l2_subdev_call(dev->sd_ir, ir, rx_s_parameters, ¶ms); |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 196 | return 0; |
| 197 | } |
| 198 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 199 | static int cx23885_input_ir_open(struct rc_dev *rc) |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 200 | { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 201 | struct cx23885_kernel_ir *kernel_ir = rc->priv; |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 202 | |
| 203 | if (kernel_ir->cx == NULL) |
| 204 | return -ENODEV; |
| 205 | |
| 206 | return cx23885_input_ir_start(kernel_ir->cx); |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | static void cx23885_input_ir_stop(struct cx23885_dev *dev) |
| 210 | { |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 211 | struct v4l2_subdev_ir_parameters params; |
| 212 | |
| 213 | if (dev->sd_ir == NULL) |
| 214 | return; |
| 215 | |
| 216 | /* |
| 217 | * Stop the sd_ir subdevice from generating notifications and |
| 218 | * scheduling work. |
| 219 | * It is shutdown this way in order to mitigate a race with |
| 220 | * cx23885_input_rx_work_handler() in the overrun case, which could |
| 221 | * re-enable the subdevice. |
| 222 | */ |
| 223 | atomic_set(&dev->ir_input_stopping, 1); |
| 224 | v4l2_subdev_call(dev->sd_ir, ir, rx_g_parameters, ¶ms); |
| 225 | while (params.shutdown == false) { |
| 226 | params.enable = false; |
| 227 | params.interrupt_enable = false; |
| 228 | params.shutdown = true; |
| 229 | v4l2_subdev_call(dev->sd_ir, ir, rx_s_parameters, ¶ms); |
| 230 | v4l2_subdev_call(dev->sd_ir, ir, rx_g_parameters, ¶ms); |
| 231 | } |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 232 | } |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 233 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 234 | static void cx23885_input_ir_close(struct rc_dev *rc) |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 235 | { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 236 | struct cx23885_kernel_ir *kernel_ir = rc->priv; |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 237 | |
| 238 | if (kernel_ir->cx != NULL) |
| 239 | cx23885_input_ir_stop(kernel_ir->cx); |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | int cx23885_input_init(struct cx23885_dev *dev) |
| 243 | { |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 244 | struct cx23885_kernel_ir *kernel_ir; |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 245 | struct rc_dev *rc; |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 246 | char *rc_map; |
| 247 | enum rc_driver_type driver_type; |
| 248 | unsigned long allowed_protos; |
| 249 | |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 250 | int ret; |
| 251 | |
| 252 | /* |
| 253 | * If the IR device (hardware registers, chip, GPIO lines, etc.) isn't |
| 254 | * encapsulated in a v4l2_subdev, then I'm not going to deal with it. |
| 255 | */ |
| 256 | if (dev->sd_ir == NULL) |
| 257 | return -ENODEV; |
| 258 | |
| 259 | switch (dev->board) { |
| 260 | case CX23885_BOARD_HAUPPAUGE_HVR1850: |
Michael Krufky | 7fec6fe | 2009-11-11 15:46:09 -0300 | [diff] [blame] | 261 | case CX23885_BOARD_HAUPPAUGE_HVR1290: |
Andy Walls | 98d109f | 2010-07-19 00:41:41 -0300 | [diff] [blame] | 262 | case CX23885_BOARD_HAUPPAUGE_HVR1250: |
| 263 | /* Integrated CX2388[58] IR controller */ |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 264 | driver_type = RC_DRIVER_IR_RAW; |
Mauro Carvalho Chehab | 52b6614 | 2010-11-17 14:20:52 -0300 | [diff] [blame] | 265 | allowed_protos = RC_TYPE_ALL; |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 266 | /* The grey Hauppauge RC-5 remote */ |
Mauro Carvalho Chehab | 15195d3 | 2011-01-24 12:18:47 -0300 | [diff] [blame^] | 267 | rc_map = RC_MAP_HAUPPAUGE; |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 268 | break; |
Andy Walls | 98d109f | 2010-07-19 00:41:41 -0300 | [diff] [blame] | 269 | case CX23885_BOARD_TEVII_S470: |
| 270 | /* Integrated CX23885 IR controller */ |
| 271 | driver_type = RC_DRIVER_IR_RAW; |
Mauro Carvalho Chehab | 52b6614 | 2010-11-17 14:20:52 -0300 | [diff] [blame] | 272 | allowed_protos = RC_TYPE_ALL; |
Andy Walls | 98d109f | 2010-07-19 00:41:41 -0300 | [diff] [blame] | 273 | /* A guess at the remote */ |
| 274 | rc_map = RC_MAP_TEVII_NEC; |
| 275 | break; |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 276 | default: |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 277 | return -ENODEV; |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 278 | } |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 279 | |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 280 | /* cx23885 board instance kernel IR state */ |
| 281 | kernel_ir = kzalloc(sizeof(struct cx23885_kernel_ir), GFP_KERNEL); |
| 282 | if (kernel_ir == NULL) |
| 283 | return -ENOMEM; |
| 284 | |
| 285 | kernel_ir->cx = dev; |
| 286 | kernel_ir->name = kasprintf(GFP_KERNEL, "cx23885 IR (%s)", |
| 287 | cx23885_boards[dev->board].name); |
| 288 | kernel_ir->phys = kasprintf(GFP_KERNEL, "pci-%s/ir0", |
| 289 | pci_name(dev->pci)); |
| 290 | |
| 291 | /* input device */ |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 292 | rc = rc_allocate_device(); |
| 293 | if (!rc) { |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 294 | ret = -ENOMEM; |
| 295 | goto err_out_free; |
| 296 | } |
| 297 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 298 | kernel_ir->rc = rc; |
| 299 | rc->input_name = kernel_ir->name; |
| 300 | rc->input_phys = kernel_ir->phys; |
| 301 | rc->input_id.bustype = BUS_PCI; |
| 302 | rc->input_id.version = 1; |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 303 | if (dev->pci->subsystem_vendor) { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 304 | rc->input_id.vendor = dev->pci->subsystem_vendor; |
| 305 | rc->input_id.product = dev->pci->subsystem_device; |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 306 | } else { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 307 | rc->input_id.vendor = dev->pci->vendor; |
| 308 | rc->input_id.product = dev->pci->device; |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 309 | } |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 310 | rc->dev.parent = &dev->pci->dev; |
| 311 | rc->driver_type = driver_type; |
| 312 | rc->allowed_protos = allowed_protos; |
| 313 | rc->priv = kernel_ir; |
| 314 | rc->open = cx23885_input_ir_open; |
| 315 | rc->close = cx23885_input_ir_close; |
| 316 | rc->map_name = rc_map; |
| 317 | rc->driver_name = MODULE_NAME; |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 318 | |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 319 | /* Go */ |
| 320 | dev->kernel_ir = kernel_ir; |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 321 | ret = rc_register_device(rc); |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 322 | if (ret) |
| 323 | goto err_out_stop; |
| 324 | |
| 325 | return 0; |
| 326 | |
| 327 | err_out_stop: |
| 328 | cx23885_input_ir_stop(dev); |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 329 | dev->kernel_ir = NULL; |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 330 | rc_free_device(rc); |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 331 | err_out_free: |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 332 | kfree(kernel_ir->phys); |
| 333 | kfree(kernel_ir->name); |
| 334 | kfree(kernel_ir); |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 335 | return ret; |
| 336 | } |
| 337 | |
| 338 | void cx23885_input_fini(struct cx23885_dev *dev) |
| 339 | { |
| 340 | /* Always stop the IR hardware from generating interrupts */ |
| 341 | cx23885_input_ir_stop(dev); |
| 342 | |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 343 | if (dev->kernel_ir == NULL) |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 344 | return; |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 345 | rc_unregister_device(dev->kernel_ir->rc); |
Andy Walls | 43c2407 | 2010-06-27 23:15:35 -0300 | [diff] [blame] | 346 | kfree(dev->kernel_ir->phys); |
| 347 | kfree(dev->kernel_ir->name); |
| 348 | kfree(dev->kernel_ir); |
| 349 | dev->kernel_ir = NULL; |
Andy Walls | dbda8f7 | 2009-09-27 20:55:41 -0300 | [diff] [blame] | 350 | } |