public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: linux-hwmon@vger.kernel.org
Cc: linux-kernel@vger.kernel.org,
	"Wolfram Sang" <wsa+renesas@sang-engineering.com>,
	"René Rebe" <rene@exactcode.de>,
	"Thomas Weißschuh" <linux@weissschuh.net>,
	"Armin Wolf" <W_Armin@gmx.de>,
	"Stephen Horvath" <s.horvath@outlook.com.au>,
	"Paul Menzel" <pmenzel@molgen.mpg.de>,
	"Sasha Kozachuk" <skozachuk@google.com>,
	"John Hamrick" <johnham@google.com>,
	"Chris Sarra" <chrissarra@google.com>,
	"Guenter Roeck" <linux@roeck-us.net>
Subject: [RFT PATCH v2 1/3] hwmon: (spd5118) Use regmap to implement paging
Date: Tue, 18 Jun 2024 12:53:46 -0700	[thread overview]
Message-ID: <20240618195348.1670547-2-linux@roeck-us.net> (raw)
In-Reply-To: <20240618195348.1670547-1-linux@roeck-us.net>

Using regmap for paging significantly improves caching since the regmap
cache no longer needs to be cleared after changing the page, so let's
use it.

Suggested-by: Armin Wolf <W_Armin@gmx.de>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
v2: Added patch

 drivers/hwmon/spd5118.c | 47 ++++++++++++++++-------------------------
 1 file changed, 18 insertions(+), 29 deletions(-)

diff --git a/drivers/hwmon/spd5118.c b/drivers/hwmon/spd5118.c
index ac94a6779360..d405c5ef755d 100644
--- a/drivers/hwmon/spd5118.c
+++ b/drivers/hwmon/spd5118.c
@@ -382,45 +382,19 @@ static const struct hwmon_chip_info spd5118_chip_info = {
 
 /* nvmem */
 
-static int spd5118_nvmem_set_page(struct regmap *regmap, int page)
-{
-	unsigned int old_page;
-	int err;
-
-	err = regmap_read(regmap, SPD5118_REG_I2C_LEGACY_MODE, &old_page);
-	if (err)
-		return err;
-
-	if (page != (old_page & SPD5118_LEGACY_MODE_MASK)) {
-		/* Update page and explicitly select 1-byte addressing */
-		err = regmap_update_bits(regmap, SPD5118_REG_I2C_LEGACY_MODE,
-					 SPD5118_LEGACY_MODE_MASK, page);
-		if (err)
-			return err;
-
-		/* Selected new NVMEM page, drop cached data */
-		regcache_drop_region(regmap, SPD5118_EEPROM_BASE, 0xff);
-	}
-
-	return 0;
-}
-
 static ssize_t spd5118_nvmem_read_page(struct regmap *regmap, char *buf,
 				       unsigned int offset, size_t count)
 {
+	int addr = (offset >> SPD5118_PAGE_SHIFT) * 0x100 + SPD5118_EEPROM_BASE;
 	int err;
 
-	err = spd5118_nvmem_set_page(regmap, offset >> SPD5118_PAGE_SHIFT);
-	if (err)
-		return err;
-
 	offset &= SPD5118_PAGE_MASK;
 
 	/* Can't cross page boundaries */
 	if (offset + count > SPD5118_PAGE_SIZE)
 		count = SPD5118_PAGE_SIZE - offset;
 
-	err = regmap_bulk_read(regmap, SPD5118_EEPROM_BASE + offset, buf, count);
+	err = regmap_bulk_read(regmap, addr + offset, buf, count);
 	if (err)
 		return err;
 
@@ -515,13 +489,28 @@ static bool spd5118_volatile_reg(struct device *dev, unsigned int reg)
 	}
 }
 
+static const struct regmap_range_cfg spd5118_regmap_range_cfg[] = {
+	{
+	.selector_reg   = SPD5118_REG_I2C_LEGACY_MODE,
+	.selector_mask  = SPD5118_LEGACY_PAGE_MASK,
+	.selector_shift = 0,
+	.window_start   = 0,
+	.window_len     = 0x100,
+	.range_min      = 0,
+	.range_max      = 0x7ff,
+	},
+};
+
 static const struct regmap_config spd5118_regmap_config = {
 	.reg_bits = 8,
 	.val_bits = 8,
-	.max_register = 0xff,
+	.max_register = 0x7ff,
 	.writeable_reg = spd5118_writeable_reg,
 	.volatile_reg = spd5118_volatile_reg,
 	.cache_type = REGCACHE_MAPLE,
+
+	.ranges = spd5118_regmap_range_cfg,
+	.num_ranges = ARRAY_SIZE(spd5118_regmap_range_cfg),
 };
 
 static int spd5118_probe(struct i2c_client *client)
-- 
2.39.2


  reply	other threads:[~2024-06-18 19:53 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-18 19:53 [RFT PATCH v2 0/3] hwmon: (spd5118) Various improvements Guenter Roeck
2024-06-18 19:53 ` Guenter Roeck [this message]
2024-06-18 19:53 ` [RFT PATCH v2 2/3] hwmon: (spd5118) Use spd5118 specific read/write operations Guenter Roeck
2024-06-18 20:37   ` Paul Menzel
2024-06-18 21:08     ` Guenter Roeck
2024-06-18 21:45       ` Paul Menzel
2024-06-18 22:37         ` Guenter Roeck
2024-06-18 22:59           ` Paul Menzel
2024-06-18 22:28       ` Wolfram Sang
2024-06-18 23:28         ` Armin Wolf
2024-06-18 23:39           ` Paul Menzel
2024-06-19  0:23             ` Guenter Roeck
2024-06-19  0:50               ` Thomas Weißschuh
2024-06-19  1:02                 ` Guenter Roeck
2024-06-19  9:13                   ` Thomas Weißschuh
2024-06-19 14:18                     ` Guenter Roeck
2024-06-18 19:53 ` [RFT PATCH v2 3/3] hwmon: (spd5118) Add support for Renesas/ITD SPD5118 hub controllers Guenter Roeck
2024-06-18 20:59 ` [RFT PATCH v2 0/3] hwmon: (spd5118) Various improvements Armin Wolf

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=20240618195348.1670547-2-linux@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=W_Armin@gmx.de \
    --cc=chrissarra@google.com \
    --cc=johnham@google.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@weissschuh.net \
    --cc=pmenzel@molgen.mpg.de \
    --cc=rene@exactcode.de \
    --cc=s.horvath@outlook.com.au \
    --cc=skozachuk@google.com \
    --cc=wsa+renesas@sang-engineering.com \
    /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