Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Heiko Schocher | f1e3a8c | 2014-10-31 08:31:04 +0100 | [diff] [blame] | 2 | /* |
| 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 Schocher | f1e3a8c | 2014-10-31 08:31:04 +0100 | [diff] [blame] | 10 | */ |
| 11 | |
Heiko Schocher | f1e3a8c | 2014-10-31 08:31:04 +0100 | [diff] [blame] | 12 | #include <asm/io.h> |
| 13 | #include <asm/arch/at91_common.h> |
Heiko Schocher | f1e3a8c | 2014-10-31 08:31:04 +0100 | [diff] [blame] | 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 | } |