blob: b3bbf3feef753cdf7150adda0fe6a26af2ba7bca [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/arm/mach-pxa/pxa27x.c
3 *
4 * Author: Nicolas Pitre
5 * Created: Nov 05, 2002
6 * Copyright: MontaVista Software Inc.
7 *
8 * Code specific to PXA27x aka Bulverde.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/module.h>
15#include <linux/kernel.h>
16#include <linux/init.h>
17#include <linux/pm.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010018#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
20#include <asm/hardware.h>
21#include <asm/irq.h>
Eric Miaocd491042007-06-22 04:14:09 +010022#include <asm/arch/irqs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <asm/arch/pxa-regs.h>
Richard Purdie81f280e2005-11-12 14:22:11 +000024#include <asm/arch/ohci.h>
Russell Kinge176bb02007-05-15 11:16:10 +010025#include <asm/arch/pm.h>
Eric Miaof53f0662007-06-22 05:40:17 +010026#include <asm/arch/dma.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
28#include "generic.h"
Russell King46c41e62007-05-15 15:39:36 +010029#include "devices.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
31/* Crystal clock: 13MHz */
32#define BASE_CLK 13000000
33
34/*
35 * Get the clock frequency as reflected by CCSR and the turbo flag.
36 * We assume these values have been applied via a fcs.
37 * If info is not 0 we also display the current settings.
38 */
Russell King15a40332007-08-20 10:07:44 +010039unsigned int pxa27x_get_clk_frequency_khz(int info)
Linus Torvalds1da177e2005-04-16 15:20:36 -070040{
41 unsigned long ccsr, clkcfg;
42 unsigned int l, L, m, M, n2, N, S;
43 int cccr_a, t, ht, b;
44
45 ccsr = CCSR;
46 cccr_a = CCCR & (1 << 25);
47
48 /* Read clkcfg register: it has turbo, b, half-turbo (and f) */
49 asm( "mrc\tp14, 0, %0, c6, c0, 0" : "=r" (clkcfg) );
Richard Purdieafe5df22006-02-01 19:25:59 +000050 t = clkcfg & (1 << 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 ht = clkcfg & (1 << 2);
52 b = clkcfg & (1 << 3);
53
54 l = ccsr & 0x1f;
55 n2 = (ccsr>>7) & 0xf;
56 m = (l <= 10) ? 1 : (l <= 20) ? 2 : 4;
57
58 L = l * BASE_CLK;
59 N = (L * n2) / 2;
60 M = (!cccr_a) ? (L/m) : ((b) ? L : (L/2));
61 S = (b) ? L : (L/2);
62
63 if (info) {
64 printk( KERN_INFO "Run Mode clock: %d.%02dMHz (*%d)\n",
65 L / 1000000, (L % 1000000) / 10000, l );
66 printk( KERN_INFO "Turbo Mode clock: %d.%02dMHz (*%d.%d, %sactive)\n",
67 N / 1000000, (N % 1000000)/10000, n2 / 2, (n2 % 2)*5,
68 (t) ? "" : "in" );
69 printk( KERN_INFO "Memory clock: %d.%02dMHz (/%d)\n",
70 M / 1000000, (M % 1000000) / 10000, m );
71 printk( KERN_INFO "System bus clock: %d.%02dMHz \n",
72 S / 1000000, (S % 1000000) / 10000 );
73 }
74
75 return (t) ? (N/1000) : (L/1000);
76}
77
78/*
79 * Return the current mem clock frequency in units of 10kHz as
80 * reflected by CCCR[A], B, and L
81 */
Russell King15a40332007-08-20 10:07:44 +010082unsigned int pxa27x_get_memclk_frequency_10khz(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070083{
84 unsigned long ccsr, clkcfg;
85 unsigned int l, L, m, M;
86 int cccr_a, b;
87
88 ccsr = CCSR;
89 cccr_a = CCCR & (1 << 25);
90
91 /* Read clkcfg register: it has turbo, b, half-turbo (and f) */
92 asm( "mrc\tp14, 0, %0, c6, c0, 0" : "=r" (clkcfg) );
93 b = clkcfg & (1 << 3);
94
95 l = ccsr & 0x1f;
96 m = (l <= 10) ? 1 : (l <= 20) ? 2 : 4;
97
98 L = l * BASE_CLK;
99 M = (!cccr_a) ? (L/m) : ((b) ? L : (L/2));
100
101 return (M / 10000);
102}
103
104/*
105 * Return the current LCD clock frequency in units of 10kHz as
106 */
Russell King15a40332007-08-20 10:07:44 +0100107unsigned int pxa27x_get_lcdclk_frequency_10khz(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108{
109 unsigned long ccsr;
110 unsigned int l, L, k, K;
111
112 ccsr = CCSR;
113
114 l = ccsr & 0x1f;
115 k = (l <= 7) ? 1 : (l <= 16) ? 2 : 4;
116
117 L = l * BASE_CLK;
118 K = L / k;
119
120 return (K / 10000);
121}
122
Nicolas Pitrea8fa3f02005-06-13 22:35:41 +0100123#ifdef CONFIG_PM
124
Eric Miao711be5c2007-07-18 11:38:45 +0100125#define SAVE(x) sleep_save[SLEEP_SAVE_##x] = x
126#define RESTORE(x) x = sleep_save[SLEEP_SAVE_##x]
127
128#define RESTORE_GPLEVEL(n) do { \
129 GPSR##n = sleep_save[SLEEP_SAVE_GPLR##n]; \
130 GPCR##n = ~sleep_save[SLEEP_SAVE_GPLR##n]; \
131} while (0)
132
133/*
134 * List of global PXA peripheral registers to preserve.
135 * More ones like CP and general purpose register values are preserved
136 * with the stack pointer in sleep.S.
137 */
138enum { SLEEP_SAVE_START = 0,
139
140 SLEEP_SAVE_GPLR0, SLEEP_SAVE_GPLR1, SLEEP_SAVE_GPLR2, SLEEP_SAVE_GPLR3,
141 SLEEP_SAVE_GPDR0, SLEEP_SAVE_GPDR1, SLEEP_SAVE_GPDR2, SLEEP_SAVE_GPDR3,
142 SLEEP_SAVE_GRER0, SLEEP_SAVE_GRER1, SLEEP_SAVE_GRER2, SLEEP_SAVE_GRER3,
143 SLEEP_SAVE_GFER0, SLEEP_SAVE_GFER1, SLEEP_SAVE_GFER2, SLEEP_SAVE_GFER3,
144 SLEEP_SAVE_PGSR0, SLEEP_SAVE_PGSR1, SLEEP_SAVE_PGSR2, SLEEP_SAVE_PGSR3,
145
146 SLEEP_SAVE_GAFR0_L, SLEEP_SAVE_GAFR0_U,
147 SLEEP_SAVE_GAFR1_L, SLEEP_SAVE_GAFR1_U,
148 SLEEP_SAVE_GAFR2_L, SLEEP_SAVE_GAFR2_U,
149 SLEEP_SAVE_GAFR3_L, SLEEP_SAVE_GAFR3_U,
150
151 SLEEP_SAVE_PSTR,
152
153 SLEEP_SAVE_ICMR,
154 SLEEP_SAVE_CKEN,
155
156 SLEEP_SAVE_MDREFR,
157 SLEEP_SAVE_PWER, SLEEP_SAVE_PCFR, SLEEP_SAVE_PRER,
158 SLEEP_SAVE_PFER, SLEEP_SAVE_PKWR,
159
160 SLEEP_SAVE_SIZE
161};
162
163void pxa27x_cpu_pm_save(unsigned long *sleep_save)
164{
165 SAVE(GPLR0); SAVE(GPLR1); SAVE(GPLR2); SAVE(GPLR3);
166 SAVE(GPDR0); SAVE(GPDR1); SAVE(GPDR2); SAVE(GPDR3);
167 SAVE(GRER0); SAVE(GRER1); SAVE(GRER2); SAVE(GRER3);
168 SAVE(GFER0); SAVE(GFER1); SAVE(GFER2); SAVE(GFER3);
169 SAVE(PGSR0); SAVE(PGSR1); SAVE(PGSR2); SAVE(PGSR3);
170
171 SAVE(GAFR0_L); SAVE(GAFR0_U);
172 SAVE(GAFR1_L); SAVE(GAFR1_U);
173 SAVE(GAFR2_L); SAVE(GAFR2_U);
174 SAVE(GAFR3_L); SAVE(GAFR3_U);
175
176 SAVE(MDREFR);
177 SAVE(PWER); SAVE(PCFR); SAVE(PRER);
178 SAVE(PFER); SAVE(PKWR);
179
180 SAVE(ICMR); ICMR = 0;
181 SAVE(CKEN);
182 SAVE(PSTR);
183
184 /* Clear GPIO transition detect bits */
185 GEDR0 = GEDR0; GEDR1 = GEDR1; GEDR2 = GEDR2; GEDR3 = GEDR3;
186}
187
188void pxa27x_cpu_pm_restore(unsigned long *sleep_save)
189{
190 /* ensure not to come back here if it wasn't intended */
191 PSPR = 0;
192
193 /* restore registers */
194 RESTORE_GPLEVEL(0); RESTORE_GPLEVEL(1);
195 RESTORE_GPLEVEL(2); RESTORE_GPLEVEL(3);
196 RESTORE(GPDR0); RESTORE(GPDR1); RESTORE(GPDR2); RESTORE(GPDR3);
197 RESTORE(GAFR0_L); RESTORE(GAFR0_U);
198 RESTORE(GAFR1_L); RESTORE(GAFR1_U);
199 RESTORE(GAFR2_L); RESTORE(GAFR2_U);
200 RESTORE(GAFR3_L); RESTORE(GAFR3_U);
201 RESTORE(GRER0); RESTORE(GRER1); RESTORE(GRER2); RESTORE(GRER3);
202 RESTORE(GFER0); RESTORE(GFER1); RESTORE(GFER2); RESTORE(GFER3);
203 RESTORE(PGSR0); RESTORE(PGSR1); RESTORE(PGSR2); RESTORE(PGSR3);
204
205 RESTORE(MDREFR);
206 RESTORE(PWER); RESTORE(PCFR); RESTORE(PRER);
207 RESTORE(PFER); RESTORE(PKWR);
208
209 PSSR = PSSR_RDH | PSSR_PH;
210
211 RESTORE(CKEN);
212
213 ICLR = 0;
214 ICCR = 1;
215 RESTORE(ICMR);
216 RESTORE(PSTR);
217}
218
219void pxa27x_cpu_pm_enter(suspend_state_t state)
Todd Poynor87754202005-06-03 20:52:27 +0100220{
221 extern void pxa_cpu_standby(void);
Todd Poynor87754202005-06-03 20:52:27 +0100222
Todd Poynor26705ca2005-07-01 11:27:05 +0100223 if (state == PM_SUSPEND_STANDBY)
Eric Miao711be5c2007-07-18 11:38:45 +0100224 CKEN = (1 << CKEN_MEMC) | (1 << CKEN_OSTIMER) |
225 (1 << CKEN_LCD) | (1 << CKEN_PWM0);
Todd Poynor26705ca2005-07-01 11:27:05 +0100226 else
Richard Purdie1f750a72007-07-02 10:19:07 +0100227 CKEN = (1 << CKEN_MEMC) | (1 << CKEN_OSTIMER);
Todd Poynor87754202005-06-03 20:52:27 +0100228
229 /* ensure voltage-change sequencer not initiated, which hangs */
230 PCFR &= ~PCFR_FVC;
231
232 /* Clear edge-detect status register. */
233 PEDR = 0xDF12FE1B;
234
235 switch (state) {
Todd Poynor26705ca2005-07-01 11:27:05 +0100236 case PM_SUSPEND_STANDBY:
237 pxa_cpu_standby();
238 break;
Todd Poynor87754202005-06-03 20:52:27 +0100239 case PM_SUSPEND_MEM:
240 /* set resume return address */
241 PSPR = virt_to_phys(pxa_cpu_resume);
Eric Miaob750a092007-07-18 11:40:13 +0100242 pxa27x_cpu_suspend(PWRMODE_SLEEP);
Todd Poynor87754202005-06-03 20:52:27 +0100243 break;
244 }
245}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246
Eric Miao711be5c2007-07-18 11:38:45 +0100247static int pxa27x_cpu_pm_valid(suspend_state_t state)
Russell King88dfe982007-05-15 11:22:48 +0100248{
249 return state == PM_SUSPEND_MEM || state == PM_SUSPEND_STANDBY;
250}
251
Eric Miao711be5c2007-07-18 11:38:45 +0100252static struct pxa_cpu_pm_fns pxa27x_cpu_pm_fns = {
253 .save_size = SLEEP_SAVE_SIZE,
254 .save = pxa27x_cpu_pm_save,
255 .restore = pxa27x_cpu_pm_restore,
256 .valid = pxa27x_cpu_pm_valid,
257 .enter = pxa27x_cpu_pm_enter,
Russell Kinge176bb02007-05-15 11:16:10 +0100258};
Eric Miao711be5c2007-07-18 11:38:45 +0100259
260static void __init pxa27x_init_pm(void)
261{
262 pxa_cpu_pm_fns = &pxa27x_cpu_pm_fns;
263}
Nicolas Pitrea8fa3f02005-06-13 22:35:41 +0100264#endif
265
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266/*
267 * device registration specific to PXA27x.
268 */
269
270static u64 pxa27x_dmamask = 0xffffffffUL;
271
272static struct resource pxa27x_ohci_resources[] = {
273 [0] = {
274 .start = 0x4C000000,
275 .end = 0x4C00ff6f,
276 .flags = IORESOURCE_MEM,
277 },
278 [1] = {
279 .start = IRQ_USBH1,
280 .end = IRQ_USBH1,
281 .flags = IORESOURCE_IRQ,
282 },
283};
284
Eric Miaoe09d02e2007-07-17 10:45:58 +0100285static struct platform_device pxa27x_device_ohci = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 .name = "pxa27x-ohci",
287 .id = -1,
288 .dev = {
289 .dma_mask = &pxa27x_dmamask,
290 .coherent_dma_mask = 0xffffffff,
291 },
292 .num_resources = ARRAY_SIZE(pxa27x_ohci_resources),
293 .resource = pxa27x_ohci_resources,
294};
295
Richard Purdie81f280e2005-11-12 14:22:11 +0000296void __init pxa_set_ohci_info(struct pxaohci_platform_data *info)
297{
Eric Miaoe09d02e2007-07-17 10:45:58 +0100298 pxa27x_device_ohci.dev.platform_data = info;
Richard Purdie81f280e2005-11-12 14:22:11 +0000299}
300
Russell King34f32312007-05-15 10:39:49 +0100301static struct resource i2c_power_resources[] = {
302 {
303 .start = 0x40f00180,
304 .end = 0x40f001a3,
305 .flags = IORESOURCE_MEM,
306 }, {
307 .start = IRQ_PWRI2C,
308 .end = IRQ_PWRI2C,
309 .flags = IORESOURCE_IRQ,
310 },
311};
312
Eric Miaoe09d02e2007-07-17 10:45:58 +0100313static struct platform_device pxa27x_device_i2c_power = {
Russell King34f32312007-05-15 10:39:49 +0100314 .name = "pxa2xx-i2c",
315 .id = 1,
316 .resource = i2c_power_resources,
317 .num_resources = ARRAY_SIZE(i2c_power_resources),
318};
319
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320static struct platform_device *devices[] __initdata = {
Eric Miaoe09d02e2007-07-17 10:45:58 +0100321 &pxa_device_mci,
322 &pxa_device_udc,
323 &pxa_device_fb,
324 &pxa_device_ffuart,
325 &pxa_device_btuart,
326 &pxa_device_stuart,
327 &pxa_device_i2c,
328 &pxa_device_i2s,
329 &pxa_device_ficp,
330 &pxa_device_rtc,
331 &pxa27x_device_i2c_power,
332 &pxa27x_device_ohci,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333};
334
Eric Miaocd491042007-06-22 04:14:09 +0100335void __init pxa27x_init_irq(void)
336{
337 pxa_init_irq_low();
338 pxa_init_irq_high();
339 pxa_init_irq_gpio(128);
340}
341
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342static int __init pxa27x_init(void)
343{
Russell Kinge176bb02007-05-15 11:16:10 +0100344 int ret = 0;
345 if (cpu_is_pxa27x()) {
Eric Miaof53f0662007-06-22 05:40:17 +0100346 if ((ret = pxa_init_dma(32)))
347 return ret;
Russell Kinge176bb02007-05-15 11:16:10 +0100348#ifdef CONFIG_PM
Eric Miao711be5c2007-07-18 11:38:45 +0100349 pxa27x_init_pm();
Russell Kinge176bb02007-05-15 11:16:10 +0100350#endif
351 ret = platform_add_devices(devices, ARRAY_SIZE(devices));
352 }
353 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354}
355
356subsys_initcall(pxa27x_init);