The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Jisheng Zhang <jszhang@kernel.org>
To: Liam Girdwood <lgirdwood@gmail.com>, Mark Brown <broonie@kernel.org>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] regulator: tps6286x-regulator: Enable REGCACHE_FLAT
Date: Tue, 30 Apr 2024 09:00:19 +0800	[thread overview]
Message-ID: <20240430010019.1980-1-jszhang@kernel.org> (raw)

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


             reply	other threads:[~2024-04-30  1:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-30  1:00 Jisheng Zhang [this message]
2024-04-30  2:09 ` [PATCH] regulator: tps6286x-regulator: Enable REGCACHE_FLAT Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240430010019.1980-1-jszhang@kernel.org \
    --to=jszhang@kernel.org \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox