blob: be3e91c7dbad5388e7349164e60c9a1f56b0b060 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Heiko Schocherf1e3a8c2014-10-31 08:31:04 +01002/*
3 * (C) Copyright 2014
4 * Heiko Schocher, DENX Software Engineering, hs@denx.de.
5 *
6 * Based on:
7 * (C) Copyright 2007-2008
8 * Stelian Pop <stelian@popies.net>
9 * Lead Tech Design <www.leadtechdesign.com>
Heiko Schocherf1e3a8c2014-10-31 08:31:04 +010010 */
11
Heiko Schocherf1e3a8c2014-10-31 08:31:04 +010012#include <asm/io.h>
13#include <asm/arch/at91_common.h>
Heiko Schocherf1e3a8c2014-10-31 08:31:04 +010014#include <asm/arch/at91sam9_sdramc.h>
15#include <asm/arch/gpio.h>
16
17int 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, &reg->cr);
24
25 /* The SDRAM memory type must be set in the Memory Device Register */
26 writel(p->mdr, &reg->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, &reg->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, &reg->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, &reg->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, &reg->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, &reg->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, &reg->tr);
72
73 return 0;
74}