aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base
diff options
context:
space:
mode:
authorStephen Warren <swarren@nvidia.com>2014-08-19 12:49:07 -0400
committerMark Brown <broonie@linaro.org>2014-08-19 17:16:51 -0400
commit45e1a279ce1d2ff9b2b2fedf4cdced10c7ca3ab5 (patch)
treeef18649470d88496209613e641e9195ed70882b1 /drivers/base
parentba1b53feb8cacbd84bcf0e48925e30ad29e141a6 (diff)
regmap: of_regmap_get_endian() cleanup
Commit d647c199510c ("regmap: add DT endianness binding support") had some issues. Commit ba1b53feb8ca ("regmap: Fix DT endianess parsing logic") fixed the main problem. This patch fixes the other. Specifically, restore the overall default of REGMAP_ENDIAN_BIG if none of the config, DT, or the bus specify any endianness. Without this, of_regmap_get_endian() could return REGMAP_ENDIAN_DEFAULT, which the calling code can't handle. Since all busses do specify an endianness in the current code, this makes no difference right now, but I saw no justification in the patch description for removing this final default. Also, clean up the code a bit: * s/of_regmap_get_endian/regmap_get_endian/ since the function isn't DT- specific, even if the reason it was originally added was to add some DT-specific features. * After potentially reading an endianess specification from DT, the code checks whether DT did specify an endianness, and if so, returns it. Move this test outside the whole switch statement so that if the REGMAP_ENDIAN_REG case ever modifies *endian, this check will pick that up. This partially reverts part of commit ba1b53feb8ca ("regmap: Fix DT endianess parsing logic"), while maintaining the bug-fix that commit made to this code. * Make the comments briefer, and only refer to the specific action taken at their location. This makes most of the comments independent of DT, and easier to follow. Cc: Xiubo Li <Li.Xiubo@freescale.com> Cc: Javier Martinez Canillas <javier.martinez@collabora.co.uk> Cc: Thierry Reding <treding@nvidia.com> Fixes: d647c199510c ("regmap: add DT endianness binding support") Signed-off-by: Stephen Warren <swarren@nvidia.com> Signed-off-by: Mark Brown <broonie@linaro.org>
Diffstat (limited to 'drivers/base')
-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