From patchwork Tue Aug 6 15:51:56 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: 2839454 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B1A1A9F485 for ; Tue, 6 Aug 2013 15:53:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D1E76201BE for ; Tue, 6 Aug 2013 15:53:25 +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 7EB7F20166 for ; Tue, 6 Aug 2013 15:53:24 +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 1V6jZY-0000TU-Jc; Tue, 06 Aug 2013 15:53:20 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1V6jZW-0001S8-FS; Tue, 06 Aug 2013 15:53:18 +0000 Received: from mailout3.samsung.com ([203.254.224.33]) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1V6jZS-0001Qk-UO for linux-arm-kernel@lists.infradead.org; Tue, 06 Aug 2013 15:53:16 +0000 Received: from epcpsbgm1.samsung.com (epcpsbgm1 [203.254.230.26]) by mailout3.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MR400KZD9G2U220@mailout3.samsung.com> for linux-arm-kernel@lists.infradead.org; Wed, 07 Aug 2013 00:52:51 +0900 (KST) X-AuditID: cbfee61a-b7f196d000007dfa-7b-52011bd27720 Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id 63.43.32250.2DB11025; Wed, 07 Aug 2013 00:52:51 +0900 (KST) Received: from amdc1344.digital.local ([106.116.147.32]) by mmp2.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MR4001I69EOKL20@mmp2.samsung.com>; Wed, 07 Aug 2013 00:52:50 +0900 (KST) From: Sylwester Nawrocki To: linux-arm-kernel@lists.infradead.org Subject: [PATCH RFC 1/2] clk: add common __clk_get(), __clk_put() implementations Date: Tue, 06 Aug 2013 17:51:56 +0200 Message-id: <1375804317-10576-2-git-send-email-s.nawrocki@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1375804317-10576-1-git-send-email-s.nawrocki@samsung.com> References: <1375804317-10576-1-git-send-email-s.nawrocki@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrLLMWRmVeSWpSXmKPExsVy+t9jQd3L0oxBBp/mslhMffiEzeL9xnlM Fj1/Ki3ONr1ht+icuITdYv/bn6wWmx5fY7W4vGsOm8WEqZPYLeb8mcJscfsyr8WBJ8vZLJ5O uMhmcWmPisXhN+2sFu9/Olo8XbeE2WL9jNcsFgsbvrBb3Jzwg9lBxKOluYfNY+V0b4/L398w e+ycdZfd48PHOI/ZHTNZPeZPf8TssWlVJ5vHnWt72DyOrlzL5HH6/SFWj81L6j12f21i9Ojb sorR4/MmuQD+KC6blNSczLLUIn27BK6MVa9WMxdMUKz4fuElcwPjXOkuRg4OCQETidPzfbsY OYFMMYkL99azgdhCAtMZJf7uyYSwO5gkVi7WBrHZBAwleo/2MYLYIgIaElO6HrN3MXJxMAt0 sEi0TPsKlhAWCJaY0rCeBcRmEVCVWLizlxXE5hVwk3i4o5ENYq+CxJxJNiBhTgF3iZXT/jNC 7HKTuHJ/CusERt4FjAyrGEVTC5ILipPScw31ihNzi0vz0vWS83M3MYIj5ZnUDsaVDRaHGAU4 GJV4eCvEGIOEWBPLiitzDzFKcDArifD6SACFeFMSK6tSi/Lji0pzUosPMUpzsCiJ8x5otQ4U EkhPLEnNTk0tSC2CyTJxcEo1MHKyPZPW7oso971/Z91rbe//Ly8zqr180Xjw257zU6av+HJL nNHIdWqEWL+K4IWknq8rdy25EqZXtDPxRr2VzJZMM40jKyvKH8w+rcjBU79B1iFqle3mlTeE Y0ul3jyUrJs1Z74Lz9z60hvV/xJ6Q2avSvgs8T8jZvrkA4e3Hv/NzjQ/1M94C6MSS3FGoqEW c1FxIgDoUa9rkAIAAA== X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130806_115315_234250_1BF3162C X-CRM114-Status: GOOD ( 12.02 ) X-Spam-Score: -5.2 (-----) Cc: linux-mips@linux-mips.org, mturquette@linaro.org, lethal@linux-sh.org, jiada_wang@mentor.com, t.figa@samsung.com, linux-sh@vger.kernel.org, linux-kernel@vger.kernel.org, ralf@linux-mips.org, kyungmin.park@samsung.com, broonie@kernel.org, vapier@gentoo.org, laurent.pinchart@ideasonboard.com, Sylwester Nawrocki , uclinux-dist-devel@blackfin.uclinux.org, linux@arm.linux.org.uk, shawn.guo@linaro.org, LW@KARO-electronics.de, g.liakhovetski@gmx.de, sebastian.hesselbarth@gmail.com 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=-2.5 required=5.0 tests=BAYES_00,KHOP_BIG_TO_CC, 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 enabled. An owner module pointer is added to struct clk so a reference to the clock supplier module is taken when the clock has active consumers. Signed-off-by: Sylwester Nawrocki Acked-by: Kyungmin Park --- 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 | 24 ++++++++++++++++++++++++ include/linux/clk-private.h | 3 +++ include/linux/clkdev.h | 5 +++++ 7 files changed, 40 insertions(+) -- 1.7.9.5 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 54a191c..4877bd6 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -1850,6 +1850,30 @@ 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 (WARN_ON((!clk))) + return 0; + + if (!try_module_get(clk->owner)) + return 0; + + return 1; +} +EXPORT_SYMBOL(__clk_get); + +void __clk_put(struct clk *clk) +{ + if (!clk || IS_ERR(clk)) + return; + + module_put(clk->owner); +} +EXPORT_SYMBOL(__clk_put); + /*** clk rate change notifiers ***/ /** diff --git a/include/linux/clk-private.h b/include/linux/clk-private.h index dd7adff..b7c0b58 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