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> |
Haojian Zhuang | e18de67 | 2018-04-11 19:05:32 +0800 | [diff] [blame] | 8 | #include <assert.h> |
Haojian Zhuang | 934ae71 | 2017-05-24 08:47:49 +0800 | [diff] [blame] | 9 | #include <debug.h> |
| 10 | #include <errno.h> |
| 11 | #include <hi6220.h> |
| 12 | #include <hi6553.h> |
Haojian Zhuang | da7109a | 2018-04-11 19:05:59 +0800 | [diff] [blame] | 13 | #include <hisi_sram_map.h> |
Haojian Zhuang | 934ae71 | 2017-05-24 08:47:49 +0800 | [diff] [blame] | 14 | #include <mmio.h> |
| 15 | #include <sp804_delay_timer.h> |
| 16 | |
Haojian Zhuang | e18de67 | 2018-04-11 19:05:32 +0800 | [diff] [blame] | 17 | #include "hikey_private.h" |
Haojian Zhuang | 934ae71 | 2017-05-24 08:47:49 +0800 | [diff] [blame] | 18 | |
| 19 | static void init_pll(void) |
| 20 | { |
| 21 | unsigned int data; |
| 22 | |
| 23 | data = mmio_read_32((0xf7032000 + 0x000)); |
| 24 | data |= 0x1; |
| 25 | mmio_write_32((0xf7032000 + 0x000), data); |
Haojian Zhuang | 934ae71 | 2017-05-24 08:47:49 +0800 | [diff] [blame] | 26 | do { |
| 27 | data = mmio_read_32((0xf7032000 + 0x000)); |
| 28 | } while (!(data & (1 << 28))); |
| 29 | |
| 30 | data = mmio_read_32((0xf7800000 + 0x000)); |
| 31 | data &= ~0x007; |
| 32 | data |= 0x004; |
| 33 | mmio_write_32((0xf7800000 + 0x000), data); |
Haojian Zhuang | 934ae71 | 2017-05-24 08:47:49 +0800 | [diff] [blame] | 34 | do { |
| 35 | data = mmio_read_32((0xf7800000 + 0x014)); |
| 36 | data &= 0x007; |
| 37 | } while (data != 0x004); |
| 38 | |
| 39 | mmio_write_32(PERI_SC_PERIPH_CTRL14, 0x2101); |
Haojian Zhuang | e18de67 | 2018-04-11 19:05:32 +0800 | [diff] [blame] | 40 | dsb(); |
| 41 | isb(); |
| 42 | udelay(10); |
| 43 | mmio_write_32(PERI_SC_PERIPH_CTRL14, 0x2001); |
| 44 | dsb(); |
| 45 | isb(); |
| 46 | udelay(10); |
| 47 | mmio_write_32(PERI_SC_PERIPH_CTRL14, 0x2201); |
| 48 | dsb(); |
| 49 | isb(); |
| 50 | udelay(10); |
Haojian Zhuang | 934ae71 | 2017-05-24 08:47:49 +0800 | [diff] [blame] | 51 | mmio_write_32(0xf7032000 + 0x02c, 0x5110103e); |
Haojian Zhuang | e18de67 | 2018-04-11 19:05:32 +0800 | [diff] [blame] | 52 | dsb(); |
| 53 | isb(); |
| 54 | udelay(10); |
Haojian Zhuang | 934ae71 | 2017-05-24 08:47:49 +0800 | [diff] [blame] | 55 | data = mmio_read_32(0xf7032000 + 0x050); |
| 56 | data |= 1 << 28; |
| 57 | mmio_write_32(0xf7032000 + 0x050, data); |
Haojian Zhuang | e18de67 | 2018-04-11 19:05:32 +0800 | [diff] [blame] | 58 | dsb(); |
| 59 | isb(); |
| 60 | udelay(10); |
Haojian Zhuang | 934ae71 | 2017-05-24 08:47:49 +0800 | [diff] [blame] | 61 | mmio_write_32(PERI_SC_PERIPH_CTRL14, 0x2101); |
Haojian Zhuang | e18de67 | 2018-04-11 19:05:32 +0800 | [diff] [blame] | 62 | dsb(); |
| 63 | isb(); |
| 64 | udelay(10); |
| 65 | mmio_write_32(PERI_SC_PERIPH_CTRL14, 0x2001); |
| 66 | dsb(); |
| 67 | isb(); |
| 68 | udelay(10); |
| 69 | mmio_write_32(PERI_SC_PERIPH_CTRL14, 0x2201); |
| 70 | dsb(); |
| 71 | isb(); |
| 72 | udelay(10); |
Haojian Zhuang | 934ae71 | 2017-05-24 08:47:49 +0800 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | static void init_freq(void) |
| 76 | { |
| 77 | unsigned int data, tmp; |
| 78 | unsigned int cpuext_cfg, ddr_cfg; |
| 79 | |
| 80 | mmio_write_32((0xf7032000 + 0x374), 0x4a); |
| 81 | mmio_write_32((0xf7032000 + 0x368), 0xda); |
| 82 | mmio_write_32((0xf7032000 + 0x36c), 0x01); |
| 83 | mmio_write_32((0xf7032000 + 0x370), 0x01); |
| 84 | mmio_write_32((0xf7032000 + 0x360), 0x60); |
| 85 | mmio_write_32((0xf7032000 + 0x364), 0x60); |
| 86 | |
| 87 | mmio_write_32((0xf7032000 + 0x114), 0x1000); |
| 88 | |
| 89 | data = mmio_read_32((0xf7032000 + 0x110)); |
| 90 | data |= (3 << 12); |
| 91 | mmio_write_32((0xf7032000 + 0x110), data); |
| 92 | |
| 93 | data = mmio_read_32((0xf7032000 + 0x110)); |
| 94 | data |= (1 << 4); |
| 95 | mmio_write_32((0xf7032000 + 0x110), data); |
| 96 | |
| 97 | |
| 98 | data = mmio_read_32((0xf7032000 + 0x110)); |
| 99 | data &= ~0x7; |
| 100 | data |= 0x5; |
| 101 | mmio_write_32((0xf7032000 + 0x110), data); |
| 102 | dsb(); |
| 103 | mdelay(10); |
| 104 | |
| 105 | |
| 106 | do { |
| 107 | data = mmio_read_32((0xf6504000 + 0x008)); |
| 108 | data &= (3 << 20); |
| 109 | } while (data != (3 << 20)); |
| 110 | dsb(); |
| 111 | mdelay(10); |
| 112 | |
| 113 | |
| 114 | data = mmio_read_32((0xf6504000 + 0x054)); |
| 115 | data &= ~((1 << 0) | (1 << 11)); |
| 116 | mmio_write_32((0xf6504000 + 0x054), data); |
| 117 | mdelay(10); |
| 118 | |
| 119 | data = mmio_read_32((0xf7032000 + 0x104)); |
| 120 | data &= ~(3 << 8); |
| 121 | data |= (1 << 8); |
| 122 | mmio_write_32((0xf7032000 + 0x104), data); |
| 123 | |
| 124 | data = mmio_read_32((0xf7032000 + 0x100)); |
| 125 | data |= (1 << 0); |
| 126 | mmio_write_32((0xf7032000 + 0x100), data); |
| 127 | dsb(); |
| 128 | |
| 129 | do { |
| 130 | data = mmio_read_32((0xf7032000 + 0x100)); |
| 131 | data &= (1 << 2); |
| 132 | } while (data != (1 << 2)); |
| 133 | |
| 134 | data = mmio_read_32((0xf6504000 + 0x06c)); |
| 135 | data &= ~0xffff; |
| 136 | data |= 0x56; |
| 137 | mmio_write_32((0xf6504000 + 0x06c), data); |
| 138 | |
| 139 | data = mmio_read_32((0xf6504000 + 0x06c)); |
| 140 | data &= ~(0xffffff << 8); |
| 141 | data |= 0xc7a << 8; |
| 142 | mmio_write_32((0xf6504000 + 0x06c), data); |
| 143 | |
| 144 | data = mmio_read_32((0xf6504000 + 0x058)); |
| 145 | data &= ((1 << 13) - 1); |
| 146 | data |= 0xccb; |
| 147 | mmio_write_32((0xf6504000 + 0x058), data); |
| 148 | |
| 149 | mmio_write_32((0xf6504000 + 0x060), 0x1fff); |
| 150 | mmio_write_32((0xf6504000 + 0x064), 0x1ffffff); |
| 151 | mmio_write_32((0xf6504000 + 0x068), 0x7fffffff); |
| 152 | mmio_write_32((0xf6504000 + 0x05c), 0x1); |
| 153 | |
| 154 | data = mmio_read_32((0xf6504000 + 0x054)); |
| 155 | data &= ~(0xf << 12); |
| 156 | data |= 1 << 12; |
| 157 | mmio_write_32((0xf6504000 + 0x054), data); |
| 158 | dsb(); |
| 159 | |
| 160 | |
| 161 | data = mmio_read_32((0xf7032000 + 0x000)); |
| 162 | data &= ~(1 << 0); |
| 163 | mmio_write_32((0xf7032000 + 0x000), data); |
| 164 | |
| 165 | mmio_write_32((0xf7032000 + 0x004), 0x5110207d); |
| 166 | mmio_write_32((0xf7032000 + 0x134), 0x10000005); |
| 167 | data = mmio_read_32((0xf7032000 + 0x134)); |
| 168 | |
| 169 | |
| 170 | data = mmio_read_32((0xf7032000 + 0x000)); |
| 171 | data |= (1 << 0); |
| 172 | mmio_write_32((0xf7032000 + 0x000), data); |
| 173 | |
| 174 | mmio_write_32((0xf7032000 + 0x368), 0x100da); |
| 175 | data = mmio_read_32((0xf7032000 + 0x378)); |
| 176 | data &= ~((1 << 7) - 1); |
| 177 | data |= 0x6b; |
| 178 | mmio_write_32((0xf7032000 + 0x378), data); |
| 179 | dsb(); |
| 180 | do { |
| 181 | data = mmio_read_32((0xf7032000 + 0x378)); |
| 182 | tmp = data & 0x7f; |
| 183 | data = (data & (0x7f << 8)) >> 8; |
| 184 | if (data != tmp) |
| 185 | continue; |
| 186 | data = mmio_read_32((0xf7032000 + 0x37c)); |
| 187 | } while (!(data & 1)); |
| 188 | |
| 189 | data = mmio_read_32((0xf7032000 + 0x104)); |
| 190 | data &= ~((3 << 0) | |
| 191 | (3 << 8)); |
| 192 | cpuext_cfg = 1; |
| 193 | ddr_cfg = 1; |
| 194 | data |= cpuext_cfg | (ddr_cfg << 8); |
| 195 | mmio_write_32((0xf7032000 + 0x104), data); |
| 196 | dsb(); |
| 197 | |
| 198 | do { |
| 199 | data = mmio_read_32((0xf7032000 + 0x104)); |
| 200 | tmp = (data & (3 << 16)) >> 16; |
| 201 | if (cpuext_cfg != tmp) |
| 202 | continue; |
| 203 | tmp = (data & (3 << 24)) >> 24; |
| 204 | if (ddr_cfg != tmp) |
| 205 | continue; |
| 206 | data = mmio_read_32((0xf7032000 + 0x000)); |
| 207 | data &= 1 << 28; |
| 208 | } while (!data); |
| 209 | |
| 210 | data = mmio_read_32((0xf7032000 + 0x100)); |
| 211 | data &= ~(1 << 0); |
| 212 | mmio_write_32((0xf7032000 + 0x100), data); |
| 213 | dsb(); |
| 214 | do { |
| 215 | data = mmio_read_32((0xf7032000 + 0x100)); |
| 216 | data &= (1 << 1); |
| 217 | } while (data != (1 << 1)); |
| 218 | mdelay(1000); |
| 219 | |
| 220 | data = mmio_read_32((0xf6504000 + 0x054)); |
| 221 | data &= ~(1 << 28); |
| 222 | mmio_write_32((0xf6504000 + 0x054), data); |
| 223 | dsb(); |
| 224 | |
| 225 | data = mmio_read_32((0xf7032000 + 0x110)); |
| 226 | data &= ~((1 << 4) | |
| 227 | (3 << 12)); |
| 228 | mmio_write_32((0xf7032000 + 0x110), data); |
| 229 | } |
| 230 | |
| 231 | int cat_533mhz_800mhz(void) |
| 232 | { |
| 233 | unsigned int data, i; |
| 234 | unsigned int bdl[5]; |
| 235 | |
| 236 | |
| 237 | data = mmio_read_32((0xf712c000 + 0x1c8)); |
| 238 | data &= 0xfffff0f0; |
Haojian Zhuang | e18de67 | 2018-04-11 19:05:32 +0800 | [diff] [blame] | 239 | data |= 0x100f01; |
Haojian Zhuang | 934ae71 | 2017-05-24 08:47:49 +0800 | [diff] [blame] | 240 | mmio_write_32((0xf712c000 + 0x1c8), data); |
| 241 | |
| 242 | for (i = 0; i < 0x20; i++) { |
| 243 | mmio_write_32((0xf712c000 + 0x1d4), 0xc0000); |
| 244 | data = (i << 0x10) + i; |
| 245 | mmio_write_32((0xf712c000 + 0x140), data); |
| 246 | mmio_write_32((0xf712c000 + 0x144), data); |
| 247 | mmio_write_32((0xf712c000 + 0x148), data); |
| 248 | mmio_write_32((0xf712c000 + 0x14c), data); |
| 249 | mmio_write_32((0xf712c000 + 0x150), data); |
| 250 | |
| 251 | |
| 252 | data = mmio_read_32((0xf712c000 + 0x070)); |
| 253 | data |= 0x80000; |
| 254 | mmio_write_32((0xf712c000 + 0x070), data); |
| 255 | data = mmio_read_32((0xf712c000 + 0x070)); |
| 256 | data &= 0xfff7ffff; |
| 257 | mmio_write_32((0xf712c000 + 0x070), data); |
| 258 | |
| 259 | |
| 260 | mmio_write_32((0xf712c000 + 0x004), 0x8000); |
| 261 | mmio_write_32((0xf712c000 + 0x004), 0x0); |
| 262 | mmio_write_32((0xf712c000 + 0x004), 0x801); |
| 263 | do { |
| 264 | data = mmio_read_32((0xf712c000 + 0x004)); |
| 265 | } while (data & 1); |
| 266 | |
| 267 | data = mmio_read_32((0xf712c000 + 0x008)); |
Haojian Zhuang | e18de67 | 2018-04-11 19:05:32 +0800 | [diff] [blame] | 268 | if ((data & 0x400) == 0) { |
Haojian Zhuang | 934ae71 | 2017-05-24 08:47:49 +0800 | [diff] [blame] | 269 | mdelay(10); |
| 270 | return 0; |
| 271 | } |
| 272 | WARN("lpddr3 cat fail\n"); |
| 273 | data = mmio_read_32((0xf712c000 + 0x1d4)); |
| 274 | if ((data & 0x1f00) && ((data & 0x1f) == 0)) { |
| 275 | bdl[0] = mmio_read_32((0xf712c000 + 0x140)); |
| 276 | bdl[1] = mmio_read_32((0xf712c000 + 0x144)); |
| 277 | bdl[2] = mmio_read_32((0xf712c000 + 0x148)); |
| 278 | bdl[3] = mmio_read_32((0xf712c000 + 0x14c)); |
| 279 | bdl[4] = mmio_read_32((0xf712c000 + 0x150)); |
| 280 | if ((!(bdl[0] & 0x1f001f)) || (!(bdl[1] & 0x1f001f)) || |
| 281 | (!(bdl[2] & 0x1f001f)) || (!(bdl[3] & 0x1f001f)) || |
| 282 | (!(bdl[4] & 0x1f001f))) { |
| 283 | WARN("lpddr3 cat deskew error\n"); |
| 284 | if (i == 0x1f) { |
| 285 | WARN("addrnbdl is max\n"); |
| 286 | return -EINVAL; |
| 287 | } |
| 288 | mmio_write_32((0xf712c000 + 0x008), 0x400); |
| 289 | } else { |
| 290 | WARN("lpddr3 cat other error1\n"); |
| 291 | return -EINVAL; |
| 292 | } |
| 293 | } else { |
| 294 | WARN("lpddr3 cat other error2\n"); |
| 295 | return -EINVAL; |
| 296 | } |
| 297 | } |
| 298 | return -EINVAL; |
| 299 | } |
| 300 | |
| 301 | static void ddrx_rdet(void) |
| 302 | { |
| 303 | unsigned int data, rdet, bdl[4]; |
| 304 | |
| 305 | data = mmio_read_32((0xf712c000 + 0x0d0)); |
| 306 | data &= 0xf800ffff; |
| 307 | data |= 0x8f0000; |
| 308 | mmio_write_32((0xf712c000 + 0x0d0), data); |
| 309 | |
| 310 | data = mmio_read_32((0xf712c000 + 0x0dc)); |
| 311 | data &= 0xfffffff0; |
| 312 | data |= 0xf; |
| 313 | mmio_write_32((0xf712c000 + 0x0dc), data); |
| 314 | |
| 315 | |
| 316 | data = mmio_read_32((0xf712c000 + 0x070)); |
| 317 | data |= 0x80000; |
| 318 | mmio_write_32((0xf712c000 + 0x070), data); |
| 319 | data = mmio_read_32((0xf712c000 + 0x070)); |
| 320 | data &= 0xfff7ffff; |
| 321 | mmio_write_32((0xf712c000 + 0x070), data); |
| 322 | |
| 323 | mmio_write_32((0xf712c000 + 0x004), 0x8000); |
| 324 | mmio_write_32((0xf712c000 + 0x004), 0); |
| 325 | |
| 326 | data = mmio_read_32((0xf712c000 + 0x0d0)); |
| 327 | data &= ~0xf0000000; |
| 328 | data |= 0x80000000; |
| 329 | mmio_write_32((0xf712c000 + 0x0d0), data); |
| 330 | |
| 331 | mmio_write_32((0xf712c000 + 0x004), 0x101); |
| 332 | do { |
| 333 | data = mmio_read_32((0xf712c000 + 0x004)); |
| 334 | } while (!(data & 1)); |
| 335 | data = mmio_read_32((0xf712c000 + 0x008)); |
| 336 | if (data & 0x100) |
| 337 | WARN("rdet lbs fail\n"); |
| 338 | |
| 339 | bdl[0] = mmio_read_32((0xf712c000 + 0x22c)) & 0x7f; |
| 340 | bdl[1] = mmio_read_32((0xf712c000 + 0x2ac)) & 0x7f; |
| 341 | bdl[2] = mmio_read_32((0xf712c000 + 0x32c)) & 0x7f; |
| 342 | bdl[3] = mmio_read_32((0xf712c000 + 0x3ac)) & 0x7f; |
| 343 | do { |
| 344 | data = mmio_read_32((0xf712c000 + 0x22c)); |
| 345 | data &= ~0x7f; |
| 346 | data |= bdl[0]; |
| 347 | mmio_write_32((0xf712c000 + 0x22c), data); |
| 348 | data = mmio_read_32((0xf712c000 + 0x2ac)); |
| 349 | data &= ~0x7f; |
| 350 | data |= bdl[1]; |
| 351 | mmio_write_32((0xf712c000 + 0x2ac), data); |
| 352 | data = mmio_read_32((0xf712c000 + 0x32c)); |
| 353 | data &= ~0x7f; |
| 354 | data |= bdl[2]; |
| 355 | mmio_write_32((0xf712c000 + 0x32c), data); |
| 356 | data = mmio_read_32((0xf712c000 + 0x3ac)); |
| 357 | data &= ~0x7f; |
| 358 | data |= bdl[3]; |
| 359 | mmio_write_32((0xf712c000 + 0x3ac), data); |
| 360 | |
| 361 | |
| 362 | data = mmio_read_32((0xf712c000 + 0x070)); |
| 363 | data |= 0x80000; |
| 364 | mmio_write_32((0xf712c000 + 0x070), data); |
| 365 | data = mmio_read_32((0xf712c000 + 0x070)); |
| 366 | data &= 0xfff7ffff; |
| 367 | mmio_write_32((0xf712c000 + 0x070), data); |
| 368 | |
| 369 | mmio_write_32((0xf712c000 + 0x004), 0x8000); |
| 370 | mmio_write_32((0xf712c000 + 0x004), 0); |
| 371 | |
| 372 | data = mmio_read_32((0xf712c000 + 0x0d0)); |
| 373 | data &= ~0xf0000000; |
| 374 | data |= 0x40000000; |
| 375 | mmio_write_32((0xf712c000 + 0x0d0), data); |
| 376 | mmio_write_32((0xf712c000 + 0x004), 0x101); |
| 377 | do { |
| 378 | data = mmio_read_32((0xf712c000 + 0x004)); |
| 379 | } while (data & 1); |
| 380 | |
| 381 | data = mmio_read_32((0xf712c000 + 0x008)); |
| 382 | rdet = data & 0x100; |
| 383 | if (rdet) { |
| 384 | INFO("rdet ds fail\n"); |
| 385 | mmio_write_32((0xf712c000 + 0x008), 0x100); |
| 386 | } |
| 387 | bdl[0]++; |
| 388 | bdl[1]++; |
| 389 | bdl[2]++; |
| 390 | bdl[3]++; |
| 391 | } while (rdet); |
| 392 | |
| 393 | data = mmio_read_32((0xf712c000 + 0x0d0)); |
| 394 | data &= ~0xf0000000; |
| 395 | data |= 0x30000000; |
| 396 | mmio_write_32((0xf712c000 + 0x0d0), data); |
| 397 | |
| 398 | mmio_write_32((0xf712c000 + 0x004), 0x101); |
| 399 | do { |
| 400 | data = mmio_read_32((0xf712c000 + 0x004)); |
| 401 | } while (data & 1); |
| 402 | data = mmio_read_32((0xf712c000 + 0x008)); |
| 403 | if (data & 0x100) |
| 404 | INFO("rdet rbs av fail\n"); |
| 405 | } |
| 406 | |
| 407 | static void ddrx_wdet(void) |
| 408 | { |
Haojian Zhuang | 6ffe56c | 2017-05-31 12:42:10 +0800 | [diff] [blame] | 409 | unsigned int data, wdet, zero_bdl = 0, dq[4]; |
Haojian Zhuang | 934ae71 | 2017-05-24 08:47:49 +0800 | [diff] [blame] | 410 | int i; |
| 411 | |
| 412 | data = mmio_read_32((0xf712c000 + 0x0d0)); |
| 413 | data &= ~0xf; |
| 414 | data |= 0xf; |
| 415 | mmio_write_32((0xf712c000 + 0x0d0), data); |
| 416 | |
| 417 | data = mmio_read_32((0xf712c000 + 0x070)); |
| 418 | data |= 0x80000; |
| 419 | mmio_write_32((0xf712c000 + 0x070), data); |
| 420 | data = mmio_read_32((0xf712c000 + 0x070)); |
| 421 | data &= ~0x80000; |
| 422 | mmio_write_32((0xf712c000 + 0x070), data); |
| 423 | |
| 424 | mmio_write_32((0xf712c000 + 0x004), 0x8000); |
| 425 | mmio_write_32((0xf712c000 + 0x004), 0); |
| 426 | data = mmio_read_32((0xf712c000 + 0x0d0)); |
| 427 | data &= ~0xf000; |
| 428 | data |= 0x8000; |
| 429 | mmio_write_32((0xf712c000 + 0x0d0), data); |
| 430 | mmio_write_32((0xf712c000 + 0x004), 0x201); |
| 431 | do { |
| 432 | data = mmio_read_32((0xf712c000 + 0x004)); |
| 433 | } while (data & 1); |
| 434 | data = mmio_read_32((0xf712c000 + 0x008)); |
| 435 | if (data & 0x200) |
| 436 | INFO("wdet lbs fail\n"); |
| 437 | |
| 438 | dq[0] = mmio_read_32((0xf712c000 + 0x234)) & 0x1f00; |
| 439 | dq[1] = mmio_read_32((0xf712c000 + 0x2b4)) & 0x1f00; |
| 440 | dq[2] = mmio_read_32((0xf712c000 + 0x334)) & 0x1f00; |
| 441 | dq[3] = mmio_read_32((0xf712c000 + 0x3b4)) & 0x1f00; |
| 442 | |
| 443 | do { |
| 444 | mmio_write_32((0xf712c000 + 0x234), dq[0]); |
| 445 | mmio_write_32((0xf712c000 + 0x2b4), dq[1]); |
| 446 | mmio_write_32((0xf712c000 + 0x334), dq[2]); |
| 447 | mmio_write_32((0xf712c000 + 0x3b4), dq[3]); |
| 448 | |
| 449 | data = mmio_read_32((0xf712c000 + 0x070)); |
| 450 | data |= 0x80000; |
| 451 | mmio_write_32((0xf712c000 + 0x070), data); |
| 452 | data = mmio_read_32((0xf712c000 + 0x070)); |
| 453 | data &= ~0x80000; |
| 454 | mmio_write_32((0xf712c000 + 0x070), data); |
| 455 | mmio_write_32((0xf712c000 + 0x004), 0x8000); |
| 456 | mmio_write_32((0xf712c000 + 0x004), 0); |
| 457 | |
| 458 | data = mmio_read_32((0xf712c000 + 0x0d0)); |
| 459 | data &= ~0xf000; |
| 460 | data |= 0x4000; |
| 461 | mmio_write_32((0xf712c000 + 0x0d0), data); |
| 462 | mmio_write_32((0xf712c000 + 0x004), 0x201); |
| 463 | do { |
| 464 | data = mmio_read_32((0xf712c000 + 0x004)); |
| 465 | } while (data & 1); |
| 466 | |
| 467 | data = mmio_read_32((0xf712c000 + 0x008)); |
| 468 | wdet = data & 0x200; |
| 469 | if (wdet) { |
| 470 | INFO("wdet ds fail\n"); |
| 471 | mmio_write_32((0xf712c000 + 0x008), 0x200); |
| 472 | } |
| 473 | mdelay(10); |
| 474 | |
| 475 | for (i = 0; i < 4; i++) { |
| 476 | data = mmio_read_32((0xf712c000 + 0x210 + i * 0x80)); |
| 477 | if ((!(data & 0x1f)) || (!(data & 0x1f00)) || |
Haojian Zhuang | 6ffe56c | 2017-05-31 12:42:10 +0800 | [diff] [blame] | 478 | (!(data & 0x1f0000)) || (!(data & 0x1f000000))) |
Haojian Zhuang | 934ae71 | 2017-05-24 08:47:49 +0800 | [diff] [blame] | 479 | zero_bdl = 1; |
| 480 | data = mmio_read_32((0xf712c000 + 0x214 + i * 0x80)); |
| 481 | if ((!(data & 0x1f)) || (!(data & 0x1f00)) || |
Haojian Zhuang | 6ffe56c | 2017-05-31 12:42:10 +0800 | [diff] [blame] | 482 | (!(data & 0x1f0000)) || (!(data & 0x1f000000))) |
Haojian Zhuang | 934ae71 | 2017-05-24 08:47:49 +0800 | [diff] [blame] | 483 | zero_bdl = 1; |
| 484 | data = mmio_read_32((0xf712c000 + 0x218 + i * 0x80)); |
| 485 | if (!(data & 0x1f)) |
| 486 | zero_bdl = 1; |
| 487 | if (zero_bdl) { |
| 488 | if (i == 0) |
| 489 | dq[0] = dq[0] - 0x100; |
| 490 | if (i == 1) |
| 491 | dq[1] = dq[1] - 0x100; |
| 492 | if (i == 2) |
| 493 | dq[2] = dq[2] - 0x100; |
| 494 | if (i == 3) |
| 495 | dq[3] = dq[3] - 0x100; |
| 496 | } |
| 497 | } |
| 498 | } while (wdet); |
| 499 | |
| 500 | data = mmio_read_32((0xf712c000 + 0x0d0)); |
| 501 | data &= ~0xf000; |
| 502 | data |= 0x3000; |
| 503 | mmio_write_32((0xf712c000 + 0x0d0), data); |
| 504 | mmio_write_32((0xf712c000 + 0x004), 0x201); |
| 505 | do { |
| 506 | data = mmio_read_32((0xf712c000 + 0x004)); |
| 507 | } while (data & 1); |
| 508 | data = mmio_read_32((0xf712c000 + 0x008)); |
| 509 | if (data & 0x200) |
| 510 | INFO("wdet rbs av fail\n"); |
| 511 | } |
| 512 | |
Haojian Zhuang | e18de67 | 2018-04-11 19:05:32 +0800 | [diff] [blame] | 513 | void set_ddrc_150mhz(void) |
| 514 | { |
| 515 | unsigned int data; |
| 516 | |
| 517 | mmio_write_32((0xf7032000 + 0x580), 0x1); |
| 518 | mmio_write_32((0xf7032000 + 0x5a8), 0x7); |
| 519 | data = mmio_read_32((0xf7032000 + 0x104)); |
| 520 | data &= 0xfffffcff; |
| 521 | mmio_write_32((0xf7032000 + 0x104), data); |
| 522 | |
| 523 | mmio_write_32((0xf7030000 + 0x050), 0x31); |
| 524 | mmio_write_32((0xf7030000 + 0x240), 0x5ffff); |
| 525 | mmio_write_32((0xf7030000 + 0x344), 0xf5ff); |
| 526 | mmio_write_32((0xf712c000 + 0x00c), 0x80000f0f); |
| 527 | mmio_write_32((0xf712c000 + 0x00c), 0xf0f); |
| 528 | mmio_write_32((0xf712c000 + 0x018), 0x7); |
| 529 | mmio_write_32((0xf712c000 + 0x090), 0x7200000); |
| 530 | mmio_write_32((0xf712c000 + 0x258), 0x720); |
| 531 | mmio_write_32((0xf712c000 + 0x2d8), 0x720); |
| 532 | mmio_write_32((0xf712c000 + 0x358), 0x720); |
| 533 | mmio_write_32((0xf712c000 + 0x3d8), 0x720); |
| 534 | mmio_write_32((0xf712c000 + 0x018), 0x7); |
| 535 | mmio_write_32((0xf712c000 + 0x0b0), 0xf00000f); |
| 536 | mmio_write_32((0xf712c000 + 0x0b4), 0xf); |
| 537 | mmio_write_32((0xf712c000 + 0x088), 0x3fff801); |
| 538 | mmio_write_32((0xf712c000 + 0x070), 0x8940000); |
| 539 | |
| 540 | data = mmio_read_32((0xf712c000 + 0x078)); |
| 541 | data |= 4; |
| 542 | mmio_write_32((0xf712c000 + 0x078), data); |
| 543 | mmio_write_32((0xf712c000 + 0x01c), 0x8000080); |
| 544 | data = mmio_read_32((0xf712c000 + 0x020)); |
| 545 | data &= 0xfffffffe; |
| 546 | mmio_write_32((0xf712c000 + 0x020), data); |
| 547 | mmio_write_32((0xf712c000 + 0x1d4), 0xc0000); |
| 548 | mmio_write_32((0xf712c000 + 0x010), 0x500000f); |
| 549 | mmio_write_32((0xf712c000 + 0x014), 0x10); |
| 550 | data = mmio_read_32((0xf712c000 + 0x1e4)); |
| 551 | data &= 0xffffff00; |
| 552 | mmio_write_32((0xf712c000 + 0x1e4), data); |
| 553 | mmio_write_32((0xf712c000 + 0x030), 0x30c82355); |
| 554 | mmio_write_32((0xf712c000 + 0x034), 0x62112bb); |
| 555 | mmio_write_32((0xf712c000 + 0x038), 0x20041022); |
| 556 | mmio_write_32((0xf712c000 + 0x03c), 0x63177497); |
| 557 | mmio_write_32((0xf712c000 + 0x040), 0x3008407); |
| 558 | mmio_write_32((0xf712c000 + 0x064), 0x10483); |
| 559 | mmio_write_32((0xf712c000 + 0x068), 0xff0a0000); |
| 560 | data = mmio_read_32((0xf712c000 + 0x070)); |
| 561 | data &= 0xffff0000; |
| 562 | data |= 0x184; |
| 563 | mmio_write_32((0xf712c000 + 0x070), data); |
| 564 | data = mmio_read_32((0xf712c000 + 0x048)); |
| 565 | data &= 0xbfffffff; |
| 566 | mmio_write_32((0xf712c000 + 0x048), data); |
| 567 | data = mmio_read_32((0xf712c000 + 0x020)); |
| 568 | data &= ~0x10; |
| 569 | mmio_write_32((0xf712c000 + 0x020), data); |
| 570 | data = mmio_read_32((0xf712c000 + 0x080)); |
| 571 | data &= ~0x2000; |
| 572 | mmio_write_32((0xf712c000 + 0x080), data); |
| 573 | mmio_write_32((0xf712c000 + 0x270), 0x3); |
| 574 | mmio_write_32((0xf712c000 + 0x2f0), 0x3); |
| 575 | mmio_write_32((0xf712c000 + 0x370), 0x3); |
| 576 | mmio_write_32((0xf712c000 + 0x3f0), 0x3); |
| 577 | mmio_write_32((0xf712c000 + 0x048), 0x90420880); |
| 578 | |
| 579 | mmio_write_32((0xf7128000 + 0x040), 0x0); |
| 580 | mmio_write_32((0xf712c000 + 0x004), 0x146d); |
| 581 | mmio_write_32((0xf7128000 + 0x050), 0x100123); |
| 582 | mmio_write_32((0xf7128000 + 0x060), 0x133); |
| 583 | mmio_write_32((0xf7128000 + 0x064), 0x133); |
| 584 | mmio_write_32((0xf7128000 + 0x200), 0xa1000); |
| 585 | |
| 586 | mmio_write_32((0xf7128000 + 0x100), 0xb3290d08); |
| 587 | mmio_write_32((0xf7128000 + 0x104), 0x9621821); |
| 588 | mmio_write_32((0xf7128000 + 0x108), 0x45009023); |
| 589 | mmio_write_32((0xf7128000 + 0x10c), 0xaf44c145); |
| 590 | mmio_write_32((0xf7128000 + 0x110), 0x10b00000); |
| 591 | mmio_write_32((0xf7128000 + 0x114), 0x11080806); |
| 592 | mmio_write_32((0xf7128000 + 0x118), 0x44); |
| 593 | do { |
| 594 | data = mmio_read_32((0xf712c000 + 0x004)); |
| 595 | } while (data & 1); |
| 596 | data = mmio_read_32((0xf712c000 + 0x008)); |
| 597 | if (data & 8) { |
| 598 | NOTICE("fail to init ddr3 rank0\n"); |
| 599 | return; |
| 600 | } |
| 601 | |
| 602 | data = mmio_read_32((0xf712c000 + 0x048)); |
| 603 | data |= 1; |
| 604 | mmio_write_32((0xf712c000 + 0x048), data); |
| 605 | mmio_write_32((0xf712c000 + 0x004), 0x21); |
| 606 | do { |
| 607 | data = mmio_read_32((0xf712c000 + 0x004)); |
| 608 | } while (data & 1); |
| 609 | |
| 610 | data = mmio_read_32((0xf712c000 + 0x008)); |
| 611 | if (data & 0x8) |
| 612 | NOTICE("ddr3 rank1 init failure\n"); |
| 613 | else |
| 614 | INFO("ddr3 rank1 init pass\n"); |
| 615 | |
| 616 | data = mmio_read_32((0xf712c000 + 0x048)); |
| 617 | data &= ~0xf; |
| 618 | mmio_write_32((0xf712c000 + 0x048), data); |
| 619 | INFO("succeed to set ddrc 150mhz\n"); |
| 620 | } |
| 621 | |
| 622 | void set_ddrc_266mhz(void) |
Haojian Zhuang | 934ae71 | 2017-05-24 08:47:49 +0800 | [diff] [blame] | 623 | { |
| 624 | unsigned int data; |
| 625 | |
| 626 | mmio_write_32((0xf7032000 + 0x580), 0x3); |
Haojian Zhuang | e18de67 | 2018-04-11 19:05:32 +0800 | [diff] [blame] | 627 | mmio_write_32((0xf7032000 + 0x5a8), 0x1003); |
| 628 | data = mmio_read_32((0xf7032000 + 0x104)); |
| 629 | data &= 0xfffffcff; |
| 630 | mmio_write_32((0xf7032000 + 0x104), data); |
| 631 | |
| 632 | mmio_write_32((0xf7030000 + 0x050), 0x31); |
| 633 | mmio_write_32((0xf7030000 + 0x240), 0x5ffff); |
| 634 | mmio_write_32((0xf7030000 + 0x344), 0xf5ff); |
| 635 | mmio_write_32((0xf712c000 + 0x00c), 0x80000f0f); |
| 636 | mmio_write_32((0xf712c000 + 0x00c), 0xf0f); |
| 637 | mmio_write_32((0xf712c000 + 0x018), 0x7); |
| 638 | mmio_write_32((0xf712c000 + 0x090), 0x7200000); |
| 639 | mmio_write_32((0xf712c000 + 0x258), 0x720); |
| 640 | mmio_write_32((0xf712c000 + 0x2d8), 0x720); |
| 641 | mmio_write_32((0xf712c000 + 0x358), 0x720); |
| 642 | mmio_write_32((0xf712c000 + 0x3d8), 0x720); |
| 643 | mmio_write_32((0xf712c000 + 0x018), 0x7); |
| 644 | mmio_write_32((0xf712c000 + 0x0b0), 0xf00000f); |
| 645 | mmio_write_32((0xf712c000 + 0x0b4), 0xf); |
| 646 | mmio_write_32((0xf712c000 + 0x088), 0x3fff801); |
| 647 | mmio_write_32((0xf712c000 + 0x070), 0x8940000); |
| 648 | |
| 649 | data = mmio_read_32((0xf712c000 + 0x078)); |
| 650 | data |= 4; |
| 651 | mmio_write_32((0xf712c000 + 0x078), data); |
| 652 | mmio_write_32((0xf712c000 + 0x01c), 0x8000080); |
| 653 | data = mmio_read_32((0xf712c000 + 0x020)); |
| 654 | data &= 0xfffffffe; |
| 655 | mmio_write_32((0xf712c000 + 0x020), data); |
| 656 | mmio_write_32((0xf712c000 + 0x1d4), 0xc0000); |
| 657 | mmio_write_32((0xf712c000 + 0x010), 0x500000f); |
| 658 | mmio_write_32((0xf712c000 + 0x014), 0x10); |
| 659 | data = mmio_read_32((0xf712c000 + 0x1e4)); |
| 660 | data &= 0xffffff00; |
| 661 | mmio_write_32((0xf712c000 + 0x1e4), data); |
| 662 | mmio_write_32((0xf712c000 + 0x030), 0x510d4455); |
| 663 | mmio_write_32((0xf712c000 + 0x034), 0x8391ebb); |
| 664 | mmio_write_32((0xf712c000 + 0x038), 0x2005103c); |
| 665 | mmio_write_32((0xf712c000 + 0x03c), 0x6329950b); |
| 666 | mmio_write_32((0xf712c000 + 0x040), 0x300858c); |
| 667 | mmio_write_32((0xf712c000 + 0x064), 0x10483); |
| 668 | mmio_write_32((0xf712c000 + 0x068), 0xff0a0000); |
| 669 | data = mmio_read_32((0xf712c000 + 0x070)); |
| 670 | data &= 0xffff0000; |
| 671 | data |= 0x184; |
| 672 | mmio_write_32((0xf712c000 + 0x070), data); |
| 673 | data = mmio_read_32((0xf712c000 + 0x048)); |
| 674 | data &= 0xbfffffff; |
| 675 | mmio_write_32((0xf712c000 + 0x048), data); |
| 676 | data = mmio_read_32((0xf712c000 + 0x020)); |
| 677 | data &= ~0x10; |
| 678 | mmio_write_32((0xf712c000 + 0x020), data); |
| 679 | data = mmio_read_32((0xf712c000 + 0x080)); |
| 680 | data &= ~0x2000; |
| 681 | mmio_write_32((0xf712c000 + 0x080), data); |
| 682 | mmio_write_32((0xf712c000 + 0x270), 0x3); |
| 683 | mmio_write_32((0xf712c000 + 0x2f0), 0x3); |
| 684 | mmio_write_32((0xf712c000 + 0x370), 0x3); |
| 685 | mmio_write_32((0xf712c000 + 0x3f0), 0x3); |
| 686 | mmio_write_32((0xf712c000 + 0x048), 0x90420880); |
| 687 | |
| 688 | mmio_write_32((0xf7128000 + 0x040), 0x0); |
| 689 | mmio_write_32((0xf712c000 + 0x004), 0x146d); |
| 690 | mmio_write_32((0xf7128000 + 0x050), 0x100123); |
| 691 | mmio_write_32((0xf7128000 + 0x060), 0x133); |
| 692 | mmio_write_32((0xf7128000 + 0x064), 0x133); |
| 693 | mmio_write_32((0xf7128000 + 0x200), 0xa1000); |
| 694 | |
| 695 | mmio_write_32((0xf7128000 + 0x100), 0xb441d50d); |
| 696 | mmio_write_32((0xf7128000 + 0x104), 0xf721839); |
| 697 | mmio_write_32((0xf7128000 + 0x108), 0x5500f03f); |
| 698 | mmio_write_32((0xf7128000 + 0x10c), 0xaf486145); |
| 699 | mmio_write_32((0xf7128000 + 0x110), 0x10b00000); |
| 700 | mmio_write_32((0xf7128000 + 0x114), 0x12080d06); |
| 701 | mmio_write_32((0xf7128000 + 0x118), 0x44); |
| 702 | do { |
| 703 | data = mmio_read_32((0xf712c000 + 0x004)); |
| 704 | } while (data & 1); |
| 705 | data = mmio_read_32((0xf712c000 + 0x008)); |
| 706 | if (data & 8) { |
| 707 | NOTICE("fail to init ddr3 rank0\n"); |
| 708 | return; |
| 709 | } |
| 710 | |
| 711 | data = mmio_read_32((0xf712c000 + 0x048)); |
| 712 | data |= 1; |
| 713 | mmio_write_32((0xf712c000 + 0x048), data); |
| 714 | mmio_write_32((0xf712c000 + 0x004), 0x21); |
| 715 | do { |
| 716 | data = mmio_read_32((0xf712c000 + 0x004)); |
| 717 | } while (data & 1); |
| 718 | |
| 719 | data = mmio_read_32((0xf712c000 + 0x008)); |
| 720 | if (data & 0x8) |
| 721 | NOTICE("ddr3 rank1 init failure\n"); |
| 722 | else |
| 723 | INFO("ddr3 rank1 init pass\n"); |
| 724 | |
| 725 | data = mmio_read_32((0xf712c000 + 0x048)); |
| 726 | data &= ~0xf; |
| 727 | mmio_write_32((0xf712c000 + 0x048), data); |
| 728 | INFO("succeed to set ddrc 266mhz\n"); |
| 729 | } |
| 730 | |
| 731 | void set_ddrc_400mhz(void) |
| 732 | { |
| 733 | unsigned int data; |
| 734 | |
| 735 | mmio_write_32((0xf7032000 + 0x580), 0x2); |
| 736 | mmio_write_32((0xf7032000 + 0x5a8), 0x1003); |
| 737 | data = mmio_read_32((0xf7032000 + 0x104)); |
| 738 | data &= 0xfffffcff; |
| 739 | mmio_write_32((0xf7032000 + 0x104), data); |
| 740 | |
| 741 | mmio_write_32((0xf7030000 + 0x050), 0x31); |
| 742 | mmio_write_32((0xf7030000 + 0x240), 0x5ffff); |
| 743 | mmio_write_32((0xf7030000 + 0x344), 0xf5ff); |
| 744 | mmio_write_32((0xf712c000 + 0x00c), 0x80000f0f); |
| 745 | mmio_write_32((0xf712c000 + 0x00c), 0xf0f); |
| 746 | mmio_write_32((0xf712c000 + 0x018), 0x7); |
| 747 | mmio_write_32((0xf712c000 + 0x090), 0x7200000); |
| 748 | mmio_write_32((0xf712c000 + 0x258), 0x720); |
| 749 | mmio_write_32((0xf712c000 + 0x2d8), 0x720); |
| 750 | mmio_write_32((0xf712c000 + 0x358), 0x720); |
| 751 | mmio_write_32((0xf712c000 + 0x3d8), 0x720); |
| 752 | mmio_write_32((0xf712c000 + 0x018), 0x7); |
| 753 | mmio_write_32((0xf712c000 + 0x0b0), 0xf00000f); |
| 754 | mmio_write_32((0xf712c000 + 0x0b4), 0xf); |
| 755 | mmio_write_32((0xf712c000 + 0x088), 0x3fff801); |
| 756 | mmio_write_32((0xf712c000 + 0x070), 0x8940000); |
| 757 | |
| 758 | data = mmio_read_32((0xf712c000 + 0x078)); |
| 759 | data |= 4; |
| 760 | mmio_write_32((0xf712c000 + 0x078), data); |
| 761 | mmio_write_32((0xf712c000 + 0x01c), 0x8000080); |
| 762 | data = mmio_read_32((0xf712c000 + 0x020)); |
| 763 | data &= 0xfffffffe; |
| 764 | mmio_write_32((0xf712c000 + 0x020), data); |
| 765 | mmio_write_32((0xf712c000 + 0x1d4), 0xc0000); |
| 766 | mmio_write_32((0xf712c000 + 0x010), 0x500000f); |
| 767 | mmio_write_32((0xf712c000 + 0x014), 0x10); |
| 768 | data = mmio_read_32((0xf712c000 + 0x1e4)); |
| 769 | data &= 0xffffff00; |
| 770 | mmio_write_32((0xf712c000 + 0x1e4), data); |
| 771 | mmio_write_32((0xf712c000 + 0x030), 0x75525655); |
| 772 | mmio_write_32((0xf712c000 + 0x034), 0xa552abb); |
| 773 | mmio_write_32((0xf712c000 + 0x038), 0x20071059); |
| 774 | mmio_write_32((0xf712c000 + 0x03c), 0x633e8591); |
| 775 | mmio_write_32((0xf712c000 + 0x040), 0x3008691); |
| 776 | mmio_write_32((0xf712c000 + 0x064), 0x10483); |
| 777 | mmio_write_32((0xf712c000 + 0x068), 0xff0a0000); |
| 778 | data = mmio_read_32((0xf712c000 + 0x070)); |
| 779 | data &= 0xffff0000; |
| 780 | data |= 0x184; |
| 781 | mmio_write_32((0xf712c000 + 0x070), data); |
| 782 | data = mmio_read_32((0xf712c000 + 0x048)); |
| 783 | data &= 0xbfffffff; |
| 784 | mmio_write_32((0xf712c000 + 0x048), data); |
| 785 | data = mmio_read_32((0xf712c000 + 0x020)); |
| 786 | data &= ~0x10; |
| 787 | mmio_write_32((0xf712c000 + 0x020), data); |
| 788 | data = mmio_read_32((0xf712c000 + 0x080)); |
| 789 | data &= ~0x2000; |
| 790 | mmio_write_32((0xf712c000 + 0x080), data); |
| 791 | mmio_write_32((0xf712c000 + 0x270), 0x3); |
| 792 | mmio_write_32((0xf712c000 + 0x2f0), 0x3); |
| 793 | mmio_write_32((0xf712c000 + 0x370), 0x3); |
| 794 | mmio_write_32((0xf712c000 + 0x3f0), 0x3); |
| 795 | mmio_write_32((0xf712c000 + 0x048), 0x90420880); |
| 796 | |
| 797 | mmio_write_32((0xf7128000 + 0x040), 0x0); |
| 798 | mmio_write_32((0xf712c000 + 0x004), 0x146d); |
| 799 | mmio_write_32((0xf7128000 + 0x050), 0x100123); |
| 800 | mmio_write_32((0xf7128000 + 0x060), 0x133); |
| 801 | mmio_write_32((0xf7128000 + 0x064), 0x133); |
| 802 | mmio_write_32((0xf7128000 + 0x200), 0xa1000); |
| 803 | |
| 804 | mmio_write_32((0xf7128000 + 0x100), 0xb55a9d12); |
| 805 | mmio_write_32((0xf7128000 + 0x104), 0x17721855); |
| 806 | mmio_write_32((0xf7128000 + 0x108), 0x7501505f); |
| 807 | mmio_write_32((0xf7128000 + 0x10c), 0xaf4ca245); |
| 808 | mmio_write_32((0xf7128000 + 0x110), 0x10b00000); |
| 809 | mmio_write_32((0xf7128000 + 0x114), 0x13081306); |
| 810 | mmio_write_32((0xf7128000 + 0x118), 0x44); |
| 811 | do { |
| 812 | data = mmio_read_32((0xf712c000 + 0x004)); |
| 813 | } while (data & 1); |
| 814 | data = mmio_read_32((0xf712c000 + 0x008)); |
| 815 | if (data & 8) { |
| 816 | NOTICE("fail to init ddr3 rank0\n"); |
| 817 | return; |
| 818 | } |
| 819 | |
| 820 | data = mmio_read_32((0xf712c000 + 0x048)); |
| 821 | data |= 1; |
| 822 | mmio_write_32((0xf712c000 + 0x048), data); |
| 823 | mmio_write_32((0xf712c000 + 0x004), 0x21); |
| 824 | do { |
| 825 | data = mmio_read_32((0xf712c000 + 0x004)); |
| 826 | } while (data & 1); |
| 827 | |
| 828 | data = mmio_read_32((0xf712c000 + 0x008)); |
| 829 | if (data & 0x8) |
| 830 | NOTICE("ddr3 rank1 init failure\n"); |
| 831 | else |
| 832 | INFO("ddr3 rank1 init pass\n"); |
| 833 | |
| 834 | data = mmio_read_32((0xf712c000 + 0x048)); |
| 835 | data &= ~0xf; |
| 836 | mmio_write_32((0xf712c000 + 0x048), data); |
| 837 | INFO("succeed to set ddrc 400mhz\n"); |
| 838 | } |
| 839 | |
| 840 | void set_ddrc_533mhz(void) |
| 841 | { |
| 842 | unsigned int data; |
| 843 | |
| 844 | mmio_write_32((0xf7032000 + 0x580), 0x3); |
Haojian Zhuang | 934ae71 | 2017-05-24 08:47:49 +0800 | [diff] [blame] | 845 | mmio_write_32((0xf7032000 + 0x5a8), 0x11111); |
| 846 | data = mmio_read_32((0xf7032000 + 0x104)); |
| 847 | data |= 0x100; |
| 848 | mmio_write_32((0xf7032000 + 0x104), data); |
| 849 | |
| 850 | mmio_write_32((0xf7030000 + 0x050), 0x30); |
| 851 | mmio_write_32((0xf7030000 + 0x240), 0x5ffff); |
| 852 | mmio_write_32((0xf7030000 + 0x344), 0xf5ff); |
| 853 | mmio_write_32((0xf712c000 + 0x00c), 0x400); |
Haojian Zhuang | e18de67 | 2018-04-11 19:05:32 +0800 | [diff] [blame] | 854 | mmio_write_32((0xf712c000 + 0x00c), 0x400); |
Haojian Zhuang | 934ae71 | 2017-05-24 08:47:49 +0800 | [diff] [blame] | 855 | mmio_write_32((0xf712c000 + 0x018), 0x7); |
| 856 | mmio_write_32((0xf712c000 + 0x090), 0x6400000); |
| 857 | mmio_write_32((0xf712c000 + 0x258), 0x640); |
| 858 | mmio_write_32((0xf712c000 + 0x2d8), 0x640); |
| 859 | mmio_write_32((0xf712c000 + 0x358), 0x640); |
| 860 | mmio_write_32((0xf712c000 + 0x3d8), 0x640); |
| 861 | mmio_write_32((0xf712c000 + 0x018), 0x0); |
| 862 | mmio_write_32((0xf712c000 + 0x0b0), 0xf00000f); |
| 863 | mmio_write_32((0xf712c000 + 0x0b4), 0xf); |
| 864 | mmio_write_32((0xf712c000 + 0x088), 0x3fff801); |
| 865 | mmio_write_32((0xf712c000 + 0x070), 0x8940000); |
| 866 | |
| 867 | data = mmio_read_32((0xf712c000 + 0x078)); |
| 868 | data |= 4; |
| 869 | mmio_write_32((0xf712c000 + 0x078), data); |
| 870 | mmio_write_32((0xf712c000 + 0x01c), 0x8000080); |
| 871 | data = mmio_read_32((0xf712c000 + 0x020)); |
| 872 | data &= 0xfffffffe; |
| 873 | mmio_write_32((0xf712c000 + 0x020), data); |
| 874 | mmio_write_32((0xf712c000 + 0x1d4), 0xc0000); |
| 875 | mmio_write_32((0xf712c000 + 0x010), 0x500000f); |
| 876 | mmio_write_32((0xf712c000 + 0x014), 0x10); |
| 877 | data = mmio_read_32((0xf712c000 + 0x1e4)); |
| 878 | data &= 0xffffff00; |
| 879 | mmio_write_32((0xf712c000 + 0x1e4), data); |
| 880 | mmio_write_32((0xf712c000 + 0x030), 0x9dd87855); |
| 881 | mmio_write_32((0xf712c000 + 0x034), 0xa7138bb); |
| 882 | mmio_write_32((0xf712c000 + 0x038), 0x20091477); |
| 883 | mmio_write_32((0xf712c000 + 0x03c), 0x84534e16); |
| 884 | mmio_write_32((0xf712c000 + 0x040), 0x3008817); |
| 885 | mmio_write_32((0xf712c000 + 0x064), 0x106c3); |
| 886 | mmio_write_32((0xf712c000 + 0x068), 0xff0a0000); |
| 887 | data = mmio_read_32((0xf712c000 + 0x070)); |
| 888 | data &= 0xffff0000; |
| 889 | data |= 0x305; |
| 890 | mmio_write_32((0xf712c000 + 0x070), data); |
| 891 | data = mmio_read_32((0xf712c000 + 0x048)); |
| 892 | data |= 0x40000000; |
| 893 | mmio_write_32((0xf712c000 + 0x048), data); |
| 894 | data = mmio_read_32((0xf712c000 + 0x020)); |
| 895 | data &= ~0x10; |
| 896 | mmio_write_32((0xf712c000 + 0x020), data); |
| 897 | data = mmio_read_32((0xf712c000 + 0x080)); |
| 898 | data &= ~0x2000; |
| 899 | mmio_write_32((0xf712c000 + 0x080), data); |
| 900 | mmio_write_32((0xf712c000 + 0x270), 0x3); |
| 901 | mmio_write_32((0xf712c000 + 0x2f0), 0x3); |
| 902 | mmio_write_32((0xf712c000 + 0x370), 0x3); |
| 903 | mmio_write_32((0xf712c000 + 0x3f0), 0x3); |
| 904 | mmio_write_32((0xf712c000 + 0x048), 0xd0420900); |
| 905 | |
| 906 | mmio_write_32((0xf7128000 + 0x040), 0x0); |
| 907 | mmio_write_32((0xf712c000 + 0x004), 0x140f); |
| 908 | do { |
| 909 | data = mmio_read_32((0xf712c000 + 0x004)); |
| 910 | } while (data & 1); |
| 911 | data = mmio_read_32((0xf712c000 + 0x008)); |
| 912 | if (data & 0x7fe) { |
| 913 | NOTICE("failed to init lpddr3 rank0 dram phy\n"); |
| 914 | return; |
| 915 | } |
Haojian Zhuang | e18de67 | 2018-04-11 19:05:32 +0800 | [diff] [blame] | 916 | cat_533mhz_800mhz(); |
| 917 | |
| 918 | mmio_write_32((0xf712c000 + 0x004), 0xf1); |
| 919 | mmio_write_32((0xf7128000 + 0x050), 0x100123); |
| 920 | mmio_write_32((0xf7128000 + 0x060), 0x133); |
| 921 | mmio_write_32((0xf7128000 + 0x064), 0x133); |
| 922 | mmio_write_32((0xf7128000 + 0x200), 0xa1000); |
| 923 | |
| 924 | mmio_write_32((0xf7128000 + 0x100), 0xb77b6718); |
| 925 | mmio_write_32((0xf7128000 + 0x104), 0x1e82a071); |
| 926 | mmio_write_32((0xf7128000 + 0x108), 0x9501c07e); |
| 927 | mmio_write_32((0xf7128000 + 0x10c), 0xaf50c255); |
| 928 | mmio_write_32((0xf7128000 + 0x110), 0x10b00000); |
| 929 | mmio_write_32((0xf7128000 + 0x114), 0x13181908); |
| 930 | mmio_write_32((0xf7128000 + 0x118), 0x44); |
| 931 | do { |
| 932 | data = mmio_read_32((0xf712c000 + 0x004)); |
| 933 | } while (data & 1); |
| 934 | data = mmio_read_32((0xf712c000 + 0x008)); |
| 935 | if (data & 0x7fe) { |
| 936 | NOTICE("fail to init ddr3 rank0\n"); |
| 937 | return; |
| 938 | } |
| 939 | ddrx_rdet(); |
| 940 | ddrx_wdet(); |
| 941 | |
| 942 | data = mmio_read_32((0xf712c000 + 0x048)); |
| 943 | data |= 1; |
| 944 | mmio_write_32((0xf712c000 + 0x048), data); |
| 945 | mmio_write_32((0xf712c000 + 0x004), 0x21); |
| 946 | do { |
| 947 | data = mmio_read_32((0xf712c000 + 0x004)); |
| 948 | } while (data & 1); |
| 949 | |
| 950 | data = mmio_read_32((0xf712c000 + 0x008)); |
| 951 | if (data & 0x7fe) |
| 952 | NOTICE("ddr3 rank1 init failure\n"); |
| 953 | else |
| 954 | INFO("ddr3 rank1 init pass\n"); |
| 955 | |
| 956 | data = mmio_read_32((0xf712c000 + 0x048)); |
| 957 | data &= ~0xf; |
| 958 | mmio_write_32((0xf712c000 + 0x048), data); |
| 959 | INFO("succeed to set ddrc 533mhz\n"); |
Haojian Zhuang | 934ae71 | 2017-05-24 08:47:49 +0800 | [diff] [blame] | 960 | } |
| 961 | |
Haojian Zhuang | e18de67 | 2018-04-11 19:05:32 +0800 | [diff] [blame] | 962 | void set_ddrc_800mhz(void) |
Haojian Zhuang | 934ae71 | 2017-05-24 08:47:49 +0800 | [diff] [blame] | 963 | { |
| 964 | unsigned int data; |
| 965 | |
| 966 | mmio_write_32((0xf7032000 + 0x580), 0x2); |
| 967 | mmio_write_32((0xf7032000 + 0x5a8), 0x1003); |
| 968 | data = mmio_read_32((0xf7032000 + 0x104)); |
| 969 | data &= 0xfffffcff; |
| 970 | mmio_write_32((0xf7032000 + 0x104), data); |
| 971 | |
| 972 | mmio_write_32((0xf7030000 + 0x050), 0x30); |
| 973 | mmio_write_32((0xf7030000 + 0x240), 0x5ffff); |
| 974 | mmio_write_32((0xf7030000 + 0x344), 0xf5ff); |
| 975 | mmio_write_32((0xf712c000 + 0x00c), 0x400); |
Haojian Zhuang | e18de67 | 2018-04-11 19:05:32 +0800 | [diff] [blame] | 976 | mmio_write_32((0xf712c000 + 0x00c), 0x400); |
Haojian Zhuang | 934ae71 | 2017-05-24 08:47:49 +0800 | [diff] [blame] | 977 | mmio_write_32((0xf712c000 + 0x018), 0x7); |
| 978 | mmio_write_32((0xf712c000 + 0x090), 0x5400000); |
| 979 | mmio_write_32((0xf712c000 + 0x258), 0x540); |
| 980 | mmio_write_32((0xf712c000 + 0x2d8), 0x540); |
| 981 | mmio_write_32((0xf712c000 + 0x358), 0x540); |
| 982 | mmio_write_32((0xf712c000 + 0x3d8), 0x540); |
| 983 | mmio_write_32((0xf712c000 + 0x018), 0x0); |
| 984 | mmio_write_32((0xf712c000 + 0x0b0), 0xf00000f); |
| 985 | mmio_write_32((0xf712c000 + 0x0b4), 0xf); |
| 986 | mmio_write_32((0xf712c000 + 0x088), 0x3fff801); |
| 987 | mmio_write_32((0xf712c000 + 0x070), 0x8940000); |
| 988 | |
| 989 | data = mmio_read_32((0xf712c000 + 0x078)); |
| 990 | data |= 4; |
| 991 | mmio_write_32((0xf712c000 + 0x078), data); |
| 992 | mmio_write_32((0xf712c000 + 0x01c), 0x8000080); |
| 993 | data = mmio_read_32((0xf712c000 + 0x020)); |
| 994 | data &= 0xfffffffe; |
| 995 | mmio_write_32((0xf712c000 + 0x020), data); |
| 996 | mmio_write_32((0xf712c000 + 0x1d4), 0xc0000); |
| 997 | mmio_write_32((0xf712c000 + 0x010), 0x500000f); |
| 998 | mmio_write_32((0xf712c000 + 0x014), 0x10); |
| 999 | data = mmio_read_32((0xf712c000 + 0x1e4)); |
| 1000 | data &= 0xffffff00; |
| 1001 | mmio_write_32((0xf712c000 + 0x1e4), data); |
| 1002 | mmio_write_32((0xf712c000 + 0x030), 0xe663ab77); |
| 1003 | mmio_write_32((0xf712c000 + 0x034), 0xea952db); |
| 1004 | mmio_write_32((0xf712c000 + 0x038), 0x200d1cb1); |
| 1005 | mmio_write_32((0xf712c000 + 0x03c), 0xc67d0721); |
| 1006 | mmio_write_32((0xf712c000 + 0x040), 0x3008aa1); |
| 1007 | mmio_write_32((0xf712c000 + 0x064), 0x11a43); |
| 1008 | mmio_write_32((0xf712c000 + 0x068), 0xff0a0000); |
| 1009 | data = mmio_read_32((0xf712c000 + 0x070)); |
| 1010 | data &= 0xffff0000; |
| 1011 | data |= 0x507; |
| 1012 | mmio_write_32((0xf712c000 + 0x070), data); |
| 1013 | data = mmio_read_32((0xf712c000 + 0x048)); |
| 1014 | data |= 0x40000000; |
| 1015 | mmio_write_32((0xf712c000 + 0x048), data); |
| 1016 | data = mmio_read_32((0xf712c000 + 0x020)); |
| 1017 | data &= 0xffffffef; |
| 1018 | mmio_write_32((0xf712c000 + 0x020), data); |
| 1019 | data = mmio_read_32((0xf712c000 + 0x080)); |
| 1020 | data &= 0xffffdfff; |
| 1021 | mmio_write_32((0xf712c000 + 0x080), data); |
| 1022 | mmio_write_32((0xf712c000 + 0x270), 0x3); |
| 1023 | mmio_write_32((0xf712c000 + 0x2f0), 0x3); |
| 1024 | mmio_write_32((0xf712c000 + 0x370), 0x3); |
| 1025 | mmio_write_32((0xf712c000 + 0x3f0), 0x3); |
| 1026 | mmio_write_32((0xf712c000 + 0x048), 0xd0420900); |
| 1027 | |
| 1028 | mmio_write_32((0xf7128000 + 0x040), 0x2001); |
| 1029 | mmio_write_32((0xf712c000 + 0x004), 0x140f); |
| 1030 | do { |
| 1031 | data = mmio_read_32((0xf712c000 + 0x004)); |
| 1032 | } while (data & 1); |
| 1033 | data = mmio_read_32((0xf712c000 + 0x008)); |
| 1034 | if (data & 0x7fe) { |
| 1035 | WARN("failed to init lpddr3 rank0 dram phy\n"); |
| 1036 | return; |
| 1037 | } |
Haojian Zhuang | e18de67 | 2018-04-11 19:05:32 +0800 | [diff] [blame] | 1038 | cat_533mhz_800mhz(); |
| 1039 | |
| 1040 | mmio_write_32((0xf712c000 + 0x004), 0xf1); |
| 1041 | mmio_write_32((0xf7128000 + 0x050), 0x100023); |
| 1042 | mmio_write_32((0xf7128000 + 0x060), 0x133); |
| 1043 | mmio_write_32((0xf7128000 + 0x064), 0x133); |
| 1044 | mmio_write_32((0xf7128000 + 0x200), 0xa1000); |
| 1045 | |
| 1046 | mmio_write_32((0xf7128000 + 0x100), 0x755a9d12); |
| 1047 | mmio_write_32((0xf7128000 + 0x104), 0x1753b055); |
| 1048 | mmio_write_32((0xf7128000 + 0x108), 0x7401505f); |
| 1049 | mmio_write_32((0xf7128000 + 0x10c), 0x578ca244); |
| 1050 | mmio_write_32((0xf7128000 + 0x110), 0x10700000); |
| 1051 | mmio_write_32((0xf7128000 + 0x114), 0x13141306); |
| 1052 | mmio_write_32((0xf7128000 + 0x118), 0x44); |
| 1053 | do { |
| 1054 | data = mmio_read_32((0xf712c000 + 0x004)); |
| 1055 | } while (data & 1); |
| 1056 | data = mmio_read_32((0xf712c000 + 0x008)); |
| 1057 | if (data & 0x7fe) { |
| 1058 | NOTICE("fail to init ddr3 rank0\n"); |
| 1059 | return; |
| 1060 | } |
| 1061 | ddrx_rdet(); |
| 1062 | ddrx_wdet(); |
| 1063 | |
| 1064 | data = mmio_read_32((0xf712c000 + 0x048)); |
| 1065 | data |= 1; |
| 1066 | mmio_write_32((0xf712c000 + 0x048), data); |
| 1067 | mmio_write_32((0xf712c000 + 0x004), 0x21); |
| 1068 | do { |
| 1069 | data = mmio_read_32((0xf712c000 + 0x004)); |
| 1070 | } while (data & 1); |
| 1071 | |
| 1072 | data = mmio_read_32((0xf712c000 + 0x008)); |
| 1073 | if (data & 0x7fe) |
| 1074 | NOTICE("ddr3 rank1 init failure\n"); |
| 1075 | else |
| 1076 | INFO("ddr3 rank1 init pass\n"); |
| 1077 | |
| 1078 | data = mmio_read_32((0xf712c000 + 0x048)); |
| 1079 | data &= ~0xf; |
| 1080 | mmio_write_32((0xf712c000 + 0x048), data); |
| 1081 | INFO("succeed to set ddrc 800mhz\n"); |
Haojian Zhuang | 934ae71 | 2017-05-24 08:47:49 +0800 | [diff] [blame] | 1082 | } |
| 1083 | |
Haojian Zhuang | e18de67 | 2018-04-11 19:05:32 +0800 | [diff] [blame] | 1084 | static void ddrc_common_init(int freq) |
Haojian Zhuang | 934ae71 | 2017-05-24 08:47:49 +0800 | [diff] [blame] | 1085 | { |
| 1086 | unsigned int data; |
| 1087 | |
| 1088 | mmio_write_32((0xf7120000 + 0x020), 0x1); |
| 1089 | mmio_write_32((0xf7120000 + 0x100), 0x1700); |
| 1090 | mmio_write_32((0xf7120000 + 0x104), 0x71040004); |
| 1091 | mmio_write_32((0xf7121400 + 0x104), 0xf); |
| 1092 | mmio_write_32((0xf7121800 + 0x104), 0xf); |
Haojian Zhuang | 934ae71 | 2017-05-24 08:47:49 +0800 | [diff] [blame] | 1093 | mmio_write_32((0xf7121c00 + 0x104), 0xf); |
| 1094 | mmio_write_32((0xf7122000 + 0x104), 0xf); |
| 1095 | mmio_write_32((0xf7128000 + 0x02c), 0x6); |
Haojian Zhuang | e18de67 | 2018-04-11 19:05:32 +0800 | [diff] [blame] | 1096 | mmio_write_32((0xf7128000 + 0x020), 0x30003); |
Haojian Zhuang | 934ae71 | 2017-05-24 08:47:49 +0800 | [diff] [blame] | 1097 | mmio_write_32((0xf7128000 + 0x028), 0x310201); |
| 1098 | mmio_write_32((0xf712c000 + 0x1e4), 0xfe007600); |
| 1099 | mmio_write_32((0xf7128000 + 0x01c), 0xaf001); |
| 1100 | |
| 1101 | |
| 1102 | data = mmio_read_32((0xf7128000 + 0x280)); |
| 1103 | data |= 1 << 7; |
| 1104 | mmio_write_32((0xf7128000 + 0x280), data); |
| 1105 | mmio_write_32((0xf7128000 + 0x244), 0x3); |
| 1106 | |
Haojian Zhuang | e18de67 | 2018-04-11 19:05:32 +0800 | [diff] [blame] | 1107 | if (freq == DDR_FREQ_800M) |
| 1108 | mmio_write_32((0xf7128000 + 0x240), 167 * (freq / 2) / 1024); |
Haojian Zhuang | 934ae71 | 2017-05-24 08:47:49 +0800 | [diff] [blame] | 1109 | else |
Haojian Zhuang | e18de67 | 2018-04-11 19:05:32 +0800 | [diff] [blame] | 1110 | mmio_write_32((0xf7128000 + 0x240), 167 * freq / 1024); |
Haojian Zhuang | 934ae71 | 2017-05-24 08:47:49 +0800 | [diff] [blame] | 1111 | |
| 1112 | data = mmio_read_32((0xf712c000 + 0x080)); |
| 1113 | data &= 0xffff; |
| 1114 | data |= 0x4002000; |
| 1115 | mmio_write_32((0xf712c000 + 0x080), data); |
| 1116 | mmio_write_32((0xf7128000 + 0x000), 0x0); |
| 1117 | do { |
| 1118 | data = mmio_read_32((0xf7128000 + 0x294)); |
| 1119 | } while (data & 1); |
| 1120 | mmio_write_32((0xf7128000 + 0x000), 0x2); |
| 1121 | } |
| 1122 | |
| 1123 | |
| 1124 | static int dienum_det_and_rowcol_cfg(void) |
| 1125 | { |
| 1126 | unsigned int data; |
| 1127 | |
| 1128 | mmio_write_32((0xf7128000 + 0x210), 0x87); |
| 1129 | mmio_write_32((0xf7128000 + 0x218), 0x10000); |
| 1130 | mmio_write_32((0xf7128000 + 0x00c), 0x1); |
| 1131 | do { |
| 1132 | data = mmio_read_32((0xf7128000 + 0x00c)); |
| 1133 | } while (data & 1); |
| 1134 | data = mmio_read_32((0xf7128000 + 0x4a8)) & 0xfc; |
| 1135 | switch (data) { |
| 1136 | case 0x18: |
| 1137 | mmio_write_32((0xf7128000 + 0x060), 0x132); |
| 1138 | mmio_write_32((0xf7128000 + 0x064), 0x132); |
| 1139 | mmio_write_32((0xf7120000 + 0x100), 0x1600); |
| 1140 | mmio_write_32((0xf7120000 + 0x104), 0x71040004); |
Haojian Zhuang | da7109a | 2018-04-11 19:05:59 +0800 | [diff] [blame] | 1141 | mmio_write_32(MEMORY_AXI_DDR_CAPACITY_ADDR, 0x40000000); |
Haojian Zhuang | 934ae71 | 2017-05-24 08:47:49 +0800 | [diff] [blame] | 1142 | break; |
| 1143 | case 0x1c: |
| 1144 | mmio_write_32((0xf7128000 + 0x060), 0x142); |
| 1145 | mmio_write_32((0xf7128000 + 0x064), 0x142); |
| 1146 | mmio_write_32((0xf7120000 + 0x100), 0x1700); |
| 1147 | mmio_write_32((0xf7120000 + 0x104), 0x71040004); |
Haojian Zhuang | da7109a | 2018-04-11 19:05:59 +0800 | [diff] [blame] | 1148 | mmio_write_32(MEMORY_AXI_DDR_CAPACITY_ADDR, 0x80000000); |
Haojian Zhuang | 934ae71 | 2017-05-24 08:47:49 +0800 | [diff] [blame] | 1149 | break; |
| 1150 | case 0x58: |
| 1151 | mmio_write_32((0xf7128000 + 0x060), 0x133); |
| 1152 | mmio_write_32((0xf7128000 + 0x064), 0x133); |
| 1153 | mmio_write_32((0xf7120000 + 0x100), 0x1700); |
| 1154 | mmio_write_32((0xf7120000 + 0x104), 0x71040004); |
Haojian Zhuang | da7109a | 2018-04-11 19:05:59 +0800 | [diff] [blame] | 1155 | mmio_write_32(MEMORY_AXI_DDR_CAPACITY_ADDR, 0x80000000); |
Haojian Zhuang | 934ae71 | 2017-05-24 08:47:49 +0800 | [diff] [blame] | 1156 | break; |
| 1157 | default: |
Haojian Zhuang | da7109a | 2018-04-11 19:05:59 +0800 | [diff] [blame] | 1158 | mmio_write_32(MEMORY_AXI_DDR_CAPACITY_ADDR, 0x80000000); |
Haojian Zhuang | 934ae71 | 2017-05-24 08:47:49 +0800 | [diff] [blame] | 1159 | break; |
| 1160 | } |
| 1161 | if (!data) |
| 1162 | return -EINVAL; |
| 1163 | return 0; |
| 1164 | } |
| 1165 | |
| 1166 | static int detect_ddr_chip_info(void) |
| 1167 | { |
| 1168 | unsigned int data, mr5, mr6, mr7; |
| 1169 | |
| 1170 | mmio_write_32((0xf7128000 + 0x210), 0x57); |
| 1171 | mmio_write_32((0xf7128000 + 0x218), 0x10000); |
| 1172 | mmio_write_32((0xf7128000 + 0x00c), 0x1); |
| 1173 | |
| 1174 | do { |
| 1175 | data = mmio_read_32((0xf7128000 + 0x00c)); |
| 1176 | } while (data & 1); |
| 1177 | |
| 1178 | data = mmio_read_32((0xf7128000 + 0x4a8)); |
| 1179 | mr5 = data & 0xff; |
| 1180 | switch (mr5) { |
| 1181 | case 1: |
| 1182 | INFO("Samsung DDR\n"); |
| 1183 | break; |
| 1184 | case 6: |
| 1185 | INFO("Hynix DDR\n"); |
| 1186 | break; |
| 1187 | case 3: |
| 1188 | INFO("Elpida DDR\n"); |
| 1189 | break; |
| 1190 | default: |
| 1191 | INFO("DDR from other vendors\n"); |
| 1192 | break; |
| 1193 | } |
| 1194 | |
| 1195 | mmio_write_32((0xf7128000 + 0x210), 0x67); |
| 1196 | mmio_write_32((0xf7128000 + 0x218), 0x10000); |
| 1197 | mmio_write_32((0xf7128000 + 0x00c), 0x1); |
| 1198 | do { |
| 1199 | data = mmio_read_32((0xf7128000 + 0x00c)); |
| 1200 | } while (data & 1); |
| 1201 | data = mmio_read_32((0xf7128000 + 0x4a8)); |
| 1202 | mr6 = data & 0xff; |
| 1203 | mmio_write_32((0xf7128000 + 0x210), 0x77); |
| 1204 | mmio_write_32((0xf7128000 + 0x218), 0x10000); |
| 1205 | mmio_write_32((0xf7128000 + 0x00c), 0x1); |
| 1206 | do { |
| 1207 | data = mmio_read_32((0xf7128000 + 0x00c)); |
| 1208 | } while (data & 1); |
| 1209 | data = mmio_read_32((0xf7128000 + 0x4a8)); |
| 1210 | mr7 = data & 0xff; |
| 1211 | data = mr5 + (mr6 << 8) + (mr7 << 16); |
| 1212 | return data; |
| 1213 | } |
| 1214 | |
Haojian Zhuang | e18de67 | 2018-04-11 19:05:32 +0800 | [diff] [blame] | 1215 | void ddr_phy_reset(void) |
Haojian Zhuang | 934ae71 | 2017-05-24 08:47:49 +0800 | [diff] [blame] | 1216 | { |
Haojian Zhuang | e18de67 | 2018-04-11 19:05:32 +0800 | [diff] [blame] | 1217 | mmio_write_32(0xf7030340, 0xa000); |
| 1218 | mmio_write_32(0xf7030344, 0xa000); |
| 1219 | } |
Haojian Zhuang | 934ae71 | 2017-05-24 08:47:49 +0800 | [diff] [blame] | 1220 | |
Haojian Zhuang | da7109a | 2018-04-11 19:05:59 +0800 | [diff] [blame] | 1221 | void lpddrx_save_ddl_para_bypass(uint32_t *ddr_ddl_para, unsigned int index) |
| 1222 | { |
| 1223 | uint32_t value; |
| 1224 | uint32_t cnt = index; |
| 1225 | uint32_t i; |
| 1226 | |
| 1227 | for (i = 0; i < 4; i++) { |
| 1228 | value = mmio_read_32(0xf712c000 + 0x22c + i * 0x80); |
| 1229 | ddr_ddl_para[cnt++] = value; |
| 1230 | value = mmio_read_32(0xf712c000 + 0x23c + i * 0x80); |
| 1231 | ddr_ddl_para[cnt++] = value; |
| 1232 | value = mmio_read_32(0xf712c000 + 0x240 + i * 0x80); |
| 1233 | ddr_ddl_para[cnt++] = value; |
| 1234 | value = mmio_read_32(0xf712c000 + 0x640 + i * 0x80); |
| 1235 | ddr_ddl_para[cnt++] = value; |
| 1236 | } |
| 1237 | } |
| 1238 | |
| 1239 | void lpddrx_save_ddl_para_mission(uint32_t *ddr_ddl_para, unsigned int index) |
| 1240 | { |
| 1241 | uint32_t value; |
| 1242 | uint32_t cnt = index; |
| 1243 | uint32_t i; |
| 1244 | |
| 1245 | value = mmio_read_32(0xf712c000 + 0x140); |
| 1246 | ddr_ddl_para[cnt++] = value; |
| 1247 | value = mmio_read_32(0xf712c000 + 0x144); |
| 1248 | ddr_ddl_para[cnt++] = value; |
| 1249 | value = mmio_read_32(0xf712c000 + 0x148); |
| 1250 | ddr_ddl_para[cnt++] = value; |
| 1251 | value = mmio_read_32(0xf712c000 + 0x14c); |
| 1252 | ddr_ddl_para[cnt++] = value; |
| 1253 | value = mmio_read_32(0xf712c000 + 0x150); |
| 1254 | ddr_ddl_para[cnt++] = value; |
| 1255 | value = mmio_read_32(0xf712c000 + 0x1d4); |
| 1256 | ddr_ddl_para[cnt++] = value; |
| 1257 | for (i = 0; i < 4; i++) { |
| 1258 | value = mmio_read_32(0xf712c000 + 0x210 + i * 0x80); |
| 1259 | ddr_ddl_para[cnt++] = value; |
| 1260 | value = mmio_read_32(0xf712c000 + 0x214 + i * 0x80); |
| 1261 | ddr_ddl_para[cnt++] = value; |
| 1262 | value = mmio_read_32(0xf712c000 + 0x218 + i * 0x80); |
| 1263 | ddr_ddl_para[cnt++] = value; |
| 1264 | value = mmio_read_32(0xf712c000 + 0x21c + i * 0x80); |
| 1265 | ddr_ddl_para[cnt++] = value; |
| 1266 | value = mmio_read_32(0xf712c000 + 0x220 + i * 0x80); |
| 1267 | ddr_ddl_para[cnt++] = value; |
| 1268 | value = mmio_read_32(0xf712c000 + 0x224 + i * 0x80); |
| 1269 | ddr_ddl_para[cnt++] = value; |
| 1270 | value = mmio_read_32(0xf712c000 + 0x228 + i * 0x80); |
| 1271 | ddr_ddl_para[cnt++] = value; |
| 1272 | value = mmio_read_32(0xf712c000 + 0x22c + i * 0x80); |
| 1273 | ddr_ddl_para[cnt++] = value; |
| 1274 | value = mmio_read_32(0xf712c000 + 0x230 + i * 0x80); |
| 1275 | ddr_ddl_para[cnt++] = value; |
| 1276 | value = mmio_read_32(0xf712c000 + 0x234 + i * 0x80); |
| 1277 | ddr_ddl_para[cnt++] = value; |
| 1278 | value = mmio_read_32(0xf712c000 + 0x238 + i * 0x80); |
| 1279 | ddr_ddl_para[cnt++] = value; |
| 1280 | value = mmio_read_32(0xf712c000 + 0x23c + i * 0x80); |
| 1281 | ddr_ddl_para[cnt++] = value; |
| 1282 | value = mmio_read_32(0xf712c000 + 0x240 + i * 0x80); |
| 1283 | ddr_ddl_para[cnt++] = value; |
| 1284 | value = mmio_read_32(0xf712c000 + 0x640 + i * 0x80); |
| 1285 | ddr_ddl_para[cnt++] = value; |
| 1286 | } |
| 1287 | value = mmio_read_32(0xf712c000 + 0x168); |
| 1288 | ddr_ddl_para[cnt++] = value; |
| 1289 | value = mmio_read_32(0xf712c000 + 0x24c + 0 * 0x80); |
| 1290 | ddr_ddl_para[cnt++] = value; |
| 1291 | value = mmio_read_32(0xf712c000 + 0x24c + 2 * 0x80); |
| 1292 | ddr_ddl_para[cnt++] = value; |
| 1293 | } |
| 1294 | |
Haojian Zhuang | e18de67 | 2018-04-11 19:05:32 +0800 | [diff] [blame] | 1295 | int lpddr3_freq_init(int freq) |
| 1296 | { |
| 1297 | set_ddrc_150mhz(); |
Haojian Zhuang | da7109a | 2018-04-11 19:05:59 +0800 | [diff] [blame] | 1298 | lpddrx_save_ddl_para_bypass((uint32_t *)MEMORY_AXI_DDR_DDL_ADDR, 0); |
Haojian Zhuang | e18de67 | 2018-04-11 19:05:32 +0800 | [diff] [blame] | 1299 | if (freq > DDR_FREQ_150M) { |
| 1300 | ddr_phy_reset(); |
| 1301 | set_ddrc_266mhz(); |
Haojian Zhuang | da7109a | 2018-04-11 19:05:59 +0800 | [diff] [blame] | 1302 | lpddrx_save_ddl_para_bypass((uint32_t *)MEMORY_AXI_DDR_DDL_ADDR, |
| 1303 | 16); |
Haojian Zhuang | 934ae71 | 2017-05-24 08:47:49 +0800 | [diff] [blame] | 1304 | } |
Haojian Zhuang | e18de67 | 2018-04-11 19:05:32 +0800 | [diff] [blame] | 1305 | if (freq > DDR_FREQ_266M) { |
| 1306 | ddr_phy_reset(); |
| 1307 | set_ddrc_400mhz(); |
Haojian Zhuang | da7109a | 2018-04-11 19:05:59 +0800 | [diff] [blame] | 1308 | lpddrx_save_ddl_para_bypass((uint32_t *)MEMORY_AXI_DDR_DDL_ADDR, |
| 1309 | 16 * 2); |
Haojian Zhuang | 934ae71 | 2017-05-24 08:47:49 +0800 | [diff] [blame] | 1310 | } |
Haojian Zhuang | e18de67 | 2018-04-11 19:05:32 +0800 | [diff] [blame] | 1311 | if (freq > DDR_FREQ_400M) { |
| 1312 | ddr_phy_reset(); |
| 1313 | set_ddrc_533mhz(); |
Haojian Zhuang | da7109a | 2018-04-11 19:05:59 +0800 | [diff] [blame] | 1314 | lpddrx_save_ddl_para_mission((uint32_t *)MEMORY_AXI_DDR_DDL_ADDR, |
| 1315 | 16 * 3); |
Haojian Zhuang | 934ae71 | 2017-05-24 08:47:49 +0800 | [diff] [blame] | 1316 | } |
Haojian Zhuang | e18de67 | 2018-04-11 19:05:32 +0800 | [diff] [blame] | 1317 | if (freq > DDR_FREQ_533M) { |
| 1318 | ddr_phy_reset(); |
| 1319 | set_ddrc_800mhz(); |
Haojian Zhuang | da7109a | 2018-04-11 19:05:59 +0800 | [diff] [blame] | 1320 | lpddrx_save_ddl_para_mission((uint32_t *)MEMORY_AXI_DDR_DDL_ADDR, |
| 1321 | 16 * 3 + 61); |
Haojian Zhuang | e18de67 | 2018-04-11 19:05:32 +0800 | [diff] [blame] | 1322 | } |
Haojian Zhuang | 934ae71 | 2017-05-24 08:47:49 +0800 | [diff] [blame] | 1323 | return 0; |
| 1324 | } |
| 1325 | |
| 1326 | static void init_ddr(int freq) |
| 1327 | { |
| 1328 | unsigned int data; |
| 1329 | int ret; |
| 1330 | |
| 1331 | |
| 1332 | data = mmio_read_32((0xf7032000 + 0x030)); |
| 1333 | data |= 1; |
| 1334 | mmio_write_32((0xf7032000 + 0x030), data); |
| 1335 | data = mmio_read_32((0xf7032000 + 0x010)); |
| 1336 | data |= 1; |
| 1337 | mmio_write_32((0xf7032000 + 0x010), data); |
| 1338 | |
Haojian Zhuang | e18de67 | 2018-04-11 19:05:32 +0800 | [diff] [blame] | 1339 | udelay(300); |
Haojian Zhuang | 934ae71 | 2017-05-24 08:47:49 +0800 | [diff] [blame] | 1340 | do { |
| 1341 | data = mmio_read_32((0xf7032000 + 0x030)); |
| 1342 | data &= 3 << 28; |
| 1343 | } while (data != (3 << 28)); |
| 1344 | do { |
| 1345 | data = mmio_read_32((0xf7032000 + 0x010)); |
| 1346 | data &= 3 << 28; |
| 1347 | } while (data != (3 << 28)); |
| 1348 | |
| 1349 | ret = lpddr3_freq_init(freq); |
| 1350 | if (ret) |
| 1351 | return; |
| 1352 | } |
| 1353 | |
| 1354 | static void init_ddrc_qos(void) |
| 1355 | { |
| 1356 | unsigned int port, data; |
| 1357 | |
| 1358 | mmio_write_32((0xf7124000 + 0x088), 1); |
| 1359 | |
| 1360 | port = 0; |
| 1361 | mmio_write_32((0xf7120000 + 0x200 + port * 0x10), 0x1210); |
| 1362 | mmio_write_32((0xf7120000 + 0x204 + port * 0x10), 0x11111111); |
| 1363 | mmio_write_32((0xf7120000 + 0x208 + port * 0x10), 0x11111111); |
| 1364 | mmio_write_32((0xf7120000 + 0x400 + 0 * 0x10), 0x001d0007); |
| 1365 | |
| 1366 | for (port = 3; port <= 4; port++) { |
| 1367 | mmio_write_32((0xf7120000 + 0x200 + port * 0x10), 0x1210); |
| 1368 | mmio_write_32((0xf7120000 + 0x204 + port * 0x10), 0x77777777); |
| 1369 | mmio_write_32((0xf7120000 + 0x208 + port * 0x10), 0x77777777); |
| 1370 | } |
| 1371 | |
| 1372 | port = 1; |
| 1373 | mmio_write_32((0xf7120000 + 0x200 + port * 0x10), 0x30000); |
| 1374 | mmio_write_32((0xf7120000 + 0x204 + port * 0x10), 0x1234567); |
| 1375 | mmio_write_32((0xf7120000 + 0x208 + port * 0x10), 0x1234567); |
| 1376 | |
| 1377 | mmio_write_32((0xf7124000 + 0x1f0), 0); |
| 1378 | mmio_write_32((0xf7124000 + 0x0bc), 0x3020100); |
| 1379 | mmio_write_32((0xf7124000 + 0x0d0), 0x3020100); |
| 1380 | mmio_write_32((0xf7124000 + 0x1f4), 0x01000100); |
| 1381 | mmio_write_32((0xf7124000 + 0x08c + 0 * 4), 0xd0670402); |
| 1382 | mmio_write_32((0xf7124000 + 0x068 + 0 * 4), 0x31); |
| 1383 | mmio_write_32((0xf7124000 + 0x000), 0x7); |
| 1384 | |
| 1385 | data = mmio_read_32((0xf7124000 + 0x09c)); |
| 1386 | data &= ~0xff0000; |
| 1387 | data |= 0x400000; |
| 1388 | mmio_write_32((0xf7124000 + 0x09c), data); |
| 1389 | data = mmio_read_32((0xf7124000 + 0x0ac)); |
| 1390 | data &= ~0xff0000; |
| 1391 | data |= 0x400000; |
| 1392 | mmio_write_32((0xf7124000 + 0x0ac), data); |
| 1393 | port = 2; |
| 1394 | mmio_write_32((0xf7120000 + 0x200 + port * 0x10), 0x30000); |
| 1395 | mmio_write_32((0xf7120000 + 0x204 + port * 0x10), 0x1234567); |
| 1396 | mmio_write_32((0xf7120000 + 0x208 + port * 0x10), 0x1234567); |
| 1397 | |
| 1398 | |
| 1399 | mmio_write_32((0xf7124000 + 0x09c), 0xff7fff); |
| 1400 | mmio_write_32((0xf7124000 + 0x0a0), 0xff); |
| 1401 | mmio_write_32((0xf7124000 + 0x0ac), 0xff7fff); |
| 1402 | mmio_write_32((0xf7124000 + 0x0b0), 0xff); |
| 1403 | mmio_write_32((0xf7124000 + 0x0bc), 0x3020100); |
| 1404 | mmio_write_32((0xf7124000 + 0x0d0), 0x3020100); |
| 1405 | } |
| 1406 | |
Haojian Zhuang | e18de67 | 2018-04-11 19:05:32 +0800 | [diff] [blame] | 1407 | void hikey_ddr_init(unsigned int ddr_freq) |
Haojian Zhuang | 934ae71 | 2017-05-24 08:47:49 +0800 | [diff] [blame] | 1408 | { |
| 1409 | uint32_t data; |
| 1410 | |
Haojian Zhuang | e18de67 | 2018-04-11 19:05:32 +0800 | [diff] [blame] | 1411 | assert((ddr_freq == DDR_FREQ_150M) || (ddr_freq == DDR_FREQ_266M) || |
| 1412 | (ddr_freq == DDR_FREQ_400M) || (ddr_freq == DDR_FREQ_533M) || |
| 1413 | (ddr_freq == DDR_FREQ_800M)); |
Haojian Zhuang | 934ae71 | 2017-05-24 08:47:49 +0800 | [diff] [blame] | 1414 | init_pll(); |
| 1415 | init_freq(); |
| 1416 | |
Haojian Zhuang | e18de67 | 2018-04-11 19:05:32 +0800 | [diff] [blame] | 1417 | init_ddr(ddr_freq); |
Haojian Zhuang | 934ae71 | 2017-05-24 08:47:49 +0800 | [diff] [blame] | 1418 | |
Haojian Zhuang | e18de67 | 2018-04-11 19:05:32 +0800 | [diff] [blame] | 1419 | ddrc_common_init(ddr_freq); |
Haojian Zhuang | 934ae71 | 2017-05-24 08:47:49 +0800 | [diff] [blame] | 1420 | dienum_det_and_rowcol_cfg(); |
| 1421 | detect_ddr_chip_info(); |
| 1422 | |
Haojian Zhuang | e18de67 | 2018-04-11 19:05:32 +0800 | [diff] [blame] | 1423 | if ((ddr_freq == DDR_FREQ_400M) || (ddr_freq == DDR_FREQ_800M)) { |
| 1424 | data = mmio_read_32(0xf7032000 + 0x010); |
| 1425 | data &= ~0x1; |
| 1426 | mmio_write_32(0xf7032000 + 0x010, data); |
| 1427 | } else if ((ddr_freq == DDR_FREQ_266M) || (ddr_freq == DDR_FREQ_533M)) { |
| 1428 | data = mmio_read_32(0xf7032000 + 0x030); |
| 1429 | data &= ~0x1; |
| 1430 | mmio_write_32(0xf7032000 + 0x030, data); |
| 1431 | } else { |
| 1432 | data = mmio_read_32(0xf7032000 + 0x010); |
| 1433 | data &= ~0x1; |
| 1434 | mmio_write_32(0xf7032000 + 0x010, data); |
| 1435 | data = mmio_read_32(0xf7032000 + 0x030); |
| 1436 | data &= ~0x1; |
| 1437 | mmio_write_32(0xf7032000 + 0x030, data); |
| 1438 | } |
| 1439 | dsb(); |
| 1440 | isb(); |
Haojian Zhuang | 934ae71 | 2017-05-24 08:47:49 +0800 | [diff] [blame] | 1441 | |
| 1442 | /* |
| 1443 | * Test memory access. Do not use address 0x0 because the compiler |
| 1444 | * may assume it is not a valid address and generate incorrect code |
| 1445 | * (GCC 4.9.1 without -fno-delete-null-pointer-checks for instance). |
| 1446 | */ |
| 1447 | mmio_write_32(0x4, 0xa5a55a5a); |
| 1448 | INFO("ddr test value:0x%x\n", mmio_read_32(0x4)); |
| 1449 | init_ddrc_qos(); |
| 1450 | } |