regulator: tps65219: Add support for TPS65215 regulator resources
authorShree Ramamoorthy <s-ramamoorthy@ti.com>
Fri, 25 Apr 2025 20:57:34 +0000 (15:57 -0500)
committerMark Brown <broonie@kernel.org>
Thu, 1 May 2025 20:39:04 +0000 (05:39 +0900)
Isolate all changes involving TPS65215 regulator desc and range resources.

- 'chipid' will identify which PMIC to support, and the corresponding
  chip_data struct element to use in probe(). The chip_data struct is
  helpful for any new PMICs added to this driver. The goal is to add future
  PMIC info to necessary structs and minimize probe() function edits.

- The probe() will now loop through common (overlapping) regulators first,
  then device-specific structs identified in the chip_data struct.

- Add TI TPS65215 PMIC to the existing platform_device_id struct, so the
  regulator probe() can handle which PMIC chip_data information to use.

Signed-off-by: Shree Ramamoorthy <s-ramamoorthy@ti.com>
Link: https://patch.msgid.link/20250425205736.76433-3-s-ramamoorthy@ti.com
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/regulator/Kconfig
drivers/regulator/tps65219-regulator.c

index ad37f274dd8e0307b01bf13c62e580ad059f6ba8..8180e56aa5a08f8ea591c5021fbffdc5803bf5ac 100644 (file)
@@ -1590,10 +1590,11 @@ config REGULATOR_TPS65219
        tristate "TI TPS65219 Power regulators"
        depends on MFD_TPS65219 && OF
        help
-         This driver supports TPS65219 voltage regulator chips.
+         This driver supports TPS65219 series and TPS65215 voltage regulator chips.
          TPS65219 series of PMICs have 3 single phase BUCKs & 4 LDOs
-         voltage regulators. It supports software based voltage control
-         for different voltage domains.
+         voltage regulators.
+         TPS65215 PMIC has 3 single phase BUCKs & 2 LDOs.
+         Both PMICs support software based voltage control for different voltage domains.
 
 config REGULATOR_TPS6594
        tristate "TI TPS6594 Power regulators"
index 3c7c3a6d4c15ffe327ea454e15b3baa0d54e5428..b95fb676e5d2a78571c38f7718530531ff2cda82 100644 (file)
@@ -1,10 +1,9 @@
 // SPDX-License-Identifier: GPL-2.0
 //
-// tps65219-regulator.c
-//
-// Regulator driver for TPS65219 PMIC
+// Regulator driver for TPS65215/TPS65219 PMIC
 //
 // Copyright (C) 2022 BayLibre Incorporated - https://www.baylibre.com/
+// Copyright (C) 2024 Texas Instruments Incorporated - https://www.ti.com/
 //
 // This implementation derived from tps65218 authored by
 // "J Keerthy <j-keerthy@ti.com>"
@@ -130,6 +129,11 @@ static const struct linear_range ldo_1_range[] = {
        REGULATOR_LINEAR_RANGE(3400000, 0x38, 0x3f, 0),
 };
 
+static const struct linear_range tps65215_ldo_2_range[] = {
+       REGULATOR_LINEAR_RANGE(1200000, 0x0, 0xC, 50000),
+       REGULATOR_LINEAR_RANGE(3300000, 0x36, 0x3F, 0),
+};
+
 static const struct linear_range tps65219_ldo_2_range[] = {
        REGULATOR_LINEAR_RANGE(600000, 0x0, 0x37, 50000),
        REGULATOR_LINEAR_RANGE(3400000, 0x38, 0x3f, 0),
@@ -221,7 +225,7 @@ static const struct regulator_ops ldos_3_4_ops = {
        .map_voltage            = regulator_map_voltage_linear_range,
 };
 
-static const struct regulator_desc regulators[] = {
+static const struct regulator_desc common_regs[] = {
        TPS65219_REGULATOR("BUCK1", "buck1", TPS65219_BUCK_1,
                           REGULATOR_VOLTAGE, bucks_ops, 64,
                           TPS65219_REG_BUCK1_VOUT,
@@ -250,6 +254,20 @@ static const struct regulator_desc regulators[] = {
                           TPS65219_REG_ENABLE_CTRL,
                           TPS65219_ENABLE_LDO1_EN_MASK, 0, 0, ldo_1_range,
                           2, 0, 0, NULL, 0, TPS65219_LDOS_BYP_CONFIG_MASK),
+};
+
+static const struct regulator_desc tps65215_regs[] = {
+       // TPS65215's LDO2 is the same as TPS65219's LDO3
+       TPS65219_REGULATOR("LDO2", "ldo2", TPS65215_LDO_2,
+                          REGULATOR_VOLTAGE, ldos_3_4_ops, 64,
+                          TPS65215_REG_LDO2_VOUT,
+                          TPS65219_BUCKS_LDOS_VOUT_VSET_MASK,
+                          TPS65219_REG_ENABLE_CTRL,
+                          TPS65215_ENABLE_LDO2_EN_MASK, 0, 0, tps65215_ldo_2_range,
+                          3, 0, 0, NULL, 0, 0),
+};
+
+static const struct regulator_desc tps65219_regs[] = {
        TPS65219_REGULATOR("LDO2", "ldo2", TPS65219_LDO_2,
                           REGULATOR_VOLTAGE, ldos_1_2_ops, 64,
                           TPS65219_REG_LDO2_VOUT,
@@ -292,28 +310,65 @@ static irqreturn_t tps65219_regulator_irq_handler(int irq, void *data)
        return IRQ_HANDLED;
 }
 
+struct tps65219_chip_data {
+       size_t rdesc_size;
+       size_t common_rdesc_size;
+       const struct regulator_desc *rdesc;
+       const struct regulator_desc *common_rdesc;
+};
+
+static struct tps65219_chip_data chip_info_table[] = {
+       [TPS65215] = {
+               .rdesc = tps65215_regs,
+               .rdesc_size = ARRAY_SIZE(tps65215_regs),
+               .common_rdesc = common_regs,
+               .common_rdesc_size = ARRAY_SIZE(common_regs),
+       },
+       [TPS65219] = {
+               .rdesc = tps65219_regs,
+               .rdesc_size = ARRAY_SIZE(tps65219_regs),
+               .common_rdesc = common_regs,
+               .common_rdesc_size = ARRAY_SIZE(common_regs),
+       },
+};
+
 static int tps65219_regulator_probe(struct platform_device *pdev)
 {
-       struct tps65219 *tps = dev_get_drvdata(pdev->dev.parent);
+       struct tps65219_regulator_irq_data *irq_data;
+       struct tps65219_regulator_irq_type *irq_type;
+
+       struct tps65219_chip_data *pmic;
        struct regulator_dev *rdev;
-       struct regulator_config config = { };
-       int i;
        int error;
        int irq;
-       struct tps65219_regulator_irq_data *irq_data;
-       struct tps65219_regulator_irq_type *irq_type;
+       int i;
+
+       struct tps65219 *tps = dev_get_drvdata(pdev->dev.parent);
+       struct regulator_config config = { };
+       enum pmic_id chip = platform_get_device_id(pdev)->driver_data;
+
+       pmic = &chip_info_table[chip];
 
        config.dev = tps->dev;
        config.driver_data = tps;
        config.regmap = tps->regmap;
 
-       for (i = 0; i < ARRAY_SIZE(regulators); i++) {
-               rdev = devm_regulator_register(&pdev->dev, &regulators[i],
+       for (i = 0; i <  pmic->common_rdesc_size; i++) {
+               rdev = devm_regulator_register(&pdev->dev, &pmic->common_rdesc[i],
+                                              &config);
+               if (IS_ERR(rdev))
+                       return dev_err_probe(tps->dev, PTR_ERR(rdev),
+                                             "Failed to register %s regulator\n",
+                                             pmic->common_rdesc[i].name);
+       }
+
+       for (i = 0; i <  pmic->rdesc_size; i++) {
+               rdev = devm_regulator_register(&pdev->dev, &pmic->rdesc[i],
                                               &config);
                if (IS_ERR(rdev))
                        return dev_err_probe(tps->dev, PTR_ERR(rdev),
-                                       "Failed to register %s regulator\n",
-                                       regulators[i].name);
+                                            "Failed to register %s regulator\n",
+                                            pmic->rdesc[i].name);
        }
 
        irq_data = devm_kmalloc(tps->dev,
@@ -349,7 +404,8 @@ static int tps65219_regulator_probe(struct platform_device *pdev)
 }
 
 static const struct platform_device_id tps65219_regulator_id_table[] = {
-       { "tps65219-regulator", },
+       { "tps65215-regulator", TPS65215 },
+       { "tps65219-regulator", TPS65219 },
        { /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(platform, tps65219_regulator_id_table);
@@ -366,5 +422,5 @@ static struct platform_driver tps65219_regulator_driver = {
 module_platform_driver(tps65219_regulator_driver);
 
 MODULE_AUTHOR("Jerome Neanne <j-neanne@baylibre.com>");
-MODULE_DESCRIPTION("TPS65219 voltage regulator driver");
+MODULE_DESCRIPTION("TPS65215/TPS65219 voltage regulator driver");
 MODULE_LICENSE("GPL");