longan/brandy/brandy-2.0/u-boot-2018/board/sunxi/power_manage.c
.. .. @@ -11,6 +11,8 @@ 11 11 #include <spare_head.h> 12 12 #include <sunxi_display2.h> 13 13 #include <console.h> 14 +#include <sunxi_power/pmu_axp81X.h>15 +14 16 /* 15 17 * Global data (for the gd->bd) 16 18 */ .. .. @@ -411,16 +413,55 @@ 411 413 return pmu_set_voltage(name, 0, onoff); 412 414 } 413 415 416 +int pmu_axp707_get_poweron_source(void)417 +{418 + int reg_value = 0;419 + reg_value = pmu_get_reg_value(AXP81X_OTG_STATUS);420 + printf("kickpi axp707 reason %x \n", reg_value);421 + pmu_set_reg_value(AXP81X_OTG_STATUS, 0xff);422 + printf("kickpi after clean reason %x \n", pmu_get_reg_value(AXP81X_OTG_STATUS));423 +424 + if (reg_value & (1 << 0)) {425 + return AXP_BOOT_SOURCE_BUTTON;426 + } else if (reg_value & (1 << 1)) {427 + return AXP_BOOT_SOURCE_CHARGER;428 + } else if (reg_value & (1 << 2)) {429 + return AXP_BOOT_SOURCE_BATTERY;430 + }431 + return -1;432 +}433 +434 +int runtime_tick(void);435 +int pmu_axp707_get_battery_probe(void)436 +{437 + int reg_value = 0;438 + int old_time = runtime_tick();439 + while ((runtime_tick() - old_time) < 2000) {440 + reg_value = pmu_get_reg_value(AXP81X_MODE_CHGSTATUS);441 + }442 +443 + /*bit4 determines whether bit5 is valid*/444 + /*bit5 determines whether bat is exist*/445 + if ((reg_value & (1<<4)) && (reg_value & (1<<5)))446 + return 1;447 +448 + return 0;449 +}414 450 415 451 int sunxi_update_axp_info(void) 416 452 { 417 453 int val = -1; 418 454 char bootreason[16] = {0}; 419 455 int ret = 0, bat_exist = 0; 456 + int dcin_exist = pmu_get_reg_value(AXP81X_STATUS);420 457 421 458 ret = script_parser_fetch(FDT_PATH_POWER_SPLY, "battery_exist", &bat_exist, 1); 422 - if (ret < 0)423 - bat_exist = 1;459 + if (ret < 0) {460 + bat_exist = pmu_axp707_get_battery_probe();461 + printf("kickpi detect battery_exist = %d, AXP81X_STATUS = %x\n", bat_exist, dcin_exist);462 + } else {463 + printf("force set battery_exist = %d\n", bat_exist);464 + }424 465 425 466 #ifdef CONFIG_SUNXI_BMU 426 467 #ifdef CONFIG_AXP_LATE_INFO .. .. @@ -429,10 +470,21 @@ 429 470 val = gd->pmu_saved_status; 430 471 #endif 431 472 #endif 473 + printf("kickpi pmu_get_sys_mode = %d\n", pmu_get_sys_mode());432 474 if ((val == -1) && (pmu_get_sys_mode() == SUNXI_CHARGING_FLAG)) { 433 475 val = AXP_BOOT_SOURCE_CHARGER; 434 476 pmu_set_sys_mode(0); 435 477 } 478 +479 + if (bat_exist == 1) {480 + /* When the battery exists, it can only be turned on by power key */481 + if (pmu_axp707_get_poweron_source() != AXP_BOOT_SOURCE_BUTTON) {482 + val = AXP_BOOT_SOURCE_CHARGER;483 + pmu_set_sys_mode(0);484 + printf("kickpi[bat_exist] not power key up when boot on \n");485 + }486 + }487 +436 488 switch (val) { 437 489 case AXP_BOOT_SOURCE_BUTTON: 438 490 strncpy(bootreason, "button", sizeof("button")); .. .. @@ -456,6 +508,8 @@ 456 508 break; 457 509 } 458 510 env_set("bootreason", bootreason); 511 +512 + printf("kickpi bootreason = %s / val = %d \n", bootreason, val);459 513 return 0; 460 514 } 461 515 longan/device/config/chips/a133/configs/c3/kickpi-k5c.dts
.. .. @@ -401,21 +401,21 @@ 401 401 pmu_ac_vol = <4600>; 402 402 pmu_ac_cur = <3000>; 403 403 404 - wakeup_ac_in;405 - wakeup_ac_out;404 + // wakeup_ac_in;405 + // wakeup_ac_out;406 406 }; 407 407 408 408 usb_power_supply: usb_power_supply { 409 409 compatible = "x-powers,axp803-usb-power-supply"; 410 410 status = "okay"; 411 411 412 - pmu_usbpc_vol = <5000>;413 - pmu_usbpc_cur = <5000>;414 - pmu_usbad_vol = <5000>;415 - pmu_usbad_cur = <5000>;412 + pmu_usbpc_vol = <4600>;413 + pmu_usbpc_cur = <2500>;414 + pmu_usbad_vol = <4600>;415 + pmu_usbad_cur = <2500>;416 416 417 - wakeup_usb_in;418 - wakeup_usb_out;417 + // wakeup_usb_in;418 + // wakeup_usb_out;419 419 }; 420 420 421 421 battery_power_supply: battery-power-supply { .. .. @@ -423,21 +423,21 @@ 423 423 status = "okay"; 424 424 425 425 pmu_chg_ic_temp = <0>; 426 - pmu_battery_rdc= <93>;427 - pmu_battery_cap = <5000>;426 + pmu_battery_rdc= <50>;427 + pmu_battery_cap = <8000>;428 428 pmu_runtime_chgcur = <1000>; 429 429 pmu_suspend_chgcur = <2000>; 430 430 pmu_shutdown_chgcur = <2000>; 431 - pmu_init_chgvol = <4200>;431 + pmu_init_chgvol = <4280>;432 432 pmu_battery_warning_level1 = <15>; 433 433 pmu_battery_warning_level2 = <0>; 434 434 pmu_chgled_func = <1>; 435 435 pmu_chgled_type = <0>; 436 436 ocv_coulumb_100 = <1>; 437 437 pmu_bat_para1 = <0>; 438 - pmu_bat_para2 = <0>;439 - pmu_bat_para3 = <0>;440 - pmu_bat_para4 = <0>;438 + pmu_bat_para2 = <3>;439 + pmu_bat_para3 = <4>;440 + pmu_bat_para4 = <5>;441 441 pmu_bat_para5 = <6>; 442 442 pmu_bat_para6 = <8>; 443 443 pmu_bat_para7 = <9>; .. .. @@ -455,16 +455,16 @@ 455 455 pmu_bat_para19 = <65>; 456 456 pmu_bat_para20 = <70>; 457 457 pmu_bat_para21 = <75>; 458 - pmu_bat_para22 = <80>;459 - pmu_bat_para23 = <83>;460 - pmu_bat_para24 = <88>;461 - pmu_bat_para25 = <92>;462 - pmu_bat_para26 = <97>;463 - pmu_bat_para27 = <100>;464 - pmu_bat_para28 = <100>;465 - pmu_bat_para29 = <100>;466 - pmu_bat_para30 = <100>;467 - pmu_bat_para31 = <100>;458 + pmu_bat_para22 = <76>;459 + pmu_bat_para23 = <77>;460 + pmu_bat_para24 = <78>;461 + pmu_bat_para25 = <79>;462 + pmu_bat_para26 = <80>;463 + pmu_bat_para27 = <83>;464 + pmu_bat_para28 = <85>;465 + pmu_bat_para29 = <88>;466 + pmu_bat_para30 = <90>;467 + pmu_bat_para31 = <95>;468 468 pmu_bat_para32 = <100>; 469 469 470 470 pmu_bat_temp_enable = <0>; longan/device/config/chips/a133/configs/c3/sys_config.fex
.. .. @@ -57,7 +57,6 @@ 57 57 dcdc5_mode = 0 58 58 dcdc2_mode = 0 59 59 dcdc3_mode = 0 60 -battery_exist = 061 60 62 61 [card_boot] 63 62 logical_start = 40960 longan/kernel/linux-4.9/drivers/power/supply/axp803_battery.c
.. .. @@ -671,8 +671,10 @@ 671 671 } 672 672 673 673 regmap_read(map, AXP803_BATCAP0, &val); 674 - if ((axp_config->pmu_battery_cap) && (!(val & 0x80))) {675 - cur_coulomb_counter = axp_config->pmu_battery_cap674 + //if ((axp_config->pmu_battery_cap) && (!(val & 0x80))) {675 + // always update from dts676 + if ((axp_config->pmu_battery_cap)) {677 + cur_coulomb_counter = axp_config->pmu_battery_cap676 678 * 1000 / 1456; 677 679 regmap_write(map, AXP803_BATCAP0, ((cur_coulomb_counter >> 8) | 0x80)); 678 680 regmap_write(map, AXP803_BATCAP1, cur_coulomb_counter & 0x00FF);