Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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
...

+2693 -2506
+1
Documentation/devicetree/bindings/gpio/gpio-pca953x.txt
··· 25 25 ti,tca6416 26 26 ti,tca6424 27 27 ti,tca9539 28 + onsemi,pca9654 28 29 exar,xra1202 29 30 30 31 Example:
+2 -1
Documentation/devicetree/bindings/gpio/gpio-sx150x.txt
··· 5 5 6 6 - compatible: should be "semtech,sx1506q", 7 7 "semtech,sx1508q", 8 - "semtech,sx1509q". 8 + "semtech,sx1509q", 9 + "semtech,sx1502q". 9 10 10 11 - reg: The I2C slave address for this device. 11 12
+16
Documentation/devicetree/bindings/gpio/gpio-tps65086.txt
··· 1 + * TPS65086 GPO Controller bindings 2 + 3 + Required properties: 4 + - compatible : Should be "ti,tps65086-gpio". 5 + - gpio-controller : Marks the device node as a GPIO Controller. 6 + - #gpio-cells : Should be two. The first cell is the pin number 7 + and the second cell is used to specify flags. 8 + See ../gpio/gpio.txt for possible values. 9 + 10 + Example: 11 + 12 + gpio4: gpio { 13 + compatible = "ti,tps65086-gpio"; 14 + gpio-controller; 15 + #gpio-cells = <2>; 16 + };
+14 -1
MAINTAINERS
··· 240 240 S: Maintained 241 241 F: drivers/hwmon/abituguru3.c 242 242 243 + ACCES 104-IDI-48 GPIO DRIVER 244 + M: "William Breathitt Gray" <vilhelm.gray@gmail.com> 245 + L: linux-gpio@vger.kernel.org 246 + S: Maintained 247 + F: drivers/gpio/gpio-104-idi-48.c 248 + 243 249 ACCES 104-IDIO-16 GPIO DRIVER 244 250 M: "William Breathitt Gray" <vilhelm.gray@gmail.com> 245 251 L: linux-gpio@vger.kernel.org ··· 7827 7821 F: arch/arm/*omap*/usb* 7828 7822 7829 7823 OMAP GPIO DRIVER 7830 - M: Javier Martinez Canillas <javier@dowhile0.org> 7824 + M: Grygorii Strashko <grygorii.strashko@ti.com> 7831 7825 M: Santosh Shilimkar <ssantosh@kernel.org> 7832 7826 M: Kevin Hilman <khilman@deeprootsystems.com> 7833 7827 L: linux-omap@vger.kernel.org 7834 7828 S: Maintained 7829 + F: Documentation/devicetree/bindings/gpio/gpio-omap.txt 7835 7830 F: drivers/gpio/gpio-omap.c 7836 7831 7837 7832 OMAP/NEWFLOW NANOBONE MACHINE SUPPORT ··· 8691 8684 F: include/sound/pxa2xx-lib.h 8692 8685 F: sound/arm/pxa* 8693 8686 F: sound/soc/pxa/ 8687 + 8688 + PXA GPIO DRIVER 8689 + M: Robert Jarzmik <robert.jarzmik@free.fr> 8690 + L: linux-gpio@vger.kernel.org 8691 + S: Maintained 8692 + F: drivers/gpio/gpio-pxa.c 8694 8693 8695 8694 PXA3xx NAND FLASH DRIVER 8696 8695 M: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
+1 -1
arch/arm/mach-clps711x/board-autcpu12.c
··· 31 31 #include <linux/mtd/partitions.h> 32 32 #include <linux/mtd/nand-gpio.h> 33 33 #include <linux/platform_device.h> 34 - #include <linux/basic_mmio_gpio.h> 34 + #include <linux/gpio/driver.h> 35 35 36 36 #include <mach/hardware.h> 37 37 #include <asm/sizes.h>
+1 -1
arch/arm/mach-clps711x/board-p720t.c
··· 28 28 #include <linux/leds.h> 29 29 #include <linux/sizes.h> 30 30 #include <linux/backlight.h> 31 - #include <linux/basic_mmio_gpio.h> 31 + #include <linux/gpio/driver.h> 32 32 #include <linux/platform_device.h> 33 33 #include <linux/mtd/partitions.h> 34 34 #include <linux/mtd/nand-gpio.h>
+1 -1
arch/arm/mach-imx/mach-mx21ads.c
··· 17 17 #include <linux/platform_device.h> 18 18 #include <linux/mtd/mtd.h> 19 19 #include <linux/mtd/physmap.h> 20 - #include <linux/basic_mmio_gpio.h> 20 + #include <linux/gpio/driver.h> 21 21 #include <linux/gpio.h> 22 22 #include <linux/regulator/fixed.h> 23 23 #include <linux/regulator/machine.h>
+1 -1
arch/arm/mach-omap1/board-ams-delta.c
··· 11 11 * it under the terms of the GNU General Public License version 2 as 12 12 * published by the Free Software Foundation. 13 13 */ 14 - #include <linux/basic_mmio_gpio.h> 14 + #include <linux/gpio/driver.h> 15 15 #include <linux/gpio.h> 16 16 #include <linux/kernel.h> 17 17 #include <linux/init.h>
+1 -1
arch/arm/mach-s3c64xx/mach-crag6410.c
··· 29 29 #include <linux/pwm_backlight.h> 30 30 #include <linux/dm9000.h> 31 31 #include <linux/gpio_keys.h> 32 - #include <linux/basic_mmio_gpio.h> 32 + #include <linux/gpio/driver.h> 33 33 #include <linux/spi/spi.h> 34 34 35 35 #include <linux/platform_data/pca953x.h>
+7 -7
arch/avr32/mach-at32ap/pio.c
··· 203 203 204 204 static int direction_input(struct gpio_chip *chip, unsigned offset) 205 205 { 206 - struct pio_device *pio = container_of(chip, struct pio_device, chip); 206 + struct pio_device *pio = gpiochip_get_data(chip); 207 207 u32 mask = 1 << offset; 208 208 209 209 if (!(pio_readl(pio, PSR) & mask)) ··· 215 215 216 216 static int gpio_get(struct gpio_chip *chip, unsigned offset) 217 217 { 218 - struct pio_device *pio = container_of(chip, struct pio_device, chip); 218 + struct pio_device *pio = gpiochip_get_data(chip); 219 219 220 220 return (pio_readl(pio, PDSR) >> offset) & 1; 221 221 } ··· 224 224 225 225 static int direction_output(struct gpio_chip *chip, unsigned offset, int value) 226 226 { 227 - struct pio_device *pio = container_of(chip, struct pio_device, chip); 227 + struct pio_device *pio = gpiochip_get_data(chip); 228 228 u32 mask = 1 << offset; 229 229 230 230 if (!(pio_readl(pio, PSR) & mask)) ··· 237 237 238 238 static void gpio_set(struct gpio_chip *chip, unsigned offset, int value) 239 239 { 240 - struct pio_device *pio = container_of(chip, struct pio_device, chip); 240 + struct pio_device *pio = gpiochip_get_data(chip); 241 241 u32 mask = 1 << offset; 242 242 243 243 if (value) ··· 335 335 */ 336 336 static void pio_bank_show(struct seq_file *s, struct gpio_chip *chip) 337 337 { 338 - struct pio_device *pio = container_of(chip, struct pio_device, chip); 338 + struct pio_device *pio = gpiochip_get_data(chip); 339 339 u32 psr, osr, imr, pdsr, pusr, ifsr, mdsr; 340 340 unsigned i; 341 341 u32 mask; ··· 397 397 pio->chip.label = pio->name; 398 398 pio->chip.base = pdev->id * 32; 399 399 pio->chip.ngpio = 32; 400 - pio->chip.dev = &pdev->dev; 400 + pio->chip.parent = &pdev->dev; 401 401 pio->chip.owner = THIS_MODULE; 402 402 403 403 pio->chip.direction_input = direction_input; ··· 406 406 pio->chip.set = gpio_set; 407 407 pio->chip.dbg_show = pio_bank_show; 408 408 409 - gpiochip_add(&pio->chip); 409 + gpiochip_add_data(&pio->chip, pio); 410 410 411 411 gpio_irq_setup(pio, irq, gpio_irq_base); 412 412
+10 -15
drivers/bcma/driver_gpio.c
··· 17 17 18 18 #define BCMA_GPIO_MAX_PINS 32 19 19 20 - static inline struct bcma_drv_cc *bcma_gpio_get_cc(struct gpio_chip *chip) 21 - { 22 - return container_of(chip, struct bcma_drv_cc, gpio); 23 - } 24 - 25 20 static int bcma_gpio_get_value(struct gpio_chip *chip, unsigned gpio) 26 21 { 27 - struct bcma_drv_cc *cc = bcma_gpio_get_cc(chip); 22 + struct bcma_drv_cc *cc = gpiochip_get_data(chip); 28 23 29 24 return !!bcma_chipco_gpio_in(cc, 1 << gpio); 30 25 } ··· 27 32 static void bcma_gpio_set_value(struct gpio_chip *chip, unsigned gpio, 28 33 int value) 29 34 { 30 - struct bcma_drv_cc *cc = bcma_gpio_get_cc(chip); 35 + struct bcma_drv_cc *cc = gpiochip_get_data(chip); 31 36 32 37 bcma_chipco_gpio_out(cc, 1 << gpio, value ? 1 << gpio : 0); 33 38 } 34 39 35 40 static int bcma_gpio_direction_input(struct gpio_chip *chip, unsigned gpio) 36 41 { 37 - struct bcma_drv_cc *cc = bcma_gpio_get_cc(chip); 42 + struct bcma_drv_cc *cc = gpiochip_get_data(chip); 38 43 39 44 bcma_chipco_gpio_outen(cc, 1 << gpio, 0); 40 45 return 0; ··· 43 48 static int bcma_gpio_direction_output(struct gpio_chip *chip, unsigned gpio, 44 49 int value) 45 50 { 46 - struct bcma_drv_cc *cc = bcma_gpio_get_cc(chip); 51 + struct bcma_drv_cc *cc = gpiochip_get_data(chip); 47 52 48 53 bcma_chipco_gpio_outen(cc, 1 << gpio, 1 << gpio); 49 54 bcma_chipco_gpio_out(cc, 1 << gpio, value ? 1 << gpio : 0); ··· 52 57 53 58 static int bcma_gpio_request(struct gpio_chip *chip, unsigned gpio) 54 59 { 55 - struct bcma_drv_cc *cc = bcma_gpio_get_cc(chip); 60 + struct bcma_drv_cc *cc = gpiochip_get_data(chip); 56 61 57 62 bcma_chipco_gpio_control(cc, 1 << gpio, 0); 58 63 /* clear pulldown */ ··· 65 70 66 71 static void bcma_gpio_free(struct gpio_chip *chip, unsigned gpio) 67 72 { 68 - struct bcma_drv_cc *cc = bcma_gpio_get_cc(chip); 73 + struct bcma_drv_cc *cc = gpiochip_get_data(chip); 69 74 70 75 /* clear pullup */ 71 76 bcma_chipco_gpio_pullup(cc, 1 << gpio, 0); ··· 76 81 static void bcma_gpio_irq_unmask(struct irq_data *d) 77 82 { 78 83 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 79 - struct bcma_drv_cc *cc = bcma_gpio_get_cc(gc); 84 + struct bcma_drv_cc *cc = gpiochip_get_data(gc); 80 85 int gpio = irqd_to_hwirq(d); 81 86 u32 val = bcma_chipco_gpio_in(cc, BIT(gpio)); 82 87 ··· 87 92 static void bcma_gpio_irq_mask(struct irq_data *d) 88 93 { 89 94 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 90 - struct bcma_drv_cc *cc = bcma_gpio_get_cc(gc); 95 + struct bcma_drv_cc *cc = gpiochip_get_data(gc); 91 96 int gpio = irqd_to_hwirq(d); 92 97 93 98 bcma_chipco_gpio_intmask(cc, BIT(gpio), 0); ··· 183 188 chip->direction_input = bcma_gpio_direction_input; 184 189 chip->direction_output = bcma_gpio_direction_output; 185 190 chip->owner = THIS_MODULE; 186 - chip->dev = bcma_bus_get_host_dev(bus); 191 + chip->parent = bcma_bus_get_host_dev(bus); 187 192 #if IS_BUILTIN(CONFIG_OF) 188 193 if (cc->core->bus->hosttype == BCMA_HOSTTYPE_SOC) 189 194 chip->of_node = cc->core->dev.of_node; ··· 211 216 else 212 217 chip->base = -1; 213 218 214 - err = gpiochip_add(chip); 219 + err = gpiochip_add_data(chip, cc); 215 220 if (err) 216 221 return err; 217 222
+21 -11
drivers/gpio/Kconfig
··· 134 134 135 135 config GPIO_BRCMSTB 136 136 tristate "BRCMSTB GPIO support" 137 - default y if ARCH_BRCMSTB 138 - depends on OF_GPIO && (ARCH_BRCMSTB || COMPILE_TEST) 137 + default y if (ARCH_BRCMSTB || BMIPS_GENERIC) 138 + depends on OF_GPIO && (ARCH_BRCMSTB || BMIPS_GENERIC || COMPILE_TEST) 139 139 select GPIO_GENERIC 140 140 select GPIOLIB_IRQCHIP 141 141 help ··· 496 496 497 497 config GPIO_104_IDIO_16 498 498 tristate "ACCES 104-IDIO-16 GPIO support" 499 + select GPIOLIB_IRQCHIP 499 500 help 500 - Enables GPIO support for the ACCES 104-IDIO-16 family. 501 + Enables GPIO support for the ACCES 104-IDIO-16 family. The base port 502 + address for the device may be set via the idio_16_base module 503 + parameter. The interrupt line number for the device may be set via the 504 + idio_16_irq module parameter. 505 + 506 + config GPIO_104_IDI_48 507 + tristate "ACCES 104-IDI-48 GPIO support" 508 + select GPIOLIB_IRQCHIP 509 + help 510 + Enables GPIO support for the ACCES 104-IDI-48 family. The base port 511 + address for the device may be configured via the idi_48_base module 512 + parameter. The interrupt line number for the device may be configured 513 + via the idi_48_irq module parameter. 501 514 502 515 config GPIO_F7188X 503 516 tristate "F71869, F71869A, F71882FG and F71889F GPIO support" ··· 920 907 921 908 config GPIO_AMD8111 922 909 tristate "AMD 8111 GPIO driver" 923 - depends on PCI 924 910 help 925 911 The AMD 8111 south bridge contains 32 GPIO pins which can be used. 926 912 ··· 931 919 932 920 config GPIO_BT8XX 933 921 tristate "BT8XX GPIO abuser" 934 - depends on PCI && VIDEO_BT848=n 922 + depends on VIDEO_BT848=n 935 923 help 936 924 The BT8xx frame grabber chip has 24 GPIO pins that can be abused 937 925 as a cheap PCI GPIO card. ··· 947 935 948 936 config GPIO_INTEL_MID 949 937 bool "Intel Mid GPIO support" 950 - depends on PCI && X86 938 + depends on X86 951 939 select GPIOLIB_IRQCHIP 952 940 help 953 941 Say Y here to support Intel Mid GPIO. 954 942 955 943 config GPIO_ML_IOH 956 944 tristate "OKI SEMICONDUCTOR ML7213 IOH GPIO support" 957 - depends on PCI 958 945 select GENERIC_IRQ_CHIP 959 946 help 960 947 ML7213 is companion chip for Intel Atom E6xx series. ··· 963 952 964 953 config GPIO_PCH 965 954 tristate "Intel EG20T PCH/LAPIS Semiconductor IOH(ML7223/ML7831) GPIO" 966 - depends on PCI && (X86_32 || COMPILE_TEST) 955 + depends on X86_32 || MIPS || COMPILE_TEST 967 956 select GENERIC_IRQ_CHIP 968 957 help 969 958 This driver is for PCH(Platform controller Hub) GPIO of Intel Topcliff ··· 979 968 980 969 config GPIO_RDC321X 981 970 tristate "RDC R-321x GPIO support" 982 - depends on PCI 983 971 select MFD_CORE 984 972 select MFD_RDC321X 985 973 help ··· 987 977 988 978 config GPIO_SODAVILLE 989 979 bool "Intel Sodaville GPIO support" 990 - depends on X86 && PCI && OF 980 + depends on X86 && OF 991 981 select GPIO_GENERIC 992 982 select GENERIC_IRQ_CHIP 993 983 help ··· 1038 1028 1039 1029 config GPIO_VIPERBOARD 1040 1030 tristate "Viperboard GPIO a & b support" 1041 - depends on MFD_VIPERBOARD && USB 1031 + depends on MFD_VIPERBOARD 1042 1032 help 1043 1033 Say yes here to access the GPIO signals of Nano River 1044 1034 Technologies Viperboard. There are two GPIO chips on the
+1
drivers/gpio/Makefile
··· 13 13 obj-$(CONFIG_GPIO_GENERIC) += gpio-generic.o 14 14 15 15 obj-$(CONFIG_GPIO_104_IDIO_16) += gpio-104-idio-16.o 16 + obj-$(CONFIG_GPIO_104_IDI_48) += gpio-104-idi-48.o 16 17 obj-$(CONFIG_GPIO_74X164) += gpio-74x164.o 17 18 obj-$(CONFIG_GPIO_74XX_MMIO) += gpio-74xx-mmio.o 18 19 obj-$(CONFIG_GPIO_ADNP) += gpio-adnp.o
+343
drivers/gpio/gpio-104-idi-48.c
··· 1 + /* 2 + * GPIO driver for the ACCES 104-IDI-48 family 3 + * Copyright (C) 2015 William Breathitt Gray 4 + * 5 + * This program is free software; you can redistribute it and/or modify 6 + * it under the terms of the GNU General Public License, version 2, as 7 + * published by the Free Software Foundation. 8 + * 9 + * This program is distributed in the hope that it will be useful, but 10 + * WITHOUT ANY WARRANTY; without even the implied warranty of 11 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 + * General Public License for more details. 13 + */ 14 + #include <linux/bitops.h> 15 + #include <linux/device.h> 16 + #include <linux/errno.h> 17 + #include <linux/gpio/driver.h> 18 + #include <linux/io.h> 19 + #include <linux/ioport.h> 20 + #include <linux/interrupt.h> 21 + #include <linux/irqdesc.h> 22 + #include <linux/kernel.h> 23 + #include <linux/module.h> 24 + #include <linux/moduleparam.h> 25 + #include <linux/platform_device.h> 26 + #include <linux/spinlock.h> 27 + 28 + static unsigned idi_48_base; 29 + module_param(idi_48_base, uint, 0); 30 + MODULE_PARM_DESC(idi_48_base, "ACCES 104-IDI-48 base address"); 31 + static unsigned idi_48_irq; 32 + module_param(idi_48_irq, uint, 0); 33 + MODULE_PARM_DESC(idi_48_irq, "ACCES 104-IDI-48 interrupt line number"); 34 + 35 + /** 36 + * struct idi_48_gpio - GPIO device private data structure 37 + * @chip: instance of the gpio_chip 38 + * @lock: synchronization lock to prevent I/O race conditions 39 + * @ack_lock: synchronization lock to prevent IRQ handler race conditions 40 + * @irq_mask: input bits affected by interrupts 41 + * @base: base port address of the GPIO device 42 + * @extent: extent of port address region of the GPIO device 43 + * @irq: Interrupt line number 44 + * @cos_enb: Change-Of-State IRQ enable boundaries mask 45 + */ 46 + struct idi_48_gpio { 47 + struct gpio_chip chip; 48 + spinlock_t lock; 49 + spinlock_t ack_lock; 50 + unsigned char irq_mask[6]; 51 + unsigned base; 52 + unsigned extent; 53 + unsigned irq; 54 + unsigned char cos_enb; 55 + }; 56 + 57 + static int idi_48_gpio_get_direction(struct gpio_chip *chip, unsigned offset) 58 + { 59 + return 1; 60 + } 61 + 62 + static int idi_48_gpio_direction_input(struct gpio_chip *chip, unsigned offset) 63 + { 64 + return 0; 65 + } 66 + 67 + static int idi_48_gpio_get(struct gpio_chip *chip, unsigned offset) 68 + { 69 + struct idi_48_gpio *const idi48gpio = gpiochip_get_data(chip); 70 + unsigned i; 71 + const unsigned register_offset[6] = { 0, 1, 2, 4, 5, 6 }; 72 + unsigned base_offset; 73 + unsigned mask; 74 + 75 + for (i = 0; i < 48; i += 8) 76 + if (offset < i + 8) { 77 + base_offset = register_offset[i / 8]; 78 + mask = BIT(offset - i); 79 + 80 + return !!(inb(idi48gpio->base + base_offset) & mask); 81 + } 82 + 83 + /* The following line should never execute since offset < 48 */ 84 + return 0; 85 + } 86 + 87 + static void idi_48_irq_ack(struct irq_data *data) 88 + { 89 + } 90 + 91 + static void idi_48_irq_mask(struct irq_data *data) 92 + { 93 + struct gpio_chip *chip = irq_data_get_irq_chip_data(data); 94 + struct idi_48_gpio *const idi48gpio = gpiochip_get_data(chip); 95 + const unsigned offset = irqd_to_hwirq(data); 96 + unsigned i; 97 + unsigned mask; 98 + unsigned boundary; 99 + unsigned long flags; 100 + 101 + for (i = 0; i < 48; i += 8) 102 + if (offset < i + 8) { 103 + mask = BIT(offset - i); 104 + boundary = i / 8; 105 + 106 + idi48gpio->irq_mask[boundary] &= ~mask; 107 + 108 + if (!idi48gpio->irq_mask[boundary]) { 109 + idi48gpio->cos_enb &= ~BIT(boundary); 110 + 111 + spin_lock_irqsave(&idi48gpio->lock, flags); 112 + 113 + outb(idi48gpio->cos_enb, idi48gpio->base + 7); 114 + 115 + spin_unlock_irqrestore(&idi48gpio->lock, flags); 116 + } 117 + 118 + return; 119 + } 120 + } 121 + 122 + static void idi_48_irq_unmask(struct irq_data *data) 123 + { 124 + struct gpio_chip *chip = irq_data_get_irq_chip_data(data); 125 + struct idi_48_gpio *const idi48gpio = gpiochip_get_data(chip); 126 + const unsigned offset = irqd_to_hwirq(data); 127 + unsigned i; 128 + unsigned mask; 129 + unsigned boundary; 130 + unsigned prev_irq_mask; 131 + unsigned long flags; 132 + 133 + for (i = 0; i < 48; i += 8) 134 + if (offset < i + 8) { 135 + mask = BIT(offset - i); 136 + boundary = i / 8; 137 + prev_irq_mask = idi48gpio->irq_mask[boundary]; 138 + 139 + idi48gpio->irq_mask[boundary] |= mask; 140 + 141 + if (!prev_irq_mask) { 142 + idi48gpio->cos_enb |= BIT(boundary); 143 + 144 + spin_lock_irqsave(&idi48gpio->lock, flags); 145 + 146 + outb(idi48gpio->cos_enb, idi48gpio->base + 7); 147 + 148 + spin_unlock_irqrestore(&idi48gpio->lock, flags); 149 + } 150 + 151 + return; 152 + } 153 + } 154 + 155 + static int idi_48_irq_set_type(struct irq_data *data, unsigned flow_type) 156 + { 157 + /* The only valid irq types are none and both-edges */ 158 + if (flow_type != IRQ_TYPE_NONE && 159 + (flow_type & IRQ_TYPE_EDGE_BOTH) != IRQ_TYPE_EDGE_BOTH) 160 + return -EINVAL; 161 + 162 + return 0; 163 + } 164 + 165 + static struct irq_chip idi_48_irqchip = { 166 + .name = "104-idi-48", 167 + .irq_ack = idi_48_irq_ack, 168 + .irq_mask = idi_48_irq_mask, 169 + .irq_unmask = idi_48_irq_unmask, 170 + .irq_set_type = idi_48_irq_set_type 171 + }; 172 + 173 + static irqreturn_t idi_48_irq_handler(int irq, void *dev_id) 174 + { 175 + struct idi_48_gpio *const idi48gpio = dev_id; 176 + unsigned long cos_status; 177 + unsigned long boundary; 178 + unsigned long irq_mask; 179 + unsigned long bit_num; 180 + unsigned long gpio; 181 + struct gpio_chip *const chip = &idi48gpio->chip; 182 + 183 + spin_lock(&idi48gpio->ack_lock); 184 + 185 + spin_lock(&idi48gpio->lock); 186 + 187 + cos_status = inb(idi48gpio->base + 7); 188 + 189 + spin_unlock(&idi48gpio->lock); 190 + 191 + /* IRQ Status (bit 6) is active low (0 = IRQ generated by device) */ 192 + if (cos_status & BIT(6)) { 193 + spin_unlock(&idi48gpio->ack_lock); 194 + return IRQ_NONE; 195 + } 196 + 197 + /* Bit 0-5 indicate which Change-Of-State boundary triggered the IRQ */ 198 + cos_status &= 0x3F; 199 + 200 + for_each_set_bit(boundary, &cos_status, 6) { 201 + irq_mask = idi48gpio->irq_mask[boundary]; 202 + 203 + for_each_set_bit(bit_num, &irq_mask, 8) { 204 + gpio = bit_num + boundary * 8; 205 + 206 + generic_handle_irq(irq_find_mapping(chip->irqdomain, 207 + gpio)); 208 + } 209 + } 210 + 211 + spin_unlock(&idi48gpio->ack_lock); 212 + 213 + return IRQ_HANDLED; 214 + } 215 + 216 + static int __init idi_48_probe(struct platform_device *pdev) 217 + { 218 + struct device *dev = &pdev->dev; 219 + struct idi_48_gpio *idi48gpio; 220 + const unsigned base = idi_48_base; 221 + const unsigned extent = 8; 222 + const char *const name = dev_name(dev); 223 + int err; 224 + const unsigned irq = idi_48_irq; 225 + 226 + idi48gpio = devm_kzalloc(dev, sizeof(*idi48gpio), GFP_KERNEL); 227 + if (!idi48gpio) 228 + return -ENOMEM; 229 + 230 + if (!request_region(base, extent, name)) { 231 + dev_err(dev, "Unable to lock %s port addresses (0x%X-0x%X)\n", 232 + name, base, base + extent); 233 + err = -EBUSY; 234 + goto err_lock_io_port; 235 + } 236 + 237 + idi48gpio->chip.label = name; 238 + idi48gpio->chip.parent = dev; 239 + idi48gpio->chip.owner = THIS_MODULE; 240 + idi48gpio->chip.base = -1; 241 + idi48gpio->chip.ngpio = 48; 242 + idi48gpio->chip.get_direction = idi_48_gpio_get_direction; 243 + idi48gpio->chip.direction_input = idi_48_gpio_direction_input; 244 + idi48gpio->chip.get = idi_48_gpio_get; 245 + idi48gpio->base = base; 246 + idi48gpio->extent = extent; 247 + idi48gpio->irq = irq; 248 + 249 + spin_lock_init(&idi48gpio->lock); 250 + 251 + dev_set_drvdata(dev, idi48gpio); 252 + 253 + err = gpiochip_add_data(&idi48gpio->chip, idi48gpio); 254 + if (err) { 255 + dev_err(dev, "GPIO registering failed (%d)\n", err); 256 + goto err_gpio_register; 257 + } 258 + 259 + /* Disable IRQ by default */ 260 + outb(0, base + 7); 261 + inb(base + 7); 262 + 263 + err = gpiochip_irqchip_add(&idi48gpio->chip, &idi_48_irqchip, 0, 264 + handle_edge_irq, IRQ_TYPE_NONE); 265 + if (err) { 266 + dev_err(dev, "Could not add irqchip (%d)\n", err); 267 + goto err_gpiochip_irqchip_add; 268 + } 269 + 270 + err = request_irq(irq, idi_48_irq_handler, 0, name, idi48gpio); 271 + if (err) { 272 + dev_err(dev, "IRQ handler registering failed (%d)\n", err); 273 + goto err_request_irq; 274 + } 275 + 276 + return 0; 277 + 278 + err_request_irq: 279 + err_gpiochip_irqchip_add: 280 + gpiochip_remove(&idi48gpio->chip); 281 + err_gpio_register: 282 + release_region(base, extent); 283 + err_lock_io_port: 284 + return err; 285 + } 286 + 287 + static int idi_48_remove(struct platform_device *pdev) 288 + { 289 + struct idi_48_gpio *const idi48gpio = platform_get_drvdata(pdev); 290 + 291 + free_irq(idi48gpio->irq, idi48gpio); 292 + gpiochip_remove(&idi48gpio->chip); 293 + release_region(idi48gpio->base, idi48gpio->extent); 294 + 295 + return 0; 296 + } 297 + 298 + static struct platform_device *idi_48_device; 299 + 300 + static struct platform_driver idi_48_driver = { 301 + .driver = { 302 + .name = "104-idi-48" 303 + }, 304 + .remove = idi_48_remove 305 + }; 306 + 307 + static void __exit idi_48_exit(void) 308 + { 309 + platform_device_unregister(idi_48_device); 310 + platform_driver_unregister(&idi_48_driver); 311 + } 312 + 313 + static int __init idi_48_init(void) 314 + { 315 + int err; 316 + 317 + idi_48_device = platform_device_alloc(idi_48_driver.driver.name, -1); 318 + if (!idi_48_device) 319 + return -ENOMEM; 320 + 321 + err = platform_device_add(idi_48_device); 322 + if (err) 323 + goto err_platform_device; 324 + 325 + err = platform_driver_probe(&idi_48_driver, idi_48_probe); 326 + if (err) 327 + goto err_platform_driver; 328 + 329 + return 0; 330 + 331 + err_platform_driver: 332 + platform_device_del(idi_48_device); 333 + err_platform_device: 334 + platform_device_put(idi_48_device); 335 + return err; 336 + } 337 + 338 + module_init(idi_48_init); 339 + module_exit(idi_48_exit); 340 + 341 + MODULE_AUTHOR("William Breathitt Gray <vilhelm.gray@gmail.com>"); 342 + MODULE_DESCRIPTION("ACCES 104-IDI-48 GPIO driver"); 343 + MODULE_LICENSE("GPL");
+130 -26
drivers/gpio/gpio-104-idio-16.c
··· 11 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 12 * General Public License for more details. 13 13 */ 14 + #include <linux/bitops.h> 14 15 #include <linux/device.h> 15 16 #include <linux/errno.h> 16 17 #include <linux/gpio/driver.h> 17 18 #include <linux/io.h> 18 19 #include <linux/ioport.h> 20 + #include <linux/interrupt.h> 21 + #include <linux/irqdesc.h> 19 22 #include <linux/kernel.h> 20 23 #include <linux/module.h> 21 24 #include <linux/moduleparam.h> ··· 28 25 static unsigned idio_16_base; 29 26 module_param(idio_16_base, uint, 0); 30 27 MODULE_PARM_DESC(idio_16_base, "ACCES 104-IDIO-16 base address"); 28 + static unsigned idio_16_irq; 29 + module_param(idio_16_irq, uint, 0); 30 + MODULE_PARM_DESC(idio_16_irq, "ACCES 104-IDIO-16 interrupt line number"); 31 31 32 32 /** 33 33 * struct idio_16_gpio - GPIO device private data structure 34 34 * @chip: instance of the gpio_chip 35 - * @lock: synchronization lock to prevent gpio_set race conditions 35 + * @lock: synchronization lock to prevent I/O race conditions 36 + * @irq_mask: I/O bits affected by interrupts 36 37 * @base: base port address of the GPIO device 37 38 * @extent: extent of port address region of the GPIO device 39 + * @irq: Interrupt line number 38 40 * @out_state: output bits state 39 41 */ 40 42 struct idio_16_gpio { 41 43 struct gpio_chip chip; 42 44 spinlock_t lock; 45 + unsigned long irq_mask; 43 46 unsigned base; 44 47 unsigned extent; 48 + unsigned irq; 45 49 unsigned out_state; 46 50 }; 47 51 ··· 72 62 return 0; 73 63 } 74 64 75 - static struct idio_16_gpio *to_idio16gpio(struct gpio_chip *gc) 76 - { 77 - return container_of(gc, struct idio_16_gpio, chip); 78 - } 79 - 80 65 static int idio_16_gpio_get(struct gpio_chip *chip, unsigned offset) 81 66 { 82 - struct idio_16_gpio *const idio16gpio = to_idio16gpio(chip); 83 - const unsigned BIT_MASK = 1U << (offset-16); 67 + struct idio_16_gpio *const idio16gpio = gpiochip_get_data(chip); 68 + const unsigned mask = BIT(offset-16); 84 69 85 70 if (offset < 16) 86 71 return -EINVAL; 87 72 88 73 if (offset < 24) 89 - return !!(inb(idio16gpio->base + 1) & BIT_MASK); 74 + return !!(inb(idio16gpio->base + 1) & mask); 90 75 91 - return !!(inb(idio16gpio->base + 5) & (BIT_MASK>>8)); 76 + return !!(inb(idio16gpio->base + 5) & (mask>>8)); 92 77 } 93 78 94 79 static void idio_16_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 95 80 { 96 - struct idio_16_gpio *const idio16gpio = to_idio16gpio(chip); 97 - const unsigned BIT_MASK = 1U << offset; 81 + struct idio_16_gpio *const idio16gpio = gpiochip_get_data(chip); 82 + const unsigned mask = BIT(offset); 98 83 unsigned long flags; 99 84 100 85 if (offset > 15) ··· 98 93 spin_lock_irqsave(&idio16gpio->lock, flags); 99 94 100 95 if (value) 101 - idio16gpio->out_state |= BIT_MASK; 96 + idio16gpio->out_state |= mask; 102 97 else 103 - idio16gpio->out_state &= ~BIT_MASK; 98 + idio16gpio->out_state &= ~mask; 104 99 105 100 if (offset > 7) 106 101 outb(idio16gpio->out_state >> 8, idio16gpio->base + 4); ··· 110 105 spin_unlock_irqrestore(&idio16gpio->lock, flags); 111 106 } 112 107 108 + static void idio_16_irq_ack(struct irq_data *data) 109 + { 110 + } 111 + 112 + static void idio_16_irq_mask(struct irq_data *data) 113 + { 114 + struct gpio_chip *chip = irq_data_get_irq_chip_data(data); 115 + struct idio_16_gpio *const idio16gpio = gpiochip_get_data(chip); 116 + const unsigned long mask = BIT(irqd_to_hwirq(data)); 117 + unsigned long flags; 118 + 119 + idio16gpio->irq_mask &= ~mask; 120 + 121 + if (!idio16gpio->irq_mask) { 122 + spin_lock_irqsave(&idio16gpio->lock, flags); 123 + 124 + outb(0, idio16gpio->base + 2); 125 + 126 + spin_unlock_irqrestore(&idio16gpio->lock, flags); 127 + } 128 + } 129 + 130 + static void idio_16_irq_unmask(struct irq_data *data) 131 + { 132 + struct gpio_chip *chip = irq_data_get_irq_chip_data(data); 133 + struct idio_16_gpio *const idio16gpio = gpiochip_get_data(chip); 134 + const unsigned long mask = BIT(irqd_to_hwirq(data)); 135 + const unsigned long prev_irq_mask = idio16gpio->irq_mask; 136 + unsigned long flags; 137 + 138 + idio16gpio->irq_mask |= mask; 139 + 140 + if (!prev_irq_mask) { 141 + spin_lock_irqsave(&idio16gpio->lock, flags); 142 + 143 + inb(idio16gpio->base + 2); 144 + 145 + spin_unlock_irqrestore(&idio16gpio->lock, flags); 146 + } 147 + } 148 + 149 + static int idio_16_irq_set_type(struct irq_data *data, unsigned flow_type) 150 + { 151 + /* The only valid irq types are none and both-edges */ 152 + if (flow_type != IRQ_TYPE_NONE && 153 + (flow_type & IRQ_TYPE_EDGE_BOTH) != IRQ_TYPE_EDGE_BOTH) 154 + return -EINVAL; 155 + 156 + return 0; 157 + } 158 + 159 + static struct irq_chip idio_16_irqchip = { 160 + .name = "104-idio-16", 161 + .irq_ack = idio_16_irq_ack, 162 + .irq_mask = idio_16_irq_mask, 163 + .irq_unmask = idio_16_irq_unmask, 164 + .irq_set_type = idio_16_irq_set_type 165 + }; 166 + 167 + static irqreturn_t idio_16_irq_handler(int irq, void *dev_id) 168 + { 169 + struct idio_16_gpio *const idio16gpio = dev_id; 170 + struct gpio_chip *const chip = &idio16gpio->chip; 171 + int gpio; 172 + 173 + for_each_set_bit(gpio, &idio16gpio->irq_mask, chip->ngpio) 174 + generic_handle_irq(irq_find_mapping(chip->irqdomain, gpio)); 175 + 176 + spin_lock(&idio16gpio->lock); 177 + 178 + outb(0, idio16gpio->base + 1); 179 + 180 + spin_unlock(&idio16gpio->lock); 181 + 182 + return IRQ_HANDLED; 183 + } 184 + 113 185 static int __init idio_16_probe(struct platform_device *pdev) 114 186 { 115 187 struct device *dev = &pdev->dev; 116 188 struct idio_16_gpio *idio16gpio; 189 + const unsigned base = idio_16_base; 190 + const unsigned extent = 8; 191 + const char *const name = dev_name(dev); 117 192 int err; 118 - 119 - const unsigned BASE = idio_16_base; 120 - const unsigned EXTENT = 8; 121 - const char *const NAME = dev_name(dev); 193 + const unsigned irq = idio_16_irq; 122 194 123 195 idio16gpio = devm_kzalloc(dev, sizeof(*idio16gpio), GFP_KERNEL); 124 196 if (!idio16gpio) 125 197 return -ENOMEM; 126 198 127 - if (!request_region(BASE, EXTENT, NAME)) { 199 + if (!request_region(base, extent, name)) { 128 200 dev_err(dev, "Unable to lock %s port addresses (0x%X-0x%X)\n", 129 - NAME, BASE, BASE + EXTENT); 201 + name, base, base + extent); 130 202 err = -EBUSY; 131 203 goto err_lock_io_port; 132 204 } 133 205 134 - idio16gpio->chip.label = NAME; 135 - idio16gpio->chip.dev = dev; 206 + idio16gpio->chip.label = name; 207 + idio16gpio->chip.parent = dev; 136 208 idio16gpio->chip.owner = THIS_MODULE; 137 209 idio16gpio->chip.base = -1; 138 210 idio16gpio->chip.ngpio = 32; ··· 218 136 idio16gpio->chip.direction_output = idio_16_gpio_direction_output; 219 137 idio16gpio->chip.get = idio_16_gpio_get; 220 138 idio16gpio->chip.set = idio_16_gpio_set; 221 - idio16gpio->base = BASE; 222 - idio16gpio->extent = EXTENT; 139 + idio16gpio->base = base; 140 + idio16gpio->extent = extent; 141 + idio16gpio->irq = irq; 223 142 idio16gpio->out_state = 0xFFFF; 224 143 225 144 spin_lock_init(&idio16gpio->lock); 226 145 227 146 dev_set_drvdata(dev, idio16gpio); 228 147 229 - err = gpiochip_add(&idio16gpio->chip); 148 + err = gpiochip_add_data(&idio16gpio->chip, idio16gpio); 230 149 if (err) { 231 150 dev_err(dev, "GPIO registering failed (%d)\n", err); 232 151 goto err_gpio_register; 233 152 } 234 153 154 + /* Disable IRQ by default */ 155 + outb(0, base + 2); 156 + outb(0, base + 1); 157 + 158 + err = gpiochip_irqchip_add(&idio16gpio->chip, &idio_16_irqchip, 0, 159 + handle_edge_irq, IRQ_TYPE_NONE); 160 + if (err) { 161 + dev_err(dev, "Could not add irqchip (%d)\n", err); 162 + goto err_gpiochip_irqchip_add; 163 + } 164 + 165 + err = request_irq(irq, idio_16_irq_handler, 0, name, idio16gpio); 166 + if (err) { 167 + dev_err(dev, "IRQ handler registering failed (%d)\n", err); 168 + goto err_request_irq; 169 + } 170 + 235 171 return 0; 236 172 173 + err_request_irq: 174 + err_gpiochip_irqchip_add: 175 + gpiochip_remove(&idio16gpio->chip); 237 176 err_gpio_register: 238 - release_region(BASE, EXTENT); 177 + release_region(base, extent); 239 178 err_lock_io_port: 240 179 return err; 241 180 } ··· 265 162 { 266 163 struct idio_16_gpio *const idio16gpio = platform_get_drvdata(pdev); 267 164 165 + free_irq(idio16gpio->irq, idio16gpio); 268 166 gpiochip_remove(&idio16gpio->chip); 269 167 release_region(idio16gpio->base, idio16gpio->extent); 270 168
+28 -51
drivers/gpio/gpio-74x164.c
··· 20 20 #define GEN_74X164_NUMBER_GPIOS 8 21 21 22 22 struct gen_74x164_chip { 23 - u8 *buffer; 24 23 struct gpio_chip gpio_chip; 25 24 struct mutex lock; 26 25 u32 registers; 27 - }; 28 - 29 - static struct gen_74x164_chip *gpio_to_74x164_chip(struct gpio_chip *gc) 30 - { 31 - return container_of(gc, struct gen_74x164_chip, gpio_chip); 32 - } 33 - 34 - static int __gen_74x164_write_config(struct gen_74x164_chip *chip) 35 - { 36 - struct spi_device *spi = to_spi_device(chip->gpio_chip.dev); 37 - struct spi_message message; 38 - struct spi_transfer *msg_buf; 39 - int i, ret = 0; 40 - 41 - msg_buf = kzalloc(chip->registers * sizeof(struct spi_transfer), 42 - GFP_KERNEL); 43 - if (!msg_buf) 44 - return -ENOMEM; 45 - 46 - spi_message_init(&message); 47 - 48 26 /* 49 27 * Since the registers are chained, every byte sent will make 50 28 * the previous byte shift to the next register in the 51 - * chain. Thus, the first byte send will end up in the last 29 + * chain. Thus, the first byte sent will end up in the last 52 30 * register at the end of the transfer. So, to have a logical 53 - * numbering, send the bytes in reverse order so that the last 54 - * byte of the buffer will end up in the last register. 31 + * numbering, store the bytes in reverse order. 55 32 */ 56 - for (i = chip->registers - 1; i >= 0; i--) { 57 - msg_buf[i].tx_buf = chip->buffer + i; 58 - msg_buf[i].len = sizeof(u8); 59 - spi_message_add_tail(msg_buf + i, &message); 60 - } 33 + u8 buffer[0]; 34 + }; 61 35 62 - ret = spi_sync(spi, &message); 36 + static int __gen_74x164_write_config(struct gen_74x164_chip *chip) 37 + { 38 + struct spi_transfer xfer = { 39 + .tx_buf = chip->buffer, 40 + .len = chip->registers, 41 + }; 63 42 64 - kfree(msg_buf); 65 - 66 - return ret; 43 + return spi_sync_transfer(to_spi_device(chip->gpio_chip.parent), 44 + &xfer, 1); 67 45 } 68 46 69 47 static int gen_74x164_get_value(struct gpio_chip *gc, unsigned offset) 70 48 { 71 - struct gen_74x164_chip *chip = gpio_to_74x164_chip(gc); 72 - u8 bank = offset / 8; 49 + struct gen_74x164_chip *chip = gpiochip_get_data(gc); 50 + u8 bank = chip->registers - 1 - offset / 8; 73 51 u8 pin = offset % 8; 74 52 int ret; 75 53 ··· 61 83 static void gen_74x164_set_value(struct gpio_chip *gc, 62 84 unsigned offset, int val) 63 85 { 64 - struct gen_74x164_chip *chip = gpio_to_74x164_chip(gc); 65 - u8 bank = offset / 8; 86 + struct gen_74x164_chip *chip = gpiochip_get_data(gc); 87 + u8 bank = chip->registers - 1 - offset / 8; 66 88 u8 pin = offset % 8; 67 89 68 90 mutex_lock(&chip->lock); ··· 85 107 static int gen_74x164_probe(struct spi_device *spi) 86 108 { 87 109 struct gen_74x164_chip *chip; 110 + u32 nregs; 88 111 int ret; 89 112 90 113 /* ··· 97 118 if (ret < 0) 98 119 return ret; 99 120 100 - chip = devm_kzalloc(&spi->dev, sizeof(*chip), GFP_KERNEL); 121 + if (of_property_read_u32(spi->dev.of_node, "registers-number", 122 + &nregs)) { 123 + dev_err(&spi->dev, 124 + "Missing registers-number property in the DT.\n"); 125 + return -EINVAL; 126 + } 127 + 128 + chip = devm_kzalloc(&spi->dev, sizeof(*chip) + nregs, GFP_KERNEL); 101 129 if (!chip) 102 130 return -ENOMEM; 103 131 ··· 116 130 chip->gpio_chip.set = gen_74x164_set_value; 117 131 chip->gpio_chip.base = -1; 118 132 119 - if (of_property_read_u32(spi->dev.of_node, "registers-number", 120 - &chip->registers)) { 121 - dev_err(&spi->dev, 122 - "Missing registers-number property in the DT.\n"); 123 - return -EINVAL; 124 - } 125 - 133 + chip->registers = nregs; 126 134 chip->gpio_chip.ngpio = GEN_74X164_NUMBER_GPIOS * chip->registers; 127 - chip->buffer = devm_kzalloc(&spi->dev, chip->registers, GFP_KERNEL); 128 - if (!chip->buffer) 129 - return -ENOMEM; 130 135 131 136 chip->gpio_chip.can_sleep = true; 132 - chip->gpio_chip.dev = &spi->dev; 137 + chip->gpio_chip.parent = &spi->dev; 133 138 chip->gpio_chip.owner = THIS_MODULE; 134 139 135 140 mutex_init(&chip->lock); ··· 131 154 goto exit_destroy; 132 155 } 133 156 134 - ret = gpiochip_add(&chip->gpio_chip); 157 + ret = gpiochip_add_data(&chip->gpio_chip, chip); 135 158 if (!ret) 136 159 return 0; 137 160
+15 -22
drivers/gpio/gpio-74xx-mmio.c
··· 10 10 */ 11 11 12 12 #include <linux/err.h> 13 - #include <linux/gpio.h> 14 13 #include <linux/module.h> 15 14 #include <linux/of_device.h> 16 - #include <linux/basic_mmio_gpio.h> 15 + #include <linux/gpio/driver.h> 17 16 #include <linux/platform_device.h> 18 17 19 18 #define MMIO_74XX_DIR_IN (0 << 8) ··· 20 21 #define MMIO_74XX_BIT_CNT(x) ((x) & 0xff) 21 22 22 23 struct mmio_74xx_gpio_priv { 23 - struct bgpio_chip bgc; 24 + struct gpio_chip gc; 24 25 unsigned flags; 25 26 }; 26 27 ··· 77 78 }; 78 79 MODULE_DEVICE_TABLE(of, mmio_74xx_gpio_ids); 79 80 80 - static inline struct mmio_74xx_gpio_priv *to_74xx_gpio(struct gpio_chip *gc) 81 - { 82 - struct bgpio_chip *bgc = to_bgpio_chip(gc); 83 - 84 - return container_of(bgc, struct mmio_74xx_gpio_priv, bgc); 85 - } 86 - 87 81 static int mmio_74xx_get_direction(struct gpio_chip *gc, unsigned offset) 88 82 { 89 - struct mmio_74xx_gpio_priv *priv = to_74xx_gpio(gc); 83 + struct mmio_74xx_gpio_priv *priv = gpiochip_get_data(gc); 90 84 91 - return (priv->flags & MMIO_74XX_DIR_OUT) ? GPIOF_DIR_OUT : GPIOF_DIR_IN; 85 + return !(priv->flags & MMIO_74XX_DIR_OUT); 92 86 } 93 87 94 88 static int mmio_74xx_dir_in(struct gpio_chip *gc, unsigned int gpio) 95 89 { 96 - struct mmio_74xx_gpio_priv *priv = to_74xx_gpio(gc); 90 + struct mmio_74xx_gpio_priv *priv = gpiochip_get_data(gc); 97 91 98 92 return (priv->flags & MMIO_74XX_DIR_OUT) ? -ENOTSUPP : 0; 99 93 } 100 94 101 95 static int mmio_74xx_dir_out(struct gpio_chip *gc, unsigned int gpio, int val) 102 96 { 103 - struct mmio_74xx_gpio_priv *priv = to_74xx_gpio(gc); 97 + struct mmio_74xx_gpio_priv *priv = gpiochip_get_data(gc); 104 98 105 99 if (priv->flags & MMIO_74XX_DIR_OUT) { 106 100 gc->set(gc, gpio, val); ··· 126 134 127 135 priv->flags = (uintptr_t) of_id->data; 128 136 129 - err = bgpio_init(&priv->bgc, &pdev->dev, 137 + err = bgpio_init(&priv->gc, &pdev->dev, 130 138 DIV_ROUND_UP(MMIO_74XX_BIT_CNT(priv->flags), 8), 131 139 dat, NULL, NULL, NULL, NULL, 0); 132 140 if (err) 133 141 return err; 134 142 135 - priv->bgc.gc.direction_input = mmio_74xx_dir_in; 136 - priv->bgc.gc.direction_output = mmio_74xx_dir_out; 137 - priv->bgc.gc.get_direction = mmio_74xx_get_direction; 138 - priv->bgc.gc.ngpio = MMIO_74XX_BIT_CNT(priv->flags); 139 - priv->bgc.gc.owner = THIS_MODULE; 143 + priv->gc.direction_input = mmio_74xx_dir_in; 144 + priv->gc.direction_output = mmio_74xx_dir_out; 145 + priv->gc.get_direction = mmio_74xx_get_direction; 146 + priv->gc.ngpio = MMIO_74XX_BIT_CNT(priv->flags); 147 + priv->gc.owner = THIS_MODULE; 140 148 141 149 platform_set_drvdata(pdev, priv); 142 150 143 - return gpiochip_add(&priv->bgc.gc); 151 + return gpiochip_add_data(&priv->gc, priv); 144 152 } 145 153 146 154 static int mmio_74xx_gpio_remove(struct platform_device *pdev) 147 155 { 148 156 struct mmio_74xx_gpio_priv *priv = platform_get_drvdata(pdev); 149 157 150 - return bgpio_remove(&priv->bgc); 158 + gpiochip_remove(&priv->gc); 159 + return 0; 151 160 } 152 161 153 162 static struct platform_driver mmio_74xx_gpio_driver = {
+21 -26
drivers/gpio/gpio-adnp.c
··· 36 36 u8 *irq_low; 37 37 }; 38 38 39 - static inline struct adnp *to_adnp(struct gpio_chip *chip) 40 - { 41 - return container_of(chip, struct adnp, gpio); 42 - } 43 - 44 39 static int adnp_read(struct adnp *adnp, unsigned offset, uint8_t *value) 45 40 { 46 41 int err; 47 42 48 43 err = i2c_smbus_read_byte_data(adnp->client, offset); 49 44 if (err < 0) { 50 - dev_err(adnp->gpio.dev, "%s failed: %d\n", 45 + dev_err(adnp->gpio.parent, "%s failed: %d\n", 51 46 "i2c_smbus_read_byte_data()", err); 52 47 return err; 53 48 } ··· 57 62 58 63 err = i2c_smbus_write_byte_data(adnp->client, offset, value); 59 64 if (err < 0) { 60 - dev_err(adnp->gpio.dev, "%s failed: %d\n", 65 + dev_err(adnp->gpio.parent, "%s failed: %d\n", 61 66 "i2c_smbus_write_byte_data()", err); 62 67 return err; 63 68 } ··· 67 72 68 73 static int adnp_gpio_get(struct gpio_chip *chip, unsigned offset) 69 74 { 70 - struct adnp *adnp = to_adnp(chip); 75 + struct adnp *adnp = gpiochip_get_data(chip); 71 76 unsigned int reg = offset >> adnp->reg_shift; 72 77 unsigned int pos = offset & 7; 73 78 u8 value; ··· 101 106 102 107 static void adnp_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 103 108 { 104 - struct adnp *adnp = to_adnp(chip); 109 + struct adnp *adnp = gpiochip_get_data(chip); 105 110 106 111 mutex_lock(&adnp->i2c_lock); 107 112 __adnp_gpio_set(adnp, offset, value); ··· 110 115 111 116 static int adnp_gpio_direction_input(struct gpio_chip *chip, unsigned offset) 112 117 { 113 - struct adnp *adnp = to_adnp(chip); 118 + struct adnp *adnp = gpiochip_get_data(chip); 114 119 unsigned int reg = offset >> adnp->reg_shift; 115 120 unsigned int pos = offset & 7; 116 121 u8 value; ··· 145 150 static int adnp_gpio_direction_output(struct gpio_chip *chip, unsigned offset, 146 151 int value) 147 152 { 148 - struct adnp *adnp = to_adnp(chip); 153 + struct adnp *adnp = gpiochip_get_data(chip); 149 154 unsigned int reg = offset >> adnp->reg_shift; 150 155 unsigned int pos = offset & 7; 151 156 int err; ··· 182 187 183 188 static void adnp_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip) 184 189 { 185 - struct adnp *adnp = to_adnp(chip); 190 + struct adnp *adnp = gpiochip_get_data(chip); 186 191 unsigned int num_regs = 1 << adnp->reg_shift, i, j; 187 192 int err; 188 193 ··· 261 266 chip->base = -1; 262 267 chip->ngpio = num_gpios; 263 268 chip->label = adnp->client->name; 264 - chip->dev = &adnp->client->dev; 265 - chip->of_node = chip->dev->of_node; 269 + chip->parent = &adnp->client->dev; 270 + chip->of_node = chip->parent->of_node; 266 271 chip->owner = THIS_MODULE; 267 272 268 - err = gpiochip_add(chip); 273 + err = gpiochip_add_data(chip, adnp); 269 274 if (err) 270 275 return err; 271 276 ··· 335 340 static void adnp_irq_mask(struct irq_data *d) 336 341 { 337 342 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 338 - struct adnp *adnp = to_adnp(gc); 343 + struct adnp *adnp = gpiochip_get_data(gc); 339 344 unsigned int reg = d->hwirq >> adnp->reg_shift; 340 345 unsigned int pos = d->hwirq & 7; 341 346 ··· 345 350 static void adnp_irq_unmask(struct irq_data *d) 346 351 { 347 352 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 348 - struct adnp *adnp = to_adnp(gc); 353 + struct adnp *adnp = gpiochip_get_data(gc); 349 354 unsigned int reg = d->hwirq >> adnp->reg_shift; 350 355 unsigned int pos = d->hwirq & 7; 351 356 ··· 355 360 static int adnp_irq_set_type(struct irq_data *d, unsigned int type) 356 361 { 357 362 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 358 - struct adnp *adnp = to_adnp(gc); 363 + struct adnp *adnp = gpiochip_get_data(gc); 359 364 unsigned int reg = d->hwirq >> adnp->reg_shift; 360 365 unsigned int pos = d->hwirq & 7; 361 366 ··· 385 390 static void adnp_irq_bus_lock(struct irq_data *d) 386 391 { 387 392 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 388 - struct adnp *adnp = to_adnp(gc); 393 + struct adnp *adnp = gpiochip_get_data(gc); 389 394 390 395 mutex_lock(&adnp->irq_lock); 391 396 } ··· 393 398 static void adnp_irq_bus_unlock(struct irq_data *d) 394 399 { 395 400 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 396 - struct adnp *adnp = to_adnp(gc); 401 + struct adnp *adnp = gpiochip_get_data(gc); 397 402 unsigned int num_regs = 1 << adnp->reg_shift, i; 398 403 399 404 mutex_lock(&adnp->i2c_lock); ··· 430 435 * is chosen to match the register layout of the hardware in that 431 436 * each segment contains the corresponding bits for all interrupts. 432 437 */ 433 - adnp->irq_enable = devm_kzalloc(chip->dev, num_regs * 6, GFP_KERNEL); 438 + adnp->irq_enable = devm_kzalloc(chip->parent, num_regs * 6, 439 + GFP_KERNEL); 434 440 if (!adnp->irq_enable) 435 441 return -ENOMEM; 436 442 ··· 458 462 adnp->irq_enable[i] = 0x00; 459 463 } 460 464 461 - err = devm_request_threaded_irq(chip->dev, adnp->client->irq, 465 + err = devm_request_threaded_irq(chip->parent, adnp->client->irq, 462 466 NULL, adnp_irq, 463 467 IRQF_TRIGGER_RISING | IRQF_ONESHOT, 464 - dev_name(chip->dev), adnp); 468 + dev_name(chip->parent), adnp); 465 469 if (err != 0) { 466 - dev_err(chip->dev, "can't request IRQ#%d: %d\n", 470 + dev_err(chip->parent, "can't request IRQ#%d: %d\n", 467 471 adnp->client->irq, err); 468 472 return err; 469 473 } ··· 474 478 handle_simple_irq, 475 479 IRQ_TYPE_NONE); 476 480 if (err) { 477 - dev_err(chip->dev, 481 + dev_err(chip->parent, 478 482 "could not connect irqchip to gpiochip\n"); 479 483 return err; 480 484 } ··· 543 547 static struct i2c_driver adnp_i2c_driver = { 544 548 .driver = { 545 549 .name = "gpio-adnp", 546 - .owner = THIS_MODULE, 547 550 .of_match_table = adnp_of_match, 548 551 }, 549 552 .probe = adnp_i2c_probe,
+5 -5
drivers/gpio/gpio-adp5520.c
··· 27 27 struct adp5520_gpio *dev; 28 28 uint8_t reg_val; 29 29 30 - dev = container_of(chip, struct adp5520_gpio, gpio_chip); 30 + dev = gpiochip_get_data(chip); 31 31 32 32 /* 33 33 * There are dedicated registers for GPIO IN/OUT. ··· 46 46 unsigned off, int val) 47 47 { 48 48 struct adp5520_gpio *dev; 49 - dev = container_of(chip, struct adp5520_gpio, gpio_chip); 49 + dev = gpiochip_get_data(chip); 50 50 51 51 if (val) 52 52 adp5520_set_bits(dev->master, ADP5520_GPIO_OUT, dev->lut[off]); ··· 57 57 static int adp5520_gpio_direction_input(struct gpio_chip *chip, unsigned off) 58 58 { 59 59 struct adp5520_gpio *dev; 60 - dev = container_of(chip, struct adp5520_gpio, gpio_chip); 60 + dev = gpiochip_get_data(chip); 61 61 62 62 clear_bit(off, &dev->output); 63 63 ··· 70 70 { 71 71 struct adp5520_gpio *dev; 72 72 int ret = 0; 73 - dev = container_of(chip, struct adp5520_gpio, gpio_chip); 73 + dev = gpiochip_get_data(chip); 74 74 75 75 set_bit(off, &dev->output); 76 76 ··· 153 153 goto err; 154 154 } 155 155 156 - ret = gpiochip_add(&dev->gpio_chip); 156 + ret = gpiochip_add_data(&dev->gpio_chip, dev); 157 157 if (ret) 158 158 goto err; 159 159
+7 -11
drivers/gpio/gpio-adp5588.c
··· 65 65 66 66 static int adp5588_gpio_get_value(struct gpio_chip *chip, unsigned off) 67 67 { 68 - struct adp5588_gpio *dev = 69 - container_of(chip, struct adp5588_gpio, gpio_chip); 68 + struct adp5588_gpio *dev = gpiochip_get_data(chip); 70 69 unsigned bank = ADP5588_BANK(off); 71 70 unsigned bit = ADP5588_BIT(off); 72 71 int val; ··· 86 87 unsigned off, int val) 87 88 { 88 89 unsigned bank, bit; 89 - struct adp5588_gpio *dev = 90 - container_of(chip, struct adp5588_gpio, gpio_chip); 90 + struct adp5588_gpio *dev = gpiochip_get_data(chip); 91 91 92 92 bank = ADP5588_BANK(off); 93 93 bit = ADP5588_BIT(off); ··· 106 108 { 107 109 int ret; 108 110 unsigned bank; 109 - struct adp5588_gpio *dev = 110 - container_of(chip, struct adp5588_gpio, gpio_chip); 111 + struct adp5588_gpio *dev = gpiochip_get_data(chip); 111 112 112 113 bank = ADP5588_BANK(off); 113 114 ··· 123 126 { 124 127 int ret; 125 128 unsigned bank, bit; 126 - struct adp5588_gpio *dev = 127 - container_of(chip, struct adp5588_gpio, gpio_chip); 129 + struct adp5588_gpio *dev = gpiochip_get_data(chip); 128 130 129 131 bank = ADP5588_BANK(off); 130 132 bit = ADP5588_BIT(off); ··· 148 152 #ifdef CONFIG_GPIO_ADP5588_IRQ 149 153 static int adp5588_gpio_to_irq(struct gpio_chip *chip, unsigned off) 150 154 { 151 - struct adp5588_gpio *dev = 152 - container_of(chip, struct adp5588_gpio, gpio_chip); 155 + struct adp5588_gpio *dev = gpiochip_get_data(chip); 156 + 153 157 return dev->irq_base + off; 154 158 } 155 159 ··· 414 418 } 415 419 } 416 420 417 - ret = gpiochip_add(&dev->gpio_chip); 421 + ret = gpiochip_add_data(&dev->gpio_chip, dev); 418 422 if (ret) 419 423 goto err_irq; 420 424
+10 -15
drivers/gpio/gpio-altera.c
··· 42 42 int mapped_irq; 43 43 }; 44 44 45 - static struct altera_gpio_chip *to_altera(struct gpio_chip *gc) 46 - { 47 - return container_of(gc, struct altera_gpio_chip, mmchip.gc); 48 - } 49 - 50 45 static void altera_gpio_irq_unmask(struct irq_data *d) 51 46 { 52 47 struct altera_gpio_chip *altera_gc; ··· 49 54 unsigned long flags; 50 55 u32 intmask; 51 56 52 - altera_gc = to_altera(irq_data_get_irq_chip_data(d)); 57 + altera_gc = gpiochip_get_data(irq_data_get_irq_chip_data(d)); 53 58 mm_gc = &altera_gc->mmchip; 54 59 55 60 spin_lock_irqsave(&altera_gc->gpio_lock, flags); ··· 67 72 unsigned long flags; 68 73 u32 intmask; 69 74 70 - altera_gc = to_altera(irq_data_get_irq_chip_data(d)); 75 + altera_gc = gpiochip_get_data(irq_data_get_irq_chip_data(d)); 71 76 mm_gc = &altera_gc->mmchip; 72 77 73 78 spin_lock_irqsave(&altera_gc->gpio_lock, flags); ··· 87 92 { 88 93 struct altera_gpio_chip *altera_gc; 89 94 90 - altera_gc = to_altera(irq_data_get_irq_chip_data(d)); 95 + altera_gc = gpiochip_get_data(irq_data_get_irq_chip_data(d)); 91 96 92 97 if (type == IRQ_TYPE_NONE) 93 98 return 0; ··· 140 145 unsigned int data_reg; 141 146 142 147 mm_gc = to_of_mm_gpio_chip(gc); 143 - chip = container_of(mm_gc, struct altera_gpio_chip, mmchip); 148 + chip = gpiochip_get_data(gc); 144 149 145 150 spin_lock_irqsave(&chip->gpio_lock, flags); 146 151 data_reg = readl(mm_gc->regs + ALTERA_GPIO_DATA); ··· 160 165 unsigned int gpio_ddr; 161 166 162 167 mm_gc = to_of_mm_gpio_chip(gc); 163 - chip = container_of(mm_gc, struct altera_gpio_chip, mmchip); 168 + chip = gpiochip_get_data(gc); 164 169 165 170 spin_lock_irqsave(&chip->gpio_lock, flags); 166 171 /* Set pin as input, assumes software controlled IP */ ··· 181 186 unsigned int data_reg, gpio_ddr; 182 187 183 188 mm_gc = to_of_mm_gpio_chip(gc); 184 - chip = container_of(mm_gc, struct altera_gpio_chip, mmchip); 189 + chip = gpiochip_get_data(gc); 185 190 186 191 spin_lock_irqsave(&chip->gpio_lock, flags); 187 192 /* Sets the GPIO value */ ··· 210 215 unsigned long status; 211 216 int i; 212 217 213 - altera_gc = to_altera(irq_desc_get_handler_data(desc)); 218 + altera_gc = gpiochip_get_data(irq_desc_get_handler_data(desc)); 214 219 chip = irq_desc_get_chip(desc); 215 220 mm_gc = &altera_gc->mmchip; 216 221 irqdomain = altera_gc->mmchip.gc.irqdomain; ··· 239 244 unsigned long status; 240 245 int i; 241 246 242 - altera_gc = to_altera(irq_desc_get_handler_data(desc)); 247 + altera_gc = gpiochip_get_data(irq_desc_get_handler_data(desc)); 243 248 chip = irq_desc_get_chip(desc); 244 249 mm_gc = &altera_gc->mmchip; 245 250 irqdomain = altera_gc->mmchip.gc.irqdomain; ··· 285 290 altera_gc->mmchip.gc.get = altera_gpio_get; 286 291 altera_gc->mmchip.gc.set = altera_gpio_set; 287 292 altera_gc->mmchip.gc.owner = THIS_MODULE; 288 - altera_gc->mmchip.gc.dev = &pdev->dev; 293 + altera_gc->mmchip.gc.parent = &pdev->dev; 289 294 290 - ret = of_mm_gpiochip_add(node, &altera_gc->mmchip); 295 + ret = of_mm_gpiochip_add_data(node, &altera_gc->mmchip, altera_gc); 291 296 if (ret) { 292 297 dev_err(&pdev->dev, "Failed adding memory mapped gpiochip\n"); 293 298 return ret;
+8 -10
drivers/gpio/gpio-amd8111.c
··· 75 75 u8 orig[32]; 76 76 }; 77 77 78 - #define to_agp(chip) container_of(chip, struct amd_gpio, chip) 79 - 80 78 static int amd_gpio_request(struct gpio_chip *chip, unsigned offset) 81 79 { 82 - struct amd_gpio *agp = to_agp(chip); 80 + struct amd_gpio *agp = gpiochip_get_data(chip); 83 81 84 82 agp->orig[offset] = ioread8(agp->pm + AMD_REG_GPIO(offset)) & 85 83 (AMD_GPIO_DEBOUNCE | AMD_GPIO_MODE_MASK | AMD_GPIO_X_MASK); ··· 89 91 90 92 static void amd_gpio_free(struct gpio_chip *chip, unsigned offset) 91 93 { 92 - struct amd_gpio *agp = to_agp(chip); 94 + struct amd_gpio *agp = gpiochip_get_data(chip); 93 95 94 96 dev_dbg(&agp->pdev->dev, "Freed gpio %d, data %x\n", offset, agp->orig[offset]); 95 97 ··· 98 100 99 101 static void amd_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 100 102 { 101 - struct amd_gpio *agp = to_agp(chip); 103 + struct amd_gpio *agp = gpiochip_get_data(chip); 102 104 u8 temp; 103 105 unsigned long flags; 104 106 ··· 113 115 114 116 static int amd_gpio_get(struct gpio_chip *chip, unsigned offset) 115 117 { 116 - struct amd_gpio *agp = to_agp(chip); 118 + struct amd_gpio *agp = gpiochip_get_data(chip); 117 119 u8 temp; 118 120 119 121 temp = ioread8(agp->pm + AMD_REG_GPIO(offset)); ··· 125 127 126 128 static int amd_gpio_dirout(struct gpio_chip *chip, unsigned offset, int value) 127 129 { 128 - struct amd_gpio *agp = to_agp(chip); 130 + struct amd_gpio *agp = gpiochip_get_data(chip); 129 131 u8 temp; 130 132 unsigned long flags; 131 133 ··· 142 144 143 145 static int amd_gpio_dirin(struct gpio_chip *chip, unsigned offset) 144 146 { 145 - struct amd_gpio *agp = to_agp(chip); 147 + struct amd_gpio *agp = gpiochip_get_data(chip); 146 148 u8 temp; 147 149 unsigned long flags; 148 150 ··· 218 220 goto out; 219 221 } 220 222 gp.pdev = pdev; 221 - gp.chip.dev = &pdev->dev; 223 + gp.chip.parent = &pdev->dev; 222 224 223 225 spin_lock_init(&gp.lock); 224 226 225 227 printk(KERN_INFO "AMD-8111 GPIO detected\n"); 226 - err = gpiochip_add(&gp.chip); 228 + err = gpiochip_add_data(&gp.chip, &gp); 227 229 if (err) { 228 230 printk(KERN_ERR "GPIO registering failed (%d)\n", 229 231 err);
+16 -18
drivers/gpio/gpio-amdpt.c
··· 31 31 spinlock_t lock; 32 32 }; 33 33 34 - #define to_pt_gpio(c) container_of(c, struct pt_gpio_chip, gc) 35 - 36 34 static int pt_gpio_request(struct gpio_chip *gc, unsigned offset) 37 35 { 38 - struct pt_gpio_chip *pt_gpio = to_pt_gpio(gc); 36 + struct pt_gpio_chip *pt_gpio = gpiochip_get_data(gc); 39 37 unsigned long flags; 40 38 u32 using_pins; 41 39 42 - dev_dbg(gc->dev, "pt_gpio_request offset=%x\n", offset); 40 + dev_dbg(gc->parent, "pt_gpio_request offset=%x\n", offset); 43 41 44 42 spin_lock_irqsave(&pt_gpio->lock, flags); 45 43 46 44 using_pins = readl(pt_gpio->reg_base + PT_SYNC_REG); 47 45 if (using_pins & BIT(offset)) { 48 - dev_warn(gc->dev, "PT GPIO pin %x reconfigured\n", 49 - offset); 46 + dev_warn(gc->parent, "PT GPIO pin %x reconfigured\n", 47 + offset); 50 48 spin_unlock_irqrestore(&pt_gpio->lock, flags); 51 49 return -EINVAL; 52 50 } ··· 58 60 59 61 static void pt_gpio_free(struct gpio_chip *gc, unsigned offset) 60 62 { 61 - struct pt_gpio_chip *pt_gpio = to_pt_gpio(gc); 63 + struct pt_gpio_chip *pt_gpio = gpiochip_get_data(gc); 62 64 unsigned long flags; 63 65 u32 using_pins; 64 66 ··· 70 72 71 73 spin_unlock_irqrestore(&pt_gpio->lock, flags); 72 74 73 - dev_dbg(gc->dev, "pt_gpio_free offset=%x\n", offset); 75 + dev_dbg(gc->parent, "pt_gpio_free offset=%x\n", offset); 74 76 } 75 77 76 78 static void pt_gpio_set_value(struct gpio_chip *gc, unsigned offset, int value) 77 79 { 78 - struct pt_gpio_chip *pt_gpio = to_pt_gpio(gc); 80 + struct pt_gpio_chip *pt_gpio = gpiochip_get_data(gc); 79 81 unsigned long flags; 80 82 u32 data; 81 83 82 - dev_dbg(gc->dev, "pt_gpio_set_value offset=%x, value=%x\n", 84 + dev_dbg(gc->parent, "pt_gpio_set_value offset=%x, value=%x\n", 83 85 offset, value); 84 86 85 87 spin_lock_irqsave(&pt_gpio->lock, flags); ··· 95 97 96 98 static int pt_gpio_get_value(struct gpio_chip *gc, unsigned offset) 97 99 { 98 - struct pt_gpio_chip *pt_gpio = to_pt_gpio(gc); 100 + struct pt_gpio_chip *pt_gpio = gpiochip_get_data(gc); 99 101 unsigned long flags; 100 102 u32 data; 101 103 ··· 114 116 data >>= offset; 115 117 data &= 1; 116 118 117 - dev_dbg(gc->dev, "pt_gpio_get_value offset=%x, value=%x\n", 119 + dev_dbg(gc->parent, "pt_gpio_get_value offset=%x, value=%x\n", 118 120 offset, data); 119 121 120 122 return data; ··· 122 124 123 125 static int pt_gpio_direction_input(struct gpio_chip *gc, unsigned offset) 124 126 { 125 - struct pt_gpio_chip *pt_gpio = to_pt_gpio(gc); 127 + struct pt_gpio_chip *pt_gpio = gpiochip_get_data(gc); 126 128 unsigned long flags; 127 129 u32 data; 128 130 129 - dev_dbg(gc->dev, "pt_gpio_dirction_input offset=%x\n", offset); 131 + dev_dbg(gc->parent, "pt_gpio_dirction_input offset=%x\n", offset); 130 132 131 133 spin_lock_irqsave(&pt_gpio->lock, flags); 132 134 ··· 142 144 static int pt_gpio_direction_output(struct gpio_chip *gc, 143 145 unsigned offset, int value) 144 146 { 145 - struct pt_gpio_chip *pt_gpio = to_pt_gpio(gc); 147 + struct pt_gpio_chip *pt_gpio = gpiochip_get_data(gc); 146 148 unsigned long flags; 147 149 u32 data; 148 150 149 - dev_dbg(gc->dev, "pt_gpio_direction_output offset=%x, value=%x\n", 151 + dev_dbg(gc->parent, "pt_gpio_direction_output offset=%x, value=%x\n", 150 152 offset, value); 151 153 152 154 spin_lock_irqsave(&pt_gpio->lock, flags); ··· 200 202 201 203 pt_gpio->gc.label = pdev->name; 202 204 pt_gpio->gc.owner = THIS_MODULE; 203 - pt_gpio->gc.dev = dev; 205 + pt_gpio->gc.parent = dev; 204 206 pt_gpio->gc.request = pt_gpio_request; 205 207 pt_gpio->gc.free = pt_gpio_free; 206 208 pt_gpio->gc.direction_input = pt_gpio_direction_input; ··· 212 214 #if defined(CONFIG_OF_GPIO) 213 215 pt_gpio->gc.of_node = pdev->dev.of_node; 214 216 #endif 215 - ret = gpiochip_add(&pt_gpio->gc); 217 + ret = gpiochip_add_data(&pt_gpio->gc, pt_gpio); 216 218 if (ret) { 217 219 dev_err(&pdev->dev, "Failed to register GPIO lib\n"); 218 220 return ret;
+6 -11
drivers/gpio/gpio-arizona.c
··· 28 28 struct gpio_chip gpio_chip; 29 29 }; 30 30 31 - static inline struct arizona_gpio *to_arizona_gpio(struct gpio_chip *chip) 32 - { 33 - return container_of(chip, struct arizona_gpio, gpio_chip); 34 - } 35 - 36 31 static int arizona_gpio_direction_in(struct gpio_chip *chip, unsigned offset) 37 32 { 38 - struct arizona_gpio *arizona_gpio = to_arizona_gpio(chip); 33 + struct arizona_gpio *arizona_gpio = gpiochip_get_data(chip); 39 34 struct arizona *arizona = arizona_gpio->arizona; 40 35 41 36 return regmap_update_bits(arizona->regmap, ARIZONA_GPIO1_CTRL + offset, ··· 39 44 40 45 static int arizona_gpio_get(struct gpio_chip *chip, unsigned offset) 41 46 { 42 - struct arizona_gpio *arizona_gpio = to_arizona_gpio(chip); 47 + struct arizona_gpio *arizona_gpio = gpiochip_get_data(chip); 43 48 struct arizona *arizona = arizona_gpio->arizona; 44 49 unsigned int val; 45 50 int ret; ··· 57 62 static int arizona_gpio_direction_out(struct gpio_chip *chip, 58 63 unsigned offset, int value) 59 64 { 60 - struct arizona_gpio *arizona_gpio = to_arizona_gpio(chip); 65 + struct arizona_gpio *arizona_gpio = gpiochip_get_data(chip); 61 66 struct arizona *arizona = arizona_gpio->arizona; 62 67 63 68 if (value) ··· 69 74 70 75 static void arizona_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 71 76 { 72 - struct arizona_gpio *arizona_gpio = to_arizona_gpio(chip); 77 + struct arizona_gpio *arizona_gpio = gpiochip_get_data(chip); 73 78 struct arizona *arizona = arizona_gpio->arizona; 74 79 75 80 if (value) ··· 103 108 104 109 arizona_gpio->arizona = arizona; 105 110 arizona_gpio->gpio_chip = template_chip; 106 - arizona_gpio->gpio_chip.dev = &pdev->dev; 111 + arizona_gpio->gpio_chip.parent = &pdev->dev; 107 112 #ifdef CONFIG_OF_GPIO 108 113 arizona_gpio->gpio_chip.of_node = arizona->dev->of_node; 109 114 #endif ··· 132 137 else 133 138 arizona_gpio->gpio_chip.base = -1; 134 139 135 - ret = gpiochip_add(&arizona_gpio->gpio_chip); 140 + ret = gpiochip_add_data(&arizona_gpio->gpio_chip, arizona_gpio); 136 141 if (ret < 0) { 137 142 dev_err(&pdev->dev, "Could not register gpiochip, %d\n", 138 143 ret);
+9 -11
drivers/gpio/gpio-ath79.c
··· 24 24 spinlock_t lock; 25 25 }; 26 26 27 - #define to_ath79_gpio_ctrl(c) container_of(c, struct ath79_gpio_ctrl, chip) 28 - 29 27 static void ath79_gpio_set_value(struct gpio_chip *chip, 30 28 unsigned gpio, int value) 31 29 { 32 - struct ath79_gpio_ctrl *ctrl = to_ath79_gpio_ctrl(chip); 30 + struct ath79_gpio_ctrl *ctrl = gpiochip_get_data(chip); 33 31 34 32 if (value) 35 33 __raw_writel(BIT(gpio), ctrl->base + AR71XX_GPIO_REG_SET); ··· 37 39 38 40 static int ath79_gpio_get_value(struct gpio_chip *chip, unsigned gpio) 39 41 { 40 - struct ath79_gpio_ctrl *ctrl = to_ath79_gpio_ctrl(chip); 42 + struct ath79_gpio_ctrl *ctrl = gpiochip_get_data(chip); 41 43 42 44 return (__raw_readl(ctrl->base + AR71XX_GPIO_REG_IN) >> gpio) & 1; 43 45 } ··· 45 47 static int ath79_gpio_direction_input(struct gpio_chip *chip, 46 48 unsigned offset) 47 49 { 48 - struct ath79_gpio_ctrl *ctrl = to_ath79_gpio_ctrl(chip); 50 + struct ath79_gpio_ctrl *ctrl = gpiochip_get_data(chip); 49 51 unsigned long flags; 50 52 51 53 spin_lock_irqsave(&ctrl->lock, flags); ··· 62 64 static int ath79_gpio_direction_output(struct gpio_chip *chip, 63 65 unsigned offset, int value) 64 66 { 65 - struct ath79_gpio_ctrl *ctrl = to_ath79_gpio_ctrl(chip); 67 + struct ath79_gpio_ctrl *ctrl = gpiochip_get_data(chip); 66 68 unsigned long flags; 67 69 68 70 spin_lock_irqsave(&ctrl->lock, flags); ··· 83 85 84 86 static int ar934x_gpio_direction_input(struct gpio_chip *chip, unsigned offset) 85 87 { 86 - struct ath79_gpio_ctrl *ctrl = to_ath79_gpio_ctrl(chip); 88 + struct ath79_gpio_ctrl *ctrl = gpiochip_get_data(chip); 87 89 unsigned long flags; 88 90 89 91 spin_lock_irqsave(&ctrl->lock, flags); ··· 100 102 static int ar934x_gpio_direction_output(struct gpio_chip *chip, unsigned offset, 101 103 int value) 102 104 { 103 - struct ath79_gpio_ctrl *ctrl = to_ath79_gpio_ctrl(chip); 105 + struct ath79_gpio_ctrl *ctrl = gpiochip_get_data(chip); 104 106 unsigned long flags; 105 107 106 108 spin_lock_irqsave(&ctrl->lock, flags); ··· 136 138 137 139 static int ath79_gpio_probe(struct platform_device *pdev) 138 140 { 139 - struct ath79_gpio_platform_data *pdata = pdev->dev.platform_data; 141 + struct ath79_gpio_platform_data *pdata = dev_get_platdata(&pdev->dev); 140 142 struct device_node *np = pdev->dev.of_node; 141 143 struct ath79_gpio_ctrl *ctrl; 142 144 struct resource *res; ··· 175 177 176 178 spin_lock_init(&ctrl->lock); 177 179 memcpy(&ctrl->chip, &ath79_gpio_chip, sizeof(ctrl->chip)); 178 - ctrl->chip.dev = &pdev->dev; 180 + ctrl->chip.parent = &pdev->dev; 179 181 ctrl->chip.ngpio = ath79_gpio_count; 180 182 if (oe_inverted) { 181 183 ctrl->chip.direction_input = ar934x_gpio_direction_input; 182 184 ctrl->chip.direction_output = ar934x_gpio_direction_output; 183 185 } 184 186 185 - err = gpiochip_add(&ctrl->chip); 187 + err = gpiochip_add_data(&ctrl->chip, ctrl); 186 188 if (err) { 187 189 dev_err(&pdev->dev, 188 190 "cannot add AR71xx GPIO chip, error=%d", err);
+13 -18
drivers/gpio/gpio-bcm-kona.c
··· 78 78 struct bcm_kona_gpio *kona_gpio; 79 79 }; 80 80 81 - static inline struct bcm_kona_gpio *to_kona_gpio(struct gpio_chip *chip) 82 - { 83 - return container_of(chip, struct bcm_kona_gpio, gpio_chip); 84 - } 85 - 86 81 static inline void bcm_kona_gpio_write_lock_regs(void __iomem *reg_base, 87 82 int bank_id, u32 lockcode) 88 83 { ··· 119 124 120 125 static int bcm_kona_gpio_get_dir(struct gpio_chip *chip, unsigned gpio) 121 126 { 122 - struct bcm_kona_gpio *kona_gpio = to_kona_gpio(chip); 127 + struct bcm_kona_gpio *kona_gpio = gpiochip_get_data(chip); 123 128 void __iomem *reg_base = kona_gpio->reg_base; 124 129 u32 val; 125 130 ··· 136 141 u32 val, reg_offset; 137 142 unsigned long flags; 138 143 139 - kona_gpio = to_kona_gpio(chip); 144 + kona_gpio = gpiochip_get_data(chip); 140 145 reg_base = kona_gpio->reg_base; 141 146 spin_lock_irqsave(&kona_gpio->lock, flags); 142 147 ··· 163 168 u32 val, reg_offset; 164 169 unsigned long flags; 165 170 166 - kona_gpio = to_kona_gpio(chip); 171 + kona_gpio = gpiochip_get_data(chip); 167 172 reg_base = kona_gpio->reg_base; 168 173 spin_lock_irqsave(&kona_gpio->lock, flags); 169 174 ··· 183 188 184 189 static int bcm_kona_gpio_request(struct gpio_chip *chip, unsigned gpio) 185 190 { 186 - struct bcm_kona_gpio *kona_gpio = to_kona_gpio(chip); 191 + struct bcm_kona_gpio *kona_gpio = gpiochip_get_data(chip); 187 192 188 193 bcm_kona_gpio_unlock_gpio(kona_gpio, gpio); 189 194 return 0; ··· 191 196 192 197 static void bcm_kona_gpio_free(struct gpio_chip *chip, unsigned gpio) 193 198 { 194 - struct bcm_kona_gpio *kona_gpio = to_kona_gpio(chip); 199 + struct bcm_kona_gpio *kona_gpio = gpiochip_get_data(chip); 195 200 196 201 bcm_kona_gpio_lock_gpio(kona_gpio, gpio); 197 202 } ··· 203 208 u32 val; 204 209 unsigned long flags; 205 210 206 - kona_gpio = to_kona_gpio(chip); 211 + kona_gpio = gpiochip_get_data(chip); 207 212 reg_base = kona_gpio->reg_base; 208 213 spin_lock_irqsave(&kona_gpio->lock, flags); 209 214 ··· 227 232 u32 val, reg_offset; 228 233 unsigned long flags; 229 234 230 - kona_gpio = to_kona_gpio(chip); 235 + kona_gpio = gpiochip_get_data(chip); 231 236 reg_base = kona_gpio->reg_base; 232 237 spin_lock_irqsave(&kona_gpio->lock, flags); 233 238 ··· 250 255 { 251 256 struct bcm_kona_gpio *kona_gpio; 252 257 253 - kona_gpio = to_kona_gpio(chip); 258 + kona_gpio = gpiochip_get_data(chip); 254 259 if (gpio >= kona_gpio->gpio_chip.ngpio) 255 260 return -ENXIO; 256 261 return irq_create_mapping(kona_gpio->irq_domain, gpio); ··· 264 269 u32 val, res; 265 270 unsigned long flags; 266 271 267 - kona_gpio = to_kona_gpio(chip); 272 + kona_gpio = gpiochip_get_data(chip); 268 273 reg_base = kona_gpio->reg_base; 269 274 /* debounce must be 1-128ms (or 0) */ 270 275 if ((debounce > 0 && debounce < 1000) || debounce > 128000) { 271 - dev_err(chip->dev, "Debounce value %u not in range\n", 276 + dev_err(chip->parent, "Debounce value %u not in range\n", 272 277 debounce); 273 278 return -EINVAL; 274 279 } ··· 411 416 case IRQ_TYPE_LEVEL_LOW: 412 417 /* BCM GPIO doesn't support level triggering */ 413 418 default: 414 - dev_err(kona_gpio->gpio_chip.dev, 419 + dev_err(kona_gpio->gpio_chip.parent, 415 420 "Invalid BCM GPIO irq type 0x%x\n", type); 416 421 return -EINVAL; 417 422 } ··· 472 477 struct bcm_kona_gpio *kona_gpio = irq_data_get_irq_chip_data(d); 473 478 474 479 if (gpiochip_lock_as_irq(&kona_gpio->gpio_chip, d->hwirq)) { 475 - dev_err(kona_gpio->gpio_chip.dev, 480 + dev_err(kona_gpio->gpio_chip.parent, 476 481 "unable to lock HW IRQ %lu for IRQ\n", 477 482 d->hwirq); 478 483 return -EINVAL; ··· 630 635 631 636 bcm_kona_gpio_reset(kona_gpio); 632 637 633 - ret = gpiochip_add(chip); 638 + ret = gpiochip_add_data(chip, kona_gpio); 634 639 if (ret < 0) { 635 640 dev_err(dev, "Couldn't add GPIO chip -- %d\n", ret); 636 641 goto err_irq_domain;
+48 -47
drivers/gpio/gpio-brcmstb.c
··· 16 16 #include <linux/of_device.h> 17 17 #include <linux/of_irq.h> 18 18 #include <linux/module.h> 19 - #include <linux/basic_mmio_gpio.h> 20 19 #include <linux/irqdomain.h> 21 20 #include <linux/irqchip/chained_irq.h> 22 21 #include <linux/interrupt.h> ··· 34 35 struct brcmstb_gpio_bank { 35 36 struct list_head node; 36 37 int id; 37 - struct bgpio_chip bgc; 38 + struct gpio_chip gc; 38 39 struct brcmstb_gpio_priv *parent_priv; 39 40 u32 width; 40 41 struct irq_chip irq_chip; ··· 56 57 /* assumes MAX_GPIO_PER_BANK is a multiple of 2 */ 57 58 #define GPIO_BIT(gpio) ((gpio) & (MAX_GPIO_PER_BANK - 1)) 58 59 59 - static inline struct brcmstb_gpio_bank * 60 - brcmstb_gpio_gc_to_bank(struct gpio_chip *gc) 61 - { 62 - struct bgpio_chip *bgc = to_bgpio_chip(gc); 63 - return container_of(bgc, struct brcmstb_gpio_bank, bgc); 64 - } 65 - 66 60 static inline struct brcmstb_gpio_priv * 67 61 brcmstb_gpio_gc_to_priv(struct gpio_chip *gc) 68 62 { 69 - struct brcmstb_gpio_bank *bank = brcmstb_gpio_gc_to_bank(gc); 63 + struct brcmstb_gpio_bank *bank = gpiochip_get_data(gc); 70 64 return bank->parent_priv; 71 65 } 72 66 73 67 static void brcmstb_gpio_set_imask(struct brcmstb_gpio_bank *bank, 74 68 unsigned int offset, bool enable) 75 69 { 76 - struct bgpio_chip *bgc = &bank->bgc; 70 + struct gpio_chip *gc = &bank->gc; 77 71 struct brcmstb_gpio_priv *priv = bank->parent_priv; 78 - u32 mask = bgc->pin2mask(bgc, offset); 72 + u32 mask = gc->pin2mask(gc, offset); 79 73 u32 imask; 80 74 unsigned long flags; 81 75 82 - spin_lock_irqsave(&bgc->lock, flags); 83 - imask = bgc->read_reg(priv->reg_base + GIO_MASK(bank->id)); 76 + spin_lock_irqsave(&gc->bgpio_lock, flags); 77 + imask = gc->read_reg(priv->reg_base + GIO_MASK(bank->id)); 84 78 if (enable) 85 79 imask |= mask; 86 80 else 87 81 imask &= ~mask; 88 - bgc->write_reg(priv->reg_base + GIO_MASK(bank->id), imask); 89 - spin_unlock_irqrestore(&bgc->lock, flags); 82 + gc->write_reg(priv->reg_base + GIO_MASK(bank->id), imask); 83 + spin_unlock_irqrestore(&gc->bgpio_lock, flags); 90 84 } 91 85 92 86 /* -------------------- IRQ chip functions -------------------- */ ··· 87 95 static void brcmstb_gpio_irq_mask(struct irq_data *d) 88 96 { 89 97 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 90 - struct brcmstb_gpio_bank *bank = brcmstb_gpio_gc_to_bank(gc); 98 + struct brcmstb_gpio_bank *bank = gpiochip_get_data(gc); 91 99 92 100 brcmstb_gpio_set_imask(bank, d->hwirq, false); 93 101 } ··· 95 103 static void brcmstb_gpio_irq_unmask(struct irq_data *d) 96 104 { 97 105 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 98 - struct brcmstb_gpio_bank *bank = brcmstb_gpio_gc_to_bank(gc); 106 + struct brcmstb_gpio_bank *bank = gpiochip_get_data(gc); 99 107 100 108 brcmstb_gpio_set_imask(bank, d->hwirq, true); 101 109 } ··· 103 111 static int brcmstb_gpio_irq_set_type(struct irq_data *d, unsigned int type) 104 112 { 105 113 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 106 - struct brcmstb_gpio_bank *bank = brcmstb_gpio_gc_to_bank(gc); 114 + struct brcmstb_gpio_bank *bank = gpiochip_get_data(gc); 107 115 struct brcmstb_gpio_priv *priv = bank->parent_priv; 108 116 u32 mask = BIT(d->hwirq); 109 117 u32 edge_insensitive, iedge_insensitive; ··· 141 149 return -EINVAL; 142 150 } 143 151 144 - spin_lock_irqsave(&bank->bgc.lock, flags); 152 + spin_lock_irqsave(&bank->gc.bgpio_lock, flags); 145 153 146 - iedge_config = bank->bgc.read_reg(priv->reg_base + 154 + iedge_config = bank->gc.read_reg(priv->reg_base + 147 155 GIO_EC(bank->id)) & ~mask; 148 - iedge_insensitive = bank->bgc.read_reg(priv->reg_base + 156 + iedge_insensitive = bank->gc.read_reg(priv->reg_base + 149 157 GIO_EI(bank->id)) & ~mask; 150 - ilevel = bank->bgc.read_reg(priv->reg_base + 158 + ilevel = bank->gc.read_reg(priv->reg_base + 151 159 GIO_LEVEL(bank->id)) & ~mask; 152 160 153 - bank->bgc.write_reg(priv->reg_base + GIO_EC(bank->id), 161 + bank->gc.write_reg(priv->reg_base + GIO_EC(bank->id), 154 162 iedge_config | edge_config); 155 - bank->bgc.write_reg(priv->reg_base + GIO_EI(bank->id), 163 + bank->gc.write_reg(priv->reg_base + GIO_EI(bank->id), 156 164 iedge_insensitive | edge_insensitive); 157 - bank->bgc.write_reg(priv->reg_base + GIO_LEVEL(bank->id), 165 + bank->gc.write_reg(priv->reg_base + GIO_LEVEL(bank->id), 158 166 ilevel | level); 159 167 160 - spin_unlock_irqrestore(&bank->bgc.lock, flags); 168 + spin_unlock_irqrestore(&bank->gc.bgpio_lock, flags); 161 169 return 0; 162 170 } 163 171 ··· 202 210 static void brcmstb_gpio_irq_bank_handler(struct brcmstb_gpio_bank *bank) 203 211 { 204 212 struct brcmstb_gpio_priv *priv = bank->parent_priv; 205 - struct irq_domain *irq_domain = bank->bgc.gc.irqdomain; 213 + struct irq_domain *irq_domain = bank->gc.irqdomain; 206 214 void __iomem *reg_base = priv->reg_base; 207 215 unsigned long status; 208 216 unsigned long flags; 209 217 210 - spin_lock_irqsave(&bank->bgc.lock, flags); 211 - while ((status = bank->bgc.read_reg(reg_base + GIO_STAT(bank->id)) & 212 - bank->bgc.read_reg(reg_base + GIO_MASK(bank->id)))) { 218 + spin_lock_irqsave(&bank->gc.bgpio_lock, flags); 219 + while ((status = bank->gc.read_reg(reg_base + GIO_STAT(bank->id)) & 220 + bank->gc.read_reg(reg_base + GIO_MASK(bank->id)))) { 213 221 int bit; 214 222 215 223 for_each_set_bit(bit, &status, 32) { 216 - u32 stat = bank->bgc.read_reg(reg_base + 224 + u32 stat = bank->gc.read_reg(reg_base + 217 225 GIO_STAT(bank->id)); 218 226 if (bit >= bank->width) 219 227 dev_warn(&priv->pdev->dev, 220 228 "IRQ for invalid GPIO (bank=%d, offset=%d)\n", 221 229 bank->id, bit); 222 - bank->bgc.write_reg(reg_base + GIO_STAT(bank->id), 230 + bank->gc.write_reg(reg_base + GIO_STAT(bank->id), 223 231 stat | BIT(bit)); 224 232 generic_handle_irq(irq_find_mapping(irq_domain, bit)); 225 233 } 226 234 } 227 - spin_unlock_irqrestore(&bank->bgc.lock, flags); 235 + spin_unlock_irqrestore(&bank->gc.bgpio_lock, flags); 228 236 } 229 237 230 238 /* Each UPG GIO block has one IRQ for all banks */ ··· 295 303 */ 296 304 list_for_each(pos, &priv->bank_list) { 297 305 bank = list_entry(pos, struct brcmstb_gpio_bank, node); 298 - ret = bgpio_remove(&bank->bgc); 299 - if (ret) 300 - dev_err(&pdev->dev, "gpiochip_remove fail in cleanup\n"); 306 + gpiochip_remove(&bank->gc); 301 307 } 302 308 if (priv->reboot_notifier.notifier_call) { 303 309 ret = unregister_reboot_notifier(&priv->reboot_notifier); ··· 310 320 const struct of_phandle_args *gpiospec, u32 *flags) 311 321 { 312 322 struct brcmstb_gpio_priv *priv = brcmstb_gpio_gc_to_priv(gc); 313 - struct brcmstb_gpio_bank *bank = brcmstb_gpio_gc_to_bank(gc); 323 + struct brcmstb_gpio_bank *bank = gpiochip_get_data(gc); 314 324 int offset; 315 325 316 326 if (gc->of_gpio_n_cells != 2) { ··· 388 398 if (priv->can_wake) 389 399 bank->irq_chip.irq_set_wake = brcmstb_gpio_irq_set_wake; 390 400 391 - gpiochip_irqchip_add(&bank->bgc.gc, &bank->irq_chip, 0, 401 + gpiochip_irqchip_add(&bank->gc, &bank->irq_chip, 0, 392 402 handle_simple_irq, IRQ_TYPE_NONE); 393 - gpiochip_set_chained_irqchip(&bank->bgc.gc, &bank->irq_chip, 403 + gpiochip_set_chained_irqchip(&bank->gc, &bank->irq_chip, 394 404 priv->parent_irq, brcmstb_gpio_irq_handler); 395 405 396 406 return 0; ··· 409 419 int num_banks = 0; 410 420 int err; 411 421 static int gpio_base; 422 + unsigned long flags = 0; 412 423 413 424 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 414 425 if (!priv) ··· 439 448 if (brcmstb_gpio_sanity_check_banks(dev, np, res)) 440 449 return -EINVAL; 441 450 451 + /* 452 + * MIPS endianness is configured by boot strap, which also reverses all 453 + * bus endianness (i.e., big-endian CPU + big endian bus ==> native 454 + * endian I/O). 455 + * 456 + * Other architectures (e.g., ARM) either do not support big endian, or 457 + * else leave I/O in little endian mode. 458 + */ 459 + #if defined(CONFIG_MIPS) && defined(__BIG_ENDIAN) 460 + flags = BGPIOF_BIG_ENDIAN_BYTE_ORDER; 461 + #endif 462 + 442 463 of_property_for_each_u32(np, "brcm,gpio-bank-widths", prop, p, 443 464 bank_width) { 444 465 struct brcmstb_gpio_bank *bank; 445 - struct bgpio_chip *bgc; 446 466 struct gpio_chip *gc; 447 467 448 468 bank = devm_kzalloc(dev, sizeof(*bank), GFP_KERNEL); ··· 475 473 * Regs are 4 bytes wide, have data reg, no set/clear regs, 476 474 * and direction bits have 0 = output and 1 = input 477 475 */ 478 - bgc = &bank->bgc; 479 - err = bgpio_init(bgc, dev, 4, 476 + gc = &bank->gc; 477 + err = bgpio_init(gc, dev, 4, 480 478 reg_base + GIO_DATA(bank->id), 481 479 NULL, NULL, NULL, 482 - reg_base + GIO_IODIR(bank->id), 0); 480 + reg_base + GIO_IODIR(bank->id), flags); 483 481 if (err) { 484 482 dev_err(dev, "bgpio_init() failed\n"); 485 483 goto fail; 486 484 } 487 485 488 - gc = &bgc->gc; 489 486 gc->of_node = np; 490 487 gc->owner = THIS_MODULE; 491 488 gc->label = np->full_name; ··· 498 497 * Mask all interrupts by default, since wakeup interrupts may 499 498 * be retained from S5 cold boot 500 499 */ 501 - bank->bgc.write_reg(reg_base + GIO_MASK(bank->id), 0); 500 + gc->write_reg(reg_base + GIO_MASK(bank->id), 0); 502 501 503 - err = gpiochip_add(gc); 502 + err = gpiochip_add_data(gc, bank); 504 503 if (err) { 505 504 dev_err(dev, "Could not add gpiochip for bank %d\n", 506 505 bank->id);
+5 -5
drivers/gpio/gpio-bt8xx.c
··· 80 80 81 81 static int bt8xxgpio_gpio_direction_input(struct gpio_chip *gpio, unsigned nr) 82 82 { 83 - struct bt8xxgpio *bg = container_of(gpio, struct bt8xxgpio, gpio); 83 + struct bt8xxgpio *bg = gpiochip_get_data(gpio); 84 84 unsigned long flags; 85 85 u32 outen, data; 86 86 ··· 101 101 102 102 static int bt8xxgpio_gpio_get(struct gpio_chip *gpio, unsigned nr) 103 103 { 104 - struct bt8xxgpio *bg = container_of(gpio, struct bt8xxgpio, gpio); 104 + struct bt8xxgpio *bg = gpiochip_get_data(gpio); 105 105 unsigned long flags; 106 106 u32 val; 107 107 ··· 115 115 static int bt8xxgpio_gpio_direction_output(struct gpio_chip *gpio, 116 116 unsigned nr, int val) 117 117 { 118 - struct bt8xxgpio *bg = container_of(gpio, struct bt8xxgpio, gpio); 118 + struct bt8xxgpio *bg = gpiochip_get_data(gpio); 119 119 unsigned long flags; 120 120 u32 outen, data; 121 121 ··· 140 140 static void bt8xxgpio_gpio_set(struct gpio_chip *gpio, 141 141 unsigned nr, int val) 142 142 { 143 - struct bt8xxgpio *bg = container_of(gpio, struct bt8xxgpio, gpio); 143 + struct bt8xxgpio *bg = gpiochip_get_data(gpio); 144 144 unsigned long flags; 145 145 u32 data; 146 146 ··· 217 217 bgwrite(0, BT848_GPIO_OUT_EN); 218 218 219 219 bt8xxgpio_gpio_setup(bg); 220 - err = gpiochip_add(&bg->gpio); 220 + err = gpiochip_add_data(&bg->gpio, bg); 221 221 if (err) { 222 222 printk(KERN_ERR "bt8xxgpio: Failed to register GPIOs\n"); 223 223 goto err_disable;
+14 -14
drivers/gpio/gpio-clps711x.c
··· 10 10 */ 11 11 12 12 #include <linux/err.h> 13 - #include <linux/gpio.h> 14 13 #include <linux/module.h> 15 - #include <linux/basic_mmio_gpio.h> 14 + #include <linux/gpio/driver.h> 16 15 #include <linux/platform_device.h> 17 16 18 17 static int clps711x_gpio_probe(struct platform_device *pdev) 19 18 { 20 19 struct device_node *np = pdev->dev.of_node; 21 20 void __iomem *dat, *dir; 22 - struct bgpio_chip *bgc; 21 + struct gpio_chip *gc; 23 22 struct resource *res; 24 23 int err, id = np ? of_alias_get_id(np, "gpio") : pdev->id; 25 24 26 25 if ((id < 0) || (id > 4)) 27 26 return -ENODEV; 28 27 29 - bgc = devm_kzalloc(&pdev->dev, sizeof(*bgc), GFP_KERNEL); 30 - if (!bgc) 28 + gc = devm_kzalloc(&pdev->dev, sizeof(*gc), GFP_KERNEL); 29 + if (!gc) 31 30 return -ENOMEM; 32 31 33 32 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); ··· 42 43 switch (id) { 43 44 case 3: 44 45 /* PORTD is inverted logic for direction register */ 45 - err = bgpio_init(bgc, &pdev->dev, 1, dat, NULL, NULL, 46 + err = bgpio_init(gc, &pdev->dev, 1, dat, NULL, NULL, 46 47 NULL, dir, 0); 47 48 break; 48 49 default: 49 - err = bgpio_init(bgc, &pdev->dev, 1, dat, NULL, NULL, 50 + err = bgpio_init(gc, &pdev->dev, 1, dat, NULL, NULL, 50 51 dir, NULL, 0); 51 52 break; 52 53 } ··· 57 58 switch (id) { 58 59 case 4: 59 60 /* PORTE is 3 lines only */ 60 - bgc->gc.ngpio = 3; 61 + gc->ngpio = 3; 61 62 break; 62 63 default: 63 64 break; 64 65 } 65 66 66 - bgc->gc.base = id * 8; 67 - bgc->gc.owner = THIS_MODULE; 68 - platform_set_drvdata(pdev, bgc); 67 + gc->base = id * 8; 68 + gc->owner = THIS_MODULE; 69 + platform_set_drvdata(pdev, gc); 69 70 70 - return gpiochip_add(&bgc->gc); 71 + return gpiochip_add_data(gc, NULL); 71 72 } 72 73 73 74 static int clps711x_gpio_remove(struct platform_device *pdev) 74 75 { 75 - struct bgpio_chip *bgc = platform_get_drvdata(pdev); 76 + struct gpio_chip *gc = platform_get_drvdata(pdev); 76 77 77 - return bgpio_remove(bgc); 78 + gpiochip_remove(gc); 79 + return 0; 78 80 } 79 81 80 82 static const struct of_device_id __maybe_unused clps711x_gpio_ids[] = {
+17 -17
drivers/gpio/gpio-crystalcove.c
··· 86 86 bool set_irq_mask; 87 87 }; 88 88 89 - static inline struct crystalcove_gpio *to_cg(struct gpio_chip *gc) 90 - { 91 - return container_of(gc, struct crystalcove_gpio, chip); 92 - } 93 - 94 89 static inline int to_reg(int gpio, enum ctrl_register reg_type) 95 90 { 96 91 int reg; ··· 129 134 130 135 static int crystalcove_gpio_dir_in(struct gpio_chip *chip, unsigned gpio) 131 136 { 132 - struct crystalcove_gpio *cg = to_cg(chip); 137 + struct crystalcove_gpio *cg = gpiochip_get_data(chip); 133 138 134 139 if (gpio > CRYSTALCOVE_VGPIO_NUM) 135 140 return 0; ··· 141 146 static int crystalcove_gpio_dir_out(struct gpio_chip *chip, unsigned gpio, 142 147 int value) 143 148 { 144 - struct crystalcove_gpio *cg = to_cg(chip); 149 + struct crystalcove_gpio *cg = gpiochip_get_data(chip); 145 150 146 151 if (gpio > CRYSTALCOVE_VGPIO_NUM) 147 152 return 0; ··· 152 157 153 158 static int crystalcove_gpio_get(struct gpio_chip *chip, unsigned gpio) 154 159 { 155 - struct crystalcove_gpio *cg = to_cg(chip); 160 + struct crystalcove_gpio *cg = gpiochip_get_data(chip); 156 161 int ret; 157 162 unsigned int val; 158 163 ··· 169 174 static void crystalcove_gpio_set(struct gpio_chip *chip, 170 175 unsigned gpio, int value) 171 176 { 172 - struct crystalcove_gpio *cg = to_cg(chip); 177 + struct crystalcove_gpio *cg = gpiochip_get_data(chip); 173 178 174 179 if (gpio > CRYSTALCOVE_VGPIO_NUM) 175 180 return; ··· 182 187 183 188 static int crystalcove_irq_type(struct irq_data *data, unsigned type) 184 189 { 185 - struct crystalcove_gpio *cg = to_cg(irq_data_get_irq_chip_data(data)); 190 + struct crystalcove_gpio *cg = 191 + gpiochip_get_data(irq_data_get_irq_chip_data(data)); 186 192 187 193 switch (type) { 188 194 case IRQ_TYPE_NONE: ··· 209 213 210 214 static void crystalcove_bus_lock(struct irq_data *data) 211 215 { 212 - struct crystalcove_gpio *cg = to_cg(irq_data_get_irq_chip_data(data)); 216 + struct crystalcove_gpio *cg = 217 + gpiochip_get_data(irq_data_get_irq_chip_data(data)); 213 218 214 219 mutex_lock(&cg->buslock); 215 220 } 216 221 217 222 static void crystalcove_bus_sync_unlock(struct irq_data *data) 218 223 { 219 - struct crystalcove_gpio *cg = to_cg(irq_data_get_irq_chip_data(data)); 224 + struct crystalcove_gpio *cg = 225 + gpiochip_get_data(irq_data_get_irq_chip_data(data)); 220 226 int gpio = data->hwirq; 221 227 222 228 if (cg->update & UPDATE_IRQ_TYPE) ··· 232 234 233 235 static void crystalcove_irq_unmask(struct irq_data *data) 234 236 { 235 - struct crystalcove_gpio *cg = to_cg(irq_data_get_irq_chip_data(data)); 237 + struct crystalcove_gpio *cg = 238 + gpiochip_get_data(irq_data_get_irq_chip_data(data)); 236 239 237 240 cg->set_irq_mask = false; 238 241 cg->update |= UPDATE_IRQ_MASK; ··· 241 242 242 243 static void crystalcove_irq_mask(struct irq_data *data) 243 244 { 244 - struct crystalcove_gpio *cg = to_cg(irq_data_get_irq_chip_data(data)); 245 + struct crystalcove_gpio *cg = 246 + gpiochip_get_data(irq_data_get_irq_chip_data(data)); 245 247 246 248 cg->set_irq_mask = true; 247 249 cg->update |= UPDATE_IRQ_MASK; ··· 288 288 static void crystalcove_gpio_dbg_show(struct seq_file *s, 289 289 struct gpio_chip *chip) 290 290 { 291 - struct crystalcove_gpio *cg = to_cg(chip); 291 + struct crystalcove_gpio *cg = gpiochip_get_data(chip); 292 292 int gpio, offset; 293 293 unsigned int ctlo, ctli, mirqs0, mirqsx, irq; 294 294 ··· 341 341 cg->chip.base = -1; 342 342 cg->chip.ngpio = CRYSTALCOVE_VGPIO_NUM; 343 343 cg->chip.can_sleep = true; 344 - cg->chip.dev = dev; 344 + cg->chip.parent = dev; 345 345 cg->chip.dbg_show = crystalcove_gpio_dbg_show; 346 346 cg->regmap = pmic->regmap; 347 347 348 - retval = gpiochip_add(&cg->chip); 348 + retval = gpiochip_add_data(&cg->chip, cg); 349 349 if (retval) { 350 350 dev_warn(&pdev->dev, "add gpio chip error: %d\n", retval); 351 351 return retval;
+8 -7
drivers/gpio/gpio-cs5535.c
··· 42 42 module_param_named(mask, mask, ulong, 0444); 43 43 MODULE_PARM_DESC(mask, "GPIO channel mask."); 44 44 45 + /* 46 + * FIXME: convert this singleton driver to use the state container 47 + * design pattern, see Documentation/driver-model/design-patterns.txt 48 + */ 45 49 static struct cs5535_gpio_chip { 46 50 struct gpio_chip chip; 47 51 resource_size_t base; ··· 205 201 206 202 static int chip_gpio_request(struct gpio_chip *c, unsigned offset) 207 203 { 208 - struct cs5535_gpio_chip *chip = 209 - container_of(c, struct cs5535_gpio_chip, chip); 204 + struct cs5535_gpio_chip *chip = gpiochip_get_data(c); 210 205 unsigned long flags; 211 206 212 207 spin_lock_irqsave(&chip->lock, flags); ··· 245 242 246 243 static int chip_direction_input(struct gpio_chip *c, unsigned offset) 247 244 { 248 - struct cs5535_gpio_chip *chip = 249 - container_of(c, struct cs5535_gpio_chip, chip); 245 + struct cs5535_gpio_chip *chip = gpiochip_get_data(c); 250 246 unsigned long flags; 251 247 252 248 spin_lock_irqsave(&chip->lock, flags); ··· 258 256 259 257 static int chip_direction_output(struct gpio_chip *c, unsigned offset, int val) 260 258 { 261 - struct cs5535_gpio_chip *chip = 262 - container_of(c, struct cs5535_gpio_chip, chip); 259 + struct cs5535_gpio_chip *chip = gpiochip_get_data(c); 263 260 unsigned long flags; 264 261 265 262 spin_lock_irqsave(&chip->lock, flags); ··· 348 347 mask_orig, mask); 349 348 350 349 /* finally, register with the generic GPIO API */ 351 - err = gpiochip_add(&cs5535_gpio_chip.chip); 350 + err = gpiochip_add_data(&cs5535_gpio_chip.chip, &cs5535_gpio_chip); 352 351 if (err) 353 352 goto done; 354 353
+9 -17
drivers/gpio/gpio-da9052.c
··· 51 51 struct gpio_chip gp; 52 52 }; 53 53 54 - static inline struct da9052_gpio *to_da9052_gpio(struct gpio_chip *chip) 55 - { 56 - return container_of(chip, struct da9052_gpio, gp); 57 - } 58 - 59 54 static unsigned char da9052_gpio_port_odd(unsigned offset) 60 55 { 61 56 return offset % 2; ··· 58 63 59 64 static int da9052_gpio_get(struct gpio_chip *gc, unsigned offset) 60 65 { 61 - struct da9052_gpio *gpio = to_da9052_gpio(gc); 66 + struct da9052_gpio *gpio = gpiochip_get_data(gc); 62 67 int da9052_port_direction = 0; 63 68 int ret; 64 69 ··· 84 89 DA9052_STATUS_D_REG); 85 90 if (ret < 0) 86 91 return ret; 87 - if (ret & (1 << DA9052_GPIO_SHIFT_COUNT(offset))) 88 - return 1; 89 - else 90 - return 0; 92 + return !!(ret & (1 << DA9052_GPIO_SHIFT_COUNT(offset))); 91 93 case DA9052_OUTPUT_PUSHPULL: 92 94 if (da9052_gpio_port_odd(offset)) 93 - return ret & DA9052_GPIO_ODD_PORT_MODE; 95 + return !!(ret & DA9052_GPIO_ODD_PORT_MODE); 94 96 else 95 - return ret & DA9052_GPIO_EVEN_PORT_MODE; 97 + return !!(ret & DA9052_GPIO_EVEN_PORT_MODE); 96 98 default: 97 99 return -EINVAL; 98 100 } ··· 97 105 98 106 static void da9052_gpio_set(struct gpio_chip *gc, unsigned offset, int value) 99 107 { 100 - struct da9052_gpio *gpio = to_da9052_gpio(gc); 108 + struct da9052_gpio *gpio = gpiochip_get_data(gc); 101 109 int ret; 102 110 103 111 if (da9052_gpio_port_odd(offset)) { ··· 123 131 124 132 static int da9052_gpio_direction_input(struct gpio_chip *gc, unsigned offset) 125 133 { 126 - struct da9052_gpio *gpio = to_da9052_gpio(gc); 134 + struct da9052_gpio *gpio = gpiochip_get_data(gc); 127 135 unsigned char register_value; 128 136 int ret; 129 137 ··· 149 157 static int da9052_gpio_direction_output(struct gpio_chip *gc, 150 158 unsigned offset, int value) 151 159 { 152 - struct da9052_gpio *gpio = to_da9052_gpio(gc); 160 + struct da9052_gpio *gpio = gpiochip_get_data(gc); 153 161 unsigned char register_value; 154 162 int ret; 155 163 ··· 174 182 175 183 static int da9052_gpio_to_irq(struct gpio_chip *gc, u32 offset) 176 184 { 177 - struct da9052_gpio *gpio = to_da9052_gpio(gc); 185 + struct da9052_gpio *gpio = gpiochip_get_data(gc); 178 186 struct da9052 *da9052 = gpio->da9052; 179 187 180 188 int irq; ··· 214 222 if (pdata && pdata->gpio_base) 215 223 gpio->gp.base = pdata->gpio_base; 216 224 217 - ret = gpiochip_add(&gpio->gp); 225 + ret = gpiochip_add_data(&gpio->gp, gpio); 218 226 if (ret < 0) { 219 227 dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret); 220 228 return ret;
+6 -11
drivers/gpio/gpio-da9055.c
··· 35 35 struct gpio_chip gp; 36 36 }; 37 37 38 - static inline struct da9055_gpio *to_da9055_gpio(struct gpio_chip *chip) 39 - { 40 - return container_of(chip, struct da9055_gpio, gp); 41 - } 42 - 43 38 static int da9055_gpio_get(struct gpio_chip *gc, unsigned offset) 44 39 { 45 - struct da9055_gpio *gpio = to_da9055_gpio(gc); 40 + struct da9055_gpio *gpio = gpiochip_get_data(gc); 46 41 int gpio_direction = 0; 47 42 int ret; 48 43 ··· 66 71 67 72 static void da9055_gpio_set(struct gpio_chip *gc, unsigned offset, int value) 68 73 { 69 - struct da9055_gpio *gpio = to_da9055_gpio(gc); 74 + struct da9055_gpio *gpio = gpiochip_get_data(gc); 70 75 71 76 da9055_reg_update(gpio->da9055, 72 77 DA9055_REG_GPIO_MODE0_2, ··· 76 81 77 82 static int da9055_gpio_direction_input(struct gpio_chip *gc, unsigned offset) 78 83 { 79 - struct da9055_gpio *gpio = to_da9055_gpio(gc); 84 + struct da9055_gpio *gpio = gpiochip_get_data(gc); 80 85 unsigned char reg_byte; 81 86 82 87 reg_byte = (DA9055_ACT_LOW | DA9055_GPI) ··· 92 97 static int da9055_gpio_direction_output(struct gpio_chip *gc, 93 98 unsigned offset, int value) 94 99 { 95 - struct da9055_gpio *gpio = to_da9055_gpio(gc); 100 + struct da9055_gpio *gpio = gpiochip_get_data(gc); 96 101 unsigned char reg_byte; 97 102 int ret; 98 103 ··· 114 119 115 120 static int da9055_gpio_to_irq(struct gpio_chip *gc, u32 offset) 116 121 { 117 - struct da9055_gpio *gpio = to_da9055_gpio(gc); 122 + struct da9055_gpio *gpio = gpiochip_get_data(gc); 118 123 struct da9055 *da9055 = gpio->da9055; 119 124 120 125 return regmap_irq_get_virq(da9055->irq_data, ··· 151 156 if (pdata && pdata->gpio_base) 152 157 gpio->gp.base = pdata->gpio_base; 153 158 154 - ret = gpiochip_add(&gpio->gp); 159 + ret = gpiochip_add_data(&gpio->gp, gpio); 155 160 if (ret < 0) { 156 161 dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret); 157 162 goto err_mem;
+11 -14
drivers/gpio/gpio-davinci.c
··· 41 41 42 42 #define BINTEN 0x8 /* GPIO Interrupt Per-Bank Enable Register */ 43 43 44 - #define chip2controller(chip) \ 45 - container_of(chip, struct davinci_gpio_controller, chip) 46 - 47 44 static void __iomem *gpio_base; 48 45 49 46 static struct davinci_gpio_regs __iomem *gpio2regs(unsigned gpio) ··· 79 82 static inline int __davinci_direction(struct gpio_chip *chip, 80 83 unsigned offset, bool out, int value) 81 84 { 82 - struct davinci_gpio_controller *d = chip2controller(chip); 85 + struct davinci_gpio_controller *d = gpiochip_get_data(chip); 83 86 struct davinci_gpio_regs __iomem *g = d->regs; 84 87 unsigned long flags; 85 88 u32 temp; ··· 119 122 */ 120 123 static int davinci_gpio_get(struct gpio_chip *chip, unsigned offset) 121 124 { 122 - struct davinci_gpio_controller *d = chip2controller(chip); 125 + struct davinci_gpio_controller *d = gpiochip_get_data(chip); 123 126 struct davinci_gpio_regs __iomem *g = d->regs; 124 127 125 - return (1 << offset) & readl_relaxed(&g->in_data); 128 + return !!((1 << offset) & readl_relaxed(&g->in_data)); 126 129 } 127 130 128 131 /* ··· 131 134 static void 132 135 davinci_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 133 136 { 134 - struct davinci_gpio_controller *d = chip2controller(chip); 137 + struct davinci_gpio_controller *d = gpiochip_get_data(chip); 135 138 struct davinci_gpio_regs __iomem *g = d->regs; 136 139 137 140 writel_relaxed((1 << offset), value ? &g->set_data : &g->clr_data); ··· 146 149 u32 val; 147 150 148 151 if (!IS_ENABLED(CONFIG_OF) || !pdev->dev.of_node) 149 - return pdev->dev.platform_data; 152 + return dev_get_platdata(&pdev->dev); 150 153 151 154 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); 152 155 if (!pdata) ··· 176 179 const struct of_phandle_args *gpiospec, 177 180 u32 *flags) 178 181 { 179 - struct davinci_gpio_controller *chips = dev_get_drvdata(gc->dev); 180 - struct davinci_gpio_platform_data *pdata = dev_get_platdata(gc->dev); 182 + struct davinci_gpio_controller *chips = dev_get_drvdata(gc->parent); 183 + struct davinci_gpio_platform_data *pdata = dev_get_platdata(gc->parent); 181 184 182 185 if (gpiospec->args[0] > pdata->ngpio) 183 186 return -EINVAL; ··· 251 254 #ifdef CONFIG_OF_GPIO 252 255 chips[i].chip.of_gpio_n_cells = 2; 253 256 chips[i].chip.of_xlate = davinci_gpio_of_xlate; 254 - chips[i].chip.dev = dev; 257 + chips[i].chip.parent = dev; 255 258 chips[i].chip.of_node = dev->of_node; 256 259 #endif 257 260 spin_lock_init(&chips[i].lock); ··· 262 265 chips[i].clr_data = &regs->clr_data; 263 266 chips[i].in_data = &regs->in_data; 264 267 265 - gpiochip_add(&chips[i].chip); 268 + gpiochip_add_data(&chips[i].chip, &chips[i]); 266 269 } 267 270 268 271 platform_set_drvdata(pdev, chips); ··· 365 368 366 369 static int gpio_to_irq_banked(struct gpio_chip *chip, unsigned offset) 367 370 { 368 - struct davinci_gpio_controller *d = chip2controller(chip); 371 + struct davinci_gpio_controller *d = gpiochip_get_data(chip); 369 372 370 373 if (d->irq_domain) 371 374 return irq_create_mapping(d->irq_domain, d->chip.base + offset); ··· 375 378 376 379 static int gpio_to_irq_unbanked(struct gpio_chip *chip, unsigned offset) 377 380 { 378 - struct davinci_gpio_controller *d = chip2controller(chip); 381 + struct davinci_gpio_controller *d = gpiochip_get_data(chip); 379 382 380 383 /* 381 384 * NOTE: we assume for now that only irqs in the first gpio_chip
+19 -19
drivers/gpio/gpio-dln2.c
··· 153 153 154 154 static int dln2_gpio_request(struct gpio_chip *chip, unsigned offset) 155 155 { 156 - struct dln2_gpio *dln2 = container_of(chip, struct dln2_gpio, gpio); 156 + struct dln2_gpio *dln2 = gpiochip_get_data(chip); 157 157 struct dln2_gpio_pin req = { 158 158 .pin = cpu_to_le16(offset), 159 159 }; ··· 194 194 195 195 static void dln2_gpio_free(struct gpio_chip *chip, unsigned offset) 196 196 { 197 - struct dln2_gpio *dln2 = container_of(chip, struct dln2_gpio, gpio); 197 + struct dln2_gpio *dln2 = gpiochip_get_data(chip); 198 198 199 199 dln2_gpio_pin_cmd(dln2, DLN2_GPIO_PIN_DISABLE, offset); 200 200 } 201 201 202 202 static int dln2_gpio_get_direction(struct gpio_chip *chip, unsigned offset) 203 203 { 204 - struct dln2_gpio *dln2 = container_of(chip, struct dln2_gpio, gpio); 204 + struct dln2_gpio *dln2 = gpiochip_get_data(chip); 205 205 206 206 if (test_bit(offset, dln2->output_enabled)) 207 207 return GPIOF_DIR_OUT; ··· 211 211 212 212 static int dln2_gpio_get(struct gpio_chip *chip, unsigned int offset) 213 213 { 214 - struct dln2_gpio *dln2 = container_of(chip, struct dln2_gpio, gpio); 214 + struct dln2_gpio *dln2 = gpiochip_get_data(chip); 215 215 int dir; 216 216 217 217 dir = dln2_gpio_get_direction(chip, offset); ··· 226 226 227 227 static void dln2_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 228 228 { 229 - struct dln2_gpio *dln2 = container_of(chip, struct dln2_gpio, gpio); 229 + struct dln2_gpio *dln2 = gpiochip_get_data(chip); 230 230 231 231 dln2_gpio_pin_set_out_val(dln2, offset, value); 232 232 } ··· 234 234 static int dln2_gpio_set_direction(struct gpio_chip *chip, unsigned offset, 235 235 unsigned dir) 236 236 { 237 - struct dln2_gpio *dln2 = container_of(chip, struct dln2_gpio, gpio); 237 + struct dln2_gpio *dln2 = gpiochip_get_data(chip); 238 238 struct dln2_gpio_pin_val req = { 239 239 .pin = cpu_to_le16(offset), 240 240 .value = dir, ··· 262 262 static int dln2_gpio_direction_output(struct gpio_chip *chip, unsigned offset, 263 263 int value) 264 264 { 265 - struct dln2_gpio *dln2 = container_of(chip, struct dln2_gpio, gpio); 265 + struct dln2_gpio *dln2 = gpiochip_get_data(chip); 266 266 int ret; 267 267 268 268 ret = dln2_gpio_pin_set_out_val(dln2, offset, value); ··· 275 275 static int dln2_gpio_set_debounce(struct gpio_chip *chip, unsigned offset, 276 276 unsigned debounce) 277 277 { 278 - struct dln2_gpio *dln2 = container_of(chip, struct dln2_gpio, gpio); 278 + struct dln2_gpio *dln2 = gpiochip_get_data(chip); 279 279 __le32 duration = cpu_to_le32(debounce); 280 280 281 281 return dln2_transfer_tx(dln2->pdev, DLN2_GPIO_SET_DEBOUNCE, ··· 302 302 static void dln2_irq_unmask(struct irq_data *irqd) 303 303 { 304 304 struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd); 305 - struct dln2_gpio *dln2 = container_of(gc, struct dln2_gpio, gpio); 305 + struct dln2_gpio *dln2 = gpiochip_get_data(gc); 306 306 int pin = irqd_to_hwirq(irqd); 307 307 308 308 set_bit(pin, dln2->unmasked_irqs); ··· 311 311 static void dln2_irq_mask(struct irq_data *irqd) 312 312 { 313 313 struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd); 314 - struct dln2_gpio *dln2 = container_of(gc, struct dln2_gpio, gpio); 314 + struct dln2_gpio *dln2 = gpiochip_get_data(gc); 315 315 int pin = irqd_to_hwirq(irqd); 316 316 317 317 clear_bit(pin, dln2->unmasked_irqs); ··· 320 320 static int dln2_irq_set_type(struct irq_data *irqd, unsigned type) 321 321 { 322 322 struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd); 323 - struct dln2_gpio *dln2 = container_of(gc, struct dln2_gpio, gpio); 323 + struct dln2_gpio *dln2 = gpiochip_get_data(gc); 324 324 int pin = irqd_to_hwirq(irqd); 325 325 326 326 switch (type) { ··· 349 349 static void dln2_irq_bus_lock(struct irq_data *irqd) 350 350 { 351 351 struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd); 352 - struct dln2_gpio *dln2 = container_of(gc, struct dln2_gpio, gpio); 352 + struct dln2_gpio *dln2 = gpiochip_get_data(gc); 353 353 354 354 mutex_lock(&dln2->irq_lock); 355 355 } ··· 357 357 static void dln2_irq_bus_unlock(struct irq_data *irqd) 358 358 { 359 359 struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd); 360 - struct dln2_gpio *dln2 = container_of(gc, struct dln2_gpio, gpio); 360 + struct dln2_gpio *dln2 = gpiochip_get_data(gc); 361 361 int pin = irqd_to_hwirq(irqd); 362 362 int enabled, unmasked; 363 363 unsigned type; ··· 377 377 378 378 ret = dln2_gpio_set_event_cfg(dln2, pin, type, 0); 379 379 if (ret) 380 - dev_err(dln2->gpio.dev, "failed to set event\n"); 380 + dev_err(dln2->gpio.parent, "failed to set event\n"); 381 381 } 382 382 383 383 mutex_unlock(&dln2->irq_lock); ··· 406 406 struct dln2_gpio *dln2 = platform_get_drvdata(pdev); 407 407 408 408 if (len < sizeof(*event)) { 409 - dev_err(dln2->gpio.dev, "short event message\n"); 409 + dev_err(dln2->gpio.parent, "short event message\n"); 410 410 return; 411 411 } 412 412 413 413 pin = le16_to_cpu(event->pin); 414 414 if (pin >= dln2->gpio.ngpio) { 415 - dev_err(dln2->gpio.dev, "out of bounds pin %d\n", pin); 415 + dev_err(dln2->gpio.parent, "out of bounds pin %d\n", pin); 416 416 return; 417 417 } 418 418 419 419 irq = irq_find_mapping(dln2->gpio.irqdomain, pin); 420 420 if (!irq) { 421 - dev_err(dln2->gpio.dev, "pin %d not mapped to IRQ\n", pin); 421 + dev_err(dln2->gpio.parent, "pin %d not mapped to IRQ\n", pin); 422 422 return; 423 423 } 424 424 ··· 462 462 dln2->pdev = pdev; 463 463 464 464 dln2->gpio.label = "dln2"; 465 - dln2->gpio.dev = dev; 465 + dln2->gpio.parent = dev; 466 466 dln2->gpio.owner = THIS_MODULE; 467 467 dln2->gpio.base = -1; 468 468 dln2->gpio.ngpio = pins; ··· 479 479 480 480 platform_set_drvdata(pdev, dln2); 481 481 482 - ret = gpiochip_add(&dln2->gpio); 482 + ret = gpiochip_add_data(&dln2->gpio, dln2); 483 483 if (ret < 0) { 484 484 dev_err(dev, "failed to add gpio chip: %d\n", ret); 485 485 goto out;
+43 -49
drivers/gpio/gpio-dwapb.c
··· 7 7 * 8 8 * All enquiries to support@picochip.com 9 9 */ 10 - #include <linux/basic_mmio_gpio.h> 10 + #include <linux/gpio/driver.h> 11 + /* FIXME: for gpio_get_value(), replace this with direct register read */ 12 + #include <linux/gpio.h> 11 13 #include <linux/err.h> 12 14 #include <linux/init.h> 13 15 #include <linux/interrupt.h> ··· 68 66 #endif 69 67 70 68 struct dwapb_gpio_port { 71 - struct bgpio_chip bgc; 69 + struct gpio_chip gc; 72 70 bool is_registered; 73 71 struct dwapb_gpio *gpio; 74 72 #ifdef CONFIG_PM_SLEEP ··· 85 83 struct irq_domain *domain; 86 84 }; 87 85 88 - static inline struct dwapb_gpio_port * 89 - to_dwapb_gpio_port(struct bgpio_chip *bgc) 90 - { 91 - return container_of(bgc, struct dwapb_gpio_port, bgc); 92 - } 93 - 94 86 static inline u32 dwapb_read(struct dwapb_gpio *gpio, unsigned int offset) 95 87 { 96 - struct bgpio_chip *bgc = &gpio->ports[0].bgc; 88 + struct gpio_chip *gc = &gpio->ports[0].gc; 97 89 void __iomem *reg_base = gpio->regs; 98 90 99 - return bgc->read_reg(reg_base + offset); 91 + return gc->read_reg(reg_base + offset); 100 92 } 101 93 102 94 static inline void dwapb_write(struct dwapb_gpio *gpio, unsigned int offset, 103 95 u32 val) 104 96 { 105 - struct bgpio_chip *bgc = &gpio->ports[0].bgc; 97 + struct gpio_chip *gc = &gpio->ports[0].gc; 106 98 void __iomem *reg_base = gpio->regs; 107 99 108 - bgc->write_reg(reg_base + offset, val); 100 + gc->write_reg(reg_base + offset, val); 109 101 } 110 102 111 103 static int dwapb_gpio_to_irq(struct gpio_chip *gc, unsigned offset) 112 104 { 113 - struct bgpio_chip *bgc = to_bgpio_chip(gc); 114 - struct dwapb_gpio_port *port = to_dwapb_gpio_port(bgc); 105 + struct dwapb_gpio_port *port = gpiochip_get_data(gc); 115 106 struct dwapb_gpio *gpio = port->gpio; 116 107 117 108 return irq_find_mapping(gpio->domain, offset); ··· 114 119 { 115 120 u32 v = dwapb_read(gpio, GPIO_INT_POLARITY); 116 121 117 - if (gpio_get_value(gpio->ports[0].bgc.gc.base + offs)) 122 + if (gpio_get_value(gpio->ports[0].gc.base + offs)) 118 123 v &= ~BIT(offs); 119 124 else 120 125 v |= BIT(offs); ··· 157 162 { 158 163 struct irq_chip_generic *igc = irq_data_get_irq_chip_data(d); 159 164 struct dwapb_gpio *gpio = igc->private; 160 - struct bgpio_chip *bgc = &gpio->ports[0].bgc; 165 + struct gpio_chip *gc = &gpio->ports[0].gc; 161 166 unsigned long flags; 162 167 u32 val; 163 168 164 - spin_lock_irqsave(&bgc->lock, flags); 169 + spin_lock_irqsave(&gc->bgpio_lock, flags); 165 170 val = dwapb_read(gpio, GPIO_INTEN); 166 171 val |= BIT(d->hwirq); 167 172 dwapb_write(gpio, GPIO_INTEN, val); 168 - spin_unlock_irqrestore(&bgc->lock, flags); 173 + spin_unlock_irqrestore(&gc->bgpio_lock, flags); 169 174 } 170 175 171 176 static void dwapb_irq_disable(struct irq_data *d) 172 177 { 173 178 struct irq_chip_generic *igc = irq_data_get_irq_chip_data(d); 174 179 struct dwapb_gpio *gpio = igc->private; 175 - struct bgpio_chip *bgc = &gpio->ports[0].bgc; 180 + struct gpio_chip *gc = &gpio->ports[0].gc; 176 181 unsigned long flags; 177 182 u32 val; 178 183 179 - spin_lock_irqsave(&bgc->lock, flags); 184 + spin_lock_irqsave(&gc->bgpio_lock, flags); 180 185 val = dwapb_read(gpio, GPIO_INTEN); 181 186 val &= ~BIT(d->hwirq); 182 187 dwapb_write(gpio, GPIO_INTEN, val); 183 - spin_unlock_irqrestore(&bgc->lock, flags); 188 + spin_unlock_irqrestore(&gc->bgpio_lock, flags); 184 189 } 185 190 186 191 static int dwapb_irq_reqres(struct irq_data *d) 187 192 { 188 193 struct irq_chip_generic *igc = irq_data_get_irq_chip_data(d); 189 194 struct dwapb_gpio *gpio = igc->private; 190 - struct bgpio_chip *bgc = &gpio->ports[0].bgc; 195 + struct gpio_chip *gc = &gpio->ports[0].gc; 191 196 192 - if (gpiochip_lock_as_irq(&bgc->gc, irqd_to_hwirq(d))) { 197 + if (gpiochip_lock_as_irq(gc, irqd_to_hwirq(d))) { 193 198 dev_err(gpio->dev, "unable to lock HW IRQ %lu for IRQ\n", 194 199 irqd_to_hwirq(d)); 195 200 return -EINVAL; ··· 201 206 { 202 207 struct irq_chip_generic *igc = irq_data_get_irq_chip_data(d); 203 208 struct dwapb_gpio *gpio = igc->private; 204 - struct bgpio_chip *bgc = &gpio->ports[0].bgc; 209 + struct gpio_chip *gc = &gpio->ports[0].gc; 205 210 206 - gpiochip_unlock_as_irq(&bgc->gc, irqd_to_hwirq(d)); 211 + gpiochip_unlock_as_irq(gc, irqd_to_hwirq(d)); 207 212 } 208 213 209 214 static int dwapb_irq_set_type(struct irq_data *d, u32 type) 210 215 { 211 216 struct irq_chip_generic *igc = irq_data_get_irq_chip_data(d); 212 217 struct dwapb_gpio *gpio = igc->private; 213 - struct bgpio_chip *bgc = &gpio->ports[0].bgc; 218 + struct gpio_chip *gc = &gpio->ports[0].gc; 214 219 int bit = d->hwirq; 215 220 unsigned long level, polarity, flags; 216 221 ··· 218 223 IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) 219 224 return -EINVAL; 220 225 221 - spin_lock_irqsave(&bgc->lock, flags); 226 + spin_lock_irqsave(&gc->bgpio_lock, flags); 222 227 level = dwapb_read(gpio, GPIO_INTTYPE_LEVEL); 223 228 polarity = dwapb_read(gpio, GPIO_INT_POLARITY); 224 229 ··· 249 254 250 255 dwapb_write(gpio, GPIO_INTTYPE_LEVEL, level); 251 256 dwapb_write(gpio, GPIO_INT_POLARITY, polarity); 252 - spin_unlock_irqrestore(&bgc->lock, flags); 257 + spin_unlock_irqrestore(&gc->bgpio_lock, flags); 253 258 254 259 return 0; 255 260 } ··· 257 262 static int dwapb_gpio_set_debounce(struct gpio_chip *gc, 258 263 unsigned offset, unsigned debounce) 259 264 { 260 - struct bgpio_chip *bgc = to_bgpio_chip(gc); 261 - struct dwapb_gpio_port *port = to_dwapb_gpio_port(bgc); 265 + struct dwapb_gpio_port *port = gpiochip_get_data(gc); 262 266 struct dwapb_gpio *gpio = port->gpio; 263 267 unsigned long flags, val_deb; 264 - unsigned long mask = bgc->pin2mask(bgc, offset); 268 + unsigned long mask = gc->pin2mask(gc, offset); 265 269 266 - spin_lock_irqsave(&bgc->lock, flags); 270 + spin_lock_irqsave(&gc->bgpio_lock, flags); 267 271 268 272 val_deb = dwapb_read(gpio, GPIO_PORTA_DEBOUNCE); 269 273 if (debounce) ··· 270 276 else 271 277 dwapb_write(gpio, GPIO_PORTA_DEBOUNCE, val_deb & ~mask); 272 278 273 - spin_unlock_irqrestore(&bgc->lock, flags); 279 + spin_unlock_irqrestore(&gc->bgpio_lock, flags); 274 280 275 281 return 0; 276 282 } ··· 289 295 struct dwapb_gpio_port *port, 290 296 struct dwapb_port_property *pp) 291 297 { 292 - struct gpio_chip *gc = &port->bgc.gc; 298 + struct gpio_chip *gc = &port->gc; 293 299 struct device_node *node = pp->node; 294 300 struct irq_chip_generic *irq_gc = NULL; 295 301 unsigned int hwirq, ngpio = gc->ngpio; ··· 363 369 for (hwirq = 0 ; hwirq < ngpio ; hwirq++) 364 370 irq_create_mapping(gpio->domain, hwirq); 365 371 366 - port->bgc.gc.to_irq = dwapb_gpio_to_irq; 372 + port->gc.to_irq = dwapb_gpio_to_irq; 367 373 } 368 374 369 375 static void dwapb_irq_teardown(struct dwapb_gpio *gpio) 370 376 { 371 377 struct dwapb_gpio_port *port = &gpio->ports[0]; 372 - struct gpio_chip *gc = &port->bgc.gc; 378 + struct gpio_chip *gc = &port->gc; 373 379 unsigned int ngpio = gc->ngpio; 374 380 irq_hw_number_t hwirq; 375 381 ··· 406 412 dirout = gpio->regs + GPIO_SWPORTA_DDR + 407 413 (pp->idx * GPIO_SWPORT_DDR_SIZE); 408 414 409 - err = bgpio_init(&port->bgc, gpio->dev, 4, dat, set, NULL, dirout, 415 + err = bgpio_init(&port->gc, gpio->dev, 4, dat, set, NULL, dirout, 410 416 NULL, false); 411 417 if (err) { 412 418 dev_err(gpio->dev, "failed to init gpio chip for %s\n", ··· 415 421 } 416 422 417 423 #ifdef CONFIG_OF_GPIO 418 - port->bgc.gc.of_node = pp->node; 424 + port->gc.of_node = pp->node; 419 425 #endif 420 - port->bgc.gc.ngpio = pp->ngpio; 421 - port->bgc.gc.base = pp->gpio_base; 426 + port->gc.ngpio = pp->ngpio; 427 + port->gc.base = pp->gpio_base; 422 428 423 429 /* Only port A support debounce */ 424 430 if (pp->idx == 0) 425 - port->bgc.gc.set_debounce = dwapb_gpio_set_debounce; 431 + port->gc.set_debounce = dwapb_gpio_set_debounce; 426 432 427 433 if (pp->irq) 428 434 dwapb_configure_irqs(gpio, port, pp); 429 435 430 - err = gpiochip_add(&port->bgc.gc); 436 + err = gpiochip_add_data(&port->gc, port); 431 437 if (err) 432 438 dev_err(gpio->dev, "failed to register gpiochip for %s\n", 433 439 pp->name); ··· 443 449 444 450 for (m = 0; m < gpio->nr_ports; ++m) 445 451 if (gpio->ports[m].is_registered) 446 - gpiochip_remove(&gpio->ports[m].bgc.gc); 452 + gpiochip_remove(&gpio->ports[m].gc); 447 453 } 448 454 449 455 static struct dwapb_platform_data * ··· 585 591 { 586 592 struct platform_device *pdev = to_platform_device(dev); 587 593 struct dwapb_gpio *gpio = platform_get_drvdata(pdev); 588 - struct bgpio_chip *bgc = &gpio->ports[0].bgc; 594 + struct gpio_chip *gc = &gpio->ports[0].gc; 589 595 unsigned long flags; 590 596 int i; 591 597 592 - spin_lock_irqsave(&bgc->lock, flags); 598 + spin_lock_irqsave(&gc->bgpio_lock, flags); 593 599 for (i = 0; i < gpio->nr_ports; i++) { 594 600 unsigned int offset; 595 601 unsigned int idx = gpio->ports[i].idx; ··· 618 624 dwapb_write(gpio, GPIO_INTMASK, 0xffffffff); 619 625 } 620 626 } 621 - spin_unlock_irqrestore(&bgc->lock, flags); 627 + spin_unlock_irqrestore(&gc->bgpio_lock, flags); 622 628 623 629 return 0; 624 630 } ··· 627 633 { 628 634 struct platform_device *pdev = to_platform_device(dev); 629 635 struct dwapb_gpio *gpio = platform_get_drvdata(pdev); 630 - struct bgpio_chip *bgc = &gpio->ports[0].bgc; 636 + struct gpio_chip *gc = &gpio->ports[0].gc; 631 637 unsigned long flags; 632 638 int i; 633 639 634 - spin_lock_irqsave(&bgc->lock, flags); 640 + spin_lock_irqsave(&gc->bgpio_lock, flags); 635 641 for (i = 0; i < gpio->nr_ports; i++) { 636 642 unsigned int offset; 637 643 unsigned int idx = gpio->ports[i].idx; ··· 660 666 dwapb_write(gpio, GPIO_PORTA_EOI, 0xffffffff); 661 667 } 662 668 } 663 - spin_unlock_irqrestore(&bgc->lock, flags); 669 + spin_unlock_irqrestore(&gc->bgpio_lock, flags); 664 670 665 671 return 0; 666 672 }
+5 -5
drivers/gpio/gpio-em.c
··· 103 103 struct em_gio_priv *p = irq_data_get_irq_chip_data(d); 104 104 105 105 if (gpiochip_lock_as_irq(&p->gpio_chip, irqd_to_hwirq(d))) { 106 - dev_err(p->gpio_chip.dev, 106 + dev_err(p->gpio_chip.parent, 107 107 "unable to lock HW IRQ %lu for IRQ\n", 108 108 irqd_to_hwirq(d)); 109 109 return -EINVAL; ··· 192 192 193 193 static inline struct em_gio_priv *gpio_to_priv(struct gpio_chip *chip) 194 194 { 195 - return container_of(chip, struct em_gio_priv, gpio_chip); 195 + return gpiochip_get_data(chip); 196 196 } 197 197 198 198 static int em_gio_direction_input(struct gpio_chip *chip, unsigned offset) ··· 203 203 204 204 static int em_gio_get(struct gpio_chip *chip, unsigned offset) 205 205 { 206 - return (int)(em_gio_read(gpio_to_priv(chip), GIO_I) & BIT(offset)); 206 + return !!(em_gio_read(gpio_to_priv(chip), GIO_I) & BIT(offset)); 207 207 } 208 208 209 209 static void __em_gio_set(struct gpio_chip *chip, unsigned int reg, ··· 332 332 gpio_chip->request = em_gio_request; 333 333 gpio_chip->free = em_gio_free; 334 334 gpio_chip->label = name; 335 - gpio_chip->dev = &pdev->dev; 335 + gpio_chip->parent = &pdev->dev; 336 336 gpio_chip->owner = THIS_MODULE; 337 337 gpio_chip->base = -1; 338 338 gpio_chip->ngpio = ngpios; ··· 368 368 goto err1; 369 369 } 370 370 371 - ret = gpiochip_add(gpio_chip); 371 + ret = gpiochip_add_data(gpio_chip, p); 372 372 if (ret) { 373 373 dev_err(&pdev->dev, "failed to add GPIO controller\n"); 374 374 goto err1;
+13 -12
drivers/gpio/gpio-ep93xx.c
··· 16 16 #include <linux/module.h> 17 17 #include <linux/platform_device.h> 18 18 #include <linux/io.h> 19 - #include <linux/gpio.h> 20 19 #include <linux/irq.h> 21 20 #include <linux/slab.h> 22 - #include <linux/basic_mmio_gpio.h> 21 + #include <linux/gpio/driver.h> 22 + /* FIXME: this is here for gpio_to_irq() - get rid of this! */ 23 + #include <linux/gpio.h> 23 24 24 25 #include <mach/hardware.h> 25 26 #include <mach/gpio-ep93xx.h> ··· 29 28 30 29 struct ep93xx_gpio { 31 30 void __iomem *mmio_base; 32 - struct bgpio_chip bgc[8]; 31 + struct gpio_chip gc[8]; 33 32 }; 34 33 35 34 /************************************************************************* ··· 320 319 return 64 + gpio; 321 320 } 322 321 323 - static int ep93xx_gpio_add_bank(struct bgpio_chip *bgc, struct device *dev, 322 + static int ep93xx_gpio_add_bank(struct gpio_chip *gc, struct device *dev, 324 323 void __iomem *mmio_base, struct ep93xx_gpio_bank *bank) 325 324 { 326 325 void __iomem *data = mmio_base + bank->data; 327 326 void __iomem *dir = mmio_base + bank->dir; 328 327 int err; 329 328 330 - err = bgpio_init(bgc, dev, 1, data, NULL, NULL, dir, NULL, 0); 329 + err = bgpio_init(gc, dev, 1, data, NULL, NULL, dir, NULL, 0); 331 330 if (err) 332 331 return err; 333 332 334 - bgc->gc.label = bank->label; 335 - bgc->gc.base = bank->base; 333 + gc->label = bank->label; 334 + gc->base = bank->base; 336 335 337 336 if (bank->has_debounce) { 338 - bgc->gc.set_debounce = ep93xx_gpio_set_debounce; 339 - bgc->gc.to_irq = ep93xx_gpio_to_irq; 337 + gc->set_debounce = ep93xx_gpio_set_debounce; 338 + gc->to_irq = ep93xx_gpio_to_irq; 340 339 } 341 340 342 - return gpiochip_add(&bgc->gc); 341 + return gpiochip_add_data(gc, NULL); 343 342 } 344 343 345 344 static int ep93xx_gpio_probe(struct platform_device *pdev) ··· 359 358 return PTR_ERR(ep93xx_gpio->mmio_base); 360 359 361 360 for (i = 0; i < ARRAY_SIZE(ep93xx_gpio_banks); i++) { 362 - struct bgpio_chip *bgc = &ep93xx_gpio->bgc[i]; 361 + struct gpio_chip *gc = &ep93xx_gpio->gc[i]; 363 362 struct ep93xx_gpio_bank *bank = &ep93xx_gpio_banks[i]; 364 363 365 - if (ep93xx_gpio_add_bank(bgc, &pdev->dev, 364 + if (ep93xx_gpio_add_bank(gc, &pdev->dev, 366 365 ep93xx_gpio->mmio_base, bank)) 367 366 dev_warn(&pdev->dev, "Unable to add gpio bank %s\n", 368 367 bank->label);
+21 -28
drivers/gpio/gpio-etraxfs.c
··· 1 1 #include <linux/kernel.h> 2 2 #include <linux/init.h> 3 - #include <linux/gpio.h> 4 3 #include <linux/gpio/driver.h> 5 4 #include <linux/of_gpio.h> 6 5 #include <linux/io.h> 7 6 #include <linux/interrupt.h> 8 7 #include <linux/platform_device.h> 9 - #include <linux/basic_mmio_gpio.h> 10 8 11 9 #define ETRAX_FS_rw_pa_dout 0 12 10 #define ETRAX_FS_r_pa_din 4 ··· 65 67 }; 66 68 67 69 struct etraxfs_gpio_chip { 68 - struct bgpio_chip bgc; 70 + struct gpio_chip gc; 69 71 struct etraxfs_gpio_block *block; 70 72 }; 71 73 ··· 174 176 .rw_intr_pins = ARTPEC3_rw_intr_pins, 175 177 }; 176 178 177 - static struct etraxfs_gpio_chip *to_etraxfs(struct gpio_chip *gc) 178 - { 179 - return container_of(gc, struct etraxfs_gpio_chip, bgc.gc); 180 - } 181 - 182 179 static unsigned int etraxfs_gpio_chip_to_port(struct gpio_chip *gc) 183 180 { 184 181 return gc->label[0] - 'A'; ··· 213 220 static unsigned int etraxfs_gpio_to_group_pin(struct etraxfs_gpio_chip *chip, 214 221 unsigned int gpio) 215 222 { 216 - return 4 * etraxfs_gpio_chip_to_port(&chip->bgc.gc) + gpio / 8; 223 + return 4 * etraxfs_gpio_chip_to_port(&chip->gc) + gpio / 8; 217 224 } 218 225 219 226 static void etraxfs_gpio_irq_ack(struct irq_data *d) 220 227 { 221 228 struct etraxfs_gpio_chip *chip = 222 - to_etraxfs(irq_data_get_irq_chip_data(d)); 229 + gpiochip_get_data(irq_data_get_irq_chip_data(d)); 223 230 struct etraxfs_gpio_block *block = chip->block; 224 231 unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq); 225 232 ··· 229 236 static void etraxfs_gpio_irq_mask(struct irq_data *d) 230 237 { 231 238 struct etraxfs_gpio_chip *chip = 232 - to_etraxfs(irq_data_get_irq_chip_data(d)); 239 + gpiochip_get_data(irq_data_get_irq_chip_data(d)); 233 240 struct etraxfs_gpio_block *block = chip->block; 234 241 unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq); 235 242 ··· 242 249 static void etraxfs_gpio_irq_unmask(struct irq_data *d) 243 250 { 244 251 struct etraxfs_gpio_chip *chip = 245 - to_etraxfs(irq_data_get_irq_chip_data(d)); 252 + gpiochip_get_data(irq_data_get_irq_chip_data(d)); 246 253 struct etraxfs_gpio_block *block = chip->block; 247 254 unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq); 248 255 ··· 255 262 static int etraxfs_gpio_irq_set_type(struct irq_data *d, u32 type) 256 263 { 257 264 struct etraxfs_gpio_chip *chip = 258 - to_etraxfs(irq_data_get_irq_chip_data(d)); 265 + gpiochip_get_data(irq_data_get_irq_chip_data(d)); 259 266 struct etraxfs_gpio_block *block = chip->block; 260 267 unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq); 261 268 u32 cfg; ··· 292 299 static int etraxfs_gpio_irq_request_resources(struct irq_data *d) 293 300 { 294 301 struct etraxfs_gpio_chip *chip = 295 - to_etraxfs(irq_data_get_irq_chip_data(d)); 302 + gpiochip_get_data(irq_data_get_irq_chip_data(d)); 296 303 struct etraxfs_gpio_block *block = chip->block; 297 304 unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq); 298 305 int ret = -EBUSY; ··· 301 308 if (block->group[grpirq]) 302 309 goto out; 303 310 304 - ret = gpiochip_lock_as_irq(&chip->bgc.gc, d->hwirq); 311 + ret = gpiochip_lock_as_irq(&chip->gc, d->hwirq); 305 312 if (ret) 306 313 goto out; 307 314 ··· 323 330 static void etraxfs_gpio_irq_release_resources(struct irq_data *d) 324 331 { 325 332 struct etraxfs_gpio_chip *chip = 326 - to_etraxfs(irq_data_get_irq_chip_data(d)); 333 + gpiochip_get_data(irq_data_get_irq_chip_data(d)); 327 334 struct etraxfs_gpio_block *block = chip->block; 328 335 unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq); 329 336 330 337 spin_lock(&block->lock); 331 338 block->group[grpirq] = 0; 332 - gpiochip_unlock_as_irq(&chip->bgc.gc, d->hwirq); 339 + gpiochip_unlock_as_irq(&chip->gc, d->hwirq); 333 340 spin_unlock(&block->lock); 334 341 } 335 342 ··· 412 419 413 420 for (i = 0; i < info->num_ports; i++) { 414 421 struct etraxfs_gpio_chip *chip = &chips[i]; 415 - struct bgpio_chip *bgc = &chip->bgc; 422 + struct gpio_chip *gc = &chip->gc; 416 423 const struct etraxfs_gpio_port *port = &info->ports[i]; 417 424 unsigned long flags = BGPIOF_READ_OUTPUT_REG_SET; 418 425 void __iomem *dat = regs + port->din; ··· 426 433 flags = BGPIOF_NO_OUTPUT; 427 434 } 428 435 429 - ret = bgpio_init(bgc, dev, 4, 436 + ret = bgpio_init(gc, dev, 4, 430 437 dat, set, NULL, dirout, NULL, 431 438 flags); 432 439 if (ret) { ··· 435 442 continue; 436 443 } 437 444 438 - bgc->gc.ngpio = port->ngpio; 439 - bgc->gc.label = port->label; 445 + gc->ngpio = port->ngpio; 446 + gc->label = port->label; 440 447 441 - bgc->gc.of_node = dev->of_node; 442 - bgc->gc.of_gpio_n_cells = 3; 443 - bgc->gc.of_xlate = etraxfs_gpio_of_xlate; 448 + gc->of_node = dev->of_node; 449 + gc->of_gpio_n_cells = 3; 450 + gc->of_xlate = etraxfs_gpio_of_xlate; 444 451 445 - ret = gpiochip_add(&bgc->gc); 452 + ret = gpiochip_add_data(gc, chip); 446 453 if (ret) { 447 454 dev_err(dev, "Unable to register port %s\n", 448 - bgc->gc.label); 455 + gc->label); 449 456 continue; 450 457 } 451 458 452 459 if (i > 0 && !allportsirq) 453 460 continue; 454 461 455 - ret = gpiochip_irqchip_add(&bgc->gc, &etraxfs_gpio_irq_chip, 0, 462 + ret = gpiochip_irqchip_add(gc, &etraxfs_gpio_irq_chip, 0, 456 463 handle_level_irq, IRQ_TYPE_NONE); 457 464 if (ret) { 458 465 dev_err(dev, "Unable to add irqchip to port %s\n", 459 - bgc->gc.label); 466 + gc->label); 460 467 } 461 468 } 462 469
+7 -11
drivers/gpio/gpio-f7188x.c
··· 193 193 static int f7188x_gpio_direction_in(struct gpio_chip *chip, unsigned offset) 194 194 { 195 195 int err; 196 - struct f7188x_gpio_bank *bank = 197 - container_of(chip, struct f7188x_gpio_bank, chip); 196 + struct f7188x_gpio_bank *bank = gpiochip_get_data(chip); 198 197 struct f7188x_sio *sio = bank->data->sio; 199 198 u8 dir; 200 199 ··· 214 215 static int f7188x_gpio_get(struct gpio_chip *chip, unsigned offset) 215 216 { 216 217 int err; 217 - struct f7188x_gpio_bank *bank = 218 - container_of(chip, struct f7188x_gpio_bank, chip); 218 + struct f7188x_gpio_bank *bank = gpiochip_get_data(chip); 219 219 struct f7188x_sio *sio = bank->data->sio; 220 220 u8 dir, data; 221 221 ··· 239 241 unsigned offset, int value) 240 242 { 241 243 int err; 242 - struct f7188x_gpio_bank *bank = 243 - container_of(chip, struct f7188x_gpio_bank, chip); 244 + struct f7188x_gpio_bank *bank = gpiochip_get_data(chip); 244 245 struct f7188x_sio *sio = bank->data->sio; 245 246 u8 dir, data_out; 246 247 ··· 267 270 static void f7188x_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 268 271 { 269 272 int err; 270 - struct f7188x_gpio_bank *bank = 271 - container_of(chip, struct f7188x_gpio_bank, chip); 273 + struct f7188x_gpio_bank *bank = gpiochip_get_data(chip); 272 274 struct f7188x_sio *sio = bank->data->sio; 273 275 u8 data_out; 274 276 ··· 294 298 { 295 299 int err; 296 300 int i; 297 - struct f7188x_sio *sio = pdev->dev.platform_data; 301 + struct f7188x_sio *sio = dev_get_platdata(&pdev->dev); 298 302 struct f7188x_gpio_data *data; 299 303 300 304 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); ··· 329 333 for (i = 0; i < data->nr_bank; i++) { 330 334 struct f7188x_gpio_bank *bank = &data->bank[i]; 331 335 332 - bank->chip.dev = &pdev->dev; 336 + bank->chip.parent = &pdev->dev; 333 337 bank->data = data; 334 338 335 - err = gpiochip_add(&bank->chip); 339 + err = gpiochip_add_data(&bank->chip, bank); 336 340 if (err) { 337 341 dev_err(&pdev->dev, 338 342 "Failed to register gpiochip %d: %d\n",
+12 -12
drivers/gpio/gpio-ge.c
··· 24 24 #include <linux/of_gpio.h> 25 25 #include <linux/of_address.h> 26 26 #include <linux/module.h> 27 - #include <linux/basic_mmio_gpio.h> 27 + #include <linux/gpio/driver.h> 28 28 29 29 #define GEF_GPIO_DIRECT 0x00 30 30 #define GEF_GPIO_IN 0x04 ··· 55 55 { 56 56 const struct of_device_id *of_id = 57 57 of_match_device(gef_gpio_ids, &pdev->dev); 58 - struct bgpio_chip *bgc; 58 + struct gpio_chip *gc; 59 59 void __iomem *regs; 60 60 int ret; 61 61 62 - bgc = devm_kzalloc(&pdev->dev, sizeof(*bgc), GFP_KERNEL); 63 - if (!bgc) 62 + gc = devm_kzalloc(&pdev->dev, sizeof(*gc), GFP_KERNEL); 63 + if (!gc) 64 64 return -ENOMEM; 65 65 66 66 regs = of_iomap(pdev->dev.of_node, 0); 67 67 if (!regs) 68 68 return -ENOMEM; 69 69 70 - ret = bgpio_init(bgc, &pdev->dev, 4, regs + GEF_GPIO_IN, 70 + ret = bgpio_init(gc, &pdev->dev, 4, regs + GEF_GPIO_IN, 71 71 regs + GEF_GPIO_OUT, NULL, NULL, 72 72 regs + GEF_GPIO_DIRECT, BGPIOF_BIG_ENDIAN_BYTE_ORDER); 73 73 if (ret) { ··· 76 76 } 77 77 78 78 /* Setup pointers to chip functions */ 79 - bgc->gc.label = devm_kstrdup(&pdev->dev, pdev->dev.of_node->full_name, 79 + gc->label = devm_kstrdup(&pdev->dev, pdev->dev.of_node->full_name, 80 80 GFP_KERNEL); 81 - if (!bgc->gc.label) { 81 + if (!gc->label) { 82 82 ret = -ENOMEM; 83 83 goto err0; 84 84 } 85 85 86 - bgc->gc.base = -1; 87 - bgc->gc.ngpio = (u16)(uintptr_t)of_id->data; 88 - bgc->gc.of_gpio_n_cells = 2; 89 - bgc->gc.of_node = pdev->dev.of_node; 86 + gc->base = -1; 87 + gc->ngpio = (u16)(uintptr_t)of_id->data; 88 + gc->of_gpio_n_cells = 2; 89 + gc->of_node = pdev->dev.of_node; 90 90 91 91 /* This function adds a memory mapped GPIO chip */ 92 - ret = gpiochip_add(&bgc->gc); 92 + ret = gpiochip_add_data(gc, NULL); 93 93 if (ret) 94 94 goto err0; 95 95
+135 -160
drivers/gpio/gpio-generic.c
··· 56 56 #include <linux/log2.h> 57 57 #include <linux/ioport.h> 58 58 #include <linux/io.h> 59 - #include <linux/gpio.h> 59 + #include <linux/gpio/driver.h> 60 60 #include <linux/slab.h> 61 + #include <linux/bitops.h> 61 62 #include <linux/platform_device.h> 62 63 #include <linux/mod_devicetable.h> 63 - #include <linux/basic_mmio_gpio.h> 64 64 65 65 static void bgpio_write8(void __iomem *reg, unsigned long data) 66 66 { ··· 124 124 return ioread32be(reg); 125 125 } 126 126 127 - static unsigned long bgpio_pin2mask(struct bgpio_chip *bgc, unsigned int pin) 127 + static unsigned long bgpio_pin2mask(struct gpio_chip *gc, unsigned int pin) 128 128 { 129 - return 1 << pin; 129 + return BIT(pin); 130 130 } 131 131 132 - static unsigned long bgpio_pin2mask_be(struct bgpio_chip *bgc, 132 + static unsigned long bgpio_pin2mask_be(struct gpio_chip *gc, 133 133 unsigned int pin) 134 134 { 135 - return 1 << (bgc->bits - 1 - pin); 135 + return BIT(gc->bgpio_bits - 1 - pin); 136 136 } 137 137 138 138 static int bgpio_get_set(struct gpio_chip *gc, unsigned int gpio) 139 139 { 140 - struct bgpio_chip *bgc = to_bgpio_chip(gc); 141 - unsigned long pinmask = bgc->pin2mask(bgc, gpio); 140 + unsigned long pinmask = gc->pin2mask(gc, gpio); 142 141 143 - if (bgc->dir & pinmask) 144 - return !!(bgc->read_reg(bgc->reg_set) & pinmask); 142 + if (gc->bgpio_dir & pinmask) 143 + return !!(gc->read_reg(gc->reg_set) & pinmask); 145 144 else 146 - return !!(bgc->read_reg(bgc->reg_dat) & pinmask); 145 + return !!(gc->read_reg(gc->reg_dat) & pinmask); 147 146 } 148 147 149 148 static int bgpio_get(struct gpio_chip *gc, unsigned int gpio) 150 149 { 151 - struct bgpio_chip *bgc = to_bgpio_chip(gc); 152 - 153 - return !!(bgc->read_reg(bgc->reg_dat) & bgc->pin2mask(bgc, gpio)); 150 + return !!(gc->read_reg(gc->reg_dat) & gc->pin2mask(gc, gpio)); 154 151 } 155 152 156 153 static void bgpio_set_none(struct gpio_chip *gc, unsigned int gpio, int val) ··· 156 159 157 160 static void bgpio_set(struct gpio_chip *gc, unsigned int gpio, int val) 158 161 { 159 - struct bgpio_chip *bgc = to_bgpio_chip(gc); 160 - unsigned long mask = bgc->pin2mask(bgc, gpio); 162 + unsigned long mask = gc->pin2mask(gc, gpio); 161 163 unsigned long flags; 162 164 163 - spin_lock_irqsave(&bgc->lock, flags); 165 + spin_lock_irqsave(&gc->bgpio_lock, flags); 164 166 165 167 if (val) 166 - bgc->data |= mask; 168 + gc->bgpio_data |= mask; 167 169 else 168 - bgc->data &= ~mask; 170 + gc->bgpio_data &= ~mask; 169 171 170 - bgc->write_reg(bgc->reg_dat, bgc->data); 172 + gc->write_reg(gc->reg_dat, gc->bgpio_data); 171 173 172 - spin_unlock_irqrestore(&bgc->lock, flags); 174 + spin_unlock_irqrestore(&gc->bgpio_lock, flags); 173 175 } 174 176 175 177 static void bgpio_set_with_clear(struct gpio_chip *gc, unsigned int gpio, 176 178 int val) 177 179 { 178 - struct bgpio_chip *bgc = to_bgpio_chip(gc); 179 - unsigned long mask = bgc->pin2mask(bgc, gpio); 180 + unsigned long mask = gc->pin2mask(gc, gpio); 180 181 181 182 if (val) 182 - bgc->write_reg(bgc->reg_set, mask); 183 + gc->write_reg(gc->reg_set, mask); 183 184 else 184 - bgc->write_reg(bgc->reg_clr, mask); 185 + gc->write_reg(gc->reg_clr, mask); 185 186 } 186 187 187 188 static void bgpio_set_set(struct gpio_chip *gc, unsigned int gpio, int val) 188 189 { 189 - struct bgpio_chip *bgc = to_bgpio_chip(gc); 190 - unsigned long mask = bgc->pin2mask(bgc, gpio); 190 + unsigned long mask = gc->pin2mask(gc, gpio); 191 191 unsigned long flags; 192 192 193 - spin_lock_irqsave(&bgc->lock, flags); 193 + spin_lock_irqsave(&gc->bgpio_lock, flags); 194 194 195 195 if (val) 196 - bgc->data |= mask; 196 + gc->bgpio_data |= mask; 197 197 else 198 - bgc->data &= ~mask; 198 + gc->bgpio_data &= ~mask; 199 199 200 - bgc->write_reg(bgc->reg_set, bgc->data); 200 + gc->write_reg(gc->reg_set, gc->bgpio_data); 201 201 202 - spin_unlock_irqrestore(&bgc->lock, flags); 202 + spin_unlock_irqrestore(&gc->bgpio_lock, flags); 203 203 } 204 204 205 - static void bgpio_multiple_get_masks(struct bgpio_chip *bgc, 205 + static void bgpio_multiple_get_masks(struct gpio_chip *gc, 206 206 unsigned long *mask, unsigned long *bits, 207 207 unsigned long *set_mask, 208 208 unsigned long *clear_mask) ··· 209 215 *set_mask = 0; 210 216 *clear_mask = 0; 211 217 212 - for (i = 0; i < bgc->bits; i++) { 218 + for (i = 0; i < gc->bgpio_bits; i++) { 213 219 if (*mask == 0) 214 220 break; 215 221 if (__test_and_clear_bit(i, mask)) { 216 222 if (test_bit(i, bits)) 217 - *set_mask |= bgc->pin2mask(bgc, i); 223 + *set_mask |= gc->pin2mask(gc, i); 218 224 else 219 - *clear_mask |= bgc->pin2mask(bgc, i); 225 + *clear_mask |= gc->pin2mask(gc, i); 220 226 } 221 227 } 222 228 } 223 229 224 - static void bgpio_set_multiple_single_reg(struct bgpio_chip *bgc, 230 + static void bgpio_set_multiple_single_reg(struct gpio_chip *gc, 225 231 unsigned long *mask, 226 232 unsigned long *bits, 227 233 void __iomem *reg) ··· 229 235 unsigned long flags; 230 236 unsigned long set_mask, clear_mask; 231 237 232 - spin_lock_irqsave(&bgc->lock, flags); 238 + spin_lock_irqsave(&gc->bgpio_lock, flags); 233 239 234 - bgpio_multiple_get_masks(bgc, mask, bits, &set_mask, &clear_mask); 240 + bgpio_multiple_get_masks(gc, mask, bits, &set_mask, &clear_mask); 235 241 236 - bgc->data |= set_mask; 237 - bgc->data &= ~clear_mask; 242 + gc->bgpio_data |= set_mask; 243 + gc->bgpio_data &= ~clear_mask; 238 244 239 - bgc->write_reg(reg, bgc->data); 245 + gc->write_reg(reg, gc->bgpio_data); 240 246 241 - spin_unlock_irqrestore(&bgc->lock, flags); 247 + spin_unlock_irqrestore(&gc->bgpio_lock, flags); 242 248 } 243 249 244 250 static void bgpio_set_multiple(struct gpio_chip *gc, unsigned long *mask, 245 251 unsigned long *bits) 246 252 { 247 - struct bgpio_chip *bgc = to_bgpio_chip(gc); 248 - 249 - bgpio_set_multiple_single_reg(bgc, mask, bits, bgc->reg_dat); 253 + bgpio_set_multiple_single_reg(gc, mask, bits, gc->reg_dat); 250 254 } 251 255 252 256 static void bgpio_set_multiple_set(struct gpio_chip *gc, unsigned long *mask, 253 257 unsigned long *bits) 254 258 { 255 - struct bgpio_chip *bgc = to_bgpio_chip(gc); 256 - 257 - bgpio_set_multiple_single_reg(bgc, mask, bits, bgc->reg_set); 259 + bgpio_set_multiple_single_reg(gc, mask, bits, gc->reg_set); 258 260 } 259 261 260 262 static void bgpio_set_multiple_with_clear(struct gpio_chip *gc, 261 263 unsigned long *mask, 262 264 unsigned long *bits) 263 265 { 264 - struct bgpio_chip *bgc = to_bgpio_chip(gc); 265 266 unsigned long set_mask, clear_mask; 266 267 267 - bgpio_multiple_get_masks(bgc, mask, bits, &set_mask, &clear_mask); 268 + bgpio_multiple_get_masks(gc, mask, bits, &set_mask, &clear_mask); 268 269 269 270 if (set_mask) 270 - bgc->write_reg(bgc->reg_set, set_mask); 271 + gc->write_reg(gc->reg_set, set_mask); 271 272 if (clear_mask) 272 - bgc->write_reg(bgc->reg_clr, clear_mask); 273 + gc->write_reg(gc->reg_clr, clear_mask); 273 274 } 274 275 275 276 static int bgpio_simple_dir_in(struct gpio_chip *gc, unsigned int gpio) ··· 288 299 289 300 static int bgpio_dir_in(struct gpio_chip *gc, unsigned int gpio) 290 301 { 291 - struct bgpio_chip *bgc = to_bgpio_chip(gc); 292 302 unsigned long flags; 293 303 294 - spin_lock_irqsave(&bgc->lock, flags); 304 + spin_lock_irqsave(&gc->bgpio_lock, flags); 295 305 296 - bgc->dir &= ~bgc->pin2mask(bgc, gpio); 297 - bgc->write_reg(bgc->reg_dir, bgc->dir); 306 + gc->bgpio_dir &= ~gc->pin2mask(gc, gpio); 307 + gc->write_reg(gc->reg_dir, gc->bgpio_dir); 298 308 299 - spin_unlock_irqrestore(&bgc->lock, flags); 309 + spin_unlock_irqrestore(&gc->bgpio_lock, flags); 300 310 301 311 return 0; 302 312 } 303 313 304 314 static int bgpio_get_dir(struct gpio_chip *gc, unsigned int gpio) 305 315 { 306 - struct bgpio_chip *bgc = to_bgpio_chip(gc); 307 - 308 - return (bgc->read_reg(bgc->reg_dir) & bgc->pin2mask(bgc, gpio)) ? 309 - GPIOF_DIR_OUT : GPIOF_DIR_IN; 316 + /* Return 0 if output, 1 of input */ 317 + return !(gc->read_reg(gc->reg_dir) & gc->pin2mask(gc, gpio)); 310 318 } 311 319 312 320 static int bgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val) 313 321 { 314 - struct bgpio_chip *bgc = to_bgpio_chip(gc); 315 322 unsigned long flags; 316 323 317 324 gc->set(gc, gpio, val); 318 325 319 - spin_lock_irqsave(&bgc->lock, flags); 326 + spin_lock_irqsave(&gc->bgpio_lock, flags); 320 327 321 - bgc->dir |= bgc->pin2mask(bgc, gpio); 322 - bgc->write_reg(bgc->reg_dir, bgc->dir); 328 + gc->bgpio_dir |= gc->pin2mask(gc, gpio); 329 + gc->write_reg(gc->reg_dir, gc->bgpio_dir); 323 330 324 - spin_unlock_irqrestore(&bgc->lock, flags); 331 + spin_unlock_irqrestore(&gc->bgpio_lock, flags); 325 332 326 333 return 0; 327 334 } 328 335 329 336 static int bgpio_dir_in_inv(struct gpio_chip *gc, unsigned int gpio) 330 337 { 331 - struct bgpio_chip *bgc = to_bgpio_chip(gc); 332 338 unsigned long flags; 333 339 334 - spin_lock_irqsave(&bgc->lock, flags); 340 + spin_lock_irqsave(&gc->bgpio_lock, flags); 335 341 336 - bgc->dir |= bgc->pin2mask(bgc, gpio); 337 - bgc->write_reg(bgc->reg_dir, bgc->dir); 342 + gc->bgpio_dir |= gc->pin2mask(gc, gpio); 343 + gc->write_reg(gc->reg_dir, gc->bgpio_dir); 338 344 339 - spin_unlock_irqrestore(&bgc->lock, flags); 345 + spin_unlock_irqrestore(&gc->bgpio_lock, flags); 340 346 341 347 return 0; 342 348 } 343 349 344 350 static int bgpio_dir_out_inv(struct gpio_chip *gc, unsigned int gpio, int val) 345 351 { 346 - struct bgpio_chip *bgc = to_bgpio_chip(gc); 347 352 unsigned long flags; 348 353 349 354 gc->set(gc, gpio, val); 350 355 351 - spin_lock_irqsave(&bgc->lock, flags); 356 + spin_lock_irqsave(&gc->bgpio_lock, flags); 352 357 353 - bgc->dir &= ~bgc->pin2mask(bgc, gpio); 354 - bgc->write_reg(bgc->reg_dir, bgc->dir); 358 + gc->bgpio_dir &= ~gc->pin2mask(gc, gpio); 359 + gc->write_reg(gc->reg_dir, gc->bgpio_dir); 355 360 356 - spin_unlock_irqrestore(&bgc->lock, flags); 361 + spin_unlock_irqrestore(&gc->bgpio_lock, flags); 357 362 358 363 return 0; 359 364 } 360 365 361 366 static int bgpio_get_dir_inv(struct gpio_chip *gc, unsigned int gpio) 362 367 { 363 - struct bgpio_chip *bgc = to_bgpio_chip(gc); 364 - 365 - return (bgc->read_reg(bgc->reg_dir) & bgc->pin2mask(bgc, gpio)) ? 366 - GPIOF_DIR_IN : GPIOF_DIR_OUT; 368 + /* Return 0 if output, 1 if input */ 369 + return !!(gc->read_reg(gc->reg_dir) & gc->pin2mask(gc, gpio)); 367 370 } 368 371 369 372 static int bgpio_setup_accessors(struct device *dev, 370 - struct bgpio_chip *bgc, 373 + struct gpio_chip *gc, 371 374 bool bit_be, 372 375 bool byte_be) 373 376 { 374 377 375 - switch (bgc->bits) { 378 + switch (gc->bgpio_bits) { 376 379 case 8: 377 - bgc->read_reg = bgpio_read8; 378 - bgc->write_reg = bgpio_write8; 380 + gc->read_reg = bgpio_read8; 381 + gc->write_reg = bgpio_write8; 379 382 break; 380 383 case 16: 381 384 if (byte_be) { 382 - bgc->read_reg = bgpio_read16be; 383 - bgc->write_reg = bgpio_write16be; 385 + gc->read_reg = bgpio_read16be; 386 + gc->write_reg = bgpio_write16be; 384 387 } else { 385 - bgc->read_reg = bgpio_read16; 386 - bgc->write_reg = bgpio_write16; 388 + gc->read_reg = bgpio_read16; 389 + gc->write_reg = bgpio_write16; 387 390 } 388 391 break; 389 392 case 32: 390 393 if (byte_be) { 391 - bgc->read_reg = bgpio_read32be; 392 - bgc->write_reg = bgpio_write32be; 394 + gc->read_reg = bgpio_read32be; 395 + gc->write_reg = bgpio_write32be; 393 396 } else { 394 - bgc->read_reg = bgpio_read32; 395 - bgc->write_reg = bgpio_write32; 397 + gc->read_reg = bgpio_read32; 398 + gc->write_reg = bgpio_write32; 396 399 } 397 400 break; 398 401 #if BITS_PER_LONG >= 64 ··· 394 413 "64 bit big endian byte order unsupported\n"); 395 414 return -EINVAL; 396 415 } else { 397 - bgc->read_reg = bgpio_read64; 398 - bgc->write_reg = bgpio_write64; 416 + gc->read_reg = bgpio_read64; 417 + gc->write_reg = bgpio_write64; 399 418 } 400 419 break; 401 420 #endif /* BITS_PER_LONG >= 64 */ 402 421 default: 403 - dev_err(dev, "unsupported data width %u bits\n", bgc->bits); 422 + dev_err(dev, "unsupported data width %u bits\n", gc->bgpio_bits); 404 423 return -EINVAL; 405 424 } 406 425 407 - bgc->pin2mask = bit_be ? bgpio_pin2mask_be : bgpio_pin2mask; 426 + gc->pin2mask = bit_be ? bgpio_pin2mask_be : bgpio_pin2mask; 408 427 409 428 return 0; 410 429 } ··· 431 450 * - an input direction register (named "dirin") where a 1 bit indicates 432 451 * the GPIO is an input. 433 452 */ 434 - static int bgpio_setup_io(struct bgpio_chip *bgc, 453 + static int bgpio_setup_io(struct gpio_chip *gc, 435 454 void __iomem *dat, 436 455 void __iomem *set, 437 456 void __iomem *clr, 438 457 unsigned long flags) 439 458 { 440 459 441 - bgc->reg_dat = dat; 442 - if (!bgc->reg_dat) 460 + gc->reg_dat = dat; 461 + if (!gc->reg_dat) 443 462 return -EINVAL; 444 463 445 464 if (set && clr) { 446 - bgc->reg_set = set; 447 - bgc->reg_clr = clr; 448 - bgc->gc.set = bgpio_set_with_clear; 449 - bgc->gc.set_multiple = bgpio_set_multiple_with_clear; 465 + gc->reg_set = set; 466 + gc->reg_clr = clr; 467 + gc->set = bgpio_set_with_clear; 468 + gc->set_multiple = bgpio_set_multiple_with_clear; 450 469 } else if (set && !clr) { 451 - bgc->reg_set = set; 452 - bgc->gc.set = bgpio_set_set; 453 - bgc->gc.set_multiple = bgpio_set_multiple_set; 470 + gc->reg_set = set; 471 + gc->set = bgpio_set_set; 472 + gc->set_multiple = bgpio_set_multiple_set; 454 473 } else if (flags & BGPIOF_NO_OUTPUT) { 455 - bgc->gc.set = bgpio_set_none; 456 - bgc->gc.set_multiple = NULL; 474 + gc->set = bgpio_set_none; 475 + gc->set_multiple = NULL; 457 476 } else { 458 - bgc->gc.set = bgpio_set; 459 - bgc->gc.set_multiple = bgpio_set_multiple; 477 + gc->set = bgpio_set; 478 + gc->set_multiple = bgpio_set_multiple; 460 479 } 461 480 462 481 if (!(flags & BGPIOF_UNREADABLE_REG_SET) && 463 482 (flags & BGPIOF_READ_OUTPUT_REG_SET)) 464 - bgc->gc.get = bgpio_get_set; 483 + gc->get = bgpio_get_set; 465 484 else 466 - bgc->gc.get = bgpio_get; 485 + gc->get = bgpio_get; 467 486 468 487 return 0; 469 488 } 470 489 471 - static int bgpio_setup_direction(struct bgpio_chip *bgc, 490 + static int bgpio_setup_direction(struct gpio_chip *gc, 472 491 void __iomem *dirout, 473 492 void __iomem *dirin, 474 493 unsigned long flags) ··· 476 495 if (dirout && dirin) { 477 496 return -EINVAL; 478 497 } else if (dirout) { 479 - bgc->reg_dir = dirout; 480 - bgc->gc.direction_output = bgpio_dir_out; 481 - bgc->gc.direction_input = bgpio_dir_in; 482 - bgc->gc.get_direction = bgpio_get_dir; 498 + gc->reg_dir = dirout; 499 + gc->direction_output = bgpio_dir_out; 500 + gc->direction_input = bgpio_dir_in; 501 + gc->get_direction = bgpio_get_dir; 483 502 } else if (dirin) { 484 - bgc->reg_dir = dirin; 485 - bgc->gc.direction_output = bgpio_dir_out_inv; 486 - bgc->gc.direction_input = bgpio_dir_in_inv; 487 - bgc->gc.get_direction = bgpio_get_dir_inv; 503 + gc->reg_dir = dirin; 504 + gc->direction_output = bgpio_dir_out_inv; 505 + gc->direction_input = bgpio_dir_in_inv; 506 + gc->get_direction = bgpio_get_dir_inv; 488 507 } else { 489 508 if (flags & BGPIOF_NO_OUTPUT) 490 - bgc->gc.direction_output = bgpio_dir_out_err; 509 + gc->direction_output = bgpio_dir_out_err; 491 510 else 492 - bgc->gc.direction_output = bgpio_simple_dir_out; 493 - bgc->gc.direction_input = bgpio_simple_dir_in; 511 + gc->direction_output = bgpio_simple_dir_out; 512 + gc->direction_input = bgpio_simple_dir_in; 494 513 } 495 514 496 515 return 0; ··· 504 523 return -EINVAL; 505 524 } 506 525 507 - int bgpio_remove(struct bgpio_chip *bgc) 508 - { 509 - gpiochip_remove(&bgc->gc); 510 - return 0; 511 - } 512 - EXPORT_SYMBOL_GPL(bgpio_remove); 513 - 514 - int bgpio_init(struct bgpio_chip *bgc, struct device *dev, 526 + int bgpio_init(struct gpio_chip *gc, struct device *dev, 515 527 unsigned long sz, void __iomem *dat, void __iomem *set, 516 528 void __iomem *clr, void __iomem *dirout, void __iomem *dirin, 517 529 unsigned long flags) ··· 514 540 if (!is_power_of_2(sz)) 515 541 return -EINVAL; 516 542 517 - bgc->bits = sz * 8; 518 - if (bgc->bits > BITS_PER_LONG) 543 + gc->bgpio_bits = sz * 8; 544 + if (gc->bgpio_bits > BITS_PER_LONG) 519 545 return -EINVAL; 520 546 521 - spin_lock_init(&bgc->lock); 522 - bgc->gc.dev = dev; 523 - bgc->gc.label = dev_name(dev); 524 - bgc->gc.base = -1; 525 - bgc->gc.ngpio = bgc->bits; 526 - bgc->gc.request = bgpio_request; 547 + spin_lock_init(&gc->bgpio_lock); 548 + gc->parent = dev; 549 + gc->label = dev_name(dev); 550 + gc->base = -1; 551 + gc->ngpio = gc->bgpio_bits; 552 + gc->request = bgpio_request; 527 553 528 - ret = bgpio_setup_io(bgc, dat, set, clr, flags); 554 + ret = bgpio_setup_io(gc, dat, set, clr, flags); 529 555 if (ret) 530 556 return ret; 531 557 532 - ret = bgpio_setup_accessors(dev, bgc, flags & BGPIOF_BIG_ENDIAN, 558 + ret = bgpio_setup_accessors(dev, gc, flags & BGPIOF_BIG_ENDIAN, 533 559 flags & BGPIOF_BIG_ENDIAN_BYTE_ORDER); 534 560 if (ret) 535 561 return ret; 536 562 537 - ret = bgpio_setup_direction(bgc, dirout, dirin, flags); 563 + ret = bgpio_setup_direction(gc, dirout, dirin, flags); 538 564 if (ret) 539 565 return ret; 540 566 541 - bgc->data = bgc->read_reg(bgc->reg_dat); 542 - if (bgc->gc.set == bgpio_set_set && 567 + gc->bgpio_data = gc->read_reg(gc->reg_dat); 568 + if (gc->set == bgpio_set_set && 543 569 !(flags & BGPIOF_UNREADABLE_REG_SET)) 544 - bgc->data = bgc->read_reg(bgc->reg_set); 545 - if (bgc->reg_dir && !(flags & BGPIOF_UNREADABLE_REG_DIR)) 546 - bgc->dir = bgc->read_reg(bgc->reg_dir); 570 + gc->bgpio_data = gc->read_reg(gc->reg_set); 571 + if (gc->reg_dir && !(flags & BGPIOF_UNREADABLE_REG_DIR)) 572 + gc->bgpio_dir = gc->read_reg(gc->reg_dir); 547 573 548 574 return ret; 549 575 } ··· 581 607 unsigned long sz; 582 608 unsigned long flags = pdev->id_entry->driver_data; 583 609 int err; 584 - struct bgpio_chip *bgc; 610 + struct gpio_chip *gc; 585 611 struct bgpio_pdata *pdata = dev_get_platdata(dev); 586 612 587 613 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dat"); ··· 610 636 if (IS_ERR(dirin)) 611 637 return PTR_ERR(dirin); 612 638 613 - bgc = devm_kzalloc(&pdev->dev, sizeof(*bgc), GFP_KERNEL); 614 - if (!bgc) 639 + gc = devm_kzalloc(&pdev->dev, sizeof(*gc), GFP_KERNEL); 640 + if (!gc) 615 641 return -ENOMEM; 616 642 617 - err = bgpio_init(bgc, dev, sz, dat, set, clr, dirout, dirin, flags); 643 + err = bgpio_init(gc, dev, sz, dat, set, clr, dirout, dirin, flags); 618 644 if (err) 619 645 return err; 620 646 621 647 if (pdata) { 622 648 if (pdata->label) 623 - bgc->gc.label = pdata->label; 624 - bgc->gc.base = pdata->base; 649 + gc->label = pdata->label; 650 + gc->base = pdata->base; 625 651 if (pdata->ngpio > 0) 626 - bgc->gc.ngpio = pdata->ngpio; 652 + gc->ngpio = pdata->ngpio; 627 653 } 628 654 629 - platform_set_drvdata(pdev, bgc); 655 + platform_set_drvdata(pdev, gc); 630 656 631 - return gpiochip_add(&bgc->gc); 657 + return gpiochip_add_data(gc, NULL); 632 658 } 633 659 634 660 static int bgpio_pdev_remove(struct platform_device *pdev) 635 661 { 636 - struct bgpio_chip *bgc = platform_get_drvdata(pdev); 662 + struct gpio_chip *gc = platform_get_drvdata(pdev); 637 663 638 - return bgpio_remove(bgc); 664 + gpiochip_remove(gc); 665 + return 0; 639 666 } 640 667 641 668 static const struct platform_device_id bgpio_id_table[] = {
+32 -41
drivers/gpio/gpio-grgpio.c
··· 31 31 #include <linux/gpio.h> 32 32 #include <linux/slab.h> 33 33 #include <linux/err.h> 34 - #include <linux/basic_mmio_gpio.h> 34 + #include <linux/gpio/driver.h> 35 35 #include <linux/interrupt.h> 36 36 #include <linux/irq.h> 37 37 #include <linux/irqdomain.h> ··· 63 63 }; 64 64 65 65 struct grgpio_priv { 66 - struct bgpio_chip bgc; 66 + struct gpio_chip gc; 67 67 void __iomem *regs; 68 68 struct device *dev; 69 69 ··· 92 92 struct grgpio_lirq lirqs[GRGPIO_MAX_NGPIO]; 93 93 }; 94 94 95 - static inline struct grgpio_priv *grgpio_gc_to_priv(struct gpio_chip *gc) 96 - { 97 - struct bgpio_chip *bgc = to_bgpio_chip(gc); 98 - 99 - return container_of(bgc, struct grgpio_priv, bgc); 100 - } 101 - 102 95 static void grgpio_set_imask(struct grgpio_priv *priv, unsigned int offset, 103 96 int val) 104 97 { 105 - struct bgpio_chip *bgc = &priv->bgc; 106 - unsigned long mask = bgc->pin2mask(bgc, offset); 98 + struct gpio_chip *gc = &priv->gc; 99 + unsigned long mask = gc->pin2mask(gc, offset); 107 100 108 101 if (val) 109 102 priv->imask |= mask; 110 103 else 111 104 priv->imask &= ~mask; 112 - bgc->write_reg(priv->regs + GRGPIO_IMASK, priv->imask); 105 + gc->write_reg(priv->regs + GRGPIO_IMASK, priv->imask); 113 106 } 114 107 115 108 static int grgpio_to_irq(struct gpio_chip *gc, unsigned offset) 116 109 { 117 - struct grgpio_priv *priv = grgpio_gc_to_priv(gc); 110 + struct grgpio_priv *priv = gpiochip_get_data(gc); 118 111 119 112 if (offset >= gc->ngpio) 120 113 return -ENXIO; ··· 151 158 return -EINVAL; 152 159 } 153 160 154 - spin_lock_irqsave(&priv->bgc.lock, flags); 161 + spin_lock_irqsave(&priv->gc.bgpio_lock, flags); 155 162 156 - ipol = priv->bgc.read_reg(priv->regs + GRGPIO_IPOL) & ~mask; 157 - iedge = priv->bgc.read_reg(priv->regs + GRGPIO_IEDGE) & ~mask; 163 + ipol = priv->gc.read_reg(priv->regs + GRGPIO_IPOL) & ~mask; 164 + iedge = priv->gc.read_reg(priv->regs + GRGPIO_IEDGE) & ~mask; 158 165 159 - priv->bgc.write_reg(priv->regs + GRGPIO_IPOL, ipol | pol); 160 - priv->bgc.write_reg(priv->regs + GRGPIO_IEDGE, iedge | edge); 166 + priv->gc.write_reg(priv->regs + GRGPIO_IPOL, ipol | pol); 167 + priv->gc.write_reg(priv->regs + GRGPIO_IEDGE, iedge | edge); 161 168 162 - spin_unlock_irqrestore(&priv->bgc.lock, flags); 169 + spin_unlock_irqrestore(&priv->gc.bgpio_lock, flags); 163 170 164 171 return 0; 165 172 } ··· 170 177 int offset = d->hwirq; 171 178 unsigned long flags; 172 179 173 - spin_lock_irqsave(&priv->bgc.lock, flags); 180 + spin_lock_irqsave(&priv->gc.bgpio_lock, flags); 174 181 175 182 grgpio_set_imask(priv, offset, 0); 176 183 177 - spin_unlock_irqrestore(&priv->bgc.lock, flags); 184 + spin_unlock_irqrestore(&priv->gc.bgpio_lock, flags); 178 185 } 179 186 180 187 static void grgpio_irq_unmask(struct irq_data *d) ··· 183 190 int offset = d->hwirq; 184 191 unsigned long flags; 185 192 186 - spin_lock_irqsave(&priv->bgc.lock, flags); 193 + spin_lock_irqsave(&priv->gc.bgpio_lock, flags); 187 194 188 195 grgpio_set_imask(priv, offset, 1); 189 196 190 - spin_unlock_irqrestore(&priv->bgc.lock, flags); 197 + spin_unlock_irqrestore(&priv->gc.bgpio_lock, flags); 191 198 } 192 199 193 200 static struct irq_chip grgpio_irq_chip = { ··· 200 207 static irqreturn_t grgpio_irq_handler(int irq, void *dev) 201 208 { 202 209 struct grgpio_priv *priv = dev; 203 - int ngpio = priv->bgc.gc.ngpio; 210 + int ngpio = priv->gc.ngpio; 204 211 unsigned long flags; 205 212 int i; 206 213 int match = 0; 207 214 208 - spin_lock_irqsave(&priv->bgc.lock, flags); 215 + spin_lock_irqsave(&priv->gc.bgpio_lock, flags); 209 216 210 217 /* 211 218 * For each gpio line, call its interrupt handler if it its underlying ··· 221 228 } 222 229 } 223 230 224 - spin_unlock_irqrestore(&priv->bgc.lock, flags); 231 + spin_unlock_irqrestore(&priv->gc.bgpio_lock, flags); 225 232 226 233 if (!match) 227 234 dev_warn(priv->dev, "No gpio line matched irq %d\n", irq); ··· 253 260 dev_dbg(priv->dev, "Mapping irq %d for gpio line %d\n", 254 261 irq, offset); 255 262 256 - spin_lock_irqsave(&priv->bgc.lock, flags); 263 + spin_lock_irqsave(&priv->gc.bgpio_lock, flags); 257 264 258 265 /* Request underlying irq if not already requested */ 259 266 lirq->irq = irq; ··· 266 273 "Could not request underlying irq %d\n", 267 274 uirq->uirq); 268 275 269 - spin_unlock_irqrestore(&priv->bgc.lock, flags); 276 + spin_unlock_irqrestore(&priv->gc.bgpio_lock, flags); 270 277 271 278 return ret; 272 279 } 273 280 } 274 281 uirq->refcnt++; 275 282 276 - spin_unlock_irqrestore(&priv->bgc.lock, flags); 283 + spin_unlock_irqrestore(&priv->gc.bgpio_lock, flags); 277 284 278 285 /* Setup irq */ 279 286 irq_set_chip_data(irq, priv); ··· 291 298 struct grgpio_lirq *lirq; 292 299 struct grgpio_uirq *uirq; 293 300 unsigned long flags; 294 - int ngpio = priv->bgc.gc.ngpio; 301 + int ngpio = priv->gc.ngpio; 295 302 int i; 296 303 297 304 irq_set_chip_and_handler(irq, NULL, NULL); 298 305 irq_set_chip_data(irq, NULL); 299 306 300 - spin_lock_irqsave(&priv->bgc.lock, flags); 307 + spin_lock_irqsave(&priv->gc.bgpio_lock, flags); 301 308 302 309 /* Free underlying irq if last user unmapped */ 303 310 index = -1; ··· 319 326 free_irq(uirq->uirq, priv); 320 327 } 321 328 322 - spin_unlock_irqrestore(&priv->bgc.lock, flags); 329 + spin_unlock_irqrestore(&priv->gc.bgpio_lock, flags); 323 330 } 324 331 325 332 static const struct irq_domain_ops grgpio_irq_domain_ops = { ··· 334 341 struct device_node *np = ofdev->dev.of_node; 335 342 void __iomem *regs; 336 343 struct gpio_chip *gc; 337 - struct bgpio_chip *bgc; 338 344 struct grgpio_priv *priv; 339 345 struct resource *res; 340 346 int err; ··· 351 359 if (IS_ERR(regs)) 352 360 return PTR_ERR(regs); 353 361 354 - bgc = &priv->bgc; 355 - err = bgpio_init(bgc, &ofdev->dev, 4, regs + GRGPIO_DATA, 362 + gc = &priv->gc; 363 + err = bgpio_init(gc, &ofdev->dev, 4, regs + GRGPIO_DATA, 356 364 regs + GRGPIO_OUTPUT, NULL, regs + GRGPIO_DIR, NULL, 357 365 BGPIOF_BIG_ENDIAN_BYTE_ORDER); 358 366 if (err) { ··· 361 369 } 362 370 363 371 priv->regs = regs; 364 - priv->imask = bgc->read_reg(regs + GRGPIO_IMASK); 372 + priv->imask = gc->read_reg(regs + GRGPIO_IMASK); 365 373 priv->dev = &ofdev->dev; 366 374 367 - gc = &bgc->gc; 368 375 gc->of_node = np; 369 376 gc->owner = THIS_MODULE; 370 377 gc->to_irq = grgpio_to_irq; ··· 426 435 427 436 platform_set_drvdata(ofdev, priv); 428 437 429 - err = gpiochip_add(gc); 438 + err = gpiochip_add_data(gc, priv); 430 439 if (err) { 431 440 dev_err(&ofdev->dev, "Could not add gpiochip\n"); 432 441 if (priv->domain) ··· 447 456 int i; 448 457 int ret = 0; 449 458 450 - spin_lock_irqsave(&priv->bgc.lock, flags); 459 + spin_lock_irqsave(&priv->gc.bgpio_lock, flags); 451 460 452 461 if (priv->domain) { 453 462 for (i = 0; i < GRGPIO_MAX_NGPIO; i++) { ··· 458 467 } 459 468 } 460 469 461 - gpiochip_remove(&priv->bgc.gc); 470 + gpiochip_remove(&priv->gc); 462 471 463 472 if (priv->domain) 464 473 irq_domain_remove(priv->domain); 465 474 466 475 out: 467 - spin_unlock_irqrestore(&priv->bgc.lock, flags); 476 + spin_unlock_irqrestore(&priv->gc.bgpio_lock, flags); 468 477 469 478 return ret; 470 479 }
+2 -2
drivers/gpio/gpio-ich.c
··· 282 282 { 283 283 chip->owner = THIS_MODULE; 284 284 chip->label = DRV_NAME; 285 - chip->dev = &ichx_priv.dev->dev; 285 + chip->parent = &ichx_priv.dev->dev; 286 286 287 287 /* Allow chip-specific overrides of request()/get() */ 288 288 chip->request = ichx_priv.desc->request ? ··· 499 499 500 500 init: 501 501 ichx_gpiolib_setup(&ichx_priv.chip); 502 - err = gpiochip_add(&ichx_priv.chip); 502 + err = gpiochip_add_data(&ichx_priv.chip, NULL); 503 503 if (err) { 504 504 pr_err("Failed to register GPIOs\n"); 505 505 goto add_err;
+9 -14
drivers/gpio/gpio-intel-mid.c
··· 78 78 struct pci_dev *pdev; 79 79 }; 80 80 81 - static inline struct intel_mid_gpio *to_intel_gpio_priv(struct gpio_chip *gc) 82 - { 83 - return container_of(gc, struct intel_mid_gpio, chip); 84 - } 85 - 86 81 static void __iomem *gpio_reg(struct gpio_chip *chip, unsigned offset, 87 82 enum GPIO_REG reg_type) 88 83 { 89 - struct intel_mid_gpio *priv = to_intel_gpio_priv(chip); 84 + struct intel_mid_gpio *priv = gpiochip_get_data(chip); 90 85 unsigned nreg = chip->ngpio / 32; 91 86 u8 reg = offset / 32; 92 87 ··· 91 96 static void __iomem *gpio_reg_2bit(struct gpio_chip *chip, unsigned offset, 92 97 enum GPIO_REG reg_type) 93 98 { 94 - struct intel_mid_gpio *priv = to_intel_gpio_priv(chip); 99 + struct intel_mid_gpio *priv = gpiochip_get_data(chip); 95 100 unsigned nreg = chip->ngpio / 32; 96 101 u8 reg = offset / 16; 97 102 ··· 115 120 { 116 121 void __iomem *gplr = gpio_reg(chip, offset, GPLR); 117 122 118 - return readl(gplr) & BIT(offset % 32); 123 + return !!(readl(gplr) & BIT(offset % 32)); 119 124 } 120 125 121 126 static void intel_gpio_set(struct gpio_chip *chip, unsigned offset, int value) ··· 133 138 134 139 static int intel_gpio_direction_input(struct gpio_chip *chip, unsigned offset) 135 140 { 136 - struct intel_mid_gpio *priv = to_intel_gpio_priv(chip); 141 + struct intel_mid_gpio *priv = gpiochip_get_data(chip); 137 142 void __iomem *gpdr = gpio_reg(chip, offset, GPDR); 138 143 u32 value; 139 144 unsigned long flags; ··· 156 161 static int intel_gpio_direction_output(struct gpio_chip *chip, 157 162 unsigned offset, int value) 158 163 { 159 - struct intel_mid_gpio *priv = to_intel_gpio_priv(chip); 164 + struct intel_mid_gpio *priv = gpiochip_get_data(chip); 160 165 void __iomem *gpdr = gpio_reg(chip, offset, GPDR); 161 166 unsigned long flags; 162 167 ··· 180 185 static int intel_mid_irq_type(struct irq_data *d, unsigned type) 181 186 { 182 187 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 183 - struct intel_mid_gpio *priv = to_intel_gpio_priv(gc); 188 + struct intel_mid_gpio *priv = gpiochip_get_data(gc); 184 189 u32 gpio = irqd_to_hwirq(d); 185 190 unsigned long flags; 186 191 u32 value; ··· 299 304 static void intel_mid_irq_handler(struct irq_desc *desc) 300 305 { 301 306 struct gpio_chip *gc = irq_desc_get_handler_data(desc); 302 - struct intel_mid_gpio *priv = to_intel_gpio_priv(gc); 307 + struct intel_mid_gpio *priv = gpiochip_get_data(gc); 303 308 struct irq_data *data = irq_desc_get_irq_data(desc); 304 309 struct irq_chip *chip = irq_data_get_irq_chip(data); 305 310 u32 base, gpio, mask; ··· 387 392 388 393 priv->reg_base = pcim_iomap_table(pdev)[0]; 389 394 priv->chip.label = dev_name(&pdev->dev); 390 - priv->chip.dev = &pdev->dev; 395 + priv->chip.parent = &pdev->dev; 391 396 priv->chip.request = intel_gpio_request; 392 397 priv->chip.direction_input = intel_gpio_direction_input; 393 398 priv->chip.direction_output = intel_gpio_direction_output; ··· 401 406 spin_lock_init(&priv->lock); 402 407 403 408 pci_set_drvdata(pdev, priv); 404 - retval = gpiochip_add(&priv->chip); 409 + retval = gpiochip_add_data(&priv->chip, priv); 405 410 if (retval) { 406 411 dev_err(&pdev->dev, "gpiochip_add error %d\n", retval); 407 412 return retval;
+1 -1
drivers/gpio/gpio-iop.c
··· 114 114 if (IS_ERR(base)) 115 115 return PTR_ERR(base); 116 116 117 - return gpiochip_add(&iop3xx_chip); 117 + return gpiochip_add_data(&iop3xx_chip, NULL); 118 118 } 119 119 120 120 static struct platform_driver iop3xx_gpio_driver = {
+6 -11
drivers/gpio/gpio-it87.c
··· 77 77 .lock = __SPIN_LOCK_UNLOCKED(it87_gpio_chip.lock), 78 78 }; 79 79 80 - static inline struct it87_gpio *to_it87_gpio(struct gpio_chip *chip) 81 - { 82 - return container_of(chip, struct it87_gpio, chip); 83 - } 84 - 85 80 /* Superio chip access functions; copied from wdt_it87 */ 86 81 87 82 static inline int superio_enter(void) ··· 160 165 { 161 166 u8 mask, group; 162 167 int rc = 0; 163 - struct it87_gpio *it87_gpio = to_it87_gpio(chip); 168 + struct it87_gpio *it87_gpio = gpiochip_get_data(chip); 164 169 165 170 mask = 1 << (gpio_num % 8); 166 171 group = (gpio_num / 8); ··· 193 198 { 194 199 u16 reg; 195 200 u8 mask; 196 - struct it87_gpio *it87_gpio = to_it87_gpio(chip); 201 + struct it87_gpio *it87_gpio = gpiochip_get_data(chip); 197 202 198 203 mask = 1 << (gpio_num % 8); 199 204 reg = (gpio_num / 8) + it87_gpio->io_base; ··· 205 210 { 206 211 u8 mask, group; 207 212 int rc = 0; 208 - struct it87_gpio *it87_gpio = to_it87_gpio(chip); 213 + struct it87_gpio *it87_gpio = gpiochip_get_data(chip); 209 214 210 215 mask = 1 << (gpio_num % 8); 211 216 group = (gpio_num / 8); ··· 231 236 { 232 237 u8 mask, curr_vals; 233 238 u16 reg; 234 - struct it87_gpio *it87_gpio = to_it87_gpio(chip); 239 + struct it87_gpio *it87_gpio = gpiochip_get_data(chip); 235 240 236 241 mask = 1 << (gpio_num % 8); 237 242 reg = (gpio_num / 8) + it87_gpio->io_base; ··· 248 253 { 249 254 u8 mask, group; 250 255 int rc = 0; 251 - struct it87_gpio *it87_gpio = to_it87_gpio(chip); 256 + struct it87_gpio *it87_gpio = gpiochip_get_data(chip); 252 257 253 258 mask = 1 << (gpio_num % 8); 254 259 group = (gpio_num / 8); ··· 375 380 376 381 it87_gpio->chip.names = (const char *const*)labels_table; 377 382 378 - rc = gpiochip_add(&it87_gpio->chip); 383 + rc = gpiochip_add_data(&it87_gpio->chip, it87_gpio); 379 384 if (rc) 380 385 goto labels_free; 381 386
+5 -5
drivers/gpio/gpio-janz-ttl.c
··· 59 59 60 60 static int ttl_get_value(struct gpio_chip *gpio, unsigned offset) 61 61 { 62 - struct ttl_module *mod = dev_get_drvdata(gpio->dev); 62 + struct ttl_module *mod = dev_get_drvdata(gpio->parent); 63 63 u8 *shadow; 64 64 int ret; 65 65 ··· 76 76 spin_lock(&mod->lock); 77 77 ret = *shadow & (1 << offset); 78 78 spin_unlock(&mod->lock); 79 - return ret; 79 + return !!ret; 80 80 } 81 81 82 82 static void ttl_set_value(struct gpio_chip *gpio, unsigned offset, int value) 83 83 { 84 - struct ttl_module *mod = dev_get_drvdata(gpio->dev); 84 + struct ttl_module *mod = dev_get_drvdata(gpio->parent); 85 85 void __iomem *port; 86 86 u8 *shadow; 87 87 ··· 172 172 173 173 /* Initialize the GPIO data structures */ 174 174 gpio = &mod->gpio; 175 - gpio->dev = &pdev->dev; 175 + gpio->parent = &pdev->dev; 176 176 gpio->label = pdev->name; 177 177 gpio->get = ttl_get_value; 178 178 gpio->set = ttl_set_value; ··· 182 182 gpio->base = -1; 183 183 gpio->ngpio = 20; 184 184 185 - ret = gpiochip_add(gpio); 185 + ret = gpiochip_add_data(gpio, NULL); 186 186 if (ret) { 187 187 dev_err(dev, "unable to add GPIO chip\n"); 188 188 return ret;
+8 -13
drivers/gpio/gpio-kempld.c
··· 65 65 66 66 static int kempld_gpio_get(struct gpio_chip *chip, unsigned offset) 67 67 { 68 - struct kempld_gpio_data *gpio 69 - = container_of(chip, struct kempld_gpio_data, chip); 68 + struct kempld_gpio_data *gpio = gpiochip_get_data(chip); 70 69 struct kempld_device_data *pld = gpio->pld; 71 70 72 - return kempld_gpio_get_bit(pld, KEMPLD_GPIO_LVL_NUM(offset), offset); 71 + return !!kempld_gpio_get_bit(pld, KEMPLD_GPIO_LVL_NUM(offset), offset); 73 72 } 74 73 75 74 static void kempld_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 76 75 { 77 - struct kempld_gpio_data *gpio 78 - = container_of(chip, struct kempld_gpio_data, chip); 76 + struct kempld_gpio_data *gpio = gpiochip_get_data(chip); 79 77 struct kempld_device_data *pld = gpio->pld; 80 78 81 79 kempld_get_mutex(pld); ··· 83 85 84 86 static int kempld_gpio_direction_input(struct gpio_chip *chip, unsigned offset) 85 87 { 86 - struct kempld_gpio_data *gpio 87 - = container_of(chip, struct kempld_gpio_data, chip); 88 + struct kempld_gpio_data *gpio = gpiochip_get_data(chip); 88 89 struct kempld_device_data *pld = gpio->pld; 89 90 90 91 kempld_get_mutex(pld); ··· 96 99 static int kempld_gpio_direction_output(struct gpio_chip *chip, unsigned offset, 97 100 int value) 98 101 { 99 - struct kempld_gpio_data *gpio 100 - = container_of(chip, struct kempld_gpio_data, chip); 102 + struct kempld_gpio_data *gpio = gpiochip_get_data(chip); 101 103 struct kempld_device_data *pld = gpio->pld; 102 104 103 105 kempld_get_mutex(pld); ··· 109 113 110 114 static int kempld_gpio_get_direction(struct gpio_chip *chip, unsigned offset) 111 115 { 112 - struct kempld_gpio_data *gpio 113 - = container_of(chip, struct kempld_gpio_data, chip); 116 + struct kempld_gpio_data *gpio = gpiochip_get_data(chip); 114 117 struct kempld_device_data *pld = gpio->pld; 115 118 116 119 return !kempld_gpio_get_bit(pld, KEMPLD_GPIO_DIR_NUM(offset), offset); ··· 161 166 chip = &gpio->chip; 162 167 chip->label = "gpio-kempld"; 163 168 chip->owner = THIS_MODULE; 164 - chip->dev = dev; 169 + chip->parent = dev; 165 170 chip->can_sleep = true; 166 171 if (pdata && pdata->gpio_base) 167 172 chip->base = pdata->gpio_base; ··· 178 183 return -ENODEV; 179 184 } 180 185 181 - ret = gpiochip_add(chip); 186 + ret = gpiochip_add_data(chip, gpio); 182 187 if (ret) { 183 188 dev_err(dev, "Could not register GPIO chip\n"); 184 189 return ret;
+1 -1
drivers/gpio/gpio-ks8695.c
··· 234 234 /* Register the GPIOs */ 235 235 void ks8695_register_gpios(void) 236 236 { 237 - if (gpiochip_add(&ks8695_gpio_chip)) 237 + if (gpiochip_add_data(&ks8695_gpio_chip, NULL)) 238 238 printk(KERN_ERR "Unable to register core GPIOs\n"); 239 239 } 240 240
+1 -1
drivers/gpio/gpio-loongson.c
··· 110 110 111 111 static int __init loongson_gpio_setup(void) 112 112 { 113 - return gpiochip_add(&loongson_chip); 113 + return gpiochip_add_data(&loongson_chip, NULL); 114 114 } 115 115 postcore_initcall(loongson_gpio_setup);
+8 -13
drivers/gpio/gpio-lp3943.c
··· 45 45 u16 input_mask; /* 1 = GPIO is input direction, 0 = output */ 46 46 }; 47 47 48 - static inline struct lp3943_gpio *to_lp3943_gpio(struct gpio_chip *_chip) 49 - { 50 - return container_of(_chip, struct lp3943_gpio, chip); 51 - } 52 - 53 48 static int lp3943_gpio_request(struct gpio_chip *chip, unsigned offset) 54 49 { 55 - struct lp3943_gpio *lp3943_gpio = to_lp3943_gpio(chip); 50 + struct lp3943_gpio *lp3943_gpio = gpiochip_get_data(chip); 56 51 struct lp3943 *lp3943 = lp3943_gpio->lp3943; 57 52 58 53 /* Return an error if the pin is already assigned */ ··· 59 64 60 65 static void lp3943_gpio_free(struct gpio_chip *chip, unsigned offset) 61 66 { 62 - struct lp3943_gpio *lp3943_gpio = to_lp3943_gpio(chip); 67 + struct lp3943_gpio *lp3943_gpio = gpiochip_get_data(chip); 63 68 struct lp3943 *lp3943 = lp3943_gpio->lp3943; 64 69 65 70 clear_bit(offset, &lp3943->pin_used); ··· 77 82 78 83 static int lp3943_gpio_direction_input(struct gpio_chip *chip, unsigned offset) 79 84 { 80 - struct lp3943_gpio *lp3943_gpio = to_lp3943_gpio(chip); 85 + struct lp3943_gpio *lp3943_gpio = gpiochip_get_data(chip); 81 86 82 87 lp3943_gpio->input_mask |= BIT(offset); 83 88 ··· 133 138 134 139 static int lp3943_gpio_get(struct gpio_chip *chip, unsigned offset) 135 140 { 136 - struct lp3943_gpio *lp3943_gpio = to_lp3943_gpio(chip); 141 + struct lp3943_gpio *lp3943_gpio = gpiochip_get_data(chip); 137 142 138 143 /* 139 144 * Limitation: ··· 152 157 153 158 static void lp3943_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 154 159 { 155 - struct lp3943_gpio *lp3943_gpio = to_lp3943_gpio(chip); 160 + struct lp3943_gpio *lp3943_gpio = gpiochip_get_data(chip); 156 161 u8 data; 157 162 158 163 if (value) ··· 166 171 static int lp3943_gpio_direction_output(struct gpio_chip *chip, unsigned offset, 167 172 int value) 168 173 { 169 - struct lp3943_gpio *lp3943_gpio = to_lp3943_gpio(chip); 174 + struct lp3943_gpio *lp3943_gpio = gpiochip_get_data(chip); 170 175 171 176 lp3943_gpio_set(chip, offset, value); 172 177 lp3943_gpio->input_mask &= ~BIT(offset); ··· 200 205 201 206 lp3943_gpio->lp3943 = lp3943; 202 207 lp3943_gpio->chip = lp3943_gpio_chip; 203 - lp3943_gpio->chip.dev = &pdev->dev; 208 + lp3943_gpio->chip.parent = &pdev->dev; 204 209 205 210 platform_set_drvdata(pdev, lp3943_gpio); 206 211 207 - return gpiochip_add(&lp3943_gpio->chip); 212 + return gpiochip_add_data(&lp3943_gpio->chip, lp3943_gpio); 208 213 } 209 214 210 215 static int lp3943_gpio_remove(struct platform_device *pdev)
+5 -10
drivers/gpio/gpio-lpc18xx.c
··· 31 31 spinlock_t lock; 32 32 }; 33 33 34 - static inline struct lpc18xx_gpio_chip *to_lpc18xx_gpio(struct gpio_chip *chip) 35 - { 36 - return container_of(chip, struct lpc18xx_gpio_chip, gpio); 37 - } 38 - 39 34 static void lpc18xx_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 40 35 { 41 - struct lpc18xx_gpio_chip *gc = to_lpc18xx_gpio(chip); 36 + struct lpc18xx_gpio_chip *gc = gpiochip_get_data(chip); 42 37 writeb(value ? 1 : 0, gc->base + offset); 43 38 } 44 39 45 40 static int lpc18xx_gpio_get(struct gpio_chip *chip, unsigned offset) 46 41 { 47 - struct lpc18xx_gpio_chip *gc = to_lpc18xx_gpio(chip); 42 + struct lpc18xx_gpio_chip *gc = gpiochip_get_data(chip); 48 43 return !!readb(gc->base + offset); 49 44 } 50 45 51 46 static int lpc18xx_gpio_direction(struct gpio_chip *chip, unsigned offset, 52 47 bool out) 53 48 { 54 - struct lpc18xx_gpio_chip *gc = to_lpc18xx_gpio(chip); 49 + struct lpc18xx_gpio_chip *gc = gpiochip_get_data(chip); 55 50 unsigned long flags; 56 51 u32 port, pin, dir; 57 52 ··· 122 127 123 128 spin_lock_init(&gc->lock); 124 129 125 - gc->gpio.dev = &pdev->dev; 130 + gc->gpio.parent = &pdev->dev; 126 131 127 - ret = gpiochip_add(&gc->gpio); 132 + ret = gpiochip_add_data(&gc->gpio, gc); 128 133 if (ret) { 129 134 dev_err(&pdev->dev, "failed to add gpio chip\n"); 130 135 clk_disable_unprepare(gc->clk);
+18 -23
drivers/gpio/gpio-lpc32xx.c
··· 165 165 struct gpio_regs *gpio_grp; 166 166 }; 167 167 168 - static inline struct lpc32xx_gpio_chip *to_lpc32xx_gpio( 169 - struct gpio_chip *gpc) 170 - { 171 - return container_of(gpc, struct lpc32xx_gpio_chip, chip); 172 - } 173 - 174 168 static void __set_gpio_dir_p012(struct lpc32xx_gpio_chip *group, 175 169 unsigned pin, int input) 176 170 { ··· 255 261 static int lpc32xx_gpio_dir_input_p012(struct gpio_chip *chip, 256 262 unsigned pin) 257 263 { 258 - struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip); 264 + struct lpc32xx_gpio_chip *group = gpiochip_get_data(chip); 259 265 260 266 __set_gpio_dir_p012(group, pin, 1); 261 267 ··· 265 271 static int lpc32xx_gpio_dir_input_p3(struct gpio_chip *chip, 266 272 unsigned pin) 267 273 { 268 - struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip); 274 + struct lpc32xx_gpio_chip *group = gpiochip_get_data(chip); 269 275 270 276 __set_gpio_dir_p3(group, pin, 1); 271 277 ··· 280 286 281 287 static int lpc32xx_gpio_get_value_p012(struct gpio_chip *chip, unsigned pin) 282 288 { 283 - struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip); 289 + struct lpc32xx_gpio_chip *group = gpiochip_get_data(chip); 284 290 285 - return __get_gpio_state_p012(group, pin); 291 + return !!__get_gpio_state_p012(group, pin); 286 292 } 287 293 288 294 static int lpc32xx_gpio_get_value_p3(struct gpio_chip *chip, unsigned pin) 289 295 { 290 - struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip); 296 + struct lpc32xx_gpio_chip *group = gpiochip_get_data(chip); 291 297 292 - return __get_gpio_state_p3(group, pin); 298 + return !!__get_gpio_state_p3(group, pin); 293 299 } 294 300 295 301 static int lpc32xx_gpi_get_value(struct gpio_chip *chip, unsigned pin) 296 302 { 297 - struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip); 303 + struct lpc32xx_gpio_chip *group = gpiochip_get_data(chip); 298 304 299 - return __get_gpi_state_p3(group, pin); 305 + return !!__get_gpi_state_p3(group, pin); 300 306 } 301 307 302 308 static int lpc32xx_gpio_dir_output_p012(struct gpio_chip *chip, unsigned pin, 303 309 int value) 304 310 { 305 - struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip); 311 + struct lpc32xx_gpio_chip *group = gpiochip_get_data(chip); 306 312 307 313 __set_gpio_level_p012(group, pin, value); 308 314 __set_gpio_dir_p012(group, pin, 0); ··· 313 319 static int lpc32xx_gpio_dir_output_p3(struct gpio_chip *chip, unsigned pin, 314 320 int value) 315 321 { 316 - struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip); 322 + struct lpc32xx_gpio_chip *group = gpiochip_get_data(chip); 317 323 318 324 __set_gpio_level_p3(group, pin, value); 319 325 __set_gpio_dir_p3(group, pin, 0); ··· 324 330 static int lpc32xx_gpio_dir_out_always(struct gpio_chip *chip, unsigned pin, 325 331 int value) 326 332 { 327 - struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip); 333 + struct lpc32xx_gpio_chip *group = gpiochip_get_data(chip); 328 334 329 335 __set_gpo_level_p3(group, pin, value); 330 336 return 0; ··· 333 339 static void lpc32xx_gpio_set_value_p012(struct gpio_chip *chip, unsigned pin, 334 340 int value) 335 341 { 336 - struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip); 342 + struct lpc32xx_gpio_chip *group = gpiochip_get_data(chip); 337 343 338 344 __set_gpio_level_p012(group, pin, value); 339 345 } ··· 341 347 static void lpc32xx_gpio_set_value_p3(struct gpio_chip *chip, unsigned pin, 342 348 int value) 343 349 { 344 - struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip); 350 + struct lpc32xx_gpio_chip *group = gpiochip_get_data(chip); 345 351 346 352 __set_gpio_level_p3(group, pin, value); 347 353 } ··· 349 355 static void lpc32xx_gpo_set_value(struct gpio_chip *chip, unsigned pin, 350 356 int value) 351 357 { 352 - struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip); 358 + struct lpc32xx_gpio_chip *group = gpiochip_get_data(chip); 353 359 354 360 __set_gpo_level_p3(group, pin, value); 355 361 } 356 362 357 363 static int lpc32xx_gpo_get_value(struct gpio_chip *chip, unsigned pin) 358 364 { 359 - struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip); 365 + struct lpc32xx_gpio_chip *group = gpiochip_get_data(chip); 360 366 361 - return __get_gpo_state_p3(group, pin); 367 + return !!__get_gpo_state_p3(group, pin); 362 368 } 363 369 364 370 static int lpc32xx_gpio_request(struct gpio_chip *chip, unsigned pin) ··· 547 553 lpc32xx_gpiochip[i].chip.of_gpio_n_cells = 3; 548 554 lpc32xx_gpiochip[i].chip.of_node = pdev->dev.of_node; 549 555 } 550 - gpiochip_add(&lpc32xx_gpiochip[i].chip); 556 + gpiochip_add_data(&lpc32xx_gpiochip[i].chip, 557 + &lpc32xx_gpiochip[i]); 551 558 } 552 559 553 560 return 0;
+12 -12
drivers/gpio/gpio-lynxpoint.c
··· 97 97 static unsigned long lp_gpio_reg(struct gpio_chip *chip, unsigned offset, 98 98 int reg) 99 99 { 100 - struct lp_gpio *lg = container_of(chip, struct lp_gpio, chip); 100 + struct lp_gpio *lg = gpiochip_get_data(chip); 101 101 int reg_offset; 102 102 103 103 if (reg == LP_CONFIG1 || reg == LP_CONFIG2) ··· 112 112 113 113 static int lp_gpio_request(struct gpio_chip *chip, unsigned offset) 114 114 { 115 - struct lp_gpio *lg = container_of(chip, struct lp_gpio, chip); 115 + struct lp_gpio *lg = gpiochip_get_data(chip); 116 116 unsigned long reg = lp_gpio_reg(chip, offset, LP_CONFIG1); 117 117 unsigned long conf2 = lp_gpio_reg(chip, offset, LP_CONFIG2); 118 118 unsigned long acpi_use = lp_gpio_reg(chip, offset, LP_ACPI_OWNED); ··· 137 137 138 138 static void lp_gpio_free(struct gpio_chip *chip, unsigned offset) 139 139 { 140 - struct lp_gpio *lg = container_of(chip, struct lp_gpio, chip); 140 + struct lp_gpio *lg = gpiochip_get_data(chip); 141 141 unsigned long conf2 = lp_gpio_reg(chip, offset, LP_CONFIG2); 142 142 143 143 /* disable input sensing */ ··· 149 149 static int lp_irq_type(struct irq_data *d, unsigned type) 150 150 { 151 151 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 152 - struct lp_gpio *lg = container_of(gc, struct lp_gpio, chip); 152 + struct lp_gpio *lg = gpiochip_get_data(gc); 153 153 u32 hwirq = irqd_to_hwirq(d); 154 154 unsigned long flags; 155 155 u32 value; ··· 191 191 192 192 static void lp_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 193 193 { 194 - struct lp_gpio *lg = container_of(chip, struct lp_gpio, chip); 194 + struct lp_gpio *lg = gpiochip_get_data(chip); 195 195 unsigned long reg = lp_gpio_reg(chip, offset, LP_CONFIG1); 196 196 unsigned long flags; 197 197 ··· 207 207 208 208 static int lp_gpio_direction_input(struct gpio_chip *chip, unsigned offset) 209 209 { 210 - struct lp_gpio *lg = container_of(chip, struct lp_gpio, chip); 210 + struct lp_gpio *lg = gpiochip_get_data(chip); 211 211 unsigned long reg = lp_gpio_reg(chip, offset, LP_CONFIG1); 212 212 unsigned long flags; 213 213 ··· 221 221 static int lp_gpio_direction_output(struct gpio_chip *chip, 222 222 unsigned offset, int value) 223 223 { 224 - struct lp_gpio *lg = container_of(chip, struct lp_gpio, chip); 224 + struct lp_gpio *lg = gpiochip_get_data(chip); 225 225 unsigned long reg = lp_gpio_reg(chip, offset, LP_CONFIG1); 226 226 unsigned long flags; 227 227 ··· 238 238 { 239 239 struct irq_data *data = irq_desc_get_irq_data(desc); 240 240 struct gpio_chip *gc = irq_desc_get_handler_data(desc); 241 - struct lp_gpio *lg = container_of(gc, struct lp_gpio, chip); 241 + struct lp_gpio *lg = gpiochip_get_data(gc); 242 242 struct irq_chip *chip = irq_data_get_irq_chip(data); 243 243 u32 base, pin, mask; 244 244 unsigned long reg, ena, pending; ··· 273 273 static void lp_irq_enable(struct irq_data *d) 274 274 { 275 275 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 276 - struct lp_gpio *lg = container_of(gc, struct lp_gpio, chip); 276 + struct lp_gpio *lg = gpiochip_get_data(gc); 277 277 u32 hwirq = irqd_to_hwirq(d); 278 278 unsigned long reg = lp_gpio_reg(&lg->chip, hwirq, LP_INT_ENABLE); 279 279 unsigned long flags; ··· 286 286 static void lp_irq_disable(struct irq_data *d) 287 287 { 288 288 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 289 - struct lp_gpio *lg = container_of(gc, struct lp_gpio, chip); 289 + struct lp_gpio *lg = gpiochip_get_data(gc); 290 290 u32 hwirq = irqd_to_hwirq(d); 291 291 unsigned long reg = lp_gpio_reg(&lg->chip, hwirq, LP_INT_ENABLE); 292 292 unsigned long flags; ··· 368 368 gc->base = -1; 369 369 gc->ngpio = LP_NUM_GPIO; 370 370 gc->can_sleep = false; 371 - gc->dev = dev; 371 + gc->parent = dev; 372 372 373 - ret = gpiochip_add(gc); 373 + ret = gpiochip_add_data(gc, lg); 374 374 if (ret) { 375 375 dev_err(dev, "failed adding lp-gpio chip\n"); 376 376 return ret;
-1
drivers/gpio/gpio-max7300.c
··· 65 65 static struct i2c_driver max7300_driver = { 66 66 .driver = { 67 67 .name = "max7300", 68 - .owner = THIS_MODULE, 69 68 }, 70 69 .probe = max7300_probe, 71 70 .remove = max7300_remove,
+6 -6
drivers/gpio/gpio-max730x.c
··· 50 50 51 51 static int max7301_direction_input(struct gpio_chip *chip, unsigned offset) 52 52 { 53 - struct max7301 *ts = container_of(chip, struct max7301, chip); 53 + struct max7301 *ts = gpiochip_get_data(chip); 54 54 u8 *config; 55 55 u8 offset_bits, pin_config; 56 56 int ret; ··· 92 92 static int max7301_direction_output(struct gpio_chip *chip, unsigned offset, 93 93 int value) 94 94 { 95 - struct max7301 *ts = container_of(chip, struct max7301, chip); 95 + struct max7301 *ts = gpiochip_get_data(chip); 96 96 u8 *config; 97 97 u8 offset_bits; 98 98 int ret; ··· 120 120 121 121 static int max7301_get(struct gpio_chip *chip, unsigned offset) 122 122 { 123 - struct max7301 *ts = container_of(chip, struct max7301, chip); 123 + struct max7301 *ts = gpiochip_get_data(chip); 124 124 int config, level = -EINVAL; 125 125 126 126 /* First 4 pins are unused in the controller */ ··· 148 148 149 149 static void max7301_set(struct gpio_chip *chip, unsigned offset, int value) 150 150 { 151 - struct max7301 *ts = container_of(chip, struct max7301, chip); 151 + struct max7301 *ts = gpiochip_get_data(chip); 152 152 153 153 /* First 4 pins are unused in the controller */ 154 154 offset += 4; ··· 189 189 190 190 ts->chip.ngpio = PIN_NUMBER; 191 191 ts->chip.can_sleep = true; 192 - ts->chip.dev = dev; 192 + ts->chip.parent = dev; 193 193 ts->chip.owner = THIS_MODULE; 194 194 195 195 /* ··· 213 213 } 214 214 } 215 215 216 - ret = gpiochip_add(&ts->chip); 216 + ret = gpiochip_add_data(&ts->chip, ts); 217 217 if (ret) 218 218 goto exit_destroy; 219 219
+14 -20
drivers/gpio/gpio-max732x.c
··· 158 158 #endif 159 159 }; 160 160 161 - static inline struct max732x_chip *to_max732x(struct gpio_chip *gc) 162 - { 163 - return container_of(gc, struct max732x_chip, gpio_chip); 164 - } 165 - 166 161 static int max732x_writeb(struct max732x_chip *chip, int group_a, uint8_t val) 167 162 { 168 163 struct i2c_client *client; ··· 196 201 197 202 static int max732x_gpio_get_value(struct gpio_chip *gc, unsigned off) 198 203 { 199 - struct max732x_chip *chip = to_max732x(gc); 204 + struct max732x_chip *chip = gpiochip_get_data(gc); 200 205 uint8_t reg_val; 201 206 int ret; 202 207 203 208 ret = max732x_readb(chip, is_group_a(chip, off), &reg_val); 204 209 if (ret < 0) 205 - return 0; 210 + return ret; 206 211 207 - return reg_val & (1u << (off & 0x7)); 212 + return !!(reg_val & (1u << (off & 0x7))); 208 213 } 209 214 210 215 static void max732x_gpio_set_mask(struct gpio_chip *gc, unsigned off, int mask, 211 216 int val) 212 217 { 213 - struct max732x_chip *chip = to_max732x(gc); 218 + struct max732x_chip *chip = gpiochip_get_data(gc); 214 219 uint8_t reg_out; 215 220 int ret; 216 221 ··· 254 259 255 260 static int max732x_gpio_direction_input(struct gpio_chip *gc, unsigned off) 256 261 { 257 - struct max732x_chip *chip = to_max732x(gc); 262 + struct max732x_chip *chip = gpiochip_get_data(gc); 258 263 unsigned int mask = 1u << off; 259 264 260 265 if ((mask & chip->dir_input) == 0) { ··· 276 281 static int max732x_gpio_direction_output(struct gpio_chip *gc, 277 282 unsigned off, int val) 278 283 { 279 - struct max732x_chip *chip = to_max732x(gc); 284 + struct max732x_chip *chip = gpiochip_get_data(gc); 280 285 unsigned int mask = 1u << off; 281 286 282 287 if ((mask & chip->dir_output) == 0) { ··· 351 356 static void max732x_irq_mask(struct irq_data *d) 352 357 { 353 358 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 354 - struct max732x_chip *chip = to_max732x(gc); 359 + struct max732x_chip *chip = gpiochip_get_data(gc); 355 360 356 361 chip->irq_mask_cur &= ~(1 << d->hwirq); 357 362 } ··· 359 364 static void max732x_irq_unmask(struct irq_data *d) 360 365 { 361 366 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 362 - struct max732x_chip *chip = to_max732x(gc); 367 + struct max732x_chip *chip = gpiochip_get_data(gc); 363 368 364 369 chip->irq_mask_cur |= 1 << d->hwirq; 365 370 } ··· 367 372 static void max732x_irq_bus_lock(struct irq_data *d) 368 373 { 369 374 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 370 - struct max732x_chip *chip = to_max732x(gc); 375 + struct max732x_chip *chip = gpiochip_get_data(gc); 371 376 372 377 mutex_lock(&chip->irq_lock); 373 378 chip->irq_mask_cur = chip->irq_mask; ··· 376 381 static void max732x_irq_bus_sync_unlock(struct irq_data *d) 377 382 { 378 383 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 379 - struct max732x_chip *chip = to_max732x(gc); 384 + struct max732x_chip *chip = gpiochip_get_data(gc); 380 385 uint16_t new_irqs; 381 386 uint16_t level; 382 387 ··· 395 400 static int max732x_irq_set_type(struct irq_data *d, unsigned int type) 396 401 { 397 402 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 398 - struct max732x_chip *chip = to_max732x(gc); 403 + struct max732x_chip *chip = gpiochip_get_data(gc); 399 404 uint16_t off = d->hwirq; 400 405 uint16_t mask = 1 << off; 401 406 ··· 598 603 gc->base = gpio_start; 599 604 gc->ngpio = port; 600 605 gc->label = chip->client->name; 601 - gc->dev = &chip->client->dev; 606 + gc->parent = &chip->client->dev; 602 607 gc->owner = THIS_MODULE; 603 608 604 609 return port; ··· 644 649 chip->client = client; 645 650 646 651 nr_port = max732x_setup_gpio(chip, id, pdata->gpio_base); 647 - chip->gpio_chip.dev = &client->dev; 652 + chip->gpio_chip.parent = &client->dev; 648 653 649 654 addr_a = (client->addr & 0x0f) | 0x60; 650 655 addr_b = (client->addr & 0x0f) | 0x50; ··· 689 694 goto out_failed; 690 695 } 691 696 692 - ret = gpiochip_add(&chip->gpio_chip); 697 + ret = gpiochip_add_data(&chip->gpio_chip, chip); 693 698 if (ret) 694 699 goto out_failed; 695 700 ··· 744 749 static struct i2c_driver max732x_driver = { 745 750 .driver = { 746 751 .name = "max732x", 747 - .owner = THIS_MODULE, 748 752 .of_match_table = of_match_ptr(max732x_of_table), 749 753 }, 750 754 .probe = max732x_probe,
+8 -13
drivers/gpio/gpio-mb86s7x.c
··· 44 44 spinlock_t lock; 45 45 }; 46 46 47 - static inline struct mb86s70_gpio_chip *chip_to_mb86s70(struct gpio_chip *gc) 48 - { 49 - return container_of(gc, struct mb86s70_gpio_chip, gc); 50 - } 51 - 52 47 static int mb86s70_gpio_request(struct gpio_chip *gc, unsigned gpio) 53 48 { 54 - struct mb86s70_gpio_chip *gchip = chip_to_mb86s70(gc); 49 + struct mb86s70_gpio_chip *gchip = gpiochip_get_data(gc); 55 50 unsigned long flags; 56 51 u32 val; 57 52 ··· 68 73 69 74 static void mb86s70_gpio_free(struct gpio_chip *gc, unsigned gpio) 70 75 { 71 - struct mb86s70_gpio_chip *gchip = chip_to_mb86s70(gc); 76 + struct mb86s70_gpio_chip *gchip = gpiochip_get_data(gc); 72 77 unsigned long flags; 73 78 u32 val; 74 79 ··· 83 88 84 89 static int mb86s70_gpio_direction_input(struct gpio_chip *gc, unsigned gpio) 85 90 { 86 - struct mb86s70_gpio_chip *gchip = chip_to_mb86s70(gc); 91 + struct mb86s70_gpio_chip *gchip = gpiochip_get_data(gc); 87 92 unsigned long flags; 88 93 unsigned char val; 89 94 ··· 101 106 static int mb86s70_gpio_direction_output(struct gpio_chip *gc, 102 107 unsigned gpio, int value) 103 108 { 104 - struct mb86s70_gpio_chip *gchip = chip_to_mb86s70(gc); 109 + struct mb86s70_gpio_chip *gchip = gpiochip_get_data(gc); 105 110 unsigned long flags; 106 111 unsigned char val; 107 112 ··· 125 130 126 131 static int mb86s70_gpio_get(struct gpio_chip *gc, unsigned gpio) 127 132 { 128 - struct mb86s70_gpio_chip *gchip = chip_to_mb86s70(gc); 133 + struct mb86s70_gpio_chip *gchip = gpiochip_get_data(gc); 129 134 130 135 return !!(readl(gchip->base + PDR(gpio)) & OFFSET(gpio)); 131 136 } 132 137 133 138 static void mb86s70_gpio_set(struct gpio_chip *gc, unsigned gpio, int value) 134 139 { 135 - struct mb86s70_gpio_chip *gchip = chip_to_mb86s70(gc); 140 + struct mb86s70_gpio_chip *gchip = gpiochip_get_data(gc); 136 141 unsigned long flags; 137 142 unsigned char val; 138 143 ··· 182 187 gchip->gc.label = dev_name(&pdev->dev); 183 188 gchip->gc.ngpio = 32; 184 189 gchip->gc.owner = THIS_MODULE; 185 - gchip->gc.dev = &pdev->dev; 190 + gchip->gc.parent = &pdev->dev; 186 191 gchip->gc.base = -1; 187 192 188 193 platform_set_drvdata(pdev, gchip); 189 194 190 - ret = gpiochip_add(&gchip->gc); 195 + ret = gpiochip_add_data(&gchip->gc, gchip); 191 196 if (ret) { 192 197 dev_err(&pdev->dev, "couldn't register gpio driver\n"); 193 198 clk_disable_unprepare(gchip->clk);
+3 -3
drivers/gpio/gpio-mc33880.c
··· 71 71 72 72 static void mc33880_set(struct gpio_chip *chip, unsigned offset, int value) 73 73 { 74 - struct mc33880 *mc = container_of(chip, struct mc33880, chip); 74 + struct mc33880 *mc = gpiochip_get_data(chip); 75 75 76 76 mutex_lock(&mc->lock); 77 77 ··· 116 116 mc->chip.base = pdata->base; 117 117 mc->chip.ngpio = PIN_NUMBER; 118 118 mc->chip.can_sleep = true; 119 - mc->chip.dev = &spi->dev; 119 + mc->chip.parent = &spi->dev; 120 120 mc->chip.owner = THIS_MODULE; 121 121 122 122 mc->port_config = 0x00; ··· 135 135 goto exit_destroy; 136 136 } 137 137 138 - ret = gpiochip_add(&mc->chip); 138 + ret = gpiochip_add_data(&mc->chip, mc); 139 139 if (ret) 140 140 goto exit_destroy; 141 141
+5 -12
drivers/gpio/gpio-mc9s08dz60.c
··· 29 29 struct gpio_chip chip; 30 30 }; 31 31 32 - static inline struct mc9s08dz60 *to_mc9s08dz60(struct gpio_chip *gc) 33 - { 34 - return container_of(gc, struct mc9s08dz60, chip); 35 - } 36 - 37 - 38 32 static void mc9s_gpio_to_reg_and_bit(int offset, u8 *reg, u8 *bit) 39 33 { 40 34 *reg = 0x20 + offset / GPIO_NUM_PER_GROUP; ··· 39 45 { 40 46 u8 reg, bit; 41 47 s32 value; 42 - struct mc9s08dz60 *mc9s = to_mc9s08dz60(gc); 48 + struct mc9s08dz60 *mc9s = gpiochip_get_data(gc); 43 49 44 50 mc9s_gpio_to_reg_and_bit(offset, &reg, &bit); 45 51 value = i2c_smbus_read_byte_data(mc9s->client, reg); ··· 69 75 70 76 static void mc9s08dz60_set_value(struct gpio_chip *gc, unsigned offset, int val) 71 77 { 72 - struct mc9s08dz60 *mc9s = to_mc9s08dz60(gc); 78 + struct mc9s08dz60 *mc9s = gpiochip_get_data(gc); 73 79 74 80 mc9s08dz60_set(mc9s, offset, val); 75 81 } ··· 77 83 static int mc9s08dz60_direction_output(struct gpio_chip *gc, 78 84 unsigned offset, int val) 79 85 { 80 - struct mc9s08dz60 *mc9s = to_mc9s08dz60(gc); 86 + struct mc9s08dz60 *mc9s = gpiochip_get_data(gc); 81 87 82 88 return mc9s08dz60_set(mc9s, offset, val); 83 89 } ··· 93 99 94 100 mc9s->chip.label = client->name; 95 101 mc9s->chip.base = -1; 96 - mc9s->chip.dev = &client->dev; 102 + mc9s->chip.parent = &client->dev; 97 103 mc9s->chip.owner = THIS_MODULE; 98 104 mc9s->chip.ngpio = GPIO_NUM; 99 105 mc9s->chip.can_sleep = true; ··· 103 109 mc9s->client = client; 104 110 i2c_set_clientdata(client, mc9s); 105 111 106 - return gpiochip_add(&mc9s->chip); 112 + return gpiochip_add_data(&mc9s->chip, mc9s); 107 113 } 108 114 109 115 static int mc9s08dz60_remove(struct i2c_client *client) ··· 125 131 126 132 static struct i2c_driver mc9s08dz60_i2c_driver = { 127 133 .driver = { 128 - .owner = THIS_MODULE, 129 134 .name = "mc9s08dz60", 130 135 }, 131 136 .probe = mc9s08dz60_probe,
+16 -14
drivers/gpio/gpio-mcp23s08.c
··· 269 269 270 270 static int mcp23s08_direction_input(struct gpio_chip *chip, unsigned offset) 271 271 { 272 - struct mcp23s08 *mcp = container_of(chip, struct mcp23s08, chip); 272 + struct mcp23s08 *mcp = gpiochip_get_data(chip); 273 273 int status; 274 274 275 275 mutex_lock(&mcp->lock); ··· 281 281 282 282 static int mcp23s08_get(struct gpio_chip *chip, unsigned offset) 283 283 { 284 - struct mcp23s08 *mcp = container_of(chip, struct mcp23s08, chip); 284 + struct mcp23s08 *mcp = gpiochip_get_data(chip); 285 285 int status; 286 286 287 287 mutex_lock(&mcp->lock); ··· 312 312 313 313 static void mcp23s08_set(struct gpio_chip *chip, unsigned offset, int value) 314 314 { 315 - struct mcp23s08 *mcp = container_of(chip, struct mcp23s08, chip); 315 + struct mcp23s08 *mcp = gpiochip_get_data(chip); 316 316 unsigned mask = 1 << offset; 317 317 318 318 mutex_lock(&mcp->lock); ··· 323 323 static int 324 324 mcp23s08_direction_output(struct gpio_chip *chip, unsigned offset, int value) 325 325 { 326 - struct mcp23s08 *mcp = container_of(chip, struct mcp23s08, chip); 326 + struct mcp23s08 *mcp = gpiochip_get_data(chip); 327 327 unsigned mask = 1 << offset; 328 328 int status; 329 329 ··· 377 377 378 378 static int mcp23s08_gpio_to_irq(struct gpio_chip *chip, unsigned offset) 379 379 { 380 - struct mcp23s08 *mcp = container_of(chip, struct mcp23s08, chip); 380 + struct mcp23s08 *mcp = gpiochip_get_data(chip); 381 381 382 382 return irq_find_mapping(mcp->irq_domain, offset); 383 383 } ··· 446 446 struct mcp23s08 *mcp = irq_data_get_irq_chip_data(data); 447 447 448 448 if (gpiochip_lock_as_irq(&mcp->chip, data->hwirq)) { 449 - dev_err(mcp->chip.dev, 449 + dev_err(mcp->chip.parent, 450 450 "unable to lock HW IRQ %lu for IRQ usage\n", 451 451 data->hwirq); 452 452 return -EINVAL; ··· 481 481 482 482 mutex_init(&mcp->irq_lock); 483 483 484 - mcp->irq_domain = irq_domain_add_linear(chip->dev->of_node, chip->ngpio, 484 + mcp->irq_domain = irq_domain_add_linear(chip->parent->of_node, 485 + chip->ngpio, 485 486 &irq_domain_simple_ops, mcp); 486 487 if (!mcp->irq_domain) 487 488 return -ENODEV; ··· 492 491 else 493 492 irqflags |= IRQF_TRIGGER_LOW; 494 493 495 - err = devm_request_threaded_irq(chip->dev, mcp->irq, NULL, mcp23s08_irq, 496 - irqflags, dev_name(chip->dev), mcp); 494 + err = devm_request_threaded_irq(chip->parent, mcp->irq, NULL, 495 + mcp23s08_irq, 496 + irqflags, dev_name(chip->parent), mcp); 497 497 if (err != 0) { 498 - dev_err(chip->dev, "unable to request IRQ#%d: %d\n", 498 + dev_err(chip->parent, "unable to request IRQ#%d: %d\n", 499 499 mcp->irq, err); 500 500 return err; 501 501 } ··· 544 542 int t; 545 543 unsigned mask; 546 544 547 - mcp = container_of(chip, struct mcp23s08, chip); 545 + mcp = gpiochip_get_data(chip); 548 546 549 547 /* NOTE: we only handle one bank for now ... */ 550 548 bank = '0' + ((mcp->addr >> 1) & 0x7); ··· 640 638 641 639 mcp->chip.base = pdata->base; 642 640 mcp->chip.can_sleep = true; 643 - mcp->chip.dev = dev; 641 + mcp->chip.parent = dev; 644 642 mcp->chip.owner = THIS_MODULE; 645 643 646 644 /* verify MCP_IOCON.SEQOP = 0, so sequential reads work, ··· 654 652 mcp->irq_controller = pdata->irq_controller; 655 653 if (mcp->irq && mcp->irq_controller) { 656 654 mcp->irq_active_high = 657 - of_property_read_bool(mcp->chip.dev->of_node, 655 + of_property_read_bool(mcp->chip.parent->of_node, 658 656 "microchip,irq-active-high"); 659 657 660 658 if (type == MCP_TYPE_017) ··· 704 702 goto fail; 705 703 } 706 704 707 - status = gpiochip_add(&mcp->chip); 705 + status = gpiochip_add_data(&mcp->chip, mcp); 708 706 if (status < 0) 709 707 goto fail; 710 708
+7 -7
drivers/gpio/gpio-ml-ioh.c
··· 106 106 static void ioh_gpio_set(struct gpio_chip *gpio, unsigned nr, int val) 107 107 { 108 108 u32 reg_val; 109 - struct ioh_gpio *chip = container_of(gpio, struct ioh_gpio, gpio); 109 + struct ioh_gpio *chip = gpiochip_get_data(gpio); 110 110 unsigned long flags; 111 111 112 112 spin_lock_irqsave(&chip->spinlock, flags); ··· 122 122 123 123 static int ioh_gpio_get(struct gpio_chip *gpio, unsigned nr) 124 124 { 125 - struct ioh_gpio *chip = container_of(gpio, struct ioh_gpio, gpio); 125 + struct ioh_gpio *chip = gpiochip_get_data(gpio); 126 126 127 - return ioread32(&chip->reg->regs[chip->ch].pi) & (1 << nr); 127 + return !!(ioread32(&chip->reg->regs[chip->ch].pi) & (1 << nr)); 128 128 } 129 129 130 130 static int ioh_gpio_direction_output(struct gpio_chip *gpio, unsigned nr, 131 131 int val) 132 132 { 133 - struct ioh_gpio *chip = container_of(gpio, struct ioh_gpio, gpio); 133 + struct ioh_gpio *chip = gpiochip_get_data(gpio); 134 134 u32 pm; 135 135 u32 reg_val; 136 136 unsigned long flags; ··· 155 155 156 156 static int ioh_gpio_direction_input(struct gpio_chip *gpio, unsigned nr) 157 157 { 158 - struct ioh_gpio *chip = container_of(gpio, struct ioh_gpio, gpio); 158 + struct ioh_gpio *chip = gpiochip_get_data(gpio); 159 159 u32 pm; 160 160 unsigned long flags; 161 161 ··· 225 225 226 226 static int ioh_gpio_to_irq(struct gpio_chip *gpio, unsigned offset) 227 227 { 228 - struct ioh_gpio *chip = container_of(gpio, struct ioh_gpio, gpio); 228 + struct ioh_gpio *chip = gpiochip_get_data(gpio); 229 229 return chip->irq_base + offset; 230 230 } 231 231 ··· 450 450 chip->ch = i; 451 451 spin_lock_init(&chip->spinlock); 452 452 ioh_gpio_setup(chip, num_ports[i]); 453 - ret = gpiochip_add(&chip->gpio); 453 + ret = gpiochip_add_data(&chip->gpio, chip); 454 454 if (ret) { 455 455 dev_err(&pdev->dev, "IOH gpio: Failed to register GPIO\n"); 456 456 goto err_gpiochip_add;
+2 -4
drivers/gpio/gpio-mm-lantiq.c
··· 61 61 */ 62 62 static void ltq_mm_set(struct gpio_chip *gc, unsigned offset, int value) 63 63 { 64 - struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc); 65 - struct ltq_mm *chip = 66 - container_of(mm_gc, struct ltq_mm, mmchip); 64 + struct ltq_mm *chip = gpiochip_get_data(gc); 67 65 68 66 if (value) 69 67 chip->shadow |= (1 << offset); ··· 120 122 if (!of_property_read_u32(pdev->dev.of_node, "lantiq,shadow", &shadow)) 121 123 chip->shadow = shadow; 122 124 123 - return of_mm_gpiochip_add(pdev->dev.of_node, &chip->mmchip); 125 + return of_mm_gpiochip_add_data(pdev->dev.of_node, &chip->mmchip, chip); 124 126 } 125 127 126 128 static int ltq_mm_remove(struct platform_device *pdev)
+14 -15
drivers/gpio/gpio-moxart.c
··· 14 14 #include <linux/init.h> 15 15 #include <linux/irq.h> 16 16 #include <linux/io.h> 17 - #include <linux/gpio.h> 18 17 #include <linux/platform_device.h> 19 18 #include <linux/module.h> 20 19 #include <linux/of_address.h> ··· 22 23 #include <linux/delay.h> 23 24 #include <linux/timer.h> 24 25 #include <linux/bitops.h> 25 - #include <linux/basic_mmio_gpio.h> 26 + #include <linux/gpio/driver.h> 26 27 27 28 #define GPIO_DATA_OUT 0x00 28 29 #define GPIO_DATA_IN 0x04 ··· 32 33 { 33 34 struct device *dev = &pdev->dev; 34 35 struct resource *res; 35 - struct bgpio_chip *bgc; 36 + struct gpio_chip *gc; 36 37 void __iomem *base; 37 38 int ret; 38 39 39 - bgc = devm_kzalloc(dev, sizeof(*bgc), GFP_KERNEL); 40 - if (!bgc) 40 + gc = devm_kzalloc(dev, sizeof(*gc), GFP_KERNEL); 41 + if (!gc) 41 42 return -ENOMEM; 42 43 43 44 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); ··· 45 46 if (IS_ERR(base)) 46 47 return PTR_ERR(base); 47 48 48 - ret = bgpio_init(bgc, dev, 4, base + GPIO_DATA_IN, 49 + ret = bgpio_init(gc, dev, 4, base + GPIO_DATA_IN, 49 50 base + GPIO_DATA_OUT, NULL, 50 51 base + GPIO_PIN_DIRECTION, NULL, 51 52 BGPIOF_READ_OUTPUT_REG_SET); ··· 54 55 return ret; 55 56 } 56 57 57 - bgc->gc.label = "moxart-gpio"; 58 - bgc->gc.request = gpiochip_generic_request; 59 - bgc->gc.free = gpiochip_generic_free; 60 - bgc->data = bgc->read_reg(bgc->reg_set); 61 - bgc->gc.base = 0; 62 - bgc->gc.ngpio = 32; 63 - bgc->gc.dev = dev; 64 - bgc->gc.owner = THIS_MODULE; 58 + gc->label = "moxart-gpio"; 59 + gc->request = gpiochip_generic_request; 60 + gc->free = gpiochip_generic_free; 61 + gc->bgpio_data = gc->read_reg(gc->reg_set); 62 + gc->base = 0; 63 + gc->ngpio = 32; 64 + gc->parent = dev; 65 + gc->owner = THIS_MODULE; 65 66 66 - ret = gpiochip_add(&bgc->gc); 67 + ret = gpiochip_add_data(gc, NULL); 67 68 if (ret) { 68 69 dev_err(dev, "%s: gpiochip_add failed\n", 69 70 dev->of_node->full_name);
+15 -24
drivers/gpio/gpio-mpc5200.c
··· 71 71 __mpc52xx_wkup_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val) 72 72 { 73 73 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc); 74 - struct mpc52xx_gpiochip *chip = container_of(mm_gc, 75 - struct mpc52xx_gpiochip, mmchip); 74 + struct mpc52xx_gpiochip *chip = gpiochip_get_data(gc); 76 75 struct mpc52xx_gpio_wkup __iomem *regs = mm_gc->regs; 77 76 78 77 if (val) ··· 99 100 static int mpc52xx_wkup_gpio_dir_in(struct gpio_chip *gc, unsigned int gpio) 100 101 { 101 102 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc); 102 - struct mpc52xx_gpiochip *chip = container_of(mm_gc, 103 - struct mpc52xx_gpiochip, mmchip); 103 + struct mpc52xx_gpiochip *chip = gpiochip_get_data(gc); 104 104 struct mpc52xx_gpio_wkup __iomem *regs = mm_gc->regs; 105 105 unsigned long flags; 106 106 ··· 123 125 { 124 126 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc); 125 127 struct mpc52xx_gpio_wkup __iomem *regs = mm_gc->regs; 126 - struct mpc52xx_gpiochip *chip = container_of(mm_gc, 127 - struct mpc52xx_gpiochip, mmchip); 128 + struct mpc52xx_gpiochip *chip = gpiochip_get_data(gc); 128 129 unsigned long flags; 129 130 130 131 spin_lock_irqsave(&gpio_lock, flags); ··· 166 169 gc->get = mpc52xx_wkup_gpio_get; 167 170 gc->set = mpc52xx_wkup_gpio_set; 168 171 169 - ret = of_mm_gpiochip_add(ofdev->dev.of_node, &chip->mmchip); 172 + ret = of_mm_gpiochip_add_data(ofdev->dev.of_node, &chip->mmchip, chip); 170 173 if (ret) 171 174 return ret; 172 175 ··· 233 236 __mpc52xx_simple_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val) 234 237 { 235 238 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc); 236 - struct mpc52xx_gpiochip *chip = container_of(mm_gc, 237 - struct mpc52xx_gpiochip, mmchip); 239 + struct mpc52xx_gpiochip *chip = gpiochip_get_data(gc); 238 240 struct mpc52xx_gpio __iomem *regs = mm_gc->regs; 239 241 240 242 if (val) ··· 260 264 static int mpc52xx_simple_gpio_dir_in(struct gpio_chip *gc, unsigned int gpio) 261 265 { 262 266 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc); 263 - struct mpc52xx_gpiochip *chip = container_of(mm_gc, 264 - struct mpc52xx_gpiochip, mmchip); 267 + struct mpc52xx_gpiochip *chip = gpiochip_get_data(gc); 265 268 struct mpc52xx_gpio __iomem *regs = mm_gc->regs; 266 269 unsigned long flags; 267 270 ··· 283 288 mpc52xx_simple_gpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val) 284 289 { 285 290 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc); 286 - struct mpc52xx_gpiochip *chip = container_of(mm_gc, 287 - struct mpc52xx_gpiochip, mmchip); 291 + struct mpc52xx_gpiochip *chip = gpiochip_get_data(gc); 288 292 struct mpc52xx_gpio __iomem *regs = mm_gc->regs; 289 293 unsigned long flags; 290 294 ··· 328 334 gc->get = mpc52xx_simple_gpio_get; 329 335 gc->set = mpc52xx_simple_gpio_set; 330 336 331 - ret = of_mm_gpiochip_add(ofdev->dev.of_node, &chip->mmchip); 337 + ret = of_mm_gpiochip_add_data(ofdev->dev.of_node, &chip->mmchip, chip); 332 338 if (ret) 333 339 return ret; 334 340 ··· 354 360 .remove = mpc52xx_gpiochip_remove, 355 361 }; 356 362 363 + static struct platform_driver * const drivers[] = { 364 + &mpc52xx_wkup_gpiochip_driver, 365 + &mpc52xx_simple_gpiochip_driver, 366 + }; 367 + 357 368 static int __init mpc52xx_gpio_init(void) 358 369 { 359 - if (platform_driver_register(&mpc52xx_wkup_gpiochip_driver)) 360 - printk(KERN_ERR "Unable to register wakeup GPIO driver\n"); 361 - 362 - if (platform_driver_register(&mpc52xx_simple_gpiochip_driver)) 363 - printk(KERN_ERR "Unable to register simple GPIO driver\n"); 364 - 365 - return 0; 370 + return platform_register_drivers(drivers, ARRAY_SIZE(drivers)); 366 371 } 367 372 368 373 /* Make sure we get initialised before anyone else tries to use us */ ··· 369 376 370 377 static void __exit mpc52xx_gpio_exit(void) 371 378 { 372 - platform_driver_unregister(&mpc52xx_wkup_gpiochip_driver); 373 - 374 - platform_driver_unregister(&mpc52xx_simple_gpiochip_driver); 379 + platform_unregister_drivers(drivers, ARRAY_SIZE(drivers)); 375 380 } 376 381 module_exit(mpc52xx_gpio_exit); 377 382
+10 -16
drivers/gpio/gpio-mpc8xxx.c
··· 49 49 return 1u << (MPC8XXX_GPIO_PINS - 1 - gpio); 50 50 } 51 51 52 - static inline struct mpc8xxx_gpio_chip * 53 - to_mpc8xxx_gpio_chip(struct of_mm_gpio_chip *mm) 54 - { 55 - return container_of(mm, struct mpc8xxx_gpio_chip, mm_gc); 56 - } 57 - 58 52 static void mpc8xxx_gpio_save_regs(struct of_mm_gpio_chip *mm) 59 53 { 60 - struct mpc8xxx_gpio_chip *mpc8xxx_gc = to_mpc8xxx_gpio_chip(mm); 54 + struct mpc8xxx_gpio_chip *mpc8xxx_gc = 55 + container_of(mm, struct mpc8xxx_gpio_chip, mm_gc); 61 56 62 57 mpc8xxx_gc->data = in_be32(mm->regs + GPIO_DAT); 63 58 } ··· 66 71 { 67 72 u32 val; 68 73 struct of_mm_gpio_chip *mm = to_of_mm_gpio_chip(gc); 69 - struct mpc8xxx_gpio_chip *mpc8xxx_gc = to_mpc8xxx_gpio_chip(mm); 74 + struct mpc8xxx_gpio_chip *mpc8xxx_gc = gpiochip_get_data(gc); 70 75 u32 out_mask, out_shadow; 71 76 72 77 out_mask = in_be32(mm->regs + GPIO_DIR); ··· 74 79 val = in_be32(mm->regs + GPIO_DAT) & ~out_mask; 75 80 out_shadow = mpc8xxx_gc->data & out_mask; 76 81 77 - return (val | out_shadow) & mpc8xxx_gpio2mask(gpio); 82 + return !!((val | out_shadow) & mpc8xxx_gpio2mask(gpio)); 78 83 } 79 84 80 85 static int mpc8xxx_gpio_get(struct gpio_chip *gc, unsigned int gpio) ··· 87 92 static void mpc8xxx_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val) 88 93 { 89 94 struct of_mm_gpio_chip *mm = to_of_mm_gpio_chip(gc); 90 - struct mpc8xxx_gpio_chip *mpc8xxx_gc = to_mpc8xxx_gpio_chip(mm); 95 + struct mpc8xxx_gpio_chip *mpc8xxx_gc = gpiochip_get_data(gc); 91 96 unsigned long flags; 92 97 93 98 raw_spin_lock_irqsave(&mpc8xxx_gc->lock, flags); ··· 106 111 unsigned long *mask, unsigned long *bits) 107 112 { 108 113 struct of_mm_gpio_chip *mm = to_of_mm_gpio_chip(gc); 109 - struct mpc8xxx_gpio_chip *mpc8xxx_gc = to_mpc8xxx_gpio_chip(mm); 114 + struct mpc8xxx_gpio_chip *mpc8xxx_gc = gpiochip_get_data(gc); 110 115 unsigned long flags; 111 116 int i; 112 117 ··· 131 136 static int mpc8xxx_gpio_dir_in(struct gpio_chip *gc, unsigned int gpio) 132 137 { 133 138 struct of_mm_gpio_chip *mm = to_of_mm_gpio_chip(gc); 134 - struct mpc8xxx_gpio_chip *mpc8xxx_gc = to_mpc8xxx_gpio_chip(mm); 139 + struct mpc8xxx_gpio_chip *mpc8xxx_gc = gpiochip_get_data(gc); 135 140 unsigned long flags; 136 141 137 142 raw_spin_lock_irqsave(&mpc8xxx_gc->lock, flags); ··· 146 151 static int mpc8xxx_gpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val) 147 152 { 148 153 struct of_mm_gpio_chip *mm = to_of_mm_gpio_chip(gc); 149 - struct mpc8xxx_gpio_chip *mpc8xxx_gc = to_mpc8xxx_gpio_chip(mm); 154 + struct mpc8xxx_gpio_chip *mpc8xxx_gc = gpiochip_get_data(gc); 150 155 unsigned long flags; 151 156 152 157 mpc8xxx_gpio_set(gc, gpio, val); ··· 180 185 181 186 static int mpc8xxx_gpio_to_irq(struct gpio_chip *gc, unsigned offset) 182 187 { 183 - struct of_mm_gpio_chip *mm = to_of_mm_gpio_chip(gc); 184 - struct mpc8xxx_gpio_chip *mpc8xxx_gc = to_mpc8xxx_gpio_chip(mm); 188 + struct mpc8xxx_gpio_chip *mpc8xxx_gc = gpiochip_get_data(gc); 185 189 186 190 if (mpc8xxx_gc->irq && offset < MPC8XXX_GPIO_PINS) 187 191 return irq_create_mapping(mpc8xxx_gc->irq, offset); ··· 411 417 gc->set_multiple = mpc8xxx_gpio_set_multiple; 412 418 gc->to_irq = mpc8xxx_gpio_to_irq; 413 419 414 - ret = of_mm_gpiochip_add(np, mm_gc); 420 + ret = of_mm_gpiochip_add_data(np, mm_gc, mpc8xxx_gc); 415 421 if (ret) 416 422 return ret; 417 423
+4 -4
drivers/gpio/gpio-msic.c
··· 143 143 if (ret < 0) 144 144 return ret; 145 145 146 - return r & MSIC_GPIO_DIN_MASK; 146 + return !!(r & MSIC_GPIO_DIN_MASK); 147 147 } 148 148 149 149 static void msic_gpio_set(struct gpio_chip *chip, unsigned offset, int value) ··· 179 179 180 180 static int msic_gpio_to_irq(struct gpio_chip *chip, unsigned offset) 181 181 { 182 - struct msic_gpio *mg = container_of(chip, struct msic_gpio, chip); 182 + struct msic_gpio *mg = gpiochip_get_data(chip); 183 183 return mg->irq_base + offset; 184 184 } 185 185 ··· 293 293 mg->chip.base = pdata->gpio_base; 294 294 mg->chip.ngpio = MSIC_NUM_GPIO; 295 295 mg->chip.can_sleep = true; 296 - mg->chip.dev = dev; 296 + mg->chip.parent = dev; 297 297 298 298 mutex_init(&mg->buslock); 299 299 300 - retval = gpiochip_add(&mg->chip); 300 + retval = gpiochip_add_data(&mg->chip, mg); 301 301 if (retval) { 302 302 dev_err(dev, "Adding MSIC gpio chip failed\n"); 303 303 goto err;
+9 -16
drivers/gpio/gpio-mvebu.c
··· 187 187 188 188 static void mvebu_gpio_set(struct gpio_chip *chip, unsigned pin, int value) 189 189 { 190 - struct mvebu_gpio_chip *mvchip = 191 - container_of(chip, struct mvebu_gpio_chip, chip); 190 + struct mvebu_gpio_chip *mvchip = gpiochip_get_data(chip); 192 191 unsigned long flags; 193 192 u32 u; 194 193 ··· 203 204 204 205 static int mvebu_gpio_get(struct gpio_chip *chip, unsigned pin) 205 206 { 206 - struct mvebu_gpio_chip *mvchip = 207 - container_of(chip, struct mvebu_gpio_chip, chip); 207 + struct mvebu_gpio_chip *mvchip = gpiochip_get_data(chip); 208 208 u32 u; 209 209 210 210 if (readl_relaxed(mvebu_gpioreg_io_conf(mvchip)) & (1 << pin)) { ··· 218 220 219 221 static void mvebu_gpio_blink(struct gpio_chip *chip, unsigned pin, int value) 220 222 { 221 - struct mvebu_gpio_chip *mvchip = 222 - container_of(chip, struct mvebu_gpio_chip, chip); 223 + struct mvebu_gpio_chip *mvchip = gpiochip_get_data(chip); 223 224 unsigned long flags; 224 225 u32 u; 225 226 ··· 234 237 235 238 static int mvebu_gpio_direction_input(struct gpio_chip *chip, unsigned pin) 236 239 { 237 - struct mvebu_gpio_chip *mvchip = 238 - container_of(chip, struct mvebu_gpio_chip, chip); 240 + struct mvebu_gpio_chip *mvchip = gpiochip_get_data(chip); 239 241 unsigned long flags; 240 242 int ret; 241 243 u32 u; ··· 257 261 static int mvebu_gpio_direction_output(struct gpio_chip *chip, unsigned pin, 258 262 int value) 259 263 { 260 - struct mvebu_gpio_chip *mvchip = 261 - container_of(chip, struct mvebu_gpio_chip, chip); 264 + struct mvebu_gpio_chip *mvchip = gpiochip_get_data(chip); 262 265 unsigned long flags; 263 266 int ret; 264 267 u32 u; ··· 282 287 283 288 static int mvebu_gpio_to_irq(struct gpio_chip *chip, unsigned pin) 284 289 { 285 - struct mvebu_gpio_chip *mvchip = 286 - container_of(chip, struct mvebu_gpio_chip, chip); 290 + struct mvebu_gpio_chip *mvchip = gpiochip_get_data(chip); 287 291 return irq_create_mapping(mvchip->domain, pin); 288 292 } 289 293 ··· 488 494 489 495 static void mvebu_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip) 490 496 { 491 - struct mvebu_gpio_chip *mvchip = 492 - container_of(chip, struct mvebu_gpio_chip, chip); 497 + struct mvebu_gpio_chip *mvchip = gpiochip_get_data(chip); 493 498 u32 out, io_conf, blink, in_pol, data_in, cause, edg_msk, lvl_msk; 494 499 int i; 495 500 ··· 691 698 692 699 mvchip->soc_variant = soc_variant; 693 700 mvchip->chip.label = dev_name(&pdev->dev); 694 - mvchip->chip.dev = &pdev->dev; 701 + mvchip->chip.parent = &pdev->dev; 695 702 mvchip->chip.request = gpiochip_generic_request; 696 703 mvchip->chip.free = gpiochip_generic_free; 697 704 mvchip->chip.direction_input = mvebu_gpio_direction_input; ··· 756 763 BUG(); 757 764 } 758 765 759 - gpiochip_add(&mvchip->chip); 766 + gpiochip_add_data(&mvchip->chip, mvchip); 760 767 761 768 /* Some gpio controllers do not provide irq support */ 762 769 if (!of_irq_count(np))
+12 -15
drivers/gpio/gpio-mxc.c
··· 26 26 #include <linux/irq.h> 27 27 #include <linux/irqdomain.h> 28 28 #include <linux/irqchip/chained_irq.h> 29 - #include <linux/gpio.h> 30 29 #include <linux/platform_device.h> 31 30 #include <linux/slab.h> 32 - #include <linux/basic_mmio_gpio.h> 31 + #include <linux/gpio/driver.h> 32 + /* FIXME: for gpio_get_value() replace this with direct register read */ 33 + #include <linux/gpio.h> 33 34 #include <linux/of.h> 34 35 #include <linux/of_device.h> 35 36 #include <linux/module.h> ··· 65 64 int irq; 66 65 int irq_high; 67 66 struct irq_domain *domain; 68 - struct bgpio_chip bgc; 67 + struct gpio_chip gc; 69 68 u32 both_edges; 70 69 }; 71 70 ··· 173 172 struct mxc_gpio_port *port = gc->private; 174 173 u32 bit, val; 175 174 u32 gpio_idx = d->hwirq; 176 - u32 gpio = port->bgc.gc.base + gpio_idx; 175 + u32 gpio = port->gc.base + gpio_idx; 177 176 int edge; 178 177 void __iomem *reg = port->base; 179 178 ··· 399 398 400 399 static int mxc_gpio_to_irq(struct gpio_chip *gc, unsigned offset) 401 400 { 402 - struct bgpio_chip *bgc = to_bgpio_chip(gc); 403 - struct mxc_gpio_port *port = 404 - container_of(bgc, struct mxc_gpio_port, bgc); 401 + struct mxc_gpio_port *port = gpiochip_get_data(gc); 405 402 406 403 return irq_find_mapping(port->domain, offset); 407 404 } ··· 450 451 port); 451 452 } 452 453 453 - err = bgpio_init(&port->bgc, &pdev->dev, 4, 454 + err = bgpio_init(&port->gc, &pdev->dev, 4, 454 455 port->base + GPIO_PSR, 455 456 port->base + GPIO_DR, NULL, 456 457 port->base + GPIO_GDIR, NULL, ··· 458 459 if (err) 459 460 goto out_bgio; 460 461 461 - port->bgc.gc.to_irq = mxc_gpio_to_irq; 462 - port->bgc.gc.base = (pdev->id < 0) ? of_alias_get_id(np, "gpio") * 32 : 462 + port->gc.to_irq = mxc_gpio_to_irq; 463 + port->gc.base = (pdev->id < 0) ? of_alias_get_id(np, "gpio") * 32 : 463 464 pdev->id * 32; 464 465 465 - err = gpiochip_add(&port->bgc.gc); 466 + err = gpiochip_add_data(&port->gc, port); 466 467 if (err) 467 - goto out_bgpio_remove; 468 + goto out_bgio; 468 469 469 470 irq_base = irq_alloc_descs(-1, 0, 32, numa_node_id()); 470 471 if (irq_base < 0) { ··· 493 494 out_irqdesc_free: 494 495 irq_free_descs(irq_base, 32); 495 496 out_gpiochip_remove: 496 - gpiochip_remove(&port->bgc.gc); 497 - out_bgpio_remove: 498 - bgpio_remove(&port->bgc); 497 + gpiochip_remove(&port->gc); 499 498 out_bgio: 500 499 dev_info(&pdev->dev, "%s failed with errno %d\n", __func__, err); 501 500 return err;
+14 -19
drivers/gpio/gpio-mxs.c
··· 26 26 #include <linux/io.h> 27 27 #include <linux/irq.h> 28 28 #include <linux/irqdomain.h> 29 - #include <linux/gpio.h> 30 29 #include <linux/of.h> 31 30 #include <linux/of_address.h> 32 31 #include <linux/of_device.h> 33 32 #include <linux/platform_device.h> 34 33 #include <linux/slab.h> 35 - #include <linux/basic_mmio_gpio.h> 34 + #include <linux/gpio/driver.h> 35 + /* FIXME: for gpio_get_value(), replace this by direct register read */ 36 + #include <linux/gpio.h> 36 37 #include <linux/module.h> 37 38 38 39 #define MXS_SET 0x4 ··· 65 64 int id; 66 65 int irq; 67 66 struct irq_domain *domain; 68 - struct bgpio_chip bgc; 67 + struct gpio_chip gc; 69 68 enum mxs_gpio_id devid; 70 69 u32 both_edges; 71 70 }; ··· 94 93 port->both_edges &= ~pin_mask; 95 94 switch (type) { 96 95 case IRQ_TYPE_EDGE_BOTH: 97 - val = gpio_get_value(port->bgc.gc.base + d->hwirq); 96 + val = gpio_get_value(port->gc.base + d->hwirq); 98 97 if (val) 99 98 edge = GPIO_INT_FALL_EDGE; 100 99 else ··· 226 225 227 226 static int mxs_gpio_to_irq(struct gpio_chip *gc, unsigned offset) 228 227 { 229 - struct bgpio_chip *bgc = to_bgpio_chip(gc); 230 - struct mxs_gpio_port *port = 231 - container_of(bgc, struct mxs_gpio_port, bgc); 228 + struct mxs_gpio_port *port = gpiochip_get_data(gc); 232 229 233 230 return irq_find_mapping(port->domain, offset); 234 231 } 235 232 236 233 static int mxs_gpio_get_direction(struct gpio_chip *gc, unsigned offset) 237 234 { 238 - struct bgpio_chip *bgc = to_bgpio_chip(gc); 239 - struct mxs_gpio_port *port = 240 - container_of(bgc, struct mxs_gpio_port, bgc); 235 + struct mxs_gpio_port *port = gpiochip_get_data(gc); 241 236 u32 mask = 1 << offset; 242 237 u32 dir; 243 238 ··· 327 330 irq_set_chained_handler_and_data(port->irq, mxs_gpio_irq_handler, 328 331 port); 329 332 330 - err = bgpio_init(&port->bgc, &pdev->dev, 4, 333 + err = bgpio_init(&port->gc, &pdev->dev, 4, 331 334 port->base + PINCTRL_DIN(port), 332 335 port->base + PINCTRL_DOUT(port) + MXS_SET, 333 336 port->base + PINCTRL_DOUT(port) + MXS_CLR, 334 337 port->base + PINCTRL_DOE(port), NULL, 0); 335 338 if (err) 336 - goto out_irqdesc_free; 339 + goto out_irqdomain_remove; 337 340 338 - port->bgc.gc.to_irq = mxs_gpio_to_irq; 339 - port->bgc.gc.get_direction = mxs_gpio_get_direction; 340 - port->bgc.gc.base = port->id * 32; 341 + port->gc.to_irq = mxs_gpio_to_irq; 342 + port->gc.get_direction = mxs_gpio_get_direction; 343 + port->gc.base = port->id * 32; 341 344 342 - err = gpiochip_add(&port->bgc.gc); 345 + err = gpiochip_add_data(&port->gc, port); 343 346 if (err) 344 - goto out_bgpio_remove; 347 + goto out_irqdomain_remove; 345 348 346 349 return 0; 347 350 348 - out_bgpio_remove: 349 - bgpio_remove(&port->bgc); 350 351 out_irqdomain_remove: 351 352 irq_domain_remove(port->domain); 352 353 out_irqdesc_free:
+7 -7
drivers/gpio/gpio-octeon.c
··· 41 41 42 42 static int octeon_gpio_dir_in(struct gpio_chip *chip, unsigned offset) 43 43 { 44 - struct octeon_gpio *gpio = container_of(chip, struct octeon_gpio, chip); 44 + struct octeon_gpio *gpio = gpiochip_get_data(chip); 45 45 46 46 cvmx_write_csr(gpio->register_base + bit_cfg_reg(offset), 0); 47 47 return 0; ··· 49 49 50 50 static void octeon_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 51 51 { 52 - struct octeon_gpio *gpio = container_of(chip, struct octeon_gpio, chip); 52 + struct octeon_gpio *gpio = gpiochip_get_data(chip); 53 53 u64 mask = 1ull << offset; 54 54 u64 reg = gpio->register_base + (value ? TX_SET : TX_CLEAR); 55 55 cvmx_write_csr(reg, mask); ··· 58 58 static int octeon_gpio_dir_out(struct gpio_chip *chip, unsigned offset, 59 59 int value) 60 60 { 61 - struct octeon_gpio *gpio = container_of(chip, struct octeon_gpio, chip); 61 + struct octeon_gpio *gpio = gpiochip_get_data(chip); 62 62 union cvmx_gpio_bit_cfgx cfgx; 63 63 64 64 octeon_gpio_set(chip, offset, value); ··· 72 72 73 73 static int octeon_gpio_get(struct gpio_chip *chip, unsigned offset) 74 74 { 75 - struct octeon_gpio *gpio = container_of(chip, struct octeon_gpio, chip); 75 + struct octeon_gpio *gpio = gpiochip_get_data(chip); 76 76 u64 read_bits = cvmx_read_csr(gpio->register_base + RX_DAT); 77 77 78 78 return ((1ull << offset) & read_bits) != 0; ··· 108 108 109 109 pdev->dev.platform_data = chip; 110 110 chip->label = "octeon-gpio"; 111 - chip->dev = &pdev->dev; 111 + chip->parent = &pdev->dev; 112 112 chip->owner = THIS_MODULE; 113 113 chip->base = 0; 114 114 chip->can_sleep = false; ··· 117 117 chip->get = octeon_gpio_get; 118 118 chip->direction_output = octeon_gpio_dir_out; 119 119 chip->set = octeon_gpio_set; 120 - err = gpiochip_add(chip); 120 + err = gpiochip_add_data(chip, gpio); 121 121 if (err) 122 122 goto out; 123 123 ··· 128 128 129 129 static int octeon_gpio_remove(struct platform_device *pdev) 130 130 { 131 - struct gpio_chip *chip = pdev->dev.platform_data; 131 + struct gpio_chip *chip = dev_get_platdata(&pdev->dev); 132 132 gpiochip_remove(chip); 133 133 return 0; 134 134 }
+12 -12
drivers/gpio/gpio-omap.c
··· 93 93 static inline struct gpio_bank *omap_irq_data_get_bank(struct irq_data *d) 94 94 { 95 95 struct gpio_chip *chip = irq_data_get_irq_chip_data(d); 96 - return container_of(chip, struct gpio_bank, chip); 96 + return gpiochip_get_data(chip); 97 97 } 98 98 99 99 static void omap_set_gpio_direction(struct gpio_bank *bank, int gpio, ··· 661 661 662 662 static int omap_gpio_request(struct gpio_chip *chip, unsigned offset) 663 663 { 664 - struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip); 664 + struct gpio_bank *bank = gpiochip_get_data(chip); 665 665 unsigned long flags; 666 666 667 667 /* ··· 681 681 682 682 static void omap_gpio_free(struct gpio_chip *chip, unsigned offset) 683 683 { 684 - struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip); 684 + struct gpio_bank *bank = gpiochip_get_data(chip); 685 685 unsigned long flags; 686 686 687 687 raw_spin_lock_irqsave(&bank->lock, flags); ··· 954 954 void __iomem *reg; 955 955 int dir; 956 956 957 - bank = container_of(chip, struct gpio_bank, chip); 957 + bank = gpiochip_get_data(chip); 958 958 reg = bank->base + bank->regs->direction; 959 959 raw_spin_lock_irqsave(&bank->lock, flags); 960 960 dir = !!(readl_relaxed(reg) & BIT(offset)); ··· 967 967 struct gpio_bank *bank; 968 968 unsigned long flags; 969 969 970 - bank = container_of(chip, struct gpio_bank, chip); 970 + bank = gpiochip_get_data(chip); 971 971 raw_spin_lock_irqsave(&bank->lock, flags); 972 972 omap_set_gpio_direction(bank, offset, 1); 973 973 raw_spin_unlock_irqrestore(&bank->lock, flags); ··· 978 978 { 979 979 struct gpio_bank *bank; 980 980 981 - bank = container_of(chip, struct gpio_bank, chip); 981 + bank = gpiochip_get_data(chip); 982 982 983 983 if (omap_gpio_is_input(bank, offset)) 984 984 return omap_get_gpio_datain(bank, offset); ··· 991 991 struct gpio_bank *bank; 992 992 unsigned long flags; 993 993 994 - bank = container_of(chip, struct gpio_bank, chip); 994 + bank = gpiochip_get_data(chip); 995 995 raw_spin_lock_irqsave(&bank->lock, flags); 996 996 bank->set_dataout(bank, offset, value); 997 997 omap_set_gpio_direction(bank, offset, 0); ··· 1005 1005 struct gpio_bank *bank; 1006 1006 unsigned long flags; 1007 1007 1008 - bank = container_of(chip, struct gpio_bank, chip); 1008 + bank = gpiochip_get_data(chip); 1009 1009 1010 1010 raw_spin_lock_irqsave(&bank->lock, flags); 1011 1011 omap2_set_gpio_debounce(bank, offset, debounce); ··· 1019 1019 struct gpio_bank *bank; 1020 1020 unsigned long flags; 1021 1021 1022 - bank = container_of(chip, struct gpio_bank, chip); 1022 + bank = gpiochip_get_data(chip); 1023 1023 raw_spin_lock_irqsave(&bank->lock, flags); 1024 1024 bank->set_dataout(bank, offset, value); 1025 1025 raw_spin_unlock_irqrestore(&bank->lock, flags); ··· 1090 1090 if (bank->is_mpuio) { 1091 1091 bank->chip.label = "mpuio"; 1092 1092 if (bank->regs->wkup_en) 1093 - bank->chip.dev = &omap_mpuio_device.dev; 1093 + bank->chip.parent = &omap_mpuio_device.dev; 1094 1094 bank->chip.base = OMAP_MPUIO(0); 1095 1095 } else { 1096 1096 bank->chip.label = "gpio"; ··· 1098 1098 } 1099 1099 bank->chip.ngpio = bank->width; 1100 1100 1101 - ret = gpiochip_add(&bank->chip); 1101 + ret = gpiochip_add_data(&bank->chip, bank); 1102 1102 if (ret) { 1103 1103 dev_err(bank->dev, "Could not register gpio chip %d\n", ret); 1104 1104 return ret; ··· 1197 1197 } 1198 1198 1199 1199 bank->dev = dev; 1200 - bank->chip.dev = dev; 1200 + bank->chip.parent = dev; 1201 1201 bank->chip.owner = THIS_MODULE; 1202 1202 bank->dbck_flag = pdata->dbck_flag; 1203 1203 bank->stride = pdata->bank_stride;
+14 -17
drivers/gpio/gpio-palmas.c
··· 35 35 int ngpio; 36 36 }; 37 37 38 - static inline struct palmas_gpio *to_palmas_gpio(struct gpio_chip *chip) 39 - { 40 - return container_of(chip, struct palmas_gpio, gpio_chip); 41 - } 42 - 43 38 static int palmas_gpio_get(struct gpio_chip *gc, unsigned offset) 44 39 { 45 - struct palmas_gpio *pg = to_palmas_gpio(gc); 40 + struct palmas_gpio *pg = gpiochip_get_data(gc); 46 41 struct palmas *palmas = pg->palmas; 47 42 unsigned int val; 48 43 int ret; ··· 49 54 50 55 ret = palmas_read(palmas, PALMAS_GPIO_BASE, reg, &val); 51 56 if (ret < 0) { 52 - dev_err(gc->dev, "Reg 0x%02x read failed, %d\n", reg, ret); 57 + dev_err(gc->parent, "Reg 0x%02x read failed, %d\n", reg, ret); 53 58 return ret; 54 59 } 55 60 ··· 60 65 61 66 ret = palmas_read(palmas, PALMAS_GPIO_BASE, reg, &val); 62 67 if (ret < 0) { 63 - dev_err(gc->dev, "Reg 0x%02x read failed, %d\n", reg, ret); 68 + dev_err(gc->parent, "Reg 0x%02x read failed, %d\n", reg, ret); 64 69 return ret; 65 70 } 66 71 return !!(val & BIT(offset)); ··· 69 74 static void palmas_gpio_set(struct gpio_chip *gc, unsigned offset, 70 75 int value) 71 76 { 72 - struct palmas_gpio *pg = to_palmas_gpio(gc); 77 + struct palmas_gpio *pg = gpiochip_get_data(gc); 73 78 struct palmas *palmas = pg->palmas; 74 79 int ret; 75 80 unsigned int reg; ··· 85 90 86 91 ret = palmas_write(palmas, PALMAS_GPIO_BASE, reg, BIT(offset)); 87 92 if (ret < 0) 88 - dev_err(gc->dev, "Reg 0x%02x write failed, %d\n", reg, ret); 93 + dev_err(gc->parent, "Reg 0x%02x write failed, %d\n", reg, ret); 89 94 } 90 95 91 96 static int palmas_gpio_output(struct gpio_chip *gc, unsigned offset, 92 97 int value) 93 98 { 94 - struct palmas_gpio *pg = to_palmas_gpio(gc); 99 + struct palmas_gpio *pg = gpiochip_get_data(gc); 95 100 struct palmas *palmas = pg->palmas; 96 101 int ret; 97 102 unsigned int reg; ··· 106 111 ret = palmas_update_bits(palmas, PALMAS_GPIO_BASE, reg, 107 112 BIT(offset), BIT(offset)); 108 113 if (ret < 0) 109 - dev_err(gc->dev, "Reg 0x%02x update failed, %d\n", reg, ret); 114 + dev_err(gc->parent, "Reg 0x%02x update failed, %d\n", reg, 115 + ret); 110 116 return ret; 111 117 } 112 118 113 119 static int palmas_gpio_input(struct gpio_chip *gc, unsigned offset) 114 120 { 115 - struct palmas_gpio *pg = to_palmas_gpio(gc); 121 + struct palmas_gpio *pg = gpiochip_get_data(gc); 116 122 struct palmas *palmas = pg->palmas; 117 123 int ret; 118 124 unsigned int reg; ··· 124 128 125 129 ret = palmas_update_bits(palmas, PALMAS_GPIO_BASE, reg, BIT(offset), 0); 126 130 if (ret < 0) 127 - dev_err(gc->dev, "Reg 0x%02x update failed, %d\n", reg, ret); 131 + dev_err(gc->parent, "Reg 0x%02x update failed, %d\n", reg, 132 + ret); 128 133 return ret; 129 134 } 130 135 131 136 static int palmas_gpio_to_irq(struct gpio_chip *gc, unsigned offset) 132 137 { 133 - struct palmas_gpio *pg = to_palmas_gpio(gc); 138 + struct palmas_gpio *pg = gpiochip_get_data(gc); 134 139 struct palmas *palmas = pg->palmas; 135 140 136 141 return palmas_irq_get_virq(palmas, PALMAS_GPIO_0_IRQ + offset); ··· 185 188 palmas_gpio->gpio_chip.to_irq = palmas_gpio_to_irq; 186 189 palmas_gpio->gpio_chip.set = palmas_gpio_set; 187 190 palmas_gpio->gpio_chip.get = palmas_gpio_get; 188 - palmas_gpio->gpio_chip.dev = &pdev->dev; 191 + palmas_gpio->gpio_chip.parent = &pdev->dev; 189 192 #ifdef CONFIG_OF_GPIO 190 193 palmas_gpio->gpio_chip.of_node = pdev->dev.of_node; 191 194 #endif ··· 195 198 else 196 199 palmas_gpio->gpio_chip.base = -1; 197 200 198 - ret = gpiochip_add(&palmas_gpio->gpio_chip); 201 + ret = gpiochip_add_data(&palmas_gpio->gpio_chip, palmas_gpio); 199 202 if (ret < 0) { 200 203 dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret); 201 204 return ret;
+90 -45
drivers/gpio/gpio-pca953x.c
··· 18 18 #include <linux/i2c.h> 19 19 #include <linux/platform_data/pca953x.h> 20 20 #include <linux/slab.h> 21 - #ifdef CONFIG_OF_GPIO 22 21 #include <linux/of_platform.h> 23 - #endif 24 22 #include <linux/acpi.h> 25 23 26 24 #define PCA953X_INPUT 0 ··· 106 108 int chip_type; 107 109 unsigned long driver_data; 108 110 }; 109 - 110 - static inline struct pca953x_chip *to_pca(struct gpio_chip *gc) 111 - { 112 - return container_of(gc, struct pca953x_chip, gpio_chip); 113 - } 114 111 115 112 static int pca953x_read_single(struct pca953x_chip *chip, int reg, u32 *val, 116 113 int off) ··· 209 216 210 217 static int pca953x_gpio_direction_input(struct gpio_chip *gc, unsigned off) 211 218 { 212 - struct pca953x_chip *chip = to_pca(gc); 219 + struct pca953x_chip *chip = gpiochip_get_data(gc); 213 220 u8 reg_val; 214 221 int ret, offset = 0; 215 222 ··· 238 245 static int pca953x_gpio_direction_output(struct gpio_chip *gc, 239 246 unsigned off, int val) 240 247 { 241 - struct pca953x_chip *chip = to_pca(gc); 248 + struct pca953x_chip *chip = gpiochip_get_data(gc); 242 249 u8 reg_val; 243 250 int ret, offset = 0; 244 251 ··· 288 295 289 296 static int pca953x_gpio_get_value(struct gpio_chip *gc, unsigned off) 290 297 { 291 - struct pca953x_chip *chip = to_pca(gc); 298 + struct pca953x_chip *chip = gpiochip_get_data(gc); 292 299 u32 reg_val; 293 300 int ret, offset = 0; 294 301 ··· 316 323 317 324 static void pca953x_gpio_set_value(struct gpio_chip *gc, unsigned off, int val) 318 325 { 319 - struct pca953x_chip *chip = to_pca(gc); 326 + struct pca953x_chip *chip = gpiochip_get_data(gc); 320 327 u8 reg_val; 321 328 int ret, offset = 0; 322 329 ··· 345 352 mutex_unlock(&chip->i2c_lock); 346 353 } 347 354 355 + 356 + static void pca953x_gpio_set_multiple(struct gpio_chip *gc, 357 + unsigned long *mask, unsigned long *bits) 358 + { 359 + struct pca953x_chip *chip = gpiochip_get_data(gc); 360 + u8 reg_val[MAX_BANK]; 361 + int ret, offset = 0; 362 + int bank_shift = fls((chip->gpio_chip.ngpio - 1) / BANK_SZ); 363 + int bank; 364 + 365 + switch (chip->chip_type) { 366 + case PCA953X_TYPE: 367 + offset = PCA953X_OUTPUT; 368 + break; 369 + case PCA957X_TYPE: 370 + offset = PCA957X_OUT; 371 + break; 372 + } 373 + 374 + memcpy(reg_val, chip->reg_output, NBANK(chip)); 375 + mutex_lock(&chip->i2c_lock); 376 + for(bank=0; bank<NBANK(chip); bank++) { 377 + unsigned bankmask = mask[bank/4] >> ((bank % 4) * 8); 378 + if(bankmask) { 379 + unsigned bankval = bits[bank/4] >> ((bank % 4) * 8); 380 + reg_val[bank] = (reg_val[bank] & ~bankmask) | bankval; 381 + } 382 + } 383 + ret = i2c_smbus_write_i2c_block_data(chip->client, offset << bank_shift, NBANK(chip), reg_val); 384 + if (ret) 385 + goto exit; 386 + 387 + memcpy(chip->reg_output, reg_val, NBANK(chip)); 388 + exit: 389 + mutex_unlock(&chip->i2c_lock); 390 + } 391 + 348 392 static void pca953x_setup_gpio(struct pca953x_chip *chip, int gpios) 349 393 { 350 394 struct gpio_chip *gc; ··· 392 362 gc->direction_output = pca953x_gpio_direction_output; 393 363 gc->get = pca953x_gpio_get_value; 394 364 gc->set = pca953x_gpio_set_value; 365 + gc->set_multiple = pca953x_gpio_set_multiple; 395 366 gc->can_sleep = true; 396 367 397 368 gc->base = chip->gpio_start; 398 369 gc->ngpio = gpios; 399 370 gc->label = chip->client->name; 400 - gc->dev = &chip->client->dev; 371 + gc->parent = &chip->client->dev; 401 372 gc->owner = THIS_MODULE; 402 373 gc->names = chip->names; 403 374 } ··· 407 376 static void pca953x_irq_mask(struct irq_data *d) 408 377 { 409 378 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 410 - struct pca953x_chip *chip = to_pca(gc); 379 + struct pca953x_chip *chip = gpiochip_get_data(gc); 411 380 412 381 chip->irq_mask[d->hwirq / BANK_SZ] &= ~(1 << (d->hwirq % BANK_SZ)); 413 382 } ··· 415 384 static void pca953x_irq_unmask(struct irq_data *d) 416 385 { 417 386 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 418 - struct pca953x_chip *chip = to_pca(gc); 387 + struct pca953x_chip *chip = gpiochip_get_data(gc); 419 388 420 389 chip->irq_mask[d->hwirq / BANK_SZ] |= 1 << (d->hwirq % BANK_SZ); 421 390 } ··· 423 392 static void pca953x_irq_bus_lock(struct irq_data *d) 424 393 { 425 394 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 426 - struct pca953x_chip *chip = to_pca(gc); 395 + struct pca953x_chip *chip = gpiochip_get_data(gc); 427 396 428 397 mutex_lock(&chip->irq_lock); 429 398 } ··· 431 400 static void pca953x_irq_bus_sync_unlock(struct irq_data *d) 432 401 { 433 402 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 434 - struct pca953x_chip *chip = to_pca(gc); 403 + struct pca953x_chip *chip = gpiochip_get_data(gc); 435 404 u8 new_irqs; 436 405 int level, i; 437 406 ··· 454 423 static int pca953x_irq_set_type(struct irq_data *d, unsigned int type) 455 424 { 456 425 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 457 - struct pca953x_chip *chip = to_pca(gc); 426 + struct pca953x_chip *chip = gpiochip_get_data(gc); 458 427 int bank_nb = d->hwirq / BANK_SZ; 459 428 u8 mask = 1 << (d->hwirq % BANK_SZ); 460 429 ··· 691 660 return ret; 692 661 } 693 662 663 + static const struct of_device_id pca953x_dt_ids[]; 664 + 694 665 static int pca953x_probe(struct i2c_client *client, 695 666 const struct i2c_device_id *id) 696 667 { ··· 724 691 chip->driver_data = id->driver_data; 725 692 } else { 726 693 const struct acpi_device_id *id; 694 + const struct of_device_id *match; 727 695 728 - id = acpi_match_device(pca953x_acpi_ids, &client->dev); 729 - if (!id) 730 - return -ENODEV; 696 + match = of_match_device(pca953x_dt_ids, &client->dev); 697 + if (match) { 698 + chip->driver_data = (int)(uintptr_t)match->data; 699 + } else { 700 + id = acpi_match_device(pca953x_acpi_ids, &client->dev); 701 + if (!id) 702 + return -ENODEV; 731 703 732 - chip->driver_data = id->driver_data; 704 + chip->driver_data = id->driver_data; 705 + } 733 706 } 734 707 735 708 chip->chip_type = PCA_CHIP_TYPE(chip->driver_data); ··· 754 715 if (ret) 755 716 return ret; 756 717 757 - ret = gpiochip_add(&chip->gpio_chip); 718 + ret = gpiochip_add_data(&chip->gpio_chip, chip); 758 719 if (ret) 759 720 return ret; 760 721 ··· 794 755 return 0; 795 756 } 796 757 758 + /* convenience to stop overlong match-table lines */ 759 + #define OF_953X(__nrgpio, __int) (void *)(__nrgpio | PCA953X_TYPE | __int) 760 + #define OF_957X(__nrgpio, __int) (void *)(__nrgpio | PCA957X_TYPE | __int) 761 + 797 762 static const struct of_device_id pca953x_dt_ids[] = { 798 - { .compatible = "nxp,pca9505", }, 799 - { .compatible = "nxp,pca9534", }, 800 - { .compatible = "nxp,pca9535", }, 801 - { .compatible = "nxp,pca9536", }, 802 - { .compatible = "nxp,pca9537", }, 803 - { .compatible = "nxp,pca9538", }, 804 - { .compatible = "nxp,pca9539", }, 805 - { .compatible = "nxp,pca9554", }, 806 - { .compatible = "nxp,pca9555", }, 807 - { .compatible = "nxp,pca9556", }, 808 - { .compatible = "nxp,pca9557", }, 809 - { .compatible = "nxp,pca9574", }, 810 - { .compatible = "nxp,pca9575", }, 811 - { .compatible = "nxp,pca9698", }, 763 + { .compatible = "nxp,pca9505", .data = OF_953X(40, PCA_INT), }, 764 + { .compatible = "nxp,pca9534", .data = OF_953X( 8, PCA_INT), }, 765 + { .compatible = "nxp,pca9535", .data = OF_953X(16, PCA_INT), }, 766 + { .compatible = "nxp,pca9536", .data = OF_953X( 4, 0), }, 767 + { .compatible = "nxp,pca9537", .data = OF_953X( 4, PCA_INT), }, 768 + { .compatible = "nxp,pca9538", .data = OF_953X( 8, PCA_INT), }, 769 + { .compatible = "nxp,pca9539", .data = OF_953X(16, PCA_INT), }, 770 + { .compatible = "nxp,pca9554", .data = OF_953X( 8, PCA_INT), }, 771 + { .compatible = "nxp,pca9555", .data = OF_953X(16, PCA_INT), }, 772 + { .compatible = "nxp,pca9556", .data = OF_953X( 8, 0), }, 773 + { .compatible = "nxp,pca9557", .data = OF_953X( 8, 0), }, 774 + { .compatible = "nxp,pca9574", .data = OF_957X( 8, PCA_INT), }, 775 + { .compatible = "nxp,pca9575", .data = OF_957X(16, PCA_INT), }, 776 + { .compatible = "nxp,pca9698", .data = OF_953X(40, 0), }, 812 777 813 - { .compatible = "maxim,max7310", }, 814 - { .compatible = "maxim,max7312", }, 815 - { .compatible = "maxim,max7313", }, 816 - { .compatible = "maxim,max7315", }, 778 + { .compatible = "maxim,max7310", .data = OF_953X( 8, 0), }, 779 + { .compatible = "maxim,max7312", .data = OF_953X(16, PCA_INT), }, 780 + { .compatible = "maxim,max7313", .data = OF_953X(16, PCA_INT), }, 781 + { .compatible = "maxim,max7315", .data = OF_953X( 8, PCA_INT), }, 817 782 818 - { .compatible = "ti,pca6107", }, 819 - { .compatible = "ti,tca6408", }, 820 - { .compatible = "ti,tca6416", }, 821 - { .compatible = "ti,tca6424", }, 783 + { .compatible = "ti,pca6107", .data = OF_953X( 8, PCA_INT), }, 784 + { .compatible = "ti,tca6408", .data = OF_953X( 8, PCA_INT), }, 785 + { .compatible = "ti,tca6416", .data = OF_953X(16, PCA_INT), }, 786 + { .compatible = "ti,tca6424", .data = OF_953X(24, PCA_INT), }, 822 787 823 - { .compatible = "exar,xra1202", }, 788 + { .compatible = "onsemi,pca9654", .data = OF_953X( 8, PCA_INT), }, 789 + 790 + { .compatible = "exar,xra1202", .data = OF_953X( 8, 0), }, 824 791 { } 825 792 }; 826 793
+6 -7
drivers/gpio/gpio-pcf857x.c
··· 137 137 138 138 static int pcf857x_input(struct gpio_chip *chip, unsigned offset) 139 139 { 140 - struct pcf857x *gpio = container_of(chip, struct pcf857x, chip); 140 + struct pcf857x *gpio = gpiochip_get_data(chip); 141 141 int status; 142 142 143 143 mutex_lock(&gpio->lock); ··· 150 150 151 151 static int pcf857x_get(struct gpio_chip *chip, unsigned offset) 152 152 { 153 - struct pcf857x *gpio = container_of(chip, struct pcf857x, chip); 153 + struct pcf857x *gpio = gpiochip_get_data(chip); 154 154 int value; 155 155 156 156 value = gpio->read(gpio->client); 157 - return (value < 0) ? 0 : (value & (1 << offset)); 157 + return (value < 0) ? value : !!(value & (1 << offset)); 158 158 } 159 159 160 160 static int pcf857x_output(struct gpio_chip *chip, unsigned offset, int value) 161 161 { 162 - struct pcf857x *gpio = container_of(chip, struct pcf857x, chip); 162 + struct pcf857x *gpio = gpiochip_get_data(chip); 163 163 unsigned bit = 1 << offset; 164 164 int status; 165 165 ··· 293 293 294 294 gpio->chip.base = pdata ? pdata->gpio_base : -1; 295 295 gpio->chip.can_sleep = true; 296 - gpio->chip.dev = &client->dev; 296 + gpio->chip.parent = &client->dev; 297 297 gpio->chip.owner = THIS_MODULE; 298 298 gpio->chip.get = pcf857x_get; 299 299 gpio->chip.set = pcf857x_set; ··· 372 372 gpio->out = ~n_latch; 373 373 gpio->status = gpio->out; 374 374 375 - status = gpiochip_add(&gpio->chip); 375 + status = gpiochip_add_data(&gpio->chip, gpio); 376 376 if (status < 0) 377 377 goto fail; 378 378 ··· 447 447 static struct i2c_driver pcf857x_driver = { 448 448 .driver = { 449 449 .name = "pcf857x", 450 - .owner = THIS_MODULE, 451 450 .of_match_table = of_match_ptr(pcf857x_of_table), 452 451 }, 453 452 .probe = pcf857x_probe,
+11 -8
drivers/gpio/gpio-pch.c
··· 109 109 static void pch_gpio_set(struct gpio_chip *gpio, unsigned nr, int val) 110 110 { 111 111 u32 reg_val; 112 - struct pch_gpio *chip = container_of(gpio, struct pch_gpio, gpio); 112 + struct pch_gpio *chip = gpiochip_get_data(gpio); 113 113 unsigned long flags; 114 114 115 115 spin_lock_irqsave(&chip->spinlock, flags); ··· 125 125 126 126 static int pch_gpio_get(struct gpio_chip *gpio, unsigned nr) 127 127 { 128 - struct pch_gpio *chip = container_of(gpio, struct pch_gpio, gpio); 128 + struct pch_gpio *chip = gpiochip_get_data(gpio); 129 129 130 - return ioread32(&chip->reg->pi) & (1 << nr); 130 + return (ioread32(&chip->reg->pi) >> nr) & 1; 131 131 } 132 132 133 133 static int pch_gpio_direction_output(struct gpio_chip *gpio, unsigned nr, 134 134 int val) 135 135 { 136 - struct pch_gpio *chip = container_of(gpio, struct pch_gpio, gpio); 136 + struct pch_gpio *chip = gpiochip_get_data(gpio); 137 137 u32 pm; 138 138 u32 reg_val; 139 139 unsigned long flags; ··· 158 158 159 159 static int pch_gpio_direction_input(struct gpio_chip *gpio, unsigned nr) 160 160 { 161 - struct pch_gpio *chip = container_of(gpio, struct pch_gpio, gpio); 161 + struct pch_gpio *chip = gpiochip_get_data(gpio); 162 162 u32 pm; 163 163 unsigned long flags; 164 164 ··· 211 211 212 212 static int pch_gpio_to_irq(struct gpio_chip *gpio, unsigned offset) 213 213 { 214 - struct pch_gpio *chip = container_of(gpio, struct pch_gpio, gpio); 214 + struct pch_gpio *chip = gpiochip_get_data(gpio); 215 215 return chip->irq_base + offset; 216 216 } 217 217 ··· 220 220 struct gpio_chip *gpio = &chip->gpio; 221 221 222 222 gpio->label = dev_name(chip->dev); 223 - gpio->dev = chip->dev; 223 + gpio->parent = chip->dev; 224 224 gpio->owner = THIS_MODULE; 225 225 gpio->direction_input = pch_gpio_direction_input; 226 226 gpio->get = pch_gpio_get; ··· 394 394 pci_set_drvdata(pdev, chip); 395 395 spin_lock_init(&chip->spinlock); 396 396 pch_gpio_setup(chip); 397 - ret = gpiochip_add(&chip->gpio); 397 + #ifdef CONFIG_OF_GPIO 398 + chip->gpio.of_node = pdev->dev.of_node; 399 + #endif 400 + ret = gpiochip_add_data(&chip->gpio, chip); 398 401 if (ret) { 399 402 dev_err(&pdev->dev, "PCH gpio: Failed to register GPIO\n"); 400 403 goto err_gpiochip_add;
+25 -16
drivers/gpio/gpio-pl061.c
··· 14 14 #include <linux/module.h> 15 15 #include <linux/io.h> 16 16 #include <linux/ioport.h> 17 + #include <linux/interrupt.h> 17 18 #include <linux/irq.h> 18 19 #include <linux/irqchip/chained_irq.h> 19 20 #include <linux/bitops.h> ··· 61 60 62 61 static int pl061_direction_input(struct gpio_chip *gc, unsigned offset) 63 62 { 64 - struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc); 63 + struct pl061_gpio *chip = gpiochip_get_data(gc); 65 64 unsigned long flags; 66 65 unsigned char gpiodir; 67 66 ··· 80 79 static int pl061_direction_output(struct gpio_chip *gc, unsigned offset, 81 80 int value) 82 81 { 83 - struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc); 82 + struct pl061_gpio *chip = gpiochip_get_data(gc); 84 83 unsigned long flags; 85 84 unsigned char gpiodir; 86 85 ··· 105 104 106 105 static int pl061_get_value(struct gpio_chip *gc, unsigned offset) 107 106 { 108 - struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc); 107 + struct pl061_gpio *chip = gpiochip_get_data(gc); 109 108 110 109 return !!readb(chip->base + (BIT(offset + 2))); 111 110 } 112 111 113 112 static void pl061_set_value(struct gpio_chip *gc, unsigned offset, int value) 114 113 { 115 - struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc); 114 + struct pl061_gpio *chip = gpiochip_get_data(gc); 116 115 117 116 writeb(!!value << offset, chip->base + (BIT(offset + 2))); 118 117 } ··· 120 119 static int pl061_irq_type(struct irq_data *d, unsigned trigger) 121 120 { 122 121 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 123 - struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc); 122 + struct pl061_gpio *chip = gpiochip_get_data(gc); 124 123 int offset = irqd_to_hwirq(d); 125 124 unsigned long flags; 126 125 u8 gpiois, gpioibe, gpioiev; ··· 132 131 if ((trigger & (IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) && 133 132 (trigger & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))) 134 133 { 135 - dev_err(gc->dev, 134 + dev_err(gc->parent, 136 135 "trying to configure line %d for both level and edge " 137 136 "detection, choose one!\n", 138 137 offset); ··· 159 158 else 160 159 gpioiev &= ~bit; 161 160 irq_set_handler_locked(d, handle_level_irq); 162 - dev_dbg(gc->dev, "line %d: IRQ on %s level\n", 161 + dev_dbg(gc->parent, "line %d: IRQ on %s level\n", 163 162 offset, 164 163 polarity ? "HIGH" : "LOW"); 165 164 } else if ((trigger & IRQ_TYPE_EDGE_BOTH) == IRQ_TYPE_EDGE_BOTH) { ··· 168 167 /* Select both edges, setting this makes GPIOEV be ignored */ 169 168 gpioibe |= bit; 170 169 irq_set_handler_locked(d, handle_edge_irq); 171 - dev_dbg(gc->dev, "line %d: IRQ on both edges\n", offset); 170 + dev_dbg(gc->parent, "line %d: IRQ on both edges\n", offset); 172 171 } else if ((trigger & IRQ_TYPE_EDGE_RISING) || 173 172 (trigger & IRQ_TYPE_EDGE_FALLING)) { 174 173 bool rising = trigger & IRQ_TYPE_EDGE_RISING; ··· 183 182 else 184 183 gpioiev &= ~bit; 185 184 irq_set_handler_locked(d, handle_edge_irq); 186 - dev_dbg(gc->dev, "line %d: IRQ on %s edge\n", 185 + dev_dbg(gc->parent, "line %d: IRQ on %s edge\n", 187 186 offset, 188 187 rising ? "RISING" : "FALLING"); 189 188 } else { ··· 192 191 gpioibe &= ~bit; 193 192 gpioiev &= ~bit; 194 193 irq_set_handler_locked(d, handle_bad_irq); 195 - dev_warn(gc->dev, "no trigger selected for line %d\n", 194 + dev_warn(gc->parent, "no trigger selected for line %d\n", 196 195 offset); 197 196 } 198 197 ··· 210 209 unsigned long pending; 211 210 int offset; 212 211 struct gpio_chip *gc = irq_desc_get_handler_data(desc); 213 - struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc); 212 + struct pl061_gpio *chip = gpiochip_get_data(gc); 214 213 struct irq_chip *irqchip = irq_desc_get_chip(desc); 215 214 216 215 chained_irq_enter(irqchip, desc); ··· 228 227 static void pl061_irq_mask(struct irq_data *d) 229 228 { 230 229 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 231 - struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc); 230 + struct pl061_gpio *chip = gpiochip_get_data(gc); 232 231 u8 mask = BIT(irqd_to_hwirq(d) % PL061_GPIO_NR); 233 232 u8 gpioie; 234 233 ··· 241 240 static void pl061_irq_unmask(struct irq_data *d) 242 241 { 243 242 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 244 - struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc); 243 + struct pl061_gpio *chip = gpiochip_get_data(gc); 245 244 u8 mask = BIT(irqd_to_hwirq(d) % PL061_GPIO_NR); 246 245 u8 gpioie; 247 246 ··· 262 261 static void pl061_irq_ack(struct irq_data *d) 263 262 { 264 263 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 265 - struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc); 264 + struct pl061_gpio *chip = gpiochip_get_data(gc); 266 265 u8 mask = BIT(irqd_to_hwirq(d) % PL061_GPIO_NR); 267 266 268 267 spin_lock(&chip->lock); 269 268 writeb(mask, chip->base + GPIOIC); 270 269 spin_unlock(&chip->lock); 270 + } 271 + 272 + static int pl061_irq_set_wake(struct irq_data *d, unsigned int state) 273 + { 274 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 275 + 276 + return irq_set_irq_wake(gc->irq_parent, state); 271 277 } 272 278 273 279 static struct irq_chip pl061_irqchip = { ··· 283 275 .irq_mask = pl061_irq_mask, 284 276 .irq_unmask = pl061_irq_unmask, 285 277 .irq_set_type = pl061_irq_type, 278 + .irq_set_wake = pl061_irq_set_wake, 286 279 }; 287 280 288 281 static int pl061_probe(struct amba_device *adev, const struct amba_id *id) ··· 325 316 chip->gc.set = pl061_set_value; 326 317 chip->gc.ngpio = PL061_GPIO_NR; 327 318 chip->gc.label = dev_name(dev); 328 - chip->gc.dev = dev; 319 + chip->gc.parent = dev; 329 320 chip->gc.owner = THIS_MODULE; 330 321 331 - ret = gpiochip_add(&chip->gc); 322 + ret = gpiochip_add_data(&chip->gc, chip); 332 323 if (ret) 333 324 return ret; 334 325
+246 -175
drivers/gpio/gpio-pxa.c
··· 24 24 #include <linux/io.h> 25 25 #include <linux/of.h> 26 26 #include <linux/of_device.h> 27 + #include <linux/pinctrl/consumer.h> 27 28 #include <linux/platform_device.h> 28 29 #include <linux/syscore_ops.h> 29 30 #include <linux/slab.h> ··· 65 64 int pxa_last_gpio; 66 65 static int irq_base; 67 66 68 - #ifdef CONFIG_OF 69 - static struct irq_domain *domain; 70 - static struct device_node *pxa_gpio_of_node; 71 - #endif 72 - 73 - struct pxa_gpio_chip { 74 - struct gpio_chip chip; 67 + struct pxa_gpio_bank { 75 68 void __iomem *regbase; 76 - char label[10]; 77 - 78 69 unsigned long irq_mask; 79 70 unsigned long irq_edge_rise; 80 71 unsigned long irq_edge_fall; 81 - int (*set_wake)(unsigned int gpio, unsigned int on); 82 72 83 73 #ifdef CONFIG_PM 84 74 unsigned long saved_gplr; ··· 77 85 unsigned long saved_grer; 78 86 unsigned long saved_gfer; 79 87 #endif 88 + }; 89 + 90 + struct pxa_gpio_chip { 91 + struct device *dev; 92 + struct gpio_chip chip; 93 + struct pxa_gpio_bank *banks; 94 + struct irq_domain *irqdomain; 95 + 96 + int irq0; 97 + int irq1; 98 + int (*set_wake)(unsigned int gpio, unsigned int on); 80 99 }; 81 100 82 101 enum pxa_gpio_type { ··· 107 104 }; 108 105 109 106 static DEFINE_SPINLOCK(gpio_lock); 110 - static struct pxa_gpio_chip *pxa_gpio_chips; 107 + static struct pxa_gpio_chip *pxa_gpio_chip; 111 108 static enum pxa_gpio_type gpio_type; 112 - static void __iomem *gpio_reg_base; 113 109 114 110 static struct pxa_gpio_id pxa25x_id = { 115 111 .type = PXA25X_GPIO, ··· 150 148 .gpio_nums = 224, 151 149 }; 152 150 153 - #define for_each_gpio_chip(i, c) \ 154 - for (i = 0, c = &pxa_gpio_chips[0]; i <= pxa_last_gpio; i += 32, c++) 151 + #define for_each_gpio_bank(i, b, pc) \ 152 + for (i = 0, b = pc->banks; i <= pxa_last_gpio; i += 32, b++) 155 153 156 - static inline void __iomem *gpio_chip_base(struct gpio_chip *c) 154 + static inline struct pxa_gpio_chip *chip_to_pxachip(struct gpio_chip *c) 157 155 { 158 - return container_of(c, struct pxa_gpio_chip, chip)->regbase; 156 + struct pxa_gpio_chip *pxa_chip = gpiochip_get_data(c); 157 + 158 + return pxa_chip; 159 159 } 160 160 161 - static inline struct pxa_gpio_chip *gpio_to_pxachip(unsigned gpio) 161 + static inline void __iomem *gpio_bank_base(struct gpio_chip *c, int gpio) 162 162 { 163 - return &pxa_gpio_chips[gpio_to_bank(gpio)]; 163 + struct pxa_gpio_chip *p = gpiochip_get_data(c); 164 + struct pxa_gpio_bank *bank = p->banks + (gpio / 32); 165 + 166 + return bank->regbase; 167 + } 168 + 169 + static inline struct pxa_gpio_bank *gpio_to_pxabank(struct gpio_chip *c, 170 + unsigned gpio) 171 + { 172 + return chip_to_pxachip(c)->banks + gpio / 32; 164 173 } 165 174 166 175 static inline int gpio_is_pxa_type(int type) ··· 200 187 * is attributed as "occupied" here (I know this terminology isn't 201 188 * accurate, you are welcome to propose a better one :-) 202 189 */ 203 - static inline int __gpio_is_occupied(unsigned gpio) 190 + static inline int __gpio_is_occupied(struct pxa_gpio_chip *pchip, unsigned gpio) 204 191 { 205 - struct pxa_gpio_chip *pxachip; 206 192 void __iomem *base; 207 193 unsigned long gafr = 0, gpdr = 0; 208 194 int ret, af = 0, dir = 0; 209 195 210 - pxachip = gpio_to_pxachip(gpio); 211 - base = gpio_chip_base(&pxachip->chip); 196 + base = gpio_bank_base(&pchip->chip, gpio); 212 197 gpdr = readl_relaxed(base + GPDR_OFFSET); 213 198 214 199 switch (gpio_type) { ··· 229 218 return ret; 230 219 } 231 220 232 - static int pxa_gpio_to_irq(struct gpio_chip *chip, unsigned offset) 233 - { 234 - return chip->base + offset + irq_base; 235 - } 236 - 237 221 int pxa_irq_to_gpio(int irq) 238 222 { 239 - return irq - irq_base; 223 + struct pxa_gpio_chip *pchip = pxa_gpio_chip; 224 + int irq_gpio0; 225 + 226 + irq_gpio0 = irq_find_mapping(pchip->irqdomain, 0); 227 + if (irq_gpio0 > 0) 228 + return irq - irq_gpio0; 229 + 230 + return irq_gpio0; 231 + } 232 + 233 + static int pxa_gpio_to_irq(struct gpio_chip *chip, unsigned offset) 234 + { 235 + struct pxa_gpio_chip *pchip = chip_to_pxachip(chip); 236 + 237 + return irq_find_mapping(pchip->irqdomain, offset); 240 238 } 241 239 242 240 static int pxa_gpio_direction_input(struct gpio_chip *chip, unsigned offset) 243 241 { 244 - void __iomem *base = gpio_chip_base(chip); 245 - uint32_t value, mask = 1 << offset; 242 + void __iomem *base = gpio_bank_base(chip, offset); 243 + uint32_t value, mask = GPIO_bit(offset); 246 244 unsigned long flags; 245 + int ret; 246 + 247 + ret = pinctrl_gpio_direction_input(chip->base + offset); 248 + if (!ret) 249 + return 0; 247 250 248 251 spin_lock_irqsave(&gpio_lock, flags); 249 252 ··· 275 250 static int pxa_gpio_direction_output(struct gpio_chip *chip, 276 251 unsigned offset, int value) 277 252 { 278 - void __iomem *base = gpio_chip_base(chip); 279 - uint32_t tmp, mask = 1 << offset; 253 + void __iomem *base = gpio_bank_base(chip, offset); 254 + uint32_t tmp, mask = GPIO_bit(offset); 280 255 unsigned long flags; 256 + int ret; 281 257 282 258 writel_relaxed(mask, base + (value ? GPSR_OFFSET : GPCR_OFFSET)); 259 + 260 + ret = pinctrl_gpio_direction_output(chip->base + offset); 261 + if (!ret) 262 + return 0; 283 263 284 264 spin_lock_irqsave(&gpio_lock, flags); 285 265 ··· 301 271 302 272 static int pxa_gpio_get(struct gpio_chip *chip, unsigned offset) 303 273 { 304 - u32 gplr = readl_relaxed(gpio_chip_base(chip) + GPLR_OFFSET); 305 - return !!(gplr & (1 << offset)); 274 + void __iomem *base = gpio_bank_base(chip, offset); 275 + u32 gplr = readl_relaxed(base + GPLR_OFFSET); 276 + 277 + return !!(gplr & GPIO_bit(offset)); 306 278 } 307 279 308 280 static void pxa_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 309 281 { 310 - writel_relaxed(1 << offset, gpio_chip_base(chip) + 311 - (value ? GPSR_OFFSET : GPCR_OFFSET)); 282 + void __iomem *base = gpio_bank_base(chip, offset); 283 + 284 + writel_relaxed(GPIO_bit(offset), 285 + base + (value ? GPSR_OFFSET : GPCR_OFFSET)); 312 286 } 313 287 314 288 #ifdef CONFIG_OF_GPIO ··· 323 289 if (gpiospec->args[0] > pxa_last_gpio) 324 290 return -EINVAL; 325 291 326 - if (gc != &pxa_gpio_chips[gpiospec->args[0] / 32].chip) 327 - return -EINVAL; 328 - 329 292 if (flags) 330 293 *flags = gpiospec->args[1]; 331 294 332 - return gpiospec->args[0] % 32; 295 + return gpiospec->args[0]; 333 296 } 334 297 #endif 335 298 336 - static int pxa_init_gpio_chip(int gpio_end, 337 - int (*set_wake)(unsigned int, unsigned int)) 299 + static int pxa_gpio_request(struct gpio_chip *chip, unsigned int offset) 338 300 { 339 - int i, gpio, nbanks = gpio_to_bank(gpio_end) + 1; 340 - struct pxa_gpio_chip *chips; 301 + return pinctrl_request_gpio(chip->base + offset); 302 + } 341 303 342 - chips = kzalloc(nbanks * sizeof(struct pxa_gpio_chip), GFP_KERNEL); 343 - if (chips == NULL) { 344 - pr_err("%s: failed to allocate GPIO chips\n", __func__); 304 + static void pxa_gpio_free(struct gpio_chip *chip, unsigned int offset) 305 + { 306 + pinctrl_free_gpio(chip->base + offset); 307 + } 308 + 309 + static int pxa_init_gpio_chip(struct pxa_gpio_chip *pchip, int ngpio, 310 + struct device_node *np, void __iomem *regbase) 311 + { 312 + int i, gpio, nbanks = DIV_ROUND_UP(ngpio, 32); 313 + struct pxa_gpio_bank *bank; 314 + 315 + pchip->banks = devm_kcalloc(pchip->dev, nbanks, sizeof(*pchip->banks), 316 + GFP_KERNEL); 317 + if (!pchip->banks) 345 318 return -ENOMEM; 346 - } 347 319 348 - for (i = 0, gpio = 0; i < nbanks; i++, gpio += 32) { 349 - struct gpio_chip *c = &chips[i].chip; 350 - 351 - sprintf(chips[i].label, "gpio-%d", i); 352 - chips[i].regbase = gpio_reg_base + BANK_OFF(i); 353 - chips[i].set_wake = set_wake; 354 - 355 - c->base = gpio; 356 - c->label = chips[i].label; 357 - 358 - c->direction_input = pxa_gpio_direction_input; 359 - c->direction_output = pxa_gpio_direction_output; 360 - c->get = pxa_gpio_get; 361 - c->set = pxa_gpio_set; 362 - c->to_irq = pxa_gpio_to_irq; 320 + pchip->chip.label = "gpio-pxa"; 321 + pchip->chip.direction_input = pxa_gpio_direction_input; 322 + pchip->chip.direction_output = pxa_gpio_direction_output; 323 + pchip->chip.get = pxa_gpio_get; 324 + pchip->chip.set = pxa_gpio_set; 325 + pchip->chip.to_irq = pxa_gpio_to_irq; 326 + pchip->chip.ngpio = ngpio; 327 + pchip->chip.request = pxa_gpio_request; 328 + pchip->chip.free = pxa_gpio_free; 363 329 #ifdef CONFIG_OF_GPIO 364 - c->of_node = pxa_gpio_of_node; 365 - c->of_xlate = pxa_gpio_of_xlate; 366 - c->of_gpio_n_cells = 2; 330 + pchip->chip.of_node = np; 331 + pchip->chip.of_xlate = pxa_gpio_of_xlate; 332 + pchip->chip.of_gpio_n_cells = 2; 367 333 #endif 368 334 369 - /* number of GPIOs on last bank may be less than 32 */ 370 - c->ngpio = (gpio + 31 > gpio_end) ? (gpio_end - gpio + 1) : 32; 371 - gpiochip_add(c); 335 + for (i = 0, gpio = 0; i < nbanks; i++, gpio += 32) { 336 + bank = pchip->banks + i; 337 + bank->regbase = regbase + BANK_OFF(i); 372 338 } 373 - pxa_gpio_chips = chips; 374 - return 0; 339 + 340 + return gpiochip_add_data(&pchip->chip, pchip); 375 341 } 376 342 377 343 /* Update only those GRERx and GFERx edge detection register bits if those 378 344 * bits are set in c->irq_mask 379 345 */ 380 - static inline void update_edge_detect(struct pxa_gpio_chip *c) 346 + static inline void update_edge_detect(struct pxa_gpio_bank *c) 381 347 { 382 348 uint32_t grer, gfer; 383 349 ··· 391 357 392 358 static int pxa_gpio_irq_type(struct irq_data *d, unsigned int type) 393 359 { 394 - struct pxa_gpio_chip *c; 395 - int gpio = pxa_irq_to_gpio(d->irq); 360 + struct pxa_gpio_chip *pchip = irq_data_get_irq_chip_data(d); 361 + unsigned int gpio = irqd_to_hwirq(d); 362 + struct pxa_gpio_bank *c = gpio_to_pxabank(&pchip->chip, gpio); 396 363 unsigned long gpdr, mask = GPIO_bit(gpio); 397 - 398 - c = gpio_to_pxachip(gpio); 399 364 400 365 if (type == IRQ_TYPE_PROBE) { 401 366 /* Don't mess with enabled GPIOs using preconfigured edges or ··· 403 370 if ((c->irq_edge_rise | c->irq_edge_fall) & GPIO_bit(gpio)) 404 371 return 0; 405 372 406 - if (__gpio_is_occupied(gpio)) 373 + if (__gpio_is_occupied(pchip, gpio)) 407 374 return 0; 408 375 409 376 type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING; ··· 434 401 return 0; 435 402 } 436 403 437 - static void pxa_gpio_demux_handler(struct irq_desc *desc) 404 + static irqreturn_t pxa_gpio_demux_handler(int in_irq, void *d) 438 405 { 439 - struct pxa_gpio_chip *c; 440 - int loop, gpio, gpio_base, n; 406 + int loop, gpio, n, handled = 0; 441 407 unsigned long gedr; 442 - struct irq_chip *chip = irq_desc_get_chip(desc); 443 - 444 - chained_irq_enter(chip, desc); 408 + struct pxa_gpio_chip *pchip = d; 409 + struct pxa_gpio_bank *c; 445 410 446 411 do { 447 412 loop = 0; 448 - for_each_gpio_chip(gpio, c) { 449 - gpio_base = c->chip.base; 450 - 413 + for_each_gpio_bank(gpio, c, pchip) { 451 414 gedr = readl_relaxed(c->regbase + GEDR_OFFSET); 452 415 gedr = gedr & c->irq_mask; 453 416 writel_relaxed(gedr, c->regbase + GEDR_OFFSET); ··· 451 422 for_each_set_bit(n, &gedr, BITS_PER_LONG) { 452 423 loop = 1; 453 424 454 - generic_handle_irq(gpio_to_irq(gpio_base + n)); 425 + generic_handle_irq(gpio_to_irq(gpio + n)); 455 426 } 456 427 } 428 + handled += loop; 457 429 } while (loop); 458 430 459 - chained_irq_exit(chip, desc); 431 + return handled ? IRQ_HANDLED : IRQ_NONE; 432 + } 433 + 434 + static irqreturn_t pxa_gpio_direct_handler(int in_irq, void *d) 435 + { 436 + struct pxa_gpio_chip *pchip = d; 437 + 438 + if (in_irq == pchip->irq0) { 439 + generic_handle_irq(gpio_to_irq(0)); 440 + } else if (in_irq == pchip->irq1) { 441 + generic_handle_irq(gpio_to_irq(1)); 442 + } else { 443 + pr_err("%s() unknown irq %d\n", __func__, in_irq); 444 + return IRQ_NONE; 445 + } 446 + return IRQ_HANDLED; 460 447 } 461 448 462 449 static void pxa_ack_muxed_gpio(struct irq_data *d) 463 450 { 464 - int gpio = pxa_irq_to_gpio(d->irq); 465 - struct pxa_gpio_chip *c = gpio_to_pxachip(gpio); 451 + struct pxa_gpio_chip *pchip = irq_data_get_irq_chip_data(d); 452 + unsigned int gpio = irqd_to_hwirq(d); 453 + void __iomem *base = gpio_bank_base(&pchip->chip, gpio); 466 454 467 - writel_relaxed(GPIO_bit(gpio), c->regbase + GEDR_OFFSET); 455 + writel_relaxed(GPIO_bit(gpio), base + GEDR_OFFSET); 468 456 } 469 457 470 458 static void pxa_mask_muxed_gpio(struct irq_data *d) 471 459 { 472 - int gpio = pxa_irq_to_gpio(d->irq); 473 - struct pxa_gpio_chip *c = gpio_to_pxachip(gpio); 460 + struct pxa_gpio_chip *pchip = irq_data_get_irq_chip_data(d); 461 + unsigned int gpio = irqd_to_hwirq(d); 462 + struct pxa_gpio_bank *b = gpio_to_pxabank(&pchip->chip, gpio); 463 + void __iomem *base = gpio_bank_base(&pchip->chip, gpio); 474 464 uint32_t grer, gfer; 475 465 476 - c->irq_mask &= ~GPIO_bit(gpio); 466 + b->irq_mask &= ~GPIO_bit(gpio); 477 467 478 - grer = readl_relaxed(c->regbase + GRER_OFFSET) & ~GPIO_bit(gpio); 479 - gfer = readl_relaxed(c->regbase + GFER_OFFSET) & ~GPIO_bit(gpio); 480 - writel_relaxed(grer, c->regbase + GRER_OFFSET); 481 - writel_relaxed(gfer, c->regbase + GFER_OFFSET); 468 + grer = readl_relaxed(base + GRER_OFFSET) & ~GPIO_bit(gpio); 469 + gfer = readl_relaxed(base + GFER_OFFSET) & ~GPIO_bit(gpio); 470 + writel_relaxed(grer, base + GRER_OFFSET); 471 + writel_relaxed(gfer, base + GFER_OFFSET); 482 472 } 483 473 484 474 static int pxa_gpio_set_wake(struct irq_data *d, unsigned int on) 485 475 { 486 - int gpio = pxa_irq_to_gpio(d->irq); 487 - struct pxa_gpio_chip *c = gpio_to_pxachip(gpio); 476 + struct pxa_gpio_chip *pchip = irq_data_get_irq_chip_data(d); 477 + unsigned int gpio = irqd_to_hwirq(d); 488 478 489 - if (c->set_wake) 490 - return c->set_wake(gpio, on); 479 + if (pchip->set_wake) 480 + return pchip->set_wake(gpio, on); 491 481 else 492 482 return 0; 493 483 } 494 484 495 485 static void pxa_unmask_muxed_gpio(struct irq_data *d) 496 486 { 497 - int gpio = pxa_irq_to_gpio(d->irq); 498 - struct pxa_gpio_chip *c = gpio_to_pxachip(gpio); 487 + struct pxa_gpio_chip *pchip = irq_data_get_irq_chip_data(d); 488 + unsigned int gpio = irqd_to_hwirq(d); 489 + struct pxa_gpio_bank *c = gpio_to_pxabank(&pchip->chip, gpio); 499 490 500 491 c->irq_mask |= GPIO_bit(gpio); 501 492 update_edge_detect(c); ··· 555 506 return count; 556 507 } 557 508 509 + static int pxa_irq_domain_map(struct irq_domain *d, unsigned int irq, 510 + irq_hw_number_t hw) 511 + { 512 + irq_set_chip_and_handler(irq, &pxa_muxed_gpio_chip, 513 + handle_edge_irq); 514 + irq_set_chip_data(irq, d->host_data); 515 + irq_set_noprobe(irq); 516 + return 0; 517 + } 518 + 519 + const struct irq_domain_ops pxa_irq_domain_ops = { 520 + .map = pxa_irq_domain_map, 521 + .xlate = irq_domain_xlate_twocell, 522 + }; 523 + 558 524 #ifdef CONFIG_OF 559 525 static const struct of_device_id pxa_gpio_dt_ids[] = { 560 526 { .compatible = "intel,pxa25x-gpio", .data = &pxa25x_id, }, ··· 583 519 {} 584 520 }; 585 521 586 - static int pxa_irq_domain_map(struct irq_domain *d, unsigned int irq, 587 - irq_hw_number_t hw) 522 + static int pxa_gpio_probe_dt(struct platform_device *pdev, 523 + struct pxa_gpio_chip *pchip) 588 524 { 589 - irq_set_chip_and_handler(irq, &pxa_muxed_gpio_chip, 590 - handle_edge_irq); 591 - irq_set_noprobe(irq); 592 - return 0; 593 - } 594 - 595 - const struct irq_domain_ops pxa_irq_domain_ops = { 596 - .map = pxa_irq_domain_map, 597 - .xlate = irq_domain_xlate_twocell, 598 - }; 599 - 600 - static int pxa_gpio_probe_dt(struct platform_device *pdev) 601 - { 602 - int ret = 0, nr_gpios; 603 - struct device_node *np = pdev->dev.of_node; 525 + int nr_gpios; 604 526 const struct of_device_id *of_id = 605 527 of_match_device(pxa_gpio_dt_ids, &pdev->dev); 606 528 const struct pxa_gpio_id *gpio_id; ··· 604 554 irq_base = irq_alloc_descs(-1, 0, nr_gpios, 0); 605 555 if (irq_base < 0) { 606 556 dev_err(&pdev->dev, "Failed to allocate IRQ numbers\n"); 607 - ret = irq_base; 608 - goto err; 557 + return irq_base; 609 558 } 610 - domain = irq_domain_add_legacy(np, nr_gpios, irq_base, 0, 611 - &pxa_irq_domain_ops, NULL); 612 - pxa_gpio_of_node = np; 613 - return 0; 614 - err: 615 - iounmap(gpio_reg_base); 616 - return ret; 559 + return irq_base; 617 560 } 618 561 #else 619 - #define pxa_gpio_probe_dt(pdev) (-1) 562 + #define pxa_gpio_probe_dt(pdev, pchip) (-1) 620 563 #endif 621 564 622 565 static int pxa_gpio_probe(struct platform_device *pdev) 623 566 { 624 - struct pxa_gpio_chip *c; 567 + struct pxa_gpio_chip *pchip; 568 + struct pxa_gpio_bank *c; 625 569 struct resource *res; 626 570 struct clk *clk; 627 571 struct pxa_gpio_platform_data *info; 628 - int gpio, irq, ret, use_of = 0; 572 + void __iomem *gpio_reg_base; 573 + int gpio, ret; 629 574 int irq0 = 0, irq1 = 0, irq_mux, gpio_offset = 0; 575 + 576 + pchip = devm_kzalloc(&pdev->dev, sizeof(*pchip), GFP_KERNEL); 577 + if (!pchip) 578 + return -ENOMEM; 579 + pchip->dev = &pdev->dev; 630 580 631 581 info = dev_get_platdata(&pdev->dev); 632 582 if (info) { ··· 634 584 if (irq_base <= 0) 635 585 return -EINVAL; 636 586 pxa_last_gpio = pxa_gpio_nums(pdev); 587 + pchip->set_wake = info->gpio_set_wake; 637 588 } else { 638 - irq_base = 0; 639 - use_of = 1; 640 - ret = pxa_gpio_probe_dt(pdev); 641 - if (ret < 0) 589 + irq_base = pxa_gpio_probe_dt(pdev, pchip); 590 + if (irq_base < 0) 642 591 return -EINVAL; 643 592 } 644 593 645 594 if (!pxa_last_gpio) 646 595 return -EINVAL; 596 + 597 + pchip->irqdomain = irq_domain_add_legacy(pdev->dev.of_node, 598 + pxa_last_gpio + 1, irq_base, 599 + 0, &pxa_irq_domain_ops, pchip); 600 + if (!pchip->irqdomain) 601 + return -ENOMEM; 647 602 648 603 irq0 = platform_get_irq_byname(pdev, "gpio0"); 649 604 irq1 = platform_get_irq_byname(pdev, "gpio1"); ··· 656 601 if ((irq0 > 0 && irq1 <= 0) || (irq0 <= 0 && irq1 > 0) 657 602 || (irq_mux <= 0)) 658 603 return -EINVAL; 604 + 605 + pchip->irq0 = irq0; 606 + pchip->irq1 = irq1; 659 607 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 660 - if (!res) 661 - return -EINVAL; 662 - gpio_reg_base = ioremap(res->start, resource_size(res)); 608 + gpio_reg_base = devm_ioremap(&pdev->dev, res->start, 609 + resource_size(res)); 663 610 if (!gpio_reg_base) 664 611 return -EINVAL; 665 612 ··· 672 615 if (IS_ERR(clk)) { 673 616 dev_err(&pdev->dev, "Error %ld to get gpio clock\n", 674 617 PTR_ERR(clk)); 675 - iounmap(gpio_reg_base); 676 618 return PTR_ERR(clk); 677 619 } 678 620 ret = clk_prepare_enable(clk); 679 621 if (ret) { 680 622 clk_put(clk); 681 - iounmap(gpio_reg_base); 682 623 return ret; 683 624 } 684 625 685 626 /* Initialize GPIO chips */ 686 - pxa_init_gpio_chip(pxa_last_gpio, info ? info->gpio_set_wake : NULL); 627 + ret = pxa_init_gpio_chip(pchip, pxa_last_gpio + 1, pdev->dev.of_node, 628 + gpio_reg_base); 629 + if (ret) { 630 + clk_put(clk); 631 + return ret; 632 + } 687 633 688 634 /* clear all GPIO edge detects */ 689 - for_each_gpio_chip(gpio, c) { 635 + for_each_gpio_bank(gpio, c, pchip) { 690 636 writel_relaxed(0, c->regbase + GFER_OFFSET); 691 637 writel_relaxed(0, c->regbase + GRER_OFFSET); 692 638 writel_relaxed(~0, c->regbase + GEDR_OFFSET); ··· 698 638 writel_relaxed(~0, c->regbase + ED_MASK_OFFSET); 699 639 } 700 640 701 - if (!use_of) { 702 - if (irq0 > 0) { 703 - irq = gpio_to_irq(0); 704 - irq_set_chip_and_handler(irq, &pxa_muxed_gpio_chip, 705 - handle_edge_irq); 706 - irq_clear_status_flags(irq, IRQ_NOREQUEST | IRQ_NOPROBE); 707 - } 708 - if (irq1 > 0) { 709 - irq = gpio_to_irq(1); 710 - irq_set_chip_and_handler(irq, &pxa_muxed_gpio_chip, 711 - handle_edge_irq); 712 - irq_clear_status_flags(irq, IRQ_NOREQUEST | IRQ_NOPROBE); 713 - } 714 - 715 - for (irq = gpio_to_irq(gpio_offset); 716 - irq <= gpio_to_irq(pxa_last_gpio); irq++) { 717 - irq_set_chip_and_handler(irq, &pxa_muxed_gpio_chip, 718 - handle_edge_irq); 719 - irq_clear_status_flags(irq, IRQ_NOREQUEST | IRQ_NOPROBE); 720 - } 641 + if (irq0 > 0) { 642 + ret = devm_request_irq(&pdev->dev, 643 + irq0, pxa_gpio_direct_handler, 0, 644 + "gpio-0", pchip); 645 + if (ret) 646 + dev_err(&pdev->dev, "request of gpio0 irq failed: %d\n", 647 + ret); 721 648 } 649 + if (irq1 > 0) { 650 + ret = devm_request_irq(&pdev->dev, 651 + irq1, pxa_gpio_direct_handler, 0, 652 + "gpio-1", pchip); 653 + if (ret) 654 + dev_err(&pdev->dev, "request of gpio1 irq failed: %d\n", 655 + ret); 656 + } 657 + ret = devm_request_irq(&pdev->dev, 658 + irq_mux, pxa_gpio_demux_handler, 0, 659 + "gpio-mux", pchip); 660 + if (ret) 661 + dev_err(&pdev->dev, "request of gpio-mux irq failed: %d\n", 662 + ret); 722 663 723 - if (irq0 > 0) 724 - irq_set_chained_handler(irq0, pxa_gpio_demux_handler); 725 - if (irq1 > 0) 726 - irq_set_chained_handler(irq1, pxa_gpio_demux_handler); 664 + pxa_gpio_chip = pchip; 727 665 728 - irq_set_chained_handler(irq_mux, pxa_gpio_demux_handler); 729 666 return 0; 730 667 } 731 668 ··· 747 690 .id_table = gpio_id_table, 748 691 }; 749 692 750 - static int __init pxa_gpio_init(void) 693 + static int __init pxa_gpio_legacy_init(void) 751 694 { 695 + if (of_have_populated_dt()) 696 + return 0; 697 + 752 698 return platform_driver_register(&pxa_gpio_driver); 753 699 } 754 - postcore_initcall(pxa_gpio_init); 700 + postcore_initcall(pxa_gpio_legacy_init); 701 + 702 + static int __init pxa_gpio_dt_init(void) 703 + { 704 + if (of_have_populated_dt()) 705 + return platform_driver_register(&pxa_gpio_driver); 706 + 707 + return 0; 708 + } 709 + device_initcall(pxa_gpio_dt_init); 755 710 756 711 #ifdef CONFIG_PM 757 712 static int pxa_gpio_suspend(void) 758 713 { 759 - struct pxa_gpio_chip *c; 714 + struct pxa_gpio_chip *pchip = pxa_gpio_chip; 715 + struct pxa_gpio_bank *c; 760 716 int gpio; 761 717 762 - for_each_gpio_chip(gpio, c) { 718 + for_each_gpio_bank(gpio, c, pchip) { 763 719 c->saved_gplr = readl_relaxed(c->regbase + GPLR_OFFSET); 764 720 c->saved_gpdr = readl_relaxed(c->regbase + GPDR_OFFSET); 765 721 c->saved_grer = readl_relaxed(c->regbase + GRER_OFFSET); ··· 786 716 787 717 static void pxa_gpio_resume(void) 788 718 { 789 - struct pxa_gpio_chip *c; 719 + struct pxa_gpio_chip *pchip = pxa_gpio_chip; 720 + struct pxa_gpio_bank *c; 790 721 int gpio; 791 722 792 - for_each_gpio_chip(gpio, c) { 723 + for_each_gpio_bank(gpio, c, pchip) { 793 724 /* restore level with set/clear */ 794 725 writel_relaxed(c->saved_gplr, c->regbase + GPSR_OFFSET); 795 726 writel_relaxed(~c->saved_gplr, c->regbase + GPCR_OFFSET);
+8 -13
drivers/gpio/gpio-rc5t583.c
··· 34 34 struct rc5t583 *rc5t583; 35 35 }; 36 36 37 - static inline struct rc5t583_gpio *to_rc5t583_gpio(struct gpio_chip *chip) 38 - { 39 - return container_of(chip, struct rc5t583_gpio, gpio_chip); 40 - } 41 - 42 37 static int rc5t583_gpio_get(struct gpio_chip *gc, unsigned int offset) 43 38 { 44 - struct rc5t583_gpio *rc5t583_gpio = to_rc5t583_gpio(gc); 39 + struct rc5t583_gpio *rc5t583_gpio = gpiochip_get_data(gc); 45 40 struct device *parent = rc5t583_gpio->rc5t583->dev; 46 41 uint8_t val = 0; 47 42 int ret; ··· 50 55 51 56 static void rc5t583_gpio_set(struct gpio_chip *gc, unsigned int offset, int val) 52 57 { 53 - struct rc5t583_gpio *rc5t583_gpio = to_rc5t583_gpio(gc); 58 + struct rc5t583_gpio *rc5t583_gpio = gpiochip_get_data(gc); 54 59 struct device *parent = rc5t583_gpio->rc5t583->dev; 55 60 if (val) 56 61 rc5t583_set_bits(parent, RC5T583_GPIO_IOOUT, BIT(offset)); ··· 60 65 61 66 static int rc5t583_gpio_dir_input(struct gpio_chip *gc, unsigned int offset) 62 67 { 63 - struct rc5t583_gpio *rc5t583_gpio = to_rc5t583_gpio(gc); 68 + struct rc5t583_gpio *rc5t583_gpio = gpiochip_get_data(gc); 64 69 struct device *parent = rc5t583_gpio->rc5t583->dev; 65 70 int ret; 66 71 ··· 75 80 static int rc5t583_gpio_dir_output(struct gpio_chip *gc, unsigned offset, 76 81 int value) 77 82 { 78 - struct rc5t583_gpio *rc5t583_gpio = to_rc5t583_gpio(gc); 83 + struct rc5t583_gpio *rc5t583_gpio = gpiochip_get_data(gc); 79 84 struct device *parent = rc5t583_gpio->rc5t583->dev; 80 85 int ret; 81 86 ··· 90 95 91 96 static int rc5t583_gpio_to_irq(struct gpio_chip *gc, unsigned offset) 92 97 { 93 - struct rc5t583_gpio *rc5t583_gpio = to_rc5t583_gpio(gc); 98 + struct rc5t583_gpio *rc5t583_gpio = gpiochip_get_data(gc); 94 99 95 100 if (offset < RC5T583_MAX_GPIO) 96 101 return rc5t583_gpio->rc5t583->irq_base + ··· 100 105 101 106 static void rc5t583_gpio_free(struct gpio_chip *gc, unsigned offset) 102 107 { 103 - struct rc5t583_gpio *rc5t583_gpio = to_rc5t583_gpio(gc); 108 + struct rc5t583_gpio *rc5t583_gpio = gpiochip_get_data(gc); 104 109 struct device *parent = rc5t583_gpio->rc5t583->dev; 105 110 106 111 rc5t583_set_bits(parent, RC5T583_GPIO_PGSEL, BIT(offset)); ··· 127 132 rc5t583_gpio->gpio_chip.to_irq = rc5t583_gpio_to_irq, 128 133 rc5t583_gpio->gpio_chip.ngpio = RC5T583_MAX_GPIO, 129 134 rc5t583_gpio->gpio_chip.can_sleep = true, 130 - rc5t583_gpio->gpio_chip.dev = &pdev->dev; 135 + rc5t583_gpio->gpio_chip.parent = &pdev->dev; 131 136 rc5t583_gpio->gpio_chip.base = -1; 132 137 rc5t583_gpio->rc5t583 = rc5t583; 133 138 ··· 136 141 137 142 platform_set_drvdata(pdev, rc5t583_gpio); 138 143 139 - return gpiochip_add(&rc5t583_gpio->gpio_chip); 144 + return gpiochip_add_data(&rc5t583_gpio->gpio_chip, rc5t583_gpio); 140 145 } 141 146 142 147 static int rc5t583_gpio_remove(struct platform_device *pdev)
+49 -74
drivers/gpio/gpio-rcar.c
··· 25 25 #include <linux/module.h> 26 26 #include <linux/of.h> 27 27 #include <linux/pinctrl/consumer.h> 28 - #include <linux/platform_data/gpio-rcar.h> 29 28 #include <linux/platform_device.h> 30 29 #include <linux/pm_runtime.h> 31 30 #include <linux/spinlock.h> ··· 33 34 struct gpio_rcar_priv { 34 35 void __iomem *base; 35 36 spinlock_t lock; 36 - struct gpio_rcar_config config; 37 37 struct platform_device *pdev; 38 38 struct gpio_chip gpio_chip; 39 39 struct irq_chip irq_chip; 40 - unsigned int irq_parent; 41 40 struct clk *clk; 41 + unsigned int irq_parent; 42 + bool has_both_edge_trigger; 43 + bool needs_clk; 42 44 }; 43 45 44 46 #define IOINTSEL 0x00 /* General IO/Interrupt Switching Register */ ··· 84 84 static void gpio_rcar_irq_disable(struct irq_data *d) 85 85 { 86 86 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 87 - struct gpio_rcar_priv *p = container_of(gc, struct gpio_rcar_priv, 88 - gpio_chip); 87 + struct gpio_rcar_priv *p = gpiochip_get_data(gc); 89 88 90 89 gpio_rcar_write(p, INTMSK, ~BIT(irqd_to_hwirq(d))); 91 90 } ··· 92 93 static void gpio_rcar_irq_enable(struct irq_data *d) 93 94 { 94 95 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 95 - struct gpio_rcar_priv *p = container_of(gc, struct gpio_rcar_priv, 96 - gpio_chip); 96 + struct gpio_rcar_priv *p = gpiochip_get_data(gc); 97 97 98 98 gpio_rcar_write(p, MSKCLR, BIT(irqd_to_hwirq(d))); 99 99 } ··· 119 121 gpio_rcar_modify_bit(p, EDGLEVEL, hwirq, !level_trigger); 120 122 121 123 /* Select one edge or both edges in BOTHEDGE */ 122 - if (p->config.has_both_edge_trigger) 124 + if (p->has_both_edge_trigger) 123 125 gpio_rcar_modify_bit(p, BOTHEDGE, hwirq, both); 124 126 125 127 /* Select "Interrupt Input Mode" in IOINTSEL */ ··· 135 137 static int gpio_rcar_irq_set_type(struct irq_data *d, unsigned int type) 136 138 { 137 139 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 138 - struct gpio_rcar_priv *p = container_of(gc, struct gpio_rcar_priv, 139 - gpio_chip); 140 + struct gpio_rcar_priv *p = gpiochip_get_data(gc); 140 141 unsigned int hwirq = irqd_to_hwirq(d); 141 142 142 143 dev_dbg(&p->pdev->dev, "sense irq = %d, type = %d\n", hwirq, type); ··· 158 161 false); 159 162 break; 160 163 case IRQ_TYPE_EDGE_BOTH: 161 - if (!p->config.has_both_edge_trigger) 164 + if (!p->has_both_edge_trigger) 162 165 return -EINVAL; 163 166 gpio_rcar_config_interrupt_input_mode(p, hwirq, true, false, 164 167 true); ··· 172 175 static int gpio_rcar_irq_set_wake(struct irq_data *d, unsigned int on) 173 176 { 174 177 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 175 - struct gpio_rcar_priv *p = container_of(gc, struct gpio_rcar_priv, 176 - gpio_chip); 178 + struct gpio_rcar_priv *p = gpiochip_get_data(gc); 177 179 int error; 178 180 179 181 if (p->irq_parent) { ··· 214 218 return irqs_handled ? IRQ_HANDLED : IRQ_NONE; 215 219 } 216 220 217 - static inline struct gpio_rcar_priv *gpio_to_priv(struct gpio_chip *chip) 218 - { 219 - return container_of(chip, struct gpio_rcar_priv, gpio_chip); 220 - } 221 - 222 221 static void gpio_rcar_config_general_input_output_mode(struct gpio_chip *chip, 223 222 unsigned int gpio, 224 223 bool output) 225 224 { 226 - struct gpio_rcar_priv *p = gpio_to_priv(chip); 225 + struct gpio_rcar_priv *p = gpiochip_get_data(chip); 227 226 unsigned long flags; 228 227 229 228 /* follow steps in the GPIO documentation for ··· 242 251 243 252 static int gpio_rcar_request(struct gpio_chip *chip, unsigned offset) 244 253 { 245 - struct gpio_rcar_priv *p = gpio_to_priv(chip); 254 + struct gpio_rcar_priv *p = gpiochip_get_data(chip); 246 255 int error; 247 256 248 257 error = pm_runtime_get_sync(&p->pdev->dev); ··· 258 267 259 268 static void gpio_rcar_free(struct gpio_chip *chip, unsigned offset) 260 269 { 261 - struct gpio_rcar_priv *p = gpio_to_priv(chip); 270 + struct gpio_rcar_priv *p = gpiochip_get_data(chip); 262 271 263 272 pinctrl_free_gpio(chip->base + offset); 264 273 ··· 282 291 283 292 /* testing on r8a7790 shows that INDT does not show correct pin state 284 293 * when configured as output, so use OUTDT in case of output pins */ 285 - if (gpio_rcar_read(gpio_to_priv(chip), INOUTSEL) & bit) 286 - return !!(gpio_rcar_read(gpio_to_priv(chip), OUTDT) & bit); 294 + if (gpio_rcar_read(gpiochip_get_data(chip), INOUTSEL) & bit) 295 + return !!(gpio_rcar_read(gpiochip_get_data(chip), OUTDT) & bit); 287 296 else 288 - return !!(gpio_rcar_read(gpio_to_priv(chip), INDT) & bit); 297 + return !!(gpio_rcar_read(gpiochip_get_data(chip), INDT) & bit); 289 298 } 290 299 291 300 static void gpio_rcar_set(struct gpio_chip *chip, unsigned offset, int value) 292 301 { 293 - struct gpio_rcar_priv *p = gpio_to_priv(chip); 302 + struct gpio_rcar_priv *p = gpiochip_get_data(chip); 294 303 unsigned long flags; 295 304 296 305 spin_lock_irqsave(&p->lock, flags); ··· 309 318 310 319 struct gpio_rcar_info { 311 320 bool has_both_edge_trigger; 321 + bool needs_clk; 312 322 }; 313 323 314 324 static const struct gpio_rcar_info gpio_rcar_info_gen1 = { 315 325 .has_both_edge_trigger = false, 326 + .needs_clk = false, 316 327 }; 317 328 318 329 static const struct gpio_rcar_info gpio_rcar_info_gen2 = { 319 330 .has_both_edge_trigger = true, 331 + .needs_clk = true, 320 332 }; 321 333 322 334 static const struct of_device_id gpio_rcar_of_table[] = { ··· 349 355 350 356 MODULE_DEVICE_TABLE(of, gpio_rcar_of_table); 351 357 352 - static int gpio_rcar_parse_pdata(struct gpio_rcar_priv *p) 358 + static int gpio_rcar_parse_dt(struct gpio_rcar_priv *p, unsigned int *npins) 353 359 { 354 - struct gpio_rcar_config *pdata = dev_get_platdata(&p->pdev->dev); 355 360 struct device_node *np = p->pdev->dev.of_node; 361 + const struct of_device_id *match; 362 + const struct gpio_rcar_info *info; 356 363 struct of_phandle_args args; 357 364 int ret; 358 365 359 - if (pdata) { 360 - p->config = *pdata; 361 - } else if (IS_ENABLED(CONFIG_OF) && np) { 362 - const struct of_device_id *match; 363 - const struct gpio_rcar_info *info; 366 + match = of_match_node(gpio_rcar_of_table, np); 367 + if (!match) 368 + return -EINVAL; 364 369 365 - match = of_match_node(gpio_rcar_of_table, np); 366 - if (!match) 367 - return -EINVAL; 370 + info = match->data; 368 371 369 - info = match->data; 372 + ret = of_parse_phandle_with_fixed_args(np, "gpio-ranges", 3, 0, &args); 373 + *npins = ret == 0 ? args.args[2] : RCAR_MAX_GPIO_PER_BANK; 374 + p->has_both_edge_trigger = info->has_both_edge_trigger; 375 + p->needs_clk = info->needs_clk; 370 376 371 - ret = of_parse_phandle_with_fixed_args(np, "gpio-ranges", 3, 0, 372 - &args); 373 - p->config.number_of_pins = ret == 0 ? args.args[2] 374 - : RCAR_MAX_GPIO_PER_BANK; 375 - p->config.gpio_base = -1; 376 - p->config.has_both_edge_trigger = info->has_both_edge_trigger; 377 - } 378 - 379 - if (p->config.number_of_pins == 0 || 380 - p->config.number_of_pins > RCAR_MAX_GPIO_PER_BANK) { 377 + if (*npins == 0 || *npins > RCAR_MAX_GPIO_PER_BANK) { 381 378 dev_warn(&p->pdev->dev, 382 - "Invalid number of gpio lines %u, using %u\n", 383 - p->config.number_of_pins, RCAR_MAX_GPIO_PER_BANK); 384 - p->config.number_of_pins = RCAR_MAX_GPIO_PER_BANK; 379 + "Invalid number of gpio lines %u, using %u\n", *npins, 380 + RCAR_MAX_GPIO_PER_BANK); 381 + *npins = RCAR_MAX_GPIO_PER_BANK; 385 382 } 386 383 387 384 return 0; ··· 386 401 struct irq_chip *irq_chip; 387 402 struct device *dev = &pdev->dev; 388 403 const char *name = dev_name(dev); 404 + unsigned int npins; 389 405 int ret; 390 406 391 407 p = devm_kzalloc(dev, sizeof(*p), GFP_KERNEL); ··· 396 410 p->pdev = pdev; 397 411 spin_lock_init(&p->lock); 398 412 399 - /* Get device configuration from DT node or platform data. */ 400 - ret = gpio_rcar_parse_pdata(p); 413 + /* Get device configuration from DT node */ 414 + ret = gpio_rcar_parse_dt(p, &npins); 401 415 if (ret < 0) 402 416 return ret; 403 417 ··· 405 419 406 420 p->clk = devm_clk_get(dev, NULL); 407 421 if (IS_ERR(p->clk)) { 408 - dev_warn(dev, "unable to get clock\n"); 422 + if (p->needs_clk) { 423 + dev_err(dev, "unable to get clock\n"); 424 + ret = PTR_ERR(p->clk); 425 + goto err0; 426 + } 409 427 p->clk = NULL; 410 428 } 411 429 ··· 439 449 gpio_chip->direction_output = gpio_rcar_direction_output; 440 450 gpio_chip->set = gpio_rcar_set; 441 451 gpio_chip->label = name; 442 - gpio_chip->dev = dev; 452 + gpio_chip->parent = dev; 443 453 gpio_chip->owner = THIS_MODULE; 444 - gpio_chip->base = p->config.gpio_base; 445 - gpio_chip->ngpio = p->config.number_of_pins; 454 + gpio_chip->base = -1; 455 + gpio_chip->ngpio = npins; 446 456 447 457 irq_chip = &p->irq_chip; 448 458 irq_chip->name = name; ··· 452 462 irq_chip->irq_set_wake = gpio_rcar_irq_set_wake; 453 463 irq_chip->flags = IRQCHIP_SET_TYPE_MASKED | IRQCHIP_MASK_ON_SUSPEND; 454 464 455 - ret = gpiochip_add(gpio_chip); 465 + ret = gpiochip_add_data(gpio_chip, p); 456 466 if (ret) { 457 467 dev_err(dev, "failed to add GPIO controller\n"); 458 468 goto err0; 459 469 } 460 470 461 - ret = gpiochip_irqchip_add(gpio_chip, irq_chip, p->config.irq_base, 462 - handle_level_irq, IRQ_TYPE_NONE); 471 + ret = gpiochip_irqchip_add(gpio_chip, irq_chip, 0, handle_level_irq, 472 + IRQ_TYPE_NONE); 463 473 if (ret) { 464 474 dev_err(dev, "cannot add irqchip\n"); 465 475 goto err1; ··· 473 483 goto err1; 474 484 } 475 485 476 - dev_info(dev, "driving %d GPIOs\n", p->config.number_of_pins); 477 - 478 - /* warn in case of mismatch if irq base is specified */ 479 - if (p->config.irq_base) { 480 - ret = irq_find_mapping(gpio_chip->irqdomain, 0); 481 - if (p->config.irq_base != ret) 482 - dev_warn(dev, "irq base mismatch (%u/%u)\n", 483 - p->config.irq_base, ret); 484 - } 485 - 486 - if (p->config.pctl_name) { 487 - ret = gpiochip_add_pin_range(gpio_chip, p->config.pctl_name, 0, 488 - gpio_chip->base, gpio_chip->ngpio); 489 - if (ret < 0) 490 - dev_warn(dev, "failed to add pin range\n"); 491 - } 486 + dev_info(dev, "driving %d GPIOs\n", npins); 492 487 493 488 return 0; 494 489
+5 -5
drivers/gpio/gpio-rdc321x.c
··· 47 47 u32 value = 0; 48 48 int reg; 49 49 50 - gpch = container_of(chip, struct rdc321x_gpio, chip); 50 + gpch = gpiochip_get_data(chip); 51 51 reg = gpio < 32 ? gpch->reg1_data_base : gpch->reg2_data_base; 52 52 53 53 spin_lock(&gpch->lock); ··· 65 65 struct rdc321x_gpio *gpch; 66 66 int reg = (gpio < 32) ? 0 : 1; 67 67 68 - gpch = container_of(chip, struct rdc321x_gpio, chip); 68 + gpch = gpiochip_get_data(chip); 69 69 70 70 if (value) 71 71 gpch->data_reg[reg] |= 1 << (gpio & 0x1f); ··· 83 83 { 84 84 struct rdc321x_gpio *gpch; 85 85 86 - gpch = container_of(chip, struct rdc321x_gpio, chip); 86 + gpch = gpiochip_get_data(chip); 87 87 spin_lock(&gpch->lock); 88 88 rdc_gpio_set_value_impl(chip, gpio, value); 89 89 spin_unlock(&gpch->lock); ··· 96 96 int err; 97 97 u32 reg; 98 98 99 - gpch = container_of(chip, struct rdc321x_gpio, chip); 99 + gpch = gpiochip_get_data(chip); 100 100 101 101 spin_lock(&gpch->lock); 102 102 err = pci_read_config_dword(gpch->sb_pdev, gpio < 32 ? ··· 194 194 195 195 dev_info(&pdev->dev, "registering %d GPIOs\n", 196 196 rdc321x_gpio_dev->chip.ngpio); 197 - return gpiochip_add(&rdc321x_gpio_dev->chip); 197 + return gpiochip_add_data(&rdc321x_gpio_dev->chip, rdc321x_gpio_dev); 198 198 } 199 199 200 200 static int rdc321x_gpio_remove(struct platform_device *pdev)
+2 -2
drivers/gpio/gpio-sa1100.c
··· 17 17 18 18 static int sa1100_gpio_get(struct gpio_chip *chip, unsigned offset) 19 19 { 20 - return GPLR & GPIO_GPIO(offset); 20 + return !!(GPLR & GPIO_GPIO(offset)); 21 21 } 22 22 23 23 static void sa1100_gpio_set(struct gpio_chip *chip, unsigned offset, int value) ··· 238 238 GRER = 0; 239 239 GEDR = -1; 240 240 241 - gpiochip_add(&sa1100_gpio_chip); 241 + gpiochip_add_data(&sa1100_gpio_chip, NULL); 242 242 243 243 sa1100_gpio_irqdomain = irq_domain_add_simple(NULL, 244 244 28, IRQ_GPIO0,
+2 -2
drivers/gpio/gpio-samsung.c
··· 753 753 #endif 754 754 755 755 /* gpiochip_add() prints own failure message on error. */ 756 - ret = gpiochip_add(gc); 756 + ret = gpiochip_add_data(gc, chip); 757 757 if (ret >= 0) 758 758 s3c_gpiolib_track(chip); 759 759 } ··· 862 862 863 863 int samsung_gpiolib_to_irq(struct gpio_chip *chip, unsigned int offset) 864 864 { 865 - struct samsung_gpio_chip *samsung_chip = container_of(chip, struct samsung_gpio_chip, chip); 865 + struct samsung_gpio_chip *samsung_chip = gpiochip_get_data(chip); 866 866 867 867 return samsung_chip->irq_base + offset; 868 868 }
+7 -9
drivers/gpio/gpio-sch.c
··· 41 41 unsigned short resume_base; 42 42 }; 43 43 44 - #define to_sch_gpio(gc) container_of(gc, struct sch_gpio, chip) 45 - 46 44 static unsigned sch_gpio_offset(struct sch_gpio *sch, unsigned gpio, 47 45 unsigned reg) 48 46 { ··· 63 65 64 66 static int sch_gpio_reg_get(struct gpio_chip *gc, unsigned gpio, unsigned reg) 65 67 { 66 - struct sch_gpio *sch = to_sch_gpio(gc); 68 + struct sch_gpio *sch = gpiochip_get_data(gc); 67 69 unsigned short offset, bit; 68 70 u8 reg_val; 69 71 ··· 78 80 static void sch_gpio_reg_set(struct gpio_chip *gc, unsigned gpio, unsigned reg, 79 81 int val) 80 82 { 81 - struct sch_gpio *sch = to_sch_gpio(gc); 83 + struct sch_gpio *sch = gpiochip_get_data(gc); 82 84 unsigned short offset, bit; 83 85 u8 reg_val; 84 86 ··· 95 97 96 98 static int sch_gpio_direction_in(struct gpio_chip *gc, unsigned gpio_num) 97 99 { 98 - struct sch_gpio *sch = to_sch_gpio(gc); 100 + struct sch_gpio *sch = gpiochip_get_data(gc); 99 101 100 102 spin_lock(&sch->lock); 101 103 sch_gpio_reg_set(gc, gpio_num, GIO, 1); ··· 110 112 111 113 static void sch_gpio_set(struct gpio_chip *gc, unsigned gpio_num, int val) 112 114 { 113 - struct sch_gpio *sch = to_sch_gpio(gc); 115 + struct sch_gpio *sch = gpiochip_get_data(gc); 114 116 115 117 spin_lock(&sch->lock); 116 118 sch_gpio_reg_set(gc, gpio_num, GLV, val); ··· 120 122 static int sch_gpio_direction_out(struct gpio_chip *gc, unsigned gpio_num, 121 123 int val) 122 124 { 123 - struct sch_gpio *sch = to_sch_gpio(gc); 125 + struct sch_gpio *sch = gpiochip_get_data(gc); 124 126 125 127 spin_lock(&sch->lock); 126 128 sch_gpio_reg_set(gc, gpio_num, GIO, 0); ··· 169 171 sch->iobase = res->start; 170 172 sch->chip = sch_gpio_chip; 171 173 sch->chip.label = dev_name(&pdev->dev); 172 - sch->chip.dev = &pdev->dev; 174 + sch->chip.parent = &pdev->dev; 173 175 174 176 switch (pdev->id) { 175 177 case PCI_DEVICE_ID_INTEL_SCH_LPC: ··· 215 217 216 218 platform_set_drvdata(pdev, sch); 217 219 218 - return gpiochip_add(&sch->chip); 220 + return gpiochip_add_data(&sch->chip, sch); 219 221 } 220 222 221 223 static int sch_gpio_remove(struct platform_device *pdev)
+11 -18
drivers/gpio/gpio-sch311x.c
··· 93 93 }, 94 94 }; 95 95 96 - static inline struct sch311x_gpio_block * 97 - to_sch311x_gpio_block(struct gpio_chip *chip) 98 - { 99 - return container_of(chip, struct sch311x_gpio_block, chip); 100 - } 101 - 102 - 103 96 /* 104 97 * Super-IO functions 105 98 */ ··· 135 142 136 143 static int sch311x_gpio_request(struct gpio_chip *chip, unsigned offset) 137 144 { 138 - struct sch311x_gpio_block *block = to_sch311x_gpio_block(chip); 145 + struct sch311x_gpio_block *block = gpiochip_get_data(chip); 139 146 140 147 if (block->config_regs[offset] == 0) /* GPIO is not available */ 141 148 return -ENODEV; 142 149 143 150 if (!request_region(block->runtime_reg + block->config_regs[offset], 144 151 1, DRV_NAME)) { 145 - dev_err(chip->dev, "Failed to request region 0x%04x.\n", 152 + dev_err(chip->parent, "Failed to request region 0x%04x.\n", 146 153 block->runtime_reg + block->config_regs[offset]); 147 154 return -EBUSY; 148 155 } ··· 151 158 152 159 static void sch311x_gpio_free(struct gpio_chip *chip, unsigned offset) 153 160 { 154 - struct sch311x_gpio_block *block = to_sch311x_gpio_block(chip); 161 + struct sch311x_gpio_block *block = gpiochip_get_data(chip); 155 162 156 163 if (block->config_regs[offset] == 0) /* GPIO is not available */ 157 164 return; ··· 161 168 162 169 static int sch311x_gpio_get(struct gpio_chip *chip, unsigned offset) 163 170 { 164 - struct sch311x_gpio_block *block = to_sch311x_gpio_block(chip); 171 + struct sch311x_gpio_block *block = gpiochip_get_data(chip); 165 172 unsigned char data; 166 173 167 174 spin_lock(&block->lock); ··· 185 192 static void sch311x_gpio_set(struct gpio_chip *chip, unsigned offset, 186 193 int value) 187 194 { 188 - struct sch311x_gpio_block *block = to_sch311x_gpio_block(chip); 195 + struct sch311x_gpio_block *block = gpiochip_get_data(chip); 189 196 190 197 spin_lock(&block->lock); 191 198 __sch311x_gpio_set(block, offset, value); ··· 194 201 195 202 static int sch311x_gpio_direction_in(struct gpio_chip *chip, unsigned offset) 196 203 { 197 - struct sch311x_gpio_block *block = to_sch311x_gpio_block(chip); 204 + struct sch311x_gpio_block *block = gpiochip_get_data(chip); 198 205 199 206 spin_lock(&block->lock); 200 207 outb(SCH311X_GPIO_CONF_IN, block->runtime_reg + ··· 207 214 static int sch311x_gpio_direction_out(struct gpio_chip *chip, unsigned offset, 208 215 int value) 209 216 { 210 - struct sch311x_gpio_block *block = to_sch311x_gpio_block(chip); 217 + struct sch311x_gpio_block *block = gpiochip_get_data(chip); 211 218 212 219 spin_lock(&block->lock); 213 220 ··· 222 229 223 230 static int sch311x_gpio_probe(struct platform_device *pdev) 224 231 { 225 - struct sch311x_pdev_data *pdata = pdev->dev.platform_data; 232 + struct sch311x_pdev_data *pdata = dev_get_platdata(&pdev->dev); 226 233 struct sch311x_gpio_priv *priv; 227 234 struct sch311x_gpio_block *block; 228 235 int err, i; ··· 254 261 block->chip.get = sch311x_gpio_get; 255 262 block->chip.set = sch311x_gpio_set; 256 263 block->chip.ngpio = 8; 257 - block->chip.dev = &pdev->dev; 264 + block->chip.parent = &pdev->dev; 258 265 block->chip.base = sch311x_gpio_blocks[i].base; 259 266 block->config_regs = sch311x_gpio_blocks[i].config_regs; 260 267 block->data_reg = sch311x_gpio_blocks[i].data_reg; 261 268 block->runtime_reg = pdata->runtime_reg; 262 269 263 - err = gpiochip_add(&block->chip); 270 + err = gpiochip_add_data(&block->chip, block); 264 271 if (err < 0) { 265 272 dev_err(&pdev->dev, 266 273 "Could not register gpiochip, %d\n", err); ··· 282 289 283 290 static int sch311x_gpio_remove(struct platform_device *pdev) 284 291 { 285 - struct sch311x_pdev_data *pdata = pdev->dev.platform_data; 292 + struct sch311x_pdev_data *pdata = dev_get_platdata(&pdev->dev); 286 293 struct sch311x_gpio_priv *priv = platform_get_drvdata(pdev); 287 294 int i; 288 295
+6 -7
drivers/gpio/gpio-sodaville.c
··· 10 10 */ 11 11 12 12 #include <linux/errno.h> 13 - #include <linux/gpio.h> 14 13 #include <linux/init.h> 15 14 #include <linux/io.h> 16 15 #include <linux/irq.h> ··· 19 20 #include <linux/pci.h> 20 21 #include <linux/platform_device.h> 21 22 #include <linux/of_irq.h> 22 - #include <linux/basic_mmio_gpio.h> 23 + #include <linux/gpio/driver.h> 23 24 24 25 #define DRV_NAME "sdv_gpio" 25 26 #define SDV_NUM_PUB_GPIOS 12 ··· 42 43 void __iomem *gpio_pub_base; 43 44 struct irq_domain *id; 44 45 struct irq_chip_generic *gc; 45 - struct bgpio_chip bgpio; 46 + struct gpio_chip chip; 46 47 }; 47 48 48 49 static int sdv_gpio_pub_set_type(struct irq_data *d, unsigned int type) ··· 225 226 writel(mux_val, sd->gpio_pub_base + GPMUXCTL); 226 227 } 227 228 228 - ret = bgpio_init(&sd->bgpio, &pdev->dev, 4, 229 + ret = bgpio_init(&sd->chip, &pdev->dev, 4, 229 230 sd->gpio_pub_base + GPINR, sd->gpio_pub_base + GPOUTR, 230 231 NULL, sd->gpio_pub_base + GPOER, NULL, 0); 231 232 if (ret) 232 233 goto unmap; 233 - sd->bgpio.gc.ngpio = SDV_NUM_PUB_GPIOS; 234 + sd->chip.ngpio = SDV_NUM_PUB_GPIOS; 234 235 235 - ret = gpiochip_add(&sd->bgpio.gc); 236 + ret = gpiochip_add_data(&sd->chip, sd); 236 237 if (ret < 0) { 237 238 dev_err(&pdev->dev, "gpiochip_add() failed.\n"); 238 239 goto unmap; ··· 264 265 free_irq(pdev->irq, sd); 265 266 irq_free_descs(sd->irq_base, SDV_NUM_PUB_GPIOS); 266 267 267 - gpiochip_remove(&sd->bgpio.gc); 268 + gpiochip_remove(&sd->chip); 268 269 pci_release_region(pdev, GPIO_BAR); 269 270 iounmap(sd->gpio_pub_base); 270 271 pci_disable_device(pdev);
+5 -8
drivers/gpio/gpio-spear-spics.c
··· 62 62 63 63 static void spics_set_value(struct gpio_chip *chip, unsigned offset, int value) 64 64 { 65 - struct spear_spics *spics = container_of(chip, struct spear_spics, 66 - chip); 65 + struct spear_spics *spics = gpiochip_get_data(chip); 67 66 u32 tmp; 68 67 69 68 /* select chip select from register */ ··· 93 94 94 95 static int spics_request(struct gpio_chip *chip, unsigned offset) 95 96 { 96 - struct spear_spics *spics = container_of(chip, struct spear_spics, 97 - chip); 97 + struct spear_spics *spics = gpiochip_get_data(chip); 98 98 u32 tmp; 99 99 100 100 if (!spics->use_count++) { ··· 108 110 109 111 static void spics_free(struct gpio_chip *chip, unsigned offset) 110 112 { 111 - struct spear_spics *spics = container_of(chip, struct spear_spics, 112 - chip); 113 + struct spear_spics *spics = gpiochip_get_data(chip); 113 114 u32 tmp; 114 115 115 116 if (!--spics->use_count) { ··· 161 164 spics->chip.get = spics_get_value; 162 165 spics->chip.set = spics_set_value; 163 166 spics->chip.label = dev_name(&pdev->dev); 164 - spics->chip.dev = &pdev->dev; 167 + spics->chip.parent = &pdev->dev; 165 168 spics->chip.owner = THIS_MODULE; 166 169 spics->last_off = -1; 167 170 168 - ret = gpiochip_add(&spics->chip); 171 + ret = gpiochip_add_data(&spics->chip, spics); 169 172 if (ret) { 170 173 dev_err(&pdev->dev, "unable to add gpio chip\n"); 171 174 return ret;
+7 -7
drivers/gpio/gpio-sta2x11.c
··· 74 74 75 75 static void gsta_gpio_set(struct gpio_chip *gpio, unsigned nr, int val) 76 76 { 77 - struct gsta_gpio *chip = container_of(gpio, struct gsta_gpio, gpio); 77 + struct gsta_gpio *chip = gpiochip_get_data(gpio); 78 78 struct gsta_regs __iomem *regs = __regs(chip, nr); 79 79 u32 bit = __bit(nr); 80 80 ··· 86 86 87 87 static int gsta_gpio_get(struct gpio_chip *gpio, unsigned nr) 88 88 { 89 - struct gsta_gpio *chip = container_of(gpio, struct gsta_gpio, gpio); 89 + struct gsta_gpio *chip = gpiochip_get_data(gpio); 90 90 struct gsta_regs __iomem *regs = __regs(chip, nr); 91 91 u32 bit = __bit(nr); 92 92 93 - return readl(&regs->dat) & bit; 93 + return !!(readl(&regs->dat) & bit); 94 94 } 95 95 96 96 static int gsta_gpio_direction_output(struct gpio_chip *gpio, unsigned nr, 97 97 int val) 98 98 { 99 - struct gsta_gpio *chip = container_of(gpio, struct gsta_gpio, gpio); 99 + struct gsta_gpio *chip = gpiochip_get_data(gpio); 100 100 struct gsta_regs __iomem *regs = __regs(chip, nr); 101 101 u32 bit = __bit(nr); 102 102 ··· 111 111 112 112 static int gsta_gpio_direction_input(struct gpio_chip *gpio, unsigned nr) 113 113 { 114 - struct gsta_gpio *chip = container_of(gpio, struct gsta_gpio, gpio); 114 + struct gsta_gpio *chip = gpiochip_get_data(gpio); 115 115 struct gsta_regs __iomem *regs = __regs(chip, nr); 116 116 u32 bit = __bit(nr); 117 117 ··· 121 121 122 122 static int gsta_gpio_to_irq(struct gpio_chip *gpio, unsigned offset) 123 123 { 124 - struct gsta_gpio *chip = container_of(gpio, struct gsta_gpio, gpio); 124 + struct gsta_gpio *chip = gpiochip_get_data(gpio); 125 125 return chip->irq_base + offset; 126 126 } 127 127 ··· 409 409 goto err_free_descs; 410 410 } 411 411 412 - err = gpiochip_add(&chip->gpio); 412 + err = gpiochip_add_data(&chip->gpio, chip); 413 413 if (err < 0) { 414 414 dev_err(&dev->dev, "sta2x11 gpio: Can't register (%i)\n", 415 415 -err);
+13 -18
drivers/gpio/gpio-stmpe.c
··· 36 36 u8 oldregs[CACHE_NR_REGS][CACHE_NR_BANKS]; 37 37 }; 38 38 39 - static inline struct stmpe_gpio *to_stmpe_gpio(struct gpio_chip *chip) 40 - { 41 - return container_of(chip, struct stmpe_gpio, chip); 42 - } 43 - 44 39 static int stmpe_gpio_get(struct gpio_chip *chip, unsigned offset) 45 40 { 46 - struct stmpe_gpio *stmpe_gpio = to_stmpe_gpio(chip); 41 + struct stmpe_gpio *stmpe_gpio = gpiochip_get_data(chip); 47 42 struct stmpe *stmpe = stmpe_gpio->stmpe; 48 43 u8 reg = stmpe->regs[STMPE_IDX_GPMR_LSB] - (offset / 8); 49 44 u8 mask = 1 << (offset % 8); ··· 53 58 54 59 static void stmpe_gpio_set(struct gpio_chip *chip, unsigned offset, int val) 55 60 { 56 - struct stmpe_gpio *stmpe_gpio = to_stmpe_gpio(chip); 61 + struct stmpe_gpio *stmpe_gpio = gpiochip_get_data(chip); 57 62 struct stmpe *stmpe = stmpe_gpio->stmpe; 58 63 int which = val ? STMPE_IDX_GPSR_LSB : STMPE_IDX_GPCR_LSB; 59 64 u8 reg = stmpe->regs[which] - (offset / 8); ··· 72 77 static int stmpe_gpio_direction_output(struct gpio_chip *chip, 73 78 unsigned offset, int val) 74 79 { 75 - struct stmpe_gpio *stmpe_gpio = to_stmpe_gpio(chip); 80 + struct stmpe_gpio *stmpe_gpio = gpiochip_get_data(chip); 76 81 struct stmpe *stmpe = stmpe_gpio->stmpe; 77 82 u8 reg = stmpe->regs[STMPE_IDX_GPDR_LSB] - (offset / 8); 78 83 u8 mask = 1 << (offset % 8); ··· 85 90 static int stmpe_gpio_direction_input(struct gpio_chip *chip, 86 91 unsigned offset) 87 92 { 88 - struct stmpe_gpio *stmpe_gpio = to_stmpe_gpio(chip); 93 + struct stmpe_gpio *stmpe_gpio = gpiochip_get_data(chip); 89 94 struct stmpe *stmpe = stmpe_gpio->stmpe; 90 95 u8 reg = stmpe->regs[STMPE_IDX_GPDR_LSB] - (offset / 8); 91 96 u8 mask = 1 << (offset % 8); ··· 95 100 96 101 static int stmpe_gpio_request(struct gpio_chip *chip, unsigned offset) 97 102 { 98 - struct stmpe_gpio *stmpe_gpio = to_stmpe_gpio(chip); 103 + struct stmpe_gpio *stmpe_gpio = gpiochip_get_data(chip); 99 104 struct stmpe *stmpe = stmpe_gpio->stmpe; 100 105 101 106 if (stmpe_gpio->norequest_mask & (1 << offset)) ··· 118 123 static int stmpe_gpio_irq_set_type(struct irq_data *d, unsigned int type) 119 124 { 120 125 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 121 - struct stmpe_gpio *stmpe_gpio = to_stmpe_gpio(gc); 126 + struct stmpe_gpio *stmpe_gpio = gpiochip_get_data(gc); 122 127 int offset = d->hwirq; 123 128 int regoffset = offset / 8; 124 129 int mask = 1 << (offset % 8); ··· 146 151 static void stmpe_gpio_irq_lock(struct irq_data *d) 147 152 { 148 153 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 149 - struct stmpe_gpio *stmpe_gpio = to_stmpe_gpio(gc); 154 + struct stmpe_gpio *stmpe_gpio = gpiochip_get_data(gc); 150 155 151 156 mutex_lock(&stmpe_gpio->irq_lock); 152 157 } ··· 154 159 static void stmpe_gpio_irq_sync_unlock(struct irq_data *d) 155 160 { 156 161 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 157 - struct stmpe_gpio *stmpe_gpio = to_stmpe_gpio(gc); 162 + struct stmpe_gpio *stmpe_gpio = gpiochip_get_data(gc); 158 163 struct stmpe *stmpe = stmpe_gpio->stmpe; 159 164 int num_banks = DIV_ROUND_UP(stmpe->num_gpios, 8); 160 165 static const u8 regmap[] = { ··· 188 193 static void stmpe_gpio_irq_mask(struct irq_data *d) 189 194 { 190 195 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 191 - struct stmpe_gpio *stmpe_gpio = to_stmpe_gpio(gc); 196 + struct stmpe_gpio *stmpe_gpio = gpiochip_get_data(gc); 192 197 int offset = d->hwirq; 193 198 int regoffset = offset / 8; 194 199 int mask = 1 << (offset % 8); ··· 199 204 static void stmpe_gpio_irq_unmask(struct irq_data *d) 200 205 { 201 206 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 202 - struct stmpe_gpio *stmpe_gpio = to_stmpe_gpio(gc); 207 + struct stmpe_gpio *stmpe_gpio = gpiochip_get_data(gc); 203 208 int offset = d->hwirq; 204 209 int regoffset = offset / 8; 205 210 int mask = 1 << (offset % 8); ··· 211 216 struct gpio_chip *gc, 212 217 unsigned offset, unsigned gpio) 213 218 { 214 - struct stmpe_gpio *stmpe_gpio = to_stmpe_gpio(gc); 219 + struct stmpe_gpio *stmpe_gpio = gpiochip_get_data(gc); 215 220 struct stmpe *stmpe = stmpe_gpio->stmpe; 216 221 const char *label = gpiochip_is_requested(gc, offset); 217 222 int num_banks = DIV_ROUND_UP(stmpe->num_gpios, 8); ··· 351 356 stmpe_gpio->stmpe = stmpe; 352 357 stmpe_gpio->chip = template_chip; 353 358 stmpe_gpio->chip.ngpio = stmpe->num_gpios; 354 - stmpe_gpio->chip.dev = &pdev->dev; 359 + stmpe_gpio->chip.parent = &pdev->dev; 355 360 stmpe_gpio->chip.of_node = np; 356 361 stmpe_gpio->chip.base = -1; 357 362 ··· 370 375 if (ret) 371 376 goto out_free; 372 377 373 - ret = gpiochip_add(&stmpe_gpio->chip); 378 + ret = gpiochip_add_data(&stmpe_gpio->chip, stmpe_gpio); 374 379 if (ret) { 375 380 dev_err(&pdev->dev, "unable to add gpiochip: %d\n", ret); 376 381 goto out_disable;
+5 -7
drivers/gpio/gpio-stp-xway.c
··· 100 100 */ 101 101 static void xway_stp_set(struct gpio_chip *gc, unsigned gpio, int val) 102 102 { 103 - struct xway_stp *chip = 104 - container_of(gc, struct xway_stp, gc); 103 + struct xway_stp *chip = gpiochip_get_data(gc); 105 104 106 105 if (val) 107 106 chip->shadow |= BIT(gpio); ··· 134 135 */ 135 136 static int xway_stp_request(struct gpio_chip *gc, unsigned gpio) 136 137 { 137 - struct xway_stp *chip = 138 - container_of(gc, struct xway_stp, gc); 138 + struct xway_stp *chip = gpiochip_get_data(gc); 139 139 140 140 if ((gpio < 8) && (chip->reserved & BIT(gpio))) { 141 - dev_err(gc->dev, "GPIO %d is driven by hardware\n", gpio); 141 + dev_err(gc->parent, "GPIO %d is driven by hardware\n", gpio); 142 142 return -ENODEV; 143 143 } 144 144 ··· 212 214 if (IS_ERR(chip->virt)) 213 215 return PTR_ERR(chip->virt); 214 216 215 - chip->gc.dev = &pdev->dev; 217 + chip->gc.parent = &pdev->dev; 216 218 chip->gc.label = "stp-xway"; 217 219 chip->gc.direction_output = xway_stp_dir_out; 218 220 chip->gc.set = xway_stp_set; ··· 258 260 259 261 ret = xway_stp_hw_init(chip); 260 262 if (!ret) 261 - ret = gpiochip_add(&chip->gc); 263 + ret = gpiochip_add_data(&chip->gc, chip); 262 264 263 265 if (!ret) 264 266 dev_info(&pdev->dev, "Init done\n");
+61 -22
drivers/gpio/gpio-sx150x.c
··· 32 32 #define NO_UPDATE_PENDING -1 33 33 34 34 /* The chip models of sx150x */ 35 - #define SX150X_456 0 36 - #define SX150X_789 1 35 + #define SX150X_123 0 36 + #define SX150X_456 1 37 + #define SX150X_789 2 38 + 39 + struct sx150x_123_pri { 40 + u8 reg_pld_mode; 41 + u8 reg_pld_table0; 42 + u8 reg_pld_table1; 43 + u8 reg_pld_table2; 44 + u8 reg_pld_table3; 45 + u8 reg_pld_table4; 46 + u8 reg_advance; 47 + }; 37 48 38 49 struct sx150x_456_pri { 39 50 u8 reg_pld_mode; ··· 76 65 u8 reg_sense; 77 66 u8 ngpios; 78 67 union { 68 + struct sx150x_123_pri x123; 79 69 struct sx150x_456_pri x456; 80 70 struct sx150x_789_pri x789; 81 71 } pri; ··· 154 142 }, 155 143 .ngpios = 16 156 144 }, 145 + [3] = { /* sx1502q */ 146 + .model = SX150X_123, 147 + .reg_pullup = 0x02, 148 + .reg_pulldn = 0x03, 149 + .reg_dir = 0x01, 150 + .reg_data = 0x00, 151 + .reg_irq_mask = 0x05, 152 + .reg_irq_src = 0x08, 153 + .reg_sense = 0x07, 154 + .pri.x123 = { 155 + .reg_pld_mode = 0x10, 156 + .reg_pld_table0 = 0x11, 157 + .reg_pld_table1 = 0x12, 158 + .reg_pld_table2 = 0x13, 159 + .reg_pld_table3 = 0x14, 160 + .reg_pld_table4 = 0x15, 161 + .reg_advance = 0xad, 162 + }, 163 + .ngpios = 8, 164 + }, 157 165 }; 158 166 159 167 static const struct i2c_device_id sx150x_id[] = { 160 168 {"sx1508q", 0}, 161 169 {"sx1509q", 1}, 162 170 {"sx1506q", 2}, 171 + {"sx1502q", 3}, 163 172 {} 164 173 }; 165 174 MODULE_DEVICE_TABLE(i2c, sx150x_id); ··· 189 156 { .compatible = "semtech,sx1508q" }, 190 157 { .compatible = "semtech,sx1509q" }, 191 158 { .compatible = "semtech,sx1506q" }, 159 + { .compatible = "semtech,sx1502q" }, 192 160 {}, 193 161 }; 194 162 MODULE_DEVICE_TABLE(of, sx150x_of_match); 195 - 196 - struct sx150x_chip *to_sx150x(struct gpio_chip *gc) 197 - { 198 - return container_of(gc, struct sx150x_chip, gpio_chip); 199 - } 200 163 201 164 static s32 sx150x_i2c_write(struct i2c_client *client, u8 reg, u8 val) 202 165 { ··· 330 301 331 302 static int sx150x_gpio_get(struct gpio_chip *gc, unsigned offset) 332 303 { 333 - struct sx150x_chip *chip = to_sx150x(gc); 304 + struct sx150x_chip *chip = gpiochip_get_data(gc); 334 305 int status = -EINVAL; 335 306 336 307 if (!offset_is_oscio(chip, offset)) { ··· 339 310 mutex_unlock(&chip->lock); 340 311 } 341 312 342 - return status; 313 + return (status < 0) ? status : !!status; 343 314 } 344 315 345 316 static void sx150x_gpio_set(struct gpio_chip *gc, unsigned offset, int val) 346 317 { 347 - struct sx150x_chip *chip = to_sx150x(gc); 318 + struct sx150x_chip *chip = gpiochip_get_data(gc); 348 319 349 320 mutex_lock(&chip->lock); 350 321 if (offset_is_oscio(chip, offset)) ··· 356 327 357 328 static int sx150x_gpio_direction_input(struct gpio_chip *gc, unsigned offset) 358 329 { 359 - struct sx150x_chip *chip = to_sx150x(gc); 330 + struct sx150x_chip *chip = gpiochip_get_data(gc); 360 331 int status = -EINVAL; 361 332 362 333 if (!offset_is_oscio(chip, offset)) { ··· 371 342 unsigned offset, 372 343 int val) 373 344 { 374 - struct sx150x_chip *chip = to_sx150x(gc); 345 + struct sx150x_chip *chip = gpiochip_get_data(gc); 375 346 int status = 0; 376 347 377 348 if (!offset_is_oscio(chip, offset)) { ··· 384 355 385 356 static void sx150x_irq_mask(struct irq_data *d) 386 357 { 387 - struct sx150x_chip *chip = to_sx150x(irq_data_get_irq_chip_data(d)); 358 + struct sx150x_chip *chip = gpiochip_get_data(irq_data_get_irq_chip_data(d)); 388 359 unsigned n = d->hwirq; 389 360 390 361 chip->irq_masked |= (1 << n); ··· 393 364 394 365 static void sx150x_irq_unmask(struct irq_data *d) 395 366 { 396 - struct sx150x_chip *chip = to_sx150x(irq_data_get_irq_chip_data(d)); 367 + struct sx150x_chip *chip = gpiochip_get_data(irq_data_get_irq_chip_data(d)); 397 368 unsigned n = d->hwirq; 398 369 399 370 chip->irq_masked &= ~(1 << n); ··· 402 373 403 374 static int sx150x_irq_set_type(struct irq_data *d, unsigned int flow_type) 404 375 { 405 - struct sx150x_chip *chip = to_sx150x(irq_data_get_irq_chip_data(d)); 376 + struct sx150x_chip *chip = gpiochip_get_data(irq_data_get_irq_chip_data(d)); 406 377 unsigned n, val = 0; 407 378 408 379 if (flow_type & (IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) ··· 457 428 458 429 static void sx150x_irq_bus_lock(struct irq_data *d) 459 430 { 460 - struct sx150x_chip *chip = to_sx150x(irq_data_get_irq_chip_data(d)); 431 + struct sx150x_chip *chip = gpiochip_get_data(irq_data_get_irq_chip_data(d)); 461 432 462 433 mutex_lock(&chip->lock); 463 434 } 464 435 465 436 static void sx150x_irq_bus_sync_unlock(struct irq_data *d) 466 437 { 467 - struct sx150x_chip *chip = to_sx150x(irq_data_get_irq_chip_data(d)); 438 + struct sx150x_chip *chip = gpiochip_get_data(irq_data_get_irq_chip_data(d)); 468 439 unsigned n; 469 440 470 441 if (chip->irq_update == NO_UPDATE_PENDING) ··· 502 473 503 474 chip->client = client; 504 475 chip->dev_cfg = &sx150x_devices[driver_data]; 505 - chip->gpio_chip.dev = &client->dev; 476 + chip->gpio_chip.parent = &client->dev; 506 477 chip->gpio_chip.label = client->name; 507 478 chip->gpio_chip.direction_input = sx150x_gpio_direction_input; 508 479 chip->gpio_chip.direction_output = sx150x_gpio_direction_output; ··· 574 545 err = sx150x_i2c_write(chip->client, 575 546 chip->dev_cfg->pri.x789.reg_misc, 576 547 0x01); 577 - else 548 + else if (chip->dev_cfg->model == SX150X_456) 578 549 err = sx150x_i2c_write(chip->client, 579 550 chip->dev_cfg->pri.x456.reg_advance, 580 551 0x04); 552 + else 553 + err = sx150x_i2c_write(chip->client, 554 + chip->dev_cfg->pri.x123.reg_advance, 555 + 0x00); 581 556 if (err < 0) 582 557 return err; 583 558 ··· 607 574 pdata->io_polarity); 608 575 if (err < 0) 609 576 return err; 610 - } else { 577 + } else if (chip->dev_cfg->model == SX150X_456) { 611 578 /* Set all pins to work in normal mode */ 612 579 err = sx150x_init_io(chip, 613 580 chip->dev_cfg->pri.x456.reg_pld_mode, 581 + 0); 582 + if (err < 0) 583 + return err; 584 + } else { 585 + /* Set all pins to work in normal mode */ 586 + err = sx150x_init_io(chip, 587 + chip->dev_cfg->pri.x123.reg_pld_mode, 614 588 0); 615 589 if (err < 0) 616 590 return err; ··· 687 647 if (rc < 0) 688 648 return rc; 689 649 690 - rc = gpiochip_add(&chip->gpio_chip); 650 + rc = gpiochip_add_data(&chip->gpio_chip, chip); 691 651 if (rc) 692 652 return rc; 693 653 ··· 720 680 static struct i2c_driver sx150x_driver = { 721 681 .driver = { 722 682 .name = "sx150x", 723 - .owner = THIS_MODULE, 724 683 .of_match_table = of_match_ptr(sx150x_of_match), 725 684 }, 726 685 .probe = sx150x_probe,
+8 -13
drivers/gpio/gpio-syscon.c
··· 59 59 u32 dir_reg_offset; 60 60 }; 61 61 62 - static inline struct syscon_gpio_priv *to_syscon_gpio(struct gpio_chip *chip) 63 - { 64 - return container_of(chip, struct syscon_gpio_priv, chip); 65 - } 66 - 67 62 static int syscon_gpio_get(struct gpio_chip *chip, unsigned offset) 68 63 { 69 - struct syscon_gpio_priv *priv = to_syscon_gpio(chip); 64 + struct syscon_gpio_priv *priv = gpiochip_get_data(chip); 70 65 unsigned int val, offs; 71 66 int ret; 72 67 ··· 77 82 78 83 static void syscon_gpio_set(struct gpio_chip *chip, unsigned offset, int val) 79 84 { 80 - struct syscon_gpio_priv *priv = to_syscon_gpio(chip); 85 + struct syscon_gpio_priv *priv = gpiochip_get_data(chip); 81 86 unsigned int offs; 82 87 83 88 offs = priv->dreg_offset + priv->data->dat_bit_offset + offset; ··· 90 95 91 96 static int syscon_gpio_dir_in(struct gpio_chip *chip, unsigned offset) 92 97 { 93 - struct syscon_gpio_priv *priv = to_syscon_gpio(chip); 98 + struct syscon_gpio_priv *priv = gpiochip_get_data(chip); 94 99 95 100 if (priv->data->flags & GPIO_SYSCON_FEAT_DIR) { 96 101 unsigned int offs; ··· 108 113 109 114 static int syscon_gpio_dir_out(struct gpio_chip *chip, unsigned offset, int val) 110 115 { 111 - struct syscon_gpio_priv *priv = to_syscon_gpio(chip); 116 + struct syscon_gpio_priv *priv = gpiochip_get_data(chip); 112 117 113 118 if (priv->data->flags & GPIO_SYSCON_FEAT_DIR) { 114 119 unsigned int offs; ··· 139 144 140 145 static void keystone_gpio_set(struct gpio_chip *chip, unsigned offset, int val) 141 146 { 142 - struct syscon_gpio_priv *priv = to_syscon_gpio(chip); 147 + struct syscon_gpio_priv *priv = gpiochip_get_data(chip); 143 148 unsigned int offs; 144 149 int ret; 145 150 ··· 154 159 BIT(offs % SYSCON_REG_BITS) | KEYSTONE_LOCK_BIT, 155 160 BIT(offs % SYSCON_REG_BITS) | KEYSTONE_LOCK_BIT); 156 161 if (ret < 0) 157 - dev_err(chip->dev, "gpio write failed ret(%d)\n", ret); 162 + dev_err(chip->parent, "gpio write failed ret(%d)\n", ret); 158 163 } 159 164 160 165 static const struct syscon_gpio_data keystone_dsp_gpio = { ··· 223 228 priv->dir_reg_offset <<= 3; 224 229 } 225 230 226 - priv->chip.dev = dev; 231 + priv->chip.parent = dev; 227 232 priv->chip.owner = THIS_MODULE; 228 233 priv->chip.label = dev_name(dev); 229 234 priv->chip.base = -1; ··· 238 243 239 244 platform_set_drvdata(pdev, priv); 240 245 241 - return gpiochip_add(&priv->chip); 246 + return gpiochip_add_data(&priv->chip, priv); 242 247 } 243 248 244 249 static int syscon_gpio_remove(struct platform_device *pdev)
+7 -12
drivers/gpio/gpio-tb10x.c
··· 87 87 spin_unlock_irqrestore(&gpio->spinlock, flags); 88 88 } 89 89 90 - static inline struct tb10x_gpio *to_tb10x_gpio(struct gpio_chip *chip) 91 - { 92 - return container_of(chip, struct tb10x_gpio, gc); 93 - } 94 - 95 90 static int tb10x_gpio_direction_in(struct gpio_chip *chip, unsigned offset) 96 91 { 97 - struct tb10x_gpio *tb10x_gpio = to_tb10x_gpio(chip); 92 + struct tb10x_gpio *tb10x_gpio = gpiochip_get_data(chip); 98 93 int mask = BIT(offset); 99 94 int val = TB10X_GPIO_DIR_IN << offset; 100 95 ··· 100 105 101 106 static int tb10x_gpio_get(struct gpio_chip *chip, unsigned offset) 102 107 { 103 - struct tb10x_gpio *tb10x_gpio = to_tb10x_gpio(chip); 108 + struct tb10x_gpio *tb10x_gpio = gpiochip_get_data(chip); 104 109 int val; 105 110 106 111 val = tb10x_reg_read(tb10x_gpio, OFFSET_TO_REG_DATA); ··· 113 118 114 119 static void tb10x_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 115 120 { 116 - struct tb10x_gpio *tb10x_gpio = to_tb10x_gpio(chip); 121 + struct tb10x_gpio *tb10x_gpio = gpiochip_get_data(chip); 117 122 int mask = BIT(offset); 118 123 int val = value << offset; 119 124 ··· 123 128 static int tb10x_gpio_direction_out(struct gpio_chip *chip, 124 129 unsigned offset, int value) 125 130 { 126 - struct tb10x_gpio *tb10x_gpio = to_tb10x_gpio(chip); 131 + struct tb10x_gpio *tb10x_gpio = gpiochip_get_data(chip); 127 132 int mask = BIT(offset); 128 133 int val = TB10X_GPIO_DIR_OUT << offset; 129 134 ··· 135 140 136 141 static int tb10x_gpio_to_irq(struct gpio_chip *chip, unsigned offset) 137 142 { 138 - struct tb10x_gpio *tb10x_gpio = to_tb10x_gpio(chip); 143 + struct tb10x_gpio *tb10x_gpio = gpiochip_get_data(chip); 139 144 140 145 return irq_create_mapping(tb10x_gpio->domain, offset); 141 146 } ··· 192 197 return PTR_ERR(tb10x_gpio->base); 193 198 194 199 tb10x_gpio->gc.label = of_node_full_name(dn); 195 - tb10x_gpio->gc.dev = &pdev->dev; 200 + tb10x_gpio->gc.parent = &pdev->dev; 196 201 tb10x_gpio->gc.owner = THIS_MODULE; 197 202 tb10x_gpio->gc.direction_input = tb10x_gpio_direction_in; 198 203 tb10x_gpio->gc.get = tb10x_gpio_get; ··· 205 210 tb10x_gpio->gc.can_sleep = false; 206 211 207 212 208 - ret = gpiochip_add(&tb10x_gpio->gc); 213 + ret = gpiochip_add_data(&tb10x_gpio->gc, tb10x_gpio); 209 214 if (ret < 0) { 210 215 dev_err(&pdev->dev, "Could not add gpiochip.\n"); 211 216 goto fail_gpiochip_registration;
+12 -17
drivers/gpio/gpio-tc3589x.c
··· 34 34 u8 oldregs[CACHE_NR_REGS][CACHE_NR_BANKS]; 35 35 }; 36 36 37 - static inline struct tc3589x_gpio *to_tc3589x_gpio(struct gpio_chip *chip) 38 - { 39 - return container_of(chip, struct tc3589x_gpio, chip); 40 - } 41 - 42 37 static int tc3589x_gpio_get(struct gpio_chip *chip, unsigned offset) 43 38 { 44 - struct tc3589x_gpio *tc3589x_gpio = to_tc3589x_gpio(chip); 39 + struct tc3589x_gpio *tc3589x_gpio = gpiochip_get_data(chip); 45 40 struct tc3589x *tc3589x = tc3589x_gpio->tc3589x; 46 41 u8 reg = TC3589x_GPIODATA0 + (offset / 8) * 2; 47 42 u8 mask = 1 << (offset % 8); ··· 46 51 if (ret < 0) 47 52 return ret; 48 53 49 - return ret & mask; 54 + return !!(ret & mask); 50 55 } 51 56 52 57 static void tc3589x_gpio_set(struct gpio_chip *chip, unsigned offset, int val) 53 58 { 54 - struct tc3589x_gpio *tc3589x_gpio = to_tc3589x_gpio(chip); 59 + struct tc3589x_gpio *tc3589x_gpio = gpiochip_get_data(chip); 55 60 struct tc3589x *tc3589x = tc3589x_gpio->tc3589x; 56 61 u8 reg = TC3589x_GPIODATA0 + (offset / 8) * 2; 57 62 unsigned pos = offset % 8; ··· 63 68 static int tc3589x_gpio_direction_output(struct gpio_chip *chip, 64 69 unsigned offset, int val) 65 70 { 66 - struct tc3589x_gpio *tc3589x_gpio = to_tc3589x_gpio(chip); 71 + struct tc3589x_gpio *tc3589x_gpio = gpiochip_get_data(chip); 67 72 struct tc3589x *tc3589x = tc3589x_gpio->tc3589x; 68 73 u8 reg = TC3589x_GPIODIR0 + offset / 8; 69 74 unsigned pos = offset % 8; ··· 76 81 static int tc3589x_gpio_direction_input(struct gpio_chip *chip, 77 82 unsigned offset) 78 83 { 79 - struct tc3589x_gpio *tc3589x_gpio = to_tc3589x_gpio(chip); 84 + struct tc3589x_gpio *tc3589x_gpio = gpiochip_get_data(chip); 80 85 struct tc3589x *tc3589x = tc3589x_gpio->tc3589x; 81 86 u8 reg = TC3589x_GPIODIR0 + offset / 8; 82 87 unsigned pos = offset % 8; ··· 97 102 static int tc3589x_gpio_irq_set_type(struct irq_data *d, unsigned int type) 98 103 { 99 104 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 100 - struct tc3589x_gpio *tc3589x_gpio = to_tc3589x_gpio(gc); 105 + struct tc3589x_gpio *tc3589x_gpio = gpiochip_get_data(gc); 101 106 int offset = d->hwirq; 102 107 int regoffset = offset / 8; 103 108 int mask = 1 << (offset % 8); ··· 125 130 static void tc3589x_gpio_irq_lock(struct irq_data *d) 126 131 { 127 132 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 128 - struct tc3589x_gpio *tc3589x_gpio = to_tc3589x_gpio(gc); 133 + struct tc3589x_gpio *tc3589x_gpio = gpiochip_get_data(gc); 129 134 130 135 mutex_lock(&tc3589x_gpio->irq_lock); 131 136 } ··· 133 138 static void tc3589x_gpio_irq_sync_unlock(struct irq_data *d) 134 139 { 135 140 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 136 - struct tc3589x_gpio *tc3589x_gpio = to_tc3589x_gpio(gc); 141 + struct tc3589x_gpio *tc3589x_gpio = gpiochip_get_data(gc); 137 142 struct tc3589x *tc3589x = tc3589x_gpio->tc3589x; 138 143 static const u8 regmap[] = { 139 144 [REG_IBE] = TC3589x_GPIOIBE0, ··· 162 167 static void tc3589x_gpio_irq_mask(struct irq_data *d) 163 168 { 164 169 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 165 - struct tc3589x_gpio *tc3589x_gpio = to_tc3589x_gpio(gc); 170 + struct tc3589x_gpio *tc3589x_gpio = gpiochip_get_data(gc); 166 171 int offset = d->hwirq; 167 172 int regoffset = offset / 8; 168 173 int mask = 1 << (offset % 8); ··· 173 178 static void tc3589x_gpio_irq_unmask(struct irq_data *d) 174 179 { 175 180 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 176 - struct tc3589x_gpio *tc3589x_gpio = to_tc3589x_gpio(gc); 181 + struct tc3589x_gpio *tc3589x_gpio = gpiochip_get_data(gc); 177 182 int offset = d->hwirq; 178 183 int regoffset = offset / 8; 179 184 int mask = 1 << (offset % 8); ··· 253 258 254 259 tc3589x_gpio->chip = template_chip; 255 260 tc3589x_gpio->chip.ngpio = tc3589x->num_gpio; 256 - tc3589x_gpio->chip.dev = &pdev->dev; 261 + tc3589x_gpio->chip.parent = &pdev->dev; 257 262 tc3589x_gpio->chip.base = -1; 258 263 tc3589x_gpio->chip.of_node = np; 259 264 ··· 272 277 return ret; 273 278 } 274 279 275 - ret = gpiochip_add(&tc3589x_gpio->chip); 280 + ret = gpiochip_add_data(&tc3589x_gpio->chip, tc3589x_gpio); 276 281 if (ret) { 277 282 dev_err(&pdev->dev, "unable to add gpiochip: %d\n", ret); 278 283 return ret;
+1 -1
drivers/gpio/gpio-tegra.c
··· 545 545 546 546 tegra_gpio_chip.of_node = pdev->dev.of_node; 547 547 548 - ret = gpiochip_add(&tegra_gpio_chip); 548 + ret = gpiochip_add_data(&tegra_gpio_chip, NULL); 549 549 if (ret < 0) { 550 550 irq_domain_remove(irq_domain); 551 551 return ret;
+5 -5
drivers/gpio/gpio-timberdale.c
··· 53 53 static int timbgpio_update_bit(struct gpio_chip *gpio, unsigned index, 54 54 unsigned offset, bool enabled) 55 55 { 56 - struct timbgpio *tgpio = container_of(gpio, struct timbgpio, gpio); 56 + struct timbgpio *tgpio = gpiochip_get_data(gpio); 57 57 u32 reg; 58 58 59 59 spin_lock(&tgpio->lock); ··· 77 77 78 78 static int timbgpio_gpio_get(struct gpio_chip *gpio, unsigned nr) 79 79 { 80 - struct timbgpio *tgpio = container_of(gpio, struct timbgpio, gpio); 80 + struct timbgpio *tgpio = gpiochip_get_data(gpio); 81 81 u32 value; 82 82 83 83 value = ioread32(tgpio->membase + TGPIOVAL); ··· 98 98 99 99 static int timbgpio_to_irq(struct gpio_chip *gpio, unsigned offset) 100 100 { 101 - struct timbgpio *tgpio = container_of(gpio, struct timbgpio, gpio); 101 + struct timbgpio *tgpio = gpiochip_get_data(gpio); 102 102 103 103 if (tgpio->irq_base <= 0) 104 104 return -EINVAL; ··· 268 268 269 269 gc->label = dev_name(&pdev->dev); 270 270 gc->owner = THIS_MODULE; 271 - gc->dev = &pdev->dev; 271 + gc->parent = &pdev->dev; 272 272 gc->direction_input = timbgpio_gpio_direction_input; 273 273 gc->get = timbgpio_gpio_get; 274 274 gc->direction_output = timbgpio_gpio_direction_output; ··· 279 279 gc->ngpio = pdata->nr_pins; 280 280 gc->can_sleep = false; 281 281 282 - err = gpiochip_add(gc); 282 + err = gpiochip_add_data(gc, tgpio); 283 283 if (err) 284 284 return err; 285 285
+6 -11
drivers/gpio/gpio-tps6586x.c
··· 38 38 struct device *parent; 39 39 }; 40 40 41 - static inline struct tps6586x_gpio *to_tps6586x_gpio(struct gpio_chip *chip) 42 - { 43 - return container_of(chip, struct tps6586x_gpio, gpio_chip); 44 - } 45 - 46 41 static int tps6586x_gpio_get(struct gpio_chip *gc, unsigned offset) 47 42 { 48 - struct tps6586x_gpio *tps6586x_gpio = to_tps6586x_gpio(gc); 43 + struct tps6586x_gpio *tps6586x_gpio = gpiochip_get_data(gc); 49 44 uint8_t val; 50 45 int ret; 51 46 ··· 54 59 static void tps6586x_gpio_set(struct gpio_chip *gc, unsigned offset, 55 60 int value) 56 61 { 57 - struct tps6586x_gpio *tps6586x_gpio = to_tps6586x_gpio(gc); 62 + struct tps6586x_gpio *tps6586x_gpio = gpiochip_get_data(gc); 58 63 59 64 tps6586x_update(tps6586x_gpio->parent, TPS6586X_GPIOSET2, 60 65 value << offset, 1 << offset); ··· 63 68 static int tps6586x_gpio_output(struct gpio_chip *gc, unsigned offset, 64 69 int value) 65 70 { 66 - struct tps6586x_gpio *tps6586x_gpio = to_tps6586x_gpio(gc); 71 + struct tps6586x_gpio *tps6586x_gpio = gpiochip_get_data(gc); 67 72 uint8_t val, mask; 68 73 69 74 tps6586x_gpio_set(gc, offset, value); ··· 77 82 78 83 static int tps6586x_gpio_to_irq(struct gpio_chip *gc, unsigned offset) 79 84 { 80 - struct tps6586x_gpio *tps6586x_gpio = to_tps6586x_gpio(gc); 85 + struct tps6586x_gpio *tps6586x_gpio = gpiochip_get_data(gc); 81 86 82 87 return tps6586x_irq_get_virq(tps6586x_gpio->parent, 83 88 TPS6586X_INT_PLDO_0 + offset); ··· 99 104 100 105 tps6586x_gpio->gpio_chip.owner = THIS_MODULE; 101 106 tps6586x_gpio->gpio_chip.label = pdev->name; 102 - tps6586x_gpio->gpio_chip.dev = &pdev->dev; 107 + tps6586x_gpio->gpio_chip.parent = &pdev->dev; 103 108 tps6586x_gpio->gpio_chip.ngpio = 4; 104 109 tps6586x_gpio->gpio_chip.can_sleep = true; 105 110 ··· 117 122 else 118 123 tps6586x_gpio->gpio_chip.base = -1; 119 124 120 - ret = gpiochip_add(&tps6586x_gpio->gpio_chip); 125 + ret = gpiochip_add_data(&tps6586x_gpio->gpio_chip, tps6586x_gpio); 121 126 if (ret < 0) { 122 127 dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret); 123 128 return ret;
+6 -11
drivers/gpio/gpio-tps65910.c
··· 27 27 struct tps65910 *tps65910; 28 28 }; 29 29 30 - static inline struct tps65910_gpio *to_tps65910_gpio(struct gpio_chip *chip) 31 - { 32 - return container_of(chip, struct tps65910_gpio, gpio_chip); 33 - } 34 - 35 30 static int tps65910_gpio_get(struct gpio_chip *gc, unsigned offset) 36 31 { 37 - struct tps65910_gpio *tps65910_gpio = to_tps65910_gpio(gc); 32 + struct tps65910_gpio *tps65910_gpio = gpiochip_get_data(gc); 38 33 struct tps65910 *tps65910 = tps65910_gpio->tps65910; 39 34 unsigned int val; 40 35 ··· 44 49 static void tps65910_gpio_set(struct gpio_chip *gc, unsigned offset, 45 50 int value) 46 51 { 47 - struct tps65910_gpio *tps65910_gpio = to_tps65910_gpio(gc); 52 + struct tps65910_gpio *tps65910_gpio = gpiochip_get_data(gc); 48 53 struct tps65910 *tps65910 = tps65910_gpio->tps65910; 49 54 50 55 if (value) ··· 58 63 static int tps65910_gpio_output(struct gpio_chip *gc, unsigned offset, 59 64 int value) 60 65 { 61 - struct tps65910_gpio *tps65910_gpio = to_tps65910_gpio(gc); 66 + struct tps65910_gpio *tps65910_gpio = gpiochip_get_data(gc); 62 67 struct tps65910 *tps65910 = tps65910_gpio->tps65910; 63 68 64 69 /* Set the initial value */ ··· 70 75 71 76 static int tps65910_gpio_input(struct gpio_chip *gc, unsigned offset) 72 77 { 73 - struct tps65910_gpio *tps65910_gpio = to_tps65910_gpio(gc); 78 + struct tps65910_gpio *tps65910_gpio = gpiochip_get_data(gc); 74 79 struct tps65910 *tps65910 = tps65910_gpio->tps65910; 75 80 76 81 return tps65910_reg_clear_bits(tps65910, TPS65910_GPIO0 + offset, ··· 141 146 tps65910_gpio->gpio_chip.direction_output = tps65910_gpio_output; 142 147 tps65910_gpio->gpio_chip.set = tps65910_gpio_set; 143 148 tps65910_gpio->gpio_chip.get = tps65910_gpio_get; 144 - tps65910_gpio->gpio_chip.dev = &pdev->dev; 149 + tps65910_gpio->gpio_chip.parent = &pdev->dev; 145 150 #ifdef CONFIG_OF_GPIO 146 151 tps65910_gpio->gpio_chip.of_node = tps65910->dev->of_node; 147 152 #endif ··· 170 175 } 171 176 172 177 skip_init: 173 - ret = gpiochip_add(&tps65910_gpio->gpio_chip); 178 + ret = gpiochip_add_data(&tps65910_gpio->gpio_chip, tps65910_gpio); 174 179 if (ret < 0) { 175 180 dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret); 176 181 return ret;
+6 -8
drivers/gpio/gpio-tps65912.c
··· 26 26 struct gpio_chip gpio_chip; 27 27 }; 28 28 29 - #define to_tgd(gc) container_of(gc, struct tps65912_gpio_data, gpio_chip) 30 - 31 29 static int tps65912_gpio_get(struct gpio_chip *gc, unsigned offset) 32 30 { 33 - struct tps65912_gpio_data *tps65912_gpio = to_tgd(gc); 31 + struct tps65912_gpio_data *tps65912_gpio = gpiochip_get_data(gc); 34 32 struct tps65912 *tps65912 = tps65912_gpio->tps65912; 35 33 int val; 36 34 ··· 43 45 static void tps65912_gpio_set(struct gpio_chip *gc, unsigned offset, 44 46 int value) 45 47 { 46 - struct tps65912_gpio_data *tps65912_gpio = to_tgd(gc); 48 + struct tps65912_gpio_data *tps65912_gpio = gpiochip_get_data(gc); 47 49 struct tps65912 *tps65912 = tps65912_gpio->tps65912; 48 50 49 51 if (value) ··· 57 59 static int tps65912_gpio_output(struct gpio_chip *gc, unsigned offset, 58 60 int value) 59 61 { 60 - struct tps65912_gpio_data *tps65912_gpio = to_tgd(gc); 62 + struct tps65912_gpio_data *tps65912_gpio = gpiochip_get_data(gc); 61 63 struct tps65912 *tps65912 = tps65912_gpio->tps65912; 62 64 63 65 /* Set the initial value */ ··· 69 71 70 72 static int tps65912_gpio_input(struct gpio_chip *gc, unsigned offset) 71 73 { 72 - struct tps65912_gpio_data *tps65912_gpio = to_tgd(gc); 74 + struct tps65912_gpio_data *tps65912_gpio = gpiochip_get_data(gc); 73 75 struct tps65912 *tps65912 = tps65912_gpio->tps65912; 74 76 75 77 return tps65912_clear_bits(tps65912, TPS65912_GPIO1 + offset, ··· 102 104 103 105 tps65912_gpio->tps65912 = tps65912; 104 106 tps65912_gpio->gpio_chip = template_chip; 105 - tps65912_gpio->gpio_chip.dev = &pdev->dev; 107 + tps65912_gpio->gpio_chip.parent = &pdev->dev; 106 108 if (pdata && pdata->gpio_base) 107 109 tps65912_gpio->gpio_chip.base = pdata->gpio_base; 108 110 109 - ret = gpiochip_add(&tps65912_gpio->gpio_chip); 111 + ret = gpiochip_add_data(&tps65912_gpio->gpio_chip, tps65912_gpio); 110 112 if (ret < 0) { 111 113 dev_err(&pdev->dev, "Failed to register gpiochip, %d\n", ret); 112 114 return ret;
+9 -13
drivers/gpio/gpio-ts5500.c
··· 185 185 TS5500_DIO_IN_IRQ(0x73, 7, 1), 186 186 }; 187 187 188 - static inline struct ts5500_priv *ts5500_gc_to_priv(struct gpio_chip *chip) 189 - { 190 - return container_of(chip, struct ts5500_priv, gpio_chip); 191 - } 192 - 193 188 static inline void ts5500_set_mask(u8 mask, u8 addr) 194 189 { 195 190 u8 val = inb(addr); ··· 201 206 202 207 static int ts5500_gpio_input(struct gpio_chip *chip, unsigned offset) 203 208 { 204 - struct ts5500_priv *priv = ts5500_gc_to_priv(chip); 209 + struct ts5500_priv *priv = gpiochip_get_data(chip); 205 210 const struct ts5500_dio line = priv->pinout[offset]; 206 211 unsigned long flags; 207 212 ··· 220 225 221 226 static int ts5500_gpio_get(struct gpio_chip *chip, unsigned offset) 222 227 { 223 - struct ts5500_priv *priv = ts5500_gc_to_priv(chip); 228 + struct ts5500_priv *priv = gpiochip_get_data(chip); 224 229 const struct ts5500_dio line = priv->pinout[offset]; 225 230 226 231 return !!(inb(line.value_addr) & line.value_mask); ··· 228 233 229 234 static int ts5500_gpio_output(struct gpio_chip *chip, unsigned offset, int val) 230 235 { 231 - struct ts5500_priv *priv = ts5500_gc_to_priv(chip); 236 + struct ts5500_priv *priv = gpiochip_get_data(chip); 232 237 const struct ts5500_dio line = priv->pinout[offset]; 233 238 unsigned long flags; 234 239 ··· 250 255 251 256 static void ts5500_gpio_set(struct gpio_chip *chip, unsigned offset, int val) 252 257 { 253 - struct ts5500_priv *priv = ts5500_gc_to_priv(chip); 258 + struct ts5500_priv *priv = gpiochip_get_data(chip); 254 259 const struct ts5500_dio line = priv->pinout[offset]; 255 260 unsigned long flags; 256 261 ··· 264 269 265 270 static int ts5500_gpio_to_irq(struct gpio_chip *chip, unsigned offset) 266 271 { 267 - struct ts5500_priv *priv = ts5500_gc_to_priv(chip); 272 + struct ts5500_priv *priv = gpiochip_get_data(chip); 268 273 const struct ts5500_dio *block = priv->pinout; 269 274 const struct ts5500_dio line = block[offset]; 270 275 ··· 310 315 else if (priv->hwirq == 1) 311 316 ts5500_clear_mask(BIT(6), 0x7d); /* LCD_RS on IRQ1 */ 312 317 else 313 - dev_err(priv->gpio_chip.dev, "invalid hwirq %d\n", priv->hwirq); 318 + dev_err(priv->gpio_chip.parent, "invalid hwirq %d\n", 319 + priv->hwirq); 314 320 spin_unlock_irqrestore(&priv->lock, flags); 315 321 } 316 322 ··· 342 346 343 347 priv->gpio_chip.owner = THIS_MODULE; 344 348 priv->gpio_chip.label = name; 345 - priv->gpio_chip.dev = dev; 349 + priv->gpio_chip.parent = dev; 346 350 priv->gpio_chip.direction_input = ts5500_gpio_input; 347 351 priv->gpio_chip.direction_output = ts5500_gpio_output; 348 352 priv->gpio_chip.get = ts5500_gpio_get; ··· 409 413 break; 410 414 } 411 415 412 - ret = gpiochip_add(&priv->gpio_chip); 416 + ret = gpiochip_add_data(&priv->gpio_chip, priv); 413 417 if (ret) { 414 418 dev_err(dev, "failed to register the gpio chip\n"); 415 419 return ret;
+11 -16
drivers/gpio/gpio-twl4030.c
··· 76 76 77 77 /*----------------------------------------------------------------------*/ 78 78 79 - static inline struct gpio_twl4030_priv *to_gpio_twl4030(struct gpio_chip *chip) 80 - { 81 - return container_of(chip, struct gpio_twl4030_priv, gpio_chip); 82 - } 83 - 84 79 /* 85 80 * To configure TWL4030 GPIO module registers 86 81 */ ··· 200 205 201 206 static int twl_request(struct gpio_chip *chip, unsigned offset) 202 207 { 203 - struct gpio_twl4030_priv *priv = to_gpio_twl4030(chip); 208 + struct gpio_twl4030_priv *priv = gpiochip_get_data(chip); 204 209 int status = 0; 205 210 206 211 mutex_lock(&priv->mutex); ··· 251 256 /* optionally have the first two GPIOs switch vMMC1 252 257 * and vMMC2 power supplies based on card presence. 253 258 */ 254 - pdata = dev_get_platdata(chip->dev); 259 + pdata = dev_get_platdata(chip->parent); 255 260 if (pdata) 256 261 value |= pdata->mmc_cd & 0x03; 257 262 ··· 268 273 269 274 static void twl_free(struct gpio_chip *chip, unsigned offset) 270 275 { 271 - struct gpio_twl4030_priv *priv = to_gpio_twl4030(chip); 276 + struct gpio_twl4030_priv *priv = gpiochip_get_data(chip); 272 277 273 278 mutex_lock(&priv->mutex); 274 279 if (offset >= TWL4030_GPIO_MAX) { ··· 288 293 289 294 static int twl_direction_in(struct gpio_chip *chip, unsigned offset) 290 295 { 291 - struct gpio_twl4030_priv *priv = to_gpio_twl4030(chip); 296 + struct gpio_twl4030_priv *priv = gpiochip_get_data(chip); 292 297 int ret; 293 298 294 299 mutex_lock(&priv->mutex); ··· 307 312 308 313 static int twl_get(struct gpio_chip *chip, unsigned offset) 309 314 { 310 - struct gpio_twl4030_priv *priv = to_gpio_twl4030(chip); 315 + struct gpio_twl4030_priv *priv = gpiochip_get_data(chip); 311 316 int ret; 312 317 int status = 0; 313 318 ··· 322 327 else 323 328 status = twl4030_get_gpio_datain(offset); 324 329 325 - ret = (status <= 0) ? 0 : 1; 330 + ret = (status < 0) ? status : !!status; 326 331 out: 327 332 mutex_unlock(&priv->mutex); 328 333 return ret; ··· 330 335 331 336 static void twl_set(struct gpio_chip *chip, unsigned offset, int value) 332 337 { 333 - struct gpio_twl4030_priv *priv = to_gpio_twl4030(chip); 338 + struct gpio_twl4030_priv *priv = gpiochip_get_data(chip); 334 339 335 340 mutex_lock(&priv->mutex); 336 341 if (offset < TWL4030_GPIO_MAX) ··· 348 353 349 354 static int twl_direction_out(struct gpio_chip *chip, unsigned offset, int value) 350 355 { 351 - struct gpio_twl4030_priv *priv = to_gpio_twl4030(chip); 356 + struct gpio_twl4030_priv *priv = gpiochip_get_data(chip); 352 357 int ret = 0; 353 358 354 359 mutex_lock(&priv->mutex); ··· 374 379 375 380 static int twl_to_irq(struct gpio_chip *chip, unsigned offset) 376 381 { 377 - struct gpio_twl4030_priv *priv = to_gpio_twl4030(chip); 382 + struct gpio_twl4030_priv *priv = gpiochip_get_data(chip); 378 383 379 384 return (priv->irq_base && (offset < TWL4030_GPIO_MAX)) 380 385 ? (priv->irq_base + offset) ··· 504 509 priv->gpio_chip = template_chip; 505 510 priv->gpio_chip.base = -1; 506 511 priv->gpio_chip.ngpio = TWL4030_GPIO_MAX; 507 - priv->gpio_chip.dev = &pdev->dev; 512 + priv->gpio_chip.parent = &pdev->dev; 508 513 509 514 mutex_init(&priv->mutex); 510 515 ··· 539 544 if (pdata->use_leds) 540 545 priv->gpio_chip.ngpio += 2; 541 546 542 - ret = gpiochip_add(&priv->gpio_chip); 547 + ret = gpiochip_add_data(&priv->gpio_chip, priv); 543 548 if (ret < 0) { 544 549 dev_err(&pdev->dev, "could not register gpiochip, %d\n", ret); 545 550 priv->gpio_chip.ngpio = 0;
+4 -4
drivers/gpio/gpio-twl6040.c
··· 36 36 37 37 static int twl6040gpo_get(struct gpio_chip *chip, unsigned offset) 38 38 { 39 - struct twl6040 *twl6040 = dev_get_drvdata(chip->dev->parent); 39 + struct twl6040 *twl6040 = dev_get_drvdata(chip->parent->parent); 40 40 int ret = 0; 41 41 42 42 ret = twl6040_reg_read(twl6040, TWL6040_REG_GPOCTL); ··· 55 55 56 56 static void twl6040gpo_set(struct gpio_chip *chip, unsigned offset, int value) 57 57 { 58 - struct twl6040 *twl6040 = dev_get_drvdata(chip->dev->parent); 58 + struct twl6040 *twl6040 = dev_get_drvdata(chip->parent->parent); 59 59 int ret; 60 60 u8 gpoctl; 61 61 ··· 95 95 else 96 96 twl6040gpo_chip.ngpio = 1; /* twl6041 have 1 GPO */ 97 97 98 - twl6040gpo_chip.dev = &pdev->dev; 98 + twl6040gpo_chip.parent = &pdev->dev; 99 99 #ifdef CONFIG_OF_GPIO 100 100 twl6040gpo_chip.of_node = twl6040_core_dev->of_node; 101 101 #endif 102 102 103 - ret = gpiochip_add(&twl6040gpo_chip); 103 + ret = gpiochip_add_data(&twl6040gpo_chip, NULL); 104 104 if (ret < 0) { 105 105 dev_err(&pdev->dev, "could not register gpiochip, %d\n", ret); 106 106 twl6040gpo_chip.ngpio = 0;
+8 -9
drivers/gpio/gpio-tz1090-pdc.c
··· 49 49 void __iomem *reg; 50 50 int irq[GPIO_PDC_NIRQ]; 51 51 }; 52 - #define to_pdc(c) container_of(c, struct tz1090_pdc_gpio, chip) 53 52 54 53 /* Register accesses into the PDC MMIO area */ 55 54 ··· 69 70 static int tz1090_pdc_gpio_direction_input(struct gpio_chip *chip, 70 71 unsigned int offset) 71 72 { 72 - struct tz1090_pdc_gpio *priv = to_pdc(chip); 73 + struct tz1090_pdc_gpio *priv = gpiochip_get_data(chip); 73 74 u32 value; 74 75 int lstat; 75 76 ··· 86 87 unsigned int offset, 87 88 int output_value) 88 89 { 89 - struct tz1090_pdc_gpio *priv = to_pdc(chip); 90 + struct tz1090_pdc_gpio *priv = gpiochip_get_data(chip); 90 91 u32 value; 91 92 int lstat; 92 93 ··· 111 112 112 113 static int tz1090_pdc_gpio_get(struct gpio_chip *chip, unsigned int offset) 113 114 { 114 - struct tz1090_pdc_gpio *priv = to_pdc(chip); 115 - return pdc_read(priv, REG_SOC_GPIO_STATUS) & BIT(offset); 115 + struct tz1090_pdc_gpio *priv = gpiochip_get_data(chip); 116 + return !!(pdc_read(priv, REG_SOC_GPIO_STATUS) & BIT(offset)); 116 117 } 117 118 118 119 static void tz1090_pdc_gpio_set(struct gpio_chip *chip, unsigned int offset, 119 120 int output_value) 120 121 { 121 - struct tz1090_pdc_gpio *priv = to_pdc(chip); 122 + struct tz1090_pdc_gpio *priv = gpiochip_get_data(chip); 122 123 u32 value; 123 124 int lstat; 124 125 ··· 138 139 139 140 static int tz1090_pdc_gpio_to_irq(struct gpio_chip *chip, unsigned int offset) 140 141 { 141 - struct tz1090_pdc_gpio *priv = to_pdc(chip); 142 + struct tz1090_pdc_gpio *priv = gpiochip_get_data(chip); 142 143 unsigned int syswake = offset - GPIO_PDC_IRQ_FIRST; 143 144 int irq; 144 145 ··· 187 188 188 189 /* Set up GPIO chip */ 189 190 priv->chip.label = "tz1090-pdc-gpio"; 190 - priv->chip.dev = &pdev->dev; 191 + priv->chip.parent = &pdev->dev; 191 192 priv->chip.direction_input = tz1090_pdc_gpio_direction_input; 192 193 priv->chip.direction_output = tz1090_pdc_gpio_direction_output; 193 194 priv->chip.get = tz1090_pdc_gpio_get; ··· 206 207 priv->irq[i] = irq_of_parse_and_map(np, i); 207 208 208 209 /* Add the GPIO bank */ 209 - gpiochip_add(&priv->chip); 210 + gpiochip_add_data(&priv->chip, priv); 210 211 211 212 return 0; 212 213 }
+10 -11
drivers/gpio/gpio-tz1090.c
··· 62 62 int irq; 63 63 char label[16]; 64 64 }; 65 - #define to_bank(c) container_of(c, struct tz1090_gpio_bank, chip) 66 65 67 66 /** 68 67 * struct tz1090_gpio - Overall GPIO device private data ··· 186 187 static int tz1090_gpio_direction_input(struct gpio_chip *chip, 187 188 unsigned int offset) 188 189 { 189 - struct tz1090_gpio_bank *bank = to_bank(chip); 190 + struct tz1090_gpio_bank *bank = gpiochip_get_data(chip); 190 191 tz1090_gpio_set_bit(bank, REG_GPIO_DIR, offset); 191 192 192 193 return 0; ··· 195 196 static int tz1090_gpio_direction_output(struct gpio_chip *chip, 196 197 unsigned int offset, int output_value) 197 198 { 198 - struct tz1090_gpio_bank *bank = to_bank(chip); 199 + struct tz1090_gpio_bank *bank = gpiochip_get_data(chip); 199 200 int lstat; 200 201 201 202 __global_lock2(lstat); ··· 211 212 */ 212 213 static int tz1090_gpio_get(struct gpio_chip *chip, unsigned int offset) 213 214 { 214 - struct tz1090_gpio_bank *bank = to_bank(chip); 215 + struct tz1090_gpio_bank *bank = gpiochip_get_data(chip); 215 216 216 - return tz1090_gpio_read_bit(bank, REG_GPIO_DIN, offset); 217 + return !!tz1090_gpio_read_bit(bank, REG_GPIO_DIN, offset); 217 218 } 218 219 219 220 /* ··· 222 223 static void tz1090_gpio_set(struct gpio_chip *chip, unsigned int offset, 223 224 int output_value) 224 225 { 225 - struct tz1090_gpio_bank *bank = to_bank(chip); 226 + struct tz1090_gpio_bank *bank = gpiochip_get_data(chip); 226 227 227 228 tz1090_gpio_mod_bit(bank, REG_GPIO_DOUT, offset, output_value); 228 229 } 229 230 230 231 static int tz1090_gpio_request(struct gpio_chip *chip, unsigned int offset) 231 232 { 232 - struct tz1090_gpio_bank *bank = to_bank(chip); 233 + struct tz1090_gpio_bank *bank = gpiochip_get_data(chip); 233 234 int ret; 234 235 235 236 ret = pinctrl_request_gpio(chip->base + offset); ··· 244 245 245 246 static void tz1090_gpio_free(struct gpio_chip *chip, unsigned int offset) 246 247 { 247 - struct tz1090_gpio_bank *bank = to_bank(chip); 248 + struct tz1090_gpio_bank *bank = gpiochip_get_data(chip); 248 249 249 250 pinctrl_free_gpio(chip->base + offset); 250 251 ··· 253 254 254 255 static int tz1090_gpio_to_irq(struct gpio_chip *chip, unsigned int offset) 255 256 { 256 - struct tz1090_gpio_bank *bank = to_bank(chip); 257 + struct tz1090_gpio_bank *bank = gpiochip_get_data(chip); 257 258 258 259 if (!bank->domain) 259 260 return -EINVAL; ··· 424 425 snprintf(bank->label, sizeof(bank->label), "tz1090-gpio-%u", 425 426 info->index); 426 427 bank->chip.label = bank->label; 427 - bank->chip.dev = dev; 428 + bank->chip.parent = dev; 428 429 bank->chip.direction_input = tz1090_gpio_direction_input; 429 430 bank->chip.direction_output = tz1090_gpio_direction_output; 430 431 bank->chip.get = tz1090_gpio_get; ··· 439 440 bank->chip.ngpio = 30; 440 441 441 442 /* Add the GPIO bank */ 442 - gpiochip_add(&bank->chip); 443 + gpiochip_add_data(&bank->chip, bank); 443 444 444 445 /* Get the GPIO bank IRQ if provided */ 445 446 bank->irq = irq_of_parse_and_map(np, 0);
+7 -6
drivers/gpio/gpio-ucb1400.c
··· 15 15 static int ucb1400_gpio_dir_in(struct gpio_chip *gc, unsigned off) 16 16 { 17 17 struct ucb1400_gpio *gpio; 18 - gpio = container_of(gc, struct ucb1400_gpio, gc); 18 + gpio = gpiochip_get_data(gc); 19 19 ucb1400_gpio_set_direction(gpio->ac97, off, 0); 20 20 return 0; 21 21 } ··· 23 23 static int ucb1400_gpio_dir_out(struct gpio_chip *gc, unsigned off, int val) 24 24 { 25 25 struct ucb1400_gpio *gpio; 26 - gpio = container_of(gc, struct ucb1400_gpio, gc); 26 + gpio = gpiochip_get_data(gc); 27 27 ucb1400_gpio_set_direction(gpio->ac97, off, 1); 28 28 ucb1400_gpio_set_value(gpio->ac97, off, val); 29 29 return 0; ··· 32 32 static int ucb1400_gpio_get(struct gpio_chip *gc, unsigned off) 33 33 { 34 34 struct ucb1400_gpio *gpio; 35 - gpio = container_of(gc, struct ucb1400_gpio, gc); 36 - return ucb1400_gpio_get_value(gpio->ac97, off); 35 + 36 + gpio = gpiochip_get_data(gc); 37 + return !!ucb1400_gpio_get_value(gpio->ac97, off); 37 38 } 38 39 39 40 static void ucb1400_gpio_set(struct gpio_chip *gc, unsigned off, int val) 40 41 { 41 42 struct ucb1400_gpio *gpio; 42 - gpio = container_of(gc, struct ucb1400_gpio, gc); 43 + gpio = gpiochip_get_data(gc); 43 44 ucb1400_gpio_set_value(gpio->ac97, off, val); 44 45 } 45 46 ··· 67 66 ucb->gc.set = ucb1400_gpio_set; 68 67 ucb->gc.can_sleep = true; 69 68 70 - err = gpiochip_add(&ucb->gc); 69 + err = gpiochip_add_data(&ucb->gc, ucb); 71 70 if (err) 72 71 goto err; 73 72
+10 -15
drivers/gpio/gpio-vf610.c
··· 62 62 63 63 static struct irq_chip vf610_gpio_irq_chip; 64 64 65 - static struct vf610_gpio_port *to_vf610_gp(struct gpio_chip *gc) 66 - { 67 - return container_of(gc, struct vf610_gpio_port, gc); 68 - } 69 - 70 65 static const struct of_device_id vf610_gpio_dt_ids[] = { 71 66 { .compatible = "fsl,vf610-gpio" }, 72 67 { /* sentinel */ } ··· 79 84 80 85 static int vf610_gpio_get(struct gpio_chip *gc, unsigned int gpio) 81 86 { 82 - struct vf610_gpio_port *port = to_vf610_gp(gc); 87 + struct vf610_gpio_port *port = gpiochip_get_data(gc); 83 88 84 89 return !!(vf610_gpio_readl(port->gpio_base + GPIO_PDIR) & BIT(gpio)); 85 90 } 86 91 87 92 static void vf610_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val) 88 93 { 89 - struct vf610_gpio_port *port = to_vf610_gp(gc); 94 + struct vf610_gpio_port *port = gpiochip_get_data(gc); 90 95 unsigned long mask = BIT(gpio); 91 96 92 97 if (val) ··· 111 116 static void vf610_gpio_irq_handler(struct irq_desc *desc) 112 117 { 113 118 struct vf610_gpio_port *port = 114 - to_vf610_gp(irq_desc_get_handler_data(desc)); 119 + gpiochip_get_data(irq_desc_get_handler_data(desc)); 115 120 struct irq_chip *chip = irq_desc_get_chip(desc); 116 121 int pin; 117 122 unsigned long irq_isfr; ··· 132 137 static void vf610_gpio_irq_ack(struct irq_data *d) 133 138 { 134 139 struct vf610_gpio_port *port = 135 - to_vf610_gp(irq_data_get_irq_chip_data(d)); 140 + gpiochip_get_data(irq_data_get_irq_chip_data(d)); 136 141 int gpio = d->hwirq; 137 142 138 143 vf610_gpio_writel(BIT(gpio), port->base + PORT_ISFR); ··· 141 146 static int vf610_gpio_irq_set_type(struct irq_data *d, u32 type) 142 147 { 143 148 struct vf610_gpio_port *port = 144 - to_vf610_gp(irq_data_get_irq_chip_data(d)); 149 + gpiochip_get_data(irq_data_get_irq_chip_data(d)); 145 150 u8 irqc; 146 151 147 152 switch (type) { ··· 177 182 static void vf610_gpio_irq_mask(struct irq_data *d) 178 183 { 179 184 struct vf610_gpio_port *port = 180 - to_vf610_gp(irq_data_get_irq_chip_data(d)); 185 + gpiochip_get_data(irq_data_get_irq_chip_data(d)); 181 186 void __iomem *pcr_base = port->base + PORT_PCR(d->hwirq); 182 187 183 188 vf610_gpio_writel(0, pcr_base); ··· 186 191 static void vf610_gpio_irq_unmask(struct irq_data *d) 187 192 { 188 193 struct vf610_gpio_port *port = 189 - to_vf610_gp(irq_data_get_irq_chip_data(d)); 194 + gpiochip_get_data(irq_data_get_irq_chip_data(d)); 190 195 void __iomem *pcr_base = port->base + PORT_PCR(d->hwirq); 191 196 192 197 vf610_gpio_writel(port->irqc[d->hwirq] << PORT_PCR_IRQC_OFFSET, ··· 196 201 static int vf610_gpio_irq_set_wake(struct irq_data *d, u32 enable) 197 202 { 198 203 struct vf610_gpio_port *port = 199 - to_vf610_gp(irq_data_get_irq_chip_data(d)); 204 + gpiochip_get_data(irq_data_get_irq_chip_data(d)); 200 205 201 206 if (enable) 202 207 enable_irq_wake(port->irq); ··· 244 249 245 250 gc = &port->gc; 246 251 gc->of_node = np; 247 - gc->dev = dev; 252 + gc->parent = dev; 248 253 gc->label = "vf610-gpio"; 249 254 gc->ngpio = VF610_GPIO_PER_PORT; 250 255 gc->base = of_alias_get_id(np, "gpio") * VF610_GPIO_PER_PORT; ··· 256 261 gc->direction_output = vf610_gpio_direction_output; 257 262 gc->set = vf610_gpio_set; 258 263 259 - ret = gpiochip_add(gc); 264 + ret = gpiochip_add_data(gc, port); 260 265 if (ret < 0) 261 266 return ret; 262 267
+19 -27
drivers/gpio/gpio-viperboard.c
··· 88 88 unsigned offset) 89 89 { 90 90 int ret, answer, error = 0; 91 - struct vprbrd_gpio *gpio = 92 - container_of(chip, struct vprbrd_gpio, gpioa); 91 + struct vprbrd_gpio *gpio = gpiochip_get_data(chip); 93 92 struct vprbrd *vb = gpio->vb; 94 93 struct vprbrd_gpioa_msg *gamsg = (struct vprbrd_gpioa_msg *)vb->buf; 95 94 96 95 /* if io is set to output, just return the saved value */ 97 96 if (gpio->gpioa_out & (1 << offset)) 98 - return gpio->gpioa_val & (1 << offset); 97 + return !!(gpio->gpioa_val & (1 << offset)); 99 98 100 99 mutex_lock(&vb->lock); 101 100 ··· 138 139 unsigned offset, int value) 139 140 { 140 141 int ret; 141 - struct vprbrd_gpio *gpio = 142 - container_of(chip, struct vprbrd_gpio, gpioa); 142 + struct vprbrd_gpio *gpio = gpiochip_get_data(chip); 143 143 struct vprbrd *vb = gpio->vb; 144 144 struct vprbrd_gpioa_msg *gamsg = (struct vprbrd_gpioa_msg *)vb->buf; 145 145 ··· 171 173 mutex_unlock(&vb->lock); 172 174 173 175 if (ret != sizeof(struct vprbrd_gpioa_msg)) 174 - dev_err(chip->dev, "usb error setting pin value\n"); 176 + dev_err(chip->parent, "usb error setting pin value\n"); 175 177 } 176 178 } 177 179 ··· 179 181 unsigned offset) 180 182 { 181 183 int ret; 182 - struct vprbrd_gpio *gpio = 183 - container_of(chip, struct vprbrd_gpio, gpioa); 184 + struct vprbrd_gpio *gpio = gpiochip_get_data(chip); 184 185 struct vprbrd *vb = gpio->vb; 185 186 struct vprbrd_gpioa_msg *gamsg = (struct vprbrd_gpioa_msg *)vb->buf; 186 187 ··· 216 219 unsigned offset, int value) 217 220 { 218 221 int ret; 219 - struct vprbrd_gpio *gpio = 220 - container_of(chip, struct vprbrd_gpio, gpioa); 222 + struct vprbrd_gpio *gpio = gpiochip_get_data(chip); 221 223 struct vprbrd *vb = gpio->vb; 222 224 struct vprbrd_gpioa_msg *gamsg = (struct vprbrd_gpioa_msg *)vb->buf; 223 225 ··· 283 287 { 284 288 int ret; 285 289 u16 val; 286 - struct vprbrd_gpio *gpio = 287 - container_of(chip, struct vprbrd_gpio, gpiob); 290 + struct vprbrd_gpio *gpio = gpiochip_get_data(chip); 288 291 struct vprbrd *vb = gpio->vb; 289 292 struct vprbrd_gpiob_msg *gbmsg = (struct vprbrd_gpiob_msg *)vb->buf; 290 293 ··· 314 319 unsigned offset, int value) 315 320 { 316 321 int ret; 317 - struct vprbrd_gpio *gpio = 318 - container_of(chip, struct vprbrd_gpio, gpiob); 322 + struct vprbrd_gpio *gpio = gpiochip_get_data(chip); 319 323 struct vprbrd *vb = gpio->vb; 320 324 struct vprbrd_gpiob_msg *gbmsg = (struct vprbrd_gpiob_msg *)vb->buf; 321 325 ··· 339 345 mutex_unlock(&vb->lock); 340 346 341 347 if (ret != sizeof(struct vprbrd_gpiob_msg)) 342 - dev_err(chip->dev, "usb error setting pin value\n"); 348 + dev_err(chip->parent, "usb error setting pin value\n"); 343 349 } 344 350 } 345 351 ··· 347 353 unsigned offset) 348 354 { 349 355 int ret; 350 - struct vprbrd_gpio *gpio = 351 - container_of(chip, struct vprbrd_gpio, gpiob); 356 + struct vprbrd_gpio *gpio = gpiochip_get_data(chip); 352 357 struct vprbrd *vb = gpio->vb; 353 358 354 359 gpio->gpiob_out &= ~(1 << offset); ··· 359 366 mutex_unlock(&vb->lock); 360 367 361 368 if (ret) 362 - dev_err(chip->dev, "usb error setting pin to input\n"); 369 + dev_err(chip->parent, "usb error setting pin to input\n"); 363 370 364 371 return ret; 365 372 } ··· 368 375 unsigned offset, int value) 369 376 { 370 377 int ret; 371 - struct vprbrd_gpio *gpio = 372 - container_of(chip, struct vprbrd_gpio, gpiob); 378 + struct vprbrd_gpio *gpio = gpiochip_get_data(chip); 373 379 struct vprbrd *vb = gpio->vb; 374 380 375 381 gpio->gpiob_out |= (1 << offset); ··· 377 385 378 386 ret = vprbrd_gpiob_setdir(vb, offset, 1); 379 387 if (ret) 380 - dev_err(chip->dev, "usb error setting pin to output\n"); 388 + dev_err(chip->parent, "usb error setting pin to output\n"); 381 389 382 390 mutex_unlock(&vb->lock); 383 391 ··· 401 409 vb_gpio->vb = vb; 402 410 /* registering gpio a */ 403 411 vb_gpio->gpioa.label = "viperboard gpio a"; 404 - vb_gpio->gpioa.dev = &pdev->dev; 412 + vb_gpio->gpioa.parent = &pdev->dev; 405 413 vb_gpio->gpioa.owner = THIS_MODULE; 406 414 vb_gpio->gpioa.base = -1; 407 415 vb_gpio->gpioa.ngpio = 16; ··· 410 418 vb_gpio->gpioa.get = vprbrd_gpioa_get; 411 419 vb_gpio->gpioa.direction_input = vprbrd_gpioa_direction_input; 412 420 vb_gpio->gpioa.direction_output = vprbrd_gpioa_direction_output; 413 - ret = gpiochip_add(&vb_gpio->gpioa); 421 + ret = gpiochip_add_data(&vb_gpio->gpioa, vb_gpio); 414 422 if (ret < 0) { 415 - dev_err(vb_gpio->gpioa.dev, "could not add gpio a"); 423 + dev_err(vb_gpio->gpioa.parent, "could not add gpio a"); 416 424 goto err_gpioa; 417 425 } 418 426 419 427 /* registering gpio b */ 420 428 vb_gpio->gpiob.label = "viperboard gpio b"; 421 - vb_gpio->gpiob.dev = &pdev->dev; 429 + vb_gpio->gpiob.parent = &pdev->dev; 422 430 vb_gpio->gpiob.owner = THIS_MODULE; 423 431 vb_gpio->gpiob.base = -1; 424 432 vb_gpio->gpiob.ngpio = 16; ··· 427 435 vb_gpio->gpiob.get = vprbrd_gpiob_get; 428 436 vb_gpio->gpiob.direction_input = vprbrd_gpiob_direction_input; 429 437 vb_gpio->gpiob.direction_output = vprbrd_gpiob_direction_output; 430 - ret = gpiochip_add(&vb_gpio->gpiob); 438 + ret = gpiochip_add_data(&vb_gpio->gpiob, vb_gpio); 431 439 if (ret < 0) { 432 - dev_err(vb_gpio->gpiob.dev, "could not add gpio b"); 440 + dev_err(vb_gpio->gpiob.parent, "could not add gpio b"); 433 441 goto err_gpiob; 434 442 } 435 443
+3 -3
drivers/gpio/gpio-vr41xx.c
··· 139 139 static unsigned int startup_giuint(struct irq_data *data) 140 140 { 141 141 if (gpiochip_lock_as_irq(&vr41xx_gpio_chip, data->hwirq)) 142 - dev_err(vr41xx_gpio_chip.dev, 142 + dev_err(vr41xx_gpio_chip.parent, 143 143 "unable to lock HW IRQ %lu for IRQ\n", 144 144 data->hwirq); 145 145 /* Satisfy the .enable semantics by unmasking the line */ ··· 542 542 if (!giu_base) 543 543 return -ENOMEM; 544 544 545 - vr41xx_gpio_chip.dev = &pdev->dev; 545 + vr41xx_gpio_chip.parent = &pdev->dev; 546 546 547 - ret = gpiochip_add(&vr41xx_gpio_chip); 547 + ret = gpiochip_add_data(&vr41xx_gpio_chip, NULL); 548 548 if (!ret) { 549 549 iounmap(giu_base); 550 550 return -ENODEV;
+4 -4
drivers/gpio/gpio-vx855.c
··· 96 96 static int vx855gpio_direction_input(struct gpio_chip *gpio, 97 97 unsigned int nr) 98 98 { 99 - struct vx855_gpio *vg = container_of(gpio, struct vx855_gpio, gpio); 99 + struct vx855_gpio *vg = gpiochip_get_data(gpio); 100 100 unsigned long flags; 101 101 u_int32_t reg_out; 102 102 ··· 120 120 121 121 static int vx855gpio_get(struct gpio_chip *gpio, unsigned int nr) 122 122 { 123 - struct vx855_gpio *vg = container_of(gpio, struct vx855_gpio, gpio); 123 + struct vx855_gpio *vg = gpiochip_get_data(gpio); 124 124 u_int32_t reg_in; 125 125 int ret = 0; 126 126 ··· 146 146 static void vx855gpio_set(struct gpio_chip *gpio, unsigned int nr, 147 147 int val) 148 148 { 149 - struct vx855_gpio *vg = container_of(gpio, struct vx855_gpio, gpio); 149 + struct vx855_gpio *vg = gpiochip_get_data(gpio); 150 150 unsigned long flags; 151 151 u_int32_t reg_out; 152 152 ··· 259 259 260 260 vx855gpio_gpio_setup(vg); 261 261 262 - return gpiochip_add(&vg->gpio); 262 + return gpiochip_add_data(&vg->gpio, vg); 263 263 } 264 264 265 265 static int vx855gpio_remove(struct platform_device *pdev)
+9 -14
drivers/gpio/gpio-wm831x.c
··· 30 30 struct gpio_chip gpio_chip; 31 31 }; 32 32 33 - static inline struct wm831x_gpio *to_wm831x_gpio(struct gpio_chip *chip) 34 - { 35 - return container_of(chip, struct wm831x_gpio, gpio_chip); 36 - } 37 - 38 33 static int wm831x_gpio_direction_in(struct gpio_chip *chip, unsigned offset) 39 34 { 40 - struct wm831x_gpio *wm831x_gpio = to_wm831x_gpio(chip); 35 + struct wm831x_gpio *wm831x_gpio = gpiochip_get_data(chip); 41 36 struct wm831x *wm831x = wm831x_gpio->wm831x; 42 37 int val = WM831X_GPN_DIR; 43 38 ··· 46 51 47 52 static int wm831x_gpio_get(struct gpio_chip *chip, unsigned offset) 48 53 { 49 - struct wm831x_gpio *wm831x_gpio = to_wm831x_gpio(chip); 54 + struct wm831x_gpio *wm831x_gpio = gpiochip_get_data(chip); 50 55 struct wm831x *wm831x = wm831x_gpio->wm831x; 51 56 int ret; 52 57 ··· 62 67 63 68 static void wm831x_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 64 69 { 65 - struct wm831x_gpio *wm831x_gpio = to_wm831x_gpio(chip); 70 + struct wm831x_gpio *wm831x_gpio = gpiochip_get_data(chip); 66 71 struct wm831x *wm831x = wm831x_gpio->wm831x; 67 72 68 73 wm831x_set_bits(wm831x, WM831X_GPIO_LEVEL, 1 << offset, ··· 72 77 static int wm831x_gpio_direction_out(struct gpio_chip *chip, 73 78 unsigned offset, int value) 74 79 { 75 - struct wm831x_gpio *wm831x_gpio = to_wm831x_gpio(chip); 80 + struct wm831x_gpio *wm831x_gpio = gpiochip_get_data(chip); 76 81 struct wm831x *wm831x = wm831x_gpio->wm831x; 77 82 int val = 0; 78 83 int ret; ··· 94 99 95 100 static int wm831x_gpio_to_irq(struct gpio_chip *chip, unsigned offset) 96 101 { 97 - struct wm831x_gpio *wm831x_gpio = to_wm831x_gpio(chip); 102 + struct wm831x_gpio *wm831x_gpio = gpiochip_get_data(chip); 98 103 struct wm831x *wm831x = wm831x_gpio->wm831x; 99 104 100 105 return irq_create_mapping(wm831x->irq_domain, ··· 104 109 static int wm831x_gpio_set_debounce(struct gpio_chip *chip, unsigned offset, 105 110 unsigned debounce) 106 111 { 107 - struct wm831x_gpio *wm831x_gpio = to_wm831x_gpio(chip); 112 + struct wm831x_gpio *wm831x_gpio = gpiochip_get_data(chip); 108 113 struct wm831x *wm831x = wm831x_gpio->wm831x; 109 114 int reg = WM831X_GPIO1_CONTROL + offset; 110 115 int ret, fn; ··· 135 140 #ifdef CONFIG_DEBUG_FS 136 141 static void wm831x_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip) 137 142 { 138 - struct wm831x_gpio *wm831x_gpio = to_wm831x_gpio(chip); 143 + struct wm831x_gpio *wm831x_gpio = gpiochip_get_data(chip); 139 144 struct wm831x *wm831x = wm831x_gpio->wm831x; 140 145 int i, tristated; 141 146 ··· 253 258 wm831x_gpio->wm831x = wm831x; 254 259 wm831x_gpio->gpio_chip = template_chip; 255 260 wm831x_gpio->gpio_chip.ngpio = wm831x->num_gpio; 256 - wm831x_gpio->gpio_chip.dev = &pdev->dev; 261 + wm831x_gpio->gpio_chip.parent = &pdev->dev; 257 262 if (pdata && pdata->gpio_base) 258 263 wm831x_gpio->gpio_chip.base = pdata->gpio_base; 259 264 else 260 265 wm831x_gpio->gpio_chip.base = -1; 261 266 262 - ret = gpiochip_add(&wm831x_gpio->gpio_chip); 267 + ret = gpiochip_add_data(&wm831x_gpio->gpio_chip, wm831x_gpio); 263 268 if (ret < 0) { 264 269 dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret); 265 270 return ret;
+7 -12
drivers/gpio/gpio-wm8350.c
··· 28 28 struct gpio_chip gpio_chip; 29 29 }; 30 30 31 - static inline struct wm8350_gpio_data *to_wm8350_gpio(struct gpio_chip *chip) 32 - { 33 - return container_of(chip, struct wm8350_gpio_data, gpio_chip); 34 - } 35 - 36 31 static int wm8350_gpio_direction_in(struct gpio_chip *chip, unsigned offset) 37 32 { 38 - struct wm8350_gpio_data *wm8350_gpio = to_wm8350_gpio(chip); 33 + struct wm8350_gpio_data *wm8350_gpio = gpiochip_get_data(chip); 39 34 struct wm8350 *wm8350 = wm8350_gpio->wm8350; 40 35 41 36 return wm8350_set_bits(wm8350, WM8350_GPIO_CONFIGURATION_I_O, ··· 39 44 40 45 static int wm8350_gpio_get(struct gpio_chip *chip, unsigned offset) 41 46 { 42 - struct wm8350_gpio_data *wm8350_gpio = to_wm8350_gpio(chip); 47 + struct wm8350_gpio_data *wm8350_gpio = gpiochip_get_data(chip); 43 48 struct wm8350 *wm8350 = wm8350_gpio->wm8350; 44 49 int ret; 45 50 ··· 55 60 56 61 static void wm8350_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 57 62 { 58 - struct wm8350_gpio_data *wm8350_gpio = to_wm8350_gpio(chip); 63 + struct wm8350_gpio_data *wm8350_gpio = gpiochip_get_data(chip); 59 64 struct wm8350 *wm8350 = wm8350_gpio->wm8350; 60 65 61 66 if (value) ··· 67 72 static int wm8350_gpio_direction_out(struct gpio_chip *chip, 68 73 unsigned offset, int value) 69 74 { 70 - struct wm8350_gpio_data *wm8350_gpio = to_wm8350_gpio(chip); 75 + struct wm8350_gpio_data *wm8350_gpio = gpiochip_get_data(chip); 71 76 struct wm8350 *wm8350 = wm8350_gpio->wm8350; 72 77 int ret; 73 78 ··· 84 89 85 90 static int wm8350_gpio_to_irq(struct gpio_chip *chip, unsigned offset) 86 91 { 87 - struct wm8350_gpio_data *wm8350_gpio = to_wm8350_gpio(chip); 92 + struct wm8350_gpio_data *wm8350_gpio = gpiochip_get_data(chip); 88 93 struct wm8350 *wm8350 = wm8350_gpio->wm8350; 89 94 90 95 if (!wm8350->irq_base) ··· 119 124 wm8350_gpio->wm8350 = wm8350; 120 125 wm8350_gpio->gpio_chip = template_chip; 121 126 wm8350_gpio->gpio_chip.ngpio = 13; 122 - wm8350_gpio->gpio_chip.dev = &pdev->dev; 127 + wm8350_gpio->gpio_chip.parent = &pdev->dev; 123 128 if (pdata && pdata->gpio_base) 124 129 wm8350_gpio->gpio_chip.base = pdata->gpio_base; 125 130 else 126 131 wm8350_gpio->gpio_chip.base = -1; 127 132 128 - ret = gpiochip_add(&wm8350_gpio->gpio_chip); 133 + ret = gpiochip_add_data(&wm8350_gpio->gpio_chip, wm8350_gpio); 129 134 if (ret < 0) { 130 135 dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret); 131 136 return ret;
+9 -14
drivers/gpio/gpio-wm8994.c
··· 31 31 struct gpio_chip gpio_chip; 32 32 }; 33 33 34 - static inline struct wm8994_gpio *to_wm8994_gpio(struct gpio_chip *chip) 35 - { 36 - return container_of(chip, struct wm8994_gpio, gpio_chip); 37 - } 38 - 39 34 static int wm8994_gpio_request(struct gpio_chip *chip, unsigned offset) 40 35 { 41 - struct wm8994_gpio *wm8994_gpio = to_wm8994_gpio(chip); 36 + struct wm8994_gpio *wm8994_gpio = gpiochip_get_data(chip); 42 37 struct wm8994 *wm8994 = wm8994_gpio->wm8994; 43 38 44 39 switch (wm8994->type) { ··· 56 61 57 62 static int wm8994_gpio_direction_in(struct gpio_chip *chip, unsigned offset) 58 63 { 59 - struct wm8994_gpio *wm8994_gpio = to_wm8994_gpio(chip); 64 + struct wm8994_gpio *wm8994_gpio = gpiochip_get_data(chip); 60 65 struct wm8994 *wm8994 = wm8994_gpio->wm8994; 61 66 62 67 return wm8994_set_bits(wm8994, WM8994_GPIO_1 + offset, ··· 65 70 66 71 static int wm8994_gpio_get(struct gpio_chip *chip, unsigned offset) 67 72 { 68 - struct wm8994_gpio *wm8994_gpio = to_wm8994_gpio(chip); 73 + struct wm8994_gpio *wm8994_gpio = gpiochip_get_data(chip); 69 74 struct wm8994 *wm8994 = wm8994_gpio->wm8994; 70 75 int ret; 71 76 ··· 82 87 static int wm8994_gpio_direction_out(struct gpio_chip *chip, 83 88 unsigned offset, int value) 84 89 { 85 - struct wm8994_gpio *wm8994_gpio = to_wm8994_gpio(chip); 90 + struct wm8994_gpio *wm8994_gpio = gpiochip_get_data(chip); 86 91 struct wm8994 *wm8994 = wm8994_gpio->wm8994; 87 92 88 93 if (value) ··· 94 99 95 100 static void wm8994_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 96 101 { 97 - struct wm8994_gpio *wm8994_gpio = to_wm8994_gpio(chip); 102 + struct wm8994_gpio *wm8994_gpio = gpiochip_get_data(chip); 98 103 struct wm8994 *wm8994 = wm8994_gpio->wm8994; 99 104 100 105 if (value) ··· 105 110 106 111 static int wm8994_gpio_to_irq(struct gpio_chip *chip, unsigned offset) 107 112 { 108 - struct wm8994_gpio *wm8994_gpio = to_wm8994_gpio(chip); 113 + struct wm8994_gpio *wm8994_gpio = gpiochip_get_data(chip); 109 114 struct wm8994 *wm8994 = wm8994_gpio->wm8994; 110 115 111 116 return regmap_irq_get_virq(wm8994->irq_data, offset); ··· 169 174 170 175 static void wm8994_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip) 171 176 { 172 - struct wm8994_gpio *wm8994_gpio = to_wm8994_gpio(chip); 177 + struct wm8994_gpio *wm8994_gpio = gpiochip_get_data(chip); 173 178 struct wm8994 *wm8994 = wm8994_gpio->wm8994; 174 179 int i; 175 180 ··· 255 260 wm8994_gpio->wm8994 = wm8994; 256 261 wm8994_gpio->gpio_chip = template_chip; 257 262 wm8994_gpio->gpio_chip.ngpio = WM8994_GPIO_MAX; 258 - wm8994_gpio->gpio_chip.dev = &pdev->dev; 263 + wm8994_gpio->gpio_chip.parent = &pdev->dev; 259 264 if (pdata && pdata->gpio_base) 260 265 wm8994_gpio->gpio_chip.base = pdata->gpio_base; 261 266 else 262 267 wm8994_gpio->gpio_chip.base = -1; 263 268 264 - ret = gpiochip_add(&wm8994_gpio->gpio_chip); 269 + ret = gpiochip_add_data(&wm8994_gpio->gpio_chip, wm8994_gpio); 265 270 if (ret < 0) { 266 271 dev_err(&pdev->dev, "Could not register gpiochip, %d\n", 267 272 ret);
+16 -24
drivers/gpio/gpio-xgene-sb.c
··· 23 23 #include <linux/io.h> 24 24 #include <linux/platform_device.h> 25 25 #include <linux/of_gpio.h> 26 - #include <linux/gpio.h> 27 26 #include <linux/gpio/driver.h> 28 27 #include <linux/acpi.h> 29 - #include <linux/basic_mmio_gpio.h> 30 28 31 29 #include "gpiolib.h" 32 30 ··· 41 43 42 44 /** 43 45 * struct xgene_gpio_sb - GPIO-Standby private data structure. 44 - * @bgc: memory-mapped GPIO controllers. 46 + * @gc: memory-mapped GPIO controllers. 45 47 * @irq: Mapping GPIO pins and interrupt number 46 48 * nirq: Number of GPIO pins that supports interrupt 47 49 */ 48 50 struct xgene_gpio_sb { 49 - struct bgpio_chip bgc; 51 + struct gpio_chip gc; 50 52 u32 *irq; 51 53 u32 nirq; 52 54 }; 53 55 54 - static inline struct xgene_gpio_sb *to_xgene_gpio_sb(struct gpio_chip *gc) 55 - { 56 - struct bgpio_chip *bgc = to_bgpio_chip(gc); 57 - 58 - return container_of(bgc, struct xgene_gpio_sb, bgc); 59 - } 60 - 61 - static void xgene_gpio_set_bit(struct bgpio_chip *bgc, void __iomem *reg, u32 gpio, int val) 56 + static void xgene_gpio_set_bit(struct gpio_chip *gc, void __iomem *reg, u32 gpio, int val) 62 57 { 63 58 u32 data; 64 59 65 - data = bgc->read_reg(reg); 60 + data = gc->read_reg(reg); 66 61 if (val) 67 62 data |= GPIO_MASK(gpio); 68 63 else 69 64 data &= ~GPIO_MASK(gpio); 70 - bgc->write_reg(reg, data); 65 + gc->write_reg(reg, data); 71 66 } 72 67 73 68 static int apm_gpio_sb_to_irq(struct gpio_chip *gc, u32 gpio) 74 69 { 75 - struct xgene_gpio_sb *priv = to_xgene_gpio_sb(gc); 70 + struct xgene_gpio_sb *priv = gpiochip_get_data(gc); 76 71 77 72 if (priv->irq[gpio]) 78 73 return priv->irq[gpio]; ··· 90 99 if (IS_ERR(regs)) 91 100 return PTR_ERR(regs); 92 101 93 - ret = bgpio_init(&priv->bgc, &pdev->dev, 4, 102 + ret = bgpio_init(&priv->gc, &pdev->dev, 4, 94 103 regs + MPA_GPIO_IN_ADDR, 95 104 regs + MPA_GPIO_OUT_ADDR, NULL, 96 105 regs + MPA_GPIO_OE_ADDR, NULL, 0); 97 106 if (ret) 98 107 return ret; 99 108 100 - priv->bgc.gc.to_irq = apm_gpio_sb_to_irq; 101 - priv->bgc.gc.ngpio = XGENE_MAX_GPIO_DS; 109 + priv->gc.to_irq = apm_gpio_sb_to_irq; 110 + priv->gc.ngpio = XGENE_MAX_GPIO_DS; 102 111 103 112 priv->nirq = XGENE_MAX_GPIO_DS_IRQ; 104 113 ··· 109 118 110 119 for (i = 0; i < priv->nirq; i++) { 111 120 priv->irq[default_lines[i]] = platform_get_irq(pdev, i); 112 - xgene_gpio_set_bit(&priv->bgc, regs + MPA_GPIO_SEL_LO, 121 + xgene_gpio_set_bit(&priv->gc, regs + MPA_GPIO_SEL_LO, 113 122 default_lines[i] * 2, 1); 114 - xgene_gpio_set_bit(&priv->bgc, regs + MPA_GPIO_INT_LVL, i, 1); 123 + xgene_gpio_set_bit(&priv->gc, regs + MPA_GPIO_INT_LVL, i, 1); 115 124 } 116 125 117 126 platform_set_drvdata(pdev, priv); 118 127 119 - ret = gpiochip_add(&priv->bgc.gc); 128 + ret = gpiochip_add_data(&priv->gc, priv); 120 129 if (ret) 121 130 dev_err(&pdev->dev, "failed to register X-Gene GPIO Standby driver\n"); 122 131 else ··· 124 133 125 134 if (priv->nirq > 0) { 126 135 /* Register interrupt handlers for gpio signaled acpi events */ 127 - acpi_gpiochip_request_interrupts(&priv->bgc.gc); 136 + acpi_gpiochip_request_interrupts(&priv->gc); 128 137 } 129 138 130 139 return ret; ··· 135 144 struct xgene_gpio_sb *priv = platform_get_drvdata(pdev); 136 145 137 146 if (priv->nirq > 0) { 138 - acpi_gpiochip_free_interrupts(&priv->bgc.gc); 147 + acpi_gpiochip_free_interrupts(&priv->gc); 139 148 } 140 149 141 - return bgpio_remove(&priv->bgc); 150 + gpiochip_remove(&priv->gc); 151 + return 0; 142 152 } 143 153 144 154 static const struct of_device_id xgene_gpio_sb_of_match[] = {
+7 -12
drivers/gpio/gpio-xgene.c
··· 47 47 #endif 48 48 }; 49 49 50 - static inline struct xgene_gpio *to_xgene_gpio(struct gpio_chip *chip) 51 - { 52 - return container_of(chip, struct xgene_gpio, chip); 53 - } 54 - 55 50 static int xgene_gpio_get(struct gpio_chip *gc, unsigned int offset) 56 51 { 57 - struct xgene_gpio *chip = to_xgene_gpio(gc); 52 + struct xgene_gpio *chip = gpiochip_get_data(gc); 58 53 unsigned long bank_offset; 59 54 u32 bit_offset; 60 55 ··· 60 65 61 66 static void __xgene_gpio_set(struct gpio_chip *gc, unsigned int offset, int val) 62 67 { 63 - struct xgene_gpio *chip = to_xgene_gpio(gc); 68 + struct xgene_gpio *chip = gpiochip_get_data(gc); 64 69 unsigned long bank_offset; 65 70 u32 setval, bit_offset; 66 71 ··· 77 82 78 83 static void xgene_gpio_set(struct gpio_chip *gc, unsigned int offset, int val) 79 84 { 80 - struct xgene_gpio *chip = to_xgene_gpio(gc); 85 + struct xgene_gpio *chip = gpiochip_get_data(gc); 81 86 unsigned long flags; 82 87 83 88 spin_lock_irqsave(&chip->lock, flags); ··· 87 92 88 93 static int xgene_gpio_dir_in(struct gpio_chip *gc, unsigned int offset) 89 94 { 90 - struct xgene_gpio *chip = to_xgene_gpio(gc); 95 + struct xgene_gpio *chip = gpiochip_get_data(gc); 91 96 unsigned long flags, bank_offset; 92 97 u32 dirval, bit_offset; 93 98 ··· 108 113 static int xgene_gpio_dir_out(struct gpio_chip *gc, 109 114 unsigned int offset, int val) 110 115 { 111 - struct xgene_gpio *chip = to_xgene_gpio(gc); 116 + struct xgene_gpio *chip = gpiochip_get_data(gc); 112 117 unsigned long flags, bank_offset; 113 118 u32 dirval, bit_offset; 114 119 ··· 183 188 gpio->chip.ngpio = XGENE_MAX_GPIOS; 184 189 185 190 spin_lock_init(&gpio->lock); 186 - gpio->chip.dev = &pdev->dev; 191 + gpio->chip.parent = &pdev->dev; 187 192 gpio->chip.direction_input = xgene_gpio_dir_in; 188 193 gpio->chip.direction_output = xgene_gpio_dir_out; 189 194 gpio->chip.get = xgene_gpio_get; ··· 193 198 194 199 platform_set_drvdata(pdev, gpio); 195 200 196 - err = gpiochip_add(&gpio->chip); 201 + err = gpiochip_add_data(&gpio->chip, gpio); 197 202 if (err) { 198 203 dev_err(&pdev->dev, 199 204 "failed to register gpiochip.\n");
+7 -11
drivers/gpio/gpio-xilinx.c
··· 92 92 static int xgpio_get(struct gpio_chip *gc, unsigned int gpio) 93 93 { 94 94 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc); 95 - struct xgpio_instance *chip = 96 - container_of(mm_gc, struct xgpio_instance, mmchip); 95 + struct xgpio_instance *chip = gpiochip_get_data(gc); 97 96 u32 val; 98 97 99 98 val = xgpio_readreg(mm_gc->regs + XGPIO_DATA_OFFSET + ··· 114 115 { 115 116 unsigned long flags; 116 117 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc); 117 - struct xgpio_instance *chip = 118 - container_of(mm_gc, struct xgpio_instance, mmchip); 118 + struct xgpio_instance *chip = gpiochip_get_data(gc); 119 119 int index = xgpio_index(chip, gpio); 120 120 int offset = xgpio_offset(chip, gpio); 121 121 ··· 145 147 { 146 148 unsigned long flags; 147 149 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc); 148 - struct xgpio_instance *chip = 149 - container_of(mm_gc, struct xgpio_instance, mmchip); 150 + struct xgpio_instance *chip = gpiochip_get_data(gc); 150 151 int index = xgpio_index(chip, gpio); 151 152 int offset = xgpio_offset(chip, gpio); 152 153 ··· 177 180 { 178 181 unsigned long flags; 179 182 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc); 180 - struct xgpio_instance *chip = 181 - container_of(mm_gc, struct xgpio_instance, mmchip); 183 + struct xgpio_instance *chip = gpiochip_get_data(gc); 182 184 int index = xgpio_index(chip, gpio); 183 185 int offset = xgpio_offset(chip, gpio); 184 186 ··· 208 212 static void xgpio_save_regs(struct of_mm_gpio_chip *mm_gc) 209 213 { 210 214 struct xgpio_instance *chip = 211 - container_of(mm_gc, struct xgpio_instance, mmchip); 215 + container_of(mm_gc, struct xgpio_instance, mmchip); 212 216 213 217 xgpio_writereg(mm_gc->regs + XGPIO_DATA_OFFSET, chip->gpio_state[0]); 214 218 xgpio_writereg(mm_gc->regs + XGPIO_TRI_OFFSET, chip->gpio_dir[0]); ··· 301 305 } 302 306 303 307 chip->mmchip.gc.ngpio = chip->gpio_width[0] + chip->gpio_width[1]; 304 - chip->mmchip.gc.dev = &pdev->dev; 308 + chip->mmchip.gc.parent = &pdev->dev; 305 309 chip->mmchip.gc.direction_input = xgpio_dir_in; 306 310 chip->mmchip.gc.direction_output = xgpio_dir_out; 307 311 chip->mmchip.gc.get = xgpio_get; ··· 310 314 chip->mmchip.save_regs = xgpio_save_regs; 311 315 312 316 /* Call the OF gpio helper to setup and register the GPIO device */ 313 - status = of_mm_gpiochip_add(np, &chip->mmchip); 317 + status = of_mm_gpiochip_add_data(np, &chip->mmchip, chip); 314 318 if (status) { 315 319 pr_err("%s: error in probe function with status %d\n", 316 320 np->full_name, status);
+10 -15
drivers/gpio/gpio-xlp.c
··· 100 100 spinlock_t lock; 101 101 }; 102 102 103 - static struct xlp_gpio_priv *gpio_chip_to_xlp_priv(struct gpio_chip *gc) 104 - { 105 - return container_of(gc, struct xlp_gpio_priv, chip); 106 - } 107 - 108 103 static int xlp_gpio_get_reg(void __iomem *addr, unsigned gpio) 109 104 { 110 105 u32 pos, regset; ··· 128 133 static void xlp_gpio_irq_disable(struct irq_data *d) 129 134 { 130 135 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 131 - struct xlp_gpio_priv *priv = gpio_chip_to_xlp_priv(gc); 136 + struct xlp_gpio_priv *priv = gpiochip_get_data(gc); 132 137 unsigned long flags; 133 138 134 139 spin_lock_irqsave(&priv->lock, flags); ··· 140 145 static void xlp_gpio_irq_mask_ack(struct irq_data *d) 141 146 { 142 147 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 143 - struct xlp_gpio_priv *priv = gpio_chip_to_xlp_priv(gc); 148 + struct xlp_gpio_priv *priv = gpiochip_get_data(gc); 144 149 unsigned long flags; 145 150 146 151 spin_lock_irqsave(&priv->lock, flags); ··· 153 158 static void xlp_gpio_irq_unmask(struct irq_data *d) 154 159 { 155 160 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 156 - struct xlp_gpio_priv *priv = gpio_chip_to_xlp_priv(gc); 161 + struct xlp_gpio_priv *priv = gpiochip_get_data(gc); 157 162 unsigned long flags; 158 163 159 164 spin_lock_irqsave(&priv->lock, flags); ··· 165 170 static int xlp_gpio_set_irq_type(struct irq_data *d, unsigned int type) 166 171 { 167 172 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 168 - struct xlp_gpio_priv *priv = gpio_chip_to_xlp_priv(gc); 173 + struct xlp_gpio_priv *priv = gpiochip_get_data(gc); 169 174 int pol, irq_type; 170 175 171 176 switch (type) { ··· 230 235 231 236 static int xlp_gpio_dir_output(struct gpio_chip *gc, unsigned gpio, int state) 232 237 { 233 - struct xlp_gpio_priv *priv = gpio_chip_to_xlp_priv(gc); 238 + struct xlp_gpio_priv *priv = gpiochip_get_data(gc); 234 239 235 240 BUG_ON(gpio >= gc->ngpio); 236 241 xlp_gpio_set_reg(priv->gpio_out_en, gpio, 0x1); ··· 240 245 241 246 static int xlp_gpio_dir_input(struct gpio_chip *gc, unsigned gpio) 242 247 { 243 - struct xlp_gpio_priv *priv = gpio_chip_to_xlp_priv(gc); 248 + struct xlp_gpio_priv *priv = gpiochip_get_data(gc); 244 249 245 250 BUG_ON(gpio >= gc->ngpio); 246 251 xlp_gpio_set_reg(priv->gpio_out_en, gpio, 0x0); ··· 250 255 251 256 static int xlp_gpio_get(struct gpio_chip *gc, unsigned gpio) 252 257 { 253 - struct xlp_gpio_priv *priv = gpio_chip_to_xlp_priv(gc); 258 + struct xlp_gpio_priv *priv = gpiochip_get_data(gc); 254 259 255 260 BUG_ON(gpio >= gc->ngpio); 256 261 return xlp_gpio_get_reg(priv->gpio_paddrv, gpio); ··· 258 263 259 264 static void xlp_gpio_set(struct gpio_chip *gc, unsigned gpio, int state) 260 265 { 261 - struct xlp_gpio_priv *priv = gpio_chip_to_xlp_priv(gc); 266 + struct xlp_gpio_priv *priv = gpiochip_get_data(gc); 262 267 263 268 BUG_ON(gpio >= gc->ngpio); 264 269 xlp_gpio_set_reg(priv->gpio_paddrv, gpio, state); ··· 368 373 gc->owner = THIS_MODULE; 369 374 gc->label = dev_name(&pdev->dev); 370 375 gc->base = 0; 371 - gc->dev = &pdev->dev; 376 + gc->parent = &pdev->dev; 372 377 gc->ngpio = ngpio; 373 378 gc->of_node = pdev->dev.of_node; 374 379 gc->direction_output = xlp_gpio_dir_output; ··· 383 388 return -ENODEV; 384 389 } 385 390 386 - err = gpiochip_add(gc); 391 + err = gpiochip_add_data(gc, priv); 387 392 if (err < 0) 388 393 goto out_free_desc; 389 394
+2 -2
drivers/gpio/gpio-xtensa.c
··· 148 148 { 149 149 int ret; 150 150 151 - ret = gpiochip_add(&impwire_chip); 151 + ret = gpiochip_add_data(&impwire_chip, NULL); 152 152 if (ret) 153 153 return ret; 154 - return gpiochip_add(&expstate_chip); 154 + return gpiochip_add_data(&expstate_chip, NULL); 155 155 } 156 156 157 157 static struct platform_driver xtensa_gpio_driver = {
+9 -10
drivers/gpio/gpio-zevio.c
··· 52 52 #define ZEVIO_GPIO_INPUT 0x18 53 53 #define ZEVIO_GPIO_INT_STICKY 0x20 54 54 55 - #define to_zevio_gpio(chip) container_of(to_of_mm_gpio_chip(chip), \ 56 - struct zevio_gpio, chip) 57 - 58 55 /* Bit number of GPIO in its section */ 59 56 #define ZEVIO_GPIO_BIT(gpio) (gpio&7) 60 57 ··· 77 80 /* Functions for struct gpio_chip */ 78 81 static int zevio_gpio_get(struct gpio_chip *chip, unsigned pin) 79 82 { 80 - struct zevio_gpio *controller = to_zevio_gpio(chip); 83 + struct zevio_gpio *controller = gpiochip_get_data(chip); 81 84 u32 val, dir; 82 85 83 86 spin_lock(&controller->lock); ··· 93 96 94 97 static void zevio_gpio_set(struct gpio_chip *chip, unsigned pin, int value) 95 98 { 96 - struct zevio_gpio *controller = to_zevio_gpio(chip); 99 + struct zevio_gpio *controller = gpiochip_get_data(chip); 97 100 u32 val; 98 101 99 102 spin_lock(&controller->lock); ··· 109 112 110 113 static int zevio_gpio_direction_input(struct gpio_chip *chip, unsigned pin) 111 114 { 112 - struct zevio_gpio *controller = to_zevio_gpio(chip); 115 + struct zevio_gpio *controller = gpiochip_get_data(chip); 113 116 u32 val; 114 117 115 118 spin_lock(&controller->lock); ··· 126 129 static int zevio_gpio_direction_output(struct gpio_chip *chip, 127 130 unsigned pin, int value) 128 131 { 129 - struct zevio_gpio *controller = to_zevio_gpio(chip); 132 + struct zevio_gpio *controller = gpiochip_get_data(chip); 130 133 u32 val; 131 134 132 135 spin_lock(&controller->lock); ··· 182 185 183 186 /* Copy our reference */ 184 187 controller->chip.gc = zevio_gpio_chip; 185 - controller->chip.gc.dev = &pdev->dev; 188 + controller->chip.gc.parent = &pdev->dev; 186 189 187 - status = of_mm_gpiochip_add(pdev->dev.of_node, &(controller->chip)); 190 + status = of_mm_gpiochip_add_data(pdev->dev.of_node, 191 + &(controller->chip), 192 + controller); 188 193 if (status) { 189 194 dev_err(&pdev->dev, "failed to add gpiochip: %d\n", status); 190 195 return status; ··· 198 199 for (i = 0; i < controller->chip.gc.ngpio; i += 8) 199 200 zevio_gpio_port_set(controller, i, ZEVIO_GPIO_INT_MASK, 0xFF); 200 201 201 - dev_dbg(controller->chip.gc.dev, "ZEVIO GPIO controller set up!\n"); 202 + dev_dbg(controller->chip.gc.parent, "ZEVIO GPIO controller set up!\n"); 202 203 203 204 return 0; 204 205 }
+10 -15
drivers/gpio/gpio-zx.c
··· 43 43 struct gpio_chip gc; 44 44 }; 45 45 46 - static inline struct zx_gpio *to_zx(struct gpio_chip *gc) 47 - { 48 - return container_of(gc, struct zx_gpio, gc); 49 - } 50 - 51 46 static int zx_direction_input(struct gpio_chip *gc, unsigned offset) 52 47 { 53 - struct zx_gpio *chip = to_zx(gc); 48 + struct zx_gpio *chip = gpiochip_get_data(gc); 54 49 unsigned long flags; 55 50 u16 gpiodir; 56 51 ··· 64 69 static int zx_direction_output(struct gpio_chip *gc, unsigned offset, 65 70 int value) 66 71 { 67 - struct zx_gpio *chip = to_zx(gc); 72 + struct zx_gpio *chip = gpiochip_get_data(gc); 68 73 unsigned long flags; 69 74 u16 gpiodir; 70 75 ··· 87 92 88 93 static int zx_get_value(struct gpio_chip *gc, unsigned offset) 89 94 { 90 - struct zx_gpio *chip = to_zx(gc); 95 + struct zx_gpio *chip = gpiochip_get_data(gc); 91 96 92 97 return !!(readw_relaxed(chip->base + ZX_GPIO_DI) & BIT(offset)); 93 98 } 94 99 95 100 static void zx_set_value(struct gpio_chip *gc, unsigned offset, int value) 96 101 { 97 - struct zx_gpio *chip = to_zx(gc); 102 + struct zx_gpio *chip = gpiochip_get_data(gc); 98 103 99 104 if (value) 100 105 writew_relaxed(BIT(offset), chip->base + ZX_GPIO_DO1); ··· 105 110 static int zx_irq_type(struct irq_data *d, unsigned trigger) 106 111 { 107 112 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 108 - struct zx_gpio *chip = to_zx(gc); 113 + struct zx_gpio *chip = gpiochip_get_data(gc); 109 114 int offset = irqd_to_hwirq(d); 110 115 unsigned long flags; 111 116 u16 gpiois, gpioi_epos, gpioi_eneg, gpioiev; ··· 157 162 unsigned long pending; 158 163 int offset; 159 164 struct gpio_chip *gc = irq_desc_get_handler_data(desc); 160 - struct zx_gpio *chip = to_zx(gc); 165 + struct zx_gpio *chip = gpiochip_get_data(gc); 161 166 struct irq_chip *irqchip = irq_desc_get_chip(desc); 162 167 163 168 chained_irq_enter(irqchip, desc); ··· 176 181 static void zx_irq_mask(struct irq_data *d) 177 182 { 178 183 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 179 - struct zx_gpio *chip = to_zx(gc); 184 + struct zx_gpio *chip = gpiochip_get_data(gc); 180 185 u16 mask = BIT(irqd_to_hwirq(d) % ZX_GPIO_NR); 181 186 u16 gpioie; 182 187 ··· 191 196 static void zx_irq_unmask(struct irq_data *d) 192 197 { 193 198 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 194 - struct zx_gpio *chip = to_zx(gc); 199 + struct zx_gpio *chip = gpiochip_get_data(gc); 195 200 u16 mask = BIT(irqd_to_hwirq(d) % ZX_GPIO_NR); 196 201 u16 gpioie; 197 202 ··· 240 245 chip->gc.base = ZX_GPIO_NR * id; 241 246 chip->gc.ngpio = ZX_GPIO_NR; 242 247 chip->gc.label = dev_name(dev); 243 - chip->gc.dev = dev; 248 + chip->gc.parent = dev; 244 249 chip->gc.owner = THIS_MODULE; 245 250 246 - ret = gpiochip_add(&chip->gc); 251 + ret = gpiochip_add_data(&chip->gc, chip); 247 252 if (ret) 248 253 return ret; 249 254
+23 -29
drivers/gpio/gpio-zynq.c
··· 131 131 static struct irq_chip zynq_gpio_level_irqchip; 132 132 static struct irq_chip zynq_gpio_edge_irqchip; 133 133 134 - static struct zynq_gpio *to_zynq_gpio(struct gpio_chip *gc) 135 - { 136 - return container_of(gc, struct zynq_gpio, chip); 137 - } 138 - 139 134 /** 140 135 * zynq_gpio_get_bank_pin - Get the bank number and pin number within that bank 141 136 * for a given pin in the GPIO device ··· 178 183 { 179 184 u32 data; 180 185 unsigned int bank_num, bank_pin_num; 181 - struct zynq_gpio *gpio = to_zynq_gpio(chip); 186 + struct zynq_gpio *gpio = gpiochip_get_data(chip); 182 187 183 188 zynq_gpio_get_bank_pin(pin, &bank_num, &bank_pin_num, gpio); 184 189 ··· 202 207 int state) 203 208 { 204 209 unsigned int reg_offset, bank_num, bank_pin_num; 205 - struct zynq_gpio *gpio = to_zynq_gpio(chip); 210 + struct zynq_gpio *gpio = gpiochip_get_data(chip); 206 211 207 212 zynq_gpio_get_bank_pin(pin, &bank_num, &bank_pin_num, gpio); 208 213 ··· 239 244 { 240 245 u32 reg; 241 246 unsigned int bank_num, bank_pin_num; 242 - struct zynq_gpio *gpio = to_zynq_gpio(chip); 247 + struct zynq_gpio *gpio = gpiochip_get_data(chip); 243 248 244 249 zynq_gpio_get_bank_pin(pin, &bank_num, &bank_pin_num, gpio); 245 250 ··· 272 277 { 273 278 u32 reg; 274 279 unsigned int bank_num, bank_pin_num; 275 - struct zynq_gpio *gpio = to_zynq_gpio(chip); 280 + struct zynq_gpio *gpio = gpiochip_get_data(chip); 276 281 277 282 zynq_gpio_get_bank_pin(pin, &bank_num, &bank_pin_num, gpio); 278 283 ··· 303 308 { 304 309 unsigned int device_pin_num, bank_num, bank_pin_num; 305 310 struct zynq_gpio *gpio = 306 - to_zynq_gpio(irq_data_get_irq_chip_data(irq_data)); 311 + gpiochip_get_data(irq_data_get_irq_chip_data(irq_data)); 307 312 308 313 device_pin_num = irq_data->hwirq; 309 314 zynq_gpio_get_bank_pin(device_pin_num, &bank_num, &bank_pin_num, gpio); ··· 324 329 { 325 330 unsigned int device_pin_num, bank_num, bank_pin_num; 326 331 struct zynq_gpio *gpio = 327 - to_zynq_gpio(irq_data_get_irq_chip_data(irq_data)); 332 + gpiochip_get_data(irq_data_get_irq_chip_data(irq_data)); 328 333 329 334 device_pin_num = irq_data->hwirq; 330 335 zynq_gpio_get_bank_pin(device_pin_num, &bank_num, &bank_pin_num, gpio); ··· 344 349 { 345 350 unsigned int device_pin_num, bank_num, bank_pin_num; 346 351 struct zynq_gpio *gpio = 347 - to_zynq_gpio(irq_data_get_irq_chip_data(irq_data)); 352 + gpiochip_get_data(irq_data_get_irq_chip_data(irq_data)); 348 353 349 354 device_pin_num = irq_data->hwirq; 350 355 zynq_gpio_get_bank_pin(device_pin_num, &bank_num, &bank_pin_num, gpio); ··· 395 400 u32 int_type, int_pol, int_any; 396 401 unsigned int device_pin_num, bank_num, bank_pin_num; 397 402 struct zynq_gpio *gpio = 398 - to_zynq_gpio(irq_data_get_irq_chip_data(irq_data)); 403 + gpiochip_get_data(irq_data_get_irq_chip_data(irq_data)); 399 404 400 405 device_pin_num = irq_data->hwirq; 401 406 zynq_gpio_get_bank_pin(device_pin_num, &bank_num, &bank_pin_num, gpio); ··· 459 464 static int zynq_gpio_set_wake(struct irq_data *data, unsigned int on) 460 465 { 461 466 struct zynq_gpio *gpio = 462 - to_zynq_gpio(irq_data_get_irq_chip_data(data)); 467 + gpiochip_get_data(irq_data_get_irq_chip_data(data)); 463 468 464 469 irq_set_irq_wake(gpio->irq, on); 465 470 ··· 525 530 u32 int_sts, int_enb; 526 531 unsigned int bank_num; 527 532 struct zynq_gpio *gpio = 528 - to_zynq_gpio(irq_desc_get_handler_data(desc)); 533 + gpiochip_get_data(irq_desc_get_handler_data(desc)); 529 534 struct irq_chip *irqchip = irq_desc_get_chip(desc); 530 535 531 536 chained_irq_enter(irqchip, desc); ··· 587 592 { 588 593 int ret; 589 594 590 - ret = pm_runtime_get_sync(chip->dev); 595 + ret = pm_runtime_get_sync(chip->parent); 591 596 592 597 /* 593 598 * If the device is already active pm_runtime_get() will return 1 on ··· 598 603 599 604 static void zynq_gpio_free(struct gpio_chip *chip, unsigned offset) 600 605 { 601 - pm_runtime_put(chip->dev); 606 + pm_runtime_put(chip->parent); 602 607 } 603 608 604 609 static const struct dev_pm_ops zynq_gpio_dev_pm_ops = { ··· 693 698 chip = &gpio->chip; 694 699 chip->label = gpio->p_data->label; 695 700 chip->owner = THIS_MODULE; 696 - chip->dev = &pdev->dev; 701 + chip->parent = &pdev->dev; 697 702 chip->get = zynq_gpio_get_value; 698 703 chip->set = zynq_gpio_set_value; 699 704 chip->request = zynq_gpio_request; ··· 703 708 chip->base = -1; 704 709 chip->ngpio = gpio->p_data->ngpio; 705 710 706 - /* Enable GPIO clock */ 711 + /* Retrieve GPIO clock */ 707 712 gpio->clk = devm_clk_get(&pdev->dev, NULL); 708 713 if (IS_ERR(gpio->clk)) { 709 714 dev_err(&pdev->dev, "input clock not found.\n"); 710 715 return PTR_ERR(gpio->clk); 711 716 } 712 - ret = clk_prepare_enable(gpio->clk); 713 - if (ret) { 714 - dev_err(&pdev->dev, "Unable to enable clock.\n"); 717 + 718 + pm_runtime_enable(&pdev->dev); 719 + ret = pm_runtime_get_sync(&pdev->dev); 720 + if (ret < 0) 715 721 return ret; 716 - } 717 722 718 723 /* report a bug if gpio chip registration fails */ 719 - ret = gpiochip_add(chip); 724 + ret = gpiochip_add_data(chip, gpio); 720 725 if (ret) { 721 726 dev_err(&pdev->dev, "Failed to add gpio chip\n"); 722 - goto err_disable_clk; 727 + goto err_pm_put; 723 728 } 724 729 725 730 /* disable interrupts for all banks */ ··· 737 742 gpiochip_set_chained_irqchip(chip, &zynq_gpio_edge_irqchip, gpio->irq, 738 743 zynq_gpio_irqhandler); 739 744 740 - pm_runtime_set_active(&pdev->dev); 741 - pm_runtime_enable(&pdev->dev); 745 + pm_runtime_put(&pdev->dev); 742 746 743 747 return 0; 744 748 745 749 err_rm_gpiochip: 746 750 gpiochip_remove(chip); 747 - err_disable_clk: 748 - clk_disable_unprepare(gpio->clk); 751 + err_pm_put: 752 + pm_runtime_put(&pdev->dev); 749 753 750 754 return ret; 751 755 }
+25 -22
drivers/gpio/gpiolib-acpi.c
··· 51 51 52 52 static int acpi_gpiochip_find(struct gpio_chip *gc, void *data) 53 53 { 54 - if (!gc->dev) 54 + if (!gc->parent) 55 55 return false; 56 56 57 - return ACPI_HANDLE(gc->dev) == data; 57 + return ACPI_HANDLE(gc->parent) == data; 58 58 } 59 59 60 60 #ifdef CONFIG_PINCTRL ··· 184 184 if (agpio->connection_type != ACPI_RESOURCE_GPIO_TYPE_INT) 185 185 return AE_OK; 186 186 187 - handle = ACPI_HANDLE(chip->dev); 187 + handle = ACPI_HANDLE(chip->parent); 188 188 pin = agpio->pin_table[0]; 189 189 190 190 if (pin <= 255) { ··· 208 208 209 209 desc = gpiochip_request_own_desc(chip, pin, "ACPI:Event"); 210 210 if (IS_ERR(desc)) { 211 - dev_err(chip->dev, "Failed to request GPIO\n"); 211 + dev_err(chip->parent, "Failed to request GPIO\n"); 212 212 return AE_ERROR; 213 213 } 214 214 ··· 216 216 217 217 ret = gpiochip_lock_as_irq(chip, pin); 218 218 if (ret) { 219 - dev_err(chip->dev, "Failed to lock GPIO as interrupt\n"); 219 + dev_err(chip->parent, "Failed to lock GPIO as interrupt\n"); 220 220 goto fail_free_desc; 221 221 } 222 222 223 223 irq = gpiod_to_irq(desc); 224 224 if (irq < 0) { 225 - dev_err(chip->dev, "Failed to translate GPIO to IRQ\n"); 225 + dev_err(chip->parent, "Failed to translate GPIO to IRQ\n"); 226 226 goto fail_unlock_irq; 227 227 } 228 228 ··· 259 259 ret = request_threaded_irq(event->irq, NULL, handler, irqflags, 260 260 "ACPI:Event", event); 261 261 if (ret) { 262 - dev_err(chip->dev, "Failed to setup interrupt handler for %d\n", 262 + dev_err(chip->parent, 263 + "Failed to setup interrupt handler for %d\n", 263 264 event->irq); 264 265 goto fail_free_event; 265 266 } ··· 294 293 acpi_handle handle; 295 294 acpi_status status; 296 295 297 - if (!chip->dev || !chip->to_irq) 296 + if (!chip->parent || !chip->to_irq) 298 297 return; 299 298 300 - handle = ACPI_HANDLE(chip->dev); 299 + handle = ACPI_HANDLE(chip->parent); 301 300 if (!handle) 302 301 return; 303 302 ··· 324 323 acpi_handle handle; 325 324 acpi_status status; 326 325 327 - if (!chip->dev || !chip->to_irq) 326 + if (!chip->parent || !chip->to_irq) 328 327 return; 329 328 330 - handle = ACPI_HANDLE(chip->dev); 329 + handle = ACPI_HANDLE(chip->parent); 331 330 if (!handle) 332 331 return; 333 332 ··· 770 769 static void acpi_gpiochip_request_regions(struct acpi_gpio_chip *achip) 771 770 { 772 771 struct gpio_chip *chip = achip->chip; 773 - acpi_handle handle = ACPI_HANDLE(chip->dev); 772 + acpi_handle handle = ACPI_HANDLE(chip->parent); 774 773 acpi_status status; 775 774 776 775 INIT_LIST_HEAD(&achip->conns); ··· 779 778 acpi_gpio_adr_space_handler, 780 779 NULL, achip); 781 780 if (ACPI_FAILURE(status)) 782 - dev_err(chip->dev, "Failed to install GPIO OpRegion handler\n"); 781 + dev_err(chip->parent, 782 + "Failed to install GPIO OpRegion handler\n"); 783 783 } 784 784 785 785 static void acpi_gpiochip_free_regions(struct acpi_gpio_chip *achip) 786 786 { 787 787 struct gpio_chip *chip = achip->chip; 788 - acpi_handle handle = ACPI_HANDLE(chip->dev); 788 + acpi_handle handle = ACPI_HANDLE(chip->parent); 789 789 struct acpi_gpio_connection *conn, *tmp; 790 790 acpi_status status; 791 791 792 792 status = acpi_remove_address_space_handler(handle, ACPI_ADR_SPACE_GPIO, 793 793 acpi_gpio_adr_space_handler); 794 794 if (ACPI_FAILURE(status)) { 795 - dev_err(chip->dev, "Failed to remove GPIO OpRegion handler\n"); 795 + dev_err(chip->parent, 796 + "Failed to remove GPIO OpRegion handler\n"); 796 797 return; 797 798 } 798 799 ··· 811 808 acpi_handle handle; 812 809 acpi_status status; 813 810 814 - if (!chip || !chip->dev) 811 + if (!chip || !chip->parent) 815 812 return; 816 813 817 - handle = ACPI_HANDLE(chip->dev); 814 + handle = ACPI_HANDLE(chip->parent); 818 815 if (!handle) 819 816 return; 820 817 821 818 acpi_gpio = kzalloc(sizeof(*acpi_gpio), GFP_KERNEL); 822 819 if (!acpi_gpio) { 823 - dev_err(chip->dev, 820 + dev_err(chip->parent, 824 821 "Failed to allocate memory for ACPI GPIO chip\n"); 825 822 return; 826 823 } ··· 830 827 831 828 status = acpi_attach_data(handle, acpi_gpio_chip_dh, acpi_gpio); 832 829 if (ACPI_FAILURE(status)) { 833 - dev_err(chip->dev, "Failed to attach ACPI GPIO chip\n"); 830 + dev_err(chip->parent, "Failed to attach ACPI GPIO chip\n"); 834 831 kfree(acpi_gpio); 835 832 return; 836 833 } ··· 844 841 acpi_handle handle; 845 842 acpi_status status; 846 843 847 - if (!chip || !chip->dev) 844 + if (!chip || !chip->parent) 848 845 return; 849 846 850 - handle = ACPI_HANDLE(chip->dev); 847 + handle = ACPI_HANDLE(chip->parent); 851 848 if (!handle) 852 849 return; 853 850 854 851 status = acpi_get_data(handle, acpi_gpio_chip_dh, (void **)&acpi_gpio); 855 852 if (ACPI_FAILURE(status)) { 856 - dev_warn(chip->dev, "Failed to retrieve ACPI GPIO chip\n"); 853 + dev_warn(chip->parent, "Failed to retrieve ACPI GPIO chip\n"); 857 854 return; 858 855 } 859 856
+9 -7
drivers/gpio/gpiolib-of.c
··· 262 262 EXPORT_SYMBOL(of_gpio_simple_xlate); 263 263 264 264 /** 265 - * of_mm_gpiochip_add - Add memory mapped GPIO chip (bank) 265 + * of_mm_gpiochip_add_data - Add memory mapped GPIO chip (bank) 266 266 * @np: device node of the GPIO chip 267 267 * @mm_gc: pointer to the of_mm_gpio_chip allocated structure 268 + * @data: driver data to store in the struct gpio_chip 268 269 * 269 270 * To use this function you should allocate and fill mm_gc with: 270 271 * ··· 281 280 * do all necessary work for you. Then you'll able to use .regs 282 281 * to manage GPIOs from the callbacks. 283 282 */ 284 - int of_mm_gpiochip_add(struct device_node *np, 285 - struct of_mm_gpio_chip *mm_gc) 283 + int of_mm_gpiochip_add_data(struct device_node *np, 284 + struct of_mm_gpio_chip *mm_gc, 285 + void *data) 286 286 { 287 287 int ret = -ENOMEM; 288 288 struct gpio_chip *gc = &mm_gc->gc; ··· 303 301 304 302 mm_gc->gc.of_node = np; 305 303 306 - ret = gpiochip_add(gc); 304 + ret = gpiochip_add_data(gc, data); 307 305 if (ret) 308 306 goto err2; 309 307 ··· 317 315 np->full_name, ret); 318 316 return ret; 319 317 } 320 - EXPORT_SYMBOL(of_mm_gpiochip_add); 318 + EXPORT_SYMBOL(of_mm_gpiochip_add_data); 321 319 322 320 /** 323 321 * of_mm_gpiochip_remove - Remove memory mapped GPIO chip (bank) ··· 425 423 { 426 424 int status; 427 425 428 - if ((!chip->of_node) && (chip->dev)) 429 - chip->of_node = chip->dev->of_node; 426 + if ((!chip->of_node) && (chip->parent)) 427 + chip->of_node = chip->parent->of_node; 430 428 431 429 if (!chip->of_node) 432 430 return 0;
+3 -2
drivers/gpio/gpiolib-sysfs.c
··· 605 605 if (chip->names && chip->names[offset]) 606 606 ioname = chip->names[offset]; 607 607 608 - dev = device_create_with_groups(&gpio_class, chip->dev, 608 + dev = device_create_with_groups(&gpio_class, chip->parent, 609 609 MKDEV(0, 0), data, gpio_groups, 610 610 ioname ? ioname : "gpio%u", 611 611 desc_to_gpio(desc)); ··· 730 730 return 0; 731 731 732 732 /* use chip->base for the ID; it's already known to be unique */ 733 - dev = device_create_with_groups(&gpio_class, chip->dev, MKDEV(0, 0), 733 + dev = device_create_with_groups(&gpio_class, chip->parent, 734 + MKDEV(0, 0), 734 735 chip, gpiochip_groups, 735 736 "gpiochip%d", chip->base); 736 737 if (IS_ERR(dev))
+68 -42
drivers/gpio/gpiolib.c
··· 182 182 183 183 /* 184 184 * Add a new chip to the global chips list, keeping the list of chips sorted 185 - * by base order. 185 + * by range(means [base, base + ngpio - 1]) order. 186 186 * 187 187 * Return -EBUSY if the new chip overlaps with some other chip's integer 188 188 * space. 189 189 */ 190 190 static int gpiochip_add_to_list(struct gpio_chip *chip) 191 191 { 192 - struct list_head *pos; 193 - struct gpio_chip *_chip; 194 - int err = 0; 192 + struct gpio_chip *iterator; 193 + struct gpio_chip *previous = NULL; 195 194 196 - /* find where to insert our chip */ 197 - list_for_each(pos, &gpio_chips) { 198 - _chip = list_entry(pos, struct gpio_chip, list); 199 - /* shall we insert before _chip? */ 200 - if (_chip->base >= chip->base + chip->ngpio) 201 - break; 195 + if (list_empty(&gpio_chips)) { 196 + list_add_tail(&chip->list, &gpio_chips); 197 + return 0; 202 198 } 203 199 204 - /* are we stepping on the chip right before? */ 205 - if (pos != &gpio_chips && pos->prev != &gpio_chips) { 206 - _chip = list_entry(pos->prev, struct gpio_chip, list); 207 - if (_chip->base + _chip->ngpio > chip->base) { 208 - dev_err(chip->dev, 209 - "GPIO integer space overlap, cannot add chip\n"); 210 - err = -EBUSY; 200 + list_for_each_entry(iterator, &gpio_chips, list) { 201 + if (iterator->base >= chip->base + chip->ngpio) { 202 + /* 203 + * Iterator is the first GPIO chip so there is no 204 + * previous one 205 + */ 206 + if (!previous) { 207 + goto found; 208 + } else { 209 + /* 210 + * We found a valid range(means 211 + * [base, base + ngpio - 1]) between previous 212 + * and iterator chip. 213 + */ 214 + if (previous->base + previous->ngpio 215 + <= chip->base) 216 + goto found; 217 + } 211 218 } 219 + previous = iterator; 212 220 } 213 221 214 - if (!err) 215 - list_add_tail(&chip->list, pos); 222 + /* 223 + * We are beyond the last chip in the list and iterator now 224 + * points to the head. 225 + * Let iterator point to the last chip in the list. 226 + */ 216 227 217 - return err; 228 + iterator = list_last_entry(&gpio_chips, struct gpio_chip, list); 229 + if (iterator->base + iterator->ngpio <= chip->base) { 230 + list_add(&chip->list, &iterator->list); 231 + return 0; 232 + } 233 + 234 + dev_err(chip->parent, 235 + "GPIO integer space overlap, cannot add chip\n"); 236 + return -EBUSY; 237 + 238 + found: 239 + list_add_tail(&chip->list, &iterator->list); 240 + return 0; 218 241 } 219 242 220 243 /** ··· 275 252 * Takes the names from gc->names and checks if they are all unique. If they 276 253 * are, they are assigned to their gpio descriptors. 277 254 * 278 - * Returns -EEXIST if one of the names is already used for a different GPIO. 255 + * Warning if one of the names is already used for a different GPIO. 279 256 */ 280 257 static int gpiochip_set_desc_names(struct gpio_chip *gc) 281 258 { ··· 290 267 291 268 gpio = gpio_name_to_desc(gc->names[i]); 292 269 if (gpio) 293 - dev_warn(gc->dev, "Detected name collision for " 270 + dev_warn(gc->parent, "Detected name collision for " 294 271 "GPIO name '%s'\n", 295 272 gc->names[i]); 296 273 } ··· 303 280 } 304 281 305 282 /** 306 - * gpiochip_add() - register a gpio_chip 283 + * gpiochip_add_data() - register a gpio_chip 307 284 * @chip: the chip to register, with chip->base initialized 308 285 * Context: potentially before irqs will work 309 286 * ··· 311 288 * because the chip->base is invalid or already associated with a 312 289 * different chip. Otherwise it returns zero as a success code. 313 290 * 314 - * When gpiochip_add() is called very early during boot, so that GPIOs 315 - * can be freely used, the chip->dev device must be registered before 291 + * When gpiochip_add_data() is called very early during boot, so that GPIOs 292 + * can be freely used, the chip->parent device must be registered before 316 293 * the gpio framework's arch_initcall(). Otherwise sysfs initialization 317 294 * for GPIOs will fail rudely. 318 295 * 319 296 * If chip->base is negative, this requests dynamic assignment of 320 297 * a range of valid GPIOs. 321 298 */ 322 - int gpiochip_add(struct gpio_chip *chip) 299 + int gpiochip_add_data(struct gpio_chip *chip, void *data) 323 300 { 324 301 unsigned long flags; 325 302 int status = 0; ··· 330 307 descs = kcalloc(chip->ngpio, sizeof(descs[0]), GFP_KERNEL); 331 308 if (!descs) 332 309 return -ENOMEM; 310 + 311 + chip->data = data; 312 + 313 + if (chip->ngpio == 0) { 314 + chip_err(chip, "tried to insert a GPIO chip with zero lines\n"); 315 + return -EINVAL; 316 + } 333 317 334 318 spin_lock_irqsave(&gpio_lock, flags); 335 319 ··· 378 348 INIT_LIST_HEAD(&chip->pin_ranges); 379 349 #endif 380 350 381 - if (!chip->owner && chip->dev && chip->dev->driver) 382 - chip->owner = chip->dev->driver->owner; 351 + if (!chip->owner && chip->parent && chip->parent->driver) 352 + chip->owner = chip->parent->driver->owner; 383 353 384 354 status = gpiochip_set_desc_names(chip); 385 355 if (status) ··· 419 389 chip->label ? : "generic"); 420 390 return status; 421 391 } 422 - EXPORT_SYMBOL_GPL(gpiochip_add); 392 + EXPORT_SYMBOL_GPL(gpiochip_add_data); 423 393 424 394 /** 425 395 * gpiochip_remove() - unregister a gpio_chip ··· 454 424 spin_unlock_irqrestore(&gpio_lock, flags); 455 425 456 426 if (requested) 457 - dev_crit(chip->dev, "REMOVING GPIOCHIP WITH GPIOS STILL REQUESTED\n"); 427 + dev_crit(chip->parent, 428 + "REMOVING GPIOCHIP WITH GPIOS STILL REQUESTED\n"); 458 429 459 430 kfree(chip->desc); 460 431 chip->desc = NULL; ··· 690 659 * gpiochip, providing an irq domain to translate the local IRQs to 691 660 * global irqs in the gpiolib core, and making sure that the gpiochip 692 661 * is passed as chip data to all related functions. Driver callbacks 693 - * need to use container_of() to get their local state containers back 662 + * need to use gpiochip_get_data() to get their local state containers back 694 663 * from the gpiochip passed as chip data. An irqdomain will be stored 695 664 * in the gpiochip that shall be used by the driver to handle IRQ number 696 665 * translation. The gpiochip will need to be initialized and registered ··· 714 683 if (!gpiochip || !irqchip) 715 684 return -EINVAL; 716 685 717 - if (!gpiochip->dev) { 686 + if (!gpiochip->parent) { 718 687 pr_err("missing gpiochip .dev parent pointer\n"); 719 688 return -EINVAL; 720 689 } 721 - of_node = gpiochip->dev->of_node; 690 + of_node = gpiochip->parent->of_node; 722 691 #ifdef CONFIG_OF_GPIO 723 692 /* 724 693 * If the gpiochip has an assigned OF node this takes precedence 725 - * FIXME: get rid of this and use gpiochip->dev->of_node everywhere 694 + * FIXME: get rid of this and use gpiochip->parent->of_node 695 + * everywhere 726 696 */ 727 697 if (gpiochip->of_node) 728 698 of_node = gpiochip->of_node; ··· 1311 1279 chip = desc->chip; 1312 1280 offset = gpio_chip_hwgpio(desc); 1313 1281 value = chip->get ? chip->get(chip, offset) : -EIO; 1314 - /* 1315 - * FIXME: fix all drivers to clamp to [0,1] or return negative, 1316 - * then change this to: 1317 - * value = value < 0 ? value : !!value; 1318 - * so we can properly propagate error codes. 1319 - */ 1320 - value = !!value; 1282 + value = value < 0 ? value : !!value; 1321 1283 trace_gpio_value(desc_to_gpio(desc), 1, value); 1322 1284 return value; 1323 1285 } ··· 2538 2512 2539 2513 seq_printf(s, "%sGPIOs %d-%d", (char *)s->private, 2540 2514 chip->base, chip->base + chip->ngpio - 1); 2541 - dev = chip->dev; 2515 + dev = chip->parent; 2542 2516 if (dev) 2543 2517 seq_printf(s, ", %s/%s", dev->bus ? dev->bus->name : "no-bus", 2544 2518 dev_name(dev));
+1 -1
drivers/gpio/gpiolib.h
··· 16 16 #include <linux/device.h> 17 17 18 18 enum of_gpio_flags; 19 - 19 + enum gpiod_flags; 20 20 struct acpi_device; 21 21 22 22 /**
+7 -11
drivers/hid/hid-cp2112.c
··· 24 24 * http://www.silabs.com/Support%20Documents/TechnicalDocs/AN495.pdf 25 25 */ 26 26 27 - #include <linux/gpio.h> 27 + #include <linux/gpio/driver.h> 28 28 #include <linux/hid.h> 29 29 #include <linux/i2c.h> 30 30 #include <linux/module.h> ··· 169 169 170 170 static int cp2112_gpio_direction_input(struct gpio_chip *chip, unsigned offset) 171 171 { 172 - struct cp2112_device *dev = container_of(chip, struct cp2112_device, 173 - gc); 172 + struct cp2112_device *dev = gpiochip_get_data(chip); 174 173 struct hid_device *hdev = dev->hdev; 175 174 u8 buf[5]; 176 175 int ret; ··· 197 198 198 199 static void cp2112_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 199 200 { 200 - struct cp2112_device *dev = container_of(chip, struct cp2112_device, 201 - gc); 201 + struct cp2112_device *dev = gpiochip_get_data(chip); 202 202 struct hid_device *hdev = dev->hdev; 203 203 u8 buf[3]; 204 204 int ret; ··· 214 216 215 217 static int cp2112_gpio_get(struct gpio_chip *chip, unsigned offset) 216 218 { 217 - struct cp2112_device *dev = container_of(chip, struct cp2112_device, 218 - gc); 219 + struct cp2112_device *dev = gpiochip_get_data(chip); 219 220 struct hid_device *hdev = dev->hdev; 220 221 u8 buf[2]; 221 222 int ret; ··· 232 235 static int cp2112_gpio_direction_output(struct gpio_chip *chip, 233 236 unsigned offset, int value) 234 237 { 235 - struct cp2112_device *dev = container_of(chip, struct cp2112_device, 236 - gc); 238 + struct cp2112_device *dev = gpiochip_get_data(chip); 237 239 struct hid_device *hdev = dev->hdev; 238 240 u8 buf[5]; 239 241 int ret; ··· 1100 1104 dev->gc.base = -1; 1101 1105 dev->gc.ngpio = 8; 1102 1106 dev->gc.can_sleep = 1; 1103 - dev->gc.dev = &hdev->dev; 1107 + dev->gc.parent = &hdev->dev; 1104 1108 1105 - ret = gpiochip_add(&dev->gc); 1109 + ret = gpiochip_add_data(&dev->gc, dev); 1106 1110 if (ret < 0) { 1107 1111 hid_err(hdev, "error registering gpio chip\n"); 1108 1112 goto err_free_i2c;
+1 -1
drivers/input/touchscreen/ad7879.c
··· 454 454 ts->gc.ngpio = 1; 455 455 ts->gc.label = "AD7879-GPIO"; 456 456 ts->gc.owner = THIS_MODULE; 457 - ts->gc.dev = ts->dev; 457 + ts->gc.parent = ts->dev; 458 458 459 459 ret = gpiochip_add(&ts->gc); 460 460 if (ret)
+7 -7
drivers/leds/leds-pca9532.c
··· 242 242 #ifdef CONFIG_LEDS_PCA9532_GPIO 243 243 static int pca9532_gpio_request_pin(struct gpio_chip *gc, unsigned offset) 244 244 { 245 - struct pca9532_data *data = container_of(gc, struct pca9532_data, gpio); 245 + struct pca9532_data *data = gpiochip_get_data(gc); 246 246 struct pca9532_led *led = &data->leds[offset]; 247 247 248 248 if (led->type == PCA9532_TYPE_GPIO) ··· 253 253 254 254 static void pca9532_gpio_set_value(struct gpio_chip *gc, unsigned offset, int val) 255 255 { 256 - struct pca9532_data *data = container_of(gc, struct pca9532_data, gpio); 256 + struct pca9532_data *data = gpiochip_get_data(gc); 257 257 struct pca9532_led *led = &data->leds[offset]; 258 258 259 259 if (val) ··· 266 266 267 267 static int pca9532_gpio_get_value(struct gpio_chip *gc, unsigned offset) 268 268 { 269 - struct pca9532_data *data = container_of(gc, struct pca9532_data, gpio); 269 + struct pca9532_data *data = gpiochip_get_data(gc); 270 270 unsigned char reg; 271 271 272 272 reg = i2c_smbus_read_byte_data(data->client, PCA9532_REG_INPUT(offset)); ··· 315 315 } 316 316 317 317 #ifdef CONFIG_LEDS_PCA9532_GPIO 318 - if (data->gpio.dev) 318 + if (data->gpio.parent) 319 319 gpiochip_remove(&data->gpio); 320 320 #endif 321 321 ··· 409 409 data->gpio.can_sleep = 1; 410 410 data->gpio.base = pdata->gpio_base; 411 411 data->gpio.ngpio = data->chip_info->num_leds; 412 - data->gpio.dev = &client->dev; 412 + data->gpio.parent = &client->dev; 413 413 data->gpio.owner = THIS_MODULE; 414 414 415 - err = gpiochip_add(&data->gpio); 415 + err = gpiochip_add_data(&data->gpio, data); 416 416 if (err) { 417 417 /* Use data->gpio.dev as a flag for freeing gpiochip */ 418 - data->gpio.dev = NULL; 418 + data->gpio.parent = NULL; 419 419 dev_warn(&client->dev, "could not add gpiochip\n"); 420 420 } else { 421 421 dev_info(&client->dev, "gpios %i...%i\n",
+3 -3
drivers/leds/leds-tca6507.c
··· 603 603 static void tca6507_gpio_set_value(struct gpio_chip *gc, 604 604 unsigned offset, int val) 605 605 { 606 - struct tca6507_chip *tca = container_of(gc, struct tca6507_chip, gpio); 606 + struct tca6507_chip *tca = gpiochip_get_data(gc); 607 607 unsigned long flags; 608 608 609 609 spin_lock_irqsave(&tca->lock, flags); ··· 651 651 tca->gpio.owner = THIS_MODULE; 652 652 tca->gpio.direction_output = tca6507_gpio_direction_output; 653 653 tca->gpio.set = tca6507_gpio_set_value; 654 - tca->gpio.dev = &client->dev; 654 + tca->gpio.parent = &client->dev; 655 655 #ifdef CONFIG_OF_GPIO 656 656 tca->gpio.of_node = of_node_get(client->dev.of_node); 657 657 #endif 658 - err = gpiochip_add(&tca->gpio); 658 + err = gpiochip_add_data(&tca->gpio, tca); 659 659 if (err) { 660 660 tca->gpio.ngpio = 0; 661 661 return err;
+1 -1
drivers/media/dvb-frontends/cxd2820r_core.c
··· 722 722 #ifdef CONFIG_GPIOLIB 723 723 /* add GPIOs */ 724 724 priv->gpio_chip.label = KBUILD_MODNAME; 725 - priv->gpio_chip.dev = &priv->i2c->dev; 725 + priv->gpio_chip.parent = &priv->i2c->dev; 726 726 priv->gpio_chip.owner = THIS_MODULE; 727 727 priv->gpio_chip.direction_output = 728 728 cxd2820r_gpio_direction_output;
+1 -1
drivers/mfd/dm355evm_msp.c
··· 259 259 int i; 260 260 261 261 /* GPIO-ish stuff */ 262 - dm355evm_msp_gpio.dev = &client->dev; 262 + dm355evm_msp_gpio.parent = &client->dev; 263 263 status = gpiochip_add(&dm355evm_msp_gpio); 264 264 if (status < 0) 265 265 return status;
+1 -1
drivers/mfd/htc-egpio.c
··· 321 321 ei->chip[i].dev = &(pdev->dev); 322 322 chip = &(ei->chip[i].chip); 323 323 chip->label = "htc-egpio"; 324 - chip->dev = &pdev->dev; 324 + chip->parent = &pdev->dev; 325 325 chip->owner = THIS_MODULE; 326 326 chip->get = egpio_get; 327 327 chip->set = egpio_set;
+2 -2
drivers/mfd/htc-i2cpld.c
··· 429 429 /* Setup the GPIO chips */ 430 430 gpio_chip = &(chip->chip_out); 431 431 gpio_chip->label = "htcpld-out"; 432 - gpio_chip->dev = dev; 432 + gpio_chip->parent = dev; 433 433 gpio_chip->owner = THIS_MODULE; 434 434 gpio_chip->get = htcpld_chip_get; 435 435 gpio_chip->set = htcpld_chip_set; ··· 440 440 441 441 gpio_chip = &(chip->chip_in); 442 442 gpio_chip->label = "htcpld-in"; 443 - gpio_chip->dev = dev; 443 + gpio_chip->parent = dev; 444 444 gpio_chip->owner = THIS_MODULE; 445 445 gpio_chip->get = htcpld_chip_get; 446 446 gpio_chip->set = NULL;
+1 -1
drivers/mfd/tps65010.c
··· 638 638 tps->outmask = board->outmask; 639 639 640 640 tps->chip.label = client->name; 641 - tps->chip.dev = &client->dev; 641 + tps->chip.parent = &client->dev; 642 642 tps->chip.owner = THIS_MODULE; 643 643 644 644 tps->chip.set = tps65010_gpio_set;
+1 -1
drivers/mfd/ucb1x00-core.c
··· 570 570 571 571 if (pdata && pdata->gpio_base) { 572 572 ucb->gpio.label = dev_name(&ucb->dev); 573 - ucb->gpio.dev = &ucb->dev; 573 + ucb->gpio.parent = &ucb->dev; 574 574 ucb->gpio.owner = THIS_MODULE; 575 575 ucb->gpio.base = pdata->gpio_base; 576 576 ucb->gpio.ngpio = 10;
+4 -4
drivers/mfd/vexpress-sysreg.c
··· 11 11 * Copyright (C) 2012 ARM Limited 12 12 */ 13 13 14 - #include <linux/basic_mmio_gpio.h> 14 + #include <linux/gpio/driver.h> 15 15 #include <linux/err.h> 16 16 #include <linux/io.h> 17 17 #include <linux/mfd/core.h> ··· 164 164 { 165 165 struct resource *mem; 166 166 void __iomem *base; 167 - struct bgpio_chip *mmc_gpio_chip; 167 + struct gpio_chip *mmc_gpio_chip; 168 168 int master; 169 169 u32 dt_hbi; 170 170 ··· 201 201 return -ENOMEM; 202 202 bgpio_init(mmc_gpio_chip, &pdev->dev, 0x4, base + SYS_MCI, 203 203 NULL, NULL, NULL, NULL, 0); 204 - mmc_gpio_chip->gc.ngpio = 2; 205 - gpiochip_add(&mmc_gpio_chip->gc); 204 + mmc_gpio_chip->ngpio = 2; 205 + gpiochip_add(mmc_gpio_chip); 206 206 207 207 return mfd_add_devices(&pdev->dev, PLATFORM_DEVID_AUTO, 208 208 vexpress_sysreg_cells,
+6 -6
drivers/pinctrl/bcm/pinctrl-bcm2835.c
··· 23 23 #include <linux/delay.h> 24 24 #include <linux/device.h> 25 25 #include <linux/err.h> 26 - #include <linux/gpio.h> 26 + #include <linux/gpio/driver.h> 27 27 #include <linux/interrupt.h> 28 28 #include <linux/io.h> 29 29 #include <linux/irq.h> ··· 337 337 338 338 static int bcm2835_gpio_get(struct gpio_chip *chip, unsigned offset) 339 339 { 340 - struct bcm2835_pinctrl *pc = dev_get_drvdata(chip->dev); 340 + struct bcm2835_pinctrl *pc = gpiochip_get_data(chip); 341 341 342 342 return bcm2835_gpio_get_bit(pc, GPLEV0, offset); 343 343 } 344 344 345 345 static void bcm2835_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 346 346 { 347 - struct bcm2835_pinctrl *pc = dev_get_drvdata(chip->dev); 347 + struct bcm2835_pinctrl *pc = gpiochip_get_data(chip); 348 348 349 349 bcm2835_gpio_set_bit(pc, value ? GPSET0 : GPCLR0, offset); 350 350 } ··· 358 358 359 359 static int bcm2835_gpio_to_irq(struct gpio_chip *chip, unsigned offset) 360 360 { 361 - struct bcm2835_pinctrl *pc = dev_get_drvdata(chip->dev); 361 + struct bcm2835_pinctrl *pc = gpiochip_get_data(chip); 362 362 363 363 return irq_linear_revmap(pc->irq_domain, offset); 364 364 } ··· 964 964 return PTR_ERR(pc->base); 965 965 966 966 pc->gpio_chip = bcm2835_gpio_chip; 967 - pc->gpio_chip.dev = dev; 967 + pc->gpio_chip.parent = dev; 968 968 pc->gpio_chip.of_node = np; 969 969 970 970 pc->irq_domain = irq_domain_add_linear(np, BCM2835_NUM_GPIOS, ··· 1021 1021 } 1022 1022 } 1023 1023 1024 - err = gpiochip_add(&pc->gpio_chip); 1024 + err = gpiochip_add_data(&pc->gpio_chip, pc); 1025 1025 if (err) { 1026 1026 dev_err(dev, "could not add GPIO chip\n"); 1027 1027 return err;
+1 -1
drivers/pinctrl/bcm/pinctrl-iproc-gpio.c
··· 694 694 gc->ngpio = ngpios; 695 695 chip->num_banks = (ngpios + NGPIOS_PER_BANK - 1) / NGPIOS_PER_BANK; 696 696 gc->label = dev_name(dev); 697 - gc->dev = dev; 697 + gc->parent = dev; 698 698 gc->of_node = dev->of_node; 699 699 gc->request = iproc_gpio_request; 700 700 gc->free = iproc_gpio_free;
+8 -13
drivers/pinctrl/bcm/pinctrl-nsp-gpio.c
··· 18 18 * through the interaction with the NSP IOMUX controller. 19 19 */ 20 20 21 - #include <linux/gpio.h> 21 + #include <linux/gpio/driver.h> 22 22 #include <linux/interrupt.h> 23 23 #include <linux/io.h> 24 24 #include <linux/ioport.h> ··· 80 80 REG, 81 81 IO_CTRL 82 82 }; 83 - 84 - static inline struct nsp_gpio *to_nsp_gpio(struct gpio_chip *gc) 85 - { 86 - return container_of(gc, struct nsp_gpio, gc); 87 - } 88 83 89 84 /* 90 85 * Mapping from PINCONF pins to GPIO pins is 1-to-1 ··· 292 297 293 298 static int nsp_gpio_direction_input(struct gpio_chip *gc, unsigned gpio) 294 299 { 295 - struct nsp_gpio *chip = to_nsp_gpio(gc); 300 + struct nsp_gpio *chip = gpiochip_get_data(gc); 296 301 unsigned long flags; 297 302 298 303 spin_lock_irqsave(&chip->lock, flags); ··· 306 311 static int nsp_gpio_direction_output(struct gpio_chip *gc, unsigned gpio, 307 312 int val) 308 313 { 309 - struct nsp_gpio *chip = to_nsp_gpio(gc); 314 + struct nsp_gpio *chip = gpiochip_get_data(gc); 310 315 unsigned long flags; 311 316 312 317 spin_lock_irqsave(&chip->lock, flags); ··· 320 325 321 326 static void nsp_gpio_set(struct gpio_chip *gc, unsigned gpio, int val) 322 327 { 323 - struct nsp_gpio *chip = to_nsp_gpio(gc); 328 + struct nsp_gpio *chip = gpiochip_get_data(gc); 324 329 unsigned long flags; 325 330 326 331 spin_lock_irqsave(&chip->lock, flags); ··· 332 337 333 338 static int nsp_gpio_get(struct gpio_chip *gc, unsigned gpio) 334 339 { 335 - struct nsp_gpio *chip = to_nsp_gpio(gc); 340 + struct nsp_gpio *chip = gpiochip_get_data(gc); 336 341 337 342 return !!(readl(chip->base + NSP_GPIO_DATA_IN) & BIT(gpio)); 338 343 } 339 344 340 345 static int nsp_gpio_to_irq(struct gpio_chip *gc, unsigned offset) 341 346 { 342 - struct nsp_gpio *chip = to_nsp_gpio(gc); 347 + struct nsp_gpio *chip = gpiochip_get_data(gc); 343 348 344 349 return irq_linear_revmap(chip->irq_domain, offset); 345 350 } ··· 664 669 gc->can_sleep = false; 665 670 gc->ngpio = val; 666 671 gc->label = dev_name(dev); 667 - gc->dev = dev; 672 + gc->parent = dev; 668 673 gc->of_node = dev->of_node; 669 674 gc->request = nsp_gpio_request; 670 675 gc->free = nsp_gpio_free; ··· 709 714 writel(val, (chip->base + NSP_CHIP_A_INT_MASK)); 710 715 } 711 716 712 - ret = gpiochip_add(gc); 717 + ret = gpiochip_add_data(gc, chip); 713 718 if (ret < 0) { 714 719 dev_err(dev, "unable to add GPIO chip\n"); 715 720 return ret;
+17 -19
drivers/pinctrl/intel/pinctrl-baytrail.c
··· 20 20 #include <linux/types.h> 21 21 #include <linux/bitops.h> 22 22 #include <linux/interrupt.h> 23 - #include <linux/gpio.h> 23 + #include <linux/gpio/driver.h> 24 24 #include <linux/acpi.h> 25 25 #include <linux/platform_device.h> 26 26 #include <linux/seq_file.h> ··· 147 147 struct byt_gpio_pin_context *saved_context; 148 148 }; 149 149 150 - #define to_byt_gpio(c) container_of(c, struct byt_gpio, chip) 151 - 152 150 static void __iomem *byt_gpio_reg(struct gpio_chip *chip, unsigned offset, 153 151 int reg) 154 152 { 155 - struct byt_gpio *vg = to_byt_gpio(chip); 153 + struct byt_gpio *vg = gpiochip_get_data(chip); 156 154 u32 reg_offset; 157 155 158 156 if (reg == BYT_INT_STAT_REG) ··· 191 193 192 194 static int byt_gpio_request(struct gpio_chip *chip, unsigned offset) 193 195 { 194 - struct byt_gpio *vg = to_byt_gpio(chip); 196 + struct byt_gpio *vg = gpiochip_get_data(chip); 195 197 void __iomem *reg = byt_gpio_reg(chip, offset, BYT_CONF0_REG); 196 198 u32 value, gpio_mux; 197 199 unsigned long flags; ··· 227 229 228 230 static void byt_gpio_free(struct gpio_chip *chip, unsigned offset) 229 231 { 230 - struct byt_gpio *vg = to_byt_gpio(chip); 232 + struct byt_gpio *vg = gpiochip_get_data(chip); 231 233 232 234 byt_gpio_clear_triggering(vg, offset); 233 235 pm_runtime_put(&vg->pdev->dev); ··· 235 237 236 238 static int byt_irq_type(struct irq_data *d, unsigned type) 237 239 { 238 - struct byt_gpio *vg = to_byt_gpio(irq_data_get_irq_chip_data(d)); 240 + struct byt_gpio *vg = gpiochip_get_data(irq_data_get_irq_chip_data(d)); 239 241 u32 offset = irqd_to_hwirq(d); 240 242 u32 value; 241 243 unsigned long flags; ··· 271 273 static int byt_gpio_get(struct gpio_chip *chip, unsigned offset) 272 274 { 273 275 void __iomem *reg = byt_gpio_reg(chip, offset, BYT_VAL_REG); 274 - struct byt_gpio *vg = to_byt_gpio(chip); 276 + struct byt_gpio *vg = gpiochip_get_data(chip); 275 277 unsigned long flags; 276 278 u32 val; 277 279 ··· 279 281 val = readl(reg); 280 282 raw_spin_unlock_irqrestore(&vg->lock, flags); 281 283 282 - return val & BYT_LEVEL; 284 + return !!(val & BYT_LEVEL); 283 285 } 284 286 285 287 static void byt_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 286 288 { 287 - struct byt_gpio *vg = to_byt_gpio(chip); 289 + struct byt_gpio *vg = gpiochip_get_data(chip); 288 290 void __iomem *reg = byt_gpio_reg(chip, offset, BYT_VAL_REG); 289 291 unsigned long flags; 290 292 u32 old_val; ··· 303 305 304 306 static int byt_gpio_direction_input(struct gpio_chip *chip, unsigned offset) 305 307 { 306 - struct byt_gpio *vg = to_byt_gpio(chip); 308 + struct byt_gpio *vg = gpiochip_get_data(chip); 307 309 void __iomem *reg = byt_gpio_reg(chip, offset, BYT_VAL_REG); 308 310 unsigned long flags; 309 311 u32 value; ··· 322 324 static int byt_gpio_direction_output(struct gpio_chip *chip, 323 325 unsigned gpio, int value) 324 326 { 325 - struct byt_gpio *vg = to_byt_gpio(chip); 327 + struct byt_gpio *vg = gpiochip_get_data(chip); 326 328 void __iomem *conf_reg = byt_gpio_reg(chip, gpio, BYT_CONF0_REG); 327 329 void __iomem *reg = byt_gpio_reg(chip, gpio, BYT_VAL_REG); 328 330 unsigned long flags; ··· 354 356 355 357 static void byt_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip) 356 358 { 357 - struct byt_gpio *vg = to_byt_gpio(chip); 359 + struct byt_gpio *vg = gpiochip_get_data(chip); 358 360 int i; 359 361 u32 conf0, val, offs; 360 362 ··· 426 428 static void byt_gpio_irq_handler(struct irq_desc *desc) 427 429 { 428 430 struct irq_data *data = irq_desc_get_irq_data(desc); 429 - struct byt_gpio *vg = to_byt_gpio(irq_desc_get_handler_data(desc)); 431 + struct byt_gpio *vg = gpiochip_get_data(irq_desc_get_handler_data(desc)); 430 432 struct irq_chip *chip = irq_data_get_irq_chip(data); 431 433 u32 base, pin; 432 434 void __iomem *reg; ··· 448 450 static void byt_irq_ack(struct irq_data *d) 449 451 { 450 452 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 451 - struct byt_gpio *vg = to_byt_gpio(gc); 453 + struct byt_gpio *vg = gpiochip_get_data(gc); 452 454 unsigned offset = irqd_to_hwirq(d); 453 455 void __iomem *reg; 454 456 ··· 461 463 static void byt_irq_unmask(struct irq_data *d) 462 464 { 463 465 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 464 - struct byt_gpio *vg = to_byt_gpio(gc); 466 + struct byt_gpio *vg = gpiochip_get_data(gc); 465 467 unsigned offset = irqd_to_hwirq(d); 466 468 unsigned long flags; 467 469 void __iomem *reg; ··· 496 498 static void byt_irq_mask(struct irq_data *d) 497 499 { 498 500 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 499 - struct byt_gpio *vg = to_byt_gpio(gc); 501 + struct byt_gpio *vg = gpiochip_get_data(gc); 500 502 501 503 byt_gpio_clear_triggering(vg, irqd_to_hwirq(d)); 502 504 } ··· 596 598 gc->dbg_show = byt_gpio_dbg_show; 597 599 gc->base = -1; 598 600 gc->can_sleep = false; 599 - gc->dev = dev; 601 + gc->parent = dev; 600 602 601 603 #ifdef CONFIG_PM_SLEEP 602 604 vg->saved_context = devm_kcalloc(&pdev->dev, gc->ngpio, 603 605 sizeof(*vg->saved_context), GFP_KERNEL); 604 606 #endif 605 607 606 - ret = gpiochip_add(gc); 608 + ret = gpiochip_add_data(gc, vg); 607 609 if (ret) { 608 610 dev_err(&pdev->dev, "failed adding byt-gpio chip\n"); 609 611 return ret;
+10 -12
drivers/pinctrl/intel/pinctrl-cherryview.c
··· 181 181 struct chv_pin_context *saved_pin_context; 182 182 }; 183 183 184 - #define gpiochip_to_pinctrl(c) container_of(c, struct chv_pinctrl, chip) 185 - 186 184 #define ALTERNATE_FUNCTION(p, m, i) \ 187 185 { \ 188 186 .pin = (p), \ ··· 1155 1157 1156 1158 static int chv_gpio_get(struct gpio_chip *chip, unsigned offset) 1157 1159 { 1158 - struct chv_pinctrl *pctrl = gpiochip_to_pinctrl(chip); 1160 + struct chv_pinctrl *pctrl = gpiochip_get_data(chip); 1159 1161 int pin = chv_gpio_offset_to_pin(pctrl, offset); 1160 1162 unsigned long flags; 1161 1163 u32 ctrl0, cfg; ··· 1174 1176 1175 1177 static void chv_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 1176 1178 { 1177 - struct chv_pinctrl *pctrl = gpiochip_to_pinctrl(chip); 1179 + struct chv_pinctrl *pctrl = gpiochip_get_data(chip); 1178 1180 unsigned pin = chv_gpio_offset_to_pin(pctrl, offset); 1179 1181 unsigned long flags; 1180 1182 void __iomem *reg; ··· 1197 1199 1198 1200 static int chv_gpio_get_direction(struct gpio_chip *chip, unsigned offset) 1199 1201 { 1200 - struct chv_pinctrl *pctrl = gpiochip_to_pinctrl(chip); 1202 + struct chv_pinctrl *pctrl = gpiochip_get_data(chip); 1201 1203 unsigned pin = chv_gpio_offset_to_pin(pctrl, offset); 1202 1204 u32 ctrl0, direction; 1203 1205 unsigned long flags; ··· 1238 1240 static void chv_gpio_irq_ack(struct irq_data *d) 1239 1241 { 1240 1242 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 1241 - struct chv_pinctrl *pctrl = gpiochip_to_pinctrl(gc); 1243 + struct chv_pinctrl *pctrl = gpiochip_get_data(gc); 1242 1244 int pin = chv_gpio_offset_to_pin(pctrl, irqd_to_hwirq(d)); 1243 1245 u32 intr_line; 1244 1246 ··· 1255 1257 static void chv_gpio_irq_mask_unmask(struct irq_data *d, bool mask) 1256 1258 { 1257 1259 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 1258 - struct chv_pinctrl *pctrl = gpiochip_to_pinctrl(gc); 1260 + struct chv_pinctrl *pctrl = gpiochip_get_data(gc); 1259 1261 int pin = chv_gpio_offset_to_pin(pctrl, irqd_to_hwirq(d)); 1260 1262 u32 value, intr_line; 1261 1263 unsigned long flags; ··· 1300 1302 */ 1301 1303 if (irqd_get_trigger_type(d) == IRQ_TYPE_NONE) { 1302 1304 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 1303 - struct chv_pinctrl *pctrl = gpiochip_to_pinctrl(gc); 1305 + struct chv_pinctrl *pctrl = gpiochip_get_data(gc); 1304 1306 unsigned offset = irqd_to_hwirq(d); 1305 1307 int pin = chv_gpio_offset_to_pin(pctrl, offset); 1306 1308 irq_flow_handler_t handler; ··· 1332 1334 static int chv_gpio_irq_type(struct irq_data *d, unsigned type) 1333 1335 { 1334 1336 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 1335 - struct chv_pinctrl *pctrl = gpiochip_to_pinctrl(gc); 1337 + struct chv_pinctrl *pctrl = gpiochip_get_data(gc); 1336 1338 unsigned offset = irqd_to_hwirq(d); 1337 1339 int pin = chv_gpio_offset_to_pin(pctrl, offset); 1338 1340 unsigned long flags; ··· 1405 1407 static void chv_gpio_irq_handler(struct irq_desc *desc) 1406 1408 { 1407 1409 struct gpio_chip *gc = irq_desc_get_handler_data(desc); 1408 - struct chv_pinctrl *pctrl = gpiochip_to_pinctrl(gc); 1410 + struct chv_pinctrl *pctrl = gpiochip_get_data(gc); 1409 1411 struct irq_chip *chip = irq_desc_get_chip(desc); 1410 1412 unsigned long pending; 1411 1413 u32 intr_line; ··· 1434 1436 1435 1437 chip->ngpio = pctrl->community->ngpios; 1436 1438 chip->label = dev_name(pctrl->dev); 1437 - chip->dev = pctrl->dev; 1439 + chip->parent = pctrl->dev; 1438 1440 chip->base = -1; 1439 1441 1440 - ret = gpiochip_add(chip); 1442 + ret = gpiochip_add_data(chip, pctrl); 1441 1443 if (ret) { 1442 1444 dev_err(pctrl->dev, "Failed to register gpiochip\n"); 1443 1445 return ret;
+8 -9
drivers/pinctrl/intel/pinctrl-intel.c
··· 103 103 struct intel_pinctrl_context context; 104 104 }; 105 105 106 - #define gpiochip_to_pinctrl(c) container_of(c, struct intel_pinctrl, chip) 107 106 #define pin_to_padno(c, p) ((p) - (c)->pin_base) 108 107 109 108 static struct intel_community *intel_get_community(struct intel_pinctrl *pctrl, ··· 595 596 596 597 static int intel_gpio_get(struct gpio_chip *chip, unsigned offset) 597 598 { 598 - struct intel_pinctrl *pctrl = gpiochip_to_pinctrl(chip); 599 + struct intel_pinctrl *pctrl = gpiochip_get_data(chip); 599 600 void __iomem *reg; 600 601 601 602 reg = intel_get_padcfg(pctrl, offset, PADCFG0); ··· 607 608 608 609 static void intel_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 609 610 { 610 - struct intel_pinctrl *pctrl = gpiochip_to_pinctrl(chip); 611 + struct intel_pinctrl *pctrl = gpiochip_get_data(chip); 611 612 void __iomem *reg; 612 613 613 614 reg = intel_get_padcfg(pctrl, offset, PADCFG0); ··· 651 652 static void intel_gpio_irq_ack(struct irq_data *d) 652 653 { 653 654 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 654 - struct intel_pinctrl *pctrl = gpiochip_to_pinctrl(gc); 655 + struct intel_pinctrl *pctrl = gpiochip_get_data(gc); 655 656 const struct intel_community *community; 656 657 unsigned pin = irqd_to_hwirq(d); 657 658 ··· 672 673 static void intel_gpio_irq_mask_unmask(struct irq_data *d, bool mask) 673 674 { 674 675 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 675 - struct intel_pinctrl *pctrl = gpiochip_to_pinctrl(gc); 676 + struct intel_pinctrl *pctrl = gpiochip_get_data(gc); 676 677 const struct intel_community *community; 677 678 unsigned pin = irqd_to_hwirq(d); 678 679 unsigned long flags; ··· 712 713 static int intel_gpio_irq_type(struct irq_data *d, unsigned type) 713 714 { 714 715 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 715 - struct intel_pinctrl *pctrl = gpiochip_to_pinctrl(gc); 716 + struct intel_pinctrl *pctrl = gpiochip_get_data(gc); 716 717 unsigned pin = irqd_to_hwirq(d); 717 718 unsigned long flags; 718 719 void __iomem *reg; ··· 766 767 static int intel_gpio_irq_wake(struct irq_data *d, unsigned int on) 767 768 { 768 769 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 769 - struct intel_pinctrl *pctrl = gpiochip_to_pinctrl(gc); 770 + struct intel_pinctrl *pctrl = gpiochip_get_data(gc); 770 771 const struct intel_community *community; 771 772 unsigned pin = irqd_to_hwirq(d); 772 773 unsigned padno, gpp, gpp_offset; ··· 871 872 872 873 pctrl->chip.ngpio = pctrl->soc->npins; 873 874 pctrl->chip.label = dev_name(pctrl->dev); 874 - pctrl->chip.dev = pctrl->dev; 875 + pctrl->chip.parent = pctrl->dev; 875 876 pctrl->chip.base = -1; 876 877 877 - ret = gpiochip_add(&pctrl->chip); 878 + ret = gpiochip_add_data(&pctrl->chip, pctrl); 878 879 if (ret) { 879 880 dev_err(pctrl->dev, "failed to register gpiochip\n"); 880 881 return ret;
+8 -8
drivers/pinctrl/mediatek/pinctrl-mtk-common.c
··· 14 14 */ 15 15 16 16 #include <linux/io.h> 17 - #include <linux/gpio.h> 17 + #include <linux/gpio/driver.h> 18 18 #include <linux/module.h> 19 19 #include <linux/of.h> 20 20 #include <linux/of_address.h> ··· 95 95 { 96 96 unsigned int reg_addr; 97 97 unsigned int bit; 98 - struct mtk_pinctrl *pctl = dev_get_drvdata(chip->dev); 98 + struct mtk_pinctrl *pctl = gpiochip_get_data(chip); 99 99 100 100 reg_addr = mtk_get_port(pctl, offset) + pctl->devdata->dout_offset; 101 101 bit = BIT(offset & 0xf); ··· 750 750 unsigned int bit; 751 751 unsigned int read_val = 0; 752 752 753 - struct mtk_pinctrl *pctl = dev_get_drvdata(chip->dev); 753 + struct mtk_pinctrl *pctl = gpiochip_get_data(chip); 754 754 755 755 reg_addr = mtk_get_port(pctl, offset) + pctl->devdata->dir_offset; 756 756 bit = BIT(offset & 0xf); ··· 763 763 unsigned int reg_addr; 764 764 unsigned int bit; 765 765 unsigned int read_val = 0; 766 - struct mtk_pinctrl *pctl = dev_get_drvdata(chip->dev); 766 + struct mtk_pinctrl *pctl = gpiochip_get_data(chip); 767 767 768 768 reg_addr = mtk_get_port(pctl, offset) + 769 769 pctl->devdata->din_offset; ··· 776 776 static int mtk_gpio_to_irq(struct gpio_chip *chip, unsigned offset) 777 777 { 778 778 const struct mtk_desc_pin *pin; 779 - struct mtk_pinctrl *pctl = dev_get_drvdata(chip->dev); 779 + struct mtk_pinctrl *pctl = gpiochip_get_data(chip); 780 780 int irq; 781 781 782 782 pin = pctl->devdata->pins + offset; ··· 944 944 static int mtk_gpio_set_debounce(struct gpio_chip *chip, unsigned offset, 945 945 unsigned debounce) 946 946 { 947 - struct mtk_pinctrl *pctl = dev_get_drvdata(chip->dev); 947 + struct mtk_pinctrl *pctl = dev_get_drvdata(chip->parent); 948 948 int eint_num, virq, eint_offset; 949 949 unsigned int set_offset, bit, clr_bit, clr_offset, rst, i, unmask, dbnc; 950 950 static const unsigned int dbnc_arr[] = {0 , 1, 16, 32, 64, 128, 256}; ··· 1353 1353 *pctl->chip = mtk_gpio_chip; 1354 1354 pctl->chip->ngpio = pctl->devdata->npins; 1355 1355 pctl->chip->label = dev_name(&pdev->dev); 1356 - pctl->chip->dev = &pdev->dev; 1356 + pctl->chip->parent = &pdev->dev; 1357 1357 pctl->chip->base = -1; 1358 1358 1359 - ret = gpiochip_add(pctl->chip); 1359 + ret = gpiochip_add_data(pctl->chip, pctl); 1360 1360 if (ret) { 1361 1361 ret = -EINVAL; 1362 1362 goto pctrl_error;
+7 -12
drivers/pinctrl/meson/pinctrl-meson.c
··· 448 448 .is_generic = true, 449 449 }; 450 450 451 - static inline struct meson_domain *to_meson_domain(struct gpio_chip *chip) 452 - { 453 - return container_of(chip, struct meson_domain, chip); 454 - } 455 - 456 451 static int meson_gpio_request(struct gpio_chip *chip, unsigned gpio) 457 452 { 458 453 return pinctrl_request_gpio(chip->base + gpio); ··· 455 460 456 461 static void meson_gpio_free(struct gpio_chip *chip, unsigned gpio) 457 462 { 458 - struct meson_domain *domain = to_meson_domain(chip); 463 + struct meson_domain *domain = gpiochip_get_data(chip); 459 464 460 465 pinctrl_free_gpio(domain->data->pin_base + gpio); 461 466 } 462 467 463 468 static int meson_gpio_direction_input(struct gpio_chip *chip, unsigned gpio) 464 469 { 465 - struct meson_domain *domain = to_meson_domain(chip); 470 + struct meson_domain *domain = gpiochip_get_data(chip); 466 471 unsigned int reg, bit, pin; 467 472 struct meson_bank *bank; 468 473 int ret; ··· 480 485 static int meson_gpio_direction_output(struct gpio_chip *chip, unsigned gpio, 481 486 int value) 482 487 { 483 - struct meson_domain *domain = to_meson_domain(chip); 488 + struct meson_domain *domain = gpiochip_get_data(chip); 484 489 unsigned int reg, bit, pin; 485 490 struct meson_bank *bank; 486 491 int ret; ··· 502 507 503 508 static void meson_gpio_set(struct gpio_chip *chip, unsigned gpio, int value) 504 509 { 505 - struct meson_domain *domain = to_meson_domain(chip); 510 + struct meson_domain *domain = gpiochip_get_data(chip); 506 511 unsigned int reg, bit, pin; 507 512 struct meson_bank *bank; 508 513 int ret; ··· 519 524 520 525 static int meson_gpio_get(struct gpio_chip *chip, unsigned gpio) 521 526 { 522 - struct meson_domain *domain = to_meson_domain(chip); 527 + struct meson_domain *domain = gpiochip_get_data(chip); 523 528 unsigned int reg, bit, val, pin; 524 529 struct meson_bank *bank; 525 530 int ret; ··· 557 562 domain = &pc->domains[i]; 558 563 559 564 domain->chip.label = domain->data->name; 560 - domain->chip.dev = pc->dev; 565 + domain->chip.parent = pc->dev; 561 566 domain->chip.request = meson_gpio_request; 562 567 domain->chip.free = meson_gpio_free; 563 568 domain->chip.direction_input = meson_gpio_direction_input; ··· 570 575 domain->chip.of_node = domain->of_node; 571 576 domain->chip.of_gpio_n_cells = 2; 572 577 573 - ret = gpiochip_add(&domain->chip); 578 + ret = gpiochip_add_data(&domain->chip, domain); 574 579 if (ret) { 575 580 dev_err(pc->dev, "can't add gpio chip %s\n", 576 581 domain->data->name);
+13 -21
drivers/pinctrl/nomadik/pinctrl-abx500.c
··· 109 109 int irq_cluster_size; 110 110 }; 111 111 112 - /** 113 - * to_abx500_pinctrl() - get the pointer to abx500_pinctrl 114 - * @chip: Member of the structure abx500_pinctrl 115 - */ 116 - static inline struct abx500_pinctrl *to_abx500_pinctrl(struct gpio_chip *chip) 117 - { 118 - return container_of(chip, struct abx500_pinctrl, chip); 119 - } 120 - 121 112 static int abx500_gpio_get_bit(struct gpio_chip *chip, u8 reg, 122 113 unsigned offset, bool *bit) 123 114 { 124 - struct abx500_pinctrl *pct = to_abx500_pinctrl(chip); 115 + struct abx500_pinctrl *pct = gpiochip_get_data(chip); 125 116 u8 pos = offset % 8; 126 117 u8 val; 127 118 int ret; ··· 134 143 static int abx500_gpio_set_bits(struct gpio_chip *chip, u8 reg, 135 144 unsigned offset, int val) 136 145 { 137 - struct abx500_pinctrl *pct = to_abx500_pinctrl(chip); 146 + struct abx500_pinctrl *pct = gpiochip_get_data(chip); 138 147 u8 pos = offset % 8; 139 148 int ret; 140 149 ··· 155 164 */ 156 165 static int abx500_gpio_get(struct gpio_chip *chip, unsigned offset) 157 166 { 158 - struct abx500_pinctrl *pct = to_abx500_pinctrl(chip); 167 + struct abx500_pinctrl *pct = gpiochip_get_data(chip); 159 168 bool bit; 160 169 bool is_out; 161 170 u8 gpio_offset = offset - 1; ··· 183 192 184 193 static void abx500_gpio_set(struct gpio_chip *chip, unsigned offset, int val) 185 194 { 186 - struct abx500_pinctrl *pct = to_abx500_pinctrl(chip); 195 + struct abx500_pinctrl *pct = gpiochip_get_data(chip); 187 196 int ret; 188 197 189 198 ret = abx500_gpio_set_bits(chip, AB8500_GPIO_OUT1_REG, offset, val); ··· 263 272 264 273 static bool abx500_pullud_supported(struct gpio_chip *chip, unsigned gpio) 265 274 { 266 - struct abx500_pinctrl *pct = to_abx500_pinctrl(chip); 275 + struct abx500_pinctrl *pct = gpiochip_get_data(chip); 267 276 struct pullud *pullud = pct->soc->pullud; 268 277 269 278 return (pullud && ··· 275 284 unsigned offset, 276 285 int val) 277 286 { 278 - struct abx500_pinctrl *pct = to_abx500_pinctrl(chip); 287 + struct abx500_pinctrl *pct = gpiochip_get_data(chip); 279 288 unsigned gpio; 280 289 int ret; 281 290 ··· 323 332 324 333 static int abx500_gpio_to_irq(struct gpio_chip *chip, unsigned offset) 325 334 { 326 - struct abx500_pinctrl *pct = to_abx500_pinctrl(chip); 335 + struct abx500_pinctrl *pct = gpiochip_get_data(chip); 327 336 /* The AB8500 GPIO numbers are off by one */ 328 337 int gpio = offset + 1; 329 338 int hwirq; ··· 625 634 { 626 635 unsigned i; 627 636 unsigned gpio = chip->base; 628 - struct abx500_pinctrl *pct = to_abx500_pinctrl(chip); 637 + struct abx500_pinctrl *pct = gpiochip_get_data(chip); 629 638 struct pinctrl_dev *pctldev = pct->pctldev; 630 639 631 640 for (i = 0; i < chip->ngpio; i++, gpio++) { ··· 977 986 param = pinconf_to_config_param(configs[i]); 978 987 argument = pinconf_to_config_argument(configs[i]); 979 988 980 - dev_dbg(chip->dev, "pin %d [%#lx]: %s %s\n", 989 + dev_dbg(chip->parent, "pin %d [%#lx]: %s %s\n", 981 990 pin, configs[i], 982 991 (param == PIN_CONFIG_OUTPUT) ? "output " : "input", 983 992 (param == PIN_CONFIG_OUTPUT) ? ··· 1068 1077 break; 1069 1078 1070 1079 default: 1071 - dev_err(chip->dev, "illegal configuration requested\n"); 1080 + dev_err(chip->parent, 1081 + "illegal configuration requested\n"); 1072 1082 } 1073 1083 } /* for each config */ 1074 1084 out: ··· 1164 1172 pct->dev = &pdev->dev; 1165 1173 pct->parent = dev_get_drvdata(pdev->dev.parent); 1166 1174 pct->chip = abx500gpio_chip; 1167 - pct->chip.dev = &pdev->dev; 1175 + pct->chip.parent = &pdev->dev; 1168 1176 pct->chip.base = -1; /* Dynamic allocation */ 1169 1177 1170 1178 match = of_match_device(abx500_gpio_match, &pdev->dev); ··· 1202 1210 pct->irq_cluster = pct->soc->gpio_irq_cluster; 1203 1211 pct->irq_cluster_size = pct->soc->ngpio_irq_cluster; 1204 1212 1205 - ret = gpiochip_add(&pct->chip); 1213 + ret = gpiochip_add_data(&pct->chip, pct); 1206 1214 if (ret) { 1207 1215 dev_err(&pdev->dev, "unable to add gpiochip: %d\n", ret); 1208 1216 return ret;
+14 -19
drivers/pinctrl/nomadik/pinctrl-nomadik.c
··· 438 438 nmk_chip->addr + NMK_GPIO_FIMSC); 439 439 } 440 440 441 - dev_dbg(nmk_chip->chip.dev, "%d: clearing interrupt mask\n", gpio); 441 + dev_dbg(nmk_chip->chip.parent, "%d: clearing interrupt mask\n", gpio); 442 442 } 443 443 444 444 static void nmk_write_masked(void __iomem *reg, u32 mask, u32 value) ··· 646 646 static void nmk_gpio_irq_ack(struct irq_data *d) 647 647 { 648 648 struct gpio_chip *chip = irq_data_get_irq_chip_data(d); 649 - struct nmk_gpio_chip *nmk_chip = container_of(chip, struct nmk_gpio_chip, chip); 649 + struct nmk_gpio_chip *nmk_chip = gpiochip_get_data(chip); 650 650 651 651 clk_enable(nmk_chip->clk); 652 652 writel(nmk_gpio_get_bitmask(d->hwirq), nmk_chip->addr + NMK_GPIO_IC); ··· 863 863 static void nmk_gpio_irq_handler(struct irq_desc *desc) 864 864 { 865 865 struct gpio_chip *chip = irq_desc_get_handler_data(desc); 866 - struct nmk_gpio_chip *nmk_chip = container_of(chip, struct nmk_gpio_chip, chip); 866 + struct nmk_gpio_chip *nmk_chip = gpiochip_get_data(chip); 867 867 u32 status; 868 868 869 869 clk_enable(nmk_chip->clk); ··· 876 876 static void nmk_gpio_latent_irq_handler(struct irq_desc *desc) 877 877 { 878 878 struct gpio_chip *chip = irq_desc_get_handler_data(desc); 879 - struct nmk_gpio_chip *nmk_chip = container_of(chip, struct nmk_gpio_chip, chip); 879 + struct nmk_gpio_chip *nmk_chip = gpiochip_get_data(chip); 880 880 u32 status = nmk_chip->get_latent_status(nmk_chip->bank); 881 881 882 882 __nmk_gpio_irq_handler(desc, status); ··· 886 886 887 887 static int nmk_gpio_make_input(struct gpio_chip *chip, unsigned offset) 888 888 { 889 - struct nmk_gpio_chip *nmk_chip = 890 - container_of(chip, struct nmk_gpio_chip, chip); 889 + struct nmk_gpio_chip *nmk_chip = gpiochip_get_data(chip); 891 890 892 891 clk_enable(nmk_chip->clk); 893 892 ··· 899 900 900 901 static int nmk_gpio_get_input(struct gpio_chip *chip, unsigned offset) 901 902 { 902 - struct nmk_gpio_chip *nmk_chip = 903 - container_of(chip, struct nmk_gpio_chip, chip); 903 + struct nmk_gpio_chip *nmk_chip = gpiochip_get_data(chip); 904 904 u32 bit = 1 << offset; 905 905 int value; 906 906 ··· 915 917 static void nmk_gpio_set_output(struct gpio_chip *chip, unsigned offset, 916 918 int val) 917 919 { 918 - struct nmk_gpio_chip *nmk_chip = 919 - container_of(chip, struct nmk_gpio_chip, chip); 920 + struct nmk_gpio_chip *nmk_chip = gpiochip_get_data(chip); 920 921 921 922 clk_enable(nmk_chip->clk); 922 923 ··· 927 930 static int nmk_gpio_make_output(struct gpio_chip *chip, unsigned offset, 928 931 int val) 929 932 { 930 - struct nmk_gpio_chip *nmk_chip = 931 - container_of(chip, struct nmk_gpio_chip, chip); 933 + struct nmk_gpio_chip *nmk_chip = gpiochip_get_data(chip); 932 934 933 935 clk_enable(nmk_chip->clk); 934 936 ··· 947 951 unsigned offset, unsigned gpio) 948 952 { 949 953 const char *label = gpiochip_is_requested(chip, offset); 950 - struct nmk_gpio_chip *nmk_chip = 951 - container_of(chip, struct nmk_gpio_chip, chip); 954 + struct nmk_gpio_chip *nmk_chip = gpiochip_get_data(chip); 952 955 int mode; 953 956 bool is_out; 954 957 bool data_out; ··· 1183 1188 chip->base = id * NMK_GPIO_PER_CHIP; 1184 1189 chip->ngpio = NMK_GPIO_PER_CHIP; 1185 1190 chip->label = dev_name(&gpio_pdev->dev); 1186 - chip->dev = &gpio_pdev->dev; 1191 + chip->parent = &gpio_pdev->dev; 1187 1192 1188 1193 res = platform_get_resource(gpio_pdev, IORESOURCE_MEM, 0); 1189 1194 base = devm_ioremap_resource(&pdev->dev, res); ··· 1273 1278 clk_disable(nmk_chip->clk); 1274 1279 chip->of_node = np; 1275 1280 1276 - ret = gpiochip_add(chip); 1281 + ret = gpiochip_add_data(chip, nmk_chip); 1277 1282 if (ret) 1278 1283 return ret; 1279 1284 ··· 1784 1789 return -EINVAL; 1785 1790 } 1786 1791 chip = range->gc; 1787 - nmk_chip = container_of(chip, struct nmk_gpio_chip, chip); 1792 + nmk_chip = gpiochip_get_data(chip); 1788 1793 1789 1794 dev_dbg(npct->dev, "enable pin %u as GPIO\n", offset); 1790 1795 ··· 1885 1890 if (slpm_val) 1886 1891 val = slpm_val - 1; 1887 1892 1888 - dev_dbg(nmk_chip->chip.dev, 1893 + dev_dbg(nmk_chip->chip.parent, 1889 1894 "pin %d: sleep pull %s, dir %s, val %s\n", 1890 1895 pin, 1891 1896 slpm_pull ? pullnames[pull] : "same", ··· 1894 1899 slpm_val ? (val ? "high" : "low") : "same"); 1895 1900 } 1896 1901 1897 - dev_dbg(nmk_chip->chip.dev, 1902 + dev_dbg(nmk_chip->chip.parent, 1898 1903 "pin %d [%#lx]: pull %s, slpm %s (%s%s), lowemi %s\n", 1899 1904 pin, cfg, pullnames[pull], slpmnames[slpm], 1900 1905 output ? "output " : "input",
+8 -8
drivers/pinctrl/pinctrl-adi2.c
··· 636 636 if (range == NULL) /* should not happen */ 637 637 return -ENODEV; 638 638 639 - port = container_of(range->gc, struct gpio_port, chip); 639 + port = gpiochip_get_data(range->gc); 640 640 641 641 spin_lock_irqsave(&port->lock, flags); 642 642 ··· 684 684 unsigned long flags; 685 685 u8 offset; 686 686 687 - port = container_of(range->gc, struct gpio_port, chip); 687 + port = gpiochip_get_data(range->gc); 688 688 offset = pin_to_offset(range, pin); 689 689 690 690 spin_lock_irqsave(&port->lock, flags); ··· 718 718 struct gpio_port *port; 719 719 unsigned long flags; 720 720 721 - port = container_of(chip, struct gpio_port, chip); 721 + port = gpiochip_get_data(chip); 722 722 723 723 spin_lock_irqsave(&port->lock, flags); 724 724 ··· 733 733 static void adi_gpio_set_value(struct gpio_chip *chip, unsigned offset, 734 734 int value) 735 735 { 736 - struct gpio_port *port = container_of(chip, struct gpio_port, chip); 736 + struct gpio_port *port = gpiochip_get_data(chip); 737 737 struct gpio_port_t *regs = port->regs; 738 738 unsigned long flags; 739 739 ··· 750 750 static int adi_gpio_direction_output(struct gpio_chip *chip, unsigned offset, 751 751 int value) 752 752 { 753 - struct gpio_port *port = container_of(chip, struct gpio_port, chip); 753 + struct gpio_port *port = gpiochip_get_data(chip); 754 754 struct gpio_port_t *regs = port->regs; 755 755 unsigned long flags; 756 756 ··· 770 770 771 771 static int adi_gpio_get_value(struct gpio_chip *chip, unsigned offset) 772 772 { 773 - struct gpio_port *port = container_of(chip, struct gpio_port, chip); 773 + struct gpio_port *port = gpiochip_get_data(chip); 774 774 struct gpio_port_t *regs = port->regs; 775 775 unsigned long flags; 776 776 int ret; ··· 786 786 787 787 static int adi_gpio_to_irq(struct gpio_chip *chip, unsigned offset) 788 788 { 789 - struct gpio_port *port = container_of(chip, struct gpio_port, chip); 789 + struct gpio_port *port = gpiochip_get_data(chip); 790 790 791 791 if (port->irq_base >= 0) 792 792 return irq_find_mapping(port->domain, offset); ··· 994 994 port->chip.ngpio = port->width; 995 995 gpio = port->chip.base + port->width; 996 996 997 - ret = gpiochip_add(&port->chip); 997 + ret = gpiochip_add_data(&port->chip, port); 998 998 if (ret) { 999 999 dev_err(&pdev->dev, "Fail to add GPIO chip.\n"); 1000 1000 goto out_remove_domain;
+15 -20
drivers/pinctrl/pinctrl-amd.c
··· 35 35 #include "pinctrl-utils.h" 36 36 #include "pinctrl-amd.h" 37 37 38 - static inline struct amd_gpio *to_amd_gpio(struct gpio_chip *gc) 39 - { 40 - return container_of(gc, struct amd_gpio, gc); 41 - } 42 - 43 38 static int amd_gpio_direction_input(struct gpio_chip *gc, unsigned offset) 44 39 { 45 40 unsigned long flags; 46 41 u32 pin_reg; 47 - struct amd_gpio *gpio_dev = to_amd_gpio(gc); 42 + struct amd_gpio *gpio_dev = gpiochip_get_data(gc); 48 43 49 44 spin_lock_irqsave(&gpio_dev->lock, flags); 50 45 pin_reg = readl(gpio_dev->base + offset * 4); ··· 66 71 { 67 72 u32 pin_reg; 68 73 unsigned long flags; 69 - struct amd_gpio *gpio_dev = to_amd_gpio(gc); 74 + struct amd_gpio *gpio_dev = gpiochip_get_data(gc); 70 75 71 76 spin_lock_irqsave(&gpio_dev->lock, flags); 72 77 pin_reg = readl(gpio_dev->base + offset * 4); ··· 85 90 { 86 91 u32 pin_reg; 87 92 unsigned long flags; 88 - struct amd_gpio *gpio_dev = to_amd_gpio(gc); 93 + struct amd_gpio *gpio_dev = gpiochip_get_data(gc); 89 94 90 95 spin_lock_irqsave(&gpio_dev->lock, flags); 91 96 pin_reg = readl(gpio_dev->base + offset * 4); ··· 98 103 { 99 104 u32 pin_reg; 100 105 unsigned long flags; 101 - struct amd_gpio *gpio_dev = to_amd_gpio(gc); 106 + struct amd_gpio *gpio_dev = gpiochip_get_data(gc); 102 107 103 108 spin_lock_irqsave(&gpio_dev->lock, flags); 104 109 pin_reg = readl(gpio_dev->base + offset * 4); ··· 117 122 u32 pin_reg; 118 123 int ret = 0; 119 124 unsigned long flags; 120 - struct amd_gpio *gpio_dev = to_amd_gpio(gc); 125 + struct amd_gpio *gpio_dev = gpiochip_get_data(gc); 121 126 122 127 spin_lock_irqsave(&gpio_dev->lock, flags); 123 128 pin_reg = readl(gpio_dev->base + offset * 4); ··· 181 186 u32 pin_reg; 182 187 unsigned long flags; 183 188 unsigned int bank, i, pin_num; 184 - struct amd_gpio *gpio_dev = to_amd_gpio(gc); 189 + struct amd_gpio *gpio_dev = gpiochip_get_data(gc); 185 190 186 191 char *level_trig; 187 192 char *active_level; ··· 322 327 u32 pin_reg; 323 328 unsigned long flags; 324 329 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 325 - struct amd_gpio *gpio_dev = to_amd_gpio(gc); 330 + struct amd_gpio *gpio_dev = gpiochip_get_data(gc); 326 331 327 332 spin_lock_irqsave(&gpio_dev->lock, flags); 328 333 pin_reg = readl(gpio_dev->base + (d->hwirq)*4); ··· 346 351 u32 pin_reg; 347 352 unsigned long flags; 348 353 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 349 - struct amd_gpio *gpio_dev = to_amd_gpio(gc); 354 + struct amd_gpio *gpio_dev = gpiochip_get_data(gc); 350 355 351 356 spin_lock_irqsave(&gpio_dev->lock, flags); 352 357 pin_reg = readl(gpio_dev->base + (d->hwirq)*4); ··· 361 366 u32 pin_reg; 362 367 unsigned long flags; 363 368 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 364 - struct amd_gpio *gpio_dev = to_amd_gpio(gc); 369 + struct amd_gpio *gpio_dev = gpiochip_get_data(gc); 365 370 366 371 spin_lock_irqsave(&gpio_dev->lock, flags); 367 372 pin_reg = readl(gpio_dev->base + (d->hwirq)*4); ··· 375 380 u32 pin_reg; 376 381 unsigned long flags; 377 382 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 378 - struct amd_gpio *gpio_dev = to_amd_gpio(gc); 383 + struct amd_gpio *gpio_dev = gpiochip_get_data(gc); 379 384 380 385 spin_lock_irqsave(&gpio_dev->lock, flags); 381 386 pin_reg = readl(gpio_dev->base + (d->hwirq)*4); ··· 389 394 u32 reg; 390 395 unsigned long flags; 391 396 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 392 - struct amd_gpio *gpio_dev = to_amd_gpio(gc); 397 + struct amd_gpio *gpio_dev = gpiochip_get_data(gc); 393 398 394 399 spin_lock_irqsave(&gpio_dev->lock, flags); 395 400 reg = readl(gpio_dev->base + WAKE_INT_MASTER_REG); ··· 404 409 u32 pin_reg; 405 410 unsigned long flags; 406 411 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 407 - struct amd_gpio *gpio_dev = to_amd_gpio(gc); 412 + struct amd_gpio *gpio_dev = gpiochip_get_data(gc); 408 413 409 414 spin_lock_irqsave(&gpio_dev->lock, flags); 410 415 pin_reg = readl(gpio_dev->base + (d->hwirq)*4); ··· 499 504 unsigned long flags; 500 505 struct irq_chip *chip = irq_desc_get_chip(desc); 501 506 struct gpio_chip *gc = irq_desc_get_handler_data(desc); 502 - struct amd_gpio *gpio_dev = to_amd_gpio(gc); 507 + struct amd_gpio *gpio_dev = gpiochip_get_data(gc); 503 508 504 509 chained_irq_enter(chip, desc); 505 510 /*enable GPIO interrupt again*/ ··· 773 778 gpio_dev->gc.base = 0; 774 779 gpio_dev->gc.label = pdev->name; 775 780 gpio_dev->gc.owner = THIS_MODULE; 776 - gpio_dev->gc.dev = &pdev->dev; 781 + gpio_dev->gc.parent = &pdev->dev; 777 782 gpio_dev->gc.ngpio = TOTAL_NUMBER_OF_PINS; 778 783 #if defined(CONFIG_OF_GPIO) 779 784 gpio_dev->gc.of_node = pdev->dev.of_node; ··· 790 795 return PTR_ERR(gpio_dev->pctrl); 791 796 } 792 797 793 - ret = gpiochip_add(&gpio_dev->gc); 798 + ret = gpiochip_add_data(&gpio_dev->gc, gpio_dev); 794 799 if (ret) 795 800 goto out1; 796 801
+5 -10
drivers/pinctrl/pinctrl-as3722.c
··· 436 436 .owner = THIS_MODULE, 437 437 }; 438 438 439 - static inline struct as3722_pctrl_info *to_as_pci(struct gpio_chip *chip) 440 - { 441 - return container_of(chip, struct as3722_pctrl_info, gpio_chip); 442 - } 443 - 444 439 static int as3722_gpio_get(struct gpio_chip *chip, unsigned offset) 445 440 { 446 - struct as3722_pctrl_info *as_pci = to_as_pci(chip); 441 + struct as3722_pctrl_info *as_pci = gpiochip_get_data(chip); 447 442 struct as3722 *as3722 = as_pci->as3722; 448 443 int ret; 449 444 u32 reg; ··· 486 491 static void as3722_gpio_set(struct gpio_chip *chip, unsigned offset, 487 492 int value) 488 493 { 489 - struct as3722_pctrl_info *as_pci = to_as_pci(chip); 494 + struct as3722_pctrl_info *as_pci = gpiochip_get_data(chip); 490 495 struct as3722 *as3722 = as_pci->as3722; 491 496 int en_invert; 492 497 u32 val; ··· 526 531 527 532 static int as3722_gpio_to_irq(struct gpio_chip *chip, unsigned offset) 528 533 { 529 - struct as3722_pctrl_info *as_pci = to_as_pci(chip); 534 + struct as3722_pctrl_info *as_pci = gpiochip_get_data(chip); 530 535 531 536 return as3722_irq_get_virq(as_pci->as3722, offset); 532 537 } ··· 577 582 } 578 583 579 584 as_pci->gpio_chip = as3722_gpio_chip; 580 - as_pci->gpio_chip.dev = &pdev->dev; 585 + as_pci->gpio_chip.parent = &pdev->dev; 581 586 as_pci->gpio_chip.of_node = pdev->dev.parent->of_node; 582 - ret = gpiochip_add(&as_pci->gpio_chip); 587 + ret = gpiochip_add_data(&as_pci->gpio_chip, as_pci); 583 588 if (ret < 0) { 584 589 dev_err(&pdev->dev, "Couldn't register gpiochip, %d\n", ret); 585 590 goto fail_chip_add;
+9 -7
drivers/pinctrl/pinctrl-at91-pio4.c
··· 15 15 */ 16 16 17 17 #include <linux/clk.h> 18 + #include <linux/gpio/driver.h> 19 + /* FIXME: needed for gpio_to_irq(), get rid of this */ 18 20 #include <linux/gpio.h> 19 21 #include <linux/interrupt.h> 20 22 #include <linux/io.h> ··· 292 290 293 291 static int atmel_gpio_direction_input(struct gpio_chip *chip, unsigned offset) 294 292 { 295 - struct atmel_pioctrl *atmel_pioctrl = dev_get_drvdata(chip->dev); 293 + struct atmel_pioctrl *atmel_pioctrl = gpiochip_get_data(chip); 296 294 struct atmel_pin *pin = atmel_pioctrl->pins[offset]; 297 295 unsigned reg; 298 296 ··· 307 305 308 306 static int atmel_gpio_get(struct gpio_chip *chip, unsigned offset) 309 307 { 310 - struct atmel_pioctrl *atmel_pioctrl = dev_get_drvdata(chip->dev); 308 + struct atmel_pioctrl *atmel_pioctrl = gpiochip_get_data(chip); 311 309 struct atmel_pin *pin = atmel_pioctrl->pins[offset]; 312 310 unsigned reg; 313 311 ··· 319 317 static int atmel_gpio_direction_output(struct gpio_chip *chip, unsigned offset, 320 318 int value) 321 319 { 322 - struct atmel_pioctrl *atmel_pioctrl = dev_get_drvdata(chip->dev); 320 + struct atmel_pioctrl *atmel_pioctrl = gpiochip_get_data(chip); 323 321 struct atmel_pin *pin = atmel_pioctrl->pins[offset]; 324 322 unsigned reg; 325 323 ··· 338 336 339 337 static void atmel_gpio_set(struct gpio_chip *chip, unsigned offset, int val) 340 338 { 341 - struct atmel_pioctrl *atmel_pioctrl = dev_get_drvdata(chip->dev); 339 + struct atmel_pioctrl *atmel_pioctrl = gpiochip_get_data(chip); 342 340 struct atmel_pin *pin = atmel_pioctrl->pins[offset]; 343 341 344 342 atmel_gpio_write(atmel_pioctrl, pin->bank, ··· 348 346 349 347 static int atmel_gpio_to_irq(struct gpio_chip *chip, unsigned offset) 350 348 { 351 - struct atmel_pioctrl *atmel_pioctrl = dev_get_drvdata(chip->dev); 349 + struct atmel_pioctrl *atmel_pioctrl = gpiochip_get_data(chip); 352 350 353 351 return irq_find_mapping(atmel_pioctrl->irq_domain, offset); 354 352 } ··· 974 972 atmel_pioctrl->gpio_chip->of_node = dev->of_node; 975 973 atmel_pioctrl->gpio_chip->ngpio = atmel_pioctrl->npins; 976 974 atmel_pioctrl->gpio_chip->label = dev_name(dev); 977 - atmel_pioctrl->gpio_chip->dev = dev; 975 + atmel_pioctrl->gpio_chip->parent = dev; 978 976 atmel_pioctrl->gpio_chip->names = atmel_pioctrl->group_names; 979 977 980 978 atmel_pioctrl->pm_wakeup_sources = devm_kzalloc(dev, ··· 1042 1040 goto pinctrl_register_error; 1043 1041 } 1044 1042 1045 - ret = gpiochip_add(atmel_pioctrl->gpio_chip); 1043 + ret = gpiochip_add_data(atmel_pioctrl->gpio_chip, atmel_pioctrl); 1046 1044 if (ret) { 1047 1045 dev_err(dev, "failed to add gpiochip\n"); 1048 1046 goto gpiochip_add_error;
+12 -16
drivers/pinctrl/pinctrl-at91.c
··· 45 45 struct at91_pinctrl_mux_ops *ops; /* ops */ 46 46 }; 47 47 48 - #define to_at91_gpio_chip(c) container_of(c, struct at91_gpio_chip, chip) 49 - 50 48 static struct at91_gpio_chip *gpio_chips[MAX_GPIO_BANKS]; 51 49 52 50 static int gpio_banks; ··· 809 811 return -EINVAL; 810 812 } 811 813 chip = range->gc; 812 - at91_chip = container_of(chip, struct at91_gpio_chip, chip); 814 + at91_chip = gpiochip_get_data(chip); 813 815 814 816 dev_dbg(npct->dev, "enable pin %u as GPIO\n", offset); 815 817 ··· 1280 1282 1281 1283 static int at91_gpio_get_direction(struct gpio_chip *chip, unsigned offset) 1282 1284 { 1283 - struct at91_gpio_chip *at91_gpio = to_at91_gpio_chip(chip); 1285 + struct at91_gpio_chip *at91_gpio = gpiochip_get_data(chip); 1284 1286 void __iomem *pio = at91_gpio->regbase; 1285 1287 unsigned mask = 1 << offset; 1286 1288 u32 osr; ··· 1291 1293 1292 1294 static int at91_gpio_direction_input(struct gpio_chip *chip, unsigned offset) 1293 1295 { 1294 - struct at91_gpio_chip *at91_gpio = to_at91_gpio_chip(chip); 1296 + struct at91_gpio_chip *at91_gpio = gpiochip_get_data(chip); 1295 1297 void __iomem *pio = at91_gpio->regbase; 1296 1298 unsigned mask = 1 << offset; 1297 1299 ··· 1301 1303 1302 1304 static int at91_gpio_get(struct gpio_chip *chip, unsigned offset) 1303 1305 { 1304 - struct at91_gpio_chip *at91_gpio = to_at91_gpio_chip(chip); 1306 + struct at91_gpio_chip *at91_gpio = gpiochip_get_data(chip); 1305 1307 void __iomem *pio = at91_gpio->regbase; 1306 1308 unsigned mask = 1 << offset; 1307 1309 u32 pdsr; ··· 1313 1315 static void at91_gpio_set(struct gpio_chip *chip, unsigned offset, 1314 1316 int val) 1315 1317 { 1316 - struct at91_gpio_chip *at91_gpio = to_at91_gpio_chip(chip); 1318 + struct at91_gpio_chip *at91_gpio = gpiochip_get_data(chip); 1317 1319 void __iomem *pio = at91_gpio->regbase; 1318 1320 unsigned mask = 1 << offset; 1319 1321 ··· 1323 1325 static void at91_gpio_set_multiple(struct gpio_chip *chip, 1324 1326 unsigned long *mask, unsigned long *bits) 1325 1327 { 1326 - struct at91_gpio_chip *at91_gpio = to_at91_gpio_chip(chip); 1328 + struct at91_gpio_chip *at91_gpio = gpiochip_get_data(chip); 1327 1329 void __iomem *pio = at91_gpio->regbase; 1328 1330 1329 1331 #define BITS_MASK(bits) (((bits) == 32) ? ~0U : (BIT(bits) - 1)) ··· 1338 1340 static int at91_gpio_direction_output(struct gpio_chip *chip, unsigned offset, 1339 1341 int val) 1340 1342 { 1341 - struct at91_gpio_chip *at91_gpio = to_at91_gpio_chip(chip); 1343 + struct at91_gpio_chip *at91_gpio = gpiochip_get_data(chip); 1342 1344 void __iomem *pio = at91_gpio->regbase; 1343 1345 unsigned mask = 1 << offset; 1344 1346 ··· 1353 1355 { 1354 1356 enum at91_mux mode; 1355 1357 int i; 1356 - struct at91_gpio_chip *at91_gpio = to_at91_gpio_chip(chip); 1358 + struct at91_gpio_chip *at91_gpio = gpiochip_get_data(chip); 1357 1359 void __iomem *pio = at91_gpio->regbase; 1358 1360 1359 1361 for (i = 0; i < chip->ngpio; i++) { ··· 1568 1570 { 1569 1571 struct irq_chip *chip = irq_desc_get_chip(desc); 1570 1572 struct gpio_chip *gpio_chip = irq_desc_get_handler_data(desc); 1571 - struct at91_gpio_chip *at91_gpio = container_of(gpio_chip, 1572 - struct at91_gpio_chip, chip); 1573 - 1573 + struct at91_gpio_chip *at91_gpio = gpiochip_get_data(gpio_chip); 1574 1574 void __iomem *pio = at91_gpio->regbase; 1575 1575 unsigned long isr; 1576 1576 int n; ··· 1644 1648 return 0; 1645 1649 } 1646 1650 1647 - prev = container_of(gpiochip_prev, struct at91_gpio_chip, chip); 1651 + prev = gpiochip_get_data(gpiochip_prev); 1648 1652 1649 1653 /* we can only have 2 banks before */ 1650 1654 for (i = 0; i < 2; i++) { ··· 1746 1750 chip = &at91_chip->chip; 1747 1751 chip->of_node = np; 1748 1752 chip->label = dev_name(&pdev->dev); 1749 - chip->dev = &pdev->dev; 1753 + chip->parent = &pdev->dev; 1750 1754 chip->owner = THIS_MODULE; 1751 1755 chip->base = alias_idx * MAX_NB_GPIO_PER_BANK; 1752 1756 ··· 1779 1783 range->npins = chip->ngpio; 1780 1784 range->gc = chip; 1781 1785 1782 - ret = gpiochip_add(chip); 1786 + ret = gpiochip_add_data(chip, at91_chip); 1783 1787 if (ret) 1784 1788 goto gpiochip_add_err; 1785 1789
+13 -22
drivers/pinctrl/pinctrl-coh901.c
··· 208 208 } 209 209 }; 210 210 211 - /** 212 - * to_u300_gpio() - get the pointer to u300_gpio 213 - * @chip: the gpio chip member of the structure u300_gpio 214 - */ 215 - static inline struct u300_gpio *to_u300_gpio(struct gpio_chip *chip) 216 - { 217 - return container_of(chip, struct u300_gpio, chip); 218 - } 219 - 220 211 static int u300_gpio_get(struct gpio_chip *chip, unsigned offset) 221 212 { 222 - struct u300_gpio *gpio = to_u300_gpio(chip); 213 + struct u300_gpio *gpio = gpiochip_get_data(chip); 223 214 224 - return readl(U300_PIN_REG(offset, dir)) & U300_PIN_BIT(offset); 215 + return !!(readl(U300_PIN_REG(offset, dir)) & U300_PIN_BIT(offset)); 225 216 } 226 217 227 218 static void u300_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 228 219 { 229 - struct u300_gpio *gpio = to_u300_gpio(chip); 220 + struct u300_gpio *gpio = gpiochip_get_data(chip); 230 221 unsigned long flags; 231 222 u32 val; 232 223 ··· 234 243 235 244 static int u300_gpio_direction_input(struct gpio_chip *chip, unsigned offset) 236 245 { 237 - struct u300_gpio *gpio = to_u300_gpio(chip); 246 + struct u300_gpio *gpio = gpiochip_get_data(chip); 238 247 unsigned long flags; 239 248 u32 val; 240 249 ··· 250 259 static int u300_gpio_direction_output(struct gpio_chip *chip, unsigned offset, 251 260 int value) 252 261 { 253 - struct u300_gpio *gpio = to_u300_gpio(chip); 262 + struct u300_gpio *gpio = gpiochip_get_data(chip); 254 263 unsigned long flags; 255 264 u32 oldmode; 256 265 u32 val; ··· 281 290 unsigned offset, 282 291 unsigned long *config) 283 292 { 284 - struct u300_gpio *gpio = to_u300_gpio(chip); 293 + struct u300_gpio *gpio = gpiochip_get_data(chip); 285 294 enum pin_config_param param = (enum pin_config_param) *config; 286 295 bool biasmode; 287 296 u32 drmode; ··· 339 348 int u300_gpio_config_set(struct gpio_chip *chip, unsigned offset, 340 349 enum pin_config_param param) 341 350 { 342 - struct u300_gpio *gpio = to_u300_gpio(chip); 351 + struct u300_gpio *gpio = gpiochip_get_data(chip); 343 352 unsigned long flags; 344 353 u32 val; 345 354 ··· 420 429 static int u300_gpio_irq_type(struct irq_data *d, unsigned trigger) 421 430 { 422 431 struct gpio_chip *chip = irq_data_get_irq_chip_data(d); 423 - struct u300_gpio *gpio = to_u300_gpio(chip); 432 + struct u300_gpio *gpio = gpiochip_get_data(chip); 424 433 struct u300_gpio_port *port = &gpio->ports[d->hwirq >> 3]; 425 434 int offset = d->hwirq; 426 435 u32 val; ··· 457 466 static void u300_gpio_irq_enable(struct irq_data *d) 458 467 { 459 468 struct gpio_chip *chip = irq_data_get_irq_chip_data(d); 460 - struct u300_gpio *gpio = to_u300_gpio(chip); 469 + struct u300_gpio *gpio = gpiochip_get_data(chip); 461 470 struct u300_gpio_port *port = &gpio->ports[d->hwirq >> 3]; 462 471 int offset = d->hwirq; 463 472 u32 val; ··· 474 483 static void u300_gpio_irq_disable(struct irq_data *d) 475 484 { 476 485 struct gpio_chip *chip = irq_data_get_irq_chip_data(d); 477 - struct u300_gpio *gpio = to_u300_gpio(chip); 486 + struct u300_gpio *gpio = gpiochip_get_data(chip); 478 487 int offset = d->hwirq; 479 488 u32 val; 480 489 unsigned long flags; ··· 497 506 unsigned int irq = irq_desc_get_irq(desc); 498 507 struct irq_chip *parent_chip = irq_desc_get_chip(desc); 499 508 struct gpio_chip *chip = irq_desc_get_handler_data(desc); 500 - struct u300_gpio *gpio = to_u300_gpio(chip); 509 + struct u300_gpio *gpio = gpiochip_get_data(chip); 501 510 struct u300_gpio_port *port = &gpio->ports[irq - chip->base]; 502 511 int pinoffset = port->number << 3; /* get the right stride */ 503 512 unsigned long val; ··· 628 637 629 638 gpio->chip = u300_gpio_chip; 630 639 gpio->chip.ngpio = U300_GPIO_NUM_PORTS * U300_GPIO_PINS_PER_PORT; 631 - gpio->chip.dev = &pdev->dev; 640 + gpio->chip.parent = &pdev->dev; 632 641 gpio->chip.base = 0; 633 642 gpio->dev = &pdev->dev; 634 643 ··· 675 684 #ifdef CONFIG_OF_GPIO 676 685 gpio->chip.of_node = pdev->dev.of_node; 677 686 #endif 678 - err = gpiochip_add(&gpio->chip); 687 + err = gpiochip_add_data(&gpio->chip, gpio); 679 688 if (err) { 680 689 dev_err(gpio->dev, "unable to add gpiochip: %d\n", err); 681 690 goto err_no_chip;
+6 -6
drivers/pinctrl/pinctrl-digicolor.c
··· 171 171 172 172 static int dc_gpio_direction_input(struct gpio_chip *chip, unsigned gpio) 173 173 { 174 - struct dc_pinmap *pmap = container_of(chip, struct dc_pinmap, chip); 174 + struct dc_pinmap *pmap = gpiochip_get_data(chip); 175 175 int reg_off = GP_DRIVE0(gpio/PINS_PER_COLLECTION); 176 176 int bit_off = gpio % PINS_PER_COLLECTION; 177 177 u8 drive; ··· 191 191 static int dc_gpio_direction_output(struct gpio_chip *chip, unsigned gpio, 192 192 int value) 193 193 { 194 - struct dc_pinmap *pmap = container_of(chip, struct dc_pinmap, chip); 194 + struct dc_pinmap *pmap = gpiochip_get_data(chip); 195 195 int reg_off = GP_DRIVE0(gpio/PINS_PER_COLLECTION); 196 196 int bit_off = gpio % PINS_PER_COLLECTION; 197 197 u8 drive; ··· 210 210 211 211 static int dc_gpio_get(struct gpio_chip *chip, unsigned gpio) 212 212 { 213 - struct dc_pinmap *pmap = container_of(chip, struct dc_pinmap, chip); 213 + struct dc_pinmap *pmap = gpiochip_get_data(chip); 214 214 int reg_off = GP_INPUT(gpio/PINS_PER_COLLECTION); 215 215 int bit_off = gpio % PINS_PER_COLLECTION; 216 216 u8 input; ··· 222 222 223 223 static void dc_gpio_set(struct gpio_chip *chip, unsigned gpio, int value) 224 224 { 225 - struct dc_pinmap *pmap = container_of(chip, struct dc_pinmap, chip); 225 + struct dc_pinmap *pmap = gpiochip_get_data(chip); 226 226 int reg_off = GP_OUTPUT0(gpio/PINS_PER_COLLECTION); 227 227 int bit_off = gpio % PINS_PER_COLLECTION; 228 228 u8 output; ··· 244 244 int ret; 245 245 246 246 chip->label = DRIVER_NAME; 247 - chip->dev = pmap->dev; 247 + chip->parent = pmap->dev; 248 248 chip->request = gpiochip_generic_request; 249 249 chip->free = gpiochip_generic_free; 250 250 chip->direction_input = dc_gpio_direction_input; ··· 258 258 259 259 spin_lock_init(&pmap->lock); 260 260 261 - ret = gpiochip_add(chip); 261 + ret = gpiochip_add_data(chip, pmap); 262 262 if (ret < 0) 263 263 return ret; 264 264
+10 -15
drivers/pinctrl/pinctrl-pistachio.c
··· 842 842 writel(val, pctl->base + reg); 843 843 } 844 844 845 - static inline struct pistachio_gpio_bank *gc_to_bank(struct gpio_chip *gc) 846 - { 847 - return container_of(gc, struct pistachio_gpio_bank, gpio_chip); 848 - } 849 - 850 845 static inline struct pistachio_gpio_bank *irqd_to_bank(struct irq_data *d) 851 846 { 852 - return gc_to_bank(irq_data_get_irq_chip_data(d)); 847 + return gpiochip_get_data(irq_data_get_irq_chip_data(d)); 853 848 } 854 849 855 850 static inline u32 gpio_readl(struct pistachio_gpio_bank *bank, u32 reg) ··· 987 992 988 993 range = pinctrl_find_gpio_range_from_pin(pctl->pctldev, pg->pin); 989 994 if (range) 990 - gpio_disable(gc_to_bank(range->gc), pg->pin - range->pin_base); 995 + gpio_disable(gpiochip_get_data(range->gc), pg->pin - range->pin_base); 991 996 992 997 return 0; 993 998 } ··· 1168 1173 1169 1174 static int pistachio_gpio_get_direction(struct gpio_chip *chip, unsigned offset) 1170 1175 { 1171 - struct pistachio_gpio_bank *bank = gc_to_bank(chip); 1176 + struct pistachio_gpio_bank *bank = gpiochip_get_data(chip); 1172 1177 1173 1178 return !(gpio_readl(bank, GPIO_OUTPUT_EN) & BIT(offset)); 1174 1179 } 1175 1180 1176 1181 static int pistachio_gpio_get(struct gpio_chip *chip, unsigned offset) 1177 1182 { 1178 - struct pistachio_gpio_bank *bank = gc_to_bank(chip); 1183 + struct pistachio_gpio_bank *bank = gpiochip_get_data(chip); 1179 1184 u32 reg; 1180 1185 1181 1186 if (gpio_readl(bank, GPIO_OUTPUT_EN) & BIT(offset)) ··· 1189 1194 static void pistachio_gpio_set(struct gpio_chip *chip, unsigned offset, 1190 1195 int value) 1191 1196 { 1192 - struct pistachio_gpio_bank *bank = gc_to_bank(chip); 1197 + struct pistachio_gpio_bank *bank = gpiochip_get_data(chip); 1193 1198 1194 1199 gpio_mask_writel(bank, GPIO_OUTPUT, offset, !!value); 1195 1200 } ··· 1197 1202 static int pistachio_gpio_direction_input(struct gpio_chip *chip, 1198 1203 unsigned offset) 1199 1204 { 1200 - struct pistachio_gpio_bank *bank = gc_to_bank(chip); 1205 + struct pistachio_gpio_bank *bank = gpiochip_get_data(chip); 1201 1206 1202 1207 gpio_mask_writel(bank, GPIO_OUTPUT_EN, offset, 0); 1203 1208 gpio_enable(bank, offset); ··· 1208 1213 static int pistachio_gpio_direction_output(struct gpio_chip *chip, 1209 1214 unsigned offset, int value) 1210 1215 { 1211 - struct pistachio_gpio_bank *bank = gc_to_bank(chip); 1216 + struct pistachio_gpio_bank *bank = gpiochip_get_data(chip); 1212 1217 1213 1218 pistachio_gpio_set(chip, offset, value); 1214 1219 gpio_mask_writel(bank, GPIO_OUTPUT_EN, offset, 1); ··· 1298 1303 static void pistachio_gpio_irq_handler(struct irq_desc *desc) 1299 1304 { 1300 1305 struct gpio_chip *gc = irq_desc_get_handler_data(desc); 1301 - struct pistachio_gpio_bank *bank = gc_to_bank(gc); 1306 + struct pistachio_gpio_bank *bank = gpiochip_get_data(gc); 1302 1307 struct irq_chip *chip = irq_desc_get_chip(desc); 1303 1308 unsigned long pending; 1304 1309 unsigned int pin; ··· 1383 1388 bank->pctl = pctl; 1384 1389 bank->base = pctl->base + GPIO_BANK_BASE(i); 1385 1390 1386 - bank->gpio_chip.dev = pctl->dev; 1391 + bank->gpio_chip.parent = pctl->dev; 1387 1392 bank->gpio_chip.of_node = child; 1388 - ret = gpiochip_add(&bank->gpio_chip); 1393 + ret = gpiochip_add_data(&bank->gpio_chip, bank); 1389 1394 if (ret < 0) { 1390 1395 dev_err(pctl->dev, "Failed to add GPIO chip %u: %d\n", 1391 1396 i, ret);
+6 -11
drivers/pinctrl/pinctrl-rockchip.c
··· 224 224 .reg_stride = 4, 225 225 }; 226 226 227 - static inline struct rockchip_pin_bank *gc_to_pin_bank(struct gpio_chip *gc) 228 - { 229 - return container_of(gc, struct rockchip_pin_bank, gpio_chip); 230 - } 231 - 232 227 static const inline struct rockchip_pin_group *pinctrl_name_to_group( 233 228 const struct rockchip_pinctrl *info, 234 229 const char *name) ··· 968 973 unsigned long flags; 969 974 u32 data; 970 975 971 - bank = gc_to_pin_bank(chip); 976 + bank = gpiochip_get_data(chip); 972 977 973 978 ret = rockchip_set_mux(bank, pin, RK_FUNC_GPIO); 974 979 if (ret < 0) ··· 1408 1413 1409 1414 static void rockchip_gpio_set(struct gpio_chip *gc, unsigned offset, int value) 1410 1415 { 1411 - struct rockchip_pin_bank *bank = gc_to_pin_bank(gc); 1416 + struct rockchip_pin_bank *bank = gpiochip_get_data(gc); 1412 1417 void __iomem *reg = bank->reg_base + GPIO_SWPORT_DR; 1413 1418 unsigned long flags; 1414 1419 u32 data; ··· 1432 1437 */ 1433 1438 static int rockchip_gpio_get(struct gpio_chip *gc, unsigned offset) 1434 1439 { 1435 - struct rockchip_pin_bank *bank = gc_to_pin_bank(gc); 1440 + struct rockchip_pin_bank *bank = gpiochip_get_data(gc); 1436 1441 u32 data; 1437 1442 1438 1443 clk_enable(bank->clk); ··· 1471 1476 */ 1472 1477 static int rockchip_gpio_to_irq(struct gpio_chip *gc, unsigned offset) 1473 1478 { 1474 - struct rockchip_pin_bank *bank = gc_to_pin_bank(gc); 1479 + struct rockchip_pin_bank *bank = gpiochip_get_data(gc); 1475 1480 unsigned int virq; 1476 1481 1477 1482 if (!bank->domain) ··· 1786 1791 gc = &bank->gpio_chip; 1787 1792 gc->base = bank->pin_base; 1788 1793 gc->ngpio = bank->nr_pins; 1789 - gc->dev = &pdev->dev; 1794 + gc->parent = &pdev->dev; 1790 1795 gc->of_node = bank->of_node; 1791 1796 gc->label = bank->name; 1792 1797 1793 - ret = gpiochip_add(gc); 1798 + ret = gpiochip_add_data(gc, bank); 1794 1799 if (ret) { 1795 1800 dev_err(&pdev->dev, "failed to register gpio_chip %s, error code: %d\n", 1796 1801 gc->label, ret);
+10 -13
drivers/pinctrl/pinctrl-st.c
··· 203 203 #define gpio_range_to_bank(chip) \ 204 204 container_of(chip, struct st_gpio_bank, range) 205 205 206 - #define gpio_chip_to_bank(chip) \ 207 - container_of(chip, struct st_gpio_bank, gpio_chip) 208 - 209 206 #define pc_to_bank(pc) \ 210 207 container_of(pc, struct st_gpio_bank, pc) 211 208 ··· 741 744 742 745 static int st_gpio_get(struct gpio_chip *chip, unsigned offset) 743 746 { 744 - struct st_gpio_bank *bank = gpio_chip_to_bank(chip); 747 + struct st_gpio_bank *bank = gpiochip_get_data(chip); 745 748 746 749 return !!(readl(bank->base + REG_PIO_PIN) & BIT(offset)); 747 750 } 748 751 749 752 static void st_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 750 753 { 751 - struct st_gpio_bank *bank = gpio_chip_to_bank(chip); 754 + struct st_gpio_bank *bank = gpiochip_get_data(chip); 752 755 __st_gpio_set(bank, offset, value); 753 756 } 754 757 ··· 762 765 static int st_gpio_direction_output(struct gpio_chip *chip, 763 766 unsigned offset, int value) 764 767 { 765 - struct st_gpio_bank *bank = gpio_chip_to_bank(chip); 768 + struct st_gpio_bank *bank = gpiochip_get_data(chip); 766 769 767 770 __st_gpio_set(bank, offset, value); 768 771 pinctrl_gpio_direction_output(chip->base + offset); ··· 772 775 773 776 static int st_gpio_get_direction(struct gpio_chip *chip, unsigned offset) 774 777 { 775 - struct st_gpio_bank *bank = gpio_chip_to_bank(chip); 778 + struct st_gpio_bank *bank = gpiochip_get_data(chip); 776 779 struct st_pio_control pc = bank->pc; 777 780 unsigned long config; 778 781 unsigned int direction = 0; ··· 1322 1325 static void st_gpio_irq_mask(struct irq_data *d) 1323 1326 { 1324 1327 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 1325 - struct st_gpio_bank *bank = gpio_chip_to_bank(gc); 1328 + struct st_gpio_bank *bank = gpiochip_get_data(gc); 1326 1329 1327 1330 writel(BIT(d->hwirq), bank->base + REG_PIO_CLR_PMASK); 1328 1331 } ··· 1330 1333 static void st_gpio_irq_unmask(struct irq_data *d) 1331 1334 { 1332 1335 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 1333 - struct st_gpio_bank *bank = gpio_chip_to_bank(gc); 1336 + struct st_gpio_bank *bank = gpiochip_get_data(gc); 1334 1337 1335 1338 writel(BIT(d->hwirq), bank->base + REG_PIO_SET_PMASK); 1336 1339 } ··· 1338 1341 static int st_gpio_irq_set_type(struct irq_data *d, unsigned type) 1339 1342 { 1340 1343 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 1341 - struct st_gpio_bank *bank = gpio_chip_to_bank(gc); 1344 + struct st_gpio_bank *bank = gpiochip_get_data(gc); 1342 1345 unsigned long flags; 1343 1346 int comp, pin = d->hwirq; 1344 1347 u32 val; ··· 1452 1455 /* interrupt dedicated per bank */ 1453 1456 struct irq_chip *chip = irq_desc_get_chip(desc); 1454 1457 struct gpio_chip *gc = irq_desc_get_handler_data(desc); 1455 - struct st_gpio_bank *bank = gpio_chip_to_bank(gc); 1458 + struct st_gpio_bank *bank = gpiochip_get_data(gc); 1456 1459 1457 1460 chained_irq_enter(chip, desc); 1458 1461 __gpio_irq_handler(bank); ··· 1519 1522 bank->gpio_chip.base = bank_num * ST_GPIO_PINS_PER_BANK; 1520 1523 bank->gpio_chip.ngpio = ST_GPIO_PINS_PER_BANK; 1521 1524 bank->gpio_chip.of_node = np; 1522 - bank->gpio_chip.dev = dev; 1525 + bank->gpio_chip.parent = dev; 1523 1526 spin_lock_init(&bank->lock); 1524 1527 1525 1528 of_property_read_string(np, "st,bank-name", &range->name); ··· 1529 1532 range->pin_base = range->base = range->id * ST_GPIO_PINS_PER_BANK; 1530 1533 range->npins = bank->gpio_chip.ngpio; 1531 1534 range->gc = &bank->gpio_chip; 1532 - err = gpiochip_add(&bank->gpio_chip); 1535 + err = gpiochip_add_data(&bank->gpio_chip, bank); 1533 1536 if (err) { 1534 1537 dev_err(dev, "Failed to add gpiochip(%d)!\n", bank_num); 1535 1538 return err;
+6 -6
drivers/pinctrl/pinctrl-xway.c
··· 1535 1535 /* --------- gpio_chip related code --------- */ 1536 1536 static void xway_gpio_set(struct gpio_chip *chip, unsigned int pin, int val) 1537 1537 { 1538 - struct ltq_pinmux_info *info = dev_get_drvdata(chip->dev); 1538 + struct ltq_pinmux_info *info = dev_get_drvdata(chip->parent); 1539 1539 1540 1540 if (val) 1541 1541 gpio_setbit(info->membase[0], GPIO_OUT(pin), PORT_PIN(pin)); ··· 1545 1545 1546 1546 static int xway_gpio_get(struct gpio_chip *chip, unsigned int pin) 1547 1547 { 1548 - struct ltq_pinmux_info *info = dev_get_drvdata(chip->dev); 1548 + struct ltq_pinmux_info *info = dev_get_drvdata(chip->parent); 1549 1549 1550 - return gpio_getbit(info->membase[0], GPIO_IN(pin), PORT_PIN(pin)); 1550 + return !!gpio_getbit(info->membase[0], GPIO_IN(pin), PORT_PIN(pin)); 1551 1551 } 1552 1552 1553 1553 static int xway_gpio_dir_in(struct gpio_chip *chip, unsigned int pin) 1554 1554 { 1555 - struct ltq_pinmux_info *info = dev_get_drvdata(chip->dev); 1555 + struct ltq_pinmux_info *info = dev_get_drvdata(chip->parent); 1556 1556 1557 1557 gpio_clearbit(info->membase[0], GPIO_DIR(pin), PORT_PIN(pin)); 1558 1558 ··· 1561 1561 1562 1562 static int xway_gpio_dir_out(struct gpio_chip *chip, unsigned int pin, int val) 1563 1563 { 1564 - struct ltq_pinmux_info *info = dev_get_drvdata(chip->dev); 1564 + struct ltq_pinmux_info *info = dev_get_drvdata(chip->parent); 1565 1565 1566 1566 if (PORT(pin) == PORT3) 1567 1567 gpio_setbit(info->membase[0], GPIO3_OD, PORT_PIN(pin)); ··· 1708 1708 xway_pctrl_desc.pins = xway_info.pads; 1709 1709 1710 1710 /* load the gpio chip */ 1711 - xway_chip.dev = &pdev->dev; 1711 + xway_chip.parent = &pdev->dev; 1712 1712 ret = gpiochip_add(&xway_chip); 1713 1713 if (ret) { 1714 1714 dev_err(&pdev->dev, "Failed to register gpio chip\n");
+13 -18
drivers/pinctrl/qcom/pinctrl-msm.c
··· 69 69 void __iomem *regs; 70 70 }; 71 71 72 - static inline struct msm_pinctrl *to_msm_pinctrl(struct gpio_chip *gc) 73 - { 74 - return container_of(gc, struct msm_pinctrl, chip); 75 - } 76 - 77 72 static int msm_get_groups_count(struct pinctrl_dev *pctldev) 78 73 { 79 74 struct msm_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); ··· 376 381 static int msm_gpio_direction_input(struct gpio_chip *chip, unsigned offset) 377 382 { 378 383 const struct msm_pingroup *g; 379 - struct msm_pinctrl *pctrl = container_of(chip, struct msm_pinctrl, chip); 384 + struct msm_pinctrl *pctrl = gpiochip_get_data(chip); 380 385 unsigned long flags; 381 386 u32 val; 382 387 ··· 396 401 static int msm_gpio_direction_output(struct gpio_chip *chip, unsigned offset, int value) 397 402 { 398 403 const struct msm_pingroup *g; 399 - struct msm_pinctrl *pctrl = container_of(chip, struct msm_pinctrl, chip); 404 + struct msm_pinctrl *pctrl = gpiochip_get_data(chip); 400 405 unsigned long flags; 401 406 u32 val; 402 407 ··· 423 428 static int msm_gpio_get(struct gpio_chip *chip, unsigned offset) 424 429 { 425 430 const struct msm_pingroup *g; 426 - struct msm_pinctrl *pctrl = container_of(chip, struct msm_pinctrl, chip); 431 + struct msm_pinctrl *pctrl = gpiochip_get_data(chip); 427 432 u32 val; 428 433 429 434 g = &pctrl->soc->groups[offset]; ··· 435 440 static void msm_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 436 441 { 437 442 const struct msm_pingroup *g; 438 - struct msm_pinctrl *pctrl = container_of(chip, struct msm_pinctrl, chip); 443 + struct msm_pinctrl *pctrl = gpiochip_get_data(chip); 439 444 unsigned long flags; 440 445 u32 val; 441 446 ··· 463 468 unsigned gpio) 464 469 { 465 470 const struct msm_pingroup *g; 466 - struct msm_pinctrl *pctrl = container_of(chip, struct msm_pinctrl, chip); 471 + struct msm_pinctrl *pctrl = gpiochip_get_data(chip); 467 472 unsigned func; 468 473 int is_out; 469 474 int drive; ··· 562 567 static void msm_gpio_irq_mask(struct irq_data *d) 563 568 { 564 569 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 565 - struct msm_pinctrl *pctrl = to_msm_pinctrl(gc); 570 + struct msm_pinctrl *pctrl = gpiochip_get_data(gc); 566 571 const struct msm_pingroup *g; 567 572 unsigned long flags; 568 573 u32 val; ··· 583 588 static void msm_gpio_irq_unmask(struct irq_data *d) 584 589 { 585 590 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 586 - struct msm_pinctrl *pctrl = to_msm_pinctrl(gc); 591 + struct msm_pinctrl *pctrl = gpiochip_get_data(gc); 587 592 const struct msm_pingroup *g; 588 593 unsigned long flags; 589 594 u32 val; ··· 608 613 static void msm_gpio_irq_ack(struct irq_data *d) 609 614 { 610 615 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 611 - struct msm_pinctrl *pctrl = to_msm_pinctrl(gc); 616 + struct msm_pinctrl *pctrl = gpiochip_get_data(gc); 612 617 const struct msm_pingroup *g; 613 618 unsigned long flags; 614 619 u32 val; ··· 633 638 static int msm_gpio_irq_set_type(struct irq_data *d, unsigned int type) 634 639 { 635 640 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 636 - struct msm_pinctrl *pctrl = to_msm_pinctrl(gc); 641 + struct msm_pinctrl *pctrl = gpiochip_get_data(gc); 637 642 const struct msm_pingroup *g; 638 643 unsigned long flags; 639 644 u32 val; ··· 727 732 static int msm_gpio_irq_set_wake(struct irq_data *d, unsigned int on) 728 733 { 729 734 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 730 - struct msm_pinctrl *pctrl = to_msm_pinctrl(gc); 735 + struct msm_pinctrl *pctrl = gpiochip_get_data(gc); 731 736 unsigned long flags; 732 737 733 738 spin_lock_irqsave(&pctrl->lock, flags); ··· 752 757 { 753 758 struct gpio_chip *gc = irq_desc_get_handler_data(desc); 754 759 const struct msm_pingroup *g; 755 - struct msm_pinctrl *pctrl = to_msm_pinctrl(gc); 760 + struct msm_pinctrl *pctrl = gpiochip_get_data(gc); 756 761 struct irq_chip *chip = irq_desc_get_chip(desc); 757 762 int irq_pin; 758 763 int handled = 0; ··· 795 800 chip->base = 0; 796 801 chip->ngpio = ngpio; 797 802 chip->label = dev_name(pctrl->dev); 798 - chip->dev = pctrl->dev; 803 + chip->parent = pctrl->dev; 799 804 chip->owner = THIS_MODULE; 800 805 chip->of_node = pctrl->dev->of_node; 801 806 802 - ret = gpiochip_add(&pctrl->chip); 807 + ret = gpiochip_add_data(&pctrl->chip, pctrl); 803 808 if (ret) { 804 809 dev_err(pctrl->dev, "Failed register gpiochip\n"); 805 810 return ret;
+9 -14
drivers/pinctrl/qcom/pinctrl-spmi-gpio.c
··· 159 159 PMIC_GPIO_FUNC_DTEST3, PMIC_GPIO_FUNC_DTEST4, 160 160 }; 161 161 162 - static inline struct pmic_gpio_state *to_gpio_state(struct gpio_chip *chip) 163 - { 164 - return container_of(chip, struct pmic_gpio_state, chip); 165 - }; 166 - 167 162 static int pmic_gpio_read(struct pmic_gpio_state *state, 168 163 struct pmic_gpio_pad *pad, unsigned int addr) 169 164 { ··· 491 496 492 497 static int pmic_gpio_direction_input(struct gpio_chip *chip, unsigned pin) 493 498 { 494 - struct pmic_gpio_state *state = to_gpio_state(chip); 499 + struct pmic_gpio_state *state = gpiochip_get_data(chip); 495 500 unsigned long config; 496 501 497 502 config = pinconf_to_config_packed(PIN_CONFIG_INPUT_ENABLE, 1); ··· 502 507 static int pmic_gpio_direction_output(struct gpio_chip *chip, 503 508 unsigned pin, int val) 504 509 { 505 - struct pmic_gpio_state *state = to_gpio_state(chip); 510 + struct pmic_gpio_state *state = gpiochip_get_data(chip); 506 511 unsigned long config; 507 512 508 513 config = pinconf_to_config_packed(PIN_CONFIG_OUTPUT, val); ··· 512 517 513 518 static int pmic_gpio_get(struct gpio_chip *chip, unsigned pin) 514 519 { 515 - struct pmic_gpio_state *state = to_gpio_state(chip); 520 + struct pmic_gpio_state *state = gpiochip_get_data(chip); 516 521 struct pmic_gpio_pad *pad; 517 522 int ret; 518 523 ··· 529 534 pad->out_value = ret & PMIC_MPP_REG_RT_STS_VAL_MASK; 530 535 } 531 536 532 - return pad->out_value; 537 + return !!pad->out_value; 533 538 } 534 539 535 540 static void pmic_gpio_set(struct gpio_chip *chip, unsigned pin, int value) 536 541 { 537 - struct pmic_gpio_state *state = to_gpio_state(chip); 542 + struct pmic_gpio_state *state = gpiochip_get_data(chip); 538 543 unsigned long config; 539 544 540 545 config = pinconf_to_config_packed(PIN_CONFIG_OUTPUT, value); ··· 557 562 558 563 static int pmic_gpio_to_irq(struct gpio_chip *chip, unsigned pin) 559 564 { 560 - struct pmic_gpio_state *state = to_gpio_state(chip); 565 + struct pmic_gpio_state *state = gpiochip_get_data(chip); 561 566 struct pmic_gpio_pad *pad; 562 567 563 568 pad = state->ctrl->desc->pins[pin].drv_data; ··· 567 572 568 573 static void pmic_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip) 569 574 { 570 - struct pmic_gpio_state *state = to_gpio_state(chip); 575 + struct pmic_gpio_state *state = gpiochip_get_data(chip); 571 576 unsigned i; 572 577 573 578 for (i = 0; i < chip->ngpio; i++) { ··· 757 762 } 758 763 759 764 state->chip = pmic_gpio_gpio_template; 760 - state->chip.dev = dev; 765 + state->chip.parent = dev; 761 766 state->chip.base = -1; 762 767 state->chip.ngpio = npins; 763 768 state->chip.label = dev_name(dev); ··· 768 773 if (IS_ERR(state->ctrl)) 769 774 return PTR_ERR(state->ctrl); 770 775 771 - ret = gpiochip_add(&state->chip); 776 + ret = gpiochip_add_data(&state->chip, state); 772 777 if (ret) { 773 778 dev_err(state->dev, "can't add gpio chip\n"); 774 779 goto err_chip;
+9 -14
drivers/pinctrl/qcom/pinctrl-spmi-mpp.c
··· 179 179 "digital", "analog", "sink" 180 180 }; 181 181 182 - static inline struct pmic_mpp_state *to_mpp_state(struct gpio_chip *chip) 183 - { 184 - return container_of(chip, struct pmic_mpp_state, chip); 185 - }; 186 - 187 182 static int pmic_mpp_read(struct pmic_mpp_state *state, 188 183 struct pmic_mpp_pad *pad, unsigned int addr) 189 184 { ··· 552 557 553 558 static int pmic_mpp_direction_input(struct gpio_chip *chip, unsigned pin) 554 559 { 555 - struct pmic_mpp_state *state = to_mpp_state(chip); 560 + struct pmic_mpp_state *state = gpiochip_get_data(chip); 556 561 unsigned long config; 557 562 558 563 config = pinconf_to_config_packed(PIN_CONFIG_INPUT_ENABLE, 1); ··· 563 568 static int pmic_mpp_direction_output(struct gpio_chip *chip, 564 569 unsigned pin, int val) 565 570 { 566 - struct pmic_mpp_state *state = to_mpp_state(chip); 571 + struct pmic_mpp_state *state = gpiochip_get_data(chip); 567 572 unsigned long config; 568 573 569 574 config = pinconf_to_config_packed(PIN_CONFIG_OUTPUT, val); ··· 573 578 574 579 static int pmic_mpp_get(struct gpio_chip *chip, unsigned pin) 575 580 { 576 - struct pmic_mpp_state *state = to_mpp_state(chip); 581 + struct pmic_mpp_state *state = gpiochip_get_data(chip); 577 582 struct pmic_mpp_pad *pad; 578 583 int ret; 579 584 ··· 587 592 pad->out_value = ret & PMIC_MPP_REG_RT_STS_VAL_MASK; 588 593 } 589 594 590 - return pad->out_value; 595 + return !!pad->out_value; 591 596 } 592 597 593 598 static void pmic_mpp_set(struct gpio_chip *chip, unsigned pin, int value) 594 599 { 595 - struct pmic_mpp_state *state = to_mpp_state(chip); 600 + struct pmic_mpp_state *state = gpiochip_get_data(chip); 596 601 unsigned long config; 597 602 598 603 config = pinconf_to_config_packed(PIN_CONFIG_OUTPUT, value); ··· 615 620 616 621 static int pmic_mpp_to_irq(struct gpio_chip *chip, unsigned pin) 617 622 { 618 - struct pmic_mpp_state *state = to_mpp_state(chip); 623 + struct pmic_mpp_state *state = gpiochip_get_data(chip); 619 624 struct pmic_mpp_pad *pad; 620 625 621 626 pad = state->ctrl->desc->pins[pin].drv_data; ··· 625 630 626 631 static void pmic_mpp_dbg_show(struct seq_file *s, struct gpio_chip *chip) 627 632 { 628 - struct pmic_mpp_state *state = to_mpp_state(chip); 633 + struct pmic_mpp_state *state = gpiochip_get_data(chip); 629 634 unsigned i; 630 635 631 636 for (i = 0; i < chip->ngpio; i++) { ··· 860 865 } 861 866 862 867 state->chip = pmic_mpp_gpio_template; 863 - state->chip.dev = dev; 868 + state->chip.parent = dev; 864 869 state->chip.base = -1; 865 870 state->chip.ngpio = npins; 866 871 state->chip.label = dev_name(dev); ··· 871 876 if (IS_ERR(state->ctrl)) 872 877 return PTR_ERR(state->ctrl); 873 878 874 - ret = gpiochip_add(&state->chip); 879 + ret = gpiochip_add_data(&state->chip, state); 875 880 if (ret) { 876 881 dev_err(state->dev, "can't add gpio chip\n"); 877 882 goto err_chip;
+8 -8
drivers/pinctrl/qcom/pinctrl-ssbi-gpio.c
··· 444 444 static int pm8xxx_gpio_direction_input(struct gpio_chip *chip, 445 445 unsigned offset) 446 446 { 447 - struct pm8xxx_gpio *pctrl = container_of(chip, struct pm8xxx_gpio, chip); 447 + struct pm8xxx_gpio *pctrl = gpiochip_get_data(chip); 448 448 struct pm8xxx_pin_data *pin = pctrl->desc.pins[offset].drv_data; 449 449 u8 val; 450 450 ··· 460 460 unsigned offset, 461 461 int value) 462 462 { 463 - struct pm8xxx_gpio *pctrl = container_of(chip, struct pm8xxx_gpio, chip); 463 + struct pm8xxx_gpio *pctrl = gpiochip_get_data(chip); 464 464 struct pm8xxx_pin_data *pin = pctrl->desc.pins[offset].drv_data; 465 465 u8 val; 466 466 ··· 478 478 479 479 static int pm8xxx_gpio_get(struct gpio_chip *chip, unsigned offset) 480 480 { 481 - struct pm8xxx_gpio *pctrl = container_of(chip, struct pm8xxx_gpio, chip); 481 + struct pm8xxx_gpio *pctrl = gpiochip_get_data(chip); 482 482 struct pm8xxx_pin_data *pin = pctrl->desc.pins[offset].drv_data; 483 483 bool state; 484 484 int ret; ··· 496 496 497 497 static void pm8xxx_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 498 498 { 499 - struct pm8xxx_gpio *pctrl = container_of(chip, struct pm8xxx_gpio, chip); 499 + struct pm8xxx_gpio *pctrl = gpiochip_get_data(chip); 500 500 struct pm8xxx_pin_data *pin = pctrl->desc.pins[offset].drv_data; 501 501 u8 val; 502 502 ··· 525 525 526 526 static int pm8xxx_gpio_to_irq(struct gpio_chip *chip, unsigned offset) 527 527 { 528 - struct pm8xxx_gpio *pctrl = container_of(chip, struct pm8xxx_gpio, chip); 528 + struct pm8xxx_gpio *pctrl = gpiochip_get_data(chip); 529 529 struct pm8xxx_pin_data *pin = pctrl->desc.pins[offset].drv_data; 530 530 531 531 return pin->irq; ··· 540 540 unsigned offset, 541 541 unsigned gpio) 542 542 { 543 - struct pm8xxx_gpio *pctrl = container_of(chip, struct pm8xxx_gpio, chip); 543 + struct pm8xxx_gpio *pctrl = gpiochip_get_data(chip); 544 544 struct pm8xxx_pin_data *pin = pctrl->desc.pins[offset].drv_data; 545 545 546 546 static const char * const modes[] = { ··· 737 737 738 738 pctrl->chip = pm8xxx_gpio_template; 739 739 pctrl->chip.base = -1; 740 - pctrl->chip.dev = &pdev->dev; 740 + pctrl->chip.parent = &pdev->dev; 741 741 pctrl->chip.of_node = pdev->dev.of_node; 742 742 pctrl->chip.of_gpio_n_cells = 2; 743 743 pctrl->chip.label = dev_name(pctrl->dev); 744 744 pctrl->chip.ngpio = pctrl->npins; 745 - ret = gpiochip_add(&pctrl->chip); 745 + ret = gpiochip_add_data(&pctrl->chip, pctrl); 746 746 if (ret) { 747 747 dev_err(&pdev->dev, "failed register gpiochip\n"); 748 748 goto unregister_pinctrl;
+9 -9
drivers/pinctrl/qcom/pinctrl-ssbi-mpp.c
··· 449 449 static int pm8xxx_mpp_direction_input(struct gpio_chip *chip, 450 450 unsigned offset) 451 451 { 452 - struct pm8xxx_mpp *pctrl = container_of(chip, struct pm8xxx_mpp, chip); 452 + struct pm8xxx_mpp *pctrl = gpiochip_get_data(chip); 453 453 struct pm8xxx_pin_data *pin = pctrl->desc.pins[offset].drv_data; 454 454 455 455 switch (pin->mode) { ··· 473 473 unsigned offset, 474 474 int value) 475 475 { 476 - struct pm8xxx_mpp *pctrl = container_of(chip, struct pm8xxx_mpp, chip); 476 + struct pm8xxx_mpp *pctrl = gpiochip_get_data(chip); 477 477 struct pm8xxx_pin_data *pin = pctrl->desc.pins[offset].drv_data; 478 478 479 479 switch (pin->mode) { ··· 497 497 498 498 static int pm8xxx_mpp_get(struct gpio_chip *chip, unsigned offset) 499 499 { 500 - struct pm8xxx_mpp *pctrl = container_of(chip, struct pm8xxx_mpp, chip); 500 + struct pm8xxx_mpp *pctrl = gpiochip_get_data(chip); 501 501 struct pm8xxx_pin_data *pin = pctrl->desc.pins[offset].drv_data; 502 502 bool state; 503 503 int ret; 504 504 505 505 if (!pin->input) 506 - return pin->output_value; 506 + return !!pin->output_value; 507 507 508 508 ret = irq_get_irqchip_state(pin->irq, IRQCHIP_STATE_LINE_LEVEL, &state); 509 509 if (!ret) ··· 514 514 515 515 static void pm8xxx_mpp_set(struct gpio_chip *chip, unsigned offset, int value) 516 516 { 517 - struct pm8xxx_mpp *pctrl = container_of(chip, struct pm8xxx_mpp, chip); 517 + struct pm8xxx_mpp *pctrl = gpiochip_get_data(chip); 518 518 struct pm8xxx_pin_data *pin = pctrl->desc.pins[offset].drv_data; 519 519 520 520 pin->output_value = !!value; ··· 538 538 539 539 static int pm8xxx_mpp_to_irq(struct gpio_chip *chip, unsigned offset) 540 540 { 541 - struct pm8xxx_mpp *pctrl = container_of(chip, struct pm8xxx_mpp, chip); 541 + struct pm8xxx_mpp *pctrl = gpiochip_get_data(chip); 542 542 struct pm8xxx_pin_data *pin = pctrl->desc.pins[offset].drv_data; 543 543 544 544 return pin->irq; ··· 553 553 unsigned offset, 554 554 unsigned gpio) 555 555 { 556 - struct pm8xxx_mpp *pctrl = container_of(chip, struct pm8xxx_mpp, chip); 556 + struct pm8xxx_mpp *pctrl = gpiochip_get_data(chip); 557 557 struct pm8xxx_pin_data *pin = pctrl->desc.pins[offset].drv_data; 558 558 559 559 static const char * const aout_lvls[] = { ··· 828 828 829 829 pctrl->chip = pm8xxx_mpp_template; 830 830 pctrl->chip.base = -1; 831 - pctrl->chip.dev = &pdev->dev; 831 + pctrl->chip.parent = &pdev->dev; 832 832 pctrl->chip.of_node = pdev->dev.of_node; 833 833 pctrl->chip.of_gpio_n_cells = 2; 834 834 pctrl->chip.label = dev_name(pctrl->dev); 835 835 pctrl->chip.ngpio = pctrl->npins; 836 - ret = gpiochip_add(&pctrl->chip); 836 + ret = gpiochip_add_data(&pctrl->chip, pctrl); 837 837 if (ret) { 838 838 dev_err(&pdev->dev, "failed register gpiochip\n"); 839 839 goto unregister_pinctrl;
+2 -1
drivers/pinctrl/samsung/pinctrl-exynos.c
··· 176 176 177 177 ret = gpiochip_lock_as_irq(&bank->gpio_chip, irqd->hwirq); 178 178 if (ret) { 179 - dev_err(bank->gpio_chip.dev, "unable to lock pin %s-%lu IRQ\n", 179 + dev_err(bank->gpio_chip.parent, 180 + "unable to lock pin %s-%lu IRQ\n", 180 181 bank->name, irqd->hwirq); 181 182 return ret; 182 183 }
+8 -8
drivers/pinctrl/samsung/pinctrl-exynos5440.c
··· 15 15 #include <linux/io.h> 16 16 #include <linux/slab.h> 17 17 #include <linux/err.h> 18 - #include <linux/gpio.h> 18 + #include <linux/gpio/driver.h> 19 19 #include <linux/device.h> 20 20 #include <linux/pinctrl/pinctrl.h> 21 21 #include <linux/pinctrl/pinmux.h> ··· 539 539 /* gpiolib gpio_set callback function */ 540 540 static void exynos5440_gpio_set(struct gpio_chip *gc, unsigned offset, int value) 541 541 { 542 - struct exynos5440_pinctrl_priv_data *priv = dev_get_drvdata(gc->dev); 542 + struct exynos5440_pinctrl_priv_data *priv = gpiochip_get_data(gc); 543 543 void __iomem *base = priv->reg_base; 544 544 u32 data; 545 545 ··· 553 553 /* gpiolib gpio_get callback function */ 554 554 static int exynos5440_gpio_get(struct gpio_chip *gc, unsigned offset) 555 555 { 556 - struct exynos5440_pinctrl_priv_data *priv = dev_get_drvdata(gc->dev); 556 + struct exynos5440_pinctrl_priv_data *priv = gpiochip_get_data(gc); 557 557 void __iomem *base = priv->reg_base; 558 558 u32 data; 559 559 ··· 566 566 /* gpiolib gpio_direction_input callback function */ 567 567 static int exynos5440_gpio_direction_input(struct gpio_chip *gc, unsigned offset) 568 568 { 569 - struct exynos5440_pinctrl_priv_data *priv = dev_get_drvdata(gc->dev); 569 + struct exynos5440_pinctrl_priv_data *priv = gpiochip_get_data(gc); 570 570 void __iomem *base = priv->reg_base; 571 571 u32 data; 572 572 ··· 586 586 static int exynos5440_gpio_direction_output(struct gpio_chip *gc, unsigned offset, 587 587 int value) 588 588 { 589 - struct exynos5440_pinctrl_priv_data *priv = dev_get_drvdata(gc->dev); 589 + struct exynos5440_pinctrl_priv_data *priv = gpiochip_get_data(gc); 590 590 void __iomem *base = priv->reg_base; 591 591 u32 data; 592 592 ··· 607 607 /* gpiolib gpio_to_irq callback function */ 608 608 static int exynos5440_gpio_to_irq(struct gpio_chip *gc, unsigned offset) 609 609 { 610 - struct exynos5440_pinctrl_priv_data *priv = dev_get_drvdata(gc->dev); 610 + struct exynos5440_pinctrl_priv_data *priv = gpiochip_get_data(gc); 611 611 unsigned int virq; 612 612 613 613 if (offset < 16 || offset > 23) ··· 817 817 priv->gc = gc; 818 818 gc->base = 0; 819 819 gc->ngpio = EXYNOS5440_MAX_PINS; 820 - gc->dev = &pdev->dev; 820 + gc->parent = &pdev->dev; 821 821 gc->set = exynos5440_gpio_set; 822 822 gc->get = exynos5440_gpio_get; 823 823 gc->direction_input = exynos5440_gpio_direction_input; ··· 825 825 gc->to_irq = exynos5440_gpio_to_irq; 826 826 gc->label = "gpiolib-exynos5440"; 827 827 gc->owner = THIS_MODULE; 828 - ret = gpiochip_add(gc); 828 + ret = gpiochip_add_data(gc, priv); 829 829 if (ret) { 830 830 dev_err(&pdev->dev, "failed to register gpio_chip %s, error " 831 831 "code: %d\n", gc->label, ret);
+6 -11
drivers/pinctrl/samsung/pinctrl-samsung.c
··· 50 50 51 51 static unsigned int pin_base; 52 52 53 - static inline struct samsung_pin_bank *gc_to_pin_bank(struct gpio_chip *gc) 54 - { 55 - return container_of(gc, struct samsung_pin_bank, gpio_chip); 56 - } 57 - 58 53 static int samsung_get_group_count(struct pinctrl_dev *pctldev) 59 54 { 60 55 struct samsung_pinctrl_drv_data *pmx = pinctrl_dev_get_drvdata(pctldev); ··· 517 522 /* gpiolib gpio_set callback function */ 518 523 static void samsung_gpio_set(struct gpio_chip *gc, unsigned offset, int value) 519 524 { 520 - struct samsung_pin_bank *bank = gc_to_pin_bank(gc); 525 + struct samsung_pin_bank *bank = gpiochip_get_data(gc); 521 526 const struct samsung_pin_bank_type *type = bank->type; 522 527 unsigned long flags; 523 528 void __iomem *reg; ··· 541 546 { 542 547 void __iomem *reg; 543 548 u32 data; 544 - struct samsung_pin_bank *bank = gc_to_pin_bank(gc); 549 + struct samsung_pin_bank *bank = gpiochip_get_data(gc); 545 550 const struct samsung_pin_bank_type *type = bank->type; 546 551 547 552 reg = bank->drvdata->virt_base + bank->pctl_offset; ··· 566 571 u32 data, mask, shift; 567 572 unsigned long flags; 568 573 569 - bank = gc_to_pin_bank(gc); 574 + bank = gpiochip_get_data(gc); 570 575 type = bank->type; 571 576 drvdata = bank->drvdata; 572 577 ··· 614 619 */ 615 620 static int samsung_gpio_to_irq(struct gpio_chip *gc, unsigned offset) 616 621 { 617 - struct samsung_pin_bank *bank = gc_to_pin_bank(gc); 622 + struct samsung_pin_bank *bank = gpiochip_get_data(gc); 618 623 unsigned int virq; 619 624 620 625 if (!bank->irq_domain) ··· 909 914 gc = &bank->gpio_chip; 910 915 gc->base = drvdata->pin_base + bank->pin_base; 911 916 gc->ngpio = bank->nr_pins; 912 - gc->dev = &pdev->dev; 917 + gc->parent = &pdev->dev; 913 918 gc->of_node = bank->of_node; 914 919 gc->label = bank->name; 915 920 916 - ret = gpiochip_add(gc); 921 + ret = gpiochip_add_data(gc, bank); 917 922 if (ret) { 918 923 dev_err(&pdev->dev, "failed to register gpio_chip %s, error code: %d\n", 919 924 gc->label, ret);
+7 -11
drivers/pinctrl/sh-pfc/gpio.c
··· 38 38 struct sh_pfc_gpio_pin *pins; 39 39 }; 40 40 41 - static struct sh_pfc_chip *gpio_to_pfc_chip(struct gpio_chip *gc) 42 - { 43 - return container_of(gc, struct sh_pfc_chip, gpio_chip); 44 - } 45 - 46 41 static struct sh_pfc *gpio_to_pfc(struct gpio_chip *gc) 47 42 { 48 - return gpio_to_pfc_chip(gc)->pfc; 43 + struct sh_pfc_chip *chip = gpiochip_get_data(gc); 44 + return chip->pfc; 49 45 } 50 46 51 47 static void gpio_get_data_reg(struct sh_pfc_chip *chip, unsigned int offset, ··· 174 178 static int gpio_pin_direction_output(struct gpio_chip *gc, unsigned offset, 175 179 int value) 176 180 { 177 - gpio_pin_set_value(gpio_to_pfc_chip(gc), offset, value); 181 + gpio_pin_set_value(gpiochip_get_data(gc), offset, value); 178 182 179 183 return pinctrl_gpio_direction_output(offset); 180 184 } 181 185 182 186 static int gpio_pin_get(struct gpio_chip *gc, unsigned offset) 183 187 { 184 - struct sh_pfc_chip *chip = gpio_to_pfc_chip(gc); 188 + struct sh_pfc_chip *chip = gpiochip_get_data(gc); 185 189 struct sh_pfc_gpio_data_reg *reg; 186 190 unsigned int bit; 187 191 unsigned int pos; ··· 195 199 196 200 static void gpio_pin_set(struct gpio_chip *gc, unsigned offset, int value) 197 201 { 198 - gpio_pin_set_value(gpio_to_pfc_chip(gc), offset, value); 202 + gpio_pin_set_value(gpiochip_get_data(gc), offset, value); 199 203 } 200 204 201 205 static int gpio_pin_to_irq(struct gpio_chip *gc, unsigned offset) ··· 242 246 gc->to_irq = gpio_pin_to_irq; 243 247 244 248 gc->label = pfc->info->name; 245 - gc->dev = pfc->dev; 249 + gc->parent = pfc->dev; 246 250 gc->owner = THIS_MODULE; 247 251 gc->base = 0; 248 252 gc->ngpio = pfc->nr_gpio_pins; ··· 318 322 if (ret < 0) 319 323 return ERR_PTR(ret); 320 324 321 - ret = gpiochip_add(&chip->gpio_chip); 325 + ret = gpiochip_add_data(&chip->gpio_chip, chip); 322 326 if (unlikely(ret < 0)) 323 327 return ERR_PTR(ret); 324 328
+13 -18
drivers/pinctrl/sirf/pinctrl-atlas7.c
··· 358 358 struct atlas7_gpio_bank banks[0]; 359 359 }; 360 360 361 - static inline struct atlas7_gpio_chip *to_atlas7_gpio(struct gpio_chip *gc) 362 - { 363 - return container_of(gc, struct atlas7_gpio_chip, chip); 364 - } 365 - 366 361 /** 367 362 * @dev: a pointer back to containing device 368 363 * @virtbase: the offset to the controller in virtual memory ··· 5637 5642 static void atlas7_gpio_irq_ack(struct irq_data *d) 5638 5643 { 5639 5644 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 5640 - struct atlas7_gpio_chip *a7gc = to_atlas7_gpio(gc); 5645 + struct atlas7_gpio_chip *a7gc = gpiochip_get_data(gc); 5641 5646 struct atlas7_gpio_bank *bank; 5642 5647 void __iomem *ctrl_reg; 5643 5648 u32 val, pin_in_bank; ··· 5675 5680 static void atlas7_gpio_irq_mask(struct irq_data *d) 5676 5681 { 5677 5682 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 5678 - struct atlas7_gpio_chip *a7gc = to_atlas7_gpio(gc); 5683 + struct atlas7_gpio_chip *a7gc = gpiochip_get_data(gc); 5679 5684 unsigned long flags; 5680 5685 5681 5686 spin_lock_irqsave(&a7gc->lock, flags); ··· 5688 5693 static void atlas7_gpio_irq_unmask(struct irq_data *d) 5689 5694 { 5690 5695 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 5691 - struct atlas7_gpio_chip *a7gc = to_atlas7_gpio(gc); 5696 + struct atlas7_gpio_chip *a7gc = gpiochip_get_data(gc); 5692 5697 struct atlas7_gpio_bank *bank; 5693 5698 void __iomem *ctrl_reg; 5694 5699 u32 val, pin_in_bank; ··· 5712 5717 unsigned int type) 5713 5718 { 5714 5719 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 5715 - struct atlas7_gpio_chip *a7gc = to_atlas7_gpio(gc); 5720 + struct atlas7_gpio_chip *a7gc = gpiochip_get_data(gc); 5716 5721 struct atlas7_gpio_bank *bank; 5717 5722 void __iomem *ctrl_reg; 5718 5723 u32 val, pin_in_bank; ··· 5781 5786 static void atlas7_gpio_handle_irq(struct irq_desc *desc) 5782 5787 { 5783 5788 struct gpio_chip *gc = irq_desc_get_handler_data(desc); 5784 - struct atlas7_gpio_chip *a7gc = to_atlas7_gpio(gc); 5789 + struct atlas7_gpio_chip *a7gc = gpiochip_get_data(gc); 5785 5790 struct atlas7_gpio_bank *bank = NULL; 5786 5791 u32 status, ctrl; 5787 5792 int pin_in_bank = 0, idx; ··· 5849 5854 static int atlas7_gpio_request(struct gpio_chip *chip, 5850 5855 unsigned int gpio) 5851 5856 { 5852 - struct atlas7_gpio_chip *a7gc = to_atlas7_gpio(chip); 5857 + struct atlas7_gpio_chip *a7gc = gpiochip_get_data(chip); 5853 5858 int ret; 5854 5859 unsigned long flags; 5855 5860 ··· 5877 5882 static void atlas7_gpio_free(struct gpio_chip *chip, 5878 5883 unsigned int gpio) 5879 5884 { 5880 - struct atlas7_gpio_chip *a7gc = to_atlas7_gpio(chip); 5885 + struct atlas7_gpio_chip *a7gc = gpiochip_get_data(chip); 5881 5886 unsigned long flags; 5882 5887 5883 5888 spin_lock_irqsave(&a7gc->lock, flags); ··· 5893 5898 static int atlas7_gpio_direction_input(struct gpio_chip *chip, 5894 5899 unsigned int gpio) 5895 5900 { 5896 - struct atlas7_gpio_chip *a7gc = to_atlas7_gpio(chip); 5901 + struct atlas7_gpio_chip *a7gc = gpiochip_get_data(chip); 5897 5902 unsigned long flags; 5898 5903 5899 5904 spin_lock_irqsave(&a7gc->lock, flags); ··· 5930 5935 static int atlas7_gpio_direction_output(struct gpio_chip *chip, 5931 5936 unsigned int gpio, int value) 5932 5937 { 5933 - struct atlas7_gpio_chip *a7gc = to_atlas7_gpio(chip); 5938 + struct atlas7_gpio_chip *a7gc = gpiochip_get_data(chip); 5934 5939 unsigned long flags; 5935 5940 5936 5941 spin_lock_irqsave(&a7gc->lock, flags); ··· 5945 5950 static int atlas7_gpio_get_value(struct gpio_chip *chip, 5946 5951 unsigned int gpio) 5947 5952 { 5948 - struct atlas7_gpio_chip *a7gc = to_atlas7_gpio(chip); 5953 + struct atlas7_gpio_chip *a7gc = gpiochip_get_data(chip); 5949 5954 struct atlas7_gpio_bank *bank; 5950 5955 u32 val, pin_in_bank; 5951 5956 unsigned long flags; ··· 5965 5970 static void atlas7_gpio_set_value(struct gpio_chip *chip, 5966 5971 unsigned int gpio, int value) 5967 5972 { 5968 - struct atlas7_gpio_chip *a7gc = to_atlas7_gpio(chip); 5973 + struct atlas7_gpio_chip *a7gc = gpiochip_get_data(chip); 5969 5974 struct atlas7_gpio_bank *bank; 5970 5975 void __iomem *ctrl_reg; 5971 5976 u32 ctrl, pin_in_bank; ··· 6049 6054 chip->label = kstrdup(np->name, GFP_KERNEL); 6050 6055 chip->of_node = np; 6051 6056 chip->of_gpio_n_cells = 2; 6052 - chip->dev = &pdev->dev; 6057 + chip->parent = &pdev->dev; 6053 6058 6054 6059 /* Add gpio chip to system */ 6055 - ret = gpiochip_add(chip); 6060 + ret = gpiochip_add_data(chip, a7gc); 6056 6061 if (ret) { 6057 6062 dev_err(&pdev->dev, 6058 6063 "%s: error in probe function with status %d\n",
+13 -18
drivers/pinctrl/sirf/pinctrl-sirf.c
··· 403 403 } 404 404 arch_initcall(sirfsoc_pinmux_init); 405 405 406 - static inline struct sirfsoc_gpio_chip *to_sirfsoc_gpio(struct gpio_chip *gc) 407 - { 408 - return container_of(gc, struct sirfsoc_gpio_chip, chip.gc); 409 - } 410 - 411 406 static inline struct sirfsoc_gpio_bank * 412 407 sirfsoc_gpio_to_bank(struct sirfsoc_gpio_chip *sgpio, unsigned int offset) 413 408 { ··· 417 422 static void sirfsoc_gpio_irq_ack(struct irq_data *d) 418 423 { 419 424 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 420 - struct sirfsoc_gpio_chip *sgpio = to_sirfsoc_gpio(gc); 425 + struct sirfsoc_gpio_chip *sgpio = gpiochip_get_data(gc); 421 426 struct sirfsoc_gpio_bank *bank = sirfsoc_gpio_to_bank(sgpio, d->hwirq); 422 427 int idx = sirfsoc_gpio_to_bankoff(d->hwirq); 423 428 u32 val, offset; ··· 456 461 static void sirfsoc_gpio_irq_mask(struct irq_data *d) 457 462 { 458 463 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 459 - struct sirfsoc_gpio_chip *sgpio = to_sirfsoc_gpio(gc); 464 + struct sirfsoc_gpio_chip *sgpio = gpiochip_get_data(gc); 460 465 struct sirfsoc_gpio_bank *bank = sirfsoc_gpio_to_bank(sgpio, d->hwirq); 461 466 462 467 __sirfsoc_gpio_irq_mask(sgpio, bank, d->hwirq % SIRFSOC_GPIO_BANK_SIZE); ··· 465 470 static void sirfsoc_gpio_irq_unmask(struct irq_data *d) 466 471 { 467 472 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 468 - struct sirfsoc_gpio_chip *sgpio = to_sirfsoc_gpio(gc); 473 + struct sirfsoc_gpio_chip *sgpio = gpiochip_get_data(gc); 469 474 struct sirfsoc_gpio_bank *bank = sirfsoc_gpio_to_bank(sgpio, d->hwirq); 470 475 int idx = sirfsoc_gpio_to_bankoff(d->hwirq); 471 476 u32 val, offset; ··· 486 491 static int sirfsoc_gpio_irq_type(struct irq_data *d, unsigned type) 487 492 { 488 493 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 489 - struct sirfsoc_gpio_chip *sgpio = to_sirfsoc_gpio(gc); 494 + struct sirfsoc_gpio_chip *sgpio = gpiochip_get_data(gc); 490 495 struct sirfsoc_gpio_bank *bank = sirfsoc_gpio_to_bank(sgpio, d->hwirq); 491 496 int idx = sirfsoc_gpio_to_bankoff(d->hwirq); 492 497 u32 val, offset; ··· 548 553 { 549 554 unsigned int irq = irq_desc_get_irq(desc); 550 555 struct gpio_chip *gc = irq_desc_get_handler_data(desc); 551 - struct sirfsoc_gpio_chip *sgpio = to_sirfsoc_gpio(gc); 556 + struct sirfsoc_gpio_chip *sgpio = gpiochip_get_data(gc); 552 557 struct sirfsoc_gpio_bank *bank; 553 558 u32 status, ctrl; 554 559 int idx = 0; ··· 606 611 607 612 static int sirfsoc_gpio_request(struct gpio_chip *chip, unsigned offset) 608 613 { 609 - struct sirfsoc_gpio_chip *sgpio = to_sirfsoc_gpio(chip); 614 + struct sirfsoc_gpio_chip *sgpio = gpiochip_get_data(chip); 610 615 struct sirfsoc_gpio_bank *bank = sirfsoc_gpio_to_bank(sgpio, offset); 611 616 unsigned long flags; 612 617 ··· 629 634 630 635 static void sirfsoc_gpio_free(struct gpio_chip *chip, unsigned offset) 631 636 { 632 - struct sirfsoc_gpio_chip *sgpio = to_sirfsoc_gpio(chip); 637 + struct sirfsoc_gpio_chip *sgpio = gpiochip_get_data(chip); 633 638 struct sirfsoc_gpio_bank *bank = sirfsoc_gpio_to_bank(sgpio, offset); 634 639 unsigned long flags; 635 640 ··· 645 650 646 651 static int sirfsoc_gpio_direction_input(struct gpio_chip *chip, unsigned gpio) 647 652 { 648 - struct sirfsoc_gpio_chip *sgpio = to_sirfsoc_gpio(chip); 653 + struct sirfsoc_gpio_chip *sgpio = gpiochip_get_data(chip); 649 654 struct sirfsoc_gpio_bank *bank = sirfsoc_gpio_to_bank(sgpio, gpio); 650 655 int idx = sirfsoc_gpio_to_bankoff(gpio); 651 656 unsigned long flags; ··· 688 693 static int sirfsoc_gpio_direction_output(struct gpio_chip *chip, 689 694 unsigned gpio, int value) 690 695 { 691 - struct sirfsoc_gpio_chip *sgpio = to_sirfsoc_gpio(chip); 696 + struct sirfsoc_gpio_chip *sgpio = gpiochip_get_data(chip); 692 697 struct sirfsoc_gpio_bank *bank = sirfsoc_gpio_to_bank(sgpio, gpio); 693 698 int idx = sirfsoc_gpio_to_bankoff(gpio); 694 699 u32 offset; ··· 707 712 708 713 static int sirfsoc_gpio_get_value(struct gpio_chip *chip, unsigned offset) 709 714 { 710 - struct sirfsoc_gpio_chip *sgpio = to_sirfsoc_gpio(chip); 715 + struct sirfsoc_gpio_chip *sgpio = gpiochip_get_data(chip); 711 716 struct sirfsoc_gpio_bank *bank = sirfsoc_gpio_to_bank(sgpio, offset); 712 717 u32 val; 713 718 unsigned long flags; ··· 724 729 static void sirfsoc_gpio_set_value(struct gpio_chip *chip, unsigned offset, 725 730 int value) 726 731 { 727 - struct sirfsoc_gpio_chip *sgpio = to_sirfsoc_gpio(chip); 732 + struct sirfsoc_gpio_chip *sgpio = gpiochip_get_data(chip); 728 733 struct sirfsoc_gpio_bank *bank = sirfsoc_gpio_to_bank(sgpio, offset); 729 734 u32 ctrl; 730 735 unsigned long flags; ··· 810 815 sgpio->chip.gc.of_node = np; 811 816 sgpio->chip.gc.of_xlate = sirfsoc_gpio_of_xlate; 812 817 sgpio->chip.gc.of_gpio_n_cells = 2; 813 - sgpio->chip.gc.dev = &pdev->dev; 818 + sgpio->chip.gc.parent = &pdev->dev; 814 819 sgpio->chip.regs = regs; 815 820 816 - err = gpiochip_add(&sgpio->chip.gc); 821 + err = gpiochip_add_data(&sgpio->chip.gc, sgpio); 817 822 if (err) { 818 823 dev_err(&pdev->dev, "%s: error in probe function with status %d\n", 819 824 np->full_name, err);
+12 -12
drivers/pinctrl/spear/pinctrl-plgpio.c
··· 107 107 /* gpio framework specific routines */ 108 108 static int plgpio_direction_input(struct gpio_chip *chip, unsigned offset) 109 109 { 110 - struct plgpio *plgpio = container_of(chip, struct plgpio, chip); 110 + struct plgpio *plgpio = gpiochip_get_data(chip); 111 111 unsigned long flags; 112 112 113 113 /* get correct offset for "offset" pin */ ··· 127 127 static int plgpio_direction_output(struct gpio_chip *chip, unsigned offset, 128 128 int value) 129 129 { 130 - struct plgpio *plgpio = container_of(chip, struct plgpio, chip); 130 + struct plgpio *plgpio = gpiochip_get_data(chip); 131 131 unsigned long flags; 132 132 unsigned dir_offset = offset, wdata_offset = offset, tmp; 133 133 ··· 159 159 160 160 static int plgpio_get_value(struct gpio_chip *chip, unsigned offset) 161 161 { 162 - struct plgpio *plgpio = container_of(chip, struct plgpio, chip); 162 + struct plgpio *plgpio = gpiochip_get_data(chip); 163 163 164 164 if (offset >= chip->ngpio) 165 165 return -EINVAL; ··· 176 176 177 177 static void plgpio_set_value(struct gpio_chip *chip, unsigned offset, int value) 178 178 { 179 - struct plgpio *plgpio = container_of(chip, struct plgpio, chip); 179 + struct plgpio *plgpio = gpiochip_get_data(chip); 180 180 181 181 if (offset >= chip->ngpio) 182 182 return; ··· 196 196 197 197 static int plgpio_request(struct gpio_chip *chip, unsigned offset) 198 198 { 199 - struct plgpio *plgpio = container_of(chip, struct plgpio, chip); 199 + struct plgpio *plgpio = gpiochip_get_data(chip); 200 200 int gpio = chip->base + offset; 201 201 unsigned long flags; 202 202 int ret = 0; ··· 248 248 249 249 static void plgpio_free(struct gpio_chip *chip, unsigned offset) 250 250 { 251 - struct plgpio *plgpio = container_of(chip, struct plgpio, chip); 251 + struct plgpio *plgpio = gpiochip_get_data(chip); 252 252 int gpio = chip->base + offset; 253 253 unsigned long flags; 254 254 ··· 280 280 static void plgpio_irq_disable(struct irq_data *d) 281 281 { 282 282 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 283 - struct plgpio *plgpio = container_of(gc, struct plgpio, chip); 283 + struct plgpio *plgpio = gpiochip_get_data(gc); 284 284 int offset = d->hwirq; 285 285 unsigned long flags; 286 286 ··· 299 299 static void plgpio_irq_enable(struct irq_data *d) 300 300 { 301 301 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 302 - struct plgpio *plgpio = container_of(gc, struct plgpio, chip); 302 + struct plgpio *plgpio = gpiochip_get_data(gc); 303 303 int offset = d->hwirq; 304 304 unsigned long flags; 305 305 ··· 318 318 static int plgpio_irq_set_type(struct irq_data *d, unsigned trigger) 319 319 { 320 320 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 321 - struct plgpio *plgpio = container_of(gc, struct plgpio, chip); 321 + struct plgpio *plgpio = gpiochip_get_data(gc); 322 322 int offset = d->hwirq; 323 323 void __iomem *reg_off; 324 324 unsigned int supported_type = 0, val; ··· 359 359 static void plgpio_irq_handler(struct irq_desc *desc) 360 360 { 361 361 struct gpio_chip *gc = irq_desc_get_handler_data(desc); 362 - struct plgpio *plgpio = container_of(gc, struct plgpio, chip); 362 + struct plgpio *plgpio = gpiochip_get_data(gc); 363 363 struct irq_chip *irqchip = irq_desc_get_chip(desc); 364 364 int regs_count, count, pin, offset, i = 0; 365 365 unsigned long pending; ··· 561 561 plgpio->chip.get = plgpio_get_value; 562 562 plgpio->chip.set = plgpio_set_value; 563 563 plgpio->chip.label = dev_name(&pdev->dev); 564 - plgpio->chip.dev = &pdev->dev; 564 + plgpio->chip.parent = &pdev->dev; 565 565 plgpio->chip.owner = THIS_MODULE; 566 566 plgpio->chip.of_node = pdev->dev.of_node; 567 567 ··· 573 573 } 574 574 } 575 575 576 - ret = gpiochip_add(&plgpio->chip); 576 + ret = gpiochip_add_data(&plgpio->chip, plgpio); 577 577 if (ret) { 578 578 dev_err(&pdev->dev, "unable to add gpio chip\n"); 579 579 goto unprepare_clk;
+8 -8
drivers/pinctrl/sunxi/pinctrl-sunxi.c
··· 12 12 13 13 #include <linux/io.h> 14 14 #include <linux/clk.h> 15 - #include <linux/gpio.h> 15 + #include <linux/gpio/driver.h> 16 16 #include <linux/irqdomain.h> 17 17 #include <linux/irqchip/chained_irq.h> 18 18 #include <linux/module.h> ··· 454 454 455 455 static int sunxi_pinctrl_gpio_get(struct gpio_chip *chip, unsigned offset) 456 456 { 457 - struct sunxi_pinctrl *pctl = dev_get_drvdata(chip->dev); 457 + struct sunxi_pinctrl *pctl = gpiochip_get_data(chip); 458 458 u32 reg = sunxi_data_reg(offset); 459 459 u8 index = sunxi_data_offset(offset); 460 460 u32 set_mux = pctl->desc->irq_read_needs_mux && ··· 469 469 if (set_mux) 470 470 sunxi_pmx_set(pctl->pctl_dev, offset, SUN4I_FUNC_IRQ); 471 471 472 - return val; 472 + return !!val; 473 473 } 474 474 475 475 static void sunxi_pinctrl_gpio_set(struct gpio_chip *chip, 476 476 unsigned offset, int value) 477 477 { 478 - struct sunxi_pinctrl *pctl = dev_get_drvdata(chip->dev); 478 + struct sunxi_pinctrl *pctl = gpiochip_get_data(chip); 479 479 u32 reg = sunxi_data_reg(offset); 480 480 u8 index = sunxi_data_offset(offset); 481 481 unsigned long flags; ··· 522 522 523 523 static int sunxi_pinctrl_gpio_to_irq(struct gpio_chip *chip, unsigned offset) 524 524 { 525 - struct sunxi_pinctrl *pctl = dev_get_drvdata(chip->dev); 525 + struct sunxi_pinctrl *pctl = gpiochip_get_data(chip); 526 526 struct sunxi_desc_function *desc; 527 527 unsigned pinnum = pctl->desc->pin_base + offset; 528 528 unsigned irqnum; ··· 536 536 537 537 irqnum = desc->irqbank * IRQ_PER_BANK + desc->irqnum; 538 538 539 - dev_dbg(chip->dev, "%s: request IRQ for GPIO %d, return %d\n", 539 + dev_dbg(chip->parent, "%s: request IRQ for GPIO %d, return %d\n", 540 540 chip->label, offset + chip->base, irqnum); 541 541 542 542 return irq_find_mapping(pctl->domain, irqnum); ··· 959 959 pctl->chip->ngpio = round_up(last_pin, PINS_PER_BANK) - 960 960 pctl->desc->pin_base; 961 961 pctl->chip->label = dev_name(&pdev->dev); 962 - pctl->chip->dev = &pdev->dev; 962 + pctl->chip->parent = &pdev->dev; 963 963 pctl->chip->base = pctl->desc->pin_base; 964 964 965 - ret = gpiochip_add(pctl->chip); 965 + ret = gpiochip_add_data(pctl->chip, pctl); 966 966 if (ret) 967 967 goto pinctrl_error; 968 968
+6 -6
drivers/pinctrl/vt8500/pinctrl-wmt.c
··· 14 14 */ 15 15 16 16 #include <linux/err.h> 17 - #include <linux/gpio.h> 17 + #include <linux/gpio/driver.h> 18 18 #include <linux/interrupt.h> 19 19 #include <linux/io.h> 20 20 #include <linux/irq.h> ··· 488 488 489 489 static int wmt_gpio_get_direction(struct gpio_chip *chip, unsigned offset) 490 490 { 491 - struct wmt_pinctrl_data *data = dev_get_drvdata(chip->dev); 491 + struct wmt_pinctrl_data *data = gpiochip_get_data(chip); 492 492 u32 bank = WMT_BANK_FROM_PIN(offset); 493 493 u32 bit = WMT_BIT_FROM_PIN(offset); 494 494 u32 reg_dir = data->banks[bank].reg_dir; ··· 503 503 504 504 static int wmt_gpio_get_value(struct gpio_chip *chip, unsigned offset) 505 505 { 506 - struct wmt_pinctrl_data *data = dev_get_drvdata(chip->dev); 506 + struct wmt_pinctrl_data *data = gpiochip_get_data(chip); 507 507 u32 bank = WMT_BANK_FROM_PIN(offset); 508 508 u32 bit = WMT_BIT_FROM_PIN(offset); 509 509 u32 reg_data_in = data->banks[bank].reg_data_in; ··· 519 519 static void wmt_gpio_set_value(struct gpio_chip *chip, unsigned offset, 520 520 int val) 521 521 { 522 - struct wmt_pinctrl_data *data = dev_get_drvdata(chip->dev); 522 + struct wmt_pinctrl_data *data = gpiochip_get_data(chip); 523 523 u32 bank = WMT_BANK_FROM_PIN(offset); 524 524 u32 bit = WMT_BIT_FROM_PIN(offset); 525 525 u32 reg_data_out = data->banks[bank].reg_data_out; ··· 575 575 wmt_desc.npins = data->npins; 576 576 577 577 data->gpio_chip = wmt_gpio_chip; 578 - data->gpio_chip.dev = &pdev->dev; 578 + data->gpio_chip.parent = &pdev->dev; 579 579 data->gpio_chip.of_node = pdev->dev.of_node; 580 580 data->gpio_chip.ngpio = data->nbanks * 32; 581 581 ··· 589 589 return PTR_ERR(data->pctl_dev); 590 590 } 591 591 592 - err = gpiochip_add(&data->gpio_chip); 592 + err = gpiochip_add_data(&data->gpio_chip, data); 593 593 if (err) { 594 594 dev_err(&pdev->dev, "could not add GPIO chip\n"); 595 595 goto fail_gpio;
+2 -2
drivers/platform/x86/intel_pmic_gpio.c
··· 274 274 pg->chip.base = pdata->gpio_base; 275 275 pg->chip.ngpio = NUM_GPIO; 276 276 pg->chip.can_sleep = 1; 277 - pg->chip.dev = dev; 277 + pg->chip.parent = dev; 278 278 279 279 mutex_init(&pg->buslock); 280 280 281 - pg->chip.dev = dev; 281 + pg->chip.parent = dev; 282 282 retval = gpiochip_add(&pg->chip); 283 283 if (retval) { 284 284 pr_err("Can not add pmic gpio chip\n");
+1 -1
drivers/tty/serial/max310x.c
··· 1174 1174 #ifdef CONFIG_GPIOLIB 1175 1175 /* Setup GPIO cotroller */ 1176 1176 s->gpio.owner = THIS_MODULE; 1177 - s->gpio.dev = dev; 1177 + s->gpio.parent = dev; 1178 1178 s->gpio.label = dev_name(dev); 1179 1179 s->gpio.direction_input = max310x_gpio_direction_input; 1180 1180 s->gpio.get = max310x_gpio_get;
+1 -1
drivers/tty/serial/sc16is7xx.c
··· 1193 1193 if (devtype->nr_gpio) { 1194 1194 /* Setup GPIO cotroller */ 1195 1195 s->gpio.owner = THIS_MODULE; 1196 - s->gpio.dev = dev; 1196 + s->gpio.parent = dev; 1197 1197 s->gpio.label = dev_name(dev); 1198 1198 s->gpio.direction_input = sc16is7xx_gpio_direction_input; 1199 1199 s->gpio.get = sc16is7xx_gpio_get;
+7 -12
drivers/video/fbdev/via/via-gpio.c
··· 6 6 */ 7 7 8 8 #include <linux/spinlock.h> 9 - #include <linux/gpio.h> 9 + #include <linux/gpio/driver.h> 10 10 #include <linux/platform_device.h> 11 11 #include <linux/via-core.h> 12 12 #include <linux/via-gpio.h> ··· 83 83 static void via_gpio_set(struct gpio_chip *chip, unsigned int nr, 84 84 int value) 85 85 { 86 - struct viafb_gpio_cfg *cfg = container_of(chip, 87 - struct viafb_gpio_cfg, 88 - gpio_chip); 86 + struct viafb_gpio_cfg *cfg = gpiochip_get_data(chip); 89 87 u8 reg; 90 88 struct viafb_gpio *gpio; 91 89 unsigned long flags; ··· 113 115 */ 114 116 static int via_gpio_dir_input(struct gpio_chip *chip, unsigned int nr) 115 117 { 116 - struct viafb_gpio_cfg *cfg = container_of(chip, 117 - struct viafb_gpio_cfg, 118 - gpio_chip); 118 + struct viafb_gpio_cfg *cfg = gpiochip_get_data(chip); 119 119 struct viafb_gpio *gpio; 120 120 unsigned long flags; 121 121 ··· 127 131 128 132 static int via_gpio_get(struct gpio_chip *chip, unsigned int nr) 129 133 { 130 - struct viafb_gpio_cfg *cfg = container_of(chip, 131 - struct viafb_gpio_cfg, 132 - gpio_chip); 134 + struct viafb_gpio_cfg *cfg = gpiochip_get_data(chip); 133 135 u8 reg; 134 136 struct viafb_gpio *gpio; 135 137 unsigned long flags; ··· 136 142 gpio = cfg->active_gpios[nr]; 137 143 reg = via_read_reg(VIASR, gpio->vg_port_index); 138 144 spin_unlock_irqrestore(&cfg->vdev->reg_lock, flags); 139 - return reg & (0x04 << gpio->vg_mask_shift); 145 + return !!(reg & (0x04 << gpio->vg_mask_shift)); 140 146 } 141 147 142 148 ··· 249 255 * Get registered. 250 256 */ 251 257 viafb_gpio_config.gpio_chip.base = -1; /* Dynamic */ 252 - ret = gpiochip_add(&viafb_gpio_config.gpio_chip); 258 + ret = gpiochip_add_data(&viafb_gpio_config.gpio_chip, 259 + &viafb_gpio_config); 253 260 if (ret) { 254 261 printk(KERN_ERR "viafb: failed to add gpios (%d)\n", ret); 255 262 viafb_gpio_config.gpio_chip.ngpio = 0;
-80
include/linux/basic_mmio_gpio.h
··· 1 - /* 2 - * Basic memory-mapped GPIO controllers. 3 - * 4 - * Copyright 2008 MontaVista Software, Inc. 5 - * Copyright 2008,2010 Anton Vorontsov <cbouatmailru@gmail.com> 6 - * 7 - * This program is free software; you can redistribute it and/or modify it 8 - * under the terms of the GNU General Public License as published by the 9 - * Free Software Foundation; either version 2 of the License, or (at your 10 - * option) any later version. 11 - */ 12 - 13 - #ifndef __BASIC_MMIO_GPIO_H 14 - #define __BASIC_MMIO_GPIO_H 15 - 16 - #include <linux/gpio.h> 17 - #include <linux/types.h> 18 - #include <linux/compiler.h> 19 - #include <linux/spinlock_types.h> 20 - 21 - struct bgpio_pdata { 22 - const char *label; 23 - int base; 24 - int ngpio; 25 - }; 26 - 27 - struct device; 28 - 29 - struct bgpio_chip { 30 - struct gpio_chip gc; 31 - 32 - unsigned long (*read_reg)(void __iomem *reg); 33 - void (*write_reg)(void __iomem *reg, unsigned long data); 34 - 35 - void __iomem *reg_dat; 36 - void __iomem *reg_set; 37 - void __iomem *reg_clr; 38 - void __iomem *reg_dir; 39 - 40 - /* Number of bits (GPIOs): <register width> * 8. */ 41 - int bits; 42 - 43 - /* 44 - * Some GPIO controllers work with the big-endian bits notation, 45 - * e.g. in a 8-bits register, GPIO7 is the least significant bit. 46 - */ 47 - unsigned long (*pin2mask)(struct bgpio_chip *bgc, unsigned int pin); 48 - 49 - /* 50 - * Used to lock bgpio_chip->data. Also, this is needed to keep 51 - * shadowed and real data registers writes together. 52 - */ 53 - spinlock_t lock; 54 - 55 - /* Shadowed data register to clear/set bits safely. */ 56 - unsigned long data; 57 - 58 - /* Shadowed direction registers to clear/set direction safely. */ 59 - unsigned long dir; 60 - }; 61 - 62 - static inline struct bgpio_chip *to_bgpio_chip(struct gpio_chip *gc) 63 - { 64 - return container_of(gc, struct bgpio_chip, gc); 65 - } 66 - 67 - int bgpio_remove(struct bgpio_chip *bgc); 68 - int bgpio_init(struct bgpio_chip *bgc, struct device *dev, 69 - unsigned long sz, void __iomem *dat, void __iomem *set, 70 - void __iomem *clr, void __iomem *dirout, void __iomem *dirin, 71 - unsigned long flags); 72 - 73 - #define BGPIOF_BIG_ENDIAN BIT(0) 74 - #define BGPIOF_UNREADABLE_REG_SET BIT(1) /* reg_set is unreadable */ 75 - #define BGPIOF_UNREADABLE_REG_DIR BIT(2) /* reg_dir is unreadable */ 76 - #define BGPIOF_BIG_ENDIAN_BYTE_ORDER BIT(3) 77 - #define BGPIOF_READ_OUTPUT_REG_SET BIT(4) /* reg_set stores output value */ 78 - #define BGPIOF_NO_OUTPUT BIT(5) /* only input */ 79 - 80 - #endif /* __BASIC_MMIO_GPIO_H */
+70 -5
include/linux/gpio/driver.h
··· 8 8 #include <linux/irqdomain.h> 9 9 #include <linux/lockdep.h> 10 10 #include <linux/pinctrl/pinctrl.h> 11 + #include <linux/kconfig.h> 11 12 12 13 struct device; 13 14 struct gpio_desc; ··· 21 20 /** 22 21 * struct gpio_chip - abstract a GPIO controller 23 22 * @label: for diagnostics 24 - * @dev: optional device providing the GPIOs 23 + * @parent: optional parent device providing the GPIOs 25 24 * @cdev: class device used by sysfs interface (may be NULL) 26 25 * @owner: helps prevent removal of modules exporting active GPIOs 26 + * @data: per-instance data assigned by the driver 27 27 * @list: links gpio_chips together for traversal 28 28 * @request: optional hook for chip-specific activation, such as 29 29 * enabling module power and clock; may sleep ··· 34 32 * (same as GPIOF_DIR_XXX), or negative error 35 33 * @direction_input: configures signal "offset" as input, or returns error 36 34 * @direction_output: configures signal "offset" as output, or returns error 37 - * @get: returns value for signal "offset"; for output signals this 38 - * returns either the value actually sensed, or zero 35 + * @get: returns value for signal "offset", 0=low, 1=high, or negative error 39 36 * @set: assigns output value for signal "offset" 40 37 * @set_multiple: assigns output values for multiple signals defined by "mask" 41 38 * @set_debounce: optional hook for setting debounce time for specified gpio in ··· 66 65 * registers. 67 66 * @irq_not_threaded: flag must be set if @can_sleep is set but the 68 67 * IRQs don't need to be threaded 68 + * @read_reg: reader function for generic GPIO 69 + * @write_reg: writer function for generic GPIO 70 + * @pin2mask: some generic GPIO controllers work with the big-endian bits 71 + * notation, e.g. in a 8-bits register, GPIO7 is the least significant 72 + * bit. This callback assigns the right bit mask. 73 + * @reg_dat: data (in) register for generic GPIO 74 + * @reg_set: output set register (out=high) for generic GPIO 75 + * @reg_clk: output clear register (out=low) for generic GPIO 76 + * @reg_dir: direction setting register for generic GPIO 77 + * @bgpio_bits: number of register bits used for a generic GPIO i.e. 78 + * <register width> * 8 79 + * @bgpio_lock: used to lock chip->bgpio_data. Also, this is needed to keep 80 + * shadowed and real data registers writes together. 81 + * @bgpio_data: shadowed data register for generic GPIO to clear/set bits 82 + * safely. 83 + * @bgpio_dir: shadowed direction register for generic GPIO to clear/set 84 + * direction safely. 69 85 * @irqchip: GPIO IRQ chip impl, provided by GPIO driver 70 86 * @irqdomain: Interrupt translation domain; responsible for mapping 71 87 * between GPIO hwirq number and linux irq number ··· 107 89 */ 108 90 struct gpio_chip { 109 91 const char *label; 110 - struct device *dev; 92 + struct device *parent; 111 93 struct device *cdev; 112 94 struct module *owner; 95 + void *data; 113 96 struct list_head list; 114 97 115 98 int (*request)(struct gpio_chip *chip, ··· 145 126 const char *const *names; 146 127 bool can_sleep; 147 128 bool irq_not_threaded; 129 + 130 + #if IS_ENABLED(CONFIG_GPIO_GENERIC) 131 + unsigned long (*read_reg)(void __iomem *reg); 132 + void (*write_reg)(void __iomem *reg, unsigned long data); 133 + unsigned long (*pin2mask)(struct gpio_chip *gc, unsigned int pin); 134 + void __iomem *reg_dat; 135 + void __iomem *reg_set; 136 + void __iomem *reg_clr; 137 + void __iomem *reg_dir; 138 + int bgpio_bits; 139 + spinlock_t bgpio_lock; 140 + unsigned long bgpio_data; 141 + unsigned long bgpio_dir; 142 + #endif 148 143 149 144 #ifdef CONFIG_GPIOLIB_IRQCHIP 150 145 /* ··· 199 166 unsigned offset); 200 167 201 168 /* add/remove chips */ 202 - extern int gpiochip_add(struct gpio_chip *chip); 169 + extern int gpiochip_add_data(struct gpio_chip *chip, void *data); 170 + static inline int gpiochip_add(struct gpio_chip *chip) 171 + { 172 + return gpiochip_add_data(chip, NULL); 173 + } 203 174 extern void gpiochip_remove(struct gpio_chip *chip); 204 175 extern struct gpio_chip *gpiochip_find(void *data, 205 176 int (*match)(struct gpio_chip *chip, void *data)); ··· 212 175 int gpiochip_lock_as_irq(struct gpio_chip *chip, unsigned int offset); 213 176 void gpiochip_unlock_as_irq(struct gpio_chip *chip, unsigned int offset); 214 177 178 + /* get driver data */ 179 + static inline void *gpiochip_get_data(struct gpio_chip *chip) 180 + { 181 + return chip->data; 182 + } 183 + 215 184 struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc); 185 + 186 + struct bgpio_pdata { 187 + const char *label; 188 + int base; 189 + int ngpio; 190 + }; 191 + 192 + #if IS_ENABLED(CONFIG_GPIO_GENERIC) 193 + 194 + int bgpio_init(struct gpio_chip *gc, struct device *dev, 195 + unsigned long sz, void __iomem *dat, void __iomem *set, 196 + void __iomem *clr, void __iomem *dirout, void __iomem *dirin, 197 + unsigned long flags); 198 + 199 + #define BGPIOF_BIG_ENDIAN BIT(0) 200 + #define BGPIOF_UNREADABLE_REG_SET BIT(1) /* reg_set is unreadable */ 201 + #define BGPIOF_UNREADABLE_REG_DIR BIT(2) /* reg_dir is unreadable */ 202 + #define BGPIOF_BIG_ENDIAN_BYTE_ORDER BIT(3) 203 + #define BGPIOF_READ_OUTPUT_REG_SET BIT(4) /* reg_set stores output value */ 204 + #define BGPIOF_NO_OUTPUT BIT(5) /* only input */ 205 + 206 + #endif 216 207 217 208 #ifdef CONFIG_GPIOLIB_IRQCHIP 218 209
+11 -2
include/linux/of_gpio.h
··· 51 51 extern int of_get_named_gpio_flags(struct device_node *np, 52 52 const char *list_name, int index, enum of_gpio_flags *flags); 53 53 54 - extern int of_mm_gpiochip_add(struct device_node *np, 55 - struct of_mm_gpio_chip *mm_gc); 54 + extern int of_mm_gpiochip_add_data(struct device_node *np, 55 + struct of_mm_gpio_chip *mm_gc, 56 + void *data); 57 + static inline int of_mm_gpiochip_add(struct device_node *np, 58 + struct of_mm_gpio_chip *mm_gc) 59 + { 60 + return of_mm_gpiochip_add_data(np, mm_gc, NULL); 61 + } 56 62 extern void of_mm_gpiochip_remove(struct of_mm_gpio_chip *mm_gc); 57 63 58 64 extern int of_gpiochip_add(struct gpio_chip *gc); ··· 73 67 static inline int of_get_named_gpio_flags(struct device_node *np, 74 68 const char *list_name, int index, enum of_gpio_flags *flags) 75 69 { 70 + if (flags) 71 + *flags = 0; 72 + 76 73 return -ENOSYS; 77 74 } 78 75
-29
include/linux/platform_data/gpio-rcar.h
··· 1 - /* 2 - * Renesas R-Car GPIO Support 3 - * 4 - * Copyright (C) 2013 Magnus Damm 5 - * 6 - * This program is free software; you can redistribute it and/or modify 7 - * it under the terms of the GNU General Public License as published by 8 - * the Free Software Foundation; either version 2 of the License 9 - * 10 - * This program is distributed in the hope that it will be useful, 11 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 - * GNU General Public License for more details. 14 - */ 15 - 16 - #ifndef __GPIO_RCAR_H__ 17 - #define __GPIO_RCAR_H__ 18 - 19 - struct gpio_rcar_config { 20 - int gpio_base; 21 - unsigned int irq_base; 22 - unsigned int number_of_pins; 23 - const char *pctl_name; 24 - unsigned has_both_edge_trigger:1; 25 - }; 26 - 27 - #define RCAR_GP_PIN(bank, pin) (((bank) * 32) + (pin)) 28 - 29 - #endif /* __GPIO_RCAR_H__ */
+1 -1
sound/soc/codecs/rt5677.c
··· 4694 4694 4695 4695 rt5677->gpio_chip = rt5677_template_chip; 4696 4696 rt5677->gpio_chip.ngpio = RT5677_GPIO_NUM; 4697 - rt5677->gpio_chip.dev = &i2c->dev; 4697 + rt5677->gpio_chip.parent = &i2c->dev; 4698 4698 rt5677->gpio_chip.base = -1; 4699 4699 4700 4700 ret = gpiochip_add(&rt5677->gpio_chip);
+1 -1
sound/soc/codecs/wm5100.c
··· 2306 2306 2307 2307 wm5100->gpio_chip = wm5100_template_chip; 2308 2308 wm5100->gpio_chip.ngpio = 6; 2309 - wm5100->gpio_chip.dev = &i2c->dev; 2309 + wm5100->gpio_chip.parent = &i2c->dev; 2310 2310 2311 2311 if (wm5100->pdata.gpio_base) 2312 2312 wm5100->gpio_chip.base = wm5100->pdata.gpio_base;
+1 -1
sound/soc/codecs/wm8903.c
··· 1853 1853 1854 1854 wm8903->gpio_chip = wm8903_template_chip; 1855 1855 wm8903->gpio_chip.ngpio = WM8903_NUM_GPIO; 1856 - wm8903->gpio_chip.dev = wm8903->dev; 1856 + wm8903->gpio_chip.parent = wm8903->dev; 1857 1857 1858 1858 if (pdata->gpio_base) 1859 1859 wm8903->gpio_chip.base = pdata->gpio_base;
+1 -1
sound/soc/codecs/wm8962.c
··· 3379 3379 3380 3380 wm8962->gpio_chip = wm8962_template_chip; 3381 3381 wm8962->gpio_chip.ngpio = WM8962_MAX_GPIO; 3382 - wm8962->gpio_chip.dev = codec->dev; 3382 + wm8962->gpio_chip.parent = codec->dev; 3383 3383 3384 3384 if (pdata->gpio_base) 3385 3385 wm8962->gpio_chip.base = pdata->gpio_base;
+1 -1
sound/soc/codecs/wm8996.c
··· 2204 2204 2205 2205 wm8996->gpio_chip = wm8996_template_chip; 2206 2206 wm8996->gpio_chip.ngpio = 5; 2207 - wm8996->gpio_chip.dev = wm8996->dev; 2207 + wm8996->gpio_chip.parent = wm8996->dev; 2208 2208 2209 2209 if (wm8996->pdata.gpio_base) 2210 2210 wm8996->gpio_chip.base = wm8996->pdata.gpio_base;
+1 -1
sound/soc/soc-ac97.c
··· 142 142 gpio_priv->codec = codec; 143 143 gpio_priv->gpio_chip = snd_soc_ac97_gpio_chip; 144 144 gpio_priv->gpio_chip.ngpio = AC97_NUM_GPIOS; 145 - gpio_priv->gpio_chip.dev = codec->dev; 145 + gpio_priv->gpio_chip.parent = codec->dev; 146 146 gpio_priv->gpio_chip.base = -1; 147 147 148 148 ret = gpiochip_add(&gpio_priv->gpio_chip);