Blame view
board/freescale/common/vid.c
24.8 KB
83d290c56 SPDX: Convert all... |
1 |
// SPDX-License-Identifier: GPL-2.0+ |
3ad2737ee powerpc/t208xqds:... |
2 3 |
/* * Copyright 2014 Freescale Semiconductor, Inc. |
da0505702 armv8: lx2162aqds... |
4 |
* Copyright 2020 NXP |
3ad2737ee powerpc/t208xqds:... |
5 6 7 8 |
*/ #include <common.h> #include <command.h> |
7b51b576d env: Move env_get... |
9 |
#include <env.h> |
3ad2737ee powerpc/t208xqds:... |
10 |
#include <i2c.h> |
36bf446b6 common: Move enab... |
11 |
#include <irq_func.h> |
02b5d2ed8 armv8/ls1043aqds:... |
12 |
#include <asm/io.h> |
126fe70d7 armv8: ls1046aqds... |
13 |
#ifdef CONFIG_FSL_LSCH2 |
02b5d2ed8 armv8/ls1043aqds:... |
14 |
#include <asm/arch/immap_lsch2.h> |
ed2530d09 armv8/ls2080ardb:... |
15 16 |
#elif defined(CONFIG_FSL_LSCH3) #include <asm/arch/immap_lsch3.h> |
02b5d2ed8 armv8/ls1043aqds:... |
17 |
#else |
3ad2737ee powerpc/t208xqds:... |
18 |
#include <asm/immap_85xx.h> |
02b5d2ed8 armv8/ls1043aqds:... |
19 |
#endif |
3ad2737ee powerpc/t208xqds:... |
20 |
#include "vid.h" |
3ad2737ee powerpc/t208xqds:... |
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
int __weak i2c_multiplexer_select_vid_channel(u8 channel) { return 0; } /* * Compensate for a board specific voltage drop between regulator and SoC * return a value in mV */ int __weak board_vdd_drop_compensation(void) { return 0; } /* |
3607570b1 board: common: vi... |
36 37 38 39 40 41 |
* Board specific settings for specific voltage value */ int __weak board_adjust_vdd(int vdd) { return 0; } |
9458316a3 board: common: vi... |
42 43 |
#if defined(CONFIG_VOL_MONITOR_IR36021_SET) || \ defined(CONFIG_VOL_MONITOR_IR36021_READ) |
3607570b1 board: common: vi... |
44 |
/* |
3ad2737ee powerpc/t208xqds:... |
45 46 47 48 49 50 51 52 53 54 |
* Get the i2c address configuration for the IR regulator chip * * There are some variance in the RDB HW regarding the I2C address configuration * for the IR regulator chip, which is likely a problem of external resistor * accuracy. So we just check each address in a hopefully non-intrusive mode * and use the first one that seems to work * * The IR chip can show up under the following addresses: * 0x08 (Verified on T1040RDB-PA,T4240RDB-PB,X-T4240RDB-16GPA) * 0x09 (Verified on T1040RDB-PA) |
2f66a828f powerpc/board/t42... |
55 |
* 0x38 (Verified on T2080QDS, T2081QDS, T4240RDB) |
3ad2737ee powerpc/t208xqds:... |
56 57 58 59 60 61 62 63 |
*/ static int find_ir_chip_on_i2c(void) { int i2caddress; int ret; u8 byte; int i; const int ir_i2c_addr[] = {0x38, 0x08, 0x09}; |
0eba65d20 boards: lx2160a: ... |
64 65 66 |
#ifdef CONFIG_DM_I2C struct udevice *dev; #endif |
3ad2737ee powerpc/t208xqds:... |
67 68 69 70 |
/* Check all the address */ for (i = 0; i < (sizeof(ir_i2c_addr)/sizeof(ir_i2c_addr[0])); i++) { i2caddress = ir_i2c_addr[i]; |
0eba65d20 boards: lx2160a: ... |
71 |
#ifndef CONFIG_DM_I2C |
3ad2737ee powerpc/t208xqds:... |
72 73 74 |
ret = i2c_read(i2caddress, IR36021_MFR_ID_OFFSET, 1, (void *)&byte, sizeof(byte)); |
0eba65d20 boards: lx2160a: ... |
75 76 77 78 79 80 |
#else ret = i2c_get_chip_for_busnum(0, i2caddress, 1, &dev); if (!ret) ret = dm_i2c_read(dev, IR36021_MFR_ID_OFFSET, (void *)&byte, sizeof(byte)); #endif |
3ad2737ee powerpc/t208xqds:... |
81 82 83 84 85 |
if ((ret >= 0) && (byte == IR36021_MFR_ID)) return i2caddress; } return -1; } |
9458316a3 board: common: vi... |
86 |
#endif |
3ad2737ee powerpc/t208xqds:... |
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
/* Maximum loop count waiting for new voltage to take effect */ #define MAX_LOOP_WAIT_NEW_VOL 100 /* Maximum loop count waiting for the voltage to be stable */ #define MAX_LOOP_WAIT_VOL_STABLE 100 /* * read_voltage from sensor on I2C bus * We use average of 4 readings, waiting for WAIT_FOR_ADC before * another reading */ #define NUM_READINGS 4 /* prefer to be power of 2 for efficiency */ /* If an INA220 chip is available, we can use it to read back the voltage * as it may have a higher accuracy than the IR chip for the same purpose */ #ifdef CONFIG_VOL_MONITOR_INA220 #define WAIT_FOR_ADC 532 /* wait for 532 microseconds for ADC */ #define ADC_MIN_ACCURACY 4 #else #define WAIT_FOR_ADC 138 /* wait for 138 microseconds for ADC */ #define ADC_MIN_ACCURACY 4 #endif #ifdef CONFIG_VOL_MONITOR_INA220 static int read_voltage_from_INA220(int i2caddress) { int i, ret, voltage_read = 0; u16 vol_mon; u8 buf[2]; |
0eba65d20 boards: lx2160a: ... |
116 117 118 |
#ifdef CONFIG_DM_I2C struct udevice *dev; #endif |
3ad2737ee powerpc/t208xqds:... |
119 120 |
for (i = 0; i < NUM_READINGS; i++) { |
0eba65d20 boards: lx2160a: ... |
121 |
#ifndef CONFIG_DM_I2C |
3ad2737ee powerpc/t208xqds:... |
122 123 124 |
ret = i2c_read(I2C_VOL_MONITOR_ADDR, I2C_VOL_MONITOR_BUS_V_OFFSET, 1, (void *)&buf, 2); |
0eba65d20 boards: lx2160a: ... |
125 126 127 128 129 130 |
#else ret = i2c_get_chip_for_busnum(0, I2C_VOL_MONITOR_ADDR, 1, &dev); if (!ret) ret = dm_i2c_read(dev, I2C_VOL_MONITOR_BUS_V_OFFSET, (void *)&buf, 2); #endif |
3ad2737ee powerpc/t208xqds:... |
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
if (ret) { printf("VID: failed to read core voltage "); return ret; } vol_mon = (buf[0] << 8) | buf[1]; if (vol_mon & I2C_VOL_MONITOR_BUS_V_OVF) { printf("VID: Core voltage sensor error "); return -1; } debug("VID: bus voltage reads 0x%04x ", vol_mon); /* LSB = 4mv */ voltage_read += (vol_mon >> I2C_VOL_MONITOR_BUS_V_SHIFT) * 4; udelay(WAIT_FOR_ADC); } /* calculate the average */ voltage_read /= NUM_READINGS; return voltage_read; } #endif /* read voltage from IR */ #ifdef CONFIG_VOL_MONITOR_IR36021_READ static int read_voltage_from_IR(int i2caddress) { int i, ret, voltage_read = 0; u16 vol_mon; u8 buf; |
0eba65d20 boards: lx2160a: ... |
162 163 164 |
#ifdef CONFIG_DM_I2C struct udevice *dev; #endif |
3ad2737ee powerpc/t208xqds:... |
165 166 |
for (i = 0; i < NUM_READINGS; i++) { |
0eba65d20 boards: lx2160a: ... |
167 |
#ifndef CONFIG_DM_I2C |
3ad2737ee powerpc/t208xqds:... |
168 169 170 |
ret = i2c_read(i2caddress, IR36021_LOOP1_VOUT_OFFSET, 1, (void *)&buf, 1); |
0eba65d20 boards: lx2160a: ... |
171 172 173 174 175 176 |
#else ret = i2c_get_chip_for_busnum(0, i2caddress, 1, &dev); if (!ret) ret = dm_i2c_read(dev, IR36021_LOOP1_VOUT_OFFSET, (void *)&buf, 1); #endif |
3ad2737ee powerpc/t208xqds:... |
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
if (ret) { printf("VID: failed to read vcpu "); return ret; } vol_mon = buf; if (!vol_mon) { printf("VID: Core voltage sensor error "); return -1; } debug("VID: bus voltage reads 0x%02x ", vol_mon); /* Resolution is 1/128V. We scale up here to get 1/128mV * and divide at the end */ voltage_read += vol_mon * 1000; udelay(WAIT_FOR_ADC); } /* Scale down to the real mV as IR resolution is 1/128V, rounding up */ voltage_read = DIV_ROUND_UP(voltage_read, 128); /* calculate the average */ voltage_read /= NUM_READINGS; /* Compensate for a board specific voltage drop between regulator and * SoC before converting into an IR VID value */ voltage_read -= board_vdd_drop_compensation(); return voltage_read; } #endif |
23a12cb3d board: common: vi... |
210 211 212 213 214 215 |
#ifdef CONFIG_VOL_MONITOR_LTC3882_READ /* read the current value of the LTC Regulator Voltage */ static int read_voltage_from_LTC(int i2caddress) { int ret, vcode = 0; u8 chan = PWM_CHANNEL0; |
0eba65d20 boards: lx2160a: ... |
216 |
#ifndef CONFIG_DM_I2C |
23a12cb3d board: common: vi... |
217 218 219 |
/* select the PAGE 0 using PMBus commands PAGE for VDD*/ ret = i2c_write(I2C_VOL_MONITOR_ADDR, PMBUS_CMD_PAGE, 1, &chan, 1); |
0eba65d20 boards: lx2160a: ... |
220 221 222 223 224 225 226 |
#else struct udevice *dev; ret = i2c_get_chip_for_busnum(0, I2C_VOL_MONITOR_ADDR, 1, &dev); if (!ret) ret = dm_i2c_write(dev, PMBUS_CMD_PAGE, &chan, 1); #endif |
23a12cb3d board: common: vi... |
227 228 229 230 231 |
if (ret) { printf("VID: failed to select VDD Page 0 "); return ret; } |
0eba65d20 boards: lx2160a: ... |
232 |
#ifndef CONFIG_DM_I2C |
23a12cb3d board: common: vi... |
233 234 235 |
/*read the output voltage using PMBus command READ_VOUT*/ ret = i2c_read(I2C_VOL_MONITOR_ADDR, PMBUS_CMD_READ_VOUT, 1, (void *)&vcode, 2); |
0eba65d20 boards: lx2160a: ... |
236 237 238 239 240 241 242 243 |
#else ret = dm_i2c_read(dev, PMBUS_CMD_READ_VOUT, (void *)&vcode, 2); if (ret) { printf("VID: failed to read the volatge "); return ret; } #endif |
23a12cb3d board: common: vi... |
244 245 246 247 248 249 250 251 252 253 254 255 |
if (ret) { printf("VID: failed to read the volatge "); return ret; } /* Scale down to the real mV as LTC resolution is 1/4096V,rounding up */ vcode = DIV_ROUND_UP(vcode * 1000, 4096); return vcode; } #endif |
3ad2737ee powerpc/t208xqds:... |
256 257 258 259 260 261 262 |
static int read_voltage(int i2caddress) { int voltage_read; #ifdef CONFIG_VOL_MONITOR_INA220 voltage_read = read_voltage_from_INA220(i2caddress); #elif defined CONFIG_VOL_MONITOR_IR36021_READ voltage_read = read_voltage_from_IR(i2caddress); |
23a12cb3d board: common: vi... |
263 264 |
#elif defined CONFIG_VOL_MONITOR_LTC3882_READ voltage_read = read_voltage_from_LTC(i2caddress); |
3ad2737ee powerpc/t208xqds:... |
265 266 267 268 269 |
#else return -1; #endif return voltage_read; } |
9458316a3 board: common: vi... |
270 |
#ifdef CONFIG_VOL_MONITOR_IR36021_SET |
3ad2737ee powerpc/t208xqds:... |
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
/* * We need to calculate how long before the voltage stops to drop * or increase. It returns with the loop count. Each loop takes * several readings (WAIT_FOR_ADC) */ static int wait_for_new_voltage(int vdd, int i2caddress) { int timeout, vdd_current; vdd_current = read_voltage(i2caddress); /* wait until voltage starts to reach the target. Voltage slew * rates by typical regulators will always lead to stable readings * within each fairly long ADC interval in comparison to the * intended voltage delta change until the target voltage is * reached. The fairly small voltage delta change to any target * VID voltage also means that this function will always complete * within few iterations. If the timeout was ever reached, it would * point to a serious failure in the regulator system. */ for (timeout = 0; abs(vdd - vdd_current) > (IR_VDD_STEP_UP + IR_VDD_STEP_DOWN) && timeout < MAX_LOOP_WAIT_NEW_VOL; timeout++) { vdd_current = read_voltage(i2caddress); } if (timeout >= MAX_LOOP_WAIT_NEW_VOL) { printf("VID: Voltage adjustment timeout "); return -1; } return timeout; } /* * this function keeps reading the voltage until it is stable or until the * timeout expires */ static int wait_for_voltage_stable(int i2caddress) { int timeout, vdd_current, vdd; vdd = read_voltage(i2caddress); udelay(NUM_READINGS * WAIT_FOR_ADC); /* wait until voltage is stable */ vdd_current = read_voltage(i2caddress); /* The maximum timeout is * MAX_LOOP_WAIT_VOL_STABLE * NUM_READINGS * WAIT_FOR_ADC */ for (timeout = MAX_LOOP_WAIT_VOL_STABLE; abs(vdd - vdd_current) > ADC_MIN_ACCURACY && timeout > 0; timeout--) { vdd = vdd_current; udelay(NUM_READINGS * WAIT_FOR_ADC); vdd_current = read_voltage(i2caddress); } if (timeout == 0) return -1; return vdd_current; } |
3ad2737ee powerpc/t208xqds:... |
330 331 332 333 334 335 336 337 338 339 340 |
/* Set the voltage to the IR chip */ static int set_voltage_to_IR(int i2caddress, int vdd) { int wait, vdd_last; int ret; u8 vid; /* Compensate for a board specific voltage drop between regulator and * SoC before converting into an IR VID value */ vdd += board_vdd_drop_compensation(); |
126fe70d7 armv8: ls1046aqds... |
341 |
#ifdef CONFIG_FSL_LSCH2 |
02b5d2ed8 armv8/ls1043aqds:... |
342 343 |
vid = DIV_ROUND_UP(vdd - 265, 5); #else |
3ad2737ee powerpc/t208xqds:... |
344 |
vid = DIV_ROUND_UP(vdd - 245, 5); |
02b5d2ed8 armv8/ls1043aqds:... |
345 |
#endif |
3ad2737ee powerpc/t208xqds:... |
346 |
|
0eba65d20 boards: lx2160a: ... |
347 |
#ifndef CONFIG_DM_I2C |
3ad2737ee powerpc/t208xqds:... |
348 349 |
ret = i2c_write(i2caddress, IR36021_LOOP1_MANUAL_ID_OFFSET, 1, (void *)&vid, sizeof(vid)); |
0eba65d20 boards: lx2160a: ... |
350 351 352 353 354 355 356 357 358 |
#else struct udevice *dev; ret = i2c_get_chip_for_busnum(0, i2caddress, 1, &dev); if (!ret) ret = dm_i2c_write(dev, IR36021_LOOP1_MANUAL_ID_OFFSET, (void *)&vid, sizeof(vid)); #endif |
3ad2737ee powerpc/t208xqds:... |
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 |
if (ret) { printf("VID: failed to write VID "); return -1; } wait = wait_for_new_voltage(vdd, i2caddress); if (wait < 0) return -1; debug("VID: Waited %d us ", wait * NUM_READINGS * WAIT_FOR_ADC); vdd_last = wait_for_voltage_stable(i2caddress); if (vdd_last < 0) return -1; debug("VID: Current voltage is %d mV ", vdd_last); return vdd_last; } |
23a12cb3d board: common: vi... |
377 378 379 380 381 382 383 384 |
#endif #ifdef CONFIG_VOL_MONITOR_LTC3882_SET /* this function sets the VDD and returns the value set */ static int set_voltage_to_LTC(int i2caddress, int vdd) { int ret, vdd_last, vdd_target = vdd; |
df182a42a board/freescale/v... |
385 |
int count = 100, temp = 0; |
724ba6f44 board/freescale/v... |
386 |
unsigned char value; |
23a12cb3d board: common: vi... |
387 388 389 390 391 392 393 394 395 396 397 |
/* Scale up to the LTC resolution is 1/4096V */ vdd = (vdd * 4096) / 1000; /* 5-byte buffer which needs to be sent following the * PMBus command PAGE_PLUS_WRITE. */ u8 buff[5] = {0x04, PWM_CHANNEL0, PMBUS_CMD_VOUT_COMMAND, vdd & 0xFF, (vdd & 0xFF00) >> 8}; /* Write the desired voltage code to the regulator */ |
0eba65d20 boards: lx2160a: ... |
398 |
#ifndef CONFIG_DM_I2C |
724ba6f44 board/freescale/v... |
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 |
/* Check write protect state */ ret = i2c_read(I2C_VOL_MONITOR_ADDR, PMBUS_CMD_WRITE_PROTECT, 1, (void *)&value, sizeof(value)); if (ret) goto exit; if (value != EN_WRITE_ALL_CMD) { value = EN_WRITE_ALL_CMD; ret = i2c_write(I2C_VOL_MONITOR_ADDR, PMBUS_CMD_WRITE_PROTECT, 1, (void *)&value, sizeof(value)); if (ret) goto exit; } |
23a12cb3d board: common: vi... |
414 |
ret = i2c_write(I2C_VOL_MONITOR_ADDR, |
724ba6f44 board/freescale/v... |
415 416 |
PMBUS_CMD_PAGE_PLUS_WRITE, 1, (void *)&buff, sizeof(buff)); |
0eba65d20 boards: lx2160a: ... |
417 418 419 420 |
#else struct udevice *dev; ret = i2c_get_chip_for_busnum(0, I2C_VOL_MONITOR_ADDR, 1, &dev); |
724ba6f44 board/freescale/v... |
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 |
if (!ret) { /* Check write protect state */ ret = dm_i2c_read(dev, PMBUS_CMD_WRITE_PROTECT, (void *)&value, sizeof(value)); if (ret) goto exit; if (value != EN_WRITE_ALL_CMD) { value = EN_WRITE_ALL_CMD; ret = dm_i2c_write(dev, PMBUS_CMD_WRITE_PROTECT, (void *)&value, sizeof(value)); if (ret) goto exit; } |
0eba65d20 boards: lx2160a: ... |
437 |
ret = dm_i2c_write(dev, PMBUS_CMD_PAGE_PLUS_WRITE, |
724ba6f44 board/freescale/v... |
438 439 |
(void *)&buff, sizeof(buff)); } |
0eba65d20 boards: lx2160a: ... |
440 |
#endif |
724ba6f44 board/freescale/v... |
441 |
exit: |
23a12cb3d board: common: vi... |
442 443 444 445 446 447 448 449 450 451 452 453 454 455 |
if (ret) { printf("VID: I2C failed to write to the volatge regulator "); return -1; } /* Wait for the volatge to get to the desired value */ do { vdd_last = read_voltage_from_LTC(i2caddress); if (vdd_last < 0) { printf("VID: Couldn't read sensor abort VID adjust "); return -1; } |
df182a42a board/freescale/v... |
456 457 458 |
count--; temp = vdd_last - vdd_target; } while ((abs(temp) > 2) && (count > 0)); |
23a12cb3d board: common: vi... |
459 460 461 |
return vdd_last; } |
3ad2737ee powerpc/t208xqds:... |
462 463 464 465 466 467 468 469 |
#endif static int set_voltage(int i2caddress, int vdd) { int vdd_last = -1; #ifdef CONFIG_VOL_MONITOR_IR36021_SET vdd_last = set_voltage_to_IR(i2caddress, vdd); |
23a12cb3d board: common: vi... |
470 471 |
#elif defined CONFIG_VOL_MONITOR_LTC3882_SET vdd_last = set_voltage_to_LTC(i2caddress, vdd); |
3ad2737ee powerpc/t208xqds:... |
472 473 474 475 476 |
#else #error Specific voltage monitor must be defined #endif return vdd_last; } |
29ca713cc armv8: fsl-lsch3:... |
477 |
#ifdef CONFIG_FSL_LSCH3 |
3ad2737ee powerpc/t208xqds:... |
478 479 480 |
int adjust_vdd(ulong vdd_override) { int re_enable = disable_interrupts(); |
29ca713cc armv8: fsl-lsch3:... |
481 482 |
struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR); u32 fusesr; |
9458316a3 board: common: vi... |
483 484 |
#if defined(CONFIG_VOL_MONITOR_IR36021_SET) || \ defined(CONFIG_VOL_MONITOR_IR36021_READ) |
29ca713cc armv8: fsl-lsch3:... |
485 |
u8 vid, buf; |
9458316a3 board: common: vi... |
486 487 488 |
#else u8 vid; #endif |
29ca713cc armv8: fsl-lsch3:... |
489 |
int vdd_target, vdd_current, vdd_last; |
fd40ade2e board: freescale:... |
490 |
int ret, i2caddress = 0; |
29ca713cc armv8: fsl-lsch3:... |
491 492 |
unsigned long vdd_string_override; char *vdd_string; |
da0505702 armv8: lx2162aqds... |
493 |
#if defined(CONFIG_ARCH_LX2160A) || defined(CONFIG_ARCH_LX2162A) |
db1e3df7c board/freescale/v... |
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 |
static const u16 vdd[32] = { 8250, 7875, 7750, 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ 8000, 8125, 8250, 0, /* reserved */ 8500, 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ }; #else |
c535ad4e9 board: common:vid... |
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 |
#ifdef CONFIG_ARCH_LS1088A static const uint16_t vdd[32] = { 10250, 9875, 9750, 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ 9000, 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ 10000, /* 1.0000V */ 10125, 10250, 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ }; #else |
29ca713cc armv8: fsl-lsch3:... |
566 567 568 569 570 571 572 573 574 575 576 577 |
static const uint16_t vdd[32] = { 10500, 0, /* reserved */ 9750, 0, /* reserved */ 9500, 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ |
4911948ec board/freescale,l... |
578 |
9000, /* reserved */ |
29ca713cc armv8: fsl-lsch3:... |
579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 |
0, /* reserved */ 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ 10000, /* 1.0000V */ 0, /* reserved */ 10250, 0, /* reserved */ 10500, 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ 0, /* reserved */ }; |
c535ad4e9 board: common:vid... |
600 |
#endif |
db1e3df7c board/freescale/v... |
601 |
#endif |
29ca713cc armv8: fsl-lsch3:... |
602 603 604 605 606 607 608 609 610 611 612 613 |
struct vdd_drive { u8 vid; unsigned voltage; }; ret = i2c_multiplexer_select_vid_channel(I2C_MUX_CH_VOL_MONITOR); if (ret) { debug("VID: I2C failed to switch channel "); ret = -1; goto exit; } |
9458316a3 board: common: vi... |
614 615 |
#if defined(CONFIG_VOL_MONITOR_IR36021_SET) || \ defined(CONFIG_VOL_MONITOR_IR36021_READ) |
29ca713cc armv8: fsl-lsch3:... |
616 617 618 619 620 621 622 623 624 625 626 627 628 |
ret = find_ir_chip_on_i2c(); if (ret < 0) { printf("VID: Could not find voltage regulator on I2C. "); ret = -1; goto exit; } else { i2caddress = ret; debug("VID: IR Chip found on I2C address 0x%02x ", i2caddress); } /* check IR chip work on Intel mode*/ |
0eba65d20 boards: lx2160a: ... |
629 |
#ifndef CONFIG_DM_I2C |
29ca713cc armv8: fsl-lsch3:... |
630 631 632 |
ret = i2c_read(i2caddress, IR36021_INTEL_MODE_OOFSET, 1, (void *)&buf, 1); |
0eba65d20 boards: lx2160a: ... |
633 634 635 636 637 638 639 640 |
#else struct udevice *dev; ret = i2c_get_chip_for_busnum(0, i2caddress, 1, &dev); if (!ret) ret = dm_i2c_read(dev, IR36021_INTEL_MODE_OOFSET, (void *)&buf, 1); #endif |
29ca713cc armv8: fsl-lsch3:... |
641 642 643 644 645 646 |
if (ret) { printf("VID: failed to read IR chip mode. "); ret = -1; goto exit; } |
0eba65d20 boards: lx2160a: ... |
647 |
|
29ca713cc armv8: fsl-lsch3:... |
648 649 650 651 652 653 |
if ((buf & IR36021_MODE_MASK) != IR36021_INTEL_MODE) { printf("VID: IR Chip is not used in Intel mode. "); ret = -1; goto exit; } |
9458316a3 board: common: vi... |
654 |
#endif |
29ca713cc armv8: fsl-lsch3:... |
655 656 657 658 659 660 661 662 663 664 665 666 |
/* get the voltage ID from fuse status register */ fusesr = in_le32(&gur->dcfg_fusesr); vid = (fusesr >> FSL_CHASSIS3_DCFG_FUSESR_ALTVID_SHIFT) & FSL_CHASSIS3_DCFG_FUSESR_ALTVID_MASK; if ((vid == 0) || (vid == FSL_CHASSIS3_DCFG_FUSESR_ALTVID_MASK)) { vid = (fusesr >> FSL_CHASSIS3_DCFG_FUSESR_VID_SHIFT) & FSL_CHASSIS3_DCFG_FUSESR_VID_MASK; } vdd_target = vdd[vid]; /* check override variable for overriding VDD */ |
00caae6d4 env: Rename geten... |
667 |
vdd_string = env_get(CONFIG_VID_FLS_ENV); |
29ca713cc armv8: fsl-lsch3:... |
668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 |
if (vdd_override == 0 && vdd_string && !strict_strtoul(vdd_string, 10, &vdd_string_override)) vdd_override = vdd_string_override; if (vdd_override >= VDD_MV_MIN && vdd_override <= VDD_MV_MAX) { vdd_target = vdd_override * 10; /* convert to 1/10 mV */ debug("VDD override is %lu ", vdd_override); } else if (vdd_override != 0) { printf("Invalid value. "); } /* divide and round up by 10 to get a value in mV */ vdd_target = DIV_ROUND_UP(vdd_target, 10); if (vdd_target == 0) { debug("VID: VID not used "); ret = 0; goto exit; } else if (vdd_target < VDD_MV_MIN || vdd_target > VDD_MV_MAX) { /* Check vdd_target is in valid range */ printf("VID: Target VID %d mV is not in range. ", vdd_target); ret = -1; goto exit; } else { debug("VID: vid = %d mV ", vdd_target); } /* * Read voltage monitor to check real voltage. */ vdd_last = read_voltage(i2caddress); if (vdd_last < 0) { printf("VID: Couldn't read sensor abort VID adjustment "); ret = -1; goto exit; } vdd_current = vdd_last; debug("VID: Core voltage is currently at %d mV ", vdd_last); |
23a12cb3d board: common: vi... |
713 714 715 716 717 |
#ifdef CONFIG_VOL_MONITOR_LTC3882_SET /* Set the target voltage */ vdd_last = vdd_current = set_voltage(i2caddress, vdd_target); #else |
29ca713cc armv8: fsl-lsch3:... |
718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 |
/* * Adjust voltage to at or one step above target. * As measurements are less precise than setting the values * we may run through dummy steps that cancel each other * when stepping up and then down. */ while (vdd_last > 0 && vdd_last < vdd_target) { vdd_current += IR_VDD_STEP_UP; vdd_last = set_voltage(i2caddress, vdd_current); } while (vdd_last > 0 && vdd_last > vdd_target + (IR_VDD_STEP_DOWN - 1)) { vdd_current -= IR_VDD_STEP_DOWN; vdd_last = set_voltage(i2caddress, vdd_current); } |
23a12cb3d board: common: vi... |
734 |
#endif |
3607570b1 board: common: vi... |
735 736 737 738 |
if (board_adjust_vdd(vdd_target) < 0) { ret = -1; goto exit; } |
29ca713cc armv8: fsl-lsch3:... |
739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 |
if (vdd_last > 0) printf("VID: Core voltage after adjustment is at %d mV ", vdd_last); else ret = -1; exit: if (re_enable) enable_interrupts(); i2c_multiplexer_select_vid_channel(I2C_MUX_CH_DEFAULT); return ret; } #else /* !CONFIG_FSL_LSCH3 */ int adjust_vdd(ulong vdd_override) { int re_enable = disable_interrupts(); #if defined(CONFIG_FSL_LSCH2) |
02b5d2ed8 armv8/ls1043aqds:... |
756 757 |
struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR); #else |
3ad2737ee powerpc/t208xqds:... |
758 759 |
ccsr_gur_t __iomem *gur = (void __iomem *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); |
02b5d2ed8 armv8/ls1043aqds:... |
760 |
#endif |
3ad2737ee powerpc/t208xqds:... |
761 |
u32 fusesr; |
cabe4d2f1 board/freescale/c... |
762 |
u8 vid, buf; |
3ad2737ee powerpc/t208xqds:... |
763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 |
int vdd_target, vdd_current, vdd_last; int ret, i2caddress; unsigned long vdd_string_override; char *vdd_string; static const uint16_t vdd[32] = { 0, /* unused */ 9875, /* 0.9875V */ 9750, 9625, 9500, 9375, 9250, 9125, 9000, 8875, 8750, 8625, 8500, 8375, 8250, 8125, 10000, /* 1.0000V */ 10125, 10250, 10375, 10500, 10625, 10750, 10875, 11000, 0, /* reserved */ }; struct vdd_drive { u8 vid; unsigned voltage; }; ret = i2c_multiplexer_select_vid_channel(I2C_MUX_CH_VOL_MONITOR); if (ret) { debug("VID: I2C failed to switch channel "); ret = -1; goto exit; } |
9458316a3 board: common: vi... |
807 808 |
#if defined(CONFIG_VOL_MONITOR_IR36021_SET) || \ defined(CONFIG_VOL_MONITOR_IR36021_READ) |
3ad2737ee powerpc/t208xqds:... |
809 810 811 812 813 814 815 816 817 818 819 |
ret = find_ir_chip_on_i2c(); if (ret < 0) { printf("VID: Could not find voltage regulator on I2C. "); ret = -1; goto exit; } else { i2caddress = ret; debug("VID: IR Chip found on I2C address 0x%02x ", i2caddress); } |
cabe4d2f1 board/freescale/c... |
820 |
/* check IR chip work on Intel mode*/ |
0eba65d20 boards: lx2160a: ... |
821 |
#ifndef CONFIG_DM_I2C |
cabe4d2f1 board/freescale/c... |
822 823 824 |
ret = i2c_read(i2caddress, IR36021_INTEL_MODE_OOFSET, 1, (void *)&buf, 1); |
0eba65d20 boards: lx2160a: ... |
825 826 827 828 829 830 831 832 |
#else struct udevice *dev; ret = i2c_get_chip_for_busnum(0, i2caddress, 1, &dev); if (!ret) ret = dm_i2c_read(dev, IR36021_INTEL_MODE_OOFSET, (void *)&buf, 1); #endif |
cabe4d2f1 board/freescale/c... |
833 834 835 836 837 838 839 840 841 842 843 844 |
if (ret) { printf("VID: failed to read IR chip mode. "); ret = -1; goto exit; } if ((buf & IR36021_MODE_MASK) != IR36021_INTEL_MODE) { printf("VID: IR Chip is not used in Intel mode. "); ret = -1; goto exit; } |
9458316a3 board: common: vi... |
845 |
#endif |
cabe4d2f1 board/freescale/c... |
846 |
|
3ad2737ee powerpc/t208xqds:... |
847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 |
/* get the voltage ID from fuse status register */ fusesr = in_be32(&gur->dcfg_fusesr); /* * VID is used according to the table below * --------------------------------------- * | DA_V | * |-------------------------------------| * | 5b00000 | 5b00001-5b11110 | 5b11111 | * ---------------+---------+-----------------+---------| * | D | 5b00000 | NO VID | VID = DA_V | NO VID | * | A |----------+---------+-----------------+---------| * | _ | 5b00001 |VID = | VID = |VID = | * | V | ~ | DA_V_ALT| DA_V_ALT | DA_A_VLT| * | _ | 5b11110 | | | | * | A |----------+---------+-----------------+---------| * | L | 5b11111 | No VID | VID = DA_V | NO VID | * | T | | | | | * ------------------------------------------------------ */ |
126fe70d7 armv8: ls1046aqds... |
866 |
#ifdef CONFIG_FSL_LSCH2 |
02b5d2ed8 armv8/ls1043aqds:... |
867 868 869 870 871 872 873 |
vid = (fusesr >> FSL_CHASSIS2_DCFG_FUSESR_ALTVID_SHIFT) & FSL_CHASSIS2_DCFG_FUSESR_ALTVID_MASK; if ((vid == 0) || (vid == FSL_CHASSIS2_DCFG_FUSESR_ALTVID_MASK)) { vid = (fusesr >> FSL_CHASSIS2_DCFG_FUSESR_VID_SHIFT) & FSL_CHASSIS2_DCFG_FUSESR_VID_MASK; } #else |
3ad2737ee powerpc/t208xqds:... |
874 875 876 877 878 879 |
vid = (fusesr >> FSL_CORENET_DCFG_FUSESR_ALTVID_SHIFT) & FSL_CORENET_DCFG_FUSESR_ALTVID_MASK; if ((vid == 0) || (vid == FSL_CORENET_DCFG_FUSESR_ALTVID_MASK)) { vid = (fusesr >> FSL_CORENET_DCFG_FUSESR_VID_SHIFT) & FSL_CORENET_DCFG_FUSESR_VID_MASK; } |
02b5d2ed8 armv8/ls1043aqds:... |
880 |
#endif |
3ad2737ee powerpc/t208xqds:... |
881 882 883 |
vdd_target = vdd[vid]; /* check override variable for overriding VDD */ |
00caae6d4 env: Rename geten... |
884 |
vdd_string = env_get(CONFIG_VID_FLS_ENV); |
3ad2737ee powerpc/t208xqds:... |
885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 |
if (vdd_override == 0 && vdd_string && !strict_strtoul(vdd_string, 10, &vdd_string_override)) vdd_override = vdd_string_override; if (vdd_override >= VDD_MV_MIN && vdd_override <= VDD_MV_MAX) { vdd_target = vdd_override * 10; /* convert to 1/10 mV */ debug("VDD override is %lu ", vdd_override); } else if (vdd_override != 0) { printf("Invalid value. "); } if (vdd_target == 0) { debug("VID: VID not used "); ret = 0; goto exit; } else { /* divide and round up by 10 to get a value in mV */ vdd_target = DIV_ROUND_UP(vdd_target, 10); debug("VID: vid = %d mV ", vdd_target); } /* * Read voltage monitor to check real voltage. */ vdd_last = read_voltage(i2caddress); if (vdd_last < 0) { printf("VID: Couldn't read sensor abort VID adjustment "); ret = -1; goto exit; } vdd_current = vdd_last; debug("VID: Core voltage is currently at %d mV ", vdd_last); /* * Adjust voltage to at or one step above target. * As measurements are less precise than setting the values * we may run through dummy steps that cancel each other * when stepping up and then down. */ while (vdd_last > 0 && vdd_last < vdd_target) { vdd_current += IR_VDD_STEP_UP; vdd_last = set_voltage(i2caddress, vdd_current); } while (vdd_last > 0 && vdd_last > vdd_target + (IR_VDD_STEP_DOWN - 1)) { vdd_current -= IR_VDD_STEP_DOWN; vdd_last = set_voltage(i2caddress, vdd_current); } if (vdd_last > 0) printf("VID: Core voltage after adjustment is at %d mV ", vdd_last); else ret = -1; exit: if (re_enable) enable_interrupts(); |
1be8d10be freescale: vid: R... |
947 948 |
i2c_multiplexer_select_vid_channel(I2C_MUX_CH_DEFAULT); |
3ad2737ee powerpc/t208xqds:... |
949 950 |
return ret; } |
29ca713cc armv8: fsl-lsch3:... |
951 |
#endif |
3ad2737ee powerpc/t208xqds:... |
952 953 954 |
static int print_vdd(void) { |
62217a8f0 board: freescale:... |
955 |
int vdd_last, ret, i2caddress = 0; |
3ad2737ee powerpc/t208xqds:... |
956 957 958 959 960 961 962 |
ret = i2c_multiplexer_select_vid_channel(I2C_MUX_CH_VOL_MONITOR); if (ret) { debug("VID : I2c failed to switch channel "); return -1; } |
9458316a3 board: common: vi... |
963 964 |
#if defined(CONFIG_VOL_MONITOR_IR36021_SET) || \ defined(CONFIG_VOL_MONITOR_IR36021_READ) |
3ad2737ee powerpc/t208xqds:... |
965 966 967 968 |
ret = find_ir_chip_on_i2c(); if (ret < 0) { printf("VID: Could not find voltage regulator on I2C. "); |
1be8d10be freescale: vid: R... |
969 |
goto exit; |
3ad2737ee powerpc/t208xqds:... |
970 971 972 973 974 |
} else { i2caddress = ret; debug("VID: IR Chip found on I2C address 0x%02x ", i2caddress); } |
9458316a3 board: common: vi... |
975 |
#endif |
3ad2737ee powerpc/t208xqds:... |
976 977 978 979 980 981 982 983 |
/* * Read voltage monitor to check real voltage. */ vdd_last = read_voltage(i2caddress); if (vdd_last < 0) { printf("VID: Couldn't read sensor abort VID adjustment "); |
1be8d10be freescale: vid: R... |
984 |
goto exit; |
3ad2737ee powerpc/t208xqds:... |
985 986 987 |
} printf("VID: Core voltage is at %d mV ", vdd_last); |
1be8d10be freescale: vid: R... |
988 989 990 991 |
exit: i2c_multiplexer_select_vid_channel(I2C_MUX_CH_DEFAULT); return ret < 0 ? -1 : 0; |
3ad2737ee powerpc/t208xqds:... |
992 |
|
3ad2737ee powerpc/t208xqds:... |
993 994 995 996 997 998 999 |
} static int do_vdd_override(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { ulong override; |
c6e6ba719 board: freescale:... |
1000 |
int ret = 0; |
3ad2737ee powerpc/t208xqds:... |
1001 1002 |
if (argc < 2) return CMD_RET_USAGE; |
8da1ef604 board: freescale:... |
1003 |
if (!strict_strtoul(argv[1], 10, &override)) { |
c6e6ba719 board: freescale:... |
1004 1005 1006 |
ret = adjust_vdd(override); /* the value is checked by callee */ if (ret < 0) return CMD_RET_FAILURE; |
8da1ef604 board: freescale:... |
1007 |
} else |
3ad2737ee powerpc/t208xqds:... |
1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 |
return CMD_RET_USAGE; return 0; } static int do_vdd_read(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { if (argc < 1) return CMD_RET_USAGE; print_vdd(); return 0; } U_BOOT_CMD( vdd_override, 2, 0, do_vdd_override, "override VDD", " - override with the voltage specified in mV, eg. 1050" ); U_BOOT_CMD( vdd_read, 1, 0, do_vdd_read, "read VDD", " - Read the voltage specified in mV" ) |