mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/4] regmap: Correct comparison in regmap_cached
@ 2018-02-12 18:15 Charles Keepax
  2018-02-12 18:15 ` [PATCH 2/4] regmap: Correct offset handling in regmap_volatile_range Charles Keepax
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Charles Keepax @ 2018-02-12 18:15 UTC (permalink / raw)
  To: broonie; +Cc: david.rhodes, linux-kernel, patches

The cache pointer points to the actual memory used by the cache, as the
comparison here is looking for the type of the cache it should check
against cache_type.

Fixes: 1ea975cf1ef5 ("regmap: Add a function to check if a regmap register is cached")
Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
---
 drivers/base/regmap/regmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index 453116fd4362e..c7b7c5fa73ab4 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -99,7 +99,7 @@ bool regmap_cached(struct regmap *map, unsigned int reg)
 	int ret;
 	unsigned int val;
 
-	if (map->cache == REGCACHE_NONE)
+	if (map->cache_type == REGCACHE_NONE)
 		return false;
 
 	if (!map->cache_ops)
-- 
2.11.0

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

* [PATCH 2/4] regmap: Correct offset handling in regmap_volatile_range
  2018-02-12 18:15 [PATCH 1/4] regmap: Correct comparison in regmap_cached Charles Keepax
@ 2018-02-12 18:15 ` Charles Keepax
  2018-02-13 12:29   ` Applied "regmap: Correct offset handling in regmap_volatile_range" to the regmap tree Mark Brown
  2018-02-12 18:15 ` [PATCH 3/4] regmap: Don't use format_val in regmap_bulk_read Charles Keepax
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Charles Keepax @ 2018-02-12 18:15 UTC (permalink / raw)
  To: broonie; +Cc: david.rhodes, linux-kernel, patches

The current implementation is broken for regmaps that have a reg_stride,
since it doesn't take the stride into account. Correct this by using the
helper function to calculate the register offset.

Fixes: f01ee60fffa4 ("regmap: implement register striding")
Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
---
 drivers/base/regmap/regmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index c7b7c5fa73ab4..2339b98f1b6e4 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -174,7 +174,7 @@ static bool regmap_volatile_range(struct regmap *map, unsigned int reg,
 	unsigned int i;
 
 	for (i = 0; i < num; i++)
-		if (!regmap_volatile(map, reg + i))
+		if (!regmap_volatile(map, reg + regmap_get_offset(map, i)))
 			return false;
 
 	return true;
-- 
2.11.0

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

* [PATCH 3/4] regmap: Don't use format_val in regmap_bulk_read
  2018-02-12 18:15 [PATCH 1/4] regmap: Correct comparison in regmap_cached Charles Keepax
  2018-02-12 18:15 ` [PATCH 2/4] regmap: Correct offset handling in regmap_volatile_range Charles Keepax
@ 2018-02-12 18:15 ` Charles Keepax
  2018-02-13 12:29   ` Applied "regmap: Don't use format_val in regmap_bulk_read" to the regmap tree Mark Brown
  2018-02-12 18:15 ` [PATCH 4/4] regmap: Use helper function for register offset Charles Keepax
  2018-02-13 12:29 ` Applied "regmap: Correct comparison in regmap_cached" " Mark Brown
  3 siblings, 1 reply; 8+ messages in thread
From: Charles Keepax @ 2018-02-12 18:15 UTC (permalink / raw)
  To: broonie; +Cc: david.rhodes, linux-kernel, patches

A bulk read can be implemented either through regmap_raw_read, or
by reading each register individually using regmap_read.  Both
regmap_read and regmap_bulk_read should return values in native
endian. In the individual case the current implementation calls
format_val to put the data into the output array, which can cause
endian issues. The regmap_read will have already converted the data
into native endian, if the hosts endian differs from the device then
format_val will switch the endian back again.

Rather than using format_val simply use the code that is called if
there is no format_val function. This code supports all cases except
24-bit but there don't appear to be any users of regmap_bulk_read for
24-bit. Additionally, it would have to be a big endian host for the
old code to actually function correctly anyway.

Fixes: 15b8d2c41fe5 ("regmap: Fix regmap_bulk_read in BE mode")
Reported-by: David Rhodes <david.rhodes@cirrus.com>
Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
---
 drivers/base/regmap/regmap.c | 55 ++++++++++++++++++--------------------------
 1 file changed, 23 insertions(+), 32 deletions(-)

diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index 2339b98f1b6e4..8594b02aa3e67 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -2709,47 +2709,38 @@ int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val,
 		for (i = 0; i < val_count * val_bytes; i += val_bytes)
 			map->format.parse_inplace(val + i);
 	} else {
+#ifdef CONFIG_64BIT
+		u64 *u64 = val;
+#endif
+		u32 *u32 = val;
+		u16 *u16 = val;
+		u8 *u8 = val;
+
 		for (i = 0; i < val_count; i++) {
 			unsigned int ival;
+
 			ret = regmap_read(map, reg + regmap_get_offset(map, i),
 					  &ival);
 			if (ret != 0)
 				return ret;
 
-			if (map->format.format_val) {
-				map->format.format_val(val + (i * val_bytes), ival, 0);
-			} else {
-				/* Devices providing read and write
-				 * operations can use the bulk I/O
-				 * functions if they define a val_bytes,
-				 * we assume that the values are native
-				 * endian.
-				 */
-#ifdef CONFIG_64BIT
-				u64 *u64 = val;
-#endif
-				u32 *u32 = val;
-				u16 *u16 = val;
-				u8 *u8 = val;
-
-				switch (map->format.val_bytes) {
+			switch (map->format.val_bytes) {
 #ifdef CONFIG_64BIT
-				case 8:
-					u64[i] = ival;
-					break;
+			case 8:
+				u64[i] = ival;
+				break;
 #endif
-				case 4:
-					u32[i] = ival;
-					break;
-				case 2:
-					u16[i] = ival;
-					break;
-				case 1:
-					u8[i] = ival;
-					break;
-				default:
-					return -EINVAL;
-				}
+			case 4:
+				u32[i] = ival;
+				break;
+			case 2:
+				u16[i] = ival;
+				break;
+			case 1:
+				u8[i] = ival;
+				break;
+			default:
+				return -EINVAL;
 			}
 		}
 	}
-- 
2.11.0

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

* [PATCH 4/4] regmap: Use helper function for register offset
  2018-02-12 18:15 [PATCH 1/4] regmap: Correct comparison in regmap_cached Charles Keepax
  2018-02-12 18:15 ` [PATCH 2/4] regmap: Correct offset handling in regmap_volatile_range Charles Keepax
  2018-02-12 18:15 ` [PATCH 3/4] regmap: Don't use format_val in regmap_bulk_read Charles Keepax
@ 2018-02-12 18:15 ` Charles Keepax
  2018-02-13 12:29   ` Applied "regmap: Use helper function for register offset" to the regmap tree Mark Brown
  2018-02-13 12:29 ` Applied "regmap: Correct comparison in regmap_cached" " Mark Brown
  3 siblings, 1 reply; 8+ messages in thread
From: Charles Keepax @ 2018-02-12 18:15 UTC (permalink / raw)
  To: broonie; +Cc: david.rhodes, linux-kernel, patches

As a helper function exists for calculating register offsets lets use
that rather than open coding with the reg_stride.

Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
---
 drivers/base/regmap/regmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index 8594b02aa3e67..6342eaefc2189 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -1993,7 +1993,7 @@ int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
 				return -EINVAL;
 			}
 
-			ret = regmap_write(map, reg + (i * map->reg_stride),
+			ret = regmap_write(map, reg + regmap_get_offset(map, i),
 					   ival);
 			if (ret)
 				return ret;
-- 
2.11.0

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

* Applied "regmap: Use helper function for register offset" to the regmap tree
  2018-02-12 18:15 ` [PATCH 4/4] regmap: Use helper function for register offset Charles Keepax
@ 2018-02-13 12:29   ` Mark Brown
  0 siblings, 0 replies; 8+ messages in thread
From: Mark Brown @ 2018-02-13 12:29 UTC (permalink / raw)
  To: Charles Keepax
  Cc: Mark Brown, broonie, david.rhodes, linux-kernel, patches, linux-kernel

The patch

   regmap: Use helper function for register offset

has been applied to the regmap tree at

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap.git 

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.  

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

>From 45abcc556721a6d18e4af82e20e164044f0a3e36 Mon Sep 17 00:00:00 2001
From: Charles Keepax <ckeepax@opensource.cirrus.com>
Date: Mon, 12 Feb 2018 18:15:47 +0000
Subject: [PATCH] regmap: Use helper function for register offset

As a helper function exists for calculating register offsets lets use
that rather than open coding with the reg_stride.

Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 drivers/base/regmap/regmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index 4037b3782bd3..f075c05859b0 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -1993,7 +1993,7 @@ int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
 				return -EINVAL;
 			}
 
-			ret = regmap_write(map, reg + (i * map->reg_stride),
+			ret = regmap_write(map, reg + regmap_get_offset(map, i),
 					   ival);
 			if (ret)
 				return ret;
-- 
2.16.1

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

* Applied "regmap: Don't use format_val in regmap_bulk_read" to the regmap tree
  2018-02-12 18:15 ` [PATCH 3/4] regmap: Don't use format_val in regmap_bulk_read Charles Keepax
@ 2018-02-13 12:29   ` Mark Brown
  0 siblings, 0 replies; 8+ messages in thread
From: Mark Brown @ 2018-02-13 12:29 UTC (permalink / raw)
  To: Charles Keepax
  Cc: David Rhodes, Mark Brown, broonie, david.rhodes, linux-kernel,
	patches, linux-kernel

The patch

   regmap: Don't use format_val in regmap_bulk_read

has been applied to the regmap tree at

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap.git 

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.  

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

>From 9ae27a8d1f3ebff09191fb8cb1341414547293b2 Mon Sep 17 00:00:00 2001
From: Charles Keepax <ckeepax@opensource.cirrus.com>
Date: Mon, 12 Feb 2018 18:15:46 +0000
Subject: [PATCH] regmap: Don't use format_val in regmap_bulk_read

A bulk read can be implemented either through regmap_raw_read, or
by reading each register individually using regmap_read.  Both
regmap_read and regmap_bulk_read should return values in native
endian. In the individual case the current implementation calls
format_val to put the data into the output array, which can cause
endian issues. The regmap_read will have already converted the data
into native endian, if the hosts endian differs from the device then
format_val will switch the endian back again.

Rather than using format_val simply use the code that is called if
there is no format_val function. This code supports all cases except
24-bit but there don't appear to be any users of regmap_bulk_read for
24-bit. Additionally, it would have to be a big endian host for the
old code to actually function correctly anyway.

Fixes: 15b8d2c41fe5 ("regmap: Fix regmap_bulk_read in BE mode")
Reported-by: David Rhodes <david.rhodes@cirrus.com>
Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 drivers/base/regmap/regmap.c | 55 ++++++++++++++++++--------------------------
 1 file changed, 23 insertions(+), 32 deletions(-)

diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index ee302ccdfbc8..4037b3782bd3 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -2709,47 +2709,38 @@ int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val,
 		for (i = 0; i < val_count * val_bytes; i += val_bytes)
 			map->format.parse_inplace(val + i);
 	} else {
+#ifdef CONFIG_64BIT
+		u64 *u64 = val;
+#endif
+		u32 *u32 = val;
+		u16 *u16 = val;
+		u8 *u8 = val;
+
 		for (i = 0; i < val_count; i++) {
 			unsigned int ival;
+
 			ret = regmap_read(map, reg + regmap_get_offset(map, i),
 					  &ival);
 			if (ret != 0)
 				return ret;
 
-			if (map->format.format_val) {
-				map->format.format_val(val + (i * val_bytes), ival, 0);
-			} else {
-				/* Devices providing read and write
-				 * operations can use the bulk I/O
-				 * functions if they define a val_bytes,
-				 * we assume that the values are native
-				 * endian.
-				 */
-#ifdef CONFIG_64BIT
-				u64 *u64 = val;
-#endif
-				u32 *u32 = val;
-				u16 *u16 = val;
-				u8 *u8 = val;
-
-				switch (map->format.val_bytes) {
+			switch (map->format.val_bytes) {
 #ifdef CONFIG_64BIT
-				case 8:
-					u64[i] = ival;
-					break;
+			case 8:
+				u64[i] = ival;
+				break;
 #endif
-				case 4:
-					u32[i] = ival;
-					break;
-				case 2:
-					u16[i] = ival;
-					break;
-				case 1:
-					u8[i] = ival;
-					break;
-				default:
-					return -EINVAL;
-				}
+			case 4:
+				u32[i] = ival;
+				break;
+			case 2:
+				u16[i] = ival;
+				break;
+			case 1:
+				u8[i] = ival;
+				break;
+			default:
+				return -EINVAL;
 			}
 		}
 	}
-- 
2.16.1

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

* Applied "regmap: Correct comparison in regmap_cached" to the regmap tree
  2018-02-12 18:15 [PATCH 1/4] regmap: Correct comparison in regmap_cached Charles Keepax
                   ` (2 preceding siblings ...)
  2018-02-12 18:15 ` [PATCH 4/4] regmap: Use helper function for register offset Charles Keepax
@ 2018-02-13 12:29 ` Mark Brown
  3 siblings, 0 replies; 8+ messages in thread
From: Mark Brown @ 2018-02-13 12:29 UTC (permalink / raw)
  To: Charles Keepax
  Cc: Mark Brown, broonie, david.rhodes, linux-kernel, patches, linux-kernel

The patch

   regmap: Correct comparison in regmap_cached

has been applied to the regmap tree at

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap.git 

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.  

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

>From 71df179363a5a733a8932e9afb869760d7559383 Mon Sep 17 00:00:00 2001
From: Charles Keepax <ckeepax@opensource.cirrus.com>
Date: Mon, 12 Feb 2018 18:15:44 +0000
Subject: [PATCH] regmap: Correct comparison in regmap_cached

The cache pointer points to the actual memory used by the cache, as the
comparison here is looking for the type of the cache it should check
against cache_type.

Fixes: 1ea975cf1ef5 ("regmap: Add a function to check if a regmap register is cached")
Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 drivers/base/regmap/regmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index ee302ccdfbc8..7519b039c162 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -99,7 +99,7 @@ bool regmap_cached(struct regmap *map, unsigned int reg)
 	int ret;
 	unsigned int val;
 
-	if (map->cache == REGCACHE_NONE)
+	if (map->cache_type == REGCACHE_NONE)
 		return false;
 
 	if (!map->cache_ops)
-- 
2.16.1

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

* Applied "regmap: Correct offset handling in regmap_volatile_range" to the regmap tree
  2018-02-12 18:15 ` [PATCH 2/4] regmap: Correct offset handling in regmap_volatile_range Charles Keepax
@ 2018-02-13 12:29   ` Mark Brown
  0 siblings, 0 replies; 8+ messages in thread
From: Mark Brown @ 2018-02-13 12:29 UTC (permalink / raw)
  To: Charles Keepax
  Cc: Mark Brown, broonie, david.rhodes, linux-kernel, patches, linux-kernel

The patch

   regmap: Correct offset handling in regmap_volatile_range

has been applied to the regmap tree at

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap.git 

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.  

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

>From b8f9a03b741ddfdde4aa8b607fa7d88eb63a6338 Mon Sep 17 00:00:00 2001
From: Charles Keepax <ckeepax@opensource.cirrus.com>
Date: Mon, 12 Feb 2018 18:15:45 +0000
Subject: [PATCH] regmap: Correct offset handling in regmap_volatile_range

The current implementation is broken for regmaps that have a reg_stride,
since it doesn't take the stride into account. Correct this by using the
helper function to calculate the register offset.

Fixes: f01ee60fffa4 ("regmap: implement register striding")
Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 drivers/base/regmap/regmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index ee302ccdfbc8..f89d01e7b257 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -174,7 +174,7 @@ static bool regmap_volatile_range(struct regmap *map, unsigned int reg,
 	unsigned int i;
 
 	for (i = 0; i < num; i++)
-		if (!regmap_volatile(map, reg + i))
+		if (!regmap_volatile(map, reg + regmap_get_offset(map, i)))
 			return false;
 
 	return true;
-- 
2.16.1

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

end of thread, other threads:[~2018-02-13 12:33 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-12 18:15 [PATCH 1/4] regmap: Correct comparison in regmap_cached Charles Keepax
2018-02-12 18:15 ` [PATCH 2/4] regmap: Correct offset handling in regmap_volatile_range Charles Keepax
2018-02-13 12:29   ` Applied "regmap: Correct offset handling in regmap_volatile_range" to the regmap tree Mark Brown
2018-02-12 18:15 ` [PATCH 3/4] regmap: Don't use format_val in regmap_bulk_read Charles Keepax
2018-02-13 12:29   ` Applied "regmap: Don't use format_val in regmap_bulk_read" to the regmap tree Mark Brown
2018-02-12 18:15 ` [PATCH 4/4] regmap: Use helper function for register offset Charles Keepax
2018-02-13 12:29   ` Applied "regmap: Use helper function for register offset" to the regmap tree Mark Brown
2018-02-13 12:29 ` Applied "regmap: Correct comparison in regmap_cached" " Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®