[PATCH] regulator: tps6286x-regulator: Enable REGCACHE_FLAT

Jisheng Zhang posted 1 patch 1 year, 7 months ago
drivers/regulator/tps6286x-regulator.c | 36 ++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
[PATCH] regulator: tps6286x-regulator: Enable REGCACHE_FLAT
Posted by Jisheng Zhang 1 year, 7 months ago
Enable regmap cache to reduce i2c transactions and corresponding
interrupts if regulator is accessed frequently. Since the register map
is small, we use a FLAT regmap cache.

Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
---
 drivers/regulator/tps6286x-regulator.c | 36 ++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/drivers/regulator/tps6286x-regulator.c b/drivers/regulator/tps6286x-regulator.c
index 758c70269653..adef970972a7 100644
--- a/drivers/regulator/tps6286x-regulator.c
+++ b/drivers/regulator/tps6286x-regulator.c
@@ -19,13 +19,49 @@
 #define TPS6286X_CONTROL_FPWM	BIT(4)
 #define TPS6286X_CONTROL_SWEN	BIT(5)
 
+#define TPS6286X_STATUS		0x05
+#define TPS6286X_MAX_REGS	(TPS6286X_STATUS + 1)
+
 #define TPS6286X_MIN_MV		400
 #define TPS6286X_MAX_MV		1675
 #define TPS6286X_STEP_MV	5
 
+static bool tps6286x_writeable_reg(struct device *dev, unsigned int reg)
+{
+	switch (reg) {
+	case TPS6286X_VOUT1 ... TPS6286X_CONTROL:
+		return true;
+	default:
+		return false;
+	}
+}
+
+static bool tps6286x_readable_reg(struct device *dev, unsigned int reg)
+{
+	switch (reg) {
+	case TPS6286X_VOUT1 ... TPS6286X_CONTROL:
+	case TPS6286X_STATUS:
+		return true;
+	default:
+		return false;
+	}
+}
+
+static bool tps6286x_volatile_reg(struct device *dev, unsigned int reg)
+{
+	if (reg == TPS6286X_STATUS)
+		return true;
+	return false;
+}
+
 static const struct regmap_config tps6286x_regmap_config = {
 	.reg_bits = 8,
 	.val_bits = 8,
+	.num_reg_defaults_raw = TPS6286X_MAX_REGS,
+	.cache_type = REGCACHE_FLAT,
+	.writeable_reg = tps6286x_writeable_reg,
+	.readable_reg = tps6286x_readable_reg,
+	.volatile_reg = tps6286x_volatile_reg,
 };
 
 static int tps6286x_set_mode(struct regulator_dev *rdev, unsigned int mode)
-- 
2.43.0
Re: [PATCH] regulator: tps6286x-regulator: Enable REGCACHE_FLAT
Posted by Mark Brown 1 year, 7 months ago
On Tue, Apr 30, 2024 at 09:00:19AM +0800, Jisheng Zhang wrote:

> Enable regmap cache to reduce i2c transactions and corresponding
> interrupts if regulator is accessed frequently. Since the register map
> is small, we use a FLAT regmap cache.

There are a number of disadvantages to the flat cache, especially the
lack of sparseness, so it is generally better to use the maple cache
unless there's a specific need for the flat cache (usually the fact that
it doesn't allocate).