Skip to contentSkip to conversation

AXP717: Add USB Power Supply

PATCH In review Chris Morgan 4 participants 9 messages May 22, 2024 – Jun 6, 2024 1 message not in the archive

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

cover AXP717: Add USB Power Supply

From: Chris Morgan <[email protected]>

This series adds support for the AXP717 USB power supply. I will be adding support for the battery in a future patch series.

Note this series depends on the "regulator: Fix AXP717 PMIC support" series which is still pending [1].

[1] https://lore.kernel.org/linux-sunxi/[email protected]/

Chris Morgan (4):
mfd: axp20x: AXP717: Correct MODULE_ENABLE_CONTROL register name
dt-bindings: mfd: x-powers,axp20x-usb-power-supply: add AXP717
power: supply: axp20x_usb_power: Add support for AXP717
arm64: dts: allwinner: Anbernic RG35XX: add AXP717 USB power

 .../x-powers,axp20x-usb-power-supply.yaml     |   1 +
 .../sun50i-h700-anbernic-rg35xx-2024.dts      |   5 +
 drivers/mfd/axp20x.c                          |  19 +-
 drivers/power/supply/axp20x_usb_power.c       | 216 +++++++++++++++++-
 drivers/regulator/axp20x-regulator.c          |   2 +-
 include/linux/mfd/axp20x.h                    |  20 +-
 6 files changed, 256 insertions(+), 7 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/4 mfd: axp20x: AXP717: Correct MODULE_ENABLE_CONTROL register name

From: Chris Morgan <[email protected]>

The datasheet lists two "MODULE_ENABLE_CONTROL" registers; the first one is at register 0x0b and the second is at 0x19. Change the name of the register at 0x19 to AXP717_MODULE_ENABLE_CONTROL_2 to reflect this.

---
 drivers/mfd/axp20x.c                 | 2 +-
 drivers/regulator/axp20x-regulator.c | 2 +-
 include/linux/mfd/axp20x.h           | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/mfd/axp20x.c +1 -1
index 609e7e149681..16950c3206d7 100644
@@ -209,7 +209,7 @@ static const struct regmap_access_table axp313a_volatile_table = {
 };
 
 static const struct regmap_range axp717_writeable_ranges[] = {
-	regmap_reg_range(AXP717_MODULE_EN_CONTROL, AXP717_MODULE_EN_CONTROL),
+	regmap_reg_range(AXP717_MODULE_EN_CONTROL_2, AXP717_MODULE_EN_CONTROL_2),
 	regmap_reg_range(AXP717_BOOST_CONTROL, AXP717_BOOST_CONTROL),
 	regmap_reg_range(AXP717_IRQ0_EN, AXP717_IRQ4_EN),
 	regmap_reg_range(AXP717_IRQ0_STATE, AXP717_IRQ4_STATE),
drivers/regulator/axp20x-regulator.c +1 -1
index 20bef3971fec..a8e91d9d028b 100644
@@ -837,7 +837,7 @@ static const struct regulator_desc axp717_regulators[] = {
 		 AXP717_LDO1_OUTPUT_CONTROL, BIT(4)),
 	AXP_DESC(AXP717, BOOST, "boost", "vin1", 4550, 5510, 64,
 		 AXP717_BOOST_CONTROL, AXP717_BOOST_V_OUT_MASK,
-		 AXP717_MODULE_EN_CONTROL, BIT(4)),
+		 AXP717_MODULE_EN_CONTROL_2, BIT(4)),
 };
 
 /* DCDC ranges shared with AXP813 */
include/linux/mfd/axp20x.h +1 -1
index 5e86b976c4ca..e0cd66bd3b6d 100644
@@ -115,7 +115,7 @@ enum axp20x_variants {
 #define AXP313A_IRQ_STATE		0x21
 
 #define AXP717_ON_INDICATE		0x00
-#define AXP717_MODULE_EN_CONTROL	0x19
+#define AXP717_MODULE_EN_CONTROL_2	0x19
 #define AXP717_BOOST_CONTROL		0x1e
 #define AXP717_IRQ0_EN			0x40
 #define AXP717_IRQ1_EN			0x41
Signature · 1 line
2.34.1
#2 lore raw

PATCH 2/4 dt-bindings: mfd: x-powers,axp20x-usb-power-supply: add AXP717

In reply to Chris Morgan

From: Chris Morgan <[email protected]>

Add binding for the AXP717 USB power supply.

---
 .../bindings/power/supply/x-powers,axp20x-usb-power-supply.yaml  | 1 +
 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/power/supply/x-powers,axp20x-usb-power-supply.yaml +1 -0
index 34b7959d6772..a50c3bafa707 100644
@@ -26,6 +26,7 @@ properties:
           - x-powers,axp202-usb-power-supply
           - x-powers,axp221-usb-power-supply
           - x-powers,axp223-usb-power-supply
+          - x-powers,axp717-usb-power-supply
           - x-powers,axp813-usb-power-supply
       - items:
           - const: x-powers,axp803-usb-power-supply
Signature · 1 line
2.34.1
#4 lore raw

PATCH 3/4 power: supply: axp20x_usb_power: Add support for AXP717

In reply to Chris Morgan

From: Chris Morgan <[email protected]>

Add support for the AXP717. It does USB BC 1.2 detection similar to the AXP813, however it is otherwise very different from previous AXP devices.

---
 drivers/mfd/axp20x.c                    |  19 ++-
 drivers/power/supply/axp20x_usb_power.c | 216 +++++++++++++++++++++++-
 include/linux/mfd/axp20x.h              |  18 ++
 3 files changed, 248 insertions(+), 5 deletions(-)
drivers/mfd/axp20x.c +16 -3
index 16950c3206d7..d52d0c1c3367 100644
@@ -209,15 +209,20 @@ static const struct regmap_access_table axp313a_volatile_table = {
 };
 
 static const struct regmap_range axp717_writeable_ranges[] = {
-	regmap_reg_range(AXP717_MODULE_EN_CONTROL_2, AXP717_MODULE_EN_CONTROL_2),
-	regmap_reg_range(AXP717_BOOST_CONTROL, AXP717_BOOST_CONTROL),
+	regmap_reg_range(AXP717_PMU_FAULT, AXP717_MODULE_EN_CONTROL_1),
+	regmap_reg_range(AXP717_MIN_SYS_V_CONTROL, AXP717_BOOST_CONTROL),
 	regmap_reg_range(AXP717_IRQ0_EN, AXP717_IRQ4_EN),
 	regmap_reg_range(AXP717_IRQ0_STATE, AXP717_IRQ4_STATE),
 	regmap_reg_range(AXP717_DCDC_OUTPUT_CONTROL, AXP717_CPUSLDO_CONTROL),
+	regmap_reg_range(AXP717_ADC_CH_EN_CONTROL, AXP717_ADC_CH_EN_CONTROL),
+	regmap_reg_range(AXP717_ADC_DATA_SEL, AXP717_ADC_DATA_SEL),
 };
 
 static const struct regmap_range axp717_volatile_ranges[] = {
+	regmap_reg_range(AXP717_ON_INDICATE, AXP717_BC_DETECT),
 	regmap_reg_range(AXP717_IRQ0_STATE, AXP717_IRQ4_STATE),
+	regmap_reg_range(AXP717_ADC_VBAT_H, AXP717_ADC_ICHG_L),
+	regmap_reg_range(AXP717_ADC_DATA_H, AXP717_ADC_DATA_L),
 };
 
 static const struct regmap_access_table axp717_writeable_table = {
@@ -310,6 +315,11 @@ static const struct resource axp22x_usb_power_supply_resources[] = {
 	DEFINE_RES_IRQ_NAMED(AXP22X_IRQ_VBUS_REMOVAL, "VBUS_REMOVAL"),
 };
 
+static const struct resource axp717_usb_power_supply_resources[] = {
+	DEFINE_RES_IRQ_NAMED(AXP717_IRQ_VBUS_PLUGIN, "VBUS_PLUGIN"),
+	DEFINE_RES_IRQ_NAMED(AXP717_IRQ_VBUS_REMOVAL, "VBUS_REMOVAL"),
+};
+
 /* AXP803 and AXP813/AXP818 share the same interrupts */
 static const struct resource axp803_usb_power_supply_resources[] = {
 	DEFINE_RES_IRQ_NAMED(AXP803_IRQ_VBUS_PLUGIN, "VBUS_PLUGIN"),
@@ -424,7 +434,7 @@ static const struct regmap_config axp717_regmap_config = {
 	.val_bits = 8,
 	.wr_table = &axp717_writeable_table,
 	.volatile_table = &axp717_volatile_table,
-	.max_register = AXP717_CPUSLDO_CONTROL,
+	.max_register = AXP717_ADC_DATA_L,
 	.cache_type = REGCACHE_MAPLE,
 };
 
@@ -1026,6 +1036,9 @@ static struct mfd_cell axp313a_cells[] = {
 static struct mfd_cell axp717_cells[] = {
 	MFD_CELL_NAME("axp20x-regulator"),
 	MFD_CELL_RES("axp20x-pek", axp717_pek_resources),
+	MFD_CELL_OF("axp717-usb-power-supply",
+		    axp717_usb_power_supply_resources, NULL, 0, 0,
+		    "x-powers,axp717-usb-power-supply"),
 };
 
 static const struct resource axp288_adc_resources[] = {
drivers/power/supply/axp20x_usb_power.c +214 -2

343 lines not on this page · raw message

include/linux/mfd/axp20x.h +18 -0
index e0cd66bd3b6d..107808df33e9 100644
@@ -115,6 +115,12 @@ enum axp20x_variants {
 #define AXP313A_IRQ_STATE		0x21
 
 #define AXP717_ON_INDICATE		0x00
+#define AXP717_BC_DETECT		0x05
+#define AXP717_PMU_FAULT		0x08
+#define AXP717_MODULE_EN_CONTROL_1	0x0b
+#define AXP717_MIN_SYS_V_CONTROL	0x15
+#define AXP717_INPUT_VOL_LIMIT_CTRL	0x16
+#define AXP717_INPUT_CUR_LIMIT_CTRL	0x17
 #define AXP717_MODULE_EN_CONTROL_2	0x19
 #define AXP717_BOOST_CONTROL		0x1e
 #define AXP717_IRQ0_EN			0x40
@@ -147,6 +153,18 @@ enum axp20x_variants {
 #define AXP717_CLDO3_CONTROL		0x9d
 #define AXP717_CLDO4_CONTROL		0x9e
 #define AXP717_CPUSLDO_CONTROL		0x9f
+#define AXP717_ADC_CH_EN_CONTROL	0xc0
+#define AXP717_ADC_VBAT_H		0xc4
+#define AXP717_ADC_VBAT_L		0xc5
+#define AXP717_ADC_VBUS_H		0xc6
+#define AXP717_ADC_VBUS_L		0xc7
+#define AXP717_ADC_VSYS_H		0xc8
+#define AXP717_ADC_VSYS_L		0xc9
+#define AXP717_ADC_ICHG_H		0xca
+#define AXP717_ADC_ICHG_L		0xcb
+#define AXP717_ADC_DATA_SEL		0xcd
+#define AXP717_ADC_DATA_H		0xce
+#define AXP717_ADC_DATA_L		0xcf
 
 #define AXP806_STARTUP_SRC		0x00
 #define AXP806_CHIP_ID			0x03
Signature · 1 line
2.34.1
#5 lore raw

Re: [PATCH 3/4] power: supply: axp20x_usb_power: Add support for AXP717

Quoted 12 lines · Chris Morgan

From: Chris Morgan <[email protected]>

Add support for the AXP717. It does USB BC 1.2 detection similar to the AXP813, however it is otherwise very different from previous AXP devices.

---

drivers/power/supply/axp20x_usb_power.c +3 -0
+static int axp717_usb_init(struct axp20x_usb_power *power)
+{
+	int ret;

drivers/power/supply/axp20x_usb_power.c static int axp20x_usb_power_get_property(struct power_supply *psy, · line 391

Quoted 10 lines
drivers/power/supply/axp20x_usb_power.c +10 -0
+
+	ret = regmap_update_bits(power->regmap, AXP717_ADC_CH_EN_CONTROL,
+				 AXP717_ADC_EN_VSYS_VOLT |
+				 AXP717_ADC_EN_VBUS_VOLT,
+				 AXP717_ADC_EN_VSYS_VOLT |
+				 AXP717_ADC_EN_VBUS_VOLT);
+	if (ret)
+		return ret;
+
+	return 0;

This is a bit silly.

Quoted 6 lines
drivers/power/supply/axp20x_usb_power.c +2 -0
+}
+
  static int axp20x_usb_power_set_voltage_min(struct axp20x_usb_power *power,
  					    int intval)
  {

drivers/power/supply/axp20x_usb_power.c static int axp20x_usb_power_set_voltage_min(struct axp20x_usb_power *power, · line 425

Quoted 9 lines
drivers/power/supply/axp20x_usb_power.c +6 -0
@@ -307,6 +417,20 @@ static int axp20x_usb_power_set_voltage_min(struct axp20x_usb_power *power,
  	return -EINVAL;
  }
 
+static int axp717_usb_power_set_voltage_min(struct axp20x_usb_power *power,
+					    int intval)
+{
+	int val;
+
+	if (intval < 3880000 || intval > 5080000)

Do you really want raw numbers here?

[..]

Quoted 8 lines
drivers/power/supply/axp20x_usb_power.c +8 -0
+static int axp717_usb_power_set_property(struct power_supply *psy,
+					 enum power_supply_property psp,
+					 const union power_supply_propval *val)
+{
+	struct axp20x_usb_power *power = power_supply_get_drvdata(psy);
+
+	switch (psp) {
+	case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:

drivers/power/supply/axp20x_usb_power.c static int axp20x_usb_power_set_property(struct power_supply *psy, · line 524

Quoted 10 lines
drivers/power/supply/axp20x_usb_power.c +10 -0
+		return axp717_usb_power_set_input_current_limit(power, val->intval);
+
+	case POWER_SUPPLY_PROP_VOLTAGE_MIN:
+		return axp717_usb_power_set_voltage_min(power, val->intval);
+
+	default:
+		return -EINVAL;
+	}
+
+	return -EINVAL;

This is also a bit silly.

Regards
Oliver

#6 lore raw

Re: [PATCH 3/4] power: supply: axp20x_usb_power: Add support for AXP717

Quoted 12 lines · Oliver Neukum
Quoted 8 lines · Chris Morgan

From: Chris Morgan <[email protected]>

Add support for the AXP717. It does USB BC 1.2 detection similar to the AXP813, however it is otherwise very different from previous AXP devices.

---

Quoted 15 lines

drivers/power/supply/axp20x_usb_power.c static int axp20x_usb_power_get_property(struct power_supply *psy, · line 391

Quoted 13 lines
drivers/power/supply/axp20x_usb_power.c +13 -0
+static int axp717_usb_init(struct axp20x_usb_power *power)
+{
+	int ret;
+
+	ret = regmap_update_bits(power->regmap, AXP717_ADC_CH_EN_CONTROL,
+				 AXP717_ADC_EN_VSYS_VOLT |
+				 AXP717_ADC_EN_VBUS_VOLT,
+				 AXP717_ADC_EN_VSYS_VOLT |
+				 AXP717_ADC_EN_VBUS_VOLT);
+	if (ret)
+		return ret;
+
+	return 0;

This is a bit silly.

Agreed, I'll fix.

Quoted 18 lines
Quoted 7 lines
drivers/power/supply/axp20x_usb_power.c +2 -0
+}
+
  static int axp20x_usb_power_set_voltage_min(struct axp20x_usb_power *power,
  					    int intval)
  {

drivers/power/supply/axp20x_usb_power.c static int axp20x_usb_power_set_voltage_min(struct axp20x_usb_power *power, · line 424

Quoted 8 lines
drivers/power/supply/axp20x_usb_power.c +6 -0
@@ -307,6 +417,20 @@ static int axp20x_usb_power_set_voltage_min(struct axp20x_usb_power *power,
  	return -EINVAL;
  }
+static int axp717_usb_power_set_voltage_min(struct axp20x_usb_power *power,
+					    int intval)
+{
+	int val;
+
+	if (intval < 3880000 || intval > 5080000)

Do you really want raw numbers here?

Raw numbers are used throughout the driver, but it probably makes sense to document *why* these numbers are here and what they mean, so I'll do that.

Quoted 13 lines

[..]

Quoted 12 lines
drivers/power/supply/axp20x_usb_power.c +12 -0
+static int axp717_usb_power_set_property(struct power_supply *psy,
+					 enum power_supply_property psp,
+					 const union power_supply_propval *val)
+{
+	struct axp20x_usb_power *power = power_supply_get_drvdata(psy);
+
+	switch (psp) {
+	case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
+		return axp717_usb_power_set_input_current_limit(power, val->intval);
+
+	case POWER_SUPPLY_PROP_VOLTAGE_MIN:
+		return axp717_usb_power_set_voltage_min(power, val->intval);
Quoted 8 lines

drivers/power/supply/axp20x_usb_power.c static int axp20x_usb_power_set_property(struct power_supply *psy, · line 524

Quoted 6 lines
drivers/power/supply/axp20x_usb_power.c +6 -0
+
+	default:
+		return -EINVAL;
+	}
+
+	return -EINVAL;

This is also a bit silly.

That's how it's done above, but I might as well just remove the default statement so it returns -EINVAL if neither of the other two conditions aren't true.

Quoted 4 lines

Regards
Oliver

I'll resubmit with the changes mentioned above.

Thank you,
Chris

A message that is not in the archive (sent off-list or not yet received): [email protected]

#8 lore raw

Re: [PATCH 3/4] power: supply: axp20x_usb_power: Add support for AXP717

Quoted 81 lines · Chris Morgan
Quoted 12 lines · Oliver Neukum
Quoted 8 lines · Chris Morgan

From: Chris Morgan <[email protected]>

Add support for the AXP717. It does USB BC 1.2 detection similar to the AXP813, however it is otherwise very different from previous AXP devices.

---

Quoted 15 lines

drivers/power/supply/axp20x_usb_power.c static int axp20x_usb_power_get_property(struct power_supply *psy, · line 391

Quoted 13 lines
drivers/power/supply/axp20x_usb_power.c +13 -0
+static int axp717_usb_init(struct axp20x_usb_power *power)
+{
+	int ret;
+
+	ret = regmap_update_bits(power->regmap, AXP717_ADC_CH_EN_CONTROL,
+				 AXP717_ADC_EN_VSYS_VOLT |
+				 AXP717_ADC_EN_VBUS_VOLT,
+				 AXP717_ADC_EN_VSYS_VOLT |
+				 AXP717_ADC_EN_VBUS_VOLT);
+	if (ret)
+		return ret;
+
+	return 0;

This is a bit silly.

Agreed, I'll fix.

Quoted 18 lines
Quoted 7 lines
drivers/power/supply/axp20x_usb_power.c +2 -0
+}
+
  static int axp20x_usb_power_set_voltage_min(struct axp20x_usb_power *power,
  					    int intval)
  {

drivers/power/supply/axp20x_usb_power.c static int axp20x_usb_power_set_voltage_min(struct axp20x_usb_power *power, · line 424

Quoted 8 lines
drivers/power/supply/axp20x_usb_power.c +6 -0
@@ -307,6 +417,20 @@ static int axp20x_usb_power_set_voltage_min(struct axp20x_usb_power *power,
  	return -EINVAL;
  }
+static int axp717_usb_power_set_voltage_min(struct axp20x_usb_power *power,
+					    int intval)
+{
+	int val;
+
+	if (intval < 3880000 || intval > 5080000)

Do you really want raw numbers here?

Raw numbers are used throughout the driver, but it probably makes sense to document *why* these numbers are here and what they mean, so I'll do that.

Quoted 13 lines

[..]

Quoted 12 lines
drivers/power/supply/axp20x_usb_power.c +12 -0
+static int axp717_usb_power_set_property(struct power_supply *psy,
+					 enum power_supply_property psp,
+					 const union power_supply_propval *val)
+{
+	struct axp20x_usb_power *power = power_supply_get_drvdata(psy);
+
+	switch (psp) {
+	case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
+		return axp717_usb_power_set_input_current_limit(power, val->intval);
+
+	case POWER_SUPPLY_PROP_VOLTAGE_MIN:
+		return axp717_usb_power_set_voltage_min(power, val->intval);
Quoted 8 lines

drivers/power/supply/axp20x_usb_power.c static int axp20x_usb_power_set_property(struct power_supply *psy, · line 524

Quoted 6 lines
drivers/power/supply/axp20x_usb_power.c +6 -0
+
+	default:
+		return -EINVAL;
+	}
+
+	return -EINVAL;

This is also a bit silly.

That's how it's done above, but I might as well just remove the default statement so it returns -EINVAL if neither of the other two conditions aren't true.

Quoted 1 line
Quoted 5 lines
Quoted 3 lines

Regards
Oliver

I'll resubmit with the changes mentioned above.

I'm going to go back to the drawing board with this, so for now I'm withdrawing this patch series. Basically moving on to the next logical step of working with the battery it became obvious I should have done this using an ADC controller just like the existing axp usb and battery drivers. So I'll start with that and then resubmit a redone version of this once I have the ADC code in place.

Thank you,
Chris.

Quoted 3 lines

Thank you,
Chris

#9 lore raw

PATCH 4/4 arm64: dts: allwinner: Anbernic RG35XX: add AXP717 USB power

In reply to Chris Morgan

From: Chris Morgan <[email protected]>

Add the necessary node for the USB power driver and bind it to the OTG port.

---
 .../boot/dts/allwinner/sun50i-h700-anbernic-rg35xx-2024.dts  | 5 +++++
 1 file changed, 5 insertions(+)
arch/arm64/boot/dts/allwinner/sun50i-h700-anbernic-rg35xx-2024.dts +5 -0
index ee30584b6ad7..96a43d55baab 100644
@@ -307,6 +307,10 @@ reg_cpusldo: cpusldo {
 				/* unused */
 			};
 		};
+
+		usb_power: usb-power {
+			compatible = "x-powers,axp717-usb-power-supply";
+		};
 	};
 };
 
@@ -323,5 +327,6 @@ &usbotg {
 };
 
 &usbphy {
+	usb0_vbus_power-supply = <&usb_power>;
 	status = "okay";
 };
Signature · 1 line
2.34.1