diff options
-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: |