The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Sebastian Reichel <sebastian.reichel@collabora.com>
To: Olivier Louvignes <olivier@mgcrea.io>
Cc: Lee Jones <lee@kernel.org>, Chen-Yu Tsai <wens@kernel.org>,
	 linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 5/7] power: supply: axp20x_usb_power: Add support for the AXP2101
Date: Tue, 1 Dec 2026 01:12:19 +0100	[thread overview]
Message-ID: <aw4Qv7CvUm7MudX5@venus> (raw)
In-Reply-To: <20261115171150.64431-6-olivier@mgcrea.io>

[-- Attachment #1: Type: text/plain, Size: 5721 bytes --]

Hi,

On Sun, Nov 15, 2026 at 06:11:48PM +0100, Olivier Louvignes wrote:
> Report whether VBUS is present (bit 5 of the first status register) and
> the input current limit (100 mA to 2 A, in IIN_LIM), and update on the
> VBUS plug-in and removal interrupts. Nothing is written: the AXP2101's
> VBUS input needs no set-up for that.
> 
> Tested on a HiBy R1: unplugging and replugging the cable gives one
> VBUS_REMOVAL and one VBUS_PLUGIN interrupt, and "online" goes 1, 0, 1.
> 
> Signed-off-by: Olivier Louvignes <olivier@mgcrea.io>
> ---

Acked-by: Sebastian Reichel <sebastian.reichel@collabora.com>

Greetings,

-- Sebastian

>  drivers/power/supply/axp20x_usb_power.c | 86 +++++++++++++++++++++++++
>  1 file changed, 86 insertions(+)
> 
> diff --git a/drivers/power/supply/axp20x_usb_power.c b/drivers/power/supply/axp20x_usb_power.c
> index 7625366104bc..926f9c3f1239 100644
> --- a/drivers/power/supply/axp20x_usb_power.c
> +++ b/drivers/power/supply/axp20x_usb_power.c
> @@ -31,6 +31,7 @@
>  #define AXP20X_PWR_STATUS_VBUS_USED	BIT(4)
>  
>  #define AXP717_PWR_STATUS_VBUS_GOOD	BIT(5)
> +#define AXP2101_PWR_STATUS_VBUS_GOOD	BIT(5)
>  
>  #define AXP20X_USB_STATUS_VBUS_VALID	BIT(2)
>  
> @@ -172,6 +173,24 @@ static void axp717_usb_power_poll_vbus(struct work_struct *work)
>  	power->old_status = val;
>  }
>  
> +static void axp2101_usb_power_poll_vbus(struct work_struct *work)
> +{
> +	struct axp20x_usb_power *power =
> +		container_of(work, struct axp20x_usb_power, vbus_detect.work);
> +	unsigned int val;
> +	int ret;
> +
> +	ret = regmap_read(power->regmap, AXP2101_PMU_STATUS_1, &val);
> +	if (ret)
> +		return;
> +
> +	val &= AXP2101_PWR_STATUS_VBUS_GOOD;
> +	if (val != power->old_status)
> +		power_supply_changed(power->supply);
> +
> +	power->old_status = val;
> +}
> +
>  static int axp20x_get_usb_type(struct axp20x_usb_power *power,
>  			       union power_supply_propval *val)
>  {
> @@ -315,6 +334,42 @@ static int axp20x_usb_power_get_property(struct power_supply *psy,
>  	return 0;
>  }
>  
> +/* Input current limits of AXP2101_IIN_LIM; 6 and 7 are reserved. */
> +static const int axp2101_usb_curr_lim_table[] = {
> +	100000, 500000, 900000, 1000000, 1500000, 2000000,
> +};
> +
> +static int axp2101_usb_power_get_property(struct power_supply *psy,
> +					  enum power_supply_property psp,
> +					  union power_supply_propval *val)
> +{
> +	struct axp20x_usb_power *power = power_supply_get_drvdata(psy);
> +	unsigned int v;
> +	int ret;
> +
> +	switch (psp) {
> +	case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
> +		ret = regmap_field_read(power->curr_lim_fld, &v);
> +		if (ret)
> +			return ret;
> +		if (v >= ARRAY_SIZE(axp2101_usb_curr_lim_table))
> +			return -EINVAL;
> +		val->intval = axp2101_usb_curr_lim_table[v];
> +		break;
> +	case POWER_SUPPLY_PROP_ONLINE:
> +	case POWER_SUPPLY_PROP_PRESENT:
> +		ret = regmap_read(power->regmap, AXP2101_PMU_STATUS_1, &v);
> +		if (ret)
> +			return ret;
> +		val->intval = !!(v & AXP2101_PWR_STATUS_VBUS_GOOD);
> +		break;
> +	default:
> +		return -EINVAL;
> +	}
> +
> +	return 0;
> +}
> +
>  static int axp717_usb_power_get_property(struct power_supply *psy,
>  	enum power_supply_property psp, union power_supply_propval *val)
>  {
> @@ -643,6 +698,12 @@ static enum power_supply_property axp22x_usb_power_properties[] = {
>  	POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT,
>  };
>  
> +static enum power_supply_property axp2101_usb_power_properties[] = {
> +	POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT,
> +	POWER_SUPPLY_PROP_ONLINE,
> +	POWER_SUPPLY_PROP_PRESENT,
> +};
> +
>  static enum power_supply_property axp717_usb_power_properties[] = {
>  	POWER_SUPPLY_PROP_HEALTH,
>  	POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT,
> @@ -682,6 +743,14 @@ static const struct power_supply_desc axp22x_usb_power_desc = {
>  	.set_property = axp20x_usb_power_set_property,
>  };
>  
> +static const struct power_supply_desc axp2101_usb_power_desc = {
> +	.name = "axp20x-usb",
> +	.type = POWER_SUPPLY_TYPE_USB,
> +	.properties = axp2101_usb_power_properties,
> +	.num_properties = ARRAY_SIZE(axp2101_usb_power_properties),
> +	.get_property = axp2101_usb_power_get_property,
> +};
> +
>  static const struct power_supply_desc axp717_usb_power_desc = {
>  	.name = "axp20x-usb",
>  	.type = POWER_SUPPLY_TYPE_USB,
> @@ -722,6 +791,11 @@ static const char * const axp22x_irq_names[] = {
>  	"VBUS_REMOVAL",
>  };
>  
> +static const char * const axp2101_irq_names[] = {
> +	"VBUS_PLUGIN",
> +	"VBUS_REMOVAL",
> +};
> +
>  static const char * const axp717_irq_names[] = {
>  	"VBUS_PLUGIN",
>  	"VBUS_REMOVAL",
> @@ -815,6 +889,15 @@ static const struct axp_data axp223_data = {
>  	.axp20x_cfg_adc_reg = axp20x_configure_adc_registers,
>  };
>  
> +static const struct axp_data axp2101_data = {
> +	.power_desc	= &axp2101_usb_power_desc,
> +	.irq_names	= axp2101_irq_names,
> +	.num_irq_names	= ARRAY_SIZE(axp2101_irq_names),
> +	.curr_lim_fld	= REG_FIELD(AXP2101_IIN_LIM, 0, 2),
> +	.vbus_needs_polling = false,
> +	.axp20x_read_vbus = &axp2101_usb_power_poll_vbus,
> +};
> +
>  static const struct axp_data axp717_data = {
>  	.power_desc     = &axp717_usb_power_desc,
>  	.irq_names      = axp717_irq_names,
> @@ -1056,6 +1139,9 @@ static const struct of_device_id axp20x_usb_power_match[] = {
>  	}, {
>  		.compatible = "x-powers,axp717-usb-power-supply",
>  		.data = &axp717_data,
> +	}, {
> +		.compatible = "x-powers,axp2101-usb-power-supply",
> +		.data = &axp2101_data,
>  	}, {
>  		.compatible = "x-powers,axp813-usb-power-supply",
>  		.data = &axp813_data,
> -- 
> 2.39.5
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2026-12-01  4:13 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-15 17:11 [PATCH v2 0/7] Add support for the X-Powers AXP2101 PMIC Olivier Louvignes
2026-11-15 17:11 ` [PATCH v2 1/7] dt-bindings: mfd: x-powers,axp152: Add the AXP2101 Olivier Louvignes
2026-11-16 12:38   ` Krzysztof Kozlowski
2026-11-15 17:11 ` [PATCH v2 2/7] mfd: axp20x: Add support for " Olivier Louvignes
2026-11-15 17:11 ` [PATCH v2 3/7] regulator: " Olivier Louvignes
2026-11-15 17:11 ` [PATCH v2 4/7] dt-bindings: power: supply: axp20x-usb-power: Add " Olivier Louvignes
2026-11-16 12:38   ` Krzysztof Kozlowski
2026-12-01  0:11   ` Sebastian Reichel
2026-11-15 17:11 ` [PATCH v2 5/7] power: supply: axp20x_usb_power: Add support for " Olivier Louvignes
2026-12-01  0:12   ` Sebastian Reichel [this message]
2026-11-15 17:11 ` [PATCH v2 6/7] dt-bindings: power: supply: axp20x-battery: Add " Olivier Louvignes
2026-12-01  0:13   ` Sebastian Reichel
2026-11-15 17:11 ` [PATCH v2 7/7] power: supply: axp20x_battery: Add support for " Olivier Louvignes
2026-12-01  0:14   ` Sebastian Reichel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aw4Qv7CvUm7MudX5@venus \
    --to=sebastian.reichel@collabora.com \
    --cc=lee@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=olivier@mgcrea.io \
    --cc=wens@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox