0013-haswell-NRI-Configure-initial-MC-settings.patch 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594
  1. From 1b0b17d85256193de825fa7ff0e04767c818f2fc Mon Sep 17 00:00:00 2001
  2. From: Angel Pons <th3fanbus@gmail.com>
  3. Date: Sat, 7 May 2022 17:22:07 +0200
  4. Subject: [PATCH 13/26] haswell NRI: Configure initial MC settings
  5. Program initial memory controller settings. Many of these values will be
  6. adjusted later during training.
  7. Change-Id: If33846b51cb1bab5d0458fe626e13afb1bdc900e
  8. Signed-off-by: Angel Pons <th3fanbus@gmail.com>
  9. ---
  10. .../intel/haswell/native_raminit/Makefile.inc | 2 +
  11. .../haswell/native_raminit/configure_mc.c | 822 ++++++++++++++++++
  12. .../haswell/native_raminit/raminit_main.c | 2 +
  13. .../haswell/native_raminit/raminit_native.h | 101 +++
  14. .../haswell/native_raminit/reg_structs.h | 405 +++++++++
  15. .../haswell/native_raminit/timings_refresh.c | 13 +
  16. .../intel/haswell/registers/mchbar.h | 94 ++
  17. 7 files changed, 1439 insertions(+)
  18. create mode 100644 src/northbridge/intel/haswell/native_raminit/configure_mc.c
  19. create mode 100644 src/northbridge/intel/haswell/native_raminit/reg_structs.h
  20. create mode 100644 src/northbridge/intel/haswell/native_raminit/timings_refresh.c
  21. diff --git a/src/northbridge/intel/haswell/native_raminit/Makefile.inc b/src/northbridge/intel/haswell/native_raminit/Makefile.inc
  22. index 2769e0bbb4..fc55277a65 100644
  23. --- a/src/northbridge/intel/haswell/native_raminit/Makefile.inc
  24. +++ b/src/northbridge/intel/haswell/native_raminit/Makefile.inc
  25. @@ -1,8 +1,10 @@
  26. ## SPDX-License-Identifier: GPL-2.0-or-later
  27. +romstage-y += configure_mc.c
  28. romstage-y += lookup_timings.c
  29. romstage-y += init_mpll.c
  30. romstage-y += io_comp_control.c
  31. romstage-y += raminit_main.c
  32. romstage-y += raminit_native.c
  33. romstage-y += spd_bitmunching.c
  34. +romstage-y += timings_refresh.c
  35. diff --git a/src/northbridge/intel/haswell/native_raminit/configure_mc.c b/src/northbridge/intel/haswell/native_raminit/configure_mc.c
  36. new file mode 100644
  37. index 0000000000..2a667b075b
  38. --- /dev/null
  39. +++ b/src/northbridge/intel/haswell/native_raminit/configure_mc.c
  40. @@ -0,0 +1,822 @@
  41. +/* SPDX-License-Identifier: GPL-2.0-or-later */
  42. +
  43. +#include <assert.h>
  44. +#include <commonlib/clamp.h>
  45. +#include <console/console.h>
  46. +#include <delay.h>
  47. +#include <lib.h>
  48. +#include <northbridge/intel/haswell/haswell.h>
  49. +#include <string.h>
  50. +#include <types.h>
  51. +
  52. +#include "raminit_native.h"
  53. +
  54. +static void program_misc_control(struct sysinfo *ctrl)
  55. +{
  56. + if (!is_hsw_ult())
  57. + return;
  58. +
  59. + const union ddr_scram_misc_control_reg ddr_scram_misc_ctrl = {
  60. + .ddr_no_ch_interleave = !ctrl->dq_pins_interleaved,
  61. + .lpddr_mode = ctrl->lpddr,
  62. + .cke_mapping_ch0 = ctrl->lpddr ? ctrl->lpddr_cke_rank_map[0] : 0,
  63. + .cke_mapping_ch1 = ctrl->lpddr ? ctrl->lpddr_cke_rank_map[1] : 0,
  64. + };
  65. + mchbar_write32(DDR_SCRAM_MISC_CONTROL, ddr_scram_misc_ctrl.raw);
  66. +}
  67. +
  68. +static void program_mrc_revision(void)
  69. +{
  70. + mchbar_write32(MRC_REVISION, 0x01090000); /* MRC 1.9.0 Build 0 */
  71. +}
  72. +
  73. +static void program_ranks_used(struct sysinfo *ctrl)
  74. +{
  75. + for (uint8_t channel = 0; channel < NUM_CHANNELS; channel++) {
  76. + mchbar_write8(MC_INIT_STATE_ch(channel), ctrl->rankmap[channel]);
  77. + if (!does_ch_exist(ctrl, channel)) {
  78. + mchbar_write32(DDR_CLK_ch_RANKS_USED(channel), 0);
  79. + mchbar_write32(DDR_CTL_ch_CTL_RANKS_USED(channel), 0);
  80. + mchbar_write32(DDR_CKE_ch_CTL_RANKS_USED(channel), 0);
  81. + continue;
  82. + }
  83. + uint32_t clk_ranks_used = ctrl->rankmap[channel];
  84. + if (ctrl->lpddr) {
  85. + /* With LPDDR, the clock usage goes by group instead */
  86. + clk_ranks_used = 0;
  87. + for (uint8_t group = 0; group < NUM_GROUPS; group++) {
  88. + if (ctrl->dq_byte_map[channel][CT_ITERATION_CLOCK][group])
  89. + clk_ranks_used |= BIT(group);
  90. + }
  91. + }
  92. + mchbar_write32(DDR_CLK_ch_RANKS_USED(channel), clk_ranks_used);
  93. +
  94. + uint32_t ctl_ranks_used = ctrl->rankmap[channel];
  95. + if (is_hsw_ult()) {
  96. + /* Set ODT disable bits */
  97. + /** TODO: May need to do this after JEDEC reset/init **/
  98. + if (ctrl->lpddr && ctrl->lpddr_dram_odt)
  99. + ctl_ranks_used |= 2 << 4; /* ODT is used on rank 0 */
  100. + else
  101. + ctl_ranks_used |= 3 << 4;
  102. + }
  103. + mchbar_write32(DDR_CTL_ch_CTL_RANKS_USED(channel), ctl_ranks_used);
  104. +
  105. + uint32_t cke_ranks_used = ctrl->rankmap[channel];
  106. + if (ctrl->lpddr) {
  107. + /* Use CKE-to-rank mapping for LPDDR */
  108. + const uint8_t cke_rank_map = ctrl->lpddr_cke_rank_map[channel];
  109. + cke_ranks_used = 0;
  110. + for (uint8_t rank = 0; rank < NUM_SLOTRANKS; rank++) {
  111. + /* ULT only has 2 ranks per channel */
  112. + if (rank >= 2)
  113. + break;
  114. +
  115. + if (!rank_in_ch(ctrl, rank, channel))
  116. + continue;
  117. +
  118. + for (uint8_t cke = 0; cke < 4; cke++) {
  119. + if (rank == ((cke_rank_map >> cke) & 1))
  120. + cke_ranks_used |= BIT(cke);
  121. + }
  122. + }
  123. + }
  124. + mchbar_write32(DDR_CKE_ch_CTL_RANKS_USED(channel), cke_ranks_used);
  125. + }
  126. +}
  127. +
  128. +static const uint8_t rxb_trad[2][5][4] = {
  129. + { /* Vdd low */
  130. + /* 1067 MHz, 1333 MHz, 1600 MHz, 1867 MHz, 2133 MHz, */
  131. + {4, 3, 3, 2}, {4, 4, 3, 2}, {5, 4, 3, 3}, {5, 4, 4, 3}, {5, 4, 4, 3},
  132. + },
  133. + { /* Vdd hi */
  134. + /* 1067 MHz, 1333 MHz, 1600 MHz, 1867 MHz, 2133 MHz, */
  135. + {4, 3, 3, 2}, {4, 4, 3, 2}, {5, 4, 3, 3}, {5, 4, 4, 3}, {4, 4, 3, 3},
  136. + },
  137. +};
  138. +
  139. +static const uint8_t rxb_ultx[2][3][4] = {
  140. + { /* Vdd low */
  141. + /* 1067 MHz, 1333 MHz, 1600 MHz, */
  142. + {5, 6, 6, 5}, {5, 6, 6, 5}, {4, 6, 6, 6},
  143. + },
  144. + { /* Vdd hi */
  145. + /* 1067 MHz, 1333 MHz, 1600 MHz, */
  146. + {7, 6, 6, 5}, {7, 6, 6, 5}, {7, 6, 6, 6},
  147. + },
  148. +};
  149. +
  150. +uint8_t get_rx_bias(const struct sysinfo *ctrl)
  151. +{
  152. + const bool is_ult = is_hsw_ult();
  153. + const bool vddhi = ctrl->vdd_mv > 1350;
  154. + const uint8_t max_rxf = is_ult ? ARRAY_SIZE(rxb_ultx[0]) : ARRAY_SIZE(rxb_trad[0]);
  155. + const uint8_t ref_clk = ctrl->base_freq == 133 ? 4 : 6;
  156. + const uint8_t rx_f = clamp_s8(0, ctrl->multiplier - ref_clk, max_rxf - 1);
  157. + const uint8_t rx_cb = mchbar_read32(DDR_CLK_CB_STATUS) & 0x3;
  158. + if (is_ult)
  159. + return rxb_ultx[vddhi][rx_f][rx_cb];
  160. + else
  161. + return rxb_trad[vddhi][rx_f][rx_cb];
  162. +}
  163. +
  164. +static void program_ddr_data(struct sysinfo *ctrl, const bool dis_odt_static, const bool vddhi)
  165. +{
  166. + const bool is_ult = is_hsw_ult();
  167. +
  168. + for (uint8_t rank = 0; rank < NUM_SLOTRANKS; rank++) {
  169. + if (!does_rank_exist(ctrl, rank))
  170. + continue;
  171. +
  172. + const union ddr_data_rx_train_rank_reg rx_train = {
  173. + .rcven = 64,
  174. + .dqs_p = 32,
  175. + .dqs_n = 32,
  176. + };
  177. + mchbar_write32(DDR_DATA_RX_TRAIN_RANK(rank), rx_train.raw);
  178. + mchbar_write32(DDR_DATA_RX_PER_BIT_RANK(rank), 0x88888888);
  179. +
  180. + const union ddr_data_tx_train_rank_reg tx_train = {
  181. + .tx_eq = TXEQFULLDRV | 11,
  182. + .dq_delay = 96,
  183. + .dqs_delay = 64,
  184. + };
  185. + mchbar_write32(DDR_DATA_TX_TRAIN_RANK(rank), tx_train.raw);
  186. + mchbar_write32(DDR_DATA_TX_PER_BIT_RANK(rank), 0x88888888);
  187. +
  188. + for (uint8_t channel = 0; channel < NUM_CHANNELS; channel++) {
  189. + for (uint8_t byte = 0; byte < ctrl->lanes; byte++) {
  190. + ctrl->tx_dq[channel][rank][byte] = tx_train.dq_delay;
  191. + ctrl->txdqs[channel][rank][byte] = tx_train.dqs_delay;
  192. + ctrl->tx_eq[channel][rank][byte] = tx_train.tx_eq;
  193. +
  194. + ctrl->rcven[channel][rank][byte] = rx_train.rcven;
  195. + ctrl->rxdqsp[channel][rank][byte] = rx_train.dqs_p;
  196. + ctrl->rxdqsn[channel][rank][byte] = rx_train.dqs_n;
  197. + ctrl->rx_eq[channel][rank][byte] = rx_train.rx_eq;
  198. + }
  199. + }
  200. + }
  201. + mchbar_write32(DDR_DATA_TX_XTALK, 0);
  202. + mchbar_write32(DDR_DATA_RX_OFFSET_VDQ, 0x88888888);
  203. + mchbar_write32(DDR_DATA_OFFSET_TRAIN, 0);
  204. + mchbar_write32(DDR_DATA_OFFSET_COMP, 0);
  205. +
  206. + const union ddr_data_control_0_reg data_control_0 = {
  207. + .internal_clocks_on = !is_ult,
  208. + .data_vccddq_hi = vddhi,
  209. + .disable_odt_static = dis_odt_static,
  210. + .lpddr_mode = ctrl->lpddr,
  211. + .odt_samp_extend_en = ctrl->lpddr,
  212. + .early_rleak_en = ctrl->lpddr && ctrl->stepping >= STEPPING_C0,
  213. + };
  214. + mchbar_write32(DDR_DATA_CONTROL_0, data_control_0.raw);
  215. +
  216. + const union ddr_data_control_1_reg data_control_1 = {
  217. + .dll_mask = 1,
  218. + .rx_bias_ctl = get_rx_bias(ctrl),
  219. + .odt_delay = -2,
  220. + .odt_duration = 7,
  221. + .sense_amp_delay = -2,
  222. + .sense_amp_duration = 7,
  223. + };
  224. + mchbar_write32(DDR_DATA_CONTROL_1, data_control_1.raw);
  225. +
  226. + clear_data_offset_train_all(ctrl);
  227. +
  228. + /* Stagger byte turn-on to reduce dI/dT */
  229. + const uint8_t byte_stagger[] = { 0, 4, 1, 5, 2, 6, 3, 7, 8 };
  230. + const uint8_t latency = 2 * ctrl->tAA - 6;
  231. + for (uint8_t channel = 0; channel < NUM_CHANNELS; channel++) {
  232. + if (!does_ch_exist(ctrl, channel))
  233. + continue;
  234. +
  235. + union ddr_data_control_2_reg data_control_2 = {
  236. + .raw = 0,
  237. + };
  238. + if (is_ult) {
  239. + data_control_2.rx_dqs_amp_offset = 8;
  240. + data_control_2.rx_clk_stg_num = 0x1f;
  241. + data_control_2.leaker_comp = ctrl->lpddr ? 3 : 0;
  242. + }
  243. + for (uint8_t byte = 0; byte < ctrl->lanes; byte++) {
  244. + const uint8_t stg = latency * byte_stagger[byte] / ctrl->lanes;
  245. + data_control_2.rx_stagger_ctl = stg & 0x1f;
  246. + mchbar_write32(DQ_CONTROL_2(channel, byte), data_control_2.raw);
  247. + ctrl->data_offset_comp[channel][byte] = 0;
  248. + ctrl->dq_control_1[channel][byte] = data_control_1.raw;
  249. + ctrl->dq_control_2[channel][byte] = data_control_2.raw;
  250. + }
  251. + ctrl->dq_control_0[channel] = data_control_0.raw;
  252. + }
  253. +}
  254. +
  255. +static void program_vsshi_control(struct sysinfo *ctrl, const uint16_t vsshi_mv)
  256. +{
  257. + const uint32_t vsshi_control_reg = is_hsw_ult() ? 0x366c : 0x306c;
  258. + const union ddr_comp_vsshi_control_reg ddr_vsshi_control = {
  259. + .vsshi_target = (vsshi_mv * 192) / ctrl->vdd_mv - 20,
  260. + .hi_bw_divider = 1,
  261. + .lo_bw_divider = 1,
  262. + .bw_error = 2,
  263. + .panic_driver_en = 1,
  264. + .panic_voltage = 24 / 8, /* Voltage in 8mV steps */
  265. + .gain_boost = 1,
  266. + };
  267. + mchbar_write32(vsshi_control_reg, ddr_vsshi_control.raw);
  268. + mchbar_write32(DDR_COMP_VSSHI_CONTROL, ddr_vsshi_control.raw);
  269. +}
  270. +
  271. +static void calc_vt_slope_code(const uint16_t slope, uint8_t *best_a, uint8_t *best_b)
  272. +{
  273. + const int16_t coding[] = {0, -125, -62, -31, 250, 125, 62, 31};
  274. + *best_a = 0;
  275. + *best_b = 0;
  276. + int16_t best_err = slope;
  277. + for (uint8_t b = 0; b < ARRAY_SIZE(coding); b++) {
  278. + for (uint8_t a = b; a < ARRAY_SIZE(coding); a++) {
  279. + int16_t error = slope - (coding[a] + coding[b]);
  280. + if (error < 0)
  281. + error = -error;
  282. +
  283. + if (error < best_err) {
  284. + best_err = error;
  285. + *best_a = a;
  286. + *best_b = b;
  287. + }
  288. + }
  289. + }
  290. +}
  291. +
  292. +static void program_dimm_vref(struct sysinfo *ctrl, const uint16_t vccio_mv, const bool vddhi)
  293. +{
  294. + const bool is_ult = is_hsw_ult();
  295. +
  296. + /* Static values for ULT */
  297. + uint8_t vt_slope_a = 4;
  298. + uint8_t vt_slope_b = 0;
  299. + if (!is_ult) {
  300. + /* On non-ULT, compute best slope code */
  301. + const uint16_t vt_slope = 1500 * vccio_mv / ctrl->vdd_mv - 1000;
  302. + calc_vt_slope_code(vt_slope, &vt_slope_a, &vt_slope_b);
  303. + }
  304. + const union ddr_data_vref_control_reg ddr_vref_control = {
  305. + .hi_bw_divider = is_ult ? 0 : 3,
  306. + .lo_bw_divider = 3,
  307. + .sample_divider = is_ult ? 1 : 3,
  308. + .slow_bw_error = 1,
  309. + .hi_bw_enable = 1,
  310. + .vt_slope_b = vt_slope_b,
  311. + .vt_slope_a = vt_slope_a,
  312. + .vt_offset = 0,
  313. + };
  314. + mchbar_write32(is_ult ? 0xf68 : 0xf6c, ddr_vref_control.raw); /* Use CH1 byte 7 */
  315. +
  316. + const union ddr_data_vref_adjust_reg ddr_vref_adjust = {
  317. + .en_dimm_vref_ca = 1,
  318. + .en_dimm_vref_ch0 = 1,
  319. + .en_dimm_vref_ch1 = 1,
  320. + .vccddq_hi_qnnn_h = vddhi,
  321. + .hi_z_timer_ctrl = 3,
  322. + };
  323. + ctrl->dimm_vref = ddr_vref_adjust;
  324. + mchbar_write32(DDR_DATA_VREF_ADJUST, ddr_vref_adjust.raw);
  325. +}
  326. +
  327. +static uint32_t pi_code(const uint32_t code)
  328. +{
  329. + return code << 21 | code << 14 | code << 7 | code << 0;
  330. +}
  331. +
  332. +static void program_ddr_ca(struct sysinfo *ctrl, const bool vddhi)
  333. +{
  334. + for (uint8_t channel = 0; channel < NUM_CHANNELS; channel++) {
  335. + if (!does_ch_exist(ctrl, channel))
  336. + continue;
  337. +
  338. + const union ddr_clk_controls_reg ddr_clk_controls = {
  339. + .dll_mask = 1,
  340. + .vccddq_hi = vddhi,
  341. + .lpddr_mode = ctrl->lpddr,
  342. + };
  343. + mchbar_write32(DDR_CLK_ch_CONTROLS(channel), ddr_clk_controls.raw);
  344. +
  345. + const union ddr_cmd_controls_reg ddr_cmd_controls = {
  346. + .dll_mask = 1,
  347. + .vccddq_hi = vddhi,
  348. + .lpddr_mode = ctrl->lpddr,
  349. + .early_weak_drive = 3,
  350. + .cmd_tx_eq = 1,
  351. + };
  352. + mchbar_write32(DDR_CMD_ch_CONTROLS(channel), ddr_cmd_controls.raw);
  353. +
  354. + const union ddr_cke_ctl_controls_reg ddr_cke_controls = {
  355. + .dll_mask = 1,
  356. + .vccddq_hi = vddhi,
  357. + .lpddr_mode = ctrl->lpddr,
  358. + .early_weak_drive = 3,
  359. + .cmd_tx_eq = 1,
  360. + .ctl_tx_eq = 1,
  361. + .ctl_sr_drv = 2,
  362. + };
  363. + mchbar_write32(DDR_CKE_ch_CTL_CONTROLS(channel), ddr_cke_controls.raw);
  364. +
  365. + const union ddr_cke_ctl_controls_reg ddr_ctl_controls = {
  366. + .dll_mask = 1,
  367. + .vccddq_hi = vddhi,
  368. + .lpddr_mode = ctrl->lpddr,
  369. + .ctl_tx_eq = 1,
  370. + .ctl_sr_drv = 2,
  371. + .la_drv_en_ovrd = 1, /* Must be set on ULT */
  372. + };
  373. + mchbar_write32(DDR_CTL_ch_CTL_CONTROLS(channel), ddr_ctl_controls.raw);
  374. +
  375. + const uint8_t cmd_pi = ctrl->lpddr ? 96 : 64;
  376. + mchbar_write32(DDR_CMD_ch_PI_CODING(channel), pi_code(cmd_pi));
  377. + mchbar_write32(DDR_CKE_ch_CMD_PI_CODING(channel), pi_code(cmd_pi));
  378. + mchbar_write32(DDR_CKE_CTL_ch_CTL_PI_CODING(channel), pi_code(64));
  379. + mchbar_write32(DDR_CLK_ch_PI_CODING(channel), pi_code(64));
  380. +
  381. + mchbar_write32(DDR_CMD_ch_COMP_OFFSET(channel), 0);
  382. + mchbar_write32(DDR_CLK_ch_COMP_OFFSET(channel), 0);
  383. + mchbar_write32(DDR_CKE_CTL_ch_CTL_COMP_OFFSET(channel), 0);
  384. +
  385. + for (uint8_t group = 0; group < NUM_GROUPS; group++) {
  386. + ctrl->cke_cmd_pi_code[channel][group] = cmd_pi;
  387. + ctrl->cmd_north_pi_code[channel][group] = cmd_pi;
  388. + ctrl->cmd_south_pi_code[channel][group] = cmd_pi;
  389. + }
  390. + for (uint8_t rank = 0; rank < NUM_SLOTRANKS; rank++) {
  391. + ctrl->clk_pi_code[channel][rank] = 64;
  392. + ctrl->ctl_pi_code[channel][rank] = 64;
  393. + }
  394. + }
  395. +}
  396. +
  397. +enum {
  398. + RCOMP_RD_ODT = 0,
  399. + RCOMP_WR_DS_DQ,
  400. + RCOMP_WR_DS_CMD,
  401. + RCOMP_WR_DS_CTL,
  402. + RCOMP_WR_DS_CLK,
  403. + RCOMP_MAX_CODES,
  404. +};
  405. +
  406. +struct rcomp_info {
  407. + uint8_t resistor;
  408. + uint8_t sz_steps;
  409. + uint8_t target_r;
  410. + int8_t result;
  411. +};
  412. +
  413. +static void program_rcomp_vref(struct sysinfo *ctrl, const bool dis_odt_static)
  414. +{
  415. + const bool is_ult = is_hsw_ult();
  416. + /*
  417. + * +-------------------------------+
  418. + * | Rcomp resistor values in ohms |
  419. + * +-----------+------+------+-----+
  420. + * | Ball name | Trad | ULTX | Use |
  421. + * +-----------+------+------+-----+
  422. + * | SM_RCOMP0 | 100 | 200 | CMD |
  423. + * | SM_RCOMP1 | 75 | 120 | DQ |
  424. + * | SM_RCOMP2 | 100 | 100 | ODT |
  425. + * +-----------+------+------+-----+
  426. + */
  427. + struct rcomp_info rcomp_cfg[RCOMP_MAX_CODES] = {
  428. + [RCOMP_RD_ODT] = {
  429. + .resistor = 50,
  430. + .sz_steps = 96,
  431. + .target_r = 50,
  432. + },
  433. + [RCOMP_WR_DS_DQ] = {
  434. + .resistor = 25,
  435. + .sz_steps = 64,
  436. + .target_r = 33,
  437. + },
  438. + [RCOMP_WR_DS_CMD] = {
  439. + .resistor = 20,
  440. + .sz_steps = 64,
  441. + .target_r = 20,
  442. + },
  443. + [RCOMP_WR_DS_CTL] = {
  444. + .resistor = 20,
  445. + .sz_steps = 64,
  446. + .target_r = 20,
  447. + },
  448. + [RCOMP_WR_DS_CLK] = {
  449. + .resistor = 25,
  450. + .sz_steps = 64,
  451. + .target_r = 29,
  452. + },
  453. + };
  454. + if (is_ult) {
  455. + rcomp_cfg[RCOMP_WR_DS_DQ].resistor = 40;
  456. + rcomp_cfg[RCOMP_WR_DS_DQ].target_r = 40;
  457. + rcomp_cfg[RCOMP_WR_DS_CLK].resistor = 40;
  458. + } else if (ctrl->dpc[0] == 2 || ctrl->dpc[1] == 2) {
  459. + rcomp_cfg[RCOMP_RD_ODT].target_r = 60;
  460. + }
  461. + for (uint8_t i = 0; i < RCOMP_MAX_CODES; i++) {
  462. + struct rcomp_info *const r = &rcomp_cfg[i];
  463. + const int32_t div = 2 * (r->resistor + r->target_r);
  464. + assert(div);
  465. + const int32_t vref = (r->sz_steps * (r->resistor - r->target_r)) / div;
  466. +
  467. + /* DqOdt is 5 bits wide, the other Rcomp targets are 4 bits wide */
  468. + const int8_t comp_limit = i == RCOMP_RD_ODT ? 16 : 8;
  469. + r->result = clamp_s32(-comp_limit, vref, comp_limit - 1);
  470. + }
  471. + const union ddr_comp_ctl_0_reg ddr_comp_ctl_0 = {
  472. + .disable_odt_static = dis_odt_static,
  473. + .dq_drv_vref = rcomp_cfg[RCOMP_WR_DS_DQ].result,
  474. + .dq_odt_vref = rcomp_cfg[RCOMP_RD_ODT].result,
  475. + .cmd_drv_vref = rcomp_cfg[RCOMP_WR_DS_CMD].result,
  476. + .ctl_drv_vref = rcomp_cfg[RCOMP_WR_DS_CTL].result,
  477. + .clk_drv_vref = rcomp_cfg[RCOMP_WR_DS_CLK].result,
  478. + };
  479. + ctrl->comp_ctl_0 = ddr_comp_ctl_0;
  480. + mchbar_write32(DDR_COMP_CTL_0, ctrl->comp_ctl_0.raw);
  481. +}
  482. +
  483. +enum {
  484. + SCOMP_DQ = 0,
  485. + SCOMP_CMD,
  486. + SCOMP_CTL,
  487. + SCOMP_CLK,
  488. + SCOMP_MAX_CODES,
  489. +};
  490. +
  491. +static void program_slew_rates(struct sysinfo *ctrl, const bool vddhi)
  492. +{
  493. + const uint8_t min_cycle_delay[SCOMP_MAX_CODES] = { 46, 70, 70, 46 };
  494. + uint8_t buffer_stage_delay_ps[SCOMP_MAX_CODES] = { 59, 53, 53, 53 };
  495. + uint16_t comp_slew_rate_codes[SCOMP_MAX_CODES];
  496. +
  497. + /* CMD Slew Rate = 1.8 for 2N */
  498. + if (ctrl->tCMD == 2)
  499. + buffer_stage_delay_ps[SCOMP_CMD] = 89;
  500. +
  501. + /* CMD Slew Rate = 4 V/ns for double-pumped CMD bus */
  502. + if (ctrl->lpddr)
  503. + buffer_stage_delay_ps[SCOMP_CMD] = 63;
  504. +
  505. + for (uint8_t i = 0; i < SCOMP_MAX_CODES; i++) {
  506. + uint16_t stages = DIV_ROUND_CLOSEST(ctrl->qclkps, buffer_stage_delay_ps[i]);
  507. + if (stages < 5)
  508. + stages = 5;
  509. +
  510. + bool dll_pc = buffer_stage_delay_ps[i] < min_cycle_delay[i] || stages > 16;
  511. +
  512. + /* Lock DLL... */
  513. + if (dll_pc)
  514. + comp_slew_rate_codes[i] = stages / 2 - 1; /* to a phase */
  515. + else
  516. + comp_slew_rate_codes[i] = (stages - 1) | BIT(4); /* to a cycle */
  517. + }
  518. + union ddr_comp_ctl_1_reg ddr_comp_ctl_1 = {
  519. + .dq_scomp = comp_slew_rate_codes[SCOMP_DQ],
  520. + .cmd_scomp = comp_slew_rate_codes[SCOMP_CMD],
  521. + .ctl_scomp = comp_slew_rate_codes[SCOMP_CTL],
  522. + .clk_scomp = comp_slew_rate_codes[SCOMP_CLK],
  523. + .vccddq_hi = vddhi,
  524. + };
  525. + ctrl->comp_ctl_1 = ddr_comp_ctl_1;
  526. + mchbar_write32(DDR_COMP_CTL_1, ctrl->comp_ctl_1.raw);
  527. +}
  528. +
  529. +static uint32_t ln_x100(const uint32_t input_x100)
  530. +{
  531. + uint32_t val = input_x100;
  532. + uint32_t ret = 0;
  533. + while (val > 271) {
  534. + val = (val * 1000) / 2718;
  535. + ret += 100;
  536. + }
  537. + return ret + (-16 * val * val + 11578 * val - 978860) / 10000;
  538. +}
  539. +
  540. +static uint32_t compute_vsshi_vref(struct sysinfo *ctrl, const uint32_t vsshi_tgt, bool up)
  541. +{
  542. + const uint32_t delta = 15;
  543. + const uint32_t c_die_vsshi = 2000;
  544. + const uint32_t r_cmd_ref = 100 * 10;
  545. + const uint32_t offset = up ? 64 : 0;
  546. + const uint32_t ln_vsshi = ln_x100((100 * vsshi_tgt) / (vsshi_tgt - delta));
  547. + const uint32_t r_target = (ctrl->qclkps * 2000) / (c_die_vsshi * ln_vsshi);
  548. + const uint32_t r_dividend = 128 * (up ? r_cmd_ref : r_target);
  549. + return r_dividend / (r_cmd_ref + r_target) - offset;
  550. +}
  551. +
  552. +static void program_vsshi(struct sysinfo *ctrl, const uint16_t vccio_mv, const uint16_t vsshi)
  553. +{
  554. + const uint16_t vsshi_down = vsshi + 24; /* Panic threshold of 24 mV */
  555. + const uint16_t vsshi_up = vccio_mv - vsshi_down;
  556. + const union ddr_comp_vsshi_reg ddr_comp_vsshi = {
  557. + .panic_drv_down_vref = compute_vsshi_vref(ctrl, vsshi_down, false),
  558. + .panic_drv_up_vref = compute_vsshi_vref(ctrl, vsshi_up, true),
  559. + .vt_offset = 128 * 450 / vccio_mv / 2,
  560. + .vt_slope_a = 4,
  561. + };
  562. + mchbar_write32(DDR_COMP_VSSHI, ddr_comp_vsshi.raw);
  563. +}
  564. +
  565. +static void program_misc(struct sysinfo *ctrl)
  566. +{
  567. + ctrl->misc_control_0.raw = mchbar_read32(DDR_SCRAM_MISC_CONTROL);
  568. + ctrl->misc_control_0.weaklock_latency = 12;
  569. + ctrl->misc_control_0.wl_sleep_cycles = 5;
  570. + ctrl->misc_control_0.wl_wake_cycles = 2;
  571. + mchbar_write32(DDR_SCRAM_MISC_CONTROL, ctrl->misc_control_0.raw);
  572. + for (uint8_t channel = 0; channel < NUM_CHANNELS; channel++) {
  573. + /* Keep scrambling disabled for training */
  574. + mchbar_write32(DDR_SCRAMBLE_ch(channel), 0);
  575. + }
  576. +}
  577. +
  578. +/* Very weird, application-specific function */
  579. +static void override_comp(uint32_t value, uint32_t width, uint32_t shift, uint32_t offset)
  580. +{
  581. + const uint32_t mask = (1 << width) - 1;
  582. + uint32_t reg32 = mchbar_read32(offset);
  583. + reg32 &= ~(mask << shift);
  584. + reg32 |= (value << shift);
  585. + mchbar_write32(offset, reg32);
  586. +}
  587. +
  588. +static void program_ls_comp(struct sysinfo *ctrl)
  589. +{
  590. + /* Disable periodic COMP */
  591. + const union pcu_comp_reg m_comp = {
  592. + .comp_disable = 1,
  593. + .comp_interval = COMP_INT,
  594. + .comp_force = 1,
  595. + };
  596. + mchbar_write32(M_COMP, m_comp.raw);
  597. + udelay(10);
  598. +
  599. + /* Override level shifter compensation */
  600. + const uint32_t ls_comp = 2;
  601. + override_comp(ls_comp, 3, 28, DDR_DATA_RCOMP_DATA_1);
  602. + override_comp(ls_comp, 3, 24, DDR_CMD_COMP);
  603. + override_comp(ls_comp, 3, 24, DDR_CKE_CTL_COMP);
  604. + override_comp(ls_comp, 3, 23, DDR_CLK_COMP);
  605. + override_comp(ls_comp, 3, 28, DDR_COMP_DATA_COMP_1);
  606. + override_comp(ls_comp, 3, 24, DDR_COMP_CMD_COMP);
  607. + override_comp(ls_comp, 4, 24, DDR_COMP_CTL_COMP);
  608. + override_comp(ls_comp, 4, 23, DDR_COMP_CLK_COMP);
  609. + override_comp(ls_comp, 3, 24, DDR_COMP_OVERRIDE);
  610. +
  611. + /* Manually update the COMP values */
  612. + union ddr_scram_misc_control_reg ddr_scram_misc_ctrl = ctrl->misc_control_0;
  613. + ddr_scram_misc_ctrl.force_comp_update = 1;
  614. + mchbar_write32(DDR_SCRAM_MISC_CONTROL, ddr_scram_misc_ctrl.raw);
  615. +
  616. + /* Use a fixed offset between ODT Up/Dn */
  617. + const union ddr_comp_data_comp_1_reg data_comp_1 = {
  618. + .raw = mchbar_read32(DDR_COMP_DATA_COMP_1),
  619. + };
  620. + const uint32_t odt_offset = data_comp_1.rcomp_odt_down - data_comp_1.rcomp_odt_up;
  621. + ctrl->comp_ctl_0.odt_up_down_off = odt_offset;
  622. + ctrl->comp_ctl_0.fixed_odt_offset = 1;
  623. + mchbar_write32(DDR_COMP_CTL_0, ctrl->comp_ctl_0.raw);
  624. +}
  625. +
  626. +/** TODO: Deduplicate PCODE stuff, it's already implemented in CPU code **/
  627. +static bool pcode_ready(void)
  628. +{
  629. + const unsigned int delay_step = 10;
  630. + for (unsigned int i = 0; i < 1000; i += delay_step) {
  631. + if (!(mchbar_read32(BIOS_MAILBOX_INTERFACE) & MAILBOX_RUN_BUSY))
  632. + return true;
  633. +
  634. + udelay(delay_step);
  635. + };
  636. + return false;
  637. +}
  638. +
  639. +static uint32_t pcode_mailbox_read(const uint32_t command)
  640. +{
  641. + if (!pcode_ready()) {
  642. + printk(BIOS_ERR, "PCODE: mailbox timeout on wait ready\n");
  643. + return 0;
  644. + }
  645. + mchbar_write32(BIOS_MAILBOX_INTERFACE, command | MAILBOX_RUN_BUSY);
  646. + if (!pcode_ready()) {
  647. + printk(BIOS_ERR, "PCODE: mailbox timeout on completion\n");
  648. + return 0;
  649. + }
  650. + return mchbar_read32(BIOS_MAILBOX_DATA);
  651. +}
  652. +
  653. +static int pcode_mailbox_write(const uint32_t command, const uint32_t data)
  654. +{
  655. + if (!pcode_ready()) {
  656. + printk(BIOS_ERR, "PCODE: mailbox timeout on wait ready\n");
  657. + return -1;
  658. + }
  659. + mchbar_write32(BIOS_MAILBOX_DATA, data);
  660. + mchbar_write32(BIOS_MAILBOX_INTERFACE, command | MAILBOX_RUN_BUSY);
  661. + if (!pcode_ready()) {
  662. + printk(BIOS_ERR, "PCODE: mailbox timeout on completion\n");
  663. + return -1;
  664. + }
  665. + return 0;
  666. +}
  667. +
  668. +static void enable_2x_refresh(struct sysinfo *ctrl)
  669. +{
  670. + if (!CONFIG(ENABLE_DDR_2X_REFRESH))
  671. + return;
  672. +
  673. + printk(BIOS_DEBUG, "Enabling 2x Refresh\n");
  674. + const bool asr = ctrl->flags.asr;
  675. + const bool lpddr = ctrl->lpddr;
  676. +
  677. + /* Mutually exclusive */
  678. + assert(!asr || !lpddr);
  679. + if (!asr) {
  680. + uint32_t reg32 = pcode_mailbox_read(MAILBOX_BIOS_CMD_READ_DDR_2X_REFRESH);
  681. + if (!(reg32 & BIT(31))) { /** TODO: What to do if this is locked? **/
  682. + reg32 |= BIT(0); /* Enable 2x refresh */
  683. + reg32 |= BIT(31); /* Lock */
  684. +
  685. + if (lpddr)
  686. + reg32 |= 4 << 1; /* LPDDR MR4 1/2 tREFI */
  687. +
  688. + if (pcode_mailbox_write(MAILBOX_BIOS_CMD_WRITE_DDR_2X_REFRESH, reg32))
  689. + printk(BIOS_ERR, "Could not enable Mailbox 2x Refresh\n");
  690. + }
  691. + if (!lpddr)
  692. + return;
  693. + }
  694. + assert(asr || lpddr);
  695. + uint16_t refi_reduction = 50;
  696. + if (lpddr) {
  697. + refi_reduction = 97;
  698. + mchbar_clrbits32(PCU_DDR_PTM_CTL, 1 << 7); /* DISABLE_DRAM_TS */
  699. + }
  700. + /** TODO: Remember why this is only done on cold boots **/
  701. + if (ctrl->bootmode == BOOTMODE_COLD) {
  702. + ctrl->tREFI *= refi_reduction;
  703. + ctrl->tREFI /= 100;
  704. + }
  705. +}
  706. +
  707. +static void set_pcu_ddr_voltage(const uint16_t vdd_mv)
  708. +{
  709. + /** TODO: Handle other voltages? **/
  710. + uint32_t pcu_ddr_voltage;
  711. + switch (vdd_mv) {
  712. + case 1200:
  713. + pcu_ddr_voltage = 3;
  714. + break;
  715. + case 1350:
  716. + pcu_ddr_voltage = 1;
  717. + break;
  718. + default:
  719. + case 1500:
  720. + pcu_ddr_voltage = 0;
  721. + break;
  722. + }
  723. + /* Set bits 0..2 */
  724. + mchbar_write32(PCU_DDR_VOLTAGE, pcu_ddr_voltage);
  725. +}
  726. +
  727. +static void program_scheduler(struct sysinfo *ctrl)
  728. +{
  729. + /*
  730. + * ZQ calibration needs to be serialized for LPDDR3. Otherwise,
  731. + * the processor issues LPDDR3 ZQ calibration in parallel when
  732. + * exiting Package C7 or deeper. This causes problems for dual
  733. + * and quad die packages since all ranks share the same ZQ pin.
  734. + *
  735. + * Erratum HSM94: LPDDR3 ZQ Calibration Following Deep Package
  736. + * C-state Exit May Lead to Unpredictable System Behavior
  737. + */
  738. + const union mcscheds_cbit_reg mcscheds_cbit = {
  739. + .dis_write_gap = 1,
  740. + .dis_odt = is_hsw_ult() && !(ctrl->lpddr && ctrl->lpddr_dram_odt),
  741. + .serialize_zq = ctrl->lpddr,
  742. + };
  743. + mchbar_write32(MCSCHEDS_CBIT, mcscheds_cbit.raw);
  744. + mchbar_write32(MCMNTS_SC_WDBWM, 0x553c3038);
  745. + if (ctrl->lpddr) {
  746. + for (uint8_t channel = 0; channel < NUM_CHANNELS; channel++) {
  747. + if (!does_ch_exist(ctrl, channel))
  748. + continue;
  749. +
  750. + union mcmain_command_rate_limit_reg cmd_rate_limit = {
  751. + .raw = mchbar_read32(COMMAND_RATE_LIMIT_ch(channel)),
  752. + };
  753. + cmd_rate_limit.enable_cmd_limit = 1;
  754. + cmd_rate_limit.cmd_rate_limit = 3;
  755. + mchbar_write32(COMMAND_RATE_LIMIT_ch(channel), cmd_rate_limit.raw);
  756. + }
  757. + }
  758. +}
  759. +
  760. +static uint8_t biggest_channel(const struct sysinfo *const ctrl)
  761. +{
  762. + _Static_assert(NUM_CHANNELS == 2, "Code assumes exactly two channels");
  763. + return !!(ctrl->channel_size_mb[0] < ctrl->channel_size_mb[1]);
  764. +}
  765. +
  766. +static void dram_zones(struct sysinfo *ctrl)
  767. +{
  768. + /** TODO: Activate channel hash here, if enabled **/
  769. + const uint8_t biggest = biggest_channel(ctrl);
  770. + const uint8_t smaller = !biggest;
  771. +
  772. + /** TODO: Use stacked mode if Memory Trace is enabled **/
  773. + const union mad_chnl_reg mad_channel = {
  774. + .ch_a = biggest,
  775. + .ch_b = smaller,
  776. + .ch_c = 2,
  777. + .lpddr_mode = ctrl->lpddr,
  778. + };
  779. + mchbar_write32(MAD_CHNL, mad_channel.raw);
  780. +
  781. + const uint8_t channel_b_zone_size = ctrl->channel_size_mb[smaller] / 256;
  782. + const union mad_zr_reg mad_zr = {
  783. + .ch_b_double = channel_b_zone_size * 2,
  784. + .ch_b_single = channel_b_zone_size,
  785. + };
  786. + mchbar_write32(MAD_ZR, mad_zr.raw);
  787. +}
  788. +
  789. +static uint8_t biggest_dimm(const struct raminit_dimm_info *dimms)
  790. +{
  791. + _Static_assert(NUM_SLOTS <= 2, "Code assumes at most two DIMMs per channel.");
  792. + if (NUM_SLOTS == 1)
  793. + return 0;
  794. +
  795. + return !!(dimms[0].data.size_mb < dimms[1].data.size_mb);
  796. +}
  797. +
  798. +static void dram_dimm_mapping(struct sysinfo *ctrl)
  799. +{
  800. + for (uint8_t channel = 0; channel < NUM_CHANNELS; channel++) {
  801. + if (!does_ch_exist(ctrl, channel)) {
  802. + const union mad_dimm_reg mad_dimm = {
  803. + .rank_interleave = 1,
  804. + .enh_interleave = 1,
  805. + };
  806. + mchbar_write32(MAD_DIMM(channel), mad_dimm.raw);
  807. + continue;
  808. + }
  809. + const uint8_t biggest = biggest_dimm(ctrl->dimms[channel]);
  810. + const uint8_t smaller = !biggest;
  811. + const struct dimm_attr_ddr3_st *dimm_a = &ctrl->dimms[channel][biggest].data;
  812. + const struct dimm_attr_ddr3_st *dimm_b = &ctrl->dimms[channel][smaller].data;
  813. + union mad_dimm_reg mad_dimm = {
  814. + .dimm_a_size = dimm_a->size_mb / 256,
  815. + .dimm_b_size = dimm_b->size_mb / 256,
  816. + .dimm_a_sel = biggest,
  817. + .dimm_a_ranks = dimm_a->ranks == 2,
  818. + .dimm_b_ranks = dimm_b->ranks == 2,
  819. + .dimm_a_width = dimm_a->width == 16,
  820. + .dimm_b_width = dimm_b->width == 16,
  821. + .rank_interleave = 1,
  822. + .enh_interleave = 1,
  823. + .ecc_mode = 0, /* Do not enable ECC yet */
  824. + };
  825. + if (is_hsw_ult())
  826. + mad_dimm.dimm_b_width = mad_dimm.dimm_a_width;
  827. +
  828. + mchbar_write32(MAD_DIMM(channel), mad_dimm.raw);
  829. + if (ctrl->lpddr)
  830. + die("%s: Missing LPDDR support (LPDDR_MR_PARAMS)\n", __func__);
  831. + }
  832. +}
  833. +
  834. +enum raminit_status configure_mc(struct sysinfo *ctrl)
  835. +{
  836. + const uint16_t vccio_mv = 1000;
  837. + const uint16_t vsshi_mv = ctrl->vdd_mv - 950;
  838. + const bool dis_odt_static = is_hsw_ult(); /* Disable static ODT legs on ULT */
  839. + const bool vddhi = ctrl->vdd_mv > 1350;
  840. +
  841. + program_misc_control(ctrl);
  842. + program_mrc_revision();
  843. + program_ranks_used(ctrl);
  844. + program_ddr_data(ctrl, dis_odt_static, vddhi);
  845. + program_vsshi_control(ctrl, vsshi_mv);
  846. + program_dimm_vref(ctrl, vccio_mv, vddhi);
  847. + program_ddr_ca(ctrl, vddhi);
  848. + program_rcomp_vref(ctrl, dis_odt_static);
  849. + program_slew_rates(ctrl, vddhi);
  850. + program_vsshi(ctrl, vccio_mv, vsshi_mv);
  851. + program_misc(ctrl);
  852. + program_ls_comp(ctrl);
  853. + enable_2x_refresh(ctrl);
  854. + set_pcu_ddr_voltage(ctrl->vdd_mv);
  855. + configure_timings(ctrl);
  856. + configure_refresh(ctrl);
  857. + program_scheduler(ctrl);
  858. + dram_zones(ctrl);
  859. + dram_dimm_mapping(ctrl);
  860. +
  861. + return RAMINIT_STATUS_SUCCESS;
  862. +}
  863. diff --git a/src/northbridge/intel/haswell/native_raminit/raminit_main.c b/src/northbridge/intel/haswell/native_raminit/raminit_main.c
  864. index 5f2be980d4..3a773cfa19 100644
  865. --- a/src/northbridge/intel/haswell/native_raminit/raminit_main.c
  866. +++ b/src/northbridge/intel/haswell/native_raminit/raminit_main.c
  867. @@ -23,6 +23,7 @@ static const struct task_entry cold_boot[] = {
  868. { collect_spd_info, true, "PROCSPD", },
  869. { initialise_mpll, true, "INITMPLL", },
  870. { convert_timings, true, "CONVTIM", },
  871. + { configure_mc, true, "CONFMC", },
  872. };
  873. /* Return a generic stepping value to make stepping checks simpler */
  874. @@ -54,6 +55,7 @@ static void initialize_ctrl(struct sysinfo *ctrl)
  875. ctrl->cpu = cpu_get_cpuid();
  876. ctrl->stepping = get_stepping(ctrl->cpu);
  877. + ctrl->vdd_mv = is_hsw_ult() ? 1350 : 1500; /** FIXME: Hardcoded, does it matter? **/
  878. ctrl->dq_pins_interleaved = cfg->dq_pins_interleaved;
  879. ctrl->bootmode = bootmode;
  880. }
  881. diff --git a/src/northbridge/intel/haswell/native_raminit/raminit_native.h b/src/northbridge/intel/haswell/native_raminit/raminit_native.h
  882. index 01e5ed1bd6..aa86b9aa39 100644
  883. --- a/src/northbridge/intel/haswell/native_raminit/raminit_native.h
  884. +++ b/src/northbridge/intel/haswell/native_raminit/raminit_native.h
  885. @@ -3,15 +3,40 @@
  886. #ifndef HASWELL_RAMINIT_NATIVE_H
  887. #define HASWELL_RAMINIT_NATIVE_H
  888. +#include <assert.h>
  889. #include <device/dram/ddr3.h>
  890. #include <northbridge/intel/haswell/haswell.h>
  891. +#include <string.h>
  892. +#include <types.h>
  893. +
  894. +#include "reg_structs.h"
  895. #define SPD_LEN 256
  896. +/* Each channel has 4 ranks, spread across 2 slots */
  897. +#define NUM_SLOTRANKS 4
  898. +
  899. +#define NUM_GROUPS 2
  900. +
  901. /* 8 data lanes + 1 ECC lane */
  902. #define NUM_LANES 9
  903. #define NUM_LANES_NO_ECC 8
  904. +#define COMP_INT 10
  905. +
  906. +/* Always use 12 legs for emphasis (not trained) */
  907. +#define TXEQFULLDRV (3 << 4)
  908. +
  909. +enum command_training_iteration {
  910. + CT_ITERATION_CLOCK = 0,
  911. + CT_ITERATION_CMD_NORTH,
  912. + CT_ITERATION_CMD_SOUTH,
  913. + CT_ITERATION_CKE,
  914. + CT_ITERATION_CTL,
  915. + CT_ITERATION_CMD_VREF,
  916. + MAX_CT_ITERATION,
  917. +};
  918. +
  919. enum raminit_boot_mode {
  920. BOOTMODE_COLD,
  921. BOOTMODE_WARM,
  922. @@ -57,6 +82,9 @@ struct sysinfo {
  923. * LPDDR-specific functions have stubs which will halt upon execution.
  924. */
  925. bool lpddr;
  926. + bool lpddr_dram_odt;
  927. + uint8_t lpddr_cke_rank_map[NUM_CHANNELS];
  928. + uint8_t dq_byte_map[NUM_CHANNELS][MAX_CT_ITERATION][2];
  929. struct raminit_dimm_info dimms[NUM_CHANNELS][NUM_SLOTS];
  930. union dimm_flags_ddr3_st flags;
  931. @@ -93,16 +121,89 @@ struct sysinfo {
  932. uint32_t mem_clock_mhz;
  933. uint32_t mem_clock_fs; /* Memory clock period in femtoseconds */
  934. uint32_t qclkps; /* Quadrature clock period in picoseconds */
  935. +
  936. + uint16_t vdd_mv;
  937. +
  938. + union ddr_scram_misc_control_reg misc_control_0;
  939. +
  940. + union ddr_comp_ctl_0_reg comp_ctl_0;
  941. + union ddr_comp_ctl_1_reg comp_ctl_1;
  942. +
  943. + union ddr_data_vref_adjust_reg dimm_vref;
  944. +
  945. + uint32_t data_offset_train[NUM_CHANNELS][NUM_LANES];
  946. + uint32_t data_offset_comp[NUM_CHANNELS][NUM_LANES];
  947. +
  948. + uint32_t dq_control_0[NUM_CHANNELS];
  949. + uint32_t dq_control_1[NUM_CHANNELS][NUM_LANES];
  950. + uint32_t dq_control_2[NUM_CHANNELS][NUM_LANES];
  951. +
  952. + uint16_t tx_dq[NUM_CHANNELS][NUM_SLOTRANKS][NUM_LANES];
  953. + uint16_t txdqs[NUM_CHANNELS][NUM_SLOTRANKS][NUM_LANES];
  954. + uint8_t tx_eq[NUM_CHANNELS][NUM_SLOTRANKS][NUM_LANES];
  955. +
  956. + uint16_t rcven[NUM_CHANNELS][NUM_SLOTRANKS][NUM_LANES];
  957. + uint8_t rx_eq[NUM_CHANNELS][NUM_SLOTRANKS][NUM_LANES];
  958. + uint8_t rxdqsp[NUM_CHANNELS][NUM_SLOTRANKS][NUM_LANES];
  959. + uint8_t rxdqsn[NUM_CHANNELS][NUM_SLOTRANKS][NUM_LANES];
  960. + int8_t rxvref[NUM_CHANNELS][NUM_SLOTRANKS][NUM_LANES];
  961. +
  962. + uint8_t clk_pi_code[NUM_CHANNELS][NUM_SLOTRANKS];
  963. + uint8_t ctl_pi_code[NUM_CHANNELS][NUM_SLOTRANKS];
  964. + uint8_t cke_pi_code[NUM_CHANNELS][NUM_SLOTRANKS];
  965. +
  966. + uint8_t cke_cmd_pi_code[NUM_CHANNELS][NUM_GROUPS];
  967. + uint8_t cmd_north_pi_code[NUM_CHANNELS][NUM_GROUPS];
  968. + uint8_t cmd_south_pi_code[NUM_CHANNELS][NUM_GROUPS];
  969. };
  970. +static inline bool is_hsw_ult(void)
  971. +{
  972. + return CONFIG(INTEL_LYNXPOINT_LP);
  973. +}
  974. +
  975. +static inline bool rank_in_mask(uint8_t rank, uint8_t rankmask)
  976. +{
  977. + assert(rank < NUM_SLOTRANKS);
  978. + return !!(BIT(rank) & rankmask);
  979. +}
  980. +
  981. +static inline bool does_ch_exist(const struct sysinfo *ctrl, uint8_t channel)
  982. +{
  983. + return !!ctrl->dpc[channel];
  984. +}
  985. +
  986. +static inline bool does_rank_exist(const struct sysinfo *ctrl, uint8_t rank)
  987. +{
  988. + return rank_in_mask(rank, ctrl->rankmap[0] | ctrl->rankmap[1]);
  989. +}
  990. +
  991. +static inline bool rank_in_ch(const struct sysinfo *ctrl, uint8_t rank, uint8_t channel)
  992. +{
  993. + assert(channel < NUM_CHANNELS);
  994. + return rank_in_mask(rank, ctrl->rankmap[channel]);
  995. +}
  996. +
  997. +/** TODO: Handling of data_offset_train could be improved, also coupled with reg updates **/
  998. +static inline void clear_data_offset_train_all(struct sysinfo *ctrl)
  999. +{
  1000. + memset(ctrl->data_offset_train, 0, sizeof(ctrl->data_offset_train));
  1001. +}
  1002. +
  1003. void raminit_main(enum raminit_boot_mode bootmode);
  1004. enum raminit_status collect_spd_info(struct sysinfo *ctrl);
  1005. enum raminit_status initialise_mpll(struct sysinfo *ctrl);
  1006. enum raminit_status convert_timings(struct sysinfo *ctrl);
  1007. +enum raminit_status configure_mc(struct sysinfo *ctrl);
  1008. +
  1009. +void configure_timings(struct sysinfo *ctrl);
  1010. +void configure_refresh(struct sysinfo *ctrl);
  1011. enum raminit_status wait_for_first_rcomp(void);
  1012. +uint8_t get_rx_bias(const struct sysinfo *ctrl);
  1013. +
  1014. uint8_t get_tCWL(uint32_t mem_clock_mhz);
  1015. uint32_t get_tREFI(uint32_t mem_clock_mhz);
  1016. uint32_t get_tXP(uint32_t mem_clock_mhz);
  1017. diff --git a/src/northbridge/intel/haswell/native_raminit/reg_structs.h b/src/northbridge/intel/haswell/native_raminit/reg_structs.h
  1018. new file mode 100644
  1019. index 0000000000..d11cda4b3d
  1020. --- /dev/null
  1021. +++ b/src/northbridge/intel/haswell/native_raminit/reg_structs.h
  1022. @@ -0,0 +1,405 @@
  1023. +/* SPDX-License-Identifier: GPL-2.0-or-later */
  1024. +
  1025. +#ifndef HASWELL_RAMINIT_REG_STRUCTS_H
  1026. +#define HASWELL_RAMINIT_REG_STRUCTS_H
  1027. +
  1028. +union ddr_data_rx_train_rank_reg {
  1029. + struct __packed {
  1030. + uint32_t rcven : 9; // Bits 8:0
  1031. + uint32_t dqs_p : 6; // Bits 14:9
  1032. + uint32_t rx_eq : 5; // Bits 19:15
  1033. + uint32_t dqs_n : 6; // Bits 25:20
  1034. + int32_t vref : 6; // Bits 31:26
  1035. + };
  1036. + uint32_t raw;
  1037. +};
  1038. +
  1039. +union ddr_data_tx_train_rank_reg {
  1040. + struct __packed {
  1041. + uint32_t dq_delay : 9; // Bits 8:0
  1042. + uint32_t dqs_delay : 9; // Bits 17:9
  1043. + uint32_t : 2; // Bits 19:18
  1044. + uint32_t tx_eq : 6; // Bits 25:20
  1045. + uint32_t : 6; // Bits 31:26
  1046. + };
  1047. + uint32_t raw;
  1048. +};
  1049. +
  1050. +union ddr_data_control_0_reg {
  1051. + struct __packed {
  1052. + uint32_t rx_training_mode : 1; // Bits 0:0
  1053. + uint32_t wl_training_mode : 1; // Bits 1:1
  1054. + uint32_t rl_training_mode : 1; // Bits 2:2
  1055. + uint32_t samp_train_mode : 1; // Bits 3:3
  1056. + uint32_t tx_on : 1; // Bits 4:4
  1057. + uint32_t rf_on : 1; // Bits 5:5
  1058. + uint32_t rx_pi_on : 1; // Bits 6:6
  1059. + uint32_t tx_pi_on : 1; // Bits 7:7
  1060. + uint32_t internal_clocks_on : 1; // Bits 8:8
  1061. + uint32_t repeater_clocks_on : 1; // Bits 9:9
  1062. + uint32_t tx_disable : 1; // Bits 10:10
  1063. + uint32_t rx_disable : 1; // Bits 11:11
  1064. + uint32_t tx_long : 1; // Bits 12:12
  1065. + uint32_t rx_dqs_ctle : 2; // Bits 14:13
  1066. + uint32_t rx_read_pointer : 3; // Bits 17:15
  1067. + uint32_t driver_segment_enable : 1; // Bits 18:18
  1068. + uint32_t data_vccddq_hi : 1; // Bits 19:19
  1069. + uint32_t read_rf_rd : 1; // Bits 20:20
  1070. + uint32_t read_rf_wr : 1; // Bits 21:21
  1071. + uint32_t read_rf_rank : 2; // Bits 23:22
  1072. + uint32_t force_odt_on : 1; // Bits 24:24
  1073. + uint32_t odt_samp_off : 1; // Bits 25:25
  1074. + uint32_t disable_odt_static : 1; // Bits 26:26
  1075. + uint32_t ddr_cr_force_odt_on : 1; // Bits 27:27
  1076. + uint32_t lpddr_mode : 1; // Bits 28:28
  1077. + uint32_t en_read_preamble : 1; // Bits 29:29
  1078. + uint32_t odt_samp_extend_en : 1; // Bits 30:30
  1079. + uint32_t early_rleak_en : 1; // Bits 31:31
  1080. + };
  1081. + uint32_t raw;
  1082. +};
  1083. +
  1084. +union ddr_data_control_1_reg {
  1085. + struct __packed {
  1086. + int32_t ref_pi : 4; // Bits 3:0
  1087. + uint32_t dll_mask : 2; // Bits 5:4
  1088. + uint32_t dll_weaklock : 1; // Bits 6:6
  1089. + uint32_t sdll_segment_disable : 3; // Bits 9:7
  1090. + uint32_t rx_bias_ctl : 3; // Bits 12:10
  1091. + int32_t odt_delay : 4; // Bits 16:13
  1092. + uint32_t odt_duration : 3; // Bits 19:17
  1093. + int32_t sense_amp_delay : 4; // Bits 23:20
  1094. + uint32_t sense_amp_duration : 3; // Bits 26:24
  1095. + uint32_t burst_end_odt_delay : 3; // Bits 29:27 *** TODO: Check Broadwell ***
  1096. + uint32_t lpddr_long_odt_en : 1; // Bits 30:30
  1097. + uint32_t : 1; // Bits 31:31
  1098. + };
  1099. + uint32_t raw;
  1100. +};
  1101. +
  1102. +/* NOTE: Bits 31:19 are only valid for Broadwell onwards */
  1103. +union ddr_data_control_2_reg {
  1104. + struct __packed {
  1105. + uint32_t rx_stagger_ctl : 5; // Bits 4:0
  1106. + uint32_t force_bias_on : 1; // Bits 5:5
  1107. + uint32_t force_rx_on : 1; // Bits 6:6
  1108. + uint32_t leaker_comp : 2; // Bits 8:7
  1109. + uint32_t rx_dqs_amp_offset : 4; // Bits 12:9
  1110. + uint32_t rx_clk_stg_num : 5; // Bits 17:13
  1111. + uint32_t wl_long_delay : 1; // Bits 18:18
  1112. + uint32_t enable_vref_pwrdn : 1; // Bits 19:19
  1113. + uint32_t ddr4_mode : 1; // Bits 20:20
  1114. + uint32_t en_vddq_odt : 1; // Bits 21:21
  1115. + uint32_t en_vtt_odt : 1; // Bits 22:22
  1116. + uint32_t en_const_z_eq_tx : 1; // Bits 23:23
  1117. + uint32_t tx_eq_dis : 1; // Bits 24:24
  1118. + uint32_t rx_vref_prog_mfc : 1; // Bits 25:25
  1119. + uint32_t cben : 3; // Bits 28:26
  1120. + uint32_t tx_deskew_disable : 1; // Bits 29:29
  1121. + uint32_t rx_deskew_disable : 1; // Bits 30:30
  1122. + uint32_t dq_slew_dly_byp : 1; // Bits 31:31
  1123. + };
  1124. + uint32_t raw;
  1125. +};
  1126. +
  1127. +union ddr_comp_data_comp_1_reg {
  1128. + struct __packed {
  1129. + uint32_t rcomp_odt_up : 6; // Bits 5:0
  1130. + uint32_t : 3; // Bits 8:6
  1131. + uint32_t rcomp_odt_down : 6; // Bits 14:9
  1132. + uint32_t : 1; // Bits 15:15
  1133. + uint32_t panic_drv_down : 6; // Bits 21:16
  1134. + uint32_t panic_drv_up : 6; // Bits 27:22
  1135. + uint32_t ls_comp : 3; // Bits 30:28
  1136. + uint32_t : 1; // Bits 31:31
  1137. + };
  1138. + uint32_t raw;
  1139. +};
  1140. +
  1141. +union ddr_comp_ctl_0_reg {
  1142. + struct __packed {
  1143. + uint32_t : 3; // Bits 2:0
  1144. + uint32_t disable_odt_static : 1; // Bits 3:3
  1145. + uint32_t odt_up_down_off : 6; // Bits 9:4
  1146. + uint32_t fixed_odt_offset : 1; // Bits 10:10
  1147. + int32_t dq_drv_vref : 4; // Bits 14:11
  1148. + int32_t dq_odt_vref : 5; // Bits 19:15
  1149. + int32_t cmd_drv_vref : 4; // Bits 23:20
  1150. + int32_t ctl_drv_vref : 4; // Bits 27:24
  1151. + int32_t clk_drv_vref : 4; // Bits 31:28
  1152. + };
  1153. + uint32_t raw;
  1154. +};
  1155. +
  1156. +union ddr_comp_ctl_1_reg {
  1157. + struct __packed {
  1158. + uint32_t dq_scomp : 5; // Bits 4:0
  1159. + uint32_t cmd_scomp : 5; // Bits 9:5
  1160. + uint32_t ctl_scomp : 5; // Bits 14:10
  1161. + uint32_t clk_scomp : 5; // Bits 19:15
  1162. + uint32_t tco_cmd_offset : 4; // Bits 23:20
  1163. + uint32_t comp_clk_on : 1; // Bits 24:24
  1164. + uint32_t vccddq_hi : 1; // Bits 25:25
  1165. + uint32_t : 3; // Bits 28:26
  1166. + uint32_t dis_quick_comp : 1; // Bits 29:29
  1167. + uint32_t sin_step : 1; // Bits 30:30
  1168. + uint32_t sin_step_adv : 1; // Bits 31:31
  1169. + };
  1170. + uint32_t raw;
  1171. +};
  1172. +
  1173. +union ddr_data_vref_adjust_reg {
  1174. + struct __packed {
  1175. + int32_t ca_vref_ctrl : 7;// Bits 6:0
  1176. + int32_t ch1_vref_ctrl : 7;// Bits 13:7
  1177. + int32_t ch0_vref_ctrl : 7;// Bits 20:14
  1178. + uint32_t en_dimm_vref_ca : 1;// Bits 21:21
  1179. + uint32_t en_dimm_vref_ch1 : 1;// Bits 22:22
  1180. + uint32_t en_dimm_vref_ch0 : 1;// Bits 23:23
  1181. + uint32_t hi_z_timer_ctrl : 2;// Bits 25:24
  1182. + uint32_t vccddq_hi_qnnn_h : 1;// Bits 26:26
  1183. + uint32_t : 2;// Bits 28:27
  1184. + uint32_t ca_slow_bw : 1;// Bits 29:29
  1185. + uint32_t ch0_slow_bw : 1;// Bits 30:30
  1186. + uint32_t ch1_slow_bw : 1;// Bits 31:31
  1187. + };
  1188. + uint32_t raw;
  1189. +};
  1190. +
  1191. +union ddr_data_vref_control_reg {
  1192. + struct __packed {
  1193. + uint32_t hi_bw_divider : 2; // Bits 1:0
  1194. + uint32_t lo_bw_divider : 2; // Bits 3:2
  1195. + uint32_t sample_divider : 3; // Bits 6:4
  1196. + uint32_t open_loop : 1; // Bits 7:7
  1197. + uint32_t slow_bw_error : 2; // Bits 9:8
  1198. + uint32_t hi_bw_enable : 1; // Bits 10:10
  1199. + uint32_t : 1; // Bits 11:11
  1200. + uint32_t vt_slope_b : 3; // Bits 14:12
  1201. + uint32_t vt_slope_a : 3; // Bits 17:15
  1202. + uint32_t vt_offset : 3; // Bits 20:18
  1203. + uint32_t sel_code : 3; // Bits 23:21
  1204. + uint32_t output_code : 8; // Bits 31:24
  1205. + };
  1206. + uint32_t raw;
  1207. +};
  1208. +
  1209. +union ddr_comp_vsshi_reg {
  1210. + struct __packed {
  1211. + uint32_t panic_drv_down_vref : 6; // Bits 5:0
  1212. + uint32_t panic_drv_up_vref : 6; // Bits 11:6
  1213. + uint32_t vt_offset : 5; // Bits 16:12
  1214. + uint32_t vt_slope_a : 3; // Bits 19:17
  1215. + uint32_t vt_slope_b : 3; // Bits 22:20
  1216. + uint32_t : 9; // Bits 31:23
  1217. + };
  1218. + uint32_t raw;
  1219. +};
  1220. +
  1221. +union ddr_comp_vsshi_control_reg {
  1222. + struct __packed {
  1223. + uint32_t vsshi_target : 6; // Bits 5:0
  1224. + uint32_t hi_bw_divider : 2; // Bits 7:6
  1225. + uint32_t lo_bw_divider : 2; // Bits 9:8
  1226. + uint32_t sample_divider : 3; // Bits 12:10
  1227. + uint32_t open_loop : 1; // Bits 13:13
  1228. + uint32_t bw_error : 2; // Bits 15:14
  1229. + uint32_t panic_driver_en : 1; // Bits 16:16
  1230. + uint32_t : 1; // Bits 17:17
  1231. + uint32_t panic_voltage : 4; // Bits 21:18
  1232. + uint32_t gain_boost : 1; // Bits 22:22
  1233. + uint32_t sel_code : 1; // Bits 23:23
  1234. + uint32_t output_code : 8; // Bits 31:24
  1235. + };
  1236. + uint32_t raw;
  1237. +};
  1238. +
  1239. +union ddr_clk_controls_reg {
  1240. + struct __packed {
  1241. + uint32_t ref_pi : 4; // Bits 3:0
  1242. + uint32_t dll_mask : 2; // Bits 5:4
  1243. + uint32_t : 1; // Bits 6:6
  1244. + uint32_t tx_on : 1; // Bits 7:7
  1245. + uint32_t internal_clocks_on : 1; // Bits 8:8
  1246. + uint32_t repeater_clocks_on : 1; // Bits 9:9
  1247. + uint32_t io_lb_ctl : 2; // Bits 11:10
  1248. + uint32_t odt_mode : 1; // Bits 12:12
  1249. + uint32_t : 8; // Bits 20:13
  1250. + uint32_t rx_vref : 6; // Bits 26:21
  1251. + uint32_t vccddq_hi : 1; // Bits 27:27
  1252. + uint32_t dll_weaklock : 1; // Bits 28:28
  1253. + uint32_t lpddr_mode : 1; // Bits 29:29
  1254. + uint32_t : 2; // Bits 31:30
  1255. + };
  1256. + uint32_t raw;
  1257. +};
  1258. +
  1259. +union ddr_cmd_controls_reg {
  1260. + struct __packed {
  1261. + int32_t ref_pi : 4; // Bits 3:0
  1262. + uint32_t dll_mask : 2; // Bits 5:4
  1263. + uint32_t : 1; // Bits 6:6
  1264. + uint32_t tx_on : 1; // Bits 7:7
  1265. + uint32_t internal_clocks_on : 1; // Bits 8:8
  1266. + uint32_t repeater_clocks_on : 1; // Bits 9:9
  1267. + uint32_t io_lb_ctl : 2; // Bits 11:10
  1268. + uint32_t odt_mode : 1; // Bits 12:12
  1269. + uint32_t cmd_tx_eq : 2; // Bits 14:13
  1270. + uint32_t early_weak_drive : 2; // Bits 16:15
  1271. + uint32_t : 4; // Bits 20:17
  1272. + int32_t rx_vref : 6; // Bits 26:21
  1273. + uint32_t vccddq_hi : 1; // Bits 27:27
  1274. + uint32_t dll_weaklock : 1; // Bits 28:28
  1275. + uint32_t lpddr_mode : 1; // Bits 29:29
  1276. + uint32_t lpddr_ca_a_dis : 1; // Bits 30:30
  1277. + uint32_t lpddr_ca_b_dis : 1; // Bits 31:31
  1278. + };
  1279. + uint32_t raw;
  1280. +};
  1281. +
  1282. +/* Same register definition for CKE and CTL fubs */
  1283. +union ddr_cke_ctl_controls_reg {
  1284. + struct __packed {
  1285. + int32_t ref_pi : 4; // Bits 3:0
  1286. + uint32_t dll_mask : 2; // Bits 5:4
  1287. + uint32_t : 1; // Bits 6:6
  1288. + uint32_t tx_on : 1; // Bits 7:7
  1289. + uint32_t internal_clocks_on : 1; // Bits 8:8
  1290. + uint32_t repeater_clocks_on : 1; // Bits 9:9
  1291. + uint32_t io_lb_ctl : 2; // Bits 11:10
  1292. + uint32_t odt_mode : 1; // Bits 12:12
  1293. + uint32_t cmd_tx_eq : 2; // Bits 14:13
  1294. + uint32_t early_weak_drive : 2; // Bits 16:15
  1295. + uint32_t ctl_tx_eq : 2; // Bits 18:17
  1296. + uint32_t ctl_sr_drv : 2; // Bits 20:19
  1297. + int32_t rx_vref : 6; // Bits 26:21
  1298. + uint32_t vccddq_hi : 1; // Bits 27:27
  1299. + uint32_t dll_weaklock : 1; // Bits 28:28
  1300. + uint32_t lpddr_mode : 1; // Bits 29:29
  1301. + uint32_t la_drv_en_ovrd : 1; // Bits 30:30
  1302. + uint32_t lpddr_ca_a_dis : 1; // Bits 31:31
  1303. + };
  1304. + uint32_t raw;
  1305. +};
  1306. +
  1307. +union ddr_scram_misc_control_reg {
  1308. + struct __packed {
  1309. + uint32_t wl_wake_cycles : 2; // Bits 1:0
  1310. + uint32_t wl_sleep_cycles : 3; // Bits 4:2
  1311. + uint32_t force_comp_update : 1; // Bits 5:5
  1312. + uint32_t weaklock_latency : 4; // Bits 9:6
  1313. + uint32_t ddr_no_ch_interleave : 1; // Bits 10:10
  1314. + uint32_t lpddr_mode : 1; // Bits 11:11
  1315. + uint32_t cke_mapping_ch0 : 4; // Bits 15:12
  1316. + uint32_t cke_mapping_ch1 : 4; // Bits 19:16
  1317. + uint32_t : 12; // Bits 31:20
  1318. + };
  1319. + uint32_t raw;
  1320. +};
  1321. +
  1322. +union mcscheds_cbit_reg {
  1323. + struct __packed {
  1324. + uint32_t dis_opp_cas : 1; // Bits 0:0
  1325. + uint32_t dis_opp_is_cas : 1; // Bits 1:1
  1326. + uint32_t dis_opp_ras : 1; // Bits 2:2
  1327. + uint32_t dis_opp_is_ras : 1; // Bits 3:3
  1328. + uint32_t dis_1c_byp : 1; // Bits 4:4
  1329. + uint32_t dis_2c_byp : 1; // Bits 5:5
  1330. + uint32_t dis_deprd_opt : 1; // Bits 6:6
  1331. + uint32_t dis_pt_it : 1; // Bits 7:7
  1332. + uint32_t dis_prcnt_ring : 1; // Bits 8:8
  1333. + uint32_t dis_prcnt_sa : 1; // Bits 9:9
  1334. + uint32_t dis_blkr_ph : 1; // Bits 10:10
  1335. + uint32_t dis_blkr_pe : 1; // Bits 11:11
  1336. + uint32_t dis_blkr_pm : 1; // Bits 12:12
  1337. + uint32_t dis_odt : 1; // Bits 13:13
  1338. + uint32_t oe_always_off : 1; // Bits 14:14
  1339. + uint32_t : 1; // Bits 15:15
  1340. + uint32_t dis_aom : 1; // Bits 16:16
  1341. + uint32_t block_rpq : 1; // Bits 17:17
  1342. + uint32_t block_wpq : 1; // Bits 18:18
  1343. + uint32_t invert_align : 1; // Bits 19:19
  1344. + uint32_t dis_write_gap : 1; // Bits 20:20
  1345. + uint32_t dis_zq : 1; // Bits 21:21
  1346. + uint32_t dis_tt : 1; // Bits 22:22
  1347. + uint32_t dis_opp_ref : 1; // Bits 23:23
  1348. + uint32_t long_zq : 1; // Bits 24:24
  1349. + uint32_t dis_srx_zq : 1; // Bits 25:25
  1350. + uint32_t serialize_zq : 1; // Bits 26:26
  1351. + uint32_t zq_fast_exec : 1; // Bits 27:27
  1352. + uint32_t dis_drive_nop : 1; // Bits 28:28
  1353. + uint32_t pres_wdb_ent : 1; // Bits 29:29
  1354. + uint32_t dis_clk_gate : 1; // Bits 30:30
  1355. + uint32_t : 1; // Bits 31:31
  1356. + };
  1357. + uint32_t raw;
  1358. +};
  1359. +
  1360. +union mcmain_command_rate_limit_reg {
  1361. + struct __packed {
  1362. + uint32_t enable_cmd_limit : 1; // Bits 0:0
  1363. + uint32_t cmd_rate_limit : 3; // Bits 3:1
  1364. + uint32_t reset_on_command : 4; // Bits 7:4
  1365. + uint32_t reset_delay : 4; // Bits 11:8
  1366. + uint32_t ck_to_cke_delay : 2; // Bits 13:12
  1367. + uint32_t : 17; // Bits 30:14
  1368. + uint32_t init_mrw_2n_cs : 1; // Bits 31:31
  1369. + };
  1370. + uint32_t raw;
  1371. +};
  1372. +
  1373. +union mad_chnl_reg {
  1374. + struct __packed {
  1375. + uint32_t ch_a : 2; // Bits 1:0
  1376. + uint32_t ch_b : 2; // Bits 3:2
  1377. + uint32_t ch_c : 2; // Bits 5:4
  1378. + uint32_t stacked_mode : 1; // Bits 6:6
  1379. + uint32_t stkd_mode_bits : 3; // Bits 9:7
  1380. + uint32_t lpddr_mode : 1; // Bits 10:10
  1381. + uint32_t : 21; // Bits 31:11
  1382. + };
  1383. + uint32_t raw;
  1384. +};
  1385. +
  1386. +union mad_dimm_reg {
  1387. + struct __packed {
  1388. + uint32_t dimm_a_size : 8; // Bits 7:0
  1389. + uint32_t dimm_b_size : 8; // Bits 15:8
  1390. + uint32_t dimm_a_sel : 1; // Bits 16:16
  1391. + uint32_t dimm_a_ranks : 1; // Bits 17:17
  1392. + uint32_t dimm_b_ranks : 1; // Bits 18:18
  1393. + uint32_t dimm_a_width : 1; // Bits 19:19
  1394. + uint32_t dimm_b_width : 1; // Bits 20:20
  1395. + uint32_t rank_interleave : 1; // Bits 21:21
  1396. + uint32_t enh_interleave : 1; // Bits 22:22
  1397. + uint32_t : 1; // Bits 23:23
  1398. + uint32_t ecc_mode : 2; // Bits 25:24
  1399. + uint32_t hori_mode : 1; // Bits 26:26
  1400. + uint32_t hori_address : 3; // Bits 29:27
  1401. + uint32_t : 2; // Bits 31:30
  1402. + };
  1403. + uint32_t raw;
  1404. +};
  1405. +
  1406. +union mad_zr_reg {
  1407. + struct __packed {
  1408. + uint32_t : 16; // Bits 15:0
  1409. + uint32_t ch_b_double : 8; // Bits 23:16
  1410. + uint32_t ch_b_single : 8; // Bits 31:24
  1411. + };
  1412. + uint32_t raw;
  1413. +};
  1414. +
  1415. +/* Same definition for P_COMP, M_COMP, D_COMP */
  1416. +union pcu_comp_reg {
  1417. + struct __packed {
  1418. + uint32_t comp_disable : 1; // Bits 0:0
  1419. + uint32_t comp_interval : 4; // Bits 4:1
  1420. + uint32_t : 3; // Bits 7:5
  1421. + uint32_t comp_force : 1; // Bits 8:8
  1422. + uint32_t : 23; // Bits 31:9
  1423. + };
  1424. + uint32_t raw;
  1425. +};
  1426. +
  1427. +#endif
  1428. diff --git a/src/northbridge/intel/haswell/native_raminit/timings_refresh.c b/src/northbridge/intel/haswell/native_raminit/timings_refresh.c
  1429. new file mode 100644
  1430. index 0000000000..a9d960f31b
  1431. --- /dev/null
  1432. +++ b/src/northbridge/intel/haswell/native_raminit/timings_refresh.c
  1433. @@ -0,0 +1,13 @@
  1434. +/* SPDX-License-Identifier: GPL-2.0-or-later */
  1435. +
  1436. +#include "raminit_native.h"
  1437. +
  1438. +void configure_timings(struct sysinfo *ctrl)
  1439. +{
  1440. + /** TODO: Stub **/
  1441. +}
  1442. +
  1443. +void configure_refresh(struct sysinfo *ctrl)
  1444. +{
  1445. + /** TODO: Stub **/
  1446. +}
  1447. diff --git a/src/northbridge/intel/haswell/registers/mchbar.h b/src/northbridge/intel/haswell/registers/mchbar.h
  1448. index 45f8174995..4c3f399b5d 100644
  1449. --- a/src/northbridge/intel/haswell/registers/mchbar.h
  1450. +++ b/src/northbridge/intel/haswell/registers/mchbar.h
  1451. @@ -7,9 +7,98 @@
  1452. #define NUM_CHANNELS 2
  1453. #define NUM_SLOTS 2
  1454. +/* Indexed register helper macros */
  1455. +#define _DDRIO_C_R_B(r, ch, rank, byte) ((r) + 0x100 * (ch) + 0x4 * (rank) + 0x200 * (byte))
  1456. +#define _MCMAIN_C_X(r, ch, x) ((r) + 0x400 * (ch) + 0x4 * (x))
  1457. +#define _MCMAIN_C(r, ch) ((r) + 0x400 * (ch))
  1458. +
  1459. /* Register definitions */
  1460. +
  1461. +/* DDR DATA per-channel per-bytelane */
  1462. +#define DQ_CONTROL_2(ch, byte) _DDRIO_C_R_B(0x0064, ch, 0, byte)
  1463. +
  1464. +/* DDR CKE per-channel */
  1465. +#define DDR_CKE_ch_CMD_COMP_OFFSET(ch) _DDRIO_C_R_B(0x1204, ch, 0, 0)
  1466. +#define DDR_CKE_ch_CMD_PI_CODING(ch) _DDRIO_C_R_B(0x1208, ch, 0, 0)
  1467. +
  1468. +#define DDR_CKE_ch_CTL_CONTROLS(ch) _DDRIO_C_R_B(0x121c, ch, 0, 0)
  1469. +#define DDR_CKE_ch_CTL_RANKS_USED(ch) _DDRIO_C_R_B(0x1220, ch, 0, 0)
  1470. +
  1471. +/* DDR CTL per-channel */
  1472. +#define DDR_CTL_ch_CTL_CONTROLS(ch) _DDRIO_C_R_B(0x1c1c, ch, 0, 0)
  1473. +#define DDR_CTL_ch_CTL_RANKS_USED(ch) _DDRIO_C_R_B(0x1c20, ch, 0, 0)
  1474. +
  1475. +/* DDR CLK per-channel */
  1476. +#define DDR_CLK_ch_RANKS_USED(ch) _DDRIO_C_R_B(0x1800, ch, 0, 0)
  1477. +#define DDR_CLK_ch_COMP_OFFSET(ch) _DDRIO_C_R_B(0x1808, ch, 0, 0)
  1478. +#define DDR_CLK_ch_PI_CODING(ch) _DDRIO_C_R_B(0x180c, ch, 0, 0)
  1479. +#define DDR_CLK_ch_CONTROLS(ch) _DDRIO_C_R_B(0x1810, ch, 0, 0)
  1480. +
  1481. +/* DDR Scrambler */
  1482. +#define DDR_SCRAMBLE_ch(ch) (0x2000 + 4 * (ch))
  1483. +#define DDR_SCRAM_MISC_CONTROL 0x2008
  1484. +
  1485. +/* DDR CMDN/CMDS per-channel (writes go to both CMDN and CMDS fubs) */
  1486. +#define DDR_CMD_ch_COMP_OFFSET(ch) _DDRIO_C_R_B(0x3204, ch, 0, 0)
  1487. +#define DDR_CMD_ch_PI_CODING(ch) _DDRIO_C_R_B(0x3208, ch, 0, 0)
  1488. +#define DDR_CMD_ch_CONTROLS(ch) _DDRIO_C_R_B(0x320c, ch, 0, 0)
  1489. +
  1490. +/* DDR CKE/CTL per-channel (writes go to both CKE and CTL fubs) */
  1491. +#define DDR_CKE_CTL_ch_CTL_COMP_OFFSET(ch) _DDRIO_C_R_B(0x3414, ch, 0, 0)
  1492. +#define DDR_CKE_CTL_ch_CTL_PI_CODING(ch) _DDRIO_C_R_B(0x3418, ch, 0, 0)
  1493. +
  1494. +/* DDR DATA broadcast */
  1495. +#define DDR_DATA_RX_TRAIN_RANK(rank) _DDRIO_C_R_B(0x3600, 0, rank, 0)
  1496. +#define DDR_DATA_RX_PER_BIT_RANK(rank) _DDRIO_C_R_B(0x3610, 0, rank, 0)
  1497. +#define DDR_DATA_TX_TRAIN_RANK(rank) _DDRIO_C_R_B(0x3620, 0, rank, 0)
  1498. +#define DDR_DATA_TX_PER_BIT_RANK(rank) _DDRIO_C_R_B(0x3630, 0, rank, 0)
  1499. +
  1500. +#define DDR_DATA_RCOMP_DATA_1 0x3644
  1501. +#define DDR_DATA_TX_XTALK 0x3648
  1502. +#define DDR_DATA_RX_OFFSET_VDQ 0x364c
  1503. +#define DDR_DATA_OFFSET_COMP 0x365c
  1504. +#define DDR_DATA_CONTROL_1 0x3660
  1505. +
  1506. +#define DDR_DATA_OFFSET_TRAIN 0x3670
  1507. +#define DDR_DATA_CONTROL_0 0x3674
  1508. +#define DDR_DATA_VREF_ADJUST 0x3678
  1509. +
  1510. +/* DDR CMD broadcast */
  1511. +#define DDR_CMD_COMP 0x3700
  1512. +
  1513. +/* DDR CKE/CTL broadcast */
  1514. +#define DDR_CKE_CTL_COMP 0x3810
  1515. +
  1516. +/* DDR CLK broadcast */
  1517. +#define DDR_CLK_COMP 0x3904
  1518. +#define DDR_CLK_CONTROLS 0x3910
  1519. +#define DDR_CLK_CB_STATUS 0x3918
  1520. +
  1521. +/* DDR COMP (global) */
  1522. +#define DDR_COMP_DATA_COMP_1 0x3a04
  1523. +#define DDR_COMP_CMD_COMP 0x3a08
  1524. +#define DDR_COMP_CTL_COMP 0x3a0c
  1525. +#define DDR_COMP_CLK_COMP 0x3a10
  1526. +#define DDR_COMP_CTL_0 0x3a14
  1527. +#define DDR_COMP_CTL_1 0x3a18
  1528. +#define DDR_COMP_VSSHI 0x3a1c
  1529. +#define DDR_COMP_OVERRIDE 0x3a20
  1530. +#define DDR_COMP_VSSHI_CONTROL 0x3a24
  1531. +
  1532. +/* MCMAIN per-channel */
  1533. +#define COMMAND_RATE_LIMIT_ch(ch) _MCMAIN_C(0x4010, ch)
  1534. +
  1535. +#define MC_INIT_STATE_ch(ch) _MCMAIN_C(0x42a0, ch)
  1536. +
  1537. +/* MCMAIN broadcast */
  1538. +#define MCSCHEDS_CBIT 0x4c20
  1539. +
  1540. +#define MCMNTS_SC_WDBWM 0x4f8c
  1541. +
  1542. +/* MCDECS */
  1543. #define MAD_CHNL 0x5000 /* Address Decoder Channel Configuration */
  1544. #define MAD_DIMM(ch) (0x5004 + (ch) * 4)
  1545. +#define MAD_ZR 0x5014
  1546. #define MC_INIT_STATE_G 0x5030
  1547. #define MRC_REVISION 0x5034 /* MRC Revision */
  1548. @@ -28,6 +117,8 @@
  1549. #define PCU_DDR_PTM_CTL 0x5880
  1550. +#define PCU_DDR_VOLTAGE 0x58a4
  1551. +
  1552. /* Some power MSRs are also represented in MCHBAR */
  1553. #define MCH_PKG_POWER_LIMIT_LO 0x59a0
  1554. #define MCH_PKG_POWER_LIMIT_HI 0x59a4
  1555. @@ -48,6 +139,8 @@
  1556. #define MAILBOX_BIOS_CMD_FSM_MEASURE_INTVL 0x909
  1557. #define MAILBOX_BIOS_CMD_READ_PCH_POWER 0xa
  1558. #define MAILBOX_BIOS_CMD_READ_PCH_POWER_EXT 0xb
  1559. +#define MAILBOX_BIOS_CMD_READ_DDR_2X_REFRESH 0x17
  1560. +#define MAILBOX_BIOS_CMD_WRITE_DDR_2X_REFRESH 0x18
  1561. #define MAILBOX_BIOS_CMD_READ_C9C10_VOLTAGE 0x26
  1562. #define MAILBOX_BIOS_CMD_WRITE_C9C10_VOLTAGE 0x27
  1563. @@ -66,6 +159,7 @@
  1564. #define MC_BIOS_REQ 0x5e00 /* Memory frequency request register */
  1565. #define MC_BIOS_DATA 0x5e04 /* Miscellaneous information for BIOS */
  1566. #define SAPMCTL 0x5f00
  1567. +#define M_COMP 0x5f08
  1568. #define HDAUDRID 0x6008
  1569. #define UMAGFXCTL 0x6020
  1570. --
  1571. 2.39.2