Kelvin Zhang | c4c3dd1 | 2021-12-24 20:59:18 +0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2014-2018 Amlogic, Inc. All rights reserved. |
| 3 | * |
| 4 | * All information contained herein is Amlogic confidential. |
| 5 | * |
| 6 | * This software is provided to you pursuant to Software License Agreement |
| 7 | * (SLA) with Amlogic Inc ("Amlogic"). This software may be used |
| 8 | * only in accordance with the terms of this agreement. |
| 9 | * |
| 10 | * Redistribution and use in source and binary forms, with or without |
| 11 | * modification is strictly prohibited without prior written permission from |
| 12 | * Amlogic. |
| 13 | * |
| 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 15 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 16 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 17 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 18 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 19 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 20 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 24 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 | *//* |
| 26 | * Copyright (C) 2014-2018 Amlogic, Inc. All rights reserved. |
| 27 | * |
| 28 | * All information contained herein is Amlogic confidential. |
| 29 | * |
| 30 | * This software is provided to you pursuant to Software License Agreement |
| 31 | * (SLA) with Amlogic Inc ("Amlogic"). This software may be used |
| 32 | * only in accordance with the terms of this agreement. |
| 33 | * |
| 34 | * Redistribution and use in source and binary forms, with or without |
| 35 | * modification is strictly prohibited without prior written permission from |
| 36 | * Amlogic. |
| 37 | * |
| 38 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 39 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 40 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 41 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 42 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 43 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 44 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 45 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 46 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 47 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 48 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 49 | */ |
| 50 | #include "ddr.h" |
| 51 | #include "common.h" |
| 52 | #include "register.h" |
| 53 | #include "FreeRTOS.h" |
| 54 | #include "task.h" |
| 55 | #include "soc.h" |
| 56 | |
| 57 | /* io defines */ |
| 58 | #define wr_reg(addr, val) (*((volatile uint32_t *)(addr))) = (val) |
| 59 | #define rd_reg(addr) (*((volatile uint32_t *)(addr))) |
| 60 | |
| 61 | /*clear [mask] 0 bits in [addr], set these 0 bits with [value] corresponding bits*/ |
| 62 | #define modify_reg(addr, value, mask) wr_reg(addr, ((rd_reg(addr) & (mask)) | (value))) |
| 63 | #define wait_set(addr, loc) do {} while (0 == (rd_reg(addr) & (1 << loc))); |
| 64 | #define wait_clr(addr, loc) do {} while (1 == (rd_reg(addr) & (1 << loc))); |
| 65 | #define wait_equal(addr, data) do {} while (data != (rd_reg(addr))); |
| 66 | |
| 67 | #define _udelay(tim) vTaskDelay(tim) |
| 68 | |
| 69 | unsigned int g_nAPDSet = 0; |
| 70 | #if 0 |
| 71 | void vDDR_suspend(uint32_t st_f) |
| 72 | { |
| 73 | //printf("aml log : DDR suspend...dummy\n"); |
| 74 | //return; |
| 75 | |
| 76 | printf("aml log : DDR suspend...1"); |
| 77 | |
| 78 | g_nAPDSet = rd_reg(DMC_DRAM_APD_CTRL); |
| 79 | wr_reg(DMC_DRAM_APD_CTRL,0); |
| 80 | |
| 81 | #ifdef CHECK_DMC_IDLE |
| 82 | while ((((rd_reg(DMC_DRAM_STAT)) & 0xf0) != 0) && |
| 83 | (((rd_reg(DMC_DRAM_STAT)) & 0xf0) != 0x40)) { |
| 84 | } |
| 85 | #endif |
| 86 | |
| 87 | #if 0 |
| 88 | wr_reg(DMC_DRAM_SCFG, 2); |
| 89 | vTaskDelay(pdMS_TO_TICKS(1)); |
| 90 | while (((((rd_reg(DMC_DRAM_STAT)) >> 4) & 0xf) != 3)) { |
| 91 | } |
| 92 | #endif |
| 93 | |
| 94 | wr_reg(DMC_DRAM_DFIINITCFG, (1 | (1 << 8))); |
| 95 | |
| 96 | wait_clr(DMC_DRAM_DFIINITCFG, 31); |
| 97 | |
| 98 | vTaskDelay(pdMS_TO_TICKS(1)); |
| 99 | //wr_reg(AM_DDR_PLL_CNTL0, |
| 100 | // (rd_reg(AM_DDR_PLL_CNTL0) & (~(0xf << 28))) | (1 << 29)); |
| 101 | |
| 102 | printf("done!!\n"); |
| 103 | |
| 104 | vTaskDelay(pdMS_TO_TICKS(1000)); |
| 105 | |
| 106 | //vDDR_resume(0); |
| 107 | |
| 108 | printf("\naml log : DMC_DRAM_STAT=0x%x",rd_reg(DMC_DRAM_STAT)); |
| 109 | printf("\naml log : DMC_DRAM_DFIINITCFG=0x%x\n",rd_reg(DMC_DRAM_DFIINITCFG)); |
| 110 | |
| 111 | } |
| 112 | |
| 113 | void vDDR_resume(uint32_t st_f) |
| 114 | { |
| 115 | printf("aml log : DDR resume...2"); |
| 116 | |
| 117 | //printf("aml log : DDR resume...dummy\n"); |
| 118 | //return; |
| 119 | |
| 120 | #if 0 |
| 121 | do { |
| 122 | wr_reg(AM_DDR_PLL_CNTL0, (rd_reg(AM_DDR_PLL_CNTL0) & (~(0xf << 28))) | (0xc << 28)); |
| 123 | vTaskDelay(pdMS_TO_TICKS(1)); |
| 124 | wr_reg(AM_DDR_PLL_CNTL0, (rd_reg(AM_DDR_PLL_CNTL0) & (~(0xf << 28))) | (0xd << 28)); |
| 125 | vTaskDelay(pdMS_TO_TICKS(5)); |
| 126 | wr_reg(AM_DDR_PLL_CNTL0, (rd_reg(AM_DDR_PLL_CNTL0) & (~(0xf << 28))) | (0x5 << 28)); |
| 127 | vTaskDelay(pdMS_TO_TICKS(10)); |
| 128 | wr_reg(AM_DDR_PLL_CNTL0, (rd_reg(AM_DDR_PLL_CNTL0) & (~(0xf << 28))) | (0x7 << 28)); |
| 129 | vTaskDelay(pdMS_TO_TICKS(100)); |
| 130 | } while ((0 == ((rd_reg(AM_DDR_PLL_STS) >> 31) & 0x1))); |
| 131 | wr_reg(DDR_CLK_CNTL, 0x10000000); |
| 132 | wr_reg(DDR_CLK_CNTL, 0xb0000007); |
| 133 | |
| 134 | vTaskDelay(pdMS_TO_TICKS(1)); |
| 135 | #endif |
| 136 | |
| 137 | |
| 138 | wr_reg(DMC_DRAM_DFIINITCFG, (0 | (1 << 8))); |
| 139 | vTaskDelay(pdMS_TO_TICKS(1)); |
| 140 | |
| 141 | printf("-1"); |
| 142 | |
| 143 | wait_set(DMC_DRAM_DFIINITCFG, 31); |
| 144 | vTaskDelay(pdMS_TO_TICKS(10)); //extra 10us for vt |
| 145 | #if 0 |
| 146 | wr_reg(DMC_DRAM_SCFG, 4); |
| 147 | #endif |
| 148 | vTaskDelay(pdMS_TO_TICKS(1)); |
| 149 | |
| 150 | printf("-2"); |
| 151 | |
| 152 | int nLoopFlag = 1; |
| 153 | do { |
| 154 | |
| 155 | switch ((rd_reg(DMC_DRAM_STAT)) & 0xf0) |
| 156 | { |
| 157 | case 0: //DRAM IDLE |
| 158 | case 0x20: //DRAM ACCESS |
| 159 | case 0x40: //DRAM APD |
| 160 | nLoopFlag = 0; |
| 161 | break; |
| 162 | default: break; |
| 163 | } |
| 164 | } while(nLoopFlag); |
| 165 | |
| 166 | vTaskDelay(pdMS_TO_TICKS(30)); |
| 167 | |
| 168 | printf("-3"); |
| 169 | |
| 170 | printf("done\n"); |
| 171 | |
| 172 | printf("\naml log : DMC_DRAM_STAT=0x%x",rd_reg(DMC_DRAM_STAT)); |
| 173 | printf("\naml log : DMC_DRAM_DFIINITCFG=0x%x\n",rd_reg(DMC_DRAM_DFIINITCFG)); |
| 174 | |
| 175 | } |
| 176 | #endif |
| 177 | |
| 178 | /* |
| 179 | #define PATTERN_MATRIX_X (3 + 32 + 16 + 17) //68*32==2176 ///2.2k -0x880-1 loop |
| 180 | #define PATTERN_MATRIX_Y (32) |
| 181 | #define PATTERN_MATRIX_LOOP_SIZE ((PATTERN_MATRIX_X)*(PATTERN_MATRIX_Y) * 4) |
| 182 | unsigned int cpu_ddr_test_init_pattern_generater(uint32_t martix_x_select, uint32_t martix_y_select) |
| 183 | { |
| 184 | unsigned int pattern_value = 0; |
| 185 | unsigned int pattern_value_temp_16 = 0; |
| 186 | |
| 187 | martix_x_select = (martix_x_select % PATTERN_MATRIX_X); |
| 188 | { |
| 189 | { |
| 190 | { |
| 191 | if (martix_x_select == 0) |
| 192 | pattern_value = 0xaaaa5555; //for 16 bit bus pattern |
| 193 | |
| 194 | if (martix_x_select == 1) |
| 195 | pattern_value = 0x0000ffff; //for 16 bit bus pattern |
| 196 | |
| 197 | if (martix_x_select == 2) |
| 198 | pattern_value = 0; |
| 199 | |
| 200 | if ((martix_x_select > 2) && (martix_x_select < (3 + 32))) |
| 201 | pattern_value = 1 << (martix_x_select - 3); |
| 202 | if ((martix_x_select > (2 + 32)) && (martix_x_select < (3 + 32 + 16))) { //for 16 bit bus pattern |
| 203 | pattern_value_temp_16 = (1 << (martix_x_select - 3 - 32)); |
| 204 | pattern_value = pattern_value_temp_16 | ((~pattern_value_temp_16) << 16); |
| 205 | } |
| 206 | if ((martix_x_select > (2 + 32 + 16)) && (martix_x_select < (3 + 32 + 16 + 17))) { //for dbi bus pattern 17 group |
| 207 | pattern_value_temp_16 = (0x0f0f + 0xf0f * (martix_x_select - 3 - 32 - 16)); |
| 208 | pattern_value = pattern_value_temp_16 | ((~pattern_value_temp_16) << 16); |
| 209 | } |
| 210 | } |
| 211 | if ((martix_y_select % 2)) |
| 212 | pattern_value = ~pattern_value; |
| 213 | if ((martix_y_select % ((PATTERN_MATRIX_Y) / 2)) == (((PATTERN_MATRIX_Y * 1) / 8) - 1)) //for dbi pattern walk 0 and walk 1 |
| 214 | pattern_value = 0; //insert for dbi pattern jiaxing 20190117 |
| 215 | if ((martix_y_select % ((PATTERN_MATRIX_Y) / 2)) == (((PATTERN_MATRIX_Y * 3) / 8) - 1)) //for dbi pattern walk 0 and walk 1 |
| 216 | pattern_value = ~0; //insert for dbi pattern jiaxing 20190117 |
| 217 | } |
| 218 | } |
| 219 | return pattern_value; |
| 220 | } |
| 221 | */ |
| 222 | #if 0 |
| 223 | static unsigned int dmc_ddr_test(unsigned int start_add, unsigned int write_enable, unsigned int read_enable, unsigned int read_compare, unsigned int test_end_add, unsigned int pattern, unsigned int seed) |
| 224 | { |
| 225 | seed=2; |
| 226 | #define DATA_LOOP_PATTERN_INDEX 4 + 32 //0xff |
| 227 | unsigned int dmc_test_sts = 0; |
| 228 | unsigned int dmc_error = 0; |
| 229 | //unsigned int pattern_select = 0; |
| 230 | unsigned int pattern_value = 0; |
| 231 | unsigned int pattern_inv_value = 0; |
| 232 | |
| 233 | dmc_error = 0; |
| 234 | { |
| 235 | test_end_add = test_end_add - 4; //sha must bit 0-6 ==ff; |
| 236 | } |
| 237 | wr_reg(DMC_TEST_STA, start_add); // RESET FIFOS //0x03d81e3f |
| 238 | wr_reg(DMC_TEST_EDA, test_end_add); //0x07d81e3f |
| 239 | if (pattern == 0) { |
| 240 | wr_reg(DMC_TEST_WD0, 0xaa5555aa); |
| 241 | wr_reg(DMC_TEST_WD1, 0x55aaaa55); |
| 242 | wr_reg(DMC_TEST_WD2, 0); |
| 243 | wr_reg(DMC_TEST_WD3, 0xffffffff); |
| 244 | wr_reg(DMC_TEST_WD4, 0); |
| 245 | wr_reg(DMC_TEST_WD5, 0x0000ffff); |
| 246 | wr_reg(DMC_TEST_WD6, 0xffff0000); |
| 247 | wr_reg(DMC_TEST_WD7, 0x33cccc33); |
| 248 | wr_reg(DMC_TEST_WD0 + 32, 0xaa5555aa); |
| 249 | wr_reg(DMC_TEST_WD1 + 32, 0x55aaaa55); |
| 250 | wr_reg(DMC_TEST_WD2 + 32, 0); |
| 251 | wr_reg(DMC_TEST_WD3 + 32, 0xffffffff); |
| 252 | wr_reg(DMC_TEST_WD4 + 32, 0); |
| 253 | wr_reg(DMC_TEST_WD5 + 32, 0x0000ffff); |
| 254 | wr_reg(DMC_TEST_WD6 + 32, 0xffff0000); |
| 255 | wr_reg(DMC_TEST_WD7 + 32, 0x33cccc33); |
| 256 | } else if (pattern < 33) { |
| 257 | wr_reg(DMC_TEST_WD0, ((1 << (pattern - 1)) + seed)); |
| 258 | wr_reg(DMC_TEST_WD1, ((2 << (pattern - 1)) + seed)); |
| 259 | wr_reg(DMC_TEST_WD2, ((3 << (pattern - 1)) + seed)); |
| 260 | wr_reg(DMC_TEST_WD3, ((4 << (pattern - 1)) + seed)); |
| 261 | wr_reg(DMC_TEST_WD4, ((4 << (pattern - 1)))); |
| 262 | wr_reg(DMC_TEST_WD5, ((4 << (pattern - 1)))); |
| 263 | wr_reg(DMC_TEST_WD6, ((4 << (pattern - 1)))); |
| 264 | wr_reg(DMC_TEST_WD7, ((4 << (pattern - 1)))); |
| 265 | if (pattern > 16) { |
| 266 | wr_reg(DMC_TEST_WD4, ((4 << (pattern - 1)) + 0x01010101)); |
| 267 | wr_reg(DMC_TEST_WD5, ((4 << (pattern - 1)) + 0x01010101)); |
| 268 | wr_reg(DMC_TEST_WD6, ((4 << (pattern - 1)) + 0x01010101)); |
| 269 | wr_reg(DMC_TEST_WD7, ((4 << (pattern - 1)) + 0x01010101)); |
| 270 | } else if (pattern > 1) { |
| 271 | wr_reg(DMC_TEST_WD4, ((4 << (pattern - 1)) + 0x01010101)); |
| 272 | wr_reg(DMC_TEST_WD5, ((4 << (pattern - 1)) + 0x01010101)); |
| 273 | wr_reg(DMC_TEST_WD6, ((4 << (pattern - 1)) + 0x01010101)); |
| 274 | wr_reg(DMC_TEST_WD7, ((4 << (pattern - 1)) + 0x01010101)); |
| 275 | } |
| 276 | } else { |
| 277 | //pattern_select = pattern - 33; |
| 278 | pattern_value =1;// cpu_ddr_test_init_pattern_generater(pattern_select, 0); |
| 279 | pattern_inv_value = ~pattern_value; |
| 280 | for (char counter = 0; counter < 32; ) { |
| 281 | wr_reg((DMC_TEST_WD0 + counter), pattern_value); |
| 282 | counter = counter + 4; |
| 283 | wr_reg((DMC_TEST_WD0 + counter), pattern_inv_value); |
| 284 | if (counter == 16) |
| 285 | wr_reg((DMC_TEST_WD0 + counter), 0); |
| 286 | counter = counter + 4; |
| 287 | } |
| 288 | for (char counter = 0; counter < 32; ) { //for g12b-revb register not continuous |
| 289 | wr_reg((DMC_TEST_WD8 + counter), pattern_value); |
| 290 | counter = counter + 4; |
| 291 | wr_reg((DMC_TEST_WD8 + counter), pattern_inv_value); |
| 292 | if (counter == 16) |
| 293 | wr_reg((DMC_TEST_WD0 + counter), ~0); |
| 294 | counter = counter + 4; |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | |
| 299 | wr_reg(DMC_TEST_STS, 0x8000001f); //must clear watchdog and done flag jiaxing debug 2016_12_07 |
| 300 | wr_reg(DMC_TEST_WDG, 0xf000f000); //wdg should >rfc value ,use dmc clk count. |
| 301 | if ((pattern == 1) || ((pattern < 33) && pattern)) //should repeat 1 times for read ,all will fail when data increase jiaxing debug 20180322 |
| 302 | wr_reg(DMC_TEST_CTRL, (1 << 31) | (read_compare << 27) | (0 << 28) | (0 << 25) | (1 << 24) | (0 << 20) | (1 << 23) | (0x0 << 16) | (0 << 8) | (0x428) | (3 << 18) | (write_enable << 30) | (read_enable << 29)); |
| 303 | else |
| 304 | wr_reg(DMC_TEST_CTRL, (1 << 31) | (read_compare << 27) | (0 << 28) | (1 << 24) | (0x0 << 16) | (0 << 18) | (0x0 << 0) | (0 << 8) | (0x428) | (3 << 18) | (write_enable << 30) | (read_enable << 29)); |
| 305 | |
| 306 | do |
| 307 | //_udelay(1); |
| 308 | dmc_test_sts = (rd_reg(DMC_TEST_STS)); |
| 309 | while (!(dmc_test_sts & 0xc0000000)); |
| 310 | |
| 311 | wr_reg(DMC_TEST_CTRL, 0x00000000); |
| 312 | |
| 313 | if ((dmc_test_sts & 0x40000000)) |
| 314 | dmc_error = 1; |
| 315 | else |
| 316 | if (dmc_test_sts & 0x40000001) //can not deter write triger ,or can not guickly recover dmc with phy? 2016_12_12 |
| 317 | dmc_error = 1; |
| 318 | |
| 319 | dmc_error = dmc_error + (rd_reg(DMC_TEST_ERR_CNT)); |
| 320 | wr_reg(DMC_TEST_STS, 0x8000001f); //must clear watchdog and done flag jiaxing debug 2016_12_07 |
| 321 | |
| 322 | if (dmc_error) { |
| 323 | for (unsigned int counter1 = 0; counter1 < (DMC_TEST_RDRSP_ADDR+4-DMC_TEST_STA); ) |
| 324 | { |
| 325 | printf( "\ncounter %08x %08x",counter1,(rd_reg(DMC_TEST_STA+(counter1)))); |
| 326 | counter1=counter1+4; |
| 327 | } |
| 328 | wr_reg(DMC_SOFT_RST, (rd_reg(DMC_SOFT_RST)) & (~((1 << 29) | (1 << 24)))); //clear read buffer dmc test reset |
| 329 | vTaskDelay(pdMS_TO_TICKS(1)); |
| 330 | wr_reg(DMC_SOFT_RST, (rd_reg(DMC_SOFT_RST)) | ((1 << 29)) | (1 << 24)); |
| 331 | vTaskDelay(pdMS_TO_TICKS(1)); |
| 332 | } |
| 333 | return dmc_error; |
| 334 | } |
| 335 | |
| 336 | unsigned int apb_sec_ctrl = 0; |
| 337 | #define DDR_APB_SEC_CTRL ((0x00f0 << 2) + 0xff639000) |
| 338 | #endif |
| 339 | #if 0 //def CFG_ENABLE_DDR_SUSPEND_TEST |
| 340 | static void ddr_suspend_resume_test(uint32_t test_size, uint32_t test_delay_time_ms, uint32_t test_write_loops, uint32_t test_read_loops, uint32_t test_skip_suspend, uint32_t p_dev) |
| 341 | { |
| 342 | //return; |
| 343 | uint32_t lock_cnt = 100; |
| 344 | uint32_t apd_value = 0; |
| 345 | p_dev = p_dev; |
| 346 | printf( "enter suspend_n_debug\n"); |
| 347 | apd_value = rd_reg(DMC_DRAM_APD_CTRL); |
| 348 | wr_reg(DMC_DRAM_APD_CTRL, 0); |
| 349 | |
| 350 | //watchdog_disable(); |
| 351 | printf( "test_size=%08x test_delay_time_ms=%d test_write_loops=%d test_read_loops=%d", \ |
| 352 | test_size, test_delay_time_ms, test_write_loops, test_read_loops); |
| 353 | printf( "enter suspend111\n"); |
| 354 | |
| 355 | #if 1 //def CFG_ENABLE_DDR_DMC_TEST |
| 356 | uint64_t dram_size = 0, dram_base = 0; |
| 357 | dram_base = 0x0000000; // p_ddrs->ddr_base_addr; |
| 358 | //dram_size = 1024;//p_ddrs->cfg_board_common_setting.dram_cs0_size_MB + p_ddrs->cfg_board_common_setting.dram_cs1_size_MB; |
| 359 | dram_size =1024; |
| 360 | |
| 361 | if (!test_size) |
| 362 | test_size = (dram_size << 20) - 4; |
| 363 | |
| 364 | //if (!test_delay_time_ms) |
| 365 | // test_delay_time_ms = 3000; |
| 366 | |
| 367 | if (!test_write_loops) |
| 368 | test_write_loops = 1; |
| 369 | |
| 370 | if (!test_read_loops) |
| 371 | test_read_loops = 1; |
| 372 | uint32_t ddr_bist_test_error = 0; |
| 373 | #endif |
| 374 | |
| 375 | while ((test_write_loops) || (test_read_loops)) { |
| 376 | if (test_write_loops) |
| 377 | ddr_bist_test_error = dmc_ddr_test(dram_base, 1, 0, 0, test_size, 1, 0) + ddr_bist_test_error; |
| 378 | printf( "enter suspend113\n"); |
| 379 | if (!test_skip_suspend) { |
| 380 | #if 0 //def CHECK_DMC_IDLE |
| 381 | while ((((rd_reg(DMC_DRAM_STAT)) & 0xf0) != 0) && (((rd_reg(DMC_DRAM_STAT)) & 0xf0) != 0x40)) { |
| 382 | } |
| 383 | #endif |
| 384 | #if 0 |
| 385 | wr_reg(DMC_DRAM_SCFG, 2); |
| 386 | vTaskDelay(pdMS_TO_TICKS(1)); |
| 387 | |
| 388 | while (((((rd_reg(DMC_DRAM_STAT)) >> 4) & 0xf) != 3)) { |
| 389 | } |
| 390 | #endif |
| 391 | //printf( "enter suspend114\n"); |
| 392 | wr_reg(DMC_DRAM_DFIINITCFG, (1 | (0 << 1) | (0 << 6) | (0 << 14) | (1 << 8))); |
| 393 | vTaskDelay(pdMS_TO_TICKS(1)); |
| 394 | wait_clr(DMC_DRAM_DFIINITCFG, 31); //final version, wait_clr |
| 395 | vTaskDelay(pdMS_TO_TICKS(3)); |
| 396 | // printf( "enter suspend115\n"); |
| 397 | wr_reg(AM_DDR_PLL_CNTL0, (rd_reg(AM_DDR_PLL_CNTL0) & (~(0xf << 28))) | (1 << 29)); |
| 398 | } |
| 399 | //_udelay(test_delay_time_ms * 1000); |
| 400 | vTaskDelay(test_delay_time_ms * pdMS_TO_TICKS(1000)); |
| 401 | //_udelay( 1000); |
| 402 | printf( "enter suspend111..wait\n"); |
| 403 | if (!test_skip_suspend) { |
| 404 | printf("enter resume\n"); |
| 405 | |
| 406 | do { |
| 407 | wr_reg(AM_DDR_PLL_CNTL0, (rd_reg(AM_DDR_PLL_CNTL0) & (~(0xf << 28))) | (1 << 29)); |
| 408 | vTaskDelay(pdMS_TO_TICKS(1)); |
| 409 | wr_reg(AM_DDR_PLL_CNTL0, (rd_reg(AM_DDR_PLL_CNTL0) & (~(0x1 << 29))) | (1 << 28)); |
| 410 | |
| 411 | vTaskDelay(pdMS_TO_TICKS(200)); //must wait some time than to read |
| 412 | } while ((0 == ((rd_reg(AM_DDR_PLL_CNTL0) >> 31) & 0x1)) && (lock_cnt--)); |
| 413 | |
| 414 | printf( "pll relock ok\n"); //need extra delay |
| 415 | vTaskDelay(pdMS_TO_TICKS(1)); |
| 416 | wr_reg(DMC_DRAM_DFIINITCFG, (0 | (0 << 1) | (0 << 6) | (0 << 14) | (1 << 8))); |
| 417 | vTaskDelay(pdMS_TO_TICKS(1)); |
| 418 | wait_set(DMC_DRAM_DFIINITCFG, 31); |
| 419 | vTaskDelay(pdMS_TO_TICKS(100)); //extra 10us for vt |
| 420 | } |
| 421 | #if 1 //def CFG_ENABLE_DDR_DMC_TEST |
| 422 | if (test_read_loops) |
| 423 | ddr_bist_test_error = dmc_ddr_test(dram_base, 0, 1, 1, test_size, 1, 0) + ddr_bist_test_error; |
| 424 | //if (ddr_bist_test_error) |
| 425 | printf( "dmc full test result = %d\n", ddr_bist_test_error); |
| 426 | #endif |
| 427 | |
| 428 | if (test_write_loops) |
| 429 | test_write_loops--; |
| 430 | |
| 431 | if (test_read_loops) |
| 432 | test_read_loops--; |
| 433 | } |
| 434 | wr_reg(DMC_DRAM_APD_CTRL, apd_value); |
| 435 | |
| 436 | //printf("end resume test11\n"); |
| 437 | } /* ddr_suspend_resume_test */ |
| 438 | #endif |
| 439 | //#define DDR_SUSPEND_MODE_DMC_TRIGGER_SUSPEND_1 1 |
| 440 | #define DDR_SUSPEND_MODE_MANUAL_TRIGGER_DFI_INIT_START 2 |
| 441 | void vDDR_suspend(uint32_t st_f) |
| 442 | { |
| 443 | //printf("aml log : DDR suspend...dummy\n"); |
| 444 | //return; |
| 445 | |
| 446 | st_f = st_f; |
| 447 | //unsigned int time_start, time_end; |
| 448 | printf("Enter ddr suspend\n"); |
| 449 | |
| 450 | //return ; |
| 451 | |
| 452 | while (0xfffffff != rd_reg(DMC_CHAN_STS)) { |
| 453 | printf("DMC_CHAN_STS: 0x%x\n", rd_reg(DMC_CHAN_STS)); |
| 454 | vTaskDelay(pdMS_TO_TICKS(100000)); |
| 455 | } |
| 456 | |
| 457 | //time_start = rd_reg(P_ISA_TIMERE); |
| 458 | |
| 459 | /* open DMC reg access for M3 */ |
| 460 | //apb_sec_ctrl = rd_reg(DDR_APB_SEC_CTRL); |
| 461 | //wr_reg(DDR_APB_SEC_CTRL,0x91911); |
| 462 | |
| 463 | wr_reg(DMC_REQ_CTRL, 0); //bit0: A53. |
| 464 | _udelay(1); |
| 465 | |
| 466 | /* suspend flow */ |
| 467 | while ((((rd_reg(DMC_DRAM_STAT))&0xf0) != 0) && (((rd_reg(DMC_DRAM_STAT))&0xf0) != 0x40)) { |
| 468 | // printf("DMC_DRAM_STAT11: 0x%x\n", rd_reg(DMC_DRAM_STAT)); |
| 469 | vTaskDelay(pdMS_TO_TICKS(1)); |
| 470 | } |
| 471 | #ifdef DDR_SUSPEND_MODE_DMC_TRIGGER_SUSPEND_1 |
| 472 | wr_reg(DMC_DRAM_ASR_CTRL,(1<<18)); //bit 18 will auto trigger dfi init start cmd when scfg set to value 2 |
| 473 | wr_reg(DMC_DRAM_SCFG, 2); |
| 474 | while (((((rd_reg(DMC_DRAM_STAT))>>4)&0xf) != 3)) { |
| 475 | //printf("DMC_DRAM_STAT22: 0x%x\n", readl(DMC_DRAM_STAT)); |
| 476 | //_udelay(1);//do not add any delay,since use ao cpu maybe speed too slow |
| 477 | } |
| 478 | |
| 479 | #endif |
| 480 | |
| 481 | #ifdef DDR_SUSPEND_MODE_MANUAL_TRIGGER_DFI_INIT_START |
| 482 | wr_reg(DMC_DRAM_SCFG, 1); |
| 483 | while (((((rd_reg(DMC_DRAM_STAT))>>4)&0xf) != 1)) { |
| 484 | //printf("DMC_DRAM_STAT22: 0x%x\n", readl(DMC_DRAM_STAT)); |
| 485 | //_udelay(1);//do not add any delay,since use ao cpu maybe speed too slow |
| 486 | } |
| 487 | |
| 488 | wr_reg(DMC_DRAM_DFIINITCFG, (1 | (0 << 1) | (0 << 6) | (0 << 14) | (1 << 8))); |
| 489 | vTaskDelay(pdMS_TO_TICKS(1)); |
| 490 | wait_clr(DMC_DRAM_DFIINITCFG, 31); |
| 491 | #endif //final version, wait_clr |
| 492 | vTaskDelay(pdMS_TO_TICKS(3)); |
| 493 | wr_reg(AM_DDR_PLL_CNTL0, (rd_reg(AM_DDR_PLL_CNTL0) & (~(0xf << 28))) | (1 << 29)); |
| 494 | |
| 495 | |
| 496 | /* print time consumption */ |
| 497 | //time_end = rd_reg(P_ISA_TIMERE); |
| 498 | //printf("ddr suspend time: %dus\n", time_end - time_start); |
| 499 | printf("\nddr suspend is done\n"); |
| 500 | //ddr_suspend_resume_test((1024<<20), 100, 3, 3, 0, 0); |
| 501 | //ddr_suspend_resume_test((80<<20), 10000000, 0, 3, 0, 0); |
| 502 | } |
| 503 | |
| 504 | static unsigned int pll_lock(void) { |
| 505 | unsigned int lock_cnt = 100; |
| 506 | do { |
| 507 | wr_reg(AM_DDR_PLL_CNTL0, (rd_reg(AM_DDR_PLL_CNTL0) & (~(0xf<<28))) | (1<<29)); |
| 508 | vTaskDelay(pdMS_TO_TICKS(1)); |
| 509 | wr_reg(AM_DDR_PLL_CNTL0, (rd_reg(AM_DDR_PLL_CNTL0) & (~(0x1<<29))) | (1<<28)); |
| 510 | vTaskDelay(pdMS_TO_TICKS(200)); |
| 511 | } while((0 == ((rd_reg(AM_DDR_PLL_CNTL0) >> 31) & 0x1)) && (lock_cnt--)); |
| 512 | return lock_cnt; |
| 513 | } |
| 514 | |
| 515 | void vDDR_resume(uint32_t st_f) |
| 516 | { |
| 517 | //unsigned int time_start, time_end; |
| 518 | unsigned int ret = 0; |
| 519 | |
| 520 | st_f = st_f; |
| 521 | printf("Enter ddr resume\n"); |
| 522 | |
| 523 | |
| 524 | //return; |
| 525 | |
| 526 | //time_start = rd_reg(P_ISA_TIMERE); |
| 527 | /* resume flow */ |
| 528 | #if 1 |
| 529 | ret = pll_lock(); |
| 530 | if (!ret) { |
| 531 | printf("ddr pll lock r1\n"); |
| 532 | wr_reg(AM_DDR_PLL_CNTL3, rd_reg(AM_DDR_PLL_CNTL3)|(1<<31)); |
| 533 | ret = pll_lock(); |
| 534 | if (!ret) { |
| 535 | printf("ddr pll lock r2\n"); |
| 536 | wr_reg(AM_DDR_PLL_CNTL6, 0x55540000); |
| 537 | ret = pll_lock(); |
| 538 | if (!ret) { |
| 539 | printf("ddr pll lock r2\n"); |
| 540 | while (1) {}; |
| 541 | } |
| 542 | } |
| 543 | } |
| 544 | #endif |
| 545 | |
| 546 | #ifdef DDR_SUSPEND_MODE_DMC_TRIGGER_SUSPEND_1 |
| 547 | |
| 548 | #endif |
| 549 | |
| 550 | #ifdef DDR_SUSPEND_MODE_MANUAL_TRIGGER_DFI_INIT_START |
| 551 | wr_reg(DMC_DRAM_DFIINITCFG, (0 | (0 << 1) | (0 << 6) | (0 << 14) | (1 << 8))); |
| 552 | vTaskDelay(pdMS_TO_TICKS(1)); |
| 553 | wait_set(DMC_DRAM_DFIINITCFG, 31); |
| 554 | vTaskDelay(pdMS_TO_TICKS(100)); |
| 555 | #endif |
| 556 | wr_reg(DMC_DRAM_SCFG, 4); |
| 557 | while (((((rd_reg(DMC_DRAM_STAT))>>4)&0xf) != 2)) { |
| 558 | //printf("DMC_DRAM_STAT22: 0x%x\n", readl(DMC_DRAM_STAT)); |
| 559 | //_udelay(1);//do not add any delay,since use ao cpu maybe speed too slow |
| 560 | } |
| 561 | |
| 562 | #if 0 |
| 563 | wr_reg( DMC_DRAM_SCFG, 4); |
| 564 | vTaskDelay(pdMS_TO_TICKS(1)); |
| 565 | #endif |
| 566 | |
| 567 | wr_reg(DMC_REQ_CTRL, 0xffffffff); |
| 568 | //wr_reg(DDR_APB_SEC_CTRL, apb_sec_ctrl); |
| 569 | /* print time consumption */ |
| 570 | //time_end = readl(P_ISA_TIMERE); |
| 571 | //printf("ddr resume time: %dus\n", time_end - time_start); |
| 572 | // unsigned int ddr_bist_test_error = 0; |
| 573 | //ddr_bist_test_error = dmc_ddr_test(dram_base, 0, 1, 1, test_size, 1, 0) + ddr_bist_test_error; |
| 574 | //ddr_bist_test_error = dmc_ddr_test(0, 0, 1, 1, (80<<20), 1, 0) + ddr_bist_test_error; |
| 575 | //printf("ddr_bist_test_error = %d\n", ddr_bist_test_error); |
| 576 | //wr_reg(0xfe002440, 2); |
| 577 | // wr_reg(0xfe002440, 0); |
| 578 | // _udelay(300); |
| 579 | //ddr_bist_test_error = dmc_ddr_test(0, 1, 0, 0, (1<<20), 1, 0) + ddr_bist_test_error; |
| 580 | //ddr_bist_test_error = dmc_ddr_test(0, 0, 1, 1, (1<<20), 1, 0) + ddr_bist_test_error; |
| 581 | // printf("ddr_bist_test_error = %d\n", ddr_bist_test_error); |
| 582 | //ddr_suspend_resume_test((1<<20), 2, 1, 3, 0, 0); |
| 583 | //ddr_suspend_resume_test((1<<20), 0, 1, 3, 0, 0); |
| 584 | //_udelay(300); |
| 585 | // wr_reg(DMC_REQ_CTRL, 0xffffffff); |
| 586 | printf("ddr resume done\n"); |
| 587 | } |
| 588 | |
| 589 | |