V4L/DVB: cx22702: Avoid duplicating code in branches
Calling the same functions in if/else or switch/case branches is inefficient. Refactor the code for a smaller binary and increased readability. Signed-off-by: Jean Delvare <khali@linux-fr.org> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
This commit is contained in:
committed by
Mauro Carvalho Chehab
parent
d6c1ef6faa
commit
27f84acf0b
@@ -128,19 +128,20 @@ static int cx22702_set_inversion(struct cx22702_state *state, int inversion)
|
|||||||
{
|
{
|
||||||
u8 val;
|
u8 val;
|
||||||
|
|
||||||
|
val = cx22702_readreg(state, 0x0C);
|
||||||
switch (inversion) {
|
switch (inversion) {
|
||||||
case INVERSION_AUTO:
|
case INVERSION_AUTO:
|
||||||
return -EOPNOTSUPP;
|
return -EOPNOTSUPP;
|
||||||
case INVERSION_ON:
|
case INVERSION_ON:
|
||||||
val = cx22702_readreg(state, 0x0C);
|
val |= 0x01;
|
||||||
return cx22702_writereg(state, 0x0C, val | 0x01);
|
break;
|
||||||
case INVERSION_OFF:
|
case INVERSION_OFF:
|
||||||
val = cx22702_readreg(state, 0x0C);
|
val &= 0xfe;
|
||||||
return cx22702_writereg(state, 0x0C, val & 0xfe);
|
break;
|
||||||
default:
|
default:
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
return cx22702_writereg(state, 0x0C, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Retrieve the demod settings */
|
/* Retrieve the demod settings */
|
||||||
@@ -247,13 +248,15 @@ static int cx22702_get_tps(struct cx22702_state *state,
|
|||||||
static int cx22702_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
|
static int cx22702_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
|
||||||
{
|
{
|
||||||
struct cx22702_state *state = fe->demodulator_priv;
|
struct cx22702_state *state = fe->demodulator_priv;
|
||||||
|
u8 val;
|
||||||
|
|
||||||
dprintk("%s(%d)\n", __func__, enable);
|
dprintk("%s(%d)\n", __func__, enable);
|
||||||
|
val = cx22702_readreg(state, 0x0D);
|
||||||
if (enable)
|
if (enable)
|
||||||
return cx22702_writereg(state, 0x0D,
|
val &= 0xfe;
|
||||||
cx22702_readreg(state, 0x0D) & 0xfe);
|
|
||||||
else
|
else
|
||||||
return cx22702_writereg(state, 0x0D,
|
val |= 0x01;
|
||||||
cx22702_readreg(state, 0x0D) | 1);
|
return cx22702_writereg(state, 0x0D, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Talk to the demod, set the FEC, GUARD, QAM settings etc */
|
/* Talk to the demod, set the FEC, GUARD, QAM settings etc */
|
||||||
@@ -273,23 +276,21 @@ static int cx22702_set_tps(struct dvb_frontend *fe,
|
|||||||
cx22702_set_inversion(state, p->inversion);
|
cx22702_set_inversion(state, p->inversion);
|
||||||
|
|
||||||
/* set bandwidth */
|
/* set bandwidth */
|
||||||
|
val = cx22702_readreg(state, 0x0C) & 0xcf;
|
||||||
switch (p->u.ofdm.bandwidth) {
|
switch (p->u.ofdm.bandwidth) {
|
||||||
case BANDWIDTH_6_MHZ:
|
case BANDWIDTH_6_MHZ:
|
||||||
cx22702_writereg(state, 0x0C,
|
val |= 0x20;
|
||||||
(cx22702_readreg(state, 0x0C) & 0xcf) | 0x20);
|
|
||||||
break;
|
break;
|
||||||
case BANDWIDTH_7_MHZ:
|
case BANDWIDTH_7_MHZ:
|
||||||
cx22702_writereg(state, 0x0C,
|
val |= 0x10;
|
||||||
(cx22702_readreg(state, 0x0C) & 0xcf) | 0x10);
|
|
||||||
break;
|
break;
|
||||||
case BANDWIDTH_8_MHZ:
|
case BANDWIDTH_8_MHZ:
|
||||||
cx22702_writereg(state, 0x0C,
|
|
||||||
cx22702_readreg(state, 0x0C) & 0xcf);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
dprintk("%s: invalid bandwidth\n", __func__);
|
dprintk("%s: invalid bandwidth\n", __func__);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
cx22702_writereg(state, 0x0C, val);
|
||||||
|
|
||||||
p->u.ofdm.code_rate_LP = FEC_AUTO; /* temp hack as manual not working */
|
p->u.ofdm.code_rate_LP = FEC_AUTO; /* temp hack as manual not working */
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user