diff options
-rw-r--r-- | drivers/regulator/gpio-regulator.c | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/drivers/regulator/gpio-regulator.c b/drivers/regulator/gpio-regulator.c index 9fd55611016c..989b23b377c0 100644 --- a/drivers/regulator/gpio-regulator.c +++ b/drivers/regulator/gpio-regulator.c | |||
@@ -171,13 +171,14 @@ of_get_gpio_regulator_config(struct device *dev, struct device_node *np) | |||
171 | if (!config->gpios) | 171 | if (!config->gpios) |
172 | return ERR_PTR(-ENOMEM); | 172 | return ERR_PTR(-ENOMEM); |
173 | 173 | ||
174 | prop = of_find_property(np, "gpios-states", NULL); | 174 | proplen = of_property_count_u32_elems(np, "gpios-states"); |
175 | if (prop) { | 175 | /* optional property */ |
176 | proplen = prop->length / sizeof(int); | 176 | if (proplen < 0) |
177 | if (proplen != config->nr_gpios) { | 177 | proplen = 0; |
178 | dev_warn(dev, "gpios <-> gpios-states mismatch\n"); | 178 | |
179 | prop = NULL; | 179 | if (proplen > 0 && proplen != config->nr_gpios) { |
180 | } | 180 | dev_warn(dev, "gpios <-> gpios-states mismatch\n"); |
181 | proplen = 0; | ||
181 | } | 182 | } |
182 | 183 | ||
183 | for (i = 0; i < config->nr_gpios; i++) { | 184 | for (i = 0; i < config->nr_gpios; i++) { |
@@ -185,8 +186,11 @@ of_get_gpio_regulator_config(struct device *dev, struct device_node *np) | |||
185 | if (gpio < 0) | 186 | if (gpio < 0) |
186 | break; | 187 | break; |
187 | config->gpios[i].gpio = gpio; | 188 | config->gpios[i].gpio = gpio; |
188 | if (prop && be32_to_cpup((int *)prop->value + i)) | 189 | if (proplen > 0) { |
189 | config->gpios[i].flags = GPIOF_OUT_INIT_HIGH; | 190 | of_property_read_u32_index(np, "gpios-states", i, &ret); |
191 | if (ret) | ||
192 | config->gpios[i].flags = GPIOF_OUT_INIT_HIGH; | ||
193 | } | ||
190 | } | 194 | } |
191 | 195 | ||
192 | /* Fetch states. */ | 196 | /* Fetch states. */ |