blob: ab8808ce7e219cd5d5fd16963aa5e81f3498fe1d [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 */
Robert Jarzmik1da10c12018-06-17 19:02:05 +020019#include <linux/dmaengine.h>
20#include <linux/dma/pxa-dma.h>
Russell King2f8163b2011-07-26 10:53:52 +010021#include <linux/gpio.h>
Haojian Zhuang157d2642011-10-17 20:37:52 +080022#include <linux/gpio-pxa.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <linux/module.h>
24#include <linux/kernel.h>
25#include <linux/init.h>
Russell King34f32312007-05-15 10:39:49 +010026#include <linux/platform_device.h>
Rafael J. Wysocki95d9ffb2007-10-18 03:04:39 -070027#include <linux/suspend.h>
Rafael J. Wysocki2eaa03b2011-04-22 22:03:11 +020028#include <linux/syscore_ops.h>
Lennert Buytenheka3f4c922010-11-29 11:18:26 +010029#include <linux/irq.h>
Robert Jarzmik32f17992016-08-15 00:24:55 +020030#include <linux/irqchip.h>
Robert Jarzmik1da10c12018-06-17 19:02:05 +020031#include <linux/platform_data/mmp_dma.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Marek Vasut851982c2010-10-11 02:20:19 +020033#include <asm/mach/map.h>
Russell King2c74a0c2011-06-22 17:41:48 +010034#include <asm/suspend.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010035#include <mach/hardware.h>
36#include <mach/irqs.h>
Arnd Bergmann4c25c5d2015-01-30 10:45:33 +010037#include "pxa25x.h"
Russell Kingafd2fc02008-08-07 11:05:25 +010038#include <mach/reset.h>
Arnd Bergmann4c25c5d2015-01-30 10:45:33 +010039#include "pm.h"
Russell Kinga09e64f2008-08-05 16:14:15 +010040#include <mach/dma.h>
Marek Vasutad68bb92010-11-03 16:29:35 +010041#include <mach/smemc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43#include "generic.h"
Russell King46c41e62007-05-15 15:39:36 +010044#include "devices.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
46/*
47 * Various clock factors driven by the CCCR register.
48 */
49
Nicolas Pitrea8fa3f02005-06-13 22:35:41 +010050#ifdef CONFIG_PM
Todd Poynor87754202005-06-03 20:52:27 +010051
Eric Miao711be5c2007-07-18 11:38:45 +010052#define SAVE(x) sleep_save[SLEEP_SAVE_##x] = x
53#define RESTORE(x) x = sleep_save[SLEEP_SAVE_##x]
54
Eric Miao711be5c2007-07-18 11:38:45 +010055/*
56 * List of global PXA peripheral registers to preserve.
57 * More ones like CP and general purpose register values are preserved
58 * with the stack pointer in sleep.S.
59 */
Eric Miao5a3d9652008-09-03 18:06:34 +080060enum {
Eric Miao711be5c2007-07-18 11:38:45 +010061 SLEEP_SAVE_PSTR,
Robert Jarzmik649de512008-05-02 21:17:06 +010062 SLEEP_SAVE_COUNT
Eric Miao711be5c2007-07-18 11:38:45 +010063};
64
65
66static void pxa25x_cpu_pm_save(unsigned long *sleep_save)
67{
Eric Miao711be5c2007-07-18 11:38:45 +010068 SAVE(PSTR);
69}
70
71static void pxa25x_cpu_pm_restore(unsigned long *sleep_save)
72{
Eric Miao711be5c2007-07-18 11:38:45 +010073 RESTORE(PSTR);
74}
75
76static void pxa25x_cpu_pm_enter(suspend_state_t state)
Todd Poynor87754202005-06-03 20:52:27 +010077{
Russell Kingdc38e2a2008-05-08 16:50:39 +010078 /* Clear reset status */
79 RCSR = RCSR_HWR | RCSR_WDR | RCSR_SMR | RCSR_GPR;
80
Todd Poynor87754202005-06-03 20:52:27 +010081 switch (state) {
82 case PM_SUSPEND_MEM:
Russell King2c74a0c2011-06-22 17:41:48 +010083 cpu_suspend(PWRMODE_SLEEP, pxa25x_finish_suspend);
Todd Poynor87754202005-06-03 20:52:27 +010084 break;
85 }
86}
Nicolas Pitrea8fa3f02005-06-13 22:35:41 +010087
Russell King41049802008-08-27 12:55:04 +010088static int pxa25x_cpu_pm_prepare(void)
89{
90 /* set resume return address */
Florian Fainelli64fc2a92017-01-15 03:59:29 +010091 PSPR = __pa_symbol(cpu_resume);
Russell King41049802008-08-27 12:55:04 +010092 return 0;
93}
94
95static void pxa25x_cpu_pm_finish(void)
96{
97 /* ensure not to come back here if it wasn't intended */
98 PSPR = 0;
99}
100
Eric Miao711be5c2007-07-18 11:38:45 +0100101static struct pxa_cpu_pm_fns pxa25x_cpu_pm_fns = {
Robert Jarzmik649de512008-05-02 21:17:06 +0100102 .save_count = SLEEP_SAVE_COUNT,
Rafael J. Wysocki26398a72007-10-18 03:04:40 -0700103 .valid = suspend_valid_only_mem,
Eric Miao711be5c2007-07-18 11:38:45 +0100104 .save = pxa25x_cpu_pm_save,
105 .restore = pxa25x_cpu_pm_restore,
106 .enter = pxa25x_cpu_pm_enter,
Russell King41049802008-08-27 12:55:04 +0100107 .prepare = pxa25x_cpu_pm_prepare,
108 .finish = pxa25x_cpu_pm_finish,
Russell Kinge176bb02007-05-15 11:16:10 +0100109};
Eric Miao711be5c2007-07-18 11:38:45 +0100110
111static void __init pxa25x_init_pm(void)
112{
113 pxa_cpu_pm_fns = &pxa25x_cpu_pm_fns;
114}
eric miaof79299c2008-01-02 08:24:49 +0800115#else
116static inline void pxa25x_init_pm(void) {}
Nicolas Pitrea8fa3f02005-06-13 22:35:41 +0100117#endif
Russell Kinge176bb02007-05-15 11:16:10 +0100118
eric miaoc95530c2007-08-29 10:22:17 +0100119/* PXA25x: supports wakeup from GPIO0..GPIO15 and RTC alarm
120 */
121
Lennert Buytenheka3f4c922010-11-29 11:18:26 +0100122static int pxa25x_set_wake(struct irq_data *d, unsigned int on)
eric miaoc95530c2007-08-29 10:22:17 +0100123{
Haojian Zhuang4929f5a2011-10-10 16:03:51 +0800124 int gpio = pxa_irq_to_gpio(d->irq);
eric miaoc0a596d2008-03-11 09:46:28 +0800125 uint32_t mask = 0;
eric miaoc95530c2007-08-29 10:22:17 +0100126
eric miaoc0a596d2008-03-11 09:46:28 +0800127 if (gpio >= 0 && gpio < 85)
128 return gpio_set_wake(gpio, on);
eric miaoc95530c2007-08-29 10:22:17 +0100129
Lennert Buytenheka3f4c922010-11-29 11:18:26 +0100130 if (d->irq == IRQ_RTCAlrm) {
eric miaoc95530c2007-08-29 10:22:17 +0100131 mask = PWER_RTC;
132 goto set_pwer;
133 }
134
135 return -EINVAL;
136
137set_pwer:
138 if (on)
139 PWER |= mask;
140 else
141 PWER &=~mask;
142
143 return 0;
144}
145
Eric Miaocd491042007-06-22 04:14:09 +0100146void __init pxa25x_init_irq(void)
147{
eric miaob9e25ac2008-03-04 14:19:58 +0800148 pxa_init_irq(32, pxa25x_set_wake);
Eric Miaocd491042007-06-22 04:14:09 +0100149}
150
Eric Miao067455a2008-11-26 18:12:04 +0800151#ifdef CONFIG_CPU_PXA26x
152void __init pxa26x_init_irq(void)
153{
154 pxa_init_irq(32, pxa25x_set_wake);
Eric Miao067455a2008-11-26 18:12:04 +0800155}
156#endif
157
Robert Jarzmik32f17992016-08-15 00:24:55 +0200158static int __init __init
159pxa25x_dt_init_irq(struct device_node *node, struct device_node *parent)
Robert Jarzmikca5be4c2016-04-10 21:29:58 +0200160{
Robert Jarzmik32f17992016-08-15 00:24:55 +0200161 pxa_dt_irq_init(pxa25x_set_wake);
Robert Jarzmike413bd332016-09-26 09:21:51 +0200162 set_handle_irq(icip_handle_irq);
Robert Jarzmik32f17992016-08-15 00:24:55 +0200163
164 return 0;
Robert Jarzmikca5be4c2016-04-10 21:29:58 +0200165}
Robert Jarzmik32f17992016-08-15 00:24:55 +0200166IRQCHIP_DECLARE(pxa25x_intc, "marvell,pxa-intc", pxa25x_dt_init_irq);
Robert Jarzmikca5be4c2016-04-10 21:29:58 +0200167
Marek Vasut851982c2010-10-11 02:20:19 +0200168static struct map_desc pxa25x_io_desc[] __initdata = {
169 { /* Mem Ctl */
Arnd Bergmann97b09da2011-10-01 22:03:45 +0200170 .virtual = (unsigned long)SMEMC_VIRT,
Marek Vasutad68bb92010-11-03 16:29:35 +0100171 .pfn = __phys_to_pfn(PXA2XX_SMEMC_BASE),
Laurent Pinchart0e329862014-07-11 13:00:36 +0200172 .length = SMEMC_SIZE,
Marek Vasut851982c2010-10-11 02:20:19 +0200173 .type = MT_DEVICE
Laurent Pinchartb10f1c82014-07-11 13:00:37 +0200174 }, { /* UNCACHED_PHYS_0 */
175 .virtual = UNCACHED_PHYS_0,
176 .pfn = __phys_to_pfn(0x00000000),
177 .length = UNCACHED_PHYS_0_SIZE,
178 .type = MT_DEVICE
Marek Vasut851982c2010-10-11 02:20:19 +0200179 },
180};
181
182void __init pxa25x_map_io(void)
183{
184 pxa_map_io();
185 iotable_init(ARRAY_AND_SIZE(pxa25x_io_desc));
186 pxa25x_get_clk_frequency_khz(1);
187}
188
Andrea Adami8757e162012-11-21 01:37:25 +0100189static struct pxa_gpio_platform_data pxa25x_gpio_info __initdata = {
Haojian Zhuangb8f649f2013-04-09 18:12:04 +0800190 .irq_base = PXA_GPIO_TO_IRQ(0),
191 .gpio_set_wake = gpio_set_wake,
Andrea Adami8757e162012-11-21 01:37:25 +0100192};
193
Russell King34f32312007-05-15 10:39:49 +0100194static struct platform_device *pxa25x_devices[] __initdata = {
Philipp Zabel7a857622008-06-22 23:36:39 +0100195 &pxa25x_device_udc,
Eric Miao09a53582010-06-14 00:43:00 +0800196 &pxa_device_pmu,
Eric Miaoe09d02e2007-07-17 10:45:58 +0100197 &pxa_device_i2s,
Robert Jarzmik72493142008-11-13 23:50:56 +0100198 &sa1100_device_rtc,
eric miaod8e0db12007-12-10 17:54:36 +0800199 &pxa25x_device_ssp,
200 &pxa25x_device_nssp,
201 &pxa25x_device_assp,
eric miao75540c12008-04-13 21:44:04 +0100202 &pxa25x_device_pwm0,
203 &pxa25x_device_pwm1,
Dmitry Eremin-Solenikovea73e752011-02-23 02:29:09 +0300204 &pxa_device_asoc_platform,
Russell King34f32312007-05-15 10:39:49 +0100205};
206
Robert Jarzmik1da10c12018-06-17 19:02:05 +0200207static const struct dma_slave_map pxa25x_slave_map[] = {
208 /* PXA25x, PXA27x and PXA3xx common entries */
209 { "pxa2xx-ac97", "pcm_pcm_mic_mono", PDMA_FILTER_PARAM(LOWEST, 8) },
210 { "pxa2xx-ac97", "pcm_pcm_aux_mono_in", PDMA_FILTER_PARAM(LOWEST, 9) },
211 { "pxa2xx-ac97", "pcm_pcm_aux_mono_out",
212 PDMA_FILTER_PARAM(LOWEST, 10) },
213 { "pxa2xx-ac97", "pcm_pcm_stereo_in", PDMA_FILTER_PARAM(LOWEST, 11) },
214 { "pxa2xx-ac97", "pcm_pcm_stereo_out", PDMA_FILTER_PARAM(LOWEST, 12) },
215 { "pxa-ssp-dai.1", "rx", PDMA_FILTER_PARAM(LOWEST, 13) },
216 { "pxa-ssp-dai.1", "tx", PDMA_FILTER_PARAM(LOWEST, 14) },
217 { "pxa-ssp-dai.2", "rx", PDMA_FILTER_PARAM(LOWEST, 15) },
218 { "pxa-ssp-dai.2", "tx", PDMA_FILTER_PARAM(LOWEST, 16) },
219 { "pxa2xx-ir", "rx", PDMA_FILTER_PARAM(LOWEST, 17) },
220 { "pxa2xx-ir", "tx", PDMA_FILTER_PARAM(LOWEST, 18) },
221 { "pxa2xx-mci.0", "rx", PDMA_FILTER_PARAM(LOWEST, 21) },
222 { "pxa2xx-mci.0", "tx", PDMA_FILTER_PARAM(LOWEST, 22) },
223
224 /* PXA25x specific map */
225 { "pxa25x-ssp.0", "rx", PDMA_FILTER_PARAM(LOWEST, 13) },
226 { "pxa25x-ssp.0", "tx", PDMA_FILTER_PARAM(LOWEST, 14) },
227 { "pxa25x-nssp.1", "rx", PDMA_FILTER_PARAM(LOWEST, 15) },
228 { "pxa25x-nssp.1", "tx", PDMA_FILTER_PARAM(LOWEST, 16) },
229 { "pxa25x-nssp.2", "rx", PDMA_FILTER_PARAM(LOWEST, 23) },
230 { "pxa25x-nssp.2", "tx", PDMA_FILTER_PARAM(LOWEST, 24) },
231};
232
233static struct mmp_dma_platdata pxa25x_dma_pdata = {
234 .dma_channels = 16,
235 .nb_requestors = 40,
236 .slave_map = pxa25x_slave_map,
237 .slave_map_cnt = ARRAY_SIZE(pxa25x_slave_map),
238};
239
Russell Kinge176bb02007-05-15 11:16:10 +0100240static int __init pxa25x_init(void)
241{
Rafael J. Wysocki2eaa03b2011-04-22 22:03:11 +0200242 int ret = 0;
Eric Miaof53f0662007-06-22 05:40:17 +0100243
Eric Miao0ffcbfd2008-09-11 10:27:30 +0800244 if (cpu_is_pxa25x()) {
Eric Miao04fef222008-07-29 14:26:00 +0800245
246 reset_status = RCSR;
247
Eric Miao711be5c2007-07-18 11:38:45 +0100248 pxa25x_init_pm();
eric miaof79299c2008-01-02 08:24:49 +0800249
Rafael J. Wysocki2eaa03b2011-04-22 22:03:11 +0200250 register_syscore_ops(&pxa_irq_syscore_ops);
251 register_syscore_ops(&pxa2xx_mfp_syscore_ops);
eric miaoc01655042008-01-28 23:00:02 +0000252
Robert Jarzmikd9edae42016-04-10 21:29:59 +0200253 if (!of_have_populated_dt()) {
Robert Jarzmik1da10c12018-06-17 19:02:05 +0200254 pxa2xx_set_dmac_info(&pxa25x_dma_pdata);
Robert Jarzmikd9edae42016-04-10 21:29:59 +0200255 pxa_register_device(&pxa25x_device_gpio, &pxa25x_gpio_info);
256 ret = platform_add_devices(pxa25x_devices,
257 ARRAY_SIZE(pxa25x_devices));
258 }
Russell Kinge176bb02007-05-15 11:16:10 +0100259 }
eric miaoc01655042008-01-28 23:00:02 +0000260
Russell King34f32312007-05-15 10:39:49 +0100261 return ret;
Russell Kinge176bb02007-05-15 11:16:10 +0100262}
263
Russell King1c104e02008-04-19 10:59:24 +0100264postcore_initcall(pxa25x_init);