From patchwork Fri Jun 30 20:51:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scheller X-Patchwork-Id: 9820469 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 104BE603D7 for ; Fri, 30 Jun 2017 20:51:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0348C28464 for ; Fri, 30 Jun 2017 20:51:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EBB2928516; Fri, 30 Jun 2017 20:51:18 +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 785D428511 for ; Fri, 30 Jun 2017 20:51:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752968AbdF3UvQ (ORCPT ); Fri, 30 Jun 2017 16:51:16 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:36364 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752957AbdF3UvP (ORCPT ); Fri, 30 Jun 2017 16:51:15 -0400 Received: by mail-wm0-f68.google.com with SMTP id y5so9855435wmh.3 for ; Fri, 30 Jun 2017 13:51:15 -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=mCRz/BV6fxo9wfRl6dTT1DsMOgBGPKXgcg086Eq2PkM=; b=ihIu4HARRieHPMkpGoGUYowsW4pUAd8002NypAzKynKrlw9Tf7p/L+DlVNKLV3+gqe zSJQ9F/INWT9VIUtNqXjXRo3f4Ou65eGE4dQsWC2FfR7oWxixroTkng/nE8Q3eHjqHCJ m9aMH+du9ClBTvUuW1hUJZtVk3fvRe5ETXmGEVJvSggJhfyVPqVA/PzRcAq8M4QCDrWO bERDmZzhSjoro/nyReS4dSFriaVEVTKwdbJzy0KpjqJolaH3381wQAhLxCffaRtgDTPD Mm2eJRNYUZl98wufKwUnDMofU+qgixEw4M+uEUVsrNyDBotXICG7YqCwsMs42ZCTtFEQ WH/A== 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=mCRz/BV6fxo9wfRl6dTT1DsMOgBGPKXgcg086Eq2PkM=; b=Z9vlgk01ScxqWEVrpab1Ndru0bFC/WbfYdx1YzVOxgsGTXAey3eTMJIRyMSN8A2ueW eQOr0yik/A3treQ1Jm96w+WaNzJYfW9pvvQdVftNOzR5yyrwr2a1qzWHGXN4+pa0Fzpz sLHU+Uo3MT7m5vKX0UhPMoWhPaVIF4OAUOwMDSGtrDdWHGWbVwOD+0tIVrPRbhu7ezpV okAmKHiUa3XS7cc8WDX3e0tikZs5IfjP7CYX2CbVDn1e/PQW8bpd5/jLSR3CXLtuSURo 822Yronf/46+ZOgYygZBKObChSWurJLmY34GtcWyfQEoeiq36lOeo4O1kUrYYBT2fH9D fzvA== X-Gm-Message-State: AKS2vOwiIWJLH1+2HxU2BK7riCc6doZhPJdxO3tI4YOH57GT+ENls+ac SW8jAelFwj/mRDOa X-Received: by 10.28.8.72 with SMTP id 69mr16032736wmi.102.1498855874135; Fri, 30 Jun 2017 13:51:14 -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 e24sm6420051wrc.35.2017.06.30.13.51.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 30 Jun 2017 13:51:13 -0700 (PDT) From: Daniel Scheller To: linux-media@vger.kernel.org, mchehab@kernel.org, mchehab@s-opensource.com Cc: rjkm@metzlerbros.de, jasmin@anw.at Subject: [PATCH v2 04/10] [media] dvb-frontends/stv0910: Add demod-only signal strength reporting Date: Fri, 30 Jun 2017 22:51:00 +0200 Message-Id: <20170630205106.1268-5-d.scheller.oss@gmail.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170630205106.1268-1-d.scheller.oss@gmail.com> References: <20170630205106.1268-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 Original code at least has some signed/unsigned issues, resulting in values like 32dBm. Implement signal strength readout to work without asking the attached tuner, and use a lookup table instead of log calc. Values reported appear plausible, gathered from feedback from several testers. Signed-off-by: Daniel Scheller --- drivers/media/dvb-frontends/stv0910.c | 51 ++++++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/drivers/media/dvb-frontends/stv0910.c b/drivers/media/dvb-frontends/stv0910.c index b9d6a61e6017..045f8f5305ab 100644 --- a/drivers/media/dvb-frontends/stv0910.c +++ b/drivers/media/dvb-frontends/stv0910.c @@ -136,7 +136,7 @@ struct sinit_table { struct slookup { s16 value; - u16 reg_value; + u32 reg_value; }; static inline int i2c_write(struct i2c_adapter *adap, u8 adr, @@ -328,6 +328,25 @@ struct slookup s2_sn_lookup[] = { { 510, 463 }, /*C/N=51.0dB*/ }; +struct slookup padc_lookup[] = { + { 0, 118000 }, /* PADC=+0dBm */ + { -100, 93600 }, /* PADC=-1dBm */ + { -200, 74500 }, /* PADC=-2dBm */ + { -300, 59100 }, /* PADC=-3dBm */ + { -400, 47000 }, /* PADC=-4dBm */ + { -500, 37300 }, /* PADC=-5dBm */ + { -600, 29650 }, /* PADC=-6dBm */ + { -700, 23520 }, /* PADC=-7dBm */ + { -900, 14850 }, /* PADC=-9dBm */ + { -1100, 9380 }, /* PADC=-11dBm */ + { -1300, 5910 }, /* PADC=-13dBm */ + { -1500, 3730 }, /* PADC=-15dBm */ + { -1700, 2354 }, /* PADC=-17dBm */ + { -1900, 1485 }, /* PADC=-19dBm */ + { -2000, 1179 }, /* PADC=-20dBm */ + { -2100, 1000 }, /* PADC=-21dBm */ +}; + /********************************************************************* * Tracking carrier loop carrier QPSK 1/4 to 8PSK 9/10 long Frame *********************************************************************/ @@ -568,7 +587,7 @@ static int tracking_optimization(struct stv *state) } static s32 table_lookup(struct slookup *table, - int table_size, u16 reg_value) + int table_size, u32 reg_value) { s32 value; int imin = 0; @@ -1301,9 +1320,33 @@ static int read_ber(struct dvb_frontend *fe) static void read_signal_strength(struct dvb_frontend *fe) { - /* FIXME: add signal strength algo */ + struct stv *state = fe->demodulator_priv; + struct dtv_frontend_properties *p = &state->fe.dtv_property_cache; + s64 strength; + u8 reg[2]; + u16 agc; + s32 padc; + s32 power = 0; + int i; - p->strength.stat[0].scale = FE_SCALE_NOT_AVAILABLE; + read_regs(state, RSTV0910_P2_AGCIQIN1 + state->regoff, reg, 2); + + agc = (((u32) reg[0]) << 8) | reg[1]; + + for (i = 0; i < 5; i += 1) { + read_regs(state, RSTV0910_P2_POWERI + state->regoff, reg, 2); + power += (u32) reg[0] * (u32) reg[0] + + (u32) reg[1] * (u32) reg[1]; + usleep_range(3000, 4000); + } + power /= 5; + + padc = table_lookup(padc_lookup, ARRAY_SIZE(padc_lookup), power) + 352; + + strength = (padc - agc); + + p->strength.stat[0].scale = FE_SCALE_DECIBEL; + p->strength.stat[0].uvalue = strength; } static int read_status(struct dvb_frontend *fe, enum fe_status *status)