From 73a85502bd2a4373d82f638b1b4c3e1f79e394e3 Mon Sep 17 00:00:00 2001 From: Kaustabh Chakraborty Date: Fri, 17 Oct 2025 20:58:17 +0530 Subject: [PATCH] power: pmic: s2mps11: add support for allowing multiple device variants 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 Reviewed-by: Peng Fan Signed-off-by: Peng Fan --- 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 23c96da3fdf..51c98afb17b 100644 --- a/drivers/power/pmic/s2mps11.c +++ b/drivers/power/pmic/s2mps11.c @@ -13,7 +13,7 @@ #include #include -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 22b38fff703..c08bea5a516 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.47.3