Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Dirk Eibach | f74a027 | 2014-11-13 19:21:18 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2007 Freescale Semiconductor, Inc. |
| 4 | * Copyright (C) 2010 Ilya Yanok, Emcraft Systems, yanok@emcraft.com |
| 5 | * |
| 6 | * Authors: Nick.Spence@freescale.com |
| 7 | * Wilson.Lo@freescale.com |
| 8 | * scottwood@freescale.com |
| 9 | * |
| 10 | * This files is mostly identical to the original from |
| 11 | * board\freescale\mpc8315erdb\sdram.c |
Dirk Eibach | f74a027 | 2014-11-13 19:21:18 +0100 | [diff] [blame] | 12 | */ |
| 13 | |
Mario Six | 0486138 | 2019-03-29 10:18:09 +0100 | [diff] [blame] | 14 | #ifndef CONFIG_MPC83XX_SDRAM |
| 15 | |
Dirk Eibach | f74a027 | 2014-11-13 19:21:18 +0100 | [diff] [blame] | 16 | #include <common.h> |
Simon Glass | 8e16b1e | 2019-12-28 10:45:05 -0700 | [diff] [blame] | 17 | #include <init.h> |
Dirk Eibach | f74a027 | 2014-11-13 19:21:18 +0100 | [diff] [blame] | 18 | #include <mpc83xx.h> |
| 19 | #include <spd_sdram.h> |
| 20 | |
| 21 | #include <asm/bitops.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 22 | #include <asm/global_data.h> |
Dirk Eibach | f74a027 | 2014-11-13 19:21:18 +0100 | [diff] [blame] | 23 | #include <asm/io.h> |
| 24 | |
| 25 | #include <asm/processor.h> |
| 26 | |
| 27 | DECLARE_GLOBAL_DATA_PTR; |
| 28 | |
| 29 | /* Fixed sdram init -- doesn't use serial presence detect. |
| 30 | * |
| 31 | * This is useful for faster booting in configs where the RAM is unlikely |
| 32 | * to be changed, or for things like NAND booting where space is tight. |
| 33 | */ |
| 34 | static long fixed_sdram(void) |
| 35 | { |
| 36 | immap_t *im = (immap_t *)CONFIG_SYS_IMMR; |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 37 | u32 msize = CFG_SYS_SDRAM_SIZE; |
Dirk Eibach | f74a027 | 2014-11-13 19:21:18 +0100 | [diff] [blame] | 38 | u32 msize_log2 = __ilog2(msize); |
| 39 | |
| 40 | out_be32(&im->sysconf.ddrlaw[0].bar, |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 41 | CFG_SYS_SDRAM_BASE & 0xfffff000); |
Dirk Eibach | f74a027 | 2014-11-13 19:21:18 +0100 | [diff] [blame] | 42 | out_be32(&im->sysconf.ddrlaw[0].ar, LBLAWAR_EN | (msize_log2 - 1)); |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 43 | out_be32(&im->sysconf.ddrcdr, CFG_SYS_DDRCDR_VALUE); |
Dirk Eibach | f74a027 | 2014-11-13 19:21:18 +0100 | [diff] [blame] | 44 | |
| 45 | out_be32(&im->ddr.csbnds[0].csbnds, (msize - 1) >> 24); |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 46 | out_be32(&im->ddr.cs_config[0], CFG_SYS_DDR_CS0_CONFIG); |
Dirk Eibach | f74a027 | 2014-11-13 19:21:18 +0100 | [diff] [blame] | 47 | |
| 48 | /* Currently we use only one CS, so disable the other bank. */ |
| 49 | out_be32(&im->ddr.cs_config[1], 0); |
| 50 | |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 51 | out_be32(&im->ddr.sdram_clk_cntl, CFG_SYS_DDR_SDRAM_CLK_CNTL); |
| 52 | out_be32(&im->ddr.timing_cfg_3, CFG_SYS_DDR_TIMING_3); |
| 53 | out_be32(&im->ddr.timing_cfg_1, CFG_SYS_DDR_TIMING_1); |
| 54 | out_be32(&im->ddr.timing_cfg_2, CFG_SYS_DDR_TIMING_2); |
| 55 | out_be32(&im->ddr.timing_cfg_0, CFG_SYS_DDR_TIMING_0); |
Dirk Eibach | f74a027 | 2014-11-13 19:21:18 +0100 | [diff] [blame] | 56 | |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 57 | out_be32(&im->ddr.sdram_cfg, CFG_SYS_DDR_SDRAM_CFG); |
| 58 | out_be32(&im->ddr.sdram_cfg2, CFG_SYS_DDR_SDRAM_CFG2); |
| 59 | out_be32(&im->ddr.sdram_mode, CFG_SYS_DDR_MODE); |
| 60 | out_be32(&im->ddr.sdram_mode2, CFG_SYS_DDR_MODE2); |
Dirk Eibach | f74a027 | 2014-11-13 19:21:18 +0100 | [diff] [blame] | 61 | |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 62 | out_be32(&im->ddr.sdram_interval, CFG_SYS_DDR_INTERVAL); |
Dirk Eibach | f74a027 | 2014-11-13 19:21:18 +0100 | [diff] [blame] | 63 | sync(); |
| 64 | |
| 65 | /* enable DDR controller */ |
| 66 | setbits_be32(&im->ddr.sdram_cfg, SDRAM_CFG_MEM_EN); |
| 67 | sync(); |
| 68 | |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 69 | return get_ram_size(CFG_SYS_SDRAM_BASE, msize); |
Dirk Eibach | f74a027 | 2014-11-13 19:21:18 +0100 | [diff] [blame] | 70 | } |
| 71 | |
Simon Glass | d35f338 | 2017-04-06 12:47:05 -0600 | [diff] [blame] | 72 | int dram_init(void) |
Dirk Eibach | f74a027 | 2014-11-13 19:21:18 +0100 | [diff] [blame] | 73 | { |
| 74 | immap_t *im = (immap_t *)CONFIG_SYS_IMMR; |
| 75 | u32 msize; |
| 76 | |
| 77 | if ((in_be32(&im->sysconf.immrbar) & IMMRBAR_BASE_ADDR) != (u32)im) |
Simon Glass | 39f90ba | 2017-03-31 08:40:25 -0600 | [diff] [blame] | 78 | return -ENXIO; |
Dirk Eibach | f74a027 | 2014-11-13 19:21:18 +0100 | [diff] [blame] | 79 | |
| 80 | /* DDR SDRAM */ |
| 81 | msize = fixed_sdram(); |
| 82 | |
| 83 | /* return total bus SDRAM size(bytes) -- DDR */ |
Simon Glass | 39f90ba | 2017-03-31 08:40:25 -0600 | [diff] [blame] | 84 | gd->ram_size = msize; |
| 85 | |
| 86 | return 0; |
Dirk Eibach | f74a027 | 2014-11-13 19:21:18 +0100 | [diff] [blame] | 87 | } |
Mario Six | 0486138 | 2019-03-29 10:18:09 +0100 | [diff] [blame] | 88 | |
| 89 | #endif /* !CONFIG_MPC83XX_SDRAM */ |