include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[safe/jmp/linux-2.6] / drivers / media / video / cx231xx / cx231xx-video.c
index 18919e0..16a73ea 100644 (file)
@@ -1,5 +1,6 @@
 /*
-   cx231xx-video.c - driver for Conexant Cx23100/101/102 USB video capture devices
+   cx231xx-video.c - driver for Conexant Cx23100/101/102
+                    USB video capture devices
 
    Copyright (C) 2008 <srinivasa.deevi at conexant dot com>
        Based on em28xx driver
@@ -31,6 +32,7 @@
 #include <linux/version.h>
 #include <linux/mm.h>
 #include <linux/mutex.h>
+#include <linux/slab.h>
 
 #include <media/v4l2-common.h>
 #include <media/v4l2-ioctl.h>
@@ -43,6 +45,8 @@
 #include "cx231xx.h"
 #include "cx231xx-vbi.h"
 
+#define CX231XX_VERSION_CODE            KERNEL_VERSION(0, 0, 1)
+
 #define DRIVER_AUTHOR   "Srinivasa Deevi <srinivasa.deevi@conexant.com>"
 #define DRIVER_DESC     "Conexant cx231xx based USB video device driver"
 
@@ -109,91 +113,91 @@ static const struct v4l2_queryctrl no_ctl = {
 static struct cx231xx_ctrl cx231xx_ctls[] = {
        /* --- video --- */
        {
-        .v = {
-              .id = V4L2_CID_BRIGHTNESS,
-              .name = "Brightness",
-              .minimum = 0x00,
-              .maximum = 0xff,
-              .step = 1,
-              .default_value = 0x7f,
-              .type = V4L2_CTRL_TYPE_INTEGER,
-              },
-        .off = 128,
-        .reg = LUMA_CTRL,
-        .mask = 0x00ff,
-        .shift = 0,
-        }, {
-            .v = {
-                  .id = V4L2_CID_CONTRAST,
-                  .name = "Contrast",
-                  .minimum = 0,
-                  .maximum = 0xff,
-                  .step = 1,
-                  .default_value = 0x3f,
-                  .type = V4L2_CTRL_TYPE_INTEGER,
-                  },
-            .off = 0,
-            .reg = LUMA_CTRL,
-            .mask = 0xff00,
-            .shift = 8,
-            }, {
-                .v = {
-                      .id = V4L2_CID_HUE,
-                      .name = "Hue",
-                      .minimum = 0,
-                      .maximum = 0xff,
-                      .step = 1,
-                      .default_value = 0x7f,
-                      .type = V4L2_CTRL_TYPE_INTEGER,
-                      },
-                .off = 128,
-                .reg = CHROMA_CTRL,
-                .mask = 0xff0000,
-                .shift = 16,
-                }, {
-                    /* strictly, this only describes only U saturation.
-                     * V saturation is handled specially through code.
-                     */
-                    .v = {
-                          .id = V4L2_CID_SATURATION,
-                          .name = "Saturation",
-                          .minimum = 0,
-                          .maximum = 0xff,
-                          .step = 1,
-                          .default_value = 0x7f,
-                          .type = V4L2_CTRL_TYPE_INTEGER,
-                          },
-                    .off = 0,
-                    .reg = CHROMA_CTRL,
-                    .mask = 0x00ff,
-                    .shift = 0,
-                    }, {
-                        /* --- audio --- */
-                        .v = {
-                              .id = V4L2_CID_AUDIO_MUTE,
-                              .name = "Mute",
-                              .minimum = 0,
-                              .maximum = 1,
-                              .default_value = 1,
-                              .type = V4L2_CTRL_TYPE_BOOLEAN,
-                              },
-                        .reg = PATH1_CTL1,
-                        .mask = (0x1f << 24),
-                        .shift = 24,
-                        }, {
-                            .v = {
-                                  .id = V4L2_CID_AUDIO_VOLUME,
-                                  .name = "Volume",
-                                  .minimum = 0,
-                                  .maximum = 0x3f,
-                                  .step = 1,
-                                  .default_value = 0x3f,
-                                  .type = V4L2_CTRL_TYPE_INTEGER,
-                                  },
-                            .reg = PATH1_VOL_CTL,
-                            .mask = 0xff,
-                            .shift = 0,
-                            }
+               .v = {
+                       .id = V4L2_CID_BRIGHTNESS,
+                       .name = "Brightness",
+                       .minimum = 0x00,
+                       .maximum = 0xff,
+                       .step = 1,
+                       .default_value = 0x7f,
+                       .type = V4L2_CTRL_TYPE_INTEGER,
+               },
+               .off = 128,
+               .reg = LUMA_CTRL,
+               .mask = 0x00ff,
+               .shift = 0,
+       }, {
+               .v = {
+                       .id = V4L2_CID_CONTRAST,
+                       .name = "Contrast",
+                       .minimum = 0,
+                       .maximum = 0xff,
+                       .step = 1,
+                       .default_value = 0x3f,
+                       .type = V4L2_CTRL_TYPE_INTEGER,
+               },
+               .off = 0,
+               .reg = LUMA_CTRL,
+               .mask = 0xff00,
+               .shift = 8,
+       }, {
+               .v = {
+                       .id = V4L2_CID_HUE,
+                       .name = "Hue",
+                       .minimum = 0,
+                       .maximum = 0xff,
+                       .step = 1,
+                       .default_value = 0x7f,
+                       .type = V4L2_CTRL_TYPE_INTEGER,
+               },
+               .off = 128,
+               .reg = CHROMA_CTRL,
+               .mask = 0xff0000,
+               .shift = 16,
+       }, {
+       /* strictly, this only describes only U saturation.
+       * V saturation is handled specially through code.
+       */
+               .v = {
+                       .id = V4L2_CID_SATURATION,
+                       .name = "Saturation",
+                       .minimum = 0,
+                       .maximum = 0xff,
+                       .step = 1,
+                       .default_value = 0x7f,
+                       .type = V4L2_CTRL_TYPE_INTEGER,
+               },
+               .off = 0,
+               .reg = CHROMA_CTRL,
+               .mask = 0x00ff,
+               .shift = 0,
+       }, {
+               /* --- audio --- */
+               .v = {
+                       .id = V4L2_CID_AUDIO_MUTE,
+                       .name = "Mute",
+                       .minimum = 0,
+                       .maximum = 1,
+                       .default_value = 1,
+                       .type = V4L2_CTRL_TYPE_BOOLEAN,
+               },
+               .reg = PATH1_CTL1,
+               .mask = (0x1f << 24),
+               .shift = 24,
+       }, {
+               .v = {
+                       .id = V4L2_CID_AUDIO_VOLUME,
+                       .name = "Volume",
+                       .minimum = 0,
+                       .maximum = 0x3f,
+                       .step = 1,
+                       .default_value = 0x3f,
+                       .type = V4L2_CTRL_TYPE_INTEGER,
+               },
+               .reg = PATH1_VOL_CTL,
+               .mask = 0xff,
+               .shift = 0,
+       }
 };
 static const int CX231XX_CTLS = ARRAY_SIZE(cx231xx_ctls);
 
@@ -362,10 +366,11 @@ static inline int cx231xx_isoc_copy(struct cx231xx *dev, struct urb *urb)
                bytes_parsed = 0;
 
                if (dma_q->is_partial_line) {
-                       /* Handle the case where we were working on a partial line */
+                       /* Handle the case of a partial line */
                        sav_eav = dma_q->last_sav;
                } else {
-                       /* Check for a SAV/EAV overlapping the buffer boundary */
+                       /* Check for a SAV/EAV overlapping
+                               the buffer boundary */
                        sav_eav =
                            cx231xx_find_boundary_SAV_EAV(p_buffer,
                                                          dma_q->partial_buf,
@@ -373,12 +378,13 @@ static inline int cx231xx_isoc_copy(struct cx231xx *dev, struct urb *urb)
                }
 
                sav_eav &= 0xF0;
-               /* Get the first line if we have some portion of an SAV/EAV from the last buffer
-                  or a partial line  */
+               /* Get the first line if we have some portion of an SAV/EAV from
+                  the last buffer or a partial line  */
                if (sav_eav) {
-                       bytes_parsed += cx231xx_get_video_line(dev, dma_q, sav_eav,     /* SAV/EAV */
-                                                              p_buffer + bytes_parsed, /* p_buffer */
-                                                              buffer_size - bytes_parsed);     /* buffer size */
+                       bytes_parsed += cx231xx_get_video_line(dev, dma_q,
+                               sav_eav,        /* SAV/EAV */
+                               p_buffer + bytes_parsed,        /* p_buffer */
+                               buffer_size - bytes_parsed);/* buf size */
                }
 
                /* Now parse data that is completely in this buffer */
@@ -387,22 +393,24 @@ static inline int cx231xx_isoc_copy(struct cx231xx *dev, struct urb *urb)
                while (bytes_parsed < buffer_size) {
                        u32 bytes_used = 0;
 
-                       sav_eav = cx231xx_find_next_SAV_EAV(p_buffer + bytes_parsed,    /* p_buffer */
-                                                           buffer_size - bytes_parsed, /* buffer size */
-                                                           &bytes_used);       /* Receives bytes used to get SAV/EAV */
+                       sav_eav = cx231xx_find_next_SAV_EAV(
+                               p_buffer + bytes_parsed,        /* p_buffer */
+                               buffer_size - bytes_parsed,     /* buf size */
+                               &bytes_used);/* bytes used to get SAV/EAV */
 
                        bytes_parsed += bytes_used;
 
                        sav_eav &= 0xF0;
                        if (sav_eav && (bytes_parsed < buffer_size)) {
-                               bytes_parsed += cx231xx_get_video_line(dev, dma_q, sav_eav,     /* SAV/EAV */
-                                                                      p_buffer + bytes_parsed, /* p_buffer */
-                                                                      buffer_size - bytes_parsed);     /* buffer size */
+                               bytes_parsed += cx231xx_get_video_line(dev,
+                                       dma_q, sav_eav, /* SAV/EAV */
+                                       p_buffer + bytes_parsed,/* p_buffer */
+                                       buffer_size - bytes_parsed);/*buf size*/
                        }
                }
 
-               /* Save the last four bytes of the buffer so we can check the buffer boundary
-                  condition next time */
+               /* Save the last four bytes of the buffer so we can check the
+                  buffer boundary condition next time */
                memcpy(dma_q->partial_buf, p_buffer + buffer_size - 4, 4);
                bytes_parsed = 0;
 
@@ -410,8 +418,8 @@ static inline int cx231xx_isoc_copy(struct cx231xx *dev, struct urb *urb)
        return rc;
 }
 
-u8 cx231xx_find_boundary_SAV_EAV(u8 * p_buffer, u8 * partial_buf,
-                                u32 * p_bytes_used)
+u8 cx231xx_find_boundary_SAV_EAV(u8 *p_buffer, u8 *partial_buf,
+                                u32 *p_bytes_used)
 {
        u32 bytes_used;
        u8 boundary_bytes[8];
@@ -426,8 +434,8 @@ u8 cx231xx_find_boundary_SAV_EAV(u8 * p_buffer, u8 * partial_buf,
        memcpy(boundary_bytes + 4, p_buffer, 4);
 
        /* Check for the SAV/EAV in the boundary buffer */
-       sav_eav =
-           cx231xx_find_next_SAV_EAV((u8 *) & boundary_bytes, 8, &bytes_used);
+       sav_eav = cx231xx_find_next_SAV_EAV((u8 *)&boundary_bytes, 8,
+                                           &bytes_used);
 
        if (sav_eav) {
                /* found a boundary SAV/EAV.  Updates the bytes used to reflect
@@ -438,13 +446,16 @@ u8 cx231xx_find_boundary_SAV_EAV(u8 * p_buffer, u8 * partial_buf,
        return sav_eav;
 }
 
-u8 cx231xx_find_next_SAV_EAV(u8 * p_buffer, u32 buffer_size, u32 * p_bytes_used)
+u8 cx231xx_find_next_SAV_EAV(u8 *p_buffer, u32 buffer_size, u32 *p_bytes_used)
 {
        u32 i;
        u8 sav_eav = 0;
 
-       /* Don't search if the buffer size is less than 4.  It causes a page fault since
-          buffer_size - 4 evaluates to a large number in that case. */
+       /*
+        * Don't search if the buffer size is less than 4.  It causes a page
+        * fault since buffer_size - 4 evaluates to a large number in that
+        * case.
+        */
        if (buffer_size < 4) {
                *p_bytes_used = buffer_size;
                return 0;
@@ -465,69 +476,61 @@ u8 cx231xx_find_next_SAV_EAV(u8 * p_buffer, u32 buffer_size, u32 * p_bytes_used)
        return 0;
 }
 
-u32 cx231xx_get_video_line(struct cx231xx * dev,
-                          struct cx231xx_dmaqueue * dma_q, u8 sav_eav,
-                          u8 * p_buffer, u32 buffer_size)
+u32 cx231xx_get_video_line(struct cx231xx *dev,
+                          struct cx231xx_dmaqueue *dma_q, u8 sav_eav,
+                          u8 *p_buffer, u32 buffer_size)
 {
        u32 bytes_copied = 0;
        int current_field = -1;
 
        switch (sav_eav) {
        case SAV_ACTIVE_VIDEO_FIELD1:
-               /* looking for skipped line which occurred in PAL 720x480 mode. In this case,
-                  there will be no active data contained between the SAV and EAV */
-               if ((buffer_size > 3) &&
-                   (p_buffer[0] == 0xFF) && (p_buffer[1] == 0x00)
-                   && (p_buffer[2] == 0x00)
-                   && ((p_buffer[3] == EAV_ACTIVE_VIDEO_FIELD1)
-                       || (p_buffer[3] == EAV_ACTIVE_VIDEO_FIELD2)
-                       || (p_buffer[3] == EAV_VBLANK_FIELD1)
-                       || (p_buffer[3] == EAV_VBLANK_FIELD2)
-                   )
-                   ) {
+               /* looking for skipped line which occurred in PAL 720x480 mode.
+                  In this case, there will be no active data contained
+                  between the SAV and EAV */
+               if ((buffer_size > 3) && (p_buffer[0] == 0xFF) &&
+                   (p_buffer[1] == 0x00) && (p_buffer[2] == 0x00) &&
+                   ((p_buffer[3] == EAV_ACTIVE_VIDEO_FIELD1) ||
+                    (p_buffer[3] == EAV_ACTIVE_VIDEO_FIELD2) ||
+                    (p_buffer[3] == EAV_VBLANK_FIELD1) ||
+                    (p_buffer[3] == EAV_VBLANK_FIELD2)))
                        return bytes_copied;
-               }
                current_field = 1;
                break;
 
        case SAV_ACTIVE_VIDEO_FIELD2:
-               /* looking for skipped line which occurred in PAL 720x480 mode. In this case,
-                  there will be no active data contained between the SAV and EAV */
-               if ((buffer_size > 3) &&
-                   (p_buffer[0] == 0xFF) && (p_buffer[1] == 0x00)
-                   && (p_buffer[2] == 0x00)
-                   && ((p_buffer[3] == EAV_ACTIVE_VIDEO_FIELD1)
-                       || (p_buffer[3] == EAV_ACTIVE_VIDEO_FIELD2)
-                       || (p_buffer[3] == EAV_VBLANK_FIELD1)
-                       || (p_buffer[3] == EAV_VBLANK_FIELD2)
-                   )
-                   ) {
+               /* looking for skipped line which occurred in PAL 720x480 mode.
+                  In this case, there will be no active data contained between
+                  the SAV and EAV */
+               if ((buffer_size > 3) && (p_buffer[0] == 0xFF) &&
+                   (p_buffer[1] == 0x00) && (p_buffer[2] == 0x00) &&
+                   ((p_buffer[3] == EAV_ACTIVE_VIDEO_FIELD1) ||
+                    (p_buffer[3] == EAV_ACTIVE_VIDEO_FIELD2) ||
+                    (p_buffer[3] == EAV_VBLANK_FIELD1)       ||
+                    (p_buffer[3] == EAV_VBLANK_FIELD2)))
                        return bytes_copied;
-               }
                current_field = 2;
                break;
        }
 
        dma_q->last_sav = sav_eav;
 
-       bytes_copied =
-           cx231xx_copy_video_line(dev, dma_q, p_buffer, buffer_size,
-                                   current_field);
+       bytes_copied = cx231xx_copy_video_line(dev, dma_q, p_buffer,
+                                              buffer_size, current_field);
 
        return bytes_copied;
 }
 
-u32 cx231xx_copy_video_line(struct cx231xx * dev,
-                           struct cx231xx_dmaqueue * dma_q, u8 * p_line,
+u32 cx231xx_copy_video_line(struct cx231xx *dev,
+                           struct cx231xx_dmaqueue *dma_q, u8 *p_line,
                            u32 length, int field_number)
 {
        u32 bytes_to_copy;
        struct cx231xx_buffer *buf;
        u32 _line_size = dev->width * 2;
 
-       if (dma_q->current_field != field_number) {
+       if (dma_q->current_field != field_number)
                cx231xx_reset_video_buffer(dev, dma_q);
-       }
 
        /* get the buffer pointer */
        buf = dev->video_mode.isoc_ctl.buf;
@@ -541,8 +544,8 @@ u32 cx231xx_copy_video_line(struct cx231xx * dev,
 
        if (dma_q->lines_completed >= dma_q->lines_per_field) {
                dma_q->bytes_left_in_line -= bytes_to_copy;
-               dma_q->is_partial_line =
-                   (dma_q->bytes_left_in_line == 0) ? 0 : 1;
+               dma_q->is_partial_line = (dma_q->bytes_left_in_line == 0) ?
+                                         0 : 1;
                return 0;
        }
 
@@ -552,8 +555,8 @@ u32 cx231xx_copy_video_line(struct cx231xx * dev,
           have copied if we had a buffer. */
        if (!buf) {
                dma_q->bytes_left_in_line -= bytes_to_copy;
-               dma_q->is_partial_line =
-                   (dma_q->bytes_left_in_line == 0) ? 0 : 1;
+               dma_q->is_partial_line = (dma_q->bytes_left_in_line == 0)
+                                        ? 0 : 1;
                return bytes_to_copy;
        }
 
@@ -564,13 +567,11 @@ u32 cx231xx_copy_video_line(struct cx231xx * dev,
        dma_q->bytes_left_in_line -= bytes_to_copy;
 
        if (dma_q->bytes_left_in_line == 0) {
-
                dma_q->bytes_left_in_line = _line_size;
                dma_q->lines_completed++;
                dma_q->is_partial_line = 0;
 
                if (cx231xx_is_buffer_done(dev, dma_q) && buf) {
-
                        buffer_filled(dev, dma_q, buf);
 
                        dma_q->pos = 0;
@@ -589,11 +590,10 @@ void cx231xx_reset_video_buffer(struct cx231xx *dev,
 
        /* handle the switch from field 1 to field 2 */
        if (dma_q->current_field == 1) {
-               if (dma_q->lines_completed >= dma_q->lines_per_field) {
+               if (dma_q->lines_completed >= dma_q->lines_per_field)
                        dma_q->field1_done = 1;
-               } else {
+               else
                        dma_q->field1_done = 0;
-               }
        }
 
        buf = dev->video_mode.isoc_ctl.buf;
@@ -617,7 +617,7 @@ void cx231xx_reset_video_buffer(struct cx231xx *dev,
 }
 
 int cx231xx_do_copy(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q,
-                   u8 * p_buffer, u32 bytes_to_copy)
+                   u8 *p_buffer, u32 bytes_to_copy)
 {
        u8 *p_out_buffer = NULL;
        u32 current_line_bytes_copied = 0;
@@ -647,14 +647,11 @@ int cx231xx_do_copy(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q,
        /* bytes already completed in the current line */
        startwrite += current_line_bytes_copied;
 
-       lencopy =
-           dma_q->bytes_left_in_line >
-           bytes_to_copy ? bytes_to_copy : dma_q->bytes_left_in_line;
+       lencopy = dma_q->bytes_left_in_line > bytes_to_copy ?
+                 bytes_to_copy : dma_q->bytes_left_in_line;
 
-       if ((u8 *) (startwrite + lencopy) >
-           (u8 *) (p_out_buffer + buf->vb.size)) {
+       if ((u8 *)(startwrite + lencopy) > (u8 *)(p_out_buffer + buf->vb.size))
                return 0;
-       }
 
        /* The below copies the UYVY data straight into video buffer */
        cx231xx_swab((u16 *) p_buffer, (u16 *) startwrite, (u16) lencopy);
@@ -662,16 +659,15 @@ int cx231xx_do_copy(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q,
        return 0;
 }
 
-void cx231xx_swab(u16 * from, u16 * to, u16 len)
+void cx231xx_swab(u16 *from, u16 *to, u16 len)
 {
        u16 i;
 
        if (len <= 0)
                return;
 
-       for (i = 0; i < len / 2; i++) {
+       for (i = 0; i < len / 2; i++)
                to[i] = (from[i] << 8) | (from[i] >> 8);
-       }
 }
 
 u8 cx231xx_is_buffer_done(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q)
@@ -679,10 +675,9 @@ u8 cx231xx_is_buffer_done(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q)
        u8 buffer_complete = 0;
 
        /* Dual field stream */
-       buffer_complete =
-           ((dma_q->current_field == 2) &&
-            (dma_q->lines_completed >= dma_q->lines_per_field) &&
-            dma_q->field1_done);
+       buffer_complete = ((dma_q->current_field == 2) &&
+                          (dma_q->lines_completed >= dma_q->lines_per_field) &&
+                           dma_q->field1_done);
 
        return buffer_complete;
 }
@@ -698,8 +693,7 @@ buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size)
        struct cx231xx *dev = fh->dev;
        struct v4l2_frequency f;
 
-       *size =
-           (fh->dev->width * fh->dev->height * dev->format->depth + 7) >> 3;
+       *size = (fh->dev->width * fh->dev->height * dev->format->depth + 7)>>3;
        if (0 == *count)
                *count = CX231XX_DEF_BUF;
 
@@ -711,7 +705,7 @@ buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size)
        f.frequency = dev->ctl_freq;
        f.type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
 
-       cx231xx_i2c_call_clients(&dev->i2c_bus[1], VIDIOC_S_FREQUENCY, &f);
+       call_all(dev, tuner, s_frequency, &f);
 
        return 0;
 }
@@ -722,6 +716,7 @@ static void free_buffer(struct videobuf_queue *vq, struct cx231xx_buffer *buf)
        struct cx231xx_fh *fh = vq->priv_data;
        struct cx231xx *dev = fh->dev;
        unsigned long flags = 0;
+
        if (in_interrupt())
                BUG();
 
@@ -754,9 +749,8 @@ buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb,
        int rc = 0, urb_init = 0;
 
        /* The only currently supported format is 16 bits/pixel */
-       buf->vb.size =
-           (fh->dev->width * fh->dev->height * dev->format->depth + 7) >> 3;
-
+       buf->vb.size = (fh->dev->width * fh->dev->height * dev->format->depth
+                       + 7) >> 3;
        if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size)
                return -EINVAL;
 
@@ -785,7 +779,7 @@ buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb,
        buf->vb.state = VIDEOBUF_PREPARED;
        return 0;
 
-      fail:
+fail:
        free_buffer(vq, buf);
        return rc;
 }
@@ -827,18 +821,12 @@ static struct videobuf_queue_ops cx231xx_video_qops = {
 
 void video_mux(struct cx231xx *dev, int index)
 {
-
-       struct v4l2_routing route;
-
-       route.input = INPUT(index)->vmux;
-       route.output = 0;
        dev->video_input = index;
        dev->ctl_ainput = INPUT(index)->amux;
 
        cx231xx_set_video_input_mux(dev, index);
 
-       cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_INT_S_VIDEO_ROUTING,
-                                &route);
+       cx25840_call(dev, video, s_routing, INPUT(index)->vmux, 0, 0);
 
        cx231xx_set_audio_input(dev, dev->ctl_ainput);
 
@@ -876,7 +864,7 @@ static int res_get(struct cx231xx_fh *fh)
 
 static int res_check(struct cx231xx_fh *fh)
 {
-       return (fh->stream_on);
+       return fh->stream_on;
 }
 
 static void res_free(struct cx231xx_fh *fh)
@@ -906,9 +894,9 @@ static int check_dev(struct cx231xx *dev)
        return 0;
 }
 
-void get_scale(struct cx231xx *dev,
-              unsigned int width, unsigned int height,
-              unsigned int *hscale, unsigned int *vscale)
+static void get_scale(struct cx231xx *dev,
+                     unsigned int width, unsigned int height,
+                     unsigned int *hscale, unsigned int *vscale)
 {
        unsigned int maxw = norm_maxw(dev);
        unsigned int maxh = norm_maxh(dev);
@@ -920,10 +908,6 @@ void get_scale(struct cx231xx *dev,
        *vscale = (((unsigned long)maxh) << 12) / height - 4096L;
        if (*vscale >= 0x4000)
                *vscale = 0x3fff;
-
-       dev->hscale = *hscale;
-       dev->vscale = *vscale;
-
 }
 
 /* ------------------------------------------------------------------
@@ -940,14 +924,15 @@ static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
 
        f->fmt.pix.width = dev->width;
        f->fmt.pix.height = dev->height;
-       f->fmt.pix.pixelformat = dev->format->fourcc;;
-       f->fmt.pix.bytesperline = (dev->width * dev->format->depth + 7) >> 3;;
+       f->fmt.pix.pixelformat = dev->format->fourcc;
+       f->fmt.pix.bytesperline = (dev->width * dev->format->depth + 7) >> 3;
        f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * dev->height;
        f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
 
        f->fmt.pix.field = V4L2_FIELD_INTERLACED;
 
        mutex_unlock(&dev->lock);
+
        return 0;
 }
 
@@ -967,8 +952,8 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
 {
        struct cx231xx_fh *fh = priv;
        struct cx231xx *dev = fh->dev;
-       int width = f->fmt.pix.width;
-       int height = f->fmt.pix.height;
+       unsigned int width = f->fmt.pix.width;
+       unsigned int height = f->fmt.pix.height;
        unsigned int maxw = norm_maxw(dev);
        unsigned int maxh = norm_maxh(dev);
        unsigned int hscale, vscale;
@@ -983,17 +968,7 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
 
        /* width must even because of the YUYV format
           height must be even because of interlacing */
-       height &= 0xfffe;
-       width &= 0xfffe;
-
-       if (unlikely(height < 32))
-               height = 32;
-       if (unlikely(height > maxh))
-               height = maxh;
-       if (unlikely(width < 48))
-               width = 48;
-       if (unlikely(width > maxw))
-               width = maxw;
+       v4l_bound_align_image(&width, 48, maxw, 1, &height, 32, maxh, 1, 0);
 
        get_scale(dev, width, height, &hscale, &vscale);
 
@@ -1051,12 +1026,12 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
        dev->format = fmt;
        get_scale(dev, dev->width, dev->height, &dev->hscale, &dev->vscale);
 
-       cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_S_FMT, f);
+       call_all(dev, video, s_fmt, f);
 
        /* Set the correct alternate setting for this resolution */
        cx231xx_resolution_set(dev);
 
-      out:
+out:
        mutex_unlock(&dev->lock);
        return rc;
 }
@@ -1070,7 +1045,7 @@ static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id * id)
        return 0;
 }
 
-static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id * norm)
+static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *norm)
 {
        struct cx231xx_fh *fh = priv;
        struct cx231xx *dev = fh->dev;
@@ -1096,7 +1071,7 @@ static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id * norm)
        dev->height = f.fmt.pix.height;
        get_scale(dev, dev->width, dev->height, &dev->hscale, &dev->vscale);
 
-       cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_S_STD, &dev->norm);
+       call_all(dev, core, s_std, dev->norm);
 
        mutex_unlock(&dev->lock);
 
@@ -1110,11 +1085,11 @@ static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id * norm)
 
 static const char *iname[] = {
        [CX231XX_VMUX_COMPOSITE1] = "Composite1",
-       [CX231XX_VMUX_SVIDEO] = "S-Video",
+       [CX231XX_VMUX_SVIDEO]     = "S-Video",
        [CX231XX_VMUX_TELEVISION] = "Television",
-       [CX231XX_VMUX_CABLE] = "Cable TV",
-       [CX231XX_VMUX_DVB] = "DVB",
-       [CX231XX_VMUX_DEBUG] = "for debug only",
+       [CX231XX_VMUX_CABLE]      = "Cable TV",
+       [CX231XX_VMUX_DVB]        = "DVB",
+       [CX231XX_VMUX_DEBUG]      = "for debug only",
 };
 
 static int vidioc_enum_input(struct file *file, void *priv,
@@ -1250,7 +1225,7 @@ static int vidioc_queryctrl(struct file *file, void *priv,
        *qc = cx231xx_ctls[i].v;
 
        mutex_lock(&dev->lock);
-       cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_QUERYCTRL, qc);
+       call_all(dev, core, queryctrl, qc);
        mutex_unlock(&dev->lock);
 
        if (qc->type)
@@ -1271,9 +1246,7 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
                return rc;
 
        mutex_lock(&dev->lock);
-
-       cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_G_CTRL, ctrl);
-
+       call_all(dev, core, g_ctrl, ctrl);
        mutex_unlock(&dev->lock);
        return rc;
 }
@@ -1290,9 +1263,7 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
                return rc;
 
        mutex_lock(&dev->lock);
-
-       cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_S_CTRL, ctrl);
-
+       call_all(dev, core, s_ctrl, ctrl);
        mutex_unlock(&dev->lock);
        return rc;
 }
@@ -1334,9 +1305,7 @@ static int vidioc_s_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
                return -EINVAL;
 #if 0
        mutex_lock(&dev->lock);
-
-       cx231xx_i2c_call_clients(&dev->i2c_bus[1], VIDIOC_S_TUNER, t);
-
+       call_all(dev, tuner, s_tuner, t);
        mutex_unlock(&dev->lock);
 #endif
        return 0;
@@ -1352,7 +1321,7 @@ static int vidioc_g_frequency(struct file *file, void *priv,
        f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
        f->frequency = dev->ctl_freq;
 
-       cx231xx_i2c_call_clients(&dev->i2c_bus[1], VIDIOC_G_FREQUENCY, f);
+       call_all(dev, tuner, g_frequency, f);
 
        mutex_unlock(&dev->lock);
 
@@ -1386,13 +1355,10 @@ static int vidioc_s_frequency(struct file *file, void *priv,
        dev->ctl_freq = f->frequency;
 
        if (dev->tuner_type == TUNER_XC5000) {
-               if (dev->cx231xx_set_analog_freq != NULL) {
+               if (dev->cx231xx_set_analog_freq != NULL)
                        dev->cx231xx_set_analog_freq(dev, f->frequency);
-               }
-       } else {
-               cx231xx_i2c_call_clients(&dev->i2c_bus[1], VIDIOC_S_FREQUENCY,
-                                        f);
-       }
+       } else
+               call_all(dev, tuner, s_frequency, f);
 
        mutex_unlock(&dev->lock);
 
@@ -1407,9 +1373,11 @@ static int vidioc_s_frequency(struct file *file, void *priv,
 #ifdef CONFIG_VIDEO_ADV_DEBUG
 
 /*
-  -R, --list-registers=type=<host/i2cdrv/i2caddr>,chip=<chip>[,min=<addr>,max=<addr>]
+  -R, --list-registers=type=<host/i2cdrv/i2caddr>,
+                               chip=<chip>[,min=<addr>,max=<addr>]
                     dump registers from <min> to <max> [VIDIOC_DBG_G_REGISTER]
-  -r, --set-register=type=<host/i2cdrv/i2caddr>,chip=<chip>,reg=<addr>,val=<val>
+  -r, --set-register=type=<host/i2cdrv/i2caddr>,
+                               chip=<chip>,reg=<addr>,val=<val>
                     set the register [VIDIOC_DBG_S_REGISTER]
 
   if type == host, then <chip> is the hosts chip ID (default 0)
@@ -1430,55 +1398,49 @@ static int vidioc_g_register(struct file *file, void *priv,
        case V4L2_CHIP_MATCH_HOST:
                switch (reg->match.addr) {
                case 0: /* Cx231xx - internal registers */
-                       ret =
-                           cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER,
-                                                 (u16) reg->reg, value, 4);
-                       reg->val =
-                           value[0] | value[1] << 8 | value[2] << 16 | value[3]
-                           << 24;
+                       ret = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER,
+                                                 (u16)reg->reg, value, 4);
+                       reg->val = value[0] | value[1] << 8 |
+                                  value[2] << 16 | value[3] << 24;
                        break;
-               case 1: /* Colibri - read byte */
-                       ret =
-                           cx231xx_read_i2c_data(dev, Colibri_DEVICE_ADDRESS,
-                                                 (u16) reg->reg, 2, &data, 1);
+               case 1: /* AFE - read byte */
+                       ret = cx231xx_read_i2c_data(dev, AFE_DEVICE_ADDRESS,
+                                                 (u16)reg->reg, 2, &data, 1);
                        reg->val = le32_to_cpu(data & 0xff);
                        break;
-               case 14:        /* Colibri - read dword */
-                       ret =
-                           cx231xx_read_i2c_data(dev, Colibri_DEVICE_ADDRESS,
-                                                 (u16) reg->reg, 2, &data, 4);
+               case 14: /* AFE - read dword */
+                       ret = cx231xx_read_i2c_data(dev, AFE_DEVICE_ADDRESS,
+                                                 (u16)reg->reg, 2, &data, 4);
                        reg->val = le32_to_cpu(data);
                        break;
-               case 2: /* Hammerhead - read byte */
-                       ret =
-                           cx231xx_read_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS,
-                                                 (u16) reg->reg, 2, &data, 1);
+               case 2: /* Video Block - read byte */
+                       ret = cx231xx_read_i2c_data(dev, VID_BLK_I2C_ADDRESS,
+                                                 (u16)reg->reg, 2, &data, 1);
                        reg->val = le32_to_cpu(data & 0xff);
                        break;
-               case 24:        /* Hammerhead - read dword */
-                       ret =
-                           cx231xx_read_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS,
-                                                 (u16) reg->reg, 2, &data, 4);
+               case 24: /* Video Block - read dword */
+                       ret = cx231xx_read_i2c_data(dev, VID_BLK_I2C_ADDRESS,
+                                                 (u16)reg->reg, 2, &data, 4);
                        reg->val = le32_to_cpu(data);
                        break;
-               case 3: /* flatiron - read byte */
-                       ret =
-                           cx231xx_read_i2c_data(dev, Flatrion_DEVICE_ADDRESS,
-                                                 (u16) reg->reg, 1, &data, 1);
+               case 3: /* I2S block - read byte */
+                       ret = cx231xx_read_i2c_data(dev,
+                                                   I2S_BLK_DEVICE_ADDRESS,
+                                                   (u16)reg->reg, 1,
+                                                   &data, 1);
                        reg->val = le32_to_cpu(data & 0xff);
                        break;
-               case 34:        /* flatiron - read dword */
+               case 34: /* I2S Block - read dword */
                        ret =
-                           cx231xx_read_i2c_data(dev, Flatrion_DEVICE_ADDRESS,
-                                                 (u16) reg->reg, 1, &data, 4);
+                           cx231xx_read_i2c_data(dev, I2S_BLK_DEVICE_ADDRESS,
+                                                 (u16)reg->reg, 1, &data, 4);
                        reg->val = le32_to_cpu(data);
                        break;
                }
                return ret < 0 ? ret : 0;
 
        case V4L2_CHIP_MATCH_I2C_DRIVER:
-               cx231xx_i2c_call_clients(&dev->i2c_bus[0],
-                                        VIDIOC_DBG_G_REGISTER, reg);
+               call_all(dev, core, g_register, reg);
                return 0;
        case V4L2_CHIP_MATCH_I2C_ADDR:
                /* Not supported yet */
@@ -1489,9 +1451,7 @@ static int vidioc_g_register(struct file *file, void *priv,
        }
 
        mutex_lock(&dev->lock);
-
-       cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_DBG_G_REGISTER, reg);
-
+       call_all(dev, core, g_register, reg);
        mutex_unlock(&dev->lock);
 
        return ret;
@@ -1520,53 +1480,50 @@ static int vidioc_s_register(struct file *file, void *priv,
                                data[1] = (u8) (value >> 8);
                                data[2] = (u8) (value >> 16);
                                data[3] = (u8) (value >> 24);
-                               ret =
-                                   cx231xx_write_ctrl_reg(dev,
+                               ret = cx231xx_write_ctrl_reg(dev,
                                                           VRT_SET_REGISTER,
-                                                          (u16) reg->reg, data,
+                                                          (u16)reg->reg, data,
                                                           4);
                                break;
-                       case 1: /* Colibri - read byte */
-                               ret =
-                                   cx231xx_write_i2c_data(dev,
-                                                          Colibri_DEVICE_ADDRESS,
-                                                          (u16) reg->reg, 2,
-                                                          value, 1);
+                       case 1: /* AFE - read byte */
+                               ret = cx231xx_write_i2c_data(dev,
+                                                       AFE_DEVICE_ADDRESS,
+                                                       (u16)reg->reg, 2,
+                                                       value, 1);
                                break;
-                       case 14:        /* Colibri - read dword */
-                               ret =
-                                   cx231xx_write_i2c_data(dev,
-                                                          Colibri_DEVICE_ADDRESS,
-                                                          (u16) reg->reg, 2,
-                                                          value, 4);
+                       case 14: /* AFE - read dword */
+                               ret = cx231xx_write_i2c_data(dev,
+                                                       AFE_DEVICE_ADDRESS,
+                                                       (u16)reg->reg, 2,
+                                                       value, 4);
                                break;
-                       case 2: /* Hammerhead - read byte */
+                       case 2: /* Video Block - read byte */
                                ret =
                                    cx231xx_write_i2c_data(dev,
-                                                          HAMMERHEAD_I2C_ADDRESS,
-                                                          (u16) reg->reg, 2,
-                                                          value, 1);
+                                                       VID_BLK_I2C_ADDRESS,
+                                                       (u16)reg->reg, 2,
+                                                       value, 1);
                                break;
-                       case 24:        /* Hammerhead - read dword */
+                       case 24: /* Video Block - read dword */
                                ret =
                                    cx231xx_write_i2c_data(dev,
-                                                          HAMMERHEAD_I2C_ADDRESS,
-                                                          (u16) reg->reg, 2,
-                                                          value, 4);
+                                                       VID_BLK_I2C_ADDRESS,
+                                                       (u16)reg->reg, 2,
+                                                       value, 4);
                                break;
-                       case 3: /* flatiron - read byte */
+                       case 3: /* I2S block - read byte */
                                ret =
                                    cx231xx_write_i2c_data(dev,
-                                                          Flatrion_DEVICE_ADDRESS,
-                                                          (u16) reg->reg, 1,
-                                                          value, 1);
+                                                       I2S_BLK_DEVICE_ADDRESS,
+                                                       (u16)reg->reg, 1,
+                                                       value, 1);
                                break;
-                       case 34:        /* flatiron - read dword */
+                       case 34: /* I2S block - read dword */
                                ret =
                                    cx231xx_write_i2c_data(dev,
-                                                          Flatrion_DEVICE_ADDRESS,
-                                                          (u16) reg->reg, 1,
-                                                          value, 4);
+                                                       I2S_BLK_DEVICE_ADDRESS,
+                                                       (u16)reg->reg, 1,
+                                                       value, 4);
                                break;
                        }
                }
@@ -1577,9 +1534,7 @@ static int vidioc_s_register(struct file *file, void *priv,
        }
 
        mutex_lock(&dev->lock);
-
-       cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_DBG_S_REGISTER, reg);
-
+       call_all(dev, core, s_register, reg);
        mutex_unlock(&dev->lock);
 
        return ret;
@@ -1623,6 +1578,8 @@ static int vidioc_streamon(struct file *file, void *priv,
        if (likely(rc >= 0))
                rc = videobuf_streamon(&fh->vb_vidq);
 
+       call_all(dev, video, s_stream, 1);
+
        mutex_unlock(&dev->lock);
 
        return rc;
@@ -1639,7 +1596,7 @@ static int vidioc_streamoff(struct file *file, void *priv,
        if (rc < 0)
                return rc;
 
-       if ((fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) ||
+       if ((fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) &&
            (fh->type != V4L2_BUF_TYPE_VBI_CAPTURE))
                return -EINVAL;
        if (type != fh->type)
@@ -1647,6 +1604,8 @@ static int vidioc_streamoff(struct file *file, void *priv,
 
        mutex_lock(&dev->lock);
 
+       cx25840_call(dev, video, s_stream, 0);
+
        videobuf_streamoff(&fh->vb_vidq);
        res_free(fh);
 
@@ -1663,17 +1622,18 @@ static int vidioc_querycap(struct file *file, void *priv,
 
        strlcpy(cap->driver, "cx231xx", sizeof(cap->driver));
        strlcpy(cap->card, cx231xx_boards[dev->model].name, sizeof(cap->card));
-       strlcpy(cap->bus_info, dev_name(&dev->udev->dev),
-               sizeof(cap->bus_info));
+       usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info));
 
        cap->version = CX231XX_VERSION_CODE;
 
        cap->capabilities = V4L2_CAP_VBI_CAPTURE |
 #if 0
-           V4L2_CAP_SLICED_VBI_CAPTURE |
+               V4L2_CAP_SLICED_VBI_CAPTURE |
 #endif
-           V4L2_CAP_VIDEO_CAPTURE |
-           V4L2_CAP_AUDIO | V4L2_CAP_READWRITE | V4L2_CAP_STREAMING;
+               V4L2_CAP_VIDEO_CAPTURE  |
+               V4L2_CAP_AUDIO          |
+               V4L2_CAP_READWRITE      |
+               V4L2_CAP_STREAMING;
 
        if (dev->tuner_type != TUNER_ABSENT)
                cap->capabilities |= V4L2_CAP_TUNER;
@@ -1709,7 +1669,7 @@ static int vidioc_g_fmt_sliced_vbi_cap(struct file *file, void *priv,
 
        f->fmt.sliced.service_set = 0;
 
-       cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_G_FMT, f);
+       call_all(dev, video, g_fmt, f);
 
        if (f->fmt.sliced.service_set == 0)
                rc = -EINVAL;
@@ -1730,7 +1690,7 @@ static int vidioc_try_set_sliced_vbi_cap(struct file *file, void *priv,
                return rc;
 
        mutex_lock(&dev->lock);
-       cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_G_FMT, f);
+       call_all(dev, video, g_fmt, f);
        mutex_unlock(&dev->lock);
 
        if (f->fmt.sliced.service_set == 0)
@@ -1805,7 +1765,7 @@ static int vidioc_reqbufs(struct file *file, void *priv,
        if (rc < 0)
                return rc;
 
-       return (videobuf_reqbufs(&fh->vb_vidq, rb));
+       return videobuf_reqbufs(&fh->vb_vidq, rb);
 }
 
 static int vidioc_querybuf(struct file *file, void *priv, struct v4l2_buffer *b)
@@ -1818,7 +1778,7 @@ static int vidioc_querybuf(struct file *file, void *priv, struct v4l2_buffer *b)
        if (rc < 0)
                return rc;
 
-       return (videobuf_querybuf(&fh->vb_vidq, b));
+       return videobuf_querybuf(&fh->vb_vidq, b);
 }
 
 static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *b)
@@ -1831,7 +1791,7 @@ static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *b)
        if (rc < 0)
                return rc;
 
-       return (videobuf_qbuf(&fh->vb_vidq, b));
+       return videobuf_qbuf(&fh->vb_vidq, b);
 }
 
 static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b)
@@ -1844,7 +1804,7 @@ static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b)
        if (rc < 0)
                return rc;
 
-       return (videobuf_dqbuf(&fh->vb_vidq, b, file->f_flags & O_NONBLOCK));
+       return videobuf_dqbuf(&fh->vb_vidq, b, file->f_flags & O_NONBLOCK);
 }
 
 #ifdef CONFIG_VIDEO_V4L1_COMPAT
@@ -1885,7 +1845,7 @@ static int radio_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
        t->type = V4L2_TUNER_RADIO;
 
        mutex_lock(&dev->lock);
-       cx231xx_i2c_call_clients(&dev->i2c_bus[1], VIDIOC_G_TUNER, t);
+       call_all(dev, tuner, s_tuner, t);
        mutex_unlock(&dev->lock);
 
        return 0;
@@ -1918,7 +1878,7 @@ static int radio_s_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
                return -EINVAL;
 
        mutex_lock(&dev->lock);
-       cx231xx_i2c_call_clients(&dev->i2c_bus[1], VIDIOC_S_TUNER, t);
+       call_all(dev, tuner, s_tuner, t);
        mutex_unlock(&dev->lock);
 
        return 0;
@@ -1957,20 +1917,29 @@ static int radio_queryctrl(struct file *file, void *priv,
  */
 static int cx231xx_v4l2_open(struct file *filp)
 {
-       int minor = video_devdata(filp)->minor;
        int errCode = 0, radio = 0;
-       struct cx231xx *dev = NULL;
+       struct video_device *vdev = video_devdata(filp);
+       struct cx231xx *dev = video_drvdata(filp);
        struct cx231xx_fh *fh;
        enum v4l2_buf_type fh_type = 0;
 
-       dev = cx231xx_get_device(minor, &fh_type, &radio);
-       if (NULL == dev)
-               return -ENODEV;
+       switch (vdev->vfl_type) {
+       case VFL_TYPE_GRABBER:
+               fh_type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+               break;
+       case VFL_TYPE_VBI:
+               fh_type = V4L2_BUF_TYPE_VBI_CAPTURE;
+               break;
+       case VFL_TYPE_RADIO:
+               radio = 1;
+               break;
+       }
 
        mutex_lock(&dev->lock);
 
-       cx231xx_videodbg("open minor=%d type=%s users=%d\n",
-                        minor, v4l2_type_names[fh_type], dev->users);
+       cx231xx_videodbg("open dev=%s type=%s users=%d\n",
+                        video_device_node_name(vdev), v4l2_type_names[fh_type],
+                        dev->users);
 
 #if 0
        errCode = cx231xx_set_mode(dev, CX231XX_ANALOG_MODE);
@@ -2024,23 +1993,24 @@ static int cx231xx_v4l2_open(struct file *filp)
 
                /* cx231xx_start_radio(dev); */
 
-               cx231xx_i2c_call_clients(&dev->i2c_bus[1], AUDC_SET_RADIO,
-                                        NULL);
+               call_all(dev, tuner, s_radio);
        }
 
        dev->users++;
 
-       if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
-               videobuf_queue_vmalloc_init(&fh->vb_vidq, &cx231xx_video_qops, NULL, &dev->video_mode.slock, fh->type, V4L2_FIELD_INTERLACED,   /* V4L2_FIELD_SEQ_TB, */
+       if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
+               videobuf_queue_vmalloc_init(&fh->vb_vidq, &cx231xx_video_qops,
+                                           NULL, &dev->video_mode.slock,
+                                           fh->type, V4L2_FIELD_INTERLACED,
                                            sizeof(struct cx231xx_buffer), fh);
-       }
-
        if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
-
-               /* Set the required alternate setting  VBI interface works in Bulk mode only */
+               /* Set the required alternate setting  VBI interface works in
+                  Bulk mode only */
                cx231xx_set_alt_setting(dev, INDEX_VANC, 0);
 
-               videobuf_queue_vmalloc_init(&fh->vb_vidq, &cx231xx_vbi_qops, NULL, &dev->vbi_mode.slock, fh->type, V4L2_FIELD_SEQ_TB,   /* V4L2_FIELD_INTERLACED,  */
+               videobuf_queue_vmalloc_init(&fh->vb_vidq, &cx231xx_vbi_qops,
+                                           NULL, &dev->vbi_mode.slock,
+                                           fh->type, V4L2_FIELD_SEQ_TB,
                                            sizeof(struct cx231xx_buffer), fh);
        }
 
@@ -2060,25 +2030,25 @@ void cx231xx_release_analog_resources(struct cx231xx *dev)
        /*FIXME: I2C IR should be disconnected */
 
        if (dev->radio_dev) {
-               if (-1 != dev->radio_dev->minor)
+               if (video_is_registered(dev->radio_dev))
                        video_unregister_device(dev->radio_dev);
                else
                        video_device_release(dev->radio_dev);
                dev->radio_dev = NULL;
        }
        if (dev->vbi_dev) {
-               cx231xx_info("V4L2 device /dev/vbi%d deregistered\n",
-                            dev->vbi_dev->num);
-               if (-1 != dev->vbi_dev->minor)
+               cx231xx_info("V4L2 device %s deregistered\n",
+                            video_device_node_name(dev->vbi_dev));
+               if (video_is_registered(dev->vbi_dev))
                        video_unregister_device(dev->vbi_dev);
                else
                        video_device_release(dev->vbi_dev);
                dev->vbi_dev = NULL;
        }
        if (dev->vdev) {
-               cx231xx_info("V4L2 device /dev/video%d deregistered\n",
-                            dev->vdev->num);
-               if (-1 != dev->vdev->minor)
+               cx231xx_info("V4L2 device %s deregistered\n",
+                            video_device_node_name(dev->vdev));
+               if (video_is_registered(dev->vdev))
                        video_unregister_device(dev->vdev);
                else
                        video_device_release(dev->vdev);
@@ -2120,11 +2090,10 @@ static int cx231xx_v4l2_close(struct file *filp)
                cx231xx_uninit_vbi_isoc(dev);
 
                /* set alternate 0 */
-               if (!dev->vbi_or_sliced_cc_mode) {
+               if (!dev->vbi_or_sliced_cc_mode)
                        cx231xx_set_alt_setting(dev, INDEX_VANC, 0);
-               } else {
+               else
                        cx231xx_set_alt_setting(dev, INDEX_HANC, 0);
-               }
 
                kfree(fh);
                dev->users--;
@@ -2147,8 +2116,7 @@ static int cx231xx_v4l2_close(struct file *filp)
                }
 
                /* Save some power by putting tuner to sleep */
-               cx231xx_i2c_call_clients(&dev->i2c_bus[1], TUNER_SET_STANDBY,
-                                        NULL);
+               call_all(dev, core, s_power, 0);
 
                /* do this before setting alternate! */
                cx231xx_uninit_isoc(dev);
@@ -2169,8 +2137,8 @@ static int cx231xx_v4l2_close(struct file *filp)
  * will allocate buffers when called for the first time
  */
 static ssize_t
-cx231xx_v4l2_read(struct file *filp, char __user * buf, size_t count,
-                 loff_t * pos)
+cx231xx_v4l2_read(struct file *filp, char __user *buf, size_t count,
+                 loff_t *pos)
 {
        struct cx231xx_fh *fh = filp->private_data;
        struct cx231xx *dev = fh->dev;
@@ -2254,118 +2222,118 @@ static int cx231xx_v4l2_mmap(struct file *filp, struct vm_area_struct *vma)
 }
 
 static const struct v4l2_file_operations cx231xx_v4l_fops = {
-       .owner = THIS_MODULE,
-       .open = cx231xx_v4l2_open,
+       .owner   = THIS_MODULE,
+       .open    = cx231xx_v4l2_open,
        .release = cx231xx_v4l2_close,
-       .read = cx231xx_v4l2_read,
-       .poll = cx231xx_v4l2_poll,
-       .mmap = cx231xx_v4l2_mmap,
-       .ioctl = video_ioctl2,
+       .read    = cx231xx_v4l2_read,
+       .poll    = cx231xx_v4l2_poll,
+       .mmap    = cx231xx_v4l2_mmap,
+       .ioctl   = video_ioctl2,
 };
 
 static const struct v4l2_ioctl_ops video_ioctl_ops = {
-       .vidioc_querycap = vidioc_querycap,
-       .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
-       .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,
-       .vidioc_g_fmt_vbi_cap = vidioc_g_fmt_vbi_cap,
-       .vidioc_try_fmt_vbi_cap = vidioc_try_fmt_vbi_cap,
-       .vidioc_s_fmt_vbi_cap = vidioc_try_fmt_vbi_cap,
-       .vidioc_g_audio = vidioc_g_audio,
-       .vidioc_s_audio = vidioc_s_audio,
-       .vidioc_cropcap = vidioc_cropcap,
-       .vidioc_g_fmt_sliced_vbi_cap = vidioc_g_fmt_sliced_vbi_cap,
+       .vidioc_querycap               = vidioc_querycap,
+       .vidioc_enum_fmt_vid_cap       = vidioc_enum_fmt_vid_cap,
+       .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,
+       .vidioc_g_fmt_vbi_cap          = vidioc_g_fmt_vbi_cap,
+       .vidioc_try_fmt_vbi_cap        = vidioc_try_fmt_vbi_cap,
+       .vidioc_s_fmt_vbi_cap          = vidioc_try_fmt_vbi_cap,
+       .vidioc_g_audio                =  vidioc_g_audio,
+       .vidioc_s_audio                = vidioc_s_audio,
+       .vidioc_cropcap                = vidioc_cropcap,
+       .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_reqbufs = vidioc_reqbufs,
-       .vidioc_querybuf = vidioc_querybuf,
-       .vidioc_qbuf = vidioc_qbuf,
-       .vidioc_dqbuf = vidioc_dqbuf,
-       .vidioc_s_std = vidioc_s_std,
-       .vidioc_g_std = vidioc_g_std,
-       .vidioc_enum_input = vidioc_enum_input,
-       .vidioc_g_input = vidioc_g_input,
-       .vidioc_s_input = vidioc_s_input,
-       .vidioc_queryctrl = vidioc_queryctrl,
-       .vidioc_g_ctrl = vidioc_g_ctrl,
-       .vidioc_s_ctrl = vidioc_s_ctrl,
-       .vidioc_streamon = vidioc_streamon,
-       .vidioc_streamoff = vidioc_streamoff,
-       .vidioc_g_tuner = vidioc_g_tuner,
-       .vidioc_s_tuner = vidioc_s_tuner,
-       .vidioc_g_frequency = vidioc_g_frequency,
-       .vidioc_s_frequency = vidioc_s_frequency,
+       .vidioc_reqbufs                = vidioc_reqbufs,
+       .vidioc_querybuf               = vidioc_querybuf,
+       .vidioc_qbuf                   = vidioc_qbuf,
+       .vidioc_dqbuf                  = vidioc_dqbuf,
+       .vidioc_s_std                  = vidioc_s_std,
+       .vidioc_g_std                  = vidioc_g_std,
+       .vidioc_enum_input             = vidioc_enum_input,
+       .vidioc_g_input                = vidioc_g_input,
+       .vidioc_s_input                = vidioc_s_input,
+       .vidioc_queryctrl              = vidioc_queryctrl,
+       .vidioc_g_ctrl                 = vidioc_g_ctrl,
+       .vidioc_s_ctrl                 = vidioc_s_ctrl,
+       .vidioc_streamon               = vidioc_streamon,
+       .vidioc_streamoff              = vidioc_streamoff,
+       .vidioc_g_tuner                = vidioc_g_tuner,
+       .vidioc_s_tuner                = vidioc_s_tuner,
+       .vidioc_g_frequency            = vidioc_g_frequency,
+       .vidioc_s_frequency            = vidioc_s_frequency,
 #ifdef CONFIG_VIDEO_ADV_DEBUG
-       .vidioc_g_register = vidioc_g_register,
-       .vidioc_s_register = vidioc_s_register,
+       .vidioc_g_register             = vidioc_g_register,
+       .vidioc_s_register             = vidioc_s_register,
 #endif
 #ifdef CONFIG_VIDEO_V4L1_COMPAT
-       .vidiocgmbuf = vidiocgmbuf,
+       .vidiocgmbuf                   = vidiocgmbuf,
 #endif
 };
 
 static struct video_device cx231xx_vbi_template;
 
 static const struct video_device cx231xx_video_template = {
-       .fops = &cx231xx_v4l_fops,
-       .release = video_device_release,
-       .ioctl_ops = &video_ioctl_ops,
-       .minor = -1,
-       .tvnorms = V4L2_STD_ALL,
+       .fops         = &cx231xx_v4l_fops,
+       .release      = video_device_release,
+       .ioctl_ops    = &video_ioctl_ops,
+       .tvnorms      = V4L2_STD_ALL,
        .current_norm = V4L2_STD_PAL,
 };
 
 static const struct v4l2_file_operations radio_fops = {
-       .owner = THIS_MODULE,
-       .open = cx231xx_v4l2_open,
+       .owner   = THIS_MODULE,
+       .open   = cx231xx_v4l2_open,
        .release = cx231xx_v4l2_close,
-       .ioctl = video_ioctl2,
+       .ioctl   = video_ioctl2,
 };
 
 static const struct v4l2_ioctl_ops radio_ioctl_ops = {
-       .vidioc_querycap = radio_querycap,
-       .vidioc_g_tuner = radio_g_tuner,
-       .vidioc_enum_input = radio_enum_input,
-       .vidioc_g_audio = radio_g_audio,
-       .vidioc_s_tuner = radio_s_tuner,
-       .vidioc_s_audio = radio_s_audio,
-       .vidioc_s_input = radio_s_input,
-       .vidioc_queryctrl = radio_queryctrl,
-       .vidioc_g_ctrl = vidioc_g_ctrl,
-       .vidioc_s_ctrl = vidioc_s_ctrl,
+       .vidioc_querycap    = radio_querycap,
+       .vidioc_g_tuner     = radio_g_tuner,
+       .vidioc_enum_input  = radio_enum_input,
+       .vidioc_g_audio     = radio_g_audio,
+       .vidioc_s_tuner     = radio_s_tuner,
+       .vidioc_s_audio     = radio_s_audio,
+       .vidioc_s_input     = radio_s_input,
+       .vidioc_queryctrl   = radio_queryctrl,
+       .vidioc_g_ctrl      = vidioc_g_ctrl,
+       .vidioc_s_ctrl      = vidioc_s_ctrl,
        .vidioc_g_frequency = vidioc_g_frequency,
        .vidioc_s_frequency = vidioc_s_frequency,
 #ifdef CONFIG_VIDEO_ADV_DEBUG
-       .vidioc_g_register = vidioc_g_register,
-       .vidioc_s_register = vidioc_s_register,
+       .vidioc_g_register  = vidioc_g_register,
+       .vidioc_s_register  = vidioc_s_register,
 #endif
 };
 
 static struct video_device cx231xx_radio_template = {
-       .name = "cx231xx-radio",
-       .fops = &radio_fops,
+       .name      = "cx231xx-radio",
+       .fops      = &radio_fops,
        .ioctl_ops = &radio_ioctl_ops,
-       .minor = -1,
 };
 
 /******************************** usb interface ******************************/
 
-static struct video_device *cx231xx_vdev_init(struct cx231xx *dev, const struct video_device
-                                             *template, const char *type_name)
+static struct video_device *cx231xx_vdev_init(struct cx231xx *dev,
+               const struct video_device
+               *template, const char *type_name)
 {
        struct video_device *vfd;
 
        vfd = video_device_alloc();
        if (NULL == vfd)
                return NULL;
+
        *vfd = *template;
-       vfd->minor = -1;
-       vfd->parent = &dev->udev->dev;
+       vfd->v4l2_dev = &dev->v4l2_dev;
        vfd->release = video_device_release;
        vfd->debug = video_debug;
 
        snprintf(vfd->name, sizeof(vfd->name), "%s %s", dev->name, type_name);
 
+       video_set_drvdata(vfd, dev);
        return vfd;
 }
 
@@ -2373,8 +2341,6 @@ int cx231xx_register_analog_devices(struct cx231xx *dev)
 {
        int ret;
 
-       cx231xx_info("%s()\n", __func__);
-
        cx231xx_info("%s: v4l2 driver version %d.%d.%d\n",
                     dev->name,
                     (CX231XX_VERSION_CODE >> 16) & 0xff,
@@ -2416,8 +2382,8 @@ int cx231xx_register_analog_devices(struct cx231xx *dev)
                return ret;
        }
 
-       cx231xx_info("%s/0: registered device video%d [v4l2]\n",
-                    dev->name, dev->vdev->num);
+       cx231xx_info("%s/0: registered device %s [v4l2]\n",
+                    dev->name, video_device_node_name(dev->vdev));
 
        /* Initialize VBI template */
        memcpy(&cx231xx_vbi_template, &cx231xx_video_template,
@@ -2435,12 +2401,12 @@ int cx231xx_register_analog_devices(struct cx231xx *dev)
                return ret;
        }
 
-       cx231xx_info("%s/0: registered device vbi%d\n",
-                    dev->name, dev->vbi_dev->num);
+       cx231xx_info("%s/0: registered device %s\n",
+                    dev->name, video_device_node_name(dev->vbi_dev));
 
        if (cx231xx_boards[dev->model].radio.type == CX231XX_RADIO) {
-               dev->radio_dev =
-                   cx231xx_vdev_init(dev, &cx231xx_radio_template, "radio");
+               dev->radio_dev = cx231xx_vdev_init(dev, &cx231xx_radio_template,
+                                                  "radio");
                if (!dev->radio_dev) {
                        cx231xx_errdev("cannot allocate video_device.\n");
                        return -ENODEV;
@@ -2451,12 +2417,13 @@ int cx231xx_register_analog_devices(struct cx231xx *dev)
                        cx231xx_errdev("can't register radio device\n");
                        return ret;
                }
-               cx231xx_info("Registered radio device as /dev/radio%d\n",
-                            dev->radio_dev->num);
+               cx231xx_info("Registered radio device as %s\n",
+                            video_device_node_name(dev->radio_dev));
        }
 
-       cx231xx_info("V4L2 device registered as /dev/video%d and /dev/vbi%d\n",
-                    dev->vdev->num, dev->vbi_dev->num);
+       cx231xx_info("V4L2 device registered as %s and %s\n",
+                    video_device_node_name(dev->vdev),
+                    video_device_node_name(dev->vbi_dev));
 
        return 0;
 }