3 * Copyright (C) 2010 Google, Inc.
4 * Copyright (c) 2012 NVIDIA CORPORATION. All rights reserved.
7 * Colin Cross <ccross@google.com>
9 * This software is licensed under the terms of the GNU General Public
10 * License version 2, as published by the Free Software Foundation, and
11 * may be copied, distributed, and modified under those terms.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
20 #include <linux/kernel.h>
21 #include <linux/clk.h>
22 #include <linux/clkdev.h>
23 #include <linux/init.h>
24 #include <linux/list.h>
25 #include <linux/module.h>
26 #include <linux/sched.h>
27 #include <linux/seq_file.h>
28 #include <linux/slab.h>
34 #include "tegra_cpu_car.h"
36 /* Global data of Tegra CPU CAR ops */
37 struct tegra_cpu_car_ops *tegra_cpu_car_ops;
42 * An additional mutex, clock_list_lock, is used to protect the list of all
46 static DEFINE_MUTEX(clock_list_lock);
47 static LIST_HEAD(clocks);
49 void tegra_clk_add(struct clk *clk)
51 struct clk_tegra *c = to_clk_tegra(__clk_get_hw(clk));
53 mutex_lock(&clock_list_lock);
54 list_add(&c->node, &clocks);
55 mutex_unlock(&clock_list_lock);
58 struct clk *tegra_get_clock_by_name(const char *name)
61 struct clk *ret = NULL;
62 mutex_lock(&clock_list_lock);
63 list_for_each_entry(c, &clocks, node) {
64 if (strcmp(__clk_get_name(c->hw.clk), name) == 0) {
69 mutex_unlock(&clock_list_lock);
73 static int tegra_clk_init_one_from_table(struct tegra_clk_init_table *table)
81 c = tegra_get_clock_by_name(table->name);
84 pr_warn("Unable to initialize clock %s\n",
89 parent = clk_get_parent(c);
92 p = tegra_get_clock_by_name(table->parent);
94 pr_warn("Unable to find parent %s of clock %s\n",
95 table->parent, table->name);
100 ret = clk_set_parent(c, p);
102 pr_warn("Unable to set parent %s of clock %s: %d\n",
103 table->parent, table->name, ret);
109 if (table->rate && table->rate != clk_get_rate(c)) {
110 ret = clk_set_rate(c, table->rate);
112 pr_warn("Unable to set clock %s to rate %lu: %d\n",
113 table->name, table->rate, ret);
118 if (table->enabled) {
119 ret = clk_prepare_enable(c);
121 pr_warn("Unable to enable clock %s: %d\n",
130 void tegra_clk_init_from_table(struct tegra_clk_init_table *table)
132 for (; table->name; table++)
133 tegra_clk_init_one_from_table(table);
136 void tegra_periph_reset_deassert(struct clk *c)
138 struct clk_tegra *clk = to_clk_tegra(__clk_get_hw(c));
140 clk->reset(__clk_get_hw(c), false);
142 EXPORT_SYMBOL(tegra_periph_reset_deassert);
144 void tegra_periph_reset_assert(struct clk *c)
146 struct clk_tegra *clk = to_clk_tegra(__clk_get_hw(c));
148 clk->reset(__clk_get_hw(c), true);
150 EXPORT_SYMBOL(tegra_periph_reset_assert);
152 /* Several extended clock configuration bits (e.g., clock routing, clock
153 * phase control) are included in PLL and peripheral clock source
155 int tegra_clk_cfg_ex(struct clk *c, enum tegra_clk_ex_param p, u32 setting)
158 struct clk_tegra *clk = to_clk_tegra(__clk_get_hw(c));
160 if (!clk->clk_cfg_ex) {
164 ret = clk->clk_cfg_ex(__clk_get_hw(c), p, setting);