From patchwork Sat Aug 24 15:19:47 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sylwester Nawrocki X-Patchwork-Id: 2849231 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 44DC19F239 for ; Sat, 24 Aug 2013 15:22:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5294320272 for ; Sat, 24 Aug 2013 15:22:28 +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 3ADA82026F for ; Sat, 24 Aug 2013 15:22:27 +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 1VDFf8-0008Kn-HC; Sat, 24 Aug 2013 15:22:02 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VDFf2-0001Hv-MQ; Sat, 24 Aug 2013 15:21:56 +0000 Received: from mail-ee0-x22b.google.com ([2a00:1450:4013:c00::22b]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VDFeh-0001Eg-Kc for linux-arm-kernel@lists.infradead.org; Sat, 24 Aug 2013 15:21:37 +0000 Received: by mail-ee0-f43.google.com with SMTP id e52so788704eek.2 for ; Sat, 24 Aug 2013 08:21:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=BI6WDRHrHM8kbIV3CshIfJziJEY+tkWAEsJjq/mzjWY=; b=WJZArB6SA3ErzsknPUupO8GyCP0WsNYXiiLRYkMAUjiOzJ17AVoxNiScfATUTPH5e5 756AGoizaIU3XoMu93LkGJs0+FY45nm7NlBlAuwRVTKHLN+ptpltmEBycY9G86/fEaZE /VuWPQh9yqg7Danv8g48HCtCFExFvPz6wtCN7JVCn1SQe1gJGA2kaA8nCBVKx2mXkPAZ fTM2wuBa+utL9Zfx7Hlk05hruH02wNQY/9toR4/uV3gYgNzpdknEahkMblK/qa/vOXjO eI9ZEdFWSsVoru/lGwnJ+M/bRrITbc2+jpF1+Irt9GFik4OR/BXdMkMo51kE9N1cVlKm AcDw== X-Received: by 10.14.220.200 with SMTP id o48mr528075eep.62.1377357674012; Sat, 24 Aug 2013 08:21:14 -0700 (PDT) Received: from localhost.localdomain (093105185086.warszawa.vectranet.pl. [93.105.185.86]) by mx.google.com with ESMTPSA id x47sm7415825eea.16.1969.12.31.16.00.00 (version=TLSv1 cipher=RC4-SHA bits=128/128); Sat, 24 Aug 2013 08:21:13 -0700 (PDT) From: Sylwester Nawrocki To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 3/5] clk: Add common __clk_get(), __clk_put() implementations Date: Sat, 24 Aug 2013 17:19:47 +0200 Message-Id: <1377357589-13242-4-git-send-email-s.nawrocki@samsung.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1377357589-13242-1-git-send-email-s.nawrocki@samsung.com> References: <1377357589-13242-1-git-send-email-s.nawrocki@samsung.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130824_112135_972804_01EF0B43 X-CRM114-Status: GOOD ( 14.86 ) X-Spam-Score: -2.0 (--) Cc: linux-mips@linux-mips.org, mturquette@linaro.org, linux-sh@vger.kernel.org, jiada_wang@mentor.com, t.figa@samsung.com, laurent.pinchart@ideasonboard.com, linux-kernel@vger.kernel.org, ralf@linux-mips.org, kyungmin.park@samsung.com, broonie@kernel.org, vapier@gentoo.org, myungjoo.ham@samsung.com, s.nawrocki@samsung.com, 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=-6.9 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, 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 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/clk-provider.h | 2 ++ include/linux/clkdev.h | 5 +++++ 8 files changed, 38 insertions(+), 0 deletions(-) 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 f46444f..8ccc1cd 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -1959,6 +1959,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/clk-provider.h b/include/linux/clk-provider.h index 1f0285b..6341e79 100644 --- a/include/linux/clk-provider.h +++ b/include/linux/clk-provider.h @@ -141,6 +141,8 @@ struct clk_ops { void (*init)(struct clk_hw *hw); }; +struct module; + /** * struct clk_init_data - holds init data that's common to all clocks and is * shared between the clock provider and the common clock framework. 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