From patchwork Fri Mar 24 18:24:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scheller X-Patchwork-Id: 9643709 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 D74EC602C9 for ; Fri, 24 Mar 2017 18:26:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CB13E26907 for ; Fri, 24 Mar 2017 18:26:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BF04126E51; Fri, 24 Mar 2017 18:26:15 +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.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM 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 3E43826907 for ; Fri, 24 Mar 2017 18:26:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755774AbdCXS0O (ORCPT ); Fri, 24 Mar 2017 14:26:14 -0400 Received: from mail-wr0-f195.google.com ([209.85.128.195]:33873 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752197AbdCXSZu (ORCPT ); Fri, 24 Mar 2017 14:25:50 -0400 Received: by mail-wr0-f195.google.com with SMTP id y90so1595998wrb.1 for ; Fri, 24 Mar 2017 11:25:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=RnaxNg7BhmSxUyWc0XWSu3bIbE03wTgqzoB53yh6b/E=; b=n2DYYvsHQVB9Pb+atxgMhWuY4akLNBfPJ3s71nYgIbx3Ok0KbLQ3y52wtF+VwSPkb0 tnEVBfAs/9g3lHlVwQOHagQEKgNtPEtwQ4b7t7fG2jIKCayUqaTE+s22sYlp7EaUEakM YtOPYF3EINPkRGGY5zbcqHWvXesstk8ZtgDbcr9gqaK2SX3P7TP3KZXS1wJadgvupR+3 iHnYcdnr+0jz+2v0mhALsNIGlYXC/FjY2JBI7DuhS6v+5H4lGdzr/Akho9GwThohl1PO MqIR69skfIuQwo0PSKc/aWQ9T3Zv+niU0XKVBdv0Ulz6egyKRXNrMhpFX51WVhFF9AgQ mV0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=RnaxNg7BhmSxUyWc0XWSu3bIbE03wTgqzoB53yh6b/E=; b=nACUox4SyBjl+E6LsQUSFxIwDzy/Ed6vmPHRTET58N9OKggZr4b2/ZTpe2vYLN06Xs R7xCVzG5UgcFPFtTDXap7cqsziOZi4+Dp1ItVd8kOg3ZKxFP8SfDJmbih0do+sEoqq7J QfK1Je/9Sv/fUdz3M2F1QEAFNqvodzh+ktR0VZxep6SUG/Cvh8AIrsznRzAYECvJtANb kHijXpOyTuFt5UknRYv2BlNVrFgC95S4STWrho/9Jn/oQmoOMQr+aQmKWr2XeOPLh0LC 3H/QqIW4DfeygktzhG6bKn/NY74Jc38GWjRQAkh7itT789pe1avAVWcbBwsFjwI/E2S2 sP9w== X-Gm-Message-State: AFeK/H0LdaUrcact8NhGWAOs6hj5cPpKe7sLvSdc2217BgCLNDbzCrYQP2tyvvdpHrQ5AA== X-Received: by 10.223.138.139 with SMTP id y11mr8492585wry.190.1490379943733; Fri, 24 Mar 2017 11:25:43 -0700 (PDT) Received: from dvbdev.wuest.de (ip-37-24-178-151.hsi14.unitymediagroup.de. [37.24.178.151]) by smtp.gmail.com with ESMTPSA id w12sm3830519wra.21.2017.03.24.11.25.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 24 Mar 2017 11:25:43 -0700 (PDT) From: Daniel Scheller To: mchehab@kernel.org, linux-media@vger.kernel.org Subject: [PATCH v2 07/12] [media] dvb-frontends/stv0367: support reading if_khz from tuner config Date: Fri, 24 Mar 2017 19:24:03 +0100 Message-Id: <20170324182408.25996-8-d.scheller.oss@gmail.com> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20170324182408.25996-1-d.scheller.oss@gmail.com> References: <20170324182408.25996-1-d.scheller.oss@gmail.com> 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 From: Daniel Scheller Currently, if_khz is set and provided using the configuration var in struct stv0367_config. However, in some constellations, the value might be different for differing channel bandwidths or even -T and -C operation. When e.g. used in conjunction with TDA18212 tuners, the tuner frontend might be aware of the different freqs. This factors if_khz retrieval in a function, which checks a new flag if an automatic retrieval attempt should be made, and if the tuner provides it, use it whenever needed. Signed-off-by: Daniel Scheller --- drivers/media/dvb-frontends/stv0367.c | 45 +++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/drivers/media/dvb-frontends/stv0367.c b/drivers/media/dvb-frontends/stv0367.c index 9370afa..74fee3f 100644 --- a/drivers/media/dvb-frontends/stv0367.c +++ b/drivers/media/dvb-frontends/stv0367.c @@ -94,6 +94,7 @@ struct stv0367_state { u8 use_i2c_gatectrl; u8 deftabs; u8 reinit_on_setfrontend; + u8 auto_if_khz; }; #define RF_LOOKUP_TABLE_SIZE 31 @@ -319,6 +320,17 @@ static void stv0367_pll_setup(struct stv0367_state *state, stv0367_writereg(state, R367TER_PLLSETUP, 0x18); } +static int stv0367_get_if_khz(struct stv0367_state *state, u32 *ifkhz) +{ + if (state->auto_if_khz && state->fe.ops.tuner_ops.get_if_frequency) { + state->fe.ops.tuner_ops.get_if_frequency(&state->fe, ifkhz); + *ifkhz = *ifkhz / 1000; /* hz -> khz */ + } else + *ifkhz = state->config->if_khz; + + return 0; +} + static int stv0367ter_gate_ctrl(struct dvb_frontend *fe, int enable) { struct stv0367_state *state = fe->demodulator_priv; @@ -992,10 +1004,12 @@ static int stv0367ter_algo(struct dvb_frontend *fe) u8 /*constell,*/ counter; s8 step; s32 timing_offset = 0; - u32 trl_nomrate = 0, InternalFreq = 0, temp = 0; + u32 trl_nomrate = 0, InternalFreq = 0, temp = 0, ifkhz = 0; dprintk("%s:\n", __func__); + stv0367_get_if_khz(state, &ifkhz); + ter_state->frequency = p->frequency; ter_state->force = FE_TER_FORCENONE + stv0367_readbits(state, F367TER_FORCE) * 2; @@ -1098,8 +1112,7 @@ static int stv0367ter_algo(struct dvb_frontend *fe) stv0367_readbits(state, F367TER_GAIN_SRC_LO); temp = (int) - ((InternalFreq - state->config->if_khz) * (1 << 16) - / (InternalFreq)); + ((InternalFreq - ifkhz) * (1 << 16) / (InternalFreq)); dprintk("DEROT temp=0x%x\n", temp); stv0367_writebits(state, F367TER_INC_DEROT_HI, temp / 256); @@ -1720,6 +1733,7 @@ struct dvb_frontend *stv0367ter_attach(const struct stv0367_config *config, state->use_i2c_gatectrl = 1; state->deftabs = STV0367_DEFTAB_GENERIC; state->reinit_on_setfrontend = 1; + state->auto_if_khz = 0; dprintk("%s: chip_id = 0x%x\n", __func__, state->chip_id); @@ -2229,7 +2243,7 @@ enum stv0367_cab_signal_type stv0367cab_algo(struct stv0367_state *state, { struct stv0367cab_state *cab_state = state->cab_state; enum stv0367_cab_signal_type signalType = FE_CAB_NOAGC; - u32 QAMFEC_Lock, QAM_Lock, u32_tmp, + u32 QAMFEC_Lock, QAM_Lock, u32_tmp, ifkhz, LockTime, TRLTimeOut, AGCTimeOut, CRLSymbols, CRLTimeOut, EQLTimeOut, DemodTimeOut, FECTimeOut; u8 TrackAGCAccum; @@ -2237,6 +2251,8 @@ enum stv0367_cab_signal_type stv0367cab_algo(struct stv0367_state *state, dprintk("%s:\n", __func__); + stv0367_get_if_khz(state, &ifkhz); + /* Timeouts calculation */ /* A max lock time of 25 ms is allowed for delayed AGC */ AGCTimeOut = 25; @@ -2315,7 +2331,7 @@ enum stv0367_cab_signal_type stv0367cab_algo(struct stv0367_state *state, /* The sweep function is never used, Sweep rate must be set to 0 */ /* Set the derotator frequency in Hz */ stv0367cab_set_derot_freq(state, cab_state->adc_clk, - (1000 * (s32)state->config->if_khz + cab_state->derot_offset)); + (1000 * (s32)ifkhz + cab_state->derot_offset)); /* Disable the Allpass Filter when the symbol rate is out of range */ if ((p->symbol_rate > 10800000) | (p->symbol_rate < 1800000)) { stv0367_writebits(state, F367CAB_ADJ_EN, 0); @@ -2405,17 +2421,17 @@ enum stv0367_cab_signal_type stv0367cab_algo(struct stv0367_state *state, F367CAB_QUAD_INV); #if 0 /* not clear for me */ - if (state->config->if_khz != 0) { - if (state->config->if_khz > cab_state->adc_clk / 1000) { + if (ifkhz != 0) { + if (ifkhz > cab_state->adc_clk / 1000) { cab_state->freq_khz = FE_Cab_TunerGetFrequency(pIntParams->hTuner) - stv0367cab_get_derot_freq(state, cab_state->adc_clk) - - cab_state->adc_clk / 1000 + state->config->if_khz; + - cab_state->adc_clk / 1000 + ifkhz; } else { cab_state->freq_khz = FE_Cab_TunerGetFrequency(pIntParams->hTuner) - stv0367cab_get_derot_freq(state, cab_state->adc_clk) - + state->config->if_khz; + + ifkhz; } } else { cab_state->freq_khz = @@ -2546,11 +2562,13 @@ static int stv0367cab_get_frontend(struct dvb_frontend *fe, { struct stv0367_state *state = fe->demodulator_priv; struct stv0367cab_state *cab_state = state->cab_state; + u32 ifkhz = 0; enum stv0367cab_mod QAMSize; dprintk("%s:\n", __func__); + stv0367_get_if_khz(state, &ifkhz); p->symbol_rate = stv0367cab_GetSymbolRate(state, cab_state->mclk); QAMSize = stv0367_readbits(state, F367CAB_QAM_MODE); @@ -2578,19 +2596,19 @@ static int stv0367cab_get_frontend(struct dvb_frontend *fe, dprintk("%s: tuner frequency = %d\n", __func__, p->frequency); - if (state->config->if_khz == 0) { + if (ifkhz == 0) { p->frequency += (stv0367cab_get_derot_freq(state, cab_state->adc_clk) - cab_state->adc_clk / 4000); return 0; } - if (state->config->if_khz > cab_state->adc_clk / 1000) - p->frequency += (state->config->if_khz + if (ifkhz > cab_state->adc_clk / 1000) + p->frequency += (ifkhz - stv0367cab_get_derot_freq(state, cab_state->adc_clk) - cab_state->adc_clk / 1000); else - p->frequency += (state->config->if_khz + p->frequency += (ifkhz - stv0367cab_get_derot_freq(state, cab_state->adc_clk)); return 0; @@ -2840,6 +2858,7 @@ struct dvb_frontend *stv0367cab_attach(const struct stv0367_config *config, state->use_i2c_gatectrl = 1; state->deftabs = STV0367_DEFTAB_GENERIC; state->reinit_on_setfrontend = 1; + state->auto_if_khz = 0; dprintk("%s: chip_id = 0x%x\n", __func__, state->chip_id);