aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/base/regmap/regmap.c54
1 files changed, 20 insertions, 34 deletions
diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index 055a9c3a3b12..bb4502a48be5 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -454,7 +454,7 @@ enum regmap_endian_type {
454 REGMAP_ENDIAN_VAL, 454 REGMAP_ENDIAN_VAL,
455}; 455};
456 456
457static int of_regmap_get_endian(struct device *dev, 457static int regmap_get_endian(struct device *dev,
458 const struct regmap_bus *bus, 458 const struct regmap_bus *bus,
459 const struct regmap_config *config, 459 const struct regmap_config *config,
460 enum regmap_endian_type type, 460 enum regmap_endian_type type,
@@ -465,15 +465,7 @@ static int of_regmap_get_endian(struct device *dev,
465 if (!endian || !config) 465 if (!endian || !config)
466 return -EINVAL; 466 return -EINVAL;
467 467
468 /* 468 /* Retrieve the endianness specification from the regmap config */
469 * Firstly, try to parse the endianness from driver's config,
470 * this is to be compatible with the none DT or the old drivers.
471 * From the driver's config the endianness value maybe:
472 * REGMAP_ENDIAN_BIG,
473 * REGMAP_ENDIAN_LITTLE,
474 * REGMAP_ENDIAN_NATIVE,
475 * REGMAP_ENDIAN_DEFAULT.
476 */
477 switch (type) { 469 switch (type) {
478 case REGMAP_ENDIAN_REG: 470 case REGMAP_ENDIAN_REG:
479 *endian = config->reg_format_endian; 471 *endian = config->reg_format_endian;
@@ -485,31 +477,17 @@ static int of_regmap_get_endian(struct device *dev,
485 return -EINVAL; 477 return -EINVAL;
486 } 478 }
487 479
488 /* 480 /* If the regmap config specified a non-default value, use that */
489 * If the endianness parsed from driver config is
490 * REGMAP_ENDIAN_DEFAULT, that means maybe we are using the DT
491 * node to specify the endianness information.
492 */
493 if (*endian != REGMAP_ENDIAN_DEFAULT) 481 if (*endian != REGMAP_ENDIAN_DEFAULT)
494 return 0; 482 return 0;
495 483
496 /* 484 /* Parse the device's DT node for an endianness specification */
497 * Secondly, try to parse the endianness from DT node if the
498 * driver config does not specify it.
499 * From the DT node the endianness value maybe:
500 * REGMAP_ENDIAN_BIG,
501 * REGMAP_ENDIAN_LITTLE,
502 */
503 switch (type) { 485 switch (type) {
504 case REGMAP_ENDIAN_VAL: 486 case REGMAP_ENDIAN_VAL:
505 if (of_property_read_bool(np, "big-endian")) 487 if (of_property_read_bool(np, "big-endian"))
506 *endian = REGMAP_ENDIAN_BIG; 488 *endian = REGMAP_ENDIAN_BIG;
507 else if (of_property_read_bool(np, "little-endian")) 489 else if (of_property_read_bool(np, "little-endian"))
508 *endian = REGMAP_ENDIAN_LITTLE; 490 *endian = REGMAP_ENDIAN_LITTLE;
509
510 if (*endian != REGMAP_ENDIAN_DEFAULT)
511 return 0;
512
513 break; 491 break;
514 case REGMAP_ENDIAN_REG: 492 case REGMAP_ENDIAN_REG:
515 break; 493 break;
@@ -517,10 +495,11 @@ static int of_regmap_get_endian(struct device *dev,
517 return -EINVAL; 495 return -EINVAL;
518 } 496 }
519 497
520 /* 498 /* If the endianness was specified in DT, use that */
521 * Finally, try to parse the endianness from regmap bus config 499 if (*endian != REGMAP_ENDIAN_DEFAULT)
522 * if in device's DT node the endianness property is absent. 500 return 0;
523 */ 501
502 /* Retrieve the endianness specification from the bus config */
524 switch (type) { 503 switch (type) {
525 case REGMAP_ENDIAN_REG: 504 case REGMAP_ENDIAN_REG:
526 if (bus && bus->reg_format_endian_default) 505 if (bus && bus->reg_format_endian_default)
@@ -534,6 +513,13 @@ static int of_regmap_get_endian(struct device *dev,
534 return -EINVAL; 513 return -EINVAL;
535 } 514 }
536 515
516 /* If the bus specified a non-default value, use that */
517 if (*endian != REGMAP_ENDIAN_DEFAULT)
518 return 0;
519
520 /* Use this if no other value was found */
521 *endian = REGMAP_ENDIAN_BIG;
522
537 return 0; 523 return 0;
538} 524}
539 525
@@ -640,13 +626,13 @@ struct regmap *regmap_init(struct device *dev,
640 map->reg_read = _regmap_bus_read; 626 map->reg_read = _regmap_bus_read;
641 } 627 }
642 628
643 ret = of_regmap_get_endian(dev, bus, config, REGMAP_ENDIAN_REG, 629 ret = regmap_get_endian(dev, bus, config, REGMAP_ENDIAN_REG,
644 &reg_endian); 630 &reg_endian);
645 if (ret) 631 if (ret)
646 return ERR_PTR(ret); 632 return ERR_PTR(ret);
647 633
648 ret = of_regmap_get_endian(dev, bus, config, REGMAP_ENDIAN_VAL, 634 ret = regmap_get_endian(dev, bus, config, REGMAP_ENDIAN_VAL,
649 &val_endian); 635 &val_endian);
650 if (ret) 636 if (ret)
651 return ERR_PTR(ret); 637 return ERR_PTR(ret);
652 638