gpio: Pass a flag to gpiochip_request_own_desc()
authorLinus Walleij <linus.walleij@linaro.org>
Tue, 4 Sep 2018 11:31:45 +0000 (13:31 +0200)
committerLinus Walleij <linus.walleij@linaro.org>
Fri, 14 Dec 2018 13:24:33 +0000 (14:24 +0100)
Before things go out of hand, make it possible to pass
flags when requesting "own" descriptors from a gpio_chip.
This is necessary if the chip wants to request a GPIO with
active low semantics, for example.

Cc: Janusz Krzysztofik <jmkrzyszt@gmail.com>
Cc: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Cc: Jason Cooper <jason@lakedaemon.net>
Cc: Jiri Kosina <jkosina@suse.cz>
Cc: Roger Quadros <rogerq@ti.com>
Reviewed-by: Gregory CLEMENT <gregory.clement@free-electrons.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Documentation/driver-api/gpio/driver.rst
arch/arm/mach-omap1/ams-delta-fiq.c
arch/arm/mach-omap1/board-ams-delta.c
drivers/gpio/gpio-mvebu.c
drivers/gpio/gpiolib-acpi.c
drivers/gpio/gpiolib.c
drivers/hid/hid-cp2112.c
drivers/memory/omap-gpmc.c
include/linux/gpio/driver.h

index a6c14ff0c54f5f09f0bdc546b0ca48c536c56cae..a92d8837b62bfd645d4bfe6337d09a337f684c1d 100644 (file)
@@ -434,7 +434,9 @@ try_module_get()). A GPIO driver can use the following functions instead
 to request and free descriptors without being pinned to the kernel forever::
 
        struct gpio_desc *gpiochip_request_own_desc(struct gpio_desc *desc,
-                                                   const char *label)
+                                                   u16 hwnum,
+                                                   const char *label,
+                                                   enum gpiod_flags flags)
 
        void gpiochip_free_own_desc(struct gpio_desc *desc)
 
index b0dc7ddf5877d70eeda21df28b331acdf99a4cdb..0324d0f209eab7deb0f1f8e391427a0fac88bc58 100644 (file)
@@ -103,7 +103,7 @@ void __init ams_delta_init_fiq(struct gpio_chip *chip,
        }
 
        for (i = 0; i < ARRAY_SIZE(irq_data); i++) {
-               gpiod = gpiochip_request_own_desc(chip, i, pin_name[i]);
+               gpiod = gpiochip_request_own_desc(chip, i, pin_name[i], 0);
                if (IS_ERR(gpiod)) {
                        pr_err("%s: failed to get GPIO pin %d (%ld)\n",
                               __func__, i, PTR_ERR(gpiod));
index 3d191fd52910f154d08b97432efc2f1701e58503..6719e139eb62ea6b9ebdc0365a1a6b532f147fbe 100644 (file)
@@ -808,7 +808,7 @@ static void __init ams_delta_led_init(struct gpio_chip *chip)
        int i;
 
        for (i = LATCH1_PIN_LED_CAMERA; i < LATCH1_PIN_DOCKIT1; i++) {
-               gpiod = gpiochip_request_own_desc(chip, i, NULL);
+               gpiod = gpiochip_request_own_desc(chip, i, "camera-led", 0);
                if (IS_ERR(gpiod)) {
                        pr_warn("%s: %s GPIO %d request failed (%ld)\n",
                                __func__, LATCH1_LABEL, i, PTR_ERR(gpiod));
index 6e02148c208b2cc600d75263d1c87064db2ebc23..6c675c5accbafddf78e8bdf329844c20441edb8f 100644 (file)
@@ -608,7 +608,7 @@ static int mvebu_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)
                ret = -EBUSY;
        } else {
                desc = gpiochip_request_own_desc(&mvchip->chip,
-                                                pwm->hwpwm, "mvebu-pwm");
+                                                pwm->hwpwm, "mvebu-pwm", 0);
                if (IS_ERR(desc)) {
                        ret = PTR_ERR(desc);
                        goto out;
index 55b72fbe163169c29766fbb6e24f58ccfdfd62c2..722a9befa8a978da2ad86433fe752ce34853fc8e 100644 (file)
@@ -167,7 +167,7 @@ static acpi_status acpi_gpiochip_request_interrupt(struct acpi_resource *ares,
        if (!handler)
                return AE_OK;
 
-       desc = gpiochip_request_own_desc(chip, pin, "ACPI:Event");
+       desc = gpiochip_request_own_desc(chip, pin, "ACPI:Event", 0);
        if (IS_ERR(desc)) {
                dev_err(chip->parent, "Failed to request GPIO\n");
                return AE_ERROR;
@@ -884,21 +884,14 @@ acpi_gpio_adr_space_handler(u32 function, acpi_physical_address address,
                        const char *label = "ACPI:OpRegion";
                        int err;
 
-                       desc = gpiochip_request_own_desc(chip, pin, label);
+                       desc = gpiochip_request_own_desc(chip, pin, label,
+                                                        flags);
                        if (IS_ERR(desc)) {
                                status = AE_ERROR;
                                mutex_unlock(&achip->conn_lock);
                                goto out;
                        }
 
-                       err = gpiod_configure_flags(desc, label, 0, flags);
-                       if (err < 0) {
-                               status = AE_NOT_CONFIGURED;
-                               gpiochip_free_own_desc(desc);
-                               mutex_unlock(&achip->conn_lock);
-                               goto out;
-                       }
-
                        conn = kzalloc(sizeof(*conn), GFP_KERNEL);
                        if (!conn) {
                                status = AE_NO_MEMORY;
index d61fdcb26fbd44543a43b285bd38364ab48b412d..2ec8b0d2096aa35bbbb87eee660605736cc287a4 100644 (file)
@@ -2454,6 +2454,7 @@ EXPORT_SYMBOL_GPL(gpiochip_is_requested);
  * @chip: GPIO chip
  * @hwnum: hardware number of the GPIO for which to request the descriptor
  * @label: label for the GPIO
+ * @flags: flags for this GPIO or 0 if default
  *
  * Function allows GPIO chip drivers to request and use their own GPIO
  * descriptors via gpiolib API. Difference to gpiod_request() is that this
@@ -2466,7 +2467,8 @@ EXPORT_SYMBOL_GPL(gpiochip_is_requested);
  * code on failure.
  */
 struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *chip, u16 hwnum,
-                                           const char *label)
+                                           const char *label,
+                                           enum gpiod_flags flags)
 {
        struct gpio_desc *desc = gpiochip_get_desc(chip, hwnum);
        int err;
@@ -2480,6 +2482,13 @@ struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *chip, u16 hwnum,
        if (err < 0)
                return ERR_PTR(err);
 
+       err = gpiod_configure_flags(desc, label, 0, flags);
+       if (err) {
+               chip_err(chip, "setup of own GPIO %s failed\n", label);
+               gpiod_free_commit(desc);
+               return ERR_PTR(err);
+       }
+
        return desc;
 }
 EXPORT_SYMBOL_GPL(gpiochip_request_own_desc);
@@ -4332,7 +4341,15 @@ int gpiod_hog(struct gpio_desc *desc, const char *name,
        chip = gpiod_to_chip(desc);
        hwnum = gpio_chip_hwgpio(desc);
 
-       local_desc = gpiochip_request_own_desc(chip, hwnum, name);
+       /*
+        * FIXME: not very elegant that we call gpiod_configure_flags()
+        * twice here (once inside gpiochip_request_own_desc() and
+        * again here), but the gpiochip_request_own_desc() is external
+        * and cannot really pass the lflags so this is the lesser evil
+        * at the moment. Pass zero as dflags on this first call so we
+        * don't screw anything up.
+        */
+       local_desc = gpiochip_request_own_desc(chip, hwnum, name, 0);
        if (IS_ERR(local_desc)) {
                status = PTR_ERR(local_desc);
                pr_err("requesting hog GPIO %s (chip %s, offset %d) failed, %d\n",
index 271f31461da427d93459632b096c578d71f3ee44..47f65857408df5c3e7d0bce84060ce57b3c8f3ae 100644 (file)
@@ -1203,7 +1203,7 @@ static int __maybe_unused cp2112_allocate_irq(struct cp2112_device *dev,
                return -EINVAL;
 
        dev->desc[pin] = gpiochip_request_own_desc(&dev->gc, pin,
-                                                  "HID/I2C:Event");
+                                                  "HID/I2C:Event", 0);
        if (IS_ERR(dev->desc[pin])) {
                dev_err(dev->gc.parent, "Failed to request GPIO\n");
                return PTR_ERR(dev->desc[pin]);
index c215287e80cf3bbff8d452f53bf097fba39148dd..b9b4f7058b05b9d6a7f7f760f81dfb296d4039ae 100644 (file)
@@ -2170,7 +2170,8 @@ static int gpmc_probe_generic_child(struct platform_device *pdev,
                unsigned int wait_pin = gpmc_s.wait_pin;
 
                waitpin_desc = gpiochip_request_own_desc(&gpmc->gpio_chip,
-                                                        wait_pin, "WAITPIN");
+                                                        wait_pin, "WAITPIN",
+                                                        0);
                if (IS_ERR(waitpin_desc)) {
                        dev_err(&pdev->dev, "invalid wait-pin: %d\n", wait_pin);
                        ret = PTR_ERR(waitpin_desc);
index 9c8d5d491680c95c0c2229496b86fe22a0ad7869..07cddbf45186c846b11e39d3ac539d982a46b10e 100644 (file)
@@ -17,6 +17,7 @@ struct device_node;
 struct seq_file;
 struct gpio_device;
 struct module;
+enum gpiod_flags;
 
 #ifdef CONFIG_GPIOLIB
 
@@ -604,7 +605,8 @@ gpiochip_remove_pin_ranges(struct gpio_chip *chip)
 #endif /* CONFIG_PINCTRL */
 
 struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *chip, u16 hwnum,
-                                           const char *label);
+                                           const char *label,
+                                           enum gpiod_flags flags);
 void gpiochip_free_own_desc(struct gpio_desc *desc);
 
 #else /* CONFIG_GPIOLIB */