* [PATCH V3 1/2] regmap: Support for caching in reg_raw_write()
@ 2012-02-10 16:00 Laxman Dewangan
2012-02-10 16:00 ` [PATCH V3 2/2] regmap: add regmap_bulk_write() for register write Laxman Dewangan
[not found] ` <1328889628-13151-1-git-send-email-ldewangan-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
0 siblings, 2 replies; 4+ messages in thread
From: Laxman Dewangan @ 2012-02-10 16:00 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
Adding support for caching of data into the
non-volatile register from the call of reg_raw_write().
This will allow the larger block of data write into multiple
register without worrying whether register is cached or not
through reg_raw_write().
Signed-off-by: Laxman Dewangan <ldewangan-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
---
Changes from V1:
- Add register number and return value in error case.
- Some variable usage cleanups..
Changes from V2:
- Fixing register number during error printing.
drivers/base/regmap/regmap.c | 26 +++++++++++++++++++++-----
1 files changed, 21 insertions(+), 5 deletions(-)
diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index 80129c0..ba92217 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -323,6 +323,26 @@ static int _regmap_raw_write(struct regmap *map, unsigned int reg,
if (!map->writeable_reg(map->dev, reg + i))
return -EINVAL;
+ if (!map->cache_bypass && map->format.parse_val) {
+ unsigned int ival;
+ int val_bytes = map->format.val_bytes;
+ for (i = 0; i < val_len / val_bytes; i++) {
+ memcpy(map->work_buf, val + (i * val_bytes), val_bytes);
+ ival = map->format.parse_val(map->work_buf);
+ ret = regcache_write(map, reg + i, ival);
+ if (ret) {
+ dev_err(map->dev,
+ "Error in caching of register: %u ret: %d\n",
+ reg + i, ret);
+ return ret;
+ }
+ }
+ if (map->cache_only) {
+ map->cache_dirty = true;
+ return 0;
+ }
+ }
+
map->format.format_reg(map->work_buf, reg);
u8[0] |= map->write_flag_mask;
@@ -373,7 +393,7 @@ int _regmap_write(struct regmap *map, unsigned int reg,
int ret;
BUG_ON(!map->format.format_write && !map->format.format_val);
- if (!map->cache_bypass) {
+ if (!map->cache_bypass && map->format.format_write) {
ret = regcache_write(map, reg, val);
if (ret != 0)
return ret;
@@ -450,12 +470,8 @@ EXPORT_SYMBOL_GPL(regmap_write);
int regmap_raw_write(struct regmap *map, unsigned int reg,
const void *val, size_t val_len)
{
- size_t val_count = val_len / map->format.val_bytes;
int ret;
- WARN_ON(!regmap_volatile_range(map, reg, val_count) &&
- map->cache_type != REGCACHE_NONE);
-
mutex_lock(&map->lock);
ret = _regmap_raw_write(map, reg, val, val_len);
--
1.7.1.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH V3 2/2] regmap: add regmap_bulk_write() for register write 2012-02-10 16:00 [PATCH V3 1/2] regmap: Support for caching in reg_raw_write() Laxman Dewangan @ 2012-02-10 16:00 ` Laxman Dewangan 2012-02-11 21:47 ` Mark Brown [not found] ` <1328889628-13151-1-git-send-email-ldewangan-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org> 1 sibling, 1 reply; 4+ messages in thread From: Laxman Dewangan @ 2012-02-10 16:00 UTC (permalink / raw) To: broonie, gregkh, lars, linux-kernel; +Cc: linux-tegra, ldewangan 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@nvidia.com> --- 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 drivers/base/regmap/regmap.c | 61 ++++++++++++++++++++++++++++++++++++++++++ include/linux/regmap.h | 2 + 2 files changed, 63 insertions(+), 0 deletions(-) diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index ba92217..a1656a7 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c @@ -482,6 +482,67 @@ 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) { + mutex_unlock(&map->lock); + dev_err(map->dev, + "Error in memory allocation\n"); + return -ENOMEM; + } + 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; + } + } + } + + 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 V3 2/2] regmap: add regmap_bulk_write() for register write 2012-02-10 16:00 ` [PATCH V3 2/2] regmap: add regmap_bulk_write() for register write Laxman Dewangan @ 2012-02-11 21:47 ` Mark Brown 0 siblings, 0 replies; 4+ messages in thread From: Mark Brown @ 2012-02-11 21:47 UTC (permalink / raw) To: Laxman Dewangan; +Cc: gregkh, lars, linux-kernel, linux-tegra [-- Attachment #1: Type: text/plain, Size: 589 bytes --] On Fri, Feb 10, 2012 at 09:30:28PM +0530, Laxman Dewangan wrote: > + /* No formatting is require if val_byte is 1 */ > + if (val_bytes == 1) > + wval = (void *)val; > + else { Please don't combine branches with and without braces. > + wval = kmemdup(val, val_count * val_bytes, GFP_KERNEL); > + if (!wval) { > + mutex_unlock(&map->lock); > + dev_err(map->dev, > + "Error in memory allocation\n"); > + return -ENOMEM; As a style thing a goto error pattern is clearer for stuff like this - there's so many branches that it's complex to keep track of the unwinding. [-- Attachment #2: Digital signature --] [-- Type: application/pgp-signature, Size: 836 bytes --] ^ permalink raw reply [flat|nested] 4+ messages in thread
[parent not found: <1328889628-13151-1-git-send-email-ldewangan-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>]
* Re: [PATCH V3 1/2] regmap: Support for caching in reg_raw_write() [not found] ` <1328889628-13151-1-git-send-email-ldewangan-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org> @ 2012-02-11 23:05 ` Mark Brown 0 siblings, 0 replies; 4+ messages in thread From: Mark Brown @ 2012-02-11 23:05 UTC (permalink / raw) To: Laxman Dewangan Cc: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r, lars-Qo5EllUWu/uELgA04lAiVw, linux-kernel-u79uwXL29TY76Z2rM5mHXA, linux-tegra-u79uwXL29TY76Z2rM5mHXA [-- Attachment #1: Type: text/plain, Size: 468 bytes --] On Fri, Feb 10, 2012 at 09:30:27PM +0530, Laxman Dewangan wrote: > Adding support for caching of data into the > non-volatile register from the call of reg_raw_write(). > > This will allow the larger block of data write into multiple > register without worrying whether register is cached or not > through reg_raw_write(). Applied, thanks. We really should refactor later on to not do the encode/decode dance if we don't have to but this is fine for now. [-- Attachment #2: Digital signature --] [-- Type: application/pgp-signature, Size: 836 bytes --] ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-02-11 23:05 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-10 16:00 [PATCH V3 1/2] regmap: Support for caching in reg_raw_write() Laxman Dewangan
2012-02-10 16:00 ` [PATCH V3 2/2] regmap: add regmap_bulk_write() for register write Laxman Dewangan
2012-02-11 21:47 ` Mark Brown
[not found] ` <1328889628-13151-1-git-send-email-ldewangan-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2012-02-11 23:05 ` [PATCH V3 1/2] regmap: Support for caching in reg_raw_write() 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).