Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2015 Marek Vasut <marex@denx.de> |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <errno.h> |
| 8 | #include <asm/arch/sdram.h> |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 9 | |
Marek Vasut | 372f70d | 2015-08-10 21:21:07 +0200 | [diff] [blame] | 10 | /* Board-specific header. */ |
| 11 | #include <qts/sdram_config.h> |
Marek Vasut | 3384e74 | 2015-08-02 17:15:19 +0200 | [diff] [blame] | 12 | |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 13 | static const struct socfpga_sdram_config sdram_config = { |
| 14 | .ctrl_cfg = |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 15 | (CFG_HPS_SDR_CTRLCFG_CTRLCFG_MEMTYPE << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 16 | SDR_CTRLGRP_CTRLCFG_MEMTYPE_LSB) | |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 17 | (CFG_HPS_SDR_CTRLCFG_CTRLCFG_MEMBL << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 18 | SDR_CTRLGRP_CTRLCFG_MEMBL_LSB) | |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 19 | (CFG_HPS_SDR_CTRLCFG_CTRLCFG_ADDRORDER << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 20 | SDR_CTRLGRP_CTRLCFG_ADDRORDER_LSB) | |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 21 | (CFG_HPS_SDR_CTRLCFG_CTRLCFG_ECCEN << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 22 | SDR_CTRLGRP_CTRLCFG_ECCEN_LSB) | |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 23 | (CFG_HPS_SDR_CTRLCFG_CTRLCFG_ECCCORREN << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 24 | SDR_CTRLGRP_CTRLCFG_ECCCORREN_LSB) | |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 25 | (CFG_HPS_SDR_CTRLCFG_CTRLCFG_REORDEREN << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 26 | SDR_CTRLGRP_CTRLCFG_REORDEREN_LSB) | |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 27 | (CFG_HPS_SDR_CTRLCFG_CTRLCFG_STARVELIMIT << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 28 | SDR_CTRLGRP_CTRLCFG_STARVELIMIT_LSB) | |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 29 | (CFG_HPS_SDR_CTRLCFG_CTRLCFG_DQSTRKEN << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 30 | SDR_CTRLGRP_CTRLCFG_DQSTRKEN_LSB) | |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 31 | (CFG_HPS_SDR_CTRLCFG_CTRLCFG_NODMPINS << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 32 | SDR_CTRLGRP_CTRLCFG_NODMPINS_LSB), |
| 33 | .dram_timing1 = |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 34 | (CFG_HPS_SDR_CTRLCFG_DRAMTIMING1_TCWL << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 35 | SDR_CTRLGRP_DRAMTIMING1_TCWL_LSB) | |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 36 | (CFG_HPS_SDR_CTRLCFG_DRAMTIMING1_AL << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 37 | SDR_CTRLGRP_DRAMTIMING1_TAL_LSB) | |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 38 | (CFG_HPS_SDR_CTRLCFG_DRAMTIMING1_TCL << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 39 | SDR_CTRLGRP_DRAMTIMING1_TCL_LSB) | |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 40 | (CFG_HPS_SDR_CTRLCFG_DRAMTIMING1_TRRD << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 41 | SDR_CTRLGRP_DRAMTIMING1_TRRD_LSB) | |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 42 | (CFG_HPS_SDR_CTRLCFG_DRAMTIMING1_TFAW << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 43 | SDR_CTRLGRP_DRAMTIMING1_TFAW_LSB) | |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 44 | (CFG_HPS_SDR_CTRLCFG_DRAMTIMING1_TRFC << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 45 | SDR_CTRLGRP_DRAMTIMING1_TRFC_LSB), |
| 46 | .dram_timing2 = |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 47 | (CFG_HPS_SDR_CTRLCFG_DRAMTIMING2_IF_TREFI << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 48 | SDR_CTRLGRP_DRAMTIMING2_TREFI_LSB) | |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 49 | (CFG_HPS_SDR_CTRLCFG_DRAMTIMING2_IF_TRCD << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 50 | SDR_CTRLGRP_DRAMTIMING2_TRCD_LSB) | |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 51 | (CFG_HPS_SDR_CTRLCFG_DRAMTIMING2_IF_TRP << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 52 | SDR_CTRLGRP_DRAMTIMING2_TRP_LSB) | |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 53 | (CFG_HPS_SDR_CTRLCFG_DRAMTIMING2_IF_TWR << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 54 | SDR_CTRLGRP_DRAMTIMING2_TWR_LSB) | |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 55 | (CFG_HPS_SDR_CTRLCFG_DRAMTIMING2_IF_TWTR << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 56 | SDR_CTRLGRP_DRAMTIMING2_TWTR_LSB), |
| 57 | .dram_timing3 = |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 58 | (CFG_HPS_SDR_CTRLCFG_DRAMTIMING3_TRTP << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 59 | SDR_CTRLGRP_DRAMTIMING3_TRTP_LSB) | |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 60 | (CFG_HPS_SDR_CTRLCFG_DRAMTIMING3_TRAS << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 61 | SDR_CTRLGRP_DRAMTIMING3_TRAS_LSB) | |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 62 | (CFG_HPS_SDR_CTRLCFG_DRAMTIMING3_TRC << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 63 | SDR_CTRLGRP_DRAMTIMING3_TRC_LSB) | |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 64 | (CFG_HPS_SDR_CTRLCFG_DRAMTIMING3_TMRD << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 65 | SDR_CTRLGRP_DRAMTIMING3_TMRD_LSB) | |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 66 | (CFG_HPS_SDR_CTRLCFG_DRAMTIMING3_TCCD << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 67 | SDR_CTRLGRP_DRAMTIMING3_TCCD_LSB), |
| 68 | .dram_timing4 = |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 69 | (CFG_HPS_SDR_CTRLCFG_DRAMTIMING4_SELFRFSHEXIT << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 70 | SDR_CTRLGRP_DRAMTIMING4_SELFRFSHEXIT_LSB) | |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 71 | (CFG_HPS_SDR_CTRLCFG_DRAMTIMING4_PWRDOWNEXIT << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 72 | SDR_CTRLGRP_DRAMTIMING4_PWRDOWNEXIT_LSB), |
| 73 | .lowpwr_timing = |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 74 | (CFG_HPS_SDR_CTRLCFG_LOWPWRTIMING_AUTOPDCYCLES << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 75 | SDR_CTRLGRP_LOWPWRTIMING_AUTOPDCYCLES_LSB) | |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 76 | (CFG_HPS_SDR_CTRLCFG_LOWPWRTIMING_CLKDISABLECYCLES << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 77 | SDR_CTRLGRP_LOWPWRTIMING_CLKDISABLECYCLES_LSB), |
| 78 | .dram_odt = |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 79 | (CFG_HPS_SDR_CTRLCFG_DRAMODT_READ << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 80 | SDR_CTRLGRP_DRAMODT_READ_LSB) | |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 81 | (CFG_HPS_SDR_CTRLCFG_DRAMODT_WRITE << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 82 | SDR_CTRLGRP_DRAMODT_WRITE_LSB), |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 83 | #if (CFG_HPS_SDR_CTRLCFG_CTRLCFG_MEMTYPE == 2) /* DDR3 */ |
Chin Liang See | 3ea5951 | 2016-09-21 10:25:56 +0800 | [diff] [blame] | 84 | .extratime1 = |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 85 | (CFG_HPS_SDR_CTRLCFG_EXTRATIME1_CFG_EXTRA_CTL_CLK_RD_TO_WR << |
Marek Vasut | 6bccacf | 2019-10-18 00:22:31 +0200 | [diff] [blame] | 86 | SDR_CTRLGRP_EXTRATIME1_RD_TO_WR_LSB) | |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 87 | (CFG_HPS_SDR_CTRLCFG_EXTRATIME1_CFG_EXTRA_CTL_CLK_RD_TO_WR_BC << |
Marek Vasut | 6bccacf | 2019-10-18 00:22:31 +0200 | [diff] [blame] | 88 | SDR_CTRLGRP_EXTRATIME1_RD_TO_WR_BC_LSB) | |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 89 | (CFG_HPS_SDR_CTRLCFG_EXTRATIME1_CFG_EXTRA_CTL_CLK_RD_TO_WR_DIFF_CHIP << |
Marek Vasut | 6bccacf | 2019-10-18 00:22:31 +0200 | [diff] [blame] | 90 | SDR_CTRLGRP_EXTRATIME1_RD_TO_WR_DIFF_LSB), |
| 91 | #endif |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 92 | .dram_addrw = |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 93 | (CFG_HPS_SDR_CTRLCFG_DRAMADDRW_COLBITS << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 94 | SDR_CTRLGRP_DRAMADDRW_COLBITS_LSB) | |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 95 | (CFG_HPS_SDR_CTRLCFG_DRAMADDRW_ROWBITS << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 96 | SDR_CTRLGRP_DRAMADDRW_ROWBITS_LSB) | |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 97 | (CFG_HPS_SDR_CTRLCFG_DRAMADDRW_BANKBITS << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 98 | SDR_CTRLGRP_DRAMADDRW_BANKBITS_LSB) | |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 99 | ((CFG_HPS_SDR_CTRLCFG_DRAMADDRW_CSBITS - 1) << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 100 | SDR_CTRLGRP_DRAMADDRW_CSBITS_LSB), |
| 101 | .dram_if_width = |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 102 | (CFG_HPS_SDR_CTRLCFG_DRAMIFWIDTH_IFWIDTH << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 103 | SDR_CTRLGRP_DRAMIFWIDTH_IFWIDTH_LSB), |
| 104 | .dram_dev_width = |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 105 | (CFG_HPS_SDR_CTRLCFG_DRAMDEVWIDTH_DEVWIDTH << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 106 | SDR_CTRLGRP_DRAMDEVWIDTH_DEVWIDTH_LSB), |
| 107 | .dram_intr = |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 108 | (CFG_HPS_SDR_CTRLCFG_DRAMINTR_INTREN << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 109 | SDR_CTRLGRP_DRAMINTR_INTREN_LSB), |
| 110 | .lowpwr_eq = |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 111 | (CFG_HPS_SDR_CTRLCFG_LOWPWREQ_SELFRFSHMASK << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 112 | SDR_CTRLGRP_LOWPWREQ_SELFRFSHMASK_LSB), |
| 113 | .static_cfg = |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 114 | (CFG_HPS_SDR_CTRLCFG_STATICCFG_MEMBL << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 115 | SDR_CTRLGRP_STATICCFG_MEMBL_LSB) | |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 116 | (CFG_HPS_SDR_CTRLCFG_STATICCFG_USEECCASDATA << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 117 | SDR_CTRLGRP_STATICCFG_USEECCASDATA_LSB), |
| 118 | .ctrl_width = |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 119 | (CFG_HPS_SDR_CTRLCFG_CTRLWIDTH_CTRLWIDTH << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 120 | SDR_CTRLGRP_CTRLWIDTH_CTRLWIDTH_LSB), |
| 121 | .cport_width = |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 122 | (CFG_HPS_SDR_CTRLCFG_CPORTWIDTH_CPORTWIDTH << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 123 | SDR_CTRLGRP_CPORTWIDTH_CMDPORTWIDTH_LSB), |
| 124 | .cport_wmap = |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 125 | (CFG_HPS_SDR_CTRLCFG_CPORTWMAP_CPORTWMAP << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 126 | SDR_CTRLGRP_CPORTWMAP_CPORTWFIFOMAP_LSB), |
| 127 | .cport_rmap = |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 128 | (CFG_HPS_SDR_CTRLCFG_CPORTRMAP_CPORTRMAP << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 129 | SDR_CTRLGRP_CPORTRMAP_CPORTRFIFOMAP_LSB), |
| 130 | .rfifo_cmap = |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 131 | (CFG_HPS_SDR_CTRLCFG_RFIFOCMAP_RFIFOCMAP << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 132 | SDR_CTRLGRP_RFIFOCMAP_RFIFOCPORTMAP_LSB), |
| 133 | .wfifo_cmap = |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 134 | (CFG_HPS_SDR_CTRLCFG_WFIFOCMAP_WFIFOCMAP << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 135 | SDR_CTRLGRP_WFIFOCMAP_WFIFOCPORTMAP_LSB), |
| 136 | .cport_rdwr = |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 137 | (CFG_HPS_SDR_CTRLCFG_CPORTRDWR_CPORTRDWR << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 138 | SDR_CTRLGRP_CPORTRDWR_CPORTRDWR_LSB), |
| 139 | .port_cfg = |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 140 | (CFG_HPS_SDR_CTRLCFG_PORTCFG_AUTOPCHEN << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 141 | SDR_CTRLGRP_PORTCFG_AUTOPCHEN_LSB), |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 142 | .fpgaport_rst = CFG_HPS_SDR_CTRLCFG_FPGAPORTRST, |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 143 | .fifo_cfg = |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 144 | (CFG_HPS_SDR_CTRLCFG_FIFOCFG_SYNCMODE << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 145 | SDR_CTRLGRP_FIFOCFG_SYNCMODE_LSB) | |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 146 | (CFG_HPS_SDR_CTRLCFG_FIFOCFG_INCSYNC << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 147 | SDR_CTRLGRP_FIFOCFG_INCSYNC_LSB), |
| 148 | .mp_priority = |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 149 | (CFG_HPS_SDR_CTRLCFG_MPPRIORITY_USERPRIORITY << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 150 | SDR_CTRLGRP_MPPRIORITY_USERPRIORITY_LSB), |
| 151 | .mp_weight0 = |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 152 | (CFG_HPS_SDR_CTRLCFG_MPWIEIGHT_0_STATICWEIGHT_31_0 << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 153 | SDR_CTRLGRP_MPWEIGHT_MPWEIGHT_0_STATICWEIGHT_31_0_LSB), |
| 154 | .mp_weight1 = |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 155 | (CFG_HPS_SDR_CTRLCFG_MPWIEIGHT_1_STATICWEIGHT_49_32 << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 156 | SDR_CTRLGRP_MPWEIGHT_MPWEIGHT_1_STATICWEIGHT_49_32_LSB) | |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 157 | (CFG_HPS_SDR_CTRLCFG_MPWIEIGHT_1_SUMOFWEIGHT_13_0 << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 158 | SDR_CTRLGRP_MPWEIGHT_MPWEIGHT_1_SUMOFWEIGHTS_13_0_LSB), |
| 159 | .mp_weight2 = |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 160 | (CFG_HPS_SDR_CTRLCFG_MPWIEIGHT_2_SUMOFWEIGHT_45_14 << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 161 | SDR_CTRLGRP_MPWEIGHT_MPWEIGHT_2_SUMOFWEIGHTS_45_14_LSB), |
| 162 | .mp_weight3 = |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 163 | (CFG_HPS_SDR_CTRLCFG_MPWIEIGHT_3_SUMOFWEIGHT_63_46 << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 164 | SDR_CTRLGRP_MPWEIGHT_MPWEIGHT_3_SUMOFWEIGHTS_63_46_LSB), |
| 165 | .mp_pacing0 = |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 166 | (CFG_HPS_SDR_CTRLCFG_MPPACING_0_THRESHOLD1_31_0 << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 167 | SDR_CTRLGRP_MPPACING_MPPACING_0_THRESHOLD1_31_0_LSB), |
| 168 | .mp_pacing1 = |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 169 | (CFG_HPS_SDR_CTRLCFG_MPPACING_1_THRESHOLD1_59_32 << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 170 | SDR_CTRLGRP_MPPACING_MPPACING_1_THRESHOLD1_59_32_LSB) | |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 171 | (CFG_HPS_SDR_CTRLCFG_MPPACING_1_THRESHOLD2_3_0 << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 172 | SDR_CTRLGRP_MPPACING_MPPACING_1_THRESHOLD2_3_0_LSB), |
| 173 | .mp_pacing2 = |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 174 | (CFG_HPS_SDR_CTRLCFG_MPPACING_2_THRESHOLD2_35_4 << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 175 | SDR_CTRLGRP_MPPACING_MPPACING_2_THRESHOLD2_35_4_LSB), |
| 176 | .mp_pacing3 = |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 177 | (CFG_HPS_SDR_CTRLCFG_MPPACING_3_THRESHOLD2_59_36 << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 178 | SDR_CTRLGRP_MPPACING_MPPACING_3_THRESHOLD2_59_36_LSB), |
| 179 | .mp_threshold0 = |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 180 | (CFG_HPS_SDR_CTRLCFG_MPTHRESHOLDRST_0_THRESHOLDRSTCYCLES_31_0 << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 181 | SDR_CTRLGRP_MPTHRESHOLDRST_0_THRESHOLDRSTCYCLES_31_0_LSB), |
| 182 | .mp_threshold1 = |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 183 | (CFG_HPS_SDR_CTRLCFG_MPTHRESHOLDRST_1_THRESHOLDRSTCYCLES_63_32 << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 184 | SDR_CTRLGRP_MPTHRESHOLDRST_1_THRESHOLDRSTCYCLES_63_32_LSB), |
| 185 | .mp_threshold2 = |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 186 | (CFG_HPS_SDR_CTRLCFG_MPTHRESHOLDRST_2_THRESHOLDRSTCYCLES_79_64 << |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 187 | SDR_CTRLGRP_MPTHRESHOLDRST_2_THRESHOLDRSTCYCLES_79_64_LSB), |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 188 | .phy_ctrl0 = CFG_HPS_SDR_CTRLCFG_PHYCTRL_PHYCTRL_0, |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 189 | }; |
| 190 | |
Marek Vasut | 39b620e | 2015-08-02 18:12:08 +0200 | [diff] [blame] | 191 | static const struct socfpga_sdram_rw_mgr_config rw_mgr_config = { |
| 192 | .activate_0_and_1 = RW_MGR_ACTIVATE_0_AND_1, |
| 193 | .activate_0_and_1_wait1 = RW_MGR_ACTIVATE_0_AND_1_WAIT1, |
| 194 | .activate_0_and_1_wait2 = RW_MGR_ACTIVATE_0_AND_1_WAIT2, |
Marek Vasut | 39b620e | 2015-08-02 18:12:08 +0200 | [diff] [blame] | 195 | .clear_dqs_enable = RW_MGR_CLEAR_DQS_ENABLE, |
| 196 | .guaranteed_read = RW_MGR_GUARANTEED_READ, |
| 197 | .guaranteed_read_cont = RW_MGR_GUARANTEED_READ_CONT, |
| 198 | .guaranteed_write = RW_MGR_GUARANTEED_WRITE, |
| 199 | .guaranteed_write_wait0 = RW_MGR_GUARANTEED_WRITE_WAIT0, |
| 200 | .guaranteed_write_wait1 = RW_MGR_GUARANTEED_WRITE_WAIT1, |
| 201 | .guaranteed_write_wait2 = RW_MGR_GUARANTEED_WRITE_WAIT2, |
| 202 | .guaranteed_write_wait3 = RW_MGR_GUARANTEED_WRITE_WAIT3, |
Marek Vasut | 39b620e | 2015-08-02 18:12:08 +0200 | [diff] [blame] | 203 | .idle_loop1 = RW_MGR_IDLE_LOOP1, |
| 204 | .idle_loop2 = RW_MGR_IDLE_LOOP2, |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 205 | #if (CFG_HPS_SDR_CTRLCFG_CTRLCFG_MEMTYPE == 1) /* DDR2 */ |
Marek Vasut | 6bccacf | 2019-10-18 00:22:31 +0200 | [diff] [blame] | 206 | .emr = RW_MGR_EMR, |
| 207 | .emr2 = RW_MGR_EMR2, |
| 208 | .emr3 = RW_MGR_EMR3, |
| 209 | .init_reset_0_cke_0 = RW_MGR_INIT_CKE_0, |
| 210 | .nop = RW_MGR_NOP, |
| 211 | .refresh = RW_MGR_REFRESH, |
| 212 | .mr_calib = RW_MGR_MR_CALIB, |
| 213 | .mr_user = RW_MGR_MR_USER, |
| 214 | .mr_dll_reset = RW_MGR_MR_DLL_RESET, |
| 215 | .emr_ocd_enable = RW_MGR_EMR_OCD_ENABLE, |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 216 | #elif (CFG_HPS_SDR_CTRLCFG_CTRLCFG_MEMTYPE == 2) /* DDR3 */ |
Marek Vasut | 6bccacf | 2019-10-18 00:22:31 +0200 | [diff] [blame] | 217 | .activate_1 = RW_MGR_ACTIVATE_1, |
| 218 | .idle = RW_MGR_IDLE, |
Marek Vasut | 39b620e | 2015-08-02 18:12:08 +0200 | [diff] [blame] | 219 | .init_reset_0_cke_0 = RW_MGR_INIT_RESET_0_CKE_0, |
| 220 | .init_reset_1_cke_0 = RW_MGR_INIT_RESET_1_CKE_0, |
Marek Vasut | 6bccacf | 2019-10-18 00:22:31 +0200 | [diff] [blame] | 221 | .mrs1 = RW_MGR_MRS1, |
| 222 | .mrs1_mirr = RW_MGR_MRS1_MIRR, |
| 223 | .mrs2 = RW_MGR_MRS2, |
| 224 | .mrs2_mirr = RW_MGR_MRS2_MIRR, |
| 225 | .mrs3 = RW_MGR_MRS3, |
| 226 | .mrs3_mirr = RW_MGR_MRS3_MIRR, |
| 227 | .refresh_all = RW_MGR_REFRESH_ALL, |
| 228 | .rreturn = RW_MGR_RETURN, |
| 229 | .sgle_read = RW_MGR_SGLE_READ, |
| 230 | .zqcl = RW_MGR_ZQCL, |
| 231 | .mrs0_dll_reset = RW_MGR_MRS0_DLL_RESET, |
| 232 | .mrs0_dll_reset_mirr = RW_MGR_MRS0_DLL_RESET_MIRR, |
| 233 | .mrs0_user = RW_MGR_MRS0_USER, |
| 234 | .mrs0_user_mirr = RW_MGR_MRS0_USER_MIRR, |
| 235 | #else |
| 236 | #error LPDDR2 and other DRAM types are not yet supported |
| 237 | #endif |
Marek Vasut | 39b620e | 2015-08-02 18:12:08 +0200 | [diff] [blame] | 238 | .lfsr_wr_rd_bank_0 = RW_MGR_LFSR_WR_RD_BANK_0, |
| 239 | .lfsr_wr_rd_bank_0_data = RW_MGR_LFSR_WR_RD_BANK_0_DATA, |
| 240 | .lfsr_wr_rd_bank_0_dqs = RW_MGR_LFSR_WR_RD_BANK_0_DQS, |
| 241 | .lfsr_wr_rd_bank_0_nop = RW_MGR_LFSR_WR_RD_BANK_0_NOP, |
| 242 | .lfsr_wr_rd_bank_0_wait = RW_MGR_LFSR_WR_RD_BANK_0_WAIT, |
| 243 | .lfsr_wr_rd_bank_0_wl_1 = RW_MGR_LFSR_WR_RD_BANK_0_WL_1, |
| 244 | .lfsr_wr_rd_dm_bank_0 = RW_MGR_LFSR_WR_RD_DM_BANK_0, |
| 245 | .lfsr_wr_rd_dm_bank_0_data = RW_MGR_LFSR_WR_RD_DM_BANK_0_DATA, |
| 246 | .lfsr_wr_rd_dm_bank_0_dqs = RW_MGR_LFSR_WR_RD_DM_BANK_0_DQS, |
| 247 | .lfsr_wr_rd_dm_bank_0_nop = RW_MGR_LFSR_WR_RD_DM_BANK_0_NOP, |
| 248 | .lfsr_wr_rd_dm_bank_0_wait = RW_MGR_LFSR_WR_RD_DM_BANK_0_WAIT, |
| 249 | .lfsr_wr_rd_dm_bank_0_wl_1 = RW_MGR_LFSR_WR_RD_DM_BANK_0_WL_1, |
Marek Vasut | 39b620e | 2015-08-02 18:12:08 +0200 | [diff] [blame] | 250 | .precharge_all = RW_MGR_PRECHARGE_ALL, |
| 251 | .read_b2b = RW_MGR_READ_B2B, |
| 252 | .read_b2b_wait1 = RW_MGR_READ_B2B_WAIT1, |
| 253 | .read_b2b_wait2 = RW_MGR_READ_B2B_WAIT2, |
Marek Vasut | 39b620e | 2015-08-02 18:12:08 +0200 | [diff] [blame] | 254 | |
| 255 | .true_mem_data_mask_width = RW_MGR_TRUE_MEM_DATA_MASK_WIDTH, |
| 256 | .mem_address_mirroring = RW_MGR_MEM_ADDRESS_MIRRORING, |
| 257 | .mem_data_mask_width = RW_MGR_MEM_DATA_MASK_WIDTH, |
| 258 | .mem_data_width = RW_MGR_MEM_DATA_WIDTH, |
| 259 | .mem_dq_per_read_dqs = RW_MGR_MEM_DQ_PER_READ_DQS, |
| 260 | .mem_dq_per_write_dqs = RW_MGR_MEM_DQ_PER_WRITE_DQS, |
| 261 | .mem_if_read_dqs_width = RW_MGR_MEM_IF_READ_DQS_WIDTH, |
| 262 | .mem_if_write_dqs_width = RW_MGR_MEM_IF_WRITE_DQS_WIDTH, |
| 263 | .mem_number_of_cs_per_dimm = RW_MGR_MEM_NUMBER_OF_CS_PER_DIMM, |
| 264 | .mem_number_of_ranks = RW_MGR_MEM_NUMBER_OF_RANKS, |
| 265 | .mem_virtual_groups_per_read_dqs = |
| 266 | RW_MGR_MEM_VIRTUAL_GROUPS_PER_READ_DQS, |
| 267 | .mem_virtual_groups_per_write_dqs = |
| 268 | RW_MGR_MEM_VIRTUAL_GROUPS_PER_WRITE_DQS, |
| 269 | }; |
| 270 | |
Simon Goldschmidt | ceab269 | 2018-11-14 21:05:12 +0100 | [diff] [blame] | 271 | static const struct socfpga_sdram_io_config io_config = { |
Marek Vasut | 3bf9204 | 2015-08-02 19:00:23 +0200 | [diff] [blame] | 272 | .delay_per_dchain_tap = IO_DELAY_PER_DCHAIN_TAP, |
| 273 | .delay_per_dqs_en_dchain_tap = IO_DELAY_PER_DQS_EN_DCHAIN_TAP, |
| 274 | .delay_per_opa_tap = IO_DELAY_PER_OPA_TAP, |
| 275 | .dll_chain_length = IO_DLL_CHAIN_LENGTH, |
| 276 | .dqdqs_out_phase_max = IO_DQDQS_OUT_PHASE_MAX, |
| 277 | .dqs_en_delay_max = IO_DQS_EN_DELAY_MAX, |
| 278 | .dqs_en_delay_offset = IO_DQS_EN_DELAY_OFFSET, |
| 279 | .dqs_en_phase_max = IO_DQS_EN_PHASE_MAX, |
| 280 | .dqs_in_delay_max = IO_DQS_IN_DELAY_MAX, |
| 281 | .dqs_in_reserve = IO_DQS_IN_RESERVE, |
| 282 | .dqs_out_reserve = IO_DQS_OUT_RESERVE, |
| 283 | .io_in_delay_max = IO_IO_IN_DELAY_MAX, |
| 284 | .io_out1_delay_max = IO_IO_OUT1_DELAY_MAX, |
| 285 | .io_out2_delay_max = IO_IO_OUT2_DELAY_MAX, |
| 286 | .shift_dqs_en_when_shift_dqs = IO_SHIFT_DQS_EN_WHEN_SHIFT_DQS, |
| 287 | }; |
| 288 | |
Simon Goldschmidt | ceab269 | 2018-11-14 21:05:12 +0100 | [diff] [blame] | 289 | static const struct socfpga_sdram_misc_config misc_config = { |
Tom Rini | dcdd3bd | 2022-10-28 20:27:14 -0400 | [diff] [blame] | 290 | #if (CFG_HPS_SDR_CTRLCFG_CTRLCFG_MEMTYPE == 1) /* DDR2 */ |
Marek Vasut | 6bccacf | 2019-10-18 00:22:31 +0200 | [diff] [blame] | 291 | .afi_clk_freq = AFI_CLK_FREQ, |
| 292 | #endif |
Marek Vasut | f00a6ea | 2015-08-02 19:18:47 +0200 | [diff] [blame] | 293 | .afi_rate_ratio = AFI_RATE_RATIO, |
| 294 | .calib_lfifo_offset = CALIB_LFIFO_OFFSET, |
| 295 | .calib_vfifo_offset = CALIB_VFIFO_OFFSET, |
| 296 | .enable_super_quick_calibration = ENABLE_SUPER_QUICK_CALIBRATION, |
| 297 | .max_latency_count_width = MAX_LATENCY_COUNT_WIDTH, |
| 298 | .read_valid_fifo_size = READ_VALID_FIFO_SIZE, |
| 299 | .reg_file_init_seq_signature = REG_FILE_INIT_SEQ_SIGNATURE, |
| 300 | .tinit_cntr0_val = TINIT_CNTR0_VAL, |
| 301 | .tinit_cntr1_val = TINIT_CNTR1_VAL, |
| 302 | .tinit_cntr2_val = TINIT_CNTR2_VAL, |
| 303 | .treset_cntr0_val = TRESET_CNTR0_VAL, |
| 304 | .treset_cntr1_val = TRESET_CNTR1_VAL, |
| 305 | .treset_cntr2_val = TRESET_CNTR2_VAL, |
| 306 | }; |
| 307 | |
Marek Vasut | 32ada57 | 2015-08-01 21:35:18 +0200 | [diff] [blame] | 308 | const struct socfpga_sdram_config *socfpga_get_sdram_config(void) |
| 309 | { |
| 310 | return &sdram_config; |
| 311 | } |
Marek Vasut | 3384e74 | 2015-08-02 17:15:19 +0200 | [diff] [blame] | 312 | |
| 313 | void socfpga_get_seq_ac_init(const u32 **init, unsigned int *nelem) |
| 314 | { |
| 315 | *init = ac_rom_init; |
| 316 | *nelem = ARRAY_SIZE(ac_rom_init); |
| 317 | } |
| 318 | |
| 319 | void socfpga_get_seq_inst_init(const u32 **init, unsigned int *nelem) |
| 320 | { |
| 321 | *init = inst_rom_init; |
| 322 | *nelem = ARRAY_SIZE(inst_rom_init); |
| 323 | } |
Marek Vasut | 39b620e | 2015-08-02 18:12:08 +0200 | [diff] [blame] | 324 | |
| 325 | const struct socfpga_sdram_rw_mgr_config *socfpga_get_sdram_rwmgr_config(void) |
| 326 | { |
| 327 | return &rw_mgr_config; |
| 328 | } |
Marek Vasut | 3bf9204 | 2015-08-02 19:00:23 +0200 | [diff] [blame] | 329 | |
| 330 | const struct socfpga_sdram_io_config *socfpga_get_sdram_io_config(void) |
| 331 | { |
| 332 | return &io_config; |
| 333 | } |
Marek Vasut | f00a6ea | 2015-08-02 19:18:47 +0200 | [diff] [blame] | 334 | |
| 335 | const struct socfpga_sdram_misc_config *socfpga_get_sdram_misc_config(void) |
| 336 | { |
| 337 | return &misc_config; |
| 338 | } |