Version:  2.0.40 2.2.26 2.4.37 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 3.10 3.11 3.12 3.13 3.14 3.15 3.16 3.17

Linux/drivers/media/usb/cx231xx/cx231xx-cards.c

  1 /*
  2    cx231xx-cards.c - driver for Conexant Cx23100/101/102
  3                                 USB video capture devices
  4 
  5    Copyright (C) 2008 <srinivasa.deevi at conexant dot com>
  6                                 Based on em28xx driver
  7 
  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>
 25 #include <linux/slab.h>
 26 #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 
 33 #include <media/cx25840.h>
 34 #include "dvb-usb-ids.h"
 35 #include "xc5000.h"
 36 #include "tda18271.h"
 37 
 38 #include "cx231xx.h"
 39 
 40 static int tuner = -1;
 41 module_param(tuner, int, 0444);
 42 MODULE_PARM_DESC(tuner, "tuner type");
 43 
 44 static int transfer_mode = 1;
 45 module_param(transfer_mode, int, 0444);
 46 MODULE_PARM_DESC(transfer_mode, "transfer mode (1-ISO or 0-BULK)");
 47 
 48 static unsigned int disable_ir;
 49 module_param(disable_ir, int, 0444);
 50 MODULE_PARM_DESC(disable_ir, "disable infrared remote support");
 51 
 52 /* Bitmask marking allocated devices from 0 to CX231XX_MAXBOARDS */
 53 static unsigned long cx231xx_devused;
 54 
 55 /*
 56  *  Reset sequences for analog/digital modes
 57  */
 58 
 59 static struct cx231xx_reg_seq RDE250_XCV_TUNER[] = {
 60         {0x03, 0x01, 10},
 61         {0x03, 0x00, 30},
 62         {0x03, 0x01, 10},
 63         {-1, -1, -1},
 64 };
 65 
 66 /*
 67  *  Board definitions
 68  */
 69 struct cx231xx_board cx231xx_boards[] = {
 70         [CX231XX_BOARD_UNKNOWN] = {
 71                 .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,
 77                                 .gpio = NULL,
 78                         }, {
 79                                 .type = CX231XX_VMUX_COMPOSITE1,
 80                                 .vmux = CX231XX_VIN_2_1,
 81                                 .amux = CX231XX_AMUX_LINE_IN,
 82                                 .gpio = NULL,
 83                         }, {
 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,
 89                                 .gpio = NULL,
 90                         }
 91                 },
 92         },
 93         [CX231XX_BOARD_CNXT_CARRAERA] = {
 94                 .name = "Conexant Hybrid TV - CARRAERA",
 95                 .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,
102                 .output_mode = OUT_MODE_VIP11,
103                 .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,
112 
113                 .input = {{
114                                 .type = CX231XX_VMUX_TELEVISION,
115                                 .vmux = CX231XX_VIN_3_1,
116                                 .amux = CX231XX_AMUX_VIDEO,
117                                 .gpio = NULL,
118                         }, {
119                                 .type = CX231XX_VMUX_COMPOSITE1,
120                                 .vmux = CX231XX_VIN_2_1,
121                                 .amux = CX231XX_AMUX_LINE_IN,
122                                 .gpio = NULL,
123                         }, {
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,
129                                 .gpio = NULL,
130                         }
131                 },
132         },
133         [CX231XX_BOARD_CNXT_SHELBY] = {
134                 .name = "Conexant Hybrid TV - SHELBY",
135                 .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,
142                 .output_mode = OUT_MODE_VIP11,
143                 .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,
152 
153                 .input = {{
154                                 .type = CX231XX_VMUX_TELEVISION,
155                                 .vmux = CX231XX_VIN_3_1,
156                                 .amux = CX231XX_AMUX_VIDEO,
157                                 .gpio = NULL,
158                         }, {
159                                 .type = CX231XX_VMUX_COMPOSITE1,
160                                 .vmux = CX231XX_VIN_2_1,
161                                 .amux = CX231XX_AMUX_LINE_IN,
162                                 .gpio = NULL,
163                         }, {
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,
169                                 .gpio = NULL,
170                         }
171                 },
172         },
173         [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,
182                 .output_mode = OUT_MODE_VIP11,
183                 .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,
223                 .output_mode = OUT_MODE_VIP11,
224                 .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",
256                 .tuner_type = TUNER_ABSENT,
257                 .decoder = CX231XX_AVDECODER,
258                 .output_mode = OUT_MODE_VIP11,
259                 .ctl_pin_status_mask = 0xFFFFFFC4,
260                 .agc_analog_digital_select_gpio = 0x1c,
261                 .gpio_pin_status_mask = 0x4001000,
262                 .norm = V4L2_STD_PAL,
263                 .no_alt_vanc = 1,
264                 .external_av = 1,
265                 .dont_use_port_3 = 1,
266                 /* 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,
270 
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,
283                         }
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,
295                 .output_mode = OUT_MODE_VIP11,
296                 .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,
323                 .output_mode = OUT_MODE_VIP11,
324                 .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         },
342         [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,
351                 .output_mode = OUT_MODE_VIP11,
352                 .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,
366                         .gpio = NULL,
367                 }, {
368                         .type = CX231XX_VMUX_COMPOSITE1,
369                         .vmux = CX231XX_VIN_2_1,
370                         .amux = CX231XX_AMUX_LINE_IN,
371                         .gpio = NULL,
372                 }, {
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,
378                         .gpio = NULL,
379                 } },
380         },
381         [CX231XX_BOARD_HAUPPAUGE_USBLIVE2] = {
382                 .name = "Hauppauge USB Live 2",
383                 .tuner_type = TUNER_ABSENT,
384                 .decoder = CX231XX_AVDECODER,
385                 .output_mode = OUT_MODE_VIP11,
386                 .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,
391                 .no_alt_vanc = 1,
392                 .external_av = 1,
393                 .dont_use_port_3 = 1,
394                 .input = {{
395                         .type = CX231XX_VMUX_COMPOSITE1,
396                         .vmux = CX231XX_VIN_2_1,
397                         .amux = CX231XX_AMUX_LINE_IN,
398                         .gpio = NULL,
399                 }, {
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,
405                         .gpio = NULL,
406                 } },
407         },
408         [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         },
446         [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         },
484         [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,
499                 .ir_i2c_master = 2,
500                 .rc_map_name = RC_MAP_PIXELVIEW_002T,
501                 .has_dvb = 1,
502                 .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,
508                         .gpio = NULL,
509                 }, {
510                         .type = CX231XX_VMUX_COMPOSITE1,
511                         .vmux = CX231XX_VIN_2_1,
512                         .amux = CX231XX_AMUX_LINE_IN,
513                         .gpio = NULL,
514                 }, {
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,
520                         .gpio = NULL,
521                 } },
522         },
523         [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         },
552 
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         },
577         [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         },
647         [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         },
674         [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         },
707         [CX231XX_BOARD_HAUPPAUGE_930C_HD_1113xx] = {
708                 .name = "Hauppauge WinTV 930C-HD (1113xx) / PCTV QuatroStick 521e",
709                 .tuner_type = TUNER_NXP_TDA18271,
710                 .tuner_addr = 0x60,
711                 .tuner_gpio = RDE250_XCV_TUNER,
712                 .tuner_sif_gpio = 0x05,
713                 .tuner_scl_gpio = 0x1a,
714                 .tuner_sda_gpio = 0x1b,
715                 .decoder = CX231XX_AVDECODER,
716                 .output_mode = OUT_MODE_VIP11,
717                 .demod_xfer_mode = 0,
718                 .ctl_pin_status_mask = 0xFFFFFFC4,
719                 .agc_analog_digital_select_gpio = 0x0c,
720                 .gpio_pin_status_mask = 0x4001000,
721                 .tuner_i2c_master = 1,
722                 .demod_i2c_master = 2,
723                 .has_dvb = 1,
724                 .demod_addr = 0x0e,
725                 .norm = V4L2_STD_PAL,
726 
727                 .input = {{
728                         .type = CX231XX_VMUX_TELEVISION,
729                         .vmux = CX231XX_VIN_3_1,
730                         .amux = CX231XX_AMUX_VIDEO,
731                         .gpio = NULL,
732                 }, {
733                         .type = CX231XX_VMUX_COMPOSITE1,
734                         .vmux = CX231XX_VIN_2_1,
735                         .amux = CX231XX_AMUX_LINE_IN,
736                         .gpio = NULL,
737                 }, {
738                         .type = CX231XX_VMUX_SVIDEO,
739                         .vmux = CX231XX_VIN_1_1 |
740                                 (CX231XX_VIN_1_2 << 8) |
741                                 CX25840_SVIDEO_ON,
742                         .amux = CX231XX_AMUX_LINE_IN,
743                         .gpio = NULL,
744                 } },
745         },
746         [CX231XX_BOARD_HAUPPAUGE_930C_HD_1114xx] = {
747                 .name = "Hauppauge WinTV 930C-HD (1114xx) / PCTV QuatroStick 522e",
748                 .tuner_type = TUNER_ABSENT,
749                 .tuner_addr = 0x60,
750                 .tuner_gpio = RDE250_XCV_TUNER,
751                 .tuner_sif_gpio = 0x05,
752                 .tuner_scl_gpio = 0x1a,
753                 .tuner_sda_gpio = 0x1b,
754                 .decoder = CX231XX_AVDECODER,
755                 .output_mode = OUT_MODE_VIP11,
756                 .demod_xfer_mode = 0,
757                 .ctl_pin_status_mask = 0xFFFFFFC4,
758                 .agc_analog_digital_select_gpio = 0x0c,
759                 .gpio_pin_status_mask = 0x4001000,
760                 .tuner_i2c_master = 1,
761                 .demod_i2c_master = 2,
762                 .has_dvb = 1,
763                 .demod_addr = 0x0e,
764                 .norm = V4L2_STD_PAL,
765 
766                 .input = {{
767                         .type = CX231XX_VMUX_TELEVISION,
768                         .vmux = CX231XX_VIN_3_1,
769                         .amux = CX231XX_AMUX_VIDEO,
770                         .gpio = NULL,
771                 }, {
772                         .type = CX231XX_VMUX_COMPOSITE1,
773                         .vmux = CX231XX_VIN_2_1,
774                         .amux = CX231XX_AMUX_LINE_IN,
775                         .gpio = NULL,
776                 }, {
777                         .type = CX231XX_VMUX_SVIDEO,
778                         .vmux = CX231XX_VIN_1_1 |
779                                 (CX231XX_VIN_1_2 << 8) |
780                                 CX25840_SVIDEO_ON,
781                         .amux = CX231XX_AMUX_LINE_IN,
782                         .gpio = NULL,
783                 } },
784         },
785 };
786 const unsigned int cx231xx_bcount = ARRAY_SIZE(cx231xx_boards);
787 
788 /* table of devices that work with this driver */
789 struct usb_device_id cx231xx_id_table[] = {
790         {USB_DEVICE(0x1D19, 0x6109),
791         .driver_info = CX231XX_BOARD_PV_XCAPTURE_USB},
792         {USB_DEVICE(0x0572, 0x5A3C),
793          .driver_info = CX231XX_BOARD_UNKNOWN},
794         {USB_DEVICE(0x0572, 0x58A2),
795          .driver_info = CX231XX_BOARD_CNXT_CARRAERA},
796         {USB_DEVICE(0x0572, 0x58A1),
797          .driver_info = CX231XX_BOARD_CNXT_SHELBY},
798         {USB_DEVICE(0x0572, 0x58A4),
799          .driver_info = CX231XX_BOARD_CNXT_RDE_253S},
800         {USB_DEVICE(0x0572, 0x58A5),
801          .driver_info = CX231XX_BOARD_CNXT_RDU_253S},
802         {USB_DEVICE(0x0572, 0x58A6),
803          .driver_info = CX231XX_BOARD_CNXT_VIDEO_GRABBER},
804         {USB_DEVICE(0x0572, 0x589E),
805          .driver_info = CX231XX_BOARD_CNXT_RDE_250},
806         {USB_DEVICE(0x0572, 0x58A0),
807          .driver_info = CX231XX_BOARD_CNXT_RDU_250},
808         {USB_DEVICE(0x2040, 0xb110),
809          .driver_info = CX231XX_BOARD_HAUPPAUGE_USB2_FM_PAL},
810         {USB_DEVICE(0x2040, 0xb111),
811          .driver_info = CX231XX_BOARD_HAUPPAUGE_USB2_FM_NTSC},
812         {USB_DEVICE(0x2040, 0xb120),
813          .driver_info = CX231XX_BOARD_HAUPPAUGE_EXETER},
814         {USB_DEVICE(0x2040, 0xb130),
815          .driver_info = CX231XX_BOARD_HAUPPAUGE_930C_HD_1113xx},
816         {USB_DEVICE(0x2040, 0xb131),
817          .driver_info = CX231XX_BOARD_HAUPPAUGE_930C_HD_1114xx},
818         {USB_DEVICE(0x2040, 0xb140),
819          .driver_info = CX231XX_BOARD_HAUPPAUGE_EXETER},
820         {USB_DEVICE(0x2040, 0xc200),
821          .driver_info = CX231XX_BOARD_HAUPPAUGE_USBLIVE2},
822         /* PCTV QuatroStick 521e */
823         {USB_DEVICE(0x2013, 0x0259),
824          .driver_info = CX231XX_BOARD_HAUPPAUGE_930C_HD_1113xx},
825         /* PCTV QuatroStick 522e */
826         {USB_DEVICE(0x2013, 0x025e),
827          .driver_info = CX231XX_BOARD_HAUPPAUGE_930C_HD_1114xx},
828         {USB_DEVICE_VER(USB_VID_PIXELVIEW, USB_PID_PIXELVIEW_SBTVD, 0x4000, 0x4001),
829          .driver_info = CX231XX_BOARD_PV_PLAYTV_USB_HYBRID},
830         {USB_DEVICE(USB_VID_PIXELVIEW, 0x5014),
831          .driver_info = CX231XX_BOARD_PV_XCAPTURE_USB},
832         {USB_DEVICE(0x1b80, 0xe424),
833          .driver_info = CX231XX_BOARD_KWORLD_UB430_USB_HYBRID},
834         {USB_DEVICE(0x1b80, 0xe421),
835          .driver_info = CX231XX_BOARD_KWORLD_UB445_USB_HYBRID},
836         {USB_DEVICE(0x1f4d, 0x0237),
837          .driver_info = CX231XX_BOARD_ICONBIT_U100},
838         {USB_DEVICE(0x0fd9, 0x0037),
839          .driver_info = CX231XX_BOARD_ELGATO_VIDEO_CAPTURE_V2},
840         {USB_DEVICE(0x1f4d, 0x0102),
841          .driver_info = CX231XX_BOARD_OTG102},
842         {},
843 };
844 
845 MODULE_DEVICE_TABLE(usb, cx231xx_id_table);
846 
847 /* cx231xx_tuner_callback
848  * will be used to reset XC5000 tuner using GPIO pin
849  */
850 
851 int cx231xx_tuner_callback(void *ptr, int component, int command, int arg)
852 {
853         int rc = 0;
854         struct cx231xx *dev = ptr;
855 
856         if (dev->tuner_type == TUNER_XC5000) {
857                 if (command == XC5000_TUNER_RESET) {
858                         cx231xx_info
859                                 ("Tuner CB: RESET: cmd %d : tuner type %d \n",
860                                  command, dev->tuner_type);
861                         cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit,
862                                                1);
863                         msleep(10);
864                         cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit,
865                                                0);
866                         msleep(330);
867                         cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit,
868                                                1);
869                         msleep(10);
870                 }
871         } else if (dev->tuner_type == TUNER_NXP_TDA18271) {
872                 switch (command) {
873                 case TDA18271_CALLBACK_CMD_AGC_ENABLE:
874                         if (dev->model == CX231XX_BOARD_PV_PLAYTV_USB_HYBRID)
875                                 rc = cx231xx_set_agc_analog_digital_mux_select(dev, arg);
876                         break;
877                 default:
878                         rc = -EINVAL;
879                         break;
880                 }
881         }
882         return rc;
883 }
884 EXPORT_SYMBOL_GPL(cx231xx_tuner_callback);
885 
886 static void cx231xx_reset_out(struct cx231xx *dev)
887 {
888         cx231xx_set_gpio_value(dev, CX23417_RESET, 1);
889         msleep(200);
890         cx231xx_set_gpio_value(dev, CX23417_RESET, 0);
891         msleep(200);
892         cx231xx_set_gpio_value(dev, CX23417_RESET, 1);
893 }
894 
895 static void cx231xx_enable_OSC(struct cx231xx *dev)
896 {
897         cx231xx_set_gpio_value(dev, CX23417_OSC_EN, 1);
898 }
899 
900 static void cx231xx_sleep_s5h1432(struct cx231xx *dev)
901 {
902         cx231xx_set_gpio_value(dev, SLEEP_S5H1432, 0);
903 }
904 
905 static inline void cx231xx_set_model(struct cx231xx *dev)
906 {
907         dev->board = cx231xx_boards[dev->model];
908 }
909 
910 /* Since cx231xx_pre_card_setup() requires a proper dev->model,
911  * this won't work for boards with generic PCI IDs
912  */
913 void cx231xx_pre_card_setup(struct cx231xx *dev)
914 {
915 
916         cx231xx_set_model(dev);
917 
918         cx231xx_info("Identified as %s (card=%d)\n",
919                      dev->board.name, dev->model);
920 
921         /* set the direction for GPIO pins */
922         if (dev->board.tuner_gpio) {
923                 cx231xx_set_gpio_direction(dev, dev->board.tuner_gpio->bit, 1);
924                 cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit, 1);
925         }
926         if (dev->board.tuner_sif_gpio >= 0)
927                 cx231xx_set_gpio_direction(dev, dev->board.tuner_sif_gpio, 1);
928 
929         /* request some modules if any required */
930 
931         /* set the mode to Analog mode initially */
932         cx231xx_set_mode(dev, CX231XX_ANALOG_MODE);
933 
934         /* Unlock device */
935         /* cx231xx_set_mode(dev, CX231XX_SUSPEND); */
936 
937 }
938 
939 static void cx231xx_config_tuner(struct cx231xx *dev)
940 {
941         struct tuner_setup tun_setup;
942         struct v4l2_frequency f;
943 
944         if (dev->tuner_type == TUNER_ABSENT)
945                 return;
946 
947         tun_setup.mode_mask = T_ANALOG_TV | T_RADIO;
948         tun_setup.type = dev->tuner_type;
949         tun_setup.addr = dev->tuner_addr;
950         tun_setup.tuner_callback = cx231xx_tuner_callback;
951 
952         tuner_call(dev, tuner, s_type_addr, &tun_setup);
953 
954 #if 0
955         if (tun_setup.type == TUNER_XC5000) {
956                 static struct xc2028_ctrl ctrl = {
957                         .fname = XC5000_DEFAULT_FIRMWARE,
958                         .max_len = 64,
959                         .demod = 0;
960                 };
961                 struct v4l2_priv_tun_config cfg = {
962                         .tuner = dev->tuner_type,
963                         .priv = &ctrl,
964                 };
965                 tuner_call(dev, tuner, s_config, &cfg);
966         }
967 #endif
968         /* configure tuner */
969         f.tuner = 0;
970         f.type = V4L2_TUNER_ANALOG_TV;
971         f.frequency = 9076;     /* just a magic number */
972         dev->ctl_freq = f.frequency;
973         call_all(dev, tuner, s_frequency, &f);
974 
975 }
976 
977 static int read_eeprom(struct cx231xx *dev, u8 *eedata, int len)
978 {
979         int ret = 0;
980         u8 addr = 0xa0 >> 1;
981         u8 start_offset = 0;
982         int len_todo = len;
983         u8 *eedata_cur = eedata;
984         int i;
985         struct i2c_msg msg_write = { .addr = addr, .flags = 0,
986                 .buf = &start_offset, .len = 1 };
987         struct i2c_msg msg_read = { .addr = addr, .flags = I2C_M_RD };
988 
989         /* mutex_lock(&dev->i2c_lock); */
990         cx231xx_enable_i2c_port_3(dev, false);
991 
992         /* start reading at offset 0 */
993         ret = i2c_transfer(&dev->i2c_bus[1].i2c_adap, &msg_write, 1);
994         if (ret < 0) {
995                 cx231xx_err("Can't read eeprom\n");
996                 return ret;
997         }
998 
999         while (len_todo > 0) {
1000                 msg_read.len = (len_todo > 64) ? 64 : len_todo;
1001                 msg_read.buf = eedata_cur;
1002 
1003                 ret = i2c_transfer(&dev->i2c_bus[1].i2c_adap, &msg_read, 1);
1004                 if (ret < 0) {
1005                         cx231xx_err("Can't read eeprom\n");
1006                         return ret;
1007                 }
1008                 eedata_cur += msg_read.len;
1009                 len_todo -= msg_read.len;
1010         }
1011 
1012         cx231xx_enable_i2c_port_3(dev, true);
1013         /* mutex_unlock(&dev->i2c_lock); */
1014 
1015         for (i = 0; i + 15 < len; i += 16)
1016                 cx231xx_info("i2c eeprom %02x: %*ph\n", i, 16, &eedata[i]);
1017 
1018         return 0;
1019 }
1020 
1021 void cx231xx_card_setup(struct cx231xx *dev)
1022 {
1023 
1024         cx231xx_set_model(dev);
1025 
1026         dev->tuner_type = cx231xx_boards[dev->model].tuner_type;
1027         if (cx231xx_boards[dev->model].tuner_addr)
1028                 dev->tuner_addr = cx231xx_boards[dev->model].tuner_addr;
1029 
1030         /* request some modules */
1031         if (dev->board.decoder == CX231XX_AVDECODER) {
1032                 dev->sd_cx25840 = v4l2_i2c_new_subdev(&dev->v4l2_dev,
1033                                         &dev->i2c_bus[0].i2c_adap,
1034                                         "cx25840", 0x88 >> 1, NULL);
1035                 if (dev->sd_cx25840 == NULL)
1036                         cx231xx_info("cx25840 subdev registration failure\n");
1037                 cx25840_call(dev, core, load_fw);
1038 
1039         }
1040 
1041         /* Initialize the tuner */
1042         if (dev->board.tuner_type != TUNER_ABSENT) {
1043                 dev->sd_tuner = v4l2_i2c_new_subdev(&dev->v4l2_dev,
1044                                                     &dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap,
1045                                                     "tuner",
1046                                                     dev->tuner_addr, NULL);
1047                 if (dev->sd_tuner == NULL)
1048                         cx231xx_info("tuner subdev registration failure\n");
1049                 else
1050                         cx231xx_config_tuner(dev);
1051         }
1052 
1053         switch (dev->model) {
1054         case CX231XX_BOARD_HAUPPAUGE_930C_HD_1113xx:
1055         case CX231XX_BOARD_HAUPPAUGE_930C_HD_1114xx:
1056                 {
1057                         struct tveeprom tvee;
1058                         static u8 eeprom[256];
1059 
1060                         read_eeprom(dev, eeprom, sizeof(eeprom));
1061                         tveeprom_hauppauge_analog(&dev->i2c_bus[1].i2c_client,
1062                                                 &tvee, eeprom + 0xc0);
1063                         break;
1064                 }
1065         }
1066 
1067 }
1068 
1069 /*
1070  * cx231xx_config()
1071  * inits registers with sane defaults
1072  */
1073 int cx231xx_config(struct cx231xx *dev)
1074 {
1075         /* TBD need to add cx231xx specific code */
1076 
1077         return 0;
1078 }
1079 
1080 /*
1081  * cx231xx_config_i2c()
1082  * configure i2c attached devices
1083  */
1084 void cx231xx_config_i2c(struct cx231xx *dev)
1085 {
1086         /* u32 input = INPUT(dev->video_input)->vmux; */
1087 
1088         call_all(dev, video, s_stream, 1);
1089 }
1090 
1091 /*
1092  * cx231xx_realease_resources()
1093  * unregisters the v4l2,i2c and usb devices
1094  * called when the device gets disconected or at module unload
1095 */
1096 void cx231xx_release_resources(struct cx231xx *dev)
1097 {
1098         cx231xx_release_analog_resources(dev);
1099 
1100         cx231xx_remove_from_devlist(dev);
1101 
1102         cx231xx_ir_exit(dev);
1103 
1104         /* Release I2C buses */
1105         cx231xx_dev_uninit(dev);
1106 
1107         /* delete v4l2 device */
1108         v4l2_device_unregister(&dev->v4l2_dev);
1109 
1110         usb_put_dev(dev->udev);
1111 
1112         /* Mark device as unused */
1113         clear_bit(dev->devno, &cx231xx_devused);
1114 }
1115 
1116 /*
1117  * cx231xx_init_dev()
1118  * allocates and inits the device structs, registers i2c bus and v4l device
1119  */
1120 static int cx231xx_init_dev(struct cx231xx *dev, struct usb_device *udev,
1121                             int minor)
1122 {
1123         int retval = -ENOMEM;
1124         unsigned int maxh, maxw;
1125 
1126         dev->udev = udev;
1127         mutex_init(&dev->lock);
1128         mutex_init(&dev->ctrl_urb_lock);
1129         mutex_init(&dev->gpio_i2c_lock);
1130         mutex_init(&dev->i2c_lock);
1131 
1132         spin_lock_init(&dev->video_mode.slock);
1133         spin_lock_init(&dev->vbi_mode.slock);
1134         spin_lock_init(&dev->sliced_cc_mode.slock);
1135 
1136         init_waitqueue_head(&dev->open);
1137         init_waitqueue_head(&dev->wait_frame);
1138         init_waitqueue_head(&dev->wait_stream);
1139 
1140         dev->cx231xx_read_ctrl_reg = cx231xx_read_ctrl_reg;
1141         dev->cx231xx_write_ctrl_reg = cx231xx_write_ctrl_reg;
1142         dev->cx231xx_send_usb_command = cx231xx_send_usb_command;
1143         dev->cx231xx_gpio_i2c_read = cx231xx_gpio_i2c_read;
1144         dev->cx231xx_gpio_i2c_write = cx231xx_gpio_i2c_write;
1145 
1146         /* Query cx231xx to find what pcb config it is related to */
1147         retval = initialize_cx231xx(dev);
1148         if (retval < 0) {
1149                 cx231xx_errdev("Failed to read PCB config\n");
1150                 return retval;
1151         }
1152 
1153         /*To workaround error number=-71 on EP0 for VideoGrabber,
1154                  need set alt here.*/
1155         if (dev->model == CX231XX_BOARD_CNXT_VIDEO_GRABBER ||
1156             dev->model == CX231XX_BOARD_HAUPPAUGE_USBLIVE2) {
1157                 cx231xx_set_alt_setting(dev, INDEX_VIDEO, 3);
1158                 cx231xx_set_alt_setting(dev, INDEX_VANC, 1);
1159         }
1160         /* Cx231xx pre card setup */
1161         cx231xx_pre_card_setup(dev);
1162 
1163         retval = cx231xx_config(dev);
1164         if (retval) {
1165                 cx231xx_errdev("error configuring device\n");
1166                 return -ENOMEM;
1167         }
1168 
1169         /* set default norm */
1170         dev->norm = dev->board.norm;
1171 
1172         /* register i2c bus */
1173         retval = cx231xx_dev_init(dev);
1174         if (retval) {
1175                 cx231xx_errdev("%s: cx231xx_i2c_register - errCode [%d]!\n",
1176                                __func__, retval);
1177                 goto err_dev_init;
1178         }
1179 
1180         /* Do board specific init */
1181         cx231xx_card_setup(dev);
1182 
1183         /* configure the device */
1184         cx231xx_config_i2c(dev);
1185 
1186         maxw = norm_maxw(dev);
1187         maxh = norm_maxh(dev);
1188 
1189         /* set default image size */
1190         dev->width = maxw;
1191         dev->height = maxh;
1192         dev->interlaced = 0;
1193         dev->video_input = 0;
1194 
1195         retval = cx231xx_config(dev);
1196         if (retval) {
1197                 cx231xx_errdev("%s: cx231xx_config - errCode [%d]!\n",
1198                                __func__, retval);
1199                 goto err_dev_init;
1200         }
1201 
1202         /* init video dma queues */
1203         INIT_LIST_HEAD(&dev->video_mode.vidq.active);
1204         INIT_LIST_HEAD(&dev->video_mode.vidq.queued);
1205 
1206         /* init vbi dma queues */
1207         INIT_LIST_HEAD(&dev->vbi_mode.vidq.active);
1208         INIT_LIST_HEAD(&dev->vbi_mode.vidq.queued);
1209 
1210         /* Reset other chips required if they are tied up with GPIO pins */
1211         cx231xx_add_into_devlist(dev);
1212 
1213         if (dev->board.has_417) {
1214                 printk(KERN_INFO "attach 417 %d\n", dev->model);
1215                 if (cx231xx_417_register(dev) < 0) {
1216                         printk(KERN_ERR
1217                                 "%s() Failed to register 417 on VID_B\n",
1218                                __func__);
1219                 }
1220         }
1221 
1222         retval = cx231xx_register_analog_devices(dev);
1223         if (retval) {
1224                 cx231xx_release_analog_resources(dev);
1225                 goto err_analog;
1226         }
1227 
1228         cx231xx_ir_init(dev);
1229 
1230         cx231xx_init_extension(dev);
1231 
1232         return 0;
1233 err_analog:
1234         cx231xx_remove_from_devlist(dev);
1235 err_dev_init:
1236         cx231xx_dev_uninit(dev);
1237         return retval;
1238 }
1239 
1240 #if defined(CONFIG_MODULES) && defined(MODULE)
1241 static void request_module_async(struct work_struct *work)
1242 {
1243         struct cx231xx *dev = container_of(work,
1244                                            struct cx231xx, request_module_wk);
1245 
1246         if (dev->has_alsa_audio)
1247                 request_module("cx231xx-alsa");
1248 
1249         if (dev->board.has_dvb)
1250                 request_module("cx231xx-dvb");
1251 
1252 }
1253 
1254 static void request_modules(struct cx231xx *dev)
1255 {
1256         INIT_WORK(&dev->request_module_wk, request_module_async);
1257         schedule_work(&dev->request_module_wk);
1258 }
1259 
1260 static void flush_request_modules(struct cx231xx *dev)
1261 {
1262         flush_work(&dev->request_module_wk);
1263 }
1264 #else
1265 #define request_modules(dev)
1266 #define flush_request_modules(dev)
1267 #endif /* CONFIG_MODULES */
1268 
1269 static int cx231xx_init_v4l2(struct cx231xx *dev,
1270                              struct usb_device *udev,
1271                              struct usb_interface *interface,
1272                              int isoc_pipe)
1273 {
1274         struct usb_interface *uif;
1275         int i, idx;
1276 
1277         /* Video Init */
1278 
1279         /* compute alternate max packet sizes for video */
1280         idx = dev->current_pcb_config.hs_config_info[0].interface_info.video_index + 1;
1281         if (idx >= dev->max_iad_interface_count) {
1282                 cx231xx_errdev("Video PCB interface #%d doesn't exist\n", idx);
1283                 return -ENODEV;
1284         }
1285 
1286         uif = udev->actconfig->interface[idx];
1287 
1288         dev->video_mode.end_point_addr = uif->altsetting[0].endpoint[isoc_pipe].desc.bEndpointAddress;
1289         dev->video_mode.num_alt = uif->num_altsetting;
1290 
1291         cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
1292                      dev->video_mode.end_point_addr,
1293                      dev->video_mode.num_alt);
1294 
1295         dev->video_mode.alt_max_pkt_size = devm_kmalloc_array(&udev->dev, 32, dev->video_mode.num_alt, GFP_KERNEL);
1296         if (dev->video_mode.alt_max_pkt_size == NULL) {
1297                 cx231xx_errdev("out of memory!\n");
1298                 return -ENOMEM;
1299         }
1300 
1301         for (i = 0; i < dev->video_mode.num_alt; i++) {
1302                 u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].desc.wMaxPacketSize);
1303                 dev->video_mode.alt_max_pkt_size[i] = (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
1304                 cx231xx_info("Alternate setting %i, max size= %i\n", i,
1305                              dev->video_mode.alt_max_pkt_size[i]);
1306         }
1307 
1308         /* VBI Init */
1309 
1310         idx = dev->current_pcb_config.hs_config_info[0].interface_info.vanc_index + 1;
1311         if (idx >= dev->max_iad_interface_count) {
1312                 cx231xx_errdev("VBI PCB interface #%d doesn't exist\n", idx);
1313                 return -ENODEV;
1314         }
1315         uif = udev->actconfig->interface[idx];
1316 
1317         dev->vbi_mode.end_point_addr =
1318             uif->altsetting[0].endpoint[isoc_pipe].desc.
1319                         bEndpointAddress;
1320 
1321         dev->vbi_mode.num_alt = uif->num_altsetting;
1322         cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
1323                      dev->vbi_mode.end_point_addr,
1324                      dev->vbi_mode.num_alt);
1325 
1326         /* compute alternate max packet sizes for vbi */
1327         dev->vbi_mode.alt_max_pkt_size = devm_kmalloc_array(&udev->dev, 32, dev->vbi_mode.num_alt, GFP_KERNEL);
1328         if (dev->vbi_mode.alt_max_pkt_size == NULL) {
1329                 cx231xx_errdev("out of memory!\n");
1330                 return -ENOMEM;
1331         }
1332 
1333         for (i = 0; i < dev->vbi_mode.num_alt; i++) {
1334                 u16 tmp =
1335                     le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
1336                                 desc.wMaxPacketSize);
1337                 dev->vbi_mode.alt_max_pkt_size[i] =
1338                     (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
1339                 cx231xx_info("Alternate setting %i, max size= %i\n", i,
1340                              dev->vbi_mode.alt_max_pkt_size[i]);
1341         }
1342 
1343         /* Sliced CC VBI init */
1344 
1345         /* compute alternate max packet sizes for sliced CC */
1346         idx = dev->current_pcb_config.hs_config_info[0].interface_info.hanc_index + 1;
1347         if (idx >= dev->max_iad_interface_count) {
1348                 cx231xx_errdev("Sliced CC PCB interface #%d doesn't exist\n", idx);
1349                 return -ENODEV;
1350         }
1351         uif = udev->actconfig->interface[idx];
1352 
1353         dev->sliced_cc_mode.end_point_addr =
1354             uif->altsetting[0].endpoint[isoc_pipe].desc.
1355                         bEndpointAddress;
1356 
1357         dev->sliced_cc_mode.num_alt = uif->num_altsetting;
1358         cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
1359                      dev->sliced_cc_mode.end_point_addr,
1360                      dev->sliced_cc_mode.num_alt);
1361         dev->sliced_cc_mode.alt_max_pkt_size = devm_kmalloc_array(&udev->dev, 32, dev->sliced_cc_mode.num_alt, GFP_KERNEL);
1362 
1363         if (dev->sliced_cc_mode.alt_max_pkt_size == NULL) {
1364                 cx231xx_errdev("out of memory!\n");
1365                 return -ENOMEM;
1366         }
1367 
1368         for (i = 0; i < dev->sliced_cc_mode.num_alt; i++) {
1369                 u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
1370                                 desc.wMaxPacketSize);
1371                 dev->sliced_cc_mode.alt_max_pkt_size[i] =
1372                     (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
1373                 cx231xx_info("Alternate setting %i, max size= %i\n", i,
1374                              dev->sliced_cc_mode.alt_max_pkt_size[i]);
1375         }
1376 
1377         return 0;
1378 }
1379 
1380 /*
1381  * cx231xx_usb_probe()
1382  * checks for supported devices
1383  */
1384 static int cx231xx_usb_probe(struct usb_interface *interface,
1385                              const struct usb_device_id *id)
1386 {
1387         struct usb_device *udev;
1388         struct usb_interface *uif;
1389         struct cx231xx *dev = NULL;
1390         int retval = -ENODEV;
1391         int nr = 0, ifnum;
1392         int i, isoc_pipe = 0;
1393         char *speed;
1394         u8 idx;
1395         struct usb_interface_assoc_descriptor *assoc_desc;
1396 
1397         ifnum = interface->altsetting[0].desc.bInterfaceNumber;
1398 
1399         /*
1400          * Interface number 0 - IR interface (handled by mceusb driver)
1401          * Interface number 1 - AV interface (handled by this driver)
1402          */
1403         if (ifnum != 1)
1404                 return -ENODEV;
1405 
1406         /* Check to see next free device and mark as used */
1407         do {
1408                 nr = find_first_zero_bit(&cx231xx_devused, CX231XX_MAXBOARDS);
1409                 if (nr >= CX231XX_MAXBOARDS) {
1410                         /* No free device slots */
1411                         cx231xx_err(DRIVER_NAME ": Supports only %i devices.\n",
1412                                         CX231XX_MAXBOARDS);
1413                         return -ENOMEM;
1414                 }
1415         } while (test_and_set_bit(nr, &cx231xx_devused));
1416 
1417         udev = usb_get_dev(interface_to_usbdev(interface));
1418 
1419         /* allocate memory for our device state and initialize it */
1420         dev = devm_kzalloc(&udev->dev, sizeof(*dev), GFP_KERNEL);
1421         if (dev == NULL) {
1422                 cx231xx_err(DRIVER_NAME ": out of memory!\n");
1423                 clear_bit(nr, &cx231xx_devused);
1424                 return -ENOMEM;
1425         }
1426 
1427         snprintf(dev->name, 29, "cx231xx #%d", nr);
1428         dev->devno = nr;
1429         dev->model = id->driver_info;
1430         dev->video_mode.alt = -1;
1431 
1432         dev->interface_count++;
1433         /* reset gpio dir and value */
1434         dev->gpio_dir = 0;
1435         dev->gpio_val = 0;
1436         dev->xc_fw_load_done = 0;
1437         dev->has_alsa_audio = 1;
1438         dev->power_mode = -1;
1439         atomic_set(&dev->devlist_count, 0);
1440 
1441         /* 0 - vbi ; 1 -sliced cc mode */
1442         dev->vbi_or_sliced_cc_mode = 0;
1443 
1444         /* get maximum no.of IAD interfaces */
1445         dev->max_iad_interface_count = udev->config->desc.bNumInterfaces;
1446 
1447         /* init CIR module TBD */
1448 
1449         /*mode_tv: digital=1 or analog=0*/
1450         dev->mode_tv = 0;
1451 
1452         dev->USE_ISO = transfer_mode;
1453 
1454         switch (udev->speed) {
1455         case USB_SPEED_LOW:
1456                 speed = "1.5";
1457                 break;
1458         case USB_SPEED_UNKNOWN:
1459         case USB_SPEED_FULL:
1460                 speed = "12";
1461                 break;
1462         case USB_SPEED_HIGH:
1463                 speed = "480";
1464                 break;
1465         default:
1466                 speed = "unknown";
1467         }
1468 
1469         cx231xx_info("New device %s %s @ %s Mbps "
1470              "(%04x:%04x) with %d interfaces\n",
1471              udev->manufacturer ? udev->manufacturer : "",
1472              udev->product ? udev->product : "",
1473              speed,
1474              le16_to_cpu(udev->descriptor.idVendor),
1475              le16_to_cpu(udev->descriptor.idProduct),
1476              dev->max_iad_interface_count);
1477 
1478         /* increment interface count */
1479         dev->interface_count++;
1480 
1481         /* get device number */
1482         nr = dev->devno;
1483 
1484         assoc_desc = udev->actconfig->intf_assoc[0];
1485         if (assoc_desc->bFirstInterface != ifnum) {
1486                 cx231xx_err(DRIVER_NAME ": Not found "
1487                             "matching IAD interface\n");
1488                 retval = -ENODEV;
1489                 goto err_if;
1490         }
1491 
1492         cx231xx_info("registering interface %d\n", ifnum);
1493 
1494         /* save our data pointer in this interface device */
1495         usb_set_intfdata(interface, dev);
1496 
1497         /* Create v4l2 device */
1498         retval = v4l2_device_register(&interface->dev, &dev->v4l2_dev);
1499         if (retval) {
1500                 cx231xx_errdev("v4l2_device_register failed\n");
1501                 goto err_v4l2;
1502         }
1503 
1504         /* allocate device struct */
1505         retval = cx231xx_init_dev(dev, udev, nr);
1506         if (retval)
1507                 goto err_init;
1508 
1509         retval = cx231xx_init_v4l2(dev, udev, interface, isoc_pipe);
1510         if (retval)
1511                 goto err_init;
1512 
1513         if (dev->current_pcb_config.ts1_source != 0xff) {
1514                 /* compute alternate max packet sizes for TS1 */
1515                 idx = dev->current_pcb_config.hs_config_info[0].interface_info.ts1_index + 1;
1516                 if (idx >= dev->max_iad_interface_count) {
1517                         cx231xx_errdev("TS1 PCB interface #%d doesn't exist\n", idx);
1518                         retval = -ENODEV;
1519                         goto err_video_alt;
1520                 }
1521                 uif = udev->actconfig->interface[idx];
1522 
1523                 dev->ts1_mode.end_point_addr =
1524                     uif->altsetting[0].endpoint[isoc_pipe].
1525                                 desc.bEndpointAddress;
1526 
1527                 dev->ts1_mode.num_alt = uif->num_altsetting;
1528                 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
1529                              dev->ts1_mode.end_point_addr,
1530                              dev->ts1_mode.num_alt);
1531 
1532                 dev->ts1_mode.alt_max_pkt_size = devm_kmalloc_array(&udev->dev, 32, dev->ts1_mode.num_alt, GFP_KERNEL);
1533                 if (dev->ts1_mode.alt_max_pkt_size == NULL) {
1534                         cx231xx_errdev("out of memory!\n");
1535                         retval = -ENOMEM;
1536                         goto err_video_alt;
1537                 }
1538 
1539                 for (i = 0; i < dev->ts1_mode.num_alt; i++) {
1540                         u16 tmp = le16_to_cpu(uif->altsetting[i].
1541                                                 endpoint[isoc_pipe].desc.
1542                                                 wMaxPacketSize);
1543                         dev->ts1_mode.alt_max_pkt_size[i] =
1544                             (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
1545                         cx231xx_info("Alternate setting %i, max size= %i\n", i,
1546                                      dev->ts1_mode.alt_max_pkt_size[i]);
1547                 }
1548         }
1549 
1550         if (dev->model == CX231XX_BOARD_CNXT_VIDEO_GRABBER) {
1551                 cx231xx_enable_OSC(dev);
1552                 cx231xx_reset_out(dev);
1553                 cx231xx_set_alt_setting(dev, INDEX_VIDEO, 3);
1554         }
1555 
1556         if (dev->model == CX231XX_BOARD_CNXT_RDE_253S)
1557                 cx231xx_sleep_s5h1432(dev);
1558 
1559         /* load other modules required */
1560         request_modules(dev);
1561 
1562         return 0;
1563 err_video_alt:
1564         /* cx231xx_uninit_dev: */
1565         cx231xx_close_extension(dev);
1566         cx231xx_ir_exit(dev);
1567         cx231xx_release_analog_resources(dev);
1568         cx231xx_417_unregister(dev);
1569         cx231xx_remove_from_devlist(dev);
1570         cx231xx_dev_uninit(dev);
1571 err_init:
1572         v4l2_device_unregister(&dev->v4l2_dev);
1573 err_v4l2:
1574         usb_set_intfdata(interface, NULL);
1575 err_if:
1576         usb_put_dev(udev);
1577         clear_bit(dev->devno, &cx231xx_devused);
1578         return retval;
1579 }
1580 
1581 /*
1582  * cx231xx_usb_disconnect()
1583  * called when the device gets diconencted
1584  * video device will be unregistered on v4l2_close in case it is still open
1585  */
1586 static void cx231xx_usb_disconnect(struct usb_interface *interface)
1587 {
1588         struct cx231xx *dev;
1589 
1590         dev = usb_get_intfdata(interface);
1591         usb_set_intfdata(interface, NULL);
1592 
1593         if (!dev)
1594                 return;
1595 
1596         if (!dev->udev)
1597                 return;
1598 
1599         dev->state |= DEV_DISCONNECTED;
1600 
1601         flush_request_modules(dev);
1602 
1603         /* wait until all current v4l2 io is finished then deallocate
1604            resources */
1605         mutex_lock(&dev->lock);
1606 
1607         wake_up_interruptible_all(&dev->open);
1608 
1609         if (dev->users) {
1610                 cx231xx_warn
1611                     ("device %s is open! Deregistration and memory "
1612                      "deallocation are deferred on close.\n",
1613                      video_device_node_name(dev->vdev));
1614 
1615                 /* Even having users, it is safe to remove the RC i2c driver */
1616                 cx231xx_ir_exit(dev);
1617 
1618                 if (dev->USE_ISO)
1619                         cx231xx_uninit_isoc(dev);
1620                 else
1621                         cx231xx_uninit_bulk(dev);
1622                 wake_up_interruptible(&dev->wait_frame);
1623                 wake_up_interruptible(&dev->wait_stream);
1624         } else {
1625         }
1626 
1627         cx231xx_close_extension(dev);
1628 
1629         mutex_unlock(&dev->lock);
1630 
1631         if (!dev->users)
1632                 cx231xx_release_resources(dev);
1633 }
1634 
1635 static struct usb_driver cx231xx_usb_driver = {
1636         .name = "cx231xx",
1637         .probe = cx231xx_usb_probe,
1638         .disconnect = cx231xx_usb_disconnect,
1639         .id_table = cx231xx_id_table,
1640 };
1641 
1642 module_usb_driver(cx231xx_usb_driver);
1643 

This page was automatically generated by LXR 0.3.1 (source).  •  Linux is a registered trademark of Linus Torvalds  •  Contact us