Commit ee36381e authored by Antti Palosaari's avatar Antti Palosaari Committed by Mauro Carvalho Chehab

[media] af9035: few small I2C master xfer changes

Biggest problem of that function is complexity. Try reduce complexity:

* define macros to detect all 3 supported xfers
* remove duplicate message maximum size checks
Signed-off-by: default avatarAntti Palosaari <crope@iki.fi>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@osg.samsung.com>
parent 6a087f1f
...@@ -319,8 +319,14 @@ static int af9035_i2c_master_xfer(struct i2c_adapter *adap, ...@@ -319,8 +319,14 @@ static int af9035_i2c_master_xfer(struct i2c_adapter *adap,
* bus, having same slave address. Due to that we reuse demod address, * bus, having same slave address. Due to that we reuse demod address,
* shifted by one bit, on that case. * shifted by one bit, on that case.
*/ */
if (num == 2 && !(msg[0].flags & I2C_M_RD) && #define AF9035_IS_I2C_XFER_WRITE_READ(_msg, _num) \
(msg[1].flags & I2C_M_RD)) { (_num == 2 && !(_msg[0].flags & I2C_M_RD) && (_msg[1].flags & I2C_M_RD))
#define AF9035_IS_I2C_XFER_WRITE(_msg, _num) \
(_num == 1 && !(_msg[0].flags & I2C_M_RD))
#define AF9035_IS_I2C_XFER_READ(_msg, _num) \
(_num == 1 && (_msg[0].flags & I2C_M_RD))
if (AF9035_IS_I2C_XFER_WRITE_READ(msg, num)) {
if (msg[0].len > 40 || msg[1].len > 40) { if (msg[0].len > 40 || msg[1].len > 40) {
/* TODO: correct limits > 40 */ /* TODO: correct limits > 40 */
ret = -EOPNOTSUPP; ret = -EOPNOTSUPP;
...@@ -338,18 +344,11 @@ static int af9035_i2c_master_xfer(struct i2c_adapter *adap, ...@@ -338,18 +344,11 @@ static int af9035_i2c_master_xfer(struct i2c_adapter *adap,
ret = af9035_rd_regs(d, reg, &msg[1].buf[0], ret = af9035_rd_regs(d, reg, &msg[1].buf[0],
msg[1].len); msg[1].len);
} else { } else {
/* I2C */ /* I2C write + read */
u8 buf[MAX_XFER_SIZE]; u8 buf[MAX_XFER_SIZE];
struct usb_req req = { CMD_I2C_RD, 0, 5 + msg[0].len, struct usb_req req = { CMD_I2C_RD, 0, 5 + msg[0].len,
buf, msg[1].len, msg[1].buf }; buf, msg[1].len, msg[1].buf };
if (5 + msg[0].len > sizeof(buf)) {
dev_warn(&d->udev->dev,
"%s: i2c xfer: len=%d is too big!\n",
KBUILD_MODNAME, msg[0].len);
ret = -EOPNOTSUPP;
goto unlock;
}
req.mbox |= ((msg[0].addr & 0x80) >> 3); req.mbox |= ((msg[0].addr & 0x80) >> 3);
buf[0] = msg[1].len; buf[0] = msg[1].len;
buf[1] = msg[0].addr << 1; buf[1] = msg[0].addr << 1;
...@@ -359,7 +358,7 @@ static int af9035_i2c_master_xfer(struct i2c_adapter *adap, ...@@ -359,7 +358,7 @@ static int af9035_i2c_master_xfer(struct i2c_adapter *adap,
memcpy(&buf[5], msg[0].buf, msg[0].len); memcpy(&buf[5], msg[0].buf, msg[0].len);
ret = af9035_ctrl_msg(d, &req); ret = af9035_ctrl_msg(d, &req);
} }
} else if (num == 1 && !(msg[0].flags & I2C_M_RD)) { } else if (AF9035_IS_I2C_XFER_WRITE(msg, num)) {
if (msg[0].len > 40) { if (msg[0].len > 40) {
/* TODO: correct limits > 40 */ /* TODO: correct limits > 40 */
ret = -EOPNOTSUPP; ret = -EOPNOTSUPP;
...@@ -377,18 +376,11 @@ static int af9035_i2c_master_xfer(struct i2c_adapter *adap, ...@@ -377,18 +376,11 @@ static int af9035_i2c_master_xfer(struct i2c_adapter *adap,
ret = af9035_wr_regs(d, reg, &msg[0].buf[3], ret = af9035_wr_regs(d, reg, &msg[0].buf[3],
msg[0].len - 3); msg[0].len - 3);
} else { } else {
/* I2C */ /* I2C write */
u8 buf[MAX_XFER_SIZE]; u8 buf[MAX_XFER_SIZE];
struct usb_req req = { CMD_I2C_WR, 0, 5 + msg[0].len, struct usb_req req = { CMD_I2C_WR, 0, 5 + msg[0].len,
buf, 0, NULL }; buf, 0, NULL };
if (5 + msg[0].len > sizeof(buf)) {
dev_warn(&d->udev->dev,
"%s: i2c xfer: len=%d is too big!\n",
KBUILD_MODNAME, msg[0].len);
ret = -EOPNOTSUPP;
goto unlock;
}
req.mbox |= ((msg[0].addr & 0x80) >> 3); req.mbox |= ((msg[0].addr & 0x80) >> 3);
buf[0] = msg[0].len; buf[0] = msg[0].len;
buf[1] = msg[0].addr << 1; buf[1] = msg[0].addr << 1;
...@@ -398,12 +390,12 @@ static int af9035_i2c_master_xfer(struct i2c_adapter *adap, ...@@ -398,12 +390,12 @@ static int af9035_i2c_master_xfer(struct i2c_adapter *adap,
memcpy(&buf[5], msg[0].buf, msg[0].len); memcpy(&buf[5], msg[0].buf, msg[0].len);
ret = af9035_ctrl_msg(d, &req); ret = af9035_ctrl_msg(d, &req);
} }
} else if (num == 1 && (msg[0].flags & I2C_M_RD)) { } else if (AF9035_IS_I2C_XFER_READ(msg, num)) {
if (msg[0].len > 40) { if (msg[0].len > 40) {
/* TODO: correct limits > 40 */ /* TODO: correct limits > 40 */
ret = -EOPNOTSUPP; ret = -EOPNOTSUPP;
} else { } else {
/* I2C */ /* I2C read */
u8 buf[5]; u8 buf[5];
struct usb_req req = { CMD_I2C_RD, 0, sizeof(buf), struct usb_req req = { CMD_I2C_RD, 0, sizeof(buf),
buf, msg[0].len, msg[0].buf }; buf, msg[0].len, msg[0].buf };
...@@ -418,14 +410,13 @@ static int af9035_i2c_master_xfer(struct i2c_adapter *adap, ...@@ -418,14 +410,13 @@ static int af9035_i2c_master_xfer(struct i2c_adapter *adap,
} else { } else {
/* /*
* We support only three kind of I2C transactions: * We support only three kind of I2C transactions:
* 1) 1 x read + 1 x write (repeated start) * 1) 1 x write + 1 x read (repeated start)
* 2) 1 x write * 2) 1 x write
* 3) 1 x read * 3) 1 x read
*/ */
ret = -EOPNOTSUPP; ret = -EOPNOTSUPP;
} }
unlock:
mutex_unlock(&d->i2c_mutex); mutex_unlock(&d->i2c_mutex);
if (ret < 0) if (ret < 0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment