0016-haswell-NRI-Add-DDR3-JEDEC-reset-and-init.patch 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039
  1. From d24def01ec15f41a48331ef1e236270b2df90b84 Mon Sep 17 00:00:00 2001
  2. From: Angel Pons <th3fanbus@gmail.com>
  3. Date: Sat, 7 May 2022 21:49:40 +0200
  4. Subject: [PATCH 16/26] haswell NRI: Add DDR3 JEDEC reset and init
  5. Implement JEDEC reset and init sequence for DDR3. The MRS commands are
  6. issued through the REUT (Robust Electrical Unified Testing) hardware.
  7. Change-Id: I2a0c066537021b587599228086727cb1e041bff5
  8. Signed-off-by: Angel Pons <th3fanbus@gmail.com>
  9. ---
  10. .../intel/haswell/native_raminit/Makefile.inc | 3 +
  11. .../intel/haswell/native_raminit/ddr3.c | 217 ++++++++++++++++++
  12. .../haswell/native_raminit/io_comp_control.c | 19 ++
  13. .../haswell/native_raminit/jedec_reset.c | 120 ++++++++++
  14. .../haswell/native_raminit/raminit_main.c | 2 +
  15. .../haswell/native_raminit/raminit_native.h | 101 ++++++++
  16. .../haswell/native_raminit/reg_structs.h | 154 +++++++++++++
  17. .../intel/haswell/native_raminit/reut.c | 196 ++++++++++++++++
  18. .../intel/haswell/registers/mchbar.h | 21 ++
  19. src/southbridge/intel/lynxpoint/pch.h | 2 +
  20. 10 files changed, 835 insertions(+)
  21. create mode 100644 src/northbridge/intel/haswell/native_raminit/ddr3.c
  22. create mode 100644 src/northbridge/intel/haswell/native_raminit/jedec_reset.c
  23. create mode 100644 src/northbridge/intel/haswell/native_raminit/reut.c
  24. diff --git a/src/northbridge/intel/haswell/native_raminit/Makefile.inc b/src/northbridge/intel/haswell/native_raminit/Makefile.inc
  25. index 37d527e972..e9212df9e6 100644
  26. --- a/src/northbridge/intel/haswell/native_raminit/Makefile.inc
  27. +++ b/src/northbridge/intel/haswell/native_raminit/Makefile.inc
  28. @@ -1,11 +1,14 @@
  29. ## SPDX-License-Identifier: GPL-2.0-or-later
  30. romstage-y += configure_mc.c
  31. +romstage-y += ddr3.c
  32. +romstage-y += jedec_reset.c
  33. romstage-y += lookup_timings.c
  34. romstage-y += init_mpll.c
  35. romstage-y += io_comp_control.c
  36. romstage-y += memory_map.c
  37. romstage-y += raminit_main.c
  38. romstage-y += raminit_native.c
  39. +romstage-y += reut.c
  40. romstage-y += spd_bitmunching.c
  41. romstage-y += timings_refresh.c
  42. diff --git a/src/northbridge/intel/haswell/native_raminit/ddr3.c b/src/northbridge/intel/haswell/native_raminit/ddr3.c
  43. new file mode 100644
  44. index 0000000000..6ddb11488b
  45. --- /dev/null
  46. +++ b/src/northbridge/intel/haswell/native_raminit/ddr3.c
  47. @@ -0,0 +1,217 @@
  48. +/* SPDX-License-Identifier: GPL-2.0-or-later */
  49. +
  50. +#include <assert.h>
  51. +#include <console/console.h>
  52. +#include <northbridge/intel/haswell/haswell.h>
  53. +#include <types.h>
  54. +
  55. +#include "raminit_native.h"
  56. +
  57. +#define DDR3_RTTNOM(a, b, c) (((a) << 9) | ((b) << 6) | ((c) << 2))
  58. +
  59. +uint16_t encode_ddr3_rttnom(const uint32_t rttnom)
  60. +{
  61. + switch (rttnom) {
  62. + case 0: return DDR3_RTTNOM(0, 0, 0); /* RttNom is disabled */
  63. + case 20: return DDR3_RTTNOM(1, 0, 0); /* RZQ/12 */
  64. + case 30: return DDR3_RTTNOM(1, 0, 1); /* RZQ/8 */
  65. + case 40: return DDR3_RTTNOM(0, 1, 1); /* RZQ/6 */
  66. + case 60: return DDR3_RTTNOM(0, 0, 1); /* RZQ/4 */
  67. + case 120: return DDR3_RTTNOM(0, 1, 0); /* RZQ/2 */
  68. + }
  69. + printk(BIOS_ERR, "%s: Invalid rtt_nom value %u\n", __func__, rttnom);
  70. + return 0;
  71. +}
  72. +
  73. +static const uint8_t jedec_wr_t[12] = { 1, 2, 3, 4, 5, 5, 6, 6, 7, 7, 0, 0 };
  74. +
  75. +static void ddr3_program_mr0(struct sysinfo *ctrl, const uint8_t dll_reset)
  76. +{
  77. + assert(ctrl->tWR >= 5 && ctrl->tWR <= 16);
  78. + assert(ctrl->tAA >= 4);
  79. + const uint8_t jedec_cas = ctrl->tAA - 4;
  80. + const union {
  81. + struct __packed {
  82. + uint16_t burst_length : 2; // Bits 1:0
  83. + uint16_t cas_latency_msb : 1; // Bits 2:2
  84. + uint16_t read_burst_type : 1; // Bits 3:3
  85. + uint16_t cas_latency_low : 3; // Bits 6:4
  86. + uint16_t test_mode : 1; // Bits 7:7
  87. + uint16_t dll_reset : 1; // Bits 8:8
  88. + uint16_t write_recovery : 3; // Bits 11:9
  89. + uint16_t precharge_pd_dll : 1; // Bits 12:12
  90. + uint16_t : 3; // Bits 15:13
  91. + };
  92. + uint16_t raw;
  93. + } mr0reg = {
  94. + .burst_length = 0,
  95. + .cas_latency_msb = !!(jedec_cas & BIT(3)),
  96. + .read_burst_type = 0,
  97. + .cas_latency_low = jedec_cas & 0x7,
  98. + .dll_reset = 1,
  99. + .write_recovery = jedec_wr_t[ctrl->tWR - 5],
  100. + .precharge_pd_dll = 0,
  101. + };
  102. + for (uint8_t channel = 0; channel < NUM_CHANNELS; channel++) {
  103. + if (!does_ch_exist(ctrl, channel))
  104. + continue;
  105. +
  106. + for (uint8_t slot = 0; slot < NUM_SLOTS; slot++) {
  107. + if (!rank_in_ch(ctrl, slot + slot, channel))
  108. + continue;
  109. +
  110. + if (!ctrl->restore_mrs)
  111. + ctrl->mr0[channel][slot] = mr0reg.raw;
  112. + }
  113. + reut_issue_mrs_all(ctrl, channel, 0, ctrl->mr0[channel]);
  114. + }
  115. +}
  116. +
  117. +void ddr3_program_mr1(struct sysinfo *ctrl, const uint8_t wl_mode, const uint8_t q_off)
  118. +{
  119. + /*
  120. + * JESD79-3F (JEDEC DDR3 spec) refers to bit 0 of MR1 as 'DLL Enable'.
  121. + * However, its encoding is weird, and 'DLL Disable' makes more sense.
  122. + *
  123. + * Moreover, bit 5 is part of ODIC (Output Driver Impedance Control),
  124. + * but all encodings where MR1 bit 5 is 1 are reserved. Thus, omit it.
  125. + */
  126. + union {
  127. + struct __packed {
  128. + uint16_t dll_disable : 1; // Bits 0:0
  129. + uint16_t od_impedance_ctl : 1; // Bits 1:1
  130. + uint16_t odt_rtt_nom_low : 1; // Bits 2:2
  131. + uint16_t additive_latency : 2; // Bits 4:3
  132. + uint16_t : 1; // Bits 5:5
  133. + uint16_t odt_rtt_nom_mid : 1; // Bits 6:6
  134. + uint16_t write_level_mode : 1; // Bits 7:7
  135. + uint16_t : 1; // Bits 8:8
  136. + uint16_t odt_rtt_nom_high : 1; // Bits 9:9
  137. + uint16_t : 1; // Bits 10:10
  138. + uint16_t t_dqs : 1; // Bits 11:11
  139. + uint16_t q_off : 1; // Bits 12:12
  140. + uint16_t : 3; // Bits 15:13
  141. + };
  142. + uint16_t raw;
  143. + } mr1reg = {
  144. + .dll_disable = 0,
  145. + .od_impedance_ctl = 1, /* RZQ/7 */
  146. + .additive_latency = 0,
  147. + .write_level_mode = wl_mode,
  148. + .t_dqs = 0,
  149. + .q_off = q_off,
  150. + };
  151. + for (uint8_t channel = 0; channel < NUM_CHANNELS; channel++) {
  152. + if (!does_ch_exist(ctrl, channel))
  153. + continue;
  154. +
  155. + mr1reg.raw &= ~RTTNOM_MASK;
  156. + mr1reg.raw |= encode_ddr3_rttnom(ctrl->dpc[channel] == 2 ? 60 : 0);
  157. + for (uint8_t slot = 0; slot < NUM_SLOTS; slot++) {
  158. + if (!rank_in_ch(ctrl, slot + slot, channel))
  159. + continue;
  160. +
  161. + if (!ctrl->restore_mrs)
  162. + ctrl->mr1[channel][slot] = mr1reg.raw;
  163. + }
  164. + reut_issue_mrs_all(ctrl, channel, 1, ctrl->mr1[channel]);
  165. + }
  166. +}
  167. +
  168. +enum {
  169. + RTT_WR_OFF = 0,
  170. + RTT_WR_60 = 1,
  171. + RTT_WR_120 = 2,
  172. +};
  173. +
  174. +static void ddr3_program_mr2(struct sysinfo *ctrl)
  175. +{
  176. + assert(ctrl->tCWL >= 5);
  177. + const bool dimm_srt = ctrl->flags.ext_temp_refresh && !ctrl->flags.asr;
  178. +
  179. + const union {
  180. + struct __packed {
  181. + uint16_t partial_array_sr : 3; // Bits 0:2
  182. + uint16_t cas_write_latency : 3; // Bits 5:3
  183. + uint16_t auto_self_refresh : 1; // Bits 6:6
  184. + uint16_t self_refresh_temp : 1; // Bits 7:7
  185. + uint16_t : 1; // Bits 8:8
  186. + uint16_t odt_rtt_wr : 2; // Bits 10:9
  187. + uint16_t : 5; // Bits 15:11
  188. + };
  189. + uint16_t raw;
  190. + } mr2reg = {
  191. + .partial_array_sr = 0,
  192. + .cas_write_latency = ctrl->tCWL - 5,
  193. + .auto_self_refresh = ctrl->flags.asr,
  194. + .self_refresh_temp = dimm_srt,
  195. + .odt_rtt_wr = is_hsw_ult() ? RTT_WR_120 : RTT_WR_60,
  196. + };
  197. + for (uint8_t channel = 0; channel < NUM_CHANNELS; channel++) {
  198. + if (!does_ch_exist(ctrl, channel))
  199. + continue;
  200. +
  201. + for (uint8_t slot = 0; slot < NUM_SLOTS; slot++) {
  202. + if (!rank_in_ch(ctrl, slot + slot, channel))
  203. + continue;
  204. +
  205. + if (!ctrl->restore_mrs)
  206. + ctrl->mr2[channel][slot] = mr2reg.raw;
  207. + }
  208. + /* MR2 shadow register is similar but not identical to MR2 */
  209. + if (!ctrl->restore_mrs) {
  210. + union tc_mr2_shadow_reg tc_mr2_shadow = {
  211. + .raw = mr2reg.raw & 0x073f,
  212. + };
  213. + for (uint8_t slot = 0; slot < NUM_SLOTS; slot++) {
  214. + if (!rank_in_ch(ctrl, slot + slot, channel))
  215. + continue;
  216. +
  217. + if (dimm_srt)
  218. + tc_mr2_shadow.srt_available |= BIT(slot);
  219. +
  220. + if (ctrl->rank_mirrored[channel] & BIT(slot + slot + 1))
  221. + tc_mr2_shadow.addr_bit_swizzle |= BIT(slot);
  222. + }
  223. + mchbar_write32(TC_MR2_SHADOW_ch(channel), tc_mr2_shadow.raw);
  224. + }
  225. + reut_issue_mrs_all(ctrl, channel, 2, ctrl->mr2[channel]);
  226. + }
  227. +}
  228. +
  229. +static void ddr3_program_mr3(struct sysinfo *ctrl, const uint8_t mpr_mode)
  230. +{
  231. + const union {
  232. + struct __packed {
  233. + uint16_t mpr_loc : 2; // Bits 1:0
  234. + uint16_t mpr_mode : 1; // Bits 2:2
  235. + uint16_t : 13; // Bits 15:3
  236. + };
  237. + uint16_t raw;
  238. + } mr3reg = {
  239. + .mpr_loc = 0,
  240. + .mpr_mode = mpr_mode,
  241. + };
  242. + for (uint8_t channel = 0; channel < NUM_CHANNELS; channel++) {
  243. + if (!does_ch_exist(ctrl, channel))
  244. + continue;
  245. +
  246. + for (uint8_t slot = 0; slot < NUM_SLOTS; slot++) {
  247. + if (!rank_in_ch(ctrl, slot + slot, channel))
  248. + continue;
  249. +
  250. + if (!ctrl->restore_mrs)
  251. + ctrl->mr3[channel][slot] = mr3reg.raw;
  252. + }
  253. + reut_issue_mrs_all(ctrl, channel, 3, ctrl->mr3[channel]);
  254. + }
  255. +}
  256. +
  257. +enum raminit_status ddr3_jedec_init(struct sysinfo *ctrl)
  258. +{
  259. + ddr3_program_mr2(ctrl);
  260. + ddr3_program_mr3(ctrl, 0);
  261. + ddr3_program_mr1(ctrl, 0, 0);
  262. + ddr3_program_mr0(ctrl, 1);
  263. + return reut_issue_zq(ctrl, ctrl->chanmap, ZQ_INIT);
  264. +}
  265. diff --git a/src/northbridge/intel/haswell/native_raminit/io_comp_control.c b/src/northbridge/intel/haswell/native_raminit/io_comp_control.c
  266. index 7e96c08938..ad8c848e57 100644
  267. --- a/src/northbridge/intel/haswell/native_raminit/io_comp_control.c
  268. +++ b/src/northbridge/intel/haswell/native_raminit/io_comp_control.c
  269. @@ -8,6 +8,25 @@
  270. #include "raminit_native.h"
  271. +enum raminit_status io_reset(void)
  272. +{
  273. + union mc_init_state_g_reg mc_init_state_g = {
  274. + .raw = mchbar_read32(MC_INIT_STATE_G),
  275. + };
  276. + mc_init_state_g.reset_io = 1;
  277. + mchbar_write32(MC_INIT_STATE_G, mc_init_state_g.raw);
  278. + struct stopwatch timer;
  279. + stopwatch_init_msecs_expire(&timer, 2000);
  280. + do {
  281. + mc_init_state_g.raw = mchbar_read32(MC_INIT_STATE_G);
  282. + if (mc_init_state_g.reset_io == 0)
  283. + return RAMINIT_STATUS_SUCCESS;
  284. +
  285. + } while (!stopwatch_expired(&timer));
  286. + printk(BIOS_ERR, "Timed out waiting for DDR I/O reset to complete\n");
  287. + return RAMINIT_STATUS_POLL_TIMEOUT;
  288. +}
  289. +
  290. enum raminit_status wait_for_first_rcomp(void)
  291. {
  292. struct stopwatch timer;
  293. diff --git a/src/northbridge/intel/haswell/native_raminit/jedec_reset.c b/src/northbridge/intel/haswell/native_raminit/jedec_reset.c
  294. new file mode 100644
  295. index 0000000000..de0f676758
  296. --- /dev/null
  297. +++ b/src/northbridge/intel/haswell/native_raminit/jedec_reset.c
  298. @@ -0,0 +1,120 @@
  299. +/* SPDX-License-Identifier: GPL-2.0-or-later */
  300. +
  301. +#include <console/console.h>
  302. +#include <delay.h>
  303. +#include <northbridge/intel/haswell/haswell.h>
  304. +#include <southbridge/intel/lynxpoint/pch.h>
  305. +#include <types.h>
  306. +#include <timer.h>
  307. +
  308. +#include "raminit_native.h"
  309. +
  310. +static void assert_reset(const bool do_reset)
  311. +{
  312. + if (is_hsw_ult()) {
  313. + uint32_t pm_cfg2 = RCBA32(PM_CFG2);
  314. + if (do_reset)
  315. + pm_cfg2 &= ~PM_CFG2_DRAM_RESET_CTL;
  316. + else
  317. + pm_cfg2 |= PM_CFG2_DRAM_RESET_CTL;
  318. + RCBA32(PM_CFG2) = pm_cfg2;
  319. + } else {
  320. + union mc_init_state_g_reg mc_init_state_g = {
  321. + .raw = mchbar_read32(MC_INIT_STATE_G),
  322. + };
  323. + mc_init_state_g.ddr_not_reset = !do_reset;
  324. + mchbar_write32(MC_INIT_STATE_G, mc_init_state_g.raw);
  325. + }
  326. +}
  327. +
  328. +/*
  329. + * Perform JEDEC reset.
  330. + *
  331. + * If RTT_NOM is to be enabled in MR1, the ODT input signal must be
  332. + * statically held low in our system since RTT_NOM is always enabled.
  333. + */
  334. +static void jedec_reset(struct sysinfo *ctrl)
  335. +{
  336. + if (is_hsw_ult())
  337. + assert_reset(false);
  338. +
  339. + union mc_init_state_g_reg mc_init_state_g = {
  340. + .ddr_not_reset = 1,
  341. + .safe_self_refresh = 1,
  342. + };
  343. + mchbar_write32(MC_INIT_STATE_G, mc_init_state_g.raw);
  344. +
  345. + union reut_misc_cke_ctrl_reg reut_misc_cke_ctrl = {
  346. + .cke_override = 0xf,
  347. + .cke_on = 0,
  348. + };
  349. + mchbar_write32(REUT_MISC_CKE_CTRL, reut_misc_cke_ctrl.raw);
  350. +
  351. + assert_reset(true);
  352. +
  353. + /** TODO: check and switch DDR3 voltage here (mainboard-specific) **/
  354. +
  355. + udelay(200);
  356. +
  357. + assert_reset(false);
  358. +
  359. + udelay(500);
  360. +
  361. + mc_init_state_g.dclk_enable = 1;
  362. + mchbar_write32(MC_INIT_STATE_G, mc_init_state_g.raw);
  363. +
  364. + /* Delay at least 20 nanoseconds for tCKSRX */
  365. + tick_delay(1);
  366. +
  367. + for (uint8_t channel = 0; channel < NUM_CHANNELS; channel++) {
  368. + reut_misc_cke_ctrl.cke_on = ctrl->rankmap[channel];
  369. + mchbar_write32(REUT_ch_MISC_CKE_CTRL(channel), reut_misc_cke_ctrl.raw);
  370. + }
  371. +
  372. + /*
  373. + * Wait minimum of reset CKE exit time, tXPR.
  374. + * Spec says MAX(tXS, 5 tCK). 5 tCK is 10 ns.
  375. + */
  376. + tick_delay(1);
  377. +}
  378. +
  379. +enum raminit_status do_jedec_init(struct sysinfo *ctrl)
  380. +{
  381. + /* Never do a JEDEC reset in S3 resume */
  382. + if (ctrl->bootmode == BOOTMODE_S3)
  383. + return RAMINIT_STATUS_SUCCESS;
  384. +
  385. + enum raminit_status status = io_reset();
  386. + if (status)
  387. + return status;
  388. +
  389. + status = wait_for_first_rcomp();
  390. + if (status)
  391. + return status;
  392. +
  393. + /* Force ODT low (JEDEC spec) */
  394. + const union reut_misc_odt_ctrl_reg reut_misc_odt_ctrl = {
  395. + .odt_override = 0xf,
  396. + .odt_on = 0,
  397. + };
  398. + mchbar_write32(REUT_MISC_ODT_CTRL, reut_misc_odt_ctrl.raw);
  399. +
  400. + /*
  401. + * Note: Haswell MRC does not clear ODT override for LPDDR3. However,
  402. + * Broadwell MRC does. Hell suspects this difference is important, as
  403. + * there is an erratum in the specification update for Broadwell:
  404. + *
  405. + * Erratum BDM74: LPDDR3 Memory Training May Cause Platform Boot Failure
  406. + */
  407. + if (ctrl->lpddr)
  408. + die("%s: LPDDR-specific JEDEC init not implemented\n", __func__);
  409. +
  410. + jedec_reset(ctrl);
  411. + status = ddr3_jedec_init(ctrl);
  412. + if (!status)
  413. + ctrl->restore_mrs = true;
  414. +
  415. + /* Release ODT override */
  416. + mchbar_write32(REUT_MISC_ODT_CTRL, 0);
  417. + return status;
  418. +}
  419. diff --git a/src/northbridge/intel/haswell/native_raminit/raminit_main.c b/src/northbridge/intel/haswell/native_raminit/raminit_main.c
  420. index 136a8ba989..73ff180b8c 100644
  421. --- a/src/northbridge/intel/haswell/native_raminit/raminit_main.c
  422. +++ b/src/northbridge/intel/haswell/native_raminit/raminit_main.c
  423. @@ -25,6 +25,7 @@ static const struct task_entry cold_boot[] = {
  424. { convert_timings, true, "CONVTIM", },
  425. { configure_mc, true, "CONFMC", },
  426. { configure_memory_map, true, "MEMMAP", },
  427. + { do_jedec_init, true, "JEDECINIT", },
  428. };
  429. /* Return a generic stepping value to make stepping checks simpler */
  430. @@ -58,6 +59,7 @@ static void initialize_ctrl(struct sysinfo *ctrl)
  431. ctrl->stepping = get_stepping(ctrl->cpu);
  432. ctrl->vdd_mv = is_hsw_ult() ? 1350 : 1500; /** FIXME: Hardcoded, does it matter? **/
  433. ctrl->dq_pins_interleaved = cfg->dq_pins_interleaved;
  434. + ctrl->restore_mrs = false;
  435. ctrl->bootmode = bootmode;
  436. }
  437. diff --git a/src/northbridge/intel/haswell/native_raminit/raminit_native.h b/src/northbridge/intel/haswell/native_raminit/raminit_native.h
  438. index 4763b25e8d..e3cf4254a0 100644
  439. --- a/src/northbridge/intel/haswell/native_raminit/raminit_native.h
  440. +++ b/src/northbridge/intel/haswell/native_raminit/raminit_native.h
  441. @@ -27,6 +27,30 @@
  442. /* Always use 12 legs for emphasis (not trained) */
  443. #define TXEQFULLDRV (3 << 4)
  444. +/* DDR3 mode register bits */
  445. +#define MR0_DLL_RESET BIT(8)
  446. +
  447. +#define MR1_WL_ENABLE BIT(7)
  448. +#define MR1_QOFF_ENABLE BIT(12) /* If set, output buffers disabled */
  449. +
  450. +#define RTTNOM_MASK (BIT(9) | BIT(6) | BIT(2))
  451. +
  452. +/* ZQ calibration types */
  453. +enum {
  454. + ZQ_INIT, /* DDR3: ZQCL with tZQinit, LPDDR3: ZQ Init with tZQinit */
  455. + ZQ_LONG, /* DDR3: ZQCL with tZQoper, LPDDR3: ZQ Long with tZQCL */
  456. + ZQ_SHORT, /* DDR3: ZQCS with tZQCS, LPDDR3: ZQ Short with tZQCS */
  457. + ZQ_RESET, /* DDR3: not used, LPDDR3: ZQ Reset with tZQreset */
  458. +};
  459. +
  460. +/* REUT initialisation modes */
  461. +enum {
  462. + REUT_MODE_IDLE = 0,
  463. + REUT_MODE_TEST = 1,
  464. + REUT_MODE_MRS = 2,
  465. + REUT_MODE_NOP = 3, /* Normal operation mode */
  466. +};
  467. +
  468. enum command_training_iteration {
  469. CT_ITERATION_CLOCK = 0,
  470. CT_ITERATION_CMD_NORTH,
  471. @@ -50,6 +74,7 @@ enum raminit_status {
  472. RAMINIT_STATUS_UNSUPPORTED_MEMORY,
  473. RAMINIT_STATUS_MPLL_INIT_FAILURE,
  474. RAMINIT_STATUS_POLL_TIMEOUT,
  475. + RAMINIT_STATUS_REUT_ERROR,
  476. RAMINIT_STATUS_UNSPECIFIED_ERROR, /** TODO: Deprecated in favor of specific values **/
  477. };
  478. @@ -72,6 +97,7 @@ struct sysinfo {
  479. uint32_t cpu; /* CPUID value */
  480. bool dq_pins_interleaved;
  481. + bool restore_mrs;
  482. /** TODO: ECC support untested **/
  483. bool is_ecc;
  484. @@ -161,6 +187,11 @@ struct sysinfo {
  485. union tc_bank_rank_b_reg tc_bankrank_b[NUM_CHANNELS];
  486. union tc_bank_rank_c_reg tc_bankrank_c[NUM_CHANNELS];
  487. union tc_bank_rank_d_reg tc_bankrank_d[NUM_CHANNELS];
  488. +
  489. + uint16_t mr0[NUM_CHANNELS][NUM_SLOTRANKS];
  490. + uint16_t mr1[NUM_CHANNELS][NUM_SLOTRANKS];
  491. + uint16_t mr2[NUM_CHANNELS][NUM_SLOTRANKS];
  492. + uint16_t mr3[NUM_CHANNELS][NUM_SLOTRANKS];
  493. };
  494. static inline bool is_hsw_ult(void)
  495. @@ -196,6 +227,55 @@ static inline void clear_data_offset_train_all(struct sysinfo *ctrl)
  496. memset(ctrl->data_offset_train, 0, sizeof(ctrl->data_offset_train));
  497. }
  498. +/* Number of ticks to wait in units of 69.841279 ns (citation needed) */
  499. +static inline void tick_delay(const uint32_t delay)
  500. +{
  501. + volatile uint32_t junk;
  502. +
  503. + /* Just perform reads to a random register */
  504. + for (uint32_t start = 0; start <= delay; start++)
  505. + junk = mchbar_read32(REUT_ERR_DATA_STATUS);
  506. +}
  507. +
  508. +/*
  509. + * 64-bit MCHBAR registers need to be accessed atomically. If one uses
  510. + * two 32-bit ops instead, there will be problems with the REUT's CADB
  511. + * (Command Address Data Buffer): hardware automatically advances the
  512. + * pointer into the register file after a write to the input register.
  513. + */
  514. +static inline uint64_t mchbar_read64(const uintptr_t x)
  515. +{
  516. + const uint64_t *offset = (uint64_t *)(CONFIG_FIXED_MCHBAR_MMIO_BASE + x);
  517. + uint64_t mmxsave, v;
  518. + asm volatile (
  519. + "\n\t movq %%mm0, %0"
  520. + "\n\t movq %2, %%mm0"
  521. + "\n\t movq %%mm0, %1"
  522. + "\n\t movq %3, %%mm0"
  523. + "\n\t emms"
  524. + : "=m"(mmxsave),
  525. + "=m"(v)
  526. + : "m"(offset[0]),
  527. + "m"(mmxsave));
  528. + return v;
  529. +}
  530. +
  531. +static inline void mchbar_write64(const uintptr_t x, const uint64_t v)
  532. +{
  533. + const uint64_t *offset = (uint64_t *)(CONFIG_FIXED_MCHBAR_MMIO_BASE + x);
  534. + uint64_t mmxsave;
  535. + asm volatile (
  536. + "\n\t movq %%mm0, %0"
  537. + "\n\t movq %2, %%mm0"
  538. + "\n\t movq %%mm0, %1"
  539. + "\n\t movq %3, %%mm0"
  540. + "\n\t emms"
  541. + : "=m"(mmxsave)
  542. + : "m"(offset[0]),
  543. + "m"(v),
  544. + "m"(mmxsave));
  545. +}
  546. +
  547. void raminit_main(enum raminit_boot_mode bootmode);
  548. enum raminit_status collect_spd_info(struct sysinfo *ctrl);
  549. @@ -203,6 +283,7 @@ enum raminit_status initialise_mpll(struct sysinfo *ctrl);
  550. enum raminit_status convert_timings(struct sysinfo *ctrl);
  551. enum raminit_status configure_mc(struct sysinfo *ctrl);
  552. enum raminit_status configure_memory_map(struct sysinfo *ctrl);
  553. +enum raminit_status do_jedec_init(struct sysinfo *ctrl);
  554. void configure_timings(struct sysinfo *ctrl);
  555. void configure_refresh(struct sysinfo *ctrl);
  556. @@ -215,8 +296,28 @@ uint32_t get_tXS_offset(uint32_t mem_clock_mhz);
  557. uint32_t get_tZQOPER(uint32_t mem_clock_mhz, bool lpddr);
  558. uint32_t get_tZQCS(uint32_t mem_clock_mhz, bool lpddr);
  559. +enum raminit_status io_reset(void);
  560. enum raminit_status wait_for_first_rcomp(void);
  561. +uint16_t encode_ddr3_rttnom(uint32_t rttnom);
  562. +void ddr3_program_mr1(struct sysinfo *ctrl, uint8_t wl_mode, uint8_t q_off);
  563. +enum raminit_status ddr3_jedec_init(struct sysinfo *ctrl);
  564. +
  565. +void reut_issue_mrs(
  566. + struct sysinfo *ctrl,
  567. + uint8_t channel,
  568. + uint8_t rankmask,
  569. + uint8_t mr,
  570. + uint16_t val);
  571. +
  572. +void reut_issue_mrs_all(
  573. + struct sysinfo *ctrl,
  574. + uint8_t channel,
  575. + uint8_t mr,
  576. + const uint16_t val[NUM_SLOTS]);
  577. +
  578. +enum raminit_status reut_issue_zq(struct sysinfo *ctrl, uint8_t chanmask, uint8_t zq_type);
  579. +
  580. uint8_t get_rx_bias(const struct sysinfo *ctrl);
  581. uint8_t get_tCWL(uint32_t mem_clock_mhz);
  582. diff --git a/src/northbridge/intel/haswell/native_raminit/reg_structs.h b/src/northbridge/intel/haswell/native_raminit/reg_structs.h
  583. index 70487e1640..9929f617fe 100644
  584. --- a/src/northbridge/intel/haswell/native_raminit/reg_structs.h
  585. +++ b/src/northbridge/intel/haswell/native_raminit/reg_structs.h
  586. @@ -335,6 +335,127 @@ union mcscheds_cbit_reg {
  587. uint32_t raw;
  588. };
  589. +union reut_pat_cadb_prog_reg {
  590. + struct __packed {
  591. + uint32_t addr : 16; // Bits 15:0
  592. + uint32_t : 8; // Bits 23:16
  593. + uint32_t bank : 3; // Bits 26:24
  594. + uint32_t : 5; // Bits 31:27
  595. + uint32_t cs : 4; // Bits 35:32
  596. + uint32_t : 4; // Bits 39:36
  597. + uint32_t cmd : 3; // Bits 42:40
  598. + uint32_t : 5; // Bits 47:43
  599. + uint32_t odt : 4; // Bits 51:48
  600. + uint32_t : 4; // Bits 55:52
  601. + uint32_t cke : 4; // Bits 59:56
  602. + uint32_t : 4; // Bits 63:60
  603. + };
  604. + uint64_t raw;
  605. + uint32_t raw32[2];
  606. +};
  607. +
  608. +union reut_pat_cadb_mrs_reg {
  609. + struct __packed {
  610. + uint32_t delay_gap : 3; // Bits 2:0
  611. + uint32_t : 5; // Bits 7:3
  612. + uint32_t start_ptr : 3; // Bits 10:8
  613. + uint32_t : 5; // Bits 15:11
  614. + uint32_t end_ptr : 3; // Bits 18:16
  615. + uint32_t : 5; // Bits 23:19
  616. + uint32_t curr_ptr : 3; // Bits 26:24
  617. + uint32_t : 5; // Bits 31:27
  618. + };
  619. + uint32_t raw;
  620. +};
  621. +
  622. +union reut_seq_cfg_reg {
  623. + struct __packed {
  624. + uint32_t : 3; // Bits 2:0
  625. + uint32_t stop_base_seq_on_wrap_trigger : 1; // Bits 3:3
  626. + uint32_t : 1; // Bits 4:4
  627. + uint32_t address_update_rate_mode : 1; // Bits 5:5
  628. + uint32_t : 1; // Bits 6:6
  629. + uint32_t enable_dummy_reads : 1; // Bits 7:7
  630. + uint32_t : 2; // Bits 9:8
  631. + uint32_t enable_constant_write_strobe : 1; // Bits 10:10
  632. + uint32_t global_control : 1; // Bits 11:11
  633. + uint32_t initialization_mode : 2; // Bits 13:12
  634. + uint32_t : 2; // Bits 15:14
  635. + uint32_t early_steppings_loop_count : 5; // Bits 20:16 *** Not on C0 ***
  636. + uint32_t : 3; // Bits 23:21
  637. + uint32_t subsequence_start_pointer : 3; // Bits 26:24
  638. + uint32_t : 1; // Bits 27:27
  639. + uint32_t subsequence_end_pointer : 3; // Bits 30:28
  640. + uint32_t : 1; // Bits 31:31
  641. + uint32_t start_test_delay : 10; // Bits 41:32
  642. + uint32_t : 22; // Bits 63:42
  643. + };
  644. + uint64_t raw;
  645. + uint32_t raw32[2];
  646. +};
  647. +
  648. +union reut_seq_ctl_reg {
  649. + struct __packed {
  650. + uint32_t start_test : 1; // Bits 0:0
  651. + uint32_t stop_test : 1; // Bits 1:1
  652. + uint32_t clear_errors : 1; // Bits 2:2
  653. + uint32_t : 1; // Bits 3:3
  654. + uint32_t stop_on_error : 1; // Bits 4:4
  655. + uint32_t : 27; // Bits 31:5
  656. + };
  657. + uint32_t raw;
  658. +};
  659. +
  660. +union reut_global_err_reg {
  661. + struct __packed {
  662. + uint32_t ch_error : 2; // Bits 1:0
  663. + uint32_t : 14; // Bits 15:2
  664. + uint32_t ch_test_done : 2; // Bits 17:16
  665. + uint32_t : 14; // Bits 31:18
  666. + };
  667. + uint32_t raw;
  668. +};
  669. +
  670. +union reut_misc_cke_ctrl_reg {
  671. + struct __packed {
  672. + uint32_t cke_override : 4; // Bits 3:0
  673. + uint32_t : 4; // Bits 7:4
  674. + uint32_t cke_en_start_test_sync : 1; // Bits 8:8
  675. + uint32_t : 7; // Bits 15:9
  676. + uint32_t cke_on : 4; // Bits 19:16
  677. + uint32_t : 12; // Bits 31:20
  678. + };
  679. + uint32_t raw;
  680. +};
  681. +
  682. +union reut_misc_odt_ctrl_reg {
  683. + struct __packed {
  684. + uint32_t odt_override : 4; // Bits 3:0
  685. + uint32_t : 12; // Bits 15:4
  686. + uint32_t odt_on : 4; // Bits 19:16
  687. + uint32_t : 11; // Bits 30:20
  688. + uint32_t mpr_train_ddr_on : 1; // Bits 31:31
  689. + };
  690. + uint32_t raw;
  691. +};
  692. +
  693. +union mcscheds_dft_misc_reg {
  694. + struct __packed {
  695. + uint32_t wdar : 1; // Bits 0:0
  696. + uint32_t safe_mask_sel : 3; // Bits 3:1
  697. + uint32_t force_rcv_en : 1; // Bits 4:4
  698. + uint32_t : 3; // Bits 7:5
  699. + uint32_t ddr_qualifier : 2; // Bits 9:8
  700. + uint32_t qualifier_length : 2; // Bits 11:10
  701. + uint32_t wdb_block_en : 1; // Bits 12:12
  702. + uint32_t rt_dft_read_ptr : 4; // Bits 16:13
  703. + uint32_t rt_dft_read_enable : 1; // Bits 17:17
  704. + uint32_t rt_dft_read_sel_addr : 1; // Bits 18:18
  705. + uint32_t : 13; // Bits 31:19
  706. + };
  707. + uint32_t raw;
  708. +};
  709. +
  710. union tc_bank_reg {
  711. struct __packed {
  712. uint32_t tRCD : 5; // Bits 4:0
  713. @@ -428,6 +549,18 @@ union tc_srftp_reg {
  714. uint32_t raw;
  715. };
  716. +union tc_mr2_shadow_reg {
  717. + struct __packed {
  718. + uint32_t mr2_shadow_low : 6; // Bits 5:0
  719. + uint32_t srt_available : 2; // Bits 7:6
  720. + uint32_t mr2_shadow_high : 3; // Bits 10:8
  721. + uint32_t : 3; // Bits 13:11
  722. + uint32_t addr_bit_swizzle : 2; // Bits 15:14
  723. + uint32_t : 16; // Bits 31:16
  724. + };
  725. + uint32_t raw;
  726. +};
  727. +
  728. union mcmain_command_rate_limit_reg {
  729. struct __packed {
  730. uint32_t enable_cmd_limit : 1; // Bits 0:0
  731. @@ -483,6 +616,27 @@ union mad_zr_reg {
  732. uint32_t raw;
  733. };
  734. +union mc_init_state_g_reg {
  735. + struct __packed {
  736. + uint32_t pu_mrc_done : 1; // Bits 0:0
  737. + uint32_t ddr_not_reset : 1; // Bits 1:1
  738. + uint32_t : 1; // Bits 2:2
  739. + uint32_t refresh_enable : 1; // Bits 3:3
  740. + uint32_t : 1; // Bits 4:4
  741. + uint32_t mc_init_done_ack : 1; // Bits 5:5
  742. + uint32_t : 1; // Bits 6:6
  743. + uint32_t mrc_done : 1; // Bits 7:7
  744. + uint32_t safe_self_refresh : 1; // Bits 8:8
  745. + uint32_t : 1; // Bits 9:9
  746. + uint32_t hvm_gate_ddr_reset : 1; // Bits 10:10
  747. + uint32_t : 11; // Bits 21:11
  748. + uint32_t dclk_enable : 1; // Bits 22:22
  749. + uint32_t reset_io : 1; // Bits 23:23
  750. + uint32_t : 8; // Bits 31:24
  751. + };
  752. + uint32_t raw;
  753. +};
  754. +
  755. /* Same definition for P_COMP, M_COMP, D_COMP */
  756. union pcu_comp_reg {
  757. struct __packed {
  758. diff --git a/src/northbridge/intel/haswell/native_raminit/reut.c b/src/northbridge/intel/haswell/native_raminit/reut.c
  759. new file mode 100644
  760. index 0000000000..c55cdd9c7e
  761. --- /dev/null
  762. +++ b/src/northbridge/intel/haswell/native_raminit/reut.c
  763. @@ -0,0 +1,196 @@
  764. +/* SPDX-License-Identifier: GPL-2.0-or-later */
  765. +
  766. +#include <console/console.h>
  767. +#include <delay.h>
  768. +#include <northbridge/intel/haswell/haswell.h>
  769. +#include <timer.h>
  770. +#include <types.h>
  771. +
  772. +#include "raminit_native.h"
  773. +
  774. +enum {
  775. + CADB_CMD_MRS = 0,
  776. + CADB_CMD_REF = 1,
  777. + CADB_CMD_PRE = 2,
  778. + CADB_CMD_ACT = 3,
  779. + CADB_CMD_WR = 4,
  780. + CADB_CMD_RD = 5,
  781. + CADB_CMD_ZQ = 6,
  782. + CADB_CMD_NOP = 7,
  783. +};
  784. +
  785. +/*
  786. + * DDR3 rank mirror swaps the following pins: A3<->A4, A5<->A6, A7<->A8, BA0<->BA1
  787. + *
  788. + * Note that the swapped bits are contiguous. We can use some XOR magic to swap the bits.
  789. + * Address lanes are at bits 0..15 and bank selects are at bits 24..26 on the REUT register.
  790. + */
  791. +#define MIRROR_BITS (BIT(24) | BIT(7) | BIT(5) | BIT(3))
  792. +static uint64_t cadb_prog_rank_mirror(const uint64_t cadb_prog)
  793. +{
  794. + /* First XOR: find which pairs of bits are different (need swapping) */
  795. + const uint64_t tmp64 = (cadb_prog ^ (cadb_prog >> 1)) & MIRROR_BITS;
  796. +
  797. + /* Second XOR: invert the pairs of bits that have different values */
  798. + return cadb_prog ^ (tmp64 | tmp64 << 1);
  799. +}
  800. +
  801. +static enum raminit_status reut_write_cadb_cmd(
  802. + struct sysinfo *ctrl,
  803. + const uint8_t channel,
  804. + const uint8_t rankmask,
  805. + const uint8_t cmd,
  806. + const uint8_t bank,
  807. + const uint16_t valarr[NUM_SLOTRANKS],
  808. + const uint8_t delay)
  809. +{
  810. + union mcscheds_dft_misc_reg dft_misc = {
  811. + .raw = mchbar_read32(MCSCHEDS_DFT_MISC),
  812. + };
  813. + dft_misc.ddr_qualifier = 0;
  814. + mchbar_write32(MCSCHEDS_DFT_MISC, dft_misc.raw);
  815. +
  816. + /* Pointer will be dynamically incremented after a write to CADB_PROG register */
  817. + mchbar_write8(REUT_ch_PAT_CADB_WRITE_PTR(channel), 0);
  818. +
  819. + uint8_t count = 0;
  820. + for (uint8_t rank = 0; rank < NUM_SLOTRANKS; rank++) {
  821. + if (!(ctrl->rankmap[channel] & BIT(rank) & rankmask))
  822. + continue;
  823. +
  824. + union reut_pat_cadb_prog_reg reut_cadb_prog = {
  825. + .addr = valarr[rank],
  826. + .bank = bank,
  827. + .cs = ~BIT(rank), /* CS is active low */
  828. + .cmd = cmd,
  829. + .cke = 0xf,
  830. + };
  831. + if (ctrl->rank_mirrored[channel] & BIT(rank))
  832. + reut_cadb_prog.raw = cadb_prog_rank_mirror(reut_cadb_prog.raw);
  833. +
  834. + mchbar_write64(REUT_ch_PAT_CADB_PROG(channel), reut_cadb_prog.raw);
  835. + count++;
  836. + }
  837. + if (!count) {
  838. + printk(BIOS_ERR, "%s: rankmask is invalid\n", __func__);
  839. + return RAMINIT_STATUS_UNSPECIFIED_ERROR; /** FIXME: Is this needed? **/
  840. + }
  841. + const union reut_pat_cadb_mrs_reg reut_cadb_mrs = {
  842. + .delay_gap = delay ? delay : 3,
  843. + .end_ptr = count - 1,
  844. + };
  845. + mchbar_write32(REUT_ch_PAT_CADB_MRS(channel), reut_cadb_mrs.raw);
  846. +
  847. + const uint32_t reut_seq_cfg_save = mchbar_read32(REUT_ch_SEQ_CFG(channel));
  848. + union reut_seq_cfg_reg reut_seq_cfg = {
  849. + .raw = reut_seq_cfg_save,
  850. + };
  851. + reut_seq_cfg.global_control = 0;
  852. + reut_seq_cfg.initialization_mode = REUT_MODE_MRS;
  853. + mchbar_write32(REUT_ch_SEQ_CFG(channel), reut_seq_cfg.raw);
  854. + mchbar_write32(REUT_ch_SEQ_CTL(channel), (union reut_seq_ctl_reg) {
  855. + .start_test = 1,
  856. + .clear_errors = 1,
  857. + }.raw);
  858. + enum raminit_status status = RAMINIT_STATUS_SUCCESS;
  859. + union reut_global_err_reg reut_global_err;
  860. + struct stopwatch timer;
  861. + stopwatch_init_msecs_expire(&timer, 100);
  862. + do {
  863. + reut_global_err.raw = mchbar_read32(REUT_GLOBAL_ERR);
  864. + if (reut_global_err.ch_error & BIT(channel)) {
  865. + printk(BIOS_ERR, "Unexpected REUT error for channel %u\n", channel);
  866. + status = RAMINIT_STATUS_REUT_ERROR;
  867. + break;
  868. + }
  869. + if (stopwatch_expired(&timer)) {
  870. + printk(BIOS_ERR, "%s: REUT timed out!\n", __func__);
  871. + status = RAMINIT_STATUS_POLL_TIMEOUT;
  872. + break;
  873. + }
  874. + } while (!(reut_global_err.ch_test_done & BIT(channel)));
  875. + mchbar_write32(REUT_ch_SEQ_CTL(channel), (union reut_seq_ctl_reg) {
  876. + .clear_errors = 1,
  877. + }.raw);
  878. + mchbar_write32(REUT_ch_SEQ_CFG(channel), reut_seq_cfg_save);
  879. + return status;
  880. +}
  881. +
  882. +static enum raminit_status reut_write_cadb_cmd_all(
  883. + struct sysinfo *ctrl,
  884. + const uint8_t channel,
  885. + const uint8_t rankmask,
  886. + const uint8_t cmd,
  887. + const uint8_t bank,
  888. + const uint16_t val,
  889. + const uint8_t delay)
  890. +{
  891. + const uint16_t valarr[NUM_SLOTRANKS] = { val, val, val, val };
  892. + return reut_write_cadb_cmd(ctrl, channel, rankmask, cmd, bank, valarr, delay);
  893. +}
  894. +
  895. +void reut_issue_mrs(
  896. + struct sysinfo *ctrl,
  897. + const uint8_t channel,
  898. + const uint8_t rankmask,
  899. + const uint8_t mr,
  900. + const uint16_t val)
  901. +{
  902. + reut_write_cadb_cmd_all(ctrl, channel, rankmask, CADB_CMD_MRS, mr, val, 0);
  903. +}
  904. +
  905. +void reut_issue_mrs_all(
  906. + struct sysinfo *ctrl,
  907. + const uint8_t channel,
  908. + const uint8_t mr,
  909. + const uint16_t val[NUM_SLOTS])
  910. +{
  911. + const uint16_t valarr[NUM_SLOTRANKS] = { val[0], val[0], val[1], val[1] };
  912. + reut_write_cadb_cmd(ctrl, channel, 0xf, CADB_CMD_MRS, mr, valarr, 0);
  913. +}
  914. +
  915. +enum raminit_status reut_issue_zq(struct sysinfo *ctrl, uint8_t chanmask, uint8_t zq_type)
  916. +{
  917. + /** TODO: Issuing ZQ commands differs for LPDDR **/
  918. + if (ctrl->lpddr)
  919. + die("%s: LPDDR not yet supported in ZQ calibration\n");
  920. +
  921. + uint8_t opcode; /* NOTE: Only used for LPDDR */
  922. + uint16_t zq = 0;
  923. + switch (zq_type) {
  924. + case ZQ_INIT:
  925. + zq = BIT(10);
  926. + opcode = 0xff;
  927. + break;
  928. + case ZQ_LONG:
  929. + zq = BIT(10);
  930. + opcode = 0xab;
  931. + break;
  932. + case ZQ_SHORT:
  933. + opcode = 0x56;
  934. + break;
  935. + case ZQ_RESET:
  936. + opcode = 0xc3;
  937. + break;
  938. + default:
  939. + die("%s: ZQ type %u is invalid\n", zq_type);
  940. + }
  941. +
  942. + /* ZQCS on single-channel needs a longer delay */
  943. + const uint8_t delay = zq_type == ZQ_SHORT && (!ctrl->dpc[0] || !ctrl->dpc[1]) ? 7 : 1;
  944. + enum raminit_status status = RAMINIT_STATUS_SUCCESS;
  945. + for (uint8_t channel = 0; channel < NUM_CHANNELS; channel++) {
  946. + if (!(BIT(channel) & chanmask) || !does_ch_exist(ctrl, channel))
  947. + continue;
  948. +
  949. + status = reut_write_cadb_cmd_all(ctrl, channel, 0xf, CADB_CMD_ZQ, 0, zq, delay);
  950. + if (status)
  951. + break;
  952. + }
  953. +
  954. + /* Wait a bit after ZQ INIT and ZQCL commands */
  955. + if (zq)
  956. + udelay(1);
  957. +
  958. + return status;
  959. +}
  960. diff --git a/src/northbridge/intel/haswell/registers/mchbar.h b/src/northbridge/intel/haswell/registers/mchbar.h
  961. index 2acc5cbbc8..4fc78a7f43 100644
  962. --- a/src/northbridge/intel/haswell/registers/mchbar.h
  963. +++ b/src/northbridge/intel/haswell/registers/mchbar.h
  964. @@ -96,15 +96,36 @@
  965. #define SC_WR_ADD_DELAY_ch(ch) _MCMAIN_C(0x40d0, ch)
  966. +#define REUT_ch_MISC_CKE_CTRL(ch) _MCMAIN_C(0x4190, ch)
  967. +
  968. +#define REUT_ch_PAT_CADB_MRS(ch) _MCMAIN_C(0x419c, ch)
  969. +
  970. +#define REUT_ch_PAT_CADB_WRITE_PTR(ch) _MCMAIN_C(0x41bc, ch)
  971. +#define REUT_ch_PAT_CADB_PROG(ch) _MCMAIN_C(0x41c0, ch)
  972. +
  973. #define TC_ZQCAL_ch(ch) _MCMAIN_C(0x4290, ch)
  974. #define TC_RFP_ch(ch) _MCMAIN_C(0x4294, ch)
  975. #define TC_RFTP_ch(ch) _MCMAIN_C(0x4298, ch)
  976. +#define TC_MR2_SHADOW_ch(ch) _MCMAIN_C(0x429c, ch)
  977. #define MC_INIT_STATE_ch(ch) _MCMAIN_C(0x42a0, ch)
  978. #define TC_SRFTP_ch(ch) _MCMAIN_C(0x42a4, ch)
  979. +#define REUT_GLOBAL_ERR 0x4804
  980. +
  981. +#define REUT_ch_SEQ_CFG(ch) (0x48a8 + 8 * (ch))
  982. +
  983. +#define REUT_ch_SEQ_CTL(ch) (0x48b8 + 4 * (ch))
  984. +
  985. /* MCMAIN broadcast */
  986. #define MCSCHEDS_CBIT 0x4c20
  987. +#define MCSCHEDS_DFT_MISC 0x4c30
  988. +
  989. +#define REUT_ERR_DATA_STATUS 0x4ce0
  990. +
  991. +#define REUT_MISC_CKE_CTRL 0x4d90
  992. +#define REUT_MISC_ODT_CTRL 0x4d94
  993. +
  994. #define MCMNTS_SC_WDBWM 0x4f8c
  995. /* MCDECS */
  996. diff --git a/src/southbridge/intel/lynxpoint/pch.h b/src/southbridge/intel/lynxpoint/pch.h
  997. index 74b4d50017..16bef5032a 100644
  998. --- a/src/southbridge/intel/lynxpoint/pch.h
  999. +++ b/src/southbridge/intel/lynxpoint/pch.h
  1000. @@ -586,6 +586,8 @@ void mainboard_config_rcba(void);
  1001. #define ACPIIRQEN 0x31e0 /* 32bit */
  1002. #define OIC 0x31fe /* 16bit */
  1003. #define PRSTS 0x3310 /* 32bit */
  1004. +#define PM_CFG2 0x333c /* 32bit */
  1005. +#define PM_CFG2_DRAM_RESET_CTL (1 << 26) /* ULT only */
  1006. #define PMSYNC_CONFIG 0x33c4 /* 32bit */
  1007. #define PMSYNC_CONFIG2 0x33cc /* 32bit */
  1008. #define SOFT_RESET_CTRL 0x38f4
  1009. --
  1010. 2.39.2