Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1421526

[PATCH 01/10] regmap: Support bulk writes for devices without raw formatting

From Chen-Yu Tsai <wens@csie.org>
Newsgroups linux.kernel
Subject [PATCH 01/10] regmap: Support bulk writes for devices without raw formatting
Date 2016-06-14 04:30 +0200
Message-ID <rJMh4-6Rv-11@gated-at.bofh.it> (permalink)
References <rJM7n-6NR-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


When doing a bulk writes from a device which lacks raw I/O support we
fall back to doing register at a time reads but we still use the raw
formatters in order to render the data into the word size used by the
device (since bulk reads still operate on the device word size rather
than unsigned ints).  This means that devices without raw formatting
such as those that provide reg_read() are not supported.  Provide
handling for them by copying the values read into native endian values
of the appropriate size.

This complements commit d5b98eb12420 ("regmap: Support bulk reads for
devices without raw formatting").

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---
 drivers/base/regmap/regmap.c | 31 ++++++++++++++++++++++++++++---
 1 file changed, 28 insertions(+), 3 deletions(-)

diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index df2d2ef5d6b3..51fa7d66a393 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -1777,8 +1777,6 @@ int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
 	size_t val_bytes = map->format.val_bytes;
 	size_t total_size = val_bytes * val_count;
 
-	if (map->bus && !map->format.parse_inplace)
-		return -EINVAL;
 	if (!IS_ALIGNED(reg, map->reg_stride))
 		return -EINVAL;
 
@@ -1789,7 +1787,8 @@ int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
 	 *
 	 * The first if block is used for memory mapped io. It does not allow
 	 * val_bytes of 3 for example.
-	 * The second one is used for busses which do not have this limitation
+	 * The second one is for busses that do not provide raw I/O.
+	 * The third one is used for busses which do not have these limitations
 	 * and can write arbitrary value lengths.
 	 */
 	if (!map->bus) {
@@ -1825,6 +1824,32 @@ int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
 		}
 out:
 		map->unlock(map->lock_arg);
+	} else if (map->bus && !map->format.parse_inplace) {
+		const u8 *u8 = val;
+		const u16 *u16 = val;
+		const u32 *u32 = val;
+		unsigned int ival;
+
+		for (i = 0; i < val_count; i++) {
+			switch (map->format.val_bytes) {
+			case 4:
+				ival = u32[i];
+				break;
+			case 2:
+				ival = u16[i];
+				break;
+			case 1:
+				ival = u8[i];
+				break;
+			default:
+				return -EINVAL;
+			}
+
+			ret = regmap_write(map, reg + (i * map->reg_stride),
+					   ival);
+			if (ret)
+				return ret;
+		}
 	} else if (map->use_single_write ||
 		   (map->max_raw_write && map->max_raw_write < total_size)) {
 		int chunk_stride = map->reg_stride;
-- 
2.8.1

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 00/10] mfd: ac100: Add support for X-Powers AC100 audio codec / RTC combo IC Chen-Yu Tsai <wens@csie.org> - 2016-06-14 04:20 +0200
  [PATCH 07/10] ARM: dts: sun9i: cubieboard4: Add device node for AC100 Chen-Yu Tsai <wens@csie.org> - 2016-06-14 04:20 +0200
  [PATCH 06/10] ARM: dts: sun9i: a80-optimus: Add device node for AC100 Chen-Yu Tsai <wens@csie.org> - 2016-06-14 04:20 +0200
  [PATCH 08/10] ARM: dts: sun9i: cubieboard4: Order nodes by alphabetical order Chen-Yu Tsai <wens@csie.org> - 2016-06-14 04:30 +0200
  [PATCH 05/10] rtc: ac100: Add clk output support Chen-Yu Tsai <wens@csie.org> - 2016-06-14 04:30 +0200
  [PATCH 01/10] regmap: Support bulk writes for devices without raw formatting Chen-Yu Tsai <wens@csie.org> - 2016-06-14 04:30 +0200
  Re: [PATCH 03/10] mfd: Add driver for X-Powers AC100 audio codec /  RTC combo IC Chen-Yu Tsai <wens@csie.org> - 2016-06-14 04:30 +0200
  [PATCH 03/10] mfd: ac100: Add driver for X-Powers AC100 audio codec / RTC combo IC Chen-Yu Tsai <wens@csie.org> - 2016-06-14 04:30 +0200
  [PATCH 04/10] rtc: ac100: Add RTC driver for X-Powers AC100 Chen-Yu Tsai <wens@csie.org> - 2016-06-14 04:30 +0200
  [PATCH 03/10] mfd: Add driver for X-Powers AC100 audio codec / RTC combo IC Chen-Yu Tsai <wens@csie.org> - 2016-06-14 04:30 +0200

csiph-web