From patchwork Fri Jan 2 13:56:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Malcolm Priestley X-Patchwork-Id: 5559181 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id A4C0F9F2ED for ; Fri, 2 Jan 2015 14:03:00 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 91FF0201F2 for ; Fri, 2 Jan 2015 14:02:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 510C32021B for ; Fri, 2 Jan 2015 14:02:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752072AbbABOC4 (ORCPT ); Fri, 2 Jan 2015 09:02:56 -0500 Received: from mail-we0-f176.google.com ([74.125.82.176]:61512 "EHLO mail-we0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751953AbbABOCz (ORCPT ); Fri, 2 Jan 2015 09:02:55 -0500 X-Greylist: delayed 356 seconds by postgrey-1.27 at vger.kernel.org; Fri, 02 Jan 2015 09:02:55 EST Received: by mail-we0-f176.google.com with SMTP id w61so4509856wes.7 for ; Fri, 02 Jan 2015 06:02:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=YuOYMkQ5dWI4IiCjR7txTz27Td4rXt/oatrVI1bdN7E=; b=fWWOgKG+zRIhoZzFKoHrgP8+c81vvDp0JB6T04vQhw5l7LFF9FCufDWKTlEHv7SGY3 10Q4e1tisASbtrld/hpbvNCxZ5Wny5DcA6o39efs7JUGBILbIMBDxWmimOTqRU1KrpM0 1VG7CGw1z7yOx+UEwBlYd50BACZkGRIxAdGY3Hv4zjFiAN2gEOY9HZAx1Ji3fwga+0Ge 1Z7E0z3/9I+9aTwx48bqrfAc2lWPc668lMGuRJ7MClRZxLyj7NpEz7nFp6cXwTVseDeT ypUoirxE+J2fSOFV94EybQoZA0Xy3WtXVh3xzWZJapi2D1ccPI/X8gBV/vFCiGh6gNPT 14dg== X-Received: by 10.194.60.243 with SMTP id k19mr46969696wjr.88.1420207018528; Fri, 02 Jan 2015 05:56:58 -0800 (PST) Received: from localhost.localdomain (dab-far1-h-1-8.dab.02.net. [82.132.222.244]) by mx.google.com with ESMTPSA id fc6sm3520943wib.12.2015.01.02.05.56.57 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 02 Jan 2015 05:56:57 -0800 (PST) From: Malcolm Priestley To: linux-media@vger.kernel.org Cc: Malcolm Priestley Subject: [PATCH 4/5] lmedm04: Create frontend call back for read status. Date: Fri, 2 Jan 2015 13:56:30 +0000 Message-Id: <1420206991-3939-4-git-send-email-tvboxspy@gmail.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1420206991-3939-1-git-send-email-tvboxspy@gmail.com> References: <1420206991-3939-1-git-send-email-tvboxspy@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 Create dm04_read_status to check lock through either interrupt values or directly by the call back. When the device is not streaming the frontends original call back is used. When streaming has started it turns off I2C messaging by setting st->i2c_talk_onoff to zero. I2C can only be turn on again by one of the other allowed frontend calls. All old code is removed from lme2510_msg and this function only needs to set st->i2c_talk_onoff to 1. The lock status is saved and when the frondend is locked is maintained by lme2510_int_response who will now just kill the lock. The call back for rs2000 tuner is nologer required. All frontend types have been tested. Signed-off-by: Malcolm Priestley --- drivers/media/usb/dvb-usb-v2/lmedm04.c | 205 ++++++++++----------------------- 1 file changed, 60 insertions(+), 145 deletions(-) diff --git a/drivers/media/usb/dvb-usb-v2/lmedm04.c b/drivers/media/usb/dvb-usb-v2/lmedm04.c index 55d7690..a9c7fd0 100644 --- a/drivers/media/usb/dvb-usb-v2/lmedm04.c +++ b/drivers/media/usb/dvb-usb-v2/lmedm04.c @@ -126,9 +126,9 @@ DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); struct lme2510_state { unsigned long int_urb_due; + fe_status_t lock_status; u8 id; u8 tuner_config; - u8 signal_lock; u8 signal_level; u8 signal_sn; u8 time_key; @@ -143,6 +143,8 @@ struct lme2510_state { void *buffer; struct urb *lme_urb; void *usb_buffer; + /* Frontend original calls */ + int (*fe_read_status)(struct dvb_frontend *, fe_status_t *); int (*fe_set_voltage)(struct dvb_frontend *, fe_sec_voltage_t); u8 dvb_usb_lme2510_firmware; }; @@ -258,6 +260,7 @@ static void lme2510_int_response(struct urb *lme_urb) static u8 *ibuf, *rbuf; int i = 0, offset; u32 key; + u8 signal_lock = 0; switch (lme_urb->status) { case 0: @@ -298,8 +301,7 @@ static void lme2510_int_response(struct urb *lme_urb) case 0xbb: switch (st->tuner_config) { case TUNER_LG: - if (ibuf[2] > 0) - st->signal_lock = ibuf[2]; + signal_lock = ibuf[2] & BIT(5); st->signal_level = ibuf[4]; st->signal_sn = ibuf[3]; st->time_key = ibuf[7]; @@ -308,29 +310,29 @@ static void lme2510_int_response(struct urb *lme_urb) case TUNER_S0194: /* Tweak for earlier firmware*/ if (ibuf[1] == 0x03) { - if (ibuf[2] > 1) - st->signal_lock = ibuf[2]; + signal_lock = ibuf[2] & BIT(4); st->signal_level = ibuf[3]; st->signal_sn = ibuf[4]; } else { st->signal_level = ibuf[4]; st->signal_sn = ibuf[5]; - st->signal_lock = - (st->signal_lock & 0xf7) + - ((ibuf[2] & 0x01) << 0x03); } break; case TUNER_RS2000: - if (ibuf[2] & 0x1) - st->signal_lock = 0xff; - else - st->signal_lock = 0x00; + signal_lock = ibuf[2] & 0xee; st->signal_level = ibuf[5]; st->signal_sn = ibuf[4]; st->time_key = ibuf[7]; default: break; } + + /* Interrupt will also throw just BIT 0 as lock */ + signal_lock |= ibuf[2] & BIT(0); + + if (!signal_lock) + st->lock_status &= ~FE_HAS_LOCK; + debug_data_snipet(5, "INT Remote data snipet in", ibuf); break; case 0xcc: @@ -457,124 +459,13 @@ static int lme2510_return_status(struct dvb_usb_device *d) static int lme2510_msg(struct dvb_usb_device *d, u8 *wbuf, int wlen, u8 *rbuf, int rlen) { - int ret = 0; struct lme2510_state *st = d->priv; - if (st->i2c_talk_onoff == 1) { - - ret = lme2510_usb_talk(d, wbuf, wlen, rbuf, rlen); - - switch (st->tuner_config) { - case TUNER_LG: - if (wbuf[2] == 0x1c) { - if (wbuf[3] == 0x0e) { - st->signal_lock = rbuf[1]; - if ((st->stream_on & 1) && - (st->signal_lock & 0x10)) { - lme2510_stream_restart(d); - st->i2c_talk_onoff = 0; - } - msleep(80); - } - } - break; - case TUNER_S7395: - if (wbuf[2] == 0xd0) { - if (wbuf[3] == 0x24) { - st->signal_lock = rbuf[1]; - if ((st->stream_on & 1) && - (st->signal_lock & 0x8)) { - lme2510_stream_restart(d); - st->i2c_talk_onoff = 0; - } - } - } - break; - case TUNER_S0194: - if (wbuf[2] == 0xd0) { - if (wbuf[3] == 0x1b) { - st->signal_lock = rbuf[1]; - if ((st->stream_on & 1) && - (st->signal_lock & 0x8)) { - lme2510_stream_restart(d); - st->i2c_talk_onoff = 0; - } - } - } - break; - case TUNER_RS2000: - default: - break; - } - } else { - /* TODO rewrite this section */ - switch (st->tuner_config) { - case TUNER_LG: - switch (wbuf[3]) { - case 0x0e: - rbuf[0] = 0x55; - rbuf[1] = st->signal_lock; - break; - default: - lme2510_usb_talk(d, wbuf, wlen, rbuf, rlen); - st->i2c_talk_onoff = 1; - break; - } - break; - case TUNER_S7395: - switch (wbuf[3]) { - case 0x24: - rbuf[0] = 0x55; - rbuf[1] = st->signal_lock; - break; - default: - lme2510_usb_talk(d, wbuf, wlen, rbuf, rlen); - st->i2c_talk_onoff = 1; - break; - } - break; - case TUNER_S0194: - switch (wbuf[3]) { - case 0x1b: - rbuf[0] = 0x55; - rbuf[1] = st->signal_lock; - break; - default: - lme2510_usb_talk(d, wbuf, wlen, rbuf, rlen); - st->i2c_talk_onoff = 1; - break; - } - break; - case TUNER_RS2000: - switch (wbuf[3]) { - case 0x8c: - rbuf[0] = 0x55; - rbuf[1] = st->signal_lock; - - /* If int_urb_due overdue - * set rbuf[1] to 0 to clear lock */ - if (time_after(jiffies, st->int_urb_due)) - rbuf[1] = 0; - - break; - default: - lme2510_usb_talk(d, wbuf, wlen, rbuf, rlen); - st->i2c_talk_onoff = 1; - break; - } - default: - break; - } - - deb_info(4, "I2C From Interrupt Message out(%02x) in(%02x)", - wbuf[3], rbuf[1]); - - } + st->i2c_talk_onoff = 1; - return ret; + return lme2510_usb_talk(d, wbuf, wlen, rbuf, rlen); } - static int lme2510_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num) { @@ -897,26 +788,8 @@ static struct stv0299_config sharp_z0194_config = { .set_symbol_rate = sharp_z0194a_set_symbol_rate, }; -static int dm04_rs2000_set_ts_param(struct dvb_frontend *fe, - int caller) -{ - struct dvb_usb_adapter *adap = fe_to_adap(fe); - struct dvb_usb_device *d = adap_to_d(adap); - struct lme2510_state *st = d->priv; - - mutex_lock(&d->i2c_mutex); - if ((st->i2c_talk_onoff == 1) && (st->stream_on & 1)) { - st->i2c_talk_onoff = 0; - lme2510_stream_restart(d); - } - mutex_unlock(&d->i2c_mutex); - - return 0; -} - static struct m88rs2000_config m88rs2000_config = { - .demod_addr = 0x68, - .set_ts_params = dm04_rs2000_set_ts_param, + .demod_addr = 0x68 }; static struct ts2020_config ts2020_config = { @@ -960,6 +833,46 @@ static int dm04_lme2510_set_voltage(struct dvb_frontend *fe, return (ret < 0) ? -ENODEV : 0; } +static int dm04_read_status(struct dvb_frontend *fe, fe_status_t *status) +{ + struct dvb_usb_device *d = fe_to_d(fe); + struct lme2510_state *st = d->priv; + int ret = 0; + + if (st->i2c_talk_onoff) { + if (st->fe_read_status) { + ret = st->fe_read_status(fe, status); + if (ret < 0) + return ret; + } + + st->lock_status = *status; + + if (*status & FE_HAS_LOCK && st->stream_on) { + mutex_lock(&d->i2c_mutex); + + st->i2c_talk_onoff = 0; + ret = lme2510_stream_restart(d); + + mutex_unlock(&d->i2c_mutex); + } + + return ret; + } + + /* Timeout of interrupt reached on RS2000 */ + if (st->tuner_config == TUNER_RS2000 && + time_after(jiffies, st->int_urb_due)) + st->lock_status &= ~FE_HAS_LOCK; + + *status = st->lock_status; + + if (!(*status & FE_HAS_LOCK)) + st->i2c_talk_onoff = 1; + + return ret; +} + static int dm04_read_signal_strength(struct dvb_frontend *fe, u16 *strength) { struct lme2510_state *st = fe_to_priv(fe); @@ -1122,6 +1035,9 @@ static int dm04_lme2510_frontend_attach(struct dvb_usb_adapter *adap) return -ENODEV; } + st->fe_read_status = adap->fe[0]->ops.read_status; + + adap->fe[0]->ops.read_status = dm04_read_status; adap->fe[0]->ops.read_signal_strength = dm04_read_signal_strength; adap->fe[0]->ops.read_snr = dm04_read_snr; adap->fe[0]->ops.read_ber = dm04_read_ber; @@ -1269,7 +1185,6 @@ static void *lme2510_exit_int(struct dvb_usb_device *d) if (st->usb_buffer != NULL) { st->i2c_talk_onoff = 1; - st->signal_lock = 0; st->signal_level = 0; st->signal_sn = 0; buffer = st->usb_buffer;