Chris Packham | 2e0d2ba | 2018-12-10 10:41:15 +1300 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * Copyright (C) Marvell International Ltd. and its affiliates |
| 4 | */ |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 5 | |
| 6 | #include "ddr3_init.h" |
Moti Buskila | 2b368e1 | 2021-02-19 17:11:22 +0100 | [diff] [blame^] | 7 | #include "mv_ddr_common.h" |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 8 | #include "mv_ddr_training_db.h" |
| 9 | #include "mv_ddr_regs.h" |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 10 | #include "mv_ddr_sys_env_lib.h" |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 11 | #include <linux/delay.h> |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 12 | |
| 13 | #define DDR_INTERFACES_NUM 1 |
| 14 | #define DDR_INTERFACE_OCTETS_NUM 5 |
| 15 | |
| 16 | /* |
| 17 | * 1. L2 filter should be set at binary header to 0xD000000, |
| 18 | * to avoid conflict with internal register IO. |
| 19 | * 2. U-Boot modifies internal registers base to 0xf100000, |
| 20 | * and than should update L2 filter accordingly to 0xf000000 (3.75 GB) |
| 21 | */ |
| 22 | #define L2_FILTER_FOR_MAX_MEMORY_SIZE 0xC0000000 /* temporary limit l2 filter to 3gb (LSP issue) */ |
| 23 | #define ADDRESS_FILTERING_END_REGISTER 0x8c04 |
| 24 | |
| 25 | #define DYNAMIC_CS_SIZE_CONFIG |
| 26 | #define DISABLE_L2_FILTERING_DURING_DDR_TRAINING |
| 27 | |
| 28 | /* Termal Sensor Registers */ |
| 29 | #define TSEN_CONTROL_LSB_REG 0xE4070 |
| 30 | #define TSEN_CONTROL_LSB_TC_TRIM_OFFSET 0 |
| 31 | #define TSEN_CONTROL_LSB_TC_TRIM_MASK (0x7 << TSEN_CONTROL_LSB_TC_TRIM_OFFSET) |
| 32 | #define TSEN_CONTROL_MSB_REG 0xE4074 |
| 33 | #define TSEN_CONTROL_MSB_RST_OFFSET 8 |
| 34 | #define TSEN_CONTROL_MSB_RST_MASK (0x1 << TSEN_CONTROL_MSB_RST_OFFSET) |
| 35 | #define TSEN_STATUS_REG 0xe4078 |
| 36 | #define TSEN_STATUS_READOUT_VALID_OFFSET 10 |
| 37 | #define TSEN_STATUS_READOUT_VALID_MASK (0x1 << \ |
| 38 | TSEN_STATUS_READOUT_VALID_OFFSET) |
| 39 | #define TSEN_STATUS_TEMP_OUT_OFFSET 0 |
| 40 | #define TSEN_STATUS_TEMP_OUT_MASK (0x3ff << TSEN_STATUS_TEMP_OUT_OFFSET) |
| 41 | |
| 42 | static struct dlb_config ddr3_dlb_config_table[] = { |
| 43 | {DLB_CTRL_REG, 0x2000005c}, |
| 44 | {DLB_BUS_OPT_WT_REG, 0x00880000}, |
| 45 | {DLB_AGING_REG, 0x0f7f007f}, |
| 46 | {DLB_EVICTION_CTRL_REG, 0x0000129f}, |
| 47 | {DLB_EVICTION_TIMERS_REG, 0x00ff0000}, |
| 48 | {DLB_WTS_DIFF_CS_REG, 0x04030802}, |
| 49 | {DLB_WTS_DIFF_BG_REG, 0x00000a02}, |
| 50 | {DLB_WTS_SAME_BG_REG, 0x09000a01}, |
| 51 | {DLB_WTS_CMDS_REG, 0x00020005}, |
| 52 | {DLB_WTS_ATTR_PRIO_REG, 0x00060f10}, |
| 53 | {DLB_QUEUE_MAP_REG, 0x00000543}, |
| 54 | {DLB_SPLIT_REG, 0x00000000}, |
| 55 | {DLB_USER_CMD_REG, 0x00000000}, |
| 56 | {0x0, 0x0} |
| 57 | }; |
| 58 | |
| 59 | static struct dlb_config *sys_env_dlb_config_ptr_get(void) |
| 60 | { |
| 61 | return &ddr3_dlb_config_table[0]; |
| 62 | } |
| 63 | |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 64 | static u8 a38x_bw_per_freq[MV_DDR_FREQ_LAST] = { |
| 65 | 0x3, /* MV_DDR_FREQ_100 */ |
| 66 | 0x4, /* MV_DDR_FREQ_400 */ |
| 67 | 0x4, /* MV_DDR_FREQ_533 */ |
| 68 | 0x5, /* MV_DDR_FREQ_667 */ |
| 69 | 0x5, /* MV_DDR_FREQ_800 */ |
| 70 | 0x5, /* MV_DDR_FREQ_933 */ |
| 71 | 0x5, /* MV_DDR_FREQ_1066 */ |
| 72 | 0x3, /* MV_DDR_FREQ_311 */ |
| 73 | 0x3, /* MV_DDR_FREQ_333 */ |
| 74 | 0x4, /* MV_DDR_FREQ_467 */ |
| 75 | 0x5, /* MV_DDR_FREQ_850 */ |
| 76 | 0x5, /* MV_DDR_FREQ_600 */ |
| 77 | 0x3, /* MV_DDR_FREQ_300 */ |
| 78 | 0x5, /* MV_DDR_FREQ_900 */ |
| 79 | 0x3, /* MV_DDR_FREQ_360 */ |
| 80 | 0x5 /* MV_DDR_FREQ_1000 */ |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 81 | }; |
| 82 | |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 83 | static u8 a38x_rate_per_freq[MV_DDR_FREQ_LAST] = { |
| 84 | 0x1, /* MV_DDR_FREQ_100 */ |
| 85 | 0x2, /* MV_DDR_FREQ_400 */ |
| 86 | 0x2, /* MV_DDR_FREQ_533 */ |
| 87 | 0x2, /* MV_DDR_FREQ_667 */ |
| 88 | 0x2, /* MV_DDR_FREQ_800 */ |
| 89 | 0x3, /* MV_DDR_FREQ_933 */ |
| 90 | 0x3, /* MV_DDR_FREQ_1066 */ |
| 91 | 0x1, /* MV_DDR_FREQ_311 */ |
| 92 | 0x1, /* MV_DDR_FREQ_333 */ |
| 93 | 0x2, /* MV_DDR_FREQ_467 */ |
| 94 | 0x2, /* MV_DDR_FREQ_850 */ |
| 95 | 0x2, /* MV_DDR_FREQ_600 */ |
| 96 | 0x1, /* MV_DDR_FREQ_300 */ |
| 97 | 0x2, /* MV_DDR_FREQ_900 */ |
| 98 | 0x1, /* MV_DDR_FREQ_360 */ |
| 99 | 0x2 /* MV_DDR_FREQ_1000 */ |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 100 | }; |
| 101 | |
| 102 | static u16 a38x_vco_freq_per_sar_ref_clk_25_mhz[] = { |
| 103 | 666, /* 0 */ |
| 104 | 1332, |
| 105 | 800, |
| 106 | 1600, |
| 107 | 1066, |
| 108 | 2132, |
| 109 | 1200, |
| 110 | 2400, |
| 111 | 1332, |
| 112 | 1332, |
| 113 | 1500, |
| 114 | 1500, |
| 115 | 1600, /* 12 */ |
| 116 | 1600, |
| 117 | 1700, |
| 118 | 1700, |
| 119 | 1866, |
| 120 | 1866, |
| 121 | 1800, /* 18 */ |
| 122 | 2000, |
| 123 | 2000, |
| 124 | 4000, |
| 125 | 2132, |
| 126 | 2132, |
| 127 | 2300, |
| 128 | 2300, |
| 129 | 2400, |
| 130 | 2400, |
| 131 | 2500, |
| 132 | 2500, |
| 133 | 800 |
| 134 | }; |
| 135 | |
| 136 | static u16 a38x_vco_freq_per_sar_ref_clk_40_mhz[] = { |
| 137 | 666, /* 0 */ |
| 138 | 1332, |
| 139 | 800, |
| 140 | 800, /* 0x3 */ |
| 141 | 1066, |
| 142 | 1066, /* 0x5 */ |
| 143 | 1200, |
| 144 | 2400, |
| 145 | 1332, |
| 146 | 1332, |
| 147 | 1500, /* 10 */ |
| 148 | 1600, /* 0xB */ |
| 149 | 1600, |
| 150 | 1600, |
| 151 | 1700, |
| 152 | 1560, /* 0xF */ |
| 153 | 1866, |
| 154 | 1866, |
| 155 | 1800, |
| 156 | 2000, |
| 157 | 2000, /* 20 */ |
| 158 | 4000, |
| 159 | 2132, |
| 160 | 2132, |
| 161 | 2300, |
| 162 | 2300, |
| 163 | 2400, |
| 164 | 2400, |
| 165 | 2500, |
| 166 | 2500, |
| 167 | 1800 /* 30 - 0x1E */ |
| 168 | }; |
| 169 | |
| 170 | |
| 171 | static u32 async_mode_at_tf; |
| 172 | |
| 173 | static u32 dq_bit_map_2_phy_pin[] = { |
| 174 | 1, 0, 2, 6, 9, 8, 3, 7, /* 0 */ |
| 175 | 8, 9, 1, 7, 2, 6, 3, 0, /* 1 */ |
| 176 | 3, 9, 7, 8, 1, 0, 2, 6, /* 2 */ |
| 177 | 1, 0, 6, 2, 8, 3, 7, 9, /* 3 */ |
| 178 | 0, 1, 2, 9, 7, 8, 3, 6, /* 4 */ |
| 179 | }; |
| 180 | |
| 181 | void mv_ddr_mem_scrubbing(void) |
| 182 | { |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 183 | ddr3_new_tip_ecc_scrub(); |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | static int ddr3_tip_a38x_set_divider(u8 dev_num, u32 if_id, |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 187 | enum mv_ddr_freq freq); |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 188 | |
| 189 | /* |
| 190 | * Read temperature TJ value |
| 191 | */ |
| 192 | static u32 ddr3_ctrl_get_junc_temp(u8 dev_num) |
| 193 | { |
| 194 | int reg = 0; |
| 195 | |
| 196 | /* Initiates TSEN hardware reset once */ |
| 197 | if ((reg_read(TSEN_CONTROL_MSB_REG) & TSEN_CONTROL_MSB_RST_MASK) == 0) { |
| 198 | reg_bit_set(TSEN_CONTROL_MSB_REG, TSEN_CONTROL_MSB_RST_MASK); |
| 199 | /* set Tsen Tc Trim to correct default value (errata #132698) */ |
| 200 | reg = reg_read(TSEN_CONTROL_LSB_REG); |
| 201 | reg &= ~TSEN_CONTROL_LSB_TC_TRIM_MASK; |
| 202 | reg |= 0x3 << TSEN_CONTROL_LSB_TC_TRIM_OFFSET; |
| 203 | reg_write(TSEN_CONTROL_LSB_REG, reg); |
| 204 | } |
| 205 | mdelay(10); |
| 206 | |
| 207 | /* Check if the readout field is valid */ |
| 208 | if ((reg_read(TSEN_STATUS_REG) & TSEN_STATUS_READOUT_VALID_MASK) == 0) { |
| 209 | printf("%s: TSEN not ready\n", __func__); |
| 210 | return 0; |
| 211 | } |
| 212 | |
| 213 | reg = reg_read(TSEN_STATUS_REG); |
| 214 | reg = (reg & TSEN_STATUS_TEMP_OUT_MASK) >> TSEN_STATUS_TEMP_OUT_OFFSET; |
| 215 | |
| 216 | return ((((10000 * reg) / 21445) * 1000) - 272674) / 1000; |
| 217 | } |
| 218 | |
| 219 | /* |
| 220 | * Name: ddr3_tip_a38x_get_freq_config. |
| 221 | * Desc: |
| 222 | * Args: |
| 223 | * Notes: |
| 224 | * Returns: MV_OK if success, other error code if fail. |
| 225 | */ |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 226 | static int ddr3_tip_a38x_get_freq_config(u8 dev_num, enum mv_ddr_freq freq, |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 227 | struct hws_tip_freq_config_info |
| 228 | *freq_config_info) |
| 229 | { |
| 230 | if (a38x_bw_per_freq[freq] == 0xff) |
| 231 | return MV_NOT_SUPPORTED; |
| 232 | |
| 233 | if (freq_config_info == NULL) |
| 234 | return MV_BAD_PARAM; |
| 235 | |
| 236 | freq_config_info->bw_per_freq = a38x_bw_per_freq[freq]; |
| 237 | freq_config_info->rate_per_freq = a38x_rate_per_freq[freq]; |
| 238 | freq_config_info->is_supported = 1; |
| 239 | |
| 240 | return MV_OK; |
| 241 | } |
| 242 | |
| 243 | static void dunit_read(u32 addr, u32 mask, u32 *data) |
| 244 | { |
| 245 | *data = reg_read(addr) & mask; |
| 246 | } |
| 247 | |
| 248 | static void dunit_write(u32 addr, u32 mask, u32 data) |
| 249 | { |
| 250 | u32 reg_val = data; |
| 251 | |
| 252 | if (mask != MASK_ALL_BITS) { |
| 253 | dunit_read(addr, MASK_ALL_BITS, ®_val); |
| 254 | reg_val &= (~mask); |
| 255 | reg_val |= (data & mask); |
| 256 | } |
| 257 | |
| 258 | reg_write(addr, reg_val); |
| 259 | } |
| 260 | |
| 261 | #define ODPG_ENABLE_REG 0x186d4 |
| 262 | #define ODPG_EN_OFFS 0 |
| 263 | #define ODPG_EN_MASK 0x1 |
| 264 | #define ODPG_EN_ENA 1 |
| 265 | #define ODPG_EN_DONE 0 |
| 266 | #define ODPG_DIS_OFFS 8 |
| 267 | #define ODPG_DIS_MASK 0x1 |
| 268 | #define ODPG_DIS_DIS 1 |
| 269 | void mv_ddr_odpg_enable(void) |
| 270 | { |
| 271 | dunit_write(ODPG_ENABLE_REG, |
| 272 | ODPG_EN_MASK << ODPG_EN_OFFS, |
| 273 | ODPG_EN_ENA << ODPG_EN_OFFS); |
| 274 | } |
| 275 | |
| 276 | void mv_ddr_odpg_disable(void) |
| 277 | { |
| 278 | dunit_write(ODPG_ENABLE_REG, |
| 279 | ODPG_DIS_MASK << ODPG_DIS_OFFS, |
| 280 | ODPG_DIS_DIS << ODPG_DIS_OFFS); |
| 281 | } |
| 282 | |
| 283 | void mv_ddr_odpg_done_clr(void) |
| 284 | { |
| 285 | return; |
| 286 | } |
| 287 | |
| 288 | int mv_ddr_is_odpg_done(u32 count) |
| 289 | { |
| 290 | u32 i, data; |
| 291 | |
| 292 | for (i = 0; i < count; i++) { |
| 293 | dunit_read(ODPG_ENABLE_REG, MASK_ALL_BITS, &data); |
| 294 | if (((data >> ODPG_EN_OFFS) & ODPG_EN_MASK) == |
| 295 | ODPG_EN_DONE) |
| 296 | break; |
| 297 | } |
| 298 | |
| 299 | if (i >= count) { |
| 300 | printf("%s: timeout\n", __func__); |
| 301 | return MV_FAIL; |
| 302 | } |
| 303 | |
| 304 | return MV_OK; |
| 305 | } |
| 306 | |
| 307 | void mv_ddr_training_enable(void) |
| 308 | { |
| 309 | dunit_write(GLOB_CTRL_STATUS_REG, |
| 310 | TRAINING_TRIGGER_MASK << TRAINING_TRIGGER_OFFS, |
| 311 | TRAINING_TRIGGER_ENA << TRAINING_TRIGGER_OFFS); |
| 312 | } |
| 313 | |
| 314 | #define DRAM_INIT_CTRL_STATUS_REG 0x18488 |
| 315 | #define TRAINING_TRIGGER_OFFS 0 |
| 316 | #define TRAINING_TRIGGER_MASK 0x1 |
| 317 | #define TRAINING_TRIGGER_ENA 1 |
| 318 | #define TRAINING_DONE_OFFS 1 |
| 319 | #define TRAINING_DONE_MASK 0x1 |
| 320 | #define TRAINING_DONE_DONE 1 |
| 321 | #define TRAINING_DONE_NOT_DONE 0 |
| 322 | #define TRAINING_RESULT_OFFS 2 |
| 323 | #define TRAINING_RESULT_MASK 0x1 |
| 324 | #define TRAINING_RESULT_PASS 0 |
| 325 | #define TRAINING_RESULT_FAIL 1 |
| 326 | int mv_ddr_is_training_done(u32 count, u32 *result) |
| 327 | { |
| 328 | u32 i, data; |
| 329 | |
| 330 | if (result == NULL) { |
| 331 | printf("%s: NULL result pointer found\n", __func__); |
| 332 | return MV_FAIL; |
| 333 | } |
| 334 | |
| 335 | for (i = 0; i < count; i++) { |
| 336 | dunit_read(DRAM_INIT_CTRL_STATUS_REG, MASK_ALL_BITS, &data); |
| 337 | if (((data >> TRAINING_DONE_OFFS) & TRAINING_DONE_MASK) == |
| 338 | TRAINING_DONE_DONE) |
| 339 | break; |
| 340 | } |
| 341 | |
| 342 | if (i >= count) { |
| 343 | printf("%s: timeout\n", __func__); |
| 344 | return MV_FAIL; |
| 345 | } |
| 346 | |
| 347 | *result = (data >> TRAINING_RESULT_OFFS) & TRAINING_RESULT_MASK; |
| 348 | |
| 349 | return MV_OK; |
| 350 | } |
| 351 | |
| 352 | #define DM_PAD 10 |
| 353 | u32 mv_ddr_dm_pad_get(void) |
| 354 | { |
| 355 | return DM_PAD; |
| 356 | } |
| 357 | |
| 358 | /* |
| 359 | * Name: ddr3_tip_a38x_select_ddr_controller. |
| 360 | * Desc: Enable/Disable access to Marvell's server. |
| 361 | * Args: dev_num - device number |
| 362 | * enable - whether to enable or disable the server |
| 363 | * Notes: |
| 364 | * Returns: MV_OK if success, other error code if fail. |
| 365 | */ |
| 366 | static int ddr3_tip_a38x_select_ddr_controller(u8 dev_num, int enable) |
| 367 | { |
| 368 | u32 reg; |
| 369 | |
| 370 | reg = reg_read(DUAL_DUNIT_CFG_REG); |
| 371 | |
| 372 | if (enable) |
| 373 | reg |= (1 << 6); |
| 374 | else |
| 375 | reg &= ~(1 << 6); |
| 376 | |
| 377 | reg_write(DUAL_DUNIT_CFG_REG, reg); |
| 378 | |
| 379 | return MV_OK; |
| 380 | } |
| 381 | |
| 382 | static u8 ddr3_tip_clock_mode(u32 frequency) |
| 383 | { |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 384 | if ((frequency == MV_DDR_FREQ_LOW_FREQ) || (mv_ddr_freq_get(frequency) <= 400)) |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 385 | return 1; |
| 386 | |
| 387 | return 2; |
| 388 | } |
| 389 | |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 390 | static int mv_ddr_sar_freq_get(int dev_num, enum mv_ddr_freq *freq) |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 391 | { |
| 392 | u32 reg, ref_clk_satr; |
| 393 | |
| 394 | /* Read sample at reset setting */ |
| 395 | reg = (reg_read(REG_DEVICE_SAR1_ADDR) >> |
| 396 | RST2_CPU_DDR_CLOCK_SELECT_IN_OFFSET) & |
| 397 | RST2_CPU_DDR_CLOCK_SELECT_IN_MASK; |
| 398 | |
| 399 | ref_clk_satr = reg_read(DEVICE_SAMPLE_AT_RESET2_REG); |
| 400 | if (((ref_clk_satr >> DEVICE_SAMPLE_AT_RESET2_REG_REFCLK_OFFSET) & 0x1) == |
| 401 | DEVICE_SAMPLE_AT_RESET2_REG_REFCLK_25MHZ) { |
| 402 | switch (reg) { |
| 403 | case 0x1: |
| 404 | DEBUG_TRAINING_ACCESS(DEBUG_LEVEL_ERROR, |
| 405 | ("Warning: Unsupported freq mode for 333Mhz configured(%d)\n", |
| 406 | reg)); |
| 407 | /* fallthrough */ |
| 408 | case 0x0: |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 409 | *freq = MV_DDR_FREQ_333; |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 410 | break; |
| 411 | case 0x3: |
| 412 | DEBUG_TRAINING_ACCESS(DEBUG_LEVEL_ERROR, |
| 413 | ("Warning: Unsupported freq mode for 400Mhz configured(%d)\n", |
| 414 | reg)); |
| 415 | /* fallthrough */ |
| 416 | case 0x2: |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 417 | *freq = MV_DDR_FREQ_400; |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 418 | break; |
| 419 | case 0xd: |
| 420 | DEBUG_TRAINING_ACCESS(DEBUG_LEVEL_ERROR, |
| 421 | ("Warning: Unsupported freq mode for 533Mhz configured(%d)\n", |
| 422 | reg)); |
| 423 | /* fallthrough */ |
| 424 | case 0x4: |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 425 | *freq = MV_DDR_FREQ_533; |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 426 | break; |
| 427 | case 0x6: |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 428 | *freq = MV_DDR_FREQ_600; |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 429 | break; |
| 430 | case 0x11: |
| 431 | case 0x14: |
| 432 | DEBUG_TRAINING_ACCESS(DEBUG_LEVEL_ERROR, |
| 433 | ("Warning: Unsupported freq mode for 667Mhz configured(%d)\n", |
| 434 | reg)); |
| 435 | /* fallthrough */ |
| 436 | case 0x8: |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 437 | *freq = MV_DDR_FREQ_667; |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 438 | break; |
| 439 | case 0x15: |
| 440 | case 0x1b: |
| 441 | DEBUG_TRAINING_ACCESS(DEBUG_LEVEL_ERROR, |
| 442 | ("Warning: Unsupported freq mode for 800Mhz configured(%d)\n", |
| 443 | reg)); |
| 444 | /* fallthrough */ |
| 445 | case 0xc: |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 446 | *freq = MV_DDR_FREQ_800; |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 447 | break; |
| 448 | case 0x10: |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 449 | *freq = MV_DDR_FREQ_933; |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 450 | break; |
| 451 | case 0x12: |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 452 | *freq = MV_DDR_FREQ_900; |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 453 | break; |
| 454 | case 0x13: |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 455 | *freq = MV_DDR_FREQ_933; |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 456 | break; |
| 457 | default: |
| 458 | *freq = 0; |
| 459 | return MV_NOT_SUPPORTED; |
| 460 | } |
| 461 | } else { /* REFCLK 40MHz case */ |
| 462 | switch (reg) { |
| 463 | case 0x3: |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 464 | *freq = MV_DDR_FREQ_400; |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 465 | break; |
| 466 | case 0x5: |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 467 | *freq = MV_DDR_FREQ_533; |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 468 | break; |
| 469 | case 0xb: |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 470 | *freq = MV_DDR_FREQ_800; |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 471 | break; |
| 472 | case 0x1e: |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 473 | *freq = MV_DDR_FREQ_900; |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 474 | break; |
| 475 | default: |
| 476 | *freq = 0; |
| 477 | return MV_NOT_SUPPORTED; |
| 478 | } |
| 479 | } |
| 480 | |
| 481 | return MV_OK; |
| 482 | } |
| 483 | |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 484 | static int ddr3_tip_a38x_get_medium_freq(int dev_num, enum mv_ddr_freq *freq) |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 485 | { |
| 486 | u32 reg, ref_clk_satr; |
| 487 | |
| 488 | /* Read sample at reset setting */ |
| 489 | reg = (reg_read(REG_DEVICE_SAR1_ADDR) >> |
| 490 | RST2_CPU_DDR_CLOCK_SELECT_IN_OFFSET) & |
| 491 | RST2_CPU_DDR_CLOCK_SELECT_IN_MASK; |
| 492 | |
| 493 | ref_clk_satr = reg_read(DEVICE_SAMPLE_AT_RESET2_REG); |
| 494 | if (((ref_clk_satr >> DEVICE_SAMPLE_AT_RESET2_REG_REFCLK_OFFSET) & 0x1) == |
| 495 | DEVICE_SAMPLE_AT_RESET2_REG_REFCLK_25MHZ) { |
| 496 | switch (reg) { |
| 497 | case 0x0: |
| 498 | case 0x1: |
| 499 | /* Medium is same as TF to run PBS in this freq */ |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 500 | *freq = MV_DDR_FREQ_333; |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 501 | break; |
| 502 | case 0x2: |
| 503 | case 0x3: |
| 504 | /* Medium is same as TF to run PBS in this freq */ |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 505 | *freq = MV_DDR_FREQ_400; |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 506 | break; |
| 507 | case 0x4: |
| 508 | case 0xd: |
| 509 | /* Medium is same as TF to run PBS in this freq */ |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 510 | *freq = MV_DDR_FREQ_533; |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 511 | break; |
| 512 | case 0x8: |
| 513 | case 0x10: |
| 514 | case 0x11: |
| 515 | case 0x14: |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 516 | *freq = MV_DDR_FREQ_333; |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 517 | break; |
| 518 | case 0xc: |
| 519 | case 0x15: |
| 520 | case 0x1b: |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 521 | *freq = MV_DDR_FREQ_400; |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 522 | break; |
| 523 | case 0x6: |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 524 | *freq = MV_DDR_FREQ_300; |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 525 | break; |
| 526 | case 0x12: |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 527 | *freq = MV_DDR_FREQ_360; |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 528 | break; |
| 529 | case 0x13: |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 530 | *freq = MV_DDR_FREQ_400; |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 531 | break; |
| 532 | default: |
| 533 | *freq = 0; |
| 534 | return MV_NOT_SUPPORTED; |
| 535 | } |
| 536 | } else { /* REFCLK 40MHz case */ |
| 537 | switch (reg) { |
| 538 | case 0x3: |
| 539 | /* Medium is same as TF to run PBS in this freq */ |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 540 | *freq = MV_DDR_FREQ_400; |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 541 | break; |
| 542 | case 0x5: |
| 543 | /* Medium is same as TF to run PBS in this freq */ |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 544 | *freq = MV_DDR_FREQ_533; |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 545 | break; |
| 546 | case 0xb: |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 547 | *freq = MV_DDR_FREQ_400; |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 548 | break; |
| 549 | case 0x1e: |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 550 | *freq = MV_DDR_FREQ_360; |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 551 | break; |
| 552 | default: |
| 553 | *freq = 0; |
| 554 | return MV_NOT_SUPPORTED; |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | return MV_OK; |
| 559 | } |
| 560 | |
| 561 | static int ddr3_tip_a38x_get_device_info(u8 dev_num, struct ddr3_device_info *info_ptr) |
| 562 | { |
| 563 | #if defined(CONFIG_ARMADA_39X) |
| 564 | info_ptr->device_id = 0x6900; |
| 565 | #else |
| 566 | info_ptr->device_id = 0x6800; |
| 567 | #endif |
| 568 | info_ptr->ck_delay = ck_delay; |
| 569 | |
| 570 | return MV_OK; |
| 571 | } |
| 572 | |
| 573 | /* check indirect access to phy register file completed */ |
| 574 | static int is_prfa_done(void) |
| 575 | { |
| 576 | u32 reg_val; |
| 577 | u32 iter = 0; |
| 578 | |
| 579 | do { |
| 580 | if (iter++ > MAX_POLLING_ITERATIONS) { |
| 581 | printf("error: %s: polling timeout\n", __func__); |
| 582 | return MV_FAIL; |
| 583 | } |
| 584 | dunit_read(PHY_REG_FILE_ACCESS_REG, MASK_ALL_BITS, ®_val); |
| 585 | reg_val >>= PRFA_REQ_OFFS; |
| 586 | reg_val &= PRFA_REQ_MASK; |
| 587 | } while (reg_val == PRFA_REQ_ENA); /* request pending */ |
| 588 | |
| 589 | return MV_OK; |
| 590 | } |
| 591 | |
| 592 | /* write to phy register thru indirect access */ |
| 593 | static int prfa_write(enum hws_access_type phy_access, u32 phy, |
| 594 | enum hws_ddr_phy phy_type, u32 addr, |
| 595 | u32 data, enum hws_operation op_type) |
| 596 | { |
| 597 | u32 reg_val = ((data & PRFA_DATA_MASK) << PRFA_DATA_OFFS) | |
| 598 | ((addr & PRFA_REG_NUM_MASK) << PRFA_REG_NUM_OFFS) | |
| 599 | ((phy & PRFA_PUP_NUM_MASK) << PRFA_PUP_NUM_OFFS) | |
| 600 | ((phy_type & PRFA_PUP_CTRL_DATA_MASK) << PRFA_PUP_CTRL_DATA_OFFS) | |
| 601 | ((phy_access & PRFA_PUP_BCAST_WR_ENA_MASK) << PRFA_PUP_BCAST_WR_ENA_OFFS) | |
| 602 | (((addr >> 6) & PRFA_REG_NUM_HI_MASK) << PRFA_REG_NUM_HI_OFFS) | |
| 603 | ((op_type & PRFA_TYPE_MASK) << PRFA_TYPE_OFFS); |
| 604 | dunit_write(PHY_REG_FILE_ACCESS_REG, MASK_ALL_BITS, reg_val); |
| 605 | reg_val |= (PRFA_REQ_ENA << PRFA_REQ_OFFS); |
| 606 | dunit_write(PHY_REG_FILE_ACCESS_REG, MASK_ALL_BITS, reg_val); |
| 607 | |
| 608 | /* polling for prfa request completion */ |
| 609 | if (is_prfa_done() != MV_OK) |
| 610 | return MV_FAIL; |
| 611 | |
| 612 | return MV_OK; |
| 613 | } |
| 614 | |
| 615 | /* read from phy register thru indirect access */ |
| 616 | static int prfa_read(enum hws_access_type phy_access, u32 phy, |
| 617 | enum hws_ddr_phy phy_type, u32 addr, u32 *data) |
| 618 | { |
| 619 | struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get(); |
| 620 | u32 max_phy = ddr3_tip_dev_attr_get(0, MV_ATTR_OCTET_PER_INTERFACE); |
| 621 | u32 i, reg_val; |
| 622 | |
| 623 | if (phy_access == ACCESS_TYPE_MULTICAST) { |
| 624 | for (i = 0; i < max_phy; i++) { |
| 625 | VALIDATE_BUS_ACTIVE(tm->bus_act_mask, i); |
| 626 | if (prfa_write(ACCESS_TYPE_UNICAST, i, phy_type, addr, 0, OPERATION_READ) != MV_OK) |
| 627 | return MV_FAIL; |
| 628 | dunit_read(PHY_REG_FILE_ACCESS_REG, MASK_ALL_BITS, ®_val); |
| 629 | data[i] = (reg_val >> PRFA_DATA_OFFS) & PRFA_DATA_MASK; |
| 630 | } |
| 631 | } else { |
| 632 | if (prfa_write(phy_access, phy, phy_type, addr, 0, OPERATION_READ) != MV_OK) |
| 633 | return MV_FAIL; |
| 634 | dunit_read(PHY_REG_FILE_ACCESS_REG, MASK_ALL_BITS, ®_val); |
| 635 | *data = (reg_val >> PRFA_DATA_OFFS) & PRFA_DATA_MASK; |
| 636 | } |
| 637 | |
| 638 | return MV_OK; |
| 639 | } |
| 640 | |
| 641 | static int mv_ddr_sw_db_init(u32 dev_num, u32 board_id) |
| 642 | { |
| 643 | struct hws_tip_config_func_db config_func; |
| 644 | |
| 645 | /* new read leveling version */ |
| 646 | config_func.mv_ddr_dunit_read = dunit_read; |
| 647 | config_func.mv_ddr_dunit_write = dunit_write; |
| 648 | config_func.tip_dunit_mux_select_func = |
| 649 | ddr3_tip_a38x_select_ddr_controller; |
| 650 | config_func.tip_get_freq_config_info_func = |
| 651 | ddr3_tip_a38x_get_freq_config; |
| 652 | config_func.tip_set_freq_divider_func = ddr3_tip_a38x_set_divider; |
| 653 | config_func.tip_get_device_info_func = ddr3_tip_a38x_get_device_info; |
| 654 | config_func.tip_get_temperature = ddr3_ctrl_get_junc_temp; |
| 655 | config_func.tip_get_clock_ratio = ddr3_tip_clock_mode; |
| 656 | config_func.tip_external_read = ddr3_tip_ext_read; |
| 657 | config_func.tip_external_write = ddr3_tip_ext_write; |
| 658 | config_func.mv_ddr_phy_read = prfa_read; |
| 659 | config_func.mv_ddr_phy_write = prfa_write; |
| 660 | |
| 661 | ddr3_tip_init_config_func(dev_num, &config_func); |
| 662 | |
| 663 | ddr3_tip_register_dq_table(dev_num, dq_bit_map_2_phy_pin); |
| 664 | |
| 665 | /* set device attributes*/ |
| 666 | ddr3_tip_dev_attr_init(dev_num); |
| 667 | ddr3_tip_dev_attr_set(dev_num, MV_ATTR_TIP_REV, MV_TIP_REV_4); |
| 668 | ddr3_tip_dev_attr_set(dev_num, MV_ATTR_PHY_EDGE, MV_DDR_PHY_EDGE_POSITIVE); |
| 669 | ddr3_tip_dev_attr_set(dev_num, MV_ATTR_OCTET_PER_INTERFACE, DDR_INTERFACE_OCTETS_NUM); |
| 670 | #ifdef CONFIG_ARMADA_39X |
| 671 | ddr3_tip_dev_attr_set(dev_num, MV_ATTR_INTERLEAVE_WA, 1); |
| 672 | #else |
| 673 | ddr3_tip_dev_attr_set(dev_num, MV_ATTR_INTERLEAVE_WA, 0); |
| 674 | #endif |
| 675 | |
| 676 | ca_delay = 0; |
| 677 | delay_enable = 1; |
| 678 | dfs_low_freq = DFS_LOW_FREQ_VALUE; |
| 679 | calibration_update_control = 1; |
| 680 | |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 681 | ddr3_tip_a38x_get_medium_freq(dev_num, &medium_freq); |
| 682 | |
| 683 | return MV_OK; |
| 684 | } |
| 685 | |
| 686 | static int mv_ddr_training_mask_set(void) |
| 687 | { |
| 688 | struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get(); |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 689 | enum mv_ddr_freq ddr_freq = tm->interface_params[0].memory_freq; |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 690 | |
| 691 | mask_tune_func = (SET_LOW_FREQ_MASK_BIT | |
| 692 | LOAD_PATTERN_MASK_BIT | |
| 693 | SET_MEDIUM_FREQ_MASK_BIT | WRITE_LEVELING_MASK_BIT | |
| 694 | WRITE_LEVELING_SUPP_MASK_BIT | |
| 695 | READ_LEVELING_MASK_BIT | |
| 696 | PBS_RX_MASK_BIT | |
| 697 | PBS_TX_MASK_BIT | |
| 698 | SET_TARGET_FREQ_MASK_BIT | |
| 699 | WRITE_LEVELING_TF_MASK_BIT | |
| 700 | WRITE_LEVELING_SUPP_TF_MASK_BIT | |
| 701 | READ_LEVELING_TF_MASK_BIT | |
| 702 | CENTRALIZATION_RX_MASK_BIT | |
| 703 | CENTRALIZATION_TX_MASK_BIT); |
| 704 | rl_mid_freq_wa = 1; |
| 705 | |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 706 | if ((ddr_freq == MV_DDR_FREQ_333) || (ddr_freq == MV_DDR_FREQ_400)) { |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 707 | mask_tune_func = (WRITE_LEVELING_MASK_BIT | |
| 708 | LOAD_PATTERN_2_MASK_BIT | |
| 709 | WRITE_LEVELING_SUPP_MASK_BIT | |
| 710 | READ_LEVELING_MASK_BIT | |
| 711 | PBS_RX_MASK_BIT | |
| 712 | PBS_TX_MASK_BIT | |
| 713 | CENTRALIZATION_RX_MASK_BIT | |
| 714 | CENTRALIZATION_TX_MASK_BIT); |
| 715 | rl_mid_freq_wa = 0; /* WA not needed if 333/400 is TF */ |
| 716 | } |
| 717 | |
| 718 | /* Supplementary not supported for ECC modes */ |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 719 | if (mv_ddr_is_ecc_ena()) { |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 720 | mask_tune_func &= ~WRITE_LEVELING_SUPP_TF_MASK_BIT; |
| 721 | mask_tune_func &= ~WRITE_LEVELING_SUPP_MASK_BIT; |
| 722 | mask_tune_func &= ~PBS_TX_MASK_BIT; |
| 723 | mask_tune_func &= ~PBS_RX_MASK_BIT; |
| 724 | } |
| 725 | |
| 726 | return MV_OK; |
| 727 | } |
| 728 | |
| 729 | /* function: mv_ddr_set_calib_controller |
| 730 | * this function sets the controller which will control |
| 731 | * the calibration cycle in the end of the training. |
| 732 | * 1 - internal controller |
| 733 | * 2 - external controller |
| 734 | */ |
| 735 | void mv_ddr_set_calib_controller(void) |
| 736 | { |
| 737 | calibration_update_control = CAL_UPDATE_CTRL_INT; |
| 738 | } |
| 739 | |
| 740 | static int ddr3_tip_a38x_set_divider(u8 dev_num, u32 if_id, |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 741 | enum mv_ddr_freq frequency) |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 742 | { |
| 743 | u32 divider = 0; |
| 744 | u32 sar_val, ref_clk_satr; |
| 745 | u32 async_val; |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 746 | u32 freq = mv_ddr_freq_get(frequency); |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 747 | |
| 748 | if (if_id != 0) { |
| 749 | DEBUG_TRAINING_ACCESS(DEBUG_LEVEL_ERROR, |
| 750 | ("A38x does not support interface 0x%x\n", |
| 751 | if_id)); |
| 752 | return MV_BAD_PARAM; |
| 753 | } |
| 754 | |
| 755 | /* get VCO freq index */ |
| 756 | sar_val = (reg_read(REG_DEVICE_SAR1_ADDR) >> |
| 757 | RST2_CPU_DDR_CLOCK_SELECT_IN_OFFSET) & |
| 758 | RST2_CPU_DDR_CLOCK_SELECT_IN_MASK; |
| 759 | |
| 760 | ref_clk_satr = reg_read(DEVICE_SAMPLE_AT_RESET2_REG); |
| 761 | if (((ref_clk_satr >> DEVICE_SAMPLE_AT_RESET2_REG_REFCLK_OFFSET) & 0x1) == |
| 762 | DEVICE_SAMPLE_AT_RESET2_REG_REFCLK_25MHZ) |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 763 | divider = a38x_vco_freq_per_sar_ref_clk_25_mhz[sar_val] / freq; |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 764 | else |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 765 | divider = a38x_vco_freq_per_sar_ref_clk_40_mhz[sar_val] / freq; |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 766 | |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 767 | if ((async_mode_at_tf == 1) && (freq > 400)) { |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 768 | /* Set async mode */ |
| 769 | dunit_write(0x20220, 0x1000, 0x1000); |
| 770 | dunit_write(0xe42f4, 0x200, 0x200); |
| 771 | |
| 772 | /* Wait for async mode setup */ |
| 773 | mdelay(5); |
| 774 | |
| 775 | /* Set KNL values */ |
| 776 | switch (frequency) { |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 777 | case MV_DDR_FREQ_467: |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 778 | async_val = 0x806f012; |
| 779 | break; |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 780 | case MV_DDR_FREQ_533: |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 781 | async_val = 0x807f012; |
| 782 | break; |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 783 | case MV_DDR_FREQ_600: |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 784 | async_val = 0x805f00a; |
| 785 | break; |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 786 | case MV_DDR_FREQ_667: |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 787 | async_val = 0x809f012; |
| 788 | break; |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 789 | case MV_DDR_FREQ_800: |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 790 | async_val = 0x807f00a; |
| 791 | break; |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 792 | case MV_DDR_FREQ_850: |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 793 | async_val = 0x80cb012; |
| 794 | break; |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 795 | case MV_DDR_FREQ_900: |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 796 | async_val = 0x80d7012; |
| 797 | break; |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 798 | case MV_DDR_FREQ_933: |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 799 | async_val = 0x80df012; |
| 800 | break; |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 801 | case MV_DDR_FREQ_1000: |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 802 | async_val = 0x80ef012; |
| 803 | break; |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 804 | case MV_DDR_FREQ_1066: |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 805 | async_val = 0x80ff012; |
| 806 | break; |
| 807 | default: |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 808 | /* set MV_DDR_FREQ_667 as default */ |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 809 | async_val = 0x809f012; |
| 810 | } |
| 811 | dunit_write(0xe42f0, 0xffffffff, async_val); |
| 812 | } else { |
| 813 | /* Set sync mode */ |
| 814 | dunit_write(0x20220, 0x1000, 0x0); |
| 815 | dunit_write(0xe42f4, 0x200, 0x0); |
| 816 | |
| 817 | /* cpupll_clkdiv_reset_mask */ |
| 818 | dunit_write(0xe4264, 0xff, 0x1f); |
| 819 | |
| 820 | /* cpupll_clkdiv_reload_smooth */ |
| 821 | dunit_write(0xe4260, (0xff << 8), (0x2 << 8)); |
| 822 | |
| 823 | /* cpupll_clkdiv_relax_en */ |
| 824 | dunit_write(0xe4260, (0xff << 24), (0x2 << 24)); |
| 825 | |
| 826 | /* write the divider */ |
| 827 | dunit_write(0xe4268, (0x3f << 8), (divider << 8)); |
| 828 | |
| 829 | /* set cpupll_clkdiv_reload_ratio */ |
| 830 | dunit_write(0xe4264, (1 << 8), (1 << 8)); |
| 831 | |
| 832 | /* undet cpupll_clkdiv_reload_ratio */ |
| 833 | dunit_write(0xe4264, (1 << 8), 0x0); |
| 834 | |
| 835 | /* clear cpupll_clkdiv_reload_force */ |
| 836 | dunit_write(0xe4260, (0xff << 8), 0x0); |
| 837 | |
| 838 | /* clear cpupll_clkdiv_relax_en */ |
| 839 | dunit_write(0xe4260, (0xff << 24), 0x0); |
| 840 | |
| 841 | /* clear cpupll_clkdiv_reset_mask */ |
| 842 | dunit_write(0xe4264, 0xff, 0x0); |
| 843 | } |
| 844 | |
| 845 | /* Dunit training clock + 1:1/2:1 mode */ |
| 846 | dunit_write(0x18488, (1 << 16), ((ddr3_tip_clock_mode(frequency) & 0x1) << 16)); |
| 847 | dunit_write(0x1524, (1 << 15), ((ddr3_tip_clock_mode(frequency) - 1) << 15)); |
| 848 | |
| 849 | return MV_OK; |
| 850 | } |
| 851 | |
| 852 | /* |
| 853 | * external read from memory |
| 854 | */ |
| 855 | int ddr3_tip_ext_read(u32 dev_num, u32 if_id, u32 reg_addr, |
| 856 | u32 num_of_bursts, u32 *data) |
| 857 | { |
| 858 | u32 burst_num; |
| 859 | |
| 860 | for (burst_num = 0; burst_num < num_of_bursts * 8; burst_num++) |
| 861 | data[burst_num] = readl(reg_addr + 4 * burst_num); |
| 862 | |
| 863 | return MV_OK; |
| 864 | } |
| 865 | |
| 866 | /* |
| 867 | * external write to memory |
| 868 | */ |
| 869 | int ddr3_tip_ext_write(u32 dev_num, u32 if_id, u32 reg_addr, |
| 870 | u32 num_of_bursts, u32 *data) { |
| 871 | u32 burst_num; |
| 872 | |
| 873 | for (burst_num = 0; burst_num < num_of_bursts * 8; burst_num++) |
| 874 | writel(data[burst_num], reg_addr + 4 * burst_num); |
| 875 | |
| 876 | return MV_OK; |
| 877 | } |
| 878 | |
| 879 | int mv_ddr_early_init(void) |
| 880 | { |
| 881 | struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get(); |
| 882 | |
| 883 | /* FIXME: change this configuration per ddr type |
| 884 | * configure a380 and a390 to work with receiver odt timing |
| 885 | * the odt_config is defined: |
| 886 | * '1' in ddr4 |
| 887 | * '0' in ddr3 |
| 888 | * here the parameter is run over in ddr4 and ddr3 to '1' (in ddr4 the default is '1') |
| 889 | * to configure the odt to work with timing restrictions |
| 890 | */ |
| 891 | |
| 892 | mv_ddr_sw_db_init(0, 0); |
| 893 | |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 894 | if (tm->interface_params[0].memory_freq != MV_DDR_FREQ_SAR) |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 895 | async_mode_at_tf = 1; |
| 896 | |
| 897 | return MV_OK; |
| 898 | } |
| 899 | |
| 900 | int mv_ddr_early_init2(void) |
| 901 | { |
| 902 | mv_ddr_training_mask_set(); |
| 903 | |
| 904 | return MV_OK; |
| 905 | } |
| 906 | |
| 907 | int mv_ddr_pre_training_fixup(void) |
| 908 | { |
| 909 | return 0; |
| 910 | } |
| 911 | |
| 912 | int mv_ddr_post_training_fixup(void) |
| 913 | { |
| 914 | return 0; |
| 915 | } |
| 916 | |
| 917 | int ddr3_post_run_alg(void) |
| 918 | { |
| 919 | return MV_OK; |
| 920 | } |
| 921 | |
| 922 | int ddr3_silicon_post_init(void) |
| 923 | { |
| 924 | struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get(); |
| 925 | |
| 926 | /* Set half bus width */ |
| 927 | if (DDR3_IS_16BIT_DRAM_MODE(tm->bus_act_mask)) { |
| 928 | CHECK_STATUS(ddr3_tip_if_write |
| 929 | (0, ACCESS_TYPE_UNICAST, PARAM_NOT_CARE, |
| 930 | SDRAM_CFG_REG, 0x0, 0x8000)); |
| 931 | } |
| 932 | |
| 933 | return MV_OK; |
| 934 | } |
| 935 | |
| 936 | u32 mv_ddr_init_freq_get(void) |
| 937 | { |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 938 | enum mv_ddr_freq freq; |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 939 | |
| 940 | mv_ddr_sar_freq_get(0, &freq); |
| 941 | |
| 942 | return freq; |
| 943 | } |
| 944 | |
| 945 | static u32 ddr3_get_bus_width(void) |
| 946 | { |
| 947 | u32 bus_width; |
| 948 | |
| 949 | bus_width = (reg_read(SDRAM_CFG_REG) & 0x8000) >> |
| 950 | BUS_IN_USE_OFFS; |
| 951 | |
| 952 | return (bus_width == 0) ? 16 : 32; |
| 953 | } |
| 954 | |
| 955 | static u32 ddr3_get_device_width(u32 cs) |
| 956 | { |
| 957 | u32 device_width; |
| 958 | |
| 959 | device_width = (reg_read(SDRAM_ADDR_CTRL_REG) & |
| 960 | (CS_STRUCT_MASK << CS_STRUCT_OFFS(cs))) >> |
| 961 | CS_STRUCT_OFFS(cs); |
| 962 | |
| 963 | return (device_width == 0) ? 8 : 16; |
| 964 | } |
| 965 | |
| 966 | static u32 ddr3_get_device_size(u32 cs) |
| 967 | { |
| 968 | u32 device_size_low, device_size_high, device_size; |
| 969 | u32 data, cs_low_offset, cs_high_offset; |
| 970 | |
| 971 | cs_low_offset = CS_SIZE_OFFS(cs); |
| 972 | cs_high_offset = CS_SIZE_HIGH_OFFS(cs); |
| 973 | |
| 974 | data = reg_read(SDRAM_ADDR_CTRL_REG); |
| 975 | device_size_low = (data >> cs_low_offset) & 0x3; |
| 976 | device_size_high = (data >> cs_high_offset) & 0x1; |
| 977 | |
| 978 | device_size = device_size_low | (device_size_high << 2); |
| 979 | |
| 980 | switch (device_size) { |
| 981 | case 0: |
| 982 | return 2048; |
| 983 | case 2: |
| 984 | return 512; |
| 985 | case 3: |
| 986 | return 1024; |
| 987 | case 4: |
| 988 | return 4096; |
| 989 | case 5: |
| 990 | return 8192; |
| 991 | case 1: |
| 992 | default: |
| 993 | DEBUG_INIT_C("Error: Wrong device size of Cs: ", cs, 1); |
| 994 | /* zeroes mem size in ddr3_calc_mem_cs_size */ |
| 995 | return 0; |
| 996 | } |
| 997 | } |
| 998 | |
Chris Packham | 915f8ee | 2018-05-10 13:28:31 +1200 | [diff] [blame] | 999 | int ddr3_calc_mem_cs_size(u32 cs, uint64_t *cs_size) |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 1000 | { |
| 1001 | u32 cs_mem_size; |
| 1002 | |
| 1003 | /* Calculate in MiB */ |
| 1004 | cs_mem_size = ((ddr3_get_bus_width() / ddr3_get_device_width(cs)) * |
| 1005 | ddr3_get_device_size(cs)) / 8; |
| 1006 | |
| 1007 | /* |
| 1008 | * Multiple controller bus width, 2x for 64 bit |
| 1009 | * (SoC controller may be 32 or 64 bit, |
| 1010 | * so bit 15 in 0x1400, that means if whole bus used or only half, |
| 1011 | * have a differnt meaning |
| 1012 | */ |
| 1013 | cs_mem_size *= DDR_CONTROLLER_BUS_WIDTH_MULTIPLIER; |
| 1014 | |
| 1015 | if ((cs_mem_size < 128) || (cs_mem_size > 4096)) { |
| 1016 | DEBUG_INIT_C("Error: Wrong Memory size of Cs: ", cs, 1); |
| 1017 | return MV_BAD_VALUE; |
| 1018 | } |
| 1019 | |
Moti Buskila | 2b368e1 | 2021-02-19 17:11:22 +0100 | [diff] [blame^] | 1020 | *cs_size = cs_mem_size; |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 1021 | |
| 1022 | return MV_OK; |
| 1023 | } |
| 1024 | |
| 1025 | static int ddr3_fast_path_dynamic_cs_size_config(u32 cs_ena) |
| 1026 | { |
| 1027 | u32 reg, cs; |
| 1028 | uint64_t mem_total_size = 0; |
Moti Buskila | 2b368e1 | 2021-02-19 17:11:22 +0100 | [diff] [blame^] | 1029 | uint64_t cs_mem_size_mb = 0; |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 1030 | uint64_t cs_mem_size = 0; |
| 1031 | uint64_t mem_total_size_c, cs_mem_size_c; |
| 1032 | |
Moti Buskila | 2b368e1 | 2021-02-19 17:11:22 +0100 | [diff] [blame^] | 1033 | |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 1034 | #ifdef DEVICE_MAX_DRAM_ADDRESS_SIZE |
| 1035 | u32 physical_mem_size; |
| 1036 | u32 max_mem_size = DEVICE_MAX_DRAM_ADDRESS_SIZE; |
| 1037 | struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get(); |
| 1038 | #endif |
| 1039 | |
| 1040 | /* Open fast path windows */ |
| 1041 | for (cs = 0; cs < MAX_CS_NUM; cs++) { |
| 1042 | if (cs_ena & (1 << cs)) { |
| 1043 | /* get CS size */ |
Moti Buskila | 2b368e1 | 2021-02-19 17:11:22 +0100 | [diff] [blame^] | 1044 | if (ddr3_calc_mem_cs_size(cs, &cs_mem_size_mb) != MV_OK) |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 1045 | return MV_FAIL; |
Moti Buskila | 2b368e1 | 2021-02-19 17:11:22 +0100 | [diff] [blame^] | 1046 | cs_mem_size = cs_mem_size_mb * _1M; |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 1047 | |
| 1048 | #ifdef DEVICE_MAX_DRAM_ADDRESS_SIZE |
| 1049 | /* |
| 1050 | * if number of address pins doesn't allow to use max |
| 1051 | * mem size that is defined in topology |
| 1052 | * mem size is defined by DEVICE_MAX_DRAM_ADDRESS_SIZE |
| 1053 | */ |
| 1054 | physical_mem_size = mem_size |
| 1055 | [tm->interface_params[0].memory_size]; |
| 1056 | |
| 1057 | if (ddr3_get_device_width(cs) == 16) { |
| 1058 | /* |
| 1059 | * 16bit mem device can be twice more - no need |
| 1060 | * in less significant pin |
| 1061 | */ |
| 1062 | max_mem_size = DEVICE_MAX_DRAM_ADDRESS_SIZE * 2; |
| 1063 | } |
| 1064 | |
| 1065 | if (physical_mem_size > max_mem_size) { |
| 1066 | cs_mem_size = max_mem_size * |
| 1067 | (ddr3_get_bus_width() / |
| 1068 | ddr3_get_device_width(cs)); |
| 1069 | printf("Updated Physical Mem size is from 0x%x to %x\n", |
| 1070 | physical_mem_size, |
| 1071 | DEVICE_MAX_DRAM_ADDRESS_SIZE); |
| 1072 | } |
| 1073 | #endif |
| 1074 | |
| 1075 | /* set fast path window control for the cs */ |
| 1076 | reg = 0xffffe1; |
| 1077 | reg |= (cs << 2); |
| 1078 | reg |= (cs_mem_size - 1) & 0xffff0000; |
| 1079 | /*Open fast path Window */ |
| 1080 | reg_write(REG_FASTPATH_WIN_CTRL_ADDR(cs), reg); |
| 1081 | |
| 1082 | /* Set fast path window base address for the cs */ |
| 1083 | reg = ((cs_mem_size) * cs) & 0xffff0000; |
| 1084 | /* Set base address */ |
| 1085 | reg_write(REG_FASTPATH_WIN_BASE_ADDR(cs), reg); |
| 1086 | |
| 1087 | /* |
| 1088 | * Since memory size may be bigger than 4G the summ may |
| 1089 | * be more than 32 bit word, |
| 1090 | * so to estimate the result divide mem_total_size and |
| 1091 | * cs_mem_size by 0x10000 (it is equal to >> 16) |
| 1092 | */ |
| 1093 | mem_total_size_c = (mem_total_size >> 16) & 0xffffffffffff; |
| 1094 | cs_mem_size_c = (cs_mem_size >> 16) & 0xffffffffffff; |
Moti Buskila | 2b368e1 | 2021-02-19 17:11:22 +0100 | [diff] [blame^] | 1095 | |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 1096 | /* if the sum less than 2 G - calculate the value */ |
| 1097 | if (mem_total_size_c + cs_mem_size_c < 0x10000) |
| 1098 | mem_total_size += cs_mem_size; |
| 1099 | else /* put max possible size */ |
| 1100 | mem_total_size = L2_FILTER_FOR_MAX_MEMORY_SIZE; |
| 1101 | } |
| 1102 | } |
| 1103 | |
| 1104 | /* Set L2 filtering to Max Memory size */ |
| 1105 | reg_write(ADDRESS_FILTERING_END_REGISTER, mem_total_size); |
| 1106 | |
| 1107 | return MV_OK; |
| 1108 | } |
| 1109 | |
| 1110 | static int ddr3_restore_and_set_final_windows(u32 *win, const char *ddr_type) |
| 1111 | { |
| 1112 | u32 win_ctrl_reg, num_of_win_regs; |
| 1113 | u32 cs_ena = mv_ddr_sys_env_get_cs_ena_from_reg(); |
| 1114 | u32 ui; |
| 1115 | |
| 1116 | win_ctrl_reg = REG_XBAR_WIN_4_CTRL_ADDR; |
| 1117 | num_of_win_regs = 16; |
| 1118 | |
| 1119 | /* Return XBAR windows 4-7 or 16-19 init configuration */ |
| 1120 | for (ui = 0; ui < num_of_win_regs; ui++) |
| 1121 | reg_write((win_ctrl_reg + 0x4 * ui), win[ui]); |
| 1122 | |
| 1123 | printf("%s Training Sequence - Switching XBAR Window to FastPath Window\n", |
| 1124 | ddr_type); |
| 1125 | |
| 1126 | #if defined DYNAMIC_CS_SIZE_CONFIG |
| 1127 | if (ddr3_fast_path_dynamic_cs_size_config(cs_ena) != MV_OK) |
| 1128 | printf("ddr3_fast_path_dynamic_cs_size_config FAILED\n"); |
| 1129 | #else |
| 1130 | u32 reg, cs; |
| 1131 | reg = 0x1fffffe1; |
| 1132 | for (cs = 0; cs < MAX_CS_NUM; cs++) { |
| 1133 | if (cs_ena & (1 << cs)) { |
| 1134 | reg |= (cs << 2); |
| 1135 | break; |
| 1136 | } |
| 1137 | } |
| 1138 | /* Open fast path Window to - 0.5G */ |
| 1139 | reg_write(REG_FASTPATH_WIN_CTRL_ADDR(0), reg); |
| 1140 | #endif |
| 1141 | |
| 1142 | return MV_OK; |
| 1143 | } |
| 1144 | |
| 1145 | static int ddr3_save_and_set_training_windows(u32 *win) |
| 1146 | { |
| 1147 | u32 cs_ena; |
| 1148 | u32 reg, tmp_count, cs, ui; |
| 1149 | u32 win_ctrl_reg, win_base_reg, win_remap_reg; |
| 1150 | u32 num_of_win_regs, win_jump_index; |
| 1151 | win_ctrl_reg = REG_XBAR_WIN_4_CTRL_ADDR; |
| 1152 | win_base_reg = REG_XBAR_WIN_4_BASE_ADDR; |
| 1153 | win_remap_reg = REG_XBAR_WIN_4_REMAP_ADDR; |
| 1154 | win_jump_index = 0x10; |
| 1155 | num_of_win_regs = 16; |
| 1156 | struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get(); |
| 1157 | |
| 1158 | #ifdef DISABLE_L2_FILTERING_DURING_DDR_TRAINING |
| 1159 | /* |
| 1160 | * Disable L2 filtering during DDR training |
| 1161 | * (when Cross Bar window is open) |
| 1162 | */ |
| 1163 | reg_write(ADDRESS_FILTERING_END_REGISTER, 0); |
| 1164 | #endif |
| 1165 | |
| 1166 | cs_ena = tm->interface_params[0].as_bus_params[0].cs_bitmask; |
| 1167 | |
| 1168 | /* Close XBAR Window 19 - Not needed */ |
| 1169 | /* {0x000200e8} - Open Mbus Window - 2G */ |
| 1170 | reg_write(REG_XBAR_WIN_19_CTRL_ADDR, 0); |
| 1171 | |
| 1172 | /* Save XBAR Windows 4-19 init configurations */ |
| 1173 | for (ui = 0; ui < num_of_win_regs; ui++) |
| 1174 | win[ui] = reg_read(win_ctrl_reg + 0x4 * ui); |
| 1175 | |
| 1176 | /* Open XBAR Windows 4-7 or 16-19 for other CS */ |
| 1177 | reg = 0; |
| 1178 | tmp_count = 0; |
| 1179 | for (cs = 0; cs < MAX_CS_NUM; cs++) { |
| 1180 | if (cs_ena & (1 << cs)) { |
| 1181 | switch (cs) { |
| 1182 | case 0: |
| 1183 | reg = 0x0e00; |
| 1184 | break; |
| 1185 | case 1: |
| 1186 | reg = 0x0d00; |
| 1187 | break; |
| 1188 | case 2: |
| 1189 | reg = 0x0b00; |
| 1190 | break; |
| 1191 | case 3: |
| 1192 | reg = 0x0700; |
| 1193 | break; |
| 1194 | } |
| 1195 | reg |= (1 << 0); |
| 1196 | reg |= (SDRAM_CS_SIZE & 0xffff0000); |
| 1197 | |
| 1198 | reg_write(win_ctrl_reg + win_jump_index * tmp_count, |
| 1199 | reg); |
| 1200 | reg = (((SDRAM_CS_SIZE + 1) * (tmp_count)) & |
| 1201 | 0xffff0000); |
| 1202 | reg_write(win_base_reg + win_jump_index * tmp_count, |
| 1203 | reg); |
| 1204 | |
| 1205 | if (win_remap_reg <= REG_XBAR_WIN_7_REMAP_ADDR) |
| 1206 | reg_write(win_remap_reg + |
| 1207 | win_jump_index * tmp_count, 0); |
| 1208 | |
| 1209 | tmp_count++; |
| 1210 | } |
| 1211 | } |
| 1212 | |
| 1213 | return MV_OK; |
| 1214 | } |
| 1215 | |
| 1216 | static u32 win[16]; |
| 1217 | |
| 1218 | int mv_ddr_pre_training_soc_config(const char *ddr_type) |
| 1219 | { |
| 1220 | u32 soc_num; |
| 1221 | u32 reg_val; |
| 1222 | |
| 1223 | /* Switching CPU to MRVL ID */ |
| 1224 | soc_num = (reg_read(REG_SAMPLE_RESET_HIGH_ADDR) & SAR1_CPU_CORE_MASK) >> |
| 1225 | SAR1_CPU_CORE_OFFSET; |
| 1226 | switch (soc_num) { |
| 1227 | case 0x3: |
| 1228 | reg_bit_set(CPU_CONFIGURATION_REG(3), CPU_MRVL_ID_OFFSET); |
| 1229 | reg_bit_set(CPU_CONFIGURATION_REG(2), CPU_MRVL_ID_OFFSET); |
| 1230 | /* fallthrough */ |
| 1231 | case 0x1: |
| 1232 | reg_bit_set(CPU_CONFIGURATION_REG(1), CPU_MRVL_ID_OFFSET); |
| 1233 | /* fallthrough */ |
| 1234 | case 0x0: |
| 1235 | reg_bit_set(CPU_CONFIGURATION_REG(0), CPU_MRVL_ID_OFFSET); |
| 1236 | /* fallthrough */ |
| 1237 | default: |
| 1238 | break; |
| 1239 | } |
| 1240 | |
| 1241 | /* |
| 1242 | * Set DRAM Reset Mask in case detected GPIO indication of wakeup from |
| 1243 | * suspend i.e the DRAM values will not be overwritten / reset when |
| 1244 | * waking from suspend |
| 1245 | */ |
| 1246 | if (mv_ddr_sys_env_suspend_wakeup_check() == |
| 1247 | SUSPEND_WAKEUP_ENABLED_GPIO_DETECTED) { |
| 1248 | reg_bit_set(SDRAM_INIT_CTRL_REG, |
| 1249 | DRAM_RESET_MASK_MASKED << DRAM_RESET_MASK_OFFS); |
| 1250 | } |
| 1251 | |
| 1252 | /* Check if DRAM is already initialized */ |
| 1253 | if (reg_read(REG_BOOTROM_ROUTINE_ADDR) & |
| 1254 | (1 << REG_BOOTROM_ROUTINE_DRAM_INIT_OFFS)) { |
| 1255 | printf("%s Training Sequence - 2nd boot - Skip\n", ddr_type); |
| 1256 | return MV_OK; |
| 1257 | } |
| 1258 | |
| 1259 | /* Fix read ready phases for all SOC in reg 0x15c8 */ |
| 1260 | reg_val = reg_read(TRAINING_DBG_3_REG); |
| 1261 | |
| 1262 | reg_val &= ~(TRN_DBG_RDY_INC_PH_2TO1_MASK << TRN_DBG_RDY_INC_PH_2TO1_OFFS(0)); |
| 1263 | reg_val |= (0x4 << TRN_DBG_RDY_INC_PH_2TO1_OFFS(0)); /* phase 0 */ |
| 1264 | |
| 1265 | reg_val &= ~(TRN_DBG_RDY_INC_PH_2TO1_MASK << TRN_DBG_RDY_INC_PH_2TO1_OFFS(1)); |
| 1266 | reg_val |= (0x4 << TRN_DBG_RDY_INC_PH_2TO1_OFFS(1)); /* phase 1 */ |
| 1267 | |
| 1268 | reg_val &= ~(TRN_DBG_RDY_INC_PH_2TO1_MASK << TRN_DBG_RDY_INC_PH_2TO1_OFFS(3)); |
| 1269 | reg_val |= (0x6 << TRN_DBG_RDY_INC_PH_2TO1_OFFS(3)); /* phase 3 */ |
| 1270 | |
| 1271 | reg_val &= ~(TRN_DBG_RDY_INC_PH_2TO1_MASK << TRN_DBG_RDY_INC_PH_2TO1_OFFS(4)); |
| 1272 | reg_val |= (0x6 << TRN_DBG_RDY_INC_PH_2TO1_OFFS(4)); /* phase 4 */ |
| 1273 | |
| 1274 | reg_val &= ~(TRN_DBG_RDY_INC_PH_2TO1_MASK << TRN_DBG_RDY_INC_PH_2TO1_OFFS(5)); |
| 1275 | reg_val |= (0x6 << TRN_DBG_RDY_INC_PH_2TO1_OFFS(5)); /* phase 5 */ |
| 1276 | |
| 1277 | reg_write(TRAINING_DBG_3_REG, reg_val); |
| 1278 | |
| 1279 | /* |
| 1280 | * Axi_bresp_mode[8] = Compliant, |
| 1281 | * Axi_addr_decode_cntrl[11] = Internal, |
| 1282 | * Axi_data_bus_width[0] = 128bit |
| 1283 | * */ |
| 1284 | /* 0x14a8 - AXI Control Register */ |
| 1285 | reg_write(AXI_CTRL_REG, 0); |
| 1286 | |
| 1287 | /* |
| 1288 | * Stage 2 - Training Values Setup |
| 1289 | */ |
| 1290 | /* Set X-BAR windows for the training sequence */ |
| 1291 | ddr3_save_and_set_training_windows(win); |
| 1292 | |
| 1293 | return MV_OK; |
| 1294 | } |
| 1295 | |
| 1296 | static int ddr3_new_tip_dlb_config(void) |
| 1297 | { |
| 1298 | u32 reg, i = 0; |
| 1299 | struct dlb_config *config_table_ptr = sys_env_dlb_config_ptr_get(); |
| 1300 | |
| 1301 | /* Write the configuration */ |
| 1302 | while (config_table_ptr[i].reg_addr != 0) { |
| 1303 | reg_write(config_table_ptr[i].reg_addr, |
| 1304 | config_table_ptr[i].reg_data); |
| 1305 | i++; |
| 1306 | } |
| 1307 | |
| 1308 | |
| 1309 | /* Enable DLB */ |
| 1310 | reg = reg_read(DLB_CTRL_REG); |
| 1311 | reg &= ~(DLB_EN_MASK << DLB_EN_OFFS) & |
| 1312 | ~(WR_COALESCE_EN_MASK << WR_COALESCE_EN_OFFS) & |
| 1313 | ~(AXI_PREFETCH_EN_MASK << AXI_PREFETCH_EN_OFFS) & |
| 1314 | ~(MBUS_PREFETCH_EN_MASK << MBUS_PREFETCH_EN_OFFS) & |
| 1315 | ~(PREFETCH_NXT_LN_SZ_TRIG_MASK << PREFETCH_NXT_LN_SZ_TRIG_OFFS); |
| 1316 | |
| 1317 | reg |= (DLB_EN_ENA << DLB_EN_OFFS) | |
| 1318 | (WR_COALESCE_EN_ENA << WR_COALESCE_EN_OFFS) | |
| 1319 | (AXI_PREFETCH_EN_ENA << AXI_PREFETCH_EN_OFFS) | |
| 1320 | (MBUS_PREFETCH_EN_ENA << MBUS_PREFETCH_EN_OFFS) | |
| 1321 | (PREFETCH_NXT_LN_SZ_TRIG_ENA << PREFETCH_NXT_LN_SZ_TRIG_OFFS); |
| 1322 | |
| 1323 | reg_write(DLB_CTRL_REG, reg); |
| 1324 | |
| 1325 | return MV_OK; |
| 1326 | } |
| 1327 | |
| 1328 | int mv_ddr_post_training_soc_config(const char *ddr_type) |
| 1329 | { |
| 1330 | u32 reg_val; |
| 1331 | |
| 1332 | /* Restore and set windows */ |
| 1333 | ddr3_restore_and_set_final_windows(win, ddr_type); |
| 1334 | |
| 1335 | /* Update DRAM init indication in bootROM register */ |
| 1336 | reg_val = reg_read(REG_BOOTROM_ROUTINE_ADDR); |
| 1337 | reg_write(REG_BOOTROM_ROUTINE_ADDR, |
| 1338 | reg_val | (1 << REG_BOOTROM_ROUTINE_DRAM_INIT_OFFS)); |
| 1339 | |
| 1340 | /* DLB config */ |
| 1341 | ddr3_new_tip_dlb_config(); |
| 1342 | |
| 1343 | return MV_OK; |
| 1344 | } |
| 1345 | |
| 1346 | void mv_ddr_mc_config(void) |
| 1347 | { |
| 1348 | /* Memory controller initializations */ |
| 1349 | struct init_cntr_param init_param; |
| 1350 | int status; |
| 1351 | |
| 1352 | init_param.do_mrs_phy = 1; |
| 1353 | init_param.is_ctrl64_bit = 0; |
| 1354 | init_param.init_phy = 1; |
| 1355 | init_param.msys_init = 1; |
| 1356 | status = hws_ddr3_tip_init_controller(0, &init_param); |
| 1357 | if (status != MV_OK) |
| 1358 | printf("DDR3 init controller - FAILED 0x%x\n", status); |
| 1359 | |
| 1360 | status = mv_ddr_mc_init(); |
| 1361 | if (status != MV_OK) |
| 1362 | printf("DDR3 init_sequence - FAILED 0x%x\n", status); |
| 1363 | } |
| 1364 | /* function: mv_ddr_mc_init |
| 1365 | * this function enables the dunit after init controller configuration |
| 1366 | */ |
| 1367 | int mv_ddr_mc_init(void) |
| 1368 | { |
| 1369 | CHECK_STATUS(ddr3_tip_enable_init_sequence(0)); |
| 1370 | |
| 1371 | return MV_OK; |
| 1372 | } |
| 1373 | |
| 1374 | /* function: ddr3_tip_configure_phy |
| 1375 | * configures phy and electrical parameters |
| 1376 | */ |
| 1377 | int ddr3_tip_configure_phy(u32 dev_num) |
| 1378 | { |
| 1379 | u32 if_id, phy_id; |
| 1380 | u32 octets_per_if_num = ddr3_tip_dev_attr_get(dev_num, MV_ATTR_OCTET_PER_INTERFACE); |
| 1381 | struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get(); |
| 1382 | |
| 1383 | CHECK_STATUS(ddr3_tip_bus_write |
| 1384 | (dev_num, ACCESS_TYPE_MULTICAST, PARAM_NOT_CARE, |
| 1385 | ACCESS_TYPE_MULTICAST, PARAM_NOT_CARE, DDR_PHY_DATA, |
| 1386 | PAD_ZRI_CAL_PHY_REG, |
| 1387 | ((0x7f & g_zpri_data) << 7 | (0x7f & g_znri_data)))); |
| 1388 | CHECK_STATUS(ddr3_tip_bus_write |
| 1389 | (dev_num, ACCESS_TYPE_MULTICAST, PARAM_NOT_CARE, |
| 1390 | ACCESS_TYPE_MULTICAST, PARAM_NOT_CARE, DDR_PHY_CONTROL, |
| 1391 | PAD_ZRI_CAL_PHY_REG, |
| 1392 | ((0x7f & g_zpri_ctrl) << 7 | (0x7f & g_znri_ctrl)))); |
| 1393 | CHECK_STATUS(ddr3_tip_bus_write |
| 1394 | (dev_num, ACCESS_TYPE_MULTICAST, PARAM_NOT_CARE, |
| 1395 | ACCESS_TYPE_MULTICAST, PARAM_NOT_CARE, DDR_PHY_DATA, |
| 1396 | PAD_ODT_CAL_PHY_REG, |
| 1397 | ((0x3f & g_zpodt_data) << 6 | (0x3f & g_znodt_data)))); |
| 1398 | CHECK_STATUS(ddr3_tip_bus_write |
| 1399 | (dev_num, ACCESS_TYPE_MULTICAST, PARAM_NOT_CARE, |
| 1400 | ACCESS_TYPE_MULTICAST, PARAM_NOT_CARE, DDR_PHY_CONTROL, |
| 1401 | PAD_ODT_CAL_PHY_REG, |
| 1402 | ((0x3f & g_zpodt_ctrl) << 6 | (0x3f & g_znodt_ctrl)))); |
| 1403 | |
| 1404 | CHECK_STATUS(ddr3_tip_bus_write |
| 1405 | (dev_num, ACCESS_TYPE_MULTICAST, PARAM_NOT_CARE, |
| 1406 | ACCESS_TYPE_MULTICAST, PARAM_NOT_CARE, DDR_PHY_DATA, |
| 1407 | PAD_PRE_DISABLE_PHY_REG, 0)); |
| 1408 | CHECK_STATUS(ddr3_tip_bus_write |
| 1409 | (dev_num, ACCESS_TYPE_MULTICAST, PARAM_NOT_CARE, |
| 1410 | ACCESS_TYPE_MULTICAST, PARAM_NOT_CARE, DDR_PHY_DATA, |
| 1411 | CMOS_CONFIG_PHY_REG, 0)); |
| 1412 | CHECK_STATUS(ddr3_tip_bus_write |
| 1413 | (dev_num, ACCESS_TYPE_MULTICAST, PARAM_NOT_CARE, |
| 1414 | ACCESS_TYPE_MULTICAST, PARAM_NOT_CARE, DDR_PHY_CONTROL, |
| 1415 | CMOS_CONFIG_PHY_REG, 0)); |
| 1416 | |
| 1417 | for (if_id = 0; if_id <= MAX_INTERFACE_NUM - 1; if_id++) { |
| 1418 | /* check if the interface is enabled */ |
| 1419 | VALIDATE_IF_ACTIVE(tm->if_act_mask, if_id); |
| 1420 | |
| 1421 | for (phy_id = 0; |
| 1422 | phy_id < octets_per_if_num; |
| 1423 | phy_id++) { |
| 1424 | VALIDATE_BUS_ACTIVE(tm->bus_act_mask, phy_id); |
| 1425 | /* Vref & clamp */ |
| 1426 | CHECK_STATUS(ddr3_tip_bus_read_modify_write |
| 1427 | (dev_num, ACCESS_TYPE_UNICAST, |
| 1428 | if_id, phy_id, DDR_PHY_DATA, |
| 1429 | PAD_CFG_PHY_REG, |
| 1430 | ((clamp_tbl[if_id] << 4) | vref_init_val), |
| 1431 | ((0x7 << 4) | 0x7))); |
| 1432 | /* clamp not relevant for control */ |
| 1433 | CHECK_STATUS(ddr3_tip_bus_read_modify_write |
| 1434 | (dev_num, ACCESS_TYPE_UNICAST, |
| 1435 | if_id, phy_id, DDR_PHY_CONTROL, |
| 1436 | PAD_CFG_PHY_REG, 0x4, 0x7)); |
| 1437 | } |
| 1438 | } |
| 1439 | |
| 1440 | if (ddr3_tip_dev_attr_get(dev_num, MV_ATTR_PHY_EDGE) == |
| 1441 | MV_DDR_PHY_EDGE_POSITIVE) |
| 1442 | CHECK_STATUS(ddr3_tip_bus_write |
| 1443 | (dev_num, ACCESS_TYPE_MULTICAST, PARAM_NOT_CARE, |
| 1444 | ACCESS_TYPE_MULTICAST, PARAM_NOT_CARE, |
| 1445 | DDR_PHY_DATA, 0x90, 0x6002)); |
| 1446 | |
| 1447 | |
| 1448 | return MV_OK; |
| 1449 | } |
| 1450 | |
| 1451 | |
| 1452 | int mv_ddr_manual_cal_do(void) |
| 1453 | { |
| 1454 | return 0; |
| 1455 | } |