2024-04-30 01:14:11

by Jisheng Zhang

[permalink] [raw]
Subject: [PATCH] regulator: tps6286x-regulator: Enable REGCACHE_FLAT

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 <[email protected]>
---
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



2024-04-30 02:09:41

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH] regulator: tps6286x-regulator: Enable REGCACHE_FLAT

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).


Attachments:
(No filename) (489.00 B)
signature.asc (499.00 B)
Download all attachments