# Axp228: properly report energy/power readings

**URL:** <https://forum.clockworkpi.com/t/axp228-properly-report-energy-power-readings/9318>\
**Category:** DevTerm\
**Created:** [December 10, 2022, 7:11am UTC](https://forum.clockworkpi.com/t/axp228-properly-report-energy-power-readings/9318 "2022-12-10T07:11:10Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![yatli](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/yatli/32/6253_2.png) [@yatli](https://forum.clockworkpi.com/u/yatli)\
**Post date:** [December 10, 2022, 7:11am UTC](https://forum.clockworkpi.com/t/axp228-properly-report-energy-power-readings/9318/1 "2022-12-10T07:11:10Z")

</div>

> <https://github.com/yatli/arch-linux-arm-clockworkpi-a06/commit/f171b5e543a216fd148a28051718efa1774a01bc>

- The AC adapter now shows up in power management apps
- Instead of reporting 8Wh total energy, it now reads customizable battery full energy from devicetree.
  - … which allows better remaining time estimation

- Device current energy logic is also updated.
- Reports current power rate, no more upowerd warnings about “battery discharging at -0.000000W”
- Exposes sysfs node `/sys/class/power\_supply/axp20x-battery/calibrate
  - Write 1 to the file to initiate battery full capacity calibration
  - Read from the file:
    - 0: calibration disabled
    - 32: calibration enabled, but not active
    - 48: calibration in progress

@guu @m4xm4n

---

<div class="post-metadata">

**Author:** ![pkr](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/pkr/32/6084_2.png) [@pkr](https://forum.clockworkpi.com/u/pkr)\
**Post date:** [December 11, 2022, 3:38am UTC](https://forum.clockworkpi.com/t/axp228-properly-report-energy-power-readings/9318/2 "2022-12-11T03:38:32Z")

</div>

Fabulous! Any chance you can implement some of the other features too? (charge termination voltage/current, led indicator behavior, etc) 😁

 ![IMG_20221210_193557472](https://canada1.discourse-cdn.com/flex029/uploads/clockworkpi/original/2X/a/a05a4d5acf4968d3e27ae50b2c5f5cefe21d6d81.jpeg)

---

<div class="post-metadata">

**Author:** ![yatli](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/yatli/32/6253_2.png) [@yatli](https://forum.clockworkpi.com/u/yatli)\
**Post date:** [December 11, 2022, 5:57am UTC](https://forum.clockworkpi.com/t/axp228-properly-report-energy-power-readings/9318/3 "2022-12-11T05:57:53Z")

</div>

I believe these are already there:

```auto
yatli@devterm /sys/class/power_supply/axp20x-battery % ls
calibrate constant_charge_current_max energy_full health power status uevent voltage_now
capacity current_now energy_full_design hwmon2 power_now subsystem voltage_max_design wakeup6
constant_charge_current device energy_now online present type voltage_min_design

```

R/W entries are:

- calibrate
- constant\_charge\_current\_max
- constant\_charge\_current
- voltage\_max\_design
- voltage\_min\_design
- status (0=disables charging)

All power/current/voltage metrics are in micro-lets. 🙂

Edit: maybe one missing piece, the end charge current. I’ll see if the linux power supply model has something equivalent.  
Edit: nope, need a custom sysfs node for that.

Where do you get the i2c commands? 😮

---

<div class="post-metadata">

**Author:** ![pkr](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/pkr/32/6084_2.png) [@pkr](https://forum.clockworkpi.com/u/pkr)\
**Post date:** [December 11, 2022, 7:34pm UTC](https://forum.clockworkpi.com/t/axp228-properly-report-energy-power-readings/9318/4 "2022-12-11T19:34:03Z")

</div>

> [@yatli](#):
>
> R/W entries are:
> 
> - calibrate
> - constant\_charge\_current\_max
> - constant\_charge\_current
> - voltage\_max\_design
> - voltage\_min\_design
> - status (0=disables charging)

Whoa! I didn’t those could be set… time to experiment!

- voltage\_min\_design: 2.6v to 3.3v in 0.1v increments
- voltage\_max\_design: either 4.1v or 4.2v (?!?)
- constant\_charge\_current: 300mA to 2100mA in 150mA increments
- constant\_charge\_current\_max: 300mA to 2100mA in 150mA increments
- status: my stock manjaro kernel only seems to accept Charging, 1, 2, and 3…  
– 2 and 3 stops charging.

> [@yatli](#):
>
> Where do you get the i2c commands? 😮

I used the AXP228 datasheet, a calculator, and pen and paper. It was my first time with both i2cset and bitmasks, and it was pretty fun 😆

Also, don’t forget the blinky charge led!  
 ![gif-20221211-123509](https://canada1.discourse-cdn.com/flex029/uploads/clockworkpi/original/2X/3/3bffc58ef319684cc5cd0b6c47337f9b38886d92.gif)

---

<div class="post-metadata">

**Author:** ![hsavior](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/hsavior/32/7560_2.png) [@hsavior](https://forum.clockworkpi.com/u/hsavior)\
**Post date:** [November 22, 2023, 10:48am UTC](https://forum.clockworkpi.com/t/axp228-properly-report-energy-power-readings/9318/5 "2023-11-22T10:48:26Z")

</div>

Would this work for the CM4 installed on the uConsole? I am having issues with my uConsole shutting down around 80% already changed batteries, same issue. I am using a pair of Samsung 35E. I should have around 22Wh it is showing “energy-full: 8 Wh”

EDIT: I see how stupid was my questions seeing the code of the patch it is strictly for the A06 (rk808). I wish I had the knowledge.

---

<div class="post-metadata">

**Author:** ![yatli](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/yatli/32/6253_2.png) [@yatli](https://forum.clockworkpi.com/u/yatli)\
**Post date:** [November 22, 2023, 3:24pm UTC](https://forum.clockworkpi.com/t/axp228-properly-report-energy-power-readings/9318/6 "2023-11-22T15:24:31Z")

</div>

Your question is actually very valid, and this patch is for axp228, the chip on the cpi mainboard, not rk808 on the a06 core.

Hopefully someone with enough time will port this over to CM4.

---

<div class="post-metadata">

**Author:** ![aloksandal](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/aloksandal/32/8035_2.png) [@aloksandal](https://forum.clockworkpi.com/u/aloksandal)\
**Post date:** [May 16, 2024, 5:36pm UTC](https://forum.clockworkpi.com/t/axp228-properly-report-energy-power-readings/9318/7 "2024-05-16T17:36:47Z")

</div>

@hsavior, did you find any soution? I’m having the same issue in CM4/uConsole.

---

<div class="post-metadata">

**Author:** ![hsavior](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/hsavior/32/7560_2.png) [@hsavior](https://forum.clockworkpi.com/u/hsavior)\
**Post date:** [July 8, 2024, 5:15am UTC](https://forum.clockworkpi.com/t/axp228-properly-report-energy-power-readings/9318/8 "2024-07-08T05:15:17Z")

</div>

Yep, charging it and using it a few times balanced it. I sold mine a few months ago.

---

<div class="post-metadata">

**Author:** ![yatli](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/yatli/32/6253_2.png) [@yatli](https://forum.clockworkpi.com/u/yatli)\
**Post date:** [July 9, 2024, 7:25am UTC](https://forum.clockworkpi.com/t/axp228-properly-report-energy-power-readings/9318/9 "2024-07-09T07:25:44Z")

</div>

> Hopefully someone with enough time will port this over to CM4.

That person turns out to be me again. This patch is included in latest kernels for Debian and Arch images.

---

<div class="post-metadata">

**Author:** ![joshg](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/joshg/32/10532_2.png) [@joshg](https://forum.clockworkpi.com/u/joshg)\
**Post date:** [September 15, 2025, 8:01pm UTC](https://forum.clockworkpi.com/t/axp228-properly-report-energy-power-readings/9318/10 "2025-09-15T20:01:27Z")

</div>

Thanks for sharing this here! Literally trying to sort out what the CALIBRATE numbers meant on my uConsole and your post was the first search hit despite not searching for uConsole specifically. 😃

Does the calibration mode end on its own after enough charges / discharges, or do you have to write a 0 to end it yourself?

---

<div class="post-metadata">

**Author:** ![dvarkin-ru](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/dvarkin-ru/32/7303_2.png) [@dvarkin-ru](https://forum.clockworkpi.com/u/dvarkin-ru)\
**Post date:** [December 30, 2025, 8:43am UTC](https://forum.clockworkpi.com/t/axp228-properly-report-energy-power-readings/9318/11 "2025-12-30T08:43:07Z")

</div>

Why not calculate percentage by (voltage-min\_voltage)(voltage\_max-voltage\_min)\*100%?
