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