Merge tag 'power-exynos' of git://git.kernel.org/pub/scm/linux/kernel/git/kgene/linux...
[deliverable/linux.git] / arch / arm / plat-samsung / include / plat / cpu-freq-core.h
CommitLineData
dc98e414 1/* arch/arm/plat-samsung/include/plat/cpu-freq-core.h
2e4ea6e8 2 *
ccae941e 3 * Copyright (c) 2006-2009 Simtec Electronics
2e4ea6e8
BD
4 * http://armlinux.simtec.co.uk/
5 * Ben Dooks <ben@simtec.co.uk>
6 *
7 * S3C CPU frequency scaling support - core support
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12*/
13
14#include <plat/cpu-freq.h>
15
e6d197a6
BD
16struct seq_file;
17
2e4ea6e8
BD
18#define MAX_BANKS (8)
19#define S3C2412_MAX_IO (8)
20
21/**
22 * struct s3c2410_iobank_timing - IO bank timings for S3C2410 style timings
23 * @bankcon: The cached version of settings in this structure.
24 * @tacp:
25 * @tacs: Time from address valid to nCS asserted.
26 * @tcos: Time from nCS asserted to nOE or nWE asserted.
27 * @tacc: Time that nOE or nWE is asserted.
28 * @tcoh: Time nCS is held after nOE or nWE are released.
29 * @tcah: Time address is held for after
30 * @nwait_en: Whether nWAIT is enabled for this bank.
31 *
32 * This structure represents the IO timings for a S3C2410 style IO bank
33 * used by the CPU frequency support if it needs to change the settings
34 * of the IO.
35 */
36struct s3c2410_iobank_timing {
37 unsigned long bankcon;
38 unsigned int tacp;
39 unsigned int tacs;
40 unsigned int tcos;
41 unsigned int tacc;
42 unsigned int tcoh; /* nCS hold afrer nOE/nWE */
43 unsigned int tcah; /* Address hold after nCS */
44 unsigned char nwait_en; /* nWait enabled for bank. */
45};
46
140780ab
BD
47/**
48 * struct s3c2412_iobank_timing - io timings for PL092 (S3C2412) style IO
49 * @idcy: The idle cycle time between transactions.
50 * @wstrd: nCS release to end of read cycle.
51 * @wstwr: nCS release to end of write cycle.
52 * @wstoen: nCS assertion to nOE assertion time.
53 * @wstwen: nCS assertion to nWE assertion time.
54 * @wstbrd: Burst ready delay.
55 * @smbidcyr: Register cache for smbidcyr value.
56 * @smbwstrd: Register cache for smbwstrd value.
57 * @smbwstwr: Register cache for smbwstwr value.
58 * @smbwstoen: Register cache for smbwstoen value.
59 * @smbwstwen: Register cache for smbwstwen value.
60 * @smbwstbrd: Register cache for smbwstbrd value.
61 *
62 * Timing information for a IO bank on an S3C2412 or similar system which
63 * uses a PL093 block.
64 */
65struct s3c2412_iobank_timing {
66 unsigned int idcy;
67 unsigned int wstrd;
68 unsigned int wstwr;
69 unsigned int wstoen;
70 unsigned int wstwen;
71 unsigned int wstbrd;
72
73 /* register cache */
74 unsigned char smbidcyr;
75 unsigned char smbwstrd;
76 unsigned char smbwstwr;
77 unsigned char smbwstoen;
78 unsigned char smbwstwen;
79 unsigned char smbwstbrd;
80};
81
2e4ea6e8 82union s3c_iobank {
140780ab
BD
83 struct s3c2410_iobank_timing *io_2410;
84 struct s3c2412_iobank_timing *io_2412;
2e4ea6e8
BD
85};
86
87/**
88 * struct s3c_iotimings - Chip IO timings holder
89 * @bank: The timings for each IO bank.
90 */
91struct s3c_iotimings {
92 union s3c_iobank bank[MAX_BANKS];
93};
94
95/**
96 * struct s3c_plltab - PLL table information.
97 * @vals: List of PLL values.
98 * @size: Size of the PLL table @vals.
99 */
100struct s3c_plltab {
101 struct s3c_pllval *vals;
102 int size;
103};
104
d6fc87d3
BD
105/**
106 * struct s3c_cpufreq_config - current cpu frequency configuration
107 * @freq: The current settings for the core clocks.
108 * @max: Maxium settings, derived from core, board and user settings.
109 * @pll: The PLL table entry for the current PLL settings.
110 * @divs: The divisor settings for the core clocks.
111 * @info: The current core driver information.
112 * @board: The information for the board we are running on.
113 * @lock_pll: Set if the PLL settings cannot be changed.
114 *
115 * This is for the core drivers that need to know information about
116 * the current settings and values. It should not be needed by any
117 * device drivers.
118*/
119struct s3c_cpufreq_config {
120 struct s3c_freq freq;
121 struct s3c_freq max;
d8b53257 122 struct clk *mpll;
d6fc87d3
BD
123 struct cpufreq_frequency_table pll;
124 struct s3c_clkdivs divs;
125 struct s3c_cpufreq_info *info; /* for core, not drivers */
126 struct s3c_cpufreq_board *board;
127
128 unsigned int lock_pll:1;
129};
130
2e4ea6e8
BD
131/**
132 * struct s3c_cpufreq_info - Information for the CPU frequency driver.
133 * @name: The name of this implementation.
134 * @max: The maximum frequencies for the system.
135 * @latency: Transition latency to give to cpufreq.
136 * @locktime_m: The lock-time in uS for the MPLL.
137 * @locktime_u: The lock-time in uS for the UPLL.
138 * @locttime_bits: The number of bits each LOCKTIME field.
3ad2f3fb 139 * @need_pll: Set if this driver needs to change the PLL values to achieve
2e4ea6e8
BD
140 * any frequency changes. This is really only need by devices like the
141 * S3C2410 where there is no or limited divider between the PLL and the
142 * ARMCLK.
143 * @resume_clocks: Update the clocks on resume.
144 * @get_iotiming: Get the current IO timing data, mainly for use at start.
145 * @set_iotiming: Update the IO timings from the cached copies calculated
146 * from the @calc_iotiming entry when changing the frequency.
147 * @calc_iotiming: Calculate and update the cached copies of the IO timings
148 * from the newly calculated frequencies.
149 * @calc_freqtable: Calculate (fill in) the given frequency table from the
150 * current frequency configuration. If the table passed in is NULL,
151 * then the return is the number of elements to be filled for allocation
152 * of the table.
153 * @set_refresh: Set the memory refresh configuration.
154 * @set_fvco: Set the PLL frequencies.
155 * @set_divs: Update the clock divisors.
156 * @calc_divs: Calculate the clock divisors.
157 */
158struct s3c_cpufreq_info {
159 const char *name;
160 struct s3c_freq max;
161
162 unsigned int latency;
163
164 unsigned int locktime_m;
165 unsigned int locktime_u;
166 unsigned char locktime_bits;
167
168 unsigned int need_pll:1;
169
170 /* driver routines */
171
172 void (*resume_clocks)(void);
173
174 int (*get_iotiming)(struct s3c_cpufreq_config *cfg,
175 struct s3c_iotimings *timings);
176
177 void (*set_iotiming)(struct s3c_cpufreq_config *cfg,
178 struct s3c_iotimings *timings);
179
180 int (*calc_iotiming)(struct s3c_cpufreq_config *cfg,
181 struct s3c_iotimings *timings);
182
183 int (*calc_freqtable)(struct s3c_cpufreq_config *cfg,
184 struct cpufreq_frequency_table *t,
185 size_t table_size);
186
e6d197a6
BD
187 void (*debug_io_show)(struct seq_file *seq,
188 struct s3c_cpufreq_config *cfg,
189 union s3c_iobank *iob);
190
2e4ea6e8
BD
191 void (*set_refresh)(struct s3c_cpufreq_config *cfg);
192 void (*set_fvco)(struct s3c_cpufreq_config *cfg);
193 void (*set_divs)(struct s3c_cpufreq_config *cfg);
194 int (*calc_divs)(struct s3c_cpufreq_config *cfg);
195};
196
197extern int s3c_cpufreq_register(struct s3c_cpufreq_info *info);
198
dc98e414
KK
199extern int s3c_plltab_register(struct cpufreq_frequency_table *plls,
200 unsigned int plls_no);
2e4ea6e8 201
e6d197a6
BD
202/* exports and utilities for debugfs */
203extern struct s3c_cpufreq_config *s3c_cpufreq_getconfig(void);
204extern struct s3c_iotimings *s3c_cpufreq_getiotimings(void);
205
f023f8dd 206#ifdef CONFIG_ARM_S3C24XX_CPUFREQ_DEBUGFS
e6d197a6
BD
207#define s3c_cpufreq_debugfs_call(x) x
208#else
209#define s3c_cpufreq_debugfs_call(x) NULL
210#endif
211
2e4ea6e8
BD
212/* Useful utility functions. */
213
214extern struct clk *s3c_cpufreq_clk_get(struct device *, const char *);
215
216/* S3C2410 and compatible exported functions */
217
218extern void s3c2410_cpufreq_setrefresh(struct s3c_cpufreq_config *cfg);
2e31de65 219extern void s3c2410_set_fvco(struct s3c_cpufreq_config *cfg);
2e4ea6e8 220
2e31de65 221#ifdef CONFIG_S3C2410_IOTIMING
baaf939d
DK
222extern void s3c2410_iotiming_debugfs(struct seq_file *seq,
223 struct s3c_cpufreq_config *cfg,
224 union s3c_iobank *iob);
225
2e4ea6e8
BD
226extern int s3c2410_iotiming_calc(struct s3c_cpufreq_config *cfg,
227 struct s3c_iotimings *iot);
228
229extern int s3c2410_iotiming_get(struct s3c_cpufreq_config *cfg,
230 struct s3c_iotimings *timings);
231
232extern void s3c2410_iotiming_set(struct s3c_cpufreq_config *cfg,
233 struct s3c_iotimings *iot);
2e31de65 234#else
baaf939d 235#define s3c2410_iotiming_debugfs NULL
2e31de65
BD
236#define s3c2410_iotiming_calc NULL
237#define s3c2410_iotiming_get NULL
238#define s3c2410_iotiming_set NULL
239#endif /* CONFIG_S3C2410_IOTIMING */
2e4ea6e8 240
140780ab
BD
241/* S3C2412 compatible routines */
242
baaf939d
DK
243#ifdef CONFIG_S3C2412_IOTIMING
244extern void s3c2412_iotiming_debugfs(struct seq_file *seq,
245 struct s3c_cpufreq_config *cfg,
246 union s3c_iobank *iob);
140780ab
BD
247
248extern int s3c2412_iotiming_get(struct s3c_cpufreq_config *cfg,
249 struct s3c_iotimings *timings);
250
251extern int s3c2412_iotiming_calc(struct s3c_cpufreq_config *cfg,
252 struct s3c_iotimings *iot);
253
254extern void s3c2412_iotiming_set(struct s3c_cpufreq_config *cfg,
255 struct s3c_iotimings *iot);
baaf939d
DK
256#else
257#define s3c2412_iotiming_debugfs NULL
258#define s3c2412_iotiming_calc NULL
259#define s3c2412_iotiming_get NULL
260#define s3c2412_iotiming_set NULL
261#endif /* CONFIG_S3C2412_IOTIMING */
140780ab 262
f023f8dd 263#ifdef CONFIG_ARM_S3C24XX_CPUFREQ_DEBUG
2e4ea6e8
BD
264#define s3c_freq_dbg(x...) printk(KERN_INFO x)
265#else
266#define s3c_freq_dbg(x...) do { if (0) printk(x); } while (0)
f023f8dd 267#endif /* CONFIG_ARM_S3C24XX_CPUFREQ_DEBUG */
2e4ea6e8 268
f023f8dd 269#ifdef CONFIG_ARM_S3C24XX_CPUFREQ_IODEBUG
2e4ea6e8
BD
270#define s3c_freq_iodbg(x...) printk(KERN_INFO x)
271#else
272#define s3c_freq_iodbg(x...) do { if (0) printk(x); } while (0)
f023f8dd 273#endif /* CONFIG_ARM_S3C24XX_CPUFREQ_IODEBUG */
2e4ea6e8
BD
274
275static inline int s3c_cpufreq_addfreq(struct cpufreq_frequency_table *table,
276 int index, size_t table_size,
277 unsigned int freq)
278{
279 if (index < 0)
280 return index;
281
282 if (table) {
283 if (index >= table_size)
284 return -ENOMEM;
285
286 s3c_freq_dbg("%s: { %d = %u kHz }\n",
287 __func__, index, freq);
288
50701588 289 table[index].driver_data = index;
2e4ea6e8
BD
290 table[index].frequency = freq;
291 }
292
293 return index + 1;
294}
This page took 0.314689 seconds and 5 git commands to generate.