linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] regmap: Return an error if a caller attempts to do an unsupported raw read
@ 2016-02-01 21:38 Mark Brown
  0 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2016-02-01 21:38 UTC (permalink / raw)
  To: mail, Fabio Estevam; +Cc: alsa-devel, nicoleotsuka, linux-kernel, Mark Brown

regmaps without raw I/O access can't implement raw I/O operations,
return an error if someone tries to do that rather than crashing.

Signed-off-by: Mark Brown <broonie@kernel.org>
---
 drivers/base/regmap/regmap.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index 343263449aff..e2f68807d970 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -2255,6 +2255,9 @@ static int _regmap_raw_read(struct regmap *map, unsigned int reg, void *val,
 
 	WARN_ON(!map->bus);
 
+	if (!map->bus || !map->bus->read)
+		return -EINVAL;
+
 	range = _regmap_range_lookup(map, reg);
 	if (range) {
 		ret = _regmap_select_page(map, &reg, range,
-- 
2.7.0.rc3

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 1/2] regmap: Return an error if a caller attempts to do an unsupported raw read
@ 2016-02-02 12:16 Fabio Estevam
  2016-02-02 12:16 ` [PATCH 2/2] regmap: cache: Fall back to register by register read for cache defaults Fabio Estevam
  2016-02-02 12:28 ` [PATCH 1/2] regmap: Return an error if a caller attempts to do an unsupported raw read Mark Brown
  0 siblings, 2 replies; 4+ messages in thread
From: Fabio Estevam @ 2016-02-02 12:16 UTC (permalink / raw)
  To: broonie; +Cc: mail, linux-kernel, Fabio Estevam

From: Mark Brown <broonie@kernel.org>

regmaps without raw I/O access can't implement raw I/O operations,
return an error if someone tries to do that rather than crashing.

Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com>
---
 drivers/base/regmap/regmap.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index 3432634..e2f6880 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -2255,6 +2255,9 @@ static int _regmap_raw_read(struct regmap *map, unsigned int reg, void *val,
 
 	WARN_ON(!map->bus);
 
+	if (!map->bus || !map->bus->read)
+		return -EINVAL;
+
 	range = _regmap_range_lookup(map, reg);
 	if (range) {
 		ret = _regmap_select_page(map, &reg, range,
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] regmap: cache: Fall back to register by register read for cache defaults
  2016-02-02 12:16 [PATCH 1/2] regmap: Return an error if a caller attempts to do an unsupported raw read Fabio Estevam
@ 2016-02-02 12:16 ` Fabio Estevam
  2016-02-02 12:28 ` [PATCH 1/2] regmap: Return an error if a caller attempts to do an unsupported raw read Mark Brown
  1 sibling, 0 replies; 4+ messages in thread
From: Fabio Estevam @ 2016-02-02 12:16 UTC (permalink / raw)
  To: broonie; +Cc: mail, linux-kernel, Fabio Estevam

From: Mark Brown <broonie@kernel.org>

If we are unable to read the cache defaults for a regmap then fall back
on attempting to read them word by word. This is going to be painfully
slow for large regmaps but might be adequate for smaller ones.

Signed-off-by: Mark Brown <broonie@kernel.org>
[maciej: Use cache_bypass around read and skipping of unreadable regs]
Signed-off-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name>
Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com>
Tested-by: Fabio Estevam <fabio.estevam@nxp.com>
---
 drivers/base/regmap/regcache.c | 41 ++++++++++++++++++++++++++++++-----------
 1 file changed, 30 insertions(+), 11 deletions(-)

diff --git a/drivers/base/regmap/regcache.c b/drivers/base/regmap/regcache.c
index 5c5090b..4170b7d 100644
--- a/drivers/base/regmap/regcache.c
+++ b/drivers/base/regmap/regcache.c
@@ -30,7 +30,7 @@ static int regcache_hw_init(struct regmap *map)
 	int i, j;
 	int ret;
 	int count;
-	unsigned int val;
+	unsigned int reg, val;
 	void *tmp_buf;
 
 	if (!map->num_reg_defaults_raw)
@@ -67,27 +67,46 @@ static int regcache_hw_init(struct regmap *map)
 		ret = regmap_raw_read(map, 0, tmp_buf,
 				      map->cache_size_raw);
 		map->cache_bypass = cache_bypass;
-		if (ret < 0)
-			goto err_cache_free;
-
-		map->reg_defaults_raw = tmp_buf;
-		map->cache_free = 1;
+		if (ret == 0) {
+			map->reg_defaults_raw = tmp_buf;
+			map->cache_free = 1;
+		} else {
+			kfree(tmp_buf);
+		}
 	}
 
 	/* fill the reg_defaults */
 	for (i = 0, j = 0; i < map->num_reg_defaults_raw; i++) {
-		if (regmap_volatile(map, i * map->reg_stride))
+		reg = i * map->reg_stride;
+
+		if (!regmap_readable(map, reg))
 			continue;
-		val = regcache_get_val(map, map->reg_defaults_raw, i);
-		map->reg_defaults[j].reg = i * map->reg_stride;
+
+		if (regmap_volatile(map, reg))
+			continue;
+
+		if (map->reg_defaults_raw) {
+			val = regcache_get_val(map, map->reg_defaults_raw, i);
+		} else {
+			bool cache_bypass = map->cache_bypass;
+
+			map->cache_bypass = true;
+			ret = regmap_read(map, reg, &val);
+			map->cache_bypass = cache_bypass;
+			if (ret != 0) {
+				dev_err(map->dev, "Failed to read %d: %d\n",
+					reg, ret);
+				goto err_free;
+			}
+		}
+
+		map->reg_defaults[j].reg = reg;
 		map->reg_defaults[j].def = val;
 		j++;
 	}
 
 	return 0;
 
-err_cache_free:
-	kfree(tmp_buf);
 err_free:
 	kfree(map->reg_defaults);
 
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] regmap: Return an error if a caller attempts to do an unsupported raw read
  2016-02-02 12:16 [PATCH 1/2] regmap: Return an error if a caller attempts to do an unsupported raw read Fabio Estevam
  2016-02-02 12:16 ` [PATCH 2/2] regmap: cache: Fall back to register by register read for cache defaults Fabio Estevam
@ 2016-02-02 12:28 ` Mark Brown
  1 sibling, 0 replies; 4+ messages in thread
From: Mark Brown @ 2016-02-02 12:28 UTC (permalink / raw)
  To: Fabio Estevam; +Cc: mail, linux-kernel, Fabio Estevam

[-- Attachment #1: Type: text/plain, Size: 306 bytes --]

On Tue, Feb 02, 2016 at 10:16:50AM -0200, Fabio Estevam wrote:
> From: Mark Brown <broonie@kernel.org>
> 
> regmaps without raw I/O access can't implement raw I/O operations,
> return an error if someone tries to do that rather than crashing.

I dropped this one into -next as soon as I wrote it...

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-02-02 12:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-02 12:16 [PATCH 1/2] regmap: Return an error if a caller attempts to do an unsupported raw read Fabio Estevam
2016-02-02 12:16 ` [PATCH 2/2] regmap: cache: Fall back to register by register read for cache defaults Fabio Estevam
2016-02-02 12:28 ` [PATCH 1/2] regmap: Return an error if a caller attempts to do an unsupported raw read Mark Brown
  -- strict thread matches above, loose matches on Subject: below --
2016-02-01 21:38 Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).