blob: ad9d0485614e8084d39512cc594c1cc3b504a65d [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);
498 cx231xx_set_gpio_direction(dev, dev->board.tuner_sif_gpio, 1);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300499
Mauro Carvalho Chehabc10469c2010-09-11 11:37:51 -0300500 /* request some modules if any required */
Mauro Carvalho Chehabc10469c2010-09-11 11:37:51 -0300501 }
Sri Deevie0d3baf2009-03-03 14:37:50 -0300502
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300503 /* set the mode to Analog mode initially */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300504 cx231xx_set_mode(dev, CX231XX_ANALOG_MODE);
505
506 /* Unlock device */
507 /* cx231xx_set_mode(dev, CX231XX_SUSPEND); */
508
509}
510
Sri Deevie0d3baf2009-03-03 14:37:50 -0300511static void cx231xx_config_tuner(struct cx231xx *dev)
512{
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300513 struct tuner_setup tun_setup;
514 struct v4l2_frequency f;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300515
516 if (dev->tuner_type == TUNER_ABSENT)
517 return;
518
519 tun_setup.mode_mask = T_ANALOG_TV | T_RADIO;
520 tun_setup.type = dev->tuner_type;
521 tun_setup.addr = dev->tuner_addr;
522 tun_setup.tuner_callback = cx231xx_tuner_callback;
523
Sri Deevib1196122009-03-20 23:33:48 -0300524 tuner_call(dev, tuner, s_type_addr, &tun_setup);
525
Sri Deevie0d3baf2009-03-03 14:37:50 -0300526#if 0
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300527 if (tun_setup.type == TUNER_XC5000) {
Sri Deevie0d3baf2009-03-03 14:37:50 -0300528 static struct xc2028_ctrl ctrl = {
529 .fname = XC5000_DEFAULT_FIRMWARE,
530 .max_len = 64,
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300531 .demod = 0;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300532 };
533 struct v4l2_priv_tun_config cfg = {
534 .tuner = dev->tuner_type,
535 .priv = &ctrl,
536 };
Sri Deevib1196122009-03-20 23:33:48 -0300537 tuner_call(dev, tuner, s_config, &cfg);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300538 }
539#endif
Sri Deevie0d3baf2009-03-03 14:37:50 -0300540 /* configure tuner */
541 f.tuner = 0;
542 f.type = V4L2_TUNER_ANALOG_TV;
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300543 f.frequency = 9076; /* just a magic number */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300544 dev->ctl_freq = f.frequency;
Sri Deevib1196122009-03-20 23:33:48 -0300545 call_all(dev, tuner, s_frequency, &f);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300546
Sri Deevib1196122009-03-20 23:33:48 -0300547}
Sri Deevie0d3baf2009-03-03 14:37:50 -0300548
549/* ----------------------------------------------------------------------- */
Jean Delvarec668f322009-05-13 16:48:50 -0300550void cx231xx_register_i2c_ir(struct cx231xx *dev)
551{
552 if (disable_ir)
553 return;
554
555 /* REVISIT: instantiate IR device */
Jean Delvarec668f322009-05-13 16:48:50 -0300556
Sri Deevie0d3baf2009-03-03 14:37:50 -0300557 /* detect & configure */
558 switch (dev->model) {
559
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300560 case CX231XX_BOARD_CNXT_CARRAERA:
561 break;
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300562 case CX231XX_BOARD_CNXT_RDE_250:
563 break;
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300564 case CX231XX_BOARD_CNXT_SHELBY:
565 break;
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300566 case CX231XX_BOARD_CNXT_RDU_250:
567 break;
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300568 case CX231XX_BOARD_CNXT_RDE_253S:
569 break;
570 case CX231XX_BOARD_CNXT_RDU_253S:
571 break;
572 case CX231XX_BOARD_CNXT_VIDEO_GRABBER:
573 break;
Michael Krufky1a50fdd2010-07-06 18:23:53 -0300574 case CX231XX_BOARD_HAUPPAUGE_EXETER:
575 break;
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300576 default:
577 break;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300578 }
579}
580
581void cx231xx_card_setup(struct cx231xx *dev)
582{
Sri Deevib1196122009-03-20 23:33:48 -0300583
Sri Deevie0d3baf2009-03-03 14:37:50 -0300584 cx231xx_set_model(dev);
585
586 dev->tuner_type = cx231xx_boards[dev->model].tuner_type;
587 if (cx231xx_boards[dev->model].tuner_addr)
588 dev->tuner_addr = cx231xx_boards[dev->model].tuner_addr;
589
Sri Deevie0d3baf2009-03-03 14:37:50 -0300590 /* request some modules */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300591 if (dev->board.decoder == CX231XX_AVDECODER) {
Hans Verkuile6574f22009-04-01 03:57:53 -0300592 dev->sd_cx25840 = v4l2_i2c_new_subdev(&dev->v4l2_dev,
593 &dev->i2c_bus[0].i2c_adap,
Hans Verkuil53dacb12009-08-10 02:49:08 -0300594 "cx25840", "cx25840", 0x88 >> 1, NULL);
Sri Deevib1196122009-03-20 23:33:48 -0300595 if (dev->sd_cx25840 == NULL)
596 cx231xx_info("cx25840 subdev registration failure\n");
Hans Verkuilcc26b072009-03-29 19:20:26 -0300597 cx25840_call(dev, core, load_fw);
Sri Deevib1196122009-03-20 23:33:48 -0300598
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300599 }
Sri Deevib1196122009-03-20 23:33:48 -0300600
Devin Heitmuellere3e0aaa2010-07-08 17:05:30 -0300601 /* Initialize the tuner */
602 if (dev->board.tuner_type != TUNER_ABSENT) {
603 dev->sd_tuner = v4l2_i2c_new_subdev(&dev->v4l2_dev,
604 &dev->i2c_bus[1].i2c_adap,
605 "tuner", "tuner",
606 dev->tuner_addr, NULL);
607 if (dev->sd_tuner == NULL)
608 cx231xx_info("tuner subdev registration failure\n");
609 else
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300610 cx231xx_config_tuner(dev);
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300611 }
Sri Deevie0d3baf2009-03-03 14:37:50 -0300612
Sri Deevib1196122009-03-20 23:33:48 -0300613#if 0
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300614 /* TBD IR will be added later */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300615 cx231xx_ir_init(dev);
616#endif
617}
618
Sri Deevie0d3baf2009-03-03 14:37:50 -0300619/*
620 * cx231xx_config()
621 * inits registers with sane defaults
622 */
623int cx231xx_config(struct cx231xx *dev)
624{
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300625 /* TBD need to add cx231xx specific code */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300626 dev->mute = 1; /* maybe not the right place... */
627 dev->volume = 0x1f;
628
629 return 0;
630}
631
632/*
633 * cx231xx_config_i2c()
634 * configure i2c attached devices
635 */
636void cx231xx_config_i2c(struct cx231xx *dev)
637{
Hans Verkuil5325b422009-04-02 11:26:22 -0300638 /* u32 input = INPUT(dev->video_input)->vmux; */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300639
Sri Deevib1196122009-03-20 23:33:48 -0300640 call_all(dev, video, s_stream, 1);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300641}
642
643/*
644 * cx231xx_realease_resources()
645 * unregisters the v4l2,i2c and usb devices
646 * called when the device gets disconected or at module unload
647*/
648void cx231xx_release_resources(struct cx231xx *dev)
649{
650
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300651#if 0 /* TBD IR related */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300652 if (dev->ir)
653 cx231xx_ir_fini(dev);
654#endif
655
656 cx231xx_release_analog_resources(dev);
657
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300658 cx231xx_remove_from_devlist(dev);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300659
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300660 cx231xx_dev_uninit(dev);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300661
662 usb_put_dev(dev->udev);
663
664 /* Mark device as unused */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300665 cx231xx_devused &= ~(1 << dev->devno);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300666}
667
Sri Deevie0d3baf2009-03-03 14:37:50 -0300668/*
669 * cx231xx_init_dev()
670 * allocates and inits the device structs, registers i2c bus and v4l device
671 */
672static int cx231xx_init_dev(struct cx231xx **devhandle, struct usb_device *udev,
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300673 int minor)
Sri Deevie0d3baf2009-03-03 14:37:50 -0300674{
675 struct cx231xx *dev = *devhandle;
676 int retval = -ENOMEM;
677 int errCode;
678 unsigned int maxh, maxw;
679
680 dev->udev = udev;
681 mutex_init(&dev->lock);
682 mutex_init(&dev->ctrl_urb_lock);
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300683 mutex_init(&dev->gpio_i2c_lock);
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300684 mutex_init(&dev->i2c_lock);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300685
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300686 spin_lock_init(&dev->video_mode.slock);
687 spin_lock_init(&dev->vbi_mode.slock);
688 spin_lock_init(&dev->sliced_cc_mode.slock);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300689
690 init_waitqueue_head(&dev->open);
691 init_waitqueue_head(&dev->wait_frame);
692 init_waitqueue_head(&dev->wait_stream);
693
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300694 dev->cx231xx_read_ctrl_reg = cx231xx_read_ctrl_reg;
695 dev->cx231xx_write_ctrl_reg = cx231xx_write_ctrl_reg;
696 dev->cx231xx_send_usb_command = cx231xx_send_usb_command;
697 dev->cx231xx_gpio_i2c_read = cx231xx_gpio_i2c_read;
698 dev->cx231xx_gpio_i2c_write = cx231xx_gpio_i2c_write;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300699
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300700 /* Query cx231xx to find what pcb config it is related to */
701 initialize_cx231xx(dev);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300702
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300703 /*To workaround error number=-71 on EP0 for VideoGrabber,
704 need set alt here.*/
Devin Heitmueller4270c3c2010-07-31 00:49:01 -0300705 if (dev->model == CX231XX_BOARD_CNXT_VIDEO_GRABBER ||
706 dev->model == CX231XX_BOARD_HAUPPAUGE_USBLIVE2) {
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300707 cx231xx_set_alt_setting(dev, INDEX_VIDEO, 3);
708 cx231xx_set_alt_setting(dev, INDEX_VANC, 1);
709 }
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300710 /* Cx231xx pre card setup */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300711 cx231xx_pre_card_setup(dev);
712
713 errCode = cx231xx_config(dev);
714 if (errCode) {
715 cx231xx_errdev("error configuring device\n");
716 return -ENOMEM;
717 }
718
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300719 /* set default norm */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300720 dev->norm = dev->board.norm;
721
722 /* register i2c bus */
723 errCode = cx231xx_dev_init(dev);
724 if (errCode < 0) {
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300725 cx231xx_dev_uninit(dev);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300726 cx231xx_errdev("%s: cx231xx_i2c_register - errCode [%d]!\n",
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300727 __func__, errCode);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300728 return errCode;
729 }
730
731 /* Do board specific init */
732 cx231xx_card_setup(dev);
733
734 /* configure the device */
735 cx231xx_config_i2c(dev);
736
737 maxw = norm_maxw(dev);
738 maxh = norm_maxh(dev);
739
740 /* set default image size */
741 dev->width = maxw;
742 dev->height = maxh;
743 dev->interlaced = 0;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300744 dev->video_input = 0;
745
746 errCode = cx231xx_config(dev);
747 if (errCode < 0) {
748 cx231xx_errdev("%s: cx231xx_config - errCode [%d]!\n",
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300749 __func__, errCode);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300750 return errCode;
751 }
752
753 /* init video dma queues */
754 INIT_LIST_HEAD(&dev->video_mode.vidq.active);
755 INIT_LIST_HEAD(&dev->video_mode.vidq.queued);
756
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300757 /* init vbi dma queues */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300758 INIT_LIST_HEAD(&dev->vbi_mode.vidq.active);
759 INIT_LIST_HEAD(&dev->vbi_mode.vidq.queued);
760
761 /* Reset other chips required if they are tied up with GPIO pins */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300762 cx231xx_add_into_devlist(dev);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300763
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300764 printk(KERN_INFO "attach 417 %d\n", dev->model);
765 if (dev->model == CX231XX_BOARD_CNXT_VIDEO_GRABBER) {
766 if (cx231xx_417_register(dev) < 0) {
767 printk(KERN_ERR
768 "%s() Failed to register 417 on VID_B\n",
769 __func__);
770 }
771 }
772
Sri Deevie0d3baf2009-03-03 14:37:50 -0300773 retval = cx231xx_register_analog_devices(dev);
774 if (retval < 0) {
775 cx231xx_release_resources(dev);
776 goto fail_reg_devices;
777 }
778
779 cx231xx_init_extension(dev);
780
781 return 0;
782
Sri Deevib9255172009-03-04 17:49:01 -0300783fail_reg_devices:
Sri Deevie0d3baf2009-03-03 14:37:50 -0300784 mutex_unlock(&dev->lock);
785 return retval;
786}
787
788#if defined(CONFIG_MODULES) && defined(MODULE)
789static void request_module_async(struct work_struct *work)
790{
791 struct cx231xx *dev = container_of(work,
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300792 struct cx231xx, request_module_wk);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300793
794 if (dev->has_alsa_audio)
795 request_module("cx231xx-alsa");
796
797 if (dev->board.has_dvb)
798 request_module("cx231xx-dvb");
799
800}
801
802static void request_modules(struct cx231xx *dev)
803{
804 INIT_WORK(&dev->request_module_wk, request_module_async);
805 schedule_work(&dev->request_module_wk);
806}
807#else
808#define request_modules(dev)
809#endif /* CONFIG_MODULES */
810
Sri Deevie0d3baf2009-03-03 14:37:50 -0300811/*
812 * cx231xx_usb_probe()
813 * checks for supported devices
814 */
815static int cx231xx_usb_probe(struct usb_interface *interface,
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300816 const struct usb_device_id *id)
Sri Deevie0d3baf2009-03-03 14:37:50 -0300817{
818 struct usb_device *udev;
819 struct usb_interface *uif;
820 struct cx231xx *dev = NULL;
821 int retval = -ENODEV;
Hans Verkuild73abcf2009-03-12 18:38:40 -0300822 int nr = 0, ifnum;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300823 int i, isoc_pipe = 0;
824 char *speed;
825 char descr[255] = "";
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300826 struct usb_interface *lif = NULL;
827 int skip_interface = 0;
828 struct usb_interface_assoc_descriptor *assoc_desc;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300829
830 udev = usb_get_dev(interface_to_usbdev(interface));
831 ifnum = interface->altsetting[0].desc.bInterfaceNumber;
832
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -0300833 if (!ifnum) {
834 /*
835 * Interface number 0 - IR interface
836 */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300837 /* Check to see next free device and mark as used */
838 nr = find_first_zero_bit(&cx231xx_devused, CX231XX_MAXBOARDS);
839 cx231xx_devused |= 1 << nr;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300840
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300841 if (nr >= CX231XX_MAXBOARDS) {
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300842 cx231xx_err(DRIVER_NAME
843 ": Supports only %i cx231xx boards.\n", CX231XX_MAXBOARDS);
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300844 cx231xx_devused &= ~(1 << nr);
845 return -ENOMEM;
846 }
Sri Deevie0d3baf2009-03-03 14:37:50 -0300847
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300848 /* allocate memory for our device state and initialize it */
849 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
850 if (dev == NULL) {
851 cx231xx_err(DRIVER_NAME ": out of memory!\n");
852 cx231xx_devused &= ~(1 << nr);
853 return -ENOMEM;
854 }
Sri Deevie0d3baf2009-03-03 14:37:50 -0300855
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300856 snprintf(dev->name, 29, "cx231xx #%d", nr);
857 dev->devno = nr;
858 dev->model = id->driver_info;
859 dev->video_mode.alt = -1;
860 dev->interface_count++;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300861
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300862 /* reset gpio dir and value */
863 dev->gpio_dir = 0;
864 dev->gpio_val = 0;
865 dev->xc_fw_load_done = 0;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300866 dev->has_alsa_audio = 1;
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300867 dev->power_mode = -1;
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300868 atomic_set(&dev->devlist_count, 0);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300869
Sri Deevib9255172009-03-04 17:49:01 -0300870 /* 0 - vbi ; 1 -sliced cc mode */
871 dev->vbi_or_sliced_cc_mode = 0;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300872
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300873 /* get maximum no.of IAD interfaces */
874 assoc_desc = udev->actconfig->intf_assoc[0];
875 dev->max_iad_interface_count = assoc_desc->bInterfaceCount;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300876
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300877 /* init CIR module TBD */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300878
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300879 /* store the current interface */
880 lif = interface;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300881
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300882 /*mode_tv: digital=1 or analog=0*/
883 dev->mode_tv = 0;
884
885 dev->USE_ISO = transfer_mode;
886
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -0300887 switch (udev->speed) {
888 case USB_SPEED_LOW:
889 speed = "1.5";
890 break;
891 case USB_SPEED_UNKNOWN:
892 case USB_SPEED_FULL:
893 speed = "12";
894 break;
895 case USB_SPEED_HIGH:
896 speed = "480";
897 break;
898 default:
899 speed = "unknown";
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300900 }
Sri Deevie0d3baf2009-03-03 14:37:50 -0300901
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -0300902 if (udev->manufacturer)
903 strlcpy(descr, udev->manufacturer, sizeof(descr));
Sri Deevie0d3baf2009-03-03 14:37:50 -0300904
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -0300905 if (udev->product) {
906 if (*descr)
907 strlcat(descr, " ", sizeof(descr));
908 strlcat(descr, udev->product, sizeof(descr));
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300909 }
Sri Deevie0d3baf2009-03-03 14:37:50 -0300910 if (*descr)
911 strlcat(descr, " ", sizeof(descr));
Sri Deevie0d3baf2009-03-03 14:37:50 -0300912
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -0300913 cx231xx_info("New device %s@ %s Mbps "
914 "(%04x:%04x) with %d interfaces\n",
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300915 descr,
916 speed,
917 le16_to_cpu(udev->descriptor.idVendor),
918 le16_to_cpu(udev->descriptor.idProduct),
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -0300919 dev->max_iad_interface_count);
920 } else {
921 /* Get dev structure first */
922 dev = usb_get_intfdata(udev->actconfig->interface[0]);
923 if (dev == NULL) {
924 cx231xx_err(DRIVER_NAME ": out of first interface!\n");
925 return -ENODEV;
Sri Deevib1196122009-03-20 23:33:48 -0300926 }
927
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -0300928 /* store the interface 0 back */
929 lif = udev->actconfig->interface[0];
Sri Deevie0d3baf2009-03-03 14:37:50 -0300930
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -0300931 /* increment interface count */
932 dev->interface_count++;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300933
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -0300934 /* get device number */
935 nr = dev->devno;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300936
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -0300937 /*
938 * set skip interface, for all interfaces but
939 * interface 1 and the last one
940 */
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300941 if ((ifnum != 1) && ((ifnum)
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -0300942 != dev->max_iad_interface_count))
943 skip_interface = 1;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300944
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -0300945 if (ifnum == 1) {
946 assoc_desc = udev->actconfig->intf_assoc[0];
947 if (assoc_desc->bFirstInterface != ifnum) {
948 cx231xx_err(DRIVER_NAME ": Not found "
949 "matching IAD interface\n");
950 return -ENODEV;
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300951 }
952 }
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300953 }
Sri Deevie0d3baf2009-03-03 14:37:50 -0300954
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -0300955 if (skip_interface)
956 return -ENODEV;
957
958 cx231xx_info("registering interface %d\n", ifnum);
959
Sri Deevie0d3baf2009-03-03 14:37:50 -0300960 /* save our data pointer in this interface device */
961 usb_set_intfdata(lif, dev);
962
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300963 if ((ifnum) != dev->max_iad_interface_count)
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -0300964 return 0;
965
966 /*
967 * AV device initialization - only done at the last interface
968 */
969
970 /* Create v4l2 device */
Janne Grunau72317482009-04-01 08:39:29 -0300971 retval = v4l2_device_register(&interface->dev, &dev->v4l2_dev);
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -0300972 if (retval) {
973 cx231xx_errdev("v4l2_device_register failed\n");
974 cx231xx_devused &= ~(1 << nr);
975 kfree(dev);
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300976 dev = NULL;
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -0300977 return -EIO;
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300978 }
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -0300979 /* allocate device struct */
980 retval = cx231xx_init_dev(&dev, udev, nr);
981 if (retval) {
982 cx231xx_devused &= ~(1 << dev->devno);
983 v4l2_device_unregister(&dev->v4l2_dev);
984 kfree(dev);
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300985 dev = NULL;
986 usb_set_intfdata(lif, NULL);
987
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -0300988 return retval;
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300989 }
Sri Deevie0d3baf2009-03-03 14:37:50 -0300990
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -0300991 /* compute alternate max packet sizes for video */
992 uif = udev->actconfig->interface[dev->current_pcb_config.
993 hs_config_info[0].interface_info.video_index + 1];
994
995 dev->video_mode.end_point_addr = le16_to_cpu(uif->altsetting[0].
996 endpoint[isoc_pipe].desc.bEndpointAddress);
997
998 dev->video_mode.num_alt = uif->num_altsetting;
999 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
1000 dev->video_mode.end_point_addr,
1001 dev->video_mode.num_alt);
1002 dev->video_mode.alt_max_pkt_size =
1003 kmalloc(32 * dev->video_mode.num_alt, GFP_KERNEL);
1004
1005 if (dev->video_mode.alt_max_pkt_size == NULL) {
1006 cx231xx_errdev("out of memory!\n");
1007 cx231xx_devused &= ~(1 << nr);
1008 v4l2_device_unregister(&dev->v4l2_dev);
1009 kfree(dev);
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -03001010 dev = NULL;
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001011 return -ENOMEM;
1012 }
1013
1014 for (i = 0; i < dev->video_mode.num_alt; i++) {
1015 u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
1016 desc.wMaxPacketSize);
1017 dev->video_mode.alt_max_pkt_size[i] =
1018 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
1019 cx231xx_info("Alternate setting %i, max size= %i\n", i,
1020 dev->video_mode.alt_max_pkt_size[i]);
1021 }
1022
1023 /* compute alternate max packet sizes for vbi */
1024 uif = udev->actconfig->interface[dev->current_pcb_config.
1025 hs_config_info[0].interface_info.
1026 vanc_index + 1];
1027
1028 dev->vbi_mode.end_point_addr =
1029 le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc.
1030 bEndpointAddress);
1031
1032 dev->vbi_mode.num_alt = uif->num_altsetting;
1033 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
1034 dev->vbi_mode.end_point_addr,
1035 dev->vbi_mode.num_alt);
1036 dev->vbi_mode.alt_max_pkt_size =
1037 kmalloc(32 * dev->vbi_mode.num_alt, GFP_KERNEL);
1038
1039 if (dev->vbi_mode.alt_max_pkt_size == NULL) {
1040 cx231xx_errdev("out of memory!\n");
1041 cx231xx_devused &= ~(1 << nr);
1042 v4l2_device_unregister(&dev->v4l2_dev);
1043 kfree(dev);
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -03001044 dev = NULL;
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001045 return -ENOMEM;
1046 }
1047
1048 for (i = 0; i < dev->vbi_mode.num_alt; i++) {
1049 u16 tmp =
1050 le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
1051 desc.wMaxPacketSize);
1052 dev->vbi_mode.alt_max_pkt_size[i] =
1053 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
1054 cx231xx_info("Alternate setting %i, max size= %i\n", i,
1055 dev->vbi_mode.alt_max_pkt_size[i]);
1056 }
1057
1058 /* compute alternate max packet sizes for sliced CC */
1059 uif = udev->actconfig->interface[dev->current_pcb_config.
1060 hs_config_info[0].interface_info.
1061 hanc_index + 1];
1062
1063 dev->sliced_cc_mode.end_point_addr =
1064 le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc.
1065 bEndpointAddress);
1066
1067 dev->sliced_cc_mode.num_alt = uif->num_altsetting;
1068 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
1069 dev->sliced_cc_mode.end_point_addr,
1070 dev->sliced_cc_mode.num_alt);
1071 dev->sliced_cc_mode.alt_max_pkt_size =
1072 kmalloc(32 * dev->sliced_cc_mode.num_alt, GFP_KERNEL);
1073
1074 if (dev->sliced_cc_mode.alt_max_pkt_size == NULL) {
1075 cx231xx_errdev("out of memory!\n");
1076 cx231xx_devused &= ~(1 << nr);
1077 v4l2_device_unregister(&dev->v4l2_dev);
1078 kfree(dev);
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -03001079 dev = NULL;
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001080 return -ENOMEM;
1081 }
1082
1083 for (i = 0; i < dev->sliced_cc_mode.num_alt; i++) {
1084 u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
1085 desc.wMaxPacketSize);
1086 dev->sliced_cc_mode.alt_max_pkt_size[i] =
1087 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
1088 cx231xx_info("Alternate setting %i, max size= %i\n", i,
1089 dev->sliced_cc_mode.alt_max_pkt_size[i]);
1090 }
1091
1092 if (dev->current_pcb_config.ts1_source != 0xff) {
1093 /* compute alternate max packet sizes for TS1 */
1094 uif = udev->actconfig->interface[dev->current_pcb_config.
1095 hs_config_info[0].
1096 interface_info.
1097 ts1_index + 1];
1098
1099 dev->ts1_mode.end_point_addr =
1100 le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].
1101 desc.bEndpointAddress);
1102
1103 dev->ts1_mode.num_alt = uif->num_altsetting;
1104 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
1105 dev->ts1_mode.end_point_addr,
1106 dev->ts1_mode.num_alt);
1107 dev->ts1_mode.alt_max_pkt_size =
1108 kmalloc(32 * dev->ts1_mode.num_alt, GFP_KERNEL);
1109
1110 if (dev->ts1_mode.alt_max_pkt_size == NULL) {
1111 cx231xx_errdev("out of memory!\n");
1112 cx231xx_devused &= ~(1 << nr);
1113 v4l2_device_unregister(&dev->v4l2_dev);
1114 kfree(dev);
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -03001115 dev = NULL;
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001116 return -ENOMEM;
1117 }
1118
1119 for (i = 0; i < dev->ts1_mode.num_alt; i++) {
1120 u16 tmp = le16_to_cpu(uif->altsetting[i].
1121 endpoint[isoc_pipe].desc.
1122 wMaxPacketSize);
1123 dev->ts1_mode.alt_max_pkt_size[i] =
1124 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
1125 cx231xx_info("Alternate setting %i, max size= %i\n", i,
1126 dev->ts1_mode.alt_max_pkt_size[i]);
1127 }
1128 }
1129
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -03001130 if (dev->model == CX231XX_BOARD_CNXT_VIDEO_GRABBER) {
1131 cx231xx_enable_OSC(dev);
1132 cx231xx_reset_out(dev);
1133 cx231xx_set_alt_setting(dev, INDEX_VIDEO, 3);
1134 }
1135
1136 if (dev->model == CX231XX_BOARD_CNXT_RDE_253S)
1137 cx231xx_sleep_s5h1432(dev);
1138
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001139 /* load other modules required */
1140 request_modules(dev);
1141
Sri Deevie0d3baf2009-03-03 14:37:50 -03001142 return 0;
1143}
1144
1145/*
1146 * cx231xx_usb_disconnect()
1147 * called when the device gets diconencted
1148 * video device will be unregistered on v4l2_close in case it is still open
1149 */
1150static void cx231xx_usb_disconnect(struct usb_interface *interface)
1151{
1152 struct cx231xx *dev;
1153
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -03001154 dev = usb_get_intfdata(interface);
Sri Deevie0d3baf2009-03-03 14:37:50 -03001155 usb_set_intfdata(interface, NULL);
1156
1157 if (!dev)
1158 return;
1159
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001160 if (!dev->udev)
1161 return;
1162
Sri Deevib1196122009-03-20 23:33:48 -03001163 /* delete v4l2 device */
1164 v4l2_device_unregister(&dev->v4l2_dev);
1165
Sri Deevie0d3baf2009-03-03 14:37:50 -03001166 /* wait until all current v4l2 io is finished then deallocate
1167 resources */
1168 mutex_lock(&dev->lock);
1169
1170 wake_up_interruptible_all(&dev->open);
1171
1172 if (dev->users) {
1173 cx231xx_warn
Laurent Pinchart38c7c032009-11-27 13:57:15 -03001174 ("device %s is open! Deregistration and memory "
1175 "deallocation are deferred on close.\n",
1176 video_device_node_name(dev->vdev));
Sri Deevie0d3baf2009-03-03 14:37:50 -03001177
1178 dev->state |= DEV_MISCONFIGURED;
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -03001179 if (dev->USE_ISO)
1180 cx231xx_uninit_isoc(dev);
1181 else
1182 cx231xx_uninit_bulk(dev);
Sri Deevie0d3baf2009-03-03 14:37:50 -03001183 dev->state |= DEV_DISCONNECTED;
1184 wake_up_interruptible(&dev->wait_frame);
1185 wake_up_interruptible(&dev->wait_stream);
1186 } else {
1187 dev->state |= DEV_DISCONNECTED;
1188 cx231xx_release_resources(dev);
1189 }
1190
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -03001191 cx231xx_close_extension(dev);
Sri Deevie0d3baf2009-03-03 14:37:50 -03001192
1193 mutex_unlock(&dev->lock);
1194
1195 if (!dev->users) {
1196 kfree(dev->video_mode.alt_max_pkt_size);
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -03001197 kfree(dev->vbi_mode.alt_max_pkt_size);
1198 kfree(dev->sliced_cc_mode.alt_max_pkt_size);
1199 kfree(dev->ts1_mode.alt_max_pkt_size);
Sri Deevie0d3baf2009-03-03 14:37:50 -03001200 kfree(dev);
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -03001201 dev = NULL;
Sri Deevie0d3baf2009-03-03 14:37:50 -03001202 }
1203}
1204
1205static struct usb_driver cx231xx_usb_driver = {
1206 .name = "cx231xx",
1207 .probe = cx231xx_usb_probe,
1208 .disconnect = cx231xx_usb_disconnect,
1209 .id_table = cx231xx_id_table,
1210};
1211
1212static int __init cx231xx_module_init(void)
1213{
1214 int result;
1215
Mauro Carvalho Chehab818fdf32009-03-13 07:41:58 -03001216 printk(KERN_INFO DRIVER_NAME " v4l2 driver loaded.\n");
Sri Deevie0d3baf2009-03-03 14:37:50 -03001217
1218 /* register this driver with the USB subsystem */
1219 result = usb_register(&cx231xx_usb_driver);
1220 if (result)
1221 cx231xx_err(DRIVER_NAME
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -03001222 " usb_register failed. Error number %d.\n", result);
Sri Deevie0d3baf2009-03-03 14:37:50 -03001223
1224 return result;
1225}
1226
1227static void __exit cx231xx_module_exit(void)
1228{
1229 /* deregister this driver with the USB subsystem */
1230 usb_deregister(&cx231xx_usb_driver);
1231}
1232
1233module_init(cx231xx_module_init);
1234module_exit(cx231xx_module_exit);