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

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

Pull GPIO changes from Linus Walleij:
"Here is the bulk of GPIO changes for the v3.13 development cycle.

I've got ACKs for the things that affect other subsystems (or it's my
own subsystem, like pinctrl). Most of that pertain to an attempt from
my side to consolidate and get rid of custom GPIO implementations in
the ARM tree. I will continue doing this.

The main change this time is the new GPIO descriptor API, background
for this can be found in Corbet's summary from this january in LWN:

http://lwn.net/Articles/533632/

Summary:

- Merged the GPIO descriptor API from Alexandre Courbot. This is a
first step toward trying to get rid of the global GPIO numberspace
for the future.

- Add an API so that driver can flag that a certain GPIO line is
being used by a irqchip backend for generating IRQs, so that we can
enforce checks, like not allowing users to switch that line to an
output at runtime, since this makes no sense. Implemented
corresponding calls in a few select drivers.

- ACPI GPIO cleanups, refactorings and switch to using the
descriptor-based interface.

- Support for the TPS80036 Palmas GPIO variant.

- A new driver for the Broadcom Kona GPIO SoC IP block.

- Device tree support for the PCF857x driver.

- A set of ARM GPIO refactorings with the goal of getting rid of a
bunch of custom GPIO implementations from the arch/arm/* tree:

* Move the IOP GPIO driver to the GPIO subsystem and fix all users
to use the gpiolib API for accessing GPIOs. Delete the old
custom GPIO implementation.

* Delete the unused custom PXA GPIO implemention.

* Convert all users of the IXP4 custom GPIO implementation to use
gpiolib and delete the custom implementation.

* Delete the custom Gemini GPIO implementation, also completely
unused.

- Various cleanups and renamings"

* tag 'gpio-v3.13-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio: (85 commits)
gpio: gpio-mxs: Remove unneeded dt checks
gpio: pl061: don't depend on CONFIG_ARM
gpio: bcm-kona: add missing .owner to struct gpio_chip
gpiolib: provide a declaration of seq_file in gpio/driver.h
gpiolib: include gpio/consumer.h in of_gpio.h for desc_to_gpio()
gpio: provide stubs for devres gpio functions
gpiolib: devres: add missing headers
gpiolib: make GPIO_DEVRES depend on GPIOLIB
gpiolib: devres: fix devm_gpiod_get_index()
gpiolib / ACPI: document the GPIO descriptor based interface
gpiolib / ACPI: allow passing GPIOF_ACTIVE_LOW for GpioInt resources
gpiolib / ACPI: add ACPI support for gpiod_get_index()
gpiolib / ACPI: convert to gpiod interfaces
gpiolib: add gpiod_get() and gpiod_put() functions
gpiolib: port of_ functions to use gpiod
gpiolib: export descriptor-based GPIO interface
Fixup "MAINTAINERS: GPIO-INTEL-MID: add maintainer"
gpio: bcm281xx: Don't print addresses of GPIO area in probe()
gpio: tegra: use new gpio_lock_as_irq() API
gpio: rcar: Include linux/of.h header
...

+3234 -1490
+22 -4
Documentation/acpi/enumeration.txt
··· 295 295 specifies the path to the controller. In order to use these GPIOs in Linux 296 296 we need to translate them to the Linux GPIO numbers. 297 297 298 - The driver can do this by including <linux/acpi_gpio.h> and then calling 299 - acpi_get_gpio(path, gpio). This will return the Linux GPIO number or 300 - negative errno if there was no translation found. 301 - 302 298 In a simple case of just getting the Linux GPIO number from device 303 299 resources one can use acpi_get_gpio_by_index() helper function. It takes 304 300 pointer to the device and index of the GpioIo/GpioInt descriptor in the ··· 318 322 319 323 In case of GpioInt resource an additional call to gpio_to_irq() must be 320 324 done before calling request_irq(). 325 + 326 + Note that the above API is ACPI specific and not recommended for drivers 327 + that need to support non-ACPI systems. The recommended way is to use 328 + the descriptor based GPIO interfaces. The above example looks like this 329 + when converted to the GPIO desc: 330 + 331 + #include <linux/gpio/consumer.h> 332 + ... 333 + 334 + struct gpio_desc *irq_desc, *power_desc; 335 + 336 + irq_desc = gpiod_get_index(dev, NULL, 1); 337 + if (IS_ERR(irq_desc)) 338 + /* handle error */ 339 + 340 + power_desc = gpiod_get_index(dev, NULL, 0); 341 + if (IS_ERR(power_desc)) 342 + /* handle error */ 343 + 344 + /* Now we can use the GPIO descriptors */ 345 + 346 + See also Documentation/gpio.txt.
+52
Documentation/devicetree/bindings/gpio/gpio-bcm-kona.txt
··· 1 + Broadcom Kona Family GPIO 2 + ========================= 3 + 4 + This GPIO driver is used in the following Broadcom SoCs: 5 + BCM11130, BCM11140, BCM11351, BCM28145, BCM28155 6 + 7 + The Broadcom GPIO Controller IP can be configured prior to synthesis to 8 + support up to 8 banks of 32 GPIOs where each bank has its own IRQ. The 9 + GPIO controller only supports edge, not level, triggering of interrupts. 10 + 11 + Required properties 12 + ------------------- 13 + 14 + - compatible: "brcm,bcm11351-gpio", "brcm,kona-gpio" 15 + - reg: Physical base address and length of the controller's registers. 16 + - interrupts: The interrupt outputs from the controller. There is one GPIO 17 + interrupt per GPIO bank. The number of interrupts listed depends on the 18 + number of GPIO banks on the SoC. The interrupts must be ordered by bank, 19 + starting with bank 0. There is always a 1:1 mapping between banks and 20 + IRQs. 21 + - #gpio-cells: Should be <2>. The first cell is the pin number, the second 22 + cell is used to specify optional parameters: 23 + - bit 0 specifies polarity (0 for normal, 1 for inverted) 24 + See also "gpio-specifier" in .../devicetree/bindings/gpio/gpio.txt. 25 + - #interrupt-cells: Should be <2>. The first cell is the GPIO number. The 26 + second cell is used to specify flags. The following subset of flags is 27 + supported: 28 + - trigger type (bits[1:0]): 29 + 1 = low-to-high edge triggered. 30 + 2 = high-to-low edge triggered. 31 + 3 = low-to-high or high-to-low edge triggered 32 + Valid values are 1, 2, 3 33 + See also .../devicetree/bindings/interrupt-controller/interrupts.txt. 34 + - gpio-controller: Marks the device node as a GPIO controller. 35 + - interrupt-controller: Marks the device node as an interrupt controller. 36 + 37 + Example: 38 + gpio: gpio@35003000 { 39 + compatible = "brcm,bcm11351-gpio", "brcm,kona-gpio"; 40 + reg = <0x35003000 0x800>; 41 + interrupts = 42 + <GIC_SPI 106 IRQ_TYPE_LEVEL_HIGH 43 + GIC_SPI 115 IRQ_TYPE_LEVEL_HIGH 44 + GIC_SPI 114 IRQ_TYPE_LEVEL_HIGH 45 + GIC_SPI 113 IRQ_TYPE_LEVEL_HIGH 46 + GIC_SPI 112 IRQ_TYPE_LEVEL_HIGH 47 + GIC_SPI 111 IRQ_TYPE_LEVEL_HIGH>; 48 + #gpio-cells = <2>; 49 + #interrupt-cells = <2>; 50 + gpio-controller; 51 + interrupt-controller; 52 + };
+71
Documentation/devicetree/bindings/gpio/gpio-pcf857x.txt
··· 1 + * PCF857x-compatible I/O expanders 2 + 3 + The PCF857x-compatible chips have "quasi-bidirectional" I/O lines that can be 4 + driven high by a pull-up current source or driven low to ground. This combines 5 + the direction and output level into a single bit per line, which can't be read 6 + back. We can't actually know at initialization time whether a line is configured 7 + (a) as output and driving the signal low/high, or (b) as input and reporting a 8 + low/high value, without knowing the last value written since the chip came out 9 + of reset (if any). The only reliable solution for setting up line direction is 10 + thus to do it explicitly. 11 + 12 + Required Properties: 13 + 14 + - compatible: should be one of the following. 15 + - "maxim,max7328": For the Maxim MAX7378 16 + - "maxim,max7329": For the Maxim MAX7329 17 + - "nxp,pca8574": For the NXP PCA8574 18 + - "nxp,pca8575": For the NXP PCA8575 19 + - "nxp,pca9670": For the NXP PCA9670 20 + - "nxp,pca9671": For the NXP PCA9671 21 + - "nxp,pca9672": For the NXP PCA9672 22 + - "nxp,pca9673": For the NXP PCA9673 23 + - "nxp,pca9674": For the NXP PCA9674 24 + - "nxp,pca9675": For the NXP PCA9675 25 + - "nxp,pcf8574": For the NXP PCF8574 26 + - "nxp,pcf8574a": For the NXP PCF8574A 27 + - "nxp,pcf8575": For the NXP PCF8575 28 + - "ti,tca9554": For the TI TCA9554 29 + 30 + - reg: I2C slave address. 31 + 32 + - gpio-controller: Marks the device node as a gpio controller. 33 + - #gpio-cells: Should be 2. The first cell is the GPIO number and the second 34 + cell specifies GPIO flags, as defined in <dt-bindings/gpio/gpio.h>. Only the 35 + GPIO_ACTIVE_HIGH and GPIO_ACTIVE_LOW flags are supported. 36 + 37 + Optional Properties: 38 + 39 + - lines-initial-states: Bitmask that specifies the initial state of each 40 + line. When a bit is set to zero, the corresponding line will be initialized to 41 + the input (pulled-up) state. When the bit is set to one, the line will be 42 + initialized the the low-level output state. If the property is not specified 43 + all lines will be initialized to the input state. 44 + 45 + The I/O expander can detect input state changes, and thus optionally act as 46 + an interrupt controller. When the expander interrupt line is connected all the 47 + following properties must be set. For more information please see the 48 + interrupt controller device tree bindings documentation available at 49 + Documentation/devicetree/bindings/interrupt-controller/interrupts.txt. 50 + 51 + - interrupt-controller: Identifies the node as an interrupt controller. 52 + - #interrupt-cells: Number of cells to encode an interrupt source, shall be 2. 53 + - interrupt-parent: phandle of the parent interrupt controller. 54 + - interrupts: Interrupt specifier for the controllers interrupt. 55 + 56 + 57 + Please refer to gpio.txt in this directory for details of the common GPIO 58 + bindings used by client devices. 59 + 60 + Example: PCF8575 I/O expander node 61 + 62 + pcf8575: gpio@20 { 63 + compatible = "nxp,pcf8575"; 64 + reg = <0x20>; 65 + interrupt-parent = <&irqpin2>; 66 + interrupts = <3 0>; 67 + gpio-controller; 68 + #gpio-cells = <2>; 69 + interrupt-controller; 70 + #interrupt-cells = <2>; 71 + };
+6
MAINTAINERS
··· 4440 4440 F: Documentation/networking/i40e.txt 4441 4441 F: drivers/net/ethernet/intel/ 4442 4442 4443 + INTEL-MID GPIO DRIVER 4444 + M: David Cohen <david.a.cohen@linux.intel.com> 4445 + L: linux-gpio@vger.kernel.org 4446 + S: Maintained 4447 + F: drivers/gpio/gpio-intel-mid.c 4448 + 4443 4449 INTEL PRO/WIRELESS 2100, 2200BG, 2915ABG NETWORK CONNECTION SUPPORT 4444 4450 M: Stanislav Yakovlev <stas.yakovlev@gmail.com> 4445 4451 L: linux-wireless@vger.kernel.org
+2 -5
arch/arm/Kconfig
··· 389 389 select CLKSRC_MMIO 390 390 select CPU_FA526 391 391 select GENERIC_CLOCKEVENTS 392 - select NEED_MACH_GPIO_H 393 392 help 394 393 Support for the Cortina Systems Gemini family SoCs 395 394 ··· 457 458 depends on MMU 458 459 select ARCH_REQUIRE_GPIOLIB 459 460 select CPU_XSCALE 460 - select NEED_MACH_GPIO_H 461 + select GPIO_IOP 461 462 select NEED_RET_TO_USER 462 463 select PCI 463 464 select PLAT_IOP ··· 470 471 depends on MMU 471 472 select ARCH_REQUIRE_GPIOLIB 472 473 select CPU_XSCALE 473 - select NEED_MACH_GPIO_H 474 + select GPIO_IOP 474 475 select NEED_RET_TO_USER 475 476 select PCI 476 477 select PLAT_IOP ··· 559 560 select GPIO_PXA 560 561 select IRQ_DOMAIN 561 562 select MULTI_IRQ_HANDLER 562 - select NEED_MACH_GPIO_H 563 563 select PINCTRL 564 564 select PLAT_PXA 565 565 select SPARSE_IRQ ··· 621 623 select GPIO_PXA 622 624 select HAVE_IDE 623 625 select MULTI_IRQ_HANDLER 624 - select NEED_MACH_GPIO_H 625 626 select PLAT_PXA 626 627 select SPARSE_IRQ 627 628 help
-75
arch/arm/include/asm/hardware/iop3xx-gpio.h
··· 1 - /* 2 - * arch/arm/include/asm/hardware/iop3xx-gpio.h 3 - * 4 - * IOP3xx GPIO wrappers 5 - * 6 - * Copyright (c) 2008 Arnaud Patard <arnaud.patard@rtp-net.org> 7 - * Based on IXP4XX gpio.h file 8 - * 9 - * This program is free software; you can redistribute it and/or modify 10 - * it under the terms of the GNU General Public License as published by 11 - * the Free Software Foundation; either version 2 of the License, or 12 - * (at your option) any later version. 13 - * 14 - * This program is distributed in the hope that it will be useful, 15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 - * GNU General Public License for more details. 18 - * 19 - * You should have received a copy of the GNU General Public License 20 - * along with this program; if not, write to the Free Software 21 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 - * 23 - */ 24 - 25 - #ifndef __ASM_ARM_HARDWARE_IOP3XX_GPIO_H 26 - #define __ASM_ARM_HARDWARE_IOP3XX_GPIO_H 27 - 28 - #include <mach/hardware.h> 29 - #include <asm-generic/gpio.h> 30 - 31 - #define __ARM_GPIOLIB_COMPLEX 32 - 33 - #define IOP3XX_N_GPIOS 8 34 - 35 - static inline int gpio_get_value(unsigned gpio) 36 - { 37 - if (gpio > IOP3XX_N_GPIOS) 38 - return __gpio_get_value(gpio); 39 - 40 - return gpio_line_get(gpio); 41 - } 42 - 43 - static inline void gpio_set_value(unsigned gpio, int value) 44 - { 45 - if (gpio > IOP3XX_N_GPIOS) { 46 - __gpio_set_value(gpio, value); 47 - return; 48 - } 49 - gpio_line_set(gpio, value); 50 - } 51 - 52 - static inline int gpio_cansleep(unsigned gpio) 53 - { 54 - if (gpio < IOP3XX_N_GPIOS) 55 - return 0; 56 - else 57 - return __gpio_cansleep(gpio); 58 - } 59 - 60 - /* 61 - * The GPIOs are not generating any interrupt 62 - * Note : manuals are not clear about this 63 - */ 64 - static inline int gpio_to_irq(int gpio) 65 - { 66 - return -EINVAL; 67 - } 68 - 69 - static inline int irq_to_gpio(int gpio) 70 - { 71 - return -EINVAL; 72 - } 73 - 74 - #endif 75 -
-12
arch/arm/include/asm/hardware/iop3xx.h
··· 18 18 /* 19 19 * IOP3XX GPIO handling 20 20 */ 21 - #define GPIO_IN 0 22 - #define GPIO_OUT 1 23 - #define GPIO_LOW 0 24 - #define GPIO_HIGH 1 25 21 #define IOP3XX_GPIO_LINE(x) (x) 26 22 27 23 #ifndef __ASSEMBLY__ 28 - extern void gpio_line_config(int line, int direction); 29 - extern int gpio_line_get(int line); 30 - extern void gpio_line_set(int line, int value); 31 24 extern int init_atu; 32 25 extern int iop3xx_get_init_atu(void); 33 26 #endif ··· 160 167 #define IOP3XX_GTSR (volatile u32 *)IOP3XX_REG_ADDR(0x0710) 161 168 /* PERCR0 DOESN'T EXIST - index from 1! */ 162 169 #define IOP3XX_PERCR0 (volatile u32 *)IOP3XX_REG_ADDR(0x0710) 163 - 164 - /* General Purpose I/O */ 165 - #define IOP3XX_GPOE (volatile u32 *)IOP3XX_GPIO_REG(0x0000) 166 - #define IOP3XX_GPID (volatile u32 *)IOP3XX_GPIO_REG(0x0004) 167 - #define IOP3XX_GPOD (volatile u32 *)IOP3XX_GPIO_REG(0x0008) 168 170 169 171 /* Timers */ 170 172 #define IOP3XX_TU_TMR0 (volatile u32 *)IOP3XX_TIMER_REG(0x0000)
+1 -1
arch/arm/mach-gemini/gpio.c
··· 21 21 22 22 #include <mach/hardware.h> 23 23 #include <mach/irqs.h> 24 - #include <mach/gpio.h> 25 24 26 25 #define GPIO_BASE(x) IO_ADDRESS(GEMINI_GPIO_BASE(x)) 26 + #define irq_to_gpio(x) ((x) - GPIO_IRQ_BASE) 27 27 28 28 /* GPIO registers definition */ 29 29 #define GPIO_DATA_OUT 0x0
-20
arch/arm/mach-gemini/include/mach/gpio.h
··· 1 - /* 2 - * Gemini gpiolib specific defines 3 - * 4 - * Copyright (C) 2008-2009 Paulius Zaleckas <paulius.zaleckas@teltonika.lt> 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, or 9 - * (at your option) any later version. 10 - */ 11 - 12 - #ifndef __MACH_GPIO_H__ 13 - #define __MACH_GPIO_H__ 14 - 15 - #include <mach/irqs.h> 16 - 17 - #define gpio_to_irq(x) ((x) + GPIO_IRQ_BASE) 18 - #define irq_to_gpio(x) ((x) - GPIO_IRQ_BASE) 19 - 20 - #endif /* __MACH_GPIO_H__ */
+2
arch/arm/mach-iop32x/em7210.c
··· 32 32 #include <asm/mach/time.h> 33 33 #include <asm/mach-types.h> 34 34 #include <mach/time.h> 35 + #include "gpio-iop32x.h" 35 36 36 37 static void __init em7210_timer_init(void) 37 38 { ··· 184 183 185 184 static void __init em7210_init_machine(void) 186 185 { 186 + register_iop32x_gpio(); 187 187 platform_device_register(&em7210_serial_device); 188 188 platform_device_register(&iop3xx_i2c0_device); 189 189 platform_device_register(&iop3xx_i2c1_device);
+2
arch/arm/mach-iop32x/glantank.c
··· 34 34 #include <asm/mach-types.h> 35 35 #include <asm/page.h> 36 36 #include <mach/time.h> 37 + #include "gpio-iop32x.h" 37 38 38 39 /* 39 40 * GLAN Tank timer tick configuration. ··· 188 187 189 188 static void __init glantank_init_machine(void) 190 189 { 190 + register_iop32x_gpio(); 191 191 platform_device_register(&iop3xx_i2c0_device); 192 192 platform_device_register(&iop3xx_i2c1_device); 193 193 platform_device_register(&glantank_flash_device);
+10
arch/arm/mach-iop32x/gpio-iop32x.h
··· 1 + static struct resource iop32x_gpio_res[] = { 2 + DEFINE_RES_MEM((IOP3XX_PERIPHERAL_PHYS_BASE + 0x07c4), 0x10), 3 + }; 4 + 5 + static inline void register_iop32x_gpio(void) 6 + { 7 + platform_device_register_simple("gpio-iop", 0, 8 + iop32x_gpio_res, 9 + ARRAY_SIZE(iop32x_gpio_res)); 10 + }
-6
arch/arm/mach-iop32x/include/mach/gpio.h
··· 1 - #ifndef __ASM_ARCH_IOP32X_GPIO_H 2 - #define __ASM_ARCH_IOP32X_GPIO_H 3 - 4 - #include <asm/hardware/iop3xx-gpio.h> 5 - 6 - #endif
-1
arch/arm/mach-iop32x/include/mach/iop32x.h
··· 19 19 * Peripherals that are shared between the iop32x and iop33x but 20 20 * located at different addresses. 21 21 */ 22 - #define IOP3XX_GPIO_REG(reg) (IOP3XX_PERIPHERAL_VIRT_BASE + 0x07c4 + (reg)) 23 22 #define IOP3XX_TIMER_REG(reg) (IOP3XX_PERIPHERAL_VIRT_BASE + 0x07e0 + (reg)) 24 23 25 24 #include <asm/hardware/iop3xx.h>
+2
arch/arm/mach-iop32x/iq31244.c
··· 37 37 #include <asm/page.h> 38 38 #include <asm/pgtable.h> 39 39 #include <mach/time.h> 40 + #include "gpio-iop32x.h" 40 41 41 42 /* 42 43 * Until March of 2007 iq31244 platforms and ep80219 platforms shared the ··· 284 283 285 284 static void __init iq31244_init_machine(void) 286 285 { 286 + register_iop32x_gpio(); 287 287 platform_device_register(&iop3xx_i2c0_device); 288 288 platform_device_register(&iop3xx_i2c1_device); 289 289 platform_device_register(&iq31244_flash_device);
+2
arch/arm/mach-iop32x/iq80321.c
··· 33 33 #include <asm/page.h> 34 34 #include <asm/pgtable.h> 35 35 #include <mach/time.h> 36 + #include "gpio-iop32x.h" 36 37 37 38 /* 38 39 * IQ80321 timer tick configuration. ··· 171 170 172 171 static void __init iq80321_init_machine(void) 173 172 { 173 + register_iop32x_gpio(); 174 174 platform_device_register(&iop3xx_i2c0_device); 175 175 platform_device_register(&iop3xx_i2c1_device); 176 176 platform_device_register(&iq80321_flash_device);
+39 -8
arch/arm/mach-iop32x/n2100.c
··· 30 30 #include <linux/platform_device.h> 31 31 #include <linux/reboot.h> 32 32 #include <linux/io.h> 33 + #include <linux/gpio.h> 33 34 #include <mach/hardware.h> 34 35 #include <asm/irq.h> 35 36 #include <asm/mach/arch.h> ··· 41 40 #include <asm/page.h> 42 41 #include <asm/pgtable.h> 43 42 #include <mach/time.h> 43 + #include "gpio-iop32x.h" 44 44 45 45 /* 46 46 * N2100 timer tick configuration. ··· 290 288 291 289 static void n2100_restart(enum reboot_mode mode, const char *cmd) 292 290 { 293 - gpio_line_set(N2100_HARDWARE_RESET, GPIO_LOW); 294 - gpio_line_config(N2100_HARDWARE_RESET, GPIO_OUT); 291 + int ret; 292 + 293 + ret = gpio_direction_output(N2100_HARDWARE_RESET, 0); 294 + if (ret) { 295 + pr_crit("could not drive reset GPIO low\n"); 296 + return; 297 + } 298 + /* Wait for reset to happen */ 295 299 while (1) 296 300 ; 297 301 } ··· 307 299 308 300 static void power_button_poll(unsigned long dummy) 309 301 { 310 - if (gpio_line_get(N2100_POWER_BUTTON) == 0) { 302 + if (gpio_get_value(N2100_POWER_BUTTON) == 0) { 311 303 ctrl_alt_del(); 312 304 return; 313 305 } ··· 316 308 add_timer(&power_button_poll_timer); 317 309 } 318 310 311 + static int __init n2100_request_gpios(void) 312 + { 313 + int ret; 314 + 315 + if (!machine_is_n2100()) 316 + return 0; 317 + 318 + ret = gpio_request(N2100_HARDWARE_RESET, "reset"); 319 + if (ret) 320 + pr_err("could not request reset GPIO\n"); 321 + 322 + ret = gpio_request(N2100_POWER_BUTTON, "power"); 323 + if (ret) 324 + pr_err("could not request power GPIO\n"); 325 + else { 326 + ret = gpio_direction_input(N2100_POWER_BUTTON); 327 + if (ret) 328 + pr_err("could not set power GPIO as input\n"); 329 + } 330 + /* Set up power button poll timer */ 331 + init_timer(&power_button_poll_timer); 332 + power_button_poll_timer.function = power_button_poll; 333 + power_button_poll_timer.expires = jiffies + (HZ / 10); 334 + add_timer(&power_button_poll_timer); 335 + return 0; 336 + } 337 + device_initcall(n2100_request_gpios); 319 338 320 339 static void __init n2100_init_machine(void) 321 340 { 341 + register_iop32x_gpio(); 322 342 platform_device_register(&iop3xx_i2c0_device); 323 343 platform_device_register(&n2100_flash_device); 324 344 platform_device_register(&n2100_serial_device); ··· 357 321 ARRAY_SIZE(n2100_i2c_devices)); 358 322 359 323 pm_power_off = n2100_power_off; 360 - 361 - init_timer(&power_button_poll_timer); 362 - power_button_poll_timer.function = power_button_poll; 363 - power_button_poll_timer.expires = jiffies + (HZ / 10); 364 - add_timer(&power_button_poll_timer); 365 324 } 366 325 367 326 MACHINE_START(N2100, "Thecus N2100")
-6
arch/arm/mach-iop33x/include/mach/gpio.h
··· 1 - #ifndef __ASM_ARCH_IOP33X_GPIO_H 2 - #define __ASM_ARCH_IOP33X_GPIO_H 3 - 4 - #include <asm/hardware/iop3xx-gpio.h> 5 - 6 - #endif
-1
arch/arm/mach-iop33x/include/mach/iop33x.h
··· 18 18 * Peripherals that are shared between the iop32x and iop33x but 19 19 * located at different addresses. 20 20 */ 21 - #define IOP3XX_GPIO_REG(reg) (IOP3XX_PERIPHERAL_VIRT_BASE + 0x1780 + (reg)) 22 21 #define IOP3XX_TIMER_REG(reg) (IOP3XX_PERIPHERAL_VIRT_BASE + 0x07d0 + (reg)) 23 22 24 23 #include <asm/hardware/iop3xx.h>
+7
arch/arm/mach-iop33x/iq80331.c
··· 122 122 .resource = &iq80331_flash_resource, 123 123 }; 124 124 125 + static struct resource iq80331_gpio_res[] = { 126 + DEFINE_RES_MEM((IOP3XX_PERIPHERAL_PHYS_BASE + 0x1780), 0x10), 127 + }; 128 + 125 129 static void __init iq80331_init_machine(void) 126 130 { 131 + platform_device_register_simple("gpio-iop", 0, 132 + iq80331_gpio_res, 133 + ARRAY_SIZE(iq80331_gpio_res)); 127 134 platform_device_register(&iop3xx_i2c0_device); 128 135 platform_device_register(&iop3xx_i2c1_device); 129 136 platform_device_register(&iop33x_uart0_device);
+7
arch/arm/mach-iop33x/iq80332.c
··· 122 122 .resource = &iq80332_flash_resource, 123 123 }; 124 124 125 + static struct resource iq80332_gpio_res[] = { 126 + DEFINE_RES_MEM((IOP3XX_PERIPHERAL_PHYS_BASE + 0x1780), 0x10), 127 + }; 128 + 125 129 static void __init iq80332_init_machine(void) 126 130 { 131 + platform_device_register_simple("gpio-iop", 0, 132 + iq80332_gpio_res, 133 + ARRAY_SIZE(iq80332_gpio_res)); 127 134 platform_device_register(&iop3xx_i2c0_device); 128 135 platform_device_register(&iop3xx_i2c1_device); 129 136 platform_device_register(&iop33x_uart0_device);
+38 -11
arch/arm/mach-ixp4xx/common.c
··· 81 81 iotable_init(ixp4xx_io_desc, ARRAY_SIZE(ixp4xx_io_desc)); 82 82 } 83 83 84 + /* 85 + * GPIO-functions 86 + */ 87 + /* 88 + * The following converted to the real HW bits the gpio_line_config 89 + */ 90 + /* GPIO pin types */ 91 + #define IXP4XX_GPIO_OUT 0x1 92 + #define IXP4XX_GPIO_IN 0x2 93 + 94 + /* GPIO signal types */ 95 + #define IXP4XX_GPIO_LOW 0 96 + #define IXP4XX_GPIO_HIGH 1 97 + 98 + /* GPIO Clocks */ 99 + #define IXP4XX_GPIO_CLK_0 14 100 + #define IXP4XX_GPIO_CLK_1 15 101 + 102 + static void gpio_line_config(u8 line, u32 direction) 103 + { 104 + if (direction == IXP4XX_GPIO_IN) 105 + *IXP4XX_GPIO_GPOER |= (1 << line); 106 + else 107 + *IXP4XX_GPIO_GPOER &= ~(1 << line); 108 + } 109 + 110 + static void gpio_line_get(u8 line, int *value) 111 + { 112 + *value = (*IXP4XX_GPIO_GPINR >> line) & 0x1; 113 + } 114 + 115 + static void gpio_line_set(u8 line, int value) 116 + { 117 + if (value == IXP4XX_GPIO_HIGH) 118 + *IXP4XX_GPIO_GPOUTR |= (1 << line); 119 + else if (value == IXP4XX_GPIO_LOW) 120 + *IXP4XX_GPIO_GPOUTR &= ~(1 << line); 121 + } 84 122 85 123 /************************************************************************* 86 124 * IXP4xx chipset IRQ handling ··· 154 116 } 155 117 return -EINVAL; 156 118 } 157 - 158 - int irq_to_gpio(unsigned int irq) 159 - { 160 - int gpio = (irq < 32) ? irq2gpio[irq] : -EINVAL; 161 - 162 - if (gpio == -1) 163 - return -EINVAL; 164 - 165 - return gpio; 166 - } 167 - EXPORT_SYMBOL(irq_to_gpio); 168 119 169 120 static int ixp4xx_set_irq_type(struct irq_data *d, unsigned int type) 170 121 {
+38 -27
arch/arm/mach-ixp4xx/dsmg600-setup.c
··· 26 26 #include <linux/reboot.h> 27 27 #include <linux/i2c.h> 28 28 #include <linux/i2c-gpio.h> 29 + #include <linux/gpio.h> 29 30 30 31 #include <mach/hardware.h> 31 32 ··· 162 161 163 162 static void dsmg600_power_off(void) 164 163 { 165 - /* enable the pwr cntl gpio */ 166 - gpio_line_config(DSMG600_PO_GPIO, IXP4XX_GPIO_OUT); 167 - 168 - /* poweroff */ 169 - gpio_line_set(DSMG600_PO_GPIO, IXP4XX_GPIO_HIGH); 164 + /* enable the pwr cntl and drive it high */ 165 + gpio_direction_output(DSMG600_PO_GPIO, 1); 170 166 } 171 167 172 168 /* This is used to make sure the power-button pusher is serious. The button ··· 200 202 ctrl_alt_del(); 201 203 202 204 /* Change the state of the power LED to "blink" */ 203 - gpio_line_set(DSMG600_LED_PWR_GPIO, IXP4XX_GPIO_LOW); 205 + gpio_set_value(DSMG600_LED_PWR_GPIO, 0); 204 206 } else { 205 207 power_button_countdown = PBUTTON_HOLDDOWN_COUNT; 206 208 } ··· 226 228 ixp4xx_timer_init(); 227 229 } 228 230 231 + static int __init dsmg600_gpio_init(void) 232 + { 233 + if (!machine_is_dsmg600()) 234 + return 0; 235 + 236 + gpio_request(DSMG600_RB_GPIO, "reset button"); 237 + if (request_irq(gpio_to_irq(DSMG600_RB_GPIO), &dsmg600_reset_handler, 238 + IRQF_DISABLED | IRQF_TRIGGER_LOW, 239 + "DSM-G600 reset button", NULL) < 0) { 240 + 241 + printk(KERN_DEBUG "Reset Button IRQ %d not available\n", 242 + gpio_to_irq(DSMG600_RB_GPIO)); 243 + } 244 + 245 + /* 246 + * The power button on the D-Link DSM-G600 is on GPIO 15, but 247 + * it cannot handle interrupts on that GPIO line. So we'll 248 + * have to poll it with a kernel timer. 249 + */ 250 + 251 + /* Make sure that the power button GPIO is set up as an input */ 252 + gpio_request(DSMG600_PB_GPIO, "power button"); 253 + gpio_direction_input(DSMG600_PB_GPIO); 254 + /* Request poweroff GPIO line */ 255 + gpio_request(DSMG600_PO_GPIO, "power off button"); 256 + 257 + /* Set the initial value for the power button IRQ handler */ 258 + power_button_countdown = PBUTTON_HOLDDOWN_COUNT; 259 + 260 + mod_timer(&dsmg600_power_timer, jiffies + msecs_to_jiffies(500)); 261 + return 0; 262 + } 263 + device_initcall(dsmg600_gpio_init); 264 + 229 265 static void __init dsmg600_init(void) 230 266 { 231 267 ixp4xx_sys_init(); ··· 283 251 platform_add_devices(dsmg600_devices, ARRAY_SIZE(dsmg600_devices)); 284 252 285 253 pm_power_off = dsmg600_power_off; 286 - 287 - if (request_irq(gpio_to_irq(DSMG600_RB_GPIO), &dsmg600_reset_handler, 288 - IRQF_DISABLED | IRQF_TRIGGER_LOW, 289 - "DSM-G600 reset button", NULL) < 0) { 290 - 291 - printk(KERN_DEBUG "Reset Button IRQ %d not available\n", 292 - gpio_to_irq(DSMG600_RB_GPIO)); 293 - } 294 - 295 - /* The power button on the D-Link DSM-G600 is on GPIO 15, but 296 - * it cannot handle interrupts on that GPIO line. So we'll 297 - * have to poll it with a kernel timer. 298 - */ 299 - 300 - /* Make sure that the power button GPIO is set up as an input */ 301 - gpio_line_config(DSMG600_PB_GPIO, IXP4XX_GPIO_IN); 302 - 303 - /* Set the initial value for the power button IRQ handler */ 304 - power_button_countdown = PBUTTON_HOLDDOWN_COUNT; 305 - 306 - mod_timer(&dsmg600_power_timer, jiffies + msecs_to_jiffies(500)); 307 254 } 308 255 309 256 MACHINE_START(DSMG600, "D-Link DSM-G600 RevA")
-39
arch/arm/mach-ixp4xx/include/mach/platform.h
··· 131 131 extern int ixp4xx_setup(int nr, struct pci_sys_data *sys); 132 132 extern struct pci_ops ixp4xx_ops; 133 133 134 - /* 135 - * GPIO-functions 136 - */ 137 - /* 138 - * The following converted to the real HW bits the gpio_line_config 139 - */ 140 - /* GPIO pin types */ 141 - #define IXP4XX_GPIO_OUT 0x1 142 - #define IXP4XX_GPIO_IN 0x2 143 - 144 - /* GPIO signal types */ 145 - #define IXP4XX_GPIO_LOW 0 146 - #define IXP4XX_GPIO_HIGH 1 147 - 148 - /* GPIO Clocks */ 149 - #define IXP4XX_GPIO_CLK_0 14 150 - #define IXP4XX_GPIO_CLK_1 15 151 - 152 - static inline void gpio_line_config(u8 line, u32 direction) 153 - { 154 - if (direction == IXP4XX_GPIO_IN) 155 - *IXP4XX_GPIO_GPOER |= (1 << line); 156 - else 157 - *IXP4XX_GPIO_GPOER &= ~(1 << line); 158 - } 159 - 160 - static inline void gpio_line_get(u8 line, int *value) 161 - { 162 - *value = (*IXP4XX_GPIO_GPINR >> line) & 0x1; 163 - } 164 - 165 - static inline void gpio_line_set(u8 line, int value) 166 - { 167 - if (value == IXP4XX_GPIO_HIGH) 168 - *IXP4XX_GPIO_GPOUTR |= (1 << line); 169 - else if (value == IXP4XX_GPIO_LOW) 170 - *IXP4XX_GPIO_GPOUTR &= ~(1 << line); 171 - } 172 - 173 134 #endif // __ASSEMBLY__ 174 135
+5 -3
arch/arm/mach-ixp4xx/ixdp425-setup.c
··· 20 20 #include <linux/mtd/nand.h> 21 21 #include <linux/mtd/partitions.h> 22 22 #include <linux/delay.h> 23 + #include <linux/gpio.h> 23 24 #include <asm/types.h> 24 25 #include <asm/setup.h> 25 26 #include <asm/memory.h> ··· 81 80 82 81 if (ctrl & NAND_CTRL_CHANGE) { 83 82 if (ctrl & NAND_NCE) { 84 - gpio_line_set(IXDP425_NAND_NCE_PIN, IXP4XX_GPIO_LOW); 83 + gpio_set_value(IXDP425_NAND_NCE_PIN, 0); 85 84 udelay(5); 86 85 } else 87 - gpio_line_set(IXDP425_NAND_NCE_PIN, IXP4XX_GPIO_HIGH); 86 + gpio_set_value(IXDP425_NAND_NCE_PIN, 1); 88 87 89 88 offset = (ctrl & NAND_CLE) ? IXDP425_NAND_CMD_BYTE : 0; 90 89 offset |= (ctrl & NAND_ALE) ? IXDP425_NAND_ADDR_BYTE : 0; ··· 228 227 ixdp425_flash_nand_resource.start = IXP4XX_EXP_BUS_BASE(3), 229 228 ixdp425_flash_nand_resource.end = IXP4XX_EXP_BUS_BASE(3) + 0x10 - 1; 230 229 231 - gpio_line_config(IXDP425_NAND_NCE_PIN, IXP4XX_GPIO_OUT); 230 + gpio_request(IXDP425_NAND_NCE_PIN, "NAND NCE pin"); 231 + gpio_direction_output(IXDP425_NAND_NCE_PIN, 0); 232 232 233 233 /* Configure expansion bus for NAND Flash */ 234 234 *IXP4XX_EXP_CS3 = IXP4XX_EXP_BUS_CS_EN |
+30 -19
arch/arm/mach-ixp4xx/nas100d-setup.c
··· 184 184 { 185 185 /* This causes the box to drop the power and go dead. */ 186 186 187 - /* enable the pwr cntl gpio */ 188 - gpio_line_config(NAS100D_PO_GPIO, IXP4XX_GPIO_OUT); 189 - 190 - /* do the deed */ 191 - gpio_line_set(NAS100D_PO_GPIO, IXP4XX_GPIO_HIGH); 187 + /* enable the pwr cntl gpio and assert power off */ 188 + gpio_direction_output(NAS100D_PO_GPIO, 1); 192 189 } 193 190 194 191 /* This is used to make sure the power-button pusher is serious. The button ··· 222 225 ctrl_alt_del(); 223 226 224 227 /* Change the state of the power LED to "blink" */ 225 - gpio_line_set(NAS100D_LED_PWR_GPIO, IXP4XX_GPIO_LOW); 228 + gpio_set_value(NAS100D_LED_PWR_GPIO, 0); 226 229 } else { 227 230 power_button_countdown = PBUTTON_HOLDDOWN_COUNT; 228 231 } ··· 238 241 239 242 return IRQ_HANDLED; 240 243 } 244 + 245 + static int __init nas100d_gpio_init(void) 246 + { 247 + if (!machine_is_nas100d()) 248 + return 0; 249 + 250 + /* 251 + * The power button on the Iomega NAS100d is on GPIO 14, but 252 + * it cannot handle interrupts on that GPIO line. So we'll 253 + * have to poll it with a kernel timer. 254 + */ 255 + 256 + /* Request the power off GPIO */ 257 + gpio_request(NAS100D_PO_GPIO, "power off"); 258 + 259 + /* Make sure that the power button GPIO is set up as an input */ 260 + gpio_request(NAS100D_PB_GPIO, "power button"); 261 + gpio_direction_input(NAS100D_PB_GPIO); 262 + 263 + /* Set the initial value for the power button IRQ handler */ 264 + power_button_countdown = PBUTTON_HOLDDOWN_COUNT; 265 + 266 + mod_timer(&nas100d_power_timer, jiffies + msecs_to_jiffies(500)); 267 + 268 + return 0; 269 + } 270 + device_initcall(nas100d_gpio_init); 241 271 242 272 static void __init nas100d_init(void) 243 273 { ··· 301 277 printk(KERN_DEBUG "Reset Button IRQ %d not available\n", 302 278 gpio_to_irq(NAS100D_RB_GPIO)); 303 279 } 304 - 305 - /* The power button on the Iomega NAS100d is on GPIO 14, but 306 - * it cannot handle interrupts on that GPIO line. So we'll 307 - * have to poll it with a kernel timer. 308 - */ 309 - 310 - /* Make sure that the power button GPIO is set up as an input */ 311 - gpio_line_config(NAS100D_PB_GPIO, IXP4XX_GPIO_IN); 312 - 313 - /* Set the initial value for the power button IRQ handler */ 314 - power_button_countdown = PBUTTON_HOLDDOWN_COUNT; 315 - 316 - mod_timer(&nas100d_power_timer, jiffies + msecs_to_jiffies(500)); 317 280 318 281 /* 319 282 * Map in a portion of the flash and read the MAC address.
+12 -5
arch/arm/mach-ixp4xx/nslu2-setup.c
··· 197 197 { 198 198 /* This causes the box to drop the power and go dead. */ 199 199 200 - /* enable the pwr cntl gpio */ 201 - gpio_line_config(NSLU2_PO_GPIO, IXP4XX_GPIO_OUT); 202 - 203 - /* do the deed */ 204 - gpio_line_set(NSLU2_PO_GPIO, IXP4XX_GPIO_HIGH); 200 + /* enable the pwr cntl gpio and assert power off */ 201 + gpio_direction_output(NSLU2_PO_GPIO, 1); 205 202 } 206 203 207 204 static irqreturn_t nslu2_power_handler(int irq, void *dev_id) ··· 219 222 220 223 return IRQ_HANDLED; 221 224 } 225 + 226 + static int __init nslu2_gpio_init(void) 227 + { 228 + if (!machine_is_nslu2()) 229 + return 0; 230 + 231 + /* Request the power off GPIO */ 232 + return gpio_request(NSLU2_PO_GPIO, "power off"); 233 + } 234 + device_initcall(nslu2_gpio_init); 222 235 223 236 static void __init nslu2_timer_init(void) 224 237 {
-8
arch/arm/mach-mmp/include/mach/gpio.h
··· 1 - #ifndef __ASM_MACH_GPIO_H 2 - #define __ASM_MACH_GPIO_H 3 - 4 - #include <asm-generic/gpio.h> 5 - 6 - #include <mach/cputype.h> 7 - 8 - #endif /* __ASM_MACH_GPIO_H */
-32
arch/arm/mach-pxa/include/mach/gpio.h
··· 1 - /* 2 - * arch/arm/mach-pxa/include/mach/gpio.h 3 - * 4 - * PXA GPIO wrappers for arch-neutral GPIO calls 5 - * 6 - * Written by Philipp Zabel <philipp.zabel@gmail.com> 7 - * 8 - * This program is free software; you can redistribute it and/or modify 9 - * it under the terms of the GNU General Public License as published by 10 - * the Free Software Foundation; either version 2 of the License, or 11 - * (at your option) any later version. 12 - * 13 - * This program is distributed in the hope that it will be useful, 14 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 - * GNU General Public License for more details. 17 - * 18 - * You should have received a copy of the GNU General Public License 19 - * along with this program; if not, write to the Free Software 20 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 - * 22 - */ 23 - 24 - #ifndef __ASM_ARCH_PXA_GPIO_H 25 - #define __ASM_ARCH_PXA_GPIO_H 26 - 27 - #include <asm-generic/gpio.h> 28 - 29 - #include <mach/irqs.h> 30 - #include <mach/hardware.h> 31 - 32 - #endif
-30
arch/arm/mach-w90x900/include/mach/gpio.h
··· 1 - /* 2 - * linux/arch/arm/mach-w90p910/include/mach/gpio.h 3 - * 4 - * Generic w90p910 GPIO handling 5 - * 6 - * Wan ZongShun <mcuos.com@gmail.com> 7 - * 8 - * This program is free software; you can redistribute it and/or modify 9 - * it under the terms of the GNU General Public License version 2 as 10 - * published by the Free Software Foundation. 11 - */ 12 - 13 - #ifndef __ASM_ARCH_W90P910_GPIO_H 14 - #define __ASM_ARCH_W90P910_GPIO_H 15 - 16 - #include <mach/hardware.h> 17 - #include <asm/irq.h> 18 - 19 - static inline int gpio_to_irq(unsigned gpio) 20 - { 21 - return gpio; 22 - } 23 - #define gpio_to_irq gpio_to_irq 24 - 25 - static inline int irq_to_gpio(unsigned irq) 26 - { 27 - return irq; 28 - } 29 - 30 - #endif
-2
arch/arm/plat-iop/Makefile
··· 5 5 obj-y := 6 6 7 7 # IOP32X 8 - obj-$(CONFIG_ARCH_IOP32X) += gpio.o 9 8 obj-$(CONFIG_ARCH_IOP32X) += i2c.o 10 9 obj-$(CONFIG_ARCH_IOP32X) += pci.o 11 10 obj-$(CONFIG_ARCH_IOP32X) += setup.o ··· 15 16 obj-$(CONFIG_ARCH_IOP32X) += restart.o 16 17 17 18 # IOP33X 18 - obj-$(CONFIG_ARCH_IOP33X) += gpio.o 19 19 obj-$(CONFIG_ARCH_IOP33X) += i2c.o 20 20 obj-$(CONFIG_ARCH_IOP33X) += pci.o 21 21 obj-$(CONFIG_ARCH_IOP33X) += setup.o
+52 -15
arch/arm/plat-iop/gpio.c drivers/gpio/gpio-iop.c
··· 16 16 #include <linux/errno.h> 17 17 #include <linux/gpio.h> 18 18 #include <linux/export.h> 19 - #include <asm/hardware/iop3xx.h> 20 - #include <mach/gpio.h> 19 + #include <linux/platform_device.h> 20 + #include <linux/bitops.h> 21 + #include <linux/io.h> 21 22 22 - void gpio_line_config(int line, int direction) 23 + #define IOP3XX_N_GPIOS 8 24 + 25 + #define GPIO_IN 0 26 + #define GPIO_OUT 1 27 + #define GPIO_LOW 0 28 + #define GPIO_HIGH 1 29 + 30 + /* Memory base offset */ 31 + static void __iomem *base; 32 + 33 + #define IOP3XX_GPIO_REG(reg) (base + (reg)) 34 + #define IOP3XX_GPOE IOP3XX_GPIO_REG(0x0000) 35 + #define IOP3XX_GPID IOP3XX_GPIO_REG(0x0004) 36 + #define IOP3XX_GPOD IOP3XX_GPIO_REG(0x0008) 37 + 38 + static void gpio_line_config(int line, int direction) 23 39 { 24 40 unsigned long flags; 41 + u32 val; 25 42 26 43 local_irq_save(flags); 44 + val = readl(IOP3XX_GPOE); 27 45 if (direction == GPIO_IN) { 28 - *IOP3XX_GPOE |= 1 << line; 46 + val |= BIT(line); 29 47 } else if (direction == GPIO_OUT) { 30 - *IOP3XX_GPOE &= ~(1 << line); 48 + val &= ~BIT(line); 31 49 } 50 + writel(val, IOP3XX_GPOE); 32 51 local_irq_restore(flags); 33 52 } 34 - EXPORT_SYMBOL(gpio_line_config); 35 53 36 - int gpio_line_get(int line) 54 + static int gpio_line_get(int line) 37 55 { 38 - return !!(*IOP3XX_GPID & (1 << line)); 56 + return !!(readl(IOP3XX_GPID) & BIT(line)); 39 57 } 40 - EXPORT_SYMBOL(gpio_line_get); 41 58 42 - void gpio_line_set(int line, int value) 59 + static void gpio_line_set(int line, int value) 43 60 { 44 61 unsigned long flags; 62 + u32 val; 45 63 46 64 local_irq_save(flags); 65 + val = readl(IOP3XX_GPOD); 47 66 if (value == GPIO_LOW) { 48 - *IOP3XX_GPOD &= ~(1 << line); 67 + val &= ~BIT(line); 49 68 } else if (value == GPIO_HIGH) { 50 - *IOP3XX_GPOD |= 1 << line; 69 + val |= BIT(line); 51 70 } 71 + writel(val, IOP3XX_GPOD); 52 72 local_irq_restore(flags); 53 73 } 54 - EXPORT_SYMBOL(gpio_line_set); 55 74 56 75 static int iop3xx_gpio_direction_input(struct gpio_chip *chip, unsigned gpio) 57 76 { ··· 105 86 .ngpio = IOP3XX_N_GPIOS, 106 87 }; 107 88 108 - static int __init iop3xx_gpio_setup(void) 89 + static int iop3xx_gpio_probe(struct platform_device *pdev) 109 90 { 91 + struct resource *res; 92 + 93 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 94 + base = devm_ioremap_resource(&pdev->dev, res); 95 + 110 96 return gpiochip_add(&iop3xx_chip); 111 97 } 112 - arch_initcall(iop3xx_gpio_setup); 98 + 99 + static struct platform_driver iop3xx_gpio_driver = { 100 + .driver = { 101 + .name = "gpio-iop", 102 + .owner = THIS_MODULE, 103 + }, 104 + .probe = iop3xx_gpio_probe, 105 + }; 106 + 107 + static int __init iop3xx_gpio_init(void) 108 + { 109 + return platform_driver_register(&iop3xx_gpio_driver); 110 + } 111 + arch_initcall(iop3xx_gpio_init);
+25 -10
drivers/gpio/Kconfig
··· 30 30 Selecting this from the architecture code will cause the gpiolib 31 31 code to always get built in. 32 32 33 - config GPIO_DEVRES 34 - def_bool y 35 - depends on HAS_IOMEM 36 - 37 33 38 34 menuconfig GPIOLIB 39 35 bool "GPIO Support" ··· 42 46 If unsure, say N. 43 47 44 48 if GPIOLIB 49 + 50 + config GPIO_DEVRES 51 + def_bool y 52 + depends on HAS_IOMEM 45 53 46 54 config OF_GPIO 47 55 def_bool y ··· 129 129 130 130 config GPIO_EM 131 131 tristate "Emma Mobile GPIO" 132 - depends on ARM 132 + depends on ARM && OF_GPIO 133 133 help 134 134 Say yes here to support GPIO on Renesas Emma Mobile SoCs. 135 135 ··· 213 213 214 214 config GPIO_PL061 215 215 bool "PrimeCell PL061 GPIO support" 216 - depends on ARM && ARM_AMBA 216 + depends on ARM_AMBA 217 217 select GENERIC_IRQ_CHIP 218 218 help 219 219 Say yes here to support the PrimeCell PL061 GPIO device ··· 317 317 ICH-based chipsets. Currently supported devices: ICH6, ICH7, ICH8 318 318 ICH9, ICH10, Series 5/3400 (eg Ibex Peak), Series 6/C200 (eg 319 319 Cougar Point), NM10 (Tiger Point), and 3100 (Whitmore Lake). 320 + 321 + If unsure, say N. 322 + 323 + config GPIO_IOP 324 + tristate "Intel IOP GPIO" 325 + depends on ARM && (ARCH_IOP32X || ARCH_IOP33X) 326 + help 327 + Say yes here to support the GPIO functionality of a number of Intel 328 + IOP32X or IOP33X. 320 329 321 330 If unsure, say N. 322 331 ··· 625 616 626 617 If unsure, say N 627 618 628 - config GPIO_LANGWELL 629 - bool "Intel Langwell/Penwell GPIO support" 619 + config GPIO_INTEL_MID 620 + bool "Intel Mid GPIO support" 630 621 depends on PCI && X86 631 622 select IRQ_DOMAIN 632 623 help 633 - Say Y here to support Intel Langwell/Penwell GPIO. 624 + Say Y here to support Intel Mid GPIO. 634 625 635 626 config GPIO_PCH 636 627 tristate "Intel EG20T PCH/LAPIS Semiconductor IOH(ML7223/ML7831) GPIO" ··· 716 707 comment "AC97 GPIO expanders:" 717 708 718 709 config GPIO_UCB1400 719 - bool "Philips UCB1400 GPIO" 710 + tristate "Philips UCB1400 GPIO" 720 711 depends on UCB1400_CORE 721 712 help 722 713 This enables support for the Philips UCB1400 GPIO pins. ··· 771 762 help 772 763 Enable support for GPIO on intel MSIC controllers found in 773 764 intel MID devices 765 + 766 + config GPIO_BCM_KONA 767 + bool "Broadcom Kona GPIO" 768 + depends on OF_GPIO 769 + help 770 + Turn on GPIO support for Broadcom "Kona" chips. 774 771 775 772 comment "USB GPIO expanders:" 776 773
+3 -1
drivers/gpio/Makefile
··· 16 16 obj-$(CONFIG_GPIO_ADP5588) += gpio-adp5588.o 17 17 obj-$(CONFIG_GPIO_AMD8111) += gpio-amd8111.o 18 18 obj-$(CONFIG_GPIO_ARIZONA) += gpio-arizona.o 19 + obj-$(CONFIG_GPIO_BCM_KONA) += gpio-bcm-kona.o 19 20 obj-$(CONFIG_GPIO_BT8XX) += gpio-bt8xx.o 20 21 obj-$(CONFIG_GPIO_CLPS711X) += gpio-clps711x.o 21 22 obj-$(CONFIG_GPIO_CS5535) += gpio-cs5535.o ··· 29 28 obj-$(CONFIG_GPIO_GE_FPGA) += gpio-ge.o 30 29 obj-$(CONFIG_GPIO_GRGPIO) += gpio-grgpio.o 31 30 obj-$(CONFIG_GPIO_ICH) += gpio-ich.o 31 + obj-$(CONFIG_GPIO_IOP) += gpio-iop.o 32 32 obj-$(CONFIG_GPIO_IT8761E) += gpio-it8761e.o 33 33 obj-$(CONFIG_GPIO_JANZ_TTL) += gpio-janz-ttl.o 34 34 obj-$(CONFIG_GPIO_KEMPLD) += gpio-kempld.o 35 35 obj-$(CONFIG_ARCH_KS8695) += gpio-ks8695.o 36 - obj-$(CONFIG_GPIO_LANGWELL) += gpio-langwell.o 36 + obj-$(CONFIG_GPIO_INTEL_MID) += gpio-intel-mid.o 37 37 obj-$(CONFIG_ARCH_LPC32XX) += gpio-lpc32xx.o 38 38 obj-$(CONFIG_GPIO_LYNXPOINT) += gpio-lynxpoint.o 39 39 obj-$(CONFIG_GPIO_MAX730X) += gpio-max730x.o
+85
drivers/gpio/devres.c
··· 15 15 */ 16 16 17 17 #include <linux/module.h> 18 + #include <linux/err.h> 18 19 #include <linux/gpio.h> 20 + #include <linux/gpio/consumer.h> 19 21 #include <linux/device.h> 20 22 #include <linux/gfp.h> 23 + 24 + static void devm_gpiod_release(struct device *dev, void *res) 25 + { 26 + struct gpio_desc **desc = res; 27 + 28 + gpiod_put(*desc); 29 + } 30 + 31 + static int devm_gpiod_match(struct device *dev, void *res, void *data) 32 + { 33 + struct gpio_desc **this = res, **gpio = data; 34 + 35 + return *this == *gpio; 36 + } 37 + 38 + /** 39 + * devm_gpiod_get - Resource-managed gpiod_get() 40 + * @dev: GPIO consumer 41 + * @con_id: function within the GPIO consumer 42 + * 43 + * Managed gpiod_get(). GPIO descriptors returned from this function are 44 + * automatically disposed on driver detach. See gpiod_get() for detailed 45 + * information about behavior and return values. 46 + */ 47 + struct gpio_desc *__must_check devm_gpiod_get(struct device *dev, 48 + const char *con_id) 49 + { 50 + return devm_gpiod_get_index(dev, con_id, 0); 51 + } 52 + EXPORT_SYMBOL(devm_gpiod_get); 53 + 54 + /** 55 + * devm_gpiod_get_index - Resource-managed gpiod_get_index() 56 + * @dev: GPIO consumer 57 + * @con_id: function within the GPIO consumer 58 + * @idx: index of the GPIO to obtain in the consumer 59 + * 60 + * Managed gpiod_get_index(). GPIO descriptors returned from this function are 61 + * automatically disposed on driver detach. See gpiod_get_index() for detailed 62 + * information about behavior and return values. 63 + */ 64 + struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev, 65 + const char *con_id, 66 + unsigned int idx) 67 + { 68 + struct gpio_desc **dr; 69 + struct gpio_desc *desc; 70 + 71 + dr = devres_alloc(devm_gpiod_release, sizeof(struct gpiod_desc *), 72 + GFP_KERNEL); 73 + if (!dr) 74 + return ERR_PTR(-ENOMEM); 75 + 76 + desc = gpiod_get_index(dev, con_id, idx); 77 + if (IS_ERR(desc)) { 78 + devres_free(dr); 79 + return desc; 80 + } 81 + 82 + *dr = desc; 83 + devres_add(dev, dr); 84 + 85 + return desc; 86 + } 87 + EXPORT_SYMBOL(devm_gpiod_get_index); 88 + 89 + /** 90 + * devm_gpiod_put - Resource-managed gpiod_put() 91 + * @desc: GPIO descriptor to dispose of 92 + * 93 + * Dispose of a GPIO descriptor obtained with devm_gpiod_get() or 94 + * devm_gpiod_get_index(). Normally this function will not be called as the GPIO 95 + * will be disposed of by the resource management code. 96 + */ 97 + void devm_gpiod_put(struct device *dev, struct gpio_desc *desc) 98 + { 99 + WARN_ON(devres_release(dev, devm_gpiod_release, devm_gpiod_match, 100 + &desc)); 101 + } 102 + EXPORT_SYMBOL(devm_gpiod_put); 103 + 104 + 105 + 21 106 22 107 static void devm_gpio_release(struct device *dev, void *res) 23 108 {
+1 -4
drivers/gpio/gpio-74x164.c
··· 176 176 return ret; 177 177 178 178 exit_destroy: 179 - spi_set_drvdata(spi, NULL); 180 179 mutex_destroy(&chip->lock); 181 180 return ret; 182 181 } ··· 188 189 chip = spi_get_drvdata(spi); 189 190 if (chip == NULL) 190 191 return -ENODEV; 191 - 192 - spi_set_drvdata(spi, NULL); 193 192 194 193 ret = gpiochip_remove(&chip->gpio_chip); 195 194 if (!ret) ··· 209 212 .driver = { 210 213 .name = "74x164", 211 214 .owner = THIS_MODULE, 212 - .of_match_table = of_match_ptr(gen_74x164_dt_ids), 215 + .of_match_table = gen_74x164_dt_ids, 213 216 }, 214 217 .probe = gen_74x164_probe, 215 218 .remove = gen_74x164_remove,
+4 -4
drivers/gpio/gpio-adnp.c
··· 325 325 pending &= isr & ier; 326 326 327 327 for_each_set_bit(bit, &pending, 8) { 328 - unsigned int virq; 329 - virq = irq_find_mapping(adnp->domain, base + bit); 330 - handle_nested_irq(virq); 328 + unsigned int child_irq; 329 + child_irq = irq_find_mapping(adnp->domain, base + bit); 330 + handle_nested_irq(child_irq); 331 331 } 332 332 } 333 333 ··· 594 594 .driver = { 595 595 .name = "gpio-adnp", 596 596 .owner = THIS_MODULE, 597 - .of_match_table = of_match_ptr(adnp_of_match), 597 + .of_match_table = adnp_of_match, 598 598 }, 599 599 .probe = adnp_i2c_probe, 600 600 .remove = adnp_i2c_remove,
+4
drivers/gpio/gpio-arizona.c
··· 109 109 arizona_gpio->arizona = arizona; 110 110 arizona_gpio->gpio_chip = template_chip; 111 111 arizona_gpio->gpio_chip.dev = &pdev->dev; 112 + #ifdef CONFIG_OF_GPIO 113 + arizona_gpio->gpio_chip.of_node = arizona->dev->of_node; 114 + #endif 112 115 113 116 switch (arizona->type) { 114 117 case WM5102: 115 118 case WM5110: 119 + case WM8997: 116 120 arizona_gpio->gpio_chip.ngpio = 5; 117 121 break; 118 122 default:
+640
drivers/gpio/gpio-bcm-kona.c
··· 1 + /* 2 + * Copyright (C) 2012-2013 Broadcom Corporation 3 + * 4 + * This program is free software; you can redistribute it and/or 5 + * modify it under the terms of the GNU General Public License as 6 + * published by the Free Software Foundation version 2. 7 + * 8 + * This program is distributed "as is" WITHOUT ANY WARRANTY of any 9 + * kind, whether express or implied; without even the implied warranty 10 + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 + * GNU General Public License for more details. 12 + */ 13 + 14 + #include <linux/bitops.h> 15 + #include <linux/err.h> 16 + #include <linux/io.h> 17 + #include <linux/gpio.h> 18 + #include <linux/of_device.h> 19 + #include <linux/of_irq.h> 20 + #include <linux/module.h> 21 + #include <linux/irqdomain.h> 22 + #include <linux/irqchip/chained_irq.h> 23 + 24 + #define BCM_GPIO_PASSWD 0x00a5a501 25 + #define GPIO_PER_BANK 32 26 + #define GPIO_MAX_BANK_NUM 8 27 + 28 + #define GPIO_BANK(gpio) ((gpio) >> 5) 29 + #define GPIO_BIT(gpio) ((gpio) & (GPIO_PER_BANK - 1)) 30 + 31 + #define GPIO_OUT_STATUS(bank) (0x00000000 + ((bank) << 2)) 32 + #define GPIO_IN_STATUS(bank) (0x00000020 + ((bank) << 2)) 33 + #define GPIO_OUT_SET(bank) (0x00000040 + ((bank) << 2)) 34 + #define GPIO_OUT_CLEAR(bank) (0x00000060 + ((bank) << 2)) 35 + #define GPIO_INT_STATUS(bank) (0x00000080 + ((bank) << 2)) 36 + #define GPIO_INT_MASK(bank) (0x000000a0 + ((bank) << 2)) 37 + #define GPIO_INT_MSKCLR(bank) (0x000000c0 + ((bank) << 2)) 38 + #define GPIO_CONTROL(bank) (0x00000100 + ((bank) << 2)) 39 + #define GPIO_PWD_STATUS(bank) (0x00000500 + ((bank) << 2)) 40 + 41 + #define GPIO_GPPWR_OFFSET 0x00000520 42 + 43 + #define GPIO_GPCTR0_DBR_SHIFT 5 44 + #define GPIO_GPCTR0_DBR_MASK 0x000001e0 45 + 46 + #define GPIO_GPCTR0_ITR_SHIFT 3 47 + #define GPIO_GPCTR0_ITR_MASK 0x00000018 48 + #define GPIO_GPCTR0_ITR_CMD_RISING_EDGE 0x00000001 49 + #define GPIO_GPCTR0_ITR_CMD_FALLING_EDGE 0x00000002 50 + #define GPIO_GPCTR0_ITR_CMD_BOTH_EDGE 0x00000003 51 + 52 + #define GPIO_GPCTR0_IOTR_MASK 0x00000001 53 + #define GPIO_GPCTR0_IOTR_CMD_0UTPUT 0x00000000 54 + #define GPIO_GPCTR0_IOTR_CMD_INPUT 0x00000001 55 + 56 + #define GPIO_GPCTR0_DB_ENABLE_MASK 0x00000100 57 + 58 + #define LOCK_CODE 0xffffffff 59 + #define UNLOCK_CODE 0x00000000 60 + 61 + struct bcm_kona_gpio { 62 + void __iomem *reg_base; 63 + int num_bank; 64 + spinlock_t lock; 65 + struct gpio_chip gpio_chip; 66 + struct irq_domain *irq_domain; 67 + struct bcm_kona_gpio_bank *banks; 68 + struct platform_device *pdev; 69 + }; 70 + 71 + struct bcm_kona_gpio_bank { 72 + int id; 73 + int irq; 74 + /* Used in the interrupt handler */ 75 + struct bcm_kona_gpio *kona_gpio; 76 + }; 77 + 78 + static inline struct bcm_kona_gpio *to_kona_gpio(struct gpio_chip *chip) 79 + { 80 + return container_of(chip, struct bcm_kona_gpio, gpio_chip); 81 + } 82 + 83 + static void bcm_kona_gpio_set_lockcode_bank(void __iomem *reg_base, 84 + int bank_id, int lockcode) 85 + { 86 + writel(BCM_GPIO_PASSWD, reg_base + GPIO_GPPWR_OFFSET); 87 + writel(lockcode, reg_base + GPIO_PWD_STATUS(bank_id)); 88 + } 89 + 90 + static inline void bcm_kona_gpio_lock_bank(void __iomem *reg_base, int bank_id) 91 + { 92 + bcm_kona_gpio_set_lockcode_bank(reg_base, bank_id, LOCK_CODE); 93 + } 94 + 95 + static inline void bcm_kona_gpio_unlock_bank(void __iomem *reg_base, 96 + int bank_id) 97 + { 98 + bcm_kona_gpio_set_lockcode_bank(reg_base, bank_id, UNLOCK_CODE); 99 + } 100 + 101 + static void bcm_kona_gpio_set(struct gpio_chip *chip, unsigned gpio, int value) 102 + { 103 + struct bcm_kona_gpio *kona_gpio; 104 + void __iomem *reg_base; 105 + int bank_id = GPIO_BANK(gpio); 106 + int bit = GPIO_BIT(gpio); 107 + u32 val, reg_offset; 108 + unsigned long flags; 109 + 110 + kona_gpio = to_kona_gpio(chip); 111 + reg_base = kona_gpio->reg_base; 112 + spin_lock_irqsave(&kona_gpio->lock, flags); 113 + bcm_kona_gpio_unlock_bank(reg_base, bank_id); 114 + 115 + /* determine the GPIO pin direction */ 116 + val = readl(reg_base + GPIO_CONTROL(gpio)); 117 + val &= GPIO_GPCTR0_IOTR_MASK; 118 + 119 + /* this function only applies to output pin */ 120 + if (GPIO_GPCTR0_IOTR_CMD_INPUT == val) 121 + goto out; 122 + 123 + reg_offset = value ? GPIO_OUT_SET(bank_id) : GPIO_OUT_CLEAR(bank_id); 124 + 125 + val = readl(reg_base + reg_offset); 126 + val |= BIT(bit); 127 + writel(val, reg_base + reg_offset); 128 + 129 + out: 130 + bcm_kona_gpio_lock_bank(reg_base, bank_id); 131 + spin_unlock_irqrestore(&kona_gpio->lock, flags); 132 + } 133 + 134 + static int bcm_kona_gpio_get(struct gpio_chip *chip, unsigned gpio) 135 + { 136 + struct bcm_kona_gpio *kona_gpio; 137 + void __iomem *reg_base; 138 + int bank_id = GPIO_BANK(gpio); 139 + int bit = GPIO_BIT(gpio); 140 + u32 val, reg_offset; 141 + unsigned long flags; 142 + 143 + kona_gpio = to_kona_gpio(chip); 144 + reg_base = kona_gpio->reg_base; 145 + spin_lock_irqsave(&kona_gpio->lock, flags); 146 + bcm_kona_gpio_unlock_bank(reg_base, bank_id); 147 + 148 + /* determine the GPIO pin direction */ 149 + val = readl(reg_base + GPIO_CONTROL(gpio)); 150 + val &= GPIO_GPCTR0_IOTR_MASK; 151 + 152 + /* read the GPIO bank status */ 153 + reg_offset = (GPIO_GPCTR0_IOTR_CMD_INPUT == val) ? 154 + GPIO_IN_STATUS(bank_id) : GPIO_OUT_STATUS(bank_id); 155 + val = readl(reg_base + reg_offset); 156 + 157 + bcm_kona_gpio_lock_bank(reg_base, bank_id); 158 + spin_unlock_irqrestore(&kona_gpio->lock, flags); 159 + 160 + /* return the specified bit status */ 161 + return !!(val & bit); 162 + } 163 + 164 + static int bcm_kona_gpio_direction_input(struct gpio_chip *chip, unsigned gpio) 165 + { 166 + struct bcm_kona_gpio *kona_gpio; 167 + void __iomem *reg_base; 168 + u32 val; 169 + unsigned long flags; 170 + int bank_id = GPIO_BANK(gpio); 171 + 172 + kona_gpio = to_kona_gpio(chip); 173 + reg_base = kona_gpio->reg_base; 174 + spin_lock_irqsave(&kona_gpio->lock, flags); 175 + bcm_kona_gpio_unlock_bank(reg_base, bank_id); 176 + 177 + val = readl(reg_base + GPIO_CONTROL(gpio)); 178 + val &= ~GPIO_GPCTR0_IOTR_MASK; 179 + val |= GPIO_GPCTR0_IOTR_CMD_INPUT; 180 + writel(val, reg_base + GPIO_CONTROL(gpio)); 181 + 182 + bcm_kona_gpio_lock_bank(reg_base, bank_id); 183 + spin_unlock_irqrestore(&kona_gpio->lock, flags); 184 + 185 + return 0; 186 + } 187 + 188 + static int bcm_kona_gpio_direction_output(struct gpio_chip *chip, 189 + unsigned gpio, int value) 190 + { 191 + struct bcm_kona_gpio *kona_gpio; 192 + void __iomem *reg_base; 193 + int bank_id = GPIO_BANK(gpio); 194 + int bit = GPIO_BIT(gpio); 195 + u32 val, reg_offset; 196 + unsigned long flags; 197 + 198 + kona_gpio = to_kona_gpio(chip); 199 + reg_base = kona_gpio->reg_base; 200 + spin_lock_irqsave(&kona_gpio->lock, flags); 201 + bcm_kona_gpio_unlock_bank(reg_base, bank_id); 202 + 203 + val = readl(reg_base + GPIO_CONTROL(gpio)); 204 + val &= ~GPIO_GPCTR0_IOTR_MASK; 205 + val |= GPIO_GPCTR0_IOTR_CMD_0UTPUT; 206 + writel(val, reg_base + GPIO_CONTROL(gpio)); 207 + reg_offset = value ? GPIO_OUT_SET(bank_id) : GPIO_OUT_CLEAR(bank_id); 208 + 209 + val = readl(reg_base + reg_offset); 210 + val |= BIT(bit); 211 + writel(val, reg_base + reg_offset); 212 + 213 + bcm_kona_gpio_lock_bank(reg_base, bank_id); 214 + spin_unlock_irqrestore(&kona_gpio->lock, flags); 215 + 216 + return 0; 217 + } 218 + 219 + static int bcm_kona_gpio_to_irq(struct gpio_chip *chip, unsigned gpio) 220 + { 221 + struct bcm_kona_gpio *kona_gpio; 222 + 223 + kona_gpio = to_kona_gpio(chip); 224 + if (gpio >= kona_gpio->gpio_chip.ngpio) 225 + return -ENXIO; 226 + return irq_create_mapping(kona_gpio->irq_domain, gpio); 227 + } 228 + 229 + static int bcm_kona_gpio_set_debounce(struct gpio_chip *chip, unsigned gpio, 230 + unsigned debounce) 231 + { 232 + struct bcm_kona_gpio *kona_gpio; 233 + void __iomem *reg_base; 234 + u32 val, res; 235 + unsigned long flags; 236 + int bank_id = GPIO_BANK(gpio); 237 + 238 + kona_gpio = to_kona_gpio(chip); 239 + reg_base = kona_gpio->reg_base; 240 + /* debounce must be 1-128ms (or 0) */ 241 + if ((debounce > 0 && debounce < 1000) || debounce > 128000) { 242 + dev_err(chip->dev, "Debounce value %u not in range\n", 243 + debounce); 244 + return -EINVAL; 245 + } 246 + 247 + /* calculate debounce bit value */ 248 + if (debounce != 0) { 249 + /* Convert to ms */ 250 + debounce /= 1000; 251 + /* find the MSB */ 252 + res = fls(debounce) - 1; 253 + /* Check if MSB-1 is set (round up or down) */ 254 + if (res > 0 && (debounce & BIT(res - 1))) 255 + res++; 256 + } 257 + 258 + /* spin lock for read-modify-write of the GPIO register */ 259 + spin_lock_irqsave(&kona_gpio->lock, flags); 260 + bcm_kona_gpio_unlock_bank(reg_base, bank_id); 261 + 262 + val = readl(reg_base + GPIO_CONTROL(gpio)); 263 + val &= ~GPIO_GPCTR0_DBR_MASK; 264 + 265 + if (debounce == 0) { 266 + /* disable debounce */ 267 + val &= ~GPIO_GPCTR0_DB_ENABLE_MASK; 268 + } else { 269 + val |= GPIO_GPCTR0_DB_ENABLE_MASK | 270 + (res << GPIO_GPCTR0_DBR_SHIFT); 271 + } 272 + 273 + writel(val, reg_base + GPIO_CONTROL(gpio)); 274 + 275 + bcm_kona_gpio_lock_bank(reg_base, bank_id); 276 + spin_unlock_irqrestore(&kona_gpio->lock, flags); 277 + 278 + return 0; 279 + } 280 + 281 + static struct gpio_chip template_chip = { 282 + .label = "bcm-kona-gpio", 283 + .owner = THIS_MODULE, 284 + .direction_input = bcm_kona_gpio_direction_input, 285 + .get = bcm_kona_gpio_get, 286 + .direction_output = bcm_kona_gpio_direction_output, 287 + .set = bcm_kona_gpio_set, 288 + .set_debounce = bcm_kona_gpio_set_debounce, 289 + .to_irq = bcm_kona_gpio_to_irq, 290 + .base = 0, 291 + }; 292 + 293 + static void bcm_kona_gpio_irq_ack(struct irq_data *d) 294 + { 295 + struct bcm_kona_gpio *kona_gpio; 296 + void __iomem *reg_base; 297 + int gpio = d->hwirq; 298 + int bank_id = GPIO_BANK(gpio); 299 + int bit = GPIO_BIT(gpio); 300 + u32 val; 301 + unsigned long flags; 302 + 303 + kona_gpio = irq_data_get_irq_chip_data(d); 304 + reg_base = kona_gpio->reg_base; 305 + spin_lock_irqsave(&kona_gpio->lock, flags); 306 + bcm_kona_gpio_unlock_bank(reg_base, bank_id); 307 + 308 + val = readl(reg_base + GPIO_INT_STATUS(bank_id)); 309 + val |= BIT(bit); 310 + writel(val, reg_base + GPIO_INT_STATUS(bank_id)); 311 + 312 + bcm_kona_gpio_lock_bank(reg_base, bank_id); 313 + spin_unlock_irqrestore(&kona_gpio->lock, flags); 314 + } 315 + 316 + static void bcm_kona_gpio_irq_mask(struct irq_data *d) 317 + { 318 + struct bcm_kona_gpio *kona_gpio; 319 + void __iomem *reg_base; 320 + int gpio = d->hwirq; 321 + int bank_id = GPIO_BANK(gpio); 322 + int bit = GPIO_BIT(gpio); 323 + u32 val; 324 + unsigned long flags; 325 + 326 + kona_gpio = irq_data_get_irq_chip_data(d); 327 + reg_base = kona_gpio->reg_base; 328 + spin_lock_irqsave(&kona_gpio->lock, flags); 329 + bcm_kona_gpio_unlock_bank(reg_base, bank_id); 330 + 331 + val = readl(reg_base + GPIO_INT_MASK(bank_id)); 332 + val |= BIT(bit); 333 + writel(val, reg_base + GPIO_INT_MASK(bank_id)); 334 + 335 + bcm_kona_gpio_lock_bank(reg_base, bank_id); 336 + spin_unlock_irqrestore(&kona_gpio->lock, flags); 337 + } 338 + 339 + static void bcm_kona_gpio_irq_unmask(struct irq_data *d) 340 + { 341 + struct bcm_kona_gpio *kona_gpio; 342 + void __iomem *reg_base; 343 + int gpio = d->hwirq; 344 + int bank_id = GPIO_BANK(gpio); 345 + int bit = GPIO_BIT(gpio); 346 + u32 val; 347 + unsigned long flags; 348 + 349 + kona_gpio = irq_data_get_irq_chip_data(d); 350 + reg_base = kona_gpio->reg_base; 351 + spin_lock_irqsave(&kona_gpio->lock, flags); 352 + bcm_kona_gpio_unlock_bank(reg_base, bank_id); 353 + 354 + val = readl(reg_base + GPIO_INT_MSKCLR(bank_id)); 355 + val |= BIT(bit); 356 + writel(val, reg_base + GPIO_INT_MSKCLR(bank_id)); 357 + 358 + bcm_kona_gpio_lock_bank(reg_base, bank_id); 359 + spin_unlock_irqrestore(&kona_gpio->lock, flags); 360 + } 361 + 362 + static int bcm_kona_gpio_irq_set_type(struct irq_data *d, unsigned int type) 363 + { 364 + struct bcm_kona_gpio *kona_gpio; 365 + void __iomem *reg_base; 366 + int gpio = d->hwirq; 367 + u32 lvl_type; 368 + u32 val; 369 + unsigned long flags; 370 + int bank_id = GPIO_BANK(gpio); 371 + 372 + kona_gpio = irq_data_get_irq_chip_data(d); 373 + reg_base = kona_gpio->reg_base; 374 + switch (type & IRQ_TYPE_SENSE_MASK) { 375 + case IRQ_TYPE_EDGE_RISING: 376 + lvl_type = GPIO_GPCTR0_ITR_CMD_RISING_EDGE; 377 + break; 378 + 379 + case IRQ_TYPE_EDGE_FALLING: 380 + lvl_type = GPIO_GPCTR0_ITR_CMD_FALLING_EDGE; 381 + break; 382 + 383 + case IRQ_TYPE_EDGE_BOTH: 384 + lvl_type = GPIO_GPCTR0_ITR_CMD_BOTH_EDGE; 385 + break; 386 + 387 + case IRQ_TYPE_LEVEL_HIGH: 388 + case IRQ_TYPE_LEVEL_LOW: 389 + /* BCM GPIO doesn't support level triggering */ 390 + default: 391 + dev_err(kona_gpio->gpio_chip.dev, 392 + "Invalid BCM GPIO irq type 0x%x\n", type); 393 + return -EINVAL; 394 + } 395 + 396 + spin_lock_irqsave(&kona_gpio->lock, flags); 397 + bcm_kona_gpio_unlock_bank(reg_base, bank_id); 398 + 399 + val = readl(reg_base + GPIO_CONTROL(gpio)); 400 + val &= ~GPIO_GPCTR0_ITR_MASK; 401 + val |= lvl_type << GPIO_GPCTR0_ITR_SHIFT; 402 + writel(val, reg_base + GPIO_CONTROL(gpio)); 403 + 404 + bcm_kona_gpio_lock_bank(reg_base, bank_id); 405 + spin_unlock_irqrestore(&kona_gpio->lock, flags); 406 + 407 + return 0; 408 + } 409 + 410 + static void bcm_kona_gpio_irq_handler(unsigned int irq, struct irq_desc *desc) 411 + { 412 + void __iomem *reg_base; 413 + int bit, bank_id; 414 + unsigned long sta; 415 + struct bcm_kona_gpio_bank *bank = irq_get_handler_data(irq); 416 + struct irq_chip *chip = irq_desc_get_chip(desc); 417 + 418 + chained_irq_enter(chip, desc); 419 + 420 + /* 421 + * For bank interrupts, we can't use chip_data to store the kona_gpio 422 + * pointer, since GIC needs it for its own purposes. Therefore, we get 423 + * our pointer from the bank structure. 424 + */ 425 + reg_base = bank->kona_gpio->reg_base; 426 + bank_id = bank->id; 427 + bcm_kona_gpio_unlock_bank(reg_base, bank_id); 428 + 429 + while ((sta = readl(reg_base + GPIO_INT_STATUS(bank_id)) & 430 + (~(readl(reg_base + GPIO_INT_MASK(bank_id)))))) { 431 + for_each_set_bit(bit, &sta, 32) { 432 + int hwirq = GPIO_PER_BANK * bank_id + bit; 433 + int child_irq = 434 + irq_find_mapping(bank->kona_gpio->irq_domain, 435 + hwirq); 436 + /* 437 + * Clear interrupt before handler is called so we don't 438 + * miss any interrupt occurred during executing them. 439 + */ 440 + writel(readl(reg_base + GPIO_INT_STATUS(bank_id)) | 441 + BIT(bit), reg_base + GPIO_INT_STATUS(bank_id)); 442 + /* Invoke interrupt handler */ 443 + generic_handle_irq(child_irq); 444 + } 445 + } 446 + 447 + bcm_kona_gpio_lock_bank(reg_base, bank_id); 448 + 449 + chained_irq_exit(chip, desc); 450 + } 451 + 452 + static struct irq_chip bcm_gpio_irq_chip = { 453 + .name = "bcm-kona-gpio", 454 + .irq_ack = bcm_kona_gpio_irq_ack, 455 + .irq_mask = bcm_kona_gpio_irq_mask, 456 + .irq_unmask = bcm_kona_gpio_irq_unmask, 457 + .irq_set_type = bcm_kona_gpio_irq_set_type, 458 + }; 459 + 460 + static struct __initconst of_device_id bcm_kona_gpio_of_match[] = { 461 + { .compatible = "brcm,kona-gpio" }, 462 + {} 463 + }; 464 + 465 + MODULE_DEVICE_TABLE(of, bcm_kona_gpio_of_match); 466 + 467 + /* 468 + * This lock class tells lockdep that GPIO irqs are in a different 469 + * category than their parents, so it won't report false recursion. 470 + */ 471 + static struct lock_class_key gpio_lock_class; 472 + 473 + static int bcm_kona_gpio_irq_map(struct irq_domain *d, unsigned int irq, 474 + irq_hw_number_t hwirq) 475 + { 476 + int ret; 477 + 478 + ret = irq_set_chip_data(irq, d->host_data); 479 + if (ret < 0) 480 + return ret; 481 + irq_set_lockdep_class(irq, &gpio_lock_class); 482 + irq_set_chip_and_handler(irq, &bcm_gpio_irq_chip, handle_simple_irq); 483 + #ifdef CONFIG_ARM 484 + set_irq_flags(irq, IRQF_VALID); 485 + #else 486 + irq_set_noprobe(irq); 487 + #endif 488 + 489 + return 0; 490 + } 491 + 492 + static void bcm_kona_gpio_irq_unmap(struct irq_domain *d, unsigned int irq) 493 + { 494 + irq_set_chip_and_handler(irq, NULL, NULL); 495 + irq_set_chip_data(irq, NULL); 496 + } 497 + 498 + static struct irq_domain_ops bcm_kona_irq_ops = { 499 + .map = bcm_kona_gpio_irq_map, 500 + .unmap = bcm_kona_gpio_irq_unmap, 501 + .xlate = irq_domain_xlate_twocell, 502 + }; 503 + 504 + static void bcm_kona_gpio_reset(struct bcm_kona_gpio *kona_gpio) 505 + { 506 + void __iomem *reg_base; 507 + int i; 508 + 509 + reg_base = kona_gpio->reg_base; 510 + /* disable interrupts and clear status */ 511 + for (i = 0; i < kona_gpio->num_bank; i++) { 512 + bcm_kona_gpio_unlock_bank(reg_base, i); 513 + writel(0xffffffff, reg_base + GPIO_INT_MASK(i)); 514 + writel(0xffffffff, reg_base + GPIO_INT_STATUS(i)); 515 + bcm_kona_gpio_lock_bank(reg_base, i); 516 + } 517 + } 518 + 519 + static int bcm_kona_gpio_probe(struct platform_device *pdev) 520 + { 521 + struct device *dev = &pdev->dev; 522 + const struct of_device_id *match; 523 + struct resource *res; 524 + struct bcm_kona_gpio_bank *bank; 525 + struct bcm_kona_gpio *kona_gpio; 526 + struct gpio_chip *chip; 527 + int ret; 528 + int i; 529 + 530 + match = of_match_device(bcm_kona_gpio_of_match, dev); 531 + if (!match) { 532 + dev_err(dev, "Failed to find gpio controller\n"); 533 + return -ENODEV; 534 + } 535 + 536 + kona_gpio = devm_kzalloc(dev, sizeof(*kona_gpio), GFP_KERNEL); 537 + if (!kona_gpio) 538 + return -ENOMEM; 539 + 540 + kona_gpio->gpio_chip = template_chip; 541 + chip = &kona_gpio->gpio_chip; 542 + kona_gpio->num_bank = of_irq_count(dev->of_node); 543 + if (kona_gpio->num_bank == 0) { 544 + dev_err(dev, "Couldn't determine # GPIO banks\n"); 545 + return -ENOENT; 546 + } 547 + if (kona_gpio->num_bank > GPIO_MAX_BANK_NUM) { 548 + dev_err(dev, "Too many GPIO banks configured (max=%d)\n", 549 + GPIO_MAX_BANK_NUM); 550 + return -ENXIO; 551 + } 552 + kona_gpio->banks = devm_kzalloc(dev, 553 + kona_gpio->num_bank * 554 + sizeof(*kona_gpio->banks), GFP_KERNEL); 555 + if (!kona_gpio->banks) 556 + return -ENOMEM; 557 + 558 + kona_gpio->pdev = pdev; 559 + platform_set_drvdata(pdev, kona_gpio); 560 + chip->of_node = dev->of_node; 561 + chip->ngpio = kona_gpio->num_bank * GPIO_PER_BANK; 562 + 563 + kona_gpio->irq_domain = irq_domain_add_linear(dev->of_node, 564 + chip->ngpio, 565 + &bcm_kona_irq_ops, 566 + kona_gpio); 567 + if (!kona_gpio->irq_domain) { 568 + dev_err(dev, "Couldn't allocate IRQ domain\n"); 569 + return -ENXIO; 570 + } 571 + 572 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 573 + kona_gpio->reg_base = devm_ioremap_resource(dev, res); 574 + if (IS_ERR(kona_gpio->reg_base)) { 575 + ret = -ENXIO; 576 + goto err_irq_domain; 577 + } 578 + 579 + for (i = 0; i < kona_gpio->num_bank; i++) { 580 + bank = &kona_gpio->banks[i]; 581 + bank->id = i; 582 + bank->irq = platform_get_irq(pdev, i); 583 + bank->kona_gpio = kona_gpio; 584 + if (bank->irq < 0) { 585 + dev_err(dev, "Couldn't get IRQ for bank %d", i); 586 + ret = -ENOENT; 587 + goto err_irq_domain; 588 + } 589 + } 590 + 591 + dev_info(&pdev->dev, "Setting up Kona GPIO\n"); 592 + 593 + bcm_kona_gpio_reset(kona_gpio); 594 + 595 + ret = gpiochip_add(chip); 596 + if (ret < 0) { 597 + dev_err(dev, "Couldn't add GPIO chip -- %d\n", ret); 598 + goto err_irq_domain; 599 + } 600 + for (i = 0; i < chip->ngpio; i++) { 601 + int irq = bcm_kona_gpio_to_irq(chip, i); 602 + irq_set_lockdep_class(irq, &gpio_lock_class); 603 + irq_set_chip_and_handler(irq, &bcm_gpio_irq_chip, 604 + handle_simple_irq); 605 + #ifdef CONFIG_ARM 606 + set_irq_flags(irq, IRQF_VALID); 607 + #else 608 + irq_set_noprobe(irq); 609 + #endif 610 + } 611 + for (i = 0; i < kona_gpio->num_bank; i++) { 612 + bank = &kona_gpio->banks[i]; 613 + irq_set_chained_handler(bank->irq, bcm_kona_gpio_irq_handler); 614 + irq_set_handler_data(bank->irq, bank); 615 + } 616 + 617 + spin_lock_init(&kona_gpio->lock); 618 + 619 + return 0; 620 + 621 + err_irq_domain: 622 + irq_domain_remove(kona_gpio->irq_domain); 623 + 624 + return ret; 625 + } 626 + 627 + static struct platform_driver bcm_kona_gpio_driver = { 628 + .driver = { 629 + .name = "bcm-kona-gpio", 630 + .owner = THIS_MODULE, 631 + .of_match_table = bcm_kona_gpio_of_match, 632 + }, 633 + .probe = bcm_kona_gpio_probe, 634 + }; 635 + 636 + module_platform_driver(bcm_kona_gpio_driver); 637 + 638 + MODULE_AUTHOR("Broadcom"); 639 + MODULE_DESCRIPTION("Broadcom Kona GPIO Driver"); 640 + MODULE_LICENSE("GPL v2");
-2
drivers/gpio/gpio-bt8xx.c
··· 228 228 err_release_mem: 229 229 release_mem_region(pci_resource_start(dev, 0), 230 230 pci_resource_len(dev, 0)); 231 - pci_set_drvdata(dev, NULL); 232 231 err_disable: 233 232 pci_disable_device(dev); 234 233 err_freebg: ··· 251 252 pci_resource_len(pdev, 0)); 252 253 pci_disable_device(pdev); 253 254 254 - pci_set_drvdata(pdev, NULL); 255 255 kfree(bg); 256 256 } 257 257
+1 -1
drivers/gpio/gpio-clps711x.c
··· 87 87 .driver = { 88 88 .name = "clps711x-gpio", 89 89 .owner = THIS_MODULE, 90 - .of_match_table = of_match_ptr(clps711x_gpio_ids), 90 + .of_match_table = clps711x_gpio_ids, 91 91 }, 92 92 .probe = clps711x_gpio_probe, 93 93 .remove = clps711x_gpio_remove,
+7 -6
drivers/gpio/gpio-em.c
··· 232 232 em_gio_direction_input(chip, offset); 233 233 } 234 234 235 - static int em_gio_irq_domain_map(struct irq_domain *h, unsigned int virq, 236 - irq_hw_number_t hw) 235 + static int em_gio_irq_domain_map(struct irq_domain *h, unsigned int irq, 236 + irq_hw_number_t hwirq) 237 237 { 238 238 struct em_gio_priv *p = h->host_data; 239 239 240 - pr_debug("gio: map hw irq = %d, virq = %d\n", (int)hw, virq); 240 + pr_debug("gio: map hw irq = %d, irq = %d\n", (int)hwirq, irq); 241 241 242 - irq_set_chip_data(virq, h->host_data); 243 - irq_set_chip_and_handler(virq, &p->irq_chip, handle_level_irq); 244 - set_irq_flags(virq, IRQF_VALID); /* kill me now */ 242 + irq_set_chip_data(irq, h->host_data); 243 + irq_set_chip_and_handler(irq, &p->irq_chip, handle_level_irq); 244 + set_irq_flags(irq, IRQF_VALID); /* kill me now */ 245 245 return 0; 246 246 } 247 247 ··· 319 319 } 320 320 321 321 gpio_chip = &p->gpio_chip; 322 + gpio_chip->of_node = pdev->dev.of_node; 322 323 gpio_chip->direction_input = em_gio_direction_input; 323 324 gpio_chip->get = em_gio_get; 324 325 gpio_chip->direction_output = em_gio_direction_output;
+9 -9
drivers/gpio/gpio-ep93xx.c
··· 51 51 { 52 52 BUG_ON(port > 2); 53 53 54 - __raw_writeb(0, EP93XX_GPIO_REG(int_en_register_offset[port])); 54 + writeb_relaxed(0, EP93XX_GPIO_REG(int_en_register_offset[port])); 55 55 56 - __raw_writeb(gpio_int_type2[port], 56 + writeb_relaxed(gpio_int_type2[port], 57 57 EP93XX_GPIO_REG(int_type2_register_offset[port])); 58 58 59 - __raw_writeb(gpio_int_type1[port], 59 + writeb_relaxed(gpio_int_type1[port], 60 60 EP93XX_GPIO_REG(int_type1_register_offset[port])); 61 61 62 - __raw_writeb(gpio_int_unmasked[port] & gpio_int_enabled[port], 62 + writeb(gpio_int_unmasked[port] & gpio_int_enabled[port], 63 63 EP93XX_GPIO_REG(int_en_register_offset[port])); 64 64 } 65 65 ··· 74 74 else 75 75 gpio_int_debounce[port] &= ~port_mask; 76 76 77 - __raw_writeb(gpio_int_debounce[port], 77 + writeb(gpio_int_debounce[port], 78 78 EP93XX_GPIO_REG(int_debounce_register_offset[port])); 79 79 } 80 80 ··· 83 83 unsigned char status; 84 84 int i; 85 85 86 - status = __raw_readb(EP93XX_GPIO_A_INT_STATUS); 86 + status = readb(EP93XX_GPIO_A_INT_STATUS); 87 87 for (i = 0; i < 8; i++) { 88 88 if (status & (1 << i)) { 89 89 int gpio_irq = gpio_to_irq(EP93XX_GPIO_LINE_A(0)) + i; ··· 91 91 } 92 92 } 93 93 94 - status = __raw_readb(EP93XX_GPIO_B_INT_STATUS); 94 + status = readb(EP93XX_GPIO_B_INT_STATUS); 95 95 for (i = 0; i < 8; i++) { 96 96 if (status & (1 << i)) { 97 97 int gpio_irq = gpio_to_irq(EP93XX_GPIO_LINE_B(0)) + i; ··· 124 124 ep93xx_gpio_update_int_params(port); 125 125 } 126 126 127 - __raw_writeb(port_mask, EP93XX_GPIO_REG(eoi_register_offset[port])); 127 + writeb(port_mask, EP93XX_GPIO_REG(eoi_register_offset[port])); 128 128 } 129 129 130 130 static void ep93xx_gpio_irq_mask_ack(struct irq_data *d) ··· 139 139 gpio_int_unmasked[port] &= ~port_mask; 140 140 ep93xx_gpio_update_int_params(port); 141 141 142 - __raw_writeb(port_mask, EP93XX_GPIO_REG(eoi_register_offset[port])); 142 + writeb(port_mask, EP93XX_GPIO_REG(eoi_register_offset[port])); 143 143 } 144 144 145 145 static void ep93xx_gpio_irq_mask(struct irq_data *d)
+471
drivers/gpio/gpio-intel-mid.c
··· 1 + /* 2 + * Moorestown platform Langwell chip GPIO driver 3 + * 4 + * Copyright (c) 2008, 2009, 2013, Intel Corporation. 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 version 2 as 8 + * published by the Free Software Foundation. 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 + * You should have received a copy of the GNU General Public License 16 + * along with this program; if not, write to the Free Software 17 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 + */ 19 + 20 + /* Supports: 21 + * Moorestown platform Langwell chip. 22 + * Medfield platform Penwell chip. 23 + * Clovertrail platform Cloverview chip. 24 + * Merrifield platform Tangier chip. 25 + */ 26 + 27 + #include <linux/module.h> 28 + #include <linux/pci.h> 29 + #include <linux/platform_device.h> 30 + #include <linux/kernel.h> 31 + #include <linux/delay.h> 32 + #include <linux/stddef.h> 33 + #include <linux/interrupt.h> 34 + #include <linux/init.h> 35 + #include <linux/irq.h> 36 + #include <linux/io.h> 37 + #include <linux/gpio.h> 38 + #include <linux/slab.h> 39 + #include <linux/pm_runtime.h> 40 + #include <linux/irqdomain.h> 41 + 42 + #define INTEL_MID_IRQ_TYPE_EDGE (1 << 0) 43 + #define INTEL_MID_IRQ_TYPE_LEVEL (1 << 1) 44 + 45 + /* 46 + * Langwell chip has 64 pins and thus there are 2 32bit registers to control 47 + * each feature, while Penwell chip has 96 pins for each block, and need 3 32bit 48 + * registers to control them, so we only define the order here instead of a 49 + * structure, to get a bit offset for a pin (use GPDR as an example): 50 + * 51 + * nreg = ngpio / 32; 52 + * reg = offset / 32; 53 + * bit = offset % 32; 54 + * reg_addr = reg_base + GPDR * nreg * 4 + reg * 4; 55 + * 56 + * so the bit of reg_addr is to control pin offset's GPDR feature 57 + */ 58 + 59 + enum GPIO_REG { 60 + GPLR = 0, /* pin level read-only */ 61 + GPDR, /* pin direction */ 62 + GPSR, /* pin set */ 63 + GPCR, /* pin clear */ 64 + GRER, /* rising edge detect */ 65 + GFER, /* falling edge detect */ 66 + GEDR, /* edge detect result */ 67 + GAFR, /* alt function */ 68 + }; 69 + 70 + /* intel_mid gpio driver data */ 71 + struct intel_mid_gpio_ddata { 72 + u16 ngpio; /* number of gpio pins */ 73 + u32 gplr_offset; /* offset of first GPLR register from base */ 74 + u32 flis_base; /* base address of FLIS registers */ 75 + u32 flis_len; /* length of FLIS registers */ 76 + u32 (*get_flis_offset)(int gpio); 77 + u32 chip_irq_type; /* chip interrupt type */ 78 + }; 79 + 80 + struct intel_mid_gpio { 81 + struct gpio_chip chip; 82 + void __iomem *reg_base; 83 + spinlock_t lock; 84 + struct pci_dev *pdev; 85 + struct irq_domain *domain; 86 + }; 87 + 88 + #define to_intel_gpio_priv(chip) container_of(chip, struct intel_mid_gpio, chip) 89 + 90 + static void __iomem *gpio_reg(struct gpio_chip *chip, unsigned offset, 91 + enum GPIO_REG reg_type) 92 + { 93 + struct intel_mid_gpio *priv = to_intel_gpio_priv(chip); 94 + unsigned nreg = chip->ngpio / 32; 95 + u8 reg = offset / 32; 96 + 97 + return priv->reg_base + reg_type * nreg * 4 + reg * 4; 98 + } 99 + 100 + static void __iomem *gpio_reg_2bit(struct gpio_chip *chip, unsigned offset, 101 + enum GPIO_REG reg_type) 102 + { 103 + struct intel_mid_gpio *priv = to_intel_gpio_priv(chip); 104 + unsigned nreg = chip->ngpio / 32; 105 + u8 reg = offset / 16; 106 + 107 + return priv->reg_base + reg_type * nreg * 4 + reg * 4; 108 + } 109 + 110 + static int intel_gpio_request(struct gpio_chip *chip, unsigned offset) 111 + { 112 + void __iomem *gafr = gpio_reg_2bit(chip, offset, GAFR); 113 + u32 value = readl(gafr); 114 + int shift = (offset % 16) << 1, af = (value >> shift) & 3; 115 + 116 + if (af) { 117 + value &= ~(3 << shift); 118 + writel(value, gafr); 119 + } 120 + return 0; 121 + } 122 + 123 + static int intel_gpio_get(struct gpio_chip *chip, unsigned offset) 124 + { 125 + void __iomem *gplr = gpio_reg(chip, offset, GPLR); 126 + 127 + return readl(gplr) & BIT(offset % 32); 128 + } 129 + 130 + static void intel_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 131 + { 132 + void __iomem *gpsr, *gpcr; 133 + 134 + if (value) { 135 + gpsr = gpio_reg(chip, offset, GPSR); 136 + writel(BIT(offset % 32), gpsr); 137 + } else { 138 + gpcr = gpio_reg(chip, offset, GPCR); 139 + writel(BIT(offset % 32), gpcr); 140 + } 141 + } 142 + 143 + static int intel_gpio_direction_input(struct gpio_chip *chip, unsigned offset) 144 + { 145 + struct intel_mid_gpio *priv = to_intel_gpio_priv(chip); 146 + void __iomem *gpdr = gpio_reg(chip, offset, GPDR); 147 + u32 value; 148 + unsigned long flags; 149 + 150 + if (priv->pdev) 151 + pm_runtime_get(&priv->pdev->dev); 152 + 153 + spin_lock_irqsave(&priv->lock, flags); 154 + value = readl(gpdr); 155 + value &= ~BIT(offset % 32); 156 + writel(value, gpdr); 157 + spin_unlock_irqrestore(&priv->lock, flags); 158 + 159 + if (priv->pdev) 160 + pm_runtime_put(&priv->pdev->dev); 161 + 162 + return 0; 163 + } 164 + 165 + static int intel_gpio_direction_output(struct gpio_chip *chip, 166 + unsigned offset, int value) 167 + { 168 + struct intel_mid_gpio *priv = to_intel_gpio_priv(chip); 169 + void __iomem *gpdr = gpio_reg(chip, offset, GPDR); 170 + unsigned long flags; 171 + 172 + intel_gpio_set(chip, offset, value); 173 + 174 + if (priv->pdev) 175 + pm_runtime_get(&priv->pdev->dev); 176 + 177 + spin_lock_irqsave(&priv->lock, flags); 178 + value = readl(gpdr); 179 + value |= BIT(offset % 32); 180 + writel(value, gpdr); 181 + spin_unlock_irqrestore(&priv->lock, flags); 182 + 183 + if (priv->pdev) 184 + pm_runtime_put(&priv->pdev->dev); 185 + 186 + return 0; 187 + } 188 + 189 + static int intel_gpio_to_irq(struct gpio_chip *chip, unsigned offset) 190 + { 191 + struct intel_mid_gpio *priv = to_intel_gpio_priv(chip); 192 + return irq_create_mapping(priv->domain, offset); 193 + } 194 + 195 + static int intel_mid_irq_type(struct irq_data *d, unsigned type) 196 + { 197 + struct intel_mid_gpio *priv = irq_data_get_irq_chip_data(d); 198 + u32 gpio = irqd_to_hwirq(d); 199 + unsigned long flags; 200 + u32 value; 201 + void __iomem *grer = gpio_reg(&priv->chip, gpio, GRER); 202 + void __iomem *gfer = gpio_reg(&priv->chip, gpio, GFER); 203 + 204 + if (gpio >= priv->chip.ngpio) 205 + return -EINVAL; 206 + 207 + if (priv->pdev) 208 + pm_runtime_get(&priv->pdev->dev); 209 + 210 + spin_lock_irqsave(&priv->lock, flags); 211 + if (type & IRQ_TYPE_EDGE_RISING) 212 + value = readl(grer) | BIT(gpio % 32); 213 + else 214 + value = readl(grer) & (~BIT(gpio % 32)); 215 + writel(value, grer); 216 + 217 + if (type & IRQ_TYPE_EDGE_FALLING) 218 + value = readl(gfer) | BIT(gpio % 32); 219 + else 220 + value = readl(gfer) & (~BIT(gpio % 32)); 221 + writel(value, gfer); 222 + spin_unlock_irqrestore(&priv->lock, flags); 223 + 224 + if (priv->pdev) 225 + pm_runtime_put(&priv->pdev->dev); 226 + 227 + return 0; 228 + } 229 + 230 + static void intel_mid_irq_unmask(struct irq_data *d) 231 + { 232 + } 233 + 234 + static void intel_mid_irq_mask(struct irq_data *d) 235 + { 236 + } 237 + 238 + static struct irq_chip intel_mid_irqchip = { 239 + .name = "INTEL_MID-GPIO", 240 + .irq_mask = intel_mid_irq_mask, 241 + .irq_unmask = intel_mid_irq_unmask, 242 + .irq_set_type = intel_mid_irq_type, 243 + }; 244 + 245 + static const struct intel_mid_gpio_ddata gpio_lincroft = { 246 + .ngpio = 64, 247 + }; 248 + 249 + static const struct intel_mid_gpio_ddata gpio_penwell_aon = { 250 + .ngpio = 96, 251 + .chip_irq_type = INTEL_MID_IRQ_TYPE_EDGE, 252 + }; 253 + 254 + static const struct intel_mid_gpio_ddata gpio_penwell_core = { 255 + .ngpio = 96, 256 + .chip_irq_type = INTEL_MID_IRQ_TYPE_EDGE, 257 + }; 258 + 259 + static const struct intel_mid_gpio_ddata gpio_cloverview_aon = { 260 + .ngpio = 96, 261 + .chip_irq_type = INTEL_MID_IRQ_TYPE_EDGE | INTEL_MID_IRQ_TYPE_LEVEL, 262 + }; 263 + 264 + static const struct intel_mid_gpio_ddata gpio_cloverview_core = { 265 + .ngpio = 96, 266 + .chip_irq_type = INTEL_MID_IRQ_TYPE_EDGE, 267 + }; 268 + 269 + static const struct intel_mid_gpio_ddata gpio_tangier = { 270 + .ngpio = 192, 271 + .gplr_offset = 4, 272 + .flis_base = 0xff0c0000, 273 + .flis_len = 0x8000, 274 + .get_flis_offset = NULL, 275 + .chip_irq_type = INTEL_MID_IRQ_TYPE_EDGE, 276 + }; 277 + 278 + static DEFINE_PCI_DEVICE_TABLE(intel_gpio_ids) = { 279 + { 280 + /* Lincroft */ 281 + PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x080f), 282 + .driver_data = (kernel_ulong_t)&gpio_lincroft, 283 + }, 284 + { 285 + /* Penwell AON */ 286 + PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x081f), 287 + .driver_data = (kernel_ulong_t)&gpio_penwell_aon, 288 + }, 289 + { 290 + /* Penwell Core */ 291 + PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x081a), 292 + .driver_data = (kernel_ulong_t)&gpio_penwell_core, 293 + }, 294 + { 295 + /* Cloverview Aon */ 296 + PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x08eb), 297 + .driver_data = (kernel_ulong_t)&gpio_cloverview_aon, 298 + }, 299 + { 300 + /* Cloverview Core */ 301 + PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x08f7), 302 + .driver_data = (kernel_ulong_t)&gpio_cloverview_core, 303 + }, 304 + { 305 + /* Tangier */ 306 + PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x1199), 307 + .driver_data = (kernel_ulong_t)&gpio_tangier, 308 + }, 309 + { 0 } 310 + }; 311 + MODULE_DEVICE_TABLE(pci, intel_gpio_ids); 312 + 313 + static void intel_mid_irq_handler(unsigned irq, struct irq_desc *desc) 314 + { 315 + struct irq_data *data = irq_desc_get_irq_data(desc); 316 + struct intel_mid_gpio *priv = irq_data_get_irq_handler_data(data); 317 + struct irq_chip *chip = irq_data_get_irq_chip(data); 318 + u32 base, gpio, mask; 319 + unsigned long pending; 320 + void __iomem *gedr; 321 + 322 + /* check GPIO controller to check which pin triggered the interrupt */ 323 + for (base = 0; base < priv->chip.ngpio; base += 32) { 324 + gedr = gpio_reg(&priv->chip, base, GEDR); 325 + while ((pending = readl(gedr))) { 326 + gpio = __ffs(pending); 327 + mask = BIT(gpio); 328 + /* Clear before handling so we can't lose an edge */ 329 + writel(mask, gedr); 330 + generic_handle_irq(irq_find_mapping(priv->domain, 331 + base + gpio)); 332 + } 333 + } 334 + 335 + chip->irq_eoi(data); 336 + } 337 + 338 + static void intel_mid_irq_init_hw(struct intel_mid_gpio *priv) 339 + { 340 + void __iomem *reg; 341 + unsigned base; 342 + 343 + for (base = 0; base < priv->chip.ngpio; base += 32) { 344 + /* Clear the rising-edge detect register */ 345 + reg = gpio_reg(&priv->chip, base, GRER); 346 + writel(0, reg); 347 + /* Clear the falling-edge detect register */ 348 + reg = gpio_reg(&priv->chip, base, GFER); 349 + writel(0, reg); 350 + /* Clear the edge detect status register */ 351 + reg = gpio_reg(&priv->chip, base, GEDR); 352 + writel(~0, reg); 353 + } 354 + } 355 + 356 + static int intel_gpio_irq_map(struct irq_domain *d, unsigned int irq, 357 + irq_hw_number_t hwirq) 358 + { 359 + struct intel_mid_gpio *priv = d->host_data; 360 + 361 + irq_set_chip_and_handler_name(irq, &intel_mid_irqchip, 362 + handle_simple_irq, "demux"); 363 + irq_set_chip_data(irq, priv); 364 + irq_set_irq_type(irq, IRQ_TYPE_NONE); 365 + 366 + return 0; 367 + } 368 + 369 + static const struct irq_domain_ops intel_gpio_irq_ops = { 370 + .map = intel_gpio_irq_map, 371 + .xlate = irq_domain_xlate_twocell, 372 + }; 373 + 374 + static int intel_gpio_runtime_idle(struct device *dev) 375 + { 376 + pm_schedule_suspend(dev, 500); 377 + return -EBUSY; 378 + } 379 + 380 + static const struct dev_pm_ops intel_gpio_pm_ops = { 381 + SET_RUNTIME_PM_OPS(NULL, NULL, intel_gpio_runtime_idle) 382 + }; 383 + 384 + static int intel_gpio_probe(struct pci_dev *pdev, 385 + const struct pci_device_id *id) 386 + { 387 + void __iomem *base; 388 + struct intel_mid_gpio *priv; 389 + u32 gpio_base; 390 + u32 irq_base; 391 + int retval; 392 + struct intel_mid_gpio_ddata *ddata = 393 + (struct intel_mid_gpio_ddata *)id->driver_data; 394 + 395 + retval = pcim_enable_device(pdev); 396 + if (retval) 397 + return retval; 398 + 399 + retval = pcim_iomap_regions(pdev, 1 << 0 | 1 << 1, pci_name(pdev)); 400 + if (retval) { 401 + dev_err(&pdev->dev, "I/O memory mapping error\n"); 402 + return retval; 403 + } 404 + 405 + base = pcim_iomap_table(pdev)[1]; 406 + 407 + irq_base = readl(base); 408 + gpio_base = readl(sizeof(u32) + base); 409 + 410 + /* release the IO mapping, since we already get the info from bar1 */ 411 + pcim_iounmap_regions(pdev, 1 << 1); 412 + 413 + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); 414 + if (!priv) { 415 + dev_err(&pdev->dev, "can't allocate chip data\n"); 416 + return -ENOMEM; 417 + } 418 + 419 + priv->reg_base = pcim_iomap_table(pdev)[0]; 420 + priv->chip.label = dev_name(&pdev->dev); 421 + priv->chip.request = intel_gpio_request; 422 + priv->chip.direction_input = intel_gpio_direction_input; 423 + priv->chip.direction_output = intel_gpio_direction_output; 424 + priv->chip.get = intel_gpio_get; 425 + priv->chip.set = intel_gpio_set; 426 + priv->chip.to_irq = intel_gpio_to_irq; 427 + priv->chip.base = gpio_base; 428 + priv->chip.ngpio = ddata->ngpio; 429 + priv->chip.can_sleep = 0; 430 + priv->pdev = pdev; 431 + 432 + spin_lock_init(&priv->lock); 433 + 434 + priv->domain = irq_domain_add_simple(pdev->dev.of_node, ddata->ngpio, 435 + irq_base, &intel_gpio_irq_ops, priv); 436 + if (!priv->domain) 437 + return -ENOMEM; 438 + 439 + pci_set_drvdata(pdev, priv); 440 + retval = gpiochip_add(&priv->chip); 441 + if (retval) { 442 + dev_err(&pdev->dev, "gpiochip_add error %d\n", retval); 443 + return retval; 444 + } 445 + 446 + intel_mid_irq_init_hw(priv); 447 + 448 + irq_set_handler_data(pdev->irq, priv); 449 + irq_set_chained_handler(pdev->irq, intel_mid_irq_handler); 450 + 451 + pm_runtime_put_noidle(&pdev->dev); 452 + pm_runtime_allow(&pdev->dev); 453 + 454 + return 0; 455 + } 456 + 457 + static struct pci_driver intel_gpio_driver = { 458 + .name = "intel_mid_gpio", 459 + .id_table = intel_gpio_ids, 460 + .probe = intel_gpio_probe, 461 + .driver = { 462 + .pm = &intel_gpio_pm_ops, 463 + }, 464 + }; 465 + 466 + static int __init intel_gpio_init(void) 467 + { 468 + return pci_register_driver(&intel_gpio_driver); 469 + } 470 + 471 + device_initcall(intel_gpio_init);
-397
drivers/gpio/gpio-langwell.c
··· 1 - /* 2 - * Moorestown platform Langwell chip GPIO driver 3 - * 4 - * Copyright (c) 2008, 2009, 2013, Intel Corporation. 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 version 2 as 8 - * published by the Free Software Foundation. 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 - * You should have received a copy of the GNU General Public License 16 - * along with this program; if not, write to the Free Software 17 - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 - */ 19 - 20 - /* Supports: 21 - * Moorestown platform Langwell chip. 22 - * Medfield platform Penwell chip. 23 - */ 24 - 25 - #include <linux/module.h> 26 - #include <linux/pci.h> 27 - #include <linux/platform_device.h> 28 - #include <linux/kernel.h> 29 - #include <linux/delay.h> 30 - #include <linux/stddef.h> 31 - #include <linux/interrupt.h> 32 - #include <linux/init.h> 33 - #include <linux/irq.h> 34 - #include <linux/io.h> 35 - #include <linux/gpio.h> 36 - #include <linux/slab.h> 37 - #include <linux/pm_runtime.h> 38 - #include <linux/irqdomain.h> 39 - 40 - /* 41 - * Langwell chip has 64 pins and thus there are 2 32bit registers to control 42 - * each feature, while Penwell chip has 96 pins for each block, and need 3 32bit 43 - * registers to control them, so we only define the order here instead of a 44 - * structure, to get a bit offset for a pin (use GPDR as an example): 45 - * 46 - * nreg = ngpio / 32; 47 - * reg = offset / 32; 48 - * bit = offset % 32; 49 - * reg_addr = reg_base + GPDR * nreg * 4 + reg * 4; 50 - * 51 - * so the bit of reg_addr is to control pin offset's GPDR feature 52 - */ 53 - 54 - enum GPIO_REG { 55 - GPLR = 0, /* pin level read-only */ 56 - GPDR, /* pin direction */ 57 - GPSR, /* pin set */ 58 - GPCR, /* pin clear */ 59 - GRER, /* rising edge detect */ 60 - GFER, /* falling edge detect */ 61 - GEDR, /* edge detect result */ 62 - GAFR, /* alt function */ 63 - }; 64 - 65 - struct lnw_gpio { 66 - struct gpio_chip chip; 67 - void __iomem *reg_base; 68 - spinlock_t lock; 69 - struct pci_dev *pdev; 70 - struct irq_domain *domain; 71 - }; 72 - 73 - #define to_lnw_priv(chip) container_of(chip, struct lnw_gpio, chip) 74 - 75 - static void __iomem *gpio_reg(struct gpio_chip *chip, unsigned offset, 76 - enum GPIO_REG reg_type) 77 - { 78 - struct lnw_gpio *lnw = to_lnw_priv(chip); 79 - unsigned nreg = chip->ngpio / 32; 80 - u8 reg = offset / 32; 81 - 82 - return lnw->reg_base + reg_type * nreg * 4 + reg * 4; 83 - } 84 - 85 - static void __iomem *gpio_reg_2bit(struct gpio_chip *chip, unsigned offset, 86 - enum GPIO_REG reg_type) 87 - { 88 - struct lnw_gpio *lnw = to_lnw_priv(chip); 89 - unsigned nreg = chip->ngpio / 32; 90 - u8 reg = offset / 16; 91 - 92 - return lnw->reg_base + reg_type * nreg * 4 + reg * 4; 93 - } 94 - 95 - static int lnw_gpio_request(struct gpio_chip *chip, unsigned offset) 96 - { 97 - void __iomem *gafr = gpio_reg_2bit(chip, offset, GAFR); 98 - u32 value = readl(gafr); 99 - int shift = (offset % 16) << 1, af = (value >> shift) & 3; 100 - 101 - if (af) { 102 - value &= ~(3 << shift); 103 - writel(value, gafr); 104 - } 105 - return 0; 106 - } 107 - 108 - static int lnw_gpio_get(struct gpio_chip *chip, unsigned offset) 109 - { 110 - void __iomem *gplr = gpio_reg(chip, offset, GPLR); 111 - 112 - return readl(gplr) & BIT(offset % 32); 113 - } 114 - 115 - static void lnw_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 116 - { 117 - void __iomem *gpsr, *gpcr; 118 - 119 - if (value) { 120 - gpsr = gpio_reg(chip, offset, GPSR); 121 - writel(BIT(offset % 32), gpsr); 122 - } else { 123 - gpcr = gpio_reg(chip, offset, GPCR); 124 - writel(BIT(offset % 32), gpcr); 125 - } 126 - } 127 - 128 - static int lnw_gpio_direction_input(struct gpio_chip *chip, unsigned offset) 129 - { 130 - struct lnw_gpio *lnw = to_lnw_priv(chip); 131 - void __iomem *gpdr = gpio_reg(chip, offset, GPDR); 132 - u32 value; 133 - unsigned long flags; 134 - 135 - if (lnw->pdev) 136 - pm_runtime_get(&lnw->pdev->dev); 137 - 138 - spin_lock_irqsave(&lnw->lock, flags); 139 - value = readl(gpdr); 140 - value &= ~BIT(offset % 32); 141 - writel(value, gpdr); 142 - spin_unlock_irqrestore(&lnw->lock, flags); 143 - 144 - if (lnw->pdev) 145 - pm_runtime_put(&lnw->pdev->dev); 146 - 147 - return 0; 148 - } 149 - 150 - static int lnw_gpio_direction_output(struct gpio_chip *chip, 151 - unsigned offset, int value) 152 - { 153 - struct lnw_gpio *lnw = to_lnw_priv(chip); 154 - void __iomem *gpdr = gpio_reg(chip, offset, GPDR); 155 - unsigned long flags; 156 - 157 - lnw_gpio_set(chip, offset, value); 158 - 159 - if (lnw->pdev) 160 - pm_runtime_get(&lnw->pdev->dev); 161 - 162 - spin_lock_irqsave(&lnw->lock, flags); 163 - value = readl(gpdr); 164 - value |= BIT(offset % 32); 165 - writel(value, gpdr); 166 - spin_unlock_irqrestore(&lnw->lock, flags); 167 - 168 - if (lnw->pdev) 169 - pm_runtime_put(&lnw->pdev->dev); 170 - 171 - return 0; 172 - } 173 - 174 - static int lnw_gpio_to_irq(struct gpio_chip *chip, unsigned offset) 175 - { 176 - struct lnw_gpio *lnw = to_lnw_priv(chip); 177 - return irq_create_mapping(lnw->domain, offset); 178 - } 179 - 180 - static int lnw_irq_type(struct irq_data *d, unsigned type) 181 - { 182 - struct lnw_gpio *lnw = irq_data_get_irq_chip_data(d); 183 - u32 gpio = irqd_to_hwirq(d); 184 - unsigned long flags; 185 - u32 value; 186 - void __iomem *grer = gpio_reg(&lnw->chip, gpio, GRER); 187 - void __iomem *gfer = gpio_reg(&lnw->chip, gpio, GFER); 188 - 189 - if (gpio >= lnw->chip.ngpio) 190 - return -EINVAL; 191 - 192 - if (lnw->pdev) 193 - pm_runtime_get(&lnw->pdev->dev); 194 - 195 - spin_lock_irqsave(&lnw->lock, flags); 196 - if (type & IRQ_TYPE_EDGE_RISING) 197 - value = readl(grer) | BIT(gpio % 32); 198 - else 199 - value = readl(grer) & (~BIT(gpio % 32)); 200 - writel(value, grer); 201 - 202 - if (type & IRQ_TYPE_EDGE_FALLING) 203 - value = readl(gfer) | BIT(gpio % 32); 204 - else 205 - value = readl(gfer) & (~BIT(gpio % 32)); 206 - writel(value, gfer); 207 - spin_unlock_irqrestore(&lnw->lock, flags); 208 - 209 - if (lnw->pdev) 210 - pm_runtime_put(&lnw->pdev->dev); 211 - 212 - return 0; 213 - } 214 - 215 - static void lnw_irq_unmask(struct irq_data *d) 216 - { 217 - } 218 - 219 - static void lnw_irq_mask(struct irq_data *d) 220 - { 221 - } 222 - 223 - static struct irq_chip lnw_irqchip = { 224 - .name = "LNW-GPIO", 225 - .irq_mask = lnw_irq_mask, 226 - .irq_unmask = lnw_irq_unmask, 227 - .irq_set_type = lnw_irq_type, 228 - }; 229 - 230 - static DEFINE_PCI_DEVICE_TABLE(lnw_gpio_ids) = { /* pin number */ 231 - { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x080f), .driver_data = 64 }, 232 - { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x081f), .driver_data = 96 }, 233 - { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x081a), .driver_data = 96 }, 234 - { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x08eb), .driver_data = 96 }, 235 - { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x08f7), .driver_data = 96 }, 236 - { 0, } 237 - }; 238 - MODULE_DEVICE_TABLE(pci, lnw_gpio_ids); 239 - 240 - static void lnw_irq_handler(unsigned irq, struct irq_desc *desc) 241 - { 242 - struct irq_data *data = irq_desc_get_irq_data(desc); 243 - struct lnw_gpio *lnw = irq_data_get_irq_handler_data(data); 244 - struct irq_chip *chip = irq_data_get_irq_chip(data); 245 - u32 base, gpio, mask; 246 - unsigned long pending; 247 - void __iomem *gedr; 248 - 249 - /* check GPIO controller to check which pin triggered the interrupt */ 250 - for (base = 0; base < lnw->chip.ngpio; base += 32) { 251 - gedr = gpio_reg(&lnw->chip, base, GEDR); 252 - while ((pending = readl(gedr))) { 253 - gpio = __ffs(pending); 254 - mask = BIT(gpio); 255 - /* Clear before handling so we can't lose an edge */ 256 - writel(mask, gedr); 257 - generic_handle_irq(irq_find_mapping(lnw->domain, 258 - base + gpio)); 259 - } 260 - } 261 - 262 - chip->irq_eoi(data); 263 - } 264 - 265 - static void lnw_irq_init_hw(struct lnw_gpio *lnw) 266 - { 267 - void __iomem *reg; 268 - unsigned base; 269 - 270 - for (base = 0; base < lnw->chip.ngpio; base += 32) { 271 - /* Clear the rising-edge detect register */ 272 - reg = gpio_reg(&lnw->chip, base, GRER); 273 - writel(0, reg); 274 - /* Clear the falling-edge detect register */ 275 - reg = gpio_reg(&lnw->chip, base, GFER); 276 - writel(0, reg); 277 - /* Clear the edge detect status register */ 278 - reg = gpio_reg(&lnw->chip, base, GEDR); 279 - writel(~0, reg); 280 - } 281 - } 282 - 283 - static int lnw_gpio_irq_map(struct irq_domain *d, unsigned int virq, 284 - irq_hw_number_t hw) 285 - { 286 - struct lnw_gpio *lnw = d->host_data; 287 - 288 - irq_set_chip_and_handler_name(virq, &lnw_irqchip, handle_simple_irq, 289 - "demux"); 290 - irq_set_chip_data(virq, lnw); 291 - irq_set_irq_type(virq, IRQ_TYPE_NONE); 292 - 293 - return 0; 294 - } 295 - 296 - static const struct irq_domain_ops lnw_gpio_irq_ops = { 297 - .map = lnw_gpio_irq_map, 298 - .xlate = irq_domain_xlate_twocell, 299 - }; 300 - 301 - static int lnw_gpio_runtime_idle(struct device *dev) 302 - { 303 - pm_schedule_suspend(dev, 500); 304 - return -EBUSY; 305 - } 306 - 307 - static const struct dev_pm_ops lnw_gpio_pm_ops = { 308 - SET_RUNTIME_PM_OPS(NULL, NULL, lnw_gpio_runtime_idle) 309 - }; 310 - 311 - static int lnw_gpio_probe(struct pci_dev *pdev, 312 - const struct pci_device_id *id) 313 - { 314 - void __iomem *base; 315 - struct lnw_gpio *lnw; 316 - u32 gpio_base; 317 - u32 irq_base; 318 - int retval; 319 - int ngpio = id->driver_data; 320 - 321 - retval = pcim_enable_device(pdev); 322 - if (retval) 323 - return retval; 324 - 325 - retval = pcim_iomap_regions(pdev, 1 << 0 | 1 << 1, pci_name(pdev)); 326 - if (retval) { 327 - dev_err(&pdev->dev, "I/O memory mapping error\n"); 328 - return retval; 329 - } 330 - 331 - base = pcim_iomap_table(pdev)[1]; 332 - 333 - irq_base = readl(base); 334 - gpio_base = readl(sizeof(u32) + base); 335 - 336 - /* release the IO mapping, since we already get the info from bar1 */ 337 - pcim_iounmap_regions(pdev, 1 << 1); 338 - 339 - lnw = devm_kzalloc(&pdev->dev, sizeof(*lnw), GFP_KERNEL); 340 - if (!lnw) { 341 - dev_err(&pdev->dev, "can't allocate chip data\n"); 342 - return -ENOMEM; 343 - } 344 - 345 - lnw->reg_base = pcim_iomap_table(pdev)[0]; 346 - lnw->chip.label = dev_name(&pdev->dev); 347 - lnw->chip.request = lnw_gpio_request; 348 - lnw->chip.direction_input = lnw_gpio_direction_input; 349 - lnw->chip.direction_output = lnw_gpio_direction_output; 350 - lnw->chip.get = lnw_gpio_get; 351 - lnw->chip.set = lnw_gpio_set; 352 - lnw->chip.to_irq = lnw_gpio_to_irq; 353 - lnw->chip.base = gpio_base; 354 - lnw->chip.ngpio = ngpio; 355 - lnw->chip.can_sleep = 0; 356 - lnw->pdev = pdev; 357 - 358 - spin_lock_init(&lnw->lock); 359 - 360 - lnw->domain = irq_domain_add_simple(pdev->dev.of_node, ngpio, irq_base, 361 - &lnw_gpio_irq_ops, lnw); 362 - if (!lnw->domain) 363 - return -ENOMEM; 364 - 365 - pci_set_drvdata(pdev, lnw); 366 - retval = gpiochip_add(&lnw->chip); 367 - if (retval) { 368 - dev_err(&pdev->dev, "gpiochip_add error %d\n", retval); 369 - return retval; 370 - } 371 - 372 - lnw_irq_init_hw(lnw); 373 - 374 - irq_set_handler_data(pdev->irq, lnw); 375 - irq_set_chained_handler(pdev->irq, lnw_irq_handler); 376 - 377 - pm_runtime_put_noidle(&pdev->dev); 378 - pm_runtime_allow(&pdev->dev); 379 - 380 - return 0; 381 - } 382 - 383 - static struct pci_driver lnw_gpio_driver = { 384 - .name = "langwell_gpio", 385 - .id_table = lnw_gpio_ids, 386 - .probe = lnw_gpio_probe, 387 - .driver = { 388 - .pm = &lnw_gpio_pm_ops, 389 - }, 390 - }; 391 - 392 - static int __init lnw_gpio_init(void) 393 - { 394 - return pci_register_driver(&lnw_gpio_driver); 395 - } 396 - 397 - device_initcall(lnw_gpio_init);
+1
drivers/gpio/gpio-lpc32xx.c
··· 21 21 #include <linux/io.h> 22 22 #include <linux/errno.h> 23 23 #include <linux/gpio.h> 24 + #include <linux/of.h> 24 25 #include <linux/of_gpio.h> 25 26 #include <linux/platform_device.h> 26 27 #include <linux/module.h>
+10 -9
drivers/gpio/gpio-lynxpoint.c
··· 242 242 return irq_create_mapping(lg->domain, offset); 243 243 } 244 244 245 - static void lp_gpio_irq_handler(unsigned irq, struct irq_desc *desc) 245 + static void lp_gpio_irq_handler(unsigned hwirq, struct irq_desc *desc) 246 246 { 247 247 struct irq_data *data = irq_desc_get_irq_data(desc); 248 248 struct lp_gpio *lg = irq_data_get_irq_handler_data(data); 249 249 struct irq_chip *chip = irq_data_get_irq_chip(data); 250 250 u32 base, pin, mask; 251 251 unsigned long reg, ena, pending; 252 - unsigned virq; 253 252 254 253 /* check from GPIO controller which pin triggered the interrupt */ 255 254 for (base = 0; base < lg->chip.ngpio; base += 32) { ··· 256 257 ena = lp_gpio_reg(&lg->chip, base, LP_INT_ENABLE); 257 258 258 259 while ((pending = (inl(reg) & inl(ena)))) { 260 + unsigned irq; 261 + 259 262 pin = __ffs(pending); 260 263 mask = BIT(pin); 261 264 /* Clear before handling so we don't lose an edge */ 262 265 outl(mask, reg); 263 - virq = irq_find_mapping(lg->domain, base + pin); 264 - generic_handle_irq(virq); 266 + irq = irq_find_mapping(lg->domain, base + pin); 267 + generic_handle_irq(irq); 265 268 } 266 269 } 267 270 chip->irq_eoi(data); ··· 326 325 } 327 326 } 328 327 329 - static int lp_gpio_irq_map(struct irq_domain *d, unsigned int virq, 330 - irq_hw_number_t hw) 328 + static int lp_gpio_irq_map(struct irq_domain *d, unsigned int irq, 329 + irq_hw_number_t hwirq) 331 330 { 332 331 struct lp_gpio *lg = d->host_data; 333 332 334 - irq_set_chip_and_handler_name(virq, &lp_irqchip, handle_simple_irq, 333 + irq_set_chip_and_handler_name(irq, &lp_irqchip, handle_simple_irq, 335 334 "demux"); 336 - irq_set_chip_data(virq, lg); 337 - irq_set_irq_type(virq, IRQ_TYPE_NONE); 335 + irq_set_chip_data(irq, lg); 336 + irq_set_irq_type(irq, IRQ_TYPE_NONE); 338 337 339 338 return 0; 340 339 }
-3
drivers/gpio/gpio-mc33880.c
··· 142 142 return ret; 143 143 144 144 exit_destroy: 145 - spi_set_drvdata(spi, NULL); 146 145 mutex_destroy(&mc->lock); 147 146 return ret; 148 147 } ··· 154 155 mc = spi_get_drvdata(spi); 155 156 if (mc == NULL) 156 157 return -ENODEV; 157 - 158 - spi_set_drvdata(spi, NULL); 159 158 160 159 ret = gpiochip_remove(&mc->chip); 161 160 if (!ret)
+4 -4
drivers/gpio/gpio-mpc8xxx.c
··· 282 282 .irq_set_type = mpc8xxx_irq_set_type, 283 283 }; 284 284 285 - static int mpc8xxx_gpio_irq_map(struct irq_domain *h, unsigned int virq, 286 - irq_hw_number_t hw) 285 + static int mpc8xxx_gpio_irq_map(struct irq_domain *h, unsigned int irq, 286 + irq_hw_number_t hwirq) 287 287 { 288 288 struct mpc8xxx_gpio_chip *mpc8xxx_gc = h->host_data; 289 289 290 290 if (mpc8xxx_gc->of_dev_id_data) 291 291 mpc8xxx_irq_chip.irq_set_type = mpc8xxx_gc->of_dev_id_data; 292 292 293 - irq_set_chip_data(virq, h->host_data); 294 - irq_set_chip_and_handler(virq, &mpc8xxx_irq_chip, handle_level_irq); 293 + irq_set_chip_data(irq, h->host_data); 294 + irq_set_chip_and_handler(irq, &mpc8xxx_irq_chip, handle_level_irq); 295 295 296 296 return 0; 297 297 }
+9 -23
drivers/gpio/gpio-mxs.c
··· 254 254 struct device_node *parent; 255 255 static void __iomem *base; 256 256 struct mxs_gpio_port *port; 257 - struct resource *iores = NULL; 258 257 int irq_base; 259 258 int err; 260 259 ··· 261 262 if (!port) 262 263 return -ENOMEM; 263 264 264 - if (np) { 265 - port->id = of_alias_get_id(np, "gpio"); 266 - if (port->id < 0) 267 - return port->id; 268 - port->devid = (enum mxs_gpio_id) of_id->data; 269 - } else { 270 - port->id = pdev->id; 271 - port->devid = pdev->id_entry->driver_data; 272 - } 273 - 265 + port->id = of_alias_get_id(np, "gpio"); 266 + if (port->id < 0) 267 + return port->id; 268 + port->devid = (enum mxs_gpio_id) of_id->data; 274 269 port->irq = platform_get_irq(pdev, 0); 275 270 if (port->irq < 0) 276 271 return port->irq; ··· 274 281 * share the same one 275 282 */ 276 283 if (!base) { 277 - if (np) { 278 - parent = of_get_parent(np); 279 - base = of_iomap(parent, 0); 280 - of_node_put(parent); 281 - if (!base) 282 - return -EADDRNOTAVAIL; 283 - } else { 284 - iores = platform_get_resource(pdev, IORESOURCE_MEM, 0); 285 - base = devm_ioremap_resource(&pdev->dev, iores); 286 - if (IS_ERR(base)) 287 - return PTR_ERR(base); 288 - } 284 + parent = of_get_parent(np); 285 + base = of_iomap(parent, 0); 286 + of_node_put(parent); 287 + if (!base) 288 + return -EADDRNOTAVAIL; 289 289 } 290 290 port->base = base; 291 291
+10 -10
drivers/gpio/gpio-omap.c
··· 514 514 return -EINVAL; 515 515 } 516 516 517 + retval = gpio_lock_as_irq(&bank->chip, offset); 518 + if (retval) { 519 + dev_err(bank->dev, "unable to lock offset %d for IRQ\n", 520 + offset); 521 + spin_unlock_irqrestore(&bank->lock, flags); 522 + return retval; 523 + } 524 + 517 525 bank->irq_usage |= 1 << GPIO_INDEX(bank, gpio); 518 526 spin_unlock_irqrestore(&bank->lock, flags); 519 527 ··· 805 797 unsigned offset = GPIO_INDEX(bank, gpio); 806 798 807 799 spin_lock_irqsave(&bank->lock, flags); 800 + gpio_unlock_as_irq(&bank->chip, offset); 808 801 bank->irq_usage &= ~(1 << offset); 809 802 _disable_gpio_module(bank, offset); 810 803 _reset_gpio(bank, gpio); ··· 966 957 { 967 958 struct gpio_bank *bank; 968 959 unsigned long flags; 969 - int retval = 0; 970 960 971 961 bank = container_of(chip, struct gpio_bank, chip); 972 962 spin_lock_irqsave(&bank->lock, flags); 973 - 974 - if (LINE_USED(bank->irq_usage, offset)) { 975 - retval = -EINVAL; 976 - goto exit; 977 - } 978 - 979 963 bank->set_dataout(bank, offset, value); 980 964 _set_gpio_direction(bank, offset, 0); 981 - 982 - exit: 983 965 spin_unlock_irqrestore(&bank->lock, flags); 984 - return retval; 966 + return 0; 985 967 } 986 968 987 969 static int gpio_debounce(struct gpio_chip *chip, unsigned offset,
+69 -35
drivers/gpio/gpio-palmas.c
··· 31 31 struct palmas *palmas; 32 32 }; 33 33 34 + struct palmas_device_data { 35 + int ngpio; 36 + }; 37 + 34 38 static inline struct palmas_gpio *to_palmas_gpio(struct gpio_chip *chip) 35 39 { 36 40 return container_of(chip, struct palmas_gpio, gpio_chip); ··· 46 42 struct palmas *palmas = pg->palmas; 47 43 unsigned int val; 48 44 int ret; 45 + unsigned int reg; 46 + int gpio16 = (offset/8); 49 47 50 - ret = palmas_read(palmas, PALMAS_GPIO_BASE, PALMAS_GPIO_DATA_DIR, &val); 48 + offset %= 8; 49 + reg = (gpio16) ? PALMAS_GPIO_DATA_DIR2 : PALMAS_GPIO_DATA_DIR; 50 + 51 + ret = palmas_read(palmas, PALMAS_GPIO_BASE, reg, &val); 51 52 if (ret < 0) { 52 - dev_err(gc->dev, "GPIO_DATA_DIR read failed, err = %d\n", ret); 53 + dev_err(gc->dev, "Reg 0x%02x read failed, %d\n", reg, ret); 53 54 return ret; 54 55 } 55 56 56 - if (val & (1 << offset)) { 57 - ret = palmas_read(palmas, PALMAS_GPIO_BASE, 58 - PALMAS_GPIO_DATA_OUT, &val); 59 - } else { 60 - ret = palmas_read(palmas, PALMAS_GPIO_BASE, 61 - PALMAS_GPIO_DATA_IN, &val); 62 - } 57 + if (val & BIT(offset)) 58 + reg = (gpio16) ? PALMAS_GPIO_DATA_OUT2 : PALMAS_GPIO_DATA_OUT; 59 + else 60 + reg = (gpio16) ? PALMAS_GPIO_DATA_IN2 : PALMAS_GPIO_DATA_IN; 61 + 62 + ret = palmas_read(palmas, PALMAS_GPIO_BASE, reg, &val); 63 63 if (ret < 0) { 64 - dev_err(gc->dev, "GPIO_DATA_IN/OUT read failed, err = %d\n", 65 - ret); 64 + dev_err(gc->dev, "Reg 0x%02x read failed, %d\n", reg, ret); 66 65 return ret; 67 66 } 68 67 return !!(val & BIT(offset)); ··· 77 70 struct palmas_gpio *pg = to_palmas_gpio(gc); 78 71 struct palmas *palmas = pg->palmas; 79 72 int ret; 73 + unsigned int reg; 74 + int gpio16 = (offset/8); 80 75 81 - if (value) 82 - ret = palmas_write(palmas, PALMAS_GPIO_BASE, 83 - PALMAS_GPIO_SET_DATA_OUT, BIT(offset)); 76 + offset %= 8; 77 + if (gpio16) 78 + reg = (value) ? 79 + PALMAS_GPIO_SET_DATA_OUT2 : PALMAS_GPIO_CLEAR_DATA_OUT2; 84 80 else 85 - ret = palmas_write(palmas, PALMAS_GPIO_BASE, 86 - PALMAS_GPIO_CLEAR_DATA_OUT, BIT(offset)); 81 + reg = (value) ? 82 + PALMAS_GPIO_SET_DATA_OUT : PALMAS_GPIO_CLEAR_DATA_OUT; 83 + 84 + ret = palmas_write(palmas, PALMAS_GPIO_BASE, reg, BIT(offset)); 87 85 if (ret < 0) 88 - dev_err(gc->dev, "%s write failed, err = %d\n", 89 - (value) ? "GPIO_SET_DATA_OUT" : "GPIO_CLEAR_DATA_OUT", 90 - ret); 86 + dev_err(gc->dev, "Reg 0x%02x write failed, %d\n", reg, ret); 91 87 } 92 88 93 89 static int palmas_gpio_output(struct gpio_chip *gc, unsigned offset, ··· 99 89 struct palmas_gpio *pg = to_palmas_gpio(gc); 100 90 struct palmas *palmas = pg->palmas; 101 91 int ret; 92 + unsigned int reg; 93 + int gpio16 = (offset/8); 94 + 95 + offset %= 8; 96 + reg = (gpio16) ? PALMAS_GPIO_DATA_DIR2 : PALMAS_GPIO_DATA_DIR; 102 97 103 98 /* Set the initial value */ 104 99 palmas_gpio_set(gc, offset, value); 105 100 106 - ret = palmas_update_bits(palmas, PALMAS_GPIO_BASE, 107 - PALMAS_GPIO_DATA_DIR, BIT(offset), BIT(offset)); 101 + ret = palmas_update_bits(palmas, PALMAS_GPIO_BASE, reg, 102 + BIT(offset), BIT(offset)); 108 103 if (ret < 0) 109 - dev_err(gc->dev, "GPIO_DATA_DIR write failed, err = %d\n", ret); 104 + dev_err(gc->dev, "Reg 0x%02x update failed, %d\n", reg, ret); 110 105 return ret; 111 106 } 112 107 ··· 120 105 struct palmas_gpio *pg = to_palmas_gpio(gc); 121 106 struct palmas *palmas = pg->palmas; 122 107 int ret; 108 + unsigned int reg; 109 + int gpio16 = (offset/8); 123 110 124 - ret = palmas_update_bits(palmas, PALMAS_GPIO_BASE, 125 - PALMAS_GPIO_DATA_DIR, BIT(offset), 0); 111 + offset %= 8; 112 + reg = (gpio16) ? PALMAS_GPIO_DATA_DIR2 : PALMAS_GPIO_DATA_DIR; 113 + 114 + ret = palmas_update_bits(palmas, PALMAS_GPIO_BASE, reg, BIT(offset), 0); 126 115 if (ret < 0) 127 - dev_err(gc->dev, "GPIO_DATA_DIR write failed, err = %d\n", ret); 116 + dev_err(gc->dev, "Reg 0x%02x update failed, %d\n", reg, ret); 128 117 return ret; 129 118 } 130 119 ··· 140 121 return palmas_irq_get_virq(palmas, PALMAS_GPIO_0_IRQ + offset); 141 122 } 142 123 124 + static const struct palmas_device_data palmas_dev_data = { 125 + .ngpio = 8, 126 + }; 127 + 128 + static const struct palmas_device_data tps80036_dev_data = { 129 + .ngpio = 16, 130 + }; 131 + 132 + static struct of_device_id of_palmas_gpio_match[] = { 133 + { .compatible = "ti,palmas-gpio", .data = &palmas_dev_data,}, 134 + { .compatible = "ti,tps65913-gpio", .data = &palmas_dev_data,}, 135 + { .compatible = "ti,tps65914-gpio", .data = &palmas_dev_data,}, 136 + { .compatible = "ti,tps80036-gpio", .data = &tps80036_dev_data,}, 137 + { }, 138 + }; 139 + MODULE_DEVICE_TABLE(of, of_palmas_gpio_match); 140 + 143 141 static int palmas_gpio_probe(struct platform_device *pdev) 144 142 { 145 143 struct palmas *palmas = dev_get_drvdata(pdev->dev.parent); 146 144 struct palmas_platform_data *palmas_pdata; 147 145 struct palmas_gpio *palmas_gpio; 148 146 int ret; 147 + const struct of_device_id *match; 148 + const struct palmas_device_data *dev_data; 149 + 150 + match = of_match_device(of_palmas_gpio_match, &pdev->dev); 151 + dev_data = match->data; 152 + if (!dev_data) 153 + dev_data = &palmas_dev_data; 149 154 150 155 palmas_gpio = devm_kzalloc(&pdev->dev, 151 156 sizeof(*palmas_gpio), GFP_KERNEL); ··· 181 138 palmas_gpio->palmas = palmas; 182 139 palmas_gpio->gpio_chip.owner = THIS_MODULE; 183 140 palmas_gpio->gpio_chip.label = dev_name(&pdev->dev); 184 - palmas_gpio->gpio_chip.ngpio = 8; 141 + palmas_gpio->gpio_chip.ngpio = dev_data->ngpio; 185 142 palmas_gpio->gpio_chip.can_sleep = 1; 186 143 palmas_gpio->gpio_chip.direction_input = palmas_gpio_input; 187 144 palmas_gpio->gpio_chip.direction_output = palmas_gpio_output; ··· 214 171 215 172 return gpiochip_remove(&palmas_gpio->gpio_chip); 216 173 } 217 - 218 - static struct of_device_id of_palmas_gpio_match[] = { 219 - { .compatible = "ti,palmas-gpio"}, 220 - { .compatible = "ti,tps65913-gpio"}, 221 - { .compatible = "ti,tps65914-gpio"}, 222 - { .compatible = "ti,tps80036-gpio"}, 223 - { }, 224 - }; 225 - MODULE_DEVICE_TABLE(of, of_palmas_gpio_match); 226 174 227 175 static struct platform_driver palmas_gpio_driver = { 228 176 .driver.name = "palmas-gpio",
-11
drivers/gpio/gpio-pca953x.c
··· 683 683 int ret; 684 684 u8 val[MAX_BANK]; 685 685 686 - /* Let every port in proper state, that could save power */ 687 - memset(val, 0, NBANK(chip)); 688 - pca953x_write_regs(chip, PCA957X_PUPD, val); 689 - memset(val, 0xFF, NBANK(chip)); 690 - pca953x_write_regs(chip, PCA957X_CFG, val); 691 - memset(val, 0, NBANK(chip)); 692 - pca953x_write_regs(chip, PCA957X_OUT, val); 693 - 694 - ret = pca953x_read_regs(chip, PCA957X_IN, val); 695 - if (ret) 696 - goto out; 697 686 ret = pca953x_read_regs(chip, PCA957X_OUT, chip->reg_output); 698 687 if (ret) 699 688 goto out;
+68 -37
drivers/gpio/gpio-pcf857x.c
··· 26 26 #include <linux/irqdomain.h> 27 27 #include <linux/kernel.h> 28 28 #include <linux/module.h> 29 + #include <linux/of.h> 30 + #include <linux/of_device.h> 29 31 #include <linux/slab.h> 30 32 #include <linux/spinlock.h> 31 - #include <linux/workqueue.h> 32 33 33 34 34 35 static const struct i2c_device_id pcf857x_id[] = { ··· 51 50 }; 52 51 MODULE_DEVICE_TABLE(i2c, pcf857x_id); 53 52 53 + #ifdef CONFIG_OF 54 + static const struct of_device_id pcf857x_of_table[] = { 55 + { .compatible = "nxp,pcf8574" }, 56 + { .compatible = "nxp,pcf8574a" }, 57 + { .compatible = "nxp,pca8574" }, 58 + { .compatible = "nxp,pca9670" }, 59 + { .compatible = "nxp,pca9672" }, 60 + { .compatible = "nxp,pca9674" }, 61 + { .compatible = "nxp,pcf8575" }, 62 + { .compatible = "nxp,pca8575" }, 63 + { .compatible = "nxp,pca9671" }, 64 + { .compatible = "nxp,pca9673" }, 65 + { .compatible = "nxp,pca9675" }, 66 + { .compatible = "maxim,max7328" }, 67 + { .compatible = "maxim,max7329" }, 68 + { .compatible = "ti,tca9554" }, 69 + { } 70 + }; 71 + MODULE_DEVICE_TABLE(of, pcf857x_of_table); 72 + #endif 73 + 54 74 /* 55 75 * The pcf857x, pca857x, and pca967x chips only expose one read and one 56 76 * write register. Writing a "one" bit (to match the reset state) lets ··· 88 66 struct gpio_chip chip; 89 67 struct i2c_client *client; 90 68 struct mutex lock; /* protect 'out' */ 91 - struct work_struct work; /* irq demux work */ 92 69 struct irq_domain *irq_domain; /* for irq demux */ 93 70 spinlock_t slock; /* protect irq demux */ 94 71 unsigned out; /* software latch */ 95 72 unsigned status; /* current status */ 96 - int irq; /* real irq number */ 73 + unsigned irq_mapped; /* mapped gpio irqs */ 97 74 98 75 int (*write)(struct i2c_client *client, unsigned data); 99 76 int (*read)(struct i2c_client *client); ··· 185 164 static int pcf857x_to_irq(struct gpio_chip *chip, unsigned offset) 186 165 { 187 166 struct pcf857x *gpio = container_of(chip, struct pcf857x, chip); 167 + int ret; 188 168 189 - return irq_create_mapping(gpio->irq_domain, offset); 169 + ret = irq_create_mapping(gpio->irq_domain, offset); 170 + if (ret > 0) 171 + gpio->irq_mapped |= (1 << offset); 172 + 173 + return ret; 190 174 } 191 175 192 - static void pcf857x_irq_demux_work(struct work_struct *work) 176 + static irqreturn_t pcf857x_irq(int irq, void *data) 193 177 { 194 - struct pcf857x *gpio = container_of(work, 195 - struct pcf857x, 196 - work); 178 + struct pcf857x *gpio = data; 197 179 unsigned long change, i, status, flags; 198 180 199 181 status = gpio->read(gpio->client); 200 182 201 183 spin_lock_irqsave(&gpio->slock, flags); 202 184 203 - change = gpio->status ^ status; 185 + /* 186 + * call the interrupt handler iff gpio is used as 187 + * interrupt source, just to avoid bad irqs 188 + */ 189 + 190 + change = ((gpio->status ^ status) & gpio->irq_mapped); 204 191 for_each_set_bit(i, &change, gpio->chip.ngpio) 205 192 generic_handle_irq(irq_find_mapping(gpio->irq_domain, i)); 206 193 gpio->status = status; 207 194 208 195 spin_unlock_irqrestore(&gpio->slock, flags); 209 - } 210 - 211 - static irqreturn_t pcf857x_irq_demux(int irq, void *data) 212 - { 213 - struct pcf857x *gpio = data; 214 - 215 - /* 216 - * pcf857x can't read/write data here, 217 - * since i2c data access might go to sleep. 218 - */ 219 - schedule_work(&gpio->work); 220 196 221 197 return IRQ_HANDLED; 222 198 } 223 199 224 - static int pcf857x_irq_domain_map(struct irq_domain *domain, unsigned int virq, 200 + static int pcf857x_irq_domain_map(struct irq_domain *domain, unsigned int irq, 225 201 irq_hw_number_t hw) 226 202 { 227 - irq_set_chip_and_handler(virq, 203 + struct pcf857x *gpio = domain->host_data; 204 + 205 + irq_set_chip_and_handler(irq, 228 206 &dummy_irq_chip, 229 207 handle_level_irq); 208 + #ifdef CONFIG_ARM 209 + set_irq_flags(irq, IRQF_VALID); 210 + #else 211 + irq_set_noprobe(irq); 212 + #endif 213 + gpio->irq_mapped |= (1 << hw); 214 + 230 215 return 0; 231 216 } 232 217 ··· 245 218 if (gpio->irq_domain) 246 219 irq_domain_remove(gpio->irq_domain); 247 220 248 - if (gpio->irq) 249 - free_irq(gpio->irq, gpio); 250 221 } 251 222 252 223 static int pcf857x_irq_domain_init(struct pcf857x *gpio, ··· 255 230 gpio->irq_domain = irq_domain_add_linear(client->dev.of_node, 256 231 gpio->chip.ngpio, 257 232 &pcf857x_irq_domain_ops, 258 - NULL); 233 + gpio); 259 234 if (!gpio->irq_domain) 260 235 goto fail; 261 236 262 237 /* enable real irq */ 263 - status = request_irq(client->irq, pcf857x_irq_demux, 0, 264 - dev_name(&client->dev), gpio); 238 + status = devm_request_threaded_irq(&client->dev, client->irq, 239 + NULL, pcf857x_irq, IRQF_ONESHOT | 240 + IRQF_TRIGGER_FALLING, 241 + dev_name(&client->dev), gpio); 242 + 265 243 if (status) 266 244 goto fail; 267 245 268 246 /* enable gpio_to_irq() */ 269 - INIT_WORK(&gpio->work, pcf857x_irq_demux_work); 270 247 gpio->chip.to_irq = pcf857x_to_irq; 271 - gpio->irq = client->irq; 272 248 273 249 return 0; 274 250 ··· 283 257 static int pcf857x_probe(struct i2c_client *client, 284 258 const struct i2c_device_id *id) 285 259 { 286 - struct pcf857x_platform_data *pdata; 260 + struct pcf857x_platform_data *pdata = dev_get_platdata(&client->dev); 261 + struct device_node *np = client->dev.of_node; 287 262 struct pcf857x *gpio; 263 + unsigned int n_latch = 0; 288 264 int status; 289 265 290 - pdata = dev_get_platdata(&client->dev); 291 - if (!pdata) { 266 + if (IS_ENABLED(CONFIG_OF) && np) 267 + of_property_read_u32(np, "lines-initial-states", &n_latch); 268 + else if (pdata) 269 + n_latch = pdata->n_latch; 270 + else 292 271 dev_dbg(&client->dev, "no platform data\n"); 293 - } 294 272 295 273 /* Allocate, initialize, and register this gpio_chip. */ 296 274 gpio = devm_kzalloc(&client->dev, sizeof(*gpio), GFP_KERNEL); ··· 387 357 * may cause transient glitching since it can't know the last value 388 358 * written (some pins may need to be driven low). 389 359 * 390 - * Using pdata->n_latch avoids that trouble. When left initialized 391 - * to zero, our software copy of the "latch" then matches the chip's 392 - * all-ones reset state. Otherwise it flags pins to be driven low. 360 + * Using n_latch avoids that trouble. When left initialized to zero, 361 + * our software copy of the "latch" then matches the chip's all-ones 362 + * reset state. Otherwise it flags pins to be driven low. 393 363 */ 394 - gpio->out = pdata ? ~pdata->n_latch : ~0; 364 + gpio->out = ~n_latch; 395 365 gpio->status = gpio->out; 396 366 397 367 status = gpiochip_add(&gpio->chip); ··· 453 423 .driver = { 454 424 .name = "pcf857x", 455 425 .owner = THIS_MODULE, 426 + .of_match_table = of_match_ptr(pcf857x_of_table), 456 427 }, 457 428 .probe = pcf857x_probe, 458 429 .remove = pcf857x_remove,
+5 -5
drivers/gpio/gpio-pl061.c
··· 238 238 .irq_set_type = pl061_irq_type, 239 239 }; 240 240 241 - static int pl061_irq_map(struct irq_domain *d, unsigned int virq, 242 - irq_hw_number_t hw) 241 + static int pl061_irq_map(struct irq_domain *d, unsigned int irq, 242 + irq_hw_number_t hwirq) 243 243 { 244 244 struct pl061_gpio *chip = d->host_data; 245 245 246 - irq_set_chip_and_handler_name(virq, &pl061_irqchip, handle_simple_irq, 246 + irq_set_chip_and_handler_name(irq, &pl061_irqchip, handle_simple_irq, 247 247 "pl061"); 248 - irq_set_chip_data(virq, chip); 249 - irq_set_irq_type(virq, IRQ_TYPE_NONE); 248 + irq_set_chip_data(irq, chip); 249 + irq_set_irq_type(irq, IRQ_TYPE_NONE); 250 250 251 251 return 0; 252 252 }
+7 -6
drivers/gpio/gpio-rcar.c
··· 22 22 #include <linux/irq.h> 23 23 #include <linux/irqdomain.h> 24 24 #include <linux/module.h> 25 + #include <linux/of.h> 25 26 #include <linux/pinctrl/consumer.h> 26 27 #include <linux/platform_data/gpio-rcar.h> 27 28 #include <linux/platform_device.h> ··· 267 266 return irq_create_mapping(gpio_to_priv(chip)->irq_domain, offset); 268 267 } 269 268 270 - static int gpio_rcar_irq_domain_map(struct irq_domain *h, unsigned int virq, 271 - irq_hw_number_t hw) 269 + static int gpio_rcar_irq_domain_map(struct irq_domain *h, unsigned int irq, 270 + irq_hw_number_t hwirq) 272 271 { 273 272 struct gpio_rcar_priv *p = h->host_data; 274 273 275 - dev_dbg(&p->pdev->dev, "map hw irq = %d, virq = %d\n", (int)hw, virq); 274 + dev_dbg(&p->pdev->dev, "map hw irq = %d, irq = %d\n", (int)hwirq, irq); 276 275 277 - irq_set_chip_data(virq, h->host_data); 278 - irq_set_chip_and_handler(virq, &p->irq_chip, handle_level_irq); 279 - set_irq_flags(virq, IRQF_VALID); /* kill me now */ 276 + irq_set_chip_data(irq, h->host_data); 277 + irq_set_chip_and_handler(irq, &p->irq_chip, handle_level_irq); 278 + set_irq_flags(irq, IRQF_VALID); /* kill me now */ 280 279 return 0; 281 280 } 282 281
+13 -12
drivers/gpio/gpio-stmpe.c
··· 254 254 while (stat) { 255 255 int bit = __ffs(stat); 256 256 int line = bank * 8 + bit; 257 - int virq = irq_find_mapping(stmpe_gpio->domain, line); 257 + int child_irq = irq_find_mapping(stmpe_gpio->domain, 258 + line); 258 259 259 - handle_nested_irq(virq); 260 + handle_nested_irq(child_irq); 260 261 stat &= ~(1 << bit); 261 262 } 262 263 ··· 272 271 return IRQ_HANDLED; 273 272 } 274 273 275 - static int stmpe_gpio_irq_map(struct irq_domain *d, unsigned int virq, 274 + static int stmpe_gpio_irq_map(struct irq_domain *d, unsigned int irq, 276 275 irq_hw_number_t hwirq) 277 276 { 278 277 struct stmpe_gpio *stmpe_gpio = d->host_data; ··· 280 279 if (!stmpe_gpio) 281 280 return -EINVAL; 282 281 283 - irq_set_chip_data(hwirq, stmpe_gpio); 284 - irq_set_chip_and_handler(hwirq, &stmpe_gpio_irq_chip, 282 + irq_set_chip_data(irq, stmpe_gpio); 283 + irq_set_chip_and_handler(irq, &stmpe_gpio_irq_chip, 285 284 handle_simple_irq); 286 - irq_set_nested_thread(hwirq, 1); 285 + irq_set_nested_thread(irq, 1); 287 286 #ifdef CONFIG_ARM 288 - set_irq_flags(hwirq, IRQF_VALID); 287 + set_irq_flags(irq, IRQF_VALID); 289 288 #else 290 - irq_set_noprobe(hwirq); 289 + irq_set_noprobe(irq); 291 290 #endif 292 291 293 292 return 0; 294 293 } 295 294 296 - static void stmpe_gpio_irq_unmap(struct irq_domain *d, unsigned int virq) 295 + static void stmpe_gpio_irq_unmap(struct irq_domain *d, unsigned int irq) 297 296 { 298 297 #ifdef CONFIG_ARM 299 - set_irq_flags(virq, 0); 298 + set_irq_flags(irq, 0); 300 299 #endif 301 - irq_set_chip_and_handler(virq, NULL, NULL); 302 - irq_set_chip_data(virq, NULL); 300 + irq_set_chip_and_handler(irq, NULL, NULL); 301 + irq_set_chip_data(irq, NULL); 303 302 } 304 303 305 304 static const struct irq_domain_ops stmpe_gpio_irq_simple_ops = {
+18 -18
drivers/gpio/gpio-tc3589x.c
··· 96 96 } 97 97 98 98 /** 99 - * tc3589x_gpio_irq_get_virq(): Map an interrupt on a chip to a virtual IRQ 99 + * tc3589x_gpio_irq_get_irq(): Map a hardware IRQ on a chip to a Linux IRQ 100 100 * 101 101 * @tc3589x_gpio: tc3589x_gpio_irq controller to operate on. 102 - * @irq: index of the interrupt requested in the chip IRQs 102 + * @irq: index of the hardware interrupt requested in the chip IRQs 103 103 * 104 104 * Useful for drivers to request their own IRQs. 105 105 */ 106 - static int tc3589x_gpio_irq_get_virq(struct tc3589x_gpio *tc3589x_gpio, 107 - int irq) 106 + static int tc3589x_gpio_irq_get_irq(struct tc3589x_gpio *tc3589x_gpio, 107 + int hwirq) 108 108 { 109 109 if (!tc3589x_gpio) 110 110 return -EINVAL; 111 111 112 - return irq_create_mapping(tc3589x_gpio->domain, irq); 112 + return irq_create_mapping(tc3589x_gpio->domain, hwirq); 113 113 } 114 114 115 115 static int tc3589x_gpio_to_irq(struct gpio_chip *chip, unsigned offset) 116 116 { 117 117 struct tc3589x_gpio *tc3589x_gpio = to_tc3589x_gpio(chip); 118 118 119 - return tc3589x_gpio_irq_get_virq(tc3589x_gpio, offset); 119 + return tc3589x_gpio_irq_get_irq(tc3589x_gpio, offset); 120 120 } 121 121 122 122 static struct gpio_chip template_chip = { ··· 242 242 while (stat) { 243 243 int bit = __ffs(stat); 244 244 int line = i * 8 + bit; 245 - int virq = tc3589x_gpio_irq_get_virq(tc3589x_gpio, line); 245 + int irq = tc3589x_gpio_irq_get_irq(tc3589x_gpio, line); 246 246 247 - handle_nested_irq(virq); 247 + handle_nested_irq(irq); 248 248 stat &= ~(1 << bit); 249 249 } 250 250 ··· 254 254 return IRQ_HANDLED; 255 255 } 256 256 257 - static int tc3589x_gpio_irq_map(struct irq_domain *d, unsigned int virq, 257 + static int tc3589x_gpio_irq_map(struct irq_domain *d, unsigned int irq, 258 258 irq_hw_number_t hwirq) 259 259 { 260 260 struct tc3589x *tc3589x_gpio = d->host_data; 261 261 262 - irq_set_chip_data(virq, tc3589x_gpio); 263 - irq_set_chip_and_handler(virq, &tc3589x_gpio_irq_chip, 262 + irq_set_chip_data(irq, tc3589x_gpio); 263 + irq_set_chip_and_handler(irq, &tc3589x_gpio_irq_chip, 264 264 handle_simple_irq); 265 - irq_set_nested_thread(virq, 1); 265 + irq_set_nested_thread(irq, 1); 266 266 #ifdef CONFIG_ARM 267 - set_irq_flags(virq, IRQF_VALID); 267 + set_irq_flags(irq, IRQF_VALID); 268 268 #else 269 - irq_set_noprobe(virq); 269 + irq_set_noprobe(irq); 270 270 #endif 271 271 272 272 return 0; 273 273 } 274 274 275 - static void tc3589x_gpio_irq_unmap(struct irq_domain *d, unsigned int virq) 275 + static void tc3589x_gpio_irq_unmap(struct irq_domain *d, unsigned int irq) 276 276 { 277 277 #ifdef CONFIG_ARM 278 - set_irq_flags(virq, 0); 278 + set_irq_flags(irq, 0); 279 279 #endif 280 - irq_set_chip_and_handler(virq, NULL, NULL); 281 - irq_set_chip_data(virq, NULL); 280 + irq_set_chip_and_handler(irq, NULL, NULL); 281 + irq_set_chip_data(irq, NULL); 282 282 } 283 283 284 284 static struct irq_domain_ops tc3589x_irq_ops = {
+18
drivers/gpio/gpio-tegra.c
··· 75 75 #endif 76 76 }; 77 77 78 + static struct device *dev; 78 79 static struct irq_domain *irq_domain; 79 80 static void __iomem *regs; 80 81 static u32 tegra_gpio_bank_count; ··· 206 205 int lvl_type; 207 206 int val; 208 207 unsigned long flags; 208 + int ret; 209 209 210 210 switch (type & IRQ_TYPE_SENSE_MASK) { 211 211 case IRQ_TYPE_EDGE_RISING: ··· 233 231 return -EINVAL; 234 232 } 235 233 234 + ret = gpio_lock_as_irq(&tegra_gpio_chip, gpio); 235 + if (ret) { 236 + dev_err(dev, "unable to lock Tegra GPIO %d as IRQ\n", gpio); 237 + return ret; 238 + } 239 + 236 240 spin_lock_irqsave(&bank->lvl_lock[port], flags); 237 241 238 242 val = tegra_gpio_readl(GPIO_INT_LVL(gpio)); ··· 257 249 __irq_set_handler_locked(d->irq, handle_edge_irq); 258 250 259 251 return 0; 252 + } 253 + 254 + static void tegra_gpio_irq_shutdown(struct irq_data *d) 255 + { 256 + int gpio = d->hwirq; 257 + 258 + gpio_unlock_as_irq(&tegra_gpio_chip, gpio); 260 259 } 261 260 262 261 static void tegra_gpio_irq_handler(unsigned int irq, struct irq_desc *desc) ··· 383 368 .irq_mask = tegra_gpio_irq_mask, 384 369 .irq_unmask = tegra_gpio_irq_unmask, 385 370 .irq_set_type = tegra_gpio_irq_set_type, 371 + .irq_shutdown = tegra_gpio_irq_shutdown, 386 372 #ifdef CONFIG_PM_SLEEP 387 373 .irq_set_wake = tegra_gpio_irq_set_wake, 388 374 #endif ··· 428 412 int gpio; 429 413 int i; 430 414 int j; 415 + 416 + dev = &pdev->dev; 431 417 432 418 match = of_match_device(tegra_gpio_of_match, &pdev->dev); 433 419 if (!match) {
+1 -1
drivers/gpio/gpio-twl4030.c
··· 594 594 .driver = { 595 595 .name = "twl4030_gpio", 596 596 .owner = THIS_MODULE, 597 - .of_match_table = of_match_ptr(twl_gpio_match), 597 + .of_match_table = twl_gpio_match, 598 598 }, 599 599 .probe = gpio_twl4030_probe, 600 600 .remove = gpio_twl4030_remove,
+90 -96
drivers/gpio/gpiolib-acpi.c
··· 11 11 */ 12 12 13 13 #include <linux/errno.h> 14 - #include <linux/gpio.h> 14 + #include <linux/gpio/consumer.h> 15 15 #include <linux/export.h> 16 16 #include <linux/acpi_gpio.h> 17 17 #include <linux/acpi.h> ··· 33 33 } 34 34 35 35 /** 36 - * acpi_get_gpio() - Translate ACPI GPIO pin to GPIO number usable with GPIO API 36 + * acpi_get_gpiod() - Translate ACPI GPIO pin to GPIO descriptor usable with GPIO API 37 37 * @path: ACPI GPIO controller full path name, (e.g. "\\_SB.GPO1") 38 38 * @pin: ACPI GPIO pin number (0-based, controller-relative) 39 39 * 40 - * Returns GPIO number to use with Linux generic GPIO API, or errno error value 40 + * Returns GPIO descriptor to use with Linux generic GPIO API, or ERR_PTR 41 + * error value 41 42 */ 42 43 43 - int acpi_get_gpio(char *path, int pin) 44 + static struct gpio_desc *acpi_get_gpiod(char *path, int pin) 44 45 { 45 46 struct gpio_chip *chip; 46 47 acpi_handle handle; ··· 49 48 50 49 status = acpi_get_handle(NULL, path, &handle); 51 50 if (ACPI_FAILURE(status)) 52 - return -ENODEV; 51 + return ERR_PTR(-ENODEV); 53 52 54 53 chip = gpiochip_find(handle, acpi_gpiochip_find); 55 54 if (!chip) 56 - return -ENODEV; 55 + return ERR_PTR(-ENODEV); 57 56 58 - if (!gpio_is_valid(chip->base + pin)) 59 - return -EINVAL; 57 + if (pin < 0 || pin > chip->ngpio) 58 + return ERR_PTR(-EINVAL); 60 59 61 - return chip->base + pin; 60 + return gpio_to_desc(chip->base + pin); 62 61 } 63 - EXPORT_SYMBOL_GPL(acpi_get_gpio); 64 62 65 63 static irqreturn_t acpi_gpio_irq_handler(int irq, void *data) 66 64 { ··· 73 73 static irqreturn_t acpi_gpio_irq_handler_evt(int irq, void *data) 74 74 { 75 75 struct acpi_gpio_evt_pin *evt_pin = data; 76 - struct acpi_object_list args; 77 - union acpi_object arg; 78 76 79 - arg.type = ACPI_TYPE_INTEGER; 80 - arg.integer.value = evt_pin->pin; 81 - args.count = 1; 82 - args.pointer = &arg; 83 - 84 - acpi_evaluate_object(evt_pin->evt_handle, NULL, &args, NULL); 77 + acpi_execute_simple_method(evt_pin->evt_handle, NULL, evt_pin->pin); 85 78 86 79 return IRQ_HANDLED; 87 80 } ··· 194 201 } 195 202 EXPORT_SYMBOL(acpi_gpiochip_request_interrupts); 196 203 197 - struct acpi_gpio_lookup { 198 - struct acpi_gpio_info info; 199 - int index; 200 - int gpio; 201 - int n; 202 - }; 203 - 204 - static int acpi_find_gpio(struct acpi_resource *ares, void *data) 205 - { 206 - struct acpi_gpio_lookup *lookup = data; 207 - 208 - if (ares->type != ACPI_RESOURCE_TYPE_GPIO) 209 - return 1; 210 - 211 - if (lookup->n++ == lookup->index && lookup->gpio < 0) { 212 - const struct acpi_resource_gpio *agpio = &ares->data.gpio; 213 - 214 - lookup->gpio = acpi_get_gpio(agpio->resource_source.string_ptr, 215 - agpio->pin_table[0]); 216 - lookup->info.gpioint = 217 - agpio->connection_type == ACPI_RESOURCE_GPIO_TYPE_INT; 218 - } 219 - 220 - return 1; 221 - } 222 - 223 - /** 224 - * acpi_get_gpio_by_index() - get a GPIO number from device resources 225 - * @dev: pointer to a device to get GPIO from 226 - * @index: index of GpioIo/GpioInt resource (starting from %0) 227 - * @info: info pointer to fill in (optional) 228 - * 229 - * Function goes through ACPI resources for @dev and based on @index looks 230 - * up a GpioIo/GpioInt resource, translates it to the Linux GPIO number, 231 - * and returns it. @index matches GpioIo/GpioInt resources only so if there 232 - * are total %3 GPIO resources, the index goes from %0 to %2. 233 - * 234 - * If the GPIO cannot be translated or there is an error, negative errno is 235 - * returned. 236 - * 237 - * Note: if the GPIO resource has multiple entries in the pin list, this 238 - * function only returns the first. 239 - */ 240 - int acpi_get_gpio_by_index(struct device *dev, int index, 241 - struct acpi_gpio_info *info) 242 - { 243 - struct acpi_gpio_lookup lookup; 244 - struct list_head resource_list; 245 - struct acpi_device *adev; 246 - acpi_handle handle; 247 - int ret; 248 - 249 - if (!dev) 250 - return -EINVAL; 251 - 252 - handle = ACPI_HANDLE(dev); 253 - if (!handle || acpi_bus_get_device(handle, &adev)) 254 - return -ENODEV; 255 - 256 - memset(&lookup, 0, sizeof(lookup)); 257 - lookup.index = index; 258 - lookup.gpio = -ENODEV; 259 - 260 - INIT_LIST_HEAD(&resource_list); 261 - ret = acpi_dev_get_resources(adev, &resource_list, acpi_find_gpio, 262 - &lookup); 263 - if (ret < 0) 264 - return ret; 265 - 266 - acpi_dev_free_resource_list(&resource_list); 267 - 268 - if (lookup.gpio >= 0 && info) 269 - *info = lookup.info; 270 - 271 - return lookup.gpio; 272 - } 273 - EXPORT_SYMBOL_GPL(acpi_get_gpio_by_index); 274 - 275 204 /** 276 205 * acpi_gpiochip_free_interrupts() - Free GPIO _EVT ACPI event interrupts. 277 206 * @chip: gpio chip ··· 231 316 kfree(evt_pins); 232 317 } 233 318 EXPORT_SYMBOL(acpi_gpiochip_free_interrupts); 319 + 320 + struct acpi_gpio_lookup { 321 + struct acpi_gpio_info info; 322 + int index; 323 + struct gpio_desc *desc; 324 + int n; 325 + }; 326 + 327 + static int acpi_find_gpio(struct acpi_resource *ares, void *data) 328 + { 329 + struct acpi_gpio_lookup *lookup = data; 330 + 331 + if (ares->type != ACPI_RESOURCE_TYPE_GPIO) 332 + return 1; 333 + 334 + if (lookup->n++ == lookup->index && !lookup->desc) { 335 + const struct acpi_resource_gpio *agpio = &ares->data.gpio; 336 + 337 + lookup->desc = acpi_get_gpiod(agpio->resource_source.string_ptr, 338 + agpio->pin_table[0]); 339 + lookup->info.gpioint = 340 + agpio->connection_type == ACPI_RESOURCE_GPIO_TYPE_INT; 341 + lookup->info.active_low = 342 + agpio->polarity == ACPI_ACTIVE_LOW; 343 + } 344 + 345 + return 1; 346 + } 347 + 348 + /** 349 + * acpi_get_gpiod_by_index() - get a GPIO descriptor from device resources 350 + * @dev: pointer to a device to get GPIO from 351 + * @index: index of GpioIo/GpioInt resource (starting from %0) 352 + * @info: info pointer to fill in (optional) 353 + * 354 + * Function goes through ACPI resources for @dev and based on @index looks 355 + * up a GpioIo/GpioInt resource, translates it to the Linux GPIO descriptor, 356 + * and returns it. @index matches GpioIo/GpioInt resources only so if there 357 + * are total %3 GPIO resources, the index goes from %0 to %2. 358 + * 359 + * If the GPIO cannot be translated or there is an error an ERR_PTR is 360 + * returned. 361 + * 362 + * Note: if the GPIO resource has multiple entries in the pin list, this 363 + * function only returns the first. 364 + */ 365 + struct gpio_desc *acpi_get_gpiod_by_index(struct device *dev, int index, 366 + struct acpi_gpio_info *info) 367 + { 368 + struct acpi_gpio_lookup lookup; 369 + struct list_head resource_list; 370 + struct acpi_device *adev; 371 + acpi_handle handle; 372 + int ret; 373 + 374 + if (!dev) 375 + return ERR_PTR(-EINVAL); 376 + 377 + handle = ACPI_HANDLE(dev); 378 + if (!handle || acpi_bus_get_device(handle, &adev)) 379 + return ERR_PTR(-ENODEV); 380 + 381 + memset(&lookup, 0, sizeof(lookup)); 382 + lookup.index = index; 383 + 384 + INIT_LIST_HEAD(&resource_list); 385 + ret = acpi_dev_get_resources(adev, &resource_list, acpi_find_gpio, 386 + &lookup); 387 + if (ret < 0) 388 + return ERR_PTR(ret); 389 + 390 + acpi_dev_free_resource_list(&resource_list); 391 + 392 + if (lookup.desc && info) 393 + *info = lookup.info; 394 + 395 + return lookup.desc ? lookup.desc : ERR_PTR(-ENODEV); 396 + } 397 + EXPORT_SYMBOL_GPL(acpi_get_gpiod_by_index);
+17 -11
drivers/gpio/gpiolib-of.c
··· 15 15 #include <linux/errno.h> 16 16 #include <linux/module.h> 17 17 #include <linux/io.h> 18 - #include <linux/gpio.h> 18 + #include <linux/gpio/consumer.h> 19 19 #include <linux/of.h> 20 20 #include <linux/of_address.h> 21 21 #include <linux/of_gpio.h> 22 22 #include <linux/pinctrl/pinctrl.h> 23 23 #include <linux/slab.h> 24 24 25 + struct gpio_desc; 26 + 25 27 /* Private data structure for of_gpiochip_find_and_xlate */ 26 28 struct gg_data { 27 29 enum of_gpio_flags *flags; 28 30 struct of_phandle_args gpiospec; 29 31 30 - int out_gpio; 32 + struct gpio_desc *out_gpio; 31 33 }; 32 34 33 35 /* Private function for resolving node pointer to gpio_chip */ ··· 47 45 if (ret < 0) 48 46 return false; 49 47 50 - gg_data->out_gpio = ret + gc->base; 48 + gg_data->out_gpio = gpio_to_desc(ret + gc->base); 51 49 return true; 52 50 } 53 51 54 52 /** 55 - * of_get_named_gpio_flags() - Get a GPIO number and flags to use with GPIO API 53 + * of_get_named_gpiod_flags() - Get a GPIO descriptor and flags for GPIO API 56 54 * @np: device node to get GPIO from 57 55 * @propname: property name containing gpio specifier(s) 58 56 * @index: index of the GPIO 59 57 * @flags: a flags pointer to fill in 60 58 * 61 - * Returns GPIO number to use with Linux generic GPIO API, or one of the errno 59 + * Returns GPIO descriptor to use with Linux GPIO API, or one of the errno 62 60 * value on the error condition. If @flags is not NULL the function also fills 63 61 * in flags for the GPIO. 64 62 */ 65 - int of_get_named_gpio_flags(struct device_node *np, const char *propname, 66 - int index, enum of_gpio_flags *flags) 63 + struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np, 64 + const char *propname, int index, enum of_gpio_flags *flags) 67 65 { 68 66 /* Return -EPROBE_DEFER to support probe() functions to be called 69 67 * later when the GPIO actually becomes available 70 68 */ 71 - struct gg_data gg_data = { .flags = flags, .out_gpio = -EPROBE_DEFER }; 69 + struct gg_data gg_data = { 70 + .flags = flags, 71 + .out_gpio = ERR_PTR(-EPROBE_DEFER) 72 + }; 72 73 int ret; 73 74 74 75 /* .of_xlate might decide to not fill in the flags, so clear it. */ ··· 83 78 if (ret) { 84 79 pr_debug("%s: can't parse gpios property of node '%s[%d]'\n", 85 80 __func__, np->full_name, index); 86 - return ret; 81 + return ERR_PTR(ret); 87 82 } 88 83 89 84 gpiochip_find(&gg_data, of_gpiochip_find_and_xlate); 90 85 91 86 of_node_put(gg_data.gpiospec.np); 92 - pr_debug("%s exited with status %d\n", __func__, gg_data.out_gpio); 87 + pr_debug("%s exited with status %d\n", __func__, 88 + PTR_RET(gg_data.out_gpio)); 93 89 return gg_data.out_gpio; 94 90 } 95 - EXPORT_SYMBOL(of_get_named_gpio_flags); 91 + EXPORT_SYMBOL(of_get_named_gpiod_flags); 96 92 97 93 /** 98 94 * of_gpio_simple_xlate - translate gpio_spec to the GPIO number and flags
+604 -244
drivers/gpio/gpiolib.c
··· 10 10 #include <linux/seq_file.h> 11 11 #include <linux/gpio.h> 12 12 #include <linux/of_gpio.h> 13 + #include <linux/acpi_gpio.h> 13 14 #include <linux/idr.h> 14 15 #include <linux/slab.h> 15 16 16 17 #define CREATE_TRACE_POINTS 17 18 #include <trace/events/gpio.h> 18 19 19 - /* Optional implementation infrastructure for GPIO interfaces. 20 + /* Implementation infrastructure for GPIO interfaces. 20 21 * 21 - * Platforms may want to use this if they tend to use very many GPIOs 22 - * that aren't part of a System-On-Chip core; or across I2C/SPI/etc. 23 - * 24 - * When kernel footprint or instruction count is an issue, simpler 25 - * implementations may be preferred. The GPIO programming interface 26 - * allows for inlining speed-critical get/set operations for common 27 - * cases, so that access to SOC-integrated GPIOs can sometimes cost 28 - * only an instruction or two per bit. 22 + * The GPIO programming interface allows for inlining speed-critical 23 + * get/set operations for common cases, so that access to SOC-integrated 24 + * GPIOs can sometimes cost only an instruction or two per bit. 29 25 */ 30 26 31 27 ··· 53 57 #define FLAG_SYSFS 3 /* exported via /sys/class/gpio/control */ 54 58 #define FLAG_TRIG_FALL 4 /* trigger on falling edge */ 55 59 #define FLAG_TRIG_RISE 5 /* trigger on rising edge */ 56 - #define FLAG_ACTIVE_LOW 6 /* sysfs value has active low */ 60 + #define FLAG_ACTIVE_LOW 6 /* value has active low */ 57 61 #define FLAG_OPEN_DRAIN 7 /* Gpio is open drain type */ 58 62 #define FLAG_OPEN_SOURCE 8 /* Gpio is open source type */ 63 + #define FLAG_USED_AS_IRQ 9 /* GPIO is connected to an IRQ */ 59 64 60 65 #define ID_SHIFT 16 /* add new flags before this one */ 61 66 ··· 71 74 72 75 #define GPIO_OFFSET_VALID(chip, offset) (offset >= 0 && offset < chip->ngpio) 73 76 77 + static DEFINE_MUTEX(gpio_lookup_lock); 78 + static LIST_HEAD(gpio_lookup_list); 74 79 static LIST_HEAD(gpio_chips); 75 80 76 81 #ifdef CONFIG_GPIO_SYSFS 77 82 static DEFINE_IDR(dirent_idr); 78 83 #endif 79 84 80 - /* 81 - * Internal gpiod_* API using descriptors instead of the integer namespace. 82 - * Most of this should eventually go public. 83 - */ 84 85 static int gpiod_request(struct gpio_desc *desc, const char *label); 85 86 static void gpiod_free(struct gpio_desc *desc); 86 - static int gpiod_direction_input(struct gpio_desc *desc); 87 - static int gpiod_direction_output(struct gpio_desc *desc, int value); 88 - static int gpiod_get_direction(const struct gpio_desc *desc); 89 - static int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce); 90 - static int gpiod_get_value_cansleep(const struct gpio_desc *desc); 91 - static void gpiod_set_value_cansleep(struct gpio_desc *desc, int value); 92 - static int gpiod_get_value(const struct gpio_desc *desc); 93 - static void gpiod_set_value(struct gpio_desc *desc, int value); 94 - static int gpiod_cansleep(const struct gpio_desc *desc); 95 - static int gpiod_to_irq(const struct gpio_desc *desc); 96 - static int gpiod_export(struct gpio_desc *desc, bool direction_may_change); 97 - static int gpiod_export_link(struct device *dev, const char *name, 98 - struct gpio_desc *desc); 99 - static int gpiod_sysfs_set_active_low(struct gpio_desc *desc, int value); 100 - static void gpiod_unexport(struct gpio_desc *desc); 101 87 88 + #ifdef CONFIG_DEBUG_FS 89 + #define gpiod_emerg(desc, fmt, ...) \ 90 + pr_emerg("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label, \ 91 + ##__VA_ARGS__) 92 + #define gpiod_crit(desc, fmt, ...) \ 93 + pr_crit("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label, \ 94 + ##__VA_ARGS__) 95 + #define gpiod_err(desc, fmt, ...) \ 96 + pr_err("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label, \ 97 + ##__VA_ARGS__) 98 + #define gpiod_warn(desc, fmt, ...) \ 99 + pr_warn("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label, \ 100 + ##__VA_ARGS__) 101 + #define gpiod_info(desc, fmt, ...) \ 102 + pr_info("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label, \ 103 + ##__VA_ARGS__) 104 + #define gpiod_dbg(desc, fmt, ...) \ 105 + pr_debug("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label, \ 106 + ##__VA_ARGS__) 107 + #else 108 + #define gpiod_emerg(desc, fmt, ...) \ 109 + pr_emerg("gpio-%d: " fmt, desc_to_gpio(desc), ##__VA_ARGS__) 110 + #define gpiod_crit(desc, fmt, ...) \ 111 + pr_crit("gpio-%d: " fmt, desc_to_gpio(desc), ##__VA_ARGS__) 112 + #define gpiod_err(desc, fmt, ...) \ 113 + pr_err("gpio-%d: " fmt, desc_to_gpio(desc), ##__VA_ARGS__) 114 + #define gpiod_warn(desc, fmt, ...) \ 115 + pr_warn("gpio-%d: " fmt, desc_to_gpio(desc), ##__VA_ARGS__) 116 + #define gpiod_info(desc, fmt, ...) \ 117 + pr_info("gpio-%d: " fmt, desc_to_gpio(desc), ##__VA_ARGS__) 118 + #define gpiod_dbg(desc, fmt, ...) \ 119 + pr_debug("gpio-%d: " fmt, desc_to_gpio(desc), ##__VA_ARGS__) 120 + #endif 102 121 103 122 static inline void desc_set_label(struct gpio_desc *d, const char *label) 104 123 { ··· 134 121 /** 135 122 * Convert a GPIO number to its descriptor 136 123 */ 137 - static struct gpio_desc *gpio_to_desc(unsigned gpio) 124 + struct gpio_desc *gpio_to_desc(unsigned gpio) 138 125 { 139 126 if (WARN(!gpio_is_valid(gpio), "invalid GPIO %d\n", gpio)) 140 127 return NULL; 141 128 else 142 129 return &gpio_desc[gpio]; 130 + } 131 + EXPORT_SYMBOL_GPL(gpio_to_desc); 132 + 133 + /** 134 + * Convert an offset on a certain chip to a corresponding descriptor 135 + */ 136 + static struct gpio_desc *gpiochip_offset_to_desc(struct gpio_chip *chip, 137 + unsigned int offset) 138 + { 139 + unsigned int gpio = chip->base + offset; 140 + 141 + return gpio_to_desc(gpio); 143 142 } 144 143 145 144 /** ··· 159 134 * This should disappear in the future but is needed since we still 160 135 * use GPIO numbers for error messages and sysfs nodes 161 136 */ 162 - static int desc_to_gpio(const struct gpio_desc *desc) 137 + int desc_to_gpio(const struct gpio_desc *desc) 163 138 { 164 139 return desc - &gpio_desc[0]; 165 140 } 141 + EXPORT_SYMBOL_GPL(desc_to_gpio); 166 142 167 143 168 144 /* Warn when drivers omit gpio_request() calls -- legal but ill-advised ··· 198 172 return 0; 199 173 } 200 174 201 - static struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc) 175 + /** 176 + * gpiod_to_chip - Return the GPIO chip to which a GPIO descriptor belongs 177 + * @desc: descriptor to return the chip of 178 + */ 179 + struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc) 202 180 { 203 181 return desc ? desc->chip : NULL; 204 182 } 205 - 206 - /* caller holds gpio_lock *OR* gpio is marked as requested */ 207 - struct gpio_chip *gpio_to_chip(unsigned gpio) 208 - { 209 - return gpiod_to_chip(gpio_to_desc(gpio)); 210 - } 183 + EXPORT_SYMBOL_GPL(gpiod_to_chip); 211 184 212 185 /* dynamic allocation of GPIOs, e.g. on a hotplugged device */ 213 186 static int gpiochip_find_base(int ngpio) ··· 232 207 } 233 208 } 234 209 235 - /* caller ensures gpio is valid and requested, chip->get_direction may sleep */ 236 - static int gpiod_get_direction(const struct gpio_desc *desc) 210 + /** 211 + * gpiod_get_direction - return the current direction of a GPIO 212 + * @desc: GPIO to get the direction of 213 + * 214 + * Return GPIOF_DIR_IN or GPIOF_DIR_OUT, or an error code in case of error. 215 + * 216 + * This function may sleep if gpiod_cansleep() is true. 217 + */ 218 + int gpiod_get_direction(const struct gpio_desc *desc) 237 219 { 238 220 struct gpio_chip *chip; 239 221 unsigned offset; ··· 266 234 } 267 235 return status; 268 236 } 237 + EXPORT_SYMBOL_GPL(gpiod_get_direction); 269 238 270 239 #ifdef CONFIG_GPIO_SYSFS 271 240 ··· 351 318 352 319 mutex_lock(&sysfs_lock); 353 320 354 - if (!test_bit(FLAG_EXPORT, &desc->flags)) { 321 + if (!test_bit(FLAG_EXPORT, &desc->flags)) 355 322 status = -EIO; 356 - } else { 357 - int value; 358 - 359 - value = !!gpiod_get_value_cansleep(desc); 360 - if (test_bit(FLAG_ACTIVE_LOW, &desc->flags)) 361 - value = !value; 362 - 363 - status = sprintf(buf, "%d\n", value); 364 - } 323 + else 324 + status = sprintf(buf, "%d\n", gpiod_get_value_cansleep(desc)); 365 325 366 326 mutex_unlock(&sysfs_lock); 367 327 return status; ··· 377 351 378 352 status = kstrtol(buf, 0, &value); 379 353 if (status == 0) { 380 - if (test_bit(FLAG_ACTIVE_LOW, &desc->flags)) 381 - value = !value; 382 - gpiod_set_value_cansleep(desc, value != 0); 354 + gpiod_set_value_cansleep(desc, value); 383 355 status = size; 384 356 } 385 357 } ··· 419 395 desc->flags &= ~GPIO_TRIGGER_MASK; 420 396 421 397 if (!gpio_flags) { 398 + gpiod_unlock_as_irq(desc); 422 399 ret = 0; 423 400 goto free_id; 424 401 } ··· 457 432 "gpiolib", value_sd); 458 433 if (ret < 0) 459 434 goto free_id; 435 + 436 + ret = gpiod_lock_as_irq(desc); 437 + if (ret < 0) { 438 + gpiod_warn(desc, "failed to flag the GPIO for IRQ\n"); 439 + goto free_id; 440 + } 460 441 461 442 desc->flags |= gpio_flags; 462 443 return 0; ··· 767 736 768 737 769 738 /** 770 - * gpio_export - export a GPIO through sysfs 739 + * gpiod_export - export a GPIO through sysfs 771 740 * @gpio: gpio to make available, already requested 772 741 * @direction_may_change: true if userspace may change gpio direction 773 742 * Context: arch_initcall or later ··· 781 750 * 782 751 * Returns zero on success, else an error. 783 752 */ 784 - static int gpiod_export(struct gpio_desc *desc, bool direction_may_change) 753 + int gpiod_export(struct gpio_desc *desc, bool direction_may_change) 785 754 { 786 755 unsigned long flags; 787 756 int status; ··· 859 828 status); 860 829 return status; 861 830 } 862 - 863 - int gpio_export(unsigned gpio, bool direction_may_change) 864 - { 865 - return gpiod_export(gpio_to_desc(gpio), direction_may_change); 866 - } 867 - EXPORT_SYMBOL_GPL(gpio_export); 831 + EXPORT_SYMBOL_GPL(gpiod_export); 868 832 869 833 static int match_export(struct device *dev, const void *data) 870 834 { ··· 867 841 } 868 842 869 843 /** 870 - * gpio_export_link - create a sysfs link to an exported GPIO node 844 + * gpiod_export_link - create a sysfs link to an exported GPIO node 871 845 * @dev: device under which to create symlink 872 846 * @name: name of the symlink 873 847 * @gpio: gpio to create symlink to, already exported ··· 877 851 * 878 852 * Returns zero on success, else an error. 879 853 */ 880 - static int gpiod_export_link(struct device *dev, const char *name, 881 - struct gpio_desc *desc) 854 + int gpiod_export_link(struct device *dev, const char *name, 855 + struct gpio_desc *desc) 882 856 { 883 857 int status = -EINVAL; 884 858 ··· 909 883 910 884 return status; 911 885 } 912 - 913 - int gpio_export_link(struct device *dev, const char *name, unsigned gpio) 914 - { 915 - return gpiod_export_link(dev, name, gpio_to_desc(gpio)); 916 - } 917 - EXPORT_SYMBOL_GPL(gpio_export_link); 886 + EXPORT_SYMBOL_GPL(gpiod_export_link); 918 887 919 888 /** 920 - * gpio_sysfs_set_active_low - set the polarity of gpio sysfs value 889 + * gpiod_sysfs_set_active_low - set the polarity of gpio sysfs value 921 890 * @gpio: gpio to change 922 891 * @value: non-zero to use active low, i.e. inverted values 923 892 * ··· 923 902 * 924 903 * Returns zero on success, else an error. 925 904 */ 926 - static int gpiod_sysfs_set_active_low(struct gpio_desc *desc, int value) 905 + int gpiod_sysfs_set_active_low(struct gpio_desc *desc, int value) 927 906 { 928 907 struct device *dev = NULL; 929 908 int status = -EINVAL; ··· 954 933 955 934 return status; 956 935 } 957 - 958 - int gpio_sysfs_set_active_low(unsigned gpio, int value) 959 - { 960 - return gpiod_sysfs_set_active_low(gpio_to_desc(gpio), value); 961 - } 962 - EXPORT_SYMBOL_GPL(gpio_sysfs_set_active_low); 936 + EXPORT_SYMBOL_GPL(gpiod_sysfs_set_active_low); 963 937 964 938 /** 965 - * gpio_unexport - reverse effect of gpio_export() 939 + * gpiod_unexport - reverse effect of gpio_export() 966 940 * @gpio: gpio to make unavailable 967 941 * 968 942 * This is implicit on gpio_free(). 969 943 */ 970 - static void gpiod_unexport(struct gpio_desc *desc) 944 + void gpiod_unexport(struct gpio_desc *desc) 971 945 { 972 946 int status = 0; 973 947 struct device *dev = NULL; ··· 995 979 pr_debug("%s: gpio%d status %d\n", __func__, desc_to_gpio(desc), 996 980 status); 997 981 } 998 - 999 - void gpio_unexport(unsigned gpio) 1000 - { 1001 - gpiod_unexport(gpio_to_desc(gpio)); 1002 - } 1003 - EXPORT_SYMBOL_GPL(gpio_unexport); 982 + EXPORT_SYMBOL_GPL(gpiod_unexport); 1004 983 1005 984 static int gpiochip_export(struct gpio_chip *chip) 1006 985 { ··· 1099 1088 } 1100 1089 1101 1090 static inline void gpiochip_unexport(struct gpio_chip *chip) 1102 - { 1103 - } 1104 - 1105 - static inline int gpiod_export(struct gpio_desc *desc, 1106 - bool direction_may_change) 1107 - { 1108 - return -ENOSYS; 1109 - } 1110 - 1111 - static inline int gpiod_export_link(struct device *dev, const char *name, 1112 - struct gpio_desc *desc) 1113 - { 1114 - return -ENOSYS; 1115 - } 1116 - 1117 - static inline int gpiod_sysfs_set_active_low(struct gpio_desc *desc, int value) 1118 - { 1119 - return -ENOSYS; 1120 - } 1121 - 1122 - static inline void gpiod_unexport(struct gpio_desc *desc) 1123 1091 { 1124 1092 } 1125 1093 ··· 1660 1670 * rely on gpio_request() having been called beforehand. 1661 1671 */ 1662 1672 1663 - static int gpiod_direction_input(struct gpio_desc *desc) 1673 + /** 1674 + * gpiod_direction_input - set the GPIO direction to input 1675 + * @desc: GPIO to set to input 1676 + * 1677 + * Set the direction of the passed GPIO to input, such as gpiod_get_value() can 1678 + * be called safely on it. 1679 + * 1680 + * Return 0 in case of success, else an error code. 1681 + */ 1682 + int gpiod_direction_input(struct gpio_desc *desc) 1664 1683 { 1665 1684 unsigned long flags; 1666 1685 struct gpio_chip *chip; ··· 1683 1684 1684 1685 chip = desc->chip; 1685 1686 if (!chip->get || !chip->direction_input) { 1686 - pr_warn("%s: missing get() or direction_input() operations\n", 1687 - __func__); 1687 + gpiod_warn(desc, 1688 + "%s: missing get() or direction_input() operations\n", 1689 + __func__); 1688 1690 return -EIO; 1689 1691 } 1690 1692 ··· 1705 1705 if (status) { 1706 1706 status = chip->request(chip, offset); 1707 1707 if (status < 0) { 1708 - pr_debug("GPIO-%d: chip request fail, %d\n", 1709 - desc_to_gpio(desc), status); 1708 + gpiod_dbg(desc, "chip request fail, %d\n", status); 1710 1709 /* and it's not available to anyone else ... 1711 1710 * gpio_request() is the fully clean solution. 1712 1711 */ ··· 1723 1724 fail: 1724 1725 spin_unlock_irqrestore(&gpio_lock, flags); 1725 1726 if (status) 1726 - pr_debug("%s: gpio-%d status %d\n", __func__, 1727 - desc_to_gpio(desc), status); 1727 + gpiod_dbg(desc, "%s status %d\n", __func__, status); 1728 1728 return status; 1729 1729 } 1730 + EXPORT_SYMBOL_GPL(gpiod_direction_input); 1730 1731 1731 - int gpio_direction_input(unsigned gpio) 1732 - { 1733 - return gpiod_direction_input(gpio_to_desc(gpio)); 1734 - } 1735 - EXPORT_SYMBOL_GPL(gpio_direction_input); 1736 - 1737 - static int gpiod_direction_output(struct gpio_desc *desc, int value) 1732 + /** 1733 + * gpiod_direction_output - set the GPIO direction to input 1734 + * @desc: GPIO to set to output 1735 + * @value: initial output value of the GPIO 1736 + * 1737 + * Set the direction of the passed GPIO to output, such as gpiod_set_value() can 1738 + * be called safely on it. The initial value of the output must be specified. 1739 + * 1740 + * Return 0 in case of success, else an error code. 1741 + */ 1742 + int gpiod_direction_output(struct gpio_desc *desc, int value) 1738 1743 { 1739 1744 unsigned long flags; 1740 1745 struct gpio_chip *chip; ··· 1748 1745 if (!desc || !desc->chip) { 1749 1746 pr_warn("%s: invalid GPIO\n", __func__); 1750 1747 return -EINVAL; 1748 + } 1749 + 1750 + /* GPIOs used for IRQs shall not be set as output */ 1751 + if (test_bit(FLAG_USED_AS_IRQ, &desc->flags)) { 1752 + gpiod_err(desc, 1753 + "%s: tried to set a GPIO tied to an IRQ as output\n", 1754 + __func__); 1755 + return -EIO; 1751 1756 } 1752 1757 1753 1758 /* Open drain pin should not be driven to 1 */ ··· 1768 1757 1769 1758 chip = desc->chip; 1770 1759 if (!chip->set || !chip->direction_output) { 1771 - pr_warn("%s: missing set() or direction_output() operations\n", 1772 - __func__); 1760 + gpiod_warn(desc, 1761 + "%s: missing set() or direction_output() operations\n", 1762 + __func__); 1773 1763 return -EIO; 1774 1764 } 1775 1765 ··· 1790 1778 if (status) { 1791 1779 status = chip->request(chip, offset); 1792 1780 if (status < 0) { 1793 - pr_debug("GPIO-%d: chip request fail, %d\n", 1794 - desc_to_gpio(desc), status); 1781 + gpiod_dbg(desc, "chip request fail, %d\n", status); 1795 1782 /* and it's not available to anyone else ... 1796 1783 * gpio_request() is the fully clean solution. 1797 1784 */ ··· 1808 1797 fail: 1809 1798 spin_unlock_irqrestore(&gpio_lock, flags); 1810 1799 if (status) 1811 - pr_debug("%s: gpio-%d status %d\n", __func__, 1812 - desc_to_gpio(desc), status); 1800 + gpiod_dbg(desc, "%s: gpio status %d\n", __func__, status); 1813 1801 return status; 1814 1802 } 1815 - 1816 - int gpio_direction_output(unsigned gpio, int value) 1817 - { 1818 - return gpiod_direction_output(gpio_to_desc(gpio), value); 1819 - } 1820 - EXPORT_SYMBOL_GPL(gpio_direction_output); 1803 + EXPORT_SYMBOL_GPL(gpiod_direction_output); 1821 1804 1822 1805 /** 1823 - * gpio_set_debounce - sets @debounce time for a @gpio 1806 + * gpiod_set_debounce - sets @debounce time for a @gpio 1824 1807 * @gpio: the gpio to set debounce time 1825 1808 * @debounce: debounce time is microseconds 1826 1809 * 1827 1810 * returns -ENOTSUPP if the controller does not support setting 1828 1811 * debounce. 1829 1812 */ 1830 - static int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce) 1813 + int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce) 1831 1814 { 1832 1815 unsigned long flags; 1833 1816 struct gpio_chip *chip; ··· 1835 1830 1836 1831 chip = desc->chip; 1837 1832 if (!chip->set || !chip->set_debounce) { 1838 - pr_debug("%s: missing set() or set_debounce() operations\n", 1839 - __func__); 1833 + gpiod_dbg(desc, 1834 + "%s: missing set() or set_debounce() operations\n", 1835 + __func__); 1840 1836 return -ENOTSUPP; 1841 1837 } 1842 1838 ··· 1859 1853 fail: 1860 1854 spin_unlock_irqrestore(&gpio_lock, flags); 1861 1855 if (status) 1862 - pr_debug("%s: gpio-%d status %d\n", __func__, 1863 - desc_to_gpio(desc), status); 1856 + gpiod_dbg(desc, "%s: status %d\n", __func__, status); 1864 1857 1865 1858 return status; 1866 1859 } 1860 + EXPORT_SYMBOL_GPL(gpiod_set_debounce); 1867 1861 1868 - int gpio_set_debounce(unsigned gpio, unsigned debounce) 1862 + /** 1863 + * gpiod_is_active_low - test whether a GPIO is active-low or not 1864 + * @desc: the gpio descriptor to test 1865 + * 1866 + * Returns 1 if the GPIO is active-low, 0 otherwise. 1867 + */ 1868 + int gpiod_is_active_low(const struct gpio_desc *desc) 1869 1869 { 1870 - return gpiod_set_debounce(gpio_to_desc(gpio), debounce); 1870 + return test_bit(FLAG_ACTIVE_LOW, &desc->flags); 1871 1871 } 1872 - EXPORT_SYMBOL_GPL(gpio_set_debounce); 1872 + EXPORT_SYMBOL_GPL(gpiod_is_active_low); 1873 1873 1874 1874 /* I/O calls are only valid after configuration completed; the relevant 1875 1875 * "is this a valid GPIO" error checks should already have been done. ··· 1899 1887 * that the GPIO was actually requested. 1900 1888 */ 1901 1889 1902 - /** 1903 - * __gpio_get_value() - return a gpio's value 1904 - * @gpio: gpio whose value will be returned 1905 - * Context: any 1906 - * 1907 - * This is used directly or indirectly to implement gpio_get_value(). 1908 - * It returns the zero or nonzero value provided by the associated 1909 - * gpio_chip.get() method; or zero if no such method is provided. 1910 - */ 1911 - static int gpiod_get_value(const struct gpio_desc *desc) 1890 + static int _gpiod_get_raw_value(const struct gpio_desc *desc) 1912 1891 { 1913 1892 struct gpio_chip *chip; 1914 1893 int value; 1915 1894 int offset; 1916 1895 1917 - if (!desc) 1918 - return 0; 1919 1896 chip = desc->chip; 1920 1897 offset = gpio_chip_hwgpio(desc); 1921 - /* Should be using gpio_get_value_cansleep() */ 1922 - WARN_ON(chip->can_sleep); 1923 1898 value = chip->get ? chip->get(chip, offset) : 0; 1924 1899 trace_gpio_value(desc_to_gpio(desc), 1, value); 1925 1900 return value; 1926 1901 } 1927 1902 1928 - int __gpio_get_value(unsigned gpio) 1903 + /** 1904 + * gpiod_get_raw_value() - return a gpio's raw value 1905 + * @desc: gpio whose value will be returned 1906 + * 1907 + * Return the GPIO's raw value, i.e. the value of the physical line disregarding 1908 + * its ACTIVE_LOW status. 1909 + * 1910 + * This function should be called from contexts where we cannot sleep, and will 1911 + * complain if the GPIO chip functions potentially sleep. 1912 + */ 1913 + int gpiod_get_raw_value(const struct gpio_desc *desc) 1929 1914 { 1930 - return gpiod_get_value(gpio_to_desc(gpio)); 1915 + if (!desc) 1916 + return 0; 1917 + /* Should be using gpio_get_value_cansleep() */ 1918 + WARN_ON(desc->chip->can_sleep); 1919 + return _gpiod_get_raw_value(desc); 1931 1920 } 1932 - EXPORT_SYMBOL_GPL(__gpio_get_value); 1921 + EXPORT_SYMBOL_GPL(gpiod_get_raw_value); 1922 + 1923 + /** 1924 + * gpiod_get_value() - return a gpio's value 1925 + * @desc: gpio whose value will be returned 1926 + * 1927 + * Return the GPIO's logical value, i.e. taking the ACTIVE_LOW status into 1928 + * account. 1929 + * 1930 + * This function should be called from contexts where we cannot sleep, and will 1931 + * complain if the GPIO chip functions potentially sleep. 1932 + */ 1933 + int gpiod_get_value(const struct gpio_desc *desc) 1934 + { 1935 + int value; 1936 + if (!desc) 1937 + return 0; 1938 + /* Should be using gpio_get_value_cansleep() */ 1939 + WARN_ON(desc->chip->can_sleep); 1940 + 1941 + value = _gpiod_get_raw_value(desc); 1942 + if (test_bit(FLAG_ACTIVE_LOW, &desc->flags)) 1943 + value = !value; 1944 + 1945 + return value; 1946 + } 1947 + EXPORT_SYMBOL_GPL(gpiod_get_value); 1933 1948 1934 1949 /* 1935 1950 * _gpio_set_open_drain_value() - Set the open drain gpio's value. 1936 - * @gpio: Gpio whose state need to be set. 1937 - * @chip: Gpio chip. 1951 + * @desc: gpio descriptor whose state need to be set. 1938 1952 * @value: Non-zero for setting it HIGH otherise it will set to LOW. 1939 1953 */ 1940 1954 static void _gpio_set_open_drain_value(struct gpio_desc *desc, int value) ··· 1980 1942 } 1981 1943 trace_gpio_direction(desc_to_gpio(desc), value, err); 1982 1944 if (err < 0) 1983 - pr_err("%s: Error in set_value for open drain gpio%d err %d\n", 1984 - __func__, desc_to_gpio(desc), err); 1945 + gpiod_err(desc, 1946 + "%s: Error in set_value for open drain err %d\n", 1947 + __func__, err); 1985 1948 } 1986 1949 1987 1950 /* 1988 - * _gpio_set_open_source() - Set the open source gpio's value. 1989 - * @gpio: Gpio whose state need to be set. 1990 - * @chip: Gpio chip. 1951 + * _gpio_set_open_source_value() - Set the open source gpio's value. 1952 + * @desc: gpio descriptor whose state need to be set. 1991 1953 * @value: Non-zero for setting it HIGH otherise it will set to LOW. 1992 1954 */ 1993 1955 static void _gpio_set_open_source_value(struct gpio_desc *desc, int value) ··· 2007 1969 } 2008 1970 trace_gpio_direction(desc_to_gpio(desc), !value, err); 2009 1971 if (err < 0) 2010 - pr_err("%s: Error in set_value for open source gpio%d err %d\n", 2011 - __func__, desc_to_gpio(desc), err); 1972 + gpiod_err(desc, 1973 + "%s: Error in set_value for open source err %d\n", 1974 + __func__, err); 2012 1975 } 2013 1976 2014 - /** 2015 - * __gpio_set_value() - assign a gpio's value 2016 - * @gpio: gpio whose value will be assigned 2017 - * @value: value to assign 2018 - * Context: any 2019 - * 2020 - * This is used directly or indirectly to implement gpio_set_value(). 2021 - * It invokes the associated gpio_chip.set() method. 2022 - */ 2023 - static void gpiod_set_value(struct gpio_desc *desc, int value) 1977 + static void _gpiod_set_raw_value(struct gpio_desc *desc, int value) 2024 1978 { 2025 1979 struct gpio_chip *chip; 2026 1980 2027 - if (!desc) 2028 - return; 2029 1981 chip = desc->chip; 2030 - /* Should be using gpio_set_value_cansleep() */ 2031 - WARN_ON(chip->can_sleep); 2032 1982 trace_gpio_value(desc_to_gpio(desc), 0, value); 2033 1983 if (test_bit(FLAG_OPEN_DRAIN, &desc->flags)) 2034 1984 _gpio_set_open_drain_value(desc, value); ··· 2026 2000 chip->set(chip, gpio_chip_hwgpio(desc), value); 2027 2001 } 2028 2002 2029 - void __gpio_set_value(unsigned gpio, int value) 2003 + /** 2004 + * gpiod_set_raw_value() - assign a gpio's raw value 2005 + * @desc: gpio whose value will be assigned 2006 + * @value: value to assign 2007 + * 2008 + * Set the raw value of the GPIO, i.e. the value of its physical line without 2009 + * regard for its ACTIVE_LOW status. 2010 + * 2011 + * This function should be called from contexts where we cannot sleep, and will 2012 + * complain if the GPIO chip functions potentially sleep. 2013 + */ 2014 + void gpiod_set_raw_value(struct gpio_desc *desc, int value) 2030 2015 { 2031 - return gpiod_set_value(gpio_to_desc(gpio), value); 2016 + if (!desc) 2017 + return; 2018 + /* Should be using gpio_set_value_cansleep() */ 2019 + WARN_ON(desc->chip->can_sleep); 2020 + _gpiod_set_raw_value(desc, value); 2032 2021 } 2033 - EXPORT_SYMBOL_GPL(__gpio_set_value); 2022 + EXPORT_SYMBOL_GPL(gpiod_set_raw_value); 2034 2023 2035 2024 /** 2036 - * __gpio_cansleep() - report whether gpio value access will sleep 2037 - * @gpio: gpio in question 2038 - * Context: any 2025 + * gpiod_set_value() - assign a gpio's value 2026 + * @desc: gpio whose value will be assigned 2027 + * @value: value to assign 2039 2028 * 2040 - * This is used directly or indirectly to implement gpio_cansleep(). It 2041 - * returns nonzero if access reading or writing the GPIO value can sleep. 2029 + * Set the logical value of the GPIO, i.e. taking its ACTIVE_LOW status into 2030 + * account 2031 + * 2032 + * This function should be called from contexts where we cannot sleep, and will 2033 + * complain if the GPIO chip functions potentially sleep. 2042 2034 */ 2043 - static int gpiod_cansleep(const struct gpio_desc *desc) 2035 + void gpiod_set_value(struct gpio_desc *desc, int value) 2036 + { 2037 + if (!desc) 2038 + return; 2039 + /* Should be using gpio_set_value_cansleep() */ 2040 + WARN_ON(desc->chip->can_sleep); 2041 + if (test_bit(FLAG_ACTIVE_LOW, &desc->flags)) 2042 + value = !value; 2043 + _gpiod_set_raw_value(desc, value); 2044 + } 2045 + EXPORT_SYMBOL_GPL(gpiod_set_value); 2046 + 2047 + /** 2048 + * gpiod_cansleep() - report whether gpio value access may sleep 2049 + * @desc: gpio to check 2050 + * 2051 + */ 2052 + int gpiod_cansleep(const struct gpio_desc *desc) 2044 2053 { 2045 2054 if (!desc) 2046 2055 return 0; 2047 - /* only call this on GPIOs that are valid! */ 2048 2056 return desc->chip->can_sleep; 2049 2057 } 2050 - 2051 - int __gpio_cansleep(unsigned gpio) 2052 - { 2053 - return gpiod_cansleep(gpio_to_desc(gpio)); 2054 - } 2055 - EXPORT_SYMBOL_GPL(__gpio_cansleep); 2058 + EXPORT_SYMBOL_GPL(gpiod_cansleep); 2056 2059 2057 2060 /** 2058 - * __gpio_to_irq() - return the IRQ corresponding to a GPIO 2059 - * @gpio: gpio whose IRQ will be returned (already requested) 2060 - * Context: any 2061 + * gpiod_to_irq() - return the IRQ corresponding to a GPIO 2062 + * @desc: gpio whose IRQ will be returned (already requested) 2061 2063 * 2062 - * This is used directly or indirectly to implement gpio_to_irq(). 2063 - * It returns the number of the IRQ signaled by this (input) GPIO, 2064 - * or a negative errno. 2064 + * Return the IRQ corresponding to the passed GPIO, or an error code in case of 2065 + * error. 2065 2066 */ 2066 - static int gpiod_to_irq(const struct gpio_desc *desc) 2067 + int gpiod_to_irq(const struct gpio_desc *desc) 2067 2068 { 2068 2069 struct gpio_chip *chip; 2069 2070 int offset; ··· 2101 2048 offset = gpio_chip_hwgpio(desc); 2102 2049 return chip->to_irq ? chip->to_irq(chip, offset) : -ENXIO; 2103 2050 } 2051 + EXPORT_SYMBOL_GPL(gpiod_to_irq); 2104 2052 2105 - int __gpio_to_irq(unsigned gpio) 2106 - { 2107 - return gpiod_to_irq(gpio_to_desc(gpio)); 2108 - } 2109 - EXPORT_SYMBOL_GPL(__gpio_to_irq); 2110 - 2111 - 2112 - /* There's no value in making it easy to inline GPIO calls that may sleep. 2113 - * Common examples include ones connected to I2C or SPI chips. 2053 + /** 2054 + * gpiod_lock_as_irq() - lock a GPIO to be used as IRQ 2055 + * @gpio: the GPIO line to lock as used for IRQ 2056 + * 2057 + * This is used directly by GPIO drivers that want to lock down 2058 + * a certain GPIO line to be used as IRQs, for example in the 2059 + * .to_irq() callback of their gpio_chip, or in the .irq_enable() 2060 + * of its irq_chip implementation if the GPIO is known from that 2061 + * code. 2114 2062 */ 2115 - 2116 - static int gpiod_get_value_cansleep(const struct gpio_desc *desc) 2063 + int gpiod_lock_as_irq(struct gpio_desc *desc) 2117 2064 { 2118 - struct gpio_chip *chip; 2065 + if (!desc) 2066 + return -EINVAL; 2067 + 2068 + if (test_bit(FLAG_IS_OUT, &desc->flags)) { 2069 + gpiod_err(desc, 2070 + "%s: tried to flag a GPIO set as output for IRQ\n", 2071 + __func__); 2072 + return -EIO; 2073 + } 2074 + 2075 + set_bit(FLAG_USED_AS_IRQ, &desc->flags); 2076 + return 0; 2077 + } 2078 + EXPORT_SYMBOL_GPL(gpiod_lock_as_irq); 2079 + 2080 + int gpio_lock_as_irq(struct gpio_chip *chip, unsigned int offset) 2081 + { 2082 + return gpiod_lock_as_irq(gpiochip_offset_to_desc(chip, offset)); 2083 + } 2084 + EXPORT_SYMBOL_GPL(gpio_lock_as_irq); 2085 + 2086 + /** 2087 + * gpiod_unlock_as_irq() - unlock a GPIO used as IRQ 2088 + * @gpio: the GPIO line to unlock from IRQ usage 2089 + * 2090 + * This is used directly by GPIO drivers that want to indicate 2091 + * that a certain GPIO is no longer used exclusively for IRQ. 2092 + */ 2093 + void gpiod_unlock_as_irq(struct gpio_desc *desc) 2094 + { 2095 + if (!desc) 2096 + return; 2097 + 2098 + clear_bit(FLAG_USED_AS_IRQ, &desc->flags); 2099 + } 2100 + EXPORT_SYMBOL_GPL(gpiod_unlock_as_irq); 2101 + 2102 + void gpio_unlock_as_irq(struct gpio_chip *chip, unsigned int offset) 2103 + { 2104 + return gpiod_unlock_as_irq(gpiochip_offset_to_desc(chip, offset)); 2105 + } 2106 + EXPORT_SYMBOL_GPL(gpio_unlock_as_irq); 2107 + 2108 + /** 2109 + * gpiod_get_raw_value_cansleep() - return a gpio's raw value 2110 + * @desc: gpio whose value will be returned 2111 + * 2112 + * Return the GPIO's raw value, i.e. the value of the physical line disregarding 2113 + * its ACTIVE_LOW status. 2114 + * 2115 + * This function is to be called from contexts that can sleep. 2116 + */ 2117 + int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc) 2118 + { 2119 + might_sleep_if(extra_checks); 2120 + if (!desc) 2121 + return 0; 2122 + return _gpiod_get_raw_value(desc); 2123 + } 2124 + EXPORT_SYMBOL_GPL(gpiod_get_raw_value_cansleep); 2125 + 2126 + /** 2127 + * gpiod_get_value_cansleep() - return a gpio's value 2128 + * @desc: gpio whose value will be returned 2129 + * 2130 + * Return the GPIO's logical value, i.e. taking the ACTIVE_LOW status into 2131 + * account. 2132 + * 2133 + * This function is to be called from contexts that can sleep. 2134 + */ 2135 + int gpiod_get_value_cansleep(const struct gpio_desc *desc) 2136 + { 2119 2137 int value; 2120 - int offset; 2121 2138 2122 2139 might_sleep_if(extra_checks); 2123 2140 if (!desc) 2124 2141 return 0; 2125 - chip = desc->chip; 2126 - offset = gpio_chip_hwgpio(desc); 2127 - value = chip->get ? chip->get(chip, offset) : 0; 2128 - trace_gpio_value(desc_to_gpio(desc), 1, value); 2142 + 2143 + value = _gpiod_get_raw_value(desc); 2144 + if (test_bit(FLAG_ACTIVE_LOW, &desc->flags)) 2145 + value = !value; 2146 + 2129 2147 return value; 2130 2148 } 2149 + EXPORT_SYMBOL_GPL(gpiod_get_value_cansleep); 2131 2150 2132 - int gpio_get_value_cansleep(unsigned gpio) 2151 + /** 2152 + * gpiod_set_raw_value_cansleep() - assign a gpio's raw value 2153 + * @desc: gpio whose value will be assigned 2154 + * @value: value to assign 2155 + * 2156 + * Set the raw value of the GPIO, i.e. the value of its physical line without 2157 + * regard for its ACTIVE_LOW status. 2158 + * 2159 + * This function is to be called from contexts that can sleep. 2160 + */ 2161 + void gpiod_set_raw_value_cansleep(struct gpio_desc *desc, int value) 2133 2162 { 2134 - return gpiod_get_value_cansleep(gpio_to_desc(gpio)); 2135 - } 2136 - EXPORT_SYMBOL_GPL(gpio_get_value_cansleep); 2137 - 2138 - static void gpiod_set_value_cansleep(struct gpio_desc *desc, int value) 2139 - { 2140 - struct gpio_chip *chip; 2141 - 2142 2163 might_sleep_if(extra_checks); 2143 2164 if (!desc) 2144 2165 return; 2145 - chip = desc->chip; 2146 - trace_gpio_value(desc_to_gpio(desc), 0, value); 2147 - if (test_bit(FLAG_OPEN_DRAIN, &desc->flags)) 2148 - _gpio_set_open_drain_value(desc, value); 2149 - else if (test_bit(FLAG_OPEN_SOURCE, &desc->flags)) 2150 - _gpio_set_open_source_value(desc, value); 2151 - else 2152 - chip->set(chip, gpio_chip_hwgpio(desc), value); 2166 + _gpiod_set_raw_value(desc, value); 2167 + } 2168 + EXPORT_SYMBOL_GPL(gpiod_set_raw_value_cansleep); 2169 + 2170 + /** 2171 + * gpiod_set_value_cansleep() - assign a gpio's value 2172 + * @desc: gpio whose value will be assigned 2173 + * @value: value to assign 2174 + * 2175 + * Set the logical value of the GPIO, i.e. taking its ACTIVE_LOW status into 2176 + * account 2177 + * 2178 + * This function is to be called from contexts that can sleep. 2179 + */ 2180 + void gpiod_set_value_cansleep(struct gpio_desc *desc, int value) 2181 + { 2182 + might_sleep_if(extra_checks); 2183 + if (!desc) 2184 + return; 2185 + 2186 + if (test_bit(FLAG_ACTIVE_LOW, &desc->flags)) 2187 + value = !value; 2188 + _gpiod_set_raw_value(desc, value); 2189 + } 2190 + EXPORT_SYMBOL_GPL(gpiod_set_value_cansleep); 2191 + 2192 + /** 2193 + * gpiod_add_table() - register GPIO device consumers 2194 + * @table: array of consumers to register 2195 + * @num: number of consumers in table 2196 + */ 2197 + void gpiod_add_table(struct gpiod_lookup *table, size_t size) 2198 + { 2199 + mutex_lock(&gpio_lookup_lock); 2200 + 2201 + while (size--) { 2202 + list_add_tail(&table->list, &gpio_lookup_list); 2203 + table++; 2204 + } 2205 + 2206 + mutex_unlock(&gpio_lookup_lock); 2153 2207 } 2154 2208 2155 - void gpio_set_value_cansleep(unsigned gpio, int value) 2209 + /* 2210 + * Caller must have a acquired gpio_lookup_lock 2211 + */ 2212 + static struct gpio_chip *find_chip_by_name(const char *name) 2156 2213 { 2157 - return gpiod_set_value_cansleep(gpio_to_desc(gpio), value); 2214 + struct gpio_chip *chip = NULL; 2215 + 2216 + list_for_each_entry(chip, &gpio_lookup_list, list) { 2217 + if (chip->label == NULL) 2218 + continue; 2219 + if (!strcmp(chip->label, name)) 2220 + break; 2221 + } 2222 + 2223 + return chip; 2158 2224 } 2159 - EXPORT_SYMBOL_GPL(gpio_set_value_cansleep); 2225 + 2226 + #ifdef CONFIG_OF 2227 + static struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id, 2228 + unsigned int idx, unsigned long *flags) 2229 + { 2230 + char prop_name[32]; /* 32 is max size of property name */ 2231 + enum of_gpio_flags of_flags; 2232 + struct gpio_desc *desc; 2233 + 2234 + if (con_id) 2235 + snprintf(prop_name, 32, "%s-gpios", con_id); 2236 + else 2237 + snprintf(prop_name, 32, "gpios"); 2238 + 2239 + desc = of_get_named_gpiod_flags(dev->of_node, prop_name, idx, 2240 + &of_flags); 2241 + 2242 + if (IS_ERR(desc)) 2243 + return desc; 2244 + 2245 + if (of_flags & OF_GPIO_ACTIVE_LOW) 2246 + *flags |= GPIOF_ACTIVE_LOW; 2247 + 2248 + return desc; 2249 + } 2250 + #else 2251 + static struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id, 2252 + unsigned int idx, unsigned long *flags) 2253 + { 2254 + return ERR_PTR(-ENODEV); 2255 + } 2256 + #endif 2257 + 2258 + static struct gpio_desc *acpi_find_gpio(struct device *dev, const char *con_id, 2259 + unsigned int idx, unsigned long *flags) 2260 + { 2261 + struct acpi_gpio_info info; 2262 + struct gpio_desc *desc; 2263 + 2264 + desc = acpi_get_gpiod_by_index(dev, idx, &info); 2265 + if (IS_ERR(desc)) 2266 + return desc; 2267 + 2268 + if (info.gpioint && info.active_low) 2269 + *flags |= GPIOF_ACTIVE_LOW; 2270 + 2271 + return desc; 2272 + } 2273 + 2274 + static struct gpio_desc *gpiod_find(struct device *dev, const char *con_id, 2275 + unsigned int idx, unsigned long *flags) 2276 + { 2277 + const char *dev_id = dev ? dev_name(dev) : NULL; 2278 + struct gpio_desc *desc = ERR_PTR(-ENODEV); 2279 + unsigned int match, best = 0; 2280 + struct gpiod_lookup *p; 2281 + 2282 + mutex_lock(&gpio_lookup_lock); 2283 + 2284 + list_for_each_entry(p, &gpio_lookup_list, list) { 2285 + match = 0; 2286 + 2287 + if (p->dev_id) { 2288 + if (!dev_id || strcmp(p->dev_id, dev_id)) 2289 + continue; 2290 + 2291 + match += 2; 2292 + } 2293 + 2294 + if (p->con_id) { 2295 + if (!con_id || strcmp(p->con_id, con_id)) 2296 + continue; 2297 + 2298 + match += 1; 2299 + } 2300 + 2301 + if (p->idx != idx) 2302 + continue; 2303 + 2304 + if (match > best) { 2305 + struct gpio_chip *chip; 2306 + 2307 + chip = find_chip_by_name(p->chip_label); 2308 + 2309 + if (!chip) { 2310 + dev_warn(dev, "cannot find GPIO chip %s\n", 2311 + p->chip_label); 2312 + continue; 2313 + } 2314 + 2315 + if (chip->ngpio >= p->chip_hwnum) { 2316 + dev_warn(dev, "GPIO chip %s has %d GPIOs\n", 2317 + chip->label, chip->ngpio); 2318 + continue; 2319 + } 2320 + 2321 + desc = gpio_to_desc(chip->base + p->chip_hwnum); 2322 + *flags = p->flags; 2323 + 2324 + if (match != 3) 2325 + best = match; 2326 + else 2327 + break; 2328 + } 2329 + } 2330 + 2331 + mutex_unlock(&gpio_lookup_lock); 2332 + 2333 + return desc; 2334 + } 2335 + 2336 + /** 2337 + * gpio_get - obtain a GPIO for a given GPIO function 2338 + * @dev: GPIO consumer 2339 + * @con_id: function within the GPIO consumer 2340 + * 2341 + * Return the GPIO descriptor corresponding to the function con_id of device 2342 + * dev, or an IS_ERR() condition if an error occured. 2343 + */ 2344 + struct gpio_desc *__must_check gpiod_get(struct device *dev, const char *con_id) 2345 + { 2346 + return gpiod_get_index(dev, con_id, 0); 2347 + } 2348 + EXPORT_SYMBOL_GPL(gpiod_get); 2349 + 2350 + /** 2351 + * gpiod_get_index - obtain a GPIO from a multi-index GPIO function 2352 + * @dev: GPIO consumer 2353 + * @con_id: function within the GPIO consumer 2354 + * @idx: index of the GPIO to obtain in the consumer 2355 + * 2356 + * This variant of gpiod_get() allows to access GPIOs other than the first 2357 + * defined one for functions that define several GPIOs. 2358 + * 2359 + * Return a valid GPIO descriptor, or an IS_ERR() condition in case of error. 2360 + */ 2361 + struct gpio_desc *__must_check gpiod_get_index(struct device *dev, 2362 + const char *con_id, 2363 + unsigned int idx) 2364 + { 2365 + struct gpio_desc *desc; 2366 + int status; 2367 + unsigned long flags = 0; 2368 + 2369 + dev_dbg(dev, "GPIO lookup for consumer %s\n", con_id); 2370 + 2371 + /* Using device tree? */ 2372 + if (IS_ENABLED(CONFIG_OF) && dev && dev->of_node) { 2373 + dev_dbg(dev, "using device tree for GPIO lookup\n"); 2374 + desc = of_find_gpio(dev, con_id, idx, &flags); 2375 + } else if (IS_ENABLED(CONFIG_ACPI) && dev && ACPI_HANDLE(dev)) { 2376 + dev_dbg(dev, "using ACPI for GPIO lookup\n"); 2377 + desc = acpi_find_gpio(dev, con_id, idx, &flags); 2378 + } else { 2379 + dev_dbg(dev, "using lookup tables for GPIO lookup"); 2380 + desc = gpiod_find(dev, con_id, idx, &flags); 2381 + } 2382 + 2383 + if (IS_ERR(desc)) { 2384 + dev_warn(dev, "lookup for GPIO %s failed\n", con_id); 2385 + return desc; 2386 + } 2387 + 2388 + status = gpiod_request(desc, con_id); 2389 + 2390 + if (status < 0) 2391 + return ERR_PTR(status); 2392 + 2393 + if (flags & GPIOF_ACTIVE_LOW) 2394 + set_bit(FLAG_ACTIVE_LOW, &desc->flags); 2395 + 2396 + return desc; 2397 + } 2398 + EXPORT_SYMBOL_GPL(gpiod_get_index); 2399 + 2400 + /** 2401 + * gpiod_put - dispose of a GPIO descriptor 2402 + * @desc: GPIO descriptor to dispose of 2403 + * 2404 + * No descriptor can be used after gpiod_put() has been called on it. 2405 + */ 2406 + void gpiod_put(struct gpio_desc *desc) 2407 + { 2408 + gpiod_free(desc); 2409 + } 2410 + EXPORT_SYMBOL_GPL(gpiod_put); 2160 2411 2161 2412 #ifdef CONFIG_DEBUG_FS 2162 2413 ··· 2470 2113 unsigned gpio = chip->base; 2471 2114 struct gpio_desc *gdesc = &chip->desc[0]; 2472 2115 int is_out; 2116 + int is_irq; 2473 2117 2474 2118 for (i = 0; i < chip->ngpio; i++, gpio++, gdesc++) { 2475 2119 if (!test_bit(FLAG_REQUESTED, &gdesc->flags)) ··· 2478 2120 2479 2121 gpiod_get_direction(gdesc); 2480 2122 is_out = test_bit(FLAG_IS_OUT, &gdesc->flags); 2481 - seq_printf(s, " gpio-%-3d (%-20.20s) %s %s", 2123 + is_irq = test_bit(FLAG_USED_AS_IRQ, &gdesc->flags); 2124 + seq_printf(s, " gpio-%-3d (%-20.20s) %s %s %s", 2482 2125 gpio, gdesc->label, 2483 2126 is_out ? "out" : "in ", 2484 2127 chip->get 2485 2128 ? (chip->get(chip, i) ? "hi" : "lo") 2486 - : "? "); 2129 + : "? ", 2130 + is_irq ? "IRQ" : " "); 2487 2131 seq_printf(s, "\n"); 2488 2132 } 2489 2133 }
+16 -9
drivers/input/misc/ixp4xx-beeper.c
··· 20 20 #include <linux/delay.h> 21 21 #include <linux/platform_device.h> 22 22 #include <linux/interrupt.h> 23 + #include <linux/gpio.h> 23 24 #include <mach/hardware.h> 24 25 25 26 MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>"); ··· 36 35 37 36 spin_lock_irqsave(&beep_lock, flags); 38 37 39 - if (count) { 40 - gpio_line_config(pin, IXP4XX_GPIO_OUT); 41 - gpio_line_set(pin, IXP4XX_GPIO_LOW); 42 - 38 + if (count) { 39 + gpio_direction_output(pin, 0); 43 40 *IXP4XX_OSRT2 = (count & ~IXP4XX_OST_RELOAD_MASK) | IXP4XX_OST_ENABLE; 44 41 } else { 45 - gpio_line_config(pin, IXP4XX_GPIO_IN); 46 - gpio_line_set(pin, IXP4XX_GPIO_HIGH); 47 - 42 + gpio_direction_output(pin, 1); 43 + gpio_direction_input(pin); 48 44 *IXP4XX_OSRT2 = 0; 49 45 } 50 46 ··· 76 78 77 79 static irqreturn_t ixp4xx_spkr_interrupt(int irq, void *dev_id) 78 80 { 81 + unsigned int pin = (unsigned int) dev_id; 82 + 79 83 /* clear interrupt */ 80 84 *IXP4XX_OSST = IXP4XX_OSST_TIMER_2_PEND; 81 85 82 86 /* flip the beeper output */ 83 - *IXP4XX_GPIO_GPOUTR ^= (1 << (unsigned int) dev_id); 87 + gpio_set_value(pin, !gpio_get_value(pin)); 84 88 85 89 return IRQ_HANDLED; 86 90 } ··· 110 110 input_dev->sndbit[0] = BIT_MASK(SND_BELL) | BIT_MASK(SND_TONE); 111 111 input_dev->event = ixp4xx_spkr_event; 112 112 113 + err = gpio_request(dev->id, "ixp4-beeper"); 114 + if (err) 115 + goto err_free_device; 116 + 113 117 err = request_irq(IRQ_IXP4XX_TIMER2, &ixp4xx_spkr_interrupt, 114 118 IRQF_NO_SUSPEND, "ixp4xx-beeper", 115 119 (void *) dev->id); 116 120 if (err) 117 - goto err_free_device; 121 + goto err_free_gpio; 118 122 119 123 err = input_register_device(input_dev); 120 124 if (err) ··· 130 126 131 127 err_free_irq: 132 128 free_irq(IRQ_IXP4XX_TIMER2, (void *)dev->id); 129 + err_free_gpio: 130 + gpio_free(dev->id); 133 131 err_free_device: 134 132 input_free_device(input_dev); 135 133 ··· 150 144 ixp4xx_spkr_control(pin, 0); 151 145 152 146 free_irq(IRQ_IXP4XX_TIMER2, (void *)dev->id); 147 + gpio_free(dev->id); 153 148 154 149 return 0; 155 150 }
+5
drivers/pinctrl/pinctrl-coh901.c
··· 529 529 530 530 dev_dbg(gpio->dev, "enable IRQ for hwirq %lu on port %s, offset %d\n", 531 531 d->hwirq, port->name, offset); 532 + if (gpio_lock_as_irq(&gpio->chip, d->hwirq)) 533 + dev_err(gpio->dev, 534 + "unable to lock HW IRQ %lu for IRQ\n", 535 + d->hwirq); 532 536 local_irq_save(flags); 533 537 val = readl(U300_PIN_REG(offset, ien)); 534 538 writel(val | U300_PIN_BIT(offset), U300_PIN_REG(offset, ien)); ··· 551 547 val = readl(U300_PIN_REG(offset, ien)); 552 548 writel(val & ~U300_PIN_BIT(offset), U300_PIN_REG(offset, ien)); 553 549 local_irq_restore(flags); 550 + gpio_unlock_as_irq(&gpio->chip, d->hwirq); 554 551 } 555 552 556 553 static struct irq_chip u300_gpio_irqchip = {
+5
drivers/pinctrl/pinctrl-nomadik.c
··· 634 634 { 635 635 struct nmk_gpio_chip *nmk_chip = irq_data_get_irq_chip_data(d); 636 636 637 + if (gpio_lock_as_irq(&nmk_chip->chip, d->hwirq)) 638 + dev_err(nmk_chip->chip.dev, 639 + "unable to lock HW IRQ %lu for IRQ\n", 640 + d->hwirq); 637 641 clk_enable(nmk_chip->clk); 638 642 nmk_gpio_irq_unmask(d); 639 643 return 0; ··· 649 645 650 646 nmk_gpio_irq_mask(d); 651 647 clk_disable(nmk_chip->clk); 648 + gpio_unlock_as_irq(&nmk_chip->chip, d->hwirq); 652 649 } 653 650 654 651 static struct irq_chip nmk_gpio_irq_chip = {
+8 -1
drivers/ptp/ptp_ixp46x.c
··· 259 259 static int setup_interrupt(int gpio) 260 260 { 261 261 int irq; 262 + int err; 262 263 263 - gpio_line_config(gpio, IXP4XX_GPIO_IN); 264 + err = gpio_request(gpio, "ixp4-ptp"); 265 + if (err) 266 + return err; 267 + 268 + err = gpio_direction_input(gpio); 269 + if (err) 270 + return err; 264 271 265 272 irq = gpio_to_irq(gpio); 266 273
+13 -3
drivers/staging/media/lirc/lirc_serial.c
··· 67 67 #include <linux/delay.h> 68 68 #include <linux/poll.h> 69 69 #include <linux/platform_device.h> 70 - 70 + #include <linux/gpio.h> 71 71 #include <linux/io.h> 72 72 #include <linux/irq.h> 73 73 #include <linux/fcntl.h> ··· 321 321 * status LED and ground 322 322 */ 323 323 if (type == LIRC_NSLU2) { 324 - gpio_line_set(NSLU2_LED_GRN, IXP4XX_GPIO_LOW); 324 + gpio_set_value(NSLU2_LED_GRN, 0); 325 325 return; 326 326 } 327 327 #endif ··· 335 335 { 336 336 #ifdef CONFIG_LIRC_SERIAL_NSLU2 337 337 if (type == LIRC_NSLU2) { 338 - gpio_line_set(NSLU2_LED_GRN, IXP4XX_GPIO_HIGH); 338 + gpio_set_value(NSLU2_LED_GRN, 1); 339 339 return; 340 340 } 341 341 #endif ··· 838 838 static int lirc_serial_probe(struct platform_device *dev) 839 839 { 840 840 int i, nlow, nhigh, result; 841 + 842 + #ifdef CONFIG_LIRC_SERIAL_NSLU2 843 + /* This GPIO is used for a LED on the NSLU2 */ 844 + result = devm_gpio_request(dev, NSLU2_LED_GRN, "lirc-serial"); 845 + if (result) 846 + return result; 847 + result = gpio_direction_output(NSLU2_LED_GRN, 0); 848 + if (result) 849 + return result; 850 + #endif 841 851 842 852 result = request_irq(irq, irq_handler, 843 853 (share_irq ? IRQF_SHARED : 0),
+65 -160
include/asm-generic/gpio.h
··· 10 10 #ifdef CONFIG_GPIOLIB 11 11 12 12 #include <linux/compiler.h> 13 + #include <linux/gpio/driver.h> 14 + #include <linux/gpio/consumer.h> 13 15 14 16 /* Platforms may implement their GPIO interface with library code, 15 17 * at a small performance cost for non-inlined operations and some ··· 51 49 struct device_node; 52 50 struct gpio_desc; 53 51 54 - /** 55 - * struct gpio_chip - abstract a GPIO controller 56 - * @label: for diagnostics 57 - * @dev: optional device providing the GPIOs 58 - * @owner: helps prevent removal of modules exporting active GPIOs 59 - * @list: links gpio_chips together for traversal 60 - * @request: optional hook for chip-specific activation, such as 61 - * enabling module power and clock; may sleep 62 - * @free: optional hook for chip-specific deactivation, such as 63 - * disabling module power and clock; may sleep 64 - * @get_direction: returns direction for signal "offset", 0=out, 1=in, 65 - * (same as GPIOF_DIR_XXX), or negative error 66 - * @direction_input: configures signal "offset" as input, or returns error 67 - * @get: returns value for signal "offset"; for output signals this 68 - * returns either the value actually sensed, or zero 69 - * @direction_output: configures signal "offset" as output, or returns error 70 - * @set_debounce: optional hook for setting debounce time for specified gpio in 71 - * interrupt triggered gpio chips 72 - * @set: assigns output value for signal "offset" 73 - * @to_irq: optional hook supporting non-static gpio_to_irq() mappings; 74 - * implementation may not sleep 75 - * @dbg_show: optional routine to show contents in debugfs; default code 76 - * will be used when this is omitted, but custom code can show extra 77 - * state (such as pullup/pulldown configuration). 78 - * @base: identifies the first GPIO number handled by this chip; or, if 79 - * negative during registration, requests dynamic ID allocation. 80 - * @ngpio: the number of GPIOs handled by this controller; the last GPIO 81 - * handled is (base + ngpio - 1). 82 - * @desc: array of ngpio descriptors. Private. 83 - * @can_sleep: flag must be set iff get()/set() methods sleep, as they 84 - * must while accessing GPIO expander chips over I2C or SPI 85 - * @names: if set, must be an array of strings to use as alternative 86 - * names for the GPIOs in this chip. Any entry in the array 87 - * may be NULL if there is no alias for the GPIO, however the 88 - * array must be @ngpio entries long. A name can include a single printk 89 - * format specifier for an unsigned int. It is substituted by the actual 90 - * number of the gpio. 91 - * 92 - * A gpio_chip can help platforms abstract various sources of GPIOs so 93 - * they can all be accessed through a common programing interface. 94 - * Example sources would be SOC controllers, FPGAs, multifunction 95 - * chips, dedicated GPIO expanders, and so on. 96 - * 97 - * Each chip controls a number of signals, identified in method calls 98 - * by "offset" values in the range 0..(@ngpio - 1). When those signals 99 - * are referenced through calls like gpio_get_value(gpio), the offset 100 - * is calculated by subtracting @base from the gpio number. 101 - */ 102 - struct gpio_chip { 103 - const char *label; 104 - struct device *dev; 105 - struct module *owner; 106 - struct list_head list; 107 - 108 - int (*request)(struct gpio_chip *chip, 109 - unsigned offset); 110 - void (*free)(struct gpio_chip *chip, 111 - unsigned offset); 112 - int (*get_direction)(struct gpio_chip *chip, 113 - unsigned offset); 114 - int (*direction_input)(struct gpio_chip *chip, 115 - unsigned offset); 116 - int (*get)(struct gpio_chip *chip, 117 - unsigned offset); 118 - int (*direction_output)(struct gpio_chip *chip, 119 - unsigned offset, int value); 120 - int (*set_debounce)(struct gpio_chip *chip, 121 - unsigned offset, unsigned debounce); 122 - 123 - void (*set)(struct gpio_chip *chip, 124 - unsigned offset, int value); 125 - 126 - int (*to_irq)(struct gpio_chip *chip, 127 - unsigned offset); 128 - 129 - void (*dbg_show)(struct seq_file *s, 130 - struct gpio_chip *chip); 131 - int base; 132 - u16 ngpio; 133 - struct gpio_desc *desc; 134 - const char *const *names; 135 - unsigned can_sleep:1; 136 - unsigned exported:1; 137 - 138 - #if defined(CONFIG_OF_GPIO) 139 - /* 140 - * If CONFIG_OF is enabled, then all GPIO controllers described in the 141 - * device tree automatically may have an OF translation 142 - */ 143 - struct device_node *of_node; 144 - int of_gpio_n_cells; 145 - int (*of_xlate)(struct gpio_chip *gc, 146 - const struct of_phandle_args *gpiospec, u32 *flags); 147 - #endif 148 - #ifdef CONFIG_PINCTRL 149 - /* 150 - * If CONFIG_PINCTRL is enabled, then gpio controllers can optionally 151 - * describe the actual pin range which they serve in an SoC. This 152 - * information would be used by pinctrl subsystem to configure 153 - * corresponding pins for gpio usage. 154 - */ 155 - struct list_head pin_ranges; 156 - #endif 157 - }; 158 - 159 - extern const char *gpiochip_is_requested(struct gpio_chip *chip, 160 - unsigned offset); 161 - extern struct gpio_chip *gpio_to_chip(unsigned gpio); 162 - 163 - /* add/remove chips */ 164 - extern int gpiochip_add(struct gpio_chip *chip); 165 - extern int __must_check gpiochip_remove(struct gpio_chip *chip); 166 - extern struct gpio_chip *gpiochip_find(void *data, 167 - int (*match)(struct gpio_chip *chip, 168 - void *data)); 169 - 52 + /* caller holds gpio_lock *OR* gpio is marked as requested */ 53 + static inline struct gpio_chip *gpio_to_chip(unsigned gpio) 54 + { 55 + return gpiod_to_chip(gpio_to_desc(gpio)); 56 + } 170 57 171 58 /* Always use the library code for GPIO management calls, 172 59 * or when sleeping may be involved. ··· 63 172 extern int gpio_request(unsigned gpio, const char *label); 64 173 extern void gpio_free(unsigned gpio); 65 174 66 - extern int gpio_direction_input(unsigned gpio); 67 - extern int gpio_direction_output(unsigned gpio, int value); 175 + static inline int gpio_direction_input(unsigned gpio) 176 + { 177 + return gpiod_direction_input(gpio_to_desc(gpio)); 178 + } 179 + static inline int gpio_direction_output(unsigned gpio, int value) 180 + { 181 + return gpiod_direction_output(gpio_to_desc(gpio), value); 182 + } 68 183 69 - extern int gpio_set_debounce(unsigned gpio, unsigned debounce); 184 + static inline int gpio_set_debounce(unsigned gpio, unsigned debounce) 185 + { 186 + return gpiod_set_debounce(gpio_to_desc(gpio), debounce); 187 + } 70 188 71 - extern int gpio_get_value_cansleep(unsigned gpio); 72 - extern void gpio_set_value_cansleep(unsigned gpio, int value); 189 + static inline int gpio_get_value_cansleep(unsigned gpio) 190 + { 191 + return gpiod_get_raw_value_cansleep(gpio_to_desc(gpio)); 192 + } 193 + static inline void gpio_set_value_cansleep(unsigned gpio, int value) 194 + { 195 + return gpiod_set_raw_value_cansleep(gpio_to_desc(gpio), value); 196 + } 73 197 74 198 75 199 /* A platform's <asm/gpio.h> code may want to inline the I/O calls when 76 200 * the GPIO is constant and refers to some always-present controller, 77 201 * giving direct access to chip registers and tight bitbanging loops. 78 202 */ 79 - extern int __gpio_get_value(unsigned gpio); 80 - extern void __gpio_set_value(unsigned gpio, int value); 203 + static inline int __gpio_get_value(unsigned gpio) 204 + { 205 + return gpiod_get_raw_value(gpio_to_desc(gpio)); 206 + } 207 + static inline void __gpio_set_value(unsigned gpio, int value) 208 + { 209 + return gpiod_set_raw_value(gpio_to_desc(gpio), value); 210 + } 81 211 82 - extern int __gpio_cansleep(unsigned gpio); 212 + static inline int __gpio_cansleep(unsigned gpio) 213 + { 214 + return gpiod_cansleep(gpio_to_desc(gpio)); 215 + } 83 216 84 - extern int __gpio_to_irq(unsigned gpio); 217 + static inline int __gpio_to_irq(unsigned gpio) 218 + { 219 + return gpiod_to_irq(gpio_to_desc(gpio)); 220 + } 221 + 222 + extern int gpio_lock_as_irq(struct gpio_chip *chip, unsigned int offset); 223 + extern void gpio_unlock_as_irq(struct gpio_chip *chip, unsigned int offset); 85 224 86 225 extern int gpio_request_one(unsigned gpio, unsigned long flags, const char *label); 87 226 extern int gpio_request_array(const struct gpio *array, size_t num); 88 227 extern void gpio_free_array(const struct gpio *array, size_t num); 89 228 90 - #ifdef CONFIG_GPIO_SYSFS 91 - 92 229 /* 93 230 * A sysfs interface can be exported by individual drivers if they want, 94 231 * but more typically is configured entirely from userspace. 95 232 */ 96 - extern int gpio_export(unsigned gpio, bool direction_may_change); 97 - extern int gpio_export_link(struct device *dev, const char *name, 98 - unsigned gpio); 99 - extern int gpio_sysfs_set_active_low(unsigned gpio, int value); 100 - extern void gpio_unexport(unsigned gpio); 233 + static inline int gpio_export(unsigned gpio, bool direction_may_change) 234 + { 235 + return gpiod_export(gpio_to_desc(gpio), direction_may_change); 236 + } 101 237 102 - #endif /* CONFIG_GPIO_SYSFS */ 238 + static inline int gpio_export_link(struct device *dev, const char *name, 239 + unsigned gpio) 240 + { 241 + return gpiod_export_link(dev, name, gpio_to_desc(gpio)); 242 + } 243 + 244 + static inline int gpio_sysfs_set_active_low(unsigned gpio, int value) 245 + { 246 + return gpiod_sysfs_set_active_low(gpio_to_desc(gpio), value); 247 + } 248 + 249 + static inline void gpio_unexport(unsigned gpio) 250 + { 251 + gpiod_unexport(gpio_to_desc(gpio)); 252 + } 103 253 104 254 #ifdef CONFIG_PINCTRL 105 255 ··· 219 287 } 220 288 221 289 #endif /* !CONFIG_GPIOLIB */ 222 - 223 - #ifndef CONFIG_GPIO_SYSFS 224 - 225 - struct device; 226 - 227 - /* sysfs support is only available with gpiolib, where it's optional */ 228 - 229 - static inline int gpio_export(unsigned gpio, bool direction_may_change) 230 - { 231 - return -ENOSYS; 232 - } 233 - 234 - static inline int gpio_export_link(struct device *dev, const char *name, 235 - unsigned gpio) 236 - { 237 - return -ENOSYS; 238 - } 239 - 240 - static inline int gpio_sysfs_set_active_low(unsigned gpio, int value) 241 - { 242 - return -ENOSYS; 243 - } 244 - 245 - static inline void gpio_unexport(unsigned gpio) 246 - { 247 - } 248 - #endif /* CONFIG_GPIO_SYSFS */ 249 290 250 291 #endif /* _ASM_GENERIC_GPIO_H */
+20 -11
include/linux/acpi_gpio.h
··· 2 2 #define _LINUX_ACPI_GPIO_H_ 3 3 4 4 #include <linux/device.h> 5 + #include <linux/err.h> 5 6 #include <linux/errno.h> 6 7 #include <linux/gpio.h> 8 + #include <linux/gpio/consumer.h> 7 9 8 10 /** 9 11 * struct acpi_gpio_info - ACPI GPIO specific information 10 12 * @gpioint: if %true this GPIO is of type GpioInt otherwise type is GpioIo 13 + * @active_low: in case of @gpioint, the pin is active low 11 14 */ 12 15 struct acpi_gpio_info { 13 16 bool gpioint; 17 + bool active_low; 14 18 }; 15 19 16 20 #ifdef CONFIG_GPIO_ACPI 17 21 18 - int acpi_get_gpio(char *path, int pin); 19 - int acpi_get_gpio_by_index(struct device *dev, int index, 20 - struct acpi_gpio_info *info); 22 + struct gpio_desc *acpi_get_gpiod_by_index(struct device *dev, int index, 23 + struct acpi_gpio_info *info); 21 24 void acpi_gpiochip_request_interrupts(struct gpio_chip *chip); 22 25 void acpi_gpiochip_free_interrupts(struct gpio_chip *chip); 23 26 24 27 #else /* CONFIG_GPIO_ACPI */ 25 28 26 - static inline int acpi_get_gpio(char *path, int pin) 29 + static inline struct gpio_desc * 30 + acpi_get_gpiod_by_index(struct device *dev, int index, 31 + struct acpi_gpio_info *info) 27 32 { 28 - return -ENODEV; 29 - } 30 - 31 - static inline int acpi_get_gpio_by_index(struct device *dev, int index, 32 - struct acpi_gpio_info *info) 33 - { 34 - return -ENODEV; 33 + return ERR_PTR(-ENOSYS); 35 34 } 36 35 37 36 static inline void acpi_gpiochip_request_interrupts(struct gpio_chip *chip) { } 38 37 static inline void acpi_gpiochip_free_interrupts(struct gpio_chip *chip) { } 39 38 40 39 #endif /* CONFIG_GPIO_ACPI */ 40 + 41 + static inline int acpi_get_gpio_by_index(struct device *dev, int index, 42 + struct acpi_gpio_info *info) 43 + { 44 + struct gpio_desc *desc = acpi_get_gpiod_by_index(dev, index, info); 45 + 46 + if (IS_ERR(desc)) 47 + return PTR_ERR(desc); 48 + return desc_to_gpio(desc); 49 + } 41 50 42 51 #endif /* _LINUX_ACPI_GPIO_H_ */
+47 -12
include/linux/gpio.h
··· 16 16 #define GPIOF_OUT_INIT_LOW (GPIOF_DIR_OUT | GPIOF_INIT_LOW) 17 17 #define GPIOF_OUT_INIT_HIGH (GPIOF_DIR_OUT | GPIOF_INIT_HIGH) 18 18 19 + /* Gpio pin is active-low */ 20 + #define GPIOF_ACTIVE_LOW (1 << 2) 21 + 19 22 /* Gpio pin is open drain */ 20 - #define GPIOF_OPEN_DRAIN (1 << 2) 23 + #define GPIOF_OPEN_DRAIN (1 << 3) 21 24 22 25 /* Gpio pin is open source */ 23 - #define GPIOF_OPEN_SOURCE (1 << 3) 26 + #define GPIOF_OPEN_SOURCE (1 << 4) 24 27 25 - #define GPIOF_EXPORT (1 << 4) 26 - #define GPIOF_EXPORT_CHANGEABLE (1 << 5) 28 + #define GPIOF_EXPORT (1 << 5) 29 + #define GPIOF_EXPORT_CHANGEABLE (1 << 6) 27 30 #define GPIOF_EXPORT_DIR_FIXED (GPIOF_EXPORT) 28 31 #define GPIOF_EXPORT_DIR_CHANGEABLE (GPIOF_EXPORT | GPIOF_EXPORT_CHANGEABLE) 29 32 ··· 76 73 } 77 74 78 75 #endif /* ! CONFIG_ARCH_HAVE_CUSTOM_GPIO_H */ 76 + 77 + /* CONFIG_GPIOLIB: bindings for managed devices that want to request gpios */ 78 + 79 + struct device; 80 + 81 + int devm_gpio_request(struct device *dev, unsigned gpio, const char *label); 82 + int devm_gpio_request_one(struct device *dev, unsigned gpio, 83 + unsigned long flags, const char *label); 84 + void devm_gpio_free(struct device *dev, unsigned int gpio); 79 85 80 86 #else /* ! CONFIG_GPIOLIB */ 81 87 ··· 217 205 return -EINVAL; 218 206 } 219 207 208 + static inline int gpio_lock_as_irq(struct gpio_chip *chip, unsigned int offset) 209 + { 210 + WARN_ON(1); 211 + return -EINVAL; 212 + } 213 + 214 + static inline void gpio_unlock_as_irq(struct gpio_chip *chip, 215 + unsigned int offset) 216 + { 217 + WARN_ON(1); 218 + } 219 + 220 220 static inline int irq_to_gpio(unsigned irq) 221 221 { 222 222 /* irq can never have been returned from gpio_to_irq() */ ··· 260 236 WARN_ON(1); 261 237 } 262 238 239 + static inline int devm_gpio_request(struct device *dev, unsigned gpio, 240 + const char *label) 241 + { 242 + WARN_ON(1); 243 + return -EINVAL; 244 + } 245 + 246 + static inline int devm_gpio_request_one(struct device *dev, unsigned gpio, 247 + unsigned long flags, const char *label) 248 + { 249 + WARN_ON(1); 250 + return -EINVAL; 251 + } 252 + 253 + static inline void devm_gpio_free(struct device *dev, unsigned int gpio) 254 + { 255 + WARN_ON(1); 256 + } 257 + 263 258 #endif /* ! CONFIG_GPIOLIB */ 264 - 265 - struct device; 266 - 267 - /* bindings for managed devices that want to request gpios */ 268 - int devm_gpio_request(struct device *dev, unsigned gpio, const char *label); 269 - int devm_gpio_request_one(struct device *dev, unsigned gpio, 270 - unsigned long flags, const char *label); 271 - void devm_gpio_free(struct device *dev, unsigned int gpio); 272 259 273 260 #endif /* __LINUX_GPIO_H */
+253
include/linux/gpio/consumer.h
··· 1 + #ifndef __LINUX_GPIO_CONSUMER_H 2 + #define __LINUX_GPIO_CONSUMER_H 3 + 4 + #include <linux/err.h> 5 + #include <linux/kernel.h> 6 + 7 + #ifdef CONFIG_GPIOLIB 8 + 9 + struct device; 10 + struct gpio_chip; 11 + 12 + /** 13 + * Opaque descriptor for a GPIO. These are obtained using gpiod_get() and are 14 + * preferable to the old integer-based handles. 15 + * 16 + * Contrary to integers, a pointer to a gpio_desc is guaranteed to be valid 17 + * until the GPIO is released. 18 + */ 19 + struct gpio_desc; 20 + 21 + /* Acquire and dispose GPIOs */ 22 + struct gpio_desc *__must_check gpiod_get(struct device *dev, 23 + const char *con_id); 24 + struct gpio_desc *__must_check gpiod_get_index(struct device *dev, 25 + const char *con_id, 26 + unsigned int idx); 27 + void gpiod_put(struct gpio_desc *desc); 28 + 29 + struct gpio_desc *__must_check devm_gpiod_get(struct device *dev, 30 + const char *con_id); 31 + struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev, 32 + const char *con_id, 33 + unsigned int idx); 34 + void devm_gpiod_put(struct device *dev, struct gpio_desc *desc); 35 + 36 + int gpiod_get_direction(const struct gpio_desc *desc); 37 + int gpiod_direction_input(struct gpio_desc *desc); 38 + int gpiod_direction_output(struct gpio_desc *desc, int value); 39 + 40 + /* Value get/set from non-sleeping context */ 41 + int gpiod_get_value(const struct gpio_desc *desc); 42 + void gpiod_set_value(struct gpio_desc *desc, int value); 43 + int gpiod_get_raw_value(const struct gpio_desc *desc); 44 + void gpiod_set_raw_value(struct gpio_desc *desc, int value); 45 + 46 + /* Value get/set from sleeping context */ 47 + int gpiod_get_value_cansleep(const struct gpio_desc *desc); 48 + void gpiod_set_value_cansleep(struct gpio_desc *desc, int value); 49 + int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc); 50 + void gpiod_set_raw_value_cansleep(struct gpio_desc *desc, int value); 51 + 52 + int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce); 53 + 54 + int gpiod_is_active_low(const struct gpio_desc *desc); 55 + int gpiod_cansleep(const struct gpio_desc *desc); 56 + 57 + int gpiod_to_irq(const struct gpio_desc *desc); 58 + 59 + /* Convert between the old gpio_ and new gpiod_ interfaces */ 60 + struct gpio_desc *gpio_to_desc(unsigned gpio); 61 + int desc_to_gpio(const struct gpio_desc *desc); 62 + struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc); 63 + 64 + #else /* CONFIG_GPIOLIB */ 65 + 66 + static inline struct gpio_desc *__must_check gpiod_get(struct device *dev, 67 + const char *con_id) 68 + { 69 + return ERR_PTR(-ENOSYS); 70 + } 71 + static inline struct gpio_desc *__must_check gpiod_get_index(struct device *dev, 72 + const char *con_id, 73 + unsigned int idx) 74 + { 75 + return ERR_PTR(-ENOSYS); 76 + } 77 + static inline void gpiod_put(struct gpio_desc *desc) 78 + { 79 + might_sleep(); 80 + 81 + /* GPIO can never have been requested */ 82 + WARN_ON(1); 83 + } 84 + 85 + static inline struct gpio_desc *__must_check devm_gpiod_get(struct device *dev, 86 + const char *con_id) 87 + { 88 + return ERR_PTR(-ENOSYS); 89 + } 90 + static inline 91 + struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev, 92 + const char *con_id, 93 + unsigned int idx) 94 + { 95 + return ERR_PTR(-ENOSYS); 96 + } 97 + static inline void devm_gpiod_put(struct device *dev, struct gpio_desc *desc) 98 + { 99 + might_sleep(); 100 + 101 + /* GPIO can never have been requested */ 102 + WARN_ON(1); 103 + } 104 + 105 + 106 + static inline int gpiod_get_direction(const struct gpio_desc *desc) 107 + { 108 + /* GPIO can never have been requested */ 109 + WARN_ON(1); 110 + return -ENOSYS; 111 + } 112 + static inline int gpiod_direction_input(struct gpio_desc *desc) 113 + { 114 + /* GPIO can never have been requested */ 115 + WARN_ON(1); 116 + return -ENOSYS; 117 + } 118 + static inline int gpiod_direction_output(struct gpio_desc *desc, int value) 119 + { 120 + /* GPIO can never have been requested */ 121 + WARN_ON(1); 122 + return -ENOSYS; 123 + } 124 + 125 + 126 + static inline int gpiod_get_value(const struct gpio_desc *desc) 127 + { 128 + /* GPIO can never have been requested */ 129 + WARN_ON(1); 130 + return 0; 131 + } 132 + static inline void gpiod_set_value(struct gpio_desc *desc, int value) 133 + { 134 + /* GPIO can never have been requested */ 135 + WARN_ON(1); 136 + } 137 + static inline int gpiod_get_raw_value(const struct gpio_desc *desc) 138 + { 139 + /* GPIO can never have been requested */ 140 + WARN_ON(1); 141 + return 0; 142 + } 143 + static inline void gpiod_set_raw_value(struct gpio_desc *desc, int value) 144 + { 145 + /* GPIO can never have been requested */ 146 + WARN_ON(1); 147 + } 148 + 149 + static inline int gpiod_get_value_cansleep(const struct gpio_desc *desc) 150 + { 151 + /* GPIO can never have been requested */ 152 + WARN_ON(1); 153 + return 0; 154 + } 155 + static inline void gpiod_set_value_cansleep(struct gpio_desc *desc, int value) 156 + { 157 + /* GPIO can never have been requested */ 158 + WARN_ON(1); 159 + } 160 + static inline int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc) 161 + { 162 + /* GPIO can never have been requested */ 163 + WARN_ON(1); 164 + return 0; 165 + } 166 + static inline void gpiod_set_raw_value_cansleep(struct gpio_desc *desc, 167 + int value) 168 + { 169 + /* GPIO can never have been requested */ 170 + WARN_ON(1); 171 + } 172 + 173 + static inline int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce) 174 + { 175 + /* GPIO can never have been requested */ 176 + WARN_ON(1); 177 + return -ENOSYS; 178 + } 179 + 180 + static inline int gpiod_is_active_low(const struct gpio_desc *desc) 181 + { 182 + /* GPIO can never have been requested */ 183 + WARN_ON(1); 184 + return 0; 185 + } 186 + static inline int gpiod_cansleep(const struct gpio_desc *desc) 187 + { 188 + /* GPIO can never have been requested */ 189 + WARN_ON(1); 190 + return 0; 191 + } 192 + 193 + static inline int gpiod_to_irq(const struct gpio_desc *desc) 194 + { 195 + /* GPIO can never have been requested */ 196 + WARN_ON(1); 197 + return -EINVAL; 198 + } 199 + 200 + static inline struct gpio_desc *gpio_to_desc(unsigned gpio) 201 + { 202 + return ERR_PTR(-EINVAL); 203 + } 204 + static inline int desc_to_gpio(const struct gpio_desc *desc) 205 + { 206 + /* GPIO can never have been requested */ 207 + WARN_ON(1); 208 + return -EINVAL; 209 + } 210 + static inline struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc) 211 + { 212 + /* GPIO can never have been requested */ 213 + WARN_ON(1); 214 + return ERR_PTR(-ENODEV); 215 + } 216 + 217 + 218 + #endif /* CONFIG_GPIOLIB */ 219 + 220 + #if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_GPIO_SYSFS) 221 + 222 + int gpiod_export(struct gpio_desc *desc, bool direction_may_change); 223 + int gpiod_export_link(struct device *dev, const char *name, 224 + struct gpio_desc *desc); 225 + int gpiod_sysfs_set_active_low(struct gpio_desc *desc, int value); 226 + void gpiod_unexport(struct gpio_desc *desc); 227 + 228 + #else /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */ 229 + 230 + static inline int gpiod_export(struct gpio_desc *desc, 231 + bool direction_may_change) 232 + { 233 + return -ENOSYS; 234 + } 235 + 236 + static inline int gpiod_export_link(struct device *dev, const char *name, 237 + struct gpio_desc *desc) 238 + { 239 + return -ENOSYS; 240 + } 241 + 242 + static inline int gpiod_sysfs_set_active_low(struct gpio_desc *desc, int value) 243 + { 244 + return -ENOSYS; 245 + } 246 + 247 + static inline void gpiod_unexport(struct gpio_desc *desc) 248 + { 249 + } 250 + 251 + #endif /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */ 252 + 253 + #endif
+184
include/linux/gpio/driver.h
··· 1 + #ifndef __LINUX_GPIO_DRIVER_H 2 + #define __LINUX_GPIO_DRIVER_H 3 + 4 + #include <linux/types.h> 5 + 6 + struct device; 7 + struct gpio_desc; 8 + struct seq_file; 9 + 10 + /** 11 + * struct gpio_chip - abstract a GPIO controller 12 + * @label: for diagnostics 13 + * @dev: optional device providing the GPIOs 14 + * @owner: helps prevent removal of modules exporting active GPIOs 15 + * @list: links gpio_chips together for traversal 16 + * @request: optional hook for chip-specific activation, such as 17 + * enabling module power and clock; may sleep 18 + * @free: optional hook for chip-specific deactivation, such as 19 + * disabling module power and clock; may sleep 20 + * @get_direction: returns direction for signal "offset", 0=out, 1=in, 21 + * (same as GPIOF_DIR_XXX), or negative error 22 + * @direction_input: configures signal "offset" as input, or returns error 23 + * @direction_output: configures signal "offset" as output, or returns error 24 + * @get: returns value for signal "offset"; for output signals this 25 + * returns either the value actually sensed, or zero 26 + * @set: assigns output value for signal "offset" 27 + * @set_debounce: optional hook for setting debounce time for specified gpio in 28 + * interrupt triggered gpio chips 29 + * @to_irq: optional hook supporting non-static gpio_to_irq() mappings; 30 + * implementation may not sleep 31 + * @dbg_show: optional routine to show contents in debugfs; default code 32 + * will be used when this is omitted, but custom code can show extra 33 + * state (such as pullup/pulldown configuration). 34 + * @base: identifies the first GPIO number handled by this chip; or, if 35 + * negative during registration, requests dynamic ID allocation. 36 + * @ngpio: the number of GPIOs handled by this controller; the last GPIO 37 + * handled is (base + ngpio - 1). 38 + * @desc: array of ngpio descriptors. Private. 39 + * @can_sleep: flag must be set iff get()/set() methods sleep, as they 40 + * must while accessing GPIO expander chips over I2C or SPI 41 + * @names: if set, must be an array of strings to use as alternative 42 + * names for the GPIOs in this chip. Any entry in the array 43 + * may be NULL if there is no alias for the GPIO, however the 44 + * array must be @ngpio entries long. A name can include a single printk 45 + * format specifier for an unsigned int. It is substituted by the actual 46 + * number of the gpio. 47 + * 48 + * A gpio_chip can help platforms abstract various sources of GPIOs so 49 + * they can all be accessed through a common programing interface. 50 + * Example sources would be SOC controllers, FPGAs, multifunction 51 + * chips, dedicated GPIO expanders, and so on. 52 + * 53 + * Each chip controls a number of signals, identified in method calls 54 + * by "offset" values in the range 0..(@ngpio - 1). When those signals 55 + * are referenced through calls like gpio_get_value(gpio), the offset 56 + * is calculated by subtracting @base from the gpio number. 57 + */ 58 + struct gpio_chip { 59 + const char *label; 60 + struct device *dev; 61 + struct module *owner; 62 + struct list_head list; 63 + 64 + int (*request)(struct gpio_chip *chip, 65 + unsigned offset); 66 + void (*free)(struct gpio_chip *chip, 67 + unsigned offset); 68 + int (*get_direction)(struct gpio_chip *chip, 69 + unsigned offset); 70 + int (*direction_input)(struct gpio_chip *chip, 71 + unsigned offset); 72 + int (*direction_output)(struct gpio_chip *chip, 73 + unsigned offset, int value); 74 + int (*get)(struct gpio_chip *chip, 75 + unsigned offset); 76 + void (*set)(struct gpio_chip *chip, 77 + unsigned offset, int value); 78 + int (*set_debounce)(struct gpio_chip *chip, 79 + unsigned offset, 80 + unsigned debounce); 81 + 82 + int (*to_irq)(struct gpio_chip *chip, 83 + unsigned offset); 84 + 85 + void (*dbg_show)(struct seq_file *s, 86 + struct gpio_chip *chip); 87 + int base; 88 + u16 ngpio; 89 + struct gpio_desc *desc; 90 + const char *const *names; 91 + unsigned can_sleep:1; 92 + unsigned exported:1; 93 + 94 + #if defined(CONFIG_OF_GPIO) 95 + /* 96 + * If CONFIG_OF is enabled, then all GPIO controllers described in the 97 + * device tree automatically may have an OF translation 98 + */ 99 + struct device_node *of_node; 100 + int of_gpio_n_cells; 101 + int (*of_xlate)(struct gpio_chip *gc, 102 + const struct of_phandle_args *gpiospec, u32 *flags); 103 + #endif 104 + #ifdef CONFIG_PINCTRL 105 + /* 106 + * If CONFIG_PINCTRL is enabled, then gpio controllers can optionally 107 + * describe the actual pin range which they serve in an SoC. This 108 + * information would be used by pinctrl subsystem to configure 109 + * corresponding pins for gpio usage. 110 + */ 111 + struct list_head pin_ranges; 112 + #endif 113 + }; 114 + 115 + extern const char *gpiochip_is_requested(struct gpio_chip *chip, 116 + unsigned offset); 117 + 118 + /* add/remove chips */ 119 + extern int gpiochip_add(struct gpio_chip *chip); 120 + extern int __must_check gpiochip_remove(struct gpio_chip *chip); 121 + extern struct gpio_chip *gpiochip_find(void *data, 122 + int (*match)(struct gpio_chip *chip, void *data)); 123 + 124 + /* lock/unlock as IRQ */ 125 + int gpiod_lock_as_irq(struct gpio_desc *desc); 126 + void gpiod_unlock_as_irq(struct gpio_desc *desc); 127 + 128 + /** 129 + * Lookup table for associating GPIOs to specific devices and functions using 130 + * platform data. 131 + */ 132 + struct gpiod_lookup { 133 + struct list_head list; 134 + /* 135 + * name of the chip the GPIO belongs to 136 + */ 137 + const char *chip_label; 138 + /* 139 + * hardware number (i.e. relative to the chip) of the GPIO 140 + */ 141 + u16 chip_hwnum; 142 + /* 143 + * name of device that can claim this GPIO 144 + */ 145 + const char *dev_id; 146 + /* 147 + * name of the GPIO from the device's point of view 148 + */ 149 + const char *con_id; 150 + /* 151 + * index of the GPIO in case several GPIOs share the same name 152 + */ 153 + unsigned int idx; 154 + /* 155 + * mask of GPIOF_* values 156 + */ 157 + unsigned long flags; 158 + }; 159 + 160 + /* 161 + * Simple definition of a single GPIO under a con_id 162 + */ 163 + #define GPIO_LOOKUP(_chip_label, _chip_hwnum, _dev_id, _con_id, _flags) \ 164 + GPIO_LOOKUP_IDX(_chip_label, _chip_hwnum, _dev_id, _con_id, 0, _flags) 165 + 166 + /* 167 + * Use this macro if you need to have several GPIOs under the same con_id. 168 + * Each GPIO needs to use a different index and can be accessed using 169 + * gpiod_get_index() 170 + */ 171 + #define GPIO_LOOKUP_IDX(_chip_label, _chip_hwnum, _dev_id, _con_id, _idx, \ 172 + _flags) \ 173 + { \ 174 + .chip_label = _chip_label, \ 175 + .chip_hwnum = _chip_hwnum, \ 176 + .dev_id = _dev_id, \ 177 + .con_id = _con_id, \ 178 + .idx = _idx, \ 179 + .flags = _flags, \ 180 + } 181 + 182 + void gpiod_add_table(struct gpiod_lookup *table, size_t size); 183 + 184 + #endif
+24 -5
include/linux/of_gpio.h
··· 19 19 #include <linux/errno.h> 20 20 #include <linux/gpio.h> 21 21 #include <linux/of.h> 22 + #include <linux/gpio/consumer.h> 22 23 23 24 struct device_node; 24 25 ··· 48 47 return container_of(gc, struct of_mm_gpio_chip, gc); 49 48 } 50 49 51 - extern int of_get_named_gpio_flags(struct device_node *np, 50 + extern struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np, 52 51 const char *list_name, int index, enum of_gpio_flags *flags); 53 52 54 53 extern int of_mm_gpiochip_add(struct device_node *np, ··· 63 62 #else /* CONFIG_OF_GPIO */ 64 63 65 64 /* Drivers may not strictly depend on the GPIO support, so let them link. */ 66 - static inline int of_get_named_gpio_flags(struct device_node *np, 65 + static inline struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np, 67 66 const char *list_name, int index, enum of_gpio_flags *flags) 68 67 { 69 - return -ENOSYS; 68 + return ERR_PTR(-ENOSYS); 70 69 } 71 70 72 71 static inline int of_gpio_simple_xlate(struct gpio_chip *gc, ··· 80 79 static inline void of_gpiochip_remove(struct gpio_chip *gc) { } 81 80 82 81 #endif /* CONFIG_OF_GPIO */ 82 + 83 + static inline int of_get_named_gpio_flags(struct device_node *np, 84 + const char *list_name, int index, enum of_gpio_flags *flags) 85 + { 86 + struct gpio_desc *desc; 87 + desc = of_get_named_gpiod_flags(np, list_name, index, flags); 88 + 89 + if (IS_ERR(desc)) 90 + return PTR_ERR(desc); 91 + else 92 + return desc_to_gpio(desc); 93 + } 83 94 84 95 /** 85 96 * of_gpio_named_count() - Count GPIOs for a device ··· 130 117 } 131 118 132 119 /** 133 - * of_get_gpio_flags() - Get a GPIO number and flags to use with GPIO API 120 + * of_get_gpiod_flags() - Get a GPIO descriptor and flags to use with GPIO API 134 121 * @np: device node to get GPIO from 135 122 * @index: index of the GPIO 136 123 * @flags: a flags pointer to fill in 137 124 * 138 - * Returns GPIO number to use with Linux generic GPIO API, or one of the errno 125 + * Returns GPIO descriptor to use with Linux generic GPIO API, or a errno 139 126 * value on the error condition. If @flags is not NULL the function also fills 140 127 * in flags for the GPIO. 141 128 */ 129 + static inline struct gpio_desc *of_get_gpiod_flags(struct device_node *np, 130 + int index, enum of_gpio_flags *flags) 131 + { 132 + return of_get_named_gpiod_flags(np, "gpios", index, flags); 133 + } 134 + 142 135 static inline int of_get_gpio_flags(struct device_node *np, int index, 143 136 enum of_gpio_flags *flags) 144 137 {