From patchwork Wed Mar 7 19:23:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scheller X-Patchwork-Id: 10264775 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 3BEF2602C8 for ; Wed, 7 Mar 2018 19:24:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2B14128ED1 for ; Wed, 7 Mar 2018 19:24:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1F7BF29119; Wed, 7 Mar 2018 19:24:10 +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 A685528ED1 for ; Wed, 7 Mar 2018 19:24:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754698AbeCGTYA (ORCPT ); Wed, 7 Mar 2018 14:24:00 -0500 Received: from mail-wr0-f194.google.com ([209.85.128.194]:36716 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754706AbeCGTX7 (ORCPT ); Wed, 7 Mar 2018 14:23:59 -0500 Received: by mail-wr0-f194.google.com with SMTP id v111so3334405wrb.3 for ; Wed, 07 Mar 2018 11:23:58 -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=OC95a3g1CU2MDNmv5n92mTXjhuerKvoHV1BYikG6LRY=; b=tWmDsJhikjqwqfWNhywLEpZHrbAHr81ei/cBF2BwpXOjTA5R2pUTs6ZxuK+lxFkKIm OIgSnDZavwZ5dy78812zDpHn7INUhB8MXRvoyMNksGKUgDLZkkdmcSs1zGCQScI3Rcao rpApZH49TgrEEjs8JyV3njrDBY4mOBFy5wkngEKaPuyFKnzFTVdkBxK2biA735BBcDqm Lsea31wRhpIyoGJiCyDsSrPuTNss3Q0v728Pp8vzJKVo/cSUvXDZpyw7PdYux7El1T+Y BHX4TlnKrsc08n2sUdZHNRF/AdP/rST02GPtzCMbfQ/ui5CWbgPHp6o4PltSx7nOWOh4 7+zA== 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=OC95a3g1CU2MDNmv5n92mTXjhuerKvoHV1BYikG6LRY=; b=ASBDxsDt/hdnH9sCsYdnUrnkPPQ1IPjh/fvJPQ0FzZRsK4gI08o53JSC+5mkEmUx+B yr5g71diX/sFuE2qFIZNzuOAR7KYPK5eH3WPYelK5EW0pmgS9LtlZdpOpXwRtCnKffFf /+aNO0StOJS+z1KTOfHPhe9CwK0ZhBXzEDiHDTRFQ7Kr7vZfcN6lhbxRKzAaAio5iG0t fEwF62cxCOUilcPPmB8WZGY5pbc/l5jU3/9tMhSnRHmkGoUDGAOBhESkMeg2SnHA21Mo zeMtmWhKV1y6ahYaLSep4Nt3wNPoI5xQzn8IffsYhDvZSIgAY8VjcMotOwZ2aLgMJ2gg Iw8Q== X-Gm-Message-State: APf1xPBqDTvcXgJYtcFKdxfdTmBiqLbXzQzmaBQsDzlSmBy52cvoYEO9 fTQK07cFURfbpWI7ff8o2I2nDg== X-Google-Smtp-Source: AG47ELvsOxovtJX+ib6H86Kp2CpHgza2aLDihRdHYTQeenRAE9Ek50tERb6fr3DoRL3/iKgFxMw6tA== X-Received: by 10.223.178.232 with SMTP id g95mr21701345wrd.35.1520450637461; Wed, 07 Mar 2018 11:23:57 -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 k11sm23031210wre.81.2018.03.07.11.23.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Mar 2018 11:23:56 -0800 (PST) From: Daniel Scheller To: linux-media@vger.kernel.org, mchehab@kernel.org, mchehab@s-opensource.com Subject: [PATCH 4/4] [media] ngene: use common DVB I2C client handling helpers Date: Wed, 7 Mar 2018 20:23:50 +0100 Message-Id: <20180307192350.930-5-d.scheller.oss@gmail.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180307192350.930-1-d.scheller.oss@gmail.com> References: <20180307192350.930-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 Like in ddbridge, get rid of all duplicated I2C client handling constructs and rather make use of the newly added dvb_module_*() helpers. Makes things more clean and removes the (cosmetic) need for some variables. The check on a valid ptr on ci->en isn't really needed since the cxd2099 driver will set it at a time where it is going to return successfully from probing. Signed-off-by: Daniel Scheller --- drivers/media/pci/ngene/ngene-cards.c | 25 ++++---------------- drivers/media/pci/ngene/ngene-core.c | 43 ++++++++--------------------------- 2 files changed, 15 insertions(+), 53 deletions(-) diff --git a/drivers/media/pci/ngene/ngene-cards.c b/drivers/media/pci/ngene/ngene-cards.c index 37e9f0eb6d20..3ae7da2e9858 100644 --- a/drivers/media/pci/ngene/ngene-cards.c +++ b/drivers/media/pci/ngene/ngene-cards.c @@ -253,15 +253,7 @@ static int tuner_attach_tda18212(struct ngene_channel *chan, u32 dmdtype) .if_dvbt2_8 = 4000, .if_dvbc = 5000, }; - struct i2c_board_info board_info = { - .type = "tda18212", - .platform_data = &config, - }; - - if (chan->number & 1) - board_info.addr = 0x63; - else - board_info.addr = 0x60; + u8 addr = (chan->number & 1) ? 0x63 : 0x60; /* * due to a hardware quirk with the I2C gate on the stv0367+tda18212 @@ -269,20 +261,13 @@ static int tuner_attach_tda18212(struct ngene_channel *chan, u32 dmdtype) * cold started, or it very likely will fail. */ if (dmdtype == DEMOD_TYPE_STV0367) - tuner_tda18212_ping(chan, i2c, board_info.addr); - - request_module(board_info.type); + tuner_tda18212_ping(chan, i2c, addr); - /* perform tuner init/attach */ - client = i2c_new_device(i2c, &board_info); - if (!client || !client->dev.driver) + /* perform tuner probe/init/attach */ + client = dvb_module_probe("tda18212", "tda18212", i2c, addr, &config); + if (!client) goto err; - if (!try_module_get(client->dev.driver->owner)) { - i2c_unregister_device(client); - goto err; - } - chan->i2c_client[0] = client; chan->i2c_client_fe = 1; diff --git a/drivers/media/pci/ngene/ngene-core.c b/drivers/media/pci/ngene/ngene-core.c index f69a8fc1ec2a..bef3c9fd75ce 100644 --- a/drivers/media/pci/ngene/ngene-core.c +++ b/drivers/media/pci/ngene/ngene-core.c @@ -1408,7 +1408,6 @@ static void release_channel(struct ngene_channel *chan) { struct dvb_demux *dvbdemux = &chan->demux; struct ngene *dev = chan->dev; - struct i2c_client *client; if (chan->running) set_transfer(chan, 0); @@ -1427,12 +1426,9 @@ static void release_channel(struct ngene_channel *chan) dvb_unregister_frontend(chan->fe); /* release I2C client (tuner) if needed */ - client = chan->i2c_client[0]; - if (chan->i2c_client_fe && client) { - module_put(client->dev.driver->owner); - i2c_unregister_device(client); + if (chan->i2c_client_fe) { + dvb_module_release(chan->i2c_client[0]); chan->i2c_client[0] = NULL; - client = NULL; } dvb_frontend_detach(chan->fe); @@ -1584,11 +1580,6 @@ static void cxd_attach(struct ngene *dev) struct ngene_ci *ci = &dev->ci; struct cxd2099_cfg cxd_cfg = cxd_cfgtmpl; struct i2c_client *client; - struct i2c_board_info board_info = { - .type = "cxd2099", - .addr = 0x40, - .platform_data = &cxd_cfg, - }; int ret; u8 type; @@ -1605,26 +1596,17 @@ static void cxd_attach(struct ngene *dev) } cxd_cfg.en = &ci->en; - - request_module(board_info.type); - - client = i2c_new_device(&dev->channel[0].i2c_adapter, &board_info); - if (!client || !client->dev.driver) - goto err_ret; - - if (!try_module_get(client->dev.driver->owner)) - goto err_i2c; - - if (!ci->en) - goto err_i2c; + client = dvb_module_probe("cxd2099", "cxd2099", + &dev->channel[0].i2c_adapter, + 0x40, &cxd_cfg); + if (!client) + goto err; ci->dev = dev; dev->channel[0].i2c_client[0] = client; return; -err_i2c: - i2c_unregister_device(client); -err_ret: +err: dev_err(pdev, "CXD2099AR attach failed\n"); return; } @@ -1632,16 +1614,11 @@ static void cxd_attach(struct ngene *dev) static void cxd_detach(struct ngene *dev) { struct ngene_ci *ci = &dev->ci; - struct i2c_client *client; dvb_ca_en50221_release(ci->en); - client = dev->channel[0].i2c_client[0]; - if (client) { - module_put(client->dev.driver->owner); - i2c_unregister_device(client); - } - + dvb_module_release(dev->channel[0].i2c_client[0]); + dev->channel[0].i2c_client[0] = NULL; ci->en = NULL; }