From patchwork Wed Jun 21 19:45:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scheller X-Patchwork-Id: 9802815 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 5FFEC6038C for ; Wed, 21 Jun 2017 19:45:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4EC7328522 for ; Wed, 21 Jun 2017 19:45:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 435F22856F; Wed, 21 Jun 2017 19:45:57 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, 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 D6A0C28522 for ; Wed, 21 Jun 2017 19:45:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751133AbdFUTpz (ORCPT ); Wed, 21 Jun 2017 15:45:55 -0400 Received: from mail-wr0-f196.google.com ([209.85.128.196]:33622 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751875AbdFUTpu (ORCPT ); Wed, 21 Jun 2017 15:45:50 -0400 Received: by mail-wr0-f196.google.com with SMTP id x23so29319830wrb.0 for ; Wed, 21 Jun 2017 12:45:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=fSM6UhbX2IAVwIjRwQMy7V0WV1dQveXCMKlp3GwDOog=; b=aw4rCd0wKrEJNTnGBQw5YLJI3UYuAdPXbE76CtfHTgpMfNi7437BcJOjz6q5olLdO6 P/MTkqDHkTU0Nvn5abCADY8chl8BkijLapPkhM23QOpTyl7eE0Bt3eB8Y8poZE8mZX50 l+crCkP7vNuZLFxZH9Wqv7ISzfyr0TkZltDPceNXjknJESALz4SIuLKRgqvR0wGW9vQ0 MEBYgm4oKHD8DOir0pig/gzSO//MLAOh777rLia2Sb1h2HlFa7I5GBdtivn6k+yjoqbc 1pytFMN3V9qSAtwkrV95Argk5tL9lBhjZOYSboe/j1ri68aJCY33VZApCa4upnF/dgmg XFZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=fSM6UhbX2IAVwIjRwQMy7V0WV1dQveXCMKlp3GwDOog=; b=QhLhXhDEYmAQvEmxOLGJc86JjToWl2aQyMQ2sne0AoR1Jr4kAtEnEioD46eD7R3BfA dmRWSc7ECb7kkGnpGtxd+CrNUqzKV8TZBGqas11AslallRT33Ib2opuH/1XxJW9mh3E1 P3OpyDEe/Auu4qZVW3HwWB/XBVS/hhUdP1xr85m5sut/EPKKAMFQGOhsDvZHCtA0zgxT uxLZUMKi8X0VNzY++ITBfNszv9+qTJMR5E+RLPrXtkbuzXAfTnWft6TgfHWsHqzo2WHI o5MlIFBDl5w3d9A9ceeq+C9mtU5yaqWfgZ6/0wXtEnYSs7fuaULO8TLf+5TZnWEtDAkc GPjw== X-Gm-Message-State: AKS2vOwVGUbees+i71URgZy3C/5mS2SAN6IMvowqkzJNrLBdLSG3C0n/ pMh8Aee1/RhWTfi4 X-Received: by 10.223.144.134 with SMTP id i6mr28370032wri.92.1498074348671; Wed, 21 Jun 2017 12:45:48 -0700 (PDT) Received: from dvbdev.wuest.de (ip-37-24-178-151.hsi14.unitymediagroup.de. [37.24.178.151]) by smtp.gmail.com with ESMTPSA id 29sm27314193wrv.23.2017.06.21.12.45.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 21 Jun 2017 12:45:48 -0700 (PDT) From: Daniel Scheller To: linux-media@vger.kernel.org, mchehab@kernel.org, mchehab@s-opensource.com Cc: liplianin@netup.ru, rjkm@metzlerbros.de, crope@iki.fi Subject: [PATCH v2 3/4] [media] dvb-frontends/stv0367: SNR DVBv5 statistics for DVB-C and T Date: Wed, 21 Jun 2017 21:45:43 +0200 Message-Id: <20170621194544.16949-4-d.scheller.oss@gmail.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170621194544.16949-1-d.scheller.oss@gmail.com> References: <20170621194544.16949-1-d.scheller.oss@gmail.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 From: Daniel Scheller Add signal-to-noise-ratio as provided by the demodulator in decibel scale. QAM/DVB-C needs some intlog calculation to have usable dB values, OFDM/ DVB-T values from the demod look alright already and are provided as-is. Signed-off-by: Daniel Scheller --- drivers/media/dvb-frontends/stv0367.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/drivers/media/dvb-frontends/stv0367.c b/drivers/media/dvb-frontends/stv0367.c index f8e9cceed04e..d3be25bc1002 100644 --- a/drivers/media/dvb-frontends/stv0367.c +++ b/drivers/media/dvb-frontends/stv0367.c @@ -25,6 +25,8 @@ #include #include +#include "dvb_math.h" + #include "stv0367.h" #include "stv0367_defs.h" #include "stv0367_regs.h" @@ -2996,6 +2998,37 @@ static int stv0367ddb_set_frontend(struct dvb_frontend *fe) return -EINVAL; } +static void stv0367ddb_read_snr(struct dvb_frontend *fe) +{ + struct stv0367_state *state = fe->demodulator_priv; + struct dtv_frontend_properties *p = &fe->dtv_property_cache; + int cab_pwr; + u32 regval, tmpval, snrval = 0; + + switch (state->activedemod) { + case demod_ter: + snrval = stv0367ter_snr_readreg(fe); + break; + case demod_cab: + cab_pwr = stv0367cab_snr_power(fe); + regval = stv0367cab_snr_readreg(fe, 0); + + /* prevent division by zero */ + if (!regval) + snrval = 0; + + tmpval = (cab_pwr * 320) / regval; + snrval = ((tmpval != 0) ? (intlog2(tmpval) / 5581) : 0); + break; + default: + p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; + return; + } + + p->cnr.stat[0].scale = FE_SCALE_DECIBEL; + p->cnr.stat[0].uvalue = snrval; +} + static void stv0367ddb_read_ucblocks(struct dvb_frontend *fe) { struct stv0367_state *state = fe->demodulator_priv; @@ -3042,10 +3075,12 @@ static int stv0367ddb_read_status(struct dvb_frontend *fe, /* stop if demod isn't locked */ if (!(*status & FE_HAS_LOCK)) { + p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; return ret; } + stv0367ddb_read_snr(fe); stv0367ddb_read_ucblocks(fe); return 0;