Re: [PATCH 2/2] mn88473: refactor and fix statistics

2016-11-26 Thread Martin Blumenstingl
On Sun, Nov 13, 2016 at 10:29 AM, Antti Palosaari  wrote:
> Remove DVB-T2 BER as it does not work at all and I didn't find
> how to fix.
>
> Fix DVB-T and DVB-C BER. It seems to return new some realistic
> looking values.
>
> Use (1 << 64) base for CNR calculations to keep it in line with
> dvb logarithm functions.
>
> Move all statistic logic to mn88473_read_status() function.
>
> Use regmap_bulk_read() for reading multiple registers as a one go.
>
> And many more and less minor changes.
>
> Cc: Martin Blumenstingl 
> Signed-off-by: Antti Palosaari 
Tested-by: Martin Blumenstingl 

Tested successfully on DVB-C (only, since DVB-T2 is unavailable and
DVB-T reception is *very* bad here).
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/2] mn88473: refactor and fix statistics

2016-11-13 Thread Antti Palosaari
Remove DVB-T2 BER as it does not work at all and I didn't find
how to fix.

Fix DVB-T and DVB-C BER. It seems to return new some realistic
looking values.

Use (1 << 64) base for CNR calculations to keep it in line with
dvb logarithm functions.

Move all statistic logic to mn88473_read_status() function.

Use regmap_bulk_read() for reading multiple registers as a one go.

And many more and less minor changes.

Cc: Martin Blumenstingl 
Signed-off-by: Antti Palosaari 
---
 drivers/media/dvb-frontends/mn88473.c  | 560 +
 drivers/media/dvb-frontends/mn88473_priv.h |   1 +
 2 files changed, 161 insertions(+), 400 deletions(-)

diff --git a/drivers/media/dvb-frontends/mn88473.c 
b/drivers/media/dvb-frontends/mn88473.c
index c8dc9d3..f3b59a5 100644
--- a/drivers/media/dvb-frontends/mn88473.c
+++ b/drivers/media/dvb-frontends/mn88473.c
@@ -234,465 +234,225 @@ static int mn88473_set_frontend(struct dvb_frontend *fe)
return ret;
 }
 
-static int mn88473_update_ber_stat_t_c(struct dvb_frontend *fe,
-  enum fe_status *status)
+static int mn88473_read_status(struct dvb_frontend *fe, enum fe_status *status)
 {
struct i2c_client *client = fe->demodulator_priv;
struct mn88473_dev *dev = i2c_get_clientdata(client);
struct dtv_frontend_properties *c = &fe->dtv_property_cache;
-   int ret;
-   u64 total;
-   unsigned int uitmp, value, errors;
-
-   if (*status & FE_HAS_LOCK) {
-   ret = regmap_read(dev->regmap[0], 0x5b, &value);
-   if (ret)
-   goto err;
-
-   ret = regmap_read(dev->regmap[0], 0xdf, &uitmp);
-   if (ret)
-   goto err;
-
-   value &= uitmp;
-   ret = regmap_write(dev->regmap[0], 0x5b, value);
-   if (ret)
-   goto err;
-
-   ret = regmap_read(dev->regmap[0], 0x60, &value);
-   if (ret)
-   goto err;
-
-   value &= 0xf0;
-   value |= 0x5;
-   ret = regmap_write(dev->regmap[0], 0x60, value);
-   if (ret)
-   goto err;
-
-   ret = regmap_read(dev->regmap[0], 0x92, &uitmp);
-   if (ret)
-   goto err;
-
-   errors = uitmp << 16;
-
-   ret = regmap_read(dev->regmap[0], 0x93, &uitmp);
-   if (ret)
-   goto err;
-
-   errors |= uitmp << 8;
-
-   ret = regmap_read(dev->regmap[0], 0x94, &uitmp);
-   if (ret)
-   goto err;
-
-   errors |= uitmp;
-
-   ret = regmap_read(dev->regmap[0], 0x95, &uitmp);
-   if (ret)
-   goto err;
-
-   total = uitmp << 8;
+   int ret, i, stmp;
+   unsigned int utmp, utmp1, utmp2;
+   u8 buf[5];
 
-   ret = regmap_read(dev->regmap[0], 0x96, &uitmp);
-   if (ret)
-   goto err;
-
-   total |= uitmp;
-
-   /* probably: (bytes -> bit) * (sizeof(TS packet) - 1) */
-   total *= 8 * 203;
-
-   c->post_bit_error.stat[0].scale = FE_SCALE_COUNTER;
-   c->post_bit_error.stat[0].uvalue += errors;
-   c->post_bit_count.stat[0].scale = FE_SCALE_COUNTER;
-   c->post_bit_count.stat[0].uvalue += total;
-   } else {
-   c->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
-   c->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+   if (!dev->active) {
+   ret = -EAGAIN;
+   goto err;
}
 
-   return 0;
-
-err:
-   dev_dbg(&client->dev, "%s failed=%d\n", __func__, ret);
-   return ret;
-}
-
-static int mn88473_update_ber_stat_t2(struct dvb_frontend *fe,
- enum fe_status *status)
-{
-   struct i2c_client *client = fe->demodulator_priv;
-   struct mn88473_dev *dev = i2c_get_clientdata(client);
-   struct dtv_frontend_properties *c = &fe->dtv_property_cache;
-   int ret;
-   u64 total;
-   unsigned int uitmp, value, berlen, fec_type_m, errors;
-   static u16 fec_type_m_tbl0[] = {
-   32400, 38880, 43200, 48600, 51840, 54000, 0
-   };
-   static u16 fec_type_m_tbl1[] = {
-   28800, 38880, 43200, 47520, 50400, 53280, 0
-   };
-
-   if (*status & FE_HAS_LOCK) {
-   ret = regmap_read(dev->regmap[2], 0x82, &value);
-   if (ret)
-   goto err;
-
-   value |= 0x20;
-   value &= 0xef;
-   ret = regmap_write(dev->regmap[2], 0x82, value);
-   if (ret)
-   goto err;
-
-   ret = regmap_read(dev->regmap[2], 0xba, &uitmp);
-   if (ret)
-   goto err;
-
-