From patchwork Wed Jul 8 12:59:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Zapolskiy X-Patchwork-Id: 6746971 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id DFA179F52D for ; Wed, 8 Jul 2015 13:00:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D8710206AB for ; Wed, 8 Jul 2015 13:00:40 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id D17D6206A5 for ; Wed, 8 Jul 2015 13:00:39 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B62B86EB19; Wed, 8 Jul 2015 06:00:38 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from relay1.mentorg.com (relay1.mentorg.com [192.94.38.131]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6648B6EB16 for ; Wed, 8 Jul 2015 06:00:33 -0700 (PDT) Received: from nat-ies.mentorg.com ([192.94.31.2] helo=SVR-IES-FEM-01.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1ZCoxk-00049U-Il from Vladimir_Zapolskiy@mentor.com ; Wed, 08 Jul 2015 06:00:32 -0700 Received: from eyas.fin.mentorg.com (137.202.0.76) by SVR-IES-FEM-01.mgc.mentorg.com (137.202.0.104) with Microsoft SMTP Server (TLS) id 14.3.224.2; Wed, 8 Jul 2015 13:59:47 +0100 From: Vladimir Zapolskiy To: David Airlie , Philipp Zabel Subject: [PATCH 04/10] drm: imx-tve: use of_get_i2c_adapter_by_node interface Date: Wed, 8 Jul 2015 15:59:43 +0300 Message-ID: <1436360383-9327-1-git-send-email-vladimir_zapolskiy@mentor.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1436360095-9065-1-git-send-email-vladimir_zapolskiy@mentor.com> References: <1436360095-9065-1-git-send-email-vladimir_zapolskiy@mentor.com> MIME-Version: 1.0 X-Originating-IP: [137.202.0.76] Cc: linux-arm-kernel@lists.infradead.org, linux-i2c@vger.kernel.org, dri-devel@lists.freedesktop.org, Wolfram Sang X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This change is needed to properly lock I2C bus driver, which serves DDC. Note that prior to this change put_device() coupled with of_find_i2c_adapter_by_node() is missing on imx_tve_bind() error path and imx_tve_unbind(), also the change fixes possibly left enabled voltage regulator on imx_tve_bind() error path. Signed-off-by: Vladimir Zapolskiy --- drivers/gpu/drm/imx/imx-tve.c | 56 +++++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 18 deletions(-) diff --git a/drivers/gpu/drm/imx/imx-tve.c b/drivers/gpu/drm/imx/imx-tve.c index 214ecee..f1ac927 100644 --- a/drivers/gpu/drm/imx/imx-tve.c +++ b/drivers/gpu/drm/imx/imx-tve.c @@ -581,14 +581,15 @@ static int imx_tve_bind(struct device *dev, struct device *master, void *data) ddc_node = of_parse_phandle(np, "ddc-i2c-bus", 0); if (ddc_node) { - tve->ddc = of_find_i2c_adapter_by_node(ddc_node); + tve->ddc = of_get_i2c_adapter_by_node(ddc_node); of_node_put(ddc_node); } tve->mode = of_get_tve_mode(np); if (tve->mode != TVE_MODE_VGA) { dev_err(dev, "only VGA mode supported, currently\n"); - return -EINVAL; + ret = -EINVAL; + goto i2c_release; } if (tve->mode == TVE_MODE_VGA) { @@ -597,7 +598,7 @@ static int imx_tve_bind(struct device *dev, struct device *master, void *data) if (ret < 0) { dev_err(dev, "failed to get vsync pin\n"); - return ret; + goto i2c_release; } ret |= of_property_read_u32(np, "fsl,vsync-pin", @@ -605,14 +606,16 @@ static int imx_tve_bind(struct device *dev, struct device *master, void *data) if (ret < 0) { dev_err(dev, "failed to get vsync pin\n"); - return ret; + goto i2c_release; } } res = platform_get_resource(pdev, IORESOURCE_MEM, 0); base = devm_ioremap_resource(dev, res); - if (IS_ERR(base)) - return PTR_ERR(base); + if (IS_ERR(base)) { + ret = PTR_ERR(base); + goto i2c_release; + } tve_regmap_config.lock_arg = tve; tve->regmap = devm_regmap_init_mmio_clk(dev, "tve", base, @@ -620,13 +623,15 @@ static int imx_tve_bind(struct device *dev, struct device *master, void *data) if (IS_ERR(tve->regmap)) { dev_err(dev, "failed to init regmap: %ld\n", PTR_ERR(tve->regmap)); - return PTR_ERR(tve->regmap); + ret = PTR_ERR(tve->regmap); + goto i2c_release; } irq = platform_get_irq(pdev, 0); if (irq < 0) { dev_err(dev, "failed to get irq\n"); - return irq; + ret = irq; + goto i2c_release; } ret = devm_request_threaded_irq(dev, irq, NULL, @@ -634,7 +639,7 @@ static int imx_tve_bind(struct device *dev, struct device *master, void *data) "imx-tve", tve); if (ret < 0) { dev_err(dev, "failed to request irq: %d\n", ret); - return ret; + goto i2c_release; } tve->dac_reg = devm_regulator_get(dev, "dac"); @@ -642,14 +647,15 @@ static int imx_tve_bind(struct device *dev, struct device *master, void *data) regulator_set_voltage(tve->dac_reg, 2750000, 2750000); ret = regulator_enable(tve->dac_reg); if (ret) - return ret; + goto i2c_release; } tve->clk = devm_clk_get(dev, "tve"); if (IS_ERR(tve->clk)) { dev_err(dev, "failed to get high speed tve clock: %ld\n", PTR_ERR(tve->clk)); - return PTR_ERR(tve->clk); + ret = PTR_ERR(tve->clk); + goto regulator_release; } /* this is the IPU DI clock input selector, can be parented to tve_di */ @@ -657,36 +663,48 @@ static int imx_tve_bind(struct device *dev, struct device *master, void *data) if (IS_ERR(tve->di_sel_clk)) { dev_err(dev, "failed to get ipu di mux clock: %ld\n", PTR_ERR(tve->di_sel_clk)); - return PTR_ERR(tve->di_sel_clk); + ret = PTR_ERR(tve->di_sel_clk); + goto regulator_release; } ret = tve_clk_init(tve, base); if (ret < 0) - return ret; + goto regulator_release; ret = regmap_read(tve->regmap, TVE_COM_CONF_REG, &val); if (ret < 0) { dev_err(dev, "failed to read configuration register: %d\n", ret); - return ret; + goto regulator_release; } if (val != 0x00100000) { - dev_err(dev, "configuration register default value indicates this is not a TVEv2\n"); - return -ENODEV; + dev_err(dev, + "configuration register default value indicates this is not a TVEv2\n"); + ret = -ENODEV; + goto regulator_release; } /* disable cable detection for VGA mode */ ret = regmap_write(tve->regmap, TVE_CD_CONT_REG, 0); if (ret) - return ret; + goto regulator_release; ret = imx_tve_register(drm, tve); if (ret) - return ret; + goto regulator_release; dev_set_drvdata(dev, tve); return 0; + + regulator_release: + if (!IS_ERR(tve->dac_reg)) + regulator_disable(tve->dac_reg); + + i2c_release: + i2c_put_adapter(tve->ddc); + + return ret; } static void imx_tve_unbind(struct device *dev, struct device *master, @@ -699,6 +717,8 @@ static void imx_tve_unbind(struct device *dev, struct device *master, if (!IS_ERR(tve->dac_reg)) regulator_disable(tve->dac_reg); + + i2c_put_adapter(tve->ddc); } static const struct component_ops imx_tve_ops = {