Re: [PATCH 2/2] power: supply: qcom_battmgr: Add support batteryless boards as MAINS

From: Bjorn Andersson

Date: Thu Jul 16 2026 - 20:13:03 EST


On Mon, May 18, 2026 at 07:19:40PM +0530, Rakesh Kota wrote:
> Add support for the "qcom,batteryless" device tree property.
> When this boolean property is present, the driver registers the power
> supply as POWER_SUPPLY_TYPE_MAINS instead of BATTERY. This prevents
> userspace from triggering battery power-saving sequences when using
> powered by 12V adapters.
>
> Signed-off-by: Rakesh Kota <rakesh.kota@xxxxxxxxxxxxxxxx>
> ---
> drivers/power/supply/qcom_battmgr.c | 47 ++++++++++++++++++++++++++++++++++++-
> 1 file changed, 46 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/power/supply/qcom_battmgr.c b/drivers/power/supply/qcom_battmgr.c
> index 490137a23d00e97a9e6ced21d1e66fe637db6c9d..35d266375d8c46b161a64f9c2a8c6054dc2211de 100644
> --- a/drivers/power/supply/qcom_battmgr.c
> +++ b/drivers/power/supply/qcom_battmgr.c
> @@ -332,6 +332,7 @@ struct qcom_battmgr {
> struct qcom_battmgr_wireless wireless;
>
> struct work_struct enable_work;
> + bool batteryless;

This is a local variable used only within qcom_battmgr_probe()

>
> /*
> * @lock is used to prevent concurrent power supply requests to the
> @@ -930,6 +931,47 @@ static const struct power_supply_desc sm8550_bat_psy_desc = {
> .property_is_writeable = qcom_battmgr_bat_is_writeable,
> };
>
> +static int qcom_battmgr_dcin_get_property(struct power_supply *psy,
> + enum power_supply_property psp,
> + union power_supply_propval *val)
> +{
> + struct qcom_battmgr *battmgr = power_supply_get_drvdata(psy);
> + int ret;
> +
> + if (!battmgr->service_up)
> + return -EAGAIN;
> +
> + ret = qcom_battmgr_bat_sm8350_update(battmgr, psp);
> + if (ret < 0)
> + return ret;
> +
> + switch (psp) {
> + case POWER_SUPPLY_PROP_STATUS:
> + val->intval = battmgr->status.status;
> + break;
> + case POWER_SUPPLY_PROP_PRESENT:
> + val->intval = battmgr->info.present;
> + break;
> + default:
> + return -EINVAL;
> + }
> +
> + return 0;
> +}
> +
> +static const enum power_supply_property dcin_props[] = {
> + POWER_SUPPLY_PROP_STATUS,
> + POWER_SUPPLY_PROP_PRESENT,
> +};
> +
> +static const struct power_supply_desc dcin_psy_desc = {

Everything else in this driver is prefixed based on which firmware
interface it's operating against, but you decided to ignore that
convention...

Don't do that.

> + .name = "qcom-battmgr-dcin",

Isn't this what we call qcom-battmgr-ac for the compute targets?

Is there any reason to not unify the naming?

> + .type = POWER_SUPPLY_TYPE_MAINS,
> + .properties = dcin_props,
> + .num_properties = ARRAY_SIZE(dcin_props),
> + .get_property = qcom_battmgr_dcin_get_property,
> +};
> +
> static int qcom_battmgr_ac_get_property(struct power_supply *psy,
> enum power_supply_property psp,
> union power_supply_propval *val)
> @@ -1652,6 +1694,7 @@ static int qcom_battmgr_probe(struct auxiliary_device *adev,
> mutex_init(&battmgr->lock);
> init_completion(&battmgr->ack);
>
> + battmgr->batteryless = device_property_read_bool(dev, "qcom,batteryless");
> match = of_match_device(qcom_battmgr_of_variants, dev->parent);
> if (match)
> battmgr->variant = (unsigned long)match->data;
> @@ -1690,7 +1733,9 @@ static int qcom_battmgr_probe(struct auxiliary_device *adev,
> return dev_err_probe(dev, PTR_ERR(battmgr->wls_psy),
> "failed to register wireless charing power supply\n");
> } else {
> - if (battmgr->variant == QCOM_BATTMGR_SM8550)
> + if (battmgr->batteryless)
> + psy_desc = &dcin_psy_desc;

The psy_desc here is what is used to register the bat_psy on the line
below. Why would you register "dcin" as your bat_psy?

Is there an actual reason or are you just lazy?

Regards,
Bjorn

> + else if (battmgr->variant == QCOM_BATTMGR_SM8550)
> psy_desc = &sm8550_bat_psy_desc;
> else
> psy_desc = &sm8350_bat_psy_desc;
>
> --
> 2.34.1
>