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

7 Likes

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

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:

1 Like

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