Commit 89faeefc authored by Michael Krufky's avatar Michael Krufky Committed by Mauro Carvalho Chehab

V4L/DVB (4868): Dvb-pll: return frequency set by dvb_pll_configure()

This patch removes some duplicated code by returning the frequency set by
dvb_pll_configure(), instead of recalculating it again in dvb_pll_set_params()
and dvb_pll_calc_regs().
If the return value of dvb_pll_configure is less than zero, it is an error
code.  Otherwise, the return value is the frequency actually set by the
function.
Signed-off-by: default avatarMichael Krufky <mkrufky@linuxtv.org>
Acked-by: default avatarAndrew de Quincey <adq_dvb@lidskialf.net>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@infradead.org>
parent 47ae9ae8
...@@ -472,7 +472,8 @@ int dvb_pll_configure(struct dvb_pll_desc *desc, u8 *buf, ...@@ -472,7 +472,8 @@ int dvb_pll_configure(struct dvb_pll_desc *desc, u8 *buf,
printk("pll: %s: div=%d | buf=0x%02x,0x%02x,0x%02x,0x%02x\n", printk("pll: %s: div=%d | buf=0x%02x,0x%02x,0x%02x,0x%02x\n",
desc->name, div, buf[0], buf[1], buf[2], buf[3]); desc->name, div, buf[0], buf[1], buf[2], buf[3]);
return 0; // calculate the frequency we set it to
return (div * desc->entries[i].stepsize) - desc->entries[i].offset;
} }
EXPORT_SYMBOL(dvb_pll_configure); EXPORT_SYMBOL(dvb_pll_configure);
...@@ -526,9 +527,7 @@ static int dvb_pll_set_params(struct dvb_frontend *fe, ...@@ -526,9 +527,7 @@ static int dvb_pll_set_params(struct dvb_frontend *fe,
{ .addr = priv->pll_i2c_address, .flags = 0, { .addr = priv->pll_i2c_address, .flags = 0,
.buf = buf, .len = sizeof(buf) }; .buf = buf, .len = sizeof(buf) };
int result; int result;
u32 div; u32 bandwidth = 0, frequency = 0;
int i;
u32 bandwidth = 0;
if (priv->i2c == NULL) if (priv->i2c == NULL)
return -EINVAL; return -EINVAL;
...@@ -538,9 +537,11 @@ static int dvb_pll_set_params(struct dvb_frontend *fe, ...@@ -538,9 +537,11 @@ static int dvb_pll_set_params(struct dvb_frontend *fe,
bandwidth = params->u.ofdm.bandwidth; bandwidth = params->u.ofdm.bandwidth;
} }
if ((result = dvb_pll_configure(priv->pll_desc, buf, params->frequency, if ((result = dvb_pll_configure(priv->pll_desc, buf,
bandwidth)) != 0) params->frequency, bandwidth)) < 0)
return result; return result;
else
frequency = result;
if (fe->ops.i2c_gate_ctrl) if (fe->ops.i2c_gate_ctrl)
fe->ops.i2c_gate_ctrl(fe, 1); fe->ops.i2c_gate_ctrl(fe, 1);
...@@ -548,16 +549,7 @@ static int dvb_pll_set_params(struct dvb_frontend *fe, ...@@ -548,16 +549,7 @@ static int dvb_pll_set_params(struct dvb_frontend *fe,
return result; return result;
} }
// calculate the frequency we set it to priv->frequency = frequency;
for (i = 0; i < priv->pll_desc->count; i++) {
if (params->frequency > priv->pll_desc->entries[i].limit)
continue;
break;
}
div = (params->frequency + priv->pll_desc->entries[i].offset) /
priv->pll_desc->entries[i].stepsize;
priv->frequency = (div * priv->pll_desc->entries[i].stepsize) -
priv->pll_desc->entries[i].offset;
priv->bandwidth = bandwidth; priv->bandwidth = bandwidth;
return 0; return 0;
...@@ -569,9 +561,7 @@ static int dvb_pll_calc_regs(struct dvb_frontend *fe, ...@@ -569,9 +561,7 @@ static int dvb_pll_calc_regs(struct dvb_frontend *fe,
{ {
struct dvb_pll_priv *priv = fe->tuner_priv; struct dvb_pll_priv *priv = fe->tuner_priv;
int result; int result;
u32 div; u32 bandwidth = 0, frequency = 0;
int i;
u32 bandwidth = 0;
if (buf_len < 5) if (buf_len < 5)
return -EINVAL; return -EINVAL;
...@@ -582,20 +572,14 @@ static int dvb_pll_calc_regs(struct dvb_frontend *fe, ...@@ -582,20 +572,14 @@ static int dvb_pll_calc_regs(struct dvb_frontend *fe,
} }
if ((result = dvb_pll_configure(priv->pll_desc, buf+1, if ((result = dvb_pll_configure(priv->pll_desc, buf+1,
params->frequency, bandwidth)) != 0) params->frequency, bandwidth)) < 0)
return result; return result;
else
frequency = result;
buf[0] = priv->pll_i2c_address; buf[0] = priv->pll_i2c_address;
// calculate the frequency we set it to priv->frequency = frequency;
for (i = 0; i < priv->pll_desc->count; i++) {
if (params->frequency > priv->pll_desc->entries[i].limit)
continue;
break;
}
div = (params->frequency + priv->pll_desc->entries[i].offset) /
priv->pll_desc->entries[i].stepsize;
priv->frequency = (div * priv->pll_desc->entries[i].stepsize) -
priv->pll_desc->entries[i].offset;
priv->bandwidth = bandwidth; priv->bandwidth = bandwidth;
return 5; return 5;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment