diff options
Diffstat (limited to 'drivers/gpio/gpiolib.c')
-rw-r--r-- | drivers/gpio/gpiolib.c | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 980c1f87866a..5db3445552b1 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c | |||
@@ -1174,15 +1174,16 @@ EXPORT_SYMBOL_GPL(gpiod_is_active_low); | |||
1174 | * that the GPIO was actually requested. | 1174 | * that the GPIO was actually requested. |
1175 | */ | 1175 | */ |
1176 | 1176 | ||
1177 | static bool _gpiod_get_raw_value(const struct gpio_desc *desc) | 1177 | static int _gpiod_get_raw_value(const struct gpio_desc *desc) |
1178 | { | 1178 | { |
1179 | struct gpio_chip *chip; | 1179 | struct gpio_chip *chip; |
1180 | bool value; | ||
1181 | int offset; | 1180 | int offset; |
1181 | int value; | ||
1182 | 1182 | ||
1183 | chip = desc->chip; | 1183 | chip = desc->chip; |
1184 | offset = gpio_chip_hwgpio(desc); | 1184 | offset = gpio_chip_hwgpio(desc); |
1185 | value = chip->get ? chip->get(chip, offset) : false; | 1185 | value = chip->get ? chip->get(chip, offset) : -EIO; |
1186 | value = value < 0 ? value : !!value; | ||
1186 | trace_gpio_value(desc_to_gpio(desc), 1, value); | 1187 | trace_gpio_value(desc_to_gpio(desc), 1, value); |
1187 | return value; | 1188 | return value; |
1188 | } | 1189 | } |
@@ -1192,7 +1193,7 @@ static bool _gpiod_get_raw_value(const struct gpio_desc *desc) | |||
1192 | * @desc: gpio whose value will be returned | 1193 | * @desc: gpio whose value will be returned |
1193 | * | 1194 | * |
1194 | * Return the GPIO's raw value, i.e. the value of the physical line disregarding | 1195 | * Return the GPIO's raw value, i.e. the value of the physical line disregarding |
1195 | * its ACTIVE_LOW status. | 1196 | * its ACTIVE_LOW status, or negative errno on failure. |
1196 | * | 1197 | * |
1197 | * This function should be called from contexts where we cannot sleep, and will | 1198 | * This function should be called from contexts where we cannot sleep, and will |
1198 | * complain if the GPIO chip functions potentially sleep. | 1199 | * complain if the GPIO chip functions potentially sleep. |
@@ -1212,7 +1213,7 @@ EXPORT_SYMBOL_GPL(gpiod_get_raw_value); | |||
1212 | * @desc: gpio whose value will be returned | 1213 | * @desc: gpio whose value will be returned |
1213 | * | 1214 | * |
1214 | * Return the GPIO's logical value, i.e. taking the ACTIVE_LOW status into | 1215 | * Return the GPIO's logical value, i.e. taking the ACTIVE_LOW status into |
1215 | * account. | 1216 | * account, or negative errno on failure. |
1216 | * | 1217 | * |
1217 | * This function should be called from contexts where we cannot sleep, and will | 1218 | * This function should be called from contexts where we cannot sleep, and will |
1218 | * complain if the GPIO chip functions potentially sleep. | 1219 | * complain if the GPIO chip functions potentially sleep. |
@@ -1226,6 +1227,9 @@ int gpiod_get_value(const struct gpio_desc *desc) | |||
1226 | WARN_ON(desc->chip->can_sleep); | 1227 | WARN_ON(desc->chip->can_sleep); |
1227 | 1228 | ||
1228 | value = _gpiod_get_raw_value(desc); | 1229 | value = _gpiod_get_raw_value(desc); |
1230 | if (value < 0) | ||
1231 | return value; | ||
1232 | |||
1229 | if (test_bit(FLAG_ACTIVE_LOW, &desc->flags)) | 1233 | if (test_bit(FLAG_ACTIVE_LOW, &desc->flags)) |
1230 | value = !value; | 1234 | value = !value; |
1231 | 1235 | ||
@@ -1548,7 +1552,7 @@ EXPORT_SYMBOL_GPL(gpiochip_unlock_as_irq); | |||
1548 | * @desc: gpio whose value will be returned | 1552 | * @desc: gpio whose value will be returned |
1549 | * | 1553 | * |
1550 | * Return the GPIO's raw value, i.e. the value of the physical line disregarding | 1554 | * Return the GPIO's raw value, i.e. the value of the physical line disregarding |
1551 | * its ACTIVE_LOW status. | 1555 | * its ACTIVE_LOW status, or negative errno on failure. |
1552 | * | 1556 | * |
1553 | * This function is to be called from contexts that can sleep. | 1557 | * This function is to be called from contexts that can sleep. |
1554 | */ | 1558 | */ |
@@ -1566,7 +1570,7 @@ EXPORT_SYMBOL_GPL(gpiod_get_raw_value_cansleep); | |||
1566 | * @desc: gpio whose value will be returned | 1570 | * @desc: gpio whose value will be returned |
1567 | * | 1571 | * |
1568 | * Return the GPIO's logical value, i.e. taking the ACTIVE_LOW status into | 1572 | * Return the GPIO's logical value, i.e. taking the ACTIVE_LOW status into |
1569 | * account. | 1573 | * account, or negative errno on failure. |
1570 | * | 1574 | * |
1571 | * This function is to be called from contexts that can sleep. | 1575 | * This function is to be called from contexts that can sleep. |
1572 | */ | 1576 | */ |
@@ -1579,6 +1583,9 @@ int gpiod_get_value_cansleep(const struct gpio_desc *desc) | |||
1579 | return 0; | 1583 | return 0; |
1580 | 1584 | ||
1581 | value = _gpiod_get_raw_value(desc); | 1585 | value = _gpiod_get_raw_value(desc); |
1586 | if (value < 0) | ||
1587 | return value; | ||
1588 | |||
1582 | if (test_bit(FLAG_ACTIVE_LOW, &desc->flags)) | 1589 | if (test_bit(FLAG_ACTIVE_LOW, &desc->flags)) |
1583 | value = !value; | 1590 | value = !value; |
1584 | 1591 | ||