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

[media] tda18218: re-implement tda18218_wr_regs()

Old i2c message length splitting logic was faulty. Make it better.
Signed-off-by: default avatarAntti Palosaari <crope@iki.fi>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 70cf058a
...@@ -28,8 +28,8 @@ MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off)."); ...@@ -28,8 +28,8 @@ MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off).");
/* write multiple registers */ /* write multiple registers */
static int tda18218_wr_regs(struct tda18218_priv *priv, u8 reg, u8 *val, u8 len) static int tda18218_wr_regs(struct tda18218_priv *priv, u8 reg, u8 *val, u8 len)
{ {
int ret = 0; int ret = 0, len2, remaining;
u8 buf[1+len], quotient, remainder, i, msg_len, msg_len_max; u8 buf[1 + len];
struct i2c_msg msg[1] = { struct i2c_msg msg[1] = {
{ {
.addr = priv->cfg->i2c_address, .addr = priv->cfg->i2c_address,
...@@ -38,17 +38,15 @@ static int tda18218_wr_regs(struct tda18218_priv *priv, u8 reg, u8 *val, u8 len) ...@@ -38,17 +38,15 @@ static int tda18218_wr_regs(struct tda18218_priv *priv, u8 reg, u8 *val, u8 len)
} }
}; };
msg_len_max = priv->cfg->i2c_wr_max - 1; for (remaining = len; remaining > 0;
quotient = len / msg_len_max; remaining -= (priv->cfg->i2c_wr_max - 1)) {
remainder = len % msg_len_max; len2 = remaining;
msg_len = msg_len_max; if (len2 > (priv->cfg->i2c_wr_max - 1))
for (i = 0; (i <= quotient && remainder); i++) { len2 = (priv->cfg->i2c_wr_max - 1);
if (i == quotient) /* set len of the last msg */
msg_len = remainder; msg[0].len = 1 + len2;
buf[0] = reg + len - remaining;
msg[0].len = msg_len + 1; memcpy(&buf[1], &val[len - remaining], len2);
buf[0] = reg + i * msg_len_max;
memcpy(&buf[1], &val[i * msg_len_max], msg_len);
ret = i2c_transfer(priv->i2c, msg, 1); ret = i2c_transfer(priv->i2c, msg, 1);
if (ret != 1) if (ret != 1)
......
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