xref: /openbmc/linux/arch/arm/mach-pxa/pxa3xx.c (revision 04fef228)
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 
252c8086a5Seric miao #include <asm/hardware.h>
262c8086a5Seric miao #include <asm/arch/pxa3xx-regs.h>
2704fef228SEric Miao #include <asm/arch/reset.h>
282c8086a5Seric miao #include <asm/arch/ohci.h>
292c8086a5Seric miao #include <asm/arch/pm.h>
302c8086a5Seric miao #include <asm/arch/dma.h>
312c8086a5Seric miao #include <asm/arch/ssp.h>
322c8086a5Seric miao 
332c8086a5Seric miao #include "generic.h"
342c8086a5Seric miao #include "devices.h"
352c8086a5Seric miao #include "clock.h"
362c8086a5Seric miao 
372c8086a5Seric miao /* Crystal clock: 13MHz */
382c8086a5Seric miao #define BASE_CLK	13000000
392c8086a5Seric miao 
402c8086a5Seric miao /* Ring Oscillator Clock: 60MHz */
412c8086a5Seric miao #define RO_CLK		60000000
422c8086a5Seric miao 
432c8086a5Seric miao #define ACCR_D0CS	(1 << 26)
44c4d1fb62Seric miao #define ACCR_PCCE	(1 << 11)
452c8086a5Seric miao 
462c8086a5Seric miao /* crystal frequency to static memory controller multiplier (SMCFS) */
472c8086a5Seric miao static unsigned char smcfs_mult[8] = { 6, 0, 8, 0, 0, 16, };
482c8086a5Seric miao 
492c8086a5Seric miao /* crystal frequency to HSIO bus frequency multiplier (HSS) */
502c8086a5Seric miao static unsigned char hss_mult[4] = { 8, 12, 16, 0 };
512c8086a5Seric miao 
522c8086a5Seric miao /*
532c8086a5Seric miao  * Get the clock frequency as reflected by CCSR and the turbo flag.
542c8086a5Seric miao  * We assume these values have been applied via a fcs.
552c8086a5Seric miao  * If info is not 0 we also display the current settings.
562c8086a5Seric miao  */
572c8086a5Seric miao unsigned int pxa3xx_get_clk_frequency_khz(int info)
582c8086a5Seric miao {
592c8086a5Seric miao 	unsigned long acsr, xclkcfg;
602c8086a5Seric miao 	unsigned int t, xl, xn, hss, ro, XL, XN, CLK, HSS;
612c8086a5Seric miao 
622c8086a5Seric miao 	/* Read XCLKCFG register turbo bit */
632c8086a5Seric miao 	__asm__ __volatile__("mrc\tp14, 0, %0, c6, c0, 0" : "=r"(xclkcfg));
642c8086a5Seric miao 	t = xclkcfg & 0x1;
652c8086a5Seric miao 
662c8086a5Seric miao 	acsr = ACSR;
672c8086a5Seric miao 
682c8086a5Seric miao 	xl  = acsr & 0x1f;
692c8086a5Seric miao 	xn  = (acsr >> 8) & 0x7;
702c8086a5Seric miao 	hss = (acsr >> 14) & 0x3;
712c8086a5Seric miao 
722c8086a5Seric miao 	XL = xl * BASE_CLK;
732c8086a5Seric miao 	XN = xn * XL;
742c8086a5Seric miao 
752c8086a5Seric miao 	ro = acsr & ACCR_D0CS;
762c8086a5Seric miao 
772c8086a5Seric miao 	CLK = (ro) ? RO_CLK : ((t) ? XN : XL);
782c8086a5Seric miao 	HSS = (ro) ? RO_CLK : hss_mult[hss] * BASE_CLK;
792c8086a5Seric miao 
802c8086a5Seric miao 	if (info) {
812c8086a5Seric miao 		pr_info("RO Mode clock: %d.%02dMHz (%sactive)\n",
822c8086a5Seric miao 			RO_CLK / 1000000, (RO_CLK % 1000000) / 10000,
832c8086a5Seric miao 			(ro) ? "" : "in");
842c8086a5Seric miao 		pr_info("Run Mode clock: %d.%02dMHz (*%d)\n",
852c8086a5Seric miao 			XL / 1000000, (XL % 1000000) / 10000, xl);
862c8086a5Seric miao 		pr_info("Turbo Mode clock: %d.%02dMHz (*%d, %sactive)\n",
872c8086a5Seric miao 			XN / 1000000, (XN % 1000000) / 10000, xn,
882c8086a5Seric miao 			(t) ? "" : "in");
892c8086a5Seric miao 		pr_info("HSIO bus clock: %d.%02dMHz\n",
902c8086a5Seric miao 			HSS / 1000000, (HSS % 1000000) / 10000);
912c8086a5Seric miao 	}
922c8086a5Seric miao 
936232be32Seric miao 	return CLK / 1000;
942c8086a5Seric miao }
952c8086a5Seric miao 
962c8086a5Seric miao /*
972c8086a5Seric miao  * Return the current static memory controller clock frequency
982c8086a5Seric miao  * in units of 10kHz
992c8086a5Seric miao  */
1002c8086a5Seric miao unsigned int pxa3xx_get_memclk_frequency_10khz(void)
1012c8086a5Seric miao {
1022c8086a5Seric miao 	unsigned long acsr;
1032c8086a5Seric miao 	unsigned int smcfs, clk = 0;
1042c8086a5Seric miao 
1052c8086a5Seric miao 	acsr = ACSR;
1062c8086a5Seric miao 
1072c8086a5Seric miao 	smcfs = (acsr >> 23) & 0x7;
1082c8086a5Seric miao 	clk = (acsr & ACCR_D0CS) ? RO_CLK : smcfs_mult[smcfs] * BASE_CLK;
1092c8086a5Seric miao 
1102c8086a5Seric miao 	return (clk / 10000);
1112c8086a5Seric miao }
1122c8086a5Seric miao 
11304fef228SEric Miao void pxa3xx_clear_reset_status(unsigned int mask)
11404fef228SEric Miao {
11504fef228SEric Miao 	/* RESET_STATUS_* has a 1:1 mapping with ARSR */
11604fef228SEric Miao 	ARSR = mask;
11704fef228SEric Miao }
11804fef228SEric Miao 
1192c8086a5Seric miao /*
12060bfe7faSMark Brown  * Return the current AC97 clock frequency.
12160bfe7faSMark Brown  */
12260bfe7faSMark Brown static unsigned long clk_pxa3xx_ac97_getrate(struct clk *clk)
12360bfe7faSMark Brown {
12460bfe7faSMark Brown 	unsigned long rate = 312000000;
12560bfe7faSMark Brown 	unsigned long ac97_div;
12660bfe7faSMark Brown 
12760bfe7faSMark Brown 	ac97_div = AC97_DIV;
12860bfe7faSMark Brown 
12960bfe7faSMark Brown 	/* This may loose precision for some rates but won't for the
13060bfe7faSMark Brown 	 * standard 24.576MHz.
13160bfe7faSMark Brown 	 */
13260bfe7faSMark Brown 	rate /= (ac97_div >> 12) & 0x7fff;
13360bfe7faSMark Brown 	rate *= (ac97_div & 0xfff);
13460bfe7faSMark Brown 
13560bfe7faSMark Brown 	return rate;
13660bfe7faSMark Brown }
13760bfe7faSMark Brown 
13860bfe7faSMark Brown /*
1392c8086a5Seric miao  * Return the current HSIO bus clock frequency
1402c8086a5Seric miao  */
1412c8086a5Seric miao static unsigned long clk_pxa3xx_hsio_getrate(struct clk *clk)
1422c8086a5Seric miao {
1432c8086a5Seric miao 	unsigned long acsr;
1442c8086a5Seric miao 	unsigned int hss, hsio_clk;
1452c8086a5Seric miao 
1462c8086a5Seric miao 	acsr = ACSR;
1472c8086a5Seric miao 
1482c8086a5Seric miao 	hss = (acsr >> 14) & 0x3;
1492c8086a5Seric miao 	hsio_clk = (acsr & ACCR_D0CS) ? RO_CLK : hss_mult[hss] * BASE_CLK;
1502c8086a5Seric miao 
1512c8086a5Seric miao 	return hsio_clk;
1522c8086a5Seric miao }
1532c8086a5Seric miao 
1547a2c5cb0Seric miao void clk_pxa3xx_cken_enable(struct clk *clk)
1552c8086a5Seric miao {
1562c8086a5Seric miao 	unsigned long mask = 1ul << (clk->cken & 0x1f);
1572c8086a5Seric miao 
1582c8086a5Seric miao 	if (clk->cken < 32)
1592c8086a5Seric miao 		CKENA |= mask;
1602c8086a5Seric miao 	else
1612c8086a5Seric miao 		CKENB |= mask;
1622c8086a5Seric miao }
1632c8086a5Seric miao 
1647a2c5cb0Seric miao void clk_pxa3xx_cken_disable(struct clk *clk)
1652c8086a5Seric miao {
1662c8086a5Seric miao 	unsigned long mask = 1ul << (clk->cken & 0x1f);
1672c8086a5Seric miao 
1682c8086a5Seric miao 	if (clk->cken < 32)
1692c8086a5Seric miao 		CKENA &= ~mask;
1702c8086a5Seric miao 	else
1712c8086a5Seric miao 		CKENB &= ~mask;
1722c8086a5Seric miao }
1732c8086a5Seric miao 
1747a2c5cb0Seric miao const struct clkops clk_pxa3xx_cken_ops = {
1752a0d7187Seric miao 	.enable		= clk_pxa3xx_cken_enable,
1762a0d7187Seric miao 	.disable	= clk_pxa3xx_cken_disable,
1772a0d7187Seric miao };
1782a0d7187Seric miao 
1792c8086a5Seric miao static const struct clkops clk_pxa3xx_hsio_ops = {
1802c8086a5Seric miao 	.enable		= clk_pxa3xx_cken_enable,
1812c8086a5Seric miao 	.disable	= clk_pxa3xx_cken_disable,
1822c8086a5Seric miao 	.getrate	= clk_pxa3xx_hsio_getrate,
1832c8086a5Seric miao };
1842c8086a5Seric miao 
18560bfe7faSMark Brown static const struct clkops clk_pxa3xx_ac97_ops = {
18660bfe7faSMark Brown 	.enable		= clk_pxa3xx_cken_enable,
18760bfe7faSMark Brown 	.disable	= clk_pxa3xx_cken_disable,
18860bfe7faSMark Brown 	.getrate	= clk_pxa3xx_ac97_getrate,
18960bfe7faSMark Brown };
19060bfe7faSMark Brown 
191dcc88a17SMark Brown static void clk_pout_enable(struct clk *clk)
192dcc88a17SMark Brown {
193dcc88a17SMark Brown 	OSCC |= OSCC_PEN;
194dcc88a17SMark Brown }
195dcc88a17SMark Brown 
196dcc88a17SMark Brown static void clk_pout_disable(struct clk *clk)
197dcc88a17SMark Brown {
198dcc88a17SMark Brown 	OSCC &= ~OSCC_PEN;
199dcc88a17SMark Brown }
200dcc88a17SMark Brown 
201dcc88a17SMark Brown static const struct clkops clk_pout_ops = {
202dcc88a17SMark Brown 	.enable		= clk_pout_enable,
203dcc88a17SMark Brown 	.disable	= clk_pout_disable,
204dcc88a17SMark Brown };
205dcc88a17SMark Brown 
2062c8086a5Seric miao static struct clk pxa3xx_clks[] = {
207dcc88a17SMark Brown 	{
208dcc88a17SMark Brown 		.name           = "CLK_POUT",
209dcc88a17SMark Brown 		.ops            = &clk_pout_ops,
210dcc88a17SMark Brown 		.rate           = 13000000,
211dcc88a17SMark Brown 		.delay          = 70,
212dcc88a17SMark Brown 	},
213dcc88a17SMark Brown 
2142a0d7187Seric miao 	PXA3xx_CK("LCDCLK",  LCD,    &clk_pxa3xx_hsio_ops, &pxa_device_fb.dev),
2152a0d7187Seric miao 	PXA3xx_CK("CAMCLK",  CAMERA, &clk_pxa3xx_hsio_ops, NULL),
21660bfe7faSMark Brown 	PXA3xx_CK("AC97CLK", AC97,   &clk_pxa3xx_ac97_ops, NULL),
2172c8086a5Seric miao 
2182a0d7187Seric miao 	PXA3xx_CKEN("UARTCLK", FFUART, 14857000, 1, &pxa_device_ffuart.dev),
2192a0d7187Seric miao 	PXA3xx_CKEN("UARTCLK", BTUART, 14857000, 1, &pxa_device_btuart.dev),
2202a0d7187Seric miao 	PXA3xx_CKEN("UARTCLK", STUART, 14857000, 1, NULL),
2212c8086a5Seric miao 
2222a0d7187Seric miao 	PXA3xx_CKEN("I2CCLK", I2C,  32842000, 0, &pxa_device_i2c.dev),
2237a857620SPhilipp Zabel 	PXA3xx_CKEN("UDCCLK", UDC,  48000000, 5, &pxa27x_device_udc.dev),
224f92a629cSeric miao 	PXA3xx_CKEN("USBCLK", USBH, 48000000, 0, &pxa27x_device_ohci.dev),
22537320980Seric miao 	PXA3xx_CKEN("KBDCLK", KEYPAD,  32768, 0, &pxa27x_device_keypad.dev),
226d8e0db11Seric miao 
227d8e0db11Seric miao 	PXA3xx_CKEN("SSPCLK", SSP1, 13000000, 0, &pxa27x_device_ssp1.dev),
228d8e0db11Seric miao 	PXA3xx_CKEN("SSPCLK", SSP2, 13000000, 0, &pxa27x_device_ssp2.dev),
229d8e0db11Seric miao 	PXA3xx_CKEN("SSPCLK", SSP3, 13000000, 0, &pxa27x_device_ssp3.dev),
230d8e0db11Seric miao 	PXA3xx_CKEN("SSPCLK", SSP4, 13000000, 0, &pxa3xx_device_ssp4.dev),
23175540c1aSeric miao 	PXA3xx_CKEN("PWMCLK", PWM0, 13000000, 0, &pxa27x_device_pwm0.dev),
23275540c1aSeric miao 	PXA3xx_CKEN("PWMCLK", PWM1, 13000000, 0, &pxa27x_device_pwm1.dev),
233fafc9d3fSBridge Wu 
234fafc9d3fSBridge Wu 	PXA3xx_CKEN("MMCCLK", MMC1, 19500000, 0, &pxa_device_mci.dev),
2358d33b055SBridge Wu 	PXA3xx_CKEN("MMCCLK", MMC2, 19500000, 0, &pxa3xx_device_mci2.dev),
2362c8086a5Seric miao };
2372c8086a5Seric miao 
2387b5dea12SRussell King #ifdef CONFIG_PM
2397b5dea12SRussell King 
2407b5dea12SRussell King #define ISRAM_START	0x5c000000
2417b5dea12SRussell King #define ISRAM_SIZE	SZ_256K
2427b5dea12SRussell King 
2437b5dea12SRussell King static void __iomem *sram;
2447b5dea12SRussell King static unsigned long wakeup_src;
2457b5dea12SRussell King 
246c4d1fb62Seric miao #define SAVE(x)		sleep_save[SLEEP_SAVE_##x] = x
247c4d1fb62Seric miao #define RESTORE(x)	x = sleep_save[SLEEP_SAVE_##x]
248c4d1fb62Seric miao 
249649de51bSRobert Jarzmik enum {	SLEEP_SAVE_CKENA,
250c4d1fb62Seric miao 	SLEEP_SAVE_CKENB,
251c4d1fb62Seric miao 	SLEEP_SAVE_ACCR,
252c4d1fb62Seric miao 
253649de51bSRobert Jarzmik 	SLEEP_SAVE_COUNT,
254c4d1fb62Seric miao };
255c4d1fb62Seric miao 
2567b5dea12SRussell King static void pxa3xx_cpu_pm_save(unsigned long *sleep_save)
2577b5dea12SRussell King {
258c4d1fb62Seric miao 	SAVE(CKENA);
259c4d1fb62Seric miao 	SAVE(CKENB);
260c4d1fb62Seric miao 	SAVE(ACCR);
2617b5dea12SRussell King }
2627b5dea12SRussell King 
2637b5dea12SRussell King static void pxa3xx_cpu_pm_restore(unsigned long *sleep_save)
2647b5dea12SRussell King {
265c4d1fb62Seric miao 	RESTORE(ACCR);
266c4d1fb62Seric miao 	RESTORE(CKENA);
267c4d1fb62Seric miao 	RESTORE(CKENB);
2687b5dea12SRussell King }
2697b5dea12SRussell King 
2707b5dea12SRussell King /*
2717b5dea12SRussell King  * Enter a standby mode (S0D1C2 or S0D2C2).  Upon wakeup, the dynamic
2727b5dea12SRussell King  * memory controller has to be reinitialised, so we place some code
2737b5dea12SRussell King  * in the SRAM to perform this function.
2747b5dea12SRussell King  *
2757b5dea12SRussell King  * We disable FIQs across the standby - otherwise, we might receive a
2767b5dea12SRussell King  * FIQ while the SDRAM is unavailable.
2777b5dea12SRussell King  */
2787b5dea12SRussell King static void pxa3xx_cpu_standby(unsigned int pwrmode)
2797b5dea12SRussell King {
2807b5dea12SRussell King 	extern const char pm_enter_standby_start[], pm_enter_standby_end[];
2817b5dea12SRussell King 	void (*fn)(unsigned int) = (void __force *)(sram + 0x8000);
2827b5dea12SRussell King 
2837b5dea12SRussell King 	memcpy_toio(sram + 0x8000, pm_enter_standby_start,
2847b5dea12SRussell King 		    pm_enter_standby_end - pm_enter_standby_start);
2857b5dea12SRussell King 
2867b5dea12SRussell King 	AD2D0SR = ~0;
2877b5dea12SRussell King 	AD2D1SR = ~0;
2887b5dea12SRussell King 	AD2D0ER = wakeup_src;
2897b5dea12SRussell King 	AD2D1ER = 0;
2907b5dea12SRussell King 	ASCR = ASCR;
2917b5dea12SRussell King 	ARSR = ARSR;
2927b5dea12SRussell King 
2937b5dea12SRussell King 	local_fiq_disable();
2947b5dea12SRussell King 	fn(pwrmode);
2957b5dea12SRussell King 	local_fiq_enable();
2967b5dea12SRussell King 
2977b5dea12SRussell King 	AD2D0ER = 0;
2987b5dea12SRussell King 	AD2D1ER = 0;
2997b5dea12SRussell King }
3007b5dea12SRussell King 
301c4d1fb62Seric miao /*
302c4d1fb62Seric miao  * NOTE:  currently, the OBM (OEM Boot Module) binary comes along with
303c4d1fb62Seric miao  * PXA3xx development kits assumes that the resuming process continues
304c4d1fb62Seric miao  * with the address stored within the first 4 bytes of SDRAM. The PSPR
305c4d1fb62Seric miao  * register is used privately by BootROM and OBM, and _must_ be set to
306c4d1fb62Seric miao  * 0x5c014000 for the moment.
307c4d1fb62Seric miao  */
308c4d1fb62Seric miao static void pxa3xx_cpu_pm_suspend(void)
309c4d1fb62Seric miao {
310c4d1fb62Seric miao 	volatile unsigned long *p = (volatile void *)0xc0000000;
311c4d1fb62Seric miao 	unsigned long saved_data = *p;
312c4d1fb62Seric miao 
313c4d1fb62Seric miao 	extern void pxa3xx_cpu_suspend(void);
314c4d1fb62Seric miao 	extern void pxa3xx_cpu_resume(void);
315c4d1fb62Seric miao 
316c4d1fb62Seric miao 	/* resuming from D2 requires the HSIO2/BOOT/TPM clocks enabled */
317c4d1fb62Seric miao 	CKENA |= (1 << CKEN_BOOT) | (1 << CKEN_TPM);
318c4d1fb62Seric miao 	CKENB |= 1 << (CKEN_HSIO2 & 0x1f);
319c4d1fb62Seric miao 
320c4d1fb62Seric miao 	/* clear and setup wakeup source */
321c4d1fb62Seric miao 	AD3SR = ~0;
322c4d1fb62Seric miao 	AD3ER = wakeup_src;
323c4d1fb62Seric miao 	ASCR = ASCR;
324c4d1fb62Seric miao 	ARSR = ARSR;
325c4d1fb62Seric miao 
326c4d1fb62Seric miao 	PCFR |= (1u << 13);			/* L1_DIS */
327c4d1fb62Seric miao 	PCFR &= ~((1u << 12) | (1u << 1));	/* L0_EN | SL_ROD */
328c4d1fb62Seric miao 
329c4d1fb62Seric miao 	PSPR = 0x5c014000;
330c4d1fb62Seric miao 
331c4d1fb62Seric miao 	/* overwrite with the resume address */
332c4d1fb62Seric miao 	*p = virt_to_phys(pxa3xx_cpu_resume);
333c4d1fb62Seric miao 
334c4d1fb62Seric miao 	pxa3xx_cpu_suspend();
335c4d1fb62Seric miao 
336c4d1fb62Seric miao 	*p = saved_data;
337c4d1fb62Seric miao 
338c4d1fb62Seric miao 	AD3ER = 0;
339c4d1fb62Seric miao }
340c4d1fb62Seric miao 
3417b5dea12SRussell King static void pxa3xx_cpu_pm_enter(suspend_state_t state)
3427b5dea12SRussell King {
3437b5dea12SRussell King 	/*
3447b5dea12SRussell King 	 * Don't sleep if no wakeup sources are defined
3457b5dea12SRussell King 	 */
346b86a5da8SMark Brown 	if (wakeup_src == 0) {
347b86a5da8SMark Brown 		printk(KERN_ERR "Not suspending: no wakeup sources\n");
3487b5dea12SRussell King 		return;
349b86a5da8SMark Brown 	}
3507b5dea12SRussell King 
3517b5dea12SRussell King 	switch (state) {
3527b5dea12SRussell King 	case PM_SUSPEND_STANDBY:
3537b5dea12SRussell King 		pxa3xx_cpu_standby(PXA3xx_PM_S0D2C2);
3547b5dea12SRussell King 		break;
3557b5dea12SRussell King 
3567b5dea12SRussell King 	case PM_SUSPEND_MEM:
357c4d1fb62Seric miao 		pxa3xx_cpu_pm_suspend();
3587b5dea12SRussell King 		break;
3597b5dea12SRussell King 	}
3607b5dea12SRussell King }
3617b5dea12SRussell King 
3627b5dea12SRussell King static int pxa3xx_cpu_pm_valid(suspend_state_t state)
3637b5dea12SRussell King {
3647b5dea12SRussell King 	return state == PM_SUSPEND_MEM || state == PM_SUSPEND_STANDBY;
3657b5dea12SRussell King }
3667b5dea12SRussell King 
3677b5dea12SRussell King static struct pxa_cpu_pm_fns pxa3xx_cpu_pm_fns = {
368649de51bSRobert Jarzmik 	.save_count	= SLEEP_SAVE_COUNT,
3697b5dea12SRussell King 	.save		= pxa3xx_cpu_pm_save,
3707b5dea12SRussell King 	.restore	= pxa3xx_cpu_pm_restore,
3717b5dea12SRussell King 	.valid		= pxa3xx_cpu_pm_valid,
3727b5dea12SRussell King 	.enter		= pxa3xx_cpu_pm_enter,
3737b5dea12SRussell King };
3747b5dea12SRussell King 
3757b5dea12SRussell King static void __init pxa3xx_init_pm(void)
3767b5dea12SRussell King {
3777b5dea12SRussell King 	sram = ioremap(ISRAM_START, ISRAM_SIZE);
3787b5dea12SRussell King 	if (!sram) {
3797b5dea12SRussell King 		printk(KERN_ERR "Unable to map ISRAM: disabling standby/suspend\n");
3807b5dea12SRussell King 		return;
3817b5dea12SRussell King 	}
3827b5dea12SRussell King 
3837b5dea12SRussell King 	/*
3847b5dea12SRussell King 	 * Since we copy wakeup code into the SRAM, we need to ensure
3857b5dea12SRussell King 	 * that it is preserved over the low power modes.  Note: bit 8
3867b5dea12SRussell King 	 * is undocumented in the developer manual, but must be set.
3877b5dea12SRussell King 	 */
3887b5dea12SRussell King 	AD1R |= ADXR_L2 | ADXR_R0;
3897b5dea12SRussell King 	AD2R |= ADXR_L2 | ADXR_R0;
3907b5dea12SRussell King 	AD3R |= ADXR_L2 | ADXR_R0;
3917b5dea12SRussell King 
3927b5dea12SRussell King 	/*
3937b5dea12SRussell King 	 * Clear the resume enable registers.
3947b5dea12SRussell King 	 */
3957b5dea12SRussell King 	AD1D0ER = 0;
3967b5dea12SRussell King 	AD2D0ER = 0;
3977b5dea12SRussell King 	AD2D1ER = 0;
3987b5dea12SRussell King 	AD3ER = 0;
3997b5dea12SRussell King 
4007b5dea12SRussell King 	pxa_cpu_pm_fns = &pxa3xx_cpu_pm_fns;
4017b5dea12SRussell King }
4027b5dea12SRussell King 
4037b5dea12SRussell King static int pxa3xx_set_wake(unsigned int irq, unsigned int on)
4047b5dea12SRussell King {
4057b5dea12SRussell King 	unsigned long flags, mask = 0;
4067b5dea12SRussell King 
4077b5dea12SRussell King 	switch (irq) {
4087b5dea12SRussell King 	case IRQ_SSP3:
4097b5dea12SRussell King 		mask = ADXER_MFP_WSSP3;
4107b5dea12SRussell King 		break;
4117b5dea12SRussell King 	case IRQ_MSL:
4127b5dea12SRussell King 		mask = ADXER_WMSL0;
4137b5dea12SRussell King 		break;
4147b5dea12SRussell King 	case IRQ_USBH2:
4157b5dea12SRussell King 	case IRQ_USBH1:
4167b5dea12SRussell King 		mask = ADXER_WUSBH;
4177b5dea12SRussell King 		break;
4187b5dea12SRussell King 	case IRQ_KEYPAD:
4197b5dea12SRussell King 		mask = ADXER_WKP;
4207b5dea12SRussell King 		break;
4217b5dea12SRussell King 	case IRQ_AC97:
4227b5dea12SRussell King 		mask = ADXER_MFP_WAC97;
4237b5dea12SRussell King 		break;
4247b5dea12SRussell King 	case IRQ_USIM:
4257b5dea12SRussell King 		mask = ADXER_WUSIM0;
4267b5dea12SRussell King 		break;
4277b5dea12SRussell King 	case IRQ_SSP2:
4287b5dea12SRussell King 		mask = ADXER_MFP_WSSP2;
4297b5dea12SRussell King 		break;
4307b5dea12SRussell King 	case IRQ_I2C:
4317b5dea12SRussell King 		mask = ADXER_MFP_WI2C;
4327b5dea12SRussell King 		break;
4337b5dea12SRussell King 	case IRQ_STUART:
4347b5dea12SRussell King 		mask = ADXER_MFP_WUART3;
4357b5dea12SRussell King 		break;
4367b5dea12SRussell King 	case IRQ_BTUART:
4377b5dea12SRussell King 		mask = ADXER_MFP_WUART2;
4387b5dea12SRussell King 		break;
4397b5dea12SRussell King 	case IRQ_FFUART:
4407b5dea12SRussell King 		mask = ADXER_MFP_WUART1;
4417b5dea12SRussell King 		break;
4427b5dea12SRussell King 	case IRQ_MMC:
4437b5dea12SRussell King 		mask = ADXER_MFP_WMMC1;
4447b5dea12SRussell King 		break;
4457b5dea12SRussell King 	case IRQ_SSP:
4467b5dea12SRussell King 		mask = ADXER_MFP_WSSP1;
4477b5dea12SRussell King 		break;
4487b5dea12SRussell King 	case IRQ_RTCAlrm:
4497b5dea12SRussell King 		mask = ADXER_WRTC;
4507b5dea12SRussell King 		break;
4517b5dea12SRussell King 	case IRQ_SSP4:
4527b5dea12SRussell King 		mask = ADXER_MFP_WSSP4;
4537b5dea12SRussell King 		break;
4547b5dea12SRussell King 	case IRQ_TSI:
4557b5dea12SRussell King 		mask = ADXER_WTSI;
4567b5dea12SRussell King 		break;
4577b5dea12SRussell King 	case IRQ_USIM2:
4587b5dea12SRussell King 		mask = ADXER_WUSIM1;
4597b5dea12SRussell King 		break;
4607b5dea12SRussell King 	case IRQ_MMC2:
4617b5dea12SRussell King 		mask = ADXER_MFP_WMMC2;
4627b5dea12SRussell King 		break;
4637b5dea12SRussell King 	case IRQ_NAND:
4647b5dea12SRussell King 		mask = ADXER_MFP_WFLASH;
4657b5dea12SRussell King 		break;
4667b5dea12SRussell King 	case IRQ_USB2:
4677b5dea12SRussell King 		mask = ADXER_WUSB2;
4687b5dea12SRussell King 		break;
4697b5dea12SRussell King 	case IRQ_WAKEUP0:
4707b5dea12SRussell King 		mask = ADXER_WEXTWAKE0;
4717b5dea12SRussell King 		break;
4727b5dea12SRussell King 	case IRQ_WAKEUP1:
4737b5dea12SRussell King 		mask = ADXER_WEXTWAKE1;
4747b5dea12SRussell King 		break;
4757b5dea12SRussell King 	case IRQ_MMC3:
4767b5dea12SRussell King 		mask = ADXER_MFP_GEN12;
4777b5dea12SRussell King 		break;
478e1217707SMark Brown 	default:
479e1217707SMark Brown 		return -EINVAL;
4807b5dea12SRussell King 	}
4817b5dea12SRussell King 
4827b5dea12SRussell King 	local_irq_save(flags);
4837b5dea12SRussell King 	if (on)
4847b5dea12SRussell King 		wakeup_src |= mask;
4857b5dea12SRussell King 	else
4867b5dea12SRussell King 		wakeup_src &= ~mask;
4877b5dea12SRussell King 	local_irq_restore(flags);
4887b5dea12SRussell King 
4897b5dea12SRussell King 	return 0;
4907b5dea12SRussell King }
4917b5dea12SRussell King #else
4927b5dea12SRussell King static inline void pxa3xx_init_pm(void) {}
493b9e25aceSeric miao #define pxa3xx_set_wake	NULL
4947b5dea12SRussell King #endif
4957b5dea12SRussell King 
4962c8086a5Seric miao void __init pxa3xx_init_irq(void)
4972c8086a5Seric miao {
4982c8086a5Seric miao 	/* enable CP6 access */
4992c8086a5Seric miao 	u32 value;
5002c8086a5Seric miao 	__asm__ __volatile__("mrc p15, 0, %0, c15, c1, 0\n": "=r"(value));
5012c8086a5Seric miao 	value |= (1 << 6);
5022c8086a5Seric miao 	__asm__ __volatile__("mcr p15, 0, %0, c15, c1, 0\n": :"r"(value));
5032c8086a5Seric miao 
504b9e25aceSeric miao 	pxa_init_irq(56, pxa3xx_set_wake);
505b9e25aceSeric miao 	pxa_init_gpio(128, NULL);
5062c8086a5Seric miao }
5072c8086a5Seric miao 
5082c8086a5Seric miao /*
5092c8086a5Seric miao  * device registration specific to PXA3xx.
5102c8086a5Seric miao  */
5112c8086a5Seric miao 
5122c8086a5Seric miao static struct platform_device *devices[] __initdata = {
513284d115eSRussell King /*	&pxa_device_udc,	The UDC driver is PXA25x only */
5142c8086a5Seric miao 	&pxa_device_ffuart,
5152c8086a5Seric miao 	&pxa_device_btuart,
5162c8086a5Seric miao 	&pxa_device_stuart,
5172c8086a5Seric miao 	&pxa_device_i2s,
5182c8086a5Seric miao 	&pxa_device_rtc,
519d8e0db11Seric miao 	&pxa27x_device_ssp1,
520d8e0db11Seric miao 	&pxa27x_device_ssp2,
521d8e0db11Seric miao 	&pxa27x_device_ssp3,
522d8e0db11Seric miao 	&pxa3xx_device_ssp4,
52375540c1aSeric miao 	&pxa27x_device_pwm0,
52475540c1aSeric miao 	&pxa27x_device_pwm1,
5252c8086a5Seric miao };
5262c8086a5Seric miao 
527c0165504Seric miao static struct sys_device pxa3xx_sysdev[] = {
528c0165504Seric miao 	{
529c0165504Seric miao 		.cls	= &pxa_irq_sysclass,
53016dfdbf0Seric miao 	}, {
5314be35e23Seric miao 		.cls	= &pxa3xx_mfp_sysclass,
5324be35e23Seric miao 	}, {
53316dfdbf0Seric miao 		.cls	= &pxa_gpio_sysclass,
534c0165504Seric miao 	},
535c0165504Seric miao };
536c0165504Seric miao 
5372c8086a5Seric miao static int __init pxa3xx_init(void)
5382c8086a5Seric miao {
539c0165504Seric miao 	int i, ret = 0;
5402c8086a5Seric miao 
5412c8086a5Seric miao 	if (cpu_is_pxa3xx()) {
54204fef228SEric Miao 
54304fef228SEric Miao 		reset_status = ARSR;
54404fef228SEric Miao 
54586260f98SDmitry Krivoschekov 		/*
54686260f98SDmitry Krivoschekov 		 * clear RDH bit every time after reset
54786260f98SDmitry Krivoschekov 		 *
54886260f98SDmitry Krivoschekov 		 * Note: the last 3 bits DxS are write-1-to-clear so carefully
54986260f98SDmitry Krivoschekov 		 * preserve them here in case they will be referenced later
55086260f98SDmitry Krivoschekov 		 */
55186260f98SDmitry Krivoschekov 		ASCR &= ~(ASCR_RDH | ASCR_D1S | ASCR_D2S | ASCR_D3S);
55286260f98SDmitry Krivoschekov 
5532c8086a5Seric miao 		clks_register(pxa3xx_clks, ARRAY_SIZE(pxa3xx_clks));
5542c8086a5Seric miao 
5552c8086a5Seric miao 		if ((ret = pxa_init_dma(32)))
5562c8086a5Seric miao 			return ret;
5572c8086a5Seric miao 
5587b5dea12SRussell King 		pxa3xx_init_pm();
5597b5dea12SRussell King 
560c0165504Seric miao 		for (i = 0; i < ARRAY_SIZE(pxa3xx_sysdev); i++) {
561c0165504Seric miao 			ret = sysdev_register(&pxa3xx_sysdev[i]);
562c0165504Seric miao 			if (ret)
563c0165504Seric miao 				pr_err("failed to register sysdev[%d]\n", i);
5642c8086a5Seric miao 		}
565c0165504Seric miao 
566c0165504Seric miao 		ret = platform_add_devices(devices, ARRAY_SIZE(devices));
567c0165504Seric miao 	}
568c0165504Seric miao 
569c0165504Seric miao 	return ret;
5702c8086a5Seric miao }
5712c8086a5Seric miao 
5721c104e0eSRussell King postcore_initcall(pxa3xx_init);
573