From patchwork Wed Jun 29 22:43:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauro Carvalho Chehab X-Patchwork-Id: 9206303 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6C6196089F for ; Wed, 29 Jun 2016 22:43:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5CE55285E7 for ; Wed, 29 Jun 2016 22:43:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5194928658; Wed, 29 Jun 2016 22:43:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E8BA3285F9 for ; Wed, 29 Jun 2016 22:43:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752000AbcF2Wnm (ORCPT ); Wed, 29 Jun 2016 18:43:42 -0400 Received: from bombadil.infradead.org ([198.137.202.9]:43478 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751935AbcF2Wnh (ORCPT ); Wed, 29 Jun 2016 18:43:37 -0400 Received: from 177.17.252.210.dynamic.adsl.gvt.net.br ([177.17.252.210] helo=smtp.w2.samsung.com) by bombadil.infradead.org with esmtpsa (Exim 4.85_2 #1 (Red Hat Linux)) id 1bIOCk-0003tU-Da; Wed, 29 Jun 2016 22:43:34 +0000 Received: from mchehab by smtp.w2.samsung.com with local (Exim 4.87) (envelope-from ) id 1bIOCf-0008KA-66; Wed, 29 Jun 2016 19:43:29 -0300 From: Mauro Carvalho Chehab To: Linux Media Mailing List Cc: Mauro Carvalho Chehab , Mauro Carvalho Chehab , Michael Ira Krufky Subject: [PATCH 07/10] lgdt3306a: Expose SNR via dvbv5 stats Date: Wed, 29 Jun 2016 19:43:23 -0300 Message-Id: <263b682ec3094833065bce3c16de902a7a2ec7ae.1467240152.git.mchehab@s-opensource.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <0003e025f7664aae1500f084bbd6f7aa5d92d47f.1467240152.git.mchehab@s-opensource.com> References: <0003e025f7664aae1500f084bbd6f7aa5d92d47f.1467240152.git.mchehab@s-opensource.com> In-Reply-To: <0003e025f7664aae1500f084bbd6f7aa5d92d47f.1467240152.git.mchehab@s-opensource.com> References: <0003e025f7664aae1500f084bbd6f7aa5d92d47f.1467240152.git.mchehab@s-opensource.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add support for dvbv5 stats to expose the S/N ratio in decibels. Signed-off-by: Mauro Carvalho Chehab --- drivers/media/dvb-frontends/lgdt3306a.c | 36 +++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/drivers/media/dvb-frontends/lgdt3306a.c b/drivers/media/dvb-frontends/lgdt3306a.c index 179c26e5eb4e..6b686c3a44ce 100644 --- a/drivers/media/dvb-frontends/lgdt3306a.c +++ b/drivers/media/dvb-frontends/lgdt3306a.c @@ -811,6 +811,7 @@ static int lgdt3306a_fe_sleep(struct dvb_frontend *fe) static int lgdt3306a_init(struct dvb_frontend *fe) { struct lgdt3306a_state *state = fe->demodulator_priv; + struct dtv_frontend_properties *p = &fe->dtv_property_cache; u8 val; int ret; @@ -962,6 +963,13 @@ static int lgdt3306a_init(struct dvb_frontend *fe) ret = lgdt3306a_sleep(state); lg_chkerr(ret); + /* Initialize DVBv5 statistics */ + p->strength.stat[0].scale = FE_SCALE_RELATIVE; + p->strength.stat[0].uvalue = 0; + p->strength.len = 1; + p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; + p->cnr.len = 1; + fail: return ret; } @@ -1032,6 +1040,11 @@ static int lgdt3306a_set_parameters(struct dvb_frontend *fe) if (lg_chkerr(ret)) goto fail; + /* Reset DVBv5 stats */ + p->strength.stat[0].scale = FE_SCALE_RELATIVE; + p->strength.stat[0].uvalue = 0; + p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; + #ifdef DBG_DUMP lgdt3306a_DumpAllRegs(state); #endif @@ -1497,6 +1510,8 @@ static u32 lgdt3306a_calculate_snr_x100(struct lgdt3306a_state *state) snr_x100 = log10_x1000((pwr * 10000) / mse) - 3000; dbg_info("mse=%u, pwr=%u, snr_x100=%d\n", mse, pwr, snr_x100); + state->snr = snr_x100; + return snr_x100; } @@ -1558,6 +1573,18 @@ lgdt3306a_qam_lock_poll(struct lgdt3306a_state *state) return LG3306_UNLOCK; } +static void lgdt3306a_get_stats(struct dvb_frontend *fe, enum fe_status status) +{ + struct dtv_frontend_properties *p = &fe->dtv_property_cache; + struct lgdt3306a_state *state = fe->demodulator_priv; + + if (!(status & FE_HAS_LOCK)) + return; + + p->cnr.stat[0].scale = FE_SCALE_DECIBEL; + p->cnr.stat[0].svalue = state->snr * 10; +} + static int lgdt3306a_read_status(struct dvb_frontend *fe, enum fe_status *status) { @@ -1599,9 +1626,16 @@ static int lgdt3306a_read_status(struct dvb_frontend *fe, } break; default: + state->snr = 0; ret = -EINVAL; } + } else { + state->snr = 0; } + + + lgdt3306a_get_stats(fe, *status); + return ret; } @@ -1610,8 +1644,6 @@ static int lgdt3306a_read_snr(struct dvb_frontend *fe, u16 *snr) { struct lgdt3306a_state *state = fe->demodulator_priv; - state->snr = lgdt3306a_calculate_snr_x100(state); - /* report SNR in dB * 10 */ *snr = state->snr/10; return 0;