blob: 823504f48f806525d6e42b68e26010c378035470 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/arm/mach-pxa/pxa25x.c
3 *
4 * Author: Nicolas Pitre
5 * Created: Jun 15, 2001
6 * Copyright: MontaVista Software Inc.
7 *
8 * Code specific to PXA21x/25x/26x variants.
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 *
14 * Since this file should be linked before any other machine specific file,
15 * the __initcall() here will be executed first. This serves as default
16 * initialization stuff for PXA machines which can be overridden later if
17 * need be.
18 */
Russell King2f8163b2011-07-26 10:53:52 +010019#include <linux/gpio.h>
Haojian Zhuang157d2642011-10-17 20:37:52 +080020#include <linux/gpio-pxa.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/module.h>
22#include <linux/kernel.h>
23#include <linux/init.h>
Russell King34f32312007-05-15 10:39:49 +010024#include <linux/platform_device.h>
Rafael J. Wysocki95d9ffb2007-10-18 03:04:39 -070025#include <linux/suspend.h>
Rafael J. Wysocki2eaa03b2011-04-22 22:03:11 +020026#include <linux/syscore_ops.h>
Lennert Buytenheka3f4c922010-11-29 11:18:26 +010027#include <linux/irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Marek Vasut851982c2010-10-11 02:20:19 +020029#include <asm/mach/map.h>
Russell King2c74a0c2011-06-22 17:41:48 +010030#include <asm/suspend.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010031#include <mach/hardware.h>
32#include <mach/irqs.h>
Arnd Bergmann4c25c5d2015-01-30 10:45:33 +010033#include "pxa25x.h"
Russell Kingafd2fc02008-08-07 11:05:25 +010034#include <mach/reset.h>
Arnd Bergmann4c25c5d2015-01-30 10:45:33 +010035#include "pm.h"
Russell Kinga09e64f2008-08-05 16:14:15 +010036#include <mach/dma.h>
Marek Vasutad68bb92010-11-03 16:29:35 +010037#include <mach/smemc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
39#include "generic.h"
Russell King46c41e62007-05-15 15:39:36 +010040#include "devices.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
42/*
43 * Various clock factors driven by the CCCR register.
44 */
45
Nicolas Pitrea8fa3f02005-06-13 22:35:41 +010046#ifdef CONFIG_PM
Todd Poynor87754202005-06-03 20:52:27 +010047
Eric Miao711be5c2007-07-18 11:38:45 +010048#define SAVE(x) sleep_save[SLEEP_SAVE_##x] = x
49#define RESTORE(x) x = sleep_save[SLEEP_SAVE_##x]
50
Eric Miao711be5c2007-07-18 11:38:45 +010051/*
52 * List of global PXA peripheral registers to preserve.
53 * More ones like CP and general purpose register values are preserved
54 * with the stack pointer in sleep.S.
55 */
Eric Miao5a3d9652008-09-03 18:06:34 +080056enum {
Eric Miao711be5c2007-07-18 11:38:45 +010057 SLEEP_SAVE_PSTR,
Robert Jarzmik649de512008-05-02 21:17:06 +010058 SLEEP_SAVE_COUNT
Eric Miao711be5c2007-07-18 11:38:45 +010059};
60
61
62static void pxa25x_cpu_pm_save(unsigned long *sleep_save)
63{
Eric Miao711be5c2007-07-18 11:38:45 +010064 SAVE(PSTR);
65}
66
67static void pxa25x_cpu_pm_restore(unsigned long *sleep_save)
68{
Eric Miao711be5c2007-07-18 11:38:45 +010069 RESTORE(PSTR);
70}
71
72static void pxa25x_cpu_pm_enter(suspend_state_t state)
Todd Poynor87754202005-06-03 20:52:27 +010073{
Russell Kingdc38e2a2008-05-08 16:50:39 +010074 /* Clear reset status */
75 RCSR = RCSR_HWR | RCSR_WDR | RCSR_SMR | RCSR_GPR;
76
Todd Poynor87754202005-06-03 20:52:27 +010077 switch (state) {
78 case PM_SUSPEND_MEM:
Russell King2c74a0c2011-06-22 17:41:48 +010079 cpu_suspend(PWRMODE_SLEEP, pxa25x_finish_suspend);
Todd Poynor87754202005-06-03 20:52:27 +010080 break;
81 }
82}
Nicolas Pitrea8fa3f02005-06-13 22:35:41 +010083
Russell King41049802008-08-27 12:55:04 +010084static int pxa25x_cpu_pm_prepare(void)
85{
86 /* set resume return address */
Russell King4f5ad992011-02-06 17:41:26 +000087 PSPR = virt_to_phys(cpu_resume);
Russell King41049802008-08-27 12:55:04 +010088 return 0;
89}
90
91static void pxa25x_cpu_pm_finish(void)
92{
93 /* ensure not to come back here if it wasn't intended */
94 PSPR = 0;
95}
96
Eric Miao711be5c2007-07-18 11:38:45 +010097static struct pxa_cpu_pm_fns pxa25x_cpu_pm_fns = {
Robert Jarzmik649de512008-05-02 21:17:06 +010098 .save_count = SLEEP_SAVE_COUNT,
Rafael J. Wysocki26398a72007-10-18 03:04:40 -070099 .valid = suspend_valid_only_mem,
Eric Miao711be5c2007-07-18 11:38:45 +0100100 .save = pxa25x_cpu_pm_save,
101 .restore = pxa25x_cpu_pm_restore,
102 .enter = pxa25x_cpu_pm_enter,
Russell King41049802008-08-27 12:55:04 +0100103 .prepare = pxa25x_cpu_pm_prepare,
104 .finish = pxa25x_cpu_pm_finish,
Russell Kinge176bb02007-05-15 11:16:10 +0100105};
Eric Miao711be5c2007-07-18 11:38:45 +0100106
107static void __init pxa25x_init_pm(void)
108{
109 pxa_cpu_pm_fns = &pxa25x_cpu_pm_fns;
110}
eric miaof79299c2008-01-02 08:24:49 +0800111#else
112static inline void pxa25x_init_pm(void) {}
Nicolas Pitrea8fa3f02005-06-13 22:35:41 +0100113#endif
Russell Kinge176bb02007-05-15 11:16:10 +0100114
eric miaoc95530c2007-08-29 10:22:17 +0100115/* PXA25x: supports wakeup from GPIO0..GPIO15 and RTC alarm
116 */
117
Lennert Buytenheka3f4c922010-11-29 11:18:26 +0100118static int pxa25x_set_wake(struct irq_data *d, unsigned int on)
eric miaoc95530c2007-08-29 10:22:17 +0100119{
Haojian Zhuang4929f5a2011-10-10 16:03:51 +0800120 int gpio = pxa_irq_to_gpio(d->irq);
eric miaoc0a596d2008-03-11 09:46:28 +0800121 uint32_t mask = 0;
eric miaoc95530c2007-08-29 10:22:17 +0100122
eric miaoc0a596d2008-03-11 09:46:28 +0800123 if (gpio >= 0 && gpio < 85)
124 return gpio_set_wake(gpio, on);
eric miaoc95530c2007-08-29 10:22:17 +0100125
Lennert Buytenheka3f4c922010-11-29 11:18:26 +0100126 if (d->irq == IRQ_RTCAlrm) {
eric miaoc95530c2007-08-29 10:22:17 +0100127 mask = PWER_RTC;
128 goto set_pwer;
129 }
130
131 return -EINVAL;
132
133set_pwer:
134 if (on)
135 PWER |= mask;
136 else
137 PWER &=~mask;
138
139 return 0;
140}
141
Eric Miaocd491042007-06-22 04:14:09 +0100142void __init pxa25x_init_irq(void)
143{
eric miaob9e25ac2008-03-04 14:19:58 +0800144 pxa_init_irq(32, pxa25x_set_wake);
Eric Miaocd491042007-06-22 04:14:09 +0100145}
146
Eric Miao067455a2008-11-26 18:12:04 +0800147#ifdef CONFIG_CPU_PXA26x
148void __init pxa26x_init_irq(void)
149{
150 pxa_init_irq(32, pxa25x_set_wake);
Eric Miao067455a2008-11-26 18:12:04 +0800151}
152#endif
153
Marek Vasut851982c2010-10-11 02:20:19 +0200154static struct map_desc pxa25x_io_desc[] __initdata = {
155 { /* Mem Ctl */
Arnd Bergmann97b09da2011-10-01 22:03:45 +0200156 .virtual = (unsigned long)SMEMC_VIRT,
Marek Vasutad68bb92010-11-03 16:29:35 +0100157 .pfn = __phys_to_pfn(PXA2XX_SMEMC_BASE),
Laurent Pinchart0e329862014-07-11 13:00:36 +0200158 .length = SMEMC_SIZE,
Marek Vasut851982c2010-10-11 02:20:19 +0200159 .type = MT_DEVICE
Laurent Pinchartb10f1c82014-07-11 13:00:37 +0200160 }, { /* UNCACHED_PHYS_0 */
161 .virtual = UNCACHED_PHYS_0,
162 .pfn = __phys_to_pfn(0x00000000),
163 .length = UNCACHED_PHYS_0_SIZE,
164 .type = MT_DEVICE
Marek Vasut851982c2010-10-11 02:20:19 +0200165 },
166};
167
168void __init pxa25x_map_io(void)
169{
170 pxa_map_io();
171 iotable_init(ARRAY_AND_SIZE(pxa25x_io_desc));
172 pxa25x_get_clk_frequency_khz(1);
173}
174
Andrea Adami8757e162012-11-21 01:37:25 +0100175static struct pxa_gpio_platform_data pxa25x_gpio_info __initdata = {
Haojian Zhuangb8f649f2013-04-09 18:12:04 +0800176 .irq_base = PXA_GPIO_TO_IRQ(0),
177 .gpio_set_wake = gpio_set_wake,
Andrea Adami8757e162012-11-21 01:37:25 +0100178};
179
Russell King34f32312007-05-15 10:39:49 +0100180static struct platform_device *pxa25x_devices[] __initdata = {
Philipp Zabel7a857622008-06-22 23:36:39 +0100181 &pxa25x_device_udc,
Eric Miao09a53582010-06-14 00:43:00 +0800182 &pxa_device_pmu,
Eric Miaoe09d02e2007-07-17 10:45:58 +0100183 &pxa_device_i2s,
Robert Jarzmik72493142008-11-13 23:50:56 +0100184 &sa1100_device_rtc,
eric miaod8e0db12007-12-10 17:54:36 +0800185 &pxa25x_device_ssp,
186 &pxa25x_device_nssp,
187 &pxa25x_device_assp,
eric miao75540c12008-04-13 21:44:04 +0100188 &pxa25x_device_pwm0,
189 &pxa25x_device_pwm1,
Dmitry Eremin-Solenikovea73e752011-02-23 02:29:09 +0300190 &pxa_device_asoc_platform,
Russell King34f32312007-05-15 10:39:49 +0100191};
192
Russell Kinge176bb02007-05-15 11:16:10 +0100193static int __init pxa25x_init(void)
194{
Rafael J. Wysocki2eaa03b2011-04-22 22:03:11 +0200195 int ret = 0;
Eric Miaof53f0662007-06-22 05:40:17 +0100196
Eric Miao0ffcbfd2008-09-11 10:27:30 +0800197 if (cpu_is_pxa25x()) {
Eric Miao04fef222008-07-29 14:26:00 +0800198
199 reset_status = RCSR;
200
Eric Miaofef1f992009-01-02 16:26:33 +0800201 if ((ret = pxa_init_dma(IRQ_DMA, 16)))
Eric Miaof53f0662007-06-22 05:40:17 +0100202 return ret;
eric miaof79299c2008-01-02 08:24:49 +0800203
Eric Miao711be5c2007-07-18 11:38:45 +0100204 pxa25x_init_pm();
eric miaof79299c2008-01-02 08:24:49 +0800205
Rafael J. Wysocki2eaa03b2011-04-22 22:03:11 +0200206 register_syscore_ops(&pxa_irq_syscore_ops);
207 register_syscore_ops(&pxa2xx_mfp_syscore_ops);
eric miaoc01655042008-01-28 23:00:02 +0000208
Robert Jarzmik72b195c2016-02-15 21:57:47 +0100209 pxa2xx_set_dmac_info(16, 40);
Haojian Zhuang2cab0292013-04-07 16:44:33 +0800210 pxa_register_device(&pxa25x_device_gpio, &pxa25x_gpio_info);
Russell King34f32312007-05-15 10:39:49 +0100211 ret = platform_add_devices(pxa25x_devices,
212 ARRAY_SIZE(pxa25x_devices));
eric miaoc01655042008-01-28 23:00:02 +0000213 if (ret)
214 return ret;
Russell Kinge176bb02007-05-15 11:16:10 +0100215 }
eric miaoc01655042008-01-28 23:00:02 +0000216
Russell King34f32312007-05-15 10:39:49 +0100217 return ret;
Russell Kinge176bb02007-05-15 11:16:10 +0100218}
219
Russell King1c104e02008-04-19 10:59:24 +0100220postcore_initcall(pxa25x_init);