mirror of
https://github.com/torvalds/linux.git
synced 2024-11-24 05:02:12 +00:00
media: mb86a20s: make the bit rate estimation function more generic
While 99% of the implementation of the bitrate estimation routine for ISDB-T is generic, the current approach mangles it with some mb86a20s-specific thing. Split the calculus from the specific stuff, in order to make easier to use the same approach on other drivers requiring a similar formula. Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> Signed-off-by: Sean Young <sean@mess.org>
This commit is contained in:
parent
ca8f245f28
commit
75564e3a50
@ -517,7 +517,7 @@ static void mb86a20s_reset_frontend_cache(struct dvb_frontend *fe)
|
||||
* Estimates the bit rate using the per-segment bit rate given by
|
||||
* ABNT/NBR 15601 spec (table 4).
|
||||
*/
|
||||
static u32 isdbt_rate[3][5][4] = {
|
||||
static const u32 isdbt_rate[3][5][4] = {
|
||||
{ /* DQPSK/QPSK */
|
||||
{ 280850, 312060, 330420, 340430 }, /* 1/2 */
|
||||
{ 374470, 416080, 440560, 453910 }, /* 2/3 */
|
||||
@ -539,13 +539,9 @@ static u32 isdbt_rate[3][5][4] = {
|
||||
}
|
||||
};
|
||||
|
||||
static void mb86a20s_layer_bitrate(struct dvb_frontend *fe, u32 layer,
|
||||
u32 modulation, u32 forward_error_correction,
|
||||
u32 guard_interval,
|
||||
u32 segment)
|
||||
static u32 isdbt_layer_min_bitrate(struct dtv_frontend_properties *c,
|
||||
u32 layer)
|
||||
{
|
||||
struct mb86a20s_state *state = fe->demodulator_priv;
|
||||
u32 rate;
|
||||
int mod, fec, guard;
|
||||
|
||||
/*
|
||||
@ -553,7 +549,7 @@ static void mb86a20s_layer_bitrate(struct dvb_frontend *fe, u32 layer,
|
||||
* to consider the lowest bit rate, to avoid taking too long time
|
||||
* to get BER.
|
||||
*/
|
||||
switch (modulation) {
|
||||
switch (c->layer[layer].modulation) {
|
||||
case DQPSK:
|
||||
case QPSK:
|
||||
default:
|
||||
@ -567,7 +563,7 @@ static void mb86a20s_layer_bitrate(struct dvb_frontend *fe, u32 layer,
|
||||
break;
|
||||
}
|
||||
|
||||
switch (forward_error_correction) {
|
||||
switch (c->layer[layer].fec) {
|
||||
default:
|
||||
case FEC_1_2:
|
||||
case FEC_AUTO:
|
||||
@ -587,7 +583,7 @@ static void mb86a20s_layer_bitrate(struct dvb_frontend *fe, u32 layer,
|
||||
break;
|
||||
}
|
||||
|
||||
switch (guard_interval) {
|
||||
switch (c->guard_interval) {
|
||||
default:
|
||||
case GUARD_INTERVAL_1_4:
|
||||
guard = 0;
|
||||
@ -603,29 +599,14 @@ static void mb86a20s_layer_bitrate(struct dvb_frontend *fe, u32 layer,
|
||||
break;
|
||||
}
|
||||
|
||||
/* Samples BER at BER_SAMPLING_RATE seconds */
|
||||
rate = isdbt_rate[mod][fec][guard] * segment * BER_SAMPLING_RATE;
|
||||
|
||||
/* Avoids sampling too quickly or to overflow the register */
|
||||
if (rate < 256)
|
||||
rate = 256;
|
||||
else if (rate > (1 << 24) - 1)
|
||||
rate = (1 << 24) - 1;
|
||||
|
||||
dev_dbg(&state->i2c->dev,
|
||||
"%s: layer %c bitrate: %d kbps; counter = %d (0x%06x)\n",
|
||||
__func__, 'A' + layer,
|
||||
segment * isdbt_rate[mod][fec][guard]/1000,
|
||||
rate, rate);
|
||||
|
||||
state->estimated_rate[layer] = rate;
|
||||
return isdbt_rate[mod][fec][guard] * c->layer[layer].segment_count;
|
||||
}
|
||||
|
||||
static int mb86a20s_get_frontend(struct dvb_frontend *fe)
|
||||
{
|
||||
struct mb86a20s_state *state = fe->demodulator_priv;
|
||||
struct dtv_frontend_properties *c = &fe->dtv_property_cache;
|
||||
int layer, rc;
|
||||
int layer, rc, rate, counter;
|
||||
|
||||
dev_dbg(&state->i2c->dev, "%s called.\n", __func__);
|
||||
|
||||
@ -676,10 +657,21 @@ static int mb86a20s_get_frontend(struct dvb_frontend *fe)
|
||||
dev_dbg(&state->i2c->dev, "%s: interleaving %d.\n",
|
||||
__func__, rc);
|
||||
c->layer[layer].interleaving = rc;
|
||||
mb86a20s_layer_bitrate(fe, layer, c->layer[layer].modulation,
|
||||
c->layer[layer].fec,
|
||||
c->guard_interval,
|
||||
c->layer[layer].segment_count);
|
||||
|
||||
rate = isdbt_layer_min_bitrate(c, layer);
|
||||
counter = rate * BER_SAMPLING_RATE;
|
||||
|
||||
/* Avoids sampling too quickly or to overflow the register */
|
||||
if (counter < 256)
|
||||
counter = 256;
|
||||
else if (counter > (1 << 24) - 1)
|
||||
counter = (1 << 24) - 1;
|
||||
|
||||
dev_dbg(&state->i2c->dev,
|
||||
"%s: layer %c bitrate: %d kbps; counter = %d (0x%06x)\n",
|
||||
__func__, 'A' + layer, rate / 1000, counter, counter);
|
||||
|
||||
state->estimated_rate[layer] = counter;
|
||||
}
|
||||
|
||||
rc = mb86a20s_writereg(state, 0x6d, 0x84);
|
||||
|
Loading…
Reference in New Issue
Block a user