blob: f0ba7ed24cb69adf54efd6cb275e59f9fb3d0c82 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * linux/arch/arm/mach-pxa/pxa27x.c
4 *
5 * Author: Nicolas Pitre
6 * Created: Nov 05, 2002
7 * Copyright: MontaVista Software Inc.
8 *
9 * Code specific to PXA27x aka Bulverde.
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 */
Robert Jarzmik1da10c12018-06-17 19:02:05 +020011#include <linux/dmaengine.h>
12#include <linux/dma/pxa-dma.h>
Russell King2f8163b2011-07-26 10:53:52 +010013#include <linux/gpio.h>
Haojian Zhuang157d2642011-10-17 20:37:52 +080014#include <linux/gpio-pxa.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/module.h>
16#include <linux/kernel.h>
17#include <linux/init.h>
Robert Jarzmik32f17992016-08-15 00:24:55 +020018#include <linux/irqchip.h>
Rafael J. Wysocki95d9ffb2007-10-18 03:04:39 -070019#include <linux/suspend.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010020#include <linux/platform_device.h>
Rafael J. Wysocki2eaa03b2011-04-22 22:03:11 +020021#include <linux/syscore_ops.h>
Marek Vasutad68bb92010-11-03 16:29:35 +010022#include <linux/io.h>
Lennert Buytenheka3f4c922010-11-29 11:18:26 +010023#include <linux/irq.h>
Wolfram Sangf15fc9b2017-11-13 18:27:39 +010024#include <linux/platform_data/i2c-pxa.h>
Robert Jarzmik1da10c12018-06-17 19:02:05 +020025#include <linux/platform_data/mmp_dma.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
Marek Vasut851982c2010-10-11 02:20:19 +020027#include <asm/mach/map.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010028#include <mach/hardware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <asm/irq.h>
Russell King2c74a0c2011-06-22 17:41:48 +010030#include <asm/suspend.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010031#include <mach/irqs.h>
Arnd Bergmann4c25c5d2015-01-30 10:45:33 +010032#include "pxa27x.h"
Russell Kingafd2fc02008-08-07 11:05:25 +010033#include <mach/reset.h>
Arnd Bergmann293b2da2012-08-24 15:16:48 +020034#include <linux/platform_data/usb-ohci-pxa27x.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>
38
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include "generic.h"
Russell King46c41e62007-05-15 15:39:36 +010040#include "devices.h"
Robert Jarzmik48a17db2014-12-27 14:55:26 +010041#include <linux/clk-provider.h>
42#include <linux/clkdev.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Eric Miao0cb0b0d2008-10-04 12:45:39 +080044void pxa27x_clear_otgph(void)
45{
46 if (cpu_is_pxa27x() && (PSSR & PSSR_OTGPH))
47 PSSR |= PSSR_OTGPH;
48}
49EXPORT_SYMBOL(pxa27x_clear_otgph);
50
Eric Miaofb1bf8c2010-01-04 16:30:58 +080051static unsigned long ac97_reset_config[] = {
Mike Dunn3b4bc7b2013-01-07 13:55:13 -080052 GPIO113_AC97_nRESET_GPIO_HIGH,
Eric Miao5e16e3c2010-07-13 09:41:28 +080053 GPIO113_AC97_nRESET,
Mike Dunn3b4bc7b2013-01-07 13:55:13 -080054 GPIO95_AC97_nRESET_GPIO_HIGH,
Eric Miao5e16e3c2010-07-13 09:41:28 +080055 GPIO95_AC97_nRESET,
Eric Miaofb1bf8c2010-01-04 16:30:58 +080056};
57
Mike Dunn053fe0f2013-01-07 13:55:14 -080058void pxa27x_configure_ac97reset(int reset_gpio, bool to_gpio)
Eric Miaofb1bf8c2010-01-04 16:30:58 +080059{
Mike Dunn053fe0f2013-01-07 13:55:14 -080060 /*
61 * This helper function is used to work around a bug in the pxa27x's
62 * ac97 controller during a warm reset. The configuration of the
63 * reset_gpio is changed as follows:
64 * to_gpio == true: configured to generic output gpio and driven high
65 * to_gpio == false: configured to ac97 controller alt fn AC97_nRESET
66 */
67
Eric Miaofb1bf8c2010-01-04 16:30:58 +080068 if (reset_gpio == 113)
Mike Dunn053fe0f2013-01-07 13:55:14 -080069 pxa2xx_mfp_config(to_gpio ? &ac97_reset_config[0] :
70 &ac97_reset_config[1], 1);
Eric Miaofb1bf8c2010-01-04 16:30:58 +080071
72 if (reset_gpio == 95)
Mike Dunn053fe0f2013-01-07 13:55:14 -080073 pxa2xx_mfp_config(to_gpio ? &ac97_reset_config[2] :
74 &ac97_reset_config[3], 1);
Eric Miaofb1bf8c2010-01-04 16:30:58 +080075}
Mike Dunn053fe0f2013-01-07 13:55:14 -080076EXPORT_SYMBOL_GPL(pxa27x_configure_ac97reset);
Eric Miaofb1bf8c2010-01-04 16:30:58 +080077
Nicolas Pitrea8fa3f02005-06-13 22:35:41 +010078#ifdef CONFIG_PM
79
Eric Miao711be5c2007-07-18 11:38:45 +010080#define SAVE(x) sleep_save[SLEEP_SAVE_##x] = x
81#define RESTORE(x) x = sleep_save[SLEEP_SAVE_##x]
82
Eric Miao711be5c2007-07-18 11:38:45 +010083/*
Mike Rapoportd082d362009-05-26 09:10:18 +030084 * allow platforms to override default PWRMODE setting used for PM_SUSPEND_MEM
85 */
86static unsigned int pwrmode = PWRMODE_SLEEP;
87
Arnd Bergmann54c09882015-10-12 15:46:08 +020088int pxa27x_set_pwrmode(unsigned int mode)
Mike Rapoportd082d362009-05-26 09:10:18 +030089{
90 switch (mode) {
91 case PWRMODE_SLEEP:
92 case PWRMODE_DEEPSLEEP:
93 pwrmode = mode;
94 return 0;
95 }
96
97 return -EINVAL;
98}
99
100/*
Eric Miao711be5c2007-07-18 11:38:45 +0100101 * List of global PXA peripheral registers to preserve.
102 * More ones like CP and general purpose register values are preserved
103 * with the stack pointer in sleep.S.
104 */
Eric Miao5a3d9652008-09-03 18:06:34 +0800105enum {
Eric Miao711be5c2007-07-18 11:38:45 +0100106 SLEEP_SAVE_PSTR,
Eric Miao711be5c2007-07-18 11:38:45 +0100107 SLEEP_SAVE_MDREFR,
Eric Miao5a3d9652008-09-03 18:06:34 +0800108 SLEEP_SAVE_PCFR,
Robert Jarzmik649de512008-05-02 21:17:06 +0100109 SLEEP_SAVE_COUNT
Eric Miao711be5c2007-07-18 11:38:45 +0100110};
111
112void pxa27x_cpu_pm_save(unsigned long *sleep_save)
113{
Marek Vasutad68bb92010-11-03 16:29:35 +0100114 sleep_save[SLEEP_SAVE_MDREFR] = __raw_readl(MDREFR);
Eric Miao5a3d9652008-09-03 18:06:34 +0800115 SAVE(PCFR);
Eric Miao711be5c2007-07-18 11:38:45 +0100116
Eric Miao711be5c2007-07-18 11:38:45 +0100117 SAVE(PSTR);
Eric Miao711be5c2007-07-18 11:38:45 +0100118}
119
120void pxa27x_cpu_pm_restore(unsigned long *sleep_save)
121{
Marek Vasutad68bb92010-11-03 16:29:35 +0100122 __raw_writel(sleep_save[SLEEP_SAVE_MDREFR], MDREFR);
Eric Miao5a3d9652008-09-03 18:06:34 +0800123 RESTORE(PCFR);
Eric Miao711be5c2007-07-18 11:38:45 +0100124
125 PSSR = PSSR_RDH | PSSR_PH;
126
Eric Miao711be5c2007-07-18 11:38:45 +0100127 RESTORE(PSTR);
128}
129
130void pxa27x_cpu_pm_enter(suspend_state_t state)
Todd Poynor87754202005-06-03 20:52:27 +0100131{
132 extern void pxa_cpu_standby(void);
Russell Kinga9503d22011-06-21 16:29:30 +0100133#ifndef CONFIG_IWMMXT
134 u64 acc0;
135
Arnd Bergmann343c1cd2016-01-29 15:06:31 +0100136 asm volatile(".arch_extension xscale\n\t"
137 "mra %Q0, %R0, acc0" : "=r" (acc0));
Russell Kinga9503d22011-06-21 16:29:30 +0100138#endif
Todd Poynor87754202005-06-03 20:52:27 +0100139
Todd Poynor87754202005-06-03 20:52:27 +0100140 /* ensure voltage-change sequencer not initiated, which hangs */
141 PCFR &= ~PCFR_FVC;
142
143 /* Clear edge-detect status register. */
144 PEDR = 0xDF12FE1B;
145
Russell Kingdc38e2a2008-05-08 16:50:39 +0100146 /* Clear reset status */
147 RCSR = RCSR_HWR | RCSR_WDR | RCSR_SMR | RCSR_GPR;
148
Todd Poynor87754202005-06-03 20:52:27 +0100149 switch (state) {
Todd Poynor26705ca2005-07-01 11:27:05 +0100150 case PM_SUSPEND_STANDBY:
151 pxa_cpu_standby();
152 break;
Todd Poynor87754202005-06-03 20:52:27 +0100153 case PM_SUSPEND_MEM:
Russell King2c74a0c2011-06-22 17:41:48 +0100154 cpu_suspend(pwrmode, pxa27x_finish_suspend);
Russell Kinga9503d22011-06-21 16:29:30 +0100155#ifndef CONFIG_IWMMXT
Arnd Bergmann343c1cd2016-01-29 15:06:31 +0100156 asm volatile(".arch_extension xscale\n\t"
157 "mar acc0, %Q0, %R0" : "=r" (acc0));
Russell Kinga9503d22011-06-21 16:29:30 +0100158#endif
Todd Poynor87754202005-06-03 20:52:27 +0100159 break;
160 }
161}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
Eric Miao711be5c2007-07-18 11:38:45 +0100163static int pxa27x_cpu_pm_valid(suspend_state_t state)
Russell King88dfe982007-05-15 11:22:48 +0100164{
165 return state == PM_SUSPEND_MEM || state == PM_SUSPEND_STANDBY;
166}
167
Russell King41049802008-08-27 12:55:04 +0100168static int pxa27x_cpu_pm_prepare(void)
169{
170 /* set resume return address */
Florian Fainelli64fc2a92017-01-15 03:59:29 +0100171 PSPR = __pa_symbol(cpu_resume);
Russell King41049802008-08-27 12:55:04 +0100172 return 0;
173}
174
175static void pxa27x_cpu_pm_finish(void)
176{
177 /* ensure not to come back here if it wasn't intended */
178 PSPR = 0;
179}
180
Eric Miao711be5c2007-07-18 11:38:45 +0100181static struct pxa_cpu_pm_fns pxa27x_cpu_pm_fns = {
Robert Jarzmik649de512008-05-02 21:17:06 +0100182 .save_count = SLEEP_SAVE_COUNT,
Eric Miao711be5c2007-07-18 11:38:45 +0100183 .save = pxa27x_cpu_pm_save,
184 .restore = pxa27x_cpu_pm_restore,
185 .valid = pxa27x_cpu_pm_valid,
186 .enter = pxa27x_cpu_pm_enter,
Russell King41049802008-08-27 12:55:04 +0100187 .prepare = pxa27x_cpu_pm_prepare,
188 .finish = pxa27x_cpu_pm_finish,
Russell Kinge176bb02007-05-15 11:16:10 +0100189};
Eric Miao711be5c2007-07-18 11:38:45 +0100190
191static void __init pxa27x_init_pm(void)
192{
193 pxa_cpu_pm_fns = &pxa27x_cpu_pm_fns;
194}
eric miaof79299c2008-01-02 08:24:49 +0800195#else
196static inline void pxa27x_init_pm(void) {}
Nicolas Pitrea8fa3f02005-06-13 22:35:41 +0100197#endif
198
eric miaoc95530c2007-08-29 10:22:17 +0100199/* PXA27x: Various gpios can issue wakeup events. This logic only
200 * handles the simple cases, not the WEMUX2 and WEMUX3 options
201 */
Lennert Buytenheka3f4c922010-11-29 11:18:26 +0100202static int pxa27x_set_wake(struct irq_data *d, unsigned int on)
eric miaoc95530c2007-08-29 10:22:17 +0100203{
Haojian Zhuang4929f5a2011-10-10 16:03:51 +0800204 int gpio = pxa_irq_to_gpio(d->irq);
eric miaoc95530c2007-08-29 10:22:17 +0100205 uint32_t mask;
206
eric miaoc0a596d2008-03-11 09:46:28 +0800207 if (gpio >= 0 && gpio < 128)
208 return gpio_set_wake(gpio, on);
eric miaoc95530c2007-08-29 10:22:17 +0100209
Lennert Buytenheka3f4c922010-11-29 11:18:26 +0100210 if (d->irq == IRQ_KEYPAD)
eric miaoc0a596d2008-03-11 09:46:28 +0800211 return keypad_set_wake(on);
eric miaoc95530c2007-08-29 10:22:17 +0100212
Lennert Buytenheka3f4c922010-11-29 11:18:26 +0100213 switch (d->irq) {
eric miaoc95530c2007-08-29 10:22:17 +0100214 case IRQ_RTCAlrm:
215 mask = PWER_RTC;
216 break;
217 case IRQ_USB:
218 mask = 1u << 26;
219 break;
220 default:
221 return -EINVAL;
222 }
223
eric miaoc95530c2007-08-29 10:22:17 +0100224 if (on)
225 PWER |= mask;
226 else
227 PWER &=~mask;
228
229 return 0;
230}
231
232void __init pxa27x_init_irq(void)
233{
eric miaob9e25ac2008-03-04 14:19:58 +0800234 pxa_init_irq(34, pxa27x_set_wake);
eric miaoc95530c2007-08-29 10:22:17 +0100235}
236
Robert Jarzmik32f17992016-08-15 00:24:55 +0200237static int __init
238pxa27x_dt_init_irq(struct device_node *node, struct device_node *parent)
Robert Jarzmikef6dbda2014-09-28 15:20:06 +0200239{
Robert Jarzmik32f17992016-08-15 00:24:55 +0200240 pxa_dt_irq_init(pxa27x_set_wake);
241 set_handle_irq(ichp_handle_irq);
242
243 return 0;
Robert Jarzmikef6dbda2014-09-28 15:20:06 +0200244}
Robert Jarzmik32f17992016-08-15 00:24:55 +0200245IRQCHIP_DECLARE(pxa27x_intc, "marvell,pxa-intc", pxa27x_dt_init_irq);
Robert Jarzmikef6dbda2014-09-28 15:20:06 +0200246
Marek Vasut851982c2010-10-11 02:20:19 +0200247static struct map_desc pxa27x_io_desc[] __initdata = {
248 { /* Mem Ctl */
Arnd Bergmann97b09da2011-10-01 22:03:45 +0200249 .virtual = (unsigned long)SMEMC_VIRT,
Marek Vasutad68bb92010-11-03 16:29:35 +0100250 .pfn = __phys_to_pfn(PXA2XX_SMEMC_BASE),
Laurent Pinchart0e329862014-07-11 13:00:36 +0200251 .length = SMEMC_SIZE,
Marek Vasut851982c2010-10-11 02:20:19 +0200252 .type = MT_DEVICE
Laurent Pinchartb10f1c82014-07-11 13:00:37 +0200253 }, { /* UNCACHED_PHYS_0 */
254 .virtual = UNCACHED_PHYS_0,
255 .pfn = __phys_to_pfn(0x00000000),
256 .length = UNCACHED_PHYS_0_SIZE,
257 .type = MT_DEVICE
Marek Vasut851982c2010-10-11 02:20:19 +0200258 },
259};
260
261void __init pxa27x_map_io(void)
262{
263 pxa_map_io();
264 iotable_init(ARRAY_AND_SIZE(pxa27x_io_desc));
265 pxa27x_get_clk_frequency_khz(1);
266}
267
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268/*
269 * device registration specific to PXA27x.
270 */
Mike Rapoport9ba63c42008-08-17 06:23:05 +0100271void __init pxa27x_set_i2c_power_info(struct i2c_pxa_platform_data *info)
Mike Rapoportb7a36702008-01-27 18:14:50 +0100272{
Philipp Zabelbc3a5952008-06-02 18:49:27 +0100273 local_irq_disable();
274 PCFR |= PCFR_PI2CEN;
275 local_irq_enable();
Eric Miao14758222008-11-28 15:24:12 +0800276 pxa_register_device(&pxa27x_device_i2c_power, info);
Mike Rapoportb7a36702008-01-27 18:14:50 +0100277}
278
Robert Jarzmikb95ace52012-04-22 13:37:24 +0200279static struct pxa_gpio_platform_data pxa27x_gpio_info __initdata = {
Haojian Zhuangb8f649f2013-04-09 18:12:04 +0800280 .irq_base = PXA_GPIO_TO_IRQ(0),
281 .gpio_set_wake = gpio_set_wake,
Robert Jarzmikb95ace52012-04-22 13:37:24 +0200282};
283
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284static struct platform_device *devices[] __initdata = {
Philipp Zabel7a857622008-06-22 23:36:39 +0100285 &pxa27x_device_udc,
Eric Miao09a53582010-06-14 00:43:00 +0800286 &pxa_device_pmu,
Eric Miaoe09d02e2007-07-17 10:45:58 +0100287 &pxa_device_i2s,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000288 &pxa_device_asoc_ssp1,
289 &pxa_device_asoc_ssp2,
290 &pxa_device_asoc_ssp3,
291 &pxa_device_asoc_platform,
Eric Miaoe09d02e2007-07-17 10:45:58 +0100292 &pxa_device_rtc,
eric miaod8e0db12007-12-10 17:54:36 +0800293 &pxa27x_device_ssp1,
294 &pxa27x_device_ssp2,
295 &pxa27x_device_ssp3,
eric miao75540c12008-04-13 21:44:04 +0100296 &pxa27x_device_pwm0,
297 &pxa27x_device_pwm1,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298};
299
Robert Jarzmik1da10c12018-06-17 19:02:05 +0200300static const struct dma_slave_map pxa27x_slave_map[] = {
301 /* PXA25x, PXA27x and PXA3xx common entries */
302 { "pxa2xx-ac97", "pcm_pcm_mic_mono", PDMA_FILTER_PARAM(LOWEST, 8) },
303 { "pxa2xx-ac97", "pcm_pcm_aux_mono_in", PDMA_FILTER_PARAM(LOWEST, 9) },
304 { "pxa2xx-ac97", "pcm_pcm_aux_mono_out",
305 PDMA_FILTER_PARAM(LOWEST, 10) },
306 { "pxa2xx-ac97", "pcm_pcm_stereo_in", PDMA_FILTER_PARAM(LOWEST, 11) },
307 { "pxa2xx-ac97", "pcm_pcm_stereo_out", PDMA_FILTER_PARAM(LOWEST, 12) },
308 { "pxa-ssp-dai.0", "rx", PDMA_FILTER_PARAM(LOWEST, 13) },
309 { "pxa-ssp-dai.0", "tx", PDMA_FILTER_PARAM(LOWEST, 14) },
310 { "pxa-ssp-dai.1", "rx", PDMA_FILTER_PARAM(LOWEST, 15) },
311 { "pxa-ssp-dai.1", "tx", PDMA_FILTER_PARAM(LOWEST, 16) },
312 { "pxa2xx-ir", "rx", PDMA_FILTER_PARAM(LOWEST, 17) },
313 { "pxa2xx-ir", "tx", PDMA_FILTER_PARAM(LOWEST, 18) },
314 { "pxa2xx-mci.0", "rx", PDMA_FILTER_PARAM(LOWEST, 21) },
315 { "pxa2xx-mci.0", "tx", PDMA_FILTER_PARAM(LOWEST, 22) },
316 { "pxa-ssp-dai.2", "rx", PDMA_FILTER_PARAM(LOWEST, 66) },
317 { "pxa-ssp-dai.2", "tx", PDMA_FILTER_PARAM(LOWEST, 67) },
318
319 /* PXA27x specific map */
320 { "pxa2xx-i2s", "rx", PDMA_FILTER_PARAM(LOWEST, 2) },
321 { "pxa2xx-i2s", "tx", PDMA_FILTER_PARAM(LOWEST, 3) },
322 { "pxa27x-camera.0", "CI_Y", PDMA_FILTER_PARAM(HIGHEST, 68) },
323 { "pxa27x-camera.0", "CI_U", PDMA_FILTER_PARAM(HIGHEST, 69) },
324 { "pxa27x-camera.0", "CI_V", PDMA_FILTER_PARAM(HIGHEST, 70) },
325};
326
327static struct mmp_dma_platdata pxa27x_dma_pdata = {
328 .dma_channels = 32,
329 .nb_requestors = 75,
330 .slave_map = pxa27x_slave_map,
331 .slave_map_cnt = ARRAY_SIZE(pxa27x_slave_map),
332};
333
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334static int __init pxa27x_init(void)
335{
Rafael J. Wysocki2eaa03b2011-04-22 22:03:11 +0200336 int ret = 0;
eric miaoc01655042008-01-28 23:00:02 +0000337
Russell Kinge176bb02007-05-15 11:16:10 +0100338 if (cpu_is_pxa27x()) {
Eric Miao04fef222008-07-29 14:26:00 +0800339
340 reset_status = RCSR;
341
Eric Miao711be5c2007-07-18 11:38:45 +0100342 pxa27x_init_pm();
eric miaof79299c2008-01-02 08:24:49 +0800343
Rafael J. Wysocki2eaa03b2011-04-22 22:03:11 +0200344 register_syscore_ops(&pxa_irq_syscore_ops);
345 register_syscore_ops(&pxa2xx_mfp_syscore_ops);
eric miaoc01655042008-01-28 23:00:02 +0000346
Robert Jarzmik24e32a52015-02-07 22:18:34 +0100347 if (!of_have_populated_dt()) {
348 pxa_register_device(&pxa27x_device_gpio,
349 &pxa27x_gpio_info);
Robert Jarzmik1da10c12018-06-17 19:02:05 +0200350 pxa2xx_set_dmac_info(&pxa27x_dma_pdata);
Robert Jarzmik24e32a52015-02-07 22:18:34 +0100351 ret = platform_add_devices(devices,
352 ARRAY_SIZE(devices));
353 }
Russell Kinge176bb02007-05-15 11:16:10 +0100354 }
eric miaoc01655042008-01-28 23:00:02 +0000355
Russell Kinge176bb02007-05-15 11:16:10 +0100356 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357}
358
Russell King1c104e02008-04-19 10:59:24 +0100359postcore_initcall(pxa27x_init);