dram.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef DRAM_H
  7. #define DRAM_H
  8. #include <stdint.h>
  9. #include <dram_regs.h>
  10. #include <plat_private.h>
  11. enum {
  12. DDR3 = 3,
  13. LPDDR2 = 5,
  14. LPDDR3 = 6,
  15. LPDDR4 = 7,
  16. UNUSED = 0xff
  17. };
  18. struct rk3399_ddr_pctl_regs {
  19. uint32_t denali_ctl[CTL_REG_NUM];
  20. };
  21. struct rk3399_ddr_publ_regs {
  22. /*
  23. * PHY registers from 0 to 90 for slice1.
  24. * These are used to restore slice1-4 on resume.
  25. */
  26. uint32_t phy0[91];
  27. /*
  28. * PHY registers from 512 to 895.
  29. * Only registers 0-37 of each 128 register range are used.
  30. */
  31. uint32_t phy512[3][38];
  32. uint32_t phy896[63];
  33. };
  34. struct rk3399_ddr_pi_regs {
  35. uint32_t denali_pi[PI_REG_NUM];
  36. };
  37. union noc_ddrtiminga0 {
  38. uint32_t d32;
  39. struct {
  40. unsigned acttoact : 6;
  41. unsigned reserved0 : 2;
  42. unsigned rdtomiss : 6;
  43. unsigned reserved1 : 2;
  44. unsigned wrtomiss : 6;
  45. unsigned reserved2 : 2;
  46. unsigned readlatency : 8;
  47. } b;
  48. };
  49. union noc_ddrtimingb0 {
  50. uint32_t d32;
  51. struct {
  52. unsigned rdtowr : 5;
  53. unsigned reserved0 : 3;
  54. unsigned wrtord : 5;
  55. unsigned reserved1 : 3;
  56. unsigned rrd : 4;
  57. unsigned reserved2 : 4;
  58. unsigned faw : 6;
  59. unsigned reserved3 : 2;
  60. } b;
  61. };
  62. union noc_ddrtimingc0 {
  63. uint32_t d32;
  64. struct {
  65. unsigned burstpenalty : 4;
  66. unsigned reserved0 : 4;
  67. unsigned wrtomwr : 6;
  68. unsigned reserved1 : 18;
  69. } b;
  70. };
  71. union noc_devtodev0 {
  72. uint32_t d32;
  73. struct {
  74. unsigned busrdtord : 3;
  75. unsigned reserved0 : 1;
  76. unsigned busrdtowr : 3;
  77. unsigned reserved1 : 1;
  78. unsigned buswrtord : 3;
  79. unsigned reserved2 : 1;
  80. unsigned buswrtowr : 3;
  81. unsigned reserved3 : 17;
  82. } b;
  83. };
  84. union noc_ddrmode {
  85. uint32_t d32;
  86. struct {
  87. unsigned autoprecharge : 1;
  88. unsigned bypassfiltering : 1;
  89. unsigned fawbank : 1;
  90. unsigned burstsize : 2;
  91. unsigned mwrsize : 2;
  92. unsigned reserved2 : 1;
  93. unsigned forceorder : 8;
  94. unsigned forceorderstate : 8;
  95. unsigned reserved3 : 8;
  96. } b;
  97. };
  98. struct rk3399_msch_timings {
  99. union noc_ddrtiminga0 ddrtiminga0;
  100. union noc_ddrtimingb0 ddrtimingb0;
  101. union noc_ddrtimingc0 ddrtimingc0;
  102. union noc_devtodev0 devtodev0;
  103. union noc_ddrmode ddrmode;
  104. uint32_t agingx0;
  105. };
  106. struct rk3399_sdram_channel {
  107. unsigned char rank;
  108. /* col = 0, means this channel is invalid */
  109. unsigned char col;
  110. /* 3:8bank, 2:4bank */
  111. unsigned char bk;
  112. /* channel buswidth, 2:32bit, 1:16bit, 0:8bit */
  113. unsigned char bw;
  114. /* die buswidth, 2:32bit, 1:16bit, 0:8bit */
  115. unsigned char dbw;
  116. /* row_3_4 = 1: 6Gb or 12Gb die
  117. * row_3_4 = 0: normal die, power of 2
  118. */
  119. unsigned char row_3_4;
  120. unsigned char cs0_row;
  121. unsigned char cs1_row;
  122. uint32_t ddrconfig;
  123. struct rk3399_msch_timings noc_timings;
  124. };
  125. struct rk3399_sdram_params {
  126. struct rk3399_sdram_channel ch[2];
  127. uint32_t ddr_freq;
  128. unsigned char dramtype;
  129. unsigned char num_channels;
  130. unsigned char stride;
  131. unsigned char odt;
  132. struct rk3399_ddr_pctl_regs pctl_regs;
  133. struct rk3399_ddr_pi_regs pi_regs;
  134. struct rk3399_ddr_publ_regs phy_regs;
  135. uint32_t rx_cal_dqs[2][4];
  136. };
  137. extern struct rk3399_sdram_params sdram_config;
  138. void dram_init(void);
  139. #endif /* DRAM_H */