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: 5658721 Return-Path: X-Original-To: patchwork-linux-samsung-soc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C62B1C058D for ; Mon, 19 Jan 2015 13:23:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5598A20389 for ; Mon, 19 Jan 2015 13:22:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2474E20382 for ; Mon, 19 Jan 2015 13:22:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751809AbbASNW5 (ORCPT ); Mon, 19 Jan 2015 08:22:57 -0500 Received: from mail-la0-f46.google.com ([209.85.215.46]:64413 "EHLO mail-la0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751593AbbASNW4 (ORCPT ); Mon, 19 Jan 2015 08:22:56 -0500 Received: by mail-la0-f46.google.com with SMTP id s18so7851595lam.5 for ; Mon, 19 Jan 2015 05:22: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=CJ1SaiUgpIW7W54YYYQH9wHvgoBuB7CSC+OLcoPnbonFbfroQSa1CV2kZ9ik9XaqBG R+OSHDMunJPwtzde3W4vABMiKGqwQAvGCritMO/Z3FoZlbxTx4KgQBTCZ8kyFrdIuCLw JvRA3SoVJ5U31iLSa/dEc4bHDqxYX8Fzv3DoLBM0SXwx0GXhi/x/K1JeDxxO1+XacVRd ChFb4fSbYTZu/xM3D7My9tzTJD2TCk80Fh3TRApaN/rXfnVWAJo7WQBygUqTb11bnYWk AKge6JUC7xb400fx2tu+kpCjXo5oYuZwOhqXa95rIjlHPnY97r7+4l8R7uZZh1bb7yKW bzIw== X-Gm-Message-State: ALoCoQlt8Momjjgt5bbaQYQhp/6w+LCjUy5fpgpMQCLpdbbeq76iK2yEtGizGEgok2k9leWohBYH 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-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@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=ham 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;