Haojian Zhuang | 934ae71 | 2017-05-24 08:47:49 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <arch_helpers.h> |
| 8 | #include <debug.h> |
| 9 | #include <errno.h> |
| 10 | #include <hi6220.h> |
| 11 | #include <hi6553.h> |
| 12 | #include <mmio.h> |
| 13 | #include <sp804_delay_timer.h> |
| 14 | |
| 15 | enum { |
| 16 | DDR_FREQ_533M = 0, |
| 17 | DDR_FREQ_800M, |
| 18 | }; |
| 19 | |
| 20 | static void init_pll(void) |
| 21 | { |
| 22 | unsigned int data; |
| 23 | |
| 24 | data = mmio_read_32((0xf7032000 + 0x000)); |
| 25 | data |= 0x1; |
| 26 | mmio_write_32((0xf7032000 + 0x000), data); |
| 27 | dsb(); |
| 28 | do { |
| 29 | data = mmio_read_32((0xf7032000 + 0x000)); |
| 30 | } while (!(data & (1 << 28))); |
| 31 | |
| 32 | data = mmio_read_32((0xf7800000 + 0x000)); |
| 33 | data &= ~0x007; |
| 34 | data |= 0x004; |
| 35 | mmio_write_32((0xf7800000 + 0x000), data); |
| 36 | dsb(); |
| 37 | do { |
| 38 | data = mmio_read_32((0xf7800000 + 0x014)); |
| 39 | data &= 0x007; |
| 40 | } while (data != 0x004); |
| 41 | |
| 42 | mmio_write_32(PERI_SC_PERIPH_CTRL14, 0x2101); |
| 43 | data = mmio_read_32(PERI_SC_PERIPH_STAT1); |
| 44 | mmio_write_32(0xf7032000 + 0x02c, 0x5110103e); |
| 45 | data = mmio_read_32(0xf7032000 + 0x050); |
| 46 | data |= 1 << 28; |
| 47 | mmio_write_32(0xf7032000 + 0x050, data); |
| 48 | mmio_write_32(PERI_SC_PERIPH_CTRL14, 0x2101); |
| 49 | mdelay(1); |
| 50 | data = mmio_read_32(PERI_SC_PERIPH_STAT1); |
| 51 | NOTICE("syspll frequency:%dHz\n", data); |
| 52 | } |
| 53 | |
| 54 | static void init_freq(void) |
| 55 | { |
| 56 | unsigned int data, tmp; |
| 57 | unsigned int cpuext_cfg, ddr_cfg; |
| 58 | |
| 59 | mmio_write_32((0xf7032000 + 0x374), 0x4a); |
| 60 | mmio_write_32((0xf7032000 + 0x368), 0xda); |
| 61 | mmio_write_32((0xf7032000 + 0x36c), 0x01); |
| 62 | mmio_write_32((0xf7032000 + 0x370), 0x01); |
| 63 | mmio_write_32((0xf7032000 + 0x360), 0x60); |
| 64 | mmio_write_32((0xf7032000 + 0x364), 0x60); |
| 65 | |
| 66 | mmio_write_32((0xf7032000 + 0x114), 0x1000); |
| 67 | |
| 68 | data = mmio_read_32((0xf7032000 + 0x110)); |
| 69 | data |= (3 << 12); |
| 70 | mmio_write_32((0xf7032000 + 0x110), data); |
| 71 | |
| 72 | data = mmio_read_32((0xf7032000 + 0x110)); |
| 73 | data |= (1 << 4); |
| 74 | mmio_write_32((0xf7032000 + 0x110), data); |
| 75 | |
| 76 | |
| 77 | data = mmio_read_32((0xf7032000 + 0x110)); |
| 78 | data &= ~0x7; |
| 79 | data |= 0x5; |
| 80 | mmio_write_32((0xf7032000 + 0x110), data); |
| 81 | dsb(); |
| 82 | mdelay(10); |
| 83 | |
| 84 | |
| 85 | do { |
| 86 | data = mmio_read_32((0xf6504000 + 0x008)); |
| 87 | data &= (3 << 20); |
| 88 | } while (data != (3 << 20)); |
| 89 | dsb(); |
| 90 | mdelay(10); |
| 91 | |
| 92 | |
| 93 | data = mmio_read_32((0xf6504000 + 0x054)); |
| 94 | data &= ~((1 << 0) | (1 << 11)); |
| 95 | mmio_write_32((0xf6504000 + 0x054), data); |
| 96 | mdelay(10); |
| 97 | |
| 98 | data = mmio_read_32((0xf7032000 + 0x104)); |
| 99 | data &= ~(3 << 8); |
| 100 | data |= (1 << 8); |
| 101 | mmio_write_32((0xf7032000 + 0x104), data); |
| 102 | |
| 103 | data = mmio_read_32((0xf7032000 + 0x100)); |
| 104 | data |= (1 << 0); |
| 105 | mmio_write_32((0xf7032000 + 0x100), data); |
| 106 | dsb(); |
| 107 | |
| 108 | do { |
| 109 | data = mmio_read_32((0xf7032000 + 0x100)); |
| 110 | data &= (1 << 2); |
| 111 | } while (data != (1 << 2)); |
| 112 | |
| 113 | data = mmio_read_32((0xf6504000 + 0x06c)); |
| 114 | data &= ~0xffff; |
| 115 | data |= 0x56; |
| 116 | mmio_write_32((0xf6504000 + 0x06c), data); |
| 117 | |
| 118 | data = mmio_read_32((0xf6504000 + 0x06c)); |
| 119 | data &= ~(0xffffff << 8); |
| 120 | data |= 0xc7a << 8; |
| 121 | mmio_write_32((0xf6504000 + 0x06c), data); |
| 122 | |
| 123 | data = mmio_read_32((0xf6504000 + 0x058)); |
| 124 | data &= ((1 << 13) - 1); |
| 125 | data |= 0xccb; |
| 126 | mmio_write_32((0xf6504000 + 0x058), data); |
| 127 | |
| 128 | mmio_write_32((0xf6504000 + 0x060), 0x1fff); |
| 129 | mmio_write_32((0xf6504000 + 0x064), 0x1ffffff); |
| 130 | mmio_write_32((0xf6504000 + 0x068), 0x7fffffff); |
| 131 | mmio_write_32((0xf6504000 + 0x05c), 0x1); |
| 132 | |
| 133 | data = mmio_read_32((0xf6504000 + 0x054)); |
| 134 | data &= ~(0xf << 12); |
| 135 | data |= 1 << 12; |
| 136 | mmio_write_32((0xf6504000 + 0x054), data); |
| 137 | dsb(); |
| 138 | |
| 139 | |
| 140 | data = mmio_read_32((0xf7032000 + 0x000)); |
| 141 | data &= ~(1 << 0); |
| 142 | mmio_write_32((0xf7032000 + 0x000), data); |
| 143 | |
| 144 | mmio_write_32((0xf7032000 + 0x004), 0x5110207d); |
| 145 | mmio_write_32((0xf7032000 + 0x134), 0x10000005); |
| 146 | data = mmio_read_32((0xf7032000 + 0x134)); |
| 147 | |
| 148 | |
| 149 | data = mmio_read_32((0xf7032000 + 0x000)); |
| 150 | data |= (1 << 0); |
| 151 | mmio_write_32((0xf7032000 + 0x000), data); |
| 152 | |
| 153 | mmio_write_32((0xf7032000 + 0x368), 0x100da); |
| 154 | data = mmio_read_32((0xf7032000 + 0x378)); |
| 155 | data &= ~((1 << 7) - 1); |
| 156 | data |= 0x6b; |
| 157 | mmio_write_32((0xf7032000 + 0x378), data); |
| 158 | dsb(); |
| 159 | do { |
| 160 | data = mmio_read_32((0xf7032000 + 0x378)); |
| 161 | tmp = data & 0x7f; |
| 162 | data = (data & (0x7f << 8)) >> 8; |
| 163 | if (data != tmp) |
| 164 | continue; |
| 165 | data = mmio_read_32((0xf7032000 + 0x37c)); |
| 166 | } while (!(data & 1)); |
| 167 | |
| 168 | data = mmio_read_32((0xf7032000 + 0x104)); |
| 169 | data &= ~((3 << 0) | |
| 170 | (3 << 8)); |
| 171 | cpuext_cfg = 1; |
| 172 | ddr_cfg = 1; |
| 173 | data |= cpuext_cfg | (ddr_cfg << 8); |
| 174 | mmio_write_32((0xf7032000 + 0x104), data); |
| 175 | dsb(); |
| 176 | |
| 177 | do { |
| 178 | data = mmio_read_32((0xf7032000 + 0x104)); |
| 179 | tmp = (data & (3 << 16)) >> 16; |
| 180 | if (cpuext_cfg != tmp) |
| 181 | continue; |
| 182 | tmp = (data & (3 << 24)) >> 24; |
| 183 | if (ddr_cfg != tmp) |
| 184 | continue; |
| 185 | data = mmio_read_32((0xf7032000 + 0x000)); |
| 186 | data &= 1 << 28; |
| 187 | } while (!data); |
| 188 | |
| 189 | data = mmio_read_32((0xf7032000 + 0x100)); |
| 190 | data &= ~(1 << 0); |
| 191 | mmio_write_32((0xf7032000 + 0x100), data); |
| 192 | dsb(); |
| 193 | do { |
| 194 | data = mmio_read_32((0xf7032000 + 0x100)); |
| 195 | data &= (1 << 1); |
| 196 | } while (data != (1 << 1)); |
| 197 | mdelay(1000); |
| 198 | |
| 199 | data = mmio_read_32((0xf6504000 + 0x054)); |
| 200 | data &= ~(1 << 28); |
| 201 | mmio_write_32((0xf6504000 + 0x054), data); |
| 202 | dsb(); |
| 203 | |
| 204 | data = mmio_read_32((0xf7032000 + 0x110)); |
| 205 | data &= ~((1 << 4) | |
| 206 | (3 << 12)); |
| 207 | mmio_write_32((0xf7032000 + 0x110), data); |
| 208 | } |
| 209 | |
| 210 | int cat_533mhz_800mhz(void) |
| 211 | { |
| 212 | unsigned int data, i; |
| 213 | unsigned int bdl[5]; |
| 214 | |
| 215 | |
| 216 | data = mmio_read_32((0xf712c000 + 0x1c8)); |
| 217 | data &= 0xfffff0f0; |
| 218 | data |= 0x100f0f; |
| 219 | mmio_write_32((0xf712c000 + 0x1c8), data); |
| 220 | |
| 221 | for (i = 0; i < 0x20; i++) { |
| 222 | mmio_write_32((0xf712c000 + 0x1d4), 0xc0000); |
| 223 | data = (i << 0x10) + i; |
| 224 | mmio_write_32((0xf712c000 + 0x140), data); |
| 225 | mmio_write_32((0xf712c000 + 0x144), data); |
| 226 | mmio_write_32((0xf712c000 + 0x148), data); |
| 227 | mmio_write_32((0xf712c000 + 0x14c), data); |
| 228 | mmio_write_32((0xf712c000 + 0x150), data); |
| 229 | |
| 230 | |
| 231 | data = mmio_read_32((0xf712c000 + 0x070)); |
| 232 | data |= 0x80000; |
| 233 | mmio_write_32((0xf712c000 + 0x070), data); |
| 234 | data = mmio_read_32((0xf712c000 + 0x070)); |
| 235 | data &= 0xfff7ffff; |
| 236 | mmio_write_32((0xf712c000 + 0x070), data); |
| 237 | |
| 238 | |
| 239 | mmio_write_32((0xf712c000 + 0x004), 0x8000); |
| 240 | mmio_write_32((0xf712c000 + 0x004), 0x0); |
| 241 | mmio_write_32((0xf712c000 + 0x004), 0x801); |
| 242 | do { |
| 243 | data = mmio_read_32((0xf712c000 + 0x004)); |
| 244 | } while (data & 1); |
| 245 | |
| 246 | data = mmio_read_32((0xf712c000 + 0x008)); |
| 247 | if (!(data & 0x400)) { |
| 248 | mdelay(10); |
| 249 | return 0; |
| 250 | } |
| 251 | WARN("lpddr3 cat fail\n"); |
| 252 | data = mmio_read_32((0xf712c000 + 0x1d4)); |
| 253 | if ((data & 0x1f00) && ((data & 0x1f) == 0)) { |
| 254 | bdl[0] = mmio_read_32((0xf712c000 + 0x140)); |
| 255 | bdl[1] = mmio_read_32((0xf712c000 + 0x144)); |
| 256 | bdl[2] = mmio_read_32((0xf712c000 + 0x148)); |
| 257 | bdl[3] = mmio_read_32((0xf712c000 + 0x14c)); |
| 258 | bdl[4] = mmio_read_32((0xf712c000 + 0x150)); |
| 259 | if ((!(bdl[0] & 0x1f001f)) || (!(bdl[1] & 0x1f001f)) || |
| 260 | (!(bdl[2] & 0x1f001f)) || (!(bdl[3] & 0x1f001f)) || |
| 261 | (!(bdl[4] & 0x1f001f))) { |
| 262 | WARN("lpddr3 cat deskew error\n"); |
| 263 | if (i == 0x1f) { |
| 264 | WARN("addrnbdl is max\n"); |
| 265 | return -EINVAL; |
| 266 | } |
| 267 | mmio_write_32((0xf712c000 + 0x008), 0x400); |
| 268 | } else { |
| 269 | WARN("lpddr3 cat other error1\n"); |
| 270 | return -EINVAL; |
| 271 | } |
| 272 | } else { |
| 273 | WARN("lpddr3 cat other error2\n"); |
| 274 | return -EINVAL; |
| 275 | } |
| 276 | } |
| 277 | return -EINVAL; |
| 278 | } |
| 279 | |
| 280 | static void ddrx_rdet(void) |
| 281 | { |
| 282 | unsigned int data, rdet, bdl[4]; |
| 283 | |
| 284 | data = mmio_read_32((0xf712c000 + 0x0d0)); |
| 285 | data &= 0xf800ffff; |
| 286 | data |= 0x8f0000; |
| 287 | mmio_write_32((0xf712c000 + 0x0d0), data); |
| 288 | |
| 289 | data = mmio_read_32((0xf712c000 + 0x0dc)); |
| 290 | data &= 0xfffffff0; |
| 291 | data |= 0xf; |
| 292 | mmio_write_32((0xf712c000 + 0x0dc), data); |
| 293 | |
| 294 | |
| 295 | data = mmio_read_32((0xf712c000 + 0x070)); |
| 296 | data |= 0x80000; |
| 297 | mmio_write_32((0xf712c000 + 0x070), data); |
| 298 | data = mmio_read_32((0xf712c000 + 0x070)); |
| 299 | data &= 0xfff7ffff; |
| 300 | mmio_write_32((0xf712c000 + 0x070), data); |
| 301 | |
| 302 | mmio_write_32((0xf712c000 + 0x004), 0x8000); |
| 303 | mmio_write_32((0xf712c000 + 0x004), 0); |
| 304 | |
| 305 | data = mmio_read_32((0xf712c000 + 0x0d0)); |
| 306 | data &= ~0xf0000000; |
| 307 | data |= 0x80000000; |
| 308 | mmio_write_32((0xf712c000 + 0x0d0), data); |
| 309 | |
| 310 | mmio_write_32((0xf712c000 + 0x004), 0x101); |
| 311 | do { |
| 312 | data = mmio_read_32((0xf712c000 + 0x004)); |
| 313 | } while (!(data & 1)); |
| 314 | data = mmio_read_32((0xf712c000 + 0x008)); |
| 315 | if (data & 0x100) |
| 316 | WARN("rdet lbs fail\n"); |
| 317 | |
| 318 | bdl[0] = mmio_read_32((0xf712c000 + 0x22c)) & 0x7f; |
| 319 | bdl[1] = mmio_read_32((0xf712c000 + 0x2ac)) & 0x7f; |
| 320 | bdl[2] = mmio_read_32((0xf712c000 + 0x32c)) & 0x7f; |
| 321 | bdl[3] = mmio_read_32((0xf712c000 + 0x3ac)) & 0x7f; |
| 322 | do { |
| 323 | data = mmio_read_32((0xf712c000 + 0x22c)); |
| 324 | data &= ~0x7f; |
| 325 | data |= bdl[0]; |
| 326 | mmio_write_32((0xf712c000 + 0x22c), data); |
| 327 | data = mmio_read_32((0xf712c000 + 0x2ac)); |
| 328 | data &= ~0x7f; |
| 329 | data |= bdl[1]; |
| 330 | mmio_write_32((0xf712c000 + 0x2ac), data); |
| 331 | data = mmio_read_32((0xf712c000 + 0x32c)); |
| 332 | data &= ~0x7f; |
| 333 | data |= bdl[2]; |
| 334 | mmio_write_32((0xf712c000 + 0x32c), data); |
| 335 | data = mmio_read_32((0xf712c000 + 0x3ac)); |
| 336 | data &= ~0x7f; |
| 337 | data |= bdl[3]; |
| 338 | mmio_write_32((0xf712c000 + 0x3ac), data); |
| 339 | |
| 340 | |
| 341 | data = mmio_read_32((0xf712c000 + 0x070)); |
| 342 | data |= 0x80000; |
| 343 | mmio_write_32((0xf712c000 + 0x070), data); |
| 344 | data = mmio_read_32((0xf712c000 + 0x070)); |
| 345 | data &= 0xfff7ffff; |
| 346 | mmio_write_32((0xf712c000 + 0x070), data); |
| 347 | |
| 348 | mmio_write_32((0xf712c000 + 0x004), 0x8000); |
| 349 | mmio_write_32((0xf712c000 + 0x004), 0); |
| 350 | |
| 351 | data = mmio_read_32((0xf712c000 + 0x0d0)); |
| 352 | data &= ~0xf0000000; |
| 353 | data |= 0x40000000; |
| 354 | mmio_write_32((0xf712c000 + 0x0d0), data); |
| 355 | mmio_write_32((0xf712c000 + 0x004), 0x101); |
| 356 | do { |
| 357 | data = mmio_read_32((0xf712c000 + 0x004)); |
| 358 | } while (data & 1); |
| 359 | |
| 360 | data = mmio_read_32((0xf712c000 + 0x008)); |
| 361 | rdet = data & 0x100; |
| 362 | if (rdet) { |
| 363 | INFO("rdet ds fail\n"); |
| 364 | mmio_write_32((0xf712c000 + 0x008), 0x100); |
| 365 | } |
| 366 | bdl[0]++; |
| 367 | bdl[1]++; |
| 368 | bdl[2]++; |
| 369 | bdl[3]++; |
| 370 | } while (rdet); |
| 371 | |
| 372 | data = mmio_read_32((0xf712c000 + 0x0d0)); |
| 373 | data &= ~0xf0000000; |
| 374 | data |= 0x30000000; |
| 375 | mmio_write_32((0xf712c000 + 0x0d0), data); |
| 376 | |
| 377 | mmio_write_32((0xf712c000 + 0x004), 0x101); |
| 378 | do { |
| 379 | data = mmio_read_32((0xf712c000 + 0x004)); |
| 380 | } while (data & 1); |
| 381 | data = mmio_read_32((0xf712c000 + 0x008)); |
| 382 | if (data & 0x100) |
| 383 | INFO("rdet rbs av fail\n"); |
| 384 | } |
| 385 | |
| 386 | static void ddrx_wdet(void) |
| 387 | { |
Haojian Zhuang | 6ffe56c | 2017-05-31 12:42:10 +0800 | [diff] [blame] | 388 | unsigned int data, wdet, zero_bdl = 0, dq[4]; |
Haojian Zhuang | 934ae71 | 2017-05-24 08:47:49 +0800 | [diff] [blame] | 389 | int i; |
| 390 | |
| 391 | data = mmio_read_32((0xf712c000 + 0x0d0)); |
| 392 | data &= ~0xf; |
| 393 | data |= 0xf; |
| 394 | mmio_write_32((0xf712c000 + 0x0d0), data); |
| 395 | |
| 396 | data = mmio_read_32((0xf712c000 + 0x070)); |
| 397 | data |= 0x80000; |
| 398 | mmio_write_32((0xf712c000 + 0x070), data); |
| 399 | data = mmio_read_32((0xf712c000 + 0x070)); |
| 400 | data &= ~0x80000; |
| 401 | mmio_write_32((0xf712c000 + 0x070), data); |
| 402 | |
| 403 | mmio_write_32((0xf712c000 + 0x004), 0x8000); |
| 404 | mmio_write_32((0xf712c000 + 0x004), 0); |
| 405 | data = mmio_read_32((0xf712c000 + 0x0d0)); |
| 406 | data &= ~0xf000; |
| 407 | data |= 0x8000; |
| 408 | mmio_write_32((0xf712c000 + 0x0d0), data); |
| 409 | mmio_write_32((0xf712c000 + 0x004), 0x201); |
| 410 | do { |
| 411 | data = mmio_read_32((0xf712c000 + 0x004)); |
| 412 | } while (data & 1); |
| 413 | data = mmio_read_32((0xf712c000 + 0x008)); |
| 414 | if (data & 0x200) |
| 415 | INFO("wdet lbs fail\n"); |
| 416 | |
| 417 | dq[0] = mmio_read_32((0xf712c000 + 0x234)) & 0x1f00; |
| 418 | dq[1] = mmio_read_32((0xf712c000 + 0x2b4)) & 0x1f00; |
| 419 | dq[2] = mmio_read_32((0xf712c000 + 0x334)) & 0x1f00; |
| 420 | dq[3] = mmio_read_32((0xf712c000 + 0x3b4)) & 0x1f00; |
| 421 | |
| 422 | do { |
| 423 | mmio_write_32((0xf712c000 + 0x234), dq[0]); |
| 424 | mmio_write_32((0xf712c000 + 0x2b4), dq[1]); |
| 425 | mmio_write_32((0xf712c000 + 0x334), dq[2]); |
| 426 | mmio_write_32((0xf712c000 + 0x3b4), dq[3]); |
| 427 | |
| 428 | data = mmio_read_32((0xf712c000 + 0x070)); |
| 429 | data |= 0x80000; |
| 430 | mmio_write_32((0xf712c000 + 0x070), data); |
| 431 | data = mmio_read_32((0xf712c000 + 0x070)); |
| 432 | data &= ~0x80000; |
| 433 | mmio_write_32((0xf712c000 + 0x070), data); |
| 434 | mmio_write_32((0xf712c000 + 0x004), 0x8000); |
| 435 | mmio_write_32((0xf712c000 + 0x004), 0); |
| 436 | |
| 437 | data = mmio_read_32((0xf712c000 + 0x0d0)); |
| 438 | data &= ~0xf000; |
| 439 | data |= 0x4000; |
| 440 | mmio_write_32((0xf712c000 + 0x0d0), data); |
| 441 | mmio_write_32((0xf712c000 + 0x004), 0x201); |
| 442 | do { |
| 443 | data = mmio_read_32((0xf712c000 + 0x004)); |
| 444 | } while (data & 1); |
| 445 | |
| 446 | data = mmio_read_32((0xf712c000 + 0x008)); |
| 447 | wdet = data & 0x200; |
| 448 | if (wdet) { |
| 449 | INFO("wdet ds fail\n"); |
| 450 | mmio_write_32((0xf712c000 + 0x008), 0x200); |
| 451 | } |
| 452 | mdelay(10); |
| 453 | |
| 454 | for (i = 0; i < 4; i++) { |
| 455 | data = mmio_read_32((0xf712c000 + 0x210 + i * 0x80)); |
| 456 | if ((!(data & 0x1f)) || (!(data & 0x1f00)) || |
Haojian Zhuang | 6ffe56c | 2017-05-31 12:42:10 +0800 | [diff] [blame] | 457 | (!(data & 0x1f0000)) || (!(data & 0x1f000000))) |
Haojian Zhuang | 934ae71 | 2017-05-24 08:47:49 +0800 | [diff] [blame] | 458 | zero_bdl = 1; |
| 459 | data = mmio_read_32((0xf712c000 + 0x214 + i * 0x80)); |
| 460 | if ((!(data & 0x1f)) || (!(data & 0x1f00)) || |
Haojian Zhuang | 6ffe56c | 2017-05-31 12:42:10 +0800 | [diff] [blame] | 461 | (!(data & 0x1f0000)) || (!(data & 0x1f000000))) |
Haojian Zhuang | 934ae71 | 2017-05-24 08:47:49 +0800 | [diff] [blame] | 462 | zero_bdl = 1; |
| 463 | data = mmio_read_32((0xf712c000 + 0x218 + i * 0x80)); |
| 464 | if (!(data & 0x1f)) |
| 465 | zero_bdl = 1; |
| 466 | if (zero_bdl) { |
| 467 | if (i == 0) |
| 468 | dq[0] = dq[0] - 0x100; |
| 469 | if (i == 1) |
| 470 | dq[1] = dq[1] - 0x100; |
| 471 | if (i == 2) |
| 472 | dq[2] = dq[2] - 0x100; |
| 473 | if (i == 3) |
| 474 | dq[3] = dq[3] - 0x100; |
| 475 | } |
| 476 | } |
| 477 | } while (wdet); |
| 478 | |
| 479 | data = mmio_read_32((0xf712c000 + 0x0d0)); |
| 480 | data &= ~0xf000; |
| 481 | data |= 0x3000; |
| 482 | mmio_write_32((0xf712c000 + 0x0d0), data); |
| 483 | mmio_write_32((0xf712c000 + 0x004), 0x201); |
| 484 | do { |
| 485 | data = mmio_read_32((0xf712c000 + 0x004)); |
| 486 | } while (data & 1); |
| 487 | data = mmio_read_32((0xf712c000 + 0x008)); |
| 488 | if (data & 0x200) |
| 489 | INFO("wdet rbs av fail\n"); |
| 490 | } |
| 491 | |
| 492 | static void set_ddrc_533mhz(void) |
| 493 | { |
| 494 | unsigned int data; |
| 495 | |
| 496 | mmio_write_32((0xf7032000 + 0x580), 0x3); |
| 497 | mmio_write_32((0xf7032000 + 0x5a8), 0x11111); |
| 498 | data = mmio_read_32((0xf7032000 + 0x104)); |
| 499 | data |= 0x100; |
| 500 | mmio_write_32((0xf7032000 + 0x104), data); |
| 501 | |
| 502 | mmio_write_32((0xf7030000 + 0x050), 0x30); |
| 503 | mmio_write_32((0xf7030000 + 0x240), 0x5ffff); |
| 504 | mmio_write_32((0xf7030000 + 0x344), 0xf5ff); |
| 505 | mmio_write_32((0xf712c000 + 0x00c), 0x400); |
| 506 | mmio_write_32((0xf712c000 + 0x018), 0x7); |
| 507 | mmio_write_32((0xf712c000 + 0x090), 0x6400000); |
| 508 | mmio_write_32((0xf712c000 + 0x258), 0x640); |
| 509 | mmio_write_32((0xf712c000 + 0x2d8), 0x640); |
| 510 | mmio_write_32((0xf712c000 + 0x358), 0x640); |
| 511 | mmio_write_32((0xf712c000 + 0x3d8), 0x640); |
| 512 | mmio_write_32((0xf712c000 + 0x018), 0x0); |
| 513 | mmio_write_32((0xf712c000 + 0x0b0), 0xf00000f); |
| 514 | mmio_write_32((0xf712c000 + 0x0b4), 0xf); |
| 515 | mmio_write_32((0xf712c000 + 0x088), 0x3fff801); |
| 516 | mmio_write_32((0xf712c000 + 0x070), 0x8940000); |
| 517 | |
| 518 | data = mmio_read_32((0xf712c000 + 0x078)); |
| 519 | data |= 4; |
| 520 | mmio_write_32((0xf712c000 + 0x078), data); |
| 521 | mmio_write_32((0xf712c000 + 0x01c), 0x8000080); |
| 522 | data = mmio_read_32((0xf712c000 + 0x020)); |
| 523 | data &= 0xfffffffe; |
| 524 | mmio_write_32((0xf712c000 + 0x020), data); |
| 525 | mmio_write_32((0xf712c000 + 0x1d4), 0xc0000); |
| 526 | mmio_write_32((0xf712c000 + 0x010), 0x500000f); |
| 527 | mmio_write_32((0xf712c000 + 0x014), 0x10); |
| 528 | data = mmio_read_32((0xf712c000 + 0x1e4)); |
| 529 | data &= 0xffffff00; |
| 530 | mmio_write_32((0xf712c000 + 0x1e4), data); |
| 531 | mmio_write_32((0xf712c000 + 0x030), 0x9dd87855); |
| 532 | mmio_write_32((0xf712c000 + 0x034), 0xa7138bb); |
| 533 | mmio_write_32((0xf712c000 + 0x038), 0x20091477); |
| 534 | mmio_write_32((0xf712c000 + 0x03c), 0x84534e16); |
| 535 | mmio_write_32((0xf712c000 + 0x040), 0x3008817); |
| 536 | mmio_write_32((0xf712c000 + 0x064), 0x106c3); |
| 537 | mmio_write_32((0xf712c000 + 0x068), 0xff0a0000); |
| 538 | data = mmio_read_32((0xf712c000 + 0x070)); |
| 539 | data &= 0xffff0000; |
| 540 | data |= 0x305; |
| 541 | mmio_write_32((0xf712c000 + 0x070), data); |
| 542 | data = mmio_read_32((0xf712c000 + 0x048)); |
| 543 | data |= 0x40000000; |
| 544 | mmio_write_32((0xf712c000 + 0x048), data); |
| 545 | data = mmio_read_32((0xf712c000 + 0x020)); |
| 546 | data &= ~0x10; |
| 547 | mmio_write_32((0xf712c000 + 0x020), data); |
| 548 | data = mmio_read_32((0xf712c000 + 0x080)); |
| 549 | data &= ~0x2000; |
| 550 | mmio_write_32((0xf712c000 + 0x080), data); |
| 551 | mmio_write_32((0xf712c000 + 0x270), 0x3); |
| 552 | mmio_write_32((0xf712c000 + 0x2f0), 0x3); |
| 553 | mmio_write_32((0xf712c000 + 0x370), 0x3); |
| 554 | mmio_write_32((0xf712c000 + 0x3f0), 0x3); |
| 555 | mmio_write_32((0xf712c000 + 0x048), 0xd0420900); |
| 556 | |
| 557 | mmio_write_32((0xf7128000 + 0x040), 0x0); |
| 558 | mmio_write_32((0xf712c000 + 0x004), 0x140f); |
| 559 | do { |
| 560 | data = mmio_read_32((0xf712c000 + 0x004)); |
| 561 | } while (data & 1); |
| 562 | data = mmio_read_32((0xf712c000 + 0x008)); |
| 563 | if (data & 0x7fe) { |
| 564 | NOTICE("failed to init lpddr3 rank0 dram phy\n"); |
| 565 | return; |
| 566 | } |
| 567 | NOTICE("succeed to init lpddr3 rank0 dram phy\n"); |
| 568 | } |
| 569 | |
| 570 | static void set_ddrc_800mhz(void) |
| 571 | { |
| 572 | unsigned int data; |
| 573 | |
| 574 | mmio_write_32((0xf7032000 + 0x580), 0x2); |
| 575 | mmio_write_32((0xf7032000 + 0x5a8), 0x1003); |
| 576 | data = mmio_read_32((0xf7032000 + 0x104)); |
| 577 | data &= 0xfffffcff; |
| 578 | mmio_write_32((0xf7032000 + 0x104), data); |
| 579 | |
| 580 | mmio_write_32((0xf7030000 + 0x050), 0x30); |
| 581 | mmio_write_32((0xf7030000 + 0x240), 0x5ffff); |
| 582 | mmio_write_32((0xf7030000 + 0x344), 0xf5ff); |
| 583 | mmio_write_32((0xf712c000 + 0x00c), 0x400); |
| 584 | mmio_write_32((0xf712c000 + 0x018), 0x7); |
| 585 | mmio_write_32((0xf712c000 + 0x090), 0x5400000); |
| 586 | mmio_write_32((0xf712c000 + 0x258), 0x540); |
| 587 | mmio_write_32((0xf712c000 + 0x2d8), 0x540); |
| 588 | mmio_write_32((0xf712c000 + 0x358), 0x540); |
| 589 | mmio_write_32((0xf712c000 + 0x3d8), 0x540); |
| 590 | mmio_write_32((0xf712c000 + 0x018), 0x0); |
| 591 | mmio_write_32((0xf712c000 + 0x0b0), 0xf00000f); |
| 592 | mmio_write_32((0xf712c000 + 0x0b4), 0xf); |
| 593 | mmio_write_32((0xf712c000 + 0x088), 0x3fff801); |
| 594 | mmio_write_32((0xf712c000 + 0x070), 0x8940000); |
| 595 | |
| 596 | data = mmio_read_32((0xf712c000 + 0x078)); |
| 597 | data |= 4; |
| 598 | mmio_write_32((0xf712c000 + 0x078), data); |
| 599 | mmio_write_32((0xf712c000 + 0x01c), 0x8000080); |
| 600 | data = mmio_read_32((0xf712c000 + 0x020)); |
| 601 | data &= 0xfffffffe; |
| 602 | mmio_write_32((0xf712c000 + 0x020), data); |
| 603 | mmio_write_32((0xf712c000 + 0x1d4), 0xc0000); |
| 604 | mmio_write_32((0xf712c000 + 0x010), 0x500000f); |
| 605 | mmio_write_32((0xf712c000 + 0x014), 0x10); |
| 606 | data = mmio_read_32((0xf712c000 + 0x1e4)); |
| 607 | data &= 0xffffff00; |
| 608 | mmio_write_32((0xf712c000 + 0x1e4), data); |
| 609 | mmio_write_32((0xf712c000 + 0x030), 0xe663ab77); |
| 610 | mmio_write_32((0xf712c000 + 0x034), 0xea952db); |
| 611 | mmio_write_32((0xf712c000 + 0x038), 0x200d1cb1); |
| 612 | mmio_write_32((0xf712c000 + 0x03c), 0xc67d0721); |
| 613 | mmio_write_32((0xf712c000 + 0x040), 0x3008aa1); |
| 614 | mmio_write_32((0xf712c000 + 0x064), 0x11a43); |
| 615 | mmio_write_32((0xf712c000 + 0x068), 0xff0a0000); |
| 616 | data = mmio_read_32((0xf712c000 + 0x070)); |
| 617 | data &= 0xffff0000; |
| 618 | data |= 0x507; |
| 619 | mmio_write_32((0xf712c000 + 0x070), data); |
| 620 | data = mmio_read_32((0xf712c000 + 0x048)); |
| 621 | data |= 0x40000000; |
| 622 | mmio_write_32((0xf712c000 + 0x048), data); |
| 623 | data = mmio_read_32((0xf712c000 + 0x020)); |
| 624 | data &= 0xffffffef; |
| 625 | mmio_write_32((0xf712c000 + 0x020), data); |
| 626 | data = mmio_read_32((0xf712c000 + 0x080)); |
| 627 | data &= 0xffffdfff; |
| 628 | mmio_write_32((0xf712c000 + 0x080), data); |
| 629 | mmio_write_32((0xf712c000 + 0x270), 0x3); |
| 630 | mmio_write_32((0xf712c000 + 0x2f0), 0x3); |
| 631 | mmio_write_32((0xf712c000 + 0x370), 0x3); |
| 632 | mmio_write_32((0xf712c000 + 0x3f0), 0x3); |
| 633 | mmio_write_32((0xf712c000 + 0x048), 0xd0420900); |
| 634 | |
| 635 | mmio_write_32((0xf7128000 + 0x040), 0x2001); |
| 636 | mmio_write_32((0xf712c000 + 0x004), 0x140f); |
| 637 | do { |
| 638 | data = mmio_read_32((0xf712c000 + 0x004)); |
| 639 | } while (data & 1); |
| 640 | data = mmio_read_32((0xf712c000 + 0x008)); |
| 641 | if (data & 0x7fe) { |
| 642 | WARN("failed to init lpddr3 rank0 dram phy\n"); |
| 643 | return; |
| 644 | } |
| 645 | } |
| 646 | |
| 647 | static void ddrc_common_init(int ddr800) |
| 648 | { |
| 649 | unsigned int data; |
| 650 | |
| 651 | mmio_write_32((0xf7120000 + 0x020), 0x1); |
| 652 | mmio_write_32((0xf7120000 + 0x100), 0x1700); |
| 653 | mmio_write_32((0xf7120000 + 0x104), 0x71040004); |
| 654 | mmio_write_32((0xf7121400 + 0x104), 0xf); |
| 655 | mmio_write_32((0xf7121800 + 0x104), 0xf); |
| 656 | mmio_write_32((0xf7121800 + 0x104), 0xf); |
| 657 | mmio_write_32((0xf7121c00 + 0x104), 0xf); |
| 658 | mmio_write_32((0xf7122000 + 0x104), 0xf); |
| 659 | mmio_write_32((0xf7128000 + 0x02c), 0x6); |
| 660 | mmio_write_32((0xf7128000 + 0x020), 0x1); |
| 661 | mmio_write_32((0xf7128000 + 0x028), 0x310201); |
| 662 | mmio_write_32((0xf712c000 + 0x1e4), 0xfe007600); |
| 663 | mmio_write_32((0xf7128000 + 0x01c), 0xaf001); |
| 664 | |
| 665 | |
| 666 | data = mmio_read_32((0xf7128000 + 0x280)); |
| 667 | data |= 1 << 7; |
| 668 | mmio_write_32((0xf7128000 + 0x280), data); |
| 669 | mmio_write_32((0xf7128000 + 0x244), 0x3); |
| 670 | |
| 671 | if (ddr800) |
| 672 | mmio_write_32((0xf7128000 + 0x240), 167 * 400000 / 1024); |
| 673 | else |
| 674 | mmio_write_32((0xf7128000 + 0x240), 167 * 533000 / 1024); |
| 675 | |
| 676 | data = mmio_read_32((0xf712c000 + 0x080)); |
| 677 | data &= 0xffff; |
| 678 | data |= 0x4002000; |
| 679 | mmio_write_32((0xf712c000 + 0x080), data); |
| 680 | mmio_write_32((0xf7128000 + 0x000), 0x0); |
| 681 | do { |
| 682 | data = mmio_read_32((0xf7128000 + 0x294)); |
| 683 | } while (data & 1); |
| 684 | mmio_write_32((0xf7128000 + 0x000), 0x2); |
| 685 | } |
| 686 | |
| 687 | |
| 688 | static int dienum_det_and_rowcol_cfg(void) |
| 689 | { |
| 690 | unsigned int data; |
| 691 | |
| 692 | mmio_write_32((0xf7128000 + 0x210), 0x87); |
| 693 | mmio_write_32((0xf7128000 + 0x218), 0x10000); |
| 694 | mmio_write_32((0xf7128000 + 0x00c), 0x1); |
| 695 | do { |
| 696 | data = mmio_read_32((0xf7128000 + 0x00c)); |
| 697 | } while (data & 1); |
| 698 | data = mmio_read_32((0xf7128000 + 0x4a8)) & 0xfc; |
| 699 | switch (data) { |
| 700 | case 0x18: |
| 701 | mmio_write_32((0xf7128000 + 0x060), 0x132); |
| 702 | mmio_write_32((0xf7128000 + 0x064), 0x132); |
| 703 | mmio_write_32((0xf7120000 + 0x100), 0x1600); |
| 704 | mmio_write_32((0xf7120000 + 0x104), 0x71040004); |
| 705 | break; |
| 706 | case 0x1c: |
| 707 | mmio_write_32((0xf7128000 + 0x060), 0x142); |
| 708 | mmio_write_32((0xf7128000 + 0x064), 0x142); |
| 709 | mmio_write_32((0xf7120000 + 0x100), 0x1700); |
| 710 | mmio_write_32((0xf7120000 + 0x104), 0x71040004); |
| 711 | break; |
| 712 | case 0x58: |
| 713 | mmio_write_32((0xf7128000 + 0x060), 0x133); |
| 714 | mmio_write_32((0xf7128000 + 0x064), 0x133); |
| 715 | mmio_write_32((0xf7120000 + 0x100), 0x1700); |
| 716 | mmio_write_32((0xf7120000 + 0x104), 0x71040004); |
| 717 | break; |
| 718 | default: |
| 719 | break; |
| 720 | } |
| 721 | if (!data) |
| 722 | return -EINVAL; |
| 723 | return 0; |
| 724 | } |
| 725 | |
| 726 | static int detect_ddr_chip_info(void) |
| 727 | { |
| 728 | unsigned int data, mr5, mr6, mr7; |
| 729 | |
| 730 | mmio_write_32((0xf7128000 + 0x210), 0x57); |
| 731 | mmio_write_32((0xf7128000 + 0x218), 0x10000); |
| 732 | mmio_write_32((0xf7128000 + 0x00c), 0x1); |
| 733 | |
| 734 | do { |
| 735 | data = mmio_read_32((0xf7128000 + 0x00c)); |
| 736 | } while (data & 1); |
| 737 | |
| 738 | data = mmio_read_32((0xf7128000 + 0x4a8)); |
| 739 | mr5 = data & 0xff; |
| 740 | switch (mr5) { |
| 741 | case 1: |
| 742 | INFO("Samsung DDR\n"); |
| 743 | break; |
| 744 | case 6: |
| 745 | INFO("Hynix DDR\n"); |
| 746 | break; |
| 747 | case 3: |
| 748 | INFO("Elpida DDR\n"); |
| 749 | break; |
| 750 | default: |
| 751 | INFO("DDR from other vendors\n"); |
| 752 | break; |
| 753 | } |
| 754 | |
| 755 | mmio_write_32((0xf7128000 + 0x210), 0x67); |
| 756 | mmio_write_32((0xf7128000 + 0x218), 0x10000); |
| 757 | mmio_write_32((0xf7128000 + 0x00c), 0x1); |
| 758 | do { |
| 759 | data = mmio_read_32((0xf7128000 + 0x00c)); |
| 760 | } while (data & 1); |
| 761 | data = mmio_read_32((0xf7128000 + 0x4a8)); |
| 762 | mr6 = data & 0xff; |
| 763 | mmio_write_32((0xf7128000 + 0x210), 0x77); |
| 764 | mmio_write_32((0xf7128000 + 0x218), 0x10000); |
| 765 | mmio_write_32((0xf7128000 + 0x00c), 0x1); |
| 766 | do { |
| 767 | data = mmio_read_32((0xf7128000 + 0x00c)); |
| 768 | } while (data & 1); |
| 769 | data = mmio_read_32((0xf7128000 + 0x4a8)); |
| 770 | mr7 = data & 0xff; |
| 771 | data = mr5 + (mr6 << 8) + (mr7 << 16); |
| 772 | return data; |
| 773 | } |
| 774 | |
| 775 | int lpddr3_freq_init(int freq) |
| 776 | { |
| 777 | unsigned int data; |
| 778 | |
| 779 | if (freq == DDR_FREQ_800M) { |
| 780 | set_ddrc_800mhz(); |
| 781 | INFO("%s, set ddrc 800mhz\n", __func__); |
| 782 | } else { |
| 783 | set_ddrc_533mhz(); |
| 784 | INFO("%s, set ddrc 533mhz\n", __func__); |
| 785 | } |
| 786 | |
| 787 | mmio_write_32((0xf712c000 + 0x004), 0xf1); |
| 788 | if (freq == DDR_FREQ_800M) |
| 789 | mmio_write_32((0xf7128000 + 0x050), 0x100023); |
| 790 | else |
| 791 | mmio_write_32((0xf7128000 + 0x050), 0x100123); |
| 792 | mmio_write_32((0xf7128000 + 0x060), 0x133); |
| 793 | mmio_write_32((0xf7128000 + 0x064), 0x133); |
| 794 | mmio_write_32((0xf7128000 + 0x200), 0xa1000); |
| 795 | |
| 796 | if (freq == DDR_FREQ_800M) { |
| 797 | mmio_write_32((0xf7128000 + 0x100), 0x755a9d12); |
| 798 | mmio_write_32((0xf7128000 + 0x104), 0x1753b055); |
| 799 | mmio_write_32((0xf7128000 + 0x108), 0x7401505f); |
| 800 | mmio_write_32((0xf7128000 + 0x10c), 0x578ca244); |
| 801 | mmio_write_32((0xf7128000 + 0x110), 0x10700000); |
| 802 | mmio_write_32((0xf7128000 + 0x114), 0x13141306); |
| 803 | } else { |
| 804 | mmio_write_32((0xf7128000 + 0x100), 0xb77b6718); |
| 805 | mmio_write_32((0xf7128000 + 0x104), 0x1e82a071); |
| 806 | mmio_write_32((0xf7128000 + 0x108), 0x9501c07e); |
| 807 | mmio_write_32((0xf7128000 + 0x10c), 0xaf50c255); |
| 808 | mmio_write_32((0xf7128000 + 0x110), 0x10b00000); |
| 809 | mmio_write_32((0xf7128000 + 0x114), 0x13181908); |
| 810 | } |
| 811 | mmio_write_32((0xf7128000 + 0x118), 0x44); |
| 812 | do { |
| 813 | data = mmio_read_32((0xf712c000 + 0x004)); |
| 814 | } while (data & 1); |
| 815 | |
| 816 | data = mmio_read_32((0xf712c000 + 0x008)); |
| 817 | if (data & 0x7fe) { |
| 818 | NOTICE("fail to init ddr3 rank0\n"); |
| 819 | return -EFAULT; |
| 820 | } |
| 821 | INFO("init ddr3 rank0\n"); |
| 822 | ddrx_rdet(); |
| 823 | ddrx_wdet(); |
| 824 | |
| 825 | data = mmio_read_32((0xf712c000 + 0x048)); |
| 826 | data |= 1; |
| 827 | mmio_write_32((0xf712c000 + 0x048), data); |
| 828 | mmio_write_32((0xf712c000 + 0x004), 0x21); |
| 829 | do { |
| 830 | data = mmio_read_32((0xf712c000 + 0x004)); |
| 831 | } while (data & 1); |
| 832 | |
| 833 | data = mmio_read_32((0xf712c000 + 0x008)); |
| 834 | if (data & 0x7fe) |
| 835 | NOTICE("ddr3 rank1 init failure\n"); |
| 836 | else |
| 837 | INFO("ddr3 rank1 init pass\n"); |
| 838 | |
| 839 | data = mmio_read_32((0xf712c000 + 0x048)); |
| 840 | data &= ~0xf; |
| 841 | mmio_write_32((0xf712c000 + 0x048), data); |
| 842 | return 0; |
| 843 | } |
| 844 | |
| 845 | static void init_ddr(int freq) |
| 846 | { |
| 847 | unsigned int data; |
| 848 | int ret; |
| 849 | |
| 850 | |
| 851 | data = mmio_read_32((0xf7032000 + 0x030)); |
| 852 | data |= 1; |
| 853 | mmio_write_32((0xf7032000 + 0x030), data); |
| 854 | data = mmio_read_32((0xf7032000 + 0x010)); |
| 855 | data |= 1; |
| 856 | mmio_write_32((0xf7032000 + 0x010), data); |
| 857 | |
| 858 | udelay(100); |
| 859 | do { |
| 860 | data = mmio_read_32((0xf7032000 + 0x030)); |
| 861 | data &= 3 << 28; |
| 862 | } while (data != (3 << 28)); |
| 863 | do { |
| 864 | data = mmio_read_32((0xf7032000 + 0x010)); |
| 865 | data &= 3 << 28; |
| 866 | } while (data != (3 << 28)); |
| 867 | |
| 868 | ret = lpddr3_freq_init(freq); |
| 869 | if (ret) |
| 870 | return; |
| 871 | } |
| 872 | |
| 873 | static void init_ddrc_qos(void) |
| 874 | { |
| 875 | unsigned int port, data; |
| 876 | |
| 877 | mmio_write_32((0xf7124000 + 0x088), 1); |
| 878 | |
| 879 | port = 0; |
| 880 | mmio_write_32((0xf7120000 + 0x200 + port * 0x10), 0x1210); |
| 881 | mmio_write_32((0xf7120000 + 0x204 + port * 0x10), 0x11111111); |
| 882 | mmio_write_32((0xf7120000 + 0x208 + port * 0x10), 0x11111111); |
| 883 | mmio_write_32((0xf7120000 + 0x400 + 0 * 0x10), 0x001d0007); |
| 884 | |
| 885 | for (port = 3; port <= 4; port++) { |
| 886 | mmio_write_32((0xf7120000 + 0x200 + port * 0x10), 0x1210); |
| 887 | mmio_write_32((0xf7120000 + 0x204 + port * 0x10), 0x77777777); |
| 888 | mmio_write_32((0xf7120000 + 0x208 + port * 0x10), 0x77777777); |
| 889 | } |
| 890 | |
| 891 | port = 1; |
| 892 | mmio_write_32((0xf7120000 + 0x200 + port * 0x10), 0x30000); |
| 893 | mmio_write_32((0xf7120000 + 0x204 + port * 0x10), 0x1234567); |
| 894 | mmio_write_32((0xf7120000 + 0x208 + port * 0x10), 0x1234567); |
| 895 | |
| 896 | mmio_write_32((0xf7124000 + 0x1f0), 0); |
| 897 | mmio_write_32((0xf7124000 + 0x0bc), 0x3020100); |
| 898 | mmio_write_32((0xf7124000 + 0x0d0), 0x3020100); |
| 899 | mmio_write_32((0xf7124000 + 0x1f4), 0x01000100); |
| 900 | mmio_write_32((0xf7124000 + 0x08c + 0 * 4), 0xd0670402); |
| 901 | mmio_write_32((0xf7124000 + 0x068 + 0 * 4), 0x31); |
| 902 | mmio_write_32((0xf7124000 + 0x000), 0x7); |
| 903 | |
| 904 | data = mmio_read_32((0xf7124000 + 0x09c)); |
| 905 | data &= ~0xff0000; |
| 906 | data |= 0x400000; |
| 907 | mmio_write_32((0xf7124000 + 0x09c), data); |
| 908 | data = mmio_read_32((0xf7124000 + 0x0ac)); |
| 909 | data &= ~0xff0000; |
| 910 | data |= 0x400000; |
| 911 | mmio_write_32((0xf7124000 + 0x0ac), data); |
| 912 | port = 2; |
| 913 | mmio_write_32((0xf7120000 + 0x200 + port * 0x10), 0x30000); |
| 914 | mmio_write_32((0xf7120000 + 0x204 + port * 0x10), 0x1234567); |
| 915 | mmio_write_32((0xf7120000 + 0x208 + port * 0x10), 0x1234567); |
| 916 | |
| 917 | |
| 918 | mmio_write_32((0xf7124000 + 0x09c), 0xff7fff); |
| 919 | mmio_write_32((0xf7124000 + 0x0a0), 0xff); |
| 920 | mmio_write_32((0xf7124000 + 0x0ac), 0xff7fff); |
| 921 | mmio_write_32((0xf7124000 + 0x0b0), 0xff); |
| 922 | mmio_write_32((0xf7124000 + 0x0bc), 0x3020100); |
| 923 | mmio_write_32((0xf7124000 + 0x0d0), 0x3020100); |
| 924 | } |
| 925 | |
| 926 | static void ddr_phy_reset(void) |
| 927 | { |
| 928 | mmio_write_32(0xf7030340, 0xa000); |
| 929 | mmio_write_32(0xf7030344, 0xa000); |
| 930 | } |
| 931 | |
| 932 | void hikey_ddr_init(void) |
| 933 | { |
| 934 | uint32_t data; |
| 935 | |
| 936 | init_pll(); |
| 937 | init_freq(); |
| 938 | |
| 939 | /* |
| 940 | * Init DDR with 533MHz. Otherwise, DDR initialization |
| 941 | * may fail on 800MHz on some boards. |
| 942 | */ |
| 943 | ddr_phy_reset(); |
| 944 | init_ddr(DDR_FREQ_533M); |
| 945 | /* Init DDR with 800MHz. */ |
| 946 | ddr_phy_reset(); |
| 947 | init_ddr(DDR_FREQ_800M); |
| 948 | |
| 949 | |
| 950 | ddrc_common_init(1); |
| 951 | dienum_det_and_rowcol_cfg(); |
| 952 | detect_ddr_chip_info(); |
| 953 | |
| 954 | data = mmio_read_32(0xf7032000 + 0x010); |
| 955 | data &= ~0x1; |
| 956 | mmio_write_32(0xf7032000 + 0x010, data); |
| 957 | data = mmio_read_32(0xf7032000 + 0x010); |
| 958 | |
| 959 | /* |
| 960 | * Test memory access. Do not use address 0x0 because the compiler |
| 961 | * may assume it is not a valid address and generate incorrect code |
| 962 | * (GCC 4.9.1 without -fno-delete-null-pointer-checks for instance). |
| 963 | */ |
| 964 | mmio_write_32(0x4, 0xa5a55a5a); |
| 965 | INFO("ddr test value:0x%x\n", mmio_read_32(0x4)); |
| 966 | init_ddrc_qos(); |
| 967 | } |