gw_ventana_spl.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2014 Gateworks Corporation
  4. * Author: Tim Harvey <tharvey@gateworks.com>
  5. */
  6. #include <common.h>
  7. #include <asm/io.h>
  8. #include <asm/arch/crm_regs.h>
  9. #include <asm/arch/mx6-ddr.h>
  10. #include <asm/arch/mx6-pins.h>
  11. #include <asm/arch/sys_proto.h>
  12. #include <asm/mach-imx/boot_mode.h>
  13. #include <asm/mach-imx/iomux-v3.h>
  14. #include <asm/mach-imx/mxc_i2c.h>
  15. #include <environment.h>
  16. #include <i2c.h>
  17. #include <spl.h>
  18. #include "gsc.h"
  19. #include "common.h"
  20. #define RTT_NOM_120OHM /* use 120ohm Rtt_nom vs 60ohm (lower power) */
  21. #define GSC_EEPROM_DDR_SIZE 0x2B /* enum (512,1024,2048) MB */
  22. #define GSC_EEPROM_DDR_WIDTH 0x2D /* enum (32,64) bit */
  23. /* configure MX6Q/DUAL mmdc DDR io registers */
  24. struct mx6dq_iomux_ddr_regs mx6dq_ddr_ioregs = {
  25. /* SDCLK[0:1], CAS, RAS, Reset: Differential input, 40ohm */
  26. .dram_sdclk_0 = 0x00020030,
  27. .dram_sdclk_1 = 0x00020030,
  28. .dram_cas = 0x00020030,
  29. .dram_ras = 0x00020030,
  30. .dram_reset = 0x00020030,
  31. /* SDCKE[0:1]: 100k pull-up */
  32. .dram_sdcke0 = 0x00003000,
  33. .dram_sdcke1 = 0x00003000,
  34. /* SDBA2: pull-up disabled */
  35. .dram_sdba2 = 0x00000000,
  36. /* SDODT[0:1]: 100k pull-up, 40 ohm */
  37. .dram_sdodt0 = 0x00003030,
  38. .dram_sdodt1 = 0x00003030,
  39. /* SDQS[0:7]: Differential input, 40 ohm */
  40. .dram_sdqs0 = 0x00000030,
  41. .dram_sdqs1 = 0x00000030,
  42. .dram_sdqs2 = 0x00000030,
  43. .dram_sdqs3 = 0x00000030,
  44. .dram_sdqs4 = 0x00000030,
  45. .dram_sdqs5 = 0x00000030,
  46. .dram_sdqs6 = 0x00000030,
  47. .dram_sdqs7 = 0x00000030,
  48. /* DQM[0:7]: Differential input, 40 ohm */
  49. .dram_dqm0 = 0x00020030,
  50. .dram_dqm1 = 0x00020030,
  51. .dram_dqm2 = 0x00020030,
  52. .dram_dqm3 = 0x00020030,
  53. .dram_dqm4 = 0x00020030,
  54. .dram_dqm5 = 0x00020030,
  55. .dram_dqm6 = 0x00020030,
  56. .dram_dqm7 = 0x00020030,
  57. };
  58. /* configure MX6Q/DUAL mmdc GRP io registers */
  59. struct mx6dq_iomux_grp_regs mx6dq_grp_ioregs = {
  60. /* DDR3 */
  61. .grp_ddr_type = 0x000c0000,
  62. .grp_ddrmode_ctl = 0x00020000,
  63. /* disable DDR pullups */
  64. .grp_ddrpke = 0x00000000,
  65. /* ADDR[00:16], SDBA[0:1]: 40 ohm */
  66. .grp_addds = 0x00000030,
  67. /* CS0/CS1/SDBA2/CKE0/CKE1/SDWE: 40 ohm */
  68. .grp_ctlds = 0x00000030,
  69. /* DATA[00:63]: Differential input, 40 ohm */
  70. .grp_ddrmode = 0x00020000,
  71. .grp_b0ds = 0x00000030,
  72. .grp_b1ds = 0x00000030,
  73. .grp_b2ds = 0x00000030,
  74. .grp_b3ds = 0x00000030,
  75. .grp_b4ds = 0x00000030,
  76. .grp_b5ds = 0x00000030,
  77. .grp_b6ds = 0x00000030,
  78. .grp_b7ds = 0x00000030,
  79. };
  80. /* configure MX6SOLO/DUALLITE mmdc DDR io registers */
  81. struct mx6sdl_iomux_ddr_regs mx6sdl_ddr_ioregs = {
  82. /* SDCLK[0:1], CAS, RAS, Reset: Differential input, 40ohm */
  83. .dram_sdclk_0 = 0x00020030,
  84. .dram_sdclk_1 = 0x00020030,
  85. .dram_cas = 0x00020030,
  86. .dram_ras = 0x00020030,
  87. .dram_reset = 0x00020030,
  88. /* SDCKE[0:1]: 100k pull-up */
  89. .dram_sdcke0 = 0x00003000,
  90. .dram_sdcke1 = 0x00003000,
  91. /* SDBA2: pull-up disabled */
  92. .dram_sdba2 = 0x00000000,
  93. /* SDODT[0:1]: 100k pull-up, 40 ohm */
  94. .dram_sdodt0 = 0x00003030,
  95. .dram_sdodt1 = 0x00003030,
  96. /* SDQS[0:7]: Differential input, 40 ohm */
  97. .dram_sdqs0 = 0x00000030,
  98. .dram_sdqs1 = 0x00000030,
  99. .dram_sdqs2 = 0x00000030,
  100. .dram_sdqs3 = 0x00000030,
  101. .dram_sdqs4 = 0x00000030,
  102. .dram_sdqs5 = 0x00000030,
  103. .dram_sdqs6 = 0x00000030,
  104. .dram_sdqs7 = 0x00000030,
  105. /* DQM[0:7]: Differential input, 40 ohm */
  106. .dram_dqm0 = 0x00020030,
  107. .dram_dqm1 = 0x00020030,
  108. .dram_dqm2 = 0x00020030,
  109. .dram_dqm3 = 0x00020030,
  110. .dram_dqm4 = 0x00020030,
  111. .dram_dqm5 = 0x00020030,
  112. .dram_dqm6 = 0x00020030,
  113. .dram_dqm7 = 0x00020030,
  114. };
  115. /* configure MX6SOLO/DUALLITE mmdc GRP io registers */
  116. struct mx6sdl_iomux_grp_regs mx6sdl_grp_ioregs = {
  117. /* DDR3 */
  118. .grp_ddr_type = 0x000c0000,
  119. /* SDQS[0:7]: Differential input, 40 ohm */
  120. .grp_ddrmode_ctl = 0x00020000,
  121. /* disable DDR pullups */
  122. .grp_ddrpke = 0x00000000,
  123. /* ADDR[00:16], SDBA[0:1]: 40 ohm */
  124. .grp_addds = 0x00000030,
  125. /* CS0/CS1/SDBA2/CKE0/CKE1/SDWE: 40 ohm */
  126. .grp_ctlds = 0x00000030,
  127. /* DATA[00:63]: Differential input, 40 ohm */
  128. .grp_ddrmode = 0x00020000,
  129. .grp_b0ds = 0x00000030,
  130. .grp_b1ds = 0x00000030,
  131. .grp_b2ds = 0x00000030,
  132. .grp_b3ds = 0x00000030,
  133. .grp_b4ds = 0x00000030,
  134. .grp_b5ds = 0x00000030,
  135. .grp_b6ds = 0x00000030,
  136. .grp_b7ds = 0x00000030,
  137. };
  138. /* MT41K64M16JT-125 (1Gb density) */
  139. static struct mx6_ddr3_cfg mt41k64m16jt_125 = {
  140. .mem_speed = 1600,
  141. .density = 1,
  142. .width = 16,
  143. .banks = 8,
  144. .rowaddr = 13,
  145. .coladdr = 10,
  146. .pagesz = 2,
  147. .trcd = 1375,
  148. .trcmin = 4875,
  149. .trasmin = 3500,
  150. };
  151. /* MT41K128M16JT-125 (2Gb density) */
  152. static struct mx6_ddr3_cfg mt41k128m16jt_125 = {
  153. .mem_speed = 1600,
  154. .density = 2,
  155. .width = 16,
  156. .banks = 8,
  157. .rowaddr = 14,
  158. .coladdr = 10,
  159. .pagesz = 2,
  160. .trcd = 1375,
  161. .trcmin = 4875,
  162. .trasmin = 3500,
  163. };
  164. /* MT41K256M16HA-125 (4Gb density) */
  165. static struct mx6_ddr3_cfg mt41k256m16ha_125 = {
  166. .mem_speed = 1600,
  167. .density = 4,
  168. .width = 16,
  169. .banks = 8,
  170. .rowaddr = 15,
  171. .coladdr = 10,
  172. .pagesz = 2,
  173. .trcd = 1375,
  174. .trcmin = 4875,
  175. .trasmin = 3500,
  176. };
  177. /* MT41K512M16HA-125 (8Gb density) */
  178. static struct mx6_ddr3_cfg mt41k512m16ha_125 = {
  179. .mem_speed = 1600,
  180. .density = 8,
  181. .width = 16,
  182. .banks = 8,
  183. .rowaddr = 16,
  184. .coladdr = 10,
  185. .pagesz = 2,
  186. .trcd = 1375,
  187. .trcmin = 4875,
  188. .trasmin = 3500,
  189. };
  190. /*
  191. * calibration - these are the various CPU/DDR3 combinations we support
  192. */
  193. static struct mx6_mmdc_calibration mx6sdl_64x16_mmdc_calib = {
  194. /* write leveling calibration determine */
  195. .p0_mpwldectrl0 = 0x004C004E,
  196. .p0_mpwldectrl1 = 0x00440044,
  197. /* Read DQS Gating calibration */
  198. .p0_mpdgctrl0 = 0x42440247,
  199. .p0_mpdgctrl1 = 0x02310232,
  200. /* Read Calibration: DQS delay relative to DQ read access */
  201. .p0_mprddlctl = 0x45424746,
  202. /* Write Calibration: DQ/DM delay relative to DQS write access */
  203. .p0_mpwrdlctl = 0x33382C31,
  204. };
  205. static struct mx6_mmdc_calibration mx6dq_256x16_mmdc_calib = {
  206. /* write leveling calibration determine */
  207. .p0_mpwldectrl0 = 0x001B0016,
  208. .p0_mpwldectrl1 = 0x000C000E,
  209. /* Read DQS Gating calibration */
  210. .p0_mpdgctrl0 = 0x4324033A,
  211. .p0_mpdgctrl1 = 0x00000000,
  212. /* Read Calibration: DQS delay relative to DQ read access */
  213. .p0_mprddlctl = 0x40403438,
  214. /* Write Calibration: DQ/DM delay relative to DQS write access */
  215. .p0_mpwrdlctl = 0x40403D36,
  216. };
  217. static struct mx6_mmdc_calibration mx6sdl_256x16_mmdc_calib = {
  218. /* write leveling calibration determine */
  219. .p0_mpwldectrl0 = 0x00420043,
  220. .p0_mpwldectrl1 = 0x0016001A,
  221. /* Read DQS Gating calibration */
  222. .p0_mpdgctrl0 = 0x4238023B,
  223. .p0_mpdgctrl1 = 0x00000000,
  224. /* Read Calibration: DQS delay relative to DQ read access */
  225. .p0_mprddlctl = 0x40404849,
  226. /* Write Calibration: DQ/DM delay relative to DQS write access */
  227. .p0_mpwrdlctl = 0x40402E2F,
  228. };
  229. static struct mx6_mmdc_calibration mx6dq_128x32_mmdc_calib = {
  230. /* write leveling calibration determine */
  231. .p0_mpwldectrl0 = 0x00190017,
  232. .p0_mpwldectrl1 = 0x00140026,
  233. /* Read DQS Gating calibration */
  234. .p0_mpdgctrl0 = 0x43380347,
  235. .p0_mpdgctrl1 = 0x433C034D,
  236. /* Read Calibration: DQS delay relative to DQ read access */
  237. .p0_mprddlctl = 0x3C313539,
  238. /* Write Calibration: DQ/DM delay relative to DQS write access */
  239. .p0_mpwrdlctl = 0x36393C39,
  240. };
  241. static struct mx6_mmdc_calibration mx6sdl_128x32_mmdc_calib = {
  242. /* write leveling calibration determine */
  243. .p0_mpwldectrl0 = 0x003C003C,
  244. .p0_mpwldectrl1 = 0x001F002A,
  245. /* Read DQS Gating calibration */
  246. .p0_mpdgctrl0 = 0x42410244,
  247. .p0_mpdgctrl1 = 0x4234023A,
  248. /* Read Calibration: DQS delay relative to DQ read access */
  249. .p0_mprddlctl = 0x484A4C4B,
  250. /* Write Calibration: DQ/DM delay relative to DQS write access */
  251. .p0_mpwrdlctl = 0x33342B32,
  252. };
  253. static struct mx6_mmdc_calibration mx6dq_128x64_mmdc_calib = {
  254. /* write leveling calibration determine */
  255. .p0_mpwldectrl0 = 0x00190017,
  256. .p0_mpwldectrl1 = 0x00140026,
  257. .p1_mpwldectrl0 = 0x0021001C,
  258. .p1_mpwldectrl1 = 0x0011001D,
  259. /* Read DQS Gating calibration */
  260. .p0_mpdgctrl0 = 0x43380347,
  261. .p0_mpdgctrl1 = 0x433C034D,
  262. .p1_mpdgctrl0 = 0x032C0324,
  263. .p1_mpdgctrl1 = 0x03310232,
  264. /* Read Calibration: DQS delay relative to DQ read access */
  265. .p0_mprddlctl = 0x3C313539,
  266. .p1_mprddlctl = 0x37343141,
  267. /* Write Calibration: DQ/DM delay relative to DQS write access */
  268. .p0_mpwrdlctl = 0x36393C39,
  269. .p1_mpwrdlctl = 0x42344438,
  270. };
  271. static struct mx6_mmdc_calibration mx6sdl_128x64_mmdc_calib = {
  272. /* write leveling calibration determine */
  273. .p0_mpwldectrl0 = 0x003C003C,
  274. .p0_mpwldectrl1 = 0x001F002A,
  275. .p1_mpwldectrl0 = 0x00330038,
  276. .p1_mpwldectrl1 = 0x0022003F,
  277. /* Read DQS Gating calibration */
  278. .p0_mpdgctrl0 = 0x42410244,
  279. .p0_mpdgctrl1 = 0x4234023A,
  280. .p1_mpdgctrl0 = 0x022D022D,
  281. .p1_mpdgctrl1 = 0x021C0228,
  282. /* Read Calibration: DQS delay relative to DQ read access */
  283. .p0_mprddlctl = 0x484A4C4B,
  284. .p1_mprddlctl = 0x4B4D4E4B,
  285. /* Write Calibration: DQ/DM delay relative to DQS write access */
  286. .p0_mpwrdlctl = 0x33342B32,
  287. .p1_mpwrdlctl = 0x3933332B,
  288. };
  289. static struct mx6_mmdc_calibration mx6dq_256x32_mmdc_calib = {
  290. /* write leveling calibration determine */
  291. .p0_mpwldectrl0 = 0x001E001A,
  292. .p0_mpwldectrl1 = 0x0026001F,
  293. /* Read DQS Gating calibration */
  294. .p0_mpdgctrl0 = 0x43370349,
  295. .p0_mpdgctrl1 = 0x032D0327,
  296. /* Read Calibration: DQS delay relative to DQ read access */
  297. .p0_mprddlctl = 0x3D303639,
  298. /* Write Calibration: DQ/DM delay relative to DQS write access */
  299. .p0_mpwrdlctl = 0x32363934,
  300. };
  301. static struct mx6_mmdc_calibration mx6sdl_256x32_mmdc_calib = {
  302. /* write leveling calibration determine */
  303. .p0_mpwldectrl0 = 0X00480047,
  304. .p0_mpwldectrl1 = 0X003D003F,
  305. /* Read DQS Gating calibration */
  306. .p0_mpdgctrl0 = 0X423E0241,
  307. .p0_mpdgctrl1 = 0X022B022C,
  308. /* Read Calibration: DQS delay relative to DQ read access */
  309. .p0_mprddlctl = 0X49454A4A,
  310. /* Write Calibration: DQ/DM delay relative to DQS write access */
  311. .p0_mpwrdlctl = 0X2E372C32,
  312. };
  313. static struct mx6_mmdc_calibration mx6dq_256x64_mmdc_calib = {
  314. /* write leveling calibration determine */
  315. .p0_mpwldectrl0 = 0X00220021,
  316. .p0_mpwldectrl1 = 0X00200030,
  317. .p1_mpwldectrl0 = 0X002D0027,
  318. .p1_mpwldectrl1 = 0X00150026,
  319. /* Read DQS Gating calibration */
  320. .p0_mpdgctrl0 = 0x43330342,
  321. .p0_mpdgctrl1 = 0x0339034A,
  322. .p1_mpdgctrl0 = 0x032F0325,
  323. .p1_mpdgctrl1 = 0x032F022E,
  324. /* Read Calibration: DQS delay relative to DQ read access */
  325. .p0_mprddlctl = 0X3A2E3437,
  326. .p1_mprddlctl = 0X35312F3F,
  327. /* Write Calibration: DQ/DM delay relative to DQS write access */
  328. .p0_mpwrdlctl = 0X33363B37,
  329. .p1_mpwrdlctl = 0X40304239,
  330. };
  331. static struct mx6_mmdc_calibration mx6sdl_256x64_mmdc_calib = {
  332. /* write leveling calibration determine */
  333. .p0_mpwldectrl0 = 0x0048004A,
  334. .p0_mpwldectrl1 = 0x003F004A,
  335. .p1_mpwldectrl0 = 0x001E0028,
  336. .p1_mpwldectrl1 = 0x002C0043,
  337. /* Read DQS Gating calibration */
  338. .p0_mpdgctrl0 = 0x02250219,
  339. .p0_mpdgctrl1 = 0x01790202,
  340. .p1_mpdgctrl0 = 0x02080208,
  341. .p1_mpdgctrl1 = 0x016C0175,
  342. /* Read Calibration: DQS delay relative to DQ read access */
  343. .p0_mprddlctl = 0x4A4C4D4C,
  344. .p1_mprddlctl = 0x494C4A48,
  345. /* Write Calibration: DQ/DM delay relative to DQS write access */
  346. .p0_mpwrdlctl = 0x403F3437,
  347. .p1_mpwrdlctl = 0x383A3930,
  348. };
  349. static struct mx6_mmdc_calibration mx6sdl_256x64x2_mmdc_calib = {
  350. /* write leveling calibration determine */
  351. .p0_mpwldectrl0 = 0x001F003F,
  352. .p0_mpwldectrl1 = 0x001F001F,
  353. .p1_mpwldectrl0 = 0x001F004E,
  354. .p1_mpwldectrl1 = 0x0059001F,
  355. /* Read DQS Gating calibration */
  356. .p0_mpdgctrl0 = 0x42220225,
  357. .p0_mpdgctrl1 = 0x0213021F,
  358. .p1_mpdgctrl0 = 0x022C0242,
  359. .p1_mpdgctrl1 = 0x022C0244,
  360. /* Read Calibration: DQS delay relative to DQ read access */
  361. .p0_mprddlctl = 0x474A4C4A,
  362. .p1_mprddlctl = 0x48494C45,
  363. /* Write Calibration: DQ/DM delay relative to DQS write access */
  364. .p0_mpwrdlctl = 0x3F3F3F36,
  365. .p1_mpwrdlctl = 0x3F36363F,
  366. };
  367. static struct mx6_mmdc_calibration mx6dq_512x32_mmdc_calib = {
  368. /* write leveling calibration determine */
  369. .p0_mpwldectrl0 = 0x002A0025,
  370. .p0_mpwldectrl1 = 0x003A002A,
  371. /* Read DQS Gating calibration */
  372. .p0_mpdgctrl0 = 0x43430356,
  373. .p0_mpdgctrl1 = 0x033C0335,
  374. /* Read Calibration: DQS delay relative to DQ read access */
  375. .p0_mprddlctl = 0x4B373F42,
  376. /* Write Calibration: DQ/DM delay relative to DQS write access */
  377. .p0_mpwrdlctl = 0x303E3C36,
  378. };
  379. static struct mx6_mmdc_calibration mx6dq_512x64_mmdc_calib = {
  380. /* write leveling calibration determine */
  381. .p0_mpwldectrl0 = 0x00230020,
  382. .p0_mpwldectrl1 = 0x002F002A,
  383. .p1_mpwldectrl0 = 0x001D0027,
  384. .p1_mpwldectrl1 = 0x00100023,
  385. /* Read DQS Gating calibration */
  386. .p0_mpdgctrl0 = 0x03250339,
  387. .p0_mpdgctrl1 = 0x031C0316,
  388. .p1_mpdgctrl0 = 0x03210331,
  389. .p1_mpdgctrl1 = 0x031C025A,
  390. /* Read Calibration: DQS delay relative to DQ read access */
  391. .p0_mprddlctl = 0x40373C40,
  392. .p1_mprddlctl = 0x3A373646,
  393. /* Write Calibration: DQ/DM delay relative to DQS write access */
  394. .p0_mpwrdlctl = 0x2E353933,
  395. .p1_mpwrdlctl = 0x3C2F3F35,
  396. };
  397. static void spl_dram_init(int width, int size_mb, int board_model)
  398. {
  399. struct mx6_ddr3_cfg *mem = NULL;
  400. struct mx6_mmdc_calibration *calib = NULL;
  401. struct mx6_ddr_sysinfo sysinfo = {
  402. /* width of data bus:0=16,1=32,2=64 */
  403. .dsize = width/32,
  404. /* config for full 4GB range so that get_mem_size() works */
  405. .cs_density = 32, /* 32Gb per CS */
  406. /* single chip select */
  407. .ncs = 1,
  408. .cs1_mirror = 0,
  409. .rtt_wr = 1 /*DDR3_RTT_60_OHM*/, /* RTT_Wr = RZQ/4 */
  410. #ifdef RTT_NOM_120OHM
  411. .rtt_nom = 2 /*DDR3_RTT_120_OHM*/, /* RTT_Nom = RZQ/2 */
  412. #else
  413. .rtt_nom = 1 /*DDR3_RTT_60_OHM*/, /* RTT_Nom = RZQ/4 */
  414. #endif
  415. .walat = 1, /* Write additional latency */
  416. .ralat = 5, /* Read additional latency */
  417. .mif3_mode = 3, /* Command prediction working mode */
  418. .bi_on = 1, /* Bank interleaving enabled */
  419. .sde_to_rst = 0x10, /* 14 cycles, 200us (JEDEC default) */
  420. .rst_to_cke = 0x23, /* 33 cycles, 500us (JEDEC default) */
  421. .pd_fast_exit = 1, /* enable precharge power-down fast exit */
  422. .ddr_type = DDR_TYPE_DDR3,
  423. .refsel = 1, /* Refresh cycles at 32KHz */
  424. .refr = 7, /* 8 refresh commands per refresh cycle */
  425. };
  426. /*
  427. * MMDC Calibration requires the following data:
  428. * mx6_mmdc_calibration - board-specific calibration (routing delays)
  429. * these calibration values depend on board routing, SoC, and DDR
  430. * mx6_ddr_sysinfo - board-specific memory architecture (width/cs/etc)
  431. * mx6_ddr_cfg - chip specific timing/layout details
  432. */
  433. if (width == 16 && size_mb == 128) {
  434. mem = &mt41k64m16jt_125;
  435. if (is_cpu_type(MXC_CPU_MX6Q))
  436. ;
  437. else
  438. calib = &mx6sdl_64x16_mmdc_calib;
  439. debug("1gB density\n");
  440. } else if (width == 16 && size_mb == 256) {
  441. /* 1x 2Gb density chip - same calib as 2x 2Gb */
  442. mem = &mt41k128m16jt_125;
  443. if (is_cpu_type(MXC_CPU_MX6Q))
  444. calib = &mx6dq_128x32_mmdc_calib;
  445. else
  446. calib = &mx6sdl_128x32_mmdc_calib;
  447. debug("2gB density\n");
  448. } else if (width == 16 && size_mb == 512) {
  449. mem = &mt41k256m16ha_125;
  450. if (is_cpu_type(MXC_CPU_MX6Q))
  451. calib = &mx6dq_256x16_mmdc_calib;
  452. else
  453. calib = &mx6sdl_256x16_mmdc_calib;
  454. debug("4gB density\n");
  455. } else if (width == 32 && size_mb == 256) {
  456. /* Same calib as width==16, size==128 */
  457. mem = &mt41k64m16jt_125;
  458. if (is_cpu_type(MXC_CPU_MX6Q))
  459. ;
  460. else
  461. calib = &mx6sdl_64x16_mmdc_calib;
  462. debug("1gB density\n");
  463. } else if (width == 32 && size_mb == 512) {
  464. mem = &mt41k128m16jt_125;
  465. if (is_cpu_type(MXC_CPU_MX6Q))
  466. calib = &mx6dq_128x32_mmdc_calib;
  467. else
  468. calib = &mx6sdl_128x32_mmdc_calib;
  469. debug("2gB density\n");
  470. } else if (width == 32 && size_mb == 1024) {
  471. mem = &mt41k256m16ha_125;
  472. if (is_cpu_type(MXC_CPU_MX6Q))
  473. calib = &mx6dq_256x32_mmdc_calib;
  474. else
  475. calib = &mx6sdl_256x32_mmdc_calib;
  476. debug("4gB density\n");
  477. } else if (width == 32 && size_mb == 2048) {
  478. mem = &mt41k512m16ha_125;
  479. if (is_cpu_type(MXC_CPU_MX6Q))
  480. calib = &mx6dq_512x32_mmdc_calib;
  481. debug("8gB density\n");
  482. } else if (width == 64 && size_mb == 512) {
  483. mem = &mt41k64m16jt_125;
  484. debug("1gB density\n");
  485. } else if (width == 64 && size_mb == 1024) {
  486. mem = &mt41k128m16jt_125;
  487. if (is_cpu_type(MXC_CPU_MX6Q))
  488. calib = &mx6dq_128x64_mmdc_calib;
  489. else
  490. calib = &mx6sdl_128x64_mmdc_calib;
  491. debug("2gB density\n");
  492. } else if (width == 64 && size_mb == 2048) {
  493. mem = &mt41k256m16ha_125;
  494. if (is_cpu_type(MXC_CPU_MX6Q))
  495. calib = &mx6dq_256x64_mmdc_calib;
  496. else
  497. calib = &mx6sdl_256x64_mmdc_calib;
  498. debug("4gB density\n");
  499. } else if (width == 64 && size_mb == 4096) {
  500. switch(board_model) {
  501. case GW5903:
  502. /* 8xMT41K256M16 (4GiB) fly-by mirrored 2-chipsels */
  503. mem = &mt41k256m16ha_125;
  504. debug("4gB density\n");
  505. if (!is_cpu_type(MXC_CPU_MX6Q)) {
  506. calib = &mx6sdl_256x64x2_mmdc_calib;
  507. sysinfo.ncs = 2;
  508. sysinfo.cs_density = 18; /* CS0_END=71 */
  509. sysinfo.cs1_mirror = 1; /* mirror enabled */
  510. }
  511. break;
  512. default:
  513. mem = &mt41k512m16ha_125;
  514. if (is_cpu_type(MXC_CPU_MX6Q))
  515. calib = &mx6dq_512x64_mmdc_calib;
  516. debug("8gB density\n");
  517. break;
  518. }
  519. }
  520. if (!(mem && calib)) {
  521. puts("Error: Invalid Calibration/Board Configuration\n");
  522. printf("MEM : %s\n", mem ? "OKAY" : "NULL");
  523. printf("CALIB : %s\n", calib ? "OKAY" : "NULL");
  524. printf("CPUTYPE: %s\n",
  525. is_cpu_type(MXC_CPU_MX6Q) ? "IMX6Q" : "IMX6DL");
  526. printf("SIZE_MB: %d\n", size_mb);
  527. printf("WIDTH : %d\n", width);
  528. hang();
  529. }
  530. if (is_cpu_type(MXC_CPU_MX6Q))
  531. mx6dq_dram_iocfg(width, &mx6dq_ddr_ioregs,
  532. &mx6dq_grp_ioregs);
  533. else
  534. mx6sdl_dram_iocfg(width, &mx6sdl_ddr_ioregs,
  535. &mx6sdl_grp_ioregs);
  536. mx6_dram_cfg(&sysinfo, calib, mem);
  537. }
  538. static void ccgr_init(void)
  539. {
  540. struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
  541. writel(0x00C03F3F, &ccm->CCGR0);
  542. writel(0x0030FC03, &ccm->CCGR1);
  543. writel(0x0FFFC000, &ccm->CCGR2);
  544. writel(0x3FF00000, &ccm->CCGR3);
  545. writel(0xFFFFF300, &ccm->CCGR4); /* enable NAND/GPMI/BCH clks */
  546. writel(0x0F0000C3, &ccm->CCGR5);
  547. writel(0x000003FF, &ccm->CCGR6);
  548. }
  549. /*
  550. * called from C runtime startup code (arch/arm/lib/crt0.S:_main)
  551. * - we have a stack and a place to store GD, both in SRAM
  552. * - no variable global data is available
  553. */
  554. void board_init_f(ulong dummy)
  555. {
  556. struct ventana_board_info ventana_info;
  557. int board_model;
  558. /* setup clock gating */
  559. ccgr_init();
  560. /* setup AIPS and disable watchdog */
  561. arch_cpu_init();
  562. /* setup AXI */
  563. gpr_init();
  564. /* iomux and setup of i2c */
  565. setup_iomux_uart();
  566. setup_ventana_i2c();
  567. /* setup GP timer */
  568. timer_init();
  569. /* UART clocks enabled and gd valid - init serial console */
  570. preloader_console_init();
  571. /* read/validate EEPROM info to determine board model and SDRAM cfg */
  572. board_model = read_eeprom(CONFIG_I2C_GSC, &ventana_info);
  573. /* configure model-specific gpio */
  574. setup_iomux_gpio(board_model, &ventana_info);
  575. /* provide some some default: 32bit 128MB */
  576. if (GW_UNKNOWN == board_model)
  577. hang();
  578. /* configure MMDC for SDRAM width/size and per-model calibration */
  579. spl_dram_init(8 << ventana_info.sdram_width,
  580. 16 << ventana_info.sdram_size,
  581. board_model);
  582. }
  583. void board_boot_order(u32 *spl_boot_list)
  584. {
  585. spl_boot_list[0] = spl_boot_device();
  586. switch (spl_boot_list[0]) {
  587. case BOOT_DEVICE_NAND:
  588. spl_boot_list[1] = BOOT_DEVICE_MMC1;
  589. spl_boot_list[2] = BOOT_DEVICE_UART;
  590. break;
  591. case BOOT_DEVICE_MMC1:
  592. spl_boot_list[1] = BOOT_DEVICE_UART;
  593. break;
  594. }
  595. }
  596. /* called from board_init_r after gd setup if CONFIG_SPL_BOARD_INIT defined */
  597. /* its our chance to print info about boot device */
  598. void spl_board_init(void)
  599. {
  600. /* determine boot device from SRC_SBMR1 (BOOT_CFG[4:1]) or SRC_GPR9 */
  601. u32 boot_device = spl_boot_device();
  602. switch (boot_device) {
  603. case BOOT_DEVICE_MMC1:
  604. puts("Booting from MMC\n");
  605. break;
  606. case BOOT_DEVICE_NAND:
  607. puts("Booting from NAND\n");
  608. break;
  609. case BOOT_DEVICE_SATA:
  610. puts("Booting from SATA\n");
  611. break;
  612. default:
  613. puts("Unknown boot device\n");
  614. }
  615. /* PMIC init */
  616. setup_pmic();
  617. }
  618. #ifdef CONFIG_SPL_OS_BOOT
  619. /* return 1 if we wish to boot to uboot vs os (falcon mode) */
  620. int spl_start_uboot(void)
  621. {
  622. unsigned char ret = 1;
  623. debug("%s\n", __func__);
  624. #ifdef CONFIG_SPL_ENV_SUPPORT
  625. env_init();
  626. env_load();
  627. debug("boot_os=%s\n", env_get("boot_os"));
  628. if (env_get_yesno("boot_os") == 1)
  629. ret = 0;
  630. #else
  631. /* use i2c-0:0x50:0x00 for falcon boot mode (0=linux, else uboot) */
  632. i2c_set_bus_num(0);
  633. gsc_i2c_read(0x50, 0x0, 1, &ret, 1);
  634. #endif
  635. if (!ret)
  636. gsc_boot_wd_disable();
  637. debug("%s booting %s\n", __func__, ret ? "uboot" : "linux");
  638. return ret;
  639. }
  640. #endif