From patchwork Tue Mar 10 13:17:27 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Francesco VIRLINZI X-Patchwork-Id: 10868 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n2ADEPeV013500 for ; Tue, 10 Mar 2009 13:17:35 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752860AbZCJNRg (ORCPT ); Tue, 10 Mar 2009 09:17:36 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752383AbZCJNRg (ORCPT ); Tue, 10 Mar 2009 09:17:36 -0400 Received: from eu1sys200aog119.obsmtp.com ([207.126.144.147]:48100 "EHLO eu1sys200aog119.obsmtp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752860AbZCJNRf (ORCPT ); Tue, 10 Mar 2009 09:17:35 -0400 Received: from source ([164.129.1.35]) (using TLSv1) by eu1sys200aob119.postini.com ([207.126.147.11]) with SMTP ID DSNKSbZoa7tIdgtuXiuE8P/PnifnX6veFFCq@postini.com; Tue, 10 Mar 2009 13:17:34 UTC Received: from zeta.dmz-eu.st.com (ns2.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 8EBAADADB for ; Tue, 10 Mar 2009 13:16:36 +0000 (GMT) Received: from mail1.ctn.st.com (mail1.ctn.st.com [164.130.116.128]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 2F1CB4C3C5 for ; Tue, 10 Mar 2009 13:17:30 +0000 (GMT) Received: from [10.52.139.41] (mdt-dhcp41.ctn.st.com [10.52.139.41]) by mail1.ctn.st.com (MOS 3.8.7a) with ESMTP id CZV02938 (AUTH virlinzi); Tue, 10 Mar 2009 14:17:29 +0100 (CET) Message-ID: <49B66867.2010406@st.com> Date: Tue, 10 Mar 2009 14:17:27 +0100 From: Francesco VIRLINZI User-Agent: Thunderbird 2.0.0.19 (X11/20090105) MIME-Version: 1.0 To: linux-sh@vger.kernel.org Subject: [PATCH] sh_clk: added clk_set_parent/clk_get_parent support Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org Hi all I would add the following functions in the clock framework - clk_set_parent - clk_get_parent and the utility function - clk_for_each Regards Francesco From 8b12a8d0c9d8adb86c70debbd2318ae7ef57784b Mon Sep 17 00:00:00 2001 From: Francesco Virlinzi Date: Tue, 10 Mar 2009 08:46:11 +0100 Subject: [PATCH] Clk set_parent/get_parent This patch: - adds set_parent/get_parent support - adds clk_for_each utility function - changes the callback function to return a value Signed-off-by: Francesco Virlinzi --- arch/sh/include/asm/clock.h | 9 ++++-- arch/sh/kernel/cpu/clock.c | 61 ++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 63 insertions(+), 7 deletions(-) diff --git a/arch/sh/include/asm/clock.h b/arch/sh/include/asm/clock.h index f9c8858..133f270 100644 --- a/arch/sh/include/asm/clock.h +++ b/arch/sh/include/asm/clock.h @@ -10,11 +10,12 @@ struct clk; struct clk_ops { - void (*init)(struct clk *clk); - void (*enable)(struct clk *clk); - void (*disable)(struct clk *clk); + int (*init)(struct clk *clk); + int (*enable)(struct clk *clk); + int (*disable)(struct clk *clk); void (*recalc)(struct clk *clk); int (*set_rate)(struct clk *clk, unsigned long rate, int algo_id); + int (*set_parent)(struct clk *clk, struct clk *parent); long (*round_rate)(struct clk *clk, unsigned long rate); }; @@ -49,6 +50,8 @@ void clk_recalc_rate(struct clk *); int clk_register(struct clk *); void clk_unregister(struct clk *); +int clk_for_each(int (*fn)(struct clk *clk, void *data), void *data); + static inline int clk_always_enable(const char *id) { struct clk *clk; diff --git a/arch/sh/kernel/cpu/clock.c b/arch/sh/kernel/cpu/clock.c index 7b17137..dc53def 100644 --- a/arch/sh/kernel/cpu/clock.c +++ b/arch/sh/kernel/cpu/clock.c @@ -135,28 +135,34 @@ static void clk_kref_release(struct kref *kref) /* Nothing to do */ } -static void __clk_disable(struct clk *clk) +static int __clk_disable(struct clk *clk) { int count = kref_put(&clk->kref, clk_kref_release); + int ret = -EINVAL; if (clk->flags & CLK_ALWAYS_ENABLED) - return; + return ret; if (!count) { /* count reaches zero, disable the clock */ if (likely(clk->ops && clk->ops->disable)) - clk->ops->disable(clk); + if (!clk->ops->disable(clk)) { + clk->rate = 0; + ret = 0; + } } + return ret; } void clk_disable(struct clk *clk) { unsigned long flags; + int ret; if (!clk) return; spin_lock_irqsave(&clock_lock, flags); - __clk_disable(clk); + ret = __clk_disable(clk); spin_unlock_irqrestore(&clock_lock, flags); clk_disable(clk->parent); @@ -239,6 +245,35 @@ void clk_recalc_rate(struct clk *clk) } EXPORT_SYMBOL_GPL(clk_recalc_rate); +int clk_set_parent(struct clk *clk, struct clk *parent) +{ + int ret = -EINVAL; + struct clk *old; + + if (!parent || !clk) + return ret; + + old = clk->parent; + if (likely(clk->ops && clk->ops->set_parent)) { + unsigned long flags; + spin_lock_irqsave(&clock_lock, flags); + ret = clk->ops->set_parent(clk, parent); + spin_unlock_irqrestore(&clock_lock, flags); + clk->parent = (ret ? old : parent); + } + + if (unlikely(clk->flags & CLK_RATE_PROPAGATES)) + propagate_rate(clk); + return ret; +} +EXPORT_SYMBOL_GPL(clk_set_parent); + +struct clk *clk_get_parent(struct clk *clk) +{ + return clk->parent; +} +EXPORT_SYMBOL_GPL(clk_get_parent); + long clk_round_rate(struct clk *clk, unsigned long rate) { if (likely(clk->ops && clk->ops->round_rate)) { @@ -255,6 +290,24 @@ long clk_round_rate(struct clk *clk, unsigned long rate) } EXPORT_SYMBOL_GPL(clk_round_rate); +int clk_for_each(int (*fn)(struct clk *clk, void *data), void *data) +{ + struct clk *clkp; + int ret = 0; + + if (!fn) + return -EINVAL; + + mutex_lock(&clock_list_sem); + + list_for_each_entry(clkp, &clock_list, node) + ret |= fn(clkp, data); + + mutex_unlock(&clock_list_sem); + return ret; +} +EXPORT_SYMBOL_GPL(clk_for_each); + /* * Returns a clock. Note that we first try to use device id on the bus * and clock name. If this fails, we try to use clock name only. -- 1.5.6.6