Skip to contentSkip to conversation

Add PMI8998 VBUS Regulator Support

PATCH In review James A. MacInnes 4 participants 9 messages Feb 11, 2025 – Feb 12, 2025

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

cover Add PMI8998 VBUS Regulator Support

Hello,

This patch series adds support for the PMI8998 VBUS regulator in the Qualcomm USB VBUS regulator driver and the device tree. These changes enable proper VBUS current limit configuration and ensure compatibility across multiple Qualcomm PMICs.

Summary of Changes:
- Patch 1/3: Updates the Device Tree Schema bindings to include "qcom,pmi8998-vbus-reg" for PMI8998 support.
- Patch 2/3: Extends the Qualcomm USB VBUS regulator driver to support PMI8998, dynamically configuring the regulator based on the PMIC type.
- Patch 3/3: Adds the VBUS regulator node to pmi8998.dtsi, enabling USB Type-C VBUS support.

Motivation:
A long time ago, in a conference room far, far away, I promised that USB Type-C capability would work on the SDM845 when we chose this chip for our instrument.

That day never came.

So I wrote it myself.

This patch series finally adds the missing support for USB Type-C VBUS regulation on PMI8998-based platforms. Future generations of engineers will no longer have to mutter "Why doesn’t this work?" while digging through device trees.

Kernel Version & Testing:
- These patches were developed and tested on Linux 6.13.
- Attempting to run Linux 6.14-rc2 on our Lantronix SOM resulted in a crash, making it unsuitable for validation.
- Validation was performed using a modified device tree, confirming proper regulator configuration.
- No regressions were observed on existing PMIC configurations.

Next Steps:
If there are any suggestions or required changes, please let me know. I will be happy to revise and address any concerns.

Thanks again,
James A. MacInnes
[email protected]

James A. MacInnes (3):
regulator: qcom_usb_vbus: Update DTS binding for PMI8998 support
regulator: qcom_usb_vbus: Add support for PMI8998 VBUS
arm64: boot: dts: pmi8998.dtsi: Add VBUS regulator

 .../regulator/qcom,usb-vbus-regulator.yaml    |  1 +
 arch/arm64/boot/dts/qcom/pmi8998.dtsi         |  6 ++++
 drivers/regulator/qcom_usb_vbus-regulator.c   | 33 ++++++++++++++++---
 3 files changed, 35 insertions(+), 5 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/3 regulator: qcom_usb_vbus: Update DTS binding for PMI8998 support

Update the binding in Documentation/devicetree/bindings/regulator/qcom,usb-vbus-regulator.yaml to include the compatible string "qcom,pmi8998-vbus-reg". This change adds PMI8998 support to the Qualcomm USB VBUS regulator bindings.

With this patch, device trees that describe a PMI8998 USB VBUS regulator using the "qcom,pmi8998-vbus-reg" compatible string will now validate correctly. This is required to support hardware based on PMI8998, which has different current limit tables and other regulator-specific configurations.

Tested: The next patch contains the driver and has been tested with Lantronix SOM.

---
 .../devicetree/bindings/regulator/qcom,usb-vbus-regulator.yaml   | 1 +
 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/regulator/qcom,usb-vbus-regulator.yaml +1 -0
index fcefc722ee2a..6092560e9048 100644
@@ -22,6 +22,7 @@ properties:
     oneOf:
       - enum:
           - qcom,pm8150b-vbus-reg
+          - qcom,pmi8998-vbus-reg
       - items:
           - enum:
               - qcom,pm4125-vbus-reg
Signature · 1 line
2.43.0
#2 lore raw

PATCH 2/3 regulator: qcom_usb_vbus: Add support for PMI8998 VBUS

In reply to James A. MacInnes

This patch extends the Qualcomm USB VBUS regulator driver to support PMI8998 PMIC alongside the existing support for PM8150B.

Key changes:
- Added current limit tables specific to PMI8998.
- Dynamically configure the VBUS regulator based on the PMIC type.
- Updated debug messages to reflect successful initialization for supported PMICs.
- Changed registration log message

These changes ensure proper VBUS current limit configuration and compatibility across multiple Qualcomm PMICs.

---
 drivers/regulator/qcom_usb_vbus-regulator.c | 33 +++++++++++++++++----
 1 file changed, 28 insertions(+), 5 deletions(-)
drivers/regulator/qcom_usb_vbus-regulator.c +28 -5
index cd94ed67621f..bfcb77698ba2 100644
@@ -20,10 +20,15 @@
 #define OTG_CFG				0x53
 #define OTG_EN_SRC_CFG			BIT(1)
 
-static const unsigned int curr_table[] = {
+static const unsigned int curr_table_pm8150b[] = {
 	500000, 1000000, 1500000, 2000000, 2500000, 3000000,
 };
 
+static const unsigned int curr_table_pmi8998[] = {
+	250000, 500000, 750000, 1000000,
+	1250000, 1500000, 1750000, 2000000,
+};
+
 static const struct regulator_ops qcom_usb_vbus_reg_ops = {
 	.enable = regulator_enable_regmap,
 	.disable = regulator_disable_regmap,
@@ -37,8 +42,8 @@ static struct regulator_desc qcom_usb_vbus_rdesc = {
 	.ops = &qcom_usb_vbus_reg_ops,
 	.owner = THIS_MODULE,
 	.type = REGULATOR_VOLTAGE,
-	.curr_table = curr_table,
-	.n_current_limits = ARRAY_SIZE(curr_table),
+	.curr_table = NULL,
+	.n_current_limits = 0,
 };
 
 static int qcom_usb_vbus_regulator_probe(struct platform_device *pdev)
@@ -50,6 +55,7 @@ static int qcom_usb_vbus_regulator_probe(struct platform_device *pdev)
 	struct regulator_init_data *init_data;
 	int ret;
 	u32 base;
+	const char *pmic_type;
 
 	ret = of_property_read_u32(dev->of_node, "reg", &base);
 	if (ret < 0) {
@@ -68,6 +74,19 @@ static int qcom_usb_vbus_regulator_probe(struct platform_device *pdev)
 	if (!init_data)
 		return -ENOMEM;
 
+	// Determine PMIC type
+	pmic_type = of_device_get_match_data(dev);
+	if (pmic_type && strcmp(pmic_type, "pmi8998") == 0) {
+		qcom_usb_vbus_rdesc.curr_table = curr_table_pmi8998;
+		qcom_usb_vbus_rdesc.n_current_limits =
+			ARRAY_SIZE(curr_table_pmi8998);
+	} else if (pmic_type && strcmp(pmic_type, "pm8150b") == 0) {
+		qcom_usb_vbus_rdesc.curr_table = curr_table_pm8150b;
+		qcom_usb_vbus_rdesc.n_current_limits =
+			ARRAY_SIZE(curr_table_pm8150b);
+	} else {
+		return -ENODEV;
+	}
 	qcom_usb_vbus_rdesc.enable_reg = base + CMD_OTG;
 	qcom_usb_vbus_rdesc.enable_mask = OTG_EN;
 	qcom_usb_vbus_rdesc.csel_reg = base + OTG_CURRENT_LIMIT_CFG;
@@ -80,18 +99,22 @@ static int qcom_usb_vbus_regulator_probe(struct platform_device *pdev)
 	rdev = devm_regulator_register(dev, &qcom_usb_vbus_rdesc, &config);
 	if (IS_ERR(rdev)) {
 		ret = PTR_ERR(rdev);
-		dev_err(dev, "not able to register vbus reg %d\n", ret);
+		dev_err(dev, "Failed to register vbus reg %d\n", ret);
 		return ret;
 	}
 
 	/* Disable HW logic for VBUS enable */
 	regmap_update_bits(regmap, base + OTG_CFG, OTG_EN_SRC_CFG, 0);
 
+	dev_info(dev, "Registered QCOM %s VBUS regulator\n",
+		 pmic_type);
+
 	return 0;
 }
 
 static const struct of_device_id qcom_usb_vbus_regulator_match[] = {
-	{ .compatible = "qcom,pm8150b-vbus-reg" },
+	{ .compatible = "qcom,pm8150b-vbus-reg", .data = "pm8150b" },
+	{ .compatible = "qcom,pmi8998-vbus-reg", .data = "pmi8998" },
 	{ }
 };
 MODULE_DEVICE_TABLE(of, qcom_usb_vbus_regulator_match);
Signature · 1 line
2.43.0
maintainer
#3 lore raw

Re: [PATCH 2/3] regulator: qcom_usb_vbus: Add support for PMI8998 VBUS

drivers/regulator/qcom_usb_vbus-regulator.c static struct regulator_desc qcom_usb_vbus_rdesc = { · line 46

Quoted 4 lines · James A. MacInnes
drivers/regulator/qcom_usb_vbus-regulator.c +2 -2
-	.curr_table = curr_table,
-	.n_current_limits = ARRAY_SIZE(curr_table),
+	.curr_table = NULL,
+	.n_current_limits = 0,

Things that are not initialised in static variables are implicitly 0.

drivers/regulator/qcom_usb_vbus-regulator.c static int qcom_usb_vbus_regulator_probe(struct platform_device *pdev) · line 89

Quoted 13 lines
drivers/regulator/qcom_usb_vbus-regulator.c +13 -0
+	// Determine PMIC type
+	pmic_type = of_device_get_match_data(dev);
+	if (pmic_type && strcmp(pmic_type, "pmi8998") == 0) {
+		qcom_usb_vbus_rdesc.curr_table = curr_table_pmi8998;
+		qcom_usb_vbus_rdesc.n_current_limits =
+			ARRAY_SIZE(curr_table_pmi8998);
+	} else if (pmic_type && strcmp(pmic_type, "pm8150b") == 0) {
+		qcom_usb_vbus_rdesc.curr_table = curr_table_pm8150b;
+		qcom_usb_vbus_rdesc.n_current_limits =
+			ARRAY_SIZE(curr_table_pm8150b);
+	} else {
+		return -ENODEV;
+	}

Instead of modifying the static variable (which you had to remove const from...) the driver should take a copy of it and modify that, that way nothing goes wrong if we get two of the devices or anything.

drivers/regulator/qcom_usb_vbus-regulator.c static int qcom_usb_vbus_regulator_probe(struct platform_device *pdev) · line 117

Quoted 4 lines

static const struct of_device_id qcom_usb_vbus_regulator_match[] = {

drivers/regulator/qcom_usb_vbus-regulator.c +2 -1
-	{ .compatible = "qcom,pm8150b-vbus-reg" },
+	{ .compatible = "qcom,pm8150b-vbus-reg", .data = "pm8150b" },
+	{ .compatible = "qcom,pmi8998-vbus-reg", .data = "pmi8998" },

The driver data should be a pointer to some quirk data for the device, if you want a string to identify the device that should be a member of the quirk data struct. This will make the use of the data safer and more idiomatic.

#4 lore raw

Re: [PATCH 2/3] regulator: qcom_usb_vbus: Add support for PMI8998 VBUS

In reply to James A. MacInnes
Quoted 59 lines · James A. MacInnes

This patch extends the Qualcomm USB VBUS regulator driver to support PMI8998 PMIC alongside the existing support for PM8150B.

Key changes:
- Added current limit tables specific to PMI8998.
- Dynamically configure the VBUS regulator based on the PMIC type.
- Updated debug messages to reflect successful initialization for supported PMICs.
- Changed registration log message

These changes ensure proper VBUS current limit configuration and compatibility across multiple Qualcomm PMICs.

---
 drivers/regulator/qcom_usb_vbus-regulator.c | 33 +++++++++++++++++----
 1 file changed, 28 insertions(+), 5 deletions(-)
drivers/regulator/qcom_usb_vbus-regulator.c +9 -3
index cd94ed67621f..bfcb77698ba2 100644
@@ -20,10 +20,15 @@
 #define OTG_CFG				0x53
 #define OTG_EN_SRC_CFG			BIT(1)
 
-static const unsigned int curr_table[] = {
+static const unsigned int curr_table_pm8150b[] = {
 	500000, 1000000, 1500000, 2000000, 2500000, 3000000,
 };
 
+static const unsigned int curr_table_pmi8998[] = {
+	250000, 500000, 750000, 1000000,
+	1250000, 1500000, 1750000, 2000000,
+};
+
 static const struct regulator_ops qcom_usb_vbus_reg_ops = {
 	.enable = regulator_enable_regmap,
 	.disable = regulator_disable_regmap,
@@ -37,8 +42,8 @@ static struct regulator_desc qcom_usb_vbus_rdesc = {
 	.ops = &qcom_usb_vbus_reg_ops,
 	.owner = THIS_MODULE,
 	.type = REGULATOR_VOLTAGE,
-	.curr_table = curr_table,
-	.n_current_limits = ARRAY_SIZE(curr_table),
+	.curr_table = NULL,
+	.n_current_limits = 0,
 };
 
 static int qcom_usb_vbus_regulator_probe(struct platform_device *pdev)
@@ -50,6 +55,7 @@ static int qcom_usb_vbus_regulator_probe(struct platform_device *pdev)
 	struct regulator_init_data *init_data;
 	int ret;
 	u32 base;
+	const char *pmic_type;
 
 	ret = of_property_read_u32(dev->of_node, "reg", &base);
 	if (ret < 0) {

drivers/regulator/qcom_usb_vbus-regulator.c static int qcom_usb_vbus_regulator_probe(struct platform_device *pdev) · line 79

Quoted 6 lines
drivers/regulator/qcom_usb_vbus-regulator.c +3 -0
@@ -68,6 +74,19 @@ static int qcom_usb_vbus_regulator_probe(struct platform_device *pdev)
 	if (!init_data)
 		return -ENOMEM;
 
+	// Determine PMIC type
+	pmic_type = of_device_get_match_data(dev);
+	if (pmic_type && strcmp(pmic_type, "pmi8998") == 0) {

I think a traditional way is to define an enum and then use that enum values as match data. Or you can just add a struct with curr_table and get that as a match data.

Quoted 17 lines
drivers/regulator/qcom_usb_vbus-regulator.c +10 -0
+		qcom_usb_vbus_rdesc.curr_table = curr_table_pmi8998;
+		qcom_usb_vbus_rdesc.n_current_limits =
+			ARRAY_SIZE(curr_table_pmi8998);
+	} else if (pmic_type && strcmp(pmic_type, "pm8150b") == 0) {
+		qcom_usb_vbus_rdesc.curr_table = curr_table_pm8150b;
+		qcom_usb_vbus_rdesc.n_current_limits =
+			ARRAY_SIZE(curr_table_pm8150b);
+	} else {
+		return -ENODEV;
+	}
 	qcom_usb_vbus_rdesc.enable_reg = base + CMD_OTG;
 	qcom_usb_vbus_rdesc.enable_mask = OTG_EN;
 	qcom_usb_vbus_rdesc.csel_reg = base + OTG_CURRENT_LIMIT_CFG;
@@ -80,18 +99,22 @@ static int qcom_usb_vbus_regulator_probe(struct platform_device *pdev)
 	rdev = devm_regulator_register(dev, &qcom_usb_vbus_rdesc, &config);
 	if (IS_ERR(rdev)) {
 		ret = PTR_ERR(rdev);

drivers/regulator/qcom_usb_vbus-regulator.c static int qcom_usb_vbus_regulator_probe(struct platform_device *pdev) · line 110

Quoted 10 lines
drivers/regulator/qcom_usb_vbus-regulator.c +3 -1
-		dev_err(dev, "not able to register vbus reg %d\n", ret);
+		dev_err(dev, "Failed to register vbus reg %d\n", ret);
 		return ret;
 	}
 
 	/* Disable HW logic for VBUS enable */
 	regmap_update_bits(regmap, base + OTG_CFG, OTG_EN_SRC_CFG, 0);
 
+	dev_info(dev, "Registered QCOM %s VBUS regulator\n",
+		 pmic_type);

dev_dbg, the driver should be silent by default.

Quoted 14 lines
drivers/regulator/qcom_usb_vbus-regulator.c +3 -1
+
 	return 0;
 }
 
 static const struct of_device_id qcom_usb_vbus_regulator_match[] = {
-	{ .compatible = "qcom,pm8150b-vbus-reg" },
+	{ .compatible = "qcom,pm8150b-vbus-reg", .data = "pm8150b" },
+	{ .compatible = "qcom,pmi8998-vbus-reg", .data = "pmi8998" },
 	{ }
 };
 MODULE_DEVICE_TABLE(of, qcom_usb_vbus_regulator_match);
Signature · 1 line
2.43.0
Signature · 2 lines
With best wishes
Dmitry
maintainer
#5 lore raw

Re: [PATCH 2/3] regulator: qcom_usb_vbus: Add support for PMI8998 VBUS

Quoted 8 lines · Dmitry Baryshkov

drivers/regulator/qcom_usb_vbus-regulator.c static int qcom_usb_vbus_regulator_probe(struct platform_device *pdev) · line 79

Quoted 2 lines · James A. MacInnes
drivers/regulator/qcom_usb_vbus-regulator.c +2 -0
+	pmic_type = of_device_get_match_data(dev);
+	if (pmic_type && strcmp(pmic_type, "pmi8998") == 0) {

I think a traditional way is to define an enum and then use that enum values as match data. Or you can just add a struct with curr_table and get that as a match data.

Either approach works, yeah.

#6 lore raw

Re: [PATCH 2/3] regulator: qcom_usb_vbus: Add support for PMI8998 VBUS

In reply to James A. MacInnes
Quoted 28 lines · James A. MacInnes
drivers/regulator/qcom_usb_vbus-regulator.c +14 -1
+	// Determine PMIC type
+	pmic_type = of_device_get_match_data(dev);
+	if (pmic_type && strcmp(pmic_type, "pmi8998") == 0) {
+		qcom_usb_vbus_rdesc.curr_table = curr_table_pmi8998;
+		qcom_usb_vbus_rdesc.n_current_limits =
+			ARRAY_SIZE(curr_table_pmi8998);
+	} else if (pmic_type && strcmp(pmic_type, "pm8150b") == 0) {
+		qcom_usb_vbus_rdesc.curr_table = curr_table_pm8150b;
+		qcom_usb_vbus_rdesc.n_current_limits =
+			ARRAY_SIZE(curr_table_pm8150b);
+	} else {
+		return -ENODEV;
+	}
  	qcom_usb_vbus_rdesc.enable_reg = base + CMD_OTG;
  	qcom_usb_vbus_rdesc.enable_mask = OTG_EN;
  	qcom_usb_vbus_rdesc.csel_reg = base + OTG_CURRENT_LIMIT_CFG;
@@ -80,18 +99,22 @@ static int qcom_usb_vbus_regulator_probe(struct platform_device *pdev)
  	rdev = devm_regulator_register(dev, &qcom_usb_vbus_rdesc, &config);
  	if (IS_ERR(rdev)) {
  		ret = PTR_ERR(rdev);
-		dev_err(dev, "not able to register vbus reg %d\n", ret);
+		dev_err(dev, "Failed to register vbus reg %d\n", ret);
  		return ret;
  	}
 
  	/* Disable HW logic for VBUS enable */
  	regmap_update_bits(regmap, base + OTG_CFG, OTG_EN_SRC_CFG, 0);
 

drivers/regulator/qcom_usb_vbus-regulator.c static int qcom_usb_vbus_regulator_probe(struct platform_device *pdev) · line 117

Quoted 10 lines
drivers/regulator/qcom_usb_vbus-regulator.c +5 -1
+	dev_info(dev, "Registered QCOM %s VBUS regulator\n",
+		 pmic_type);
+
  	return 0;
  }
 
  static const struct of_device_id qcom_usb_vbus_regulator_match[] = {
-	{ .compatible = "qcom,pm8150b-vbus-reg" },
+	{ .compatible = "qcom,pm8150b-vbus-reg", .data = "pm8150b" },
+	{ .compatible = "qcom,pmi8998-vbus-reg", .data = "pmi8998" },

I think the other two said much the same thing but .data should point to the differentiator instead of being a string which you disjoin on and then hook your differentiated data.

i.e.

.data = &my_driver_specific_static_data_here.

---
bod

#7 lore raw

PATCH 3/3 arm64: boot: dts: pmi8998.dtsi: Add VBUS regulator

In reply to James A. MacInnes

This patch adds support for the USB Type-C VBUS regulator to the PMI8998 PMIC device tree.

Key changes:
- Defined the usb-vbus-regulator node for VBUS handling, enabling control over USB power delivery.

This addition enable USB Type-C VBUS support on sdm845 platforms.

---
 arch/arm64/boot/dts/qcom/pmi8998.dtsi | 6 ++++++
 1 file changed, 6 insertions(+)
arch/arm64/boot/dts/qcom/pmi8998.dtsi +6 -0
index cd3f0790fd42..8cb1d851b5a3 100644
@@ -29,6 +29,12 @@ pmi8998_charger: charger@1000 {
 			status = "disabled";
 		};
 
+		pmi8998_vbus: usb-vbus-regulator@1100 {
+			compatible = "qcom,pmi8998-vbus-reg";
+			status = "disabled";
+			reg = <0x1100>;
+		};
+
 		pmi8998_gpios: gpio@c000 {
 			compatible = "qcom,pmi8998-gpio", "qcom,spmi-gpio";
 			reg = <0xc000>;
Signature · 1 line
2.43.0
#8 lore raw

Re: [PATCH 3/3] arm64: boot: dts: pmi8998.dtsi: Add VBUS regulator

Quoted 2 lines · James A. MacInnes

This patch adds support for the USB Type-C VBUS regulator to the PMI8998 PMIC device tree.

"In order to enable USB Type-C VBUS support on the SDM845 platform add device node for the USB Vbus regulator to the PMI8998 PMIC device tree."

Drop the rest of the commit message.

Quoted 32 lines

Key changes:
- Defined the usb-vbus-regulator node for VBUS handling, enabling control over USB power delivery.

This addition enable USB Type-C VBUS support on sdm845 platforms.

---
 arch/arm64/boot/dts/qcom/pmi8998.dtsi | 6 ++++++
 1 file changed, 6 insertions(+)
arch/arm64/boot/dts/qcom/pmi8998.dtsi +6 -0
index cd3f0790fd42..8cb1d851b5a3 100644
@@ -29,6 +29,12 @@ pmi8998_charger: charger@1000 {
 			status = "disabled";
 		};
 
+		pmi8998_vbus: usb-vbus-regulator@1100 {
+			compatible = "qcom,pmi8998-vbus-reg";
+			status = "disabled";
+			reg = <0x1100>;
+		};
+
 		pmi8998_gpios: gpio@c000 {
 			compatible = "qcom,pmi8998-gpio", "qcom,spmi-gpio";
 			reg = <0xc000>;
Signature · 1 line
2.43.0
Signature · 2 lines
With best wishes
Dmitry