ddr3_1333.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #include <common.h>
  2. #include <asm/arch/dram.h>
  3. #include <asm/arch/cpu.h>
  4. void mctl_set_timing_params(uint16_t socid, struct dram_para *para)
  5. {
  6. struct sunxi_mctl_ctl_reg * const mctl_ctl =
  7. (struct sunxi_mctl_ctl_reg *)SUNXI_DRAM_CTL0_BASE;
  8. u8 tccd = 2;
  9. u8 tfaw = ns_to_t(50);
  10. u8 trrd = max(ns_to_t(10), 4);
  11. u8 trcd = ns_to_t(15);
  12. u8 trc = ns_to_t(53);
  13. u8 txp = max(ns_to_t(8), 3);
  14. u8 twtr = max(ns_to_t(8), 4);
  15. u8 trtp = max(ns_to_t(8), 4);
  16. u8 twr = max(ns_to_t(15), 3);
  17. u8 trp = ns_to_t(15);
  18. u8 tras = ns_to_t(38);
  19. u16 trefi = ns_to_t(7800) / 32;
  20. u16 trfc = ns_to_t(350);
  21. u8 tmrw = 0;
  22. u8 tmrd = 4;
  23. u8 tmod = 12;
  24. u8 tcke = 3;
  25. u8 tcksrx = 5;
  26. u8 tcksre = 5;
  27. u8 tckesr = 4;
  28. u8 trasmax = 24;
  29. u8 tcl = 6; /* CL 12 */
  30. u8 tcwl = 4; /* CWL 8 */
  31. u8 t_rdata_en = 4;
  32. u8 wr_latency = 2;
  33. u32 tdinit0 = (500 * CONFIG_DRAM_CLK) + 1; /* 500us */
  34. u32 tdinit1 = (360 * CONFIG_DRAM_CLK) / 1000 + 1; /* 360ns */
  35. u32 tdinit2 = (200 * CONFIG_DRAM_CLK) + 1; /* 200us */
  36. u32 tdinit3 = (1 * CONFIG_DRAM_CLK) + 1; /* 1us */
  37. u8 twtp = tcwl + 2 + twr; /* WL + BL / 2 + tWR */
  38. u8 twr2rd = tcwl + 2 + twtr; /* WL + BL / 2 + tWTR */
  39. u8 trd2wr = tcl + 2 + 1 - tcwl; /* RL + BL / 2 + 2 - WL */
  40. /* set mode register */
  41. writel(0x1c70, &mctl_ctl->mr[0]); /* CL=11, WR=12 */
  42. writel(0x40, &mctl_ctl->mr[1]);
  43. writel(0x18, &mctl_ctl->mr[2]); /* CWL=8 */
  44. writel(0x0, &mctl_ctl->mr[3]);
  45. if (socid == SOCID_R40)
  46. writel(0x3, &mctl_ctl->lp3mr11); /* odt_en[7:4] */
  47. /* set DRAM timing */
  48. writel(DRAMTMG0_TWTP(twtp) | DRAMTMG0_TFAW(tfaw) |
  49. DRAMTMG0_TRAS_MAX(trasmax) | DRAMTMG0_TRAS(tras),
  50. &mctl_ctl->dramtmg[0]);
  51. writel(DRAMTMG1_TXP(txp) | DRAMTMG1_TRTP(trtp) | DRAMTMG1_TRC(trc),
  52. &mctl_ctl->dramtmg[1]);
  53. writel(DRAMTMG2_TCWL(tcwl) | DRAMTMG2_TCL(tcl) |
  54. DRAMTMG2_TRD2WR(trd2wr) | DRAMTMG2_TWR2RD(twr2rd),
  55. &mctl_ctl->dramtmg[2]);
  56. writel(DRAMTMG3_TMRW(tmrw) | DRAMTMG3_TMRD(tmrd) | DRAMTMG3_TMOD(tmod),
  57. &mctl_ctl->dramtmg[3]);
  58. writel(DRAMTMG4_TRCD(trcd) | DRAMTMG4_TCCD(tccd) | DRAMTMG4_TRRD(trrd) |
  59. DRAMTMG4_TRP(trp), &mctl_ctl->dramtmg[4]);
  60. writel(DRAMTMG5_TCKSRX(tcksrx) | DRAMTMG5_TCKSRE(tcksre) |
  61. DRAMTMG5_TCKESR(tckesr) | DRAMTMG5_TCKE(tcke),
  62. &mctl_ctl->dramtmg[5]);
  63. /* set two rank timing */
  64. clrsetbits_le32(&mctl_ctl->dramtmg[8], (0xff << 8) | (0xff << 0),
  65. ((socid == SOCID_H5 ? 0x33 : 0x66) << 8) | (0x10 << 0));
  66. /* set PHY interface timing, write latency and read latency configure */
  67. writel((0x2 << 24) | (t_rdata_en << 16) | (0x1 << 8) |
  68. (wr_latency << 0), &mctl_ctl->pitmg[0]);
  69. /* set PHY timing, PTR0-2 use default */
  70. writel(PTR3_TDINIT0(tdinit0) | PTR3_TDINIT1(tdinit1), &mctl_ctl->ptr[3]);
  71. writel(PTR4_TDINIT2(tdinit2) | PTR4_TDINIT3(tdinit3), &mctl_ctl->ptr[4]);
  72. /* set refresh timing */
  73. writel(RFSHTMG_TREFI(trefi) | RFSHTMG_TRFC(trfc), &mctl_ctl->rfshtmg);
  74. }