]> Pileus Git - ~andy/linux/blobdiff - drivers/media/video/em28xx/em28xx-video.c
V4L/DVB (11331): em28xx: convert to v4l2_subdev
[~andy/linux] / drivers / media / video / em28xx / em28xx-video.c
index 5b2a19b0cca6f33a1613f32c7ccb3922157977f9..6c09a37e404878ffdcb2ebe623feac6b15eaafa2 100644 (file)
@@ -49,7 +49,7 @@
                      "Sascha Sommer <saschasommer@freenet.de>"
 
 #define DRIVER_DESC         "Empia em28xx based USB video device driver"
-#define EM28XX_VERSION_CODE  KERNEL_VERSION(0, 1, 1)
+#define EM28XX_VERSION_CODE  KERNEL_VERSION(0, 1, 2)
 
 #define em28xx_videodbg(fmt, arg...) do {\
        if (video_debug) \
@@ -186,7 +186,8 @@ static void em28xx_copy_video(struct em28xx *dev,
                em28xx_isocdbg("Overflow of %zi bytes past buffer end (1)\n",
                               ((char *)startwrite + lencopy) -
                               ((char *)outp + buf->vb.size));
-               lencopy = remain = (char *)outp + buf->vb.size - (char *)startwrite;
+               remain = (char *)outp + buf->vb.size - (char *)startwrite;
+               lencopy = remain;
        }
        if (lencopy <= 0)
                return;
@@ -202,7 +203,8 @@ static void em28xx_copy_video(struct em28xx *dev,
                else
                        lencopy = bytesperline;
 
-               if ((char *)startwrite + lencopy > (char *)outp + buf->vb.size) {
+               if ((char *)startwrite + lencopy > (char *)outp +
+                   buf->vb.size) {
                        em28xx_isocdbg("Overflow of %zi bytes past buffer end (2)\n",
                                       ((char *)startwrite + lencopy) -
                                       ((char *)outp + buf->vb.size));
@@ -347,7 +349,7 @@ static inline int em28xx_isoc_copy(struct em28xx *dev, struct urb *urb)
                }
                if (p[0] == 0x22 && p[1] == 0x5a) {
                        em28xx_isocdbg("Video frame %d, length=%i, %s\n", p[2],
-                                      len, (p[2] & 1)? "odd" : "even");
+                                      len, (p[2] & 1) ? "odd" : "even");
 
                        if (!(p[2] & 1)) {
                                if (buf != NULL)
@@ -398,7 +400,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;
 
-       em28xx_i2c_call_clients(dev, VIDIOC_S_FREQUENCY, &f);
+       v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, &f);
 
        return 0;
 }
@@ -476,7 +478,9 @@ fail:
 static void
 buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
 {
-       struct em28xx_buffer    *buf     = container_of(vb, struct em28xx_buffer, vb);
+       struct em28xx_buffer    *buf     = container_of(vb,
+                                                       struct em28xx_buffer,
+                                                       vb);
        struct em28xx_fh        *fh      = vq->priv_data;
        struct em28xx           *dev     = fh->dev;
        struct em28xx_dmaqueue  *vidq    = &dev->vidq;
@@ -489,7 +493,9 @@ buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
 static void buffer_release(struct videobuf_queue *vq,
                                struct videobuf_buffer *vb)
 {
-       struct em28xx_buffer   *buf  = container_of(vb, struct em28xx_buffer, vb);
+       struct em28xx_buffer   *buf  = container_of(vb,
+                                                   struct em28xx_buffer,
+                                                   vb);
        struct em28xx_fh       *fh   = vq->priv_data;
        struct em28xx          *dev  = (struct em28xx *)fh->dev;
 
@@ -520,18 +526,25 @@ static void video_mux(struct em28xx *dev, int index)
        if (!dev->ctl_aoutput)
                dev->ctl_aoutput = EM28XX_AOUT_MASTER;
 
-       em28xx_i2c_call_clients(dev, VIDIOC_INT_S_VIDEO_ROUTING, &route);
+       v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_routing, &route);
 
        if (dev->board.has_msp34xx) {
                if (dev->i2s_speed) {
-                       em28xx_i2c_call_clients(dev, VIDIOC_INT_I2S_CLOCK_FREQ,
-                               &dev->i2s_speed);
+                       v4l2_device_call_all(&dev->v4l2_dev, 0, audio,
+                               s_i2s_clock_freq, dev->i2s_speed);
                }
-               route.input = dev->ctl_ainput;
+               route.input  = dev->ctl_ainput;
                route.output = MSP_OUTPUT(MSP_SC_IN_DSP_SCART1);
+
                /* Note: this is msp3400 specific */
-               em28xx_i2c_call_clients(dev, VIDIOC_INT_S_AUDIO_ROUTING,
-                       &route);
+               v4l2_device_call_all(&dev->v4l2_dev, 0, audio, s_routing, &route);
+       }
+
+       if (dev->board.adecoder != EM28XX_NOADECODER) {
+               route.input  = dev->ctl_ainput;
+               route.output = dev->ctl_aoutput;
+
+               v4l2_device_call_all(&dev->v4l2_dev, 0, audio, s_routing, &route);
        }
 
        em28xx_audio_analog_set(dev);
@@ -557,7 +570,7 @@ static int res_get(struct em28xx_fh *fh)
 
 static int res_check(struct em28xx_fh *fh)
 {
-       return (fh->stream_on);
+       return fh->stream_on;
 }
 
 static void res_free(struct em28xx_fh *fh)
@@ -791,7 +804,7 @@ out:
        return rc;
 }
 
-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 em28xx_fh   *fh  = priv;
        struct em28xx      *dev = fh->dev;
@@ -816,7 +829,7 @@ static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id * norm)
        get_scale(dev, dev->width, dev->height, &dev->hscale, &dev->vscale);
 
        em28xx_resolution_set(dev);
-       em28xx_i2c_call_clients(dev, VIDIOC_S_STD, &dev->norm);
+       v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_std, dev->norm);
 
        mutex_unlock(&dev->lock);
        return 0;
@@ -982,8 +995,9 @@ static int vidioc_queryctrl(struct file *file, void *priv,
                        }
                }
        }
+
        mutex_lock(&dev->lock);
-       em28xx_i2c_call_clients(dev, VIDIOC_QUERYCTRL, qc);
+       v4l2_device_call_all(&dev->v4l2_dev, 0, core, queryctrl, qc);
        mutex_unlock(&dev->lock);
 
        if (qc->type)
@@ -1007,11 +1021,11 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
        mutex_lock(&dev->lock);
 
        if (dev->board.has_msp34xx)
-               em28xx_i2c_call_clients(dev, VIDIOC_G_CTRL, ctrl);
+               v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_ctrl, ctrl);
        else {
                rc = em28xx_get_ctrl(dev, ctrl);
                if (rc < 0) {
-                       em28xx_i2c_call_clients(dev, VIDIOC_G_CTRL, ctrl);
+                       v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_ctrl, ctrl);
                        rc = 0;
                }
        }
@@ -1035,7 +1049,7 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
        mutex_lock(&dev->lock);
 
        if (dev->board.has_msp34xx)
-               em28xx_i2c_call_clients(dev, VIDIOC_S_CTRL, ctrl);
+               v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_ctrl, ctrl);
        else {
                rc = 1;
                for (i = 0; i < ARRAY_SIZE(em28xx_qctrl); i++) {
@@ -1054,7 +1068,7 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
 
        /* Control not found - try to send it to the attached devices */
        if (rc == 1) {
-               em28xx_i2c_call_clients(dev, VIDIOC_S_CTRL, ctrl);
+               v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_ctrl, ctrl);
                rc = 0;
        }
 
@@ -1079,10 +1093,9 @@ static int vidioc_g_tuner(struct file *file, void *priv,
        strcpy(t->name, "Tuner");
 
        mutex_lock(&dev->lock);
-
-       em28xx_i2c_call_clients(dev, VIDIOC_G_TUNER, t);
-
+       v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_tuner, t);
        mutex_unlock(&dev->lock);
+
        return 0;
 }
 
@@ -1101,10 +1114,9 @@ static int vidioc_s_tuner(struct file *file, void *priv,
                return -EINVAL;
 
        mutex_lock(&dev->lock);
-
-       em28xx_i2c_call_clients(dev, VIDIOC_S_TUNER, t);
-
+       v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_tuner, t);
        mutex_unlock(&dev->lock);
+
        return 0;
 }
 
@@ -1144,7 +1156,7 @@ static int vidioc_s_frequency(struct file *file, void *priv,
        mutex_lock(&dev->lock);
 
        dev->ctl_freq = f->frequency;
-       em28xx_i2c_call_clients(dev, VIDIOC_S_FREQUENCY, f);
+       v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, f);
 
        mutex_unlock(&dev->lock);
 
@@ -1173,7 +1185,7 @@ static int vidioc_g_chip_ident(struct file *file, void *priv,
        chip->ident = V4L2_IDENT_NONE;
        chip->revision = 0;
 
-       em28xx_i2c_call_clients(dev, VIDIOC_DBG_G_CHIP_IDENT, chip);
+       v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_chip_ident, chip);
 
        return 0;
 }
@@ -1198,7 +1210,7 @@ static int vidioc_g_register(struct file *file, void *priv,
                reg->size = 1;
                return 0;
        case V4L2_CHIP_MATCH_I2C_DRIVER:
-               em28xx_i2c_call_clients(dev, VIDIOC_DBG_G_REGISTER, reg);
+               v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_register, reg);
                return 0;
        case V4L2_CHIP_MATCH_I2C_ADDR:
                /* Not supported yet */
@@ -1250,7 +1262,7 @@ static int vidioc_s_register(struct file *file, void *priv,
 
                return rc;
        case V4L2_CHIP_MATCH_I2C_DRIVER:
-               em28xx_i2c_call_clients(dev, VIDIOC_DBG_S_REGISTER, reg);
+               v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_register, reg);
                return 0;
        case V4L2_CHIP_MATCH_I2C_ADDR:
                /* Not supported yet */
@@ -1393,13 +1405,13 @@ static int vidioc_g_fmt_sliced_vbi_cap(struct file *file, void *priv,
        mutex_lock(&dev->lock);
 
        f->fmt.sliced.service_set = 0;
-
-       em28xx_i2c_call_clients(dev, VIDIOC_G_FMT, f);
+       v4l2_device_call_all(&dev->v4l2_dev, 0, video, g_fmt, f);
 
        if (f->fmt.sliced.service_set == 0)
                rc = -EINVAL;
 
        mutex_unlock(&dev->lock);
+
        return rc;
 }
 
@@ -1415,7 +1427,7 @@ static int vidioc_try_set_sliced_vbi_cap(struct file *file, void *priv,
                return rc;
 
        mutex_lock(&dev->lock);
-       em28xx_i2c_call_clients(dev, VIDIOC_G_FMT, f);
+       v4l2_device_call_all(&dev->v4l2_dev, 0, video, g_fmt, f);
        mutex_unlock(&dev->lock);
 
        if (f->fmt.sliced.service_set == 0)
@@ -1436,7 +1448,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,
@@ -1450,7 +1462,7 @@ static int vidioc_querybuf(struct file *file, void *priv,
        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)
@@ -1463,7 +1475,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)
@@ -1476,8 +1488,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
@@ -1520,7 +1531,7 @@ static int radio_g_tuner(struct file *file, void *priv,
        t->type = V4L2_TUNER_RADIO;
 
        mutex_lock(&dev->lock);
-       em28xx_i2c_call_clients(dev, VIDIOC_G_TUNER, t);
+       v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_tuner, t);
        mutex_unlock(&dev->lock);
 
        return 0;
@@ -1555,7 +1566,7 @@ static int radio_s_tuner(struct file *file, void *priv,
                return -EINVAL;
 
        mutex_lock(&dev->lock);
-       em28xx_i2c_call_clients(dev, VIDIOC_S_TUNER, t);
+       v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_tuner, t);
        mutex_unlock(&dev->lock);
 
        return 0;
@@ -1643,7 +1654,7 @@ static int em28xx_v4l2_open(struct file *filp)
        }
        if (fh->radio) {
                em28xx_videodbg("video_open: setting radio device\n");
-               em28xx_i2c_call_clients(dev, AUDC_SET_RADIO, NULL);
+               v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_radio);
        }
 
        dev->users++;
@@ -1726,7 +1737,7 @@ static int em28xx_v4l2_close(struct file *filp)
                }
 
                /* Save some power by putting tuner to sleep */
-               em28xx_i2c_call_clients(dev, TUNER_SET_STANDBY, NULL);
+               v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_standby, 0);
 
                /* do this before setting alternate! */
                em28xx_uninit_isoc(dev);
@@ -1786,7 +1797,7 @@ em28xx_v4l2_read(struct file *filp, char __user *buf, size_t count,
  * em28xx_v4l2_poll()
  * will allocate buffers when called for the first time
  */
-static unsigned int em28xx_v4l2_poll(struct file *filp, poll_table * wait)
+static unsigned int em28xx_v4l2_poll(struct file *filp, poll_table *wait)
 {
        struct em28xx_fh *fh = filp->private_data;
        struct em28xx *dev = fh->dev;
@@ -1939,19 +1950,20 @@ static struct video_device em28xx_radio_template = {
 
 
 static struct video_device *em28xx_vdev_init(struct em28xx *dev,
-                                            const struct video_device *template,
-                                            const char *type_name)
+                                       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->release = video_device_release;
-       vfd->debug = video_debug;
+
+       *vfd            = *template;
+       vfd->minor      = -1;
+       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);
@@ -1989,8 +2001,9 @@ int em28xx_register_analog_devices(struct em28xx *dev)
        /* enable vbi capturing */
 
 /*     em28xx_write_reg(dev, EM28XX_R0E_AUDIOSRC, 0xc0); audio register */
-       val = (u8)em28xx_read_reg(dev, EM28XX_R0F_XCLK);
-       em28xx_write_reg(dev, EM28XX_R0F_XCLK, (EM28XX_XCLK_AUDIO_UNMUTE | val));
+       val = (u8)em28xx_read_reg(dev, EM28XX_R0F_XCLK);
+       em28xx_write_reg(dev, EM28XX_R0F_XCLK,
+                        (EM28XX_XCLK_AUDIO_UNMUTE | val));
        em28xx_write_reg(dev, EM28XX_R11_VINCTRL, 0x51);
 
        em28xx_set_outfmt(dev);
@@ -2025,7 +2038,8 @@ int em28xx_register_analog_devices(struct em28xx *dev)
        }
 
        if (em28xx_boards[dev->model].radio.type == EM28XX_RADIO) {
-               dev->radio_dev = em28xx_vdev_init(dev, &em28xx_radio_template, "radio");
+               dev->radio_dev = em28xx_vdev_init(dev, &em28xx_radio_template,
+                                                 "radio");
                if (!dev->radio_dev) {
                        em28xx_errdev("cannot allocate video_device.\n");
                        return -ENODEV;