From patchwork Mon Jul 3 17:20:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scheller X-Patchwork-Id: 9823761 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 B682960237 for ; Mon, 3 Jul 2017 17:21:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9CA2227FB1 for ; Mon, 3 Jul 2017 17:21:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 914C52860D; Mon, 3 Jul 2017 17:21: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 1FFFB27FB1 for ; Mon, 3 Jul 2017 17:21:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755520AbdGCRVQ (ORCPT ); Mon, 3 Jul 2017 13:21:16 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:33139 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755472AbdGCRVN (ORCPT ); Mon, 3 Jul 2017 13:21:13 -0400 Received: by mail-wm0-f66.google.com with SMTP id j85so21729207wmj.0 for ; Mon, 03 Jul 2017 10:21:12 -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=pXO+aEOCtKCsrR89njxHH1BZmNQIeiulvXDyiDrnEbw=; b=HdGrpmJLN5zOFlIu/bAL1pJBEjEN/7zWAQZ7qUf0sjISM+5e7utviAk4w6uLY52WJt M5t9BNzK0tS4h8DU3/52gUls/VRvtFW617fFirjWrEQhAR+wcLFfCbo1426xXZ4lUqYa IaZVcJkxjeeiTX+UgKcjkPBDA+SNMPxuQyeh0EHmcWjp+P4HA0hpQd2woqhFltjm7rah UozwVl4WSyzYb6xm++OYz3rcC2cHzgSZGd/gjLNOk52anvJyxIOSTWkVp/piEUq8/GEH 2+jRSC5HeYa0TpFvz58Zsw6PFIfMShc+1QhzdT4W1TafNi/2/ylRJjSAkAQW+mlxQ88Q FkBg== 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=pXO+aEOCtKCsrR89njxHH1BZmNQIeiulvXDyiDrnEbw=; b=tqL3oAQNWFOukOPVB1eNNmHOsEoW8G+8049yr6qQmPrvksbTu05gk7rwAn4lV79q6I CezEtm/yPoHQTdo69jQ2kouSMIeZkS4s/NBL/ViG+Xh/Cj027qez0qrh7MrYiVAZKzQz Acei2I+7s3ycqsUvUaGtnNUXu2le0o96A8mduH+Ap6Doe8XBgMO89x3NYqt7tl5qvSFW 68UZKumqEMEuOYqUZUt4o/feolsBXl3AXmbX02LXMKJ5JR/sLG4EmDhVODoRzXM781t8 5Mz+snTsB3HofgGFIJOtnJaq0CsCgG00jGqYJXFKK3+ood6GrM5OKZz89fRzGbFVxKr2 mivQ== X-Gm-Message-State: AKS2vOx6id1fdDAnx0rRqG9+f7Ah24FDEysgVlrZzuXGjMo5Gljklaqf wswnzIPf0KbrJxFM X-Received: by 10.28.209.138 with SMTP id i132mr15177738wmg.30.1499102471751; Mon, 03 Jul 2017 10:21:11 -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 x21sm17350309wme.24.2017.07.03.10.21.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 03 Jul 2017 10:21:11 -0700 (PDT) From: Daniel Scheller To: linux-media@vger.kernel.org, mchehab@kernel.org, mchehab@s-opensource.com Cc: jasmin@anw.at, rjkm@metzlerbros.de Subject: [PATCH v3 04/10] [media] dvb-frontends/stv0910: Add demod-only signal strength reporting Date: Mon, 3 Jul 2017 19:20:57 +0200 Message-Id: <20170703172104.27283-5-d.scheller.oss@gmail.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170703172104.27283-1-d.scheller.oss@gmail.com> References: <20170703172104.27283-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 Tested-by: Richard Scobie --- drivers/media/dvb-frontends/stv0910.c | 48 ++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/drivers/media/dvb-frontends/stv0910.c b/drivers/media/dvb-frontends/stv0910.c index dc848ebe1a44..dc4d829bb47a 100644 --- a/drivers/media/dvb-frontends/stv0910.c +++ b/drivers/media/dvb-frontends/stv0910.c @@ -135,7 +135,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, @@ -327,6 +327,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 *********************************************************************/ @@ -567,7 +586,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; @@ -1300,11 +1319,32 @@ 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, 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)