From patchwork Fri Mar 9 15:53:36 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: 10271051 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 C020360594 for ; Fri, 9 Mar 2018 15:53:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A748C29EB1 for ; Fri, 9 Mar 2018 15:53:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9EB9E29EBC; Fri, 9 Mar 2018 15:53:53 +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 F1CDC29EB7 for ; Fri, 9 Mar 2018 15:53:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932075AbeCIPxu (ORCPT ); Fri, 9 Mar 2018 10:53:50 -0500 Received: from osg.samsung.com ([64.30.133.232]:46745 "EHLO osg.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751278AbeCIPxq (ORCPT ); Fri, 9 Mar 2018 10:53:46 -0500 Received: from localhost (localhost [127.0.0.1]) by osg.samsung.com (Postfix) with ESMTP id 69FB5727F; Fri, 9 Mar 2018 07:53:46 -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 ky0fE4C9IfFQ; Fri, 9 Mar 2018 07:53:45 -0800 (PST) Received: from smtp.s-opensource.com (unknown [179.179.39.66]) by osg.samsung.com (Postfix) with ESMTPSA id 1DEB17226; 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-0004NU-GJ; 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 11/11] media: lgdt330x: add block error counts via DVBv5 Date: Fri, 9 Mar 2018 12:53:36 -0300 Message-Id: <9068a8d6825d63594ea8f680ef53756d55463531.1520610788.git.mchehab@s-opensource.com> 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 Show the UCB error counts via DVBv5. Please notice that there's no scale indication at the driver. As we don't have the datasheet, let's assume that it is receiving data at a rate of 10.000 packets per second. Ideally, this should be read or estimated. In order to avoid flooding I2C bus with data, the maximum polling rate for those stats was set to 1 second. Signed-off-by: Mauro Carvalho Chehab --- drivers/media/dvb-frontends/lgdt330x.c | 98 ++++++++++++++++++++++++---------- 1 file changed, 70 insertions(+), 28 deletions(-) diff --git a/drivers/media/dvb-frontends/lgdt330x.c b/drivers/media/dvb-frontends/lgdt330x.c index b430b0500f12..f14948df223b 100644 --- a/drivers/media/dvb-frontends/lgdt330x.c +++ b/drivers/media/dvb-frontends/lgdt330x.c @@ -65,6 +65,8 @@ struct lgdt330x_state { /* Demodulator private data */ enum fe_modulation current_modulation; u32 snr; /* Result of last SNR calculation */ + u16 ucblocks; + unsigned long last_stats_time; /* Tuner private data */ u32 current_frequency; @@ -296,6 +298,11 @@ static int lgdt330x_init(struct dvb_frontend *fe) p->cnr.len = 1; p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; + p->block_error.len = 1; + p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; + p->block_count.len = 1; + p->block_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; + state->last_stats_time = 0; return lgdt330x_sw_reset(state); } @@ -303,29 +310,9 @@ static int lgdt330x_init(struct dvb_frontend *fe) static int lgdt330x_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks) { struct lgdt330x_state *state = fe->demodulator_priv; - int err; - u8 buf[2]; - *ucblocks = 0; + *ucblocks = state->ucblocks; - switch (state->config.demod_chip) { - case LGDT3302: - err = i2c_read_demod_bytes(state, LGDT3302_PACKET_ERR_COUNTER1, - buf, sizeof(buf)); - break; - case LGDT3303: - err = i2c_read_demod_bytes(state, LGDT3303_PACKET_ERR_COUNTER1, - buf, sizeof(buf)); - break; - default: - dev_warn(&state->client->dev, - "Only LGDT3302 and LGDT3303 are supported chips.\n"); - err = -ENODEV; - } - if (err < 0) - return err; - - *ucblocks = (buf[0] << 8) | buf[1]; return 0; } @@ -644,6 +631,7 @@ static int lgdt3302_read_status(struct dvb_frontend *fe, struct lgdt330x_state *state = fe->demodulator_priv; struct dtv_frontend_properties *p = &fe->dtv_property_cache; u8 buf[3]; + int err; *status = 0; /* Reset status result */ @@ -698,11 +686,38 @@ 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_NOT_AVAILABLE; + p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; + p->block_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; + + if (!(*status & FE_HAS_LOCK)) + return 0; + + if (state->last_stats_time && + time_is_after_jiffies(state->last_stats_time)) + return 0; + + state->last_stats_time = jiffies +msecs_to_jiffies(1000); + + err = lgdt3302_read_snr(fe); + if (!err) { 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; + } + + err = i2c_read_demod_bytes(state, LGDT3302_PACKET_ERR_COUNTER1, + buf, sizeof(buf)); + if (!err) { + state->ucblocks = (buf[0] << 8) | buf[1]; + + dprintk(state, "UCB = 0x%02x\n", state->ucblocks); + + p->block_error.stat[0].uvalue += state->ucblocks; + /* FIXME: what's the basis for block count */ + p->block_count.stat[0].uvalue += 10000; + + p->block_error.stat[0].scale = FE_SCALE_COUNTER; + p->block_count.stat[0].scale = FE_SCALE_COUNTER; } return 0; @@ -713,8 +728,8 @@ static int lgdt3303_read_status(struct dvb_frontend *fe, { struct lgdt330x_state *state = fe->demodulator_priv; struct dtv_frontend_properties *p = &fe->dtv_property_cache; - int err; u8 buf[3]; + int err; *status = 0; /* Reset status result */ @@ -772,11 +787,38 @@ static int lgdt3303_read_status(struct dvb_frontend *fe, __func__); } - if (*status & FE_HAS_LOCK && lgdt3303_read_snr(fe) >= 0) { + p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; + p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; + p->block_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; + + if (!(*status & FE_HAS_LOCK)) + return 0; + + if (state->last_stats_time && + time_is_after_jiffies(state->last_stats_time)) + return 0; + + state->last_stats_time = jiffies +msecs_to_jiffies(1000); + + err = lgdt3303_read_snr(fe); + if (!err) { 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; + } + + err = i2c_read_demod_bytes(state, LGDT3303_PACKET_ERR_COUNTER1, + buf, sizeof(buf)); + if (!err) { + state->ucblocks = (buf[0] << 8) | buf[1]; + + dprintk(state, "UCB = 0x%02x\n", state->ucblocks); + + p->block_error.stat[0].uvalue += state->ucblocks; + /* FIXME: what's the basis for block count */ + p->block_count.stat[0].uvalue += 10000; + + p->block_error.stat[0].scale = FE_SCALE_COUNTER; + p->block_count.stat[0].scale = FE_SCALE_COUNTER; } return 0;