]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/commitdiff
Merge tag 'gpio-v4.10-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw...
authorLinus Torvalds <torvalds@linux-foundation.org>
Tue, 13 Dec 2016 15:54:57 +0000 (07:54 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 13 Dec 2016 15:54:57 +0000 (07:54 -0800)
Pull GPIO updates from Luinus Walleij:
 "Bulk GPIO changes for the v4.10 kernel cycle:

  Core changes:

   - Simplify threaded interrupt handling: instead of passing numbed
     parameters to gpiochip_irqchip_add_chained() we create a new call:
     gpiochip_irqchip_add_nested() so the two types are clearly
     semantically different. Also make sure that all nested chips call
     gpiochip_set_nested_irqchip() which is necessary for IRQ resend to
     work properly if it happens.

   - Return error on seek operations for the chardev.

   - Clamp values set as part of gpio[d]_direction_output() so that
     anything != 0 will be send down to the driver as "1" not the value
     passed in.

   - ACPI can now support naming of GPIO lines, hogs and holes in the
     GPIO lists.

  New drivers:

   - The SX150x driver was deemed unfit for the GPIO subsystem and was
     moved over to a combined GPIO+pinctrl driver in the pinctrl
     subsystem.

  New features:

   - Various cleanups to various drivers"

* tag 'gpio-v4.10-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio: (49 commits)
  gpio: merrifield: Implement gpio_get_direction callback
  gpio: merrifield: Add support for hardware debouncer
  gpio: chardev: Return error for seek operations
  gpio: arizona: Tidy up probe error path
  gpio: arizona: Remove pointless set of platform drvdata
  gpio: pl061: delete platform data handling
  gpio: pl061: move platform data into driver
  gpio: pl061: rename variable from chip to pl061
  gpio: pl061: rename state container struct
  gpio: pl061: use local state for parent IRQ storage
  gpio: set explicit nesting on drivers
  gpio: simplify adding threaded interrupts
  gpio: vf610: use builtin_platform_driver
  gpio: axp209: use correct register for GPIO input status
  gpio: stmpe: fix interrupt handling bug
  gpio: em: depnd on ARCH_SHMOBILE
  gpio: zx: depend on ARCH_ZX
  gpio: x86: update config dependencies for x86 specific hardware
  gpio: mb86s7x: use builtin_platform_driver
  gpio: etraxfs: use builtin_platform_driver
  ...

1  2 
drivers/gpio/Kconfig
drivers/gpio/Makefile
drivers/gpio/gpio-mxs.c
drivers/gpio/gpio-pca953x.c
drivers/gpio/gpio-stmpe.c
drivers/gpio/gpio-tc3589x.c
drivers/gpio/gpiolib-acpi.c
drivers/gpio/gpiolib-of.c
drivers/gpio/gpiolib.c

diff --combined drivers/gpio/Kconfig
index ed37e5908b910cd51cb378ffc171fe2a9104c082,28ed4ccc15b43b42f7a4cba05d1295a89052fe32..d5d36549ecc1ecea2c53cddea2a209e54ab94b56
@@@ -22,6 -22,10 +22,6 @@@ menuconfig GPIOLI
  
  if GPIOLIB
  
 -config GPIO_DEVRES
 -      def_bool y
 -      depends on HAS_IOMEM
 -
  config OF_GPIO
        def_bool y
        depends on OF
@@@ -167,7 -171,7 +167,7 @@@ config GPIO_DWAP
  
  config GPIO_EM
        tristate "Emma Mobile GPIO"
-       depends on ARM && OF_GPIO
+       depends on (ARCH_EMEV2 || COMPILE_TEST) && OF_GPIO
        help
          Say yes here to support GPIO on Renesas Emma Mobile SoCs.
  
@@@ -280,7 -284,7 +280,7 @@@ config GPIO_MM_LANTI
  
  config GPIO_MOCKUP
        tristate "GPIO Testing Driver"
 -      depends on GPIOLIB
 +      depends on GPIOLIB && SYSFS
        select GPIO_SYSFS
        help
          This enables GPIO Testing driver, which provides a way to test GPIO
@@@ -451,7 -455,7 +451,7 @@@ config GPIO_VR41X
  
  config GPIO_VX855
        tristate "VIA VX855/VX875 GPIO"
-       depends on PCI
+       depends on (X86 || COMPILE_TEST) && PCI
        select MFD_CORE
        select MFD_VX855
        help
@@@ -520,6 -524,7 +520,7 @@@ config GPIO_ZYN
  
  config GPIO_ZX
        bool "ZTE ZX GPIO support"
+       depends on ARCH_ZX || COMPILE_TEST
        select GPIOLIB_IRQCHIP
        help
          Say yes here to support the GPIO device on ZTE ZX SoCs.
@@@ -603,7 -608,7 +604,7 @@@ config GPIO_IT8
  
  config GPIO_SCH
        tristate "Intel SCH/TunnelCreek/Centerton/Quark X1000 GPIO"
-       depends on PCI
+       depends on (X86 || COMPILE_TEST) && PCI
        select MFD_CORE
        select LPC_SCH
        help
@@@ -777,16 -782,13 +778,13 @@@ config GPIO_PCF857
          platform-neutral GPIO calls.
  
  config GPIO_SX150X
-       bool "Semtech SX150x I2C GPIO expander"
-       depends on I2C=y
-       select GPIOLIB_IRQCHIP
+       bool "Semtech SX150x I2C GPIO expander (deprecated)"
+       depends on PINCTRL && I2C=y
+       select PINCTRL_SX150X
        default n
        help
-         Say yes here to provide support for Semtech SX150-series I2C
-         GPIO expanders. Compatible models include:
-         8 bits:  sx1508q
-         16 bits: sx1509q
+         Say yes here to provide support for Semtech SX150x-series I2C
+         GPIO expanders. The GPIO driver was replaced by a Pinctrl version.
  
  config GPIO_TPIC2810
        tristate "TPIC2810 8-Bit I2C GPO expander"
  
  config GPIO_TS4900
        tristate "Technologic Systems FPGA I2C GPIO"
+       depends on SOC_IMX6 || COMPILE_TEST
        select REGMAP_I2C
        help
          Say yes here to enabled the GPIO driver for Technologic's FPGA core.
@@@ -814,6 -817,14 +813,14 @@@ config GPIO_ADP552
          This option enables support for on-chip GPIO found
          on Analog Devices ADP5520 PMICs.
  
+ config GPIO_ALTERA_A10SR
+       tristate "Altera Arria10 System Resource GPIO"
+       depends on MFD_ALTERA_A10SR
+       help
+         Driver for Arria10 Development Kit GPIO expansion which
+         includes reads of pushbuttons and DIP switches as well
+         as writes to LEDs.
  config GPIO_ARIZONA
        tristate "Wolfson Microelectronics Arizona class devices"
        depends on MFD_ARIZONA
  
  config GPIO_CRYSTAL_COVE
        tristate "GPIO support for Crystal Cove PMIC"
-       depends on INTEL_SOC_PMIC
+       depends on (X86 || COMPILE_TEST) && INTEL_SOC_PMIC
        select GPIOLIB_IRQCHIP
        help
          Support for GPIO pins on Crystal Cove PMIC.
  
  config GPIO_CS5535
        tristate "AMD CS5535/CS5536 GPIO support"
+       depends on X86 || MIPS || COMPILE_TEST
        depends on MFD_CS5535
        help
          The AMD CS5535 and CS5536 southbridges support 28 GPIO pins that
@@@ -927,7 -939,7 +935,7 @@@ config GPIO_MAX7762
  
  config GPIO_MSIC
        bool "Intel MSIC mixed signal gpio support"
-       depends on MFD_INTEL_MSIC
+       depends on (X86 || COMPILE_TEST) && MFD_INTEL_MSIC
        help
          Enable support for GPIO on intel MSIC controllers found in
          intel MID devices
@@@ -1028,7 -1040,7 +1036,7 @@@ config GPIO_UCB140
  
  config GPIO_WHISKEY_COVE
        tristate "GPIO support for Whiskey Cove PMIC"
-       depends on INTEL_SOC_PMIC
+       depends on (X86 || COMPILE_TEST) && INTEL_SOC_PMIC
        select GPIOLIB_IRQCHIP
        help
          Support for GPIO pins on Whiskey Cove PMIC.
@@@ -1067,6 -1079,7 +1075,7 @@@ menu "PCI GPIO expanders
  
  config GPIO_AMD8111
        tristate "AMD 8111 GPIO driver"
+       depends on X86 || COMPILE_TEST
        help
          The AMD 8111 south bridge contains 32 GPIO pins which can be used.
  
@@@ -1108,6 -1121,7 +1117,7 @@@ config GPIO_MERRIFIEL
  
  config GPIO_ML_IOH
        tristate "OKI SEMICONDUCTOR ML7213 IOH GPIO support"
+       depends on X86 || COMPILE_TEST
        select GENERIC_IRQ_CHIP
        help
          ML7213 is companion chip for Intel Atom E6xx series.
diff --combined drivers/gpio/Makefile
index d074c2299393dc9cef3456b0068ff2d229677c27,8043a95e43dc71e114234a0cf7611e9795f01b4a..a7676b82de6f4accd75d57817fb2f0c4f5407bd1
@@@ -2,9 -2,10 +2,10 @@@
  
  ccflags-$(CONFIG_DEBUG_GPIO)  += -DDEBUG
  
 -obj-$(CONFIG_GPIO_DEVRES)     += devres.o
 +obj-$(CONFIG_GPIOLIB)         += devres.o
  obj-$(CONFIG_GPIOLIB)         += gpiolib.o
  obj-$(CONFIG_GPIOLIB)         += gpiolib-legacy.o
+ obj-$(CONFIG_GPIOLIB)         += gpiolib-devprop.o
  obj-$(CONFIG_OF_GPIO)         += gpiolib-of.o
  obj-$(CONFIG_GPIO_SYSFS)      += gpiolib-sysfs.o
  obj-$(CONFIG_GPIO_ACPI)               += gpiolib-acpi.o
@@@ -24,6 -25,7 +25,7 @@@ obj-$(CONFIG_GPIO_ADNP)               += gpio-adnp.
  obj-$(CONFIG_GPIO_ADP5520)    += gpio-adp5520.o
  obj-$(CONFIG_GPIO_ADP5588)    += gpio-adp5588.o
  obj-$(CONFIG_GPIO_ALTERA)     += gpio-altera.o
+ obj-$(CONFIG_GPIO_ALTERA_A10SR)       += gpio-altera-a10sr.o
  obj-$(CONFIG_GPIO_AMD8111)    += gpio-amd8111.o
  obj-$(CONFIG_GPIO_AMDPT)      += gpio-amdpt.o
  obj-$(CONFIG_GPIO_ARIZONA)    += gpio-arizona.o
@@@ -102,7 -104,6 +104,6 @@@ obj-$(CONFIG_GPIO_SPEAR_SPICS)     += gpio-
  obj-$(CONFIG_GPIO_STA2X11)    += gpio-sta2x11.o
  obj-$(CONFIG_GPIO_STMPE)      += gpio-stmpe.o
  obj-$(CONFIG_GPIO_STP_XWAY)   += gpio-stp-xway.o
- obj-$(CONFIG_GPIO_SX150X)     += gpio-sx150x.o
  obj-$(CONFIG_GPIO_SYSCON)     += gpio-syscon.o
  obj-$(CONFIG_GPIO_TB10X)      += gpio-tb10x.o
  obj-$(CONFIG_GPIO_TC3589X)    += gpio-tc3589x.o
diff --combined drivers/gpio/gpio-mxs.c
index ee1724806f46db13d7eb2b41ce900fd2043b3d91,62061f740ccf7a82784702e584588814315f1aa8..1e8fde8cb803d7406dd98d51673b63eb69fdfd23
@@@ -87,10 -87,15 +87,15 @@@ static int mxs_gpio_set_irq_type(struc
        u32 val;
        u32 pin_mask = 1 << d->hwirq;
        struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
+       struct irq_chip_type *ct = irq_data_get_chip_type(d);
        struct mxs_gpio_port *port = gc->private;
        void __iomem *pin_addr;
        int edge;
  
+       if (!(ct->type & type))
+               if (irq_setup_alt_chip(d, type))
+                       return -EINVAL;
        port->both_edges &= ~pin_mask;
        switch (type) {
        case IRQ_TYPE_EDGE_BOTH:
  
        /* set level or edge */
        pin_addr = port->base + PINCTRL_IRQLEV(port);
-       if (edge & GPIO_INT_LEV_MASK)
+       if (edge & GPIO_INT_LEV_MASK) {
                writel(pin_mask, pin_addr + MXS_SET);
-       else
+               writel(pin_mask, port->base + PINCTRL_IRQEN(port) + MXS_SET);
+       } else {
                writel(pin_mask, pin_addr + MXS_CLR);
+               writel(pin_mask, port->base + PINCTRL_PIN2IRQ(port) + MXS_SET);
+       }
  
        /* set polarity */
        pin_addr = port->base + PINCTRL_IRQPOL(port);
@@@ -202,21 -210,37 +210,37 @@@ static int __init mxs_gpio_init_gc(stru
        struct irq_chip_generic *gc;
        struct irq_chip_type *ct;
  
-       gc = irq_alloc_generic_chip("gpio-mxs", 1, irq_base,
+       gc = irq_alloc_generic_chip("gpio-mxs", 2, irq_base,
                                    port->base, handle_level_irq);
        if (!gc)
                return -ENOMEM;
  
        gc->private = port;
  
-       ct = gc->chip_types;
+       ct = &gc->chip_types[0];
+       ct->type = IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW;
+       ct->chip.irq_ack = irq_gc_ack_set_bit;
+       ct->chip.irq_mask = irq_gc_mask_disable_reg;
+       ct->chip.irq_unmask = irq_gc_unmask_enable_reg;
+       ct->chip.irq_set_type = mxs_gpio_set_irq_type;
+       ct->chip.irq_set_wake = mxs_gpio_set_wake_irq;
+       ct->chip.flags = IRQCHIP_SET_TYPE_MASKED;
+       ct->regs.ack = PINCTRL_IRQSTAT(port) + MXS_CLR;
+       ct->regs.enable = PINCTRL_PIN2IRQ(port) + MXS_SET;
+       ct->regs.disable = PINCTRL_PIN2IRQ(port) + MXS_CLR;
+       ct = &gc->chip_types[1];
+       ct->type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
        ct->chip.irq_ack = irq_gc_ack_set_bit;
-       ct->chip.irq_mask = irq_gc_mask_clr_bit;
-       ct->chip.irq_unmask = irq_gc_mask_set_bit;
+       ct->chip.irq_mask = irq_gc_mask_disable_reg;
+       ct->chip.irq_unmask = irq_gc_unmask_enable_reg;
        ct->chip.irq_set_type = mxs_gpio_set_irq_type;
        ct->chip.irq_set_wake = mxs_gpio_set_wake_irq;
+       ct->chip.flags = IRQCHIP_SET_TYPE_MASKED;
        ct->regs.ack = PINCTRL_IRQSTAT(port) + MXS_CLR;
-       ct->regs.mask = PINCTRL_IRQEN(port);
+       ct->regs.enable = PINCTRL_IRQEN(port) + MXS_SET;
+       ct->regs.disable = PINCTRL_IRQEN(port) + MXS_CLR;
+       ct->handler = handle_level_irq;
  
        irq_setup_generic_chip(gc, IRQ_MSK(32), IRQ_GC_INIT_NESTED_LOCK,
                               IRQ_NOREQUEST, 0);
@@@ -297,21 -321,16 +321,18 @@@ static int mxs_gpio_probe(struct platfo
        }
        port->base = base;
  
-       /*
-        * select the pin interrupt functionality but initially
-        * disable the interrupts
-        */
-       writel(~0U, port->base + PINCTRL_PIN2IRQ(port));
+       /* initially disable the interrupts */
+       writel(0, port->base + PINCTRL_PIN2IRQ(port));
        writel(0, port->base + PINCTRL_IRQEN(port));
  
        /* clear address has to be used to clear IRQSTAT bits */
        writel(~0U, port->base + PINCTRL_IRQSTAT(port) + MXS_CLR);
  
        irq_base = irq_alloc_descs(-1, 0, 32, numa_node_id());
 -      if (irq_base < 0)
 -              return irq_base;
 +      if (irq_base < 0) {
 +              err = irq_base;
 +              goto out_iounmap;
 +      }
  
        port->domain = irq_domain_add_legacy(np, 32, irq_base, 0,
                                             &irq_domain_simple_ops, NULL);
@@@ -351,8 -370,6 +372,8 @@@ out_irqdomain_remove
        irq_domain_remove(port->domain);
  out_irqdesc_free:
        irq_free_descs(irq_base, 32);
 +out_iounmap:
 +      iounmap(port->base);
        return err;
  }
  
index fe731f09425712b546655d7097a84b7a47a35d68,9733678f0219501d2ed44717ec5879dc691938d1..d5d72d84b719014feaf38bcdd4b39fdbb67c6b61
@@@ -74,6 -74,7 +74,7 @@@ static const struct i2c_device_id pca95
        { "max7312", 16 | PCA953X_TYPE | PCA_INT, },
        { "max7313", 16 | PCA953X_TYPE | PCA_INT, },
        { "max7315", 8  | PCA953X_TYPE | PCA_INT, },
+       { "max7318", 16 | PCA953X_TYPE | PCA_INT, },
        { "pca6107", 8  | PCA953X_TYPE | PCA_INT, },
        { "tca6408", 8  | PCA953X_TYPE | PCA_INT, },
        { "tca6416", 16 | PCA953X_TYPE | PCA_INT, },
@@@ -372,15 -373,14 +373,15 @@@ static void pca953x_gpio_set_multiple(s
  
        bank_shift = fls((chip->gpio_chip.ngpio - 1) / BANK_SZ);
  
 -      memcpy(reg_val, chip->reg_output, NBANK(chip));
        mutex_lock(&chip->i2c_lock);
 +      memcpy(reg_val, chip->reg_output, NBANK(chip));
        for (bank = 0; bank < NBANK(chip); bank++) {
                bank_mask = mask[bank / sizeof(*mask)] >>
                           ((bank % sizeof(*mask)) * 8);
                if (bank_mask) {
                        bank_val = bits[bank / sizeof(*bits)] >>
                                  ((bank % sizeof(*bits)) * 8);
 +                      bank_val &= bank_mask;
                        reg_val[bank] = (reg_val[bank] & ~bank_mask) | bank_val;
                }
        }
@@@ -608,6 -608,7 +609,6 @@@ static int pca953x_irq_setup(struct pca
  
        if (client->irq && irq_base != -1
                        && (chip->driver_data & PCA_INT)) {
 -
                ret = pca953x_read_regs(chip,
                                        chip->regs->input, chip->irq_stat);
                if (ret)
                        return ret;
                }
  
-               ret =  gpiochip_irqchip_add(&chip->gpio_chip,
-                                           &pca953x_irq_chip,
-                                           irq_base,
-                                           handle_simple_irq,
-                                           IRQ_TYPE_NONE);
+               ret =  gpiochip_irqchip_add_nested(&chip->gpio_chip,
+                                                  &pca953x_irq_chip,
+                                                  irq_base,
+                                                  handle_simple_irq,
+                                                  IRQ_TYPE_NONE);
                if (ret) {
                        dev_err(&client->dev,
                                "could not connect irqchip to gpiochip\n");
                        return ret;
                }
  
-               gpiochip_set_chained_irqchip(&chip->gpio_chip,
-                                            &pca953x_irq_chip,
-                                            client->irq, NULL);
+               gpiochip_set_nested_irqchip(&chip->gpio_chip,
+                                           &pca953x_irq_chip,
+                                           client->irq);
        }
  
        return 0;
@@@ -907,6 -908,7 +908,7 @@@ static const struct of_device_id pca953
        { .compatible = "maxim,max7312", .data = OF_953X(16, PCA_INT), },
        { .compatible = "maxim,max7313", .data = OF_953X(16, PCA_INT), },
        { .compatible = "maxim,max7315", .data = OF_953X( 8, PCA_INT), },
+       { .compatible = "maxim,max7318", .data = OF_953X(16, PCA_INT), },
  
        { .compatible = "ti,pca6107", .data = OF_953X( 8, PCA_INT), },
        { .compatible = "ti,pca9536", .data = OF_953X( 4, 0), },
index 5b0042776ec7081f49d3eaff1dc56fe08733f3d1,21364e95065dc30075ee11cc1b4883b474222e54..16cbc5702865cd2765ad5aeabcd98460623eb353
@@@ -409,11 -409,11 +409,11 @@@ static irqreturn_t stmpe_gpio_irq(int i
                 * 801/1801/1600, bits are cleared when read.
                 * Edge detect register is not present on 801/1600/1801
                 */
 -              if (stmpe->partnum != STMPE801 || stmpe->partnum != STMPE1600 ||
 +              if (stmpe->partnum != STMPE801 && stmpe->partnum != STMPE1600 &&
                    stmpe->partnum != STMPE1801) {
                        stmpe_reg_write(stmpe, statmsbreg + i, status[i]);
                        stmpe_reg_write(stmpe,
-                                       stmpe->regs[STMPE_IDX_GPEDR_LSB + i],
+                                       stmpe->regs[STMPE_IDX_GPEDR_MSB] + i,
                                        status[i]);
                }
        }
@@@ -484,21 -484,20 +484,20 @@@ static int stmpe_gpio_probe(struct plat
                                if (stmpe_gpio->norequest_mask & BIT(i))
                                        clear_bit(i, stmpe_gpio->chip.irq_valid_mask);
                }
-               ret =  gpiochip_irqchip_add(&stmpe_gpio->chip,
-                                           &stmpe_gpio_irq_chip,
-                                           0,
-                                           handle_simple_irq,
-                                           IRQ_TYPE_NONE);
+               ret =  gpiochip_irqchip_add_nested(&stmpe_gpio->chip,
+                                                  &stmpe_gpio_irq_chip,
+                                                  0,
+                                                  handle_simple_irq,
+                                                  IRQ_TYPE_NONE);
                if (ret) {
                        dev_err(&pdev->dev,
                                "could not connect irqchip to gpiochip\n");
                        goto out_disable;
                }
  
-               gpiochip_set_chained_irqchip(&stmpe_gpio->chip,
-                                            &stmpe_gpio_irq_chip,
-                                            irq,
-                                            NULL);
+               gpiochip_set_nested_irqchip(&stmpe_gpio->chip,
+                                           &stmpe_gpio_irq_chip,
+                                           irq);
        }
  
        platform_set_drvdata(pdev, stmpe_gpio);
index d6e21f1a70a9dc685aa8dfc786230ad620022691,f041965f1b0399ef9b2a649e47b7da3cdfa15d4d..be97101c2c9a86f333059e133d0db2c515a8b447
@@@ -97,7 -97,7 +97,7 @@@ static int tc3589x_gpio_get_direction(s
        if (ret < 0)
                return ret;
  
 -      return !!(ret & BIT(pos));
 +      return !(ret & BIT(pos));
  }
  
  static int tc3589x_gpio_set_single_ended(struct gpio_chip *chip,
@@@ -337,21 -337,20 +337,20 @@@ static int tc3589x_gpio_probe(struct pl
                return ret;
        }
  
-       ret =  gpiochip_irqchip_add(&tc3589x_gpio->chip,
-                                   &tc3589x_gpio_irq_chip,
-                                   0,
-                                   handle_simple_irq,
-                                   IRQ_TYPE_NONE);
+       ret =  gpiochip_irqchip_add_nested(&tc3589x_gpio->chip,
+                                          &tc3589x_gpio_irq_chip,
+                                          0,
+                                          handle_simple_irq,
+                                          IRQ_TYPE_NONE);
        if (ret) {
                dev_err(&pdev->dev,
                        "could not connect irqchip to gpiochip\n");
                return ret;
        }
  
-       gpiochip_set_chained_irqchip(&tc3589x_gpio->chip,
-                                    &tc3589x_gpio_irq_chip,
-                                    irq,
-                                    NULL);
+       gpiochip_set_nested_irqchip(&tc3589x_gpio->chip,
+                                   &tc3589x_gpio_irq_chip,
+                                   irq);
  
        platform_set_drvdata(pdev, tc3589x_gpio);
  
index 72a4b326fd0da2f1d84f9e05a97416ff5761c9d3,fec93b994fe918d140717bbdb9f89b5a3a8c5df6..a3faefa44f6822b6420f3f06833ba6254bee01b1
@@@ -468,7 -468,8 +468,8 @@@ static int acpi_gpio_property_lookup(st
        int ret;
  
        memset(&args, 0, sizeof(args));
-       ret = acpi_node_get_property_reference(fwnode, propname, index, &args);
+       ret = __acpi_node_get_property_reference(fwnode, propname, index, 3,
+                                                &args);
        if (ret) {
                struct acpi_device *adev = to_acpi_device_node(fwnode);
  
         * on returned args.
         */
        lookup->adev = args.adev;
-       if (args.nargs >= 2) {
-               lookup->index = args.args[0];
-               lookup->pin_index = args.args[1];
-               /* 3rd argument, if present is used to specify active_low. */
-               if (args.nargs >= 3)
-                       lookup->active_low = !!args.args[2];
-       }
+       if (args.nargs != 3)
+               return -EPROTO;
+       lookup->index = args.args[0];
+       lookup->pin_index = args.args[1];
+       lookup->active_low = !!args.args[2];
        return 0;
  }
  
@@@ -653,17 -654,14 +654,17 @@@ int acpi_dev_gpio_irq_get(struct acpi_d
  {
        int idx, i;
        unsigned int irq_flags;
 +      int ret = -ENOENT;
  
        for (i = 0, idx = 0; idx <= index; i++) {
                struct acpi_gpio_info info;
                struct gpio_desc *desc;
  
                desc = acpi_get_gpiod_by_index(adev, NULL, i, &info);
 -              if (IS_ERR(desc))
 +              if (IS_ERR(desc)) {
 +                      ret = PTR_ERR(desc);
                        break;
 +              }
                if (info.gpioint && idx++ == index) {
                        int irq = gpiod_to_irq(desc);
  
                }
  
        }
 -      return -ENOENT;
 +      return ret;
  }
  EXPORT_SYMBOL_GPL(acpi_dev_gpio_irq_get);
  
@@@ -859,6 -857,77 +860,77 @@@ static void acpi_gpiochip_free_regions(
        }
  }
  
+ static struct gpio_desc *acpi_gpiochip_parse_own_gpio(
+       struct acpi_gpio_chip *achip, struct fwnode_handle *fwnode,
+       const char **name, unsigned int *lflags, unsigned int *dflags)
+ {
+       struct gpio_chip *chip = achip->chip;
+       struct gpio_desc *desc;
+       u32 gpios[2];
+       int ret;
+       *lflags = 0;
+       *dflags = 0;
+       *name = NULL;
+       ret = fwnode_property_read_u32_array(fwnode, "gpios", gpios,
+                                            ARRAY_SIZE(gpios));
+       if (ret < 0)
+               return ERR_PTR(ret);
+       ret = acpi_gpiochip_pin_to_gpio_offset(chip->gpiodev, gpios[0]);
+       if (ret < 0)
+               return ERR_PTR(ret);
+       desc = gpiochip_get_desc(chip, ret);
+       if (IS_ERR(desc))
+               return desc;
+       if (gpios[1])
+               *lflags |= GPIO_ACTIVE_LOW;
+       if (fwnode_property_present(fwnode, "input"))
+               *dflags |= GPIOD_IN;
+       else if (fwnode_property_present(fwnode, "output-low"))
+               *dflags |= GPIOD_OUT_LOW;
+       else if (fwnode_property_present(fwnode, "output-high"))
+               *dflags |= GPIOD_OUT_HIGH;
+       else
+               return ERR_PTR(-EINVAL);
+       fwnode_property_read_string(fwnode, "line-name", name);
+       return desc;
+ }
+ static void acpi_gpiochip_scan_gpios(struct acpi_gpio_chip *achip)
+ {
+       struct gpio_chip *chip = achip->chip;
+       struct fwnode_handle *fwnode;
+       device_for_each_child_node(chip->parent, fwnode) {
+               unsigned int lflags, dflags;
+               struct gpio_desc *desc;
+               const char *name;
+               int ret;
+               if (!fwnode_property_present(fwnode, "gpio-hog"))
+                       continue;
+               desc = acpi_gpiochip_parse_own_gpio(achip, fwnode, &name,
+                                                   &lflags, &dflags);
+               if (IS_ERR(desc))
+                       continue;
+               ret = gpiod_hog(desc, name, lflags, dflags);
+               if (ret) {
+                       dev_err(chip->parent, "Failed to hog GPIO\n");
+                       fwnode_handle_put(fwnode);
+                       return;
+               }
+       }
+ }
  void acpi_gpiochip_add(struct gpio_chip *chip)
  {
        struct acpi_gpio_chip *acpi_gpio;
                return;
        }
  
+       if (!chip->names)
+               devprop_gpiochip_set_names(chip);
        acpi_gpiochip_request_regions(acpi_gpio);
+       acpi_gpiochip_scan_gpios(acpi_gpio);
        acpi_walk_dep_device_list(handle);
  }
  
@@@ -918,18 -991,27 +994,27 @@@ void acpi_gpiochip_remove(struct gpio_c
        kfree(acpi_gpio);
  }
  
- static unsigned int acpi_gpio_package_count(const union acpi_object *obj)
+ static int acpi_gpio_package_count(const union acpi_object *obj)
  {
        const union acpi_object *element = obj->package.elements;
        const union acpi_object *end = element + obj->package.count;
        unsigned int count = 0;
  
        while (element < end) {
-               if (element->type == ACPI_TYPE_LOCAL_REFERENCE)
+               switch (element->type) {
+               case ACPI_TYPE_LOCAL_REFERENCE:
+                       element += 3;
+                       /* Fallthrough */
+               case ACPI_TYPE_INTEGER:
+                       element++;
                        count++;
+                       break;
  
-               element++;
+               default:
+                       return -EPROTO;
+               }
        }
        return count;
  }
  
index 193f15d50bbaa33e9728f98c462f8fddaf96971b,5236966b1bdfc4008466cf25a583218a60fe4b12..92b185f19232f7fc3f1207bc320ce6ca887f117f
  
  #include "gpiolib.h"
  
 -static int of_gpiochip_match_node(struct gpio_chip *chip, void *data)
 +static int of_gpiochip_match_node_and_xlate(struct gpio_chip *chip, void *data)
  {
 -      return chip->gpiodev->dev.of_node == data;
 +      struct of_phandle_args *gpiospec = data;
 +
 +      return chip->gpiodev->dev.of_node == gpiospec->np &&
 +                              chip->of_xlate(chip, gpiospec, NULL) >= 0;
  }
  
 -static struct gpio_chip *of_find_gpiochip_by_node(struct device_node *np)
 +static struct gpio_chip *of_find_gpiochip_by_xlate(
 +                                      struct of_phandle_args *gpiospec)
  {
 -      return gpiochip_find(np, of_gpiochip_match_node);
 +      return gpiochip_find(gpiospec, of_gpiochip_match_node_and_xlate);
  }
  
  static struct gpio_desc *of_xlate_and_get_gpiod_flags(struct gpio_chip *chip,
@@@ -83,7 -79,7 +83,7 @@@ struct gpio_desc *of_get_named_gpiod_fl
                return ERR_PTR(ret);
        }
  
 -      chip = of_find_gpiochip_by_node(gpiospec.np);
 +      chip = of_find_gpiochip_by_xlate(&gpiospec);
        if (!chip) {
                desc = ERR_PTR(-EPROBE_DEFER);
                goto out;
@@@ -225,51 -221,6 +225,6 @@@ static struct gpio_desc *of_parse_own_g
        return desc;
  }
  
- /**
-  * of_gpiochip_set_names() - set up the names of the lines
-  * @chip: GPIO chip whose lines should be named, if possible
-  */
- static void of_gpiochip_set_names(struct gpio_chip *gc)
- {
-       struct gpio_device *gdev = gc->gpiodev;
-       struct device_node *np = gc->of_node;
-       int i;
-       int nstrings;
-       nstrings = of_property_count_strings(np, "gpio-line-names");
-       if (nstrings <= 0)
-               /* Lines names not present */
-               return;
-       /* This is normally not what you want */
-       if (gdev->ngpio != nstrings)
-               dev_info(&gdev->dev, "gpio-line-names specifies %d line "
-                        "names but there are %d lines on the chip\n",
-                        nstrings, gdev->ngpio);
-       /*
-        * Make sure to not index beyond the end of the number of descriptors
-        * of the GPIO device.
-        */
-       for (i = 0; i < gdev->ngpio; i++) {
-               const char *name;
-               int ret;
-               ret = of_property_read_string_index(np,
-                                                   "gpio-line-names",
-                                                   i,
-                                                   &name);
-               if (ret) {
-                       if (ret != -ENODATA)
-                                 dev_err(&gdev->dev,
-                                         "unable to name line %d: %d\n",
-                                         i, ret);
-                       break;
-               }
-               gdev->descs[i].name = name;
-       }
- }
  /**
   * of_gpiochip_scan_gpios - Scan gpio-controller for gpio definitions
   * @chip:     gpio chip to act on
@@@ -296,8 -247,10 +251,10 @@@ static int of_gpiochip_scan_gpios(struc
                        continue;
  
                ret = gpiod_hog(desc, name, lflags, dflags);
-               if (ret < 0)
+               if (ret < 0) {
+                       of_node_put(np);
                        return ret;
+               }
        }
  
        return 0;
@@@ -526,7 -479,7 +483,7 @@@ int of_gpiochip_add(struct gpio_chip *c
  
        /* If the chip defines names itself, these take precedence */
        if (!chip->names)
-               of_gpiochip_set_names(chip);
+               devprop_gpiochip_set_names(chip);
  
        of_node_get(chip->of_node);
  
diff --combined drivers/gpio/gpiolib.c
index 868128a676bae832090c2c18b1f45e94c2996a5f,acdff62f2ee2f54a4a6abd2a1cb76b6f40255d5e..f4c26c7826cdfc0b5163632e596c0e664586549b
@@@ -21,7 -21,6 +21,7 @@@
  #include <linux/uaccess.h>
  #include <linux/compat.h>
  #include <linux/anon_inodes.h>
 +#include <linux/file.h>
  #include <linux/kfifo.h>
  #include <linux/poll.h>
  #include <linux/timekeeping.h>
@@@ -334,13 -333,6 +334,13 @@@ struct linehandle_state 
        u32 numdescs;
  };
  
 +#define GPIOHANDLE_REQUEST_VALID_FLAGS \
 +      (GPIOHANDLE_REQUEST_INPUT | \
 +      GPIOHANDLE_REQUEST_OUTPUT | \
 +      GPIOHANDLE_REQUEST_ACTIVE_LOW | \
 +      GPIOHANDLE_REQUEST_OPEN_DRAIN | \
 +      GPIOHANDLE_REQUEST_OPEN_SOURCE)
 +
  static long linehandle_ioctl(struct file *filep, unsigned int cmd,
                             unsigned long arg)
  {
        if (cmd == GPIOHANDLE_GET_LINE_VALUES_IOCTL) {
                int val;
  
 +              memset(&ghd, 0, sizeof(ghd));
 +
                /* TODO: check if descriptors are really input */
                for (i = 0; i < lh->numdescs; i++) {
                        val = gpiod_get_value_cansleep(lh->descs[i]);
@@@ -424,7 -414,6 +424,7 @@@ static int linehandle_create(struct gpi
  {
        struct gpiohandle_request handlereq;
        struct linehandle_state *lh;
 +      struct file *file;
        int fd, i, ret;
  
        if (copy_from_user(&handlereq, ip, sizeof(handlereq)))
                u32 lflags = handlereq.flags;
                struct gpio_desc *desc;
  
 +              if (offset >= gdev->ngpio) {
 +                      ret = -EINVAL;
 +                      goto out_free_descs;
 +              }
 +
 +              /* Return an error if a unknown flag is set */
 +              if (lflags & ~GPIOHANDLE_REQUEST_VALID_FLAGS) {
 +                      ret = -EINVAL;
 +                      goto out_free_descs;
 +              }
 +
                desc = &gdev->descs[offset];
                ret = gpiod_request(desc, lh->label);
                if (ret)
        i--;
        lh->numdescs = handlereq.lines;
  
 -      fd = anon_inode_getfd("gpio-linehandle",
 -                            &linehandle_fileops,
 -                            lh,
 -                            O_RDONLY | O_CLOEXEC);
 +      fd = get_unused_fd_flags(O_RDONLY | O_CLOEXEC);
        if (fd < 0) {
                ret = fd;
                goto out_free_descs;
        }
  
 +      file = anon_inode_getfile("gpio-linehandle",
 +                                &linehandle_fileops,
 +                                lh,
 +                                O_RDONLY | O_CLOEXEC);
 +      if (IS_ERR(file)) {
 +              ret = PTR_ERR(file);
 +              goto out_put_unused_fd;
 +      }
 +
        handlereq.fd = fd;
        if (copy_to_user(ip, &handlereq, sizeof(handlereq))) {
 -              ret = -EFAULT;
 -              goto out_free_descs;
 +              /*
 +               * fput() will trigger the release() callback, so do not go onto
 +               * the regular error cleanup path here.
 +               */
 +              fput(file);
 +              put_unused_fd(fd);
 +              return -EFAULT;
        }
  
 +      fd_install(fd, file);
 +
        dev_dbg(&gdev->dev, "registered chardev handle for %d lines\n",
                lh->numdescs);
  
        return 0;
  
 +out_put_unused_fd:
 +      put_unused_fd(fd);
  out_free_descs:
        for (; i >= 0; i--)
                gpiod_free(lh->descs[i]);
@@@ -573,10 -536,6 +573,10 @@@ struct lineevent_state 
        struct mutex read_lock;
  };
  
 +#define GPIOEVENT_REQUEST_VALID_FLAGS \
 +      (GPIOEVENT_REQUEST_RISING_EDGE | \
 +      GPIOEVENT_REQUEST_FALLING_EDGE)
 +
  static unsigned int lineevent_poll(struct file *filep,
                                   struct poll_table_struct *wait)
  {
@@@ -664,8 -623,6 +664,8 @@@ static long lineevent_ioctl(struct fil
        if (cmd == GPIOHANDLE_GET_LINE_VALUES_IOCTL) {
                int val;
  
 +              memset(&ghd, 0, sizeof(ghd));
 +
                val = gpiod_get_value_cansleep(le->desc);
                if (val < 0)
                        return val;
@@@ -738,7 -695,6 +738,7 @@@ static int lineevent_create(struct gpio
        struct gpioevent_request eventreq;
        struct lineevent_state *le;
        struct gpio_desc *desc;
 +      struct file *file;
        u32 offset;
        u32 lflags;
        u32 eflags;
        lflags = eventreq.handleflags;
        eflags = eventreq.eventflags;
  
 +      if (offset >= gdev->ngpio) {
 +              ret = -EINVAL;
 +              goto out_free_label;
 +      }
 +
 +      /* Return an error if a unknown flag is set */
 +      if ((lflags & ~GPIOHANDLE_REQUEST_VALID_FLAGS) ||
 +          (eflags & ~GPIOEVENT_REQUEST_VALID_FLAGS)) {
 +              ret = -EINVAL;
 +              goto out_free_label;
 +      }
 +
        /* This is just wrong: we don't look for events on output lines */
        if (lflags & GPIOHANDLE_REQUEST_OUTPUT) {
                ret = -EINVAL;
        if (ret)
                goto out_free_desc;
  
 -      fd = anon_inode_getfd("gpio-event",
 -                            &lineevent_fileops,
 -                            le,
 -                            O_RDONLY | O_CLOEXEC);
 +      fd = get_unused_fd_flags(O_RDONLY | O_CLOEXEC);
        if (fd < 0) {
                ret = fd;
                goto out_free_irq;
        }
  
 +      file = anon_inode_getfile("gpio-event",
 +                                &lineevent_fileops,
 +                                le,
 +                                O_RDONLY | O_CLOEXEC);
 +      if (IS_ERR(file)) {
 +              ret = PTR_ERR(file);
 +              goto out_put_unused_fd;
 +      }
 +
        eventreq.fd = fd;
        if (copy_to_user(ip, &eventreq, sizeof(eventreq))) {
 -              ret = -EFAULT;
 -              goto out_free_irq;
 +              /*
 +               * fput() will trigger the release() callback, so do not go onto
 +               * the regular error cleanup path here.
 +               */
 +              fput(file);
 +              put_unused_fd(fd);
 +              return -EFAULT;
        }
  
 +      fd_install(fd, file);
 +
        return 0;
  
 +out_put_unused_fd:
 +      put_unused_fd(fd);
  out_free_irq:
        free_irq(le->irq, le);
  out_free_desc:
@@@ -894,8 -823,6 +894,8 @@@ static long gpio_ioctl(struct file *fil
        if (cmd == GPIO_GET_CHIPINFO_IOCTL) {
                struct gpiochip_info chipinfo;
  
 +              memset(&chipinfo, 0, sizeof(chipinfo));
 +
                strncpy(chipinfo.name, dev_name(&gdev->dev),
                        sizeof(chipinfo.name));
                chipinfo.name[sizeof(chipinfo.name)-1] = '\0';
  
                if (copy_from_user(&lineinfo, ip, sizeof(lineinfo)))
                        return -EFAULT;
 -              if (lineinfo.line_offset > gdev->ngpio)
 +              if (lineinfo.line_offset >= gdev->ngpio)
                        return -EINVAL;
  
                desc = &gdev->descs[lineinfo.line_offset];
@@@ -986,7 -913,8 +986,8 @@@ static int gpio_chrdev_open(struct inod
                return -ENODEV;
        get_device(&gdev->dev);
        filp->private_data = gdev;
-       return 0;
+       return nonseekable_open(inode, filp);
  }
  
  /**
@@@ -1011,7 -939,7 +1012,7 @@@ static const struct file_operations gpi
        .release = gpio_chrdev_release,
        .open = gpio_chrdev_open,
        .owner = THIS_MODULE,
-       .llseek = noop_llseek,
+       .llseek = no_llseek,
        .unlocked_ioctl = gpio_ioctl,
  #ifdef CONFIG_COMPAT
        .compat_ioctl = gpio_ioctl_compat,
@@@ -1512,7 -1440,7 +1513,7 @@@ static bool gpiochip_irqchip_irq_valid(
  }
  
  /**
-  * gpiochip_set_chained_irqchip() - sets a chained irqchip to a gpiochip
+  * gpiochip_set_cascaded_irqchip() - connects a cascaded irqchip to a gpiochip
   * @gpiochip: the gpiochip to set the irqchip chain to
   * @irqchip: the irqchip to chain to the gpiochip
   * @parent_irq: the irq number corresponding to the parent IRQ for this
   * coming out of the gpiochip. If the interrupt is nested rather than
   * cascaded, pass NULL in this handler argument
   */
void gpiochip_set_chained_irqchip(struct gpio_chip *gpiochip,
-                                 struct irq_chip *irqchip,
-                                 int parent_irq,
-                                 irq_flow_handler_t parent_handler)
static void gpiochip_set_cascaded_irqchip(struct gpio_chip *gpiochip,
+                                         struct irq_chip *irqchip,
+                                         int parent_irq,
+                                         irq_flow_handler_t parent_handler)
  {
        unsigned int offset;
  
                irq_set_chained_handler_and_data(parent_irq, parent_handler,
                                                 gpiochip);
  
-               gpiochip->irq_parent = parent_irq;
+               gpiochip->irq_chained_parent = parent_irq;
        }
  
        /* Set the parent IRQ for all affected IRQs */
                               parent_irq);
        }
  }
+ /**
+  * gpiochip_set_chained_irqchip() - connects a chained irqchip to a gpiochip
+  * @gpiochip: the gpiochip to set the irqchip chain to
+  * @irqchip: the irqchip to chain to the gpiochip
+  * @parent_irq: the irq number corresponding to the parent IRQ for this
+  * chained irqchip
+  * @parent_handler: the parent interrupt handler for the accumulated IRQ
+  * coming out of the gpiochip. If the interrupt is nested rather than
+  * cascaded, pass NULL in this handler argument
+  */
+ void gpiochip_set_chained_irqchip(struct gpio_chip *gpiochip,
+                                 struct irq_chip *irqchip,
+                                 int parent_irq,
+                                 irq_flow_handler_t parent_handler)
+ {
+       gpiochip_set_cascaded_irqchip(gpiochip, irqchip, parent_irq,
+                                     parent_handler);
+ }
  EXPORT_SYMBOL_GPL(gpiochip_set_chained_irqchip);
  
+ /**
+  * gpiochip_set_nested_irqchip() - connects a nested irqchip to a gpiochip
+  * @gpiochip: the gpiochip to set the irqchip nested handler to
+  * @irqchip: the irqchip to nest to the gpiochip
+  * @parent_irq: the irq number corresponding to the parent IRQ for this
+  * nested irqchip
+  */
+ void gpiochip_set_nested_irqchip(struct gpio_chip *gpiochip,
+                                struct irq_chip *irqchip,
+                                int parent_irq)
+ {
+       if (!gpiochip->irq_nested) {
+               chip_err(gpiochip, "tried to nest a chained gpiochip\n");
+               return;
+       }
+       gpiochip_set_cascaded_irqchip(gpiochip, irqchip, parent_irq,
+                                     NULL);
+ }
+ EXPORT_SYMBOL_GPL(gpiochip_set_nested_irqchip);
  /**
   * gpiochip_irq_map() - maps an IRQ into a GPIO irqchip
   * @d: the irqdomain used by this irqchip
@@@ -1583,8 -1550,8 +1623,8 @@@ static int gpiochip_irq_map(struct irq_
         */
        irq_set_lockdep_class(irq, chip->lock_key);
        irq_set_chip_and_handler(irq, chip->irqchip, chip->irq_handler);
-       /* Chips that can sleep need nested thread handlers */
-       if (chip->can_sleep && !chip->irq_not_threaded)
+       /* Chips that use nested thread handlers have them marked */
+       if (chip->irq_nested)
                irq_set_nested_thread(irq, 1);
        irq_set_noprobe(irq);
  
@@@ -1602,7 -1569,7 +1642,7 @@@ static void gpiochip_irq_unmap(struct i
  {
        struct gpio_chip *chip = d->host_data;
  
-       if (chip->can_sleep)
+       if (chip->irq_nested)
                irq_set_nested_thread(irq, 0);
        irq_set_chip_and_handler(irq, NULL, NULL);
        irq_set_chip_data(irq, NULL);
@@@ -1657,9 -1624,9 +1697,9 @@@ static void gpiochip_irqchip_remove(str
  
        acpi_gpiochip_free_interrupts(gpiochip);
  
-       if (gpiochip->irq_parent) {
-               irq_set_chained_handler(gpiochip->irq_parent, NULL);
-               irq_set_handler_data(gpiochip->irq_parent, NULL);
+       if (gpiochip->irq_chained_parent) {
+               irq_set_chained_handler(gpiochip->irq_chained_parent, NULL);
+               irq_set_handler_data(gpiochip->irq_chained_parent, NULL);
        }
  
        /* Remove all IRQ mappings and delete the domain */
  }
  
  /**
-  * gpiochip_irqchip_add() - adds an irqchip to a gpiochip
+  * _gpiochip_irqchip_add() - adds an irqchip to a gpiochip
   * @gpiochip: the gpiochip to add the irqchip to
   * @irqchip: the irqchip to add to the gpiochip
   * @first_irq: if not dynamically assigned, the base (first) IRQ to
   * @handler: the irq handler to use (often a predefined irq core function)
   * @type: the default type for IRQs on this irqchip, pass IRQ_TYPE_NONE
   * to have the core avoid setting up any default type in the hardware.
+  * @nested: whether this is a nested irqchip calling handle_nested_irq()
+  * in its IRQ handler
   * @lock_key: lockdep class
   *
   * This function closely associates a certain irqchip with a certain
@@@ -1712,6 -1681,7 +1754,7 @@@ int _gpiochip_irqchip_add(struct gpio_c
                          unsigned int first_irq,
                          irq_flow_handler_t handler,
                          unsigned int type,
+                         bool nested,
                          struct lock_class_key *lock_key)
  {
        struct device_node *of_node;
                pr_err("missing gpiochip .dev parent pointer\n");
                return -EINVAL;
        }
+       gpiochip->irq_nested = nested;
        of_node = gpiochip->parent->of_node;
  #ifdef CONFIG_OF_GPIO
        /*
@@@ -2223,6 -2194,7 +2267,7 @@@ EXPORT_SYMBOL_GPL(gpiod_direction_input
  static int _gpiod_direction_output_raw(struct gpio_desc *desc, int value)
  {
        struct gpio_chip *gc = desc->gdev->chip;
+       int val = !!value;
        int ret;
  
        /* GPIOs used for IRQs shall not be set as output */
                                goto set_output_value;
                }
                /* Emulate open drain by not actively driving the line high */
-               if (value)
+               if (val)
                        return gpiod_direction_input(desc);
        }
        else if (test_bit(FLAG_OPEN_SOURCE, &desc->flags)) {
                                goto set_output_value;
                }
                /* Emulate open source by not actively driving the line low */
-               if (!value)
+               if (!val)
                        return gpiod_direction_input(desc);
        } else {
                /* Make sure to disable open drain/source hardware, if any */
@@@ -2271,10 -2243,10 +2316,10 @@@ set_output_value
                return -EIO;
        }
  
-       ret = gc->direction_output(gc, gpio_chip_hwgpio(desc), value);
+       ret = gc->direction_output(gc, gpio_chip_hwgpio(desc), val);
        if (!ret)
                set_bit(FLAG_IS_OUT, &desc->flags);
-       trace_gpio_value(desc_to_gpio(desc), 0, value);
+       trace_gpio_value(desc_to_gpio(desc), 0, val);
        trace_gpio_direction(desc_to_gpio(desc), 0, ret);
        return ret;
  }
@@@ -2314,6 -2286,8 +2359,8 @@@ int gpiod_direction_output(struct gpio_
        VALIDATE_DESC(desc);
        if (test_bit(FLAG_ACTIVE_LOW, &desc->flags))
                value = !value;
+       else
+               value = !!value;
        return _gpiod_direction_output_raw(desc, value);
  }
  EXPORT_SYMBOL_GPL(gpiod_direction_output);
@@@ -2737,11 -2711,8 +2784,11 @@@ int gpiochip_lock_as_irq(struct gpio_ch
        if (IS_ERR(desc))
                return PTR_ERR(desc);
  
 -      /* Flush direction if something changed behind our back */
 -      if (chip->get_direction) {
 +      /*
 +       * If it's fast: flush the direction setting if something changed
 +       * behind our back
 +       */
 +      if (!chip->can_sleep && chip->get_direction) {
                int dir = chip->get_direction(chip, offset);
  
                if (dir)
        }
  
        set_bit(FLAG_USED_AS_IRQ, &desc->flags);
+       /*
+        * If the consumer has not set up a label (such as when the
+        * IRQ is referenced from .to_irq()) we set up a label here
+        * so it is clear this is used as an interrupt.
+        */
+       if (!desc->label)
+               desc_set_label(desc, "interrupt");
        return 0;
  }
  EXPORT_SYMBOL_GPL(gpiochip_lock_as_irq);
   */
  void gpiochip_unlock_as_irq(struct gpio_chip *chip, unsigned int offset)
  {
-       if (offset >= chip->ngpio)
+       struct gpio_desc *desc;
+       desc = gpiochip_get_desc(chip, offset);
+       if (IS_ERR(desc))
                return;
  
-       clear_bit(FLAG_USED_AS_IRQ, &chip->gpiodev->descs[offset].flags);
+       clear_bit(FLAG_USED_AS_IRQ, &desc->flags);
+       /* If we only had this marking, erase it */
+       if (desc->label && !strcmp(desc->label, "interrupt"))
+               desc_set_label(desc, NULL);
  }
  EXPORT_SYMBOL_GPL(gpiochip_unlock_as_irq);
  
@@@ -3170,7 -3157,7 +3233,7 @@@ static int gpiod_configure_flags(struc
        /* Process flags */
        if (dflags & GPIOD_FLAGS_BIT_DIR_OUT)
                status = gpiod_direction_output(desc,
-                                             dflags & GPIOD_FLAGS_BIT_DIR_VAL);
+                               !!(dflags & GPIOD_FLAGS_BIT_DIR_VAL));
        else
                status = gpiod_direction_input(desc);