Commit 58cf279a authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'gpio-v4.5-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio

Pull GPIO updates from Linus Walleij:
 "Here is the bulk of GPIO changes for v4.5.

  Notably there are big refactorings mostly by myself, aimed at getting
  the gpio_chip into a shape that makes me believe I can proceed to
  preserve state for a proper userspace ABI (character device) that has
  already been proposed once, but resulted in the feedback that I need
  to go back and restructure stuff.  So I've been restructuring stuff.
  On the way I ran into brokenness (return code from the get_value()
  callback) and had to fix it.  Also, refactored generic GPIO to be
  simpler.

  Some of that is still waiting to trickle down from the subsystems all
  over the kernel that provide random gpio_chips, I've touched every
  single GPIO driver in the kernel now, oh man I didn't know I was
  responsible for so much...

  Apart from that we're churning along as usual.

  I took some effort to test and retest so it should merge nicely and we
  shook out a couple of bugs in -next.

  Infrastructural changes:

   - In struct gpio_chip, rename the .dev node to .parent to better
     reflect the fact that this is not the GPIO struct device
     abstraction.  We will add that soon so this would be totallt
     confusing.

   - It was noted that the driver .get_value() callbacks was sometimes
     reporting negative -ERR values to the gpiolib core, expecting them
     to be propagated to consumer gpiod_get_value() and gpio_get_value()
     calls.  This was not happening, so as there was a mess of drivers
     returning negative errors and some returning "anything else than
     zero" to indicate that a line was active.  As some would have bit
     31 set to indicate "line active" it clashed with negative error
     codes.  This is fixed by the largeish series clamping values in all
     drivers with !!value to [0,1] and then augmenting the code to
     propagate error codes to consumers.  (Includes some ACKed patches
     in other subsystems.)

   - Add a void *data pointer to struct gpio_chip.  The container_of()
     design pattern is indeed very nice, but we want to reform the
     struct gpio_chip to be a non-volative, stateless business, and keep
     states internal to the gpiolib to be able to hold on to the state
     when adding a proper userspace ABI (character device) further down
     the road.  To achieve this, drivers need a handle at the internal
     state that is not dependent on their struct gpio_chip() so we add
     gpiochip_add_data() and gpiochip_get_data() following the pattern
     of many other subsystems.  All the "use gpiochip data pointer"
     patches transforms drivers to this scheme.

   - The Generic GPIO chip header has been merged into the general
     <linux/gpio/driver.h> header, and the custom header for that
     removed.  Instead of having a separate mm_gpio_chip struct for
     these generic drivers, merge that into struct gpio_chip,
     simplifying the code and removing the need for separate and
     confusing includes.

  Misc improvements:

   - Stabilize the way GPIOs are looked up from the ACPI legacy
     specification.

   - Incremental driver features for PXA, PCA953X, Lantiq (patches from
     the OpenWRT community), RCAR, Zynq, PL061, 104-idi-48

  New drivers:

   - Add a GPIO chip to the ALSA SoC AC97 driver.

   - Add a new Broadcom NSP SoC driver (this lands in the pinctrl dir,
     but the branch is merged here too to account for infrastructural
     changes).

   - The sx150x driver now supports the sx1502"

* tag 'gpio-v4.5-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio: (220 commits)
  gpio: generic: make bgpio_pdata always visible
  gpiolib: fix chip order in gpio list
  gpio: mpc8xxx: Do not use gpiochip_get_data() in mpc8xxx_gpio_save_regs()
  gpio: mm-lantiq: Do not use gpiochip_get_data() in ltq_mm_save_regs()
  gpio: brcmstb: Allow building driver for BMIPS_GENERIC
  gpio: brcmstb: Set endian flags for big-endian MIPS
  gpio: moxart: fix build regression
  gpio: xilinx: Do not use gpiochip_get_data() in xgpio_save_regs()
  leds: pca9532: use gpiochip data pointer
  leds: tca6507: use gpiochip data pointer
  hid: cp2112: use gpiochip data pointer
  bcma: gpio: use gpiochip data pointer
  avr32: gpio: use gpiochip data pointer
  video: fbdev: via: use gpiochip data pointer
  gpio: pch: Optimize pch_gpio_get()
  Revert "pinctrl: lantiq: Implement gpio_chip.to_irq"
  pinctrl: nsp-gpio: use gpiochip data pointer
  pinctrl: vt8500-wmt: use gpiochip data pointer
  pinctrl: exynos5440: use gpiochip data pointer
  pinctrl: at91-pio4: use gpiochip data pointer
  ...
parents 6606b342 c474e348
...@@ -25,6 +25,7 @@ Required properties: ...@@ -25,6 +25,7 @@ Required properties:
ti,tca6416 ti,tca6416
ti,tca6424 ti,tca6424
ti,tca9539 ti,tca9539
onsemi,pca9654
exar,xra1202 exar,xra1202
Example: Example:
......
...@@ -5,7 +5,8 @@ Required properties: ...@@ -5,7 +5,8 @@ Required properties:
- compatible: should be "semtech,sx1506q", - compatible: should be "semtech,sx1506q",
"semtech,sx1508q", "semtech,sx1508q",
"semtech,sx1509q". "semtech,sx1509q",
"semtech,sx1502q".
- reg: The I2C slave address for this device. - reg: The I2C slave address for this device.
......
* TPS65086 GPO Controller bindings
Required properties:
- compatible : Should be "ti,tps65086-gpio".
- gpio-controller : Marks the device node as a GPIO Controller.
- #gpio-cells : Should be two. The first cell is the pin number
and the second cell is used to specify flags.
See ../gpio/gpio.txt for possible values.
Example:
gpio4: gpio {
compatible = "ti,tps65086-gpio";
gpio-controller;
#gpio-cells = <2>;
};
...@@ -240,6 +240,12 @@ L: lm-sensors@lm-sensors.org ...@@ -240,6 +240,12 @@ L: lm-sensors@lm-sensors.org
S: Maintained S: Maintained
F: drivers/hwmon/abituguru3.c F: drivers/hwmon/abituguru3.c
ACCES 104-IDI-48 GPIO DRIVER
M: "William Breathitt Gray" <vilhelm.gray@gmail.com>
L: linux-gpio@vger.kernel.org
S: Maintained
F: drivers/gpio/gpio-104-idi-48.c
ACCES 104-IDIO-16 GPIO DRIVER ACCES 104-IDIO-16 GPIO DRIVER
M: "William Breathitt Gray" <vilhelm.gray@gmail.com> M: "William Breathitt Gray" <vilhelm.gray@gmail.com>
L: linux-gpio@vger.kernel.org L: linux-gpio@vger.kernel.org
...@@ -7821,11 +7827,12 @@ F: drivers/usb/*/*omap* ...@@ -7821,11 +7827,12 @@ F: drivers/usb/*/*omap*
F: arch/arm/*omap*/usb* F: arch/arm/*omap*/usb*
OMAP GPIO DRIVER OMAP GPIO DRIVER
M: Javier Martinez Canillas <javier@dowhile0.org> M: Grygorii Strashko <grygorii.strashko@ti.com>
M: Santosh Shilimkar <ssantosh@kernel.org> M: Santosh Shilimkar <ssantosh@kernel.org>
M: Kevin Hilman <khilman@deeprootsystems.com> M: Kevin Hilman <khilman@deeprootsystems.com>
L: linux-omap@vger.kernel.org L: linux-omap@vger.kernel.org
S: Maintained S: Maintained
F: Documentation/devicetree/bindings/gpio/gpio-omap.txt
F: drivers/gpio/gpio-omap.c F: drivers/gpio/gpio-omap.c
OMAP/NEWFLOW NANOBONE MACHINE SUPPORT OMAP/NEWFLOW NANOBONE MACHINE SUPPORT
...@@ -8685,6 +8692,12 @@ F: include/sound/pxa2xx-lib.h ...@@ -8685,6 +8692,12 @@ F: include/sound/pxa2xx-lib.h
F: sound/arm/pxa* F: sound/arm/pxa*
F: sound/soc/pxa/ F: sound/soc/pxa/
PXA GPIO DRIVER
M: Robert Jarzmik <robert.jarzmik@free.fr>
L: linux-gpio@vger.kernel.org
S: Maintained
F: drivers/gpio/gpio-pxa.c
PXA3xx NAND FLASH DRIVER PXA3xx NAND FLASH DRIVER
M: Ezequiel Garcia <ezequiel.garcia@free-electrons.com> M: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
L: linux-mtd@lists.infradead.org L: linux-mtd@lists.infradead.org
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
#include <linux/mtd/partitions.h> #include <linux/mtd/partitions.h>
#include <linux/mtd/nand-gpio.h> #include <linux/mtd/nand-gpio.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/basic_mmio_gpio.h> #include <linux/gpio/driver.h>
#include <mach/hardware.h> #include <mach/hardware.h>
#include <asm/sizes.h> #include <asm/sizes.h>
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
#include <linux/leds.h> #include <linux/leds.h>
#include <linux/sizes.h> #include <linux/sizes.h>
#include <linux/backlight.h> #include <linux/backlight.h>
#include <linux/basic_mmio_gpio.h> #include <linux/gpio/driver.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/mtd/partitions.h> #include <linux/mtd/partitions.h>
#include <linux/mtd/nand-gpio.h> #include <linux/mtd/nand-gpio.h>
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/mtd/mtd.h> #include <linux/mtd/mtd.h>
#include <linux/mtd/physmap.h> #include <linux/mtd/physmap.h>
#include <linux/basic_mmio_gpio.h> #include <linux/gpio/driver.h>
#include <linux/gpio.h> #include <linux/gpio.h>
#include <linux/regulator/fixed.h> #include <linux/regulator/fixed.h>
#include <linux/regulator/machine.h> #include <linux/regulator/machine.h>
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* it under the terms of the GNU General Public License version 2 as * it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation. * published by the Free Software Foundation.
*/ */
#include <linux/basic_mmio_gpio.h> #include <linux/gpio/driver.h>
#include <linux/gpio.h> #include <linux/gpio.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/init.h> #include <linux/init.h>
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
#include <linux/pwm_backlight.h> #include <linux/pwm_backlight.h>
#include <linux/dm9000.h> #include <linux/dm9000.h>
#include <linux/gpio_keys.h> #include <linux/gpio_keys.h>
#include <linux/basic_mmio_gpio.h> #include <linux/gpio/driver.h>
#include <linux/spi/spi.h> #include <linux/spi/spi.h>
#include <linux/platform_data/pca953x.h> #include <linux/platform_data/pca953x.h>
......
...@@ -203,7 +203,7 @@ void __init at32_reserve_pin(unsigned int port, u32 pin_mask) ...@@ -203,7 +203,7 @@ void __init at32_reserve_pin(unsigned int port, u32 pin_mask)
static int direction_input(struct gpio_chip *chip, unsigned offset) static int direction_input(struct gpio_chip *chip, unsigned offset)
{ {
struct pio_device *pio = container_of(chip, struct pio_device, chip); struct pio_device *pio = gpiochip_get_data(chip);
u32 mask = 1 << offset; u32 mask = 1 << offset;
if (!(pio_readl(pio, PSR) & mask)) if (!(pio_readl(pio, PSR) & mask))
...@@ -215,7 +215,7 @@ static int direction_input(struct gpio_chip *chip, unsigned offset) ...@@ -215,7 +215,7 @@ static int direction_input(struct gpio_chip *chip, unsigned offset)
static int gpio_get(struct gpio_chip *chip, unsigned offset) static int gpio_get(struct gpio_chip *chip, unsigned offset)
{ {
struct pio_device *pio = container_of(chip, struct pio_device, chip); struct pio_device *pio = gpiochip_get_data(chip);
return (pio_readl(pio, PDSR) >> offset) & 1; return (pio_readl(pio, PDSR) >> offset) & 1;
} }
...@@ -224,7 +224,7 @@ static void gpio_set(struct gpio_chip *chip, unsigned offset, int value); ...@@ -224,7 +224,7 @@ static void gpio_set(struct gpio_chip *chip, unsigned offset, int value);
static int direction_output(struct gpio_chip *chip, unsigned offset, int value) static int direction_output(struct gpio_chip *chip, unsigned offset, int value)
{ {
struct pio_device *pio = container_of(chip, struct pio_device, chip); struct pio_device *pio = gpiochip_get_data(chip);
u32 mask = 1 << offset; u32 mask = 1 << offset;
if (!(pio_readl(pio, PSR) & mask)) if (!(pio_readl(pio, PSR) & mask))
...@@ -237,7 +237,7 @@ static int direction_output(struct gpio_chip *chip, unsigned offset, int value) ...@@ -237,7 +237,7 @@ static int direction_output(struct gpio_chip *chip, unsigned offset, int value)
static void gpio_set(struct gpio_chip *chip, unsigned offset, int value) static void gpio_set(struct gpio_chip *chip, unsigned offset, int value)
{ {
struct pio_device *pio = container_of(chip, struct pio_device, chip); struct pio_device *pio = gpiochip_get_data(chip);
u32 mask = 1 << offset; u32 mask = 1 << offset;
if (value) if (value)
...@@ -335,7 +335,7 @@ gpio_irq_setup(struct pio_device *pio, int irq, int gpio_irq) ...@@ -335,7 +335,7 @@ gpio_irq_setup(struct pio_device *pio, int irq, int gpio_irq)
*/ */
static void pio_bank_show(struct seq_file *s, struct gpio_chip *chip) static void pio_bank_show(struct seq_file *s, struct gpio_chip *chip)
{ {
struct pio_device *pio = container_of(chip, struct pio_device, chip); struct pio_device *pio = gpiochip_get_data(chip);
u32 psr, osr, imr, pdsr, pusr, ifsr, mdsr; u32 psr, osr, imr, pdsr, pusr, ifsr, mdsr;
unsigned i; unsigned i;
u32 mask; u32 mask;
...@@ -397,7 +397,7 @@ static int __init pio_probe(struct platform_device *pdev) ...@@ -397,7 +397,7 @@ static int __init pio_probe(struct platform_device *pdev)
pio->chip.label = pio->name; pio->chip.label = pio->name;
pio->chip.base = pdev->id * 32; pio->chip.base = pdev->id * 32;
pio->chip.ngpio = 32; pio->chip.ngpio = 32;
pio->chip.dev = &pdev->dev; pio->chip.parent = &pdev->dev;
pio->chip.owner = THIS_MODULE; pio->chip.owner = THIS_MODULE;
pio->chip.direction_input = direction_input; pio->chip.direction_input = direction_input;
...@@ -406,7 +406,7 @@ static int __init pio_probe(struct platform_device *pdev) ...@@ -406,7 +406,7 @@ static int __init pio_probe(struct platform_device *pdev)
pio->chip.set = gpio_set; pio->chip.set = gpio_set;
pio->chip.dbg_show = pio_bank_show; pio->chip.dbg_show = pio_bank_show;
gpiochip_add(&pio->chip); gpiochip_add_data(&pio->chip, pio);
gpio_irq_setup(pio, irq, gpio_irq_base); gpio_irq_setup(pio, irq, gpio_irq_base);
......
...@@ -17,14 +17,9 @@ ...@@ -17,14 +17,9 @@
#define BCMA_GPIO_MAX_PINS 32 #define BCMA_GPIO_MAX_PINS 32
static inline struct bcma_drv_cc *bcma_gpio_get_cc(struct gpio_chip *chip)
{
return container_of(chip, struct bcma_drv_cc, gpio);
}
static int bcma_gpio_get_value(struct gpio_chip *chip, unsigned gpio) static int bcma_gpio_get_value(struct gpio_chip *chip, unsigned gpio)
{ {
struct bcma_drv_cc *cc = bcma_gpio_get_cc(chip); struct bcma_drv_cc *cc = gpiochip_get_data(chip);
return !!bcma_chipco_gpio_in(cc, 1 << gpio); return !!bcma_chipco_gpio_in(cc, 1 << gpio);
} }
...@@ -32,14 +27,14 @@ static int bcma_gpio_get_value(struct gpio_chip *chip, unsigned gpio) ...@@ -32,14 +27,14 @@ static int bcma_gpio_get_value(struct gpio_chip *chip, unsigned gpio)
static void bcma_gpio_set_value(struct gpio_chip *chip, unsigned gpio, static void bcma_gpio_set_value(struct gpio_chip *chip, unsigned gpio,
int value) int value)
{ {
struct bcma_drv_cc *cc = bcma_gpio_get_cc(chip); struct bcma_drv_cc *cc = gpiochip_get_data(chip);
bcma_chipco_gpio_out(cc, 1 << gpio, value ? 1 << gpio : 0); bcma_chipco_gpio_out(cc, 1 << gpio, value ? 1 << gpio : 0);
} }
static int bcma_gpio_direction_input(struct gpio_chip *chip, unsigned gpio) static int bcma_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
{ {
struct bcma_drv_cc *cc = bcma_gpio_get_cc(chip); struct bcma_drv_cc *cc = gpiochip_get_data(chip);
bcma_chipco_gpio_outen(cc, 1 << gpio, 0); bcma_chipco_gpio_outen(cc, 1 << gpio, 0);
return 0; return 0;
...@@ -48,7 +43,7 @@ static int bcma_gpio_direction_input(struct gpio_chip *chip, unsigned gpio) ...@@ -48,7 +43,7 @@ static int bcma_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
static int bcma_gpio_direction_output(struct gpio_chip *chip, unsigned gpio, static int bcma_gpio_direction_output(struct gpio_chip *chip, unsigned gpio,
int value) int value)
{ {
struct bcma_drv_cc *cc = bcma_gpio_get_cc(chip); struct bcma_drv_cc *cc = gpiochip_get_data(chip);
bcma_chipco_gpio_outen(cc, 1 << gpio, 1 << gpio); bcma_chipco_gpio_outen(cc, 1 << gpio, 1 << gpio);
bcma_chipco_gpio_out(cc, 1 << gpio, value ? 1 << gpio : 0); bcma_chipco_gpio_out(cc, 1 << gpio, value ? 1 << gpio : 0);
...@@ -57,7 +52,7 @@ static int bcma_gpio_direction_output(struct gpio_chip *chip, unsigned gpio, ...@@ -57,7 +52,7 @@ static int bcma_gpio_direction_output(struct gpio_chip *chip, unsigned gpio,
static int bcma_gpio_request(struct gpio_chip *chip, unsigned gpio) static int bcma_gpio_request(struct gpio_chip *chip, unsigned gpio)
{ {
struct bcma_drv_cc *cc = bcma_gpio_get_cc(chip); struct bcma_drv_cc *cc = gpiochip_get_data(chip);
bcma_chipco_gpio_control(cc, 1 << gpio, 0); bcma_chipco_gpio_control(cc, 1 << gpio, 0);
/* clear pulldown */ /* clear pulldown */
...@@ -70,7 +65,7 @@ static int bcma_gpio_request(struct gpio_chip *chip, unsigned gpio) ...@@ -70,7 +65,7 @@ static int bcma_gpio_request(struct gpio_chip *chip, unsigned gpio)
static void bcma_gpio_free(struct gpio_chip *chip, unsigned gpio) static void bcma_gpio_free(struct gpio_chip *chip, unsigned gpio)
{ {
struct bcma_drv_cc *cc = bcma_gpio_get_cc(chip); struct bcma_drv_cc *cc = gpiochip_get_data(chip);
/* clear pullup */ /* clear pullup */
bcma_chipco_gpio_pullup(cc, 1 << gpio, 0); bcma_chipco_gpio_pullup(cc, 1 << gpio, 0);
...@@ -81,7 +76,7 @@ static void bcma_gpio_free(struct gpio_chip *chip, unsigned gpio) ...@@ -81,7 +76,7 @@ static void bcma_gpio_free(struct gpio_chip *chip, unsigned gpio)
static void bcma_gpio_irq_unmask(struct irq_data *d) static void bcma_gpio_irq_unmask(struct irq_data *d)
{ {
struct gpio_chip *gc = irq_data_get_irq_chip_data(d); struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
struct bcma_drv_cc *cc = bcma_gpio_get_cc(gc); struct bcma_drv_cc *cc = gpiochip_get_data(gc);
int gpio = irqd_to_hwirq(d); int gpio = irqd_to_hwirq(d);
u32 val = bcma_chipco_gpio_in(cc, BIT(gpio)); u32 val = bcma_chipco_gpio_in(cc, BIT(gpio));
...@@ -92,7 +87,7 @@ static void bcma_gpio_irq_unmask(struct irq_data *d) ...@@ -92,7 +87,7 @@ static void bcma_gpio_irq_unmask(struct irq_data *d)
static void bcma_gpio_irq_mask(struct irq_data *d) static void bcma_gpio_irq_mask(struct irq_data *d)
{ {
struct gpio_chip *gc = irq_data_get_irq_chip_data(d); struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
struct bcma_drv_cc *cc = bcma_gpio_get_cc(gc); struct bcma_drv_cc *cc = gpiochip_get_data(gc);
int gpio = irqd_to_hwirq(d); int gpio = irqd_to_hwirq(d);
bcma_chipco_gpio_intmask(cc, BIT(gpio), 0); bcma_chipco_gpio_intmask(cc, BIT(gpio), 0);
...@@ -188,7 +183,7 @@ int bcma_gpio_init(struct bcma_drv_cc *cc) ...@@ -188,7 +183,7 @@ int bcma_gpio_init(struct bcma_drv_cc *cc)
chip->direction_input = bcma_gpio_direction_input; chip->direction_input = bcma_gpio_direction_input;
chip->direction_output = bcma_gpio_direction_output; chip->direction_output = bcma_gpio_direction_output;
chip->owner = THIS_MODULE; chip->owner = THIS_MODULE;
chip->dev = bcma_bus_get_host_dev(bus); chip->parent = bcma_bus_get_host_dev(bus);
#if IS_BUILTIN(CONFIG_OF) #if IS_BUILTIN(CONFIG_OF)
if (cc->core->bus->hosttype == BCMA_HOSTTYPE_SOC) if (cc->core->bus->hosttype == BCMA_HOSTTYPE_SOC)
chip->of_node = cc->core->dev.of_node; chip->of_node = cc->core->dev.of_node;
...@@ -216,7 +211,7 @@ int bcma_gpio_init(struct bcma_drv_cc *cc) ...@@ -216,7 +211,7 @@ int bcma_gpio_init(struct bcma_drv_cc *cc)
else else
chip->base = -1; chip->base = -1;
err = gpiochip_add(chip); err = gpiochip_add_data(chip, cc);
if (err) if (err)
return err; return err;
......
...@@ -134,8 +134,8 @@ config GPIO_BCM_KONA ...@@ -134,8 +134,8 @@ config GPIO_BCM_KONA
config GPIO_BRCMSTB config GPIO_BRCMSTB
tristate "BRCMSTB GPIO support" tristate "BRCMSTB GPIO support"
default y if ARCH_BRCMSTB default y if (ARCH_BRCMSTB || BMIPS_GENERIC)
depends on OF_GPIO && (ARCH_BRCMSTB || COMPILE_TEST) depends on OF_GPIO && (ARCH_BRCMSTB || BMIPS_GENERIC || COMPILE_TEST)
select GPIO_GENERIC select GPIO_GENERIC
select GPIOLIB_IRQCHIP select GPIOLIB_IRQCHIP
help help
...@@ -496,8 +496,21 @@ menu "Port-mapped I/O GPIO drivers" ...@@ -496,8 +496,21 @@ menu "Port-mapped I/O GPIO drivers"
config GPIO_104_IDIO_16 config GPIO_104_IDIO_16
tristate "ACCES 104-IDIO-16 GPIO support" tristate "ACCES 104-IDIO-16 GPIO support"
select GPIOLIB_IRQCHIP
help
Enables GPIO support for the ACCES 104-IDIO-16 family. The base port
address for the device may be set via the idio_16_base module
parameter. The interrupt line number for the device may be set via the
idio_16_irq module parameter.
config GPIO_104_IDI_48
tristate "ACCES 104-IDI-48 GPIO support"
select GPIOLIB_IRQCHIP
help help
Enables GPIO support for the ACCES 104-IDIO-16 family. Enables GPIO support for the ACCES 104-IDI-48 family. The base port
address for the device may be configured via the idi_48_base module
parameter. The interrupt line number for the device may be configured
via the idi_48_irq module parameter.
config GPIO_F7188X config GPIO_F7188X
tristate "F71869, F71869A, F71882FG and F71889F GPIO support" tristate "F71869, F71869A, F71882FG and F71889F GPIO support"
...@@ -907,7 +920,6 @@ menu "PCI GPIO expanders" ...@@ -907,7 +920,6 @@ menu "PCI GPIO expanders"
config GPIO_AMD8111 config GPIO_AMD8111
tristate "AMD 8111 GPIO driver" tristate "AMD 8111 GPIO driver"
depends on PCI
help help
The AMD 8111 south bridge contains 32 GPIO pins which can be used. The AMD 8111 south bridge contains 32 GPIO pins which can be used.
...@@ -919,7 +931,7 @@ config GPIO_AMD8111 ...@@ -919,7 +931,7 @@ config GPIO_AMD8111
config GPIO_BT8XX config GPIO_BT8XX
tristate "BT8XX GPIO abuser" tristate "BT8XX GPIO abuser"
depends on PCI && VIDEO_BT848=n depends on VIDEO_BT848=n
help help
The BT8xx frame grabber chip has 24 GPIO pins that can be abused The BT8xx frame grabber chip has 24 GPIO pins that can be abused
as a cheap PCI GPIO card. as a cheap PCI GPIO card.
...@@ -935,14 +947,13 @@ config GPIO_BT8XX ...@@ -935,14 +947,13 @@ config GPIO_BT8XX
config GPIO_INTEL_MID config GPIO_INTEL_MID
bool "Intel Mid GPIO support" bool "Intel Mid GPIO support"
depends on PCI && X86 depends on X86
select GPIOLIB_IRQCHIP select GPIOLIB_IRQCHIP
help help
Say Y here to support Intel Mid GPIO. Say Y here to support Intel Mid GPIO.
config GPIO_ML_IOH config GPIO_ML_IOH
tristate "OKI SEMICONDUCTOR ML7213 IOH GPIO support" tristate "OKI SEMICONDUCTOR ML7213 IOH GPIO support"
depends on PCI
select GENERIC_IRQ_CHIP select GENERIC_IRQ_CHIP
help help
ML7213 is companion chip for Intel Atom E6xx series. ML7213 is companion chip for Intel Atom E6xx series.
...@@ -952,7 +963,7 @@ config GPIO_ML_IOH ...@@ -952,7 +963,7 @@ config GPIO_ML_IOH
config GPIO_PCH config GPIO_PCH
tristate "Intel EG20T PCH/LAPIS Semiconductor IOH(ML7223/ML7831) GPIO" tristate "Intel EG20T PCH/LAPIS Semiconductor IOH(ML7223/ML7831) GPIO"
depends on PCI && (X86_32 || COMPILE_TEST) depends on X86_32 || MIPS || COMPILE_TEST
select GENERIC_IRQ_CHIP select GENERIC_IRQ_CHIP
help help
This driver is for PCH(Platform controller Hub) GPIO of Intel Topcliff This driver is for PCH(Platform controller Hub) GPIO of Intel Topcliff
...@@ -968,7 +979,6 @@ config GPIO_PCH ...@@ -968,7 +979,6 @@ config GPIO_PCH
config GPIO_RDC321X config GPIO_RDC321X
tristate "RDC R-321x GPIO support" tristate "RDC R-321x GPIO support"
depends on PCI
select MFD_CORE select MFD_CORE
select MFD_RDC321X select MFD_RDC321X
help help
...@@ -977,7 +987,7 @@ config GPIO_RDC321X ...@@ -977,7 +987,7 @@ config GPIO_RDC321X
config GPIO_SODAVILLE config GPIO_SODAVILLE
bool "Intel Sodaville GPIO support" bool "Intel Sodaville GPIO support"
depends on X86 && PCI && OF depends on X86 && OF
select GPIO_GENERIC select GPIO_GENERIC
select GENERIC_IRQ_CHIP select GENERIC_IRQ_CHIP
help help
...@@ -1028,7 +1038,7 @@ menu "USB GPIO expanders" ...@@ -1028,7 +1038,7 @@ menu "USB GPIO expanders"
config GPIO_VIPERBOARD config GPIO_VIPERBOARD
tristate "Viperboard GPIO a & b support" tristate "Viperboard GPIO a & b support"
depends on MFD_VIPERBOARD && USB depends on MFD_VIPERBOARD
help help
Say yes here to access the GPIO signals of Nano River Say yes here to access the GPIO signals of Nano River
Technologies Viperboard. There are two GPIO chips on the Technologies Viperboard. There are two GPIO chips on the
......
...@@ -13,6 +13,7 @@ obj-$(CONFIG_GPIO_ACPI) += gpiolib-acpi.o ...@@ -13,6 +13,7 @@ obj-$(CONFIG_GPIO_ACPI) += gpiolib-acpi.o
obj-$(CONFIG_GPIO_GENERIC) += gpio-generic.o obj-$(CONFIG_GPIO_GENERIC) += gpio-generic.o
obj-$(CONFIG_GPIO_104_IDIO_16) += gpio-104-idio-16.o obj-$(CONFIG_GPIO_104_IDIO_16) += gpio-104-idio-16.o
obj-$(CONFIG_GPIO_104_IDI_48) += gpio-104-idi-48.o
obj-$(CONFIG_GPIO_74X164) += gpio-74x164.o obj-$(CONFIG_GPIO_74X164) += gpio-74x164.o
obj-$(CONFIG_GPIO_74XX_MMIO) += gpio-74xx-mmio.o obj-$(CONFIG_GPIO_74XX_MMIO) += gpio-74xx-mmio.o
obj-$(CONFIG_GPIO_ADNP) += gpio-adnp.o obj-$(CONFIG_GPIO_ADNP) += gpio-adnp.o
......
/*
* GPIO driver for the ACCES 104-IDI-48 family
* Copyright (C) 2015 William Breathitt Gray
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2, as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*/
#include <linux/bitops.h>
#include <linux/device.h>
#include <linux/errno.h>
#include <linux/gpio/driver.h>
#include <linux/io.h>
#include <linux/ioport.h>
#include <linux/interrupt.h>
#include <linux/irqdesc.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/platform_device.h>
#include <linux/spinlock.h>
static unsigned idi_48_base;
module_param(idi_48_base, uint, 0);
MODULE_PARM_DESC(idi_48_base, "ACCES 104-IDI-48 base address");
static unsigned idi_48_irq;
module_param(idi_48_irq, uint, 0);
MODULE_PARM_DESC(idi_48_irq, "ACCES 104-IDI-48 interrupt line number");
/**
* struct idi_48_gpio - GPIO device private data structure
* @chip: instance of the gpio_chip
* @lock: synchronization lock to prevent I/O race conditions
* @ack_lock: synchronization lock to prevent IRQ handler race conditions
* @irq_mask: input bits affected by interrupts
* @base: base port address of the GPIO device
* @extent: extent of port address region of the GPIO device
* @irq: Interrupt line number
* @cos_enb: Change-Of-State IRQ enable boundaries mask
*/
struct idi_48_gpio {
struct gpio_chip chip;
spinlock_t lock;
spinlock_t ack_lock;
unsigned char irq_mask[6];
unsigned base;
unsigned extent;
unsigned irq;
unsigned char cos_enb;
};
static int idi_48_gpio_get_direction(struct gpio_chip *chip, unsigned offset)
{
return 1;
}
static int idi_48_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
{
return 0;
}
static int idi_48_gpio_get(struct gpio_chip *chip, unsigned offset)
{
struct idi_48_gpio *const idi48gpio = gpiochip_get_data(chip);
unsigned i;
const unsigned register_offset[6] = { 0, 1, 2, 4, 5, 6 };
unsigned base_offset;
unsigned mask;
for (i = 0; i < 48; i += 8)
if (offset < i + 8) {
base_offset = register_offset[i / 8];
mask = BIT(offset - i);
return !!(inb(idi48gpio->base + base_offset) & mask);
}
/* The following line should never execute since offset < 48 */
return 0;
}
static void idi_48_irq_ack(struct irq_data *data)
{
}
static void idi_48_irq_mask(struct irq_data *data)
{
struct gpio_chip *chip = irq_data_get_irq_chip_data(data);
struct idi_48_gpio *const idi48gpio = gpiochip_get_data(chip);
const unsigned offset = irqd_to_hwirq(data);
unsigned i;
unsigned mask;
unsigned boundary;
unsigned long flags;
for (i = 0; i < 48; i += 8)
if (offset < i + 8) {
mask = BIT(offset - i);
boundary = i / 8;
idi48gpio->irq_mask[boundary] &= ~mask;
if (!idi48gpio->irq_mask[boundary]) {
idi48gpio->cos_enb &= ~BIT(boundary);
spin_lock_irqsave(&idi48gpio->lock, flags);
outb(idi48gpio->cos_enb, idi48gpio->base + 7);
spin_unlock_irqrestore(&idi48gpio->lock, flags);
}
return;
}
}
static void idi_48_irq_unmask(struct irq_data *data)
{
struct gpio_chip *chip = irq_data_get_irq_chip_data(data);
struct idi_48_gpio *const idi48gpio = gpiochip_get_data(chip);
const unsigned offset = irqd_to_hwirq(data);
unsigned i;
unsigned mask;
unsigned boundary;
unsigned prev_irq_mask;
unsigned long flags;
for (i = 0; i < 48; i += 8)
if (offset < i + 8) {
mask = BIT(offset - i);
boundary = i / 8;
prev_irq_mask = idi48gpio->irq_mask[boundary];
idi48gpio->irq_mask[boundary] |= mask;
if (!prev_irq_mask) {
idi48gpio->cos_enb |= BIT(boundary);
spin_lock_irqsave(&idi48gpio->lock, flags);
outb(idi48gpio->cos_enb, idi48gpio->base + 7);
spin_unlock_irqrestore(&idi48gpio->lock, flags);
}
return;
}
}
static int idi_48_irq_set_type(struct irq_data *data, unsigned flow_type)
{
/* The only valid irq types are none and both-edges */
if (flow_type != IRQ_TYPE_NONE &&
(flow_type & IRQ_TYPE_EDGE_BOTH) != IRQ_TYPE_EDGE_BOTH)
return -EINVAL;
return 0;
}
static struct irq_chip idi_48_irqchip = {
.name = "104-idi-48",
.irq_ack = idi_48_irq_ack,
.irq_mask = idi_48_irq_mask,
.irq_unmask = idi_48_irq_unmask,
.irq_set_type = idi_48_irq_set_type
};
static irqreturn_t idi_48_irq_handler(int irq, void *dev_id)
{
struct idi_48_gpio *const idi48gpio = dev_id;
unsigned long cos_status;
unsigned long boundary;
unsigned long irq_mask;
unsigned long bit_num;
unsigned long gpio;
struct gpio_chip *const chip = &idi48gpio->chip;
spin_lock(&idi48gpio->ack_lock);
spin_lock(&idi48gpio->lock);
cos_status = inb(idi48gpio->base + 7);
spin_unlock(&idi48gpio->lock);
/* IRQ Status (bit 6) is active low (0 = IRQ generated by device) */
if (cos_status & BIT(6)) {
spin_unlock(&idi48gpio->ack_lock);
return IRQ_NONE;
}
/* Bit 0-5 indicate which Change-Of-State boundary triggered the IRQ */
cos_status &= 0x3F;
for_each_set_bit(boundary, &cos_status, 6) {
irq_mask = idi48gpio->irq_mask[boundary];
for_each_set_bit(bit_num, &irq_mask, 8) {
gpio = bit_num + boundary * 8;
generic_handle_irq(irq_find_mapping(chip->irqdomain,
gpio));
}
}
spin_unlock(&idi48gpio->ack_lock);
return IRQ_HANDLED;
}
static int __init idi_48_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct idi_48_gpio *idi48gpio;
const unsigned base = idi_48_base;
const unsigned extent = 8;
const char *const name = dev_name(dev);
int err;
const unsigned irq = idi_48_irq;
idi48gpio = devm_kzalloc(dev, sizeof(*idi48gpio), GFP_KERNEL);
if (!idi48gpio)
return -ENOMEM;
if (!request_region(base, extent, name)) {
dev_err(dev, "Unable to lock %s port addresses (0x%X-0x%X)\n",
name, base, base + extent);
err = -EBUSY;
goto err_lock_io_port;
}
idi48gpio->chip.label = name;
idi48gpio->chip.parent = dev;
idi48gpio->chip.owner = THIS_MODULE;
idi48gpio->chip.base = -1;
idi48gpio->chip.ngpio = 48;
idi48gpio->chip.get_direction = idi_48_gpio_get_direction;
idi48gpio->chip.direction_input = idi_48_gpio_direction_input;
idi48gpio->chip.get = idi_48_gpio_get;
idi48gpio->base = base;
idi48gpio->extent = extent;
idi48gpio->irq = irq;
spin_lock_init(&idi48gpio->lock);
dev_set_drvdata(dev, idi48gpio);
err = gpiochip_add_data(&idi48gpio->chip, idi48gpio);
if (err) {
dev_err(dev, "GPIO registering failed (%d)\n", err);
goto err_gpio_register;
}
/* Disable IRQ by default */
outb(0, base + 7);
inb(base + 7);
err = gpiochip_irqchip_add(&idi48gpio->chip, &idi_48_irqchip, 0,
handle_edge_irq, IRQ_TYPE_NONE);
if (err) {
dev_err(dev, "Could not add irqchip (%d)\n", err);
goto err_gpiochip_irqchip_add;
}
err = request_irq(irq, idi_48_irq_handler, 0, name, idi48gpio);
if (err) {
dev_err(dev, "IRQ handler registering failed (%d)\n", err);
goto err_request_irq;
}
return 0;
err_request_irq:
err_gpiochip_irqchip_add:
gpiochip_remove(&idi48gpio->chip);
err_gpio_register:
release_region(base, extent);
err_lock_io_port:
return err;
}
static int idi_48_remove(struct platform_device *pdev)
{
struct idi_48_gpio *const idi48gpio = platform_get_drvdata(pdev);
free_irq(idi48gpio->irq, idi48gpio);
gpiochip_remove(&idi48gpio->chip);
release_region(idi48gpio->base, idi48gpio->extent);
return 0;
}
static struct platform_device *idi_48_device;
static struct platform_driver idi_48_driver = {
.driver = {
.name = "104-idi-48"
},
.remove = idi_48_remove
};
static void __exit idi_48_exit(void)
{
platform_device_unregister(idi_48_device);
platform_driver_unregister(&idi_48_driver);
}
static int __init idi_48_init(void)
{
int err;
idi_48_device = platform_device_alloc(idi_48_driver.driver.name, -1);
if (!idi_48_device)
return -ENOMEM;
err = platform_device_add(idi_48_device);
if (err)
goto err_platform_device;
err = platform_driver_probe(&idi_48_driver, idi_48_probe);
if (err)
goto err_platform_driver;
return 0;
err_platform_driver:
platform_device_del(idi_48_device);
err_platform_device:
platform_device_put(idi_48_device);
return err;
}
module_init(idi_48_init);
module_exit(idi_48_exit);
MODULE_AUTHOR("William Breathitt Gray <vilhelm.gray@gmail.com>");
MODULE_DESCRIPTION("ACCES 104-IDI-48 GPIO driver");
MODULE_LICENSE("GPL");
...@@ -11,11 +11,14 @@ ...@@ -11,11 +11,14 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details. * General Public License for more details.
*/ */
#include <linux/bitops.h>
#include <linux/device.h> #include <linux/device.h>
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/gpio/driver.h> #include <linux/gpio/driver.h>
#include <linux/io.h> #include <linux/io.h>
#include <linux/ioport.h> #include <linux/ioport.h>
#include <linux/interrupt.h>
#include <linux/irqdesc.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/moduleparam.h> #include <linux/moduleparam.h>
...@@ -25,20 +28,27 @@ ...@@ -25,20 +28,27 @@
static unsigned idio_16_base; static unsigned idio_16_base;
module_param(idio_16_base, uint, 0); module_param(idio_16_base, uint, 0);
MODULE_PARM_DESC(idio_16_base, "ACCES 104-IDIO-16 base address"); MODULE_PARM_DESC(idio_16_base, "ACCES 104-IDIO-16 base address");
static unsigned idio_16_irq;
module_param(idio_16_irq, uint, 0);
MODULE_PARM_DESC(idio_16_irq, "ACCES 104-IDIO-16 interrupt line number");
/** /**
* struct idio_16_gpio - GPIO device private data structure * struct idio_16_gpio - GPIO device private data structure
* @chip: instance of the gpio_chip * @chip: instance of the gpio_chip
* @lock: synchronization lock to prevent gpio_set race conditions * @lock: synchronization lock to prevent I/O race conditions
* @irq_mask: I/O bits affected by interrupts
* @base: base port address of the GPIO device * @base: base port address of the GPIO device
* @extent: extent of port address region of the GPIO device * @extent: extent of port address region of the GPIO device
* @irq: Interrupt line number
* @out_state: output bits state * @out_state: output bits state
*/ */
struct idio_16_gpio { struct idio_16_gpio {
struct gpio_chip chip; struct gpio_chip chip;
spinlock_t lock; spinlock_t lock;
unsigned long irq_mask;
unsigned base; unsigned base;
unsigned extent; unsigned extent;
unsigned irq;
unsigned out_state; unsigned out_state;
}; };
...@@ -62,29 +72,24 @@ static int idio_16_gpio_direction_output(struct gpio_chip *chip, ...@@ -62,29 +72,24 @@ static int idio_16_gpio_direction_output(struct gpio_chip *chip,
return 0; return 0;
} }
static struct idio_16_gpio *to_idio16gpio(struct gpio_chip *gc)
{
return container_of(gc, struct idio_16_gpio, chip);
}
static int idio_16_gpio_get(struct gpio_chip *chip, unsigned offset) static int idio_16_gpio_get(struct gpio_chip *chip, unsigned offset)
{ {
struct idio_16_gpio *const idio16gpio = to_idio16gpio(chip); struct idio_16_gpio *const idio16gpio = gpiochip_get_data(chip);
const unsigned BIT_MASK = 1U << (offset-16); const unsigned mask = BIT(offset-16);
if (offset < 16) if (offset < 16)
return -EINVAL; return -EINVAL;
if (offset < 24) if (offset < 24)
return !!(inb(idio16gpio->base + 1) & BIT_MASK); return !!(inb(idio16gpio->base + 1) & mask);
return !!(inb(idio16gpio->base + 5) & (BIT_MASK>>8)); return !!(inb(idio16gpio->base + 5) & (mask>>8));
} }
static void idio_16_gpio_set(struct gpio_chip *chip, unsigned offset, int value) static void idio_16_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
{ {
struct idio_16_gpio *const idio16gpio = to_idio16gpio(chip); struct idio_16_gpio *const idio16gpio = gpiochip_get_data(chip);
const unsigned BIT_MASK = 1U << offset; const unsigned mask = BIT(offset);
unsigned long flags; unsigned long flags;
if (offset > 15) if (offset > 15)
...@@ -93,9 +98,9 @@ static void idio_16_gpio_set(struct gpio_chip *chip, unsigned offset, int value) ...@@ -93,9 +98,9 @@ static void idio_16_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
spin_lock_irqsave(&idio16gpio->lock, flags); spin_lock_irqsave(&idio16gpio->lock, flags);
if (value) if (value)
idio16gpio->out_state |= BIT_MASK; idio16gpio->out_state |= mask;
else else
idio16gpio->out_state &= ~BIT_MASK; idio16gpio->out_state &= ~mask;
if (offset > 7) if (offset > 7)
outb(idio16gpio->out_state >> 8, idio16gpio->base + 4); outb(idio16gpio->out_state >> 8, idio16gpio->base + 4);
...@@ -105,29 +110,106 @@ static void idio_16_gpio_set(struct gpio_chip *chip, unsigned offset, int value) ...@@ -105,29 +110,106 @@ static void idio_16_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
spin_unlock_irqrestore(&idio16gpio->lock, flags); spin_unlock_irqrestore(&idio16gpio->lock, flags);
} }
static void idio_16_irq_ack(struct irq_data *data)
{
}
static void idio_16_irq_mask(struct irq_data *data)
{
struct gpio_chip *chip = irq_data_get_irq_chip_data(data);
struct idio_16_gpio *const idio16gpio = gpiochip_get_data(chip);
const unsigned long mask = BIT(irqd_to_hwirq(data));
unsigned long flags;
idio16gpio->irq_mask &= ~mask;
if (!idio16gpio->irq_mask) {
spin_lock_irqsave(&idio16gpio->lock, flags);
outb(0, idio16gpio->base + 2);
spin_unlock_irqrestore(&idio16gpio->lock, flags);
}
}
static void idio_16_irq_unmask(struct irq_data *data)
{
struct gpio_chip *chip = irq_data_get_irq_chip_data(data);
struct idio_16_gpio *const idio16gpio = gpiochip_get_data(chip);
const unsigned long mask = BIT(irqd_to_hwirq(data));
const unsigned long prev_irq_mask = idio16gpio->irq_mask;
unsigned long flags;
idio16gpio->irq_mask |= mask;
if (!prev_irq_mask) {
spin_lock_irqsave(&idio16gpio->lock, flags);
inb(idio16gpio->base + 2);
spin_unlock_irqrestore(&idio16gpio->lock, flags);
}
}
static int idio_16_irq_set_type(struct irq_data *data, unsigned flow_type)
{
/* The only valid irq types are none and both-edges */
if (flow_type != IRQ_TYPE_NONE &&
(flow_type & IRQ_TYPE_EDGE_BOTH) != IRQ_TYPE_EDGE_BOTH)
return -EINVAL;
return 0;
}
static struct irq_chip idio_16_irqchip = {
.name = "104-idio-16",
.irq_ack = idio_16_irq_ack,
.irq_mask = idio_16_irq_mask,
.irq_unmask = idio_16_irq_unmask,
.irq_set_type = idio_16_irq_set_type
};
static irqreturn_t idio_16_irq_handler(int irq, void *dev_id)
{
struct idio_16_gpio *const idio16gpio = dev_id;
struct gpio_chip *const chip = &idio16gpio->chip;
int gpio;
for_each_set_bit(gpio, &idio16gpio->irq_mask, chip->ngpio)
generic_handle_irq(irq_find_mapping(chip->irqdomain, gpio));
spin_lock(&idio16gpio->lock);
outb(0, idio16gpio->base + 1);
spin_unlock(&idio16gpio->lock);
return IRQ_HANDLED;
}
static int __init idio_16_probe(struct platform_device *pdev) static int __init idio_16_probe(struct platform_device *pdev)
{ {
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct idio_16_gpio *idio16gpio; struct idio_16_gpio *idio16gpio;
const unsigned base = idio_16_base;
const unsigned extent = 8;
const char *const name = dev_name(dev);
int err; int err;
const unsigned irq = idio_16_irq;
const unsigned BASE = idio_16_base;
const unsigned EXTENT = 8;
const char *const NAME = dev_name(dev);
idio16gpio = devm_kzalloc(dev, sizeof(*idio16gpio), GFP_KERNEL); idio16gpio = devm_kzalloc(dev, sizeof(*idio16gpio), GFP_KERNEL);
if (!idio16gpio) if (!idio16gpio)
return -ENOMEM; return -ENOMEM;
if (!request_region(BASE, EXTENT, NAME)) { if (!request_region(base, extent, name)) {
dev_err(dev, "Unable to lock %s port addresses (0x%X-0x%X)\n", dev_err(dev, "Unable to lock %s port addresses (0x%X-0x%X)\n",
NAME, BASE, BASE + EXTENT); name, base, base + extent);
err = -EBUSY; err = -EBUSY;
goto err_lock_io_port; goto err_lock_io_port;
} }
idio16gpio->chip.label = NAME; idio16gpio->chip.label = name;
idio16gpio->chip.dev = dev; idio16gpio->chip.parent = dev;
idio16gpio->chip.owner = THIS_MODULE; idio16gpio->chip.owner = THIS_MODULE;
idio16gpio->chip.base = -1; idio16gpio->chip.base = -1;
idio16gpio->chip.ngpio = 32; idio16gpio->chip.ngpio = 32;
...@@ -136,24 +218,45 @@ static int __init idio_16_probe(struct platform_device *pdev) ...@@ -136,24 +218,45 @@ static int __init idio_16_probe(struct platform_device *pdev)
idio16gpio->chip.direction_output = idio_16_gpio_direction_output; idio16gpio->chip.direction_output = idio_16_gpio_direction_output;
idio16gpio->chip.get = idio_16_gpio_get; idio16gpio->chip.get = idio_16_gpio_get;
idio16gpio->chip.set = idio_16_gpio_set; idio16gpio->chip.set = idio_16_gpio_set;
idio16gpio->base = BASE; idio16gpio->base = base;
idio16gpio->extent = EXTENT; idio16gpio->extent = extent;
idio16gpio->irq = irq;
idio16gpio->out_state = 0xFFFF; idio16gpio->out_state = 0xFFFF;
spin_lock_init(&idio16gpio->lock); spin_lock_init(&idio16gpio->lock);
dev_set_drvdata(dev, idio16gpio); dev_set_drvdata(dev, idio16gpio);
err = gpiochip_add(&idio16gpio->chip); err = gpiochip_add_data(&idio16gpio->chip, idio16gpio);
if (err) { if (err) {
dev_err(dev, "GPIO registering failed (%d)\n", err); dev_err(dev, "GPIO registering failed (%d)\n", err);
goto err_gpio_register; goto err_gpio_register;
} }
/* Disable IRQ by default */
outb(0, base + 2);
outb(0, base + 1);
err = gpiochip_irqchip_add(&idio16gpio->chip, &idio_16_irqchip, 0,
handle_edge_irq, IRQ_TYPE_NONE);
if (err) {
dev_err(dev, "Could not add irqchip (%d)\n", err);
goto err_gpiochip_irqchip_add;
}
err = request_irq(irq, idio_16_irq_handler, 0, name, idio16gpio);
if (err) {
dev_err(dev, "IRQ handler registering failed (%d)\n", err);
goto err_request_irq;
}
return 0; return 0;
err_request_irq:
err_gpiochip_irqchip_add:
gpiochip_remove(&idio16gpio->chip);
err_gpio_register: err_gpio_register:
release_region(BASE, EXTENT); release_region(base, extent);
err_lock_io_port: err_lock_io_port:
return err; return err;
} }
...@@ -162,6 +265,7 @@ static int idio_16_remove(struct platform_device *pdev) ...@@ -162,6 +265,7 @@ static int idio_16_remove(struct platform_device *pdev)
{ {
struct idio_16_gpio *const idio16gpio = platform_get_drvdata(pdev); struct idio_16_gpio *const idio16gpio = platform_get_drvdata(pdev);
free_irq(idio16gpio->irq, idio16gpio);
gpiochip_remove(&idio16gpio->chip); gpiochip_remove(&idio16gpio->chip);
release_region(idio16gpio->base, idio16gpio->extent); release_region(idio16gpio->base, idio16gpio->extent);
......
...@@ -20,56 +20,34 @@ ...@@ -20,56 +20,34 @@
#define GEN_74X164_NUMBER_GPIOS 8 #define GEN_74X164_NUMBER_GPIOS 8
struct gen_74x164_chip { struct gen_74x164_chip {
u8 *buffer;
struct gpio_chip gpio_chip; struct gpio_chip gpio_chip;
struct mutex lock; struct mutex lock;
u32 registers; u32 registers;
};
static struct gen_74x164_chip *gpio_to_74x164_chip(struct gpio_chip *gc)
{
return container_of(gc, struct gen_74x164_chip, gpio_chip);
}
static int __gen_74x164_write_config(struct gen_74x164_chip *chip)
{
struct spi_device *spi = to_spi_device(chip->gpio_chip.dev);
struct spi_message message;
struct spi_transfer *msg_buf;
int i, ret = 0;
msg_buf = kzalloc(chip->registers * sizeof(struct spi_transfer),
GFP_KERNEL);
if (!msg_buf)
return -ENOMEM;
spi_message_init(&message);
/* /*
* Since the registers are chained, every byte sent will make * Since the registers are chained, every byte sent will make
* the previous byte shift to the next register in the * the previous byte shift to the next register in the
* chain. Thus, the first byte send will end up in the last * chain. Thus, the first byte sent will end up in the last
* register at the end of the transfer. So, to have a logical * register at the end of the transfer. So, to have a logical
* numbering, send the bytes in reverse order so that the last * numbering, store the bytes in reverse order.
* byte of the buffer will end up in the last register.
*/ */
for (i = chip->registers - 1; i >= 0; i--) { u8 buffer[0];
msg_buf[i].tx_buf = chip->buffer + i; };
msg_buf[i].len = sizeof(u8);
spi_message_add_tail(msg_buf + i, &message);
}
ret = spi_sync(spi, &message);
kfree(msg_buf); static int __gen_74x164_write_config(struct gen_74x164_chip *chip)
{
struct spi_transfer xfer = {
.tx_buf = chip->buffer,
.len = chip->registers,
};
return ret; return spi_sync_transfer(to_spi_device(chip->gpio_chip.parent),
&xfer, 1);
} }
static int gen_74x164_get_value(struct gpio_chip *gc, unsigned offset) static int gen_74x164_get_value(struct gpio_chip *gc, unsigned offset)
{ {
struct gen_74x164_chip *chip = gpio_to_74x164_chip(gc); struct gen_74x164_chip *chip = gpiochip_get_data(gc);
u8 bank = offset / 8; u8 bank = chip->registers - 1 - offset / 8;
u8 pin = offset % 8; u8 pin = offset % 8;
int ret; int ret;
...@@ -83,8 +61,8 @@ static int gen_74x164_get_value(struct gpio_chip *gc, unsigned offset) ...@@ -83,8 +61,8 @@ static int gen_74x164_get_value(struct gpio_chip *gc, unsigned offset)
static void gen_74x164_set_value(struct gpio_chip *gc, static void gen_74x164_set_value(struct gpio_chip *gc,
unsigned offset, int val) unsigned offset, int val)
{ {
struct gen_74x164_chip *chip = gpio_to_74x164_chip(gc); struct gen_74x164_chip *chip = gpiochip_get_data(gc);
u8 bank = offset / 8; u8 bank = chip->registers - 1 - offset / 8;
u8 pin = offset % 8; u8 pin = offset % 8;
mutex_lock(&chip->lock); mutex_lock(&chip->lock);
...@@ -107,6 +85,7 @@ static int gen_74x164_direction_output(struct gpio_chip *gc, ...@@ -107,6 +85,7 @@ static int gen_74x164_direction_output(struct gpio_chip *gc,
static int gen_74x164_probe(struct spi_device *spi) static int gen_74x164_probe(struct spi_device *spi)
{ {
struct gen_74x164_chip *chip; struct gen_74x164_chip *chip;
u32 nregs;
int ret; int ret;
/* /*
...@@ -118,7 +97,14 @@ static int gen_74x164_probe(struct spi_device *spi) ...@@ -118,7 +97,14 @@ static int gen_74x164_probe(struct spi_device *spi)
if (ret < 0) if (ret < 0)
return ret; return ret;
chip = devm_kzalloc(&spi->dev, sizeof(*chip), GFP_KERNEL); if (of_property_read_u32(spi->dev.of_node, "registers-number",
&nregs)) {
dev_err(&spi->dev,
"Missing registers-number property in the DT.\n");
return -EINVAL;
}
chip = devm_kzalloc(&spi->dev, sizeof(*chip) + nregs, GFP_KERNEL);
if (!chip) if (!chip)
return -ENOMEM; return -ENOMEM;
...@@ -130,20 +116,11 @@ static int gen_74x164_probe(struct spi_device *spi) ...@@ -130,20 +116,11 @@ static int gen_74x164_probe(struct spi_device *spi)
chip->gpio_chip.set = gen_74x164_set_value; chip->gpio_chip.set = gen_74x164_set_value;
chip->gpio_chip.base = -1; chip->gpio_chip.base = -1;
if (of_property_read_u32(spi->dev.of_node, "registers-number", chip->registers = nregs;
&chip->registers)) {
dev_err(&spi->dev,
"Missing registers-number property in the DT.\n");
return -EINVAL;
}
chip->gpio_chip.ngpio = GEN_74X164_NUMBER_GPIOS * chip->registers; chip->gpio_chip.ngpio = GEN_74X164_NUMBER_GPIOS * chip->registers;
chip->buffer = devm_kzalloc(&spi->dev, chip->registers, GFP_KERNEL);
if (!chip->buffer)
return -ENOMEM;
chip->gpio_chip.can_sleep = true; chip->gpio_chip.can_sleep = true;
chip->gpio_chip.dev = &spi->dev; chip->gpio_chip.parent = &spi->dev;
chip->gpio_chip.owner = THIS_MODULE; chip->gpio_chip.owner = THIS_MODULE;
mutex_init(&chip->lock); mutex_init(&chip->lock);
...@@ -154,7 +131,7 @@ static int gen_74x164_probe(struct spi_device *spi) ...@@ -154,7 +131,7 @@ static int gen_74x164_probe(struct spi_device *spi)
goto exit_destroy; goto exit_destroy;
} }
ret = gpiochip_add(&chip->gpio_chip); ret = gpiochip_add_data(&chip->gpio_chip, chip);
if (!ret) if (!ret)
return 0; return 0;
......
...@@ -10,10 +10,9 @@ ...@@ -10,10 +10,9 @@
*/ */
#include <linux/err.h> #include <linux/err.h>
#include <linux/gpio.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/of_device.h> #include <linux/of_device.h>
#include <linux/basic_mmio_gpio.h> #include <linux/gpio/driver.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#define MMIO_74XX_DIR_IN (0 << 8) #define MMIO_74XX_DIR_IN (0 << 8)
...@@ -21,7 +20,7 @@ ...@@ -21,7 +20,7 @@
#define MMIO_74XX_BIT_CNT(x) ((x) & 0xff) #define MMIO_74XX_BIT_CNT(x) ((x) & 0xff)
struct mmio_74xx_gpio_priv { struct mmio_74xx_gpio_priv {
struct bgpio_chip bgc; struct gpio_chip gc;
unsigned flags; unsigned flags;
}; };
...@@ -78,30 +77,23 @@ static const struct of_device_id mmio_74xx_gpio_ids[] = { ...@@ -78,30 +77,23 @@ static const struct of_device_id mmio_74xx_gpio_ids[] = {
}; };
MODULE_DEVICE_TABLE(of, mmio_74xx_gpio_ids); MODULE_DEVICE_TABLE(of, mmio_74xx_gpio_ids);
static inline struct mmio_74xx_gpio_priv *to_74xx_gpio(struct gpio_chip *gc)
{
struct bgpio_chip *bgc = to_bgpio_chip(gc);
return container_of(bgc, struct mmio_74xx_gpio_priv, bgc);
}
static int mmio_74xx_get_direction(struct gpio_chip *gc, unsigned offset) static int mmio_74xx_get_direction(struct gpio_chip *gc, unsigned offset)
{ {
struct mmio_74xx_gpio_priv *priv = to_74xx_gpio(gc); struct mmio_74xx_gpio_priv *priv = gpiochip_get_data(gc);
return (priv->flags & MMIO_74XX_DIR_OUT) ? GPIOF_DIR_OUT : GPIOF_DIR_IN; return !(priv->flags & MMIO_74XX_DIR_OUT);
} }
static int mmio_74xx_dir_in(struct gpio_chip *gc, unsigned int gpio) static int mmio_74xx_dir_in(struct gpio_chip *gc, unsigned int gpio)
{ {
struct mmio_74xx_gpio_priv *priv = to_74xx_gpio(gc); struct mmio_74xx_gpio_priv *priv = gpiochip_get_data(gc);
return (priv->flags & MMIO_74XX_DIR_OUT) ? -ENOTSUPP : 0; return (priv->flags & MMIO_74XX_DIR_OUT) ? -ENOTSUPP : 0;
} }
static int mmio_74xx_dir_out(struct gpio_chip *gc, unsigned int gpio, int val) static int mmio_74xx_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
{ {
struct mmio_74xx_gpio_priv *priv = to_74xx_gpio(gc); struct mmio_74xx_gpio_priv *priv = gpiochip_get_data(gc);
if (priv->flags & MMIO_74XX_DIR_OUT) { if (priv->flags & MMIO_74XX_DIR_OUT) {
gc->set(gc, gpio, val); gc->set(gc, gpio, val);
...@@ -134,28 +126,29 @@ static int mmio_74xx_gpio_probe(struct platform_device *pdev) ...@@ -134,28 +126,29 @@ static int mmio_74xx_gpio_probe(struct platform_device *pdev)
priv->flags = (uintptr_t) of_id->data; priv->flags = (uintptr_t) of_id->data;
err = bgpio_init(&priv->bgc, &pdev->dev, err = bgpio_init(&priv->gc, &pdev->dev,
DIV_ROUND_UP(MMIO_74XX_BIT_CNT(priv->flags), 8), DIV_ROUND_UP(MMIO_74XX_BIT_CNT(priv->flags), 8),
dat, NULL, NULL, NULL, NULL, 0); dat, NULL, NULL, NULL, NULL, 0);
if (err) if (err)
return err; return err;
priv->bgc.gc.direction_input = mmio_74xx_dir_in; priv->gc.direction_input = mmio_74xx_dir_in;
priv->bgc.gc.direction_output = mmio_74xx_dir_out; priv->gc.direction_output = mmio_74xx_dir_out;
priv->bgc.gc.get_direction = mmio_74xx_get_direction; priv->gc.get_direction = mmio_74xx_get_direction;
priv->bgc.gc.ngpio = MMIO_74XX_BIT_CNT(priv->flags); priv->gc.ngpio = MMIO_74XX_BIT_CNT(priv->flags);
priv->bgc.gc.owner = THIS_MODULE; priv->gc.owner = THIS_MODULE;
platform_set_drvdata(pdev, priv); platform_set_drvdata(pdev, priv);
return gpiochip_add(&priv->bgc.gc); return gpiochip_add_data(&priv->gc, priv);
} }
static int mmio_74xx_gpio_remove(struct platform_device *pdev) static int mmio_74xx_gpio_remove(struct platform_device *pdev)
{ {
struct mmio_74xx_gpio_priv *priv = platform_get_drvdata(pdev); struct mmio_74xx_gpio_priv *priv = platform_get_drvdata(pdev);
return bgpio_remove(&priv->bgc); gpiochip_remove(&priv->gc);
return 0;
} }
static struct platform_driver mmio_74xx_gpio_driver = { static struct platform_driver mmio_74xx_gpio_driver = {
......
...@@ -36,18 +36,13 @@ struct adnp { ...@@ -36,18 +36,13 @@ struct adnp {
u8 *irq_low; u8 *irq_low;
}; };
static inline struct adnp *to_adnp(struct gpio_chip *chip)
{
return container_of(chip, struct adnp, gpio);
}
static int adnp_read(struct adnp *adnp, unsigned offset, uint8_t *value) static int adnp_read(struct adnp *adnp, unsigned offset, uint8_t *value)
{ {
int err; int err;
err = i2c_smbus_read_byte_data(adnp->client, offset); err = i2c_smbus_read_byte_data(adnp->client, offset);
if (err < 0) { if (err < 0) {
dev_err(adnp->gpio.dev, "%s failed: %d\n", dev_err(adnp->gpio.parent, "%s failed: %d\n",
"i2c_smbus_read_byte_data()", err); "i2c_smbus_read_byte_data()", err);
return err; return err;
} }
...@@ -62,7 +57,7 @@ static int adnp_write(struct adnp *adnp, unsigned offset, uint8_t value) ...@@ -62,7 +57,7 @@ static int adnp_write(struct adnp *adnp, unsigned offset, uint8_t value)
err = i2c_smbus_write_byte_data(adnp->client, offset, value); err = i2c_smbus_write_byte_data(adnp->client, offset, value);
if (err < 0) { if (err < 0) {
dev_err(adnp->gpio.dev, "%s failed: %d\n", dev_err(adnp->gpio.parent, "%s failed: %d\n",
"i2c_smbus_write_byte_data()", err); "i2c_smbus_write_byte_data()", err);
return err; return err;
} }
...@@ -72,7 +67,7 @@ static int adnp_write(struct adnp *adnp, unsigned offset, uint8_t value) ...@@ -72,7 +67,7 @@ static int adnp_write(struct adnp *adnp, unsigned offset, uint8_t value)
static int adnp_gpio_get(struct gpio_chip *chip, unsigned offset) static int adnp_gpio_get(struct gpio_chip *chip, unsigned offset)
{ {
struct adnp *adnp = to_adnp(chip); struct adnp *adnp = gpiochip_get_data(chip);
unsigned int reg = offset >> adnp->reg_shift; unsigned int reg = offset >> adnp->reg_shift;
unsigned int pos = offset & 7; unsigned int pos = offset & 7;
u8 value; u8 value;
...@@ -106,7 +101,7 @@ static void __adnp_gpio_set(struct adnp *adnp, unsigned offset, int value) ...@@ -106,7 +101,7 @@ static void __adnp_gpio_set(struct adnp *adnp, unsigned offset, int value)
static void adnp_gpio_set(struct gpio_chip *chip, unsigned offset, int value) static void adnp_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
{ {
struct adnp *adnp = to_adnp(chip); struct adnp *adnp = gpiochip_get_data(chip);
mutex_lock(&adnp->i2c_lock); mutex_lock(&adnp->i2c_lock);
__adnp_gpio_set(adnp, offset, value); __adnp_gpio_set(adnp, offset, value);
...@@ -115,7 +110,7 @@ static void adnp_gpio_set(struct gpio_chip *chip, unsigned offset, int value) ...@@ -115,7 +110,7 @@ static void adnp_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
static int adnp_gpio_direction_input(struct gpio_chip *chip, unsigned offset) static int adnp_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
{ {
struct adnp *adnp = to_adnp(chip); struct adnp *adnp = gpiochip_get_data(chip);
unsigned int reg = offset >> adnp->reg_shift; unsigned int reg = offset >> adnp->reg_shift;
unsigned int pos = offset & 7; unsigned int pos = offset & 7;
u8 value; u8 value;
...@@ -150,7 +145,7 @@ static int adnp_gpio_direction_input(struct gpio_chip *chip, unsigned offset) ...@@ -150,7 +145,7 @@ static int adnp_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
static int adnp_gpio_direction_output(struct gpio_chip *chip, unsigned offset, static int adnp_gpio_direction_output(struct gpio_chip *chip, unsigned offset,
int value) int value)
{ {
struct adnp *adnp = to_adnp(chip); struct adnp *adnp = gpiochip_get_data(chip);
unsigned int reg = offset >> adnp->reg_shift; unsigned int reg = offset >> adnp->reg_shift;
unsigned int pos = offset & 7; unsigned int pos = offset & 7;
int err; int err;
...@@ -187,7 +182,7 @@ static int adnp_gpio_direction_output(struct gpio_chip *chip, unsigned offset, ...@@ -187,7 +182,7 @@ static int adnp_gpio_direction_output(struct gpio_chip *chip, unsigned offset,
static void adnp_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip) static void adnp_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
{ {
struct adnp *adnp = to_adnp(chip); struct adnp *adnp = gpiochip_get_data(chip);
unsigned int num_regs = 1 << adnp->reg_shift, i, j; unsigned int num_regs = 1 << adnp->reg_shift, i, j;
int err; int err;
...@@ -266,11 +261,11 @@ static int adnp_gpio_setup(struct adnp *adnp, unsigned int num_gpios) ...@@ -266,11 +261,11 @@ static int adnp_gpio_setup(struct adnp *adnp, unsigned int num_gpios)
chip->base = -1; chip->base = -1;
chip->ngpio = num_gpios; chip->ngpio = num_gpios;
chip->label = adnp->client->name; chip->label = adnp->client->name;
chip->dev = &adnp->client->dev; chip->parent = &adnp->client->dev;
chip->of_node = chip->dev->of_node; chip->of_node = chip->parent->of_node;
chip->owner = THIS_MODULE; chip->owner = THIS_MODULE;
err = gpiochip_add(chip); err = gpiochip_add_data(chip, adnp);
if (err) if (err)
return err; return err;
...@@ -340,7 +335,7 @@ static irqreturn_t adnp_irq(int irq, void *data) ...@@ -340,7 +335,7 @@ static irqreturn_t adnp_irq(int irq, void *data)
static void adnp_irq_mask(struct irq_data *d) static void adnp_irq_mask(struct irq_data *d)
{ {
struct gpio_chip *gc = irq_data_get_irq_chip_data(d); struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
struct adnp *adnp = to_adnp(gc); struct adnp *adnp = gpiochip_get_data(gc);
unsigned int reg = d->hwirq >> adnp->reg_shift; unsigned int reg = d->hwirq >> adnp->reg_shift;
unsigned int pos = d->hwirq & 7; unsigned int pos = d->hwirq & 7;
...@@ -350,7 +345,7 @@ static void adnp_irq_mask(struct irq_data *d) ...@@ -350,7 +345,7 @@ static void adnp_irq_mask(struct irq_data *d)
static void adnp_irq_unmask(struct irq_data *d) static void adnp_irq_unmask(struct irq_data *d)
{ {
struct gpio_chip *gc = irq_data_get_irq_chip_data(d); struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
struct adnp *adnp = to_adnp(gc); struct adnp *adnp = gpiochip_get_data(gc);
unsigned int reg = d->hwirq >> adnp->reg_shift; unsigned int reg = d->hwirq >> adnp->reg_shift;
unsigned int pos = d->hwirq & 7; unsigned int pos = d->hwirq & 7;
...@@ -360,7 +355,7 @@ static void adnp_irq_unmask(struct irq_data *d) ...@@ -360,7 +355,7 @@ static void adnp_irq_unmask(struct irq_data *d)
static int adnp_irq_set_type(struct irq_data *d, unsigned int type) static int adnp_irq_set_type(struct irq_data *d, unsigned int type)
{ {
struct gpio_chip *gc = irq_data_get_irq_chip_data(d); struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
struct adnp *adnp = to_adnp(gc); struct adnp *adnp = gpiochip_get_data(gc);
unsigned int reg = d->hwirq >> adnp->reg_shift; unsigned int reg = d->hwirq >> adnp->reg_shift;
unsigned int pos = d->hwirq & 7; unsigned int pos = d->hwirq & 7;
...@@ -390,7 +385,7 @@ static int adnp_irq_set_type(struct irq_data *d, unsigned int type) ...@@ -390,7 +385,7 @@ static int adnp_irq_set_type(struct irq_data *d, unsigned int type)
static void adnp_irq_bus_lock(struct irq_data *d) static void adnp_irq_bus_lock(struct irq_data *d)
{ {
struct gpio_chip *gc = irq_data_get_irq_chip_data(d); struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
struct adnp *adnp = to_adnp(gc); struct adnp *adnp = gpiochip_get_data(gc);
mutex_lock(&adnp->irq_lock); mutex_lock(&adnp->irq_lock);
} }
...@@ -398,7 +393,7 @@ static void adnp_irq_bus_lock(struct irq_data *d) ...@@ -398,7 +393,7 @@ static void adnp_irq_bus_lock(struct irq_data *d)
static void adnp_irq_bus_unlock(struct irq_data *d) static void adnp_irq_bus_unlock(struct irq_data *d)
{ {
struct gpio_chip *gc = irq_data_get_irq_chip_data(d); struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
struct adnp *adnp = to_adnp(gc); struct adnp *adnp = gpiochip_get_data(gc);
unsigned int num_regs = 1 << adnp->reg_shift, i; unsigned int num_regs = 1 << adnp->reg_shift, i;
mutex_lock(&adnp->i2c_lock); mutex_lock(&adnp->i2c_lock);
...@@ -435,7 +430,8 @@ static int adnp_irq_setup(struct adnp *adnp) ...@@ -435,7 +430,8 @@ static int adnp_irq_setup(struct adnp *adnp)
* is chosen to match the register layout of the hardware in that * is chosen to match the register layout of the hardware in that
* each segment contains the corresponding bits for all interrupts. * each segment contains the corresponding bits for all interrupts.
*/ */
adnp->irq_enable = devm_kzalloc(chip->dev, num_regs * 6, GFP_KERNEL); adnp->irq_enable = devm_kzalloc(chip->parent, num_regs * 6,
GFP_KERNEL);
if (!adnp->irq_enable) if (!adnp->irq_enable)
return -ENOMEM; return -ENOMEM;
...@@ -462,12 +458,12 @@ static int adnp_irq_setup(struct adnp *adnp) ...@@ -462,12 +458,12 @@ static int adnp_irq_setup(struct adnp *adnp)
adnp->irq_enable[i] = 0x00; adnp->irq_enable[i] = 0x00;
} }
err = devm_request_threaded_irq(chip->dev, adnp->client->irq, err = devm_request_threaded_irq(chip->parent, adnp->client->irq,
NULL, adnp_irq, NULL, adnp_irq,
IRQF_TRIGGER_RISING | IRQF_ONESHOT, IRQF_TRIGGER_RISING | IRQF_ONESHOT,
dev_name(chip->dev), adnp); dev_name(chip->parent), adnp);
if (err != 0) { if (err != 0) {
dev_err(chip->dev, "can't request IRQ#%d: %d\n", dev_err(chip->parent, "can't request IRQ#%d: %d\n",
adnp->client->irq, err); adnp->client->irq, err);
return err; return err;
} }
...@@ -478,7 +474,7 @@ static int adnp_irq_setup(struct adnp *adnp) ...@@ -478,7 +474,7 @@ static int adnp_irq_setup(struct adnp *adnp)
handle_simple_irq, handle_simple_irq,
IRQ_TYPE_NONE); IRQ_TYPE_NONE);
if (err) { if (err) {
dev_err(chip->dev, dev_err(chip->parent,
"could not connect irqchip to gpiochip\n"); "could not connect irqchip to gpiochip\n");
return err; return err;
} }
...@@ -547,7 +543,6 @@ MODULE_DEVICE_TABLE(of, adnp_of_match); ...@@ -547,7 +543,6 @@ MODULE_DEVICE_TABLE(of, adnp_of_match);
static struct i2c_driver adnp_i2c_driver = { static struct i2c_driver adnp_i2c_driver = {
.driver = { .driver = {
.name = "gpio-adnp", .name = "gpio-adnp",
.owner = THIS_MODULE,
.of_match_table = adnp_of_match, .of_match_table = adnp_of_match,
}, },
.probe = adnp_i2c_probe, .probe = adnp_i2c_probe,
......
...@@ -27,7 +27,7 @@ static int adp5520_gpio_get_value(struct gpio_chip *chip, unsigned off) ...@@ -27,7 +27,7 @@ static int adp5520_gpio_get_value(struct gpio_chip *chip, unsigned off)
struct adp5520_gpio *dev; struct adp5520_gpio *dev;
uint8_t reg_val; uint8_t reg_val;
dev = container_of(chip, struct adp5520_gpio, gpio_chip); dev = gpiochip_get_data(chip);
/* /*
* There are dedicated registers for GPIO IN/OUT. * There are dedicated registers for GPIO IN/OUT.
...@@ -46,7 +46,7 @@ static void adp5520_gpio_set_value(struct gpio_chip *chip, ...@@ -46,7 +46,7 @@ static void adp5520_gpio_set_value(struct gpio_chip *chip,
unsigned off, int val) unsigned off, int val)
{ {
struct adp5520_gpio *dev; struct adp5520_gpio *dev;
dev = container_of(chip, struct adp5520_gpio, gpio_chip); dev = gpiochip_get_data(chip);
if (val) if (val)
adp5520_set_bits(dev->master, ADP5520_GPIO_OUT, dev->lut[off]); adp5520_set_bits(dev->master, ADP5520_GPIO_OUT, dev->lut[off]);
...@@ -57,7 +57,7 @@ static void adp5520_gpio_set_value(struct gpio_chip *chip, ...@@ -57,7 +57,7 @@ static void adp5520_gpio_set_value(struct gpio_chip *chip,
static int adp5520_gpio_direction_input(struct gpio_chip *chip, unsigned off) static int adp5520_gpio_direction_input(struct gpio_chip *chip, unsigned off)
{ {
struct adp5520_gpio *dev; struct adp5520_gpio *dev;
dev = container_of(chip, struct adp5520_gpio, gpio_chip); dev = gpiochip_get_data(chip);
clear_bit(off, &dev->output); clear_bit(off, &dev->output);
...@@ -70,7 +70,7 @@ static int adp5520_gpio_direction_output(struct gpio_chip *chip, ...@@ -70,7 +70,7 @@ static int adp5520_gpio_direction_output(struct gpio_chip *chip,
{ {
struct adp5520_gpio *dev; struct adp5520_gpio *dev;
int ret = 0; int ret = 0;
dev = container_of(chip, struct adp5520_gpio, gpio_chip); dev = gpiochip_get_data(chip);
set_bit(off, &dev->output); set_bit(off, &dev->output);
...@@ -153,7 +153,7 @@ static int adp5520_gpio_probe(struct platform_device *pdev) ...@@ -153,7 +153,7 @@ static int adp5520_gpio_probe(struct platform_device *pdev)
goto err; goto err;
} }
ret = gpiochip_add(&dev->gpio_chip); ret = gpiochip_add_data(&dev->gpio_chip, dev);
if (ret) if (ret)
goto err; goto err;
......
...@@ -65,8 +65,7 @@ static int adp5588_gpio_write(struct i2c_client *client, u8 reg, u8 val) ...@@ -65,8 +65,7 @@ static int adp5588_gpio_write(struct i2c_client *client, u8 reg, u8 val)
static int adp5588_gpio_get_value(struct gpio_chip *chip, unsigned off) static int adp5588_gpio_get_value(struct gpio_chip *chip, unsigned off)
{ {
struct adp5588_gpio *dev = struct adp5588_gpio *dev = gpiochip_get_data(chip);
container_of(chip, struct adp5588_gpio, gpio_chip);
unsigned bank = ADP5588_BANK(off); unsigned bank = ADP5588_BANK(off);
unsigned bit = ADP5588_BIT(off); unsigned bit = ADP5588_BIT(off);
int val; int val;
...@@ -87,8 +86,7 @@ static void adp5588_gpio_set_value(struct gpio_chip *chip, ...@@ -87,8 +86,7 @@ static void adp5588_gpio_set_value(struct gpio_chip *chip,
unsigned off, int val) unsigned off, int val)
{ {
unsigned bank, bit; unsigned bank, bit;
struct adp5588_gpio *dev = struct adp5588_gpio *dev = gpiochip_get_data(chip);
container_of(chip, struct adp5588_gpio, gpio_chip);
bank = ADP5588_BANK(off); bank = ADP5588_BANK(off);
bit = ADP5588_BIT(off); bit = ADP5588_BIT(off);
...@@ -108,8 +106,7 @@ static int adp5588_gpio_direction_input(struct gpio_chip *chip, unsigned off) ...@@ -108,8 +106,7 @@ static int adp5588_gpio_direction_input(struct gpio_chip *chip, unsigned off)
{ {
int ret; int ret;
unsigned bank; unsigned bank;
struct adp5588_gpio *dev = struct adp5588_gpio *dev = gpiochip_get_data(chip);
container_of(chip, struct adp5588_gpio, gpio_chip);
bank = ADP5588_BANK(off); bank = ADP5588_BANK(off);
...@@ -126,8 +123,7 @@ static int adp5588_gpio_direction_output(struct gpio_chip *chip, ...@@ -126,8 +123,7 @@ static int adp5588_gpio_direction_output(struct gpio_chip *chip,
{ {
int ret; int ret;
unsigned bank, bit; unsigned bank, bit;
struct adp5588_gpio *dev = struct adp5588_gpio *dev = gpiochip_get_data(chip);
container_of(chip, struct adp5588_gpio, gpio_chip);
bank = ADP5588_BANK(off); bank = ADP5588_BANK(off);
bit = ADP5588_BIT(off); bit = ADP5588_BIT(off);
...@@ -152,8 +148,8 @@ static int adp5588_gpio_direction_output(struct gpio_chip *chip, ...@@ -152,8 +148,8 @@ static int adp5588_gpio_direction_output(struct gpio_chip *chip,
#ifdef CONFIG_GPIO_ADP5588_IRQ #ifdef CONFIG_GPIO_ADP5588_IRQ
static int adp5588_gpio_to_irq(struct gpio_chip *chip, unsigned off) static int adp5588_gpio_to_irq(struct gpio_chip *chip, unsigned off)
{ {
struct adp5588_gpio *dev = struct adp5588_gpio *dev = gpiochip_get_data(chip);
container_of(chip, struct adp5588_gpio, gpio_chip);
return dev->irq_base + off; return dev->irq_base + off;
} }
...@@ -418,7 +414,7 @@ static int adp5588_gpio_probe(struct i2c_client *client, ...@@ -418,7 +414,7 @@ static int adp5588_gpio_probe(struct i2c_client *client,
} }
} }
ret = gpiochip_add(&dev->gpio_chip); ret = gpiochip_add_data(&dev->gpio_chip, dev);
if (ret) if (ret)
goto err_irq; goto err_irq;
......
...@@ -42,11 +42,6 @@ struct altera_gpio_chip { ...@@ -42,11 +42,6 @@ struct altera_gpio_chip {
int mapped_irq; int mapped_irq;
}; };
static struct altera_gpio_chip *to_altera(struct gpio_chip *gc)
{
return container_of(gc, struct altera_gpio_chip, mmchip.gc);
}
static void altera_gpio_irq_unmask(struct irq_data *d) static void altera_gpio_irq_unmask(struct irq_data *d)
{ {
struct altera_gpio_chip *altera_gc; struct altera_gpio_chip *altera_gc;
...@@ -54,7 +49,7 @@ static void altera_gpio_irq_unmask(struct irq_data *d) ...@@ -54,7 +49,7 @@ static void altera_gpio_irq_unmask(struct irq_data *d)
unsigned long flags; unsigned long flags;
u32 intmask; u32 intmask;
altera_gc = to_altera(irq_data_get_irq_chip_data(d)); altera_gc = gpiochip_get_data(irq_data_get_irq_chip_data(d));
mm_gc = &altera_gc->mmchip; mm_gc = &altera_gc->mmchip;
spin_lock_irqsave(&altera_gc->gpio_lock, flags); spin_lock_irqsave(&altera_gc->gpio_lock, flags);
...@@ -72,7 +67,7 @@ static void altera_gpio_irq_mask(struct irq_data *d) ...@@ -72,7 +67,7 @@ static void altera_gpio_irq_mask(struct irq_data *d)
unsigned long flags; unsigned long flags;
u32 intmask; u32 intmask;
altera_gc = to_altera(irq_data_get_irq_chip_data(d)); altera_gc = gpiochip_get_data(irq_data_get_irq_chip_data(d));
mm_gc = &altera_gc->mmchip; mm_gc = &altera_gc->mmchip;
spin_lock_irqsave(&altera_gc->gpio_lock, flags); spin_lock_irqsave(&altera_gc->gpio_lock, flags);
...@@ -92,7 +87,7 @@ static int altera_gpio_irq_set_type(struct irq_data *d, ...@@ -92,7 +87,7 @@ static int altera_gpio_irq_set_type(struct irq_data *d,
{ {
struct altera_gpio_chip *altera_gc; struct altera_gpio_chip *altera_gc;
altera_gc = to_altera(irq_data_get_irq_chip_data(d)); altera_gc = gpiochip_get_data(irq_data_get_irq_chip_data(d));
if (type == IRQ_TYPE_NONE) if (type == IRQ_TYPE_NONE)
return 0; return 0;
...@@ -145,7 +140,7 @@ static void altera_gpio_set(struct gpio_chip *gc, unsigned offset, int value) ...@@ -145,7 +140,7 @@ static void altera_gpio_set(struct gpio_chip *gc, unsigned offset, int value)
unsigned int data_reg; unsigned int data_reg;
mm_gc = to_of_mm_gpio_chip(gc); mm_gc = to_of_mm_gpio_chip(gc);
chip = container_of(mm_gc, struct altera_gpio_chip, mmchip); chip = gpiochip_get_data(gc);
spin_lock_irqsave(&chip->gpio_lock, flags); spin_lock_irqsave(&chip->gpio_lock, flags);
data_reg = readl(mm_gc->regs + ALTERA_GPIO_DATA); data_reg = readl(mm_gc->regs + ALTERA_GPIO_DATA);
...@@ -165,7 +160,7 @@ static int altera_gpio_direction_input(struct gpio_chip *gc, unsigned offset) ...@@ -165,7 +160,7 @@ static int altera_gpio_direction_input(struct gpio_chip *gc, unsigned offset)
unsigned int gpio_ddr; unsigned int gpio_ddr;
mm_gc = to_of_mm_gpio_chip(gc); mm_gc = to_of_mm_gpio_chip(gc);
chip = container_of(mm_gc, struct altera_gpio_chip, mmchip); chip = gpiochip_get_data(gc);
spin_lock_irqsave(&chip->gpio_lock, flags); spin_lock_irqsave(&chip->gpio_lock, flags);
/* Set pin as input, assumes software controlled IP */ /* Set pin as input, assumes software controlled IP */
...@@ -186,7 +181,7 @@ static int altera_gpio_direction_output(struct gpio_chip *gc, ...@@ -186,7 +181,7 @@ static int altera_gpio_direction_output(struct gpio_chip *gc,
unsigned int data_reg, gpio_ddr; unsigned int data_reg, gpio_ddr;
mm_gc = to_of_mm_gpio_chip(gc); mm_gc = to_of_mm_gpio_chip(gc);
chip = container_of(mm_gc, struct altera_gpio_chip, mmchip); chip = gpiochip_get_data(gc);
spin_lock_irqsave(&chip->gpio_lock, flags); spin_lock_irqsave(&chip->gpio_lock, flags);
/* Sets the GPIO value */ /* Sets the GPIO value */
...@@ -215,7 +210,7 @@ static void altera_gpio_irq_edge_handler(struct irq_desc *desc) ...@@ -215,7 +210,7 @@ static void altera_gpio_irq_edge_handler(struct irq_desc *desc)
unsigned long status; unsigned long status;
int i; int i;
altera_gc = to_altera(irq_desc_get_handler_data(desc)); altera_gc = gpiochip_get_data(irq_desc_get_handler_data(desc));
chip = irq_desc_get_chip(desc); chip = irq_desc_get_chip(desc);
mm_gc = &altera_gc->mmchip; mm_gc = &altera_gc->mmchip;
irqdomain = altera_gc->mmchip.gc.irqdomain; irqdomain = altera_gc->mmchip.gc.irqdomain;
...@@ -244,7 +239,7 @@ static void altera_gpio_irq_leveL_high_handler(struct irq_desc *desc) ...@@ -244,7 +239,7 @@ static void altera_gpio_irq_leveL_high_handler(struct irq_desc *desc)
unsigned long status; unsigned long status;
int i; int i;
altera_gc = to_altera(irq_desc_get_handler_data(desc)); altera_gc = gpiochip_get_data(irq_desc_get_handler_data(desc));
chip = irq_desc_get_chip(desc); chip = irq_desc_get_chip(desc);
mm_gc = &altera_gc->mmchip; mm_gc = &altera_gc->mmchip;
irqdomain = altera_gc->mmchip.gc.irqdomain; irqdomain = altera_gc->mmchip.gc.irqdomain;
...@@ -290,9 +285,9 @@ static int altera_gpio_probe(struct platform_device *pdev) ...@@ -290,9 +285,9 @@ static int altera_gpio_probe(struct platform_device *pdev)
altera_gc->mmchip.gc.get = altera_gpio_get; altera_gc->mmchip.gc.get = altera_gpio_get;
altera_gc->mmchip.gc.set = altera_gpio_set; altera_gc->mmchip.gc.set = altera_gpio_set;
altera_gc->mmchip.gc.owner = THIS_MODULE; altera_gc->mmchip.gc.owner = THIS_MODULE;
altera_gc->mmchip.gc.dev = &pdev->dev; altera_gc->mmchip.gc.parent = &pdev->dev;
ret = of_mm_gpiochip_add(node, &altera_gc->mmchip); ret = of_mm_gpiochip_add_data(node, &altera_gc->mmchip, altera_gc);
if (ret) { if (ret) {
dev_err(&pdev->dev, "Failed adding memory mapped gpiochip\n"); dev_err(&pdev->dev, "Failed adding memory mapped gpiochip\n");
return ret; return ret;
......
...@@ -75,11 +75,9 @@ struct amd_gpio { ...@@ -75,11 +75,9 @@ struct amd_gpio {
u8 orig[32]; u8 orig[32];
}; };
#define to_agp(chip) container_of(chip, struct amd_gpio, chip)
static int amd_gpio_request(struct gpio_chip *chip, unsigned offset) static int amd_gpio_request(struct gpio_chip *chip, unsigned offset)
{ {
struct amd_gpio *agp = to_agp(chip); struct amd_gpio *agp = gpiochip_get_data(chip);
agp->orig[offset] = ioread8(agp->pm + AMD_REG_GPIO(offset)) & agp->orig[offset] = ioread8(agp->pm + AMD_REG_GPIO(offset)) &
(AMD_GPIO_DEBOUNCE | AMD_GPIO_MODE_MASK | AMD_GPIO_X_MASK); (AMD_GPIO_DEBOUNCE | AMD_GPIO_MODE_MASK | AMD_GPIO_X_MASK);
...@@ -91,7 +89,7 @@ static int amd_gpio_request(struct gpio_chip *chip, unsigned offset) ...@@ -91,7 +89,7 @@ static int amd_gpio_request(struct gpio_chip *chip, unsigned offset)
static void amd_gpio_free(struct gpio_chip *chip, unsigned offset) static void amd_gpio_free(struct gpio_chip *chip, unsigned offset)
{ {
struct amd_gpio *agp = to_agp(chip); struct amd_gpio *agp = gpiochip_get_data(chip);
dev_dbg(&agp->pdev->dev, "Freed gpio %d, data %x\n", offset, agp->orig[offset]); dev_dbg(&agp->pdev->dev, "Freed gpio %d, data %x\n", offset, agp->orig[offset]);
...@@ -100,7 +98,7 @@ static void amd_gpio_free(struct gpio_chip *chip, unsigned offset) ...@@ -100,7 +98,7 @@ static void amd_gpio_free(struct gpio_chip *chip, unsigned offset)
static void amd_gpio_set(struct gpio_chip *chip, unsigned offset, int value) static void amd_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
{ {
struct amd_gpio *agp = to_agp(chip); struct amd_gpio *agp = gpiochip_get_data(chip);
u8 temp; u8 temp;
unsigned long flags; unsigned long flags;
...@@ -115,7 +113,7 @@ static void amd_gpio_set(struct gpio_chip *chip, unsigned offset, int value) ...@@ -115,7 +113,7 @@ static void amd_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
static int amd_gpio_get(struct gpio_chip *chip, unsigned offset) static int amd_gpio_get(struct gpio_chip *chip, unsigned offset)
{ {
struct amd_gpio *agp = to_agp(chip); struct amd_gpio *agp = gpiochip_get_data(chip);
u8 temp; u8 temp;
temp = ioread8(agp->pm + AMD_REG_GPIO(offset)); temp = ioread8(agp->pm + AMD_REG_GPIO(offset));
...@@ -127,7 +125,7 @@ static int amd_gpio_get(struct gpio_chip *chip, unsigned offset) ...@@ -127,7 +125,7 @@ static int amd_gpio_get(struct gpio_chip *chip, unsigned offset)
static int amd_gpio_dirout(struct gpio_chip *chip, unsigned offset, int value) static int amd_gpio_dirout(struct gpio_chip *chip, unsigned offset, int value)
{ {
struct amd_gpio *agp = to_agp(chip); struct amd_gpio *agp = gpiochip_get_data(chip);
u8 temp; u8 temp;
unsigned long flags; unsigned long flags;
...@@ -144,7 +142,7 @@ static int amd_gpio_dirout(struct gpio_chip *chip, unsigned offset, int value) ...@@ -144,7 +142,7 @@ static int amd_gpio_dirout(struct gpio_chip *chip, unsigned offset, int value)
static int amd_gpio_dirin(struct gpio_chip *chip, unsigned offset) static int amd_gpio_dirin(struct gpio_chip *chip, unsigned offset)
{ {
struct amd_gpio *agp = to_agp(chip); struct amd_gpio *agp = gpiochip_get_data(chip);
u8 temp; u8 temp;
unsigned long flags; unsigned long flags;
...@@ -220,12 +218,12 @@ static int __init amd_gpio_init(void) ...@@ -220,12 +218,12 @@ static int __init amd_gpio_init(void)
goto out; goto out;
} }
gp.pdev = pdev; gp.pdev = pdev;
gp.chip.dev = &pdev->dev; gp.chip.parent = &pdev->dev;
spin_lock_init(&gp.lock); spin_lock_init(&gp.lock);
printk(KERN_INFO "AMD-8111 GPIO detected\n"); printk(KERN_INFO "AMD-8111 GPIO detected\n");
err = gpiochip_add(&gp.chip); err = gpiochip_add_data(&gp.chip, &gp);
if (err) { if (err) {
printk(KERN_ERR "GPIO registering failed (%d)\n", printk(KERN_ERR "GPIO registering failed (%d)\n",
err); err);
......
...@@ -31,22 +31,20 @@ struct pt_gpio_chip { ...@@ -31,22 +31,20 @@ struct pt_gpio_chip {
spinlock_t lock; spinlock_t lock;
}; };
#define to_pt_gpio(c) container_of(c, struct pt_gpio_chip, gc)
static int pt_gpio_request(struct gpio_chip *gc, unsigned offset) static int pt_gpio_request(struct gpio_chip *gc, unsigned offset)
{ {
struct pt_gpio_chip *pt_gpio = to_pt_gpio(gc); struct pt_gpio_chip *pt_gpio = gpiochip_get_data(gc);
unsigned long flags; unsigned long flags;
u32 using_pins; u32 using_pins;
dev_dbg(gc->dev, "pt_gpio_request offset=%x\n", offset); dev_dbg(gc->parent, "pt_gpio_request offset=%x\n", offset);
spin_lock_irqsave(&pt_gpio->lock, flags); spin_lock_irqsave(&pt_gpio->lock, flags);
using_pins = readl(pt_gpio->reg_base + PT_SYNC_REG); using_pins = readl(pt_gpio->reg_base + PT_SYNC_REG);
if (using_pins & BIT(offset)) { if (using_pins & BIT(offset)) {
dev_warn(gc->dev, "PT GPIO pin %x reconfigured\n", dev_warn(gc->parent, "PT GPIO pin %x reconfigured\n",
offset); offset);
spin_unlock_irqrestore(&pt_gpio->lock, flags); spin_unlock_irqrestore(&pt_gpio->lock, flags);
return -EINVAL; return -EINVAL;
} }
...@@ -60,7 +58,7 @@ static int pt_gpio_request(struct gpio_chip *gc, unsigned offset) ...@@ -60,7 +58,7 @@ static int pt_gpio_request(struct gpio_chip *gc, unsigned offset)
static void pt_gpio_free(struct gpio_chip *gc, unsigned offset) static void pt_gpio_free(struct gpio_chip *gc, unsigned offset)
{ {
struct pt_gpio_chip *pt_gpio = to_pt_gpio(gc); struct pt_gpio_chip *pt_gpio = gpiochip_get_data(gc);
unsigned long flags; unsigned long flags;
u32 using_pins; u32 using_pins;
...@@ -72,16 +70,16 @@ static void pt_gpio_free(struct gpio_chip *gc, unsigned offset) ...@@ -72,16 +70,16 @@ static void pt_gpio_free(struct gpio_chip *gc, unsigned offset)
spin_unlock_irqrestore(&pt_gpio->lock, flags); spin_unlock_irqrestore(&pt_gpio->lock, flags);
dev_dbg(gc->dev, "pt_gpio_free offset=%x\n", offset); dev_dbg(gc->parent, "pt_gpio_free offset=%x\n", offset);
} }
static void pt_gpio_set_value(struct gpio_chip *gc, unsigned offset, int value) static void pt_gpio_set_value(struct gpio_chip *gc, unsigned offset, int value)
{ {
struct pt_gpio_chip *pt_gpio = to_pt_gpio(gc); struct pt_gpio_chip *pt_gpio = gpiochip_get_data(gc);
unsigned long flags; unsigned long flags;
u32 data; u32 data;
dev_dbg(gc->dev, "pt_gpio_set_value offset=%x, value=%x\n", dev_dbg(gc->parent, "pt_gpio_set_value offset=%x, value=%x\n",
offset, value); offset, value);
spin_lock_irqsave(&pt_gpio->lock, flags); spin_lock_irqsave(&pt_gpio->lock, flags);
...@@ -97,7 +95,7 @@ static void pt_gpio_set_value(struct gpio_chip *gc, unsigned offset, int value) ...@@ -97,7 +95,7 @@ static void pt_gpio_set_value(struct gpio_chip *gc, unsigned offset, int value)
static int pt_gpio_get_value(struct gpio_chip *gc, unsigned offset) static int pt_gpio_get_value(struct gpio_chip *gc, unsigned offset)
{ {
struct pt_gpio_chip *pt_gpio = to_pt_gpio(gc); struct pt_gpio_chip *pt_gpio = gpiochip_get_data(gc);
unsigned long flags; unsigned long flags;
u32 data; u32 data;
...@@ -116,7 +114,7 @@ static int pt_gpio_get_value(struct gpio_chip *gc, unsigned offset) ...@@ -116,7 +114,7 @@ static int pt_gpio_get_value(struct gpio_chip *gc, unsigned offset)
data >>= offset; data >>= offset;
data &= 1; data &= 1;
dev_dbg(gc->dev, "pt_gpio_get_value offset=%x, value=%x\n", dev_dbg(gc->parent, "pt_gpio_get_value offset=%x, value=%x\n",
offset, data); offset, data);
return data; return data;
...@@ -124,11 +122,11 @@ static int pt_gpio_get_value(struct gpio_chip *gc, unsigned offset) ...@@ -124,11 +122,11 @@ static int pt_gpio_get_value(struct gpio_chip *gc, unsigned offset)
static int pt_gpio_direction_input(struct gpio_chip *gc, unsigned offset) static int pt_gpio_direction_input(struct gpio_chip *gc, unsigned offset)
{ {
struct pt_gpio_chip *pt_gpio = to_pt_gpio(gc); struct pt_gpio_chip *pt_gpio = gpiochip_get_data(gc);
unsigned long flags; unsigned long flags;
u32 data; u32 data;
dev_dbg(gc->dev, "pt_gpio_dirction_input offset=%x\n", offset); dev_dbg(gc->parent, "pt_gpio_dirction_input offset=%x\n", offset);
spin_lock_irqsave(&pt_gpio->lock, flags); spin_lock_irqsave(&pt_gpio->lock, flags);
...@@ -144,11 +142,11 @@ static int pt_gpio_direction_input(struct gpio_chip *gc, unsigned offset) ...@@ -144,11 +142,11 @@ static int pt_gpio_direction_input(struct gpio_chip *gc, unsigned offset)
static int pt_gpio_direction_output(struct gpio_chip *gc, static int pt_gpio_direction_output(struct gpio_chip *gc,
unsigned offset, int value) unsigned offset, int value)
{ {
struct pt_gpio_chip *pt_gpio = to_pt_gpio(gc); struct pt_gpio_chip *pt_gpio = gpiochip_get_data(gc);
unsigned long flags; unsigned long flags;
u32 data; u32 data;
dev_dbg(gc->dev, "pt_gpio_direction_output offset=%x, value=%x\n", dev_dbg(gc->parent, "pt_gpio_direction_output offset=%x, value=%x\n",
offset, value); offset, value);
spin_lock_irqsave(&pt_gpio->lock, flags); spin_lock_irqsave(&pt_gpio->lock, flags);
...@@ -202,7 +200,7 @@ static int pt_gpio_probe(struct platform_device *pdev) ...@@ -202,7 +200,7 @@ static int pt_gpio_probe(struct platform_device *pdev)
pt_gpio->gc.label = pdev->name; pt_gpio->gc.label = pdev->name;
pt_gpio->gc.owner = THIS_MODULE; pt_gpio->gc.owner = THIS_MODULE;
pt_gpio->gc.dev = dev; pt_gpio->gc.parent = dev;
pt_gpio->gc.request = pt_gpio_request; pt_gpio->gc.request = pt_gpio_request;
pt_gpio->gc.free = pt_gpio_free; pt_gpio->gc.free = pt_gpio_free;
pt_gpio->gc.direction_input = pt_gpio_direction_input; pt_gpio->gc.direction_input = pt_gpio_direction_input;
...@@ -214,7 +212,7 @@ static int pt_gpio_probe(struct platform_device *pdev) ...@@ -214,7 +212,7 @@ static int pt_gpio_probe(struct platform_device *pdev)
#if defined(CONFIG_OF_GPIO) #if defined(CONFIG_OF_GPIO)
pt_gpio->gc.of_node = pdev->dev.of_node; pt_gpio->gc.of_node = pdev->dev.of_node;
#endif #endif
ret = gpiochip_add(&pt_gpio->gc); ret = gpiochip_add_data(&pt_gpio->gc, pt_gpio);
if (ret) { if (ret) {
dev_err(&pdev->dev, "Failed to register GPIO lib\n"); dev_err(&pdev->dev, "Failed to register GPIO lib\n");
return ret; return ret;
......
...@@ -28,14 +28,9 @@ struct arizona_gpio { ...@@ -28,14 +28,9 @@ struct arizona_gpio {
struct gpio_chip gpio_chip; struct gpio_chip gpio_chip;
}; };
static inline struct arizona_gpio *to_arizona_gpio(struct gpio_chip *chip)
{
return container_of(chip, struct arizona_gpio, gpio_chip);
}
static int arizona_gpio_direction_in(struct gpio_chip *chip, unsigned offset) static int arizona_gpio_direction_in(struct gpio_chip *chip, unsigned offset)
{ {
struct arizona_gpio *arizona_gpio = to_arizona_gpio(chip); struct arizona_gpio *arizona_gpio = gpiochip_get_data(chip);
struct arizona *arizona = arizona_gpio->arizona; struct arizona *arizona = arizona_gpio->arizona;
return regmap_update_bits(arizona->regmap, ARIZONA_GPIO1_CTRL + offset, return regmap_update_bits(arizona->regmap, ARIZONA_GPIO1_CTRL + offset,
...@@ -44,7 +39,7 @@ static int arizona_gpio_direction_in(struct gpio_chip *chip, unsigned offset) ...@@ -44,7 +39,7 @@ static int arizona_gpio_direction_in(struct gpio_chip *chip, unsigned offset)
static int arizona_gpio_get(struct gpio_chip *chip, unsigned offset) static int arizona_gpio_get(struct gpio_chip *chip, unsigned offset)
{ {
struct arizona_gpio *arizona_gpio = to_arizona_gpio(chip); struct arizona_gpio *arizona_gpio = gpiochip_get_data(chip);
struct arizona *arizona = arizona_gpio->arizona; struct arizona *arizona = arizona_gpio->arizona;
unsigned int val; unsigned int val;
int ret; int ret;
...@@ -62,7 +57,7 @@ static int arizona_gpio_get(struct gpio_chip *chip, unsigned offset) ...@@ -62,7 +57,7 @@ static int arizona_gpio_get(struct gpio_chip *chip, unsigned offset)
static int arizona_gpio_direction_out(struct gpio_chip *chip, static int arizona_gpio_direction_out(struct gpio_chip *chip,
unsigned offset, int value) unsigned offset, int value)
{ {
struct arizona_gpio *arizona_gpio = to_arizona_gpio(chip); struct arizona_gpio *arizona_gpio = gpiochip_get_data(chip);
struct arizona *arizona = arizona_gpio->arizona; struct arizona *arizona = arizona_gpio->arizona;
if (value) if (value)
...@@ -74,7 +69,7 @@ static int arizona_gpio_direction_out(struct gpio_chip *chip, ...@@ -74,7 +69,7 @@ static int arizona_gpio_direction_out(struct gpio_chip *chip,
static void arizona_gpio_set(struct gpio_chip *chip, unsigned offset, int value) static void arizona_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
{ {
struct arizona_gpio *arizona_gpio = to_arizona_gpio(chip); struct arizona_gpio *arizona_gpio = gpiochip_get_data(chip);
struct arizona *arizona = arizona_gpio->arizona; struct arizona *arizona = arizona_gpio->arizona;
if (value) if (value)
...@@ -108,7 +103,7 @@ static int arizona_gpio_probe(struct platform_device *pdev) ...@@ -108,7 +103,7 @@ static int arizona_gpio_probe(struct platform_device *pdev)
arizona_gpio->arizona = arizona; arizona_gpio->arizona = arizona;
arizona_gpio->gpio_chip = template_chip; arizona_gpio->gpio_chip = template_chip;
arizona_gpio->gpio_chip.dev = &pdev->dev; arizona_gpio->gpio_chip.parent = &pdev->dev;
#ifdef CONFIG_OF_GPIO #ifdef CONFIG_OF_GPIO
arizona_gpio->gpio_chip.of_node = arizona->dev->of_node; arizona_gpio->gpio_chip.of_node = arizona->dev->of_node;
#endif #endif
...@@ -137,7 +132,7 @@ static int arizona_gpio_probe(struct platform_device *pdev) ...@@ -137,7 +132,7 @@ static int arizona_gpio_probe(struct platform_device *pdev)
else else
arizona_gpio->gpio_chip.base = -1; arizona_gpio->gpio_chip.base = -1;
ret = gpiochip_add(&arizona_gpio->gpio_chip); ret = gpiochip_add_data(&arizona_gpio->gpio_chip, arizona_gpio);
if (ret < 0) { if (ret < 0) {
dev_err(&pdev->dev, "Could not register gpiochip, %d\n", dev_err(&pdev->dev, "Could not register gpiochip, %d\n",
ret); ret);
......
...@@ -24,12 +24,10 @@ struct ath79_gpio_ctrl { ...@@ -24,12 +24,10 @@ struct ath79_gpio_ctrl {
spinlock_t lock; spinlock_t lock;
}; };
#define to_ath79_gpio_ctrl(c) container_of(c, struct ath79_gpio_ctrl, chip)
static void ath79_gpio_set_value(struct gpio_chip *chip, static void ath79_gpio_set_value(struct gpio_chip *chip,
unsigned gpio, int value) unsigned gpio, int value)
{ {
struct ath79_gpio_ctrl *ctrl = to_ath79_gpio_ctrl(chip); struct ath79_gpio_ctrl *ctrl = gpiochip_get_data(chip);
if (value) if (value)
__raw_writel(BIT(gpio), ctrl->base + AR71XX_GPIO_REG_SET); __raw_writel(BIT(gpio), ctrl->base + AR71XX_GPIO_REG_SET);
...@@ -39,7 +37,7 @@ static void ath79_gpio_set_value(struct gpio_chip *chip, ...@@ -39,7 +37,7 @@ static void ath79_gpio_set_value(struct gpio_chip *chip,
static int ath79_gpio_get_value(struct gpio_chip *chip, unsigned gpio) static int ath79_gpio_get_value(struct gpio_chip *chip, unsigned gpio)
{ {
struct ath79_gpio_ctrl *ctrl = to_ath79_gpio_ctrl(chip); struct ath79_gpio_ctrl *ctrl = gpiochip_get_data(chip);
return (__raw_readl(ctrl->base + AR71XX_GPIO_REG_IN) >> gpio) & 1; return (__raw_readl(ctrl->base + AR71XX_GPIO_REG_IN) >> gpio) & 1;
} }
...@@ -47,7 +45,7 @@ static int ath79_gpio_get_value(struct gpio_chip *chip, unsigned gpio) ...@@ -47,7 +45,7 @@ static int ath79_gpio_get_value(struct gpio_chip *chip, unsigned gpio)
static int ath79_gpio_direction_input(struct gpio_chip *chip, static int ath79_gpio_direction_input(struct gpio_chip *chip,
unsigned offset) unsigned offset)
{ {
struct ath79_gpio_ctrl *ctrl = to_ath79_gpio_ctrl(chip); struct ath79_gpio_ctrl *ctrl = gpiochip_get_data(chip);
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&ctrl->lock, flags); spin_lock_irqsave(&ctrl->lock, flags);
...@@ -64,7 +62,7 @@ static int ath79_gpio_direction_input(struct gpio_chip *chip, ...@@ -64,7 +62,7 @@ static int ath79_gpio_direction_input(struct gpio_chip *chip,
static int ath79_gpio_direction_output(struct gpio_chip *chip, static int ath79_gpio_direction_output(struct gpio_chip *chip,
unsigned offset, int value) unsigned offset, int value)
{ {
struct ath79_gpio_ctrl *ctrl = to_ath79_gpio_ctrl(chip); struct ath79_gpio_ctrl *ctrl = gpiochip_get_data(chip);
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&ctrl->lock, flags); spin_lock_irqsave(&ctrl->lock, flags);
...@@ -85,7 +83,7 @@ static int ath79_gpio_direction_output(struct gpio_chip *chip, ...@@ -85,7 +83,7 @@ static int ath79_gpio_direction_output(struct gpio_chip *chip,
static int ar934x_gpio_direction_input(struct gpio_chip *chip, unsigned offset) static int ar934x_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
{ {
struct ath79_gpio_ctrl *ctrl = to_ath79_gpio_ctrl(chip); struct ath79_gpio_ctrl *ctrl = gpiochip_get_data(chip);
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&ctrl->lock, flags); spin_lock_irqsave(&ctrl->lock, flags);
...@@ -102,7 +100,7 @@ static int ar934x_gpio_direction_input(struct gpio_chip *chip, unsigned offset) ...@@ -102,7 +100,7 @@ static int ar934x_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
static int ar934x_gpio_direction_output(struct gpio_chip *chip, unsigned offset, static int ar934x_gpio_direction_output(struct gpio_chip *chip, unsigned offset,
int value) int value)
{ {
struct ath79_gpio_ctrl *ctrl = to_ath79_gpio_ctrl(chip); struct ath79_gpio_ctrl *ctrl = gpiochip_get_data(chip);
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&ctrl->lock, flags); spin_lock_irqsave(&ctrl->lock, flags);
...@@ -138,7 +136,7 @@ static const struct of_device_id ath79_gpio_of_match[] = { ...@@ -138,7 +136,7 @@ static const struct of_device_id ath79_gpio_of_match[] = {
static int ath79_gpio_probe(struct platform_device *pdev) static int ath79_gpio_probe(struct platform_device *pdev)
{ {
struct ath79_gpio_platform_data *pdata = pdev->dev.platform_data; struct ath79_gpio_platform_data *pdata = dev_get_platdata(&pdev->dev);
struct device_node *np = pdev->dev.of_node; struct device_node *np = pdev->dev.of_node;
struct ath79_gpio_ctrl *ctrl; struct ath79_gpio_ctrl *ctrl;
struct resource *res; struct resource *res;
...@@ -177,14 +175,14 @@ static int ath79_gpio_probe(struct platform_device *pdev) ...@@ -177,14 +175,14 @@ static int ath79_gpio_probe(struct platform_device *pdev)
spin_lock_init(&ctrl->lock); spin_lock_init(&ctrl->lock);
memcpy(&ctrl->chip, &ath79_gpio_chip, sizeof(ctrl->chip)); memcpy(&ctrl->chip, &ath79_gpio_chip, sizeof(ctrl->chip));
ctrl->chip.dev = &pdev->dev; ctrl->chip.parent = &pdev->dev;
ctrl->chip.ngpio = ath79_gpio_count; ctrl->chip.ngpio = ath79_gpio_count;
if (oe_inverted) { if (oe_inverted) {
ctrl->chip.direction_input = ar934x_gpio_direction_input; ctrl->chip.direction_input = ar934x_gpio_direction_input;
ctrl->chip.direction_output = ar934x_gpio_direction_output; ctrl->chip.direction_output = ar934x_gpio_direction_output;
} }
err = gpiochip_add(&ctrl->chip); err = gpiochip_add_data(&ctrl->chip, ctrl);
if (err) { if (err) {
dev_err(&pdev->dev, dev_err(&pdev->dev,
"cannot add AR71xx GPIO chip, error=%d", err); "cannot add AR71xx GPIO chip, error=%d", err);
......
...@@ -78,11 +78,6 @@ struct bcm_kona_gpio_bank { ...@@ -78,11 +78,6 @@ struct bcm_kona_gpio_bank {
struct bcm_kona_gpio *kona_gpio; struct bcm_kona_gpio *kona_gpio;
}; };
static inline struct bcm_kona_gpio *to_kona_gpio(struct gpio_chip *chip)
{
return container_of(chip, struct bcm_kona_gpio, gpio_chip);
}
static inline void bcm_kona_gpio_write_lock_regs(void __iomem *reg_base, static inline void bcm_kona_gpio_write_lock_regs(void __iomem *reg_base,
int bank_id, u32 lockcode) int bank_id, u32 lockcode)
{ {
...@@ -124,7 +119,7 @@ static void bcm_kona_gpio_unlock_gpio(struct bcm_kona_gpio *kona_gpio, ...@@ -124,7 +119,7 @@ static void bcm_kona_gpio_unlock_gpio(struct bcm_kona_gpio *kona_gpio,
static int bcm_kona_gpio_get_dir(struct gpio_chip *chip, unsigned gpio) static int bcm_kona_gpio_get_dir(struct gpio_chip *chip, unsigned gpio)
{ {
struct bcm_kona_gpio *kona_gpio = to_kona_gpio(chip); struct bcm_kona_gpio *kona_gpio = gpiochip_get_data(chip);
void __iomem *reg_base = kona_gpio->reg_base; void __iomem *reg_base = kona_gpio->reg_base;
u32 val; u32 val;
...@@ -141,7 +136,7 @@ static void bcm_kona_gpio_set(struct gpio_chip *chip, unsigned gpio, int value) ...@@ -141,7 +136,7 @@ static void bcm_kona_gpio_set(struct gpio_chip *chip, unsigned gpio, int value)
u32 val, reg_offset; u32 val, reg_offset;
unsigned long flags; unsigned long flags;
kona_gpio = to_kona_gpio(chip); kona_gpio = gpiochip_get_data(chip);
reg_base = kona_gpio->reg_base; reg_base = kona_gpio->reg_base;
spin_lock_irqsave(&kona_gpio->lock, flags); spin_lock_irqsave(&kona_gpio->lock, flags);
...@@ -168,7 +163,7 @@ static int bcm_kona_gpio_get(struct gpio_chip *chip, unsigned gpio) ...@@ -168,7 +163,7 @@ static int bcm_kona_gpio_get(struct gpio_chip *chip, unsigned gpio)
u32 val, reg_offset; u32 val, reg_offset;
unsigned long flags; unsigned long flags;
kona_gpio = to_kona_gpio(chip); kona_gpio = gpiochip_get_data(chip);
reg_base = kona_gpio->reg_base; reg_base = kona_gpio->reg_base;
spin_lock_irqsave(&kona_gpio->lock, flags); spin_lock_irqsave(&kona_gpio->lock, flags);
...@@ -188,7 +183,7 @@ static int bcm_kona_gpio_get(struct gpio_chip *chip, unsigned gpio) ...@@ -188,7 +183,7 @@ static int bcm_kona_gpio_get(struct gpio_chip *chip, unsigned gpio)
static int bcm_kona_gpio_request(struct gpio_chip *chip, unsigned gpio) static int bcm_kona_gpio_request(struct gpio_chip *chip, unsigned gpio)
{ {
struct bcm_kona_gpio *kona_gpio = to_kona_gpio(chip); struct bcm_kona_gpio *kona_gpio = gpiochip_get_data(chip);
bcm_kona_gpio_unlock_gpio(kona_gpio, gpio); bcm_kona_gpio_unlock_gpio(kona_gpio, gpio);
return 0; return 0;
...@@ -196,7 +191,7 @@ static int bcm_kona_gpio_request(struct gpio_chip *chip, unsigned gpio) ...@@ -196,7 +191,7 @@ static int bcm_kona_gpio_request(struct gpio_chip *chip, unsigned gpio)
static void bcm_kona_gpio_free(struct gpio_chip *chip, unsigned gpio) static void bcm_kona_gpio_free(struct gpio_chip *chip, unsigned gpio)
{ {
struct bcm_kona_gpio *kona_gpio = to_kona_gpio(chip); struct bcm_kona_gpio *kona_gpio = gpiochip_get_data(chip);
bcm_kona_gpio_lock_gpio(kona_gpio, gpio); bcm_kona_gpio_lock_gpio(kona_gpio, gpio);
} }
...@@ -208,7 +203,7 @@ static int bcm_kona_gpio_direction_input(struct gpio_chip *chip, unsigned gpio) ...@@ -208,7 +203,7 @@ static int bcm_kona_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
u32 val; u32 val;
unsigned long flags; unsigned long flags;
kona_gpio = to_kona_gpio(chip); kona_gpio = gpiochip_get_data(chip);
reg_base = kona_gpio->reg_base; reg_base = kona_gpio->reg_base;
spin_lock_irqsave(&kona_gpio->lock, flags); spin_lock_irqsave(&kona_gpio->lock, flags);
...@@ -232,7 +227,7 @@ static int bcm_kona_gpio_direction_output(struct gpio_chip *chip, ...@@ -232,7 +227,7 @@ static int bcm_kona_gpio_direction_output(struct gpio_chip *chip,
u32 val, reg_offset; u32 val, reg_offset;
unsigned long flags; unsigned long flags;
kona_gpio = to_kona_gpio(chip); kona_gpio = gpiochip_get_data(chip);
reg_base = kona_gpio->reg_base; reg_base = kona_gpio->reg_base;
spin_lock_irqsave(&kona_gpio->lock, flags); spin_lock_irqsave(&kona_gpio->lock, flags);
...@@ -255,7 +250,7 @@ static int bcm_kona_gpio_to_irq(struct gpio_chip *chip, unsigned gpio) ...@@ -255,7 +250,7 @@ static int bcm_kona_gpio_to_irq(struct gpio_chip *chip, unsigned gpio)
{ {
struct bcm_kona_gpio *kona_gpio; struct bcm_kona_gpio *kona_gpio;
kona_gpio = to_kona_gpio(chip); kona_gpio = gpiochip_get_data(chip);
if (gpio >= kona_gpio->gpio_chip.ngpio) if (gpio >= kona_gpio->gpio_chip.ngpio)
return -ENXIO; return -ENXIO;
return irq_create_mapping(kona_gpio->irq_domain, gpio); return irq_create_mapping(kona_gpio->irq_domain, gpio);
...@@ -269,11 +264,11 @@ static int bcm_kona_gpio_set_debounce(struct gpio_chip *chip, unsigned gpio, ...@@ -269,11 +264,11 @@ static int bcm_kona_gpio_set_debounce(struct gpio_chip *chip, unsigned gpio,
u32 val, res; u32 val, res;
unsigned long flags; unsigned long flags;
kona_gpio = to_kona_gpio(chip); kona_gpio = gpiochip_get_data(chip);
reg_base = kona_gpio->reg_base; reg_base = kona_gpio->reg_base;
/* debounce must be 1-128ms (or 0) */ /* debounce must be 1-128ms (or 0) */
if ((debounce > 0 && debounce < 1000) || debounce > 128000) { if ((debounce > 0 && debounce < 1000) || debounce > 128000) {
dev_err(chip->dev, "Debounce value %u not in range\n", dev_err(chip->parent, "Debounce value %u not in range\n",
debounce); debounce);
return -EINVAL; return -EINVAL;
} }
...@@ -416,7 +411,7 @@ static int bcm_kona_gpio_irq_set_type(struct irq_data *d, unsigned int type) ...@@ -416,7 +411,7 @@ static int bcm_kona_gpio_irq_set_type(struct irq_data *d, unsigned int type)
case IRQ_TYPE_LEVEL_LOW: case IRQ_TYPE_LEVEL_LOW:
/* BCM GPIO doesn't support level triggering */ /* BCM GPIO doesn't support level triggering */
default: default:
dev_err(kona_gpio->gpio_chip.dev, dev_err(kona_gpio->gpio_chip.parent,
"Invalid BCM GPIO irq type 0x%x\n", type); "Invalid BCM GPIO irq type 0x%x\n", type);
return -EINVAL; return -EINVAL;
} }
...@@ -477,7 +472,7 @@ static int bcm_kona_gpio_irq_reqres(struct irq_data *d) ...@@ -477,7 +472,7 @@ static int bcm_kona_gpio_irq_reqres(struct irq_data *d)
struct bcm_kona_gpio *kona_gpio = irq_data_get_irq_chip_data(d); struct bcm_kona_gpio *kona_gpio = irq_data_get_irq_chip_data(d);
if (gpiochip_lock_as_irq(&kona_gpio->gpio_chip, d->hwirq)) { if (gpiochip_lock_as_irq(&kona_gpio->gpio_chip, d->hwirq)) {
dev_err(kona_gpio->gpio_chip.dev, dev_err(kona_gpio->gpio_chip.parent,
"unable to lock HW IRQ %lu for IRQ\n", "unable to lock HW IRQ %lu for IRQ\n",
d->hwirq); d->hwirq);
return -EINVAL; return -EINVAL;
...@@ -635,7 +630,7 @@ static int bcm_kona_gpio_probe(struct platform_device *pdev) ...@@ -635,7 +630,7 @@ static int bcm_kona_gpio_probe(struct platform_device *pdev)
bcm_kona_gpio_reset(kona_gpio); bcm_kona_gpio_reset(kona_gpio);
ret = gpiochip_add(chip); ret = gpiochip_add_data(chip, kona_gpio);
if (ret < 0) { if (ret < 0) {
dev_err(dev, "Couldn't add GPIO chip -- %d\n", ret); dev_err(dev, "Couldn't add GPIO chip -- %d\n", ret);
goto err_irq_domain; goto err_irq_domain;
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#include <linux/of_device.h> #include <linux/of_device.h>
#include <linux/of_irq.h> #include <linux/of_irq.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/basic_mmio_gpio.h>
#include <linux/irqdomain.h> #include <linux/irqdomain.h>
#include <linux/irqchip/chained_irq.h> #include <linux/irqchip/chained_irq.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
...@@ -35,7 +34,7 @@ ...@@ -35,7 +34,7 @@
struct brcmstb_gpio_bank { struct brcmstb_gpio_bank {
struct list_head node; struct list_head node;
int id; int id;
struct bgpio_chip bgc; struct gpio_chip gc;
struct brcmstb_gpio_priv *parent_priv; struct brcmstb_gpio_priv *parent_priv;
u32 width; u32 width;
struct irq_chip irq_chip; struct irq_chip irq_chip;
...@@ -57,37 +56,30 @@ struct brcmstb_gpio_priv { ...@@ -57,37 +56,30 @@ struct brcmstb_gpio_priv {
/* assumes MAX_GPIO_PER_BANK is a multiple of 2 */ /* assumes MAX_GPIO_PER_BANK is a multiple of 2 */
#define GPIO_BIT(gpio) ((gpio) & (MAX_GPIO_PER_BANK - 1)) #define GPIO_BIT(gpio) ((gpio) & (MAX_GPIO_PER_BANK - 1))
static inline struct brcmstb_gpio_bank *
brcmstb_gpio_gc_to_bank(struct gpio_chip *gc)
{
struct bgpio_chip *bgc = to_bgpio_chip(gc);
return container_of(bgc, struct brcmstb_gpio_bank, bgc);
}
static inline struct brcmstb_gpio_priv * static inline struct brcmstb_gpio_priv *
brcmstb_gpio_gc_to_priv(struct gpio_chip *gc) brcmstb_gpio_gc_to_priv(struct gpio_chip *gc)
{ {
struct brcmstb_gpio_bank *bank = brcmstb_gpio_gc_to_bank(gc); struct brcmstb_gpio_bank *bank = gpiochip_get_data(gc);
return bank->parent_priv; return bank->parent_priv;
} }
static void brcmstb_gpio_set_imask(struct brcmstb_gpio_bank *bank, static void brcmstb_gpio_set_imask(struct brcmstb_gpio_bank *bank,
unsigned int offset, bool enable) unsigned int offset, bool enable)
{ {
struct bgpio_chip *bgc = &bank->bgc; struct gpio_chip *gc = &bank->gc;
struct brcmstb_gpio_priv *priv = bank->parent_priv; struct brcmstb_gpio_priv *priv = bank->parent_priv;
u32 mask = bgc->pin2mask(bgc, offset); u32 mask = gc->pin2mask(gc, offset);
u32 imask; u32 imask;
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&bgc->lock, flags); spin_lock_irqsave(&gc->bgpio_lock, flags);
imask = bgc->read_reg(priv->reg_base + GIO_MASK(bank->id)); imask = gc->read_reg(priv->reg_base + GIO_MASK(bank->id));
if (enable) if (enable)
imask |= mask; imask |= mask;
else else
imask &= ~mask; imask &= ~mask;
bgc->write_reg(priv->reg_base + GIO_MASK(bank->id), imask); gc->write_reg(priv->reg_base + GIO_MASK(bank->id), imask);
spin_unlock_irqrestore(&bgc->lock, flags); spin_unlock_irqrestore(&gc->bgpio_lock, flags);
} }
/* -------------------- IRQ chip functions -------------------- */ /* -------------------- IRQ chip functions -------------------- */
...@@ -95,7 +87,7 @@ static void brcmstb_gpio_set_imask(struct brcmstb_gpio_bank *bank, ...@@ -95,7 +87,7 @@ static void brcmstb_gpio_set_imask(struct brcmstb_gpio_bank *bank,
static void brcmstb_gpio_irq_mask(struct irq_data *d) static void brcmstb_gpio_irq_mask(struct irq_data *d)
{ {
struct gpio_chip *gc = irq_data_get_irq_chip_data(d); struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
struct brcmstb_gpio_bank *bank = brcmstb_gpio_gc_to_bank(gc); struct brcmstb_gpio_bank *bank = gpiochip_get_data(gc);
brcmstb_gpio_set_imask(bank, d->hwirq, false); brcmstb_gpio_set_imask(bank, d->hwirq, false);
} }
...@@ -103,7 +95,7 @@ static void brcmstb_gpio_irq_mask(struct irq_data *d) ...@@ -103,7 +95,7 @@ static void brcmstb_gpio_irq_mask(struct irq_data *d)
static void brcmstb_gpio_irq_unmask(struct irq_data *d) static void brcmstb_gpio_irq_unmask(struct irq_data *d)
{ {
struct gpio_chip *gc = irq_data_get_irq_chip_data(d); struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
struct brcmstb_gpio_bank *bank = brcmstb_gpio_gc_to_bank(gc); struct brcmstb_gpio_bank *bank = gpiochip_get_data(gc);
brcmstb_gpio_set_imask(bank, d->hwirq, true); brcmstb_gpio_set_imask(bank, d->hwirq, true);
} }
...@@ -111,7 +103,7 @@ static void brcmstb_gpio_irq_unmask(struct irq_data *d) ...@@ -111,7 +103,7 @@ static void brcmstb_gpio_irq_unmask(struct irq_data *d)
static int brcmstb_gpio_irq_set_type(struct irq_data *d, unsigned int type) static int brcmstb_gpio_irq_set_type(struct irq_data *d, unsigned int type)
{ {
struct gpio_chip *gc = irq_data_get_irq_chip_data(d); struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
struct brcmstb_gpio_bank *bank = brcmstb_gpio_gc_to_bank(gc); struct brcmstb_gpio_bank *bank = gpiochip_get_data(gc);
struct brcmstb_gpio_priv *priv = bank->parent_priv; struct brcmstb_gpio_priv *priv = bank->parent_priv;
u32 mask = BIT(d->hwirq); u32 mask = BIT(d->hwirq);
u32 edge_insensitive, iedge_insensitive; u32 edge_insensitive, iedge_insensitive;
...@@ -149,23 +141,23 @@ static int brcmstb_gpio_irq_set_type(struct irq_data *d, unsigned int type) ...@@ -149,23 +141,23 @@ static int brcmstb_gpio_irq_set_type(struct irq_data *d, unsigned int type)
return -EINVAL; return -EINVAL;
} }
spin_lock_irqsave(&bank->bgc.lock, flags); spin_lock_irqsave(&bank->gc.bgpio_lock, flags);
iedge_config = bank->bgc.read_reg(priv->reg_base + iedge_config = bank->gc.read_reg(priv->reg_base +
GIO_EC(bank->id)) & ~mask; GIO_EC(bank->id)) & ~mask;
iedge_insensitive = bank->bgc.read_reg(priv->reg_base + iedge_insensitive = bank->gc.read_reg(priv->reg_base +
GIO_EI(bank->id)) & ~mask; GIO_EI(bank->id)) & ~mask;
ilevel = bank->bgc.read_reg(priv->reg_base + ilevel = bank->gc.read_reg(priv->reg_base +
GIO_LEVEL(bank->id)) & ~mask; GIO_LEVEL(bank->id)) & ~mask;
bank->bgc.write_reg(priv->reg_base + GIO_EC(bank->id), bank->gc.write_reg(priv->reg_base + GIO_EC(bank->id),
iedge_config | edge_config); iedge_config | edge_config);
bank->bgc.write_reg(priv->reg_base + GIO_EI(bank->id), bank->gc.write_reg(priv->reg_base + GIO_EI(bank->id),
iedge_insensitive | edge_insensitive); iedge_insensitive | edge_insensitive);
bank->bgc.write_reg(priv->reg_base + GIO_LEVEL(bank->id), bank->gc.write_reg(priv->reg_base + GIO_LEVEL(bank->id),
ilevel | level); ilevel | level);
spin_unlock_irqrestore(&bank->bgc.lock, flags); spin_unlock_irqrestore(&bank->gc.bgpio_lock, flags);
return 0; return 0;
} }
...@@ -210,29 +202,29 @@ static irqreturn_t brcmstb_gpio_wake_irq_handler(int irq, void *data) ...@@ -210,29 +202,29 @@ static irqreturn_t brcmstb_gpio_wake_irq_handler(int irq, void *data)
static void brcmstb_gpio_irq_bank_handler(struct brcmstb_gpio_bank *bank) static void brcmstb_gpio_irq_bank_handler(struct brcmstb_gpio_bank *bank)
{ {
struct brcmstb_gpio_priv *priv = bank->parent_priv; struct brcmstb_gpio_priv *priv = bank->parent_priv;
struct irq_domain *irq_domain = bank->bgc.gc.irqdomain; struct irq_domain *irq_domain = bank->gc.irqdomain;
void __iomem *reg_base = priv->reg_base; void __iomem *reg_base = priv->reg_base;
unsigned long status; unsigned long status;
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&bank->bgc.lock, flags); spin_lock_irqsave(&bank->gc.bgpio_lock, flags);
while ((status = bank->bgc.read_reg(reg_base + GIO_STAT(bank->id)) & while ((status = bank->gc.read_reg(reg_base + GIO_STAT(bank->id)) &
bank->bgc.read_reg(reg_base + GIO_MASK(bank->id)))) { bank->gc.read_reg(reg_base + GIO_MASK(bank->id)))) {
int bit; int bit;
for_each_set_bit(bit, &status, 32) { for_each_set_bit(bit, &status, 32) {
u32 stat = bank->bgc.read_reg(reg_base + u32 stat = bank->gc.read_reg(reg_base +
GIO_STAT(bank->id)); GIO_STAT(bank->id));
if (bit >= bank->width) if (bit >= bank->width)
dev_warn(&priv->pdev->dev, dev_warn(&priv->pdev->dev,
"IRQ for invalid GPIO (bank=%d, offset=%d)\n", "IRQ for invalid GPIO (bank=%d, offset=%d)\n",
bank->id, bit); bank->id, bit);
bank->bgc.write_reg(reg_base + GIO_STAT(bank->id), bank->gc.write_reg(reg_base + GIO_STAT(bank->id),
stat | BIT(bit)); stat | BIT(bit));
generic_handle_irq(irq_find_mapping(irq_domain, bit)); generic_handle_irq(irq_find_mapping(irq_domain, bit));
} }
} }
spin_unlock_irqrestore(&bank->bgc.lock, flags); spin_unlock_irqrestore(&bank->gc.bgpio_lock, flags);
} }
/* Each UPG GIO block has one IRQ for all banks */ /* Each UPG GIO block has one IRQ for all banks */
...@@ -303,9 +295,7 @@ static int brcmstb_gpio_remove(struct platform_device *pdev) ...@@ -303,9 +295,7 @@ static int brcmstb_gpio_remove(struct platform_device *pdev)
*/ */
list_for_each(pos, &priv->bank_list) { list_for_each(pos, &priv->bank_list) {
bank = list_entry(pos, struct brcmstb_gpio_bank, node); bank = list_entry(pos, struct brcmstb_gpio_bank, node);
ret = bgpio_remove(&bank->bgc); gpiochip_remove(&bank->gc);
if (ret)
dev_err(&pdev->dev, "gpiochip_remove fail in cleanup\n");
} }
if (priv->reboot_notifier.notifier_call) { if (priv->reboot_notifier.notifier_call) {
ret = unregister_reboot_notifier(&priv->reboot_notifier); ret = unregister_reboot_notifier(&priv->reboot_notifier);
...@@ -320,7 +310,7 @@ static int brcmstb_gpio_of_xlate(struct gpio_chip *gc, ...@@ -320,7 +310,7 @@ static int brcmstb_gpio_of_xlate(struct gpio_chip *gc,
const struct of_phandle_args *gpiospec, u32 *flags) const struct of_phandle_args *gpiospec, u32 *flags)
{ {
struct brcmstb_gpio_priv *priv = brcmstb_gpio_gc_to_priv(gc); struct brcmstb_gpio_priv *priv = brcmstb_gpio_gc_to_priv(gc);
struct brcmstb_gpio_bank *bank = brcmstb_gpio_gc_to_bank(gc); struct brcmstb_gpio_bank *bank = gpiochip_get_data(gc);
int offset; int offset;
if (gc->of_gpio_n_cells != 2) { if (gc->of_gpio_n_cells != 2) {
...@@ -398,9 +388,9 @@ static int brcmstb_gpio_irq_setup(struct platform_device *pdev, ...@@ -398,9 +388,9 @@ static int brcmstb_gpio_irq_setup(struct platform_device *pdev,
if (priv->can_wake) if (priv->can_wake)
bank->irq_chip.irq_set_wake = brcmstb_gpio_irq_set_wake; bank->irq_chip.irq_set_wake = brcmstb_gpio_irq_set_wake;
gpiochip_irqchip_add(&bank->bgc.gc, &bank->irq_chip, 0, gpiochip_irqchip_add(&bank->gc, &bank->irq_chip, 0,
handle_simple_irq, IRQ_TYPE_NONE); handle_simple_irq, IRQ_TYPE_NONE);
gpiochip_set_chained_irqchip(&bank->bgc.gc, &bank->irq_chip, gpiochip_set_chained_irqchip(&bank->gc, &bank->irq_chip,
priv->parent_irq, brcmstb_gpio_irq_handler); priv->parent_irq, brcmstb_gpio_irq_handler);
return 0; return 0;
...@@ -419,6 +409,7 @@ static int brcmstb_gpio_probe(struct platform_device *pdev) ...@@ -419,6 +409,7 @@ static int brcmstb_gpio_probe(struct platform_device *pdev)
int num_banks = 0; int num_banks = 0;
int err; int err;
static int gpio_base; static int gpio_base;
unsigned long flags = 0;
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
if (!priv) if (!priv)
...@@ -448,10 +439,21 @@ static int brcmstb_gpio_probe(struct platform_device *pdev) ...@@ -448,10 +439,21 @@ static int brcmstb_gpio_probe(struct platform_device *pdev)
if (brcmstb_gpio_sanity_check_banks(dev, np, res)) if (brcmstb_gpio_sanity_check_banks(dev, np, res))
return -EINVAL; return -EINVAL;
/*
* MIPS endianness is configured by boot strap, which also reverses all
* bus endianness (i.e., big-endian CPU + big endian bus ==> native
* endian I/O).
*
* Other architectures (e.g., ARM) either do not support big endian, or
* else leave I/O in little endian mode.
*/
#if defined(CONFIG_MIPS) && defined(__BIG_ENDIAN)
flags = BGPIOF_BIG_ENDIAN_BYTE_ORDER;
#endif
of_property_for_each_u32(np, "brcm,gpio-bank-widths", prop, p, of_property_for_each_u32(np, "brcm,gpio-bank-widths", prop, p,
bank_width) { bank_width) {
struct brcmstb_gpio_bank *bank; struct brcmstb_gpio_bank *bank;
struct bgpio_chip *bgc;
struct gpio_chip *gc; struct gpio_chip *gc;
bank = devm_kzalloc(dev, sizeof(*bank), GFP_KERNEL); bank = devm_kzalloc(dev, sizeof(*bank), GFP_KERNEL);
...@@ -473,17 +475,16 @@ static int brcmstb_gpio_probe(struct platform_device *pdev) ...@@ -473,17 +475,16 @@ static int brcmstb_gpio_probe(struct platform_device *pdev)
* Regs are 4 bytes wide, have data reg, no set/clear regs, * Regs are 4 bytes wide, have data reg, no set/clear regs,
* and direction bits have 0 = output and 1 = input * and direction bits have 0 = output and 1 = input
*/ */
bgc = &bank->bgc; gc = &bank->gc;
err = bgpio_init(bgc, dev, 4, err = bgpio_init(gc, dev, 4,
reg_base + GIO_DATA(bank->id), reg_base + GIO_DATA(bank->id),
NULL, NULL, NULL, NULL, NULL, NULL,
reg_base + GIO_IODIR(bank->id), 0); reg_base + GIO_IODIR(bank->id), flags);
if (err) { if (err) {
dev_err(dev, "bgpio_init() failed\n"); dev_err(dev, "bgpio_init() failed\n");
goto fail; goto fail;
} }
gc = &bgc->gc;
gc->of_node = np; gc->of_node = np;
gc->owner = THIS_MODULE; gc->owner = THIS_MODULE;
gc->label = np->full_name; gc->label = np->full_name;
...@@ -497,9 +498,9 @@ static int brcmstb_gpio_probe(struct platform_device *pdev) ...@@ -497,9 +498,9 @@ static int brcmstb_gpio_probe(struct platform_device *pdev)
* Mask all interrupts by default, since wakeup interrupts may * Mask all interrupts by default, since wakeup interrupts may
* be retained from S5 cold boot * be retained from S5 cold boot
*/ */
bank->bgc.write_reg(reg_base + GIO_MASK(bank->id), 0); gc->write_reg(reg_base + GIO_MASK(bank->id), 0);
err = gpiochip_add(gc); err = gpiochip_add_data(gc, bank);
if (err) { if (err) {
dev_err(dev, "Could not add gpiochip for bank %d\n", dev_err(dev, "Could not add gpiochip for bank %d\n",
bank->id); bank->id);
......
...@@ -80,7 +80,7 @@ MODULE_PARM_DESC(gpiobase, "The GPIO number base. -1 means dynamic, which is the ...@@ -80,7 +80,7 @@ MODULE_PARM_DESC(gpiobase, "The GPIO number base. -1 means dynamic, which is the
static int bt8xxgpio_gpio_direction_input(struct gpio_chip *gpio, unsigned nr) static int bt8xxgpio_gpio_direction_input(struct gpio_chip *gpio, unsigned nr)
{ {
struct bt8xxgpio *bg = container_of(gpio, struct bt8xxgpio, gpio); struct bt8xxgpio *bg = gpiochip_get_data(gpio);
unsigned long flags; unsigned long flags;
u32 outen, data; u32 outen, data;
...@@ -101,7 +101,7 @@ static int bt8xxgpio_gpio_direction_input(struct gpio_chip *gpio, unsigned nr) ...@@ -101,7 +101,7 @@ static int bt8xxgpio_gpio_direction_input(struct gpio_chip *gpio, unsigned nr)
static int bt8xxgpio_gpio_get(struct gpio_chip *gpio, unsigned nr) static int bt8xxgpio_gpio_get(struct gpio_chip *gpio, unsigned nr)
{ {
struct bt8xxgpio *bg = container_of(gpio, struct bt8xxgpio, gpio); struct bt8xxgpio *bg = gpiochip_get_data(gpio);
unsigned long flags; unsigned long flags;
u32 val; u32 val;
...@@ -115,7 +115,7 @@ static int bt8xxgpio_gpio_get(struct gpio_chip *gpio, unsigned nr) ...@@ -115,7 +115,7 @@ static int bt8xxgpio_gpio_get(struct gpio_chip *gpio, unsigned nr)
static int bt8xxgpio_gpio_direction_output(struct gpio_chip *gpio, static int bt8xxgpio_gpio_direction_output(struct gpio_chip *gpio,
unsigned nr, int val) unsigned nr, int val)
{ {
struct bt8xxgpio *bg = container_of(gpio, struct bt8xxgpio, gpio); struct bt8xxgpio *bg = gpiochip_get_data(gpio);
unsigned long flags; unsigned long flags;
u32 outen, data; u32 outen, data;
...@@ -140,7 +140,7 @@ static int bt8xxgpio_gpio_direction_output(struct gpio_chip *gpio, ...@@ -140,7 +140,7 @@ static int bt8xxgpio_gpio_direction_output(struct gpio_chip *gpio,
static void bt8xxgpio_gpio_set(struct gpio_chip *gpio, static void bt8xxgpio_gpio_set(struct gpio_chip *gpio,
unsigned nr, int val) unsigned nr, int val)
{ {
struct bt8xxgpio *bg = container_of(gpio, struct bt8xxgpio, gpio); struct bt8xxgpio *bg = gpiochip_get_data(gpio);
unsigned long flags; unsigned long flags;
u32 data; u32 data;
...@@ -217,7 +217,7 @@ static int bt8xxgpio_probe(struct pci_dev *dev, ...@@ -217,7 +217,7 @@ static int bt8xxgpio_probe(struct pci_dev *dev,
bgwrite(0, BT848_GPIO_OUT_EN); bgwrite(0, BT848_GPIO_OUT_EN);
bt8xxgpio_gpio_setup(bg); bt8xxgpio_gpio_setup(bg);
err = gpiochip_add(&bg->gpio); err = gpiochip_add_data(&bg->gpio, bg);
if (err) { if (err) {
printk(KERN_ERR "bt8xxgpio: Failed to register GPIOs\n"); printk(KERN_ERR "bt8xxgpio: Failed to register GPIOs\n");
goto err_disable; goto err_disable;
......
...@@ -10,24 +10,23 @@ ...@@ -10,24 +10,23 @@
*/ */
#include <linux/err.h> #include <linux/err.h>
#include <linux/gpio.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/basic_mmio_gpio.h> #include <linux/gpio/driver.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
static int clps711x_gpio_probe(struct platform_device *pdev) static int clps711x_gpio_probe(struct platform_device *pdev)
{ {
struct device_node *np = pdev->dev.of_node; struct device_node *np = pdev->dev.of_node;
void __iomem *dat, *dir; void __iomem *dat, *dir;
struct bgpio_chip *bgc; struct gpio_chip *gc;
struct resource *res; struct resource *res;
int err, id = np ? of_alias_get_id(np, "gpio") : pdev->id; int err, id = np ? of_alias_get_id(np, "gpio") : pdev->id;
if ((id < 0) || (id > 4)) if ((id < 0) || (id > 4))
return -ENODEV; return -ENODEV;
bgc = devm_kzalloc(&pdev->dev, sizeof(*bgc), GFP_KERNEL); gc = devm_kzalloc(&pdev->dev, sizeof(*gc), GFP_KERNEL);
if (!bgc) if (!gc)
return -ENOMEM; return -ENOMEM;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
...@@ -43,11 +42,11 @@ static int clps711x_gpio_probe(struct platform_device *pdev) ...@@ -43,11 +42,11 @@ static int clps711x_gpio_probe(struct platform_device *pdev)
switch (id) { switch (id) {
case 3: case 3:
/* PORTD is inverted logic for direction register */ /* PORTD is inverted logic for direction register */
err = bgpio_init(bgc, &pdev->dev, 1, dat, NULL, NULL, err = bgpio_init(gc, &pdev->dev, 1, dat, NULL, NULL,
NULL, dir, 0); NULL, dir, 0);
break; break;
default: default:
err = bgpio_init(bgc, &pdev->dev, 1, dat, NULL, NULL, err = bgpio_init(gc, &pdev->dev, 1, dat, NULL, NULL,
dir, NULL, 0); dir, NULL, 0);
break; break;
} }
...@@ -58,24 +57,25 @@ static int clps711x_gpio_probe(struct platform_device *pdev) ...@@ -58,24 +57,25 @@ static int clps711x_gpio_probe(struct platform_device *pdev)
switch (id) { switch (id) {
case 4: case 4:
/* PORTE is 3 lines only */ /* PORTE is 3 lines only */
bgc->gc.ngpio = 3; gc->ngpio = 3;
break; break;
default: default:
break; break;
} }
bgc->gc.base = id * 8; gc->base = id * 8;
bgc->gc.owner = THIS_MODULE; gc->owner = THIS_MODULE;
platform_set_drvdata(pdev, bgc); platform_set_drvdata(pdev, gc);
return gpiochip_add(&bgc->gc); return gpiochip_add_data(gc, NULL);
} }
static int clps711x_gpio_remove(struct platform_device *pdev) static int clps711x_gpio_remove(struct platform_device *pdev)
{ {
struct bgpio_chip *bgc = platform_get_drvdata(pdev); struct gpio_chip *gc = platform_get_drvdata(pdev);
return bgpio_remove(bgc); gpiochip_remove(gc);
return 0;
} }
static const struct of_device_id __maybe_unused clps711x_gpio_ids[] = { static const struct of_device_id __maybe_unused clps711x_gpio_ids[] = {
......
...@@ -86,11 +86,6 @@ struct crystalcove_gpio { ...@@ -86,11 +86,6 @@ struct crystalcove_gpio {
bool set_irq_mask; bool set_irq_mask;
}; };
static inline struct crystalcove_gpio *to_cg(struct gpio_chip *gc)
{
return container_of(gc, struct crystalcove_gpio, chip);
}
static inline int to_reg(int gpio, enum ctrl_register reg_type) static inline int to_reg(int gpio, enum ctrl_register reg_type)
{ {
int reg; int reg;
...@@ -134,7 +129,7 @@ static void crystalcove_update_irq_ctrl(struct crystalcove_gpio *cg, int gpio) ...@@ -134,7 +129,7 @@ static void crystalcove_update_irq_ctrl(struct crystalcove_gpio *cg, int gpio)
static int crystalcove_gpio_dir_in(struct gpio_chip *chip, unsigned gpio) static int crystalcove_gpio_dir_in(struct gpio_chip *chip, unsigned gpio)
{ {
struct crystalcove_gpio *cg = to_cg(chip); struct crystalcove_gpio *cg = gpiochip_get_data(chip);
if (gpio > CRYSTALCOVE_VGPIO_NUM) if (gpio > CRYSTALCOVE_VGPIO_NUM)
return 0; return 0;
...@@ -146,7 +141,7 @@ static int crystalcove_gpio_dir_in(struct gpio_chip *chip, unsigned gpio) ...@@ -146,7 +141,7 @@ static int crystalcove_gpio_dir_in(struct gpio_chip *chip, unsigned gpio)
static int crystalcove_gpio_dir_out(struct gpio_chip *chip, unsigned gpio, static int crystalcove_gpio_dir_out(struct gpio_chip *chip, unsigned gpio,
int value) int value)
{ {
struct crystalcove_gpio *cg = to_cg(chip); struct crystalcove_gpio *cg = gpiochip_get_data(chip);
if (gpio > CRYSTALCOVE_VGPIO_NUM) if (gpio > CRYSTALCOVE_VGPIO_NUM)
return 0; return 0;
...@@ -157,7 +152,7 @@ static int crystalcove_gpio_dir_out(struct gpio_chip *chip, unsigned gpio, ...@@ -157,7 +152,7 @@ static int crystalcove_gpio_dir_out(struct gpio_chip *chip, unsigned gpio,
static int crystalcove_gpio_get(struct gpio_chip *chip, unsigned gpio) static int crystalcove_gpio_get(struct gpio_chip *chip, unsigned gpio)
{ {
struct crystalcove_gpio *cg = to_cg(chip); struct crystalcove_gpio *cg = gpiochip_get_data(chip);
int ret; int ret;
unsigned int val; unsigned int val;
...@@ -174,7 +169,7 @@ static int crystalcove_gpio_get(struct gpio_chip *chip, unsigned gpio) ...@@ -174,7 +169,7 @@ static int crystalcove_gpio_get(struct gpio_chip *chip, unsigned gpio)
static void crystalcove_gpio_set(struct gpio_chip *chip, static void crystalcove_gpio_set(struct gpio_chip *chip,
unsigned gpio, int value) unsigned gpio, int value)
{ {
struct crystalcove_gpio *cg = to_cg(chip); struct crystalcove_gpio *cg = gpiochip_get_data(chip);
if (gpio > CRYSTALCOVE_VGPIO_NUM) if (gpio > CRYSTALCOVE_VGPIO_NUM)
return; return;
...@@ -187,7 +182,8 @@ static void crystalcove_gpio_set(struct gpio_chip *chip, ...@@ -187,7 +182,8 @@ static void crystalcove_gpio_set(struct gpio_chip *chip,
static int crystalcove_irq_type(struct irq_data *data, unsigned type) static int crystalcove_irq_type(struct irq_data *data, unsigned type)
{ {
struct crystalcove_gpio *cg = to_cg(irq_data_get_irq_chip_data(data)); struct crystalcove_gpio *cg =
gpiochip_get_data(irq_data_get_irq_chip_data(data));
switch (type) { switch (type) {
case IRQ_TYPE_NONE: case IRQ_TYPE_NONE:
...@@ -213,14 +209,16 @@ static int crystalcove_irq_type(struct irq_data *data, unsigned type) ...@@ -213,14 +209,16 @@ static int crystalcove_irq_type(struct irq_data *data, unsigned type)
static void crystalcove_bus_lock(struct irq_data *data) static void crystalcove_bus_lock(struct irq_data *data)
{ {
struct crystalcove_gpio *cg = to_cg(irq_data_get_irq_chip_data(data)); struct crystalcove_gpio *cg =
gpiochip_get_data(irq_data_get_irq_chip_data(data));
mutex_lock(&cg->buslock); mutex_lock(&cg->buslock);
} }
static void crystalcove_bus_sync_unlock(struct irq_data *data) static void crystalcove_bus_sync_unlock(struct irq_data *data)
{ {
struct crystalcove_gpio *cg = to_cg(irq_data_get_irq_chip_data(data)); struct crystalcove_gpio *cg =
gpiochip_get_data(irq_data_get_irq_chip_data(data));
int gpio = data->hwirq; int gpio = data->hwirq;
if (cg->update & UPDATE_IRQ_TYPE) if (cg->update & UPDATE_IRQ_TYPE)
...@@ -234,7 +232,8 @@ static void crystalcove_bus_sync_unlock(struct irq_data *data) ...@@ -234,7 +232,8 @@ static void crystalcove_bus_sync_unlock(struct irq_data *data)
static void crystalcove_irq_unmask(struct irq_data *data) static void crystalcove_irq_unmask(struct irq_data *data)
{ {
struct crystalcove_gpio *cg = to_cg(irq_data_get_irq_chip_data(data)); struct crystalcove_gpio *cg =
gpiochip_get_data(irq_data_get_irq_chip_data(data));
cg->set_irq_mask = false; cg->set_irq_mask = false;
cg->update |= UPDATE_IRQ_MASK; cg->update |= UPDATE_IRQ_MASK;
...@@ -242,7 +241,8 @@ static void crystalcove_irq_unmask(struct irq_data *data) ...@@ -242,7 +241,8 @@ static void crystalcove_irq_unmask(struct irq_data *data)
static void crystalcove_irq_mask(struct irq_data *data) static void crystalcove_irq_mask(struct irq_data *data)
{ {
struct crystalcove_gpio *cg = to_cg(irq_data_get_irq_chip_data(data)); struct crystalcove_gpio *cg =
gpiochip_get_data(irq_data_get_irq_chip_data(data));
cg->set_irq_mask = true; cg->set_irq_mask = true;
cg->update |= UPDATE_IRQ_MASK; cg->update |= UPDATE_IRQ_MASK;
...@@ -288,7 +288,7 @@ static irqreturn_t crystalcove_gpio_irq_handler(int irq, void *data) ...@@ -288,7 +288,7 @@ static irqreturn_t crystalcove_gpio_irq_handler(int irq, void *data)
static void crystalcove_gpio_dbg_show(struct seq_file *s, static void crystalcove_gpio_dbg_show(struct seq_file *s,
struct gpio_chip *chip) struct gpio_chip *chip)
{ {
struct crystalcove_gpio *cg = to_cg(chip); struct crystalcove_gpio *cg = gpiochip_get_data(chip);
int gpio, offset; int gpio, offset;
unsigned int ctlo, ctli, mirqs0, mirqsx, irq; unsigned int ctlo, ctli, mirqs0, mirqsx, irq;
...@@ -341,11 +341,11 @@ static int crystalcove_gpio_probe(struct platform_device *pdev) ...@@ -341,11 +341,11 @@ static int crystalcove_gpio_probe(struct platform_device *pdev)
cg->chip.base = -1; cg->chip.base = -1;
cg->chip.ngpio = CRYSTALCOVE_VGPIO_NUM; cg->chip.ngpio = CRYSTALCOVE_VGPIO_NUM;
cg->chip.can_sleep = true; cg->chip.can_sleep = true;
cg->chip.dev = dev; cg->chip.parent = dev;
cg->chip.dbg_show = crystalcove_gpio_dbg_show; cg->chip.dbg_show = crystalcove_gpio_dbg_show;
cg->regmap = pmic->regmap; cg->regmap = pmic->regmap;
retval = gpiochip_add(&cg->chip); retval = gpiochip_add_data(&cg->chip, cg);
if (retval) { if (retval) {
dev_warn(&pdev->dev, "add gpio chip error: %d\n", retval); dev_warn(&pdev->dev, "add gpio chip error: %d\n", retval);
return retval; return retval;
......
...@@ -42,6 +42,10 @@ static ulong mask = GPIO_DEFAULT_MASK; ...@@ -42,6 +42,10 @@ static ulong mask = GPIO_DEFAULT_MASK;
module_param_named(mask, mask, ulong, 0444); module_param_named(mask, mask, ulong, 0444);
MODULE_PARM_DESC(mask, "GPIO channel mask."); MODULE_PARM_DESC(mask, "GPIO channel mask.");
/*
* FIXME: convert this singleton driver to use the state container
* design pattern, see Documentation/driver-model/design-patterns.txt
*/
static struct cs5535_gpio_chip { static struct cs5535_gpio_chip {
struct gpio_chip chip; struct gpio_chip chip;
resource_size_t base; resource_size_t base;
...@@ -201,8 +205,7 @@ EXPORT_SYMBOL_GPL(cs5535_gpio_setup_event); ...@@ -201,8 +205,7 @@ EXPORT_SYMBOL_GPL(cs5535_gpio_setup_event);
static int chip_gpio_request(struct gpio_chip *c, unsigned offset) static int chip_gpio_request(struct gpio_chip *c, unsigned offset)
{ {
struct cs5535_gpio_chip *chip = struct cs5535_gpio_chip *chip = gpiochip_get_data(c);
container_of(c, struct cs5535_gpio_chip, chip);
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&chip->lock, flags); spin_lock_irqsave(&chip->lock, flags);
...@@ -242,8 +245,7 @@ static void chip_gpio_set(struct gpio_chip *chip, unsigned offset, int val) ...@@ -242,8 +245,7 @@ static void chip_gpio_set(struct gpio_chip *chip, unsigned offset, int val)
static int chip_direction_input(struct gpio_chip *c, unsigned offset) static int chip_direction_input(struct gpio_chip *c, unsigned offset)
{ {
struct cs5535_gpio_chip *chip = struct cs5535_gpio_chip *chip = gpiochip_get_data(c);
container_of(c, struct cs5535_gpio_chip, chip);
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&chip->lock, flags); spin_lock_irqsave(&chip->lock, flags);
...@@ -256,8 +258,7 @@ static int chip_direction_input(struct gpio_chip *c, unsigned offset) ...@@ -256,8 +258,7 @@ static int chip_direction_input(struct gpio_chip *c, unsigned offset)
static int chip_direction_output(struct gpio_chip *c, unsigned offset, int val) static int chip_direction_output(struct gpio_chip *c, unsigned offset, int val)
{ {
struct cs5535_gpio_chip *chip = struct cs5535_gpio_chip *chip = gpiochip_get_data(c);
container_of(c, struct cs5535_gpio_chip, chip);
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&chip->lock, flags); spin_lock_irqsave(&chip->lock, flags);
...@@ -347,7 +348,7 @@ static int cs5535_gpio_probe(struct platform_device *pdev) ...@@ -347,7 +348,7 @@ static int cs5535_gpio_probe(struct platform_device *pdev)
mask_orig, mask); mask_orig, mask);
/* finally, register with the generic GPIO API */ /* finally, register with the generic GPIO API */
err = gpiochip_add(&cs5535_gpio_chip.chip); err = gpiochip_add_data(&cs5535_gpio_chip.chip, &cs5535_gpio_chip);
if (err) if (err)
goto done; goto done;
......
...@@ -51,11 +51,6 @@ struct da9052_gpio { ...@@ -51,11 +51,6 @@ struct da9052_gpio {
struct gpio_chip gp; struct gpio_chip gp;
}; };
static inline struct da9052_gpio *to_da9052_gpio(struct gpio_chip *chip)
{
return container_of(chip, struct da9052_gpio, gp);
}
static unsigned char da9052_gpio_port_odd(unsigned offset) static unsigned char da9052_gpio_port_odd(unsigned offset)
{ {
return offset % 2; return offset % 2;
...@@ -63,7 +58,7 @@ static unsigned char da9052_gpio_port_odd(unsigned offset) ...@@ -63,7 +58,7 @@ static unsigned char da9052_gpio_port_odd(unsigned offset)
static int da9052_gpio_get(struct gpio_chip *gc, unsigned offset) static int da9052_gpio_get(struct gpio_chip *gc, unsigned offset)
{ {
struct da9052_gpio *gpio = to_da9052_gpio(gc); struct da9052_gpio *gpio = gpiochip_get_data(gc);
int da9052_port_direction = 0; int da9052_port_direction = 0;
int ret; int ret;
...@@ -89,15 +84,12 @@ static int da9052_gpio_get(struct gpio_chip *gc, unsigned offset) ...@@ -89,15 +84,12 @@ static int da9052_gpio_get(struct gpio_chip *gc, unsigned offset)
DA9052_STATUS_D_REG); DA9052_STATUS_D_REG);
if (ret < 0) if (ret < 0)
return ret; return ret;
if (ret & (1 << DA9052_GPIO_SHIFT_COUNT(offset))) return !!(ret & (1 << DA9052_GPIO_SHIFT_COUNT(offset)));
return 1;
else
return 0;
case DA9052_OUTPUT_PUSHPULL: case DA9052_OUTPUT_PUSHPULL:
if (da9052_gpio_port_odd(offset)) if (da9052_gpio_port_odd(offset))
return ret & DA9052_GPIO_ODD_PORT_MODE; return !!(ret & DA9052_GPIO_ODD_PORT_MODE);
else else
return ret & DA9052_GPIO_EVEN_PORT_MODE; return !!(ret & DA9052_GPIO_EVEN_PORT_MODE);
default: default:
return -EINVAL; return -EINVAL;
} }
...@@ -105,7 +97,7 @@ static int da9052_gpio_get(struct gpio_chip *gc, unsigned offset) ...@@ -105,7 +97,7 @@ static int da9052_gpio_get(struct gpio_chip *gc, unsigned offset)
static void da9052_gpio_set(struct gpio_chip *gc, unsigned offset, int value) static void da9052_gpio_set(struct gpio_chip *gc, unsigned offset, int value)
{ {
struct da9052_gpio *gpio = to_da9052_gpio(gc); struct da9052_gpio *gpio = gpiochip_get_data(gc);
int ret; int ret;
if (da9052_gpio_port_odd(offset)) { if (da9052_gpio_port_odd(offset)) {
...@@ -131,7 +123,7 @@ static void da9052_gpio_set(struct gpio_chip *gc, unsigned offset, int value) ...@@ -131,7 +123,7 @@ static void da9052_gpio_set(struct gpio_chip *gc, unsigned offset, int value)
static int da9052_gpio_direction_input(struct gpio_chip *gc, unsigned offset) static int da9052_gpio_direction_input(struct gpio_chip *gc, unsigned offset)
{ {
struct da9052_gpio *gpio = to_da9052_gpio(gc); struct da9052_gpio *gpio = gpiochip_get_data(gc);
unsigned char register_value; unsigned char register_value;
int ret; int ret;
...@@ -157,7 +149,7 @@ static int da9052_gpio_direction_input(struct gpio_chip *gc, unsigned offset) ...@@ -157,7 +149,7 @@ static int da9052_gpio_direction_input(struct gpio_chip *gc, unsigned offset)
static int da9052_gpio_direction_output(struct gpio_chip *gc, static int da9052_gpio_direction_output(struct gpio_chip *gc,
unsigned offset, int value) unsigned offset, int value)
{ {
struct da9052_gpio *gpio = to_da9052_gpio(gc); struct da9052_gpio *gpio = gpiochip_get_data(gc);
unsigned char register_value; unsigned char register_value;
int ret; int ret;
...@@ -182,7 +174,7 @@ static int da9052_gpio_direction_output(struct gpio_chip *gc, ...@@ -182,7 +174,7 @@ static int da9052_gpio_direction_output(struct gpio_chip *gc,
static int da9052_gpio_to_irq(struct gpio_chip *gc, u32 offset) static int da9052_gpio_to_irq(struct gpio_chip *gc, u32 offset)
{ {
struct da9052_gpio *gpio = to_da9052_gpio(gc); struct da9052_gpio *gpio = gpiochip_get_data(gc);
struct da9052 *da9052 = gpio->da9052; struct da9052 *da9052 = gpio->da9052;
int irq; int irq;
...@@ -222,7 +214,7 @@ static int da9052_gpio_probe(struct platform_device *pdev) ...@@ -222,7 +214,7 @@ static int da9052_gpio_probe(struct platform_device *pdev)
if (pdata && pdata->gpio_base) if (pdata && pdata->gpio_base)
gpio->gp.base = pdata->gpio_base; gpio->gp.base = pdata->gpio_base;
ret = gpiochip_add(&gpio->gp); ret = gpiochip_add_data(&gpio->gp, gpio);
if (ret < 0) { if (ret < 0) {
dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret); dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret);
return ret; return ret;
......
...@@ -35,14 +35,9 @@ struct da9055_gpio { ...@@ -35,14 +35,9 @@ struct da9055_gpio {
struct gpio_chip gp; struct gpio_chip gp;
}; };
static inline struct da9055_gpio *to_da9055_gpio(struct gpio_chip *chip)
{
return container_of(chip, struct da9055_gpio, gp);
}
static int da9055_gpio_get(struct gpio_chip *gc, unsigned offset) static int da9055_gpio_get(struct gpio_chip *gc, unsigned offset)
{ {
struct da9055_gpio *gpio = to_da9055_gpio(gc); struct da9055_gpio *gpio = gpiochip_get_data(gc);
int gpio_direction = 0; int gpio_direction = 0;
int ret; int ret;
...@@ -71,7 +66,7 @@ static int da9055_gpio_get(struct gpio_chip *gc, unsigned offset) ...@@ -71,7 +66,7 @@ static int da9055_gpio_get(struct gpio_chip *gc, unsigned offset)
static void da9055_gpio_set(struct gpio_chip *gc, unsigned offset, int value) static void da9055_gpio_set(struct gpio_chip *gc, unsigned offset, int value)
{ {
struct da9055_gpio *gpio = to_da9055_gpio(gc); struct da9055_gpio *gpio = gpiochip_get_data(gc);
da9055_reg_update(gpio->da9055, da9055_reg_update(gpio->da9055,
DA9055_REG_GPIO_MODE0_2, DA9055_REG_GPIO_MODE0_2,
...@@ -81,7 +76,7 @@ static void da9055_gpio_set(struct gpio_chip *gc, unsigned offset, int value) ...@@ -81,7 +76,7 @@ static void da9055_gpio_set(struct gpio_chip *gc, unsigned offset, int value)
static int da9055_gpio_direction_input(struct gpio_chip *gc, unsigned offset) static int da9055_gpio_direction_input(struct gpio_chip *gc, unsigned offset)
{ {
struct da9055_gpio *gpio = to_da9055_gpio(gc); struct da9055_gpio *gpio = gpiochip_get_data(gc);
unsigned char reg_byte; unsigned char reg_byte;
reg_byte = (DA9055_ACT_LOW | DA9055_GPI) reg_byte = (DA9055_ACT_LOW | DA9055_GPI)
...@@ -97,7 +92,7 @@ static int da9055_gpio_direction_input(struct gpio_chip *gc, unsigned offset) ...@@ -97,7 +92,7 @@ static int da9055_gpio_direction_input(struct gpio_chip *gc, unsigned offset)
static int da9055_gpio_direction_output(struct gpio_chip *gc, static int da9055_gpio_direction_output(struct gpio_chip *gc,
unsigned offset, int value) unsigned offset, int value)
{ {
struct da9055_gpio *gpio = to_da9055_gpio(gc); struct da9055_gpio *gpio = gpiochip_get_data(gc);
unsigned char reg_byte; unsigned char reg_byte;
int ret; int ret;
...@@ -119,7 +114,7 @@ static int da9055_gpio_direction_output(struct gpio_chip *gc, ...@@ -119,7 +114,7 @@ static int da9055_gpio_direction_output(struct gpio_chip *gc,
static int da9055_gpio_to_irq(struct gpio_chip *gc, u32 offset) static int da9055_gpio_to_irq(struct gpio_chip *gc, u32 offset)
{ {
struct da9055_gpio *gpio = to_da9055_gpio(gc); struct da9055_gpio *gpio = gpiochip_get_data(gc);
struct da9055 *da9055 = gpio->da9055; struct da9055 *da9055 = gpio->da9055;
return regmap_irq_get_virq(da9055->irq_data, return regmap_irq_get_virq(da9055->irq_data,
...@@ -156,7 +151,7 @@ static int da9055_gpio_probe(struct platform_device *pdev) ...@@ -156,7 +151,7 @@ static int da9055_gpio_probe(struct platform_device *pdev)
if (pdata && pdata->gpio_base) if (pdata && pdata->gpio_base)
gpio->gp.base = pdata->gpio_base; gpio->gp.base = pdata->gpio_base;
ret = gpiochip_add(&gpio->gp); ret = gpiochip_add_data(&gpio->gp, gpio);
if (ret < 0) { if (ret < 0) {
dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret); dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret);
goto err_mem; goto err_mem;
......
...@@ -41,9 +41,6 @@ typedef struct irq_chip *(*gpio_get_irq_chip_cb_t)(unsigned int irq); ...@@ -41,9 +41,6 @@ typedef struct irq_chip *(*gpio_get_irq_chip_cb_t)(unsigned int irq);
#define BINTEN 0x8 /* GPIO Interrupt Per-Bank Enable Register */ #define BINTEN 0x8 /* GPIO Interrupt Per-Bank Enable Register */
#define chip2controller(chip) \
container_of(chip, struct davinci_gpio_controller, chip)
static void __iomem *gpio_base; static void __iomem *gpio_base;
static struct davinci_gpio_regs __iomem *gpio2regs(unsigned gpio) static struct davinci_gpio_regs __iomem *gpio2regs(unsigned gpio)
...@@ -82,7 +79,7 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev); ...@@ -82,7 +79,7 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev);
static inline int __davinci_direction(struct gpio_chip *chip, static inline int __davinci_direction(struct gpio_chip *chip,
unsigned offset, bool out, int value) unsigned offset, bool out, int value)
{ {
struct davinci_gpio_controller *d = chip2controller(chip); struct davinci_gpio_controller *d = gpiochip_get_data(chip);
struct davinci_gpio_regs __iomem *g = d->regs; struct davinci_gpio_regs __iomem *g = d->regs;
unsigned long flags; unsigned long flags;
u32 temp; u32 temp;
...@@ -122,10 +119,10 @@ davinci_direction_out(struct gpio_chip *chip, unsigned offset, int value) ...@@ -122,10 +119,10 @@ davinci_direction_out(struct gpio_chip *chip, unsigned offset, int value)
*/ */
static int davinci_gpio_get(struct gpio_chip *chip, unsigned offset) static int davinci_gpio_get(struct gpio_chip *chip, unsigned offset)
{ {
struct davinci_gpio_controller *d = chip2controller(chip); struct davinci_gpio_controller *d = gpiochip_get_data(chip);
struct davinci_gpio_regs __iomem *g = d->regs; struct davinci_gpio_regs __iomem *g = d->regs;
return (1 << offset) & readl_relaxed(&g->in_data); return !!((1 << offset) & readl_relaxed(&g->in_data));
} }
/* /*
...@@ -134,7 +131,7 @@ static int davinci_gpio_get(struct gpio_chip *chip, unsigned offset) ...@@ -134,7 +131,7 @@ static int davinci_gpio_get(struct gpio_chip *chip, unsigned offset)
static void static void
davinci_gpio_set(struct gpio_chip *chip, unsigned offset, int value) davinci_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
{ {
struct davinci_gpio_controller *d = chip2controller(chip); struct davinci_gpio_controller *d = gpiochip_get_data(chip);
struct davinci_gpio_regs __iomem *g = d->regs; struct davinci_gpio_regs __iomem *g = d->regs;
writel_relaxed((1 << offset), value ? &g->set_data : &g->clr_data); writel_relaxed((1 << offset), value ? &g->set_data : &g->clr_data);
...@@ -149,7 +146,7 @@ davinci_gpio_get_pdata(struct platform_device *pdev) ...@@ -149,7 +146,7 @@ davinci_gpio_get_pdata(struct platform_device *pdev)
u32 val; u32 val;
if (!IS_ENABLED(CONFIG_OF) || !pdev->dev.of_node) if (!IS_ENABLED(CONFIG_OF) || !pdev->dev.of_node)
return pdev->dev.platform_data; return dev_get_platdata(&pdev->dev);
pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
if (!pdata) if (!pdata)
...@@ -179,8 +176,8 @@ static int davinci_gpio_of_xlate(struct gpio_chip *gc, ...@@ -179,8 +176,8 @@ static int davinci_gpio_of_xlate(struct gpio_chip *gc,
const struct of_phandle_args *gpiospec, const struct of_phandle_args *gpiospec,
u32 *flags) u32 *flags)
{ {
struct davinci_gpio_controller *chips = dev_get_drvdata(gc->dev); struct davinci_gpio_controller *chips = dev_get_drvdata(gc->parent);
struct davinci_gpio_platform_data *pdata = dev_get_platdata(gc->dev); struct davinci_gpio_platform_data *pdata = dev_get_platdata(gc->parent);
if (gpiospec->args[0] > pdata->ngpio) if (gpiospec->args[0] > pdata->ngpio)
return -EINVAL; return -EINVAL;
...@@ -254,7 +251,7 @@ static int davinci_gpio_probe(struct platform_device *pdev) ...@@ -254,7 +251,7 @@ static int davinci_gpio_probe(struct platform_device *pdev)
#ifdef CONFIG_OF_GPIO #ifdef CONFIG_OF_GPIO
chips[i].chip.of_gpio_n_cells = 2; chips[i].chip.of_gpio_n_cells = 2;
chips[i].chip.of_xlate = davinci_gpio_of_xlate; chips[i].chip.of_xlate = davinci_gpio_of_xlate;
chips[i].chip.dev = dev; chips[i].chip.parent = dev;
chips[i].chip.of_node = dev->of_node; chips[i].chip.of_node = dev->of_node;
#endif #endif
spin_lock_init(&chips[i].lock); spin_lock_init(&chips[i].lock);
...@@ -265,7 +262,7 @@ static int davinci_gpio_probe(struct platform_device *pdev) ...@@ -265,7 +262,7 @@ static int davinci_gpio_probe(struct platform_device *pdev)
chips[i].clr_data = &regs->clr_data; chips[i].clr_data = &regs->clr_data;
chips[i].in_data = &regs->in_data; chips[i].in_data = &regs->in_data;
gpiochip_add(&chips[i].chip); gpiochip_add_data(&chips[i].chip, &chips[i]);
} }
platform_set_drvdata(pdev, chips); platform_set_drvdata(pdev, chips);
...@@ -368,7 +365,7 @@ static void gpio_irq_handler(struct irq_desc *desc) ...@@ -368,7 +365,7 @@ static void gpio_irq_handler(struct irq_desc *desc)
static int gpio_to_irq_banked(struct gpio_chip *chip, unsigned offset) static int gpio_to_irq_banked(struct gpio_chip *chip, unsigned offset)
{ {
struct davinci_gpio_controller *d = chip2controller(chip); struct davinci_gpio_controller *d = gpiochip_get_data(chip);
if (d->irq_domain) if (d->irq_domain)
return irq_create_mapping(d->irq_domain, d->chip.base + offset); return irq_create_mapping(d->irq_domain, d->chip.base + offset);
...@@ -378,7 +375,7 @@ static int gpio_to_irq_banked(struct gpio_chip *chip, unsigned offset) ...@@ -378,7 +375,7 @@ static int gpio_to_irq_banked(struct gpio_chip *chip, unsigned offset)
static int gpio_to_irq_unbanked(struct gpio_chip *chip, unsigned offset) static int gpio_to_irq_unbanked(struct gpio_chip *chip, unsigned offset)
{ {
struct davinci_gpio_controller *d = chip2controller(chip); struct davinci_gpio_controller *d = gpiochip_get_data(chip);
/* /*
* NOTE: we assume for now that only irqs in the first gpio_chip * NOTE: we assume for now that only irqs in the first gpio_chip
......
...@@ -153,7 +153,7 @@ static int dln2_gpio_pin_set_out_val(struct dln2_gpio *dln2, ...@@ -153,7 +153,7 @@ static int dln2_gpio_pin_set_out_val(struct dln2_gpio *dln2,
static int dln2_gpio_request(struct gpio_chip *chip, unsigned offset) static int dln2_gpio_request(struct gpio_chip *chip, unsigned offset)
{ {
struct dln2_gpio *dln2 = container_of(chip, struct dln2_gpio, gpio); struct dln2_gpio *dln2 = gpiochip_get_data(chip);
struct dln2_gpio_pin req = { struct dln2_gpio_pin req = {
.pin = cpu_to_le16(offset), .pin = cpu_to_le16(offset),
}; };
...@@ -194,14 +194,14 @@ static int dln2_gpio_request(struct gpio_chip *chip, unsigned offset) ...@@ -194,14 +194,14 @@ static int dln2_gpio_request(struct gpio_chip *chip, unsigned offset)
static void dln2_gpio_free(struct gpio_chip *chip, unsigned offset) static void dln2_gpio_free(struct gpio_chip *chip, unsigned offset)
{ {
struct dln2_gpio *dln2 = container_of(chip, struct dln2_gpio, gpio); struct dln2_gpio *dln2 = gpiochip_get_data(chip);
dln2_gpio_pin_cmd(dln2, DLN2_GPIO_PIN_DISABLE, offset); dln2_gpio_pin_cmd(dln2, DLN2_GPIO_PIN_DISABLE, offset);
} }
static int dln2_gpio_get_direction(struct gpio_chip *chip, unsigned offset) static int dln2_gpio_get_direction(struct gpio_chip *chip, unsigned offset)
{ {
struct dln2_gpio *dln2 = container_of(chip, struct dln2_gpio, gpio); struct dln2_gpio *dln2 = gpiochip_get_data(chip);
if (test_bit(offset, dln2->output_enabled)) if (test_bit(offset, dln2->output_enabled))
return GPIOF_DIR_OUT; return GPIOF_DIR_OUT;
...@@ -211,7 +211,7 @@ static int dln2_gpio_get_direction(struct gpio_chip *chip, unsigned offset) ...@@ -211,7 +211,7 @@ static int dln2_gpio_get_direction(struct gpio_chip *chip, unsigned offset)
static int dln2_gpio_get(struct gpio_chip *chip, unsigned int offset) static int dln2_gpio_get(struct gpio_chip *chip, unsigned int offset)
{ {
struct dln2_gpio *dln2 = container_of(chip, struct dln2_gpio, gpio); struct dln2_gpio *dln2 = gpiochip_get_data(chip);
int dir; int dir;
dir = dln2_gpio_get_direction(chip, offset); dir = dln2_gpio_get_direction(chip, offset);
...@@ -226,7 +226,7 @@ static int dln2_gpio_get(struct gpio_chip *chip, unsigned int offset) ...@@ -226,7 +226,7 @@ static int dln2_gpio_get(struct gpio_chip *chip, unsigned int offset)
static void dln2_gpio_set(struct gpio_chip *chip, unsigned offset, int value) static void dln2_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
{ {
struct dln2_gpio *dln2 = container_of(chip, struct dln2_gpio, gpio); struct dln2_gpio *dln2 = gpiochip_get_data(chip);
dln2_gpio_pin_set_out_val(dln2, offset, value); dln2_gpio_pin_set_out_val(dln2, offset, value);
} }
...@@ -234,7 +234,7 @@ static void dln2_gpio_set(struct gpio_chip *chip, unsigned offset, int value) ...@@ -234,7 +234,7 @@ static void dln2_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
static int dln2_gpio_set_direction(struct gpio_chip *chip, unsigned offset, static int dln2_gpio_set_direction(struct gpio_chip *chip, unsigned offset,
unsigned dir) unsigned dir)
{ {
struct dln2_gpio *dln2 = container_of(chip, struct dln2_gpio, gpio); struct dln2_gpio *dln2 = gpiochip_get_data(chip);
struct dln2_gpio_pin_val req = { struct dln2_gpio_pin_val req = {
.pin = cpu_to_le16(offset), .pin = cpu_to_le16(offset),
.value = dir, .value = dir,
...@@ -262,7 +262,7 @@ static int dln2_gpio_direction_input(struct gpio_chip *chip, unsigned offset) ...@@ -262,7 +262,7 @@ static int dln2_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
static int dln2_gpio_direction_output(struct gpio_chip *chip, unsigned offset, static int dln2_gpio_direction_output(struct gpio_chip *chip, unsigned offset,
int value) int value)
{ {
struct dln2_gpio *dln2 = container_of(chip, struct dln2_gpio, gpio); struct dln2_gpio *dln2 = gpiochip_get_data(chip);
int ret; int ret;
ret = dln2_gpio_pin_set_out_val(dln2, offset, value); ret = dln2_gpio_pin_set_out_val(dln2, offset, value);
...@@ -275,7 +275,7 @@ static int dln2_gpio_direction_output(struct gpio_chip *chip, unsigned offset, ...@@ -275,7 +275,7 @@ static int dln2_gpio_direction_output(struct gpio_chip *chip, unsigned offset,
static int dln2_gpio_set_debounce(struct gpio_chip *chip, unsigned offset, static int dln2_gpio_set_debounce(struct gpio_chip *chip, unsigned offset,
unsigned debounce) unsigned debounce)
{ {
struct dln2_gpio *dln2 = container_of(chip, struct dln2_gpio, gpio); struct dln2_gpio *dln2 = gpiochip_get_data(chip);
__le32 duration = cpu_to_le32(debounce); __le32 duration = cpu_to_le32(debounce);
return dln2_transfer_tx(dln2->pdev, DLN2_GPIO_SET_DEBOUNCE, return dln2_transfer_tx(dln2->pdev, DLN2_GPIO_SET_DEBOUNCE,
...@@ -302,7 +302,7 @@ static int dln2_gpio_set_event_cfg(struct dln2_gpio *dln2, unsigned pin, ...@@ -302,7 +302,7 @@ static int dln2_gpio_set_event_cfg(struct dln2_gpio *dln2, unsigned pin,
static void dln2_irq_unmask(struct irq_data *irqd) static void dln2_irq_unmask(struct irq_data *irqd)
{ {
struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd); struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd);
struct dln2_gpio *dln2 = container_of(gc, struct dln2_gpio, gpio); struct dln2_gpio *dln2 = gpiochip_get_data(gc);
int pin = irqd_to_hwirq(irqd); int pin = irqd_to_hwirq(irqd);
set_bit(pin, dln2->unmasked_irqs); set_bit(pin, dln2->unmasked_irqs);
...@@ -311,7 +311,7 @@ static void dln2_irq_unmask(struct irq_data *irqd) ...@@ -311,7 +311,7 @@ static void dln2_irq_unmask(struct irq_data *irqd)
static void dln2_irq_mask(struct irq_data *irqd) static void dln2_irq_mask(struct irq_data *irqd)
{ {
struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd); struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd);
struct dln2_gpio *dln2 = container_of(gc, struct dln2_gpio, gpio); struct dln2_gpio *dln2 = gpiochip_get_data(gc);
int pin = irqd_to_hwirq(irqd); int pin = irqd_to_hwirq(irqd);
clear_bit(pin, dln2->unmasked_irqs); clear_bit(pin, dln2->unmasked_irqs);
...@@ -320,7 +320,7 @@ static void dln2_irq_mask(struct irq_data *irqd) ...@@ -320,7 +320,7 @@ static void dln2_irq_mask(struct irq_data *irqd)
static int dln2_irq_set_type(struct irq_data *irqd, unsigned type) static int dln2_irq_set_type(struct irq_data *irqd, unsigned type)
{ {
struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd); struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd);
struct dln2_gpio *dln2 = container_of(gc, struct dln2_gpio, gpio); struct dln2_gpio *dln2 = gpiochip_get_data(gc);
int pin = irqd_to_hwirq(irqd); int pin = irqd_to_hwirq(irqd);
switch (type) { switch (type) {
...@@ -349,7 +349,7 @@ static int dln2_irq_set_type(struct irq_data *irqd, unsigned type) ...@@ -349,7 +349,7 @@ static int dln2_irq_set_type(struct irq_data *irqd, unsigned type)
static void dln2_irq_bus_lock(struct irq_data *irqd) static void dln2_irq_bus_lock(struct irq_data *irqd)
{ {
struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd); struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd);
struct dln2_gpio *dln2 = container_of(gc, struct dln2_gpio, gpio); struct dln2_gpio *dln2 = gpiochip_get_data(gc);
mutex_lock(&dln2->irq_lock); mutex_lock(&dln2->irq_lock);
} }
...@@ -357,7 +357,7 @@ static void dln2_irq_bus_lock(struct irq_data *irqd) ...@@ -357,7 +357,7 @@ static void dln2_irq_bus_lock(struct irq_data *irqd)
static void dln2_irq_bus_unlock(struct irq_data *irqd) static void dln2_irq_bus_unlock(struct irq_data *irqd)
{ {
struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd); struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd);
struct dln2_gpio *dln2 = container_of(gc, struct dln2_gpio, gpio); struct dln2_gpio *dln2 = gpiochip_get_data(gc);
int pin = irqd_to_hwirq(irqd); int pin = irqd_to_hwirq(irqd);
int enabled, unmasked; int enabled, unmasked;
unsigned type; unsigned type;
...@@ -377,7 +377,7 @@ static void dln2_irq_bus_unlock(struct irq_data *irqd) ...@@ -377,7 +377,7 @@ static void dln2_irq_bus_unlock(struct irq_data *irqd)
ret = dln2_gpio_set_event_cfg(dln2, pin, type, 0); ret = dln2_gpio_set_event_cfg(dln2, pin, type, 0);
if (ret) if (ret)
dev_err(dln2->gpio.dev, "failed to set event\n"); dev_err(dln2->gpio.parent, "failed to set event\n");
} }
mutex_unlock(&dln2->irq_lock); mutex_unlock(&dln2->irq_lock);
...@@ -406,19 +406,19 @@ static void dln2_gpio_event(struct platform_device *pdev, u16 echo, ...@@ -406,19 +406,19 @@ static void dln2_gpio_event(struct platform_device *pdev, u16 echo,
struct dln2_gpio *dln2 = platform_get_drvdata(pdev); struct dln2_gpio *dln2 = platform_get_drvdata(pdev);
if (len < sizeof(*event)) { if (len < sizeof(*event)) {
dev_err(dln2->gpio.dev, "short event message\n"); dev_err(dln2->gpio.parent, "short event message\n");
return; return;
} }
pin = le16_to_cpu(event->pin); pin = le16_to_cpu(event->pin);
if (pin >= dln2->gpio.ngpio) { if (pin >= dln2->gpio.ngpio) {
dev_err(dln2->gpio.dev, "out of bounds pin %d\n", pin); dev_err(dln2->gpio.parent, "out of bounds pin %d\n", pin);
return; return;
} }
irq = irq_find_mapping(dln2->gpio.irqdomain, pin); irq = irq_find_mapping(dln2->gpio.irqdomain, pin);
if (!irq) { if (!irq) {
dev_err(dln2->gpio.dev, "pin %d not mapped to IRQ\n", pin); dev_err(dln2->gpio.parent, "pin %d not mapped to IRQ\n", pin);
return; return;
} }
...@@ -462,7 +462,7 @@ static int dln2_gpio_probe(struct platform_device *pdev) ...@@ -462,7 +462,7 @@ static int dln2_gpio_probe(struct platform_device *pdev)
dln2->pdev = pdev; dln2->pdev = pdev;
dln2->gpio.label = "dln2"; dln2->gpio.label = "dln2";
dln2->gpio.dev = dev; dln2->gpio.parent = dev;
dln2->gpio.owner = THIS_MODULE; dln2->gpio.owner = THIS_MODULE;
dln2->gpio.base = -1; dln2->gpio.base = -1;
dln2->gpio.ngpio = pins; dln2->gpio.ngpio = pins;
...@@ -479,7 +479,7 @@ static int dln2_gpio_probe(struct platform_device *pdev) ...@@ -479,7 +479,7 @@ static int dln2_gpio_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, dln2); platform_set_drvdata(pdev, dln2);
ret = gpiochip_add(&dln2->gpio); ret = gpiochip_add_data(&dln2->gpio, dln2);
if (ret < 0) { if (ret < 0) {
dev_err(dev, "failed to add gpio chip: %d\n", ret); dev_err(dev, "failed to add gpio chip: %d\n", ret);
goto out; goto out;
......
...@@ -7,7 +7,9 @@ ...@@ -7,7 +7,9 @@
* *
* All enquiries to support@picochip.com * All enquiries to support@picochip.com
*/ */
#include <linux/basic_mmio_gpio.h> #include <linux/gpio/driver.h>
/* FIXME: for gpio_get_value(), replace this with direct register read */
#include <linux/gpio.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
...@@ -66,7 +68,7 @@ struct dwapb_context { ...@@ -66,7 +68,7 @@ struct dwapb_context {
#endif #endif
struct dwapb_gpio_port { struct dwapb_gpio_port {
struct bgpio_chip bgc; struct gpio_chip gc;
bool is_registered; bool is_registered;
struct dwapb_gpio *gpio; struct dwapb_gpio *gpio;
#ifdef CONFIG_PM_SLEEP #ifdef CONFIG_PM_SLEEP
...@@ -83,33 +85,26 @@ struct dwapb_gpio { ...@@ -83,33 +85,26 @@ struct dwapb_gpio {
struct irq_domain *domain; struct irq_domain *domain;
}; };
static inline struct dwapb_gpio_port *
to_dwapb_gpio_port(struct bgpio_chip *bgc)
{
return container_of(bgc, struct dwapb_gpio_port, bgc);
}
static inline u32 dwapb_read(struct dwapb_gpio *gpio, unsigned int offset) static inline u32 dwapb_read(struct dwapb_gpio *gpio, unsigned int offset)
{ {
struct bgpio_chip *bgc = &gpio->ports[0].bgc; struct gpio_chip *gc = &gpio->ports[0].gc;
void __iomem *reg_base = gpio->regs; void __iomem *reg_base = gpio->regs;
return bgc->read_reg(reg_base + offset); return gc->read_reg(reg_base + offset);
} }
static inline void dwapb_write(struct dwapb_gpio *gpio, unsigned int offset, static inline void dwapb_write(struct dwapb_gpio *gpio, unsigned int offset,
u32 val) u32 val)
{ {
struct bgpio_chip *bgc = &gpio->ports[0].bgc; struct gpio_chip *gc = &gpio->ports[0].gc;
void __iomem *reg_base = gpio->regs; void __iomem *reg_base = gpio->regs;
bgc->write_reg(reg_base + offset, val); gc->write_reg(reg_base + offset, val);
} }
static int dwapb_gpio_to_irq(struct gpio_chip *gc, unsigned offset) static int dwapb_gpio_to_irq(struct gpio_chip *gc, unsigned offset)
{ {
struct bgpio_chip *bgc = to_bgpio_chip(gc); struct dwapb_gpio_port *port = gpiochip_get_data(gc);
struct dwapb_gpio_port *port = to_dwapb_gpio_port(bgc);
struct dwapb_gpio *gpio = port->gpio; struct dwapb_gpio *gpio = port->gpio;
return irq_find_mapping(gpio->domain, offset); return irq_find_mapping(gpio->domain, offset);
...@@ -119,7 +114,7 @@ static void dwapb_toggle_trigger(struct dwapb_gpio *gpio, unsigned int offs) ...@@ -119,7 +114,7 @@ static void dwapb_toggle_trigger(struct dwapb_gpio *gpio, unsigned int offs)
{ {
u32 v = dwapb_read(gpio, GPIO_INT_POLARITY); u32 v = dwapb_read(gpio, GPIO_INT_POLARITY);
if (gpio_get_value(gpio->ports[0].bgc.gc.base + offs)) if (gpio_get_value(gpio->ports[0].gc.base + offs))
v &= ~BIT(offs); v &= ~BIT(offs);
else else
v |= BIT(offs); v |= BIT(offs);
...@@ -162,39 +157,39 @@ static void dwapb_irq_enable(struct irq_data *d) ...@@ -162,39 +157,39 @@ static void dwapb_irq_enable(struct irq_data *d)
{ {
struct irq_chip_generic *igc = irq_data_get_irq_chip_data(d); struct irq_chip_generic *igc = irq_data_get_irq_chip_data(d);
struct dwapb_gpio *gpio = igc->private; struct dwapb_gpio *gpio = igc->private;
struct bgpio_chip *bgc = &gpio->ports[0].bgc; struct gpio_chip *gc = &gpio->ports[0].gc;
unsigned long flags; unsigned long flags;
u32 val; u32 val;
spin_lock_irqsave(&bgc->lock, flags); spin_lock_irqsave(&gc->bgpio_lock, flags);
val = dwapb_read(gpio, GPIO_INTEN); val = dwapb_read(gpio, GPIO_INTEN);
val |= BIT(d->hwirq); val |= BIT(d->hwirq);
dwapb_write(gpio, GPIO_INTEN, val); dwapb_write(gpio, GPIO_INTEN, val);
spin_unlock_irqrestore(&bgc->lock, flags); spin_unlock_irqrestore(&gc->bgpio_lock, flags);
} }
static void dwapb_irq_disable(struct irq_data *d) static void dwapb_irq_disable(struct irq_data *d)
{ {
struct irq_chip_generic *igc = irq_data_get_irq_chip_data(d); struct irq_chip_generic *igc = irq_data_get_irq_chip_data(d);
struct dwapb_gpio *gpio = igc->private; struct dwapb_gpio *gpio = igc->private;
struct bgpio_chip *bgc = &gpio->ports[0].bgc; struct gpio_chip *gc = &gpio->ports[0].gc;
unsigned long flags; unsigned long flags;
u32 val; u32 val;
spin_lock_irqsave(&bgc->lock, flags); spin_lock_irqsave(&gc->bgpio_lock, flags);
val = dwapb_read(gpio, GPIO_INTEN); val = dwapb_read(gpio, GPIO_INTEN);
val &= ~BIT(d->hwirq); val &= ~BIT(d->hwirq);
dwapb_write(gpio, GPIO_INTEN, val); dwapb_write(gpio, GPIO_INTEN, val);
spin_unlock_irqrestore(&bgc->lock, flags); spin_unlock_irqrestore(&gc->bgpio_lock, flags);
} }
static int dwapb_irq_reqres(struct irq_data *d) static int dwapb_irq_reqres(struct irq_data *d)
{ {
struct irq_chip_generic *igc = irq_data_get_irq_chip_data(d); struct irq_chip_generic *igc = irq_data_get_irq_chip_data(d);
struct dwapb_gpio *gpio = igc->private; struct dwapb_gpio *gpio = igc->private;
struct bgpio_chip *bgc = &gpio->ports[0].bgc; struct gpio_chip *gc = &gpio->ports[0].gc;
if (gpiochip_lock_as_irq(&bgc->gc, irqd_to_hwirq(d))) { if (gpiochip_lock_as_irq(gc, irqd_to_hwirq(d))) {
dev_err(gpio->dev, "unable to lock HW IRQ %lu for IRQ\n", dev_err(gpio->dev, "unable to lock HW IRQ %lu for IRQ\n",
irqd_to_hwirq(d)); irqd_to_hwirq(d));
return -EINVAL; return -EINVAL;
...@@ -206,16 +201,16 @@ static void dwapb_irq_relres(struct irq_data *d) ...@@ -206,16 +201,16 @@ static void dwapb_irq_relres(struct irq_data *d)
{ {
struct irq_chip_generic *igc = irq_data_get_irq_chip_data(d); struct irq_chip_generic *igc = irq_data_get_irq_chip_data(d);
struct dwapb_gpio *gpio = igc->private; struct dwapb_gpio *gpio = igc->private;
struct bgpio_chip *bgc = &gpio->ports[0].bgc; struct gpio_chip *gc = &gpio->ports[0].gc;
gpiochip_unlock_as_irq(&bgc->gc, irqd_to_hwirq(d)); gpiochip_unlock_as_irq(gc, irqd_to_hwirq(d));
} }
static int dwapb_irq_set_type(struct irq_data *d, u32 type) static int dwapb_irq_set_type(struct irq_data *d, u32 type)
{ {
struct irq_chip_generic *igc = irq_data_get_irq_chip_data(d); struct irq_chip_generic *igc = irq_data_get_irq_chip_data(d);
struct dwapb_gpio *gpio = igc->private; struct dwapb_gpio *gpio = igc->private;
struct bgpio_chip *bgc = &gpio->ports[0].bgc; struct gpio_chip *gc = &gpio->ports[0].gc;
int bit = d->hwirq; int bit = d->hwirq;
unsigned long level, polarity, flags; unsigned long level, polarity, flags;
...@@ -223,7 +218,7 @@ static int dwapb_irq_set_type(struct irq_data *d, u32 type) ...@@ -223,7 +218,7 @@ static int dwapb_irq_set_type(struct irq_data *d, u32 type)
IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW))
return -EINVAL; return -EINVAL;
spin_lock_irqsave(&bgc->lock, flags); spin_lock_irqsave(&gc->bgpio_lock, flags);
level = dwapb_read(gpio, GPIO_INTTYPE_LEVEL); level = dwapb_read(gpio, GPIO_INTTYPE_LEVEL);
polarity = dwapb_read(gpio, GPIO_INT_POLARITY); polarity = dwapb_read(gpio, GPIO_INT_POLARITY);
...@@ -254,7 +249,7 @@ static int dwapb_irq_set_type(struct irq_data *d, u32 type) ...@@ -254,7 +249,7 @@ static int dwapb_irq_set_type(struct irq_data *d, u32 type)
dwapb_write(gpio, GPIO_INTTYPE_LEVEL, level); dwapb_write(gpio, GPIO_INTTYPE_LEVEL, level);
dwapb_write(gpio, GPIO_INT_POLARITY, polarity); dwapb_write(gpio, GPIO_INT_POLARITY, polarity);
spin_unlock_irqrestore(&bgc->lock, flags); spin_unlock_irqrestore(&gc->bgpio_lock, flags);
return 0; return 0;
} }
...@@ -262,13 +257,12 @@ static int dwapb_irq_set_type(struct irq_data *d, u32 type) ...@@ -262,13 +257,12 @@ static int dwapb_irq_set_type(struct irq_data *d, u32 type)
static int dwapb_gpio_set_debounce(struct gpio_chip *gc, static int dwapb_gpio_set_debounce(struct gpio_chip *gc,
unsigned offset, unsigned debounce) unsigned offset, unsigned debounce)
{ {
struct bgpio_chip *bgc = to_bgpio_chip(gc); struct dwapb_gpio_port *port = gpiochip_get_data(gc);
struct dwapb_gpio_port *port = to_dwapb_gpio_port(bgc);
struct dwapb_gpio *gpio = port->gpio; struct dwapb_gpio *gpio = port->gpio;
unsigned long flags, val_deb; unsigned long flags, val_deb;
unsigned long mask = bgc->pin2mask(bgc, offset); unsigned long mask = gc->pin2mask(gc, offset);
spin_lock_irqsave(&bgc->lock, flags); spin_lock_irqsave(&gc->bgpio_lock, flags);
val_deb = dwapb_read(gpio, GPIO_PORTA_DEBOUNCE); val_deb = dwapb_read(gpio, GPIO_PORTA_DEBOUNCE);
if (debounce) if (debounce)
...@@ -276,7 +270,7 @@ static int dwapb_gpio_set_debounce(struct gpio_chip *gc, ...@@ -276,7 +270,7 @@ static int dwapb_gpio_set_debounce(struct gpio_chip *gc,
else else
dwapb_write(gpio, GPIO_PORTA_DEBOUNCE, val_deb & ~mask); dwapb_write(gpio, GPIO_PORTA_DEBOUNCE, val_deb & ~mask);
spin_unlock_irqrestore(&bgc->lock, flags); spin_unlock_irqrestore(&gc->bgpio_lock, flags);
return 0; return 0;
} }
...@@ -295,7 +289,7 @@ static void dwapb_configure_irqs(struct dwapb_gpio *gpio, ...@@ -295,7 +289,7 @@ static void dwapb_configure_irqs(struct dwapb_gpio *gpio,
struct dwapb_gpio_port *port, struct dwapb_gpio_port *port,
struct dwapb_port_property *pp) struct dwapb_port_property *pp)
{ {
struct gpio_chip *gc = &port->bgc.gc; struct gpio_chip *gc = &port->gc;
struct device_node *node = pp->node; struct device_node *node = pp->node;
struct irq_chip_generic *irq_gc = NULL; struct irq_chip_generic *irq_gc = NULL;
unsigned int hwirq, ngpio = gc->ngpio; unsigned int hwirq, ngpio = gc->ngpio;
...@@ -369,13 +363,13 @@ static void dwapb_configure_irqs(struct dwapb_gpio *gpio, ...@@ -369,13 +363,13 @@ static void dwapb_configure_irqs(struct dwapb_gpio *gpio,
for (hwirq = 0 ; hwirq < ngpio ; hwirq++) for (hwirq = 0 ; hwirq < ngpio ; hwirq++)
irq_create_mapping(gpio->domain, hwirq); irq_create_mapping(gpio->domain, hwirq);
port->bgc.gc.to_irq = dwapb_gpio_to_irq; port->gc.to_irq = dwapb_gpio_to_irq;
} }
static void dwapb_irq_teardown(struct dwapb_gpio *gpio) static void dwapb_irq_teardown(struct dwapb_gpio *gpio)
{ {
struct dwapb_gpio_port *port = &gpio->ports[0]; struct dwapb_gpio_port *port = &gpio->ports[0];
struct gpio_chip *gc = &port->bgc.gc; struct gpio_chip *gc = &port->gc;
unsigned int ngpio = gc->ngpio; unsigned int ngpio = gc->ngpio;
irq_hw_number_t hwirq; irq_hw_number_t hwirq;
...@@ -412,7 +406,7 @@ static int dwapb_gpio_add_port(struct dwapb_gpio *gpio, ...@@ -412,7 +406,7 @@ static int dwapb_gpio_add_port(struct dwapb_gpio *gpio,
dirout = gpio->regs + GPIO_SWPORTA_DDR + dirout = gpio->regs + GPIO_SWPORTA_DDR +
(pp->idx * GPIO_SWPORT_DDR_SIZE); (pp->idx * GPIO_SWPORT_DDR_SIZE);
err = bgpio_init(&port->bgc, gpio->dev, 4, dat, set, NULL, dirout, err = bgpio_init(&port->gc, gpio->dev, 4, dat, set, NULL, dirout,
NULL, false); NULL, false);
if (err) { if (err) {
dev_err(gpio->dev, "failed to init gpio chip for %s\n", dev_err(gpio->dev, "failed to init gpio chip for %s\n",
...@@ -421,19 +415,19 @@ static int dwapb_gpio_add_port(struct dwapb_gpio *gpio, ...@@ -421,19 +415,19 @@ static int dwapb_gpio_add_port(struct dwapb_gpio *gpio,
} }
#ifdef CONFIG_OF_GPIO #ifdef CONFIG_OF_GPIO
port->bgc.gc.of_node = pp->node; port->gc.of_node = pp->node;
#endif #endif
port->bgc.gc.ngpio = pp->ngpio; port->gc.ngpio = pp->ngpio;
port->bgc.gc.base = pp->gpio_base; port->gc.base = pp->gpio_base;
/* Only port A support debounce */ /* Only port A support debounce */
if (pp->idx == 0) if (pp->idx == 0)
port->bgc.gc.set_debounce = dwapb_gpio_set_debounce; port->gc.set_debounce = dwapb_gpio_set_debounce;
if (pp->irq) if (pp->irq)
dwapb_configure_irqs(gpio, port, pp); dwapb_configure_irqs(gpio, port, pp);
err = gpiochip_add(&port->bgc.gc); err = gpiochip_add_data(&port->gc, port);
if (err) if (err)
dev_err(gpio->dev, "failed to register gpiochip for %s\n", dev_err(gpio->dev, "failed to register gpiochip for %s\n",
pp->name); pp->name);
...@@ -449,7 +443,7 @@ static void dwapb_gpio_unregister(struct dwapb_gpio *gpio) ...@@ -449,7 +443,7 @@ static void dwapb_gpio_unregister(struct dwapb_gpio *gpio)
for (m = 0; m < gpio->nr_ports; ++m) for (m = 0; m < gpio->nr_ports; ++m)
if (gpio->ports[m].is_registered) if (gpio->ports[m].is_registered)
gpiochip_remove(&gpio->ports[m].bgc.gc); gpiochip_remove(&gpio->ports[m].gc);
} }
static struct dwapb_platform_data * static struct dwapb_platform_data *
...@@ -591,11 +585,11 @@ static int dwapb_gpio_suspend(struct device *dev) ...@@ -591,11 +585,11 @@ static int dwapb_gpio_suspend(struct device *dev)
{ {
struct platform_device *pdev = to_platform_device(dev); struct platform_device *pdev = to_platform_device(dev);
struct dwapb_gpio *gpio = platform_get_drvdata(pdev); struct dwapb_gpio *gpio = platform_get_drvdata(pdev);
struct bgpio_chip *bgc = &gpio->ports[0].bgc; struct gpio_chip *gc = &gpio->ports[0].gc;
unsigned long flags; unsigned long flags;
int i; int i;
spin_lock_irqsave(&bgc->lock, flags); spin_lock_irqsave(&gc->bgpio_lock, flags);
for (i = 0; i < gpio->nr_ports; i++) { for (i = 0; i < gpio->nr_ports; i++) {
unsigned int offset; unsigned int offset;
unsigned int idx = gpio->ports[i].idx; unsigned int idx = gpio->ports[i].idx;
...@@ -624,7 +618,7 @@ static int dwapb_gpio_suspend(struct device *dev) ...@@ -624,7 +618,7 @@ static int dwapb_gpio_suspend(struct device *dev)
dwapb_write(gpio, GPIO_INTMASK, 0xffffffff); dwapb_write(gpio, GPIO_INTMASK, 0xffffffff);
} }
} }
spin_unlock_irqrestore(&bgc->lock, flags); spin_unlock_irqrestore(&gc->bgpio_lock, flags);
return 0; return 0;
} }
...@@ -633,11 +627,11 @@ static int dwapb_gpio_resume(struct device *dev) ...@@ -633,11 +627,11 @@ static int dwapb_gpio_resume(struct device *dev)
{ {
struct platform_device *pdev = to_platform_device(dev); struct platform_device *pdev = to_platform_device(dev);
struct dwapb_gpio *gpio = platform_get_drvdata(pdev); struct dwapb_gpio *gpio = platform_get_drvdata(pdev);
struct bgpio_chip *bgc = &gpio->ports[0].bgc; struct gpio_chip *gc = &gpio->ports[0].gc;
unsigned long flags; unsigned long flags;
int i; int i;
spin_lock_irqsave(&bgc->lock, flags); spin_lock_irqsave(&gc->bgpio_lock, flags);
for (i = 0; i < gpio->nr_ports; i++) { for (i = 0; i < gpio->nr_ports; i++) {
unsigned int offset; unsigned int offset;
unsigned int idx = gpio->ports[i].idx; unsigned int idx = gpio->ports[i].idx;
...@@ -666,7 +660,7 @@ static int dwapb_gpio_resume(struct device *dev) ...@@ -666,7 +660,7 @@ static int dwapb_gpio_resume(struct device *dev)
dwapb_write(gpio, GPIO_PORTA_EOI, 0xffffffff); dwapb_write(gpio, GPIO_PORTA_EOI, 0xffffffff);
} }
} }
spin_unlock_irqrestore(&bgc->lock, flags); spin_unlock_irqrestore(&gc->bgpio_lock, flags);
return 0; return 0;
} }
......
...@@ -103,7 +103,7 @@ static int em_gio_irq_reqres(struct irq_data *d) ...@@ -103,7 +103,7 @@ static int em_gio_irq_reqres(struct irq_data *d)
struct em_gio_priv *p = irq_data_get_irq_chip_data(d); struct em_gio_priv *p = irq_data_get_irq_chip_data(d);
if (gpiochip_lock_as_irq(&p->gpio_chip, irqd_to_hwirq(d))) { if (gpiochip_lock_as_irq(&p->gpio_chip, irqd_to_hwirq(d))) {
dev_err(p->gpio_chip.dev, dev_err(p->gpio_chip.parent,
"unable to lock HW IRQ %lu for IRQ\n", "unable to lock HW IRQ %lu for IRQ\n",
irqd_to_hwirq(d)); irqd_to_hwirq(d));
return -EINVAL; return -EINVAL;
...@@ -192,7 +192,7 @@ static irqreturn_t em_gio_irq_handler(int irq, void *dev_id) ...@@ -192,7 +192,7 @@ static irqreturn_t em_gio_irq_handler(int irq, void *dev_id)
static inline struct em_gio_priv *gpio_to_priv(struct gpio_chip *chip) static inline struct em_gio_priv *gpio_to_priv(struct gpio_chip *chip)
{ {
return container_of(chip, struct em_gio_priv, gpio_chip); return gpiochip_get_data(chip);
} }
static int em_gio_direction_input(struct gpio_chip *chip, unsigned offset) static int em_gio_direction_input(struct gpio_chip *chip, unsigned offset)
...@@ -203,7 +203,7 @@ static int em_gio_direction_input(struct gpio_chip *chip, unsigned offset) ...@@ -203,7 +203,7 @@ static int em_gio_direction_input(struct gpio_chip *chip, unsigned offset)
static int em_gio_get(struct gpio_chip *chip, unsigned offset) static int em_gio_get(struct gpio_chip *chip, unsigned offset)
{ {
return (int)(em_gio_read(gpio_to_priv(chip), GIO_I) & BIT(offset)); return !!(em_gio_read(gpio_to_priv(chip), GIO_I) & BIT(offset));
} }
static void __em_gio_set(struct gpio_chip *chip, unsigned int reg, static void __em_gio_set(struct gpio_chip *chip, unsigned int reg,
...@@ -332,7 +332,7 @@ static int em_gio_probe(struct platform_device *pdev) ...@@ -332,7 +332,7 @@ static int em_gio_probe(struct platform_device *pdev)
gpio_chip->request = em_gio_request; gpio_chip->request = em_gio_request;
gpio_chip->free = em_gio_free; gpio_chip->free = em_gio_free;
gpio_chip->label = name; gpio_chip->label = name;
gpio_chip->dev = &pdev->dev; gpio_chip->parent = &pdev->dev;
gpio_chip->owner = THIS_MODULE; gpio_chip->owner = THIS_MODULE;
gpio_chip->base = -1; gpio_chip->base = -1;
gpio_chip->ngpio = ngpios; gpio_chip->ngpio = ngpios;
...@@ -368,7 +368,7 @@ static int em_gio_probe(struct platform_device *pdev) ...@@ -368,7 +368,7 @@ static int em_gio_probe(struct platform_device *pdev)
goto err1; goto err1;
} }
ret = gpiochip_add(gpio_chip); ret = gpiochip_add_data(gpio_chip, p);
if (ret) { if (ret) {
dev_err(&pdev->dev, "failed to add GPIO controller\n"); dev_err(&pdev->dev, "failed to add GPIO controller\n");
goto err1; goto err1;
......
...@@ -16,10 +16,11 @@ ...@@ -16,10 +16,11 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/io.h> #include <linux/io.h>
#include <linux/gpio.h>
#include <linux/irq.h> #include <linux/irq.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/basic_mmio_gpio.h> #include <linux/gpio/driver.h>
/* FIXME: this is here for gpio_to_irq() - get rid of this! */
#include <linux/gpio.h>
#include <mach/hardware.h> #include <mach/hardware.h>
#include <mach/gpio-ep93xx.h> #include <mach/gpio-ep93xx.h>
...@@ -28,7 +29,7 @@ ...@@ -28,7 +29,7 @@
struct ep93xx_gpio { struct ep93xx_gpio {
void __iomem *mmio_base; void __iomem *mmio_base;
struct bgpio_chip bgc[8]; struct gpio_chip gc[8];
}; };
/************************************************************************* /*************************************************************************
...@@ -319,26 +320,26 @@ static int ep93xx_gpio_to_irq(struct gpio_chip *chip, unsigned offset) ...@@ -319,26 +320,26 @@ static int ep93xx_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
return 64 + gpio; return 64 + gpio;
} }
static int ep93xx_gpio_add_bank(struct bgpio_chip *bgc, struct device *dev, static int ep93xx_gpio_add_bank(struct gpio_chip *gc, struct device *dev,
void __iomem *mmio_base, struct ep93xx_gpio_bank *bank) void __iomem *mmio_base, struct ep93xx_gpio_bank *bank)
{ {
void __iomem *data = mmio_base + bank->data; void __iomem *data = mmio_base + bank->data;
void __iomem *dir = mmio_base + bank->dir; void __iomem *dir = mmio_base + bank->dir;
int err; int err;
err = bgpio_init(bgc, dev, 1, data, NULL, NULL, dir, NULL, 0); err = bgpio_init(gc, dev, 1, data, NULL, NULL, dir, NULL, 0);
if (err) if (err)
return err; return err;
bgc->gc.label = bank->label; gc->label = bank->label;
bgc->gc.base = bank->base; gc->base = bank->base;
if (bank->has_debounce) { if (bank->has_debounce) {
bgc->gc.set_debounce = ep93xx_gpio_set_debounce; gc->set_debounce = ep93xx_gpio_set_debounce;
bgc->gc.to_irq = ep93xx_gpio_to_irq; gc->to_irq = ep93xx_gpio_to_irq;
} }
return gpiochip_add(&bgc->gc); return gpiochip_add_data(gc, NULL);
} }
static int ep93xx_gpio_probe(struct platform_device *pdev) static int ep93xx_gpio_probe(struct platform_device *pdev)
...@@ -358,10 +359,10 @@ static int ep93xx_gpio_probe(struct platform_device *pdev) ...@@ -358,10 +359,10 @@ static int ep93xx_gpio_probe(struct platform_device *pdev)
return PTR_ERR(ep93xx_gpio->mmio_base); return PTR_ERR(ep93xx_gpio->mmio_base);
for (i = 0; i < ARRAY_SIZE(ep93xx_gpio_banks); i++) { for (i = 0; i < ARRAY_SIZE(ep93xx_gpio_banks); i++) {
struct bgpio_chip *bgc = &ep93xx_gpio->bgc[i]; struct gpio_chip *gc = &ep93xx_gpio->gc[i];
struct ep93xx_gpio_bank *bank = &ep93xx_gpio_banks[i]; struct ep93xx_gpio_bank *bank = &ep93xx_gpio_banks[i];
if (ep93xx_gpio_add_bank(bgc, &pdev->dev, if (ep93xx_gpio_add_bank(gc, &pdev->dev,
ep93xx_gpio->mmio_base, bank)) ep93xx_gpio->mmio_base, bank))
dev_warn(&pdev->dev, "Unable to add gpio bank %s\n", dev_warn(&pdev->dev, "Unable to add gpio bank %s\n",
bank->label); bank->label);
......
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/gpio.h>
#include <linux/gpio/driver.h> #include <linux/gpio/driver.h>
#include <linux/of_gpio.h> #include <linux/of_gpio.h>
#include <linux/io.h> #include <linux/io.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/basic_mmio_gpio.h>
#define ETRAX_FS_rw_pa_dout 0 #define ETRAX_FS_rw_pa_dout 0
#define ETRAX_FS_r_pa_din 4 #define ETRAX_FS_r_pa_din 4
...@@ -67,7 +65,7 @@ struct etraxfs_gpio_block { ...@@ -67,7 +65,7 @@ struct etraxfs_gpio_block {
}; };
struct etraxfs_gpio_chip { struct etraxfs_gpio_chip {
struct bgpio_chip bgc; struct gpio_chip gc;
struct etraxfs_gpio_block *block; struct etraxfs_gpio_block *block;
}; };
...@@ -176,11 +174,6 @@ static const struct etraxfs_gpio_info etraxfs_gpio_artpec3 = { ...@@ -176,11 +174,6 @@ static const struct etraxfs_gpio_info etraxfs_gpio_artpec3 = {
.rw_intr_pins = ARTPEC3_rw_intr_pins, .rw_intr_pins = ARTPEC3_rw_intr_pins,
}; };
static struct etraxfs_gpio_chip *to_etraxfs(struct gpio_chip *gc)
{
return container_of(gc, struct etraxfs_gpio_chip, bgc.gc);
}
static unsigned int etraxfs_gpio_chip_to_port(struct gpio_chip *gc) static unsigned int etraxfs_gpio_chip_to_port(struct gpio_chip *gc)
{ {
return gc->label[0] - 'A'; return gc->label[0] - 'A';
...@@ -220,13 +213,13 @@ static unsigned int etraxfs_gpio_to_group_irq(unsigned int gpio) ...@@ -220,13 +213,13 @@ static unsigned int etraxfs_gpio_to_group_irq(unsigned int gpio)
static unsigned int etraxfs_gpio_to_group_pin(struct etraxfs_gpio_chip *chip, static unsigned int etraxfs_gpio_to_group_pin(struct etraxfs_gpio_chip *chip,
unsigned int gpio) unsigned int gpio)
{ {
return 4 * etraxfs_gpio_chip_to_port(&chip->bgc.gc) + gpio / 8; return 4 * etraxfs_gpio_chip_to_port(&chip->gc) + gpio / 8;
} }
static void etraxfs_gpio_irq_ack(struct irq_data *d) static void etraxfs_gpio_irq_ack(struct irq_data *d)
{ {
struct etraxfs_gpio_chip *chip = struct etraxfs_gpio_chip *chip =
to_etraxfs(irq_data_get_irq_chip_data(d)); gpiochip_get_data(irq_data_get_irq_chip_data(d));
struct etraxfs_gpio_block *block = chip->block; struct etraxfs_gpio_block *block = chip->block;
unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq); unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq);
...@@ -236,7 +229,7 @@ static void etraxfs_gpio_irq_ack(struct irq_data *d) ...@@ -236,7 +229,7 @@ static void etraxfs_gpio_irq_ack(struct irq_data *d)
static void etraxfs_gpio_irq_mask(struct irq_data *d) static void etraxfs_gpio_irq_mask(struct irq_data *d)
{ {
struct etraxfs_gpio_chip *chip = struct etraxfs_gpio_chip *chip =
to_etraxfs(irq_data_get_irq_chip_data(d)); gpiochip_get_data(irq_data_get_irq_chip_data(d));
struct etraxfs_gpio_block *block = chip->block; struct etraxfs_gpio_block *block = chip->block;
unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq); unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq);
...@@ -249,7 +242,7 @@ static void etraxfs_gpio_irq_mask(struct irq_data *d) ...@@ -249,7 +242,7 @@ static void etraxfs_gpio_irq_mask(struct irq_data *d)
static void etraxfs_gpio_irq_unmask(struct irq_data *d) static void etraxfs_gpio_irq_unmask(struct irq_data *d)
{ {
struct etraxfs_gpio_chip *chip = struct etraxfs_gpio_chip *chip =
to_etraxfs(irq_data_get_irq_chip_data(d)); gpiochip_get_data(irq_data_get_irq_chip_data(d));
struct etraxfs_gpio_block *block = chip->block; struct etraxfs_gpio_block *block = chip->block;
unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq); unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq);
...@@ -262,7 +255,7 @@ static void etraxfs_gpio_irq_unmask(struct irq_data *d) ...@@ -262,7 +255,7 @@ static void etraxfs_gpio_irq_unmask(struct irq_data *d)
static int etraxfs_gpio_irq_set_type(struct irq_data *d, u32 type) static int etraxfs_gpio_irq_set_type(struct irq_data *d, u32 type)
{ {
struct etraxfs_gpio_chip *chip = struct etraxfs_gpio_chip *chip =
to_etraxfs(irq_data_get_irq_chip_data(d)); gpiochip_get_data(irq_data_get_irq_chip_data(d));
struct etraxfs_gpio_block *block = chip->block; struct etraxfs_gpio_block *block = chip->block;
unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq); unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq);
u32 cfg; u32 cfg;
...@@ -299,7 +292,7 @@ static int etraxfs_gpio_irq_set_type(struct irq_data *d, u32 type) ...@@ -299,7 +292,7 @@ static int etraxfs_gpio_irq_set_type(struct irq_data *d, u32 type)
static int etraxfs_gpio_irq_request_resources(struct irq_data *d) static int etraxfs_gpio_irq_request_resources(struct irq_data *d)
{ {
struct etraxfs_gpio_chip *chip = struct etraxfs_gpio_chip *chip =
to_etraxfs(irq_data_get_irq_chip_data(d)); gpiochip_get_data(irq_data_get_irq_chip_data(d));
struct etraxfs_gpio_block *block = chip->block; struct etraxfs_gpio_block *block = chip->block;
unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq); unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq);
int ret = -EBUSY; int ret = -EBUSY;
...@@ -308,7 +301,7 @@ static int etraxfs_gpio_irq_request_resources(struct irq_data *d) ...@@ -308,7 +301,7 @@ static int etraxfs_gpio_irq_request_resources(struct irq_data *d)
if (block->group[grpirq]) if (block->group[grpirq])
goto out; goto out;
ret = gpiochip_lock_as_irq(&chip->bgc.gc, d->hwirq); ret = gpiochip_lock_as_irq(&chip->gc, d->hwirq);
if (ret) if (ret)
goto out; goto out;
...@@ -330,13 +323,13 @@ static int etraxfs_gpio_irq_request_resources(struct irq_data *d) ...@@ -330,13 +323,13 @@ static int etraxfs_gpio_irq_request_resources(struct irq_data *d)
static void etraxfs_gpio_irq_release_resources(struct irq_data *d) static void etraxfs_gpio_irq_release_resources(struct irq_data *d)
{ {
struct etraxfs_gpio_chip *chip = struct etraxfs_gpio_chip *chip =
to_etraxfs(irq_data_get_irq_chip_data(d)); gpiochip_get_data(irq_data_get_irq_chip_data(d));
struct etraxfs_gpio_block *block = chip->block; struct etraxfs_gpio_block *block = chip->block;
unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq); unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq);
spin_lock(&block->lock); spin_lock(&block->lock);
block->group[grpirq] = 0; block->group[grpirq] = 0;
gpiochip_unlock_as_irq(&chip->bgc.gc, d->hwirq); gpiochip_unlock_as_irq(&chip->gc, d->hwirq);
spin_unlock(&block->lock); spin_unlock(&block->lock);
} }
...@@ -419,7 +412,7 @@ static int etraxfs_gpio_probe(struct platform_device *pdev) ...@@ -419,7 +412,7 @@ static int etraxfs_gpio_probe(struct platform_device *pdev)
for (i = 0; i < info->num_ports; i++) { for (i = 0; i < info->num_ports; i++) {
struct etraxfs_gpio_chip *chip = &chips[i]; struct etraxfs_gpio_chip *chip = &chips[i];
struct bgpio_chip *bgc = &chip->bgc; struct gpio_chip *gc = &chip->gc;
const struct etraxfs_gpio_port *port = &info->ports[i]; const struct etraxfs_gpio_port *port = &info->ports[i];
unsigned long flags = BGPIOF_READ_OUTPUT_REG_SET; unsigned long flags = BGPIOF_READ_OUTPUT_REG_SET;
void __iomem *dat = regs + port->din; void __iomem *dat = regs + port->din;
...@@ -433,7 +426,7 @@ static int etraxfs_gpio_probe(struct platform_device *pdev) ...@@ -433,7 +426,7 @@ static int etraxfs_gpio_probe(struct platform_device *pdev)
flags = BGPIOF_NO_OUTPUT; flags = BGPIOF_NO_OUTPUT;
} }
ret = bgpio_init(bgc, dev, 4, ret = bgpio_init(gc, dev, 4,
dat, set, NULL, dirout, NULL, dat, set, NULL, dirout, NULL,
flags); flags);
if (ret) { if (ret) {
...@@ -442,28 +435,28 @@ static int etraxfs_gpio_probe(struct platform_device *pdev) ...@@ -442,28 +435,28 @@ static int etraxfs_gpio_probe(struct platform_device *pdev)
continue; continue;
} }
bgc->gc.ngpio = port->ngpio; gc->ngpio = port->ngpio;
bgc->gc.label = port->label; gc->label = port->label;
bgc->gc.of_node = dev->of_node; gc->of_node = dev->of_node;
bgc->gc.of_gpio_n_cells = 3; gc->of_gpio_n_cells = 3;
bgc->gc.of_xlate = etraxfs_gpio_of_xlate; gc->of_xlate = etraxfs_gpio_of_xlate;
ret = gpiochip_add(&bgc->gc); ret = gpiochip_add_data(gc, chip);
if (ret) { if (ret) {
dev_err(dev, "Unable to register port %s\n", dev_err(dev, "Unable to register port %s\n",
bgc->gc.label); gc->label);
continue; continue;
} }
if (i > 0 && !allportsirq) if (i > 0 && !allportsirq)
continue; continue;
ret = gpiochip_irqchip_add(&bgc->gc, &etraxfs_gpio_irq_chip, 0, ret = gpiochip_irqchip_add(gc, &etraxfs_gpio_irq_chip, 0,
handle_level_irq, IRQ_TYPE_NONE); handle_level_irq, IRQ_TYPE_NONE);
if (ret) { if (ret) {
dev_err(dev, "Unable to add irqchip to port %s\n", dev_err(dev, "Unable to add irqchip to port %s\n",
bgc->gc.label); gc->label);
} }
} }
......
...@@ -193,8 +193,7 @@ static struct f7188x_gpio_bank f71889_gpio_bank[] = { ...@@ -193,8 +193,7 @@ static struct f7188x_gpio_bank f71889_gpio_bank[] = {
static int f7188x_gpio_direction_in(struct gpio_chip *chip, unsigned offset) static int f7188x_gpio_direction_in(struct gpio_chip *chip, unsigned offset)
{ {
int err; int err;
struct f7188x_gpio_bank *bank = struct f7188x_gpio_bank *bank = gpiochip_get_data(chip);
container_of(chip, struct f7188x_gpio_bank, chip);
struct f7188x_sio *sio = bank->data->sio; struct f7188x_sio *sio = bank->data->sio;
u8 dir; u8 dir;
...@@ -215,8 +214,7 @@ static int f7188x_gpio_direction_in(struct gpio_chip *chip, unsigned offset) ...@@ -215,8 +214,7 @@ static int f7188x_gpio_direction_in(struct gpio_chip *chip, unsigned offset)
static int f7188x_gpio_get(struct gpio_chip *chip, unsigned offset) static int f7188x_gpio_get(struct gpio_chip *chip, unsigned offset)
{ {
int err; int err;
struct f7188x_gpio_bank *bank = struct f7188x_gpio_bank *bank = gpiochip_get_data(chip);
container_of(chip, struct f7188x_gpio_bank, chip);
struct f7188x_sio *sio = bank->data->sio; struct f7188x_sio *sio = bank->data->sio;
u8 dir, data; u8 dir, data;
...@@ -241,8 +239,7 @@ static int f7188x_gpio_direction_out(struct gpio_chip *chip, ...@@ -241,8 +239,7 @@ static int f7188x_gpio_direction_out(struct gpio_chip *chip,
unsigned offset, int value) unsigned offset, int value)
{ {
int err; int err;
struct f7188x_gpio_bank *bank = struct f7188x_gpio_bank *bank = gpiochip_get_data(chip);
container_of(chip, struct f7188x_gpio_bank, chip);
struct f7188x_sio *sio = bank->data->sio; struct f7188x_sio *sio = bank->data->sio;
u8 dir, data_out; u8 dir, data_out;
...@@ -270,8 +267,7 @@ static int f7188x_gpio_direction_out(struct gpio_chip *chip, ...@@ -270,8 +267,7 @@ static int f7188x_gpio_direction_out(struct gpio_chip *chip,
static void f7188x_gpio_set(struct gpio_chip *chip, unsigned offset, int value) static void f7188x_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
{ {
int err; int err;
struct f7188x_gpio_bank *bank = struct f7188x_gpio_bank *bank = gpiochip_get_data(chip);
container_of(chip, struct f7188x_gpio_bank, chip);
struct f7188x_sio *sio = bank->data->sio; struct f7188x_sio *sio = bank->data->sio;
u8 data_out; u8 data_out;
...@@ -298,7 +294,7 @@ static int f7188x_gpio_probe(struct platform_device *pdev) ...@@ -298,7 +294,7 @@ static int f7188x_gpio_probe(struct platform_device *pdev)
{ {
int err; int err;
int i; int i;
struct f7188x_sio *sio = pdev->dev.platform_data; struct f7188x_sio *sio = dev_get_platdata(&pdev->dev);
struct f7188x_gpio_data *data; struct f7188x_gpio_data *data;
data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
...@@ -333,10 +329,10 @@ static int f7188x_gpio_probe(struct platform_device *pdev) ...@@ -333,10 +329,10 @@ static int f7188x_gpio_probe(struct platform_device *pdev)
for (i = 0; i < data->nr_bank; i++) { for (i = 0; i < data->nr_bank; i++) {
struct f7188x_gpio_bank *bank = &data->bank[i]; struct f7188x_gpio_bank *bank = &data->bank[i];
bank->chip.dev = &pdev->dev; bank->chip.parent = &pdev->dev;
bank->data = data; bank->data = data;
err = gpiochip_add(&bank->chip); err = gpiochip_add_data(&bank->chip, bank);
if (err) { if (err) {
dev_err(&pdev->dev, dev_err(&pdev->dev,
"Failed to register gpiochip %d: %d\n", "Failed to register gpiochip %d: %d\n",
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
#include <linux/of_gpio.h> #include <linux/of_gpio.h>
#include <linux/of_address.h> #include <linux/of_address.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/basic_mmio_gpio.h> #include <linux/gpio/driver.h>
#define GEF_GPIO_DIRECT 0x00 #define GEF_GPIO_DIRECT 0x00
#define GEF_GPIO_IN 0x04 #define GEF_GPIO_IN 0x04
...@@ -55,19 +55,19 @@ static int __init gef_gpio_probe(struct platform_device *pdev) ...@@ -55,19 +55,19 @@ static int __init gef_gpio_probe(struct platform_device *pdev)
{ {
const struct of_device_id *of_id = const struct of_device_id *of_id =
of_match_device(gef_gpio_ids, &pdev->dev); of_match_device(gef_gpio_ids, &pdev->dev);
struct bgpio_chip *bgc; struct gpio_chip *gc;
void __iomem *regs; void __iomem *regs;
int ret; int ret;
bgc = devm_kzalloc(&pdev->dev, sizeof(*bgc), GFP_KERNEL); gc = devm_kzalloc(&pdev->dev, sizeof(*gc), GFP_KERNEL);
if (!bgc) if (!gc)
return -ENOMEM; return -ENOMEM;
regs = of_iomap(pdev->dev.of_node, 0); regs = of_iomap(pdev->dev.of_node, 0);
if (!regs) if (!regs)
return -ENOMEM; return -ENOMEM;
ret = bgpio_init(bgc, &pdev->dev, 4, regs + GEF_GPIO_IN, ret = bgpio_init(gc, &pdev->dev, 4, regs + GEF_GPIO_IN,
regs + GEF_GPIO_OUT, NULL, NULL, regs + GEF_GPIO_OUT, NULL, NULL,
regs + GEF_GPIO_DIRECT, BGPIOF_BIG_ENDIAN_BYTE_ORDER); regs + GEF_GPIO_DIRECT, BGPIOF_BIG_ENDIAN_BYTE_ORDER);
if (ret) { if (ret) {
...@@ -76,20 +76,20 @@ static int __init gef_gpio_probe(struct platform_device *pdev) ...@@ -76,20 +76,20 @@ static int __init gef_gpio_probe(struct platform_device *pdev)
} }
/* Setup pointers to chip functions */ /* Setup pointers to chip functions */
bgc->gc.label = devm_kstrdup(&pdev->dev, pdev->dev.of_node->full_name, gc->label = devm_kstrdup(&pdev->dev, pdev->dev.of_node->full_name,
GFP_KERNEL); GFP_KERNEL);
if (!bgc->gc.label) { if (!gc->label) {
ret = -ENOMEM; ret = -ENOMEM;
goto err0; goto err0;
} }
bgc->gc.base = -1; gc->base = -1;
bgc->gc.ngpio = (u16)(uintptr_t)of_id->data; gc->ngpio = (u16)(uintptr_t)of_id->data;
bgc->gc.of_gpio_n_cells = 2; gc->of_gpio_n_cells = 2;
bgc->gc.of_node = pdev->dev.of_node; gc->of_node = pdev->dev.of_node;
/* This function adds a memory mapped GPIO chip */ /* This function adds a memory mapped GPIO chip */
ret = gpiochip_add(&bgc->gc); ret = gpiochip_add_data(gc, NULL);
if (ret) if (ret)
goto err0; goto err0;
......
This diff is collapsed.
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
#include <linux/gpio.h> #include <linux/gpio.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/basic_mmio_gpio.h> #include <linux/gpio/driver.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/irq.h> #include <linux/irq.h>
#include <linux/irqdomain.h> #include <linux/irqdomain.h>
...@@ -63,7 +63,7 @@ struct grgpio_lirq { ...@@ -63,7 +63,7 @@ struct grgpio_lirq {
}; };
struct grgpio_priv { struct grgpio_priv {
struct bgpio_chip bgc; struct gpio_chip gc;
void __iomem *regs; void __iomem *regs;
struct device *dev; struct device *dev;
...@@ -92,29 +92,22 @@ struct grgpio_priv { ...@@ -92,29 +92,22 @@ struct grgpio_priv {
struct grgpio_lirq lirqs[GRGPIO_MAX_NGPIO]; struct grgpio_lirq lirqs[GRGPIO_MAX_NGPIO];
}; };
static inline struct grgpio_priv *grgpio_gc_to_priv(struct gpio_chip *gc)
{
struct bgpio_chip *bgc = to_bgpio_chip(gc);
return container_of(bgc, struct grgpio_priv, bgc);
}
static void grgpio_set_imask(struct grgpio_priv *priv, unsigned int offset, static void grgpio_set_imask(struct grgpio_priv *priv, unsigned int offset,
int val) int val)
{ {
struct bgpio_chip *bgc = &priv->bgc; struct gpio_chip *gc = &priv->gc;
unsigned long mask = bgc->pin2mask(bgc, offset); unsigned long mask = gc->pin2mask(gc, offset);
if (val) if (val)
priv->imask |= mask; priv->imask |= mask;
else else
priv->imask &= ~mask; priv->imask &= ~mask;
bgc->write_reg(priv->regs + GRGPIO_IMASK, priv->imask); gc->write_reg(priv->regs + GRGPIO_IMASK, priv->imask);
} }
static int grgpio_to_irq(struct gpio_chip *gc, unsigned offset) static int grgpio_to_irq(struct gpio_chip *gc, unsigned offset)
{ {
struct grgpio_priv *priv = grgpio_gc_to_priv(gc); struct grgpio_priv *priv = gpiochip_get_data(gc);
if (offset >= gc->ngpio) if (offset >= gc->ngpio)
return -ENXIO; return -ENXIO;
...@@ -158,15 +151,15 @@ static int grgpio_irq_set_type(struct irq_data *d, unsigned int type) ...@@ -158,15 +151,15 @@ static int grgpio_irq_set_type(struct irq_data *d, unsigned int type)
return -EINVAL; return -EINVAL;
} }
spin_lock_irqsave(&priv->bgc.lock, flags); spin_lock_irqsave(&priv->gc.bgpio_lock, flags);
ipol = priv->bgc.read_reg(priv->regs + GRGPIO_IPOL) & ~mask; ipol = priv->gc.read_reg(priv->regs + GRGPIO_IPOL) & ~mask;
iedge = priv->bgc.read_reg(priv->regs + GRGPIO_IEDGE) & ~mask; iedge = priv->gc.read_reg(priv->regs + GRGPIO_IEDGE) & ~mask;
priv->bgc.write_reg(priv->regs + GRGPIO_IPOL, ipol | pol); priv->gc.write_reg(priv->regs + GRGPIO_IPOL, ipol | pol);
priv->bgc.write_reg(priv->regs + GRGPIO_IEDGE, iedge | edge); priv->gc.write_reg(priv->regs + GRGPIO_IEDGE, iedge | edge);
spin_unlock_irqrestore(&priv->bgc.lock, flags); spin_unlock_irqrestore(&priv->gc.bgpio_lock, flags);
return 0; return 0;
} }
...@@ -177,11 +170,11 @@ static void grgpio_irq_mask(struct irq_data *d) ...@@ -177,11 +170,11 @@ static void grgpio_irq_mask(struct irq_data *d)
int offset = d->hwirq; int offset = d->hwirq;
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&priv->bgc.lock, flags); spin_lock_irqsave(&priv->gc.bgpio_lock, flags);
grgpio_set_imask(priv, offset, 0); grgpio_set_imask(priv, offset, 0);
spin_unlock_irqrestore(&priv->bgc.lock, flags); spin_unlock_irqrestore(&priv->gc.bgpio_lock, flags);
} }
static void grgpio_irq_unmask(struct irq_data *d) static void grgpio_irq_unmask(struct irq_data *d)
...@@ -190,11 +183,11 @@ static void grgpio_irq_unmask(struct irq_data *d) ...@@ -190,11 +183,11 @@ static void grgpio_irq_unmask(struct irq_data *d)
int offset = d->hwirq; int offset = d->hwirq;
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&priv->bgc.lock, flags); spin_lock_irqsave(&priv->gc.bgpio_lock, flags);
grgpio_set_imask(priv, offset, 1); grgpio_set_imask(priv, offset, 1);
spin_unlock_irqrestore(&priv->bgc.lock, flags); spin_unlock_irqrestore(&priv->gc.bgpio_lock, flags);
} }
static struct irq_chip grgpio_irq_chip = { static struct irq_chip grgpio_irq_chip = {
...@@ -207,12 +200,12 @@ static struct irq_chip grgpio_irq_chip = { ...@@ -207,12 +200,12 @@ static struct irq_chip grgpio_irq_chip = {
static irqreturn_t grgpio_irq_handler(int irq, void *dev) static irqreturn_t grgpio_irq_handler(int irq, void *dev)
{ {
struct grgpio_priv *priv = dev; struct grgpio_priv *priv = dev;
int ngpio = priv->bgc.gc.ngpio; int ngpio = priv->gc.ngpio;
unsigned long flags; unsigned long flags;
int i; int i;
int match = 0; int match = 0;
spin_lock_irqsave(&priv->bgc.lock, flags); spin_lock_irqsave(&priv->gc.bgpio_lock, flags);
/* /*
* For each gpio line, call its interrupt handler if it its underlying * For each gpio line, call its interrupt handler if it its underlying
...@@ -228,7 +221,7 @@ static irqreturn_t grgpio_irq_handler(int irq, void *dev) ...@@ -228,7 +221,7 @@ static irqreturn_t grgpio_irq_handler(int irq, void *dev)
} }
} }
spin_unlock_irqrestore(&priv->bgc.lock, flags); spin_unlock_irqrestore(&priv->gc.bgpio_lock, flags);
if (!match) if (!match)
dev_warn(priv->dev, "No gpio line matched irq %d\n", irq); dev_warn(priv->dev, "No gpio line matched irq %d\n", irq);
...@@ -260,7 +253,7 @@ static int grgpio_irq_map(struct irq_domain *d, unsigned int irq, ...@@ -260,7 +253,7 @@ static int grgpio_irq_map(struct irq_domain *d, unsigned int irq,
dev_dbg(priv->dev, "Mapping irq %d for gpio line %d\n", dev_dbg(priv->dev, "Mapping irq %d for gpio line %d\n",
irq, offset); irq, offset);
spin_lock_irqsave(&priv->bgc.lock, flags); spin_lock_irqsave(&priv->gc.bgpio_lock, flags);
/* Request underlying irq if not already requested */ /* Request underlying irq if not already requested */
lirq->irq = irq; lirq->irq = irq;
...@@ -273,14 +266,14 @@ static int grgpio_irq_map(struct irq_domain *d, unsigned int irq, ...@@ -273,14 +266,14 @@ static int grgpio_irq_map(struct irq_domain *d, unsigned int irq,
"Could not request underlying irq %d\n", "Could not request underlying irq %d\n",
uirq->uirq); uirq->uirq);
spin_unlock_irqrestore(&priv->bgc.lock, flags); spin_unlock_irqrestore(&priv->gc.bgpio_lock, flags);
return ret; return ret;
} }
} }
uirq->refcnt++; uirq->refcnt++;
spin_unlock_irqrestore(&priv->bgc.lock, flags); spin_unlock_irqrestore(&priv->gc.bgpio_lock, flags);
/* Setup irq */ /* Setup irq */
irq_set_chip_data(irq, priv); irq_set_chip_data(irq, priv);
...@@ -298,13 +291,13 @@ static void grgpio_irq_unmap(struct irq_domain *d, unsigned int irq) ...@@ -298,13 +291,13 @@ static void grgpio_irq_unmap(struct irq_domain *d, unsigned int irq)
struct grgpio_lirq *lirq; struct grgpio_lirq *lirq;
struct grgpio_uirq *uirq; struct grgpio_uirq *uirq;
unsigned long flags; unsigned long flags;
int ngpio = priv->bgc.gc.ngpio; int ngpio = priv->gc.ngpio;
int i; int i;
irq_set_chip_and_handler(irq, NULL, NULL); irq_set_chip_and_handler(irq, NULL, NULL);
irq_set_chip_data(irq, NULL); irq_set_chip_data(irq, NULL);
spin_lock_irqsave(&priv->bgc.lock, flags); spin_lock_irqsave(&priv->gc.bgpio_lock, flags);
/* Free underlying irq if last user unmapped */ /* Free underlying irq if last user unmapped */
index = -1; index = -1;
...@@ -326,7 +319,7 @@ static void grgpio_irq_unmap(struct irq_domain *d, unsigned int irq) ...@@ -326,7 +319,7 @@ static void grgpio_irq_unmap(struct irq_domain *d, unsigned int irq)
free_irq(uirq->uirq, priv); free_irq(uirq->uirq, priv);
} }
spin_unlock_irqrestore(&priv->bgc.lock, flags); spin_unlock_irqrestore(&priv->gc.bgpio_lock, flags);
} }
static const struct irq_domain_ops grgpio_irq_domain_ops = { static const struct irq_domain_ops grgpio_irq_domain_ops = {
...@@ -341,7 +334,6 @@ static int grgpio_probe(struct platform_device *ofdev) ...@@ -341,7 +334,6 @@ static int grgpio_probe(struct platform_device *ofdev)
struct device_node *np = ofdev->dev.of_node; struct device_node *np = ofdev->dev.of_node;
void __iomem *regs; void __iomem *regs;
struct gpio_chip *gc; struct gpio_chip *gc;
struct bgpio_chip *bgc;
struct grgpio_priv *priv; struct grgpio_priv *priv;
struct resource *res; struct resource *res;
int err; int err;
...@@ -359,8 +351,8 @@ static int grgpio_probe(struct platform_device *ofdev) ...@@ -359,8 +351,8 @@ static int grgpio_probe(struct platform_device *ofdev)
if (IS_ERR(regs)) if (IS_ERR(regs))
return PTR_ERR(regs); return PTR_ERR(regs);
bgc = &priv->bgc; gc = &priv->gc;
err = bgpio_init(bgc, &ofdev->dev, 4, regs + GRGPIO_DATA, err = bgpio_init(gc, &ofdev->dev, 4, regs + GRGPIO_DATA,
regs + GRGPIO_OUTPUT, NULL, regs + GRGPIO_DIR, NULL, regs + GRGPIO_OUTPUT, NULL, regs + GRGPIO_DIR, NULL,
BGPIOF_BIG_ENDIAN_BYTE_ORDER); BGPIOF_BIG_ENDIAN_BYTE_ORDER);
if (err) { if (err) {
...@@ -369,10 +361,9 @@ static int grgpio_probe(struct platform_device *ofdev) ...@@ -369,10 +361,9 @@ static int grgpio_probe(struct platform_device *ofdev)
} }
priv->regs = regs; priv->regs = regs;
priv->imask = bgc->read_reg(regs + GRGPIO_IMASK); priv->imask = gc->read_reg(regs + GRGPIO_IMASK);
priv->dev = &ofdev->dev; priv->dev = &ofdev->dev;
gc = &bgc->gc;
gc->of_node = np; gc->of_node = np;
gc->owner = THIS_MODULE; gc->owner = THIS_MODULE;
gc->to_irq = grgpio_to_irq; gc->to_irq = grgpio_to_irq;
...@@ -435,7 +426,7 @@ static int grgpio_probe(struct platform_device *ofdev) ...@@ -435,7 +426,7 @@ static int grgpio_probe(struct platform_device *ofdev)
platform_set_drvdata(ofdev, priv); platform_set_drvdata(ofdev, priv);
err = gpiochip_add(gc); err = gpiochip_add_data(gc, priv);
if (err) { if (err) {
dev_err(&ofdev->dev, "Could not add gpiochip\n"); dev_err(&ofdev->dev, "Could not add gpiochip\n");
if (priv->domain) if (priv->domain)
...@@ -456,7 +447,7 @@ static int grgpio_remove(struct platform_device *ofdev) ...@@ -456,7 +447,7 @@ static int grgpio_remove(struct platform_device *ofdev)
int i; int i;
int ret = 0; int ret = 0;
spin_lock_irqsave(&priv->bgc.lock, flags); spin_lock_irqsave(&priv->gc.bgpio_lock, flags);
if (priv->domain) { if (priv->domain) {
for (i = 0; i < GRGPIO_MAX_NGPIO; i++) { for (i = 0; i < GRGPIO_MAX_NGPIO; i++) {
...@@ -467,13 +458,13 @@ static int grgpio_remove(struct platform_device *ofdev) ...@@ -467,13 +458,13 @@ static int grgpio_remove(struct platform_device *ofdev)
} }
} }
gpiochip_remove(&priv->bgc.gc); gpiochip_remove(&priv->gc);
if (priv->domain) if (priv->domain)
irq_domain_remove(priv->domain); irq_domain_remove(priv->domain);
out: out:
spin_unlock_irqrestore(&priv->bgc.lock, flags); spin_unlock_irqrestore(&priv->gc.bgpio_lock, flags);
return ret; return ret;
} }
......
...@@ -282,7 +282,7 @@ static void ichx_gpiolib_setup(struct gpio_chip *chip) ...@@ -282,7 +282,7 @@ static void ichx_gpiolib_setup(struct gpio_chip *chip)
{ {
chip->owner = THIS_MODULE; chip->owner = THIS_MODULE;
chip->label = DRV_NAME; chip->label = DRV_NAME;
chip->dev = &ichx_priv.dev->dev; chip->parent = &ichx_priv.dev->dev;
/* Allow chip-specific overrides of request()/get() */ /* Allow chip-specific overrides of request()/get() */
chip->request = ichx_priv.desc->request ? chip->request = ichx_priv.desc->request ?
...@@ -499,7 +499,7 @@ static int ichx_gpio_probe(struct platform_device *pdev) ...@@ -499,7 +499,7 @@ static int ichx_gpio_probe(struct platform_device *pdev)
init: init:
ichx_gpiolib_setup(&ichx_priv.chip); ichx_gpiolib_setup(&ichx_priv.chip);
err = gpiochip_add(&ichx_priv.chip); err = gpiochip_add_data(&ichx_priv.chip, NULL);
if (err) { if (err) {
pr_err("Failed to register GPIOs\n"); pr_err("Failed to register GPIOs\n");
goto add_err; goto add_err;
......
...@@ -78,15 +78,10 @@ struct intel_mid_gpio { ...@@ -78,15 +78,10 @@ struct intel_mid_gpio {
struct pci_dev *pdev; struct pci_dev *pdev;
}; };
static inline struct intel_mid_gpio *to_intel_gpio_priv(struct gpio_chip *gc)
{
return container_of(gc, struct intel_mid_gpio, chip);
}
static void __iomem *gpio_reg(struct gpio_chip *chip, unsigned offset, static void __iomem *gpio_reg(struct gpio_chip *chip, unsigned offset,
enum GPIO_REG reg_type) enum GPIO_REG reg_type)
{ {
struct intel_mid_gpio *priv = to_intel_gpio_priv(chip); struct intel_mid_gpio *priv = gpiochip_get_data(chip);
unsigned nreg = chip->ngpio / 32; unsigned nreg = chip->ngpio / 32;
u8 reg = offset / 32; u8 reg = offset / 32;
...@@ -96,7 +91,7 @@ static void __iomem *gpio_reg(struct gpio_chip *chip, unsigned offset, ...@@ -96,7 +91,7 @@ static void __iomem *gpio_reg(struct gpio_chip *chip, unsigned offset,
static void __iomem *gpio_reg_2bit(struct gpio_chip *chip, unsigned offset, static void __iomem *gpio_reg_2bit(struct gpio_chip *chip, unsigned offset,
enum GPIO_REG reg_type) enum GPIO_REG reg_type)
{ {
struct intel_mid_gpio *priv = to_intel_gpio_priv(chip); struct intel_mid_gpio *priv = gpiochip_get_data(chip);
unsigned nreg = chip->ngpio / 32; unsigned nreg = chip->ngpio / 32;
u8 reg = offset / 16; u8 reg = offset / 16;
...@@ -120,7 +115,7 @@ static int intel_gpio_get(struct gpio_chip *chip, unsigned offset) ...@@ -120,7 +115,7 @@ static int intel_gpio_get(struct gpio_chip *chip, unsigned offset)
{ {
void __iomem *gplr = gpio_reg(chip, offset, GPLR); void __iomem *gplr = gpio_reg(chip, offset, GPLR);
return readl(gplr) & BIT(offset % 32); return !!(readl(gplr) & BIT(offset % 32));
} }
static void intel_gpio_set(struct gpio_chip *chip, unsigned offset, int value) static void intel_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
...@@ -138,7 +133,7 @@ static void intel_gpio_set(struct gpio_chip *chip, unsigned offset, int value) ...@@ -138,7 +133,7 @@ static void intel_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
static int intel_gpio_direction_input(struct gpio_chip *chip, unsigned offset) static int intel_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
{ {
struct intel_mid_gpio *priv = to_intel_gpio_priv(chip); struct intel_mid_gpio *priv = gpiochip_get_data(chip);
void __iomem *gpdr = gpio_reg(chip, offset, GPDR); void __iomem *gpdr = gpio_reg(chip, offset, GPDR);
u32 value; u32 value;
unsigned long flags; unsigned long flags;
...@@ -161,7 +156,7 @@ static int intel_gpio_direction_input(struct gpio_chip *chip, unsigned offset) ...@@ -161,7 +156,7 @@ static int intel_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
static int intel_gpio_direction_output(struct gpio_chip *chip, static int intel_gpio_direction_output(struct gpio_chip *chip,
unsigned offset, int value) unsigned offset, int value)
{ {
struct intel_mid_gpio *priv = to_intel_gpio_priv(chip); struct intel_mid_gpio *priv = gpiochip_get_data(chip);
void __iomem *gpdr = gpio_reg(chip, offset, GPDR); void __iomem *gpdr = gpio_reg(chip, offset, GPDR);
unsigned long flags; unsigned long flags;
...@@ -185,7 +180,7 @@ static int intel_gpio_direction_output(struct gpio_chip *chip, ...@@ -185,7 +180,7 @@ static int intel_gpio_direction_output(struct gpio_chip *chip,
static int intel_mid_irq_type(struct irq_data *d, unsigned type) static int intel_mid_irq_type(struct irq_data *d, unsigned type)
{ {
struct gpio_chip *gc = irq_data_get_irq_chip_data(d); struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
struct intel_mid_gpio *priv = to_intel_gpio_priv(gc); struct intel_mid_gpio *priv = gpiochip_get_data(gc);
u32 gpio = irqd_to_hwirq(d); u32 gpio = irqd_to_hwirq(d);
unsigned long flags; unsigned long flags;
u32 value; u32 value;
...@@ -304,7 +299,7 @@ MODULE_DEVICE_TABLE(pci, intel_gpio_ids); ...@@ -304,7 +299,7 @@ MODULE_DEVICE_TABLE(pci, intel_gpio_ids);
static void intel_mid_irq_handler(struct irq_desc *desc) static void intel_mid_irq_handler(struct irq_desc *desc)
{ {
struct gpio_chip *gc = irq_desc_get_handler_data(desc); struct gpio_chip *gc = irq_desc_get_handler_data(desc);
struct intel_mid_gpio *priv = to_intel_gpio_priv(gc); struct intel_mid_gpio *priv = gpiochip_get_data(gc);
struct irq_data *data = irq_desc_get_irq_data(desc); struct irq_data *data = irq_desc_get_irq_data(desc);
struct irq_chip *chip = irq_data_get_irq_chip(data); struct irq_chip *chip = irq_data_get_irq_chip(data);
u32 base, gpio, mask; u32 base, gpio, mask;
...@@ -392,7 +387,7 @@ static int intel_gpio_probe(struct pci_dev *pdev, ...@@ -392,7 +387,7 @@ static int intel_gpio_probe(struct pci_dev *pdev,
priv->reg_base = pcim_iomap_table(pdev)[0]; priv->reg_base = pcim_iomap_table(pdev)[0];
priv->chip.label = dev_name(&pdev->dev); priv->chip.label = dev_name(&pdev->dev);
priv->chip.dev = &pdev->dev; priv->chip.parent = &pdev->dev;
priv->chip.request = intel_gpio_request; priv->chip.request = intel_gpio_request;
priv->chip.direction_input = intel_gpio_direction_input; priv->chip.direction_input = intel_gpio_direction_input;
priv->chip.direction_output = intel_gpio_direction_output; priv->chip.direction_output = intel_gpio_direction_output;
...@@ -406,7 +401,7 @@ static int intel_gpio_probe(struct pci_dev *pdev, ...@@ -406,7 +401,7 @@ static int intel_gpio_probe(struct pci_dev *pdev,
spin_lock_init(&priv->lock); spin_lock_init(&priv->lock);
pci_set_drvdata(pdev, priv); pci_set_drvdata(pdev, priv);
retval = gpiochip_add(&priv->chip); retval = gpiochip_add_data(&priv->chip, priv);
if (retval) { if (retval) {
dev_err(&pdev->dev, "gpiochip_add error %d\n", retval); dev_err(&pdev->dev, "gpiochip_add error %d\n", retval);
return retval; return retval;
......
...@@ -114,7 +114,7 @@ static int iop3xx_gpio_probe(struct platform_device *pdev) ...@@ -114,7 +114,7 @@ static int iop3xx_gpio_probe(struct platform_device *pdev)
if (IS_ERR(base)) if (IS_ERR(base))
return PTR_ERR(base); return PTR_ERR(base);
return gpiochip_add(&iop3xx_chip); return gpiochip_add_data(&iop3xx_chip, NULL);
} }
static struct platform_driver iop3xx_gpio_driver = { static struct platform_driver iop3xx_gpio_driver = {
......
...@@ -77,11 +77,6 @@ static struct it87_gpio it87_gpio_chip = { ...@@ -77,11 +77,6 @@ static struct it87_gpio it87_gpio_chip = {
.lock = __SPIN_LOCK_UNLOCKED(it87_gpio_chip.lock), .lock = __SPIN_LOCK_UNLOCKED(it87_gpio_chip.lock),
}; };
static inline struct it87_gpio *to_it87_gpio(struct gpio_chip *chip)
{
return container_of(chip, struct it87_gpio, chip);
}
/* Superio chip access functions; copied from wdt_it87 */ /* Superio chip access functions; copied from wdt_it87 */
static inline int superio_enter(void) static inline int superio_enter(void)
...@@ -165,7 +160,7 @@ static int it87_gpio_request(struct gpio_chip *chip, unsigned gpio_num) ...@@ -165,7 +160,7 @@ static int it87_gpio_request(struct gpio_chip *chip, unsigned gpio_num)
{ {
u8 mask, group; u8 mask, group;
int rc = 0; int rc = 0;
struct it87_gpio *it87_gpio = to_it87_gpio(chip); struct it87_gpio *it87_gpio = gpiochip_get_data(chip);
mask = 1 << (gpio_num % 8); mask = 1 << (gpio_num % 8);
group = (gpio_num / 8); group = (gpio_num / 8);
...@@ -198,7 +193,7 @@ static int it87_gpio_get(struct gpio_chip *chip, unsigned gpio_num) ...@@ -198,7 +193,7 @@ static int it87_gpio_get(struct gpio_chip *chip, unsigned gpio_num)
{ {
u16 reg; u16 reg;
u8 mask; u8 mask;
struct it87_gpio *it87_gpio = to_it87_gpio(chip); struct it87_gpio *it87_gpio = gpiochip_get_data(chip);
mask = 1 << (gpio_num % 8); mask = 1 << (gpio_num % 8);
reg = (gpio_num / 8) + it87_gpio->io_base; reg = (gpio_num / 8) + it87_gpio->io_base;
...@@ -210,7 +205,7 @@ static int it87_gpio_direction_in(struct gpio_chip *chip, unsigned gpio_num) ...@@ -210,7 +205,7 @@ static int it87_gpio_direction_in(struct gpio_chip *chip, unsigned gpio_num)
{ {
u8 mask, group; u8 mask, group;
int rc = 0; int rc = 0;
struct it87_gpio *it87_gpio = to_it87_gpio(chip); struct it87_gpio *it87_gpio = gpiochip_get_data(chip);
mask = 1 << (gpio_num % 8); mask = 1 << (gpio_num % 8);
group = (gpio_num / 8); group = (gpio_num / 8);
...@@ -236,7 +231,7 @@ static void it87_gpio_set(struct gpio_chip *chip, ...@@ -236,7 +231,7 @@ static void it87_gpio_set(struct gpio_chip *chip,
{ {
u8 mask, curr_vals; u8 mask, curr_vals;
u16 reg; u16 reg;
struct it87_gpio *it87_gpio = to_it87_gpio(chip); struct it87_gpio *it87_gpio = gpiochip_get_data(chip);
mask = 1 << (gpio_num % 8); mask = 1 << (gpio_num % 8);
reg = (gpio_num / 8) + it87_gpio->io_base; reg = (gpio_num / 8) + it87_gpio->io_base;
...@@ -253,7 +248,7 @@ static int it87_gpio_direction_out(struct gpio_chip *chip, ...@@ -253,7 +248,7 @@ static int it87_gpio_direction_out(struct gpio_chip *chip,
{ {
u8 mask, group; u8 mask, group;
int rc = 0; int rc = 0;
struct it87_gpio *it87_gpio = to_it87_gpio(chip); struct it87_gpio *it87_gpio = gpiochip_get_data(chip);
mask = 1 << (gpio_num % 8); mask = 1 << (gpio_num % 8);
group = (gpio_num / 8); group = (gpio_num / 8);
...@@ -380,7 +375,7 @@ static int __init it87_gpio_init(void) ...@@ -380,7 +375,7 @@ static int __init it87_gpio_init(void)
it87_gpio->chip.names = (const char *const*)labels_table; it87_gpio->chip.names = (const char *const*)labels_table;
rc = gpiochip_add(&it87_gpio->chip); rc = gpiochip_add_data(&it87_gpio->chip, it87_gpio);
if (rc) if (rc)
goto labels_free; goto labels_free;
......
...@@ -59,7 +59,7 @@ struct ttl_module { ...@@ -59,7 +59,7 @@ struct ttl_module {
static int ttl_get_value(struct gpio_chip *gpio, unsigned offset) static int ttl_get_value(struct gpio_chip *gpio, unsigned offset)
{ {
struct ttl_module *mod = dev_get_drvdata(gpio->dev); struct ttl_module *mod = dev_get_drvdata(gpio->parent);
u8 *shadow; u8 *shadow;
int ret; int ret;
...@@ -76,12 +76,12 @@ static int ttl_get_value(struct gpio_chip *gpio, unsigned offset) ...@@ -76,12 +76,12 @@ static int ttl_get_value(struct gpio_chip *gpio, unsigned offset)
spin_lock(&mod->lock); spin_lock(&mod->lock);
ret = *shadow & (1 << offset); ret = *shadow & (1 << offset);
spin_unlock(&mod->lock); spin_unlock(&mod->lock);
return ret; return !!ret;
} }
static void ttl_set_value(struct gpio_chip *gpio, unsigned offset, int value) static void ttl_set_value(struct gpio_chip *gpio, unsigned offset, int value)
{ {
struct ttl_module *mod = dev_get_drvdata(gpio->dev); struct ttl_module *mod = dev_get_drvdata(gpio->parent);
void __iomem *port; void __iomem *port;
u8 *shadow; u8 *shadow;
...@@ -172,7 +172,7 @@ static int ttl_probe(struct platform_device *pdev) ...@@ -172,7 +172,7 @@ static int ttl_probe(struct platform_device *pdev)
/* Initialize the GPIO data structures */ /* Initialize the GPIO data structures */
gpio = &mod->gpio; gpio = &mod->gpio;
gpio->dev = &pdev->dev; gpio->parent = &pdev->dev;
gpio->label = pdev->name; gpio->label = pdev->name;
gpio->get = ttl_get_value; gpio->get = ttl_get_value;
gpio->set = ttl_set_value; gpio->set = ttl_set_value;
...@@ -182,7 +182,7 @@ static int ttl_probe(struct platform_device *pdev) ...@@ -182,7 +182,7 @@ static int ttl_probe(struct platform_device *pdev)
gpio->base = -1; gpio->base = -1;
gpio->ngpio = 20; gpio->ngpio = 20;
ret = gpiochip_add(gpio); ret = gpiochip_add_data(gpio, NULL);
if (ret) { if (ret) {
dev_err(dev, "unable to add GPIO chip\n"); dev_err(dev, "unable to add GPIO chip\n");
return ret; return ret;
......
...@@ -65,17 +65,15 @@ static int kempld_gpio_get_bit(struct kempld_device_data *pld, u8 reg, u8 bit) ...@@ -65,17 +65,15 @@ static int kempld_gpio_get_bit(struct kempld_device_data *pld, u8 reg, u8 bit)
static int kempld_gpio_get(struct gpio_chip *chip, unsigned offset) static int kempld_gpio_get(struct gpio_chip *chip, unsigned offset)
{ {
struct kempld_gpio_data *gpio struct kempld_gpio_data *gpio = gpiochip_get_data(chip);
= container_of(chip, struct kempld_gpio_data, chip);
struct kempld_device_data *pld = gpio->pld; struct kempld_device_data *pld = gpio->pld;
return kempld_gpio_get_bit(pld, KEMPLD_GPIO_LVL_NUM(offset), offset); return !!kempld_gpio_get_bit(pld, KEMPLD_GPIO_LVL_NUM(offset), offset);
} }
static void kempld_gpio_set(struct gpio_chip *chip, unsigned offset, int value) static void kempld_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
{ {
struct kempld_gpio_data *gpio struct kempld_gpio_data *gpio = gpiochip_get_data(chip);
= container_of(chip, struct kempld_gpio_data, chip);
struct kempld_device_data *pld = gpio->pld; struct kempld_device_data *pld = gpio->pld;
kempld_get_mutex(pld); kempld_get_mutex(pld);
...@@ -85,8 +83,7 @@ static void kempld_gpio_set(struct gpio_chip *chip, unsigned offset, int value) ...@@ -85,8 +83,7 @@ static void kempld_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
static int kempld_gpio_direction_input(struct gpio_chip *chip, unsigned offset) static int kempld_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
{ {
struct kempld_gpio_data *gpio struct kempld_gpio_data *gpio = gpiochip_get_data(chip);
= container_of(chip, struct kempld_gpio_data, chip);
struct kempld_device_data *pld = gpio->pld; struct kempld_device_data *pld = gpio->pld;
kempld_get_mutex(pld); kempld_get_mutex(pld);
...@@ -99,8 +96,7 @@ static int kempld_gpio_direction_input(struct gpio_chip *chip, unsigned offset) ...@@ -99,8 +96,7 @@ static int kempld_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
static int kempld_gpio_direction_output(struct gpio_chip *chip, unsigned offset, static int kempld_gpio_direction_output(struct gpio_chip *chip, unsigned offset,
int value) int value)
{ {
struct kempld_gpio_data *gpio struct kempld_gpio_data *gpio = gpiochip_get_data(chip);
= container_of(chip, struct kempld_gpio_data, chip);
struct kempld_device_data *pld = gpio->pld; struct kempld_device_data *pld = gpio->pld;
kempld_get_mutex(pld); kempld_get_mutex(pld);
...@@ -113,8 +109,7 @@ static int kempld_gpio_direction_output(struct gpio_chip *chip, unsigned offset, ...@@ -113,8 +109,7 @@ static int kempld_gpio_direction_output(struct gpio_chip *chip, unsigned offset,
static int kempld_gpio_get_direction(struct gpio_chip *chip, unsigned offset) static int kempld_gpio_get_direction(struct gpio_chip *chip, unsigned offset)
{ {
struct kempld_gpio_data *gpio struct kempld_gpio_data *gpio = gpiochip_get_data(chip);
= container_of(chip, struct kempld_gpio_data, chip);
struct kempld_device_data *pld = gpio->pld; struct kempld_device_data *pld = gpio->pld;
return !kempld_gpio_get_bit(pld, KEMPLD_GPIO_DIR_NUM(offset), offset); return !kempld_gpio_get_bit(pld, KEMPLD_GPIO_DIR_NUM(offset), offset);
...@@ -166,7 +161,7 @@ static int kempld_gpio_probe(struct platform_device *pdev) ...@@ -166,7 +161,7 @@ static int kempld_gpio_probe(struct platform_device *pdev)
chip = &gpio->chip; chip = &gpio->chip;
chip->label = "gpio-kempld"; chip->label = "gpio-kempld";
chip->owner = THIS_MODULE; chip->owner = THIS_MODULE;
chip->dev = dev; chip->parent = dev;
chip->can_sleep = true; chip->can_sleep = true;
if (pdata && pdata->gpio_base) if (pdata && pdata->gpio_base)
chip->base = pdata->gpio_base; chip->base = pdata->gpio_base;
...@@ -183,7 +178,7 @@ static int kempld_gpio_probe(struct platform_device *pdev) ...@@ -183,7 +178,7 @@ static int kempld_gpio_probe(struct platform_device *pdev)
return -ENODEV; return -ENODEV;
} }
ret = gpiochip_add(chip); ret = gpiochip_add_data(chip, gpio);
if (ret) { if (ret) {
dev_err(dev, "Could not register GPIO chip\n"); dev_err(dev, "Could not register GPIO chip\n");
return ret; return ret;
......
...@@ -234,7 +234,7 @@ static struct gpio_chip ks8695_gpio_chip = { ...@@ -234,7 +234,7 @@ static struct gpio_chip ks8695_gpio_chip = {
/* Register the GPIOs */ /* Register the GPIOs */
void ks8695_register_gpios(void) void ks8695_register_gpios(void)
{ {
if (gpiochip_add(&ks8695_gpio_chip)) if (gpiochip_add_data(&ks8695_gpio_chip, NULL))
printk(KERN_ERR "Unable to register core GPIOs\n"); printk(KERN_ERR "Unable to register core GPIOs\n");
} }
......
...@@ -110,6 +110,6 @@ static struct gpio_chip loongson_chip = { ...@@ -110,6 +110,6 @@ static struct gpio_chip loongson_chip = {
static int __init loongson_gpio_setup(void) static int __init loongson_gpio_setup(void)
{ {
return gpiochip_add(&loongson_chip); return gpiochip_add_data(&loongson_chip, NULL);
} }
postcore_initcall(loongson_gpio_setup); postcore_initcall(loongson_gpio_setup);
...@@ -45,14 +45,9 @@ struct lp3943_gpio { ...@@ -45,14 +45,9 @@ struct lp3943_gpio {
u16 input_mask; /* 1 = GPIO is input direction, 0 = output */ u16 input_mask; /* 1 = GPIO is input direction, 0 = output */
}; };
static inline struct lp3943_gpio *to_lp3943_gpio(struct gpio_chip *_chip)
{
return container_of(_chip, struct lp3943_gpio, chip);
}
static int lp3943_gpio_request(struct gpio_chip *chip, unsigned offset) static int lp3943_gpio_request(struct gpio_chip *chip, unsigned offset)
{ {
struct lp3943_gpio *lp3943_gpio = to_lp3943_gpio(chip); struct lp3943_gpio *lp3943_gpio = gpiochip_get_data(chip);
struct lp3943 *lp3943 = lp3943_gpio->lp3943; struct lp3943 *lp3943 = lp3943_gpio->lp3943;
/* Return an error if the pin is already assigned */ /* Return an error if the pin is already assigned */
...@@ -64,7 +59,7 @@ static int lp3943_gpio_request(struct gpio_chip *chip, unsigned offset) ...@@ -64,7 +59,7 @@ static int lp3943_gpio_request(struct gpio_chip *chip, unsigned offset)
static void lp3943_gpio_free(struct gpio_chip *chip, unsigned offset) static void lp3943_gpio_free(struct gpio_chip *chip, unsigned offset)
{ {
struct lp3943_gpio *lp3943_gpio = to_lp3943_gpio(chip); struct lp3943_gpio *lp3943_gpio = gpiochip_get_data(chip);
struct lp3943 *lp3943 = lp3943_gpio->lp3943; struct lp3943 *lp3943 = lp3943_gpio->lp3943;
clear_bit(offset, &lp3943->pin_used); clear_bit(offset, &lp3943->pin_used);
...@@ -82,7 +77,7 @@ static int lp3943_gpio_set_mode(struct lp3943_gpio *lp3943_gpio, u8 offset, ...@@ -82,7 +77,7 @@ static int lp3943_gpio_set_mode(struct lp3943_gpio *lp3943_gpio, u8 offset,
static int lp3943_gpio_direction_input(struct gpio_chip *chip, unsigned offset) static int lp3943_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
{ {
struct lp3943_gpio *lp3943_gpio = to_lp3943_gpio(chip); struct lp3943_gpio *lp3943_gpio = gpiochip_get_data(chip);
lp3943_gpio->input_mask |= BIT(offset); lp3943_gpio->input_mask |= BIT(offset);
...@@ -138,7 +133,7 @@ static int lp3943_get_gpio_out_status(struct lp3943_gpio *lp3943_gpio, ...@@ -138,7 +133,7 @@ static int lp3943_get_gpio_out_status(struct lp3943_gpio *lp3943_gpio,
static int lp3943_gpio_get(struct gpio_chip *chip, unsigned offset) static int lp3943_gpio_get(struct gpio_chip *chip, unsigned offset)
{ {
struct lp3943_gpio *lp3943_gpio = to_lp3943_gpio(chip); struct lp3943_gpio *lp3943_gpio = gpiochip_get_data(chip);
/* /*
* Limitation: * Limitation:
...@@ -157,7 +152,7 @@ static int lp3943_gpio_get(struct gpio_chip *chip, unsigned offset) ...@@ -157,7 +152,7 @@ static int lp3943_gpio_get(struct gpio_chip *chip, unsigned offset)
static void lp3943_gpio_set(struct gpio_chip *chip, unsigned offset, int value) static void lp3943_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
{ {
struct lp3943_gpio *lp3943_gpio = to_lp3943_gpio(chip); struct lp3943_gpio *lp3943_gpio = gpiochip_get_data(chip);
u8 data; u8 data;
if (value) if (value)
...@@ -171,7 +166,7 @@ static void lp3943_gpio_set(struct gpio_chip *chip, unsigned offset, int value) ...@@ -171,7 +166,7 @@ static void lp3943_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
static int lp3943_gpio_direction_output(struct gpio_chip *chip, unsigned offset, static int lp3943_gpio_direction_output(struct gpio_chip *chip, unsigned offset,
int value) int value)
{ {
struct lp3943_gpio *lp3943_gpio = to_lp3943_gpio(chip); struct lp3943_gpio *lp3943_gpio = gpiochip_get_data(chip);
lp3943_gpio_set(chip, offset, value); lp3943_gpio_set(chip, offset, value);
lp3943_gpio->input_mask &= ~BIT(offset); lp3943_gpio->input_mask &= ~BIT(offset);
...@@ -205,11 +200,11 @@ static int lp3943_gpio_probe(struct platform_device *pdev) ...@@ -205,11 +200,11 @@ static int lp3943_gpio_probe(struct platform_device *pdev)
lp3943_gpio->lp3943 = lp3943; lp3943_gpio->lp3943 = lp3943;
lp3943_gpio->chip = lp3943_gpio_chip; lp3943_gpio->chip = lp3943_gpio_chip;
lp3943_gpio->chip.dev = &pdev->dev; lp3943_gpio->chip.parent = &pdev->dev;
platform_set_drvdata(pdev, lp3943_gpio); platform_set_drvdata(pdev, lp3943_gpio);
return gpiochip_add(&lp3943_gpio->chip); return gpiochip_add_data(&lp3943_gpio->chip, lp3943_gpio);
} }
static int lp3943_gpio_remove(struct platform_device *pdev) static int lp3943_gpio_remove(struct platform_device *pdev)
......
...@@ -31,27 +31,22 @@ struct lpc18xx_gpio_chip { ...@@ -31,27 +31,22 @@ struct lpc18xx_gpio_chip {
spinlock_t lock; spinlock_t lock;
}; };
static inline struct lpc18xx_gpio_chip *to_lpc18xx_gpio(struct gpio_chip *chip)
{
return container_of(chip, struct lpc18xx_gpio_chip, gpio);
}
static void lpc18xx_gpio_set(struct gpio_chip *chip, unsigned offset, int value) static void lpc18xx_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
{ {
struct lpc18xx_gpio_chip *gc = to_lpc18xx_gpio(chip); struct lpc18xx_gpio_chip *gc = gpiochip_get_data(chip);
writeb(value ? 1 : 0, gc->base + offset); writeb(value ? 1 : 0, gc->base + offset);
} }
static int lpc18xx_gpio_get(struct gpio_chip *chip, unsigned offset) static int lpc18xx_gpio_get(struct gpio_chip *chip, unsigned offset)
{ {
struct lpc18xx_gpio_chip *gc = to_lpc18xx_gpio(chip); struct lpc18xx_gpio_chip *gc = gpiochip_get_data(chip);
return !!readb(gc->base + offset); return !!readb(gc->base + offset);
} }
static int lpc18xx_gpio_direction(struct gpio_chip *chip, unsigned offset, static int lpc18xx_gpio_direction(struct gpio_chip *chip, unsigned offset,
bool out) bool out)
{ {
struct lpc18xx_gpio_chip *gc = to_lpc18xx_gpio(chip); struct lpc18xx_gpio_chip *gc = gpiochip_get_data(chip);
unsigned long flags; unsigned long flags;
u32 port, pin, dir; u32 port, pin, dir;
...@@ -127,9 +122,9 @@ static int lpc18xx_gpio_probe(struct platform_device *pdev) ...@@ -127,9 +122,9 @@ static int lpc18xx_gpio_probe(struct platform_device *pdev)
spin_lock_init(&gc->lock); spin_lock_init(&gc->lock);
gc->gpio.dev = &pdev->dev; gc->gpio.parent = &pdev->dev;
ret = gpiochip_add(&gc->gpio); ret = gpiochip_add_data(&gc->gpio, gc);
if (ret) { if (ret) {
dev_err(&pdev->dev, "failed to add gpio chip\n"); dev_err(&pdev->dev, "failed to add gpio chip\n");
clk_disable_unprepare(gc->clk); clk_disable_unprepare(gc->clk);
......
...@@ -165,12 +165,6 @@ struct lpc32xx_gpio_chip { ...@@ -165,12 +165,6 @@ struct lpc32xx_gpio_chip {
struct gpio_regs *gpio_grp; struct gpio_regs *gpio_grp;
}; };
static inline struct lpc32xx_gpio_chip *to_lpc32xx_gpio(
struct gpio_chip *gpc)
{
return container_of(gpc, struct lpc32xx_gpio_chip, chip);
}
static void __set_gpio_dir_p012(struct lpc32xx_gpio_chip *group, static void __set_gpio_dir_p012(struct lpc32xx_gpio_chip *group,
unsigned pin, int input) unsigned pin, int input)
{ {
...@@ -261,7 +255,7 @@ static int __get_gpo_state_p3(struct lpc32xx_gpio_chip *group, ...@@ -261,7 +255,7 @@ static int __get_gpo_state_p3(struct lpc32xx_gpio_chip *group,
static int lpc32xx_gpio_dir_input_p012(struct gpio_chip *chip, static int lpc32xx_gpio_dir_input_p012(struct gpio_chip *chip,
unsigned pin) unsigned pin)
{ {
struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip); struct lpc32xx_gpio_chip *group = gpiochip_get_data(chip);
__set_gpio_dir_p012(group, pin, 1); __set_gpio_dir_p012(group, pin, 1);
...@@ -271,7 +265,7 @@ static int lpc32xx_gpio_dir_input_p012(struct gpio_chip *chip, ...@@ -271,7 +265,7 @@ static int lpc32xx_gpio_dir_input_p012(struct gpio_chip *chip,
static int lpc32xx_gpio_dir_input_p3(struct gpio_chip *chip, static int lpc32xx_gpio_dir_input_p3(struct gpio_chip *chip,
unsigned pin) unsigned pin)
{ {
struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip); struct lpc32xx_gpio_chip *group = gpiochip_get_data(chip);
__set_gpio_dir_p3(group, pin, 1); __set_gpio_dir_p3(group, pin, 1);
...@@ -286,29 +280,29 @@ static int lpc32xx_gpio_dir_in_always(struct gpio_chip *chip, ...@@ -286,29 +280,29 @@ static int lpc32xx_gpio_dir_in_always(struct gpio_chip *chip,
static int lpc32xx_gpio_get_value_p012(struct gpio_chip *chip, unsigned pin) static int lpc32xx_gpio_get_value_p012(struct gpio_chip *chip, unsigned pin)
{ {
struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip); struct lpc32xx_gpio_chip *group = gpiochip_get_data(chip);
return __get_gpio_state_p012(group, pin); return !!__get_gpio_state_p012(group, pin);
} }
static int lpc32xx_gpio_get_value_p3(struct gpio_chip *chip, unsigned pin) static int lpc32xx_gpio_get_value_p3(struct gpio_chip *chip, unsigned pin)
{ {
struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip); struct lpc32xx_gpio_chip *group = gpiochip_get_data(chip);
return __get_gpio_state_p3(group, pin); return !!__get_gpio_state_p3(group, pin);
} }
static int lpc32xx_gpi_get_value(struct gpio_chip *chip, unsigned pin) static int lpc32xx_gpi_get_value(struct gpio_chip *chip, unsigned pin)
{ {
struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip); struct lpc32xx_gpio_chip *group = gpiochip_get_data(chip);
return __get_gpi_state_p3(group, pin); return !!__get_gpi_state_p3(group, pin);
} }
static int lpc32xx_gpio_dir_output_p012(struct gpio_chip *chip, unsigned pin, static int lpc32xx_gpio_dir_output_p012(struct gpio_chip *chip, unsigned pin,
int value) int value)
{ {
struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip); struct lpc32xx_gpio_chip *group = gpiochip_get_data(chip);
__set_gpio_level_p012(group, pin, value); __set_gpio_level_p012(group, pin, value);
__set_gpio_dir_p012(group, pin, 0); __set_gpio_dir_p012(group, pin, 0);
...@@ -319,7 +313,7 @@ static int lpc32xx_gpio_dir_output_p012(struct gpio_chip *chip, unsigned pin, ...@@ -319,7 +313,7 @@ static int lpc32xx_gpio_dir_output_p012(struct gpio_chip *chip, unsigned pin,
static int lpc32xx_gpio_dir_output_p3(struct gpio_chip *chip, unsigned pin, static int lpc32xx_gpio_dir_output_p3(struct gpio_chip *chip, unsigned pin,
int value) int value)
{ {
struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip); struct lpc32xx_gpio_chip *group = gpiochip_get_data(chip);
__set_gpio_level_p3(group, pin, value); __set_gpio_level_p3(group, pin, value);
__set_gpio_dir_p3(group, pin, 0); __set_gpio_dir_p3(group, pin, 0);
...@@ -330,7 +324,7 @@ static int lpc32xx_gpio_dir_output_p3(struct gpio_chip *chip, unsigned pin, ...@@ -330,7 +324,7 @@ static int lpc32xx_gpio_dir_output_p3(struct gpio_chip *chip, unsigned pin,
static int lpc32xx_gpio_dir_out_always(struct gpio_chip *chip, unsigned pin, static int lpc32xx_gpio_dir_out_always(struct gpio_chip *chip, unsigned pin,
int value) int value)
{ {
struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip); struct lpc32xx_gpio_chip *group = gpiochip_get_data(chip);
__set_gpo_level_p3(group, pin, value); __set_gpo_level_p3(group, pin, value);
return 0; return 0;
...@@ -339,7 +333,7 @@ static int lpc32xx_gpio_dir_out_always(struct gpio_chip *chip, unsigned pin, ...@@ -339,7 +333,7 @@ static int lpc32xx_gpio_dir_out_always(struct gpio_chip *chip, unsigned pin,
static void lpc32xx_gpio_set_value_p012(struct gpio_chip *chip, unsigned pin, static void lpc32xx_gpio_set_value_p012(struct gpio_chip *chip, unsigned pin,
int value) int value)
{ {
struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip); struct lpc32xx_gpio_chip *group = gpiochip_get_data(chip);
__set_gpio_level_p012(group, pin, value); __set_gpio_level_p012(group, pin, value);
} }
...@@ -347,7 +341,7 @@ static void lpc32xx_gpio_set_value_p012(struct gpio_chip *chip, unsigned pin, ...@@ -347,7 +341,7 @@ static void lpc32xx_gpio_set_value_p012(struct gpio_chip *chip, unsigned pin,
static void lpc32xx_gpio_set_value_p3(struct gpio_chip *chip, unsigned pin, static void lpc32xx_gpio_set_value_p3(struct gpio_chip *chip, unsigned pin,
int value) int value)
{ {
struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip); struct lpc32xx_gpio_chip *group = gpiochip_get_data(chip);
__set_gpio_level_p3(group, pin, value); __set_gpio_level_p3(group, pin, value);
} }
...@@ -355,16 +349,16 @@ static void lpc32xx_gpio_set_value_p3(struct gpio_chip *chip, unsigned pin, ...@@ -355,16 +349,16 @@ static void lpc32xx_gpio_set_value_p3(struct gpio_chip *chip, unsigned pin,
static void lpc32xx_gpo_set_value(struct gpio_chip *chip, unsigned pin, static void lpc32xx_gpo_set_value(struct gpio_chip *chip, unsigned pin,
int value) int value)
{ {
struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip); struct lpc32xx_gpio_chip *group = gpiochip_get_data(chip);
__set_gpo_level_p3(group, pin, value); __set_gpo_level_p3(group, pin, value);
} }
static int lpc32xx_gpo_get_value(struct gpio_chip *chip, unsigned pin) static int lpc32xx_gpo_get_value(struct gpio_chip *chip, unsigned pin)
{ {
struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip); struct lpc32xx_gpio_chip *group = gpiochip_get_data(chip);
return __get_gpo_state_p3(group, pin); return !!__get_gpo_state_p3(group, pin);
} }
static int lpc32xx_gpio_request(struct gpio_chip *chip, unsigned pin) static int lpc32xx_gpio_request(struct gpio_chip *chip, unsigned pin)
...@@ -553,7 +547,8 @@ static int lpc32xx_gpio_probe(struct platform_device *pdev) ...@@ -553,7 +547,8 @@ static int lpc32xx_gpio_probe(struct platform_device *pdev)
lpc32xx_gpiochip[i].chip.of_gpio_n_cells = 3; lpc32xx_gpiochip[i].chip.of_gpio_n_cells = 3;
lpc32xx_gpiochip[i].chip.of_node = pdev->dev.of_node; lpc32xx_gpiochip[i].chip.of_node = pdev->dev.of_node;
} }
gpiochip_add(&lpc32xx_gpiochip[i].chip); gpiochip_add_data(&lpc32xx_gpiochip[i].chip,
&lpc32xx_gpiochip[i]);
} }
return 0; return 0;
......
...@@ -97,7 +97,7 @@ struct lp_gpio { ...@@ -97,7 +97,7 @@ struct lp_gpio {
static unsigned long lp_gpio_reg(struct gpio_chip *chip, unsigned offset, static unsigned long lp_gpio_reg(struct gpio_chip *chip, unsigned offset,
int reg) int reg)
{ {
struct lp_gpio *lg = container_of(chip, struct lp_gpio, chip); struct lp_gpio *lg = gpiochip_get_data(chip);
int reg_offset; int reg_offset;
if (reg == LP_CONFIG1 || reg == LP_CONFIG2) if (reg == LP_CONFIG1 || reg == LP_CONFIG2)
...@@ -112,7 +112,7 @@ static unsigned long lp_gpio_reg(struct gpio_chip *chip, unsigned offset, ...@@ -112,7 +112,7 @@ static unsigned long lp_gpio_reg(struct gpio_chip *chip, unsigned offset,
static int lp_gpio_request(struct gpio_chip *chip, unsigned offset) static int lp_gpio_request(struct gpio_chip *chip, unsigned offset)
{ {
struct lp_gpio *lg = container_of(chip, struct lp_gpio, chip); struct lp_gpio *lg = gpiochip_get_data(chip);
unsigned long reg = lp_gpio_reg(chip, offset, LP_CONFIG1); unsigned long reg = lp_gpio_reg(chip, offset, LP_CONFIG1);
unsigned long conf2 = lp_gpio_reg(chip, offset, LP_CONFIG2); unsigned long conf2 = lp_gpio_reg(chip, offset, LP_CONFIG2);
unsigned long acpi_use = lp_gpio_reg(chip, offset, LP_ACPI_OWNED); unsigned long acpi_use = lp_gpio_reg(chip, offset, LP_ACPI_OWNED);
...@@ -137,7 +137,7 @@ static int lp_gpio_request(struct gpio_chip *chip, unsigned offset) ...@@ -137,7 +137,7 @@ static int lp_gpio_request(struct gpio_chip *chip, unsigned offset)
static void lp_gpio_free(struct gpio_chip *chip, unsigned offset) static void lp_gpio_free(struct gpio_chip *chip, unsigned offset)
{ {
struct lp_gpio *lg = container_of(chip, struct lp_gpio, chip); struct lp_gpio *lg = gpiochip_get_data(chip);
unsigned long conf2 = lp_gpio_reg(chip, offset, LP_CONFIG2); unsigned long conf2 = lp_gpio_reg(chip, offset, LP_CONFIG2);
/* disable input sensing */ /* disable input sensing */
...@@ -149,7 +149,7 @@ static void lp_gpio_free(struct gpio_chip *chip, unsigned offset) ...@@ -149,7 +149,7 @@ static void lp_gpio_free(struct gpio_chip *chip, unsigned offset)
static int lp_irq_type(struct irq_data *d, unsigned type) static int lp_irq_type(struct irq_data *d, unsigned type)
{ {
struct gpio_chip *gc = irq_data_get_irq_chip_data(d); struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
struct lp_gpio *lg = container_of(gc, struct lp_gpio, chip); struct lp_gpio *lg = gpiochip_get_data(gc);
u32 hwirq = irqd_to_hwirq(d); u32 hwirq = irqd_to_hwirq(d);
unsigned long flags; unsigned long flags;
u32 value; u32 value;
...@@ -191,7 +191,7 @@ static int lp_gpio_get(struct gpio_chip *chip, unsigned offset) ...@@ -191,7 +191,7 @@ static int lp_gpio_get(struct gpio_chip *chip, unsigned offset)
static void lp_gpio_set(struct gpio_chip *chip, unsigned offset, int value) static void lp_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
{ {
struct lp_gpio *lg = container_of(chip, struct lp_gpio, chip); struct lp_gpio *lg = gpiochip_get_data(chip);
unsigned long reg = lp_gpio_reg(chip, offset, LP_CONFIG1); unsigned long reg = lp_gpio_reg(chip, offset, LP_CONFIG1);
unsigned long flags; unsigned long flags;
...@@ -207,7 +207,7 @@ static void lp_gpio_set(struct gpio_chip *chip, unsigned offset, int value) ...@@ -207,7 +207,7 @@ static void lp_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
static int lp_gpio_direction_input(struct gpio_chip *chip, unsigned offset) static int lp_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
{ {
struct lp_gpio *lg = container_of(chip, struct lp_gpio, chip); struct lp_gpio *lg = gpiochip_get_data(chip);
unsigned long reg = lp_gpio_reg(chip, offset, LP_CONFIG1); unsigned long reg = lp_gpio_reg(chip, offset, LP_CONFIG1);
unsigned long flags; unsigned long flags;
...@@ -221,7 +221,7 @@ static int lp_gpio_direction_input(struct gpio_chip *chip, unsigned offset) ...@@ -221,7 +221,7 @@ static int lp_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
static int lp_gpio_direction_output(struct gpio_chip *chip, static int lp_gpio_direction_output(struct gpio_chip *chip,
unsigned offset, int value) unsigned offset, int value)
{ {
struct lp_gpio *lg = container_of(chip, struct lp_gpio, chip); struct lp_gpio *lg = gpiochip_get_data(chip);
unsigned long reg = lp_gpio_reg(chip, offset, LP_CONFIG1); unsigned long reg = lp_gpio_reg(chip, offset, LP_CONFIG1);
unsigned long flags; unsigned long flags;
...@@ -238,7 +238,7 @@ static void lp_gpio_irq_handler(struct irq_desc *desc) ...@@ -238,7 +238,7 @@ static void lp_gpio_irq_handler(struct irq_desc *desc)
{ {
struct irq_data *data = irq_desc_get_irq_data(desc); struct irq_data *data = irq_desc_get_irq_data(desc);
struct gpio_chip *gc = irq_desc_get_handler_data(desc); struct gpio_chip *gc = irq_desc_get_handler_data(desc);
struct lp_gpio *lg = container_of(gc, struct lp_gpio, chip); struct lp_gpio *lg = gpiochip_get_data(gc);
struct irq_chip *chip = irq_data_get_irq_chip(data); struct irq_chip *chip = irq_data_get_irq_chip(data);
u32 base, pin, mask; u32 base, pin, mask;
unsigned long reg, ena, pending; unsigned long reg, ena, pending;
...@@ -273,7 +273,7 @@ static void lp_irq_mask(struct irq_data *d) ...@@ -273,7 +273,7 @@ static void lp_irq_mask(struct irq_data *d)
static void lp_irq_enable(struct irq_data *d) static void lp_irq_enable(struct irq_data *d)
{ {
struct gpio_chip *gc = irq_data_get_irq_chip_data(d); struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
struct lp_gpio *lg = container_of(gc, struct lp_gpio, chip); struct lp_gpio *lg = gpiochip_get_data(gc);
u32 hwirq = irqd_to_hwirq(d); u32 hwirq = irqd_to_hwirq(d);
unsigned long reg = lp_gpio_reg(&lg->chip, hwirq, LP_INT_ENABLE); unsigned long reg = lp_gpio_reg(&lg->chip, hwirq, LP_INT_ENABLE);
unsigned long flags; unsigned long flags;
...@@ -286,7 +286,7 @@ static void lp_irq_enable(struct irq_data *d) ...@@ -286,7 +286,7 @@ static void lp_irq_enable(struct irq_data *d)
static void lp_irq_disable(struct irq_data *d) static void lp_irq_disable(struct irq_data *d)
{ {
struct gpio_chip *gc = irq_data_get_irq_chip_data(d); struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
struct lp_gpio *lg = container_of(gc, struct lp_gpio, chip); struct lp_gpio *lg = gpiochip_get_data(gc);
u32 hwirq = irqd_to_hwirq(d); u32 hwirq = irqd_to_hwirq(d);
unsigned long reg = lp_gpio_reg(&lg->chip, hwirq, LP_INT_ENABLE); unsigned long reg = lp_gpio_reg(&lg->chip, hwirq, LP_INT_ENABLE);
unsigned long flags; unsigned long flags;
...@@ -368,9 +368,9 @@ static int lp_gpio_probe(struct platform_device *pdev) ...@@ -368,9 +368,9 @@ static int lp_gpio_probe(struct platform_device *pdev)
gc->base = -1; gc->base = -1;
gc->ngpio = LP_NUM_GPIO; gc->ngpio = LP_NUM_GPIO;
gc->can_sleep = false; gc->can_sleep = false;
gc->dev = dev; gc->parent = dev;
ret = gpiochip_add(gc); ret = gpiochip_add_data(gc, lg);
if (ret) { if (ret) {
dev_err(dev, "failed adding lp-gpio chip\n"); dev_err(dev, "failed adding lp-gpio chip\n");
return ret; return ret;
......
...@@ -65,7 +65,6 @@ MODULE_DEVICE_TABLE(i2c, max7300_id); ...@@ -65,7 +65,6 @@ MODULE_DEVICE_TABLE(i2c, max7300_id);
static struct i2c_driver max7300_driver = { static struct i2c_driver max7300_driver = {
.driver = { .driver = {
.name = "max7300", .name = "max7300",
.owner = THIS_MODULE,
}, },
.probe = max7300_probe, .probe = max7300_probe,
.remove = max7300_remove, .remove = max7300_remove,
......
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
static int max7301_direction_input(struct gpio_chip *chip, unsigned offset) static int max7301_direction_input(struct gpio_chip *chip, unsigned offset)
{ {
struct max7301 *ts = container_of(chip, struct max7301, chip); struct max7301 *ts = gpiochip_get_data(chip);
u8 *config; u8 *config;
u8 offset_bits, pin_config; u8 offset_bits, pin_config;
int ret; int ret;
...@@ -92,7 +92,7 @@ static int __max7301_set(struct max7301 *ts, unsigned offset, int value) ...@@ -92,7 +92,7 @@ static int __max7301_set(struct max7301 *ts, unsigned offset, int value)
static int max7301_direction_output(struct gpio_chip *chip, unsigned offset, static int max7301_direction_output(struct gpio_chip *chip, unsigned offset,
int value) int value)
{ {
struct max7301 *ts = container_of(chip, struct max7301, chip); struct max7301 *ts = gpiochip_get_data(chip);
u8 *config; u8 *config;
u8 offset_bits; u8 offset_bits;
int ret; int ret;
...@@ -120,7 +120,7 @@ static int max7301_direction_output(struct gpio_chip *chip, unsigned offset, ...@@ -120,7 +120,7 @@ static int max7301_direction_output(struct gpio_chip *chip, unsigned offset,
static int max7301_get(struct gpio_chip *chip, unsigned offset) static int max7301_get(struct gpio_chip *chip, unsigned offset)
{ {
struct max7301 *ts = container_of(chip, struct max7301, chip); struct max7301 *ts = gpiochip_get_data(chip);
int config, level = -EINVAL; int config, level = -EINVAL;
/* First 4 pins are unused in the controller */ /* First 4 pins are unused in the controller */
...@@ -148,7 +148,7 @@ static int max7301_get(struct gpio_chip *chip, unsigned offset) ...@@ -148,7 +148,7 @@ static int max7301_get(struct gpio_chip *chip, unsigned offset)
static void max7301_set(struct gpio_chip *chip, unsigned offset, int value) static void max7301_set(struct gpio_chip *chip, unsigned offset, int value)
{ {
struct max7301 *ts = container_of(chip, struct max7301, chip); struct max7301 *ts = gpiochip_get_data(chip);
/* First 4 pins are unused in the controller */ /* First 4 pins are unused in the controller */
offset += 4; offset += 4;
...@@ -189,7 +189,7 @@ int __max730x_probe(struct max7301 *ts) ...@@ -189,7 +189,7 @@ int __max730x_probe(struct max7301 *ts)
ts->chip.ngpio = PIN_NUMBER; ts->chip.ngpio = PIN_NUMBER;
ts->chip.can_sleep = true; ts->chip.can_sleep = true;
ts->chip.dev = dev; ts->chip.parent = dev;
ts->chip.owner = THIS_MODULE; ts->chip.owner = THIS_MODULE;
/* /*
...@@ -213,7 +213,7 @@ int __max730x_probe(struct max7301 *ts) ...@@ -213,7 +213,7 @@ int __max730x_probe(struct max7301 *ts)
} }
} }
ret = gpiochip_add(&ts->chip); ret = gpiochip_add_data(&ts->chip, ts);
if (ret) if (ret)
goto exit_destroy; goto exit_destroy;
......
This diff is collapsed.
...@@ -44,14 +44,9 @@ struct mb86s70_gpio_chip { ...@@ -44,14 +44,9 @@ struct mb86s70_gpio_chip {
spinlock_t lock; spinlock_t lock;
}; };
static inline struct mb86s70_gpio_chip *chip_to_mb86s70(struct gpio_chip *gc)
{
return container_of(gc, struct mb86s70_gpio_chip, gc);
}
static int mb86s70_gpio_request(struct gpio_chip *gc, unsigned gpio) static int mb86s70_gpio_request(struct gpio_chip *gc, unsigned gpio)
{ {
struct mb86s70_gpio_chip *gchip = chip_to_mb86s70(gc); struct mb86s70_gpio_chip *gchip = gpiochip_get_data(gc);
unsigned long flags; unsigned long flags;
u32 val; u32 val;
...@@ -73,7 +68,7 @@ static int mb86s70_gpio_request(struct gpio_chip *gc, unsigned gpio) ...@@ -73,7 +68,7 @@ static int mb86s70_gpio_request(struct gpio_chip *gc, unsigned gpio)
static void mb86s70_gpio_free(struct gpio_chip *gc, unsigned gpio) static void mb86s70_gpio_free(struct gpio_chip *gc, unsigned gpio)
{ {
struct mb86s70_gpio_chip *gchip = chip_to_mb86s70(gc); struct mb86s70_gpio_chip *gchip = gpiochip_get_data(gc);
unsigned long flags; unsigned long flags;
u32 val; u32 val;
...@@ -88,7 +83,7 @@ static void mb86s70_gpio_free(struct gpio_chip *gc, unsigned gpio) ...@@ -88,7 +83,7 @@ static void mb86s70_gpio_free(struct gpio_chip *gc, unsigned gpio)
static int mb86s70_gpio_direction_input(struct gpio_chip *gc, unsigned gpio) static int mb86s70_gpio_direction_input(struct gpio_chip *gc, unsigned gpio)
{ {
struct mb86s70_gpio_chip *gchip = chip_to_mb86s70(gc); struct mb86s70_gpio_chip *gchip = gpiochip_get_data(gc);
unsigned long flags; unsigned long flags;
unsigned char val; unsigned char val;
...@@ -106,7 +101,7 @@ static int mb86s70_gpio_direction_input(struct gpio_chip *gc, unsigned gpio) ...@@ -106,7 +101,7 @@ static int mb86s70_gpio_direction_input(struct gpio_chip *gc, unsigned gpio)
static int mb86s70_gpio_direction_output(struct gpio_chip *gc, static int mb86s70_gpio_direction_output(struct gpio_chip *gc,
unsigned gpio, int value) unsigned gpio, int value)
{ {
struct mb86s70_gpio_chip *gchip = chip_to_mb86s70(gc); struct mb86s70_gpio_chip *gchip = gpiochip_get_data(gc);
unsigned long flags; unsigned long flags;
unsigned char val; unsigned char val;
...@@ -130,14 +125,14 @@ static int mb86s70_gpio_direction_output(struct gpio_chip *gc, ...@@ -130,14 +125,14 @@ static int mb86s70_gpio_direction_output(struct gpio_chip *gc,
static int mb86s70_gpio_get(struct gpio_chip *gc, unsigned gpio) static int mb86s70_gpio_get(struct gpio_chip *gc, unsigned gpio)
{ {
struct mb86s70_gpio_chip *gchip = chip_to_mb86s70(gc); struct mb86s70_gpio_chip *gchip = gpiochip_get_data(gc);
return !!(readl(gchip->base + PDR(gpio)) & OFFSET(gpio)); return !!(readl(gchip->base + PDR(gpio)) & OFFSET(gpio));
} }
static void mb86s70_gpio_set(struct gpio_chip *gc, unsigned gpio, int value) static void mb86s70_gpio_set(struct gpio_chip *gc, unsigned gpio, int value)
{ {
struct mb86s70_gpio_chip *gchip = chip_to_mb86s70(gc); struct mb86s70_gpio_chip *gchip = gpiochip_get_data(gc);
unsigned long flags; unsigned long flags;
unsigned char val; unsigned char val;
...@@ -187,12 +182,12 @@ static int mb86s70_gpio_probe(struct platform_device *pdev) ...@@ -187,12 +182,12 @@ static int mb86s70_gpio_probe(struct platform_device *pdev)
gchip->gc.label = dev_name(&pdev->dev); gchip->gc.label = dev_name(&pdev->dev);
gchip->gc.ngpio = 32; gchip->gc.ngpio = 32;
gchip->gc.owner = THIS_MODULE; gchip->gc.owner = THIS_MODULE;
gchip->gc.dev = &pdev->dev; gchip->gc.parent = &pdev->dev;
gchip->gc.base = -1; gchip->gc.base = -1;
platform_set_drvdata(pdev, gchip); platform_set_drvdata(pdev, gchip);
ret = gpiochip_add(&gchip->gc); ret = gpiochip_add_data(&gchip->gc, gchip);
if (ret) { if (ret) {
dev_err(&pdev->dev, "couldn't register gpio driver\n"); dev_err(&pdev->dev, "couldn't register gpio driver\n");
clk_disable_unprepare(gchip->clk); clk_disable_unprepare(gchip->clk);
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -545,7 +545,7 @@ static int tegra_gpio_probe(struct platform_device *pdev) ...@@ -545,7 +545,7 @@ static int tegra_gpio_probe(struct platform_device *pdev)
tegra_gpio_chip.of_node = pdev->dev.of_node; tegra_gpio_chip.of_node = pdev->dev.of_node;
ret = gpiochip_add(&tegra_gpio_chip); ret = gpiochip_add_data(&tegra_gpio_chip, NULL);
if (ret < 0) { if (ret < 0) {
irq_domain_remove(irq_domain); irq_domain_remove(irq_domain);
return ret; return ret;
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment