Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright 2013 Google Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <arch/io.h> |
| 17 | #include <console/console.h> |
| 18 | #include <delay.h> |
| 19 | #include <soc/addressmap.h> |
| 20 | #include <soc/clock.h> |
Julius Werner | f0d21ff3 | 2014-10-20 13:24:14 -0700 | [diff] [blame] | 21 | #include <soc/emc.h> |
| 22 | #include <soc/mc.h> |
| 23 | #include <soc/pmc.h> |
| 24 | #include <soc/sdram.h> |
Gabe Black | 5cbbc70 | 2014-02-08 05:17:38 -0800 | [diff] [blame] | 25 | #include <stdlib.h> |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 26 | #include <symbols.h> |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 27 | |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 28 | |
| 29 | static void sdram_patch(uintptr_t addr, uint32_t value) |
| 30 | { |
| 31 | if (addr) |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 32 | write32((uint32_t *)addr, value); |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | static void writebits(uint32_t value, uint32_t *addr, uint32_t mask) |
| 36 | { |
| 37 | clrsetbits_le32(addr, mask, (value & mask)); |
| 38 | } |
| 39 | |
| 40 | /* PMC must be configured before clock-enable and de-reset of MC/EMC. */ |
| 41 | static void sdram_configure_pmc(const struct sdram_params *param, |
| 42 | struct tegra_pmc_regs *regs) |
| 43 | { |
| 44 | /* VDDP Select */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 45 | write32(®s->vddp_sel, param->PmcVddpSel); |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 46 | udelay(param->PmcVddpSelWait); |
| 47 | |
| 48 | /* Set DDR pad voltage */ |
| 49 | writebits(param->PmcDdrPwr, ®s->ddr_pwr, PMC_DDR_PWR_VAL_MASK); |
| 50 | |
| 51 | /* Set package and DPD pad control */ |
| 52 | writebits(param->PmcDdrCfg, ®s->ddr_cfg, |
| 53 | (PMC_DDR_CFG_PKG_MASK | PMC_DDR_CFG_IF_MASK | |
| 54 | PMC_DDR_CFG_XM0_RESET_TRI_MASK | |
| 55 | PMC_DDR_CFG_XM0_RESET_DPDIO_MASK)); |
| 56 | |
| 57 | /* Turn on MEM IO Power */ |
| 58 | writebits(param->PmcNoIoPower, ®s->no_iopower, |
| 59 | (PMC_NO_IOPOWER_MEM_MASK | PMC_NO_IOPOWER_MEM_COMP_MASK)); |
| 60 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 61 | write32(®s->reg_short, param->PmcRegShort); |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | static void sdram_start_clocks(const struct sdram_params *param) |
| 65 | { |
| 66 | u32 is_same_freq = (param->McEmemArbMisc0 & |
| 67 | MC_EMEM_ARB_MISC0_MC_EMC_SAME_FREQ_MASK) ? 1 : 0; |
| 68 | |
| 69 | clock_sdram(param->PllMInputDivider, param->PllMFeedbackDivider, |
| 70 | param->PllMSelectDiv2, param->PllMSetupControl, |
| 71 | param->PllMPDLshiftPh45, param->PllMPDLshiftPh90, |
| 72 | param->PllMPDLshiftPh135, param->PllMKVCO, |
| 73 | param->PllMKCP, param->PllMStableTime, |
| 74 | param->EmcClockSource, is_same_freq); |
| 75 | } |
| 76 | |
| 77 | static void sdram_deassert_clock_enable_signal(const struct sdram_params *param, |
| 78 | struct tegra_pmc_regs *regs) |
| 79 | { |
| 80 | clrbits_le32(®s->por_dpd_ctrl, |
| 81 | PMC_POR_DPD_CTRL_MEM0_HOLD_CKE_LOW_OVR_MASK); |
| 82 | udelay(param->PmcPorDpdCtrlWait); |
| 83 | } |
| 84 | |
| 85 | static void sdram_deassert_sel_dpd(const struct sdram_params *param, |
| 86 | struct tegra_pmc_regs *regs) |
| 87 | { |
| 88 | clrbits_le32(®s->por_dpd_ctrl, |
| 89 | (PMC_POR_DPD_CTRL_MEM0_ADDR0_CLK_SEL_DPD_MASK | |
| 90 | PMC_POR_DPD_CTRL_MEM0_ADDR1_CLK_SEL_DPD_MASK)); |
| 91 | /* |
| 92 | * Note NVIDIA recommended to always do 10us delay here and ignore |
| 93 | * BCT.PmcPorDpdCtrlWait. |
| 94 | * */ |
| 95 | udelay(10); |
| 96 | } |
| 97 | |
| 98 | static void sdram_set_swizzle(const struct sdram_params *param, |
| 99 | struct tegra_emc_regs *regs) |
| 100 | { |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 101 | write32(®s->swizzle_rank0_byte_cfg, param->EmcSwizzleRank0ByteCfg); |
| 102 | write32(®s->swizzle_rank0_byte0, param->EmcSwizzleRank0Byte0); |
| 103 | write32(®s->swizzle_rank0_byte1, param->EmcSwizzleRank0Byte1); |
| 104 | write32(®s->swizzle_rank0_byte2, param->EmcSwizzleRank0Byte2); |
| 105 | write32(®s->swizzle_rank0_byte3, param->EmcSwizzleRank0Byte3); |
| 106 | write32(®s->swizzle_rank1_byte_cfg, param->EmcSwizzleRank1ByteCfg); |
| 107 | write32(®s->swizzle_rank1_byte0, param->EmcSwizzleRank1Byte0); |
| 108 | write32(®s->swizzle_rank1_byte1, param->EmcSwizzleRank1Byte1); |
| 109 | write32(®s->swizzle_rank1_byte2, param->EmcSwizzleRank1Byte2); |
| 110 | write32(®s->swizzle_rank1_byte3, param->EmcSwizzleRank1Byte3); |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | static void sdram_set_pad_controls(const struct sdram_params *param, |
| 114 | struct tegra_emc_regs *regs) |
| 115 | { |
| 116 | /* Program the pad controls */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 117 | write32(®s->xm2cmdpadctrl, param->EmcXm2CmdPadCtrl); |
| 118 | write32(®s->xm2cmdpadctrl2, param->EmcXm2CmdPadCtrl2); |
| 119 | write32(®s->xm2cmdpadctrl3, param->EmcXm2CmdPadCtrl3); |
| 120 | write32(®s->xm2cmdpadctrl4, param->EmcXm2CmdPadCtrl4); |
| 121 | write32(®s->xm2cmdpadctrl5, param->EmcXm2CmdPadCtrl5); |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 122 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 123 | write32(®s->xm2dqspadctrl, param->EmcXm2DqsPadCtrl); |
| 124 | write32(®s->xm2dqspadctrl2, param->EmcXm2DqsPadCtrl2); |
| 125 | write32(®s->xm2dqspadctrl3, param->EmcXm2DqsPadCtrl3); |
| 126 | write32(®s->xm2dqspadctrl4, param->EmcXm2DqsPadCtrl4); |
| 127 | write32(®s->xm2dqspadctrl5, param->EmcXm2DqsPadCtrl5); |
| 128 | write32(®s->xm2dqspadctrl6, param->EmcXm2DqsPadCtrl6); |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 129 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 130 | write32(®s->xm2dqpadctrl, param->EmcXm2DqPadCtrl); |
| 131 | write32(®s->xm2dqpadctrl2, param->EmcXm2DqPadCtrl2); |
| 132 | write32(®s->xm2dqpadctrl3, param->EmcXm2DqPadCtrl3); |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 133 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 134 | write32(®s->xm2clkpadctrl, param->EmcXm2ClkPadCtrl); |
| 135 | write32(®s->xm2clkpadctrl2, param->EmcXm2ClkPadCtrl2); |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 136 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 137 | write32(®s->xm2comppadctrl, param->EmcXm2CompPadCtrl); |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 138 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 139 | write32(®s->xm2vttgenpadctrl, param->EmcXm2VttGenPadCtrl); |
| 140 | write32(®s->xm2vttgenpadctrl2, param->EmcXm2VttGenPadCtrl2); |
| 141 | write32(®s->xm2vttgenpadctrl3, param->EmcXm2VttGenPadCtrl3); |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 142 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 143 | write32(®s->ctt_term_ctrl, param->EmcCttTermCtrl); |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | static void sdram_trigger_emc_timing_update(struct tegra_emc_regs *regs) |
| 147 | { |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 148 | write32(®s->timing_control, EMC_TIMING_CONTROL_TIMING_UPDATE); |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | static void sdram_init_mc(const struct sdram_params *param, |
| 152 | struct tegra_mc_regs *regs) |
| 153 | { |
| 154 | /* Initialize MC VPR settings */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 155 | write32(®s->display_snap_ring, param->McDisplaySnapRing); |
| 156 | write32(®s->video_protect_bom, param->McVideoProtectBom); |
| 157 | write32(®s->video_protect_bom_adr_hi, |
| 158 | param->McVideoProtectBomAdrHi); |
| 159 | write32(®s->video_protect_size_mb, param->McVideoProtectSizeMb); |
| 160 | write32(®s->video_protect_vpr_override, |
| 161 | param->McVideoProtectVprOverride); |
| 162 | write32(®s->video_protect_vpr_override1, |
| 163 | param->McVideoProtectVprOverride1); |
| 164 | write32(®s->video_protect_gpu_override_0, |
| 165 | param->McVideoProtectGpuOverride0); |
| 166 | write32(®s->video_protect_gpu_override_1, |
| 167 | param->McVideoProtectGpuOverride1); |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 168 | |
| 169 | /* Program SDRAM geometry paarameters */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 170 | write32(®s->emem_adr_cfg, param->McEmemAdrCfg); |
| 171 | write32(®s->emem_adr_cfg_dev0, param->McEmemAdrCfgDev0); |
| 172 | write32(®s->emem_adr_cfg_dev1, param->McEmemAdrCfgDev1); |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 173 | |
| 174 | /* Program bank swizzling */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 175 | write32(®s->emem_bank_swizzle_cfg0, param->McEmemAdrCfgBankMask0); |
| 176 | write32(®s->emem_bank_swizzle_cfg1, param->McEmemAdrCfgBankMask1); |
| 177 | write32(®s->emem_bank_swizzle_cfg2, param->McEmemAdrCfgBankMask2); |
| 178 | write32(®s->emem_bank_swizzle_cfg3, |
| 179 | param->McEmemAdrCfgBankSwizzle3); |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 180 | |
| 181 | /* Program external memory aperature (base and size) */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 182 | write32(®s->emem_cfg, param->McEmemCfg); |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 183 | |
| 184 | /* Program SEC carveout (base and size) */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 185 | write32(®s->sec_carveout_bom, param->McSecCarveoutBom); |
| 186 | write32(®s->sec_carveout_adr_hi, param->McSecCarveoutAdrHi); |
| 187 | write32(®s->sec_carveout_size_mb, param->McSecCarveoutSizeMb); |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 188 | |
| 189 | /* Program MTS carveout (base and size) */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 190 | write32(®s->mts_carveout_bom, param->McMtsCarveoutBom); |
| 191 | write32(®s->mts_carveout_adr_hi, param->McMtsCarveoutAdrHi); |
| 192 | write32(®s->mts_carveout_size_mb, param->McMtsCarveoutSizeMb); |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 193 | |
| 194 | /* Program the memory arbiter */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 195 | write32(®s->emem_arb_cfg, param->McEmemArbCfg); |
| 196 | write32(®s->emem_arb_outstanding_req, |
| 197 | param->McEmemArbOutstandingReq); |
| 198 | write32(®s->emem_arb_timing_rcd, param->McEmemArbTimingRcd); |
| 199 | write32(®s->emem_arb_timing_rp, param->McEmemArbTimingRp); |
| 200 | write32(®s->emem_arb_timing_rc, param->McEmemArbTimingRc); |
| 201 | write32(®s->emem_arb_timing_ras, param->McEmemArbTimingRas); |
| 202 | write32(®s->emem_arb_timing_faw, param->McEmemArbTimingFaw); |
| 203 | write32(®s->emem_arb_timing_rrd, param->McEmemArbTimingRrd); |
| 204 | write32(®s->emem_arb_timing_rap2pre, param->McEmemArbTimingRap2Pre); |
| 205 | write32(®s->emem_arb_timing_wap2pre, param->McEmemArbTimingWap2Pre); |
| 206 | write32(®s->emem_arb_timing_r2r, param->McEmemArbTimingR2R); |
| 207 | write32(®s->emem_arb_timing_w2w, param->McEmemArbTimingW2W); |
| 208 | write32(®s->emem_arb_timing_r2w, param->McEmemArbTimingR2W); |
| 209 | write32(®s->emem_arb_timing_w2r, param->McEmemArbTimingW2R); |
| 210 | write32(®s->emem_arb_da_turns, param->McEmemArbDaTurns); |
| 211 | write32(®s->emem_arb_da_covers, param->McEmemArbDaCovers); |
| 212 | write32(®s->emem_arb_misc0, param->McEmemArbMisc0); |
| 213 | write32(®s->emem_arb_misc1, param->McEmemArbMisc1); |
| 214 | write32(®s->emem_arb_ring1_throttle, param->McEmemArbRing1Throttle); |
| 215 | write32(®s->emem_arb_override, param->McEmemArbOverride); |
| 216 | write32(®s->emem_arb_override_1, param->McEmemArbOverride1); |
| 217 | write32(®s->emem_arb_rsv, param->McEmemArbRsv); |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 218 | |
| 219 | /* Program extra snap levels for display client */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 220 | write32(®s->dis_extra_snap_levels, param->McDisExtraSnapLevels); |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 221 | |
| 222 | /* Trigger MC timing update */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 223 | write32(®s->timing_control, MC_TIMING_CONTROL_TIMING_UPDATE); |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 224 | |
| 225 | /* Program second-level clock enable overrides */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 226 | write32(®s->clken_override, param->McClkenOverride); |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 227 | |
| 228 | /* Program statistics gathering */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 229 | write32(®s->stat_control, param->McStatControl); |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | static void sdram_init_emc(const struct sdram_params *param, |
| 233 | struct tegra_emc_regs *regs) |
| 234 | { |
| 235 | /* Program SDRAM geometry parameters */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 236 | write32(®s->adr_cfg, param->EmcAdrCfg); |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 237 | |
| 238 | /* Program second-level clock enable overrides */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 239 | write32(®s->clken_override, param->EmcClkenOverride); |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 240 | |
| 241 | /* Program EMC pad auto calibration */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 242 | write32(®s->auto_cal_interval, param->EmcAutoCalInterval); |
| 243 | write32(®s->auto_cal_config2, param->EmcAutoCalConfig2); |
| 244 | write32(®s->auto_cal_config3, param->EmcAutoCalConfig3); |
| 245 | write32(®s->auto_cal_config, param->EmcAutoCalConfig); |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 246 | udelay(param->EmcAutoCalWait); |
| 247 | } |
| 248 | |
| 249 | static void sdram_set_emc_timing(const struct sdram_params *param, |
| 250 | struct tegra_emc_regs *regs) |
| 251 | { |
| 252 | /* Program EMC timing configuration */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 253 | write32(®s->cfg_2, param->EmcCfg2); |
| 254 | write32(®s->cfg_pipe, param->EmcCfgPipe); |
| 255 | write32(®s->dbg, param->EmcDbg); |
| 256 | write32(®s->cmdq, param->EmcCmdQ); |
| 257 | write32(®s->mc2emcq, param->EmcMc2EmcQ); |
| 258 | write32(®s->mrs_wait_cnt, param->EmcMrsWaitCnt); |
| 259 | write32(®s->mrs_wait_cnt2, param->EmcMrsWaitCnt2); |
| 260 | write32(®s->fbio_cfg5, param->EmcFbioCfg5); |
| 261 | write32(®s->rc, param->EmcRc); |
| 262 | write32(®s->rfc, param->EmcRfc); |
| 263 | write32(®s->rfc_slr, param->EmcRfcSlr); |
| 264 | write32(®s->ras, param->EmcRas); |
| 265 | write32(®s->rp, param->EmcRp); |
| 266 | write32(®s->r2r, param->EmcR2r); |
| 267 | write32(®s->w2w, param->EmcW2w); |
| 268 | write32(®s->r2w, param->EmcR2w); |
| 269 | write32(®s->w2r, param->EmcW2r); |
| 270 | write32(®s->r2p, param->EmcR2p); |
| 271 | write32(®s->w2p, param->EmcW2p); |
| 272 | write32(®s->rd_rcd, param->EmcRdRcd); |
| 273 | write32(®s->wr_rcd, param->EmcWrRcd); |
| 274 | write32(®s->rrd, param->EmcRrd); |
| 275 | write32(®s->rext, param->EmcRext); |
| 276 | write32(®s->wext, param->EmcWext); |
| 277 | write32(®s->wdv, param->EmcWdv); |
| 278 | write32(®s->wdv_mask, param->EmcWdvMask); |
| 279 | write32(®s->quse, param->EmcQUse); |
| 280 | write32(®s->quse_width, param->EmcQuseWidth); |
| 281 | write32(®s->ibdly, param->EmcIbdly); |
| 282 | write32(®s->einput, param->EmcEInput); |
| 283 | write32(®s->einput_duration, param->EmcEInputDuration); |
| 284 | write32(®s->puterm_extra, param->EmcPutermExtra); |
| 285 | write32(®s->puterm_width, param->EmcPutermWidth); |
| 286 | write32(®s->puterm_adj, param->EmcPutermAdj); |
| 287 | write32(®s->cdb_cntl_1, param->EmcCdbCntl1); |
| 288 | write32(®s->cdb_cntl_2, param->EmcCdbCntl2); |
| 289 | write32(®s->cdb_cntl_3, param->EmcCdbCntl3); |
| 290 | write32(®s->qrst, param->EmcQRst); |
| 291 | write32(®s->qsafe, param->EmcQSafe); |
| 292 | write32(®s->rdv, param->EmcRdv); |
| 293 | write32(®s->rdv_mask, param->EmcRdvMask); |
| 294 | write32(®s->qpop, param->EmcQpop); |
| 295 | write32(®s->ctt, param->EmcCtt); |
| 296 | write32(®s->ctt_duration, param->EmcCttDuration); |
| 297 | write32(®s->refresh, param->EmcRefresh); |
| 298 | write32(®s->burst_refresh_num, param->EmcBurstRefreshNum); |
| 299 | write32(®s->pre_refresh_req_cnt, param->EmcPreRefreshReqCnt); |
| 300 | write32(®s->pdex2wr, param->EmcPdEx2Wr); |
| 301 | write32(®s->pdex2rd, param->EmcPdEx2Rd); |
| 302 | write32(®s->pchg2pden, param->EmcPChg2Pden); |
| 303 | write32(®s->act2pden, param->EmcAct2Pden); |
| 304 | write32(®s->ar2pden, param->EmcAr2Pden); |
| 305 | write32(®s->rw2pden, param->EmcRw2Pden); |
| 306 | write32(®s->txsr, param->EmcTxsr); |
| 307 | write32(®s->txsrdll, param->EmcTxsrDll); |
| 308 | write32(®s->tcke, param->EmcTcke); |
| 309 | write32(®s->tckesr, param->EmcTckesr); |
| 310 | write32(®s->tpd, param->EmcTpd); |
| 311 | write32(®s->tfaw, param->EmcTfaw); |
| 312 | write32(®s->trpab, param->EmcTrpab); |
| 313 | write32(®s->tclkstable, param->EmcTClkStable); |
| 314 | write32(®s->tclkstop, param->EmcTClkStop); |
| 315 | write32(®s->trefbw, param->EmcTRefBw); |
| 316 | write32(®s->odt_write, param->EmcOdtWrite); |
| 317 | write32(®s->odt_read, param->EmcOdtRead); |
| 318 | write32(®s->fbio_cfg6, param->EmcFbioCfg6); |
| 319 | write32(®s->cfg_dig_dll, param->EmcCfgDigDll); |
| 320 | write32(®s->cfg_dig_dll_period, param->EmcCfgDigDllPeriod); |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 321 | |
| 322 | /* Don't write bit 1: addr swizzle lock bit. Written at end of sequence. */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 323 | write32(®s->fbio_spare, param->EmcFbioSpare & 0xfffffffd); |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 324 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 325 | write32(®s->cfg_rsv, param->EmcCfgRsv); |
| 326 | write32(®s->dll_xform_dqs0, param->EmcDllXformDqs0); |
| 327 | write32(®s->dll_xform_dqs1, param->EmcDllXformDqs1); |
| 328 | write32(®s->dll_xform_dqs2, param->EmcDllXformDqs2); |
| 329 | write32(®s->dll_xform_dqs3, param->EmcDllXformDqs3); |
| 330 | write32(®s->dll_xform_dqs4, param->EmcDllXformDqs4); |
| 331 | write32(®s->dll_xform_dqs5, param->EmcDllXformDqs5); |
| 332 | write32(®s->dll_xform_dqs6, param->EmcDllXformDqs6); |
| 333 | write32(®s->dll_xform_dqs7, param->EmcDllXformDqs7); |
| 334 | write32(®s->dll_xform_dqs8, param->EmcDllXformDqs8); |
| 335 | write32(®s->dll_xform_dqs9, param->EmcDllXformDqs9); |
| 336 | write32(®s->dll_xform_dqs10, param->EmcDllXformDqs10); |
| 337 | write32(®s->dll_xform_dqs11, param->EmcDllXformDqs11); |
| 338 | write32(®s->dll_xform_dqs12, param->EmcDllXformDqs12); |
| 339 | write32(®s->dll_xform_dqs13, param->EmcDllXformDqs13); |
| 340 | write32(®s->dll_xform_dqs14, param->EmcDllXformDqs14); |
| 341 | write32(®s->dll_xform_dqs15, param->EmcDllXformDqs15); |
| 342 | write32(®s->dll_xform_quse0, param->EmcDllXformQUse0); |
| 343 | write32(®s->dll_xform_quse1, param->EmcDllXformQUse1); |
| 344 | write32(®s->dll_xform_quse2, param->EmcDllXformQUse2); |
| 345 | write32(®s->dll_xform_quse3, param->EmcDllXformQUse3); |
| 346 | write32(®s->dll_xform_quse4, param->EmcDllXformQUse4); |
| 347 | write32(®s->dll_xform_quse5, param->EmcDllXformQUse5); |
| 348 | write32(®s->dll_xform_quse6, param->EmcDllXformQUse6); |
| 349 | write32(®s->dll_xform_quse7, param->EmcDllXformQUse7); |
| 350 | write32(®s->dll_xform_quse8, param->EmcDllXformQUse8); |
| 351 | write32(®s->dll_xform_quse9, param->EmcDllXformQUse9); |
| 352 | write32(®s->dll_xform_quse10, param->EmcDllXformQUse10); |
| 353 | write32(®s->dll_xform_quse11, param->EmcDllXformQUse11); |
| 354 | write32(®s->dll_xform_quse12, param->EmcDllXformQUse12); |
| 355 | write32(®s->dll_xform_quse13, param->EmcDllXformQUse13); |
| 356 | write32(®s->dll_xform_quse14, param->EmcDllXformQUse14); |
| 357 | write32(®s->dll_xform_quse15, param->EmcDllXformQUse15); |
| 358 | write32(®s->dll_xform_dq0, param->EmcDllXformDq0); |
| 359 | write32(®s->dll_xform_dq1, param->EmcDllXformDq1); |
| 360 | write32(®s->dll_xform_dq2, param->EmcDllXformDq2); |
| 361 | write32(®s->dll_xform_dq3, param->EmcDllXformDq3); |
| 362 | write32(®s->dll_xform_dq4, param->EmcDllXformDq4); |
| 363 | write32(®s->dll_xform_dq5, param->EmcDllXformDq5); |
| 364 | write32(®s->dll_xform_dq6, param->EmcDllXformDq6); |
| 365 | write32(®s->dll_xform_dq7, param->EmcDllXformDq7); |
| 366 | write32(®s->dll_xform_addr0, param->EmcDllXformAddr0); |
| 367 | write32(®s->dll_xform_addr1, param->EmcDllXformAddr1); |
| 368 | write32(®s->dll_xform_addr2, param->EmcDllXformAddr2); |
| 369 | write32(®s->dll_xform_addr3, param->EmcDllXformAddr3); |
| 370 | write32(®s->dll_xform_addr4, param->EmcDllXformAddr4); |
| 371 | write32(®s->dll_xform_addr5, param->EmcDllXformAddr5); |
| 372 | write32(®s->acpd_control, param->EmcAcpdControl); |
| 373 | write32(®s->dsr_vttgen_drv, param->EmcDsrVttgenDrv); |
| 374 | write32(®s->txdsrvttgen, param->EmcTxdsrvttgen); |
| 375 | write32(®s->bgbias_ctl0, param->EmcBgbiasCtl0); |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 376 | |
| 377 | /* |
| 378 | * Set pipe bypass enable bits before sending any DRAM commands. |
| 379 | * Note other bits in EMC_CFG must be set AFTER REFCTRL is configured. |
| 380 | */ |
| 381 | writebits(param->EmcCfg, ®s->cfg, |
| 382 | (EMC_CFG_EMC2PMACRO_CFG_BYPASS_ADDRPIPE_MASK | |
| 383 | EMC_CFG_EMC2PMACRO_CFG_BYPASS_DATAPIPE1_MASK | |
| 384 | EMC_CFG_EMC2PMACRO_CFG_BYPASS_DATAPIPE2_MASK)); |
| 385 | } |
| 386 | |
| 387 | static void sdram_patch_bootrom(const struct sdram_params *param, |
| 388 | struct tegra_mc_regs *regs) |
| 389 | { |
| 390 | if (param->BootRomPatchControl & BOOT_ROM_PATCH_CONTROL_ENABLE_MASK) { |
| 391 | uintptr_t addr = ((param->BootRomPatchControl & |
| 392 | BOOT_ROM_PATCH_CONTROL_OFFSET_MASK) >> |
| 393 | BOOT_ROM_PATCH_CONTROL_OFFSET_SHIFT); |
| 394 | addr = BOOT_ROM_PATCH_CONTROL_BASE_ADDRESS + (addr << 2); |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 395 | write32((uint32_t *)addr, param->BootRomPatchData); |
| 396 | write32(®s->timing_control, 1); |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 397 | } |
| 398 | } |
| 399 | |
| 400 | static void sdram_set_dpd3(const struct sdram_params *param, |
| 401 | struct tegra_pmc_regs *regs) |
| 402 | { |
| 403 | /* Program DPD request */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 404 | write32(®s->io_dpd3_req, param->PmcIoDpd3Req); |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 405 | udelay(param->PmcIoDpd3ReqWait); |
| 406 | } |
| 407 | |
| 408 | static void sdram_set_dli_trims(const struct sdram_params *param, |
| 409 | struct tegra_emc_regs *regs) |
| 410 | { |
| 411 | /* Program DLI trims */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 412 | write32(®s->dli_trim_txdqs0, param->EmcDliTrimTxDqs0); |
| 413 | write32(®s->dli_trim_txdqs1, param->EmcDliTrimTxDqs1); |
| 414 | write32(®s->dli_trim_txdqs2, param->EmcDliTrimTxDqs2); |
| 415 | write32(®s->dli_trim_txdqs3, param->EmcDliTrimTxDqs3); |
| 416 | write32(®s->dli_trim_txdqs4, param->EmcDliTrimTxDqs4); |
| 417 | write32(®s->dli_trim_txdqs5, param->EmcDliTrimTxDqs5); |
| 418 | write32(®s->dli_trim_txdqs6, param->EmcDliTrimTxDqs6); |
| 419 | write32(®s->dli_trim_txdqs7, param->EmcDliTrimTxDqs7); |
| 420 | write32(®s->dli_trim_txdqs8, param->EmcDliTrimTxDqs8); |
| 421 | write32(®s->dli_trim_txdqs9, param->EmcDliTrimTxDqs9); |
| 422 | write32(®s->dli_trim_txdqs10, param->EmcDliTrimTxDqs10); |
| 423 | write32(®s->dli_trim_txdqs11, param->EmcDliTrimTxDqs11); |
| 424 | write32(®s->dli_trim_txdqs12, param->EmcDliTrimTxDqs12); |
| 425 | write32(®s->dli_trim_txdqs13, param->EmcDliTrimTxDqs13); |
| 426 | write32(®s->dli_trim_txdqs14, param->EmcDliTrimTxDqs14); |
| 427 | write32(®s->dli_trim_txdqs15, param->EmcDliTrimTxDqs15); |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 428 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 429 | write32(®s->ca_training_timing_cntl1, |
| 430 | param->EmcCaTrainingTimingCntl1); |
| 431 | write32(®s->ca_training_timing_cntl2, |
| 432 | param->EmcCaTrainingTimingCntl2); |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 433 | |
| 434 | sdram_trigger_emc_timing_update(regs); |
| 435 | udelay(param->EmcTimingControlWait); |
| 436 | } |
| 437 | |
| 438 | static void sdram_set_clock_enable_signal(const struct sdram_params *param, |
| 439 | struct tegra_emc_regs *regs) |
| 440 | { |
| 441 | volatile uint32_t dummy = 0; |
| 442 | clrbits_le32(®s->pin, (EMC_PIN_RESET_MASK | EMC_PIN_DQM_MASK | |
| 443 | EMC_PIN_CKE_MASK)); |
| 444 | /* |
| 445 | * Assert dummy read of PIN register to ensure above write to PIN |
| 446 | * register went through. 200 is the recommended value by NVIDIA. |
| 447 | */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 448 | dummy |= read32(®s->pin); |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 449 | udelay(200 + param->EmcPinExtraWait); |
| 450 | |
| 451 | /* Deassert reset */ |
| 452 | setbits_le32(®s->pin, EMC_PIN_RESET_INACTIVE); |
| 453 | /* |
| 454 | * Assert dummy read of PIN register to ensure above write to PIN |
| 455 | * register went through. 200 is the recommended value by NVIDIA. |
| 456 | */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 457 | dummy |= read32(®s->pin); |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 458 | udelay(500 + param->EmcPinExtraWait); |
| 459 | |
| 460 | /* Enable clock enable signal */ |
| 461 | setbits_le32(®s->pin, EMC_PIN_CKE_NORMAL); |
| 462 | /* |
| 463 | * Assert dummy read of PIN register to ensure above write to PIN |
| 464 | * register went through. 200 is the recommended value by NVIDIA. |
| 465 | */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 466 | dummy |= read32(®s->pin); |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 467 | udelay(param->EmcPinProgramWait); |
| 468 | |
| 469 | if (!dummy) { |
| 470 | die("Failed to program EMC pin."); |
| 471 | } |
| 472 | |
| 473 | /* Send NOP (trigger) */ |
| 474 | writebits(((1 << EMC_NOP_NOP_CMD_SHIFT) | |
| 475 | (param->EmcDevSelect << EMC_NOP_NOP_DEV_SELECTN_SHIFT)), |
| 476 | ®s->nop, |
| 477 | EMC_NOP_NOP_CMD_MASK | EMC_NOP_NOP_DEV_SELECTN_MASK); |
| 478 | |
| 479 | /* Write mode registers */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 480 | write32(®s->emrs2, param->EmcEmrs2); |
| 481 | write32(®s->emrs3, param->EmcEmrs3); |
| 482 | write32(®s->emrs, param->EmcEmrs); |
| 483 | write32(®s->mrs, param->EmcMrs); |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 484 | |
| 485 | if (param->EmcExtraModeRegWriteEnable) { |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 486 | write32(®s->mrs, param->EmcMrwExtra); |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 487 | } |
| 488 | } |
| 489 | |
| 490 | static void sdram_init_zq_calibration(const struct sdram_params *param, |
| 491 | struct tegra_emc_regs *regs) |
| 492 | { |
| 493 | if ((param->EmcZcalWarmColdBootEnables & |
| 494 | EMC_ZCAL_WARM_COLD_BOOT_ENABLES_COLDBOOT_MASK) == 1) { |
| 495 | /* Need to initialize ZCAL on coldboot. */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 496 | write32(®s->zq_cal, param->EmcZcalInitDev0); |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 497 | udelay(param->EmcZcalInitWait); |
| 498 | |
| 499 | if ((param->EmcDevSelect & 2) == 0) { |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 500 | write32(®s->zq_cal, param->EmcZcalInitDev1); |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 501 | udelay(param->EmcZcalInitWait); |
| 502 | } |
| 503 | } else { |
| 504 | udelay(param->EmcZcalInitWait); |
| 505 | } |
| 506 | } |
| 507 | |
| 508 | static void sdram_set_zq_calibration(const struct sdram_params *param, |
| 509 | struct tegra_emc_regs *regs) |
| 510 | { |
| 511 | /* Start periodic ZQ calibration */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 512 | write32(®s->zcal_interval, param->EmcZcalInterval); |
| 513 | write32(®s->zcal_wait_cnt, param->EmcZcalWaitCnt); |
| 514 | write32(®s->zcal_mrw_cmd, param->EmcZcalMrwCmd); |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | static void sdram_set_refresh(const struct sdram_params *param, |
| 518 | struct tegra_emc_regs *regs) |
| 519 | { |
| 520 | /* Insert burst refresh */ |
| 521 | if (param->EmcExtraRefreshNum > 0) { |
| 522 | uint32_t refresh_num = (1 << param->EmcExtraRefreshNum) - 1; |
| 523 | writebits((EMC_REF_CMD_REFRESH | EMC_REF_NORMAL_ENABLED | |
| 524 | (refresh_num << EMC_REF_NUM_SHIFT) | |
| 525 | (param->EmcDevSelect << EMC_REF_DEV_SELECTN_SHIFT)), |
| 526 | ®s->ref, (EMC_REF_CMD_MASK | EMC_REF_NORMAL_MASK | |
| 527 | EMC_REF_NUM_MASK | |
| 528 | EMC_REF_DEV_SELECTN_MASK)); |
| 529 | } |
| 530 | |
| 531 | /* Enable refresh */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 532 | write32(®s->refctrl, |
| 533 | (param->EmcDevSelect | EMC_REFCTRL_REF_VALID_ENABLED)); |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 534 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 535 | write32(®s->dyn_self_ref_control, param->EmcDynSelfRefControl); |
| 536 | write32(®s->cfg, param->EmcCfg); |
| 537 | write32(®s->sel_dpd_ctrl, param->EmcSelDpdCtrl); |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 538 | |
| 539 | /* Write addr swizzle lock bit */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 540 | write32(®s->fbio_spare, param->EmcFbioSpare); |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 541 | |
| 542 | /* Re-trigger timing to latch power saving functions */ |
| 543 | sdram_trigger_emc_timing_update(regs); |
| 544 | } |
| 545 | |
| 546 | static void sdram_enable_arbiter(const struct sdram_params *param) |
| 547 | { |
| 548 | /* TODO(hungte) Move values here to standalone header file. */ |
| 549 | uint32_t *AHB_ARBITRATION_XBAR_CTRL = (uint32_t*)(0x6000c000 + 0xe0); |
| 550 | setbits_le32(AHB_ARBITRATION_XBAR_CTRL, |
| 551 | param->AhbArbitrationXbarCtrlMemInitDone << 16); |
| 552 | } |
| 553 | |
| 554 | static void sdram_lock_carveouts(const struct sdram_params *param, |
| 555 | struct tegra_mc_regs *regs) |
| 556 | { |
| 557 | /* Lock carveouts, and emem_cfg registers */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 558 | write32(®s->video_protect_reg_ctrl, |
| 559 | param->McVideoProtectWriteAccess); |
| 560 | write32(®s->emem_cfg_access_ctrl, |
| 561 | MC_EMEM_CFG_ACCESS_CTRL_WRITE_ACCESS_DISABLED); |
| 562 | write32(®s->sec_carveout_reg_ctrl, |
| 563 | param->McSecCarveoutProtectWriteAccess); |
| 564 | write32(®s->mts_carveout_reg_ctrl, param->McMtsCarveoutRegCtrl); |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | void sdram_init(const struct sdram_params *param) |
| 568 | { |
| 569 | struct tegra_pmc_regs *pmc = (struct tegra_pmc_regs*)TEGRA_PMC_BASE; |
| 570 | struct tegra_mc_regs *mc = (struct tegra_mc_regs*)TEGRA_MC_BASE; |
| 571 | struct tegra_emc_regs *emc = (struct tegra_emc_regs*)TEGRA_EMC_BASE; |
| 572 | |
Tom Warren | 64982c50 | 2014-01-23 13:37:50 -0700 | [diff] [blame] | 573 | printk(BIOS_DEBUG, "Initializing SDRAM of type %d with %dKHz\n", |
Julius Werner | e57c303 | 2014-04-11 18:23:12 -0700 | [diff] [blame] | 574 | param->MemoryType, clock_get_pll_input_khz() * |
Tom Warren | 64982c50 | 2014-01-23 13:37:50 -0700 | [diff] [blame] | 575 | param->PllMFeedbackDivider / param->PllMInputDivider / |
| 576 | (1 + param->PllMSelectDiv2)); |
| 577 | if (param->MemoryType != NvBootMemoryType_Ddr3) |
| 578 | die("Unsupported memory type!\n"); |
| 579 | |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 580 | sdram_configure_pmc(param, pmc); |
| 581 | sdram_patch(param->EmcBctSpare0, param->EmcBctSpare1); |
| 582 | |
| 583 | sdram_start_clocks(param); |
| 584 | sdram_patch(param->EmcBctSpare2, param->EmcBctSpare3); |
| 585 | |
| 586 | sdram_deassert_sel_dpd(param, pmc); |
| 587 | sdram_set_swizzle(param, emc); |
| 588 | sdram_set_pad_controls(param, emc); |
| 589 | sdram_patch(param->EmcBctSpare4, param->EmcBctSpare5); |
| 590 | |
| 591 | sdram_trigger_emc_timing_update(emc); |
| 592 | sdram_init_mc(param, mc); |
| 593 | sdram_init_emc(param, emc); |
| 594 | sdram_patch(param->EmcBctSpare6, param->EmcBctSpare7); |
| 595 | |
| 596 | sdram_set_emc_timing(param, emc); |
| 597 | sdram_patch_bootrom(param, mc); |
| 598 | sdram_set_dpd3(param, pmc); |
| 599 | sdram_set_dli_trims(param, emc); |
| 600 | sdram_deassert_clock_enable_signal(param, pmc); |
| 601 | sdram_set_clock_enable_signal(param, emc); |
| 602 | sdram_init_zq_calibration(param, emc); |
| 603 | sdram_patch(param->EmcBctSpare8, param->EmcBctSpare9); |
| 604 | |
| 605 | sdram_set_zq_calibration(param, emc); |
| 606 | sdram_patch(param->EmcBctSpare10, param->EmcBctSpare11); |
| 607 | |
| 608 | sdram_trigger_emc_timing_update(emc); |
| 609 | sdram_set_refresh(param, emc); |
| 610 | sdram_enable_arbiter(param); |
| 611 | sdram_lock_carveouts(param, mc); |
Tom Warren | 64982c50 | 2014-01-23 13:37:50 -0700 | [diff] [blame] | 612 | |
| 613 | sdram_lp0_save_params(param); |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | uint32_t sdram_get_ram_code(void) |
| 617 | { |
| 618 | struct tegra_pmc_regs *pmc = (struct tegra_pmc_regs*)TEGRA_PMC_BASE; |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 619 | return ((read32(&pmc->strapping_opt_a) & |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 620 | PMC_STRAPPING_OPT_A_RAM_CODE_MASK) >> |
| 621 | PMC_STRAPPING_OPT_A_RAM_CODE_SHIFT); |
| 622 | } |
Tom Warren | 64982c50 | 2014-01-23 13:37:50 -0700 | [diff] [blame] | 623 | |
| 624 | /* returns total amount of DRAM (in MB) from memory controller registers */ |
| 625 | int sdram_size_mb(void) |
| 626 | { |
| 627 | struct tegra_mc_regs *mc = (struct tegra_mc_regs *)TEGRA_MC_BASE; |
| 628 | static int total_size = 0; |
| 629 | |
| 630 | if (total_size) |
| 631 | return total_size; |
| 632 | |
| 633 | /* |
| 634 | * This obtains memory size from the External Memory Aperture |
| 635 | * Configuration register. Nvidia confirmed that it is safe to assume |
| 636 | * this value represents the total physical DRAM size. |
| 637 | */ |
| 638 | total_size = (read32(&mc->emem_cfg) >> |
| 639 | MC_EMEM_CFG_SIZE_MB_SHIFT) & MC_EMEM_CFG_SIZE_MB_MASK; |
| 640 | |
| 641 | printk(BIOS_DEBUG, "%s: Total SDRAM (MB): %u\n", __func__, total_size); |
| 642 | return total_size; |
| 643 | } |
Gabe Black | 5cbbc70 | 2014-02-08 05:17:38 -0800 | [diff] [blame] | 644 | |
| 645 | uintptr_t sdram_max_addressable_mb(void) |
| 646 | { |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 647 | return MIN(((uintptr_t)_dram/MiB) + sdram_size_mb(), 4096); |
Gabe Black | 5cbbc70 | 2014-02-08 05:17:38 -0800 | [diff] [blame] | 648 | } |