From patchwork Sun Jun 25 11:26:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scheller X-Patchwork-Id: 9808115 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 997EA6038C for ; Sun, 25 Jun 2017 11:27:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8B7CE26E97 for ; Sun, 25 Jun 2017 11:27:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 80694271CB; Sun, 25 Jun 2017 11:27:00 +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.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM 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 BBDA6285DA for ; Sun, 25 Jun 2017 11:26:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751189AbdFYL0x (ORCPT ); Sun, 25 Jun 2017 07:26:53 -0400 Received: from mail-wr0-f195.google.com ([209.85.128.195]:34490 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751050AbdFYL0v (ORCPT ); Sun, 25 Jun 2017 07:26:51 -0400 Received: by mail-wr0-f195.google.com with SMTP id k67so23865324wrc.1 for ; Sun, 25 Jun 2017 04:26:51 -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=9xwkWy30MjvTHOsEpBH3dFqHiZwgvBWMAaXCIjCeUAw=; b=oMHvWHl4jV5XVXeZQROSd/0SwwVeyR06eRHCgK5I9gNqcyNmQarXHQNHihaz/wU4mC FFqvBF4pBm5xfAA7sbfCxmOuqHb0UHXb4LUCPqa5xE3JlgT2dMz+XS3iXosyWITB0BuS GRaK3qMhGik3E1GITnFtxveot1//jy/CD1rWecCiAyT6m7O5tr4cSPIRXGUrhsgpDdb8 2uuTJ3T8T+VbIo5/nHVjpqdIKjPxO3DimGu9sxv13lHFpQhUQJx01wvHdHYz+yp6KW1J lKT0n4aYdDfA/VTzE1u0qsw5gzuWIdYFZpagllRDRCzcLK/gONvs1SCPr1LpxHQpJo0Y dtzQ== 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=9xwkWy30MjvTHOsEpBH3dFqHiZwgvBWMAaXCIjCeUAw=; b=c88Iw+d7uk/nB3MIk56QtVeMgK+q0NetlqQuR1xW8eSrYZvoseDvSs4rE9E43aXenh oZF3n3oImgvLcosIuUK+04qOra+OcU+UkFQgCMxue/TzVza/q//ZCBxqjp+5ptVjVMJ1 07uMBhaye6h/67WrVZP791CF/J+bwhHnyZei2aLOltKDTRtsWZw6Afg/W+r93UFnlItb tfL9kP2Tlf4CYJhauTE59i0JzEU/zLxZw3Tr7lDh3C3d+ZjTuy7FXZDy8kidhJkJgTnI e4VczQvLkkGYeutPgIhfxIHdcyKEstRZhlKavwTNIX8k03MJPQdGtYttZTGNl0ALJ1Yj wa7A== X-Gm-Message-State: AKS2vOzx0GkgarG3KmFJqqjp9edJsaCylBUpXhcjZjSSCb/jomIZ+hHh c0ULL0sznnhWWAC7 X-Received: by 10.223.173.140 with SMTP id w12mr11859892wrc.4.1498390010140; Sun, 25 Jun 2017 04:26:50 -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 b131sm9896099wma.11.2017.06.25.04.26.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 25 Jun 2017 04:26:49 -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 v3 2/4] [media] dvb-frontends/stv0367: SNR DVBv5 statistics for DVB-C and T Date: Sun, 25 Jun 2017 13:26:44 +0200 Message-Id: <20170625112646.7973-3-d.scheller.oss@gmail.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170625112646.7973-1-d.scheller.oss@gmail.com> References: <20170625112646.7973-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 | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/drivers/media/dvb-frontends/stv0367.c b/drivers/media/dvb-frontends/stv0367.c index 9e5432b761b5..138f859d0f25 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" @@ -3009,6 +3011,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; @@ -3053,6 +3086,12 @@ static int stv0367ddb_read_status(struct dvb_frontend *fe, if (ret) return ret; + /* read carrier/noise when a carrier is detected */ + if (*status & FE_HAS_CARRIER) + stv0367ddb_read_snr(fe); + else + p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; + /* stop if demod isn't locked */ if (!(*status & FE_HAS_LOCK)) { p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;