3 * Heiko Schocher, DENX Software Engineering, hs@denx.de.
6 * (C) Copyright 2007-2008
7 * Stelian Pop <stelian@popies.net>
8 * Lead Tech Design <www.leadtechdesign.com>
10 * SPDX-License-Identifier: GPL-2.0+
15 #include <asm/arch/at91_common.h>
16 #include <asm/arch/at91sam9_sdramc.h>
17 #include <asm/arch/gpio.h>
19 int sdramc_initialize(unsigned int sdram_address, const struct sdramc_reg *p)
21 struct sdramc_reg *reg = (struct sdramc_reg *)ATMEL_BASE_SDRAMC;
24 /* SDRAM feature must be in the configuration register */
25 writel(p->cr, ®->cr);
27 /* The SDRAM memory type must be set in the Memory Device Register */
28 writel(p->mdr, ®->mdr);
31 * The minimum pause of 200 us is provided to precede any single
34 for (i = 0; i < 1000; i++)
37 /* A NOP command is issued to the SDRAM devices */
38 writel(AT91_SDRAMC_MODE_NOP, ®->mr);
39 writel(0x00000000, sdram_address);
41 /* An All Banks Precharge command is issued to the SDRAM devices */
42 writel(AT91_SDRAMC_MODE_PRECHARGE, ®->mr);
43 writel(0x00000000, sdram_address);
45 for (i = 0; i < 10000; i++)
48 /* Eight auto-refresh cycles are provided */
49 for (i = 0; i < 8; i++) {
50 writel(AT91_SDRAMC_MODE_REFRESH, ®->mr);
51 writel(0x00000001 + i, sdram_address + 4 + 4 * i);
55 * A Mode Register set (MRS) cyscle is issued to program the
56 * SDRAM parameters(TCSR, PASR, DS)
58 writel(AT91_SDRAMC_MODE_LMR, ®->mr);
59 writel(0xcafedede, sdram_address + 0x24);
62 * The application must go into Normal Mode, setting Mode
63 * to 0 in the Mode Register and perform a write access at
64 * any location in the SDRAM.
66 writel(AT91_SDRAMC_MODE_NORMAL, ®->mr);
67 writel(0x00000000, sdram_address); /* Perform Normal mode */
70 * Write the refresh rate into the count field in the SDRAMC
71 * Refresh Timer Rgister.
73 writel(p->tr, ®->tr);