regmap: of_regmap_get_endian() cleanup

Commit d647c19951 ("regmap: add DT endianness binding support") had
some issues. Commit ba1b53feb8 ("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 ba1b53feb8 ("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: d647c19951 ("regmap: add DT endianness binding support")
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
This commit is contained in:
Stephen Warren 2014-08-19 10:49:07 -06:00 committed by Mark Brown
parent ba1b53feb8
commit 45e1a279ce

View File

@ -454,7 +454,7 @@ enum regmap_endian_type {
REGMAP_ENDIAN_VAL, REGMAP_ENDIAN_VAL,
}; };
static int of_regmap_get_endian(struct device *dev, static int regmap_get_endian(struct device *dev,
const struct regmap_bus *bus, const struct regmap_bus *bus,
const struct regmap_config *config, const struct regmap_config *config,
enum regmap_endian_type type, enum regmap_endian_type type,
@ -465,15 +465,7 @@ static int of_regmap_get_endian(struct device *dev,
if (!endian || !config) if (!endian || !config)
return -EINVAL; return -EINVAL;
/* /* Retrieve the endianness specification from the regmap config */
* Firstly, try to parse the endianness from driver's config,
* this is to be compatible with the none DT or the old drivers.
* From the driver's config the endianness value maybe:
* REGMAP_ENDIAN_BIG,
* REGMAP_ENDIAN_LITTLE,
* REGMAP_ENDIAN_NATIVE,
* REGMAP_ENDIAN_DEFAULT.
*/
switch (type) { switch (type) {
case REGMAP_ENDIAN_REG: case REGMAP_ENDIAN_REG:
*endian = config->reg_format_endian; *endian = config->reg_format_endian;
@ -485,31 +477,17 @@ static int of_regmap_get_endian(struct device *dev,
return -EINVAL; return -EINVAL;
} }
/* /* If the regmap config specified a non-default value, use that */
* If the endianness parsed from driver config is
* REGMAP_ENDIAN_DEFAULT, that means maybe we are using the DT
* node to specify the endianness information.
*/
if (*endian != REGMAP_ENDIAN_DEFAULT) if (*endian != REGMAP_ENDIAN_DEFAULT)
return 0; return 0;
/* /* Parse the device's DT node for an endianness specification */
* Secondly, try to parse the endianness from DT node if the
* driver config does not specify it.
* From the DT node the endianness value maybe:
* REGMAP_ENDIAN_BIG,
* REGMAP_ENDIAN_LITTLE,
*/
switch (type) { switch (type) {
case REGMAP_ENDIAN_VAL: case REGMAP_ENDIAN_VAL:
if (of_property_read_bool(np, "big-endian")) if (of_property_read_bool(np, "big-endian"))
*endian = REGMAP_ENDIAN_BIG; *endian = REGMAP_ENDIAN_BIG;
else if (of_property_read_bool(np, "little-endian")) else if (of_property_read_bool(np, "little-endian"))
*endian = REGMAP_ENDIAN_LITTLE; *endian = REGMAP_ENDIAN_LITTLE;
if (*endian != REGMAP_ENDIAN_DEFAULT)
return 0;
break; break;
case REGMAP_ENDIAN_REG: case REGMAP_ENDIAN_REG:
break; break;
@ -517,10 +495,11 @@ static int of_regmap_get_endian(struct device *dev,
return -EINVAL; return -EINVAL;
} }
/* /* If the endianness was specified in DT, use that */
* Finally, try to parse the endianness from regmap bus config if (*endian != REGMAP_ENDIAN_DEFAULT)
* if in device's DT node the endianness property is absent. return 0;
*/
/* Retrieve the endianness specification from the bus config */
switch (type) { switch (type) {
case REGMAP_ENDIAN_REG: case REGMAP_ENDIAN_REG:
if (bus && bus->reg_format_endian_default) if (bus && bus->reg_format_endian_default)
@ -534,6 +513,13 @@ static int of_regmap_get_endian(struct device *dev,
return -EINVAL; return -EINVAL;
} }
/* If the bus specified a non-default value, use that */
if (*endian != REGMAP_ENDIAN_DEFAULT)
return 0;
/* Use this if no other value was found */
*endian = REGMAP_ENDIAN_BIG;
return 0; return 0;
} }
@ -640,13 +626,13 @@ struct regmap *regmap_init(struct device *dev,
map->reg_read = _regmap_bus_read; map->reg_read = _regmap_bus_read;
} }
ret = of_regmap_get_endian(dev, bus, config, REGMAP_ENDIAN_REG, ret = regmap_get_endian(dev, bus, config, REGMAP_ENDIAN_REG,
&reg_endian); &reg_endian);
if (ret) if (ret)
return ERR_PTR(ret); return ERR_PTR(ret);
ret = of_regmap_get_endian(dev, bus, config, REGMAP_ENDIAN_VAL, ret = regmap_get_endian(dev, bus, config, REGMAP_ENDIAN_VAL,
&val_endian); &val_endian);
if (ret) if (ret)
return ERR_PTR(ret); return ERR_PTR(ret);