From patchwork Wed Mar 7 19:23:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scheller X-Patchwork-Id: 10264773 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 AFC1A6055B for ; Wed, 7 Mar 2018 19:24:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9F88F28ED1 for ; Wed, 7 Mar 2018 19:24:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9432C29119; Wed, 7 Mar 2018 19:24:08 +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 1F9BD28ED1 for ; Wed, 7 Mar 2018 19:24:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932537AbeCGTYA (ORCPT ); Wed, 7 Mar 2018 14:24:00 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:50516 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754705AbeCGTX6 (ORCPT ); Wed, 7 Mar 2018 14:23:58 -0500 Received: by mail-wm0-f67.google.com with SMTP id w128so6989421wmw.0 for ; Wed, 07 Mar 2018 11:23:57 -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=+F1DZbsZQqOQhm9noriHck+ACjRosB6utjz7wIbJuR4=; b=NFWB8OpDCnwQ0kSrdJ15iuqNLFqc0MVYLpnotwLp2XNH09Ij2f0wBqqrO+gyHXoxCc 5MbZX6TkVTS2tc4QnUClCiKozhmYPz52PdpvilQD14K0cdb1oQevPPdqAN7YfAakHoqZ d4IWalWETKt9j1Ky9QmmUdpNvmlOPyPn2nJerRG63EXWd5J8Pqzy09TpBV2eW3Mj1T/L lHqs3aFRle+liv/tN9QbI55rB5arkm+ARq5ztAqVcz1gIWcTQSXAE4ty7Oy4/kakkG38 egeeXb1AWjp5i91qNug8liOhBNF1ZQjS4k7+e3C8E8Af+ND6yj6K6OiOqpc67A99zfjA ZUkg== 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=+F1DZbsZQqOQhm9noriHck+ACjRosB6utjz7wIbJuR4=; b=FkPiKtR/W6Ta4dAeU3QLrVLlwTEyI4zWV58/2pn/5fgbgWovUQwMGxDD3DqGPXhhFm 4fRCpfqhk53+eO3MrG+GP+N/COG7RJp/xDQ66DHhVfr/bGEk/yb6hGedaguphD+uZlAa 86HJuCqfDb9TEmACIZj7ymmu35ClQyq8lfrG+FbLKMvec86ZnIHtiA41knwF4Z7mQrBw wM+v0DrLsgbMbJgEJmBYPwdeTr+UizFyiC6a3ZfFZjpA7PH14fmdayerynN3VFn0wR5X mIvtzUk+ifPpaC7Kvms3jxTKwdl/qMnBAWJ1GoBENrkFmgnooayInHmVFVaoOJMqJOoc fQfg== X-Gm-Message-State: AElRT7HBOy5sMLo4yTEdbAPEU9RgEB/+nrDYw82NpGl0XOStZoikJ5ji L4Ng/S9mH1CpKZFeWlQsrBP+IQ== X-Google-Smtp-Source: AG47ELtWDPb74Hv8c24F8v66IYZ2b2LrUXEERCSK3qA8Cvn8zIJOSVgLbyQkIEabPTyxMv1ZBJRI1g== X-Received: by 10.28.191.193 with SMTP id o62mr15048510wmi.113.1520450636584; Wed, 07 Mar 2018 11:23:56 -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.55 (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 3/4] [media] ddbridge: use common DVB I2C client handling helpers Date: Wed, 7 Mar 2018 20:23:49 +0100 Message-Id: <20180307192350.930-4-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 Instead of keeping duplicated I2C client handling construct, make use of the newly introduced dvb_module_*() helpers. This not only keeps things way cleaner and removes the need for duplicated I2C client attach code, but even allows to get rid of some variables that won't help in making things look cleaner anymore. The check on a valid ptr on port->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/ddbridge/ddbridge-ci.c | 33 ++++++-------------------- drivers/media/pci/ddbridge/ddbridge-core.c | 37 +++++++----------------------- 2 files changed, 15 insertions(+), 55 deletions(-) diff --git a/drivers/media/pci/ddbridge/ddbridge-ci.c b/drivers/media/pci/ddbridge/ddbridge-ci.c index 6585ef54ac22..d0ce6a1f1bd0 100644 --- a/drivers/media/pci/ddbridge/ddbridge-ci.c +++ b/drivers/media/pci/ddbridge/ddbridge-ci.c @@ -324,34 +324,20 @@ static int ci_cxd2099_attach(struct ddb_port *port, u32 bitrate) { 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, - }; cxd_cfg.bitrate = bitrate; cxd_cfg.en = &port->en; - request_module(board_info.type); - - client = i2c_new_device(&port->i2c->adap, &board_info); - if (!client || !client->dev.driver) - goto err_ret; - - if (!try_module_get(client->dev.driver->owner)) - goto err_i2c; - - if (!port->en) - goto err_i2c; + client = dvb_module_probe("cxd2099", "cxd2099", &port->i2c->adap, + 0x40, &cxd_cfg); + if (!client) + goto err; port->dvb[0].i2c_client[0] = client; port->en_freedata = 0; return 0; -err_i2c: - i2c_unregister_device(client); -err_ret: +err: dev_err(port->dev->dev, "CXD2099AR attach failed\n"); return -ENODEV; } @@ -385,18 +371,13 @@ int ddb_ci_attach(struct ddb_port *port, u32 bitrate) void ddb_ci_detach(struct ddb_port *port) { - struct i2c_client *client; - if (port->dvb[0].dev) dvb_unregister_device(port->dvb[0].dev); if (port->en) { dvb_ca_en50221_release(port->en); - client = port->dvb[0].i2c_client[0]; - if (client) { - module_put(client->dev.driver->owner); - i2c_unregister_device(client); - } + dvb_module_release(port->dvb[0].i2c_client[0]); + port->dvb[0].i2c_client[0] = NULL; /* free alloc'ed memory if needed */ if (port->en_freedata) diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c b/drivers/media/pci/ddbridge/ddbridge-core.c index f9bee36f1cad..36d2deb1c106 100644 --- a/drivers/media/pci/ddbridge/ddbridge-core.c +++ b/drivers/media/pci/ddbridge/ddbridge-core.c @@ -999,37 +999,22 @@ static int tuner_attach_tda18212(struct ddb_input *input, u32 porttype) .if_dvbt2_8 = 4000, .if_dvbc = 5000, }; - struct i2c_board_info board_info = { - .type = "tda18212", - .platform_data = &config, - }; - - if (input->nr & 1) - board_info.addr = 0x63; - else - board_info.addr = 0x60; + u8 addr = (input->nr & 1) ? 0x63 : 0x60; /* 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 * cold started, or it very likely will fail. */ if (porttype == DDB_TUNER_DVBCT_ST) - tuner_tda18212_ping(input, board_info.addr); - - request_module(board_info.type); - - /* perform tuner init/attach */ - client = i2c_new_device(adapter, &board_info); - if (!client || !client->dev.driver) - goto err; + tuner_tda18212_ping(input, addr); - if (!try_module_get(client->dev.driver->owner)) { - i2c_unregister_device(client); + /* perform tuner probe/init/attach */ + client = dvb_module_probe("tda18212", "tda18212", + adapter, addr, &config); + if (!client) goto err; - } dvb->i2c_client[0] = client; - return 0; err: dev_err(dev, "TDA18212 tuner not found. Device is not fully operational.\n"); @@ -1253,7 +1238,6 @@ static void dvb_input_detach(struct ddb_input *input) { struct ddb_dvb *dvb = &input->port->dvb[input->nr & 1]; struct dvb_demux *dvbdemux = &dvb->demux; - struct i2c_client *client; switch (dvb->attached) { case 0x31: @@ -1263,13 +1247,8 @@ static void dvb_input_detach(struct ddb_input *input) dvb_unregister_frontend(dvb->fe); /* fallthrough */ case 0x30: - client = dvb->i2c_client[0]; - if (client) { - module_put(client->dev.driver->owner); - i2c_unregister_device(client); - dvb->i2c_client[0] = NULL; - client = NULL; - } + dvb_module_release(dvb->i2c_client[0]); + dvb->i2c_client[0] = NULL; if (dvb->fe2) dvb_frontend_detach(dvb->fe2);