blob: 873faf114743c99f42e632bb29699b4e15fac7f8 [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);
112
113/*
114 * Generic clock-definition struct and macros
115 */
116struct rcg_clk {
117 bool enabled;
118 void *const ns_reg;
119 void *const md_reg;
120
121 const uint32_t root_en_mask;
122 uint32_t ns_mask;
123 const uint32_t ctl_mask;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700124
Stephen Boydc78d9a72011-07-20 00:46:24 -0700125 void *bank_info;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700126 void (*set_rate)(struct rcg_clk *, struct clk_freq_tbl *);
Stephen Boydc78d9a72011-07-20 00:46:24 -0700127
Tianyi Goubaf6d342011-08-30 21:49:02 -0700128 struct clk_freq_tbl *freq_tbl;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700129 struct clk_freq_tbl *current_freq;
130
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700131 struct branch b;
132 struct clk c;
133};
134
135static inline struct rcg_clk *to_rcg_clk(struct clk *clk)
136{
137 return container_of(clk, struct rcg_clk, c);
138}
139
Matt Wagantall84f43fd2011-08-16 23:28:38 -0700140extern struct clk_freq_tbl rcg_dummy_freq;
141
Matt Wagantall0625ea02011-07-13 18:51:56 -0700142int rcg_clk_enable(struct clk *clk);
143void rcg_clk_disable(struct clk *clk);
144void rcg_clk_auto_off(struct clk *clk);
145int rcg_clk_set_rate(struct clk *clk, unsigned rate);
146int rcg_clk_set_min_rate(struct clk *clk, unsigned rate);
Matt Wagantall0625ea02011-07-13 18:51:56 -0700147unsigned rcg_clk_get_rate(struct clk *clk);
148int rcg_clk_list_rate(struct clk *clk, unsigned n);
149int rcg_clk_is_enabled(struct clk *clk);
150long rcg_clk_round_rate(struct clk *clk, unsigned rate);
151struct clk *rcg_clk_get_parent(struct clk *c);
Matt Wagantall271a6cd2011-09-20 16:06:31 -0700152int rcg_clk_handoff(struct clk *c);
Matt Wagantall0625ea02011-07-13 18:51:56 -0700153
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700154/**
155 * struct fixed_clk - fixed rate clock (used for crystal oscillators)
156 * @rate: output rate
157 * @c: clk
158 */
159struct fixed_clk {
160 unsigned long rate;
161 struct clk c;
162};
163
164static inline struct fixed_clk *to_fixed_clk(struct clk *clk)
165{
166 return container_of(clk, struct fixed_clk, c);
167}
168
169static inline unsigned fixed_clk_get_rate(struct clk *clk)
170{
171 struct fixed_clk *f = to_fixed_clk(clk);
172 return f->rate;
173}
174
175
176/**
177 * struct pll_vote_clk - phase locked loop (HW voteable)
178 * @rate: output rate
179 * @en_reg: enable register
180 * @en_mask: ORed with @en_reg to enable the clock
181 * @status_reg: status register
182 * @parent: clock source
183 * @c: clk
184 */
185struct pll_vote_clk {
186 unsigned long rate;
187
188 void __iomem *const en_reg;
189 const u32 en_mask;
190
191 void __iomem *const status_reg;
192
193 struct clk *parent;
194 struct clk c;
195};
196
197extern struct clk_ops clk_ops_pll_vote;
198
199static inline struct pll_vote_clk *to_pll_vote_clk(struct clk *clk)
200{
201 return container_of(clk, struct pll_vote_clk, c);
202}
203
204/**
205 * struct pll_clk - phase locked loop
206 * @rate: output rate
207 * @mode_reg: enable register
208 * @parent: clock source
209 * @c: clk
210 */
211struct pll_clk {
212 unsigned long rate;
213
214 void __iomem *const mode_reg;
215
216 struct clk *parent;
217 struct clk c;
218};
219
220extern struct clk_ops clk_ops_pll;
221
222static inline struct pll_clk *to_pll_clk(struct clk *clk)
223{
224 return container_of(clk, struct pll_clk, c);
225}
226
Vikram Mulukutla489e39e2011-08-31 18:04:05 -0700227int sr_pll_clk_enable(struct clk *clk);
228
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700229/**
230 * struct branch_clk - branch
231 * @enabled: true if clock is on, false otherwise
232 * @b: branch
233 * @parent: clock source
234 * @c: clk
235 *
236 * An on/off switch with a rate derived from the parent.
237 */
238struct branch_clk {
239 bool enabled;
240 struct branch b;
241 struct clk *parent;
242 struct clk c;
243};
244
245static inline struct branch_clk *to_branch_clk(struct clk *clk)
246{
247 return container_of(clk, struct branch_clk, c);
248}
249
250int branch_clk_enable(struct clk *clk);
251void branch_clk_disable(struct clk *clk);
252struct clk *branch_clk_get_parent(struct clk *clk);
253int branch_clk_set_parent(struct clk *clk, struct clk *parent);
254int branch_clk_is_enabled(struct clk *clk);
255void branch_clk_auto_off(struct clk *clk);
256int branch_clk_reset(struct clk *c, enum clk_reset_action action);
257
258/**
259 * struct measure_clk - for rate measurement debug use
260 * @sample_ticks: sample period in reference clock ticks
261 * @multiplier: measurement scale-up factor
262 * @divider: measurement scale-down factor
263 * @c: clk
264*/
265struct measure_clk {
266 u64 sample_ticks;
267 u32 multiplier;
268 u32 divider;
269 struct clk c;
270};
271
272extern struct clk_ops clk_ops_measure;
273
274static inline struct measure_clk *to_measure_clk(struct clk *clk)
275{
276 return container_of(clk, struct measure_clk, c);
277}
278
279/*
280 * Variables from clock-local driver
281 */
282extern spinlock_t local_clock_reg_lock;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700283extern struct fixed_clk gnd_clk;
284
285/*
286 * Local-clock APIs
287 */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700288bool local_clk_is_local(struct clk *clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700289
290/*
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700291 * Generic set-rate implementations
292 */
293void set_rate_mnd(struct rcg_clk *clk, struct clk_freq_tbl *nf);
294void set_rate_nop(struct rcg_clk *clk, struct clk_freq_tbl *nf);
295void set_rate_mnd_8(struct rcg_clk *clk, struct clk_freq_tbl *nf);
296void set_rate_mnd_banked(struct rcg_clk *clk, struct clk_freq_tbl *nf);
297void set_rate_div_banked(struct rcg_clk *clk, struct clk_freq_tbl *nf);
298
299#endif /* __ARCH_ARM_MACH_MSM_CLOCK_LOCAL_H */
300