From patchwork Sun Apr 7 23:53:26 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauro Carvalho Chehab X-Patchwork-Id: 2404501 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 76CCCDF2A1 for ; Sun, 7 Apr 2013 23:53:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934571Ab3DGXxw (ORCPT ); Sun, 7 Apr 2013 19:53:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:62957 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934549Ab3DGXxt (ORCPT ); Sun, 7 Apr 2013 19:53:49 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r37NrnpB012338 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sun, 7 Apr 2013 19:53:49 -0400 Received: from pedra (vpn-53-173.rdu2.redhat.com [10.10.53.173]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r37NriZR005849 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sun, 7 Apr 2013 19:53:49 -0400 Received: from v4l by pedra with local (Exim 4.80.1) (envelope-from ) id 1UOzP2-0000Ri-79; Sun, 07 Apr 2013 20:53:40 -0300 From: Mauro Carvalho Chehab Cc: Mauro Carvalho Chehab , Linux Media Mailing List Subject: [RFC PATCH 1/5] r820t: Give a better estimation of the signal strength Date: Sun, 7 Apr 2013 20:53:26 -0300 Message-Id: <1365378810-1637-1-git-send-email-mchehab@redhat.com> In-Reply-To: <1365351031-22079-1-git-send-email-mchehab@redhat.com> References: <1365351031-22079-1-git-send-email-mchehab@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 To: unlisted-recipients:; (no To-header on input) Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Instead of a binary signal strength measure, use the tuner gain to obtain a better estimation of the signal strength. Signed-off-by: Mauro Carvalho Chehab --- drivers/media/tuners/r820t.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/drivers/media/tuners/r820t.c b/drivers/media/tuners/r820t.c index 7e02920..ed9cd65 100644 --- a/drivers/media/tuners/r820t.c +++ b/drivers/media/tuners/r820t.c @@ -1082,6 +1082,18 @@ static int r820t_set_tv_standard(struct r820t_priv *priv, return 0; } +static int r820t_read_gain(struct r820t_priv *priv) +{ + u8 data[4]; + int rc; + + rc = r820_read(priv, 0x00, data, sizeof(data)); + if (rc < 0) + return rc; + + return ((data[3] & 0x0f) << 1) + ((data[3] & 0xf0) >> 4); +} + static int generic_set_freq(struct dvb_frontend *fe, u32 freq /* in HZ */, unsigned bw, @@ -1353,11 +1365,23 @@ static int r820t_set_params(struct dvb_frontend *fe) static int r820t_signal(struct dvb_frontend *fe, u16 *strength) { struct r820t_priv *priv = fe->tuner_priv; + int rc = 0; - if (priv->has_lock) - *strength = 0xffff; - else + if (priv->has_lock) { + rc = r820t_read_gain(priv); + if (rc < 0) + return rc; + + /* A higher gain at LNA means a lower signal strength */ + *strength = (45 - rc) << 4 | 0xff; + } else { *strength = 0; + } + + tuner_dbg("%s: %s, gain=%d strength=%d\n", + __func__, + priv->has_lock ? "PLL locked" : "no signal", + rc, *strength); return 0; }