Merge branch 'omap-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tmlind...
[cascardo/linux.git] / drivers / media / video / 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 #include <media/v4l2-chip-ident.h>
33
34 #include <media/cx25840.h>
35 #include "dvb-usb-ids.h"
36 #include "xc5000.h"
37 #include "tda18271.h"
38
39 #include "cx231xx.h"
40
41 static int tuner = -1;
42 module_param(tuner, int, 0444);
43 MODULE_PARM_DESC(tuner, "tuner type");
44
45 static int transfer_mode = 1;
46 module_param(transfer_mode, int, 0444);
47 MODULE_PARM_DESC(transfer_mode, "transfer mode (1-ISO or 0-BULK)");
48
49 static unsigned int disable_ir;
50 module_param(disable_ir, int, 0444);
51 MODULE_PARM_DESC(disable_ir, "disable infrared remote support");
52
53 /* Bitmask marking allocated devices from 0 to CX231XX_MAXBOARDS */
54 static unsigned long cx231xx_devused;
55
56 /*
57  *  Reset sequences for analog/digital modes
58  */
59
60 static struct cx231xx_reg_seq RDE250_XCV_TUNER[] = {
61         {0x03, 0x01, 10},
62         {0x03, 0x00, 30},
63         {0x03, 0x01, 10},
64         {-1, -1, -1},
65 };
66
67 /*
68  *  Board definitions
69  */
70 struct cx231xx_board cx231xx_boards[] = {
71         [CX231XX_BOARD_UNKNOWN] = {
72                 .name = "Unknown CX231xx video grabber",
73                 .tuner_type = TUNER_ABSENT,
74                 .input = {{
75                                 .type = CX231XX_VMUX_TELEVISION,
76                                 .vmux = CX231XX_VIN_3_1,
77                                 .amux = CX231XX_AMUX_VIDEO,
78                                 .gpio = NULL,
79                         }, {
80                                 .type = CX231XX_VMUX_COMPOSITE1,
81                                 .vmux = CX231XX_VIN_2_1,
82                                 .amux = CX231XX_AMUX_LINE_IN,
83                                 .gpio = NULL,
84                         }, {
85                                 .type = CX231XX_VMUX_SVIDEO,
86                                 .vmux = CX231XX_VIN_1_1 |
87                                         (CX231XX_VIN_1_2 << 8) |
88                                         CX25840_SVIDEO_ON,
89                                 .amux = CX231XX_AMUX_LINE_IN,
90                                 .gpio = NULL,
91                         }
92                 },
93         },
94         [CX231XX_BOARD_CNXT_CARRAERA] = {
95                 .name = "Conexant Hybrid TV - CARRAERA",
96                 .tuner_type = TUNER_XC5000,
97                 .tuner_addr = 0x61,
98                 .tuner_gpio = RDE250_XCV_TUNER,
99                 .tuner_sif_gpio = 0x05,
100                 .tuner_scl_gpio = 0x1a,
101                 .tuner_sda_gpio = 0x1b,
102                 .decoder = CX231XX_AVDECODER,
103                 .output_mode = OUT_MODE_VIP11,
104                 .demod_xfer_mode = 0,
105                 .ctl_pin_status_mask = 0xFFFFFFC4,
106                 .agc_analog_digital_select_gpio = 0x0c,
107                 .gpio_pin_status_mask = 0x4001000,
108                 .tuner_i2c_master = 1,
109                 .demod_i2c_master = 2,
110                 .has_dvb = 1,
111                 .demod_addr = 0x02,
112                 .norm = V4L2_STD_PAL,
113
114                 .input = {{
115                                 .type = CX231XX_VMUX_TELEVISION,
116                                 .vmux = CX231XX_VIN_3_1,
117                                 .amux = CX231XX_AMUX_VIDEO,
118                                 .gpio = NULL,
119                         }, {
120                                 .type = CX231XX_VMUX_COMPOSITE1,
121                                 .vmux = CX231XX_VIN_2_1,
122                                 .amux = CX231XX_AMUX_LINE_IN,
123                                 .gpio = NULL,
124                         }, {
125                                 .type = CX231XX_VMUX_SVIDEO,
126                                 .vmux = CX231XX_VIN_1_1 |
127                                         (CX231XX_VIN_1_2 << 8) |
128                                         CX25840_SVIDEO_ON,
129                                 .amux = CX231XX_AMUX_LINE_IN,
130                                 .gpio = NULL,
131                         }
132                 },
133         },
134         [CX231XX_BOARD_CNXT_SHELBY] = {
135                 .name = "Conexant Hybrid TV - SHELBY",
136                 .tuner_type = TUNER_XC5000,
137                 .tuner_addr = 0x61,
138                 .tuner_gpio = RDE250_XCV_TUNER,
139                 .tuner_sif_gpio = 0x05,
140                 .tuner_scl_gpio = 0x1a,
141                 .tuner_sda_gpio = 0x1b,
142                 .decoder = CX231XX_AVDECODER,
143                 .output_mode = OUT_MODE_VIP11,
144                 .demod_xfer_mode = 0,
145                 .ctl_pin_status_mask = 0xFFFFFFC4,
146                 .agc_analog_digital_select_gpio = 0x0c,
147                 .gpio_pin_status_mask = 0x4001000,
148                 .tuner_i2c_master = 1,
149                 .demod_i2c_master = 2,
150                 .has_dvb = 1,
151                 .demod_addr = 0x32,
152                 .norm = V4L2_STD_NTSC,
153
154                 .input = {{
155                                 .type = CX231XX_VMUX_TELEVISION,
156                                 .vmux = CX231XX_VIN_3_1,
157                                 .amux = CX231XX_AMUX_VIDEO,
158                                 .gpio = NULL,
159                         }, {
160                                 .type = CX231XX_VMUX_COMPOSITE1,
161                                 .vmux = CX231XX_VIN_2_1,
162                                 .amux = CX231XX_AMUX_LINE_IN,
163                                 .gpio = NULL,
164                         }, {
165                                 .type = CX231XX_VMUX_SVIDEO,
166                                 .vmux = CX231XX_VIN_1_1 |
167                                         (CX231XX_VIN_1_2 << 8) |
168                                         CX25840_SVIDEO_ON,
169                                 .amux = CX231XX_AMUX_LINE_IN,
170                                 .gpio = NULL,
171                         }
172                 },
173         },
174         [CX231XX_BOARD_CNXT_RDE_253S] = {
175                 .name = "Conexant Hybrid TV - RDE253S",
176                 .tuner_type = TUNER_NXP_TDA18271,
177                 .tuner_addr = 0x60,
178                 .tuner_gpio = RDE250_XCV_TUNER,
179                 .tuner_sif_gpio = 0x05,
180                 .tuner_scl_gpio = 0x1a,
181                 .tuner_sda_gpio = 0x1b,
182                 .decoder = CX231XX_AVDECODER,
183                 .output_mode = OUT_MODE_VIP11,
184                 .demod_xfer_mode = 0,
185                 .ctl_pin_status_mask = 0xFFFFFFC4,
186                 .agc_analog_digital_select_gpio = 0x1c,
187                 .gpio_pin_status_mask = 0x4001000,
188                 .tuner_i2c_master = 1,
189                 .demod_i2c_master = 2,
190                 .has_dvb = 1,
191                 .demod_addr = 0x02,
192                 .norm = V4L2_STD_PAL,
193
194                 .input = {{
195                                 .type = CX231XX_VMUX_TELEVISION,
196                                 .vmux = CX231XX_VIN_3_1,
197                                 .amux = CX231XX_AMUX_VIDEO,
198                                 .gpio = NULL,
199                         }, {
200                                 .type = CX231XX_VMUX_COMPOSITE1,
201                                 .vmux = CX231XX_VIN_2_1,
202                                 .amux = CX231XX_AMUX_LINE_IN,
203                                 .gpio = NULL,
204                         }, {
205                                 .type = CX231XX_VMUX_SVIDEO,
206                                 .vmux = CX231XX_VIN_1_1 |
207                                         (CX231XX_VIN_1_2 << 8) |
208                                         CX25840_SVIDEO_ON,
209                                 .amux = CX231XX_AMUX_LINE_IN,
210                                 .gpio = NULL,
211                         }
212                 },
213         },
214
215         [CX231XX_BOARD_CNXT_RDU_253S] = {
216                 .name = "Conexant Hybrid TV - RDU253S",
217                 .tuner_type = TUNER_NXP_TDA18271,
218                 .tuner_addr = 0x60,
219                 .tuner_gpio = RDE250_XCV_TUNER,
220                 .tuner_sif_gpio = 0x05,
221                 .tuner_scl_gpio = 0x1a,
222                 .tuner_sda_gpio = 0x1b,
223                 .decoder = CX231XX_AVDECODER,
224                 .output_mode = OUT_MODE_VIP11,
225                 .demod_xfer_mode = 0,
226                 .ctl_pin_status_mask = 0xFFFFFFC4,
227                 .agc_analog_digital_select_gpio = 0x1c,
228                 .gpio_pin_status_mask = 0x4001000,
229                 .tuner_i2c_master = 1,
230                 .demod_i2c_master = 2,
231                 .has_dvb = 1,
232                 .demod_addr = 0x02,
233                 .norm = V4L2_STD_PAL,
234
235                 .input = {{
236                                 .type = CX231XX_VMUX_TELEVISION,
237                                 .vmux = CX231XX_VIN_3_1,
238                                 .amux = CX231XX_AMUX_VIDEO,
239                                 .gpio = NULL,
240                         }, {
241                                 .type = CX231XX_VMUX_COMPOSITE1,
242                                 .vmux = CX231XX_VIN_2_1,
243                                 .amux = CX231XX_AMUX_LINE_IN,
244                                 .gpio = NULL,
245                         }, {
246                                 .type = CX231XX_VMUX_SVIDEO,
247                                 .vmux = CX231XX_VIN_1_1 |
248                                         (CX231XX_VIN_1_2 << 8) |
249                                         CX25840_SVIDEO_ON,
250                                 .amux = CX231XX_AMUX_LINE_IN,
251                                 .gpio = NULL,
252                         }
253                 },
254         },
255         [CX231XX_BOARD_CNXT_VIDEO_GRABBER] = {
256                 .name = "Conexant VIDEO GRABBER",
257                 .tuner_type = TUNER_ABSENT,
258                 .decoder = CX231XX_AVDECODER,
259                 .output_mode = OUT_MODE_VIP11,
260                 .ctl_pin_status_mask = 0xFFFFFFC4,
261                 .agc_analog_digital_select_gpio = 0x1c,
262                 .gpio_pin_status_mask = 0x4001000,
263                 .norm = V4L2_STD_PAL,
264
265                 .input = {{
266                                 .type = CX231XX_VMUX_COMPOSITE1,
267                                 .vmux = CX231XX_VIN_2_1,
268                                 .amux = CX231XX_AMUX_LINE_IN,
269                                 .gpio = NULL,
270                         }, {
271                                 .type = CX231XX_VMUX_SVIDEO,
272                                 .vmux = CX231XX_VIN_1_1 |
273                                         (CX231XX_VIN_1_2 << 8) |
274                                         CX25840_SVIDEO_ON,
275                                 .amux = CX231XX_AMUX_LINE_IN,
276                                 .gpio = NULL,
277                         }
278                 },
279         },
280         [CX231XX_BOARD_CNXT_RDE_250] = {
281                 .name = "Conexant Hybrid TV - rde 250",
282                 .tuner_type = TUNER_XC5000,
283                 .tuner_addr = 0x61,
284                 .tuner_gpio = RDE250_XCV_TUNER,
285                 .tuner_sif_gpio = 0x05,
286                 .tuner_scl_gpio = 0x1a,
287                 .tuner_sda_gpio = 0x1b,
288                 .decoder = CX231XX_AVDECODER,
289                 .output_mode = OUT_MODE_VIP11,
290                 .demod_xfer_mode = 0,
291                 .ctl_pin_status_mask = 0xFFFFFFC4,
292                 .agc_analog_digital_select_gpio = 0x0c,
293                 .gpio_pin_status_mask = 0x4001000,
294                 .tuner_i2c_master = 1,
295                 .demod_i2c_master = 2,
296                 .has_dvb = 1,
297                 .demod_addr = 0x02,
298                 .norm = V4L2_STD_PAL,
299
300                 .input = {{
301                                 .type = CX231XX_VMUX_TELEVISION,
302                                 .vmux = CX231XX_VIN_2_1,
303                                 .amux = CX231XX_AMUX_VIDEO,
304                                 .gpio = NULL,
305                         }
306                 },
307         },
308         [CX231XX_BOARD_CNXT_RDU_250] = {
309                 .name = "Conexant Hybrid TV - RDU 250",
310                 .tuner_type = TUNER_XC5000,
311                 .tuner_addr = 0x61,
312                 .tuner_gpio = RDE250_XCV_TUNER,
313                 .tuner_sif_gpio = 0x05,
314                 .tuner_scl_gpio = 0x1a,
315                 .tuner_sda_gpio = 0x1b,
316                 .decoder = CX231XX_AVDECODER,
317                 .output_mode = OUT_MODE_VIP11,
318                 .demod_xfer_mode = 0,
319                 .ctl_pin_status_mask = 0xFFFFFFC4,
320                 .agc_analog_digital_select_gpio = 0x0c,
321                 .gpio_pin_status_mask = 0x4001000,
322                 .tuner_i2c_master = 1,
323                 .demod_i2c_master = 2,
324                 .has_dvb = 1,
325                 .demod_addr = 0x32,
326                 .norm = V4L2_STD_NTSC,
327
328                 .input = {{
329                                 .type = CX231XX_VMUX_TELEVISION,
330                                 .vmux = CX231XX_VIN_2_1,
331                                 .amux = CX231XX_AMUX_VIDEO,
332                                 .gpio = NULL,
333                         }
334                 },
335         },
336         [CX231XX_BOARD_HAUPPAUGE_EXETER] = {
337                 .name = "Hauppauge EXETER",
338                 .tuner_type = TUNER_NXP_TDA18271,
339                 .tuner_addr = 0x60,
340                 .tuner_gpio = RDE250_XCV_TUNER,
341                 .tuner_sif_gpio = 0x05,
342                 .tuner_scl_gpio = 0x1a,
343                 .tuner_sda_gpio = 0x1b,
344                 .decoder = CX231XX_AVDECODER,
345                 .output_mode = OUT_MODE_VIP11,
346                 .demod_xfer_mode = 0,
347                 .ctl_pin_status_mask = 0xFFFFFFC4,
348                 .agc_analog_digital_select_gpio = 0x0c,
349                 .gpio_pin_status_mask = 0x4001000,
350                 .tuner_i2c_master = 1,
351                 .demod_i2c_master = 2,
352                 .has_dvb = 1,
353                 .demod_addr = 0x0e,
354                 .norm = V4L2_STD_NTSC,
355
356                 .input = {{
357                         .type = CX231XX_VMUX_TELEVISION,
358                         .vmux = CX231XX_VIN_3_1,
359                         .amux = CX231XX_AMUX_VIDEO,
360                         .gpio = 0,
361                 }, {
362                         .type = CX231XX_VMUX_COMPOSITE1,
363                         .vmux = CX231XX_VIN_2_1,
364                         .amux = CX231XX_AMUX_LINE_IN,
365                         .gpio = 0,
366                 }, {
367                         .type = CX231XX_VMUX_SVIDEO,
368                         .vmux = CX231XX_VIN_1_1 |
369                                 (CX231XX_VIN_1_2 << 8) |
370                                 CX25840_SVIDEO_ON,
371                         .amux = CX231XX_AMUX_LINE_IN,
372                         .gpio = 0,
373                 } },
374         },
375         [CX231XX_BOARD_HAUPPAUGE_USBLIVE2] = {
376                 .name = "Hauppauge USB Live 2",
377                 .tuner_type = TUNER_ABSENT,
378                 .decoder = CX231XX_AVDECODER,
379                 .output_mode = OUT_MODE_VIP11,
380                 .demod_xfer_mode = 0,
381                 .ctl_pin_status_mask = 0xFFFFFFC4,
382                 .agc_analog_digital_select_gpio = 0x0c,
383                 .gpio_pin_status_mask = 0x4001000,
384                 .norm = V4L2_STD_NTSC,
385                 .input = {{
386                         .type = CX231XX_VMUX_COMPOSITE1,
387                         .vmux = CX231XX_VIN_2_1,
388                         .amux = CX231XX_AMUX_LINE_IN,
389                         .gpio = 0,
390                 }, {
391                         .type = CX231XX_VMUX_SVIDEO,
392                         .vmux = CX231XX_VIN_1_1 |
393                                 (CX231XX_VIN_1_2 << 8) |
394                                 CX25840_SVIDEO_ON,
395                         .amux = CX231XX_AMUX_LINE_IN,
396                         .gpio = 0,
397                 } },
398         },
399         [CX231XX_BOARD_PV_PLAYTV_USB_HYBRID] = {
400                 .name = "Pixelview PlayTV USB Hybrid",
401                 .tuner_type = TUNER_NXP_TDA18271,
402                 .tuner_addr = 0x60,
403                 .decoder = CX231XX_AVDECODER,
404                 .output_mode = OUT_MODE_VIP11,
405                 .demod_xfer_mode = 0,
406                 .ctl_pin_status_mask = 0xFFFFFFC4,
407                 .agc_analog_digital_select_gpio = 0x00, /* According with PV cxPolaris.inf file */
408                 .tuner_sif_gpio = -1,
409                 .tuner_scl_gpio = -1,
410                 .tuner_sda_gpio = -1,
411                 .gpio_pin_status_mask = 0x4001000,
412                 .tuner_i2c_master = 2,
413                 .demod_i2c_master = 1,
414                 .ir_i2c_master = 2,
415                 .rc_map_name = RC_MAP_PIXELVIEW_002T,
416                 .has_dvb = 1,
417                 .demod_addr = 0x10,
418                 .norm = V4L2_STD_PAL_M,
419                 .input = {{
420                         .type = CX231XX_VMUX_TELEVISION,
421                         .vmux = CX231XX_VIN_3_1,
422                         .amux = CX231XX_AMUX_VIDEO,
423                         .gpio = 0,
424                 }, {
425                         .type = CX231XX_VMUX_COMPOSITE1,
426                         .vmux = CX231XX_VIN_2_1,
427                         .amux = CX231XX_AMUX_LINE_IN,
428                         .gpio = 0,
429                 }, {
430                         .type = CX231XX_VMUX_SVIDEO,
431                         .vmux = CX231XX_VIN_1_1 |
432                                 (CX231XX_VIN_1_2 << 8) |
433                                 CX25840_SVIDEO_ON,
434                         .amux = CX231XX_AMUX_LINE_IN,
435                         .gpio = 0,
436                 } },
437         },
438 };
439 const unsigned int cx231xx_bcount = ARRAY_SIZE(cx231xx_boards);
440
441 /* table of devices that work with this driver */
442 struct usb_device_id cx231xx_id_table[] = {
443         {USB_DEVICE(0x0572, 0x5A3C),
444          .driver_info = CX231XX_BOARD_UNKNOWN},
445         {USB_DEVICE(0x0572, 0x58A2),
446          .driver_info = CX231XX_BOARD_CNXT_CARRAERA},
447         {USB_DEVICE(0x0572, 0x58A1),
448          .driver_info = CX231XX_BOARD_CNXT_SHELBY},
449         {USB_DEVICE(0x0572, 0x58A4),
450          .driver_info = CX231XX_BOARD_CNXT_RDE_253S},
451         {USB_DEVICE(0x0572, 0x58A5),
452          .driver_info = CX231XX_BOARD_CNXT_RDU_253S},
453         {USB_DEVICE(0x0572, 0x58A6),
454          .driver_info = CX231XX_BOARD_CNXT_VIDEO_GRABBER},
455         {USB_DEVICE(0x0572, 0x589E),
456          .driver_info = CX231XX_BOARD_CNXT_RDE_250},
457         {USB_DEVICE(0x0572, 0x58A0),
458          .driver_info = CX231XX_BOARD_CNXT_RDU_250},
459         {USB_DEVICE(0x2040, 0xb120),
460          .driver_info = CX231XX_BOARD_HAUPPAUGE_EXETER},
461         {USB_DEVICE(0x2040, 0xb140),
462          .driver_info = CX231XX_BOARD_HAUPPAUGE_EXETER},
463         {USB_DEVICE(0x2040, 0xc200),
464          .driver_info = CX231XX_BOARD_HAUPPAUGE_USBLIVE2},
465         {USB_DEVICE_VER(USB_VID_PIXELVIEW, USB_PID_PIXELVIEW_SBTVD, 0x4000, 0x4001),
466          .driver_info = CX231XX_BOARD_PV_PLAYTV_USB_HYBRID},
467         {},
468 };
469
470 MODULE_DEVICE_TABLE(usb, cx231xx_id_table);
471
472 /* cx231xx_tuner_callback
473  * will be used to reset XC5000 tuner using GPIO pin
474  */
475
476 int cx231xx_tuner_callback(void *ptr, int component, int command, int arg)
477 {
478         int rc = 0;
479         struct cx231xx *dev = ptr;
480
481         if (dev->tuner_type == TUNER_XC5000) {
482                 if (command == XC5000_TUNER_RESET) {
483                         cx231xx_info
484                                 ("Tuner CB: RESET: cmd %d : tuner type %d \n",
485                                  command, dev->tuner_type);
486                         cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit,
487                                                1);
488                         msleep(10);
489                         cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit,
490                                                0);
491                         msleep(330);
492                         cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit,
493                                                1);
494                         msleep(10);
495                 }
496         } else if (dev->tuner_type == TUNER_NXP_TDA18271) {
497                 switch (command) {
498                 case TDA18271_CALLBACK_CMD_AGC_ENABLE:
499                         if (dev->model == CX231XX_BOARD_PV_PLAYTV_USB_HYBRID)
500                                 rc = cx231xx_set_agc_analog_digital_mux_select(dev, arg);
501                         break;
502                 default:
503                         rc = -EINVAL;
504                         break;
505                 }
506         }
507         return rc;
508 }
509 EXPORT_SYMBOL_GPL(cx231xx_tuner_callback);
510
511 void cx231xx_reset_out(struct cx231xx *dev)
512 {
513         cx231xx_set_gpio_value(dev, CX23417_RESET, 1);
514         msleep(200);
515         cx231xx_set_gpio_value(dev, CX23417_RESET, 0);
516         msleep(200);
517         cx231xx_set_gpio_value(dev, CX23417_RESET, 1);
518 }
519 void cx231xx_enable_OSC(struct cx231xx *dev)
520 {
521         cx231xx_set_gpio_value(dev, CX23417_OSC_EN, 1);
522 }
523 void cx231xx_sleep_s5h1432(struct cx231xx *dev)
524 {
525         cx231xx_set_gpio_value(dev, SLEEP_S5H1432, 0);
526 }
527
528 static inline void cx231xx_set_model(struct cx231xx *dev)
529 {
530         memcpy(&dev->board, &cx231xx_boards[dev->model], sizeof(dev->board));
531 }
532
533 /* Since cx231xx_pre_card_setup() requires a proper dev->model,
534  * this won't work for boards with generic PCI IDs
535  */
536 void cx231xx_pre_card_setup(struct cx231xx *dev)
537 {
538
539         cx231xx_set_model(dev);
540
541         cx231xx_info("Identified as %s (card=%d)\n",
542                      dev->board.name, dev->model);
543
544         /* set the direction for GPIO pins */
545         if (dev->board.tuner_gpio) {
546                 cx231xx_set_gpio_direction(dev, dev->board.tuner_gpio->bit, 1);
547                 cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit, 1);
548         }
549         if (dev->board.tuner_sif_gpio >= 0)
550                 cx231xx_set_gpio_direction(dev, dev->board.tuner_sif_gpio, 1);
551
552         /* request some modules if any required */
553
554         /* set the mode to Analog mode initially */
555         cx231xx_set_mode(dev, CX231XX_ANALOG_MODE);
556
557         /* Unlock device */
558         /* cx231xx_set_mode(dev, CX231XX_SUSPEND); */
559
560 }
561
562 static void cx231xx_config_tuner(struct cx231xx *dev)
563 {
564         struct tuner_setup tun_setup;
565         struct v4l2_frequency f;
566
567         if (dev->tuner_type == TUNER_ABSENT)
568                 return;
569
570         tun_setup.mode_mask = T_ANALOG_TV | T_RADIO;
571         tun_setup.type = dev->tuner_type;
572         tun_setup.addr = dev->tuner_addr;
573         tun_setup.tuner_callback = cx231xx_tuner_callback;
574
575         tuner_call(dev, tuner, s_type_addr, &tun_setup);
576
577 #if 0
578         if (tun_setup.type == TUNER_XC5000) {
579                 static struct xc2028_ctrl ctrl = {
580                         .fname = XC5000_DEFAULT_FIRMWARE,
581                         .max_len = 64,
582                         .demod = 0;
583                 };
584                 struct v4l2_priv_tun_config cfg = {
585                         .tuner = dev->tuner_type,
586                         .priv = &ctrl,
587                 };
588                 tuner_call(dev, tuner, s_config, &cfg);
589         }
590 #endif
591         /* configure tuner */
592         f.tuner = 0;
593         f.type = V4L2_TUNER_ANALOG_TV;
594         f.frequency = 9076;     /* just a magic number */
595         dev->ctl_freq = f.frequency;
596         call_all(dev, tuner, s_frequency, &f);
597
598 }
599
600 void cx231xx_card_setup(struct cx231xx *dev)
601 {
602
603         cx231xx_set_model(dev);
604
605         dev->tuner_type = cx231xx_boards[dev->model].tuner_type;
606         if (cx231xx_boards[dev->model].tuner_addr)
607                 dev->tuner_addr = cx231xx_boards[dev->model].tuner_addr;
608
609         /* request some modules */
610         if (dev->board.decoder == CX231XX_AVDECODER) {
611                 dev->sd_cx25840 = v4l2_i2c_new_subdev(&dev->v4l2_dev,
612                                         &dev->i2c_bus[0].i2c_adap,
613                                         "cx25840", 0x88 >> 1, NULL);
614                 if (dev->sd_cx25840 == NULL)
615                         cx231xx_info("cx25840 subdev registration failure\n");
616                 cx25840_call(dev, core, load_fw);
617
618         }
619
620         /* Initialize the tuner */
621         if (dev->board.tuner_type != TUNER_ABSENT) {
622                 dev->sd_tuner = v4l2_i2c_new_subdev(&dev->v4l2_dev,
623                                                     &dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap,
624                                                     "tuner",
625                                                     dev->tuner_addr, NULL);
626                 if (dev->sd_tuner == NULL)
627                         cx231xx_info("tuner subdev registration failure\n");
628                 else
629                         cx231xx_config_tuner(dev);
630         }
631 }
632
633 /*
634  * cx231xx_config()
635  * inits registers with sane defaults
636  */
637 int cx231xx_config(struct cx231xx *dev)
638 {
639         /* TBD need to add cx231xx specific code */
640         dev->mute = 1;          /* maybe not the right place... */
641         dev->volume = 0x1f;
642
643         return 0;
644 }
645
646 /*
647  * cx231xx_config_i2c()
648  * configure i2c attached devices
649  */
650 void cx231xx_config_i2c(struct cx231xx *dev)
651 {
652         /* u32 input = INPUT(dev->video_input)->vmux; */
653
654         call_all(dev, video, s_stream, 1);
655 }
656
657 /*
658  * cx231xx_realease_resources()
659  * unregisters the v4l2,i2c and usb devices
660  * called when the device gets disconected or at module unload
661 */
662 void cx231xx_release_resources(struct cx231xx *dev)
663 {
664         cx231xx_release_analog_resources(dev);
665
666         cx231xx_remove_from_devlist(dev);
667
668         /* Release I2C buses */
669         cx231xx_dev_uninit(dev);
670
671         cx231xx_ir_exit(dev);
672
673         usb_put_dev(dev->udev);
674
675         /* Mark device as unused */
676         cx231xx_devused &= ~(1 << dev->devno);
677 }
678
679 /*
680  * cx231xx_init_dev()
681  * allocates and inits the device structs, registers i2c bus and v4l device
682  */
683 static int cx231xx_init_dev(struct cx231xx **devhandle, struct usb_device *udev,
684                             int minor)
685 {
686         struct cx231xx *dev = *devhandle;
687         int retval = -ENOMEM;
688         int errCode;
689         unsigned int maxh, maxw;
690
691         dev->udev = udev;
692         mutex_init(&dev->lock);
693         mutex_init(&dev->ctrl_urb_lock);
694         mutex_init(&dev->gpio_i2c_lock);
695         mutex_init(&dev->i2c_lock);
696
697         spin_lock_init(&dev->video_mode.slock);
698         spin_lock_init(&dev->vbi_mode.slock);
699         spin_lock_init(&dev->sliced_cc_mode.slock);
700
701         init_waitqueue_head(&dev->open);
702         init_waitqueue_head(&dev->wait_frame);
703         init_waitqueue_head(&dev->wait_stream);
704
705         dev->cx231xx_read_ctrl_reg = cx231xx_read_ctrl_reg;
706         dev->cx231xx_write_ctrl_reg = cx231xx_write_ctrl_reg;
707         dev->cx231xx_send_usb_command = cx231xx_send_usb_command;
708         dev->cx231xx_gpio_i2c_read = cx231xx_gpio_i2c_read;
709         dev->cx231xx_gpio_i2c_write = cx231xx_gpio_i2c_write;
710
711         /* Query cx231xx to find what pcb config it is related to */
712         initialize_cx231xx(dev);
713
714         /*To workaround error number=-71 on EP0 for VideoGrabber,
715                  need set alt here.*/
716         if (dev->model == CX231XX_BOARD_CNXT_VIDEO_GRABBER ||
717             dev->model == CX231XX_BOARD_HAUPPAUGE_USBLIVE2) {
718                 cx231xx_set_alt_setting(dev, INDEX_VIDEO, 3);
719                 cx231xx_set_alt_setting(dev, INDEX_VANC, 1);
720         }
721         /* Cx231xx pre card setup */
722         cx231xx_pre_card_setup(dev);
723
724         errCode = cx231xx_config(dev);
725         if (errCode) {
726                 cx231xx_errdev("error configuring device\n");
727                 return -ENOMEM;
728         }
729
730         /* set default norm */
731         dev->norm = dev->board.norm;
732
733         /* register i2c bus */
734         errCode = cx231xx_dev_init(dev);
735         if (errCode < 0) {
736                 cx231xx_dev_uninit(dev);
737                 cx231xx_errdev("%s: cx231xx_i2c_register - errCode [%d]!\n",
738                                __func__, errCode);
739                 return errCode;
740         }
741
742         /* Do board specific init */
743         cx231xx_card_setup(dev);
744
745         /* configure the device */
746         cx231xx_config_i2c(dev);
747
748         maxw = norm_maxw(dev);
749         maxh = norm_maxh(dev);
750
751         /* set default image size */
752         dev->width = maxw;
753         dev->height = maxh;
754         dev->interlaced = 0;
755         dev->video_input = 0;
756
757         errCode = cx231xx_config(dev);
758         if (errCode < 0) {
759                 cx231xx_errdev("%s: cx231xx_config - errCode [%d]!\n",
760                                __func__, errCode);
761                 return errCode;
762         }
763
764         /* init video dma queues */
765         INIT_LIST_HEAD(&dev->video_mode.vidq.active);
766         INIT_LIST_HEAD(&dev->video_mode.vidq.queued);
767
768         /* init vbi dma queues */
769         INIT_LIST_HEAD(&dev->vbi_mode.vidq.active);
770         INIT_LIST_HEAD(&dev->vbi_mode.vidq.queued);
771
772         /* Reset other chips required if they are tied up with GPIO pins */
773         cx231xx_add_into_devlist(dev);
774
775         if (dev->model == CX231XX_BOARD_CNXT_VIDEO_GRABBER) {
776                 printk(KERN_INFO "attach 417 %d\n", dev->model);
777                 if (cx231xx_417_register(dev) < 0) {
778                         printk(KERN_ERR
779                                 "%s() Failed to register 417 on VID_B\n",
780                                __func__);
781                 }
782         }
783
784         retval = cx231xx_register_analog_devices(dev);
785         if (retval < 0) {
786                 cx231xx_release_resources(dev);
787                 return retval;
788         }
789
790         cx231xx_ir_init(dev);
791
792         cx231xx_init_extension(dev);
793
794         return 0;
795 }
796
797 #if defined(CONFIG_MODULES) && defined(MODULE)
798 static void request_module_async(struct work_struct *work)
799 {
800         struct cx231xx *dev = container_of(work,
801                                            struct cx231xx, request_module_wk);
802
803         if (dev->has_alsa_audio)
804                 request_module("cx231xx-alsa");
805
806         if (dev->board.has_dvb)
807                 request_module("cx231xx-dvb");
808
809 }
810
811 static void request_modules(struct cx231xx *dev)
812 {
813         INIT_WORK(&dev->request_module_wk, request_module_async);
814         schedule_work(&dev->request_module_wk);
815 }
816 #else
817 #define request_modules(dev)
818 #endif /* CONFIG_MODULES */
819
820 /*
821  * cx231xx_usb_probe()
822  * checks for supported devices
823  */
824 static int cx231xx_usb_probe(struct usb_interface *interface,
825                              const struct usb_device_id *id)
826 {
827         struct usb_device *udev;
828         struct usb_interface *uif;
829         struct cx231xx *dev = NULL;
830         int retval = -ENODEV;
831         int nr = 0, ifnum;
832         int i, isoc_pipe = 0;
833         char *speed;
834         char descr[255] = "";
835         struct usb_interface *lif = NULL;
836         struct usb_interface_assoc_descriptor *assoc_desc;
837
838         udev = usb_get_dev(interface_to_usbdev(interface));
839         ifnum = interface->altsetting[0].desc.bInterfaceNumber;
840
841         if (ifnum == 1) {
842                 /*
843                  * Interface number 0 - IR interface
844                  */
845                 /* Check to see next free device and mark as used */
846                 nr = find_first_zero_bit(&cx231xx_devused, CX231XX_MAXBOARDS);
847                 cx231xx_devused |= 1 << nr;
848
849                 if (nr >= CX231XX_MAXBOARDS) {
850                         cx231xx_err(DRIVER_NAME
851                  ": Supports only %i cx231xx boards.\n", CX231XX_MAXBOARDS);
852                         cx231xx_devused &= ~(1 << nr);
853                         return -ENOMEM;
854                 }
855
856                 /* allocate memory for our device state and initialize it */
857                 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
858                 if (dev == NULL) {
859                         cx231xx_err(DRIVER_NAME ": out of memory!\n");
860                         cx231xx_devused &= ~(1 << nr);
861                         return -ENOMEM;
862                 }
863
864                 snprintf(dev->name, 29, "cx231xx #%d", nr);
865                 dev->devno = nr;
866                 dev->model = id->driver_info;
867                 dev->video_mode.alt = -1;
868                 dev->interface_count++;
869
870                 /* reset gpio dir and value */
871                 dev->gpio_dir = 0;
872                 dev->gpio_val = 0;
873                 dev->xc_fw_load_done = 0;
874                 dev->has_alsa_audio = 1;
875                 dev->power_mode = -1;
876                 atomic_set(&dev->devlist_count, 0);
877
878                 /* 0 - vbi ; 1 -sliced cc mode */
879                 dev->vbi_or_sliced_cc_mode = 0;
880
881                 /* get maximum no.of IAD interfaces */
882                 assoc_desc = udev->actconfig->intf_assoc[0];
883                 dev->max_iad_interface_count = assoc_desc->bInterfaceCount;
884
885                 /* init CIR module TBD */
886
887                 /* store the current interface */
888                 lif = interface;
889
890                 /*mode_tv: digital=1 or analog=0*/
891                 dev->mode_tv = 0;
892
893                 dev->USE_ISO = transfer_mode;
894
895                 switch (udev->speed) {
896                 case USB_SPEED_LOW:
897                         speed = "1.5";
898                         break;
899                 case USB_SPEED_UNKNOWN:
900                 case USB_SPEED_FULL:
901                         speed = "12";
902                         break;
903                 case USB_SPEED_HIGH:
904                         speed = "480";
905                         break;
906                 default:
907                         speed = "unknown";
908                 }
909
910                 if (udev->manufacturer)
911                         strlcpy(descr, udev->manufacturer, sizeof(descr));
912
913                 if (udev->product) {
914                         if (*descr)
915                                 strlcat(descr, " ", sizeof(descr));
916                         strlcat(descr, udev->product, sizeof(descr));
917                 }
918                 if (*descr)
919                         strlcat(descr, " ", sizeof(descr));
920
921                 cx231xx_info("New device %s@ %s Mbps "
922                      "(%04x:%04x) with %d interfaces\n",
923                      descr,
924                      speed,
925                      le16_to_cpu(udev->descriptor.idVendor),
926                      le16_to_cpu(udev->descriptor.idProduct),
927                      dev->max_iad_interface_count);
928
929                 /* store the interface 0 back */
930                 lif = udev->actconfig->interface[0];
931
932                 /* increment interface count */
933                 dev->interface_count++;
934
935                 /* get device number */
936                 nr = dev->devno;
937
938                 assoc_desc = udev->actconfig->intf_assoc[0];
939                 if (assoc_desc->bFirstInterface != ifnum) {
940                         cx231xx_err(DRIVER_NAME ": Not found "
941                                     "matching IAD interface\n");
942                         return -ENODEV;
943                 }
944         } else {
945                 return -ENODEV;
946         }
947
948         cx231xx_info("registering interface %d\n", ifnum);
949
950         /* save our data pointer in this interface device */
951         usb_set_intfdata(lif, dev);
952
953         /*
954          * AV device initialization - only done at the last interface
955          */
956
957         /* Create v4l2 device */
958         retval = v4l2_device_register(&interface->dev, &dev->v4l2_dev);
959         if (retval) {
960                 cx231xx_errdev("v4l2_device_register failed\n");
961                 cx231xx_devused &= ~(1 << nr);
962                 kfree(dev);
963                 dev = NULL;
964                 return -EIO;
965         }
966         /* allocate device struct */
967         retval = cx231xx_init_dev(&dev, udev, nr);
968         if (retval) {
969                 cx231xx_devused &= ~(1 << dev->devno);
970                 v4l2_device_unregister(&dev->v4l2_dev);
971                 kfree(dev);
972                 dev = NULL;
973                 usb_set_intfdata(lif, NULL);
974
975                 return retval;
976         }
977
978         /* compute alternate max packet sizes for video */
979         uif = udev->actconfig->interface[dev->current_pcb_config.
980                        hs_config_info[0].interface_info.video_index + 1];
981
982         dev->video_mode.end_point_addr = le16_to_cpu(uif->altsetting[0].
983                         endpoint[isoc_pipe].desc.bEndpointAddress);
984
985         dev->video_mode.num_alt = uif->num_altsetting;
986         cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
987                      dev->video_mode.end_point_addr,
988                      dev->video_mode.num_alt);
989         dev->video_mode.alt_max_pkt_size =
990                 kmalloc(32 * dev->video_mode.num_alt, GFP_KERNEL);
991
992         if (dev->video_mode.alt_max_pkt_size == NULL) {
993                 cx231xx_errdev("out of memory!\n");
994                 cx231xx_devused &= ~(1 << nr);
995                 v4l2_device_unregister(&dev->v4l2_dev);
996                 kfree(dev);
997                 dev = NULL;
998                 return -ENOMEM;
999         }
1000
1001         for (i = 0; i < dev->video_mode.num_alt; i++) {
1002                 u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
1003                                 desc.wMaxPacketSize);
1004                 dev->video_mode.alt_max_pkt_size[i] =
1005                     (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
1006                 cx231xx_info("Alternate setting %i, max size= %i\n", i,
1007                              dev->video_mode.alt_max_pkt_size[i]);
1008         }
1009
1010         /* compute alternate max packet sizes for vbi */
1011         uif = udev->actconfig->interface[dev->current_pcb_config.
1012                                        hs_config_info[0].interface_info.
1013                                        vanc_index + 1];
1014
1015         dev->vbi_mode.end_point_addr =
1016             le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc.
1017                         bEndpointAddress);
1018
1019         dev->vbi_mode.num_alt = uif->num_altsetting;
1020         cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
1021                      dev->vbi_mode.end_point_addr,
1022                      dev->vbi_mode.num_alt);
1023         dev->vbi_mode.alt_max_pkt_size =
1024             kmalloc(32 * dev->vbi_mode.num_alt, GFP_KERNEL);
1025
1026         if (dev->vbi_mode.alt_max_pkt_size == NULL) {
1027                 cx231xx_errdev("out of memory!\n");
1028                 cx231xx_devused &= ~(1 << nr);
1029                 v4l2_device_unregister(&dev->v4l2_dev);
1030                 kfree(dev);
1031                 dev = NULL;
1032                 return -ENOMEM;
1033         }
1034
1035         for (i = 0; i < dev->vbi_mode.num_alt; i++) {
1036                 u16 tmp =
1037                     le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
1038                                 desc.wMaxPacketSize);
1039                 dev->vbi_mode.alt_max_pkt_size[i] =
1040                     (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
1041                 cx231xx_info("Alternate setting %i, max size= %i\n", i,
1042                              dev->vbi_mode.alt_max_pkt_size[i]);
1043         }
1044
1045         /* compute alternate max packet sizes for sliced CC */
1046         uif = udev->actconfig->interface[dev->current_pcb_config.
1047                                        hs_config_info[0].interface_info.
1048                                        hanc_index + 1];
1049
1050         dev->sliced_cc_mode.end_point_addr =
1051             le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc.
1052                         bEndpointAddress);
1053
1054         dev->sliced_cc_mode.num_alt = uif->num_altsetting;
1055         cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
1056                      dev->sliced_cc_mode.end_point_addr,
1057                      dev->sliced_cc_mode.num_alt);
1058         dev->sliced_cc_mode.alt_max_pkt_size =
1059                 kmalloc(32 * dev->sliced_cc_mode.num_alt, GFP_KERNEL);
1060
1061         if (dev->sliced_cc_mode.alt_max_pkt_size == NULL) {
1062                 cx231xx_errdev("out of memory!\n");
1063                 cx231xx_devused &= ~(1 << nr);
1064                 v4l2_device_unregister(&dev->v4l2_dev);
1065                 kfree(dev);
1066                 dev = NULL;
1067                 return -ENOMEM;
1068         }
1069
1070         for (i = 0; i < dev->sliced_cc_mode.num_alt; i++) {
1071                 u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
1072                                 desc.wMaxPacketSize);
1073                 dev->sliced_cc_mode.alt_max_pkt_size[i] =
1074                     (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
1075                 cx231xx_info("Alternate setting %i, max size= %i\n", i,
1076                              dev->sliced_cc_mode.alt_max_pkt_size[i]);
1077         }
1078
1079         if (dev->current_pcb_config.ts1_source != 0xff) {
1080                 /* compute alternate max packet sizes for TS1 */
1081                 uif = udev->actconfig->interface[dev->current_pcb_config.
1082                                                hs_config_info[0].
1083                                                interface_info.
1084                                                ts1_index + 1];
1085
1086                 dev->ts1_mode.end_point_addr =
1087                     le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].
1088                                 desc.bEndpointAddress);
1089
1090                 dev->ts1_mode.num_alt = uif->num_altsetting;
1091                 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
1092                              dev->ts1_mode.end_point_addr,
1093                              dev->ts1_mode.num_alt);
1094                 dev->ts1_mode.alt_max_pkt_size =
1095                         kmalloc(32 * dev->ts1_mode.num_alt, GFP_KERNEL);
1096
1097                 if (dev->ts1_mode.alt_max_pkt_size == NULL) {
1098                         cx231xx_errdev("out of memory!\n");
1099                         cx231xx_devused &= ~(1 << nr);
1100                         v4l2_device_unregister(&dev->v4l2_dev);
1101                         kfree(dev);
1102                         dev = NULL;
1103                         return -ENOMEM;
1104                 }
1105
1106                 for (i = 0; i < dev->ts1_mode.num_alt; i++) {
1107                         u16 tmp = le16_to_cpu(uif->altsetting[i].
1108                                                 endpoint[isoc_pipe].desc.
1109                                                 wMaxPacketSize);
1110                         dev->ts1_mode.alt_max_pkt_size[i] =
1111                             (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
1112                         cx231xx_info("Alternate setting %i, max size= %i\n", i,
1113                                      dev->ts1_mode.alt_max_pkt_size[i]);
1114                 }
1115         }
1116
1117         if (dev->model == CX231XX_BOARD_CNXT_VIDEO_GRABBER) {
1118                 cx231xx_enable_OSC(dev);
1119                 cx231xx_reset_out(dev);
1120                 cx231xx_set_alt_setting(dev, INDEX_VIDEO, 3);
1121         }
1122
1123         if (dev->model == CX231XX_BOARD_CNXT_RDE_253S)
1124                 cx231xx_sleep_s5h1432(dev);
1125
1126         /* load other modules required */
1127         request_modules(dev);
1128
1129         return 0;
1130 }
1131
1132 /*
1133  * cx231xx_usb_disconnect()
1134  * called when the device gets diconencted
1135  * video device will be unregistered on v4l2_close in case it is still open
1136  */
1137 static void cx231xx_usb_disconnect(struct usb_interface *interface)
1138 {
1139         struct cx231xx *dev;
1140
1141         dev = usb_get_intfdata(interface);
1142         usb_set_intfdata(interface, NULL);
1143
1144         if (!dev)
1145                 return;
1146
1147         if (!dev->udev)
1148                 return;
1149
1150         /* delete v4l2 device */
1151         v4l2_device_unregister(&dev->v4l2_dev);
1152
1153         /* wait until all current v4l2 io is finished then deallocate
1154            resources */
1155         mutex_lock(&dev->lock);
1156
1157         wake_up_interruptible_all(&dev->open);
1158
1159         if (dev->users) {
1160                 cx231xx_warn
1161                     ("device %s is open! Deregistration and memory "
1162                      "deallocation are deferred on close.\n",
1163                      video_device_node_name(dev->vdev));
1164
1165                 dev->state |= DEV_MISCONFIGURED;
1166                 if (dev->USE_ISO)
1167                         cx231xx_uninit_isoc(dev);
1168                 else
1169                         cx231xx_uninit_bulk(dev);
1170                 dev->state |= DEV_DISCONNECTED;
1171                 wake_up_interruptible(&dev->wait_frame);
1172                 wake_up_interruptible(&dev->wait_stream);
1173         } else {
1174                 dev->state |= DEV_DISCONNECTED;
1175                 cx231xx_release_resources(dev);
1176         }
1177
1178         cx231xx_close_extension(dev);
1179
1180         mutex_unlock(&dev->lock);
1181
1182         if (!dev->users) {
1183                 kfree(dev->video_mode.alt_max_pkt_size);
1184                 kfree(dev->vbi_mode.alt_max_pkt_size);
1185                 kfree(dev->sliced_cc_mode.alt_max_pkt_size);
1186                 kfree(dev->ts1_mode.alt_max_pkt_size);
1187                 kfree(dev);
1188                 dev = NULL;
1189         }
1190 }
1191
1192 static struct usb_driver cx231xx_usb_driver = {
1193         .name = "cx231xx",
1194         .probe = cx231xx_usb_probe,
1195         .disconnect = cx231xx_usb_disconnect,
1196         .id_table = cx231xx_id_table,
1197 };
1198
1199 static int __init cx231xx_module_init(void)
1200 {
1201         int result;
1202
1203         printk(KERN_INFO DRIVER_NAME " v4l2 driver loaded.\n");
1204
1205         /* register this driver with the USB subsystem */
1206         result = usb_register(&cx231xx_usb_driver);
1207         if (result)
1208                 cx231xx_err(DRIVER_NAME
1209                             " usb_register failed. Error number %d.\n", result);
1210
1211         return result;
1212 }
1213
1214 static void __exit cx231xx_module_exit(void)
1215 {
1216         /* deregister this driver with the USB subsystem */
1217         usb_deregister(&cx231xx_usb_driver);
1218 }
1219
1220 module_init(cx231xx_module_init);
1221 module_exit(cx231xx_module_exit);