From patchwork Tue Dec 17 15:30:42 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: 3363891 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9E41CC0D4A for ; Tue, 17 Dec 2013 18:34:09 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6E210202B4 for ; Tue, 17 Dec 2013 18:34:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7AD95203AC for ; Tue, 17 Dec 2013 18:33:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932096Ab3LQSdw (ORCPT ); Tue, 17 Dec 2013 13:33:52 -0500 Received: from bombadil.infradead.org ([198.137.202.9]:41989 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756279Ab3LQSds (ORCPT ); Tue, 17 Dec 2013 13:33:48 -0500 Received: from [177.143.133.66] (helo=smtp.w2.samsung.com) by bombadil.infradead.org with esmtpsa (Exim 4.80.1 #2 (Red Hat Linux)) id 1VszSk-0001w7-VS; Tue, 17 Dec 2013 18:33:48 +0000 Received: from mchehab by smtp.w2.samsung.com with local (Exim 4.80.1) (envelope-from ) id 1Vswbf-0002eX-TA; Tue, 17 Dec 2013 13:30:47 -0200 From: Mauro Carvalho Chehab Cc: Mauro Carvalho Chehab , Linux Media Mailing List , Mauro Carvalho Chehab Subject: [PATCH 2/6] [media] dib8000: estimate strength in dBm Date: Tue, 17 Dec 2013 13:30:42 -0200 Message-Id: <1387294246-10155-3-git-send-email-m.chehab@samsung.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1387294246-10155-1-git-send-email-m.chehab@samsung.com> References: <1387294246-10155-1-git-send-email-m.chehab@samsung.com> 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 X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Better to have Signal strength in dB. This takes a very rough estimation for the signal strength, that was calibrated using a Dektec DTA-2111 Gold RF generator and a Pixelview dib8076 stick. It estimates the signal strength using a linear equation where: - the max is -22.5 dBm, with returns 55953 - the min is -35.0 dBm, with returns 50110 With -22dBm, the signal strengh is returned as 65535. Unfortunately, the min strength generated with DTA-2111 is -35dBm. It should be noticed that approximating it by a linear equation is not right. I should probably be splitting it into 0.5 dB linear segments, in order to get a higher precision, just like it is done on mb86a20s, but that would force me to add some attenuators, in order to get dB levels below -35dBm, which is, btw, strong enough to get signal lock. Signed-off-by: Mauro Carvalho Chehab --- drivers/media/dvb-frontends/dib8000.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/drivers/media/dvb-frontends/dib8000.c b/drivers/media/dvb-frontends/dib8000.c index 2dbf89365a97..faf469d1d437 100644 --- a/drivers/media/dvb-frontends/dib8000.c +++ b/drivers/media/dvb-frontends/dib8000.c @@ -11,6 +11,7 @@ #include #include #include +#include #include "dvb_math.h" @@ -1002,7 +1003,7 @@ static void dib8000_reset_stats(struct dvb_frontend *fe) c->post_bit_error.len = 1; c->post_bit_count.len = 1; - c->strength.stat[0].scale = FE_SCALE_RELATIVE; + c->strength.stat[0].scale = FE_SCALE_DECIBEL; c->strength.stat[0].uvalue = 0; c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; @@ -3847,12 +3848,30 @@ static int dib8000_get_stats(struct dvb_frontend *fe, fe_status_t stat) struct dib8000_state *state = fe->demodulator_priv; struct dtv_frontend_properties *c = &state->fe[0]->dtv_property_cache; int i, lock; + u64 tmp; u32 snr, val; u16 strength; /* Get Signal strength */ dib8000_read_signal_strength(fe, &strength); - c->strength.stat[0].uvalue = strength; + + /* + * Estimate it in dBm + * This calculus was empirically determinated by measuring the signal + * strength generated by a DTA-2111 RF generator directly connected into + * a dib8076 device. The real value can actually be different on other + * devices, depending if LNA is enabled or not, if diversity is enabled, + * etc. + */ + if (strength == 65535) { + c->strength.stat[0].svalue = -22000; + } else { + tmp = strength * 25000L; + do_div(tmp, 11646); + c->strength.stat[0].svalue = tmp - 142569; + if (c->strength.stat[0].svalue > -22000) + c->strength.stat[0].svalue = -22000; + } /* Check if 1 second was elapsed */ if (!time_after(jiffies, state->get_stats_time))