Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 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 King | 2f8163b | 2011-07-26 10:53:52 +0100 | [diff] [blame] | 19 | #include <linux/gpio.h> |
Haojian Zhuang | 157d264 | 2011-10-17 20:37:52 +0800 | [diff] [blame] | 20 | #include <linux/gpio-pxa.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/module.h> |
| 22 | #include <linux/kernel.h> |
| 23 | #include <linux/init.h> |
Russell King | 34f3231 | 2007-05-15 10:39:49 +0100 | [diff] [blame] | 24 | #include <linux/platform_device.h> |
Rafael J. Wysocki | 95d9ffb | 2007-10-18 03:04:39 -0700 | [diff] [blame] | 25 | #include <linux/suspend.h> |
Rafael J. Wysocki | 2eaa03b | 2011-04-22 22:03:11 +0200 | [diff] [blame] | 26 | #include <linux/syscore_ops.h> |
Lennert Buytenhek | a3f4c92 | 2010-11-29 11:18:26 +0100 | [diff] [blame] | 27 | #include <linux/irq.h> |
Robert Jarzmik | 32f1799 | 2016-08-15 00:24:55 +0200 | [diff] [blame^] | 28 | #include <linux/irqchip.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
Marek Vasut | 851982c | 2010-10-11 02:20:19 +0200 | [diff] [blame] | 30 | #include <asm/mach/map.h> |
Russell King | 2c74a0c | 2011-06-22 17:41:48 +0100 | [diff] [blame] | 31 | #include <asm/suspend.h> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 32 | #include <mach/hardware.h> |
| 33 | #include <mach/irqs.h> |
Arnd Bergmann | 4c25c5d | 2015-01-30 10:45:33 +0100 | [diff] [blame] | 34 | #include "pxa25x.h" |
Russell King | afd2fc0 | 2008-08-07 11:05:25 +0100 | [diff] [blame] | 35 | #include <mach/reset.h> |
Arnd Bergmann | 4c25c5d | 2015-01-30 10:45:33 +0100 | [diff] [blame] | 36 | #include "pm.h" |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 37 | #include <mach/dma.h> |
Marek Vasut | ad68bb9 | 2010-11-03 16:29:35 +0100 | [diff] [blame] | 38 | #include <mach/smemc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
| 40 | #include "generic.h" |
Russell King | 46c41e6 | 2007-05-15 15:39:36 +0100 | [diff] [blame] | 41 | #include "devices.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
| 43 | /* |
| 44 | * Various clock factors driven by the CCCR register. |
| 45 | */ |
| 46 | |
Nicolas Pitre | a8fa3f0 | 2005-06-13 22:35:41 +0100 | [diff] [blame] | 47 | #ifdef CONFIG_PM |
Todd Poynor | 8775420 | 2005-06-03 20:52:27 +0100 | [diff] [blame] | 48 | |
Eric Miao | 711be5c | 2007-07-18 11:38:45 +0100 | [diff] [blame] | 49 | #define SAVE(x) sleep_save[SLEEP_SAVE_##x] = x |
| 50 | #define RESTORE(x) x = sleep_save[SLEEP_SAVE_##x] |
| 51 | |
Eric Miao | 711be5c | 2007-07-18 11:38:45 +0100 | [diff] [blame] | 52 | /* |
| 53 | * List of global PXA peripheral registers to preserve. |
| 54 | * More ones like CP and general purpose register values are preserved |
| 55 | * with the stack pointer in sleep.S. |
| 56 | */ |
Eric Miao | 5a3d965 | 2008-09-03 18:06:34 +0800 | [diff] [blame] | 57 | enum { |
Eric Miao | 711be5c | 2007-07-18 11:38:45 +0100 | [diff] [blame] | 58 | SLEEP_SAVE_PSTR, |
Robert Jarzmik | 649de51 | 2008-05-02 21:17:06 +0100 | [diff] [blame] | 59 | SLEEP_SAVE_COUNT |
Eric Miao | 711be5c | 2007-07-18 11:38:45 +0100 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | |
| 63 | static void pxa25x_cpu_pm_save(unsigned long *sleep_save) |
| 64 | { |
Eric Miao | 711be5c | 2007-07-18 11:38:45 +0100 | [diff] [blame] | 65 | SAVE(PSTR); |
| 66 | } |
| 67 | |
| 68 | static void pxa25x_cpu_pm_restore(unsigned long *sleep_save) |
| 69 | { |
Eric Miao | 711be5c | 2007-07-18 11:38:45 +0100 | [diff] [blame] | 70 | RESTORE(PSTR); |
| 71 | } |
| 72 | |
| 73 | static void pxa25x_cpu_pm_enter(suspend_state_t state) |
Todd Poynor | 8775420 | 2005-06-03 20:52:27 +0100 | [diff] [blame] | 74 | { |
Russell King | dc38e2a | 2008-05-08 16:50:39 +0100 | [diff] [blame] | 75 | /* Clear reset status */ |
| 76 | RCSR = RCSR_HWR | RCSR_WDR | RCSR_SMR | RCSR_GPR; |
| 77 | |
Todd Poynor | 8775420 | 2005-06-03 20:52:27 +0100 | [diff] [blame] | 78 | switch (state) { |
| 79 | case PM_SUSPEND_MEM: |
Russell King | 2c74a0c | 2011-06-22 17:41:48 +0100 | [diff] [blame] | 80 | cpu_suspend(PWRMODE_SLEEP, pxa25x_finish_suspend); |
Todd Poynor | 8775420 | 2005-06-03 20:52:27 +0100 | [diff] [blame] | 81 | break; |
| 82 | } |
| 83 | } |
Nicolas Pitre | a8fa3f0 | 2005-06-13 22:35:41 +0100 | [diff] [blame] | 84 | |
Russell King | 4104980 | 2008-08-27 12:55:04 +0100 | [diff] [blame] | 85 | static int pxa25x_cpu_pm_prepare(void) |
| 86 | { |
| 87 | /* set resume return address */ |
Russell King | 4f5ad99 | 2011-02-06 17:41:26 +0000 | [diff] [blame] | 88 | PSPR = virt_to_phys(cpu_resume); |
Russell King | 4104980 | 2008-08-27 12:55:04 +0100 | [diff] [blame] | 89 | return 0; |
| 90 | } |
| 91 | |
| 92 | static void pxa25x_cpu_pm_finish(void) |
| 93 | { |
| 94 | /* ensure not to come back here if it wasn't intended */ |
| 95 | PSPR = 0; |
| 96 | } |
| 97 | |
Eric Miao | 711be5c | 2007-07-18 11:38:45 +0100 | [diff] [blame] | 98 | static struct pxa_cpu_pm_fns pxa25x_cpu_pm_fns = { |
Robert Jarzmik | 649de51 | 2008-05-02 21:17:06 +0100 | [diff] [blame] | 99 | .save_count = SLEEP_SAVE_COUNT, |
Rafael J. Wysocki | 26398a7 | 2007-10-18 03:04:40 -0700 | [diff] [blame] | 100 | .valid = suspend_valid_only_mem, |
Eric Miao | 711be5c | 2007-07-18 11:38:45 +0100 | [diff] [blame] | 101 | .save = pxa25x_cpu_pm_save, |
| 102 | .restore = pxa25x_cpu_pm_restore, |
| 103 | .enter = pxa25x_cpu_pm_enter, |
Russell King | 4104980 | 2008-08-27 12:55:04 +0100 | [diff] [blame] | 104 | .prepare = pxa25x_cpu_pm_prepare, |
| 105 | .finish = pxa25x_cpu_pm_finish, |
Russell King | e176bb0 | 2007-05-15 11:16:10 +0100 | [diff] [blame] | 106 | }; |
Eric Miao | 711be5c | 2007-07-18 11:38:45 +0100 | [diff] [blame] | 107 | |
| 108 | static void __init pxa25x_init_pm(void) |
| 109 | { |
| 110 | pxa_cpu_pm_fns = &pxa25x_cpu_pm_fns; |
| 111 | } |
eric miao | f79299c | 2008-01-02 08:24:49 +0800 | [diff] [blame] | 112 | #else |
| 113 | static inline void pxa25x_init_pm(void) {} |
Nicolas Pitre | a8fa3f0 | 2005-06-13 22:35:41 +0100 | [diff] [blame] | 114 | #endif |
Russell King | e176bb0 | 2007-05-15 11:16:10 +0100 | [diff] [blame] | 115 | |
eric miao | c95530c | 2007-08-29 10:22:17 +0100 | [diff] [blame] | 116 | /* PXA25x: supports wakeup from GPIO0..GPIO15 and RTC alarm |
| 117 | */ |
| 118 | |
Lennert Buytenhek | a3f4c92 | 2010-11-29 11:18:26 +0100 | [diff] [blame] | 119 | static int pxa25x_set_wake(struct irq_data *d, unsigned int on) |
eric miao | c95530c | 2007-08-29 10:22:17 +0100 | [diff] [blame] | 120 | { |
Haojian Zhuang | 4929f5a | 2011-10-10 16:03:51 +0800 | [diff] [blame] | 121 | int gpio = pxa_irq_to_gpio(d->irq); |
eric miao | c0a596d | 2008-03-11 09:46:28 +0800 | [diff] [blame] | 122 | uint32_t mask = 0; |
eric miao | c95530c | 2007-08-29 10:22:17 +0100 | [diff] [blame] | 123 | |
eric miao | c0a596d | 2008-03-11 09:46:28 +0800 | [diff] [blame] | 124 | if (gpio >= 0 && gpio < 85) |
| 125 | return gpio_set_wake(gpio, on); |
eric miao | c95530c | 2007-08-29 10:22:17 +0100 | [diff] [blame] | 126 | |
Lennert Buytenhek | a3f4c92 | 2010-11-29 11:18:26 +0100 | [diff] [blame] | 127 | if (d->irq == IRQ_RTCAlrm) { |
eric miao | c95530c | 2007-08-29 10:22:17 +0100 | [diff] [blame] | 128 | mask = PWER_RTC; |
| 129 | goto set_pwer; |
| 130 | } |
| 131 | |
| 132 | return -EINVAL; |
| 133 | |
| 134 | set_pwer: |
| 135 | if (on) |
| 136 | PWER |= mask; |
| 137 | else |
| 138 | PWER &=~mask; |
| 139 | |
| 140 | return 0; |
| 141 | } |
| 142 | |
Eric Miao | cd49104 | 2007-06-22 04:14:09 +0100 | [diff] [blame] | 143 | void __init pxa25x_init_irq(void) |
| 144 | { |
eric miao | b9e25ac | 2008-03-04 14:19:58 +0800 | [diff] [blame] | 145 | pxa_init_irq(32, pxa25x_set_wake); |
Eric Miao | cd49104 | 2007-06-22 04:14:09 +0100 | [diff] [blame] | 146 | } |
| 147 | |
Eric Miao | 067455a | 2008-11-26 18:12:04 +0800 | [diff] [blame] | 148 | #ifdef CONFIG_CPU_PXA26x |
| 149 | void __init pxa26x_init_irq(void) |
| 150 | { |
| 151 | pxa_init_irq(32, pxa25x_set_wake); |
Eric Miao | 067455a | 2008-11-26 18:12:04 +0800 | [diff] [blame] | 152 | } |
| 153 | #endif |
| 154 | |
Robert Jarzmik | 32f1799 | 2016-08-15 00:24:55 +0200 | [diff] [blame^] | 155 | static int __init __init |
| 156 | pxa25x_dt_init_irq(struct device_node *node, struct device_node *parent) |
Robert Jarzmik | ca5be4c | 2016-04-10 21:29:58 +0200 | [diff] [blame] | 157 | { |
Robert Jarzmik | 32f1799 | 2016-08-15 00:24:55 +0200 | [diff] [blame^] | 158 | pxa_dt_irq_init(pxa25x_set_wake); |
| 159 | set_handle_irq(ichp_handle_irq); |
| 160 | |
| 161 | return 0; |
Robert Jarzmik | ca5be4c | 2016-04-10 21:29:58 +0200 | [diff] [blame] | 162 | } |
Robert Jarzmik | 32f1799 | 2016-08-15 00:24:55 +0200 | [diff] [blame^] | 163 | IRQCHIP_DECLARE(pxa25x_intc, "marvell,pxa-intc", pxa25x_dt_init_irq); |
Robert Jarzmik | ca5be4c | 2016-04-10 21:29:58 +0200 | [diff] [blame] | 164 | |
Marek Vasut | 851982c | 2010-10-11 02:20:19 +0200 | [diff] [blame] | 165 | static struct map_desc pxa25x_io_desc[] __initdata = { |
| 166 | { /* Mem Ctl */ |
Arnd Bergmann | 97b09da | 2011-10-01 22:03:45 +0200 | [diff] [blame] | 167 | .virtual = (unsigned long)SMEMC_VIRT, |
Marek Vasut | ad68bb9 | 2010-11-03 16:29:35 +0100 | [diff] [blame] | 168 | .pfn = __phys_to_pfn(PXA2XX_SMEMC_BASE), |
Laurent Pinchart | 0e32986 | 2014-07-11 13:00:36 +0200 | [diff] [blame] | 169 | .length = SMEMC_SIZE, |
Marek Vasut | 851982c | 2010-10-11 02:20:19 +0200 | [diff] [blame] | 170 | .type = MT_DEVICE |
Laurent Pinchart | b10f1c8 | 2014-07-11 13:00:37 +0200 | [diff] [blame] | 171 | }, { /* UNCACHED_PHYS_0 */ |
| 172 | .virtual = UNCACHED_PHYS_0, |
| 173 | .pfn = __phys_to_pfn(0x00000000), |
| 174 | .length = UNCACHED_PHYS_0_SIZE, |
| 175 | .type = MT_DEVICE |
Marek Vasut | 851982c | 2010-10-11 02:20:19 +0200 | [diff] [blame] | 176 | }, |
| 177 | }; |
| 178 | |
| 179 | void __init pxa25x_map_io(void) |
| 180 | { |
| 181 | pxa_map_io(); |
| 182 | iotable_init(ARRAY_AND_SIZE(pxa25x_io_desc)); |
| 183 | pxa25x_get_clk_frequency_khz(1); |
| 184 | } |
| 185 | |
Andrea Adami | 8757e16 | 2012-11-21 01:37:25 +0100 | [diff] [blame] | 186 | static struct pxa_gpio_platform_data pxa25x_gpio_info __initdata = { |
Haojian Zhuang | b8f649f | 2013-04-09 18:12:04 +0800 | [diff] [blame] | 187 | .irq_base = PXA_GPIO_TO_IRQ(0), |
| 188 | .gpio_set_wake = gpio_set_wake, |
Andrea Adami | 8757e16 | 2012-11-21 01:37:25 +0100 | [diff] [blame] | 189 | }; |
| 190 | |
Russell King | 34f3231 | 2007-05-15 10:39:49 +0100 | [diff] [blame] | 191 | static struct platform_device *pxa25x_devices[] __initdata = { |
Philipp Zabel | 7a85762 | 2008-06-22 23:36:39 +0100 | [diff] [blame] | 192 | &pxa25x_device_udc, |
Eric Miao | 09a5358 | 2010-06-14 00:43:00 +0800 | [diff] [blame] | 193 | &pxa_device_pmu, |
Eric Miao | e09d02e | 2007-07-17 10:45:58 +0100 | [diff] [blame] | 194 | &pxa_device_i2s, |
Robert Jarzmik | 7249314 | 2008-11-13 23:50:56 +0100 | [diff] [blame] | 195 | &sa1100_device_rtc, |
eric miao | d8e0db1 | 2007-12-10 17:54:36 +0800 | [diff] [blame] | 196 | &pxa25x_device_ssp, |
| 197 | &pxa25x_device_nssp, |
| 198 | &pxa25x_device_assp, |
eric miao | 75540c1 | 2008-04-13 21:44:04 +0100 | [diff] [blame] | 199 | &pxa25x_device_pwm0, |
| 200 | &pxa25x_device_pwm1, |
Dmitry Eremin-Solenikov | ea73e75 | 2011-02-23 02:29:09 +0300 | [diff] [blame] | 201 | &pxa_device_asoc_platform, |
Russell King | 34f3231 | 2007-05-15 10:39:49 +0100 | [diff] [blame] | 202 | }; |
| 203 | |
Russell King | e176bb0 | 2007-05-15 11:16:10 +0100 | [diff] [blame] | 204 | static int __init pxa25x_init(void) |
| 205 | { |
Rafael J. Wysocki | 2eaa03b | 2011-04-22 22:03:11 +0200 | [diff] [blame] | 206 | int ret = 0; |
Eric Miao | f53f066 | 2007-06-22 05:40:17 +0100 | [diff] [blame] | 207 | |
Eric Miao | 0ffcbfd | 2008-09-11 10:27:30 +0800 | [diff] [blame] | 208 | if (cpu_is_pxa25x()) { |
Eric Miao | 04fef22 | 2008-07-29 14:26:00 +0800 | [diff] [blame] | 209 | |
| 210 | reset_status = RCSR; |
| 211 | |
Eric Miao | 711be5c | 2007-07-18 11:38:45 +0100 | [diff] [blame] | 212 | pxa25x_init_pm(); |
eric miao | f79299c | 2008-01-02 08:24:49 +0800 | [diff] [blame] | 213 | |
Rafael J. Wysocki | 2eaa03b | 2011-04-22 22:03:11 +0200 | [diff] [blame] | 214 | register_syscore_ops(&pxa_irq_syscore_ops); |
| 215 | register_syscore_ops(&pxa2xx_mfp_syscore_ops); |
eric miao | c0165504 | 2008-01-28 23:00:02 +0000 | [diff] [blame] | 216 | |
Robert Jarzmik | d9edae4 | 2016-04-10 21:29:59 +0200 | [diff] [blame] | 217 | if (!of_have_populated_dt()) { |
| 218 | pxa2xx_set_dmac_info(16, 40); |
| 219 | pxa_register_device(&pxa25x_device_gpio, &pxa25x_gpio_info); |
| 220 | ret = platform_add_devices(pxa25x_devices, |
| 221 | ARRAY_SIZE(pxa25x_devices)); |
| 222 | } |
Russell King | e176bb0 | 2007-05-15 11:16:10 +0100 | [diff] [blame] | 223 | } |
eric miao | c0165504 | 2008-01-28 23:00:02 +0000 | [diff] [blame] | 224 | |
Russell King | 34f3231 | 2007-05-15 10:39:49 +0100 | [diff] [blame] | 225 | return ret; |
Russell King | e176bb0 | 2007-05-15 11:16:10 +0100 | [diff] [blame] | 226 | } |
| 227 | |
Russell King | 1c104e0 | 2008-04-19 10:59:24 +0100 | [diff] [blame] | 228 | postcore_initcall(pxa25x_init); |