blob: be69ae1156c2e1ec6ada47b9b771c16dd68e3b2b [file] [log] [blame]
Colin Crossd8611962010-01-28 16:40:29 -08001/*
2 * arch/arm/mach-tegra/include/mach/clock.h
3 *
4 * Copyright (C) 2010 Google, Inc.
Prashant Gaikwad96a1bd12012-08-06 11:57:42 +05305 * Copyright (c) 2012 NVIDIA CORPORATION. All rights reserved.
Colin Crossd8611962010-01-28 16:40:29 -08006 *
7 * Author:
8 * Colin Cross <ccross@google.com>
9 *
10 * This software is licensed under the terms of the GNU General Public
11 * License version 2, as published by the Free Software Foundation, and
12 * may be copied, distributed, and modified under those terms.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 */
20
21#ifndef __MACH_TEGRA_CLOCK_H
22#define __MACH_TEGRA_CLOCK_H
23
Prashant Gaikwad96a1bd12012-08-06 11:57:42 +053024#include <linux/clk-provider.h>
Jean-Christop PLAGNIOL-VILLARD6d803ba2010-11-17 10:04:33 +010025#include <linux/clkdev.h>
Colin Cross4729fd72011-02-12 16:43:05 -080026#include <linux/list.h>
27#include <linux/spinlock.h>
Colin Crossd8611962010-01-28 16:40:29 -080028
Peter De Schrijver4fccf752012-01-09 05:35:11 +000029#include <mach/clk.h>
30
Colin Crossd8611962010-01-28 16:40:29 -080031#define DIV_BUS (1 << 0)
32#define DIV_U71 (1 << 1)
33#define DIV_U71_FIXED (1 << 2)
34#define DIV_2 (1 << 3)
Colin Cross71fc84c2010-06-07 20:49:46 -070035#define DIV_U16 (1 << 4)
36#define PLL_FIXED (1 << 5)
37#define PLL_HAS_CPCON (1 << 6)
38#define MUX (1 << 7)
39#define PLLD (1 << 8)
40#define PERIPH_NO_RESET (1 << 9)
41#define PERIPH_NO_ENB (1 << 10)
42#define PERIPH_EMC_ENB (1 << 11)
43#define PERIPH_MANUAL_RESET (1 << 12)
44#define PLL_ALT_MISC_REG (1 << 13)
45#define PLLU (1 << 14)
Peter De Schrijver4fccf752012-01-09 05:35:11 +000046#define PLLX (1 << 15)
47#define MUX_PWM (1 << 16)
48#define MUX8 (1 << 17)
49#define DIV_U71_UART (1 << 18)
50#define MUX_CLK_OUT (1 << 19)
51#define PLLM (1 << 20)
52#define DIV_U71_INT (1 << 21)
53#define DIV_U71_IDLE (1 << 22)
Colin Crossd8611962010-01-28 16:40:29 -080054#define ENABLE_ON_INIT (1 << 28)
Peter De Schrijver4fccf752012-01-09 05:35:11 +000055#define PERIPH_ON_APB (1 << 29)
Colin Crossd8611962010-01-28 16:40:29 -080056
57struct clk;
58
Prashant Gaikwad96a1bd12012-08-06 11:57:42 +053059#ifdef CONFIG_COMMON_CLK
60struct clk_tegra;
61#define to_clk_tegra(_hw) container_of(_hw, struct clk_tegra, hw)
62#endif
63
Colin Crossd8611962010-01-28 16:40:29 -080064struct clk_mux_sel {
65 struct clk *input;
66 u32 value;
67};
68
Colin Crossf1519612011-02-12 16:05:31 -080069struct clk_pll_freq_table {
Colin Crossd8611962010-01-28 16:40:29 -080070 unsigned long input_rate;
71 unsigned long output_rate;
72 u16 n;
73 u16 m;
74 u8 p;
75 u8 cpcon;
76};
77
Prashant Gaikwad96a1bd12012-08-06 11:57:42 +053078enum clk_state {
79 UNINITIALIZED = 0,
80 ON,
81 OFF,
82};
83
84#ifndef CONFIG_COMMON_CLK
Colin Crossd8611962010-01-28 16:40:29 -080085struct clk_ops {
86 void (*init)(struct clk *);
87 int (*enable)(struct clk *);
88 void (*disable)(struct clk *);
Colin Crossd8611962010-01-28 16:40:29 -080089 int (*set_parent)(struct clk *, struct clk *);
90 int (*set_rate)(struct clk *, unsigned long);
Colin Crossd8611962010-01-28 16:40:29 -080091 long (*round_rate)(struct clk *, unsigned long);
Dima Zavin2b84cb4f2010-09-02 19:11:11 -070092 void (*reset)(struct clk *, bool);
Peter De Schrijver4fccf752012-01-09 05:35:11 +000093 int (*clk_cfg_ex)(struct clk *,
94 enum tegra_clk_ex_param, u32);
Colin Crossd8611962010-01-28 16:40:29 -080095};
96
Colin Crossd8611962010-01-28 16:40:29 -080097struct clk {
98 /* node for master clocks list */
Colin Crossf1519612011-02-12 16:05:31 -080099 struct list_head node; /* node for list of all clocks */
Colin Crossf1519612011-02-12 16:05:31 -0800100 struct clk_lookup lookup;
101
Colin Crossd8611962010-01-28 16:40:29 -0800102#ifdef CONFIG_DEBUG_FS
Colin Crossf1519612011-02-12 16:05:31 -0800103 struct dentry *dent;
Colin Crossd8611962010-01-28 16:40:29 -0800104#endif
Colin Cross4db4afb2011-02-20 23:35:07 -0800105 bool set;
Colin Crossf1519612011-02-12 16:05:31 -0800106 struct clk_ops *ops;
107 unsigned long rate;
108 unsigned long max_rate;
Colin Cross310992c2011-02-12 16:14:03 -0800109 unsigned long min_rate;
Colin Crossf1519612011-02-12 16:05:31 -0800110 u32 flags;
111 const char *name;
112
113 u32 refcnt;
114 enum clk_state state;
115 struct clk *parent;
116 u32 div;
117 u32 mul;
118
119 const struct clk_mux_sel *inputs;
Colin Crossd8611962010-01-28 16:40:29 -0800120 u32 reg;
121 u32 reg_shift;
Colin Crossd8611962010-01-28 16:40:29 -0800122
Colin Cross310992c2011-02-12 16:14:03 -0800123 struct list_head shared_bus_list;
124
Colin Crossf1519612011-02-12 16:05:31 -0800125 union {
126 struct {
127 unsigned int clk_num;
128 } periph;
129 struct {
130 unsigned long input_min;
131 unsigned long input_max;
132 unsigned long cf_min;
133 unsigned long cf_max;
134 unsigned long vco_min;
135 unsigned long vco_max;
136 const struct clk_pll_freq_table *freq_table;
137 int lock_delay;
Peter De Schrijver4fccf752012-01-09 05:35:11 +0000138 unsigned long fixed_rate;
Colin Crossf1519612011-02-12 16:05:31 -0800139 } pll;
140 struct {
141 u32 sel;
142 u32 reg_mask;
143 } mux;
144 struct {
145 struct clk *main;
146 struct clk *backup;
147 } cpu;
Colin Cross310992c2011-02-12 16:14:03 -0800148 struct {
149 struct list_head node;
150 bool enabled;
151 unsigned long rate;
152 } shared_bus_user;
Colin Crossf1519612011-02-12 16:05:31 -0800153 } u;
Colin Crossd8611962010-01-28 16:40:29 -0800154
Colin Cross4729fd72011-02-12 16:43:05 -0800155 spinlock_t spinlock;
156};
Colin Crossd8611962010-01-28 16:40:29 -0800157
Prashant Gaikwad96a1bd12012-08-06 11:57:42 +0530158#else
159
160struct clk_tegra {
161 /* node for master clocks list */
162 struct list_head node; /* node for list of all clocks */
163 struct clk_lookup lookup;
164 struct clk_hw hw;
165
166 bool set;
167 unsigned long fixed_rate;
168 unsigned long max_rate;
169 unsigned long min_rate;
170 u32 flags;
171 const char *name;
172
173 enum clk_state state;
174 u32 div;
175 u32 mul;
176
177 u32 reg;
178 u32 reg_shift;
179
180 struct list_head shared_bus_list;
181
182 union {
183 struct {
184 unsigned int clk_num;
185 } periph;
186 struct {
187 unsigned long input_min;
188 unsigned long input_max;
189 unsigned long cf_min;
190 unsigned long cf_max;
191 unsigned long vco_min;
192 unsigned long vco_max;
193 const struct clk_pll_freq_table *freq_table;
194 int lock_delay;
195 unsigned long fixed_rate;
196 } pll;
197 struct {
198 u32 sel;
199 u32 reg_mask;
200 } mux;
201 struct {
202 struct clk *main;
203 struct clk *backup;
204 } cpu;
205 struct {
206 struct list_head node;
207 bool enabled;
208 unsigned long rate;
209 } shared_bus_user;
210 } u;
211
212 void (*reset)(struct clk_hw *, bool);
213 int (*clk_cfg_ex)(struct clk_hw *, enum tegra_clk_ex_param, u32);
214};
215#endif /* !CONFIG_COMMON_CLK */
216
Colin Crossd8611962010-01-28 16:40:29 -0800217struct clk_duplicate {
218 const char *name;
219 struct clk_lookup lookup;
220};
221
222struct tegra_clk_init_table {
223 const char *name;
224 const char *parent;
225 unsigned long rate;
226 bool enabled;
227};
228
Prashant Gaikwad96a1bd12012-08-06 11:57:42 +0530229#ifndef CONFIG_COMMON_CLK
Colin Crossd8611962010-01-28 16:40:29 -0800230void clk_init(struct clk *clk);
Colin Cross4729fd72011-02-12 16:43:05 -0800231unsigned long clk_get_rate_locked(struct clk *c);
232int clk_set_rate_locked(struct clk *c, unsigned long rate);
Prashant Gaikwad96a1bd12012-08-06 11:57:42 +0530233int clk_reparent(struct clk *c, struct clk *parent);
234#endif /* !CONFIG_COMMON_CLK */
235
Prashant Gaikwad92fe58f2012-08-06 11:57:43 +0530236void tegra_clk_add(struct clk *c);
Prashant Gaikwad96a1bd12012-08-06 11:57:42 +0530237void tegra2_init_clocks(void);
238void tegra30_init_clocks(void);
239struct clk *tegra_get_clock_by_name(const char *name);
240void tegra_clk_init_from_table(struct tegra_clk_init_table *table);
Colin Crossd8611962010-01-28 16:40:29 -0800241
242#endif