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:
Mauro Carvalho Chehab 2019-10-04 08:42:47 -03:00
parent ca8f245f28
commit 75564e3a50

View File

@ -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 * Estimates the bit rate using the per-segment bit rate given by
* ABNT/NBR 15601 spec (table 4). * ABNT/NBR 15601 spec (table 4).
*/ */
static u32 isdbt_rate[3][5][4] = { static const u32 isdbt_rate[3][5][4] = {
{ /* DQPSK/QPSK */ { /* DQPSK/QPSK */
{ 280850, 312060, 330420, 340430 }, /* 1/2 */ { 280850, 312060, 330420, 340430 }, /* 1/2 */
{ 374470, 416080, 440560, 453910 }, /* 2/3 */ { 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, static u32 isdbt_layer_min_bitrate(struct dtv_frontend_properties *c,
u32 modulation, u32 forward_error_correction, u32 layer)
u32 guard_interval,
u32 segment)
{ {
struct mb86a20s_state *state = fe->demodulator_priv;
u32 rate;
int mod, fec, guard; 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 consider the lowest bit rate, to avoid taking too long time
* to get BER. * to get BER.
*/ */
switch (modulation) { switch (c->layer[layer].modulation) {
case DQPSK: case DQPSK:
case QPSK: case QPSK:
default: default:
@ -567,7 +563,7 @@ static void mb86a20s_layer_bitrate(struct dvb_frontend *fe, u32 layer,
break; break;
} }
switch (forward_error_correction) { switch (c->layer[layer].fec) {
default: default:
case FEC_1_2: case FEC_1_2:
case FEC_AUTO: case FEC_AUTO:
@ -587,7 +583,7 @@ static void mb86a20s_layer_bitrate(struct dvb_frontend *fe, u32 layer,
break; break;
} }
switch (guard_interval) { switch (c->guard_interval) {
default: default:
case GUARD_INTERVAL_1_4: case GUARD_INTERVAL_1_4:
guard = 0; guard = 0;
@ -603,29 +599,14 @@ static void mb86a20s_layer_bitrate(struct dvb_frontend *fe, u32 layer,
break; break;
} }
/* Samples BER at BER_SAMPLING_RATE seconds */ return isdbt_rate[mod][fec][guard] * c->layer[layer].segment_count;
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;
} }
static int mb86a20s_get_frontend(struct dvb_frontend *fe) static int mb86a20s_get_frontend(struct dvb_frontend *fe)
{ {
struct mb86a20s_state *state = fe->demodulator_priv; struct mb86a20s_state *state = fe->demodulator_priv;
struct dtv_frontend_properties *c = &fe->dtv_property_cache; 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__); 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", dev_dbg(&state->i2c->dev, "%s: interleaving %d.\n",
__func__, rc); __func__, rc);
c->layer[layer].interleaving = rc; c->layer[layer].interleaving = rc;
mb86a20s_layer_bitrate(fe, layer, c->layer[layer].modulation,
c->layer[layer].fec, rate = isdbt_layer_min_bitrate(c, layer);
c->guard_interval, counter = rate * BER_SAMPLING_RATE;
c->layer[layer].segment_count);
/* 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); rc = mb86a20s_writereg(state, 0x6d, 0x84);