blob: a1f4894443551e0e73b852912c1e28d6a700a3ff [file] [log] [blame]
Andy Wallsdbda8f72009-09-27 20:55:41 -03001/*
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 Walls6afdeaf2010-05-23 18:53:35 -03008 * Copyright (C) 2009 Andy Walls <awalls@md.metrocast.net>
Andy Wallsdbda8f72009-09-27 20:55:41 -03009 *
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 Wallsdbda8f72009-09-27 20:55:41 -030031 */
32
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090033#include <linux/slab.h>
Mauro Carvalho Chehab6bda9642010-11-17 13:28:38 -030034#include <media/rc-core.h>
Andy Wallsdbda8f72009-09-27 20:55:41 -030035#include <media/v4l2-subdev.h>
36
37#include "cx23885.h"
Mauro Carvalho Chehabada73ee2012-10-27 11:29:23 -030038#include "cx23885-input.h"
Andy Wallsdbda8f72009-09-27 20:55:41 -030039
Mauro Carvalho Chehab727e6252010-03-12 21:18:14 -030040#define MODULE_NAME "cx23885"
41
Andy Walls43c24072010-06-27 23:15:35 -030042static void cx23885_input_process_measurements(struct cx23885_dev *dev,
43 bool overrun)
Andy Wallsdbda8f72009-09-27 20:55:41 -030044{
Andy Walls43c24072010-06-27 23:15:35 -030045 struct cx23885_kernel_ir *kernel_ir = dev->kernel_ir;
Andy Wallsdbda8f72009-09-27 20:55:41 -030046
Andy Walls43c24072010-06-27 23:15:35 -030047 ssize_t num;
Andy Wallsdbda8f72009-09-27 20:55:41 -030048 int count, i;
Andy Walls43c24072010-06-27 23:15:35 -030049 bool handle = false;
Andy Wallsc02e0d12010-08-01 02:18:13 -030050 struct ir_raw_event ir_core_event[64];
Andy Wallsdbda8f72009-09-27 20:55:41 -030051
52 do {
Andy Walls43c24072010-06-27 23:15:35 -030053 num = 0;
Andy Wallsc02e0d12010-08-01 02:18:13 -030054 v4l2_subdev_call(dev->sd_ir, ir, rx_read, (u8 *) ir_core_event,
55 sizeof(ir_core_event), &num);
Andy Wallsdbda8f72009-09-27 20:55:41 -030056
Andy Wallsc02e0d12010-08-01 02:18:13 -030057 count = num / sizeof(struct ir_raw_event);
Andy Wallsdbda8f72009-09-27 20:55:41 -030058
Andy Walls43c24072010-06-27 23:15:35 -030059 for (i = 0; i < count; i++) {
David Härdemand8b4b582010-10-29 16:08:23 -030060 ir_raw_event_store(kernel_ir->rc,
Andy Wallsc02e0d12010-08-01 02:18:13 -030061 &ir_core_event[i]);
Andy Walls43c24072010-06-27 23:15:35 -030062 handle = true;
Andy Wallsdbda8f72009-09-27 20:55:41 -030063 }
Andy Wallsdbda8f72009-09-27 20:55:41 -030064 } while (num != 0);
Andy Walls43c24072010-06-27 23:15:35 -030065
66 if (overrun)
David Härdemand8b4b582010-10-29 16:08:23 -030067 ir_raw_event_reset(kernel_ir->rc);
Andy Walls43c24072010-06-27 23:15:35 -030068 else if (handle)
David Härdemand8b4b582010-10-29 16:08:23 -030069 ir_raw_event_handle(kernel_ir->rc);
Andy Wallsdbda8f72009-09-27 20:55:41 -030070}
71
72void 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 Walls9b3d8ec2011-06-08 21:24:25 -030081 case CX23885_BOARD_HAUPPAUGE_HVR1270:
Andy Wallsdbda8f72009-09-27 20:55:41 -030082 case CX23885_BOARD_HAUPPAUGE_HVR1850:
Michael Krufky7fec6fe2009-11-11 15:46:09 -030083 case CX23885_BOARD_HAUPPAUGE_HVR1290:
Djuri Baars076f0e32012-07-28 09:01:38 -030084 case CX23885_BOARD_TERRATEC_CINERGY_T_PCIE_DUAL:
Andy Walls98d109f2010-07-19 00:41:41 -030085 case CX23885_BOARD_TEVII_S470:
86 case CX23885_BOARD_HAUPPAUGE_HVR1250:
Alfredo Jesús Delaitie5f670b2012-11-08 15:50:25 -030087 case CX23885_BOARD_MYGICA_X8507:
Luis Alvese6001482013-10-01 22:11:35 -030088 case CX23885_BOARD_TBS_6980:
89 case CX23885_BOARD_TBS_6981:
nibble.maxd11a3832014-09-29 11:17:36 -030090 case CX23885_BOARD_DVBSKY_T9580:
nibble.max070e6662014-10-23 07:02:16 -030091 case CX23885_BOARD_DVBSKY_T980C:
92 case CX23885_BOARD_DVBSKY_S950C:
Olli Salonen61b103e2014-10-30 17:48:27 -030093 case CX23885_BOARD_TT_CT2_4500_CI:
nibble.maxcba54802014-11-05 11:58:07 -030094 case CX23885_BOARD_DVBSKY_S950:
nibble.maxc29d6a82014-11-05 11:58:38 -030095 case CX23885_BOARD_DVBSKY_S952:
Andy Wallsdbda8f72009-09-27 20:55:41 -030096 /*
Andy Walls98d109f2010-07-19 00:41:41 -030097 * The only boards we handle right now. However other boards
Andy Wallsdbda8f72009-09-27 20:55:41 -030098 * using the CX2388x integrated IR controller should be similar
99 */
100 break;
101 default:
102 return;
103 }
104
105 overrun = events & (V4L2_SUBDEV_IR_RX_SW_FIFO_OVERRUN |
106 V4L2_SUBDEV_IR_RX_HW_FIFO_OVERRUN);
107
108 data_available = events & (V4L2_SUBDEV_IR_RX_END_OF_RX_DETECTED |
109 V4L2_SUBDEV_IR_RX_FIFO_SERVICE_REQ);
110
111 if (overrun) {
112 /* If there was a FIFO overrun, stop the device */
113 v4l2_subdev_call(dev->sd_ir, ir, rx_g_parameters, &params);
114 params.enable = false;
115 /* Mitigate race with cx23885_input_ir_stop() */
116 params.shutdown = atomic_read(&dev->ir_input_stopping);
117 v4l2_subdev_call(dev->sd_ir, ir, rx_s_parameters, &params);
118 }
119
120 if (data_available)
Andy Walls43c24072010-06-27 23:15:35 -0300121 cx23885_input_process_measurements(dev, overrun);
Andy Wallsdbda8f72009-09-27 20:55:41 -0300122
123 if (overrun) {
124 /* If there was a FIFO overrun, clear & restart the device */
125 params.enable = true;
126 /* Mitigate race with cx23885_input_ir_stop() */
127 params.shutdown = atomic_read(&dev->ir_input_stopping);
128 v4l2_subdev_call(dev->sd_ir, ir, rx_s_parameters, &params);
129 }
130}
131
Andy Walls43c24072010-06-27 23:15:35 -0300132static int cx23885_input_ir_start(struct cx23885_dev *dev)
Andy Wallsdbda8f72009-09-27 20:55:41 -0300133{
Andy Wallsdbda8f72009-09-27 20:55:41 -0300134 struct v4l2_subdev_ir_parameters params;
135
136 if (dev->sd_ir == NULL)
Andy Walls43c24072010-06-27 23:15:35 -0300137 return -ENODEV;
Andy Wallsdbda8f72009-09-27 20:55:41 -0300138
139 atomic_set(&dev->ir_input_stopping, 0);
140
Andy Wallsdbda8f72009-09-27 20:55:41 -0300141 v4l2_subdev_call(dev->sd_ir, ir, rx_g_parameters, &params);
142 switch (dev->board) {
Andy Walls9b3d8ec2011-06-08 21:24:25 -0300143 case CX23885_BOARD_HAUPPAUGE_HVR1270:
Andy Wallsdbda8f72009-09-27 20:55:41 -0300144 case CX23885_BOARD_HAUPPAUGE_HVR1850:
Michael Krufky7fec6fe2009-11-11 15:46:09 -0300145 case CX23885_BOARD_HAUPPAUGE_HVR1290:
Andy Walls98d109f2010-07-19 00:41:41 -0300146 case CX23885_BOARD_HAUPPAUGE_HVR1250:
Alfredo Jesús Delaitie5f670b2012-11-08 15:50:25 -0300147 case CX23885_BOARD_MYGICA_X8507:
nibble.maxd11a3832014-09-29 11:17:36 -0300148 case CX23885_BOARD_DVBSKY_T9580:
nibble.max070e6662014-10-23 07:02:16 -0300149 case CX23885_BOARD_DVBSKY_T980C:
150 case CX23885_BOARD_DVBSKY_S950C:
Olli Salonen61b103e2014-10-30 17:48:27 -0300151 case CX23885_BOARD_TT_CT2_4500_CI:
nibble.maxcba54802014-11-05 11:58:07 -0300152 case CX23885_BOARD_DVBSKY_S950:
nibble.maxc29d6a82014-11-05 11:58:38 -0300153 case CX23885_BOARD_DVBSKY_S952:
Andy Wallsdbda8f72009-09-27 20:55:41 -0300154 /*
155 * The IR controller on this board only returns pulse widths.
156 * Any other mode setting will fail to set up the device.
157 */
158 params.mode = V4L2_SUBDEV_IR_MODE_PULSE_WIDTH;
159 params.enable = true;
160 params.interrupt_enable = true;
161 params.shutdown = false;
162
163 /* Setup for baseband compatible with both RC-5 and RC-6A */
164 params.modulation = false;
165 /* RC-5: 2,222,222 ns = 1/36 kHz * 32 cycles * 2 marks * 1.25*/
166 /* RC-6A: 3,333,333 ns = 1/36 kHz * 16 cycles * 6 marks * 1.25*/
167 params.max_pulse_width = 3333333; /* ns */
168 /* RC-5: 666,667 ns = 1/36 kHz * 32 cycles * 1 mark * 0.75 */
169 /* RC-6A: 333,333 ns = 1/36 kHz * 16 cycles * 1 mark * 0.75 */
170 params.noise_filter_min_width = 333333; /* ns */
171 /*
172 * This board has inverted receive sense:
173 * mark is received as low logic level;
174 * falling edges are detected as rising edges; etc.
175 */
Andy Walls5a28d9a2010-07-18 19:57:25 -0300176 params.invert_level = true;
Andy Wallsdbda8f72009-09-27 20:55:41 -0300177 break;
Djuri Baars076f0e32012-07-28 09:01:38 -0300178 case CX23885_BOARD_TERRATEC_CINERGY_T_PCIE_DUAL:
Andy Walls98d109f2010-07-19 00:41:41 -0300179 case CX23885_BOARD_TEVII_S470:
Luis Alvese6001482013-10-01 22:11:35 -0300180 case CX23885_BOARD_TBS_6980:
181 case CX23885_BOARD_TBS_6981:
Andy Walls98d109f2010-07-19 00:41:41 -0300182 /*
183 * The IR controller on this board only returns pulse widths.
184 * Any other mode setting will fail to set up the device.
185 */
186 params.mode = V4L2_SUBDEV_IR_MODE_PULSE_WIDTH;
187 params.enable = true;
188 params.interrupt_enable = true;
189 params.shutdown = false;
190
191 /* Setup for a standard NEC protocol */
192 params.carrier_freq = 37917; /* Hz, 455 kHz/12 for NEC */
193 params.carrier_range_lower = 33000; /* Hz */
194 params.carrier_range_upper = 43000; /* Hz */
195 params.duty_cycle = 33; /* percent, 33 percent for NEC */
196
197 /*
198 * NEC max pulse width: (64/3)/(455 kHz/12) * 16 nec_units
199 * (64/3)/(455 kHz/12) * 16 nec_units * 1.375 = 12378022 ns
200 */
201 params.max_pulse_width = 12378022; /* ns */
202
203 /*
204 * NEC noise filter min width: (64/3)/(455 kHz/12) * 1 nec_unit
205 * (64/3)/(455 kHz/12) * 1 nec_units * 0.625 = 351648 ns
206 */
207 params.noise_filter_min_width = 351648; /* ns */
208
209 params.modulation = false;
210 params.invert_level = true;
211 break;
Andy Wallsdbda8f72009-09-27 20:55:41 -0300212 }
213 v4l2_subdev_call(dev->sd_ir, ir, rx_s_parameters, &params);
Andy Walls43c24072010-06-27 23:15:35 -0300214 return 0;
215}
216
David Härdemand8b4b582010-10-29 16:08:23 -0300217static int cx23885_input_ir_open(struct rc_dev *rc)
Andy Walls43c24072010-06-27 23:15:35 -0300218{
David Härdemand8b4b582010-10-29 16:08:23 -0300219 struct cx23885_kernel_ir *kernel_ir = rc->priv;
Andy Walls43c24072010-06-27 23:15:35 -0300220
221 if (kernel_ir->cx == NULL)
222 return -ENODEV;
223
224 return cx23885_input_ir_start(kernel_ir->cx);
Andy Wallsdbda8f72009-09-27 20:55:41 -0300225}
226
227static void cx23885_input_ir_stop(struct cx23885_dev *dev)
228{
Andy Wallsdbda8f72009-09-27 20:55:41 -0300229 struct v4l2_subdev_ir_parameters params;
230
231 if (dev->sd_ir == NULL)
232 return;
233
234 /*
235 * Stop the sd_ir subdevice from generating notifications and
236 * scheduling work.
237 * It is shutdown this way in order to mitigate a race with
238 * cx23885_input_rx_work_handler() in the overrun case, which could
239 * re-enable the subdevice.
240 */
241 atomic_set(&dev->ir_input_stopping, 1);
242 v4l2_subdev_call(dev->sd_ir, ir, rx_g_parameters, &params);
243 while (params.shutdown == false) {
244 params.enable = false;
245 params.interrupt_enable = false;
246 params.shutdown = true;
247 v4l2_subdev_call(dev->sd_ir, ir, rx_s_parameters, &params);
248 v4l2_subdev_call(dev->sd_ir, ir, rx_g_parameters, &params);
249 }
Linus Torvalds0b8e74c2012-10-07 17:49:05 +0900250 flush_work(&dev->cx25840_work);
251 flush_work(&dev->ir_rx_work);
252 flush_work(&dev->ir_tx_work);
Andy Walls43c24072010-06-27 23:15:35 -0300253}
Andy Wallsdbda8f72009-09-27 20:55:41 -0300254
David Härdemand8b4b582010-10-29 16:08:23 -0300255static void cx23885_input_ir_close(struct rc_dev *rc)
Andy Walls43c24072010-06-27 23:15:35 -0300256{
David Härdemand8b4b582010-10-29 16:08:23 -0300257 struct cx23885_kernel_ir *kernel_ir = rc->priv;
Andy Walls43c24072010-06-27 23:15:35 -0300258
259 if (kernel_ir->cx != NULL)
260 cx23885_input_ir_stop(kernel_ir->cx);
Andy Wallsdbda8f72009-09-27 20:55:41 -0300261}
262
263int cx23885_input_init(struct cx23885_dev *dev)
264{
Andy Walls43c24072010-06-27 23:15:35 -0300265 struct cx23885_kernel_ir *kernel_ir;
David Härdemand8b4b582010-10-29 16:08:23 -0300266 struct rc_dev *rc;
Andy Walls43c24072010-06-27 23:15:35 -0300267 char *rc_map;
268 enum rc_driver_type driver_type;
269 unsigned long allowed_protos;
270
Andy Wallsdbda8f72009-09-27 20:55:41 -0300271 int ret;
272
273 /*
274 * If the IR device (hardware registers, chip, GPIO lines, etc.) isn't
275 * encapsulated in a v4l2_subdev, then I'm not going to deal with it.
276 */
277 if (dev->sd_ir == NULL)
278 return -ENODEV;
279
280 switch (dev->board) {
Andy Walls9b3d8ec2011-06-08 21:24:25 -0300281 case CX23885_BOARD_HAUPPAUGE_HVR1270:
Andy Wallsdbda8f72009-09-27 20:55:41 -0300282 case CX23885_BOARD_HAUPPAUGE_HVR1850:
Michael Krufky7fec6fe2009-11-11 15:46:09 -0300283 case CX23885_BOARD_HAUPPAUGE_HVR1290:
Andy Walls98d109f2010-07-19 00:41:41 -0300284 case CX23885_BOARD_HAUPPAUGE_HVR1250:
285 /* Integrated CX2388[58] IR controller */
Andy Walls43c24072010-06-27 23:15:35 -0300286 driver_type = RC_DRIVER_IR_RAW;
David Härdemanc003ab12012-10-11 19:11:54 -0300287 allowed_protos = RC_BIT_ALL;
Andy Walls43c24072010-06-27 23:15:35 -0300288 /* The grey Hauppauge RC-5 remote */
Mauro Carvalho Chehab15195d32011-01-24 12:18:47 -0300289 rc_map = RC_MAP_HAUPPAUGE;
Andy Wallsdbda8f72009-09-27 20:55:41 -0300290 break;
Djuri Baars076f0e32012-07-28 09:01:38 -0300291 case CX23885_BOARD_TERRATEC_CINERGY_T_PCIE_DUAL:
292 /* Integrated CX23885 IR controller */
293 driver_type = RC_DRIVER_IR_RAW;
David Härdemanc003ab12012-10-11 19:11:54 -0300294 allowed_protos = RC_BIT_NEC;
Djuri Baars076f0e32012-07-28 09:01:38 -0300295 /* The grey Terratec remote with orange buttons */
296 rc_map = RC_MAP_NEC_TERRATEC_CINERGY_XS;
297 break;
Andy Walls98d109f2010-07-19 00:41:41 -0300298 case CX23885_BOARD_TEVII_S470:
299 /* Integrated CX23885 IR controller */
300 driver_type = RC_DRIVER_IR_RAW;
David Härdemanc003ab12012-10-11 19:11:54 -0300301 allowed_protos = RC_BIT_ALL;
Andy Walls98d109f2010-07-19 00:41:41 -0300302 /* A guess at the remote */
303 rc_map = RC_MAP_TEVII_NEC;
304 break;
Alfredo Jesús Delaitie5f670b2012-11-08 15:50:25 -0300305 case CX23885_BOARD_MYGICA_X8507:
306 /* Integrated CX23885 IR controller */
307 driver_type = RC_DRIVER_IR_RAW;
308 allowed_protos = RC_BIT_ALL;
309 /* A guess at the remote */
310 rc_map = RC_MAP_TOTAL_MEDIA_IN_HAND_02;
311 break;
Luis Alvese6001482013-10-01 22:11:35 -0300312 case CX23885_BOARD_TBS_6980:
313 case CX23885_BOARD_TBS_6981:
314 /* Integrated CX23885 IR controller */
315 driver_type = RC_DRIVER_IR_RAW;
316 allowed_protos = RC_BIT_ALL;
317 /* A guess at the remote */
318 rc_map = RC_MAP_TBS_NEC;
319 break;
nibble.maxd11a3832014-09-29 11:17:36 -0300320 case CX23885_BOARD_DVBSKY_T9580:
nibble.max070e6662014-10-23 07:02:16 -0300321 case CX23885_BOARD_DVBSKY_T980C:
322 case CX23885_BOARD_DVBSKY_S950C:
nibble.maxcba54802014-11-05 11:58:07 -0300323 case CX23885_BOARD_DVBSKY_S950:
nibble.maxc29d6a82014-11-05 11:58:38 -0300324 case CX23885_BOARD_DVBSKY_S952:
nibble.maxd11a3832014-09-29 11:17:36 -0300325 /* Integrated CX23885 IR controller */
326 driver_type = RC_DRIVER_IR_RAW;
327 allowed_protos = RC_BIT_ALL;
328 rc_map = RC_MAP_DVBSKY;
329 break;
Olli Salonen61b103e2014-10-30 17:48:27 -0300330 case CX23885_BOARD_TT_CT2_4500_CI:
331 /* Integrated CX23885 IR controller */
332 driver_type = RC_DRIVER_IR_RAW;
333 allowed_protos = RC_BIT_ALL;
334 rc_map = RC_MAP_TT_1500;
335 break;
Andy Walls43c24072010-06-27 23:15:35 -0300336 default:
Andy Wallsdbda8f72009-09-27 20:55:41 -0300337 return -ENODEV;
Andy Walls43c24072010-06-27 23:15:35 -0300338 }
Andy Wallsdbda8f72009-09-27 20:55:41 -0300339
Andy Walls43c24072010-06-27 23:15:35 -0300340 /* cx23885 board instance kernel IR state */
341 kernel_ir = kzalloc(sizeof(struct cx23885_kernel_ir), GFP_KERNEL);
342 if (kernel_ir == NULL)
343 return -ENOMEM;
344
345 kernel_ir->cx = dev;
346 kernel_ir->name = kasprintf(GFP_KERNEL, "cx23885 IR (%s)",
347 cx23885_boards[dev->board].name);
348 kernel_ir->phys = kasprintf(GFP_KERNEL, "pci-%s/ir0",
349 pci_name(dev->pci));
350
351 /* input device */
David Härdemand8b4b582010-10-29 16:08:23 -0300352 rc = rc_allocate_device();
353 if (!rc) {
Andy Wallsdbda8f72009-09-27 20:55:41 -0300354 ret = -ENOMEM;
355 goto err_out_free;
356 }
357
David Härdemand8b4b582010-10-29 16:08:23 -0300358 kernel_ir->rc = rc;
359 rc->input_name = kernel_ir->name;
360 rc->input_phys = kernel_ir->phys;
361 rc->input_id.bustype = BUS_PCI;
362 rc->input_id.version = 1;
Andy Wallsdbda8f72009-09-27 20:55:41 -0300363 if (dev->pci->subsystem_vendor) {
David Härdemand8b4b582010-10-29 16:08:23 -0300364 rc->input_id.vendor = dev->pci->subsystem_vendor;
365 rc->input_id.product = dev->pci->subsystem_device;
Andy Wallsdbda8f72009-09-27 20:55:41 -0300366 } else {
David Härdemand8b4b582010-10-29 16:08:23 -0300367 rc->input_id.vendor = dev->pci->vendor;
368 rc->input_id.product = dev->pci->device;
Andy Wallsdbda8f72009-09-27 20:55:41 -0300369 }
David Härdemand8b4b582010-10-29 16:08:23 -0300370 rc->dev.parent = &dev->pci->dev;
371 rc->driver_type = driver_type;
David Härdemanc5540fb2014-04-03 20:32:21 -0300372 rc->allowed_protocols = allowed_protos;
David Härdemand8b4b582010-10-29 16:08:23 -0300373 rc->priv = kernel_ir;
374 rc->open = cx23885_input_ir_open;
375 rc->close = cx23885_input_ir_close;
376 rc->map_name = rc_map;
377 rc->driver_name = MODULE_NAME;
Andy Wallsdbda8f72009-09-27 20:55:41 -0300378
Andy Walls43c24072010-06-27 23:15:35 -0300379 /* Go */
380 dev->kernel_ir = kernel_ir;
David Härdemand8b4b582010-10-29 16:08:23 -0300381 ret = rc_register_device(rc);
Andy Wallsdbda8f72009-09-27 20:55:41 -0300382 if (ret)
383 goto err_out_stop;
384
385 return 0;
386
387err_out_stop:
388 cx23885_input_ir_stop(dev);
Andy Walls43c24072010-06-27 23:15:35 -0300389 dev->kernel_ir = NULL;
David Härdemand8b4b582010-10-29 16:08:23 -0300390 rc_free_device(rc);
Andy Wallsdbda8f72009-09-27 20:55:41 -0300391err_out_free:
Andy Walls43c24072010-06-27 23:15:35 -0300392 kfree(kernel_ir->phys);
393 kfree(kernel_ir->name);
394 kfree(kernel_ir);
Andy Wallsdbda8f72009-09-27 20:55:41 -0300395 return ret;
396}
397
398void cx23885_input_fini(struct cx23885_dev *dev)
399{
400 /* Always stop the IR hardware from generating interrupts */
401 cx23885_input_ir_stop(dev);
402
Andy Walls43c24072010-06-27 23:15:35 -0300403 if (dev->kernel_ir == NULL)
Andy Wallsdbda8f72009-09-27 20:55:41 -0300404 return;
David Härdemand8b4b582010-10-29 16:08:23 -0300405 rc_unregister_device(dev->kernel_ir->rc);
Andy Walls43c24072010-06-27 23:15:35 -0300406 kfree(dev->kernel_ir->phys);
407 kfree(dev->kernel_ir->name);
408 kfree(dev->kernel_ir);
409 dev->kernel_ir = NULL;
Andy Wallsdbda8f72009-09-27 20:55:41 -0300410}