diff options
author | Antti Palosaari <crope@iki.fi> | 2012-08-21 11:12:50 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2012-09-15 08:22:49 -0400 |
commit | af3a07ac70142f3c30c4fb23c7d3ec4c0e773cce (patch) | |
tree | a5ac9f72c80b69cc7ce5bf87f703e3f9f82b0423 /drivers/media/tuners/tda18218.c | |
parent | 70cf058aa900394abba126d5950712e5c107768f (diff) |
[media] tda18218: re-implement tda18218_wr_regs()
Old i2c message length splitting logic was faulty. Make it better.
Signed-off-by: Antti Palosaari <crope@iki.fi>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/tuners/tda18218.c')
-rw-r--r-- | drivers/media/tuners/tda18218.c | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/drivers/media/tuners/tda18218.c b/drivers/media/tuners/tda18218.c index 8a6f9ca788f0..c400440c5dea 100644 --- a/drivers/media/tuners/tda18218.c +++ b/drivers/media/tuners/tda18218.c | |||
@@ -28,8 +28,8 @@ MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off)."); | |||
28 | /* write multiple registers */ | 28 | /* write multiple registers */ |
29 | static int tda18218_wr_regs(struct tda18218_priv *priv, u8 reg, u8 *val, u8 len) | 29 | static int tda18218_wr_regs(struct tda18218_priv *priv, u8 reg, u8 *val, u8 len) |
30 | { | 30 | { |
31 | int ret = 0; | 31 | int ret = 0, len2, remaining; |
32 | u8 buf[1+len], quotient, remainder, i, msg_len, msg_len_max; | 32 | u8 buf[1 + len]; |
33 | struct i2c_msg msg[1] = { | 33 | struct i2c_msg msg[1] = { |
34 | { | 34 | { |
35 | .addr = priv->cfg->i2c_address, | 35 | .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 | } | 38 | } |
39 | }; | 39 | }; |
40 | 40 | ||
41 | msg_len_max = priv->cfg->i2c_wr_max - 1; | 41 | for (remaining = len; remaining > 0; |
42 | quotient = len / msg_len_max; | 42 | remaining -= (priv->cfg->i2c_wr_max - 1)) { |
43 | remainder = len % msg_len_max; | 43 | len2 = remaining; |
44 | msg_len = msg_len_max; | 44 | if (len2 > (priv->cfg->i2c_wr_max - 1)) |
45 | for (i = 0; (i <= quotient && remainder); i++) { | 45 | len2 = (priv->cfg->i2c_wr_max - 1); |
46 | if (i == quotient) /* set len of the last msg */ | 46 | |
47 | msg_len = remainder; | 47 | msg[0].len = 1 + len2; |
48 | 48 | buf[0] = reg + len - remaining; | |
49 | msg[0].len = msg_len + 1; | 49 | memcpy(&buf[1], &val[len - remaining], len2); |
50 | buf[0] = reg + i * msg_len_max; | ||
51 | memcpy(&buf[1], &val[i * msg_len_max], msg_len); | ||
52 | 50 | ||
53 | ret = i2c_transfer(priv->i2c, msg, 1); | 51 | ret = i2c_transfer(priv->i2c, msg, 1); |
54 | if (ret != 1) | 52 | if (ret != 1) |