diff options
Diffstat (limited to 'v4l/mt352.c')
-rw-r--r-- | v4l/mt352.c | 72 |
1 files changed, 33 insertions, 39 deletions
diff --git a/v4l/mt352.c b/v4l/mt352.c index baa3f67a7..6eeb659eb 100644 --- a/v4l/mt352.c +++ b/v4l/mt352.c @@ -46,7 +46,7 @@ struct mt352_state { /* configuration settings */ const struct mt352_config* config; - int status,s0,s1,s3; + int s0,s1,s3; struct dvb_frontend frontend; }; @@ -57,32 +57,33 @@ do { \ if (debug) printk(KERN_DEBUG "mt352: " args); \ } while (0) -int mt352_write(struct dvb_frontend* fe, u8* ibuf, int ilen) +static int mt352_single_write(struct dvb_frontend *fe, u8 reg, u8 val) { struct mt352_state* state = (struct mt352_state*) fe->demodulator_priv; + u8 buf[2] = { reg, val }; struct i2c_msg msg = { .addr = state->config->demod_address, .flags = 0, - .buf = ibuf, .len = ilen }; - if (debug) { - int i; - printk("%s:",__FUNCTION__); - for (i = 0; i < ilen; i++) - printk(" %02x",ibuf[i]); - printk("\n"); - } - + .buf = buf, .len = 2 }; int err = i2c_transfer(state->i2c, &msg, 1); if (err != 1) { - printk(KERN_WARNING - "mt352_write() failed (err = %d)!\n", err); + printk("mt352_write() to reg %x failed (err = %d)!\n", reg, err); return err; } + return 0; +} + +int mt352_write(struct dvb_frontend* fe, u8* ibuf, int ilen) +{ + int err,i; + for (i=0; i < ilen-1; i++) + if ((err = mt352_single_write(fe,ibuf[0]+i,ibuf[i+1]))) + return err; return 0; } static int mt352_read_register(struct mt352_state* state, u8 reg) { - int ret,i; + int ret; u8 b0 [] = { reg }; u8 b1 [] = { 0 }; struct i2c_msg msg [] = { { .addr = state->config->demod_address, @@ -92,24 +93,22 @@ static int mt352_read_register(struct mt352_state* state, u8 reg) .flags = I2C_M_RD, .buf = b1, .len = 1 } }; - for (i = 0; i < 5; i++) { - ret = i2c_transfer(state->i2c, msg, 2); - if (2 == ret) - break; - msleep(10); - dprintk("%s: readreg error #%d, retrying\n", - __FUNCTION__, i+1); - } + ret = i2c_transfer(state->i2c, msg, 2); if (ret != 2) { - printk(KERN_WARNING - "%s: readreg error (ret == %i)\n", __FUNCTION__, ret); - return -1; + printk("%s: readreg error (reg=%d, ret==%i)\n", + __FUNCTION__, reg, ret); + return ret; } return b1[0]; } +int mt352_read(struct dvb_frontend *fe, u8 reg) +{ + return mt352_read_register(fe->demodulator_priv,reg); +} + static int mt352_sleep(struct dvb_frontend* fe) { static u8 mt352_softdown[] = { CLOCK_CTL, 0x20, 0x08 }; @@ -435,6 +434,7 @@ static int mt352_get_parameters(struct dvb_frontend* fe, static int mt352_read_status(struct dvb_frontend* fe, fe_status_t* status) { struct mt352_state* state = (struct mt352_state*) fe->demodulator_priv; +#if 1 int val; if (0 != mt352_read_register(state, INTERRUPT_0)) { @@ -448,6 +448,13 @@ static int mt352_read_status(struct dvb_frontend* fe, fe_status_t* status) if (-1 != val) state->s3 = val; } +#else + state->s0 = mt352_read_register(state, STATUS_0); + state->s1 = mt352_read_register(state, STATUS_1); + state->s3 = mt352_read_register(state, STATUS_3); + if (-1 == state->s0 || -1 == state->s1 || -1 == state->s3) + return -EIO; +#endif *status = 0; if (state->s0 & (1 << 4)) @@ -465,20 +472,6 @@ static int mt352_read_status(struct dvb_frontend* fe, fe_status_t* status) (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC)) *status &= ~FE_HAS_LOCK; - if (debug && state->status != *status) { - /* log status bit changes */ - printk("%s:%s%s%s%s%s | r0=0x%02x r1=0x%02x r3=0x%02x\n", - __FUNCTION__, - *status & FE_HAS_CARRIER ? " CARRIER" : "", - *status & FE_HAS_VITERBI ? " VITERBI" : "", - *status & FE_HAS_LOCK ? " LOCK" : "", - *status & FE_HAS_SYNC ? " SYNC" : "", - *status & FE_HAS_SIGNAL ? " SIGNAL" : "", - state->s0, state->s1, state->s3); - - } - state->status = *status; - return 0; } @@ -631,6 +624,7 @@ MODULE_LICENSE("GPL"); EXPORT_SYMBOL(mt352_attach); EXPORT_SYMBOL(mt352_write); +EXPORT_SYMBOL(mt352_read); /* * Local variables: * c-basic-offset: 8 |