From patchwork Wed Mar 7 20:07:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scheller X-Patchwork-Id: 10265107 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 18244602C8 for ; Wed, 7 Mar 2018 20:08:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0CC622946E for ; Wed, 7 Mar 2018 20:08:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 01729295B1; Wed, 7 Mar 2018 20:08: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 801282946E for ; Wed, 7 Mar 2018 20:08:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965061AbeCGUIB (ORCPT ); Wed, 7 Mar 2018 15:08:01 -0500 Received: from mail-wr0-f194.google.com ([209.85.128.194]:39549 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934297AbeCGUH7 (ORCPT ); Wed, 7 Mar 2018 15:07:59 -0500 Received: by mail-wr0-f194.google.com with SMTP id w77so3439131wrc.6 for ; Wed, 07 Mar 2018 12:07: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; bh=C24Rp9Jgh+LakzocH8MROquSW0tDxyJPYS7miUdfVy4=; b=qnYD4usOaXnsN20dO8muVSCK56q/KGB2PzP4HMceTz/6kal2aiuxfGGg5/HB66SAcg pIK7veSuNFRv0Ke6yMYVux53vE7qiD3ffQfP44ib+1LgfEYGqCvOqjNek+gTRLEkM4O0 ytn7X703Gsf9qG/F4+2ohn73ZG8k9lKJkCfLhTHDI+lD+EE19d/ElUilPrQH5TZbH9jM e4sJ8/VfOV7BnWxP/t3hId6uzc+AdD5FNW1ZCwh24vpqwTtOLs1np6T2c3bOhkuSms6Z lqHP+wjnMgj/0U4kffuWQqOsBBZnAiXEkSFgUHA7+Us6uanwVuomC7CaFDxgYj6MP/5t euvQ== 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; bh=C24Rp9Jgh+LakzocH8MROquSW0tDxyJPYS7miUdfVy4=; b=MbkURkn3ux4WSKty6bY4RU7LkEgTDzOIBUibi1FY+Bl+2gkVW8H+4utRgNaSSAZJ5C +sKPZmrCQ8vuuJhvJRD4YC9GNZTkmtis0PZKFYSxfZVubnE/RyCQYmmmsCxVjadYeZXQ wTIqUZZRu9dmC1enVSl7PosqVFwy4XfYNSMfk8TiSl2L3pzgIzl0EIGC2e6sp504Lw7l c3IJ3WIdeh0HTWmSZjKcmo5U0iW5qd9MqqBMDN3gwzaBPE+gVXREQOeQD6m9y+I3SUZx 3aTYiKcyGQSmgRZt7yZtr1cve1pXshvWZ5uROWGLB+A+nrz5e5VJtBgDKyk7tj9l4k7I RRIw== X-Gm-Message-State: APf1xPD15ZSeeMGEEikHR9U7WXU6RQKo0FM51G4Z7knCwJm5jlGSmhNJ o9OW6dANV2fypLYTAuwE+KmWPw== X-Google-Smtp-Source: AG47ELuw/jhj/SQUnRREtk5ebBLkdbz0Z4ZHh1ELynq+ykW7kicxjNU9wod8B9h4wiZs6S2Db53lgw== X-Received: by 10.223.128.201 with SMTP id 67mr19733401wrl.131.1520453277712; Wed, 07 Mar 2018 12:07: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 67sm12108144wmw.17.2018.03.07.12.07.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Mar 2018 12:07:57 -0800 (PST) From: Daniel Scheller To: linux-media@vger.kernel.org, mchehab@kernel.org, mchehab@s-opensource.com Subject: [PATCH v2 1/2] [media] ddbridge: use common DVB I2C client handling helpers Date: Wed, 7 Mar 2018 21:07:55 +0100 Message-Id: <20180307200756.7078-1-d.scheller.oss@gmail.com> X-Mailer: git-send-email 2.16.1 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 --- V2: * pass NULL as (optional) I2C name when calling dvb_module_probe() drivers/media/pci/ddbridge/ddbridge-ci.c | 33 ++++++--------------------- drivers/media/pci/ddbridge/ddbridge-core.c | 36 ++++++------------------------ 2 files changed, 14 insertions(+), 55 deletions(-) diff --git a/drivers/media/pci/ddbridge/ddbridge-ci.c b/drivers/media/pci/ddbridge/ddbridge-ci.c index 6585ef54ac22..a9dbc4ebf94f 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", NULL, &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..90687eff5909 100644 --- a/drivers/media/pci/ddbridge/ddbridge-core.c +++ b/drivers/media/pci/ddbridge/ddbridge-core.c @@ -999,37 +999,21 @@ 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", NULL, 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 +1237,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 +1246,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);