blob: 627829f4d8c96e40b83a085e217dadabc4029b22 [file] [log] [blame]
Sri Deevie0d3baf2009-03-03 14:37:50 -03001/*
Sri Deevib9255172009-03-04 17:49:01 -03002 cx231xx-cards.c - driver for Conexant Cx23100/101/102
3 USB video capture devices
Sri Deevie0d3baf2009-03-03 14:37:50 -03004
5 Copyright (C) 2008 <srinivasa.deevi at conexant dot com>
Sri Deevib9255172009-03-04 17:49:01 -03006 Based on em28xx driver
Sri Deevie0d3baf2009-03-03 14:37:50 -03007
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23#include <linux/init.h>
24#include <linux/module.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090025#include <linux/slab.h>
Sri Deevie0d3baf2009-03-03 14:37:50 -030026#include <linux/delay.h>
27#include <linux/i2c.h>
28#include <linux/usb.h>
29#include <media/tuner.h>
30#include <media/tveeprom.h>
31#include <media/v4l2-common.h>
32#include <media/v4l2-chip-ident.h>
33
34#include <media/cx25840.h>
Mauro Carvalho Chehab3bfb3172010-09-03 10:50:24 -030035#include "dvb-usb-ids.h"
Sri Deevie0d3baf2009-03-03 14:37:50 -030036#include "xc5000.h"
Mauro Carvalho Chehab55fa2882010-09-29 11:07:08 -030037#include "tda18271.h"
Sri Deevie0d3baf2009-03-03 14:37:50 -030038
39#include "cx231xx.h"
40
41static int tuner = -1;
42module_param(tuner, int, 0444);
43MODULE_PARM_DESC(tuner, "tuner type");
44
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -030045static int transfer_mode = 1;
46module_param(transfer_mode, int, 0444);
47MODULE_PARM_DESC(transfer_mode, "transfer mode (1-ISO or 0-BULK)");
48
Sri Deevie0d3baf2009-03-03 14:37:50 -030049static unsigned int disable_ir;
50module_param(disable_ir, int, 0444);
51MODULE_PARM_DESC(disable_ir, "disable infrared remote support");
52
53/* Bitmask marking allocated devices from 0 to CX231XX_MAXBOARDS */
54static unsigned long cx231xx_devused;
55
56/*
57 * Reset sequences for analog/digital modes
58 */
59
60static struct cx231xx_reg_seq RDE250_XCV_TUNER[] = {
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -030061 {0x03, 0x01, 10},
62 {0x03, 0x00, 30},
63 {0x03, 0x01, 10},
64 {-1, -1, -1},
Sri Deevie0d3baf2009-03-03 14:37:50 -030065};
66
Sri Deevie0d3baf2009-03-03 14:37:50 -030067/*
68 * Board definitions
69 */
70struct cx231xx_board cx231xx_boards[] = {
Sri Deevie0d3baf2009-03-03 14:37:50 -030071 [CX231XX_BOARD_UNKNOWN] = {
Sri Deevi6e4f5742009-03-10 21:16:26 -030072 .name = "Unknown CX231xx video grabber",
73 .tuner_type = TUNER_ABSENT,
74 .input = {{
75 .type = CX231XX_VMUX_TELEVISION,
76 .vmux = CX231XX_VIN_3_1,
77 .amux = CX231XX_AMUX_VIDEO,
Márton Németh7ee0a282009-12-13 17:06:10 -030078 .gpio = NULL,
Sri Deevi6e4f5742009-03-10 21:16:26 -030079 }, {
80 .type = CX231XX_VMUX_COMPOSITE1,
81 .vmux = CX231XX_VIN_2_1,
82 .amux = CX231XX_AMUX_LINE_IN,
Márton Németh7ee0a282009-12-13 17:06:10 -030083 .gpio = NULL,
Sri Deevi6e4f5742009-03-10 21:16:26 -030084 }, {
85 .type = CX231XX_VMUX_SVIDEO,
86 .vmux = CX231XX_VIN_1_1 |
87 (CX231XX_VIN_1_2 << 8) |
88 CX25840_SVIDEO_ON,
89 .amux = CX231XX_AMUX_LINE_IN,
Márton Németh7ee0a282009-12-13 17:06:10 -030090 .gpio = NULL,
Sri Deevi6e4f5742009-03-10 21:16:26 -030091 }
92 },
93 },
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -030094 [CX231XX_BOARD_CNXT_CARRAERA] = {
95 .name = "Conexant Hybrid TV - CARRAERA",
Sri Deevi6e4f5742009-03-10 21:16:26 -030096 .tuner_type = TUNER_XC5000,
97 .tuner_addr = 0x61,
98 .tuner_gpio = RDE250_XCV_TUNER,
99 .tuner_sif_gpio = 0x05,
100 .tuner_scl_gpio = 0x1a,
101 .tuner_sda_gpio = 0x1b,
102 .decoder = CX231XX_AVDECODER,
Devin Heitmueller88806212010-08-18 17:50:07 -0300103 .output_mode = OUT_MODE_VIP11,
Sri Deevi6e4f5742009-03-10 21:16:26 -0300104 .demod_xfer_mode = 0,
105 .ctl_pin_status_mask = 0xFFFFFFC4,
106 .agc_analog_digital_select_gpio = 0x0c,
107 .gpio_pin_status_mask = 0x4001000,
108 .tuner_i2c_master = 1,
109 .demod_i2c_master = 2,
110 .has_dvb = 1,
111 .demod_addr = 0x02,
112 .norm = V4L2_STD_PAL,
Sri Deevie0d3baf2009-03-03 14:37:50 -0300113
Sri Deevi6e4f5742009-03-10 21:16:26 -0300114 .input = {{
115 .type = CX231XX_VMUX_TELEVISION,
116 .vmux = CX231XX_VIN_3_1,
117 .amux = CX231XX_AMUX_VIDEO,
Márton Németh7ee0a282009-12-13 17:06:10 -0300118 .gpio = NULL,
Sri Deevi6e4f5742009-03-10 21:16:26 -0300119 }, {
120 .type = CX231XX_VMUX_COMPOSITE1,
121 .vmux = CX231XX_VIN_2_1,
122 .amux = CX231XX_AMUX_LINE_IN,
Márton Németh7ee0a282009-12-13 17:06:10 -0300123 .gpio = NULL,
Sri Deevi6e4f5742009-03-10 21:16:26 -0300124 }, {
125 .type = CX231XX_VMUX_SVIDEO,
126 .vmux = CX231XX_VIN_1_1 |
127 (CX231XX_VIN_1_2 << 8) |
128 CX25840_SVIDEO_ON,
129 .amux = CX231XX_AMUX_LINE_IN,
Márton Németh7ee0a282009-12-13 17:06:10 -0300130 .gpio = NULL,
Sri Deevi6e4f5742009-03-10 21:16:26 -0300131 }
132 },
133 },
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300134 [CX231XX_BOARD_CNXT_SHELBY] = {
135 .name = "Conexant Hybrid TV - SHELBY",
Sri Deevi6e4f5742009-03-10 21:16:26 -0300136 .tuner_type = TUNER_XC5000,
137 .tuner_addr = 0x61,
138 .tuner_gpio = RDE250_XCV_TUNER,
139 .tuner_sif_gpio = 0x05,
140 .tuner_scl_gpio = 0x1a,
141 .tuner_sda_gpio = 0x1b,
142 .decoder = CX231XX_AVDECODER,
Devin Heitmueller88806212010-08-18 17:50:07 -0300143 .output_mode = OUT_MODE_VIP11,
Sri Deevi6e4f5742009-03-10 21:16:26 -0300144 .demod_xfer_mode = 0,
145 .ctl_pin_status_mask = 0xFFFFFFC4,
146 .agc_analog_digital_select_gpio = 0x0c,
147 .gpio_pin_status_mask = 0x4001000,
148 .tuner_i2c_master = 1,
149 .demod_i2c_master = 2,
150 .has_dvb = 1,
151 .demod_addr = 0x32,
152 .norm = V4L2_STD_NTSC,
Sri Deevie0d3baf2009-03-03 14:37:50 -0300153
Sri Deevi6e4f5742009-03-10 21:16:26 -0300154 .input = {{
155 .type = CX231XX_VMUX_TELEVISION,
156 .vmux = CX231XX_VIN_3_1,
157 .amux = CX231XX_AMUX_VIDEO,
Márton Németh7ee0a282009-12-13 17:06:10 -0300158 .gpio = NULL,
Sri Deevi6e4f5742009-03-10 21:16:26 -0300159 }, {
160 .type = CX231XX_VMUX_COMPOSITE1,
161 .vmux = CX231XX_VIN_2_1,
162 .amux = CX231XX_AMUX_LINE_IN,
Márton Németh7ee0a282009-12-13 17:06:10 -0300163 .gpio = NULL,
Sri Deevi6e4f5742009-03-10 21:16:26 -0300164 }, {
165 .type = CX231XX_VMUX_SVIDEO,
166 .vmux = CX231XX_VIN_1_1 |
167 (CX231XX_VIN_1_2 << 8) |
168 CX25840_SVIDEO_ON,
169 .amux = CX231XX_AMUX_LINE_IN,
Márton Németh7ee0a282009-12-13 17:06:10 -0300170 .gpio = NULL,
Sri Deevi6e4f5742009-03-10 21:16:26 -0300171 }
172 },
173 },
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300174 [CX231XX_BOARD_CNXT_RDE_253S] = {
175 .name = "Conexant Hybrid TV - RDE253S",
176 .tuner_type = TUNER_NXP_TDA18271,
177 .tuner_addr = 0x60,
178 .tuner_gpio = RDE250_XCV_TUNER,
179 .tuner_sif_gpio = 0x05,
180 .tuner_scl_gpio = 0x1a,
181 .tuner_sda_gpio = 0x1b,
182 .decoder = CX231XX_AVDECODER,
Devin Heitmueller88806212010-08-18 17:50:07 -0300183 .output_mode = OUT_MODE_VIP11,
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300184 .demod_xfer_mode = 0,
185 .ctl_pin_status_mask = 0xFFFFFFC4,
186 .agc_analog_digital_select_gpio = 0x1c,
187 .gpio_pin_status_mask = 0x4001000,
188 .tuner_i2c_master = 1,
189 .demod_i2c_master = 2,
190 .has_dvb = 1,
191 .demod_addr = 0x02,
192 .norm = V4L2_STD_PAL,
193
194 .input = {{
195 .type = CX231XX_VMUX_TELEVISION,
196 .vmux = CX231XX_VIN_3_1,
197 .amux = CX231XX_AMUX_VIDEO,
198 .gpio = NULL,
199 }, {
200 .type = CX231XX_VMUX_COMPOSITE1,
201 .vmux = CX231XX_VIN_2_1,
202 .amux = CX231XX_AMUX_LINE_IN,
203 .gpio = NULL,
204 }, {
205 .type = CX231XX_VMUX_SVIDEO,
206 .vmux = CX231XX_VIN_1_1 |
207 (CX231XX_VIN_1_2 << 8) |
208 CX25840_SVIDEO_ON,
209 .amux = CX231XX_AMUX_LINE_IN,
210 .gpio = NULL,
211 }
212 },
213 },
214
215 [CX231XX_BOARD_CNXT_RDU_253S] = {
216 .name = "Conexant Hybrid TV - RDU253S",
217 .tuner_type = TUNER_NXP_TDA18271,
218 .tuner_addr = 0x60,
219 .tuner_gpio = RDE250_XCV_TUNER,
220 .tuner_sif_gpio = 0x05,
221 .tuner_scl_gpio = 0x1a,
222 .tuner_sda_gpio = 0x1b,
223 .decoder = CX231XX_AVDECODER,
Devin Heitmueller88806212010-08-18 17:50:07 -0300224 .output_mode = OUT_MODE_VIP11,
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300225 .demod_xfer_mode = 0,
226 .ctl_pin_status_mask = 0xFFFFFFC4,
227 .agc_analog_digital_select_gpio = 0x1c,
228 .gpio_pin_status_mask = 0x4001000,
229 .tuner_i2c_master = 1,
230 .demod_i2c_master = 2,
231 .has_dvb = 1,
232 .demod_addr = 0x02,
233 .norm = V4L2_STD_PAL,
234
235 .input = {{
236 .type = CX231XX_VMUX_TELEVISION,
237 .vmux = CX231XX_VIN_3_1,
238 .amux = CX231XX_AMUX_VIDEO,
239 .gpio = NULL,
240 }, {
241 .type = CX231XX_VMUX_COMPOSITE1,
242 .vmux = CX231XX_VIN_2_1,
243 .amux = CX231XX_AMUX_LINE_IN,
244 .gpio = NULL,
245 }, {
246 .type = CX231XX_VMUX_SVIDEO,
247 .vmux = CX231XX_VIN_1_1 |
248 (CX231XX_VIN_1_2 << 8) |
249 CX25840_SVIDEO_ON,
250 .amux = CX231XX_AMUX_LINE_IN,
251 .gpio = NULL,
252 }
253 },
254 },
255 [CX231XX_BOARD_CNXT_VIDEO_GRABBER] = {
256 .name = "Conexant VIDEO GRABBER",
Devin Heitmueller9f512592010-08-18 18:04:04 -0300257 .tuner_type = TUNER_ABSENT,
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300258 .decoder = CX231XX_AVDECODER,
Devin Heitmueller88806212010-08-18 17:50:07 -0300259 .output_mode = OUT_MODE_VIP11,
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300260 .ctl_pin_status_mask = 0xFFFFFFC4,
261 .agc_analog_digital_select_gpio = 0x1c,
262 .gpio_pin_status_mask = 0x4001000,
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300263 .norm = V4L2_STD_PAL,
Mauro Carvalho Chehab2f861382011-01-31 22:12:15 -0300264 .no_alt_vanc = 1,
265 .external_av = 1,
266 .has_417 = 1,
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300267
268 .input = {{
269 .type = CX231XX_VMUX_COMPOSITE1,
270 .vmux = CX231XX_VIN_2_1,
271 .amux = CX231XX_AMUX_LINE_IN,
272 .gpio = NULL,
273 }, {
274 .type = CX231XX_VMUX_SVIDEO,
275 .vmux = CX231XX_VIN_1_1 |
276 (CX231XX_VIN_1_2 << 8) |
277 CX25840_SVIDEO_ON,
278 .amux = CX231XX_AMUX_LINE_IN,
279 .gpio = NULL,
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300280 }
281 },
282 },
283 [CX231XX_BOARD_CNXT_RDE_250] = {
284 .name = "Conexant Hybrid TV - rde 250",
285 .tuner_type = TUNER_XC5000,
286 .tuner_addr = 0x61,
287 .tuner_gpio = RDE250_XCV_TUNER,
288 .tuner_sif_gpio = 0x05,
289 .tuner_scl_gpio = 0x1a,
290 .tuner_sda_gpio = 0x1b,
291 .decoder = CX231XX_AVDECODER,
Devin Heitmueller88806212010-08-18 17:50:07 -0300292 .output_mode = OUT_MODE_VIP11,
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300293 .demod_xfer_mode = 0,
294 .ctl_pin_status_mask = 0xFFFFFFC4,
295 .agc_analog_digital_select_gpio = 0x0c,
296 .gpio_pin_status_mask = 0x4001000,
297 .tuner_i2c_master = 1,
298 .demod_i2c_master = 2,
299 .has_dvb = 1,
300 .demod_addr = 0x02,
301 .norm = V4L2_STD_PAL,
302
303 .input = {{
304 .type = CX231XX_VMUX_TELEVISION,
305 .vmux = CX231XX_VIN_2_1,
306 .amux = CX231XX_AMUX_VIDEO,
307 .gpio = NULL,
308 }
309 },
310 },
311 [CX231XX_BOARD_CNXT_RDU_250] = {
312 .name = "Conexant Hybrid TV - RDU 250",
313 .tuner_type = TUNER_XC5000,
314 .tuner_addr = 0x61,
315 .tuner_gpio = RDE250_XCV_TUNER,
316 .tuner_sif_gpio = 0x05,
317 .tuner_scl_gpio = 0x1a,
318 .tuner_sda_gpio = 0x1b,
319 .decoder = CX231XX_AVDECODER,
Devin Heitmueller88806212010-08-18 17:50:07 -0300320 .output_mode = OUT_MODE_VIP11,
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300321 .demod_xfer_mode = 0,
322 .ctl_pin_status_mask = 0xFFFFFFC4,
323 .agc_analog_digital_select_gpio = 0x0c,
324 .gpio_pin_status_mask = 0x4001000,
325 .tuner_i2c_master = 1,
326 .demod_i2c_master = 2,
327 .has_dvb = 1,
328 .demod_addr = 0x32,
329 .norm = V4L2_STD_NTSC,
330
331 .input = {{
332 .type = CX231XX_VMUX_TELEVISION,
333 .vmux = CX231XX_VIN_2_1,
334 .amux = CX231XX_AMUX_VIDEO,
335 .gpio = NULL,
336 }
337 },
338 },
Michael Krufky1a50fdd2010-07-06 18:23:53 -0300339 [CX231XX_BOARD_HAUPPAUGE_EXETER] = {
340 .name = "Hauppauge EXETER",
341 .tuner_type = TUNER_NXP_TDA18271,
342 .tuner_addr = 0x60,
343 .tuner_gpio = RDE250_XCV_TUNER,
344 .tuner_sif_gpio = 0x05,
345 .tuner_scl_gpio = 0x1a,
346 .tuner_sda_gpio = 0x1b,
347 .decoder = CX231XX_AVDECODER,
Devin Heitmueller88806212010-08-18 17:50:07 -0300348 .output_mode = OUT_MODE_VIP11,
Michael Krufky1a50fdd2010-07-06 18:23:53 -0300349 .demod_xfer_mode = 0,
350 .ctl_pin_status_mask = 0xFFFFFFC4,
351 .agc_analog_digital_select_gpio = 0x0c,
352 .gpio_pin_status_mask = 0x4001000,
353 .tuner_i2c_master = 1,
354 .demod_i2c_master = 2,
355 .has_dvb = 1,
356 .demod_addr = 0x0e,
357 .norm = V4L2_STD_NTSC,
358
359 .input = {{
360 .type = CX231XX_VMUX_TELEVISION,
361 .vmux = CX231XX_VIN_3_1,
362 .amux = CX231XX_AMUX_VIDEO,
Peter Huewef72cfd82011-01-25 17:38:52 -0300363 .gpio = NULL,
Michael Krufky1a50fdd2010-07-06 18:23:53 -0300364 }, {
365 .type = CX231XX_VMUX_COMPOSITE1,
366 .vmux = CX231XX_VIN_2_1,
367 .amux = CX231XX_AMUX_LINE_IN,
Peter Huewef72cfd82011-01-25 17:38:52 -0300368 .gpio = NULL,
Michael Krufky1a50fdd2010-07-06 18:23:53 -0300369 }, {
370 .type = CX231XX_VMUX_SVIDEO,
371 .vmux = CX231XX_VIN_1_1 |
372 (CX231XX_VIN_1_2 << 8) |
373 CX25840_SVIDEO_ON,
374 .amux = CX231XX_AMUX_LINE_IN,
Peter Huewef72cfd82011-01-25 17:38:52 -0300375 .gpio = NULL,
Michael Krufky1a50fdd2010-07-06 18:23:53 -0300376 } },
377 },
Devin Heitmueller4270c3c2010-07-31 00:49:01 -0300378 [CX231XX_BOARD_HAUPPAUGE_USBLIVE2] = {
379 .name = "Hauppauge USB Live 2",
380 .tuner_type = TUNER_ABSENT,
381 .decoder = CX231XX_AVDECODER,
Devin Heitmueller88806212010-08-18 17:50:07 -0300382 .output_mode = OUT_MODE_VIP11,
Devin Heitmueller4270c3c2010-07-31 00:49:01 -0300383 .demod_xfer_mode = 0,
384 .ctl_pin_status_mask = 0xFFFFFFC4,
385 .agc_analog_digital_select_gpio = 0x0c,
386 .gpio_pin_status_mask = 0x4001000,
387 .norm = V4L2_STD_NTSC,
Mauro Carvalho Chehab2f861382011-01-31 22:12:15 -0300388 .no_alt_vanc = 1,
389 .external_av = 1,
Devin Heitmueller992299e2011-07-23 22:17:17 -0300390 .dont_use_port_3 = 1,
Devin Heitmueller4270c3c2010-07-31 00:49:01 -0300391 .input = {{
392 .type = CX231XX_VMUX_COMPOSITE1,
393 .vmux = CX231XX_VIN_2_1,
394 .amux = CX231XX_AMUX_LINE_IN,
Peter Huewef72cfd82011-01-25 17:38:52 -0300395 .gpio = NULL,
Devin Heitmueller4270c3c2010-07-31 00:49:01 -0300396 }, {
397 .type = CX231XX_VMUX_SVIDEO,
398 .vmux = CX231XX_VIN_1_1 |
399 (CX231XX_VIN_1_2 << 8) |
400 CX25840_SVIDEO_ON,
401 .amux = CX231XX_AMUX_LINE_IN,
Peter Huewef72cfd82011-01-25 17:38:52 -0300402 .gpio = NULL,
Devin Heitmueller4270c3c2010-07-31 00:49:01 -0300403 } },
404 },
Márcio Alveseeaaf812011-04-11 19:57:15 -0300405 [CX231XX_BOARD_KWORLD_UB430_USB_HYBRID] = {
406 .name = "Kworld UB430 USB Hybrid",
407 .tuner_type = TUNER_NXP_TDA18271,
408 .tuner_addr = 0x60,
409 .decoder = CX231XX_AVDECODER,
410 .output_mode = OUT_MODE_VIP11,
411 .demod_xfer_mode = 0,
412 .ctl_pin_status_mask = 0xFFFFFFC4,
413 .agc_analog_digital_select_gpio = 0x11, /* According with PV cxPolaris.inf file */
414 .tuner_sif_gpio = -1,
415 .tuner_scl_gpio = -1,
416 .tuner_sda_gpio = -1,
417 .gpio_pin_status_mask = 0x4001000,
418 .tuner_i2c_master = 2,
419 .demod_i2c_master = 1,
420 .ir_i2c_master = 2,
421 .has_dvb = 1,
422 .demod_addr = 0x10,
423 .norm = V4L2_STD_PAL_M,
424 .input = {{
425 .type = CX231XX_VMUX_TELEVISION,
426 .vmux = CX231XX_VIN_3_1,
427 .amux = CX231XX_AMUX_VIDEO,
428 .gpio = NULL,
429 }, {
430 .type = CX231XX_VMUX_COMPOSITE1,
431 .vmux = CX231XX_VIN_2_1,
432 .amux = CX231XX_AMUX_LINE_IN,
433 .gpio = NULL,
434 }, {
435 .type = CX231XX_VMUX_SVIDEO,
436 .vmux = CX231XX_VIN_1_1 |
437 (CX231XX_VIN_1_2 << 8) |
438 CX25840_SVIDEO_ON,
439 .amux = CX231XX_AMUX_LINE_IN,
440 .gpio = NULL,
441 } },
442 },
Mauro Carvalho Chehab9417bc62010-09-26 20:44:31 -0300443 [CX231XX_BOARD_PV_PLAYTV_USB_HYBRID] = {
444 .name = "Pixelview PlayTV USB Hybrid",
445 .tuner_type = TUNER_NXP_TDA18271,
446 .tuner_addr = 0x60,
447 .decoder = CX231XX_AVDECODER,
448 .output_mode = OUT_MODE_VIP11,
449 .demod_xfer_mode = 0,
450 .ctl_pin_status_mask = 0xFFFFFFC4,
451 .agc_analog_digital_select_gpio = 0x00, /* According with PV cxPolaris.inf file */
452 .tuner_sif_gpio = -1,
453 .tuner_scl_gpio = -1,
454 .tuner_sda_gpio = -1,
455 .gpio_pin_status_mask = 0x4001000,
456 .tuner_i2c_master = 2,
457 .demod_i2c_master = 1,
Mauro Carvalho Chehab1bc25f72010-10-23 13:35:58 -0300458 .ir_i2c_master = 2,
Mauro Carvalho Chehab788e5d42010-12-17 14:47:27 -0300459 .rc_map_name = RC_MAP_PIXELVIEW_002T,
Mauro Carvalho Chehabede676c2010-09-27 23:44:27 -0300460 .has_dvb = 1,
Mauro Carvalho Chehab9417bc62010-09-26 20:44:31 -0300461 .demod_addr = 0x10,
462 .norm = V4L2_STD_PAL_M,
463 .input = {{
464 .type = CX231XX_VMUX_TELEVISION,
465 .vmux = CX231XX_VIN_3_1,
466 .amux = CX231XX_AMUX_VIDEO,
Peter Huewef72cfd82011-01-25 17:38:52 -0300467 .gpio = NULL,
Mauro Carvalho Chehab9417bc62010-09-26 20:44:31 -0300468 }, {
469 .type = CX231XX_VMUX_COMPOSITE1,
470 .vmux = CX231XX_VIN_2_1,
471 .amux = CX231XX_AMUX_LINE_IN,
Peter Huewef72cfd82011-01-25 17:38:52 -0300472 .gpio = NULL,
Mauro Carvalho Chehab9417bc62010-09-26 20:44:31 -0300473 }, {
474 .type = CX231XX_VMUX_SVIDEO,
475 .vmux = CX231XX_VIN_1_1 |
476 (CX231XX_VIN_1_2 << 8) |
477 CX25840_SVIDEO_ON,
478 .amux = CX231XX_AMUX_LINE_IN,
Peter Huewef72cfd82011-01-25 17:38:52 -0300479 .gpio = NULL,
Mauro Carvalho Chehab9417bc62010-09-26 20:44:31 -0300480 } },
481 },
Mauro Carvalho Chehab4e105032011-01-31 22:18:21 -0300482 [CX231XX_BOARD_PV_XCAPTURE_USB] = {
483 .name = "Pixelview Xcapture USB",
484 .tuner_type = TUNER_ABSENT,
485 .decoder = CX231XX_AVDECODER,
486 .output_mode = OUT_MODE_VIP11,
487 .demod_xfer_mode = 0,
488 .ctl_pin_status_mask = 0xFFFFFFC4,
489 .agc_analog_digital_select_gpio = 0x0c,
490 .gpio_pin_status_mask = 0x4001000,
491 .norm = V4L2_STD_NTSC,
492 .no_alt_vanc = 1,
493 .external_av = 1,
494 .dont_use_port_3 = 1,
495
496 .input = {{
497 .type = CX231XX_VMUX_COMPOSITE1,
498 .vmux = CX231XX_VIN_2_1,
499 .amux = CX231XX_AMUX_LINE_IN,
500 .gpio = NULL,
501 }, {
502 .type = CX231XX_VMUX_SVIDEO,
503 .vmux = CX231XX_VIN_1_1 |
504 (CX231XX_VIN_1_2 << 8) |
505 CX25840_SVIDEO_ON,
506 .amux = CX231XX_AMUX_LINE_IN,
507 .gpio = NULL,
508 }
509 },
510 },
Igor Novgorodov2a7b6a42011-05-17 13:46:36 -0300511
512 [CX231XX_BOARD_ICONBIT_U100] = {
513 .name = "Iconbit Analog Stick U100 FM",
514 .tuner_type = TUNER_ABSENT,
515 .decoder = CX231XX_AVDECODER,
516 .output_mode = OUT_MODE_VIP11,
517 .demod_xfer_mode = 0,
518 .ctl_pin_status_mask = 0xFFFFFFC4,
519 .agc_analog_digital_select_gpio = 0x1C,
520 .gpio_pin_status_mask = 0x4001000,
521
522 .input = {{
523 .type = CX231XX_VMUX_COMPOSITE1,
524 .vmux = CX231XX_VIN_2_1,
525 .amux = CX231XX_AMUX_LINE_IN,
526 .gpio = NULL,
527 }, {
528 .type = CX231XX_VMUX_SVIDEO,
529 .vmux = CX231XX_VIN_1_1 |
530 (CX231XX_VIN_1_2 << 8) |
531 CX25840_SVIDEO_ON,
532 .amux = CX231XX_AMUX_LINE_IN,
533 .gpio = NULL,
534 } },
535 },
Peter Moonde8ae0d2011-06-08 15:54:19 -0300536 [CX231XX_BOARD_HAUPPAUGE_USB2_FM_PAL] = {
537 .name = "Hauppauge WinTV USB2 FM (PAL)",
538 .tuner_type = TUNER_NXP_TDA18271,
539 .tuner_addr = 0x60,
540 .tuner_gpio = RDE250_XCV_TUNER,
541 .tuner_sif_gpio = 0x05,
542 .tuner_scl_gpio = 0x1a,
543 .tuner_sda_gpio = 0x1b,
544 .decoder = CX231XX_AVDECODER,
545 .output_mode = OUT_MODE_VIP11,
546 .ctl_pin_status_mask = 0xFFFFFFC4,
547 .agc_analog_digital_select_gpio = 0x0c,
548 .gpio_pin_status_mask = 0x4001000,
549 .tuner_i2c_master = 1,
550 .norm = V4L2_STD_PAL,
551
552 .input = {{
553 .type = CX231XX_VMUX_TELEVISION,
554 .vmux = CX231XX_VIN_3_1,
555 .amux = CX231XX_AMUX_VIDEO,
556 .gpio = NULL,
557 }, {
558 .type = CX231XX_VMUX_COMPOSITE1,
559 .vmux = CX231XX_VIN_2_1,
560 .amux = CX231XX_AMUX_LINE_IN,
561 .gpio = NULL,
562 }, {
563 .type = CX231XX_VMUX_SVIDEO,
564 .vmux = CX231XX_VIN_1_1 |
565 (CX231XX_VIN_1_2 << 8) |
566 CX25840_SVIDEO_ON,
567 .amux = CX231XX_AMUX_LINE_IN,
568 .gpio = NULL,
569 } },
570 },
571 [CX231XX_BOARD_HAUPPAUGE_USB2_FM_NTSC] = {
572 .name = "Hauppauge WinTV USB2 FM (NTSC)",
573 .tuner_type = TUNER_NXP_TDA18271,
574 .tuner_addr = 0x60,
575 .tuner_gpio = RDE250_XCV_TUNER,
576 .tuner_sif_gpio = 0x05,
577 .tuner_scl_gpio = 0x1a,
578 .tuner_sda_gpio = 0x1b,
579 .decoder = CX231XX_AVDECODER,
580 .output_mode = OUT_MODE_VIP11,
581 .ctl_pin_status_mask = 0xFFFFFFC4,
582 .agc_analog_digital_select_gpio = 0x0c,
583 .gpio_pin_status_mask = 0x4001000,
584 .tuner_i2c_master = 1,
585 .norm = V4L2_STD_NTSC,
586
587 .input = {{
588 .type = CX231XX_VMUX_TELEVISION,
589 .vmux = CX231XX_VIN_3_1,
590 .amux = CX231XX_AMUX_VIDEO,
591 .gpio = NULL,
592 }, {
593 .type = CX231XX_VMUX_COMPOSITE1,
594 .vmux = CX231XX_VIN_2_1,
595 .amux = CX231XX_AMUX_LINE_IN,
596 .gpio = NULL,
597 }, {
598 .type = CX231XX_VMUX_SVIDEO,
599 .vmux = CX231XX_VIN_1_1 |
600 (CX231XX_VIN_1_2 << 8) |
601 CX25840_SVIDEO_ON,
602 .amux = CX231XX_AMUX_LINE_IN,
603 .gpio = NULL,
604 } },
605 },
Sri Deevie0d3baf2009-03-03 14:37:50 -0300606};
607const unsigned int cx231xx_bcount = ARRAY_SIZE(cx231xx_boards);
608
609/* table of devices that work with this driver */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300610struct usb_device_id cx231xx_id_table[] = {
Sri Deevied559ed2009-03-13 18:35:14 -0300611 {USB_DEVICE(0x0572, 0x5A3C),
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300612 .driver_info = CX231XX_BOARD_UNKNOWN},
613 {USB_DEVICE(0x0572, 0x58A2),
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300614 .driver_info = CX231XX_BOARD_CNXT_CARRAERA},
Sri Deevied559ed2009-03-13 18:35:14 -0300615 {USB_DEVICE(0x0572, 0x58A1),
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300616 .driver_info = CX231XX_BOARD_CNXT_SHELBY},
617 {USB_DEVICE(0x0572, 0x58A4),
618 .driver_info = CX231XX_BOARD_CNXT_RDE_253S},
619 {USB_DEVICE(0x0572, 0x58A5),
620 .driver_info = CX231XX_BOARD_CNXT_RDU_253S},
621 {USB_DEVICE(0x0572, 0x58A6),
622 .driver_info = CX231XX_BOARD_CNXT_VIDEO_GRABBER},
623 {USB_DEVICE(0x0572, 0x589E),
624 .driver_info = CX231XX_BOARD_CNXT_RDE_250},
625 {USB_DEVICE(0x0572, 0x58A0),
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300626 .driver_info = CX231XX_BOARD_CNXT_RDU_250},
Peter Moonde8ae0d2011-06-08 15:54:19 -0300627 {USB_DEVICE(0x2040, 0xb110),
628 .driver_info = CX231XX_BOARD_HAUPPAUGE_USB2_FM_PAL},
629 {USB_DEVICE(0x2040, 0xb111),
630 .driver_info = CX231XX_BOARD_HAUPPAUGE_USB2_FM_NTSC},
Michael Krufky1a50fdd2010-07-06 18:23:53 -0300631 {USB_DEVICE(0x2040, 0xb120),
632 .driver_info = CX231XX_BOARD_HAUPPAUGE_EXETER},
Devin Heitmuellerd78148f2010-07-06 18:25:19 -0300633 {USB_DEVICE(0x2040, 0xb140),
634 .driver_info = CX231XX_BOARD_HAUPPAUGE_EXETER},
Devin Heitmueller4270c3c2010-07-31 00:49:01 -0300635 {USB_DEVICE(0x2040, 0xc200),
636 .driver_info = CX231XX_BOARD_HAUPPAUGE_USBLIVE2},
Mauro Carvalho Chehab9417bc62010-09-26 20:44:31 -0300637 {USB_DEVICE_VER(USB_VID_PIXELVIEW, USB_PID_PIXELVIEW_SBTVD, 0x4000, 0x4001),
638 .driver_info = CX231XX_BOARD_PV_PLAYTV_USB_HYBRID},
Mauro Carvalho Chehab4e105032011-01-31 22:18:21 -0300639 {USB_DEVICE(USB_VID_PIXELVIEW, 0x5014),
640 .driver_info = CX231XX_BOARD_PV_XCAPTURE_USB},
Márcio Alveseeaaf812011-04-11 19:57:15 -0300641 {USB_DEVICE(0x1b80, 0xe424),
642 .driver_info = CX231XX_BOARD_KWORLD_UB430_USB_HYBRID},
Igor Novgorodov2a7b6a42011-05-17 13:46:36 -0300643 {USB_DEVICE(0x1f4d, 0x0237),
644 .driver_info = CX231XX_BOARD_ICONBIT_U100},
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300645 {},
Sri Deevie0d3baf2009-03-03 14:37:50 -0300646};
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300647
Sri Deevie0d3baf2009-03-03 14:37:50 -0300648MODULE_DEVICE_TABLE(usb, cx231xx_id_table);
649
650/* cx231xx_tuner_callback
651 * will be used to reset XC5000 tuner using GPIO pin
652 */
653
654int cx231xx_tuner_callback(void *ptr, int component, int command, int arg)
655{
656 int rc = 0;
657 struct cx231xx *dev = ptr;
658
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300659 if (dev->tuner_type == TUNER_XC5000) {
660 if (command == XC5000_TUNER_RESET) {
661 cx231xx_info
Sri Deevib9255172009-03-04 17:49:01 -0300662 ("Tuner CB: RESET: cmd %d : tuner type %d \n",
663 command, dev->tuner_type);
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300664 cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit,
665 1);
666 msleep(10);
667 cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit,
668 0);
669 msleep(330);
670 cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit,
671 1);
672 msleep(10);
673 }
Mauro Carvalho Chehab55fa2882010-09-29 11:07:08 -0300674 } else if (dev->tuner_type == TUNER_NXP_TDA18271) {
675 switch (command) {
676 case TDA18271_CALLBACK_CMD_AGC_ENABLE:
677 if (dev->model == CX231XX_BOARD_PV_PLAYTV_USB_HYBRID)
678 rc = cx231xx_set_agc_analog_digital_mux_select(dev, arg);
679 break;
680 default:
681 rc = -EINVAL;
682 break;
683 }
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300684 }
Sri Deevie0d3baf2009-03-03 14:37:50 -0300685 return rc;
686}
687EXPORT_SYMBOL_GPL(cx231xx_tuner_callback);
688
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300689void cx231xx_reset_out(struct cx231xx *dev)
690{
691 cx231xx_set_gpio_value(dev, CX23417_RESET, 1);
692 msleep(200);
693 cx231xx_set_gpio_value(dev, CX23417_RESET, 0);
694 msleep(200);
695 cx231xx_set_gpio_value(dev, CX23417_RESET, 1);
696}
697void cx231xx_enable_OSC(struct cx231xx *dev)
698{
699 cx231xx_set_gpio_value(dev, CX23417_OSC_EN, 1);
700}
701void cx231xx_sleep_s5h1432(struct cx231xx *dev)
702{
703 cx231xx_set_gpio_value(dev, SLEEP_S5H1432, 0);
704}
705
Sri Deevib9255172009-03-04 17:49:01 -0300706static inline void cx231xx_set_model(struct cx231xx *dev)
Sri Deevie0d3baf2009-03-03 14:37:50 -0300707{
708 memcpy(&dev->board, &cx231xx_boards[dev->model], sizeof(dev->board));
709}
710
711/* Since cx231xx_pre_card_setup() requires a proper dev->model,
712 * this won't work for boards with generic PCI IDs
713 */
714void cx231xx_pre_card_setup(struct cx231xx *dev)
715{
716
717 cx231xx_set_model(dev);
718
719 cx231xx_info("Identified as %s (card=%d)\n",
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300720 dev->board.name, dev->model);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300721
Sri Deevi6e4f5742009-03-10 21:16:26 -0300722 /* set the direction for GPIO pins */
Mauro Carvalho Chehabc10469c2010-09-11 11:37:51 -0300723 if (dev->board.tuner_gpio) {
724 cx231xx_set_gpio_direction(dev, dev->board.tuner_gpio->bit, 1);
725 cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit, 1);
Mauro Carvalho Chehab78bb6df2010-09-26 20:48:38 -0300726 }
727 if (dev->board.tuner_sif_gpio >= 0)
Mauro Carvalho Chehabc10469c2010-09-11 11:37:51 -0300728 cx231xx_set_gpio_direction(dev, dev->board.tuner_sif_gpio, 1);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300729
Mauro Carvalho Chehab78bb6df2010-09-26 20:48:38 -0300730 /* request some modules if any required */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300731
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300732 /* set the mode to Analog mode initially */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300733 cx231xx_set_mode(dev, CX231XX_ANALOG_MODE);
734
735 /* Unlock device */
736 /* cx231xx_set_mode(dev, CX231XX_SUSPEND); */
737
738}
739
Sri Deevie0d3baf2009-03-03 14:37:50 -0300740static void cx231xx_config_tuner(struct cx231xx *dev)
741{
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300742 struct tuner_setup tun_setup;
743 struct v4l2_frequency f;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300744
745 if (dev->tuner_type == TUNER_ABSENT)
746 return;
747
748 tun_setup.mode_mask = T_ANALOG_TV | T_RADIO;
749 tun_setup.type = dev->tuner_type;
750 tun_setup.addr = dev->tuner_addr;
751 tun_setup.tuner_callback = cx231xx_tuner_callback;
752
Sri Deevib1196122009-03-20 23:33:48 -0300753 tuner_call(dev, tuner, s_type_addr, &tun_setup);
754
Sri Deevie0d3baf2009-03-03 14:37:50 -0300755#if 0
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300756 if (tun_setup.type == TUNER_XC5000) {
Sri Deevie0d3baf2009-03-03 14:37:50 -0300757 static struct xc2028_ctrl ctrl = {
758 .fname = XC5000_DEFAULT_FIRMWARE,
759 .max_len = 64,
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300760 .demod = 0;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300761 };
762 struct v4l2_priv_tun_config cfg = {
763 .tuner = dev->tuner_type,
764 .priv = &ctrl,
765 };
Sri Deevib1196122009-03-20 23:33:48 -0300766 tuner_call(dev, tuner, s_config, &cfg);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300767 }
768#endif
Sri Deevie0d3baf2009-03-03 14:37:50 -0300769 /* configure tuner */
770 f.tuner = 0;
771 f.type = V4L2_TUNER_ANALOG_TV;
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300772 f.frequency = 9076; /* just a magic number */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300773 dev->ctl_freq = f.frequency;
Sri Deevib1196122009-03-20 23:33:48 -0300774 call_all(dev, tuner, s_frequency, &f);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300775
Sri Deevib1196122009-03-20 23:33:48 -0300776}
Sri Deevie0d3baf2009-03-03 14:37:50 -0300777
Sri Deevie0d3baf2009-03-03 14:37:50 -0300778void cx231xx_card_setup(struct cx231xx *dev)
779{
Sri Deevib1196122009-03-20 23:33:48 -0300780
Sri Deevie0d3baf2009-03-03 14:37:50 -0300781 cx231xx_set_model(dev);
782
783 dev->tuner_type = cx231xx_boards[dev->model].tuner_type;
784 if (cx231xx_boards[dev->model].tuner_addr)
785 dev->tuner_addr = cx231xx_boards[dev->model].tuner_addr;
786
Sri Deevie0d3baf2009-03-03 14:37:50 -0300787 /* request some modules */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300788 if (dev->board.decoder == CX231XX_AVDECODER) {
Hans Verkuile6574f22009-04-01 03:57:53 -0300789 dev->sd_cx25840 = v4l2_i2c_new_subdev(&dev->v4l2_dev,
790 &dev->i2c_bus[0].i2c_adap,
Laurent Pinchart9a1f8b32010-09-24 10:16:44 -0300791 "cx25840", 0x88 >> 1, NULL);
Sri Deevib1196122009-03-20 23:33:48 -0300792 if (dev->sd_cx25840 == NULL)
793 cx231xx_info("cx25840 subdev registration failure\n");
Hans Verkuilcc26b072009-03-29 19:20:26 -0300794 cx25840_call(dev, core, load_fw);
Sri Deevib1196122009-03-20 23:33:48 -0300795
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300796 }
Sri Deevib1196122009-03-20 23:33:48 -0300797
Devin Heitmuellere3e0aaa2010-07-08 17:05:30 -0300798 /* Initialize the tuner */
799 if (dev->board.tuner_type != TUNER_ABSENT) {
800 dev->sd_tuner = v4l2_i2c_new_subdev(&dev->v4l2_dev,
Mauro Carvalho Chehab1a4aa922010-09-26 20:01:51 -0300801 &dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap,
Laurent Pinchart9a1f8b32010-09-24 10:16:44 -0300802 "tuner",
Devin Heitmuellere3e0aaa2010-07-08 17:05:30 -0300803 dev->tuner_addr, NULL);
804 if (dev->sd_tuner == NULL)
805 cx231xx_info("tuner subdev registration failure\n");
806 else
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300807 cx231xx_config_tuner(dev);
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300808 }
Sri Deevie0d3baf2009-03-03 14:37:50 -0300809}
810
Sri Deevie0d3baf2009-03-03 14:37:50 -0300811/*
812 * cx231xx_config()
813 * inits registers with sane defaults
814 */
815int cx231xx_config(struct cx231xx *dev)
816{
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300817 /* TBD need to add cx231xx specific code */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300818 dev->mute = 1; /* maybe not the right place... */
819 dev->volume = 0x1f;
820
821 return 0;
822}
823
824/*
825 * cx231xx_config_i2c()
826 * configure i2c attached devices
827 */
828void cx231xx_config_i2c(struct cx231xx *dev)
829{
Hans Verkuil5325b422009-04-02 11:26:22 -0300830 /* u32 input = INPUT(dev->video_input)->vmux; */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300831
Sri Deevib1196122009-03-20 23:33:48 -0300832 call_all(dev, video, s_stream, 1);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300833}
834
835/*
836 * cx231xx_realease_resources()
837 * unregisters the v4l2,i2c and usb devices
838 * called when the device gets disconected or at module unload
839*/
840void cx231xx_release_resources(struct cx231xx *dev)
841{
Sri Deevie0d3baf2009-03-03 14:37:50 -0300842 cx231xx_release_analog_resources(dev);
843
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300844 cx231xx_remove_from_devlist(dev);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300845
Mauro Carvalho Chehab7528cd22012-01-10 09:20:01 -0200846 cx231xx_ir_exit(dev);
847
Mauro Carvalho Chehab9ab66912010-10-23 13:28:33 -0300848 /* Release I2C buses */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300849 cx231xx_dev_uninit(dev);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300850
Mauro Carvalho Chehab7528cd22012-01-10 09:20:01 -0200851 /* delete v4l2 device */
852 v4l2_device_unregister(&dev->v4l2_dev);
Mauro Carvalho Chehab9ab66912010-10-23 13:28:33 -0300853
Sri Deevie0d3baf2009-03-03 14:37:50 -0300854 usb_put_dev(dev->udev);
855
856 /* Mark device as unused */
Mauro Carvalho Chehabdb702a72012-01-10 09:33:47 -0200857 clear_bit(dev->devno, &cx231xx_devused);
Mauro Carvalho Chehab7528cd22012-01-10 09:20:01 -0200858
859 kfree(dev->video_mode.alt_max_pkt_size);
860 kfree(dev->vbi_mode.alt_max_pkt_size);
861 kfree(dev->sliced_cc_mode.alt_max_pkt_size);
862 kfree(dev->ts1_mode.alt_max_pkt_size);
863 kfree(dev);
864 dev = NULL;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300865}
866
Sri Deevie0d3baf2009-03-03 14:37:50 -0300867/*
868 * cx231xx_init_dev()
869 * allocates and inits the device structs, registers i2c bus and v4l device
870 */
Thomas Petazzoni15cb6af2012-01-07 09:52:40 -0300871static int cx231xx_init_dev(struct cx231xx *dev, struct usb_device *udev,
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300872 int minor)
Sri Deevie0d3baf2009-03-03 14:37:50 -0300873{
Sri Deevie0d3baf2009-03-03 14:37:50 -0300874 int retval = -ENOMEM;
875 int errCode;
876 unsigned int maxh, maxw;
877
878 dev->udev = udev;
879 mutex_init(&dev->lock);
880 mutex_init(&dev->ctrl_urb_lock);
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300881 mutex_init(&dev->gpio_i2c_lock);
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300882 mutex_init(&dev->i2c_lock);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300883
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300884 spin_lock_init(&dev->video_mode.slock);
885 spin_lock_init(&dev->vbi_mode.slock);
886 spin_lock_init(&dev->sliced_cc_mode.slock);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300887
888 init_waitqueue_head(&dev->open);
889 init_waitqueue_head(&dev->wait_frame);
890 init_waitqueue_head(&dev->wait_stream);
891
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300892 dev->cx231xx_read_ctrl_reg = cx231xx_read_ctrl_reg;
893 dev->cx231xx_write_ctrl_reg = cx231xx_write_ctrl_reg;
894 dev->cx231xx_send_usb_command = cx231xx_send_usb_command;
895 dev->cx231xx_gpio_i2c_read = cx231xx_gpio_i2c_read;
896 dev->cx231xx_gpio_i2c_write = cx231xx_gpio_i2c_write;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300897
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300898 /* Query cx231xx to find what pcb config it is related to */
899 initialize_cx231xx(dev);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300900
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300901 /*To workaround error number=-71 on EP0 for VideoGrabber,
902 need set alt here.*/
Devin Heitmueller4270c3c2010-07-31 00:49:01 -0300903 if (dev->model == CX231XX_BOARD_CNXT_VIDEO_GRABBER ||
904 dev->model == CX231XX_BOARD_HAUPPAUGE_USBLIVE2) {
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300905 cx231xx_set_alt_setting(dev, INDEX_VIDEO, 3);
906 cx231xx_set_alt_setting(dev, INDEX_VANC, 1);
907 }
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300908 /* Cx231xx pre card setup */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300909 cx231xx_pre_card_setup(dev);
910
911 errCode = cx231xx_config(dev);
912 if (errCode) {
913 cx231xx_errdev("error configuring device\n");
914 return -ENOMEM;
915 }
916
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300917 /* set default norm */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300918 dev->norm = dev->board.norm;
919
920 /* register i2c bus */
921 errCode = cx231xx_dev_init(dev);
922 if (errCode < 0) {
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300923 cx231xx_dev_uninit(dev);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300924 cx231xx_errdev("%s: cx231xx_i2c_register - errCode [%d]!\n",
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300925 __func__, errCode);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300926 return errCode;
927 }
928
929 /* Do board specific init */
930 cx231xx_card_setup(dev);
931
932 /* configure the device */
933 cx231xx_config_i2c(dev);
934
935 maxw = norm_maxw(dev);
936 maxh = norm_maxh(dev);
937
938 /* set default image size */
939 dev->width = maxw;
940 dev->height = maxh;
941 dev->interlaced = 0;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300942 dev->video_input = 0;
943
944 errCode = cx231xx_config(dev);
945 if (errCode < 0) {
946 cx231xx_errdev("%s: cx231xx_config - errCode [%d]!\n",
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300947 __func__, errCode);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300948 return errCode;
949 }
950
951 /* init video dma queues */
952 INIT_LIST_HEAD(&dev->video_mode.vidq.active);
953 INIT_LIST_HEAD(&dev->video_mode.vidq.queued);
954
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300955 /* init vbi dma queues */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300956 INIT_LIST_HEAD(&dev->vbi_mode.vidq.active);
957 INIT_LIST_HEAD(&dev->vbi_mode.vidq.queued);
958
959 /* Reset other chips required if they are tied up with GPIO pins */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300960 cx231xx_add_into_devlist(dev);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300961
Mauro Carvalho Chehab2f861382011-01-31 22:12:15 -0300962 if (dev->board.has_417) {
Devin Heitmueller2b43db32010-08-18 18:09:28 -0300963 printk(KERN_INFO "attach 417 %d\n", dev->model);
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300964 if (cx231xx_417_register(dev) < 0) {
965 printk(KERN_ERR
966 "%s() Failed to register 417 on VID_B\n",
967 __func__);
968 }
969 }
970
Sri Deevie0d3baf2009-03-03 14:37:50 -0300971 retval = cx231xx_register_analog_devices(dev);
972 if (retval < 0) {
973 cx231xx_release_resources(dev);
Dan Carpenter5ae094c2010-11-18 00:56:37 -0300974 return retval;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300975 }
976
Mauro Carvalho Chehab9ab66912010-10-23 13:28:33 -0300977 cx231xx_ir_init(dev);
978
Sri Deevie0d3baf2009-03-03 14:37:50 -0300979 cx231xx_init_extension(dev);
980
981 return 0;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300982}
983
984#if defined(CONFIG_MODULES) && defined(MODULE)
985static void request_module_async(struct work_struct *work)
986{
987 struct cx231xx *dev = container_of(work,
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300988 struct cx231xx, request_module_wk);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300989
990 if (dev->has_alsa_audio)
991 request_module("cx231xx-alsa");
992
993 if (dev->board.has_dvb)
994 request_module("cx231xx-dvb");
995
996}
997
998static void request_modules(struct cx231xx *dev)
999{
1000 INIT_WORK(&dev->request_module_wk, request_module_async);
1001 schedule_work(&dev->request_module_wk);
1002}
Tejun Heo707bcf32010-12-24 16:14:20 +01001003
1004static void flush_request_modules(struct cx231xx *dev)
1005{
1006 flush_work_sync(&dev->request_module_wk);
1007}
Sri Deevie0d3baf2009-03-03 14:37:50 -03001008#else
1009#define request_modules(dev)
Tejun Heo707bcf32010-12-24 16:14:20 +01001010#define flush_request_modules(dev)
Sri Deevie0d3baf2009-03-03 14:37:50 -03001011#endif /* CONFIG_MODULES */
1012
Sri Deevie0d3baf2009-03-03 14:37:50 -03001013/*
1014 * cx231xx_usb_probe()
1015 * checks for supported devices
1016 */
1017static int cx231xx_usb_probe(struct usb_interface *interface,
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -03001018 const struct usb_device_id *id)
Sri Deevie0d3baf2009-03-03 14:37:50 -03001019{
1020 struct usb_device *udev;
1021 struct usb_interface *uif;
1022 struct cx231xx *dev = NULL;
1023 int retval = -ENODEV;
Hans Verkuild73abcf2009-03-12 18:38:40 -03001024 int nr = 0, ifnum;
Sri Deevie0d3baf2009-03-03 14:37:50 -03001025 int i, isoc_pipe = 0;
1026 char *speed;
1027 char descr[255] = "";
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -03001028 struct usb_interface_assoc_descriptor *assoc_desc;
Sri Deevie0d3baf2009-03-03 14:37:50 -03001029
1030 udev = usb_get_dev(interface_to_usbdev(interface));
1031 ifnum = interface->altsetting[0].desc.bInterfaceNumber;
1032
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -03001033 /*
1034 * Interface number 0 - IR interface (handled by mceusb driver)
1035 * Interface number 1 - AV interface (handled by this driver)
1036 */
1037 if (ifnum != 1)
1038 return -ENODEV;
Sri Deevie0d3baf2009-03-03 14:37:50 -03001039
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -03001040 /* Check to see next free device and mark as used */
Mauro Carvalho Chehabdb702a72012-01-10 09:33:47 -02001041 do {
1042 nr = find_first_zero_bit(&cx231xx_devused, CX231XX_MAXBOARDS);
1043 if (nr >= CX231XX_MAXBOARDS) {
1044 /* No free device slots */
1045 cx231xx_err(DRIVER_NAME ": Supports only %i devices.\n",
1046 CX231XX_MAXBOARDS);
1047 return -ENOMEM;
1048 }
1049 } while (test_and_set_bit(nr, &cx231xx_devused));
Sri Deevie0d3baf2009-03-03 14:37:50 -03001050
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -03001051 /* allocate memory for our device state and initialize it */
1052 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
1053 if (dev == NULL) {
1054 cx231xx_err(DRIVER_NAME ": out of memory!\n");
Mauro Carvalho Chehabdb702a72012-01-10 09:33:47 -02001055 clear_bit(dev->devno, &cx231xx_devused);
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -03001056 return -ENOMEM;
1057 }
Sri Deevie0d3baf2009-03-03 14:37:50 -03001058
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -03001059 snprintf(dev->name, 29, "cx231xx #%d", nr);
1060 dev->devno = nr;
1061 dev->model = id->driver_info;
1062 dev->video_mode.alt = -1;
Sri Deevie0d3baf2009-03-03 14:37:50 -03001063
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -03001064 dev->interface_count++;
1065 /* reset gpio dir and value */
1066 dev->gpio_dir = 0;
1067 dev->gpio_val = 0;
1068 dev->xc_fw_load_done = 0;
1069 dev->has_alsa_audio = 1;
1070 dev->power_mode = -1;
1071 atomic_set(&dev->devlist_count, 0);
Sri Deevie0d3baf2009-03-03 14:37:50 -03001072
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -03001073 /* 0 - vbi ; 1 -sliced cc mode */
1074 dev->vbi_or_sliced_cc_mode = 0;
Sri Deevie0d3baf2009-03-03 14:37:50 -03001075
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -03001076 /* get maximum no.of IAD interfaces */
1077 assoc_desc = udev->actconfig->intf_assoc[0];
1078 dev->max_iad_interface_count = assoc_desc->bInterfaceCount;
Sri Deevie0d3baf2009-03-03 14:37:50 -03001079
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -03001080 /* init CIR module TBD */
Sri Deevie0d3baf2009-03-03 14:37:50 -03001081
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -03001082 /*mode_tv: digital=1 or analog=0*/
1083 dev->mode_tv = 0;
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -03001084
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -03001085 dev->USE_ISO = transfer_mode;
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -03001086
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -03001087 switch (udev->speed) {
1088 case USB_SPEED_LOW:
1089 speed = "1.5";
1090 break;
1091 case USB_SPEED_UNKNOWN:
1092 case USB_SPEED_FULL:
1093 speed = "12";
1094 break;
1095 case USB_SPEED_HIGH:
1096 speed = "480";
1097 break;
1098 default:
1099 speed = "unknown";
1100 }
Sri Deevie0d3baf2009-03-03 14:37:50 -03001101
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -03001102 if (udev->manufacturer)
1103 strlcpy(descr, udev->manufacturer, sizeof(descr));
Sri Deevie0d3baf2009-03-03 14:37:50 -03001104
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -03001105 if (udev->product) {
Sri Deevie0d3baf2009-03-03 14:37:50 -03001106 if (*descr)
1107 strlcat(descr, " ", sizeof(descr));
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -03001108 strlcat(descr, udev->product, sizeof(descr));
1109 }
1110 if (*descr)
1111 strlcat(descr, " ", sizeof(descr));
Sri Deevie0d3baf2009-03-03 14:37:50 -03001112
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -03001113 cx231xx_info("New device %s@ %s Mbps "
1114 "(%04x:%04x) with %d interfaces\n",
1115 descr,
1116 speed,
1117 le16_to_cpu(udev->descriptor.idVendor),
1118 le16_to_cpu(udev->descriptor.idProduct),
1119 dev->max_iad_interface_count);
Sri Deevib1196122009-03-20 23:33:48 -03001120
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -03001121 /* increment interface count */
1122 dev->interface_count++;
Sri Deevie0d3baf2009-03-03 14:37:50 -03001123
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -03001124 /* get device number */
1125 nr = dev->devno;
Sri Deevie0d3baf2009-03-03 14:37:50 -03001126
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -03001127 assoc_desc = udev->actconfig->intf_assoc[0];
1128 if (assoc_desc->bFirstInterface != ifnum) {
1129 cx231xx_err(DRIVER_NAME ": Not found "
1130 "matching IAD interface\n");
Mauro Carvalho Chehabdb702a72012-01-10 09:33:47 -02001131 clear_bit(dev->devno, &cx231xx_devused);
Julia Lawallef60e8f2011-07-04 11:11:41 -03001132 kfree(dev);
1133 dev = NULL;
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001134 return -ENODEV;
Mauro Carvalho Chehab10e4ebb2010-10-18 21:10:46 -03001135 }
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001136
1137 cx231xx_info("registering interface %d\n", ifnum);
1138
Sri Deevie0d3baf2009-03-03 14:37:50 -03001139 /* save our data pointer in this interface device */
Thomas Petazzonia116a052012-01-07 09:52:38 -03001140 usb_set_intfdata(interface, dev);
Sri Deevie0d3baf2009-03-03 14:37:50 -03001141
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001142 /*
1143 * AV device initialization - only done at the last interface
1144 */
1145
1146 /* Create v4l2 device */
Janne Grunau72317482009-04-01 08:39:29 -03001147 retval = v4l2_device_register(&interface->dev, &dev->v4l2_dev);
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001148 if (retval) {
1149 cx231xx_errdev("v4l2_device_register failed\n");
Mauro Carvalho Chehabdb702a72012-01-10 09:33:47 -02001150 clear_bit(dev->devno, &cx231xx_devused);
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001151 kfree(dev);
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -03001152 dev = NULL;
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001153 return -EIO;
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -03001154 }
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001155 /* allocate device struct */
Thomas Petazzoni15cb6af2012-01-07 09:52:40 -03001156 retval = cx231xx_init_dev(dev, udev, nr);
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001157 if (retval) {
Mauro Carvalho Chehabdb702a72012-01-10 09:33:47 -02001158 clear_bit(dev->devno, &cx231xx_devused);
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001159 v4l2_device_unregister(&dev->v4l2_dev);
1160 kfree(dev);
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -03001161 dev = NULL;
Thomas Petazzonia116a052012-01-07 09:52:38 -03001162 usb_set_intfdata(interface, NULL);
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -03001163
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001164 return retval;
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -03001165 }
Sri Deevie0d3baf2009-03-03 14:37:50 -03001166
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001167 /* compute alternate max packet sizes for video */
1168 uif = udev->actconfig->interface[dev->current_pcb_config.
1169 hs_config_info[0].interface_info.video_index + 1];
1170
1171 dev->video_mode.end_point_addr = le16_to_cpu(uif->altsetting[0].
1172 endpoint[isoc_pipe].desc.bEndpointAddress);
1173
1174 dev->video_mode.num_alt = uif->num_altsetting;
1175 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
1176 dev->video_mode.end_point_addr,
1177 dev->video_mode.num_alt);
1178 dev->video_mode.alt_max_pkt_size =
1179 kmalloc(32 * dev->video_mode.num_alt, GFP_KERNEL);
1180
1181 if (dev->video_mode.alt_max_pkt_size == NULL) {
1182 cx231xx_errdev("out of memory!\n");
Mauro Carvalho Chehabdb702a72012-01-10 09:33:47 -02001183 clear_bit(dev->devno, &cx231xx_devused);
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001184 v4l2_device_unregister(&dev->v4l2_dev);
1185 kfree(dev);
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -03001186 dev = NULL;
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001187 return -ENOMEM;
1188 }
1189
1190 for (i = 0; i < dev->video_mode.num_alt; i++) {
1191 u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
1192 desc.wMaxPacketSize);
1193 dev->video_mode.alt_max_pkt_size[i] =
1194 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
1195 cx231xx_info("Alternate setting %i, max size= %i\n", i,
1196 dev->video_mode.alt_max_pkt_size[i]);
1197 }
1198
1199 /* compute alternate max packet sizes for vbi */
1200 uif = udev->actconfig->interface[dev->current_pcb_config.
1201 hs_config_info[0].interface_info.
1202 vanc_index + 1];
1203
1204 dev->vbi_mode.end_point_addr =
1205 le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc.
1206 bEndpointAddress);
1207
1208 dev->vbi_mode.num_alt = uif->num_altsetting;
1209 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
1210 dev->vbi_mode.end_point_addr,
1211 dev->vbi_mode.num_alt);
1212 dev->vbi_mode.alt_max_pkt_size =
1213 kmalloc(32 * dev->vbi_mode.num_alt, GFP_KERNEL);
1214
1215 if (dev->vbi_mode.alt_max_pkt_size == NULL) {
1216 cx231xx_errdev("out of memory!\n");
Mauro Carvalho Chehabdb702a72012-01-10 09:33:47 -02001217 clear_bit(dev->devno, &cx231xx_devused);
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001218 v4l2_device_unregister(&dev->v4l2_dev);
1219 kfree(dev);
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -03001220 dev = NULL;
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001221 return -ENOMEM;
1222 }
1223
1224 for (i = 0; i < dev->vbi_mode.num_alt; i++) {
1225 u16 tmp =
1226 le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
1227 desc.wMaxPacketSize);
1228 dev->vbi_mode.alt_max_pkt_size[i] =
1229 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
1230 cx231xx_info("Alternate setting %i, max size= %i\n", i,
1231 dev->vbi_mode.alt_max_pkt_size[i]);
1232 }
1233
1234 /* compute alternate max packet sizes for sliced CC */
1235 uif = udev->actconfig->interface[dev->current_pcb_config.
1236 hs_config_info[0].interface_info.
1237 hanc_index + 1];
1238
1239 dev->sliced_cc_mode.end_point_addr =
1240 le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc.
1241 bEndpointAddress);
1242
1243 dev->sliced_cc_mode.num_alt = uif->num_altsetting;
1244 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
1245 dev->sliced_cc_mode.end_point_addr,
1246 dev->sliced_cc_mode.num_alt);
1247 dev->sliced_cc_mode.alt_max_pkt_size =
1248 kmalloc(32 * dev->sliced_cc_mode.num_alt, GFP_KERNEL);
1249
1250 if (dev->sliced_cc_mode.alt_max_pkt_size == NULL) {
1251 cx231xx_errdev("out of memory!\n");
Mauro Carvalho Chehabdb702a72012-01-10 09:33:47 -02001252 clear_bit(dev->devno, &cx231xx_devused);
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001253 v4l2_device_unregister(&dev->v4l2_dev);
1254 kfree(dev);
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -03001255 dev = NULL;
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001256 return -ENOMEM;
1257 }
1258
1259 for (i = 0; i < dev->sliced_cc_mode.num_alt; i++) {
1260 u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
1261 desc.wMaxPacketSize);
1262 dev->sliced_cc_mode.alt_max_pkt_size[i] =
1263 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
1264 cx231xx_info("Alternate setting %i, max size= %i\n", i,
1265 dev->sliced_cc_mode.alt_max_pkt_size[i]);
1266 }
1267
1268 if (dev->current_pcb_config.ts1_source != 0xff) {
1269 /* compute alternate max packet sizes for TS1 */
1270 uif = udev->actconfig->interface[dev->current_pcb_config.
1271 hs_config_info[0].
1272 interface_info.
1273 ts1_index + 1];
1274
1275 dev->ts1_mode.end_point_addr =
1276 le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].
1277 desc.bEndpointAddress);
1278
1279 dev->ts1_mode.num_alt = uif->num_altsetting;
1280 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
1281 dev->ts1_mode.end_point_addr,
1282 dev->ts1_mode.num_alt);
1283 dev->ts1_mode.alt_max_pkt_size =
1284 kmalloc(32 * dev->ts1_mode.num_alt, GFP_KERNEL);
1285
1286 if (dev->ts1_mode.alt_max_pkt_size == NULL) {
1287 cx231xx_errdev("out of memory!\n");
Mauro Carvalho Chehabdb702a72012-01-10 09:33:47 -02001288 clear_bit(dev->devno, &cx231xx_devused);
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001289 v4l2_device_unregister(&dev->v4l2_dev);
1290 kfree(dev);
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -03001291 dev = NULL;
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001292 return -ENOMEM;
1293 }
1294
1295 for (i = 0; i < dev->ts1_mode.num_alt; i++) {
1296 u16 tmp = le16_to_cpu(uif->altsetting[i].
1297 endpoint[isoc_pipe].desc.
1298 wMaxPacketSize);
1299 dev->ts1_mode.alt_max_pkt_size[i] =
1300 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
1301 cx231xx_info("Alternate setting %i, max size= %i\n", i,
1302 dev->ts1_mode.alt_max_pkt_size[i]);
1303 }
1304 }
1305
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -03001306 if (dev->model == CX231XX_BOARD_CNXT_VIDEO_GRABBER) {
1307 cx231xx_enable_OSC(dev);
1308 cx231xx_reset_out(dev);
1309 cx231xx_set_alt_setting(dev, INDEX_VIDEO, 3);
1310 }
1311
1312 if (dev->model == CX231XX_BOARD_CNXT_RDE_253S)
1313 cx231xx_sleep_s5h1432(dev);
1314
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001315 /* load other modules required */
1316 request_modules(dev);
1317
Sri Deevie0d3baf2009-03-03 14:37:50 -03001318 return 0;
1319}
1320
1321/*
1322 * cx231xx_usb_disconnect()
1323 * called when the device gets diconencted
1324 * video device will be unregistered on v4l2_close in case it is still open
1325 */
1326static void cx231xx_usb_disconnect(struct usb_interface *interface)
1327{
1328 struct cx231xx *dev;
1329
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -03001330 dev = usb_get_intfdata(interface);
Sri Deevie0d3baf2009-03-03 14:37:50 -03001331 usb_set_intfdata(interface, NULL);
1332
1333 if (!dev)
1334 return;
1335
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001336 if (!dev->udev)
1337 return;
1338
Mauro Carvalho Chehab990862a2012-01-10 09:48:50 -02001339 dev->state |= DEV_DISCONNECTED;
1340
Tejun Heo707bcf32010-12-24 16:14:20 +01001341 flush_request_modules(dev);
1342
Sri Deevie0d3baf2009-03-03 14:37:50 -03001343 /* wait until all current v4l2 io is finished then deallocate
1344 resources */
1345 mutex_lock(&dev->lock);
1346
1347 wake_up_interruptible_all(&dev->open);
1348
1349 if (dev->users) {
1350 cx231xx_warn
Laurent Pinchart38c7c032009-11-27 13:57:15 -03001351 ("device %s is open! Deregistration and memory "
1352 "deallocation are deferred on close.\n",
1353 video_device_node_name(dev->vdev));
Sri Deevie0d3baf2009-03-03 14:37:50 -03001354
Mauro Carvalho Chehab7528cd22012-01-10 09:20:01 -02001355 /* Even having users, it is safe to remove the RC i2c driver */
1356 cx231xx_ir_exit(dev);
1357
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -03001358 if (dev->USE_ISO)
1359 cx231xx_uninit_isoc(dev);
1360 else
1361 cx231xx_uninit_bulk(dev);
Sri Deevie0d3baf2009-03-03 14:37:50 -03001362 wake_up_interruptible(&dev->wait_frame);
1363 wake_up_interruptible(&dev->wait_stream);
1364 } else {
Sri Deevie0d3baf2009-03-03 14:37:50 -03001365 }
1366
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -03001367 cx231xx_close_extension(dev);
Sri Deevie0d3baf2009-03-03 14:37:50 -03001368
1369 mutex_unlock(&dev->lock);
1370
Mauro Carvalho Chehab7528cd22012-01-10 09:20:01 -02001371 if (!dev->users)
1372 cx231xx_release_resources(dev);
Sri Deevie0d3baf2009-03-03 14:37:50 -03001373}
1374
1375static struct usb_driver cx231xx_usb_driver = {
1376 .name = "cx231xx",
1377 .probe = cx231xx_usb_probe,
1378 .disconnect = cx231xx_usb_disconnect,
1379 .id_table = cx231xx_id_table,
1380};
1381
1382static int __init cx231xx_module_init(void)
1383{
1384 int result;
1385
Mauro Carvalho Chehab818fdf32009-03-13 07:41:58 -03001386 printk(KERN_INFO DRIVER_NAME " v4l2 driver loaded.\n");
Sri Deevie0d3baf2009-03-03 14:37:50 -03001387
1388 /* register this driver with the USB subsystem */
1389 result = usb_register(&cx231xx_usb_driver);
1390 if (result)
1391 cx231xx_err(DRIVER_NAME
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -03001392 " usb_register failed. Error number %d.\n", result);
Sri Deevie0d3baf2009-03-03 14:37:50 -03001393
1394 return result;
1395}
1396
1397static void __exit cx231xx_module_exit(void)
1398{
1399 /* deregister this driver with the USB subsystem */
1400 usb_deregister(&cx231xx_usb_driver);
1401}
1402
1403module_init(cx231xx_module_init);
1404module_exit(cx231xx_module_exit);