Skip to content

Commit cf673fb

Browse files
geertubroonie
authored andcommitted
regmap: Split regmap_get_endian() in two functions
Split regmap_get_endian() in two functions, regmap_get_reg_endian() and regmap_get_val_endian(). This allows to: - Get rid of the three switch()es on "type", incl. error handling in three "default" cases, - Get rid of the regmap_endian_type enum, - Get rid of the non-NULL check of "config" (regmap_init() already checks for that), - Get rid of the "endian" output parameters, and just return the regmap_endian enum value, as the functions can no longer fail. This saves 21 lines of code (despite the still-present one-comment-per-line over-documentation), and 30 bytes of code on ARM V7. Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be> Reviewed-by: Stephen Warren <swarren@nvidia.com> Signed-off-by: Mark Brown <broonie@linaro.org>
1 parent 45e1a27 commit cf673fb

1 file changed

Lines changed: 43 additions & 64 deletions

File tree

‎drivers/base/regmap/regmap.c‎

Lines changed: 43 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -449,78 +449,64 @@ int regmap_attach_dev(struct device *dev, struct regmap *map,
449449
}
450450
EXPORT_SYMBOL_GPL(regmap_attach_dev);
451451

452-
enum regmap_endian_type {
453-
REGMAP_ENDIAN_REG,
454-
REGMAP_ENDIAN_VAL,
455-
};
452+
static enum regmap_endian regmap_get_reg_endian(const struct regmap_bus *bus,
453+
const struct regmap_config *config)
454+
{
455+
enum regmap_endian endian;
456456

457-
static int regmap_get_endian(struct device *dev,
458-
const struct regmap_bus *bus,
459-
const struct regmap_config *config,
460-
enum regmap_endian_type type,
461-
enum regmap_endian *endian)
457+
/* Retrieve the endianness specification from the regmap config */
458+
endian = config->reg_format_endian;
459+
460+
/* If the regmap config specified a non-default value, use that */
461+
if (endian != REGMAP_ENDIAN_DEFAULT)
462+
return endian;
463+
464+
/* Retrieve the endianness specification from the bus config */
465+
if (bus && bus->reg_format_endian_default)
466+
endian = bus->reg_format_endian_default;
467+
468+
/* If the bus specified a non-default value, use that */
469+
if (endian != REGMAP_ENDIAN_DEFAULT)
470+
return endian;
471+
472+
/* Use this if no other value was found */
473+
return REGMAP_ENDIAN_BIG;
474+
}
475+
476+
static enum regmap_endian regmap_get_val_endian(struct device *dev,
477+
const struct regmap_bus *bus,
478+
const struct regmap_config *config)
462479
{
463480
struct device_node *np = dev->of_node;
464-
465-
if (!endian || !config)
466-
return -EINVAL;
481+
enum regmap_endian endian;
467482

468483
/* Retrieve the endianness specification from the regmap config */
469-
switch (type) {
470-
case REGMAP_ENDIAN_REG:
471-
*endian = config->reg_format_endian;
472-
break;
473-
case REGMAP_ENDIAN_VAL:
474-
*endian = config->val_format_endian;
475-
break;
476-
default:
477-
return -EINVAL;
478-
}
484+
endian = config->val_format_endian;
479485

480486
/* If the regmap config specified a non-default value, use that */
481-
if (*endian != REGMAP_ENDIAN_DEFAULT)
482-
return 0;
487+
if (endian != REGMAP_ENDIAN_DEFAULT)
488+
return endian;
483489

484490
/* Parse the device's DT node for an endianness specification */
485-
switch (type) {
486-
case REGMAP_ENDIAN_VAL:
487-
if (of_property_read_bool(np, "big-endian"))
488-
*endian = REGMAP_ENDIAN_BIG;
489-
else if (of_property_read_bool(np, "little-endian"))
490-
*endian = REGMAP_ENDIAN_LITTLE;
491-
break;
492-
case REGMAP_ENDIAN_REG:
493-
break;
494-
default:
495-
return -EINVAL;
496-
}
491+
if (of_property_read_bool(np, "big-endian"))
492+
endian = REGMAP_ENDIAN_BIG;
493+
else if (of_property_read_bool(np, "little-endian"))
494+
endian = REGMAP_ENDIAN_LITTLE;
497495

498496
/* If the endianness was specified in DT, use that */
499-
if (*endian != REGMAP_ENDIAN_DEFAULT)
500-
return 0;
497+
if (endian != REGMAP_ENDIAN_DEFAULT)
498+
return endian;
501499

502500
/* Retrieve the endianness specification from the bus config */
503-
switch (type) {
504-
case REGMAP_ENDIAN_REG:
505-
if (bus && bus->reg_format_endian_default)
506-
*endian = bus->reg_format_endian_default;
507-
break;
508-
case REGMAP_ENDIAN_VAL:
509-
if (bus && bus->val_format_endian_default)
510-
*endian = bus->val_format_endian_default;
511-
break;
512-
default:
513-
return -EINVAL;
514-
}
501+
if (bus && bus->val_format_endian_default)
502+
endian = bus->val_format_endian_default;
515503

516504
/* If the bus specified a non-default value, use that */
517-
if (*endian != REGMAP_ENDIAN_DEFAULT)
518-
return 0;
505+
if (endian != REGMAP_ENDIAN_DEFAULT)
506+
return endian;
519507

520508
/* Use this if no other value was found */
521-
*endian = REGMAP_ENDIAN_BIG;
522-
523-
return 0;
509+
return REGMAP_ENDIAN_BIG;
524510
}
525511

526512
/**
@@ -626,15 +612,8 @@ struct regmap *regmap_init(struct device *dev,
626612
map->reg_read = _regmap_bus_read;
627613
}
628614

629-
ret = regmap_get_endian(dev, bus, config, REGMAP_ENDIAN_REG,
630-
&reg_endian);
631-
if (ret)
632-
return ERR_PTR(ret);
633-
634-
ret = regmap_get_endian(dev, bus, config, REGMAP_ENDIAN_VAL,
635-
&val_endian);
636-
if (ret)
637-
return ERR_PTR(ret);
615+
reg_endian = regmap_get_reg_endian(bus, config);
616+
val_endian = regmap_get_val_endian(dev, bus, config);
638617

639618
switch (config->reg_bits + map->reg_shift) {
640619
case 2:

0 commit comments

Comments
 (0)