Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Sergei Poselenov | f2bf96c | 2008-04-30 11:42:50 +0200 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2008 |
| 4 | * Sergei Poselenov, Emcraft Systems, sposelenov@emcraft.com. |
Sergei Poselenov | f2bf96c | 2008-04-30 11:42:50 +0200 | [diff] [blame] | 5 | */ |
| 6 | |
Tom Rini | dec7ea0 | 2024-05-20 13:35:03 -0600 | [diff] [blame] | 7 | #include <config.h> |
Simon Glass | 8e16b1e | 2019-12-28 10:45:05 -0700 | [diff] [blame] | 8 | #include <init.h> |
Sergei Poselenov | f2bf96c | 2008-04-30 11:42:50 +0200 | [diff] [blame] | 9 | #include <asm/processor.h> |
| 10 | #include <asm/immap_85xx.h> |
York Sun | f062659 | 2013-09-30 09:22:09 -0700 | [diff] [blame] | 11 | #include <fsl_ddr_sdram.h> |
Sergei Poselenov | f2bf96c | 2008-04-30 11:42:50 +0200 | [diff] [blame] | 12 | #include <asm/processor.h> |
| 13 | #include <asm/mmu.h> |
| 14 | #include <spd_sdram.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 15 | #include <linux/delay.h> |
Sergei Poselenov | f2bf96c | 2008-04-30 11:42:50 +0200 | [diff] [blame] | 16 | |
Sergei Poselenov | f2bf96c | 2008-04-30 11:42:50 +0200 | [diff] [blame] | 17 | #if !defined(CONFIG_SPD_EEPROM) |
| 18 | /* |
| 19 | * Autodetect onboard DDR SDRAM on 85xx platforms |
| 20 | * |
| 21 | * NOTE: Some of the hardcoded values are hardware dependant, |
| 22 | * so this should be extended for other future boards |
| 23 | * using this routine! |
| 24 | */ |
Becky Bruce | 5e35d8a | 2010-12-17 17:17:56 -0600 | [diff] [blame] | 25 | phys_size_t fixed_sdram(void) |
Sergei Poselenov | f2bf96c | 2008-04-30 11:42:50 +0200 | [diff] [blame] | 26 | { |
York Sun | a21803d | 2013-11-18 10:29:32 -0800 | [diff] [blame] | 27 | struct ccsr_ddr __iomem *ddr = |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 28 | (struct ccsr_ddr __iomem *)(CFG_SYS_FSL_DDR_ADDR); |
Sergei Poselenov | f2bf96c | 2008-04-30 11:42:50 +0200 | [diff] [blame] | 29 | |
| 30 | /* |
| 31 | * Disable memory controller. |
| 32 | */ |
| 33 | ddr->cs0_config = 0; |
| 34 | ddr->sdram_cfg = 0; |
| 35 | |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 36 | ddr->cs0_bnds = CFG_SYS_DDR_CS0_BNDS; |
| 37 | ddr->cs0_config = CFG_SYS_DDR_CS0_CONFIG; |
| 38 | ddr->timing_cfg_0 = CFG_SYS_DDR_TIMING_0; |
| 39 | ddr->timing_cfg_1 = CFG_SYS_DDR_TIMING_1; |
| 40 | ddr->timing_cfg_2 = CFG_SYS_DDR_TIMING_2; |
| 41 | ddr->sdram_mode = CFG_SYS_DDR_MODE; |
| 42 | ddr->sdram_interval = CFG_SYS_DDR_INTERVAL; |
| 43 | ddr->sdram_cfg_2 = CFG_SYS_DDR_CONFIG_2; |
| 44 | ddr->sdram_clk_cntl = CFG_SYS_DDR_CLK_CONTROL; |
Sergei Poselenov | f2bf96c | 2008-04-30 11:42:50 +0200 | [diff] [blame] | 45 | |
| 46 | asm ("sync;isync;msync"); |
| 47 | udelay(1000); |
| 48 | |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 49 | ddr->sdram_cfg = CFG_SYS_DDR_CONFIG; |
Sergei Poselenov | f2bf96c | 2008-04-30 11:42:50 +0200 | [diff] [blame] | 50 | asm ("sync; isync; msync"); |
| 51 | udelay(1000); |
| 52 | |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 53 | if (get_ram_size(0, CFG_SYS_SDRAM_SIZE<<20) == CFG_SYS_SDRAM_SIZE<<20) { |
Sergei Poselenov | f2bf96c | 2008-04-30 11:42:50 +0200 | [diff] [blame] | 54 | /* |
| 55 | * OK, size detected -> all done |
| 56 | */ |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 57 | return CFG_SYS_SDRAM_SIZE<<20; |
Sergei Poselenov | f2bf96c | 2008-04-30 11:42:50 +0200 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | return 0; /* nothing found ! */ |
| 61 | } |
| 62 | #endif |
| 63 | |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 64 | #if defined(CFG_SYS_DRAM_TEST) |
Simon Glass | 0ffd9db | 2019-12-28 10:45:06 -0700 | [diff] [blame] | 65 | int testdram(void) |
Sergei Poselenov | f2bf96c | 2008-04-30 11:42:50 +0200 | [diff] [blame] | 66 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 67 | uint *pstart = (uint *) CONFIG_SYS_MEMTEST_START; |
| 68 | uint *pend = (uint *) CONFIG_SYS_MEMTEST_END; |
Sergei Poselenov | f2bf96c | 2008-04-30 11:42:50 +0200 | [diff] [blame] | 69 | uint *p; |
| 70 | |
| 71 | printf ("SDRAM test phase 1:\n"); |
| 72 | for (p = pstart; p < pend; p++) |
| 73 | *p = 0xaaaaaaaa; |
| 74 | |
| 75 | for (p = pstart; p < pend; p++) { |
| 76 | if (*p != 0xaaaaaaaa) { |
| 77 | printf ("SDRAM test fails at: %08x\n", (uint) p); |
| 78 | return 1; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | printf ("SDRAM test phase 2:\n"); |
| 83 | for (p = pstart; p < pend; p++) |
| 84 | *p = 0x55555555; |
| 85 | |
| 86 | for (p = pstart; p < pend; p++) { |
| 87 | if (*p != 0x55555555) { |
| 88 | printf ("SDRAM test fails at: %08x\n", (uint) p); |
| 89 | return 1; |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | printf ("SDRAM test passed.\n"); |
| 94 | return 0; |
| 95 | } |
| 96 | #endif |