From patchwork Sun Feb 25 12:31:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scheller X-Patchwork-Id: 10240853 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 7F772603B4 for ; Sun, 25 Feb 2018 12:32:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 72DD029CBE for ; Sun, 25 Feb 2018 12:32:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 67A7929CE4; Sun, 25 Feb 2018 12:32:02 +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 E426E29CBE for ; Sun, 25 Feb 2018 12:32:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751763AbeBYMb7 (ORCPT ); Sun, 25 Feb 2018 07:31:59 -0500 Received: from mail-wm0-f65.google.com ([74.125.82.65]:33029 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751775AbeBYMbw (ORCPT ); Sun, 25 Feb 2018 07:31:52 -0500 Received: by mail-wm0-f65.google.com with SMTP id s206so13202675wme.0 for ; Sun, 25 Feb 2018 04:31:52 -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=hPxlI9PNY9dAR0CAG4ZB2M3rhj9CsAX8XFScfy1O8FkNOhqaXGW3cwlszPkK6ufKGn 6H1NXdY4bo2fnXtL9dg9B4ZOz7A30ufU1D5V2u1TheGbDmkpnukeV6AL5h6x/+esy5Wk X5FvvCwLQ2C05xolmR8g+VAOm92c4R076QP4VAUXyKyF6srVvoV8RyUKehyzsAo5rgBY hBylTSbEsoJBbW7tsdpMTPlKJ04SfzEWyuNYKJRrG3Q54Hbc++iah8m1jDtxzASN5GEF GhuIobUiPIQ8y/5OY5oCFQKtmquWctEe8uatkB+LJSl2yAaPpNEDTmUUTS43608jNBTU ELeg== 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=tOh73vTCzUXCdcZFtRwRtiXJ4y2wr023E3NuCubtAQeMS4wLfQsYVLdT4s2EdBnrK1 GtCbLgbAMAM6ByeyIbKLK/F7Xm5C+UnxshQqtGT27+nkwGCQThDZJQCQKSJJ6nSJfbik zne2AKfEOuefaYLcK6JyTXqvIOME8dLp76f43SM7sVc05AkNeU+XEDpklb9Abh7BWi7m 56sUDk5CZetwh10dYCoZBTtCzwtfBvnjBvyyLZRrzuuy9WuOacIkKCTUfssZzUMXUeQi kAOy21z0jQyEIdw2NMX7xF+yQyTJ9JLA3404xDkFvvgyMUQl3aA52CEOwsP6jW608NUY Kpuw== X-Gm-Message-State: APf1xPCyT1CG0XXqkdfMoZ6D3wkUUConJlpYEl6waBgA5rql33bto00j dtdZvKunRg1lKoDuC1fNtO4Raw== X-Google-Smtp-Source: AG47ELsRv2i2DA409dqvbzOLVY6NoLzkJOtzJCZgI5Yv4zDKSyO0OYLKFSOAaGzJdlf/JQYxwV3I6Q== X-Received: by 10.28.150.138 with SMTP id y132mr858247wmd.104.1519561911011; Sun, 25 Feb 2018 04:31:51 -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 y34sm15304779wry.19.2018.02.25.04.31.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 25 Feb 2018 04:31:50 -0800 (PST) From: Daniel Scheller To: linux-media@vger.kernel.org, mchehab@kernel.org, mchehab@s-opensource.com Subject: [PATCH v2 08/12] [media] ngene: deduplicate I2C adapter evaluation Date: Sun, 25 Feb 2018 13:31:36 +0100 Message-Id: <20180225123140.19486-9-d.scheller.oss@gmail.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180225123140.19486-1-d.scheller.oss@gmail.com> References: <20180225123140.19486-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",