forked from Minki/linux
regmap: of_regmap_get_endian() cleanup
Commitd647c19951
("regmap: add DT endianness binding support") had some issues. Commitba1b53feb8
("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 commitba1b53feb8
("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:
parent
ba1b53feb8
commit
45e1a279ce
@ -454,7 +454,7 @@ enum regmap_endian_type {
|
||||
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_config *config,
|
||||
enum regmap_endian_type type,
|
||||
@ -465,15 +465,7 @@ static int of_regmap_get_endian(struct device *dev,
|
||||
if (!endian || !config)
|
||||
return -EINVAL;
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
/* Retrieve the endianness specification from the regmap config */
|
||||
switch (type) {
|
||||
case REGMAP_ENDIAN_REG:
|
||||
*endian = config->reg_format_endian;
|
||||
@ -485,31 +477,17 @@ static int of_regmap_get_endian(struct device *dev,
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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 the regmap config specified a non-default value, use that */
|
||||
if (*endian != REGMAP_ENDIAN_DEFAULT)
|
||||
return 0;
|
||||
|
||||
/*
|
||||
* 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,
|
||||
*/
|
||||
/* Parse the device's DT node for an endianness specification */
|
||||
switch (type) {
|
||||
case REGMAP_ENDIAN_VAL:
|
||||
if (of_property_read_bool(np, "big-endian"))
|
||||
*endian = REGMAP_ENDIAN_BIG;
|
||||
else if (of_property_read_bool(np, "little-endian"))
|
||||
*endian = REGMAP_ENDIAN_LITTLE;
|
||||
|
||||
if (*endian != REGMAP_ENDIAN_DEFAULT)
|
||||
return 0;
|
||||
|
||||
break;
|
||||
case REGMAP_ENDIAN_REG:
|
||||
break;
|
||||
@ -517,10 +495,11 @@ static int of_regmap_get_endian(struct device *dev,
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Finally, try to parse the endianness from regmap bus config
|
||||
* if in device's DT node the endianness property is absent.
|
||||
*/
|
||||
/* If the endianness was specified in DT, use that */
|
||||
if (*endian != REGMAP_ENDIAN_DEFAULT)
|
||||
return 0;
|
||||
|
||||
/* Retrieve the endianness specification from the bus config */
|
||||
switch (type) {
|
||||
case REGMAP_ENDIAN_REG:
|
||||
if (bus && bus->reg_format_endian_default)
|
||||
@ -534,6 +513,13 @@ static int of_regmap_get_endian(struct device *dev,
|
||||
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;
|
||||
}
|
||||
|
||||
@ -640,13 +626,13 @@ struct regmap *regmap_init(struct device *dev,
|
||||
map->reg_read = _regmap_bus_read;
|
||||
}
|
||||
|
||||
ret = of_regmap_get_endian(dev, bus, config, REGMAP_ENDIAN_REG,
|
||||
®_endian);
|
||||
ret = regmap_get_endian(dev, bus, config, REGMAP_ENDIAN_REG,
|
||||
®_endian);
|
||||
if (ret)
|
||||
return ERR_PTR(ret);
|
||||
|
||||
ret = of_regmap_get_endian(dev, bus, config, REGMAP_ENDIAN_VAL,
|
||||
&val_endian);
|
||||
ret = regmap_get_endian(dev, bus, config, REGMAP_ENDIAN_VAL,
|
||||
&val_endian);
|
||||
if (ret)
|
||||
return ERR_PTR(ret);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user