From patchwork Fri Aug 30 14:53:20 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sylwester Nawrocki/Kernel \\(PLT\\) /SRPOL/Staff Engineer/Samsung Electronics" X-Patchwork-Id: 2852103 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 3AC09C0AB5 for ; Fri, 30 Aug 2013 14:56:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0173C20279 for ; Fri, 30 Aug 2013 14:56:01 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 14C8020259 for ; Fri, 30 Aug 2013 14:55:56 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VFQ75-0003O8-0B; Fri, 30 Aug 2013 14:55:51 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VFQ6w-0001zn-AD; Fri, 30 Aug 2013 14:55:42 +0000 Received: from mailout2.samsung.com ([203.254.224.25]) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VFQ6r-0001xM-FH for linux-arm-kernel@lists.infradead.org; Fri, 30 Aug 2013 14:55:39 +0000 Received: from epcpsbgm2.samsung.com (epcpsbgm2 [203.254.230.27]) by mailout2.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MSC004XNMRXSZK0@mailout2.samsung.com> for linux-arm-kernel@lists.infradead.org; Fri, 30 Aug 2013 23:55:12 +0900 (KST) X-AuditID: cbfee61b-b7f776d0000016c8-36-5220b250ecb4 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id BD.1A.05832.052B0225; Fri, 30 Aug 2013 23:55:12 +0900 (KST) Received: from amdc1344.digital.local ([106.116.147.32]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MSC00KB2MP05U90@mmp1.samsung.com>; Fri, 30 Aug 2013 23:55:12 +0900 (KST) From: Sylwester Nawrocki To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v6 3/5] clk: Add common __clk_get(), __clk_put() implementations Date: Fri, 30 Aug 2013 16:53:20 +0200 Message-id: <1377874402-2944-4-git-send-email-s.nawrocki@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1377874402-2944-1-git-send-email-s.nawrocki@samsung.com> References: <1377874402-2944-1-git-send-email-s.nawrocki@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrELMWRmVeSWpSXmKPExsVy+t9jAd2ATQpBBg2/DCzeb5zHZNHzp9Li bNMbdovOiUvYLTY9vsZqcXnXHDaLCVMnsVvM+TOF2eL2ZV6LpxMuslncblzBZnH4TTurxfoZ r1kceD1amnvYPD58jPOY3TGT1ePOtT1sHkdXrmXy2Lyk3mP31yZGj74tqxg9Pm+SC+CM4rJJ Sc3JLEst0rdL4MqYsqKNtaBduWLHiinMDYznZboYOTkkBEwkdi9exgphi0lcuLeerYuRi0NI YBGjxMu3c1ggnA4mife3ljGBVLEJGEr0Hu1jBLFFBDQkpnQ9ZgcpYha4zCSx6UsXO0hCWCBA 4u3+XSwgNouAqsSszdfAbF4BV4lFv78BNXMArVOQmDPJBiTMKeAmcWEayGZOoGWuEnNOrGKc wMi7gJFhFaNoakFyQXFSeq6RXnFibnFpXrpecn7uJkZwyD6T3sG4qsHiEKMAB6MSD+/O5QpB QqyJZcWVuYcYJTiYlUR4Py4GCvGmJFZWpRblxxeV5qQWH2KU5mBREuc92GodKCSQnliSmp2a WpBaBJNl4uCUamBUTVfziDn8KbQ2Jlnl6PpZ9xzVVi+7PO9nufzj2zPYNY0C/CySU1p6k545 /bW/dL3M9qFZYe9Xh0mKCxiu+R7psFk6w8zslcyvjTK+l2ZclAt6OGVa7q+He5gu6hxe6rPl 2GKPXwffBbNoswpelNi2c/+i/1b26j+SHj4+X/cnO2ZiB4deXv8DJZbijERDLeai4kQAcGyx 31UCAAA= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130830_105537_712465_D3513150 X-CRM114-Status: GOOD ( 13.27 ) X-Spam-Score: -9.1 (---------) Cc: linux-mips@linux-mips.org, mturquette@linaro.org, linux-sh@vger.kernel.org, jiada_wang@mentor.com, t.figa@samsung.com, linux-kernel@vger.kernel.org, kyungmin.park@samsung.com, myungjoo.ham@samsung.com, laurent.pinchart@ideasonboard.com, Sylwester Nawrocki , linux@arm.linux.org.uk, g.liakhovetski@gmx.de X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-6.3 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 patch adds common __clk_get(), __clk_put() clkdev helpers which replace their platform specific counterparts when the common clock API is enabled. The owner module pointer field is added to struct clk so a reference to the clock supplier module can be taken by the clock consumers. Signed-off-by: Sylwester Nawrocki Signed-off-by: Kyungmin Park --- Changes since v5: - none. Changes since v4: - dropped unnecessary struct module forward declaration from clk-provider.h Changes since v3: - dropped exporting of __clk_get(), __clk_put(). Changes since v2: - fixed handling of NULL clock pointers in __clk_get(), __clk_put(); --- arch/arm/include/asm/clkdev.h | 2 ++ arch/blackfin/include/asm/clkdev.h | 2 ++ arch/mips/include/asm/clkdev.h | 2 ++ arch/sh/include/asm/clkdev.h | 2 ++ drivers/clk/clk.c | 20 ++++++++++++++++++++ include/linux/clk-private.h | 3 +++ include/linux/clkdev.h | 5 +++++ 7 files changed, 36 insertions(+) diff --git a/arch/arm/include/asm/clkdev.h b/arch/arm/include/asm/clkdev.h index 80751c1..4e8a4b2 100644 --- a/arch/arm/include/asm/clkdev.h +++ b/arch/arm/include/asm/clkdev.h @@ -14,12 +14,14 @@ #include +#ifndef CONFIG_COMMON_CLK #ifdef CONFIG_HAVE_MACH_CLKDEV #include #else #define __clk_get(clk) ({ 1; }) #define __clk_put(clk) do { } while (0) #endif +#endif static inline struct clk_lookup_alloc *__clkdev_alloc(size_t size) { diff --git a/arch/blackfin/include/asm/clkdev.h b/arch/blackfin/include/asm/clkdev.h index 9053bed..7ac2436 100644 --- a/arch/blackfin/include/asm/clkdev.h +++ b/arch/blackfin/include/asm/clkdev.h @@ -8,7 +8,9 @@ static inline struct clk_lookup_alloc *__clkdev_alloc(size_t size) return kzalloc(size, GFP_KERNEL); } +#ifndef CONFIG_COMMON_CLK #define __clk_put(clk) #define __clk_get(clk) ({ 1; }) +#endif #endif diff --git a/arch/mips/include/asm/clkdev.h b/arch/mips/include/asm/clkdev.h index 2624754..1b3ad7b 100644 --- a/arch/mips/include/asm/clkdev.h +++ b/arch/mips/include/asm/clkdev.h @@ -14,8 +14,10 @@ #include +#ifndef CONFIG_COMMON_CLK #define __clk_get(clk) ({ 1; }) #define __clk_put(clk) do { } while (0) +#endif static inline struct clk_lookup_alloc *__clkdev_alloc(size_t size) { diff --git a/arch/sh/include/asm/clkdev.h b/arch/sh/include/asm/clkdev.h index 6ba9186..c419014 100644 --- a/arch/sh/include/asm/clkdev.h +++ b/arch/sh/include/asm/clkdev.h @@ -25,7 +25,9 @@ static inline struct clk_lookup_alloc *__clkdev_alloc(size_t size) return kzalloc(size, GFP_KERNEL); } +#ifndef CONFIG_COMMON_CLK #define __clk_put(clk) #define __clk_get(clk) ({ 1; }) +#endif #endif /* __CLKDEV_H__ */ diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 8f18564..dcf061a 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -1965,6 +1965,26 @@ void devm_clk_unregister(struct device *dev, struct clk *clk) } EXPORT_SYMBOL_GPL(devm_clk_unregister); +/* + * clkdev helpers + */ +int __clk_get(struct clk *clk) +{ + if (clk && !try_module_get(clk->owner)) + return 0; + + return 1; +} + +void __clk_put(struct clk *clk) +{ + if (WARN_ON_ONCE(IS_ERR(clk))) + return; + + if (clk) + module_put(clk->owner); +} + /*** clk rate change notifiers ***/ /** diff --git a/include/linux/clk-private.h b/include/linux/clk-private.h index 8138c94..8cb1865 100644 --- a/include/linux/clk-private.h +++ b/include/linux/clk-private.h @@ -25,10 +25,13 @@ #ifdef CONFIG_COMMON_CLK +struct module; + struct clk { const char *name; const struct clk_ops *ops; struct clk_hw *hw; + struct module *owner; struct clk *parent; const char **parent_names; struct clk **parents; diff --git a/include/linux/clkdev.h b/include/linux/clkdev.h index a6a6f60..94bad77 100644 --- a/include/linux/clkdev.h +++ b/include/linux/clkdev.h @@ -43,4 +43,9 @@ int clk_add_alias(const char *, const char *, char *, struct device *); int clk_register_clkdev(struct clk *, const char *, const char *, ...); int clk_register_clkdevs(struct clk *, struct clk_lookup *, size_t); +#ifdef CONFIG_COMMON_CLK +int __clk_get(struct clk *clk); +void __clk_put(struct clk *clk); +#endif + #endif