]> git.karo-electronics.de Git - linux-beck.git/blob - drivers/media/video/cx231xx/cx231xx-cards.c
[media] cx231xx: Properly name rc_map name
[linux-beck.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_NEW,
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                 goto fail_reg_devices;
788         }
789
790         cx231xx_ir_init(dev);
791
792         cx231xx_init_extension(dev);
793
794         return 0;
795
796 fail_reg_devices:
797         mutex_unlock(&dev->lock);
798         return retval;
799 }
800
801 #if defined(CONFIG_MODULES) && defined(MODULE)
802 static void request_module_async(struct work_struct *work)
803 {
804         struct cx231xx *dev = container_of(work,
805                                            struct cx231xx, request_module_wk);
806
807         if (dev->has_alsa_audio)
808                 request_module("cx231xx-alsa");
809
810         if (dev->board.has_dvb)
811                 request_module("cx231xx-dvb");
812
813 }
814
815 static void request_modules(struct cx231xx *dev)
816 {
817         INIT_WORK(&dev->request_module_wk, request_module_async);
818         schedule_work(&dev->request_module_wk);
819 }
820 #else
821 #define request_modules(dev)
822 #endif /* CONFIG_MODULES */
823
824 /*
825  * cx231xx_usb_probe()
826  * checks for supported devices
827  */
828 static int cx231xx_usb_probe(struct usb_interface *interface,
829                              const struct usb_device_id *id)
830 {
831         struct usb_device *udev;
832         struct usb_interface *uif;
833         struct cx231xx *dev = NULL;
834         int retval = -ENODEV;
835         int nr = 0, ifnum;
836         int i, isoc_pipe = 0;
837         char *speed;
838         char descr[255] = "";
839         struct usb_interface *lif = NULL;
840         struct usb_interface_assoc_descriptor *assoc_desc;
841
842         udev = usb_get_dev(interface_to_usbdev(interface));
843         ifnum = interface->altsetting[0].desc.bInterfaceNumber;
844
845         if (ifnum == 1) {
846                 /*
847                  * Interface number 0 - IR interface
848                  */
849                 /* Check to see next free device and mark as used */
850                 nr = find_first_zero_bit(&cx231xx_devused, CX231XX_MAXBOARDS);
851                 cx231xx_devused |= 1 << nr;
852
853                 if (nr >= CX231XX_MAXBOARDS) {
854                         cx231xx_err(DRIVER_NAME
855                  ": Supports only %i cx231xx boards.\n", CX231XX_MAXBOARDS);
856                         cx231xx_devused &= ~(1 << nr);
857                         return -ENOMEM;
858                 }
859
860                 /* allocate memory for our device state and initialize it */
861                 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
862                 if (dev == NULL) {
863                         cx231xx_err(DRIVER_NAME ": out of memory!\n");
864                         cx231xx_devused &= ~(1 << nr);
865                         return -ENOMEM;
866                 }
867
868                 snprintf(dev->name, 29, "cx231xx #%d", nr);
869                 dev->devno = nr;
870                 dev->model = id->driver_info;
871                 dev->video_mode.alt = -1;
872                 dev->interface_count++;
873
874                 /* reset gpio dir and value */
875                 dev->gpio_dir = 0;
876                 dev->gpio_val = 0;
877                 dev->xc_fw_load_done = 0;
878                 dev->has_alsa_audio = 1;
879                 dev->power_mode = -1;
880                 atomic_set(&dev->devlist_count, 0);
881
882                 /* 0 - vbi ; 1 -sliced cc mode */
883                 dev->vbi_or_sliced_cc_mode = 0;
884
885                 /* get maximum no.of IAD interfaces */
886                 assoc_desc = udev->actconfig->intf_assoc[0];
887                 dev->max_iad_interface_count = assoc_desc->bInterfaceCount;
888
889                 /* init CIR module TBD */
890
891                 /* store the current interface */
892                 lif = interface;
893
894                 /*mode_tv: digital=1 or analog=0*/
895                 dev->mode_tv = 0;
896
897                 dev->USE_ISO = transfer_mode;
898
899                 switch (udev->speed) {
900                 case USB_SPEED_LOW:
901                         speed = "1.5";
902                         break;
903                 case USB_SPEED_UNKNOWN:
904                 case USB_SPEED_FULL:
905                         speed = "12";
906                         break;
907                 case USB_SPEED_HIGH:
908                         speed = "480";
909                         break;
910                 default:
911                         speed = "unknown";
912                 }
913
914                 if (udev->manufacturer)
915                         strlcpy(descr, udev->manufacturer, sizeof(descr));
916
917                 if (udev->product) {
918                         if (*descr)
919                                 strlcat(descr, " ", sizeof(descr));
920                         strlcat(descr, udev->product, sizeof(descr));
921                 }
922                 if (*descr)
923                         strlcat(descr, " ", sizeof(descr));
924
925                 cx231xx_info("New device %s@ %s Mbps "
926                      "(%04x:%04x) with %d interfaces\n",
927                      descr,
928                      speed,
929                      le16_to_cpu(udev->descriptor.idVendor),
930                      le16_to_cpu(udev->descriptor.idProduct),
931                      dev->max_iad_interface_count);
932
933                 /* store the interface 0 back */
934                 lif = udev->actconfig->interface[0];
935
936                 /* increment interface count */
937                 dev->interface_count++;
938
939                 /* get device number */
940                 nr = dev->devno;
941
942                 assoc_desc = udev->actconfig->intf_assoc[0];
943                 if (assoc_desc->bFirstInterface != ifnum) {
944                         cx231xx_err(DRIVER_NAME ": Not found "
945                                     "matching IAD interface\n");
946                         return -ENODEV;
947                 }
948         } else {
949                 return -ENODEV;
950         }
951
952         cx231xx_info("registering interface %d\n", ifnum);
953
954         /* save our data pointer in this interface device */
955         usb_set_intfdata(lif, dev);
956
957         /*
958          * AV device initialization - only done at the last interface
959          */
960
961         /* Create v4l2 device */
962         retval = v4l2_device_register(&interface->dev, &dev->v4l2_dev);
963         if (retval) {
964                 cx231xx_errdev("v4l2_device_register failed\n");
965                 cx231xx_devused &= ~(1 << nr);
966                 kfree(dev);
967                 dev = NULL;
968                 return -EIO;
969         }
970         /* allocate device struct */
971         retval = cx231xx_init_dev(&dev, udev, nr);
972         if (retval) {
973                 cx231xx_devused &= ~(1 << dev->devno);
974                 v4l2_device_unregister(&dev->v4l2_dev);
975                 kfree(dev);
976                 dev = NULL;
977                 usb_set_intfdata(lif, NULL);
978
979                 return retval;
980         }
981
982         /* compute alternate max packet sizes for video */
983         uif = udev->actconfig->interface[dev->current_pcb_config.
984                        hs_config_info[0].interface_info.video_index + 1];
985
986         dev->video_mode.end_point_addr = le16_to_cpu(uif->altsetting[0].
987                         endpoint[isoc_pipe].desc.bEndpointAddress);
988
989         dev->video_mode.num_alt = uif->num_altsetting;
990         cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
991                      dev->video_mode.end_point_addr,
992                      dev->video_mode.num_alt);
993         dev->video_mode.alt_max_pkt_size =
994                 kmalloc(32 * dev->video_mode.num_alt, GFP_KERNEL);
995
996         if (dev->video_mode.alt_max_pkt_size == NULL) {
997                 cx231xx_errdev("out of memory!\n");
998                 cx231xx_devused &= ~(1 << nr);
999                 v4l2_device_unregister(&dev->v4l2_dev);
1000                 kfree(dev);
1001                 dev = NULL;
1002                 return -ENOMEM;
1003         }
1004
1005         for (i = 0; i < dev->video_mode.num_alt; i++) {
1006                 u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
1007                                 desc.wMaxPacketSize);
1008                 dev->video_mode.alt_max_pkt_size[i] =
1009                     (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
1010                 cx231xx_info("Alternate setting %i, max size= %i\n", i,
1011                              dev->video_mode.alt_max_pkt_size[i]);
1012         }
1013
1014         /* compute alternate max packet sizes for vbi */
1015         uif = udev->actconfig->interface[dev->current_pcb_config.
1016                                        hs_config_info[0].interface_info.
1017                                        vanc_index + 1];
1018
1019         dev->vbi_mode.end_point_addr =
1020             le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc.
1021                         bEndpointAddress);
1022
1023         dev->vbi_mode.num_alt = uif->num_altsetting;
1024         cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
1025                      dev->vbi_mode.end_point_addr,
1026                      dev->vbi_mode.num_alt);
1027         dev->vbi_mode.alt_max_pkt_size =
1028             kmalloc(32 * dev->vbi_mode.num_alt, GFP_KERNEL);
1029
1030         if (dev->vbi_mode.alt_max_pkt_size == NULL) {
1031                 cx231xx_errdev("out of memory!\n");
1032                 cx231xx_devused &= ~(1 << nr);
1033                 v4l2_device_unregister(&dev->v4l2_dev);
1034                 kfree(dev);
1035                 dev = NULL;
1036                 return -ENOMEM;
1037         }
1038
1039         for (i = 0; i < dev->vbi_mode.num_alt; i++) {
1040                 u16 tmp =
1041                     le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
1042                                 desc.wMaxPacketSize);
1043                 dev->vbi_mode.alt_max_pkt_size[i] =
1044                     (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
1045                 cx231xx_info("Alternate setting %i, max size= %i\n", i,
1046                              dev->vbi_mode.alt_max_pkt_size[i]);
1047         }
1048
1049         /* compute alternate max packet sizes for sliced CC */
1050         uif = udev->actconfig->interface[dev->current_pcb_config.
1051                                        hs_config_info[0].interface_info.
1052                                        hanc_index + 1];
1053
1054         dev->sliced_cc_mode.end_point_addr =
1055             le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc.
1056                         bEndpointAddress);
1057
1058         dev->sliced_cc_mode.num_alt = uif->num_altsetting;
1059         cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
1060                      dev->sliced_cc_mode.end_point_addr,
1061                      dev->sliced_cc_mode.num_alt);
1062         dev->sliced_cc_mode.alt_max_pkt_size =
1063                 kmalloc(32 * dev->sliced_cc_mode.num_alt, GFP_KERNEL);
1064
1065         if (dev->sliced_cc_mode.alt_max_pkt_size == NULL) {
1066                 cx231xx_errdev("out of memory!\n");
1067                 cx231xx_devused &= ~(1 << nr);
1068                 v4l2_device_unregister(&dev->v4l2_dev);
1069                 kfree(dev);
1070                 dev = NULL;
1071                 return -ENOMEM;
1072         }
1073
1074         for (i = 0; i < dev->sliced_cc_mode.num_alt; i++) {
1075                 u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
1076                                 desc.wMaxPacketSize);
1077                 dev->sliced_cc_mode.alt_max_pkt_size[i] =
1078                     (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
1079                 cx231xx_info("Alternate setting %i, max size= %i\n", i,
1080                              dev->sliced_cc_mode.alt_max_pkt_size[i]);
1081         }
1082
1083         if (dev->current_pcb_config.ts1_source != 0xff) {
1084                 /* compute alternate max packet sizes for TS1 */
1085                 uif = udev->actconfig->interface[dev->current_pcb_config.
1086                                                hs_config_info[0].
1087                                                interface_info.
1088                                                ts1_index + 1];
1089
1090                 dev->ts1_mode.end_point_addr =
1091                     le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].
1092                                 desc.bEndpointAddress);
1093
1094                 dev->ts1_mode.num_alt = uif->num_altsetting;
1095                 cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n",
1096                              dev->ts1_mode.end_point_addr,
1097                              dev->ts1_mode.num_alt);
1098                 dev->ts1_mode.alt_max_pkt_size =
1099                         kmalloc(32 * dev->ts1_mode.num_alt, GFP_KERNEL);
1100
1101                 if (dev->ts1_mode.alt_max_pkt_size == NULL) {
1102                         cx231xx_errdev("out of memory!\n");
1103                         cx231xx_devused &= ~(1 << nr);
1104                         v4l2_device_unregister(&dev->v4l2_dev);
1105                         kfree(dev);
1106                         dev = NULL;
1107                         return -ENOMEM;
1108                 }
1109
1110                 for (i = 0; i < dev->ts1_mode.num_alt; i++) {
1111                         u16 tmp = le16_to_cpu(uif->altsetting[i].
1112                                                 endpoint[isoc_pipe].desc.
1113                                                 wMaxPacketSize);
1114                         dev->ts1_mode.alt_max_pkt_size[i] =
1115                             (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
1116                         cx231xx_info("Alternate setting %i, max size= %i\n", i,
1117                                      dev->ts1_mode.alt_max_pkt_size[i]);
1118                 }
1119         }
1120
1121         if (dev->model == CX231XX_BOARD_CNXT_VIDEO_GRABBER) {
1122                 cx231xx_enable_OSC(dev);
1123                 cx231xx_reset_out(dev);
1124                 cx231xx_set_alt_setting(dev, INDEX_VIDEO, 3);
1125         }
1126
1127         if (dev->model == CX231XX_BOARD_CNXT_RDE_253S)
1128                 cx231xx_sleep_s5h1432(dev);
1129
1130         /* load other modules required */
1131         request_modules(dev);
1132
1133         return 0;
1134 }
1135
1136 /*
1137  * cx231xx_usb_disconnect()
1138  * called when the device gets diconencted
1139  * video device will be unregistered on v4l2_close in case it is still open
1140  */
1141 static void cx231xx_usb_disconnect(struct usb_interface *interface)
1142 {
1143         struct cx231xx *dev;
1144
1145         dev = usb_get_intfdata(interface);
1146         usb_set_intfdata(interface, NULL);
1147
1148         if (!dev)
1149                 return;
1150
1151         if (!dev->udev)
1152                 return;
1153
1154         /* delete v4l2 device */
1155         v4l2_device_unregister(&dev->v4l2_dev);
1156
1157         /* wait until all current v4l2 io is finished then deallocate
1158            resources */
1159         mutex_lock(&dev->lock);
1160
1161         wake_up_interruptible_all(&dev->open);
1162
1163         if (dev->users) {
1164                 cx231xx_warn
1165                     ("device %s is open! Deregistration and memory "
1166                      "deallocation are deferred on close.\n",
1167                      video_device_node_name(dev->vdev));
1168
1169                 dev->state |= DEV_MISCONFIGURED;
1170                 if (dev->USE_ISO)
1171                         cx231xx_uninit_isoc(dev);
1172                 else
1173                         cx231xx_uninit_bulk(dev);
1174                 dev->state |= DEV_DISCONNECTED;
1175                 wake_up_interruptible(&dev->wait_frame);
1176                 wake_up_interruptible(&dev->wait_stream);
1177         } else {
1178                 dev->state |= DEV_DISCONNECTED;
1179                 cx231xx_release_resources(dev);
1180         }
1181
1182         cx231xx_close_extension(dev);
1183
1184         mutex_unlock(&dev->lock);
1185
1186         if (!dev->users) {
1187                 kfree(dev->video_mode.alt_max_pkt_size);
1188                 kfree(dev->vbi_mode.alt_max_pkt_size);
1189                 kfree(dev->sliced_cc_mode.alt_max_pkt_size);
1190                 kfree(dev->ts1_mode.alt_max_pkt_size);
1191                 kfree(dev);
1192                 dev = NULL;
1193         }
1194 }
1195
1196 static struct usb_driver cx231xx_usb_driver = {
1197         .name = "cx231xx",
1198         .probe = cx231xx_usb_probe,
1199         .disconnect = cx231xx_usb_disconnect,
1200         .id_table = cx231xx_id_table,
1201 };
1202
1203 static int __init cx231xx_module_init(void)
1204 {
1205         int result;
1206
1207         printk(KERN_INFO DRIVER_NAME " v4l2 driver loaded.\n");
1208
1209         /* register this driver with the USB subsystem */
1210         result = usb_register(&cx231xx_usb_driver);
1211         if (result)
1212                 cx231xx_err(DRIVER_NAME
1213                             " usb_register failed. Error number %d.\n", result);
1214
1215         return result;
1216 }
1217
1218 static void __exit cx231xx_module_exit(void)
1219 {
1220         /* deregister this driver with the USB subsystem */
1221         usb_deregister(&cx231xx_usb_driver);
1222 }
1223
1224 module_init(cx231xx_module_init);
1225 module_exit(cx231xx_module_exit);