blob: f49230d170e6e871a3661f0558af85b88c2e039a [file] [log] [blame]
Sri Deevie0d3baf2009-03-03 14:37:50 -03001/*
Sri Deevib9255172009-03-04 17:49:01 -03002 cx231xx-cards.c - driver for Conexant Cx23100/101/102
3 USB video capture devices
Sri Deevie0d3baf2009-03-03 14:37:50 -03004
5 Copyright (C) 2008 <srinivasa.deevi at conexant dot com>
Sri Deevib9255172009-03-04 17:49:01 -03006 Based on em28xx driver
Sri Deevie0d3baf2009-03-03 14:37:50 -03007
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23#include <linux/init.h>
24#include <linux/module.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090025#include <linux/slab.h>
Sri Deevie0d3baf2009-03-03 14:37:50 -030026#include <linux/delay.h>
27#include <linux/i2c.h>
28#include <linux/usb.h>
29#include <media/tuner.h>
30#include <media/tveeprom.h>
31#include <media/v4l2-common.h>
32#include <media/v4l2-chip-ident.h>
33
34#include <media/cx25840.h>
Mauro Carvalho Chehab3bfb3172010-09-03 10:50:24 -030035#include "dvb-usb-ids.h"
Sri Deevie0d3baf2009-03-03 14:37:50 -030036#include "xc5000.h"
Mauro Carvalho Chehab55fa2882010-09-29 11:07:08 -030037#include "tda18271.h"
Sri Deevie0d3baf2009-03-03 14:37:50 -030038
39#include "cx231xx.h"
40
41static int tuner = -1;
42module_param(tuner, int, 0444);
43MODULE_PARM_DESC(tuner, "tuner type");
44
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -030045static int transfer_mode = 1;
46module_param(transfer_mode, int, 0444);
47MODULE_PARM_DESC(transfer_mode, "transfer mode (1-ISO or 0-BULK)");
48
Sri Deevie0d3baf2009-03-03 14:37:50 -030049static unsigned int disable_ir;
50module_param(disable_ir, int, 0444);
51MODULE_PARM_DESC(disable_ir, "disable infrared remote support");
52
53/* Bitmask marking allocated devices from 0 to CX231XX_MAXBOARDS */
54static unsigned long cx231xx_devused;
55
56/*
57 * Reset sequences for analog/digital modes
58 */
59
60static struct cx231xx_reg_seq RDE250_XCV_TUNER[] = {
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -030061 {0x03, 0x01, 10},
62 {0x03, 0x00, 30},
63 {0x03, 0x01, 10},
64 {-1, -1, -1},
Sri Deevie0d3baf2009-03-03 14:37:50 -030065};
66
Sri Deevie0d3baf2009-03-03 14:37:50 -030067/*
68 * Board definitions
69 */
70struct cx231xx_board cx231xx_boards[] = {
Sri Deevie0d3baf2009-03-03 14:37:50 -030071 [CX231XX_BOARD_UNKNOWN] = {
Sri Deevi6e4f5742009-03-10 21:16:26 -030072 .name = "Unknown CX231xx video grabber",
73 .tuner_type = TUNER_ABSENT,
74 .input = {{
75 .type = CX231XX_VMUX_TELEVISION,
76 .vmux = CX231XX_VIN_3_1,
77 .amux = CX231XX_AMUX_VIDEO,
Márton Németh7ee0a282009-12-13 17:06:10 -030078 .gpio = NULL,
Sri Deevi6e4f5742009-03-10 21:16:26 -030079 }, {
80 .type = CX231XX_VMUX_COMPOSITE1,
81 .vmux = CX231XX_VIN_2_1,
82 .amux = CX231XX_AMUX_LINE_IN,
Márton Németh7ee0a282009-12-13 17:06:10 -030083 .gpio = NULL,
Sri Deevi6e4f5742009-03-10 21:16:26 -030084 }, {
85 .type = CX231XX_VMUX_SVIDEO,
86 .vmux = CX231XX_VIN_1_1 |
87 (CX231XX_VIN_1_2 << 8) |
88 CX25840_SVIDEO_ON,
89 .amux = CX231XX_AMUX_LINE_IN,
Márton Németh7ee0a282009-12-13 17:06:10 -030090 .gpio = NULL,
Sri Deevi6e4f5742009-03-10 21:16:26 -030091 }
92 },
93 },
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -030094 [CX231XX_BOARD_CNXT_CARRAERA] = {
95 .name = "Conexant Hybrid TV - CARRAERA",
Sri Deevi6e4f5742009-03-10 21:16:26 -030096 .tuner_type = TUNER_XC5000,
97 .tuner_addr = 0x61,
98 .tuner_gpio = RDE250_XCV_TUNER,
99 .tuner_sif_gpio = 0x05,
100 .tuner_scl_gpio = 0x1a,
101 .tuner_sda_gpio = 0x1b,
102 .decoder = CX231XX_AVDECODER,
Devin Heitmueller88806212010-08-18 17:50:07 -0300103 .output_mode = OUT_MODE_VIP11,
Sri Deevi6e4f5742009-03-10 21:16:26 -0300104 .demod_xfer_mode = 0,
105 .ctl_pin_status_mask = 0xFFFFFFC4,
106 .agc_analog_digital_select_gpio = 0x0c,
107 .gpio_pin_status_mask = 0x4001000,
108 .tuner_i2c_master = 1,
109 .demod_i2c_master = 2,
110 .has_dvb = 1,
111 .demod_addr = 0x02,
112 .norm = V4L2_STD_PAL,
Sri Deevie0d3baf2009-03-03 14:37:50 -0300113
Sri Deevi6e4f5742009-03-10 21:16:26 -0300114 .input = {{
115 .type = CX231XX_VMUX_TELEVISION,
116 .vmux = CX231XX_VIN_3_1,
117 .amux = CX231XX_AMUX_VIDEO,
Márton Németh7ee0a282009-12-13 17:06:10 -0300118 .gpio = NULL,
Sri Deevi6e4f5742009-03-10 21:16:26 -0300119 }, {
120 .type = CX231XX_VMUX_COMPOSITE1,
121 .vmux = CX231XX_VIN_2_1,
122 .amux = CX231XX_AMUX_LINE_IN,
Márton Németh7ee0a282009-12-13 17:06:10 -0300123 .gpio = NULL,
Sri Deevi6e4f5742009-03-10 21:16:26 -0300124 }, {
125 .type = CX231XX_VMUX_SVIDEO,
126 .vmux = CX231XX_VIN_1_1 |
127 (CX231XX_VIN_1_2 << 8) |
128 CX25840_SVIDEO_ON,
129 .amux = CX231XX_AMUX_LINE_IN,
Márton Németh7ee0a282009-12-13 17:06:10 -0300130 .gpio = NULL,
Sri Deevi6e4f5742009-03-10 21:16:26 -0300131 }
132 },
133 },
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300134 [CX231XX_BOARD_CNXT_SHELBY] = {
135 .name = "Conexant Hybrid TV - SHELBY",
Sri Deevi6e4f5742009-03-10 21:16:26 -0300136 .tuner_type = TUNER_XC5000,
137 .tuner_addr = 0x61,
138 .tuner_gpio = RDE250_XCV_TUNER,
139 .tuner_sif_gpio = 0x05,
140 .tuner_scl_gpio = 0x1a,
141 .tuner_sda_gpio = 0x1b,
142 .decoder = CX231XX_AVDECODER,
Devin Heitmueller88806212010-08-18 17:50:07 -0300143 .output_mode = OUT_MODE_VIP11,
Sri Deevi6e4f5742009-03-10 21:16:26 -0300144 .demod_xfer_mode = 0,
145 .ctl_pin_status_mask = 0xFFFFFFC4,
146 .agc_analog_digital_select_gpio = 0x0c,
147 .gpio_pin_status_mask = 0x4001000,
148 .tuner_i2c_master = 1,
149 .demod_i2c_master = 2,
150 .has_dvb = 1,
151 .demod_addr = 0x32,
152 .norm = V4L2_STD_NTSC,
Sri Deevie0d3baf2009-03-03 14:37:50 -0300153
Sri Deevi6e4f5742009-03-10 21:16:26 -0300154 .input = {{
155 .type = CX231XX_VMUX_TELEVISION,
156 .vmux = CX231XX_VIN_3_1,
157 .amux = CX231XX_AMUX_VIDEO,
Márton Németh7ee0a282009-12-13 17:06:10 -0300158 .gpio = NULL,
Sri Deevi6e4f5742009-03-10 21:16:26 -0300159 }, {
160 .type = CX231XX_VMUX_COMPOSITE1,
161 .vmux = CX231XX_VIN_2_1,
162 .amux = CX231XX_AMUX_LINE_IN,
Márton Németh7ee0a282009-12-13 17:06:10 -0300163 .gpio = NULL,
Sri Deevi6e4f5742009-03-10 21:16:26 -0300164 }, {
165 .type = CX231XX_VMUX_SVIDEO,
166 .vmux = CX231XX_VIN_1_1 |
167 (CX231XX_VIN_1_2 << 8) |
168 CX25840_SVIDEO_ON,
169 .amux = CX231XX_AMUX_LINE_IN,
Márton Németh7ee0a282009-12-13 17:06:10 -0300170 .gpio = NULL,
Sri Deevi6e4f5742009-03-10 21:16:26 -0300171 }
172 },
173 },
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300174 [CX231XX_BOARD_CNXT_RDE_253S] = {
175 .name = "Conexant Hybrid TV - RDE253S",
176 .tuner_type = TUNER_NXP_TDA18271,
177 .tuner_addr = 0x60,
178 .tuner_gpio = RDE250_XCV_TUNER,
179 .tuner_sif_gpio = 0x05,
180 .tuner_scl_gpio = 0x1a,
181 .tuner_sda_gpio = 0x1b,
182 .decoder = CX231XX_AVDECODER,
Devin Heitmueller88806212010-08-18 17:50:07 -0300183 .output_mode = OUT_MODE_VIP11,
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300184 .demod_xfer_mode = 0,
185 .ctl_pin_status_mask = 0xFFFFFFC4,
186 .agc_analog_digital_select_gpio = 0x1c,
187 .gpio_pin_status_mask = 0x4001000,
188 .tuner_i2c_master = 1,
189 .demod_i2c_master = 2,
190 .has_dvb = 1,
191 .demod_addr = 0x02,
192 .norm = V4L2_STD_PAL,
193
194 .input = {{
195 .type = CX231XX_VMUX_TELEVISION,
196 .vmux = CX231XX_VIN_3_1,
197 .amux = CX231XX_AMUX_VIDEO,
198 .gpio = NULL,
199 }, {
200 .type = CX231XX_VMUX_COMPOSITE1,
201 .vmux = CX231XX_VIN_2_1,
202 .amux = CX231XX_AMUX_LINE_IN,
203 .gpio = NULL,
204 }, {
205 .type = CX231XX_VMUX_SVIDEO,
206 .vmux = CX231XX_VIN_1_1 |
207 (CX231XX_VIN_1_2 << 8) |
208 CX25840_SVIDEO_ON,
209 .amux = CX231XX_AMUX_LINE_IN,
210 .gpio = NULL,
211 }
212 },
213 },
214
215 [CX231XX_BOARD_CNXT_RDU_253S] = {
216 .name = "Conexant Hybrid TV - RDU253S",
217 .tuner_type = TUNER_NXP_TDA18271,
218 .tuner_addr = 0x60,
219 .tuner_gpio = RDE250_XCV_TUNER,
220 .tuner_sif_gpio = 0x05,
221 .tuner_scl_gpio = 0x1a,
222 .tuner_sda_gpio = 0x1b,
223 .decoder = CX231XX_AVDECODER,
Devin Heitmueller88806212010-08-18 17:50:07 -0300224 .output_mode = OUT_MODE_VIP11,
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300225 .demod_xfer_mode = 0,
226 .ctl_pin_status_mask = 0xFFFFFFC4,
227 .agc_analog_digital_select_gpio = 0x1c,
228 .gpio_pin_status_mask = 0x4001000,
229 .tuner_i2c_master = 1,
230 .demod_i2c_master = 2,
231 .has_dvb = 1,
232 .demod_addr = 0x02,
233 .norm = V4L2_STD_PAL,
234
235 .input = {{
236 .type = CX231XX_VMUX_TELEVISION,
237 .vmux = CX231XX_VIN_3_1,
238 .amux = CX231XX_AMUX_VIDEO,
239 .gpio = NULL,
240 }, {
241 .type = CX231XX_VMUX_COMPOSITE1,
242 .vmux = CX231XX_VIN_2_1,
243 .amux = CX231XX_AMUX_LINE_IN,
244 .gpio = NULL,
245 }, {
246 .type = CX231XX_VMUX_SVIDEO,
247 .vmux = CX231XX_VIN_1_1 |
248 (CX231XX_VIN_1_2 << 8) |
249 CX25840_SVIDEO_ON,
250 .amux = CX231XX_AMUX_LINE_IN,
251 .gpio = NULL,
252 }
253 },
254 },
255 [CX231XX_BOARD_CNXT_VIDEO_GRABBER] = {
256 .name = "Conexant VIDEO GRABBER",
Devin Heitmueller9f512592010-08-18 18:04:04 -0300257 .tuner_type = TUNER_ABSENT,
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300258 .decoder = CX231XX_AVDECODER,
Devin Heitmueller88806212010-08-18 17:50:07 -0300259 .output_mode = OUT_MODE_VIP11,
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300260 .ctl_pin_status_mask = 0xFFFFFFC4,
261 .agc_analog_digital_select_gpio = 0x1c,
262 .gpio_pin_status_mask = 0x4001000,
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300263 .norm = V4L2_STD_PAL,
Mauro Carvalho Chehab2f861382011-01-31 22:12:15 -0300264 .no_alt_vanc = 1,
265 .external_av = 1,
266 .has_417 = 1,
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300267
268 .input = {{
269 .type = CX231XX_VMUX_COMPOSITE1,
270 .vmux = CX231XX_VIN_2_1,
271 .amux = CX231XX_AMUX_LINE_IN,
272 .gpio = NULL,
273 }, {
274 .type = CX231XX_VMUX_SVIDEO,
275 .vmux = CX231XX_VIN_1_1 |
276 (CX231XX_VIN_1_2 << 8) |
277 CX25840_SVIDEO_ON,
278 .amux = CX231XX_AMUX_LINE_IN,
279 .gpio = NULL,
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300280 }
281 },
282 },
283 [CX231XX_BOARD_CNXT_RDE_250] = {
284 .name = "Conexant Hybrid TV - rde 250",
285 .tuner_type = TUNER_XC5000,
286 .tuner_addr = 0x61,
287 .tuner_gpio = RDE250_XCV_TUNER,
288 .tuner_sif_gpio = 0x05,
289 .tuner_scl_gpio = 0x1a,
290 .tuner_sda_gpio = 0x1b,
291 .decoder = CX231XX_AVDECODER,
Devin Heitmueller88806212010-08-18 17:50:07 -0300292 .output_mode = OUT_MODE_VIP11,
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300293 .demod_xfer_mode = 0,
294 .ctl_pin_status_mask = 0xFFFFFFC4,
295 .agc_analog_digital_select_gpio = 0x0c,
296 .gpio_pin_status_mask = 0x4001000,
297 .tuner_i2c_master = 1,
298 .demod_i2c_master = 2,
299 .has_dvb = 1,
300 .demod_addr = 0x02,
301 .norm = V4L2_STD_PAL,
302
303 .input = {{
304 .type = CX231XX_VMUX_TELEVISION,
305 .vmux = CX231XX_VIN_2_1,
306 .amux = CX231XX_AMUX_VIDEO,
307 .gpio = NULL,
308 }
309 },
310 },
311 [CX231XX_BOARD_CNXT_RDU_250] = {
312 .name = "Conexant Hybrid TV - RDU 250",
313 .tuner_type = TUNER_XC5000,
314 .tuner_addr = 0x61,
315 .tuner_gpio = RDE250_XCV_TUNER,
316 .tuner_sif_gpio = 0x05,
317 .tuner_scl_gpio = 0x1a,
318 .tuner_sda_gpio = 0x1b,
319 .decoder = CX231XX_AVDECODER,
Devin Heitmueller88806212010-08-18 17:50:07 -0300320 .output_mode = OUT_MODE_VIP11,
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300321 .demod_xfer_mode = 0,
322 .ctl_pin_status_mask = 0xFFFFFFC4,
323 .agc_analog_digital_select_gpio = 0x0c,
324 .gpio_pin_status_mask = 0x4001000,
325 .tuner_i2c_master = 1,
326 .demod_i2c_master = 2,
327 .has_dvb = 1,
328 .demod_addr = 0x32,
329 .norm = V4L2_STD_NTSC,
330
331 .input = {{
332 .type = CX231XX_VMUX_TELEVISION,
333 .vmux = CX231XX_VIN_2_1,
334 .amux = CX231XX_AMUX_VIDEO,
335 .gpio = NULL,
336 }
337 },
338 },
Michael Krufky1a50fdd2010-07-06 18:23:53 -0300339 [CX231XX_BOARD_HAUPPAUGE_EXETER] = {
340 .name = "Hauppauge EXETER",
341 .tuner_type = TUNER_NXP_TDA18271,
342 .tuner_addr = 0x60,
343 .tuner_gpio = RDE250_XCV_TUNER,
344 .tuner_sif_gpio = 0x05,
345 .tuner_scl_gpio = 0x1a,
346 .tuner_sda_gpio = 0x1b,
347 .decoder = CX231XX_AVDECODER,
Devin Heitmueller88806212010-08-18 17:50:07 -0300348 .output_mode = OUT_MODE_VIP11,
Michael Krufky1a50fdd2010-07-06 18:23:53 -0300349 .demod_xfer_mode = 0,
350 .ctl_pin_status_mask = 0xFFFFFFC4,
351 .agc_analog_digital_select_gpio = 0x0c,
352 .gpio_pin_status_mask = 0x4001000,
353 .tuner_i2c_master = 1,
354 .demod_i2c_master = 2,
355 .has_dvb = 1,
356 .demod_addr = 0x0e,
357 .norm = V4L2_STD_NTSC,
358
359 .input = {{
360 .type = CX231XX_VMUX_TELEVISION,
361 .vmux = CX231XX_VIN_3_1,
362 .amux = CX231XX_AMUX_VIDEO,
Peter Huewef72cfd82011-01-25 17:38:52 -0300363 .gpio = NULL,
Michael Krufky1a50fdd2010-07-06 18:23:53 -0300364 }, {
365 .type = CX231XX_VMUX_COMPOSITE1,
366 .vmux = CX231XX_VIN_2_1,
367 .amux = CX231XX_AMUX_LINE_IN,
Peter Huewef72cfd82011-01-25 17:38:52 -0300368 .gpio = NULL,
Michael Krufky1a50fdd2010-07-06 18:23:53 -0300369 }, {
370 .type = CX231XX_VMUX_SVIDEO,
371 .vmux = CX231XX_VIN_1_1 |
372 (CX231XX_VIN_1_2 << 8) |
373 CX25840_SVIDEO_ON,
374 .amux = CX231XX_AMUX_LINE_IN,
Peter Huewef72cfd82011-01-25 17:38:52 -0300375 .gpio = NULL,
Michael Krufky1a50fdd2010-07-06 18:23:53 -0300376 } },
377 },
Devin Heitmueller4270c3c2010-07-31 00:49:01 -0300378 [CX231XX_BOARD_HAUPPAUGE_USBLIVE2] = {
379 .name = "Hauppauge USB Live 2",
380 .tuner_type = TUNER_ABSENT,
381 .decoder = CX231XX_AVDECODER,
Devin Heitmueller88806212010-08-18 17:50:07 -0300382 .output_mode = OUT_MODE_VIP11,
Devin Heitmueller4270c3c2010-07-31 00:49:01 -0300383 .demod_xfer_mode = 0,
384 .ctl_pin_status_mask = 0xFFFFFFC4,
385 .agc_analog_digital_select_gpio = 0x0c,
386 .gpio_pin_status_mask = 0x4001000,
387 .norm = V4L2_STD_NTSC,
Mauro Carvalho Chehab2f861382011-01-31 22:12:15 -0300388 .no_alt_vanc = 1,
389 .external_av = 1,
Devin Heitmueller4270c3c2010-07-31 00:49:01 -0300390 .input = {{
391 .type = CX231XX_VMUX_COMPOSITE1,
392 .vmux = CX231XX_VIN_2_1,
393 .amux = CX231XX_AMUX_LINE_IN,
Peter Huewef72cfd82011-01-25 17:38:52 -0300394 .gpio = NULL,
Devin Heitmueller4270c3c2010-07-31 00:49:01 -0300395 }, {
396 .type = CX231XX_VMUX_SVIDEO,
397 .vmux = CX231XX_VIN_1_1 |
398 (CX231XX_VIN_1_2 << 8) |
399 CX25840_SVIDEO_ON,
400 .amux = CX231XX_AMUX_LINE_IN,
Peter Huewef72cfd82011-01-25 17:38:52 -0300401 .gpio = NULL,
Devin Heitmueller4270c3c2010-07-31 00:49:01 -0300402 } },
403 },
Mauro Carvalho Chehab9417bc62010-09-26 20:44:31 -0300404 [CX231XX_BOARD_PV_PLAYTV_USB_HYBRID] = {
405 .name = "Pixelview PlayTV USB Hybrid",
406 .tuner_type = TUNER_NXP_TDA18271,
407 .tuner_addr = 0x60,
408 .decoder = CX231XX_AVDECODER,
409 .output_mode = OUT_MODE_VIP11,
410 .demod_xfer_mode = 0,
411 .ctl_pin_status_mask = 0xFFFFFFC4,
412 .agc_analog_digital_select_gpio = 0x00, /* According with PV cxPolaris.inf file */
413 .tuner_sif_gpio = -1,
414 .tuner_scl_gpio = -1,
415 .tuner_sda_gpio = -1,
416 .gpio_pin_status_mask = 0x4001000,
417 .tuner_i2c_master = 2,
418 .demod_i2c_master = 1,
Mauro Carvalho Chehab1bc25f72010-10-23 13:35:58 -0300419 .ir_i2c_master = 2,
Mauro Carvalho Chehab788e5d42010-12-17 14:47:27 -0300420 .rc_map_name = RC_MAP_PIXELVIEW_002T,
Mauro Carvalho Chehabede676c2010-09-27 23:44:27 -0300421 .has_dvb = 1,
Mauro Carvalho Chehab9417bc62010-09-26 20:44:31 -0300422 .demod_addr = 0x10,
423 .norm = V4L2_STD_PAL_M,
424 .input = {{
425 .type = CX231XX_VMUX_TELEVISION,
426 .vmux = CX231XX_VIN_3_1,
427 .amux = CX231XX_AMUX_VIDEO,
Peter Huewef72cfd82011-01-25 17:38:52 -0300428 .gpio = NULL,
Mauro Carvalho Chehab9417bc62010-09-26 20:44:31 -0300429 }, {
430 .type = CX231XX_VMUX_COMPOSITE1,
431 .vmux = CX231XX_VIN_2_1,
432 .amux = CX231XX_AMUX_LINE_IN,
Peter Huewef72cfd82011-01-25 17:38:52 -0300433 .gpio = NULL,
Mauro Carvalho Chehab9417bc62010-09-26 20:44:31 -0300434 }, {
435 .type = CX231XX_VMUX_SVIDEO,
436 .vmux = CX231XX_VIN_1_1 |
437 (CX231XX_VIN_1_2 << 8) |
438 CX25840_SVIDEO_ON,
439 .amux = CX231XX_AMUX_LINE_IN,
Peter Huewef72cfd82011-01-25 17:38:52 -0300440 .gpio = NULL,
Mauro Carvalho Chehab9417bc62010-09-26 20:44:31 -0300441 } },
442 },
Mauro Carvalho Chehab4e105032011-01-31 22:18:21 -0300443 [CX231XX_BOARD_PV_XCAPTURE_USB] = {
444 .name = "Pixelview Xcapture USB",
445 .tuner_type = TUNER_ABSENT,
446 .decoder = CX231XX_AVDECODER,
447 .output_mode = OUT_MODE_VIP11,
448 .demod_xfer_mode = 0,
449 .ctl_pin_status_mask = 0xFFFFFFC4,
450 .agc_analog_digital_select_gpio = 0x0c,
451 .gpio_pin_status_mask = 0x4001000,
452 .norm = V4L2_STD_NTSC,
453 .no_alt_vanc = 1,
454 .external_av = 1,
455 .dont_use_port_3 = 1,
456
457 .input = {{
458 .type = CX231XX_VMUX_COMPOSITE1,
459 .vmux = CX231XX_VIN_2_1,
460 .amux = CX231XX_AMUX_LINE_IN,
461 .gpio = NULL,
462 }, {
463 .type = CX231XX_VMUX_SVIDEO,
464 .vmux = CX231XX_VIN_1_1 |
465 (CX231XX_VIN_1_2 << 8) |
466 CX25840_SVIDEO_ON,
467 .amux = CX231XX_AMUX_LINE_IN,
468 .gpio = NULL,
469 }
470 },
471 },
Sri Deevie0d3baf2009-03-03 14:37:50 -0300472};
473const unsigned int cx231xx_bcount = ARRAY_SIZE(cx231xx_boards);
474
475/* table of devices that work with this driver */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300476struct usb_device_id cx231xx_id_table[] = {
Sri Deevied559ed2009-03-13 18:35:14 -0300477 {USB_DEVICE(0x0572, 0x5A3C),
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300478 .driver_info = CX231XX_BOARD_UNKNOWN},
479 {USB_DEVICE(0x0572, 0x58A2),
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300480 .driver_info = CX231XX_BOARD_CNXT_CARRAERA},
Sri Deevied559ed2009-03-13 18:35:14 -0300481 {USB_DEVICE(0x0572, 0x58A1),
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300482 .driver_info = CX231XX_BOARD_CNXT_SHELBY},
483 {USB_DEVICE(0x0572, 0x58A4),
484 .driver_info = CX231XX_BOARD_CNXT_RDE_253S},
485 {USB_DEVICE(0x0572, 0x58A5),
486 .driver_info = CX231XX_BOARD_CNXT_RDU_253S},
487 {USB_DEVICE(0x0572, 0x58A6),
488 .driver_info = CX231XX_BOARD_CNXT_VIDEO_GRABBER},
489 {USB_DEVICE(0x0572, 0x589E),
490 .driver_info = CX231XX_BOARD_CNXT_RDE_250},
491 {USB_DEVICE(0x0572, 0x58A0),
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300492 .driver_info = CX231XX_BOARD_CNXT_RDU_250},
Michael Krufky1a50fdd2010-07-06 18:23:53 -0300493 {USB_DEVICE(0x2040, 0xb120),
494 .driver_info = CX231XX_BOARD_HAUPPAUGE_EXETER},
Devin Heitmuellerd78148f2010-07-06 18:25:19 -0300495 {USB_DEVICE(0x2040, 0xb140),
496 .driver_info = CX231XX_BOARD_HAUPPAUGE_EXETER},
Devin Heitmueller4270c3c2010-07-31 00:49:01 -0300497 {USB_DEVICE(0x2040, 0xc200),
498 .driver_info = CX231XX_BOARD_HAUPPAUGE_USBLIVE2},
Mauro Carvalho Chehab9417bc62010-09-26 20:44:31 -0300499 {USB_DEVICE_VER(USB_VID_PIXELVIEW, USB_PID_PIXELVIEW_SBTVD, 0x4000, 0x4001),
500 .driver_info = CX231XX_BOARD_PV_PLAYTV_USB_HYBRID},
Mauro Carvalho Chehab4e105032011-01-31 22:18:21 -0300501 {USB_DEVICE(USB_VID_PIXELVIEW, 0x5014),
502 .driver_info = CX231XX_BOARD_PV_XCAPTURE_USB},
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300503 {},
Sri Deevie0d3baf2009-03-03 14:37:50 -0300504};
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300505
Sri Deevie0d3baf2009-03-03 14:37:50 -0300506MODULE_DEVICE_TABLE(usb, cx231xx_id_table);
507
508/* cx231xx_tuner_callback
509 * will be used to reset XC5000 tuner using GPIO pin
510 */
511
512int cx231xx_tuner_callback(void *ptr, int component, int command, int arg)
513{
514 int rc = 0;
515 struct cx231xx *dev = ptr;
516
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300517 if (dev->tuner_type == TUNER_XC5000) {
518 if (command == XC5000_TUNER_RESET) {
519 cx231xx_info
Sri Deevib9255172009-03-04 17:49:01 -0300520 ("Tuner CB: RESET: cmd %d : tuner type %d \n",
521 command, dev->tuner_type);
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300522 cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit,
523 1);
524 msleep(10);
525 cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit,
526 0);
527 msleep(330);
528 cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit,
529 1);
530 msleep(10);
531 }
Mauro Carvalho Chehab55fa2882010-09-29 11:07:08 -0300532 } else if (dev->tuner_type == TUNER_NXP_TDA18271) {
533 switch (command) {
534 case TDA18271_CALLBACK_CMD_AGC_ENABLE:
535 if (dev->model == CX231XX_BOARD_PV_PLAYTV_USB_HYBRID)
536 rc = cx231xx_set_agc_analog_digital_mux_select(dev, arg);
537 break;
538 default:
539 rc = -EINVAL;
540 break;
541 }
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300542 }
Sri Deevie0d3baf2009-03-03 14:37:50 -0300543 return rc;
544}
545EXPORT_SYMBOL_GPL(cx231xx_tuner_callback);
546
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300547void cx231xx_reset_out(struct cx231xx *dev)
548{
549 cx231xx_set_gpio_value(dev, CX23417_RESET, 1);
550 msleep(200);
551 cx231xx_set_gpio_value(dev, CX23417_RESET, 0);
552 msleep(200);
553 cx231xx_set_gpio_value(dev, CX23417_RESET, 1);
554}
555void cx231xx_enable_OSC(struct cx231xx *dev)
556{
557 cx231xx_set_gpio_value(dev, CX23417_OSC_EN, 1);
558}
559void cx231xx_sleep_s5h1432(struct cx231xx *dev)
560{
561 cx231xx_set_gpio_value(dev, SLEEP_S5H1432, 0);
562}
563
Sri Deevib9255172009-03-04 17:49:01 -0300564static inline void cx231xx_set_model(struct cx231xx *dev)
Sri Deevie0d3baf2009-03-03 14:37:50 -0300565{
566 memcpy(&dev->board, &cx231xx_boards[dev->model], sizeof(dev->board));
567}
568
569/* Since cx231xx_pre_card_setup() requires a proper dev->model,
570 * this won't work for boards with generic PCI IDs
571 */
572void cx231xx_pre_card_setup(struct cx231xx *dev)
573{
574
575 cx231xx_set_model(dev);
576
577 cx231xx_info("Identified as %s (card=%d)\n",
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300578 dev->board.name, dev->model);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300579
Sri Deevi6e4f5742009-03-10 21:16:26 -0300580 /* set the direction for GPIO pins */
Mauro Carvalho Chehabc10469c2010-09-11 11:37:51 -0300581 if (dev->board.tuner_gpio) {
582 cx231xx_set_gpio_direction(dev, dev->board.tuner_gpio->bit, 1);
583 cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit, 1);
Mauro Carvalho Chehab78bb6df2010-09-26 20:48:38 -0300584 }
585 if (dev->board.tuner_sif_gpio >= 0)
Mauro Carvalho Chehabc10469c2010-09-11 11:37:51 -0300586 cx231xx_set_gpio_direction(dev, dev->board.tuner_sif_gpio, 1);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300587
Mauro Carvalho Chehab78bb6df2010-09-26 20:48:38 -0300588 /* request some modules if any required */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300589
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300590 /* set the mode to Analog mode initially */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300591 cx231xx_set_mode(dev, CX231XX_ANALOG_MODE);
592
593 /* Unlock device */
594 /* cx231xx_set_mode(dev, CX231XX_SUSPEND); */
595
596}
597
Sri Deevie0d3baf2009-03-03 14:37:50 -0300598static void cx231xx_config_tuner(struct cx231xx *dev)
599{
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300600 struct tuner_setup tun_setup;
601 struct v4l2_frequency f;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300602
603 if (dev->tuner_type == TUNER_ABSENT)
604 return;
605
606 tun_setup.mode_mask = T_ANALOG_TV | T_RADIO;
607 tun_setup.type = dev->tuner_type;
608 tun_setup.addr = dev->tuner_addr;
609 tun_setup.tuner_callback = cx231xx_tuner_callback;
610
Sri Deevib1196122009-03-20 23:33:48 -0300611 tuner_call(dev, tuner, s_type_addr, &tun_setup);
612
Sri Deevie0d3baf2009-03-03 14:37:50 -0300613#if 0
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300614 if (tun_setup.type == TUNER_XC5000) {
Sri Deevie0d3baf2009-03-03 14:37:50 -0300615 static struct xc2028_ctrl ctrl = {
616 .fname = XC5000_DEFAULT_FIRMWARE,
617 .max_len = 64,
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300618 .demod = 0;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300619 };
620 struct v4l2_priv_tun_config cfg = {
621 .tuner = dev->tuner_type,
622 .priv = &ctrl,
623 };
Sri Deevib1196122009-03-20 23:33:48 -0300624 tuner_call(dev, tuner, s_config, &cfg);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300625 }
626#endif
Sri Deevie0d3baf2009-03-03 14:37:50 -0300627 /* configure tuner */
628 f.tuner = 0;
629 f.type = V4L2_TUNER_ANALOG_TV;
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300630 f.frequency = 9076; /* just a magic number */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300631 dev->ctl_freq = f.frequency;
Sri Deevib1196122009-03-20 23:33:48 -0300632 call_all(dev, tuner, s_frequency, &f);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300633
Sri Deevib1196122009-03-20 23:33:48 -0300634}
Sri Deevie0d3baf2009-03-03 14:37:50 -0300635
Sri Deevie0d3baf2009-03-03 14:37:50 -0300636void cx231xx_card_setup(struct cx231xx *dev)
637{
Sri Deevib1196122009-03-20 23:33:48 -0300638
Sri Deevie0d3baf2009-03-03 14:37:50 -0300639 cx231xx_set_model(dev);
640
641 dev->tuner_type = cx231xx_boards[dev->model].tuner_type;
642 if (cx231xx_boards[dev->model].tuner_addr)
643 dev->tuner_addr = cx231xx_boards[dev->model].tuner_addr;
644
Sri Deevie0d3baf2009-03-03 14:37:50 -0300645 /* request some modules */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300646 if (dev->board.decoder == CX231XX_AVDECODER) {
Hans Verkuile6574f22009-04-01 03:57:53 -0300647 dev->sd_cx25840 = v4l2_i2c_new_subdev(&dev->v4l2_dev,
648 &dev->i2c_bus[0].i2c_adap,
Laurent Pinchart9a1f8b32010-09-24 10:16:44 -0300649 "cx25840", 0x88 >> 1, NULL);
Sri Deevib1196122009-03-20 23:33:48 -0300650 if (dev->sd_cx25840 == NULL)
651 cx231xx_info("cx25840 subdev registration failure\n");
Hans Verkuilcc26b072009-03-29 19:20:26 -0300652 cx25840_call(dev, core, load_fw);
Sri Deevib1196122009-03-20 23:33:48 -0300653
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300654 }
Sri Deevib1196122009-03-20 23:33:48 -0300655
Devin Heitmuellere3e0aaa2010-07-08 17:05:30 -0300656 /* Initialize the tuner */
657 if (dev->board.tuner_type != TUNER_ABSENT) {
658 dev->sd_tuner = v4l2_i2c_new_subdev(&dev->v4l2_dev,
Mauro Carvalho Chehab1a4aa922010-09-26 20:01:51 -0300659 &dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap,
Laurent Pinchart9a1f8b32010-09-24 10:16:44 -0300660 "tuner",
Devin Heitmuellere3e0aaa2010-07-08 17:05:30 -0300661 dev->tuner_addr, NULL);
662 if (dev->sd_tuner == NULL)
663 cx231xx_info("tuner subdev registration failure\n");
664 else
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300665 cx231xx_config_tuner(dev);
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300666 }
Sri Deevie0d3baf2009-03-03 14:37:50 -0300667}
668
Sri Deevie0d3baf2009-03-03 14:37:50 -0300669/*
670 * cx231xx_config()
671 * inits registers with sane defaults
672 */
673int cx231xx_config(struct cx231xx *dev)
674{
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300675 /* TBD need to add cx231xx specific code */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300676 dev->mute = 1; /* maybe not the right place... */
677 dev->volume = 0x1f;
678
679 return 0;
680}
681
682/*
683 * cx231xx_config_i2c()
684 * configure i2c attached devices
685 */
686void cx231xx_config_i2c(struct cx231xx *dev)
687{
Hans Verkuil5325b422009-04-02 11:26:22 -0300688 /* u32 input = INPUT(dev->video_input)->vmux; */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300689
Sri Deevib1196122009-03-20 23:33:48 -0300690 call_all(dev, video, s_stream, 1);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300691}
692
693/*
694 * cx231xx_realease_resources()
695 * unregisters the v4l2,i2c and usb devices
696 * called when the device gets disconected or at module unload
697*/
698void cx231xx_release_resources(struct cx231xx *dev)
699{
Sri Deevie0d3baf2009-03-03 14:37:50 -0300700 cx231xx_release_analog_resources(dev);
701
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300702 cx231xx_remove_from_devlist(dev);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300703
Mauro Carvalho Chehab9ab66912010-10-23 13:28:33 -0300704 /* Release I2C buses */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300705 cx231xx_dev_uninit(dev);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300706
Mauro Carvalho Chehab9ab66912010-10-23 13:28:33 -0300707 cx231xx_ir_exit(dev);
708
Sri Deevie0d3baf2009-03-03 14:37:50 -0300709 usb_put_dev(dev->udev);
710
711 /* Mark device as unused */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300712 cx231xx_devused &= ~(1 << dev->devno);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300713}
714
Sri Deevie0d3baf2009-03-03 14:37:50 -0300715/*
716 * cx231xx_init_dev()
717 * allocates and inits the device structs, registers i2c bus and v4l device
718 */
719static int cx231xx_init_dev(struct cx231xx **devhandle, struct usb_device *udev,
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300720 int minor)
Sri Deevie0d3baf2009-03-03 14:37:50 -0300721{
722 struct cx231xx *dev = *devhandle;
723 int retval = -ENOMEM;
724 int errCode;
725 unsigned int maxh, maxw;
726
727 dev->udev = udev;
728 mutex_init(&dev->lock);
729 mutex_init(&dev->ctrl_urb_lock);
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300730 mutex_init(&dev->gpio_i2c_lock);
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300731 mutex_init(&dev->i2c_lock);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300732
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300733 spin_lock_init(&dev->video_mode.slock);
734 spin_lock_init(&dev->vbi_mode.slock);
735 spin_lock_init(&dev->sliced_cc_mode.slock);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300736
737 init_waitqueue_head(&dev->open);
738 init_waitqueue_head(&dev->wait_frame);
739 init_waitqueue_head(&dev->wait_stream);
740
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300741 dev->cx231xx_read_ctrl_reg = cx231xx_read_ctrl_reg;
742 dev->cx231xx_write_ctrl_reg = cx231xx_write_ctrl_reg;
743 dev->cx231xx_send_usb_command = cx231xx_send_usb_command;
744 dev->cx231xx_gpio_i2c_read = cx231xx_gpio_i2c_read;
745 dev->cx231xx_gpio_i2c_write = cx231xx_gpio_i2c_write;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300746
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300747 /* Query cx231xx to find what pcb config it is related to */
748 initialize_cx231xx(dev);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300749
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300750 /*To workaround error number=-71 on EP0 for VideoGrabber,
751 need set alt here.*/
Devin Heitmueller4270c3c2010-07-31 00:49:01 -0300752 if (dev->model == CX231XX_BOARD_CNXT_VIDEO_GRABBER ||
753 dev->model == CX231XX_BOARD_HAUPPAUGE_USBLIVE2) {
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300754 cx231xx_set_alt_setting(dev, INDEX_VIDEO, 3);
755 cx231xx_set_alt_setting(dev, INDEX_VANC, 1);
756 }
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300757 /* Cx231xx pre card setup */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300758 cx231xx_pre_card_setup(dev);
759
760 errCode = cx231xx_config(dev);
761 if (errCode) {
762 cx231xx_errdev("error configuring device\n");
763 return -ENOMEM;
764 }
765
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300766 /* set default norm */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300767 dev->norm = dev->board.norm;
768
769 /* register i2c bus */
770 errCode = cx231xx_dev_init(dev);
771 if (errCode < 0) {
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300772 cx231xx_dev_uninit(dev);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300773 cx231xx_errdev("%s: cx231xx_i2c_register - errCode [%d]!\n",
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300774 __func__, errCode);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300775 return errCode;
776 }
777
778 /* Do board specific init */
779 cx231xx_card_setup(dev);
780
781 /* configure the device */
782 cx231xx_config_i2c(dev);
783
784 maxw = norm_maxw(dev);
785 maxh = norm_maxh(dev);
786
787 /* set default image size */
788 dev->width = maxw;
789 dev->height = maxh;
790 dev->interlaced = 0;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300791 dev->video_input = 0;
792
793 errCode = cx231xx_config(dev);
794 if (errCode < 0) {
795 cx231xx_errdev("%s: cx231xx_config - errCode [%d]!\n",
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300796 __func__, errCode);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300797 return errCode;
798 }
799
800 /* init video dma queues */
801 INIT_LIST_HEAD(&dev->video_mode.vidq.active);
802 INIT_LIST_HEAD(&dev->video_mode.vidq.queued);
803
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300804 /* init vbi dma queues */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300805 INIT_LIST_HEAD(&dev->vbi_mode.vidq.active);
806 INIT_LIST_HEAD(&dev->vbi_mode.vidq.queued);
807
808 /* Reset other chips required if they are tied up with GPIO pins */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300809 cx231xx_add_into_devlist(dev);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300810
Mauro Carvalho Chehab2f861382011-01-31 22:12:15 -0300811 if (dev->board.has_417) {
Devin Heitmueller2b43db32010-08-18 18:09:28 -0300812 printk(KERN_INFO "attach 417 %d\n", dev->model);
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300813 if (cx231xx_417_register(dev) < 0) {
814 printk(KERN_ERR
815 "%s() Failed to register 417 on VID_B\n",
816 __func__);
817 }
818 }
819
Sri Deevie0d3baf2009-03-03 14:37:50 -0300820 retval = cx231xx_register_analog_devices(dev);
821 if (retval < 0) {
822 cx231xx_release_resources(dev);
Dan Carpenter5ae094c2010-11-18 00:56:37 -0300823 return retval;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300824 }
825
Mauro Carvalho Chehab9ab66912010-10-23 13:28:33 -0300826 cx231xx_ir_init(dev);
827
Sri Deevie0d3baf2009-03-03 14:37:50 -0300828 cx231xx_init_extension(dev);
829
830 return 0;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300831}
832
833#if defined(CONFIG_MODULES) && defined(MODULE)
834static void request_module_async(struct work_struct *work)
835{
836 struct cx231xx *dev = container_of(work,
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300837 struct cx231xx, request_module_wk);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300838
839 if (dev->has_alsa_audio)
840 request_module("cx231xx-alsa");
841
842 if (dev->board.has_dvb)
843 request_module("cx231xx-dvb");
844
845}
846
847static void request_modules(struct cx231xx *dev)
848{
849 INIT_WORK(&dev->request_module_wk, request_module_async);
850 schedule_work(&dev->request_module_wk);
851}
Tejun Heo707bcf32010-12-24 16:14:20 +0100852
853static void flush_request_modules(struct cx231xx *dev)
854{
855 flush_work_sync(&dev->request_module_wk);
856}
Sri Deevie0d3baf2009-03-03 14:37:50 -0300857#else
858#define request_modules(dev)
Tejun Heo707bcf32010-12-24 16:14:20 +0100859#define flush_request_modules(dev)
Sri Deevie0d3baf2009-03-03 14:37:50 -0300860#endif /* CONFIG_MODULES */
861
Sri Deevie0d3baf2009-03-03 14:37:50 -0300862/*
863 * cx231xx_usb_probe()
864 * checks for supported devices
865 */
866static int cx231xx_usb_probe(struct usb_interface *interface,
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300867 const struct usb_device_id *id)
Sri Deevie0d3baf2009-03-03 14:37:50 -0300868{
869 struct usb_device *udev;
870 struct usb_interface *uif;
871 struct cx231xx *dev = NULL;
872 int retval = -ENODEV;
Hans Verkuild73abcf2009-03-12 18:38:40 -0300873 int nr = 0, ifnum;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300874 int i, isoc_pipe = 0;
875 char *speed;
876 char descr[255] = "";
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300877 struct usb_interface *lif = NULL;
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300878 struct usb_interface_assoc_descriptor *assoc_desc;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300879
880 udev = usb_get_dev(interface_to_usbdev(interface));
881 ifnum = interface->altsetting[0].desc.bInterfaceNumber;
882
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -0300883 /*
884 * Interface number 0 - IR interface (handled by mceusb driver)
885 * Interface number 1 - AV interface (handled by this driver)
886 */
887 if (ifnum != 1)
888 return -ENODEV;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300889
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -0300890 /* Check to see next free device and mark as used */
891 nr = find_first_zero_bit(&cx231xx_devused, CX231XX_MAXBOARDS);
892 cx231xx_devused |= 1 << nr;
893
894 if (nr >= CX231XX_MAXBOARDS) {
895 cx231xx_err(DRIVER_NAME
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300896 ": Supports only %i cx231xx boards.\n", CX231XX_MAXBOARDS);
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -0300897 cx231xx_devused &= ~(1 << nr);
898 return -ENOMEM;
899 }
Sri Deevie0d3baf2009-03-03 14:37:50 -0300900
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -0300901 /* allocate memory for our device state and initialize it */
902 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
903 if (dev == NULL) {
904 cx231xx_err(DRIVER_NAME ": out of memory!\n");
905 cx231xx_devused &= ~(1 << nr);
906 return -ENOMEM;
907 }
Sri Deevie0d3baf2009-03-03 14:37:50 -0300908
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -0300909 snprintf(dev->name, 29, "cx231xx #%d", nr);
910 dev->devno = nr;
911 dev->model = id->driver_info;
912 dev->video_mode.alt = -1;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300913
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -0300914 dev->interface_count++;
915 /* reset gpio dir and value */
916 dev->gpio_dir = 0;
917 dev->gpio_val = 0;
918 dev->xc_fw_load_done = 0;
919 dev->has_alsa_audio = 1;
920 dev->power_mode = -1;
921 atomic_set(&dev->devlist_count, 0);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300922
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -0300923 /* 0 - vbi ; 1 -sliced cc mode */
924 dev->vbi_or_sliced_cc_mode = 0;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300925
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -0300926 /* get maximum no.of IAD interfaces */
927 assoc_desc = udev->actconfig->intf_assoc[0];
928 dev->max_iad_interface_count = assoc_desc->bInterfaceCount;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300929
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -0300930 /* init CIR module TBD */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300931
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -0300932 /* store the current interface */
933 lif = interface;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300934
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -0300935 /*mode_tv: digital=1 or analog=0*/
936 dev->mode_tv = 0;
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300937
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -0300938 dev->USE_ISO = transfer_mode;
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300939
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -0300940 switch (udev->speed) {
941 case USB_SPEED_LOW:
942 speed = "1.5";
943 break;
944 case USB_SPEED_UNKNOWN:
945 case USB_SPEED_FULL:
946 speed = "12";
947 break;
948 case USB_SPEED_HIGH:
949 speed = "480";
950 break;
951 default:
952 speed = "unknown";
953 }
Sri Deevie0d3baf2009-03-03 14:37:50 -0300954
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -0300955 if (udev->manufacturer)
956 strlcpy(descr, udev->manufacturer, sizeof(descr));
Sri Deevie0d3baf2009-03-03 14:37:50 -0300957
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -0300958 if (udev->product) {
Sri Deevie0d3baf2009-03-03 14:37:50 -0300959 if (*descr)
960 strlcat(descr, " ", sizeof(descr));
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -0300961 strlcat(descr, udev->product, sizeof(descr));
962 }
963 if (*descr)
964 strlcat(descr, " ", sizeof(descr));
Sri Deevie0d3baf2009-03-03 14:37:50 -0300965
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -0300966 cx231xx_info("New device %s@ %s Mbps "
967 "(%04x:%04x) with %d interfaces\n",
968 descr,
969 speed,
970 le16_to_cpu(udev->descriptor.idVendor),
971 le16_to_cpu(udev->descriptor.idProduct),
972 dev->max_iad_interface_count);
Sri Deevib1196122009-03-20 23:33:48 -0300973
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -0300974 /* store the interface 0 back */
975 lif = udev->actconfig->interface[0];
Sri Deevie0d3baf2009-03-03 14:37:50 -0300976
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -0300977 /* increment interface count */
978 dev->interface_count++;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300979
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -0300980 /* get device number */
981 nr = dev->devno;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300982
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -0300983 assoc_desc = udev->actconfig->intf_assoc[0];
984 if (assoc_desc->bFirstInterface != ifnum) {
985 cx231xx_err(DRIVER_NAME ": Not found "
986 "matching IAD interface\n");
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -0300987 return -ENODEV;
Mauro Carvalho Chehab10e4ebb2010-10-18 21:10:46 -0300988 }
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -0300989
990 cx231xx_info("registering interface %d\n", ifnum);
991
Sri Deevie0d3baf2009-03-03 14:37:50 -0300992 /* save our data pointer in this interface device */
993 usb_set_intfdata(lif, dev);
994
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -0300995 /*
996 * AV device initialization - only done at the last interface
997 */
998
999 /* Create v4l2 device */
Janne Grunau72317482009-04-01 08:39:29 -03001000 retval = v4l2_device_register(&interface->dev, &dev->v4l2_dev);
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001001 if (retval) {
1002 cx231xx_errdev("v4l2_device_register failed\n");
1003 cx231xx_devused &= ~(1 << nr);
1004 kfree(dev);
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -03001005 dev = NULL;
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001006 return -EIO;
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -03001007 }
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001008 /* allocate device struct */
1009 retval = cx231xx_init_dev(&dev, udev, nr);
1010 if (retval) {
1011 cx231xx_devused &= ~(1 << dev->devno);
1012 v4l2_device_unregister(&dev->v4l2_dev);
1013 kfree(dev);
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -03001014 dev = NULL;
1015 usb_set_intfdata(lif, NULL);
1016
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001017 return retval;
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -03001018 }
Sri Deevie0d3baf2009-03-03 14:37:50 -03001019
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001020 /* compute alternate max packet sizes for video */
1021 uif = udev->actconfig->interface[dev->current_pcb_config.
1022 hs_config_info[0].interface_info.video_index + 1];
1023
1024 dev->video_mode.end_point_addr = le16_to_cpu(uif->altsetting[0].
1025 endpoint[isoc_pipe].desc.bEndpointAddress);
1026
1027 dev->video_mode.num_alt = uif->num_altsetting;
1028 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
1029 dev->video_mode.end_point_addr,
1030 dev->video_mode.num_alt);
1031 dev->video_mode.alt_max_pkt_size =
1032 kmalloc(32 * dev->video_mode.num_alt, GFP_KERNEL);
1033
1034 if (dev->video_mode.alt_max_pkt_size == NULL) {
1035 cx231xx_errdev("out of memory!\n");
1036 cx231xx_devused &= ~(1 << nr);
1037 v4l2_device_unregister(&dev->v4l2_dev);
1038 kfree(dev);
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -03001039 dev = NULL;
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001040 return -ENOMEM;
1041 }
1042
1043 for (i = 0; i < dev->video_mode.num_alt; i++) {
1044 u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
1045 desc.wMaxPacketSize);
1046 dev->video_mode.alt_max_pkt_size[i] =
1047 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
1048 cx231xx_info("Alternate setting %i, max size= %i\n", i,
1049 dev->video_mode.alt_max_pkt_size[i]);
1050 }
1051
1052 /* compute alternate max packet sizes for vbi */
1053 uif = udev->actconfig->interface[dev->current_pcb_config.
1054 hs_config_info[0].interface_info.
1055 vanc_index + 1];
1056
1057 dev->vbi_mode.end_point_addr =
1058 le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc.
1059 bEndpointAddress);
1060
1061 dev->vbi_mode.num_alt = uif->num_altsetting;
1062 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
1063 dev->vbi_mode.end_point_addr,
1064 dev->vbi_mode.num_alt);
1065 dev->vbi_mode.alt_max_pkt_size =
1066 kmalloc(32 * dev->vbi_mode.num_alt, GFP_KERNEL);
1067
1068 if (dev->vbi_mode.alt_max_pkt_size == NULL) {
1069 cx231xx_errdev("out of memory!\n");
1070 cx231xx_devused &= ~(1 << nr);
1071 v4l2_device_unregister(&dev->v4l2_dev);
1072 kfree(dev);
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -03001073 dev = NULL;
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001074 return -ENOMEM;
1075 }
1076
1077 for (i = 0; i < dev->vbi_mode.num_alt; i++) {
1078 u16 tmp =
1079 le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
1080 desc.wMaxPacketSize);
1081 dev->vbi_mode.alt_max_pkt_size[i] =
1082 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
1083 cx231xx_info("Alternate setting %i, max size= %i\n", i,
1084 dev->vbi_mode.alt_max_pkt_size[i]);
1085 }
1086
1087 /* compute alternate max packet sizes for sliced CC */
1088 uif = udev->actconfig->interface[dev->current_pcb_config.
1089 hs_config_info[0].interface_info.
1090 hanc_index + 1];
1091
1092 dev->sliced_cc_mode.end_point_addr =
1093 le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc.
1094 bEndpointAddress);
1095
1096 dev->sliced_cc_mode.num_alt = uif->num_altsetting;
1097 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
1098 dev->sliced_cc_mode.end_point_addr,
1099 dev->sliced_cc_mode.num_alt);
1100 dev->sliced_cc_mode.alt_max_pkt_size =
1101 kmalloc(32 * dev->sliced_cc_mode.num_alt, GFP_KERNEL);
1102
1103 if (dev->sliced_cc_mode.alt_max_pkt_size == NULL) {
1104 cx231xx_errdev("out of memory!\n");
1105 cx231xx_devused &= ~(1 << nr);
1106 v4l2_device_unregister(&dev->v4l2_dev);
1107 kfree(dev);
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -03001108 dev = NULL;
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001109 return -ENOMEM;
1110 }
1111
1112 for (i = 0; i < dev->sliced_cc_mode.num_alt; i++) {
1113 u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
1114 desc.wMaxPacketSize);
1115 dev->sliced_cc_mode.alt_max_pkt_size[i] =
1116 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
1117 cx231xx_info("Alternate setting %i, max size= %i\n", i,
1118 dev->sliced_cc_mode.alt_max_pkt_size[i]);
1119 }
1120
1121 if (dev->current_pcb_config.ts1_source != 0xff) {
1122 /* compute alternate max packet sizes for TS1 */
1123 uif = udev->actconfig->interface[dev->current_pcb_config.
1124 hs_config_info[0].
1125 interface_info.
1126 ts1_index + 1];
1127
1128 dev->ts1_mode.end_point_addr =
1129 le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].
1130 desc.bEndpointAddress);
1131
1132 dev->ts1_mode.num_alt = uif->num_altsetting;
1133 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
1134 dev->ts1_mode.end_point_addr,
1135 dev->ts1_mode.num_alt);
1136 dev->ts1_mode.alt_max_pkt_size =
1137 kmalloc(32 * dev->ts1_mode.num_alt, GFP_KERNEL);
1138
1139 if (dev->ts1_mode.alt_max_pkt_size == NULL) {
1140 cx231xx_errdev("out of memory!\n");
1141 cx231xx_devused &= ~(1 << nr);
1142 v4l2_device_unregister(&dev->v4l2_dev);
1143 kfree(dev);
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -03001144 dev = NULL;
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001145 return -ENOMEM;
1146 }
1147
1148 for (i = 0; i < dev->ts1_mode.num_alt; i++) {
1149 u16 tmp = le16_to_cpu(uif->altsetting[i].
1150 endpoint[isoc_pipe].desc.
1151 wMaxPacketSize);
1152 dev->ts1_mode.alt_max_pkt_size[i] =
1153 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
1154 cx231xx_info("Alternate setting %i, max size= %i\n", i,
1155 dev->ts1_mode.alt_max_pkt_size[i]);
1156 }
1157 }
1158
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -03001159 if (dev->model == CX231XX_BOARD_CNXT_VIDEO_GRABBER) {
1160 cx231xx_enable_OSC(dev);
1161 cx231xx_reset_out(dev);
1162 cx231xx_set_alt_setting(dev, INDEX_VIDEO, 3);
1163 }
1164
1165 if (dev->model == CX231XX_BOARD_CNXT_RDE_253S)
1166 cx231xx_sleep_s5h1432(dev);
1167
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001168 /* load other modules required */
1169 request_modules(dev);
1170
Sri Deevie0d3baf2009-03-03 14:37:50 -03001171 return 0;
1172}
1173
1174/*
1175 * cx231xx_usb_disconnect()
1176 * called when the device gets diconencted
1177 * video device will be unregistered on v4l2_close in case it is still open
1178 */
1179static void cx231xx_usb_disconnect(struct usb_interface *interface)
1180{
1181 struct cx231xx *dev;
1182
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -03001183 dev = usb_get_intfdata(interface);
Sri Deevie0d3baf2009-03-03 14:37:50 -03001184 usb_set_intfdata(interface, NULL);
1185
1186 if (!dev)
1187 return;
1188
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001189 if (!dev->udev)
1190 return;
1191
Tejun Heo707bcf32010-12-24 16:14:20 +01001192 flush_request_modules(dev);
1193
Sri Deevib1196122009-03-20 23:33:48 -03001194 /* delete v4l2 device */
1195 v4l2_device_unregister(&dev->v4l2_dev);
1196
Sri Deevie0d3baf2009-03-03 14:37:50 -03001197 /* wait until all current v4l2 io is finished then deallocate
1198 resources */
1199 mutex_lock(&dev->lock);
1200
1201 wake_up_interruptible_all(&dev->open);
1202
1203 if (dev->users) {
1204 cx231xx_warn
Laurent Pinchart38c7c032009-11-27 13:57:15 -03001205 ("device %s is open! Deregistration and memory "
1206 "deallocation are deferred on close.\n",
1207 video_device_node_name(dev->vdev));
Sri Deevie0d3baf2009-03-03 14:37:50 -03001208
1209 dev->state |= DEV_MISCONFIGURED;
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -03001210 if (dev->USE_ISO)
1211 cx231xx_uninit_isoc(dev);
1212 else
1213 cx231xx_uninit_bulk(dev);
Sri Deevie0d3baf2009-03-03 14:37:50 -03001214 dev->state |= DEV_DISCONNECTED;
1215 wake_up_interruptible(&dev->wait_frame);
1216 wake_up_interruptible(&dev->wait_stream);
1217 } else {
1218 dev->state |= DEV_DISCONNECTED;
1219 cx231xx_release_resources(dev);
1220 }
1221
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -03001222 cx231xx_close_extension(dev);
Sri Deevie0d3baf2009-03-03 14:37:50 -03001223
1224 mutex_unlock(&dev->lock);
1225
1226 if (!dev->users) {
1227 kfree(dev->video_mode.alt_max_pkt_size);
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -03001228 kfree(dev->vbi_mode.alt_max_pkt_size);
1229 kfree(dev->sliced_cc_mode.alt_max_pkt_size);
1230 kfree(dev->ts1_mode.alt_max_pkt_size);
Sri Deevie0d3baf2009-03-03 14:37:50 -03001231 kfree(dev);
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -03001232 dev = NULL;
Sri Deevie0d3baf2009-03-03 14:37:50 -03001233 }
1234}
1235
1236static struct usb_driver cx231xx_usb_driver = {
1237 .name = "cx231xx",
1238 .probe = cx231xx_usb_probe,
1239 .disconnect = cx231xx_usb_disconnect,
1240 .id_table = cx231xx_id_table,
1241};
1242
1243static int __init cx231xx_module_init(void)
1244{
1245 int result;
1246
Mauro Carvalho Chehab818fdf32009-03-13 07:41:58 -03001247 printk(KERN_INFO DRIVER_NAME " v4l2 driver loaded.\n");
Sri Deevie0d3baf2009-03-03 14:37:50 -03001248
1249 /* register this driver with the USB subsystem */
1250 result = usb_register(&cx231xx_usb_driver);
1251 if (result)
1252 cx231xx_err(DRIVER_NAME
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -03001253 " usb_register failed. Error number %d.\n", result);
Sri Deevie0d3baf2009-03-03 14:37:50 -03001254
1255 return result;
1256}
1257
1258static void __exit cx231xx_module_exit(void)
1259{
1260 /* deregister this driver with the USB subsystem */
1261 usb_deregister(&cx231xx_usb_driver);
1262}
1263
1264module_init(cx231xx_module_init);
1265module_exit(cx231xx_module_exit);