gw_ventana_spl.c 20 KB

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