1c942fddfSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
2b285192aSMauro Carvalho Chehab /*
3b285192aSMauro Carvalho Chehab * Driver for the Conexant CX23885/7/8 PCIe bridge
4b285192aSMauro Carvalho Chehab *
5b285192aSMauro Carvalho Chehab * Infrared remote control input device
6b285192aSMauro Carvalho Chehab *
7b285192aSMauro Carvalho Chehab * Most of this file is
8b285192aSMauro Carvalho Chehab *
9b285192aSMauro Carvalho Chehab * Copyright (C) 2009 Andy Walls <awalls@md.metrocast.net>
10b285192aSMauro Carvalho Chehab *
11b285192aSMauro Carvalho Chehab * However, the cx23885_input_{init,fini} functions contained herein are
12b285192aSMauro Carvalho Chehab * derived from Linux kernel files linux/media/video/.../...-input.c marked as:
13b285192aSMauro Carvalho Chehab *
14b285192aSMauro Carvalho Chehab * Copyright (C) 2008 <srinivasa.deevi at conexant dot com>
15b285192aSMauro Carvalho Chehab * Copyright (C) 2005 Ludovico Cavedon <cavedon@sssup.it>
16b285192aSMauro Carvalho Chehab * Markus Rechberger <mrechberger@gmail.com>
1732590819SMauro Carvalho Chehab * Mauro Carvalho Chehab <mchehab@kernel.org>
18b285192aSMauro Carvalho Chehab * Sascha Sommer <saschasommer@freenet.de>
19b285192aSMauro Carvalho Chehab * Copyright (C) 2004, 2005 Chris Pascoe
20b285192aSMauro Carvalho Chehab * Copyright (C) 2003, 2004 Gerd Knorr
21b285192aSMauro Carvalho Chehab * Copyright (C) 2003 Pavel Machek
22b285192aSMauro Carvalho Chehab */
23b285192aSMauro Carvalho Chehab
24e39682b5SMauro Carvalho Chehab #include "cx23885.h"
25e39682b5SMauro Carvalho Chehab #include "cx23885-input.h"
26e39682b5SMauro Carvalho Chehab
27b285192aSMauro Carvalho Chehab #include <linux/slab.h>
28b285192aSMauro Carvalho Chehab #include <media/rc-core.h>
29b285192aSMauro Carvalho Chehab #include <media/v4l2-subdev.h>
30b285192aSMauro Carvalho Chehab
31b285192aSMauro Carvalho Chehab #define MODULE_NAME "cx23885"
32b285192aSMauro Carvalho Chehab
cx23885_input_process_measurements(struct cx23885_dev * dev,bool overrun)33b285192aSMauro Carvalho Chehab static void cx23885_input_process_measurements(struct cx23885_dev *dev,
34b285192aSMauro Carvalho Chehab bool overrun)
35b285192aSMauro Carvalho Chehab {
36b285192aSMauro Carvalho Chehab struct cx23885_kernel_ir *kernel_ir = dev->kernel_ir;
37b285192aSMauro Carvalho Chehab
38b285192aSMauro Carvalho Chehab ssize_t num;
39b285192aSMauro Carvalho Chehab int count, i;
40b285192aSMauro Carvalho Chehab bool handle = false;
41b285192aSMauro Carvalho Chehab struct ir_raw_event ir_core_event[64];
42b285192aSMauro Carvalho Chehab
43b285192aSMauro Carvalho Chehab do {
44b285192aSMauro Carvalho Chehab num = 0;
45b285192aSMauro Carvalho Chehab v4l2_subdev_call(dev->sd_ir, ir, rx_read, (u8 *) ir_core_event,
46b285192aSMauro Carvalho Chehab sizeof(ir_core_event), &num);
47b285192aSMauro Carvalho Chehab
48b285192aSMauro Carvalho Chehab count = num / sizeof(struct ir_raw_event);
49b285192aSMauro Carvalho Chehab
50b285192aSMauro Carvalho Chehab for (i = 0; i < count; i++) {
51b285192aSMauro Carvalho Chehab ir_raw_event_store(kernel_ir->rc,
52b285192aSMauro Carvalho Chehab &ir_core_event[i]);
53b285192aSMauro Carvalho Chehab handle = true;
54b285192aSMauro Carvalho Chehab }
55b285192aSMauro Carvalho Chehab } while (num != 0);
56b285192aSMauro Carvalho Chehab
57b285192aSMauro Carvalho Chehab if (overrun)
58*950170d6SSean Young ir_raw_event_overflow(kernel_ir->rc);
59b285192aSMauro Carvalho Chehab else if (handle)
60b285192aSMauro Carvalho Chehab ir_raw_event_handle(kernel_ir->rc);
61b285192aSMauro Carvalho Chehab }
62b285192aSMauro Carvalho Chehab
cx23885_input_rx_work_handler(struct cx23885_dev * dev,u32 events)63b285192aSMauro Carvalho Chehab void cx23885_input_rx_work_handler(struct cx23885_dev *dev, u32 events)
64b285192aSMauro Carvalho Chehab {
65b285192aSMauro Carvalho Chehab struct v4l2_subdev_ir_parameters params;
66b285192aSMauro Carvalho Chehab int overrun, data_available;
67b285192aSMauro Carvalho Chehab
68b285192aSMauro Carvalho Chehab if (dev->sd_ir == NULL || events == 0)
69b285192aSMauro Carvalho Chehab return;
70b285192aSMauro Carvalho Chehab
71b285192aSMauro Carvalho Chehab switch (dev->board) {
72b285192aSMauro Carvalho Chehab case CX23885_BOARD_HAUPPAUGE_HVR1270:
73b285192aSMauro Carvalho Chehab case CX23885_BOARD_HAUPPAUGE_HVR1850:
74b285192aSMauro Carvalho Chehab case CX23885_BOARD_HAUPPAUGE_HVR1290:
75b285192aSMauro Carvalho Chehab case CX23885_BOARD_TERRATEC_CINERGY_T_PCIE_DUAL:
76b285192aSMauro Carvalho Chehab case CX23885_BOARD_TEVII_S470:
77b285192aSMauro Carvalho Chehab case CX23885_BOARD_HAUPPAUGE_HVR1250:
78e5f670b7SAlfredo Jesús Delaiti case CX23885_BOARD_MYGICA_X8507:
79e6001482SLuis Alves case CX23885_BOARD_TBS_6980:
80e6001482SLuis Alves case CX23885_BOARD_TBS_6981:
81d11a3835Snibble.max case CX23885_BOARD_DVBSKY_T9580:
82070e6661Snibble.max case CX23885_BOARD_DVBSKY_T980C:
83070e6661Snibble.max case CX23885_BOARD_DVBSKY_S950C:
8461b103e8SOlli Salonen case CX23885_BOARD_TT_CT2_4500_CI:
85cba5480cSnibble.max case CX23885_BOARD_DVBSKY_S950:
86c29d6a83Snibble.max case CX23885_BOARD_DVBSKY_S952:
87c02ef64aSNibble Max case CX23885_BOARD_DVBSKY_T982:
8894f11518SBrad Love case CX23885_BOARD_HAUPPAUGE_HVR1265_K4:
89b285192aSMauro Carvalho Chehab /*
90b285192aSMauro Carvalho Chehab * The only boards we handle right now. However other boards
91b285192aSMauro Carvalho Chehab * using the CX2388x integrated IR controller should be similar
92b285192aSMauro Carvalho Chehab */
93b285192aSMauro Carvalho Chehab break;
94b285192aSMauro Carvalho Chehab default:
95b285192aSMauro Carvalho Chehab return;
96b285192aSMauro Carvalho Chehab }
97b285192aSMauro Carvalho Chehab
98b285192aSMauro Carvalho Chehab overrun = events & (V4L2_SUBDEV_IR_RX_SW_FIFO_OVERRUN |
99b285192aSMauro Carvalho Chehab V4L2_SUBDEV_IR_RX_HW_FIFO_OVERRUN);
100b285192aSMauro Carvalho Chehab
101b285192aSMauro Carvalho Chehab data_available = events & (V4L2_SUBDEV_IR_RX_END_OF_RX_DETECTED |
102b285192aSMauro Carvalho Chehab V4L2_SUBDEV_IR_RX_FIFO_SERVICE_REQ);
103b285192aSMauro Carvalho Chehab
104b285192aSMauro Carvalho Chehab if (overrun) {
105b285192aSMauro Carvalho Chehab /* If there was a FIFO overrun, stop the device */
106b285192aSMauro Carvalho Chehab v4l2_subdev_call(dev->sd_ir, ir, rx_g_parameters, ¶ms);
107b285192aSMauro Carvalho Chehab params.enable = false;
108b285192aSMauro Carvalho Chehab /* Mitigate race with cx23885_input_ir_stop() */
109b285192aSMauro Carvalho Chehab params.shutdown = atomic_read(&dev->ir_input_stopping);
110b285192aSMauro Carvalho Chehab v4l2_subdev_call(dev->sd_ir, ir, rx_s_parameters, ¶ms);
111b285192aSMauro Carvalho Chehab }
112b285192aSMauro Carvalho Chehab
113b285192aSMauro Carvalho Chehab if (data_available)
114b285192aSMauro Carvalho Chehab cx23885_input_process_measurements(dev, overrun);
115b285192aSMauro Carvalho Chehab
116b285192aSMauro Carvalho Chehab if (overrun) {
117b285192aSMauro Carvalho Chehab /* If there was a FIFO overrun, clear & restart the device */
118b285192aSMauro Carvalho Chehab params.enable = true;
119b285192aSMauro Carvalho Chehab /* Mitigate race with cx23885_input_ir_stop() */
120b285192aSMauro Carvalho Chehab params.shutdown = atomic_read(&dev->ir_input_stopping);
121b285192aSMauro Carvalho Chehab v4l2_subdev_call(dev->sd_ir, ir, rx_s_parameters, ¶ms);
122b285192aSMauro Carvalho Chehab }
123b285192aSMauro Carvalho Chehab }
124b285192aSMauro Carvalho Chehab
cx23885_input_ir_start(struct cx23885_dev * dev)125b285192aSMauro Carvalho Chehab static int cx23885_input_ir_start(struct cx23885_dev *dev)
126b285192aSMauro Carvalho Chehab {
127b285192aSMauro Carvalho Chehab struct v4l2_subdev_ir_parameters params;
128b285192aSMauro Carvalho Chehab
129b285192aSMauro Carvalho Chehab if (dev->sd_ir == NULL)
130b285192aSMauro Carvalho Chehab return -ENODEV;
131b285192aSMauro Carvalho Chehab
132b285192aSMauro Carvalho Chehab atomic_set(&dev->ir_input_stopping, 0);
133b285192aSMauro Carvalho Chehab
134b285192aSMauro Carvalho Chehab v4l2_subdev_call(dev->sd_ir, ir, rx_g_parameters, ¶ms);
135b285192aSMauro Carvalho Chehab switch (dev->board) {
136b285192aSMauro Carvalho Chehab case CX23885_BOARD_HAUPPAUGE_HVR1270:
137b285192aSMauro Carvalho Chehab case CX23885_BOARD_HAUPPAUGE_HVR1850:
138b285192aSMauro Carvalho Chehab case CX23885_BOARD_HAUPPAUGE_HVR1290:
139b285192aSMauro Carvalho Chehab case CX23885_BOARD_HAUPPAUGE_HVR1250:
140e5f670b7SAlfredo Jesús Delaiti case CX23885_BOARD_MYGICA_X8507:
141d11a3835Snibble.max case CX23885_BOARD_DVBSKY_T9580:
142070e6661Snibble.max case CX23885_BOARD_DVBSKY_T980C:
143070e6661Snibble.max case CX23885_BOARD_DVBSKY_S950C:
14461b103e8SOlli Salonen case CX23885_BOARD_TT_CT2_4500_CI:
145cba5480cSnibble.max case CX23885_BOARD_DVBSKY_S950:
146c29d6a83Snibble.max case CX23885_BOARD_DVBSKY_S952:
147c02ef64aSNibble Max case CX23885_BOARD_DVBSKY_T982:
14894f11518SBrad Love case CX23885_BOARD_HAUPPAUGE_HVR1265_K4:
149b285192aSMauro Carvalho Chehab /*
150b285192aSMauro Carvalho Chehab * The IR controller on this board only returns pulse widths.
151b285192aSMauro Carvalho Chehab * Any other mode setting will fail to set up the device.
152b285192aSMauro Carvalho Chehab */
153b285192aSMauro Carvalho Chehab params.mode = V4L2_SUBDEV_IR_MODE_PULSE_WIDTH;
154b285192aSMauro Carvalho Chehab params.enable = true;
155b285192aSMauro Carvalho Chehab params.interrupt_enable = true;
156b285192aSMauro Carvalho Chehab params.shutdown = false;
157b285192aSMauro Carvalho Chehab
158b285192aSMauro Carvalho Chehab /* Setup for baseband compatible with both RC-5 and RC-6A */
159b285192aSMauro Carvalho Chehab params.modulation = false;
160b285192aSMauro Carvalho Chehab /* RC-5: 2,222,222 ns = 1/36 kHz * 32 cycles * 2 marks * 1.25*/
161b285192aSMauro Carvalho Chehab /* RC-6A: 3,333,333 ns = 1/36 kHz * 16 cycles * 6 marks * 1.25*/
162b285192aSMauro Carvalho Chehab params.max_pulse_width = 3333333; /* ns */
163b285192aSMauro Carvalho Chehab /* RC-5: 666,667 ns = 1/36 kHz * 32 cycles * 1 mark * 0.75 */
164b285192aSMauro Carvalho Chehab /* RC-6A: 333,333 ns = 1/36 kHz * 16 cycles * 1 mark * 0.75 */
165b285192aSMauro Carvalho Chehab params.noise_filter_min_width = 333333; /* ns */
166b285192aSMauro Carvalho Chehab /*
167b285192aSMauro Carvalho Chehab * This board has inverted receive sense:
168b285192aSMauro Carvalho Chehab * mark is received as low logic level;
169b285192aSMauro Carvalho Chehab * falling edges are detected as rising edges; etc.
170b285192aSMauro Carvalho Chehab */
171b285192aSMauro Carvalho Chehab params.invert_level = true;
172b285192aSMauro Carvalho Chehab break;
173b285192aSMauro Carvalho Chehab case CX23885_BOARD_TERRATEC_CINERGY_T_PCIE_DUAL:
174b285192aSMauro Carvalho Chehab case CX23885_BOARD_TEVII_S470:
175e6001482SLuis Alves case CX23885_BOARD_TBS_6980:
176e6001482SLuis Alves case CX23885_BOARD_TBS_6981:
177b285192aSMauro Carvalho Chehab /*
178b285192aSMauro Carvalho Chehab * The IR controller on this board only returns pulse widths.
179b285192aSMauro Carvalho Chehab * Any other mode setting will fail to set up the device.
180b285192aSMauro Carvalho Chehab */
181b285192aSMauro Carvalho Chehab params.mode = V4L2_SUBDEV_IR_MODE_PULSE_WIDTH;
182b285192aSMauro Carvalho Chehab params.enable = true;
183b285192aSMauro Carvalho Chehab params.interrupt_enable = true;
184b285192aSMauro Carvalho Chehab params.shutdown = false;
185b285192aSMauro Carvalho Chehab
186b285192aSMauro Carvalho Chehab /* Setup for a standard NEC protocol */
187b285192aSMauro Carvalho Chehab params.carrier_freq = 37917; /* Hz, 455 kHz/12 for NEC */
188b285192aSMauro Carvalho Chehab params.carrier_range_lower = 33000; /* Hz */
189b285192aSMauro Carvalho Chehab params.carrier_range_upper = 43000; /* Hz */
190b285192aSMauro Carvalho Chehab params.duty_cycle = 33; /* percent, 33 percent for NEC */
191b285192aSMauro Carvalho Chehab
192b285192aSMauro Carvalho Chehab /*
193b285192aSMauro Carvalho Chehab * NEC max pulse width: (64/3)/(455 kHz/12) * 16 nec_units
194b285192aSMauro Carvalho Chehab * (64/3)/(455 kHz/12) * 16 nec_units * 1.375 = 12378022 ns
195b285192aSMauro Carvalho Chehab */
196b285192aSMauro Carvalho Chehab params.max_pulse_width = 12378022; /* ns */
197b285192aSMauro Carvalho Chehab
198b285192aSMauro Carvalho Chehab /*
199b285192aSMauro Carvalho Chehab * NEC noise filter min width: (64/3)/(455 kHz/12) * 1 nec_unit
200b285192aSMauro Carvalho Chehab * (64/3)/(455 kHz/12) * 1 nec_units * 0.625 = 351648 ns
201b285192aSMauro Carvalho Chehab */
202b285192aSMauro Carvalho Chehab params.noise_filter_min_width = 351648; /* ns */
203b285192aSMauro Carvalho Chehab
204b285192aSMauro Carvalho Chehab params.modulation = false;
205b285192aSMauro Carvalho Chehab params.invert_level = true;
206b285192aSMauro Carvalho Chehab break;
207b285192aSMauro Carvalho Chehab }
208b285192aSMauro Carvalho Chehab v4l2_subdev_call(dev->sd_ir, ir, rx_s_parameters, ¶ms);
209b285192aSMauro Carvalho Chehab return 0;
210b285192aSMauro Carvalho Chehab }
211b285192aSMauro Carvalho Chehab
cx23885_input_ir_open(struct rc_dev * rc)212b285192aSMauro Carvalho Chehab static int cx23885_input_ir_open(struct rc_dev *rc)
213b285192aSMauro Carvalho Chehab {
214b285192aSMauro Carvalho Chehab struct cx23885_kernel_ir *kernel_ir = rc->priv;
215b285192aSMauro Carvalho Chehab
216b285192aSMauro Carvalho Chehab if (kernel_ir->cx == NULL)
217b285192aSMauro Carvalho Chehab return -ENODEV;
218b285192aSMauro Carvalho Chehab
219b285192aSMauro Carvalho Chehab return cx23885_input_ir_start(kernel_ir->cx);
220b285192aSMauro Carvalho Chehab }
221b285192aSMauro Carvalho Chehab
cx23885_input_ir_stop(struct cx23885_dev * dev)222b285192aSMauro Carvalho Chehab static void cx23885_input_ir_stop(struct cx23885_dev *dev)
223b285192aSMauro Carvalho Chehab {
224b285192aSMauro Carvalho Chehab struct v4l2_subdev_ir_parameters params;
225b285192aSMauro Carvalho Chehab
226b285192aSMauro Carvalho Chehab if (dev->sd_ir == NULL)
227b285192aSMauro Carvalho Chehab return;
228b285192aSMauro Carvalho Chehab
229b285192aSMauro Carvalho Chehab /*
230b285192aSMauro Carvalho Chehab * Stop the sd_ir subdevice from generating notifications and
231b285192aSMauro Carvalho Chehab * scheduling work.
232b285192aSMauro Carvalho Chehab * It is shutdown this way in order to mitigate a race with
233b285192aSMauro Carvalho Chehab * cx23885_input_rx_work_handler() in the overrun case, which could
234b285192aSMauro Carvalho Chehab * re-enable the subdevice.
235b285192aSMauro Carvalho Chehab */
236b285192aSMauro Carvalho Chehab atomic_set(&dev->ir_input_stopping, 1);
237b285192aSMauro Carvalho Chehab v4l2_subdev_call(dev->sd_ir, ir, rx_g_parameters, ¶ms);
238b285192aSMauro Carvalho Chehab while (params.shutdown == false) {
239b285192aSMauro Carvalho Chehab params.enable = false;
240b285192aSMauro Carvalho Chehab params.interrupt_enable = false;
241b285192aSMauro Carvalho Chehab params.shutdown = true;
242b285192aSMauro Carvalho Chehab v4l2_subdev_call(dev->sd_ir, ir, rx_s_parameters, ¶ms);
243b285192aSMauro Carvalho Chehab v4l2_subdev_call(dev->sd_ir, ir, rx_g_parameters, ¶ms);
244b285192aSMauro Carvalho Chehab }
2450b8e74c6SLinus Torvalds flush_work(&dev->cx25840_work);
2460b8e74c6SLinus Torvalds flush_work(&dev->ir_rx_work);
2470b8e74c6SLinus Torvalds flush_work(&dev->ir_tx_work);
248b285192aSMauro Carvalho Chehab }
249b285192aSMauro Carvalho Chehab
cx23885_input_ir_close(struct rc_dev * rc)250b285192aSMauro Carvalho Chehab static void cx23885_input_ir_close(struct rc_dev *rc)
251b285192aSMauro Carvalho Chehab {
252b285192aSMauro Carvalho Chehab struct cx23885_kernel_ir *kernel_ir = rc->priv;
253b285192aSMauro Carvalho Chehab
254b285192aSMauro Carvalho Chehab if (kernel_ir->cx != NULL)
255b285192aSMauro Carvalho Chehab cx23885_input_ir_stop(kernel_ir->cx);
256b285192aSMauro Carvalho Chehab }
257b285192aSMauro Carvalho Chehab
cx23885_input_init(struct cx23885_dev * dev)258b285192aSMauro Carvalho Chehab int cx23885_input_init(struct cx23885_dev *dev)
259b285192aSMauro Carvalho Chehab {
260b285192aSMauro Carvalho Chehab struct cx23885_kernel_ir *kernel_ir;
261b285192aSMauro Carvalho Chehab struct rc_dev *rc;
262b285192aSMauro Carvalho Chehab char *rc_map;
263439be348SHeiner Kallweit u64 allowed_protos;
264b285192aSMauro Carvalho Chehab
265b285192aSMauro Carvalho Chehab int ret;
266b285192aSMauro Carvalho Chehab
267b285192aSMauro Carvalho Chehab /*
268b285192aSMauro Carvalho Chehab * If the IR device (hardware registers, chip, GPIO lines, etc.) isn't
269b285192aSMauro Carvalho Chehab * encapsulated in a v4l2_subdev, then I'm not going to deal with it.
270b285192aSMauro Carvalho Chehab */
271b285192aSMauro Carvalho Chehab if (dev->sd_ir == NULL)
272b285192aSMauro Carvalho Chehab return -ENODEV;
273b285192aSMauro Carvalho Chehab
274b285192aSMauro Carvalho Chehab switch (dev->board) {
275b285192aSMauro Carvalho Chehab case CX23885_BOARD_HAUPPAUGE_HVR1270:
276b285192aSMauro Carvalho Chehab case CX23885_BOARD_HAUPPAUGE_HVR1850:
277b285192aSMauro Carvalho Chehab case CX23885_BOARD_HAUPPAUGE_HVR1290:
278b285192aSMauro Carvalho Chehab case CX23885_BOARD_HAUPPAUGE_HVR1250:
27994f11518SBrad Love case CX23885_BOARD_HAUPPAUGE_HVR1265_K4:
280b285192aSMauro Carvalho Chehab /* Integrated CX2388[58] IR controller */
2816d741bfeSSean Young allowed_protos = RC_PROTO_BIT_ALL_IR_DECODER;
282b285192aSMauro Carvalho Chehab /* The grey Hauppauge RC-5 remote */
283b285192aSMauro Carvalho Chehab rc_map = RC_MAP_HAUPPAUGE;
284b285192aSMauro Carvalho Chehab break;
285b285192aSMauro Carvalho Chehab case CX23885_BOARD_TERRATEC_CINERGY_T_PCIE_DUAL:
286b285192aSMauro Carvalho Chehab /* Integrated CX23885 IR controller */
2876d741bfeSSean Young allowed_protos = RC_PROTO_BIT_ALL_IR_DECODER;
288b285192aSMauro Carvalho Chehab /* The grey Terratec remote with orange buttons */
289b285192aSMauro Carvalho Chehab rc_map = RC_MAP_NEC_TERRATEC_CINERGY_XS;
290b285192aSMauro Carvalho Chehab break;
291b285192aSMauro Carvalho Chehab case CX23885_BOARD_TEVII_S470:
292b285192aSMauro Carvalho Chehab /* Integrated CX23885 IR controller */
2936d741bfeSSean Young allowed_protos = RC_PROTO_BIT_ALL_IR_DECODER;
294b285192aSMauro Carvalho Chehab /* A guess at the remote */
295b285192aSMauro Carvalho Chehab rc_map = RC_MAP_TEVII_NEC;
296b285192aSMauro Carvalho Chehab break;
297e5f670b7SAlfredo Jesús Delaiti case CX23885_BOARD_MYGICA_X8507:
298e5f670b7SAlfredo Jesús Delaiti /* Integrated CX23885 IR controller */
2996d741bfeSSean Young allowed_protos = RC_PROTO_BIT_ALL_IR_DECODER;
300e5f670b7SAlfredo Jesús Delaiti /* A guess at the remote */
301e5f670b7SAlfredo Jesús Delaiti rc_map = RC_MAP_TOTAL_MEDIA_IN_HAND_02;
302e5f670b7SAlfredo Jesús Delaiti break;
303e6001482SLuis Alves case CX23885_BOARD_TBS_6980:
304e6001482SLuis Alves case CX23885_BOARD_TBS_6981:
305e6001482SLuis Alves /* Integrated CX23885 IR controller */
3066d741bfeSSean Young allowed_protos = RC_PROTO_BIT_ALL_IR_DECODER;
307e6001482SLuis Alves /* A guess at the remote */
308e6001482SLuis Alves rc_map = RC_MAP_TBS_NEC;
309e6001482SLuis Alves break;
310d11a3835Snibble.max case CX23885_BOARD_DVBSKY_T9580:
311070e6661Snibble.max case CX23885_BOARD_DVBSKY_T980C:
312070e6661Snibble.max case CX23885_BOARD_DVBSKY_S950C:
313cba5480cSnibble.max case CX23885_BOARD_DVBSKY_S950:
314c29d6a83Snibble.max case CX23885_BOARD_DVBSKY_S952:
315c02ef64aSNibble Max case CX23885_BOARD_DVBSKY_T982:
316d11a3835Snibble.max /* Integrated CX23885 IR controller */
3176d741bfeSSean Young allowed_protos = RC_PROTO_BIT_ALL_IR_DECODER;
318d11a3835Snibble.max rc_map = RC_MAP_DVBSKY;
319d11a3835Snibble.max break;
32061b103e8SOlli Salonen case CX23885_BOARD_TT_CT2_4500_CI:
32161b103e8SOlli Salonen /* Integrated CX23885 IR controller */
3226d741bfeSSean Young allowed_protos = RC_PROTO_BIT_ALL_IR_DECODER;
32361b103e8SOlli Salonen rc_map = RC_MAP_TT_1500;
32461b103e8SOlli Salonen break;
325b285192aSMauro Carvalho Chehab default:
326b285192aSMauro Carvalho Chehab return -ENODEV;
327b285192aSMauro Carvalho Chehab }
328b285192aSMauro Carvalho Chehab
329b285192aSMauro Carvalho Chehab /* cx23885 board instance kernel IR state */
330b285192aSMauro Carvalho Chehab kernel_ir = kzalloc(sizeof(struct cx23885_kernel_ir), GFP_KERNEL);
331b285192aSMauro Carvalho Chehab if (kernel_ir == NULL)
332b285192aSMauro Carvalho Chehab return -ENOMEM;
333b285192aSMauro Carvalho Chehab
334b285192aSMauro Carvalho Chehab kernel_ir->cx = dev;
335b285192aSMauro Carvalho Chehab kernel_ir->name = kasprintf(GFP_KERNEL, "cx23885 IR (%s)",
336b285192aSMauro Carvalho Chehab cx23885_boards[dev->board].name);
3371ee332acSArvind Yadav if (!kernel_ir->name) {
3381ee332acSArvind Yadav ret = -ENOMEM;
3391ee332acSArvind Yadav goto err_out_free;
3401ee332acSArvind Yadav }
3411ee332acSArvind Yadav
342b285192aSMauro Carvalho Chehab kernel_ir->phys = kasprintf(GFP_KERNEL, "pci-%s/ir0",
343b285192aSMauro Carvalho Chehab pci_name(dev->pci));
3441ee332acSArvind Yadav if (!kernel_ir->phys) {
3451ee332acSArvind Yadav ret = -ENOMEM;
3461ee332acSArvind Yadav goto err_out_free_name;
3471ee332acSArvind Yadav }
348b285192aSMauro Carvalho Chehab
349b285192aSMauro Carvalho Chehab /* input device */
3500f7499fdSAndi Shyti rc = rc_allocate_device(RC_DRIVER_IR_RAW);
351b285192aSMauro Carvalho Chehab if (!rc) {
352b285192aSMauro Carvalho Chehab ret = -ENOMEM;
3531ee332acSArvind Yadav goto err_out_free_phys;
354b285192aSMauro Carvalho Chehab }
355b285192aSMauro Carvalho Chehab
356b285192aSMauro Carvalho Chehab kernel_ir->rc = rc;
357518f4b26SSean Young rc->device_name = kernel_ir->name;
358b285192aSMauro Carvalho Chehab rc->input_phys = kernel_ir->phys;
359b285192aSMauro Carvalho Chehab rc->input_id.bustype = BUS_PCI;
360b285192aSMauro Carvalho Chehab rc->input_id.version = 1;
361b285192aSMauro Carvalho Chehab if (dev->pci->subsystem_vendor) {
362b285192aSMauro Carvalho Chehab rc->input_id.vendor = dev->pci->subsystem_vendor;
363b285192aSMauro Carvalho Chehab rc->input_id.product = dev->pci->subsystem_device;
364b285192aSMauro Carvalho Chehab } else {
365b285192aSMauro Carvalho Chehab rc->input_id.vendor = dev->pci->vendor;
366b285192aSMauro Carvalho Chehab rc->input_id.product = dev->pci->device;
367b285192aSMauro Carvalho Chehab }
368b285192aSMauro Carvalho Chehab rc->dev.parent = &dev->pci->dev;
369c5540fbbSDavid Härdeman rc->allowed_protocols = allowed_protos;
370b285192aSMauro Carvalho Chehab rc->priv = kernel_ir;
371b285192aSMauro Carvalho Chehab rc->open = cx23885_input_ir_open;
372b285192aSMauro Carvalho Chehab rc->close = cx23885_input_ir_close;
373b285192aSMauro Carvalho Chehab rc->map_name = rc_map;
374b285192aSMauro Carvalho Chehab rc->driver_name = MODULE_NAME;
375b285192aSMauro Carvalho Chehab
376b285192aSMauro Carvalho Chehab /* Go */
377b285192aSMauro Carvalho Chehab dev->kernel_ir = kernel_ir;
378b285192aSMauro Carvalho Chehab ret = rc_register_device(rc);
379b285192aSMauro Carvalho Chehab if (ret)
380b285192aSMauro Carvalho Chehab goto err_out_stop;
381b285192aSMauro Carvalho Chehab
382b285192aSMauro Carvalho Chehab return 0;
383b285192aSMauro Carvalho Chehab
384b285192aSMauro Carvalho Chehab err_out_stop:
385b285192aSMauro Carvalho Chehab cx23885_input_ir_stop(dev);
386b285192aSMauro Carvalho Chehab dev->kernel_ir = NULL;
387b285192aSMauro Carvalho Chehab rc_free_device(rc);
3881ee332acSArvind Yadav err_out_free_phys:
389b285192aSMauro Carvalho Chehab kfree(kernel_ir->phys);
3901ee332acSArvind Yadav err_out_free_name:
391b285192aSMauro Carvalho Chehab kfree(kernel_ir->name);
3921ee332acSArvind Yadav err_out_free:
393b285192aSMauro Carvalho Chehab kfree(kernel_ir);
394b285192aSMauro Carvalho Chehab return ret;
395b285192aSMauro Carvalho Chehab }
396b285192aSMauro Carvalho Chehab
cx23885_input_fini(struct cx23885_dev * dev)397b285192aSMauro Carvalho Chehab void cx23885_input_fini(struct cx23885_dev *dev)
398b285192aSMauro Carvalho Chehab {
399b285192aSMauro Carvalho Chehab /* Always stop the IR hardware from generating interrupts */
400b285192aSMauro Carvalho Chehab cx23885_input_ir_stop(dev);
401b285192aSMauro Carvalho Chehab
402b285192aSMauro Carvalho Chehab if (dev->kernel_ir == NULL)
403b285192aSMauro Carvalho Chehab return;
404b285192aSMauro Carvalho Chehab rc_unregister_device(dev->kernel_ir->rc);
405b285192aSMauro Carvalho Chehab kfree(dev->kernel_ir->phys);
406b285192aSMauro Carvalho Chehab kfree(dev->kernel_ir->name);
407b285192aSMauro Carvalho Chehab kfree(dev->kernel_ir);
408b285192aSMauro Carvalho Chehab dev->kernel_ir = NULL;
409b285192aSMauro Carvalho Chehab }
410