From patchwork Sat Feb 17 15:03:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scheller X-Patchwork-Id: 10226225 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 56B7960596 for ; Sat, 17 Feb 2018 15:03:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 52E6A28B05 for ; Sat, 17 Feb 2018 15:03:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4779228C71; Sat, 17 Feb 2018 15:03:43 +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 CF8FD28C64 for ; Sat, 17 Feb 2018 15:03:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751110AbeBQPDk (ORCPT ); Sat, 17 Feb 2018 10:03:40 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:50404 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751102AbeBQPDh (ORCPT ); Sat, 17 Feb 2018 10:03:37 -0500 Received: by mail-wm0-f66.google.com with SMTP id k87so7929422wmi.0 for ; Sat, 17 Feb 2018 07:03:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=GdWhCb/lopJ5OhjJancBPDtoToMsdpqXx14VVJckmCQ=; b=Tt3izxSpumEtJcuE1FERbsiDoK4RUKYldM815DhYlMBrnFpdRuv+idonPxDirdGnbh OIoej+j3hsNZlWmY9BN8IBiKIk4t0eGstvF5t/roGz1WEie1uPWk9VBtUg/3+rOLOPBV FlHX+9iBbT37divqGwE4uKGgT/EZxfKtGaj6eF1k9MEYkp7icbt0JUEU6BIBGKz25tUR 1DNlJ5qbdjYNJ+xvwiHSic+3W6XqBz7MWMWMqH91Dfg4AtX5kRUXDzdIQpo2y6AeXb20 s7vCil/CoxHTTwhyQqCYvFJE+ca5ghkTBoxaZBLphr3Z8bVcdZ4LZSw3i8sHOzEVki7m BzDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=GdWhCb/lopJ5OhjJancBPDtoToMsdpqXx14VVJckmCQ=; b=qw38XSFt44E5Yfdd2QDAtFZan2clDSI4IzCQpJzJ6Xj5msPjRQ30uL0e2lc+4BQjmk Mwki1UWKQCEy95ZbkwLL+qt9M3I8ROb7G11ErsCxFaAay7jd6+g98FprZ9Gt/Gb8gGoT bAmsP+fKHwMHf4+H+vZj3l/VL6JXKisYXOonRtJ1vri5oD8DNNPC1ZcrricimPZYJ9b0 UBucpIMhbPdJORRNL4SrcHd/kVMHbqzI+AsVua+yWahrTy9v8dcssUzjqV7nxPKwp+uy 8LNqDpkn3EFGFZ4ykIuoC9y0EEvzwY0hV4hdK3iCLrt/Rpqsg1Qqwobakh7zIW7K1Lw3 Q2Qg== X-Gm-Message-State: APf1xPCGBUDM3fyq9WDx/Z0gHUQtWd14JVCDjufZRcBsmYrps3Vq6v0R zT/sn2uV7C2RiXK+PFzfqlOOGA== X-Google-Smtp-Source: AH8x224YaC9Nrlc0uLaL/Y+0VR3cK+6g5oATfxjcrsGNHjaEYS8L7E1uTUbIsOmzcsp5Ug/om7w4QA== X-Received: by 10.28.161.66 with SMTP id k63mr7038808wme.150.1518879815435; Sat, 17 Feb 2018 07:03:35 -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 f142sm2740628wme.15.2018.02.17.07.03.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 17 Feb 2018 07:03:34 -0800 (PST) From: Daniel Scheller To: linux-media@vger.kernel.org, mchehab@kernel.org, mchehab@s-opensource.com Cc: jasmin@anw.at Subject: [PATCH v2 3/7] [media] ddbridge: adapt cxd2099 attach to new i2c_client way Date: Sat, 17 Feb 2018 16:03:24 +0100 Message-Id: <20180217150328.686-4-d.scheller.oss@gmail.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180217150328.686-1-d.scheller.oss@gmail.com> References: <20180217150328.686-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 Change the way the cxd2099 hardware is being attached to the new I2C client interface way. Signed-off-by: Daniel Scheller Signed-off-by: Jasmin Jessich --- drivers/media/pci/ddbridge/ddbridge-ci.c | 62 +++++++++++++++++++++++++++++--- drivers/media/pci/ddbridge/ddbridge.h | 1 + 2 files changed, 58 insertions(+), 5 deletions(-) diff --git a/drivers/media/pci/ddbridge/ddbridge-ci.c b/drivers/media/pci/ddbridge/ddbridge-ci.c index ed19890710d6..6585ef54ac22 100644 --- a/drivers/media/pci/ddbridge/ddbridge-ci.c +++ b/drivers/media/pci/ddbridge/ddbridge-ci.c @@ -172,6 +172,7 @@ static void ci_attach(struct ddb_port *port) memcpy(&ci->en, &en_templ, sizeof(en_templ)); ci->en.data = ci; port->en = &ci->en; + port->en_freedata = 1; ci->port = port; ci->nr = port->nr - 2; } @@ -304,6 +305,7 @@ static void ci_xo2_attach(struct ddb_port *port) memcpy(&ci->en, &en_xo2_templ, sizeof(en_xo2_templ)); ci->en.data = ci; port->en = &ci->en; + port->en_freedata = 1; ci->port = port; ci->nr = port->nr - 2; ci->port->creg = 0; @@ -311,20 +313,58 @@ static void ci_xo2_attach(struct ddb_port *port) write_creg(ci, 0x08, 0x08); } -static struct cxd2099_cfg cxd_cfg = { +static const struct cxd2099_cfg cxd_cfgtmpl = { .bitrate = 72000, - .adr = 0x40, .polarity = 1, .clock_mode = 1, .max_i2c = 512, }; +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; + + port->dvb[0].i2c_client[0] = client; + port->en_freedata = 0; + return 0; + +err_i2c: + i2c_unregister_device(client); +err_ret: + dev_err(port->dev->dev, "CXD2099AR attach failed\n"); + return -ENODEV; +} + int ddb_ci_attach(struct ddb_port *port, u32 bitrate) { + int ret; + switch (port->type) { case DDB_CI_EXTERNAL_SONY: - cxd_cfg.bitrate = bitrate; - port->en = cxd2099_attach(&cxd_cfg, port, &port->i2c->adap); + ret = ci_cxd2099_attach(port, bitrate); + if (ret) + return -ENODEV; break; case DDB_CI_EXTERNAL_XO2: case DDB_CI_EXTERNAL_XO2_B: @@ -345,11 +385,23 @@ 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); - kfree(port->en->data); + + client = port->dvb[0].i2c_client[0]; + if (client) { + module_put(client->dev.driver->owner); + i2c_unregister_device(client); + } + + /* free alloc'ed memory if needed */ + if (port->en_freedata) + kfree(port->en->data); + port->en = NULL; } } diff --git a/drivers/media/pci/ddbridge/ddbridge.h b/drivers/media/pci/ddbridge/ddbridge.h index 095457737bc1..f223dc6c9963 100644 --- a/drivers/media/pci/ddbridge/ddbridge.h +++ b/drivers/media/pci/ddbridge/ddbridge.h @@ -276,6 +276,7 @@ struct ddb_port { struct ddb_input *input[2]; struct ddb_output *output; struct dvb_ca_en50221 *en; + u8 en_freedata; struct ddb_dvb dvb[2]; u32 gap; u32 obr;