Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 Red Hat Inc. |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the |
| 6 | * "Software"), to deal in the Software without restriction, including |
| 7 | * without limitation the rights to use, copy, modify, merge, publish, |
| 8 | * distribute, sub license, and/or sell copies of the Software, and to |
| 9 | * permit persons to whom the Software is furnished to do so, subject to |
| 10 | * the following conditions: |
| 11 | * |
| 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL |
| 15 | * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, |
| 16 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 17 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
| 18 | * USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 19 | * |
| 20 | * The above copyright notice and this permission notice (including the |
| 21 | * next paragraph) shall be included in all copies or substantial portions |
| 22 | * of the Software. |
| 23 | * |
| 24 | */ |
| 25 | /* |
| 26 | * Authors: Dave Airlie <airlied@redhat.com> |
| 27 | */ |
| 28 | |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 29 | #include <drm/drmP.h> |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 30 | #include "ast_drv.h" |
| 31 | |
| 32 | #include "ast_dram_tables.h" |
| 33 | |
| 34 | static void ast_init_dram_2300(struct drm_device *dev); |
| 35 | |
| 36 | static void |
| 37 | ast_enable_vga(struct drm_device *dev) |
| 38 | { |
| 39 | struct ast_private *ast = dev->dev_private; |
| 40 | |
| 41 | ast_io_write8(ast, 0x43, 0x01); |
| 42 | ast_io_write8(ast, 0x42, 0x01); |
| 43 | } |
| 44 | |
| 45 | #if 0 /* will use later */ |
| 46 | static bool |
| 47 | ast_is_vga_enabled(struct drm_device *dev) |
| 48 | { |
| 49 | struct ast_private *ast = dev->dev_private; |
| 50 | u8 ch; |
| 51 | |
| 52 | if (ast->chip == AST1180) { |
| 53 | /* TODO 1180 */ |
| 54 | } else { |
| 55 | ch = ast_io_read8(ast, 0x43); |
| 56 | if (ch) { |
| 57 | ast_open_key(ast); |
| 58 | ch = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb6, 0xff); |
| 59 | return ch & 0x04; |
| 60 | } |
| 61 | } |
| 62 | return 0; |
| 63 | } |
| 64 | #endif |
| 65 | |
| 66 | static const u8 extreginfo[] = { 0x0f, 0x04, 0x1c, 0xff }; |
| 67 | static const u8 extreginfo_ast2300a0[] = { 0x0f, 0x04, 0x1c, 0xff }; |
| 68 | static const u8 extreginfo_ast2300[] = { 0x0f, 0x04, 0x1f, 0xff }; |
| 69 | |
| 70 | static void |
| 71 | ast_set_def_ext_reg(struct drm_device *dev) |
| 72 | { |
| 73 | struct ast_private *ast = dev->dev_private; |
| 74 | u8 i, index, reg; |
| 75 | const u8 *ext_reg_info; |
| 76 | |
| 77 | /* reset scratch */ |
| 78 | for (i = 0x81; i <= 0x8f; i++) |
| 79 | ast_set_index_reg(ast, AST_IO_CRTC_PORT, i, 0x00); |
| 80 | |
Dave Airlie | 1453bf4 | 2014-03-28 09:18:45 +1000 | [diff] [blame] | 81 | if (ast->chip == AST2300 || ast->chip == AST2400) { |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 82 | if (dev->pdev->revision >= 0x20) |
| 83 | ext_reg_info = extreginfo_ast2300; |
| 84 | else |
| 85 | ext_reg_info = extreginfo_ast2300a0; |
| 86 | } else |
| 87 | ext_reg_info = extreginfo; |
| 88 | |
| 89 | index = 0xa0; |
| 90 | while (*ext_reg_info != 0xff) { |
| 91 | ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, index, 0x00, *ext_reg_info); |
| 92 | index++; |
| 93 | ext_reg_info++; |
| 94 | } |
| 95 | |
| 96 | /* disable standard IO/MEM decode if secondary */ |
| 97 | /* ast_set_index_reg-mask(ast, AST_IO_CRTC_PORT, 0xa1, 0xff, 0x3); */ |
| 98 | |
| 99 | /* Set Ext. Default */ |
| 100 | ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0x8c, 0x00, 0x01); |
| 101 | ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x00, 0x00); |
| 102 | |
| 103 | /* Enable RAMDAC for A1 */ |
| 104 | reg = 0x04; |
Dave Airlie | 1453bf4 | 2014-03-28 09:18:45 +1000 | [diff] [blame] | 105 | if (ast->chip == AST2300 || ast->chip == AST2400) |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 106 | reg |= 0x20; |
| 107 | ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb6, 0xff, reg); |
| 108 | } |
| 109 | |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 110 | static u32 ast_mindwm(struct ast_private *ast, u32 r) |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 111 | { |
Dave Airlie | 318cfa2 | 2014-01-17 11:36:14 +1000 | [diff] [blame] | 112 | uint32_t data; |
| 113 | |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 114 | ast_write32(ast, 0xf004, r & 0xffff0000); |
| 115 | ast_write32(ast, 0xf000, 0x1); |
| 116 | |
Dave Airlie | 318cfa2 | 2014-01-17 11:36:14 +1000 | [diff] [blame] | 117 | do { |
| 118 | data = ast_read32(ast, 0xf004) & 0xffff0000; |
| 119 | } while (data != (r & 0xffff0000)); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 120 | return ast_read32(ast, 0x10000 + (r & 0x0000ffff)); |
| 121 | } |
| 122 | |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 123 | static void ast_moutdwm(struct ast_private *ast, u32 r, u32 v) |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 124 | { |
Dave Airlie | 318cfa2 | 2014-01-17 11:36:14 +1000 | [diff] [blame] | 125 | uint32_t data; |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 126 | ast_write32(ast, 0xf004, r & 0xffff0000); |
| 127 | ast_write32(ast, 0xf000, 0x1); |
Dave Airlie | 318cfa2 | 2014-01-17 11:36:14 +1000 | [diff] [blame] | 128 | do { |
| 129 | data = ast_read32(ast, 0xf004) & 0xffff0000; |
| 130 | } while (data != (r & 0xffff0000)); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 131 | ast_write32(ast, 0x10000 + (r & 0x0000ffff), v); |
| 132 | } |
| 133 | |
| 134 | /* |
| 135 | * AST2100/2150 DLL CBR Setting |
| 136 | */ |
| 137 | #define CBR_SIZE_AST2150 ((16 << 10) - 1) |
| 138 | #define CBR_PASSNUM_AST2150 5 |
| 139 | #define CBR_THRESHOLD_AST2150 10 |
| 140 | #define CBR_THRESHOLD2_AST2150 10 |
| 141 | #define TIMEOUT_AST2150 5000000 |
| 142 | |
| 143 | #define CBR_PATNUM_AST2150 8 |
| 144 | |
| 145 | static const u32 pattern_AST2150[14] = { |
| 146 | 0xFF00FF00, |
| 147 | 0xCC33CC33, |
| 148 | 0xAA55AA55, |
| 149 | 0xFFFE0001, |
| 150 | 0x683501FE, |
| 151 | 0x0F1929B0, |
| 152 | 0x2D0B4346, |
| 153 | 0x60767F02, |
| 154 | 0x6FBE36A6, |
| 155 | 0x3A253035, |
| 156 | 0x3019686D, |
| 157 | 0x41C6167E, |
| 158 | 0x620152BF, |
| 159 | 0x20F050E0 |
| 160 | }; |
| 161 | |
| 162 | static u32 mmctestburst2_ast2150(struct ast_private *ast, u32 datagen) |
| 163 | { |
| 164 | u32 data, timeout; |
| 165 | |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 166 | ast_moutdwm(ast, 0x1e6e0070, 0x00000000); |
| 167 | ast_moutdwm(ast, 0x1e6e0070, 0x00000001 | (datagen << 3)); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 168 | timeout = 0; |
| 169 | do { |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 170 | data = ast_mindwm(ast, 0x1e6e0070) & 0x40; |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 171 | if (++timeout > TIMEOUT_AST2150) { |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 172 | ast_moutdwm(ast, 0x1e6e0070, 0x00000000); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 173 | return 0xffffffff; |
| 174 | } |
| 175 | } while (!data); |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 176 | ast_moutdwm(ast, 0x1e6e0070, 0x00000000); |
| 177 | ast_moutdwm(ast, 0x1e6e0070, 0x00000003 | (datagen << 3)); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 178 | timeout = 0; |
| 179 | do { |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 180 | data = ast_mindwm(ast, 0x1e6e0070) & 0x40; |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 181 | if (++timeout > TIMEOUT_AST2150) { |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 182 | ast_moutdwm(ast, 0x1e6e0070, 0x00000000); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 183 | return 0xffffffff; |
| 184 | } |
| 185 | } while (!data); |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 186 | data = (ast_mindwm(ast, 0x1e6e0070) & 0x80) >> 7; |
| 187 | ast_moutdwm(ast, 0x1e6e0070, 0x00000000); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 188 | return data; |
| 189 | } |
| 190 | |
| 191 | #if 0 /* unused in DDX driver - here for completeness */ |
| 192 | static u32 mmctestsingle2_ast2150(struct ast_private *ast, u32 datagen) |
| 193 | { |
| 194 | u32 data, timeout; |
| 195 | |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 196 | ast_moutdwm(ast, 0x1e6e0070, 0x00000000); |
| 197 | ast_moutdwm(ast, 0x1e6e0070, 0x00000005 | (datagen << 3)); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 198 | timeout = 0; |
| 199 | do { |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 200 | data = ast_mindwm(ast, 0x1e6e0070) & 0x40; |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 201 | if (++timeout > TIMEOUT_AST2150) { |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 202 | ast_moutdwm(ast, 0x1e6e0070, 0x00000000); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 203 | return 0xffffffff; |
| 204 | } |
| 205 | } while (!data); |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 206 | data = (ast_mindwm(ast, 0x1e6e0070) & 0x80) >> 7; |
| 207 | ast_moutdwm(ast, 0x1e6e0070, 0x00000000); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 208 | return data; |
| 209 | } |
| 210 | #endif |
| 211 | |
| 212 | static int cbrtest_ast2150(struct ast_private *ast) |
| 213 | { |
| 214 | int i; |
| 215 | |
| 216 | for (i = 0; i < 8; i++) |
| 217 | if (mmctestburst2_ast2150(ast, i)) |
| 218 | return 0; |
| 219 | return 1; |
| 220 | } |
| 221 | |
| 222 | static int cbrscan_ast2150(struct ast_private *ast, int busw) |
| 223 | { |
| 224 | u32 patcnt, loop; |
| 225 | |
| 226 | for (patcnt = 0; patcnt < CBR_PATNUM_AST2150; patcnt++) { |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 227 | ast_moutdwm(ast, 0x1e6e007c, pattern_AST2150[patcnt]); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 228 | for (loop = 0; loop < CBR_PASSNUM_AST2150; loop++) { |
| 229 | if (cbrtest_ast2150(ast)) |
| 230 | break; |
| 231 | } |
| 232 | if (loop == CBR_PASSNUM_AST2150) |
| 233 | return 0; |
| 234 | } |
| 235 | return 1; |
| 236 | } |
| 237 | |
| 238 | |
| 239 | static void cbrdlli_ast2150(struct ast_private *ast, int busw) |
| 240 | { |
| 241 | u32 dll_min[4], dll_max[4], dlli, data, passcnt; |
| 242 | |
| 243 | cbr_start: |
| 244 | dll_min[0] = dll_min[1] = dll_min[2] = dll_min[3] = 0xff; |
| 245 | dll_max[0] = dll_max[1] = dll_max[2] = dll_max[3] = 0x0; |
| 246 | passcnt = 0; |
| 247 | |
| 248 | for (dlli = 0; dlli < 100; dlli++) { |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 249 | ast_moutdwm(ast, 0x1e6e0068, dlli | (dlli << 8) | (dlli << 16) | (dlli << 24)); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 250 | data = cbrscan_ast2150(ast, busw); |
| 251 | if (data != 0) { |
| 252 | if (data & 0x1) { |
| 253 | if (dll_min[0] > dlli) |
| 254 | dll_min[0] = dlli; |
| 255 | if (dll_max[0] < dlli) |
| 256 | dll_max[0] = dlli; |
| 257 | } |
| 258 | passcnt++; |
| 259 | } else if (passcnt >= CBR_THRESHOLD_AST2150) |
| 260 | goto cbr_start; |
| 261 | } |
| 262 | if (dll_max[0] == 0 || (dll_max[0]-dll_min[0]) < CBR_THRESHOLD_AST2150) |
| 263 | goto cbr_start; |
| 264 | |
| 265 | dlli = dll_min[0] + (((dll_max[0] - dll_min[0]) * 7) >> 4); |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 266 | ast_moutdwm(ast, 0x1e6e0068, dlli | (dlli << 8) | (dlli << 16) | (dlli << 24)); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | |
| 270 | |
| 271 | static void ast_init_dram_reg(struct drm_device *dev) |
| 272 | { |
| 273 | struct ast_private *ast = dev->dev_private; |
| 274 | u8 j; |
| 275 | u32 data, temp, i; |
| 276 | const struct ast_dramstruct *dram_reg_info; |
| 277 | |
| 278 | j = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd0, 0xff); |
| 279 | |
| 280 | if ((j & 0x80) == 0) { /* VGA only */ |
| 281 | if (ast->chip == AST2000) { |
| 282 | dram_reg_info = ast2000_dram_table_data; |
| 283 | ast_write32(ast, 0xf004, 0x1e6e0000); |
| 284 | ast_write32(ast, 0xf000, 0x1); |
| 285 | ast_write32(ast, 0x10100, 0xa8); |
| 286 | |
| 287 | do { |
| 288 | ; |
| 289 | } while (ast_read32(ast, 0x10100) != 0xa8); |
| 290 | } else {/* AST2100/1100 */ |
| 291 | if (ast->chip == AST2100 || ast->chip == 2200) |
| 292 | dram_reg_info = ast2100_dram_table_data; |
| 293 | else |
| 294 | dram_reg_info = ast1100_dram_table_data; |
| 295 | |
| 296 | ast_write32(ast, 0xf004, 0x1e6e0000); |
| 297 | ast_write32(ast, 0xf000, 0x1); |
| 298 | ast_write32(ast, 0x12000, 0x1688A8A8); |
| 299 | do { |
| 300 | ; |
| 301 | } while (ast_read32(ast, 0x12000) != 0x01); |
| 302 | |
| 303 | ast_write32(ast, 0x10000, 0xfc600309); |
| 304 | do { |
| 305 | ; |
| 306 | } while (ast_read32(ast, 0x10000) != 0x01); |
| 307 | } |
| 308 | |
| 309 | while (dram_reg_info->index != 0xffff) { |
| 310 | if (dram_reg_info->index == 0xff00) {/* delay fn */ |
| 311 | for (i = 0; i < 15; i++) |
| 312 | udelay(dram_reg_info->data); |
| 313 | } else if (dram_reg_info->index == 0x4 && ast->chip != AST2000) { |
| 314 | data = dram_reg_info->data; |
| 315 | if (ast->dram_type == AST_DRAM_1Gx16) |
| 316 | data = 0x00000d89; |
| 317 | else if (ast->dram_type == AST_DRAM_1Gx32) |
| 318 | data = 0x00000c8d; |
| 319 | |
| 320 | temp = ast_read32(ast, 0x12070); |
| 321 | temp &= 0xc; |
| 322 | temp <<= 2; |
| 323 | ast_write32(ast, 0x10000 + dram_reg_info->index, data | temp); |
| 324 | } else |
| 325 | ast_write32(ast, 0x10000 + dram_reg_info->index, dram_reg_info->data); |
| 326 | dram_reg_info++; |
| 327 | } |
| 328 | |
| 329 | /* AST 2100/2150 DRAM calibration */ |
| 330 | data = ast_read32(ast, 0x10120); |
| 331 | if (data == 0x5061) { /* 266Mhz */ |
| 332 | data = ast_read32(ast, 0x10004); |
| 333 | if (data & 0x40) |
| 334 | cbrdlli_ast2150(ast, 16); /* 16 bits */ |
| 335 | else |
| 336 | cbrdlli_ast2150(ast, 32); /* 32 bits */ |
| 337 | } |
| 338 | |
| 339 | switch (ast->chip) { |
| 340 | case AST2000: |
| 341 | temp = ast_read32(ast, 0x10140); |
| 342 | ast_write32(ast, 0x10140, temp | 0x40); |
| 343 | break; |
| 344 | case AST1100: |
| 345 | case AST2100: |
| 346 | case AST2200: |
| 347 | case AST2150: |
| 348 | temp = ast_read32(ast, 0x1200c); |
| 349 | ast_write32(ast, 0x1200c, temp & 0xfffffffd); |
| 350 | temp = ast_read32(ast, 0x12040); |
| 351 | ast_write32(ast, 0x12040, temp | 0x40); |
| 352 | break; |
| 353 | default: |
| 354 | break; |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | /* wait ready */ |
| 359 | do { |
| 360 | j = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd0, 0xff); |
| 361 | } while ((j & 0x40) == 0); |
| 362 | } |
| 363 | |
| 364 | void ast_post_gpu(struct drm_device *dev) |
| 365 | { |
| 366 | u32 reg; |
| 367 | struct ast_private *ast = dev->dev_private; |
| 368 | |
| 369 | pci_read_config_dword(ast->dev->pdev, 0x04, ®); |
| 370 | reg |= 0x3; |
| 371 | pci_write_config_dword(ast->dev->pdev, 0x04, reg); |
| 372 | |
| 373 | ast_enable_vga(dev); |
| 374 | ast_open_key(ast); |
| 375 | ast_set_def_ext_reg(dev); |
| 376 | |
Dave Airlie | 1453bf4 | 2014-03-28 09:18:45 +1000 | [diff] [blame] | 377 | if (ast->chip == AST2300 || ast->chip == AST2400) |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 378 | ast_init_dram_2300(dev); |
| 379 | else |
| 380 | ast_init_dram_reg(dev); |
| 381 | } |
| 382 | |
| 383 | /* AST 2300 DRAM settings */ |
| 384 | #define AST_DDR3 0 |
| 385 | #define AST_DDR2 1 |
| 386 | |
| 387 | struct ast2300_dram_param { |
| 388 | u32 dram_type; |
| 389 | u32 dram_chipid; |
| 390 | u32 dram_freq; |
| 391 | u32 vram_size; |
| 392 | u32 odt; |
| 393 | u32 wodt; |
| 394 | u32 rodt; |
| 395 | u32 dram_config; |
| 396 | u32 reg_PERIOD; |
| 397 | u32 reg_MADJ; |
| 398 | u32 reg_SADJ; |
| 399 | u32 reg_MRS; |
| 400 | u32 reg_EMRS; |
| 401 | u32 reg_AC1; |
| 402 | u32 reg_AC2; |
| 403 | u32 reg_DQSIC; |
| 404 | u32 reg_DRV; |
| 405 | u32 reg_IOZ; |
| 406 | u32 reg_DQIDLY; |
| 407 | u32 reg_FREQ; |
| 408 | u32 madj_max; |
| 409 | u32 dll2_finetune_step; |
| 410 | }; |
| 411 | |
| 412 | /* |
| 413 | * DQSI DLL CBR Setting |
| 414 | */ |
Dave Airlie | 318cfa2 | 2014-01-17 11:36:14 +1000 | [diff] [blame] | 415 | #define CBR_SIZE0 ((1 << 10) - 1) |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 416 | #define CBR_SIZE1 ((4 << 10) - 1) |
| 417 | #define CBR_SIZE2 ((64 << 10) - 1) |
| 418 | #define CBR_PASSNUM 5 |
| 419 | #define CBR_PASSNUM2 5 |
| 420 | #define CBR_THRESHOLD 10 |
| 421 | #define CBR_THRESHOLD2 10 |
| 422 | #define TIMEOUT 5000000 |
| 423 | #define CBR_PATNUM 8 |
| 424 | |
| 425 | static const u32 pattern[8] = { |
| 426 | 0xFF00FF00, |
| 427 | 0xCC33CC33, |
| 428 | 0xAA55AA55, |
| 429 | 0x88778877, |
| 430 | 0x92CC4D6E, |
| 431 | 0x543D3CDE, |
| 432 | 0xF1E843C7, |
| 433 | 0x7C61D253 |
| 434 | }; |
| 435 | |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 436 | static int mmc_test_burst(struct ast_private *ast, u32 datagen) |
| 437 | { |
| 438 | u32 data, timeout; |
| 439 | |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 440 | ast_moutdwm(ast, 0x1e6e0070, 0x00000000); |
| 441 | ast_moutdwm(ast, 0x1e6e0070, 0x000000c1 | (datagen << 3)); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 442 | timeout = 0; |
| 443 | do { |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 444 | data = ast_mindwm(ast, 0x1e6e0070) & 0x3000; |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 445 | if (data & 0x2000) { |
| 446 | return 0; |
| 447 | } |
| 448 | if (++timeout > TIMEOUT) { |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 449 | ast_moutdwm(ast, 0x1e6e0070, 0x00000000); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 450 | return 0; |
| 451 | } |
| 452 | } while (!data); |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 453 | ast_moutdwm(ast, 0x1e6e0070, 0x00000000); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 454 | return 1; |
| 455 | } |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 456 | |
| 457 | static int mmc_test_burst2(struct ast_private *ast, u32 datagen) |
| 458 | { |
| 459 | u32 data, timeout; |
| 460 | |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 461 | ast_moutdwm(ast, 0x1e6e0070, 0x00000000); |
| 462 | ast_moutdwm(ast, 0x1e6e0070, 0x00000041 | (datagen << 3)); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 463 | timeout = 0; |
| 464 | do { |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 465 | data = ast_mindwm(ast, 0x1e6e0070) & 0x1000; |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 466 | if (++timeout > TIMEOUT) { |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 467 | ast_moutdwm(ast, 0x1e6e0070, 0x0); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 468 | return -1; |
| 469 | } |
| 470 | } while (!data); |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 471 | data = ast_mindwm(ast, 0x1e6e0078); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 472 | data = (data | (data >> 16)) & 0xffff; |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 473 | ast_moutdwm(ast, 0x1e6e0070, 0x0); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 474 | return data; |
| 475 | } |
| 476 | |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 477 | static int mmc_test_single(struct ast_private *ast, u32 datagen) |
| 478 | { |
| 479 | u32 data, timeout; |
| 480 | |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 481 | ast_moutdwm(ast, 0x1e6e0070, 0x00000000); |
| 482 | ast_moutdwm(ast, 0x1e6e0070, 0x000000c5 | (datagen << 3)); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 483 | timeout = 0; |
| 484 | do { |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 485 | data = ast_mindwm(ast, 0x1e6e0070) & 0x3000; |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 486 | if (data & 0x2000) |
| 487 | return 0; |
| 488 | if (++timeout > TIMEOUT) { |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 489 | ast_moutdwm(ast, 0x1e6e0070, 0x0); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 490 | return 0; |
| 491 | } |
| 492 | } while (!data); |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 493 | ast_moutdwm(ast, 0x1e6e0070, 0x0); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 494 | return 1; |
| 495 | } |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 496 | |
| 497 | static int mmc_test_single2(struct ast_private *ast, u32 datagen) |
| 498 | { |
| 499 | u32 data, timeout; |
| 500 | |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 501 | ast_moutdwm(ast, 0x1e6e0070, 0x00000000); |
| 502 | ast_moutdwm(ast, 0x1e6e0070, 0x00000005 | (datagen << 3)); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 503 | timeout = 0; |
| 504 | do { |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 505 | data = ast_mindwm(ast, 0x1e6e0070) & 0x1000; |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 506 | if (++timeout > TIMEOUT) { |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 507 | ast_moutdwm(ast, 0x1e6e0070, 0x0); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 508 | return -1; |
| 509 | } |
| 510 | } while (!data); |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 511 | data = ast_mindwm(ast, 0x1e6e0078); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 512 | data = (data | (data >> 16)) & 0xffff; |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 513 | ast_moutdwm(ast, 0x1e6e0070, 0x0); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 514 | return data; |
| 515 | } |
| 516 | |
| 517 | static int cbr_test(struct ast_private *ast) |
| 518 | { |
| 519 | u32 data; |
| 520 | int i; |
| 521 | data = mmc_test_single2(ast, 0); |
| 522 | if ((data & 0xff) && (data & 0xff00)) |
| 523 | return 0; |
| 524 | for (i = 0; i < 8; i++) { |
| 525 | data = mmc_test_burst2(ast, i); |
| 526 | if ((data & 0xff) && (data & 0xff00)) |
| 527 | return 0; |
| 528 | } |
| 529 | if (!data) |
| 530 | return 3; |
| 531 | else if (data & 0xff) |
| 532 | return 2; |
| 533 | return 1; |
| 534 | } |
| 535 | |
| 536 | static int cbr_scan(struct ast_private *ast) |
| 537 | { |
| 538 | u32 data, data2, patcnt, loop; |
| 539 | |
| 540 | data2 = 3; |
| 541 | for (patcnt = 0; patcnt < CBR_PATNUM; patcnt++) { |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 542 | ast_moutdwm(ast, 0x1e6e007c, pattern[patcnt]); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 543 | for (loop = 0; loop < CBR_PASSNUM2; loop++) { |
| 544 | if ((data = cbr_test(ast)) != 0) { |
| 545 | data2 &= data; |
| 546 | if (!data2) |
| 547 | return 0; |
| 548 | break; |
| 549 | } |
| 550 | } |
| 551 | if (loop == CBR_PASSNUM2) |
| 552 | return 0; |
| 553 | } |
| 554 | return data2; |
| 555 | } |
| 556 | |
| 557 | static u32 cbr_test2(struct ast_private *ast) |
| 558 | { |
| 559 | u32 data; |
| 560 | |
| 561 | data = mmc_test_burst2(ast, 0); |
| 562 | if (data == 0xffff) |
| 563 | return 0; |
| 564 | data |= mmc_test_single2(ast, 0); |
| 565 | if (data == 0xffff) |
| 566 | return 0; |
| 567 | |
| 568 | return ~data & 0xffff; |
| 569 | } |
| 570 | |
| 571 | static u32 cbr_scan2(struct ast_private *ast) |
| 572 | { |
| 573 | u32 data, data2, patcnt, loop; |
| 574 | |
| 575 | data2 = 0xffff; |
| 576 | for (patcnt = 0; patcnt < CBR_PATNUM; patcnt++) { |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 577 | ast_moutdwm(ast, 0x1e6e007c, pattern[patcnt]); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 578 | for (loop = 0; loop < CBR_PASSNUM2; loop++) { |
| 579 | if ((data = cbr_test2(ast)) != 0) { |
| 580 | data2 &= data; |
| 581 | if (!data) |
| 582 | return 0; |
| 583 | break; |
| 584 | } |
| 585 | } |
| 586 | if (loop == CBR_PASSNUM2) |
| 587 | return 0; |
| 588 | } |
| 589 | return data2; |
| 590 | } |
| 591 | |
Dave Airlie | 318cfa2 | 2014-01-17 11:36:14 +1000 | [diff] [blame] | 592 | static u32 cbr_test3(struct ast_private *ast) |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 593 | { |
Dave Airlie | 318cfa2 | 2014-01-17 11:36:14 +1000 | [diff] [blame] | 594 | if (!mmc_test_burst(ast, 0)) |
| 595 | return 0; |
| 596 | if (!mmc_test_single(ast, 0)) |
| 597 | return 0; |
| 598 | return 1; |
| 599 | } |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 600 | |
Dave Airlie | 318cfa2 | 2014-01-17 11:36:14 +1000 | [diff] [blame] | 601 | static u32 cbr_scan3(struct ast_private *ast) |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 602 | { |
Dave Airlie | 318cfa2 | 2014-01-17 11:36:14 +1000 | [diff] [blame] | 603 | u32 patcnt, loop; |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 604 | |
Dave Airlie | 318cfa2 | 2014-01-17 11:36:14 +1000 | [diff] [blame] | 605 | for (patcnt = 0; patcnt < CBR_PATNUM; patcnt++) { |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 606 | ast_moutdwm(ast, 0x1e6e007c, pattern[patcnt]); |
Dave Airlie | 318cfa2 | 2014-01-17 11:36:14 +1000 | [diff] [blame] | 607 | for (loop = 0; loop < 2; loop++) { |
| 608 | if (cbr_test3(ast)) |
| 609 | break; |
| 610 | } |
| 611 | if (loop == 2) |
| 612 | return 0; |
| 613 | } |
| 614 | return 1; |
| 615 | } |
| 616 | |
| 617 | static bool finetuneDQI_L(struct ast_private *ast, struct ast2300_dram_param *param) |
| 618 | { |
| 619 | u32 gold_sadj[2], dllmin[16], dllmax[16], dlli, data, cnt, mask, passcnt, retry = 0; |
| 620 | bool status = false; |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 621 | FINETUNE_START: |
| 622 | for (cnt = 0; cnt < 16; cnt++) { |
| 623 | dllmin[cnt] = 0xff; |
| 624 | dllmax[cnt] = 0x0; |
| 625 | } |
| 626 | passcnt = 0; |
| 627 | for (dlli = 0; dlli < 76; dlli++) { |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 628 | ast_moutdwm(ast, 0x1E6E0068, 0x00001400 | (dlli << 16) | (dlli << 24)); |
| 629 | ast_moutdwm(ast, 0x1E6E0074, CBR_SIZE1); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 630 | data = cbr_scan2(ast); |
| 631 | if (data != 0) { |
| 632 | mask = 0x00010001; |
| 633 | for (cnt = 0; cnt < 16; cnt++) { |
| 634 | if (data & mask) { |
| 635 | if (dllmin[cnt] > dlli) { |
| 636 | dllmin[cnt] = dlli; |
| 637 | } |
| 638 | if (dllmax[cnt] < dlli) { |
| 639 | dllmax[cnt] = dlli; |
| 640 | } |
| 641 | } |
| 642 | mask <<= 1; |
| 643 | } |
| 644 | passcnt++; |
| 645 | } else if (passcnt >= CBR_THRESHOLD2) { |
| 646 | break; |
| 647 | } |
| 648 | } |
| 649 | gold_sadj[0] = 0x0; |
| 650 | passcnt = 0; |
| 651 | for (cnt = 0; cnt < 16; cnt++) { |
| 652 | if ((dllmax[cnt] > dllmin[cnt]) && ((dllmax[cnt] - dllmin[cnt]) >= CBR_THRESHOLD2)) { |
| 653 | gold_sadj[0] += dllmin[cnt]; |
| 654 | passcnt++; |
| 655 | } |
| 656 | } |
Dave Airlie | 318cfa2 | 2014-01-17 11:36:14 +1000 | [diff] [blame] | 657 | if (retry++ > 10) |
| 658 | goto FINETUNE_DONE; |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 659 | if (passcnt != 16) { |
| 660 | goto FINETUNE_START; |
| 661 | } |
Dave Airlie | 318cfa2 | 2014-01-17 11:36:14 +1000 | [diff] [blame] | 662 | status = true; |
| 663 | FINETUNE_DONE: |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 664 | gold_sadj[0] = gold_sadj[0] >> 4; |
| 665 | gold_sadj[1] = gold_sadj[0]; |
| 666 | |
| 667 | data = 0; |
| 668 | for (cnt = 0; cnt < 8; cnt++) { |
| 669 | data >>= 3; |
| 670 | if ((dllmax[cnt] > dllmin[cnt]) && ((dllmax[cnt] - dllmin[cnt]) >= CBR_THRESHOLD2)) { |
| 671 | dlli = dllmin[cnt]; |
| 672 | if (gold_sadj[0] >= dlli) { |
| 673 | dlli = ((gold_sadj[0] - dlli) * 19) >> 5; |
| 674 | if (dlli > 3) { |
| 675 | dlli = 3; |
| 676 | } |
| 677 | } else { |
| 678 | dlli = ((dlli - gold_sadj[0]) * 19) >> 5; |
| 679 | if (dlli > 4) { |
| 680 | dlli = 4; |
| 681 | } |
| 682 | dlli = (8 - dlli) & 0x7; |
| 683 | } |
| 684 | data |= dlli << 21; |
| 685 | } |
| 686 | } |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 687 | ast_moutdwm(ast, 0x1E6E0080, data); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 688 | |
| 689 | data = 0; |
| 690 | for (cnt = 8; cnt < 16; cnt++) { |
| 691 | data >>= 3; |
| 692 | if ((dllmax[cnt] > dllmin[cnt]) && ((dllmax[cnt] - dllmin[cnt]) >= CBR_THRESHOLD2)) { |
| 693 | dlli = dllmin[cnt]; |
| 694 | if (gold_sadj[1] >= dlli) { |
| 695 | dlli = ((gold_sadj[1] - dlli) * 19) >> 5; |
| 696 | if (dlli > 3) { |
| 697 | dlli = 3; |
| 698 | } else { |
| 699 | dlli = (dlli - 1) & 0x7; |
| 700 | } |
| 701 | } else { |
| 702 | dlli = ((dlli - gold_sadj[1]) * 19) >> 5; |
| 703 | dlli += 1; |
| 704 | if (dlli > 4) { |
| 705 | dlli = 4; |
| 706 | } |
| 707 | dlli = (8 - dlli) & 0x7; |
| 708 | } |
| 709 | data |= dlli << 21; |
| 710 | } |
| 711 | } |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 712 | ast_moutdwm(ast, 0x1E6E0084, data); |
Dave Airlie | 318cfa2 | 2014-01-17 11:36:14 +1000 | [diff] [blame] | 713 | return status; |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 714 | } /* finetuneDQI_L */ |
| 715 | |
Dave Airlie | 318cfa2 | 2014-01-17 11:36:14 +1000 | [diff] [blame] | 716 | static void finetuneDQSI(struct ast_private *ast) |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 717 | { |
Dave Airlie | 318cfa2 | 2014-01-17 11:36:14 +1000 | [diff] [blame] | 718 | u32 dlli, dqsip, dqidly; |
| 719 | u32 reg_mcr18, reg_mcr0c, passcnt[2], diff; |
| 720 | u32 g_dqidly, g_dqsip, g_margin, g_side; |
| 721 | u16 pass[32][2][2]; |
| 722 | char tag[2][76]; |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 723 | |
Dave Airlie | 318cfa2 | 2014-01-17 11:36:14 +1000 | [diff] [blame] | 724 | /* Disable DQI CBR */ |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 725 | reg_mcr0c = ast_mindwm(ast, 0x1E6E000C); |
| 726 | reg_mcr18 = ast_mindwm(ast, 0x1E6E0018); |
Dave Airlie | 318cfa2 | 2014-01-17 11:36:14 +1000 | [diff] [blame] | 727 | reg_mcr18 &= 0x0000ffff; |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 728 | ast_moutdwm(ast, 0x1E6E0018, reg_mcr18); |
Dave Airlie | 318cfa2 | 2014-01-17 11:36:14 +1000 | [diff] [blame] | 729 | |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 730 | for (dlli = 0; dlli < 76; dlli++) { |
Dave Airlie | 318cfa2 | 2014-01-17 11:36:14 +1000 | [diff] [blame] | 731 | tag[0][dlli] = 0x0; |
| 732 | tag[1][dlli] = 0x0; |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 733 | } |
Dave Airlie | 318cfa2 | 2014-01-17 11:36:14 +1000 | [diff] [blame] | 734 | for (dqidly = 0; dqidly < 32; dqidly++) { |
| 735 | pass[dqidly][0][0] = 0xff; |
| 736 | pass[dqidly][0][1] = 0x0; |
| 737 | pass[dqidly][1][0] = 0xff; |
| 738 | pass[dqidly][1][1] = 0x0; |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 739 | } |
Dave Airlie | 318cfa2 | 2014-01-17 11:36:14 +1000 | [diff] [blame] | 740 | for (dqidly = 0; dqidly < 32; dqidly++) { |
| 741 | passcnt[0] = passcnt[1] = 0; |
| 742 | for (dqsip = 0; dqsip < 2; dqsip++) { |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 743 | ast_moutdwm(ast, 0x1E6E000C, 0); |
| 744 | ast_moutdwm(ast, 0x1E6E0018, reg_mcr18 | (dqidly << 16) | (dqsip << 23)); |
| 745 | ast_moutdwm(ast, 0x1E6E000C, reg_mcr0c); |
Dave Airlie | 318cfa2 | 2014-01-17 11:36:14 +1000 | [diff] [blame] | 746 | for (dlli = 0; dlli < 76; dlli++) { |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 747 | ast_moutdwm(ast, 0x1E6E0068, 0x00001300 | (dlli << 16) | (dlli << 24)); |
| 748 | ast_moutdwm(ast, 0x1E6E0070, 0); |
| 749 | ast_moutdwm(ast, 0x1E6E0074, CBR_SIZE0); |
Dave Airlie | 318cfa2 | 2014-01-17 11:36:14 +1000 | [diff] [blame] | 750 | if (cbr_scan3(ast)) { |
| 751 | if (dlli == 0) |
| 752 | break; |
| 753 | passcnt[dqsip]++; |
| 754 | tag[dqsip][dlli] = 'P'; |
| 755 | if (dlli < pass[dqidly][dqsip][0]) |
| 756 | pass[dqidly][dqsip][0] = (u16) dlli; |
| 757 | if (dlli > pass[dqidly][dqsip][1]) |
| 758 | pass[dqidly][dqsip][1] = (u16) dlli; |
| 759 | } else if (passcnt[dqsip] >= 5) |
| 760 | break; |
| 761 | else { |
| 762 | pass[dqidly][dqsip][0] = 0xff; |
| 763 | pass[dqidly][dqsip][1] = 0x0; |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 764 | } |
| 765 | } |
| 766 | } |
Dave Airlie | 318cfa2 | 2014-01-17 11:36:14 +1000 | [diff] [blame] | 767 | if (passcnt[0] == 0 && passcnt[1] == 0) |
| 768 | dqidly++; |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 769 | } |
Dave Airlie | 318cfa2 | 2014-01-17 11:36:14 +1000 | [diff] [blame] | 770 | /* Search margin */ |
| 771 | g_dqidly = g_dqsip = g_margin = g_side = 0; |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 772 | |
Dave Airlie | 318cfa2 | 2014-01-17 11:36:14 +1000 | [diff] [blame] | 773 | for (dqidly = 0; dqidly < 32; dqidly++) { |
| 774 | for (dqsip = 0; dqsip < 2; dqsip++) { |
| 775 | if (pass[dqidly][dqsip][0] > pass[dqidly][dqsip][1]) |
| 776 | continue; |
| 777 | diff = pass[dqidly][dqsip][1] - pass[dqidly][dqsip][0]; |
| 778 | if ((diff+2) < g_margin) |
| 779 | continue; |
| 780 | passcnt[0] = passcnt[1] = 0; |
| 781 | for (dlli = pass[dqidly][dqsip][0]; dlli > 0 && tag[dqsip][dlli] != 0; dlli--, passcnt[0]++); |
| 782 | for (dlli = pass[dqidly][dqsip][1]; dlli < 76 && tag[dqsip][dlli] != 0; dlli++, passcnt[1]++); |
| 783 | if (passcnt[0] > passcnt[1]) |
| 784 | passcnt[0] = passcnt[1]; |
| 785 | passcnt[1] = 0; |
| 786 | if (passcnt[0] > g_side) |
| 787 | passcnt[1] = passcnt[0] - g_side; |
| 788 | if (diff > (g_margin+1) && (passcnt[1] > 0 || passcnt[0] > 8)) { |
| 789 | g_margin = diff; |
| 790 | g_dqidly = dqidly; |
| 791 | g_dqsip = dqsip; |
| 792 | g_side = passcnt[0]; |
| 793 | } else if (passcnt[1] > 1 && g_side < 8) { |
| 794 | if (diff > g_margin) |
| 795 | g_margin = diff; |
| 796 | g_dqidly = dqidly; |
| 797 | g_dqsip = dqsip; |
| 798 | g_side = passcnt[0]; |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 799 | } |
| 800 | } |
| 801 | } |
Dave Airlie | 318cfa2 | 2014-01-17 11:36:14 +1000 | [diff] [blame] | 802 | reg_mcr18 = reg_mcr18 | (g_dqidly << 16) | (g_dqsip << 23); |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 803 | ast_moutdwm(ast, 0x1E6E0018, reg_mcr18); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 804 | |
Dave Airlie | 318cfa2 | 2014-01-17 11:36:14 +1000 | [diff] [blame] | 805 | } |
| 806 | static bool cbr_dll2(struct ast_private *ast, struct ast2300_dram_param *param) |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 807 | { |
Dave Airlie | 318cfa2 | 2014-01-17 11:36:14 +1000 | [diff] [blame] | 808 | u32 dllmin[2], dllmax[2], dlli, data, passcnt, retry = 0; |
| 809 | bool status = false; |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 810 | |
Dave Airlie | 318cfa2 | 2014-01-17 11:36:14 +1000 | [diff] [blame] | 811 | finetuneDQSI(ast); |
| 812 | if (finetuneDQI_L(ast, param) == false) |
| 813 | return status; |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 814 | |
| 815 | CBR_START2: |
| 816 | dllmin[0] = dllmin[1] = 0xff; |
| 817 | dllmax[0] = dllmax[1] = 0x0; |
| 818 | passcnt = 0; |
| 819 | for (dlli = 0; dlli < 76; dlli++) { |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 820 | ast_moutdwm(ast, 0x1E6E0068, 0x00001300 | (dlli << 16) | (dlli << 24)); |
| 821 | ast_moutdwm(ast, 0x1E6E0074, CBR_SIZE2); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 822 | data = cbr_scan(ast); |
| 823 | if (data != 0) { |
| 824 | if (data & 0x1) { |
| 825 | if (dllmin[0] > dlli) { |
| 826 | dllmin[0] = dlli; |
| 827 | } |
| 828 | if (dllmax[0] < dlli) { |
| 829 | dllmax[0] = dlli; |
| 830 | } |
| 831 | } |
| 832 | if (data & 0x2) { |
| 833 | if (dllmin[1] > dlli) { |
| 834 | dllmin[1] = dlli; |
| 835 | } |
| 836 | if (dllmax[1] < dlli) { |
| 837 | dllmax[1] = dlli; |
| 838 | } |
| 839 | } |
| 840 | passcnt++; |
| 841 | } else if (passcnt >= CBR_THRESHOLD) { |
| 842 | break; |
| 843 | } |
| 844 | } |
Dave Airlie | 318cfa2 | 2014-01-17 11:36:14 +1000 | [diff] [blame] | 845 | if (retry++ > 10) |
| 846 | goto CBR_DONE2; |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 847 | if (dllmax[0] == 0 || (dllmax[0]-dllmin[0]) < CBR_THRESHOLD) { |
| 848 | goto CBR_START2; |
| 849 | } |
| 850 | if (dllmax[1] == 0 || (dllmax[1]-dllmin[1]) < CBR_THRESHOLD) { |
| 851 | goto CBR_START2; |
| 852 | } |
Dave Airlie | 318cfa2 | 2014-01-17 11:36:14 +1000 | [diff] [blame] | 853 | status = true; |
| 854 | CBR_DONE2: |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 855 | dlli = (dllmin[1] + dllmax[1]) >> 1; |
| 856 | dlli <<= 8; |
| 857 | dlli += (dllmin[0] + dllmax[0]) >> 1; |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 858 | ast_moutdwm(ast, 0x1E6E0068, ast_mindwm(ast, 0x1E720058) | (dlli << 16)); |
Dave Airlie | 318cfa2 | 2014-01-17 11:36:14 +1000 | [diff] [blame] | 859 | return status; |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 860 | } /* CBRDLL2 */ |
| 861 | |
| 862 | static void get_ddr3_info(struct ast_private *ast, struct ast2300_dram_param *param) |
| 863 | { |
| 864 | u32 trap, trap_AC2, trap_MRS; |
| 865 | |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 866 | ast_moutdwm(ast, 0x1E6E2000, 0x1688A8A8); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 867 | |
| 868 | /* Ger trap info */ |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 869 | trap = (ast_mindwm(ast, 0x1E6E2070) >> 25) & 0x3; |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 870 | trap_AC2 = 0x00020000 + (trap << 16); |
| 871 | trap_AC2 |= 0x00300000 + ((trap & 0x2) << 19); |
| 872 | trap_MRS = 0x00000010 + (trap << 4); |
| 873 | trap_MRS |= ((trap & 0x2) << 18); |
| 874 | |
| 875 | param->reg_MADJ = 0x00034C4C; |
| 876 | param->reg_SADJ = 0x00001800; |
| 877 | param->reg_DRV = 0x000000F0; |
| 878 | param->reg_PERIOD = param->dram_freq; |
| 879 | param->rodt = 0; |
| 880 | |
| 881 | switch (param->dram_freq) { |
| 882 | case 336: |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 883 | ast_moutdwm(ast, 0x1E6E2020, 0x0190); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 884 | param->wodt = 0; |
| 885 | param->reg_AC1 = 0x22202725; |
| 886 | param->reg_AC2 = 0xAA007613 | trap_AC2; |
| 887 | param->reg_DQSIC = 0x000000BA; |
| 888 | param->reg_MRS = 0x04001400 | trap_MRS; |
| 889 | param->reg_EMRS = 0x00000000; |
Dave Airlie | 318cfa2 | 2014-01-17 11:36:14 +1000 | [diff] [blame] | 890 | param->reg_IOZ = 0x00000023; |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 891 | param->reg_DQIDLY = 0x00000074; |
| 892 | param->reg_FREQ = 0x00004DC0; |
| 893 | param->madj_max = 96; |
| 894 | param->dll2_finetune_step = 3; |
Dave Airlie | 318cfa2 | 2014-01-17 11:36:14 +1000 | [diff] [blame] | 895 | switch (param->dram_chipid) { |
| 896 | default: |
| 897 | case AST_DRAM_512Mx16: |
| 898 | case AST_DRAM_1Gx16: |
| 899 | param->reg_AC2 = 0xAA007613 | trap_AC2; |
| 900 | break; |
| 901 | case AST_DRAM_2Gx16: |
| 902 | param->reg_AC2 = 0xAA00761C | trap_AC2; |
| 903 | break; |
| 904 | case AST_DRAM_4Gx16: |
| 905 | param->reg_AC2 = 0xAA007636 | trap_AC2; |
| 906 | break; |
| 907 | } |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 908 | break; |
| 909 | default: |
| 910 | case 396: |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 911 | ast_moutdwm(ast, 0x1E6E2020, 0x03F1); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 912 | param->wodt = 1; |
| 913 | param->reg_AC1 = 0x33302825; |
| 914 | param->reg_AC2 = 0xCC009617 | trap_AC2; |
| 915 | param->reg_DQSIC = 0x000000E2; |
| 916 | param->reg_MRS = 0x04001600 | trap_MRS; |
| 917 | param->reg_EMRS = 0x00000000; |
| 918 | param->reg_IOZ = 0x00000034; |
| 919 | param->reg_DRV = 0x000000FA; |
| 920 | param->reg_DQIDLY = 0x00000089; |
Dave Airlie | 318cfa2 | 2014-01-17 11:36:14 +1000 | [diff] [blame] | 921 | param->reg_FREQ = 0x00005040; |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 922 | param->madj_max = 96; |
| 923 | param->dll2_finetune_step = 4; |
| 924 | |
| 925 | switch (param->dram_chipid) { |
| 926 | default: |
| 927 | case AST_DRAM_512Mx16: |
| 928 | case AST_DRAM_1Gx16: |
| 929 | param->reg_AC2 = 0xCC009617 | trap_AC2; |
| 930 | break; |
| 931 | case AST_DRAM_2Gx16: |
| 932 | param->reg_AC2 = 0xCC009622 | trap_AC2; |
| 933 | break; |
| 934 | case AST_DRAM_4Gx16: |
| 935 | param->reg_AC2 = 0xCC00963F | trap_AC2; |
| 936 | break; |
| 937 | } |
| 938 | break; |
| 939 | |
| 940 | case 408: |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 941 | ast_moutdwm(ast, 0x1E6E2020, 0x01F0); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 942 | param->wodt = 1; |
| 943 | param->reg_AC1 = 0x33302825; |
| 944 | param->reg_AC2 = 0xCC009617 | trap_AC2; |
| 945 | param->reg_DQSIC = 0x000000E2; |
| 946 | param->reg_MRS = 0x04001600 | trap_MRS; |
| 947 | param->reg_EMRS = 0x00000000; |
Dave Airlie | 318cfa2 | 2014-01-17 11:36:14 +1000 | [diff] [blame] | 948 | param->reg_IOZ = 0x00000023; |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 949 | param->reg_DRV = 0x000000FA; |
| 950 | param->reg_DQIDLY = 0x00000089; |
| 951 | param->reg_FREQ = 0x000050C0; |
| 952 | param->madj_max = 96; |
| 953 | param->dll2_finetune_step = 4; |
| 954 | |
| 955 | switch (param->dram_chipid) { |
| 956 | default: |
| 957 | case AST_DRAM_512Mx16: |
| 958 | case AST_DRAM_1Gx16: |
| 959 | param->reg_AC2 = 0xCC009617 | trap_AC2; |
| 960 | break; |
| 961 | case AST_DRAM_2Gx16: |
| 962 | param->reg_AC2 = 0xCC009622 | trap_AC2; |
| 963 | break; |
| 964 | case AST_DRAM_4Gx16: |
| 965 | param->reg_AC2 = 0xCC00963F | trap_AC2; |
| 966 | break; |
| 967 | } |
| 968 | |
| 969 | break; |
| 970 | case 456: |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 971 | ast_moutdwm(ast, 0x1E6E2020, 0x0230); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 972 | param->wodt = 0; |
| 973 | param->reg_AC1 = 0x33302926; |
| 974 | param->reg_AC2 = 0xCD44961A; |
| 975 | param->reg_DQSIC = 0x000000FC; |
| 976 | param->reg_MRS = 0x00081830; |
| 977 | param->reg_EMRS = 0x00000000; |
| 978 | param->reg_IOZ = 0x00000045; |
| 979 | param->reg_DQIDLY = 0x00000097; |
| 980 | param->reg_FREQ = 0x000052C0; |
| 981 | param->madj_max = 88; |
| 982 | param->dll2_finetune_step = 4; |
| 983 | break; |
| 984 | case 504: |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 985 | ast_moutdwm(ast, 0x1E6E2020, 0x0270); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 986 | param->wodt = 1; |
| 987 | param->reg_AC1 = 0x33302926; |
| 988 | param->reg_AC2 = 0xDE44A61D; |
| 989 | param->reg_DQSIC = 0x00000117; |
| 990 | param->reg_MRS = 0x00081A30; |
| 991 | param->reg_EMRS = 0x00000000; |
| 992 | param->reg_IOZ = 0x070000BB; |
| 993 | param->reg_DQIDLY = 0x000000A0; |
| 994 | param->reg_FREQ = 0x000054C0; |
| 995 | param->madj_max = 79; |
| 996 | param->dll2_finetune_step = 4; |
| 997 | break; |
| 998 | case 528: |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 999 | ast_moutdwm(ast, 0x1E6E2020, 0x0290); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1000 | param->wodt = 1; |
| 1001 | param->rodt = 1; |
| 1002 | param->reg_AC1 = 0x33302926; |
| 1003 | param->reg_AC2 = 0xEF44B61E; |
| 1004 | param->reg_DQSIC = 0x00000125; |
| 1005 | param->reg_MRS = 0x00081A30; |
| 1006 | param->reg_EMRS = 0x00000040; |
| 1007 | param->reg_DRV = 0x000000F5; |
| 1008 | param->reg_IOZ = 0x00000023; |
| 1009 | param->reg_DQIDLY = 0x00000088; |
| 1010 | param->reg_FREQ = 0x000055C0; |
| 1011 | param->madj_max = 76; |
| 1012 | param->dll2_finetune_step = 3; |
| 1013 | break; |
| 1014 | case 576: |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1015 | ast_moutdwm(ast, 0x1E6E2020, 0x0140); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1016 | param->reg_MADJ = 0x00136868; |
| 1017 | param->reg_SADJ = 0x00004534; |
| 1018 | param->wodt = 1; |
| 1019 | param->rodt = 1; |
| 1020 | param->reg_AC1 = 0x33302A37; |
| 1021 | param->reg_AC2 = 0xEF56B61E; |
| 1022 | param->reg_DQSIC = 0x0000013F; |
| 1023 | param->reg_MRS = 0x00101A50; |
| 1024 | param->reg_EMRS = 0x00000040; |
| 1025 | param->reg_DRV = 0x000000FA; |
| 1026 | param->reg_IOZ = 0x00000023; |
| 1027 | param->reg_DQIDLY = 0x00000078; |
| 1028 | param->reg_FREQ = 0x000057C0; |
| 1029 | param->madj_max = 136; |
| 1030 | param->dll2_finetune_step = 3; |
| 1031 | break; |
| 1032 | case 600: |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1033 | ast_moutdwm(ast, 0x1E6E2020, 0x02E1); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1034 | param->reg_MADJ = 0x00136868; |
| 1035 | param->reg_SADJ = 0x00004534; |
| 1036 | param->wodt = 1; |
| 1037 | param->rodt = 1; |
| 1038 | param->reg_AC1 = 0x32302A37; |
| 1039 | param->reg_AC2 = 0xDF56B61F; |
| 1040 | param->reg_DQSIC = 0x0000014D; |
| 1041 | param->reg_MRS = 0x00101A50; |
| 1042 | param->reg_EMRS = 0x00000004; |
| 1043 | param->reg_DRV = 0x000000F5; |
| 1044 | param->reg_IOZ = 0x00000023; |
| 1045 | param->reg_DQIDLY = 0x00000078; |
| 1046 | param->reg_FREQ = 0x000058C0; |
| 1047 | param->madj_max = 132; |
| 1048 | param->dll2_finetune_step = 3; |
| 1049 | break; |
| 1050 | case 624: |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1051 | ast_moutdwm(ast, 0x1E6E2020, 0x0160); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1052 | param->reg_MADJ = 0x00136868; |
| 1053 | param->reg_SADJ = 0x00004534; |
| 1054 | param->wodt = 1; |
| 1055 | param->rodt = 1; |
| 1056 | param->reg_AC1 = 0x32302A37; |
| 1057 | param->reg_AC2 = 0xEF56B621; |
| 1058 | param->reg_DQSIC = 0x0000015A; |
| 1059 | param->reg_MRS = 0x02101A50; |
| 1060 | param->reg_EMRS = 0x00000004; |
| 1061 | param->reg_DRV = 0x000000F5; |
| 1062 | param->reg_IOZ = 0x00000034; |
| 1063 | param->reg_DQIDLY = 0x00000078; |
| 1064 | param->reg_FREQ = 0x000059C0; |
| 1065 | param->madj_max = 128; |
| 1066 | param->dll2_finetune_step = 3; |
| 1067 | break; |
| 1068 | } /* switch freq */ |
| 1069 | |
| 1070 | switch (param->dram_chipid) { |
| 1071 | case AST_DRAM_512Mx16: |
| 1072 | param->dram_config = 0x130; |
| 1073 | break; |
| 1074 | default: |
| 1075 | case AST_DRAM_1Gx16: |
| 1076 | param->dram_config = 0x131; |
| 1077 | break; |
| 1078 | case AST_DRAM_2Gx16: |
| 1079 | param->dram_config = 0x132; |
| 1080 | break; |
| 1081 | case AST_DRAM_4Gx16: |
| 1082 | param->dram_config = 0x133; |
| 1083 | break; |
| 1084 | }; /* switch size */ |
| 1085 | |
| 1086 | switch (param->vram_size) { |
| 1087 | default: |
| 1088 | case AST_VIDMEM_SIZE_8M: |
| 1089 | param->dram_config |= 0x00; |
| 1090 | break; |
| 1091 | case AST_VIDMEM_SIZE_16M: |
| 1092 | param->dram_config |= 0x04; |
| 1093 | break; |
| 1094 | case AST_VIDMEM_SIZE_32M: |
| 1095 | param->dram_config |= 0x08; |
| 1096 | break; |
| 1097 | case AST_VIDMEM_SIZE_64M: |
| 1098 | param->dram_config |= 0x0c; |
| 1099 | break; |
| 1100 | } |
| 1101 | |
| 1102 | } |
| 1103 | |
| 1104 | static void ddr3_init(struct ast_private *ast, struct ast2300_dram_param *param) |
| 1105 | { |
Dave Airlie | 318cfa2 | 2014-01-17 11:36:14 +1000 | [diff] [blame] | 1106 | u32 data, data2, retry = 0; |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1107 | |
Dave Airlie | 318cfa2 | 2014-01-17 11:36:14 +1000 | [diff] [blame] | 1108 | ddr3_init_start: |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1109 | ast_moutdwm(ast, 0x1E6E0000, 0xFC600309); |
| 1110 | ast_moutdwm(ast, 0x1E6E0018, 0x00000100); |
| 1111 | ast_moutdwm(ast, 0x1E6E0024, 0x00000000); |
| 1112 | ast_moutdwm(ast, 0x1E6E0034, 0x00000000); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1113 | udelay(10); |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1114 | ast_moutdwm(ast, 0x1E6E0064, param->reg_MADJ); |
| 1115 | ast_moutdwm(ast, 0x1E6E0068, param->reg_SADJ); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1116 | udelay(10); |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1117 | ast_moutdwm(ast, 0x1E6E0064, param->reg_MADJ | 0xC0000); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1118 | udelay(10); |
| 1119 | |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1120 | ast_moutdwm(ast, 0x1E6E0004, param->dram_config); |
| 1121 | ast_moutdwm(ast, 0x1E6E0008, 0x90040f); |
| 1122 | ast_moutdwm(ast, 0x1E6E0010, param->reg_AC1); |
| 1123 | ast_moutdwm(ast, 0x1E6E0014, param->reg_AC2); |
| 1124 | ast_moutdwm(ast, 0x1E6E0020, param->reg_DQSIC); |
| 1125 | ast_moutdwm(ast, 0x1E6E0080, 0x00000000); |
| 1126 | ast_moutdwm(ast, 0x1E6E0084, 0x00000000); |
| 1127 | ast_moutdwm(ast, 0x1E6E0088, param->reg_DQIDLY); |
| 1128 | ast_moutdwm(ast, 0x1E6E0018, 0x4000A170); |
| 1129 | ast_moutdwm(ast, 0x1E6E0018, 0x00002370); |
| 1130 | ast_moutdwm(ast, 0x1E6E0038, 0x00000000); |
| 1131 | ast_moutdwm(ast, 0x1E6E0040, 0xFF444444); |
| 1132 | ast_moutdwm(ast, 0x1E6E0044, 0x22222222); |
| 1133 | ast_moutdwm(ast, 0x1E6E0048, 0x22222222); |
| 1134 | ast_moutdwm(ast, 0x1E6E004C, 0x00000002); |
| 1135 | ast_moutdwm(ast, 0x1E6E0050, 0x80000000); |
| 1136 | ast_moutdwm(ast, 0x1E6E0050, 0x00000000); |
| 1137 | ast_moutdwm(ast, 0x1E6E0054, 0); |
| 1138 | ast_moutdwm(ast, 0x1E6E0060, param->reg_DRV); |
| 1139 | ast_moutdwm(ast, 0x1E6E006C, param->reg_IOZ); |
| 1140 | ast_moutdwm(ast, 0x1E6E0070, 0x00000000); |
| 1141 | ast_moutdwm(ast, 0x1E6E0074, 0x00000000); |
| 1142 | ast_moutdwm(ast, 0x1E6E0078, 0x00000000); |
| 1143 | ast_moutdwm(ast, 0x1E6E007C, 0x00000000); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1144 | /* Wait MCLK2X lock to MCLK */ |
| 1145 | do { |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1146 | data = ast_mindwm(ast, 0x1E6E001C); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1147 | } while (!(data & 0x08000000)); |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1148 | data = ast_mindwm(ast, 0x1E6E001C); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1149 | data = (data >> 8) & 0xff; |
| 1150 | while ((data & 0x08) || ((data & 0x7) < 2) || (data < 4)) { |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1151 | data2 = (ast_mindwm(ast, 0x1E6E0064) & 0xfff3ffff) + 4; |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1152 | if ((data2 & 0xff) > param->madj_max) { |
| 1153 | break; |
| 1154 | } |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1155 | ast_moutdwm(ast, 0x1E6E0064, data2); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1156 | if (data2 & 0x00100000) { |
| 1157 | data2 = ((data2 & 0xff) >> 3) + 3; |
| 1158 | } else { |
| 1159 | data2 = ((data2 & 0xff) >> 2) + 5; |
| 1160 | } |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1161 | data = ast_mindwm(ast, 0x1E6E0068) & 0xffff00ff; |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1162 | data2 += data & 0xff; |
| 1163 | data = data | (data2 << 8); |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1164 | ast_moutdwm(ast, 0x1E6E0068, data); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1165 | udelay(10); |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1166 | ast_moutdwm(ast, 0x1E6E0064, ast_mindwm(ast, 0x1E6E0064) | 0xC0000); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1167 | udelay(10); |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1168 | data = ast_mindwm(ast, 0x1E6E0018) & 0xfffff1ff; |
| 1169 | ast_moutdwm(ast, 0x1E6E0018, data); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1170 | data = data | 0x200; |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1171 | ast_moutdwm(ast, 0x1E6E0018, data); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1172 | do { |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1173 | data = ast_mindwm(ast, 0x1E6E001C); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1174 | } while (!(data & 0x08000000)); |
| 1175 | |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1176 | data = ast_mindwm(ast, 0x1E6E001C); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1177 | data = (data >> 8) & 0xff; |
| 1178 | } |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1179 | ast_moutdwm(ast, 0x1E720058, ast_mindwm(ast, 0x1E6E0068) & 0xffff); |
| 1180 | data = ast_mindwm(ast, 0x1E6E0018) | 0xC00; |
| 1181 | ast_moutdwm(ast, 0x1E6E0018, data); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1182 | |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1183 | ast_moutdwm(ast, 0x1E6E0034, 0x00000001); |
| 1184 | ast_moutdwm(ast, 0x1E6E000C, 0x00000040); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1185 | udelay(50); |
| 1186 | /* Mode Register Setting */ |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1187 | ast_moutdwm(ast, 0x1E6E002C, param->reg_MRS | 0x100); |
| 1188 | ast_moutdwm(ast, 0x1E6E0030, param->reg_EMRS); |
| 1189 | ast_moutdwm(ast, 0x1E6E0028, 0x00000005); |
| 1190 | ast_moutdwm(ast, 0x1E6E0028, 0x00000007); |
| 1191 | ast_moutdwm(ast, 0x1E6E0028, 0x00000003); |
| 1192 | ast_moutdwm(ast, 0x1E6E0028, 0x00000001); |
| 1193 | ast_moutdwm(ast, 0x1E6E002C, param->reg_MRS); |
| 1194 | ast_moutdwm(ast, 0x1E6E000C, 0x00005C08); |
| 1195 | ast_moutdwm(ast, 0x1E6E0028, 0x00000001); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1196 | |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1197 | ast_moutdwm(ast, 0x1E6E000C, 0x00005C01); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1198 | data = 0; |
| 1199 | if (param->wodt) { |
| 1200 | data = 0x300; |
| 1201 | } |
| 1202 | if (param->rodt) { |
| 1203 | data = data | 0x3000 | ((param->reg_AC2 & 0x60000) >> 3); |
| 1204 | } |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1205 | ast_moutdwm(ast, 0x1E6E0034, data | 0x3); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1206 | |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1207 | /* Calibrate the DQSI delay */ |
Dave Airlie | 318cfa2 | 2014-01-17 11:36:14 +1000 | [diff] [blame] | 1208 | if ((cbr_dll2(ast, param) == false) && (retry++ < 10)) |
| 1209 | goto ddr3_init_start; |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1210 | |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1211 | ast_moutdwm(ast, 0x1E6E0120, param->reg_FREQ); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1212 | /* ECC Memory Initialization */ |
| 1213 | #ifdef ECC |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1214 | ast_moutdwm(ast, 0x1E6E007C, 0x00000000); |
| 1215 | ast_moutdwm(ast, 0x1E6E0070, 0x221); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1216 | do { |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1217 | data = ast_mindwm(ast, 0x1E6E0070); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1218 | } while (!(data & 0x00001000)); |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1219 | ast_moutdwm(ast, 0x1E6E0070, 0x00000000); |
| 1220 | ast_moutdwm(ast, 0x1E6E0050, 0x80000000); |
| 1221 | ast_moutdwm(ast, 0x1E6E0050, 0x00000000); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1222 | #endif |
| 1223 | |
| 1224 | |
| 1225 | } |
| 1226 | |
| 1227 | static void get_ddr2_info(struct ast_private *ast, struct ast2300_dram_param *param) |
| 1228 | { |
| 1229 | u32 trap, trap_AC2, trap_MRS; |
| 1230 | |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1231 | ast_moutdwm(ast, 0x1E6E2000, 0x1688A8A8); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1232 | |
| 1233 | /* Ger trap info */ |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1234 | trap = (ast_mindwm(ast, 0x1E6E2070) >> 25) & 0x3; |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1235 | trap_AC2 = (trap << 20) | (trap << 16); |
| 1236 | trap_AC2 += 0x00110000; |
| 1237 | trap_MRS = 0x00000040 | (trap << 4); |
| 1238 | |
| 1239 | |
| 1240 | param->reg_MADJ = 0x00034C4C; |
| 1241 | param->reg_SADJ = 0x00001800; |
| 1242 | param->reg_DRV = 0x000000F0; |
| 1243 | param->reg_PERIOD = param->dram_freq; |
| 1244 | param->rodt = 0; |
| 1245 | |
| 1246 | switch (param->dram_freq) { |
| 1247 | case 264: |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1248 | ast_moutdwm(ast, 0x1E6E2020, 0x0130); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1249 | param->wodt = 0; |
| 1250 | param->reg_AC1 = 0x11101513; |
| 1251 | param->reg_AC2 = 0x78117011; |
| 1252 | param->reg_DQSIC = 0x00000092; |
| 1253 | param->reg_MRS = 0x00000842; |
| 1254 | param->reg_EMRS = 0x00000000; |
| 1255 | param->reg_DRV = 0x000000F0; |
| 1256 | param->reg_IOZ = 0x00000034; |
| 1257 | param->reg_DQIDLY = 0x0000005A; |
| 1258 | param->reg_FREQ = 0x00004AC0; |
| 1259 | param->madj_max = 138; |
| 1260 | param->dll2_finetune_step = 3; |
| 1261 | break; |
| 1262 | case 336: |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1263 | ast_moutdwm(ast, 0x1E6E2020, 0x0190); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1264 | param->wodt = 1; |
| 1265 | param->reg_AC1 = 0x22202613; |
| 1266 | param->reg_AC2 = 0xAA009016 | trap_AC2; |
| 1267 | param->reg_DQSIC = 0x000000BA; |
| 1268 | param->reg_MRS = 0x00000A02 | trap_MRS; |
| 1269 | param->reg_EMRS = 0x00000040; |
| 1270 | param->reg_DRV = 0x000000FA; |
| 1271 | param->reg_IOZ = 0x00000034; |
| 1272 | param->reg_DQIDLY = 0x00000074; |
| 1273 | param->reg_FREQ = 0x00004DC0; |
| 1274 | param->madj_max = 96; |
| 1275 | param->dll2_finetune_step = 3; |
Dave Airlie | 318cfa2 | 2014-01-17 11:36:14 +1000 | [diff] [blame] | 1276 | switch (param->dram_chipid) { |
| 1277 | default: |
| 1278 | case AST_DRAM_512Mx16: |
| 1279 | param->reg_AC2 = 0xAA009012 | trap_AC2; |
| 1280 | break; |
| 1281 | case AST_DRAM_1Gx16: |
| 1282 | param->reg_AC2 = 0xAA009016 | trap_AC2; |
| 1283 | break; |
| 1284 | case AST_DRAM_2Gx16: |
| 1285 | param->reg_AC2 = 0xAA009023 | trap_AC2; |
| 1286 | break; |
| 1287 | case AST_DRAM_4Gx16: |
| 1288 | param->reg_AC2 = 0xAA00903B | trap_AC2; |
| 1289 | break; |
| 1290 | } |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1291 | break; |
| 1292 | default: |
| 1293 | case 396: |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1294 | ast_moutdwm(ast, 0x1E6E2020, 0x03F1); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1295 | param->wodt = 1; |
| 1296 | param->rodt = 0; |
| 1297 | param->reg_AC1 = 0x33302714; |
| 1298 | param->reg_AC2 = 0xCC00B01B | trap_AC2; |
| 1299 | param->reg_DQSIC = 0x000000E2; |
| 1300 | param->reg_MRS = 0x00000C02 | trap_MRS; |
| 1301 | param->reg_EMRS = 0x00000040; |
| 1302 | param->reg_DRV = 0x000000FA; |
| 1303 | param->reg_IOZ = 0x00000034; |
| 1304 | param->reg_DQIDLY = 0x00000089; |
Dave Airlie | 318cfa2 | 2014-01-17 11:36:14 +1000 | [diff] [blame] | 1305 | param->reg_FREQ = 0x00005040; |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1306 | param->madj_max = 96; |
| 1307 | param->dll2_finetune_step = 4; |
| 1308 | |
| 1309 | switch (param->dram_chipid) { |
| 1310 | case AST_DRAM_512Mx16: |
| 1311 | param->reg_AC2 = 0xCC00B016 | trap_AC2; |
| 1312 | break; |
| 1313 | default: |
| 1314 | case AST_DRAM_1Gx16: |
| 1315 | param->reg_AC2 = 0xCC00B01B | trap_AC2; |
| 1316 | break; |
| 1317 | case AST_DRAM_2Gx16: |
| 1318 | param->reg_AC2 = 0xCC00B02B | trap_AC2; |
| 1319 | break; |
| 1320 | case AST_DRAM_4Gx16: |
| 1321 | param->reg_AC2 = 0xCC00B03F | trap_AC2; |
| 1322 | break; |
| 1323 | } |
| 1324 | |
| 1325 | break; |
| 1326 | |
| 1327 | case 408: |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1328 | ast_moutdwm(ast, 0x1E6E2020, 0x01F0); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1329 | param->wodt = 1; |
| 1330 | param->rodt = 0; |
| 1331 | param->reg_AC1 = 0x33302714; |
| 1332 | param->reg_AC2 = 0xCC00B01B | trap_AC2; |
| 1333 | param->reg_DQSIC = 0x000000E2; |
| 1334 | param->reg_MRS = 0x00000C02 | trap_MRS; |
| 1335 | param->reg_EMRS = 0x00000040; |
| 1336 | param->reg_DRV = 0x000000FA; |
| 1337 | param->reg_IOZ = 0x00000034; |
| 1338 | param->reg_DQIDLY = 0x00000089; |
| 1339 | param->reg_FREQ = 0x000050C0; |
| 1340 | param->madj_max = 96; |
| 1341 | param->dll2_finetune_step = 4; |
| 1342 | |
| 1343 | switch (param->dram_chipid) { |
| 1344 | case AST_DRAM_512Mx16: |
| 1345 | param->reg_AC2 = 0xCC00B016 | trap_AC2; |
| 1346 | break; |
| 1347 | default: |
| 1348 | case AST_DRAM_1Gx16: |
| 1349 | param->reg_AC2 = 0xCC00B01B | trap_AC2; |
| 1350 | break; |
| 1351 | case AST_DRAM_2Gx16: |
| 1352 | param->reg_AC2 = 0xCC00B02B | trap_AC2; |
| 1353 | break; |
| 1354 | case AST_DRAM_4Gx16: |
| 1355 | param->reg_AC2 = 0xCC00B03F | trap_AC2; |
| 1356 | break; |
| 1357 | } |
| 1358 | |
| 1359 | break; |
| 1360 | case 456: |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1361 | ast_moutdwm(ast, 0x1E6E2020, 0x0230); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1362 | param->wodt = 0; |
| 1363 | param->reg_AC1 = 0x33302815; |
| 1364 | param->reg_AC2 = 0xCD44B01E; |
| 1365 | param->reg_DQSIC = 0x000000FC; |
| 1366 | param->reg_MRS = 0x00000E72; |
| 1367 | param->reg_EMRS = 0x00000000; |
| 1368 | param->reg_DRV = 0x00000000; |
| 1369 | param->reg_IOZ = 0x00000034; |
| 1370 | param->reg_DQIDLY = 0x00000097; |
| 1371 | param->reg_FREQ = 0x000052C0; |
| 1372 | param->madj_max = 88; |
| 1373 | param->dll2_finetune_step = 3; |
| 1374 | break; |
| 1375 | case 504: |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1376 | ast_moutdwm(ast, 0x1E6E2020, 0x0261); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1377 | param->wodt = 1; |
| 1378 | param->rodt = 1; |
| 1379 | param->reg_AC1 = 0x33302815; |
| 1380 | param->reg_AC2 = 0xDE44C022; |
| 1381 | param->reg_DQSIC = 0x00000117; |
| 1382 | param->reg_MRS = 0x00000E72; |
| 1383 | param->reg_EMRS = 0x00000040; |
| 1384 | param->reg_DRV = 0x0000000A; |
| 1385 | param->reg_IOZ = 0x00000045; |
| 1386 | param->reg_DQIDLY = 0x000000A0; |
| 1387 | param->reg_FREQ = 0x000054C0; |
| 1388 | param->madj_max = 79; |
| 1389 | param->dll2_finetune_step = 3; |
| 1390 | break; |
| 1391 | case 528: |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1392 | ast_moutdwm(ast, 0x1E6E2020, 0x0120); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1393 | param->wodt = 1; |
| 1394 | param->rodt = 1; |
| 1395 | param->reg_AC1 = 0x33302815; |
| 1396 | param->reg_AC2 = 0xEF44D024; |
| 1397 | param->reg_DQSIC = 0x00000125; |
| 1398 | param->reg_MRS = 0x00000E72; |
| 1399 | param->reg_EMRS = 0x00000004; |
| 1400 | param->reg_DRV = 0x000000F9; |
| 1401 | param->reg_IOZ = 0x00000045; |
| 1402 | param->reg_DQIDLY = 0x000000A7; |
| 1403 | param->reg_FREQ = 0x000055C0; |
| 1404 | param->madj_max = 76; |
| 1405 | param->dll2_finetune_step = 3; |
| 1406 | break; |
| 1407 | case 552: |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1408 | ast_moutdwm(ast, 0x1E6E2020, 0x02A1); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1409 | param->wodt = 1; |
| 1410 | param->rodt = 1; |
| 1411 | param->reg_AC1 = 0x43402915; |
| 1412 | param->reg_AC2 = 0xFF44E025; |
| 1413 | param->reg_DQSIC = 0x00000132; |
| 1414 | param->reg_MRS = 0x00000E72; |
| 1415 | param->reg_EMRS = 0x00000040; |
| 1416 | param->reg_DRV = 0x0000000A; |
| 1417 | param->reg_IOZ = 0x00000045; |
| 1418 | param->reg_DQIDLY = 0x000000AD; |
| 1419 | param->reg_FREQ = 0x000056C0; |
| 1420 | param->madj_max = 76; |
| 1421 | param->dll2_finetune_step = 3; |
| 1422 | break; |
| 1423 | case 576: |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1424 | ast_moutdwm(ast, 0x1E6E2020, 0x0140); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1425 | param->wodt = 1; |
| 1426 | param->rodt = 1; |
| 1427 | param->reg_AC1 = 0x43402915; |
| 1428 | param->reg_AC2 = 0xFF44E027; |
| 1429 | param->reg_DQSIC = 0x0000013F; |
| 1430 | param->reg_MRS = 0x00000E72; |
| 1431 | param->reg_EMRS = 0x00000004; |
| 1432 | param->reg_DRV = 0x000000F5; |
| 1433 | param->reg_IOZ = 0x00000045; |
| 1434 | param->reg_DQIDLY = 0x000000B3; |
| 1435 | param->reg_FREQ = 0x000057C0; |
| 1436 | param->madj_max = 76; |
| 1437 | param->dll2_finetune_step = 3; |
| 1438 | break; |
| 1439 | } |
| 1440 | |
| 1441 | switch (param->dram_chipid) { |
| 1442 | case AST_DRAM_512Mx16: |
| 1443 | param->dram_config = 0x100; |
| 1444 | break; |
| 1445 | default: |
| 1446 | case AST_DRAM_1Gx16: |
| 1447 | param->dram_config = 0x121; |
| 1448 | break; |
| 1449 | case AST_DRAM_2Gx16: |
| 1450 | param->dram_config = 0x122; |
| 1451 | break; |
| 1452 | case AST_DRAM_4Gx16: |
| 1453 | param->dram_config = 0x123; |
| 1454 | break; |
| 1455 | }; /* switch size */ |
| 1456 | |
| 1457 | switch (param->vram_size) { |
| 1458 | default: |
| 1459 | case AST_VIDMEM_SIZE_8M: |
| 1460 | param->dram_config |= 0x00; |
| 1461 | break; |
| 1462 | case AST_VIDMEM_SIZE_16M: |
| 1463 | param->dram_config |= 0x04; |
| 1464 | break; |
| 1465 | case AST_VIDMEM_SIZE_32M: |
| 1466 | param->dram_config |= 0x08; |
| 1467 | break; |
| 1468 | case AST_VIDMEM_SIZE_64M: |
| 1469 | param->dram_config |= 0x0c; |
| 1470 | break; |
| 1471 | } |
| 1472 | } |
| 1473 | |
| 1474 | static void ddr2_init(struct ast_private *ast, struct ast2300_dram_param *param) |
| 1475 | { |
Dave Airlie | 318cfa2 | 2014-01-17 11:36:14 +1000 | [diff] [blame] | 1476 | u32 data, data2, retry = 0; |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1477 | |
Dave Airlie | 318cfa2 | 2014-01-17 11:36:14 +1000 | [diff] [blame] | 1478 | ddr2_init_start: |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1479 | ast_moutdwm(ast, 0x1E6E0000, 0xFC600309); |
| 1480 | ast_moutdwm(ast, 0x1E6E0018, 0x00000100); |
| 1481 | ast_moutdwm(ast, 0x1E6E0024, 0x00000000); |
| 1482 | ast_moutdwm(ast, 0x1E6E0064, param->reg_MADJ); |
| 1483 | ast_moutdwm(ast, 0x1E6E0068, param->reg_SADJ); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1484 | udelay(10); |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1485 | ast_moutdwm(ast, 0x1E6E0064, param->reg_MADJ | 0xC0000); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1486 | udelay(10); |
| 1487 | |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1488 | ast_moutdwm(ast, 0x1E6E0004, param->dram_config); |
| 1489 | ast_moutdwm(ast, 0x1E6E0008, 0x90040f); |
| 1490 | ast_moutdwm(ast, 0x1E6E0010, param->reg_AC1); |
| 1491 | ast_moutdwm(ast, 0x1E6E0014, param->reg_AC2); |
| 1492 | ast_moutdwm(ast, 0x1E6E0020, param->reg_DQSIC); |
| 1493 | ast_moutdwm(ast, 0x1E6E0080, 0x00000000); |
| 1494 | ast_moutdwm(ast, 0x1E6E0084, 0x00000000); |
| 1495 | ast_moutdwm(ast, 0x1E6E0088, param->reg_DQIDLY); |
| 1496 | ast_moutdwm(ast, 0x1E6E0018, 0x4000A130); |
| 1497 | ast_moutdwm(ast, 0x1E6E0018, 0x00002330); |
| 1498 | ast_moutdwm(ast, 0x1E6E0038, 0x00000000); |
| 1499 | ast_moutdwm(ast, 0x1E6E0040, 0xFF808000); |
| 1500 | ast_moutdwm(ast, 0x1E6E0044, 0x88848466); |
| 1501 | ast_moutdwm(ast, 0x1E6E0048, 0x44440008); |
| 1502 | ast_moutdwm(ast, 0x1E6E004C, 0x00000000); |
| 1503 | ast_moutdwm(ast, 0x1E6E0050, 0x80000000); |
| 1504 | ast_moutdwm(ast, 0x1E6E0050, 0x00000000); |
| 1505 | ast_moutdwm(ast, 0x1E6E0054, 0); |
| 1506 | ast_moutdwm(ast, 0x1E6E0060, param->reg_DRV); |
| 1507 | ast_moutdwm(ast, 0x1E6E006C, param->reg_IOZ); |
| 1508 | ast_moutdwm(ast, 0x1E6E0070, 0x00000000); |
| 1509 | ast_moutdwm(ast, 0x1E6E0074, 0x00000000); |
| 1510 | ast_moutdwm(ast, 0x1E6E0078, 0x00000000); |
| 1511 | ast_moutdwm(ast, 0x1E6E007C, 0x00000000); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1512 | |
| 1513 | /* Wait MCLK2X lock to MCLK */ |
| 1514 | do { |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1515 | data = ast_mindwm(ast, 0x1E6E001C); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1516 | } while (!(data & 0x08000000)); |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1517 | data = ast_mindwm(ast, 0x1E6E001C); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1518 | data = (data >> 8) & 0xff; |
| 1519 | while ((data & 0x08) || ((data & 0x7) < 2) || (data < 4)) { |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1520 | data2 = (ast_mindwm(ast, 0x1E6E0064) & 0xfff3ffff) + 4; |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1521 | if ((data2 & 0xff) > param->madj_max) { |
| 1522 | break; |
| 1523 | } |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1524 | ast_moutdwm(ast, 0x1E6E0064, data2); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1525 | if (data2 & 0x00100000) { |
| 1526 | data2 = ((data2 & 0xff) >> 3) + 3; |
| 1527 | } else { |
| 1528 | data2 = ((data2 & 0xff) >> 2) + 5; |
| 1529 | } |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1530 | data = ast_mindwm(ast, 0x1E6E0068) & 0xffff00ff; |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1531 | data2 += data & 0xff; |
| 1532 | data = data | (data2 << 8); |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1533 | ast_moutdwm(ast, 0x1E6E0068, data); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1534 | udelay(10); |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1535 | ast_moutdwm(ast, 0x1E6E0064, ast_mindwm(ast, 0x1E6E0064) | 0xC0000); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1536 | udelay(10); |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1537 | data = ast_mindwm(ast, 0x1E6E0018) & 0xfffff1ff; |
| 1538 | ast_moutdwm(ast, 0x1E6E0018, data); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1539 | data = data | 0x200; |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1540 | ast_moutdwm(ast, 0x1E6E0018, data); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1541 | do { |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1542 | data = ast_mindwm(ast, 0x1E6E001C); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1543 | } while (!(data & 0x08000000)); |
| 1544 | |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1545 | data = ast_mindwm(ast, 0x1E6E001C); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1546 | data = (data >> 8) & 0xff; |
| 1547 | } |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1548 | ast_moutdwm(ast, 0x1E720058, ast_mindwm(ast, 0x1E6E0008) & 0xffff); |
| 1549 | data = ast_mindwm(ast, 0x1E6E0018) | 0xC00; |
| 1550 | ast_moutdwm(ast, 0x1E6E0018, data); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1551 | |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1552 | ast_moutdwm(ast, 0x1E6E0034, 0x00000001); |
| 1553 | ast_moutdwm(ast, 0x1E6E000C, 0x00000000); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1554 | udelay(50); |
| 1555 | /* Mode Register Setting */ |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1556 | ast_moutdwm(ast, 0x1E6E002C, param->reg_MRS | 0x100); |
| 1557 | ast_moutdwm(ast, 0x1E6E0030, param->reg_EMRS); |
| 1558 | ast_moutdwm(ast, 0x1E6E0028, 0x00000005); |
| 1559 | ast_moutdwm(ast, 0x1E6E0028, 0x00000007); |
| 1560 | ast_moutdwm(ast, 0x1E6E0028, 0x00000003); |
| 1561 | ast_moutdwm(ast, 0x1E6E0028, 0x00000001); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1562 | |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1563 | ast_moutdwm(ast, 0x1E6E000C, 0x00005C08); |
| 1564 | ast_moutdwm(ast, 0x1E6E002C, param->reg_MRS); |
| 1565 | ast_moutdwm(ast, 0x1E6E0028, 0x00000001); |
| 1566 | ast_moutdwm(ast, 0x1E6E0030, param->reg_EMRS | 0x380); |
| 1567 | ast_moutdwm(ast, 0x1E6E0028, 0x00000003); |
| 1568 | ast_moutdwm(ast, 0x1E6E0030, param->reg_EMRS); |
| 1569 | ast_moutdwm(ast, 0x1E6E0028, 0x00000003); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1570 | |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1571 | ast_moutdwm(ast, 0x1E6E000C, 0x7FFF5C01); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1572 | data = 0; |
| 1573 | if (param->wodt) { |
| 1574 | data = 0x500; |
| 1575 | } |
| 1576 | if (param->rodt) { |
| 1577 | data = data | 0x3000 | ((param->reg_AC2 & 0x60000) >> 3); |
| 1578 | } |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1579 | ast_moutdwm(ast, 0x1E6E0034, data | 0x3); |
| 1580 | ast_moutdwm(ast, 0x1E6E0120, param->reg_FREQ); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1581 | |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1582 | /* Calibrate the DQSI delay */ |
Dave Airlie | 318cfa2 | 2014-01-17 11:36:14 +1000 | [diff] [blame] | 1583 | if ((cbr_dll2(ast, param) == false) && (retry++ < 10)) |
| 1584 | goto ddr2_init_start; |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1585 | |
| 1586 | /* ECC Memory Initialization */ |
| 1587 | #ifdef ECC |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1588 | ast_moutdwm(ast, 0x1E6E007C, 0x00000000); |
| 1589 | ast_moutdwm(ast, 0x1E6E0070, 0x221); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1590 | do { |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1591 | data = ast_mindwm(ast, 0x1E6E0070); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1592 | } while (!(data & 0x00001000)); |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1593 | ast_moutdwm(ast, 0x1E6E0070, 0x00000000); |
| 1594 | ast_moutdwm(ast, 0x1E6E0050, 0x80000000); |
| 1595 | ast_moutdwm(ast, 0x1E6E0050, 0x00000000); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1596 | #endif |
| 1597 | |
| 1598 | } |
| 1599 | |
| 1600 | static void ast_init_dram_2300(struct drm_device *dev) |
| 1601 | { |
| 1602 | struct ast_private *ast = dev->dev_private; |
| 1603 | struct ast2300_dram_param param; |
| 1604 | u32 temp; |
| 1605 | u8 reg; |
| 1606 | |
| 1607 | reg = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd0, 0xff); |
| 1608 | if ((reg & 0x80) == 0) {/* vga only */ |
| 1609 | ast_write32(ast, 0xf004, 0x1e6e0000); |
| 1610 | ast_write32(ast, 0xf000, 0x1); |
| 1611 | ast_write32(ast, 0x12000, 0x1688a8a8); |
| 1612 | do { |
| 1613 | ; |
| 1614 | } while (ast_read32(ast, 0x12000) != 0x1); |
| 1615 | |
| 1616 | ast_write32(ast, 0x10000, 0xfc600309); |
| 1617 | do { |
| 1618 | ; |
| 1619 | } while (ast_read32(ast, 0x10000) != 0x1); |
| 1620 | |
| 1621 | /* Slow down CPU/AHB CLK in VGA only mode */ |
| 1622 | temp = ast_read32(ast, 0x12008); |
| 1623 | temp |= 0x73; |
| 1624 | ast_write32(ast, 0x12008, temp); |
| 1625 | |
| 1626 | param.dram_type = AST_DDR3; |
| 1627 | if (temp & 0x01000000) |
| 1628 | param.dram_type = AST_DDR2; |
| 1629 | param.dram_chipid = ast->dram_type; |
| 1630 | param.dram_freq = ast->mclk; |
| 1631 | param.vram_size = ast->vram_size; |
| 1632 | |
| 1633 | if (param.dram_type == AST_DDR3) { |
| 1634 | get_ddr3_info(ast, ¶m); |
| 1635 | ddr3_init(ast, ¶m); |
| 1636 | } else { |
| 1637 | get_ddr2_info(ast, ¶m); |
| 1638 | ddr2_init(ast, ¶m); |
| 1639 | } |
| 1640 | |
Dave Airlie | 0e5ce92 | 2014-03-28 10:22:41 +1000 | [diff] [blame^] | 1641 | temp = ast_mindwm(ast, 0x1e6e2040); |
| 1642 | ast_moutdwm(ast, 0x1e6e2040, temp | 0x40); |
Dave Airlie | 312fec1 | 2012-02-29 13:40:04 +0000 | [diff] [blame] | 1643 | } |
| 1644 | |
| 1645 | /* wait ready */ |
| 1646 | do { |
| 1647 | reg = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd0, 0xff); |
| 1648 | } while ((reg & 0x40) == 0); |
| 1649 | } |
| 1650 | |