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