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