Caesar Wang | 9740bba | 2016-08-25 08:37:42 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved. |
| 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Caesar Wang | 9740bba | 2016-08-25 08:37:42 +0800 | [diff] [blame] | 5 | */ |
| 6 | |
Caesar Wang | a845690 | 2016-10-27 01:12:34 +0800 | [diff] [blame] | 7 | #include <dram.h> |
Caesar Wang | 9740bba | 2016-08-25 08:37:42 +0800 | [diff] [blame] | 8 | #include <plat_private.h> |
Xing Zheng | 22a9871 | 2017-02-24 14:56:41 +0800 | [diff] [blame] | 9 | #include <secure.h> |
Caesar Wang | a845690 | 2016-10-27 01:12:34 +0800 | [diff] [blame] | 10 | #include <soc.h> |
| 11 | #include <rk3399_def.h> |
Caesar Wang | 9740bba | 2016-08-25 08:37:42 +0800 | [diff] [blame] | 12 | |
Caesar Wang | a845690 | 2016-10-27 01:12:34 +0800 | [diff] [blame] | 13 | __sramdata struct rk3399_sdram_params sdram_config; |
Caesar Wang | 9740bba | 2016-08-25 08:37:42 +0800 | [diff] [blame] | 14 | |
Caesar Wang | a845690 | 2016-10-27 01:12:34 +0800 | [diff] [blame] | 15 | void dram_init(void) |
Caesar Wang | 9740bba | 2016-08-25 08:37:42 +0800 | [diff] [blame] | 16 | { |
| 17 | uint32_t os_reg2_val, i; |
| 18 | |
Caesar Wang | a845690 | 2016-10-27 01:12:34 +0800 | [diff] [blame] | 19 | os_reg2_val = mmio_read_32(PMUGRF_BASE + PMUGRF_OSREG(2)); |
| 20 | sdram_config.dramtype = SYS_REG_DEC_DDRTYPE(os_reg2_val); |
| 21 | sdram_config.num_channels = SYS_REG_DEC_NUM_CH(os_reg2_val); |
| 22 | sdram_config.stride = (mmio_read_32(SGRF_BASE + SGRF_SOC_CON3_7(4)) >> |
| 23 | 10) & 0x1f; |
Caesar Wang | 9740bba | 2016-08-25 08:37:42 +0800 | [diff] [blame] | 24 | |
Caesar Wang | a845690 | 2016-10-27 01:12:34 +0800 | [diff] [blame] | 25 | for (i = 0; i < 2; i++) { |
| 26 | struct rk3399_sdram_channel *ch = &sdram_config.ch[i]; |
| 27 | struct rk3399_msch_timings *noc = &ch->noc_timings; |
Caesar Wang | 9740bba | 2016-08-25 08:37:42 +0800 | [diff] [blame] | 28 | |
Caesar Wang | a845690 | 2016-10-27 01:12:34 +0800 | [diff] [blame] | 29 | if (!(SYS_REG_DEC_CHINFO(os_reg2_val, i))) |
Caesar Wang | 9740bba | 2016-08-25 08:37:42 +0800 | [diff] [blame] | 30 | continue; |
| 31 | |
Caesar Wang | a845690 | 2016-10-27 01:12:34 +0800 | [diff] [blame] | 32 | ch->rank = SYS_REG_DEC_RANK(os_reg2_val, i); |
| 33 | ch->col = SYS_REG_DEC_COL(os_reg2_val, i); |
| 34 | ch->bk = SYS_REG_DEC_BK(os_reg2_val, i); |
| 35 | ch->bw = SYS_REG_DEC_BW(os_reg2_val, i); |
| 36 | ch->dbw = SYS_REG_DEC_DBW(os_reg2_val, i); |
| 37 | ch->row_3_4 = SYS_REG_DEC_ROW_3_4(os_reg2_val, i); |
| 38 | ch->cs0_row = SYS_REG_DEC_CS0_ROW(os_reg2_val, i); |
| 39 | ch->cs1_row = SYS_REG_DEC_CS1_ROW(os_reg2_val, i); |
| 40 | ch->ddrconfig = mmio_read_32(MSCH_BASE(i) + MSCH_DEVICECONF); |
Caesar Wang | 9740bba | 2016-08-25 08:37:42 +0800 | [diff] [blame] | 41 | |
Caesar Wang | a845690 | 2016-10-27 01:12:34 +0800 | [diff] [blame] | 42 | noc->ddrtiminga0.d32 = mmio_read_32(MSCH_BASE(i) + |
| 43 | MSCH_DDRTIMINGA0); |
| 44 | noc->ddrtimingb0.d32 = mmio_read_32(MSCH_BASE(i) + |
| 45 | MSCH_DDRTIMINGB0); |
| 46 | noc->ddrtimingc0.d32 = mmio_read_32(MSCH_BASE(i) + |
| 47 | MSCH_DDRTIMINGC0); |
| 48 | noc->devtodev0.d32 = mmio_read_32(MSCH_BASE(i) + |
| 49 | MSCH_DEVTODEV0); |
| 50 | noc->ddrmode.d32 = mmio_read_32(MSCH_BASE(i) + MSCH_DDRMODE); |
| 51 | noc->agingx0 = mmio_read_32(MSCH_BASE(i) + MSCH_AGINGX0); |
Caesar Wang | 9740bba | 2016-08-25 08:37:42 +0800 | [diff] [blame] | 52 | } |
Caesar Wang | 9740bba | 2016-08-25 08:37:42 +0800 | [diff] [blame] | 53 | } |