| 
									
										
										
										
											2008-09-21 21:35:18 +01:00
										 |  |  | /* | 
					
						
							|  |  |  |  * arch/arm/mach-at91/pm_slow_clock.S | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *  Copyright (C) 2006 Savin Zlobec | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * AT91SAM9 support: | 
					
						
							|  |  |  |  *  Copyright (C) 2007 Anti Sullin <anti.sullin@artecdesign.ee
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software; you can redistribute it and/or modify
 | 
					
						
							|  |  |  |  * it under the terms of the GNU General Public License version 2 as | 
					
						
							|  |  |  |  * published by the Free Software Foundation. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <linux/linkage.h> | 
					
						
							|  |  |  | #include <mach/hardware.h> | 
					
						
							|  |  |  | #include <mach/at91_pmc.h> | 
					
						
							| 
									
										
										
										
											2012-02-13 12:58:53 +08:00
										 |  |  | #include <mach/at91_ramc.h> | 
					
						
							| 
									
										
										
										
											2008-09-21 21:35:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-06 11:51:50 +08:00
										 |  |  | #ifdef CONFIG_SOC_AT91SAM9263 | 
					
						
							| 
									
										
										
										
											2008-09-21 21:35:18 +01:00
										 |  |  | /* | 
					
						
							|  |  |  |  * FIXME either or both the SDRAM controllers (EB0, EB1) might be in use;
 | 
					
						
							|  |  |  |  * handle those cases both here and in the Suspend-To-RAM support. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | #warning Assuming EB1 SDRAM controller is *NOT* used | 
					
						
							|  |  |  | #endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* | 
					
						
							|  |  |  |  * When SLOWDOWN_MASTER_CLOCK is defined we will also slow down the Master | 
					
						
							|  |  |  |  * clock during suspend by adjusting its prescalar and divisor. | 
					
						
							|  |  |  |  * NOTE: This hasn't been shown to be stable on SAM9s; and on the RM9200 there
 | 
					
						
							|  |  |  |  *       are errata regarding adjusting the prescalar and divisor. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | #undef SLOWDOWN_MASTER_CLOCK | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define MCKRDY_TIMEOUT		1000 | 
					
						
							|  |  |  | #define MOSCRDY_TIMEOUT 	1000 | 
					
						
							|  |  |  | #define PLLALOCK_TIMEOUT	1000 | 
					
						
							|  |  |  | #define PLLBLOCK_TIMEOUT	1000 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:54 +01:00
										 |  |  | pmc	.req	r0 | 
					
						
							|  |  |  | sdramc	.req	r1 | 
					
						
							|  |  |  | ramc1	.req	r2 | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:55 +01:00
										 |  |  | memctrl	.req	r3 | 
					
						
							|  |  |  | tmp1	.req	r4 | 
					
						
							|  |  |  | tmp2	.req	r5 | 
					
						
							| 
									
										
										
										
											2008-09-21 21:35:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* | 
					
						
							|  |  |  |  * Wait until master clock is ready (after switching master clock source) | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 	.macro wait_mckrdy
 | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:53 +01:00
										 |  |  | 	mov	tmp2, #MCKRDY_TIMEOUT | 
					
						
							|  |  |  | 1:	sub	tmp2, tmp2, #1 | 
					
						
							|  |  |  | 	cmp	tmp2, #0 | 
					
						
							| 
									
										
										
										
											2008-09-21 21:35:18 +01:00
										 |  |  | 	beq	2f | 
					
						
							| 
									
										
										
										
											2011-11-25 09:59:46 +08:00
										 |  |  | 	ldr	tmp1, [pmc, #AT91_PMC_SR] | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:53 +01:00
										 |  |  | 	tst	tmp1, #AT91_PMC_MCKRDY | 
					
						
							| 
									
										
										
										
											2008-09-21 21:35:18 +01:00
										 |  |  | 	beq	1b | 
					
						
							|  |  |  | 2: | 
					
						
							|  |  |  | 	.endm | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* | 
					
						
							|  |  |  |  * Wait until master oscillator has stabilized. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 	.macro wait_moscrdy
 | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:53 +01:00
										 |  |  | 	mov	tmp2, #MOSCRDY_TIMEOUT | 
					
						
							|  |  |  | 1:	sub	tmp2, tmp2, #1 | 
					
						
							|  |  |  | 	cmp	tmp2, #0 | 
					
						
							| 
									
										
										
										
											2008-09-21 21:35:18 +01:00
										 |  |  | 	beq	2f | 
					
						
							| 
									
										
										
										
											2011-11-25 09:59:46 +08:00
										 |  |  | 	ldr	tmp1, [pmc, #AT91_PMC_SR] | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:53 +01:00
										 |  |  | 	tst	tmp1, #AT91_PMC_MOSCS | 
					
						
							| 
									
										
										
										
											2008-09-21 21:35:18 +01:00
										 |  |  | 	beq	1b | 
					
						
							|  |  |  | 2: | 
					
						
							|  |  |  | 	.endm | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* | 
					
						
							|  |  |  |  * Wait until PLLA has locked. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 	.macro wait_pllalock
 | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:53 +01:00
										 |  |  | 	mov	tmp2, #PLLALOCK_TIMEOUT | 
					
						
							|  |  |  | 1:	sub	tmp2, tmp2, #1 | 
					
						
							|  |  |  | 	cmp	tmp2, #0 | 
					
						
							| 
									
										
										
										
											2008-09-21 21:35:18 +01:00
										 |  |  | 	beq	2f | 
					
						
							| 
									
										
										
										
											2011-11-25 09:59:46 +08:00
										 |  |  | 	ldr	tmp1, [pmc, #AT91_PMC_SR] | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:53 +01:00
										 |  |  | 	tst	tmp1, #AT91_PMC_LOCKA | 
					
						
							| 
									
										
										
										
											2008-09-21 21:35:18 +01:00
										 |  |  | 	beq	1b | 
					
						
							|  |  |  | 2: | 
					
						
							|  |  |  | 	.endm | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* | 
					
						
							|  |  |  |  * Wait until PLLB has locked. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 	.macro wait_pllblock
 | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:53 +01:00
										 |  |  | 	mov	tmp2, #PLLBLOCK_TIMEOUT | 
					
						
							|  |  |  | 1:	sub	tmp2, tmp2, #1 | 
					
						
							|  |  |  | 	cmp	tmp2, #0 | 
					
						
							| 
									
										
										
										
											2008-09-21 21:35:18 +01:00
										 |  |  | 	beq	2f | 
					
						
							| 
									
										
										
										
											2011-11-25 09:59:46 +08:00
										 |  |  | 	ldr	tmp1, [pmc, #AT91_PMC_SR] | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:53 +01:00
										 |  |  | 	tst	tmp1, #AT91_PMC_LOCKB | 
					
						
							| 
									
										
										
										
											2008-09-21 21:35:18 +01:00
										 |  |  | 	beq	1b | 
					
						
							|  |  |  | 2: | 
					
						
							|  |  |  | 	.endm | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	.text | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:55 +01:00
										 |  |  | /* void at91_slow_clock(void __iomem *pmc, void __iomem *sdramc, | 
					
						
							|  |  |  |  *			void __iomem *ramc1, int memctrl) | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2008-09-21 21:35:18 +01:00
										 |  |  | ENTRY(at91_slow_clock) | 
					
						
							|  |  |  | 	/* Save registers on stack */ | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:55 +01:00
										 |  |  | 	stmfd	sp!, {r4 - r12, lr} | 
					
						
							| 
									
										
										
										
											2008-09-21 21:35:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* | 
					
						
							|  |  |  | 	 * Register usage: | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:54 +01:00
										 |  |  | 	 *  R0 = Base address of AT91_PMC | 
					
						
							|  |  |  | 	 *  R1 = Base address of RAM Controller (SDRAM, DDRSDR, or AT91_SYS) | 
					
						
							|  |  |  | 	 *  R2 = Base address of second RAM Controller or 0 if not present | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:55 +01:00
										 |  |  | 	 *  R3 = Memory controller | 
					
						
							| 
									
										
										
										
											2008-09-21 21:35:18 +01:00
										 |  |  | 	 *  R4 = temporary register | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:55 +01:00
										 |  |  | 	 *  R5 = temporary register | 
					
						
							| 
									
										
										
										
											2008-09-21 21:35:18 +01:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Drain write buffer */ | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:53 +01:00
										 |  |  | 	mov	tmp1, #0 | 
					
						
							|  |  |  | 	mcr	p15, 0, tmp1, c7, c10, 4 | 
					
						
							| 
									
										
										
										
											2008-09-21 21:35:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:55 +01:00
										 |  |  | 	cmp	memctrl, #AT91_MEMCTRL_MC | 
					
						
							|  |  |  | 	bne	ddr_sr_enable | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* | 
					
						
							|  |  |  | 	 * at91rm9200 Memory controller | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2008-09-21 21:35:18 +01:00
										 |  |  | 	/* Put SDRAM in self-refresh mode */ | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:53 +01:00
										 |  |  | 	mov	tmp1, #1 | 
					
						
							| 
									
										
										
										
											2011-11-16 02:58:31 +08:00
										 |  |  | 	str	tmp1, [sdramc, #AT91RM9200_SDRAMC_SRR] | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:55 +01:00
										 |  |  | 	b	sdr_sr_done | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* | 
					
						
							|  |  |  | 	 * DDRSDR Memory controller | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | ddr_sr_enable: | 
					
						
							|  |  |  | 	cmp	memctrl, #AT91_MEMCTRL_DDRSDR | 
					
						
							|  |  |  | 	bne	sdr_sr_enable | 
					
						
							| 
									
										
										
										
											2008-09-21 21:35:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-21 14:59:27 +01:00
										 |  |  | 	/* prepare for DDRAM self-refresh mode */ | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:53 +01:00
										 |  |  | 	ldr	tmp1, [sdramc, #AT91_DDRSDRC_LPR] | 
					
						
							|  |  |  | 	str	tmp1, .saved_sam9_lpr | 
					
						
							|  |  |  | 	bic	tmp1, #AT91_DDRSDRC_LPCB | 
					
						
							|  |  |  | 	orr	tmp1, #AT91_DDRSDRC_LPCB_SELF_REFRESH | 
					
						
							| 
									
										
										
										
											2010-06-21 14:59:27 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* figure out if we use the second ram controller */ | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:53 +01:00
										 |  |  | 	cmp	ramc1, #0 | 
					
						
							|  |  |  | 	ldrne	tmp2, [ramc1, #AT91_DDRSDRC_LPR] | 
					
						
							|  |  |  | 	strne	tmp2, .saved_sam9_lpr1 | 
					
						
							|  |  |  | 	bicne	tmp2, #AT91_DDRSDRC_LPCB | 
					
						
							|  |  |  | 	orrne	tmp2, #AT91_DDRSDRC_LPCB_SELF_REFRESH | 
					
						
							| 
									
										
										
										
											2010-06-21 14:59:27 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Enable DDRAM self-refresh mode */ | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:53 +01:00
										 |  |  | 	str	tmp1, [sdramc, #AT91_DDRSDRC_LPR] | 
					
						
							|  |  |  | 	strne	tmp2, [ramc1, #AT91_DDRSDRC_LPR] | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:55 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	b	sdr_sr_done | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* | 
					
						
							|  |  |  | 	 * SDRAMC Memory controller | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | sdr_sr_enable: | 
					
						
							| 
									
										
										
										
											2008-09-21 21:35:18 +01:00
										 |  |  | 	/* Enable SDRAM self-refresh mode */ | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:53 +01:00
										 |  |  | 	ldr	tmp1, [sdramc, #AT91_SDRAMC_LPR] | 
					
						
							|  |  |  | 	str	tmp1, .saved_sam9_lpr | 
					
						
							| 
									
										
										
										
											2008-09-21 21:35:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:53 +01:00
										 |  |  | 	bic	tmp1, #AT91_SDRAMC_LPCB | 
					
						
							|  |  |  | 	orr	tmp1, #AT91_SDRAMC_LPCB_SELF_REFRESH | 
					
						
							|  |  |  | 	str	tmp1, [sdramc, #AT91_SDRAMC_LPR] | 
					
						
							| 
									
										
										
										
											2008-09-21 21:35:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:55 +01:00
										 |  |  | sdr_sr_done: | 
					
						
							| 
									
										
										
										
											2008-09-21 21:35:18 +01:00
										 |  |  | 	/* Save Master clock setting */ | 
					
						
							| 
									
										
										
										
											2011-11-25 09:59:46 +08:00
										 |  |  | 	ldr	tmp1, [pmc, #AT91_PMC_MCKR] | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:53 +01:00
										 |  |  | 	str	tmp1, .saved_mckr | 
					
						
							| 
									
										
										
										
											2008-09-21 21:35:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* | 
					
						
							|  |  |  | 	 * Set the Master clock source to slow clock | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:53 +01:00
										 |  |  | 	bic	tmp1, tmp1, #AT91_PMC_CSS | 
					
						
							| 
									
										
										
										
											2011-11-25 09:59:46 +08:00
										 |  |  | 	str	tmp1, [pmc, #AT91_PMC_MCKR] | 
					
						
							| 
									
										
										
										
											2008-09-21 21:35:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	wait_mckrdy | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef SLOWDOWN_MASTER_CLOCK | 
					
						
							|  |  |  | 	/* | 
					
						
							|  |  |  | 	 * Set the Master Clock PRES and MDIV fields. | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * See AT91RM9200 errata #27 and #28 for details. | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:53 +01:00
										 |  |  | 	mov	tmp1, #0 | 
					
						
							| 
									
										
										
										
											2011-11-25 09:59:46 +08:00
										 |  |  | 	str	tmp1, [pmc, #AT91_PMC_MCKR] | 
					
						
							| 
									
										
										
										
											2008-09-21 21:35:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	wait_mckrdy | 
					
						
							|  |  |  | #endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Save PLLA setting and disable it */ | 
					
						
							| 
									
										
										
										
											2011-11-25 09:59:46 +08:00
										 |  |  | 	ldr	tmp1, [pmc, #AT91_CKGR_PLLAR] | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:53 +01:00
										 |  |  | 	str	tmp1, .saved_pllar | 
					
						
							| 
									
										
										
										
											2008-09-21 21:35:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:53 +01:00
										 |  |  | 	mov	tmp1, #AT91_PMC_PLLCOUNT | 
					
						
							|  |  |  | 	orr	tmp1, tmp1, #(1 << 29)		/* bit 29 always set */ | 
					
						
							| 
									
										
										
										
											2011-11-25 09:59:46 +08:00
										 |  |  | 	str	tmp1, [pmc, #AT91_CKGR_PLLAR] | 
					
						
							| 
									
										
										
										
											2008-09-21 21:35:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Save PLLB setting and disable it */ | 
					
						
							| 
									
										
										
										
											2011-11-25 09:59:46 +08:00
										 |  |  | 	ldr	tmp1, [pmc, #AT91_CKGR_PLLBR] | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:53 +01:00
										 |  |  | 	str	tmp1, .saved_pllbr | 
					
						
							| 
									
										
										
										
											2008-09-21 21:35:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:53 +01:00
										 |  |  | 	mov	tmp1, #AT91_PMC_PLLCOUNT | 
					
						
							| 
									
										
										
										
											2011-11-25 09:59:46 +08:00
										 |  |  | 	str	tmp1, [pmc, #AT91_CKGR_PLLBR] | 
					
						
							| 
									
										
										
										
											2008-09-21 21:35:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Turn off the main oscillator */ | 
					
						
							| 
									
										
										
										
											2011-11-25 09:59:46 +08:00
										 |  |  | 	ldr	tmp1, [pmc, #AT91_CKGR_MOR] | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:53 +01:00
										 |  |  | 	bic	tmp1, tmp1, #AT91_PMC_MOSCEN | 
					
						
							| 
									
										
										
										
											2011-11-25 09:59:46 +08:00
										 |  |  | 	str	tmp1, [pmc, #AT91_CKGR_MOR] | 
					
						
							| 
									
										
										
										
											2008-09-21 21:35:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Wait for interrupt */ | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:53 +01:00
										 |  |  | 	mcr	p15, 0, tmp1, c7, c0, 4 | 
					
						
							| 
									
										
										
										
											2008-09-21 21:35:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Turn on the main oscillator */ | 
					
						
							| 
									
										
										
										
											2011-11-25 09:59:46 +08:00
										 |  |  | 	ldr	tmp1, [pmc, #AT91_CKGR_MOR] | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:53 +01:00
										 |  |  | 	orr	tmp1, tmp1, #AT91_PMC_MOSCEN | 
					
						
							| 
									
										
										
										
											2011-11-25 09:59:46 +08:00
										 |  |  | 	str	tmp1, [pmc, #AT91_CKGR_MOR] | 
					
						
							| 
									
										
										
										
											2008-09-21 21:35:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	wait_moscrdy | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Restore PLLB setting */ | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:53 +01:00
										 |  |  | 	ldr	tmp1, .saved_pllbr | 
					
						
							| 
									
										
										
										
											2011-11-25 09:59:46 +08:00
										 |  |  | 	str	tmp1, [pmc, #AT91_CKGR_PLLBR] | 
					
						
							| 
									
										
										
										
											2008-09-21 21:35:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:53 +01:00
										 |  |  | 	tst	tmp1, #(AT91_PMC_MUL &  0xff0000) | 
					
						
							| 
									
										
										
										
											2010-04-08 11:48:16 +01:00
										 |  |  | 	bne	1f | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:53 +01:00
										 |  |  | 	tst	tmp1, #(AT91_PMC_MUL & ~0xff0000) | 
					
						
							| 
									
										
										
										
											2010-04-08 11:48:16 +01:00
										 |  |  | 	beq	2f | 
					
						
							|  |  |  | 1: | 
					
						
							| 
									
										
										
										
											2008-09-21 21:35:18 +01:00
										 |  |  | 	wait_pllblock | 
					
						
							| 
									
										
										
										
											2010-04-08 11:48:16 +01:00
										 |  |  | 2: | 
					
						
							| 
									
										
										
										
											2008-09-21 21:35:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Restore PLLA setting */ | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:53 +01:00
										 |  |  | 	ldr	tmp1, .saved_pllar | 
					
						
							| 
									
										
										
										
											2011-11-25 09:59:46 +08:00
										 |  |  | 	str	tmp1, [pmc, #AT91_CKGR_PLLAR] | 
					
						
							| 
									
										
										
										
											2008-09-21 21:35:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:53 +01:00
										 |  |  | 	tst	tmp1, #(AT91_PMC_MUL &  0xff0000) | 
					
						
							| 
									
										
										
										
											2010-04-08 11:48:16 +01:00
										 |  |  | 	bne	3f | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:53 +01:00
										 |  |  | 	tst	tmp1, #(AT91_PMC_MUL & ~0xff0000) | 
					
						
							| 
									
										
										
										
											2010-04-08 11:48:16 +01:00
										 |  |  | 	beq	4f | 
					
						
							|  |  |  | 3: | 
					
						
							| 
									
										
										
										
											2008-09-21 21:35:18 +01:00
										 |  |  | 	wait_pllalock | 
					
						
							| 
									
										
										
										
											2010-04-08 11:48:16 +01:00
										 |  |  | 4: | 
					
						
							| 
									
										
										
										
											2008-09-21 21:35:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef SLOWDOWN_MASTER_CLOCK | 
					
						
							|  |  |  | 	/* | 
					
						
							|  |  |  | 	 * First set PRES if it was not 0, | 
					
						
							|  |  |  | 	 * than set CSS and MDIV fields. | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * See AT91RM9200 errata #27 and #28 for details. | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:53 +01:00
										 |  |  | 	ldr	tmp1, .saved_mckr | 
					
						
							|  |  |  | 	tst	tmp1, #AT91_PMC_PRES | 
					
						
							| 
									
										
										
										
											2008-09-21 21:35:18 +01:00
										 |  |  | 	beq	2f | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:53 +01:00
										 |  |  | 	and	tmp1, tmp1, #AT91_PMC_PRES | 
					
						
							| 
									
										
										
										
											2011-11-25 09:59:46 +08:00
										 |  |  | 	str	tmp1, [pmc, #AT91_PMC_MCKR] | 
					
						
							| 
									
										
										
										
											2008-09-21 21:35:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	wait_mckrdy | 
					
						
							|  |  |  | #endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* | 
					
						
							|  |  |  | 	 * Restore master clock setting | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:53 +01:00
										 |  |  | 2:	ldr	tmp1, .saved_mckr | 
					
						
							| 
									
										
										
										
											2011-11-25 09:59:46 +08:00
										 |  |  | 	str	tmp1, [pmc, #AT91_PMC_MCKR] | 
					
						
							| 
									
										
										
										
											2008-09-21 21:35:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	wait_mckrdy | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:55 +01:00
										 |  |  | 	/* | 
					
						
							|  |  |  | 	 * at91rm9200 Memory controller | 
					
						
							|  |  |  | 	 * Do nothing - self-refresh is automatically disabled. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	cmp	memctrl, #AT91_MEMCTRL_MC | 
					
						
							|  |  |  | 	beq	ram_restored | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* | 
					
						
							|  |  |  | 	 * DDRSDR Memory controller | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	cmp	memctrl, #AT91_MEMCTRL_DDRSDR | 
					
						
							|  |  |  | 	bne	sdr_en_restore | 
					
						
							| 
									
										
										
										
											2010-06-21 14:59:27 +01:00
										 |  |  | 	/* Restore LPR on AT91 with DDRAM */ | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:53 +01:00
										 |  |  | 	ldr	tmp1, .saved_sam9_lpr | 
					
						
							|  |  |  | 	str	tmp1, [sdramc, #AT91_DDRSDRC_LPR] | 
					
						
							| 
									
										
										
										
											2010-06-21 14:59:27 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* if we use the second ram controller */ | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:53 +01:00
										 |  |  | 	cmp	ramc1, #0 | 
					
						
							|  |  |  | 	ldrne	tmp2, .saved_sam9_lpr1 | 
					
						
							|  |  |  | 	strne	tmp2, [ramc1, #AT91_DDRSDRC_LPR] | 
					
						
							| 
									
										
										
										
											2010-06-21 14:59:27 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:55 +01:00
										 |  |  | 	b	ram_restored | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* | 
					
						
							|  |  |  | 	 * SDRAMC Memory controller | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | sdr_en_restore: | 
					
						
							| 
									
										
										
										
											2010-06-21 14:59:27 +01:00
										 |  |  | 	/* Restore LPR on AT91 with SDRAM */ | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:53 +01:00
										 |  |  | 	ldr	tmp1, .saved_sam9_lpr | 
					
						
							|  |  |  | 	str	tmp1, [sdramc, #AT91_SDRAMC_LPR] | 
					
						
							| 
									
										
										
										
											2008-09-21 21:35:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:55 +01:00
										 |  |  | ram_restored: | 
					
						
							| 
									
										
										
										
											2008-09-21 21:35:18 +01:00
										 |  |  | 	/* Restore registers, and return */ | 
					
						
							| 
									
										
										
										
											2012-02-22 17:50:55 +01:00
										 |  |  | 	ldmfd	sp!, {r4 - r12, pc} | 
					
						
							| 
									
										
										
										
											2008-09-21 21:35:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | .saved_mckr: | 
					
						
							|  |  |  | 	.word 0
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | .saved_pllar: | 
					
						
							|  |  |  | 	.word 0
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | .saved_pllbr: | 
					
						
							|  |  |  | 	.word 0
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | .saved_sam9_lpr: | 
					
						
							|  |  |  | 	.word 0
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-21 14:59:27 +01:00
										 |  |  | .saved_sam9_lpr1: | 
					
						
							|  |  |  | 	.word 0
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-21 21:35:18 +01:00
										 |  |  | ENTRY(at91_slow_clock_sz) | 
					
						
							|  |  |  | 	.word .-at91_slow_clock |