ddr_rk3368.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. /*
  2. * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <stdint.h>
  7. #include <string.h>
  8. #include <platform_def.h>
  9. #include <common/debug.h>
  10. #include <lib/mmio.h>
  11. #include <ddr_rk3368.h>
  12. #include <pmu.h>
  13. #include <rk3368_def.h>
  14. #include <soc.h>
  15. /* GRF_SOC_STATUS0 */
  16. #define DPLL_LOCK (0x1 << 2)
  17. /* GRF_DDRC0_CON0 */
  18. #define GRF_DDR_16BIT_EN (((0x1 << 3) << 16) | (0x1 << 3))
  19. #define GRF_DDR_32BIT_EN (((0x1 << 3) << 16) | (0x0 << 3))
  20. #define GRF_MOBILE_DDR_EN (((0x1 << 4) << 16) | (0x1 << 4))
  21. #define GRF_MOBILE_DDR_DISB (((0x1 << 4) << 16) | (0x0 << 4))
  22. #define GRF_DDR3_EN (((0x1 << 2) << 16) | (0x1 << 2))
  23. #define GRF_LPDDR2_3_EN (((0x1 << 2) << 16) | (0x0 << 2))
  24. /* PMUGRF_SOC_CON0 */
  25. #define ddrphy_bufferen_io_en(n) ((0x1 << (9 + 16)) | (n << 9))
  26. #define ddrphy_bufferen_core_en(n) ((0x1 << (8 + 16)) | (n << 8))
  27. struct PCTRL_TIMING_TAG {
  28. uint32_t ddrfreq;
  29. uint32_t TOGCNT1U;
  30. uint32_t TINIT;
  31. uint32_t TRSTH;
  32. uint32_t TOGCNT100N;
  33. uint32_t TREFI;
  34. uint32_t TMRD;
  35. uint32_t TRFC;
  36. uint32_t TRP;
  37. uint32_t TRTW;
  38. uint32_t TAL;
  39. uint32_t TCL;
  40. uint32_t TCWL;
  41. uint32_t TRAS;
  42. uint32_t TRC;
  43. uint32_t TRCD;
  44. uint32_t TRRD;
  45. uint32_t TRTP;
  46. uint32_t TWR;
  47. uint32_t TWTR;
  48. uint32_t TEXSR;
  49. uint32_t TXP;
  50. uint32_t TXPDLL;
  51. uint32_t TZQCS;
  52. uint32_t TZQCSI;
  53. uint32_t TDQS;
  54. uint32_t TCKSRE;
  55. uint32_t TCKSRX;
  56. uint32_t TCKE;
  57. uint32_t TMOD;
  58. uint32_t TRSTL;
  59. uint32_t TZQCL;
  60. uint32_t TMRR;
  61. uint32_t TCKESR;
  62. uint32_t TDPD;
  63. uint32_t TREFI_MEM_DDR3;
  64. };
  65. struct MSCH_SAVE_REG_TAG {
  66. uint32_t ddrconf;
  67. uint32_t ddrtiming;
  68. uint32_t ddrmode;
  69. uint32_t readlatency;
  70. uint32_t activate;
  71. uint32_t devtodev;
  72. };
  73. /* ddr suspend need save reg */
  74. struct PCTL_SAVE_REG_TAG {
  75. uint32_t SCFG;
  76. uint32_t CMDTSTATEN;
  77. uint32_t MCFG1;
  78. uint32_t MCFG;
  79. uint32_t PPCFG;
  80. struct PCTRL_TIMING_TAG pctl_timing;
  81. /* DFI Control Registers */
  82. uint32_t DFITCTRLDELAY;
  83. uint32_t DFIODTCFG;
  84. uint32_t DFIODTCFG1;
  85. uint32_t DFIODTRANKMAP;
  86. /* DFI Write Data Registers */
  87. uint32_t DFITPHYWRDATA;
  88. uint32_t DFITPHYWRLAT;
  89. uint32_t DFITPHYWRDATALAT;
  90. /* DFI Read Data Registers */
  91. uint32_t DFITRDDATAEN;
  92. uint32_t DFITPHYRDLAT;
  93. /* DFI Update Registers */
  94. uint32_t DFITPHYUPDTYPE0;
  95. uint32_t DFITPHYUPDTYPE1;
  96. uint32_t DFITPHYUPDTYPE2;
  97. uint32_t DFITPHYUPDTYPE3;
  98. uint32_t DFITCTRLUPDMIN;
  99. uint32_t DFITCTRLUPDMAX;
  100. uint32_t DFITCTRLUPDDLY;
  101. uint32_t DFIUPDCFG;
  102. uint32_t DFITREFMSKI;
  103. uint32_t DFITCTRLUPDI;
  104. /* DFI Status Registers */
  105. uint32_t DFISTCFG0;
  106. uint32_t DFISTCFG1;
  107. uint32_t DFITDRAMCLKEN;
  108. uint32_t DFITDRAMCLKDIS;
  109. uint32_t DFISTCFG2;
  110. /* DFI Low Power Register */
  111. uint32_t DFILPCFG0;
  112. };
  113. struct DDRPHY_SAVE_REG_TAG {
  114. uint32_t PHY_REG0;
  115. uint32_t PHY_REG1;
  116. uint32_t PHY_REGB;
  117. uint32_t PHY_REGC;
  118. uint32_t PHY_REG11;
  119. uint32_t PHY_REG13;
  120. uint32_t PHY_REG14;
  121. uint32_t PHY_REG16;
  122. uint32_t PHY_REG20;
  123. uint32_t PHY_REG21;
  124. uint32_t PHY_REG26;
  125. uint32_t PHY_REG27;
  126. uint32_t PHY_REG28;
  127. uint32_t PHY_REG30;
  128. uint32_t PHY_REG31;
  129. uint32_t PHY_REG36;
  130. uint32_t PHY_REG37;
  131. uint32_t PHY_REG38;
  132. uint32_t PHY_REG40;
  133. uint32_t PHY_REG41;
  134. uint32_t PHY_REG46;
  135. uint32_t PHY_REG47;
  136. uint32_t PHY_REG48;
  137. uint32_t PHY_REG50;
  138. uint32_t PHY_REG51;
  139. uint32_t PHY_REG56;
  140. uint32_t PHY_REG57;
  141. uint32_t PHY_REG58;
  142. uint32_t PHY_REGDLL;
  143. uint32_t PHY_REGEC;
  144. uint32_t PHY_REGED;
  145. uint32_t PHY_REGEE;
  146. uint32_t PHY_REGEF;
  147. uint32_t PHY_REGFB;
  148. uint32_t PHY_REGFC;
  149. uint32_t PHY_REGFD;
  150. uint32_t PHY_REGFE;
  151. };
  152. struct BACKUP_REG_TAG {
  153. uint32_t tag;
  154. uint32_t pctladdr;
  155. struct PCTL_SAVE_REG_TAG pctl;
  156. uint32_t phyaddr;
  157. struct DDRPHY_SAVE_REG_TAG phy;
  158. uint32_t nocaddr;
  159. struct MSCH_SAVE_REG_TAG noc;
  160. uint32_t pllselect;
  161. uint32_t phypllockaddr;
  162. uint32_t phyplllockmask;
  163. uint32_t phyplllockval;
  164. uint32_t pllpdstat;
  165. uint32_t dpllmodeaddr;
  166. uint32_t dpllslowmode;
  167. uint32_t dpllnormalmode;
  168. uint32_t dpllresetaddr;
  169. uint32_t dpllreset;
  170. uint32_t dplldereset;
  171. uint32_t dpllconaddr;
  172. uint32_t dpllcon[4];
  173. uint32_t dplllockaddr;
  174. uint32_t dplllockmask;
  175. uint32_t dplllockval;
  176. uint32_t ddrpllsrcdivaddr;
  177. uint32_t ddrpllsrcdiv;
  178. uint32_t retendisaddr;
  179. uint32_t retendisval;
  180. uint32_t grfregaddr;
  181. uint32_t grfddrcreg;
  182. uint32_t crupctlphysoftrstaddr;
  183. uint32_t cruresetpctlphy;
  184. uint32_t cruderesetphy;
  185. uint32_t cruderesetpctlphy;
  186. uint32_t physoftrstaddr;
  187. uint32_t endtag;
  188. };
  189. static uint32_t ddr_get_phy_pll_freq(void)
  190. {
  191. uint32_t ret = 0;
  192. uint32_t fb_div, pre_div;
  193. fb_div = mmio_read_32(DDR_PHY_BASE + DDR_PHY_REGEC);
  194. fb_div |= (mmio_read_32(DDR_PHY_BASE + DDR_PHY_REGED) & 0x1) << 8;
  195. pre_div = mmio_read_32(DDR_PHY_BASE + DDR_PHY_REGEE) & 0xff;
  196. ret = 2 * 24 * fb_div / (4 * pre_div);
  197. return ret;
  198. }
  199. static void ddr_copy(uint32_t *pdest, uint32_t *psrc, uint32_t words)
  200. {
  201. uint32_t i;
  202. for (i = 0; i < words; i++)
  203. pdest[i] = psrc[i];
  204. }
  205. static void ddr_get_dpll_cfg(uint32_t *p)
  206. {
  207. uint32_t nmhz, NO, NF, NR;
  208. nmhz = ddr_get_phy_pll_freq();
  209. if (nmhz <= 150)
  210. NO = 6;
  211. else if (nmhz <= 250)
  212. NO = 4;
  213. else if (nmhz <= 500)
  214. NO = 2;
  215. else
  216. NO = 1;
  217. NR = 1;
  218. NF = 2 * nmhz * NR * NO / 24;
  219. p[0] = SET_NR(NR) | SET_NO(NO);
  220. p[1] = SET_NF(NF);
  221. p[2] = SET_NB(NF / 2);
  222. }
  223. void ddr_reg_save(uint32_t pllpdstat, uint64_t base_addr)
  224. {
  225. struct BACKUP_REG_TAG *p_ddr_reg = (struct BACKUP_REG_TAG *)base_addr;
  226. struct PCTL_SAVE_REG_TAG *pctl_tim = &p_ddr_reg->pctl;
  227. p_ddr_reg->tag = 0x56313031;
  228. p_ddr_reg->pctladdr = DDR_PCTL_BASE;
  229. p_ddr_reg->phyaddr = DDR_PHY_BASE;
  230. p_ddr_reg->nocaddr = SERVICE_BUS_BASE;
  231. /* PCTLR */
  232. ddr_copy((uint32_t *)&pctl_tim->pctl_timing.TOGCNT1U,
  233. (uint32_t *)(DDR_PCTL_BASE + DDR_PCTL_TOGCNT1U), 35);
  234. pctl_tim->pctl_timing.TREFI |= DDR_UPD_REF_ENABLE;
  235. pctl_tim->SCFG = mmio_read_32(DDR_PCTL_BASE + DDR_PCTL_SCFG);
  236. pctl_tim->CMDTSTATEN = mmio_read_32(DDR_PCTL_BASE +
  237. DDR_PCTL_CMDTSTATEN);
  238. pctl_tim->MCFG1 = mmio_read_32(DDR_PCTL_BASE + DDR_PCTL_MCFG1);
  239. pctl_tim->MCFG = mmio_read_32(DDR_PCTL_BASE + DDR_PCTL_MCFG);
  240. pctl_tim->PPCFG = mmio_read_32(DDR_PCTL_BASE + DDR_PCTL_PPCFG);
  241. pctl_tim->pctl_timing.ddrfreq = mmio_read_32(DDR_PCTL_BASE +
  242. DDR_PCTL_TOGCNT1U * 2);
  243. pctl_tim->DFITCTRLDELAY = mmio_read_32(DDR_PCTL_BASE +
  244. DDR_PCTL_DFITCTRLDELAY);
  245. pctl_tim->DFIODTCFG = mmio_read_32(DDR_PCTL_BASE + DDR_PCTL_DFIODTCFG);
  246. pctl_tim->DFIODTCFG1 = mmio_read_32(DDR_PCTL_BASE +
  247. DDR_PCTL_DFIODTCFG1);
  248. pctl_tim->DFIODTRANKMAP = mmio_read_32(DDR_PCTL_BASE +
  249. DDR_PCTL_DFIODTRANKMAP);
  250. pctl_tim->DFITPHYWRDATA = mmio_read_32(DDR_PCTL_BASE +
  251. DDR_PCTL_DFITPHYWRDATA);
  252. pctl_tim->DFITPHYWRLAT = mmio_read_32(DDR_PCTL_BASE +
  253. DDR_PCTL_DFITPHYWRLAT);
  254. pctl_tim->DFITPHYWRDATALAT = mmio_read_32(DDR_PCTL_BASE +
  255. DDR_PCTL_DFITPHYWRDATALAT);
  256. pctl_tim->DFITRDDATAEN = mmio_read_32(DDR_PCTL_BASE +
  257. DDR_PCTL_DFITRDDATAEN);
  258. pctl_tim->DFITPHYRDLAT = mmio_read_32(DDR_PCTL_BASE +
  259. DDR_PCTL_DFITPHYRDLAT);
  260. pctl_tim->DFITPHYUPDTYPE0 = mmio_read_32(DDR_PCTL_BASE +
  261. DDR_PCTL_DFITPHYUPDTYPE0);
  262. pctl_tim->DFITPHYUPDTYPE1 = mmio_read_32(DDR_PCTL_BASE +
  263. DDR_PCTL_DFITPHYUPDTYPE1);
  264. pctl_tim->DFITPHYUPDTYPE2 = mmio_read_32(DDR_PCTL_BASE +
  265. DDR_PCTL_DFITPHYUPDTYPE2);
  266. pctl_tim->DFITPHYUPDTYPE3 = mmio_read_32(DDR_PCTL_BASE +
  267. DDR_PCTL_DFITPHYUPDTYPE3);
  268. pctl_tim->DFITCTRLUPDMIN = mmio_read_32(DDR_PCTL_BASE +
  269. DDR_PCTL_DFITCTRLUPDMIN);
  270. pctl_tim->DFITCTRLUPDMAX = mmio_read_32(DDR_PCTL_BASE +
  271. DDR_PCTL_DFITCTRLUPDMAX);
  272. pctl_tim->DFITCTRLUPDDLY = mmio_read_32(DDR_PCTL_BASE +
  273. DDR_PCTL_DFITCTRLUPDDLY);
  274. pctl_tim->DFIUPDCFG = mmio_read_32(DDR_PCTL_BASE + DDR_PCTL_DFIUPDCFG);
  275. pctl_tim->DFITREFMSKI = mmio_read_32(DDR_PCTL_BASE +
  276. DDR_PCTL_DFITREFMSKI);
  277. pctl_tim->DFITCTRLUPDI = mmio_read_32(DDR_PCTL_BASE +
  278. DDR_PCTL_DFITCTRLUPDI);
  279. pctl_tim->DFISTCFG0 = mmio_read_32(DDR_PCTL_BASE + DDR_PCTL_DFISTCFG0);
  280. pctl_tim->DFISTCFG1 = mmio_read_32(DDR_PCTL_BASE + DDR_PCTL_DFISTCFG1);
  281. pctl_tim->DFITDRAMCLKEN = mmio_read_32(DDR_PCTL_BASE +
  282. DDR_PCTL_DFITDRAMCLKEN);
  283. pctl_tim->DFITDRAMCLKDIS = mmio_read_32(DDR_PCTL_BASE +
  284. DDR_PCTL_DFITDRAMCLKDIS);
  285. pctl_tim->DFISTCFG2 = mmio_read_32(DDR_PCTL_BASE + DDR_PCTL_DFISTCFG2);
  286. pctl_tim->DFILPCFG0 = mmio_read_32(DDR_PCTL_BASE + DDR_PCTL_DFILPCFG0);
  287. /* PHY */
  288. p_ddr_reg->phy.PHY_REG0 = mmio_read_32(DDR_PHY_BASE + DDR_PHY_REG0);
  289. p_ddr_reg->phy.PHY_REG1 = mmio_read_32(DDR_PHY_BASE + DDR_PHY_REG1);
  290. p_ddr_reg->phy.PHY_REGB = mmio_read_32(DDR_PHY_BASE + DDR_PHY_REGB);
  291. p_ddr_reg->phy.PHY_REGC = mmio_read_32(DDR_PHY_BASE + DDR_PHY_REGC);
  292. p_ddr_reg->phy.PHY_REG11 = mmio_read_32(DDR_PHY_BASE + DDR_PHY_REG11);
  293. p_ddr_reg->phy.PHY_REG13 = mmio_read_32(DDR_PHY_BASE + DDR_PHY_REG13);
  294. p_ddr_reg->phy.PHY_REG14 = mmio_read_32(DDR_PHY_BASE + DDR_PHY_REG14);
  295. p_ddr_reg->phy.PHY_REG16 = mmio_read_32(DDR_PHY_BASE + DDR_PHY_REG16);
  296. p_ddr_reg->phy.PHY_REG20 = mmio_read_32(DDR_PHY_BASE + DDR_PHY_REG20);
  297. p_ddr_reg->phy.PHY_REG21 = mmio_read_32(DDR_PHY_BASE + DDR_PHY_REG21);
  298. p_ddr_reg->phy.PHY_REG26 = mmio_read_32(DDR_PHY_BASE + DDR_PHY_REG26);
  299. p_ddr_reg->phy.PHY_REG27 = mmio_read_32(DDR_PHY_BASE + DDR_PHY_REG27);
  300. p_ddr_reg->phy.PHY_REG28 = mmio_read_32(DDR_PHY_BASE + DDR_PHY_REG28);
  301. p_ddr_reg->phy.PHY_REG30 = mmio_read_32(DDR_PHY_BASE + DDR_PHY_REG30);
  302. p_ddr_reg->phy.PHY_REG31 = mmio_read_32(DDR_PHY_BASE + DDR_PHY_REG31);
  303. p_ddr_reg->phy.PHY_REG36 = mmio_read_32(DDR_PHY_BASE + DDR_PHY_REG36);
  304. p_ddr_reg->phy.PHY_REG37 = mmio_read_32(DDR_PHY_BASE + DDR_PHY_REG37);
  305. p_ddr_reg->phy.PHY_REG38 = mmio_read_32(DDR_PHY_BASE + DDR_PHY_REG38);
  306. p_ddr_reg->phy.PHY_REG40 = mmio_read_32(DDR_PHY_BASE + DDR_PHY_REG40);
  307. p_ddr_reg->phy.PHY_REG41 = mmio_read_32(DDR_PHY_BASE + DDR_PHY_REG41);
  308. p_ddr_reg->phy.PHY_REG46 = mmio_read_32(DDR_PHY_BASE + DDR_PHY_REG46);
  309. p_ddr_reg->phy.PHY_REG47 = mmio_read_32(DDR_PHY_BASE + DDR_PHY_REG47);
  310. p_ddr_reg->phy.PHY_REG48 = mmio_read_32(DDR_PHY_BASE + DDR_PHY_REG48);
  311. p_ddr_reg->phy.PHY_REG50 = mmio_read_32(DDR_PHY_BASE + DDR_PHY_REG50);
  312. p_ddr_reg->phy.PHY_REG51 = mmio_read_32(DDR_PHY_BASE + DDR_PHY_REG51);
  313. p_ddr_reg->phy.PHY_REG56 = mmio_read_32(DDR_PHY_BASE + DDR_PHY_REG56);
  314. p_ddr_reg->phy.PHY_REG57 = mmio_read_32(DDR_PHY_BASE + DDR_PHY_REG57);
  315. p_ddr_reg->phy.PHY_REG58 = mmio_read_32(DDR_PHY_BASE + DDR_PHY_REG58);
  316. p_ddr_reg->phy.PHY_REGDLL = mmio_read_32(DDR_PHY_BASE +
  317. DDR_PHY_REGDLL);
  318. p_ddr_reg->phy.PHY_REGEC = mmio_read_32(DDR_PHY_BASE + DDR_PHY_REGEC);
  319. p_ddr_reg->phy.PHY_REGED = mmio_read_32(DDR_PHY_BASE + DDR_PHY_REGED);
  320. p_ddr_reg->phy.PHY_REGEE = mmio_read_32(DDR_PHY_BASE + DDR_PHY_REGEE);
  321. p_ddr_reg->phy.PHY_REGEF = 0;
  322. if (mmio_read_32(DDR_PHY_BASE + DDR_PHY_REG2) & 0x2) {
  323. p_ddr_reg->phy.PHY_REGFB = mmio_read_32(DDR_PHY_BASE +
  324. DDR_PHY_REG2C);
  325. p_ddr_reg->phy.PHY_REGFC = mmio_read_32(DDR_PHY_BASE +
  326. DDR_PHY_REG3C);
  327. p_ddr_reg->phy.PHY_REGFD = mmio_read_32(DDR_PHY_BASE +
  328. DDR_PHY_REG4C);
  329. p_ddr_reg->phy.PHY_REGFE = mmio_read_32(DDR_PHY_BASE +
  330. DDR_PHY_REG5C);
  331. } else {
  332. p_ddr_reg->phy.PHY_REGFB = mmio_read_32(DDR_PHY_BASE +
  333. DDR_PHY_REGFB);
  334. p_ddr_reg->phy.PHY_REGFC = mmio_read_32(DDR_PHY_BASE +
  335. DDR_PHY_REGFC);
  336. p_ddr_reg->phy.PHY_REGFD = mmio_read_32(DDR_PHY_BASE +
  337. DDR_PHY_REGFD);
  338. p_ddr_reg->phy.PHY_REGFE = mmio_read_32(DDR_PHY_BASE +
  339. DDR_PHY_REGFE);
  340. }
  341. /* NOC */
  342. p_ddr_reg->noc.ddrconf = mmio_read_32(SERVICE_BUS_BASE + MSCH_DDRCONF);
  343. p_ddr_reg->noc.ddrtiming = mmio_read_32(SERVICE_BUS_BASE +
  344. MSCH_DDRTIMING);
  345. p_ddr_reg->noc.ddrmode = mmio_read_32(SERVICE_BUS_BASE + MSCH_DDRMODE);
  346. p_ddr_reg->noc.readlatency = mmio_read_32(SERVICE_BUS_BASE +
  347. MSCH_READLATENCY);
  348. p_ddr_reg->noc.activate = mmio_read_32(SERVICE_BUS_BASE +
  349. MSCH_ACTIVATE);
  350. p_ddr_reg->noc.devtodev = mmio_read_32(SERVICE_BUS_BASE +
  351. MSCH_DEVTODEV);
  352. p_ddr_reg->pllselect = mmio_read_32(DDR_PHY_BASE + DDR_PHY_REGEE) * 0x1;
  353. p_ddr_reg->phypllockaddr = GRF_BASE + GRF_SOC_STATUS0;
  354. p_ddr_reg->phyplllockmask = GRF_DDRPHY_LOCK;
  355. p_ddr_reg->phyplllockval = 0;
  356. /* PLLPD */
  357. p_ddr_reg->pllpdstat = pllpdstat;
  358. /* DPLL */
  359. p_ddr_reg->dpllmodeaddr = CRU_BASE + PLL_CONS(DPLL_ID, 3);
  360. /* slow mode and power on */
  361. p_ddr_reg->dpllslowmode = DPLL_WORK_SLOW_MODE | DPLL_POWER_DOWN;
  362. p_ddr_reg->dpllnormalmode = DPLL_WORK_NORMAL_MODE;
  363. p_ddr_reg->dpllresetaddr = CRU_BASE + PLL_CONS(DPLL_ID, 3);
  364. p_ddr_reg->dpllreset = DPLL_RESET_CONTROL_NORMAL;
  365. p_ddr_reg->dplldereset = DPLL_RESET_CONTROL_RESET;
  366. p_ddr_reg->dpllconaddr = CRU_BASE + PLL_CONS(DPLL_ID, 0);
  367. if (p_ddr_reg->pllselect == 0) {
  368. p_ddr_reg->dpllcon[0] = (mmio_read_32(CRU_BASE +
  369. PLL_CONS(DPLL_ID, 0))
  370. & 0xffff) |
  371. (0xFFFFu << 16);
  372. p_ddr_reg->dpllcon[1] = (mmio_read_32(CRU_BASE +
  373. PLL_CONS(DPLL_ID, 1))
  374. & 0xffff);
  375. p_ddr_reg->dpllcon[2] = (mmio_read_32(CRU_BASE +
  376. PLL_CONS(DPLL_ID, 2))
  377. & 0xffff);
  378. p_ddr_reg->dpllcon[3] = (mmio_read_32(CRU_BASE +
  379. PLL_CONS(DPLL_ID, 3))
  380. & 0xffff) |
  381. (0xFFFFu << 16);
  382. } else {
  383. ddr_get_dpll_cfg(&p_ddr_reg->dpllcon[0]);
  384. }
  385. p_ddr_reg->pllselect = 0;
  386. p_ddr_reg->dplllockaddr = CRU_BASE + PLL_CONS(DPLL_ID, 1);
  387. p_ddr_reg->dplllockmask = DPLL_STATUS_LOCK;
  388. p_ddr_reg->dplllockval = DPLL_STATUS_LOCK;
  389. /* SET_DDR_PLL_SRC */
  390. p_ddr_reg->ddrpllsrcdivaddr = CRU_BASE + CRU_CLKSELS_CON(13);
  391. p_ddr_reg->ddrpllsrcdiv = (mmio_read_32(CRU_BASE + CRU_CLKSELS_CON(13))
  392. & DDR_PLL_SRC_MASK)
  393. | (DDR_PLL_SRC_MASK << 16);
  394. p_ddr_reg->retendisaddr = PMU_BASE + PMU_PWRMD_COM;
  395. p_ddr_reg->retendisval = PD_PERI_PWRDN_ENABLE;
  396. p_ddr_reg->grfregaddr = GRF_BASE + GRF_DDRC0_CON0;
  397. p_ddr_reg->grfddrcreg = (mmio_read_32(GRF_BASE + GRF_DDRC0_CON0) &
  398. DDR_PLL_SRC_MASK) |
  399. (DDR_PLL_SRC_MASK << 16);
  400. /* pctl phy soft reset */
  401. p_ddr_reg->crupctlphysoftrstaddr = CRU_BASE + CRU_SOFTRSTS_CON(10);
  402. p_ddr_reg->cruresetpctlphy = DDRCTRL0_PSRSTN_REQ(1) |
  403. DDRCTRL0_SRSTN_REQ(1) |
  404. DDRPHY0_PSRSTN_REQ(1) |
  405. DDRPHY0_SRSTN_REQ(1);
  406. p_ddr_reg->cruderesetphy = DDRCTRL0_PSRSTN_REQ(1) |
  407. DDRCTRL0_SRSTN_REQ(1) |
  408. DDRPHY0_PSRSTN_REQ(0) |
  409. DDRPHY0_SRSTN_REQ(0);
  410. p_ddr_reg->cruderesetpctlphy = DDRCTRL0_PSRSTN_REQ(0) |
  411. DDRCTRL0_SRSTN_REQ(0) |
  412. DDRPHY0_PSRSTN_REQ(0) |
  413. DDRPHY0_SRSTN_REQ(0);
  414. p_ddr_reg->physoftrstaddr = DDR_PHY_BASE + DDR_PHY_REG0;
  415. p_ddr_reg->endtag = 0xFFFFFFFF;
  416. }
  417. /*
  418. * "rk3368_ddr_reg_resume_V1.05.bin" is an executable bin which is generated
  419. * by ARM DS5 for resuming ddr controller. If the soc wakes up from system
  420. * suspend, ddr needs to be resumed and the resuming code needs to be run in
  421. * sram. But there is not a way to pointing the resuming code to the PMUSRAM
  422. * when linking .o files of bl31, so we use the
  423. * "rk3368_ddr_reg_resume_V1.05.bin" whose code is position-independent and
  424. * it can be loaded anywhere and run.
  425. */
  426. static __aligned(4) unsigned int ddr_reg_resume[] = {
  427. #include "rk3368_ddr_reg_resume_V1.05.bin"
  428. };
  429. uint32_t ddr_get_resume_code_size(void)
  430. {
  431. return sizeof(ddr_reg_resume);
  432. }
  433. uint32_t ddr_get_resume_data_size(void)
  434. {
  435. return sizeof(struct BACKUP_REG_TAG);
  436. }
  437. uint32_t *ddr_get_resume_code_base(void)
  438. {
  439. return (unsigned int *)ddr_reg_resume;
  440. }