Initial Contribution
msm-2.6.38: tag AU_LINUX_ANDROID_GINGERBREAD.02.03.04.00.142
Signed-off-by: Bryan Huntsman <bryanh@codeaurora.org>
diff --git a/arch/arm/mach-msm/clock.c b/arch/arm/mach-msm/clock.c
index 22a5376..05265f8 100644
--- a/arch/arm/mach-msm/clock.c
+++ b/arch/arm/mach-msm/clock.c
@@ -1,7 +1,7 @@
/* arch/arm/mach-msm/clock.c
*
* Copyright (C) 2007 Google, Inc.
- * Copyright (c) 2007-2010, Code Aurora Forum. All rights reserved.
+ * Copyright (c) 2007-2011, Code Aurora Forum. All rights reserved.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
@@ -15,109 +15,141 @@
*/
#include <linux/kernel.h>
-#include <linux/list.h>
#include <linux/err.h>
#include <linux/spinlock.h>
-#include <linux/pm_qos_params.h>
-#include <linux/mutex.h>
-#include <linux/clk.h>
#include <linux/string.h>
#include <linux/module.h>
+#include <linux/clk.h>
#include <linux/clkdev.h>
#include "clock.h"
-static DEFINE_MUTEX(clocks_mutex);
-static DEFINE_SPINLOCK(clocks_lock);
-static LIST_HEAD(clocks);
-
/*
* Standard clock functions defined in include/linux/clk.h
*/
int clk_enable(struct clk *clk)
{
+ int ret = 0;
unsigned long flags;
- spin_lock_irqsave(&clocks_lock, flags);
+ struct clk *parent;
+
+ if (!clk)
+ return 0;
+
+ spin_lock_irqsave(&clk->lock, flags);
+ if (clk->count == 0) {
+ parent = clk_get_parent(clk);
+ ret = clk_enable(parent);
+ if (ret)
+ goto out;
+
+ if (clk->ops->enable)
+ ret = clk->ops->enable(clk);
+ if (ret) {
+ clk_disable(parent);
+ goto out;
+ }
+ }
clk->count++;
- if (clk->count == 1)
- clk->ops->enable(clk->id);
- spin_unlock_irqrestore(&clocks_lock, flags);
- return 0;
+out:
+ spin_unlock_irqrestore(&clk->lock, flags);
+
+ return ret;
}
EXPORT_SYMBOL(clk_enable);
void clk_disable(struct clk *clk)
{
unsigned long flags;
- spin_lock_irqsave(&clocks_lock, flags);
- BUG_ON(clk->count == 0);
+ struct clk *parent;
+
+ if (!clk)
+ return;
+
+ spin_lock_irqsave(&clk->lock, flags);
+ if (WARN_ON(clk->count == 0))
+ goto out;
+ if (clk->count == 1) {
+ if (clk->ops->disable)
+ clk->ops->disable(clk);
+ parent = clk_get_parent(clk);
+ clk_disable(parent);
+ }
clk->count--;
- if (clk->count == 0)
- clk->ops->disable(clk->id);
- spin_unlock_irqrestore(&clocks_lock, flags);
+out:
+ spin_unlock_irqrestore(&clk->lock, flags);
}
EXPORT_SYMBOL(clk_disable);
int clk_reset(struct clk *clk, enum clk_reset_action action)
{
- return clk->ops->reset(clk->remote_id, action);
+ if (!clk->ops->reset)
+ return -ENOSYS;
+
+ return clk->ops->reset(clk, action);
}
EXPORT_SYMBOL(clk_reset);
unsigned long clk_get_rate(struct clk *clk)
{
- return clk->ops->get_rate(clk->id);
+ if (!clk->ops->get_rate)
+ return 0;
+
+ return clk->ops->get_rate(clk);
}
EXPORT_SYMBOL(clk_get_rate);
int clk_set_rate(struct clk *clk, unsigned long rate)
{
- int ret;
- if (clk->flags & CLKFLAG_MAX) {
- ret = clk->ops->set_max_rate(clk->id, rate);
- if (ret)
- return ret;
- }
- if (clk->flags & CLKFLAG_MIN) {
- ret = clk->ops->set_min_rate(clk->id, rate);
- if (ret)
- return ret;
- }
+ if (!clk->ops->set_rate)
+ return -ENOSYS;
- if (clk->flags & CLKFLAG_MAX || clk->flags & CLKFLAG_MIN)
- return ret;
-
- return clk->ops->set_rate(clk->id, rate);
+ return clk->ops->set_rate(clk, rate);
}
EXPORT_SYMBOL(clk_set_rate);
long clk_round_rate(struct clk *clk, unsigned long rate)
{
- return clk->ops->round_rate(clk->id, rate);
+ if (!clk->ops->round_rate)
+ return -ENOSYS;
+
+ return clk->ops->round_rate(clk, rate);
}
EXPORT_SYMBOL(clk_round_rate);
int clk_set_min_rate(struct clk *clk, unsigned long rate)
{
- return clk->ops->set_min_rate(clk->id, rate);
+ if (!clk->ops->set_min_rate)
+ return -ENOSYS;
+
+ return clk->ops->set_min_rate(clk, rate);
}
EXPORT_SYMBOL(clk_set_min_rate);
int clk_set_max_rate(struct clk *clk, unsigned long rate)
{
- return clk->ops->set_max_rate(clk->id, rate);
+ if (!clk->ops->set_max_rate)
+ return -ENOSYS;
+
+ return clk->ops->set_max_rate(clk, rate);
}
EXPORT_SYMBOL(clk_set_max_rate);
int clk_set_parent(struct clk *clk, struct clk *parent)
{
- return -ENOSYS;
+ if (!clk->ops->set_parent)
+ return 0;
+
+ return clk->ops->set_parent(clk, parent);
}
EXPORT_SYMBOL(clk_set_parent);
struct clk *clk_get_parent(struct clk *clk)
{
- return ERR_PTR(-ENOSYS);
+ if (!clk->ops->get_parent)
+ return NULL;
+
+ return clk->ops->get_parent(clk);
}
EXPORT_SYMBOL(clk_get_parent);
@@ -125,60 +157,57 @@
{
if (clk == NULL || IS_ERR(clk))
return -EINVAL;
- return clk->ops->set_flags(clk->id, flags);
+ if (!clk->ops->set_flags)
+ return -ENOSYS;
+
+ return clk->ops->set_flags(clk, flags);
}
EXPORT_SYMBOL(clk_set_flags);
-/* EBI1 is the only shared clock that several clients want to vote on as of
- * this commit. If this changes in the future, then it might be better to
- * make clk_min_rate handle the voting or make ebi1_clk_set_min_rate more
- * generic to support different clocks.
- */
-static struct clk *ebi1_clk;
+static struct clk_lookup *msm_clocks;
+static unsigned msm_num_clocks;
-void __init msm_clock_init(struct clk_lookup *clock_tbl, unsigned num_clocks)
+void __init msm_clock_init(struct clk_lookup *clock_tbl, size_t num_clocks)
{
unsigned n;
- mutex_lock(&clocks_mutex);
for (n = 0; n < num_clocks; n++) {
- clkdev_add(&clock_tbl[n]);
- list_add_tail(&clock_tbl[n].clk->list, &clocks);
+ struct clk *clk = clock_tbl[n].clk;
+ struct clk *parent = clk_get_parent(clk);
+ clk_set_parent(clk, parent);
}
- mutex_unlock(&clocks_mutex);
- ebi1_clk = clk_get(NULL, "ebi1_clk");
- BUG_ON(ebi1_clk == NULL);
-
+ clkdev_add_table(clock_tbl, num_clocks);
+ msm_clocks = clock_tbl;
+ msm_num_clocks = num_clocks;
}
-/* The bootloader and/or AMSS may have left various clocks enabled.
- * Disable any clocks that belong to us (CLKFLAG_AUTO_OFF) but have
- * not been explicitly enabled by a clk_enable() call.
+/*
+ * The bootloader and/or AMSS may have left various clocks enabled.
+ * Disable any clocks that have not been explicitly enabled by a
+ * clk_enable() call and don't have the CLKFLAG_SKIP_AUTO_OFF flag.
*/
static int __init clock_late_init(void)
{
+ unsigned n;
unsigned long flags;
- struct clk *clk;
unsigned count = 0;
- clock_debug_init();
- mutex_lock(&clocks_mutex);
- list_for_each_entry(clk, &clocks, list) {
+ clock_debug_init(msm_clocks, msm_num_clocks);
+ for (n = 0; n < msm_num_clocks; n++) {
+ struct clk *clk = msm_clocks[n].clk;
+
clock_debug_add(clk);
- if (clk->flags & CLKFLAG_AUTO_OFF) {
- spin_lock_irqsave(&clocks_lock, flags);
- if (!clk->count) {
+ if (!(clk->flags & CLKFLAG_SKIP_AUTO_OFF)) {
+ spin_lock_irqsave(&clk->lock, flags);
+ if (!clk->count && clk->ops->auto_off) {
count++;
- clk->ops->auto_off(clk->id);
+ clk->ops->auto_off(clk);
}
- spin_unlock_irqrestore(&clocks_lock, flags);
+ spin_unlock_irqrestore(&clk->lock, flags);
}
}
- mutex_unlock(&clocks_mutex);
pr_info("clock_late_init() disabled %d unused clocks\n", count);
return 0;
}
-
late_initcall(clock_late_init);
-