Version:  2.0.40 2.2.26 2.4.37 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 3.18 3.19 4.0 4.1

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 "cx231xx.h"
 24 #include <linux/init.h>
 25 #include <linux/module.h>
 26 #include <linux/slab.h>
 27 #include <linux/delay.h>
 28 #include <linux/i2c.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 
 39 static int tuner = -1;
 40 module_param(tuner, int, 0444);
 41 MODULE_PARM_DESC(tuner, "tuner type");
 42 
 43 static int transfer_mode = 1;
 44 module_param(transfer_mode, int, 0444);
 45 MODULE_PARM_DESC(transfer_mode, "transfer mode (1-ISO or 0-BULK)");
 46 
 47 static unsigned int disable_ir;
 48 module_param(disable_ir, int, 0444);
 49 MODULE_PARM_DESC(disable_ir, "disable infrared remote support");
 50 
 51 /* Bitmask marking allocated devices from 0 to CX231XX_MAXBOARDS */
 52 static unsigned long cx231xx_devused;
 53 
 54 /*
 55  *  Reset sequences for analog/digital modes
 56  */
 57 
 58 static struct cx231xx_reg_seq RDE250_XCV_TUNER[] = {
 59         {0x03, 0x01, 10},
 60         {0x03, 0x00, 30},
 61         {0x03, 0x01, 10},
 62         {-1, -1, -1},
 63 };
 64 
 65 /*
 66  *  Board definitions
 67  */
 68 struct cx231xx_board cx231xx_boards[] = {
 69         [CX231XX_BOARD_UNKNOWN] = {
 70                 .name = "Unknown CX231xx video grabber",
 71                 .tuner_type = TUNER_ABSENT,
 72                 .input = {{
 73                                 .type = CX231XX_VMUX_TELEVISION,
 74                                 .vmux = CX231XX_VIN_3_1,
 75                                 .amux = CX231XX_AMUX_VIDEO,
 76                                 .gpio = NULL,
 77                         }, {
 78                                 .type = CX231XX_VMUX_COMPOSITE1,
 79                                 .vmux = CX231XX_VIN_2_1,
 80                                 .amux = CX231XX_AMUX_LINE_IN,
 81                                 .gpio = NULL,
 82                         }, {
 83                                 .type = CX231XX_VMUX_SVIDEO,
 84                                 .vmux = CX231XX_VIN_1_1 |
 85                                         (CX231XX_VIN_1_2 << 8) |
 86                                         CX25840_SVIDEO_ON,
 87                                 .amux = CX231XX_AMUX_LINE_IN,
 88                                 .gpio = NULL,
 89                         }
 90                 },
 91         },
 92         [CX231XX_BOARD_CNXT_CARRAERA] = {
 93                 .name = "Conexant Hybrid TV - CARRAERA",
 94                 .tuner_type = TUNER_XC5000,
 95                 .tuner_addr = 0x61,
 96                 .tuner_gpio = RDE250_XCV_TUNER,
 97                 .tuner_sif_gpio = 0x05,
 98                 .tuner_scl_gpio = 0x1a,
 99                 .tuner_sda_gpio = 0x1b,
100                 .decoder = CX231XX_AVDECODER,
101                 .output_mode = OUT_MODE_VIP11,
102                 .demod_xfer_mode = 0,
103                 .ctl_pin_status_mask = 0xFFFFFFC4,
104                 .agc_analog_digital_select_gpio = 0x0c,
105                 .gpio_pin_status_mask = 0x4001000,
106                 .tuner_i2c_master = I2C_1_MUX_3,
107                 .demod_i2c_master = I2C_2,
108                 .has_dvb = 1,
109                 .demod_addr = 0x02,
110                 .norm = V4L2_STD_PAL,
111 
112                 .input = {{
113                                 .type = CX231XX_VMUX_TELEVISION,
114                                 .vmux = CX231XX_VIN_3_1,
115                                 .amux = CX231XX_AMUX_VIDEO,
116                                 .gpio = NULL,
117                         }, {
118                                 .type = CX231XX_VMUX_COMPOSITE1,
119                                 .vmux = CX231XX_VIN_2_1,
120                                 .amux = CX231XX_AMUX_LINE_IN,
121                                 .gpio = NULL,
122                         }, {
123                                 .type = CX231XX_VMUX_SVIDEO,
124                                 .vmux = CX231XX_VIN_1_1 |
125                                         (CX231XX_VIN_1_2 << 8) |
126                                         CX25840_SVIDEO_ON,
127                                 .amux = CX231XX_AMUX_LINE_IN,
128                                 .gpio = NULL,
129                         }
130                 },
131         },
132         [CX231XX_BOARD_CNXT_SHELBY] = {
133                 .name = "Conexant Hybrid TV - SHELBY",
134                 .tuner_type = TUNER_XC5000,
135                 .tuner_addr = 0x61,
136                 .tuner_gpio = RDE250_XCV_TUNER,
137                 .tuner_sif_gpio = 0x05,
138                 .tuner_scl_gpio = 0x1a,
139                 .tuner_sda_gpio = 0x1b,
140                 .decoder = CX231XX_AVDECODER,
141                 .output_mode = OUT_MODE_VIP11,
142                 .demod_xfer_mode = 0,
143                 .ctl_pin_status_mask = 0xFFFFFFC4,
144                 .agc_analog_digital_select_gpio = 0x0c,
145                 .gpio_pin_status_mask = 0x4001000,
146                 .tuner_i2c_master = I2C_1_MUX_3,
147                 .demod_i2c_master = I2C_2,
148                 .has_dvb = 1,
149                 .demod_addr = 0x32,
150                 .norm = V4L2_STD_NTSC,
151 
152                 .input = {{
153                                 .type = CX231XX_VMUX_TELEVISION,
154                                 .vmux = CX231XX_VIN_3_1,
155                                 .amux = CX231XX_AMUX_VIDEO,
156                                 .gpio = NULL,
157                         }, {
158                                 .type = CX231XX_VMUX_COMPOSITE1,
159                                 .vmux = CX231XX_VIN_2_1,
160                                 .amux = CX231XX_AMUX_LINE_IN,
161                                 .gpio = NULL,
162                         }, {
163                                 .type = CX231XX_VMUX_SVIDEO,
164                                 .vmux = CX231XX_VIN_1_1 |
165                                         (CX231XX_VIN_1_2 << 8) |
166                                         CX25840_SVIDEO_ON,
167                                 .amux = CX231XX_AMUX_LINE_IN,
168                                 .gpio = NULL,
169                         }
170                 },
171         },
172         [CX231XX_BOARD_CNXT_RDE_253S] = {
173                 .name = "Conexant Hybrid TV - RDE253S",
174                 .tuner_type = TUNER_NXP_TDA18271,
175                 .tuner_addr = 0x60,
176                 .tuner_gpio = RDE250_XCV_TUNER,
177                 .tuner_sif_gpio = 0x05,
178                 .tuner_scl_gpio = 0x1a,
179                 .tuner_sda_gpio = 0x1b,
180                 .decoder = CX231XX_AVDECODER,
181                 .output_mode = OUT_MODE_VIP11,
182                 .demod_xfer_mode = 0,
183                 .ctl_pin_status_mask = 0xFFFFFFC4,
184                 .agc_analog_digital_select_gpio = 0x1c,
185                 .gpio_pin_status_mask = 0x4001000,
186                 .tuner_i2c_master = I2C_1_MUX_3,
187                 .demod_i2c_master = I2C_2,
188                 .has_dvb = 1,
189                 .demod_addr = 0x02,
190                 .norm = V4L2_STD_PAL,
191 
192                 .input = {{
193                                 .type = CX231XX_VMUX_TELEVISION,
194                                 .vmux = CX231XX_VIN_3_1,
195                                 .amux = CX231XX_AMUX_VIDEO,
196                                 .gpio = NULL,
197                         }, {
198                                 .type = CX231XX_VMUX_COMPOSITE1,
199                                 .vmux = CX231XX_VIN_2_1,
200                                 .amux = CX231XX_AMUX_LINE_IN,
201                                 .gpio = NULL,
202                         }, {
203                                 .type = CX231XX_VMUX_SVIDEO,
204                                 .vmux = CX231XX_VIN_1_1 |
205                                         (CX231XX_VIN_1_2 << 8) |
206                                         CX25840_SVIDEO_ON,
207                                 .amux = CX231XX_AMUX_LINE_IN,
208                                 .gpio = NULL,
209                         }
210                 },
211         },
212 
213         [CX231XX_BOARD_CNXT_RDU_253S] = {
214                 .name = "Conexant Hybrid TV - RDU253S",
215                 .tuner_type = TUNER_NXP_TDA18271,
216                 .tuner_addr = 0x60,
217                 .tuner_gpio = RDE250_XCV_TUNER,
218                 .tuner_sif_gpio = 0x05,
219                 .tuner_scl_gpio = 0x1a,
220                 .tuner_sda_gpio = 0x1b,
221                 .decoder = CX231XX_AVDECODER,
222                 .output_mode = OUT_MODE_VIP11,
223                 .demod_xfer_mode = 0,
224                 .ctl_pin_status_mask = 0xFFFFFFC4,
225                 .agc_analog_digital_select_gpio = 0x1c,
226                 .gpio_pin_status_mask = 0x4001000,
227                 .tuner_i2c_master = I2C_1_MUX_3,
228                 .demod_i2c_master = I2C_2,
229                 .has_dvb = 1,
230                 .demod_addr = 0x02,
231                 .norm = V4L2_STD_PAL,
232 
233                 .input = {{
234                                 .type = CX231XX_VMUX_TELEVISION,
235                                 .vmux = CX231XX_VIN_3_1,
236                                 .amux = CX231XX_AMUX_VIDEO,
237                                 .gpio = NULL,
238                         }, {
239                                 .type = CX231XX_VMUX_COMPOSITE1,
240                                 .vmux = CX231XX_VIN_2_1,
241                                 .amux = CX231XX_AMUX_LINE_IN,
242                                 .gpio = NULL,
243                         }, {
244                                 .type = CX231XX_VMUX_SVIDEO,
245                                 .vmux = CX231XX_VIN_1_1 |
246                                         (CX231XX_VIN_1_2 << 8) |
247                                         CX25840_SVIDEO_ON,
248                                 .amux = CX231XX_AMUX_LINE_IN,
249                                 .gpio = NULL,
250                         }
251                 },
252         },
253         [CX231XX_BOARD_CNXT_VIDEO_GRABBER] = {
254                 .name = "Conexant VIDEO GRABBER",
255                 .tuner_type = TUNER_ABSENT,
256                 .decoder = CX231XX_AVDECODER,
257                 .output_mode = OUT_MODE_VIP11,
258                 .ctl_pin_status_mask = 0xFFFFFFC4,
259                 .agc_analog_digital_select_gpio = 0x1c,
260                 .gpio_pin_status_mask = 0x4001000,
261                 .norm = V4L2_STD_PAL,
262                 .no_alt_vanc = 1,
263                 .external_av = 1,
264                 /* Actually, it has a 417, but it isn't working correctly.
265                  * So set to 0 for now until someone can manage to get this
266                  * to work reliably. */
267                 .has_417 = 0,
268 
269                 .input = {{
270                                 .type = CX231XX_VMUX_COMPOSITE1,
271                                 .vmux = CX231XX_VIN_2_1,
272                                 .amux = CX231XX_AMUX_LINE_IN,
273                                 .gpio = NULL,
274                         }, {
275                                 .type = CX231XX_VMUX_SVIDEO,
276                                 .vmux = CX231XX_VIN_1_1 |
277                                         (CX231XX_VIN_1_2 << 8) |
278                                         CX25840_SVIDEO_ON,
279                                 .amux = CX231XX_AMUX_LINE_IN,
280                                 .gpio = NULL,
281                         }
282                 },
283         },
284         [CX231XX_BOARD_CNXT_RDE_250] = {
285                 .name = "Conexant Hybrid TV - rde 250",
286                 .tuner_type = TUNER_XC5000,
287                 .tuner_addr = 0x61,
288                 .tuner_gpio = RDE250_XCV_TUNER,
289                 .tuner_sif_gpio = 0x05,
290                 .tuner_scl_gpio = 0x1a,
291                 .tuner_sda_gpio = 0x1b,
292                 .decoder = CX231XX_AVDECODER,
293                 .output_mode = OUT_MODE_VIP11,
294                 .demod_xfer_mode = 0,
295                 .ctl_pin_status_mask = 0xFFFFFFC4,
296                 .agc_analog_digital_select_gpio = 0x0c,
297                 .gpio_pin_status_mask = 0x4001000,
298                 .tuner_i2c_master = I2C_1_MUX_3,
299                 .demod_i2c_master = I2C_2,
300                 .has_dvb = 1,
301                 .demod_addr = 0x02,
302                 .norm = V4L2_STD_PAL,
303 
304                 .input = {{
305                                 .type = CX231XX_VMUX_TELEVISION,
306                                 .vmux = CX231XX_VIN_2_1,
307                                 .amux = CX231XX_AMUX_VIDEO,
308                                 .gpio = NULL,
309                         }
310                 },
311         },
312         [CX231XX_BOARD_CNXT_RDU_250] = {
313                 .name = "Conexant Hybrid TV - RDU 250",
314                 .tuner_type = TUNER_XC5000,
315                 .tuner_addr = 0x61,
316                 .tuner_gpio = RDE250_XCV_TUNER,
317                 .tuner_sif_gpio = 0x05,
318                 .tuner_scl_gpio = 0x1a,
319                 .tuner_sda_gpio = 0x1b,
320                 .decoder = CX231XX_AVDECODER,
321                 .output_mode = OUT_MODE_VIP11,
322                 .demod_xfer_mode = 0,
323                 .ctl_pin_status_mask = 0xFFFFFFC4,
324                 .agc_analog_digital_select_gpio = 0x0c,
325                 .gpio_pin_status_mask = 0x4001000,
326                 .tuner_i2c_master = I2C_1_MUX_3,
327                 .demod_i2c_master = I2C_2,
328                 .has_dvb = 1,
329                 .demod_addr = 0x32,
330                 .norm = V4L2_STD_NTSC,
331 
332                 .input = {{
333                                 .type = CX231XX_VMUX_TELEVISION,
334                                 .vmux = CX231XX_VIN_2_1,
335                                 .amux = CX231XX_AMUX_VIDEO,
336                                 .gpio = NULL,
337                         }
338                 },
339         },
340         [CX231XX_BOARD_HAUPPAUGE_EXETER] = {
341                 .name = "Hauppauge EXETER",
342                 .tuner_type = TUNER_NXP_TDA18271,
343                 .tuner_addr = 0x60,
344                 .tuner_gpio = RDE250_XCV_TUNER,
345                 .tuner_sif_gpio = 0x05,
346                 .tuner_scl_gpio = 0x1a,
347                 .tuner_sda_gpio = 0x1b,
348                 .decoder = CX231XX_AVDECODER,
349                 .output_mode = OUT_MODE_VIP11,
350                 .demod_xfer_mode = 0,
351                 .ctl_pin_status_mask = 0xFFFFFFC4,
352                 .agc_analog_digital_select_gpio = 0x0c,
353                 .gpio_pin_status_mask = 0x4001000,
354                 .tuner_i2c_master = I2C_1_MUX_1,
355                 .demod_i2c_master = I2C_2,
356                 .has_dvb = 1,
357                 .demod_addr = 0x0e,
358                 .norm = V4L2_STD_NTSC,
359 
360                 .input = {{
361                         .type = CX231XX_VMUX_TELEVISION,
362                         .vmux = CX231XX_VIN_3_1,
363                         .amux = CX231XX_AMUX_VIDEO,
364                         .gpio = NULL,
365                 }, {
366                         .type = CX231XX_VMUX_COMPOSITE1,
367                         .vmux = CX231XX_VIN_2_1,
368                         .amux = CX231XX_AMUX_LINE_IN,
369                         .gpio = NULL,
370                 }, {
371                         .type = CX231XX_VMUX_SVIDEO,
372                         .vmux = CX231XX_VIN_1_1 |
373                                 (CX231XX_VIN_1_2 << 8) |
374                                 CX25840_SVIDEO_ON,
375                         .amux = CX231XX_AMUX_LINE_IN,
376                         .gpio = NULL,
377                 } },
378         },
379         [CX231XX_BOARD_HAUPPAUGE_USBLIVE2] = {
380                 .name = "Hauppauge USB Live 2",
381                 .tuner_type = TUNER_ABSENT,
382                 .decoder = CX231XX_AVDECODER,
383                 .output_mode = OUT_MODE_VIP11,
384                 .demod_xfer_mode = 0,
385                 .ctl_pin_status_mask = 0xFFFFFFC4,
386                 .agc_analog_digital_select_gpio = 0x0c,
387                 .gpio_pin_status_mask = 0x4001000,
388                 .norm = V4L2_STD_NTSC,
389                 .no_alt_vanc = 1,
390                 .external_av = 1,
391                 .input = {{
392                         .type = CX231XX_VMUX_COMPOSITE1,
393                         .vmux = CX231XX_VIN_2_1,
394                         .amux = CX231XX_AMUX_LINE_IN,
395                         .gpio = NULL,
396                 }, {
397                         .type = CX231XX_VMUX_SVIDEO,
398                         .vmux = CX231XX_VIN_1_1 |
399                                 (CX231XX_VIN_1_2 << 8) |
400                                 CX25840_SVIDEO_ON,
401                         .amux = CX231XX_AMUX_LINE_IN,
402                         .gpio = NULL,
403                 } },
404         },
405         [CX231XX_BOARD_KWORLD_UB430_USB_HYBRID] = {
406                 .name = "Kworld UB430 USB Hybrid",
407                 .tuner_type = TUNER_NXP_TDA18271,
408                 .tuner_addr = 0x60,
409                 .decoder = CX231XX_AVDECODER,
410                 .output_mode = OUT_MODE_VIP11,
411                 .demod_xfer_mode = 0,
412                 .ctl_pin_status_mask = 0xFFFFFFC4,
413                 .agc_analog_digital_select_gpio = 0x11, /* According with PV cxPolaris.inf file */
414                 .tuner_sif_gpio = -1,
415                 .tuner_scl_gpio = -1,
416                 .tuner_sda_gpio = -1,
417                 .gpio_pin_status_mask = 0x4001000,
418                 .tuner_i2c_master = I2C_2,
419                 .demod_i2c_master = I2C_1_MUX_3,
420                 .ir_i2c_master = I2C_2,
421                 .has_dvb = 1,
422                 .demod_addr = 0x10,
423                 .norm = V4L2_STD_PAL_M,
424                 .input = {{
425                         .type = CX231XX_VMUX_TELEVISION,
426                         .vmux = CX231XX_VIN_3_1,
427                         .amux = CX231XX_AMUX_VIDEO,
428                         .gpio = NULL,
429                 }, {
430                         .type = CX231XX_VMUX_COMPOSITE1,
431                         .vmux = CX231XX_VIN_2_1,
432                         .amux = CX231XX_AMUX_LINE_IN,
433                         .gpio = NULL,
434                 }, {
435                         .type = CX231XX_VMUX_SVIDEO,
436                         .vmux = CX231XX_VIN_1_1 |
437                                 (CX231XX_VIN_1_2 << 8) |
438                                 CX25840_SVIDEO_ON,
439                         .amux = CX231XX_AMUX_LINE_IN,
440                         .gpio = NULL,
441                 } },
442         },
443         [CX231XX_BOARD_KWORLD_UB445_USB_HYBRID] = {
444                 .name = "Kworld UB445 USB Hybrid",
445                 .tuner_type = TUNER_NXP_TDA18271,
446                 .tuner_addr = 0x60,
447                 .decoder = CX231XX_AVDECODER,
448                 .output_mode = OUT_MODE_VIP11,
449                 .demod_xfer_mode = 0,
450                 .ctl_pin_status_mask = 0xFFFFFFC4,
451                 .agc_analog_digital_select_gpio = 0x11, /* According with PV cxPolaris.inf file */
452                 .tuner_sif_gpio = -1,
453                 .tuner_scl_gpio = -1,
454                 .tuner_sda_gpio = -1,
455                 .gpio_pin_status_mask = 0x4001000,
456                 .tuner_i2c_master = I2C_2,
457                 .demod_i2c_master = I2C_1_MUX_3,
458                 .ir_i2c_master = I2C_2,
459                 .has_dvb = 1,
460                 .demod_addr = 0x10,
461                 .norm = V4L2_STD_NTSC_M,
462                 .input = {{
463                         .type = CX231XX_VMUX_TELEVISION,
464                         .vmux = CX231XX_VIN_3_1,
465                         .amux = CX231XX_AMUX_VIDEO,
466                         .gpio = NULL,
467                 }, {
468                         .type = CX231XX_VMUX_COMPOSITE1,
469                         .vmux = CX231XX_VIN_2_1,
470                         .amux = CX231XX_AMUX_LINE_IN,
471                         .gpio = NULL,
472                 }, {
473                         .type = CX231XX_VMUX_SVIDEO,
474                         .vmux = CX231XX_VIN_1_1 |
475                                 (CX231XX_VIN_1_2 << 8) |
476                                 CX25840_SVIDEO_ON,
477                         .amux = CX231XX_AMUX_LINE_IN,
478                         .gpio = NULL,
479                 } },
480         },
481         [CX231XX_BOARD_PV_PLAYTV_USB_HYBRID] = {
482                 .name = "Pixelview PlayTV USB Hybrid",
483                 .tuner_type = TUNER_NXP_TDA18271,
484                 .tuner_addr = 0x60,
485                 .decoder = CX231XX_AVDECODER,
486                 .output_mode = OUT_MODE_VIP11,
487                 .demod_xfer_mode = 0,
488                 .ctl_pin_status_mask = 0xFFFFFFC4,
489                 .agc_analog_digital_select_gpio = 0x00, /* According with PV cxPolaris.inf file */
490                 .tuner_sif_gpio = -1,
491                 .tuner_scl_gpio = -1,
492                 .tuner_sda_gpio = -1,
493                 .gpio_pin_status_mask = 0x4001000,
494                 .tuner_i2c_master = I2C_2,
495                 .demod_i2c_master = I2C_1_MUX_3,
496                 .ir_i2c_master = I2C_2,
497                 .rc_map_name = RC_MAP_PIXELVIEW_002T,
498                 .has_dvb = 1,
499                 .demod_addr = 0x10,
500                 .norm = V4L2_STD_PAL_M,
501                 .input = {{
502                         .type = CX231XX_VMUX_TELEVISION,
503                         .vmux = CX231XX_VIN_3_1,
504                         .amux = CX231XX_AMUX_VIDEO,
505                         .gpio = NULL,
506                 }, {
507                         .type = CX231XX_VMUX_COMPOSITE1,
508                         .vmux = CX231XX_VIN_2_1,
509                         .amux = CX231XX_AMUX_LINE_IN,
510                         .gpio = NULL,
511                 }, {
512                         .type = CX231XX_VMUX_SVIDEO,
513                         .vmux = CX231XX_VIN_1_1 |
514                                 (CX231XX_VIN_1_2 << 8) |
515                                 CX25840_SVIDEO_ON,
516                         .amux = CX231XX_AMUX_LINE_IN,
517                         .gpio = NULL,
518                 } },
519         },
520         [CX231XX_BOARD_PV_XCAPTURE_USB] = {
521                 .name = "Pixelview Xcapture USB",
522                 .tuner_type = TUNER_ABSENT,
523                 .decoder = CX231XX_AVDECODER,
524                 .output_mode = OUT_MODE_VIP11,
525                 .demod_xfer_mode = 0,
526                 .ctl_pin_status_mask = 0xFFFFFFC4,
527                 .agc_analog_digital_select_gpio = 0x0c,
528                 .gpio_pin_status_mask = 0x4001000,
529                 .norm = V4L2_STD_NTSC,
530                 .no_alt_vanc = 1,
531                 .external_av = 1,
532 
533                 .input = {{
534                                 .type = CX231XX_VMUX_COMPOSITE1,
535                                 .vmux = CX231XX_VIN_2_1,
536                                 .amux = CX231XX_AMUX_LINE_IN,
537                                 .gpio = NULL,
538                         }, {
539                                 .type = CX231XX_VMUX_SVIDEO,
540                                 .vmux = CX231XX_VIN_1_1 |
541                                         (CX231XX_VIN_1_2 << 8) |
542                                         CX25840_SVIDEO_ON,
543                                 .amux = CX231XX_AMUX_LINE_IN,
544                                 .gpio = NULL,
545                         }
546                 },
547         },
548 
549         [CX231XX_BOARD_ICONBIT_U100] = {
550                 .name = "Iconbit Analog Stick U100 FM",
551                 .tuner_type = TUNER_ABSENT,
552                 .decoder = CX231XX_AVDECODER,
553                 .output_mode = OUT_MODE_VIP11,
554                 .demod_xfer_mode = 0,
555                 .ctl_pin_status_mask = 0xFFFFFFC4,
556                 .agc_analog_digital_select_gpio = 0x1C,
557                 .gpio_pin_status_mask = 0x4001000,
558 
559                 .input = {{
560                         .type = CX231XX_VMUX_COMPOSITE1,
561                         .vmux = CX231XX_VIN_2_1,
562                         .amux = CX231XX_AMUX_LINE_IN,
563                         .gpio = NULL,
564                 }, {
565                         .type = CX231XX_VMUX_SVIDEO,
566                         .vmux = CX231XX_VIN_1_1 |
567                                 (CX231XX_VIN_1_2 << 8) |
568                                 CX25840_SVIDEO_ON,
569                         .amux = CX231XX_AMUX_LINE_IN,
570                         .gpio = NULL,
571                 } },
572         },
573         [CX231XX_BOARD_HAUPPAUGE_USB2_FM_PAL] = {
574                 .name = "Hauppauge WinTV USB2 FM (PAL)",
575                 .tuner_type = TUNER_NXP_TDA18271,
576                 .tuner_addr = 0x60,
577                 .tuner_gpio = RDE250_XCV_TUNER,
578                 .tuner_sif_gpio = 0x05,
579                 .tuner_scl_gpio = 0x1a,
580                 .tuner_sda_gpio = 0x1b,
581                 .decoder = CX231XX_AVDECODER,
582                 .output_mode = OUT_MODE_VIP11,
583                 .ctl_pin_status_mask = 0xFFFFFFC4,
584                 .agc_analog_digital_select_gpio = 0x0c,
585                 .gpio_pin_status_mask = 0x4001000,
586                 .tuner_i2c_master = I2C_1_MUX_3,
587                 .norm = V4L2_STD_PAL,
588 
589                 .input = {{
590                         .type = CX231XX_VMUX_TELEVISION,
591                         .vmux = CX231XX_VIN_3_1,
592                         .amux = CX231XX_AMUX_VIDEO,
593                         .gpio = NULL,
594                 }, {
595                         .type = CX231XX_VMUX_COMPOSITE1,
596                         .vmux = CX231XX_VIN_2_1,
597                         .amux = CX231XX_AMUX_LINE_IN,
598                         .gpio = NULL,
599                 }, {
600                         .type = CX231XX_VMUX_SVIDEO,
601                         .vmux = CX231XX_VIN_1_1 |
602                                 (CX231XX_VIN_1_2 << 8) |
603                                 CX25840_SVIDEO_ON,
604                         .amux = CX231XX_AMUX_LINE_IN,
605                         .gpio = NULL,
606                 } },
607         },
608         [CX231XX_BOARD_HAUPPAUGE_USB2_FM_NTSC] = {
609                 .name = "Hauppauge WinTV USB2 FM (NTSC)",
610                 .tuner_type = TUNER_NXP_TDA18271,
611                 .tuner_addr = 0x60,
612                 .tuner_gpio = RDE250_XCV_TUNER,
613                 .tuner_sif_gpio = 0x05,
614                 .tuner_scl_gpio = 0x1a,
615                 .tuner_sda_gpio = 0x1b,
616                 .decoder = CX231XX_AVDECODER,
617                 .output_mode = OUT_MODE_VIP11,
618                 .ctl_pin_status_mask = 0xFFFFFFC4,
619                 .agc_analog_digital_select_gpio = 0x0c,
620                 .gpio_pin_status_mask = 0x4001000,
621                 .tuner_i2c_master = I2C_1_MUX_3,
622                 .norm = V4L2_STD_NTSC,
623 
624                 .input = {{
625                         .type = CX231XX_VMUX_TELEVISION,
626                         .vmux = CX231XX_VIN_3_1,
627                         .amux = CX231XX_AMUX_VIDEO,
628                         .gpio = NULL,
629                 }, {
630                         .type = CX231XX_VMUX_COMPOSITE1,
631                         .vmux = CX231XX_VIN_2_1,
632                         .amux = CX231XX_AMUX_LINE_IN,
633                         .gpio = NULL,
634                 }, {
635                         .type = CX231XX_VMUX_SVIDEO,
636                         .vmux = CX231XX_VIN_1_1 |
637                                 (CX231XX_VIN_1_2 << 8) |
638                                 CX25840_SVIDEO_ON,
639                         .amux = CX231XX_AMUX_LINE_IN,
640                         .gpio = NULL,
641                 } },
642         },
643         [CX231XX_BOARD_ELGATO_VIDEO_CAPTURE_V2] = {
644                 .name = "Elgato Video Capture V2",
645                 .tuner_type = TUNER_ABSENT,
646                 .decoder = CX231XX_AVDECODER,
647                 .output_mode = OUT_MODE_VIP11,
648                 .demod_xfer_mode = 0,
649                 .ctl_pin_status_mask = 0xFFFFFFC4,
650                 .agc_analog_digital_select_gpio = 0x0c,
651                 .gpio_pin_status_mask = 0x4001000,
652                 .norm = V4L2_STD_NTSC,
653                 .no_alt_vanc = 1,
654                 .external_av = 1,
655                 .input = {{
656                         .type = CX231XX_VMUX_COMPOSITE1,
657                         .vmux = CX231XX_VIN_2_1,
658                         .amux = CX231XX_AMUX_LINE_IN,
659                         .gpio = NULL,
660                 }, {
661                         .type = CX231XX_VMUX_SVIDEO,
662                         .vmux = CX231XX_VIN_1_1 |
663                                 (CX231XX_VIN_1_2 << 8) |
664                                 CX25840_SVIDEO_ON,
665                         .amux = CX231XX_AMUX_LINE_IN,
666                         .gpio = NULL,
667                 } },
668         },
669         [CX231XX_BOARD_OTG102] = {
670                 .name = "Geniatech OTG102",
671                 .tuner_type = TUNER_ABSENT,
672                 .decoder = CX231XX_AVDECODER,
673                 .output_mode = OUT_MODE_VIP11,
674                 .ctl_pin_status_mask = 0xFFFFFFC4,
675                 .agc_analog_digital_select_gpio = 0x0c,
676                         /* According with PV CxPlrCAP.inf file */
677                 .gpio_pin_status_mask = 0x4001000,
678                 .norm = V4L2_STD_NTSC,
679                 .no_alt_vanc = 1,
680                 .external_av = 1,
681                 /*.has_417 = 1, */
682                 /* This board is believed to have a hardware encoding chip
683                  * supporting mpeg1/2/4, but as the 417 is apparently not
684                  * working for the reference board it is not here either. */
685 
686                 .input = {{
687                                 .type = CX231XX_VMUX_COMPOSITE1,
688                                 .vmux = CX231XX_VIN_2_1,
689                                 .amux = CX231XX_AMUX_LINE_IN,
690                                 .gpio = NULL,
691                         }, {
692                                 .type = CX231XX_VMUX_SVIDEO,
693                                 .vmux = CX231XX_VIN_1_1 |
694                                         (CX231XX_VIN_1_2 << 8) |
695                                         CX25840_SVIDEO_ON,
696                                 .amux = CX231XX_AMUX_LINE_IN,
697                                 .gpio = NULL,
698                         }
699                 },
700         },
701         [CX231XX_BOARD_HAUPPAUGE_930C_HD_1113xx] = {
702                 .name = "Hauppauge WinTV 930C-HD (1113xx) / HVR-900H (111xxx) / PCTV QuatroStick 521e",
703                 .tuner_type = TUNER_NXP_TDA18271,
704                 .tuner_addr = 0x60,
705                 .tuner_gpio = RDE250_XCV_TUNER,
706                 .tuner_sif_gpio = 0x05,
707                 .tuner_scl_gpio = 0x1a,
708                 .tuner_sda_gpio = 0x1b,
709                 .decoder = CX231XX_AVDECODER,
710                 .output_mode = OUT_MODE_VIP11,
711                 .demod_xfer_mode = 0,
712                 .ctl_pin_status_mask = 0xFFFFFFC4,
713                 .agc_analog_digital_select_gpio = 0x0c,
714                 .gpio_pin_status_mask = 0x4001000,
715                 .tuner_i2c_master = I2C_1_MUX_3,
716                 .demod_i2c_master = I2C_2,
717                 .has_dvb = 1,
718                 .demod_addr = 0x0e,
719                 .norm = V4L2_STD_PAL,
720 
721                 .input = {{
722                         .type = CX231XX_VMUX_TELEVISION,
723                         .vmux = CX231XX_VIN_3_1,
724                         .amux = CX231XX_AMUX_VIDEO,
725                         .gpio = NULL,
726                 }, {
727                         .type = CX231XX_VMUX_COMPOSITE1,
728                         .vmux = CX231XX_VIN_2_1,
729                         .amux = CX231XX_AMUX_LINE_IN,
730                         .gpio = NULL,
731                 }, {
732                         .type = CX231XX_VMUX_SVIDEO,
733                         .vmux = CX231XX_VIN_1_1 |
734                                 (CX231XX_VIN_1_2 << 8) |
735                                 CX25840_SVIDEO_ON,
736                         .amux = CX231XX_AMUX_LINE_IN,
737                         .gpio = NULL,
738                 } },
739         },
740         [CX231XX_BOARD_HAUPPAUGE_930C_HD_1114xx] = {
741                 .name = "Hauppauge WinTV 930C-HD (1114xx) / HVR-901H (1114xx) / PCTV QuatroStick 522e",
742                 .tuner_type = TUNER_ABSENT,
743                 .tuner_addr = 0x60,
744                 .tuner_gpio = RDE250_XCV_TUNER,
745                 .tuner_sif_gpio = 0x05,
746                 .tuner_scl_gpio = 0x1a,
747                 .tuner_sda_gpio = 0x1b,
748                 .decoder = CX231XX_AVDECODER,
749                 .output_mode = OUT_MODE_VIP11,
750                 .demod_xfer_mode = 0,
751                 .ctl_pin_status_mask = 0xFFFFFFC4,
752                 .agc_analog_digital_select_gpio = 0x0c,
753                 .gpio_pin_status_mask = 0x4001000,
754                 .tuner_i2c_master = I2C_1_MUX_3,
755                 .demod_i2c_master = I2C_2,
756                 .has_dvb = 1,
757                 .demod_addr = 0x0e,
758                 .norm = V4L2_STD_PAL,
759 
760                 .input = {{
761                         .type = CX231XX_VMUX_TELEVISION,
762                         .vmux = CX231XX_VIN_3_1,
763                         .amux = CX231XX_AMUX_VIDEO,
764                         .gpio = NULL,
765                 }, {
766                         .type = CX231XX_VMUX_COMPOSITE1,
767                         .vmux = CX231XX_VIN_2_1,
768                         .amux = CX231XX_AMUX_LINE_IN,
769                         .gpio = NULL,
770                 }, {
771                         .type = CX231XX_VMUX_SVIDEO,
772                         .vmux = CX231XX_VIN_1_1 |
773                                 (CX231XX_VIN_1_2 << 8) |
774                                 CX25840_SVIDEO_ON,
775                         .amux = CX231XX_AMUX_LINE_IN,
776                         .gpio = NULL,
777                 } },
778         },
779         [CX231XX_BOARD_HAUPPAUGE_955Q] = {
780                 .name = "Hauppauge WinTV-HVR-955Q (111401)",
781                 .tuner_type = TUNER_ABSENT,
782                 .tuner_addr = 0x60,
783                 .tuner_gpio = RDE250_XCV_TUNER,
784                 .tuner_sif_gpio = 0x05,
785                 .tuner_scl_gpio = 0x1a,
786                 .tuner_sda_gpio = 0x1b,
787                 .decoder = CX231XX_AVDECODER,
788                 .output_mode = OUT_MODE_VIP11,
789                 .demod_xfer_mode = 0,
790                 .ctl_pin_status_mask = 0xFFFFFFC4,
791                 .agc_analog_digital_select_gpio = 0x0c,
792                 .gpio_pin_status_mask = 0x4001000,
793                 .tuner_i2c_master = I2C_1_MUX_3,
794                 .demod_i2c_master = I2C_2,
795                 .has_dvb = 1,
796                 .demod_addr = 0x0e,
797                 .norm = V4L2_STD_NTSC,
798 
799                 .input = {{
800                         .type = CX231XX_VMUX_TELEVISION,
801                         .vmux = CX231XX_VIN_3_1,
802                         .amux = CX231XX_AMUX_VIDEO,
803                         .gpio = NULL,
804                 }, {
805                         .type = CX231XX_VMUX_COMPOSITE1,
806                         .vmux = CX231XX_VIN_2_1,
807                         .amux = CX231XX_AMUX_LINE_IN,
808                         .gpio = NULL,
809                 }, {
810                         .type = CX231XX_VMUX_SVIDEO,
811                         .vmux = CX231XX_VIN_1_1 |
812                                 (CX231XX_VIN_1_2 << 8) |
813                                 CX25840_SVIDEO_ON,
814                         .amux = CX231XX_AMUX_LINE_IN,
815                         .gpio = NULL,
816                 } },
817         },
818 };
819 const unsigned int cx231xx_bcount = ARRAY_SIZE(cx231xx_boards);
820 
821 /* table of devices that work with this driver */
822 struct usb_device_id cx231xx_id_table[] = {
823         {USB_DEVICE(0x1D19, 0x6109),
824         .driver_info = CX231XX_BOARD_PV_XCAPTURE_USB},
825         {USB_DEVICE(0x0572, 0x5A3C),
826          .driver_info = CX231XX_BOARD_UNKNOWN},
827         {USB_DEVICE(0x0572, 0x58A2),
828          .driver_info = CX231XX_BOARD_CNXT_CARRAERA},
829         {USB_DEVICE(0x0572, 0x58A1),
830          .driver_info = CX231XX_BOARD_CNXT_SHELBY},
831         {USB_DEVICE(0x0572, 0x58A4),
832          .driver_info = CX231XX_BOARD_CNXT_RDE_253S},
833         {USB_DEVICE(0x0572, 0x58A5),
834          .driver_info = CX231XX_BOARD_CNXT_RDU_253S},
835         {USB_DEVICE(0x0572, 0x58A6),
836          .driver_info = CX231XX_BOARD_CNXT_VIDEO_GRABBER},
837         {USB_DEVICE(0x0572, 0x589E),
838          .driver_info = CX231XX_BOARD_CNXT_RDE_250},
839         {USB_DEVICE(0x0572, 0x58A0),
840          .driver_info = CX231XX_BOARD_CNXT_RDU_250},
841         {USB_DEVICE(0x2040, 0xb110),
842          .driver_info = CX231XX_BOARD_HAUPPAUGE_USB2_FM_PAL},
843         {USB_DEVICE(0x2040, 0xb111),
844          .driver_info = CX231XX_BOARD_HAUPPAUGE_USB2_FM_NTSC},
845         {USB_DEVICE(0x2040, 0xb120),
846          .driver_info = CX231XX_BOARD_HAUPPAUGE_EXETER},
847         {USB_DEVICE(0x2040, 0xb123),
848          .driver_info = CX231XX_BOARD_HAUPPAUGE_955Q},
849         {USB_DEVICE(0x2040, 0xb130),
850          .driver_info = CX231XX_BOARD_HAUPPAUGE_930C_HD_1113xx},
851         {USB_DEVICE(0x2040, 0xb131),
852          .driver_info = CX231XX_BOARD_HAUPPAUGE_930C_HD_1114xx},
853         /* Hauppauge WinTV-HVR-900-H */
854         {USB_DEVICE(0x2040, 0xb138),
855          .driver_info = CX231XX_BOARD_HAUPPAUGE_930C_HD_1113xx},
856         /* Hauppauge WinTV-HVR-901-H */
857         {USB_DEVICE(0x2040, 0xb139),
858          .driver_info = CX231XX_BOARD_HAUPPAUGE_930C_HD_1114xx},
859         {USB_DEVICE(0x2040, 0xb140),
860          .driver_info = CX231XX_BOARD_HAUPPAUGE_EXETER},
861         {USB_DEVICE(0x2040, 0xc200),
862          .driver_info = CX231XX_BOARD_HAUPPAUGE_USBLIVE2},
863         /* PCTV QuatroStick 521e */
864         {USB_DEVICE(0x2013, 0x0259),
865          .driver_info = CX231XX_BOARD_HAUPPAUGE_930C_HD_1113xx},
866         /* PCTV QuatroStick 522e */
867         {USB_DEVICE(0x2013, 0x025e),
868          .driver_info = CX231XX_BOARD_HAUPPAUGE_930C_HD_1114xx},
869         {USB_DEVICE_VER(USB_VID_PIXELVIEW, USB_PID_PIXELVIEW_SBTVD, 0x4000, 0x4001),
870          .driver_info = CX231XX_BOARD_PV_PLAYTV_USB_HYBRID},
871         {USB_DEVICE(USB_VID_PIXELVIEW, 0x5014),
872          .driver_info = CX231XX_BOARD_PV_XCAPTURE_USB},
873         {USB_DEVICE(0x1b80, 0xe424),
874          .driver_info = CX231XX_BOARD_KWORLD_UB430_USB_HYBRID},
875         {USB_DEVICE(0x1b80, 0xe421),
876          .driver_info = CX231XX_BOARD_KWORLD_UB445_USB_HYBRID},
877         {USB_DEVICE(0x1f4d, 0x0237),
878          .driver_info = CX231XX_BOARD_ICONBIT_U100},
879         {USB_DEVICE(0x0fd9, 0x0037),
880          .driver_info = CX231XX_BOARD_ELGATO_VIDEO_CAPTURE_V2},
881         {USB_DEVICE(0x1f4d, 0x0102),
882          .driver_info = CX231XX_BOARD_OTG102},
883         {},
884 };
885 
886 MODULE_DEVICE_TABLE(usb, cx231xx_id_table);
887 
888 /* cx231xx_tuner_callback
889  * will be used to reset XC5000 tuner using GPIO pin
890  */
891 
892 int cx231xx_tuner_callback(void *ptr, int component, int command, int arg)
893 {
894         int rc = 0;
895         struct cx231xx *dev = ptr;
896 
897         if (dev->tuner_type == TUNER_XC5000) {
898                 if (command == XC5000_TUNER_RESET) {
899                         dev_dbg(dev->dev,
900                                 "Tuner CB: RESET: cmd %d : tuner type %d\n",
901                                 command, dev->tuner_type);
902                         cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit,
903                                                1);
904                         msleep(10);
905                         cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit,
906                                                0);
907                         msleep(330);
908                         cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit,
909                                                1);
910                         msleep(10);
911                 }
912         } else if (dev->tuner_type == TUNER_NXP_TDA18271) {
913                 switch (command) {
914                 case TDA18271_CALLBACK_CMD_AGC_ENABLE:
915                         if (dev->model == CX231XX_BOARD_PV_PLAYTV_USB_HYBRID)
916                                 rc = cx231xx_set_agc_analog_digital_mux_select(dev, arg);
917                         break;
918                 default:
919                         rc = -EINVAL;
920                         break;
921                 }
922         }
923         return rc;
924 }
925 EXPORT_SYMBOL_GPL(cx231xx_tuner_callback);
926 
927 static void cx231xx_reset_out(struct cx231xx *dev)
928 {
929         cx231xx_set_gpio_value(dev, CX23417_RESET, 1);
930         msleep(200);
931         cx231xx_set_gpio_value(dev, CX23417_RESET, 0);
932         msleep(200);
933         cx231xx_set_gpio_value(dev, CX23417_RESET, 1);
934 }
935 
936 static void cx231xx_enable_OSC(struct cx231xx *dev)
937 {
938         cx231xx_set_gpio_value(dev, CX23417_OSC_EN, 1);
939 }
940 
941 static void cx231xx_sleep_s5h1432(struct cx231xx *dev)
942 {
943         cx231xx_set_gpio_value(dev, SLEEP_S5H1432, 0);
944 }
945 
946 static inline void cx231xx_set_model(struct cx231xx *dev)
947 {
948         dev->board = cx231xx_boards[dev->model];
949 }
950 
951 /* Since cx231xx_pre_card_setup() requires a proper dev->model,
952  * this won't work for boards with generic PCI IDs
953  */
954 void cx231xx_pre_card_setup(struct cx231xx *dev)
955 {
956         dev_info(dev->dev, "Identified as %s (card=%d)\n",
957                 dev->board.name, dev->model);
958 
959         /* set the direction for GPIO pins */
960         if (dev->board.tuner_gpio) {
961                 cx231xx_set_gpio_direction(dev, dev->board.tuner_gpio->bit, 1);
962                 cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit, 1);
963         }
964         if (dev->board.tuner_sif_gpio >= 0)
965                 cx231xx_set_gpio_direction(dev, dev->board.tuner_sif_gpio, 1);
966 
967         /* request some modules if any required */
968 
969         /* set the mode to Analog mode initially */
970         cx231xx_set_mode(dev, CX231XX_ANALOG_MODE);
971 
972         /* Unlock device */
973         /* cx231xx_set_mode(dev, CX231XX_SUSPEND); */
974 
975 }
976 
977 static void cx231xx_config_tuner(struct cx231xx *dev)
978 {
979         struct tuner_setup tun_setup;
980         struct v4l2_frequency f;
981 
982         if (dev->tuner_type == TUNER_ABSENT)
983                 return;
984 
985         tun_setup.mode_mask = T_ANALOG_TV | T_RADIO;
986         tun_setup.type = dev->tuner_type;
987         tun_setup.addr = dev->tuner_addr;
988         tun_setup.tuner_callback = cx231xx_tuner_callback;
989 
990         tuner_call(dev, tuner, s_type_addr, &tun_setup);
991 
992 #if 0
993         if (tun_setup.type == TUNER_XC5000) {
994                 static struct xc2028_ctrl ctrl = {
995                         .fname = XC5000_DEFAULT_FIRMWARE,
996                         .max_len = 64,
997                         .demod = 0;
998                 };
999                 struct v4l2_priv_tun_config cfg = {
1000                         .tuner = dev->tuner_type,
1001                         .priv = &ctrl,
1002                 };
1003                 tuner_call(dev, tuner, s_config, &cfg);
1004         }
1005 #endif
1006         /* configure tuner */
1007         f.tuner = 0;
1008         f.type = V4L2_TUNER_ANALOG_TV;
1009         f.frequency = 9076;     /* just a magic number */
1010         dev->ctl_freq = f.frequency;
1011         call_all(dev, tuner, s_frequency, &f);
1012 
1013 }
1014 
1015 static int read_eeprom(struct cx231xx *dev, struct i2c_client *client,
1016                        u8 *eedata, int len)
1017 {
1018         int ret = 0;
1019         u8 start_offset = 0;
1020         int len_todo = len;
1021         u8 *eedata_cur = eedata;
1022         int i;
1023         struct i2c_msg msg_write = { .addr = client->addr, .flags = 0,
1024                 .buf = &start_offset, .len = 1 };
1025         struct i2c_msg msg_read = { .addr = client->addr, .flags = I2C_M_RD };
1026 
1027         /* start reading at offset 0 */
1028         ret = i2c_transfer(client->adapter, &msg_write, 1);
1029         if (ret < 0) {
1030                 dev_err(dev->dev, "Can't read eeprom\n");
1031                 return ret;
1032         }
1033 
1034         while (len_todo > 0) {
1035                 msg_read.len = (len_todo > 64) ? 64 : len_todo;
1036                 msg_read.buf = eedata_cur;
1037 
1038                 ret = i2c_transfer(client->adapter, &msg_read, 1);
1039                 if (ret < 0) {
1040                         dev_err(dev->dev, "Can't read eeprom\n");
1041                         return ret;
1042                 }
1043                 eedata_cur += msg_read.len;
1044                 len_todo -= msg_read.len;
1045         }
1046 
1047         for (i = 0; i + 15 < len; i += 16)
1048                 dev_dbg(dev->dev, "i2c eeprom %02x: %*ph\n",
1049                         i, 16, &eedata[i]);
1050 
1051         return 0;
1052 }
1053 
1054 void cx231xx_card_setup(struct cx231xx *dev)
1055 {
1056 
1057         cx231xx_set_model(dev);
1058 
1059         dev->tuner_type = cx231xx_boards[dev->model].tuner_type;
1060         if (cx231xx_boards[dev->model].tuner_addr)
1061                 dev->tuner_addr = cx231xx_boards[dev->model].tuner_addr;
1062 
1063         /* request some modules */
1064         if (dev->board.decoder == CX231XX_AVDECODER) {
1065                 dev->sd_cx25840 = v4l2_i2c_new_subdev(&dev->v4l2_dev,
1066                                         cx231xx_get_i2c_adap(dev, I2C_0),
1067                                         "cx25840", 0x88 >> 1, NULL);
1068                 if (dev->sd_cx25840 == NULL)
1069                         dev_err(dev->dev,
1070                                 "cx25840 subdev registration failure\n");
1071                 cx25840_call(dev, core, load_fw);
1072 
1073         }
1074 
1075         /* Initialize the tuner */
1076         if (dev->board.tuner_type != TUNER_ABSENT) {
1077                 struct i2c_adapter *tuner_i2c = cx231xx_get_i2c_adap(dev,
1078                                                 dev->board.tuner_i2c_master);
1079                 dev->sd_tuner = v4l2_i2c_new_subdev(&dev->v4l2_dev,
1080                                                     tuner_i2c,
1081                                                     "tuner",
1082                                                     dev->tuner_addr, NULL);
1083                 if (dev->sd_tuner == NULL)
1084                         dev_err(dev->dev,
1085                                 "tuner subdev registration failure\n");
1086                 else
1087                         cx231xx_config_tuner(dev);
1088         }
1089 
1090         switch (dev->model) {
1091         case CX231XX_BOARD_HAUPPAUGE_930C_HD_1113xx:
1092         case CX231XX_BOARD_HAUPPAUGE_930C_HD_1114xx:
1093         case CX231XX_BOARD_HAUPPAUGE_955Q:
1094                 {
1095                         struct tveeprom tvee;
1096                         static u8 eeprom[256];
1097                         struct i2c_client client;
1098 
1099                         memset(&client, 0, sizeof(client));
1100                         client.adapter = cx231xx_get_i2c_adap(dev, I2C_1_MUX_1);
1101                         client.addr = 0xa0 >> 1;
1102 
1103                         read_eeprom(dev, &client, eeprom, sizeof(eeprom));
1104                         tveeprom_hauppauge_analog(&client,
1105                                                 &tvee, eeprom + 0xc0);
1106                         break;
1107                 }
1108         }
1109 
1110 }
1111 
1112 /*
1113  * cx231xx_config()
1114  * inits registers with sane defaults
1115  */
1116 int cx231xx_config(struct cx231xx *dev)
1117 {
1118         /* TBD need to add cx231xx specific code */
1119 
1120         return 0;
1121 }
1122 
1123 /*
1124  * cx231xx_config_i2c()
1125  * configure i2c attached devices
1126  */
1127 void cx231xx_config_i2c(struct cx231xx *dev)
1128 {
1129         /* u32 input = INPUT(dev->video_input)->vmux; */
1130 
1131         call_all(dev, video, s_stream, 1);
1132 }
1133 
1134 static void cx231xx_unregister_media_device(struct cx231xx *dev)
1135 {
1136 #ifdef CONFIG_MEDIA_CONTROLLER
1137         if (dev->media_dev) {
1138                 media_device_unregister(dev->media_dev);
1139                 kfree(dev->media_dev);
1140                 dev->media_dev = NULL;
1141         }
1142 #endif
1143 }
1144 
1145 /*
1146  * cx231xx_realease_resources()
1147  * unregisters the v4l2,i2c and usb devices
1148  * called when the device gets disconected or at module unload
1149 */
1150 void cx231xx_release_resources(struct cx231xx *dev)
1151 {
1152         cx231xx_unregister_media_device(dev);
1153 
1154         cx231xx_release_analog_resources(dev);
1155 
1156         cx231xx_remove_from_devlist(dev);
1157 
1158         cx231xx_ir_exit(dev);
1159 
1160         /* Release I2C buses */
1161         cx231xx_dev_uninit(dev);
1162 
1163         /* delete v4l2 device */
1164         v4l2_device_unregister(&dev->v4l2_dev);
1165 
1166         usb_put_dev(dev->udev);
1167 
1168         /* Mark device as unused */
1169         clear_bit(dev->devno, &cx231xx_devused);
1170 }
1171 
1172 static void cx231xx_media_device_register(struct cx231xx *dev,
1173                                           struct usb_device *udev)
1174 {
1175 #ifdef CONFIG_MEDIA_CONTROLLER
1176         struct media_device *mdev;
1177         int ret;
1178 
1179         mdev = kzalloc(sizeof(*mdev), GFP_KERNEL);
1180         if (!mdev)
1181                 return;
1182 
1183         mdev->dev = dev->dev;
1184         strlcpy(mdev->model, dev->board.name, sizeof(mdev->model));
1185         if (udev->serial)
1186                 strlcpy(mdev->serial, udev->serial, sizeof(mdev->serial));
1187         strcpy(mdev->bus_info, udev->devpath);
1188         mdev->hw_revision = le16_to_cpu(udev->descriptor.bcdDevice);
1189         mdev->driver_version = LINUX_VERSION_CODE;
1190 
1191         ret = media_device_register(mdev);
1192         if (ret) {
1193                 dev_err(dev->dev,
1194                         "Couldn't create a media device. Error: %d\n",
1195                         ret);
1196                 kfree(mdev);
1197                 return;
1198         }
1199 
1200         dev->media_dev = mdev;
1201 #endif
1202 }
1203 
1204 static void cx231xx_create_media_graph(struct cx231xx *dev)
1205 {
1206 #ifdef CONFIG_MEDIA_CONTROLLER
1207         struct media_device *mdev = dev->media_dev;
1208         struct media_entity *entity;
1209         struct media_entity *tuner = NULL, *decoder = NULL;
1210 
1211         if (!mdev)
1212                 return;
1213 
1214         media_device_for_each_entity(entity, mdev) {
1215                 switch (entity->type) {
1216                 case MEDIA_ENT_T_V4L2_SUBDEV_TUNER:
1217                         tuner = entity;
1218                         break;
1219                 case MEDIA_ENT_T_V4L2_SUBDEV_DECODER:
1220                         decoder = entity;
1221                         break;
1222                 }
1223         }
1224 
1225         /* Analog setup, using tuner as a link */
1226 
1227         if (!decoder)
1228                 return;
1229 
1230         if (tuner)
1231                 media_entity_create_link(tuner, 0, decoder, 0,
1232                                          MEDIA_LNK_FL_ENABLED);
1233         media_entity_create_link(decoder, 1, &dev->vdev.entity, 0,
1234                                  MEDIA_LNK_FL_ENABLED);
1235         media_entity_create_link(decoder, 2, &dev->vbi_dev.entity, 0,
1236                                  MEDIA_LNK_FL_ENABLED);
1237 #endif
1238 }
1239 
1240 /*
1241  * cx231xx_init_dev()
1242  * allocates and inits the device structs, registers i2c bus and v4l device
1243  */
1244 static int cx231xx_init_dev(struct cx231xx *dev, struct usb_device *udev,
1245                             int minor)
1246 {
1247         int retval = -ENOMEM;
1248         unsigned int maxh, maxw;
1249 
1250         dev->udev = udev;
1251         mutex_init(&dev->lock);
1252         mutex_init(&dev->ctrl_urb_lock);
1253         mutex_init(&dev->gpio_i2c_lock);
1254         mutex_init(&dev->i2c_lock);
1255 
1256         spin_lock_init(&dev->video_mode.slock);
1257         spin_lock_init(&dev->vbi_mode.slock);
1258         spin_lock_init(&dev->sliced_cc_mode.slock);
1259 
1260         init_waitqueue_head(&dev->open);
1261         init_waitqueue_head(&dev->wait_frame);
1262         init_waitqueue_head(&dev->wait_stream);
1263 
1264         dev->cx231xx_read_ctrl_reg = cx231xx_read_ctrl_reg;
1265         dev->cx231xx_write_ctrl_reg = cx231xx_write_ctrl_reg;
1266         dev->cx231xx_send_usb_command = cx231xx_send_usb_command;
1267         dev->cx231xx_gpio_i2c_read = cx231xx_gpio_i2c_read;
1268         dev->cx231xx_gpio_i2c_write = cx231xx_gpio_i2c_write;
1269 
1270         /* Query cx231xx to find what pcb config it is related to */
1271         retval = initialize_cx231xx(dev);
1272         if (retval < 0) {
1273                 dev_err(dev->dev, "Failed to read PCB config\n");
1274                 return retval;
1275         }
1276 
1277         /*To workaround error number=-71 on EP0 for VideoGrabber,
1278                  need set alt here.*/
1279         if (dev->model == CX231XX_BOARD_CNXT_VIDEO_GRABBER ||
1280             dev->model == CX231XX_BOARD_HAUPPAUGE_USBLIVE2) {
1281                 cx231xx_set_alt_setting(dev, INDEX_VIDEO, 3);
1282                 cx231xx_set_alt_setting(dev, INDEX_VANC, 1);
1283         }
1284         /* Cx231xx pre card setup */
1285         cx231xx_pre_card_setup(dev);
1286 
1287         retval = cx231xx_config(dev);
1288         if (retval) {
1289                 dev_err(dev->dev, "error configuring device\n");
1290                 return -ENOMEM;
1291         }
1292 
1293         /* set default norm */
1294         dev->norm = dev->board.norm;
1295 
1296         /* register i2c bus */
1297         retval = cx231xx_dev_init(dev);
1298         if (retval) {
1299                 dev_err(dev->dev,
1300                         "%s: cx231xx_i2c_register - errCode [%d]!\n",
1301                         __func__, retval);
1302                 goto err_dev_init;
1303         }
1304 
1305         /* Do board specific init */
1306         cx231xx_card_setup(dev);
1307 
1308         /* configure the device */
1309         cx231xx_config_i2c(dev);
1310 
1311         maxw = norm_maxw(dev);
1312         maxh = norm_maxh(dev);
1313 
1314         /* set default image size */
1315         dev->width = maxw;
1316         dev->height = maxh;
1317         dev->interlaced = 0;
1318         dev->video_input = 0;
1319 
1320         retval = cx231xx_config(dev);
1321         if (retval) {
1322                 dev_err(dev->dev, "%s: cx231xx_config - errCode [%d]!\n",
1323                         __func__, retval);
1324                 goto err_dev_init;
1325         }
1326 
1327         /* init video dma queues */
1328         INIT_LIST_HEAD(&dev->video_mode.vidq.active);
1329         INIT_LIST_HEAD(&dev->video_mode.vidq.queued);
1330 
1331         /* init vbi dma queues */
1332         INIT_LIST_HEAD(&dev->vbi_mode.vidq.active);
1333         INIT_LIST_HEAD(&dev->vbi_mode.vidq.queued);
1334 
1335         /* Reset other chips required if they are tied up with GPIO pins */
1336         cx231xx_add_into_devlist(dev);
1337 
1338         if (dev->board.has_417) {
1339                 dev_info(dev->dev, "attach 417 %d\n", dev->model);
1340                 if (cx231xx_417_register(dev) < 0) {
1341                         dev_err(dev->dev,
1342                                 "%s() Failed to register 417 on VID_B\n",
1343                                 __func__);
1344                 }
1345         }
1346 
1347         retval = cx231xx_register_analog_devices(dev);
1348         if (retval)
1349                 goto err_analog;
1350 
1351         cx231xx_ir_init(dev);
1352 
1353         cx231xx_init_extension(dev);
1354 
1355         return 0;
1356 err_analog:
1357         cx231xx_unregister_media_device(dev);
1358         cx231xx_release_analog_resources(dev);
1359         cx231xx_remove_from_devlist(dev);
1360 err_dev_init:
1361         cx231xx_dev_uninit(dev);
1362         return retval;
1363 }
1364 
1365 #if defined(CONFIG_MODULES) && defined(MODULE)
1366 static void request_module_async(struct work_struct *work)
1367 {
1368         struct cx231xx *dev = container_of(work,
1369                                            struct cx231xx, request_module_wk);
1370 
1371         if (dev->has_alsa_audio)
1372                 request_module("cx231xx-alsa");
1373 
1374         if (dev->board.has_dvb)
1375                 request_module("cx231xx-dvb");
1376 
1377 }
1378 
1379 static void request_modules(struct cx231xx *dev)
1380 {
1381         INIT_WORK(&dev->request_module_wk, request_module_async);
1382         schedule_work(&dev->request_module_wk);
1383 }
1384 
1385 static void flush_request_modules(struct cx231xx *dev)
1386 {
1387         flush_work(&dev->request_module_wk);
1388 }
1389 #else
1390 #define request_modules(dev)
1391 #define flush_request_modules(dev)
1392 #endif /* CONFIG_MODULES */
1393 
1394 static int cx231xx_init_v4l2(struct cx231xx *dev,
1395                              struct usb_device *udev,
1396                              struct usb_interface *interface,
1397                              int isoc_pipe)
1398 {
1399         struct usb_interface *uif;
1400         int i, idx;
1401 
1402         /* Video Init */
1403 
1404         /* compute alternate max packet sizes for video */
1405         idx = dev->current_pcb_config.hs_config_info[0].interface_info.video_index + 1;
1406         if (idx >= dev->max_iad_interface_count) {
1407                 dev_err(dev->dev,
1408                         "Video PCB interface #%d doesn't exist\n", idx);
1409                 return -ENODEV;
1410         }
1411 
1412         uif = udev->actconfig->interface[idx];
1413 
1414         dev->video_mode.end_point_addr = uif->altsetting[0].endpoint[isoc_pipe].desc.bEndpointAddress;
1415         dev->video_mode.num_alt = uif->num_altsetting;
1416 
1417         dev_info(dev->dev,
1418                  "video EndPoint Addr 0x%x, Alternate settings: %i\n",
1419                  dev->video_mode.end_point_addr,
1420                  dev->video_mode.num_alt);
1421 
1422         dev->video_mode.alt_max_pkt_size = devm_kmalloc_array(&udev->dev, 32, dev->video_mode.num_alt, GFP_KERNEL);
1423         if (dev->video_mode.alt_max_pkt_size == NULL)
1424                 return -ENOMEM;
1425 
1426         for (i = 0; i < dev->video_mode.num_alt; i++) {
1427                 u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].desc.wMaxPacketSize);
1428                 dev->video_mode.alt_max_pkt_size[i] = (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
1429                 dev_dbg(dev->dev,
1430                         "Alternate setting %i, max size= %i\n", i,
1431                         dev->video_mode.alt_max_pkt_size[i]);
1432         }
1433 
1434         /* VBI Init */
1435 
1436         idx = dev->current_pcb_config.hs_config_info[0].interface_info.vanc_index + 1;
1437         if (idx >= dev->max_iad_interface_count) {
1438                 dev_err(dev->dev,
1439                         "VBI PCB interface #%d doesn't exist\n", idx);
1440                 return -ENODEV;
1441         }
1442         uif = udev->actconfig->interface[idx];
1443 
1444         dev->vbi_mode.end_point_addr =
1445             uif->altsetting[0].endpoint[isoc_pipe].desc.
1446                         bEndpointAddress;
1447 
1448         dev->vbi_mode.num_alt = uif->num_altsetting;
1449         dev_info(dev->dev,
1450                  "VBI EndPoint Addr 0x%x, Alternate settings: %i\n",
1451                  dev->vbi_mode.end_point_addr,
1452                  dev->vbi_mode.num_alt);
1453 
1454         /* compute alternate max packet sizes for vbi */
1455         dev->vbi_mode.alt_max_pkt_size = devm_kmalloc_array(&udev->dev, 32, dev->vbi_mode.num_alt, GFP_KERNEL);
1456         if (dev->vbi_mode.alt_max_pkt_size == NULL)
1457                 return -ENOMEM;
1458 
1459         for (i = 0; i < dev->vbi_mode.num_alt; i++) {
1460                 u16 tmp =
1461                     le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
1462                                 desc.wMaxPacketSize);
1463                 dev->vbi_mode.alt_max_pkt_size[i] =
1464                     (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
1465                 dev_dbg(dev->dev,
1466                         "Alternate setting %i, max size= %i\n", i,
1467                         dev->vbi_mode.alt_max_pkt_size[i]);
1468         }
1469 
1470         /* Sliced CC VBI init */
1471 
1472         /* compute alternate max packet sizes for sliced CC */
1473         idx = dev->current_pcb_config.hs_config_info[0].interface_info.hanc_index + 1;
1474         if (idx >= dev->max_iad_interface_count) {
1475                 dev_err(dev->dev,
1476                         "Sliced CC PCB interface #%d doesn't exist\n", idx);
1477                 return -ENODEV;
1478         }
1479         uif = udev->actconfig->interface[idx];
1480 
1481         dev->sliced_cc_mode.end_point_addr =
1482             uif->altsetting[0].endpoint[isoc_pipe].desc.
1483                         bEndpointAddress;
1484 
1485         dev->sliced_cc_mode.num_alt = uif->num_altsetting;
1486         dev_info(dev->dev,
1487                  "sliced CC EndPoint Addr 0x%x, Alternate settings: %i\n",
1488                  dev->sliced_cc_mode.end_point_addr,
1489                  dev->sliced_cc_mode.num_alt);
1490         dev->sliced_cc_mode.alt_max_pkt_size = devm_kmalloc_array(&udev->dev, 32, dev->sliced_cc_mode.num_alt, GFP_KERNEL);
1491         if (dev->sliced_cc_mode.alt_max_pkt_size == NULL)
1492                 return -ENOMEM;
1493 
1494         for (i = 0; i < dev->sliced_cc_mode.num_alt; i++) {
1495                 u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
1496                                 desc.wMaxPacketSize);
1497                 dev->sliced_cc_mode.alt_max_pkt_size[i] =
1498                     (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
1499                 dev_dbg(dev->dev,
1500                         "Alternate setting %i, max size= %i\n", i,
1501                         dev->sliced_cc_mode.alt_max_pkt_size[i]);
1502         }
1503 
1504         return 0;
1505 }
1506 
1507 /*
1508  * cx231xx_usb_probe()
1509  * checks for supported devices
1510  */
1511 static int cx231xx_usb_probe(struct usb_interface *interface,
1512                              const struct usb_device_id *id)
1513 {
1514         struct usb_device *udev;
1515         struct device *d = &interface->dev;
1516         struct usb_interface *uif;
1517         struct cx231xx *dev = NULL;
1518         int retval = -ENODEV;
1519         int nr = 0, ifnum;
1520         int i, isoc_pipe = 0;
1521         char *speed;
1522         u8 idx;
1523         struct usb_interface_assoc_descriptor *assoc_desc;
1524 
1525         ifnum = interface->altsetting[0].desc.bInterfaceNumber;
1526 
1527         /*
1528          * Interface number 0 - IR interface (handled by mceusb driver)
1529          * Interface number 1 - AV interface (handled by this driver)
1530          */
1531         if (ifnum != 1)
1532                 return -ENODEV;
1533 
1534         /* Check to see next free device and mark as used */
1535         do {
1536                 nr = find_first_zero_bit(&cx231xx_devused, CX231XX_MAXBOARDS);
1537                 if (nr >= CX231XX_MAXBOARDS) {
1538                         /* No free device slots */
1539                         dev_err(d,
1540                                 "Supports only %i devices.\n",
1541                                 CX231XX_MAXBOARDS);
1542                         return -ENOMEM;
1543                 }
1544         } while (test_and_set_bit(nr, &cx231xx_devused));
1545 
1546         udev = usb_get_dev(interface_to_usbdev(interface));
1547 
1548         /* allocate memory for our device state and initialize it */
1549         dev = devm_kzalloc(&udev->dev, sizeof(*dev), GFP_KERNEL);
1550         if (dev == NULL) {
1551                 retval = -ENOMEM;
1552                 goto err_if;
1553         }
1554 
1555         snprintf(dev->name, 29, "cx231xx #%d", nr);
1556         dev->devno = nr;
1557         dev->model = id->driver_info;
1558         dev->video_mode.alt = -1;
1559         dev->dev = d;
1560 
1561         cx231xx_set_model(dev);
1562 
1563         dev->interface_count++;
1564         /* reset gpio dir and value */
1565         dev->gpio_dir = 0;
1566         dev->gpio_val = 0;
1567         dev->xc_fw_load_done = 0;
1568         dev->has_alsa_audio = 1;
1569         dev->power_mode = -1;
1570         atomic_set(&dev->devlist_count, 0);
1571 
1572         /* 0 - vbi ; 1 -sliced cc mode */
1573         dev->vbi_or_sliced_cc_mode = 0;
1574 
1575         /* get maximum no.of IAD interfaces */
1576         dev->max_iad_interface_count = udev->config->desc.bNumInterfaces;
1577 
1578         /* init CIR module TBD */
1579 
1580         /*mode_tv: digital=1 or analog=0*/
1581         dev->mode_tv = 0;
1582 
1583         dev->USE_ISO = transfer_mode;
1584 
1585         switch (udev->speed) {
1586         case USB_SPEED_LOW:
1587                 speed = "1.5";
1588                 break;
1589         case USB_SPEED_UNKNOWN:
1590         case USB_SPEED_FULL:
1591                 speed = "12";
1592                 break;
1593         case USB_SPEED_HIGH:
1594                 speed = "480";
1595                 break;
1596         default:
1597                 speed = "unknown";
1598         }
1599 
1600         dev_info(d,
1601                  "New device %s %s @ %s Mbps (%04x:%04x) with %d interfaces\n",
1602                  udev->manufacturer ? udev->manufacturer : "",
1603                  udev->product ? udev->product : "",
1604                  speed,
1605                  le16_to_cpu(udev->descriptor.idVendor),
1606                  le16_to_cpu(udev->descriptor.idProduct),
1607                  dev->max_iad_interface_count);
1608 
1609         /* increment interface count */
1610         dev->interface_count++;
1611 
1612         /* get device number */
1613         nr = dev->devno;
1614 
1615         assoc_desc = udev->actconfig->intf_assoc[0];
1616         if (assoc_desc->bFirstInterface != ifnum) {
1617                 dev_err(d, "Not found matching IAD interface\n");
1618                 retval = -ENODEV;
1619                 goto err_if;
1620         }
1621 
1622         dev_dbg(d, "registering interface %d\n", ifnum);
1623 
1624         /* save our data pointer in this interface device */
1625         usb_set_intfdata(interface, dev);
1626 
1627         /* Register the media controller */
1628         cx231xx_media_device_register(dev, udev);
1629 
1630         /* Create v4l2 device */
1631 #ifdef CONFIG_MEDIA_CONTROLLER
1632         dev->v4l2_dev.mdev = dev->media_dev;
1633 #endif
1634         retval = v4l2_device_register(&interface->dev, &dev->v4l2_dev);
1635         if (retval) {
1636                 dev_err(d, "v4l2_device_register failed\n");
1637                 goto err_v4l2;
1638         }
1639 
1640         /* allocate device struct */
1641         retval = cx231xx_init_dev(dev, udev, nr);
1642         if (retval)
1643                 goto err_init;
1644 
1645         retval = cx231xx_init_v4l2(dev, udev, interface, isoc_pipe);
1646         if (retval)
1647                 goto err_init;
1648 
1649         if (dev->current_pcb_config.ts1_source != 0xff) {
1650                 /* compute alternate max packet sizes for TS1 */
1651                 idx = dev->current_pcb_config.hs_config_info[0].interface_info.ts1_index + 1;
1652                 if (idx >= dev->max_iad_interface_count) {
1653                         dev_err(d, "TS1 PCB interface #%d doesn't exist\n",
1654                                 idx);
1655                         retval = -ENODEV;
1656                         goto err_video_alt;
1657                 }
1658                 uif = udev->actconfig->interface[idx];
1659 
1660                 dev->ts1_mode.end_point_addr =
1661                     uif->altsetting[0].endpoint[isoc_pipe].
1662                                 desc.bEndpointAddress;
1663 
1664                 dev->ts1_mode.num_alt = uif->num_altsetting;
1665                 dev_info(d,
1666                          "TS EndPoint Addr 0x%x, Alternate settings: %i\n",
1667                          dev->ts1_mode.end_point_addr,
1668                          dev->ts1_mode.num_alt);
1669 
1670                 dev->ts1_mode.alt_max_pkt_size = devm_kmalloc_array(&udev->dev, 32, dev->ts1_mode.num_alt, GFP_KERNEL);
1671                 if (dev->ts1_mode.alt_max_pkt_size == NULL) {
1672                         retval = -ENOMEM;
1673                         goto err_video_alt;
1674                 }
1675 
1676                 for (i = 0; i < dev->ts1_mode.num_alt; i++) {
1677                         u16 tmp = le16_to_cpu(uif->altsetting[i].
1678                                                 endpoint[isoc_pipe].desc.
1679                                                 wMaxPacketSize);
1680                         dev->ts1_mode.alt_max_pkt_size[i] =
1681                             (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
1682                         dev_dbg(d, "Alternate setting %i, max size= %i\n",
1683                                 i, dev->ts1_mode.alt_max_pkt_size[i]);
1684                 }
1685         }
1686 
1687         if (dev->model == CX231XX_BOARD_CNXT_VIDEO_GRABBER) {
1688                 cx231xx_enable_OSC(dev);
1689                 cx231xx_reset_out(dev);
1690                 cx231xx_set_alt_setting(dev, INDEX_VIDEO, 3);
1691         }
1692 
1693         if (dev->model == CX231XX_BOARD_CNXT_RDE_253S)
1694                 cx231xx_sleep_s5h1432(dev);
1695 
1696         /* load other modules required */
1697         request_modules(dev);
1698 
1699         cx231xx_create_media_graph(dev);
1700 
1701         return 0;
1702 err_video_alt:
1703         /* cx231xx_uninit_dev: */
1704         cx231xx_close_extension(dev);
1705         cx231xx_ir_exit(dev);
1706         cx231xx_release_analog_resources(dev);
1707         cx231xx_417_unregister(dev);
1708         cx231xx_remove_from_devlist(dev);
1709         cx231xx_dev_uninit(dev);
1710 err_init:
1711         v4l2_device_unregister(&dev->v4l2_dev);
1712 err_v4l2:
1713         usb_set_intfdata(interface, NULL);
1714 err_if:
1715         usb_put_dev(udev);
1716         clear_bit(nr, &cx231xx_devused);
1717         return retval;
1718 }
1719 
1720 /*
1721  * cx231xx_usb_disconnect()
1722  * called when the device gets diconencted
1723  * video device will be unregistered on v4l2_close in case it is still open
1724  */
1725 static void cx231xx_usb_disconnect(struct usb_interface *interface)
1726 {
1727         struct cx231xx *dev;
1728 
1729         dev = usb_get_intfdata(interface);
1730         usb_set_intfdata(interface, NULL);
1731 
1732         if (!dev)
1733                 return;
1734 
1735         if (!dev->udev)
1736                 return;
1737 
1738         dev->state |= DEV_DISCONNECTED;
1739 
1740         flush_request_modules(dev);
1741 
1742         /* wait until all current v4l2 io is finished then deallocate
1743            resources */
1744         mutex_lock(&dev->lock);
1745 
1746         wake_up_interruptible_all(&dev->open);
1747 
1748         if (dev->users) {
1749                 dev_warn(dev->dev,
1750                          "device %s is open! Deregistration and memory deallocation are deferred on close.\n",
1751                          video_device_node_name(&dev->vdev));
1752 
1753                 /* Even having users, it is safe to remove the RC i2c driver */
1754                 cx231xx_ir_exit(dev);
1755 
1756                 if (dev->USE_ISO)
1757                         cx231xx_uninit_isoc(dev);
1758                 else
1759                         cx231xx_uninit_bulk(dev);
1760                 wake_up_interruptible(&dev->wait_frame);
1761                 wake_up_interruptible(&dev->wait_stream);
1762         } else {
1763         }
1764 
1765         cx231xx_close_extension(dev);
1766 
1767         mutex_unlock(&dev->lock);
1768 
1769         if (!dev->users)
1770                 cx231xx_release_resources(dev);
1771 }
1772 
1773 static struct usb_driver cx231xx_usb_driver = {
1774         .name = "cx231xx",
1775         .probe = cx231xx_usb_probe,
1776         .disconnect = cx231xx_usb_disconnect,
1777         .id_table = cx231xx_id_table,
1778 };
1779 
1780 module_usb_driver(cx231xx_usb_driver);
1781 

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