1 // SPDX-License-Identifier: GPL-2.0+
4 * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
10 #include <dt-bindings/memory/mpc83xx-sdram.h>
12 DECLARE_GLOBAL_DATA_PTR;
14 /* Masks for the CS config register */
15 static const u32 CSCONFIG_ENABLE = 0x80000000;
17 static const u32 BANK_BITS_2;
18 static const u32 BANK_BITS_3 = 0x00004000;
20 static const u32 ROW_BITS_12;
21 static const u32 ROW_BITS_13 = 0x00000100;
22 static const u32 ROW_BITS_14 = 0x00000200;
24 static const u32 COL_BITS_8;
25 static const u32 COL_BITS_9 = 0x00000001;
26 static const u32 COL_BITS_10 = 0x00000002;
27 static const u32 COL_BITS_11 = 0x00000003;
29 /* Shifts for the DDR SDRAM Timing Configuration 3 register */
30 static const uint TIMING_CFG3_EXT_REFREC_SHIFT = (31 - 15);
32 /* Shifts for the DDR SDRAM Timing Configuration 0 register */
33 static const uint TIMING_CFG0_RWT_SHIFT = (31 - 1);
34 static const uint TIMING_CFG0_WRT_SHIFT = (31 - 3);
35 static const uint TIMING_CFG0_RRT_SHIFT = (31 - 5);
36 static const uint TIMING_CFG0_WWT_SHIFT = (31 - 7);
37 static const uint TIMING_CFG0_ACT_PD_EXIT_SHIFT = (31 - 11);
38 static const uint TIMING_CFG0_PRE_PD_EXIT_SHIFT = (31 - 15);
39 static const uint TIMING_CFG0_ODT_PD_EXIT_SHIFT = (31 - 23);
40 static const uint TIMING_CFG0_MRS_CYC_SHIFT = (31 - 31);
42 /* Shifts for the DDR SDRAM Timing Configuration 1 register */
43 static const uint TIMING_CFG1_PRETOACT_SHIFT = (31 - 3);
44 static const uint TIMING_CFG1_ACTTOPRE_SHIFT = (31 - 7);
45 static const uint TIMING_CFG1_ACTTORW_SHIFT = (31 - 11);
46 static const uint TIMING_CFG1_CASLAT_SHIFT = (31 - 15);
47 static const uint TIMING_CFG1_REFREC_SHIFT = (31 - 19);
48 static const uint TIMING_CFG1_WRREC_SHIFT = (31 - 23);
49 static const uint TIMING_CFG1_ACTTOACT_SHIFT = (31 - 27);
50 static const uint TIMING_CFG1_WRTORD_SHIFT = (31 - 31);
52 /* Shifts for the DDR SDRAM Timing Configuration 2 register */
53 static const uint TIMING_CFG2_CPO_SHIFT = (31 - 8);
54 static const uint TIMING_CFG2_WR_DATA_DELAY_SHIFT = (31 - 21);
55 static const uint TIMING_CFG2_ADD_LAT_SHIFT = (31 - 3);
56 static const uint TIMING_CFG2_WR_LAT_DELAY_SHIFT = (31 - 12);
57 static const uint TIMING_CFG2_RD_TO_PRE_SHIFT = (31 - 18);
58 static const uint TIMING_CFG2_CKE_PLS_SHIFT = (31 - 25);
59 static const uint TIMING_CFG2_FOUR_ACT_SHIFT;
61 /* Shifts for the DDR SDRAM Control Configuration register */
62 static const uint SDRAM_CFG_SREN_SHIFT = (31 - 1);
63 static const uint SDRAM_CFG_ECC_EN_SHIFT = (31 - 2);
64 static const uint SDRAM_CFG_RD_EN_SHIFT = (31 - 3);
65 static const uint SDRAM_CFG_SDRAM_TYPE_SHIFT = (31 - 7);
66 static const uint SDRAM_CFG_DYN_PWR_SHIFT = (31 - 10);
67 static const uint SDRAM_CFG_DBW_SHIFT = (31 - 12);
68 static const uint SDRAM_CFG_NCAP_SHIFT = (31 - 14);
69 static const uint SDRAM_CFG_2T_EN_SHIFT = (31 - 16);
70 static const uint SDRAM_CFG_BA_INTLV_CTL_SHIFT = (31 - 23);
71 static const uint SDRAM_CFG_PCHB8_SHIFT = (31 - 27);
72 static const uint SDRAM_CFG_HSE_SHIFT = (31 - 28);
73 static const uint SDRAM_CFG_BI_SHIFT = (31 - 31);
75 /* Shifts for the DDR SDRAM Control Configuration 2 register */
76 static const uint SDRAM_CFG2_FRC_SR_SHIFT = (31 - 0);
77 static const uint SDRAM_CFG2_DLL_RST_DIS = (31 - 2);
78 static const uint SDRAM_CFG2_DQS_CFG = (31 - 5);
79 static const uint SDRAM_CFG2_ODT_CFG = (31 - 10);
80 static const uint SDRAM_CFG2_NUM_PR = (31 - 19);
82 /* Shifts for the DDR SDRAM Mode register */
83 static const uint SDRAM_MODE_ESD_SHIFT = (31 - 15);
84 static const uint SDRAM_MODE_SD_SHIFT = (31 - 31);
86 /* Shifts for the DDR SDRAM Mode 2 register */
87 static const uint SDRAM_MODE2_ESD2_SHIFT = (31 - 15);
88 static const uint SDRAM_MODE2_ESD3_SHIFT = (31 - 31);
90 /* Shifts for the DDR SDRAM Interval Configuration register */
91 static const uint SDRAM_INTERVAL_REFINT_SHIFT = (31 - 15);
92 static const uint SDRAM_INTERVAL_BSTOPRE_SHIFT = (31 - 31);
94 /* Mask for the DDR SDRAM Mode Control register */
95 static const u32 SDRAM_CFG_MEM_EN = 0x80000000;
99 struct udevice *ram_ctrl;
102 /* Current assumption: There is only one RAM controller */
103 ret = uclass_first_device_err(UCLASS_RAM, &ram_ctrl);
105 debug("%s: uclass_first_device_err failed: %d\n",
110 /* FIXME(mario.six@gdsys.cc): Set gd->ram_size? */
115 phys_size_t get_effective_memsize(void)
117 if (!IS_ENABLED(CONFIG_VERY_BIG_RAM))
120 /* Limit stack to what we can reasonable map */
121 return ((gd->ram_size > CONFIG_MAX_MEM_MAPPED) ?
122 CONFIG_MAX_MEM_MAPPED : gd->ram_size);
126 * struct mpc83xx_sdram_priv - Private data for MPC83xx RAM controllers
127 * @total_size: The total size of all RAM modules associated with this RAM
128 * controller in bytes
130 struct mpc83xx_sdram_priv {
135 * mpc83xx_sdram_static_init() - Statically initialize a RAM module.
136 * @node: Device tree node associated with ths module in question
137 * @cs: The chip select to use for this RAM module
138 * @mapaddr: The address where the RAM module should be mapped
139 * @size: The size of the RAM module to be mapped in bytes
141 * Return: 0 if OK, -ve on error
143 static int mpc83xx_sdram_static_init(ofnode node, u32 cs, u32 mapaddr, u32 size)
145 immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
147 u32 msize_log2 = __ilog2(msize);
148 u32 auto_precharge, odt_rd_cfg, odt_wr_cfg, bank_bits, row_bits,
150 u32 bank_bits_mask, row_bits_mask, col_bits_mask;
152 /* Configure the DDR local access window */
153 out_be32(&im->sysconf.ddrlaw[cs].bar, mapaddr & 0xfffff000);
154 out_be32(&im->sysconf.ddrlaw[cs].ar, LBLAWAR_EN | (msize_log2 - 1));
156 out_be32(&im->ddr.csbnds[cs].csbnds, (msize - 1) >> 24);
158 auto_precharge = ofnode_read_u32_default(node, "auto_precharge", 0);
159 switch (auto_precharge) {
160 case AUTO_PRECHARGE_ENABLE:
161 case AUTO_PRECHARGE_DISABLE:
164 debug("%s: auto_precharge value %d invalid.\n",
165 ofnode_get_name(node), auto_precharge);
169 odt_rd_cfg = ofnode_read_u32_default(node, "odt_rd_cfg", 0);
170 switch (odt_rd_cfg) {
171 case ODT_RD_ONLY_OTHER_DIMM:
172 if (!IS_ENABLED(CONFIG_ARCH_MPC8360) &&
173 !IS_ENABLED(CONFIG_ARCH_MPC837X)) {
174 debug("%s: odt_rd_cfg value %d invalid.\n",
175 ofnode_get_name(node), odt_rd_cfg);
180 case ODT_RD_ONLY_CURRENT:
181 case ODT_RD_ONLY_OTHER_CS:
182 if (!IS_ENABLED(CONFIG_ARCH_MPC830X) &&
183 !IS_ENABLED(CONFIG_ARCH_MPC831X) &&
184 !IS_ENABLED(CONFIG_ARCH_MPC8360) &&
185 !IS_ENABLED(CONFIG_ARCH_MPC837X)) {
186 debug("%s: odt_rd_cfg value %d invalid.\n",
187 ofnode_get_name(node), odt_rd_cfg);
191 /* Only MPC832x knows this value */
195 debug("%s: odt_rd_cfg value %d invalid.\n",
196 ofnode_get_name(node), odt_rd_cfg);
200 odt_wr_cfg = ofnode_read_u32_default(node, "odt_wr_cfg", 0);
201 switch (odt_wr_cfg) {
202 case ODT_WR_ONLY_OTHER_DIMM:
203 if (!IS_ENABLED(CONFIG_ARCH_MPC8360) &&
204 !IS_ENABLED(CONFIG_ARCH_MPC837X)) {
205 debug("%s: odt_wr_cfg value %d invalid.\n",
206 ofnode_get_name(node), odt_wr_cfg);
211 case ODT_WR_ONLY_CURRENT:
212 case ODT_WR_ONLY_OTHER_CS:
213 if (!IS_ENABLED(CONFIG_ARCH_MPC830X) &&
214 !IS_ENABLED(CONFIG_ARCH_MPC831X) &&
215 !IS_ENABLED(CONFIG_ARCH_MPC8360) &&
216 !IS_ENABLED(CONFIG_ARCH_MPC837X)) {
217 debug("%s: odt_wr_cfg value %d invalid.\n",
218 ofnode_get_name(node), odt_wr_cfg);
222 /* MPC832x only knows this value */
226 debug("%s: odt_wr_cfg value %d invalid.\n",
227 ofnode_get_name(node), odt_wr_cfg);
231 bank_bits = ofnode_read_u32_default(node, "bank_bits", 0);
234 bank_bits_mask = BANK_BITS_2;
237 bank_bits_mask = BANK_BITS_3;
240 debug("%s: bank_bits value %d invalid.\n",
241 ofnode_get_name(node), bank_bits);
245 row_bits = ofnode_read_u32_default(node, "row_bits", 0);
248 row_bits_mask = ROW_BITS_12;
251 row_bits_mask = ROW_BITS_13;
254 row_bits_mask = ROW_BITS_14;
257 debug("%s: row_bits value %d invalid.\n",
258 ofnode_get_name(node), row_bits);
262 col_bits = ofnode_read_u32_default(node, "col_bits", 0);
265 col_bits_mask = COL_BITS_8;
268 col_bits_mask = COL_BITS_9;
271 col_bits_mask = COL_BITS_10;
274 col_bits_mask = COL_BITS_11;
277 debug("%s: col_bits value %d invalid.\n",
278 ofnode_get_name(node), col_bits);
282 /* Write CS config value */
283 out_be32(&im->ddr.cs_config[cs], CSCONFIG_ENABLE | auto_precharge |
284 odt_rd_cfg | odt_wr_cfg |
285 bank_bits_mask | row_bits_mask |
291 * mpc83xx_sdram_spd_init() - Initialize a RAM module using a SPD flash.
292 * @node: Device tree node associated with ths module in question
293 * @cs: The chip select to use for this RAM module
294 * @mapaddr: The address where the RAM module should be mapped
295 * @size: The size of the RAM module to be mapped in bytes
297 * Return: 0 if OK, -ve on error
299 static int mpc83xx_sdram_spd_init(ofnode node, u32 cs, u32 mapaddr, u32 size)
301 /* TODO(mario.six@gdsys.cc): Implement */
305 static int mpc83xx_sdram_ofdata_to_platdata(struct udevice *dev)
310 static int mpc83xx_sdram_probe(struct udevice *dev)
312 struct mpc83xx_sdram_priv *priv = dev_get_priv(dev);
313 immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
316 /* DDR control driver register values */
317 u32 dso, pz_override, nz_override, odt_term, ddr_type, mvref_sel, m_odr;
319 /* DDR SDRAM Clock Control register values */
321 /* DDR SDRAM Timing Configuration 3 register values */
322 u32 ext_refresh_rec, ext_refresh_rec_mask;
323 /* DDR SDRAM Timing Configuration 0 register values */
324 u32 read_to_write, write_to_read, read_to_read, write_to_write,
325 active_powerdown_exit, precharge_powerdown_exit,
326 odt_powerdown_exit, mode_reg_set_cycle;
328 /* DDR SDRAM Timing Configuration 1 register values */
329 u32 precharge_to_activate, activate_to_precharge,
330 activate_to_readwrite, mcas_latency, refresh_recovery,
331 last_data_to_precharge, activate_to_activate,
332 last_write_data_to_read;
334 /* DDR SDRAM Timing Configuration 2 register values */
335 u32 additive_latency, mcas_to_preamble_override, write_latency,
336 read_to_precharge, write_cmd_to_write_data,
337 minimum_cke_pulse_width, four_activates_window;
339 /* DDR SDRAM Control Configuration register values */
340 u32 self_refresh, ecc, registered_dram, sdram_type,
341 dynamic_power_management, databus_width, nc_auto_precharge,
342 timing_2t, bank_interleaving_ctrl, precharge_bit_8, half_strength,
343 bypass_initialization;
345 /* DDR SDRAM Control Configuration 2 register values */
346 u32 force_self_refresh, dll_reset, dqs_config, odt_config,
349 /* DDR SDRAM Mode Configuration register values */
352 /* DDR SDRAM Mode Configuration 2 register values */
353 u32 esdmode2, esdmode3;
355 /* DDR SDRAM Interval Configuration register values */
356 u32 refresh_interval, precharge_interval;
359 priv->total_size = 0;
361 /* Disable both banks initially (might be re-enabled in loop below) */
362 out_be32(&im->ddr.cs_config[0], 0);
363 out_be32(&im->ddr.cs_config[1], 0);
365 dso = dev_read_u32_default(dev, "driver_software_override", 0);
367 debug("%s: driver_software_override value %d invalid.\n",
372 pz_override = dev_read_u32_default(dev, "p_impedance_override", 0);
374 switch (pz_override) {
375 case DSO_P_IMPEDANCE_HIGHEST_Z:
376 case DSO_P_IMPEDANCE_MUCH_HIGHER_Z:
377 case DSO_P_IMPEDANCE_HIGHER_Z:
378 case DSO_P_IMPEDANCE_NOMINAL:
379 case DSO_P_IMPEDANCE_LOWER_Z:
382 debug("%s: p_impedance_override value %d invalid.\n",
383 dev->name, pz_override);
387 nz_override = dev_read_u32_default(dev, "n_impedance_override", 0);
389 switch (nz_override) {
390 case DSO_N_IMPEDANCE_HIGHEST_Z:
391 case DSO_N_IMPEDANCE_MUCH_HIGHER_Z:
392 case DSO_N_IMPEDANCE_HIGHER_Z:
393 case DSO_N_IMPEDANCE_NOMINAL:
394 case DSO_N_IMPEDANCE_LOWER_Z:
397 debug("%s: n_impedance_override value %d invalid.\n",
398 dev->name, nz_override);
402 odt_term = dev_read_u32_default(dev, "odt_termination_value", 0);
404 debug("%s: odt_termination_value value %d invalid.\n",
405 dev->name, odt_term);
409 ddr_type = dev_read_u32_default(dev, "ddr_type", 0);
411 debug("%s: ddr_type value %d invalid.\n",
412 dev->name, ddr_type);
416 mvref_sel = dev_read_u32_default(dev, "mvref_sel", 0);
418 debug("%s: mvref_sel value %d invalid.\n",
419 dev->name, mvref_sel);
423 m_odr = dev_read_u32_default(dev, "m_odr", 0);
425 debug("%s: m_odr value %d invalid.\n",
430 ddrcdr = dso << (31 - 1) |
431 pz_override << (31 - 5) |
432 nz_override << (31 - 9) |
433 odt_term << (31 - 12) |
434 ddr_type << (31 - 13) |
435 mvref_sel << (31 - 29) |
436 m_odr << (31 - 30) | 1;
438 /* Configure the DDR control driver register */
439 out_be32(&im->sysconf.ddrcdr, ddrcdr);
441 dev_for_each_subnode(subnode, dev) {
445 /* CS, map address, size -> three values */
446 ofnode_read_u32_array(subnode, "reg", val, 3);
453 debug("%s: chip select value %d invalid.\n",
458 /* TODO(mario.six@gdsys.cc): Sanity check for size. */
460 if (ofnode_read_bool(subnode, "read-spd"))
461 ret = mpc83xx_sdram_spd_init(subnode, cs, addr, size);
463 ret = mpc83xx_sdram_static_init(subnode, cs, addr,
466 debug("%s: RAM init failed.\n", dev->name);
472 * TODO(mario.six@gdsys.cc): This should only occur for static
476 clock_adjust = dev_read_u32_default(dev, "clock_adjust", 0);
477 switch (clock_adjust) {
478 case CLOCK_ADJUST_025:
479 case CLOCK_ADJUST_05:
480 case CLOCK_ADJUST_075:
484 debug("%s: clock_adjust value %d invalid.\n",
485 dev->name, clock_adjust);
489 /* Configure the DDR SDRAM Clock Control register */
490 out_be32(&im->ddr.sdram_clk_cntl, clock_adjust);
492 ext_refresh_rec = dev_read_u32_default(dev, "ext_refresh_rec", 0);
493 switch (ext_refresh_rec) {
495 ext_refresh_rec_mask = 0 << TIMING_CFG3_EXT_REFREC_SHIFT;
498 ext_refresh_rec_mask = 1 << TIMING_CFG3_EXT_REFREC_SHIFT;
501 ext_refresh_rec_mask = 2 << TIMING_CFG3_EXT_REFREC_SHIFT;
504 ext_refresh_rec_mask = 3 << TIMING_CFG3_EXT_REFREC_SHIFT;
507 ext_refresh_rec_mask = 4 << TIMING_CFG3_EXT_REFREC_SHIFT;
510 ext_refresh_rec_mask = 5 << TIMING_CFG3_EXT_REFREC_SHIFT;
513 ext_refresh_rec_mask = 6 << TIMING_CFG3_EXT_REFREC_SHIFT;
516 ext_refresh_rec_mask = 7 << TIMING_CFG3_EXT_REFREC_SHIFT;
519 debug("%s: ext_refresh_rec value %d invalid.\n",
520 dev->name, ext_refresh_rec);
524 /* Configure the DDR SDRAM Timing Configuration 3 register */
525 out_be32(&im->ddr.timing_cfg_3, ext_refresh_rec_mask);
527 read_to_write = dev_read_u32_default(dev, "read_to_write", 0);
528 if (read_to_write > 3) {
529 debug("%s: read_to_write value %d invalid.\n",
530 dev->name, read_to_write);
534 write_to_read = dev_read_u32_default(dev, "write_to_read", 0);
535 if (write_to_read > 3) {
536 debug("%s: write_to_read value %d invalid.\n",
537 dev->name, write_to_read);
541 read_to_read = dev_read_u32_default(dev, "read_to_read", 0);
542 if (read_to_read > 3) {
543 debug("%s: read_to_read value %d invalid.\n",
544 dev->name, read_to_read);
548 write_to_write = dev_read_u32_default(dev, "write_to_write", 0);
549 if (write_to_write > 3) {
550 debug("%s: write_to_write value %d invalid.\n",
551 dev->name, write_to_write);
555 active_powerdown_exit =
556 dev_read_u32_default(dev, "active_powerdown_exit", 0);
557 if (active_powerdown_exit > 7) {
558 debug("%s: active_powerdown_exit value %d invalid.\n",
559 dev->name, active_powerdown_exit);
563 precharge_powerdown_exit =
564 dev_read_u32_default(dev, "precharge_powerdown_exit", 0);
565 if (precharge_powerdown_exit > 7) {
566 debug("%s: precharge_powerdown_exit value %d invalid.\n",
567 dev->name, precharge_powerdown_exit);
571 odt_powerdown_exit = dev_read_u32_default(dev, "odt_powerdown_exit", 0);
572 if (odt_powerdown_exit > 15) {
573 debug("%s: odt_powerdown_exit value %d invalid.\n",
574 dev->name, odt_powerdown_exit);
578 mode_reg_set_cycle = dev_read_u32_default(dev, "mode_reg_set_cycle", 0);
579 if (mode_reg_set_cycle > 15) {
580 debug("%s: mode_reg_set_cycle value %d invalid.\n",
581 dev->name, mode_reg_set_cycle);
585 timing_cfg_0 = read_to_write << TIMING_CFG0_RWT_SHIFT |
586 write_to_read << TIMING_CFG0_WRT_SHIFT |
587 read_to_read << TIMING_CFG0_RRT_SHIFT |
588 write_to_write << TIMING_CFG0_WWT_SHIFT |
589 active_powerdown_exit << TIMING_CFG0_ACT_PD_EXIT_SHIFT |
590 precharge_powerdown_exit << TIMING_CFG0_PRE_PD_EXIT_SHIFT |
591 odt_powerdown_exit << TIMING_CFG0_ODT_PD_EXIT_SHIFT |
592 mode_reg_set_cycle << TIMING_CFG0_MRS_CYC_SHIFT;
594 out_be32(&im->ddr.timing_cfg_0, timing_cfg_0);
596 precharge_to_activate =
597 dev_read_u32_default(dev, "precharge_to_activate", 0);
598 if (precharge_to_activate > 7 || precharge_to_activate == 0) {
599 debug("%s: precharge_to_activate value %d invalid.\n",
600 dev->name, precharge_to_activate);
604 activate_to_precharge =
605 dev_read_u32_default(dev, "activate_to_precharge", 0);
606 if (activate_to_precharge > 19) {
607 debug("%s: activate_to_precharge value %d invalid.\n",
608 dev->name, activate_to_precharge);
612 activate_to_readwrite =
613 dev_read_u32_default(dev, "activate_to_readwrite", 0);
614 if (activate_to_readwrite > 7 || activate_to_readwrite == 0) {
615 debug("%s: activate_to_readwrite value %d invalid.\n",
616 dev->name, activate_to_readwrite);
620 mcas_latency = dev_read_u32_default(dev, "mcas_latency", 0);
621 switch (mcas_latency) {
624 if (!IS_ENABLED(CONFIG_ARCH_MPC8308)) {
625 debug("%s: MCAS latency < 3.0 unsupported on MPC8308\n",
643 debug("%s: mcas_latency value %d invalid.\n",
644 dev->name, mcas_latency);
648 refresh_recovery = dev_read_u32_default(dev, "refresh_recovery", 0);
649 if (refresh_recovery > 23 || refresh_recovery < 8) {
650 debug("%s: refresh_recovery value %d invalid.\n",
651 dev->name, refresh_recovery);
655 last_data_to_precharge =
656 dev_read_u32_default(dev, "last_data_to_precharge", 0);
657 if (last_data_to_precharge > 7 || last_data_to_precharge == 0) {
658 debug("%s: last_data_to_precharge value %d invalid.\n",
659 dev->name, last_data_to_precharge);
663 activate_to_activate =
664 dev_read_u32_default(dev, "activate_to_activate", 0);
665 if (activate_to_activate > 7 || activate_to_activate == 0) {
666 debug("%s: activate_to_activate value %d invalid.\n",
667 dev->name, activate_to_activate);
671 last_write_data_to_read =
672 dev_read_u32_default(dev, "last_write_data_to_read", 0);
673 if (last_write_data_to_read > 7 || last_write_data_to_read == 0) {
674 debug("%s: last_write_data_to_read value %d invalid.\n",
675 dev->name, last_write_data_to_read);
679 timing_cfg_1 = precharge_to_activate << TIMING_CFG1_PRETOACT_SHIFT |
680 (activate_to_precharge > 15 ?
681 activate_to_precharge - 16 :
682 activate_to_precharge) << TIMING_CFG1_ACTTOPRE_SHIFT |
683 activate_to_readwrite << TIMING_CFG1_ACTTORW_SHIFT |
684 mcas_latency << TIMING_CFG1_CASLAT_SHIFT |
685 (refresh_recovery - 8) << TIMING_CFG1_REFREC_SHIFT |
686 last_data_to_precharge << TIMING_CFG1_WRREC_SHIFT |
687 activate_to_activate << TIMING_CFG1_ACTTOACT_SHIFT |
688 last_write_data_to_read << TIMING_CFG1_WRTORD_SHIFT;
690 /* Configure the DDR SDRAM Timing Configuration 1 register */
691 out_be32(&im->ddr.timing_cfg_1, timing_cfg_1);
693 additive_latency = dev_read_u32_default(dev, "additive_latency", 0);
694 if (additive_latency > 5) {
695 debug("%s: additive_latency value %d invalid.\n",
696 dev->name, additive_latency);
700 mcas_to_preamble_override =
701 dev_read_u32_default(dev, "mcas_to_preamble_override", 0);
702 switch (mcas_to_preamble_override) {
703 case READ_LAT_PLUS_1:
705 case READ_LAT_PLUS_1_4:
706 case READ_LAT_PLUS_1_2:
707 case READ_LAT_PLUS_3_4:
708 case READ_LAT_PLUS_5_4:
709 case READ_LAT_PLUS_3_2:
710 case READ_LAT_PLUS_7_4:
711 case READ_LAT_PLUS_2:
712 case READ_LAT_PLUS_9_4:
713 case READ_LAT_PLUS_5_2:
714 case READ_LAT_PLUS_11_4:
715 case READ_LAT_PLUS_3:
716 case READ_LAT_PLUS_13_4:
717 case READ_LAT_PLUS_7_2:
718 case READ_LAT_PLUS_15_4:
719 case READ_LAT_PLUS_4:
720 case READ_LAT_PLUS_17_4:
721 case READ_LAT_PLUS_9_2:
722 case READ_LAT_PLUS_19_4:
725 debug("%s: mcas_to_preamble_override value %d invalid.\n",
726 dev->name, mcas_to_preamble_override);
730 write_latency = dev_read_u32_default(dev, "write_latency", 0);
731 if (write_latency > 7 || write_latency == 0) {
732 debug("%s: write_latency value %d invalid.\n",
733 dev->name, write_latency);
737 read_to_precharge = dev_read_u32_default(dev, "read_to_precharge", 0);
738 if (read_to_precharge > 4 || read_to_precharge == 0) {
739 debug("%s: read_to_precharge value %d invalid.\n",
740 dev->name, read_to_precharge);
744 write_cmd_to_write_data =
745 dev_read_u32_default(dev, "write_cmd_to_write_data", 0);
746 switch (write_cmd_to_write_data) {
748 case CLOCK_DELAY_1_4:
749 case CLOCK_DELAY_1_2:
750 case CLOCK_DELAY_3_4:
752 case CLOCK_DELAY_5_4:
753 case CLOCK_DELAY_3_2:
756 debug("%s: write_cmd_to_write_data value %d invalid.\n",
757 dev->name, write_cmd_to_write_data);
761 minimum_cke_pulse_width =
762 dev_read_u32_default(dev, "minimum_cke_pulse_width", 0);
763 if (minimum_cke_pulse_width > 4 || minimum_cke_pulse_width == 0) {
764 debug("%s: minimum_cke_pulse_width value %d invalid.\n",
765 dev->name, minimum_cke_pulse_width);
769 four_activates_window =
770 dev_read_u32_default(dev, "four_activates_window", 0);
771 if (four_activates_window > 20 || four_activates_window == 0) {
772 debug("%s: four_activates_window value %d invalid.\n",
773 dev->name, four_activates_window);
777 timing_cfg_2 = additive_latency << TIMING_CFG2_ADD_LAT_SHIFT |
778 mcas_to_preamble_override << TIMING_CFG2_CPO_SHIFT |
779 write_latency << TIMING_CFG2_WR_LAT_DELAY_SHIFT |
780 read_to_precharge << TIMING_CFG2_RD_TO_PRE_SHIFT |
781 write_cmd_to_write_data << TIMING_CFG2_WR_DATA_DELAY_SHIFT |
782 minimum_cke_pulse_width << TIMING_CFG2_CKE_PLS_SHIFT |
783 four_activates_window << TIMING_CFG2_FOUR_ACT_SHIFT;
785 out_be32(&im->ddr.timing_cfg_2, timing_cfg_2);
787 self_refresh = dev_read_u32_default(dev, "self_refresh", 0);
788 switch (self_refresh) {
793 debug("%s: self_refresh value %d invalid.\n",
794 dev->name, self_refresh);
798 ecc = dev_read_u32_default(dev, "ecc", 0);
804 debug("%s: ecc value %d invalid.\n", dev->name, ecc);
808 registered_dram = dev_read_u32_default(dev, "registered_dram", 0);
809 switch (registered_dram) {
814 debug("%s: registered_dram value %d invalid.\n",
815 dev->name, registered_dram);
819 sdram_type = dev_read_u32_default(dev, "sdram_type", 0);
820 switch (sdram_type) {
825 debug("%s: sdram_type value %d invalid.\n",
826 dev->name, sdram_type);
830 dynamic_power_management =
831 dev_read_u32_default(dev, "dynamic_power_management", 0);
832 switch (dynamic_power_management) {
833 case DYN_PWR_DISABLE:
837 debug("%s: dynamic_power_management value %d invalid.\n",
838 dev->name, dynamic_power_management);
842 databus_width = dev_read_u32_default(dev, "databus_width", 0);
843 switch (databus_width) {
844 case DATA_BUS_WIDTH_16:
845 case DATA_BUS_WIDTH_32:
848 debug("%s: databus_width value %d invalid.\n",
849 dev->name, databus_width);
853 nc_auto_precharge = dev_read_u32_default(dev, "nc_auto_precharge", 0);
854 switch (nc_auto_precharge) {
859 debug("%s: nc_auto_precharge value %d invalid.\n",
860 dev->name, nc_auto_precharge);
864 timing_2t = dev_read_u32_default(dev, "timing_2t", 0);
870 debug("%s: timing_2t value %d invalid.\n",
871 dev->name, timing_2t);
875 bank_interleaving_ctrl =
876 dev_read_u32_default(dev, "bank_interleaving_ctrl", 0);
877 switch (bank_interleaving_ctrl) {
878 case INTERLEAVE_NONE:
879 case INTERLEAVE_1_AND_2:
882 debug("%s: bank_interleaving_ctrl value %d invalid.\n",
883 dev->name, bank_interleaving_ctrl);
887 precharge_bit_8 = dev_read_u32_default(dev, "precharge_bit_8", 0);
888 switch (precharge_bit_8) {
889 case PRECHARGE_MA_10:
893 debug("%s: precharge_bit_8 value %d invalid.\n",
894 dev->name, precharge_bit_8);
898 half_strength = dev_read_u32_default(dev, "half_strength", 0);
899 switch (half_strength) {
904 debug("%s: half_strength value %d invalid.\n",
905 dev->name, half_strength);
909 bypass_initialization =
910 dev_read_u32_default(dev, "bypass_initialization", 0);
911 switch (bypass_initialization) {
912 case INITIALIZATION_DONT_BYPASS:
913 case INITIALIZATION_BYPASS:
916 debug("%s: bypass_initialization value %d invalid.\n",
917 dev->name, bypass_initialization);
921 sdram_cfg = self_refresh << SDRAM_CFG_SREN_SHIFT |
922 ecc << SDRAM_CFG_ECC_EN_SHIFT |
923 registered_dram << SDRAM_CFG_RD_EN_SHIFT |
924 sdram_type << SDRAM_CFG_SDRAM_TYPE_SHIFT |
925 dynamic_power_management << SDRAM_CFG_DYN_PWR_SHIFT |
926 databus_width << SDRAM_CFG_DBW_SHIFT |
927 nc_auto_precharge << SDRAM_CFG_NCAP_SHIFT |
928 timing_2t << SDRAM_CFG_2T_EN_SHIFT |
929 bank_interleaving_ctrl << SDRAM_CFG_BA_INTLV_CTL_SHIFT |
930 precharge_bit_8 << SDRAM_CFG_PCHB8_SHIFT |
931 half_strength << SDRAM_CFG_HSE_SHIFT |
932 bypass_initialization << SDRAM_CFG_BI_SHIFT;
934 out_be32(&im->ddr.sdram_cfg, sdram_cfg);
936 force_self_refresh = dev_read_u32_default(dev, "force_self_refresh", 0);
937 switch (force_self_refresh) {
942 debug("%s: force_self_refresh value %d invalid.\n",
943 dev->name, force_self_refresh);
947 dll_reset = dev_read_u32_default(dev, "dll_reset", 0);
949 case DLL_RESET_ENABLE:
950 case DLL_RESET_DISABLE:
953 debug("%s: dll_reset value %d invalid.\n",
954 dev->name, dll_reset);
958 dqs_config = dev_read_u32_default(dev, "dqs_config", 0);
959 switch (dqs_config) {
963 debug("%s: dqs_config value %d invalid.\n",
964 dev->name, dqs_config);
968 odt_config = dev_read_u32_default(dev, "odt_config", 0);
969 switch (odt_config) {
970 case ODT_ASSERT_NEVER:
971 case ODT_ASSERT_WRITES:
972 case ODT_ASSERT_READS:
973 case ODT_ASSERT_ALWAYS:
976 debug("%s: odt_config value %d invalid.\n",
977 dev->name, odt_config);
981 posted_refreshes = dev_read_u32_default(dev, "posted_refreshes", 0);
982 if (posted_refreshes > 8 || posted_refreshes == 0) {
983 debug("%s: posted_refreshes value %d invalid.\n",
984 dev->name, posted_refreshes);
988 sdram_cfg2 = force_self_refresh << SDRAM_CFG2_FRC_SR_SHIFT |
989 dll_reset << SDRAM_CFG2_DLL_RST_DIS |
990 dqs_config << SDRAM_CFG2_DQS_CFG |
991 odt_config << SDRAM_CFG2_ODT_CFG |
992 posted_refreshes << SDRAM_CFG2_NUM_PR;
994 out_be32(&im->ddr.sdram_cfg2, sdram_cfg2);
996 sdmode = dev_read_u32_default(dev, "sdmode", 0);
997 if (sdmode > 0xFFFF) {
998 debug("%s: sdmode value %d invalid.\n",
1003 esdmode = dev_read_u32_default(dev, "esdmode", 0);
1004 if (esdmode > 0xFFFF) {
1005 debug("%s: esdmode value %d invalid.\n", dev->name, esdmode);
1009 sdram_mode = sdmode << SDRAM_MODE_SD_SHIFT |
1010 esdmode << SDRAM_MODE_ESD_SHIFT;
1012 out_be32(&im->ddr.sdram_mode, sdram_mode);
1014 esdmode2 = dev_read_u32_default(dev, "esdmode2", 0);
1015 if (esdmode2 > 0xFFFF) {
1016 debug("%s: esdmode2 value %d invalid.\n", dev->name, esdmode2);
1020 esdmode3 = dev_read_u32_default(dev, "esdmode3", 0);
1021 if (esdmode3 > 0xFFFF) {
1022 debug("%s: esdmode3 value %d invalid.\n", dev->name, esdmode3);
1026 sdram_mode2 = esdmode2 << SDRAM_MODE2_ESD2_SHIFT |
1027 esdmode3 << SDRAM_MODE2_ESD3_SHIFT;
1029 out_be32(&im->ddr.sdram_mode2, sdram_mode2);
1031 refresh_interval = dev_read_u32_default(dev, "refresh_interval", 0);
1032 if (refresh_interval > 0xFFFF) {
1033 debug("%s: refresh_interval value %d invalid.\n",
1034 dev->name, refresh_interval);
1038 precharge_interval = dev_read_u32_default(dev, "precharge_interval", 0);
1039 if (precharge_interval > 0x3FFF) {
1040 debug("%s: precharge_interval value %d invalid.\n",
1041 dev->name, precharge_interval);
1045 sdram_interval = refresh_interval << SDRAM_INTERVAL_REFINT_SHIFT |
1046 precharge_interval << SDRAM_INTERVAL_BSTOPRE_SHIFT;
1048 out_be32(&im->ddr.sdram_interval, sdram_interval);
1051 /* Enable DDR controller */
1052 setbits_be32(&im->ddr.sdram_cfg, SDRAM_CFG_MEM_EN);
1055 dev_for_each_subnode(subnode, dev) {
1059 /* CS, map address, size -> three values */
1060 ofnode_read_u32_array(subnode, "reg", val, 3);
1065 priv->total_size += get_ram_size((long int *)addr, size);
1068 gd->ram_size = priv->total_size;
1073 static int mpc83xx_sdram_get_info(struct udevice *dev, struct ram_info *info)
1075 /* TODO(mario.six@gdsys.cc): Implement */
1079 static struct ram_ops mpc83xx_sdram_ops = {
1080 .get_info = mpc83xx_sdram_get_info,
1083 static const struct udevice_id mpc83xx_sdram_ids[] = {
1084 { .compatible = "fsl,mpc83xx-mem-controller" },
1088 U_BOOT_DRIVER(mpc83xx_sdram) = {
1089 .name = "mpc83xx_sdram",
1091 .of_match = mpc83xx_sdram_ids,
1092 .ops = &mpc83xx_sdram_ops,
1093 .ofdata_to_platdata = mpc83xx_sdram_ofdata_to_platdata,
1094 .probe = mpc83xx_sdram_probe,
1095 .priv_auto_alloc_size = sizeof(struct mpc83xx_sdram_priv),