include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[linux-3.10.git] / drivers / media / video / au0828 / au0828-video.c
index f6e8cb1..8c140c0 100644 (file)
  */
 
 #include <linux/module.h>
+#include <linux/slab.h>
 #include <linux/init.h>
 #include <linux/device.h>
 #include <linux/suspend.h>
 #include <linux/version.h>
-#include <linux/videodev.h>
 #include <media/v4l2-common.h>
 #include <media/v4l2-ioctl.h>
 #include <media/v4l2-chip-ident.h>
 #include "au0828.h"
 #include "au0828-reg.h"
 
-static LIST_HEAD(au0828_devlist);
 static DEFINE_MUTEX(au0828_sysfs_lock);
 
 #define AU0828_VERSION_CODE KERNEL_VERSION(0, 0, 1)
 
-/* Forward declarations */
-void au0828_analog_stream_reset(struct au0828_dev *dev);
-
 /* ------------------------------------------------------------------
        Videobuf operations
    ------------------------------------------------------------------*/
@@ -107,12 +103,12 @@ static inline void print_err_status(struct au0828_dev *dev,
 static int check_dev(struct au0828_dev *dev)
 {
        if (dev->dev_state & DEV_DISCONNECTED) {
-               printk("v4l2 ioctl: device not present\n");
+               printk(KERN_INFO "v4l2 ioctl: device not present\n");
                return -ENODEV;
        }
 
        if (dev->dev_state & DEV_MISCONFIGURED) {
-               printk("v4l2 ioctl: device is misconfigured; "
+               printk(KERN_INFO "v4l2 ioctl: device is misconfigured; "
                       "close and open it again\n");
                return -EIO;
        }
@@ -271,7 +267,7 @@ int au0828_init_isoc(struct au0828_dev *dev, int max_packets,
                                 au0828_irq_callback, dma_q, 1);
 
                urb->number_of_packets = max_packets;
-               urb->transfer_flags = URB_ISO_ASAP;
+               urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
 
                k = 0;
                for (j = 0; j < max_packets; j++) {
@@ -373,7 +369,7 @@ static void au0828_copy_video(struct au0828_dev *dev,
 
                if ((char *)startwrite + lencopy > (char *)outp +
                    buf->vb.size) {
-                       au0828_isocdbg("Overflow of %zi bytes past buffer end (2)\n",
+                       au0828_isocdbg("Overflow %zi bytes past buf end (2)\n",
                                       ((char *)startwrite + lencopy) -
                                       ((char *)outp + buf->vb.size));
                        lencopy = remain = (char *)outp + buf->vb.size -
@@ -389,9 +385,8 @@ static void au0828_copy_video(struct au0828_dev *dev,
 
        if (offset > 1440) {
                /* We have enough data to check for greenscreen */
-               if (outp[0] < 0x60 && outp[1440] < 0x60) {
+               if (outp[0] < 0x60 && outp[1440] < 0x60)
                        dev->greenscreen_detected = 1;
-               }
        }
 
        dma_q->pos += len;
@@ -457,9 +452,9 @@ static inline int au0828_isoc_copy(struct au0828_dev *dev, struct urb *urb)
                                continue;
                }
 
-               if (urb->iso_frame_desc[i].actual_length <= 0) {
+               if (urb->iso_frame_desc[i].actual_length <= 0)
                        continue;
-               }
+
                if (urb->iso_frame_desc[i].actual_length >
                                                dev->max_pkt_size) {
                        au0828_isocdbg("packet bigger than packet size");
@@ -480,25 +475,23 @@ static inline int au0828_isoc_copy(struct au0828_dev *dev, struct urb *urb)
                                if (buf != NULL)
                                        buffer_filled(dev, dma_q, buf);
                                get_next_buf(dma_q, &buf);
-                               if (buf == NULL) {
+                               if (buf == NULL)
                                        outp = NULL;
-                               } else
+                               else
                                        outp = videobuf_to_vmalloc(&buf->vb);
                        }
 
                        if (buf != NULL) {
-                               if (fbyte & 0x40) {
+                               if (fbyte & 0x40)
                                        buf->top_field = 1;
-                               } else {
+                               else
                                        buf->top_field = 0;
-                               }
                        }
 
                        dma_q->pos = 0;
                }
-               if (buf != NULL) {
+               if (buf != NULL)
                        au0828_copy_video(dev, dma_q, buf, p, outp, len);
-               }
        }
        return rc;
 }
@@ -566,7 +559,7 @@ buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb,
        if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
                rc = videobuf_iolock(vq, &buf->vb, NULL);
                if (rc < 0) {
-                       printk("videobuf_iolock failed\n");
+                       printk(KERN_INFO "videobuf_iolock failed\n");
                        goto fail;
                }
        }
@@ -579,7 +572,7 @@ buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb,
                                      AU0828_MAX_ISO_BUFS, dev->max_pkt_size,
                                      au0828_isoc_copy);
                if (rc < 0) {
-                       printk("au0828_init_isoc failed\n");
+                       printk(KERN_INFO "au0828_init_isoc failed\n");
                        goto fail;
                }
        }
@@ -681,11 +674,11 @@ static int au0828_stream_interrupt(struct au0828_dev *dev)
        int ret = 0;
 
        dev->stream_state = STREAM_INTERRUPT;
-       if(dev->dev_state == DEV_DISCONNECTED)
+       if (dev->dev_state == DEV_DISCONNECTED)
                return -ENODEV;
-       else if(ret) {
+       else if (ret) {
                dev->dev_state = DEV_MISCONFIGURED;
-               dprintk(1, "%s device is misconfigured!\n", __FUNCTION__);
+               dprintk(1, "%s device is misconfigured!\n", __func__);
                return ret;
        }
        return 0;
@@ -700,10 +693,8 @@ void au0828_analog_unregister(struct au0828_dev *dev)
        dprintk(1, "au0828_release_resources called\n");
        mutex_lock(&au0828_sysfs_lock);
 
-       if (dev->vdev) {
-               list_del(&dev->au0828list);
+       if (dev->vdev)
                video_unregister_device(dev->vdev);
-       }
        if (dev->vbi_dev)
                video_unregister_device(dev->vbi_dev);
 
@@ -744,32 +735,18 @@ static void res_free(struct au0828_fh *fh)
 
 static int au0828_v4l2_open(struct file *filp)
 {
-       int minor = video_devdata(filp)->minor;
        int ret = 0;
-       struct au0828_dev *h, *dev = NULL;
+       struct au0828_dev *dev = video_drvdata(filp);
        struct au0828_fh *fh;
-       int type = 0;
-       struct list_head *list;
-
-       list_for_each(list, &au0828_devlist) {
-               h = list_entry(list, struct au0828_dev, au0828list);
-               if(h->vdev->minor == minor) {
-                       dev = h;
-                       type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
-               }
-#ifdef VBI_NOT_YET_WORKING
-               if(h->vbi_dev->minor == minor) {
-                       dev = h;
-                       type = V4L2_BUF_TYPE_VBI_CAPTURE;
-               }
-#endif
-       }
+       int type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
 
-       if(NULL == dev)
-               return -ENODEV;
+#ifdef VBI_IS_WORKING
+       if (video_devdata(filp)->vfl_type == VFL_TYPE_GRABBER)
+               type = V4L2_BUF_TYPE_VBI_CAPTURE;
+#endif
 
        fh = kzalloc(sizeof(struct au0828_fh), GFP_KERNEL);
-       if(NULL == fh) {
+       if (NULL == fh) {
                dprintk(1, "Failed allocate au0828_fh struct!\n");
                return -ENOMEM;
        }
@@ -778,11 +755,11 @@ static int au0828_v4l2_open(struct file *filp)
        fh->dev = dev;
        filp->private_data = fh;
 
-       if(fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE && dev->users == 0) {
+       if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE && dev->users == 0) {
                /* set au0828 interface0 to AS5 here again */
                ret = usb_set_interface(dev->usbdev, 0, 5);
-               if(ret < 0) {
-                       printk("Au0828 can't set alt setting to 5!\n");
+               if (ret < 0) {
+                       printk(KERN_INFO "Au0828 can't set alternate to 5!\n");
                        return -EBUSY;
                }
                dev->width = NTSC_STD_W;
@@ -821,11 +798,11 @@ static int au0828_v4l2_close(struct file *filp)
        if (res_check(fh))
                res_free(fh);
 
-       if(dev->users == 1) {
+       if (dev->users == 1) {
                videobuf_stop(&fh->vb_vidq);
                videobuf_mmap_free(&fh->vb_vidq);
 
-               if(dev->dev_state & DEV_DISCONNECTED) {
+               if (dev->dev_state & DEV_DISCONNECTED) {
                        au0828_analog_unregister(dev);
                        mutex_unlock(&dev->lock);
                        kfree(dev);
@@ -836,11 +813,14 @@ static int au0828_v4l2_close(struct file *filp)
 
                au0828_uninit_isoc(dev);
 
+               /* Save some power by putting tuner to sleep */
+               v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_power, 0);
+
                /* When close the device, set the usb intf0 into alt0 to free
                   USB bandwidth */
                ret = usb_set_interface(dev->usbdev, 0, 0);
-               if(ret < 0)
-                       printk("Au0828 can't set alt setting to 0!\n");
+               if (ret < 0)
+                       printk(KERN_INFO "Au0828 can't set alternate to 0!\n");
        }
 
        kfree(fh);
@@ -861,7 +841,7 @@ static ssize_t au0828_v4l2_read(struct file *filp, char __user *buf,
        if (rc < 0)
                return rc;
 
-       if(fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
+       if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
                mutex_lock(&dev->lock);
                rc = res_get(fh);
                mutex_unlock(&dev->lock);
@@ -917,11 +897,6 @@ static int au0828_v4l2_mmap(struct file *filp, struct vm_area_struct *vma)
 
        rc = videobuf_mmap_mapper(&fh->vb_vidq, vma);
 
-       dprintk(2, "vma start=0x%08lx, size=%ld, ret=%d\n",
-               (unsigned long)vma->vm_start,
-               (unsigned long)vma->vm_end-(unsigned long)vma->vm_start,
-               rc);
-
        return rc;
 }
 
@@ -936,29 +911,26 @@ static int au0828_set_format(struct au0828_dev *dev, unsigned int cmd,
        maxwidth = 720;
        maxheight = 480;
 
-#ifdef VBI_NOT_YET_WORKING
-       if(format->type == V4L2_BUF_TYPE_SLICED_VBI_CAPTURE) {
+#ifdef VBI_IS_WORKING
+       if (format->type == V4L2_BUF_TYPE_SLICED_VBI_CAPTURE) {
                dprintk(1, "VBI format set: to be supported!\n");
                return 0;
        }
-       if(format->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
+       if (format->type == V4L2_BUF_TYPE_VBI_CAPTURE)
                return 0;
-       }
 #endif
-       if(format->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
+       if (format->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
                return -EINVAL;
-       }
 
        /* If they are demanding a format other than the one we support,
           bail out (tvtime asks for UYVY and then retries with YUYV) */
-       if (format->fmt.pix.pixelformat != V4L2_PIX_FMT_UYVY) {
+       if (format->fmt.pix.pixelformat != V4L2_PIX_FMT_UYVY)
                return -EINVAL;
-       }
 
        /* format->fmt.pix.width only support 720 and height 480 */
-       if(width != 720)
+       if (width != 720)
                width = 720;
-       if(height != 480)
+       if (height != 480)
                height = 480;
 
        format->fmt.pix.width = width;
@@ -969,7 +941,7 @@ static int au0828_set_format(struct au0828_dev *dev, unsigned int cmd,
        format->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
        format->fmt.pix.field = V4L2_FIELD_INTERLACED;
 
-       if(cmd == VIDIOC_TRY_FMT)
+       if (cmd == VIDIOC_TRY_FMT)
                return 0;
 
        /* maybe set new image format, driver current only support 720*480 */
@@ -979,9 +951,10 @@ static int au0828_set_format(struct au0828_dev *dev, unsigned int cmd,
        dev->field_size = width * height;
        dev->bytesperline = width * 2;
 
-       if(dev->stream_state == STREAM_ON) {
+       if (dev->stream_state == STREAM_ON) {
                dprintk(1, "VIDIOC_SET_FMT: interrupting stream!\n");
-               if((ret = au0828_stream_interrupt(dev))) {
+               ret = au0828_stream_interrupt(dev);
+               if (ret != 0) {
                        dprintk(1, "error interrupting video stream!\n");
                        return ret;
                }
@@ -989,8 +962,8 @@ static int au0828_set_format(struct au0828_dev *dev, unsigned int cmd,
 
        /* set au0828 interface0 to AS5 here again */
        ret = usb_set_interface(dev->usbdev, 0, 5);
-       if(ret < 0) {
-               printk("Au0828 can't set alt setting to 5!\n");
+       if (ret < 0) {
+               printk(KERN_INFO "Au0828 can't set alt setting to 5!\n");
                return -EBUSY;
        }
 
@@ -1005,7 +978,7 @@ static int vidioc_queryctrl(struct file *file, void *priv,
 {
        struct au0828_fh *fh = priv;
        struct au0828_dev *dev = fh->dev;
-       au0828_call_i2c_clients(dev, VIDIOC_QUERYCTRL, qc);
+       v4l2_device_call_all(&dev->v4l2_dev, 0, core, queryctrl, qc);
        if (qc->type)
                return 0;
        else
@@ -1018,7 +991,6 @@ static int vidioc_querycap(struct file *file, void  *priv,
        struct au0828_fh *fh  = priv;
        struct au0828_dev *dev = fh->dev;
 
-       memset(cap, 0, sizeof(*cap));
        strlcpy(cap->driver, "au0828", sizeof(cap->driver));
        strlcpy(cap->card, dev->board.name, sizeof(cap->card));
        strlcpy(cap->bus_info, dev->v4l2_dev.name, sizeof(cap->bus_info));
@@ -1027,7 +999,7 @@ static int vidioc_querycap(struct file *file, void  *priv,
 
        /*set the device capabilities */
        cap->capabilities = V4L2_CAP_VIDEO_CAPTURE |
-#ifdef VBI_NOT_YET_WORKING
+#ifdef VBI_IS_WORKING
                V4L2_CAP_VBI_CAPTURE |
 #endif
                V4L2_CAP_AUDIO |
@@ -1040,17 +1012,15 @@ static int vidioc_querycap(struct file *file, void  *priv,
 static int vidioc_enum_fmt_vid_cap(struct file *file, void  *priv,
                                        struct v4l2_fmtdesc *f)
 {
-       if(f->index)
+       if (f->index)
                return -EINVAL;
 
-       memset(f, 0, sizeof(*f));
        f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
        strcpy(f->description, "Packed YUV2");
 
        f->flags = 0;
        f->pixelformat = V4L2_PIX_FMT_UYVY;
 
-       memset(f->reserved, 0, sizeof(f->reserved));
        return 0;
 }
 
@@ -1087,13 +1057,13 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
        int rc;
 
        if (videobuf_queue_is_busy(&fh->vb_vidq)) {
-               printk("%s queue busy\n", __func__);
+               printk(KERN_INFO "%s queue busy\n", __func__);
                rc = -EBUSY;
                goto out;
        }
 
        if (dev->stream_on && !fh->stream_on) {
-               printk("%s device in use by another fh\n", __func__);
+               printk(KERN_INFO "%s device in use by another fh\n", __func__);
                rc = -EBUSY;
                goto out;
        }
@@ -1112,7 +1082,7 @@ static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id * norm)
           have to make the au0828 bridge adjust the size of its capture
           buffer, which is currently hardcoded at 720x480 */
 
-       au0828_call_i2c_clients(dev, VIDIOC_S_STD, norm);
+       v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_std, *norm);
        return 0;
 }
 
@@ -1124,6 +1094,7 @@ static int vidioc_enum_input(struct file *file, void *priv,
        unsigned int tmp;
 
        static const char *inames[] = {
+               [AU0828_VMUX_UNDEFINED] = "Undefined",
                [AU0828_VMUX_COMPOSITE] = "Composite",
                [AU0828_VMUX_SVIDEO] = "S-Video",
                [AU0828_VMUX_CABLE] = "Cable TV",
@@ -1134,16 +1105,15 @@ static int vidioc_enum_input(struct file *file, void *priv,
 
        tmp = input->index;
 
-       if(tmp > AU0828_MAX_INPUT)
+       if (tmp > AU0828_MAX_INPUT)
                return -EINVAL;
-       if(AUVI_INPUT(tmp).type == 0)
+       if (AUVI_INPUT(tmp).type == 0)
                return -EINVAL;
 
-       memset(input, 0, sizeof(*input));
        input->index = tmp;
        strcpy(input->name, inames[AUVI_INPUT(tmp).type]);
-       if((AUVI_INPUT(tmp).type == AU0828_VMUX_TELEVISION) ||
-          (AUVI_INPUT(tmp).type == AU0828_VMUX_CABLE))
+       if ((AUVI_INPUT(tmp).type == AU0828_VMUX_TELEVISION) ||
+           (AUVI_INPUT(tmp).type == AU0828_VMUX_CABLE))
                input->type |= V4L2_INPUT_TYPE_TUNER;
        else
                input->type |= V4L2_INPUT_TYPE_CAMERA;
@@ -1166,45 +1136,38 @@ static int vidioc_s_input(struct file *file, void *priv, unsigned int index)
        struct au0828_fh *fh = priv;
        struct au0828_dev *dev = fh->dev;
        int i;
-       struct v4l2_routing route;
 
-       dprintk(1, "VIDIOC_S_INPUT in function %s, input=%d\n", __FUNCTION__,
+       dprintk(1, "VIDIOC_S_INPUT in function %s, input=%d\n", __func__,
                index);
-       if(index >= AU0828_MAX_INPUT)
+       if (index >= AU0828_MAX_INPUT)
                return -EINVAL;
-       if(AUVI_INPUT(index).type == 0)
+       if (AUVI_INPUT(index).type == 0)
                return -EINVAL;
        dev->ctrl_input = index;
 
-       switch(AUVI_INPUT(index).type) {
+       switch (AUVI_INPUT(index).type) {
        case AU0828_VMUX_SVIDEO:
-       {
                dev->input_type = AU0828_VMUX_SVIDEO;
                break;
-       }
        case AU0828_VMUX_COMPOSITE:
-       {
                dev->input_type = AU0828_VMUX_COMPOSITE;
                break;
-       }
        case AU0828_VMUX_TELEVISION:
-       {
                dev->input_type = AU0828_VMUX_TELEVISION;
                break;
-       }
        default:
-               ;
+               dprintk(1, "VIDIOC_S_INPUT unknown input type set [%d]\n",
+                       AUVI_INPUT(index).type);
+               break;
        }
 
-       route.input = AUVI_INPUT(index).vmux;
-       route.output = 0;
-       au0828_call_i2c_clients(dev, VIDIOC_INT_S_VIDEO_ROUTING, &route);
+       v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_routing,
+                       AUVI_INPUT(index).vmux, 0, 0);
 
        for (i = 0; i < AU0828_MAX_INPUT; i++) {
                int enable = 0;
-               if (AUVI_INPUT(i).audio_setup == NULL) {
+               if (AUVI_INPUT(i).audio_setup == NULL)
                        continue;
-               }
 
                if (i == index)
                        enable = 1;
@@ -1222,9 +1185,8 @@ static int vidioc_s_input(struct file *file, void *priv, unsigned int index)
                }
        }
 
-       route.input = AUVI_INPUT(index).amux;
-       au0828_call_i2c_clients(dev, VIDIOC_INT_S_AUDIO_ROUTING,
-                               &route);
+       v4l2_device_call_all(&dev->v4l2_dev, 0, audio, s_routing,
+                       AUVI_INPUT(index).amux, 0, 0);
        return 0;
 }
 
@@ -1234,12 +1196,11 @@ static int vidioc_g_audio(struct file *file, void *priv, struct v4l2_audio *a)
        struct au0828_dev *dev = fh->dev;
        unsigned int index = a->index;
 
-       if(a->index > 1)
+       if (a->index > 1)
                return -EINVAL;
 
-       memset(a, 0, sizeof(*a));
        index = dev->ctrl_ainput;
-       if(index == 0)
+       if (index == 0)
                strcpy(a->name, "Television");
        else
                strcpy(a->name, "Line in");
@@ -1253,7 +1214,7 @@ static int vidioc_s_audio(struct file *file, void *priv, struct v4l2_audio *a)
 {
        struct au0828_fh *fh = priv;
        struct au0828_dev *dev = fh->dev;
-       if(a->index != dev->ctrl_ainput)
+       if (a->index != dev->ctrl_ainput)
                return -EINVAL;
        return 0;
 }
@@ -1264,7 +1225,7 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
        struct au0828_fh *fh = priv;
        struct au0828_dev *dev = fh->dev;
 
-       au0828_call_i2c_clients(dev, VIDIOC_G_CTRL, ctrl);
+       v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_ctrl, ctrl);
        return 0;
 
 }
@@ -1274,7 +1235,7 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
 {
        struct au0828_fh *fh = priv;
        struct au0828_dev *dev = fh->dev;
-       au0828_call_i2c_clients(dev, VIDIOC_S_CTRL, ctrl);
+       v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_ctrl, ctrl);
        return 0;
 }
 
@@ -1283,13 +1244,11 @@ static int vidioc_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
        struct au0828_fh *fh = priv;
        struct au0828_dev *dev = fh->dev;
 
-       if(t->index != 0)
+       if (t->index != 0)
                return -EINVAL;
 
-       memset(t, 0, sizeof(*t));
        strcpy(t->name, "Auvitek tuner");
-
-       au0828_call_i2c_clients(dev, VIDIOC_G_TUNER, t);
+       v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_tuner, t);
        return 0;
 }
 
@@ -1299,11 +1258,11 @@ static int vidioc_s_tuner(struct file *file, void *priv,
        struct au0828_fh *fh = priv;
        struct au0828_dev *dev = fh->dev;
 
-       if(t->index != 0)
+       if (t->index != 0)
                return -EINVAL;
 
        t->type = V4L2_TUNER_ANALOG_TV;
-       au0828_call_i2c_clients(dev, VIDIOC_S_TUNER, t);
+       v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_tuner, t);
        dprintk(1, "VIDIOC_S_TUNER: signal = %x, afc = %x\n", t->signal,
                t->afc);
        return 0;
@@ -1315,7 +1274,7 @@ static int vidioc_g_frequency(struct file *file, void *priv,
 {
        struct au0828_fh *fh = priv;
        struct au0828_dev *dev = fh->dev;
-       memset(freq, 0, sizeof(*freq));
+
        freq->type = V4L2_TUNER_ANALOG_TV;
        freq->frequency = dev->ctrl_freq;
        return 0;
@@ -1327,14 +1286,14 @@ static int vidioc_s_frequency(struct file *file, void *priv,
        struct au0828_fh *fh = priv;
        struct au0828_dev *dev = fh->dev;
 
-       if(freq->tuner != 0)
+       if (freq->tuner != 0)
                return -EINVAL;
-       if(freq->type != V4L2_TUNER_ANALOG_TV)
+       if (freq->type != V4L2_TUNER_ANALOG_TV)
                return -EINVAL;
 
        dev->ctrl_freq = freq->frequency;
 
-       au0828_call_i2c_clients(dev, VIDIOC_S_FREQUENCY, freq);
+       v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, freq);
 
        au0828_analog_stream_reset(dev);
 
@@ -1354,7 +1313,7 @@ static int vidioc_g_chip_ident(struct file *file, void *priv,
                return 0;
        }
 
-       au0828_call_i2c_clients(dev, VIDIOC_DBG_G_CHIP_IDENT, chip);
+       v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_chip_ident, chip);
        if (chip->ident == V4L2_IDENT_NONE)
                return -EINVAL;
 
@@ -1367,7 +1326,7 @@ static int vidioc_cropcap(struct file *file, void *priv,
        struct au0828_fh *fh = priv;
        struct au0828_dev *dev = fh->dev;
 
-       if(cc->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
+       if (cc->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
                return -EINVAL;
 
        cc->bounds.left = 0;
@@ -1388,7 +1347,6 @@ static int vidioc_streamon(struct file *file, void *priv,
 {
        struct au0828_fh *fh = priv;
        struct au0828_dev *dev = fh->dev;
-       int b = V4L2_BUF_TYPE_VIDEO_CAPTURE;
        int rc;
 
        rc = check_dev(dev);
@@ -1397,7 +1355,7 @@ static int vidioc_streamon(struct file *file, void *priv,
 
        if (type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
                au0828_analog_stream_enable(dev);
-               au0828_call_i2c_clients(dev, VIDIOC_STREAMON, &b);
+               v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_stream, 1);
        }
 
        mutex_lock(&dev->lock);
@@ -1415,7 +1373,6 @@ static int vidioc_streamoff(struct file *file, void *priv,
 {
        struct au0828_fh *fh = priv;
        struct au0828_dev *dev = fh->dev;
-       int b = V4L2_BUF_TYPE_VIDEO_CAPTURE;
        int i;
        int ret;
        int rc;
@@ -1430,15 +1387,15 @@ static int vidioc_streamoff(struct file *file, void *priv,
                return -EINVAL;
 
        if (type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
-               au0828_call_i2c_clients(dev, VIDIOC_STREAMOFF, &b);
-               if((ret = au0828_stream_interrupt(dev)) != 0)
+               v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_stream, 0);
+               ret = au0828_stream_interrupt(dev);
+               if (ret != 0)
                        return ret;
        }
 
        for (i = 0; i < AU0828_MAX_INPUT; i++) {
-               if (AUVI_INPUT(i).audio_setup == NULL) {
+               if (AUVI_INPUT(i).audio_setup == NULL)
                        continue;
-               }
                (AUVI_INPUT(i).audio_setup)(dev, 0);
        }
 
@@ -1450,6 +1407,7 @@ static int vidioc_streamoff(struct file *file, void *priv,
        return 0;
 }
 
+#ifdef CONFIG_VIDEO_ADV_DEBUG
 static int vidioc_g_register(struct file *file, void *priv,
                             struct v4l2_dbg_register *reg)
 {
@@ -1458,7 +1416,7 @@ static int vidioc_g_register(struct file *file, void *priv,
 
        switch (reg->match.type) {
        case V4L2_CHIP_MATCH_I2C_DRIVER:
-               au0828_call_i2c_clients(dev, VIDIOC_DBG_G_REGISTER, reg);
+               v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_register, reg);
                return 0;
        default:
                return -EINVAL;
@@ -1473,13 +1431,14 @@ static int vidioc_s_register(struct file *file, void *priv,
 
        switch (reg->match.type) {
        case V4L2_CHIP_MATCH_I2C_DRIVER:
-               au0828_call_i2c_clients(dev, VIDIOC_DBG_S_REGISTER, reg);
+               v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_register, reg);
                return 0;
        default:
                return -EINVAL;
        }
        return 0;
 }
+#endif
 
 static int vidioc_reqbufs(struct file *file, void *priv,
                          struct v4l2_requestbuffers *rb)
@@ -1568,7 +1527,7 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
        .vidioc_g_fmt_vid_cap       = vidioc_g_fmt_vid_cap,
        .vidioc_try_fmt_vid_cap     = vidioc_try_fmt_vid_cap,
        .vidioc_s_fmt_vid_cap       = vidioc_s_fmt_vid_cap,
-#ifdef VBI_NOT_YET_WORKING
+#ifdef VBI_IS_WORKING
        .vidioc_g_fmt_vbi_cap       = vidioc_g_fmt_vbi_cap,
        .vidioc_try_fmt_vbi_cap     = vidioc_s_fmt_vbi_cap,
        .vidioc_s_fmt_vbi_cap       = vidioc_s_fmt_vbi_cap,
@@ -1576,7 +1535,7 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
        .vidioc_g_audio             = vidioc_g_audio,
        .vidioc_s_audio             = vidioc_s_audio,
        .vidioc_cropcap             = vidioc_cropcap,
-#ifdef VBI_NOT_YET_WORKING
+#ifdef VBI_IS_WORKING
        .vidioc_g_fmt_sliced_vbi_cap   = vidioc_g_fmt_sliced_vbi_cap,
        .vidioc_try_fmt_sliced_vbi_cap = vidioc_try_set_sliced_vbi_cap,
        .vidioc_s_fmt_sliced_vbi_cap   = vidioc_try_set_sliced_vbi_cap,
@@ -1601,8 +1560,8 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
 #ifdef CONFIG_VIDEO_ADV_DEBUG
        .vidioc_g_register          = vidioc_g_register,
        .vidioc_s_register          = vidioc_s_register,
-       .vidioc_g_chip_ident        = vidioc_g_chip_ident,
 #endif
+       .vidioc_g_chip_ident        = vidioc_g_chip_ident,
 #ifdef CONFIG_VIDEO_V4L1_COMPAT
        .vidiocgmbuf                = vidiocgmbuf,
 #endif
@@ -1612,7 +1571,6 @@ static const struct video_device au0828_video_template = {
        .fops                       = &au0828_v4l_fops,
        .release                    = video_device_release,
        .ioctl_ops                  = &video_ioctl_ops,
-       .minor                      = -1,
        .tvnorms                    = V4L2_STD_NTSC_M,
        .current_norm               = V4L2_STD_NTSC_M,
 };
@@ -1631,27 +1589,30 @@ int au0828_analog_register(struct au0828_dev *dev,
 
        /* set au0828 usb interface0 to as5 */
        retval = usb_set_interface(dev->usbdev,
-                                  interface->cur_altsetting->desc.bInterfaceNumber, 5);
+                       interface->cur_altsetting->desc.bInterfaceNumber, 5);
        if (retval != 0) {
-               printk("Failure setting usb interface0 to as5\n");
+               printk(KERN_INFO "Failure setting usb interface0 to as5\n");
                return retval;
        }
 
        /* Figure out which endpoint has the isoc interface */
        iface_desc = interface->cur_altsetting;
-       for(i = 0; i < iface_desc->desc.bNumEndpoints; i++){
+       for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) {
                endpoint = &iface_desc->endpoint[i].desc;
-               if(((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN) &&
-                  ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_ISOC)){
+               if (((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK)
+                    == USB_DIR_IN) &&
+                   ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
+                    == USB_ENDPOINT_XFER_ISOC)) {
 
                        /* we find our isoc in endpoint */
                        u16 tmp = le16_to_cpu(endpoint->wMaxPacketSize);
-                       dev->max_pkt_size = (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
+                       dev->max_pkt_size = (tmp & 0x07ff) *
+                               (((tmp & 0x1800) >> 11) + 1);
                        dev->isoc_in_endpointaddr = endpoint->bEndpointAddress;
                }
        }
-       if(!(dev->isoc_in_endpointaddr)) {
-               printk("Could not locate isoc endpoint\n");
+       if (!(dev->isoc_in_endpointaddr)) {
+               printk(KERN_INFO "Could not locate isoc endpoint\n");
                kfree(dev);
                return -ENODEV;
        }
@@ -1672,14 +1633,14 @@ int au0828_analog_register(struct au0828_dev *dev,
 
        /* allocate and fill v4l2 video struct */
        dev->vdev = video_device_alloc();
-       if(NULL == dev->vdev) {
+       if (NULL == dev->vdev) {
                dprintk(1, "Can't allocate video_device.\n");
                return -ENOMEM;
        }
 
-#ifdef VBI_NOT_YET_WORKING
+#ifdef VBI_IS_WORKING
        dev->vbi_dev = video_device_alloc();
-       if(NULL == dev->vbi_dev) {
+       if (NULL == dev->vbi_dev) {
                dprintk(1, "Can't allocate vbi_device.\n");
                kfree(dev->vdev);
                return -ENOMEM;
@@ -1688,40 +1649,40 @@ int au0828_analog_register(struct au0828_dev *dev,
 
        /* Fill the video capture device struct */
        *dev->vdev = au0828_video_template;
-       dev->vdev->vfl_type = VID_TYPE_CAPTURE | VID_TYPE_TUNER;
        dev->vdev->parent = &dev->usbdev->dev;
        strcpy(dev->vdev->name, "au0828a video");
 
-#ifdef VBI_NOT_YET_WORKING
+#ifdef VBI_IS_WORKING
        /* Setup the VBI device */
        *dev->vbi_dev = au0828_video_template;
-       dev->vbi_dev->vfl_type = VFL_TYPE_VBI;
        dev->vbi_dev->parent = &dev->usbdev->dev;
        strcpy(dev->vbi_dev->name, "au0828a vbi");
 #endif
 
-       list_add_tail(&dev->au0828list, &au0828_devlist);
-
        /* Register the v4l2 device */
-       if((retval = video_register_device(dev->vdev, VFL_TYPE_GRABBER, -1)) != 0) {
-               dprintk(1, "unable to register video device (error = %d).\n", retval);
-               list_del(&dev->au0828list);
+       video_set_drvdata(dev->vdev, dev);
+       retval = video_register_device(dev->vdev, VFL_TYPE_GRABBER, -1);
+       if (retval != 0) {
+               dprintk(1, "unable to register video device (error = %d).\n",
+                       retval);
                video_device_release(dev->vdev);
                return -ENODEV;
        }
 
-#ifdef VBI_NOT_YET_WORKING
+#ifdef VBI_IS_WORKING
        /* Register the vbi device */
-       if((retval = video_register_device(dev->vbi_dev, VFL_TYPE_VBI, -1)) != 0) {
-               dprintk(1, "unable to register vbi device (error = %d).\n", retval);
-               list_del(&dev->au0828list);
+       video_set_drvdata(dev->vbi_dev, dev);
+       retval = video_register_device(dev->vbi_dev, VFL_TYPE_VBI, -1);
+       if (retval != 0) {
+               dprintk(1, "unable to register vbi device (error = %d).\n",
+                       retval);
                video_device_release(dev->vbi_dev);
                video_device_release(dev->vdev);
                return -ENODEV;
        }
 #endif
 
-       dprintk(1, "%s completed!\n", __FUNCTION__);
+       dprintk(1, "%s completed!\n", __func__);
 
        return 0;
 }