diff mbox series

[v2,6/7] regulator: tps65215: Define probe() helper functions

Message ID 20250103230446.197597-7-s-ramamoorthy@ti.com
State New
Headers show
Series Add TI TPS65215 PMIC Regulator Support | expand

Commit Message

Shree Ramamoorthy Jan. 3, 2025, 11:04 p.m. UTC
Factor register_regulators() and request_irqs() out into smaller functions.
These 2 helper functions are used in the next restructure probe() patch to
go through the common (overlapping) regulators and irqs first, then the
device-specific structs identifed in the chip_data struct.

Signed-off-by: Shree Ramamoorthy <s-ramamoorthy@ti.com>
---
 drivers/regulator/tps65219-regulator.c | 59 ++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)
diff mbox series

Patch

diff --git a/drivers/regulator/tps65219-regulator.c b/drivers/regulator/tps65219-regulator.c
index 6dc0829cf29a..31d76706bfc0 100644
--- a/drivers/regulator/tps65219-regulator.c
+++ b/drivers/regulator/tps65219-regulator.c
@@ -347,6 +347,65 @@  static struct tps65219_chip_data chip_info_table[] = {
 	},
 };
 
+static int tps65219_register_regulators(const struct regulator_desc *regulators,
+					struct tps65219 *tps,
+					struct device *dev,
+					struct regulator_config config,
+					unsigned int arr_size)
+{
+	int i;
+	struct regulator_dev *rdev;
+
+	config.driver_data = tps;
+	config.dev = tps->dev;
+	config.regmap = tps->regmap;
+
+	for (i = 0; i < arr_size; i++) {
+		rdev = devm_regulator_register(dev, &regulators[i],
+						&config);
+		if (IS_ERR(rdev))
+			return dev_err_probe(tps->dev, PTR_ERR(rdev),
+				"Failed to register %s regulator\n",
+				regulators[i].name);
+	}
+
+	return 0;
+}
+
+static int tps65219_request_irqs(struct tps65219_regulator_irq_type *irq_types,
+				 struct tps65219 *tps, struct platform_device *pdev,
+				 struct tps65219_regulator_irq_data *irq_data,
+				 unsigned int arr_size)
+{
+	int i;
+	int irq;
+	int error;
+	struct tps65219_regulator_irq_type *irq_type;
+
+	for (i = 0; i < arr_size; ++i) {
+		irq_type = &irq_types[i];
+
+		irq = platform_get_irq_byname(pdev, irq_type->irq_name);
+		if (irq < 0)
+			return -EINVAL;
+
+		irq_data[i].dev = tps->dev;
+		irq_data[i].type = irq_type;
+
+		error = devm_request_threaded_irq(tps->dev, irq, NULL,
+						  tps65219_regulator_irq_handler,
+						  IRQF_ONESHOT,
+						  irq_type->irq_name,
+						  &irq_data[i]);
+		if (error)
+			return dev_err_probe(tps->dev, error,
+				"Failed to request %s IRQ %d\n",
+				irq_type->irq_name, irq);
+	}
+
+	return 0;
+}
+
 static int tps65219_regulator_probe(struct platform_device *pdev)
 {
 	struct tps65219 *tps = dev_get_drvdata(pdev->dev.parent);