From patchwork Fri Mar 24 18:23:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scheller X-Patchwork-Id: 9643699 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 92E52602C9 for ; Fri, 24 Mar 2017 18:26:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 88E1F26CF9 for ; Fri, 24 Mar 2017 18:26:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7C9B926E56; Fri, 24 Mar 2017 18:26:01 +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 1EB7B26CF9 for ; Fri, 24 Mar 2017 18:26:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754597AbdCXSZ7 (ORCPT ); Fri, 24 Mar 2017 14:25:59 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:33070 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935497AbdCXSZr (ORCPT ); Fri, 24 Mar 2017 14:25:47 -0400 Received: by mail-wm0-f68.google.com with SMTP id n11so2235698wma.0 for ; Fri, 24 Mar 2017 11:25:46 -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=dyp/r6BpcRwIzXR0kWsbmDYfTekb4vMhWflrbZWtAqE=; b=nCuCuX4/xFNBYgE/va76u1Xxa2JCsTjFchxgCSbSKXXkIJJRkZfK2O7gbKex0akYrU o5h1CJ7M2ftlnl0z7jzwwQKrMALmnGyGPDTaZxn0sKBl2EK4FxisePrTHzobMZ4CAzcF Q6GFzkieoJRzUg4i7UGzcemSvOn6cu49w+njsmt8dcqNaQyQu/mAA5JuvLPtP0anCOrE YB6n+trLtjSjs+47Bd7v78HvW41PA7j+EmmiQDEW46Av7RPVywlcfv8mUZRecER3JSPl bny7lR5V0vHMMKCJuCxPCNxLdA68obUqp/Igb/EmluC5eKIRoMQQtFOS3gOfrzNP70se p0hw== 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=dyp/r6BpcRwIzXR0kWsbmDYfTekb4vMhWflrbZWtAqE=; b=bpGEYFctNhxNGtYDCOotgbn1EvQtCI0M4SZoceNKTjc0RqhErd9aaGV1CoMrtesdOj F96gONnjvmTKmKfDpYh1Lg4VBY0bDFaLha7rOMXNlCRDtUA8a1vMbgKWBYNJBgVdAaki tC2pNbT7HZR400dPJN9Pn8cD40ZL23t51IIEUsGa+unqN1I+DBXvSvhJBilousOK0Hyd WCX0U1GRqkmQ/GMMTZmiwBYZnhN0QJbcjTdDk1Nt08SIvpgQ+2ZxfqMhcvnIZ/94RHHU y6HuGgvRrOo8TTj0744wUnmDZLcFGCwAg0hcf4iIO0N4InRpT63FISbE5b6JP82RaHhP qoYg== X-Gm-Message-State: AFeK/H2235nhjE5KBO6ofhDryXYCgnJEYnrVYVMQSbrmZpKEOPE/MaAm7bqbGF9fXUWdFg== X-Received: by 10.28.16.149 with SMTP id 143mr4265545wmq.42.1490379940278; Fri, 24 Mar 2017 11:25:40 -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.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 24 Mar 2017 11:25:39 -0700 (PDT) From: Daniel Scheller To: mchehab@kernel.org, linux-media@vger.kernel.org Subject: [PATCH v2 03/12] [media] dvb-frontends/stv0367: refactor defaults table handling Date: Fri, 24 Mar 2017 19:23:59 +0100 Message-Id: <20170324182408.25996-4-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 Change defaults table writing so tables can be of dynamic length without having to keep track of their lengths by adding and evaluating an end marker (reg 0x0000), also move table writing to a dedicated function to remove code duplication. Additionally mark st_register tables const since they're used read-only. Signed-off-by: Daniel Scheller --- drivers/media/dvb-frontends/stv0367.c | 30 ++++++++++++++++++++---------- drivers/media/dvb-frontends/stv0367_regs.h | 4 ---- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/drivers/media/dvb-frontends/stv0367.c b/drivers/media/dvb-frontends/stv0367.c index 0064d9d..5ed52ec 100644 --- a/drivers/media/dvb-frontends/stv0367.c +++ b/drivers/media/dvb-frontends/stv0367.c @@ -99,7 +99,7 @@ struct st_register { }; /* values for STV4100 XTAL=30M int clk=53.125M*/ -static struct st_register def0367ter[STV0367TER_NBREGS] = { +static const struct st_register def0367ter[] = { {R367TER_ID, 0x60}, {R367TER_I2CRPT, 0xa0}, /* {R367TER_I2CRPT, 0x22},*/ @@ -546,6 +546,7 @@ static struct st_register def0367ter[STV0367TER_NBREGS] = { {R367TER_DEBUG_LT7, 0x00}, {R367TER_DEBUG_LT8, 0x00}, {R367TER_DEBUG_LT9, 0x00}, + {0x0000, 0x00}, }; #define RF_LOOKUP_TABLE_SIZE 31 @@ -573,7 +574,7 @@ static const s32 stv0367cab_RF_LookUp2[RF_LOOKUP_TABLE2_SIZE][RF_LOOKUP_TABLE2_S } }; -static struct st_register def0367cab[STV0367CAB_NBREGS] = { +static const struct st_register def0367cab[] = { {R367CAB_ID, 0x60}, {R367CAB_I2CRPT, 0xa0}, /*{R367CAB_I2CRPT, 0x22},*/ @@ -762,6 +763,7 @@ static struct st_register def0367cab[STV0367CAB_NBREGS] = { {R367CAB_T_O_ID_1, 0x00}, {R367CAB_T_O_ID_2, 0x00}, {R367CAB_T_O_ID_3, 0x00}, + {0x0000, 0x00}, }; static @@ -901,6 +903,20 @@ static u8 stv0367_getbits(u8 reg, u32 label) return (reg & mask) >> pos; } #endif + +static void stv0367_write_table(struct stv0367_state *state, + const struct st_register *deftab) +{ + int i = 0; + + while (1) { + if (!deftab[i].addr) + break; + stv0367_writereg(state, deftab[i].addr, deftab[i].value); + i++; + } +} + static int stv0367ter_gate_ctrl(struct dvb_frontend *fe, int enable) { struct stv0367_state *state = fe->demodulator_priv; @@ -1540,15 +1556,12 @@ static int stv0367ter_init(struct dvb_frontend *fe) { struct stv0367_state *state = fe->demodulator_priv; struct stv0367ter_state *ter_state = state->ter_state; - int i; dprintk("%s:\n", __func__); ter_state->pBER = 0; - for (i = 0; i < STV0367TER_NBREGS; i++) - stv0367_writereg(state, def0367ter[i].addr, - def0367ter[i].value); + stv0367_write_table(state, def0367ter); switch (state->config->xtal) { /*set internal freq to 53.125MHz */ @@ -2782,13 +2795,10 @@ static int stv0367cab_init(struct dvb_frontend *fe) { struct stv0367_state *state = fe->demodulator_priv; struct stv0367cab_state *cab_state = state->cab_state; - int i; dprintk("%s:\n", __func__); - for (i = 0; i < STV0367CAB_NBREGS; i++) - stv0367_writereg(state, def0367cab[i].addr, - def0367cab[i].value); + stv0367_write_table(state, def0367cab); switch (state->config->ts_mode) { case STV0367_DVBCI_CLOCK: diff --git a/drivers/media/dvb-frontends/stv0367_regs.h b/drivers/media/dvb-frontends/stv0367_regs.h index 1d15862..cc66d93 100644 --- a/drivers/media/dvb-frontends/stv0367_regs.h +++ b/drivers/media/dvb-frontends/stv0367_regs.h @@ -2639,8 +2639,6 @@ #define R367TER_DEBUG_LT9 0xf405 #define F367TER_F_DEBUG_LT9 0xf40500ff -#define STV0367TER_NBREGS 445 - /* ID */ #define R367CAB_ID 0xf000 #define F367CAB_IDENTIFICATIONREGISTER 0xf00000ff @@ -3605,6 +3603,4 @@ #define R367CAB_T_O_ID_3 0xf4d3 #define F367CAB_TS_ID_I_H 0xf4d300ff -#define STV0367CAB_NBREGS 187 - #endif