Skip to content

Commit 5923ea6

Browse files
author
Linus Walleij
committed
gpio: pass lookup and descriptor flags to request_own
When a gpio_chip wants to request a descriptor from itself using gpiochip_request_own_desc() it needs to be able to specify fully how to use the descriptor, notably line inversion semantics. The workaround in the gpiolib.c can be removed and cases (such as SPI CS) where we need at times to request a GPIO with line inversion semantics directly on a chip for workarounds, can be fully supported with this call. Fix up some users of the API that weren't really using the last flag to set up the line as input or output properly but instead just calling direction setting explicitly after requesting the line. Cc: Martin Sperl <kernel@martin.sperl.org> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
1 parent 0aa3ebf commit 5923ea6

8 files changed

Lines changed: 34 additions & 38 deletions

File tree

‎arch/arm/mach-omap1/ams-delta-fiq.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* the Free Software Foundation.
1515
*/
1616
#include <linux/gpio/consumer.h>
17+
#include <linux/gpio/machine.h>
1718
#include <linux/gpio/driver.h>
1819
#include <linux/interrupt.h>
1920
#include <linux/irq.h>
@@ -102,7 +103,8 @@ void __init ams_delta_init_fiq(struct gpio_chip *chip,
102103
}
103104

104105
for (i = 0; i < ARRAY_SIZE(irq_data); i++) {
105-
gpiod = gpiochip_request_own_desc(chip, i, pin_name[i], 0);
106+
gpiod = gpiochip_request_own_desc(chip, i, pin_name[i],
107+
GPIO_ACTIVE_HIGH, GPIOD_IN);
106108
if (IS_ERR(gpiod)) {
107109
pr_err("%s: failed to get GPIO pin %d (%ld)\n",
108110
__func__, i, PTR_ERR(gpiod));

‎arch/arm/mach-omap1/board-ams-delta.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*/
1414
#include <linux/gpio/driver.h>
1515
#include <linux/gpio/machine.h>
16+
#include <linux/gpio/consumer.h>
1617
#include <linux/gpio.h>
1718
#include <linux/kernel.h>
1819
#include <linux/init.h>
@@ -609,12 +610,12 @@ static void __init modem_assign_irq(struct gpio_chip *chip)
609610
struct gpio_desc *gpiod;
610611

611612
gpiod = gpiochip_request_own_desc(chip, AMS_DELTA_GPIO_PIN_MODEM_IRQ,
612-
"modem_irq", 0);
613+
"modem_irq", GPIO_ACTIVE_HIGH,
614+
GPIOD_IN);
613615
if (IS_ERR(gpiod)) {
614616
pr_err("%s: modem IRQ GPIO request failed (%ld)\n", __func__,
615617
PTR_ERR(gpiod));
616618
} else {
617-
gpiod_direction_input(gpiod);
618619
ams_delta_modem_ports[0].irq = gpiod_to_irq(gpiod);
619620
}
620621
}

‎drivers/gpio/gpio-mvebu.c‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include <linux/err.h>
3939
#include <linux/gpio/driver.h>
4040
#include <linux/gpio/consumer.h>
41+
#include <linux/gpio/machine.h>
4142
#include <linux/init.h>
4243
#include <linux/io.h>
4344
#include <linux/irq.h>
@@ -618,18 +619,14 @@ static int mvebu_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)
618619
ret = -EBUSY;
619620
} else {
620621
desc = gpiochip_request_own_desc(&mvchip->chip,
621-
pwm->hwpwm, "mvebu-pwm", 0);
622+
pwm->hwpwm, "mvebu-pwm",
623+
GPIO_ACTIVE_HIGH,
624+
GPIOD_OUT_LOW);
622625
if (IS_ERR(desc)) {
623626
ret = PTR_ERR(desc);
624627
goto out;
625628
}
626629

627-
ret = gpiod_direction_output(desc, 0);
628-
if (ret) {
629-
gpiochip_free_own_desc(desc);
630-
goto out;
631-
}
632-
633630
mvpwm->gpiod = desc;
634631
}
635632
out:

‎drivers/gpio/gpiolib-acpi.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,13 @@ static acpi_status acpi_gpiochip_alloc_event(struct acpi_resource *ares,
217217
if (!handler)
218218
return AE_OK;
219219

220-
desc = gpiochip_request_own_desc(chip, pin, "ACPI:Event", 0);
220+
desc = gpiochip_request_own_desc(chip, pin, "ACPI:Event",
221+
GPIO_ACTIVE_HIGH, GPIOD_IN);
221222
if (IS_ERR(desc)) {
222223
dev_err(chip->parent, "Failed to request GPIO\n");
223224
return AE_ERROR;
224225
}
225226

226-
gpiod_direction_input(desc);
227-
228227
ret = gpiochip_lock_as_irq(chip, pin);
229228
if (ret) {
230229
dev_err(chip->parent, "Failed to lock GPIO as interrupt\n");
@@ -951,6 +950,7 @@ acpi_gpio_adr_space_handler(u32 function, acpi_physical_address address,
951950
const char *label = "ACPI:OpRegion";
952951

953952
desc = gpiochip_request_own_desc(chip, pin, label,
953+
GPIO_ACTIVE_HIGH,
954954
flags);
955955
if (IS_ERR(desc)) {
956956
status = AE_ERROR;

‎drivers/gpio/gpiolib.c‎

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2503,7 +2503,11 @@ EXPORT_SYMBOL_GPL(gpiochip_is_requested);
25032503
* @chip: GPIO chip
25042504
* @hwnum: hardware number of the GPIO for which to request the descriptor
25052505
* @label: label for the GPIO
2506-
* @flags: flags for this GPIO or 0 if default
2506+
* @lflags: lookup flags for this GPIO or 0 if default, this can be used to
2507+
* specify things like line inversion semantics with the machine flags
2508+
* such as GPIO_OUT_LOW
2509+
* @dflags: descriptor request flags for this GPIO or 0 if default, this
2510+
* can be used to specify consumer semantics such as open drain
25072511
*
25082512
* Function allows GPIO chip drivers to request and use their own GPIO
25092513
* descriptors via gpiolib API. Difference to gpiod_request() is that this
@@ -2517,9 +2521,9 @@ EXPORT_SYMBOL_GPL(gpiochip_is_requested);
25172521
*/
25182522
struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *chip, u16 hwnum,
25192523
const char *label,
2520-
enum gpiod_flags flags)
2524+
enum gpio_lookup_flags lflags,
2525+
enum gpiod_flags dflags)
25212526
{
2522-
unsigned long lflags = GPIO_LOOKUP_FLAGS_DEFAULT;
25232527
struct gpio_desc *desc = gpiochip_get_desc(chip, hwnum);
25242528
int err;
25252529

@@ -2532,7 +2536,7 @@ struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *chip, u16 hwnum,
25322536
if (err < 0)
25332537
return ERR_PTR(err);
25342538

2535-
err = gpiod_configure_flags(desc, label, lflags, flags);
2539+
err = gpiod_configure_flags(desc, label, lflags, dflags);
25362540
if (err) {
25372541
chip_err(chip, "setup of own GPIO %s failed\n", label);
25382542
gpiod_free_commit(desc);
@@ -4420,30 +4424,15 @@ int gpiod_hog(struct gpio_desc *desc, const char *name,
44204424
chip = gpiod_to_chip(desc);
44214425
hwnum = gpio_chip_hwgpio(desc);
44224426

4423-
/*
4424-
* FIXME: not very elegant that we call gpiod_configure_flags()
4425-
* twice here (once inside gpiochip_request_own_desc() and
4426-
* again here), but the gpiochip_request_own_desc() is external
4427-
* and cannot really pass the lflags so this is the lesser evil
4428-
* at the moment. Pass zero as dflags on this first call so we
4429-
* don't screw anything up.
4430-
*/
4431-
local_desc = gpiochip_request_own_desc(chip, hwnum, name, 0);
4427+
local_desc = gpiochip_request_own_desc(chip, hwnum, name,
4428+
lflags, dflags);
44324429
if (IS_ERR(local_desc)) {
44334430
status = PTR_ERR(local_desc);
44344431
pr_err("requesting hog GPIO %s (chip %s, offset %d) failed, %d\n",
44354432
name, chip->label, hwnum, status);
44364433
return status;
44374434
}
44384435

4439-
status = gpiod_configure_flags(desc, name, lflags, dflags);
4440-
if (status < 0) {
4441-
pr_err("setup of hog GPIO %s (chip %s, offset %d) failed, %d\n",
4442-
name, chip->label, hwnum, status);
4443-
gpiochip_free_own_desc(desc);
4444-
return status;
4445-
}
4446-
44474436
/* Mark GPIO as hogged so it can be identified and removed later */
44484437
set_bit(FLAG_IS_HOGGED, &desc->flags);
44494438

‎drivers/hid/hid-cp2112.c‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
* https://www.silabs.com/documents/public/application-notes/an495-cp2112-interface-specification.pdf
2525
*/
2626

27-
#include <linux/gpio.h>
27+
#include <linux/gpio/consumer.h>
28+
#include <linux/gpio/machine.h>
2829
#include <linux/gpio/driver.h>
2930
#include <linux/hid.h>
3031
#include <linux/hidraw.h>
@@ -1203,7 +1204,9 @@ static int __maybe_unused cp2112_allocate_irq(struct cp2112_device *dev,
12031204
return -EINVAL;
12041205

12051206
dev->desc[pin] = gpiochip_request_own_desc(&dev->gc, pin,
1206-
"HID/I2C:Event", 0);
1207+
"HID/I2C:Event",
1208+
GPIO_ACTIVE_HIGH,
1209+
GPIOD_IN);
12071210
if (IS_ERR(dev->desc[pin])) {
12081211
dev_err(dev->gc.parent, "Failed to request GPIO\n");
12091212
return PTR_ERR(dev->desc[pin]);

‎drivers/memory/omap-gpmc.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <linux/io.h>
2323
#include <linux/gpio/driver.h>
2424
#include <linux/gpio/consumer.h> /* GPIO descriptor enum */
25+
#include <linux/gpio/machine.h>
2526
#include <linux/interrupt.h>
2627
#include <linux/irqdomain.h>
2728
#include <linux/platform_device.h>
@@ -2172,7 +2173,8 @@ static int gpmc_probe_generic_child(struct platform_device *pdev,
21722173

21732174
waitpin_desc = gpiochip_request_own_desc(&gpmc->gpio_chip,
21742175
wait_pin, "WAITPIN",
2175-
0);
2176+
GPIO_ACTIVE_HIGH,
2177+
GPIOD_IN);
21762178
if (IS_ERR(waitpin_desc)) {
21772179
dev_err(&pdev->dev, "invalid wait-pin: %d\n", wait_pin);
21782180
ret = PTR_ERR(waitpin_desc);

‎include/linux/gpio/driver.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ struct seq_file;
1818
struct gpio_device;
1919
struct module;
2020
enum gpiod_flags;
21+
enum gpio_lookup_flags;
2122

2223
#ifdef CONFIG_GPIOLIB
2324

@@ -614,7 +615,8 @@ gpiochip_remove_pin_ranges(struct gpio_chip *chip)
614615

615616
struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *chip, u16 hwnum,
616617
const char *label,
617-
enum gpiod_flags flags);
618+
enum gpio_lookup_flags lflags,
619+
enum gpiod_flags dflags);
618620
void gpiochip_free_own_desc(struct gpio_desc *desc);
619621

620622
void devprop_gpiochip_set_names(struct gpio_chip *chip,

0 commit comments

Comments
 (0)