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