aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-imx/imx6sl_wfi.S
blob: 4bd0a86f11b4fee3a2c9371af533f63bf8ec35c7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
/*
 * Copyright (C) 2012-2014 Freescale Semiconductor, Inc. All Rights Reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include <linux/linkage.h>
#include "hardware.h"

.extern iram_tlb_phys_addr
.globl mx6sl_lpm_wfi_start
.globl mx6sl_lpm_wfi_end

	.macro	sl_ddr_io_save

	ldr	r4, [r1, #0x30c] /* DRAM_DQM0 */
	ldr	r5, [r1, #0x310] /* DRAM_DQM1 */
	ldr	r6, [r1, #0x314] /* DRAM_DQM2 */
	ldr	r7, [r1, #0x318] /* DRAM_DQM3 */
	stmfd	r9!, {r4-r7}

	ldr	r4, [r1, #0x5c4] /* GPR_B0DS */
	ldr	r5, [r1, #0x5cc] /* GPR_B1DS */
	ldr	r6, [r1, #0x5d4] /* GPR_B2DS */
	ldr	r7, [r1, #0x5d8] /* GPR_B3DS */
	stmfd	r9!, {r4-r7}

	ldr	r4, [r1, #0x300] /* DRAM_CAS */
	ldr	r5, [r1, #0x31c] /* DRAM_RAS */
	ldr	r6, [r1, #0x338] /* DRAM_SDCLK_0 */
	ldr r7, [r1, #0x5ac] /* GPR_ADDS*/
	stmfd	r9!, {r4-r7}

	ldr	r4, [r1, #0x5b0] /* DDRMODE_CTL */
	ldr	r5, [r1, #0x5c0] /* DDRMODE */
	ldr	r6, [r1, #0x33c] /* DRAM_SODT0*/
	ldr	r7, [r1, #0x340] /* DRAM_SODT1*/
	stmfd	r9!, {r4-r7}

	ldr	r4, [r1, #0x330] /* DRAM_SDCKE0 */
	ldr	r5, [r1, #0x334] /* DRAM_SDCKE1 */
	ldr	r6, [r1, #0x320] /* DRAM_RESET */
	stmfd	r9!, {r4-r6}

	.endm

	.macro	sl_ddr_io_restore

	/*
	 * r9 points to IRAM stack.
	 * r1 points to IOMUX base address.
	 * r8 points to MMDC  base address.
	 */
	ldmea	r9!, {r4-r7}
	str	r4, [r1, #0x30c] /* DRAM_DQM0 */
	str	r5, [r1, #0x310] /* DRAM_DQM1 */
	str	r6, [r1, #0x314] /* DRAM_DQM2 */
	str	r7, [r1, #0x318] /* DRAM_DQM3 */

	ldmea	r9!, {r4-r7}
	str	r4, [r1, #0x5c4] /* GPR_B0DS */
	str	r5, [r1, #0x5cc] /* GPR_B1DS */
	str r6, [r1, #0x5d4] /* GPR_B2DS */
	str r7, [r1, #0x5d8] /* GPR_B3DS */

	ldmea	r9!, {r4-r7}
	str	r4, [r1, #0x300] /* DRAM_CAS */
	str	r5, [r1, #0x31c] /* DRAM_RAS */
	str	r6, [r1, #0x338] /* DRAM_SDCLK_0 */
	str r7, [r1, #0x5ac] /* GPR_ADDS*/

	ldmea	r9!, {r4-r7}
	str	r4, [r1, #0x5b0] /* DDRMODE_CTL */
	str	r5, [r1, #0x5c0] /* DDRMODE */
	str	r6, [r1, #0x33c] /* DRAM_SODT0*/
	str	r7, [r1, #0x340] /* DRAM_SODT1*/

	ldmea	r9!, {r4-r6}
	str	r4, [r1, #0x330] /* DRAM_SDCKE0 */
	str	r5, [r1, #0x334] /* DRAM_SDCKE1 */
	str	r6, [r1, #0x320] /* DRAM_RESET */

	/*
	 * Need to reset the FIFO to avoid MMDC lockup
	 * caused because of floating/changing the
	 * configuration of many DDR IO pads.
	 */
	ldr	r7, =0x83c
	ldr	r6, [r8, r7]
	orr	r6, r6, #0x80000000
	str	r6, [r8, r7]
fifo_reset1_wait:
	ldr	r6, [r8, r7]
	and	r6, r6, #0x80000000
	cmp	r6, #0
	bne	fifo_reset1_wait

	/* reset FIFO a second time */
	ldr	r6, [r8, r7]
	orr	r6, r6, #0x80000000
	str	r6, [r8, r7]
fifo_reset2_wait:
	ldr	r6, [r8, r7]
	and	r6, r6, #0x80000000
	cmp	r6, #0
	bne	fifo_reset2_wait

	.endm

	.macro	sl_ddr_io_set_lpm

	mov	r4, #0
	str	r4, [r1, #0x30c] /* DRAM_DQM0 */
	str	r4, [r1, #0x310] /* DRAM_DQM1 */
	str	r4, [r1, #0x314] /* DRAM_DQM2 */
	str	r4, [r1, #0x318] /* DRAM_DQM3 */

	str	r4, [r1, #0x5c4] /* GPR_B0DS */
	str	r4, [r1, #0x5cc] /* GPR_B1DS */
	str r4, [r1, #0x5d4] /* GPR_B2DS */
	str r4, [r1, #0x5d8] /* GPR_B3DS */

	str	r4, [r1, #0x300] /* DRAM_CAS */
	str	r4, [r1, #0x31c] /* DRAM_RAS */
	str	r4, [r1, #0x338] /* DRAM_SDCLK_0 */
	str r4, [r1, #0x5ac] /* GPR_ADDS*/

	str	r4, [r1, #0x5b0] /* DDRMODE_CTL */
	str	r4, [r1, #0x5c0] /* DDRMODE */
	str	r4, [r1, #0x33c] /* DRAM_SODT0*/
	str	r4, [r1, #0x340] /* DRAM_SODT1*/

	mov	r4, #0x80000
	str	r4, [r1, #0x320] /* DRAM_RESET */
	mov	r4, #0x1000
	str	r4, [r1, #0x330] /* DRAM_SDCKE0 */
	str	r4, [r1, #0x334] /* DRAM_SDCKE1 */

	.endm

/*
 *  imx6sl_low_power_wfi
 *
 *  Idle the processor (eg, wait for interrupt).
 *  Make sure DDR is in self-refresh.
 *  IRQs are already disabled.
 * r0: WFI IRAMcode base address.
 * r1: 1 if vbus_ldo (ldo2p5) cannot be disabled
 * r2: 1 if in audio_bus_freq_mode
 */
	.align 3
ENTRY(imx6sl_low_power_wfi)

mx6sl_lpm_wfi_start:

	push {r4-r12}

	/* Can LDO2p5 be disabled */
	mov	r12, r1
	/* Store audio_bus_freq_mode */
	mov	r11, r2

	/* Get the IRAM data storage address. */
	mov	r10, r0
	mov	r9, r0		/* get wfi_iram_base */
	adrl	r4, mx6sl_lpm_wfi_end
	add	r9, r4, #MX6SL_WFI_IRAM_DATA_SIZE

	/*
	 * To ensure no page table walks occur in DDR, we
	 * have a another page table stored in IRAM that only
	 * contains entries pointing to IRAM, AIPS1 and AIPS2.
	 * We need to set the TTBR1 to the new IRAM TLB.
	 * Do the following steps:
	 * 1. Flush the Branch Target Address Cache (BTAC)
	 * 2. Set TTBR1 to point to IRAM page table.
	 * 3. Disable page table walks in TTBR0 (PD0 = 1)
	 * 4. Set TTBR0.N=1, implying 0-2G is translated by TTBR0
	 *     and 2-4G is translated by TTBR1.
	 */

	ldr	r6, =iram_tlb_phys_addr
	ldr	r7, [r6]

	/* Disable Branch Prediction, Z bit in SCTLR. */
	mrc	p15, 0, r6, c1, c0, 0
	bic	r6, r6, #0x800
	mcr	p15, 0, r6, c1, c0, 0

	/* Flush the BTAC. */
	ldr	r6, =0x0
	mcr	p15, 0, r6, c7, c1, 6

	dsb
	isb

	/* Store the IRAM table in TTBR1 */
	mcr	p15, 0, r7, c2, c0, 1

	/* Read TTBCR and set PD0=1, N = 1 */
	mrc	p15, 0, r6, c2, c0, 2
	orr	r6, r6, #0x11
	mcr	p15, 0, r6, c2, c0, 2

	dsb
	isb

	/* flush the TLB */
	ldr	r6, =0x0
	mcr	p15, 0, r6, c8, c3, 0

	/* Disable L1 data cache. */
	mrc	p15, 0, r6, c1, c0, 0
	bic	r6, r6, #0x4
	mcr	p15, 0, r6, c1, c0, 0

	dsb
	isb

#ifdef CONFIG_CACHE_L2X0
	/*
	 * Need to make sure the buffers in L2 are drained.
	 * Performing a sync operation does this.
	 */
	ldr	r7, =IMX_IO_P2V(MX6Q_L2_BASE_ADDR)

	/* Wait for background operations to complete. */
wait_for_l2_to_idle:
	ldr	r6, [r7, #0x730]
	cmp	r6, #0x0
	bne	wait_for_l2_to_idle

	mov	r6, #0x0
	str	r6, [r7, #0x730]

	/* Disable L2. */
	str	r6, [r7, #0x100]

	/*
	 * The second dsb might be needed to keep cache sync (device write)
	 * ordering with the memory accesses before it.
	 */
	dsb
	isb
#endif


	ldr	r1, =IMX_IO_P2V(MX6Q_IOMUXC_BASE_ADDR)
	ldr	r3, =IMX_IO_P2V(MX6Q_ANATOP_BASE_ADDR)
	ldr	r2, =IMX_IO_P2V(MX6Q_CCM_BASE_ADDR)
	ldr	r8, =IMX_IO_P2V(MX6Q_MMDC_P0_BASE_ADDR)

	/* Store the original ARM PODF. */
	ldr	r0, [r2, #0x10]

	/* Save the DDR IO state. */
	sl_ddr_io_save

	/* Disable Automatic power savings. */
	ldr	r6, [r8, #0x404]
	orr	r6, r6, #0x01
	str	r6, [r8, #0x404]

	/* Make the DDR explicitly enter self-refresh. */
	ldr	r6, [r8, #0x404]
	orr	r6, r6, #0x200000
	str	r6, [r8, #0x404]

poll_dvfs_set_1:
	ldr	r6, [r8, #0x404]
	and	r6, r6, #0x2000000
	cmp	r6, #0x2000000
	bne	poll_dvfs_set_1

	/* set SBS step-by-step mode */
	ldr	r6, [r8, #0x410]
	orr	r6, r6, #0x100
	str	r6, [r8, #0x410]

	cmp	r11, #1
	beq	audio_mode
	/*
	 * Now set DDR rate to 1MHz.
	 * DDR is from bypassed PLL2 on periph2_clk2 path.
	 * Set the periph2_clk2_podf to divide by 8.
	 */
	ldr	r6, [r2, #0x14]
	orr	r6, r6, #0x07
	str	r6, [r2, #0x14]

	/* Now set MMDC PODF to divide by 3. */
	ldr	r6, [r2, #0x14]
	bic	r6, r6, #0x38
	orr	r6, r6, #0x10
	str	r6, [r2, #0x14]
	b	mmdc_podf

audio_mode:
	/* MMDC is from PLL2_200M.
	 * Set the mmdc_podf to div by 8.
	 */
	ldr	r6, [r2, #0x14]
	orr	r6, r6, #0x38
	str	r6, [r2, #0x14]

	/* Loop till podf is accepted. */
mmdc_podf:
	ldr	r6, [r2, #0x48]
	cmp	r6, #0x0
	bne	mmdc_podf

	/* Set the DDR IO in LPM state. */
	sl_ddr_io_set_lpm

	cmp	r11, #1
	beq	do_audio_arm_clk

	/*
	 * Check if none of the PLLs are
	 * locked, except PLL1 which will get
	 * bypassed below.
	 * We should not be here if PLL2 is not
	 * bypassed.
	 */
	ldr	r7, =1
	/* USB1 PLL3 */
	ldr	r6, [r3, #0x10]
	and	r6, r6, #0x80000000
	cmp	r6, #0x80000000
	beq	no_analog_saving

	/* USB2 PLL7 */
	ldr	r6, [r3, #0x20]
	and	r6, r6, #0x80000000
	cmp	r6, #0x80000000
	beq	no_analog_saving

	/* Audio PLL4 */
	ldr	r6, [r3, #0x70]
	and	r6, r6, #0x80000000
	cmp	r6, #0x80000000
	beq	no_analog_saving

	/* Video PLL5 */
	ldr	r6, [r3, #0xA0]
	and	r6, r6, #0x80000000
	cmp	r6, #0x80000000
	beq	no_analog_saving

	/* ENET PLL8 */
	ldr	r6, [r3, #0xE0]
	and	r6, r6, #0x80000000
	cmp	r6, #0x80000000
	beq	no_analog_saving

	b	cont

no_analog_saving:
	ldr	r7, =0

cont:
	/* Set the AHB to 3MHz. AXI to 3MHz. */
	ldr	r9, [r2, #0x14]
	mov	r6, r9
	orr	r6, r6, #0x1c00
	orr	r6, r6, #0x70000
	str	r6, [r2, #0x14]

	/* Loop till podf is accepted. */
ahb_podf:
	ldr	r6, [r2, #0x48]
	cmp	r6, #0x0
	bne	podf_loop

	/*
	 * Now set ARM to 24MHz.
	 * Move ARM to be sourced from STEP_CLK
	 * after setting STEP_CLK to 24MHz.
	 */
	ldr	r6, [r2, #0xc]
	bic	r6, r6, #0x100
	str	r6, [r2, #0x0c]
	/* Now PLL1_SW_CLK to step_clk. */
	ldr	r6, [r2, #0x0c]
	orr	r6, r6, #0x4
	str	r6, [r2, #0x0c]

	/* Bypass PLL1 and power it down. */
	ldr	r6, =(1 << 16)
	orr	r6, r6, #0x1000
	str	r6, [r3, #0x04]

	/*
	 * Set the ARM PODF to divide by 8.
	 * IPG is at 1.5MHz here, we need ARM to
	 * run at the 12:5 ratio (WAIT mode issue).
	 */
	ldr	r6, =0x7
	str	r6, [r2, #0x10]

	/* Loop till podf is accepted. */
podf_loop:
	ldr	r6, [r2, #0x48]
	cmp	r6, #0x0
	bne   podf_loop

	/*
	 * Check if we can save some
	 * power in the Analog section.
	 */
	cmp	r7, #0x1
	bne	do_wfi

	/* Disable 1p1 brown out. */
	ldr	r6, [r3, #0x110]
	bic	r6, r6, #0x2
	str	r6, [r3, #0x110]

	/*
	 * Set the OSC bias current to -37.5%
	 * to drop the power on VDDHIGH.
	 */
	ldr	r6, [r3, #0x150]
	orr	r6, r6, #0xC000
	str	r6, [r3, #0x150]

	cmp	r12, #0x1
	beq	leave_2p5_on

	/* Enable the weak 2P5 */
	ldr	r6, [r3, #0x130]
	orr	r6, r6, #0x40000
	str	r6, [r3, #0x130]

	/* Disable main 2p5. */
	ldr	r6, [r3, #0x130]
	bic	r6, r6, #0x1
	str	r6, [r3, #0x130]

	/* Enable low power bandgap */
	ldr	r6, [r3, #0x260]
	orr	r6, r6, #0x20
	str	r6, [r3, #0x260]

	/*
	 * Turn off the bias current
	 * from the regular bandgap.
	 */
	ldr	r6, [r3, #0x260]
	orr	r6, r6, #0x80
	str	r6, [r3, #0x260]

	/*
	 * Clear the REFTOP_SELFBIASOFF,
	 * self-bias circuit of the band gap.
	 * Per RM, should be cleared when
	 * band gap is powered down.
	 */
	ldr	r6, [r3, #0x150]
	bic	r6, r6, #0x8
	str	r6, [r3, #0x150]

	/* Power down the regular bandgap. */
	ldr	r6, [r3, #0x150]
	orr	r6, r6, #0x1
	str	r6, [r3, #0x150]

leave_2p5_on:
	b	do_wfi

do_audio_arm_clk:
	/*
	 * ARM is from PLL2_PFD2_400M here.
	 * Switch ARM to bypassed PLL1.
	 */
	ldr	r6, [r2, #0xC]
	bic	r6, r6, #0x4
	str	r6, [r2, #0xC]

	/*
	 * Set the ARM_PODF to divide by 2
	 * as IPG is at 4MHz, we cannot run
	 * ARM_CLK above 9.6MHz when
	 * system enters WAIT mode.
	 */
	ldr	r6, =0x2
	str	r6, [r2, #0x10]

	/* Loop till podf is accepted. */
podf_loop_audio:
	ldr	r6, [r2, #0x48]
	cmp	r6, #0x0
	bne	podf_loop_audio

do_wfi:
	/* Now do WFI. */
	wfi

	/* Set original ARM PODF back. */
	str	r0, [r2, #0x10]

	/* Loop till podf is accepted. */
podf_loop1:
	ldr	r6, [r2, #0x48]
	cmp	r6, #0x0
	bne	podf_loop1

	cmp	r11, #1
	beq	audio_arm_clk_restore

	/*
	 * Check if powered down
	 * analog components.
	 */
	cmp	r7, #0x1
	bne	skip_analog_restore

	cmp	r12, #1
	beq	ldo2p5_not_disabled

	/* Power up the regular bandgap. */
	ldr	r6, [r3, #0x150]
	bic	r6, r6, #0x1
	str	r6, [r3, #0x150]

	/*
	 * Turn on the bias current
	 * from the regular bandgap.
	 */
	ldr	r6, [r3, #0x260]
	bic	r6, r6, #0x80
	str	r6, [r3, #0x260]

	/* Disable the low power bandgap */
	ldr	r6, [r3, #0x260]
	bic	r6, r6, #0x20
	str	r6, [r3, #0x260]

	/* Enable main 2p5. */
	ldr	r6, [r3, #0x130]
	orr	r6, r6, #0x1
	str	r6, [r3, #0x130]

	/* Ensure the 2P5 is up. */
loop_2p5:
	ldr	r6, [r3, #0x130]
	and	r6, r6, #0x20000
	cmp	r6, #0x20000
	bne	loop_2p5

	/* Disable the  weak 2P5 */
	ldr	r6, [r3, #0x130]
	bic	r6, r6, #0x40000
	str	r6, [r3, #0x130]

ldo2p5_not_disabled:
	/*
	 * Set the OSC bias current to max
	 * value for normal operation.
	 */
	ldr	r6, [r3, #0x150]
	bic	r6, r6, #0xC000
	str	r6, [r3, #0x150]


	/* Enable 1p1 brown out. */
	ldr	r6, [r3, #0x110]
	orr	r6, r6, #0x2
	str	r6, [r3, #0x110]

skip_analog_restore:

	/* Power up PLL1 and un-bypass it. */
	ldr	r6, =(1 << 12)
	str	r6, [r3, #0x08]

	/* Wait for PLL1 to relock. */
wait_for_pll_lock:
	ldr	r6, [r3, #0x0]
	and	r6, r6, #0x80000000
	cmp	r6, #0x80000000
	bne	wait_for_pll_lock

	ldr	r6, =(1 << 16)
	str	r6, [r3, #0x08]

	/* Set PLL1_sw_clk back to PLL1. */
	ldr	r6, [r2, #0x0c]
	bic	r6, r6, #0x4
	str	r6, [r2, #0xc]

	/* Restore AHB/AXI back. */
	str	r9, [r2, #0x14]

	/* Loop till podf is accepted. */
ahb_podf1:
	ldr	r6, [r2, #0x48]
	cmp	r6, #0x0
	bne	podf_loop1

	b	wfi_restore

audio_arm_clk_restore:
	/* Move ARM back to PLL2_PFD2_400M */
	ldr	r6, [r2, #0xC]
	orr	r6, r6, #0x4
	str	r6, [r2, #0xC]

wfi_restore:
	/* get wfi_iram_base */
	adrl	r9, mx6sl_lpm_wfi_end
	add	r9, r9, #MX6SL_WFI_IRAM_DATA_SIZE

	/* Restore the DDR IO before exiting self-refresh. */
	sl_ddr_io_restore

	/*
	 * Set MMDC back to 24MHz.
	 * Set periph2_clk2_podf to divide by 1
	 * Now set MMDC PODF to divide by 1.
	 */
	ldr	r6, [r2, #0x14]
	bic	r6, r6, #0x3f
	str	r6, [r2, #0x14]

mmdc_podf1:
	ldr	r6, [r2, #0x48]
	cmp	r6, #0x0
	bne	mmdc_podf1

	/* clear DVFS - exit from self refresh mode */
	ldr	r6, [r8, #0x404]
	bic	r6, r6, #0x200000
	str	r6, [r8, #0x404]

poll_dvfs_clear_1:
	ldr	r6, [r8, #0x404]
	and	r6, r6, #0x2000000
	cmp	r6, #0x2000000
	beq	poll_dvfs_clear_1

	/* Enable Automatic power savings. */
	ldr	r6, [r8, #0x404]
	bic	r6, r6, #0x01
	str	r6, [r8, #0x404]

	/* clear SBS - unblock DDR accesses */
	ldr	r6, [r8, #0x410]
	bic	r6, r6, #0x100
	str	r6, [r8, #0x410]

#ifdef CONFIG_CACHE_L2X0
	/* Enable L2. */
	ldr	r7, =IMX_IO_P2V(MX6Q_L2_BASE_ADDR)
	ldr	r6, =0x1
	str	r6, [r7, #0x100]
#endif

	/* Enable L1 data cache. */
	mrc	p15, 0, r6, c1, c0, 0
	orr	r6, r6, #0x4
	mcr	p15, 0, r6, c1, c0, 0

	/* Restore the TTBCR */

	dsb
	isb

	/* Read TTBCR and set PD0=0, N = 0 */
	mrc	p15, 0, r6, c2, c0, 2
	bic	r6, r6, #0x11
	mcr	p15, 0, r6, c2, c0, 2

	dsb
	isb

	/* flush the TLB */
	ldr	r6, =0x0
	mcr	p15, 0, r6, c8, c3, 0

	dsb
	isb

	/* Enable Branch Prediction, Z bit in SCTLR. */
	mrc	p15, 0, r6, c1, c0, 0
	orr	r6, r6, #0x800
	mcr	p15, 0, r6, c1, c0, 0

	/* Flush the Branch Target Address Cache (BTAC) */
	ldr	r6, =0x0
	mcr	p15, 0, r6, c7, c1, 6

	/*
	 * Add these nops so that the
	 * prefetcher will not try to get
	 * any instructions from DDR.
	 * The prefetch depth is about 23
	 * on A9, so adding 25 nops.
	 */
	nop
	nop
	nop
	nop
	nop

	nop
	nop
	nop
	nop
	nop

	nop
	nop
	nop
	nop
	nop

	nop
	nop
	nop
	nop
	nop

	nop
	nop
	nop
	nop
	nop

	pop {r4-r12}

	/* Restore registers */
	mov	pc, lr
	/*
	 * Add ltorg here to ensure that all
	 * literals are stored here and are
	 * within the text space.
	 */
	.ltorg
mx6sl_lpm_wfi_end: