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