From patchwork Mon Jan 19 13:22:33 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 5658861 Return-Path: X-Original-To: patchwork-linux-media@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 8D26E9F333 for ; Mon, 19 Jan 2015 13:31:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B6A2C2038F for ; Mon, 19 Jan 2015 13:31:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4A3B320386 for ; Mon, 19 Jan 2015 13:30:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752035AbbASNa5 (ORCPT ); Mon, 19 Jan 2015 08:30:57 -0500 Received: from mail-la0-f53.google.com ([209.85.215.53]:44964 "EHLO mail-la0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751659AbbASNa5 (ORCPT ); Mon, 19 Jan 2015 08:30:57 -0500 Received: by mail-la0-f53.google.com with SMTP id gq15so4397113lab.12 for ; Mon, 19 Jan 2015 05:30:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=t2l+HOKJ1FFDpLt8UtuuJrf+Txg6Avah6GMbJ4ms/ro=; b=IWShYD5FAiCNDL+celcZBrZIJL8CzPyO2/pSa3HccKBhVfA9HzIsEE+MJTd5h91RNM Yw1zFvE5hTra816KIq/MbTeE7XzL0MkDhNWSPgFLZOtG21uaPEXqh8XDNnvXgjEnROBd /X+8gCzVRXGMwjf8IvItrP5/cuuIGXPpECeynzekDR3CLa0FhzTSCL7NCHIjt94VVQOH pFD83gSvuxB3gsRoF/0nFD8cSxH9y8/89Klf6VvGBCI8jFNkGBBp8mnFkqWcmqury4Ku /PMKV5FW+AFuUeQePDpv3CfH5EtC0LQKsyU+awoklcghmfLS/x12iAEgNcRrpx1oyW2h wTvw== X-Gm-Message-State: ALoCoQlsBSZ3nOYW8gIvzhrXa8hWXzoJkZvAAYZprdR7MHLm4nzTENoqetzMphsFGFhd2EAb7s/h X-Received: by 10.112.56.142 with SMTP id a14mr30318295lbq.16.1421673775307; Mon, 19 Jan 2015 05:22:55 -0800 (PST) Received: from localhost.localdomain ([85.235.11.236]) by mx.google.com with ESMTPSA id v4sm3080344lbz.12.2015.01.19.05.22.53 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 19 Jan 2015 05:22:54 -0800 (PST) From: Ulf Hansson To: Mauro Carvalho Chehab , linux-media@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, Kukjin Kim , Sylwester Nawrocki , Kyungmin Park , Ulf Hansson Subject: [PATCH V2 1/8] [media] exynos-gsc: Simplify clock management Date: Mon, 19 Jan 2015 14:22:33 +0100 Message-Id: <1421673760-2600-2-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1421673760-2600-1-git-send-email-ulf.hansson@linaro.org> References: <1421673760-2600-1-git-send-email-ulf.hansson@linaro.org> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_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 Instead of having separate functions that fecthes, prepares and unprepares the clock, let's encapsulate this code into ->probe(). This makes error handling easier and decreases the lines of code. Signed-off-by: Ulf Hansson --- drivers/media/platform/exynos-gsc/gsc-core.c | 49 ++++++++-------------------- 1 file changed, 14 insertions(+), 35 deletions(-) diff --git a/drivers/media/platform/exynos-gsc/gsc-core.c b/drivers/media/platform/exynos-gsc/gsc-core.c index fd2891c..bd769d4 100644 --- a/drivers/media/platform/exynos-gsc/gsc-core.c +++ b/drivers/media/platform/exynos-gsc/gsc-core.c @@ -1003,36 +1003,6 @@ static void *gsc_get_drv_data(struct platform_device *pdev) return driver_data; } -static void gsc_clk_put(struct gsc_dev *gsc) -{ - if (!IS_ERR(gsc->clock)) - clk_unprepare(gsc->clock); -} - -static int gsc_clk_get(struct gsc_dev *gsc) -{ - int ret; - - dev_dbg(&gsc->pdev->dev, "gsc_clk_get Called\n"); - - gsc->clock = devm_clk_get(&gsc->pdev->dev, GSC_CLOCK_GATE_NAME); - if (IS_ERR(gsc->clock)) { - dev_err(&gsc->pdev->dev, "failed to get clock~~~: %s\n", - GSC_CLOCK_GATE_NAME); - return PTR_ERR(gsc->clock); - } - - ret = clk_prepare(gsc->clock); - if (ret < 0) { - dev_err(&gsc->pdev->dev, "clock prepare failed for clock: %s\n", - GSC_CLOCK_GATE_NAME); - gsc->clock = ERR_PTR(-EINVAL); - return ret; - } - - return 0; -} - static int gsc_m2m_suspend(struct gsc_dev *gsc) { unsigned long flags; @@ -1101,7 +1071,6 @@ static int gsc_probe(struct platform_device *pdev) init_waitqueue_head(&gsc->irq_queue); spin_lock_init(&gsc->slock); mutex_init(&gsc->lock); - gsc->clock = ERR_PTR(-EINVAL); res = platform_get_resource(pdev, IORESOURCE_MEM, 0); gsc->regs = devm_ioremap_resource(dev, res); @@ -1114,9 +1083,19 @@ static int gsc_probe(struct platform_device *pdev) return -ENXIO; } - ret = gsc_clk_get(gsc); - if (ret) + gsc->clock = devm_clk_get(dev, GSC_CLOCK_GATE_NAME); + if (IS_ERR(gsc->clock)) { + dev_err(dev, "failed to get clock~~~: %s\n", + GSC_CLOCK_GATE_NAME); + return PTR_ERR(gsc->clock); + } + + ret = clk_prepare(gsc->clock); + if (ret) { + dev_err(&gsc->pdev->dev, "clock prepare failed for clock: %s\n", + GSC_CLOCK_GATE_NAME); return ret; + } ret = devm_request_irq(dev, res->start, gsc_irq_handler, 0, pdev->name, gsc); @@ -1157,7 +1136,7 @@ err_m2m: err_v4l2: v4l2_device_unregister(&gsc->v4l2_dev); err_clk: - gsc_clk_put(gsc); + clk_unprepare(gsc->clock); return ret; } @@ -1170,7 +1149,7 @@ static int gsc_remove(struct platform_device *pdev) vb2_dma_contig_cleanup_ctx(gsc->alloc_ctx); pm_runtime_disable(&pdev->dev); - gsc_clk_put(gsc); + clk_unprepare(gsc->clock); dev_dbg(&pdev->dev, "%s driver unloaded\n", pdev->name); return 0;