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