diff options
author | Geert Uytterhoeven <geert+renesas@glider.be> | 2014-08-27 10:36:03 -0400 |
---|---|---|
committer | Mark Brown <broonie@linaro.org> | 2014-08-27 12:45:56 -0400 |
commit | cf673fbc6342b1c2310cdfdc4ed99f18f866b8e4 (patch) | |
tree | 49954b4cd132431f9c3c3d6e0ced4c1e0cf7d3c7 /drivers/base/regmap | |
parent | 45e1a279ce1d2ff9b2b2fedf4cdced10c7ca3ab5 (diff) |
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>
Diffstat (limited to 'drivers/base/regmap')
-rw-r--r-- | drivers/base/regmap/regmap.c | 107 |
1 files changed, 43 insertions, 64 deletions
diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index bb4502a48be5..01ae4b829360 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c | |||
@@ -449,78 +449,64 @@ int regmap_attach_dev(struct device *dev, struct regmap *map, | |||
449 | } | 449 | } |
450 | EXPORT_SYMBOL_GPL(regmap_attach_dev); | 450 | EXPORT_SYMBOL_GPL(regmap_attach_dev); |
451 | 451 | ||
452 | enum regmap_endian_type { | 452 | static enum regmap_endian regmap_get_reg_endian(const struct regmap_bus *bus, |
453 | REGMAP_ENDIAN_REG, | 453 | const struct regmap_config *config) |
454 | REGMAP_ENDIAN_VAL, | 454 | { |
455 | }; | 455 | enum regmap_endian endian; |
456 | 456 | ||
457 | static int regmap_get_endian(struct device *dev, | 457 | /* Retrieve the endianness specification from the regmap config */ |
458 | const struct regmap_bus *bus, | 458 | endian = config->reg_format_endian; |
459 | const struct regmap_config *config, | 459 | |
460 | enum regmap_endian_type type, | 460 | /* If the regmap config specified a non-default value, use that */ |
461 | enum regmap_endian *endian) | 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) | ||
462 | { | 479 | { |
463 | struct device_node *np = dev->of_node; | 480 | struct device_node *np = dev->of_node; |
464 | 481 | enum regmap_endian endian; | |
465 | if (!endian || !config) | ||
466 | return -EINVAL; | ||
467 | 482 | ||
468 | /* Retrieve the endianness specification from the regmap config */ | 483 | /* Retrieve the endianness specification from the regmap config */ |
469 | switch (type) { | 484 | endian = config->val_format_endian; |
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 | } | ||
479 | 485 | ||
480 | /* If the regmap config specified a non-default value, use that */ | 486 | /* If the regmap config specified a non-default value, use that */ |
481 | if (*endian != REGMAP_ENDIAN_DEFAULT) | 487 | if (endian != REGMAP_ENDIAN_DEFAULT) |
482 | return 0; | 488 | return endian; |
483 | 489 | ||
484 | /* Parse the device's DT node for an endianness specification */ | 490 | /* Parse the device's DT node for an endianness specification */ |
485 | switch (type) { | 491 | if (of_property_read_bool(np, "big-endian")) |
486 | case REGMAP_ENDIAN_VAL: | 492 | endian = REGMAP_ENDIAN_BIG; |
487 | if (of_property_read_bool(np, "big-endian")) | 493 | else if (of_property_read_bool(np, "little-endian")) |
488 | *endian = REGMAP_ENDIAN_BIG; | 494 | endian = REGMAP_ENDIAN_LITTLE; |
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 | } | ||
497 | 495 | ||
498 | /* If the endianness was specified in DT, use that */ | 496 | /* If the endianness was specified in DT, use that */ |
499 | if (*endian != REGMAP_ENDIAN_DEFAULT) | 497 | if (endian != REGMAP_ENDIAN_DEFAULT) |
500 | return 0; | 498 | return endian; |
501 | 499 | ||
502 | /* Retrieve the endianness specification from the bus config */ | 500 | /* Retrieve the endianness specification from the bus config */ |
503 | switch (type) { | 501 | if (bus && bus->val_format_endian_default) |
504 | case REGMAP_ENDIAN_REG: | 502 | endian = bus->val_format_endian_default; |
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 | } | ||
515 | 503 | ||
516 | /* If the bus specified a non-default value, use that */ | 504 | /* If the bus specified a non-default value, use that */ |
517 | if (*endian != REGMAP_ENDIAN_DEFAULT) | 505 | if (endian != REGMAP_ENDIAN_DEFAULT) |
518 | return 0; | 506 | return endian; |
519 | 507 | ||
520 | /* Use this if no other value was found */ | 508 | /* Use this if no other value was found */ |
521 | *endian = REGMAP_ENDIAN_BIG; | 509 | return REGMAP_ENDIAN_BIG; |
522 | |||
523 | return 0; | ||
524 | } | 510 | } |
525 | 511 | ||
526 | /** | 512 | /** |
@@ -626,15 +612,8 @@ struct regmap *regmap_init(struct device *dev, | |||
626 | map->reg_read = _regmap_bus_read; | 612 | map->reg_read = _regmap_bus_read; |
627 | } | 613 | } |
628 | 614 | ||
629 | ret = regmap_get_endian(dev, bus, config, REGMAP_ENDIAN_REG, | 615 | reg_endian = regmap_get_reg_endian(bus, config); |
630 | ®_endian); | 616 | val_endian = regmap_get_val_endian(dev, bus, config); |
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); | ||
638 | 617 | ||
639 | switch (config->reg_bits + map->reg_shift) { | 618 | switch (config->reg_bits + map->reg_shift) { |
640 | case 2: | 619 | case 2: |