huangcm
2025-03-28 46a072a7ae48464c18a6f5c7d215141157664582
feat(battery): fix battery boot on & cap

1. when battery exists only powerkey boot
2. force update battery cap from dts
4 files modified
113 ■■■■ changed files
longan/brandy/brandy-2.0/u-boot-2018/board/sunxi/power_manage.c 58 ●●●●● patch | view | raw | blame | history
longan/device/config/chips/a133/configs/c3/kickpi-k5c.dts 48 ●●●● patch | view | raw | blame | history
longan/device/config/chips/a133/configs/c3/sys_config.fex 1 ●●●● patch | view | raw | blame | history
longan/kernel/linux-4.9/drivers/power/supply/axp803_battery.c 6 ●●●●● patch | view | raw | blame | history
longan/brandy/brandy-2.0/u-boot-2018/board/sunxi/power_manage.c
....@@ -11,6 +11,8 @@
1111 #include <spare_head.h>
1212 #include <sunxi_display2.h>
1313 #include <console.h>
14
+#include <sunxi_power/pmu_axp81X.h>
15
+
1416 /*
1517 * Global data (for the gd->bd)
1618 */
....@@ -411,16 +413,55 @@
411413 return pmu_set_voltage(name, 0, onoff);
412414 }
413415
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
+}
414450
415451 int sunxi_update_axp_info(void)
416452 {
417453 int val = -1;
418454 char bootreason[16] = {0};
419455 int ret = 0, bat_exist = 0;
456
+ int dcin_exist = pmu_get_reg_value(AXP81X_STATUS);
420457
421458 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
+ }
424465
425466 #ifdef CONFIG_SUNXI_BMU
426467 #ifdef CONFIG_AXP_LATE_INFO
....@@ -429,10 +470,21 @@
429470 val = gd->pmu_saved_status;
430471 #endif
431472 #endif
473
+ printf("kickpi pmu_get_sys_mode = %d\n", pmu_get_sys_mode());
432474 if ((val == -1) && (pmu_get_sys_mode() == SUNXI_CHARGING_FLAG)) {
433475 val = AXP_BOOT_SOURCE_CHARGER;
434476 pmu_set_sys_mode(0);
435477 }
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
+
436488 switch (val) {
437489 case AXP_BOOT_SOURCE_BUTTON:
438490 strncpy(bootreason, "button", sizeof("button"));
....@@ -456,6 +508,8 @@
456508 break;
457509 }
458510 env_set("bootreason", bootreason);
511
+
512
+ printf("kickpi bootreason = %s / val = %d \n", bootreason, val);
459513 return 0;
460514 }
461515
longan/device/config/chips/a133/configs/c3/kickpi-k5c.dts
....@@ -401,21 +401,21 @@
401401 pmu_ac_vol = <4600>;
402402 pmu_ac_cur = <3000>;
403403
404
- wakeup_ac_in;
405
- wakeup_ac_out;
404
+ // wakeup_ac_in;
405
+ // wakeup_ac_out;
406406 };
407407
408408 usb_power_supply: usb_power_supply {
409409 compatible = "x-powers,axp803-usb-power-supply";
410410 status = "okay";
411411
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>;
416416
417
- wakeup_usb_in;
418
- wakeup_usb_out;
417
+ // wakeup_usb_in;
418
+ // wakeup_usb_out;
419419 };
420420
421421 battery_power_supply: battery-power-supply {
....@@ -423,21 +423,21 @@
423423 status = "okay";
424424
425425 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>;
428428 pmu_runtime_chgcur = <1000>;
429429 pmu_suspend_chgcur = <2000>;
430430 pmu_shutdown_chgcur = <2000>;
431
- pmu_init_chgvol = <4200>;
431
+ pmu_init_chgvol = <4280>;
432432 pmu_battery_warning_level1 = <15>;
433433 pmu_battery_warning_level2 = <0>;
434434 pmu_chgled_func = <1>;
435435 pmu_chgled_type = <0>;
436436 ocv_coulumb_100 = <1>;
437437 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>;
441441 pmu_bat_para5 = <6>;
442442 pmu_bat_para6 = <8>;
443443 pmu_bat_para7 = <9>;
....@@ -455,16 +455,16 @@
455455 pmu_bat_para19 = <65>;
456456 pmu_bat_para20 = <70>;
457457 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>;
468468 pmu_bat_para32 = <100>;
469469
470470 pmu_bat_temp_enable = <0>;
longan/device/config/chips/a133/configs/c3/sys_config.fex
....@@ -57,7 +57,6 @@
5757 dcdc5_mode = 0
5858 dcdc2_mode = 0
5959 dcdc3_mode = 0
60
-battery_exist = 0
6160
6261 [card_boot]
6362 logical_start = 40960
longan/kernel/linux-4.9/drivers/power/supply/axp803_battery.c
....@@ -671,8 +671,10 @@
671671 }
672672
673673 regmap_read(map, AXP803_BATCAP0, &val);
674
- if ((axp_config->pmu_battery_cap) && (!(val & 0x80))) {
675
- cur_coulomb_counter = axp_config->pmu_battery_cap
674
+ //if ((axp_config->pmu_battery_cap) && (!(val & 0x80))) {
675
+ // always update from dts
676
+ if ((axp_config->pmu_battery_cap)) {
677
+ cur_coulomb_counter = axp_config->pmu_battery_cap
676678 * 1000 / 1456;
677679 regmap_write(map, AXP803_BATCAP0, ((cur_coulomb_counter >> 8) | 0x80));
678680 regmap_write(map, AXP803_BATCAP1, cur_coulomb_counter & 0x00FF);