From patchwork Sat Feb 24 18:55:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scheller X-Patchwork-Id: 10240461 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 9B7AD602A0 for ; Sat, 24 Feb 2018 18:55:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D46529BE3 for ; Sat, 24 Feb 2018 18:55:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7FCE129BFC; Sat, 24 Feb 2018 18:55:50 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, 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 0C24E29BE3 for ; Sat, 24 Feb 2018 18:55:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751499AbeBXSzs (ORCPT ); Sat, 24 Feb 2018 13:55:48 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:53108 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751399AbeBXSzq (ORCPT ); Sat, 24 Feb 2018 13:55:46 -0500 Received: by mail-wm0-f66.google.com with SMTP id t3so10466085wmc.2 for ; Sat, 24 Feb 2018 10:55:45 -0800 (PST) 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=ur94Es1ILBMLT6Q+mAqQ6ZMFWJNyujDP2dfYewH4CwM=; b=qYzNMYVZ47wiUIxTv87oiIbvbNgV7uRxK3Cz+tIm0Vm/OerJ54d/CwNxDpagjHeBPA uDqOrsAlSDzVELP6Etf4H4FMCkBnEadeR5zMAUQm4pvMzqx4usnkpVpFSHWcDV0YASQ6 XwE6IYt4/OgzaOChfY12bnF+FgI89hgl2CjoyVEziTNSKt7mhFHMjjxnYj/1u4z+l2iY XsksuBgr7kOsO7UjxliAyVtR3OxD49rWozpYqX4UIh5eha2ufzeorZdW8P2RjzJ5z//3 doQh/bzM+x8ax/Nkn/x0ZUV59hUchD3pxVG3CoQjN705ohSnq87FUJQSuzPh0xStsOKG NARw== 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=ur94Es1ILBMLT6Q+mAqQ6ZMFWJNyujDP2dfYewH4CwM=; b=Y5Zzc/ENfYf5rx5YVvNXeH5s5r6yEDrqOKaa9bp4YQD8/bpMOSwgW45U8bL4I3mJLa qbiWMMqPGaG/UK259wTIHsgJRSvqKDHRq97WRnBXG6hTSdx85dYB2gIBvfEEfqlXCGVk O1IezbBKYCzEYMnGHuwYBVEN/Lmo4yeUGKuFu22XQbuO/fh4gZz3uaNdtaJyb//3sXQk NHNVxXfzVJjXEQNbzdL44LgJjvSd0CMZjBumMQf+pRVS1izpNaMzdfkk6u7GjfT2p7N5 pds5oZXuQukBQ1rSxwiKX0AAcGV75/zzc35YcUiXStkJW6Kfgten6pIckS3+PYkg39uU BAtQ== X-Gm-Message-State: APf1xPC8LpXC5F3yTAh2S80I+M/C9xnp+Fc1HPrJAr1tvrCcR6iC9XYN wTSlbvArITTYnHKNJpzFFZMNAA== X-Google-Smtp-Source: AH8x224WTE7+w4PLLpJmWPJ41dtSlnk5NDI4MukPDYgyYzndueXFY7ncD51+e+VjtZCf1+U5fQLQNg== X-Received: by 10.28.93.80 with SMTP id r77mr4356089wmb.73.1519498544581; Sat, 24 Feb 2018 10:55:44 -0800 (PST) Received: from dvbdev.wuest.de (ip-84-118-193-200.unity-media.net. [84.118.193.200]) by smtp.gmail.com with ESMTPSA id 3sm526270wry.29.2018.02.24.10.55.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 24 Feb 2018 10:55:44 -0800 (PST) From: Daniel Scheller To: linux-media@vger.kernel.org, mchehab@kernel.org, mchehab@s-opensource.com Subject: [PATCH 08/12] [media] ngene: deduplicate I2C adapter evaluation Date: Sat, 24 Feb 2018 19:55:30 +0100 Message-Id: <20180224185534.13792-9-d.scheller.oss@gmail.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180224185534.13792-1-d.scheller.oss@gmail.com> References: <20180224185534.13792-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 The I2C adapter evaluation (based on chan->number) is duplicated at several places (tuner_attach_() functions, demod_attach_stv0900() and cineS2_probe()). Clean this up by wrapping that construct in a separate function which all users of that can pass the ngene_channel pointer and get the correct I2C adapter from. Signed-off-by: Daniel Scheller --- drivers/media/pci/ngene/ngene-cards.c | 41 +++++++++++++---------------------- 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/drivers/media/pci/ngene/ngene-cards.c b/drivers/media/pci/ngene/ngene-cards.c index 00b100660784..dff55c7c9f86 100644 --- a/drivers/media/pci/ngene/ngene-cards.c +++ b/drivers/media/pci/ngene/ngene-cards.c @@ -118,17 +118,25 @@ static int i2c_read_reg(struct i2c_adapter *adapter, u8 adr, u8 reg, u8 *val) /* Demod/tuner attachment ***************************************************/ /****************************************************************************/ +static struct i2c_adapter *i2c_adapter_from_chan(struct ngene_channel *chan) +{ + /* tuner 1+2: i2c adapter #0, tuner 3+4: i2c adapter #1 */ + if (chan->number < 2) + return &chan->dev->channel[0].i2c_adapter; + + return &chan->dev->channel[1].i2c_adapter; +} + static int tuner_attach_stv6110(struct ngene_channel *chan) { struct device *pdev = &chan->dev->pci_dev->dev; - struct i2c_adapter *i2c; + struct i2c_adapter *i2c = i2c_adapter_from_chan(chan); struct stv090x_config *feconf = (struct stv090x_config *) chan->dev->card_info->fe_config[chan->number]; struct stv6110x_config *tunerconf = (struct stv6110x_config *) chan->dev->card_info->tuner_config[chan->number]; const struct stv6110x_devctl *ctl; - /* tuner 1+2: i2c adapter #0, tuner 3+4: i2c adapter #1 */ if (chan->number < 2) i2c = &chan->dev->channel[0].i2c_adapter; else @@ -158,16 +166,10 @@ static int tuner_attach_stv6110(struct ngene_channel *chan) static int tuner_attach_stv6111(struct ngene_channel *chan) { struct device *pdev = &chan->dev->pci_dev->dev; - struct i2c_adapter *i2c; + struct i2c_adapter *i2c = i2c_adapter_from_chan(chan); struct dvb_frontend *fe; u8 adr = 4 + ((chan->number & 1) ? 0x63 : 0x60); - /* tuner 1+2: i2c adapter #0, tuner 3+4: i2c adapter #1 */ - if (chan->number < 2) - i2c = &chan->dev->channel[0].i2c_adapter; - else - i2c = &chan->dev->channel[1].i2c_adapter; - fe = dvb_attach(stv6111_attach, chan->fe, i2c, adr); if (!fe) { fe = dvb_attach(stv6111_attach, chan->fe, i2c, adr & ~4); @@ -197,10 +199,9 @@ static int drxk_gate_ctrl(struct dvb_frontend *fe, int enable) static int tuner_attach_tda18271(struct ngene_channel *chan) { struct device *pdev = &chan->dev->pci_dev->dev; - struct i2c_adapter *i2c; + struct i2c_adapter *i2c = i2c_adapter_from_chan(chan); struct dvb_frontend *fe; - i2c = &chan->dev->channel[0].i2c_adapter; if (chan->fe->ops.i2c_gate_ctrl) chan->fe->ops.i2c_gate_ctrl(chan->fe, 1); fe = dvb_attach(tda18271c2dd_attach, chan->fe, i2c, 0x60); @@ -240,7 +241,7 @@ static int tuner_tda18212_ping(struct ngene_channel *chan, static int tuner_attach_tda18212(struct ngene_channel *chan, u32 dmdtype) { struct device *pdev = &chan->dev->pci_dev->dev; - struct i2c_adapter *i2c; + struct i2c_adapter *i2c = i2c_adapter_from_chan(chan); struct i2c_client *client; struct tda18212_config config = { .fe = chan->fe, @@ -262,12 +263,6 @@ static int tuner_attach_tda18212(struct ngene_channel *chan, u32 dmdtype) else board_info.addr = 0x60; - /* tuner 1+2: i2c adapter #0, tuner 3+4: i2c adapter #1 */ - if (chan->number < 2) - i2c = &chan->dev->channel[0].i2c_adapter; - else - i2c = &chan->dev->channel[1].i2c_adapter; - /* * due to a hardware quirk with the I2C gate on the stv0367+tda18212 * combo, the tda18212 must be probed by reading it's id _twice_ when @@ -320,7 +315,7 @@ static int tuner_attach_probe(struct ngene_channel *chan) static int demod_attach_stv0900(struct ngene_channel *chan) { struct device *pdev = &chan->dev->pci_dev->dev; - struct i2c_adapter *i2c; + struct i2c_adapter *i2c = i2c_adapter_from_chan(chan); struct stv090x_config *feconf = (struct stv090x_config *) chan->dev->card_info->fe_config[chan->number]; @@ -620,7 +615,7 @@ static int port_has_xo2(struct i2c_adapter *i2c, u8 *type, u8 *id) static int cineS2_probe(struct ngene_channel *chan) { struct device *pdev = &chan->dev->pci_dev->dev; - struct i2c_adapter *i2c; + struct i2c_adapter *i2c = i2c_adapter_from_chan(chan); struct stv090x_config *fe_conf; u8 buf[3]; u8 xo2_type, xo2_id, xo2_demodtype; @@ -628,12 +623,6 @@ static int cineS2_probe(struct ngene_channel *chan) struct i2c_msg i2c_msg = { .flags = 0, .buf = buf }; int rc; - /* tuner 1+2: i2c adapter #0, tuner 3+4: i2c adapter #1 */ - if (chan->number < 2) - i2c = &chan->dev->channel[0].i2c_adapter; - else - i2c = &chan->dev->channel[1].i2c_adapter; - if (port_has_xo2(i2c, &xo2_type, &xo2_id)) { xo2_id >>= 2; dev_dbg(pdev, "XO2 on channel %d (type %d, id %d)\n",