]> err.no Git - linux-2.6/commitdiff
Merge ../linux-2.6
authorMauro Carvalho Chehab <mchehab@infradead.org>
Thu, 24 Jul 2008 17:05:50 +0000 (14:05 -0300)
committerMauro Carvalho Chehab <mchehab@infradead.org>
Thu, 24 Jul 2008 17:05:50 +0000 (14:05 -0300)
119 files changed:
Documentation/video4linux/gspca.txt
drivers/media/dvb/dvb-usb/Kconfig
drivers/media/dvb/dvb-usb/Makefile
drivers/media/dvb/dvb-usb/dvb-usb-ids.h
drivers/media/dvb/dvb-usb/dw2102.c [new file with mode: 0644]
drivers/media/dvb/dvb-usb/dw2102.h [new file with mode: 0644]
drivers/media/dvb/frontends/Kconfig
drivers/media/dvb/frontends/Makefile
drivers/media/dvb/frontends/drx397xD.c [new file with mode: 0644]
drivers/media/dvb/frontends/drx397xD.h [new file with mode: 0644]
drivers/media/dvb/frontends/drx397xD_fw.h [new file with mode: 0644]
drivers/media/dvb/frontends/z0194a.h [new file with mode: 0644]
drivers/media/radio/dsbr100.c
drivers/media/radio/miropcm20-radio.c
drivers/media/radio/radio-aimslab.c
drivers/media/radio/radio-aztech.c
drivers/media/radio/radio-cadet.c
drivers/media/radio/radio-gemtek-pci.c
drivers/media/radio/radio-gemtek.c
drivers/media/radio/radio-maestro.c
drivers/media/radio/radio-maxiradio.c
drivers/media/radio/radio-rtrack2.c
drivers/media/radio/radio-sf16fmi.c
drivers/media/radio/radio-sf16fmr2.c
drivers/media/radio/radio-si470x.c
drivers/media/radio/radio-terratec.c
drivers/media/radio/radio-trust.c
drivers/media/radio/radio-typhoon.c
drivers/media/radio/radio-zoltrix.c
drivers/media/video/Kconfig
drivers/media/video/Makefile
drivers/media/video/bt8xx/bttv-driver.c
drivers/media/video/bt8xx/bttv-risc.c
drivers/media/video/bt8xx/bttv-vbi.c
drivers/media/video/bw-qcam.c
drivers/media/video/c-qcam.c
drivers/media/video/cafe_ccic.c
drivers/media/video/compat_ioctl32.c
drivers/media/video/cpia.h
drivers/media/video/cpia2/cpia2_v4l.c
drivers/media/video/cs5345.c
drivers/media/video/cx18/cx18-driver.h
drivers/media/video/cx18/cx18-firmware.c
drivers/media/video/cx18/cx18-streams.c
drivers/media/video/cx23885/cx23885-417.c
drivers/media/video/cx23885/cx23885-video.c
drivers/media/video/cx88/cx88-blackbird.c
drivers/media/video/cx88/cx88-core.c
drivers/media/video/cx88/cx88-video.c
drivers/media/video/em28xx/em28xx-video.c
drivers/media/video/et61x251/et61x251_core.c
drivers/media/video/gspca/conex.c
drivers/media/video/gspca/etoms.c
drivers/media/video/gspca/gspca.c
drivers/media/video/gspca/mars.c
drivers/media/video/gspca/ov519.c
drivers/media/video/gspca/pac207.c
drivers/media/video/gspca/pac7311.c
drivers/media/video/gspca/sonixb.c
drivers/media/video/gspca/sonixj.c
drivers/media/video/gspca/spca500.c
drivers/media/video/gspca/spca501.c
drivers/media/video/gspca/spca505.c
drivers/media/video/gspca/spca506.c
drivers/media/video/gspca/spca508.c
drivers/media/video/gspca/spca561.c
drivers/media/video/gspca/stk014.c
drivers/media/video/gspca/sunplus.c
drivers/media/video/gspca/t613.c
drivers/media/video/gspca/tv8532.c
drivers/media/video/gspca/vc032x.c
drivers/media/video/gspca/zc3xx.c
drivers/media/video/ivtv/ivtv-driver.h
drivers/media/video/ivtv/ivtv-streams.c
drivers/media/video/meye.c
drivers/media/video/msp3400-driver.c
drivers/media/video/mt9m001.c
drivers/media/video/ov511.c
drivers/media/video/ov511.h
drivers/media/video/pms.c
drivers/media/video/pvrusb2/pvrusb2-v4l2.c
drivers/media/video/pwc/pwc-if.c
drivers/media/video/pwc/pwc.h
drivers/media/video/s2255drv.c
drivers/media/video/saa5246a.c
drivers/media/video/saa5249.c
drivers/media/video/saa7134/saa7134-core.c
drivers/media/video/saa7134/saa7134-empress.c
drivers/media/video/saa7134/saa7134.h
drivers/media/video/se401.h
drivers/media/video/sh_mobile_ceu_camera.c
drivers/media/video/sn9c102/sn9c102.h
drivers/media/video/sn9c102/sn9c102_core.c
drivers/media/video/soc_camera.c
drivers/media/video/stk-webcam.c
drivers/media/video/stradis.c
drivers/media/video/stv680.c
drivers/media/video/tda7432.c
drivers/media/video/tuner-core.c
drivers/media/video/usbvideo/usbvideo.c
drivers/media/video/usbvideo/usbvideo.h
drivers/media/video/usbvision/usbvision-video.c
drivers/media/video/uvc/uvc_driver.c
drivers/media/video/uvc/uvc_v4l2.c
drivers/media/video/v4l1-compat.c
drivers/media/video/v4l2-dev.c [new file with mode: 0644]
drivers/media/video/v4l2-ioctl.c [new file with mode: 0644]
drivers/media/video/videobuf-dma-contig.c
drivers/media/video/videodev.c
drivers/media/video/vivi.c
drivers/media/video/w9966.c
drivers/media/video/w9968cf.c
drivers/media/video/zc0301/zc0301.h
drivers/media/video/zoran_driver.c
drivers/media/video/zr364xx.c
include/media/saa7146_vv.h
include/media/v4l2-common.h
include/media/v4l2-dev.h
include/media/v4l2-ioctl.h [new file with mode: 0644]

index 0c4880af57a337d597baf871cb4926f48bfffd76..bcaf4ab383be001214f33d5abfbd2adbf954575a 100644 (file)
@@ -1,4 +1,4 @@
-List of the webcams know by gspca.
+List of the webcams known by gspca.
 
 The modules are:
        gspca_main      main driver
index a577c0f89f6745c421426a9b49f2af6888ba285e..3c663c65ef66a5a2358bfe364c2e37f7ba80d97c 100644 (file)
@@ -246,6 +246,14 @@ config DVB_USB_AF9005_REMOTE
          Say Y here to support the default remote control decoding for the
          Afatech AF9005 based receiver.
 
+config DVB_USB_DW2102
+       tristate "DvbWorld 2102 DVB-S USB2.0 receiver"
+       depends on DVB_USB
+       select DVB_STV0299 if !DVB_FE_CUSTOMISE
+       select DVB_PLL if !DVB_FE_CUSTOMISE
+       help
+          Say Y here to support the DvbWorld 2102 DVB-S USB2.0 receiver.
+
 config DVB_USB_ANYSEE
        tristate "Anysee DVB-T/C USB2.0 support"
        depends on DVB_USB
index 44c11e45e564022ba889a5c9a7437a12a0f5ad87..e206f1ea0027c9804789525fa9a558c3bcaf6be1 100644 (file)
@@ -64,6 +64,9 @@ obj-$(CONFIG_DVB_USB_AF9005_REMOTE) += dvb-usb-af9005-remote.o
 dvb-usb-anysee-objs = anysee.o
 obj-$(CONFIG_DVB_USB_ANYSEE) += dvb-usb-anysee.o
 
+dvb-usb-dw2102-objs = dw2102.o
+obj-$(CONFIG_DVB_USB_DW2102) += dvb-usb-dw2102.o
+
 EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/
 # due to tuner-xc3028
 EXTRA_CFLAGS += -Idrivers/media/common/tuners
index e5238b31e946e1b26c426d5ea5a76cbabedb5520..029b437caf9a11d20896df531762e279d7378858 100644 (file)
 #define USB_PID_ASUS_U3000                             0x171f
 #define USB_PID_ASUS_U3100                             0x173f
 #define USB_PID_YUAN_EC372S                            0x1edc
+#define USB_PID_DW2102                                 0x2102
 
 #endif
diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
new file mode 100644 (file)
index 0000000..a4d898b
--- /dev/null
@@ -0,0 +1,425 @@
+/* DVB USB framework compliant Linux driver for the DVBWorld DVB-S 2102 Card
+*
+* Copyright (C) 2008 Igor M. Liplianin (liplianin@me.by)
+*
+*      This program is free software; you can redistribute it and/or modify it
+*      under the terms of the GNU General Public License as published by the
+*      Free Software Foundation, version 2.
+*
+* see Documentation/dvb/README.dvb-usb for more information
+*/
+#include <linux/version.h>
+#include "dw2102.h"
+#include "stv0299.h"
+#include "z0194a.h"
+
+#ifndef USB_PID_DW2102
+#define USB_PID_DW2102 0x2102
+#endif
+
+#define DW2102_READ_MSG 0
+#define DW2102_WRITE_MSG 1
+
+#define REG_1F_SYMBOLRATE_BYTE0 0x1f
+#define REG_20_SYMBOLRATE_BYTE1 0x20
+#define REG_21_SYMBOLRATE_BYTE2 0x21
+
+#define DW2102_VOLTAGE_CTRL (0x1800)
+#define DW2102_RC_QUERY (0x1a00)
+
+struct dw2102_state {
+       u32 last_key_pressed;
+};
+struct dw2102_rc_keys {
+       u32 keycode;
+       u32 event;
+};
+
+DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
+
+static int dw2102_op_rw(struct usb_device *dev, u8 request, u16 value,
+               u8 *data, u16 len, int flags)
+{
+       int ret;
+       u8 u8buf[len];
+
+       unsigned int pipe = (flags == DW2102_READ_MSG) ?
+               usb_rcvctrlpipe(dev, 0) : usb_sndctrlpipe(dev, 0);
+       u8 request_type = (flags == DW2102_READ_MSG) ? USB_DIR_IN : USB_DIR_OUT;
+
+       if (flags == DW2102_WRITE_MSG)
+               memcpy(u8buf, data, len);
+       ret = usb_control_msg(dev, pipe, request,
+               request_type | USB_TYPE_VENDOR, value, 0 , u8buf, len, 2000);
+
+       if (flags == DW2102_READ_MSG)
+               memcpy(data, u8buf, len);
+       return ret;
+}
+
+/* I2C */
+
+static int dw2102_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
+               int num)
+{
+struct dvb_usb_device *d = i2c_get_adapdata(adap);
+       int i = 0, ret = 0;
+       u8 buf6[] = {0x2c, 0x05, 0xc0, 0, 0, 0, 0};
+       u8 request;
+       u16 value;
+
+       if (!d)
+               return -ENODEV;
+       if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
+               return -EAGAIN;
+
+       switch (num) {
+       case 2:
+               /* read stv0299 register */
+               request = 0xb5;
+               value = msg[0].buf[0];/* register */
+               for (i = 0; i < msg[1].len; i++) {
+                       value = value + i;
+                       ret = dw2102_op_rw(d->udev, 0xb5,
+                               value, buf6, 2, DW2102_READ_MSG);
+                       msg[1].buf[i] = buf6[0];
+
+               }
+               break;
+       case 1:
+               switch (msg[0].addr) {
+               case 0x68:
+                       /* write to stv0299 register */
+                       buf6[0] = 0x2a;
+                       buf6[1] = msg[0].buf[0];
+                       buf6[2] = msg[0].buf[1];
+                       ret = dw2102_op_rw(d->udev, 0xb2,
+                               0, buf6, 3, DW2102_WRITE_MSG);
+                       break;
+               case 0x60:
+                       if (msg[0].flags == 0) {
+                       /* write to tuner pll */
+                               buf6[0] = 0x2c;
+                               buf6[1] = 5;
+                               buf6[2] = 0xc0;
+                               buf6[3] = msg[0].buf[0];
+                               buf6[4] = msg[0].buf[1];
+                               buf6[5] = msg[0].buf[2];
+                               buf6[6] = msg[0].buf[3];
+                               ret = dw2102_op_rw(d->udev, 0xb2,
+                               0, buf6, 7, DW2102_WRITE_MSG);
+                       } else {
+                       /* write to tuner pll */
+                               ret = dw2102_op_rw(d->udev, 0xb5,
+                               0, buf6, 1, DW2102_READ_MSG);
+                               msg[0].buf[0] = buf6[0];
+                       }
+                       break;
+               case (DW2102_RC_QUERY):
+                       ret  = dw2102_op_rw(d->udev, 0xb8,
+                               0, buf6, 2, DW2102_READ_MSG);
+                       msg[0].buf[0] = buf6[0];
+                       msg[0].buf[1] = buf6[1];
+                       break;
+               case (DW2102_VOLTAGE_CTRL):
+                       buf6[0] = 0x30;
+                       buf6[1] = msg[0].buf[0];
+                       ret = dw2102_op_rw(d->udev, 0xb2,
+                               0, buf6, 2, DW2102_WRITE_MSG);
+                       break;
+               }
+
+               break;
+       }
+
+       mutex_unlock(&d->i2c_mutex);
+       return num;
+}
+
+static u32 dw2102_i2c_func(struct i2c_adapter *adapter)
+{
+       return I2C_FUNC_I2C;
+}
+
+static struct i2c_algorithm dw2102_i2c_algo = {
+       .master_xfer = dw2102_i2c_transfer,
+       .functionality = dw2102_i2c_func,
+};
+
+static int dw2102_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
+{
+       static u8 command_13v[1] = {0x00};
+       static u8 command_18v[1] = {0x01};
+       struct i2c_msg msg[] = {
+               {.addr = DW2102_VOLTAGE_CTRL, .flags = 0,
+                       .buf = command_13v, .len = 1},
+       };
+
+       struct dvb_usb_adapter *udev_adap =
+               (struct dvb_usb_adapter *)(fe->dvb->priv);
+       if (voltage == SEC_VOLTAGE_18)
+               msg[0].buf = command_18v;
+       i2c_transfer(&udev_adap->dev->i2c_adap, msg, 1);
+       return 0;
+}
+
+static int dw2102_frontend_attach(struct dvb_usb_adapter *d)
+{
+       d->fe = dvb_attach(stv0299_attach, &sharp_z0194a_config,
+               &d->dev->i2c_adap);
+       if (d->fe != NULL) {
+               d->fe->ops.set_voltage = dw2102_set_voltage;
+               info("Attached stv0299!\n");
+               return 0;
+       }
+       return -EIO;
+}
+
+static int dw2102_tuner_attach(struct dvb_usb_adapter *adap)
+{
+       dvb_attach(dvb_pll_attach, adap->fe, 0x60,
+               &adap->dev->i2c_adap, DVB_PLL_OPERA1);
+       return 0;
+}
+
+static struct dvb_usb_rc_key dw2102_rc_keys[] = {
+       { 0xf8, 0x0a, KEY_Q },          /*power*/
+       { 0xf8, 0x0c, KEY_M },          /*mute*/
+       { 0xf8, 0x11, KEY_1 },
+       { 0xf8, 0x12, KEY_2 },
+       { 0xf8, 0x13, KEY_3 },
+       { 0xf8, 0x14, KEY_4 },
+       { 0xf8, 0x15, KEY_5 },
+       { 0xf8, 0x16, KEY_6 },
+       { 0xf8, 0x17, KEY_7 },
+       { 0xf8, 0x18, KEY_8 },
+       { 0xf8, 0x19, KEY_9 },
+       { 0xf8, 0x10, KEY_0 },
+       { 0xf8, 0x1c, KEY_PAGEUP },     /*ch+*/
+       { 0xf8, 0x0f, KEY_PAGEDOWN },   /*ch-*/
+       { 0xf8, 0x1a, KEY_O },          /*vol+*/
+       { 0xf8, 0x0e, KEY_Z },          /*vol-*/
+       { 0xf8, 0x04, KEY_R },          /*rec*/
+       { 0xf8, 0x09, KEY_D },          /*fav*/
+       { 0xf8, 0x08, KEY_BACKSPACE },  /*rewind*/
+       { 0xf8, 0x07, KEY_A },          /*fast*/
+       { 0xf8, 0x0b, KEY_P },          /*pause*/
+       { 0xf8, 0x02, KEY_ESC },        /*cancel*/
+       { 0xf8, 0x03, KEY_G },          /*tab*/
+       { 0xf8, 0x00, KEY_UP },         /*up*/
+       { 0xf8, 0x1f, KEY_ENTER },      /*ok*/
+       { 0xf8, 0x01, KEY_DOWN },       /*down*/
+       { 0xf8, 0x05, KEY_C },          /*cap*/
+       { 0xf8, 0x06, KEY_S },          /*stop*/
+       { 0xf8, 0x40, KEY_F },          /*full*/
+       { 0xf8, 0x1e, KEY_W },          /*tvmode*/
+       { 0xf8, 0x1b, KEY_B },          /*recall*/
+
+};
+
+
+
+static int dw2102_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
+{
+       struct dw2102_state *st = d->priv;
+       u8 key[2];
+       struct i2c_msg msg[] = {
+               {.addr = DW2102_RC_QUERY, .flags = I2C_M_RD, .buf = key,
+               .len = 2},
+       };
+       int i;
+
+       *state = REMOTE_NO_KEY_PRESSED;
+       if (dw2102_i2c_transfer(&d->i2c_adap, msg, 1) == 1) {
+               for (i = 0; i < ARRAY_SIZE(dw2102_rc_keys); i++) {
+                       if (dw2102_rc_keys[i].data == msg[0].buf[0]) {
+                               *state = REMOTE_KEY_PRESSED;
+                               *event = dw2102_rc_keys[i].event;
+                               st->last_key_pressed =
+                                       dw2102_rc_keys[i].event;
+                               break;
+                       }
+               st->last_key_pressed = 0;
+               }
+       }
+       /* info("key: %x %x\n",key[0],key[1]); */
+       return 0;
+}
+
+static struct usb_device_id dw2102_table[] = {
+       {USB_DEVICE(USB_VID_CYPRESS, USB_PID_DW2102)},
+       {USB_DEVICE(USB_VID_CYPRESS, 0x2101)},
+       { }
+};
+
+MODULE_DEVICE_TABLE(usb, dw2102_table);
+
+static int dw2102_load_firmware(struct usb_device *dev,
+                       const struct firmware *frmwr)
+{
+       u8 *b, *p;
+       int ret = 0, i;
+       u8 reset;
+       u8 reset16 [] = {0, 0, 0, 0, 0, 0, 0};
+       const struct firmware *fw;
+       const char *filename = "dvb-usb-dw2101.fw";
+       switch (dev->descriptor.idProduct) {
+       case 0x2101:
+               ret = request_firmware(&fw, filename, &dev->dev);
+               if (ret != 0) {
+                       err("did not find the firmware file. (%s) "
+                       "Please see linux/Documentation/dvb/ for more details "
+                       "on firmware-problems.", filename);
+                       return ret;
+               }
+               break;
+       case USB_PID_DW2102:
+               fw = frmwr;
+               break;
+       }
+       info("start downloading DW2102 firmware");
+       p = kmalloc(fw->size, GFP_KERNEL);
+       reset = 1;
+       /*stop the CPU*/
+       dw2102_op_rw(dev, 0xa0, 0x7f92, &reset, 1, DW2102_WRITE_MSG);
+       dw2102_op_rw(dev, 0xa0, 0xe600, &reset, 1, DW2102_WRITE_MSG);
+
+       if (p != NULL) {
+               memcpy(p, fw->data, fw->size);
+               for (i = 0; i < fw->size; i += 0x40) {
+                       b = (u8 *) p + i;
+                       if (dw2102_op_rw
+                               (dev, 0xa0, i, b , 0x40,
+                                       DW2102_WRITE_MSG) != 0x40
+                               ) {
+                               err("error while transferring firmware");
+                               ret = -EINVAL;
+                               break;
+                       }
+               }
+               /* restart the CPU */
+               reset = 0;
+               if (ret || dw2102_op_rw
+                       (dev, 0xa0, 0x7f92, &reset, 1,
+                       DW2102_WRITE_MSG) != 1) {
+                       err("could not restart the USB controller CPU.");
+                       ret = -EINVAL;
+               }
+               if (ret || dw2102_op_rw
+                       (dev, 0xa0, 0xe600, &reset, 1,
+                       DW2102_WRITE_MSG) != 1) {
+                       err("could not restart the USB controller CPU.");
+                       ret = -EINVAL;
+               }
+               /* init registers */
+               switch (dev->descriptor.idProduct) {
+               case USB_PID_DW2102:
+                       dw2102_op_rw
+                               (dev, 0xbf, 0x0040, &reset, 0,
+                               DW2102_WRITE_MSG);
+                       dw2102_op_rw
+                               (dev, 0xb9, 0x0000, &reset16[0], 2,
+                               DW2102_READ_MSG);
+                       break;
+               case 0x2101:
+                       dw2102_op_rw
+                               (dev, 0xbc, 0x0030, &reset16[0], 2,
+                               DW2102_READ_MSG);
+                       dw2102_op_rw
+                               (dev, 0xba, 0x0000, &reset16[0], 7,
+                               DW2102_READ_MSG);
+                       dw2102_op_rw
+                               (dev, 0xba, 0x0000, &reset16[0], 7,
+                               DW2102_READ_MSG);
+                       dw2102_op_rw
+                               (dev, 0xb9, 0x0000, &reset16[0], 2,
+                               DW2102_READ_MSG);
+                       break;
+               }
+               kfree(p);
+       }
+       return ret;
+}
+
+static struct dvb_usb_device_properties dw2102_properties = {
+       .caps = DVB_USB_IS_AN_I2C_ADAPTER,
+       .usb_ctrl = DEVICE_SPECIFIC,
+       .firmware = "dvb-usb-dw2102.fw",
+       .size_of_priv = sizeof(struct dw2102_state),
+       .no_reconnect = 1,
+
+       .i2c_algo = &dw2102_i2c_algo,
+       .rc_key_map = dw2102_rc_keys,
+       .rc_key_map_size = ARRAY_SIZE(dw2102_rc_keys),
+       .rc_interval = 150,
+       .rc_query = dw2102_rc_query,
+
+       .generic_bulk_ctrl_endpoint = 0x81,
+       /* parameter for the MPEG2-data transfer */
+       .num_adapters = 1,
+       .download_firmware = dw2102_load_firmware,
+       .adapter = {
+               {
+                       .frontend_attach = dw2102_frontend_attach,
+                       .streaming_ctrl = NULL,
+                       .tuner_attach = dw2102_tuner_attach,
+                       .stream = {
+                               .type = USB_BULK,
+                               .count = 8,
+                               .endpoint = 0x82,
+                               .u = {
+                                       .bulk = {
+                                               .buffersize = 4096,
+                                       }
+                               }
+                       },
+               }
+       },
+       .num_device_descs = 2,
+       .devices = {
+               {"DVBWorld DVB-S 2102 USB2.0",
+                       {&dw2102_table[0], NULL},
+                       {NULL},
+               },
+               {"DVBWorld DVB-S 2101 USB2.0",
+                       {&dw2102_table[1], NULL},
+                       {NULL},
+               },
+       }
+};
+
+static int dw2102_probe(struct usb_interface *intf,
+               const struct usb_device_id *id)
+{
+       return dvb_usb_device_init(intf, &dw2102_properties,
+               THIS_MODULE, NULL, adapter_nr);
+}
+
+static struct usb_driver dw2102_driver = {
+       .name = "dw2102",
+       .probe = dw2102_probe,
+       .disconnect = dvb_usb_device_exit,
+       .id_table = dw2102_table,
+};
+
+static int __init dw2102_module_init(void)
+{
+       int ret =  usb_register(&dw2102_driver);
+       if (ret)
+               err("usb_register failed. Error number %d", ret);
+
+       return ret;
+}
+
+static void __exit dw2102_module_exit(void)
+{
+       usb_deregister(&dw2102_driver);
+}
+
+module_init(dw2102_module_init);
+module_exit(dw2102_module_exit);
+
+MODULE_AUTHOR("Igor M. Liplianin (c) liplianin@me.by");
+MODULE_DESCRIPTION("Driver for DVBWorld DVB-S 2101 2102 USB2.0 device");
+MODULE_VERSION("0.1");
+MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/dvb-usb/dw2102.h b/drivers/media/dvb/dvb-usb/dw2102.h
new file mode 100644 (file)
index 0000000..cb58737
--- /dev/null
@@ -0,0 +1,9 @@
+#ifndef _DW2102_H_
+#define _DW2102_H_
+
+#define DVB_USB_LOG_PREFIX "dw2102"
+#include <dvb-usb.h>
+
+extern int dvb_usb_dw2102_debug;
+#define deb_xfer(args...) dprintk(dvb_usb_dw2102_debug, 0x02, args)
+#endif
index c20553c4da1faa4645b44cf6d77417c897bf0bdb..fa7f0c56377003f40f9ec2661d5224d6bd667c2f 100644 (file)
@@ -135,6 +135,20 @@ config DVB_CX22702
        help
          A DVB-T tuner module. Say Y when you want to support this frontend.
 
+config DVB_DRX397XD
+       tristate "Micronas DRX3975D/DRX3977D based"
+       depends on DVB_CORE && I2C && HOTPLUG
+       default m if DVB_FE_CUSTOMISE
+       select FW_LOADER
+       help
+         A DVB-T tuner module. Say Y when you want to support this frontend.
+
+         TODO:
+         This driver needs external firmware. Please use the command
+         "<kerneldir>/Documentation/dvb/get_dvb_firmware drx397xD" to
+         download/extract them, and then copy them to /usr/lib/hotplug/firmware
+         or /lib/firmware (depending on configuration of firmware hotplug).
+
 config DVB_L64781
        tristate "LSI L64781"
        depends on DVB_CORE && I2C
index a89dc0fc4c6fe90dbb97d5fd22368a66b0c65000..028da55611c02cbad0c1b20404ad7326de2066e0 100644 (file)
@@ -25,6 +25,7 @@ obj-$(CONFIG_DVB_NXT6000) += nxt6000.o
 obj-$(CONFIG_DVB_MT352) += mt352.o
 obj-$(CONFIG_DVB_ZL10353) += zl10353.o
 obj-$(CONFIG_DVB_CX22702) += cx22702.o
+obj-$(CONFIG_DVB_DRX397XD) += drx397xD.o
 obj-$(CONFIG_DVB_TDA10021) += tda10021.o
 obj-$(CONFIG_DVB_TDA10023) += tda10023.o
 obj-$(CONFIG_DVB_STV0297) += stv0297.o
diff --git a/drivers/media/dvb/frontends/drx397xD.c b/drivers/media/dvb/frontends/drx397xD.c
new file mode 100644 (file)
index 0000000..3cbed87
--- /dev/null
@@ -0,0 +1,1504 @@
+/*
+ * Driver for Micronas drx397xD demodulator
+ *
+ * Copyright (C) 2007 Henk Vergonet <Henk.Vergonet@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#define DEBUG                  /* uncomment if you want debugging output */
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/init.h>
+#include <linux/device.h>
+#include <linux/delay.h>
+#include <linux/string.h>
+#include <linux/firmware.h>
+#include <asm/div64.h>
+
+#include "dvb_frontend.h"
+#include "drx397xD.h"
+
+static const char mod_name[] = "drx397xD";
+
+#define MAX_CLOCK_DRIFT                200     /* maximal 200 PPM allowed */
+
+#define F_SET_0D0h     1
+#define F_SET_0D4h     2
+
+typedef enum fw_ix {
+#define _FW_ENTRY(a, b)                b
+#include "drx397xD_fw.h"
+} fw_ix_t;
+
+/* chip specifics */
+struct drx397xD_state {
+       struct i2c_adapter *i2c;
+       struct dvb_frontend frontend;
+       struct drx397xD_config config;
+       fw_ix_t chip_rev;
+       int flags;
+       u32 bandwidth_parm;     /* internal bandwidth conversions */
+       u32 f_osc;              /* w90: actual osc frequency [Hz] */
+};
+
+/*******************************************************************************
+ * Firmware
+ ******************************************************************************/
+
+static const char *blob_name[] = {
+#define _BLOB_ENTRY(a, b)              a
+#include "drx397xD_fw.h"
+};
+
+typedef enum blob_ix {
+#define _BLOB_ENTRY(a, b)              b
+#include "drx397xD_fw.h"
+} blob_ix_t;
+
+static struct {
+       const char *name;
+       const struct firmware *file;
+       rwlock_t lock;
+       int refcnt;
+       const u8 *data[ARRAY_SIZE(blob_name)];
+} fw[] = {
+#define _FW_ENTRY(a, b)                {                       \
+                       .name   = a,                    \
+                       .file   = 0,                    \
+                       .lock   = RW_LOCK_UNLOCKED,     \
+                       .refcnt = 0,                    \
+                       .data   = { }           }
+#include "drx397xD_fw.h"
+};
+
+/* use only with writer lock aquired */
+static void _drx_release_fw(struct drx397xD_state *s, fw_ix_t ix)
+{
+       memset(&fw[ix].data[0], 0, sizeof(fw[0].data));
+       if (fw[ix].file)
+               release_firmware(fw[ix].file);
+}
+
+static void drx_release_fw(struct drx397xD_state *s)
+{
+       fw_ix_t ix = s->chip_rev;
+
+       pr_debug("%s\n", __FUNCTION__);
+
+       write_lock(&fw[ix].lock);
+       if (fw[ix].refcnt) {
+               fw[ix].refcnt--;
+               if (fw[ix].refcnt == 0)
+                       _drx_release_fw(s, ix);
+       }
+       write_unlock(&fw[ix].lock);
+}
+
+static int drx_load_fw(struct drx397xD_state *s, fw_ix_t ix)
+{
+       const u8 *data;
+       size_t size, len;
+       int i = 0, j, rc = -EINVAL;
+
+       pr_debug("%s\n", __FUNCTION__);
+
+       if (ix < 0 || ix >= ARRAY_SIZE(fw))
+               return -EINVAL;
+       s->chip_rev = ix;
+
+       write_lock(&fw[ix].lock);
+       if (fw[ix].file) {
+               rc = 0;
+               goto exit_ok;
+       }
+       memset(&fw[ix].data[0], 0, sizeof(fw[0].data));
+
+       if (request_firmware(&fw[ix].file, fw[ix].name, &s->i2c->dev) != 0) {
+               printk(KERN_ERR "%s: Firmware \"%s\" not available\n",
+                      mod_name, fw[ix].name);
+               rc = -ENOENT;
+               goto exit_err;
+       }
+
+       if (!fw[ix].file->data || fw[ix].file->size < 10)
+               goto exit_corrupt;
+
+       data = fw[ix].file->data;
+       size = fw[ix].file->size;
+
+       if (data[i++] != 2)     /* check firmware version */
+               goto exit_corrupt;
+
+       do {
+               switch (data[i++]) {
+               case 0x00:      /* bytecode */
+                       if (i >= size)
+                               break;
+                       i += data[i];
+               case 0x01:      /* reset */
+               case 0x02:      /* sleep */
+                       i++;
+                       break;
+               case 0xfe:      /* name */
+                       len = strnlen(&data[i], size - i);
+                       if (i + len + 1 >= size)
+                               goto exit_corrupt;
+                       if (data[i + len + 1] != 0)
+                               goto exit_corrupt;
+                       for (j = 0; j < ARRAY_SIZE(blob_name); j++) {
+                               if (strcmp(blob_name[j], &data[i]) == 0) {
+                                       fw[ix].data[j] = &data[i + len + 1];
+                                       pr_debug("Loading %s\n", blob_name[j]);
+                               }
+                       }
+                       i += len + 1;
+                       break;
+               case 0xff:      /* file terminator */
+                       if (i == size) {
+                               rc = 0;
+                               goto exit_ok;
+                       }
+               default:
+                       goto exit_corrupt;
+               }
+       } while (i < size);
+      exit_corrupt:
+       printk(KERN_ERR "%s: Firmware is corrupt\n", mod_name);
+      exit_err:
+       _drx_release_fw(s, ix);
+       fw[ix].refcnt--;
+      exit_ok:
+       fw[ix].refcnt++;
+       write_unlock(&fw[ix].lock);
+       return rc;
+}
+
+/*******************************************************************************
+ * i2c bus IO
+ ******************************************************************************/
+
+static int write_fw(struct drx397xD_state *s, blob_ix_t ix)
+{
+       struct i2c_msg msg = {.addr = s->config.demod_address,.flags = 0 };
+       const u8 *data;
+       int len, rc = 0, i = 0;
+
+       if (ix < 0 || ix >= ARRAY_SIZE(blob_name)) {
+               pr_debug("%s drx_fw_ix_t out of range\n", __FUNCTION__);
+               return -EINVAL;
+       }
+       pr_debug("%s %s\n", __FUNCTION__, blob_name[ix]);
+
+       read_lock(&fw[s->chip_rev].lock);
+       data = fw[s->chip_rev].data[ix];
+       if (!data) {
+               rc = -EINVAL;
+               goto exit_rc;
+       }
+
+       for (;;) {
+               switch (data[i++]) {
+               case 0: /* bytecode */
+                       len = data[i++];
+                       msg.len = len;
+                       msg.buf = (__u8 *) &data[i];
+                       if (i2c_transfer(s->i2c, &msg, 1) != 1) {
+                               rc = -EIO;
+                               goto exit_rc;
+                       }
+                       i += len;
+                       break;
+               case 1: /* reset */
+               case 2: /* sleep */
+                       i++;
+                       break;
+               default:
+                       goto exit_rc;
+               }
+       }
+      exit_rc:
+       read_unlock(&fw[s->chip_rev].lock);
+       return 0;
+}
+
+/* Function is not endian safe, use the RD16 wrapper below */
+static int _read16(struct drx397xD_state *s, u32 i2c_adr)
+{
+       int rc;
+       u8 a[4];
+       u16 v;
+       struct i2c_msg msg[2] = {
+               {
+                .addr = s->config.demod_address,
+                .flags = 0,
+                .buf = a,
+                .len = sizeof(a)
+                }
+               , {
+                  .addr = s->config.demod_address,
+                  .flags = I2C_M_RD,
+                  .buf = (u8 *) & v,
+                  .len = sizeof(v)
+                  }
+       };
+
+       *(u32 *) a = i2c_adr;
+
+       rc = i2c_transfer(s->i2c, msg, 2);
+       if (rc != 2)
+               return -EIO;
+
+       return le16_to_cpu(v);
+}
+
+/* Function is not endian safe, use the WR16.. wrappers below */
+static int _write16(struct drx397xD_state *s, u32 i2c_adr, u16 val)
+{
+       u8 a[6];
+       int rc;
+       struct i2c_msg msg = {
+               .addr = s->config.demod_address,
+               .flags = 0,
+               .buf = a,
+               .len = sizeof(a)
+       };
+
+       *(u32 *) a = i2c_adr;
+       *(u16 *) & a[4] = val;
+
+       rc = i2c_transfer(s->i2c, &msg, 1);
+       if (rc != 1)
+               return -EIO;
+       return 0;
+}
+
+#define WR16(ss,adr, val) \
+               _write16(ss, I2C_ADR_C0(adr), cpu_to_le16(val))
+#define WR16_E0(ss,adr, val) \
+               _write16(ss, I2C_ADR_E0(adr), cpu_to_le16(val))
+#define RD16(ss,adr) \
+               _read16(ss, I2C_ADR_C0(adr))
+
+#define EXIT_RC( cmd ) if ( (rc = (cmd)) < 0) goto exit_rc
+
+/*******************************************************************************
+ * Tuner callback
+ ******************************************************************************/
+
+static int PLL_Set(struct drx397xD_state *s,
+                  struct dvb_frontend_parameters *fep, int *df_tuner)
+{
+       struct dvb_frontend *fe = &s->frontend;
+       u32 f_tuner, f = fep->frequency;
+       int rc;
+
+       pr_debug("%s\n", __FUNCTION__);
+
+       if ((f > s->frontend.ops.tuner_ops.info.frequency_max) ||
+           (f < s->frontend.ops.tuner_ops.info.frequency_min))
+               return -EINVAL;
+
+       *df_tuner = 0;
+       if (!s->frontend.ops.tuner_ops.set_params ||
+           !s->frontend.ops.tuner_ops.get_frequency)
+               return -ENOSYS;
+
+       rc = s->frontend.ops.tuner_ops.set_params(fe, fep);
+       if (rc < 0)
+               return rc;
+
+       rc = s->frontend.ops.tuner_ops.get_frequency(fe, &f_tuner);
+       if (rc < 0)
+               return rc;
+
+       *df_tuner = f_tuner - f;
+       pr_debug("%s requested %d [Hz] tuner %d [Hz]\n", __FUNCTION__, f,
+                f_tuner);
+
+       return 0;
+}
+
+/*******************************************************************************
+ * Demodulator helper functions
+ ******************************************************************************/
+
+static int SC_WaitForReady(struct drx397xD_state *s)
+{
+       int cnt = 1000;
+       int rc;
+
+       pr_debug("%s\n", __FUNCTION__);
+
+       while (cnt--) {
+               rc = RD16(s, 0x820043);
+               if (rc == 0)
+                       return 0;
+       }
+       return -1;
+}
+
+static int SC_SendCommand(struct drx397xD_state *s, int cmd)
+{
+       int rc;
+
+       pr_debug("%s\n", __FUNCTION__);
+
+       WR16(s, 0x820043, cmd);
+       SC_WaitForReady(s);
+       rc = RD16(s, 0x820042);
+       if ((rc & 0xffff) == 0xffff)
+               return -1;
+       return 0;
+}
+
+static int HI_Command(struct drx397xD_state *s, u16 cmd)
+{
+       int rc, cnt = 1000;
+
+       pr_debug("%s\n", __FUNCTION__);
+
+       rc = WR16(s, 0x420032, cmd);
+       if (rc < 0)
+               return rc;
+
+       do {
+               rc = RD16(s, 0x420032);
+               if (rc == 0) {
+                       rc = RD16(s, 0x420031);
+                       return rc;
+               }
+               if (rc < 0)
+                       return rc;
+       } while (--cnt);
+       return rc;
+}
+
+static int HI_CfgCommand(struct drx397xD_state *s)
+{
+
+       pr_debug("%s\n", __FUNCTION__);
+
+       WR16(s, 0x420033, 0x3973);
+       WR16(s, 0x420034, s->config.w50);       // code 4, log 4
+       WR16(s, 0x420035, s->config.w52);       // code 15,  log 9
+       WR16(s, 0x420036, s->config.demod_address << 1);
+       WR16(s, 0x420037, s->config.w56);       // code (set_i2c ??  initX 1 ), log 1
+//      WR16(s, 0x420033, 0x3973);
+       if ((s->config.w56 & 8) == 0)
+               return HI_Command(s, 3);
+       return WR16(s, 0x420032, 0x3);
+}
+
+static const u8 fastIncrDecLUT_15273[] = {
+       0x0e, 0x0f, 0x0f, 0x10, 0x11, 0x12, 0x12, 0x13, 0x14,
+       0x15, 0x16, 0x17, 0x18, 0x1a, 0x1b, 0x1c, 0x1d, 0x1f
+};
+
+static const u8 slowIncrDecLUT_15272[] = {
+       3, 4, 4, 5, 6
+};
+
+static int SetCfgIfAgc(struct drx397xD_state *s, struct drx397xD_CfgIfAgc *agc)
+{
+       u16 w06 = agc->w06;
+       u16 w08 = agc->w08;
+       u16 w0A = agc->w0A;
+       u16 w0C = agc->w0C;
+       int quot, rem, i, rc = -EINVAL;
+
+       pr_debug("%s\n", __FUNCTION__);
+
+       if (agc->w04 > 0x3ff)
+               goto exit_rc;
+
+       if (agc->d00 == 1) {
+               EXIT_RC(RD16(s, 0x0c20010));
+               rc &= ~0x10;
+               EXIT_RC(WR16(s, 0x0c20010, rc));
+               return WR16(s, 0x0c20030, agc->w04 & 0x7ff);
+       }
+
+       if (agc->d00 != 0)
+               goto exit_rc;
+       if (w0A < w08)
+               goto exit_rc;
+       if (w0A > 0x3ff)
+               goto exit_rc;
+       if (w0C > 0x3ff)
+               goto exit_rc;
+       if (w06 > 0x3ff)
+               goto exit_rc;
+
+       EXIT_RC(RD16(s, 0x0c20010));
+       rc |= 0x10;
+       EXIT_RC(WR16(s, 0x0c20010, rc));
+
+       EXIT_RC(WR16(s, 0x0c20025, (w06 >> 1) & 0x1ff));
+       EXIT_RC(WR16(s, 0x0c20031, (w0A - w08) >> 1));
+       EXIT_RC(WR16(s, 0x0c20032, ((w0A + w08) >> 1) - 0x1ff));
+
+       quot = w0C / 113;
+       rem = w0C % 113;
+       if (quot <= 8) {
+               quot = 8 - quot;
+       } else {
+               quot = 0;
+               rem += 113;
+       }
+
+       EXIT_RC(WR16(s, 0x0c20024, quot));
+
+       i = fastIncrDecLUT_15273[rem / 8];
+       EXIT_RC(WR16(s, 0x0c2002d, i));
+       EXIT_RC(WR16(s, 0x0c2002e, i));
+
+       i = slowIncrDecLUT_15272[rem / 28];
+       EXIT_RC(WR16(s, 0x0c2002b, i));
+       rc = WR16(s, 0x0c2002c, i);
+      exit_rc:
+       return rc;
+}
+
+static int SetCfgRfAgc(struct drx397xD_state *s, struct drx397xD_CfgRfAgc *agc)
+{
+       u16 w04 = agc->w04;
+       u16 w06 = agc->w06;
+       int rc = -1;
+
+       pr_debug("%s %d 0x%x 0x%x\n", __FUNCTION__, agc->d00, w04, w06);
+
+       if (w04 > 0x3ff)
+               goto exit_rc;
+
+       switch (agc->d00) {
+       case 1:
+               if (w04 == 0x3ff)
+                       w04 = 0x400;
+
+               EXIT_RC(WR16(s, 0x0c20036, w04));
+               s->config.w9C &= ~2;
+               EXIT_RC(WR16(s, 0x0c20015, s->config.w9C));
+               EXIT_RC(RD16(s, 0x0c20010));
+               rc &= 0xbfdf;
+               EXIT_RC(WR16(s, 0x0c20010, rc));
+               EXIT_RC(RD16(s, 0x0c20013));
+               rc &= ~2;
+               break;
+       case 0:
+               // loc_8000659
+               s->config.w9C &= ~2;
+               EXIT_RC(WR16(s, 0x0c20015, s->config.w9C));
+               EXIT_RC(RD16(s, 0x0c20010));
+               rc &= 0xbfdf;
+               rc |= 0x4000;
+               EXIT_RC(WR16(s, 0x0c20010, rc));
+               EXIT_RC(WR16(s, 0x0c20051, (w06 >> 4) & 0x3f));
+               EXIT_RC(RD16(s, 0x0c20013));
+               rc &= ~2;
+               break;
+       default:
+               s->config.w9C |= 2;
+               EXIT_RC(WR16(s, 0x0c20015, s->config.w9C));
+               EXIT_RC(RD16(s, 0x0c20010));
+               rc &= 0xbfdf;
+               EXIT_RC(WR16(s, 0x0c20010, rc));
+
+               EXIT_RC(WR16(s, 0x0c20036, 0));
+
+               EXIT_RC(RD16(s, 0x0c20013));
+               rc |= 2;
+       }
+       rc = WR16(s, 0x0c20013, rc);
+      exit_rc:
+       return rc;
+}
+
+static int GetLockStatus(struct drx397xD_state *s, int *lockstat)
+{
+       int rc;
+
+       *lockstat = 0;
+
+       rc = RD16(s, 0x082004b);
+       if (rc < 0)
+               return rc;
+
+       if (s->config.d60 != 2)
+               return 0;
+
+       if ((rc & 7) == 7)
+               *lockstat |= 1;
+       if ((rc & 3) == 3)
+               *lockstat |= 2;
+       if (rc & 1)
+               *lockstat |= 4;
+       return 0;
+}
+
+static int CorrectSysClockDeviation(struct drx397xD_state *s)
+{
+       int rc = -EINVAL;
+       int lockstat;
+       u32 clk, clk_limit;
+
+       pr_debug("%s\n", __FUNCTION__);
+
+       if (s->config.d5C == 0) {
+               EXIT_RC(WR16(s, 0x08200e8, 0x010));
+               EXIT_RC(WR16(s, 0x08200e9, 0x113));
+               s->config.d5C = 1;
+               return rc;
+       }
+       if (s->config.d5C != 1)
+               goto exit_rc;
+
+       rc = RD16(s, 0x0820048);
+
+       rc = GetLockStatus(s, &lockstat);
+       if (rc < 0)
+               goto exit_rc;
+       if ((lockstat & 1) == 0)
+               goto exit_rc;
+
+       EXIT_RC(WR16(s, 0x0420033, 0x200));
+       EXIT_RC(WR16(s, 0x0420034, 0xc5));
+       EXIT_RC(WR16(s, 0x0420035, 0x10));
+       EXIT_RC(WR16(s, 0x0420036, 0x1));
+       EXIT_RC(WR16(s, 0x0420037, 0xa));
+       EXIT_RC(HI_Command(s, 6));
+       EXIT_RC(RD16(s, 0x0420040));
+       clk = rc;
+       EXIT_RC(RD16(s, 0x0420041));
+       clk |= rc << 16;
+
+       if (clk <= 0x26ffff)
+               goto exit_rc;
+       if (clk > 0x610000)
+               goto exit_rc;
+
+       if (!s->bandwidth_parm)
+               return -EINVAL;
+
+       /* round & convert to Hz */
+       clk = ((u64) (clk + 0x800000) * s->bandwidth_parm + (1 << 20)) >> 21;
+       clk_limit = s->config.f_osc * MAX_CLOCK_DRIFT / 1000;
+
+       if (clk - s->config.f_osc * 1000 + clk_limit <= 2 * clk_limit) {
+               s->f_osc = clk;
+               pr_debug("%s: osc %d %d [Hz]\n", __FUNCTION__,
+                        s->config.f_osc * 1000, clk - s->config.f_osc * 1000);
+       }
+       rc = WR16(s, 0x08200e8, 0);
+      exit_rc:
+       return rc;
+}
+
+static int ConfigureMPEGOutput(struct drx397xD_state *s, int type)
+{
+       int rc, si, bp;
+
+       pr_debug("%s\n", __FUNCTION__);
+
+       si = s->config.wA0;
+       if (s->config.w98 == 0) {
+               si |= 1;
+               bp = 0;
+       } else {
+               si &= ~1;
+               bp = 0x200;
+       }
+       if (s->config.w9A == 0) {
+               si |= 0x80;
+       } else {
+               si &= ~0x80;
+       }
+
+       EXIT_RC(WR16(s, 0x2150045, 0));
+       EXIT_RC(WR16(s, 0x2150010, si));
+       EXIT_RC(WR16(s, 0x2150011, bp));
+       rc = WR16(s, 0x2150012, (type == 0 ? 0xfff : 0));
+      exit_rc:
+       return rc;
+}
+
+static int drx_tune(struct drx397xD_state *s,
+                   struct dvb_frontend_parameters *fep)
+{
+       u16 v22 = 0;
+       u16 v1C = 0;
+       u16 v1A = 0;
+       u16 v18 = 0;
+       u32 edi = 0, ebx = 0, ebp = 0, edx = 0;
+       u16 v20 = 0, v1E = 0, v16 = 0, v14 = 0, v12 = 0, v10 = 0, v0E = 0;
+
+       int rc, df_tuner;
+       int a, b, c, d;
+       pr_debug("%s %d\n", __FUNCTION__, s->config.d60);
+
+       if (s->config.d60 != 2)
+               goto set_tuner;
+       rc = CorrectSysClockDeviation(s);
+       if (rc < 0)
+               goto set_tuner;
+
+       s->config.d60 = 1;
+       rc = ConfigureMPEGOutput(s, 0);
+       if (rc < 0)
+               goto set_tuner;
+      set_tuner:
+
+       rc = PLL_Set(s, fep, &df_tuner);
+       if (rc < 0) {
+               printk(KERN_ERR "Error in pll_set\n");
+               goto exit_rc;
+       }
+       msleep(200);
+
+       a = rc = RD16(s, 0x2150016);
+       if (rc < 0)
+               goto exit_rc;
+       b = rc = RD16(s, 0x2150010);
+       if (rc < 0)
+               goto exit_rc;
+       c = rc = RD16(s, 0x2150034);
+       if (rc < 0)
+               goto exit_rc;
+       d = rc = RD16(s, 0x2150035);
+       if (rc < 0)
+               goto exit_rc;
+       rc = WR16(s, 0x2150014, c);
+       rc = WR16(s, 0x2150015, d);
+       rc = WR16(s, 0x2150010, 0);
+       rc = WR16(s, 0x2150000, 2);
+       rc = WR16(s, 0x2150036, 0x0fff);
+       rc = WR16(s, 0x2150016, a);
+
+       rc = WR16(s, 0x2150010, 2);
+       rc = WR16(s, 0x2150007, 0);
+       rc = WR16(s, 0x2150000, 1);
+       rc = WR16(s, 0x2110000, 0);
+       rc = WR16(s, 0x0800000, 0);
+       rc = WR16(s, 0x2800000, 0);
+       rc = WR16(s, 0x2110010, 0x664);
+
+       rc = write_fw(s, DRXD_ResetECRAM);
+       rc = WR16(s, 0x2110000, 1);
+
+       rc = write_fw(s, DRXD_InitSC);
+       if (rc < 0)
+               goto exit_rc;
+
+       rc = SetCfgIfAgc(s, &s->config.ifagc);
+       if (rc < 0)
+               goto exit_rc;
+
+       rc = SetCfgRfAgc(s, &s->config.rfagc);
+       if (rc < 0)
+               goto exit_rc;
+
+       if (fep->u.ofdm.transmission_mode != TRANSMISSION_MODE_2K)
+               v22 = 1;
+       switch (fep->u.ofdm.transmission_mode) {
+       case TRANSMISSION_MODE_8K:
+               edi = 1;
+               if (s->chip_rev == DRXD_FW_B1)
+                       break;
+
+               rc = WR16(s, 0x2010010, 0);
+               if (rc < 0)
+                       break;
+               v1C = 0x63;
+               v1A = 0x53;
+               v18 = 0x43;
+               break;
+       default:
+               edi = 0;
+               if (s->chip_rev == DRXD_FW_B1)
+                       break;
+
+               rc = WR16(s, 0x2010010, 1);
+               if (rc < 0)
+                       break;
+
+               v1C = 0x61;
+               v1A = 0x47;
+               v18 = 0x41;
+       }
+
+       switch (fep->u.ofdm.guard_interval) {
+       case GUARD_INTERVAL_1_4:
+               edi |= 0x0c;
+               break;
+       case GUARD_INTERVAL_1_8:
+               edi |= 0x08;
+               break;
+       case GUARD_INTERVAL_1_16:
+               edi |= 0x04;
+               break;
+       case GUARD_INTERVAL_1_32:
+               break;
+       default:
+               v22 |= 2;
+       }
+
+       ebx = 0;
+       ebp = 0;
+       v20 = 0;
+       v1E = 0;
+       v16 = 0;
+       v14 = 0;
+       v12 = 0;
+       v10 = 0;
+       v0E = 0;
+
+       switch (fep->u.ofdm.hierarchy_information) {
+       case HIERARCHY_1:
+               edi |= 0x40;
+               if (s->chip_rev == DRXD_FW_B1)
+                       break;
+               rc = WR16(s, 0x1c10047, 1);
+               if (rc < 0)
+                       goto exit_rc;
+               rc = WR16(s, 0x2010012, 1);
+               if (rc < 0)
+                       goto exit_rc;
+               ebx = 0x19f;
+               ebp = 0x1fb;
+               v20 = 0x0c0;
+               v1E = 0x195;
+               v16 = 0x1d6;
+               v14 = 0x1ef;
+               v12 = 4;
+               v10 = 5;
+               v0E = 5;
+               break;
+       case HIERARCHY_2:
+               edi |= 0x80;
+               if (s->chip_rev == DRXD_FW_B1)
+                       break;
+               rc = WR16(s, 0x1c10047, 2);
+               if (rc < 0)
+                       goto exit_rc;
+               rc = WR16(s, 0x2010012, 2);
+               if (rc < 0)
+                       goto exit_rc;
+               ebx = 0x08f;
+               ebp = 0x12f;
+               v20 = 0x0c0;
+               v1E = 0x11e;
+               v16 = 0x1d6;
+               v14 = 0x15e;
+               v12 = 4;
+               v10 = 5;
+               v0E = 5;
+               break;
+       case HIERARCHY_4:
+               edi |= 0xc0;
+               if (s->chip_rev == DRXD_FW_B1)
+                       break;
+               rc = WR16(s, 0x1c10047, 3);
+               if (rc < 0)
+                       goto exit_rc;
+               rc = WR16(s, 0x2010012, 3);
+               if (rc < 0)
+                       goto exit_rc;
+               ebx = 0x14d;
+               ebp = 0x197;
+               v20 = 0x0c0;
+               v1E = 0x1ce;
+               v16 = 0x1d6;
+               v14 = 0x11a;
+               v12 = 4;
+               v10 = 6;
+               v0E = 5;
+               break;
+       default:
+               v22 |= 8;
+               if (s->chip_rev == DRXD_FW_B1)
+                       break;
+               rc = WR16(s, 0x1c10047, 0);
+               if (rc < 0)
+                       goto exit_rc;
+               rc = WR16(s, 0x2010012, 0);
+               if (rc < 0)
+                       goto exit_rc;
+               //              QPSK    QAM16   QAM64
+               ebx = 0x19f;    //                 62
+               ebp = 0x1fb;    //                 15
+               v20 = 0x16a;    //  62
+               v1E = 0x195;    //         62
+               v16 = 0x1bb;    //  15
+               v14 = 0x1ef;    //         15
+               v12 = 5;        //  16
+               v10 = 5;        //         16
+               v0E = 5;        //                 16
+       }
+
+       switch (fep->u.ofdm.constellation) {
+       default:
+               v22 |= 4;
+       case QPSK:
+               if (s->chip_rev == DRXD_FW_B1)
+                       break;
+
+               rc = WR16(s, 0x1c10046, 0);
+               if (rc < 0)
+                       goto exit_rc;
+               rc = WR16(s, 0x2010011, 0);
+               if (rc < 0)
+                       goto exit_rc;
+               rc = WR16(s, 0x201001a, 0x10);
+               if (rc < 0)
+                       goto exit_rc;
+               rc = WR16(s, 0x201001b, 0);
+               if (rc < 0)
+                       goto exit_rc;
+               rc = WR16(s, 0x201001c, 0);
+               if (rc < 0)
+                       goto exit_rc;
+               rc = WR16(s, 0x1c10062, v20);
+               if (rc < 0)
+                       goto exit_rc;
+               rc = WR16(s, 0x1c1002a, v1C);
+               if (rc < 0)
+                       goto exit_rc;
+               rc = WR16(s, 0x1c10015, v16);
+               if (rc < 0)
+                       goto exit_rc;
+               rc = WR16(s, 0x1c10016, v12);
+               if (rc < 0)
+                       goto exit_rc;
+               break;
+       case QAM_16:
+               edi |= 0x10;
+               if (s->chip_rev == DRXD_FW_B1)
+                       break;
+
+               rc = WR16(s, 0x1c10046, 1);
+               if (rc < 0)
+                       goto exit_rc;
+               rc = WR16(s, 0x2010011, 1);
+               if (rc < 0)
+                       goto exit_rc;
+               rc = WR16(s, 0x201001a, 0x10);
+               if (rc < 0)
+                       goto exit_rc;
+               rc = WR16(s, 0x201001b, 4);
+               if (rc < 0)
+                       goto exit_rc;
+               rc = WR16(s, 0x201001c, 0);
+               if (rc < 0)
+                       goto exit_rc;
+               rc = WR16(s, 0x1c10062, v1E);
+               if (rc < 0)
+                       goto exit_rc;
+               rc = WR16(s, 0x1c1002a, v1A);
+               if (rc < 0)
+                       goto exit_rc;
+               rc = WR16(s, 0x1c10015, v14);
+               if (rc < 0)
+                       goto exit_rc;
+               rc = WR16(s, 0x1c10016, v10);
+               if (rc < 0)
+                       goto exit_rc;
+               break;
+       case QAM_64:
+               edi |= 0x20;
+               rc = WR16(s, 0x1c10046, 2);
+               if (rc < 0)
+                       goto exit_rc;
+               rc = WR16(s, 0x2010011, 2);
+               if (rc < 0)
+                       goto exit_rc;
+               rc = WR16(s, 0x201001a, 0x20);
+               if (rc < 0)
+                       goto exit_rc;
+               rc = WR16(s, 0x201001b, 8);
+               if (rc < 0)
+                       goto exit_rc;
+               rc = WR16(s, 0x201001c, 2);
+               if (rc < 0)
+                       goto exit_rc;
+               rc = WR16(s, 0x1c10062, ebx);
+               if (rc < 0)
+                       goto exit_rc;
+               rc = WR16(s, 0x1c1002a, v18);
+               if (rc < 0)
+                       goto exit_rc;
+               rc = WR16(s, 0x1c10015, ebp);
+               if (rc < 0)
+                       goto exit_rc;
+               rc = WR16(s, 0x1c10016, v0E);
+               if (rc < 0)
+                       goto exit_rc;
+               break;
+       }
+
+       if (s->config.s20d24 == 1) {
+               rc = WR16(s, 0x2010013, 0);
+       } else {
+               rc = WR16(s, 0x2010013, 1);
+               edi |= 0x1000;
+       }
+
+       switch (fep->u.ofdm.code_rate_HP) {
+       default:
+               v22 |= 0x10;
+       case FEC_1_2:
+               if (s->chip_rev == DRXD_FW_B1)
+                       break;
+               rc = WR16(s, 0x2090011, 0);
+               break;
+       case FEC_2_3:
+               edi |= 0x200;
+               if (s->chip_rev == DRXD_FW_B1)
+                       break;
+               rc = WR16(s, 0x2090011, 1);
+               break;
+       case FEC_3_4:
+               edi |= 0x400;
+               if (s->chip_rev == DRXD_FW_B1)
+                       break;
+               rc = WR16(s, 0x2090011, 2);
+               break;
+       case FEC_5_6:           /* 5 */
+               edi |= 0x600;
+               if (s->chip_rev == DRXD_FW_B1)
+                       break;
+               rc = WR16(s, 0x2090011, 3);
+               break;
+       case FEC_7_8:           /* 7 */
+               edi |= 0x800;
+               if (s->chip_rev == DRXD_FW_B1)
+                       break;
+               rc = WR16(s, 0x2090011, 4);
+               break;
+       };
+       if (rc < 0)
+               goto exit_rc;
+
+       switch (fep->u.ofdm.bandwidth) {
+       default:
+               rc = -EINVAL;
+               goto exit_rc;
+       case BANDWIDTH_8_MHZ:   /* 0 */
+       case BANDWIDTH_AUTO:
+               rc = WR16(s, 0x0c2003f, 0x32);
+               s->bandwidth_parm = ebx = 0x8b8249;     // 9142857
+               edx = 0;
+               break;
+       case BANDWIDTH_7_MHZ:
+               rc = WR16(s, 0x0c2003f, 0x3b);
+               s->bandwidth_parm = ebx = 0x7a1200;     // 8000000
+               edx = 0x4807;
+               break;
+       case BANDWIDTH_6_MHZ:
+               rc = WR16(s, 0x0c2003f, 0x47);
+               s->bandwidth_parm = ebx = 0x68a1b6;     // 6857142
+               edx = 0x0f07;
+               break;
+       };
+
+       if (rc < 0)
+               goto exit_rc;
+
+       rc = WR16(s, 0x08200ec, edx);
+       if (rc < 0)
+               goto exit_rc;
+
+       rc = RD16(s, 0x0820050);
+       if (rc < 0)
+               goto exit_rc;
+       rc = WR16(s, 0x0820050, rc);
+
+       {
+               /* Configure bandwidth specific factor */
+               ebx = div64_u64(((u64) (s->f_osc) << 21) + (ebx >> 1),
+                                    (u64)ebx) - 0x800000;
+               EXIT_RC(WR16(s, 0x0c50010, ebx & 0xffff));
+               EXIT_RC(WR16(s, 0x0c50011, ebx >> 16));
+
+               /* drx397xD oscillator calibration */
+               ebx = div64_u64(((u64) (s->config.f_if + df_tuner) << 28) +
+                                    (s->f_osc >> 1), (u64)s->f_osc);
+       }
+       ebx &= 0xfffffff;
+       if (fep->inversion == INVERSION_ON)
+               ebx = 0x10000000 - ebx;
+
+       EXIT_RC(WR16(s, 0x0c30010, ebx & 0xffff));
+       EXIT_RC(WR16(s, 0x0c30011, ebx >> 16));
+
+       EXIT_RC(WR16(s, 0x0800000, 1));
+       EXIT_RC(RD16(s, 0x0800000));
+
+
+       EXIT_RC(SC_WaitForReady(s));
+       EXIT_RC(WR16(s, 0x0820042, 0));
+       EXIT_RC(WR16(s, 0x0820041, v22));
+       EXIT_RC(WR16(s, 0x0820040, edi));
+       EXIT_RC(SC_SendCommand(s, 3));
+
+       rc = RD16(s, 0x0800000);
+
+       SC_WaitForReady(s);
+       WR16(s, 0x0820042, 0);
+       WR16(s, 0x0820041, 1);
+       WR16(s, 0x0820040, 1);
+       SC_SendCommand(s, 1);
+
+//      rc = WR16(s, 0x2150000, 1);
+//      if (rc < 0) goto exit_rc;
+
+       rc = WR16(s, 0x2150000, 2);
+       rc = WR16(s, 0x2150016, a);
+       rc = WR16(s, 0x2150010, 4);
+       rc = WR16(s, 0x2150036, 0);
+       rc = WR16(s, 0x2150000, 1);
+       s->config.d60 = 2;
+      exit_rc:
+       return rc;
+}
+
+/*******************************************************************************
+ * DVB interface
+ ******************************************************************************/
+
+static int drx397x_init(struct dvb_frontend *fe)
+{
+       struct drx397xD_state *s = fe->demodulator_priv;
+       int rc;
+
+       pr_debug("%s\n", __FUNCTION__);
+
+       s->config.rfagc.d00 = 2;        /* 0x7c */
+       s->config.rfagc.w04 = 0;
+       s->config.rfagc.w06 = 0x3ff;
+
+       s->config.ifagc.d00 = 0;        /* 0x68 */
+       s->config.ifagc.w04 = 0;
+       s->config.ifagc.w06 = 140;
+       s->config.ifagc.w08 = 0;
+       s->config.ifagc.w0A = 0x3ff;
+       s->config.ifagc.w0C = 0x388;
+
+       /* for signal strenght calculations */
+       s->config.ss76 = 820;
+       s->config.ss78 = 2200;
+       s->config.ss7A = 150;
+
+       /* HI_CfgCommand */
+       s->config.w50 = 4;
+       s->config.w52 = 9;      // 0xf;
+
+       s->config.f_if = 42800000;      /* d14: intermediate frequency [Hz]     */
+       s->config.f_osc = 48000;        /* s66 : oscillator frequency [kHz]     */
+       s->config.w92 = 12000;  // 20000;
+
+       s->config.w9C = 0x000e;
+       s->config.w9E = 0x0000;
+
+       /* ConfigureMPEGOutput params */
+       s->config.wA0 = 4;
+       s->config.w98 = 1;      // 0;
+       s->config.w9A = 1;
+
+       /* get chip revision */
+       rc = RD16(s, 0x2410019);
+       if (rc < 0)
+               return -ENODEV;
+
+       if (rc == 0) {
+               printk(KERN_INFO "%s: chip revision A2\n", mod_name);
+               rc = drx_load_fw(s, DRXD_FW_A2);
+       } else {
+
+               rc = (rc >> 12) - 3;
+               switch (rc) {
+               case 1:
+                       s->flags |= F_SET_0D4h;
+               case 0:
+               case 4:
+                       s->flags |= F_SET_0D0h;
+                       break;
+               case 2:
+               case 5:
+                       break;
+               case 3:
+                       s->flags |= F_SET_0D4h;
+                       break;
+               default:
+                       return -ENODEV;
+               };
+               printk(KERN_INFO "%s: chip revision B1.%d\n", mod_name, rc);
+               rc = drx_load_fw(s, DRXD_FW_B1);
+       }
+       if (rc < 0)
+               goto error;
+
+       rc = WR16(s, 0x0420033, 0x3973);
+       if (rc < 0)
+               goto error;
+
+       rc = HI_Command(s, 2);
+
+       msleep(1);
+
+       if (s->chip_rev == DRXD_FW_A2) {
+               rc = WR16(s, 0x043012d, 0x47F);
+               if (rc < 0)
+                       goto error;
+       }
+       rc = WR16_E0(s, 0x0400000, 0);
+       if (rc < 0)
+               goto error;
+
+       if (s->config.w92 > 20000 || s->config.w92 % 4000) {
+               printk(KERN_ERR "%s: invalid osc frequency\n", mod_name);
+               rc = -1;
+               goto error;
+       }
+
+       rc = WR16(s, 0x2410010, 1);
+       if (rc < 0)
+               goto error;
+       rc = WR16(s, 0x2410011, 0x15);
+       if (rc < 0)
+               goto error;
+       rc = WR16(s, 0x2410012, s->config.w92 / 4000);
+       if (rc < 0)
+               goto error;
+#ifdef ORIG_FW
+       rc = WR16(s, 0x2410015, 2);
+       if (rc < 0)
+               goto error;
+#endif
+       rc = WR16(s, 0x2410017, 0x3973);
+       if (rc < 0)
+               goto error;
+
+       s->f_osc = s->config.f_osc * 1000;      /* initial estimator */
+
+       s->config.w56 = 1;
+
+       rc = HI_CfgCommand(s);
+       if (rc < 0)
+               goto error;
+
+       rc = write_fw(s, DRXD_InitAtomicRead);
+       if (rc < 0)
+               goto error;
+
+       if (s->chip_rev == DRXD_FW_A2) {
+               rc = WR16(s, 0x2150013, 0);
+               if (rc < 0)
+                       goto error;
+       }
+
+       rc = WR16_E0(s, 0x0400002, 0);
+       if (rc < 0)
+               goto error;
+       rc = WR16(s, 0x0400002, 0);
+       if (rc < 0)
+               goto error;
+
+       if (s->chip_rev == DRXD_FW_A2) {
+               rc = write_fw(s, DRXD_ResetCEFR);
+               if (rc < 0)
+                       goto error;
+       }
+       rc = write_fw(s, DRXD_microcode);
+       if (rc < 0)
+               goto error;
+
+       s->config.w9C = 0x0e;
+       if (s->flags & F_SET_0D0h) {
+               s->config.w9C = 0;
+               rc = RD16(s, 0x0c20010);
+               if (rc < 0)
+                       goto write_DRXD_InitFE_1;
+
+               rc &= ~0x1000;
+               rc = WR16(s, 0x0c20010, rc);
+               if (rc < 0)
+                       goto write_DRXD_InitFE_1;
+
+               rc = RD16(s, 0x0c20011);
+               if (rc < 0)
+                       goto write_DRXD_InitFE_1;
+
+               rc &= ~0x8;
+               rc = WR16(s, 0x0c20011, rc);
+               if (rc < 0)
+                       goto write_DRXD_InitFE_1;
+
+               rc = WR16(s, 0x0c20012, 1);
+       }
+
+      write_DRXD_InitFE_1:
+
+       rc = write_fw(s, DRXD_InitFE_1);
+       if (rc < 0)
+               goto error;
+
+       rc = 1;
+       if (s->chip_rev == DRXD_FW_B1) {
+               if (s->flags & F_SET_0D0h)
+                       rc = 0;
+       } else {
+               if (s->flags & F_SET_0D0h)
+                       rc = 4;
+       }
+
+       rc = WR16(s, 0x0C20012, rc);
+       if (rc < 0)
+               goto error;
+
+       rc = WR16(s, 0x0C20013, s->config.w9E);
+       if (rc < 0)
+               goto error;
+       rc = WR16(s, 0x0C20015, s->config.w9C);
+       if (rc < 0)
+               goto error;
+
+       rc = write_fw(s, DRXD_InitFE_2);
+       if (rc < 0)
+               goto error;
+       rc = write_fw(s, DRXD_InitFT);
+       if (rc < 0)
+               goto error;
+       rc = write_fw(s, DRXD_InitCP);
+       if (rc < 0)
+               goto error;
+       rc = write_fw(s, DRXD_InitCE);
+       if (rc < 0)
+               goto error;
+       rc = write_fw(s, DRXD_InitEQ);
+       if (rc < 0)
+               goto error;
+       rc = write_fw(s, DRXD_InitEC);
+       if (rc < 0)
+               goto error;
+       rc = write_fw(s, DRXD_InitSC);
+       if (rc < 0)
+               goto error;
+
+       rc = SetCfgIfAgc(s, &s->config.ifagc);
+       if (rc < 0)
+               goto error;
+
+       rc = SetCfgRfAgc(s, &s->config.rfagc);
+       if (rc < 0)
+               goto error;
+
+       rc = ConfigureMPEGOutput(s, 1);
+       rc = WR16(s, 0x08201fe, 0x0017);
+       rc = WR16(s, 0x08201ff, 0x0101);
+
+       s->config.d5C = 0;
+       s->config.d60 = 1;
+       s->config.d48 = 1;
+      error:
+       return rc;
+}
+
+static int drx397x_get_frontend(struct dvb_frontend *fe,
+                               struct dvb_frontend_parameters *params)
+{
+       return 0;
+}
+
+static int drx397x_set_frontend(struct dvb_frontend *fe,
+                               struct dvb_frontend_parameters *params)
+{
+       struct drx397xD_state *s = fe->demodulator_priv;
+
+       s->config.s20d24 = 1;   // 0;
+       return drx_tune(s, params);
+}
+
+static int drx397x_get_tune_settings(struct dvb_frontend *fe,
+                                    struct dvb_frontend_tune_settings
+                                    *fe_tune_settings)
+{
+       fe_tune_settings->min_delay_ms = 10000;
+       fe_tune_settings->step_size = 0;
+       fe_tune_settings->max_drift = 0;
+       return 0;
+}
+
+static int drx397x_read_status(struct dvb_frontend *fe, fe_status_t * status)
+{
+       struct drx397xD_state *s = fe->demodulator_priv;
+       int lockstat;
+
+       GetLockStatus(s, &lockstat);
+       /* TODO */
+//      if (lockstat & 1)
+//      CorrectSysClockDeviation(s);
+
+       *status = 0;
+       if (lockstat & 2) {
+               CorrectSysClockDeviation(s);
+               ConfigureMPEGOutput(s, 1);
+               *status = FE_HAS_LOCK | FE_HAS_SYNC | FE_HAS_VITERBI;
+       }
+       if (lockstat & 4) {
+               *status |= FE_HAS_CARRIER | FE_HAS_SIGNAL;
+       }
+
+       return 0;
+}
+
+static int drx397x_read_ber(struct dvb_frontend *fe, unsigned int *ber)
+{
+       *ber = 0;
+       return 0;
+}
+
+static int drx397x_read_snr(struct dvb_frontend *fe, u16 * snr)
+{
+       *snr = 0;
+       return 0;
+}
+
+static int drx397x_read_signal_strength(struct dvb_frontend *fe, u16 * strength)
+{
+       struct drx397xD_state *s = fe->demodulator_priv;
+       int rc;
+
+       if (s->config.ifagc.d00 == 2) {
+               *strength = 0xffff;
+               return 0;
+       }
+       rc = RD16(s, 0x0c20035);
+       if (rc < 0) {
+               *strength = 0;
+               return 0;
+       }
+       rc &= 0x3ff;
+       /* Signal strength is calculated using the following formula:
+        *
+        * a = 2200 * 150 / (2200 + 150);
+        * a = a * 3300 /  (a + 820);
+        * b = 2200 * 3300 / (2200 + 820);
+        * c = (((b-a) * rc) >> 10  + a) << 4;
+        * strength = ~c & 0xffff;
+        *
+        * The following does the same but with less rounding errors:
+        */
+       *strength = ~(7720 + (rc * 30744 >> 10));
+       return 0;
+}
+
+static int drx397x_read_ucblocks(struct dvb_frontend *fe,
+                                unsigned int *ucblocks)
+{
+       *ucblocks = 0;
+       return 0;
+}
+
+static int drx397x_sleep(struct dvb_frontend *fe)
+{
+       return 0;
+}
+
+static void drx397x_release(struct dvb_frontend *fe)
+{
+       struct drx397xD_state *s = fe->demodulator_priv;
+       printk(KERN_INFO "%s: release demodulator\n", mod_name);
+       if (s) {
+               drx_release_fw(s);
+               kfree(s);
+       }
+
+}
+
+static struct dvb_frontend_ops drx397x_ops = {
+
+       .info = {
+                .name                  = "Micronas DRX397xD DVB-T Frontend",
+                .type                  = FE_OFDM,
+                .frequency_min         = 47125000,
+                .frequency_max         = 855250000,
+                .frequency_stepsize    = 166667,
+                .frequency_tolerance   = 0,
+                .caps =                                        /* 0x0C01B2EAE */
+                        FE_CAN_FEC_1_2                 |       // = 0x2,
+                        FE_CAN_FEC_2_3                 |       // = 0x4,
+                        FE_CAN_FEC_3_4                 |       // = 0x8,
+                        FE_CAN_FEC_5_6                 |       // = 0x20,
+                        FE_CAN_FEC_7_8                 |       // = 0x80,
+                        FE_CAN_FEC_AUTO                |       // = 0x200,
+                        FE_CAN_QPSK                    |       // = 0x400,
+                        FE_CAN_QAM_16                  |       // = 0x800,
+                        FE_CAN_QAM_64                  |       // = 0x2000,
+                        FE_CAN_QAM_AUTO                |       // = 0x10000,
+                        FE_CAN_TRANSMISSION_MODE_AUTO  |       // = 0x20000,
+                        FE_CAN_GUARD_INTERVAL_AUTO     |       // = 0x80000,
+                        FE_CAN_HIERARCHY_AUTO          |       // = 0x100000,
+                        FE_CAN_RECOVER                 |       // = 0x40000000,
+                        FE_CAN_MUTE_TS                         // = 0x80000000
+        },
+
+       .release = drx397x_release,
+       .init = drx397x_init,
+       .sleep = drx397x_sleep,
+
+       .set_frontend = drx397x_set_frontend,
+       .get_tune_settings = drx397x_get_tune_settings,
+       .get_frontend = drx397x_get_frontend,
+
+       .read_status = drx397x_read_status,
+       .read_snr = drx397x_read_snr,
+       .read_signal_strength = drx397x_read_signal_strength,
+       .read_ber = drx397x_read_ber,
+       .read_ucblocks = drx397x_read_ucblocks,
+};
+
+struct dvb_frontend *drx397xD_attach(const struct drx397xD_config *config,
+                                    struct i2c_adapter *i2c)
+{
+       struct drx397xD_state *s = NULL;
+
+       /* allocate memory for the internal state */
+       s = kzalloc(sizeof(struct drx397xD_state), GFP_KERNEL);
+       if (s == NULL)
+               goto error;
+
+       /* setup the state */
+       s->i2c = i2c;
+       memcpy(&s->config, config, sizeof(struct drx397xD_config));
+
+       /* check if the demod is there */
+       if (RD16(s, 0x2410019) < 0)
+               goto error;
+
+       /* create dvb_frontend */
+       memcpy(&s->frontend.ops, &drx397x_ops, sizeof(struct dvb_frontend_ops));
+       s->frontend.demodulator_priv = s;
+
+       return &s->frontend;
+      error:
+       kfree(s);
+       return NULL;
+}
+
+MODULE_DESCRIPTION("Micronas DRX397xD DVB-T Frontend");
+MODULE_AUTHOR("Henk Vergonet");
+MODULE_LICENSE("GPL");
+
+EXPORT_SYMBOL(drx397xD_attach);
diff --git a/drivers/media/dvb/frontends/drx397xD.h b/drivers/media/dvb/frontends/drx397xD.h
new file mode 100644 (file)
index 0000000..ddc7a07
--- /dev/null
@@ -0,0 +1,130 @@
+/*
+ *  Driver for Micronas DVB-T drx397xD demodulator
+ *
+ *  Copyright (C) 2007 Henk vergonet <Henk.Vergonet@gmail.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.=
+ */
+
+#ifndef _DRX397XD_H_INCLUDED
+#define _DRX397XD_H_INCLUDED
+
+#include <linux/dvb/frontend.h>
+
+#define DRX_F_STEPSIZE 166667
+#define DRX_F_OFFSET   36000000
+
+#define I2C_ADR_C0(x) \
+(      (u32)cpu_to_le32( \
+               (u32)( \
+                       (((u32)(x) & (u32)0x000000ffUL)      ) | \
+                       (((u32)(x) & (u32)0x0000ff00UL) << 16) | \
+                       (((u32)(x) & (u32)0x0fff0000UL) >>  8) | \
+                        (           (u32)0x00c00000UL)          \
+                     )) \
+)
+
+#define I2C_ADR_E0(x) \
+(      (u32)cpu_to_le32( \
+               (u32)( \
+                       (((u32)(x) & (u32)0x000000ffUL)      ) | \
+                       (((u32)(x) & (u32)0x0000ff00UL) << 16) | \
+                       (((u32)(x) & (u32)0x0fff0000UL) >>  8) | \
+                        (           (u32)0x00e00000UL)          \
+                     )) \
+)
+
+struct drx397xD_CfgRfAgc       /* 0x7c */
+{
+       int d00;        /* 2 */
+       u16 w04;
+       u16 w06;
+};
+
+struct drx397xD_CfgIfAgc       /* 0x68 */
+{
+       int d00;        /* 0 */
+       u16 w04;        /* 0 */
+       u16 w06;
+       u16 w08;
+       u16 w0A;
+       u16 w0C;
+};
+
+struct drx397xD_s20 {
+       int d04;
+       u32 d18;
+       u32 d1C;
+       u32 d20;
+       u32 d14;
+       u32 d24;
+       u32 d0C;
+       u32 d08;
+};
+
+struct drx397xD_config
+{
+       /* demodulator's I2C address */
+       u8      demod_address;          /* 0x0f */
+
+       struct drx397xD_CfgIfAgc  ifagc;  /* 0x68 */
+       struct drx397xD_CfgRfAgc  rfagc;  /* 0x7c */
+       u32     s20d24;
+
+       /* HI_CfgCommand parameters */
+       u16     w50, w52, /* w54, */ w56;
+
+       int     d5C;
+       int     d60;
+       int     d48;
+       int     d28;
+
+       u32     f_if;   /* d14: intermediate frequency [Hz]             */
+                       /*      36000000 on Cinergy 2400i DT            */
+                       /*      42800000 on Pinnacle Hybrid PRO 330e    */
+
+       u16     f_osc;  /* s66: 48000 oscillator frequency [kHz]        */
+
+       u16     w92;    /* 20000 */
+
+       u16     wA0;
+       u16     w98;
+       u16     w9A;
+
+       u16     w9C;    /* 0xe0 */
+       u16     w9E;    /* 0x00 */
+
+       /* used for signal strength calculations in
+          drx397x_read_signal_strength
+       */
+       u16     ss78;   // 2200
+       u16     ss7A;   // 150
+       u16     ss76;   // 820
+};
+
+#if defined(CONFIG_DVB_DRX397XD) || (defined(CONFIG_DVB_DRX397XD_MODULE) && defined(MODULE))
+extern struct dvb_frontend* drx397xD_attach(const struct drx397xD_config *config,
+                                          struct i2c_adapter *i2c);
+#else
+static inline struct dvb_frontend* drx397xD_attach(const struct drx397xD_config *config,
+                                          struct i2c_adapter *i2c)
+{
+       printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
+       return NULL;
+}
+#endif /* CONFIG_DVB_DRX397XD */
+
+#endif /* _DRX397XD_H_INCLUDED */
diff --git a/drivers/media/dvb/frontends/drx397xD_fw.h b/drivers/media/dvb/frontends/drx397xD_fw.h
new file mode 100644 (file)
index 0000000..01de02a
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Firmware definitions for Micronas drx397xD
+ *
+ * Copyright (C) 2007 Henk Vergonet <Henk.Vergonet@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef _FW_ENTRY
+       _FW_ENTRY("drx397xD.A2.fw",     DRXD_FW_A2 = 0          ),
+       _FW_ENTRY("drx397xD.B1.fw",     DRXD_FW_B1              ),
+#undef _FW_ENTRY
+#endif /* _FW_ENTRY */
+
+#ifdef _BLOB_ENTRY
+       _BLOB_ENTRY("InitAtomicRead",   DRXD_InitAtomicRead = 0 ),
+       _BLOB_ENTRY("InitCE",           DRXD_InitCE             ),
+       _BLOB_ENTRY("InitCP",           DRXD_InitCP             ),
+       _BLOB_ENTRY("InitEC",           DRXD_InitEC             ),
+       _BLOB_ENTRY("InitEQ",           DRXD_InitEQ             ),
+       _BLOB_ENTRY("InitFE_1",         DRXD_InitFE_1           ),
+       _BLOB_ENTRY("InitFE_2",         DRXD_InitFE_2           ),
+       _BLOB_ENTRY("InitFT",           DRXD_InitFT             ),
+       _BLOB_ENTRY("InitSC",           DRXD_InitSC             ),
+       _BLOB_ENTRY("ResetCEFR",        DRXD_ResetCEFR          ),
+       _BLOB_ENTRY("ResetECRAM",       DRXD_ResetECRAM         ),
+       _BLOB_ENTRY("microcode",        DRXD_microcode          ),
+#undef _BLOB_ENTRY
+#endif /* _BLOB_ENTRY */
diff --git a/drivers/media/dvb/frontends/z0194a.h b/drivers/media/dvb/frontends/z0194a.h
new file mode 100644 (file)
index 0000000..d2876d2
--- /dev/null
@@ -0,0 +1,97 @@
+/* z0194a.h Sharp z0194a tuner support
+*
+* Copyright (C) 2008 Igor M. Liplianin (liplianin@me.by)
+*
+*      This program is free software; you can redistribute it and/or modify it
+*      under the terms of the GNU General Public License as published by the
+*      Free Software Foundation, version 2.
+*
+* see Documentation/dvb/README.dvb-usb for more information
+*/
+
+#ifndef Z0194A
+#define Z0194A
+
+static int sharp_z0194a__set_symbol_rate(struct dvb_frontend *fe,
+                                        u32 srate, u32 ratio)
+{
+       u8 aclk = 0;
+       u8 bclk = 0;
+
+       if (srate < 1500000) {
+               aclk = 0xb7; bclk = 0x47; }
+       else if (srate < 3000000) {
+               aclk = 0xb7; bclk = 0x4b; }
+       else if (srate < 7000000) {
+               aclk = 0xb7; bclk = 0x4f; }
+       else if (srate < 14000000) {
+               aclk = 0xb7; bclk = 0x53; }
+       else if (srate < 30000000) {
+               aclk = 0xb6; bclk = 0x53; }
+       else if (srate < 45000000) {
+               aclk = 0xb4; bclk = 0x51; }
+
+       stv0299_writereg(fe, 0x13, aclk);
+       stv0299_writereg(fe, 0x14, bclk);
+       stv0299_writereg(fe, 0x1f, (ratio >> 16) & 0xff);
+       stv0299_writereg(fe, 0x20, (ratio >> 8) & 0xff);
+       stv0299_writereg(fe, 0x21, (ratio) & 0xf0);
+
+       return 0;
+}
+
+static u8 sharp_z0194a__inittab[] = {
+       0x01, 0x15,
+       0x02, 0x00,
+       0x03, 0x00,
+       0x04, 0x7d,   /* F22FR = 0x7d, F22 = f_VCO / 128 / 0x7d = 22 kHz */
+       0x05, 0x35,   /* I2CT = 0, SCLT = 1, SDAT = 1 */
+       0x06, 0x40,   /* DAC not used, set to high impendance mode */
+       0x07, 0x00,   /* DAC LSB */
+       0x08, 0x40,   /* DiSEqC off, LNB power on OP2/LOCK pin on */
+       0x09, 0x00,   /* FIFO */
+       0x0c, 0x51,   /* OP1 ctl = Normal, OP1 val = 1 (LNB Power ON) */
+       0x0d, 0x82,   /* DC offset compensation = ON, beta_agc1 = 2 */
+       0x0e, 0x23,   /* alpha_tmg = 2, beta_tmg = 3 */
+       0x10, 0x3f,   /* AGC2  0x3d */
+       0x11, 0x84,
+       0x12, 0xb9,
+       0x15, 0xc9,   /* lock detector threshold */
+       0x16, 0x00,
+       0x17, 0x00,
+       0x18, 0x00,
+       0x19, 0x00,
+       0x1a, 0x00,
+       0x1f, 0x50,
+       0x20, 0x00,
+       0x21, 0x00,
+       0x22, 0x00,
+       0x23, 0x00,
+       0x28, 0x00,  /* out imp: normal  out type: parallel FEC mode:0 */
+       0x29, 0x1e,  /* 1/2 threshold */
+       0x2a, 0x14,  /* 2/3 threshold */
+       0x2b, 0x0f,  /* 3/4 threshold */
+       0x2c, 0x09,  /* 5/6 threshold */
+       0x2d, 0x05,  /* 7/8 threshold */
+       0x2e, 0x01,
+       0x31, 0x1f,  /* test all FECs */
+       0x32, 0x19,  /* viterbi and synchro search */
+       0x33, 0xfc,  /* rs control */
+       0x34, 0x93,  /* error control */
+       0x0f, 0x52,
+       0xff, 0xff
+};
+
+static struct stv0299_config sharp_z0194a_config = {
+       .demod_address = 0x68,
+       .inittab = sharp_z0194a__inittab,
+       .mclk = 88000000UL,
+       .invert = 1,
+       .skip_reinit = 0,
+       .lock_output = STV0299_LOCKOUTPUT_1,
+       .volt13_op0_op1 = STV0299_VOLT13_OP1,
+       .min_delay_ms = 100,
+       .set_symbol_rate = sharp_z0194a__set_symbol_rate,
+};
+
+#endif
index 4e3f83e4e48f34f4f2878df5823c00f3f0729bc7..97c6853ad1d324313f5d3a54748dee7c66447a87 100644 (file)
@@ -85,6 +85,7 @@
 #include <linux/input.h>
 #include <linux/videodev2.h>
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 #include <linux/usb.h>
 
 /*
index 09fe6f1cdf14b124d8b10fcc64e91bc91625649e..4a332fe8b64b1a2769ee5b37fdee888fee31820d 100644 (file)
@@ -23,6 +23,7 @@
 #include <linux/init.h>
 #include <linux/videodev.h>
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 #include "oss/aci.h"
 #include "miropcm20-rds-core.h"
 
index 1ec18ed1a73365dbfad685238648f63faeba4177..ec8d64704dd03f19a88f0b9e21c6c3f7ad74726f 100644 (file)
@@ -36,6 +36,7 @@
 #include <asm/uaccess.h>       /* copy to/from user            */
 #include <linux/videodev2.h>   /* kernel radio structs         */
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 
 #include <linux/version.h>     /* for KERNEL_VERSION MACRO     */
 #define RADIO_VERSION KERNEL_VERSION(0,0,2)
index 46cdb549eac736eb1321777e9616e2f7fe5070d8..639164a974a13d11721f26158551149ea832478f 100644 (file)
@@ -33,6 +33,7 @@
 #include <asm/uaccess.h>       /* copy to/from user            */
 #include <linux/videodev2.h>   /* kernel radio structs         */
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 
 #include <linux/version.h>      /* for KERNEL_VERSION MACRO     */
 #define RADIO_VERSION KERNEL_VERSION(0,0,2)
index b14db53ea456514153ee49ae0a61759c3d522847..484ea87d7fbaba7ce416d33e98abb40b423314be 100644 (file)
@@ -39,6 +39,7 @@
 #include <asm/uaccess.h>       /* copy to/from user            */
 #include <linux/videodev2.h>   /* V4L2 API defs                */
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 #include <linux/param.h>
 #include <linux/pnp.h>
 
index de49be971480fd8ec1b569904f8d329fd3ee821f..2b834b95f3e7bc2f43f493b929bbee7d685e81d6 100644 (file)
@@ -46,6 +46,7 @@
 #include <linux/pci.h>
 #include <linux/videodev2.h>
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 #include <linux/errno.h>
 
 #include <linux/version.h>      /* for KERNEL_VERSION MACRO     */
index 81f6aeb1cd1154d62e707d41d620381fa100c25c..4740bacc2f88e43a59768f308223b9d2c3c3f9f1 100644 (file)
@@ -23,6 +23,7 @@
 #include <asm/io.h>            /* outb, outb_p                 */
 #include <asm/uaccess.h>       /* copy to/from user            */
 #include <linux/videodev2.h>   /* kernel radio structs         */
+#include <media/v4l2-ioctl.h>
 #include <media/v4l2-common.h>
 #include <linux/spinlock.h>
 
index bddd3c409aa95a84112b1930ea0844ab060b4150..040a73fac69488b2911b8f90941b45d5e3f980d7 100644 (file)
@@ -27,6 +27,7 @@
 #include <linux/pci.h>
 #include <linux/videodev2.h>
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 
 #include <linux/version.h>      /* for KERNEL_VERSION MACRO     */
 #define RADIO_VERSION KERNEL_VERSION(0,0,6)
index 0133ecf3e040b0905f157581283c384f6ec7b876..9e824a7d5cc4de8f76aa08ec52a67c2f6b1fdcaf 100644 (file)
@@ -44,6 +44,7 @@
 #include <linux/pci.h>
 #include <linux/videodev2.h>
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 
 #define DRIVER_VERSION "0.77"
 
index 070802103dc34d52176b87fa78c43511f2ce3798..c3fb270f211b2525d57f9cf831d9500069bc58a5 100644 (file)
@@ -17,6 +17,7 @@
 #include <asm/uaccess.h>       /* copy to/from user            */
 #include <linux/videodev2.h>   /* kernel radio structs         */
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 #include <linux/spinlock.h>
 
 #include <linux/version.h>      /* for KERNEL_VERSION MACRO     */
index 66e052fd3909aa3531ce5e7b1e22bfe91f865537..bb8b1c9107b12fec3c0362b6f16f7b51d23a4172 100644 (file)
@@ -24,6 +24,7 @@
 #include <linux/delay.h>       /* udelay                       */
 #include <linux/videodev2.h>   /* kernel radio structs         */
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 #include <linux/isapnp.h>
 #include <asm/io.h>            /* outb, outb_p                 */
 #include <asm/uaccess.h>       /* copy to/from user            */
index b0ccf7cb5952a8c0edda2ef0588a0800fe1a6682..9fa025b704cb8a387c7eb4b499b941667238bc38 100644 (file)
@@ -22,6 +22,7 @@
 #include <asm/uaccess.h>       /* copy to/from user            */
 #include <linux/videodev2.h>   /* kernel radio structs         */
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 #include <linux/mutex.h>
 
 static struct mutex lock;
index dc93a882b38595114169bb575820cf023155a460..333612180176d537aea6a13600cec5d93ea320f0 100644 (file)
 #include <linux/videodev2.h>
 #include <linux/mutex.h>
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 #include <media/rds.h>
 #include <asm/unaligned.h>
 
index acc32080e9bdefef40bc84d0e2e0bbf09f758a42..a9914dbcf493acb071a6eaa64b23eeacc1a04f1a 100644 (file)
@@ -32,6 +32,7 @@
 #include <asm/uaccess.h>       /* copy to/from user            */
 #include <linux/videodev2.h>   /* kernel radio structs         */
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 #include <linux/spinlock.h>
 
 #include <linux/version.h>      /* for KERNEL_VERSION MACRO     */
index 4ebdfbadeb9ce6160d7d7ea023b87cc6d13860c3..560c49481a2ddc66b9ee8333a8a3809c53a6985f 100644 (file)
@@ -23,6 +23,7 @@
 #include <asm/uaccess.h>
 #include <linux/videodev2.h>
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 
 #include <linux/version.h>      /* for KERNEL_VERSION MACRO     */
 #define RADIO_VERSION KERNEL_VERSION(0,0,2)
index 18f2abd7e2552e985d670551b1abc729c0d24d5f..023d6f3c751cc329af3a21f8d9617f0a41b4250c 100644 (file)
@@ -40,6 +40,7 @@
 #include <asm/uaccess.h>       /* copy to/from user              */
 #include <linux/videodev2.h>   /* kernel radio structs           */
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 
 #include <linux/version.h>      /* for KERNEL_VERSION MACRO     */
 #define RADIO_VERSION KERNEL_VERSION(0,1,1)
index 43773c56c62f0fcd45e25f87629591d51fb5d5ce..cf0355bb6ef75748d21432d4f3a115b3cc9c9af0 100644 (file)
@@ -37,6 +37,7 @@
 #include <asm/uaccess.h>       /* copy to/from user              */
 #include <linux/videodev2.h>   /* kernel radio structs           */
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 
 #include <linux/version.h>      /* for KERNEL_VERSION MACRO     */
 #define RADIO_VERSION KERNEL_VERSION(0,0,2)
index f606d2951fde5a44fb650df92187ff71cd5ea3ad..2a747db6dc3e8653c13fa2bbf2eb5bb49a94e44a 100644 (file)
@@ -806,13 +806,7 @@ menuconfig V4L_USB_DRIVERS
 
 if V4L_USB_DRIVERS && USB
 
-config USB_VIDEO_CLASS
-       tristate "USB Video Class (UVC)"
-       ---help---
-         Support for the USB Video Class (UVC).  Currently only video
-         input devices, such as webcams, are supported.
-
-         For more information see: <http://linux-uvc.berlios.de/>
+source "drivers/media/video/uvc/Kconfig"
 
 source "drivers/media/video/gspca/Kconfig"
 
index 45d5db5abb1eabe445c8af4cf8182e0f1728c6f9..9de1e4885246675a622a105f9b7b803159892646 100644 (file)
@@ -10,6 +10,8 @@ msp3400-objs  :=      msp3400-driver.o msp3400-kthreads.o
 
 stkwebcam-objs :=      stk-webcam.o stk-sensor.o
 
+videodev-objs  :=      v4l2-dev.o v4l2-ioctl.o
+
 obj-$(CONFIG_VIDEO_DEV) += videodev.o compat_ioctl32.o v4l2-int-device.o
 
 obj-$(CONFIG_VIDEO_V4L2_COMMON) += v4l2-common.o
index 0ea559a7fe59ea3dba50fc435dfd57900477592f..33c72055447d69d1f6da90cd2b46c64afcd7baa7 100644 (file)
@@ -45,6 +45,7 @@
 #include <linux/kdev_t.h>
 #include "bttvp.h"
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 #include <media/tvaudio.h>
 #include <media/msp3400.h>
 
@@ -163,8 +164,8 @@ MODULE_LICENSE("GPL");
 static ssize_t show_card(struct device *cd,
                         struct device_attribute *attr, char *buf)
 {
-       struct video_device *vfd = container_of(cd, struct video_device, class_dev);
-       struct bttv *btv = dev_get_drvdata(vfd->dev);
+       struct video_device *vfd = container_of(cd, struct video_device, dev);
+       struct bttv *btv = dev_get_drvdata(vfd->parent);
        return sprintf(buf, "%d\n", btv ? btv->c.type : UNSET);
 }
 static DEVICE_ATTR(card, S_IRUGO, show_card, NULL);
@@ -4185,7 +4186,7 @@ static struct video_device *vdev_init(struct bttv *btv,
                return NULL;
        *vfd = *template;
        vfd->minor   = -1;
-       vfd->dev     = &btv->c.pci->dev;
+       vfd->parent  = &btv->c.pci->dev;
        vfd->release = video_device_release;
        vfd->type    = type;
        vfd->debug   = bttv_debug;
@@ -4244,7 +4245,7 @@ static int __devinit bttv_register_video(struct bttv *btv)
                goto err;
        printk(KERN_INFO "bttv%d: registered device video%d\n",
               btv->c.nr,btv->video_dev->minor & 0x1f);
-       if (device_create_file(&btv->video_dev->class_dev,
+       if (device_create_file(&btv->video_dev->dev,
                                     &dev_attr_card)<0) {
                printk(KERN_ERR "bttv%d: device_create_file 'card' "
                       "failed\n", btv->c.nr);
index 0af586876e72f6f7f01295cb99381f159feec47e..649682aac1acebf4ff3a4bc45033f897258f875f 100644 (file)
@@ -31,6 +31,7 @@
 #include <linux/interrupt.h>
 #include <asm/page.h>
 #include <asm/pgtable.h>
+#include <media/v4l2-ioctl.h>
 
 #include "bttvp.h"
 
index 68f28e5fa0409307c460546e511dbbb68b7a04e0..6819e21a3773ea747a7ef8e5762076d097f9d008 100644 (file)
@@ -29,6 +29,7 @@
 #include <linux/kernel.h>
 #include <linux/interrupt.h>
 #include <linux/kdev_t.h>
+#include <media/v4l2-ioctl.h>
 #include <asm/io.h>
 #include "bttvp.h"
 
index b364adaae78d8e8262043a5e2c3734249ca01c51..e367862313e198259b9b37176b2956e66a8ecb67 100644 (file)
@@ -74,6 +74,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include <linux/sched.h>
 #include <linux/videodev.h>
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 #include <linux/mutex.h>
 #include <asm/uaccess.h>
 
index fe1e67bb1ca860b6a946afb0ed6804654c8bf4ce..8d690410c84f20f5bf74896d8153291ae6a61c9d 100644 (file)
@@ -35,6 +35,7 @@
 #include <linux/sched.h>
 #include <linux/videodev.h>
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 #include <linux/mutex.h>
 #include <linux/jiffies.h>
 
index d99453faaab79715d3723492e99a9ea9d9a92116..302c57f151c2a1247b59e20b245074490d3ac1d9 100644 (file)
@@ -25,6 +25,7 @@
 #include <linux/spinlock.h>
 #include <linux/videodev2.h>
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 #include <media/v4l2-chip-ident.h>
 #include <linux/device.h>
 #include <linux/wait.h>
@@ -2157,7 +2158,7 @@ static int cafe_pci_probe(struct pci_dev *pdev,
        cam->v4ldev = cafe_v4l_template;
        cam->v4ldev.debug = 0;
 //     cam->v4ldev.debug = V4L2_DEBUG_IOCTL_ARG;
-       cam->v4ldev.dev = &pdev->dev;
+       cam->v4ldev.parent = &pdev->dev;
        ret = video_register_device(&cam->v4ldev, VFL_TYPE_GRABBER, -1);
        if (ret)
                goto out_smbus;
index 54de0cd482e926c1f31f230ea823b90e3e77d078..bd5d9de5a008eacfc6b493e5813d49d3fd668a57 100644 (file)
@@ -17,7 +17,7 @@
 #include <linux/videodev2.h>
 #include <linux/module.h>
 #include <linux/smp_lock.h>
-#include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 
 #ifdef CONFIG_COMPAT
 
index 5096058bf5793a68b3ea69d748913cd34caaa3e6..8f0cfee4b8a110be08eba133866568816be1ee0b 100644 (file)
@@ -46,6 +46,7 @@
 #include <asm/uaccess.h>
 #include <linux/videodev.h>
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 #include <linux/list.h>
 #include <linux/mutex.h>
 
index 7ce2789fa976213188419ced61d709339fbf134e..8817c3841463d6e1bd0be51d58e26acba5f87836 100644 (file)
@@ -37,6 +37,7 @@
 #include <linux/sched.h>
 #include <linux/slab.h>
 #include <linux/init.h>
+#include <media/v4l2-ioctl.h>
 
 #include "cpia2.h"
 #include "cpia2dev.h"
index 1c3fa3a7470a3f9b7dd3f316aa14fe810d51631a..61d14d26686fdc05dffa7f1baf8185a861115d27 100644 (file)
@@ -111,7 +111,7 @@ static int cs5345_command(struct i2c_client *client, unsigned cmd, void *arg)
                if (cmd == VIDIOC_DBG_G_REGISTER)
                        reg->val = cs5345_read(client, reg->reg & 0x1f);
                else
-                       cs5345_write(client, reg->reg & 0x1f, reg->val & 0x1f);
+                       cs5345_write(client, reg->reg & 0x1f, reg->val & 0xff);
                break;
        }
 #endif
index 45e31b04730e2c2780c9253d938cac4891a95e7b..4801bc7fb5b224336c2cd4ba609df9fde7368bb6 100644 (file)
@@ -46,6 +46,7 @@
 #include <linux/dvb/video.h>
 #include <linux/dvb/audio.h>
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 #include <media/tuner.h>
 #include "cx18-mailbox.h"
 #include "cx18-av-core.h"
index 2d630d9f7496b8c2e6b8989f11f64d44903437ff..78fadd2ada5d72a4a1d45708ebe352e03cb099d0 100644 (file)
 
 #define CX18_DSP0_INTERRUPT_MASK       0xd0004C
 
-/* Encoder/decoder firmware sizes */
-#define CX18_FW_CPU_SIZE               (158332)
-#define CX18_FW_APU_SIZE               (141200)
-
 #define APU_ROM_SYNC1 0x6D676553 /* "mgeS" */
 #define APU_ROM_SYNC2 0x72646548 /* "rdeH" */
 
@@ -100,35 +96,22 @@ struct cx18_apu_rom_seghdr {
        u32 size;
 };
 
-static int load_cpu_fw_direct(const char *fn, u8 __iomem *mem, struct cx18 *cx, long size)
+static int load_cpu_fw_direct(const char *fn, u8 __iomem *mem, struct cx18 *cx)
 {
        const struct firmware *fw = NULL;
-       int retries = 3;
        int i, j;
+       unsigned size;
        u32 __iomem *dst = (u32 __iomem *)mem;
        const u32 *src;
 
-retry:
-       if (!retries || request_firmware(&fw, fn, &cx->dev->dev)) {
-               CX18_ERR("Unable to open firmware %s (must be %ld bytes)\n",
-                               fn, size);
+       if (request_firmware(&fw, fn, &cx->dev->dev)) {
+               CX18_ERR("Unable to open firmware %s\n", fn);
                CX18_ERR("Did you put the firmware in the hotplug firmware directory?\n");
                return -ENOMEM;
        }
 
        src = (const u32 *)fw->data;
 
-       if (fw->size != size) {
-               /* Due to race conditions in firmware loading (esp. with
-                  udev <0.95) the wrong file was sometimes loaded. So we check
-                  filesizes to see if at least the right-sized file was
-                  loaded. If not, then we retry. */
-               CX18_INFO("retry: file loaded was not %s (expected size %ld, got %zd)\n",
-                               fn, size, fw->size);
-               release_firmware(fw);
-               retries--;
-               goto retry;
-       }
        for (i = 0; i < fw->size; i += 4096) {
                setup_page(i);
                for (j = i; j < fw->size && j < i + 4096; j += 4) {
@@ -145,15 +128,16 @@ retry:
        }
        if (!test_bit(CX18_F_I_LOADED_FW, &cx->i_flags))
                CX18_INFO("loaded %s firmware (%zd bytes)\n", fn, fw->size);
+       size = fw->size;
        release_firmware(fw);
        return size;
 }
 
-static int load_apu_fw_direct(const char *fn, u8 __iomem *dst, struct cx18 *cx, long size)
+static int load_apu_fw_direct(const char *fn, u8 __iomem *dst, struct cx18 *cx)
 {
        const struct firmware *fw = NULL;
-       int retries = 3;
        int i, j;
+       unsigned size;
        const u32 *src;
        struct cx18_apu_rom_seghdr seghdr;
        const u8 *vers;
@@ -161,10 +145,8 @@ static int load_apu_fw_direct(const char *fn, u8 __iomem *dst, struct cx18 *cx,
        u32 apu_version = 0;
        int sz;
 
-retry:
-       if (!retries || request_firmware(&fw, fn, &cx->dev->dev)) {
-               CX18_ERR("unable to open firmware %s (must be %ld bytes)\n",
-                               fn, size);
+       if (request_firmware(&fw, fn, &cx->dev->dev)) {
+               CX18_ERR("unable to open firmware %s\n", fn);
                CX18_ERR("did you put the firmware in the hotplug firmware directory?\n");
                return -ENOMEM;
        }
@@ -173,19 +155,8 @@ retry:
        vers = fw->data + sizeof(seghdr);
        sz = fw->size;
 
-       if (fw->size != size) {
-               /* Due to race conditions in firmware loading (esp. with
-                  udev <0.95) the wrong file was sometimes loaded. So we check
-                  filesizes to see if at least the right-sized file was
-                  loaded. If not, then we retry. */
-               CX18_INFO("retry: file loaded was not %s (expected size %ld, got %zd)\n",
-                              fn, size, fw->size);
-               release_firmware(fw);
-               retries--;
-               goto retry;
-       }
        apu_version = (vers[0] << 24) | (vers[4] << 16) | vers[32];
-       while (offset + sizeof(seghdr) < size) {
+       while (offset + sizeof(seghdr) < fw->size) {
                /* TODO: byteswapping */
                memcpy(&seghdr, src + offset / 4, sizeof(seghdr));
                offset += sizeof(seghdr);
@@ -215,6 +186,7 @@ retry:
        if (!test_bit(CX18_F_I_LOADED_FW, &cx->i_flags))
                CX18_INFO("loaded %s firmware V%08x (%zd bytes)\n",
                                fn, apu_version, fw->size);
+       size = fw->size;
        release_firmware(fw);
        /* Clear bit0 for APU to start from 0 */
        write_reg(read_reg(0xc72030) & ~1, 0xc72030);
@@ -340,7 +312,7 @@ int cx18_firmware_init(struct cx18 *cx)
        /* Only if the processor is not running */
        if (read_reg(CX18_PROC_SOFT_RESET) & 8) {
                int sz = load_apu_fw_direct("v4l-cx23418-apu.fw",
-                              cx->enc_mem, cx, CX18_FW_APU_SIZE);
+                              cx->enc_mem, cx);
 
                write_enc(0xE51FF004, 0);
                write_enc(0xa00000, 4);  /* todo: not hardcoded */
@@ -348,7 +320,7 @@ int cx18_firmware_init(struct cx18 *cx)
                cx18_msleep_timeout(500, 0);
 
                sz = sz <= 0 ? sz : load_cpu_fw_direct("v4l-cx23418-cpu.fw",
-                                       cx->enc_mem, cx, CX18_FW_CPU_SIZE);
+                                       cx->enc_mem, cx);
 
                if (sz > 0) {
                        int retries = 0;
index 1728b1d832a9ca2eef5f147553da2e1d97a9e4f3..210a2416b320c1205a6f5ffb0409db79d6c69ca6 100644 (file)
@@ -194,7 +194,7 @@ static int cx18_prep_dev(struct cx18 *cx, int type)
                        cx->num);
 
        s->v4l2dev->minor = minor;
-       s->v4l2dev->dev = &cx->dev->dev;
+       s->v4l2dev->parent = &cx->dev->dev;
        s->v4l2dev->fops = cx18_stream_info[type].fops;
        s->v4l2dev->release = video_device_release;
        s->v4l2dev->tvnorms = V4L2_STD_ALL;
index e7ef093265af0d2275ca149a98355f0423d7949c..4d0dcb06c19db46fb7750126202960814e06e72e 100644 (file)
@@ -32,6 +32,7 @@
 #include <linux/device.h>
 #include <linux/firmware.h>
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 #include <media/cx2341x.h>
 
 #include "cx23885.h"
@@ -1766,7 +1767,7 @@ static struct video_device *cx23885_video_dev_alloc(
        vfd->minor   = -1;
        snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)", dev->name,
                type, cx23885_boards[tsport->dev->board].name);
-       vfd->dev     = &pci->dev;
+       vfd->parent  = &pci->dev;
        vfd->release = video_device_release;
        return vfd;
 }
index 043fc4e5c586c82ec547d595a48e8a6ed0580edf..245712e45f6939554722e8dd253c13003f9830f7 100644 (file)
@@ -33,6 +33,7 @@
 
 #include "cx23885.h"
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 
 #ifdef CONFIG_VIDEO_V4L1_COMPAT
 /* Include V4L1 specific functions. Should be removed soon */
@@ -326,7 +327,7 @@ struct video_device *cx23885_vdev_init(struct cx23885_dev *dev,
                return NULL;
        *vfd = *template;
        vfd->minor   = -1;
-       vfd->dev     = &pci->dev;
+       vfd->parent  = &pci->dev;
        vfd->release = video_device_release;
        snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)",
                 dev->name, type, cx23885_boards[dev->board].name);
index bfdca5847764fde66852c48a5ab85712d8340a63..4d1a461f329f087189c284f6241b79f3ec240523 100644 (file)
@@ -33,6 +33,7 @@
 #include <linux/device.h>
 #include <linux/firmware.h>
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 #include <media/cx2341x.h>
 
 #include "cx88.h"
index 60eeda3057e9e8552bf0bb5361987e6f8d7b04d7..d656fec5901086469fb750eeced37588b7702ccc 100644 (file)
@@ -40,6 +40,7 @@
 
 #include "cx88.h"
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 
 MODULE_DESCRIPTION("v4l2 driver module for cx2388x based TV cards");
 MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
@@ -1006,7 +1007,7 @@ struct video_device *cx88_vdev_init(struct cx88_core *core,
                return NULL;
        *vfd = *template;
        vfd->minor   = -1;
-       vfd->dev     = &pci->dev;
+       vfd->parent  = &pci->dev;
        vfd->release = video_device_release;
        snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)",
                 core->name, type, core->board.name);
index 0fed5cd2cceaa7caa808afba923e70e47c765b8f..d08c11eb8a75eb04cfbfe464a9788cbbb57eedd4 100644 (file)
@@ -39,6 +39,7 @@
 
 #include "cx88.h"
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 
 #ifdef CONFIG_VIDEO_V4L1_COMPAT
 /* Include V4L1 specific functions. Should be removed soon */
index 2d9f14d2a00b817119abeb1d5f29a2886014232d..67c62eaa5b6d6cda7521e7a52e40416e2e8fa78d 100644 (file)
@@ -38,6 +38,7 @@
 
 #include "em28xx.h"
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 #include <media/msp3400.h>
 #include <media/tuner.h>
 
@@ -1892,7 +1893,7 @@ static struct video_device *em28xx_vdev_init(struct em28xx *dev,
                return NULL;
        *vfd = *template;
        vfd->minor   = -1;
-       vfd->dev = &dev->udev->dev;
+       vfd->parent = &dev->udev->dev;
        vfd->release = video_device_release;
        vfd->type = type;
        vfd->debug = video_debug;
index 15d037ae25c5fed1700bdf589b9f8bb6136b5173..8cd5f37425eaccfdc67129abde20458c8b186502 100644 (file)
@@ -34,6 +34,7 @@
 #include <linux/mm.h>
 #include <linux/vmalloc.h>
 #include <linux/page-flags.h>
+#include <media/v4l2-ioctl.h>
 #include <asm/byteorder.h>
 #include <asm/page.h>
 #include <asm/uaccess.h>
@@ -985,7 +986,7 @@ static DEVICE_ATTR(i2c_val, S_IRUGO | S_IWUSR,
 
 static int et61x251_create_sysfs(struct et61x251_device* cam)
 {
-       struct device *classdev = &(cam->v4ldev->class_dev);
+       struct device *classdev = &(cam->v4ldev->dev);
        int err = 0;
 
        if ((err = device_create_file(classdev, &dev_attr_reg)))
index 013d593b0c678979faff6075900bdac237d08508..18c1dec2f769fcf673ffe8e04d4435509fb55b80 100644 (file)
@@ -25,9 +25,6 @@
 #define CONEX_CAM 1            /* special JPEG header */
 #include "jpeg.h"
 
-#define DRIVER_VERSION_NUMBER  KERNEL_VERSION(2, 1, 7)
-static const char version[] = "2.1.7";
-
 MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
 MODULE_DESCRIPTION("GSPCA USB Conexant Camera Driver");
 MODULE_LICENSE("GPL");
@@ -1038,7 +1035,7 @@ static int __init sd_mod_init(void)
 {
        if (usb_register(&sd_driver) < 0)
                return -1;
-       PDEBUG(D_PROBE, "v%s registered", version);
+       PDEBUG(D_PROBE, "registered");
        return 0;
 }
 static void __exit sd_mod_exit(void)
index 8ab4ea7201a90e2ac5c127d5624128521001fc12..6f2f1d24b7eb9b36e07b88ab7852d2c818a62468 100644 (file)
@@ -22,9 +22,6 @@
 
 #include "gspca.h"
 
-#define DRIVER_VERSION_NUMBER  KERNEL_VERSION(2, 1, 7)
-static const char version[] = "2.1.7";
-
 MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
 MODULE_DESCRIPTION("Etoms USB Camera Driver");
 MODULE_LICENSE("GPL");
@@ -942,7 +939,7 @@ static int __init sd_mod_init(void)
 {
        if (usb_register(&sd_driver) < 0)
                return -1;
-       PDEBUG(D_PROBE, "v%s registered", version);
+       PDEBUG(D_PROBE, "registered");
        return 0;
 }
 
index 16e367cec76077981c2d398754d0ff1e3018e98c..0f09784631adb41ddb6a83fbf99bb73f9fc5548b 100644 (file)
@@ -32,6 +32,7 @@
 #include <asm/page.h>
 #include <linux/uaccess.h>
 #include <linux/jiffies.h>
+#include <media/v4l2-ioctl.h>
 
 #include "gspca.h"
 
@@ -42,8 +43,7 @@ MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>");
 MODULE_DESCRIPTION("GSPCA USB Camera Driver");
 MODULE_LICENSE("GPL");
 
-#define DRIVER_VERSION_NUMBER  KERNEL_VERSION(2, 1, 7)
-static const char version[] = "2.1.7";
+#define DRIVER_VERSION_NUMBER  KERNEL_VERSION(2, 2, 0)
 
 static int video_nr = -1;
 
@@ -209,6 +209,8 @@ struct gspca_frame *gspca_frame_add(struct gspca_dev *gspca_dev,
                                   &frame->v4l2_buf.timestamp);
                frame->v4l2_buf.sequence = ++gspca_dev->sequence;
        } else if (gspca_dev->last_packet_type == DISCARD_PACKET) {
+               if (packet_type == LAST_PACKET)
+                       gspca_dev->last_packet_type = packet_type;
                return frame;
        }
 
@@ -399,7 +401,7 @@ static struct usb_host_endpoint *alt_isoc(struct usb_host_interface *alt,
  * This routine may be called many times when the bandwidth is too small
  * (the bandwidth is checked on urb submit).
  */
-struct usb_host_endpoint *get_isoc_ep(struct gspca_dev *gspca_dev)
+static struct usb_host_endpoint *get_isoc_ep(struct gspca_dev *gspca_dev)
 {
        struct usb_interface *intf;
        struct usb_host_endpoint *ep;
@@ -1740,7 +1742,7 @@ int gspca_dev_probe(struct usb_interface *intf,
 
        /* init video stuff */
        memcpy(&gspca_dev->vdev, &gspca_template, sizeof gspca_template);
-       gspca_dev->vdev.dev = &dev->dev;
+       gspca_dev->vdev.parent = &dev->dev;
        memcpy(&gspca_dev->fops, &dev_fops, sizeof gspca_dev->fops);
        gspca_dev->vdev.fops = &gspca_dev->fops;
        gspca_dev->fops.owner = module;         /* module protection */
@@ -1885,7 +1887,10 @@ EXPORT_SYMBOL(gspca_auto_gain_n_exposure);
 /* -- module insert / remove -- */
 static int __init gspca_init(void)
 {
-       info("main v%s registered", version);
+       info("main v%d.%d.%d registered",
+               (DRIVER_VERSION_NUMBER >> 16) & 0xff,
+               (DRIVER_VERSION_NUMBER >> 8) & 0xff,
+               DRIVER_VERSION_NUMBER & 0xff);
        return 0;
 }
 static void __exit gspca_exit(void)
index 88c2b02f380a191064b32de47454842595021d00..a4706162f4154ed5025bf611cf8fe1abaf6a3ea4 100644 (file)
@@ -24,9 +24,6 @@
 #include "gspca.h"
 #include "jpeg.h"
 
-#define DRIVER_VERSION_NUMBER  KERNEL_VERSION(2, 1, 7)
-static const char version[] = "2.1.7";
-
 MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
 MODULE_DESCRIPTION("GSPCA/Mars USB Camera Driver");
 MODULE_LICENSE("GPL");
@@ -451,7 +448,7 @@ static int __init sd_mod_init(void)
 {
        if (usb_register(&sd_driver) < 0)
                return -1;
-       PDEBUG(D_PROBE, "v%s registered", version);
+       PDEBUG(D_PROBE, "registered");
        return 0;
 }
 static void __exit sd_mod_exit(void)
index 08d99c3b78e2ddafcae52d32aa4aa70615c27e5d..f15bec7080c93d98d58fbe4bba23cf1bae6f7522 100644 (file)
@@ -24,9 +24,6 @@
 
 #include "gspca.h"
 
-#define DRIVER_VERSION_NUMBER  KERNEL_VERSION(2, 1, 7)
-static const char version[] = "2.1.7";
-
 MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>");
 MODULE_DESCRIPTION("OV519 USB Camera Driver");
 MODULE_LICENSE("GPL");
@@ -2169,7 +2166,7 @@ static int __init sd_mod_init(void)
 {
        if (usb_register(&sd_driver) < 0)
                return -1;
-       PDEBUG(D_PROBE, "v%s registered", version);
+       PDEBUG(D_PROBE, "registered");
        return 0;
 }
 static void __exit sd_mod_exit(void)
index fa7abc411090c48e7803be522bda37640c36eea2..f790746370d7344c38d6c81e51f760819b6467db 100644 (file)
@@ -27,9 +27,6 @@
 
 #include "gspca.h"
 
-#define DRIVER_VERSION_NUMBER  KERNEL_VERSION(2, 1, 7)
-static const char version[] = "2.1.7";
-
 MODULE_AUTHOR("Hans de Goede <j.w.r.degoede@hhs.nl>");
 MODULE_DESCRIPTION("Pixart PAC207");
 MODULE_LICENSE("GPL");
@@ -208,7 +205,7 @@ static int pac207_write_regs(struct gspca_dev *gspca_dev, u16 index,
 }
 
 
-int pac207_write_reg(struct gspca_dev *gspca_dev, u16 index, u16 value)
+static int pac207_write_reg(struct gspca_dev *gspca_dev, u16 index, u16 value)
 {
        struct usb_device *udev = gspca_dev->dev;
        int err;
@@ -223,8 +220,7 @@ int pac207_write_reg(struct gspca_dev *gspca_dev, u16 index, u16 value)
        return err;
 }
 
-
-int pac207_read_reg(struct gspca_dev *gspca_dev, u16 index)
+static int pac207_read_reg(struct gspca_dev *gspca_dev, u16 index)
 {
        struct usb_device *udev = gspca_dev->dev;
        int res;
@@ -609,7 +605,7 @@ static int __init sd_mod_init(void)
 {
        if (usb_register(&sd_driver) < 0)
                return -1;
-       PDEBUG(D_PROBE, "v%s registered", version);
+       PDEBUG(D_PROBE, "registered");
        return 0;
 }
 static void __exit sd_mod_exit(void)
index 5c052e31be4adad49b2eb93e496e0d8c2e89e5a7..2267ae7cb87f53d122a2fedb97b6a407b35be15e 100644 (file)
@@ -23,9 +23,6 @@
 
 #include "gspca.h"
 
-#define DRIVER_VERSION_NUMBER  KERNEL_VERSION(2, 1, 7)
-static const char version[] = "2.1.7";
-
 MODULE_AUTHOR("Thomas Kaiser thomas@kaiser-linux.li");
 MODULE_DESCRIPTION("Pixart PAC7311");
 MODULE_LICENSE("GPL");
@@ -747,7 +744,7 @@ static int __init sd_mod_init(void)
 {
        if (usb_register(&sd_driver) < 0)
                return -1;
-       PDEBUG(D_PROBE, "v%s registered", version);
+       PDEBUG(D_PROBE, "registered");
        return 0;
 }
 static void __exit sd_mod_exit(void)
index dbeebe8625c59189021660462d4326c73f820715..f6bef896d3a526e1a84080eeff3700c00d9453b2 100644 (file)
@@ -24,9 +24,6 @@
 
 #include "gspca.h"
 
-#define DRIVER_VERSION_NUMBER  KERNEL_VERSION(2, 1, 8)
-static const char version[] = "2.1.8";
-
 MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
 MODULE_DESCRIPTION("GSPCA/SN9C102 USB Camera Driver");
 MODULE_LICENSE("GPL");
@@ -1464,7 +1461,7 @@ static int __init sd_mod_init(void)
 {
        if (usb_register(&sd_driver) < 0)
                return -1;
-       PDEBUG(D_PROBE, "v%s registered", version);
+       PDEBUG(D_PROBE, "registered");
        return 0;
 }
 static void __exit sd_mod_exit(void)
index 3e68b992695676b5bdaf3147367a6ecca26da9be..35b1a3ee4c3f806634e4484f3562144b7495a0ed 100644 (file)
@@ -24,9 +24,6 @@
 #include "gspca.h"
 #include "jpeg.h"
 
-#define DRIVER_VERSION_NUMBER  KERNEL_VERSION(2, 1, 7)
-static const char version[] = "2.1.7";
-
 MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
 MODULE_DESCRIPTION("GSPCA/SONIX JPEG USB Camera Driver");
 MODULE_LICENSE("GPL");
@@ -361,6 +358,7 @@ static const __u8 mo4000_sensor_init[][8] = {
 };
 static const __u8 ov7660_sensor_init[][8] = {
        {0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, /* reset SCCB */
+/*             (delay 20ms) */
        {0xa1, 0x21, 0x12, 0x05, 0x00, 0x00, 0x00, 0x10},
                                                /* Outformat ?? rawRGB */
        {0xa1, 0x21, 0x13, 0xb8, 0x00, 0x00, 0x00, 0x10}, /* init COM8 */
@@ -539,13 +537,31 @@ static void reg_r(struct gspca_dev *gspca_dev,
                        value, 0,
                        gspca_dev->usb_buf, len,
                        500);
+       PDEBUG(D_USBI, "reg_r [%02x] -> %02x", value, gspca_dev->usb_buf[0]);
 }
 
+static void reg_w1(struct gspca_dev *gspca_dev,
+                  __u16 value,
+                  __u8 data)
+{
+       PDEBUG(D_USBO, "reg_w1 [%02x] = %02x", value, data);
+       gspca_dev->usb_buf[0] = data;
+       usb_control_msg(gspca_dev->dev,
+                       usb_sndctrlpipe(gspca_dev->dev, 0),
+                       0x08,
+                       USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
+                       value,
+                       0,
+                       gspca_dev->usb_buf, 1,
+                       500);
+}
 static void reg_w(struct gspca_dev *gspca_dev,
                          __u16 value,
                          const __u8 *buffer,
                          int len)
 {
+       PDEBUG(D_USBO, "reg_w [%02x] = %02x %02x ..",
+               value, buffer[0], buffer[1]);
        if (len <= sizeof gspca_dev->usb_buf) {
                memcpy(gspca_dev->usb_buf, buffer, len);
                usb_control_msg(gspca_dev->dev,
@@ -571,31 +587,42 @@ static void reg_w(struct gspca_dev *gspca_dev,
        }
 }
 
-/* I2C write 2 bytes */
-static void i2c_w2(struct gspca_dev *gspca_dev,
-                  const __u8 *buffer)
+/* I2C write 1 byte */
+static void i2c_w1(struct gspca_dev *gspca_dev, __u8 reg, __u8 val)
 {
        struct sd *sd = (struct sd *) gspca_dev;
-       __u8 mode[8];
 
-       /* is i2c ready */
-       mode[0] = 0x81 | (2 << 4);
-       mode[1] = sd->i2c_base;
-       mode[2] = buffer[0];
-       mode[3] = buffer[1];
-       mode[4] = 0;
-       mode[5] = 0;
-       mode[6] = 0;
-       mode[7] = 0x10;
-       reg_w(gspca_dev, 0x08, mode, 8);
+       PDEBUG(D_USBO, "i2c_w2 [%02x] = %02x", reg, val);
+       gspca_dev->usb_buf[0] = 0x81 | (2 << 4);        /* = a1 */
+       gspca_dev->usb_buf[1] = sd->i2c_base;
+       gspca_dev->usb_buf[2] = reg;
+       gspca_dev->usb_buf[3] = val;
+       gspca_dev->usb_buf[4] = 0;
+       gspca_dev->usb_buf[5] = 0;
+       gspca_dev->usb_buf[6] = 0;
+       gspca_dev->usb_buf[7] = 0x10;
+       usb_control_msg(gspca_dev->dev,
+                       usb_sndctrlpipe(gspca_dev->dev, 0),
+                       0x08,
+                       USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
+                       0x08,                   /* value = i2c */
+                       0,
+                       gspca_dev->usb_buf, 8,
+                       500);
 }
 
 /* I2C write 8 bytes */
 static void i2c_w8(struct gspca_dev *gspca_dev,
                   const __u8 *buffer)
 {
-       reg_w(gspca_dev, 0x08, buffer, 8);
-       msleep(1);
+       memcpy(gspca_dev->usb_buf, buffer, 8);
+       usb_control_msg(gspca_dev->dev,
+                       usb_sndctrlpipe(gspca_dev->dev, 0),
+                       0x08,
+                       USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
+                       0x08, 0,                /* value, index */
+                       gspca_dev->usb_buf, 8,
+                       500);
 }
 
 /* read 5 bytes in gspca_dev->usb_buf */
@@ -613,24 +640,21 @@ static void i2c_r5(struct gspca_dev *gspca_dev, __u8 reg)
        mode[6] = 0;
        mode[7] = 0x10;
        i2c_w8(gspca_dev, mode);
+       msleep(2);
        mode[0] = 0x81 | (5 << 4) | 0x02;
        mode[2] = 0;
        i2c_w8(gspca_dev, mode);
+       msleep(2);
        reg_r(gspca_dev, 0x0a, 5);
 }
 
 static int probesensor(struct gspca_dev *gspca_dev)
 {
        struct sd *sd = (struct sd *) gspca_dev;
-       __u8 reg02;
-       static const __u8 datasend[] = { 2, 0 };
-       /* reg val1 val2 val3 val4 */
 
-       i2c_w2(gspca_dev, datasend);
-/* should write 0xa1 0x11 0x02 0x00 0x00 0x00 0x00 the 0x10 is add by i2cw */
+       i2c_w1(gspca_dev, 0x02, 0);                     /* sensor wakeup */
        msleep(10);
-       reg02 = 0x66;
-       reg_w(gspca_dev, 0x02, &reg02, 1);              /* Gpio on */
+       reg_w1(gspca_dev, 0x02, 0x66);                  /* Gpio on */
        msleep(10);
        i2c_r5(gspca_dev, 0);                           /* read sensor id */
        if (gspca_dev->usb_buf[0] == 0x02
@@ -642,7 +666,7 @@ static int probesensor(struct gspca_dev *gspca_dev)
                sd->sensor = SENSOR_HV7131R;
                return SENSOR_HV7131R;
        }
-       PDEBUG(D_PROBE, "Find Sensor %d %d %d",
+       PDEBUG(D_PROBE, "Find Sensor 0x%02x 0x%02x 0x%02x",
                gspca_dev->usb_buf[0], gspca_dev->usb_buf[1],
                gspca_dev->usb_buf[2]);
        PDEBUG(D_PROBE, "Sensor sn9c102P Not found");
@@ -653,8 +677,6 @@ static int configure_gpio(struct gspca_dev *gspca_dev,
                          const __u8 *sn9c1xx)
 {
        struct sd *sd = (struct sd *) gspca_dev;
-       __u8 data;
-       __u8 regF1;
        const __u8 *reg9a;
        static const __u8 reg9a_def[] =
                {0x08, 0x40, 0x20, 0x10, 0x00, 0x04};
@@ -663,15 +685,13 @@ static int configure_gpio(struct gspca_dev *gspca_dev,
        static const __u8 reg9a_sn9c325[] =
                {0x0a, 0x40, 0x38, 0x30, 0x00, 0x20};
 
-
-       regF1 = 0x00;
-       reg_w(gspca_dev, 0xf1, &regF1, 1);
-       reg_w(gspca_dev, 0x01, &sn9c1xx[0], 1); /*fixme:jfm was [1] en v1*/
+       reg_w1(gspca_dev, 0xf1, 0x00);
+       reg_w1(gspca_dev, 0x01, sn9c1xx[0]);    /*fixme:jfm was [1] en v1*/
 
        /* configure gpio */
        reg_w(gspca_dev, 0x01, &sn9c1xx[1], 2);
        reg_w(gspca_dev, 0x08, &sn9c1xx[8], 2);
-       reg_w(gspca_dev, 0x17, &sn9c1xx[0x17], 5);      /* jfm was 3 */
+       reg_w(gspca_dev, 0x17, &sn9c1xx[0x17], 5);      /* jfm len was 3 */
        switch (sd->bridge) {
        case BRIDGE_SN9C325:
                reg9a = reg9a_sn9c325;
@@ -685,35 +705,25 @@ static int configure_gpio(struct gspca_dev *gspca_dev,
        }
        reg_w(gspca_dev, 0x9a, reg9a, 6);
 
-       data = 0x60;                            /*fixme:jfm 60 00 00 (3) */
-       reg_w(gspca_dev, 0xd4, &data, 1);
+       reg_w1(gspca_dev, 0xd4, 0x60);  /*fixme:jfm 60 00 00 (3) ? */
 
        reg_w(gspca_dev, 0x03, &sn9c1xx[3], 0x0f);
 
        switch (sd->bridge) {
        case BRIDGE_SN9C120:                    /* from win trace */
-               data = 0x61;
-               reg_w(gspca_dev, 0x01, &data, 1);
-               data = 0x20;
-               reg_w(gspca_dev, 0x17, &data, 1);
-               data = 0x60;
-               reg_w(gspca_dev, 0x01, &data, 1);
+               reg_w1(gspca_dev, 0x01, 0x61);
+               reg_w1(gspca_dev, 0x17, 0x20);
+               reg_w1(gspca_dev, 0x01, 0x60);
                break;
        case BRIDGE_SN9C325:
-               data = 0x43;
-               reg_w(gspca_dev, 0x01, &data, 1);
-               data = 0xae;
-               reg_w(gspca_dev, 0x17, &data, 1);
-               data = 0x42;
-               reg_w(gspca_dev, 0x01, &data, 1);
+               reg_w1(gspca_dev, 0x01, 0x43);
+               reg_w1(gspca_dev, 0x17, 0xae);
+               reg_w1(gspca_dev, 0x01, 0x42);
                break;
        default:
-               data = 0x43;
-               reg_w(gspca_dev, 0x01, &data, 1);
-               data = 0x61;
-               reg_w(gspca_dev, 0x17, &data, 1);
-               data = 0x42;
-               reg_w(gspca_dev, 0x01, &data, 1);
+               reg_w1(gspca_dev, 0x01, 0x43);
+               reg_w1(gspca_dev, 0x17, 0x61);
+               reg_w1(gspca_dev, 0x01, 0x42);
        }
 
        if (sd->sensor == SENSOR_HV7131R) {
@@ -770,6 +780,9 @@ static void ov7660_InitSensor(struct gspca_dev *gspca_dev)
 {
        int i = 0;
 
+       i2c_w8(gspca_dev, ov7660_sensor_init[i]);       /* reset SCCB */
+       i++;
+       msleep(20);
        while (ov7660_sensor_init[i][0]) {
                i2c_w8(gspca_dev, ov7660_sensor_init[i]);
                i++;
@@ -782,13 +795,11 @@ static int sd_config(struct gspca_dev *gspca_dev,
 {
        struct sd *sd = (struct sd *) gspca_dev;
        struct cam *cam;
-       __u16 vendor;
        __u16 product;
 
-       vendor = id->idVendor;
        product = id->idProduct;
        sd->sensor = -1;
-       switch (vendor) {
+       switch (id->idVendor) {
        case 0x0458:                            /* Genius */
 /*             switch (product) {
                case 0x7025: */
@@ -960,7 +971,7 @@ static int sd_config(struct gspca_dev *gspca_dev,
        }
        if (sd->sensor < 0) {
                PDEBUG(D_ERR, "Invalid vendor/product %04x:%04x",
-                       vendor, product);
+                       id->idVendor, product);
                return -EINVAL;
        }
 
@@ -983,34 +994,26 @@ static int sd_open(struct gspca_dev *gspca_dev)
 {
        struct sd *sd = (struct sd *) gspca_dev;
 /*     const __u8 *sn9c1xx; */
-       __u8 regF1;
        __u8 regGpio[] = { 0x29, 0x74 };
+       __u8 regF1;
 
        /* setup a selector by bridge */
-       regF1 = 0x01;
-       reg_w(gspca_dev, 0xf1, &regF1, 1);
+       reg_w1(gspca_dev, 0xf1, 0x01);
        reg_r(gspca_dev, 0x00, 1);              /* -> regF1 = 0x00 */
-       regF1 = gspca_dev->usb_buf[0];
-       reg_w(gspca_dev, 0xf1, &regF1, 1);
+       reg_w1(gspca_dev, 0xf1, gspca_dev->usb_buf[0]);
        reg_r(gspca_dev, 0x00, 1);
        regF1 = gspca_dev->usb_buf[0];
        switch (sd->bridge) {
        case BRIDGE_SN9C102P:
                if (regF1 != 0x11)
                        return -ENODEV;
-               reg_w(gspca_dev, 0x02, &regGpio[1], 1);
+               reg_w1(gspca_dev, 0x02, regGpio[1]);
                break;
        case BRIDGE_SN9C105:
                if (regF1 != 0x11)
                        return -ENODEV;
                reg_w(gspca_dev, 0x02, regGpio, 2);
                break;
-       case BRIDGE_SN9C110:
-               if (regF1 != 0x12)
-                       return -ENODEV;
-               regGpio[1] = 0x62;
-               reg_w(gspca_dev, 0x02, &regGpio[1], 1);
-               break;
        case BRIDGE_SN9C120:
                if (regF1 != 0x12)
                        return -ENODEV;
@@ -1018,16 +1021,15 @@ static int sd_open(struct gspca_dev *gspca_dev)
                reg_w(gspca_dev, 0x02, regGpio, 2);
                break;
        default:
+/*     case BRIDGE_SN9C110: */
 /*     case BRIDGE_SN9C325: */
                if (regF1 != 0x12)
                        return -ENODEV;
-               regGpio[1] = 0x62;
-               reg_w(gspca_dev, 0x02, &regGpio[1], 1);
+               reg_w1(gspca_dev, 0x02, 0x62);
                break;
        }
 
-       regF1 = 0x01;
-       reg_w(gspca_dev, 0xf1, &regF1, 1);
+       reg_w1(gspca_dev, 0xf1, 0x01);
 
        return 0;
 }
@@ -1123,7 +1125,7 @@ static void setbrightness(struct gspca_dev *gspca_dev)
        }
 
        k2 = sd->brightness >> 10;
-       reg_w(gspca_dev, 0x96, &k2, 1);
+       reg_w1(gspca_dev, 0x96, k2);
 }
 
 static void setcontrast(struct gspca_dev *gspca_dev)
@@ -1152,7 +1154,7 @@ static void setcolors(struct gspca_dev *gspca_dev)
                data = (colour + 32) & 0x7f;    /* blue */
        else
                data = (-colour + 32) & 0x7f;   /* red */
-       reg_w(gspca_dev, 0x05, &data, 1);
+       reg_w1(gspca_dev, 0x05, data);
 }
 
 /* -- start the camera -- */
@@ -1165,7 +1167,6 @@ static void sd_start(struct gspca_dev *gspca_dev)
        __u8 reg17;
        const __u8 *sn9c1xx;
        int mode;
-       static const __u8 DC29[] = { 0x6a, 0x50, 0x00, 0x00, 0x50, 0x3c };
        static const __u8 C0[] = { 0x2d, 0x2d, 0x3a, 0x05, 0x04, 0x3f };
        static const __u8 CA[] = { 0x28, 0xd8, 0x14, 0xec };
        static const __u8 CA_sn9c120[] =
@@ -1179,21 +1180,20 @@ static void sd_start(struct gspca_dev *gspca_dev)
 
 /*fixme:jfm this sequence should appear at end of sd_start */
 /* with
-       data = 0x44;
-       reg_w(gspca_dev, 0x01, &data, 1); */
-       reg_w(gspca_dev, 0x15, &sn9c1xx[0x15], 1);
-       reg_w(gspca_dev, 0x16, &sn9c1xx[0x16], 1);
-       reg_w(gspca_dev, 0x12, &sn9c1xx[0x12], 1);
-       reg_w(gspca_dev, 0x13, &sn9c1xx[0x13], 1);
-       reg_w(gspca_dev, 0x18, &sn9c1xx[0x18], 1);
-       reg_w(gspca_dev, 0xd2, &DC29[0], 1);
-       reg_w(gspca_dev, 0xd3, &DC29[1], 1);
-       reg_w(gspca_dev, 0xc6, &DC29[2], 1);
-       reg_w(gspca_dev, 0xc7, &DC29[3], 1);
-       reg_w(gspca_dev, 0xc8, &DC29[4], 1);
-       reg_w(gspca_dev, 0xc9, &DC29[5], 1);
+       reg_w1(gspca_dev, 0x01, 0x44); */
+       reg_w1(gspca_dev, 0x15, sn9c1xx[0x15]);
+       reg_w1(gspca_dev, 0x16, sn9c1xx[0x16]);
+       reg_w1(gspca_dev, 0x12, sn9c1xx[0x12]);
+       reg_w1(gspca_dev, 0x13, sn9c1xx[0x13]);
+       reg_w1(gspca_dev, 0x18, sn9c1xx[0x18]);
+       reg_w1(gspca_dev, 0xd2, 0x6a);          /* DC29 */
+       reg_w1(gspca_dev, 0xd3, 0x50);
+       reg_w1(gspca_dev, 0xc6, 0x00);
+       reg_w1(gspca_dev, 0xc7, 0x00);
+       reg_w1(gspca_dev, 0xc8, 0x50);
+       reg_w1(gspca_dev, 0xc9, 0x3c);
 /*fixme:jfm end of ending sequence */
-       reg_w(gspca_dev, 0x18, &sn9c1xx[0x18], 1);
+       reg_w1(gspca_dev, 0x18, sn9c1xx[0x18]);
        switch (sd->bridge) {
        case BRIDGE_SN9C325:
                data = 0xae;
@@ -1205,11 +1205,11 @@ static void sd_start(struct gspca_dev *gspca_dev)
                data = 0x60;
                break;
        }
-       reg_w(gspca_dev, 0x17, &data, 1);
-       reg_w(gspca_dev, 0x05, &sn9c1xx[5], 1);
-       reg_w(gspca_dev, 0x07, &sn9c1xx[7], 1);
-       reg_w(gspca_dev, 0x06, &sn9c1xx[6], 1);
-       reg_w(gspca_dev, 0x14, &sn9c1xx[0x14], 1);
+       reg_w1(gspca_dev, 0x17, data);
+       reg_w1(gspca_dev, 0x05, sn9c1xx[5]);
+       reg_w1(gspca_dev, 0x07, sn9c1xx[7]);
+       reg_w1(gspca_dev, 0x06, sn9c1xx[6]);
+       reg_w1(gspca_dev, 0x14, sn9c1xx[0x14]);
        switch (sd->bridge) {
        case BRIDGE_SN9C325:
                reg_w(gspca_dev, 0x20, regsn20_sn9c325,
@@ -1217,10 +1217,8 @@ static void sd_start(struct gspca_dev *gspca_dev)
                for (i = 0; i < 8; i++)
                        reg_w(gspca_dev, 0x84, reg84_sn9c325,
                                        sizeof reg84_sn9c325);
-               data = 0x0a;
-               reg_w(gspca_dev, 0x9a, &data, 1);
-               data = 0x60;
-               reg_w(gspca_dev, 0x99, &data, 1);
+               reg_w1(gspca_dev, 0x9a, 0x0a);
+               reg_w1(gspca_dev, 0x99, 0x60);
                break;
        case BRIDGE_SN9C120:
                reg_w(gspca_dev, 0x20, regsn20_sn9c120,
@@ -1233,39 +1231,30 @@ static void sd_start(struct gspca_dev *gspca_dev)
                                        sizeof reg84_sn9c120_2);
                reg_w(gspca_dev, 0x84, reg84_sn9c120_3,
                                sizeof reg84_sn9c120_3);
-               data = 0x05;
-               reg_w(gspca_dev, 0x9a, &data, 1);
-               data = 0x5b;
-               reg_w(gspca_dev, 0x99, &data, 1);
+               reg_w1(gspca_dev, 0x9a, 0x05);
+               reg_w1(gspca_dev, 0x99, 0x5b);
                break;
        default:
                reg_w(gspca_dev, 0x20, regsn20, sizeof regsn20);
                for (i = 0; i < 8; i++)
                        reg_w(gspca_dev, 0x84, reg84, sizeof reg84);
-               data = 0x08;
-               reg_w(gspca_dev, 0x9a, &data, 1);
-               data = 0x59;
-               reg_w(gspca_dev, 0x99, &data, 1);
+               reg_w1(gspca_dev, 0x9a, 0x08);
+               reg_w1(gspca_dev, 0x99, 0x59);
                break;
        }
 
        mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
-       reg1 = 0x02;
+       if (mode)
+               reg1 = 0x46;    /* 320 clk 48Mhz */
+       else
+               reg1 = 0x06;    /* 640 clk 24Mz */
        reg17 = 0x61;
        switch (sd->sensor) {
        case SENSOR_HV7131R:
                hv7131R_InitSensor(gspca_dev);
-               if (mode)
-                       reg1 = 0x46;    /* 320 clk 48Mhz */
-               else
-                       reg1 = 0x06;    /* 640 clk 24Mz */
                break;
        case SENSOR_MI0360:
                mi0360_InitSensor(gspca_dev);
-               if (mode)
-                       reg1 = 0x46;    /* 320 clk 48Mhz */
-               else
-                       reg1 = 0x06;    /* 640 clk 24Mz */
                break;
        case SENSOR_MO4000:
                mo4000_InitSensor(gspca_dev);
@@ -1274,13 +1263,13 @@ static void sd_start(struct gspca_dev *gspca_dev)
                        reg1 = 0x06;    /* clk 24Mz */
                } else {
                        reg17 = 0x22;   /* 640 MCKSIZE */
-                       reg1 = 0x06;    /* 640 clk 24Mz */
+/*                     reg1 = 0x06;     * 640 clk 24Mz (done) */
                }
                break;
        case SENSOR_OV7648:
+               ov7648_InitSensor(gspca_dev);
                reg17 = 0xa2;
                reg1 = 0x44;
-               ov7648_InitSensor(gspca_dev);
 /*             if (mode)
                        ;                * 320x2...
                else
@@ -1292,7 +1281,7 @@ static void sd_start(struct gspca_dev *gspca_dev)
                if (mode) {
 /*                     reg17 = 0x21;    * 320 */
 /*                     reg1 = 0x44; */
-                       reg1 = 0x46;
+/*                     reg1 = 0x46;    (done) */
                } else {
                        reg17 = 0xa2;   /* 640 */
                        reg1 = 0x40;
@@ -1321,16 +1310,16 @@ static void sd_start(struct gspca_dev *gspca_dev)
 
        /* here change size mode 0 -> VGA; 1 -> CIF */
        data = 0x40 | sn9c1xx[0x18] | (mode << 4);
-       reg_w(gspca_dev, 0x18, &data, 1);
+       reg_w1(gspca_dev, 0x18, data);
 
        reg_w(gspca_dev, 0x100, qtable4, 0x40);
        reg_w(gspca_dev, 0x140, qtable4 + 0x40, 0x40);
 
        data = sn9c1xx[0x18] | (mode << 4);
-       reg_w(gspca_dev, 0x18, &data, 1);
+       reg_w1(gspca_dev, 0x18, data);
 
-       reg_w(gspca_dev, 0x17, &reg17, 1);
-       reg_w(gspca_dev, 0x01, &reg1, 1);
+       reg_w1(gspca_dev, 0x17, reg17);
+       reg_w1(gspca_dev, 0x01, reg1);
        setbrightness(gspca_dev);
        setcontrast(gspca_dev);
 }
@@ -1342,7 +1331,6 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
                { 0xa1, 0x11, 0x02, 0x09, 0x00, 0x00, 0x00, 0x10 };
        static const __u8 stopmi0360[] =
                { 0xb1, 0x5d, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10 };
-       __u8 regF1;
        __u8 data;
        const __u8 *sn9c1xx;
 
@@ -1366,12 +1354,11 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
                break;
        }
        sn9c1xx = sn_tb[(int) sd->sensor];
-       reg_w(gspca_dev, 0x01, &sn9c1xx[1], 1);
-       reg_w(gspca_dev, 0x17, &sn9c1xx[0x17], 1);
-       reg_w(gspca_dev, 0x01, &sn9c1xx[1], 1);
-       reg_w(gspca_dev, 0x01, &data, 1);
-       regF1 = 0x01;
-       reg_w(gspca_dev, 0xf1, &regF1, 1);
+       reg_w1(gspca_dev, 0x01, sn9c1xx[1]);
+       reg_w1(gspca_dev, 0x17, sn9c1xx[0x17]);
+       reg_w1(gspca_dev, 0x01, sn9c1xx[1]);
+       reg_w1(gspca_dev, 0x01, data);
+       reg_w1(gspca_dev, 0xf1, 0x01);
 }
 
 static void sd_stop0(struct gspca_dev *gspca_dev)
@@ -1658,7 +1645,7 @@ static int __init sd_mod_init(void)
 {
        if (usb_register(&sd_driver) < 0)
                return -1;
-       info("v%s registered", version);
+       info("registered");
        return 0;
 }
 static void __exit sd_mod_exit(void)
index 15620611879555a7797cd8c4675530ac0e77c4cb..8c83823745f05e7f0496c0260e311cbe44866fd0 100644 (file)
@@ -24,9 +24,6 @@
 #include "gspca.h"
 #include "jpeg.h"
 
-#define DRIVER_VERSION_NUMBER  KERNEL_VERSION(2, 1, 7)
-static const char version[] = "2.1.7";
-
 MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
 MODULE_DESCRIPTION("GSPCA/SPCA500 USB Camera Driver");
 MODULE_LICENSE("GPL");
@@ -1203,7 +1200,7 @@ static int __init sd_mod_init(void)
 {
        if (usb_register(&sd_driver) < 0)
                return -1;
-       PDEBUG(D_PROBE, "v%s registered", version);
+       PDEBUG(D_PROBE, "registered");
        return 0;
 }
 static void __exit sd_mod_exit(void)
index 50e929de02036c78d259d96587e937835bca30f3..6537acee89dd09534315edfdd2aecc63006b6d6e 100644 (file)
@@ -23,9 +23,6 @@
 
 #include "gspca.h"
 
-#define DRIVER_VERSION_NUMBER  KERNEL_VERSION(2, 1, 7)
-static const char version[] = "2.1.7";
-
 MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
 MODULE_DESCRIPTION("GSPCA/SPCA501 USB Camera Driver");
 MODULE_LICENSE("GPL");
@@ -2216,7 +2213,7 @@ static int __init sd_mod_init(void)
 {
        if (usb_register(&sd_driver) < 0)
                return -1;
-       PDEBUG(D_PROBE, "v%s registered", version);
+       PDEBUG(D_PROBE, "registered");
        return 0;
 }
 static void __exit sd_mod_exit(void)
index ddea6e140aa833bbc1d7b7167da0354828834406..1bb23d03f048332f906a6f1be8a3f331a0f79fe6 100644 (file)
@@ -23,9 +23,6 @@
 
 #include "gspca.h"
 
-#define DRIVER_VERSION_NUMBER  KERNEL_VERSION(2, 1, 7)
-static const char version[] = "2.1.7";
-
 MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
 MODULE_DESCRIPTION("GSPCA/SPCA505 USB Camera Driver");
 MODULE_LICENSE("GPL");
@@ -938,7 +935,7 @@ static int __init sd_mod_init(void)
 {
        if (usb_register(&sd_driver) < 0)
                return -1;
-       PDEBUG(D_PROBE, "v%s registered", version);
+       PDEBUG(D_PROBE, "registered");
        return 0;
 }
 static void __exit sd_mod_exit(void)
index 143203c1fd9fbf92772f26714321e31ce8097561..40e8541b2b898ca04746b1a6f294f0f0b5e35eea 100644 (file)
@@ -25,9 +25,6 @@
 
 #include "gspca.h"
 
-#define DRIVER_VERSION_NUMBER  KERNEL_VERSION(2, 1, 7)
-static const char version[] = "2.1.7";
-
 MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
 MODULE_DESCRIPTION("GSPCA/SPCA506 USB Camera Driver");
 MODULE_LICENSE("GPL");
@@ -834,7 +831,7 @@ static int __init sd_mod_init(void)
 {
        if (usb_register(&sd_driver) < 0)
                return -1;
-       PDEBUG(D_PROBE, "v%s registered", version);
+       PDEBUG(D_PROBE, "registered");
        return 0;
 }
 static void __exit sd_mod_exit(void)
index d8cd93866a4a6c6b9aec8f73c844ceca0420eceb..362f645d08c6c16ee11a57d34ba95d6a538a06cb 100644 (file)
@@ -22,9 +22,6 @@
 
 #include "gspca.h"
 
-#define DRIVER_VERSION_NUMBER  KERNEL_VERSION(2, 1, 7)
-static const char version[] = "2.1.7";
-
 MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
 MODULE_DESCRIPTION("GSPCA/SPCA508 USB Camera Driver");
 MODULE_LICENSE("GPL");
@@ -1778,7 +1775,7 @@ static int __init sd_mod_init(void)
 {
        if (usb_register(&sd_driver) < 0)
                return -1;
-       PDEBUG(D_PROBE, "v%s registered", version);
+       PDEBUG(D_PROBE, "registered");
        return 0;
 }
 static void __exit sd_mod_exit(void)
index b659bd0f788da4d86afbbf2b21787ab443756637..85c37f396aaf3a0e6466ecf0c988ab6f29727734 100644 (file)
@@ -24,9 +24,6 @@
 
 #include "gspca.h"
 
-#define DRIVER_VERSION_NUMBER  KERNEL_VERSION(2, 1, 7)
-static const char version[] = "2.1.7";
-
 MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
 MODULE_DESCRIPTION("GSPCA/SPCA561 USB Camera Driver");
 MODULE_LICENSE("GPL");
@@ -1039,7 +1036,7 @@ static int __init sd_mod_init(void)
 {
        if (usb_register(&sd_driver) < 0)
                return -1;
-       PDEBUG(D_PROBE, "v%s registered", version);
+       PDEBUG(D_PROBE, "registered");
        return 0;
 }
 static void __exit sd_mod_exit(void)
index c78ee0d3e59bface920e16ac31539af824d839b1..90efde17b08b1a78e786a83c8856eb6720640ee2 100644 (file)
@@ -23,9 +23,6 @@
 #include "gspca.h"
 #include "jpeg.h"
 
-#define DRIVER_VERSION_NUMBER  KERNEL_VERSION(2, 1, 7)
-static const char version[] = "2.1.7";
-
 MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>");
 MODULE_DESCRIPTION("Syntek DV4000 (STK014) USB Camera Driver");
 MODULE_LICENSE("GPL");
@@ -576,7 +573,7 @@ static int __init sd_mod_init(void)
 {
        if (usb_register(&sd_driver) < 0)
                return -1;
-       info("v%s registered", version);
+       info("registered");
        return 0;
 }
 static void __exit sd_mod_exit(void)
index abd7bef9b3d1b270484f6bc9d555e46fbc426b23..53e20275f26db728c77ccb964ba88e7f66c72cff 100644 (file)
@@ -24,9 +24,6 @@
 #include "gspca.h"
 #include "jpeg.h"
 
-#define DRIVER_VERSION_NUMBER  KERNEL_VERSION(2, 1, 8)
-static const char version[] = "2.1.8";
-
 MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
 MODULE_DESCRIPTION("GSPCA/SPCA5xx USB Camera Driver");
 MODULE_LICENSE("GPL");
@@ -1664,7 +1661,7 @@ static int __init sd_mod_init(void)
 {
        if (usb_register(&sd_driver) < 0)
                return -1;
-       PDEBUG(D_PROBE, "v%s registered", version);
+       PDEBUG(D_PROBE, "registered");
        return 0;
 }
 static void __exit sd_mod_exit(void)
index 00f47e463a05b8ccef3449ec3640fe45fe03e680..fc1c62e5a2fdde720f66317f53560e0f395143b0 100644 (file)
@@ -1,12 +1,4 @@
 /*
- *Notes: * t613  + tas5130A
- *     * Focus to light do not balance well as in win.
- *       Quality in win is not good, but its kinda better.
- *      * Fix some "extraneous bytes", most of apps will show the image anyway
- *      * Gamma table, is there, but its really doing something?
- *      * 7~8 Fps, its ok, max on win its 10.
- *                     Costantino Leandro
- *
  * V4L2 by Jean-Francois Moine <http://moinejf.free.fr>
  *
  * This program is free software; you can redistribute it and/or modify
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ *Notes: * t613  + tas5130A
+ *     * Focus to light do not balance well as in win.
+ *       Quality in win is not good, but its kinda better.
+ *      * Fix some "extraneous bytes", most of apps will show the image anyway
+ *      * Gamma table, is there, but its really doing something?
+ *      * 7~8 Fps, its ok, max on win its 10.
+ *                     Costantino Leandro
  */
 
 #define MODULE_NAME "t613"
+
 #include "gspca.h"
-#define DRIVER_VERSION_NUMBER  KERNEL_VERSION(2, 1, 7)
-static const char version[] = "2.1.7";
 
 #define MAX_GAMMA 0x10         /* 0 to 15 */
 
-/* From LUVCVIEW */
 #define V4L2_CID_EFFECTS (V4L2_CID_PRIVATE_BASE + 3)
 
 MODULE_AUTHOR("Leandro Costantino <le_costantino@pixartargentina.com.ar>");
@@ -1025,7 +1023,7 @@ static int __init sd_mod_init(void)
 {
        if (usb_register(&sd_driver) < 0)
                return -1;
-       PDEBUG(D_PROBE, "v%s registered", version);
+       PDEBUG(D_PROBE, "registered");
        return 0;
 }
 static void __exit sd_mod_exit(void)
index 0b793899095f29d09a6e4e99b415495c8ea2b617..cb2d9da2a224d3c7d3ced19c01ad7981a8a86e2c 100644 (file)
@@ -22,9 +22,6 @@
 
 #include "gspca.h"
 
-#define DRIVER_VERSION_NUMBER  KERNEL_VERSION(2, 1, 7)
-static const char version[] = "2.1.7";
-
 MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
 MODULE_DESCRIPTION("TV8532 USB Camera Driver");
 MODULE_LICENSE("GPL");
@@ -656,7 +653,7 @@ static int __init sd_mod_init(void)
 {
        if (usb_register(&sd_driver) < 0)
                return -1;
-       PDEBUG(D_PROBE, "v%s registered", version);
+       PDEBUG(D_PROBE, "registered");
        return 0;
 }
 
index fcf2c9e32573a5d8a2a23a94c5a49fed086c8fa4..e306ac420298a015c96f593bb228090184cbfa82 100644 (file)
@@ -24,9 +24,6 @@
 
 #include "gspca.h"
 
-#define DRIVER_VERSION_NUMBER  KERNEL_VERSION(2, 1, 7)
-static const char version[] = "2.1.7";
-
 MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
 MODULE_DESCRIPTION("GSPCA/VC032X USB Camera Driver");
 MODULE_LICENSE("GPL");
@@ -1805,7 +1802,7 @@ static int __init sd_mod_init(void)
 {
        if (usb_register(&sd_driver) < 0)
                return -1;
-       PDEBUG(D_PROBE, "v%s registered", version);
+       PDEBUG(D_PROBE, "registered");
        return 0;
 }
 static void __exit sd_mod_exit(void)
index b761b11c5c6a45d8f9eba88b2620b127c322b456..f8d6f1780a45a14a9dbcd8e7b2c30d4e8e6bae51 100644 (file)
@@ -24,9 +24,6 @@
 
 #include "gspca.h"
 
-#define DRIVER_VERSION_NUMBER  KERNEL_VERSION(2, 1, 7)
-static const char version[] = "2.1.7";
-
 MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>, "
                "Serge A. Suchkov <Serge.A.S@tochka.ru>");
 MODULE_DESCRIPTION("GSPCA ZC03xx/VC3xx USB Camera Driver");
@@ -49,7 +46,7 @@ struct sd {
        __u8 sharpness;
 
        char qindex;
-       char sensor;                    /* Type of image sensor chip */
+       signed char sensor;             /* Type of image sensor chip */
 /* !! values used in different tables */
 #define SENSOR_CS2102 0
 #define SENSOR_CS2102K 1
@@ -2205,10 +2202,10 @@ static const struct usb_action hdcs2020xb_InitialScale[] = {
 };
 static const struct usb_action hdcs2020b_50HZ[] = {
        {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* 00,19,00,cc */
-       {0xaa, 0x13, 0x0018}, /* 00,13,18,aa */
-       {0xaa, 0x14, 0x0001}, /* 00,14,01,aa */
-       {0xaa, 0x0e, 0x0005}, /* 00,0e,05,aa */
-       {0xaa, 0x19, 0x001f}, /* 00,19,1f,aa */
+       {0xaa, 0x13, 0x0018},                   /* 00,13,18,aa */
+       {0xaa, 0x14, 0x0001},                   /* 00,14,01,aa */
+       {0xaa, 0x0e, 0x0005},                   /* 00,0e,05,aa */
+       {0xaa, 0x19, 0x001f},                   /* 00,19,1f,aa */
        {0xa0, 0x00, ZC3XX_R190_EXPOSURELIMITHIGH}, /* 01,90,00,cc */
        {0xa0, 0x02, ZC3XX_R191_EXPOSURELIMITMID}, /* 01,91,02,cc */
        {0xa0, 0x76, ZC3XX_R192_EXPOSURELIMITLOW}, /* 01,92,76,cc */
@@ -2226,10 +2223,10 @@ static const struct usb_action hdcs2020b_50HZ[] = {
 };
 static const struct usb_action hdcs2020b_60HZ[] = {
        {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* 00,19,00,cc */
-       {0xaa, 0x13, 0x0031}, /* 00,13,31,aa */
-       {0xaa, 0x14, 0x0001}, /* 00,14,01,aa */
-       {0xaa, 0x0e, 0x0004}, /* 00,0e,04,aa */
-       {0xaa, 0x19, 0x00cd}, /* 00,19,cd,aa */
+       {0xaa, 0x13, 0x0031},                   /* 00,13,31,aa */
+       {0xaa, 0x14, 0x0001},                   /* 00,14,01,aa */
+       {0xaa, 0x0e, 0x0004},                   /* 00,0e,04,aa */
+       {0xaa, 0x19, 0x00cd},                   /* 00,19,cd,aa */
        {0xa0, 0x00, ZC3XX_R190_EXPOSURELIMITHIGH}, /* 01,90,00,cc */
        {0xa0, 0x02, ZC3XX_R191_EXPOSURELIMITMID}, /* 01,91,02,cc */
        {0xa0, 0x62, ZC3XX_R192_EXPOSURELIMITLOW}, /* 01,92,62,cc */
@@ -2247,10 +2244,10 @@ static const struct usb_action hdcs2020b_60HZ[] = {
 };
 static const struct usb_action hdcs2020b_NoFliker[] = {
        {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* 00,19,00,cc */
-       {0xaa, 0x13, 0x0010}, /* 00,13,10,aa */
-       {0xaa, 0x14, 0x0001}, /* 00,14,01,aa */
-       {0xaa, 0x0e, 0x0004}, /* 00,0e,04,aa */
-       {0xaa, 0x19, 0x0000}, /* 00,19,00,aa */
+       {0xaa, 0x13, 0x0010},                   /* 00,13,10,aa */
+       {0xaa, 0x14, 0x0001},                   /* 00,14,01,aa */
+       {0xaa, 0x0e, 0x0004},                   /* 00,0e,04,aa */
+       {0xaa, 0x19, 0x0000},                   /* 00,19,00,aa */
        {0xa0, 0x00, ZC3XX_R190_EXPOSURELIMITHIGH}, /* 01,90,00,cc */
        {0xa0, 0x02, ZC3XX_R191_EXPOSURELIMITMID}, /* 01,91,02,cc */
        {0xa0, 0x70, ZC3XX_R192_EXPOSURELIMITLOW}, /* 01,92,70,cc */
@@ -4102,27 +4099,27 @@ static const struct usb_action pas106b_Initial_com[] = {
 
 static const struct usb_action pas106b_Initial[] = {   /* 176x144 */
 /* JPEG control */
-       {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING},          /* ClockSetting */
+       {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING},
 /* Sream and Sensor specific */
-       {0xa0, 0x0f, ZC3XX_R010_CMOSSENSORSELECT},      /* CMOSSensorSelect */
+       {0xa0, 0x0f, ZC3XX_R010_CMOSSENSORSELECT},
 /* Picture size */
-       {0xa0, 0x00, ZC3XX_R003_FRAMEWIDTHHIGH},  /* FrameWidthHigh 00 */
-       {0xa0, 0xb0, ZC3XX_R004_FRAMEWIDTHLOW},   /* FrameWidthLow B0 */
-       {0xa0, 0x00, ZC3XX_R005_FRAMEHEIGHTHIGH}, /* FrameHeightHigh 00 */
-       {0xa0, 0x90, ZC3XX_R006_FRAMEHEIGHTLOW},  /* FrameHightLow 90 */
+       {0xa0, 0x00, ZC3XX_R003_FRAMEWIDTHHIGH},
+       {0xa0, 0xb0, ZC3XX_R004_FRAMEWIDTHLOW},
+       {0xa0, 0x00, ZC3XX_R005_FRAMEHEIGHTHIGH},
+       {0xa0, 0x90, ZC3XX_R006_FRAMEHEIGHTLOW},
 /* System */
-       {0xa0, 0x01, ZC3XX_R001_SYSTEMOPERATING}, /* SystemOperating */
+       {0xa0, 0x01, ZC3XX_R001_SYSTEMOPERATING},
 /* Sream and Sensor specific */
-       {0xa0, 0x03, ZC3XX_R012_VIDEOCONTROLFUNC}, /* VideoControlFunction */
-       {0xa0, 0x01, ZC3XX_R012_VIDEOCONTROLFUNC}, /* VideoControlFunction */
+       {0xa0, 0x03, ZC3XX_R012_VIDEOCONTROLFUNC},
+       {0xa0, 0x01, ZC3XX_R012_VIDEOCONTROLFUNC},
 /* Sensor Interface */
-       {0xa0, 0x08, ZC3XX_R08D_COMPABILITYMODE},  /* Compatibily Mode */
+       {0xa0, 0x08, ZC3XX_R08D_COMPABILITYMODE},
 /* Window inside sensor array */
-       {0xa0, 0x03, ZC3XX_R09A_WINXSTARTLOW},  /* WinXStartLow */
-       {0xa0, 0x00, ZC3XX_R11A_FIRSTYLOW},     /* FirstYLow */
-       {0xa0, 0x03, ZC3XX_R11C_FIRSTXLOW},     /* FirstxLow */
-       {0xa0, 0x28, ZC3XX_R09C_WINHEIGHTLOW},  /* WinHeightLow */
-       {0xa0, 0x68, ZC3XX_R09E_WINWIDTHLOW},   /* WinWidthLow */
+       {0xa0, 0x03, ZC3XX_R09A_WINXSTARTLOW},
+       {0xa0, 0x00, ZC3XX_R11A_FIRSTYLOW},
+       {0xa0, 0x03, ZC3XX_R11C_FIRSTXLOW},
+       {0xa0, 0x28, ZC3XX_R09C_WINHEIGHTLOW},
+       {0xa0, 0x68, ZC3XX_R09E_WINWIDTHLOW},
 /* Init the sensor */
        {0xaa, 0x02, 0x0004},
        {0xaa, 0x08, 0x0000},
@@ -4135,40 +4132,40 @@ static const struct usb_action pas106b_Initial[] = {    /* 176x144 */
        {0xaa, 0x14, 0x0081},
 
 /* Other registors */
-       {0xa0, 0x37, ZC3XX_R101_SENSORCORRECTION}, /* SensorCorrection */
+       {0xa0, 0x37, ZC3XX_R101_SENSORCORRECTION},
 /* Frame retreiving */
-       {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* AutoAdjustFPS */
+       {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS},
 /* Gains */
-       {0xa0, 0xa0, ZC3XX_R1A8_DIGITALGAIN},   /* DigitalGain */
+       {0xa0, 0xa0, ZC3XX_R1A8_DIGITALGAIN},
 /* Unknown */
        {0xa0, 0x00, 0x01ad},
 /* Sharpness */
-       {0xa0, 0x03, ZC3XX_R1C5_SHARPNESSMODE}, /* SharpnessMode */
-       {0xa0, 0x13, ZC3XX_R1CB_SHARPNESS05},   /* Sharpness05 */
+       {0xa0, 0x03, ZC3XX_R1C5_SHARPNESSMODE},
+       {0xa0, 0x13, ZC3XX_R1CB_SHARPNESS05},
 /* Other registors */
-       {0xa0, 0x0d, ZC3XX_R100_OPERATIONMODE}, /* OperationMode */
+       {0xa0, 0x0d, ZC3XX_R100_OPERATIONMODE},
 /* Auto exposure and white balance */
-       {0xa0, 0x06, ZC3XX_R189_AWBSTATUS},     /* AWBStatus */
+       {0xa0, 0x06, ZC3XX_R189_AWBSTATUS},
 /*Dead pixels */
-       {0xa0, 0x08, ZC3XX_R250_DEADPIXELSMODE}, /* DeadPixelsMode */
+       {0xa0, 0x08, ZC3XX_R250_DEADPIXELSMODE},
 /* EEPROM */
-       {0xa0, 0x08, ZC3XX_R301_EEPROMACCESS},  /* EEPROMAccess */
+       {0xa0, 0x08, ZC3XX_R301_EEPROMACCESS},
 /* JPEG control */
-       {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING},  /* ClockSetting */
-       {0xa0, 0x08, ZC3XX_R1C6_SHARPNESS00},   /* sharpness+ */
-       {0xa0, 0x0f, ZC3XX_R1CB_SHARPNESS05},   /* sharpness- */
+       {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING},
+       {0xa0, 0x08, ZC3XX_R1C6_SHARPNESS00},
+       {0xa0, 0x0f, ZC3XX_R1CB_SHARPNESS05},
 /* Other registers */
-       {0xa0, 0x0d, ZC3XX_R100_OPERATIONMODE}, /* OperationMode */
+       {0xa0, 0x0d, ZC3XX_R100_OPERATIONMODE},
 /* Auto exposure and white balance */
-       {0xa0, 0x06, ZC3XX_R189_AWBSTATUS},     /* AWBStatus */
+       {0xa0, 0x06, ZC3XX_R189_AWBSTATUS},
 /*Dead pixels */
-       {0xa0, 0x08, ZC3XX_R250_DEADPIXELSMODE}, /* DeadPixelsMode */
+       {0xa0, 0x08, ZC3XX_R250_DEADPIXELSMODE},
 /* EEPROM */
-       {0xa0, 0x08, ZC3XX_R301_EEPROMACCESS},  /* EEPROMAccess */
+       {0xa0, 0x08, ZC3XX_R301_EEPROMACCESS},
 /* JPEG control */
-       {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING},  /* ClockSetting */
-       {0xa0, 0x08, ZC3XX_R1C6_SHARPNESS00},   /* sharpness+ */
-       {0xa0, 0x0f, ZC3XX_R1CB_SHARPNESS05},   /* sharpness- */
+       {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING},
+       {0xa0, 0x08, ZC3XX_R1C6_SHARPNESS00},
+       {0xa0, 0x0f, ZC3XX_R1CB_SHARPNESS05},
 
        {0xa0, 0x58, ZC3XX_R10A_RGB00}, /* matrix */
        {0xa0, 0xf4, ZC3XX_R10B_RGB01},
@@ -4180,67 +4177,67 @@ static const struct usb_action pas106b_Initial[] = {    /* 176x144 */
        {0xa0, 0xf4, ZC3XX_R111_RGB21},
        {0xa0, 0x58, ZC3XX_R112_RGB22},
 /* Auto correction */
-       {0xa0, 0x03, ZC3XX_R181_WINXSTART},     /* WinXstart */
-       {0xa0, 0x08, ZC3XX_R182_WINXWIDTH},     /* WinXWidth */
-       {0xa0, 0x16, ZC3XX_R183_WINXCENTER},    /* WinXCenter */
-       {0xa0, 0x03, ZC3XX_R184_WINYSTART},     /* WinYStart */
-       {0xa0, 0x05, ZC3XX_R185_WINYWIDTH},     /* WinYWidth */
-       {0xa0, 0x14, ZC3XX_R186_WINYCENTER},    /* WinYCenter */
-       {0xa0, 0x00, ZC3XX_R180_AUTOCORRECTENABLE}, /* AutoCorrectEnable */
+       {0xa0, 0x03, ZC3XX_R181_WINXSTART},
+       {0xa0, 0x08, ZC3XX_R182_WINXWIDTH},
+       {0xa0, 0x16, ZC3XX_R183_WINXCENTER},
+       {0xa0, 0x03, ZC3XX_R184_WINYSTART},
+       {0xa0, 0x05, ZC3XX_R185_WINYWIDTH},
+       {0xa0, 0x14, ZC3XX_R186_WINYCENTER},
+       {0xa0, 0x00, ZC3XX_R180_AUTOCORRECTENABLE},
 
 /* Auto exposure and white balance */
-       {0xa0, 0x00, ZC3XX_R190_EXPOSURELIMITHIGH},     /* ExposureLimitHigh */
-       {0xa0, 0x03, ZC3XX_R191_EXPOSURELIMITMID},      /* ExposureLimitMid */
-       {0xa0, 0xb1, ZC3XX_R192_EXPOSURELIMITLOW},      /* ExposureLimitLow */
-       {0xa0, 0x00, ZC3XX_R195_ANTIFLICKERHIGH},       /* AntiFlickerHigh */
-       {0xa0, 0x00, ZC3XX_R196_ANTIFLICKERMID},        /* AntiFlickerLow */
-       {0xa0, 0x87, ZC3XX_R197_ANTIFLICKERLOW},        /* AntiFlickerLow */
-       {0xa0, 0x0c, ZC3XX_R18C_AEFREEZE},              /* AEBFreeze */
-       {0xa0, 0x18, ZC3XX_R18F_AEUNFREEZE},            /* AEBUnfreeze */
+       {0xa0, 0x00, ZC3XX_R190_EXPOSURELIMITHIGH},
+       {0xa0, 0x03, ZC3XX_R191_EXPOSURELIMITMID},
+       {0xa0, 0xb1, ZC3XX_R192_EXPOSURELIMITLOW},
+       {0xa0, 0x00, ZC3XX_R195_ANTIFLICKERHIGH},
+       {0xa0, 0x00, ZC3XX_R196_ANTIFLICKERMID},
+       {0xa0, 0x87, ZC3XX_R197_ANTIFLICKERLOW},
+       {0xa0, 0x0c, ZC3XX_R18C_AEFREEZE},
+       {0xa0, 0x18, ZC3XX_R18F_AEUNFREEZE},
 /* sensor on */
        {0xaa, 0x07, 0x00b1},
        {0xaa, 0x05, 0x0003},
        {0xaa, 0x04, 0x0001},
        {0xaa, 0x03, 0x003b},
 /* Gains */
-       {0xa0, 0x20, ZC3XX_R1A9_DIGITALLIMITDIFF},      /* DigitalLimitDiff */
-       {0xa0, 0x26, ZC3XX_R1AA_DIGITALGAINSTEP},       /* DigitalGainStep */
-       {0xa0, 0xa0, ZC3XX_R11D_GLOBALGAIN},            /* GlobalGain */
-       {0xa0, 0x60, ZC3XX_R11D_GLOBALGAIN},            /* GlobalGain */
+       {0xa0, 0x20, ZC3XX_R1A9_DIGITALLIMITDIFF},
+       {0xa0, 0x26, ZC3XX_R1AA_DIGITALGAINSTEP},
+       {0xa0, 0xa0, ZC3XX_R11D_GLOBALGAIN},
+       {0xa0, 0x60, ZC3XX_R11D_GLOBALGAIN},
 /* Auto correction */
-       {0xa0, 0x40, ZC3XX_R180_AUTOCORRECTENABLE},     /* AutoCorrectEnable */
+       {0xa0, 0x40, ZC3XX_R180_AUTOCORRECTENABLE},
        {0xa1, 0x01, 0x0180},                           /* AutoCorrectEnable */
-       {0xa0, 0x42, ZC3XX_R180_AUTOCORRECTENABLE},     /* AutoCorrectEnable */
+       {0xa0, 0x42, ZC3XX_R180_AUTOCORRECTENABLE},
 /* Gains */
-       {0xa0, 0x40, ZC3XX_R116_RGAIN},                 /* RGain */
-       {0xa0, 0x40, ZC3XX_R117_GGAIN},                 /* GGain */
-       {0xa0, 0x40, ZC3XX_R118_BGAIN},                 /* BGain */
+       {0xa0, 0x40, ZC3XX_R116_RGAIN},
+       {0xa0, 0x40, ZC3XX_R117_GGAIN},
+       {0xa0, 0x40, ZC3XX_R118_BGAIN},
        {}
 };
 
 static const struct usb_action pas106b_InitialScale[] = {      /* 352x288 */
 /* JPEG control */
-       {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING},          /* ClockSetting */
+       {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING},
 /* Sream and Sensor specific */
-       {0xa0, 0x0f, ZC3XX_R010_CMOSSENSORSELECT},      /* CMOSSensorSelect */
+       {0xa0, 0x0f, ZC3XX_R010_CMOSSENSORSELECT},
 /* Picture size */
-       {0xa0, 0x01, ZC3XX_R003_FRAMEWIDTHHIGH},        /* FrameWidthHigh */
-       {0xa0, 0x60, ZC3XX_R004_FRAMEWIDTHLOW},         /* FrameWidthLow */
-       {0xa0, 0x01, ZC3XX_R005_FRAMEHEIGHTHIGH},       /* FrameHeightHigh */
-       {0xa0, 0x20, ZC3XX_R006_FRAMEHEIGHTLOW},        /* FrameHightLow */
+       {0xa0, 0x01, ZC3XX_R003_FRAMEWIDTHHIGH},
+       {0xa0, 0x60, ZC3XX_R004_FRAMEWIDTHLOW},
+       {0xa0, 0x01, ZC3XX_R005_FRAMEHEIGHTHIGH},
+       {0xa0, 0x20, ZC3XX_R006_FRAMEHEIGHTLOW},
 /* System */
-       {0xa0, 0x01, ZC3XX_R001_SYSTEMOPERATING},       /* SystemOperating */
+       {0xa0, 0x01, ZC3XX_R001_SYSTEMOPERATING},
 /* Sream and Sensor specific */
-       {0xa0, 0x03, ZC3XX_R012_VIDEOCONTROLFUNC}, /* VideoControlFunction */
-       {0xa0, 0x01, ZC3XX_R012_VIDEOCONTROLFUNC}, /* VideoControlFunction */
+       {0xa0, 0x03, ZC3XX_R012_VIDEOCONTROLFUNC},
+       {0xa0, 0x01, ZC3XX_R012_VIDEOCONTROLFUNC},
 /* Sensor Interface */
-       {0xa0, 0x08, ZC3XX_R08D_COMPABILITYMODE},       /* Compatibily Mode */
+       {0xa0, 0x08, ZC3XX_R08D_COMPABILITYMODE},
 /* Window inside sensor array */
-       {0xa0, 0x03, ZC3XX_R09A_WINXSTARTLOW},  /* WinXStartLow */
-       {0xa0, 0x00, ZC3XX_R11A_FIRSTYLOW},     /* FirstYLow */
-       {0xa0, 0x03, ZC3XX_R11C_FIRSTXLOW},     /* FirstxLow */
-       {0xa0, 0x28, ZC3XX_R09C_WINHEIGHTLOW},  /* WinHeightLow */
-       {0xa0, 0x68, ZC3XX_R09E_WINWIDTHLOW},   /* WinWidthLow */
+       {0xa0, 0x03, ZC3XX_R09A_WINXSTARTLOW},
+       {0xa0, 0x00, ZC3XX_R11A_FIRSTYLOW},
+       {0xa0, 0x03, ZC3XX_R11C_FIRSTXLOW},
+       {0xa0, 0x28, ZC3XX_R09C_WINHEIGHTLOW},
+       {0xa0, 0x68, ZC3XX_R09E_WINWIDTHLOW},
 /* Init the sensor */
        {0xaa, 0x02, 0x0004},
        {0xaa, 0x08, 0x0000},
@@ -4253,41 +4250,41 @@ static const struct usb_action pas106b_InitialScale[] = {       /* 352x288 */
        {0xaa, 0x14, 0x0081},
 
 /* Other registors */
-       {0xa0, 0x37, ZC3XX_R101_SENSORCORRECTION}, /* SensorCorrection */
+       {0xa0, 0x37, ZC3XX_R101_SENSORCORRECTION},
 /* Frame retreiving */
-       {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* AutoAdjustFPS */
+       {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS},
 /* Gains */
-       {0xa0, 0xa0, ZC3XX_R1A8_DIGITALGAIN},   /* DigitalGain */
+       {0xa0, 0xa0, ZC3XX_R1A8_DIGITALGAIN},
 /* Unknown */
        {0xa0, 0x00, 0x01ad},
 /* Sharpness */
-       {0xa0, 0x03, ZC3XX_R1C5_SHARPNESSMODE}, /* SharpnessMode */
-       {0xa0, 0x13, ZC3XX_R1CB_SHARPNESS05},   /* Sharpness05 */
+       {0xa0, 0x03, ZC3XX_R1C5_SHARPNESSMODE},
+       {0xa0, 0x13, ZC3XX_R1CB_SHARPNESS05},
 /* Other registors */
-       {0xa0, 0x0d, ZC3XX_R100_OPERATIONMODE}, /* OperationMode */
+       {0xa0, 0x0d, ZC3XX_R100_OPERATIONMODE},
 /* Auto exposure and white balance */
-       {0xa0, 0x06, ZC3XX_R189_AWBSTATUS},     /* AWBStatus */
-       {0xa0, 0x80, ZC3XX_R18D_YTARGET},       /* ????????? */
+       {0xa0, 0x06, ZC3XX_R189_AWBSTATUS},
+       {0xa0, 0x80, ZC3XX_R18D_YTARGET},
 /*Dead pixels */
-       {0xa0, 0x08, ZC3XX_R250_DEADPIXELSMODE}, /* DeadPixelsMode */
+       {0xa0, 0x08, ZC3XX_R250_DEADPIXELSMODE},
 /* EEPROM */
-       {0xa0, 0x08, ZC3XX_R301_EEPROMACCESS},  /* EEPROMAccess */
+       {0xa0, 0x08, ZC3XX_R301_EEPROMACCESS},
 /* JPEG control */
-       {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING},  /* ClockSetting */
-       {0xa0, 0x08, ZC3XX_R1C6_SHARPNESS00},   /* sharpness+ */
-       {0xa0, 0x0f, ZC3XX_R1CB_SHARPNESS05},   /* sharpness- */
+       {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING},
+       {0xa0, 0x08, ZC3XX_R1C6_SHARPNESS00},
+       {0xa0, 0x0f, ZC3XX_R1CB_SHARPNESS05},
 /* Other registers */
-       {0xa0, 0x0d, ZC3XX_R100_OPERATIONMODE}, /* OperationMode */
+       {0xa0, 0x0d, ZC3XX_R100_OPERATIONMODE},
 /* Auto exposure and white balance */
-       {0xa0, 0x06, ZC3XX_R189_AWBSTATUS},     /* AWBStatus */
+       {0xa0, 0x06, ZC3XX_R189_AWBSTATUS},
 /*Dead pixels */
-       {0xa0, 0x08, ZC3XX_R250_DEADPIXELSMODE}, /* DeadPixelsMode */
+       {0xa0, 0x08, ZC3XX_R250_DEADPIXELSMODE},
 /* EEPROM */
-       {0xa0, 0x08, ZC3XX_R301_EEPROMACCESS},  /* EEPROMAccess */
+       {0xa0, 0x08, ZC3XX_R301_EEPROMACCESS},
 /* JPEG control */
-       {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING},  /* ClockSetting */
-       {0xa0, 0x08, ZC3XX_R1C6_SHARPNESS00},   /* sharpness+ */
-       {0xa0, 0x0f, ZC3XX_R1CB_SHARPNESS05},   /* sharpness- */
+       {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING},
+       {0xa0, 0x08, ZC3XX_R1C6_SHARPNESS00},
+       {0xa0, 0x0f, ZC3XX_R1CB_SHARPNESS05},
 
        {0xa0, 0x58, ZC3XX_R10A_RGB00}, /* matrix */
        {0xa0, 0xf4, ZC3XX_R10B_RGB01},
@@ -4299,43 +4296,43 @@ static const struct usb_action pas106b_InitialScale[] = {       /* 352x288 */
        {0xa0, 0xf4, ZC3XX_R111_RGB21},
        {0xa0, 0x58, ZC3XX_R112_RGB22},
 /* Auto correction */
-       {0xa0, 0x03, ZC3XX_R181_WINXSTART},     /* WinXstart */
-       {0xa0, 0x08, ZC3XX_R182_WINXWIDTH},     /* WinXWidth */
-       {0xa0, 0x16, ZC3XX_R183_WINXCENTER},    /* WinXCenter */
-       {0xa0, 0x03, ZC3XX_R184_WINYSTART},     /* WinYStart */
-       {0xa0, 0x05, ZC3XX_R185_WINYWIDTH},     /* WinYWidth */
-       {0xa0, 0x14, ZC3XX_R186_WINYCENTER},    /* WinYCenter */
-       {0xa0, 0x00, ZC3XX_R180_AUTOCORRECTENABLE}, /* AutoCorrectEnable */
+       {0xa0, 0x03, ZC3XX_R181_WINXSTART},
+       {0xa0, 0x08, ZC3XX_R182_WINXWIDTH},
+       {0xa0, 0x16, ZC3XX_R183_WINXCENTER},
+       {0xa0, 0x03, ZC3XX_R184_WINYSTART},
+       {0xa0, 0x05, ZC3XX_R185_WINYWIDTH},
+       {0xa0, 0x14, ZC3XX_R186_WINYCENTER},
+       {0xa0, 0x00, ZC3XX_R180_AUTOCORRECTENABLE},
 
 /* Auto exposure and white balance */
-       {0xa0, 0x00, ZC3XX_R190_EXPOSURELIMITHIGH}, /* ExposureLimitHigh 0 */
-       {0xa0, 0x03, ZC3XX_R191_EXPOSURELIMITMID},  /* ExposureLimitMid */
-       {0xa0, 0xb1, ZC3XX_R192_EXPOSURELIMITLOW},  /* ExposureLimitLow 0xb1 */
+       {0xa0, 0x00, ZC3XX_R190_EXPOSURELIMITHIGH},
+       {0xa0, 0x03, ZC3XX_R191_EXPOSURELIMITMID},
+       {0xa0, 0xb1, ZC3XX_R192_EXPOSURELIMITLOW},
 
-       {0xa0, 0x00, ZC3XX_R195_ANTIFLICKERHIGH},   /* AntiFlickerHigh 0x00 */
-       {0xa0, 0x00, ZC3XX_R196_ANTIFLICKERMID},    /* AntiFlickerLow 0x00 */
-       {0xa0, 0x87, ZC3XX_R197_ANTIFLICKERLOW},    /* AntiFlickerLow 0x87 */
+       {0xa0, 0x00, ZC3XX_R195_ANTIFLICKERHIGH},
+       {0xa0, 0x00, ZC3XX_R196_ANTIFLICKERMID},
+       {0xa0, 0x87, ZC3XX_R197_ANTIFLICKERLOW},
 
-       {0xa0, 0x10, ZC3XX_R18C_AEFREEZE},      /* AEBFreeze 0x10 0x0c */
-       {0xa0, 0x20, ZC3XX_R18F_AEUNFREEZE},    /* AEBUnfreeze 0x30 0x18 */
+       {0xa0, 0x10, ZC3XX_R18C_AEFREEZE},
+       {0xa0, 0x20, ZC3XX_R18F_AEUNFREEZE},
 /* sensor on */
        {0xaa, 0x07, 0x00b1},
        {0xaa, 0x05, 0x0003},
        {0xaa, 0x04, 0x0001},
        {0xaa, 0x03, 0x003b},
 /* Gains */
-       {0xa0, 0x20, ZC3XX_R1A9_DIGITALLIMITDIFF},      /* DigitalLimitDiff */
-       {0xa0, 0x26, ZC3XX_R1AA_DIGITALGAINSTEP},       /* DigitalGainStep */
-       {0xa0, 0xa0, ZC3XX_R11D_GLOBALGAIN},    /* GlobalGain */
-       {0xa0, 0x60, ZC3XX_R11D_GLOBALGAIN},    /* GlobalGain */
+       {0xa0, 0x20, ZC3XX_R1A9_DIGITALLIMITDIFF},
+       {0xa0, 0x26, ZC3XX_R1AA_DIGITALGAINSTEP},
+       {0xa0, 0xa0, ZC3XX_R11D_GLOBALGAIN},
+       {0xa0, 0x60, ZC3XX_R11D_GLOBALGAIN},
 /* Auto correction */
-       {0xa0, 0x40, ZC3XX_R180_AUTOCORRECTENABLE},     /* AutoCorrectEnable */
+       {0xa0, 0x40, ZC3XX_R180_AUTOCORRECTENABLE},
        {0xa1, 0x01, 0x0180},                           /* AutoCorrectEnable */
-       {0xa0, 0x42, ZC3XX_R180_AUTOCORRECTENABLE},     /* AutoCorrectEnable */
+       {0xa0, 0x42, ZC3XX_R180_AUTOCORRECTENABLE},
 /* Gains */
-       {0xa0, 0x40, ZC3XX_R116_RGAIN},         /* RGain */
-       {0xa0, 0x40, ZC3XX_R117_GGAIN},         /* GGain */
-       {0xa0, 0x40, ZC3XX_R118_BGAIN},         /* BGain */
+       {0xa0, 0x40, ZC3XX_R116_RGAIN},
+       {0xa0, 0x40, ZC3XX_R117_GGAIN},
+       {0xa0, 0x40, ZC3XX_R118_BGAIN},
 
        {0xa0, 0x00, 0x0007},                   /* AutoCorrectEnable */
        {0xa0, 0xff, ZC3XX_R018_FRAMELOST},     /* Frame adjust */
@@ -4459,8 +4456,8 @@ static const struct usb_action pb03303x_Initial[] = {
        {0xa0, 0x50, ZC3XX_R112_RGB22},
 
        {0xa1, 0x01, 0x0008},
-       {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING},  /* clock ? */
-       {0xa0, 0x08, ZC3XX_R1C6_SHARPNESS00},   /* sharpness+ */
+       {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING},
+       {0xa0, 0x08, ZC3XX_R1C6_SHARPNESS00},
        {0xa1, 0x01, 0x01c8},
        {0xa1, 0x01, 0x01c9},
        {0xa1, 0x01, 0x01ca},
@@ -5984,7 +5981,7 @@ static const struct usb_action tas5130c_vf0250_Initial[] = {
        {0xaa, 0x1b, 0x0000},           /* 00,1b,00,aa, */
        {0xaa, 0x13, 0x0002},           /* 00,13,02,aa, */
        {0xaa, 0x15, 0x0004},           /* 00,15,04,aa */
-       {0xaa, 0x01, 0x0000},
+/*??   {0xaa, 0x01, 0x0000}, */
        {0xaa, 0x01, 0x0000},
        {0xaa, 0x1a, 0x0000},           /* 00,1a,00,aa, */
        {0xaa, 0x1c, 0x0017},           /* 00,1c,17,aa, */
@@ -6000,8 +5997,8 @@ static const struct usb_action tas5130c_vf0250_Initial[] = {
        {0xaa, 0x0f, 0x00a0},           /* 00,0f,a0,aa, */
        {0xaa, 0x10, 0x0000},           /* 00,10,00,aa, */
        {0xaa, 0x11, 0x00a0},           /* 00,11,a0,aa, */
-       {0xa0, 0x00, 0x0039},
-       {0xa1, 0x01, 0x0037},
+/*??   {0xa0, 0x00, 0x0039},
+       {0xa1, 0x01, 0x0037}, */
        {0xaa, 0x16, 0x0001},           /* 00,16,01,aa, */
        {0xaa, 0x17, 0x00e8},           /* 00,17,e6,aa, (e6 -> e8) */
        {0xaa, 0x18, 0x0002},           /* 00,18,02,aa, */
@@ -6272,7 +6269,7 @@ static void reg_w(struct usb_device *dev,
                        __u8 value,
                        __u16 index)
 {
-       PDEBUG(D_USBO, "reg w %02x -> [%04x]", value, index);
+       PDEBUG(D_USBO, "reg w [%04x] = %02x", index, value);
        reg_w_i(dev, value, index);
 }
 
@@ -6280,17 +6277,17 @@ static __u16 i2c_read(struct gspca_dev *gspca_dev,
                        __u8 reg)
 {
        __u8 retbyte;
-       __u8 retval[2];
+       __u16 retval;
 
        reg_w_i(gspca_dev->dev, reg, 0x92);
        reg_w_i(gspca_dev->dev, 0x02, 0x90);            /* <- read command */
        msleep(25);
        retbyte = reg_r_i(gspca_dev, 0x0091);           /* read status */
-       retval[0] = reg_r_i(gspca_dev, 0x0095);         /* read Lowbyte */
-       retval[1] = reg_r_i(gspca_dev, 0x0096);         /* read Hightbyte */
-       PDEBUG(D_USBO, "i2c r [%02x] -> (%02x) %02x%02x",
-                       reg, retbyte, retval[1], retval[0]);
-       return (retval[1] << 8) | retval[0];
+       retval = reg_r_i(gspca_dev, 0x0095);            /* read Lowbyte */
+       retval |= reg_r_i(gspca_dev, 0x0096) << 8;      /* read Hightbyte */
+       PDEBUG(D_USBO, "i2c r [%02x] -> %04x (%02x)",
+                       reg, retval, retbyte);
+       return retval;
 }
 
 static __u8 i2c_write(struct gspca_dev *gspca_dev,
@@ -6306,7 +6303,7 @@ static __u8 i2c_write(struct gspca_dev *gspca_dev,
        reg_w_i(gspca_dev->dev, 0x01, 0x90);            /* <- write command */
        msleep(5);
        retbyte = reg_r_i(gspca_dev, 0x0091);           /* read status */
-       PDEBUG(D_USBO, "i2c w [%02x] %02x%02x (%02x)",
+       PDEBUG(D_USBO, "i2c w [%02x] %02x%02x (%02x)",
                        reg, valH, valL, retbyte);
        return retbyte;
 }
@@ -6349,6 +6346,8 @@ static void setmatrix(struct gspca_dev *gspca_dev)
                {0x58, 0xf4, 0xf4, 0xf4, 0x58, 0xf4, 0xf4, 0xf4, 0x58};
        static const __u8 po2030_matrix[9] =
                {0x60, 0xf0, 0xf0, 0xf0, 0x60, 0xf0, 0xf0, 0xf0, 0x60};
+       static const __u8 vf0250_matrix[9] =
+               {0x7b, 0xea, 0xea, 0xea, 0x7b, 0xea, 0xea, 0xea, 0x7b};
 
        switch (sd->sensor) {
        case SENSOR_GC0305:
@@ -6363,8 +6362,9 @@ static void setmatrix(struct gspca_dev *gspca_dev)
        case SENSOR_PO2030:
                matrix = po2030_matrix;
                break;
-       case SENSOR_TAS5130C_VF0250:    /* no matrix? */
-               return;
+       case SENSOR_TAS5130C_VF0250:
+               matrix = vf0250_matrix;
+               break;
        default:                /* matrix already loaded */
                return;
        }
@@ -6744,7 +6744,7 @@ static int vga_2wr_probe(struct gspca_dev *gspca_dev)
                return 0x04;                    /* CS2102 */
 
        start_2wr_probe(dev, 0x06);             /* OmniVision */
-       reg_w(dev, 0x08, 0x8d);
+       reg_w(dev, 0x08, 0x008d);
        i2c_write(gspca_dev, 0x11, 0xaa, 0x00);
        retbyte = i2c_read(gspca_dev, 0x11);
        if (retbyte != 0) {
@@ -6778,7 +6778,7 @@ static int vga_2wr_probe(struct gspca_dev *gspca_dev)
                return 0x0c;                    /* ICM105A */
 
        start_2wr_probe(dev, 0x0e);             /* PAS202BCB */
-       reg_w(dev, 0x08, 0x8d);
+       reg_w(dev, 0x08, 0x008d);
        i2c_write(gspca_dev, 0x03, 0xaa, 0x00);
        msleep(500);
        retbyte = i2c_read(gspca_dev, 0x03);
@@ -6830,7 +6830,6 @@ static const struct sensor_by_chipset_revision chipset_revision_sensor[] = {
        {0x8001, 0x13},
        {0x8000, 0x14},         /* CS2102K */
        {0x8400, 0x15},         /* TAS5130K */
-       {0, 0}
 };
 
 static int vga_3wr_probe(struct gspca_dev *gspca_dev)
@@ -6843,7 +6842,7 @@ static int vga_3wr_probe(struct gspca_dev *gspca_dev)
 
 /*fixme: lack of 8b=b3 (11,12)-> 10, 8b=e0 (14,15,16)-> 12 found in gspcav1*/
        reg_w(dev, 0x02, 0x0010);
-       reg_r(gspca_dev, 0x10);
+       reg_r(gspca_dev, 0x0010);
        reg_w(dev, 0x01, 0x0000);
        reg_w(dev, 0x00, 0x0010);
        reg_w(dev, 0x01, 0x0001);
@@ -6869,17 +6868,15 @@ static int vga_3wr_probe(struct gspca_dev *gspca_dev)
        PDEBUG(D_PROBE, "probe 3wr vga 1 0x%04x", checkword);
        reg_r(gspca_dev, 0x0010);
        /* this is tested only once anyway */
-       i = 0;
-       while (chipset_revision_sensor[i].revision) {
+       for (i = 0; i < ARRAY_SIZE(chipset_revision_sensor); i++) {
                if (chipset_revision_sensor[i].revision == checkword) {
                        sd->chip_revision = checkword;
                        send_unknown(dev, SENSOR_PB0330);
                        return chipset_revision_sensor[i].internal_sensor_id;
                }
-               i++;
        }
 
-       reg_w(dev, 0x01, 0x0000);
+       reg_w(dev, 0x01, 0x0000);       /* check ?? */
        reg_w(dev, 0x01, 0x0001);
        reg_w(dev, 0xdd, 0x008b);
        reg_w(dev, 0x0a, 0x0010);
@@ -6901,8 +6898,11 @@ static int vga_3wr_probe(struct gspca_dev *gspca_dev)
        retbyte = i2c_read(gspca_dev, 0x00);
        if (retbyte != 0) {
                PDEBUG(D_PROBE, "probe 3wr vga type %02x", retbyte);
-               send_unknown(dev, SENSOR_GC0305);
-               return retbyte;         /* 0x29 = gc0305 - should continue? */
+               if (retbyte == 0x11)                    /* VF0250 */
+                       return 0x0250;
+               if (retbyte == 0x29)                    /* gc0305 */
+                       send_unknown(dev, SENSOR_GC0305);
+               return retbyte;
        }
 
        reg_w(dev, 0x01, 0x0000);       /* check OmniVision */
@@ -6918,18 +6918,18 @@ static int vga_3wr_probe(struct gspca_dev *gspca_dev)
                return 0x06;            /* OmniVision confirm ? */
        }
 
-       reg_w(dev, 0x01, 0x00);
-       reg_w(dev, 0x00, 0x02);
-       reg_w(dev, 0x01, 0x10);
-       reg_w(dev, 0x01, 0x01);
-       reg_w(dev, 0xee, 0x8b);
-       reg_w(dev, 0x03, 0x12);
+       reg_w(dev, 0x01, 0x0000);
+       reg_w(dev, 0x00, 0x0002);
+       reg_w(dev, 0x01, 0x0010);
+       reg_w(dev, 0x01, 0x0001);
+       reg_w(dev, 0xee, 0x008b);
+       reg_w(dev, 0x03, 0x0012);
 /*     msleep(150); */
-       reg_w(dev, 0x01, 0x12);
-       reg_w(dev, 0x05, 0x12);
-       retbyte = i2c_read(gspca_dev, 0x00);            /* ID 0 */
+       reg_w(dev, 0x01, 0x0012);
+       reg_w(dev, 0x05, 0x0012);
+       retbyte = i2c_read(gspca_dev, 0x0000);          /* ID 0 */
        checkword = retbyte << 8;
-       retbyte = i2c_read(gspca_dev, 0x01);            /* ID 1 */
+       retbyte = i2c_read(gspca_dev, 0x0001);          /* ID 1 */
        checkword |= retbyte;
        PDEBUG(D_PROBE, "probe 3wr vga 2 0x%04x", checkword);
        if (checkword == 0x2030) {
@@ -6939,14 +6939,14 @@ static int vga_3wr_probe(struct gspca_dev *gspca_dev)
                return checkword;
        }
 
-       reg_w(dev, 0x01, 0x00);
-       reg_w(dev, 0x0a, 0x10);
-       reg_w(dev, 0xd3, 0x8b);
-       reg_w(dev, 0x01, 0x01);
-       reg_w(dev, 0x03, 0x12);
-       reg_w(dev, 0x01, 0x12);
-       reg_w(dev, 0x05, 0x01);
-       reg_w(dev, 0xd3, 0x8b);
+       reg_w(dev, 0x01, 0x0000);
+       reg_w(dev, 0x0a, 0x0010);
+       reg_w(dev, 0xd3, 0x008b);
+       reg_w(dev, 0x01, 0x0001);
+       reg_w(dev, 0x03, 0x0012);
+       reg_w(dev, 0x01, 0x0012);
+       reg_w(dev, 0x05, 0x0001);
+       reg_w(dev, 0xd3, 0x008b);
        retbyte = i2c_read(gspca_dev, 0x01);
        if (retbyte != 0) {
                PDEBUG(D_PROBE, "probe 3wr vga type 0a ?");
@@ -6962,7 +6962,9 @@ static int zcxx_probeSensor(struct gspca_dev *gspca_dev)
 
        switch (sd->sensor) {
        case SENSOR_MC501CB:
+               return -1;              /* don't probe */
        case SENSOR_TAS5130C_VF0250:
+                               /* may probe but with write in reg 0x0010 */
                return -1;              /* don't probe */
        }
        sensor = vga_2wr_probe(gspca_dev);
@@ -7010,6 +7012,7 @@ static int sd_config(struct gspca_dev *gspca_dev,
 
        /* define some sensors from the vendor/product */
        sd->sharpness = 2;
+       sd->sensor = -1;
        switch (id->idVendor) {
        case 0x041e:                            /* Creative */
                switch (id->idProduct) {
@@ -7119,6 +7122,10 @@ static int sd_config(struct gspca_dev *gspca_dev,
                        PDEBUG(D_PROBE, "Find Sensor GC0305");
                        sd->sensor = SENSOR_GC0305;
                        break;
+               case 0x0250:
+                       PDEBUG(D_PROBE, "Sensor Tas5130 (VF0250)");
+                       sd->sensor =  SENSOR_TAS5130C_VF0250;
+                       break;
                case 0x2030:
                        PDEBUG(D_PROBE, "Find Sensor PO2030");
                        sd->sensor = SENSOR_PO2030;
@@ -7235,6 +7242,7 @@ static void sd_start(struct gspca_dev *gspca_dev)
        case SENSOR_GC0305:
        case SENSOR_OV7620:
        case SENSOR_PO2030:
+       case SENSOR_TAS5130C_VF0250:
                msleep(100);                    /* ?? */
                reg_r(gspca_dev, 0x0002);       /* --> 0x40 */
                reg_w(dev, 0x09, 0x01ad);       /* (from win traces) */
@@ -7605,7 +7613,7 @@ static int __init sd_mod_init(void)
 {
        if (usb_register(&sd_driver) < 0)
                return -1;
-       PDEBUG(D_PROBE, "v%s registered", version);
+       PDEBUG(D_PROBE, "registered");
        return 0;
 }
 
index a08bb3331cfbd05f7926912dd3fab6bd8daac569..ab287b48fc2b91a7940bd1f158ddbf438f78b1bd 100644 (file)
@@ -60,6 +60,7 @@
 #include <linux/dvb/video.h>
 #include <linux/dvb/audio.h>
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 #include <media/tuner.h>
 #include <media/cx2341x.h>
 
index f8883b487f4a9dbbee6cda1d1edd0c0fb64fd2c6..b883c4e08fbd7e79951f85204c07189c72f22081 100644 (file)
@@ -217,7 +217,7 @@ static int ivtv_prep_dev(struct ivtv *itv, int type)
                        itv->num, s->name);
 
        s->v4l2dev->minor = minor;
-       s->v4l2dev->dev = &itv->dev->dev;
+       s->v4l2dev->parent = &itv->dev->dev;
        s->v4l2dev->fops = ivtv_stream_info[type].fops;
        s->v4l2dev->release = video_device_release;
        s->v4l2dev->tvnorms = V4L2_STD_ALL;
index 2fb5854cf6f039d58967b9ad07735c0a73e5f9b3..a1fb9874fdcfd1c6b34d94ab2c3719fefcc30599 100644 (file)
@@ -31,6 +31,7 @@
 #include <linux/init.h>
 #include <linux/videodev.h>
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 #include <asm/uaccess.h>
 #include <asm/io.h>
 #include <linux/delay.h>
@@ -1801,7 +1802,7 @@ static int __devinit meye_probe(struct pci_dev *pcidev,
        }
 
        memcpy(meye.video_dev, &meye_template, sizeof(meye_template));
-       meye.video_dev->dev = &meye.mchip_dev->dev;
+       meye.video_dev->parent = &meye.mchip_dev->dev;
 
        if ((ret = sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERA, 1))) {
                printk(KERN_ERR "meye: unable to power on the camera\n");
index 5691e019d19567d56ba8f9ba1f82a354f55a6ee5..780531b587a430e7e4dbf3502e768fd86e0a92f7 100644 (file)
@@ -54,6 +54,7 @@
 #include <linux/videodev.h>
 #include <linux/videodev2.h>
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 #include <media/v4l2-i2c-drv-legacy.h>
 #include <media/tvaudio.h>
 #include <media/msp3400.h>
index ee43499544c13d9f01cd12d1c973762099475db8..554d2295484e5f1b02f7fec28c34768fa596d0dd 100644 (file)
@@ -120,7 +120,7 @@ static int mt9m001_init(struct soc_camera_device *icd)
        int ret;
 
        /* Disable chip, synchronous option update */
-       dev_dbg(icd->vdev->dev, "%s\n", __func__);
+       dev_dbg(icd->vdev->parent, "%s\n", __func__);
 
        ret = reg_write(icd, MT9M001_RESET, 1);
        if (ret >= 0)
index eafb0c7736e630bff974b002db478702aeee5100..b72e5660bc193c5327fb161989e8df7b549f9fc2 100644 (file)
@@ -5833,7 +5833,7 @@ ov51x_probe(struct usb_interface *intf, const struct usb_device_id *id)
                goto error;
 
        memcpy(ov->vdev, &vdev_template, sizeof(*ov->vdev));
-       ov->vdev->dev = &intf->dev;
+       ov->vdev->parent = &intf->dev;
        video_set_drvdata(ov->vdev, ov);
 
        for (i = 0; i < OV511_MAX_UNIT_VIDEO; i++) {
index 1010e51189b77bd3f6d2970bd69111659e84e51a..baded1262ca9f68b675ca72d3ad18d045d8f2f41 100644 (file)
@@ -4,6 +4,7 @@
 #include <asm/uaccess.h>
 #include <linux/videodev.h>
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 #include <linux/usb.h>
 #include <linux/mutex.h>
 
index 51b1461d8fb62707f48482a59ee34cef55d85a50..260c1d3f9692550a51fa91d68d6bdb56f3bd83eb 100644 (file)
@@ -30,6 +30,7 @@
 #include <asm/io.h>
 #include <linux/videodev.h>
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 #include <linux/mutex.h>
 
 #include <asm/uaccess.h>
index 0d72dc470fef871a16b24d35cb339b92badcf313..bd6169fbdcca91f66b8cc1cc885d2eb4e40b3e07 100644 (file)
@@ -30,6 +30,7 @@
 #include <linux/videodev2.h>
 #include <media/v4l2-dev.h>
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 
 struct pvr2_v4l2_dev;
 struct pvr2_v4l2_fh;
index 423fa7c2d0c9b465fa54f0a6cb761ea06e1cd420..b4de82115e5b68e2addfe1ad04f22199d06355f0 100644 (file)
@@ -1767,7 +1767,7 @@ static int usb_pwc_probe(struct usb_interface *intf, const struct usb_device_id
                return -ENOMEM;
        }
        memcpy(pdev->vdev, &pwc_template, sizeof(pwc_template));
-       pdev->vdev->dev = &(udev->dev);
+       pdev->vdev->parent = &(udev->dev);
        strcpy(pdev->vdev->name, name);
        pdev->vdev->owner = THIS_MODULE;
        video_set_drvdata(pdev->vdev, pdev);
index 8e8e5b27e77ea2f9c77edd549bc696b7b7c1000e..835db149a3b149157a901683e941cf47765b2ede 100644 (file)
@@ -35,6 +35,7 @@
 #include <asm/errno.h>
 #include <linux/videodev.h>
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 
 #include "pwc-uncompress.h"
 #include <media/pwc-ioctl.h>
index 04eb2c3fabd8767ad6e8d282aec7660d426a514e..eb81915935b136bc4e2e73830025ff9f7d2db1d3 100644 (file)
@@ -49,6 +49,7 @@
 #include <linux/version.h>
 #include <media/videobuf-vmalloc.h>
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 #include <linux/vmalloc.h>
 #include <linux/usb.h>
 
@@ -1706,7 +1707,7 @@ static int s2255_probe_v4l(struct s2255_dev *dev)
                /* register 4 video devices */
                dev->vdev[i] = video_device_alloc();
                memcpy(dev->vdev[i], &template, sizeof(struct video_device));
-               dev->vdev[i]->dev = &dev->interface->dev;
+               dev->vdev[i]->parent = &dev->interface->dev;
                if (video_nr == -1)
                        ret = video_register_device(dev->vdev[i],
                                                    VFL_TYPE_GRABBER,
index 03e772130b55f2edeec58f3febce448b1f970a72..8d69632a66581ff483c528e4accfa014acc287df 100644 (file)
@@ -46,6 +46,7 @@
 #include <linux/videotext.h>
 #include <linux/videodev.h>
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 #include <linux/mutex.h>
 
 #include "saa5246a.h"
index fde99d9ee71f5716f7acdcefcc3625a3cc05c7e6..812cfe3fd3f30185477e69d300b5579621e6831c 100644 (file)
@@ -57,6 +57,7 @@
 #include <linux/videotext.h>
 #include <linux/videodev.h>
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 #include <linux/mutex.h>
 
 
index cfee84ee7a88a3e5c0a187ddd96532afe700549d..f3e7a598e4b522b1d2d4d457ef53bb8116258889 100644 (file)
@@ -798,7 +798,7 @@ static struct video_device *vdev_init(struct saa7134_dev *dev,
                return NULL;
        *vfd = *template;
        vfd->minor   = -1;
-       vfd->dev     = &dev->pci->dev;
+       vfd->parent  = &dev->pci->dev;
        vfd->release = video_device_release;
        vfd->debug   = video_debug;
        snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)",
index 2a5ab957542dfacab6e3e73dfe77da44c2975280..3854cc29752d30472be07839bf08d4cc7c9e02f5 100644 (file)
@@ -465,7 +465,7 @@ static int empress_init(struct saa7134_dev *dev)
        if (NULL == dev->empress_dev)
                return -ENOMEM;
        *(dev->empress_dev) = saa7134_empress_template;
-       dev->empress_dev->dev     = &dev->pci->dev;
+       dev->empress_dev->parent  = &dev->pci->dev;
        dev->empress_dev->release = video_device_release;
        snprintf(dev->empress_dev->name, sizeof(dev->empress_dev->name),
                 "%s empress (%s)", dev->name,
index 6927cbea86245b6e49cd268af82fc04da600ff76..ade4e19799e948ac4b588e00a91e45ca353d4a4a 100644 (file)
@@ -34,6 +34,7 @@
 #include <asm/io.h>
 
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 #include <media/tuner.h>
 #include <media/ir-common.h>
 #include <media/ir-kbd-i2c.h>
index 835ef872e80375af580d676d5616ce0635f9a536..2ce685db5d8b2eaa91021d7668b669cf59f1e74e 100644 (file)
@@ -5,6 +5,7 @@
 #include <asm/uaccess.h>
 #include <linux/videodev.h>
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 #include <linux/mutex.h>
 
 #define se401_DEBUG    /* Turn on debug messages */
index 012005e1a77b60e771e54ed329d315d2a0a8b132..f7ca3cb9340ad3ef0fb750dcd60a229f9d0c2208 100644 (file)
@@ -91,6 +91,7 @@ struct sh_mobile_ceu_dev {
        void __iomem *base;
        unsigned long video_limit;
 
+       /* lock used to protect videobuf */
        spinlock_t lock;
        struct list_head capture;
        struct videobuf_buffer *active;
index 0c8d87d8d18dd0b7e3b60b1b530942f944bfef96..cbfc44433b99fd56a2bbb8aff56712698f96a61e 100644 (file)
@@ -25,6 +25,7 @@
 #include <linux/usb.h>
 #include <linux/videodev2.h>
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 #include <linux/device.h>
 #include <linux/list.h>
 #include <linux/spinlock.h>
index 7f9c7bcf3c852428b73052e89b146c33c4569e2b..475b78191151ed6e9bf4c9825ac8c4493a8eace9 100644 (file)
@@ -1038,8 +1038,7 @@ static ssize_t sn9c102_show_reg(struct device* cd,
        if (mutex_lock_interruptible(&sn9c102_sysfs_lock))
                return -ERESTARTSYS;
 
-       cam = video_get_drvdata(container_of(cd, struct video_device,
-                                            class_dev));
+       cam = video_get_drvdata(container_of(cd, struct video_device, dev));
        if (!cam) {
                mutex_unlock(&sn9c102_sysfs_lock);
                return -ENODEV;
@@ -1064,8 +1063,7 @@ sn9c102_store_reg(struct device* cd, struct device_attribute *attr,
        if (mutex_lock_interruptible(&sn9c102_sysfs_lock))
                return -ERESTARTSYS;
 
-       cam = video_get_drvdata(container_of(cd, struct video_device,
-                                            class_dev));
+       cam = video_get_drvdata(container_of(cd, struct video_device, dev));
        if (!cam) {
                mutex_unlock(&sn9c102_sysfs_lock);
                return -ENODEV;
@@ -1098,8 +1096,7 @@ static ssize_t sn9c102_show_val(struct device* cd,
        if (mutex_lock_interruptible(&sn9c102_sysfs_lock))
                return -ERESTARTSYS;
 
-       cam = video_get_drvdata(container_of(cd, struct video_device,
-                                            class_dev));
+       cam = video_get_drvdata(container_of(cd, struct video_device, dev));
        if (!cam) {
                mutex_unlock(&sn9c102_sysfs_lock);
                return -ENODEV;
@@ -1132,8 +1129,7 @@ sn9c102_store_val(struct device* cd, struct device_attribute *attr,
        if (mutex_lock_interruptible(&sn9c102_sysfs_lock))
                return -ERESTARTSYS;
 
-       cam = video_get_drvdata(container_of(cd, struct video_device,
-                                            class_dev));
+       cam = video_get_drvdata(container_of(cd, struct video_device, dev));
        if (!cam) {
                mutex_unlock(&sn9c102_sysfs_lock);
                return -ENODEV;
@@ -1170,8 +1166,7 @@ static ssize_t sn9c102_show_i2c_reg(struct device* cd,
        if (mutex_lock_interruptible(&sn9c102_sysfs_lock))
                return -ERESTARTSYS;
 
-       cam = video_get_drvdata(container_of(cd, struct video_device,
-                                            class_dev));
+       cam = video_get_drvdata(container_of(cd, struct video_device, dev));
        if (!cam) {
                mutex_unlock(&sn9c102_sysfs_lock);
                return -ENODEV;
@@ -1198,8 +1193,7 @@ sn9c102_store_i2c_reg(struct device* cd, struct device_attribute *attr,
        if (mutex_lock_interruptible(&sn9c102_sysfs_lock))
                return -ERESTARTSYS;
 
-       cam = video_get_drvdata(container_of(cd, struct video_device,
-                                            class_dev));
+       cam = video_get_drvdata(container_of(cd, struct video_device, dev));
        if (!cam) {
                mutex_unlock(&sn9c102_sysfs_lock);
                return -ENODEV;
@@ -1232,8 +1226,7 @@ static ssize_t sn9c102_show_i2c_val(struct device* cd,
        if (mutex_lock_interruptible(&sn9c102_sysfs_lock))
                return -ERESTARTSYS;
 
-       cam = video_get_drvdata(container_of(cd, struct video_device,
-                                            class_dev));
+       cam = video_get_drvdata(container_of(cd, struct video_device, dev));
        if (!cam) {
                mutex_unlock(&sn9c102_sysfs_lock);
                return -ENODEV;
@@ -1271,8 +1264,7 @@ sn9c102_store_i2c_val(struct device* cd, struct device_attribute *attr,
        if (mutex_lock_interruptible(&sn9c102_sysfs_lock))
                return -ERESTARTSYS;
 
-       cam = video_get_drvdata(container_of(cd, struct video_device,
-                                            class_dev));
+       cam = video_get_drvdata(container_of(cd, struct video_device, dev));
        if (!cam) {
                mutex_unlock(&sn9c102_sysfs_lock);
                return -ENODEV;
@@ -1318,8 +1310,7 @@ sn9c102_store_green(struct device* cd, struct device_attribute *attr,
        if (mutex_lock_interruptible(&sn9c102_sysfs_lock))
                return -ERESTARTSYS;
 
-       cam = video_get_drvdata(container_of(cd, struct video_device,
-                                            class_dev));
+       cam = video_get_drvdata(container_of(cd, struct video_device, dev));
        if (!cam) {
                mutex_unlock(&sn9c102_sysfs_lock);
                return -ENODEV;
@@ -1400,8 +1391,7 @@ static ssize_t sn9c102_show_frame_header(struct device* cd,
        struct sn9c102_device* cam;
        ssize_t count;
 
-       cam = video_get_drvdata(container_of(cd, struct video_device,
-                                            class_dev));
+       cam = video_get_drvdata(container_of(cd, struct video_device, dev));
        if (!cam)
                return -ENODEV;
 
@@ -1428,49 +1418,49 @@ static DEVICE_ATTR(frame_header, S_IRUGO, sn9c102_show_frame_header, NULL);
 
 static int sn9c102_create_sysfs(struct sn9c102_device* cam)
 {
-       struct device *classdev = &(cam->v4ldev->class_dev);
+       struct device *dev = &(cam->v4ldev->dev);
        int err = 0;
 
-       if ((err = device_create_file(classdev, &dev_attr_reg)))
+       if ((err = device_create_file(dev, &dev_attr_reg)))
                goto err_out;
-       if ((err = device_create_file(classdev, &dev_attr_val)))
+       if ((err = device_create_file(dev, &dev_attr_val)))
                goto err_reg;
-       if ((err = device_create_file(classdev, &dev_attr_frame_header)))
+       if ((err = device_create_file(dev, &dev_attr_frame_header)))
                goto err_val;
 
        if (cam->sensor.sysfs_ops) {
-               if ((err = device_create_file(classdev, &dev_attr_i2c_reg)))
+               if ((err = device_create_file(dev, &dev_attr_i2c_reg)))
                        goto err_frame_header;
-               if ((err = device_create_file(classdev, &dev_attr_i2c_val)))
+               if ((err = device_create_file(dev, &dev_attr_i2c_val)))
                        goto err_i2c_reg;
        }
 
        if (cam->bridge == BRIDGE_SN9C101 || cam->bridge == BRIDGE_SN9C102) {
-               if ((err = device_create_file(classdev, &dev_attr_green)))
+               if ((err = device_create_file(dev, &dev_attr_green)))
                        goto err_i2c_val;
        } else {
-               if ((err = device_create_file(classdev, &dev_attr_blue)))
+               if ((err = device_create_file(dev, &dev_attr_blue)))
                        goto err_i2c_val;
-               if ((err = device_create_file(classdev, &dev_attr_red)))
+               if ((err = device_create_file(dev, &dev_attr_red)))
                        goto err_blue;
        }
 
        return 0;
 
 err_blue:
-       device_remove_file(classdev, &dev_attr_blue);
+       device_remove_file(dev, &dev_attr_blue);
 err_i2c_val:
        if (cam->sensor.sysfs_ops)
-               device_remove_file(classdev, &dev_attr_i2c_val);
+               device_remove_file(dev, &dev_attr_i2c_val);
 err_i2c_reg:
        if (cam->sensor.sysfs_ops)
-               device_remove_file(classdev, &dev_attr_i2c_reg);
+               device_remove_file(dev, &dev_attr_i2c_reg);
 err_frame_header:
-       device_remove_file(classdev, &dev_attr_frame_header);
+       device_remove_file(dev, &dev_attr_frame_header);
 err_val:
-       device_remove_file(classdev, &dev_attr_val);
+       device_remove_file(dev, &dev_attr_val);
 err_reg:
-       device_remove_file(classdev, &dev_attr_reg);
+       device_remove_file(dev, &dev_attr_reg);
 err_out:
        return err;
 }
index e39b98f1eca4e97edc94ca6008436eef20449fdd..b01749088472c1294c8b8f798d3081647f7bdb4e 100644 (file)
@@ -25,6 +25,7 @@
 #include <linux/vmalloc.h>
 
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 #include <media/v4l2-dev.h>
 #include <media/videobuf-core.h>
 #include <media/soc_camera.h>
@@ -193,7 +194,7 @@ static int soc_camera_open(struct inode *inode, struct file *file)
        mutex_lock(&video_lock);
 
        vdev = video_devdata(file);
-       icd = container_of(vdev->dev, struct soc_camera_device, dev);
+       icd = container_of(vdev->parent, struct soc_camera_device, dev);
        ici = to_soc_camera_host(icd->dev.parent);
 
        if (!try_module_get(icd->ops->owner)) {
@@ -258,7 +259,7 @@ static int soc_camera_close(struct inode *inode, struct file *file)
 
        vfree(icf);
 
-       dev_dbg(vdev->dev, "camera device close\n");
+       dev_dbg(vdev->parent, "camera device close\n");
 
        return 0;
 }
@@ -271,7 +272,7 @@ static ssize_t soc_camera_read(struct file *file, char __user *buf,
        struct video_device *vdev = icd->vdev;
        int err = -EINVAL;
 
-       dev_err(vdev->dev, "camera device read not implemented\n");
+       dev_err(vdev->parent, "camera device read not implemented\n");
 
        return err;
 }
@@ -877,7 +878,7 @@ int soc_camera_video_start(struct soc_camera_device *icd)
 
        strlcpy(vdev->name, ici->drv_name, sizeof(vdev->name));
        /* Maybe better &ici->dev */
-       vdev->dev               = &icd->dev;
+       vdev->parent            = &icd->dev;
        vdev->type              = VID_TYPE_CAPTURE;
        vdev->current_norm      = V4L2_STD_UNKNOWN;
        vdev->fops              = &soc_camera_fops;
@@ -915,7 +916,7 @@ int soc_camera_video_start(struct soc_camera_device *icd)
 
        err = video_register_device(vdev, VFL_TYPE_GRABBER, vdev->minor);
        if (err < 0) {
-               dev_err(vdev->dev, "video_register_device failed\n");
+               dev_err(vdev->parent, "video_register_device failed\n");
                goto evidregd;
        }
        icd->vdev = vdev;
index f308c38d744fb2e7747328baf339492282ca8beb..20028aeb842b3bb23b231ee4df424ae989096c98 100644 (file)
@@ -34,6 +34,7 @@
 #include <linux/vmalloc.h>
 #include <linux/videodev2.h>
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 
 #include "stk-webcam.h"
 
@@ -1369,7 +1370,7 @@ static int stk_register_video_device(struct stk_camera *dev)
 
        dev->vdev = stk_v4l_data;
        dev->vdev.debug = debug;
-       dev->vdev.dev = &dev->interface->dev;
+       dev->vdev.parent = &dev->interface->dev;
        dev->vdev.priv = dev;
        err = video_register_device(&dev->vdev, VFL_TYPE_GRABBER, -1);
        if (err)
index c109511f21ea8a92b307d4ce1596748567c0348f..6ace8923b797b25ca944368e44fae0b7bc965d90 100644 (file)
@@ -43,6 +43,7 @@
 #include <linux/vmalloc.h>
 #include <linux/videodev.h>
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 
 #include "saa7146.h"
 #include "saa7146reg.h"
index d7f130bedb5f47a05f6eddff87634e6af54d25c4..da94d3fd8fac7ea99f5687e0c47d1d0c07423429 100644 (file)
@@ -66,6 +66,7 @@
 #include <linux/errno.h>
 #include <linux/videodev.h>
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 #include <linux/usb.h>
 #include <linux/mutex.h>
 
@@ -1454,7 +1455,7 @@ static int stv680_probe (struct usb_interface *intf, const struct usb_device_id
                goto error;
        }
        memcpy(stv680->vdev, &stv680_template, sizeof(stv680_template));
-       stv680->vdev->dev = &intf->dev;
+       stv680->vdev->parent = &intf->dev;
        video_set_drvdata(stv680->vdev, stv680);
 
        memcpy (stv680->vdev->name, stv680->camera_name, strlen (stv680->camera_name));
index ae75c187da79baa0623da0667694aa308a67f015..2fda40c0f2553d3931e5eb4b0e1b76f0bbf30b02 100644 (file)
@@ -48,6 +48,7 @@
 #include <linux/i2c.h>
 
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 #include <media/i2c-addr.h>
 
 #ifndef VIDEO_AUDIO_BALANCE
index 93d879dc510f2b5b0d5e0d148696942cb1cfed17..d806a3556eedd9f48b8ba40fc07ef8bf7417bef2 100644 (file)
@@ -19,6 +19,7 @@
 #include <media/tuner.h>
 #include <media/tuner-types.h>
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 #include <media/v4l2-i2c-drv-legacy.h>
 #include "mt20xx.h"
 #include "tda8290.h"
index 4128ee20b64e3eee52db9e720b44d2f143a63f2b..7e6ab2910c138a2ead2bfc44d19f1c9e301df9b6 100644 (file)
@@ -1040,7 +1040,7 @@ int usbvideo_RegisterVideoDevice(struct uvd *uvd)
                err("%s: uvd->dev == NULL", __func__);
                return -EINVAL;
        }
-       uvd->vdev.dev = &uvd->dev->dev;
+       uvd->vdev.parent = &uvd->dev->dev;
        if (video_register_device(&uvd->vdev, VFL_TYPE_GRABBER, video_nr) == -1) {
                err("%s: video_register_device failed", __func__);
                return -EPIPE;
index 051775d4c72611c89a1a6aeda4ba8260d90e81c0..c66985beb8c9dfdfcf364547af4a5c8d0e413d95 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <linux/videodev.h>
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 #include <linux/usb.h>
 #include <linux/mutex.h>
 
index cd6c41d67899280d9628e3f4e29fd3e57826866d..56cd685d35ea85b59614e89127f0d99d2b28cb1f 100644 (file)
@@ -65,6 +65,7 @@
 
 #include <media/saa7115.h>
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 #include <media/tuner.h>
 #include <media/audiochip.h>
 
@@ -184,7 +185,7 @@ MODULE_ALIAS(DRIVER_ALIAS);
 static inline struct usb_usbvision *cd_to_usbvision(struct device *cd)
 {
        struct video_device *vdev =
-               container_of(cd, struct video_device, class_dev);
+               container_of(cd, struct video_device, dev);
        return video_get_drvdata(vdev);
 }
 
@@ -199,7 +200,7 @@ static ssize_t show_model(struct device *cd,
                          struct device_attribute *attr, char *buf)
 {
        struct video_device *vdev =
-               container_of(cd, struct video_device, class_dev);
+               container_of(cd, struct video_device, dev);
        struct usb_usbvision *usbvision = video_get_drvdata(vdev);
        return sprintf(buf, "%s\n",
                       usbvision_device_data[usbvision->DevModel].ModelString);
@@ -210,7 +211,7 @@ static ssize_t show_hue(struct device *cd,
                        struct device_attribute *attr, char *buf)
 {
        struct video_device *vdev =
-               container_of(cd, struct video_device, class_dev);
+               container_of(cd, struct video_device, dev);
        struct usb_usbvision *usbvision = video_get_drvdata(vdev);
        struct v4l2_control ctrl;
        ctrl.id = V4L2_CID_HUE;
@@ -225,7 +226,7 @@ static ssize_t show_contrast(struct device *cd,
                             struct device_attribute *attr, char *buf)
 {
        struct video_device *vdev =
-               container_of(cd, struct video_device, class_dev);
+               container_of(cd, struct video_device, dev);
        struct usb_usbvision *usbvision = video_get_drvdata(vdev);
        struct v4l2_control ctrl;
        ctrl.id = V4L2_CID_CONTRAST;
@@ -240,7 +241,7 @@ static ssize_t show_brightness(struct device *cd,
                               struct device_attribute *attr, char *buf)
 {
        struct video_device *vdev =
-               container_of(cd, struct video_device, class_dev);
+               container_of(cd, struct video_device, dev);
        struct usb_usbvision *usbvision = video_get_drvdata(vdev);
        struct v4l2_control ctrl;
        ctrl.id = V4L2_CID_BRIGHTNESS;
@@ -255,7 +256,7 @@ static ssize_t show_saturation(struct device *cd,
                               struct device_attribute *attr, char *buf)
 {
        struct video_device *vdev =
-               container_of(cd, struct video_device, class_dev);
+               container_of(cd, struct video_device, dev);
        struct usb_usbvision *usbvision = video_get_drvdata(vdev);
        struct v4l2_control ctrl;
        ctrl.id = V4L2_CID_SATURATION;
@@ -270,7 +271,7 @@ static ssize_t show_streaming(struct device *cd,
                              struct device_attribute *attr, char *buf)
 {
        struct video_device *vdev =
-               container_of(cd, struct video_device, class_dev);
+               container_of(cd, struct video_device, dev);
        struct usb_usbvision *usbvision = video_get_drvdata(vdev);
        return sprintf(buf, "%s\n",
                       YES_NO(usbvision->streaming==Stream_On?1:0));
@@ -281,7 +282,7 @@ static ssize_t show_compression(struct device *cd,
                                struct device_attribute *attr, char *buf)
 {
        struct video_device *vdev =
-               container_of(cd, struct video_device, class_dev);
+               container_of(cd, struct video_device, dev);
        struct usb_usbvision *usbvision = video_get_drvdata(vdev);
        return sprintf(buf, "%s\n",
                       YES_NO(usbvision->isocMode==ISOC_MODE_COMPRESS));
@@ -292,7 +293,7 @@ static ssize_t show_device_bridge(struct device *cd,
                                  struct device_attribute *attr, char *buf)
 {
        struct video_device *vdev =
-               container_of(cd, struct video_device, class_dev);
+               container_of(cd, struct video_device, dev);
        struct usb_usbvision *usbvision = video_get_drvdata(vdev);
        return sprintf(buf, "%d\n", usbvision->bridgeType);
 }
@@ -304,40 +305,31 @@ static void usbvision_create_sysfs(struct video_device *vdev)
        if (!vdev)
                return;
        do {
-               res = device_create_file(&vdev->class_dev,
-                                        &dev_attr_version);
+               res = device_create_file(&vdev->dev, &dev_attr_version);
                if (res<0)
                        break;
-               res = device_create_file(&vdev->class_dev,
-                                        &dev_attr_model);
+               res = device_create_file(&vdev->dev, &dev_attr_model);
                if (res<0)
                        break;
-               res = device_create_file(&vdev->class_dev,
-                                        &dev_attr_hue);
+               res = device_create_file(&vdev->dev, &dev_attr_hue);
                if (res<0)
                        break;
-               res = device_create_file(&vdev->class_dev,
-                                        &dev_attr_contrast);
+               res = device_create_file(&vdev->dev, &dev_attr_contrast);
                if (res<0)
                        break;
-               res = device_create_file(&vdev->class_dev,
-                                        &dev_attr_brightness);
+               res = device_create_file(&vdev->dev, &dev_attr_brightness);
                if (res<0)
                        break;
-               res = device_create_file(&vdev->class_dev,
-                                        &dev_attr_saturation);
+               res = device_create_file(&vdev->dev, &dev_attr_saturation);
                if (res<0)
                        break;
-               res = device_create_file(&vdev->class_dev,
-                                        &dev_attr_streaming);
+               res = device_create_file(&vdev->dev, &dev_attr_streaming);
                if (res<0)
                        break;
-               res = device_create_file(&vdev->class_dev,
-                                        &dev_attr_compression);
+               res = device_create_file(&vdev->dev, &dev_attr_compression);
                if (res<0)
                        break;
-               res = device_create_file(&vdev->class_dev,
-                                        &dev_attr_bridge);
+               res = device_create_file(&vdev->dev, &dev_attr_bridge);
                if (res>=0)
                        return;
        } while (0);
@@ -348,24 +340,15 @@ static void usbvision_create_sysfs(struct video_device *vdev)
 static void usbvision_remove_sysfs(struct video_device *vdev)
 {
        if (vdev) {
-               device_remove_file(&vdev->class_dev,
-                                        &dev_attr_version);
-               device_remove_file(&vdev->class_dev,
-                                        &dev_attr_model);
-               device_remove_file(&vdev->class_dev,
-                                        &dev_attr_hue);
-               device_remove_file(&vdev->class_dev,
-                                        &dev_attr_contrast);
-               device_remove_file(&vdev->class_dev,
-                                        &dev_attr_brightness);
-               device_remove_file(&vdev->class_dev,
-                                        &dev_attr_saturation);
-               device_remove_file(&vdev->class_dev,
-                                        &dev_attr_streaming);
-               device_remove_file(&vdev->class_dev,
-                                        &dev_attr_compression);
-               device_remove_file(&vdev->class_dev,
-                                        &dev_attr_bridge);
+               device_remove_file(&vdev->dev, &dev_attr_version);
+               device_remove_file(&vdev->dev, &dev_attr_model);
+               device_remove_file(&vdev->dev, &dev_attr_hue);
+               device_remove_file(&vdev->dev, &dev_attr_contrast);
+               device_remove_file(&vdev->dev, &dev_attr_brightness);
+               device_remove_file(&vdev->dev, &dev_attr_saturation);
+               device_remove_file(&vdev->dev, &dev_attr_streaming);
+               device_remove_file(&vdev->dev, &dev_attr_compression);
+               device_remove_file(&vdev->dev, &dev_attr_bridge);
        }
 }
 
@@ -1506,7 +1489,7 @@ static struct video_device *usbvision_vdev_init(struct usb_usbvision *usbvision,
        }
        *vdev = *vdev_template;
 //     vdev->minor   = -1;
-       vdev->dev     = &usb_dev->dev;
+       vdev->parent  = &usb_dev->dev;
        snprintf(vdev->name, sizeof(vdev->name), "%s", name);
        video_set_drvdata(vdev, usbvision);
        return vdev;
index f2b2983fe06270eae97d10f6c1f4a4117a159fa1..79d6821c4741cb37411f5f826830115690cfc46f 100644 (file)
@@ -1458,7 +1458,7 @@ static int uvc_register_video(struct uvc_device *dev)
         * unregistered before the reference is released, so we don't need to
         * get another one.
         */
-       vdev->dev = &dev->intf->dev;
+       vdev->parent = &dev->intf->dev;
        vdev->type = 0;
        vdev->type2 = 0;
        vdev->minor = -1;
index b5a11eb8f9fa9eb6cb4ff06840770da621092928..d7bd71be40a9d8f76afd3a71c12b5025c714867d 100644 (file)
@@ -23,6 +23,7 @@
 #include <asm/atomic.h>
 
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 
 #include "uvcvideo.h"
 
index a0f6c60279ece8cb97cc69612889e0a646beae63..79937d1031fc81283baf06abc62c5bc45a4c8409 100644 (file)
@@ -30,6 +30,7 @@
 #include <linux/slab.h>
 #include <linux/videodev.h>
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 
 #include <asm/uaccess.h>
 #include <asm/system.h>
diff --git a/drivers/media/video/v4l2-dev.c b/drivers/media/video/v4l2-dev.c
new file mode 100644 (file)
index 0000000..88eeee1
--- /dev/null
@@ -0,0 +1,421 @@
+/*
+ * Video capture interface for Linux version 2
+ *
+ *     A generic video device interface for the LINUX operating system
+ *     using a set of device structures/vectors for low level operations.
+ *
+ *     This program is free software; you can redistribute it and/or
+ *     modify it under the terms of the GNU General Public License
+ *     as published by the Free Software Foundation; either version
+ *     2 of the License, or (at your option) any later version.
+ *
+ * Authors:    Alan Cox, <alan@redhat.com> (version 1)
+ *              Mauro Carvalho Chehab <mchehab@infradead.org> (version 2)
+ *
+ * Fixes:      20000516  Claudio Matsuoka <claudio@conectiva.com>
+ *             - Added procfs support
+ */
+
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/kernel.h>
+#include <linux/mm.h>
+#include <linux/string.h>
+#include <linux/errno.h>
+#include <linux/init.h>
+#include <linux/kmod.h>
+#include <linux/slab.h>
+#include <linux/smp_lock.h>
+#include <asm/uaccess.h>
+#include <asm/system.h>
+
+#include <media/v4l2-common.h>
+
+#define VIDEO_NUM_DEVICES      256
+#define VIDEO_NAME              "video4linux"
+
+/*
+ *     sysfs stuff
+ */
+
+static ssize_t show_index(struct device *cd,
+                        struct device_attribute *attr, char *buf)
+{
+       struct video_device *vfd = container_of(cd, struct video_device, dev);
+       return sprintf(buf, "%i\n", vfd->index);
+}
+
+static ssize_t show_name(struct device *cd,
+                        struct device_attribute *attr, char *buf)
+{
+       struct video_device *vfd = container_of(cd, struct video_device, dev);
+       return sprintf(buf, "%.*s\n", (int)sizeof(vfd->name), vfd->name);
+}
+
+static struct device_attribute video_device_attrs[] = {
+       __ATTR(name, S_IRUGO, show_name, NULL),
+       __ATTR(index, S_IRUGO, show_index, NULL),
+       __ATTR_NULL
+};
+
+struct video_device *video_device_alloc(void)
+{
+       struct video_device *vfd;
+
+       vfd = kzalloc(sizeof(*vfd), GFP_KERNEL);
+       return vfd;
+}
+EXPORT_SYMBOL(video_device_alloc);
+
+void video_device_release(struct video_device *vfd)
+{
+       kfree(vfd);
+}
+EXPORT_SYMBOL(video_device_release);
+
+static void video_release(struct device *cd)
+{
+       struct video_device *vfd = container_of(cd, struct video_device, dev);
+
+#if 1
+       /* needed until all drivers are fixed */
+       if (!vfd->release)
+               return;
+#endif
+       vfd->release(vfd);
+}
+
+static struct class video_class = {
+       .name = VIDEO_NAME,
+       .dev_attrs = video_device_attrs,
+       .dev_release = video_release,
+};
+
+/*
+ *     Active devices
+ */
+
+static struct video_device *video_device[VIDEO_NUM_DEVICES];
+static DEFINE_MUTEX(videodev_lock);
+
+struct video_device *video_devdata(struct file *file)
+{
+       return video_device[iminor(file->f_path.dentry->d_inode)];
+}
+EXPORT_SYMBOL(video_devdata);
+
+/*
+ *     Open a video device - FIXME: Obsoleted
+ */
+static int video_open(struct inode *inode, struct file *file)
+{
+       unsigned int minor = iminor(inode);
+       int err = 0;
+       struct video_device *vfl;
+       const struct file_operations *old_fops;
+
+       if (minor >= VIDEO_NUM_DEVICES)
+               return -ENODEV;
+       lock_kernel();
+       mutex_lock(&videodev_lock);
+       vfl = video_device[minor];
+       if (vfl == NULL) {
+               mutex_unlock(&videodev_lock);
+               request_module("char-major-%d-%d", VIDEO_MAJOR, minor);
+               mutex_lock(&videodev_lock);
+               vfl = video_device[minor];
+               if (vfl == NULL) {
+                       mutex_unlock(&videodev_lock);
+                       unlock_kernel();
+                       return -ENODEV;
+               }
+       }
+       old_fops = file->f_op;
+       file->f_op = fops_get(vfl->fops);
+       if (file->f_op->open)
+               err = file->f_op->open(inode, file);
+       if (err) {
+               fops_put(file->f_op);
+               file->f_op = fops_get(old_fops);
+       }
+       fops_put(old_fops);
+       mutex_unlock(&videodev_lock);
+       unlock_kernel();
+       return err;
+}
+
+/*
+ * open/release helper functions -- handle exclusive opens
+ * Should be removed soon
+ */
+int video_exclusive_open(struct inode *inode, struct file *file)
+{
+       struct video_device *vfl = video_devdata(file);
+       int retval = 0;
+
+       mutex_lock(&vfl->lock);
+       if (vfl->users)
+               retval = -EBUSY;
+       else
+               vfl->users++;
+       mutex_unlock(&vfl->lock);
+       return retval;
+}
+EXPORT_SYMBOL(video_exclusive_open);
+
+int video_exclusive_release(struct inode *inode, struct file *file)
+{
+       struct video_device *vfl = video_devdata(file);
+
+       vfl->users--;
+       return 0;
+}
+EXPORT_SYMBOL(video_exclusive_release);
+
+/**
+ * get_index - assign stream number based on parent device
+ * @vdev: video_device to assign index number to, vdev->dev should be assigned
+ * @num: -1 if auto assign, requested number otherwise
+ *
+ *
+ * returns -ENFILE if num is already in use, a free index number if
+ * successful.
+ */
+static int get_index(struct video_device *vdev, int num)
+{
+       u32 used = 0;
+       const int max_index = sizeof(used) * 8 - 1;
+       int i;
+
+       /* Currently a single v4l driver instance cannot create more than
+          32 devices.
+          Increase to u64 or an array of u32 if more are needed. */
+       if (num > max_index) {
+               printk(KERN_ERR "videodev: %s num is too large\n", __func__);
+               return -EINVAL;
+       }
+
+       for (i = 0; i < VIDEO_NUM_DEVICES; i++) {
+               if (video_device[i] != NULL &&
+                   video_device[i] != vdev &&
+                   video_device[i]->parent == vdev->parent) {
+                       used |= 1 << video_device[i]->index;
+               }
+       }
+
+       if (num >= 0) {
+               if (used & (1 << num))
+                       return -ENFILE;
+               return num;
+       }
+
+       i = ffz(used);
+       return i > max_index ? -ENFILE : i;
+}
+
+static const struct file_operations video_fops;
+
+int video_register_device(struct video_device *vfd, int type, int nr)
+{
+       return video_register_device_index(vfd, type, nr, -1);
+}
+EXPORT_SYMBOL(video_register_device);
+
+/**
+ *     video_register_device - register video4linux devices
+ *     @vfd:  video device structure we want to register
+ *     @type: type of device to register
+ *     @nr:   which device number (0 == /dev/video0, 1 == /dev/video1, ...
+ *             -1 == first free)
+ *
+ *     The registration code assigns minor numbers based on the type
+ *     requested. -ENFILE is returned in all the device slots for this
+ *     category are full. If not then the minor field is set and the
+ *     driver initialize function is called (if non %NULL).
+ *
+ *     Zero is returned on success.
+ *
+ *     Valid types are
+ *
+ *     %VFL_TYPE_GRABBER - A frame grabber
+ *
+ *     %VFL_TYPE_VTX - A teletext device
+ *
+ *     %VFL_TYPE_VBI - Vertical blank data (undecoded)
+ *
+ *     %VFL_TYPE_RADIO - A radio card
+ */
+
+int video_register_device_index(struct video_device *vfd, int type, int nr,
+                                       int index)
+{
+       int i = 0;
+       int base;
+       int end;
+       int ret;
+       char *name_base;
+
+       switch (type) {
+       case VFL_TYPE_GRABBER:
+               base = MINOR_VFL_TYPE_GRABBER_MIN;
+               end = MINOR_VFL_TYPE_GRABBER_MAX+1;
+               name_base = "video";
+               break;
+       case VFL_TYPE_VTX:
+               base = MINOR_VFL_TYPE_VTX_MIN;
+               end = MINOR_VFL_TYPE_VTX_MAX+1;
+               name_base = "vtx";
+               break;
+       case VFL_TYPE_VBI:
+               base = MINOR_VFL_TYPE_VBI_MIN;
+               end = MINOR_VFL_TYPE_VBI_MAX+1;
+               name_base = "vbi";
+               break;
+       case VFL_TYPE_RADIO:
+               base = MINOR_VFL_TYPE_RADIO_MIN;
+               end = MINOR_VFL_TYPE_RADIO_MAX+1;
+               name_base = "radio";
+               break;
+       default:
+               printk(KERN_ERR "%s called with unknown type: %d\n",
+                      __func__, type);
+               return -1;
+       }
+
+       /* pick a minor number */
+       mutex_lock(&videodev_lock);
+       if (nr >= 0  &&  nr < end-base) {
+               /* use the one the driver asked for */
+               i = base + nr;
+               if (NULL != video_device[i]) {
+                       mutex_unlock(&videodev_lock);
+                       return -ENFILE;
+               }
+       } else {
+               /* use first free */
+               for (i = base; i < end; i++)
+                       if (NULL == video_device[i])
+                               break;
+               if (i == end) {
+                       mutex_unlock(&videodev_lock);
+                       return -ENFILE;
+               }
+       }
+       video_device[i] = vfd;
+       vfd->minor = i;
+
+       ret = get_index(vfd, index);
+       vfd->index = ret;
+
+       mutex_unlock(&videodev_lock);
+
+       if (ret < 0) {
+               printk(KERN_ERR "%s: get_index failed\n", __func__);
+               goto fail_minor;
+       }
+
+       mutex_init(&vfd->lock);
+
+       /* sysfs class */
+       memset(&vfd->dev, 0x00, sizeof(vfd->dev));
+       vfd->dev.class = &video_class;
+       vfd->dev.devt = MKDEV(VIDEO_MAJOR, vfd->minor);
+       if (vfd->parent)
+               vfd->dev.parent = vfd->parent;
+       sprintf(vfd->dev.bus_id, "%s%d", name_base, i - base);
+       ret = device_register(&vfd->dev);
+       if (ret < 0) {
+               printk(KERN_ERR "%s: device_register failed\n", __func__);
+               goto fail_minor;
+       }
+
+#if 1
+       /* needed until all drivers are fixed */
+       if (!vfd->release)
+               printk(KERN_WARNING "videodev: \"%s\" has no release callback. "
+                      "Please fix your driver for proper sysfs support, see "
+                      "http://lwn.net/Articles/36850/\n", vfd->name);
+#endif
+       return 0;
+
+fail_minor:
+       mutex_lock(&videodev_lock);
+       video_device[vfd->minor] = NULL;
+       vfd->minor = -1;
+       mutex_unlock(&videodev_lock);
+       return ret;
+}
+EXPORT_SYMBOL(video_register_device_index);
+
+/**
+ *     video_unregister_device - unregister a video4linux device
+ *     @vfd: the device to unregister
+ *
+ *     This unregisters the passed device and deassigns the minor
+ *     number. Future open calls will be met with errors.
+ */
+
+void video_unregister_device(struct video_device *vfd)
+{
+       mutex_lock(&videodev_lock);
+       if (video_device[vfd->minor] != vfd)
+               panic("videodev: bad unregister");
+
+       video_device[vfd->minor] = NULL;
+       device_unregister(&vfd->dev);
+       mutex_unlock(&videodev_lock);
+}
+EXPORT_SYMBOL(video_unregister_device);
+
+/*
+ * Video fs operations
+ */
+static const struct file_operations video_fops = {
+       .owner          = THIS_MODULE,
+       .llseek         = no_llseek,
+       .open           = video_open,
+};
+
+/*
+ *     Initialise video for linux
+ */
+
+static int __init videodev_init(void)
+{
+       int ret;
+
+       printk(KERN_INFO "Linux video capture interface: v2.00\n");
+       if (register_chrdev(VIDEO_MAJOR, VIDEO_NAME, &video_fops)) {
+               printk(KERN_WARNING "video_dev: unable to get major %d\n", VIDEO_MAJOR);
+               return -EIO;
+       }
+
+       ret = class_register(&video_class);
+       if (ret < 0) {
+               unregister_chrdev(VIDEO_MAJOR, VIDEO_NAME);
+               printk(KERN_WARNING "video_dev: class_register failed\n");
+               return -EIO;
+       }
+
+       return 0;
+}
+
+static void __exit videodev_exit(void)
+{
+       class_unregister(&video_class);
+       unregister_chrdev(VIDEO_MAJOR, VIDEO_NAME);
+}
+
+module_init(videodev_init)
+module_exit(videodev_exit)
+
+MODULE_AUTHOR("Alan Cox, Mauro Carvalho Chehab <mchehab@infradead.org>");
+MODULE_DESCRIPTION("Device registrar for Video4Linux drivers v2");
+MODULE_LICENSE("GPL");
+
+
+/*
+ * Local variables:
+ * c-basic-offset: 8
+ * End:
+ */
diff --git a/drivers/media/video/v4l2-ioctl.c b/drivers/media/video/v4l2-ioctl.c
new file mode 100644 (file)
index 0000000..56a4fde
--- /dev/null
@@ -0,0 +1,1865 @@
+/*
+ * Video capture interface for Linux version 2
+ *
+ * A generic framework to process V4L2 ioctl commands.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ *
+ * Authors:    Alan Cox, <alan@redhat.com> (version 1)
+ *              Mauro Carvalho Chehab <mchehab@infradead.org> (version 2)
+ */
+
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/kernel.h>
+
+#define __OLD_VIDIOC_ /* To allow fixing old calls */
+#include <linux/videodev2.h>
+
+#ifdef CONFIG_VIDEO_V4L1
+#include <linux/videodev.h>
+#endif
+#include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
+#include <linux/video_decoder.h>
+
+#define dbgarg(cmd, fmt, arg...) \
+               do {                                                    \
+                   if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {            \
+                       printk(KERN_DEBUG "%s: ",  vfd->name);          \
+                       v4l_printk_ioctl(cmd);                          \
+                       printk(" " fmt,  ## arg);                       \
+                   }                                                   \
+               } while (0)
+
+#define dbgarg2(fmt, arg...) \
+               do {                                                    \
+                   if (vfd->debug & V4L2_DEBUG_IOCTL_ARG)              \
+                       printk(KERN_DEBUG "%s: " fmt, vfd->name, ## arg);\
+               } while (0)
+
+struct std_descr {
+       v4l2_std_id std;
+       const char *descr;
+};
+
+static const struct std_descr standards[] = {
+       { V4L2_STD_NTSC,        "NTSC"      },
+       { V4L2_STD_NTSC_M,      "NTSC-M"    },
+       { V4L2_STD_NTSC_M_JP,   "NTSC-M-JP" },
+       { V4L2_STD_NTSC_M_KR,   "NTSC-M-KR" },
+       { V4L2_STD_NTSC_443,    "NTSC-443"  },
+       { V4L2_STD_PAL,         "PAL"       },
+       { V4L2_STD_PAL_BG,      "PAL-BG"    },
+       { V4L2_STD_PAL_B,       "PAL-B"     },
+       { V4L2_STD_PAL_B1,      "PAL-B1"    },
+       { V4L2_STD_PAL_G,       "PAL-G"     },
+       { V4L2_STD_PAL_H,       "PAL-H"     },
+       { V4L2_STD_PAL_I,       "PAL-I"     },
+       { V4L2_STD_PAL_DK,      "PAL-DK"    },
+       { V4L2_STD_PAL_D,       "PAL-D"     },
+       { V4L2_STD_PAL_D1,      "PAL-D1"    },
+       { V4L2_STD_PAL_K,       "PAL-K"     },
+       { V4L2_STD_PAL_M,       "PAL-M"     },
+       { V4L2_STD_PAL_N,       "PAL-N"     },
+       { V4L2_STD_PAL_Nc,      "PAL-Nc"    },
+       { V4L2_STD_PAL_60,      "PAL-60"    },
+       { V4L2_STD_SECAM,       "SECAM"     },
+       { V4L2_STD_SECAM_B,     "SECAM-B"   },
+       { V4L2_STD_SECAM_G,     "SECAM-G"   },
+       { V4L2_STD_SECAM_H,     "SECAM-H"   },
+       { V4L2_STD_SECAM_DK,    "SECAM-DK"  },
+       { V4L2_STD_SECAM_D,     "SECAM-D"   },
+       { V4L2_STD_SECAM_K,     "SECAM-K"   },
+       { V4L2_STD_SECAM_K1,    "SECAM-K1"  },
+       { V4L2_STD_SECAM_L,     "SECAM-L"   },
+       { V4L2_STD_SECAM_LC,    "SECAM-Lc"  },
+       { 0,                    "Unknown"   }
+};
+
+/* video4linux standard ID conversion to standard name
+ */
+const char *v4l2_norm_to_name(v4l2_std_id id)
+{
+       u32 myid = id;
+       int i;
+
+       /* HACK: ppc32 architecture doesn't have __ucmpdi2 function to handle
+          64 bit comparations. So, on that architecture, with some gcc
+          variants, compilation fails. Currently, the max value is 30bit wide.
+        */
+       BUG_ON(myid != id);
+
+       for (i = 0; standards[i].std; i++)
+               if (myid == standards[i].std)
+                       break;
+       return standards[i].descr;
+}
+EXPORT_SYMBOL(v4l2_norm_to_name);
+
+/* Fill in the fields of a v4l2_standard structure according to the
+   'id' and 'transmission' parameters.  Returns negative on error.  */
+int v4l2_video_std_construct(struct v4l2_standard *vs,
+                            int id, const char *name)
+{
+       u32 index = vs->index;
+
+       memset(vs, 0, sizeof(struct v4l2_standard));
+       vs->index = index;
+       vs->id    = id;
+       if (id & V4L2_STD_525_60) {
+               vs->frameperiod.numerator = 1001;
+               vs->frameperiod.denominator = 30000;
+               vs->framelines = 525;
+       } else {
+               vs->frameperiod.numerator = 1;
+               vs->frameperiod.denominator = 25;
+               vs->framelines = 625;
+       }
+       strlcpy(vs->name, name, sizeof(vs->name));
+       return 0;
+}
+EXPORT_SYMBOL(v4l2_video_std_construct);
+
+/* ----------------------------------------------------------------- */
+/* some arrays for pretty-printing debug messages of enum types      */
+
+const char *v4l2_field_names[] = {
+       [V4L2_FIELD_ANY]        = "any",
+       [V4L2_FIELD_NONE]       = "none",
+       [V4L2_FIELD_TOP]        = "top",
+       [V4L2_FIELD_BOTTOM]     = "bottom",
+       [V4L2_FIELD_INTERLACED] = "interlaced",
+       [V4L2_FIELD_SEQ_TB]     = "seq-tb",
+       [V4L2_FIELD_SEQ_BT]     = "seq-bt",
+       [V4L2_FIELD_ALTERNATE]  = "alternate",
+       [V4L2_FIELD_INTERLACED_TB] = "interlaced-tb",
+       [V4L2_FIELD_INTERLACED_BT] = "interlaced-bt",
+};
+EXPORT_SYMBOL(v4l2_field_names);
+
+const char *v4l2_type_names[] = {
+       [V4L2_BUF_TYPE_VIDEO_CAPTURE]      = "vid-cap",
+       [V4L2_BUF_TYPE_VIDEO_OVERLAY]      = "vid-overlay",
+       [V4L2_BUF_TYPE_VIDEO_OUTPUT]       = "vid-out",
+       [V4L2_BUF_TYPE_VBI_CAPTURE]        = "vbi-cap",
+       [V4L2_BUF_TYPE_VBI_OUTPUT]         = "vbi-out",
+       [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE] = "sliced-vbi-cap",
+       [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT]  = "sliced-vbi-out",
+       [V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY] = "vid-out-overlay",
+};
+EXPORT_SYMBOL(v4l2_type_names);
+
+static const char *v4l2_memory_names[] = {
+       [V4L2_MEMORY_MMAP]    = "mmap",
+       [V4L2_MEMORY_USERPTR] = "userptr",
+       [V4L2_MEMORY_OVERLAY] = "overlay",
+};
+
+#define prt_names(a, arr) ((((a) >= 0) && ((a) < ARRAY_SIZE(arr))) ? \
+                          arr[a] : "unknown")
+
+/* ------------------------------------------------------------------ */
+/* debug help functions                                               */
+
+#ifdef CONFIG_VIDEO_V4L1_COMPAT
+static const char *v4l1_ioctls[] = {
+       [_IOC_NR(VIDIOCGCAP)]       = "VIDIOCGCAP",
+       [_IOC_NR(VIDIOCGCHAN)]      = "VIDIOCGCHAN",
+       [_IOC_NR(VIDIOCSCHAN)]      = "VIDIOCSCHAN",
+       [_IOC_NR(VIDIOCGTUNER)]     = "VIDIOCGTUNER",
+       [_IOC_NR(VIDIOCSTUNER)]     = "VIDIOCSTUNER",
+       [_IOC_NR(VIDIOCGPICT)]      = "VIDIOCGPICT",
+       [_IOC_NR(VIDIOCSPICT)]      = "VIDIOCSPICT",
+       [_IOC_NR(VIDIOCCAPTURE)]    = "VIDIOCCAPTURE",
+       [_IOC_NR(VIDIOCGWIN)]       = "VIDIOCGWIN",
+       [_IOC_NR(VIDIOCSWIN)]       = "VIDIOCSWIN",
+       [_IOC_NR(VIDIOCGFBUF)]      = "VIDIOCGFBUF",
+       [_IOC_NR(VIDIOCSFBUF)]      = "VIDIOCSFBUF",
+       [_IOC_NR(VIDIOCKEY)]        = "VIDIOCKEY",
+       [_IOC_NR(VIDIOCGFREQ)]      = "VIDIOCGFREQ",
+       [_IOC_NR(VIDIOCSFREQ)]      = "VIDIOCSFREQ",
+       [_IOC_NR(VIDIOCGAUDIO)]     = "VIDIOCGAUDIO",
+       [_IOC_NR(VIDIOCSAUDIO)]     = "VIDIOCSAUDIO",
+       [_IOC_NR(VIDIOCSYNC)]       = "VIDIOCSYNC",
+       [_IOC_NR(VIDIOCMCAPTURE)]   = "VIDIOCMCAPTURE",
+       [_IOC_NR(VIDIOCGMBUF)]      = "VIDIOCGMBUF",
+       [_IOC_NR(VIDIOCGUNIT)]      = "VIDIOCGUNIT",
+       [_IOC_NR(VIDIOCGCAPTURE)]   = "VIDIOCGCAPTURE",
+       [_IOC_NR(VIDIOCSCAPTURE)]   = "VIDIOCSCAPTURE",
+       [_IOC_NR(VIDIOCSPLAYMODE)]  = "VIDIOCSPLAYMODE",
+       [_IOC_NR(VIDIOCSWRITEMODE)] = "VIDIOCSWRITEMODE",
+       [_IOC_NR(VIDIOCGPLAYINFO)]  = "VIDIOCGPLAYINFO",
+       [_IOC_NR(VIDIOCSMICROCODE)] = "VIDIOCSMICROCODE",
+       [_IOC_NR(VIDIOCGVBIFMT)]    = "VIDIOCGVBIFMT",
+       [_IOC_NR(VIDIOCSVBIFMT)]    = "VIDIOCSVBIFMT"
+};
+#define V4L1_IOCTLS ARRAY_SIZE(v4l1_ioctls)
+#endif
+
+static const char *v4l2_ioctls[] = {
+       [_IOC_NR(VIDIOC_QUERYCAP)]         = "VIDIOC_QUERYCAP",
+       [_IOC_NR(VIDIOC_RESERVED)]         = "VIDIOC_RESERVED",
+       [_IOC_NR(VIDIOC_ENUM_FMT)]         = "VIDIOC_ENUM_FMT",
+       [_IOC_NR(VIDIOC_G_FMT)]            = "VIDIOC_G_FMT",
+       [_IOC_NR(VIDIOC_S_FMT)]            = "VIDIOC_S_FMT",
+       [_IOC_NR(VIDIOC_REQBUFS)]          = "VIDIOC_REQBUFS",
+       [_IOC_NR(VIDIOC_QUERYBUF)]         = "VIDIOC_QUERYBUF",
+       [_IOC_NR(VIDIOC_G_FBUF)]           = "VIDIOC_G_FBUF",
+       [_IOC_NR(VIDIOC_S_FBUF)]           = "VIDIOC_S_FBUF",
+       [_IOC_NR(VIDIOC_OVERLAY)]          = "VIDIOC_OVERLAY",
+       [_IOC_NR(VIDIOC_QBUF)]             = "VIDIOC_QBUF",
+       [_IOC_NR(VIDIOC_DQBUF)]            = "VIDIOC_DQBUF",
+       [_IOC_NR(VIDIOC_STREAMON)]         = "VIDIOC_STREAMON",
+       [_IOC_NR(VIDIOC_STREAMOFF)]        = "VIDIOC_STREAMOFF",
+       [_IOC_NR(VIDIOC_G_PARM)]           = "VIDIOC_G_PARM",
+       [_IOC_NR(VIDIOC_S_PARM)]           = "VIDIOC_S_PARM",
+       [_IOC_NR(VIDIOC_G_STD)]            = "VIDIOC_G_STD",
+       [_IOC_NR(VIDIOC_S_STD)]            = "VIDIOC_S_STD",
+       [_IOC_NR(VIDIOC_ENUMSTD)]          = "VIDIOC_ENUMSTD",
+       [_IOC_NR(VIDIOC_ENUMINPUT)]        = "VIDIOC_ENUMINPUT",
+       [_IOC_NR(VIDIOC_G_CTRL)]           = "VIDIOC_G_CTRL",
+       [_IOC_NR(VIDIOC_S_CTRL)]           = "VIDIOC_S_CTRL",
+       [_IOC_NR(VIDIOC_G_TUNER)]          = "VIDIOC_G_TUNER",
+       [_IOC_NR(VIDIOC_S_TUNER)]          = "VIDIOC_S_TUNER",
+       [_IOC_NR(VIDIOC_G_AUDIO)]          = "VIDIOC_G_AUDIO",
+       [_IOC_NR(VIDIOC_S_AUDIO)]          = "VIDIOC_S_AUDIO",
+       [_IOC_NR(VIDIOC_QUERYCTRL)]        = "VIDIOC_QUERYCTRL",
+       [_IOC_NR(VIDIOC_QUERYMENU)]        = "VIDIOC_QUERYMENU",
+       [_IOC_NR(VIDIOC_G_INPUT)]          = "VIDIOC_G_INPUT",
+       [_IOC_NR(VIDIOC_S_INPUT)]          = "VIDIOC_S_INPUT",
+       [_IOC_NR(VIDIOC_G_OUTPUT)]         = "VIDIOC_G_OUTPUT",
+       [_IOC_NR(VIDIOC_S_OUTPUT)]         = "VIDIOC_S_OUTPUT",
+       [_IOC_NR(VIDIOC_ENUMOUTPUT)]       = "VIDIOC_ENUMOUTPUT",
+       [_IOC_NR(VIDIOC_G_AUDOUT)]         = "VIDIOC_G_AUDOUT",
+       [_IOC_NR(VIDIOC_S_AUDOUT)]         = "VIDIOC_S_AUDOUT",
+       [_IOC_NR(VIDIOC_G_MODULATOR)]      = "VIDIOC_G_MODULATOR",
+       [_IOC_NR(VIDIOC_S_MODULATOR)]      = "VIDIOC_S_MODULATOR",
+       [_IOC_NR(VIDIOC_G_FREQUENCY)]      = "VIDIOC_G_FREQUENCY",
+       [_IOC_NR(VIDIOC_S_FREQUENCY)]      = "VIDIOC_S_FREQUENCY",
+       [_IOC_NR(VIDIOC_CROPCAP)]          = "VIDIOC_CROPCAP",
+       [_IOC_NR(VIDIOC_G_CROP)]           = "VIDIOC_G_CROP",
+       [_IOC_NR(VIDIOC_S_CROP)]           = "VIDIOC_S_CROP",
+       [_IOC_NR(VIDIOC_G_JPEGCOMP)]       = "VIDIOC_G_JPEGCOMP",
+       [_IOC_NR(VIDIOC_S_JPEGCOMP)]       = "VIDIOC_S_JPEGCOMP",
+       [_IOC_NR(VIDIOC_QUERYSTD)]         = "VIDIOC_QUERYSTD",
+       [_IOC_NR(VIDIOC_TRY_FMT)]          = "VIDIOC_TRY_FMT",
+       [_IOC_NR(VIDIOC_ENUMAUDIO)]        = "VIDIOC_ENUMAUDIO",
+       [_IOC_NR(VIDIOC_ENUMAUDOUT)]       = "VIDIOC_ENUMAUDOUT",
+       [_IOC_NR(VIDIOC_G_PRIORITY)]       = "VIDIOC_G_PRIORITY",
+       [_IOC_NR(VIDIOC_S_PRIORITY)]       = "VIDIOC_S_PRIORITY",
+       [_IOC_NR(VIDIOC_G_SLICED_VBI_CAP)] = "VIDIOC_G_SLICED_VBI_CAP",
+       [_IOC_NR(VIDIOC_LOG_STATUS)]       = "VIDIOC_LOG_STATUS",
+       [_IOC_NR(VIDIOC_G_EXT_CTRLS)]      = "VIDIOC_G_EXT_CTRLS",
+       [_IOC_NR(VIDIOC_S_EXT_CTRLS)]      = "VIDIOC_S_EXT_CTRLS",
+       [_IOC_NR(VIDIOC_TRY_EXT_CTRLS)]    = "VIDIOC_TRY_EXT_CTRLS",
+#if 1
+       [_IOC_NR(VIDIOC_ENUM_FRAMESIZES)]  = "VIDIOC_ENUM_FRAMESIZES",
+       [_IOC_NR(VIDIOC_ENUM_FRAMEINTERVALS)] = "VIDIOC_ENUM_FRAMEINTERVALS",
+       [_IOC_NR(VIDIOC_G_ENC_INDEX)]      = "VIDIOC_G_ENC_INDEX",
+       [_IOC_NR(VIDIOC_ENCODER_CMD)]      = "VIDIOC_ENCODER_CMD",
+       [_IOC_NR(VIDIOC_TRY_ENCODER_CMD)]  = "VIDIOC_TRY_ENCODER_CMD",
+
+       [_IOC_NR(VIDIOC_DBG_S_REGISTER)]   = "VIDIOC_DBG_S_REGISTER",
+       [_IOC_NR(VIDIOC_DBG_G_REGISTER)]   = "VIDIOC_DBG_G_REGISTER",
+
+       [_IOC_NR(VIDIOC_G_CHIP_IDENT)]     = "VIDIOC_G_CHIP_IDENT",
+       [_IOC_NR(VIDIOC_S_HW_FREQ_SEEK)]   = "VIDIOC_S_HW_FREQ_SEEK",
+#endif
+};
+#define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
+
+static const char *v4l2_int_ioctls[] = {
+#ifdef CONFIG_VIDEO_V4L1_COMPAT
+       [_IOC_NR(DECODER_GET_CAPABILITIES)]    = "DECODER_GET_CAPABILITIES",
+       [_IOC_NR(DECODER_GET_STATUS)]          = "DECODER_GET_STATUS",
+       [_IOC_NR(DECODER_SET_NORM)]            = "DECODER_SET_NORM",
+       [_IOC_NR(DECODER_SET_INPUT)]           = "DECODER_SET_INPUT",
+       [_IOC_NR(DECODER_SET_OUTPUT)]          = "DECODER_SET_OUTPUT",
+       [_IOC_NR(DECODER_ENABLE_OUTPUT)]       = "DECODER_ENABLE_OUTPUT",
+       [_IOC_NR(DECODER_SET_PICTURE)]         = "DECODER_SET_PICTURE",
+       [_IOC_NR(DECODER_SET_GPIO)]            = "DECODER_SET_GPIO",
+       [_IOC_NR(DECODER_INIT)]                = "DECODER_INIT",
+       [_IOC_NR(DECODER_SET_VBI_BYPASS)]      = "DECODER_SET_VBI_BYPASS",
+       [_IOC_NR(DECODER_DUMP)]                = "DECODER_DUMP",
+#endif
+       [_IOC_NR(AUDC_SET_RADIO)]              = "AUDC_SET_RADIO",
+
+       [_IOC_NR(TUNER_SET_TYPE_ADDR)]         = "TUNER_SET_TYPE_ADDR",
+       [_IOC_NR(TUNER_SET_STANDBY)]           = "TUNER_SET_STANDBY",
+       [_IOC_NR(TUNER_SET_CONFIG)]            = "TUNER_SET_CONFIG",
+
+       [_IOC_NR(VIDIOC_INT_S_TUNER_MODE)]     = "VIDIOC_INT_S_TUNER_MODE",
+       [_IOC_NR(VIDIOC_INT_RESET)]            = "VIDIOC_INT_RESET",
+       [_IOC_NR(VIDIOC_INT_AUDIO_CLOCK_FREQ)] = "VIDIOC_INT_AUDIO_CLOCK_FREQ",
+       [_IOC_NR(VIDIOC_INT_DECODE_VBI_LINE)]  = "VIDIOC_INT_DECODE_VBI_LINE",
+       [_IOC_NR(VIDIOC_INT_S_VBI_DATA)]       = "VIDIOC_INT_S_VBI_DATA",
+       [_IOC_NR(VIDIOC_INT_G_VBI_DATA)]       = "VIDIOC_INT_G_VBI_DATA",
+       [_IOC_NR(VIDIOC_INT_I2S_CLOCK_FREQ)]   = "VIDIOC_INT_I2S_CLOCK_FREQ",
+       [_IOC_NR(VIDIOC_INT_S_STANDBY)]        = "VIDIOC_INT_S_STANDBY",
+       [_IOC_NR(VIDIOC_INT_S_AUDIO_ROUTING)]  = "VIDIOC_INT_S_AUDIO_ROUTING",
+       [_IOC_NR(VIDIOC_INT_G_AUDIO_ROUTING)]  = "VIDIOC_INT_G_AUDIO_ROUTING",
+       [_IOC_NR(VIDIOC_INT_S_VIDEO_ROUTING)]  = "VIDIOC_INT_S_VIDEO_ROUTING",
+       [_IOC_NR(VIDIOC_INT_G_VIDEO_ROUTING)]  = "VIDIOC_INT_G_VIDEO_ROUTING",
+       [_IOC_NR(VIDIOC_INT_S_CRYSTAL_FREQ)]   = "VIDIOC_INT_S_CRYSTAL_FREQ",
+       [_IOC_NR(VIDIOC_INT_INIT)]             = "VIDIOC_INT_INIT",
+       [_IOC_NR(VIDIOC_INT_G_STD_OUTPUT)]     = "VIDIOC_INT_G_STD_OUTPUT",
+       [_IOC_NR(VIDIOC_INT_S_STD_OUTPUT)]     = "VIDIOC_INT_S_STD_OUTPUT",
+};
+#define V4L2_INT_IOCTLS ARRAY_SIZE(v4l2_int_ioctls)
+
+/* Common ioctl debug function. This function can be used by
+   external ioctl messages as well as internal V4L ioctl */
+void v4l_printk_ioctl(unsigned int cmd)
+{
+       char *dir, *type;
+
+       switch (_IOC_TYPE(cmd)) {
+       case 'd':
+               if (_IOC_NR(cmd) >= V4L2_INT_IOCTLS) {
+                       type = "v4l2_int";
+                       break;
+               }
+               printk("%s", v4l2_int_ioctls[_IOC_NR(cmd)]);
+               return;
+#ifdef CONFIG_VIDEO_V4L1_COMPAT
+       case 'v':
+               if (_IOC_NR(cmd) >= V4L1_IOCTLS) {
+                       type = "v4l1";
+                       break;
+               }
+               printk("%s", v4l1_ioctls[_IOC_NR(cmd)]);
+               return;
+#endif
+       case 'V':
+               if (_IOC_NR(cmd) >= V4L2_IOCTLS) {
+                       type = "v4l2";
+                       break;
+               }
+               printk("%s", v4l2_ioctls[_IOC_NR(cmd)]);
+               return;
+       default:
+               type = "unknown";
+       }
+
+       switch (_IOC_DIR(cmd)) {
+       case _IOC_NONE:              dir = "--"; break;
+       case _IOC_READ:              dir = "r-"; break;
+       case _IOC_WRITE:             dir = "-w"; break;
+       case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
+       default:                     dir = "*ERR*"; break;
+       }
+       printk("%s ioctl '%c', dir=%s, #%d (0x%08x)",
+               type, _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd);
+}
+EXPORT_SYMBOL(v4l_printk_ioctl);
+
+/*
+ * helper function -- handles userspace copying for ioctl arguments
+ */
+
+#ifdef __OLD_VIDIOC_
+static unsigned int
+video_fix_command(unsigned int cmd)
+{
+       switch (cmd) {
+       case VIDIOC_OVERLAY_OLD:
+               cmd = VIDIOC_OVERLAY;
+               break;
+       case VIDIOC_S_PARM_OLD:
+               cmd = VIDIOC_S_PARM;
+               break;
+       case VIDIOC_S_CTRL_OLD:
+               cmd = VIDIOC_S_CTRL;
+               break;
+       case VIDIOC_G_AUDIO_OLD:
+               cmd = VIDIOC_G_AUDIO;
+               break;
+       case VIDIOC_G_AUDOUT_OLD:
+               cmd = VIDIOC_G_AUDOUT;
+               break;
+       case VIDIOC_CROPCAP_OLD:
+               cmd = VIDIOC_CROPCAP;
+               break;
+       }
+       return cmd;
+}
+#endif
+
+/*
+ * Obsolete usercopy function - Should be removed soon
+ */
+int
+video_usercopy(struct inode *inode, struct file *file,
+              unsigned int cmd, unsigned long arg,
+              int (*func)(struct inode *inode, struct file *file,
+                          unsigned int cmd, void *arg))
+{
+       char    sbuf[128];
+       void    *mbuf = NULL;
+       void    *parg = NULL;
+       int     err  = -EINVAL;
+       int     is_ext_ctrl;
+       size_t  ctrls_size = 0;
+       void __user *user_ptr = NULL;
+
+#ifdef __OLD_VIDIOC_
+       cmd = video_fix_command(cmd);
+#endif
+       is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS ||
+                      cmd == VIDIOC_TRY_EXT_CTRLS);
+
+       /*  Copy arguments into temp kernel buffer  */
+       switch (_IOC_DIR(cmd)) {
+       case _IOC_NONE:
+               parg = NULL;
+               break;
+       case _IOC_READ:
+       case _IOC_WRITE:
+       case (_IOC_WRITE | _IOC_READ):
+               if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
+                       parg = sbuf;
+               } else {
+                       /* too big to allocate from stack */
+                       mbuf = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL);
+                       if (NULL == mbuf)
+                               return -ENOMEM;
+                       parg = mbuf;
+               }
+
+               err = -EFAULT;
+               if (_IOC_DIR(cmd) & _IOC_WRITE)
+                       if (copy_from_user(parg, (void __user *)arg, _IOC_SIZE(cmd)))
+                               goto out;
+               break;
+       }
+       if (is_ext_ctrl) {
+               struct v4l2_ext_controls *p = parg;
+
+               /* In case of an error, tell the caller that it wasn't
+                  a specific control that caused it. */
+               p->error_idx = p->count;
+               user_ptr = (void __user *)p->controls;
+               if (p->count) {
+                       ctrls_size = sizeof(struct v4l2_ext_control) * p->count;
+                       /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
+                       mbuf = kmalloc(ctrls_size, GFP_KERNEL);
+                       err = -ENOMEM;
+                       if (NULL == mbuf)
+                               goto out_ext_ctrl;
+                       err = -EFAULT;
+                       if (copy_from_user(mbuf, user_ptr, ctrls_size))
+                               goto out_ext_ctrl;
+                       p->controls = mbuf;
+               }
+       }
+
+       /* call driver */
+       err = func(inode, file, cmd, parg);
+       if (err == -ENOIOCTLCMD)
+               err = -EINVAL;
+       if (is_ext_ctrl) {
+               struct v4l2_ext_controls *p = parg;
+
+               p->controls = (void *)user_ptr;
+               if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size))
+                       err = -EFAULT;
+               goto out_ext_ctrl;
+       }
+       if (err < 0)
+               goto out;
+
+out_ext_ctrl:
+       /*  Copy results into user buffer  */
+       switch (_IOC_DIR(cmd)) {
+       case _IOC_READ:
+       case (_IOC_WRITE | _IOC_READ):
+               if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
+                       err = -EFAULT;
+               break;
+       }
+
+out:
+       kfree(mbuf);
+       return err;
+}
+EXPORT_SYMBOL(video_usercopy);
+
+static void dbgbuf(unsigned int cmd, struct video_device *vfd,
+                                       struct v4l2_buffer *p)
+{
+       struct v4l2_timecode *tc = &p->timecode;
+
+       dbgarg(cmd, "%02ld:%02d:%02d.%08ld index=%d, type=%s, "
+               "bytesused=%d, flags=0x%08d, "
+               "field=%0d, sequence=%d, memory=%s, offset/userptr=0x%08lx, length=%d\n",
+                       p->timestamp.tv_sec / 3600,
+                       (int)(p->timestamp.tv_sec / 60) % 60,
+                       (int)(p->timestamp.tv_sec % 60),
+                       p->timestamp.tv_usec,
+                       p->index,
+                       prt_names(p->type, v4l2_type_names),
+                       p->bytesused, p->flags,
+                       p->field, p->sequence,
+                       prt_names(p->memory, v4l2_memory_names),
+                       p->m.userptr, p->length);
+       dbgarg2("timecode=%02d:%02d:%02d type=%d, "
+               "flags=0x%08d, frames=%d, userbits=0x%08x\n",
+                       tc->hours, tc->minutes, tc->seconds,
+                       tc->type, tc->flags, tc->frames, *(__u32 *)tc->userbits);
+}
+
+static inline void dbgrect(struct video_device *vfd, char *s,
+                                                       struct v4l2_rect *r)
+{
+       dbgarg2("%sRect start at %dx%d, size=%dx%d\n", s, r->left, r->top,
+                                               r->width, r->height);
+};
+
+static inline void v4l_print_pix_fmt(struct video_device *vfd,
+                                               struct v4l2_pix_format *fmt)
+{
+       dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
+               "bytesperline=%d sizeimage=%d, colorspace=%d\n",
+               fmt->width, fmt->height,
+               (fmt->pixelformat & 0xff),
+               (fmt->pixelformat >>  8) & 0xff,
+               (fmt->pixelformat >> 16) & 0xff,
+               (fmt->pixelformat >> 24) & 0xff,
+               prt_names(fmt->field, v4l2_field_names),
+               fmt->bytesperline, fmt->sizeimage, fmt->colorspace);
+};
+
+static inline void v4l_print_ext_ctrls(unsigned int cmd,
+       struct video_device *vfd, struct v4l2_ext_controls *c, int show_vals)
+{
+       __u32 i;
+
+       if (!(vfd->debug & V4L2_DEBUG_IOCTL_ARG))
+               return;
+       dbgarg(cmd, "");
+       printk(KERN_CONT "class=0x%x", c->ctrl_class);
+       for (i = 0; i < c->count; i++) {
+               if (show_vals)
+                       printk(KERN_CONT " id/val=0x%x/0x%x",
+                               c->controls[i].id, c->controls[i].value);
+               else
+                       printk(KERN_CONT " id=0x%x", c->controls[i].id);
+       }
+       printk(KERN_CONT "\n");
+};
+
+static inline int check_ext_ctrls(struct v4l2_ext_controls *c, int allow_priv)
+{
+       __u32 i;
+
+       /* zero the reserved fields */
+       c->reserved[0] = c->reserved[1] = 0;
+       for (i = 0; i < c->count; i++) {
+               c->controls[i].reserved2[0] = 0;
+               c->controls[i].reserved2[1] = 0;
+       }
+       /* V4L2_CID_PRIVATE_BASE cannot be used as control class
+          when using extended controls.
+          Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL
+          is it allowed for backwards compatibility.
+        */
+       if (!allow_priv && c->ctrl_class == V4L2_CID_PRIVATE_BASE)
+               return 0;
+       /* Check that all controls are from the same control class. */
+       for (i = 0; i < c->count; i++) {
+               if (V4L2_CTRL_ID2CLASS(c->controls[i].id) != c->ctrl_class) {
+                       c->error_idx = i;
+                       return 0;
+               }
+       }
+       return 1;
+}
+
+static int check_fmt(struct video_device *vfd, enum v4l2_buf_type type)
+{
+       switch (type) {
+       case V4L2_BUF_TYPE_VIDEO_CAPTURE:
+               if (vfd->vidioc_try_fmt_vid_cap)
+                       return 0;
+               break;
+       case V4L2_BUF_TYPE_VIDEO_OVERLAY:
+               if (vfd->vidioc_try_fmt_vid_overlay)
+                       return 0;
+               break;
+       case V4L2_BUF_TYPE_VIDEO_OUTPUT:
+               if (vfd->vidioc_try_fmt_vid_out)
+                       return 0;
+               break;
+       case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
+               if (vfd->vidioc_try_fmt_vid_out_overlay)
+                       return 0;
+               break;
+       case V4L2_BUF_TYPE_VBI_CAPTURE:
+               if (vfd->vidioc_try_fmt_vbi_cap)
+                       return 0;
+               break;
+       case V4L2_BUF_TYPE_VBI_OUTPUT:
+               if (vfd->vidioc_try_fmt_vbi_out)
+                       return 0;
+               break;
+       case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
+               if (vfd->vidioc_try_fmt_sliced_vbi_cap)
+                       return 0;
+               break;
+       case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
+               if (vfd->vidioc_try_fmt_sliced_vbi_out)
+                       return 0;
+               break;
+       case V4L2_BUF_TYPE_PRIVATE:
+               if (vfd->vidioc_try_fmt_type_private)
+                       return 0;
+               break;
+       }
+       return -EINVAL;
+}
+
+static int __video_do_ioctl(struct inode *inode, struct file *file,
+               unsigned int cmd, void *arg)
+{
+       struct video_device *vfd = video_devdata(file);
+       void                 *fh = file->private_data;
+       int                  ret = -EINVAL;
+
+       if ((vfd->debug & V4L2_DEBUG_IOCTL) &&
+                               !(vfd->debug & V4L2_DEBUG_IOCTL_ARG)) {
+               v4l_print_ioctl(vfd->name, cmd);
+               printk(KERN_CONT "\n");
+       }
+
+#ifdef CONFIG_VIDEO_V4L1_COMPAT
+       /***********************************************************
+        Handles calls to the obsoleted V4L1 API
+        Due to the nature of VIDIOCGMBUF, each driver that supports
+        V4L1 should implement its own handler for this ioctl.
+        ***********************************************************/
+
+       /* --- streaming capture ------------------------------------- */
+       if (cmd == VIDIOCGMBUF) {
+               struct video_mbuf *p = arg;
+
+               memset(p, 0, sizeof(*p));
+
+               if (!vfd->vidiocgmbuf)
+                       return ret;
+               ret = vfd->vidiocgmbuf(file, fh, p);
+               if (!ret)
+                       dbgarg(cmd, "size=%d, frames=%d, offsets=0x%08lx\n",
+                                               p->size, p->frames,
+                                               (unsigned long)p->offsets);
+               return ret;
+       }
+
+       /********************************************************
+        All other V4L1 calls are handled by v4l1_compat module.
+        Those calls will be translated into V4L2 calls, and
+        __video_do_ioctl will be called again, with one or more
+        V4L2 ioctls.
+        ********************************************************/
+       if (_IOC_TYPE(cmd) == 'v')
+               return v4l_compat_translate_ioctl(inode, file, cmd, arg,
+                                               __video_do_ioctl);
+#endif
+
+       switch (cmd) {
+       /* --- capabilities ------------------------------------------ */
+       case VIDIOC_QUERYCAP:
+       {
+               struct v4l2_capability *cap = (struct v4l2_capability *)arg;
+               memset(cap, 0, sizeof(*cap));
+
+               if (!vfd->vidioc_querycap)
+                       break;
+
+               ret = vfd->vidioc_querycap(file, fh, cap);
+               if (!ret)
+                       dbgarg(cmd, "driver=%s, card=%s, bus=%s, "
+                                       "version=0x%08x, "
+                                       "capabilities=0x%08x\n",
+                                       cap->driver, cap->card, cap->bus_info,
+                                       cap->version,
+                                       cap->capabilities);
+               break;
+       }
+
+       /* --- priority ------------------------------------------ */
+       case VIDIOC_G_PRIORITY:
+       {
+               enum v4l2_priority *p = arg;
+
+               if (!vfd->vidioc_g_priority)
+                       break;
+               ret = vfd->vidioc_g_priority(file, fh, p);
+               if (!ret)
+                       dbgarg(cmd, "priority is %d\n", *p);
+               break;
+       }
+       case VIDIOC_S_PRIORITY:
+       {
+               enum v4l2_priority *p = arg;
+
+               if (!vfd->vidioc_s_priority)
+                       break;
+               dbgarg(cmd, "setting priority to %d\n", *p);
+               ret = vfd->vidioc_s_priority(file, fh, *p);
+               break;
+       }
+
+       /* --- capture ioctls ---------------------------------------- */
+       case VIDIOC_ENUM_FMT:
+       {
+               struct v4l2_fmtdesc *f = arg;
+               enum v4l2_buf_type type;
+               unsigned int index;
+
+               index = f->index;
+               type  = f->type;
+               memset(f, 0, sizeof(*f));
+               f->index = index;
+               f->type  = type;
+
+               switch (type) {
+               case V4L2_BUF_TYPE_VIDEO_CAPTURE:
+                       if (vfd->vidioc_enum_fmt_vid_cap)
+                               ret = vfd->vidioc_enum_fmt_vid_cap(file, fh, f);
+                       break;
+               case V4L2_BUF_TYPE_VIDEO_OVERLAY:
+                       if (vfd->vidioc_enum_fmt_vid_overlay)
+                               ret = vfd->vidioc_enum_fmt_vid_overlay(file,
+                                       fh, f);
+                       break;
+#if 1
+               /* V4L2_BUF_TYPE_VBI_CAPTURE should not support VIDIOC_ENUM_FMT
+                * according to the spec. The bttv and saa7134 drivers support
+                * it though, so just warn that this is deprecated and will be
+                * removed in the near future. */
+               case V4L2_BUF_TYPE_VBI_CAPTURE:
+                       if (vfd->vidioc_enum_fmt_vbi_cap) {
+                               printk(KERN_WARNING "vidioc_enum_fmt_vbi_cap will be removed in 2.6.28!\n");
+                               ret = vfd->vidioc_enum_fmt_vbi_cap(file, fh, f);
+                       }
+                       break;
+#endif
+               case V4L2_BUF_TYPE_VIDEO_OUTPUT:
+                       if (vfd->vidioc_enum_fmt_vid_out)
+                               ret = vfd->vidioc_enum_fmt_vid_out(file, fh, f);
+                       break;
+               case V4L2_BUF_TYPE_PRIVATE:
+                       if (vfd->vidioc_enum_fmt_type_private)
+                               ret = vfd->vidioc_enum_fmt_type_private(file,
+                                                               fh, f);
+                       break;
+               default:
+                       break;
+               }
+               if (!ret)
+                       dbgarg(cmd, "index=%d, type=%d, flags=%d, "
+                               "pixelformat=%c%c%c%c, description='%s'\n",
+                               f->index, f->type, f->flags,
+                               (f->pixelformat & 0xff),
+                               (f->pixelformat >>  8) & 0xff,
+                               (f->pixelformat >> 16) & 0xff,
+                               (f->pixelformat >> 24) & 0xff,
+                               f->description);
+               break;
+       }
+       case VIDIOC_G_FMT:
+       {
+               struct v4l2_format *f = (struct v4l2_format *)arg;
+
+               memset(f->fmt.raw_data, 0, sizeof(f->fmt.raw_data));
+
+               /* FIXME: Should be one dump per type */
+               dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
+
+               switch (f->type) {
+               case V4L2_BUF_TYPE_VIDEO_CAPTURE:
+                       if (vfd->vidioc_g_fmt_vid_cap)
+                               ret = vfd->vidioc_g_fmt_vid_cap(file, fh, f);
+                       if (!ret)
+                               v4l_print_pix_fmt(vfd, &f->fmt.pix);
+                       break;
+               case V4L2_BUF_TYPE_VIDEO_OVERLAY:
+                       if (vfd->vidioc_g_fmt_vid_overlay)
+                               ret = vfd->vidioc_g_fmt_vid_overlay(file,
+                                                                   fh, f);
+                       break;
+               case V4L2_BUF_TYPE_VIDEO_OUTPUT:
+                       if (vfd->vidioc_g_fmt_vid_out)
+                               ret = vfd->vidioc_g_fmt_vid_out(file, fh, f);
+                       if (!ret)
+                               v4l_print_pix_fmt(vfd, &f->fmt.pix);
+                       break;
+               case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
+                       if (vfd->vidioc_g_fmt_vid_out_overlay)
+                               ret = vfd->vidioc_g_fmt_vid_out_overlay(file,
+                                      fh, f);
+                       break;
+               case V4L2_BUF_TYPE_VBI_CAPTURE:
+                       if (vfd->vidioc_g_fmt_vbi_cap)
+                               ret = vfd->vidioc_g_fmt_vbi_cap(file, fh, f);
+                       break;
+               case V4L2_BUF_TYPE_VBI_OUTPUT:
+                       if (vfd->vidioc_g_fmt_vbi_out)
+                               ret = vfd->vidioc_g_fmt_vbi_out(file, fh, f);
+                       break;
+               case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
+                       if (vfd->vidioc_g_fmt_sliced_vbi_cap)
+                               ret = vfd->vidioc_g_fmt_sliced_vbi_cap(file,
+                                                                       fh, f);
+                       break;
+               case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
+                       if (vfd->vidioc_g_fmt_sliced_vbi_out)
+                               ret = vfd->vidioc_g_fmt_sliced_vbi_out(file,
+                                                                       fh, f);
+                       break;
+               case V4L2_BUF_TYPE_PRIVATE:
+                       if (vfd->vidioc_g_fmt_type_private)
+                               ret = vfd->vidioc_g_fmt_type_private(file,
+                                                               fh, f);
+                       break;
+               }
+
+               break;
+       }
+       case VIDIOC_S_FMT:
+       {
+               struct v4l2_format *f = (struct v4l2_format *)arg;
+
+               /* FIXME: Should be one dump per type */
+               dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
+
+               switch (f->type) {
+               case V4L2_BUF_TYPE_VIDEO_CAPTURE:
+                       v4l_print_pix_fmt(vfd, &f->fmt.pix);
+                       if (vfd->vidioc_s_fmt_vid_cap)
+                               ret = vfd->vidioc_s_fmt_vid_cap(file, fh, f);
+                       break;
+               case V4L2_BUF_TYPE_VIDEO_OVERLAY:
+                       if (vfd->vidioc_s_fmt_vid_overlay)
+                               ret = vfd->vidioc_s_fmt_vid_overlay(file,
+                                                                   fh, f);
+                       break;
+               case V4L2_BUF_TYPE_VIDEO_OUTPUT:
+                       v4l_print_pix_fmt(vfd, &f->fmt.pix);
+                       if (vfd->vidioc_s_fmt_vid_out)
+                               ret = vfd->vidioc_s_fmt_vid_out(file, fh, f);
+                       break;
+               case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
+                       if (vfd->vidioc_s_fmt_vid_out_overlay)
+                               ret = vfd->vidioc_s_fmt_vid_out_overlay(file,
+                                       fh, f);
+                       break;
+               case V4L2_BUF_TYPE_VBI_CAPTURE:
+                       if (vfd->vidioc_s_fmt_vbi_cap)
+                               ret = vfd->vidioc_s_fmt_vbi_cap(file, fh, f);
+                       break;
+               case V4L2_BUF_TYPE_VBI_OUTPUT:
+                       if (vfd->vidioc_s_fmt_vbi_out)
+                               ret = vfd->vidioc_s_fmt_vbi_out(file, fh, f);
+                       break;
+               case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
+                       if (vfd->vidioc_s_fmt_sliced_vbi_cap)
+                               ret = vfd->vidioc_s_fmt_sliced_vbi_cap(file,
+                                                                       fh, f);
+                       break;
+               case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
+                       if (vfd->vidioc_s_fmt_sliced_vbi_out)
+                               ret = vfd->vidioc_s_fmt_sliced_vbi_out(file,
+                                                                       fh, f);
+                       break;
+               case V4L2_BUF_TYPE_PRIVATE:
+                       if (vfd->vidioc_s_fmt_type_private)
+                               ret = vfd->vidioc_s_fmt_type_private(file,
+                                                               fh, f);
+                       break;
+               }
+               break;
+       }
+       case VIDIOC_TRY_FMT:
+       {
+               struct v4l2_format *f = (struct v4l2_format *)arg;
+
+               /* FIXME: Should be one dump per type */
+               dbgarg(cmd, "type=%s\n", prt_names(f->type,
+                                               v4l2_type_names));
+               switch (f->type) {
+               case V4L2_BUF_TYPE_VIDEO_CAPTURE:
+                       if (vfd->vidioc_try_fmt_vid_cap)
+                               ret = vfd->vidioc_try_fmt_vid_cap(file, fh, f);
+                       if (!ret)
+                               v4l_print_pix_fmt(vfd, &f->fmt.pix);
+                       break;
+               case V4L2_BUF_TYPE_VIDEO_OVERLAY:
+                       if (vfd->vidioc_try_fmt_vid_overlay)
+                               ret = vfd->vidioc_try_fmt_vid_overlay(file,
+                                       fh, f);
+                       break;
+               case V4L2_BUF_TYPE_VIDEO_OUTPUT:
+                       if (vfd->vidioc_try_fmt_vid_out)
+                               ret = vfd->vidioc_try_fmt_vid_out(file, fh, f);
+                       if (!ret)
+                               v4l_print_pix_fmt(vfd, &f->fmt.pix);
+                       break;
+               case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
+                       if (vfd->vidioc_try_fmt_vid_out_overlay)
+                               ret = vfd->vidioc_try_fmt_vid_out_overlay(file,
+                                      fh, f);
+                       break;
+               case V4L2_BUF_TYPE_VBI_CAPTURE:
+                       if (vfd->vidioc_try_fmt_vbi_cap)
+                               ret = vfd->vidioc_try_fmt_vbi_cap(file, fh, f);
+                       break;
+               case V4L2_BUF_TYPE_VBI_OUTPUT:
+                       if (vfd->vidioc_try_fmt_vbi_out)
+                               ret = vfd->vidioc_try_fmt_vbi_out(file, fh, f);
+                       break;
+               case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
+                       if (vfd->vidioc_try_fmt_sliced_vbi_cap)
+                               ret = vfd->vidioc_try_fmt_sliced_vbi_cap(file,
+                                                               fh, f);
+                       break;
+               case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
+                       if (vfd->vidioc_try_fmt_sliced_vbi_out)
+                               ret = vfd->vidioc_try_fmt_sliced_vbi_out(file,
+                                                               fh, f);
+                       break;
+               case V4L2_BUF_TYPE_PRIVATE:
+                       if (vfd->vidioc_try_fmt_type_private)
+                               ret = vfd->vidioc_try_fmt_type_private(file,
+                                                               fh, f);
+                       break;
+               }
+
+               break;
+       }
+       /* FIXME: Those buf reqs could be handled here,
+          with some changes on videobuf to allow its header to be included at
+          videodev2.h or being merged at videodev2.
+        */
+       case VIDIOC_REQBUFS:
+       {
+               struct v4l2_requestbuffers *p = arg;
+
+               if (!vfd->vidioc_reqbufs)
+                       break;
+               ret = check_fmt(vfd, p->type);
+               if (ret)
+                       break;
+
+               ret = vfd->vidioc_reqbufs(file, fh, p);
+               dbgarg(cmd, "count=%d, type=%s, memory=%s\n",
+                               p->count,
+                               prt_names(p->type, v4l2_type_names),
+                               prt_names(p->memory, v4l2_memory_names));
+               break;
+       }
+       case VIDIOC_QUERYBUF:
+       {
+               struct v4l2_buffer *p = arg;
+
+               if (!vfd->vidioc_querybuf)
+                       break;
+               ret = check_fmt(vfd, p->type);
+               if (ret)
+                       break;
+
+               ret = vfd->vidioc_querybuf(file, fh, p);
+               if (!ret)
+                       dbgbuf(cmd, vfd, p);
+               break;
+       }
+       case VIDIOC_QBUF:
+       {
+               struct v4l2_buffer *p = arg;
+
+               if (!vfd->vidioc_qbuf)
+                       break;
+               ret = check_fmt(vfd, p->type);
+               if (ret)
+                       break;
+
+               ret = vfd->vidioc_qbuf(file, fh, p);
+               if (!ret)
+                       dbgbuf(cmd, vfd, p);
+               break;
+       }
+       case VIDIOC_DQBUF:
+       {
+               struct v4l2_buffer *p = arg;
+
+               if (!vfd->vidioc_dqbuf)
+                       break;
+               ret = check_fmt(vfd, p->type);
+               if (ret)
+                       break;
+
+               ret = vfd->vidioc_dqbuf(file, fh, p);
+               if (!ret)
+                       dbgbuf(cmd, vfd, p);
+               break;
+       }
+       case VIDIOC_OVERLAY:
+       {
+               int *i = arg;
+
+               if (!vfd->vidioc_overlay)
+                       break;
+               dbgarg(cmd, "value=%d\n", *i);
+               ret = vfd->vidioc_overlay(file, fh, *i);
+               break;
+       }
+       case VIDIOC_G_FBUF:
+       {
+               struct v4l2_framebuffer *p = arg;
+
+               if (!vfd->vidioc_g_fbuf)
+                       break;
+               ret = vfd->vidioc_g_fbuf(file, fh, arg);
+               if (!ret) {
+                       dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
+                                       p->capability, p->flags,
+                                       (unsigned long)p->base);
+                       v4l_print_pix_fmt(vfd, &p->fmt);
+               }
+               break;
+       }
+       case VIDIOC_S_FBUF:
+       {
+               struct v4l2_framebuffer *p = arg;
+
+               if (!vfd->vidioc_s_fbuf)
+                       break;
+               dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
+                       p->capability, p->flags, (unsigned long)p->base);
+               v4l_print_pix_fmt(vfd, &p->fmt);
+               ret = vfd->vidioc_s_fbuf(file, fh, arg);
+               break;
+       }
+       case VIDIOC_STREAMON:
+       {
+               enum v4l2_buf_type i = *(int *)arg;
+
+               if (!vfd->vidioc_streamon)
+                       break;
+               dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
+               ret = vfd->vidioc_streamon(file, fh, i);
+               break;
+       }
+       case VIDIOC_STREAMOFF:
+       {
+               enum v4l2_buf_type i = *(int *)arg;
+
+               if (!vfd->vidioc_streamoff)
+                       break;
+               dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
+               ret = vfd->vidioc_streamoff(file, fh, i);
+               break;
+       }
+       /* ---------- tv norms ---------- */
+       case VIDIOC_ENUMSTD:
+       {
+               struct v4l2_standard *p = arg;
+               v4l2_std_id id = vfd->tvnorms, curr_id = 0;
+               unsigned int index = p->index, i, j = 0;
+               const char *descr = "";
+
+               /* Return norm array in a canonical way */
+               for (i = 0; i <= index && id; i++) {
+                       /* last std value in the standards array is 0, so this
+                          while always ends there since (id & 0) == 0. */
+                       while ((id & standards[j].std) != standards[j].std)
+                               j++;
+                       curr_id = standards[j].std;
+                       descr = standards[j].descr;
+                       j++;
+                       if (curr_id == 0)
+                               break;
+                       if (curr_id != V4L2_STD_PAL &&
+                           curr_id != V4L2_STD_SECAM &&
+                           curr_id != V4L2_STD_NTSC)
+                               id &= ~curr_id;
+               }
+               if (i <= index)
+                       return -EINVAL;
+
+               v4l2_video_std_construct(p, curr_id, descr);
+               p->index = index;
+
+               dbgarg(cmd, "index=%d, id=0x%Lx, name=%s, fps=%d/%d, "
+                               "framelines=%d\n", p->index,
+                               (unsigned long long)p->id, p->name,
+                               p->frameperiod.numerator,
+                               p->frameperiod.denominator,
+                               p->framelines);
+
+               ret = 0;
+               break;
+       }
+       case VIDIOC_G_STD:
+       {
+               v4l2_std_id *id = arg;
+
+               ret = 0;
+               /* Calls the specific handler */
+               if (vfd->vidioc_g_std)
+                       ret = vfd->vidioc_g_std(file, fh, id);
+               else
+                       *id = vfd->current_norm;
+
+               if (!ret)
+                       dbgarg(cmd, "std=0x%08Lx\n", (long long unsigned)*id);
+               break;
+       }
+       case VIDIOC_S_STD:
+       {
+               v4l2_std_id *id = arg, norm;
+
+               dbgarg(cmd, "std=%08Lx\n", (long long unsigned)*id);
+
+               norm = (*id) & vfd->tvnorms;
+               if (vfd->tvnorms && !norm)      /* Check if std is supported */
+                       break;
+
+               /* Calls the specific handler */
+               if (vfd->vidioc_s_std)
+                       ret = vfd->vidioc_s_std(file, fh, &norm);
+               else
+                       ret = -EINVAL;
+
+               /* Updates standard information */
+               if (ret >= 0)
+                       vfd->current_norm = norm;
+               break;
+       }
+       case VIDIOC_QUERYSTD:
+       {
+               v4l2_std_id *p = arg;
+
+               if (!vfd->vidioc_querystd)
+                       break;
+               ret = vfd->vidioc_querystd(file, fh, arg);
+               if (!ret)
+                       dbgarg(cmd, "detected std=%08Lx\n",
+                                               (unsigned long long)*p);
+               break;
+       }
+       /* ------ input switching ---------- */
+       /* FIXME: Inputs can be handled inside videodev2 */
+       case VIDIOC_ENUMINPUT:
+       {
+               struct v4l2_input *p = arg;
+               int i = p->index;
+
+               if (!vfd->vidioc_enum_input)
+                       break;
+               memset(p, 0, sizeof(*p));
+               p->index = i;
+
+               ret = vfd->vidioc_enum_input(file, fh, p);
+               if (!ret)
+                       dbgarg(cmd, "index=%d, name=%s, type=%d, "
+                               "audioset=%d, "
+                               "tuner=%d, std=%08Lx, status=%d\n",
+                               p->index, p->name, p->type, p->audioset,
+                               p->tuner,
+                               (unsigned long long)p->std,
+                               p->status);
+               break;
+       }
+       case VIDIOC_G_INPUT:
+       {
+               unsigned int *i = arg;
+
+               if (!vfd->vidioc_g_input)
+                       break;
+               ret = vfd->vidioc_g_input(file, fh, i);
+               if (!ret)
+                       dbgarg(cmd, "value=%d\n", *i);
+               break;
+       }
+       case VIDIOC_S_INPUT:
+       {
+               unsigned int *i = arg;
+
+               if (!vfd->vidioc_s_input)
+                       break;
+               dbgarg(cmd, "value=%d\n", *i);
+               ret = vfd->vidioc_s_input(file, fh, *i);
+               break;
+       }
+
+       /* ------ output switching ---------- */
+       case VIDIOC_ENUMOUTPUT:
+       {
+               struct v4l2_output *p = arg;
+               int i = p->index;
+
+               if (!vfd->vidioc_enum_output)
+                       break;
+               memset(p, 0, sizeof(*p));
+               p->index = i;
+
+               ret = vfd->vidioc_enum_output(file, fh, p);
+               if (!ret)
+                       dbgarg(cmd, "index=%d, name=%s, type=%d, "
+                               "audioset=0x%x, "
+                               "modulator=%d, std=0x%08Lx\n",
+                               p->index, p->name, p->type, p->audioset,
+                               p->modulator, (unsigned long long)p->std);
+               break;
+       }
+       case VIDIOC_G_OUTPUT:
+       {
+               unsigned int *i = arg;
+
+               if (!vfd->vidioc_g_output)
+                       break;
+               ret = vfd->vidioc_g_output(file, fh, i);
+               if (!ret)
+                       dbgarg(cmd, "value=%d\n", *i);
+               break;
+       }
+       case VIDIOC_S_OUTPUT:
+       {
+               unsigned int *i = arg;
+
+               if (!vfd->vidioc_s_output)
+                       break;
+               dbgarg(cmd, "value=%d\n", *i);
+               ret = vfd->vidioc_s_output(file, fh, *i);
+               break;
+       }
+
+       /* --- controls ---------------------------------------------- */
+       case VIDIOC_QUERYCTRL:
+       {
+               struct v4l2_queryctrl *p = arg;
+
+               if (!vfd->vidioc_queryctrl)
+                       break;
+               ret = vfd->vidioc_queryctrl(file, fh, p);
+               if (!ret)
+                       dbgarg(cmd, "id=0x%x, type=%d, name=%s, min/max=%d/%d, "
+                                       "step=%d, default=%d, flags=0x%08x\n",
+                                       p->id, p->type, p->name,
+                                       p->minimum, p->maximum,
+                                       p->step, p->default_value, p->flags);
+               else
+                       dbgarg(cmd, "id=0x%x\n", p->id);
+               break;
+       }
+       case VIDIOC_G_CTRL:
+       {
+               struct v4l2_control *p = arg;
+
+               if (vfd->vidioc_g_ctrl)
+                       ret = vfd->vidioc_g_ctrl(file, fh, p);
+               else if (vfd->vidioc_g_ext_ctrls) {
+                       struct v4l2_ext_controls ctrls;
+                       struct v4l2_ext_control ctrl;
+
+                       ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
+                       ctrls.count = 1;
+                       ctrls.controls = &ctrl;
+                       ctrl.id = p->id;
+                       ctrl.value = p->value;
+                       if (check_ext_ctrls(&ctrls, 1)) {
+                               ret = vfd->vidioc_g_ext_ctrls(file, fh, &ctrls);
+                               if (ret == 0)
+                                       p->value = ctrl.value;
+                       }
+               } else
+                       break;
+               if (!ret)
+                       dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
+               else
+                       dbgarg(cmd, "id=0x%x\n", p->id);
+               break;
+       }
+       case VIDIOC_S_CTRL:
+       {
+               struct v4l2_control *p = arg;
+               struct v4l2_ext_controls ctrls;
+               struct v4l2_ext_control ctrl;
+
+               if (!vfd->vidioc_s_ctrl && !vfd->vidioc_s_ext_ctrls)
+                       break;
+
+               dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
+
+               if (vfd->vidioc_s_ctrl) {
+                       ret = vfd->vidioc_s_ctrl(file, fh, p);
+                       break;
+               }
+               if (!vfd->vidioc_s_ext_ctrls)
+                       break;
+
+               ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
+               ctrls.count = 1;
+               ctrls.controls = &ctrl;
+               ctrl.id = p->id;
+               ctrl.value = p->value;
+               if (check_ext_ctrls(&ctrls, 1))
+                       ret = vfd->vidioc_s_ext_ctrls(file, fh, &ctrls);
+               break;
+       }
+       case VIDIOC_G_EXT_CTRLS:
+       {
+               struct v4l2_ext_controls *p = arg;
+
+               p->error_idx = p->count;
+               if (!vfd->vidioc_g_ext_ctrls)
+                       break;
+               if (check_ext_ctrls(p, 0))
+                       ret = vfd->vidioc_g_ext_ctrls(file, fh, p);
+               v4l_print_ext_ctrls(cmd, vfd, p, !ret);
+               break;
+       }
+       case VIDIOC_S_EXT_CTRLS:
+       {
+               struct v4l2_ext_controls *p = arg;
+
+               p->error_idx = p->count;
+               if (!vfd->vidioc_s_ext_ctrls)
+                       break;
+               v4l_print_ext_ctrls(cmd, vfd, p, 1);
+               if (check_ext_ctrls(p, 0))
+                       ret = vfd->vidioc_s_ext_ctrls(file, fh, p);
+               break;
+       }
+       case VIDIOC_TRY_EXT_CTRLS:
+       {
+               struct v4l2_ext_controls *p = arg;
+
+               p->error_idx = p->count;
+               if (!vfd->vidioc_try_ext_ctrls)
+                       break;
+               v4l_print_ext_ctrls(cmd, vfd, p, 1);
+               if (check_ext_ctrls(p, 0))
+                       ret = vfd->vidioc_try_ext_ctrls(file, fh, p);
+               break;
+       }
+       case VIDIOC_QUERYMENU:
+       {
+               struct v4l2_querymenu *p = arg;
+
+               if (!vfd->vidioc_querymenu)
+                       break;
+               ret = vfd->vidioc_querymenu(file, fh, p);
+               if (!ret)
+                       dbgarg(cmd, "id=0x%x, index=%d, name=%s\n",
+                               p->id, p->index, p->name);
+               else
+                       dbgarg(cmd, "id=0x%x, index=%d\n",
+                               p->id, p->index);
+               break;
+       }
+       /* --- audio ---------------------------------------------- */
+       case VIDIOC_ENUMAUDIO:
+       {
+               struct v4l2_audio *p = arg;
+
+               if (!vfd->vidioc_enumaudio)
+                       break;
+               ret = vfd->vidioc_enumaudio(file, fh, p);
+               if (!ret)
+                       dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
+                                       "mode=0x%x\n", p->index, p->name,
+                                       p->capability, p->mode);
+               else
+                       dbgarg(cmd, "index=%d\n", p->index);
+               break;
+       }
+       case VIDIOC_G_AUDIO:
+       {
+               struct v4l2_audio *p = arg;
+               __u32 index = p->index;
+
+               if (!vfd->vidioc_g_audio)
+                       break;
+
+               memset(p, 0, sizeof(*p));
+               p->index = index;
+               ret = vfd->vidioc_g_audio(file, fh, p);
+               if (!ret)
+                       dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
+                                       "mode=0x%x\n", p->index,
+                                       p->name, p->capability, p->mode);
+               else
+                       dbgarg(cmd, "index=%d\n", p->index);
+               break;
+       }
+       case VIDIOC_S_AUDIO:
+       {
+               struct v4l2_audio *p = arg;
+
+               if (!vfd->vidioc_s_audio)
+                       break;
+               dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
+                                       "mode=0x%x\n", p->index, p->name,
+                                       p->capability, p->mode);
+               ret = vfd->vidioc_s_audio(file, fh, p);
+               break;
+       }
+       case VIDIOC_ENUMAUDOUT:
+       {
+               struct v4l2_audioout *p = arg;
+
+               if (!vfd->vidioc_enumaudout)
+                       break;
+               dbgarg(cmd, "Enum for index=%d\n", p->index);
+               ret = vfd->vidioc_enumaudout(file, fh, p);
+               if (!ret)
+                       dbgarg2("index=%d, name=%s, capability=%d, "
+                                       "mode=%d\n", p->index, p->name,
+                                       p->capability, p->mode);
+               break;
+       }
+       case VIDIOC_G_AUDOUT:
+       {
+               struct v4l2_audioout *p = arg;
+
+               if (!vfd->vidioc_g_audout)
+                       break;
+               dbgarg(cmd, "Enum for index=%d\n", p->index);
+               ret = vfd->vidioc_g_audout(file, fh, p);
+               if (!ret)
+                       dbgarg2("index=%d, name=%s, capability=%d, "
+                                       "mode=%d\n", p->index, p->name,
+                                       p->capability, p->mode);
+               break;
+       }
+       case VIDIOC_S_AUDOUT:
+       {
+               struct v4l2_audioout *p = arg;
+
+               if (!vfd->vidioc_s_audout)
+                       break;
+               dbgarg(cmd, "index=%d, name=%s, capability=%d, "
+                                       "mode=%d\n", p->index, p->name,
+                                       p->capability, p->mode);
+
+               ret = vfd->vidioc_s_audout(file, fh, p);
+               break;
+       }
+       case VIDIOC_G_MODULATOR:
+       {
+               struct v4l2_modulator *p = arg;
+
+               if (!vfd->vidioc_g_modulator)
+                       break;
+               ret = vfd->vidioc_g_modulator(file, fh, p);
+               if (!ret)
+                       dbgarg(cmd, "index=%d, name=%s, "
+                                       "capability=%d, rangelow=%d,"
+                                       " rangehigh=%d, txsubchans=%d\n",
+                                       p->index, p->name, p->capability,
+                                       p->rangelow, p->rangehigh,
+                                       p->txsubchans);
+               break;
+       }
+       case VIDIOC_S_MODULATOR:
+       {
+               struct v4l2_modulator *p = arg;
+
+               if (!vfd->vidioc_s_modulator)
+                       break;
+               dbgarg(cmd, "index=%d, name=%s, capability=%d, "
+                               "rangelow=%d, rangehigh=%d, txsubchans=%d\n",
+                               p->index, p->name, p->capability, p->rangelow,
+                               p->rangehigh, p->txsubchans);
+                       ret = vfd->vidioc_s_modulator(file, fh, p);
+               break;
+       }
+       case VIDIOC_G_CROP:
+       {
+               struct v4l2_crop *p = arg;
+
+               if (!vfd->vidioc_g_crop)
+                       break;
+               dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
+               ret = vfd->vidioc_g_crop(file, fh, p);
+               if (!ret)
+                       dbgrect(vfd, "", &p->c);
+               break;
+       }
+       case VIDIOC_S_CROP:
+       {
+               struct v4l2_crop *p = arg;
+
+               if (!vfd->vidioc_s_crop)
+                       break;
+               dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
+               dbgrect(vfd, "", &p->c);
+               ret = vfd->vidioc_s_crop(file, fh, p);
+               break;
+       }
+       case VIDIOC_CROPCAP:
+       {
+               struct v4l2_cropcap *p = arg;
+
+               /*FIXME: Should also show v4l2_fract pixelaspect */
+               if (!vfd->vidioc_cropcap)
+                       break;
+               dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
+               ret = vfd->vidioc_cropcap(file, fh, p);
+               if (!ret) {
+                       dbgrect(vfd, "bounds ", &p->bounds);
+                       dbgrect(vfd, "defrect ", &p->defrect);
+               }
+               break;
+       }
+       case VIDIOC_G_JPEGCOMP:
+       {
+               struct v4l2_jpegcompression *p = arg;
+
+               if (!vfd->vidioc_g_jpegcomp)
+                       break;
+               ret = vfd->vidioc_g_jpegcomp(file, fh, p);
+               if (!ret)
+                       dbgarg(cmd, "quality=%d, APPn=%d, "
+                                       "APP_len=%d, COM_len=%d, "
+                                       "jpeg_markers=%d\n",
+                                       p->quality, p->APPn, p->APP_len,
+                                       p->COM_len, p->jpeg_markers);
+               break;
+       }
+       case VIDIOC_S_JPEGCOMP:
+       {
+               struct v4l2_jpegcompression *p = arg;
+
+               if (!vfd->vidioc_g_jpegcomp)
+                       break;
+               dbgarg(cmd, "quality=%d, APPn=%d, APP_len=%d, "
+                                       "COM_len=%d, jpeg_markers=%d\n",
+                                       p->quality, p->APPn, p->APP_len,
+                                       p->COM_len, p->jpeg_markers);
+                       ret = vfd->vidioc_s_jpegcomp(file, fh, p);
+               break;
+       }
+       case VIDIOC_G_ENC_INDEX:
+       {
+               struct v4l2_enc_idx *p = arg;
+
+               if (!vfd->vidioc_g_enc_index)
+                       break;
+               ret = vfd->vidioc_g_enc_index(file, fh, p);
+               if (!ret)
+                       dbgarg(cmd, "entries=%d, entries_cap=%d\n",
+                                       p->entries, p->entries_cap);
+               break;
+       }
+       case VIDIOC_ENCODER_CMD:
+       {
+               struct v4l2_encoder_cmd *p = arg;
+
+               if (!vfd->vidioc_encoder_cmd)
+                       break;
+               memset(&p->raw, 0, sizeof(p->raw));
+               ret = vfd->vidioc_encoder_cmd(file, fh, p);
+               if (!ret)
+                       dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
+               break;
+       }
+       case VIDIOC_TRY_ENCODER_CMD:
+       {
+               struct v4l2_encoder_cmd *p = arg;
+
+               if (!vfd->vidioc_try_encoder_cmd)
+                       break;
+               memset(&p->raw, 0, sizeof(p->raw));
+               ret = vfd->vidioc_try_encoder_cmd(file, fh, p);
+               if (!ret)
+                       dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
+               break;
+       }
+       case VIDIOC_G_PARM:
+       {
+               struct v4l2_streamparm *p = arg;
+               __u32 type = p->type;
+
+               memset(p, 0, sizeof(*p));
+               p->type = type;
+
+               if (vfd->vidioc_g_parm) {
+                       ret = vfd->vidioc_g_parm(file, fh, p);
+               } else {
+                       struct v4l2_standard s;
+
+                       if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
+                               return -EINVAL;
+
+                       v4l2_video_std_construct(&s, vfd->current_norm,
+                                                v4l2_norm_to_name(vfd->current_norm));
+
+                       p->parm.capture.timeperframe = s.frameperiod;
+                       ret = 0;
+               }
+
+               dbgarg(cmd, "type=%d\n", p->type);
+               break;
+       }
+       case VIDIOC_S_PARM:
+       {
+               struct v4l2_streamparm *p = arg;
+
+               if (!vfd->vidioc_s_parm)
+                       break;
+               dbgarg(cmd, "type=%d\n", p->type);
+               ret = vfd->vidioc_s_parm(file, fh, p);
+               break;
+       }
+       case VIDIOC_G_TUNER:
+       {
+               struct v4l2_tuner *p = arg;
+               __u32 index = p->index;
+
+               if (!vfd->vidioc_g_tuner)
+                       break;
+
+               memset(p, 0, sizeof(*p));
+               p->index = index;
+
+               ret = vfd->vidioc_g_tuner(file, fh, p);
+               if (!ret)
+                       dbgarg(cmd, "index=%d, name=%s, type=%d, "
+                                       "capability=0x%x, rangelow=%d, "
+                                       "rangehigh=%d, signal=%d, afc=%d, "
+                                       "rxsubchans=0x%x, audmode=%d\n",
+                                       p->index, p->name, p->type,
+                                       p->capability, p->rangelow,
+                                       p->rangehigh, p->signal, p->afc,
+                                       p->rxsubchans, p->audmode);
+               break;
+       }
+       case VIDIOC_S_TUNER:
+       {
+               struct v4l2_tuner *p = arg;
+
+               if (!vfd->vidioc_s_tuner)
+                       break;
+               dbgarg(cmd, "index=%d, name=%s, type=%d, "
+                               "capability=0x%x, rangelow=%d, "
+                               "rangehigh=%d, signal=%d, afc=%d, "
+                               "rxsubchans=0x%x, audmode=%d\n",
+                               p->index, p->name, p->type,
+                               p->capability, p->rangelow,
+                               p->rangehigh, p->signal, p->afc,
+                               p->rxsubchans, p->audmode);
+               ret = vfd->vidioc_s_tuner(file, fh, p);
+               break;
+       }
+       case VIDIOC_G_FREQUENCY:
+       {
+               struct v4l2_frequency *p = arg;
+
+               if (!vfd->vidioc_g_frequency)
+                       break;
+
+               memset(p->reserved, 0, sizeof(p->reserved));
+
+               ret = vfd->vidioc_g_frequency(file, fh, p);
+               if (!ret)
+                       dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
+                                       p->tuner, p->type, p->frequency);
+               break;
+       }
+       case VIDIOC_S_FREQUENCY:
+       {
+               struct v4l2_frequency *p = arg;
+
+               if (!vfd->vidioc_s_frequency)
+                       break;
+               dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
+                               p->tuner, p->type, p->frequency);
+               ret = vfd->vidioc_s_frequency(file, fh, p);
+               break;
+       }
+       case VIDIOC_G_SLICED_VBI_CAP:
+       {
+               struct v4l2_sliced_vbi_cap *p = arg;
+               __u32 type = p->type;
+
+               if (!vfd->vidioc_g_sliced_vbi_cap)
+                       break;
+               memset(p, 0, sizeof(*p));
+               p->type = type;
+               dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
+               ret = vfd->vidioc_g_sliced_vbi_cap(file, fh, p);
+               if (!ret)
+                       dbgarg2("service_set=%d\n", p->service_set);
+               break;
+       }
+       case VIDIOC_LOG_STATUS:
+       {
+               if (!vfd->vidioc_log_status)
+                       break;
+               ret = vfd->vidioc_log_status(file, fh);
+               break;
+       }
+#ifdef CONFIG_VIDEO_ADV_DEBUG
+       case VIDIOC_DBG_G_REGISTER:
+       {
+               struct v4l2_register *p = arg;
+
+               if (!capable(CAP_SYS_ADMIN))
+                       ret = -EPERM;
+               else if (vfd->vidioc_g_register)
+                       ret = vfd->vidioc_g_register(file, fh, p);
+               break;
+       }
+       case VIDIOC_DBG_S_REGISTER:
+       {
+               struct v4l2_register *p = arg;
+
+               if (!capable(CAP_SYS_ADMIN))
+                       ret = -EPERM;
+               else if (vfd->vidioc_s_register)
+                       ret = vfd->vidioc_s_register(file, fh, p);
+               break;
+       }
+#endif
+       case VIDIOC_G_CHIP_IDENT:
+       {
+               struct v4l2_chip_ident *p = arg;
+
+               if (!vfd->vidioc_g_chip_ident)
+                       break;
+               ret = vfd->vidioc_g_chip_ident(file, fh, p);
+               if (!ret)
+                       dbgarg(cmd, "chip_ident=%u, revision=0x%x\n", p->ident, p->revision);
+               break;
+       }
+       default:
+       {
+               if (!vfd->vidioc_default)
+                       break;
+               ret = vfd->vidioc_default(file, fh, cmd, arg);
+               break;
+       }
+       case VIDIOC_S_HW_FREQ_SEEK:
+       {
+               struct v4l2_hw_freq_seek *p = arg;
+
+               if (!vfd->vidioc_s_hw_freq_seek)
+                       break;
+               dbgarg(cmd,
+                       "tuner=%d, type=%d, seek_upward=%d, wrap_around=%d\n",
+                       p->tuner, p->type, p->seek_upward, p->wrap_around);
+               ret = vfd->vidioc_s_hw_freq_seek(file, fh, p);
+               break;
+       }
+       } /* switch */
+
+       if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {
+               if (ret < 0) {
+                       v4l_print_ioctl(vfd->name, cmd);
+                       printk(KERN_CONT " error %d\n", ret);
+               }
+       }
+
+       return ret;
+}
+
+int video_ioctl2(struct inode *inode, struct file *file,
+              unsigned int cmd, unsigned long arg)
+{
+       char    sbuf[128];
+       void    *mbuf = NULL;
+       void    *parg = NULL;
+       int     err  = -EINVAL;
+       int     is_ext_ctrl;
+       size_t  ctrls_size = 0;
+       void __user *user_ptr = NULL;
+
+#ifdef __OLD_VIDIOC_
+       cmd = video_fix_command(cmd);
+#endif
+       is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS ||
+                      cmd == VIDIOC_TRY_EXT_CTRLS);
+
+       /*  Copy arguments into temp kernel buffer  */
+       switch (_IOC_DIR(cmd)) {
+       case _IOC_NONE:
+               parg = NULL;
+               break;
+       case _IOC_READ:
+       case _IOC_WRITE:
+       case (_IOC_WRITE | _IOC_READ):
+               if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
+                       parg = sbuf;
+               } else {
+                       /* too big to allocate from stack */
+                       mbuf = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL);
+                       if (NULL == mbuf)
+                               return -ENOMEM;
+                       parg = mbuf;
+               }
+
+               err = -EFAULT;
+               if (_IOC_DIR(cmd) & _IOC_WRITE)
+                       if (copy_from_user(parg, (void __user *)arg, _IOC_SIZE(cmd)))
+                               goto out;
+               break;
+       }
+
+       if (is_ext_ctrl) {
+               struct v4l2_ext_controls *p = parg;
+
+               /* In case of an error, tell the caller that it wasn't
+                  a specific control that caused it. */
+               p->error_idx = p->count;
+               user_ptr = (void __user *)p->controls;
+               if (p->count) {
+                       ctrls_size = sizeof(struct v4l2_ext_control) * p->count;
+                       /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
+                       mbuf = kmalloc(ctrls_size, GFP_KERNEL);
+                       err = -ENOMEM;
+                       if (NULL == mbuf)
+                               goto out_ext_ctrl;
+                       err = -EFAULT;
+                       if (copy_from_user(mbuf, user_ptr, ctrls_size))
+                               goto out_ext_ctrl;
+                       p->controls = mbuf;
+               }
+       }
+
+       /* Handles IOCTL */
+       err = __video_do_ioctl(inode, file, cmd, parg);
+       if (err == -ENOIOCTLCMD)
+               err = -EINVAL;
+       if (is_ext_ctrl) {
+               struct v4l2_ext_controls *p = parg;
+
+               p->controls = (void *)user_ptr;
+               if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size))
+                       err = -EFAULT;
+               goto out_ext_ctrl;
+       }
+       if (err < 0)
+               goto out;
+
+out_ext_ctrl:
+       /*  Copy results into user buffer  */
+       switch (_IOC_DIR(cmd)) {
+       case _IOC_READ:
+       case (_IOC_WRITE | _IOC_READ):
+               if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
+                       err = -EFAULT;
+               break;
+       }
+
+out:
+       kfree(mbuf);
+       return err;
+}
+EXPORT_SYMBOL(video_ioctl2);
index 03f20acb668cfd193a5ef8fea7a0315fe0083c88..31944b11e6ea409fa454eb1f02a99f7e761f2e4e 100644 (file)
@@ -28,10 +28,10 @@ struct videobuf_dma_contig_memory {
 };
 
 #define MAGIC_DC_MEM 0x0733ac61
-#define MAGIC_CHECK(is, should)                                                \
-       if (unlikely((is) != (should))) {                               \
-               pr_err("magic mismatch: %x expected %x\n", is, should); \
-               BUG();                                                  \
+#define MAGIC_CHECK(is, should)                                                    \
+       if (unlikely((is) != (should))) {                                   \
+               pr_err("magic mismatch: %x expected %x\n", (is), (should)); \
+               BUG();                                                      \
        }
 
 static void
index 6616e6570557b84960d89afc2753e7bf4bf053f0..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 (file)
-/*
- * Video capture interface for Linux version 2
- *
- *     A generic video device interface for the LINUX operating system
- *     using a set of device structures/vectors for low level operations.
- *
- *     This program is free software; you can redistribute it and/or
- *     modify it under the terms of the GNU General Public License
- *     as published by the Free Software Foundation; either version
- *     2 of the License, or (at your option) any later version.
- *
- * Authors:    Alan Cox, <alan@redhat.com> (version 1)
- *              Mauro Carvalho Chehab <mchehab@infradead.org> (version 2)
- *
- * Fixes:      20000516  Claudio Matsuoka <claudio@conectiva.com>
- *             - Added procfs support
- */
-
-#define dbgarg(cmd, fmt, arg...) \
-               do {                                                    \
-                   if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {            \
-                       printk(KERN_DEBUG "%s: ",  vfd->name);          \
-                       v4l_printk_ioctl(cmd);                          \
-                       printk(" " fmt,  ## arg);                       \
-                   }                                                   \
-               } while (0)
-
-#define dbgarg2(fmt, arg...) \
-               do {                                                    \
-                   if (vfd->debug & V4L2_DEBUG_IOCTL_ARG)              \
-                       printk(KERN_DEBUG "%s: " fmt, vfd->name, ## arg);\
-               } while (0)
-
-#include <linux/module.h>
-#include <linux/types.h>
-#include <linux/kernel.h>
-#include <linux/mm.h>
-#include <linux/string.h>
-#include <linux/errno.h>
-#include <linux/init.h>
-#include <linux/kmod.h>
-#include <linux/slab.h>
-#include <linux/smp_lock.h>
-#include <asm/uaccess.h>
-#include <asm/system.h>
-
-#define __OLD_VIDIOC_ /* To allow fixing old calls*/
-#include <linux/videodev2.h>
-
-#ifdef CONFIG_VIDEO_V4L1
-#include <linux/videodev.h>
-#endif
-#include <media/v4l2-common.h>
-#include <linux/video_decoder.h>
-
-#define VIDEO_NUM_DEVICES      256
-#define VIDEO_NAME              "video4linux"
-
-struct std_descr {
-       v4l2_std_id std;
-       const char *descr;
-};
-
-static const struct std_descr standards[] = {
-       { V4L2_STD_NTSC,        "NTSC"      },
-       { V4L2_STD_NTSC_M,      "NTSC-M"    },
-       { V4L2_STD_NTSC_M_JP,   "NTSC-M-JP" },
-       { V4L2_STD_NTSC_M_KR,   "NTSC-M-KR" },
-       { V4L2_STD_NTSC_443,    "NTSC-443"  },
-       { V4L2_STD_PAL,         "PAL"       },
-       { V4L2_STD_PAL_BG,      "PAL-BG"    },
-       { V4L2_STD_PAL_B,       "PAL-B"     },
-       { V4L2_STD_PAL_B1,      "PAL-B1"    },
-       { V4L2_STD_PAL_G,       "PAL-G"     },
-       { V4L2_STD_PAL_H,       "PAL-H"     },
-       { V4L2_STD_PAL_I,       "PAL-I"     },
-       { V4L2_STD_PAL_DK,      "PAL-DK"    },
-       { V4L2_STD_PAL_D,       "PAL-D"     },
-       { V4L2_STD_PAL_D1,      "PAL-D1"    },
-       { V4L2_STD_PAL_K,       "PAL-K"     },
-       { V4L2_STD_PAL_M,       "PAL-M"     },
-       { V4L2_STD_PAL_N,       "PAL-N"     },
-       { V4L2_STD_PAL_Nc,      "PAL-Nc"    },
-       { V4L2_STD_PAL_60,      "PAL-60"    },
-       { V4L2_STD_SECAM,       "SECAM"     },
-       { V4L2_STD_SECAM_B,     "SECAM-B"   },
-       { V4L2_STD_SECAM_G,     "SECAM-G"   },
-       { V4L2_STD_SECAM_H,     "SECAM-H"   },
-       { V4L2_STD_SECAM_DK,    "SECAM-DK"  },
-       { V4L2_STD_SECAM_D,     "SECAM-D"   },
-       { V4L2_STD_SECAM_K,     "SECAM-K"   },
-       { V4L2_STD_SECAM_K1,    "SECAM-K1"  },
-       { V4L2_STD_SECAM_L,     "SECAM-L"   },
-       { V4L2_STD_SECAM_LC,    "SECAM-Lc"  },
-       { 0,                    "Unknown"   }
-};
-
-/* video4linux standard ID conversion to standard name
- */
-const char *v4l2_norm_to_name(v4l2_std_id id)
-{
-       u32 myid = id;
-       int i;
-
-       /* HACK: ppc32 architecture doesn't have __ucmpdi2 function to handle
-          64 bit comparations. So, on that architecture, with some gcc
-          variants, compilation fails. Currently, the max value is 30bit wide.
-        */
-       BUG_ON(myid != id);
-
-       for (i = 0; standards[i].std; i++)
-               if (myid == standards[i].std)
-                       break;
-       return standards[i].descr;
-}
-EXPORT_SYMBOL(v4l2_norm_to_name);
-
-/* Fill in the fields of a v4l2_standard structure according to the
-   'id' and 'transmission' parameters.  Returns negative on error.  */
-int v4l2_video_std_construct(struct v4l2_standard *vs,
-                            int id, const char *name)
-{
-       u32 index = vs->index;
-
-       memset(vs, 0, sizeof(struct v4l2_standard));
-       vs->index = index;
-       vs->id    = id;
-       if (id & V4L2_STD_525_60) {
-               vs->frameperiod.numerator = 1001;
-               vs->frameperiod.denominator = 30000;
-               vs->framelines = 525;
-       } else {
-               vs->frameperiod.numerator = 1;
-               vs->frameperiod.denominator = 25;
-               vs->framelines = 625;
-       }
-       strlcpy(vs->name, name, sizeof(vs->name));
-       return 0;
-}
-EXPORT_SYMBOL(v4l2_video_std_construct);
-
-/* ----------------------------------------------------------------- */
-/* some arrays for pretty-printing debug messages of enum types      */
-
-const char *v4l2_field_names[] = {
-       [V4L2_FIELD_ANY]        = "any",
-       [V4L2_FIELD_NONE]       = "none",
-       [V4L2_FIELD_TOP]        = "top",
-       [V4L2_FIELD_BOTTOM]     = "bottom",
-       [V4L2_FIELD_INTERLACED] = "interlaced",
-       [V4L2_FIELD_SEQ_TB]     = "seq-tb",
-       [V4L2_FIELD_SEQ_BT]     = "seq-bt",
-       [V4L2_FIELD_ALTERNATE]  = "alternate",
-       [V4L2_FIELD_INTERLACED_TB] = "interlaced-tb",
-       [V4L2_FIELD_INTERLACED_BT] = "interlaced-bt",
-};
-EXPORT_SYMBOL(v4l2_field_names);
-
-const char *v4l2_type_names[] = {
-       [V4L2_BUF_TYPE_VIDEO_CAPTURE]      = "vid-cap",
-       [V4L2_BUF_TYPE_VIDEO_OVERLAY]      = "vid-overlay",
-       [V4L2_BUF_TYPE_VIDEO_OUTPUT]       = "vid-out",
-       [V4L2_BUF_TYPE_VBI_CAPTURE]        = "vbi-cap",
-       [V4L2_BUF_TYPE_VBI_OUTPUT]         = "vbi-out",
-       [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE] = "sliced-vbi-cap",
-       [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT]  = "sliced-vbi-out",
-       [V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY] = "vid-out-overlay",
-};
-EXPORT_SYMBOL(v4l2_type_names);
-
-static const char *v4l2_memory_names[] = {
-       [V4L2_MEMORY_MMAP]    = "mmap",
-       [V4L2_MEMORY_USERPTR] = "userptr",
-       [V4L2_MEMORY_OVERLAY] = "overlay",
-};
-
-#define prt_names(a, arr) ((((a) >= 0) && ((a) < ARRAY_SIZE(arr))) ? \
-                          arr[a] : "unknown")
-
-/* ------------------------------------------------------------------ */
-/* debug help functions                                               */
-
-#ifdef CONFIG_VIDEO_V4L1_COMPAT
-static const char *v4l1_ioctls[] = {
-       [_IOC_NR(VIDIOCGCAP)]       = "VIDIOCGCAP",
-       [_IOC_NR(VIDIOCGCHAN)]      = "VIDIOCGCHAN",
-       [_IOC_NR(VIDIOCSCHAN)]      = "VIDIOCSCHAN",
-       [_IOC_NR(VIDIOCGTUNER)]     = "VIDIOCGTUNER",
-       [_IOC_NR(VIDIOCSTUNER)]     = "VIDIOCSTUNER",
-       [_IOC_NR(VIDIOCGPICT)]      = "VIDIOCGPICT",
-       [_IOC_NR(VIDIOCSPICT)]      = "VIDIOCSPICT",
-       [_IOC_NR(VIDIOCCAPTURE)]    = "VIDIOCCAPTURE",
-       [_IOC_NR(VIDIOCGWIN)]       = "VIDIOCGWIN",
-       [_IOC_NR(VIDIOCSWIN)]       = "VIDIOCSWIN",
-       [_IOC_NR(VIDIOCGFBUF)]      = "VIDIOCGFBUF",
-       [_IOC_NR(VIDIOCSFBUF)]      = "VIDIOCSFBUF",
-       [_IOC_NR(VIDIOCKEY)]        = "VIDIOCKEY",
-       [_IOC_NR(VIDIOCGFREQ)]      = "VIDIOCGFREQ",
-       [_IOC_NR(VIDIOCSFREQ)]      = "VIDIOCSFREQ",
-       [_IOC_NR(VIDIOCGAUDIO)]     = "VIDIOCGAUDIO",
-       [_IOC_NR(VIDIOCSAUDIO)]     = "VIDIOCSAUDIO",
-       [_IOC_NR(VIDIOCSYNC)]       = "VIDIOCSYNC",
-       [_IOC_NR(VIDIOCMCAPTURE)]   = "VIDIOCMCAPTURE",
-       [_IOC_NR(VIDIOCGMBUF)]      = "VIDIOCGMBUF",
-       [_IOC_NR(VIDIOCGUNIT)]      = "VIDIOCGUNIT",
-       [_IOC_NR(VIDIOCGCAPTURE)]   = "VIDIOCGCAPTURE",
-       [_IOC_NR(VIDIOCSCAPTURE)]   = "VIDIOCSCAPTURE",
-       [_IOC_NR(VIDIOCSPLAYMODE)]  = "VIDIOCSPLAYMODE",
-       [_IOC_NR(VIDIOCSWRITEMODE)] = "VIDIOCSWRITEMODE",
-       [_IOC_NR(VIDIOCGPLAYINFO)]  = "VIDIOCGPLAYINFO",
-       [_IOC_NR(VIDIOCSMICROCODE)] = "VIDIOCSMICROCODE",
-       [_IOC_NR(VIDIOCGVBIFMT)]    = "VIDIOCGVBIFMT",
-       [_IOC_NR(VIDIOCSVBIFMT)]    = "VIDIOCSVBIFMT"
-};
-#define V4L1_IOCTLS ARRAY_SIZE(v4l1_ioctls)
-#endif
-
-static const char *v4l2_ioctls[] = {
-       [_IOC_NR(VIDIOC_QUERYCAP)]         = "VIDIOC_QUERYCAP",
-       [_IOC_NR(VIDIOC_RESERVED)]         = "VIDIOC_RESERVED",
-       [_IOC_NR(VIDIOC_ENUM_FMT)]         = "VIDIOC_ENUM_FMT",
-       [_IOC_NR(VIDIOC_G_FMT)]            = "VIDIOC_G_FMT",
-       [_IOC_NR(VIDIOC_S_FMT)]            = "VIDIOC_S_FMT",
-       [_IOC_NR(VIDIOC_REQBUFS)]          = "VIDIOC_REQBUFS",
-       [_IOC_NR(VIDIOC_QUERYBUF)]         = "VIDIOC_QUERYBUF",
-       [_IOC_NR(VIDIOC_G_FBUF)]           = "VIDIOC_G_FBUF",
-       [_IOC_NR(VIDIOC_S_FBUF)]           = "VIDIOC_S_FBUF",
-       [_IOC_NR(VIDIOC_OVERLAY)]          = "VIDIOC_OVERLAY",
-       [_IOC_NR(VIDIOC_QBUF)]             = "VIDIOC_QBUF",
-       [_IOC_NR(VIDIOC_DQBUF)]            = "VIDIOC_DQBUF",
-       [_IOC_NR(VIDIOC_STREAMON)]         = "VIDIOC_STREAMON",
-       [_IOC_NR(VIDIOC_STREAMOFF)]        = "VIDIOC_STREAMOFF",
-       [_IOC_NR(VIDIOC_G_PARM)]           = "VIDIOC_G_PARM",
-       [_IOC_NR(VIDIOC_S_PARM)]           = "VIDIOC_S_PARM",
-       [_IOC_NR(VIDIOC_G_STD)]            = "VIDIOC_G_STD",
-       [_IOC_NR(VIDIOC_S_STD)]            = "VIDIOC_S_STD",
-       [_IOC_NR(VIDIOC_ENUMSTD)]          = "VIDIOC_ENUMSTD",
-       [_IOC_NR(VIDIOC_ENUMINPUT)]        = "VIDIOC_ENUMINPUT",
-       [_IOC_NR(VIDIOC_G_CTRL)]           = "VIDIOC_G_CTRL",
-       [_IOC_NR(VIDIOC_S_CTRL)]           = "VIDIOC_S_CTRL",
-       [_IOC_NR(VIDIOC_G_TUNER)]          = "VIDIOC_G_TUNER",
-       [_IOC_NR(VIDIOC_S_TUNER)]          = "VIDIOC_S_TUNER",
-       [_IOC_NR(VIDIOC_G_AUDIO)]          = "VIDIOC_G_AUDIO",
-       [_IOC_NR(VIDIOC_S_AUDIO)]          = "VIDIOC_S_AUDIO",
-       [_IOC_NR(VIDIOC_QUERYCTRL)]        = "VIDIOC_QUERYCTRL",
-       [_IOC_NR(VIDIOC_QUERYMENU)]        = "VIDIOC_QUERYMENU",
-       [_IOC_NR(VIDIOC_G_INPUT)]          = "VIDIOC_G_INPUT",
-       [_IOC_NR(VIDIOC_S_INPUT)]          = "VIDIOC_S_INPUT",
-       [_IOC_NR(VIDIOC_G_OUTPUT)]         = "VIDIOC_G_OUTPUT",
-       [_IOC_NR(VIDIOC_S_OUTPUT)]         = "VIDIOC_S_OUTPUT",
-       [_IOC_NR(VIDIOC_ENUMOUTPUT)]       = "VIDIOC_ENUMOUTPUT",
-       [_IOC_NR(VIDIOC_G_AUDOUT)]         = "VIDIOC_G_AUDOUT",
-       [_IOC_NR(VIDIOC_S_AUDOUT)]         = "VIDIOC_S_AUDOUT",
-       [_IOC_NR(VIDIOC_G_MODULATOR)]      = "VIDIOC_G_MODULATOR",
-       [_IOC_NR(VIDIOC_S_MODULATOR)]      = "VIDIOC_S_MODULATOR",
-       [_IOC_NR(VIDIOC_G_FREQUENCY)]      = "VIDIOC_G_FREQUENCY",
-       [_IOC_NR(VIDIOC_S_FREQUENCY)]      = "VIDIOC_S_FREQUENCY",
-       [_IOC_NR(VIDIOC_CROPCAP)]          = "VIDIOC_CROPCAP",
-       [_IOC_NR(VIDIOC_G_CROP)]           = "VIDIOC_G_CROP",
-       [_IOC_NR(VIDIOC_S_CROP)]           = "VIDIOC_S_CROP",
-       [_IOC_NR(VIDIOC_G_JPEGCOMP)]       = "VIDIOC_G_JPEGCOMP",
-       [_IOC_NR(VIDIOC_S_JPEGCOMP)]       = "VIDIOC_S_JPEGCOMP",
-       [_IOC_NR(VIDIOC_QUERYSTD)]         = "VIDIOC_QUERYSTD",
-       [_IOC_NR(VIDIOC_TRY_FMT)]          = "VIDIOC_TRY_FMT",
-       [_IOC_NR(VIDIOC_ENUMAUDIO)]        = "VIDIOC_ENUMAUDIO",
-       [_IOC_NR(VIDIOC_ENUMAUDOUT)]       = "VIDIOC_ENUMAUDOUT",
-       [_IOC_NR(VIDIOC_G_PRIORITY)]       = "VIDIOC_G_PRIORITY",
-       [_IOC_NR(VIDIOC_S_PRIORITY)]       = "VIDIOC_S_PRIORITY",
-       [_IOC_NR(VIDIOC_G_SLICED_VBI_CAP)] = "VIDIOC_G_SLICED_VBI_CAP",
-       [_IOC_NR(VIDIOC_LOG_STATUS)]       = "VIDIOC_LOG_STATUS",
-       [_IOC_NR(VIDIOC_G_EXT_CTRLS)]      = "VIDIOC_G_EXT_CTRLS",
-       [_IOC_NR(VIDIOC_S_EXT_CTRLS)]      = "VIDIOC_S_EXT_CTRLS",
-       [_IOC_NR(VIDIOC_TRY_EXT_CTRLS)]    = "VIDIOC_TRY_EXT_CTRLS",
-#if 1
-       [_IOC_NR(VIDIOC_ENUM_FRAMESIZES)]  = "VIDIOC_ENUM_FRAMESIZES",
-       [_IOC_NR(VIDIOC_ENUM_FRAMEINTERVALS)] = "VIDIOC_ENUM_FRAMEINTERVALS",
-       [_IOC_NR(VIDIOC_G_ENC_INDEX)]      = "VIDIOC_G_ENC_INDEX",
-       [_IOC_NR(VIDIOC_ENCODER_CMD)]      = "VIDIOC_ENCODER_CMD",
-       [_IOC_NR(VIDIOC_TRY_ENCODER_CMD)]  = "VIDIOC_TRY_ENCODER_CMD",
-
-       [_IOC_NR(VIDIOC_DBG_S_REGISTER)]   = "VIDIOC_DBG_S_REGISTER",
-       [_IOC_NR(VIDIOC_DBG_G_REGISTER)]   = "VIDIOC_DBG_G_REGISTER",
-
-       [_IOC_NR(VIDIOC_G_CHIP_IDENT)]     = "VIDIOC_G_CHIP_IDENT",
-       [_IOC_NR(VIDIOC_S_HW_FREQ_SEEK)]   = "VIDIOC_S_HW_FREQ_SEEK",
-#endif
-};
-#define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
-
-static const char *v4l2_int_ioctls[] = {
-#ifdef CONFIG_VIDEO_V4L1_COMPAT
-       [_IOC_NR(DECODER_GET_CAPABILITIES)]    = "DECODER_GET_CAPABILITIES",
-       [_IOC_NR(DECODER_GET_STATUS)]          = "DECODER_GET_STATUS",
-       [_IOC_NR(DECODER_SET_NORM)]            = "DECODER_SET_NORM",
-       [_IOC_NR(DECODER_SET_INPUT)]           = "DECODER_SET_INPUT",
-       [_IOC_NR(DECODER_SET_OUTPUT)]          = "DECODER_SET_OUTPUT",
-       [_IOC_NR(DECODER_ENABLE_OUTPUT)]       = "DECODER_ENABLE_OUTPUT",
-       [_IOC_NR(DECODER_SET_PICTURE)]         = "DECODER_SET_PICTURE",
-       [_IOC_NR(DECODER_SET_GPIO)]            = "DECODER_SET_GPIO",
-       [_IOC_NR(DECODER_INIT)]                = "DECODER_INIT",
-       [_IOC_NR(DECODER_SET_VBI_BYPASS)]      = "DECODER_SET_VBI_BYPASS",
-       [_IOC_NR(DECODER_DUMP)]                = "DECODER_DUMP",
-#endif
-       [_IOC_NR(AUDC_SET_RADIO)]              = "AUDC_SET_RADIO",
-
-       [_IOC_NR(TUNER_SET_TYPE_ADDR)]         = "TUNER_SET_TYPE_ADDR",
-       [_IOC_NR(TUNER_SET_STANDBY)]           = "TUNER_SET_STANDBY",
-       [_IOC_NR(TUNER_SET_CONFIG)]            = "TUNER_SET_CONFIG",
-
-       [_IOC_NR(VIDIOC_INT_S_TUNER_MODE)]     = "VIDIOC_INT_S_TUNER_MODE",
-       [_IOC_NR(VIDIOC_INT_RESET)]            = "VIDIOC_INT_RESET",
-       [_IOC_NR(VIDIOC_INT_AUDIO_CLOCK_FREQ)] = "VIDIOC_INT_AUDIO_CLOCK_FREQ",
-       [_IOC_NR(VIDIOC_INT_DECODE_VBI_LINE)]  = "VIDIOC_INT_DECODE_VBI_LINE",
-       [_IOC_NR(VIDIOC_INT_S_VBI_DATA)]       = "VIDIOC_INT_S_VBI_DATA",
-       [_IOC_NR(VIDIOC_INT_G_VBI_DATA)]       = "VIDIOC_INT_G_VBI_DATA",
-       [_IOC_NR(VIDIOC_INT_I2S_CLOCK_FREQ)]   = "VIDIOC_INT_I2S_CLOCK_FREQ",
-       [_IOC_NR(VIDIOC_INT_S_STANDBY)]        = "VIDIOC_INT_S_STANDBY",
-       [_IOC_NR(VIDIOC_INT_S_AUDIO_ROUTING)]  = "VIDIOC_INT_S_AUDIO_ROUTING",
-       [_IOC_NR(VIDIOC_INT_G_AUDIO_ROUTING)]  = "VIDIOC_INT_G_AUDIO_ROUTING",
-       [_IOC_NR(VIDIOC_INT_S_VIDEO_ROUTING)]  = "VIDIOC_INT_S_VIDEO_ROUTING",
-       [_IOC_NR(VIDIOC_INT_G_VIDEO_ROUTING)]  = "VIDIOC_INT_G_VIDEO_ROUTING",
-       [_IOC_NR(VIDIOC_INT_S_CRYSTAL_FREQ)]   = "VIDIOC_INT_S_CRYSTAL_FREQ",
-       [_IOC_NR(VIDIOC_INT_INIT)]             = "VIDIOC_INT_INIT",
-       [_IOC_NR(VIDIOC_INT_G_STD_OUTPUT)]     = "VIDIOC_INT_G_STD_OUTPUT",
-       [_IOC_NR(VIDIOC_INT_S_STD_OUTPUT)]     = "VIDIOC_INT_S_STD_OUTPUT",
-};
-#define V4L2_INT_IOCTLS ARRAY_SIZE(v4l2_int_ioctls)
-
-/* Common ioctl debug function. This function can be used by
-   external ioctl messages as well as internal V4L ioctl */
-void v4l_printk_ioctl(unsigned int cmd)
-{
-       char *dir, *type;
-
-       switch (_IOC_TYPE(cmd)) {
-       case 'd':
-               if (_IOC_NR(cmd) >= V4L2_INT_IOCTLS) {
-                       type = "v4l2_int";
-                       break;
-               }
-               printk("%s", v4l2_int_ioctls[_IOC_NR(cmd)]);
-               return;
-#ifdef CONFIG_VIDEO_V4L1_COMPAT
-       case 'v':
-               if (_IOC_NR(cmd) >= V4L1_IOCTLS) {
-                       type = "v4l1";
-                       break;
-               }
-               printk("%s", v4l1_ioctls[_IOC_NR(cmd)]);
-               return;
-#endif
-       case 'V':
-               if (_IOC_NR(cmd) >= V4L2_IOCTLS) {
-                       type = "v4l2";
-                       break;
-               }
-               printk("%s", v4l2_ioctls[_IOC_NR(cmd)]);
-               return;
-       default:
-               type = "unknown";
-       }
-
-       switch (_IOC_DIR(cmd)) {
-       case _IOC_NONE:              dir = "--"; break;
-       case _IOC_READ:              dir = "r-"; break;
-       case _IOC_WRITE:             dir = "-w"; break;
-       case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
-       default:                     dir = "*ERR*"; break;
-       }
-       printk("%s ioctl '%c', dir=%s, #%d (0x%08x)",
-               type, _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd);
-}
-EXPORT_SYMBOL(v4l_printk_ioctl);
-
-/*
- *     sysfs stuff
- */
-
-static ssize_t show_index(struct device *cd,
-                        struct device_attribute *attr, char *buf)
-{
-       struct video_device *vfd = container_of(cd, struct video_device,
-                                               class_dev);
-       return sprintf(buf, "%i\n", vfd->index);
-}
-
-static ssize_t show_name(struct device *cd,
-                        struct device_attribute *attr, char *buf)
-{
-       struct video_device *vfd = container_of(cd, struct video_device,
-                                               class_dev);
-       return sprintf(buf, "%.*s\n", (int)sizeof(vfd->name), vfd->name);
-}
-
-static struct device_attribute video_device_attrs[] = {
-       __ATTR(name, S_IRUGO, show_name, NULL),
-       __ATTR(index, S_IRUGO, show_index, NULL),
-       __ATTR_NULL
-};
-
-struct video_device *video_device_alloc(void)
-{
-       struct video_device *vfd;
-
-       vfd = kzalloc(sizeof(*vfd),GFP_KERNEL);
-       return vfd;
-}
-EXPORT_SYMBOL(video_device_alloc);
-
-void video_device_release(struct video_device *vfd)
-{
-       kfree(vfd);
-}
-EXPORT_SYMBOL(video_device_release);
-
-static void video_release(struct device *cd)
-{
-       struct video_device *vfd = container_of(cd, struct video_device,
-                                                               class_dev);
-
-#if 1
-       /* needed until all drivers are fixed */
-       if (!vfd->release)
-               return;
-#endif
-       vfd->release(vfd);
-}
-
-static struct class video_class = {
-       .name    = VIDEO_NAME,
-       .dev_attrs = video_device_attrs,
-       .dev_release = video_release,
-};
-
-/*
- *     Active devices
- */
-
-static struct video_device *video_device[VIDEO_NUM_DEVICES];
-static DEFINE_MUTEX(videodev_lock);
-
-struct video_device* video_devdata(struct file *file)
-{
-       return video_device[iminor(file->f_path.dentry->d_inode)];
-}
-EXPORT_SYMBOL(video_devdata);
-
-/*
- *     Open a video device - FIXME: Obsoleted
- */
-static int video_open(struct inode *inode, struct file *file)
-{
-       unsigned int minor = iminor(inode);
-       int err = 0;
-       struct video_device *vfl;
-       const struct file_operations *old_fops;
-
-       if(minor>=VIDEO_NUM_DEVICES)
-               return -ENODEV;
-       lock_kernel();
-       mutex_lock(&videodev_lock);
-       vfl=video_device[minor];
-       if(vfl==NULL) {
-               mutex_unlock(&videodev_lock);
-               request_module("char-major-%d-%d", VIDEO_MAJOR, minor);
-               mutex_lock(&videodev_lock);
-               vfl=video_device[minor];
-               if (vfl==NULL) {
-                       mutex_unlock(&videodev_lock);
-                       unlock_kernel();
-                       return -ENODEV;
-               }
-       }
-       old_fops = file->f_op;
-       file->f_op = fops_get(vfl->fops);
-       if(file->f_op->open)
-               err = file->f_op->open(inode,file);
-       if (err) {
-               fops_put(file->f_op);
-               file->f_op = fops_get(old_fops);
-       }
-       fops_put(old_fops);
-       mutex_unlock(&videodev_lock);
-       unlock_kernel();
-       return err;
-}
-
-/*
- * helper function -- handles userspace copying for ioctl arguments
- */
-
-#ifdef __OLD_VIDIOC_
-static unsigned int
-video_fix_command(unsigned int cmd)
-{
-       switch (cmd) {
-       case VIDIOC_OVERLAY_OLD:
-               cmd = VIDIOC_OVERLAY;
-               break;
-       case VIDIOC_S_PARM_OLD:
-               cmd = VIDIOC_S_PARM;
-               break;
-       case VIDIOC_S_CTRL_OLD:
-               cmd = VIDIOC_S_CTRL;
-               break;
-       case VIDIOC_G_AUDIO_OLD:
-               cmd = VIDIOC_G_AUDIO;
-               break;
-       case VIDIOC_G_AUDOUT_OLD:
-               cmd = VIDIOC_G_AUDOUT;
-               break;
-       case VIDIOC_CROPCAP_OLD:
-               cmd = VIDIOC_CROPCAP;
-               break;
-       }
-       return cmd;
-}
-#endif
-
-/*
- * Obsolete usercopy function - Should be removed soon
- */
-int
-video_usercopy(struct inode *inode, struct file *file,
-              unsigned int cmd, unsigned long arg,
-              int (*func)(struct inode *inode, struct file *file,
-                          unsigned int cmd, void *arg))
-{
-       char    sbuf[128];
-       void    *mbuf = NULL;
-       void    *parg = NULL;
-       int     err  = -EINVAL;
-       int     is_ext_ctrl;
-       size_t  ctrls_size = 0;
-       void __user *user_ptr = NULL;
-
-#ifdef __OLD_VIDIOC_
-       cmd = video_fix_command(cmd);
-#endif
-       is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS ||
-                      cmd == VIDIOC_TRY_EXT_CTRLS);
-
-       /*  Copy arguments into temp kernel buffer  */
-       switch (_IOC_DIR(cmd)) {
-       case _IOC_NONE:
-               parg = NULL;
-               break;
-       case _IOC_READ:
-       case _IOC_WRITE:
-       case (_IOC_WRITE | _IOC_READ):
-               if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
-                       parg = sbuf;
-               } else {
-                       /* too big to allocate from stack */
-                       mbuf = kmalloc(_IOC_SIZE(cmd),GFP_KERNEL);
-                       if (NULL == mbuf)
-                               return -ENOMEM;
-                       parg = mbuf;
-               }
-
-               err = -EFAULT;
-               if (_IOC_DIR(cmd) & _IOC_WRITE)
-                       if (copy_from_user(parg, (void __user *)arg, _IOC_SIZE(cmd)))
-                               goto out;
-               break;
-       }
-       if (is_ext_ctrl) {
-               struct v4l2_ext_controls *p = parg;
-
-               /* In case of an error, tell the caller that it wasn't
-                  a specific control that caused it. */
-               p->error_idx = p->count;
-               user_ptr = (void __user *)p->controls;
-               if (p->count) {
-                       ctrls_size = sizeof(struct v4l2_ext_control) * p->count;
-                       /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
-                       mbuf = kmalloc(ctrls_size, GFP_KERNEL);
-                       err = -ENOMEM;
-                       if (NULL == mbuf)
-                               goto out_ext_ctrl;
-                       err = -EFAULT;
-                       if (copy_from_user(mbuf, user_ptr, ctrls_size))
-                               goto out_ext_ctrl;
-                       p->controls = mbuf;
-               }
-       }
-
-       /* call driver */
-       err = func(inode, file, cmd, parg);
-       if (err == -ENOIOCTLCMD)
-               err = -EINVAL;
-       if (is_ext_ctrl) {
-               struct v4l2_ext_controls *p = parg;
-
-               p->controls = (void *)user_ptr;
-               if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size))
-                       err = -EFAULT;
-               goto out_ext_ctrl;
-       }
-       if (err < 0)
-               goto out;
-
-out_ext_ctrl:
-       /*  Copy results into user buffer  */
-       switch (_IOC_DIR(cmd))
-       {
-       case _IOC_READ:
-       case (_IOC_WRITE | _IOC_READ):
-               if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
-                       err = -EFAULT;
-               break;
-       }
-
-out:
-       kfree(mbuf);
-       return err;
-}
-EXPORT_SYMBOL(video_usercopy);
-
-/*
- * open/release helper functions -- handle exclusive opens
- * Should be removed soon
- */
-int video_exclusive_open(struct inode *inode, struct file *file)
-{
-       struct  video_device *vfl = video_devdata(file);
-       int retval = 0;
-
-       mutex_lock(&vfl->lock);
-       if (vfl->users) {
-               retval = -EBUSY;
-       } else {
-               vfl->users++;
-       }
-       mutex_unlock(&vfl->lock);
-       return retval;
-}
-EXPORT_SYMBOL(video_exclusive_open);
-
-int video_exclusive_release(struct inode *inode, struct file *file)
-{
-       struct  video_device *vfl = video_devdata(file);
-
-       vfl->users--;
-       return 0;
-}
-EXPORT_SYMBOL(video_exclusive_release);
-
-static void dbgbuf(unsigned int cmd, struct video_device *vfd,
-                                       struct v4l2_buffer *p)
-{
-       struct v4l2_timecode *tc=&p->timecode;
-
-       dbgarg (cmd, "%02ld:%02d:%02d.%08ld index=%d, type=%s, "
-               "bytesused=%d, flags=0x%08d, "
-               "field=%0d, sequence=%d, memory=%s, offset/userptr=0x%08lx, length=%d\n",
-                       (p->timestamp.tv_sec/3600),
-                       (int)(p->timestamp.tv_sec/60)%60,
-                       (int)(p->timestamp.tv_sec%60),
-                       p->timestamp.tv_usec,
-                       p->index,
-                       prt_names(p->type, v4l2_type_names),
-                       p->bytesused, p->flags,
-                       p->field, p->sequence,
-                       prt_names(p->memory, v4l2_memory_names),
-                       p->m.userptr, p->length);
-       dbgarg2("timecode=%02d:%02d:%02d type=%d, "
-               "flags=0x%08d, frames=%d, userbits=0x%08x\n",
-                       tc->hours,tc->minutes,tc->seconds,
-                       tc->type, tc->flags, tc->frames, *(__u32 *) tc->userbits);
-}
-
-static inline void dbgrect(struct video_device *vfd, char *s,
-                                                       struct v4l2_rect *r)
-{
-       dbgarg2("%sRect start at %dx%d, size=%dx%d\n", s, r->left, r->top,
-                                               r->width, r->height);
-};
-
-static inline void v4l_print_pix_fmt (struct video_device *vfd,
-                                               struct v4l2_pix_format *fmt)
-{
-       dbgarg2 ("width=%d, height=%d, format=%c%c%c%c, field=%s, "
-               "bytesperline=%d sizeimage=%d, colorspace=%d\n",
-               fmt->width,fmt->height,
-               (fmt->pixelformat & 0xff),
-               (fmt->pixelformat >>  8) & 0xff,
-               (fmt->pixelformat >> 16) & 0xff,
-               (fmt->pixelformat >> 24) & 0xff,
-               prt_names(fmt->field, v4l2_field_names),
-               fmt->bytesperline, fmt->sizeimage, fmt->colorspace);
-};
-
-static inline void v4l_print_ext_ctrls(unsigned int cmd,
-       struct video_device *vfd, struct v4l2_ext_controls *c, int show_vals)
-{
-       __u32 i;
-
-       if (!(vfd->debug & V4L2_DEBUG_IOCTL_ARG))
-               return;
-       dbgarg(cmd, "");
-       printk(KERN_CONT "class=0x%x", c->ctrl_class);
-       for (i = 0; i < c->count; i++) {
-               if (show_vals)
-                       printk(KERN_CONT " id/val=0x%x/0x%x",
-                               c->controls[i].id, c->controls[i].value);
-               else
-                       printk(KERN_CONT " id=0x%x", c->controls[i].id);
-       }
-       printk(KERN_CONT "\n");
-};
-
-static inline int check_ext_ctrls(struct v4l2_ext_controls *c, int allow_priv)
-{
-       __u32 i;
-
-       /* zero the reserved fields */
-       c->reserved[0] = c->reserved[1] = 0;
-       for (i = 0; i < c->count; i++) {
-               c->controls[i].reserved2[0] = 0;
-               c->controls[i].reserved2[1] = 0;
-       }
-       /* V4L2_CID_PRIVATE_BASE cannot be used as control class
-          when using extended controls.
-          Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL
-          is it allowed for backwards compatibility.
-        */
-       if (!allow_priv && c->ctrl_class == V4L2_CID_PRIVATE_BASE)
-               return 0;
-       /* Check that all controls are from the same control class. */
-       for (i = 0; i < c->count; i++) {
-               if (V4L2_CTRL_ID2CLASS(c->controls[i].id) != c->ctrl_class) {
-                       c->error_idx = i;
-                       return 0;
-               }
-       }
-       return 1;
-}
-
-static int check_fmt (struct video_device *vfd, enum v4l2_buf_type type)
-{
-       switch (type) {
-       case V4L2_BUF_TYPE_VIDEO_CAPTURE:
-               if (vfd->vidioc_try_fmt_vid_cap)
-                       return (0);
-               break;
-       case V4L2_BUF_TYPE_VIDEO_OVERLAY:
-               if (vfd->vidioc_try_fmt_vid_overlay)
-                       return (0);
-               break;
-       case V4L2_BUF_TYPE_VIDEO_OUTPUT:
-               if (vfd->vidioc_try_fmt_vid_out)
-                       return (0);
-               break;
-       case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
-               if (vfd->vidioc_try_fmt_vid_out_overlay)
-                       return (0);
-               break;
-       case V4L2_BUF_TYPE_VBI_CAPTURE:
-               if (vfd->vidioc_try_fmt_vbi_cap)
-                       return (0);
-               break;
-       case V4L2_BUF_TYPE_VBI_OUTPUT:
-               if (vfd->vidioc_try_fmt_vbi_out)
-                       return (0);
-               break;
-       case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
-               if (vfd->vidioc_try_fmt_sliced_vbi_cap)
-                       return (0);
-               break;
-       case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
-               if (vfd->vidioc_try_fmt_sliced_vbi_out)
-                       return (0);
-               break;
-       case V4L2_BUF_TYPE_PRIVATE:
-               if (vfd->vidioc_try_fmt_type_private)
-                       return (0);
-               break;
-       }
-       return (-EINVAL);
-}
-
-static int __video_do_ioctl(struct inode *inode, struct file *file,
-               unsigned int cmd, void *arg)
-{
-       struct video_device *vfd = video_devdata(file);
-       void                 *fh = file->private_data;
-       int                  ret = -EINVAL;
-
-       if ( (vfd->debug & V4L2_DEBUG_IOCTL) &&
-                               !(vfd->debug & V4L2_DEBUG_IOCTL_ARG)) {
-               v4l_print_ioctl(vfd->name, cmd);
-               printk("\n");
-       }
-
-#ifdef CONFIG_VIDEO_V4L1_COMPAT
-       /***********************************************************
-        Handles calls to the obsoleted V4L1 API
-        Due to the nature of VIDIOCGMBUF, each driver that supports
-        V4L1 should implement its own handler for this ioctl.
-        ***********************************************************/
-
-       /* --- streaming capture ------------------------------------- */
-       if (cmd == VIDIOCGMBUF) {
-               struct video_mbuf *p=arg;
-
-               memset(p, 0, sizeof(*p));
-
-               if (!vfd->vidiocgmbuf)
-                       return ret;
-               ret=vfd->vidiocgmbuf(file, fh, p);
-               if (!ret)
-                       dbgarg (cmd, "size=%d, frames=%d, offsets=0x%08lx\n",
-                                               p->size, p->frames,
-                                               (unsigned long)p->offsets);
-               return ret;
-       }
-
-       /********************************************************
-        All other V4L1 calls are handled by v4l1_compat module.
-        Those calls will be translated into V4L2 calls, and
-        __video_do_ioctl will be called again, with one or more
-        V4L2 ioctls.
-        ********************************************************/
-       if (_IOC_TYPE(cmd)=='v')
-               return v4l_compat_translate_ioctl(inode,file,cmd,arg,
-                                               __video_do_ioctl);
-#endif
-
-       switch(cmd) {
-       /* --- capabilities ------------------------------------------ */
-       case VIDIOC_QUERYCAP:
-       {
-               struct v4l2_capability *cap = (struct v4l2_capability*)arg;
-               memset(cap, 0, sizeof(*cap));
-
-               if (!vfd->vidioc_querycap)
-                       break;
-
-               ret=vfd->vidioc_querycap(file, fh, cap);
-               if (!ret)
-                       dbgarg (cmd, "driver=%s, card=%s, bus=%s, "
-                                       "version=0x%08x, "
-                                       "capabilities=0x%08x\n",
-                                       cap->driver,cap->card,cap->bus_info,
-                                       cap->version,
-                                       cap->capabilities);
-               break;
-       }
-
-       /* --- priority ------------------------------------------ */
-       case VIDIOC_G_PRIORITY:
-       {
-               enum v4l2_priority *p=arg;
-
-               if (!vfd->vidioc_g_priority)
-                       break;
-               ret=vfd->vidioc_g_priority(file, fh, p);
-               if (!ret)
-                       dbgarg(cmd, "priority is %d\n", *p);
-               break;
-       }
-       case VIDIOC_S_PRIORITY:
-       {
-               enum v4l2_priority *p=arg;
-
-               if (!vfd->vidioc_s_priority)
-                       break;
-               dbgarg(cmd, "setting priority to %d\n", *p);
-               ret=vfd->vidioc_s_priority(file, fh, *p);
-               break;
-       }
-
-       /* --- capture ioctls ---------------------------------------- */
-       case VIDIOC_ENUM_FMT:
-       {
-               struct v4l2_fmtdesc *f = arg;
-               enum v4l2_buf_type type;
-               unsigned int index;
-
-               index = f->index;
-               type  = f->type;
-               memset(f,0,sizeof(*f));
-               f->index = index;
-               f->type  = type;
-
-               switch (type) {
-               case V4L2_BUF_TYPE_VIDEO_CAPTURE:
-                       if (vfd->vidioc_enum_fmt_vid_cap)
-                               ret = vfd->vidioc_enum_fmt_vid_cap(file, fh, f);
-                       break;
-               case V4L2_BUF_TYPE_VIDEO_OVERLAY:
-                       if (vfd->vidioc_enum_fmt_vid_overlay)
-                               ret = vfd->vidioc_enum_fmt_vid_overlay(file,
-                                       fh, f);
-                       break;
-#if 1
-               /* V4L2_BUF_TYPE_VBI_CAPTURE should not support VIDIOC_ENUM_FMT
-                * according to the spec. The bttv and saa7134 drivers support
-                * it though, so just warn that this is deprecated and will be
-                * removed in the near future. */
-               case V4L2_BUF_TYPE_VBI_CAPTURE:
-                       if (vfd->vidioc_enum_fmt_vbi_cap) {
-                               printk(KERN_WARNING "vidioc_enum_fmt_vbi_cap will be removed in 2.6.28!\n");
-                               ret = vfd->vidioc_enum_fmt_vbi_cap(file, fh, f);
-                       }
-                       break;
-#endif
-               case V4L2_BUF_TYPE_VIDEO_OUTPUT:
-                       if (vfd->vidioc_enum_fmt_vid_out)
-                               ret = vfd->vidioc_enum_fmt_vid_out(file, fh, f);
-                       break;
-               case V4L2_BUF_TYPE_PRIVATE:
-                       if (vfd->vidioc_enum_fmt_type_private)
-                               ret = vfd->vidioc_enum_fmt_type_private(file,
-                                                               fh, f);
-                       break;
-               default:
-                       break;
-               }
-               if (!ret)
-                       dbgarg (cmd, "index=%d, type=%d, flags=%d, "
-                                       "pixelformat=%c%c%c%c, description='%s'\n",
-                                       f->index, f->type, f->flags,
-                                       (f->pixelformat & 0xff),
-                                       (f->pixelformat >>  8) & 0xff,
-                                       (f->pixelformat >> 16) & 0xff,
-                                       (f->pixelformat >> 24) & 0xff,
-                                       f->description);
-               break;
-       }
-       case VIDIOC_G_FMT:
-       {
-               struct v4l2_format *f = (struct v4l2_format *)arg;
-
-               memset(f->fmt.raw_data, 0, sizeof(f->fmt.raw_data));
-
-               /* FIXME: Should be one dump per type */
-               dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
-
-               switch (f->type) {
-               case V4L2_BUF_TYPE_VIDEO_CAPTURE:
-                       if (vfd->vidioc_g_fmt_vid_cap)
-                               ret = vfd->vidioc_g_fmt_vid_cap(file, fh, f);
-                       if (!ret)
-                               v4l_print_pix_fmt(vfd, &f->fmt.pix);
-                       break;
-               case V4L2_BUF_TYPE_VIDEO_OVERLAY:
-                       if (vfd->vidioc_g_fmt_vid_overlay)
-                               ret = vfd->vidioc_g_fmt_vid_overlay(file,
-                                                                   fh, f);
-                       break;
-               case V4L2_BUF_TYPE_VIDEO_OUTPUT:
-                       if (vfd->vidioc_g_fmt_vid_out)
-                               ret = vfd->vidioc_g_fmt_vid_out(file, fh, f);
-                       if (!ret)
-                               v4l_print_pix_fmt(vfd, &f->fmt.pix);
-                       break;
-               case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
-                       if (vfd->vidioc_g_fmt_vid_out_overlay)
-                               ret = vfd->vidioc_g_fmt_vid_out_overlay(file,
-                                      fh, f);
-                       break;
-               case V4L2_BUF_TYPE_VBI_CAPTURE:
-                       if (vfd->vidioc_g_fmt_vbi_cap)
-                               ret = vfd->vidioc_g_fmt_vbi_cap(file, fh, f);
-                       break;
-               case V4L2_BUF_TYPE_VBI_OUTPUT:
-                       if (vfd->vidioc_g_fmt_vbi_out)
-                               ret = vfd->vidioc_g_fmt_vbi_out(file, fh, f);
-                       break;
-               case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
-                       if (vfd->vidioc_g_fmt_sliced_vbi_cap)
-                               ret = vfd->vidioc_g_fmt_sliced_vbi_cap(file,
-                                                                       fh, f);
-                       break;
-               case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
-                       if (vfd->vidioc_g_fmt_sliced_vbi_out)
-                               ret = vfd->vidioc_g_fmt_sliced_vbi_out(file,
-                                                                       fh, f);
-                       break;
-               case V4L2_BUF_TYPE_PRIVATE:
-                       if (vfd->vidioc_g_fmt_type_private)
-                               ret = vfd->vidioc_g_fmt_type_private(file,
-                                                               fh, f);
-                       break;
-               }
-
-               break;
-       }
-       case VIDIOC_S_FMT:
-       {
-               struct v4l2_format *f = (struct v4l2_format *)arg;
-
-               /* FIXME: Should be one dump per type */
-               dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
-
-               switch (f->type) {
-               case V4L2_BUF_TYPE_VIDEO_CAPTURE:
-                       v4l_print_pix_fmt(vfd, &f->fmt.pix);
-                       if (vfd->vidioc_s_fmt_vid_cap)
-                               ret = vfd->vidioc_s_fmt_vid_cap(file, fh, f);
-                       break;
-               case V4L2_BUF_TYPE_VIDEO_OVERLAY:
-                       if (vfd->vidioc_s_fmt_vid_overlay)
-                               ret = vfd->vidioc_s_fmt_vid_overlay(file,
-                                                                   fh, f);
-                       break;
-               case V4L2_BUF_TYPE_VIDEO_OUTPUT:
-                       v4l_print_pix_fmt(vfd, &f->fmt.pix);
-                       if (vfd->vidioc_s_fmt_vid_out)
-                               ret = vfd->vidioc_s_fmt_vid_out(file, fh, f);
-                       break;
-               case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
-                       if (vfd->vidioc_s_fmt_vid_out_overlay)
-                               ret = vfd->vidioc_s_fmt_vid_out_overlay(file,
-                                       fh, f);
-                       break;
-               case V4L2_BUF_TYPE_VBI_CAPTURE:
-                       if (vfd->vidioc_s_fmt_vbi_cap)
-                               ret = vfd->vidioc_s_fmt_vbi_cap(file, fh, f);
-                       break;
-               case V4L2_BUF_TYPE_VBI_OUTPUT:
-                       if (vfd->vidioc_s_fmt_vbi_out)
-                               ret = vfd->vidioc_s_fmt_vbi_out(file, fh, f);
-                       break;
-               case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
-                       if (vfd->vidioc_s_fmt_sliced_vbi_cap)
-                               ret = vfd->vidioc_s_fmt_sliced_vbi_cap(file,
-                                                                       fh, f);
-                       break;
-               case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
-                       if (vfd->vidioc_s_fmt_sliced_vbi_out)
-                               ret = vfd->vidioc_s_fmt_sliced_vbi_out(file,
-                                                                       fh, f);
-                       break;
-               case V4L2_BUF_TYPE_PRIVATE:
-                       if (vfd->vidioc_s_fmt_type_private)
-                               ret = vfd->vidioc_s_fmt_type_private(file,
-                                                               fh, f);
-                       break;
-               }
-               break;
-       }
-       case VIDIOC_TRY_FMT:
-       {
-               struct v4l2_format *f = (struct v4l2_format *)arg;
-
-               /* FIXME: Should be one dump per type */
-               dbgarg (cmd, "type=%s\n", prt_names(f->type,
-                                               v4l2_type_names));
-               switch (f->type) {
-               case V4L2_BUF_TYPE_VIDEO_CAPTURE:
-                       if (vfd->vidioc_try_fmt_vid_cap)
-                               ret = vfd->vidioc_try_fmt_vid_cap(file, fh, f);
-                       if (!ret)
-                               v4l_print_pix_fmt(vfd, &f->fmt.pix);
-                       break;
-               case V4L2_BUF_TYPE_VIDEO_OVERLAY:
-                       if (vfd->vidioc_try_fmt_vid_overlay)
-                               ret = vfd->vidioc_try_fmt_vid_overlay(file,
-                                       fh, f);
-                       break;
-               case V4L2_BUF_TYPE_VIDEO_OUTPUT:
-                       if (vfd->vidioc_try_fmt_vid_out)
-                               ret = vfd->vidioc_try_fmt_vid_out(file, fh, f);
-                       if (!ret)
-                               v4l_print_pix_fmt(vfd, &f->fmt.pix);
-                       break;
-               case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
-                       if (vfd->vidioc_try_fmt_vid_out_overlay)
-                               ret = vfd->vidioc_try_fmt_vid_out_overlay(file,
-                                      fh, f);
-                       break;
-               case V4L2_BUF_TYPE_VBI_CAPTURE:
-                       if (vfd->vidioc_try_fmt_vbi_cap)
-                               ret = vfd->vidioc_try_fmt_vbi_cap(file, fh, f);
-                       break;
-               case V4L2_BUF_TYPE_VBI_OUTPUT:
-                       if (vfd->vidioc_try_fmt_vbi_out)
-                               ret = vfd->vidioc_try_fmt_vbi_out(file, fh, f);
-                       break;
-               case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
-                       if (vfd->vidioc_try_fmt_sliced_vbi_cap)
-                               ret = vfd->vidioc_try_fmt_sliced_vbi_cap(file,
-                                                               fh, f);
-                       break;
-               case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
-                       if (vfd->vidioc_try_fmt_sliced_vbi_out)
-                               ret = vfd->vidioc_try_fmt_sliced_vbi_out(file,
-                                                               fh, f);
-                       break;
-               case V4L2_BUF_TYPE_PRIVATE:
-                       if (vfd->vidioc_try_fmt_type_private)
-                               ret = vfd->vidioc_try_fmt_type_private(file,
-                                                               fh, f);
-                       break;
-               }
-
-               break;
-       }
-       /* FIXME: Those buf reqs could be handled here,
-          with some changes on videobuf to allow its header to be included at
-          videodev2.h or being merged at videodev2.
-        */
-       case VIDIOC_REQBUFS:
-       {
-               struct v4l2_requestbuffers *p=arg;
-
-               if (!vfd->vidioc_reqbufs)
-                       break;
-               ret = check_fmt (vfd, p->type);
-               if (ret)
-                       break;
-
-               ret=vfd->vidioc_reqbufs(file, fh, p);
-               dbgarg (cmd, "count=%d, type=%s, memory=%s\n",
-                               p->count,
-                               prt_names(p->type, v4l2_type_names),
-                               prt_names(p->memory, v4l2_memory_names));
-               break;
-       }
-       case VIDIOC_QUERYBUF:
-       {
-               struct v4l2_buffer *p=arg;
-
-               if (!vfd->vidioc_querybuf)
-                       break;
-               ret = check_fmt (vfd, p->type);
-               if (ret)
-                       break;
-
-               ret=vfd->vidioc_querybuf(file, fh, p);
-               if (!ret)
-                       dbgbuf(cmd,vfd,p);
-               break;
-       }
-       case VIDIOC_QBUF:
-       {
-               struct v4l2_buffer *p=arg;
-
-               if (!vfd->vidioc_qbuf)
-                       break;
-               ret = check_fmt (vfd, p->type);
-               if (ret)
-                       break;
-
-               ret=vfd->vidioc_qbuf(file, fh, p);
-               if (!ret)
-                       dbgbuf(cmd,vfd,p);
-               break;
-       }
-       case VIDIOC_DQBUF:
-       {
-               struct v4l2_buffer *p=arg;
-               if (!vfd->vidioc_dqbuf)
-                       break;
-               ret = check_fmt (vfd, p->type);
-               if (ret)
-                       break;
-
-               ret=vfd->vidioc_dqbuf(file, fh, p);
-               if (!ret)
-                       dbgbuf(cmd,vfd,p);
-               break;
-       }
-       case VIDIOC_OVERLAY:
-       {
-               int *i = arg;
-
-               if (!vfd->vidioc_overlay)
-                       break;
-               dbgarg (cmd, "value=%d\n",*i);
-               ret=vfd->vidioc_overlay(file, fh, *i);
-               break;
-       }
-       case VIDIOC_G_FBUF:
-       {
-               struct v4l2_framebuffer *p = arg;
-
-               if (!vfd->vidioc_g_fbuf)
-                       break;
-               ret = vfd->vidioc_g_fbuf(file, fh, arg);
-               if (!ret) {
-                       dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
-                                       p->capability, p->flags,
-                                       (unsigned long)p->base);
-                       v4l_print_pix_fmt(vfd, &p->fmt);
-               }
-               break;
-       }
-       case VIDIOC_S_FBUF:
-       {
-               struct v4l2_framebuffer *p = arg;
-
-               if (!vfd->vidioc_s_fbuf)
-                       break;
-               dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
-                       p->capability, p->flags, (unsigned long)p->base);
-               v4l_print_pix_fmt(vfd, &p->fmt);
-               ret = vfd->vidioc_s_fbuf(file, fh, arg);
-               break;
-       }
-       case VIDIOC_STREAMON:
-       {
-               enum v4l2_buf_type i = *(int *)arg;
-               if (!vfd->vidioc_streamon)
-                       break;
-               dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
-               ret=vfd->vidioc_streamon(file, fh,i);
-               break;
-       }
-       case VIDIOC_STREAMOFF:
-       {
-               enum v4l2_buf_type i = *(int *)arg;
-
-               if (!vfd->vidioc_streamoff)
-                       break;
-               dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
-               ret=vfd->vidioc_streamoff(file, fh, i);
-               break;
-       }
-       /* ---------- tv norms ---------- */
-       case VIDIOC_ENUMSTD:
-       {
-               struct v4l2_standard *p = arg;
-               v4l2_std_id id = vfd->tvnorms, curr_id = 0;
-               unsigned int index = p->index, i, j = 0;
-               const char *descr = "";
-
-               /* Return norm array in a canonical way */
-               for (i = 0; i <= index && id; i++) {
-                       /* last std value in the standards array is 0, so this
-                          while always ends there since (id & 0) == 0. */
-                       while ((id & standards[j].std) != standards[j].std)
-                               j++;
-                       curr_id = standards[j].std;
-                       descr = standards[j].descr;
-                       j++;
-                       if (curr_id == 0)
-                               break;
-                       if (curr_id != V4L2_STD_PAL &&
-                           curr_id != V4L2_STD_SECAM &&
-                           curr_id != V4L2_STD_NTSC)
-                               id &= ~curr_id;
-               }
-               if (i <= index)
-                       return -EINVAL;
-
-               v4l2_video_std_construct(p, curr_id, descr);
-               p->index = index;
-
-               dbgarg(cmd, "index=%d, id=0x%Lx, name=%s, fps=%d/%d, "
-                               "framelines=%d\n", p->index,
-                               (unsigned long long)p->id, p->name,
-                               p->frameperiod.numerator,
-                               p->frameperiod.denominator,
-                               p->framelines);
-
-               ret = 0;
-               break;
-       }
-       case VIDIOC_G_STD:
-       {
-               v4l2_std_id *id = arg;
-
-               ret = 0;
-               /* Calls the specific handler */
-               if (vfd->vidioc_g_std)
-                       ret = vfd->vidioc_g_std(file, fh, id);
-               else
-                       *id = vfd->current_norm;
-
-               if (!ret)
-                       dbgarg(cmd, "std=0x%08Lx\n", (long long unsigned)*id);
-               break;
-       }
-       case VIDIOC_S_STD:
-       {
-               v4l2_std_id *id = arg,norm;
-
-               dbgarg(cmd, "std=%08Lx\n", (long long unsigned)*id);
-
-               norm = (*id) & vfd->tvnorms;
-               if ( vfd->tvnorms && !norm)     /* Check if std is supported */
-                       break;
-
-               /* Calls the specific handler */
-               if (vfd->vidioc_s_std)
-                       ret=vfd->vidioc_s_std(file, fh, &norm);
-               else
-                       ret=-EINVAL;
-
-               /* Updates standard information */
-               if (ret>=0)
-                       vfd->current_norm=norm;
-
-               break;
-       }
-       case VIDIOC_QUERYSTD:
-       {
-               v4l2_std_id *p=arg;
-
-               if (!vfd->vidioc_querystd)
-                       break;
-               ret=vfd->vidioc_querystd(file, fh, arg);
-               if (!ret)
-                       dbgarg (cmd, "detected std=%08Lx\n",
-                                               (unsigned long long)*p);
-               break;
-       }
-       /* ------ input switching ---------- */
-       /* FIXME: Inputs can be handled inside videodev2 */
-       case VIDIOC_ENUMINPUT:
-       {
-               struct v4l2_input *p=arg;
-               int i=p->index;
-
-               if (!vfd->vidioc_enum_input)
-                       break;
-               memset(p, 0, sizeof(*p));
-               p->index=i;
-
-               ret=vfd->vidioc_enum_input(file, fh, p);
-               if (!ret)
-                       dbgarg (cmd, "index=%d, name=%s, type=%d, "
-                                       "audioset=%d, "
-                                       "tuner=%d, std=%08Lx, status=%d\n",
-                                       p->index,p->name,p->type,p->audioset,
-                                       p->tuner,
-                                       (unsigned long long)p->std,
-                                       p->status);
-               break;
-       }
-       case VIDIOC_G_INPUT:
-       {
-               unsigned int *i = arg;
-
-               if (!vfd->vidioc_g_input)
-                       break;
-               ret=vfd->vidioc_g_input(file, fh, i);
-               if (!ret)
-                       dbgarg (cmd, "value=%d\n",*i);
-               break;
-       }
-       case VIDIOC_S_INPUT:
-       {
-               unsigned int *i = arg;
-
-               if (!vfd->vidioc_s_input)
-                       break;
-               dbgarg (cmd, "value=%d\n",*i);
-               ret=vfd->vidioc_s_input(file, fh, *i);
-               break;
-       }
-
-       /* ------ output switching ---------- */
-       case VIDIOC_ENUMOUTPUT:
-       {
-               struct v4l2_output *p = arg;
-               int i = p->index;
-
-               if (!vfd->vidioc_enum_output)
-                       break;
-               memset(p, 0, sizeof(*p));
-               p->index = i;
-
-               ret = vfd->vidioc_enum_output(file, fh, p);
-               if (!ret)
-                       dbgarg(cmd, "index=%d, name=%s, type=%d, "
-                               "audioset=0x%x, "
-                               "modulator=%d, std=0x%08Lx\n",
-                               p->index, p->name, p->type, p->audioset,
-                               p->modulator, (unsigned long long)p->std);
-               break;
-       }
-       case VIDIOC_G_OUTPUT:
-       {
-               unsigned int *i = arg;
-
-               if (!vfd->vidioc_g_output)
-                       break;
-               ret=vfd->vidioc_g_output(file, fh, i);
-               if (!ret)
-                       dbgarg (cmd, "value=%d\n",*i);
-               break;
-       }
-       case VIDIOC_S_OUTPUT:
-       {
-               unsigned int *i = arg;
-
-               if (!vfd->vidioc_s_output)
-                       break;
-               dbgarg (cmd, "value=%d\n",*i);
-               ret=vfd->vidioc_s_output(file, fh, *i);
-               break;
-       }
-
-       /* --- controls ---------------------------------------------- */
-       case VIDIOC_QUERYCTRL:
-       {
-               struct v4l2_queryctrl *p = arg;
-
-               if (!vfd->vidioc_queryctrl)
-                       break;
-               ret = vfd->vidioc_queryctrl(file, fh, p);
-               if (!ret)
-                       dbgarg(cmd, "id=0x%x, type=%d, name=%s, min/max=%d/%d, "
-                                       "step=%d, default=%d, flags=0x%08x\n",
-                                       p->id, p->type, p->name,
-                                       p->minimum, p->maximum,
-                                       p->step, p->default_value, p->flags);
-               else
-                       dbgarg(cmd, "id=0x%x\n", p->id);
-               break;
-       }
-       case VIDIOC_G_CTRL:
-       {
-               struct v4l2_control *p = arg;
-
-               if (vfd->vidioc_g_ctrl)
-                       ret = vfd->vidioc_g_ctrl(file, fh, p);
-               else if (vfd->vidioc_g_ext_ctrls) {
-                       struct v4l2_ext_controls ctrls;
-                       struct v4l2_ext_control ctrl;
-
-                       ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
-                       ctrls.count = 1;
-                       ctrls.controls = &ctrl;
-                       ctrl.id = p->id;
-                       ctrl.value = p->value;
-                       if (check_ext_ctrls(&ctrls, 1)) {
-                               ret = vfd->vidioc_g_ext_ctrls(file, fh, &ctrls);
-                               if (ret == 0)
-                                       p->value = ctrl.value;
-                       }
-               } else
-                       break;
-               if (!ret)
-                       dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
-               else
-                       dbgarg(cmd, "id=0x%x\n", p->id);
-               break;
-       }
-       case VIDIOC_S_CTRL:
-       {
-               struct v4l2_control *p = arg;
-               struct v4l2_ext_controls ctrls;
-               struct v4l2_ext_control ctrl;
-
-               if (!vfd->vidioc_s_ctrl && !vfd->vidioc_s_ext_ctrls)
-                       break;
-
-               dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
-
-               if (vfd->vidioc_s_ctrl) {
-                       ret = vfd->vidioc_s_ctrl(file, fh, p);
-                       break;
-               }
-               if (!vfd->vidioc_s_ext_ctrls)
-                       break;
-
-               ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
-               ctrls.count = 1;
-               ctrls.controls = &ctrl;
-               ctrl.id = p->id;
-               ctrl.value = p->value;
-               if (check_ext_ctrls(&ctrls, 1))
-                       ret = vfd->vidioc_s_ext_ctrls(file, fh, &ctrls);
-               break;
-       }
-       case VIDIOC_G_EXT_CTRLS:
-       {
-               struct v4l2_ext_controls *p = arg;
-
-               p->error_idx = p->count;
-               if (!vfd->vidioc_g_ext_ctrls)
-                       break;
-               if (check_ext_ctrls(p, 0))
-                       ret = vfd->vidioc_g_ext_ctrls(file, fh, p);
-               v4l_print_ext_ctrls(cmd, vfd, p, !ret);
-               break;
-       }
-       case VIDIOC_S_EXT_CTRLS:
-       {
-               struct v4l2_ext_controls *p = arg;
-
-               p->error_idx = p->count;
-               if (!vfd->vidioc_s_ext_ctrls)
-                       break;
-               v4l_print_ext_ctrls(cmd, vfd, p, 1);
-               if (check_ext_ctrls(p, 0))
-                       ret = vfd->vidioc_s_ext_ctrls(file, fh, p);
-               break;
-       }
-       case VIDIOC_TRY_EXT_CTRLS:
-       {
-               struct v4l2_ext_controls *p = arg;
-
-               p->error_idx = p->count;
-               if (!vfd->vidioc_try_ext_ctrls)
-                       break;
-               v4l_print_ext_ctrls(cmd, vfd, p, 1);
-               if (check_ext_ctrls(p, 0))
-                       ret = vfd->vidioc_try_ext_ctrls(file, fh, p);
-               break;
-       }
-       case VIDIOC_QUERYMENU:
-       {
-               struct v4l2_querymenu *p = arg;
-
-               if (!vfd->vidioc_querymenu)
-                       break;
-               ret = vfd->vidioc_querymenu(file, fh, p);
-               if (!ret)
-                       dbgarg(cmd, "id=0x%x, index=%d, name=%s\n",
-                               p->id, p->index, p->name);
-               else
-                       dbgarg(cmd, "id=0x%x, index=%d\n",
-                               p->id, p->index);
-               break;
-       }
-       /* --- audio ---------------------------------------------- */
-       case VIDIOC_ENUMAUDIO:
-       {
-               struct v4l2_audio *p = arg;
-
-               if (!vfd->vidioc_enumaudio)
-                       break;
-               ret = vfd->vidioc_enumaudio(file, fh, p);
-               if (!ret)
-                       dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
-                                       "mode=0x%x\n", p->index, p->name,
-                                       p->capability, p->mode);
-               else
-                       dbgarg(cmd, "index=%d\n", p->index);
-               break;
-       }
-       case VIDIOC_G_AUDIO:
-       {
-               struct v4l2_audio *p = arg;
-               __u32 index = p->index;
-
-               if (!vfd->vidioc_g_audio)
-                       break;
-
-               memset(p, 0, sizeof(*p));
-               p->index = index;
-               ret = vfd->vidioc_g_audio(file, fh, p);
-               if (!ret)
-                       dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
-                                       "mode=0x%x\n", p->index,
-                                       p->name, p->capability, p->mode);
-               else
-                       dbgarg(cmd, "index=%d\n", p->index);
-               break;
-       }
-       case VIDIOC_S_AUDIO:
-       {
-               struct v4l2_audio *p = arg;
-
-               if (!vfd->vidioc_s_audio)
-                       break;
-               dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
-                                       "mode=0x%x\n", p->index, p->name,
-                                       p->capability, p->mode);
-               ret = vfd->vidioc_s_audio(file, fh, p);
-               break;
-       }
-       case VIDIOC_ENUMAUDOUT:
-       {
-               struct v4l2_audioout *p=arg;
-
-               if (!vfd->vidioc_enumaudout)
-                       break;
-               dbgarg(cmd, "Enum for index=%d\n", p->index);
-               ret=vfd->vidioc_enumaudout(file, fh, p);
-               if (!ret)
-                       dbgarg2("index=%d, name=%s, capability=%d, "
-                                       "mode=%d\n", p->index, p->name,
-                                       p->capability,p->mode);
-               break;
-       }
-       case VIDIOC_G_AUDOUT:
-       {
-               struct v4l2_audioout *p=arg;
-
-               if (!vfd->vidioc_g_audout)
-                       break;
-               dbgarg(cmd, "Enum for index=%d\n", p->index);
-               ret=vfd->vidioc_g_audout(file, fh, p);
-               if (!ret)
-                       dbgarg2("index=%d, name=%s, capability=%d, "
-                                       "mode=%d\n", p->index, p->name,
-                                       p->capability,p->mode);
-               break;
-       }
-       case VIDIOC_S_AUDOUT:
-       {
-               struct v4l2_audioout *p=arg;
-
-               if (!vfd->vidioc_s_audout)
-                       break;
-               dbgarg(cmd, "index=%d, name=%s, capability=%d, "
-                                       "mode=%d\n", p->index, p->name,
-                                       p->capability,p->mode);
-
-               ret=vfd->vidioc_s_audout(file, fh, p);
-               break;
-       }
-       case VIDIOC_G_MODULATOR:
-       {
-               struct v4l2_modulator *p=arg;
-               if (!vfd->vidioc_g_modulator)
-                       break;
-               ret=vfd->vidioc_g_modulator(file, fh, p);
-               if (!ret)
-                       dbgarg(cmd, "index=%d, name=%s, "
-                                       "capability=%d, rangelow=%d,"
-                                       " rangehigh=%d, txsubchans=%d\n",
-                                       p->index, p->name,p->capability,
-                                       p->rangelow, p->rangehigh,
-                                       p->txsubchans);
-               break;
-       }
-       case VIDIOC_S_MODULATOR:
-       {
-               struct v4l2_modulator *p=arg;
-               if (!vfd->vidioc_s_modulator)
-                       break;
-               dbgarg(cmd, "index=%d, name=%s, capability=%d, "
-                               "rangelow=%d, rangehigh=%d, txsubchans=%d\n",
-                               p->index, p->name,p->capability,p->rangelow,
-                               p->rangehigh,p->txsubchans);
-                       ret=vfd->vidioc_s_modulator(file, fh, p);
-               break;
-       }
-       case VIDIOC_G_CROP:
-       {
-               struct v4l2_crop *p=arg;
-               if (!vfd->vidioc_g_crop)
-                       break;
-               dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
-               ret=vfd->vidioc_g_crop(file, fh, p);
-               if (!ret) {
-                       dbgrect(vfd, "", &p->c);
-               }
-               break;
-       }
-       case VIDIOC_S_CROP:
-       {
-               struct v4l2_crop *p=arg;
-               if (!vfd->vidioc_s_crop)
-                       break;
-               dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
-               dbgrect(vfd, "", &p->c);
-               ret=vfd->vidioc_s_crop(file, fh, p);
-               break;
-       }
-       case VIDIOC_CROPCAP:
-       {
-               struct v4l2_cropcap *p = arg;
-
-               /*FIXME: Should also show v4l2_fract pixelaspect */
-               if (!vfd->vidioc_cropcap)
-                       break;
-               dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
-               ret = vfd->vidioc_cropcap(file, fh, p);
-               if (!ret) {
-                       dbgrect(vfd, "bounds ", &p->bounds);
-                       dbgrect(vfd, "defrect ", &p->defrect);
-               }
-               break;
-       }
-       case VIDIOC_G_JPEGCOMP:
-       {
-               struct v4l2_jpegcompression *p=arg;
-               if (!vfd->vidioc_g_jpegcomp)
-                       break;
-               ret=vfd->vidioc_g_jpegcomp(file, fh, p);
-               if (!ret)
-                       dbgarg (cmd, "quality=%d, APPn=%d, "
-                                               "APP_len=%d, COM_len=%d, "
-                                               "jpeg_markers=%d\n",
-                                               p->quality,p->APPn,p->APP_len,
-                                               p->COM_len,p->jpeg_markers);
-               break;
-       }
-       case VIDIOC_S_JPEGCOMP:
-       {
-               struct v4l2_jpegcompression *p=arg;
-               if (!vfd->vidioc_g_jpegcomp)
-                       break;
-               dbgarg (cmd, "quality=%d, APPn=%d, APP_len=%d, "
-                                       "COM_len=%d, jpeg_markers=%d\n",
-                                       p->quality,p->APPn,p->APP_len,
-                                       p->COM_len,p->jpeg_markers);
-                       ret=vfd->vidioc_s_jpegcomp(file, fh, p);
-               break;
-       }
-       case VIDIOC_G_ENC_INDEX:
-       {
-               struct v4l2_enc_idx *p=arg;
-
-               if (!vfd->vidioc_g_enc_index)
-                       break;
-               ret=vfd->vidioc_g_enc_index(file, fh, p);
-               if (!ret)
-                       dbgarg (cmd, "entries=%d, entries_cap=%d\n",
-                                       p->entries,p->entries_cap);
-               break;
-       }
-       case VIDIOC_ENCODER_CMD:
-       {
-               struct v4l2_encoder_cmd *p = arg;
-
-               if (!vfd->vidioc_encoder_cmd)
-                       break;
-               memset(&p->raw, 0, sizeof(p->raw));
-               ret = vfd->vidioc_encoder_cmd(file, fh, p);
-               if (!ret)
-                       dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
-               break;
-       }
-       case VIDIOC_TRY_ENCODER_CMD:
-       {
-               struct v4l2_encoder_cmd *p = arg;
-
-               if (!vfd->vidioc_try_encoder_cmd)
-                       break;
-               memset(&p->raw, 0, sizeof(p->raw));
-               ret = vfd->vidioc_try_encoder_cmd(file, fh, p);
-               if (!ret)
-                       dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
-               break;
-       }
-       case VIDIOC_G_PARM:
-       {
-               struct v4l2_streamparm *p=arg;
-               __u32 type=p->type;
-
-               memset(p,0,sizeof(*p));
-               p->type=type;
-
-               if (vfd->vidioc_g_parm) {
-                       ret=vfd->vidioc_g_parm(file, fh, p);
-               } else {
-                       struct v4l2_standard s;
-
-                       if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
-                               return -EINVAL;
-
-                       v4l2_video_std_construct(&s, vfd->current_norm,
-                                                v4l2_norm_to_name(vfd->current_norm));
-
-                       p->parm.capture.timeperframe = s.frameperiod;
-                       ret=0;
-               }
-
-               dbgarg (cmd, "type=%d\n", p->type);
-               break;
-       }
-       case VIDIOC_S_PARM:
-       {
-               struct v4l2_streamparm *p=arg;
-               if (!vfd->vidioc_s_parm)
-                       break;
-               dbgarg (cmd, "type=%d\n", p->type);
-               ret=vfd->vidioc_s_parm(file, fh, p);
-               break;
-       }
-       case VIDIOC_G_TUNER:
-       {
-               struct v4l2_tuner *p = arg;
-               __u32 index = p->index;
-
-               if (!vfd->vidioc_g_tuner)
-                       break;
-
-               memset(p, 0, sizeof(*p));
-               p->index = index;
-
-               ret = vfd->vidioc_g_tuner(file, fh, p);
-               if (!ret)
-                       dbgarg(cmd, "index=%d, name=%s, type=%d, "
-                                       "capability=0x%x, rangelow=%d, "
-                                       "rangehigh=%d, signal=%d, afc=%d, "
-                                       "rxsubchans=0x%x, audmode=%d\n",
-                                       p->index, p->name, p->type,
-                                       p->capability, p->rangelow,
-                                       p->rangehigh, p->signal, p->afc,
-                                       p->rxsubchans, p->audmode);
-               break;
-       }
-       case VIDIOC_S_TUNER:
-       {
-               struct v4l2_tuner *p = arg;
-
-               if (!vfd->vidioc_s_tuner)
-                       break;
-               dbgarg(cmd, "index=%d, name=%s, type=%d, "
-                               "capability=0x%x, rangelow=%d, "
-                               "rangehigh=%d, signal=%d, afc=%d, "
-                               "rxsubchans=0x%x, audmode=%d\n",
-                               p->index, p->name, p->type,
-                               p->capability, p->rangelow,
-                               p->rangehigh, p->signal, p->afc,
-                               p->rxsubchans, p->audmode);
-               ret = vfd->vidioc_s_tuner(file, fh, p);
-               break;
-       }
-       case VIDIOC_G_FREQUENCY:
-       {
-               struct v4l2_frequency *p = arg;
-
-               if (!vfd->vidioc_g_frequency)
-                       break;
-
-               memset(p->reserved, 0, sizeof(p->reserved));
-
-               ret = vfd->vidioc_g_frequency(file, fh, p);
-               if (!ret)
-                       dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
-                                       p->tuner, p->type, p->frequency);
-               break;
-       }
-       case VIDIOC_S_FREQUENCY:
-       {
-               struct v4l2_frequency *p=arg;
-               if (!vfd->vidioc_s_frequency)
-                       break;
-               dbgarg (cmd, "tuner=%d, type=%d, frequency=%d\n",
-                               p->tuner,p->type,p->frequency);
-               ret=vfd->vidioc_s_frequency(file, fh, p);
-               break;
-       }
-       case VIDIOC_G_SLICED_VBI_CAP:
-       {
-               struct v4l2_sliced_vbi_cap *p = arg;
-               __u32 type = p->type;
-
-               if (!vfd->vidioc_g_sliced_vbi_cap)
-                       break;
-               memset(p, 0, sizeof(*p));
-               p->type = type;
-               dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
-               ret = vfd->vidioc_g_sliced_vbi_cap(file, fh, p);
-               if (!ret)
-                       dbgarg2("service_set=%d\n", p->service_set);
-               break;
-       }
-       case VIDIOC_LOG_STATUS:
-       {
-               if (!vfd->vidioc_log_status)
-                       break;
-               ret=vfd->vidioc_log_status(file, fh);
-               break;
-       }
-#ifdef CONFIG_VIDEO_ADV_DEBUG
-       case VIDIOC_DBG_G_REGISTER:
-       {
-               struct v4l2_register *p=arg;
-               if (!capable(CAP_SYS_ADMIN))
-                       ret=-EPERM;
-               else if (vfd->vidioc_g_register)
-                       ret=vfd->vidioc_g_register(file, fh, p);
-               break;
-       }
-       case VIDIOC_DBG_S_REGISTER:
-       {
-               struct v4l2_register *p=arg;
-               if (!capable(CAP_SYS_ADMIN))
-                       ret=-EPERM;
-               else if (vfd->vidioc_s_register)
-                       ret=vfd->vidioc_s_register(file, fh, p);
-               break;
-       }
-#endif
-       case VIDIOC_G_CHIP_IDENT:
-       {
-               struct v4l2_chip_ident *p=arg;
-               if (!vfd->vidioc_g_chip_ident)
-                       break;
-               ret=vfd->vidioc_g_chip_ident(file, fh, p);
-               if (!ret)
-                       dbgarg (cmd, "chip_ident=%u, revision=0x%x\n", p->ident, p->revision);
-               break;
-       }
-       default:
-       {
-               if (!vfd->vidioc_default)
-                       break;
-               ret = vfd->vidioc_default(file, fh, cmd, arg);
-               break;
-       }
-       case VIDIOC_S_HW_FREQ_SEEK:
-       {
-               struct v4l2_hw_freq_seek *p = arg;
-               if (!vfd->vidioc_s_hw_freq_seek)
-                       break;
-               dbgarg(cmd,
-                       "tuner=%d, type=%d, seek_upward=%d, wrap_around=%d\n",
-                       p->tuner, p->type, p->seek_upward, p->wrap_around);
-               ret = vfd->vidioc_s_hw_freq_seek(file, fh, p);
-               break;
-       }
-       } /* switch */
-
-       if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {
-               if (ret < 0) {
-                       v4l_print_ioctl(vfd->name, cmd);
-                       printk(KERN_CONT " error %d\n", ret);
-               }
-       }
-
-       return ret;
-}
-
-int video_ioctl2 (struct inode *inode, struct file *file,
-              unsigned int cmd, unsigned long arg)
-{
-       char    sbuf[128];
-       void    *mbuf = NULL;
-       void    *parg = NULL;
-       int     err  = -EINVAL;
-       int     is_ext_ctrl;
-       size_t  ctrls_size = 0;
-       void __user *user_ptr = NULL;
-
-#ifdef __OLD_VIDIOC_
-       cmd = video_fix_command(cmd);
-#endif
-       is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS ||
-                      cmd == VIDIOC_TRY_EXT_CTRLS);
-
-       /*  Copy arguments into temp kernel buffer  */
-       switch (_IOC_DIR(cmd)) {
-       case _IOC_NONE:
-               parg = NULL;
-               break;
-       case _IOC_READ:
-       case _IOC_WRITE:
-       case (_IOC_WRITE | _IOC_READ):
-               if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
-                       parg = sbuf;
-               } else {
-                       /* too big to allocate from stack */
-                       mbuf = kmalloc(_IOC_SIZE(cmd),GFP_KERNEL);
-                       if (NULL == mbuf)
-                               return -ENOMEM;
-                       parg = mbuf;
-               }
-
-               err = -EFAULT;
-               if (_IOC_DIR(cmd) & _IOC_WRITE)
-                       if (copy_from_user(parg, (void __user *)arg, _IOC_SIZE(cmd)))
-                               goto out;
-               break;
-       }
-
-       if (is_ext_ctrl) {
-               struct v4l2_ext_controls *p = parg;
-
-               /* In case of an error, tell the caller that it wasn't
-                  a specific control that caused it. */
-               p->error_idx = p->count;
-               user_ptr = (void __user *)p->controls;
-               if (p->count) {
-                       ctrls_size = sizeof(struct v4l2_ext_control) * p->count;
-                       /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
-                       mbuf = kmalloc(ctrls_size, GFP_KERNEL);
-                       err = -ENOMEM;
-                       if (NULL == mbuf)
-                               goto out_ext_ctrl;
-                       err = -EFAULT;
-                       if (copy_from_user(mbuf, user_ptr, ctrls_size))
-                               goto out_ext_ctrl;
-                       p->controls = mbuf;
-               }
-       }
-
-       /* Handles IOCTL */
-       err = __video_do_ioctl(inode, file, cmd, parg);
-       if (err == -ENOIOCTLCMD)
-               err = -EINVAL;
-       if (is_ext_ctrl) {
-               struct v4l2_ext_controls *p = parg;
-
-               p->controls = (void *)user_ptr;
-               if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size))
-                       err = -EFAULT;
-               goto out_ext_ctrl;
-       }
-       if (err < 0)
-               goto out;
-
-out_ext_ctrl:
-       /*  Copy results into user buffer  */
-       switch (_IOC_DIR(cmd))
-       {
-       case _IOC_READ:
-       case (_IOC_WRITE | _IOC_READ):
-               if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
-                       err = -EFAULT;
-               break;
-       }
-
-out:
-       kfree(mbuf);
-       return err;
-}
-EXPORT_SYMBOL(video_ioctl2);
-
-/**
- * get_index - assign stream number based on parent device
- * @vdev: video_device to assign index number to, vdev->dev should be assigned
- * @num: -1 if auto assign, requested number otherwise
- *
- *
- * returns -ENFILE if num is already in use, a free index number if
- * successful.
- */
-static int get_index(struct video_device *vdev, int num)
-{
-       u32 used = 0;
-       const int max_index = sizeof(used) * 8 - 1;
-       int i;
-
-       /* Currently a single v4l driver instance cannot create more than
-          32 devices.
-          Increase to u64 or an array of u32 if more are needed. */
-       if (num > max_index) {
-               printk(KERN_ERR "videodev: %s num is too large\n", __func__);
-               return -EINVAL;
-       }
-
-       for (i = 0; i < VIDEO_NUM_DEVICES; i++) {
-               if (video_device[i] != NULL &&
-                   video_device[i] != vdev &&
-                   video_device[i]->dev == vdev->dev) {
-                       used |= 1 << video_device[i]->index;
-               }
-       }
-
-       if (num >= 0) {
-               if (used & (1 << num))
-                       return -ENFILE;
-               return num;
-       }
-
-       i = ffz(used);
-       return i > max_index ? -ENFILE : i;
-}
-
-static const struct file_operations video_fops;
-
-int video_register_device(struct video_device *vfd, int type, int nr)
-{
-       return video_register_device_index(vfd, type, nr, -1);
-}
-EXPORT_SYMBOL(video_register_device);
-
-/**
- *     video_register_device - register video4linux devices
- *     @vfd:  video device structure we want to register
- *     @type: type of device to register
- *     @nr:   which device number (0 == /dev/video0, 1 == /dev/video1, ...
- *             -1 == first free)
- *
- *     The registration code assigns minor numbers based on the type
- *     requested. -ENFILE is returned in all the device slots for this
- *     category are full. If not then the minor field is set and the
- *     driver initialize function is called (if non %NULL).
- *
- *     Zero is returned on success.
- *
- *     Valid types are
- *
- *     %VFL_TYPE_GRABBER - A frame grabber
- *
- *     %VFL_TYPE_VTX - A teletext device
- *
- *     %VFL_TYPE_VBI - Vertical blank data (undecoded)
- *
- *     %VFL_TYPE_RADIO - A radio card
- */
-
-int video_register_device_index(struct video_device *vfd, int type, int nr,
-                                       int index)
-{
-       int i=0;
-       int base;
-       int end;
-       int ret;
-       char *name_base;
-
-       switch(type)
-       {
-               case VFL_TYPE_GRABBER:
-                       base=MINOR_VFL_TYPE_GRABBER_MIN;
-                       end=MINOR_VFL_TYPE_GRABBER_MAX+1;
-                       name_base = "video";
-                       break;
-               case VFL_TYPE_VTX:
-                       base=MINOR_VFL_TYPE_VTX_MIN;
-                       end=MINOR_VFL_TYPE_VTX_MAX+1;
-                       name_base = "vtx";
-                       break;
-               case VFL_TYPE_VBI:
-                       base=MINOR_VFL_TYPE_VBI_MIN;
-                       end=MINOR_VFL_TYPE_VBI_MAX+1;
-                       name_base = "vbi";
-                       break;
-               case VFL_TYPE_RADIO:
-                       base=MINOR_VFL_TYPE_RADIO_MIN;
-                       end=MINOR_VFL_TYPE_RADIO_MAX+1;
-                       name_base = "radio";
-                       break;
-               default:
-                       printk(KERN_ERR "%s called with unknown type: %d\n",
-                              __func__, type);
-                       return -1;
-       }
-
-       /* pick a minor number */
-       mutex_lock(&videodev_lock);
-       if (nr >= 0  &&  nr < end-base) {
-               /* use the one the driver asked for */
-               i = base+nr;
-               if (NULL != video_device[i]) {
-                       mutex_unlock(&videodev_lock);
-                       return -ENFILE;
-               }
-       } else {
-               /* use first free */
-               for(i=base;i<end;i++)
-                       if (NULL == video_device[i])
-                               break;
-               if (i == end) {
-                       mutex_unlock(&videodev_lock);
-                       return -ENFILE;
-               }
-       }
-       video_device[i]=vfd;
-       vfd->minor=i;
-
-       ret = get_index(vfd, index);
-       vfd->index = ret;
-
-       mutex_unlock(&videodev_lock);
-
-       if (ret < 0) {
-               printk(KERN_ERR "%s: get_index failed\n", __func__);
-               goto fail_minor;
-       }
-
-       mutex_init(&vfd->lock);
-
-       /* sysfs class */
-       memset(&vfd->class_dev, 0x00, sizeof(vfd->class_dev));
-       vfd->class_dev.class       = &video_class;
-       vfd->class_dev.devt        = MKDEV(VIDEO_MAJOR, vfd->minor);
-       if (vfd->dev)
-               vfd->class_dev.parent = vfd->dev;
-       sprintf(vfd->class_dev.bus_id, "%s%d", name_base, i - base);
-       ret = device_register(&vfd->class_dev);
-       if (ret < 0) {
-               printk(KERN_ERR "%s: device_register failed\n", __func__);
-               goto fail_minor;
-       }
-
-#if 1
-       /* needed until all drivers are fixed */
-       if (!vfd->release)
-               printk(KERN_WARNING "videodev: \"%s\" has no release callback. "
-                      "Please fix your driver for proper sysfs support, see "
-                      "http://lwn.net/Articles/36850/\n", vfd->name);
-#endif
-       return 0;
-
-fail_minor:
-       mutex_lock(&videodev_lock);
-       video_device[vfd->minor] = NULL;
-       vfd->minor = -1;
-       mutex_unlock(&videodev_lock);
-       return ret;
-}
-EXPORT_SYMBOL(video_register_device_index);
-
-/**
- *     video_unregister_device - unregister a video4linux device
- *     @vfd: the device to unregister
- *
- *     This unregisters the passed device and deassigns the minor
- *     number. Future open calls will be met with errors.
- */
-
-void video_unregister_device(struct video_device *vfd)
-{
-       mutex_lock(&videodev_lock);
-       if(video_device[vfd->minor]!=vfd)
-               panic("videodev: bad unregister");
-
-       video_device[vfd->minor]=NULL;
-       device_unregister(&vfd->class_dev);
-       mutex_unlock(&videodev_lock);
-}
-EXPORT_SYMBOL(video_unregister_device);
-
-/*
- * Video fs operations
- */
-static const struct file_operations video_fops=
-{
-       .owner          = THIS_MODULE,
-       .llseek         = no_llseek,
-       .open           = video_open,
-};
-
-/*
- *     Initialise video for linux
- */
-
-static int __init videodev_init(void)
-{
-       int ret;
-
-       printk(KERN_INFO "Linux video capture interface: v2.00\n");
-       if (register_chrdev(VIDEO_MAJOR, VIDEO_NAME, &video_fops)) {
-               printk(KERN_WARNING "video_dev: unable to get major %d\n", VIDEO_MAJOR);
-               return -EIO;
-       }
-
-       ret = class_register(&video_class);
-       if (ret < 0) {
-               unregister_chrdev(VIDEO_MAJOR, VIDEO_NAME);
-               printk(KERN_WARNING "video_dev: class_register failed\n");
-               return -EIO;
-       }
-
-       return 0;
-}
-
-static void __exit videodev_exit(void)
-{
-       class_unregister(&video_class);
-       unregister_chrdev(VIDEO_MAJOR, VIDEO_NAME);
-}
-
-module_init(videodev_init)
-module_exit(videodev_exit)
-
-MODULE_AUTHOR("Alan Cox, Mauro Carvalho Chehab <mchehab@infradead.org>");
-MODULE_DESCRIPTION("Device registrar for Video4Linux drivers v2");
-MODULE_LICENSE("GPL");
-
-
-/*
- * Local variables:
- * c-basic-offset: 8
- * End:
- */
index 059b01c11dc133e4abb708ace787fa9cc3242843..e4b3a006c71e66a60d979064f83d5d6405a6576b 100644 (file)
@@ -35,6 +35,7 @@
 #include <linux/interrupt.h>
 #include <media/videobuf-vmalloc.h>
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 #include <linux/kthread.h>
 #include <linux/highmem.h>
 #include <linux/freezer.h>
index 33f702698a56f06d629bceb96bef454661282855..a63e11f8399b2b00225e10d83c9569481982613c 100644 (file)
@@ -59,6 +59,7 @@
 #include <linux/delay.h>
 #include <linux/videodev.h>
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 #include <linux/parport.h>
 
 /*#define DEBUG*/                              /* Undef me for production */
index 840522442d07d4a6316a76a7f658481da60de77f..56bbeec542c5fb0fde6e6e45fb239f3d6bb73677 100644 (file)
@@ -42,6 +42,7 @@
 #include <asm/page.h>
 #include <asm/uaccess.h>
 #include <linux/page-flags.h>
+#include <media/v4l2-ioctl.h>
 
 #include "w9968cf.h"
 #include "w9968cf_decoder.h"
@@ -3555,7 +3556,7 @@ w9968cf_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
        cam->v4ldev->minor = video_nr[dev_nr];
        cam->v4ldev->release = video_device_release;
        video_set_drvdata(cam->v4ldev, cam);
-       cam->v4ldev->dev = &cam->dev;
+       cam->v4ldev->parent = &cam->dev;
 
        err = video_register_device(cam->v4ldev, VFL_TYPE_GRABBER,
                                    video_nr[dev_nr]);
index 7bbab541a309d59f6141b7a0b10ff918baf945ce..b1b5cceb4baa3c0172720942693a68b0ad793a74 100644 (file)
@@ -25,6 +25,7 @@
 #include <linux/usb.h>
 #include <linux/videodev2.h>
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 #include <linux/device.h>
 #include <linux/list.h>
 #include <linux/spinlock.h>
index c0675921fe20465ff80f2d72881264d8a43f07f6..e1e1b19a0aed6b82a57edc996d53aa064a3e5256 100644 (file)
@@ -71,6 +71,7 @@
 
 #include <linux/videodev.h>
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 #include "videocodec.h"
 
 #include <asm/byteorder.h>
index 485df2e3613286292c842769efd8116f87c84b15..ea5265c229839975033d2a56891c074c6a52307a 100644 (file)
@@ -35,6 +35,7 @@
 #include <linux/proc_fs.h>
 #include <linux/highmem.h>
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 
 
 /* Version Information */
index 89c442eb884930b2f5f92de6e2da78ddd7845771..1d104096619cf78d779e573c6a6fb1795117e81c 100644 (file)
@@ -2,6 +2,7 @@
 #define __SAA7146_VV__
 
 #include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
 #include <media/saa7146.h>
 #include <media/videobuf-dma-sg.h>
 
index 020d05758bd8b951a352aabc043b0312de827800..07d3a9a575d1422c1d1b1cb16b7cf58e137111f2 100644 (file)
 
 #include <media/v4l2-dev.h>
 
-/* v4l debugging and diagnostics */
-
-/* Debug bitmask flags to be used on V4L2 */
-#define V4L2_DEBUG_IOCTL     0x01
-#define V4L2_DEBUG_IOCTL_ARG 0x02
-
 /* Common printk constucts for v4l-i2c drivers. These macros create a unique
    prefix consisting of the driver name, the adapter number and the i2c
    address. */
                        v4l_client_printk(KERN_DEBUG, client, fmt , ## arg); \
        } while (0)
 
+/* ------------------------------------------------------------------------- */
 
-/* Use this macro for non-I2C drivers. Pass the driver name as the first arg. */
-#define v4l_print_ioctl(name, cmd)              \
-       do {                                     \
-               printk(KERN_DEBUG "%s: ", name); \
-               v4l_printk_ioctl(cmd);           \
-       } while (0)
+/* Priority helper functions */
 
-/* Use this macro in I2C drivers where 'client' is the struct i2c_client
-   pointer */
-#define v4l_i2c_print_ioctl(client, cmd)                  \
-       do {                                               \
-               v4l_client_printk(KERN_DEBUG, client, ""); \
-               v4l_printk_ioctl(cmd);                     \
-       } while (0)
+struct v4l2_prio_state {
+       atomic_t prios[4];
+};
+int v4l2_prio_init(struct v4l2_prio_state *global);
+int v4l2_prio_change(struct v4l2_prio_state *global, enum v4l2_priority *local,
+                    enum v4l2_priority new);
+int v4l2_prio_open(struct v4l2_prio_state *global, enum v4l2_priority *local);
+int v4l2_prio_close(struct v4l2_prio_state *global, enum v4l2_priority *local);
+enum v4l2_priority v4l2_prio_max(struct v4l2_prio_state *global);
+int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority *local);
 
 /* ------------------------------------------------------------------------- */
 
index 33f379b1ecfeac87bfaf3d0c3cdf92137e8af802..ad62d322e1781d091eaf6294081182fb86596630 100644 (file)
 #define VFL_TYPE_RADIO         2
 #define VFL_TYPE_VTX           3
 
-/*  Video standard functions  */
-extern const char *v4l2_norm_to_name(v4l2_std_id id);
-extern int v4l2_video_std_construct(struct v4l2_standard *vs,
-                                   int id, const char *name);
-/* Prints the ioctl in a human-readable format */
-extern void v4l_printk_ioctl(unsigned int cmd);
-
-/* prority handling */
-struct v4l2_prio_state {
-       atomic_t prios[4];
-};
-int v4l2_prio_init(struct v4l2_prio_state *global);
-int v4l2_prio_change(struct v4l2_prio_state *global, enum v4l2_priority *local,
-                    enum v4l2_priority new);
-int v4l2_prio_open(struct v4l2_prio_state *global, enum v4l2_priority *local);
-int v4l2_prio_close(struct v4l2_prio_state *global, enum v4l2_priority *local);
-enum v4l2_priority v4l2_prio_max(struct v4l2_prio_state *global);
-int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority *local);
-
-/* names for fancy debug output */
-extern const char *v4l2_field_names[];
-extern const char *v4l2_type_names[];
-
-/*  Compatibility layer interface  --  v4l1-compat module */
-typedef int (*v4l2_kioctl)(struct inode *inode, struct file *file,
-                          unsigned int cmd, void *arg);
-#ifdef CONFIG_VIDEO_V4L1_COMPAT
-int v4l_compat_translate_ioctl(struct inode *inode, struct file *file,
-                              int cmd, void *arg, v4l2_kioctl driver_ioctl);
-#else
-#define v4l_compat_translate_ioctl(inode,file,cmd,arg,ioctl) -EINVAL
-#endif
-
-/* 32 Bits compatibility layer for 64 bits processors */
-extern long v4l_compat_ioctl32(struct file *file, unsigned int cmd,
-                               unsigned long arg);
-
 /*
  * Newer version of video_device, handled by videodev2.c
  *     This version moves redundant code from video device code to
@@ -88,18 +51,18 @@ struct video_device
        const struct file_operations *fops;
 
        /* sysfs */
-       struct device class_dev;        /* v4l device */
-       struct device *dev;             /* device parent */
+       struct device dev;              /* v4l device */
+       struct device *parent;          /* device parent */
 
        /* device info */
        char name[32];
-       int type;       /* v4l1 */
-       int type2;      /* v4l2 */
+       int type;                       /* v4l1 */
+       int type2;                      /* v4l2 */
        int minor;
        /* attribute to diferentiate multiple indexs on one physical device */
        int index;
 
-       int debug;      /* Activates debug level*/
+       int debug;                      /* Activates debug level*/
 
        /* Video standard vars */
        v4l2_std_id tvnorms;            /* Supported tv norms */
@@ -345,27 +308,19 @@ void *priv;
 };
 
 /* Class-dev to video-device */
-#define to_video_device(cd) container_of(cd, struct video_device, class_dev)
+#define to_video_device(cd) container_of(cd, struct video_device, dev)
 
 /* Version 2 functions */
 extern int video_register_device(struct video_device *vfd, int type, int nr);
 int video_register_device_index(struct video_device *vfd, int type, int nr,
                                        int index);
 void video_unregister_device(struct video_device *);
-extern int video_ioctl2(struct inode *inode, struct file *file,
-                         unsigned int cmd, unsigned long arg);
 
 /* helper functions to alloc / release struct video_device, the
    later can be used for video_device->release() */
 struct video_device *video_device_alloc(void);
 void video_device_release(struct video_device *vfd);
 
-/* Include support for obsoleted stuff */
-extern int video_usercopy(struct inode *inode, struct file *file,
-                         unsigned int cmd, unsigned long arg,
-                         int (*func)(struct inode *inode, struct file *file,
-                                     unsigned int cmd, void *arg));
-
 #ifdef CONFIG_VIDEO_V4L1_COMPAT
 #include <linux/mm.h>
 
@@ -373,7 +328,7 @@ static inline int __must_check
 video_device_create_file(struct video_device *vfd,
                         struct device_attribute *attr)
 {
-       int ret = device_create_file(&vfd->class_dev, attr);
+       int ret = device_create_file(&vfd->dev, attr);
        if (ret < 0)
                printk(KERN_WARNING "%s error: %d\n", __func__, ret);
        return ret;
@@ -382,7 +337,7 @@ static inline void
 video_device_remove_file(struct video_device *vfd,
                         struct device_attribute *attr)
 {
-       device_remove_file(&vfd->class_dev, attr);
+       device_remove_file(&vfd->dev, attr);
 }
 
 #endif /* CONFIG_VIDEO_V4L1_COMPAT */
diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
new file mode 100644 (file)
index 0000000..e319d1f
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ *
+ *     V 4 L 2   D R I V E R   H E L P E R   A P I
+ *
+ * Moved from videodev2.h
+ *
+ *     Some commonly needed functions for drivers (v4l2-common.o module)
+ */
+#ifndef _V4L2_IOCTL_H
+#define _V4L2_IOCTL_H
+
+#include <linux/poll.h>
+#include <linux/fs.h>
+#include <linux/device.h>
+#include <linux/mutex.h>
+#include <linux/compiler.h> /* need __user */
+#ifdef CONFIG_VIDEO_V4L1_COMPAT
+#include <linux/videodev.h>
+#else
+#include <linux/videodev2.h>
+#endif
+
+/* v4l debugging and diagnostics */
+
+/* Debug bitmask flags to be used on V4L2 */
+#define V4L2_DEBUG_IOCTL     0x01
+#define V4L2_DEBUG_IOCTL_ARG 0x02
+
+/* Use this macro for non-I2C drivers. Pass the driver name as the first arg. */
+#define v4l_print_ioctl(name, cmd)              \
+       do {                                     \
+               printk(KERN_DEBUG "%s: ", name); \
+               v4l_printk_ioctl(cmd);           \
+       } while (0)
+
+/* Use this macro in I2C drivers where 'client' is the struct i2c_client
+   pointer */
+#define v4l_i2c_print_ioctl(client, cmd)                  \
+       do {                                               \
+               v4l_client_printk(KERN_DEBUG, client, ""); \
+               v4l_printk_ioctl(cmd);                     \
+       } while (0)
+
+/*  Video standard functions  */
+extern const char *v4l2_norm_to_name(v4l2_std_id id);
+extern int v4l2_video_std_construct(struct v4l2_standard *vs,
+                                   int id, const char *name);
+/* Prints the ioctl in a human-readable format */
+extern void v4l_printk_ioctl(unsigned int cmd);
+
+/* names for fancy debug output */
+extern const char *v4l2_field_names[];
+extern const char *v4l2_type_names[];
+
+/*  Compatibility layer interface  --  v4l1-compat module */
+typedef int (*v4l2_kioctl)(struct inode *inode, struct file *file,
+                          unsigned int cmd, void *arg);
+#ifdef CONFIG_VIDEO_V4L1_COMPAT
+int v4l_compat_translate_ioctl(struct inode *inode, struct file *file,
+                              int cmd, void *arg, v4l2_kioctl driver_ioctl);
+#else
+#define v4l_compat_translate_ioctl(inode, file, cmd, arg, ioctl) (-EINVAL)
+#endif
+
+/* 32 Bits compatibility layer for 64 bits processors */
+extern long v4l_compat_ioctl32(struct file *file, unsigned int cmd,
+                               unsigned long arg);
+
+extern int video_ioctl2(struct inode *inode, struct file *file,
+                         unsigned int cmd, unsigned long arg);
+
+/* Include support for obsoleted stuff */
+extern int video_usercopy(struct inode *inode, struct file *file,
+                         unsigned int cmd, unsigned long arg,
+                         int (*func)(struct inode *inode, struct file *file,
+                                     unsigned int cmd, void *arg));
+
+#endif /* _V4L2_IOCTL_H */