linux-tegra.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V4 2/2] regmap: add regmap_bulk_write() for register write
@ 2012-02-12  8:49 Laxman Dewangan
       [not found] ` <1329036556-15408-1-git-send-email-ldewangan-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Laxman Dewangan @ 2012-02-12  8:49 UTC (permalink / raw)
  To: broonie-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E,
	gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	lars-Qo5EllUWu/uELgA04lAiVw, linux-kernel-u79uwXL29TY76Z2rM5mHXA
  Cc: linux-tegra-u79uwXL29TY76Z2rM5mHXA,
	ldewangan-DDmLM1+adcrQT0dZR+AlfA

The bulk_write() supports the data transfer to multi
register which takes the data into cpu_endianness format
and does formatting of data to device format before
sending to device.
The transfer can be completed in single transfer or multiple
transfer based on data formatting.

Signed-off-by: Laxman Dewangan <ldewangan-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
---
Changes from V1: 
- Change commit message.
- Byte swapping in input data packet.
Changes from V2: 
- Remove formatting if val_byte is 1.
- Allocating proper size of memory for val_byte != 1
Changes from V3:
- Stylish fixes.

 drivers/base/regmap/regmap.c |   62 ++++++++++++++++++++++++++++++++++++++++++
 include/linux/regmap.h       |    2 +
 2 files changed, 64 insertions(+), 0 deletions(-)

diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index ba92217..39be1b3 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -482,6 +482,68 @@ int regmap_raw_write(struct regmap *map, unsigned int reg,
 }
 EXPORT_SYMBOL_GPL(regmap_raw_write);
 
+/*
+ * regmap_bulk_write(): Write multiple registers to the device
+ *
+ * @map: Register map to write to
+ * @reg: First register to be write from
+ * @val: Block of data to be written, in native register size for device
+ * @val_count: Number of registers to write
+ *
+ * This function is intended to be used for writing a large block of
+ * data to be device either in single transfer or multiple transfer.
+ *
+ * A value of zero will be returned on success, a negative errno will
+ * be returned in error cases.
+ */
+int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
+		     size_t val_count)
+{
+	int ret = 0, i;
+	unsigned int ival;
+	size_t val_bytes = map->format.val_bytes;
+
+	mutex_lock(&map->lock);
+
+	if (map->format.parse_val) {
+		void *wval;
+		/* No formatting is require if val_byte is 1 */
+		if (val_bytes == 1) {
+			wval = (void *)val;
+		} else {
+			wval = kmemdup(val, val_count * val_bytes, GFP_KERNEL);
+			if (!wval) {
+				ret = -ENOMEM;
+				dev_err(map->dev,
+					"Error in memory allocation\n");
+				goto out;
+			}
+			for (i = 0; i < val_count * val_bytes; i += val_bytes)
+				map->format.parse_val(wval + i);
+		}
+		ret = _regmap_raw_write(map, reg, wval, val_bytes * val_count);
+
+		if (val_bytes != 1)
+			kfree(wval);
+	} else {
+		for (i = 0; i < val_count; i++) {
+			memcpy(&ival, val + (i * val_bytes), val_bytes);
+			ret = _regmap_write(map, reg + i, ival);
+			if (ret) {
+				dev_err(map->dev,
+				    "Error in register %u write, ret %d\n",
+						reg + i, ret);
+				break;
+			}
+		}
+	}
+
+out:
+	mutex_unlock(&map->lock);
+	return ret;
+}
+EXPORT_SYMBOL_GPL(regmap_bulk_write);
+
 static int _regmap_raw_read(struct regmap *map, unsigned int reg, void *val,
 			    unsigned int val_len)
 {
diff --git a/include/linux/regmap.h b/include/linux/regmap.h
index a6ed6e6..0925e24 100644
--- a/include/linux/regmap.h
+++ b/include/linux/regmap.h
@@ -135,6 +135,8 @@ int regmap_reinit_cache(struct regmap *map,
 int regmap_write(struct regmap *map, unsigned int reg, unsigned int val);
 int regmap_raw_write(struct regmap *map, unsigned int reg,
 		     const void *val, size_t val_len);
+int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
+			size_t val_count);
 int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val);
 int regmap_raw_read(struct regmap *map, unsigned int reg,
 		    void *val, size_t val_len);
-- 
1.7.1.1

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

* Re: [PATCH V4 2/2] regmap: add regmap_bulk_write() for register write
       [not found] ` <1329036556-15408-1-git-send-email-ldewangan-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
@ 2012-02-12 11:57   ` Lars-Peter Clausen
  2012-02-12 13:11     ` Mark Brown
  0 siblings, 1 reply; 4+ messages in thread
From: Lars-Peter Clausen @ 2012-02-12 11:57 UTC (permalink / raw)
  To: Laxman Dewangan
  Cc: broonie-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E,
	gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-tegra-u79uwXL29TY76Z2rM5mHXA

On 02/12/2012 09:49 AM, Laxman Dewangan wrote:
> [...]
> +	} else {
> +		for (i = 0; i < val_count; i++) {
> +			memcpy(&ival, val + (i * val_bytes), val_bytes);

This will have endianess issues. You'll need something like regcache_get_val.

> +			ret = _regmap_write(map, reg + i, ival);
> +			if (ret) {
> +				dev_err(map->dev,
> +				    "Error in register %u write, ret %d\n",
> +						reg + i, ret);
> +				break;
> +			}
> +		}
> +	}
> [...]

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

* Re: [PATCH V4 2/2] regmap: add regmap_bulk_write() for register write
  2012-02-12 11:57   ` Lars-Peter Clausen
@ 2012-02-12 13:11     ` Mark Brown
       [not found]       ` <20120212131101.GA3395-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Mark Brown @ 2012-02-12 13:11 UTC (permalink / raw)
  To: Lars-Peter Clausen; +Cc: Laxman Dewangan, gregkh, linux-kernel, linux-tegra

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

On Sun, Feb 12, 2012 at 12:57:25PM +0100, Lars-Peter Clausen wrote:
> On 02/12/2012 09:49 AM, Laxman Dewangan wrote:
> > [...]
> > +	} else {
> > +		for (i = 0; i < val_count; i++) {
> > +			memcpy(&ival, val + (i * val_bytes), val_bytes);

> This will have endianess issues. You'll need something like regcache_get_val.

> > +			ret = _regmap_write(map, reg + i, ival);

Or just don't provide this fallback at all - it's not something the
underlying device supports anyway and none of the other block or bulk
operations work on these devices either.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

* Re: [PATCH V4 2/2] regmap: add regmap_bulk_write() for register write
       [not found]       ` <20120212131101.GA3395-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
@ 2012-02-12 14:14         ` Laxman Dewangan
  0 siblings, 0 replies; 4+ messages in thread
From: Laxman Dewangan @ 2012-02-12 14:14 UTC (permalink / raw)
  To: Mark Brown
  Cc: Lars-Peter Clausen,
	gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org

On Sunday 12 February 2012 06:41 PM, Mark Brown wrote:
> * PGP Signed by an unknown key
>
> On Sun, Feb 12, 2012 at 12:57:25PM +0100, Lars-Peter Clausen wrote:
>> On 02/12/2012 09:49 AM, Laxman Dewangan wrote:
>>> [...]
>>> +	} else {
>>> +		for (i = 0; i<  val_count; i++) {
>>> +			memcpy(&ival, val + (i * val_bytes), val_bytes);
>> This will have endianess issues. You'll need something like regcache_get_val.
The data pointer of this function is in cpu-endianess and so I am just 
copying it because regmap_write takes integer type value.
>>> +			ret = _regmap_write(map, reg + i, ival);
> Or just don't provide this fallback at all - it's not something the
> underlying device supports anyway and none of the other block or bulk
> operations work on these devices either.
Yaah, Seeing other function I think I can remove this fallback.

> * Unknown Key
> * 0x6E30FDDD

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

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

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-12  8:49 [PATCH V4 2/2] regmap: add regmap_bulk_write() for register write Laxman Dewangan
     [not found] ` <1329036556-15408-1-git-send-email-ldewangan-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2012-02-12 11:57   ` Lars-Peter Clausen
2012-02-12 13:11     ` Mark Brown
     [not found]       ` <20120212131101.GA3395-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
2012-02-12 14:14         ` Laxman Dewangan

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).