From patchwork Tue Apr 3 20:59:43 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans-Frieder Vogt X-Patchwork-Id: 10574 Received: from mail.tu-berlin.de ([130.149.7.33]) by www.linuxtv.org with esmtp (Exim 4.72) (envelope-from ) id 1SFApW-0007RT-TP for patchwork@linuxtv.org; Tue, 03 Apr 2012 22:59:54 +0200 X-tubIT-Incoming-IP: 209.132.180.67 Received: from vger.kernel.org ([209.132.180.67]) by mail.tu-berlin.de (exim-4.75/mailfrontend-3) with esmtp for id 1SFApW-0004RB-Cu; Tue, 03 Apr 2012 22:59:54 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754291Ab2DCU7v (ORCPT ); Tue, 3 Apr 2012 16:59:51 -0400 Received: from mailout-de.gmx.net ([213.165.64.23]:51168 "HELO mailout-de.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1753690Ab2DCU7v (ORCPT ); Tue, 3 Apr 2012 16:59:51 -0400 Received: (qmail invoked by alias); 03 Apr 2012 20:59:49 -0000 Received: from p4FC09DC8.dip0.t-ipconnect.de (EHLO maximilian.localnet) [79.192.157.200] by mail.gmx.net (mp039) with SMTP; 03 Apr 2012 22:59:49 +0200 X-Authenticated: #24390674 X-Provags-ID: V01U2FsdGVkX190A8tZKBN0KwzYpGatjbd0vUgYmHaD/pgnZfUckf 9gryMr90KljKlp From: "Hans-Frieder Vogt" To: Antti Palosaari Subject: [PATCH] af9033: implement ber and ucb functions Date: Tue, 3 Apr 2012 22:59:43 +0200 User-Agent: KMail/1.13.7 (Linux/3.3.0-a64; KDE/4.7.4; x86_64; ; ) Cc: linux-media@vger.kernel.org MIME-Version: 1.0 Message-Id: <201204032259.43658.hfvogt@gmx.net> X-Y-GMX-Trusted: 0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-PMX-Version: 5.6.1.2065439, Antispam-Engine: 2.7.2.376379, Antispam-Data: 2012.4.3.205415 X-PMX-Spam: Gauge=IIIIIIII, Probability=8%, Report=' HTML_00_01 0.05, HTML_00_10 0.05, BODYTEXTP_SIZE_3000_LESS 0, BODY_SIZE_2000_2999 0, BODY_SIZE_5000_LESS 0, BODY_SIZE_7000_LESS 0, URI_ENDS_IN_HTML 0, __ANY_URI 0, __CP_URI_IN_BODY 0, __CT 0, __CTE 0, __CT_TEXT_PLAIN 0, __HAS_MSGID 0, __HAS_X_MAILING_LIST 0, __MIME_TEXT_ONLY 0, __MIME_VERSION 0, __SANE_MSGID 0, __SUBJ_ALPHA_END 0, __TO_MALFORMED_2 0, __URI_NO_WWW 0, __URI_NS , __USER_AGENT 0' af9033: implement read_ber and read_ucblocks functions. Signed-off-by: Hans-Frieder Vogt drivers/media/dvb/frontends/af9033.c | 62 +++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-) Hans-Frieder Vogt e-mail: hfvogt gmx .dot. net --- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff -Nupr a/drivers/media/dvb/frontends/af9033.c b/drivers/media/dvb/frontends/af9033.c --- a/drivers/media/dvb/frontends/af9033.c 2012-04-03 19:07:50.991367619 +0200 +++ b/drivers/media/dvb/frontends/af9033.c 2012-04-03 22:47:34.152121451 +0200 @@ -29,6 +29,10 @@ struct af9033_state { u32 bandwidth_hz; bool ts_mode_parallel; bool ts_mode_serial; + + u32 ber; + u32 ucb; + unsigned long last_stat_check; }; /* write multiple registers */ @@ -645,16 +649,70 @@ err: return ret; } +static int af9033_update_ch_stat(struct af9033_state *state) +{ + int ret = 0; + u32 post_err_cnt, post_bit_cnt; + u16 abort_cnt; + u8 buf[7]; + + /* only update data every half second */ + if (time_after(jiffies, state->last_stat_check + msecs_to_jiffies(500))) { + ret = af9033_rd_regs(state, 0x800032, buf, sizeof(buf)); + if (ret < 0) + goto err; + abort_cnt = (buf[1] << 8) + buf[0]; + post_err_cnt = (buf[4] << 16) + (buf[3] << 8) + buf[2]; + post_bit_cnt = (buf[6] << 8) + buf[5]; + if (post_bit_cnt == 0) { + abort_cnt = 1000; + post_err_cnt = 1; + post_bit_cnt = 2; + } else { + post_bit_cnt -= (u32)abort_cnt; + if (post_bit_cnt == 0) { + post_err_cnt = 1; + post_bit_cnt = 2; + } else { + post_err_cnt -= (u32)abort_cnt * 8 * 8; + post_bit_cnt *= 204 * 8; + } + } + state->ber = post_err_cnt * (0xffffffff / post_bit_cnt); + state->ucb = abort_cnt; + state->last_stat_check = jiffies; + } + + return 0; +err: + pr_debug("%s: failed=%d\n", __func__, ret); + return ret; +} + static int af9033_read_ber(struct dvb_frontend *fe, u32 *ber) { - *ber = 0; + struct af9033_state *state = fe->demodulator_priv; + int ret; + + ret = af9033_update_ch_stat(state); + if (ret < 0) + return ret; + + *ber = state->ber; return 0; } static int af9033_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks) { - *ucblocks = 0; + struct af9033_state *state = fe->demodulator_priv; + int ret; + + ret = af9033_update_ch_stat(state); + if (ret < 0) + return ret; + + *ucblocks = state->ucb; return 0; }