From: Stephen Warren Date: Tue, 19 Aug 2014 16:49:07 +0000 (-0600) Subject: regmap: of_regmap_get_endian() cleanup X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=45e1a279ce1d2ff9b2b2fedf4cdced10c7ca3ab5;p=GitHub%2Fmoto-9609%2Fandroid_kernel_motorola_exynos9610.git 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 Cc: Javier Martinez Canillas Cc: Thierry Reding Fixes: d647c199510c ("regmap: add DT endianness binding support") Signed-off-by: Stephen Warren Signed-off-by: Mark Brown --- 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 { 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);