aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base
diff options
context:
space:
mode:
authorMark Brown <broonie@opensource.wolfsonmicro.com>2013-03-03 20:04:51 -0500
committerMark Brown <broonie@opensource.wolfsonmicro.com>2013-03-03 21:30:27 -0500
commit8a819ff8abac9ad49f120c84cce01878b3d235c2 (patch)
treee4bc968500984f5380a36ee4d12b1bc8e29ce9aa /drivers/base
parent325acab447f775bc2258b3a37a780893c203ab6c (diff)
regmap: core: Split out in place value parsing
Currently the value parsing operations both return the parsed value and modify the passed buffer. This precludes their use in places like the cache code so split out the in place modification into a new parse_inplace() operation. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'drivers/base')
-rw-r--r--drivers/base/regmap/internal.h3
-rw-r--r--drivers/base/regmap/regmap.c52
2 files changed, 38 insertions, 17 deletions
diff --git a/drivers/base/regmap/internal.h b/drivers/base/regmap/internal.h
index 582d7fdf414b..2b5851d42dbb 100644
--- a/drivers/base/regmap/internal.h
+++ b/drivers/base/regmap/internal.h
@@ -38,7 +38,8 @@ struct regmap_format {
38 unsigned int reg, unsigned int val); 38 unsigned int reg, unsigned int val);
39 void (*format_reg)(void *buf, unsigned int reg, unsigned int shift); 39 void (*format_reg)(void *buf, unsigned int reg, unsigned int shift);
40 void (*format_val)(void *buf, unsigned int val, unsigned int shift); 40 void (*format_val)(void *buf, unsigned int val, unsigned int shift);
41 unsigned int (*parse_val)(void *buf); 41 unsigned int (*parse_val)(const void *buf);
42 void (*parse_inplace)(void *buf);
42}; 43};
43 44
44struct regmap_async { 45struct regmap_async {
diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index 3d2367501fd0..aff5a8b73947 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -228,30 +228,39 @@ static void regmap_format_32_native(void *buf, unsigned int val,
228 *(u32 *)buf = val << shift; 228 *(u32 *)buf = val << shift;
229} 229}
230 230
231static unsigned int regmap_parse_8(void *buf) 231static void regmap_parse_inplace_noop(void *buf)
232{ 232{
233 u8 *b = buf; 233}
234
235static unsigned int regmap_parse_8(const void *buf)
236{
237 const u8 *b = buf;
234 238
235 return b[0]; 239 return b[0];
236} 240}
237 241
238static unsigned int regmap_parse_16_be(void *buf) 242static unsigned int regmap_parse_16_be(const void *buf)
243{
244 const __be16 *b = buf;
245
246 return be16_to_cpu(b[0]);
247}
248
249static void regmap_parse_16_be_inplace(void *buf)
239{ 250{
240 __be16 *b = buf; 251 __be16 *b = buf;
241 252
242 b[0] = be16_to_cpu(b[0]); 253 b[0] = be16_to_cpu(b[0]);
243
244 return b[0];
245} 254}
246 255
247static unsigned int regmap_parse_16_native(void *buf) 256static unsigned int regmap_parse_16_native(const void *buf)
248{ 257{
249 return *(u16 *)buf; 258 return *(u16 *)buf;
250} 259}
251 260
252static unsigned int regmap_parse_24(void *buf) 261static unsigned int regmap_parse_24(const void *buf)
253{ 262{
254 u8 *b = buf; 263 const u8 *b = buf;
255 unsigned int ret = b[2]; 264 unsigned int ret = b[2];
256 ret |= ((unsigned int)b[1]) << 8; 265 ret |= ((unsigned int)b[1]) << 8;
257 ret |= ((unsigned int)b[0]) << 16; 266 ret |= ((unsigned int)b[0]) << 16;
@@ -259,16 +268,21 @@ static unsigned int regmap_parse_24(void *buf)
259 return ret; 268 return ret;
260} 269}
261 270
262static unsigned int regmap_parse_32_be(void *buf) 271static unsigned int regmap_parse_32_be(const void *buf)
272{
273 const __be32 *b = buf;
274
275 return be32_to_cpu(b[0]);
276}
277
278static void regmap_parse_32_be_inplace(void *buf)
263{ 279{
264 __be32 *b = buf; 280 __be32 *b = buf;
265 281
266 b[0] = be32_to_cpu(b[0]); 282 b[0] = be32_to_cpu(b[0]);
267
268 return b[0];
269} 283}
270 284
271static unsigned int regmap_parse_32_native(void *buf) 285static unsigned int regmap_parse_32_native(const void *buf)
272{ 286{
273 return *(u32 *)buf; 287 return *(u32 *)buf;
274} 288}
@@ -555,16 +569,21 @@ struct regmap *regmap_init(struct device *dev,
555 goto err_map; 569 goto err_map;
556 } 570 }
557 571
572 if (val_endian == REGMAP_ENDIAN_NATIVE)
573 map->format.parse_inplace = regmap_parse_inplace_noop;
574
558 switch (config->val_bits) { 575 switch (config->val_bits) {
559 case 8: 576 case 8:
560 map->format.format_val = regmap_format_8; 577 map->format.format_val = regmap_format_8;
561 map->format.parse_val = regmap_parse_8; 578 map->format.parse_val = regmap_parse_8;
579 map->format.parse_inplace = regmap_parse_inplace_noop;
562 break; 580 break;
563 case 16: 581 case 16:
564 switch (val_endian) { 582 switch (val_endian) {
565 case REGMAP_ENDIAN_BIG: 583 case REGMAP_ENDIAN_BIG:
566 map->format.format_val = regmap_format_16_be; 584 map->format.format_val = regmap_format_16_be;
567 map->format.parse_val = regmap_parse_16_be; 585 map->format.parse_val = regmap_parse_16_be;
586 map->format.parse_inplace = regmap_parse_16_be_inplace;
568 break; 587 break;
569 case REGMAP_ENDIAN_NATIVE: 588 case REGMAP_ENDIAN_NATIVE:
570 map->format.format_val = regmap_format_16_native; 589 map->format.format_val = regmap_format_16_native;
@@ -585,6 +604,7 @@ struct regmap *regmap_init(struct device *dev,
585 case REGMAP_ENDIAN_BIG: 604 case REGMAP_ENDIAN_BIG:
586 map->format.format_val = regmap_format_32_be; 605 map->format.format_val = regmap_format_32_be;
587 map->format.parse_val = regmap_parse_32_be; 606 map->format.parse_val = regmap_parse_32_be;
607 map->format.parse_inplace = regmap_parse_32_be_inplace;
588 break; 608 break;
589 case REGMAP_ENDIAN_NATIVE: 609 case REGMAP_ENDIAN_NATIVE:
590 map->format.format_val = regmap_format_32_native; 610 map->format.format_val = regmap_format_32_native;
@@ -1240,7 +1260,7 @@ int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
1240 1260
1241 if (!map->bus) 1261 if (!map->bus)
1242 return -EINVAL; 1262 return -EINVAL;
1243 if (!map->format.parse_val) 1263 if (!map->format.parse_inplace)
1244 return -EINVAL; 1264 return -EINVAL;
1245 if (reg % map->reg_stride) 1265 if (reg % map->reg_stride)
1246 return -EINVAL; 1266 return -EINVAL;
@@ -1258,7 +1278,7 @@ int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
1258 goto out; 1278 goto out;
1259 } 1279 }
1260 for (i = 0; i < val_count * val_bytes; i += val_bytes) 1280 for (i = 0; i < val_count * val_bytes; i += val_bytes)
1261 map->format.parse_val(wval + i); 1281 map->format.parse_inplace(wval + i);
1262 } 1282 }
1263 /* 1283 /*
1264 * Some devices does not support bulk write, for 1284 * Some devices does not support bulk write, for
@@ -1519,7 +1539,7 @@ int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val,
1519 1539
1520 if (!map->bus) 1540 if (!map->bus)
1521 return -EINVAL; 1541 return -EINVAL;
1522 if (!map->format.parse_val) 1542 if (!map->format.parse_inplace)
1523 return -EINVAL; 1543 return -EINVAL;
1524 if (reg % map->reg_stride) 1544 if (reg % map->reg_stride)
1525 return -EINVAL; 1545 return -EINVAL;
@@ -1546,7 +1566,7 @@ int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val,
1546 } 1566 }
1547 1567
1548 for (i = 0; i < val_count * val_bytes; i += val_bytes) 1568 for (i = 0; i < val_count * val_bytes; i += val_bytes)
1549 map->format.parse_val(val + i); 1569 map->format.parse_inplace(val + i);
1550 } else { 1570 } else {
1551 for (i = 0; i < val_count; i++) { 1571 for (i = 0; i < val_count; i++) {
1552 unsigned int ival; 1572 unsigned int ival;