ot1200_spl.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * Copyright (C) 2015, Bachmann electronic GmbH
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <spl.h>
  8. #include <asm/arch/mx6-ddr.h>
  9. DECLARE_GLOBAL_DATA_PTR;
  10. /* Configure MX6Q/DUAL mmdc DDR io registers */
  11. static struct mx6dq_iomux_ddr_regs ot1200_ddr_ioregs = {
  12. /* SDCLK[0:1], CAS, RAS, Reset: Differential input, 48ohm */
  13. .dram_sdclk_0 = 0x00000028,
  14. .dram_sdclk_1 = 0x00000028,
  15. .dram_cas = 0x00000028,
  16. .dram_ras = 0x00000028,
  17. .dram_reset = 0x00000028,
  18. /* SDCKE[0:1]: 100k pull-up */
  19. .dram_sdcke0 = 0x00003000,
  20. .dram_sdcke1 = 0x00003000,
  21. /* SDBA2: pull-up disabled */
  22. .dram_sdba2 = 0x00000000,
  23. /* SDODT[0:1]: 100k pull-up, 48 ohm */
  24. .dram_sdodt0 = 0x00000028,
  25. .dram_sdodt1 = 0x00000028,
  26. /* SDQS[0:7]: Differential input, 48 ohm */
  27. .dram_sdqs0 = 0x00000028,
  28. .dram_sdqs1 = 0x00000028,
  29. .dram_sdqs2 = 0x00000028,
  30. .dram_sdqs3 = 0x00000028,
  31. .dram_sdqs4 = 0x00000028,
  32. .dram_sdqs5 = 0x00000028,
  33. .dram_sdqs6 = 0x00000028,
  34. .dram_sdqs7 = 0x00000028,
  35. /* DQM[0:7]: Differential input, 48 ohm */
  36. .dram_dqm0 = 0x00000028,
  37. .dram_dqm1 = 0x00000028,
  38. .dram_dqm2 = 0x00000028,
  39. .dram_dqm3 = 0x00000028,
  40. .dram_dqm4 = 0x00000028,
  41. .dram_dqm5 = 0x00000028,
  42. .dram_dqm6 = 0x00000028,
  43. .dram_dqm7 = 0x00000028,
  44. };
  45. /* Configure MX6Q/DUAL mmdc GRP io registers */
  46. static struct mx6dq_iomux_grp_regs ot1200_grp_ioregs = {
  47. /* DDR3 */
  48. .grp_ddr_type = 0x000c0000,
  49. .grp_ddrmode_ctl = 0x00020000,
  50. /* Disable DDR pullups */
  51. .grp_ddrpke = 0x00000000,
  52. /* ADDR[00:16], SDBA[0:1]: 48 ohm */
  53. .grp_addds = 0x00000028,
  54. /* CS0/CS1/SDBA2/CKE0/CKE1/SDWE: 48 ohm */
  55. .grp_ctlds = 0x00000028,
  56. /* DATA[00:63]: Differential input, 48 ohm */
  57. .grp_ddrmode = 0x00020000,
  58. .grp_b0ds = 0x00000028,
  59. .grp_b1ds = 0x00000028,
  60. .grp_b2ds = 0x00000028,
  61. .grp_b3ds = 0x00000028,
  62. .grp_b4ds = 0x00000028,
  63. .grp_b5ds = 0x00000028,
  64. .grp_b6ds = 0x00000028,
  65. .grp_b7ds = 0x00000028,
  66. };
  67. static struct mx6_ddr_sysinfo ot1200_ddr_sysinfo = {
  68. /* Width of data bus: 0=16, 1=32, 2=64 */
  69. .dsize = 2,
  70. /* config for full 4GB range so that get_mem_size() works */
  71. .cs_density = 32, /* 32Gb per CS */
  72. /* Single chip select */
  73. .ncs = 1,
  74. .cs1_mirror = 0, /* war 0 */
  75. .rtt_wr = 1, /* DDR3_RTT_60_OHM - RTT_Wr = RZQ/4 */
  76. .rtt_nom = 1, /* DDR3_RTT_60_OHM - RTT_Nom = RZQ/4 */
  77. .walat = 1, /* Write additional latency */
  78. .ralat = 5, /* Read additional latency */
  79. .mif3_mode = 3, /* Command prediction working mode */
  80. .bi_on = 1, /* Bank interleaving enabled */ /* war 1 */
  81. .sde_to_rst = 0x10, /* 14 cycles, 200us (JEDEC default) */
  82. .rst_to_cke = 0x23, /* 33 cycles, 500us (JEDEC default) */
  83. .refsel = 1, /* Refresh cycles at 32KHz */
  84. .refr = 7, /* 8 refresh commands per refresh cycle */
  85. };
  86. /* MT41K128M16JT-125 */
  87. static struct mx6_ddr3_cfg micron_2gib_1600 = {
  88. .mem_speed = 1600,
  89. .density = 2,
  90. .width = 16,
  91. .banks = 8,
  92. .rowaddr = 14,
  93. .coladdr = 10,
  94. .pagesz = 2,
  95. .trcd = 1375,
  96. .trcmin = 4875,
  97. .trasmin = 3500,
  98. .SRT = 1,
  99. };
  100. static struct mx6_mmdc_calibration micron_2gib_1600_mmdc_calib = {
  101. /* write leveling calibration determine */
  102. .p0_mpwldectrl0 = 0x00260025,
  103. .p0_mpwldectrl1 = 0x00270021,
  104. .p1_mpwldectrl0 = 0x00180034,
  105. .p1_mpwldectrl1 = 0x00180024,
  106. /* Read DQS Gating calibration */
  107. .p0_mpdgctrl0 = 0x04380344,
  108. .p0_mpdgctrl1 = 0x0330032C,
  109. .p1_mpdgctrl0 = 0x0338033C,
  110. .p1_mpdgctrl1 = 0x032C0300,
  111. /* Read Calibration: DQS delay relative to DQ read access */
  112. .p0_mprddlctl = 0x3C2E3238,
  113. .p1_mprddlctl = 0x3A2E303C,
  114. /* Write Calibration: DQ/DM delay relative to DQS write access */
  115. .p0_mpwrdlctl = 0x36384036,
  116. .p1_mpwrdlctl = 0x442E4438,
  117. };
  118. static void ot1200_spl_dram_init(void)
  119. {
  120. mx6dq_dram_iocfg(64, &ot1200_ddr_ioregs, &ot1200_grp_ioregs);
  121. mx6_dram_cfg(&ot1200_ddr_sysinfo, &micron_2gib_1600_mmdc_calib,
  122. &micron_2gib_1600);
  123. }
  124. /*
  125. * called from C runtime startup code (arch/arm/lib/crt0.S:_main)
  126. * - we have a stack and a place to store GD, both in SRAM
  127. * - no variable global data is available
  128. */
  129. void board_init_f(ulong dummy)
  130. {
  131. /* setup AIPS and disable watchdog */
  132. arch_cpu_init();
  133. /* iomux and setup of i2c */
  134. board_early_init_f();
  135. /* setup GP timer */
  136. timer_init();
  137. /* UART clocks enabled and gd valid - init serial console */
  138. preloader_console_init();
  139. /* configure MMDC for SDRAM width/size and per-model calibration */
  140. ot1200_spl_dram_init();
  141. /* Clear the BSS. */
  142. memset(__bss_start, 0, __bss_end - __bss_start);
  143. /* load/boot image from boot device */
  144. board_init_r(NULL, 0);
  145. }