[PATCH 2/6] power: pmic: s2mps11: add support for allowing multiple device variants

Kaustabh Chakraborty kauschluss at disroot.org
Fri Oct 17 17:28:17 CEST 2025


There are multiple PMICs by Samsung which are similar in architecture
(register layout, interface, etc.) and is possible to be driven by a
single driver. Variant specific code and data should be managed properly
in the driver.

And an enum which describes all supported variants. Pass the enum as the
device driver data. Introduce a switch-case block on the enum for any
variant specific code.

Signed-off-by: Kaustabh Chakraborty <kauschluss at disroot.org>
---
 drivers/power/pmic/s2mps11.c | 21 ++++++++++++++++++---
 include/power/s2mps11.h      |  5 +++++
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/drivers/power/pmic/s2mps11.c b/drivers/power/pmic/s2mps11.c
index 23c96da3fdf485e171252f76f54a8778fa8bb20a..51c98afb17b2b1a790860419b55e211b0c533685 100644
--- a/drivers/power/pmic/s2mps11.c
+++ b/drivers/power/pmic/s2mps11.c
@@ -13,7 +13,7 @@
 #include <power/pmic.h>
 #include <power/s2mps11.h>
 
-static const struct pmic_child_info pmic_children_info[] = {
+static const struct pmic_child_info s2mps11_pmic_children_info[] = {
 	{ .prefix = S2MPS11_OF_LDO_PREFIX, .driver = S2MPS11_LDO_DRIVER },
 	{ .prefix = S2MPS11_OF_BUCK_PREFIX, .driver = S2MPS11_BUCK_DRIVER },
 	{ },
@@ -21,7 +21,12 @@ static const struct pmic_child_info pmic_children_info[] = {
 
 static int s2mps11_reg_count(struct udevice *dev)
 {
-	return S2MPS11_REG_COUNT;
+	switch (dev_get_driver_data(dev)) {
+	case VARIANT_S2MPS11:
+		return S2MPS11_REG_COUNT;
+	default:
+		return -EINVAL;
+	}
 }
 
 static int s2mps11_write(struct udevice *dev, uint reg, const uint8_t *buff,
@@ -51,6 +56,7 @@ static int s2mps11_bind(struct udevice *dev)
 {
 	ofnode regulators_node;
 	int children;
+	const struct pmic_child_info *pmic_children_info;
 
 	regulators_node = dev_read_subnode(dev, "regulators");
 	if (!ofnode_valid(regulators_node)) {
@@ -61,6 +67,15 @@ static int s2mps11_bind(struct udevice *dev)
 
 	debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
 
+	switch (dev_get_driver_data(dev)) {
+	case VARIANT_S2MPS11:
+		pmic_children_info = s2mps11_pmic_children_info;
+		break;
+	default:
+		debug("%s: unknown device type\n", __func__);
+		return -EINVAL;
+	}
+
 	children = pmic_bind_children(dev, regulators_node, pmic_children_info);
 	if (!children)
 		debug("%s: %s - no child found\n", __func__, dev->name);
@@ -75,7 +90,7 @@ static struct dm_pmic_ops s2mps11_ops = {
 };
 
 static const struct udevice_id s2mps11_ids[] = {
-	{ .compatible = "samsung,s2mps11-pmic" },
+	{ .compatible = "samsung,s2mps11-pmic", .data = VARIANT_S2MPS11 },
 	{ }
 };
 
diff --git a/include/power/s2mps11.h b/include/power/s2mps11.h
index 22b38fff7032b510d646dac4e7f00723727d8d06..c08bea5a516a8a48e8ffea993e28df158da026a3 100644
--- a/include/power/s2mps11.h
+++ b/include/power/s2mps11.h
@@ -161,4 +161,9 @@ enum {
 	OP_ON,
 };
 
+enum {
+	VARIANT_NONE,
+	VARIANT_S2MPS11,
+};
+
 #endif

-- 
2.51.0



More information about the U-Boot mailing list