]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
5abc00d0 HS |
2 | /* |
3 | * (C) Copyright 2014 | |
4 | * Heiko Schocher, DENX Software Engineering, [email protected]. | |
5 | * | |
6 | * Based on: | |
7 | * (C) Copyright 2007-2008 | |
8 | * Stelian Pop <[email protected]> | |
9 | * Lead Tech Design <www.leadtechdesign.com> | |
5abc00d0 HS |
10 | */ |
11 | ||
5abc00d0 HS |
12 | #include <asm/io.h> |
13 | #include <asm/arch/at91_common.h> | |
5abc00d0 HS |
14 | #include <asm/arch/at91sam9_sdramc.h> |
15 | #include <asm/arch/gpio.h> | |
16 | ||
17 | int sdramc_initialize(unsigned int sdram_address, const struct sdramc_reg *p) | |
18 | { | |
19 | struct sdramc_reg *reg = (struct sdramc_reg *)ATMEL_BASE_SDRAMC; | |
20 | unsigned int i; | |
21 | ||
22 | /* SDRAM feature must be in the configuration register */ | |
23 | writel(p->cr, ®->cr); | |
24 | ||
25 | /* The SDRAM memory type must be set in the Memory Device Register */ | |
26 | writel(p->mdr, ®->mdr); | |
27 | ||
28 | /* | |
29 | * The minimum pause of 200 us is provided to precede any single | |
30 | * toggle | |
31 | */ | |
32 | for (i = 0; i < 1000; i++) | |
33 | ; | |
34 | ||
35 | /* A NOP command is issued to the SDRAM devices */ | |
36 | writel(AT91_SDRAMC_MODE_NOP, ®->mr); | |
37 | writel(0x00000000, sdram_address); | |
38 | ||
39 | /* An All Banks Precharge command is issued to the SDRAM devices */ | |
40 | writel(AT91_SDRAMC_MODE_PRECHARGE, ®->mr); | |
41 | writel(0x00000000, sdram_address); | |
42 | ||
43 | for (i = 0; i < 10000; i++) | |
44 | ; | |
45 | ||
46 | /* Eight auto-refresh cycles are provided */ | |
47 | for (i = 0; i < 8; i++) { | |
48 | writel(AT91_SDRAMC_MODE_REFRESH, ®->mr); | |
49 | writel(0x00000001 + i, sdram_address + 4 + 4 * i); | |
50 | } | |
51 | ||
52 | /* | |
53 | * A Mode Register set (MRS) cyscle is issued to program the | |
54 | * SDRAM parameters(TCSR, PASR, DS) | |
55 | */ | |
56 | writel(AT91_SDRAMC_MODE_LMR, ®->mr); | |
57 | writel(0xcafedede, sdram_address + 0x24); | |
58 | ||
59 | /* | |
60 | * The application must go into Normal Mode, setting Mode | |
61 | * to 0 in the Mode Register and perform a write access at | |
62 | * any location in the SDRAM. | |
63 | */ | |
64 | writel(AT91_SDRAMC_MODE_NORMAL, ®->mr); | |
65 | writel(0x00000000, sdram_address); /* Perform Normal mode */ | |
66 | ||
67 | /* | |
68 | * Write the refresh rate into the count field in the SDRAMC | |
69 | * Refresh Timer Rgister. | |
70 | */ | |
71 | writel(p->tr, ®->tr); | |
72 | ||
73 | return 0; | |
74 | } |