From patchwork Fri Mar 9 15:53:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauro Carvalho Chehab X-Patchwork-Id: 10271063 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 7472560594 for ; Fri, 9 Mar 2018 15:54:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5B3D829EB7 for ; Fri, 9 Mar 2018 15:54:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 501DA29EB3; Fri, 9 Mar 2018 15:54:03 +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.9 required=2.0 tests=BAYES_00,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 AFAB229EB2 for ; Fri, 9 Mar 2018 15:54:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751268AbeCIPyB (ORCPT ); Fri, 9 Mar 2018 10:54:01 -0500 Received: from osg.samsung.com ([64.30.133.232]:52446 "EHLO osg.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751271AbeCIPxr (ORCPT ); Fri, 9 Mar 2018 10:53:47 -0500 Received: from localhost (localhost [127.0.0.1]) by osg.samsung.com (Postfix) with ESMTP id 51892728B; Fri, 9 Mar 2018 07:53:47 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at dev.s-opensource.com X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" Received: from osg.samsung.com ([127.0.0.1]) by localhost (localhost [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id jQ2isBiPBU33; Fri, 9 Mar 2018 07:53:46 -0800 (PST) Received: from smtp.s-opensource.com (unknown [179.179.39.66]) by osg.samsung.com (Postfix) with ESMTPSA id 2185F7227; Fri, 9 Mar 2018 07:53:41 -0800 (PST) Received: from mchehab by smtp.s-opensource.com with local (Exim 4.90_1) (envelope-from ) id 1euKKw-0004NM-Eu; Fri, 09 Mar 2018 12:53:38 -0300 From: Mauro Carvalho Chehab To: Linux Media Mailing List Cc: Mauro Carvalho Chehab , Mauro Carvalho Chehab Subject: [PATCH 09/11] media: lgdt330x: provide DVBv5 Carrier S/N measurements Date: Fri, 9 Mar 2018 12:53:34 -0300 Message-Id: X-Mailer: git-send-email 2.14.3 In-Reply-To: References: In-Reply-To: References: 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 Change the logic at the driver to provide CNR stats via DVBv5 API. Signed-off-by: Mauro Carvalho Chehab --- drivers/media/dvb-frontends/lgdt330x.c | 47 +++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/drivers/media/dvb-frontends/lgdt330x.c b/drivers/media/dvb-frontends/lgdt330x.c index bb61b4fb1df1..75b9ae6583e8 100644 --- a/drivers/media/dvb-frontends/lgdt330x.c +++ b/drivers/media/dvb-frontends/lgdt330x.c @@ -64,7 +64,7 @@ struct lgdt330x_state { /* Demodulator private data */ enum fe_modulation current_modulation; - u32 snr; /* Result of last SNR calculation */ + u32 snr; /* Result of last SNR calculation */ /* Tuner private data */ u32 current_frequency; @@ -187,6 +187,7 @@ static int lgdt330x_sw_reset(struct lgdt330x_state *state) static int lgdt330x_init(struct dvb_frontend *fe) { struct lgdt330x_state *state = fe->demodulator_priv; + struct dtv_frontend_properties *p = &fe->dtv_property_cache; char *chip_name; int err; /* @@ -292,6 +293,10 @@ static int lgdt330x_init(struct dvb_frontend *fe) dprintk(state, "Initialized the %s chip\n", chip_name); if (err < 0) return err; + + p->cnr.len = 1; + p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; + return lgdt330x_sw_reset(state); } @@ -513,7 +518,7 @@ static u32 calculate_snr(u32 mse, u32 c) return 10 * (c - mse); } -static int lgdt3302_read_snr(struct dvb_frontend *fe, u16 *snr) +static int lgdt3302_read_snr(struct dvb_frontend *fe) { struct lgdt330x_state *state = fe->demodulator_priv; u8 buf[5]; /* read data buffer */ @@ -546,11 +551,13 @@ static int lgdt3302_read_snr(struct dvb_frontend *fe, u16 *snr) dev_err(&state->client->dev, "%s: Modulation set to unsupported value\n", __func__); + + state->snr = 0; + return -EREMOTEIO; /* return -EDRIVER_IS_GIBBERED; */ } state->snr = calculate_snr(noise, c); - *snr = (state->snr) >> 16; /* Convert from 8.24 fixed-point to 8.8 */ dprintk(state, "noise = 0x%08x, snr = %d.%02d dB\n", noise, state->snr >> 24, (((state->snr >> 8) & 0xffff) * 100) >> 16); @@ -558,7 +565,7 @@ static int lgdt3302_read_snr(struct dvb_frontend *fe, u16 *snr) return 0; } -static int lgdt3303_read_snr(struct dvb_frontend *fe, u16 *snr) +static int lgdt3303_read_snr(struct dvb_frontend *fe) { struct lgdt330x_state *state = fe->demodulator_priv; u8 buf[5]; /* read data buffer */ @@ -591,11 +598,11 @@ static int lgdt3303_read_snr(struct dvb_frontend *fe, u16 *snr) dev_err(&state->client->dev, "%s: Modulation set to unsupported value\n", __func__); + state->snr = 0; return -EREMOTEIO; /* return -EDRIVER_IS_GIBBERED; */ } state->snr = calculate_snr(noise, c); - *snr = (state->snr) >> 16; /* Convert from 8.24 fixed-point to 8.8 */ dprintk(state, "noise = 0x%08x, snr = %d.%02d dB\n", noise, state->snr >> 24, (((state->snr >> 8) & 0xffff) * 100) >> 16); @@ -603,6 +610,15 @@ static int lgdt3303_read_snr(struct dvb_frontend *fe, u16 *snr) return 0; } +static int lgdt330x_read_snr(struct dvb_frontend *fe, u16 *snr) +{ + struct lgdt330x_state *state = fe->demodulator_priv; + + *snr = (state->snr) >> 16; /* Convert from 8.24 fixed-point to 8.8 */ + + return 0; +} + static int lgdt330x_read_signal_strength(struct dvb_frontend *fe, u16 *strength) { /* Calculate Strength from SNR up to 35dB */ @@ -632,6 +648,7 @@ static int lgdt3302_read_status(struct dvb_frontend *fe, enum fe_status *status) { struct lgdt330x_state *state = fe->demodulator_priv; + struct dtv_frontend_properties *p = &fe->dtv_property_cache; u8 buf[3]; *status = 0; /* Reset status result */ @@ -687,6 +704,13 @@ static int lgdt3302_read_status(struct dvb_frontend *fe, __func__); } + if (*status & FE_HAS_LOCK && lgdt3302_read_snr(fe) >= 0) { + p->cnr.stat[0].scale = FE_SCALE_DECIBEL; + p->cnr.stat[0].svalue = (((u64)state->snr) * 1000) >> 24; + } else { + p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; + } + return 0; } @@ -694,6 +718,7 @@ static int lgdt3303_read_status(struct dvb_frontend *fe, enum fe_status *status) { struct lgdt330x_state *state = fe->demodulator_priv; + struct dtv_frontend_properties *p = &fe->dtv_property_cache; int err; u8 buf[3]; @@ -752,6 +777,14 @@ static int lgdt3303_read_status(struct dvb_frontend *fe, "%s: Modulation set to unsupported value\n", __func__); } + + if (*status & FE_HAS_LOCK && lgdt3303_read_snr(fe) >= 0) { + p->cnr.stat[0].scale = FE_SCALE_DECIBEL; + p->cnr.stat[0].svalue = (((u64)state->snr) * 1000) >> 24; + } else { + p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; + } + return 0; } @@ -878,7 +911,7 @@ static const struct dvb_frontend_ops lgdt3302_ops = { .read_status = lgdt3302_read_status, .read_ber = lgdt330x_read_ber, .read_signal_strength = lgdt330x_read_signal_strength, - .read_snr = lgdt3302_read_snr, + .read_snr = lgdt330x_read_snr, .read_ucblocks = lgdt330x_read_ucblocks, .release = lgdt330x_release, }; @@ -901,7 +934,7 @@ static const struct dvb_frontend_ops lgdt3303_ops = { .read_status = lgdt3303_read_status, .read_ber = lgdt330x_read_ber, .read_signal_strength = lgdt330x_read_signal_strength, - .read_snr = lgdt3303_read_snr, + .read_snr = lgdt330x_read_snr, .read_ucblocks = lgdt330x_read_ucblocks, .release = lgdt330x_release, };