1 /* arch/arm/mach-msm/clock.c
3 * Copyright (C) 2007 Google, Inc.
4 * Copyright (c) 2007-2010, Code Aurora Forum. All rights reserved.
6 * This software is licensed under the terms of the GNU General Public
7 * License version 2, as published by the Free Software Foundation, and
8 * may be copied, distributed, and modified under those terms.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
17 #include <linux/kernel.h>
18 #include <linux/list.h>
19 #include <linux/err.h>
20 #include <linux/spinlock.h>
21 #include <linux/pm_qos_params.h>
24 #include "proc_comm.h"
25 #include "clock-7x30.h"
26 #include "clock-pcom.h"
28 static DEFINE_MUTEX(clocks_mutex);
29 static DEFINE_SPINLOCK(clocks_lock);
30 static LIST_HEAD(clocks);
33 * Standard clock functions defined in include/linux/clk.h
35 struct clk *clk_get(struct device *dev, const char *id)
39 mutex_lock(&clocks_mutex);
41 list_for_each_entry(clk, &clocks, list)
42 if (!strcmp(id, clk->name) && clk->dev == dev)
45 list_for_each_entry(clk, &clocks, list)
46 if (!strcmp(id, clk->name) && clk->dev == NULL)
49 clk = ERR_PTR(-ENOENT);
51 mutex_unlock(&clocks_mutex);
54 EXPORT_SYMBOL(clk_get);
56 void clk_put(struct clk *clk)
59 EXPORT_SYMBOL(clk_put);
61 int clk_enable(struct clk *clk)
64 spin_lock_irqsave(&clocks_lock, flags);
67 clk->ops->enable(clk->id);
68 spin_unlock_irqrestore(&clocks_lock, flags);
71 EXPORT_SYMBOL(clk_enable);
73 void clk_disable(struct clk *clk)
76 spin_lock_irqsave(&clocks_lock, flags);
77 BUG_ON(clk->count == 0);
80 clk->ops->disable(clk->id);
81 spin_unlock_irqrestore(&clocks_lock, flags);
83 EXPORT_SYMBOL(clk_disable);
85 int clk_reset(struct clk *clk, enum clk_reset_action action)
88 clk->ops->reset = &pc_clk_reset;
89 return clk->ops->reset(clk->remote_id, action);
91 EXPORT_SYMBOL(clk_reset);
93 unsigned long clk_get_rate(struct clk *clk)
95 return clk->ops->get_rate(clk->id);
97 EXPORT_SYMBOL(clk_get_rate);
99 int clk_set_rate(struct clk *clk, unsigned long rate)
102 if (clk->flags & CLKFLAG_MAX) {
103 ret = clk->ops->set_max_rate(clk->id, rate);
107 if (clk->flags & CLKFLAG_MIN) {
108 ret = clk->ops->set_min_rate(clk->id, rate);
113 if (clk->flags & CLKFLAG_MAX || clk->flags & CLKFLAG_MIN)
116 return clk->ops->set_rate(clk->id, rate);
118 EXPORT_SYMBOL(clk_set_rate);
120 long clk_round_rate(struct clk *clk, unsigned long rate)
122 return clk->ops->round_rate(clk->id, rate);
124 EXPORT_SYMBOL(clk_round_rate);
126 int clk_set_min_rate(struct clk *clk, unsigned long rate)
128 return clk->ops->set_min_rate(clk->id, rate);
130 EXPORT_SYMBOL(clk_set_min_rate);
132 int clk_set_max_rate(struct clk *clk, unsigned long rate)
134 return clk->ops->set_max_rate(clk->id, rate);
136 EXPORT_SYMBOL(clk_set_max_rate);
138 int clk_set_parent(struct clk *clk, struct clk *parent)
142 EXPORT_SYMBOL(clk_set_parent);
144 struct clk *clk_get_parent(struct clk *clk)
146 return ERR_PTR(-ENOSYS);
148 EXPORT_SYMBOL(clk_get_parent);
150 int clk_set_flags(struct clk *clk, unsigned long flags)
152 if (clk == NULL || IS_ERR(clk))
154 return clk->ops->set_flags(clk->id, flags);
156 EXPORT_SYMBOL(clk_set_flags);
158 /* EBI1 is the only shared clock that several clients want to vote on as of
159 * this commit. If this changes in the future, then it might be better to
160 * make clk_min_rate handle the voting or make ebi1_clk_set_min_rate more
161 * generic to support different clocks.
163 static struct clk *ebi1_clk;
165 static void __init set_clock_ops(struct clk *clk)
168 clk->ops = &clk_ops_pcom;
169 clk->id = clk->remote_id;
173 void __init msm_clock_init(struct clk *clock_tbl, unsigned num_clocks)
177 mutex_lock(&clocks_mutex);
178 for (n = 0; n < num_clocks; n++) {
179 set_clock_ops(&clock_tbl[n]);
180 list_add_tail(&clock_tbl[n].list, &clocks);
182 mutex_unlock(&clocks_mutex);
184 ebi1_clk = clk_get(NULL, "ebi1_clk");
185 BUG_ON(ebi1_clk == NULL);
189 /* The bootloader and/or AMSS may have left various clocks enabled.
190 * Disable any clocks that belong to us (CLKFLAG_AUTO_OFF) but have
191 * not been explicitly enabled by a clk_enable() call.
193 static int __init clock_late_init(void)
200 mutex_lock(&clocks_mutex);
201 list_for_each_entry(clk, &clocks, list) {
202 clock_debug_add(clk);
203 if (clk->flags & CLKFLAG_AUTO_OFF) {
204 spin_lock_irqsave(&clocks_lock, flags);
207 clk->ops->auto_off(clk->id);
209 spin_unlock_irqrestore(&clocks_lock, flags);
212 mutex_unlock(&clocks_mutex);
213 pr_info("clock_late_init() disabled %d unused clocks\n", count);
217 late_initcall(clock_late_init);