diff options
author | Hans Verkuil <hverkuil@xs4all.nl> | 2009-06-19 16:58:21 +0200 |
---|---|---|
committer | Jean Delvare <khali@linux-fr.org> | 2009-06-19 16:58:21 +0200 |
commit | c70366732f67dbdb32f7fe9c6aa59299b76feca6 (patch) | |
tree | 3e091c303c478759f5bf67bcc7f06cfd3f989adb /include/linux/i2c.h | |
parent | 23af8400571ac4431fac0caefeac18f8aef490df (diff) | |
download | linux-exynos-c70366732f67dbdb32f7fe9c6aa59299b76feca6.tar.gz linux-exynos-c70366732f67dbdb32f7fe9c6aa59299b76feca6.tar.bz2 linux-exynos-c70366732f67dbdb32f7fe9c6aa59299b76feca6.zip |
i2c: New macro to initialize i2c address lists on the fly
For video4linux we sometimes need to probe for a single i2c address.
Normally you would do it like this:
static const unsigned short addrs[] = {
addr, I2C_CLIENT_END
};
client = i2c_new_probed_device(adapter, &info, addrs);
This is a bit awkward and I came up with this macro:
#define V4L2_I2C_ADDRS(addr, addrs...) \
((const unsigned short []){ addr, ## addrs, I2C_CLIENT_END })
This can construct a list of one or more i2c addresses on the fly. But
this is something that really belongs in i2c.h, renamed to I2C_ADDRS.
With this macro we can just do:
client = i2c_new_probed_device(adapter, &info, I2C_ADDRS(addr));
Note that this can also be used to initialize an array:
static const unsigned short addrs[] = I2C_ADDRS(0x2a, 0x2c);
Whether you want to is another matter, but it works. This functionality is
also available in the oldest supported gcc (3.2).
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'include/linux/i2c.h')
-rw-r--r-- | include/linux/i2c.h | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/include/linux/i2c.h b/include/linux/i2c.h index bc17f7fa7d39..f4784c0fe975 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h @@ -393,6 +393,10 @@ struct i2c_client_address_data { /* The numbers to use to set I2C bus address */ #define ANY_I2C_BUS 0xffff +/* Construct an I2C_CLIENT_END-terminated array of i2c addresses */ +#define I2C_ADDRS(addr, addrs...) \ + ((const unsigned short []){ addr, ## addrs, I2C_CLIENT_END }) + /* ----- functions exported by i2c.o */ |