V4L/DVB: gspca_sonixb: Add support for camera button
[safe/jmp/linux-2.6] / drivers / media / video / cafe_ccic.c
index 3363e50..cbbf7e8 100644 (file)
  *
  * Written by Jonathan Corbet, corbet@lwn.net.
  *
+ * v4l2_device/v4l2_subdev conversion by:
+ * Copyright (C) 2009 Hans Verkuil <hverkuil@xs4all.nl>
+ *
+ * Note: this conversion is untested! Please contact the linux-media
+ * mailinglist if you can test this, together with the test results.
+ *
  * This file may be distributed under the terms of the GNU General
  * Public License, version 2.
  */
@@ -33,7 +39,6 @@
 #include <linux/list.h>
 #include <linux/dma-mapping.h>
 #include <linux/delay.h>
-#include <linux/debugfs.h>
 #include <linux/jiffies.h>
 #include <linux/vmalloc.h>
 
@@ -182,10 +187,6 @@ struct cafe_camera
        /* Misc */
        wait_queue_head_t smbus_wait;   /* Waiting on i2c events */
        wait_queue_head_t iowait;       /* Waiting on frame data */
-#ifdef CONFIG_VIDEO_ADV_DEBUG
-       struct dentry *dfs_regs;
-       struct dentry *dfs_cam_regs;
-#endif
 };
 
 /*
@@ -489,7 +490,6 @@ static int cafe_smbus_setup(struct cafe_camera *cam)
        int ret;
 
        cafe_smbus_enable_irq(cam);
-       adap->id = I2C_HW_SMBUS_CAFE;
        adap->owner = THIS_MODULE;
        adap->algo = &cafe_smbus_algo;
        strcpy(adap->name, "cafe_ccic");
@@ -773,6 +773,7 @@ static int cafe_cam_init(struct cafe_camera *cam)
        ret = __cafe_cam_reset(cam);
        if (ret)
                goto out;
+       chip.ident = V4L2_IDENT_NONE;
        chip.match.type = V4L2_CHIP_MATCH_I2C_ADDR;
        chip.match.addr = cam->sensor_addr;
        ret = sensor_call(cam, core, g_chip_ident, &chip);
@@ -1150,8 +1151,6 @@ static int cafe_vidioc_reqbufs(struct file *filp, void *priv,
         * Make sure it's something we can do.  User pointers could be
         * implemented without great pain, but that's not been done yet.
         */
-       if (req->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
-               return -EINVAL;
        if (req->memory != V4L2_MEMORY_MMAP)
                return -EINVAL;
        /*
@@ -1215,9 +1214,7 @@ static int cafe_vidioc_querybuf(struct file *filp, void *priv,
        int ret = -EINVAL;
 
        mutex_lock(&cam->s_mutex);
-       if (buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
-               goto out;
-       if (buf->index < 0 || buf->index >= cam->n_sbufs)
+       if (buf->index >= cam->n_sbufs)
                goto out;
        *buf = cam->sb_bufs[buf->index].v4lbuf;
        ret = 0;
@@ -1235,9 +1232,7 @@ static int cafe_vidioc_qbuf(struct file *filp, void *priv,
        unsigned long flags;
 
        mutex_lock(&cam->s_mutex);
-       if (buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
-               goto out;
-       if (buf->index < 0 || buf->index >= cam->n_sbufs)
+       if (buf->index >= cam->n_sbufs)
                goto out;
        sbuf = cam->sb_bufs + buf->index;
        if (sbuf->v4lbuf.flags & V4L2_BUF_FLAG_QUEUED) {
@@ -1268,8 +1263,6 @@ static int cafe_vidioc_dqbuf(struct file *filp, void *priv,
        unsigned long flags;
 
        mutex_lock(&cam->s_mutex);
-       if (buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
-               goto out_unlock;
        if (cam->state != S_STREAMING)
                goto out_unlock;
        if (list_empty(&cam->sb_full) && filp->f_flags & O_NONBLOCK) {
@@ -1332,7 +1325,7 @@ static void cafe_v4l_vm_close(struct vm_area_struct *vma)
        mutex_unlock(&sbuf->cam->s_mutex);
 }
 
-static struct vm_operations_struct cafe_v4l_vm_ops = {
+static const struct vm_operations_struct cafe_v4l_vm_ops = {
        .open = cafe_v4l_vm_open,
        .close = cafe_v4l_vm_close
 };
@@ -1502,8 +1495,6 @@ static int cafe_vidioc_enum_fmt_vid_cap(struct file *filp,
        struct cafe_camera *cam = priv;
        int ret;
 
-       if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
-               return -EINVAL;
        mutex_lock(&cam->s_mutex);
        ret = sensor_call(cam, video, enum_fmt, fmt);
        mutex_unlock(&cam->s_mutex);
@@ -1646,6 +1637,47 @@ static int cafe_vidioc_s_parm(struct file *filp, void *priv,
        return ret;
 }
 
+static int cafe_vidioc_g_chip_ident(struct file *file, void *priv,
+               struct v4l2_dbg_chip_ident *chip)
+{
+       struct cafe_camera *cam = priv;
+
+       chip->ident = V4L2_IDENT_NONE;
+       chip->revision = 0;
+       if (v4l2_chip_match_host(&chip->match)) {
+               chip->ident = V4L2_IDENT_CAFE;
+               return 0;
+       }
+       return sensor_call(cam, core, g_chip_ident, chip);
+}
+
+#ifdef CONFIG_VIDEO_ADV_DEBUG
+static int cafe_vidioc_g_register(struct file *file, void *priv,
+               struct v4l2_dbg_register *reg)
+{
+       struct cafe_camera *cam = priv;
+
+       if (v4l2_chip_match_host(&reg->match)) {
+               reg->val = cafe_reg_read(cam, reg->reg);
+               reg->size = 4;
+               return 0;
+       }
+       return sensor_call(cam, core, g_register, reg);
+}
+
+static int cafe_vidioc_s_register(struct file *file, void *priv,
+               struct v4l2_dbg_register *reg)
+{
+       struct cafe_camera *cam = priv;
+
+       if (v4l2_chip_match_host(&reg->match)) {
+               cafe_reg_write(cam, reg->reg, reg->val);
+               return 0;
+       }
+       return sensor_call(cam, core, s_register, reg);
+}
+#endif
+
 /*
  * This template device holds all of those v4l2 methods; we
  * clone it for specific real devices.
@@ -1682,11 +1714,15 @@ static const struct v4l2_ioctl_ops cafe_v4l_ioctl_ops = {
        .vidioc_s_ctrl          = cafe_vidioc_s_ctrl,
        .vidioc_g_parm          = cafe_vidioc_g_parm,
        .vidioc_s_parm          = cafe_vidioc_s_parm,
+       .vidioc_g_chip_ident    = cafe_vidioc_g_chip_ident,
+#ifdef CONFIG_VIDEO_ADV_DEBUG
+       .vidioc_g_register      = cafe_vidioc_g_register,
+       .vidioc_s_register      = cafe_vidioc_s_register,
+#endif
 };
 
 static struct video_device cafe_v4l_template = {
        .name = "cafe",
-       .minor = -1, /* Get one dynamically */
        .tvnorms = V4L2_STD_NTSC_M,
        .current_norm = V4L2_STD_NTSC_M,  /* make mplayer happy */
 
@@ -1849,127 +1885,6 @@ static irqreturn_t cafe_irq(int irq, void *data)
 
 
 /* -------------------------------------------------------------------------- */
-#ifdef CONFIG_VIDEO_ADV_DEBUG
-/*
- * Debugfs stuff.
- */
-
-static char cafe_debug_buf[1024];
-static struct dentry *cafe_dfs_root;
-
-static void cafe_dfs_setup(void)
-{
-       cafe_dfs_root = debugfs_create_dir("cafe_ccic", NULL);
-       if (IS_ERR(cafe_dfs_root)) {
-               cafe_dfs_root = NULL;  /* Never mind */
-               printk(KERN_NOTICE "cafe_ccic unable to set up debugfs\n");
-       }
-}
-
-static void cafe_dfs_shutdown(void)
-{
-       if (cafe_dfs_root)
-               debugfs_remove(cafe_dfs_root);
-}
-
-static int cafe_dfs_open(struct inode *inode, struct file *file)
-{
-       file->private_data = inode->i_private;
-       return 0;
-}
-
-static ssize_t cafe_dfs_read_regs(struct file *file,
-               char __user *buf, size_t count, loff_t *ppos)
-{
-       struct cafe_camera *cam = file->private_data;
-       char *s = cafe_debug_buf;
-       int offset;
-
-       for (offset = 0; offset < 0x44; offset += 4)
-               s += sprintf(s, "%02x: %08x\n", offset,
-                               cafe_reg_read(cam, offset));
-       for (offset = 0x88; offset <= 0x90; offset += 4)
-               s += sprintf(s, "%02x: %08x\n", offset,
-                               cafe_reg_read(cam, offset));
-       for (offset = 0xb4; offset <= 0xbc; offset += 4)
-               s += sprintf(s, "%02x: %08x\n", offset,
-                               cafe_reg_read(cam, offset));
-       for (offset = 0x3000; offset <= 0x300c; offset += 4)
-               s += sprintf(s, "%04x: %08x\n", offset,
-                               cafe_reg_read(cam, offset));
-       return simple_read_from_buffer(buf, count, ppos, cafe_debug_buf,
-                       s - cafe_debug_buf);
-}
-
-static const struct file_operations cafe_dfs_reg_ops = {
-       .owner = THIS_MODULE,
-       .read = cafe_dfs_read_regs,
-       .open = cafe_dfs_open
-};
-
-static ssize_t cafe_dfs_read_cam(struct file *file,
-               char __user *buf, size_t count, loff_t *ppos)
-{
-       struct cafe_camera *cam = file->private_data;
-       char *s = cafe_debug_buf;
-       int offset;
-
-       if (! cam->sensor)
-               return -EINVAL;
-       for (offset = 0x0; offset < 0x8a; offset++)
-       {
-               u8 v;
-
-               cafe_smbus_read_data(cam, cam->sensor_addr, offset, &v);
-               s += sprintf(s, "%02x: %02x\n", offset, v);
-       }
-       return simple_read_from_buffer(buf, count, ppos, cafe_debug_buf,
-                       s - cafe_debug_buf);
-}
-
-static const struct file_operations cafe_dfs_cam_ops = {
-       .owner = THIS_MODULE,
-       .read = cafe_dfs_read_cam,
-       .open = cafe_dfs_open
-};
-
-
-
-static void cafe_dfs_cam_setup(struct cafe_camera *cam)
-{
-       char fname[40];
-
-       if (!cafe_dfs_root)
-               return;
-       sprintf(fname, "regs-%d", cam->vdev.num);
-       cam->dfs_regs = debugfs_create_file(fname, 0444, cafe_dfs_root,
-                       cam, &cafe_dfs_reg_ops);
-       sprintf(fname, "cam-%d", cam->vdev.num);
-       cam->dfs_cam_regs = debugfs_create_file(fname, 0444, cafe_dfs_root,
-                       cam, &cafe_dfs_cam_ops);
-}
-
-
-static void cafe_dfs_cam_shutdown(struct cafe_camera *cam)
-{
-       if (! IS_ERR(cam->dfs_regs))
-               debugfs_remove(cam->dfs_regs);
-       if (! IS_ERR(cam->dfs_cam_regs))
-               debugfs_remove(cam->dfs_cam_regs);
-}
-
-#else
-
-#define cafe_dfs_setup()
-#define cafe_dfs_shutdown()
-#define cafe_dfs_cam_setup(cam)
-#define cafe_dfs_cam_shutdown(cam)
-#endif    /* CONFIG_VIDEO_ADV_DEBUG */
-
-
-
-
-/* ------------------------------------------------------------------------*/
 /*
  * PCI interface stuff.
  */
@@ -1992,7 +1907,6 @@ static int cafe_pci_probe(struct pci_dev *pdev,
                goto out_free;
 
        mutex_init(&cam->s_mutex);
-       mutex_lock(&cam->s_mutex);
        spin_lock_init(&cam->dev_lock);
        cam->state = S_NOTREADY;
        cafe_set_config_needed(cam, 1);
@@ -2032,14 +1946,13 @@ static int cafe_pci_probe(struct pci_dev *pdev,
         * because the sensor could attach in this call chain, leading to
         * unsightly deadlocks.
         */
-       mutex_unlock(&cam->s_mutex);  /* attach can deadlock */
        ret = cafe_smbus_setup(cam);
        if (ret)
                goto out_freeirq;
 
        cam->sensor_addr = 0x42;
-       cam->sensor = v4l2_i2c_new_subdev(&cam->i2c_adapter,
-                       "ov7670", "ov7670", cam->sensor_addr);
+       cam->sensor = v4l2_i2c_new_subdev(&cam->v4l2_dev, &cam->i2c_adapter,
+                       "ov7670", "ov7670", cam->sensor_addr, NULL);
        if (cam->sensor == NULL) {
                ret = -ENODEV;
                goto out_smbus;
@@ -2058,7 +1971,7 @@ static int cafe_pci_probe(struct pci_dev *pdev,
        cam->vdev.v4l2_dev = &cam->v4l2_dev;
        ret = video_register_device(&cam->vdev, VFL_TYPE_GRABBER, -1);
        if (ret)
-               goto out_smbus;
+               goto out_unlock;
        video_set_drvdata(&cam->vdev, cam);
 
        /*
@@ -2070,10 +1983,11 @@ static int cafe_pci_probe(struct pci_dev *pdev,
                                        " will try again later.");
        }
 
-       cafe_dfs_cam_setup(cam);
        mutex_unlock(&cam->s_mutex);
        return 0;
 
+out_unlock:
+       mutex_unlock(&cam->s_mutex);
 out_smbus:
        cafe_smbus_shutdown(cam);
 out_freeirq:
@@ -2096,7 +2010,6 @@ out:
 static void cafe_shutdown(struct cafe_camera *cam)
 {
 /* FIXME: Make sure we take care of everything here */
-       cafe_dfs_cam_shutdown(cam);
        if (cam->n_sbufs > 0)
                /* What if they are still mapped?  Shouldn't be, but... */
                cafe_free_sio_buffers(cam);
@@ -2216,7 +2129,6 @@ static int __init cafe_init(void)
 
        printk(KERN_NOTICE "Marvell M88ALP01 'CAFE' Camera Controller version %d\n",
                        CAFE_VERSION);
-       cafe_dfs_setup();
        ret = pci_register_driver(&cafe_pci_driver);
        if (ret) {
                printk(KERN_ERR "Unable to register cafe_ccic driver\n");
@@ -2232,7 +2144,6 @@ static int __init cafe_init(void)
 static void __exit cafe_exit(void)
 {
        pci_unregister_driver(&cafe_pci_driver);
-       cafe_dfs_shutdown();
 }
 
 module_init(cafe_init);