Unverified Commit 3f2e457e authored by Shree Ramamoorthy's avatar Shree Ramamoorthy Committed by Mark Brown
Browse files

regulator: tps65219: Add support for TPS65215 regulator resources



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: default avatarShree Ramamoorthy <s-ramamoorthy@ti.com>
Link: https://patch.msgid.link/20250425205736.76433-3-s-ramamoorthy@ti.com


Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent 8c04144e
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -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"
+71 −15
Original line number Diff line number Diff line
// 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);
					     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");