Skip to content

Commit e3186e3

Browse files
dtorBartosz Golaszewski
authored andcommitted
gpiolib: of: factor out code overriding gpio line polarity
There are several instances where we use a separate property to override polarity specified in gpio property. Factor it out into a separate function. Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
1 parent eaf1a29 commit e3186e3

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

drivers/gpio/gpiolib-of.c

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,28 @@ bool of_gpio_need_valid_mask(const struct gpio_chip *gc)
130130
return false;
131131
}
132132

133+
/*
134+
* Overrides stated polarity of a gpio line and warns when there is a
135+
* discrepancy.
136+
*/
137+
static void of_gpio_quirk_polarity(const struct device_node *np,
138+
bool active_high,
139+
enum of_gpio_flags *flags)
140+
{
141+
if (active_high) {
142+
if (*flags & OF_GPIO_ACTIVE_LOW) {
143+
pr_warn("%s GPIO handle specifies active low - ignored\n",
144+
of_node_full_name(np));
145+
*flags &= ~OF_GPIO_ACTIVE_LOW;
146+
}
147+
} else {
148+
if (!(*flags & OF_GPIO_ACTIVE_LOW))
149+
pr_info("%s enforce active low on GPIO handle\n",
150+
of_node_full_name(np));
151+
*flags |= OF_GPIO_ACTIVE_LOW;
152+
}
153+
}
154+
133155
static void of_gpio_flags_quirks(const struct device_node *np,
134156
const char *propname,
135157
enum of_gpio_flags *flags,
@@ -145,21 +167,15 @@ static void of_gpio_flags_quirks(const struct device_node *np,
145167
(!(strcmp(propname, "enable-gpio") &&
146168
strcmp(propname, "enable-gpios")) &&
147169
of_device_is_compatible(np, "regulator-gpio")))) {
148-
bool active_low = !of_property_read_bool(np,
170+
bool active_high = of_property_read_bool(np,
149171
"enable-active-high");
150172
/*
151173
* The regulator GPIO handles are specified such that the
152174
* presence or absence of "enable-active-high" solely controls
153175
* the polarity of the GPIO line. Any phandle flags must
154176
* be actively ignored.
155177
*/
156-
if ((*flags & OF_GPIO_ACTIVE_LOW) && !active_low) {
157-
pr_warn("%s GPIO handle specifies active low - ignored\n",
158-
of_node_full_name(np));
159-
*flags &= ~OF_GPIO_ACTIVE_LOW;
160-
}
161-
if (active_low)
162-
*flags |= OF_GPIO_ACTIVE_LOW;
178+
of_gpio_quirk_polarity(np, active_high, flags);
163179
}
164180
/*
165181
* Legacy open drain handling for fixed voltage regulators.
@@ -200,18 +216,10 @@ static void of_gpio_flags_quirks(const struct device_node *np,
200216
* conflict and the "spi-cs-high" flag will
201217
* take precedence.
202218
*/
203-
if (of_property_read_bool(child, "spi-cs-high")) {
204-
if (*flags & OF_GPIO_ACTIVE_LOW) {
205-
pr_warn("%s GPIO handle specifies active low - ignored\n",
206-
of_node_full_name(child));
207-
*flags &= ~OF_GPIO_ACTIVE_LOW;
208-
}
209-
} else {
210-
if (!(*flags & OF_GPIO_ACTIVE_LOW))
211-
pr_info("%s enforce active low on chipselect handle\n",
212-
of_node_full_name(child));
213-
*flags |= OF_GPIO_ACTIVE_LOW;
214-
}
219+
bool active_high = of_property_read_bool(child,
220+
"spi-cs-high");
221+
of_gpio_quirk_polarity(child, active_high,
222+
flags);
215223
of_node_put(child);
216224
break;
217225
}

0 commit comments

Comments
 (0)