summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorHans Verkuil <hverkuil@xs4all.nl>2007-09-12 08:32:50 -0300
committerMauro Carvalho Chehab <mchehab@infradead.org>2008-01-25 19:01:16 -0200
commit8ffbc6559493c64d6194c92d856196fdaeb8a5fb (patch)
treeb279073efa70f56cf6f0614a6a96374464e492ec /drivers
parent5ef4730d1bfe5be71ce54d927c510ad5da968854 (diff)
V4L/DVB (6451): v4l2: add support for bus-based I2C drivers
Two new headers were added: one for I2C drivers that are only used by V4L2 drivers converted to the new bus-based I2C API, and one that can be used by both converted and unconverted drivers (at the expense of some additional overhead). To support the legacy I2C API a helper function was added to v4l2-common.c. These headers take care of all the 'boilerplate' code that all V4L2 I2C drivers have in common and will automatically support the bus-based I2C API introduced in kernel 2.6.22. Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/media/video/v4l2-common.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/drivers/media/video/v4l2-common.c b/drivers/media/video/v4l2-common.c
index a4d68d3ba5e4..32607a612b18 100644
--- a/drivers/media/video/v4l2-common.c
+++ b/drivers/media/video/v4l2-common.c
@@ -1013,6 +1013,35 @@ int v4l2_chip_match_host(u32 match_type, u32 match_chip)
/* ----------------------------------------------------------------- */
+/* Helper function for I2C legacy drivers */
+
+int v4l2_i2c_attach(struct i2c_adapter *adapter, int address, struct i2c_driver *driver,
+ const char *name, int (*probe)(struct i2c_client *))
+{
+ struct i2c_client *client;
+ int err;
+
+ client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
+ if (client == 0)
+ return -ENOMEM;
+
+ client->addr = address;
+ client->adapter = adapter;
+ client->driver = driver;
+ snprintf(client->name, sizeof(client->name) - 1, name);
+
+ err = probe(client);
+ if (err == 0) {
+ i2c_attach_client(client);
+ }
+ else {
+ kfree(client);
+ }
+ return err;
+}
+
+/* ----------------------------------------------------------------- */
+
EXPORT_SYMBOL(v4l2_norm_to_name);
EXPORT_SYMBOL(v4l2_video_std_construct);
@@ -1038,6 +1067,8 @@ EXPORT_SYMBOL(v4l2_chip_match_i2c_client);
EXPORT_SYMBOL(v4l2_chip_ident_i2c_client);
EXPORT_SYMBOL(v4l2_chip_match_host);
+EXPORT_SYMBOL(v4l2_i2c_attach);
+
/*
* Local variables:
* c-basic-offset: 8