[media] tda18271: allow restricting max out to 4 bytes
By default, tda18271 tries to optimize I2C bus by updating all registers at the same time. Unfortunately, some devices doesn't support it. The current logic has a problem when small_i2c is equal to 8, since there are some transfers using 11 + 1 bytes. Fix the problem by enforcing the max size at the right place, and allows reducing it to max = 3 + 1. Acked-by: Michael Krufky <mkrufky@kernellabs.com> Acked-by: Sri Deevi <Srinivasa.Deevi@conexant.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
This commit is contained in:
@@ -193,20 +193,46 @@ int tda18271_write_regs(struct dvb_frontend *fe, int idx, int len)
|
|||||||
unsigned char *regs = priv->tda18271_regs;
|
unsigned char *regs = priv->tda18271_regs;
|
||||||
unsigned char buf[TDA18271_NUM_REGS + 1];
|
unsigned char buf[TDA18271_NUM_REGS + 1];
|
||||||
struct i2c_msg msg = { .addr = priv->i2c_props.addr, .flags = 0,
|
struct i2c_msg msg = { .addr = priv->i2c_props.addr, .flags = 0,
|
||||||
.buf = buf, .len = len + 1 };
|
.buf = buf };
|
||||||
int i, ret;
|
int i, ret = 1, max;
|
||||||
|
|
||||||
BUG_ON((len == 0) || (idx + len > sizeof(buf)));
|
BUG_ON((len == 0) || (idx + len > sizeof(buf)));
|
||||||
|
|
||||||
buf[0] = idx;
|
|
||||||
for (i = 1; i <= len; i++)
|
switch (priv->small_i2c) {
|
||||||
buf[i] = regs[idx - 1 + i];
|
case TDA18271_03_BYTE_CHUNK_INIT:
|
||||||
|
max = 3;
|
||||||
|
break;
|
||||||
|
case TDA18271_08_BYTE_CHUNK_INIT:
|
||||||
|
max = 8;
|
||||||
|
break;
|
||||||
|
case TDA18271_16_BYTE_CHUNK_INIT:
|
||||||
|
max = 16;
|
||||||
|
break;
|
||||||
|
case TDA18271_39_BYTE_CHUNK_INIT:
|
||||||
|
default:
|
||||||
|
max = 39;
|
||||||
|
}
|
||||||
|
|
||||||
tda18271_i2c_gate_ctrl(fe, 1);
|
tda18271_i2c_gate_ctrl(fe, 1);
|
||||||
|
while (len) {
|
||||||
|
if (max > len)
|
||||||
|
max = len;
|
||||||
|
|
||||||
/* write registers */
|
buf[0] = idx;
|
||||||
ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
|
for (i = 1; i <= max; i++)
|
||||||
|
buf[i] = regs[idx - 1 + i];
|
||||||
|
|
||||||
|
msg.len = max + 1;
|
||||||
|
|
||||||
|
/* write registers */
|
||||||
|
ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
|
||||||
|
if (ret != 1)
|
||||||
|
break;
|
||||||
|
|
||||||
|
idx += max;
|
||||||
|
len -= max;
|
||||||
|
}
|
||||||
tda18271_i2c_gate_ctrl(fe, 0);
|
tda18271_i2c_gate_ctrl(fe, 0);
|
||||||
|
|
||||||
if (ret != 1)
|
if (ret != 1)
|
||||||
@@ -326,24 +352,7 @@ int tda18271_init_regs(struct dvb_frontend *fe)
|
|||||||
regs[R_EB22] = 0x48;
|
regs[R_EB22] = 0x48;
|
||||||
regs[R_EB23] = 0xb0;
|
regs[R_EB23] = 0xb0;
|
||||||
|
|
||||||
switch (priv->small_i2c) {
|
tda18271_write_regs(fe, 0x00, TDA18271_NUM_REGS);
|
||||||
case TDA18271_08_BYTE_CHUNK_INIT:
|
|
||||||
tda18271_write_regs(fe, 0x00, 0x08);
|
|
||||||
tda18271_write_regs(fe, 0x08, 0x08);
|
|
||||||
tda18271_write_regs(fe, 0x10, 0x08);
|
|
||||||
tda18271_write_regs(fe, 0x18, 0x08);
|
|
||||||
tda18271_write_regs(fe, 0x20, 0x07);
|
|
||||||
break;
|
|
||||||
case TDA18271_16_BYTE_CHUNK_INIT:
|
|
||||||
tda18271_write_regs(fe, 0x00, 0x10);
|
|
||||||
tda18271_write_regs(fe, 0x10, 0x10);
|
|
||||||
tda18271_write_regs(fe, 0x20, 0x07);
|
|
||||||
break;
|
|
||||||
case TDA18271_39_BYTE_CHUNK_INIT:
|
|
||||||
default:
|
|
||||||
tda18271_write_regs(fe, 0x00, TDA18271_NUM_REGS);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* setup agc1 gain */
|
/* setup agc1 gain */
|
||||||
regs[R_EB17] = 0x00;
|
regs[R_EB17] = 0x00;
|
||||||
|
@@ -80,8 +80,9 @@ enum tda18271_output_options {
|
|||||||
|
|
||||||
enum tda18271_small_i2c {
|
enum tda18271_small_i2c {
|
||||||
TDA18271_39_BYTE_CHUNK_INIT = 0,
|
TDA18271_39_BYTE_CHUNK_INIT = 0,
|
||||||
TDA18271_16_BYTE_CHUNK_INIT = 1,
|
TDA18271_16_BYTE_CHUNK_INIT = 16,
|
||||||
TDA18271_08_BYTE_CHUNK_INIT = 2,
|
TDA18271_08_BYTE_CHUNK_INIT = 8,
|
||||||
|
TDA18271_03_BYTE_CHUNK_INIT = 3,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct tda18271_config {
|
struct tda18271_config {
|
||||||
|
@@ -427,7 +427,7 @@ static void set_type(struct i2c_client *c, unsigned int type,
|
|||||||
{
|
{
|
||||||
struct tda18271_config cfg = {
|
struct tda18271_config cfg = {
|
||||||
.config = t->config,
|
.config = t->config,
|
||||||
.small_i2c = TDA18271_08_BYTE_CHUNK_INIT,
|
.small_i2c = TDA18271_03_BYTE_CHUNK_INIT,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!dvb_attach(tda18271_attach, &t->fe, t->i2c->addr,
|
if (!dvb_attach(tda18271_attach, &t->fe, t->i2c->addr,
|
||||||
|
Reference in New Issue
Block a user