blob: 56c2d8195ac6fb301f27016f18543fa13c5b4904 [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"
37
38#include "cx231xx.h"
39
40static int tuner = -1;
41module_param(tuner, int, 0444);
42MODULE_PARM_DESC(tuner, "tuner type");
43
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -030044static int transfer_mode = 1;
45module_param(transfer_mode, int, 0444);
46MODULE_PARM_DESC(transfer_mode, "transfer mode (1-ISO or 0-BULK)");
47
Sri Deevie0d3baf2009-03-03 14:37:50 -030048static unsigned int disable_ir;
49module_param(disable_ir, int, 0444);
50MODULE_PARM_DESC(disable_ir, "disable infrared remote support");
51
52/* Bitmask marking allocated devices from 0 to CX231XX_MAXBOARDS */
53static unsigned long cx231xx_devused;
54
55/*
56 * Reset sequences for analog/digital modes
57 */
58
59static struct cx231xx_reg_seq RDE250_XCV_TUNER[] = {
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -030060 {0x03, 0x01, 10},
61 {0x03, 0x00, 30},
62 {0x03, 0x01, 10},
63 {-1, -1, -1},
Sri Deevie0d3baf2009-03-03 14:37:50 -030064};
65
Sri Deevie0d3baf2009-03-03 14:37:50 -030066/*
67 * Board definitions
68 */
69struct cx231xx_board cx231xx_boards[] = {
Sri Deevie0d3baf2009-03-03 14:37:50 -030070 [CX231XX_BOARD_UNKNOWN] = {
Sri Deevi6e4f5742009-03-10 21:16:26 -030071 .name = "Unknown CX231xx video grabber",
72 .tuner_type = TUNER_ABSENT,
73 .input = {{
74 .type = CX231XX_VMUX_TELEVISION,
75 .vmux = CX231XX_VIN_3_1,
76 .amux = CX231XX_AMUX_VIDEO,
Márton Németh7ee0a282009-12-13 17:06:10 -030077 .gpio = NULL,
Sri Deevi6e4f5742009-03-10 21:16:26 -030078 }, {
79 .type = CX231XX_VMUX_COMPOSITE1,
80 .vmux = CX231XX_VIN_2_1,
81 .amux = CX231XX_AMUX_LINE_IN,
Márton Németh7ee0a282009-12-13 17:06:10 -030082 .gpio = NULL,
Sri Deevi6e4f5742009-03-10 21:16:26 -030083 }, {
84 .type = CX231XX_VMUX_SVIDEO,
85 .vmux = CX231XX_VIN_1_1 |
86 (CX231XX_VIN_1_2 << 8) |
87 CX25840_SVIDEO_ON,
88 .amux = CX231XX_AMUX_LINE_IN,
Márton Németh7ee0a282009-12-13 17:06:10 -030089 .gpio = NULL,
Sri Deevi6e4f5742009-03-10 21:16:26 -030090 }
91 },
92 },
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -030093 [CX231XX_BOARD_CNXT_CARRAERA] = {
94 .name = "Conexant Hybrid TV - CARRAERA",
Sri Deevi6e4f5742009-03-10 21:16:26 -030095 .tuner_type = TUNER_XC5000,
96 .tuner_addr = 0x61,
97 .tuner_gpio = RDE250_XCV_TUNER,
98 .tuner_sif_gpio = 0x05,
99 .tuner_scl_gpio = 0x1a,
100 .tuner_sda_gpio = 0x1b,
101 .decoder = CX231XX_AVDECODER,
Devin Heitmueller88806212010-08-18 17:50:07 -0300102 .output_mode = OUT_MODE_VIP11,
Sri Deevi6e4f5742009-03-10 21:16:26 -0300103 .demod_xfer_mode = 0,
104 .ctl_pin_status_mask = 0xFFFFFFC4,
105 .agc_analog_digital_select_gpio = 0x0c,
106 .gpio_pin_status_mask = 0x4001000,
107 .tuner_i2c_master = 1,
108 .demod_i2c_master = 2,
109 .has_dvb = 1,
110 .demod_addr = 0x02,
111 .norm = V4L2_STD_PAL,
Sri Deevie0d3baf2009-03-03 14:37:50 -0300112
Sri Deevi6e4f5742009-03-10 21:16:26 -0300113 .input = {{
114 .type = CX231XX_VMUX_TELEVISION,
115 .vmux = CX231XX_VIN_3_1,
116 .amux = CX231XX_AMUX_VIDEO,
Márton Németh7ee0a282009-12-13 17:06:10 -0300117 .gpio = NULL,
Sri Deevi6e4f5742009-03-10 21:16:26 -0300118 }, {
119 .type = CX231XX_VMUX_COMPOSITE1,
120 .vmux = CX231XX_VIN_2_1,
121 .amux = CX231XX_AMUX_LINE_IN,
Márton Németh7ee0a282009-12-13 17:06:10 -0300122 .gpio = NULL,
Sri Deevi6e4f5742009-03-10 21:16:26 -0300123 }, {
124 .type = CX231XX_VMUX_SVIDEO,
125 .vmux = CX231XX_VIN_1_1 |
126 (CX231XX_VIN_1_2 << 8) |
127 CX25840_SVIDEO_ON,
128 .amux = CX231XX_AMUX_LINE_IN,
Márton Németh7ee0a282009-12-13 17:06:10 -0300129 .gpio = NULL,
Sri Deevi6e4f5742009-03-10 21:16:26 -0300130 }
131 },
132 },
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300133 [CX231XX_BOARD_CNXT_SHELBY] = {
134 .name = "Conexant Hybrid TV - SHELBY",
Sri Deevi6e4f5742009-03-10 21:16:26 -0300135 .tuner_type = TUNER_XC5000,
136 .tuner_addr = 0x61,
137 .tuner_gpio = RDE250_XCV_TUNER,
138 .tuner_sif_gpio = 0x05,
139 .tuner_scl_gpio = 0x1a,
140 .tuner_sda_gpio = 0x1b,
141 .decoder = CX231XX_AVDECODER,
Devin Heitmueller88806212010-08-18 17:50:07 -0300142 .output_mode = OUT_MODE_VIP11,
Sri Deevi6e4f5742009-03-10 21:16:26 -0300143 .demod_xfer_mode = 0,
144 .ctl_pin_status_mask = 0xFFFFFFC4,
145 .agc_analog_digital_select_gpio = 0x0c,
146 .gpio_pin_status_mask = 0x4001000,
147 .tuner_i2c_master = 1,
148 .demod_i2c_master = 2,
149 .has_dvb = 1,
150 .demod_addr = 0x32,
151 .norm = V4L2_STD_NTSC,
Sri Deevie0d3baf2009-03-03 14:37:50 -0300152
Sri Deevi6e4f5742009-03-10 21:16:26 -0300153 .input = {{
154 .type = CX231XX_VMUX_TELEVISION,
155 .vmux = CX231XX_VIN_3_1,
156 .amux = CX231XX_AMUX_VIDEO,
Márton Németh7ee0a282009-12-13 17:06:10 -0300157 .gpio = NULL,
Sri Deevi6e4f5742009-03-10 21:16:26 -0300158 }, {
159 .type = CX231XX_VMUX_COMPOSITE1,
160 .vmux = CX231XX_VIN_2_1,
161 .amux = CX231XX_AMUX_LINE_IN,
Márton Németh7ee0a282009-12-13 17:06:10 -0300162 .gpio = NULL,
Sri Deevi6e4f5742009-03-10 21:16:26 -0300163 }, {
164 .type = CX231XX_VMUX_SVIDEO,
165 .vmux = CX231XX_VIN_1_1 |
166 (CX231XX_VIN_1_2 << 8) |
167 CX25840_SVIDEO_ON,
168 .amux = CX231XX_AMUX_LINE_IN,
Márton Németh7ee0a282009-12-13 17:06:10 -0300169 .gpio = NULL,
Sri Deevi6e4f5742009-03-10 21:16:26 -0300170 }
171 },
172 },
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300173 [CX231XX_BOARD_CNXT_RDE_253S] = {
174 .name = "Conexant Hybrid TV - RDE253S",
175 .tuner_type = TUNER_NXP_TDA18271,
176 .tuner_addr = 0x60,
177 .tuner_gpio = RDE250_XCV_TUNER,
178 .tuner_sif_gpio = 0x05,
179 .tuner_scl_gpio = 0x1a,
180 .tuner_sda_gpio = 0x1b,
181 .decoder = CX231XX_AVDECODER,
Devin Heitmueller88806212010-08-18 17:50:07 -0300182 .output_mode = OUT_MODE_VIP11,
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300183 .demod_xfer_mode = 0,
184 .ctl_pin_status_mask = 0xFFFFFFC4,
185 .agc_analog_digital_select_gpio = 0x1c,
186 .gpio_pin_status_mask = 0x4001000,
187 .tuner_i2c_master = 1,
188 .demod_i2c_master = 2,
189 .has_dvb = 1,
190 .demod_addr = 0x02,
191 .norm = V4L2_STD_PAL,
192
193 .input = {{
194 .type = CX231XX_VMUX_TELEVISION,
195 .vmux = CX231XX_VIN_3_1,
196 .amux = CX231XX_AMUX_VIDEO,
197 .gpio = NULL,
198 }, {
199 .type = CX231XX_VMUX_COMPOSITE1,
200 .vmux = CX231XX_VIN_2_1,
201 .amux = CX231XX_AMUX_LINE_IN,
202 .gpio = NULL,
203 }, {
204 .type = CX231XX_VMUX_SVIDEO,
205 .vmux = CX231XX_VIN_1_1 |
206 (CX231XX_VIN_1_2 << 8) |
207 CX25840_SVIDEO_ON,
208 .amux = CX231XX_AMUX_LINE_IN,
209 .gpio = NULL,
210 }
211 },
212 },
213
214 [CX231XX_BOARD_CNXT_RDU_253S] = {
215 .name = "Conexant Hybrid TV - RDU253S",
216 .tuner_type = TUNER_NXP_TDA18271,
217 .tuner_addr = 0x60,
218 .tuner_gpio = RDE250_XCV_TUNER,
219 .tuner_sif_gpio = 0x05,
220 .tuner_scl_gpio = 0x1a,
221 .tuner_sda_gpio = 0x1b,
222 .decoder = CX231XX_AVDECODER,
Devin Heitmueller88806212010-08-18 17:50:07 -0300223 .output_mode = OUT_MODE_VIP11,
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300224 .demod_xfer_mode = 0,
225 .ctl_pin_status_mask = 0xFFFFFFC4,
226 .agc_analog_digital_select_gpio = 0x1c,
227 .gpio_pin_status_mask = 0x4001000,
228 .tuner_i2c_master = 1,
229 .demod_i2c_master = 2,
230 .has_dvb = 1,
231 .demod_addr = 0x02,
232 .norm = V4L2_STD_PAL,
233
234 .input = {{
235 .type = CX231XX_VMUX_TELEVISION,
236 .vmux = CX231XX_VIN_3_1,
237 .amux = CX231XX_AMUX_VIDEO,
238 .gpio = NULL,
239 }, {
240 .type = CX231XX_VMUX_COMPOSITE1,
241 .vmux = CX231XX_VIN_2_1,
242 .amux = CX231XX_AMUX_LINE_IN,
243 .gpio = NULL,
244 }, {
245 .type = CX231XX_VMUX_SVIDEO,
246 .vmux = CX231XX_VIN_1_1 |
247 (CX231XX_VIN_1_2 << 8) |
248 CX25840_SVIDEO_ON,
249 .amux = CX231XX_AMUX_LINE_IN,
250 .gpio = NULL,
251 }
252 },
253 },
254 [CX231XX_BOARD_CNXT_VIDEO_GRABBER] = {
255 .name = "Conexant VIDEO GRABBER",
Devin Heitmueller9f512592010-08-18 18:04:04 -0300256 .tuner_type = TUNER_ABSENT,
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300257 .decoder = CX231XX_AVDECODER,
Devin Heitmueller88806212010-08-18 17:50:07 -0300258 .output_mode = OUT_MODE_VIP11,
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300259 .ctl_pin_status_mask = 0xFFFFFFC4,
260 .agc_analog_digital_select_gpio = 0x1c,
261 .gpio_pin_status_mask = 0x4001000,
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300262 .norm = V4L2_STD_PAL,
263
264 .input = {{
265 .type = CX231XX_VMUX_COMPOSITE1,
266 .vmux = CX231XX_VIN_2_1,
267 .amux = CX231XX_AMUX_LINE_IN,
268 .gpio = NULL,
269 }, {
270 .type = CX231XX_VMUX_SVIDEO,
271 .vmux = CX231XX_VIN_1_1 |
272 (CX231XX_VIN_1_2 << 8) |
273 CX25840_SVIDEO_ON,
274 .amux = CX231XX_AMUX_LINE_IN,
275 .gpio = NULL,
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300276 }
277 },
278 },
279 [CX231XX_BOARD_CNXT_RDE_250] = {
280 .name = "Conexant Hybrid TV - rde 250",
281 .tuner_type = TUNER_XC5000,
282 .tuner_addr = 0x61,
283 .tuner_gpio = RDE250_XCV_TUNER,
284 .tuner_sif_gpio = 0x05,
285 .tuner_scl_gpio = 0x1a,
286 .tuner_sda_gpio = 0x1b,
287 .decoder = CX231XX_AVDECODER,
Devin Heitmueller88806212010-08-18 17:50:07 -0300288 .output_mode = OUT_MODE_VIP11,
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300289 .demod_xfer_mode = 0,
290 .ctl_pin_status_mask = 0xFFFFFFC4,
291 .agc_analog_digital_select_gpio = 0x0c,
292 .gpio_pin_status_mask = 0x4001000,
293 .tuner_i2c_master = 1,
294 .demod_i2c_master = 2,
295 .has_dvb = 1,
296 .demod_addr = 0x02,
297 .norm = V4L2_STD_PAL,
298
299 .input = {{
300 .type = CX231XX_VMUX_TELEVISION,
301 .vmux = CX231XX_VIN_2_1,
302 .amux = CX231XX_AMUX_VIDEO,
303 .gpio = NULL,
304 }
305 },
306 },
307 [CX231XX_BOARD_CNXT_RDU_250] = {
308 .name = "Conexant Hybrid TV - RDU 250",
309 .tuner_type = TUNER_XC5000,
310 .tuner_addr = 0x61,
311 .tuner_gpio = RDE250_XCV_TUNER,
312 .tuner_sif_gpio = 0x05,
313 .tuner_scl_gpio = 0x1a,
314 .tuner_sda_gpio = 0x1b,
315 .decoder = CX231XX_AVDECODER,
Devin Heitmueller88806212010-08-18 17:50:07 -0300316 .output_mode = OUT_MODE_VIP11,
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300317 .demod_xfer_mode = 0,
318 .ctl_pin_status_mask = 0xFFFFFFC4,
319 .agc_analog_digital_select_gpio = 0x0c,
320 .gpio_pin_status_mask = 0x4001000,
321 .tuner_i2c_master = 1,
322 .demod_i2c_master = 2,
323 .has_dvb = 1,
324 .demod_addr = 0x32,
325 .norm = V4L2_STD_NTSC,
326
327 .input = {{
328 .type = CX231XX_VMUX_TELEVISION,
329 .vmux = CX231XX_VIN_2_1,
330 .amux = CX231XX_AMUX_VIDEO,
331 .gpio = NULL,
332 }
333 },
334 },
Michael Krufky1a50fdd2010-07-06 18:23:53 -0300335 [CX231XX_BOARD_HAUPPAUGE_EXETER] = {
336 .name = "Hauppauge EXETER",
337 .tuner_type = TUNER_NXP_TDA18271,
338 .tuner_addr = 0x60,
339 .tuner_gpio = RDE250_XCV_TUNER,
340 .tuner_sif_gpio = 0x05,
341 .tuner_scl_gpio = 0x1a,
342 .tuner_sda_gpio = 0x1b,
343 .decoder = CX231XX_AVDECODER,
Devin Heitmueller88806212010-08-18 17:50:07 -0300344 .output_mode = OUT_MODE_VIP11,
Michael Krufky1a50fdd2010-07-06 18:23:53 -0300345 .demod_xfer_mode = 0,
346 .ctl_pin_status_mask = 0xFFFFFFC4,
347 .agc_analog_digital_select_gpio = 0x0c,
348 .gpio_pin_status_mask = 0x4001000,
349 .tuner_i2c_master = 1,
350 .demod_i2c_master = 2,
351 .has_dvb = 1,
352 .demod_addr = 0x0e,
353 .norm = V4L2_STD_NTSC,
354
355 .input = {{
356 .type = CX231XX_VMUX_TELEVISION,
357 .vmux = CX231XX_VIN_3_1,
358 .amux = CX231XX_AMUX_VIDEO,
359 .gpio = 0,
360 }, {
361 .type = CX231XX_VMUX_COMPOSITE1,
362 .vmux = CX231XX_VIN_2_1,
363 .amux = CX231XX_AMUX_LINE_IN,
364 .gpio = 0,
365 }, {
366 .type = CX231XX_VMUX_SVIDEO,
367 .vmux = CX231XX_VIN_1_1 |
368 (CX231XX_VIN_1_2 << 8) |
369 CX25840_SVIDEO_ON,
370 .amux = CX231XX_AMUX_LINE_IN,
371 .gpio = 0,
372 } },
373 },
Devin Heitmueller4270c3c2010-07-31 00:49:01 -0300374 [CX231XX_BOARD_HAUPPAUGE_USBLIVE2] = {
375 .name = "Hauppauge USB Live 2",
376 .tuner_type = TUNER_ABSENT,
377 .decoder = CX231XX_AVDECODER,
Devin Heitmueller88806212010-08-18 17:50:07 -0300378 .output_mode = OUT_MODE_VIP11,
Devin Heitmueller4270c3c2010-07-31 00:49:01 -0300379 .demod_xfer_mode = 0,
380 .ctl_pin_status_mask = 0xFFFFFFC4,
381 .agc_analog_digital_select_gpio = 0x0c,
382 .gpio_pin_status_mask = 0x4001000,
383 .norm = V4L2_STD_NTSC,
384 .input = {{
385 .type = CX231XX_VMUX_COMPOSITE1,
386 .vmux = CX231XX_VIN_2_1,
387 .amux = CX231XX_AMUX_LINE_IN,
388 .gpio = 0,
389 }, {
390 .type = CX231XX_VMUX_SVIDEO,
391 .vmux = CX231XX_VIN_1_1 |
392 (CX231XX_VIN_1_2 << 8) |
393 CX25840_SVIDEO_ON,
394 .amux = CX231XX_AMUX_LINE_IN,
395 .gpio = 0,
396 } },
397 },
Sri Deevie0d3baf2009-03-03 14:37:50 -0300398};
399const unsigned int cx231xx_bcount = ARRAY_SIZE(cx231xx_boards);
400
401/* table of devices that work with this driver */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300402struct usb_device_id cx231xx_id_table[] = {
Sri Deevied559ed2009-03-13 18:35:14 -0300403 {USB_DEVICE(0x0572, 0x5A3C),
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300404 .driver_info = CX231XX_BOARD_UNKNOWN},
Michael Krufky1a50fdd2010-07-06 18:23:53 -0300405 {USB_DEVICE_VER(USB_VID_PIXELVIEW, USB_PID_PIXELVIEW_SBTVD, 0x4000,0x4fff),
406 .driver_info = CX231XX_BOARD_UNKNOWN},
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300407 {USB_DEVICE(0x0572, 0x58A2),
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300408 .driver_info = CX231XX_BOARD_CNXT_CARRAERA},
Sri Deevied559ed2009-03-13 18:35:14 -0300409 {USB_DEVICE(0x0572, 0x58A1),
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300410 .driver_info = CX231XX_BOARD_CNXT_SHELBY},
411 {USB_DEVICE(0x0572, 0x58A4),
412 .driver_info = CX231XX_BOARD_CNXT_RDE_253S},
413 {USB_DEVICE(0x0572, 0x58A5),
414 .driver_info = CX231XX_BOARD_CNXT_RDU_253S},
415 {USB_DEVICE(0x0572, 0x58A6),
416 .driver_info = CX231XX_BOARD_CNXT_VIDEO_GRABBER},
417 {USB_DEVICE(0x0572, 0x589E),
418 .driver_info = CX231XX_BOARD_CNXT_RDE_250},
419 {USB_DEVICE(0x0572, 0x58A0),
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300420 .driver_info = CX231XX_BOARD_CNXT_RDU_250},
Michael Krufky1a50fdd2010-07-06 18:23:53 -0300421 {USB_DEVICE(0x2040, 0xb120),
422 .driver_info = CX231XX_BOARD_HAUPPAUGE_EXETER},
Devin Heitmuellerd78148f2010-07-06 18:25:19 -0300423 {USB_DEVICE(0x2040, 0xb140),
424 .driver_info = CX231XX_BOARD_HAUPPAUGE_EXETER},
Devin Heitmueller4270c3c2010-07-31 00:49:01 -0300425 {USB_DEVICE(0x2040, 0xc200),
426 .driver_info = CX231XX_BOARD_HAUPPAUGE_USBLIVE2},
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300427 {},
Sri Deevie0d3baf2009-03-03 14:37:50 -0300428};
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300429
Sri Deevie0d3baf2009-03-03 14:37:50 -0300430MODULE_DEVICE_TABLE(usb, cx231xx_id_table);
431
432/* cx231xx_tuner_callback
433 * will be used to reset XC5000 tuner using GPIO pin
434 */
435
436int cx231xx_tuner_callback(void *ptr, int component, int command, int arg)
437{
438 int rc = 0;
439 struct cx231xx *dev = ptr;
440
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300441 if (dev->tuner_type == TUNER_XC5000) {
442 if (command == XC5000_TUNER_RESET) {
443 cx231xx_info
Sri Deevib9255172009-03-04 17:49:01 -0300444 ("Tuner CB: RESET: cmd %d : tuner type %d \n",
445 command, dev->tuner_type);
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300446 cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit,
447 1);
448 msleep(10);
449 cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit,
450 0);
451 msleep(330);
452 cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit,
453 1);
454 msleep(10);
455 }
456 }
Sri Deevie0d3baf2009-03-03 14:37:50 -0300457 return rc;
458}
459EXPORT_SYMBOL_GPL(cx231xx_tuner_callback);
460
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300461void cx231xx_reset_out(struct cx231xx *dev)
462{
463 cx231xx_set_gpio_value(dev, CX23417_RESET, 1);
464 msleep(200);
465 cx231xx_set_gpio_value(dev, CX23417_RESET, 0);
466 msleep(200);
467 cx231xx_set_gpio_value(dev, CX23417_RESET, 1);
468}
469void cx231xx_enable_OSC(struct cx231xx *dev)
470{
471 cx231xx_set_gpio_value(dev, CX23417_OSC_EN, 1);
472}
473void cx231xx_sleep_s5h1432(struct cx231xx *dev)
474{
475 cx231xx_set_gpio_value(dev, SLEEP_S5H1432, 0);
476}
477
Sri Deevib9255172009-03-04 17:49:01 -0300478static inline void cx231xx_set_model(struct cx231xx *dev)
Sri Deevie0d3baf2009-03-03 14:37:50 -0300479{
480 memcpy(&dev->board, &cx231xx_boards[dev->model], sizeof(dev->board));
481}
482
483/* Since cx231xx_pre_card_setup() requires a proper dev->model,
484 * this won't work for boards with generic PCI IDs
485 */
486void cx231xx_pre_card_setup(struct cx231xx *dev)
487{
488
489 cx231xx_set_model(dev);
490
491 cx231xx_info("Identified as %s (card=%d)\n",
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300492 dev->board.name, dev->model);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300493
Sri Deevi6e4f5742009-03-10 21:16:26 -0300494 /* set the direction for GPIO pins */
Mauro Carvalho Chehabc10469c2010-09-11 11:37:51 -0300495 if (dev->board.tuner_gpio) {
496 cx231xx_set_gpio_direction(dev, dev->board.tuner_gpio->bit, 1);
497 cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit, 1);
Mauro Carvalho Chehab78bb6df2010-09-26 20:48:38 -0300498 }
499 if (dev->board.tuner_sif_gpio >= 0)
Mauro Carvalho Chehabc10469c2010-09-11 11:37:51 -0300500 cx231xx_set_gpio_direction(dev, dev->board.tuner_sif_gpio, 1);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300501
Mauro Carvalho Chehab78bb6df2010-09-26 20:48:38 -0300502 /* request some modules if any required */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300503
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300504 /* set the mode to Analog mode initially */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300505 cx231xx_set_mode(dev, CX231XX_ANALOG_MODE);
506
507 /* Unlock device */
508 /* cx231xx_set_mode(dev, CX231XX_SUSPEND); */
509
510}
511
Sri Deevie0d3baf2009-03-03 14:37:50 -0300512static void cx231xx_config_tuner(struct cx231xx *dev)
513{
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300514 struct tuner_setup tun_setup;
515 struct v4l2_frequency f;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300516
517 if (dev->tuner_type == TUNER_ABSENT)
518 return;
519
520 tun_setup.mode_mask = T_ANALOG_TV | T_RADIO;
521 tun_setup.type = dev->tuner_type;
522 tun_setup.addr = dev->tuner_addr;
523 tun_setup.tuner_callback = cx231xx_tuner_callback;
524
Sri Deevib1196122009-03-20 23:33:48 -0300525 tuner_call(dev, tuner, s_type_addr, &tun_setup);
526
Sri Deevie0d3baf2009-03-03 14:37:50 -0300527#if 0
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300528 if (tun_setup.type == TUNER_XC5000) {
Sri Deevie0d3baf2009-03-03 14:37:50 -0300529 static struct xc2028_ctrl ctrl = {
530 .fname = XC5000_DEFAULT_FIRMWARE,
531 .max_len = 64,
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300532 .demod = 0;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300533 };
534 struct v4l2_priv_tun_config cfg = {
535 .tuner = dev->tuner_type,
536 .priv = &ctrl,
537 };
Sri Deevib1196122009-03-20 23:33:48 -0300538 tuner_call(dev, tuner, s_config, &cfg);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300539 }
540#endif
Sri Deevie0d3baf2009-03-03 14:37:50 -0300541 /* configure tuner */
542 f.tuner = 0;
543 f.type = V4L2_TUNER_ANALOG_TV;
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300544 f.frequency = 9076; /* just a magic number */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300545 dev->ctl_freq = f.frequency;
Sri Deevib1196122009-03-20 23:33:48 -0300546 call_all(dev, tuner, s_frequency, &f);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300547
Sri Deevib1196122009-03-20 23:33:48 -0300548}
Sri Deevie0d3baf2009-03-03 14:37:50 -0300549
Sri Deevie0d3baf2009-03-03 14:37:50 -0300550void cx231xx_card_setup(struct cx231xx *dev)
551{
Sri Deevib1196122009-03-20 23:33:48 -0300552
Sri Deevie0d3baf2009-03-03 14:37:50 -0300553 cx231xx_set_model(dev);
554
555 dev->tuner_type = cx231xx_boards[dev->model].tuner_type;
556 if (cx231xx_boards[dev->model].tuner_addr)
557 dev->tuner_addr = cx231xx_boards[dev->model].tuner_addr;
558
Sri Deevie0d3baf2009-03-03 14:37:50 -0300559 /* request some modules */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300560 if (dev->board.decoder == CX231XX_AVDECODER) {
Hans Verkuile6574f22009-04-01 03:57:53 -0300561 dev->sd_cx25840 = v4l2_i2c_new_subdev(&dev->v4l2_dev,
562 &dev->i2c_bus[0].i2c_adap,
Laurent Pinchart1532a072010-09-24 07:58:29 -0300563 NULL, "cx25840", 0x88 >> 1, NULL);
Sri Deevib1196122009-03-20 23:33:48 -0300564 if (dev->sd_cx25840 == NULL)
565 cx231xx_info("cx25840 subdev registration failure\n");
Hans Verkuilcc26b072009-03-29 19:20:26 -0300566 cx25840_call(dev, core, load_fw);
Sri Deevib1196122009-03-20 23:33:48 -0300567
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300568 }
Sri Deevib1196122009-03-20 23:33:48 -0300569
Devin Heitmuellere3e0aaa2010-07-08 17:05:30 -0300570 /* Initialize the tuner */
571 if (dev->board.tuner_type != TUNER_ABSENT) {
572 dev->sd_tuner = v4l2_i2c_new_subdev(&dev->v4l2_dev,
Mauro Carvalho Chehab1a4aa922010-09-26 20:01:51 -0300573 &dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap,
Laurent Pinchart1532a072010-09-24 07:58:29 -0300574 NULL, "tuner",
Devin Heitmuellere3e0aaa2010-07-08 17:05:30 -0300575 dev->tuner_addr, NULL);
576 if (dev->sd_tuner == NULL)
577 cx231xx_info("tuner subdev registration failure\n");
578 else
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300579 cx231xx_config_tuner(dev);
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300580 }
Sri Deevie0d3baf2009-03-03 14:37:50 -0300581}
582
Sri Deevie0d3baf2009-03-03 14:37:50 -0300583/*
584 * cx231xx_config()
585 * inits registers with sane defaults
586 */
587int cx231xx_config(struct cx231xx *dev)
588{
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300589 /* TBD need to add cx231xx specific code */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300590 dev->mute = 1; /* maybe not the right place... */
591 dev->volume = 0x1f;
592
593 return 0;
594}
595
596/*
597 * cx231xx_config_i2c()
598 * configure i2c attached devices
599 */
600void cx231xx_config_i2c(struct cx231xx *dev)
601{
Hans Verkuil5325b422009-04-02 11:26:22 -0300602 /* u32 input = INPUT(dev->video_input)->vmux; */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300603
Sri Deevib1196122009-03-20 23:33:48 -0300604 call_all(dev, video, s_stream, 1);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300605}
606
607/*
608 * cx231xx_realease_resources()
609 * unregisters the v4l2,i2c and usb devices
610 * called when the device gets disconected or at module unload
611*/
612void cx231xx_release_resources(struct cx231xx *dev)
613{
Sri Deevie0d3baf2009-03-03 14:37:50 -0300614 cx231xx_release_analog_resources(dev);
615
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300616 cx231xx_remove_from_devlist(dev);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300617
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300618 cx231xx_dev_uninit(dev);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300619
620 usb_put_dev(dev->udev);
621
622 /* Mark device as unused */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300623 cx231xx_devused &= ~(1 << dev->devno);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300624}
625
Sri Deevie0d3baf2009-03-03 14:37:50 -0300626/*
627 * cx231xx_init_dev()
628 * allocates and inits the device structs, registers i2c bus and v4l device
629 */
630static int cx231xx_init_dev(struct cx231xx **devhandle, struct usb_device *udev,
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300631 int minor)
Sri Deevie0d3baf2009-03-03 14:37:50 -0300632{
633 struct cx231xx *dev = *devhandle;
634 int retval = -ENOMEM;
635 int errCode;
636 unsigned int maxh, maxw;
637
638 dev->udev = udev;
639 mutex_init(&dev->lock);
640 mutex_init(&dev->ctrl_urb_lock);
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300641 mutex_init(&dev->gpio_i2c_lock);
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300642 mutex_init(&dev->i2c_lock);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300643
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300644 spin_lock_init(&dev->video_mode.slock);
645 spin_lock_init(&dev->vbi_mode.slock);
646 spin_lock_init(&dev->sliced_cc_mode.slock);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300647
648 init_waitqueue_head(&dev->open);
649 init_waitqueue_head(&dev->wait_frame);
650 init_waitqueue_head(&dev->wait_stream);
651
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300652 dev->cx231xx_read_ctrl_reg = cx231xx_read_ctrl_reg;
653 dev->cx231xx_write_ctrl_reg = cx231xx_write_ctrl_reg;
654 dev->cx231xx_send_usb_command = cx231xx_send_usb_command;
655 dev->cx231xx_gpio_i2c_read = cx231xx_gpio_i2c_read;
656 dev->cx231xx_gpio_i2c_write = cx231xx_gpio_i2c_write;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300657
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300658 /* Query cx231xx to find what pcb config it is related to */
659 initialize_cx231xx(dev);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300660
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300661 /*To workaround error number=-71 on EP0 for VideoGrabber,
662 need set alt here.*/
Devin Heitmueller4270c3c2010-07-31 00:49:01 -0300663 if (dev->model == CX231XX_BOARD_CNXT_VIDEO_GRABBER ||
664 dev->model == CX231XX_BOARD_HAUPPAUGE_USBLIVE2) {
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300665 cx231xx_set_alt_setting(dev, INDEX_VIDEO, 3);
666 cx231xx_set_alt_setting(dev, INDEX_VANC, 1);
667 }
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300668 /* Cx231xx pre card setup */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300669 cx231xx_pre_card_setup(dev);
670
671 errCode = cx231xx_config(dev);
672 if (errCode) {
673 cx231xx_errdev("error configuring device\n");
674 return -ENOMEM;
675 }
676
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300677 /* set default norm */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300678 dev->norm = dev->board.norm;
679
680 /* register i2c bus */
681 errCode = cx231xx_dev_init(dev);
682 if (errCode < 0) {
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300683 cx231xx_dev_uninit(dev);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300684 cx231xx_errdev("%s: cx231xx_i2c_register - errCode [%d]!\n",
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300685 __func__, errCode);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300686 return errCode;
687 }
688
689 /* Do board specific init */
690 cx231xx_card_setup(dev);
691
692 /* configure the device */
693 cx231xx_config_i2c(dev);
694
695 maxw = norm_maxw(dev);
696 maxh = norm_maxh(dev);
697
698 /* set default image size */
699 dev->width = maxw;
700 dev->height = maxh;
701 dev->interlaced = 0;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300702 dev->video_input = 0;
703
704 errCode = cx231xx_config(dev);
705 if (errCode < 0) {
706 cx231xx_errdev("%s: cx231xx_config - errCode [%d]!\n",
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300707 __func__, errCode);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300708 return errCode;
709 }
710
711 /* init video dma queues */
712 INIT_LIST_HEAD(&dev->video_mode.vidq.active);
713 INIT_LIST_HEAD(&dev->video_mode.vidq.queued);
714
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300715 /* init vbi dma queues */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300716 INIT_LIST_HEAD(&dev->vbi_mode.vidq.active);
717 INIT_LIST_HEAD(&dev->vbi_mode.vidq.queued);
718
719 /* Reset other chips required if they are tied up with GPIO pins */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300720 cx231xx_add_into_devlist(dev);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300721
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300722 if (dev->model == CX231XX_BOARD_CNXT_VIDEO_GRABBER) {
Devin Heitmueller2b43db32010-08-18 18:09:28 -0300723 printk(KERN_INFO "attach 417 %d\n", dev->model);
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300724 if (cx231xx_417_register(dev) < 0) {
725 printk(KERN_ERR
726 "%s() Failed to register 417 on VID_B\n",
727 __func__);
728 }
729 }
730
Sri Deevie0d3baf2009-03-03 14:37:50 -0300731 retval = cx231xx_register_analog_devices(dev);
732 if (retval < 0) {
733 cx231xx_release_resources(dev);
734 goto fail_reg_devices;
735 }
736
737 cx231xx_init_extension(dev);
738
739 return 0;
740
Sri Deevib9255172009-03-04 17:49:01 -0300741fail_reg_devices:
Sri Deevie0d3baf2009-03-03 14:37:50 -0300742 mutex_unlock(&dev->lock);
743 return retval;
744}
745
746#if defined(CONFIG_MODULES) && defined(MODULE)
747static void request_module_async(struct work_struct *work)
748{
749 struct cx231xx *dev = container_of(work,
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300750 struct cx231xx, request_module_wk);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300751
752 if (dev->has_alsa_audio)
753 request_module("cx231xx-alsa");
754
755 if (dev->board.has_dvb)
756 request_module("cx231xx-dvb");
757
758}
759
760static void request_modules(struct cx231xx *dev)
761{
762 INIT_WORK(&dev->request_module_wk, request_module_async);
763 schedule_work(&dev->request_module_wk);
764}
765#else
766#define request_modules(dev)
767#endif /* CONFIG_MODULES */
768
Sri Deevie0d3baf2009-03-03 14:37:50 -0300769/*
770 * cx231xx_usb_probe()
771 * checks for supported devices
772 */
773static int cx231xx_usb_probe(struct usb_interface *interface,
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300774 const struct usb_device_id *id)
Sri Deevie0d3baf2009-03-03 14:37:50 -0300775{
776 struct usb_device *udev;
777 struct usb_interface *uif;
778 struct cx231xx *dev = NULL;
779 int retval = -ENODEV;
Hans Verkuild73abcf2009-03-12 18:38:40 -0300780 int nr = 0, ifnum;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300781 int i, isoc_pipe = 0;
782 char *speed;
783 char descr[255] = "";
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300784 struct usb_interface *lif = NULL;
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300785 struct usb_interface_assoc_descriptor *assoc_desc;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300786
787 udev = usb_get_dev(interface_to_usbdev(interface));
788 ifnum = interface->altsetting[0].desc.bInterfaceNumber;
789
Mauro Carvalho Chehab10e4ebb2010-10-18 21:10:46 -0300790 if (ifnum == 1) {
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -0300791 /*
792 * Interface number 0 - IR interface
793 */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300794 /* Check to see next free device and mark as used */
795 nr = find_first_zero_bit(&cx231xx_devused, CX231XX_MAXBOARDS);
796 cx231xx_devused |= 1 << nr;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300797
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300798 if (nr >= CX231XX_MAXBOARDS) {
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300799 cx231xx_err(DRIVER_NAME
800 ": Supports only %i cx231xx boards.\n", CX231XX_MAXBOARDS);
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300801 cx231xx_devused &= ~(1 << nr);
802 return -ENOMEM;
803 }
Sri Deevie0d3baf2009-03-03 14:37:50 -0300804
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300805 /* allocate memory for our device state and initialize it */
806 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
807 if (dev == NULL) {
808 cx231xx_err(DRIVER_NAME ": out of memory!\n");
809 cx231xx_devused &= ~(1 << nr);
810 return -ENOMEM;
811 }
Sri Deevie0d3baf2009-03-03 14:37:50 -0300812
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300813 snprintf(dev->name, 29, "cx231xx #%d", nr);
814 dev->devno = nr;
815 dev->model = id->driver_info;
816 dev->video_mode.alt = -1;
817 dev->interface_count++;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300818
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300819 /* reset gpio dir and value */
820 dev->gpio_dir = 0;
821 dev->gpio_val = 0;
822 dev->xc_fw_load_done = 0;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300823 dev->has_alsa_audio = 1;
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300824 dev->power_mode = -1;
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300825 atomic_set(&dev->devlist_count, 0);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300826
Sri Deevib9255172009-03-04 17:49:01 -0300827 /* 0 - vbi ; 1 -sliced cc mode */
828 dev->vbi_or_sliced_cc_mode = 0;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300829
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300830 /* get maximum no.of IAD interfaces */
831 assoc_desc = udev->actconfig->intf_assoc[0];
832 dev->max_iad_interface_count = assoc_desc->bInterfaceCount;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300833
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300834 /* init CIR module TBD */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300835
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300836 /* store the current interface */
837 lif = interface;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300838
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300839 /*mode_tv: digital=1 or analog=0*/
840 dev->mode_tv = 0;
841
842 dev->USE_ISO = transfer_mode;
843
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -0300844 switch (udev->speed) {
845 case USB_SPEED_LOW:
846 speed = "1.5";
847 break;
848 case USB_SPEED_UNKNOWN:
849 case USB_SPEED_FULL:
850 speed = "12";
851 break;
852 case USB_SPEED_HIGH:
853 speed = "480";
854 break;
855 default:
856 speed = "unknown";
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300857 }
Sri Deevie0d3baf2009-03-03 14:37:50 -0300858
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -0300859 if (udev->manufacturer)
860 strlcpy(descr, udev->manufacturer, sizeof(descr));
Sri Deevie0d3baf2009-03-03 14:37:50 -0300861
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -0300862 if (udev->product) {
863 if (*descr)
864 strlcat(descr, " ", sizeof(descr));
865 strlcat(descr, udev->product, sizeof(descr));
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300866 }
Sri Deevie0d3baf2009-03-03 14:37:50 -0300867 if (*descr)
868 strlcat(descr, " ", sizeof(descr));
Sri Deevie0d3baf2009-03-03 14:37:50 -0300869
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -0300870 cx231xx_info("New device %s@ %s Mbps "
871 "(%04x:%04x) with %d interfaces\n",
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300872 descr,
873 speed,
874 le16_to_cpu(udev->descriptor.idVendor),
875 le16_to_cpu(udev->descriptor.idProduct),
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -0300876 dev->max_iad_interface_count);
Sri Deevib1196122009-03-20 23:33:48 -0300877
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -0300878 /* store the interface 0 back */
879 lif = udev->actconfig->interface[0];
Sri Deevie0d3baf2009-03-03 14:37:50 -0300880
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -0300881 /* increment interface count */
882 dev->interface_count++;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300883
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -0300884 /* get device number */
885 nr = dev->devno;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300886
Mauro Carvalho Chehab10e4ebb2010-10-18 21:10:46 -0300887 assoc_desc = udev->actconfig->intf_assoc[0];
888 if (assoc_desc->bFirstInterface != ifnum) {
889 cx231xx_err(DRIVER_NAME ": Not found "
890 "matching IAD interface\n");
891 return -ENODEV;
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300892 }
Mauro Carvalho Chehab10e4ebb2010-10-18 21:10:46 -0300893 } else {
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -0300894 return -ENODEV;
Mauro Carvalho Chehab10e4ebb2010-10-18 21:10:46 -0300895 }
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -0300896
897 cx231xx_info("registering interface %d\n", ifnum);
898
Sri Deevie0d3baf2009-03-03 14:37:50 -0300899 /* save our data pointer in this interface device */
900 usb_set_intfdata(lif, dev);
901
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -0300902 /*
903 * AV device initialization - only done at the last interface
904 */
905
906 /* Create v4l2 device */
Janne Grunau72317482009-04-01 08:39:29 -0300907 retval = v4l2_device_register(&interface->dev, &dev->v4l2_dev);
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -0300908 if (retval) {
909 cx231xx_errdev("v4l2_device_register failed\n");
910 cx231xx_devused &= ~(1 << nr);
911 kfree(dev);
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300912 dev = NULL;
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -0300913 return -EIO;
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300914 }
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -0300915 /* allocate device struct */
916 retval = cx231xx_init_dev(&dev, udev, nr);
917 if (retval) {
918 cx231xx_devused &= ~(1 << dev->devno);
919 v4l2_device_unregister(&dev->v4l2_dev);
920 kfree(dev);
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300921 dev = NULL;
922 usb_set_intfdata(lif, NULL);
923
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -0300924 return retval;
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300925 }
Sri Deevie0d3baf2009-03-03 14:37:50 -0300926
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -0300927 /* compute alternate max packet sizes for video */
928 uif = udev->actconfig->interface[dev->current_pcb_config.
929 hs_config_info[0].interface_info.video_index + 1];
930
931 dev->video_mode.end_point_addr = le16_to_cpu(uif->altsetting[0].
932 endpoint[isoc_pipe].desc.bEndpointAddress);
933
934 dev->video_mode.num_alt = uif->num_altsetting;
935 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
936 dev->video_mode.end_point_addr,
937 dev->video_mode.num_alt);
938 dev->video_mode.alt_max_pkt_size =
939 kmalloc(32 * dev->video_mode.num_alt, GFP_KERNEL);
940
941 if (dev->video_mode.alt_max_pkt_size == NULL) {
942 cx231xx_errdev("out of memory!\n");
943 cx231xx_devused &= ~(1 << nr);
944 v4l2_device_unregister(&dev->v4l2_dev);
945 kfree(dev);
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300946 dev = NULL;
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -0300947 return -ENOMEM;
948 }
949
950 for (i = 0; i < dev->video_mode.num_alt; i++) {
951 u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
952 desc.wMaxPacketSize);
953 dev->video_mode.alt_max_pkt_size[i] =
954 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
955 cx231xx_info("Alternate setting %i, max size= %i\n", i,
956 dev->video_mode.alt_max_pkt_size[i]);
957 }
958
959 /* compute alternate max packet sizes for vbi */
960 uif = udev->actconfig->interface[dev->current_pcb_config.
961 hs_config_info[0].interface_info.
962 vanc_index + 1];
963
964 dev->vbi_mode.end_point_addr =
965 le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc.
966 bEndpointAddress);
967
968 dev->vbi_mode.num_alt = uif->num_altsetting;
969 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
970 dev->vbi_mode.end_point_addr,
971 dev->vbi_mode.num_alt);
972 dev->vbi_mode.alt_max_pkt_size =
973 kmalloc(32 * dev->vbi_mode.num_alt, GFP_KERNEL);
974
975 if (dev->vbi_mode.alt_max_pkt_size == NULL) {
976 cx231xx_errdev("out of memory!\n");
977 cx231xx_devused &= ~(1 << nr);
978 v4l2_device_unregister(&dev->v4l2_dev);
979 kfree(dev);
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300980 dev = NULL;
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -0300981 return -ENOMEM;
982 }
983
984 for (i = 0; i < dev->vbi_mode.num_alt; i++) {
985 u16 tmp =
986 le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
987 desc.wMaxPacketSize);
988 dev->vbi_mode.alt_max_pkt_size[i] =
989 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
990 cx231xx_info("Alternate setting %i, max size= %i\n", i,
991 dev->vbi_mode.alt_max_pkt_size[i]);
992 }
993
994 /* compute alternate max packet sizes for sliced CC */
995 uif = udev->actconfig->interface[dev->current_pcb_config.
996 hs_config_info[0].interface_info.
997 hanc_index + 1];
998
999 dev->sliced_cc_mode.end_point_addr =
1000 le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc.
1001 bEndpointAddress);
1002
1003 dev->sliced_cc_mode.num_alt = uif->num_altsetting;
1004 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
1005 dev->sliced_cc_mode.end_point_addr,
1006 dev->sliced_cc_mode.num_alt);
1007 dev->sliced_cc_mode.alt_max_pkt_size =
1008 kmalloc(32 * dev->sliced_cc_mode.num_alt, GFP_KERNEL);
1009
1010 if (dev->sliced_cc_mode.alt_max_pkt_size == NULL) {
1011 cx231xx_errdev("out of memory!\n");
1012 cx231xx_devused &= ~(1 << nr);
1013 v4l2_device_unregister(&dev->v4l2_dev);
1014 kfree(dev);
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -03001015 dev = NULL;
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001016 return -ENOMEM;
1017 }
1018
1019 for (i = 0; i < dev->sliced_cc_mode.num_alt; i++) {
1020 u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
1021 desc.wMaxPacketSize);
1022 dev->sliced_cc_mode.alt_max_pkt_size[i] =
1023 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
1024 cx231xx_info("Alternate setting %i, max size= %i\n", i,
1025 dev->sliced_cc_mode.alt_max_pkt_size[i]);
1026 }
1027
1028 if (dev->current_pcb_config.ts1_source != 0xff) {
1029 /* compute alternate max packet sizes for TS1 */
1030 uif = udev->actconfig->interface[dev->current_pcb_config.
1031 hs_config_info[0].
1032 interface_info.
1033 ts1_index + 1];
1034
1035 dev->ts1_mode.end_point_addr =
1036 le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].
1037 desc.bEndpointAddress);
1038
1039 dev->ts1_mode.num_alt = uif->num_altsetting;
1040 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
1041 dev->ts1_mode.end_point_addr,
1042 dev->ts1_mode.num_alt);
1043 dev->ts1_mode.alt_max_pkt_size =
1044 kmalloc(32 * dev->ts1_mode.num_alt, GFP_KERNEL);
1045
1046 if (dev->ts1_mode.alt_max_pkt_size == NULL) {
1047 cx231xx_errdev("out of memory!\n");
1048 cx231xx_devused &= ~(1 << nr);
1049 v4l2_device_unregister(&dev->v4l2_dev);
1050 kfree(dev);
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -03001051 dev = NULL;
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001052 return -ENOMEM;
1053 }
1054
1055 for (i = 0; i < dev->ts1_mode.num_alt; i++) {
1056 u16 tmp = le16_to_cpu(uif->altsetting[i].
1057 endpoint[isoc_pipe].desc.
1058 wMaxPacketSize);
1059 dev->ts1_mode.alt_max_pkt_size[i] =
1060 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
1061 cx231xx_info("Alternate setting %i, max size= %i\n", i,
1062 dev->ts1_mode.alt_max_pkt_size[i]);
1063 }
1064 }
1065
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -03001066 if (dev->model == CX231XX_BOARD_CNXT_VIDEO_GRABBER) {
1067 cx231xx_enable_OSC(dev);
1068 cx231xx_reset_out(dev);
1069 cx231xx_set_alt_setting(dev, INDEX_VIDEO, 3);
1070 }
1071
1072 if (dev->model == CX231XX_BOARD_CNXT_RDE_253S)
1073 cx231xx_sleep_s5h1432(dev);
1074
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001075 /* load other modules required */
1076 request_modules(dev);
1077
Sri Deevie0d3baf2009-03-03 14:37:50 -03001078 return 0;
1079}
1080
1081/*
1082 * cx231xx_usb_disconnect()
1083 * called when the device gets diconencted
1084 * video device will be unregistered on v4l2_close in case it is still open
1085 */
1086static void cx231xx_usb_disconnect(struct usb_interface *interface)
1087{
1088 struct cx231xx *dev;
1089
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -03001090 dev = usb_get_intfdata(interface);
Sri Deevie0d3baf2009-03-03 14:37:50 -03001091 usb_set_intfdata(interface, NULL);
1092
1093 if (!dev)
1094 return;
1095
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001096 if (!dev->udev)
1097 return;
1098
Sri Deevib1196122009-03-20 23:33:48 -03001099 /* delete v4l2 device */
1100 v4l2_device_unregister(&dev->v4l2_dev);
1101
Sri Deevie0d3baf2009-03-03 14:37:50 -03001102 /* wait until all current v4l2 io is finished then deallocate
1103 resources */
1104 mutex_lock(&dev->lock);
1105
1106 wake_up_interruptible_all(&dev->open);
1107
1108 if (dev->users) {
1109 cx231xx_warn
Laurent Pinchart38c7c032009-11-27 13:57:15 -03001110 ("device %s is open! Deregistration and memory "
1111 "deallocation are deferred on close.\n",
1112 video_device_node_name(dev->vdev));
Sri Deevie0d3baf2009-03-03 14:37:50 -03001113
1114 dev->state |= DEV_MISCONFIGURED;
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -03001115 if (dev->USE_ISO)
1116 cx231xx_uninit_isoc(dev);
1117 else
1118 cx231xx_uninit_bulk(dev);
Sri Deevie0d3baf2009-03-03 14:37:50 -03001119 dev->state |= DEV_DISCONNECTED;
1120 wake_up_interruptible(&dev->wait_frame);
1121 wake_up_interruptible(&dev->wait_stream);
1122 } else {
1123 dev->state |= DEV_DISCONNECTED;
1124 cx231xx_release_resources(dev);
1125 }
1126
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -03001127 cx231xx_close_extension(dev);
Sri Deevie0d3baf2009-03-03 14:37:50 -03001128
1129 mutex_unlock(&dev->lock);
1130
1131 if (!dev->users) {
1132 kfree(dev->video_mode.alt_max_pkt_size);
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -03001133 kfree(dev->vbi_mode.alt_max_pkt_size);
1134 kfree(dev->sliced_cc_mode.alt_max_pkt_size);
1135 kfree(dev->ts1_mode.alt_max_pkt_size);
Sri Deevie0d3baf2009-03-03 14:37:50 -03001136 kfree(dev);
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -03001137 dev = NULL;
Sri Deevie0d3baf2009-03-03 14:37:50 -03001138 }
1139}
1140
1141static struct usb_driver cx231xx_usb_driver = {
1142 .name = "cx231xx",
1143 .probe = cx231xx_usb_probe,
1144 .disconnect = cx231xx_usb_disconnect,
1145 .id_table = cx231xx_id_table,
1146};
1147
1148static int __init cx231xx_module_init(void)
1149{
1150 int result;
1151
Mauro Carvalho Chehab818fdf32009-03-13 07:41:58 -03001152 printk(KERN_INFO DRIVER_NAME " v4l2 driver loaded.\n");
Sri Deevie0d3baf2009-03-03 14:37:50 -03001153
1154 /* register this driver with the USB subsystem */
1155 result = usb_register(&cx231xx_usb_driver);
1156 if (result)
1157 cx231xx_err(DRIVER_NAME
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -03001158 " usb_register failed. Error number %d.\n", result);
Sri Deevie0d3baf2009-03-03 14:37:50 -03001159
1160 return result;
1161}
1162
1163static void __exit cx231xx_module_exit(void)
1164{
1165 /* deregister this driver with the USB subsystem */
1166 usb_deregister(&cx231xx_usb_driver);
1167}
1168
1169module_init(cx231xx_module_init);
1170module_exit(cx231xx_module_exit);