From patchwork Tue Jul 19 15:22:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abylai Ospan X-Patchwork-Id: 9237703 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 844006075D for ; Tue, 19 Jul 2016 15:22:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7617727165 for ; Tue, 19 Jul 2016 15:22:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6A7ED277D9; Tue, 19 Jul 2016 15:22:17 +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 EC5B127165 for ; Tue, 19 Jul 2016 15:22:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753562AbcGSPWL (ORCPT ); Tue, 19 Jul 2016 11:22:11 -0400 Received: from 108-197-250-228.lightspeed.miamfl.sbcglobal.net ([108.197.250.228]:48762 "EHLO usa.attlocal.net" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753532AbcGSPWK (ORCPT ); Tue, 19 Jul 2016 11:22:10 -0400 Received: by usa.attlocal.net (Postfix, from userid 1000) id 74EE1105225; Tue, 19 Jul 2016 11:22:05 -0400 (EDT) From: Abylay Ospan To: Mauro Carvalho Chehab , linux-media@vger.kernel.org Cc: Abylay Ospan Subject: [PATCH] [media] cxd2841er: BER and SNR reading for ISDB-T Date: Tue, 19 Jul 2016 11:22:03 -0400 Message-Id: <1468941723-19263-1-git-send-email-aospan@netup.ru> X-Mailer: git-send-email 2.7.4 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 Added function to read BER for ISDB-T Also SNR values fixed for ISDB-T Signed-off-by: Abylay Ospan --- drivers/media/dvb-frontends/cxd2841er.c | 48 ++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/drivers/media/dvb-frontends/cxd2841er.c b/drivers/media/dvb-frontends/cxd2841er.c index d2e28ea..3df0604 100644 --- a/drivers/media/dvb-frontends/cxd2841er.c +++ b/drivers/media/dvb-frontends/cxd2841er.c @@ -206,6 +206,9 @@ static const struct cxd2841er_cnr_data s2_cn_data[] = { (u32)(((iffreq)/48.0)*16777216.0 + 0.5) : \ (u32)(((iffreq)/41.0)*16777216.0 + 0.5)) +static int cxd2841er_freeze_regs(struct cxd2841er_priv *priv); +static int cxd2841er_unfreeze_regs(struct cxd2841er_priv *priv); + static void cxd2841er_i2c_debug(struct cxd2841er_priv *priv, u8 addr, u8 reg, u8 write, const u8 *data, u32 len) @@ -1401,6 +1404,41 @@ static int cxd2841er_read_ber_c(struct cxd2841er_priv *priv, return 0; } +static int cxd2841er_read_ber_i(struct cxd2841er_priv *priv, + u32 *bit_error, u32 *bit_count) +{ + u8 data[3]; + u8 pktnum[2]; + + dev_dbg(&priv->i2c->dev, "%s()\n", __func__); + if (priv->state != STATE_ACTIVE_TC) { + dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n", + __func__, priv->state); + return -EINVAL; + } + + cxd2841er_freeze_regs(priv); + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x60); + cxd2841er_read_regs(priv, I2C_SLVT, 0x5B, pktnum, sizeof(pktnum)); + cxd2841er_read_regs(priv, I2C_SLVT, 0x16, data, sizeof(data)); + + if (!pktnum[0] && !pktnum[1]) { + dev_dbg(&priv->i2c->dev, + "%s(): no valid BER data\n", __func__); + cxd2841er_unfreeze_regs(priv); + return -EINVAL; + } + + *bit_error = ((u32)(data[0] & 0x7F) << 16) | + ((u32)data[1] << 8) | data[2]; + *bit_count = ((((u32)pktnum[0] << 8) | pktnum[1]) * 204 * 8); + dev_dbg(&priv->i2c->dev, "%s(): bit_error=%u bit_count=%u\n", + __func__, *bit_error, *bit_count); + + cxd2841er_unfreeze_regs(priv); + return 0; +} + static int cxd2841er_mon_read_ber_s(struct cxd2841er_priv *priv, u32 *bit_error, u32 *bit_count) { @@ -1798,9 +1836,7 @@ static int cxd2841er_read_snr_i(struct cxd2841er_priv *priv, u32 *snr) cxd2841er_unfreeze_regs(priv); return 0; } - if (reg > 4996) - reg = 4996; - *snr = 100 * intlog10(reg) - 9031; + *snr = 10000 * (intlog10(reg) >> 24) - 9031; cxd2841er_unfreeze_regs(priv); return 0; } @@ -1879,6 +1915,9 @@ static void cxd2841er_read_ber(struct dvb_frontend *fe) case SYS_DVBC_ANNEX_C: ret = cxd2841er_read_ber_c(priv, &bit_error, &bit_count); break; + case SYS_ISDBT: + ret = cxd2841er_read_ber_i(priv, &bit_error, &bit_count); + break; case SYS_DVBS: ret = cxd2841er_mon_read_ber_s(priv, &bit_error, &bit_count); break; @@ -1992,6 +2031,9 @@ static void cxd2841er_read_snr(struct dvb_frontend *fe) return; } + dev_dbg(&priv->i2c->dev, "%s(): snr=%d\n", + __func__, (int32_t)tmp); + if (!ret) { p->cnr.stat[0].scale = FE_SCALE_DECIBEL; p->cnr.stat[0].svalue = tmp;