xref: /openbmc/linux/arch/arm/mach-pxa/pxa3xx.c (revision aae8224d)
12c8086a5Seric miao /*
22c8086a5Seric miao  * linux/arch/arm/mach-pxa/pxa3xx.c
32c8086a5Seric miao  *
42c8086a5Seric miao  * code specific to pxa3xx aka Monahans
52c8086a5Seric miao  *
62c8086a5Seric miao  * Copyright (C) 2006 Marvell International Ltd.
72c8086a5Seric miao  *
8e9bba8eeSeric miao  * 2007-09-02: eric miao <eric.miao@marvell.com>
92c8086a5Seric miao  *             initial version
102c8086a5Seric miao  *
112c8086a5Seric miao  * This program is free software; you can redistribute it and/or modify
122c8086a5Seric miao  * it under the terms of the GNU General Public License version 2 as
132c8086a5Seric miao  * published by the Free Software Foundation.
142c8086a5Seric miao  */
152c8086a5Seric miao 
162c8086a5Seric miao #include <linux/module.h>
172c8086a5Seric miao #include <linux/kernel.h>
182c8086a5Seric miao #include <linux/init.h>
192c8086a5Seric miao #include <linux/pm.h>
202c8086a5Seric miao #include <linux/platform_device.h>
212c8086a5Seric miao #include <linux/irq.h>
227b5dea12SRussell King #include <linux/io.h>
23c0165504Seric miao #include <linux/sysdev.h>
242c8086a5Seric miao 
25851982c1SMarek Vasut #include <asm/mach/map.h>
26a09e64fbSRussell King #include <mach/hardware.h>
27a58fbcd8SEric Miao #include <mach/gpio.h>
28a09e64fbSRussell King #include <mach/pxa3xx-regs.h>
29afd2fc02SRussell King #include <mach/reset.h>
30a09e64fbSRussell King #include <mach/ohci.h>
31a09e64fbSRussell King #include <mach/pm.h>
32a09e64fbSRussell King #include <mach/dma.h>
33bf293aecSMike Rapoport #include <mach/regs-intc.h>
34ad68bb9fSMarek Vasut #include <mach/smemc.h>
35f0a83701SEric Miao #include <plat/i2c.h>
362c8086a5Seric miao 
372c8086a5Seric miao #include "generic.h"
382c8086a5Seric miao #include "devices.h"
392c8086a5Seric miao #include "clock.h"
402c8086a5Seric miao 
41bf293aecSMike Rapoport #define PECR_IE(n)	((1 << ((n) * 2)) << 28)
42bf293aecSMike Rapoport #define PECR_IS(n)	((1 << ((n) * 2)) << 29)
43bf293aecSMike Rapoport 
4404fef228SEric Miao void pxa3xx_clear_reset_status(unsigned int mask)
4504fef228SEric Miao {
4604fef228SEric Miao 	/* RESET_STATUS_* has a 1:1 mapping with ARSR */
4704fef228SEric Miao 	ARSR = mask;
4804fef228SEric Miao }
4904fef228SEric Miao 
508c3abc7dSRussell King static DEFINE_PXA3_CKEN(pxa3xx_ffuart, FFUART, 14857000, 1);
518c3abc7dSRussell King static DEFINE_PXA3_CKEN(pxa3xx_btuart, BTUART, 14857000, 1);
528c3abc7dSRussell King static DEFINE_PXA3_CKEN(pxa3xx_stuart, STUART, 14857000, 1);
538c3abc7dSRussell King static DEFINE_PXA3_CKEN(pxa3xx_i2c, I2C, 32842000, 0);
548c3abc7dSRussell King static DEFINE_PXA3_CKEN(pxa3xx_udc, UDC, 48000000, 5);
558c3abc7dSRussell King static DEFINE_PXA3_CKEN(pxa3xx_usbh, USBH, 48000000, 0);
56e68750aeSIgor Grinberg static DEFINE_PXA3_CKEN(pxa3xx_u2d, USB2, 48000000, 0);
578c3abc7dSRussell King static DEFINE_PXA3_CKEN(pxa3xx_keypad, KEYPAD, 32768, 0);
588c3abc7dSRussell King static DEFINE_PXA3_CKEN(pxa3xx_ssp1, SSP1, 13000000, 0);
598c3abc7dSRussell King static DEFINE_PXA3_CKEN(pxa3xx_ssp2, SSP2, 13000000, 0);
608c3abc7dSRussell King static DEFINE_PXA3_CKEN(pxa3xx_ssp3, SSP3, 13000000, 0);
618c3abc7dSRussell King static DEFINE_PXA3_CKEN(pxa3xx_ssp4, SSP4, 13000000, 0);
628c3abc7dSRussell King static DEFINE_PXA3_CKEN(pxa3xx_pwm0, PWM0, 13000000, 0);
638c3abc7dSRussell King static DEFINE_PXA3_CKEN(pxa3xx_pwm1, PWM1, 13000000, 0);
648c3abc7dSRussell King static DEFINE_PXA3_CKEN(pxa3xx_mmc1, MMC1, 19500000, 0);
658c3abc7dSRussell King static DEFINE_PXA3_CKEN(pxa3xx_mmc2, MMC2, 19500000, 0);
662c8086a5Seric miao 
672e8581e7SEric Miao static DEFINE_CK(pxa3xx_lcd, LCD, &clk_pxa3xx_hsio_ops);
682e8581e7SEric Miao static DEFINE_CK(pxa3xx_camera, CAMERA, &clk_pxa3xx_hsio_ops);
692e8581e7SEric Miao static DEFINE_CK(pxa3xx_ac97, AC97, &clk_pxa3xx_ac97_ops);
704029813cSEric Miao static DEFINE_CLK(pxa3xx_pout, &clk_pxa3xx_pout_ops, 13000000, 70);
712e8581e7SEric Miao 
728c3abc7dSRussell King static struct clk_lookup pxa3xx_clkregs[] = {
738c3abc7dSRussell King 	INIT_CLKREG(&clk_pxa3xx_pout, NULL, "CLK_POUT"),
748c3abc7dSRussell King 	/* Power I2C clock is always on */
755c68b099SDaniel Mack 	INIT_CLKREG(&clk_dummy, "pxa3xx-pwri2c.1", NULL),
768c3abc7dSRussell King 	INIT_CLKREG(&clk_pxa3xx_lcd, "pxa2xx-fb", NULL),
778c3abc7dSRussell King 	INIT_CLKREG(&clk_pxa3xx_camera, NULL, "CAMCLK"),
788c3abc7dSRussell King 	INIT_CLKREG(&clk_pxa3xx_ac97, NULL, "AC97CLK"),
798c3abc7dSRussell King 	INIT_CLKREG(&clk_pxa3xx_ffuart, "pxa2xx-uart.0", NULL),
808c3abc7dSRussell King 	INIT_CLKREG(&clk_pxa3xx_btuart, "pxa2xx-uart.1", NULL),
818c3abc7dSRussell King 	INIT_CLKREG(&clk_pxa3xx_stuart, "pxa2xx-uart.2", NULL),
828c3abc7dSRussell King 	INIT_CLKREG(&clk_pxa3xx_stuart, "pxa2xx-ir", "UARTCLK"),
838c3abc7dSRussell King 	INIT_CLKREG(&clk_pxa3xx_i2c, "pxa2xx-i2c.0", NULL),
848c3abc7dSRussell King 	INIT_CLKREG(&clk_pxa3xx_udc, "pxa27x-udc", NULL),
858c3abc7dSRussell King 	INIT_CLKREG(&clk_pxa3xx_usbh, "pxa27x-ohci", NULL),
8669f22be7SIgor Grinberg 	INIT_CLKREG(&clk_pxa3xx_u2d, "pxa3xx-u2d", NULL),
878c3abc7dSRussell King 	INIT_CLKREG(&clk_pxa3xx_keypad, "pxa27x-keypad", NULL),
888c3abc7dSRussell King 	INIT_CLKREG(&clk_pxa3xx_ssp1, "pxa27x-ssp.0", NULL),
898c3abc7dSRussell King 	INIT_CLKREG(&clk_pxa3xx_ssp2, "pxa27x-ssp.1", NULL),
908c3abc7dSRussell King 	INIT_CLKREG(&clk_pxa3xx_ssp3, "pxa27x-ssp.2", NULL),
918c3abc7dSRussell King 	INIT_CLKREG(&clk_pxa3xx_ssp4, "pxa27x-ssp.3", NULL),
928c3abc7dSRussell King 	INIT_CLKREG(&clk_pxa3xx_pwm0, "pxa27x-pwm.0", NULL),
938c3abc7dSRussell King 	INIT_CLKREG(&clk_pxa3xx_pwm1, "pxa27x-pwm.1", NULL),
948c3abc7dSRussell King 	INIT_CLKREG(&clk_pxa3xx_mmc1, "pxa2xx-mci.0", NULL),
958c3abc7dSRussell King 	INIT_CLKREG(&clk_pxa3xx_mmc2, "pxa2xx-mci.1", NULL),
962c8086a5Seric miao };
972c8086a5Seric miao 
987b5dea12SRussell King #ifdef CONFIG_PM
997b5dea12SRussell King 
1007b5dea12SRussell King #define ISRAM_START	0x5c000000
1017b5dea12SRussell King #define ISRAM_SIZE	SZ_256K
1027b5dea12SRussell King 
1037b5dea12SRussell King static void __iomem *sram;
1047b5dea12SRussell King static unsigned long wakeup_src;
1057b5dea12SRussell King 
1067b5dea12SRussell King /*
1077b5dea12SRussell King  * Enter a standby mode (S0D1C2 or S0D2C2).  Upon wakeup, the dynamic
1087b5dea12SRussell King  * memory controller has to be reinitialised, so we place some code
1097b5dea12SRussell King  * in the SRAM to perform this function.
1107b5dea12SRussell King  *
1117b5dea12SRussell King  * We disable FIQs across the standby - otherwise, we might receive a
1127b5dea12SRussell King  * FIQ while the SDRAM is unavailable.
1137b5dea12SRussell King  */
1147b5dea12SRussell King static void pxa3xx_cpu_standby(unsigned int pwrmode)
1157b5dea12SRussell King {
1167b5dea12SRussell King 	extern const char pm_enter_standby_start[], pm_enter_standby_end[];
1177b5dea12SRussell King 	void (*fn)(unsigned int) = (void __force *)(sram + 0x8000);
1187b5dea12SRussell King 
1197b5dea12SRussell King 	memcpy_toio(sram + 0x8000, pm_enter_standby_start,
1207b5dea12SRussell King 		    pm_enter_standby_end - pm_enter_standby_start);
1217b5dea12SRussell King 
1227b5dea12SRussell King 	AD2D0SR = ~0;
1237b5dea12SRussell King 	AD2D1SR = ~0;
1247b5dea12SRussell King 	AD2D0ER = wakeup_src;
1257b5dea12SRussell King 	AD2D1ER = 0;
1267b5dea12SRussell King 	ASCR = ASCR;
1277b5dea12SRussell King 	ARSR = ARSR;
1287b5dea12SRussell King 
1297b5dea12SRussell King 	local_fiq_disable();
1307b5dea12SRussell King 	fn(pwrmode);
1317b5dea12SRussell King 	local_fiq_enable();
1327b5dea12SRussell King 
1337b5dea12SRussell King 	AD2D0ER = 0;
1347b5dea12SRussell King 	AD2D1ER = 0;
1357b5dea12SRussell King }
1367b5dea12SRussell King 
137c4d1fb62Seric miao /*
138c4d1fb62Seric miao  * NOTE:  currently, the OBM (OEM Boot Module) binary comes along with
139c4d1fb62Seric miao  * PXA3xx development kits assumes that the resuming process continues
140c4d1fb62Seric miao  * with the address stored within the first 4 bytes of SDRAM. The PSPR
141c4d1fb62Seric miao  * register is used privately by BootROM and OBM, and _must_ be set to
142c4d1fb62Seric miao  * 0x5c014000 for the moment.
143c4d1fb62Seric miao  */
144c4d1fb62Seric miao static void pxa3xx_cpu_pm_suspend(void)
145c4d1fb62Seric miao {
146c4d1fb62Seric miao 	volatile unsigned long *p = (volatile void *)0xc0000000;
147c4d1fb62Seric miao 	unsigned long saved_data = *p;
148c4d1fb62Seric miao 
149c4d1fb62Seric miao 	extern void pxa3xx_cpu_suspend(void);
150c4d1fb62Seric miao 	extern void pxa3xx_cpu_resume(void);
151c4d1fb62Seric miao 
152c4d1fb62Seric miao 	/* resuming from D2 requires the HSIO2/BOOT/TPM clocks enabled */
153c4d1fb62Seric miao 	CKENA |= (1 << CKEN_BOOT) | (1 << CKEN_TPM);
154c4d1fb62Seric miao 	CKENB |= 1 << (CKEN_HSIO2 & 0x1f);
155c4d1fb62Seric miao 
156c4d1fb62Seric miao 	/* clear and setup wakeup source */
157c4d1fb62Seric miao 	AD3SR = ~0;
158c4d1fb62Seric miao 	AD3ER = wakeup_src;
159c4d1fb62Seric miao 	ASCR = ASCR;
160c4d1fb62Seric miao 	ARSR = ARSR;
161c4d1fb62Seric miao 
162c4d1fb62Seric miao 	PCFR |= (1u << 13);			/* L1_DIS */
163c4d1fb62Seric miao 	PCFR &= ~((1u << 12) | (1u << 1));	/* L0_EN | SL_ROD */
164c4d1fb62Seric miao 
165c4d1fb62Seric miao 	PSPR = 0x5c014000;
166c4d1fb62Seric miao 
167c4d1fb62Seric miao 	/* overwrite with the resume address */
168c4d1fb62Seric miao 	*p = virt_to_phys(pxa3xx_cpu_resume);
169c4d1fb62Seric miao 
170c4d1fb62Seric miao 	pxa3xx_cpu_suspend();
171c4d1fb62Seric miao 
172c4d1fb62Seric miao 	*p = saved_data;
173c4d1fb62Seric miao 
174c4d1fb62Seric miao 	AD3ER = 0;
175c4d1fb62Seric miao }
176c4d1fb62Seric miao 
1777b5dea12SRussell King static void pxa3xx_cpu_pm_enter(suspend_state_t state)
1787b5dea12SRussell King {
1797b5dea12SRussell King 	/*
1807b5dea12SRussell King 	 * Don't sleep if no wakeup sources are defined
1817b5dea12SRussell King 	 */
182b86a5da8SMark Brown 	if (wakeup_src == 0) {
183b86a5da8SMark Brown 		printk(KERN_ERR "Not suspending: no wakeup sources\n");
1847b5dea12SRussell King 		return;
185b86a5da8SMark Brown 	}
1867b5dea12SRussell King 
1877b5dea12SRussell King 	switch (state) {
1887b5dea12SRussell King 	case PM_SUSPEND_STANDBY:
1897b5dea12SRussell King 		pxa3xx_cpu_standby(PXA3xx_PM_S0D2C2);
1907b5dea12SRussell King 		break;
1917b5dea12SRussell King 
1927b5dea12SRussell King 	case PM_SUSPEND_MEM:
193c4d1fb62Seric miao 		pxa3xx_cpu_pm_suspend();
1947b5dea12SRussell King 		break;
1957b5dea12SRussell King 	}
1967b5dea12SRussell King }
1977b5dea12SRussell King 
1987b5dea12SRussell King static int pxa3xx_cpu_pm_valid(suspend_state_t state)
1997b5dea12SRussell King {
2007b5dea12SRussell King 	return state == PM_SUSPEND_MEM || state == PM_SUSPEND_STANDBY;
2017b5dea12SRussell King }
2027b5dea12SRussell King 
2037b5dea12SRussell King static struct pxa_cpu_pm_fns pxa3xx_cpu_pm_fns = {
2047b5dea12SRussell King 	.valid		= pxa3xx_cpu_pm_valid,
2057b5dea12SRussell King 	.enter		= pxa3xx_cpu_pm_enter,
2067b5dea12SRussell King };
2077b5dea12SRussell King 
2087b5dea12SRussell King static void __init pxa3xx_init_pm(void)
2097b5dea12SRussell King {
2107b5dea12SRussell King 	sram = ioremap(ISRAM_START, ISRAM_SIZE);
2117b5dea12SRussell King 	if (!sram) {
2127b5dea12SRussell King 		printk(KERN_ERR "Unable to map ISRAM: disabling standby/suspend\n");
2137b5dea12SRussell King 		return;
2147b5dea12SRussell King 	}
2157b5dea12SRussell King 
2167b5dea12SRussell King 	/*
2177b5dea12SRussell King 	 * Since we copy wakeup code into the SRAM, we need to ensure
2187b5dea12SRussell King 	 * that it is preserved over the low power modes.  Note: bit 8
2197b5dea12SRussell King 	 * is undocumented in the developer manual, but must be set.
2207b5dea12SRussell King 	 */
2217b5dea12SRussell King 	AD1R |= ADXR_L2 | ADXR_R0;
2227b5dea12SRussell King 	AD2R |= ADXR_L2 | ADXR_R0;
2237b5dea12SRussell King 	AD3R |= ADXR_L2 | ADXR_R0;
2247b5dea12SRussell King 
2257b5dea12SRussell King 	/*
2267b5dea12SRussell King 	 * Clear the resume enable registers.
2277b5dea12SRussell King 	 */
2287b5dea12SRussell King 	AD1D0ER = 0;
2297b5dea12SRussell King 	AD2D0ER = 0;
2307b5dea12SRussell King 	AD2D1ER = 0;
2317b5dea12SRussell King 	AD3ER = 0;
2327b5dea12SRussell King 
2337b5dea12SRussell King 	pxa_cpu_pm_fns = &pxa3xx_cpu_pm_fns;
2347b5dea12SRussell King }
2357b5dea12SRussell King 
2367b5dea12SRussell King static int pxa3xx_set_wake(unsigned int irq, unsigned int on)
2377b5dea12SRussell King {
2387b5dea12SRussell King 	unsigned long flags, mask = 0;
2397b5dea12SRussell King 
2407b5dea12SRussell King 	switch (irq) {
2417b5dea12SRussell King 	case IRQ_SSP3:
2427b5dea12SRussell King 		mask = ADXER_MFP_WSSP3;
2437b5dea12SRussell King 		break;
2447b5dea12SRussell King 	case IRQ_MSL:
2457b5dea12SRussell King 		mask = ADXER_WMSL0;
2467b5dea12SRussell King 		break;
2477b5dea12SRussell King 	case IRQ_USBH2:
2487b5dea12SRussell King 	case IRQ_USBH1:
2497b5dea12SRussell King 		mask = ADXER_WUSBH;
2507b5dea12SRussell King 		break;
2517b5dea12SRussell King 	case IRQ_KEYPAD:
2527b5dea12SRussell King 		mask = ADXER_WKP;
2537b5dea12SRussell King 		break;
2547b5dea12SRussell King 	case IRQ_AC97:
2557b5dea12SRussell King 		mask = ADXER_MFP_WAC97;
2567b5dea12SRussell King 		break;
2577b5dea12SRussell King 	case IRQ_USIM:
2587b5dea12SRussell King 		mask = ADXER_WUSIM0;
2597b5dea12SRussell King 		break;
2607b5dea12SRussell King 	case IRQ_SSP2:
2617b5dea12SRussell King 		mask = ADXER_MFP_WSSP2;
2627b5dea12SRussell King 		break;
2637b5dea12SRussell King 	case IRQ_I2C:
2647b5dea12SRussell King 		mask = ADXER_MFP_WI2C;
2657b5dea12SRussell King 		break;
2667b5dea12SRussell King 	case IRQ_STUART:
2677b5dea12SRussell King 		mask = ADXER_MFP_WUART3;
2687b5dea12SRussell King 		break;
2697b5dea12SRussell King 	case IRQ_BTUART:
2707b5dea12SRussell King 		mask = ADXER_MFP_WUART2;
2717b5dea12SRussell King 		break;
2727b5dea12SRussell King 	case IRQ_FFUART:
2737b5dea12SRussell King 		mask = ADXER_MFP_WUART1;
2747b5dea12SRussell King 		break;
2757b5dea12SRussell King 	case IRQ_MMC:
2767b5dea12SRussell King 		mask = ADXER_MFP_WMMC1;
2777b5dea12SRussell King 		break;
2787b5dea12SRussell King 	case IRQ_SSP:
2797b5dea12SRussell King 		mask = ADXER_MFP_WSSP1;
2807b5dea12SRussell King 		break;
2817b5dea12SRussell King 	case IRQ_RTCAlrm:
2827b5dea12SRussell King 		mask = ADXER_WRTC;
2837b5dea12SRussell King 		break;
2847b5dea12SRussell King 	case IRQ_SSP4:
2857b5dea12SRussell King 		mask = ADXER_MFP_WSSP4;
2867b5dea12SRussell King 		break;
2877b5dea12SRussell King 	case IRQ_TSI:
2887b5dea12SRussell King 		mask = ADXER_WTSI;
2897b5dea12SRussell King 		break;
2907b5dea12SRussell King 	case IRQ_USIM2:
2917b5dea12SRussell King 		mask = ADXER_WUSIM1;
2927b5dea12SRussell King 		break;
2937b5dea12SRussell King 	case IRQ_MMC2:
2947b5dea12SRussell King 		mask = ADXER_MFP_WMMC2;
2957b5dea12SRussell King 		break;
2967b5dea12SRussell King 	case IRQ_NAND:
2977b5dea12SRussell King 		mask = ADXER_MFP_WFLASH;
2987b5dea12SRussell King 		break;
2997b5dea12SRussell King 	case IRQ_USB2:
3007b5dea12SRussell King 		mask = ADXER_WUSB2;
3017b5dea12SRussell King 		break;
3027b5dea12SRussell King 	case IRQ_WAKEUP0:
3037b5dea12SRussell King 		mask = ADXER_WEXTWAKE0;
3047b5dea12SRussell King 		break;
3057b5dea12SRussell King 	case IRQ_WAKEUP1:
3067b5dea12SRussell King 		mask = ADXER_WEXTWAKE1;
3077b5dea12SRussell King 		break;
3087b5dea12SRussell King 	case IRQ_MMC3:
3097b5dea12SRussell King 		mask = ADXER_MFP_GEN12;
3107b5dea12SRussell King 		break;
311e1217707SMark Brown 	default:
312e1217707SMark Brown 		return -EINVAL;
3137b5dea12SRussell King 	}
3147b5dea12SRussell King 
3157b5dea12SRussell King 	local_irq_save(flags);
3167b5dea12SRussell King 	if (on)
3177b5dea12SRussell King 		wakeup_src |= mask;
3187b5dea12SRussell King 	else
3197b5dea12SRussell King 		wakeup_src &= ~mask;
3207b5dea12SRussell King 	local_irq_restore(flags);
3217b5dea12SRussell King 
3227b5dea12SRussell King 	return 0;
3237b5dea12SRussell King }
3247b5dea12SRussell King #else
3257b5dea12SRussell King static inline void pxa3xx_init_pm(void) {}
326b9e25aceSeric miao #define pxa3xx_set_wake	NULL
3277b5dea12SRussell King #endif
3287b5dea12SRussell King 
329bf293aecSMike Rapoport static void pxa_ack_ext_wakeup(unsigned int irq)
330bf293aecSMike Rapoport {
331bf293aecSMike Rapoport 	PECR |= PECR_IS(irq - IRQ_WAKEUP0);
332bf293aecSMike Rapoport }
333bf293aecSMike Rapoport 
334bf293aecSMike Rapoport static void pxa_mask_ext_wakeup(unsigned int irq)
335bf293aecSMike Rapoport {
336bf293aecSMike Rapoport 	ICMR2 &= ~(1 << ((irq - PXA_IRQ(0)) & 0x1f));
337bf293aecSMike Rapoport 	PECR &= ~PECR_IE(irq - IRQ_WAKEUP0);
338bf293aecSMike Rapoport }
339bf293aecSMike Rapoport 
340bf293aecSMike Rapoport static void pxa_unmask_ext_wakeup(unsigned int irq)
341bf293aecSMike Rapoport {
342bf293aecSMike Rapoport 	ICMR2 |= 1 << ((irq - PXA_IRQ(0)) & 0x1f);
343bf293aecSMike Rapoport 	PECR |= PECR_IE(irq - IRQ_WAKEUP0);
344bf293aecSMike Rapoport }
345bf293aecSMike Rapoport 
34612882096SIgor Grinberg static int pxa_set_ext_wakeup_type(unsigned int irq, unsigned int flow_type)
34712882096SIgor Grinberg {
34812882096SIgor Grinberg 	if (flow_type & IRQ_TYPE_EDGE_RISING)
34912882096SIgor Grinberg 		PWER |= 1 << (irq - IRQ_WAKEUP0);
35012882096SIgor Grinberg 
35112882096SIgor Grinberg 	if (flow_type & IRQ_TYPE_EDGE_FALLING)
35212882096SIgor Grinberg 		PWER |= 1 << (irq - IRQ_WAKEUP0 + 2);
35312882096SIgor Grinberg 
35412882096SIgor Grinberg 	return 0;
35512882096SIgor Grinberg }
35612882096SIgor Grinberg 
357bf293aecSMike Rapoport static struct irq_chip pxa_ext_wakeup_chip = {
358bf293aecSMike Rapoport 	.name		= "WAKEUP",
359bf293aecSMike Rapoport 	.ack		= pxa_ack_ext_wakeup,
360bf293aecSMike Rapoport 	.mask		= pxa_mask_ext_wakeup,
361bf293aecSMike Rapoport 	.unmask		= pxa_unmask_ext_wakeup,
36212882096SIgor Grinberg 	.set_type	= pxa_set_ext_wakeup_type,
363bf293aecSMike Rapoport };
364bf293aecSMike Rapoport 
365bf293aecSMike Rapoport static void __init pxa_init_ext_wakeup_irq(set_wake_t fn)
366bf293aecSMike Rapoport {
367bf293aecSMike Rapoport 	int irq;
368bf293aecSMike Rapoport 
369bf293aecSMike Rapoport 	for (irq = IRQ_WAKEUP0; irq <= IRQ_WAKEUP1; irq++) {
370bf293aecSMike Rapoport 		set_irq_chip(irq, &pxa_ext_wakeup_chip);
371bf293aecSMike Rapoport 		set_irq_handler(irq, handle_edge_irq);
372bf293aecSMike Rapoport 		set_irq_flags(irq, IRQF_VALID);
373bf293aecSMike Rapoport 	}
374bf293aecSMike Rapoport 
375bf293aecSMike Rapoport 	pxa_ext_wakeup_chip.set_wake = fn;
376bf293aecSMike Rapoport }
377bf293aecSMike Rapoport 
3782c8086a5Seric miao void __init pxa3xx_init_irq(void)
3792c8086a5Seric miao {
3802c8086a5Seric miao 	/* enable CP6 access */
3812c8086a5Seric miao 	u32 value;
3822c8086a5Seric miao 	__asm__ __volatile__("mrc p15, 0, %0, c15, c1, 0\n": "=r"(value));
3832c8086a5Seric miao 	value |= (1 << 6);
3842c8086a5Seric miao 	__asm__ __volatile__("mcr p15, 0, %0, c15, c1, 0\n": :"r"(value));
3852c8086a5Seric miao 
386b9e25aceSeric miao 	pxa_init_irq(56, pxa3xx_set_wake);
387bf293aecSMike Rapoport 	pxa_init_ext_wakeup_irq(pxa3xx_set_wake);
388a58fbcd8SEric Miao 	pxa_init_gpio(IRQ_GPIO_2_x, 2, 127, NULL);
3892c8086a5Seric miao }
3902c8086a5Seric miao 
391851982c1SMarek Vasut static struct map_desc pxa3xx_io_desc[] __initdata = {
392851982c1SMarek Vasut 	{	/* Mem Ctl */
393ad68bb9fSMarek Vasut 		.virtual	= SMEMC_VIRT,
394ad68bb9fSMarek Vasut 		.pfn		= __phys_to_pfn(PXA3XX_SMEMC_BASE),
395851982c1SMarek Vasut 		.length		= 0x00200000,
396851982c1SMarek Vasut 		.type		= MT_DEVICE
397851982c1SMarek Vasut 	}
398851982c1SMarek Vasut };
399851982c1SMarek Vasut 
400851982c1SMarek Vasut void __init pxa3xx_map_io(void)
401851982c1SMarek Vasut {
402851982c1SMarek Vasut 	pxa_map_io();
403851982c1SMarek Vasut 	iotable_init(ARRAY_AND_SIZE(pxa3xx_io_desc));
404851982c1SMarek Vasut 	pxa3xx_get_clk_frequency_khz(1);
405851982c1SMarek Vasut }
406851982c1SMarek Vasut 
4072c8086a5Seric miao /*
4082c8086a5Seric miao  * device registration specific to PXA3xx.
4092c8086a5Seric miao  */
4102c8086a5Seric miao 
4119ba63c4fSMike Rapoport void __init pxa3xx_set_i2c_power_info(struct i2c_pxa_platform_data *info)
4129ba63c4fSMike Rapoport {
41314758220SEric Miao 	pxa_register_device(&pxa3xx_device_i2c_power, info);
4149ba63c4fSMike Rapoport }
4159ba63c4fSMike Rapoport 
4162c8086a5Seric miao static struct platform_device *devices[] __initdata = {
41794c35a6bSRobert Jarzmik 	&pxa27x_device_udc,
41809a5358dSEric Miao 	&pxa_device_pmu,
4192c8086a5Seric miao 	&pxa_device_i2s,
420f0fba2adSLiam Girdwood 	&pxa_device_asoc_ssp1,
421f0fba2adSLiam Girdwood 	&pxa_device_asoc_ssp2,
422f0fba2adSLiam Girdwood 	&pxa_device_asoc_ssp3,
423f0fba2adSLiam Girdwood 	&pxa_device_asoc_ssp4,
424f0fba2adSLiam Girdwood 	&pxa_device_asoc_platform,
42572493146SRobert Jarzmik 	&sa1100_device_rtc,
4262c8086a5Seric miao 	&pxa_device_rtc,
427d8e0db11Seric miao 	&pxa27x_device_ssp1,
428d8e0db11Seric miao 	&pxa27x_device_ssp2,
429d8e0db11Seric miao 	&pxa27x_device_ssp3,
430d8e0db11Seric miao 	&pxa3xx_device_ssp4,
43175540c1aSeric miao 	&pxa27x_device_pwm0,
43275540c1aSeric miao 	&pxa27x_device_pwm1,
4332c8086a5Seric miao };
4342c8086a5Seric miao 
435c0165504Seric miao static struct sys_device pxa3xx_sysdev[] = {
436c0165504Seric miao 	{
437c0165504Seric miao 		.cls	= &pxa_irq_sysclass,
43816dfdbf0Seric miao 	}, {
4394be35e23Seric miao 		.cls	= &pxa3xx_mfp_sysclass,
4404be35e23Seric miao 	}, {
44116dfdbf0Seric miao 		.cls	= &pxa_gpio_sysclass,
442aae8224dSEric Miao 	}, {
443aae8224dSEric Miao 		.cls	= &pxa3xx_clock_sysclass,
444aae8224dSEric Miao 	}
445c0165504Seric miao };
446c0165504Seric miao 
4472c8086a5Seric miao static int __init pxa3xx_init(void)
4482c8086a5Seric miao {
449c0165504Seric miao 	int i, ret = 0;
4502c8086a5Seric miao 
4512c8086a5Seric miao 	if (cpu_is_pxa3xx()) {
45204fef228SEric Miao 
45304fef228SEric Miao 		reset_status = ARSR;
45404fef228SEric Miao 
45586260f98SDmitry Krivoschekov 		/*
45686260f98SDmitry Krivoschekov 		 * clear RDH bit every time after reset
45786260f98SDmitry Krivoschekov 		 *
45886260f98SDmitry Krivoschekov 		 * Note: the last 3 bits DxS are write-1-to-clear so carefully
45986260f98SDmitry Krivoschekov 		 * preserve them here in case they will be referenced later
46086260f98SDmitry Krivoschekov 		 */
46186260f98SDmitry Krivoschekov 		ASCR &= ~(ASCR_RDH | ASCR_D1S | ASCR_D2S | ASCR_D3S);
46286260f98SDmitry Krivoschekov 
4630a0300dcSRussell King 		clkdev_add_table(pxa3xx_clkregs, ARRAY_SIZE(pxa3xx_clkregs));
4642c8086a5Seric miao 
465fef1f99aSEric Miao 		if ((ret = pxa_init_dma(IRQ_DMA, 32)))
4662c8086a5Seric miao 			return ret;
4672c8086a5Seric miao 
4687b5dea12SRussell King 		pxa3xx_init_pm();
4697b5dea12SRussell King 
470c0165504Seric miao 		for (i = 0; i < ARRAY_SIZE(pxa3xx_sysdev); i++) {
471c0165504Seric miao 			ret = sysdev_register(&pxa3xx_sysdev[i]);
472c0165504Seric miao 			if (ret)
473c0165504Seric miao 				pr_err("failed to register sysdev[%d]\n", i);
4742c8086a5Seric miao 		}
475c0165504Seric miao 
476c0165504Seric miao 		ret = platform_add_devices(devices, ARRAY_SIZE(devices));
477c0165504Seric miao 	}
478c0165504Seric miao 
479c0165504Seric miao 	return ret;
4802c8086a5Seric miao }
4812c8086a5Seric miao 
4821c104e0eSRussell King postcore_initcall(pxa3xx_init);
483