From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=165.173.180.11 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796098437; b=SiyRHcLL6WQhokQ7QWbC3OME5dTa7+j3FzVIm+2QFVQGaOxpdZyIZj+RnKqibMBvOeNK RMH8GX0r5sClEjEPfaemwOrGmAGbpHszXse2ts1iDAQJoTO4wyiO+Y5/D/HQIugXn8rPg PuObaDmBfRshTIbFIFmKCss+xNFoFeD6pzA3B4qpT+NZ/Tew38BzpxCcYiBIdj2QaIOAc JaRf9QZRoJIUo8Ml+fQ6v3gcGW5ppy8YzkIYvkRMx/sgZcj2jgVzNSA/qwq8/ZoDsRFrS z+O0olYiek7mteQKqF9OnfxOgEevJwhUsXqhCW5n1SR4t7PO5TgMcfjBj3wf+34ECDg== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796098437; h=DMARC-Filter:DKIM-Signature:Received:Received:Date:From:To:Cc: Subject:Message-ID:References:MIME-Version:Content-Type: Content-Disposition:In-Reply-To:X-Zoho-Virus-Status:X-Zoho-AV-Stamp: X-ZohoMailClient; bh=Zux5SV+hICrWa0jw56NkGEgljSszAnixTMt7WbyYrIg=; b=V5iRvj7FDXQ7X3kay74ukZlzGQpO7XIocEAnByuQUp9g1Q0cJK282tGNFMJoZHY+22J4 2lh1kxtdzRQf/uepj9xX0AF3dPni+oWQRYD/Ucf5FVspjkgNCVTV2FyZcDDJ2U4ktYqOr 6G6maRbytWS6Z72jSUHWvH2M5pdz/TTYI1zeNkF364JfDrmyduesVz7XX9hGqJU7kN+nK jy67xui+hJAwZdLI/KB1UeE+FuY/ptx7Uo1NlJVkieut27b+yKc1r47RKoAJzBbP9NHLw R4HEMn+NlmWv3Sd/Ta80KsVh+hf0Scu30LLxLAt3/nx8ZKCGAr79p1mVK8WeUdvTUnA== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=zohomail header.b=CoUFudOk; arc=pass header.oldest-pass=0 smtp.remote-ip=165.173.180.11 Received: from sender6-op-o11.zoho.com (sender6-op-o11.zoho.com [165.173.180.11]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5022B606A320; Tue, 1 Dec 2026 04:13:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5022B606A320 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=zohomail header.b=CoUFudOk ARC-Seal: i=1; a=rsa-sha256; t=1796098430; cv=none; d=zohomail.com; s=zohoarc; b=Xgws0PgnNdNKTfoxTv24euKYqpzkFTFSnFLKFmzucsrSJmqGRh7f4YF+9iLVKI6NxF/UT3mQPWfu3yaxIBXSGSYt484stGHZiQe9q/wmw6q8deLaTgxxPuzuoArUNFHY/UN3UuC5kdm2bBY1Chr8MPv7wC8x79meOkZj1V7Cobs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1796098430; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=Zux5SV+hICrWa0jw56NkGEgljSszAnixTMt7WbyYrIg=; b=hmi1CdzfvXoIkQQToE3q1mGfYuwtctbpXKMKzJKG99Lf2MAYg8b4dV+vpwbvVpt79oQmLbZnpAKD8+f6kRCUj9EYdLE25S8iXNoCukEIzr7VUPly0ATPuM1Z9shCRqqWTTnCpAsxeI2VpfQwjxNC6dVsGuG6ZXjtsYOFChk44h8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=sebastian.reichel@collabora.com; dmarc=pass header.from= DKIM-Signature: a=rsa-sha256; b=CoUFudOk9VNU3gcJHq4YQ1V2CKaDx9poQunMnrzlbclon9YxNjd5C20ibjNtZ067Ku8bAP82MdLVlaqmP0wUW+jrztMavtSgvRIQkX2HeQSzYjnGLU30DUnQTXdTFWhHDgf6q1cIDqANEFqKPy1jtwPyi70BwsxVdiFL/q/l1hA=; c=relaxed/relaxed; s=zohomail; d=collabora.com; v=1; bh=Zux5SV+hICrWa0jw56NkGEgljSszAnixTMt7WbyYrIg=; h=Content-Description:Content-ID:Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Resent-Sender:Resent-Cc:Resent-Date:Resent-To:Reply-To:Resent-Message-ID:Resent-From:Sender:Subject:To:Date:From:Message-Id:Reply-To:Subject:To:Cc; Received: by smtp.zohomail.com with SMTPS id 179609842740686.39326848350481; Mon, 30 Nov 2026 20:13:47 -0800 (PST) Received: by venus (Postfix, from userid 1000) id 0EBAE180BB4; Tue, 01 Dec 2026 01:14:25 +0100 (CET) Date: Tue, 1 Dec 2026 01:14:25 +0100 From: Sebastian Reichel To: Olivier Louvignes Cc: Lee Jones , Chen-Yu Tsai , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 7/7] power: supply: axp20x_battery: Add support for the AXP2101 Message-ID: References: <20261115171150.64431-1-olivier@mgcrea.io> <20261115171150.64431-8-olivier@mgcrea.io> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="zahizajyptpvwpa2" Content-Disposition: inline In-Reply-To: <20261115171150.64431-8-olivier@mgcrea.io> X-Zoho-Virus-Status: 1 X-Zoho-AV-Stamp: zmail-av-0.2.28.1.5.5/296.93.39 X-ZohoMailClient: External --zahizajyptpvwpa2 Content-Type: text/plain; protected-headers=v1; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Subject: Re: [PATCH v2 7/7] power: supply: axp20x_battery: Add support for the AXP2101 MIME-Version: 1.0 Hi, On Sun, Nov 15, 2026 at 06:11:50PM +0100, Olivier Louvignes wrote: > Program the AXP2101's charger from the monitored battery: the end of > charge voltage (CV_CHG_SET, 4.0 to 4.4 V), the constant charge current > (ICC_CHG_SET, 25 mA steps to 200 mA then 100 mA steps to 1 A), and the > termination and precharge currents (25 mA steps). Report whether the > battery is present, the charge state (precharge, constant current or > constant voltage charging, done, or by the current direction) and the > settings. >=20 > The supply is read-only and reports no capacity: the AXP2101's own fuel > gauge needs a battery model, and the HiBy R1 uses a CW2015 for that. >=20 > Tested on a HiBy R1: the charger registers read back as the stock > firmware's values after boot, and the status is Full on USB, > Discharging unplugged and Charging after a replug. >=20 > Signed-off-by: Olivier Louvignes > --- Acked-by: Sebastian Reichel Greetings, -- Sebastian > drivers/power/supply/axp20x_battery.c | 221 ++++++++++++++++++++++++++ > 1 file changed, 221 insertions(+) >=20 > diff --git a/drivers/power/supply/axp20x_battery.c b/drivers/power/supply= /axp20x_battery.c > index c119014b319a..b26056c4d019 100644 > --- a/drivers/power/supply/axp20x_battery.c > +++ b/drivers/power/supply/axp20x_battery.c > @@ -91,6 +91,26 @@ > =20 > #define AXP717_TS_PIN_DISABLE BIT(4) > =20 > +#define AXP2101_PWR_OP_BATT_PRESENT BIT(3) > +#define AXP2101_PWR_STATUS_MASK GENMASK(6, 5) > +#define AXP2101_PWR_STATUS_BAT_STANDBY 0 > +#define AXP2101_PWR_STATUS_BAT_CHRG 1 > +#define AXP2101_PWR_STATUS_BAT_DISCHRG 2 > +#define AXP2101_CHRG_STATE_MASK GENMASK(2, 0) > +#define AXP2101_CHRG_STATE_TRICKLE 0 > +#define AXP2101_CHRG_STATE_PRECHARGE 1 > +#define AXP2101_CHRG_STATE_CC 2 > +#define AXP2101_CHRG_STATE_CV 3 > +#define AXP2101_CHRG_STATE_DONE 4 > +/* CV_CHG_SET: end of charge voltage selector, 1 to 5 for 4.0 to 4.4 V. = */ > +#define AXP2101_CHRG_CV_VOLT_MASK GENMASK(2, 0) > +#define AXP2101_ICC_MASK GENMASK(4, 0) > +#define AXP2101_ICC_MAX_SEL 16 /* 1 A; 17 to 31 are reserved */ > +#define AXP2101_ITERM_MASK GENMASK(3, 0) > +#define AXP2101_ITERM_ENABLE BIT(4) > +#define AXP2101_IPRECHG_MASK GENMASK(3, 0) > +#define AXP2101_CURRENT_STEP 25000 > + > struct axp20x_batt_ps; > =20 > struct axp_data { > @@ -213,6 +233,44 @@ static int axp717_battery_get_max_voltage(struct axp= 20x_batt_ps *axp20x_batt, > } > } > =20 > +/* End of charge voltages of CV_CHG_SET selectors 0 to 7; 0, 6 and 7 are= reserved. */ > +static const int axp2101_cv_uv[] =3D { > + 0, 4000000, 4100000, 4200000, 4350000, 4400000, 0, 0, > +}; > + > +static int axp2101_battery_get_max_voltage(struct axp20x_batt_ps *axp20x= _batt, > + int *val) > +{ > + int ret, reg; > + > + ret =3D regmap_read(axp20x_batt->regmap, AXP2101_CV_CHG_SET, ®); > + if (ret) > + return ret; > + > + *val =3D axp2101_cv_uv[reg & AXP2101_CHRG_CV_VOLT_MASK]; > + return *val ? 0 : -EINVAL; > +} > + > +static int axp2101_battery_set_max_voltage(struct axp20x_batt_ps *axp20x= _batt, > + int val) > +{ > + int sel; > + > + for (sel =3D 0; sel < ARRAY_SIZE(axp2101_cv_uv); sel++) > + if (axp2101_cv_uv[sel] && axp2101_cv_uv[sel] =3D=3D val) > + return regmap_update_bits(axp20x_batt->regmap, > + AXP2101_CV_CHG_SET, > + AXP2101_CHRG_CV_VOLT_MASK, sel); > + > + return -EINVAL; > +} > + > +/* CONSTANT_CHARGE_CURRENT: 25 mA steps up to 200 mA, then 100 mA steps.= */ > +static int axp2101_ccc_from_sel(unsigned int sel) > +{ > + return sel <=3D 8 ? sel * 25000 : 200000 + (sel - 8) * 100000; > +} > + > static int axp813_battery_get_max_voltage(struct axp20x_batt_ps *axp20x_= batt, > int *val) > { > @@ -425,6 +483,89 @@ static int axp20x_battery_get_prop(struct power_supp= ly *psy, > return 0; > } > =20 > +static int axp2101_battery_get_prop(struct power_supply *psy, > + enum power_supply_property psp, > + union power_supply_propval *val) > +{ > + struct axp20x_batt_ps *axp20x_batt =3D power_supply_get_drvdata(psy); > + int ret, reg; > + > + switch (psp) { > + case POWER_SUPPLY_PROP_PRESENT: > + case POWER_SUPPLY_PROP_ONLINE: > + ret =3D regmap_read(axp20x_batt->regmap, AXP2101_PMU_STATUS_1, > + ®); > + if (ret) > + return ret; > + > + val->intval =3D !!(reg & AXP2101_PWR_OP_BATT_PRESENT); > + return 0; > + > + case POWER_SUPPLY_PROP_STATUS: > + ret =3D regmap_read(axp20x_batt->regmap, AXP2101_PMU_STATUS_2, > + ®); > + if (ret) > + return ret; > + > + switch (FIELD_GET(AXP2101_CHRG_STATE_MASK, reg)) { > + case AXP2101_CHRG_STATE_PRECHARGE: > + case AXP2101_CHRG_STATE_CC: > + case AXP2101_CHRG_STATE_CV: > + val->intval =3D POWER_SUPPLY_STATUS_CHARGING; > + return 0; > + case AXP2101_CHRG_STATE_DONE: > + val->intval =3D POWER_SUPPLY_STATUS_FULL; > + return 0; > + } > + > + /* Trickle charging or not charging: by the current direction. */ > + switch (FIELD_GET(AXP2101_PWR_STATUS_MASK, reg)) { > + case AXP2101_PWR_STATUS_BAT_STANDBY: > + val->intval =3D POWER_SUPPLY_STATUS_NOT_CHARGING; > + return 0; > + case AXP2101_PWR_STATUS_BAT_CHRG: > + val->intval =3D POWER_SUPPLY_STATUS_CHARGING; > + return 0; > + case AXP2101_PWR_STATUS_BAT_DISCHRG: > + val->intval =3D POWER_SUPPLY_STATUS_DISCHARGING; > + return 0; > + default: > + val->intval =3D POWER_SUPPLY_STATUS_UNKNOWN; > + return 0; > + } > + > + case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX: > + ret =3D regmap_read(axp20x_batt->regmap, AXP2101_ICC_CHG_SET, > + ®); > + if (ret) > + return ret; > + > + val->intval =3D axp2101_ccc_from_sel(FIELD_GET(AXP2101_ICC_MASK, > + reg)); > + return 0; > + > + case POWER_SUPPLY_PROP_VOLTAGE_MAX: > + return axp2101_battery_get_max_voltage(axp20x_batt, > + &val->intval); > + > + case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT: > + ret =3D regmap_read(axp20x_batt->regmap, AXP2101_ITERM_CHG_SET, > + ®); > + if (ret) > + return ret; > + > + if (!(reg & AXP2101_ITERM_ENABLE)) > + val->intval =3D 0; > + else > + val->intval =3D FIELD_GET(AXP2101_ITERM_MASK, reg) * > + AXP2101_CURRENT_STEP; > + return 0; > + > + default: > + return -EINVAL; > + } > +} > + > static int axp717_battery_get_prop(struct power_supply *psy, > enum power_supply_property psp, > union power_supply_propval *val) > @@ -852,6 +993,15 @@ static enum power_supply_property axp20x_battery_pro= ps[] =3D { > POWER_SUPPLY_PROP_CAPACITY, > }; > =20 > +static enum power_supply_property axp2101_battery_props[] =3D { > + POWER_SUPPLY_PROP_PRESENT, > + POWER_SUPPLY_PROP_ONLINE, > + POWER_SUPPLY_PROP_STATUS, > + POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX, > + POWER_SUPPLY_PROP_VOLTAGE_MAX, > + POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT, > +}; > + > static enum power_supply_property axp717_battery_props[] =3D { > POWER_SUPPLY_PROP_PRESENT, > POWER_SUPPLY_PROP_ONLINE, > @@ -895,6 +1045,15 @@ static const struct power_supply_desc axp209_batt_p= s_desc =3D { > .set_property =3D axp20x_battery_set_prop, > }; > =20 > +/* Read-only: the charge settings come from the monitored battery. */ > +static const struct power_supply_desc axp2101_batt_ps_desc =3D { > + .name =3D "axp20x-battery", > + .type =3D POWER_SUPPLY_TYPE_BATTERY, > + .properties =3D axp2101_battery_props, > + .num_properties =3D ARRAY_SIZE(axp2101_battery_props), > + .get_property =3D axp2101_battery_get_prop, > +}; > + > static const struct power_supply_desc axp717_batt_ps_desc =3D { > .name =3D "axp20x-battery", > .type =3D POWER_SUPPLY_TYPE_BATTERY, > @@ -978,6 +1137,57 @@ static void axp209_set_battery_info(struct platform= _device *pdev, > } > } > =20 > +static int axp2101_bat_cfg_iio_channels(struct platform_device *pdev, > + struct axp20x_batt_ps *axp_batt) > +{ > + return 0; > +} > + > +/* > + * Programs the charger from the monitored battery: end of charge voltag= e, > + * constant charge current, termination and precharge currents. What the > + * battery doesn't give is left as it is. > + */ > +static void axp2101_set_battery_info(struct platform_device *pdev, > + struct axp20x_batt_ps *axp_batt, > + struct power_supply_battery_info *info) > +{ > + int cv =3D info->constant_charge_voltage_max_uv; > + int ccc =3D info->constant_charge_current_max_ua; > + int iterm =3D info->charge_term_current_ua; > + int iprechg =3D info->precharge_current_ua; > + unsigned int sel; > + > + if (cv > 0 && axp2101_battery_set_max_voltage(axp_batt, cv)) > + dev_err(&pdev->dev, "unsupported charge voltage %d uV\n", cv); > + > + if (ccc > 0) { > + if (ccc <=3D 200000) > + sel =3D ccc / AXP2101_CURRENT_STEP; > + else > + sel =3D min((ccc - 200000) / 100000 + 8, > + AXP2101_ICC_MAX_SEL); > + axp_batt->max_ccc =3D axp2101_ccc_from_sel(sel); > + regmap_update_bits(axp_batt->regmap, AXP2101_ICC_CHG_SET, > + AXP2101_ICC_MASK, sel); > + } > + > + if (iterm > 0) { > + sel =3D min(iterm / AXP2101_CURRENT_STEP, > + (int)FIELD_MAX(AXP2101_ITERM_MASK)); > + regmap_update_bits(axp_batt->regmap, AXP2101_ITERM_CHG_SET, > + AXP2101_ITERM_MASK | AXP2101_ITERM_ENABLE, > + sel | AXP2101_ITERM_ENABLE); > + } > + > + if (iprechg > 0) { > + sel =3D min(iprechg / AXP2101_CURRENT_STEP, > + (int)FIELD_MAX(AXP2101_IPRECHG_MASK)); > + regmap_update_bits(axp_batt->regmap, AXP2101_IPRECHG_SET, > + AXP2101_IPRECHG_MASK, sel); > + } > +} > + > static void axp717_set_battery_info(struct platform_device *pdev, > struct axp20x_batt_ps *axp_batt, > struct power_supply_battery_info *info) > @@ -1047,6 +1257,14 @@ static const struct axp_data axp221_data =3D { > .set_bat_info =3D axp209_set_battery_info, > }; > =20 > +static const struct axp_data axp2101_data =3D { > + .bat_ps_desc =3D &axp2101_batt_ps_desc, > + .get_max_voltage =3D axp2101_battery_get_max_voltage, > + .set_max_voltage =3D axp2101_battery_set_max_voltage, > + .cfg_iio_chan =3D axp2101_bat_cfg_iio_channels, > + .set_bat_info =3D axp2101_set_battery_info, > +}; > + > static const struct axp_data axp717_data =3D { > .ccc_scale =3D 64000, > .ccc_offset =3D 0, > @@ -1082,6 +1300,9 @@ static const struct of_device_id axp20x_battery_ps_= id[] =3D { > }, { > .compatible =3D "x-powers,axp717-battery-power-supply", > .data =3D (void *)&axp717_data, > + }, { > + .compatible =3D "x-powers,axp2101-battery-power-supply", > + .data =3D (void *)&axp2101_data, > }, { > .compatible =3D "x-powers,axp813-battery-power-supply", > .data =3D (void *)&axp813_data, > --=20 > 2.39.5 >=20 --zahizajyptpvwpa2 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEE72YNB0Y/i3JqeVQT2O7X88g7+poFAmsOEWAACgkQ2O7X88g7 +prmcw//SviMClra0wwchYrpzlpidg7QUwr6PpWE4TUIhR0nu6a+3+nhoc+dVQxM U/KJN06FO9GU0t0FmUwfB6r319vbV5JCvUZWDIhvq6A6vMKVTk3ZvazlGeJuHw63 gqdZ8iJKO5eSckOhrdK21/fJRwpm2YMbALgOUV3WfDjL/uQULKAqt2GgYDZRC8sr 33XRw4Wmkrrxp7/MHhgqkOP90OdsmBu1BwwGjwndeQAbjBrWK3XqsaihnAbUy0KA TjQyIuaj34lKgVNtphj3P992vvh/ihW7JW+KUpQnp3jXEPFaighCtjKkmUg1SWg4 I4W+dtz5nXPXXBE2M0il5kytq9gD/W4ULyXoGh2h2dqEKuKlCkRZtbsjIhEaDO9a yf+4EZM5KqSfrUS/d/gfEth/lwcFOBBsaVeXe6kVJBQkN8/GyBhtLKK31C1PnKb4 ghQRJAlKFFXsbnjMNd+0vTzn4giDIzjw+Z0w7b4Fq9YoodZoTm1TvMV23FdS8AA5 s3BooGhu17VNg6oqin5CYTTnnac9L/913qASL/sJArKCiKq/RH2d3gWJnAGtyFtP JanjGg4HpMH8zgjoebD1RTKi6f6IIjKVh1BOWf084uvIF7kev/rBAScM+1ALz1yY 6HvO5+ti/xt5X1W+iHNRdy1M9MLx3eioivHcBRO9pzvnRux++Xs= =97F/ -----END PGP SIGNATURE----- --zahizajyptpvwpa2--