mirror of
https://github.com/edk2-porting/linux-next.git
synced 2024-12-22 04:03:58 +08:00
[media] mn88472: implement cnr statistics
Implement DVBv5 CNR. Signed-off-by: Antti Palosaari <crope@iki.fi> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
This commit is contained in:
parent
61d7c6aa4f
commit
c635a5e2cf
@ -28,9 +28,9 @@ static int mn88472_read_status(struct dvb_frontend *fe, enum fe_status *status)
|
||||
struct i2c_client *client = fe->demodulator_priv;
|
||||
struct mn88472_dev *dev = i2c_get_clientdata(client);
|
||||
struct dtv_frontend_properties *c = &fe->dtv_property_cache;
|
||||
int ret, i;
|
||||
unsigned int utmp, utmp1;
|
||||
u8 buf[2];
|
||||
int ret, i, stmp;
|
||||
unsigned int utmp, utmp1, utmp2;
|
||||
u8 buf[5];
|
||||
|
||||
if (!dev->active) {
|
||||
ret = -EAGAIN;
|
||||
@ -96,6 +96,89 @@ static int mn88472_read_status(struct dvb_frontend *fe, enum fe_status *status)
|
||||
c->strength.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
/* CNR */
|
||||
if (*status & FE_HAS_VITERBI && c->delivery_system == SYS_DVBT) {
|
||||
/* DVB-T CNR */
|
||||
ret = regmap_bulk_read(dev->regmap[0], 0x9c, buf, 2);
|
||||
if (ret)
|
||||
goto err;
|
||||
|
||||
utmp = buf[0] << 8 | buf[1] << 0;
|
||||
if (utmp) {
|
||||
/* CNR[dB]: 10 * log10(65536 / value) + 2 */
|
||||
/* log10(65536) = 80807124, 0.2 = 3355443 */
|
||||
stmp = ((u64)80807124 - intlog10(utmp) + 3355443)
|
||||
* 10000 >> 24;
|
||||
|
||||
dev_dbg(&client->dev, "cnr=%d value=%u\n", stmp, utmp);
|
||||
} else {
|
||||
stmp = 0;
|
||||
}
|
||||
|
||||
c->cnr.stat[0].svalue = stmp;
|
||||
c->cnr.stat[0].scale = FE_SCALE_DECIBEL;
|
||||
} else if (*status & FE_HAS_VITERBI &&
|
||||
c->delivery_system == SYS_DVBT2) {
|
||||
/* DVB-T2 CNR */
|
||||
for (i = 0; i < 3; i++) {
|
||||
ret = regmap_bulk_read(dev->regmap[2], 0xbc + i,
|
||||
&buf[i], 1);
|
||||
if (ret)
|
||||
goto err;
|
||||
}
|
||||
|
||||
utmp = buf[1] << 8 | buf[2] << 0;
|
||||
utmp1 = (buf[0] >> 2) & 0x01; /* 0=SISO, 1=MISO */
|
||||
if (utmp) {
|
||||
if (utmp1) {
|
||||
/* CNR[dB]: 10 * log10(16384 / value) - 6 */
|
||||
/* log10(16384) = 70706234, 0.6 = 10066330 */
|
||||
stmp = ((u64)70706234 - intlog10(utmp)
|
||||
- 10066330) * 10000 >> 24;
|
||||
dev_dbg(&client->dev, "cnr=%d value=%u MISO\n",
|
||||
stmp, utmp);
|
||||
} else {
|
||||
/* CNR[dB]: 10 * log10(65536 / value) + 2 */
|
||||
/* log10(65536) = 80807124, 0.2 = 3355443 */
|
||||
stmp = ((u64)80807124 - intlog10(utmp)
|
||||
+ 3355443) * 10000 >> 24;
|
||||
|
||||
dev_dbg(&client->dev, "cnr=%d value=%u SISO\n",
|
||||
stmp, utmp);
|
||||
}
|
||||
} else {
|
||||
stmp = 0;
|
||||
}
|
||||
|
||||
c->cnr.stat[0].svalue = stmp;
|
||||
c->cnr.stat[0].scale = FE_SCALE_DECIBEL;
|
||||
} else if (*status & FE_HAS_VITERBI &&
|
||||
c->delivery_system == SYS_DVBC_ANNEX_A) {
|
||||
/* DVB-C CNR */
|
||||
ret = regmap_bulk_read(dev->regmap[1], 0xa1, buf, 4);
|
||||
if (ret)
|
||||
goto err;
|
||||
|
||||
utmp1 = buf[0] << 8 | buf[1] << 0; /* signal */
|
||||
utmp2 = buf[2] << 8 | buf[3] << 0; /* noise */
|
||||
if (utmp1 && utmp2) {
|
||||
/* CNR[dB]: 10 * log10(8 * (signal / noise)) */
|
||||
/* log10(8) = 15151336 */
|
||||
stmp = ((u64)15151336 + intlog10(utmp1)
|
||||
- intlog10(utmp2)) * 10000 >> 24;
|
||||
|
||||
dev_dbg(&client->dev, "cnr=%d signal=%u noise=%u\n",
|
||||
stmp, utmp1, utmp2);
|
||||
} else {
|
||||
stmp = 0;
|
||||
}
|
||||
|
||||
c->cnr.stat[0].svalue = stmp;
|
||||
c->cnr.stat[0].scale = FE_SCALE_DECIBEL;
|
||||
} else {
|
||||
c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
return 0;
|
||||
err:
|
||||
dev_dbg(&client->dev, "failed=%d\n", ret);
|
||||
@ -570,6 +653,7 @@ static int mn88472_probe(struct i2c_client *client,
|
||||
/* Init stats to indicate which stats are supported */
|
||||
c = &dev->fe.dtv_property_cache;
|
||||
c->strength.len = 1;
|
||||
c->cnr.len = 1;
|
||||
|
||||
/* Setup callbacks */
|
||||
pdata->get_dvb_frontend = mn88472_get_dvb_frontend;
|
||||
|
@ -18,6 +18,7 @@
|
||||
#define MN88472_PRIV_H
|
||||
|
||||
#include "dvb_frontend.h"
|
||||
#include "dvb_math.h"
|
||||
#include "mn88472.h"
|
||||
#include <linux/firmware.h>
|
||||
#include <linux/regmap.h>
|
||||
|
Loading…
Reference in New Issue
Block a user