Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
TsiChungLiew | 99b037a | 2008-01-14 17:43:33 -0600 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2000-2003 |
| 4 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 5 | * |
Alison Wang | 8bce3ec | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 6 | * Copyright (C) 2004-2007, 2012 Freescale Semiconductor, Inc. |
TsiChungLiew | 99b037a | 2008-01-14 17:43:33 -0600 | [diff] [blame] | 7 | * TsiChung Liew (Tsi-Chung.Liew@freescale.com) |
TsiChungLiew | 99b037a | 2008-01-14 17:43:33 -0600 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <common.h> |
| 11 | #include <asm/immap.h> |
Alison Wang | 8bce3ec | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 12 | #include <asm/io.h> |
TsiChungLiew | 99b037a | 2008-01-14 17:43:33 -0600 | [diff] [blame] | 13 | |
| 14 | DECLARE_GLOBAL_DATA_PTR; |
| 15 | |
| 16 | int checkboard(void) |
| 17 | { |
| 18 | puts("Board: "); |
| 19 | puts("Freescale M52277 EVB\n"); |
| 20 | return 0; |
| 21 | }; |
| 22 | |
Simon Glass | d35f338 | 2017-04-06 12:47:05 -0600 | [diff] [blame] | 23 | int dram_init(void) |
TsiChungLiew | 99b037a | 2008-01-14 17:43:33 -0600 | [diff] [blame] | 24 | { |
TsiChung Liew | 39966e3 | 2008-10-21 15:37:02 +0000 | [diff] [blame] | 25 | u32 dramsize; |
| 26 | |
| 27 | #ifdef CONFIG_CF_SBF |
| 28 | /* |
| 29 | * Serial Boot: The dram is already initialized in start.S |
| 30 | * only require to return DRAM size |
| 31 | */ |
| 32 | dramsize = CONFIG_SYS_SDRAM_SIZE * 0x100000; |
| 33 | #else |
Alison Wang | 8bce3ec | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 34 | sdramc_t *sdram = (sdramc_t *)(MMAP_SDRAM); |
| 35 | gpio_t *gpio = (gpio_t *)(MMAP_GPIO); |
TsiChung Liew | 39966e3 | 2008-10-21 15:37:02 +0000 | [diff] [blame] | 36 | u32 i; |
TsiChungLiew | 99b037a | 2008-01-14 17:43:33 -0600 | [diff] [blame] | 37 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 38 | dramsize = CONFIG_SYS_SDRAM_SIZE * 0x100000; |
TsiChungLiew | 99b037a | 2008-01-14 17:43:33 -0600 | [diff] [blame] | 39 | |
| 40 | for (i = 0x13; i < 0x20; i++) { |
| 41 | if (dramsize == (1 << i)) |
| 42 | break; |
| 43 | } |
| 44 | i--; |
| 45 | |
Alison Wang | 8bce3ec | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 46 | out_8(&gpio->mscr_sdram, CONFIG_SYS_SDRAM_DRV_STRENGTH); |
TsiChung Liew | 39966e3 | 2008-10-21 15:37:02 +0000 | [diff] [blame] | 47 | |
Alison Wang | 8bce3ec | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 48 | out_be32(&sdram->sdcs0, CONFIG_SYS_SDRAM_BASE | i); |
TsiChungLiew | 99b037a | 2008-01-14 17:43:33 -0600 | [diff] [blame] | 49 | |
Alison Wang | 8bce3ec | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 50 | out_be32(&sdram->sdcfg1, CONFIG_SYS_SDRAM_CFG1); |
| 51 | out_be32(&sdram->sdcfg2, CONFIG_SYS_SDRAM_CFG2); |
TsiChungLiew | 99b037a | 2008-01-14 17:43:33 -0600 | [diff] [blame] | 52 | |
| 53 | /* Issue PALL */ |
Alison Wang | 8bce3ec | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 54 | out_be32(&sdram->sdcr, CONFIG_SYS_SDRAM_CTRL | 2); |
TsiChung Liew | 39966e3 | 2008-10-21 15:37:02 +0000 | [diff] [blame] | 55 | __asm__("nop"); |
TsiChungLiew | 99b037a | 2008-01-14 17:43:33 -0600 | [diff] [blame] | 56 | |
| 57 | /* Issue LEMR */ |
Alison Wang | 8bce3ec | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 58 | out_be32(&sdram->sdmr, CONFIG_SYS_SDRAM_MODE); |
TsiChung Liew | 39966e3 | 2008-10-21 15:37:02 +0000 | [diff] [blame] | 59 | __asm__("nop"); |
Alison Wang | 8bce3ec | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 60 | out_be32(&sdram->sdmr, CONFIG_SYS_SDRAM_EMOD); |
TsiChung Liew | 39966e3 | 2008-10-21 15:37:02 +0000 | [diff] [blame] | 61 | __asm__("nop"); |
TsiChungLiew | 99b037a | 2008-01-14 17:43:33 -0600 | [diff] [blame] | 62 | |
| 63 | udelay(1000); |
| 64 | |
| 65 | /* Issue PALL */ |
Alison Wang | 8bce3ec | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 66 | out_be32(&sdram->sdcr, CONFIG_SYS_SDRAM_CTRL | 2); |
TsiChung Liew | 39966e3 | 2008-10-21 15:37:02 +0000 | [diff] [blame] | 67 | __asm__("nop"); |
TsiChungLiew | 99b037a | 2008-01-14 17:43:33 -0600 | [diff] [blame] | 68 | |
| 69 | /* Perform two refresh cycles */ |
Alison Wang | 8bce3ec | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 70 | out_be32(&sdram->sdcr, CONFIG_SYS_SDRAM_CTRL | 4); |
TsiChung Liew | 39966e3 | 2008-10-21 15:37:02 +0000 | [diff] [blame] | 71 | __asm__("nop"); |
Alison Wang | 8bce3ec | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 72 | out_be32(&sdram->sdcr, CONFIG_SYS_SDRAM_CTRL | 4); |
TsiChung Liew | 39966e3 | 2008-10-21 15:37:02 +0000 | [diff] [blame] | 73 | __asm__("nop"); |
TsiChungLiew | 99b037a | 2008-01-14 17:43:33 -0600 | [diff] [blame] | 74 | |
Alison Wang | 8bce3ec | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 75 | out_be32(&sdram->sdcr, |
| 76 | (CONFIG_SYS_SDRAM_CTRL & ~0x80000000) | 0x10000c00); |
TsiChungLiew | 99b037a | 2008-01-14 17:43:33 -0600 | [diff] [blame] | 77 | |
| 78 | udelay(100); |
TsiChung Liew | 39966e3 | 2008-10-21 15:37:02 +0000 | [diff] [blame] | 79 | #endif |
Simon Glass | 39f90ba | 2017-03-31 08:40:25 -0600 | [diff] [blame] | 80 | gd->ram_size = dramsize; |
| 81 | |
| 82 | return 0; |
TsiChungLiew | 99b037a | 2008-01-14 17:43:33 -0600 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | int testdram(void) |
| 86 | { |
| 87 | /* TODO: XXX XXX XXX */ |
| 88 | printf("DRAM test not implemented!\n"); |
| 89 | |
| 90 | return (0); |
| 91 | } |