Discussion:
[linux-sunxi] Charger/battery driver for axp20x being worked on?
Michael Haas
2016-03-31 06:18:02 UTC
Permalink
Hello all,

I'd like to monitor the battery and charging status connected to my axp209.
Is anyone working on that? Currently, there is only USB power supply
support via
drivers/power/axp20x_usb_power.c.

Adding support for the charging/battery/ACIN bits should be rather
straightforward.
There is a rather nasty bash script which polls the axp20x via i2cget.
I'd rather have a proper solution.

Is anyone working on that? If not, I'll get started.

Or is there an existing driver implemented by Allwinner which can be
re-used?

CC'ing Hans as he implemented axp20x_usb_power.c.

Best

Michael
--
You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Chen-Yu Tsai
2016-03-31 06:24:51 UTC
Permalink
Hi,
Post by Michael Haas
Hello all,
I'd like to monitor the battery and charging status connected to my axp209.
Is anyone working on that? Currently, there is only USB power supply
support via
drivers/power/axp20x_usb_power.c.
Adding support for the charging/battery/ACIN bits should be rather
straightforward.
There is a rather nasty bash script which polls the axp20x via i2cget.
I'd rather have a proper solution.
Is anyone working on that? If not, I'll get started.
There was an attempt some time ago:
http://lists.infradead.org/pipermail/linux-arm-kernel/2014-October/295547.html
Post by Michael Haas
Or is there an existing driver implemented by Allwinner which can be
re-used?
It probably won't fit in with the mfd driver in mainline.
Post by Michael Haas
CC'ing Hans as he implemented axp20x_usb_power.c.
IIRC, Hans previously said that the acin and vbus supplies should be handled
by separate power supply drivers. ACIN is easy to do. Just port the VBUS one.

The charger would likely be another separate driver, either combined or
separate from the fuel gauge (charge level) driver.

You could also take a look at the AXP288 power supply driver, though they
are doing it in a monolithic driver handling all the supplies and charging.

Regards
ChenYu
--
You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Michael Haas
2016-03-31 06:41:57 UTC
Permalink
Hello,

(adding Bruno to CC)
Post by Chen-Yu Tsai
Post by Michael Haas
Is anyone working on that? If not, I'll get started.
http://lists.infradead.org/pipermail/linux-arm-kernel/2014-October/295547.html
Bruno had submitted a new version a year later:

http://comments.gmane.org/gmane.comp.hardware.netbook.arm.sunxi/17980

There was also a different patchset by Siarhei Siamashka:

https://groups.google.com/forum/#!topic/linux-sunxi/u4Rwo630MnY

Bruno,

can you comment on the state of the patchset? I'd be happy to pick up
where you left off.
Post by Chen-Yu Tsai
Post by Michael Haas
CC'ing Hans as he implemented axp20x_usb_power.c.
IIRC, Hans previously said that the acin and vbus supplies should be handled
by separate power supply drivers. ACIN is easy to do. Just port the VBUS one.
Yeah, that is very straightforward.
Post by Chen-Yu Tsai
The charger would likely be another separate driver, either combined or
separate from the fuel gauge (charge level) driver.
I agree.

Best

Michael
--
You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Bruno Prémont
2016-03-31 07:06:05 UTC
Permalink
Hello Michael,
Post by Michael Haas
Hello,
(adding Bruno to CC)
Thanks for CCing, as I currently catch up with mailing list rather
sporadically!
Post by Michael Haas
Post by Chen-Yu Tsai
Post by Michael Haas
Is anyone working on that? If not, I'll get started.
http://lists.infradead.org/pipermail/linux-arm-kernel/2014-October/295547.html
http://comments.gmane.org/gmane.comp.hardware.netbook.arm.sunxi/17980
https://groups.google.com/forum/#!topic/linux-sunxi/u4Rwo630MnY
Bruno,
can you comment on the state of the patchset? I'd be happy to pick up
where you left off.
Currently I don't have enough spare time to (actively) work on the patch
set, so feel free to pick up!

With recent additions of support for other AXP variants some porting
work has to be done (not sure I published my latest porting attempts
with some rework to adapt to Hans's axp20x_usb_power.c) and I won't have
time/access to right device to check before mid April.
Post by Michael Haas
Post by Chen-Yu Tsai
Post by Michael Haas
CC'ing Hans as he implemented axp20x_usb_power.c.
IIRC, Hans previously said that the acin and vbus supplies should be handled
by separate power supply drivers. ACIN is easy to do. Just port the VBUS one.
Yeah, that is very straightforward.
Just remember that some devices short-cut ACIN and VBUS, thus the ACIN
driver should only load when the AXP status bit indicates they are
distinct (maybe also having device-tree flag to indicate connector
presence when not short-cutted).
Post by Michael Haas
Post by Chen-Yu Tsai
The charger would likely be another separate driver, either combined or
separate from the fuel gauge (charge level) driver.
One thing I explicitly left aside was "estimating battery capacity", the
original 3.4.x code included some heuristics for that with saving
intermediate values to AXP's registers (data registers kept alive as
long as power was present).

Gauge and charger should be a single driver, especially when capacity
estimation comes into play. Interesting is the part of adjusting charge
current based on AC/VBUS power source and taking VBUS's max-current into
account.


The RTC battery charger though can be a mostly hidden driver as all it
needs is some settings from device-tree (voltage/current) and has no
data to report. Letting the user tune voltage/current or enable/disable
the charger is a matter of taste. From my cubietruck's behavior it seems
as if charger enablement might have an impact of rtc battery's
discharge rate while device is powered-off.

Best,
bruno
Post by Michael Haas
I agree.
Best
Michael
--
You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Michael Haas
2016-04-01 05:44:01 UTC
Permalink
Hello all,
Post by Bruno Prémont
Currently I don't have enough spare time to (actively) work on the patch
set, so feel free to pick up!
With recent additions of support for other AXP variants some porting
work has to be done (not sure I published my latest porting attempts
with some rework to adapt to Hans's axp20x_usb_power.c) and I won't have
time/access to right device to check before mid April.
I have applied your patch to my local tree. No conflicts! I'll be
cleaning this up and submit it as a series.
The latest patch I found [0] mentions that it's a port "on top of Hans'
work".
Post by Bruno Prémont
Post by Michael Haas
Post by Chen-Yu Tsai
Post by Michael Haas
CC'ing Hans as he implemented axp20x_usb_power.c.
IIRC, Hans previously said that the acin and vbus supplies should be handled
by separate power supply drivers. ACIN is easy to do. Just port the VBUS one.
Yeah, that is very straightforward.
Just remember that some devices short-cut ACIN and VBUS, thus the ACIN
driver should only load when the AXP status bit indicates they are
distinct (maybe also having device-tree flag to indicate connector
presence when not short-cutted).
I have added a check for the short-cut bit in the power status register.
Regarding device-tree flag: if the device short-cuts ACIN and VBUS, the
dts file should only contain the VBUS node.
Post by Bruno Prémont
Post by Michael Haas
Post by Chen-Yu Tsai
The charger would likely be another separate driver, either combined or
separate from the fuel gauge (charge level) driver.
One thing I explicitly left aside was "estimating battery capacity", the
original 3.4.x code included some heuristics for that with saving
intermediate values to AXP's registers (data registers kept alive as
long as power was present).
In any case, I'd rather not get too fancy here. Maybe I'll take a stab
at this in a second iteration.
It looks like the "estimating battery capacity" bit would be exposed via
CHARGE_FULL and
CHARGE_EMPTY attributes. Getting that right is probably not that easy as
you have to go
through at least a single charge/discharge cycle.
Post by Bruno Prémont
Gauge and charger should be a single driver, especially when capacity
estimation comes into play. Interesting is the part of adjusting charge
current based on AC/VBUS power source and taking VBUS's max-current into
account.
Doesn't the AXP209 do that automatically?
Post by Bruno Prémont
The RTC battery charger though can be a mostly hidden driver as all it
needs is some settings from device-tree (voltage/current) and has no
data to report. Letting the user tune voltage/current or enable/disable
the charger is a matter of taste. From my cubietruck's behavior it seems
as if charger enablement might have an impact of rtc battery's
discharge rate while device is powered-off.
Do you mean that the RTC battery discharges faster when the charger is
disabled
and the device is powered off (and disconnected from power)?

Two questions about your original patch at [0]:

1) In axp20x_fuel_gauge.c, there is lots of code commented out in
axp20x_power_probe().
It seems to me that the commented out functionality is actually
implemented above. Is that correct?
2) Do you remember what's missing from the power management in
axp20x_fuel_gauge, e.g. in
axp20x_power_suspend()? You noted that as a TODO and the references
to those functions are commented out.


Thanks for the input so far!

Michael

[0] https://groups.google.com/forum/#!topic/linux-sunxi/_XIjwZfEi2U
--
You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Алексей Мамлин
2016-03-31 18:30:09 UTC
Permalink
Post by Michael Haas
Hello all,
I'd like to monitor the battery and charging status connected to my axp209.
Is anyone working on that? Currently, there is only USB power supply
support via
drivers/power/axp20x_usb_power.c.
Adding support for the charging/battery/ACIN bits should be rather
straightforward.
There is a rather nasty bash script which polls the axp20x via i2cget.
I'd rather have a proper solution.
Is anyone working on that? If not, I'll get started.
Or is there an existing driver implemented by Allwinner which can be
re-used?
CC'ing Hans as he implemented axp20x_usb_power.c.
Best
Michael
Have you seen [1] and [2]?

[1]
http://forum.armbian.com/index.php/topic/611-rfc-needs-testing-axp209-mainline-sysfs-interface/
[2] https://github.com/zador-blood-stained/axp209-sysfs-interface
--
You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...