blob: 38d8510f93c2c0ad4d742405b23b41eb267d1bb4 [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>
Sri Deevie0d3baf2009-03-03 14:37:50 -030032
33#include <media/cx25840.h>
Mauro Carvalho Chehab3bfb3172010-09-03 10:50:24 -030034#include "dvb-usb-ids.h"
Sri Deevie0d3baf2009-03-03 14:37:50 -030035#include "xc5000.h"
Mauro Carvalho Chehab55fa2882010-09-29 11:07:08 -030036#include "tda18271.h"
Sri Deevie0d3baf2009-03-03 14:37:50 -030037
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,
Mauro Carvalho Chehab2f861382011-01-31 22:12:15 -0300263 .no_alt_vanc = 1,
264 .external_av = 1,
Hans Verkuilfff9e812013-02-08 12:43:25 -0300265 .dont_use_port_3 = 1,
Hans Verkuilb31077a2013-02-07 13:22:06 -0300266 /* Actually, it has a 417, but it isn't working correctly.
267 * So set to 0 for now until someone can manage to get this
268 * to work reliably. */
269 .has_417 = 0,
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300270
271 .input = {{
272 .type = CX231XX_VMUX_COMPOSITE1,
273 .vmux = CX231XX_VIN_2_1,
274 .amux = CX231XX_AMUX_LINE_IN,
275 .gpio = NULL,
276 }, {
277 .type = CX231XX_VMUX_SVIDEO,
278 .vmux = CX231XX_VIN_1_1 |
279 (CX231XX_VIN_1_2 << 8) |
280 CX25840_SVIDEO_ON,
281 .amux = CX231XX_AMUX_LINE_IN,
282 .gpio = NULL,
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300283 }
284 },
285 },
286 [CX231XX_BOARD_CNXT_RDE_250] = {
287 .name = "Conexant Hybrid TV - rde 250",
288 .tuner_type = TUNER_XC5000,
289 .tuner_addr = 0x61,
290 .tuner_gpio = RDE250_XCV_TUNER,
291 .tuner_sif_gpio = 0x05,
292 .tuner_scl_gpio = 0x1a,
293 .tuner_sda_gpio = 0x1b,
294 .decoder = CX231XX_AVDECODER,
Devin Heitmueller88806212010-08-18 17:50:07 -0300295 .output_mode = OUT_MODE_VIP11,
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300296 .demod_xfer_mode = 0,
297 .ctl_pin_status_mask = 0xFFFFFFC4,
298 .agc_analog_digital_select_gpio = 0x0c,
299 .gpio_pin_status_mask = 0x4001000,
300 .tuner_i2c_master = 1,
301 .demod_i2c_master = 2,
302 .has_dvb = 1,
303 .demod_addr = 0x02,
304 .norm = V4L2_STD_PAL,
305
306 .input = {{
307 .type = CX231XX_VMUX_TELEVISION,
308 .vmux = CX231XX_VIN_2_1,
309 .amux = CX231XX_AMUX_VIDEO,
310 .gpio = NULL,
311 }
312 },
313 },
314 [CX231XX_BOARD_CNXT_RDU_250] = {
315 .name = "Conexant Hybrid TV - RDU 250",
316 .tuner_type = TUNER_XC5000,
317 .tuner_addr = 0x61,
318 .tuner_gpio = RDE250_XCV_TUNER,
319 .tuner_sif_gpio = 0x05,
320 .tuner_scl_gpio = 0x1a,
321 .tuner_sda_gpio = 0x1b,
322 .decoder = CX231XX_AVDECODER,
Devin Heitmueller88806212010-08-18 17:50:07 -0300323 .output_mode = OUT_MODE_VIP11,
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300324 .demod_xfer_mode = 0,
325 .ctl_pin_status_mask = 0xFFFFFFC4,
326 .agc_analog_digital_select_gpio = 0x0c,
327 .gpio_pin_status_mask = 0x4001000,
328 .tuner_i2c_master = 1,
329 .demod_i2c_master = 2,
330 .has_dvb = 1,
331 .demod_addr = 0x32,
332 .norm = V4L2_STD_NTSC,
333
334 .input = {{
335 .type = CX231XX_VMUX_TELEVISION,
336 .vmux = CX231XX_VIN_2_1,
337 .amux = CX231XX_AMUX_VIDEO,
338 .gpio = NULL,
339 }
340 },
341 },
Michael Krufky1a50fdd2010-07-06 18:23:53 -0300342 [CX231XX_BOARD_HAUPPAUGE_EXETER] = {
343 .name = "Hauppauge EXETER",
344 .tuner_type = TUNER_NXP_TDA18271,
345 .tuner_addr = 0x60,
346 .tuner_gpio = RDE250_XCV_TUNER,
347 .tuner_sif_gpio = 0x05,
348 .tuner_scl_gpio = 0x1a,
349 .tuner_sda_gpio = 0x1b,
350 .decoder = CX231XX_AVDECODER,
Devin Heitmueller88806212010-08-18 17:50:07 -0300351 .output_mode = OUT_MODE_VIP11,
Michael Krufky1a50fdd2010-07-06 18:23:53 -0300352 .demod_xfer_mode = 0,
353 .ctl_pin_status_mask = 0xFFFFFFC4,
354 .agc_analog_digital_select_gpio = 0x0c,
355 .gpio_pin_status_mask = 0x4001000,
356 .tuner_i2c_master = 1,
357 .demod_i2c_master = 2,
358 .has_dvb = 1,
359 .demod_addr = 0x0e,
360 .norm = V4L2_STD_NTSC,
361
362 .input = {{
363 .type = CX231XX_VMUX_TELEVISION,
364 .vmux = CX231XX_VIN_3_1,
365 .amux = CX231XX_AMUX_VIDEO,
Peter Huewef72cfd82011-01-25 17:38:52 -0300366 .gpio = NULL,
Michael Krufky1a50fdd2010-07-06 18:23:53 -0300367 }, {
368 .type = CX231XX_VMUX_COMPOSITE1,
369 .vmux = CX231XX_VIN_2_1,
370 .amux = CX231XX_AMUX_LINE_IN,
Peter Huewef72cfd82011-01-25 17:38:52 -0300371 .gpio = NULL,
Michael Krufky1a50fdd2010-07-06 18:23:53 -0300372 }, {
373 .type = CX231XX_VMUX_SVIDEO,
374 .vmux = CX231XX_VIN_1_1 |
375 (CX231XX_VIN_1_2 << 8) |
376 CX25840_SVIDEO_ON,
377 .amux = CX231XX_AMUX_LINE_IN,
Peter Huewef72cfd82011-01-25 17:38:52 -0300378 .gpio = NULL,
Michael Krufky1a50fdd2010-07-06 18:23:53 -0300379 } },
380 },
Devin Heitmueller4270c3c2010-07-31 00:49:01 -0300381 [CX231XX_BOARD_HAUPPAUGE_USBLIVE2] = {
382 .name = "Hauppauge USB Live 2",
383 .tuner_type = TUNER_ABSENT,
384 .decoder = CX231XX_AVDECODER,
Devin Heitmueller88806212010-08-18 17:50:07 -0300385 .output_mode = OUT_MODE_VIP11,
Devin Heitmueller4270c3c2010-07-31 00:49:01 -0300386 .demod_xfer_mode = 0,
387 .ctl_pin_status_mask = 0xFFFFFFC4,
388 .agc_analog_digital_select_gpio = 0x0c,
389 .gpio_pin_status_mask = 0x4001000,
390 .norm = V4L2_STD_NTSC,
Mauro Carvalho Chehab2f861382011-01-31 22:12:15 -0300391 .no_alt_vanc = 1,
392 .external_av = 1,
Devin Heitmueller992299e2011-07-23 22:17:17 -0300393 .dont_use_port_3 = 1,
Devin Heitmueller4270c3c2010-07-31 00:49:01 -0300394 .input = {{
395 .type = CX231XX_VMUX_COMPOSITE1,
396 .vmux = CX231XX_VIN_2_1,
397 .amux = CX231XX_AMUX_LINE_IN,
Peter Huewef72cfd82011-01-25 17:38:52 -0300398 .gpio = NULL,
Devin Heitmueller4270c3c2010-07-31 00:49:01 -0300399 }, {
400 .type = CX231XX_VMUX_SVIDEO,
401 .vmux = CX231XX_VIN_1_1 |
402 (CX231XX_VIN_1_2 << 8) |
403 CX25840_SVIDEO_ON,
404 .amux = CX231XX_AMUX_LINE_IN,
Peter Huewef72cfd82011-01-25 17:38:52 -0300405 .gpio = NULL,
Devin Heitmueller4270c3c2010-07-31 00:49:01 -0300406 } },
407 },
Márcio Alveseeaaf812011-04-11 19:57:15 -0300408 [CX231XX_BOARD_KWORLD_UB430_USB_HYBRID] = {
409 .name = "Kworld UB430 USB Hybrid",
410 .tuner_type = TUNER_NXP_TDA18271,
411 .tuner_addr = 0x60,
412 .decoder = CX231XX_AVDECODER,
413 .output_mode = OUT_MODE_VIP11,
414 .demod_xfer_mode = 0,
415 .ctl_pin_status_mask = 0xFFFFFFC4,
416 .agc_analog_digital_select_gpio = 0x11, /* According with PV cxPolaris.inf file */
417 .tuner_sif_gpio = -1,
418 .tuner_scl_gpio = -1,
419 .tuner_sda_gpio = -1,
420 .gpio_pin_status_mask = 0x4001000,
421 .tuner_i2c_master = 2,
422 .demod_i2c_master = 1,
423 .ir_i2c_master = 2,
424 .has_dvb = 1,
425 .demod_addr = 0x10,
426 .norm = V4L2_STD_PAL_M,
427 .input = {{
428 .type = CX231XX_VMUX_TELEVISION,
429 .vmux = CX231XX_VIN_3_1,
430 .amux = CX231XX_AMUX_VIDEO,
431 .gpio = NULL,
432 }, {
433 .type = CX231XX_VMUX_COMPOSITE1,
434 .vmux = CX231XX_VIN_2_1,
435 .amux = CX231XX_AMUX_LINE_IN,
436 .gpio = NULL,
437 }, {
438 .type = CX231XX_VMUX_SVIDEO,
439 .vmux = CX231XX_VIN_1_1 |
440 (CX231XX_VIN_1_2 << 8) |
441 CX25840_SVIDEO_ON,
442 .amux = CX231XX_AMUX_LINE_IN,
443 .gpio = NULL,
444 } },
445 },
Johannes Erdfelt8b1255a2013-08-16 21:29:02 -0300446 [CX231XX_BOARD_KWORLD_UB445_USB_HYBRID] = {
447 .name = "Kworld UB445 USB Hybrid",
448 .tuner_type = TUNER_NXP_TDA18271,
449 .tuner_addr = 0x60,
450 .decoder = CX231XX_AVDECODER,
451 .output_mode = OUT_MODE_VIP11,
452 .demod_xfer_mode = 0,
453 .ctl_pin_status_mask = 0xFFFFFFC4,
454 .agc_analog_digital_select_gpio = 0x11, /* According with PV cxPolaris.inf file */
455 .tuner_sif_gpio = -1,
456 .tuner_scl_gpio = -1,
457 .tuner_sda_gpio = -1,
458 .gpio_pin_status_mask = 0x4001000,
459 .tuner_i2c_master = 2,
460 .demod_i2c_master = 1,
461 .ir_i2c_master = 2,
462 .has_dvb = 1,
463 .demod_addr = 0x10,
464 .norm = V4L2_STD_NTSC_M,
465 .input = {{
466 .type = CX231XX_VMUX_TELEVISION,
467 .vmux = CX231XX_VIN_3_1,
468 .amux = CX231XX_AMUX_VIDEO,
469 .gpio = NULL,
470 }, {
471 .type = CX231XX_VMUX_COMPOSITE1,
472 .vmux = CX231XX_VIN_2_1,
473 .amux = CX231XX_AMUX_LINE_IN,
474 .gpio = NULL,
475 }, {
476 .type = CX231XX_VMUX_SVIDEO,
477 .vmux = CX231XX_VIN_1_1 |
478 (CX231XX_VIN_1_2 << 8) |
479 CX25840_SVIDEO_ON,
480 .amux = CX231XX_AMUX_LINE_IN,
481 .gpio = NULL,
482 } },
483 },
Mauro Carvalho Chehab9417bc62010-09-26 20:44:31 -0300484 [CX231XX_BOARD_PV_PLAYTV_USB_HYBRID] = {
485 .name = "Pixelview PlayTV USB Hybrid",
486 .tuner_type = TUNER_NXP_TDA18271,
487 .tuner_addr = 0x60,
488 .decoder = CX231XX_AVDECODER,
489 .output_mode = OUT_MODE_VIP11,
490 .demod_xfer_mode = 0,
491 .ctl_pin_status_mask = 0xFFFFFFC4,
492 .agc_analog_digital_select_gpio = 0x00, /* According with PV cxPolaris.inf file */
493 .tuner_sif_gpio = -1,
494 .tuner_scl_gpio = -1,
495 .tuner_sda_gpio = -1,
496 .gpio_pin_status_mask = 0x4001000,
497 .tuner_i2c_master = 2,
498 .demod_i2c_master = 1,
Mauro Carvalho Chehab1bc25f72010-10-23 13:35:58 -0300499 .ir_i2c_master = 2,
Mauro Carvalho Chehab788e5d42010-12-17 14:47:27 -0300500 .rc_map_name = RC_MAP_PIXELVIEW_002T,
Mauro Carvalho Chehabede676c2010-09-27 23:44:27 -0300501 .has_dvb = 1,
Mauro Carvalho Chehab9417bc62010-09-26 20:44:31 -0300502 .demod_addr = 0x10,
503 .norm = V4L2_STD_PAL_M,
504 .input = {{
505 .type = CX231XX_VMUX_TELEVISION,
506 .vmux = CX231XX_VIN_3_1,
507 .amux = CX231XX_AMUX_VIDEO,
Peter Huewef72cfd82011-01-25 17:38:52 -0300508 .gpio = NULL,
Mauro Carvalho Chehab9417bc62010-09-26 20:44:31 -0300509 }, {
510 .type = CX231XX_VMUX_COMPOSITE1,
511 .vmux = CX231XX_VIN_2_1,
512 .amux = CX231XX_AMUX_LINE_IN,
Peter Huewef72cfd82011-01-25 17:38:52 -0300513 .gpio = NULL,
Mauro Carvalho Chehab9417bc62010-09-26 20:44:31 -0300514 }, {
515 .type = CX231XX_VMUX_SVIDEO,
516 .vmux = CX231XX_VIN_1_1 |
517 (CX231XX_VIN_1_2 << 8) |
518 CX25840_SVIDEO_ON,
519 .amux = CX231XX_AMUX_LINE_IN,
Peter Huewef72cfd82011-01-25 17:38:52 -0300520 .gpio = NULL,
Mauro Carvalho Chehab9417bc62010-09-26 20:44:31 -0300521 } },
522 },
Mauro Carvalho Chehab4e105032011-01-31 22:18:21 -0300523 [CX231XX_BOARD_PV_XCAPTURE_USB] = {
524 .name = "Pixelview Xcapture USB",
525 .tuner_type = TUNER_ABSENT,
526 .decoder = CX231XX_AVDECODER,
527 .output_mode = OUT_MODE_VIP11,
528 .demod_xfer_mode = 0,
529 .ctl_pin_status_mask = 0xFFFFFFC4,
530 .agc_analog_digital_select_gpio = 0x0c,
531 .gpio_pin_status_mask = 0x4001000,
532 .norm = V4L2_STD_NTSC,
533 .no_alt_vanc = 1,
534 .external_av = 1,
535 .dont_use_port_3 = 1,
536
537 .input = {{
538 .type = CX231XX_VMUX_COMPOSITE1,
539 .vmux = CX231XX_VIN_2_1,
540 .amux = CX231XX_AMUX_LINE_IN,
541 .gpio = NULL,
542 }, {
543 .type = CX231XX_VMUX_SVIDEO,
544 .vmux = CX231XX_VIN_1_1 |
545 (CX231XX_VIN_1_2 << 8) |
546 CX25840_SVIDEO_ON,
547 .amux = CX231XX_AMUX_LINE_IN,
548 .gpio = NULL,
549 }
550 },
551 },
Igor Novgorodov2a7b6a42011-05-17 13:46:36 -0300552
553 [CX231XX_BOARD_ICONBIT_U100] = {
554 .name = "Iconbit Analog Stick U100 FM",
555 .tuner_type = TUNER_ABSENT,
556 .decoder = CX231XX_AVDECODER,
557 .output_mode = OUT_MODE_VIP11,
558 .demod_xfer_mode = 0,
559 .ctl_pin_status_mask = 0xFFFFFFC4,
560 .agc_analog_digital_select_gpio = 0x1C,
561 .gpio_pin_status_mask = 0x4001000,
562
563 .input = {{
564 .type = CX231XX_VMUX_COMPOSITE1,
565 .vmux = CX231XX_VIN_2_1,
566 .amux = CX231XX_AMUX_LINE_IN,
567 .gpio = NULL,
568 }, {
569 .type = CX231XX_VMUX_SVIDEO,
570 .vmux = CX231XX_VIN_1_1 |
571 (CX231XX_VIN_1_2 << 8) |
572 CX25840_SVIDEO_ON,
573 .amux = CX231XX_AMUX_LINE_IN,
574 .gpio = NULL,
575 } },
576 },
Peter Moonde8ae0d2011-06-08 15:54:19 -0300577 [CX231XX_BOARD_HAUPPAUGE_USB2_FM_PAL] = {
578 .name = "Hauppauge WinTV USB2 FM (PAL)",
579 .tuner_type = TUNER_NXP_TDA18271,
580 .tuner_addr = 0x60,
581 .tuner_gpio = RDE250_XCV_TUNER,
582 .tuner_sif_gpio = 0x05,
583 .tuner_scl_gpio = 0x1a,
584 .tuner_sda_gpio = 0x1b,
585 .decoder = CX231XX_AVDECODER,
586 .output_mode = OUT_MODE_VIP11,
587 .ctl_pin_status_mask = 0xFFFFFFC4,
588 .agc_analog_digital_select_gpio = 0x0c,
589 .gpio_pin_status_mask = 0x4001000,
590 .tuner_i2c_master = 1,
591 .norm = V4L2_STD_PAL,
592
593 .input = {{
594 .type = CX231XX_VMUX_TELEVISION,
595 .vmux = CX231XX_VIN_3_1,
596 .amux = CX231XX_AMUX_VIDEO,
597 .gpio = NULL,
598 }, {
599 .type = CX231XX_VMUX_COMPOSITE1,
600 .vmux = CX231XX_VIN_2_1,
601 .amux = CX231XX_AMUX_LINE_IN,
602 .gpio = NULL,
603 }, {
604 .type = CX231XX_VMUX_SVIDEO,
605 .vmux = CX231XX_VIN_1_1 |
606 (CX231XX_VIN_1_2 << 8) |
607 CX25840_SVIDEO_ON,
608 .amux = CX231XX_AMUX_LINE_IN,
609 .gpio = NULL,
610 } },
611 },
612 [CX231XX_BOARD_HAUPPAUGE_USB2_FM_NTSC] = {
613 .name = "Hauppauge WinTV USB2 FM (NTSC)",
614 .tuner_type = TUNER_NXP_TDA18271,
615 .tuner_addr = 0x60,
616 .tuner_gpio = RDE250_XCV_TUNER,
617 .tuner_sif_gpio = 0x05,
618 .tuner_scl_gpio = 0x1a,
619 .tuner_sda_gpio = 0x1b,
620 .decoder = CX231XX_AVDECODER,
621 .output_mode = OUT_MODE_VIP11,
622 .ctl_pin_status_mask = 0xFFFFFFC4,
623 .agc_analog_digital_select_gpio = 0x0c,
624 .gpio_pin_status_mask = 0x4001000,
625 .tuner_i2c_master = 1,
626 .norm = V4L2_STD_NTSC,
627
628 .input = {{
629 .type = CX231XX_VMUX_TELEVISION,
630 .vmux = CX231XX_VIN_3_1,
631 .amux = CX231XX_AMUX_VIDEO,
632 .gpio = NULL,
633 }, {
634 .type = CX231XX_VMUX_COMPOSITE1,
635 .vmux = CX231XX_VIN_2_1,
636 .amux = CX231XX_AMUX_LINE_IN,
637 .gpio = NULL,
638 }, {
639 .type = CX231XX_VMUX_SVIDEO,
640 .vmux = CX231XX_VIN_1_1 |
641 (CX231XX_VIN_1_2 << 8) |
642 CX25840_SVIDEO_ON,
643 .amux = CX231XX_AMUX_LINE_IN,
644 .gpio = NULL,
645 } },
646 },
Alf Høgemark68c97bf2012-11-28 14:29:16 -0300647 [CX231XX_BOARD_ELGATO_VIDEO_CAPTURE_V2] = {
648 .name = "Elgato Video Capture V2",
649 .tuner_type = TUNER_ABSENT,
650 .decoder = CX231XX_AVDECODER,
651 .output_mode = OUT_MODE_VIP11,
652 .demod_xfer_mode = 0,
653 .ctl_pin_status_mask = 0xFFFFFFC4,
654 .agc_analog_digital_select_gpio = 0x0c,
655 .gpio_pin_status_mask = 0x4001000,
656 .norm = V4L2_STD_NTSC,
657 .no_alt_vanc = 1,
658 .external_av = 1,
659 .dont_use_port_3 = 1,
660 .input = {{
661 .type = CX231XX_VMUX_COMPOSITE1,
662 .vmux = CX231XX_VIN_2_1,
663 .amux = CX231XX_AMUX_LINE_IN,
664 .gpio = NULL,
665 }, {
666 .type = CX231XX_VMUX_SVIDEO,
667 .vmux = CX231XX_VIN_1_1 |
668 (CX231XX_VIN_1_2 << 8) |
669 CX25840_SVIDEO_ON,
670 .amux = CX231XX_AMUX_LINE_IN,
671 .gpio = NULL,
672 } },
673 },
Matt Gomboc3ead1ba312013-03-01 19:53:30 -0300674 [CX231XX_BOARD_OTG102] = {
675 .name = "Geniatech OTG102",
676 .tuner_type = TUNER_ABSENT,
677 .decoder = CX231XX_AVDECODER,
678 .output_mode = OUT_MODE_VIP11,
679 .ctl_pin_status_mask = 0xFFFFFFC4,
680 .agc_analog_digital_select_gpio = 0x0c,
681 /* According with PV CxPlrCAP.inf file */
682 .gpio_pin_status_mask = 0x4001000,
683 .norm = V4L2_STD_NTSC,
684 .no_alt_vanc = 1,
685 .external_av = 1,
686 .dont_use_port_3 = 1,
687 /*.has_417 = 1, */
688 /* This board is believed to have a hardware encoding chip
689 * supporting mpeg1/2/4, but as the 417 is apparently not
690 * working for the reference board it is not here either. */
691
692 .input = {{
693 .type = CX231XX_VMUX_COMPOSITE1,
694 .vmux = CX231XX_VIN_2_1,
695 .amux = CX231XX_AMUX_LINE_IN,
696 .gpio = NULL,
697 }, {
698 .type = CX231XX_VMUX_SVIDEO,
699 .vmux = CX231XX_VIN_1_1 |
700 (CX231XX_VIN_1_2 << 8) |
701 CX25840_SVIDEO_ON,
702 .amux = CX231XX_AMUX_LINE_IN,
703 .gpio = NULL,
704 }
705 },
706 },
Sri Deevie0d3baf2009-03-03 14:37:50 -0300707};
708const unsigned int cx231xx_bcount = ARRAY_SIZE(cx231xx_boards);
709
710/* table of devices that work with this driver */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300711struct usb_device_id cx231xx_id_table[] = {
Links (Markus)dad4c412014-01-04 19:44:34 -0300712 {USB_DEVICE(0x1D19, 0x6109),
713 .driver_info = CX231XX_BOARD_PV_XCAPTURE_USB},
Sri Deevied559ed2009-03-13 18:35:14 -0300714 {USB_DEVICE(0x0572, 0x5A3C),
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300715 .driver_info = CX231XX_BOARD_UNKNOWN},
716 {USB_DEVICE(0x0572, 0x58A2),
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300717 .driver_info = CX231XX_BOARD_CNXT_CARRAERA},
Sri Deevied559ed2009-03-13 18:35:14 -0300718 {USB_DEVICE(0x0572, 0x58A1),
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300719 .driver_info = CX231XX_BOARD_CNXT_SHELBY},
720 {USB_DEVICE(0x0572, 0x58A4),
721 .driver_info = CX231XX_BOARD_CNXT_RDE_253S},
722 {USB_DEVICE(0x0572, 0x58A5),
723 .driver_info = CX231XX_BOARD_CNXT_RDU_253S},
724 {USB_DEVICE(0x0572, 0x58A6),
725 .driver_info = CX231XX_BOARD_CNXT_VIDEO_GRABBER},
726 {USB_DEVICE(0x0572, 0x589E),
727 .driver_info = CX231XX_BOARD_CNXT_RDE_250},
728 {USB_DEVICE(0x0572, 0x58A0),
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300729 .driver_info = CX231XX_BOARD_CNXT_RDU_250},
Peter Moonde8ae0d2011-06-08 15:54:19 -0300730 {USB_DEVICE(0x2040, 0xb110),
731 .driver_info = CX231XX_BOARD_HAUPPAUGE_USB2_FM_PAL},
732 {USB_DEVICE(0x2040, 0xb111),
733 .driver_info = CX231XX_BOARD_HAUPPAUGE_USB2_FM_NTSC},
Michael Krufky1a50fdd2010-07-06 18:23:53 -0300734 {USB_DEVICE(0x2040, 0xb120),
735 .driver_info = CX231XX_BOARD_HAUPPAUGE_EXETER},
Devin Heitmuellerd78148f2010-07-06 18:25:19 -0300736 {USB_DEVICE(0x2040, 0xb140),
737 .driver_info = CX231XX_BOARD_HAUPPAUGE_EXETER},
Devin Heitmueller4270c3c2010-07-31 00:49:01 -0300738 {USB_DEVICE(0x2040, 0xc200),
739 .driver_info = CX231XX_BOARD_HAUPPAUGE_USBLIVE2},
Mauro Carvalho Chehab9417bc62010-09-26 20:44:31 -0300740 {USB_DEVICE_VER(USB_VID_PIXELVIEW, USB_PID_PIXELVIEW_SBTVD, 0x4000, 0x4001),
741 .driver_info = CX231XX_BOARD_PV_PLAYTV_USB_HYBRID},
Mauro Carvalho Chehab4e105032011-01-31 22:18:21 -0300742 {USB_DEVICE(USB_VID_PIXELVIEW, 0x5014),
743 .driver_info = CX231XX_BOARD_PV_XCAPTURE_USB},
Márcio Alveseeaaf812011-04-11 19:57:15 -0300744 {USB_DEVICE(0x1b80, 0xe424),
745 .driver_info = CX231XX_BOARD_KWORLD_UB430_USB_HYBRID},
Johannes Erdfelt8b1255a2013-08-16 21:29:02 -0300746 {USB_DEVICE(0x1b80, 0xe421),
747 .driver_info = CX231XX_BOARD_KWORLD_UB445_USB_HYBRID},
Igor Novgorodov2a7b6a42011-05-17 13:46:36 -0300748 {USB_DEVICE(0x1f4d, 0x0237),
749 .driver_info = CX231XX_BOARD_ICONBIT_U100},
Alf Høgemark68c97bf2012-11-28 14:29:16 -0300750 {USB_DEVICE(0x0fd9, 0x0037),
751 .driver_info = CX231XX_BOARD_ELGATO_VIDEO_CAPTURE_V2},
Matt Gomboc3ead1ba312013-03-01 19:53:30 -0300752 {USB_DEVICE(0x1f4d, 0x0102),
753 .driver_info = CX231XX_BOARD_OTG102},
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300754 {},
Sri Deevie0d3baf2009-03-03 14:37:50 -0300755};
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300756
Sri Deevie0d3baf2009-03-03 14:37:50 -0300757MODULE_DEVICE_TABLE(usb, cx231xx_id_table);
758
759/* cx231xx_tuner_callback
760 * will be used to reset XC5000 tuner using GPIO pin
761 */
762
763int cx231xx_tuner_callback(void *ptr, int component, int command, int arg)
764{
765 int rc = 0;
766 struct cx231xx *dev = ptr;
767
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300768 if (dev->tuner_type == TUNER_XC5000) {
769 if (command == XC5000_TUNER_RESET) {
770 cx231xx_info
Sri Deevib9255172009-03-04 17:49:01 -0300771 ("Tuner CB: RESET: cmd %d : tuner type %d \n",
772 command, dev->tuner_type);
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300773 cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit,
774 1);
775 msleep(10);
776 cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit,
777 0);
778 msleep(330);
779 cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit,
780 1);
781 msleep(10);
782 }
Mauro Carvalho Chehab55fa2882010-09-29 11:07:08 -0300783 } else if (dev->tuner_type == TUNER_NXP_TDA18271) {
784 switch (command) {
785 case TDA18271_CALLBACK_CMD_AGC_ENABLE:
786 if (dev->model == CX231XX_BOARD_PV_PLAYTV_USB_HYBRID)
787 rc = cx231xx_set_agc_analog_digital_mux_select(dev, arg);
788 break;
789 default:
790 rc = -EINVAL;
791 break;
792 }
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300793 }
Sri Deevie0d3baf2009-03-03 14:37:50 -0300794 return rc;
795}
796EXPORT_SYMBOL_GPL(cx231xx_tuner_callback);
797
Mauro Carvalho Chehabd4c06132012-10-27 14:02:49 -0300798static void cx231xx_reset_out(struct cx231xx *dev)
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300799{
800 cx231xx_set_gpio_value(dev, CX23417_RESET, 1);
801 msleep(200);
802 cx231xx_set_gpio_value(dev, CX23417_RESET, 0);
803 msleep(200);
804 cx231xx_set_gpio_value(dev, CX23417_RESET, 1);
805}
Mauro Carvalho Chehabd4c06132012-10-27 14:02:49 -0300806
807static void cx231xx_enable_OSC(struct cx231xx *dev)
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300808{
809 cx231xx_set_gpio_value(dev, CX23417_OSC_EN, 1);
810}
Mauro Carvalho Chehabd4c06132012-10-27 14:02:49 -0300811
812static void cx231xx_sleep_s5h1432(struct cx231xx *dev)
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300813{
814 cx231xx_set_gpio_value(dev, SLEEP_S5H1432, 0);
815}
816
Sri Deevib9255172009-03-04 17:49:01 -0300817static inline void cx231xx_set_model(struct cx231xx *dev)
Sri Deevie0d3baf2009-03-03 14:37:50 -0300818{
Ezequiel Garcia3724dde2012-10-23 15:57:05 -0300819 dev->board = cx231xx_boards[dev->model];
Sri Deevie0d3baf2009-03-03 14:37:50 -0300820}
821
822/* Since cx231xx_pre_card_setup() requires a proper dev->model,
823 * this won't work for boards with generic PCI IDs
824 */
825void cx231xx_pre_card_setup(struct cx231xx *dev)
826{
827
828 cx231xx_set_model(dev);
829
830 cx231xx_info("Identified as %s (card=%d)\n",
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300831 dev->board.name, dev->model);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300832
Sri Deevi6e4f5742009-03-10 21:16:26 -0300833 /* set the direction for GPIO pins */
Mauro Carvalho Chehabc10469c2010-09-11 11:37:51 -0300834 if (dev->board.tuner_gpio) {
835 cx231xx_set_gpio_direction(dev, dev->board.tuner_gpio->bit, 1);
836 cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit, 1);
Mauro Carvalho Chehab78bb6df2010-09-26 20:48:38 -0300837 }
838 if (dev->board.tuner_sif_gpio >= 0)
Mauro Carvalho Chehabc10469c2010-09-11 11:37:51 -0300839 cx231xx_set_gpio_direction(dev, dev->board.tuner_sif_gpio, 1);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300840
Mauro Carvalho Chehab78bb6df2010-09-26 20:48:38 -0300841 /* request some modules if any required */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300842
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300843 /* set the mode to Analog mode initially */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300844 cx231xx_set_mode(dev, CX231XX_ANALOG_MODE);
845
846 /* Unlock device */
847 /* cx231xx_set_mode(dev, CX231XX_SUSPEND); */
848
849}
850
Sri Deevie0d3baf2009-03-03 14:37:50 -0300851static void cx231xx_config_tuner(struct cx231xx *dev)
852{
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300853 struct tuner_setup tun_setup;
854 struct v4l2_frequency f;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300855
856 if (dev->tuner_type == TUNER_ABSENT)
857 return;
858
859 tun_setup.mode_mask = T_ANALOG_TV | T_RADIO;
860 tun_setup.type = dev->tuner_type;
861 tun_setup.addr = dev->tuner_addr;
862 tun_setup.tuner_callback = cx231xx_tuner_callback;
863
Sri Deevib1196122009-03-20 23:33:48 -0300864 tuner_call(dev, tuner, s_type_addr, &tun_setup);
865
Sri Deevie0d3baf2009-03-03 14:37:50 -0300866#if 0
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300867 if (tun_setup.type == TUNER_XC5000) {
Sri Deevie0d3baf2009-03-03 14:37:50 -0300868 static struct xc2028_ctrl ctrl = {
869 .fname = XC5000_DEFAULT_FIRMWARE,
870 .max_len = 64,
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300871 .demod = 0;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300872 };
873 struct v4l2_priv_tun_config cfg = {
874 .tuner = dev->tuner_type,
875 .priv = &ctrl,
876 };
Sri Deevib1196122009-03-20 23:33:48 -0300877 tuner_call(dev, tuner, s_config, &cfg);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300878 }
879#endif
Sri Deevie0d3baf2009-03-03 14:37:50 -0300880 /* configure tuner */
881 f.tuner = 0;
882 f.type = V4L2_TUNER_ANALOG_TV;
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300883 f.frequency = 9076; /* just a magic number */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300884 dev->ctl_freq = f.frequency;
Sri Deevib1196122009-03-20 23:33:48 -0300885 call_all(dev, tuner, s_frequency, &f);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300886
Sri Deevib1196122009-03-20 23:33:48 -0300887}
Sri Deevie0d3baf2009-03-03 14:37:50 -0300888
Sri Deevie0d3baf2009-03-03 14:37:50 -0300889void cx231xx_card_setup(struct cx231xx *dev)
890{
Sri Deevib1196122009-03-20 23:33:48 -0300891
Sri Deevie0d3baf2009-03-03 14:37:50 -0300892 cx231xx_set_model(dev);
893
894 dev->tuner_type = cx231xx_boards[dev->model].tuner_type;
895 if (cx231xx_boards[dev->model].tuner_addr)
896 dev->tuner_addr = cx231xx_boards[dev->model].tuner_addr;
897
Sri Deevie0d3baf2009-03-03 14:37:50 -0300898 /* request some modules */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300899 if (dev->board.decoder == CX231XX_AVDECODER) {
Hans Verkuile6574f22009-04-01 03:57:53 -0300900 dev->sd_cx25840 = v4l2_i2c_new_subdev(&dev->v4l2_dev,
901 &dev->i2c_bus[0].i2c_adap,
Laurent Pinchart9a1f8b32010-09-24 10:16:44 -0300902 "cx25840", 0x88 >> 1, NULL);
Sri Deevib1196122009-03-20 23:33:48 -0300903 if (dev->sd_cx25840 == NULL)
904 cx231xx_info("cx25840 subdev registration failure\n");
Hans Verkuilcc26b072009-03-29 19:20:26 -0300905 cx25840_call(dev, core, load_fw);
Sri Deevib1196122009-03-20 23:33:48 -0300906
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300907 }
Sri Deevib1196122009-03-20 23:33:48 -0300908
Devin Heitmuellere3e0aaa2010-07-08 17:05:30 -0300909 /* Initialize the tuner */
910 if (dev->board.tuner_type != TUNER_ABSENT) {
911 dev->sd_tuner = v4l2_i2c_new_subdev(&dev->v4l2_dev,
Mauro Carvalho Chehab1a4aa922010-09-26 20:01:51 -0300912 &dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap,
Laurent Pinchart9a1f8b32010-09-24 10:16:44 -0300913 "tuner",
Devin Heitmuellere3e0aaa2010-07-08 17:05:30 -0300914 dev->tuner_addr, NULL);
915 if (dev->sd_tuner == NULL)
916 cx231xx_info("tuner subdev registration failure\n");
917 else
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300918 cx231xx_config_tuner(dev);
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300919 }
Sri Deevie0d3baf2009-03-03 14:37:50 -0300920}
921
Sri Deevie0d3baf2009-03-03 14:37:50 -0300922/*
923 * cx231xx_config()
924 * inits registers with sane defaults
925 */
926int cx231xx_config(struct cx231xx *dev)
927{
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300928 /* TBD need to add cx231xx specific code */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300929
930 return 0;
931}
932
933/*
934 * cx231xx_config_i2c()
935 * configure i2c attached devices
936 */
937void cx231xx_config_i2c(struct cx231xx *dev)
938{
Hans Verkuil5325b422009-04-02 11:26:22 -0300939 /* u32 input = INPUT(dev->video_input)->vmux; */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300940
Sri Deevib1196122009-03-20 23:33:48 -0300941 call_all(dev, video, s_stream, 1);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300942}
943
944/*
945 * cx231xx_realease_resources()
946 * unregisters the v4l2,i2c and usb devices
947 * called when the device gets disconected or at module unload
948*/
949void cx231xx_release_resources(struct cx231xx *dev)
950{
Sri Deevie0d3baf2009-03-03 14:37:50 -0300951 cx231xx_release_analog_resources(dev);
952
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300953 cx231xx_remove_from_devlist(dev);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300954
Mauro Carvalho Chehab7528cd22012-01-10 09:20:01 -0200955 cx231xx_ir_exit(dev);
956
Mauro Carvalho Chehab9ab66912010-10-23 13:28:33 -0300957 /* Release I2C buses */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300958 cx231xx_dev_uninit(dev);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300959
Mauro Carvalho Chehab7528cd22012-01-10 09:20:01 -0200960 /* delete v4l2 device */
961 v4l2_device_unregister(&dev->v4l2_dev);
Mauro Carvalho Chehab9ab66912010-10-23 13:28:33 -0300962
Sri Deevie0d3baf2009-03-03 14:37:50 -0300963 usb_put_dev(dev->udev);
964
965 /* Mark device as unused */
Mauro Carvalho Chehabdb702a72012-01-10 09:33:47 -0200966 clear_bit(dev->devno, &cx231xx_devused);
Mauro Carvalho Chehab7528cd22012-01-10 09:20:01 -0200967
968 kfree(dev->video_mode.alt_max_pkt_size);
969 kfree(dev->vbi_mode.alt_max_pkt_size);
970 kfree(dev->sliced_cc_mode.alt_max_pkt_size);
971 kfree(dev->ts1_mode.alt_max_pkt_size);
972 kfree(dev);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300973}
974
Sri Deevie0d3baf2009-03-03 14:37:50 -0300975/*
976 * cx231xx_init_dev()
977 * allocates and inits the device structs, registers i2c bus and v4l device
978 */
Thomas Petazzoni15cb6af2012-01-07 09:52:40 -0300979static int cx231xx_init_dev(struct cx231xx *dev, struct usb_device *udev,
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300980 int minor)
Sri Deevie0d3baf2009-03-03 14:37:50 -0300981{
Sri Deevie0d3baf2009-03-03 14:37:50 -0300982 int retval = -ENOMEM;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300983 unsigned int maxh, maxw;
984
985 dev->udev = udev;
986 mutex_init(&dev->lock);
987 mutex_init(&dev->ctrl_urb_lock);
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300988 mutex_init(&dev->gpio_i2c_lock);
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -0300989 mutex_init(&dev->i2c_lock);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300990
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300991 spin_lock_init(&dev->video_mode.slock);
992 spin_lock_init(&dev->vbi_mode.slock);
993 spin_lock_init(&dev->sliced_cc_mode.slock);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300994
995 init_waitqueue_head(&dev->open);
996 init_waitqueue_head(&dev->wait_frame);
997 init_waitqueue_head(&dev->wait_stream);
998
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300999 dev->cx231xx_read_ctrl_reg = cx231xx_read_ctrl_reg;
1000 dev->cx231xx_write_ctrl_reg = cx231xx_write_ctrl_reg;
1001 dev->cx231xx_send_usb_command = cx231xx_send_usb_command;
1002 dev->cx231xx_gpio_i2c_read = cx231xx_gpio_i2c_read;
1003 dev->cx231xx_gpio_i2c_write = cx231xx_gpio_i2c_write;
Sri Deevie0d3baf2009-03-03 14:37:50 -03001004
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -03001005 /* Query cx231xx to find what pcb config it is related to */
1006 initialize_cx231xx(dev);
Sri Deevie0d3baf2009-03-03 14:37:50 -03001007
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -03001008 /*To workaround error number=-71 on EP0 for VideoGrabber,
1009 need set alt here.*/
Devin Heitmueller4270c3c2010-07-31 00:49:01 -03001010 if (dev->model == CX231XX_BOARD_CNXT_VIDEO_GRABBER ||
1011 dev->model == CX231XX_BOARD_HAUPPAUGE_USBLIVE2) {
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -03001012 cx231xx_set_alt_setting(dev, INDEX_VIDEO, 3);
1013 cx231xx_set_alt_setting(dev, INDEX_VANC, 1);
1014 }
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -03001015 /* Cx231xx pre card setup */
Sri Deevie0d3baf2009-03-03 14:37:50 -03001016 cx231xx_pre_card_setup(dev);
1017
Alexey Khoroshilov256d0132013-10-07 18:06:04 -03001018 retval = cx231xx_config(dev);
1019 if (retval) {
Sri Deevie0d3baf2009-03-03 14:37:50 -03001020 cx231xx_errdev("error configuring device\n");
1021 return -ENOMEM;
1022 }
1023
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -03001024 /* set default norm */
Sri Deevie0d3baf2009-03-03 14:37:50 -03001025 dev->norm = dev->board.norm;
1026
1027 /* register i2c bus */
Alexey Khoroshilov256d0132013-10-07 18:06:04 -03001028 retval = cx231xx_dev_init(dev);
1029 if (retval) {
Sri Deevie0d3baf2009-03-03 14:37:50 -03001030 cx231xx_errdev("%s: cx231xx_i2c_register - errCode [%d]!\n",
Alexey Khoroshilov256d0132013-10-07 18:06:04 -03001031 __func__, retval);
1032 goto err_dev_init;
Sri Deevie0d3baf2009-03-03 14:37:50 -03001033 }
1034
1035 /* Do board specific init */
1036 cx231xx_card_setup(dev);
1037
1038 /* configure the device */
1039 cx231xx_config_i2c(dev);
1040
1041 maxw = norm_maxw(dev);
1042 maxh = norm_maxh(dev);
1043
1044 /* set default image size */
1045 dev->width = maxw;
1046 dev->height = maxh;
1047 dev->interlaced = 0;
Sri Deevie0d3baf2009-03-03 14:37:50 -03001048 dev->video_input = 0;
1049
Alexey Khoroshilov256d0132013-10-07 18:06:04 -03001050 retval = cx231xx_config(dev);
1051 if (retval) {
Sri Deevie0d3baf2009-03-03 14:37:50 -03001052 cx231xx_errdev("%s: cx231xx_config - errCode [%d]!\n",
Alexey Khoroshilov256d0132013-10-07 18:06:04 -03001053 __func__, retval);
1054 goto err_dev_init;
Sri Deevie0d3baf2009-03-03 14:37:50 -03001055 }
1056
1057 /* init video dma queues */
1058 INIT_LIST_HEAD(&dev->video_mode.vidq.active);
1059 INIT_LIST_HEAD(&dev->video_mode.vidq.queued);
1060
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -03001061 /* init vbi dma queues */
Sri Deevie0d3baf2009-03-03 14:37:50 -03001062 INIT_LIST_HEAD(&dev->vbi_mode.vidq.active);
1063 INIT_LIST_HEAD(&dev->vbi_mode.vidq.queued);
1064
1065 /* Reset other chips required if they are tied up with GPIO pins */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -03001066 cx231xx_add_into_devlist(dev);
Sri Deevie0d3baf2009-03-03 14:37:50 -03001067
Mauro Carvalho Chehab2f861382011-01-31 22:12:15 -03001068 if (dev->board.has_417) {
Devin Heitmueller2b43db32010-08-18 18:09:28 -03001069 printk(KERN_INFO "attach 417 %d\n", dev->model);
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -03001070 if (cx231xx_417_register(dev) < 0) {
1071 printk(KERN_ERR
1072 "%s() Failed to register 417 on VID_B\n",
1073 __func__);
1074 }
1075 }
1076
Sri Deevie0d3baf2009-03-03 14:37:50 -03001077 retval = cx231xx_register_analog_devices(dev);
Alexey Khoroshilov256d0132013-10-07 18:06:04 -03001078 if (retval) {
1079 cx231xx_release_analog_resources(dev);
1080 goto err_analog;
Sri Deevie0d3baf2009-03-03 14:37:50 -03001081 }
1082
Mauro Carvalho Chehab9ab66912010-10-23 13:28:33 -03001083 cx231xx_ir_init(dev);
1084
Sri Deevie0d3baf2009-03-03 14:37:50 -03001085 cx231xx_init_extension(dev);
1086
1087 return 0;
Alexey Khoroshilov256d0132013-10-07 18:06:04 -03001088err_analog:
1089 cx231xx_remove_from_devlist(dev);
1090err_dev_init:
1091 cx231xx_dev_uninit(dev);
1092 return retval;
Sri Deevie0d3baf2009-03-03 14:37:50 -03001093}
1094
1095#if defined(CONFIG_MODULES) && defined(MODULE)
1096static void request_module_async(struct work_struct *work)
1097{
1098 struct cx231xx *dev = container_of(work,
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -03001099 struct cx231xx, request_module_wk);
Sri Deevie0d3baf2009-03-03 14:37:50 -03001100
1101 if (dev->has_alsa_audio)
1102 request_module("cx231xx-alsa");
1103
1104 if (dev->board.has_dvb)
1105 request_module("cx231xx-dvb");
1106
1107}
1108
1109static void request_modules(struct cx231xx *dev)
1110{
1111 INIT_WORK(&dev->request_module_wk, request_module_async);
1112 schedule_work(&dev->request_module_wk);
1113}
Tejun Heo707bcf32010-12-24 16:14:20 +01001114
1115static void flush_request_modules(struct cx231xx *dev)
1116{
Tejun Heo43829732012-08-20 14:51:24 -07001117 flush_work(&dev->request_module_wk);
Tejun Heo707bcf32010-12-24 16:14:20 +01001118}
Sri Deevie0d3baf2009-03-03 14:37:50 -03001119#else
1120#define request_modules(dev)
Tejun Heo707bcf32010-12-24 16:14:20 +01001121#define flush_request_modules(dev)
Sri Deevie0d3baf2009-03-03 14:37:50 -03001122#endif /* CONFIG_MODULES */
1123
Sri Deevie0d3baf2009-03-03 14:37:50 -03001124/*
1125 * cx231xx_usb_probe()
1126 * checks for supported devices
1127 */
1128static int cx231xx_usb_probe(struct usb_interface *interface,
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -03001129 const struct usb_device_id *id)
Sri Deevie0d3baf2009-03-03 14:37:50 -03001130{
1131 struct usb_device *udev;
1132 struct usb_interface *uif;
1133 struct cx231xx *dev = NULL;
1134 int retval = -ENODEV;
Hans Verkuild73abcf2009-03-12 18:38:40 -03001135 int nr = 0, ifnum;
Sri Deevie0d3baf2009-03-03 14:37:50 -03001136 int i, isoc_pipe = 0;
1137 char *speed;
Mauro Carvalho Chehabdcb78ac2014-07-27 16:27:28 -03001138 u8 idx;
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -03001139 struct usb_interface_assoc_descriptor *assoc_desc;
Sri Deevie0d3baf2009-03-03 14:37:50 -03001140
Sri Deevie0d3baf2009-03-03 14:37:50 -03001141 ifnum = interface->altsetting[0].desc.bInterfaceNumber;
1142
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -03001143 /*
1144 * Interface number 0 - IR interface (handled by mceusb driver)
1145 * Interface number 1 - AV interface (handled by this driver)
1146 */
1147 if (ifnum != 1)
1148 return -ENODEV;
Sri Deevie0d3baf2009-03-03 14:37:50 -03001149
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -03001150 /* Check to see next free device and mark as used */
Mauro Carvalho Chehabdb702a72012-01-10 09:33:47 -02001151 do {
1152 nr = find_first_zero_bit(&cx231xx_devused, CX231XX_MAXBOARDS);
1153 if (nr >= CX231XX_MAXBOARDS) {
1154 /* No free device slots */
1155 cx231xx_err(DRIVER_NAME ": Supports only %i devices.\n",
1156 CX231XX_MAXBOARDS);
1157 return -ENOMEM;
1158 }
1159 } while (test_and_set_bit(nr, &cx231xx_devused));
Sri Deevie0d3baf2009-03-03 14:37:50 -03001160
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -03001161 /* allocate memory for our device state and initialize it */
1162 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
1163 if (dev == NULL) {
1164 cx231xx_err(DRIVER_NAME ": out of memory!\n");
Dan Carpenter6c2cc5b2012-01-13 02:34:00 -03001165 clear_bit(nr, &cx231xx_devused);
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -03001166 return -ENOMEM;
1167 }
Sri Deevie0d3baf2009-03-03 14:37:50 -03001168
Alexey Khoroshilov256d0132013-10-07 18:06:04 -03001169 udev = usb_get_dev(interface_to_usbdev(interface));
1170
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -03001171 snprintf(dev->name, 29, "cx231xx #%d", nr);
1172 dev->devno = nr;
1173 dev->model = id->driver_info;
1174 dev->video_mode.alt = -1;
Sri Deevie0d3baf2009-03-03 14:37:50 -03001175
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -03001176 dev->interface_count++;
1177 /* reset gpio dir and value */
1178 dev->gpio_dir = 0;
1179 dev->gpio_val = 0;
1180 dev->xc_fw_load_done = 0;
1181 dev->has_alsa_audio = 1;
1182 dev->power_mode = -1;
1183 atomic_set(&dev->devlist_count, 0);
Sri Deevie0d3baf2009-03-03 14:37:50 -03001184
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -03001185 /* 0 - vbi ; 1 -sliced cc mode */
1186 dev->vbi_or_sliced_cc_mode = 0;
Sri Deevie0d3baf2009-03-03 14:37:50 -03001187
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -03001188 /* get maximum no.of IAD interfaces */
Mauro Carvalho Chehab139d2882014-07-27 16:27:27 -03001189 dev->max_iad_interface_count = udev->config->desc.bNumInterfaces;
Sri Deevie0d3baf2009-03-03 14:37:50 -03001190
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -03001191 /* init CIR module TBD */
Sri Deevie0d3baf2009-03-03 14:37:50 -03001192
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -03001193 /*mode_tv: digital=1 or analog=0*/
1194 dev->mode_tv = 0;
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -03001195
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -03001196 dev->USE_ISO = transfer_mode;
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -03001197
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -03001198 switch (udev->speed) {
1199 case USB_SPEED_LOW:
1200 speed = "1.5";
1201 break;
1202 case USB_SPEED_UNKNOWN:
1203 case USB_SPEED_FULL:
1204 speed = "12";
1205 break;
1206 case USB_SPEED_HIGH:
1207 speed = "480";
1208 break;
1209 default:
1210 speed = "unknown";
1211 }
Sri Deevie0d3baf2009-03-03 14:37:50 -03001212
Peter Senna Tschudinadb60962012-06-14 13:58:09 -03001213 cx231xx_info("New device %s %s @ %s Mbps "
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -03001214 "(%04x:%04x) with %d interfaces\n",
Peter Senna Tschudinadb60962012-06-14 13:58:09 -03001215 udev->manufacturer ? udev->manufacturer : "",
1216 udev->product ? udev->product : "",
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -03001217 speed,
1218 le16_to_cpu(udev->descriptor.idVendor),
1219 le16_to_cpu(udev->descriptor.idProduct),
1220 dev->max_iad_interface_count);
Sri Deevib1196122009-03-20 23:33:48 -03001221
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -03001222 /* increment interface count */
1223 dev->interface_count++;
Sri Deevie0d3baf2009-03-03 14:37:50 -03001224
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -03001225 /* get device number */
1226 nr = dev->devno;
Sri Deevie0d3baf2009-03-03 14:37:50 -03001227
Mauro Carvalho Chehab8bb84222011-01-29 22:10:56 -03001228 assoc_desc = udev->actconfig->intf_assoc[0];
1229 if (assoc_desc->bFirstInterface != ifnum) {
1230 cx231xx_err(DRIVER_NAME ": Not found "
1231 "matching IAD interface\n");
Alexey Khoroshilov256d0132013-10-07 18:06:04 -03001232 retval = -ENODEV;
1233 goto err_if;
Mauro Carvalho Chehab10e4ebb2010-10-18 21:10:46 -03001234 }
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001235
1236 cx231xx_info("registering interface %d\n", ifnum);
1237
Sri Deevie0d3baf2009-03-03 14:37:50 -03001238 /* save our data pointer in this interface device */
Thomas Petazzonia116a052012-01-07 09:52:38 -03001239 usb_set_intfdata(interface, dev);
Sri Deevie0d3baf2009-03-03 14:37:50 -03001240
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001241 /*
1242 * AV device initialization - only done at the last interface
1243 */
1244
1245 /* Create v4l2 device */
Janne Grunau72317482009-04-01 08:39:29 -03001246 retval = v4l2_device_register(&interface->dev, &dev->v4l2_dev);
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001247 if (retval) {
1248 cx231xx_errdev("v4l2_device_register failed\n");
Alexey Khoroshilov256d0132013-10-07 18:06:04 -03001249 retval = -EIO;
1250 goto err_v4l2;
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -03001251 }
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001252 /* allocate device struct */
Thomas Petazzoni15cb6af2012-01-07 09:52:40 -03001253 retval = cx231xx_init_dev(dev, udev, nr);
Alexey Khoroshilov256d0132013-10-07 18:06:04 -03001254 if (retval)
1255 goto err_init;
Sri Deevie0d3baf2009-03-03 14:37:50 -03001256
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001257 /* compute alternate max packet sizes for video */
Mauro Carvalho Chehabdcb78ac2014-07-27 16:27:28 -03001258 idx = dev->current_pcb_config.hs_config_info[0].interface_info.video_index + 1;
1259 if (idx >= dev->max_iad_interface_count) {
1260 cx231xx_errdev("Video PCB interface #%d doesn't exist\n", idx);
1261 retval = -ENODEV;
1262 goto err_init;
1263 }
1264 uif = udev->actconfig->interface[idx];
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001265
Hans Verkuil69a11a32013-02-07 15:28:53 -03001266 dev->video_mode.end_point_addr = uif->altsetting[0].
1267 endpoint[isoc_pipe].desc.bEndpointAddress;
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001268
1269 dev->video_mode.num_alt = uif->num_altsetting;
1270 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
1271 dev->video_mode.end_point_addr,
1272 dev->video_mode.num_alt);
1273 dev->video_mode.alt_max_pkt_size =
1274 kmalloc(32 * dev->video_mode.num_alt, GFP_KERNEL);
1275
1276 if (dev->video_mode.alt_max_pkt_size == NULL) {
1277 cx231xx_errdev("out of memory!\n");
Alexey Khoroshilov256d0132013-10-07 18:06:04 -03001278 retval = -ENOMEM;
1279 goto err_video_alt;
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001280 }
1281
1282 for (i = 0; i < dev->video_mode.num_alt; i++) {
1283 u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
1284 desc.wMaxPacketSize);
1285 dev->video_mode.alt_max_pkt_size[i] =
1286 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
1287 cx231xx_info("Alternate setting %i, max size= %i\n", i,
1288 dev->video_mode.alt_max_pkt_size[i]);
1289 }
1290
1291 /* compute alternate max packet sizes for vbi */
Mauro Carvalho Chehabdcb78ac2014-07-27 16:27:28 -03001292
1293 idx = dev->current_pcb_config.hs_config_info[0].interface_info.vanc_index + 1;
1294 if (idx >= dev->max_iad_interface_count) {
1295 cx231xx_errdev("VBI PCB interface #%d doesn't exist\n", idx);
1296 retval = -ENODEV;
1297 goto err_vbi_alt;
1298 }
1299 uif = udev->actconfig->interface[idx];
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001300
1301 dev->vbi_mode.end_point_addr =
Hans Verkuil69a11a32013-02-07 15:28:53 -03001302 uif->altsetting[0].endpoint[isoc_pipe].desc.
1303 bEndpointAddress;
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001304
1305 dev->vbi_mode.num_alt = uif->num_altsetting;
1306 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
1307 dev->vbi_mode.end_point_addr,
1308 dev->vbi_mode.num_alt);
1309 dev->vbi_mode.alt_max_pkt_size =
1310 kmalloc(32 * dev->vbi_mode.num_alt, GFP_KERNEL);
1311
1312 if (dev->vbi_mode.alt_max_pkt_size == NULL) {
1313 cx231xx_errdev("out of memory!\n");
Alexey Khoroshilov256d0132013-10-07 18:06:04 -03001314 retval = -ENOMEM;
1315 goto err_vbi_alt;
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001316 }
1317
1318 for (i = 0; i < dev->vbi_mode.num_alt; i++) {
1319 u16 tmp =
1320 le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
1321 desc.wMaxPacketSize);
1322 dev->vbi_mode.alt_max_pkt_size[i] =
1323 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
1324 cx231xx_info("Alternate setting %i, max size= %i\n", i,
1325 dev->vbi_mode.alt_max_pkt_size[i]);
1326 }
1327
1328 /* compute alternate max packet sizes for sliced CC */
Mauro Carvalho Chehabdcb78ac2014-07-27 16:27:28 -03001329 idx = dev->current_pcb_config.hs_config_info[0].interface_info.hanc_index + 1;
1330 if (idx >= dev->max_iad_interface_count) {
1331 cx231xx_errdev("Sliced CC PCB interface #%d doesn't exist\n", idx);
1332 retval = -ENODEV;
1333 goto err_sliced_cc_alt;
1334 }
1335 uif = udev->actconfig->interface[idx];
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001336
1337 dev->sliced_cc_mode.end_point_addr =
Hans Verkuil69a11a32013-02-07 15:28:53 -03001338 uif->altsetting[0].endpoint[isoc_pipe].desc.
1339 bEndpointAddress;
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001340
1341 dev->sliced_cc_mode.num_alt = uif->num_altsetting;
1342 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
1343 dev->sliced_cc_mode.end_point_addr,
1344 dev->sliced_cc_mode.num_alt);
1345 dev->sliced_cc_mode.alt_max_pkt_size =
1346 kmalloc(32 * dev->sliced_cc_mode.num_alt, GFP_KERNEL);
1347
1348 if (dev->sliced_cc_mode.alt_max_pkt_size == NULL) {
1349 cx231xx_errdev("out of memory!\n");
Alexey Khoroshilov256d0132013-10-07 18:06:04 -03001350 retval = -ENOMEM;
1351 goto err_sliced_cc_alt;
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001352 }
1353
1354 for (i = 0; i < dev->sliced_cc_mode.num_alt; i++) {
1355 u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
1356 desc.wMaxPacketSize);
1357 dev->sliced_cc_mode.alt_max_pkt_size[i] =
1358 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
1359 cx231xx_info("Alternate setting %i, max size= %i\n", i,
1360 dev->sliced_cc_mode.alt_max_pkt_size[i]);
1361 }
1362
1363 if (dev->current_pcb_config.ts1_source != 0xff) {
1364 /* compute alternate max packet sizes for TS1 */
Mauro Carvalho Chehabdcb78ac2014-07-27 16:27:28 -03001365 idx = dev->current_pcb_config.hs_config_info[0].interface_info.ts1_index + 1;
1366 if (idx >= dev->max_iad_interface_count) {
1367 cx231xx_errdev("TS1 PCB interface #%d doesn't exist\n", idx);
1368 retval = -ENODEV;
1369 goto err_ts1_alt;
1370 }
1371 uif = udev->actconfig->interface[idx];
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001372
1373 dev->ts1_mode.end_point_addr =
Hans Verkuil69a11a32013-02-07 15:28:53 -03001374 uif->altsetting[0].endpoint[isoc_pipe].
1375 desc.bEndpointAddress;
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001376
1377 dev->ts1_mode.num_alt = uif->num_altsetting;
1378 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
1379 dev->ts1_mode.end_point_addr,
1380 dev->ts1_mode.num_alt);
1381 dev->ts1_mode.alt_max_pkt_size =
1382 kmalloc(32 * dev->ts1_mode.num_alt, GFP_KERNEL);
1383
1384 if (dev->ts1_mode.alt_max_pkt_size == NULL) {
1385 cx231xx_errdev("out of memory!\n");
Alexey Khoroshilov256d0132013-10-07 18:06:04 -03001386 retval = -ENOMEM;
1387 goto err_ts1_alt;
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001388 }
1389
1390 for (i = 0; i < dev->ts1_mode.num_alt; i++) {
1391 u16 tmp = le16_to_cpu(uif->altsetting[i].
1392 endpoint[isoc_pipe].desc.
1393 wMaxPacketSize);
1394 dev->ts1_mode.alt_max_pkt_size[i] =
1395 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
1396 cx231xx_info("Alternate setting %i, max size= %i\n", i,
1397 dev->ts1_mode.alt_max_pkt_size[i]);
1398 }
1399 }
1400
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -03001401 if (dev->model == CX231XX_BOARD_CNXT_VIDEO_GRABBER) {
1402 cx231xx_enable_OSC(dev);
1403 cx231xx_reset_out(dev);
1404 cx231xx_set_alt_setting(dev, INDEX_VIDEO, 3);
1405 }
1406
1407 if (dev->model == CX231XX_BOARD_CNXT_RDE_253S)
1408 cx231xx_sleep_s5h1432(dev);
1409
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001410 /* load other modules required */
1411 request_modules(dev);
1412
Sri Deevie0d3baf2009-03-03 14:37:50 -03001413 return 0;
Alexey Khoroshilov256d0132013-10-07 18:06:04 -03001414err_ts1_alt:
1415 kfree(dev->sliced_cc_mode.alt_max_pkt_size);
1416err_sliced_cc_alt:
1417 kfree(dev->vbi_mode.alt_max_pkt_size);
1418err_vbi_alt:
1419 kfree(dev->video_mode.alt_max_pkt_size);
1420err_video_alt:
1421 /* cx231xx_uninit_dev: */
1422 cx231xx_close_extension(dev);
1423 cx231xx_ir_exit(dev);
1424 cx231xx_release_analog_resources(dev);
1425 cx231xx_417_unregister(dev);
1426 cx231xx_remove_from_devlist(dev);
1427 cx231xx_dev_uninit(dev);
1428err_init:
1429 v4l2_device_unregister(&dev->v4l2_dev);
1430err_v4l2:
1431 usb_set_intfdata(interface, NULL);
1432err_if:
1433 usb_put_dev(udev);
Alexey Khoroshilov256d0132013-10-07 18:06:04 -03001434 clear_bit(dev->devno, &cx231xx_devused);
Dan Carpenter7e4b9182013-11-01 07:34:40 -03001435 kfree(dev);
Alexey Khoroshilov256d0132013-10-07 18:06:04 -03001436 return retval;
Sri Deevie0d3baf2009-03-03 14:37:50 -03001437}
1438
1439/*
1440 * cx231xx_usb_disconnect()
1441 * called when the device gets diconencted
1442 * video device will be unregistered on v4l2_close in case it is still open
1443 */
1444static void cx231xx_usb_disconnect(struct usb_interface *interface)
1445{
1446 struct cx231xx *dev;
1447
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -03001448 dev = usb_get_intfdata(interface);
Sri Deevie0d3baf2009-03-03 14:37:50 -03001449 usb_set_intfdata(interface, NULL);
1450
1451 if (!dev)
1452 return;
1453
Mauro Carvalho Chehab90960742009-03-22 07:52:02 -03001454 if (!dev->udev)
1455 return;
1456
Mauro Carvalho Chehab990862a2012-01-10 09:48:50 -02001457 dev->state |= DEV_DISCONNECTED;
Tejun Heo707bcf32010-12-24 16:14:20 +01001458
Sri Deevie0d3baf2009-03-03 14:37:50 -03001459 flush_request_modules(dev);
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -03001460
1461 /* wait until all current v4l2 io is finished then deallocate
Sri Deevie0d3baf2009-03-03 14:37:50 -03001462 resources */
1463 mutex_lock(&dev->lock);
1464
1465 wake_up_interruptible_all(&dev->open);
1466
1467 if (dev->users) {
1468 cx231xx_warn
Laurent Pinchart38c7c032009-11-27 13:57:15 -03001469 ("device %s is open! Deregistration and memory "
1470 "deallocation are deferred on close.\n",
1471 video_device_node_name(dev->vdev));
Sri Deevie0d3baf2009-03-03 14:37:50 -03001472
Mauro Carvalho Chehab7528cd22012-01-10 09:20:01 -02001473 /* Even having users, it is safe to remove the RC i2c driver */
1474 cx231xx_ir_exit(dev);
1475
Palash Bandyopadhyay64fbf442010-07-06 18:12:25 -03001476 if (dev->USE_ISO)
1477 cx231xx_uninit_isoc(dev);
1478 else
1479 cx231xx_uninit_bulk(dev);
Sri Deevie0d3baf2009-03-03 14:37:50 -03001480 wake_up_interruptible(&dev->wait_frame);
1481 wake_up_interruptible(&dev->wait_stream);
1482 } else {
Sri Deevie0d3baf2009-03-03 14:37:50 -03001483 }
1484
1485 cx231xx_close_extension(dev);
1486
1487 mutex_unlock(&dev->lock);
1488
Mauro Carvalho Chehab7528cd22012-01-10 09:20:01 -02001489 if (!dev->users)
1490 cx231xx_release_resources(dev);
Sri Deevie0d3baf2009-03-03 14:37:50 -03001491}
1492
1493static struct usb_driver cx231xx_usb_driver = {
1494 .name = "cx231xx",
1495 .probe = cx231xx_usb_probe,
1496 .disconnect = cx231xx_usb_disconnect,
1497 .id_table = cx231xx_id_table,
1498};
1499
Greg Kroah-Hartmanecb3b2b2011-11-18 09:46:12 -08001500module_usb_driver(cx231xx_usb_driver);