Skip to content

Commit 45e1a27

Browse files
Stephen Warrenbroonie
authored andcommitted
regmap: of_regmap_get_endian() cleanup
Commit d647c19 ("regmap: add DT endianness binding support") had some issues. Commit ba1b53f ("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 ba1b53f ("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: d647c19 ("regmap: add DT endianness binding support") Signed-off-by: Stephen Warren <swarren@nvidia.com> Signed-off-by: Mark Brown <broonie@linaro.org>
1 parent ba1b53f commit 45e1a27

1 file changed

Lines changed: 20 additions & 34 deletions

File tree

‎drivers/base/regmap/regmap.c‎

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ enum regmap_endian_type {
454454
REGMAP_ENDIAN_VAL,
455455
};
456456

457-
static int of_regmap_get_endian(struct device *dev,
457+
static int regmap_get_endian(struct device *dev,
458458
const struct regmap_bus *bus,
459459
const struct regmap_config *config,
460460
enum regmap_endian_type type,
@@ -465,15 +465,7 @@ static int of_regmap_get_endian(struct device *dev,
465465
if (!endian || !config)
466466
return -EINVAL;
467467

468-
/*
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-
*/
468+
/* Retrieve the endianness specification from the regmap config */
477469
switch (type) {
478470
case REGMAP_ENDIAN_REG:
479471
*endian = config->reg_format_endian;
@@ -485,42 +477,29 @@ static int of_regmap_get_endian(struct device *dev,
485477
return -EINVAL;
486478
}
487479

488-
/*
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-
*/
480+
/* If the regmap config specified a non-default value, use that */
493481
if (*endian != REGMAP_ENDIAN_DEFAULT)
494482
return 0;
495483

496-
/*
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-
*/
484+
/* Parse the device's DT node for an endianness specification */
503485
switch (type) {
504486
case REGMAP_ENDIAN_VAL:
505487
if (of_property_read_bool(np, "big-endian"))
506488
*endian = REGMAP_ENDIAN_BIG;
507489
else if (of_property_read_bool(np, "little-endian"))
508490
*endian = REGMAP_ENDIAN_LITTLE;
509-
510-
if (*endian != REGMAP_ENDIAN_DEFAULT)
511-
return 0;
512-
513491
break;
514492
case REGMAP_ENDIAN_REG:
515493
break;
516494
default:
517495
return -EINVAL;
518496
}
519497

520-
/*
521-
* Finally, try to parse the endianness from regmap bus config
522-
* if in device's DT node the endianness property is absent.
523-
*/
498+
/* If the endianness was specified in DT, use that */
499+
if (*endian != REGMAP_ENDIAN_DEFAULT)
500+
return 0;
501+
502+
/* Retrieve the endianness specification from the bus config */
524503
switch (type) {
525504
case REGMAP_ENDIAN_REG:
526505
if (bus && bus->reg_format_endian_default)
@@ -534,6 +513,13 @@ static int of_regmap_get_endian(struct device *dev,
534513
return -EINVAL;
535514
}
536515

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+
537523
return 0;
538524
}
539525

@@ -640,13 +626,13 @@ struct regmap *regmap_init(struct device *dev,
640626
map->reg_read = _regmap_bus_read;
641627
}
642628

643-
ret = of_regmap_get_endian(dev, bus, config, REGMAP_ENDIAN_REG,
644-
&reg_endian);
629+
ret = regmap_get_endian(dev, bus, config, REGMAP_ENDIAN_REG,
630+
&reg_endian);
645631
if (ret)
646632
return ERR_PTR(ret);
647633

648-
ret = of_regmap_get_endian(dev, bus, config, REGMAP_ENDIAN_VAL,
649-
&val_endian);
634+
ret = regmap_get_endian(dev, bus, config, REGMAP_ENDIAN_VAL,
635+
&val_endian);
650636
if (ret)
651637
return ERR_PTR(ret);
652638

0 commit comments

Comments
 (0)