Re: [PATCH v5 05/10] power: supply: rt5033_charger: Add RT5033 charger device driver

Jakob Hauser
2023-05-14T12:55:12Z

Hi Sebastian,

On 14.05.23 14:31, Jakob Hauser wrote:
...
> +static struct rt5033_charger_data *rt5033_charger_dt_init(
> + struct rt5033_charger *charger)
> +{
> + struct rt5033_charger_data *chg;
> + struct power_supply_battery_info *info;
> + int ret;
> +
> + chg = devm_kzalloc(charger->dev, sizeof(*chg), GFP_KERNEL);
> + if (!chg)
> + return ERR_PTR(-ENOMEM);
> +
> + ret = power_supply_get_battery_info(charger->psy, &info);
> + if (ret)
> + return ERR_PTR(dev_err_probe(charger->dev, -EINVAL,
> + "missing battery info\n"));

Here you suggested to use: "info = charger->psy->battery_info;". This
didn't work.

The supply type of the rt5033-charger is set as POWER_SUPPLY_TYPE_USB.
The one of rt5033-battery is POWER_SUPPLY_TYPE_BATTERY. Which makes
sense because if both of them are POWER_SUPPLY_TYPE_BATTERY, userspace
sees two batteries reported, one of which with 0% capacity (the charger
doesn't report capacity).

The ...->psy->battery_info, however, gets populated only for a power
supply device that is supply type POWER_SUPPLY_TYPE_BATTERY [1].

[1]
https://github.com/torvalds/linux/blob/v6.4-rc1/drivers/power/supply/power_supply_core.c#L1390-L1399

> +
> + /* Assign data. Validity will be checked in the init functions. */
> + chg->pre_uamp = info->precharge_current_ua;
> + chg->fast_uamp = info->constant_charge_current_max_ua;
> + chg->eoc_uamp = info->charge_term_current_ua;
> + chg->pre_uvolt = info->precharge_voltage_max_uv;
> + chg->const_uvolt = info->constant_charge_voltage_max_uv;
> +
> + return chg;
> +}
...

Kind regards,
Jakob