From patchwork Wed Jun 21 19:45:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scheller X-Patchwork-Id: 9802811 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 C29D16038C for ; Wed, 21 Jun 2017 19:45:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B21D428522 for ; Wed, 21 Jun 2017 19:45:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A704F2856F; Wed, 21 Jun 2017 19:45:53 +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 3BA9A28522 for ; Wed, 21 Jun 2017 19:45:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751962AbdFUTpv (ORCPT ); Wed, 21 Jun 2017 15:45:51 -0400 Received: from mail-wr0-f193.google.com ([209.85.128.193]:33605 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751927AbdFUTpt (ORCPT ); Wed, 21 Jun 2017 15:45:49 -0400 Received: by mail-wr0-f193.google.com with SMTP id x23so29319705wrb.0 for ; Wed, 21 Jun 2017 12:45:48 -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=MF7sBREjCr0epaXUL1GMBXlZbdlqUF3c5JHEicNcKK4=; b=VbZWzyRFVKTPxuv6bZvcscRnv+MQjXwlFN/iGuP0Sux/VggpKsAE3RYmcnKUTlP1LD OlD/Na41nv2oJDOYsbFmG7WxO8xv/iBfbR9ggdxn4AJrb3q7hDfTC4/Jry+5VV8OPmgQ L2UEp8yHzbnQVWT+fj1+lmRiqWps1pRyudcKHASMDs5zXx2mX3kRazfcQbiZehKJoHbf /B/4NhABMgWyP8F4TmBkZksUHsJNhwsPjgviaJt8iCCEXWhDzxBwRmqwhS8Qr8OlaROO q1JoqlvqH/Z19mt2QwNFZ8Hks29qpozPXW3Ud7HvBXkSuIN/0YL/HEnyDZH1PzqM+e0W crWA== 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=MF7sBREjCr0epaXUL1GMBXlZbdlqUF3c5JHEicNcKK4=; b=UMNtMUmhz1RSki60f+6gr+SVkrGdZb8FtxlX6SEPSRjSIyzu7656HVgVLzSOG+wpkP J+rdCGz4xTMbwg6Y3N7B4YSxMw3Vna5DU8KV8avJHuT7ozGPYOaIc4KgbuzeIZlVry6e 3AQaxjhY9uf/H9uXtfJaN3vQ7mgpE1z8vI8F1OaSm/BqeaXJ0mQPjXiDNBgiXD1lhsjq 658IW7GBvLxrHcfwq3av3IKzhndf7e/OcVHUKwtdQPnCPn9uFKjjpoRd4rCKyoOd9YIT yV1h4TZgTTA1imzpuyB3BZrMjFRjaBQYAigam8piR7fFhvwRcz6yVpBzatF9lq9QMxW3 nLZA== X-Gm-Message-State: AKS2vOwJ0m/M678Hu5CSMGXAyJZxYg9mmg8mR59a48ChP/trIuOCemi2 3rR8/0bVuiHtzKfK X-Received: by 10.28.218.140 with SMTP id r134mr2570674wmg.78.1498074347750; Wed, 21 Jun 2017 12:45:47 -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.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 21 Jun 2017 12:45:47 -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 2/4] [media] dvb-frontends/stv0367: split SNR determination into functions Date: Wed, 21 Jun 2017 21:45:42 +0200 Message-Id: <20170621194544.16949-3-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 The read_snr() functions currently do some magic to return relative scale values when called. Split out register readouts into separate functions so the functionality can be reused in some other way. Signed-off-by: Daniel Scheller --- drivers/media/dvb-frontends/stv0367.c | 68 +++++++++++++++++++++-------------- 1 file changed, 42 insertions(+), 26 deletions(-) diff --git a/drivers/media/dvb-frontends/stv0367.c b/drivers/media/dvb-frontends/stv0367.c index 8ba15dc339f8..f8e9cceed04e 100644 --- a/drivers/media/dvb-frontends/stv0367.c +++ b/drivers/media/dvb-frontends/stv0367.c @@ -1437,7 +1437,7 @@ static int stv0367ter_get_frontend(struct dvb_frontend *fe, return 0; } -static int stv0367ter_read_snr(struct dvb_frontend *fe, u16 *snr) +static u32 stv0367ter_snr_readreg(struct dvb_frontend *fe) { struct stv0367_state *state = fe->demodulator_priv; u32 snru32 = 0; @@ -1453,10 +1453,16 @@ static int stv0367ter_read_snr(struct dvb_frontend *fe, u16 *snr) cpt++; } - snru32 /= 10;/*average on 10 values*/ - *snr = snru32 / 1000; + return snru32; +} + +static int stv0367ter_read_snr(struct dvb_frontend *fe, u16 *snr) +{ + u32 snrval = stv0367ter_snr_readreg(fe); + + *snr = snrval / 1000; return 0; } @@ -2702,51 +2708,61 @@ static int stv0367cab_read_strength(struct dvb_frontend *fe, u16 *strength) return 0; } -static int stv0367cab_read_snr(struct dvb_frontend *fe, u16 *snr) +static int stv0367cab_snr_power(struct dvb_frontend *fe) { struct stv0367_state *state = fe->demodulator_priv; - u32 noisepercentage; enum stv0367cab_mod QAMSize; - u32 regval = 0, temp = 0; - int power, i; QAMSize = stv0367_readbits(state, F367CAB_QAM_MODE); switch (QAMSize) { case FE_CAB_MOD_QAM4: - power = 21904; - break; + return 21904; case FE_CAB_MOD_QAM16: - power = 20480; - break; + return 20480; case FE_CAB_MOD_QAM32: - power = 23040; - break; + return 23040; case FE_CAB_MOD_QAM64: - power = 21504; - break; + return 21504; case FE_CAB_MOD_QAM128: - power = 23616; - break; + return 23616; case FE_CAB_MOD_QAM256: - power = 21760; - break; - case FE_CAB_MOD_QAM512: - power = 1; - break; + return 21760; case FE_CAB_MOD_QAM1024: - power = 21280; - break; + return 21280; default: - power = 1; break; } + return 1; +} + +static int stv0367cab_snr_readreg(struct dvb_frontend *fe, int avgdiv) +{ + struct stv0367_state *state = fe->demodulator_priv; + u32 regval = 0; + int i; + for (i = 0; i < 10; i++) { regval += (stv0367_readbits(state, F367CAB_SNR_LO) + 256 * stv0367_readbits(state, F367CAB_SNR_HI)); } - regval /= 10; /*for average over 10 times in for loop above*/ + if (avgdiv) + regval /= 10; + + return regval; +} + +static int stv0367cab_read_snr(struct dvb_frontend *fe, u16 *snr) +{ + struct stv0367_state *state = fe->demodulator_priv; + u32 noisepercentage; + u32 regval = 0, temp = 0; + int power; + + power = stv0367cab_snr_power(fe); + regval = stv0367cab_snr_readreg(fe, 1); + if (regval != 0) { temp = power * (1 << (3 + stv0367_readbits(state, F367CAB_SNR_PER)));