aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntti Palosaari <crope@iki.fi>2014-12-09 04:14:36 -0500
committerMauro Carvalho Chehab <mchehab@osg.samsung.com>2015-02-02 14:53:53 -0500
commit47b4dbfff1f31686ac74aae7c69dec23b36005d9 (patch)
tree2cbe7d75ed7ca74e3039bba02338fb07d229fec1
parent947debb4f2e8aba1d1678b7b5d4753258a0b1513 (diff)
[media] rtl2830: implement DVBv5 CNR statistic
DVBv5 CNR. Signed-off-by: Antti Palosaari <crope@iki.fi> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
-rw-r--r--drivers/media/dvb-frontends/rtl2830.c74
-rw-r--r--drivers/media/dvb-frontends/rtl2830_priv.h3
2 files changed, 77 insertions, 0 deletions
diff --git a/drivers/media/dvb-frontends/rtl2830.c b/drivers/media/dvb-frontends/rtl2830.c
index 8025b19ac36d..c484634a9fc9 100644
--- a/drivers/media/dvb-frontends/rtl2830.c
+++ b/drivers/media/dvb-frontends/rtl2830.c
@@ -177,6 +177,7 @@ static int rtl2830_init(struct dvb_frontend *fe)
177{ 177{
178 struct i2c_client *client = fe->demodulator_priv; 178 struct i2c_client *client = fe->demodulator_priv;
179 struct rtl2830_dev *dev = i2c_get_clientdata(client); 179 struct rtl2830_dev *dev = i2c_get_clientdata(client);
180 struct dtv_frontend_properties *c = &dev->fe.dtv_property_cache;
180 int ret, i; 181 int ret, i;
181 struct rtl2830_reg_val_mask tab[] = { 182 struct rtl2830_reg_val_mask tab[] = {
182 {0x00d, 0x01, 0x03}, 183 {0x00d, 0x01, 0x03},
@@ -244,6 +245,12 @@ static int rtl2830_init(struct dvb_frontend *fe)
244 if (ret) 245 if (ret)
245 goto err; 246 goto err;
246 247
248 /* init stats here in order signal app which stats are supported */
249 c->cnr.len = 1;
250 c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
251 /* start statistics polling */
252 schedule_delayed_work(&dev->stat_work, msecs_to_jiffies(2000));
253
247 dev->sleeping = false; 254 dev->sleeping = false;
248 255
249 return ret; 256 return ret;
@@ -258,6 +265,9 @@ static int rtl2830_sleep(struct dvb_frontend *fe)
258 struct rtl2830_dev *dev = i2c_get_clientdata(client); 265 struct rtl2830_dev *dev = i2c_get_clientdata(client);
259 266
260 dev->sleeping = true; 267 dev->sleeping = true;
268 /* stop statistics polling */
269 cancel_delayed_work_sync(&dev->stat_work);
270 dev->fe_status = 0;
261 271
262 return 0; 272 return 0;
263} 273}
@@ -518,6 +528,8 @@ static int rtl2830_read_status(struct dvb_frontend *fe, fe_status_t *status)
518 FE_HAS_VITERBI; 528 FE_HAS_VITERBI;
519 } 529 }
520 530
531 dev->fe_status = *status;
532
521 return ret; 533 return ret;
522err: 534err:
523 dev_dbg(&client->dev, "failed=%d\n", ret); 535 dev_dbg(&client->dev, "failed=%d\n", ret);
@@ -670,6 +682,66 @@ static struct dvb_frontend_ops rtl2830_ops = {
670 .read_signal_strength = rtl2830_read_signal_strength, 682 .read_signal_strength = rtl2830_read_signal_strength,
671}; 683};
672 684
685static void rtl2830_stat_work(struct work_struct *work)
686{
687 struct rtl2830_dev *dev = container_of(work, struct rtl2830_dev, stat_work.work);
688 struct i2c_client *client = dev->client;
689 struct dtv_frontend_properties *c = &dev->fe.dtv_property_cache;
690 int ret, tmp;
691 u8 u8tmp, buf[2];
692 u16 u16tmp;
693
694 dev_dbg(&client->dev, "\n");
695
696 /* CNR */
697 if (dev->fe_status & FE_HAS_VITERBI) {
698 unsigned hierarchy, constellation;
699 #define CONSTELLATION_NUM 3
700 #define HIERARCHY_NUM 4
701 static const u32 constant[CONSTELLATION_NUM][HIERARCHY_NUM] = {
702 {70705899, 70705899, 70705899, 70705899},
703 {82433173, 82433173, 87483115, 94445660},
704 {92888734, 92888734, 95487525, 99770748},
705 };
706
707 ret = rtl2830_rd_reg(client, 0x33c, &u8tmp);
708 if (ret)
709 goto err;
710
711 constellation = (u8tmp >> 2) & 0x03; /* [3:2] */
712 if (constellation > CONSTELLATION_NUM - 1)
713 goto err_schedule_delayed_work;
714
715 hierarchy = (u8tmp >> 4) & 0x07; /* [6:4] */
716 if (hierarchy > HIERARCHY_NUM - 1)
717 goto err_schedule_delayed_work;
718
719 ret = rtl2830_rd_regs(client, 0x40c, buf, 2);
720 if (ret)
721 goto err;
722
723 u16tmp = buf[0] << 8 | buf[1] << 0;
724 if (u16tmp)
725 tmp = (constant[constellation][hierarchy] -
726 intlog10(u16tmp)) / ((1 << 24) / 10000);
727 else
728 tmp = 0;
729
730 dev_dbg(&client->dev, "CNR raw=%u\n", u16tmp);
731
732 c->cnr.stat[0].scale = FE_SCALE_DECIBEL;
733 c->cnr.stat[0].svalue = tmp;
734 } else {
735 c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
736 }
737
738err_schedule_delayed_work:
739 schedule_delayed_work(&dev->stat_work, msecs_to_jiffies(2000));
740 return;
741err:
742 dev_dbg(&client->dev, "failed=%d\n", ret);
743}
744
673/* 745/*
674 * I2C gate/repeater logic 746 * I2C gate/repeater logic
675 * We must use unlocked i2c_transfer() here because I2C lock is already taken 747 * We must use unlocked i2c_transfer() here because I2C lock is already taken
@@ -765,8 +837,10 @@ static int rtl2830_probe(struct i2c_client *client,
765 837
766 /* setup the state */ 838 /* setup the state */
767 i2c_set_clientdata(client, dev); 839 i2c_set_clientdata(client, dev);
840 dev->client = client;
768 dev->pdata = client->dev.platform_data; 841 dev->pdata = client->dev.platform_data;
769 dev->sleeping = true; 842 dev->sleeping = true;
843 INIT_DELAYED_WORK(&dev->stat_work, rtl2830_stat_work);
770 844
771 /* check if the demod is there */ 845 /* check if the demod is there */
772 ret = rtl2830_rd_reg(client, 0x000, &u8tmp); 846 ret = rtl2830_rd_reg(client, 0x000, &u8tmp);
diff --git a/drivers/media/dvb-frontends/rtl2830_priv.h b/drivers/media/dvb-frontends/rtl2830_priv.h
index 5f9973a07fcd..7cf316d0d149 100644
--- a/drivers/media/dvb-frontends/rtl2830_priv.h
+++ b/drivers/media/dvb-frontends/rtl2830_priv.h
@@ -25,10 +25,13 @@
25 25
26struct rtl2830_dev { 26struct rtl2830_dev {
27 struct rtl2830_platform_data *pdata; 27 struct rtl2830_platform_data *pdata;
28 struct i2c_client *client;
28 struct i2c_adapter *adapter; 29 struct i2c_adapter *adapter;
29 struct dvb_frontend fe; 30 struct dvb_frontend fe;
30 bool sleeping; 31 bool sleeping;
31 u8 page; /* active register page */ 32 u8 page; /* active register page */
33 struct delayed_work stat_work;
34 fe_status_t fe_status;
32}; 35};
33 36
34struct rtl2830_reg_val_mask { 37struct rtl2830_reg_val_mask {