Skip to content

Commit 0600044

Browse files
andy-shevbroonie
authored andcommitted
regmap: Make use of get_unaligned_be24(), put_unaligned_be24()
Since we have a proper endianness converters for BE 24-bit data use them. While at it, format the code using switch-cases as it's done for the rest of the endianness handlers. Signed-off-by: Andy Shevchenko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 568035b commit 0600044

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

drivers/base/regmap/regmap.c

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -288,15 +288,9 @@ static void regmap_format_16_native(void *buf, unsigned int val,
288288
memcpy(buf, &v, sizeof(v));
289289
}
290290

291-
static void regmap_format_24(void *buf, unsigned int val, unsigned int shift)
291+
static void regmap_format_24_be(void *buf, unsigned int val, unsigned int shift)
292292
{
293-
u8 *b = buf;
294-
295-
val <<= shift;
296-
297-
b[0] = val >> 16;
298-
b[1] = val >> 8;
299-
b[2] = val;
293+
put_unaligned_be24(val << shift, buf);
300294
}
301295

302296
static void regmap_format_32_be(void *buf, unsigned int val, unsigned int shift)
@@ -380,14 +374,9 @@ static unsigned int regmap_parse_16_native(const void *buf)
380374
return v;
381375
}
382376

383-
static unsigned int regmap_parse_24(const void *buf)
377+
static unsigned int regmap_parse_24_be(const void *buf)
384378
{
385-
const u8 *b = buf;
386-
unsigned int ret = b[2];
387-
ret |= ((unsigned int)b[1]) << 8;
388-
ret |= ((unsigned int)b[0]) << 16;
389-
390-
return ret;
379+
return get_unaligned_be24(buf);
391380
}
392381

393382
static unsigned int regmap_parse_32_be(const void *buf)
@@ -991,9 +980,13 @@ struct regmap *__regmap_init(struct device *dev,
991980
break;
992981

993982
case 24:
994-
if (reg_endian != REGMAP_ENDIAN_BIG)
983+
switch (reg_endian) {
984+
case REGMAP_ENDIAN_BIG:
985+
map->format.format_reg = regmap_format_24_be;
986+
break;
987+
default:
995988
goto err_hwlock;
996-
map->format.format_reg = regmap_format_24;
989+
}
997990
break;
998991

999992
case 32:
@@ -1064,10 +1057,14 @@ struct regmap *__regmap_init(struct device *dev,
10641057
}
10651058
break;
10661059
case 24:
1067-
if (val_endian != REGMAP_ENDIAN_BIG)
1060+
switch (val_endian) {
1061+
case REGMAP_ENDIAN_BIG:
1062+
map->format.format_val = regmap_format_24_be;
1063+
map->format.parse_val = regmap_parse_24_be;
1064+
break;
1065+
default:
10681066
goto err_hwlock;
1069-
map->format.format_val = regmap_format_24;
1070-
map->format.parse_val = regmap_parse_24;
1067+
}
10711068
break;
10721069
case 32:
10731070
switch (val_endian) {

0 commit comments

Comments
 (0)