On Tue, Jan 11, 2022 at 09:59:27AM +0100, Patrick Wildt wrote:
> Can you try this?
> 
> diff --git a/sys/dev/fdt/axppmic.c b/sys/dev/fdt/axppmic.c
> index 7e2b0c99942..2a3497f6755 100644
> --- a/sys/dev/fdt/axppmic.c
> +++ b/sys/dev/fdt/axppmic.c
> @@ -36,6 +36,8 @@ extern void (*powerdownfn)(void);
>  #define  AXP209_ADC_EN1_ACIN (3 << 4)
>  #define  AXP209_ADC_EN1_VBUS (3 << 2)
>  
> +#define AXP803_BC_MOD_GLOBAL         0x2c
> +#define AXP803_BC_MOD_GLOBAL_EN              (1 << 0)
>  #define AXP803_BAT_CAP_WARN          0xe6
>  #define  AXP803_BAT_CAP_WARN_LV1     0xf0
>  #define  AXP803_BAT_CAP_WARN_LV1BASE 5
> @@ -554,6 +556,15 @@ axppmic_attach_node(struct axppmic_softc *sc, int node)
>  
>       if (OF_is_compatible(node, "x-powers,axp803-battery-power-supply"))
>               sc->sc_sensdata = axp803_battery_sensdata;
> +
> +     if (OF_is_compatible(node, "x-powers,axp803-usb-power-supply")) {
> +             uint8_t reg;
> +
> +             /* Turn on battery charging module. */
> +             reg = axppmic_read_reg(sc, AXP803_BC_MOD_GLOBAL);
> +             reg |= AXP803_BC_MOD_GLOBAL_EN;
> +             axppmic_write_reg(sc, AXP803_BC_MOD_GLOBAL, reg);
> +     }
>  }
>  
>  /* Regulators */

I had another look at this, and added code to read the 0x2c register before and 
after writing to it.

>From a cold power-on without AC, (I.E. battery removed, battery replaced, 
>phone booted on battery power), the register always reads 0x00, and correctly 
>reads 0x01 after being set.

After a power cycle, but without removing the battery, I.E. just halt -p, and 
then powering on again, the register reads the 0x01 value before and after 
being set.

This is the expected behaviour, and confirms that we are indeed writing to the 
register.

Connecting AC and rebooting, the register reads 0x01 before being set, then 
0x91 afterwards.

The 0x91 value remains over a power cycle, (battery in place, and not removed), 
even when AC is removed.

In other words:
        * Phone running on AC, register set to 0x91
        * Disconnect AC
        * Issue halt -p
        * Battery left in place
        * Power on with power button
        * During boot, register reads 0x91 before being set

Setting the register to 0x00 and rebooting it stays at 0x00, even if AC is 
connected.

Removing the battery whilst the phone was running made the white LED, (camera 
flash / torch), blink repeatedly at regular intervals.  It looked like some 
kind of warning indicator.

Powering on the phone with no battery, hw.sensors.axppmic0.indicator2, (which 
is battery present), continued to say ON, and hw.sensors.axppmic0.percent0 read 
0%.

However, after replacing the battery, (whilst the phone continued powered up on 
AC), did not change the percent0 reading, it stayed at 0%.

Even after a power cycle, I.E. battery left in place, AC disconnected, phone 
halted, and then powered up on battery power, percent0 remained at 0%!

It was necessary to remove the battery and then replace it and boot again to 
get a reading of 95%, (which was probably correct).

Reply via email to