aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/dvb
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2010-09-10 09:33:42 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2010-10-20 23:06:10 -0400
commit27f84acf0be090a4948596696e534b65f0bff980 (patch)
tree1b3e2785bc83f84cb3326ad4622ba91763c93626 /drivers/media/dvb
parentd6c1ef6faa45b6a07a439719084756c3d136fa90 (diff)
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>
Diffstat (limited to 'drivers/media/dvb')
-rw-r--r--drivers/media/dvb/frontends/cx22702.c31
1 files changed, 16 insertions, 15 deletions
diff --git a/drivers/media/dvb/frontends/cx22702.c b/drivers/media/dvb/frontends/cx22702.c
index c3681d19b43e..a5dcf876f81a 100644
--- a/drivers/media/dvb/frontends/cx22702.c
+++ b/drivers/media/dvb/frontends/cx22702.c
@@ -128,19 +128,20 @@ static int cx22702_set_inversion(struct cx22702_state *state, int inversion)
128{ 128{
129 u8 val; 129 u8 val;
130 130
131 val = cx22702_readreg(state, 0x0C);
131 switch (inversion) { 132 switch (inversion) {
132 case INVERSION_AUTO: 133 case INVERSION_AUTO:
133 return -EOPNOTSUPP; 134 return -EOPNOTSUPP;
134 case INVERSION_ON: 135 case INVERSION_ON:
135 val = cx22702_readreg(state, 0x0C); 136 val |= 0x01;
136 return cx22702_writereg(state, 0x0C, val | 0x01); 137 break;
137 case INVERSION_OFF: 138 case INVERSION_OFF:
138 val = cx22702_readreg(state, 0x0C); 139 val &= 0xfe;
139 return cx22702_writereg(state, 0x0C, val & 0xfe); 140 break;
140 default: 141 default:
141 return -EINVAL; 142 return -EINVAL;
142 } 143 }
143 144 return cx22702_writereg(state, 0x0C, val);
144} 145}
145 146
146/* Retrieve the demod settings */ 147/* Retrieve the demod settings */
@@ -247,13 +248,15 @@ static int cx22702_get_tps(struct cx22702_state *state,
247static int cx22702_i2c_gate_ctrl(struct dvb_frontend *fe, int enable) 248static int cx22702_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
248{ 249{
249 struct cx22702_state *state = fe->demodulator_priv; 250 struct cx22702_state *state = fe->demodulator_priv;
251 u8 val;
252
250 dprintk("%s(%d)\n", __func__, enable); 253 dprintk("%s(%d)\n", __func__, enable);
254 val = cx22702_readreg(state, 0x0D);
251 if (enable) 255 if (enable)
252 return cx22702_writereg(state, 0x0D, 256 val &= 0xfe;
253 cx22702_readreg(state, 0x0D) & 0xfe);
254 else 257 else
255 return cx22702_writereg(state, 0x0D, 258 val |= 0x01;
256 cx22702_readreg(state, 0x0D) | 1); 259 return cx22702_writereg(state, 0x0D, val);
257} 260}
258 261
259/* Talk to the demod, set the FEC, GUARD, QAM settings etc */ 262/* Talk to the demod, set the FEC, GUARD, QAM settings etc */
@@ -273,23 +276,21 @@ static int cx22702_set_tps(struct dvb_frontend *fe,
273 cx22702_set_inversion(state, p->inversion); 276 cx22702_set_inversion(state, p->inversion);
274 277
275 /* set bandwidth */ 278 /* set bandwidth */
279 val = cx22702_readreg(state, 0x0C) & 0xcf;
276 switch (p->u.ofdm.bandwidth) { 280 switch (p->u.ofdm.bandwidth) {
277 case BANDWIDTH_6_MHZ: 281 case BANDWIDTH_6_MHZ:
278 cx22702_writereg(state, 0x0C, 282 val |= 0x20;
279 (cx22702_readreg(state, 0x0C) & 0xcf) | 0x20);
280 break; 283 break;
281 case BANDWIDTH_7_MHZ: 284 case BANDWIDTH_7_MHZ:
282 cx22702_writereg(state, 0x0C, 285 val |= 0x10;
283 (cx22702_readreg(state, 0x0C) & 0xcf) | 0x10);
284 break; 286 break;
285 case BANDWIDTH_8_MHZ: 287 case BANDWIDTH_8_MHZ:
286 cx22702_writereg(state, 0x0C,
287 cx22702_readreg(state, 0x0C) & 0xcf);
288 break; 288 break;
289 default: 289 default:
290 dprintk("%s: invalid bandwidth\n", __func__); 290 dprintk("%s: invalid bandwidth\n", __func__);
291 return -EINVAL; 291 return -EINVAL;
292 } 292 }
293 cx22702_writereg(state, 0x0C, val);
293 294
294 p->u.ofdm.code_rate_LP = FEC_AUTO; /* temp hack as manual not working */ 295 p->u.ofdm.code_rate_LP = FEC_AUTO; /* temp hack as manual not working */
295 296