| From 51aa410393648a2969fc7bbe5d23ea4009e782b2 Mon Sep 17 00:00:00 2001 |
| From: Heiko Stuebner <heiko.stuebner@bqreaders.com> |
| Date: Wed, 12 Feb 2014 01:01:08 +0100 |
| Subject: regulator: gpio-regulator: do not open-code counting and access of dt |
| array elements |
| |
| Open coding the counting of elements in a dt-property is abstracted by the newly |
| introduced of_property_count_uXX_elems functions. Additionally the raw iteration |
| over the states element exposes the endian conversion and dtb-format details, |
| which according to Mark Rutland "would be nice to limit [...] to of_ helper |
| functions". |
| |
| Thus change gpio-regulator to use the helper for element counting and |
| of_property_read_u32_index for retrieval of individual values. |
| |
| This makes it possible to remove the raw access to the states property entirely. |
| |
| Signed-off-by: Heiko Stuebner <heiko.stuebner@bqreaders.com> |
| Acked-by: Mark Rutland <mark.rutland@arm.com> |
| Signed-off-by: Mark Brown <broonie@linaro.org> |
| (cherry picked from commit 934624d6e9f0b3d41557c4105c286e8daeaadb4e) |
| Signed-off-by: Simon Horman <horms+renesas@verge.net.au> |
| --- |
| drivers/regulator/gpio-regulator.c | 15 ++++++--------- |
| 1 file changed, 6 insertions(+), 9 deletions(-) |
| |
| diff --git a/drivers/regulator/gpio-regulator.c b/drivers/regulator/gpio-regulator.c |
| index 5491ceeb53cc..9fd55611016c 100644 |
| --- a/drivers/regulator/gpio-regulator.c |
| +++ b/drivers/regulator/gpio-regulator.c |
| @@ -136,7 +136,6 @@ static struct gpio_regulator_config * |
| of_get_gpio_regulator_config(struct device *dev, struct device_node *np) |
| { |
| struct gpio_regulator_config *config; |
| - struct property *prop; |
| const char *regtype; |
| int proplen, gpio, i; |
| int ret; |
| @@ -191,14 +190,12 @@ of_get_gpio_regulator_config(struct device *dev, struct device_node *np) |
| } |
| |
| /* Fetch states. */ |
| - prop = of_find_property(np, "states", NULL); |
| - if (!prop) { |
| + proplen = of_property_count_u32_elems(np, "states"); |
| + if (proplen < 0) { |
| dev_err(dev, "No 'states' property found\n"); |
| return ERR_PTR(-EINVAL); |
| } |
| |
| - proplen = prop->length / sizeof(int); |
| - |
| config->states = devm_kzalloc(dev, |
| sizeof(struct gpio_regulator_state) |
| * (proplen / 2), |
| @@ -207,10 +204,10 @@ of_get_gpio_regulator_config(struct device *dev, struct device_node *np) |
| return ERR_PTR(-ENOMEM); |
| |
| for (i = 0; i < proplen / 2; i++) { |
| - config->states[i].value = |
| - be32_to_cpup((int *)prop->value + (i * 2)); |
| - config->states[i].gpios = |
| - be32_to_cpup((int *)prop->value + (i * 2 + 1)); |
| + of_property_read_u32_index(np, "states", i * 2, |
| + &config->states[i].value); |
| + of_property_read_u32_index(np, "states", i * 2 + 1, |
| + &config->states[i].gpios); |
| } |
| config->nr_states = i; |
| |
| -- |
| 2.1.2 |
| |