]> err.no Git - linux-2.6/commitdiff
V4L/DVB (5304): Improve chip matching in v4l2_register
authorHans Verkuil <hverkuil@xs4all.nl>
Fri, 23 Feb 2007 23:55:14 +0000 (20:55 -0300)
committerMauro Carvalho Chehab <mchehab@infradead.org>
Thu, 1 Mar 2007 15:09:44 +0000 (13:09 -0200)
The chip matching in struct v4l2_register for VIDIOC_DBG_G/S_REGISTER
was rather primitive. It could not be extended to other busses besides
i2c and it lacked a way to.

Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
14 files changed:
drivers/media/video/cx25840/cx25840-core.c
drivers/media/video/cx88/cx88-video.c
drivers/media/video/pvrusb2/pvrusb2-hdw.c
drivers/media/video/pvrusb2/pvrusb2-hdw.h
drivers/media/video/pvrusb2/pvrusb2-v4l2.c
drivers/media/video/saa7115.c
drivers/media/video/saa7127.c
drivers/media/video/tvp5150.c
drivers/media/video/upd64031a.c
drivers/media/video/upd64083.c
drivers/media/video/usbvision/usbvision-video.c
drivers/media/video/v4l2-common.c
include/linux/videodev2.h
include/media/v4l2-common.h

index 3ff5fc00c09d269bac20851030a86b6f1b353d9e..774d2536555b8d6dbe7001c1c6f8b7b6928e4020 100644 (file)
@@ -633,7 +633,7 @@ static int cx25840_command(struct i2c_client *client, unsigned int cmd,
        {
                struct v4l2_register *reg = arg;
 
-               if (reg->i2c_id != I2C_DRIVERID_CX25840)
+               if (!v4l2_chip_match_i2c_client(client, reg->match_type, reg->match_chip))
                        return -EINVAL;
                if (!capable(CAP_SYS_ADMIN))
                        return -EPERM;
index a97be1bdc31d97d7acfd812eb2ef7db883a24ad5..bdfe2af70124c8ecac34a22bd4e184227c204ec1 100644 (file)
@@ -1389,7 +1389,7 @@ static int vidioc_g_register (struct file *file, void *fh,
 {
        struct cx88_core *core = ((struct cx8800_fh*)fh)->dev->core;
 
-       if (reg->i2c_id != 0)
+       if (!v4l2_chip_match_host(reg->match_type, reg->match_chip))
                return -EINVAL;
        /* cx2388x has a 24-bit register space */
        reg->val = cx_read(reg->reg&0xffffff);
@@ -1401,7 +1401,7 @@ static int vidioc_s_register (struct file *file, void *fh,
 {
        struct cx88_core *core = ((struct cx8800_fh*)fh)->dev->core;
 
-       if (reg->i2c_id != 0)
+       if (!v4l2_chip_match_host(reg->match_type, reg->match_chip))
                return -EINVAL;
        cx_write(reg->reg&0xffffff, reg->val);
        return 0;
index a1ca0f5007e075736b6ba6fd6ad29541618c2e3c..1cd4bb3ae260d19248fb2f8a700bf0d51d38b3e0 100644 (file)
@@ -3256,8 +3256,8 @@ static int pvr2_hdw_get_eeprom_addr(struct pvr2_hdw *hdw)
 
 
 int pvr2_hdw_register_access(struct pvr2_hdw *hdw,
-                            u32 chip_id, u64 reg_id,
-                            int setFl,u32 *val_ptr)
+                            u32 match_type, u32 match_chip, u64 reg_id,
+                            int setFl,u64 *val_ptr)
 {
 #ifdef CONFIG_VIDEO_ADV_DEBUG
        struct list_head *item;
@@ -3268,13 +3268,16 @@ int pvr2_hdw_register_access(struct pvr2_hdw *hdw,
 
        if (!capable(CAP_SYS_ADMIN)) return -EPERM;
 
-       req.i2c_id = chip_id;
+       req.match_type = match_type;
+       req.match_chip = match_chip;
        req.reg = reg_id;
        if (setFl) req.val = *val_ptr;
        mutex_lock(&hdw->i2c_list_lock); do {
                list_for_each(item,&hdw->i2c_clients) {
                        cp = list_entry(item,struct pvr2_i2c_client,list);
-                       if (cp->client->driver->id != chip_id) continue;
+                       if (!v4l2_chip_match_i2c_client(cp->client, req.match_type, req.match_chip)) {
+                               continue;
+                       }
                        stat = pvr2_i2c_client_cmd(
                                cp,(setFl ? VIDIOC_DBG_S_REGISTER :
                                    VIDIOC_DBG_G_REGISTER),&req);
index 566a8ef7e1216abbdf9b33ad8041a8c0dccd70dc..0c9cca43ff854042fc97a94c9006d60ccdd83d06 100644 (file)
@@ -217,13 +217,14 @@ void pvr2_hdw_v4l_store_minor_number(struct pvr2_hdw *,
                                     enum pvr2_v4l_type index,int);
 
 /* Direct read/write access to chip's registers:
-   chip_id - unique id of chip (e.g. I2C_DRIVERD_xxxx)
+   match_type - how to interpret match_chip (e.g. driver ID, i2c address)
+   match_chip - chip match value (e.g. I2C_DRIVERD_xxxx)
    reg_id  - register number to access
    setFl   - true to set the register, false to read it
    val_ptr - storage location for source / result. */
 int pvr2_hdw_register_access(struct pvr2_hdw *,
-                            u32 chip_id,u64 reg_id,
-                            int setFl,u32 *val_ptr);
+                            u32 match_type, u32 match_chip,u64 reg_id,
+                            int setFl,u64 *val_ptr);
 
 /* The following entry points are all lower level things you normally don't
    want to worry about. */
index 4fe4136204c7bc443776fec9ebe69c976a2a1523..5313d342666e4e4a0b2507d20df67d83ec42a375 100644 (file)
@@ -740,11 +740,11 @@ static int pvr2_v4l2_do_ioctl(struct inode *inode, struct file *file,
        case VIDIOC_DBG_S_REGISTER:
        case VIDIOC_DBG_G_REGISTER:
        {
-               u32 val;
+               u64 val;
                struct v4l2_register *req = (struct v4l2_register *)arg;
                if (cmd == VIDIOC_DBG_S_REGISTER) val = req->val;
                ret = pvr2_hdw_register_access(
-                       hdw,req->i2c_id,req->reg,
+                       hdw,req->match_type,req->match_chip,req->reg,
                        cmd == VIDIOC_DBG_S_REGISTER,&val);
                if (cmd == VIDIOC_DBG_G_REGISTER) req->val = val;
                break;
index c4f066d6668ef093bd5743f3e3982f2ee339d03b..7735b6758921f6cda72663474b71be3b767fb517 100644 (file)
@@ -1425,7 +1425,7 @@ static int saa711x_command(struct i2c_client *client, unsigned int cmd, void *ar
        {
                struct v4l2_register *reg = arg;
 
-               if (reg->i2c_id != I2C_DRIVERID_SAA711X)
+               if (!v4l2_chip_match_i2c_client(client, reg->match_type, reg->match_chip))
                        return -EINVAL;
                if (!capable(CAP_SYS_ADMIN))
                        return -EPERM;
index bd9c4f3ad02ee34a3a25ed19da3d7de00eef6380..654863db15919b4e5a9c7d891195d75b3afaa4fa 100644 (file)
@@ -619,7 +619,7 @@ static int saa7127_command(struct i2c_client *client,
        {
                struct v4l2_register *reg = arg;
 
-               if (reg->i2c_id != I2C_DRIVERID_SAA7127)
+               if (!v4l2_chip_match_i2c_client(client, reg->match_type, reg->match_chip))
                        return -EINVAL;
                if (!capable(CAP_SYS_ADMIN))
                        return -EPERM;
index 886b5df7c9d146610d4410057e49eb0e37282965..d5ec05f56adfad470a6edca177746a134113290a 100644 (file)
@@ -955,7 +955,7 @@ static int tvp5150_command(struct i2c_client *c,
        {
                struct v4l2_register *reg = arg;
 
-               if (reg->i2c_id != I2C_DRIVERID_TVP5150)
+               if (!v4l2_chip_match_i2c_client(c, reg->match_type, reg->match_chip))
                        return -EINVAL;
                if (!capable(CAP_SYS_ADMIN))
                        return -EPERM;
index b3b5fd536dc3c89b884d5e5480c04b2752347d5a..28d1133a3b7a6f770b427991a9e2441a59224dab 100644 (file)
@@ -167,7 +167,7 @@ static int upd64031a_command(struct i2c_client *client, unsigned int cmd, void *
        {
                struct v4l2_register *reg = arg;
 
-               if (reg->i2c_id != I2C_DRIVERID_UPD64031A)
+               if (!v4l2_chip_match_i2c_client(client, reg->match_type, reg->match_chip))
                        return -EINVAL;
                if (!capable(CAP_SYS_ADMIN))
                        return -EPERM;
index 8852903e7a92dba432d4af40fc2d8ab517e5b166..fe38224150d8ae0abd116953ec09c6f92721ee23 100644 (file)
@@ -144,7 +144,7 @@ static int upd64083_command(struct i2c_client *client, unsigned int cmd, void *a
        {
                struct v4l2_register *reg = arg;
 
-               if (reg->i2c_id != I2C_DRIVERID_UPD64083)
+               if (!v4l2_chip_match_i2c_client(client, reg->match_type, reg->match_chip))
                        return -EINVAL;
                if (!capable(CAP_SYS_ADMIN))
                        return -EPERM;
index ae5f42562c0c410fff2ed53b120efa1f618d484d..6fc14557d623779aa3a21e93c3eeb56d422e81cf 100644 (file)
@@ -521,7 +521,7 @@ static int usbvision_v4l2_do_ioctl(struct inode *inode, struct file *file,
                        struct v4l2_register *reg = arg;
                        int errCode;
 
-                       if (reg->i2c_id != 0)
+                       if (!v4l2_chip_match_host(reg->match_type, reg->match_chip))
                                return -EINVAL;
                        if (!capable(CAP_SYS_ADMIN))
                                return -EPERM;
@@ -540,7 +540,7 @@ static int usbvision_v4l2_do_ioctl(struct inode *inode, struct file *file,
 
                        PDEBUG(DBG_IOCTL, "VIDIOC_DBG_%c_REGISTER reg=0x%02X, value=0x%02X",
                               cmd == VIDIOC_DBG_G_REGISTER ? 'G' : 'S',
-                              (unsigned int)reg->reg, reg->val);
+                              (unsigned int)reg->reg, (unsigned int)reg->val);
                        return 0;
                }
 #endif
index ddfd80c5618bcb6b74665e78c73a3996b0a6e3dd..3506cb6671116e051a5bbfe0fd2632b36fb75f7f 100644 (file)
@@ -51,6 +51,7 @@
 #include <linux/mm.h>
 #include <linux/string.h>
 #include <linux/errno.h>
+#include <linux/i2c.h>
 #include <asm/uaccess.h>
 #include <asm/system.h>
 #include <asm/pgtable.h>
@@ -947,6 +948,32 @@ u32 v4l2_ctrl_next(const u32 * const * ctrl_classes, u32 id)
        return **ctrl_classes;
 }
 
+int v4l2_chip_match_i2c_client(struct i2c_client *c, u32 match_type, u32 match_chip)
+{
+       switch (match_type) {
+       case V4L2_CHIP_MATCH_ALWAYS:
+               return 1;
+       case V4L2_CHIP_MATCH_I2C_DRIVER:
+               return (c != NULL && c->driver != NULL && c->driver->id == match_chip);
+       case V4L2_CHIP_MATCH_I2C_ADDR:
+               return (c != NULL && c->addr == match_chip);
+       default:
+               return 0;
+       }
+}
+
+int v4l2_chip_match_host(u32 match_type, u32 match_chip)
+{
+       switch (match_type) {
+       case V4L2_CHIP_MATCH_ALWAYS:
+               return 1;
+       case V4L2_CHIP_MATCH_HOST:
+               return match_chip == 0;
+       default:
+               return 0;
+       }
+}
+
 /* ----------------------------------------------------------------- */
 
 EXPORT_SYMBOL(v4l2_norm_to_name);
@@ -970,6 +997,9 @@ EXPORT_SYMBOL(v4l2_ctrl_query_menu);
 EXPORT_SYMBOL(v4l2_ctrl_query_fill);
 EXPORT_SYMBOL(v4l2_ctrl_query_fill_std);
 
+EXPORT_SYMBOL(v4l2_chip_match_i2c_client);
+EXPORT_SYMBOL(v4l2_chip_match_host);
+
 /*
  * Local variables:
  * c-basic-offset: 8
index 65a165f918c9f9760a9bb1aa7c152ad2aafea29c..e3ab047f90ef472182aecaa17296987ecc1c60e1 100644 (file)
@@ -1306,10 +1306,17 @@ struct v4l2_streamparm
  */
 
 /* VIDIOC_DBG_G_REGISTER and VIDIOC_DBG_S_REGISTER */
+
+#define V4L2_CHIP_MATCH_ALWAYS     0  /* Match always (match_chip is not used) */
+#define V4L2_CHIP_MATCH_HOST       1  /* Match against chip ID on host (0 for the host) */
+#define V4L2_CHIP_MATCH_I2C_DRIVER 2  /* Match against I2C driver ID */
+#define V4L2_CHIP_MATCH_I2C_ADDR   3  /* Match against I2C 7-bit address */
+
 struct v4l2_register {
+       __u32 match_type; /* Match type */
+       __u32 match_chip; /* Match this chip, meaning determined by match_type */
        __u64 reg;
-       __u32 i2c_id; /* I2C driver ID of the I2C chip, or 0 for the host */
-       __u32 val;
+       __u64 val;
 };
 
 /*
index 244e440edb5353d2f2817601718f1e36e90ae6fb..6eaeec98ed8908fc819193a7226002a4218e5ac4 100644 (file)
@@ -94,6 +94,14 @@ u32 v4l2_ctrl_next(const u32 * const *ctrl_classes, u32 id);
 
 /* ------------------------------------------------------------------------- */
 
+/* Register/chip ident helper function */
+
+struct i2c_client; /* forward reference */
+int v4l2_chip_match_i2c_client(struct i2c_client *c, u32 id_type, u32 chip_id);
+int v4l2_chip_match_host(u32 id_type, u32 chip_id);
+
+/* ------------------------------------------------------------------------- */
+
 /* Internal ioctls */
 
 /* VIDIOC_INT_DECODE_VBI_LINE */