York Sun | 667ab1a | 2012-10-11 07:13:37 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2009-2012 Freescale Semiconductor, Inc. |
| 3 | * |
| 4 | * See file CREDITS for list of people who contributed to this |
| 5 | * project. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License as |
| 9 | * published by the Free Software Foundation; either version 2 of |
| 10 | * the License, or (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 20 | * MA 02111-1307 USA |
| 21 | */ |
| 22 | |
| 23 | #include <common.h> |
| 24 | #include <command.h> |
| 25 | #include <i2c.h> |
| 26 | #include <netdev.h> |
| 27 | #include <linux/compiler.h> |
| 28 | #include <asm/mmu.h> |
| 29 | #include <asm/processor.h> |
| 30 | #include <asm/cache.h> |
| 31 | #include <asm/immap_85xx.h> |
| 32 | #include <asm/fsl_law.h> |
| 33 | #include <asm/fsl_serdes.h> |
| 34 | #include <asm/fsl_portals.h> |
| 35 | #include <asm/fsl_liodn.h> |
| 36 | #include <fm_eth.h> |
| 37 | |
| 38 | #include "../common/qixis.h" |
| 39 | #include "../common/vsc3316_3308.h" |
| 40 | #include "t4qds.h" |
| 41 | #include "t4240qds_qixis.h" |
| 42 | |
| 43 | DECLARE_GLOBAL_DATA_PTR; |
| 44 | |
Timur Tabi | e9fabd8 | 2012-12-12 11:07:12 +0000 | [diff] [blame] | 45 | static const int8_t vsc3316_fsm1_tx[8][2] = { {0, 0}, {1, 1}, {6, 6}, {7, 7}, |
| 46 | {8, 8}, {9, 9}, {14, 14}, {15, 15} }; |
| 47 | |
| 48 | static const int8_t vsc3316_fsm2_tx[8][2] = { {2, 2}, {3, 3}, {4, 4}, {5, 5}, |
| 49 | {10, 10}, {11, 11}, {12, 12}, {13, 13} }; |
| 50 | |
| 51 | static const int8_t vsc3316_fsm1_rx[8][2] = { {2, 12}, {3, 13}, {4, 5}, {5, 4}, |
| 52 | {10, 11}, {11, 10}, {12, 2}, {13, 3} }; |
| 53 | |
| 54 | static const int8_t vsc3316_fsm2_rx[8][2] = { {0, 15}, {1, 14}, {6, 7}, {7, 6}, |
| 55 | {8, 9}, {9, 8}, {14, 1}, {15, 0} }; |
| 56 | |
York Sun | 667ab1a | 2012-10-11 07:13:37 +0000 | [diff] [blame] | 57 | int checkboard(void) |
| 58 | { |
Prabhakar Kushwaha | 033d07e | 2012-12-23 19:26:03 +0000 | [diff] [blame] | 59 | char buf[64]; |
York Sun | 667ab1a | 2012-10-11 07:13:37 +0000 | [diff] [blame] | 60 | u8 sw; |
Simon Glass | a8b5739 | 2012-12-13 20:48:48 +0000 | [diff] [blame] | 61 | struct cpu_type *cpu = gd->arch.cpu; |
York Sun | 667ab1a | 2012-10-11 07:13:37 +0000 | [diff] [blame] | 62 | ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR; |
| 63 | unsigned int i; |
| 64 | |
| 65 | printf("Board: %sQDS, ", cpu->name); |
Prabhakar Kushwaha | 033d07e | 2012-12-23 19:26:03 +0000 | [diff] [blame] | 66 | printf("Sys ID: 0x%02x, Sys Ver: 0x%02x, ", |
| 67 | QIXIS_READ(id), QIXIS_READ(arch)); |
York Sun | 667ab1a | 2012-10-11 07:13:37 +0000 | [diff] [blame] | 68 | |
| 69 | sw = QIXIS_READ(brdcfg[0]); |
| 70 | sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT; |
| 71 | |
| 72 | if (sw < 0x8) |
| 73 | printf("vBank: %d\n", sw); |
| 74 | else if (sw == 0x8) |
| 75 | puts("Promjet\n"); |
| 76 | else if (sw == 0x9) |
| 77 | puts("NAND\n"); |
| 78 | else |
| 79 | printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH); |
| 80 | |
Prabhakar Kushwaha | 033d07e | 2012-12-23 19:26:03 +0000 | [diff] [blame] | 81 | printf("FPGA: v%d (%s), build %d", |
| 82 | (int)QIXIS_READ(scver), qixis_read_tag(buf), |
| 83 | (int)qixis_read_minor()); |
| 84 | /* the timestamp string contains "\n" at the end */ |
| 85 | printf(" on %s", qixis_read_time(buf)); |
| 86 | |
York Sun | 667ab1a | 2012-10-11 07:13:37 +0000 | [diff] [blame] | 87 | /* Display the RCW, so that no one gets confused as to what RCW |
| 88 | * we're actually using for this boot. |
| 89 | */ |
| 90 | puts("Reset Configuration Word (RCW):"); |
| 91 | for (i = 0; i < ARRAY_SIZE(gur->rcwsr); i++) { |
| 92 | u32 rcw = in_be32(&gur->rcwsr[i]); |
| 93 | |
| 94 | if ((i % 4) == 0) |
| 95 | printf("\n %08x:", i * 4); |
| 96 | printf(" %08x", rcw); |
| 97 | } |
| 98 | puts("\n"); |
| 99 | |
| 100 | /* |
| 101 | * Display the actual SERDES reference clocks as configured by the |
| 102 | * dip switches on the board. Note that the SWx registers could |
| 103 | * technically be set to force the reference clocks to match the |
| 104 | * values that the SERDES expects (or vice versa). For now, however, |
| 105 | * we just display both values and hope the user notices when they |
| 106 | * don't match. |
| 107 | */ |
| 108 | puts("SERDES Reference Clocks: "); |
| 109 | sw = QIXIS_READ(brdcfg[2]); |
| 110 | for (i = 0; i < MAX_SERDES; i++) { |
| 111 | static const char *freq[] = { |
| 112 | "100", "125", "156.25", "161.1328125"}; |
Roy Zang | c04362f | 2013-03-25 07:33:15 +0000 | [diff] [blame] | 113 | unsigned int clock = (sw >> (6 - 2 * i)) & 3; |
York Sun | 667ab1a | 2012-10-11 07:13:37 +0000 | [diff] [blame] | 114 | |
| 115 | printf("SERDES%u=%sMHz ", i+1, freq[clock]); |
| 116 | } |
| 117 | puts("\n"); |
| 118 | |
| 119 | return 0; |
| 120 | } |
| 121 | |
| 122 | int select_i2c_ch_pca9547(u8 ch) |
| 123 | { |
| 124 | int ret; |
| 125 | |
| 126 | ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1); |
| 127 | if (ret) { |
| 128 | puts("PCA: failed to select proper channel\n"); |
| 129 | return ret; |
| 130 | } |
| 131 | |
| 132 | return 0; |
| 133 | } |
| 134 | |
York Sun | d58bef1 | 2013-03-25 07:33:22 +0000 | [diff] [blame^] | 135 | /* |
| 136 | * read_voltage from sensor on I2C bus |
| 137 | * We use average of 4 readings, waiting for 532us befor another reading |
| 138 | */ |
| 139 | #define NUM_READINGS 4 /* prefer to be power of 2 for efficiency */ |
| 140 | #define WAIT_FOR_ADC 532 /* wait for 532 microseconds for ADC */ |
| 141 | |
| 142 | static inline int read_voltage(void) |
| 143 | { |
| 144 | int i, ret, voltage_read = 0; |
| 145 | u16 vol_mon; |
| 146 | |
| 147 | for (i = 0; i < NUM_READINGS; i++) { |
| 148 | ret = i2c_read(I2C_VOL_MONITOR_ADDR, |
| 149 | I2C_VOL_MONITOR_BUS_V_OFFSET, 1, (void *)&vol_mon, 2); |
| 150 | if (ret) { |
| 151 | printf("VID: failed to read core voltage\n"); |
| 152 | return ret; |
| 153 | } |
| 154 | if (vol_mon & I2C_VOL_MONITOR_BUS_V_OVF) { |
| 155 | printf("VID: Core voltage sensor error\n"); |
| 156 | return -1; |
| 157 | } |
| 158 | debug("VID: bus voltage reads 0x%04x\n", vol_mon); |
| 159 | /* LSB = 4mv */ |
| 160 | voltage_read += (vol_mon >> I2C_VOL_MONITOR_BUS_V_SHIFT) * 4; |
| 161 | udelay(WAIT_FOR_ADC); |
| 162 | } |
| 163 | /* calculate the average */ |
| 164 | voltage_read /= NUM_READINGS; |
| 165 | |
| 166 | return voltage_read; |
| 167 | } |
| 168 | |
| 169 | /* |
| 170 | * We need to calculate how long before the voltage starts to drop or increase |
| 171 | * It returns with the loop count. Each loop takes several readings (532us) |
| 172 | */ |
| 173 | static inline int wait_for_voltage_change(int vdd_last) |
| 174 | { |
| 175 | int timeout, vdd_current; |
| 176 | |
| 177 | vdd_current = read_voltage(); |
| 178 | /* wait until voltage starts to drop */ |
| 179 | for (timeout = 0; abs(vdd_last - vdd_current) <= 4 && |
| 180 | timeout < 100; timeout++) { |
| 181 | vdd_current = read_voltage(); |
| 182 | } |
| 183 | if (timeout >= 100) { |
| 184 | printf("VID: Voltage adjustment timeout\n"); |
| 185 | return -1; |
| 186 | } |
| 187 | return timeout; |
| 188 | } |
| 189 | |
| 190 | /* |
| 191 | * argument 'wait' is the time we know the voltage difference can be measured |
| 192 | * this function keeps reading the voltage until it is stable |
| 193 | */ |
| 194 | static inline int wait_for_voltage_stable(int wait) |
| 195 | { |
| 196 | int timeout, vdd_current, vdd_last; |
| 197 | |
| 198 | vdd_last = read_voltage(); |
| 199 | udelay(wait * NUM_READINGS * WAIT_FOR_ADC); |
| 200 | /* wait until voltage is stable */ |
| 201 | vdd_current = read_voltage(); |
| 202 | for (timeout = 0; abs(vdd_last - vdd_current) >= 4 && |
| 203 | timeout < 100; timeout++) { |
| 204 | vdd_last = vdd_current; |
| 205 | udelay(wait * NUM_READINGS * WAIT_FOR_ADC); |
| 206 | vdd_current = read_voltage(); |
| 207 | } |
| 208 | if (timeout >= 100) { |
| 209 | printf("VID: Voltage adjustment timeout\n"); |
| 210 | return -1; |
| 211 | } |
| 212 | |
| 213 | return vdd_current; |
| 214 | } |
| 215 | |
| 216 | static inline int set_voltage(u8 vid) |
| 217 | { |
| 218 | int wait, vdd_last; |
| 219 | |
| 220 | vdd_last = read_voltage(); |
| 221 | QIXIS_WRITE(brdcfg[6], vid); |
| 222 | wait = wait_for_voltage_change(vdd_last); |
| 223 | if (wait < 0) |
| 224 | return -1; |
| 225 | debug("VID: Waited %d us\n", wait * NUM_READINGS * WAIT_FOR_ADC); |
| 226 | wait = wait ? wait : 1; |
| 227 | |
| 228 | vdd_last = wait_for_voltage_stable(wait); |
| 229 | if (vdd_last < 0) |
| 230 | return -1; |
| 231 | debug("VID: Current voltage is %d mV\n", vdd_last); |
| 232 | |
| 233 | return vdd_last; |
| 234 | } |
| 235 | |
| 236 | |
| 237 | static int adjust_vdd(void) |
| 238 | { |
| 239 | int re_enable = disable_interrupts(); |
| 240 | ccsr_gur_t __iomem *gur = |
| 241 | (void __iomem *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); |
| 242 | u32 fusesr; |
| 243 | u8 vid, vid_current; |
| 244 | int vdd_target, vdd_current, vdd_last; |
| 245 | int ret; |
| 246 | static const uint16_t vdd[32] = { |
| 247 | 0, /* unused */ |
| 248 | 9875, /* 0.9875V */ |
| 249 | 9750, |
| 250 | 9625, |
| 251 | 9500, |
| 252 | 9375, |
| 253 | 9250, |
| 254 | 9125, |
| 255 | 9000, |
| 256 | 8875, |
| 257 | 8750, |
| 258 | 8625, |
| 259 | 8500, |
| 260 | 8375, |
| 261 | 8250, |
| 262 | 8125, |
| 263 | 10000, /* 1.0000V */ |
| 264 | 10125, |
| 265 | 10250, |
| 266 | 10375, |
| 267 | 10500, |
| 268 | 10625, |
| 269 | 10750, |
| 270 | 10875, |
| 271 | 11000, |
| 272 | 0, /* reserved */ |
| 273 | }; |
| 274 | struct vdd_drive { |
| 275 | u8 vid; |
| 276 | unsigned voltage; |
| 277 | }; |
| 278 | |
| 279 | ret = select_i2c_ch_pca9547(I2C_MUX_CH_VOL_MONITOR); |
| 280 | if (ret) { |
| 281 | debug("VID: I2c failed to switch channel\n"); |
| 282 | ret = -1; |
| 283 | goto exit; |
| 284 | } |
| 285 | |
| 286 | /* get the voltage ID from fuse status register */ |
| 287 | fusesr = in_be32(&gur->dcfg_fusesr); |
| 288 | vid = (fusesr >> FSL_CORENET_DCFG_FUSESR_VID_SHIFT) & |
| 289 | FSL_CORENET_DCFG_FUSESR_VID_MASK; |
| 290 | if (vid == FSL_CORENET_DCFG_FUSESR_VID_MASK) { |
| 291 | vid = (fusesr >> FSL_CORENET_DCFG_FUSESR_ALTVID_SHIFT) & |
| 292 | FSL_CORENET_DCFG_FUSESR_ALTVID_MASK; |
| 293 | } |
| 294 | vdd_target = vdd[vid]; |
| 295 | if (vdd_target == 0) { |
| 296 | debug("VID: VID not used\n"); |
| 297 | ret = 0; |
| 298 | goto exit; |
| 299 | } else { |
| 300 | /* round up and divice by 10 to get a value in mV */ |
| 301 | vdd_target = DIV_ROUND_UP(vdd_target, 10); |
| 302 | debug("VID: vid = %d mV\n", vdd_target); |
| 303 | } |
| 304 | |
| 305 | /* |
| 306 | * Check current board VID setting |
| 307 | * Voltage regulator support output to 6.250mv step |
| 308 | * The highes voltage allowed for this board is (vid=0x40) 1.21250V |
| 309 | * the lowest is (vid=0x7f) 0.81875V |
| 310 | */ |
| 311 | vid_current = QIXIS_READ(brdcfg[6]); |
| 312 | vdd_current = 121250 - (vid_current - 0x40) * 625; |
| 313 | debug("VID: Current vid setting is (0x%x) %d mV\n", |
| 314 | vid_current, vdd_current/100); |
| 315 | |
| 316 | /* |
| 317 | * Read voltage monitor to check real voltage. |
| 318 | * Voltage monitor LSB is 4mv. |
| 319 | */ |
| 320 | vdd_last = read_voltage(); |
| 321 | if (vdd_last < 0) { |
| 322 | printf("VID: Could not read voltage sensor abort VID adjustment\n"); |
| 323 | ret = -1; |
| 324 | goto exit; |
| 325 | } |
| 326 | debug("VID: Core voltage is at %d mV\n", vdd_last); |
| 327 | /* |
| 328 | * Adjust voltage to at or 8mV above target. |
| 329 | * Each step of adjustment is 6.25mV. |
| 330 | * Stepping down too fast may cause over current. |
| 331 | */ |
| 332 | while (vdd_last > 0 && vid_current < 0x80 && |
| 333 | vdd_last > (vdd_target + 8)) { |
| 334 | vid_current++; |
| 335 | vdd_last = set_voltage(vid_current); |
| 336 | } |
| 337 | /* |
| 338 | * Check if we need to step up |
| 339 | * This happens when board voltage switch was set too low |
| 340 | */ |
| 341 | while (vdd_last > 0 && vid_current >= 0x40 && |
| 342 | vdd_last < vdd_target + 2) { |
| 343 | vid_current--; |
| 344 | vdd_last = set_voltage(vid_current); |
| 345 | } |
| 346 | if (vdd_last > 0) |
| 347 | printf("VID: Core voltage %d mV\n", vdd_last); |
| 348 | else |
| 349 | ret = -1; |
| 350 | |
| 351 | exit: |
| 352 | if (re_enable) |
| 353 | enable_interrupts(); |
| 354 | return ret; |
| 355 | } |
| 356 | |
York Sun | 667ab1a | 2012-10-11 07:13:37 +0000 | [diff] [blame] | 357 | /* Configure Crossbar switches for Front-Side SerDes Ports */ |
| 358 | int config_frontside_crossbar_vsc3316(void) |
| 359 | { |
| 360 | ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); |
| 361 | u32 srds_prtcl_s1, srds_prtcl_s2; |
| 362 | int ret; |
| 363 | |
| 364 | ret = select_i2c_ch_pca9547(I2C_MUX_CH_VSC3316_FS); |
| 365 | if (ret) |
| 366 | return ret; |
| 367 | |
| 368 | srds_prtcl_s1 = in_be32(&gur->rcwsr[4]) & |
| 369 | FSL_CORENET2_RCWSR4_SRDS1_PRTCL; |
| 370 | srds_prtcl_s1 >>= FSL_CORENET2_RCWSR4_SRDS1_PRTCL_SHIFT; |
| 371 | if (srds_prtcl_s1) { |
| 372 | ret = vsc3316_config(VSC3316_FSM_TX_ADDR, vsc3316_fsm1_tx, 8); |
| 373 | if (ret) |
| 374 | return ret; |
| 375 | ret = vsc3316_config(VSC3316_FSM_RX_ADDR, vsc3316_fsm1_rx, 8); |
| 376 | if (ret) |
| 377 | return ret; |
| 378 | } |
| 379 | |
| 380 | srds_prtcl_s2 = in_be32(&gur->rcwsr[4]) & |
| 381 | FSL_CORENET2_RCWSR4_SRDS2_PRTCL; |
| 382 | srds_prtcl_s2 >>= FSL_CORENET2_RCWSR4_SRDS2_PRTCL_SHIFT; |
| 383 | if (srds_prtcl_s2) { |
| 384 | ret = vsc3316_config(VSC3316_FSM_TX_ADDR, vsc3316_fsm2_tx, 8); |
| 385 | if (ret) |
| 386 | return ret; |
| 387 | ret = vsc3316_config(VSC3316_FSM_RX_ADDR, vsc3316_fsm2_rx, 8); |
| 388 | if (ret) |
| 389 | return ret; |
| 390 | } |
| 391 | |
| 392 | return 0; |
| 393 | } |
| 394 | |
| 395 | int config_backside_crossbar_mux(void) |
| 396 | { |
| 397 | ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); |
| 398 | u32 srds_prtcl_s3, srds_prtcl_s4; |
| 399 | u8 brdcfg; |
| 400 | |
| 401 | srds_prtcl_s3 = in_be32(&gur->rcwsr[4]) & |
| 402 | FSL_CORENET2_RCWSR4_SRDS3_PRTCL; |
| 403 | srds_prtcl_s3 >>= FSL_CORENET2_RCWSR4_SRDS3_PRTCL_SHIFT; |
| 404 | switch (srds_prtcl_s3) { |
| 405 | case 0: |
| 406 | /* SerDes3 is not enabled */ |
| 407 | break; |
| 408 | case 2: |
| 409 | case 9: |
| 410 | case 10: |
| 411 | /* SD3(0:7) => SLOT5(0:7) */ |
| 412 | brdcfg = QIXIS_READ(brdcfg[12]); |
| 413 | brdcfg &= ~BRDCFG12_SD3MX_MASK; |
| 414 | brdcfg |= BRDCFG12_SD3MX_SLOT5; |
| 415 | QIXIS_WRITE(brdcfg[12], brdcfg); |
| 416 | break; |
| 417 | case 4: |
| 418 | case 6: |
| 419 | case 8: |
| 420 | case 12: |
| 421 | case 14: |
| 422 | case 16: |
| 423 | case 17: |
| 424 | case 19: |
| 425 | case 20: |
| 426 | /* SD3(4:7) => SLOT6(0:3) */ |
| 427 | brdcfg = QIXIS_READ(brdcfg[12]); |
| 428 | brdcfg &= ~BRDCFG12_SD3MX_MASK; |
| 429 | brdcfg |= BRDCFG12_SD3MX_SLOT6; |
| 430 | QIXIS_WRITE(brdcfg[12], brdcfg); |
| 431 | break; |
| 432 | default: |
| 433 | printf("WARNING: unsupported for SerDes3 Protocol %d\n", |
| 434 | srds_prtcl_s3); |
| 435 | return -1; |
| 436 | } |
| 437 | |
| 438 | srds_prtcl_s4 = in_be32(&gur->rcwsr[4]) & |
| 439 | FSL_CORENET2_RCWSR4_SRDS4_PRTCL; |
| 440 | srds_prtcl_s4 >>= FSL_CORENET2_RCWSR4_SRDS4_PRTCL_SHIFT; |
| 441 | switch (srds_prtcl_s4) { |
| 442 | case 0: |
| 443 | /* SerDes4 is not enabled */ |
| 444 | break; |
| 445 | case 2: |
| 446 | /* 10b, SD4(0:7) => SLOT7(0:7) */ |
| 447 | brdcfg = QIXIS_READ(brdcfg[12]); |
| 448 | brdcfg &= ~BRDCFG12_SD4MX_MASK; |
| 449 | brdcfg |= BRDCFG12_SD4MX_SLOT7; |
| 450 | QIXIS_WRITE(brdcfg[12], brdcfg); |
| 451 | break; |
| 452 | case 4: |
| 453 | case 6: |
| 454 | case 8: |
| 455 | /* x1b, SD4(4:7) => SLOT8(0:3) */ |
| 456 | brdcfg = QIXIS_READ(brdcfg[12]); |
| 457 | brdcfg &= ~BRDCFG12_SD4MX_MASK; |
| 458 | brdcfg |= BRDCFG12_SD4MX_SLOT8; |
| 459 | QIXIS_WRITE(brdcfg[12], brdcfg); |
| 460 | break; |
| 461 | case 10: |
| 462 | case 12: |
| 463 | case 14: |
| 464 | case 16: |
| 465 | case 18: |
| 466 | /* 00b, SD4(4:5) => AURORA, SD4(6:7) => SATA */ |
| 467 | brdcfg = QIXIS_READ(brdcfg[12]); |
| 468 | brdcfg &= ~BRDCFG12_SD4MX_MASK; |
| 469 | brdcfg |= BRDCFG12_SD4MX_AURO_SATA; |
| 470 | QIXIS_WRITE(brdcfg[12], brdcfg); |
| 471 | break; |
| 472 | default: |
| 473 | printf("WARNING: unsupported for SerDes4 Protocol %d\n", |
| 474 | srds_prtcl_s4); |
| 475 | return -1; |
| 476 | } |
| 477 | |
| 478 | return 0; |
| 479 | } |
| 480 | |
| 481 | int board_early_init_r(void) |
| 482 | { |
| 483 | const unsigned int flashbase = CONFIG_SYS_FLASH_BASE; |
| 484 | const u8 flash_esel = find_tlb_idx((void *)flashbase, 1); |
| 485 | |
| 486 | /* |
| 487 | * Remap Boot flash + PROMJET region to caching-inhibited |
| 488 | * so that flash can be erased properly. |
| 489 | */ |
| 490 | |
| 491 | /* Flush d-cache and invalidate i-cache of any FLASH data */ |
| 492 | flush_dcache(); |
| 493 | invalidate_icache(); |
| 494 | |
| 495 | /* invalidate existing TLB entry for flash + promjet */ |
| 496 | disable_tlb(flash_esel); |
| 497 | |
| 498 | set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS, |
| 499 | MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G, |
| 500 | 0, flash_esel, BOOKE_PAGESZ_256M, 1); |
| 501 | |
| 502 | set_liodns(); |
| 503 | #ifdef CONFIG_SYS_DPAA_QBMAN |
| 504 | setup_portals(); |
| 505 | #endif |
| 506 | |
| 507 | /* Disable remote I2C connectoin */ |
| 508 | QIXIS_WRITE(brdcfg[5], BRDCFG5_RESET); |
| 509 | |
York Sun | d58bef1 | 2013-03-25 07:33:22 +0000 | [diff] [blame^] | 510 | /* |
| 511 | * Adjust core voltage according to voltage ID |
| 512 | * This function changes I2C mux to channel 2. |
| 513 | */ |
| 514 | if (adjust_vdd()) |
| 515 | printf("Warning: Adjusting core voltage failed.\n"); |
| 516 | |
York Sun | 667ab1a | 2012-10-11 07:13:37 +0000 | [diff] [blame] | 517 | /* Configure board SERDES ports crossbar */ |
| 518 | config_frontside_crossbar_vsc3316(); |
| 519 | config_backside_crossbar_mux(); |
| 520 | select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT); |
| 521 | |
| 522 | return 0; |
| 523 | } |
| 524 | |
| 525 | unsigned long get_board_sys_clk(void) |
| 526 | { |
| 527 | u8 sysclk_conf = QIXIS_READ(brdcfg[1]); |
| 528 | |
| 529 | switch (sysclk_conf & 0x0F) { |
| 530 | case QIXIS_SYSCLK_83: |
| 531 | return 83333333; |
| 532 | case QIXIS_SYSCLK_100: |
| 533 | return 100000000; |
| 534 | case QIXIS_SYSCLK_125: |
| 535 | return 125000000; |
| 536 | case QIXIS_SYSCLK_133: |
| 537 | return 133333333; |
| 538 | case QIXIS_SYSCLK_150: |
| 539 | return 150000000; |
| 540 | case QIXIS_SYSCLK_160: |
| 541 | return 160000000; |
| 542 | case QIXIS_SYSCLK_166: |
| 543 | return 166666666; |
| 544 | } |
| 545 | return 66666666; |
| 546 | } |
| 547 | |
| 548 | unsigned long get_board_ddr_clk(void) |
| 549 | { |
| 550 | u8 ddrclk_conf = QIXIS_READ(brdcfg[1]); |
| 551 | |
| 552 | switch ((ddrclk_conf & 0x30) >> 4) { |
| 553 | case QIXIS_DDRCLK_100: |
| 554 | return 100000000; |
| 555 | case QIXIS_DDRCLK_125: |
| 556 | return 125000000; |
| 557 | case QIXIS_DDRCLK_133: |
| 558 | return 133333333; |
| 559 | } |
| 560 | return 66666666; |
| 561 | } |
| 562 | |
| 563 | static const char *serdes_clock_to_string(u32 clock) |
| 564 | { |
| 565 | switch (clock) { |
| 566 | case SRDS_PLLCR0_RFCK_SEL_100: |
| 567 | return "100"; |
| 568 | case SRDS_PLLCR0_RFCK_SEL_125: |
| 569 | return "125"; |
| 570 | case SRDS_PLLCR0_RFCK_SEL_156_25: |
| 571 | return "156.25"; |
| 572 | case SRDS_PLLCR0_RFCK_SEL_161_13: |
| 573 | return "161.1328125"; |
| 574 | default: |
| 575 | return "???"; |
| 576 | } |
| 577 | } |
| 578 | |
| 579 | int misc_init_r(void) |
| 580 | { |
| 581 | u8 sw; |
| 582 | serdes_corenet_t *srds_regs = |
| 583 | (void *)CONFIG_SYS_FSL_CORENET_SERDES_ADDR; |
| 584 | u32 actual[MAX_SERDES]; |
| 585 | unsigned int i; |
| 586 | |
| 587 | sw = QIXIS_READ(brdcfg[2]); |
| 588 | for (i = 0; i < MAX_SERDES; i++) { |
Roy Zang | c04362f | 2013-03-25 07:33:15 +0000 | [diff] [blame] | 589 | unsigned int clock = (sw >> (6 - 2 * i)) & 3; |
York Sun | 667ab1a | 2012-10-11 07:13:37 +0000 | [diff] [blame] | 590 | switch (clock) { |
| 591 | case 0: |
| 592 | actual[i] = SRDS_PLLCR0_RFCK_SEL_100; |
| 593 | break; |
| 594 | case 1: |
| 595 | actual[i] = SRDS_PLLCR0_RFCK_SEL_125; |
| 596 | break; |
| 597 | case 2: |
| 598 | actual[i] = SRDS_PLLCR0_RFCK_SEL_156_25; |
| 599 | break; |
| 600 | case 3: |
| 601 | actual[i] = SRDS_PLLCR0_RFCK_SEL_161_13; |
| 602 | break; |
| 603 | } |
| 604 | } |
| 605 | |
| 606 | for (i = 0; i < MAX_SERDES; i++) { |
| 607 | u32 pllcr0 = srds_regs->bank[i].pllcr0; |
| 608 | u32 expected = pllcr0 & SRDS_PLLCR0_RFCK_SEL_MASK; |
| 609 | if (expected != actual[i]) { |
| 610 | printf("Warning: SERDES%u expects reference clock" |
| 611 | " %sMHz, but actual is %sMHz\n", i + 1, |
| 612 | serdes_clock_to_string(expected), |
| 613 | serdes_clock_to_string(actual[i])); |
| 614 | } |
| 615 | } |
| 616 | |
| 617 | return 0; |
| 618 | } |
| 619 | |
| 620 | void ft_board_setup(void *blob, bd_t *bd) |
| 621 | { |
| 622 | phys_addr_t base; |
| 623 | phys_size_t size; |
| 624 | |
| 625 | ft_cpu_setup(blob, bd); |
| 626 | |
| 627 | base = getenv_bootm_low(); |
| 628 | size = getenv_bootm_size(); |
| 629 | |
| 630 | fdt_fixup_memory(blob, (u64)base, (u64)size); |
| 631 | |
| 632 | #ifdef CONFIG_PCI |
| 633 | pci_of_setup(blob, bd); |
| 634 | #endif |
| 635 | |
| 636 | fdt_fixup_liodn(blob); |
| 637 | fdt_fixup_dr_usb(blob, bd); |
| 638 | |
| 639 | #ifdef CONFIG_SYS_DPAA_FMAN |
| 640 | fdt_fixup_fman_ethernet(blob); |
| 641 | fdt_fixup_board_enet(blob); |
| 642 | #endif |
| 643 | } |
Shaveta Leekha | 4038ab6 | 2012-12-23 19:25:50 +0000 | [diff] [blame] | 644 | |
| 645 | /* |
| 646 | * Reverse engineering switch settings. |
| 647 | * Some bits cannot be figured out. They will be displayed as |
| 648 | * underscore in binary format. mask[] has those bits. |
| 649 | * Some bits are calculated differently than the actual switches |
| 650 | * if booting with overriding by FPGA. |
| 651 | */ |
| 652 | void qixis_dump_switch(void) |
| 653 | { |
| 654 | int i; |
| 655 | u8 sw[9]; |
| 656 | |
| 657 | /* |
| 658 | * Any bit with 1 means that bit cannot be reverse engineered. |
| 659 | * It will be displayed as _ in binary format. |
| 660 | */ |
| 661 | static const u8 mask[] = {0, 0, 0, 0, 0, 0x1, 0xdf, 0x3f, 0x1f}; |
| 662 | char buf[10]; |
| 663 | u8 brdcfg[16], dutcfg[16]; |
| 664 | |
| 665 | for (i = 0; i < 16; i++) { |
| 666 | brdcfg[i] = qixis_read(offsetof(struct qixis, brdcfg[0]) + i); |
| 667 | dutcfg[i] = qixis_read(offsetof(struct qixis, dutcfg[0]) + i); |
| 668 | } |
| 669 | |
| 670 | sw[0] = dutcfg[0]; |
| 671 | sw[1] = (dutcfg[1] << 0x07) | \ |
| 672 | ((dutcfg[12] & 0xC0) >> 1) | \ |
| 673 | ((dutcfg[11] & 0xE0) >> 3) | \ |
| 674 | ((dutcfg[6] & 0x80) >> 6) | \ |
| 675 | ((dutcfg[1] & 0x80) >> 7); |
| 676 | sw[2] = ((brdcfg[1] & 0x0f) << 4) | \ |
| 677 | ((brdcfg[1] & 0x30) >> 2) | \ |
| 678 | ((brdcfg[1] & 0x40) >> 5) | \ |
| 679 | ((brdcfg[1] & 0x80) >> 7); |
| 680 | sw[3] = brdcfg[2]; |
| 681 | sw[4] = ((dutcfg[2] & 0x01) << 7) | \ |
| 682 | ((dutcfg[2] & 0x06) << 4) | \ |
| 683 | ((~QIXIS_READ(present)) & 0x10) | \ |
| 684 | ((brdcfg[3] & 0x80) >> 4) | \ |
| 685 | ((brdcfg[3] & 0x01) << 2) | \ |
| 686 | ((brdcfg[6] == 0x62) ? 3 : \ |
| 687 | ((brdcfg[6] == 0x5a) ? 2 : \ |
| 688 | ((brdcfg[6] == 0x5e) ? 1 : 0))); |
| 689 | sw[5] = ((brdcfg[0] & 0x0f) << 4) | \ |
| 690 | ((QIXIS_READ(rst_ctl) & 0x30) >> 2) | \ |
| 691 | ((brdcfg[0] & 0x40) >> 5); |
| 692 | sw[6] = (brdcfg[11] & 0x20); |
| 693 | sw[7] = (((~QIXIS_READ(rst_ctl)) & 0x40) << 1) | \ |
| 694 | ((brdcfg[5] & 0x10) << 2); |
| 695 | sw[8] = ((brdcfg[12] & 0x08) << 4) | \ |
| 696 | ((brdcfg[12] & 0x03) << 5); |
| 697 | |
| 698 | puts("DIP switch (reverse-engineering)\n"); |
| 699 | for (i = 0; i < 9; i++) { |
| 700 | printf("SW%d = 0b%s (0x%02x)\n", |
| 701 | i + 1, byte_to_binary_mask(sw[i], mask[i], buf), sw[i]); |
| 702 | } |
| 703 | } |