blob: 31f64ce41586873a3278e007a179a845fc62c056 [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/* Copyright (c) 2009-2011, Code Aurora Forum. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 */
13
14#ifndef __ARCH_ARM_MACH_MSM_CLOCK_LOCAL_H
15#define __ARCH_ARM_MACH_MSM_CLOCK_LOCAL_H
16
17#include <linux/spinlock.h>
18#include "clock.h"
19
20/*
21 * Bit manipulation macros
22 */
23#define BM(msb, lsb) (((((uint32_t)-1) << (31-msb)) >> (31-msb+lsb)) << lsb)
24#define BVAL(msb, lsb, val) (((val) << lsb) & BM(msb, lsb))
25
26/*
27 * Halt/Status Checking Mode Macros
28 */
29#define HALT 0 /* Bit pol: 1 = halted */
30#define NOCHECK 1 /* No bit to check, do nothing */
31#define HALT_VOTED 2 /* Bit pol: 1 = halted; delay on disable */
32#define ENABLE 3 /* Bit pol: 1 = running */
33#define ENABLE_VOTED 4 /* Bit pol: 1 = running; delay on disable */
34#define DELAY 5 /* No bit to check, just delay */
35
36/*
37 * Clock Definition Macros
38 */
39#define DEFINE_CLK_MEASURE(name) \
40 struct clk name = { \
41 .ops = &clk_ops_measure, \
42 .dbg_name = #name, \
43 CLK_INIT(name), \
44 }; \
45
46/*
47 * Generic frequency-definition structs and macros
48 */
49struct clk_freq_tbl {
50 const uint32_t freq_hz;
51 struct clk *src_clk;
52 const uint32_t md_val;
53 const uint32_t ns_val;
54 const uint32_t ctl_val;
55 uint32_t mnd_en_mask;
56 const unsigned sys_vdd;
57 void *const extra_freq_data;
58};
59
60/* Some clocks have two banks to avoid glitches when switching frequencies.
61 * The unused bank is programmed while running on the other bank, and
62 * switched to afterwards. The following two structs describe the banks. */
63struct bank_mask_info {
64 void *const md_reg;
65 const uint32_t ns_mask;
66 const uint32_t rst_mask;
67 const uint32_t mnd_en_mask;
68 const uint32_t mode_mask;
69};
70
71struct bank_masks {
72 const uint32_t bank_sel_mask;
73 const struct bank_mask_info bank0_mask;
74 const struct bank_mask_info bank1_mask;
75};
76
Matt Wagantalle18bbc82011-10-06 10:07:28 -070077#define F_RAW(f, sc, m_v, n_v, c_v, m_m, e) { \
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070078 .freq_hz = f, \
79 .src_clk = sc, \
80 .md_val = m_v, \
81 .ns_val = n_v, \
82 .ctl_val = c_v, \
83 .mnd_en_mask = m_m, \
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070084 .extra_freq_data = e, \
85 }
86#define FREQ_END (UINT_MAX-1)
Matt Wagantalle18bbc82011-10-06 10:07:28 -070087#define F_END { .freq_hz = FREQ_END }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070088
89/**
90 * struct branch - branch on/off
91 * @ctl_reg: clock control register
92 * @en_mask: ORed with @ctl_reg to enable the clock
93 * @halt_reg: halt register
94 * @halt_check: type of halt check to perform
95 * @halt_bit: ANDed with @halt_reg to test for clock halted
96 * @reset_reg: reset register
97 * @reset_mask: ORed with @reset_reg to reset the clock domain
98 */
99struct branch {
100 void __iomem *const ctl_reg;
101 const u32 en_mask;
102
103 void __iomem *const halt_reg;
104 const u16 halt_check;
105 const u16 halt_bit;
106
107 void __iomem *const reset_reg;
108 const u32 reset_mask;
109};
110
111int branch_reset(struct branch *clk, enum clk_reset_action action);
Stephen Boyd092fd182011-10-21 15:56:30 -0700112void __branch_clk_enable_reg(const struct branch *clk, const char *name);
113u32 __branch_clk_disable_reg(const struct branch *clk, const char *name);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700114
115/*
116 * Generic clock-definition struct and macros
117 */
118struct rcg_clk {
119 bool enabled;
120 void *const ns_reg;
121 void *const md_reg;
122
123 const uint32_t root_en_mask;
124 uint32_t ns_mask;
125 const uint32_t ctl_mask;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700126
Stephen Boydc78d9a72011-07-20 00:46:24 -0700127 void *bank_info;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700128 void (*set_rate)(struct rcg_clk *, struct clk_freq_tbl *);
Stephen Boydc78d9a72011-07-20 00:46:24 -0700129
Tianyi Goubaf6d342011-08-30 21:49:02 -0700130 struct clk_freq_tbl *freq_tbl;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700131 struct clk_freq_tbl *current_freq;
132
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700133 struct branch b;
134 struct clk c;
135};
136
137static inline struct rcg_clk *to_rcg_clk(struct clk *clk)
138{
139 return container_of(clk, struct rcg_clk, c);
140}
141
Matt Wagantall84f43fd2011-08-16 23:28:38 -0700142extern struct clk_freq_tbl rcg_dummy_freq;
143
Matt Wagantall0625ea02011-07-13 18:51:56 -0700144int rcg_clk_enable(struct clk *clk);
145void rcg_clk_disable(struct clk *clk);
Matt Wagantall9de3bfb2011-11-03 20:13:12 -0700146int rcg_clk_set_rate(struct clk *clk, unsigned long rate);
Matt Wagantall9de3bfb2011-11-03 20:13:12 -0700147unsigned long rcg_clk_get_rate(struct clk *clk);
Matt Wagantall0625ea02011-07-13 18:51:56 -0700148int rcg_clk_list_rate(struct clk *clk, unsigned n);
149int rcg_clk_is_enabled(struct clk *clk);
Matt Wagantall9de3bfb2011-11-03 20:13:12 -0700150long rcg_clk_round_rate(struct clk *clk, unsigned long rate);
Matt Wagantall0625ea02011-07-13 18:51:56 -0700151struct clk *rcg_clk_get_parent(struct clk *c);
Matt Wagantall271a6cd2011-09-20 16:06:31 -0700152int rcg_clk_handoff(struct clk *c);
Stephen Boyd7bf28142011-12-07 00:30:52 -0800153int rcg_clk_reset(struct clk *clk, enum clk_reset_action action);
Matt Wagantall0625ea02011-07-13 18:51:56 -0700154
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700155/**
Stephen Boydb8ad8222011-11-28 12:17:58 -0800156 * struct cdiv_clk - integer divider clock with external source selection
157 * @ns_reg: source select and divider settings register
158 * @ext_mask: bit to set to select an external source
159 * @cur_div: current divider setting (or 0 for external source)
160 * @max_div: maximum divider value supported (must be power of 2)
161 * @div_offset: number of bits to shift divider left by in @ns_reg
162 * @b: branch
163 * @c: clock
164 */
165struct cdiv_clk {
166 void __iomem *const ns_reg;
167 u32 ext_mask;
168
169 unsigned long cur_div;
170 u8 div_offset;
171 u32 max_div;
172
173 struct branch b;
174 struct clk c;
175};
176
177static inline struct cdiv_clk *to_cdiv_clk(struct clk *clk)
178{
179 return container_of(clk, struct cdiv_clk, c);
180}
181
182extern struct clk_ops clk_ops_cdiv;
183
184/**
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700185 * struct fixed_clk - fixed rate clock (used for crystal oscillators)
186 * @rate: output rate
187 * @c: clk
188 */
189struct fixed_clk {
190 unsigned long rate;
191 struct clk c;
192};
193
194static inline struct fixed_clk *to_fixed_clk(struct clk *clk)
195{
196 return container_of(clk, struct fixed_clk, c);
197}
198
Matt Wagantall9de3bfb2011-11-03 20:13:12 -0700199static inline unsigned long fixed_clk_get_rate(struct clk *clk)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700200{
201 struct fixed_clk *f = to_fixed_clk(clk);
202 return f->rate;
203}
204
205
206/**
207 * struct pll_vote_clk - phase locked loop (HW voteable)
208 * @rate: output rate
Vikram Mulukutla31680ae2011-11-04 14:23:55 -0700209 * @soft_vote: soft voting variable for multiple PLL software instances
210 * @soft_vote_mask: soft voting mask for multiple PLL software instances
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700211 * @en_reg: enable register
212 * @en_mask: ORed with @en_reg to enable the clock
213 * @status_reg: status register
214 * @parent: clock source
215 * @c: clk
216 */
217struct pll_vote_clk {
218 unsigned long rate;
219
Vikram Mulukutla31680ae2011-11-04 14:23:55 -0700220 u32 *soft_vote;
221 const u32 soft_vote_mask;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700222 void __iomem *const en_reg;
223 const u32 en_mask;
224
225 void __iomem *const status_reg;
226
227 struct clk *parent;
228 struct clk c;
229};
230
231extern struct clk_ops clk_ops_pll_vote;
232
233static inline struct pll_vote_clk *to_pll_vote_clk(struct clk *clk)
234{
235 return container_of(clk, struct pll_vote_clk, c);
236}
237
238/**
239 * struct pll_clk - phase locked loop
240 * @rate: output rate
241 * @mode_reg: enable register
242 * @parent: clock source
243 * @c: clk
244 */
245struct pll_clk {
246 unsigned long rate;
247
248 void __iomem *const mode_reg;
249
250 struct clk *parent;
251 struct clk c;
252};
253
254extern struct clk_ops clk_ops_pll;
255
256static inline struct pll_clk *to_pll_clk(struct clk *clk)
257{
258 return container_of(clk, struct pll_clk, c);
259}
260
Vikram Mulukutla489e39e2011-08-31 18:04:05 -0700261int sr_pll_clk_enable(struct clk *clk);
262
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700263/**
264 * struct branch_clk - branch
265 * @enabled: true if clock is on, false otherwise
266 * @b: branch
267 * @parent: clock source
268 * @c: clk
269 *
270 * An on/off switch with a rate derived from the parent.
271 */
272struct branch_clk {
273 bool enabled;
274 struct branch b;
275 struct clk *parent;
276 struct clk c;
277};
278
279static inline struct branch_clk *to_branch_clk(struct clk *clk)
280{
281 return container_of(clk, struct branch_clk, c);
282}
283
284int branch_clk_enable(struct clk *clk);
285void branch_clk_disable(struct clk *clk);
286struct clk *branch_clk_get_parent(struct clk *clk);
287int branch_clk_set_parent(struct clk *clk, struct clk *parent);
288int branch_clk_is_enabled(struct clk *clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700289int branch_clk_reset(struct clk *c, enum clk_reset_action action);
290
291/**
292 * struct measure_clk - for rate measurement debug use
293 * @sample_ticks: sample period in reference clock ticks
294 * @multiplier: measurement scale-up factor
295 * @divider: measurement scale-down factor
296 * @c: clk
297*/
298struct measure_clk {
299 u64 sample_ticks;
300 u32 multiplier;
301 u32 divider;
302 struct clk c;
303};
304
305extern struct clk_ops clk_ops_measure;
306
307static inline struct measure_clk *to_measure_clk(struct clk *clk)
308{
309 return container_of(clk, struct measure_clk, c);
310}
311
312/*
313 * Variables from clock-local driver
314 */
315extern spinlock_t local_clock_reg_lock;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700316extern struct fixed_clk gnd_clk;
317
318/*
319 * Local-clock APIs
320 */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700321bool local_clk_is_local(struct clk *clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700322
323/*
Vikram Mulukutla31680ae2011-11-04 14:23:55 -0700324 * PLL vote clock APIs
325 */
326int pll_vote_clk_enable(struct clk *clk);
327void pll_vote_clk_disable(struct clk *clk);
328unsigned long pll_vote_clk_get_rate(struct clk *clk);
329struct clk *pll_vote_clk_get_parent(struct clk *clk);
330int pll_vote_clk_is_enabled(struct clk *clk);
331
332/*
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700333 * Generic set-rate implementations
334 */
335void set_rate_mnd(struct rcg_clk *clk, struct clk_freq_tbl *nf);
336void set_rate_nop(struct rcg_clk *clk, struct clk_freq_tbl *nf);
337void set_rate_mnd_8(struct rcg_clk *clk, struct clk_freq_tbl *nf);
338void set_rate_mnd_banked(struct rcg_clk *clk, struct clk_freq_tbl *nf);
339void set_rate_div_banked(struct rcg_clk *clk, struct clk_freq_tbl *nf);
340
341#endif /* __ARCH_ARM_MACH_MSM_CLOCK_LOCAL_H */
342