dram.c 1.6 KB

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