Re: [PATCH v4 7/8] power: supply: rt5033_battery: Adopt status property from charger

From: Jakob Hauser
Date: Tue May 09 2023 - 19:00:25 EST


Hi Sebastian,

On 09.05.23 09:25, Sebastian Reichel wrote:
On Tue, May 09, 2023 at 03:01:32AM +0200, Jakob Hauser wrote:
On 09.05.23 00:06, Sebastian Reichel wrote:

...

I suppose your DT is missing the connection between the charger and
the battery:

rt5033_charger: charger {
compatible = "rt5033-charger";
...
}

fuel-gauge {
compatible = "rt5033-battery";
...
power-supplies = <&rt5033_charger>; // you are probably missing this
};

See also Documentation/devicetree/bindings/power/supply/power-supply.yaml

...

Thanks for the hints.

This leads to updating the dt-bindings because adding the "power-supplies"
property is important to be aware of.

It should already be part of the binding, because richtek,rt5033-battery.yaml has

allOf:
- $ref: power-supply.yaml#

Uh, I see, you're two steps ahead ;)

Btw. first it didn't work. It took me quite some time to debug. I needed to
add "psy_cfg.of_node = client->dev.of_node;" to the rt5033-battery probe
function.

Now it works. However, there is a new problem. The battery driver gets
probed first. The charger driver a bit later. In the meantime the battery
driver spams dmesg with several "Failed to register power supply" because
the charger driver isn't available yet. Once the charger driver is there, it
works fine and dmesg becomes silent.

With the current state of the patchset:
dmesg | grep rt5033
[ 13.628030] rt5033 6-0034: Device found (rev. 6)
[ 13.633552] rt5033-led: Failed to locate of_node [id: -1]
[ 13.790478] rt5033-charger rt5033-charger: DMA mask not set

With the changes discussed here:
dmesg | grep rt5033
[ 15.741915] rt5033-battery 4-0035: Failed to register power supply
[ 15.752894] rt5033-battery 4-0035: Failed to register power supply
[ 15.795458] rt5033-battery 4-0035: Failed to register power supply
[ 15.910760] rt5033-battery 4-0035: Failed to register power supply
[ 15.913187] rt5033 6-0034: Device found (rev. 6)
[ 15.914341] rt5033-led: Failed to locate of_node [id: -1]
[ 15.920052] rt5033-battery 4-0035: Failed to register power supply
[ 15.927262] rt5033-battery 4-0035: Failed to register power supply
[ 16.017131] rt5033-battery 4-0035: Failed to register power supply
[ 16.017401] rt5033-charger rt5033-charger: DMA mask not set

The message is comming from the rt5033-battery probe function, it's the
power_supply_register() that fails.

Any ideas what could be done about this?

Replace the dev_err() with dev_err_probe():

if (IS_ERR(battery->psy))
return dev_err_probe(&client->dev, PTR_ERR(battery->psy), "Failed to register power supply\n");

That will avoid printing an error for -EPROBE_DEFER.

Confirming, that works. Thanks!

Kind regards,
Jakob