[PATCH 2/3] drivers/media/tuners: introduce macros for i2c_msg initialization

Julia Lawall
2012-09-30T07:33:06Z

From: Julia Lawall <Julia.Lawall@lip6.fr>

Introduce use of I2c_MSG_READ/WRITE/OP, for readability.

A simplified version of the semantic patch that makes this change is as
follows: (http://coccinelle.lip6.fr/)

// <smpl>
@@
expression a,b,c;
identifier x;
@@

struct i2c_msg x - {.addr = a, .buf = b, .len = c, .flags = I2C_M_RD}
+ I2C_MSG_READ(a,b,c)
;

@@
expression a,b,c;
identifier x;
@@

struct i2c_msg x - {.addr = a, .buf = b, .len = c, .flags = 0}
+ I2C_MSG_WRITE(a,b,c)
;

@@
expression a,b,c,d;
identifier x;
@@

struct i2c_msg x =
- {.addr = a, .buf = b, .len = c, .flags = d}
+ I2C_MSG_OP(a,b,c,d)
;
// </smpl>

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

---
drivers/media/tuners/e4000.c | 20 +++-----------------
drivers/media/tuners/fc0012.c | 8 +++-----
drivers/media/tuners/fc0013.c | 8 +++-----
drivers/media/tuners/fc2580.c | 20 +++-----------------
drivers/media/tuners/max2165.c | 6 +++---
drivers/media/tuners/mc44s803.c | 7 ++-----
drivers/media/tuners/mt2060.c | 12 ++++--------
drivers/media/tuners/mt2063.c | 21 ++++-----------------
drivers/media/tuners/mt2131.c | 12 ++++--------
drivers/media/tuners/mt2266.c | 12 ++++--------
drivers/media/tuners/mxl5005s.c | 6 ++----
drivers/media/tuners/mxl5007t.c | 14 ++++----------
drivers/media/tuners/qt1010.c | 9 +++------
drivers/media/tuners/tda18212.c | 20 +++-----------------
drivers/media/tuners/tda18218.c | 19 +++----------------
drivers/media/tuners/tda18271-common.c | 15 +++++----------
drivers/media/tuners/tda827x.c | 29 +++++++++++------------------
drivers/media/tuners/tda8290.c | 16 ++++++++--------
drivers/media/tuners/tua9001.c | 7 +------
drivers/media/tuners/tuner-simple.c | 5 +----
drivers/media/tuners/xc4000.c | 9 +++------
drivers/media/tuners/xc5000.c | 12 ++++--------
22 files changed, 81 insertions(+), 206 deletions(-)

diff --git a/drivers/media/tuners/e4000.c b/drivers/media/tuners/e4000.c
index ffaa482..898adc9 100644
--- a/drivers/media/tuners/e4000.c
+++ b/drivers/media/tuners/e4000.c
@@ -26,12 +26,7 @@ static int e4000_wr_regs(struct e4000_priv *priv, u8 reg, u8 *val, int len)
int ret;
u8 buf[1 + len];
struct i2c_msg msg[1] = {
- {
- .addr = priv->cfg->i2c_addr,
- .flags = 0,
- .len = sizeof(buf),
- .buf = buf,
- }
+ I2C_MSG_WRITE(priv->cfg->i2c_addr, buf, sizeof(buf))
};

buf[0] = reg;
@@ -54,17 +49,8 @@ static int e4000_rd_regs(struct e4000_priv *priv, u8 reg, u8 *val, int len)
int ret;
u8 buf[len];
struct i2c_msg msg[2] = {
- {
- .addr = priv->cfg->i2c_addr,
- .flags = 0,
- .len = 1,
- .buf = &reg,
- }, {
- .addr = priv->cfg->i2c_addr,
- .flags = I2C_M_RD,
- .len = sizeof(buf),
- .buf = buf,
- }
+ I2C_MSG_WRITE(priv->cfg->i2c_addr, &reg, 1),
+ I2C_MSG_READ(priv->cfg->i2c_addr, buf, sizeof(buf))
};

ret = i2c_transfer(priv->i2c, msg, 2);
diff --git a/drivers/media/tuners/fc0012.c b/drivers/media/tuners/fc0012.c
index 308135a..8e955e3 100644
--- a/drivers/media/tuners/fc0012.c
+++ b/drivers/media/tuners/fc0012.c
@@ -24,9 +24,7 @@
static int fc0012_writereg(struct fc0012_priv *priv, u8 reg, u8 val)
{
u8 buf[2] = {reg, val};
- struct i2c_msg msg = {
- .addr = priv->addr, .flags = 0, .buf = buf, .len = 2
- };
+ struct i2c_msg msg = I2C_MSG_WRITE(priv->addr, buf, 2);

if (i2c_transfer(priv->i2c, &msg, 1) != 1) {
err("I2C write reg failed, reg: %02x, val: %02x", reg, val);
@@ -38,8 +36,8 @@ static int fc0012_writereg(struct fc0012_priv *priv, u8 reg, u8 val)
static int fc0012_readreg(struct fc0012_priv *priv, u8 reg, u8 *val)
{
struct i2c_msg msg[2] = {
- { .addr = priv->addr, .flags = 0, .buf = &reg, .len = 1 },
- { .addr = priv->addr, .flags = I2C_M_RD, .buf = val, .len = 1 },
+ I2C_MSG_WRITE(priv->addr, &reg, 1),
+ I2C_MSG_READ(priv->addr, val, 1),
};

if (i2c_transfer(priv->i2c, msg, 2) != 2) {
diff --git a/drivers/media/tuners/fc0013.c b/drivers/media/tuners/fc0013.c
index bd8f0f1..569e995 100644
--- a/drivers/media/tuners/fc0013.c
+++ b/drivers/media/tuners/fc0013.c
@@ -27,9 +27,7 @@
static int fc0013_writereg(struct fc0013_priv *priv, u8 reg, u8 val)
{
u8 buf[2] = {reg, val};
- struct i2c_msg msg = {
- .addr = priv->addr, .flags = 0, .buf = buf, .len = 2
- };
+ struct i2c_msg msg = I2C_MSG_WRITE(priv->addr, buf, 2);

if (i2c_transfer(priv->i2c, &msg, 1) != 1) {
err("I2C write reg failed, reg: %02x, val: %02x", reg, val);
@@ -41,8 +39,8 @@ static int fc0013_writereg(struct fc0013_priv *priv, u8 reg, u8 val)
static int fc0013_readreg(struct fc0013_priv *priv, u8 reg, u8 *val)
{
struct i2c_msg msg[2] = {
- { .addr = priv->addr, .flags = 0, .buf = &reg, .len = 1 },
- { .addr = priv->addr, .flags = I2C_M_RD, .buf = val, .len = 1 },
+ I2C_MSG_WRITE(priv->addr, &reg, 1),
+ I2C_MSG_READ(priv->addr, val, 1),
};

if (i2c_transfer(priv->i2c, msg, 2) != 2) {
diff --git a/drivers/media/tuners/fc2580.c b/drivers/media/tuners/fc2580.c
index afc0491..fe04fd5 100644
--- a/drivers/media/tuners/fc2580.c
+++ b/drivers/media/tuners/fc2580.c
@@ -45,12 +45,7 @@ static int fc2580_wr_regs(struct fc2580_priv *priv, u8 reg, u8 *val, int len)
int ret;
u8 buf[1 + len];
struct i2c_msg msg[1] = {
- {
- .addr = priv->cfg->i2c_addr,
- .flags = 0,
- .len = sizeof(buf),
- .buf = buf,
- }
+ I2C_MSG_WRITE(priv->cfg->i2c_addr, buf, sizeof(buf))
};

buf[0] = reg;
@@ -73,17 +68,8 @@ static int fc2580_rd_regs(struct fc2580_priv *priv, u8 reg, u8 *val, int len)
int ret;
u8 buf[len];
struct i2c_msg msg[2] = {
- {
- .addr = priv->cfg->i2c_addr,
- .flags = 0,
- .len = 1,
- .buf = &reg,
- }, {
- .addr = priv->cfg->i2c_addr,
- .flags = I2C_M_RD,
- .len = sizeof(buf),
- .buf = buf,
- }
+ I2C_MSG_WRITE(priv->cfg->i2c_addr, &reg, 1),
+ I2C_MSG_READ(priv->cfg->i2c_addr, buf, sizeof(buf))
};

ret = i2c_transfer(priv->i2c, msg, 2);
diff --git a/drivers/media/tuners/max2165.c b/drivers/media/tuners/max2165.c
index ba84936..3606117 100644
--- a/drivers/media/tuners/max2165.c
+++ b/drivers/media/tuners/max2165.c
@@ -47,7 +47,7 @@ static int max2165_write_reg(struct max2165_priv *priv, u8 reg, u8 data)
{
int ret;
u8 buf[] = { reg, data };
- struct i2c_msg msg = { .flags = 0, .buf = buf, .len = 2 };
+ struct i2c_msg msg = I2C_MSG_WRITE(0, buf, 2);

msg.addr = priv->config->i2c_address;

@@ -71,8 +71,8 @@ static int max2165_read_reg(struct max2165_priv *priv, u8 reg, u8 *p_data)
u8 b0[] = { reg };
u8 b1[] = { 0 };
struct i2c_msg msg[] = {
- { .addr = dev_addr, .flags = 0, .buf = b0, .len = 1 },
- { .addr = dev_addr, .flags = I2C_M_RD, .buf = b1, .len = 1 },
+ I2C_MSG_WRITE(dev_addr, b0, 1),
+ I2C_MSG_READ(dev_addr, b1, 1),
};

ret = i2c_transfer(priv->i2c, msg, 2);
diff --git a/drivers/media/tuners/mc44s803.c b/drivers/media/tuners/mc44s803.c
index f1b7640..e09ba2b 100644
--- a/drivers/media/tuners/mc44s803.c
+++ b/drivers/media/tuners/mc44s803.c
@@ -37,9 +37,7 @@
static int mc44s803_writereg(struct mc44s803_priv *priv, u32 val)
{
u8 buf[3];
- struct i2c_msg msg = {
- .addr = priv->cfg->i2c_address, .flags = 0, .buf = buf, .len = 3
- };
+ struct i2c_msg msg = I2C_MSG_WRITE(priv->cfg->i2c_address, buf, 3);

buf[0] = (val & 0xff0000) >> 16;
buf[1] = (val & 0xff00) >> 8;
@@ -59,8 +57,7 @@ static int mc44s803_readreg(struct mc44s803_priv *priv, u8 reg, u32 *val)
u8 buf[3];
int ret;
struct i2c_msg msg[] = {
- { .addr = priv->cfg->i2c_address, .flags = I2C_M_RD,
- .buf = buf, .len = 3 },
+ I2C_MSG_READ(priv->cfg->i2c_address, buf, 3),
};

wval = MC44S803_REG_SM(MC44S803_REG_DATAREG, MC44S803_ADDR) |
diff --git a/drivers/media/tuners/mt2060.c b/drivers/media/tuners/mt2060.c
index 13381de..bd0556a 100644
--- a/drivers/media/tuners/mt2060.c
+++ b/drivers/media/tuners/mt2060.c
@@ -42,8 +42,8 @@ MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off).");
static int mt2060_readreg(struct mt2060_priv *priv, u8 reg, u8 *val)
{
struct i2c_msg msg[2] = {
- { .addr = priv->cfg->i2c_address, .flags = 0, .buf = &reg, .len = 1 },
- { .addr = priv->cfg->i2c_address, .flags = I2C_M_RD, .buf = val, .len = 1 },
+ I2C_MSG_WRITE(priv->cfg->i2c_address, &reg, 1),
+ I2C_MSG_READ(priv->cfg->i2c_address, val, 1),
};

if (i2c_transfer(priv->i2c, msg, 2) != 2) {
@@ -57,9 +57,7 @@ static int mt2060_readreg(struct mt2060_priv *priv, u8 reg, u8 *val)
static int mt2060_writereg(struct mt2060_priv *priv, u8 reg, u8 val)
{
u8 buf[2] = { reg, val };
- struct i2c_msg msg = {
- .addr = priv->cfg->i2c_address, .flags = 0, .buf = buf, .len = 2
- };
+ struct i2c_msg msg = I2C_MSG_WRITE(priv->cfg->i2c_address, buf, 2);

if (i2c_transfer(priv->i2c, &msg, 1) != 1) {
printk(KERN_WARNING "mt2060 I2C write failed\n");
@@ -71,9 +69,7 @@ static int mt2060_writereg(struct mt2060_priv *priv, u8 reg, u8 val)
// Writes a set of consecutive registers
static int mt2060_writeregs(struct mt2060_priv *priv,u8 *buf, u8 len)
{
- struct i2c_msg msg = {
- .addr = priv->cfg->i2c_address, .flags = 0, .buf = buf, .len = len
- };
+ struct i2c_msg msg = I2C_MSG_WRITE(priv->cfg->i2c_address, buf, len);
if (i2c_transfer(priv->i2c, &msg, 1) != 1) {
printk(KERN_WARNING "mt2060 I2C write failed (len=%i)\n",(int)len);
return -EREMOTEIO;
diff --git a/drivers/media/tuners/mt2063.c b/drivers/media/tuners/mt2063.c
index 0ed9091..e45186f 100644
--- a/drivers/media/tuners/mt2063.c
+++ b/drivers/media/tuners/mt2063.c
@@ -250,12 +250,8 @@ static u32 mt2063_write(struct mt2063_state *state, u8 reg, u8 *data, u32 len)
struct dvb_frontend *fe = state->frontend;
int ret;
u8 buf[60];
- struct i2c_msg msg = {
- .addr = state->config->tuner_address,
- .flags = 0,
- .buf = buf,
- .len = len + 1
- };
+ struct i2c_msg msg + I2C_MSG_WRITE(state->config->tuner_address, buf, len + 1);

dprintk(2, "\n");

@@ -313,17 +309,8 @@ static u32 mt2063_read(struct mt2063_state *state,
for (i = 0; i < cnt; i++) {
u8 b0[] = { subAddress + i };
struct i2c_msg msg[] = {
- {
- .addr = state->config->tuner_address,
- .flags = 0,
- .buf = b0,
- .len = 1
- }, {
- .addr = state->config->tuner_address,
- .flags = I2C_M_RD,
- .buf = pData + i,
- .len = 1
- }
+ I2C_MSG_WRITE(state->config->tuner_address, b0, 1),
+ I2C_MSG_READ(state->config->tuner_address, pData + i, 1)
};

status = i2c_transfer(state->i2c, msg, 2);
diff --git a/drivers/media/tuners/mt2131.c b/drivers/media/tuners/mt2131.c
index f83b0c1..cdc32b7 100644
--- a/drivers/media/tuners/mt2131.c
+++ b/drivers/media/tuners/mt2131.c
@@ -53,10 +53,8 @@ static u8 mt2131_config2[] = {
static int mt2131_readreg(struct mt2131_priv *priv, u8 reg, u8 *val)
{
struct i2c_msg msg[2] = {
- { .addr = priv->cfg->i2c_address, .flags = 0,
- .buf = &reg, .len = 1 },
- { .addr = priv->cfg->i2c_address, .flags = I2C_M_RD,
- .buf = val, .len = 1 },
+ I2C_MSG_WRITE(priv->cfg->i2c_address, &reg, 1),
+ I2C_MSG_READ(priv->cfg->i2c_address, val, 1),
};

if (i2c_transfer(priv->i2c, msg, 2) != 2) {
@@ -69,8 +67,7 @@ static int mt2131_readreg(struct mt2131_priv *priv, u8 reg, u8 *val)
static int mt2131_writereg(struct mt2131_priv *priv, u8 reg, u8 val)
{
u8 buf[2] = { reg, val };
- struct i2c_msg msg = { .addr = priv->cfg->i2c_address, .flags = 0,
- .buf = buf, .len = 2 };
+ struct i2c_msg msg = I2C_MSG_WRITE(priv->cfg->i2c_address, buf, 2);

if (i2c_transfer(priv->i2c, &msg, 1) != 1) {
printk(KERN_WARNING "mt2131 I2C write failed\n");
@@ -81,8 +78,7 @@ static int mt2131_writereg(struct mt2131_priv *priv, u8 reg, u8 val)

static int mt2131_writeregs(struct mt2131_priv *priv,u8 *buf, u8 len)
{
- struct i2c_msg msg = { .addr = priv->cfg->i2c_address,
- .flags = 0, .buf = buf, .len = len };
+ struct i2c_msg msg = I2C_MSG_WRITE(priv->cfg->i2c_address, buf, len);

if (i2c_transfer(priv->i2c, &msg, 1) != 1) {
printk(KERN_WARNING "mt2131 I2C write failed (len=%i)\n",
diff --git a/drivers/media/tuners/mt2266.c b/drivers/media/tuners/mt2266.c
index bca4d75..4159e6b 100644
--- a/drivers/media/tuners/mt2266.c
+++ b/drivers/media/tuners/mt2266.c
@@ -57,8 +57,8 @@ MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off).");
static int mt2266_readreg(struct mt2266_priv *priv, u8 reg, u8 *val)
{
struct i2c_msg msg[2] = {
- { .addr = priv->cfg->i2c_address, .flags = 0, .buf = &reg, .len = 1 },
- { .addr = priv->cfg->i2c_address, .flags = I2C_M_RD, .buf = val, .len = 1 },
+ I2C_MSG_WRITE(priv->cfg->i2c_address, &reg, 1),
+ I2C_MSG_READ(priv->cfg->i2c_address, val, 1),
};
if (i2c_transfer(priv->i2c, msg, 2) != 2) {
printk(KERN_WARNING "MT2266 I2C read failed\n");
@@ -71,9 +71,7 @@ static int mt2266_readreg(struct mt2266_priv *priv, u8 reg, u8 *val)
static int mt2266_writereg(struct mt2266_priv *priv, u8 reg, u8 val)
{
u8 buf[2] = { reg, val };
- struct i2c_msg msg = {
- .addr = priv->cfg->i2c_address, .flags = 0, .buf = buf, .len = 2
- };
+ struct i2c_msg msg = I2C_MSG_WRITE(priv->cfg->i2c_address, buf, 2);
if (i2c_transfer(priv->i2c, &msg, 1) != 1) {
printk(KERN_WARNING "MT2266 I2C write failed\n");
return -EREMOTEIO;
@@ -84,9 +82,7 @@ static int mt2266_writereg(struct mt2266_priv *priv, u8 reg, u8 val)
// Writes a set of consecutive registers
static int mt2266_writeregs(struct mt2266_priv *priv,u8 *buf, u8 len)
{
- struct i2c_msg msg = {
- .addr = priv->cfg->i2c_address, .flags = 0, .buf = buf, .len = len
- };
+ struct i2c_msg msg = I2C_MSG_WRITE(priv->cfg->i2c_address, buf, len);
if (i2c_transfer(priv->i2c, &msg, 1) != 1) {
printk(KERN_WARNING "MT2266 I2C write failed (len=%i)\n",(int)len);
return -EREMOTEIO;
diff --git a/drivers/media/tuners/mxl5005s.c b/drivers/media/tuners/mxl5005s.c
index b473b76..ff7ba97 100644
--- a/drivers/media/tuners/mxl5005s.c
+++ b/drivers/media/tuners/mxl5005s.c
@@ -3848,8 +3848,7 @@ static int mxl5005s_reset(struct dvb_frontend *fe)
int ret = 0;

u8 buf[2] = { 0xff, 0x00 };
- struct i2c_msg msg = { .addr = state->config->i2c_address, .flags = 0,
- .buf = buf, .len = 2 };
+ struct i2c_msg msg = I2C_MSG_WRITE(state->config->i2c_address, buf, 2);

dprintk(2, "%s()\n", __func__);

@@ -3874,8 +3873,7 @@ static int mxl5005s_writereg(struct dvb_frontend *fe, u8 reg, u8 val, int latch)
{
struct mxl5005s_state *state = fe->tuner_priv;
u8 buf[3] = { reg, val, MXL5005S_LATCH_BYTE };
- struct i2c_msg msg = { .addr = state->config->i2c_address, .flags = 0,
- .buf = buf, .len = 3 };
+ struct i2c_msg msg = I2C_MSG_WRITE(state->config->i2c_address, buf, 3);

if (latch = 0)
msg.len = 2;
diff --git a/drivers/media/tuners/mxl5007t.c b/drivers/media/tuners/mxl5007t.c
index 69e453e..62774aa 100644
--- a/drivers/media/tuners/mxl5007t.c
+++ b/drivers/media/tuners/mxl5007t.c
@@ -464,8 +464,7 @@ reg_pair_t *mxl5007t_calc_rf_tune_regs(struct mxl5007t_state *state,
static int mxl5007t_write_reg(struct mxl5007t_state *state, u8 reg, u8 val)
{
u8 buf[] = { reg, val };
- struct i2c_msg msg = { .addr = state->i2c_props.addr, .flags = 0,
- .buf = buf, .len = 2 };
+ struct i2c_msg msg = I2C_MSG_WRITE(state->i2c_props.addr, buf, 2);
int ret;

ret = i2c_transfer(state->i2c_props.adap, &msg, 1);
@@ -494,10 +493,8 @@ static int mxl5007t_read_reg(struct mxl5007t_state *state, u8 reg, u8 *val)
{
u8 buf[2] = { 0xfb, reg };
struct i2c_msg msg[] = {
- { .addr = state->i2c_props.addr, .flags = 0,
- .buf = buf, .len = 2 },
- { .addr = state->i2c_props.addr, .flags = I2C_M_RD,
- .buf = val, .len = 1 },
+ I2C_MSG_WRITE(state->i2c_props.addr, buf, 2),
+ I2C_MSG_READ(state->i2c_props.addr, val, 1),
};
int ret;

@@ -512,10 +509,7 @@ static int mxl5007t_read_reg(struct mxl5007t_state *state, u8 reg, u8 *val)
static int mxl5007t_soft_reset(struct mxl5007t_state *state)
{
u8 d = 0xff;
- struct i2c_msg msg = {
- .addr = state->i2c_props.addr, .flags = 0,
- .buf = &d, .len = 1
- };
+ struct i2c_msg msg = I2C_MSG_WRITE(state->i2c_props.addr, &d, 1);
int ret = i2c_transfer(state->i2c_props.adap, &msg, 1);

if (ret != 1) {
diff --git a/drivers/media/tuners/qt1010.c b/drivers/media/tuners/qt1010.c
index bc419f8..2358300 100644
--- a/drivers/media/tuners/qt1010.c
+++ b/drivers/media/tuners/qt1010.c
@@ -25,10 +25,8 @@
static int qt1010_readreg(struct qt1010_priv *priv, u8 reg, u8 *val)
{
struct i2c_msg msg[2] = {
- { .addr = priv->cfg->i2c_address,
- .flags = 0, .buf = &reg, .len = 1 },
- { .addr = priv->cfg->i2c_address,
- .flags = I2C_M_RD, .buf = val, .len = 1 },
+ I2C_MSG_WRITE(priv->cfg->i2c_address, &reg, 1),
+ I2C_MSG_READ(priv->cfg->i2c_address, val, 1),
};

if (i2c_transfer(priv->i2c, msg, 2) != 2) {
@@ -43,8 +41,7 @@ static int qt1010_readreg(struct qt1010_priv *priv, u8 reg, u8 *val)
static int qt1010_writereg(struct qt1010_priv *priv, u8 reg, u8 val)
{
u8 buf[2] = { reg, val };
- struct i2c_msg msg = { .addr = priv->cfg->i2c_address,
- .flags = 0, .buf = buf, .len = 2 };
+ struct i2c_msg msg = I2C_MSG_WRITE(priv->cfg->i2c_address, buf, 2);

if (i2c_transfer(priv->i2c, &msg, 1) != 1) {
dev_warn(&priv->i2c->dev, "%s: i2c wr failed reg=%02x\n",
diff --git a/drivers/media/tuners/tda18212.c b/drivers/media/tuners/tda18212.c
index 5d9f028..2d9a459 100644
--- a/drivers/media/tuners/tda18212.c
+++ b/drivers/media/tuners/tda18212.c
@@ -34,12 +34,7 @@ static int tda18212_wr_regs(struct tda18212_priv *priv, u8 reg, u8 *val,
int ret;
u8 buf[len+1];
struct i2c_msg msg[1] = {
- {
- .addr = priv->cfg->i2c_address,
- .flags = 0,
- .len = sizeof(buf),
- .buf = buf,
- }
+ I2C_MSG_WRITE(priv->cfg->i2c_address, buf, sizeof(buf))
};

buf[0] = reg;
@@ -63,17 +58,8 @@ static int tda18212_rd_regs(struct tda18212_priv *priv, u8 reg, u8 *val,
int ret;
u8 buf[len];
struct i2c_msg msg[2] = {
- {
- .addr = priv->cfg->i2c_address,
- .flags = 0,
- .len = 1,
- .buf = &reg,
- }, {
- .addr = priv->cfg->i2c_address,
- .flags = I2C_M_RD,
- .len = sizeof(buf),
- .buf = buf,
- }
+ I2C_MSG_WRITE(priv->cfg->i2c_address, &reg, 1),
+ I2C_MSG_READ(priv->cfg->i2c_address, buf, sizeof(buf))
};

ret = i2c_transfer(priv->i2c, msg, 2);
diff --git a/drivers/media/tuners/tda18218.c b/drivers/media/tuners/tda18218.c
index 1819853..ecb5406 100644
--- a/drivers/media/tuners/tda18218.c
+++ b/drivers/media/tuners/tda18218.c
@@ -26,11 +26,7 @@ static int tda18218_wr_regs(struct tda18218_priv *priv, u8 reg, u8 *val, u8 len)
int ret = 0, len2, remaining;
u8 buf[1 + len];
struct i2c_msg msg[1] = {
- {
- .addr = priv->cfg->i2c_address,
- .flags = 0,
- .buf = buf,
- }
+ I2C_MSG_WRITE(priv->cfg->i2c_address, buf, 0)
};

for (remaining = len; remaining > 0;
@@ -65,17 +61,8 @@ static int tda18218_rd_regs(struct tda18218_priv *priv, u8 reg, u8 *val, u8 len)
int ret;
u8 buf[reg+len]; /* we must start read always from reg 0x00 */
struct i2c_msg msg[2] = {
- {
- .addr = priv->cfg->i2c_address,
- .flags = 0,
- .len = 1,
- .buf = "\x00",
- }, {
- .addr = priv->cfg->i2c_address,
- .flags = I2C_M_RD,
- .len = sizeof(buf),
- .buf = buf,
- }
+ I2C_MSG_WRITE(priv->cfg->i2c_address, "\x00", 1),
+ I2C_MSG_READ(priv->cfg->i2c_address, buf, sizeof(buf))
};

ret = i2c_transfer(priv->i2c, msg, 2);
diff --git a/drivers/media/tuners/tda18271-common.c b/drivers/media/tuners/tda18271-common.c
index 221171e..bf7a564 100644
--- a/drivers/media/tuners/tda18271-common.c
+++ b/drivers/media/tuners/tda18271-common.c
@@ -125,10 +125,8 @@ int tda18271_read_regs(struct dvb_frontend *fe)
unsigned char buf = 0x00;
int ret;
struct i2c_msg msg[] = {
- { .addr = priv->i2c_props.addr, .flags = 0,
- .buf = &buf, .len = 1 },
- { .addr = priv->i2c_props.addr, .flags = I2C_M_RD,
- .buf = regs, .len = 16 }
+ I2C_MSG_WRITE(priv->i2c_props.addr, &buf, 1),
+ I2C_MSG_READ(priv->i2c_props.addr, regs, 16)
};

tda18271_i2c_gate_ctrl(fe, 1);
@@ -155,10 +153,8 @@ int tda18271_read_extended(struct dvb_frontend *fe)
unsigned char buf = 0x00;
int ret, i;
struct i2c_msg msg[] = {
- { .addr = priv->i2c_props.addr, .flags = 0,
- .buf = &buf, .len = 1 },
- { .addr = priv->i2c_props.addr, .flags = I2C_M_RD,
- .buf = regdump, .len = TDA18271_NUM_REGS }
+ I2C_MSG_WRITE(priv->i2c_props.addr, &buf, 1),
+ I2C_MSG_READ(priv->i2c_props.addr, regdump, TDA18271_NUM_REGS)
};

tda18271_i2c_gate_ctrl(fe, 1);
@@ -192,8 +188,7 @@ int tda18271_write_regs(struct dvb_frontend *fe, int idx, int len)
struct tda18271_priv *priv = fe->tuner_priv;
unsigned char *regs = priv->tda18271_regs;
unsigned char buf[TDA18271_NUM_REGS + 1];
- struct i2c_msg msg = { .addr = priv->i2c_props.addr, .flags = 0,
- .buf = buf };
+ struct i2c_msg msg = I2C_MSG_WRITE(priv->i2c_props.addr, buf, 0);
int i, ret = 1, max;

BUG_ON((len = 0) || (idx + len > sizeof(buf)));
diff --git a/drivers/media/tuners/tda827x.c b/drivers/media/tuners/tda827x.c
index a0d1762..b75a29e 100644
--- a/drivers/media/tuners/tda827x.c
+++ b/drivers/media/tuners/tda827x.c
@@ -159,8 +159,7 @@ static int tda827xo_set_params(struct dvb_frontend *fe)
u8 buf[14];
int rc;

- struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,
- .buf = buf, .len = sizeof(buf) };
+ struct i2c_msg msg = I2C_MSG_WRITE(priv->i2c_addr, buf, sizeof(buf));
int i, tuner_freq, if_freq;
u32 N;

@@ -233,8 +232,7 @@ static int tda827xo_sleep(struct dvb_frontend *fe)
{
struct tda827x_priv *priv = fe->tuner_priv;
static u8 buf[] = { 0x30, 0xd0 };
- struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,
- .buf = buf, .len = sizeof(buf) };
+ struct i2c_msg msg = I2C_MSG_WRITE(priv->i2c_addr, buf, sizeof(buf));

dprintk("%s:\n", __func__);
tuner_transfer(fe, &msg, 1);
@@ -255,7 +253,7 @@ static int tda827xo_set_analog_params(struct dvb_frontend *fe,
u32 N;
int i;
struct tda827x_priv *priv = fe->tuner_priv;
- struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0 };
+ struct i2c_msg msg = I2C_MSG_WRITE(priv->i2c_addr, NULL, 0);
unsigned int freq = params->frequency;

tda827x_set_std(fe, params);
@@ -335,8 +333,7 @@ static void tda827xo_agcf(struct dvb_frontend *fe)
{
struct tda827x_priv *priv = fe->tuner_priv;
unsigned char data[] = { 0x80, 0x0c };
- struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,
- .buf = data, .len = 2};
+ struct i2c_msg msg = I2C_MSG_WRITE(priv->i2c_addr, data, 2);

tuner_transfer(fe, &msg, 1);
}
@@ -445,8 +442,7 @@ static int tda827xa_sleep(struct dvb_frontend *fe)
{
struct tda827x_priv *priv = fe->tuner_priv;
static u8 buf[] = { 0x30, 0x90 };
- struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,
- .buf = buf, .len = sizeof(buf) };
+ struct i2c_msg msg = I2C_MSG_WRITE(priv->i2c_addr, buf, sizeof(buf));

dprintk("%s:\n", __func__);

@@ -465,7 +461,7 @@ static void tda827xa_lna_gain(struct dvb_frontend *fe, int high,
unsigned char buf[] = {0x22, 0x01};
int arg;
int gp_func;
- struct i2c_msg msg = { .flags = 0, .buf = buf, .len = sizeof(buf) };
+ struct i2c_msg msg = I2C_MSG_WRITE(0, buf, sizeof(buf));

if (NULL = priv->cfg) {
dprintk("tda827x_config not defined, cannot set LNA gain!\n");
@@ -518,8 +514,7 @@ static int tda827xa_set_params(struct dvb_frontend *fe)
struct tda827xa_data *frequency_map = tda827xa_dvbt;
u8 buf[11];

- struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,
- .buf = buf, .len = sizeof(buf) };
+ struct i2c_msg msg = I2C_MSG_WRITE(priv->i2c_addr, buf, sizeof(buf));

int i, tuner_freq, if_freq, rc;
u32 N;
@@ -665,8 +660,8 @@ static int tda827xa_set_analog_params(struct dvb_frontend *fe,
u32 N;
int i;
struct tda827x_priv *priv = fe->tuner_priv;
- struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,
- .buf = tuner_reg, .len = sizeof(tuner_reg) };
+ struct i2c_msg msg = I2C_MSG_WRITE(priv->i2c_addr, tuner_reg,
+ sizeof(tuner_reg));
unsigned int freq = params->frequency;

tda827x_set_std(fe, params);
@@ -760,8 +755,7 @@ static void tda827xa_agcf(struct dvb_frontend *fe)
{
struct tda827x_priv *priv = fe->tuner_priv;
unsigned char data[] = {0x80, 0x2c};
- struct i2c_msg msg = {.addr = priv->i2c_addr, .flags = 0,
- .buf = data, .len = 2};
+ struct i2c_msg msg = I2C_MSG_WRITE(priv->i2c_addr, data, 2);
tuner_transfer(fe, &msg, 1);
}

@@ -855,8 +849,7 @@ static int tda827x_probe_version(struct dvb_frontend *fe)
u8 data;
int rc;
struct tda827x_priv *priv = fe->tuner_priv;
- struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = I2C_M_RD,
- .buf = &data, .len = 1 };
+ struct i2c_msg msg = I2C_MSG_READ(priv->i2c_addr, &data, 1);

rc = tuner_transfer(fe, &msg, 1);

diff --git a/drivers/media/tuners/tda8290.c b/drivers/media/tuners/tda8290.c
index 8c48521..cf3dc6f 100644
--- a/drivers/media/tuners/tda8290.c
+++ b/drivers/media/tuners/tda8290.c
@@ -463,7 +463,7 @@ static void tda8290_standby(struct dvb_frontend *fe)
unsigned char cb1[] = { 0x30, 0xD0 };
unsigned char tda8290_standby[] = { 0x00, 0x02 };
unsigned char tda8290_agc_tri[] = { 0x02, 0x20 };
- struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0, .bufË1, .len = 2};
+ struct i2c_msg msg = I2C_MSG_WRITE(priv->tda827x_addr, cb1, 2);

tda8290_i2c_bridge(fe, 1);
if (priv->ver & TDA8275A)
@@ -532,8 +532,8 @@ static void tda8290_init_tuner(struct dvb_frontend *fe)
0x3F, 0x2A, 0x04, 0xFF, 0x00, 0x00, 0x40 };
unsigned char tda8275a_init[] = { 0x00, 0x00, 0x00, 0x00, 0xdC, 0x05, 0x8b,
0x0c, 0x04, 0x20, 0xFF, 0x00, 0x00, 0x4b };
- struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0,
- .buf=tda8275_init, .len = 14};
+ struct i2c_msg msg = I2C_MSG_WRITE(priv->tda827x_addr, tda8275_init,
+ 14);
if (priv->ver & TDA8275A)
msg.buf = tda8275a_init;

@@ -569,7 +569,7 @@ static int tda829x_find_tuner(struct dvb_frontend *fe)
int i, ret, tuners_found;
u32 tuner_addrs;
u8 data;
- struct i2c_msg msg = { .flags = I2C_M_RD, .buf = &data, .len = 1 };
+ struct i2c_msg msg = I2C_MSG_READ(0, &data, 1);

if (!analog_ops->i2c_gate_ctrl) {
printk(KERN_ERR "tda8290: no gate control were provided!\n");
@@ -658,8 +658,8 @@ static int tda8290_probe(struct tuner_i2c_props *i2c_props)
#define TDA8290_ID 0x89
u8 reg = 0x1f, id;
struct i2c_msg msg_read[] = {
- { .addr = i2c_props->addr, .flags = 0, .len = 1, .buf = &reg },
- { .addr = i2c_props->addr, .flags = I2C_M_RD, .len = 1, .buf = &id },
+ I2C_MSG_WRITE(i2c_props->addr, &reg, 1),
+ I2C_MSG_READ(i2c_props->addr, &id, 1),
};

/* detect tda8290 */
@@ -685,8 +685,8 @@ static int tda8295_probe(struct tuner_i2c_props *i2c_props)
#define TDA8295C2_ID 0x8b
u8 reg = 0x2f, id;
struct i2c_msg msg_read[] = {
- { .addr = i2c_props->addr, .flags = 0, .len = 1, .buf = &reg },
- { .addr = i2c_props->addr, .flags = I2C_M_RD, .len = 1, .buf = &id },
+ I2C_MSG_WRITE(i2c_props->addr, &reg, 1),
+ I2C_MSG_READ(i2c_props->addr, &id, 1),
};

/* detect tda8295 */
diff --git a/drivers/media/tuners/tua9001.c b/drivers/media/tuners/tua9001.c
index e6394fc..afbfefc 100644
--- a/drivers/media/tuners/tua9001.c
+++ b/drivers/media/tuners/tua9001.c
@@ -27,12 +27,7 @@ static int tua9001_wr_reg(struct tua9001_priv *priv, u8 reg, u16 val)
int ret;
u8 buf[3] = { reg, (val >> 8) & 0xff, (val >> 0) & 0xff };
struct i2c_msg msg[1] = {
- {
- .addr = priv->cfg->i2c_addr,
- .flags = 0,
- .len = sizeof(buf),
- .buf = buf,
- }
+ I2C_MSG_WRITE(priv->cfg->i2c_addr, buf, sizeof(buf))
};

ret = i2c_transfer(priv->i2c, msg, 1);
diff --git a/drivers/media/tuners/tuner-simple.c b/drivers/media/tuners/tuner-simple.c
index 39e7e58..1d946af 100644
--- a/drivers/media/tuners/tuner-simple.c
+++ b/drivers/media/tuners/tuner-simple.c
@@ -1065,10 +1065,7 @@ struct dvb_frontend *simple_tuner_attach(struct dvb_frontend *fe,
*/
if (i2c_adap != NULL) {
u8 b[1];
- struct i2c_msg msg = {
- .addr = i2c_addr, .flags = I2C_M_RD,
- .buf = b, .len = 1,
- };
+ struct i2c_msg msg = I2C_MSG_READ(i2c_addr, b, 1);

if (fe->ops.i2c_gate_ctrl)
fe->ops.i2c_gate_ctrl(fe, 1);
diff --git a/drivers/media/tuners/xc4000.c b/drivers/media/tuners/xc4000.c
index 4937712..c4fb078 100644
--- a/drivers/media/tuners/xc4000.c
+++ b/drivers/media/tuners/xc4000.c
@@ -256,8 +256,7 @@ static void xc_debug_dump(struct xc4000_priv *priv);

static int xc_send_i2c_data(struct xc4000_priv *priv, u8 *buf, int len)
{
- struct i2c_msg msg = { .addr = priv->i2c_props.addr,
- .flags = 0, .buf = buf, .len = len };
+ struct i2c_msg msg = I2C_MSG_WRITE(priv->i2c_props.addr, buf, len);
if (i2c_transfer(priv->i2c_props.adap, &msg, 1) != 1) {
if (priv->ignore_i2c_write_errors = 0) {
printk(KERN_ERR "xc4000: I2C write failed (len=%i)\n",
@@ -550,10 +549,8 @@ static int xc4000_readreg(struct xc4000_priv *priv, u16 reg, u16 *val)
u8 buf[2] = { reg >> 8, reg & 0xff };
u8 bval[2] = { 0, 0 };
struct i2c_msg msg[2] = {
- { .addr = priv->i2c_props.addr,
- .flags = 0, .buf = &buf[0], .len = 2 },
- { .addr = priv->i2c_props.addr,
- .flags = I2C_M_RD, .buf = &bval[0], .len = 2 },
+ I2C_MSG_WRITE(priv->i2c_props.addr, &buf[0], 2),
+ I2C_MSG_READ(priv->i2c_props.addr, &bval[0], 2),
};

if (i2c_transfer(priv->i2c_props.adap, msg, 2) != 2) {
diff --git a/drivers/media/tuners/xc5000.c b/drivers/media/tuners/xc5000.c
index dc93cf3..84c9870 100644
--- a/drivers/media/tuners/xc5000.c
+++ b/drivers/media/tuners/xc5000.c
@@ -253,8 +253,7 @@ static int xc5000_TunerReset(struct dvb_frontend *fe);

static int xc_send_i2c_data(struct xc5000_priv *priv, u8 *buf, int len)
{
- struct i2c_msg msg = { .addr = priv->i2c_props.addr,
- .flags = 0, .buf = buf, .len = len };
+ struct i2c_msg msg = I2C_MSG_WRITE(priv->i2c_props.addr, buf, len);

if (i2c_transfer(priv->i2c_props.adap, &msg, 1) != 1) {
printk(KERN_ERR "xc5000: I2C write failed (len=%i)\n", len);
@@ -269,8 +268,7 @@ static int xc_send_i2c_data(struct xc5000_priv *priv, u8 *buf, int len)
transaction in case we are on a multi-master bus */
static int xc_read_i2c_data(struct xc5000_priv *priv, u8 *buf, int len)
{
- struct i2c_msg msg = { .addr = priv->i2c_props.addr,
- .flags = I2C_M_RD, .buf = buf, .len = len };
+ struct i2c_msg msg = I2C_MSG_READ(priv->i2c_props.addr, buf, len);

if (i2c_transfer(priv->i2c_props.adap, &msg, 1) != 1) {
printk(KERN_ERR "xc5000 I2C read failed (len=%i)\n", len);
@@ -285,10 +283,8 @@ static int xc5000_readreg(struct xc5000_priv *priv, u16 reg, u16 *val)
u8 buf[2] = { reg >> 8, reg & 0xff };
u8 bval[2] = { 0, 0 };
struct i2c_msg msg[2] = {
- { .addr = priv->i2c_props.addr,
- .flags = 0, .buf = &buf[0], .len = 2 },
- { .addr = priv->i2c_props.addr,
- .flags = I2C_M_RD, .buf = &bval[0], .len = 2 },
+ I2C_MSG_WRITE(priv->i2c_props.addr, &buf[0], 2),
+ I2C_MSG_READ(priv->i2c_props.addr, &bval[0], 2),
};

if (i2c_transfer(priv->i2c_props.adap, msg, 2) != 2) {

--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html