aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXiubo Li <Li.Xiubo@freescale.com>2014-04-02 06:09:07 -0400
committerMark Brown <broonie@linaro.org>2014-04-14 11:58:15 -0400
commit4aa8c0694c731e03eb660b92a3afe14859142381 (patch)
treeb8289710b9f9190acbddd6e9fdfb9f76b80529f8
parentc9eaa447e77efe77b7fa4c953bd62de8297fd6c5 (diff)
regmap: implement LE formatting/parsing for 16/32-bit values.
Allow busses to request little endianness formatting and parsing for 16- and 32-bit values. This will be useful to support regmap-mmio. For the following the scenarios using the regmap-mmio, for example: Index CPU Device Endianess flag for values ---------------------------------------------------------- 1 LE LE REGMAP_ENDIAN_DEFAULT/NATIVE 2 LE BE REGMAP_ENDIAN_BIG 3 BE BE REGMAP_ENDIAN_DEFAULT/NATIVE 4 BE LE REGMAP_ENDIAN_LITTLE For one device driver, which will support all the cases above, needs two boolean properties in DT node like: 'big-endian' for case 2 and 'little-endian' for case 4, and for cases 1 and 3 they all will be absent. Signed-off-by: Xiubo Li <Li.Xiubo@freescale.com> Signed-off-by: Mark Brown <broonie@linaro.org>
-rw-r--r--drivers/base/regmap/regmap.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index 63e30ef096e2..a1beffb4b066 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -192,6 +192,13 @@ static void regmap_format_16_be(void *buf, unsigned int val, unsigned int shift)
192 b[0] = cpu_to_be16(val << shift); 192 b[0] = cpu_to_be16(val << shift);
193} 193}
194 194
195static void regmap_format_16_le(void *buf, unsigned int val, unsigned int shift)
196{
197 __le16 *b = buf;
198
199 b[0] = cpu_to_le16(val << shift);
200}
201
195static void regmap_format_16_native(void *buf, unsigned int val, 202static void regmap_format_16_native(void *buf, unsigned int val,
196 unsigned int shift) 203 unsigned int shift)
197{ 204{
@@ -216,6 +223,13 @@ static void regmap_format_32_be(void *buf, unsigned int val, unsigned int shift)
216 b[0] = cpu_to_be32(val << shift); 223 b[0] = cpu_to_be32(val << shift);
217} 224}
218 225
226static void regmap_format_32_le(void *buf, unsigned int val, unsigned int shift)
227{
228 __le32 *b = buf;
229
230 b[0] = cpu_to_le32(val << shift);
231}
232
219static void regmap_format_32_native(void *buf, unsigned int val, 233static void regmap_format_32_native(void *buf, unsigned int val,
220 unsigned int shift) 234 unsigned int shift)
221{ 235{
@@ -240,6 +254,13 @@ static unsigned int regmap_parse_16_be(const void *buf)
240 return be16_to_cpu(b[0]); 254 return be16_to_cpu(b[0]);
241} 255}
242 256
257static unsigned int regmap_parse_16_le(const void *buf)
258{
259 const __le16 *b = buf;
260
261 return le16_to_cpu(b[0]);
262}
263
243static void regmap_parse_16_be_inplace(void *buf) 264static void regmap_parse_16_be_inplace(void *buf)
244{ 265{
245 __be16 *b = buf; 266 __be16 *b = buf;
@@ -247,6 +268,13 @@ static void regmap_parse_16_be_inplace(void *buf)
247 b[0] = be16_to_cpu(b[0]); 268 b[0] = be16_to_cpu(b[0]);
248} 269}
249 270
271static void regmap_parse_16_le_inplace(void *buf)
272{
273 __le16 *b = buf;
274
275 b[0] = le16_to_cpu(b[0]);
276}
277
250static unsigned int regmap_parse_16_native(const void *buf) 278static unsigned int regmap_parse_16_native(const void *buf)
251{ 279{
252 return *(u16 *)buf; 280 return *(u16 *)buf;
@@ -269,6 +297,13 @@ static unsigned int regmap_parse_32_be(const void *buf)
269 return be32_to_cpu(b[0]); 297 return be32_to_cpu(b[0]);
270} 298}
271 299
300static unsigned int regmap_parse_32_le(const void *buf)
301{
302 const __le32 *b = buf;
303
304 return le32_to_cpu(b[0]);
305}
306
272static void regmap_parse_32_be_inplace(void *buf) 307static void regmap_parse_32_be_inplace(void *buf)
273{ 308{
274 __be32 *b = buf; 309 __be32 *b = buf;
@@ -276,6 +311,13 @@ static void regmap_parse_32_be_inplace(void *buf)
276 b[0] = be32_to_cpu(b[0]); 311 b[0] = be32_to_cpu(b[0]);
277} 312}
278 313
314static void regmap_parse_32_le_inplace(void *buf)
315{
316 __le32 *b = buf;
317
318 b[0] = le32_to_cpu(b[0]);
319}
320
279static unsigned int regmap_parse_32_native(const void *buf) 321static unsigned int regmap_parse_32_native(const void *buf)
280{ 322{
281 return *(u32 *)buf; 323 return *(u32 *)buf;
@@ -608,6 +650,11 @@ struct regmap *regmap_init(struct device *dev,
608 map->format.parse_val = regmap_parse_16_be; 650 map->format.parse_val = regmap_parse_16_be;
609 map->format.parse_inplace = regmap_parse_16_be_inplace; 651 map->format.parse_inplace = regmap_parse_16_be_inplace;
610 break; 652 break;
653 case REGMAP_ENDIAN_LITTLE:
654 map->format.format_val = regmap_format_16_le;
655 map->format.parse_val = regmap_parse_16_le;
656 map->format.parse_inplace = regmap_parse_16_le_inplace;
657 break;
611 case REGMAP_ENDIAN_NATIVE: 658 case REGMAP_ENDIAN_NATIVE:
612 map->format.format_val = regmap_format_16_native; 659 map->format.format_val = regmap_format_16_native;
613 map->format.parse_val = regmap_parse_16_native; 660 map->format.parse_val = regmap_parse_16_native;
@@ -629,6 +676,11 @@ struct regmap *regmap_init(struct device *dev,
629 map->format.parse_val = regmap_parse_32_be; 676 map->format.parse_val = regmap_parse_32_be;
630 map->format.parse_inplace = regmap_parse_32_be_inplace; 677 map->format.parse_inplace = regmap_parse_32_be_inplace;
631 break; 678 break;
679 case REGMAP_ENDIAN_LITTLE:
680 map->format.format_val = regmap_format_32_le;
681 map->format.parse_val = regmap_parse_32_le;
682 map->format.parse_inplace = regmap_parse_32_le_inplace;
683 break;
632 case REGMAP_ENDIAN_NATIVE: 684 case REGMAP_ENDIAN_NATIVE:
633 map->format.format_val = regmap_format_32_native; 685 map->format.format_val = regmap_format_32_native;
634 map->format.parse_val = regmap_parse_32_native; 686 map->format.parse_val = regmap_parse_32_native;