Axp228: properly report energy/power readings

  • 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

12 Likes

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

2 Likes

I believe these are already there:

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. :slight_smile:

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? :open_mouth:

3 Likes

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.

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 :laughing:

Also, don’t forget the blinky charge led!
gif-20221211-123509

2 Likes

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.

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.

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

2 Likes

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

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.

2 Likes