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

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

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

The only changes hitting outside drivers/gpio are in the pin control
subsystem and these seem to have settled nicely in linux-next.

Development mistakes and catfights are nicely documented in the
reverts as you can see. The outcome of the ABI fight is that we're
working on a chardev ABI for GPIO now, where hope to show results for
the v4.5 kernel.

Summary of changes:

GPIO core:
- Define and handle flags for open drain/open collector and open
source/open emitter, also know as "single-ended" configurations.
- Generic request/free operations that handle calling out to the
(optional) pin control backend.
- Some refactoring related to an ABI change that did not happen, yet
provide useful.
- Added a real-time compliance checklist. Many GPIO chips have
irqchips, and need to think this over with the RT patches going
upstream.
- Restructure, fix and clean up Kconfig menus a bit.

New drivers:
- New driver for AMD Promony.
- New driver for ACCES 104-IDIO-16, a port-mapped I/O card,
ISA-style. Very retro.

Subdriver changes:
- OMAP changes to handle real time requirements.
- Handle trigger types for edge and level IRQs on PL061 properly. As
this hardware is very common it needs to set a proper example for
others to follow.
- Some container_of() cleanups.
- Delete the unused MSM driver in favor of the driver that is
embedded inside the pin control driver.
- Cleanup of the ath79 GPIO driver used by many, many OpenWRT router
targets.
- A consolidated IT87xx driver replacing the earlier very specific
IT8761e driver.
- Handle the TI TCA9539 in the PCA953x driver. Also handle ACPI
devices in this subdriver.
- Drop xilinx arch dependencies as these FPGAs seem to profilate over
a few different architectures. MIPS and ARM come to mind"

* tag 'gpio-v4.4-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio: (57 commits)
gpio: fix up SPI submenu
gpio: drop surplus I2C dependencies
gpio: drop surplus X86 dependencies
gpio: dt-bindings: document the official use of "ngpios"
gpio: MAINTAINERS: Add an entry for the ATH79 GPIO driver
gpio / ACPI: Allow shared GPIO event to be read via operation region
gpio: group port-mapped I/O drivers in a menu
gpio: Add ACCES 104-IDIO-16 driver maintainer entry
gpio: zynq: Document interrupt-controller DT binding
gpio: xilinx: Drop architecture dependencies
gpio: generic: Revert to old error handling in bgpio_map
gpio: add a real time compliance notes
Revert "gpio: add a real time compliance checklist"
gpio: Add GPIO support for the ACCES 104-IDIO-16
gpio: driver for AMD Promontory
gpio: xlp: Convert to use gpiolib irqchip helpers
gpio: add a real time compliance checklist
gpio/xilinx: enable for MIPS
gpiolib: Add and use OF_GPIO_SINGLE_ENDED flag
gpiolib: Split GPIO flags parsing and GPIO configuration
...

+1733 -1478
-26
Documentation/devicetree/bindings/gpio/gpio-msm.txt
··· 1 - MSM GPIO controller bindings 2 - 3 - Required properties: 4 - - compatible: 5 - - "qcom,msm-gpio" for MSM controllers 6 - - #gpio-cells : Should be two. 7 - - first cell is the pin number 8 - - second cell is used to specify optional parameters (unused) 9 - - gpio-controller : Marks the device node as a GPIO controller. 10 - - #interrupt-cells : Should be 2. 11 - - interrupt-controller: Mark the device node as an interrupt controller 12 - - interrupts : Specify the TLMM summary interrupt number 13 - - ngpio : Specify the number of MSM GPIOs 14 - 15 - Example: 16 - 17 - msmgpio: gpio@fd510000 { 18 - compatible = "qcom,msm-gpio"; 19 - gpio-controller; 20 - #gpio-cells = <2>; 21 - interrupt-controller; 22 - #interrupt-cells = <2>; 23 - reg = <0xfd510000 0x4000>; 24 - interrupts = <0 208 0>; 25 - ngpio = <150>; 26 - };
+1
Documentation/devicetree/bindings/gpio/gpio-pca953x.txt
··· 24 24 ti,tca6408 25 25 ti,tca6416 26 26 ti,tca6424 27 + ti,tca9539 27 28 exar,xra1202 28 29 29 30 Example:
+9
Documentation/devicetree/bindings/gpio/gpio-zynq.txt
··· 12 12 - interrupts : Interrupt specifier (see interrupt bindings for 13 13 details) 14 14 - interrupt-parent : Must be core interrupt controller 15 + - interrupt-controller : Marks the device node as an interrupt controller. 16 + - #interrupt-cells : Should be 2. The first cell is the GPIO number. 17 + The second cell bits[3:0] is used to specify trigger type and level flags: 18 + 1 = low-to-high edge triggered. 19 + 2 = high-to-low edge triggered. 20 + 4 = active high level-sensitive. 21 + 8 = active low level-sensitive. 15 22 - reg : Address and length of the register set for the device 16 23 17 24 Example: ··· 29 22 gpio-controller; 30 23 interrupt-parent = <&intc>; 31 24 interrupts = <0 20 4>; 25 + interrupt-controller; 26 + #interrupt-cells = <2>; 32 27 reg = <0xe000a000 0x1000>; 33 28 };
+39 -2
Documentation/devicetree/bindings/gpio/gpio.txt
··· 54 54 55 55 gpio-specifier may encode: bank, pin position inside the bank, 56 56 whether pin is open-drain and whether pin is logically inverted. 57 + 57 58 Exact meaning of each specifier cell is controller specific, and must 58 - be documented in the device tree binding for the device. Use the macros 59 - defined in include/dt-bindings/gpio/gpio.h whenever possible: 59 + be documented in the device tree binding for the device. 60 + 61 + Most controllers are however specifying a generic flag bitfield 62 + in the last cell, so for these, use the macros defined in 63 + include/dt-bindings/gpio/gpio.h whenever possible: 60 64 61 65 Example of a node using GPIOs: 62 66 ··· 70 66 71 67 GPIO_ACTIVE_HIGH is 0, so in this example gpio-specifier is "18 0" and encodes 72 68 GPIO pin number, and GPIO flags as accepted by the "qe_pio_e" gpio-controller. 69 + 70 + Optional standard bitfield specifiers for the last cell: 71 + 72 + - Bit 0: 0 means active high, 1 means active low 73 + - Bit 1: 1 means single-ended wiring, see: 74 + https://en.wikipedia.org/wiki/Single-ended_triode 75 + When used with active-low, this means open drain/collector, see: 76 + https://en.wikipedia.org/wiki/Open_collector 77 + When used with active-high, this means open source/emitter 73 78 74 79 1.1) GPIO specifier best practices 75 80 ---------------------------------- ··· 130 117 Every GPIO controller node must contain both an empty "gpio-controller" 131 118 property, and a #gpio-cells integer property, which indicates the number of 132 119 cells in a gpio-specifier. 120 + 121 + Optionally, a GPIO controller may have a "ngpios" property. This property 122 + indicates the number of in-use slots of available slots for GPIOs. The 123 + typical example is something like this: the hardware register is 32 bits 124 + wide, but only 18 of the bits have a physical counterpart. The driver is 125 + generally written so that all 32 bits can be used, but the IP block is reused 126 + in a lot of designs, some using all 32 bits, some using 18 and some using 127 + 12. In this case, setting "ngpios = <18>;" informs the driver that only the 128 + first 18 GPIOs, at local offset 0 .. 17, are in use. 129 + 130 + If these GPIOs do not happen to be the first N GPIOs at offset 0...N-1, an 131 + additional bitmask is needed to specify which GPIOs are actually in use, 132 + and which are dummies. The bindings for this case has not yet been 133 + specified, but should be specified if/when such hardware appears. 134 + 135 + Example: 136 + 137 + gpio-controller@00000000 { 138 + compatible = "foo"; 139 + reg = <0x00000000 0x1000>; 140 + gpio-controller; 141 + #gpio-cells = <2>; 142 + ngpios = <18>; 143 + } 133 144 134 145 The GPIO chip may contain GPIO hog definitions. GPIO hogging is a mechanism 135 146 providing automatic GPIO request and configuration as part of the
+80
Documentation/gpio/driver.txt
··· 62 62 requested as GPIOs. They can use gpiochip_is_requested(), which returns either 63 63 NULL or the label associated with that GPIO when it was requested. 64 64 65 + RT_FULL: GPIO driver should not use spinlock_t or any sleepable APIs 66 + (like PM runtime) in its gpio_chip implementation (.get/.set and direction 67 + control callbacks) if it is expected to call GPIO APIs from atomic context 68 + on -RT (inside hard IRQ handlers and similar contexts). Normally this should 69 + not be required. 65 70 66 71 GPIO drivers providing IRQs 67 72 --------------------------- ··· 77 72 The IRQ portions of the GPIO block are implemented using an irqchip, using 78 73 the header <linux/irq.h>. So basically such a driver is utilizing two sub- 79 74 systems simultaneously: gpio and irq. 75 + 76 + RT_FULL: GPIO driver should not use spinlock_t or any sleepable APIs 77 + (like PM runtime) as part of its irq_chip implementation on -RT. 78 + - spinlock_t should be replaced with raw_spinlock_t [1]. 79 + - If sleepable APIs have to be used, these can be done from the .irq_bus_lock() 80 + and .irq_bus_unlock() callbacks, as these are the only slowpath callbacks 81 + on an irqchip. Create the callbacks if needed [2]. 80 82 81 83 GPIO irqchips usually fall in one of two categories: 82 84 ··· 104 92 105 93 Chained GPIO irqchips typically can NOT set the .can_sleep flag on 106 94 struct gpio_chip, as everything happens directly in the callbacks. 95 + 96 + RT_FULL: Note, chained IRQ handlers will not be forced threaded on -RT. 97 + As result, spinlock_t or any sleepable APIs (like PM runtime) can't be used 98 + in chained IRQ handler. 99 + if required (and if it can't be converted to the nested threaded GPIO irqchip) 100 + - chained IRQ handler can be converted to generic irq handler and this way 101 + it will be threaded IRQ handler on -RT and hard IRQ handler on non-RT 102 + (for example, see [3]). 103 + Know W/A: The generic_handle_irq() is expected to be called with IRQ disabled, 104 + so IRQ core will complain if it will be called from IRQ handler wich is forced 105 + thread. The "fake?" raw lock can be used to W/A this problem: 106 + 107 + raw_spinlock_t wa_lock; 108 + static irqreturn_t omap_gpio_irq_handler(int irq, void *gpiobank) 109 + unsigned long wa_lock_flags; 110 + raw_spin_lock_irqsave(&bank->wa_lock, wa_lock_flags); 111 + generic_handle_irq(irq_find_mapping(bank->chip.irqdomain, bit)); 112 + raw_spin_unlock_irqrestore(&bank->wa_lock, wa_lock_flags); 113 + 114 + * GENERIC CHAINED GPIO irqchips: these are the same as "CHAINED GPIO irqchips", 115 + but chained IRQ handlers are not used. Instead GPIO IRQs dispatching is 116 + performed by generic IRQ handler which is configured using request_irq(). 117 + The GPIO irqchip will then end up calling something like this sequence in 118 + its interrupt handler: 119 + 120 + static irqreturn_t gpio_rcar_irq_handler(int irq, void *dev_id) 121 + for each detected GPIO IRQ 122 + generic_handle_irq(...); 123 + 124 + RT_FULL: Such kind of handlers will be forced threaded on -RT, as result IRQ 125 + core will complain that generic_handle_irq() is called with IRQ enabled and 126 + the same W/A as for "CHAINED GPIO irqchips" can be applied. 107 127 108 128 * NESTED THREADED GPIO irqchips: these are off-chip GPIO expanders and any 109 129 other GPIO irqchip residing on the other side of a sleeping bus. Of course ··· 177 133 the irqchip can initialize. E.g. .dev and .can_sleep shall be set up 178 134 properly. 179 135 136 + - Nominally set all handlers to handle_bad_irq() in the setup call and pass 137 + handle_bad_irq() as flow handler parameter in gpiochip_irqchip_add() if it is 138 + expected for GPIO driver that irqchip .set_type() callback have to be called 139 + before using/enabling GPIO IRQ. Then set the handler to handle_level_irq() 140 + and/or handle_edge_irq() in the irqchip .set_type() callback depending on 141 + what your controller supports. 142 + 180 143 It is legal for any IRQ consumer to request an IRQ from any irqchip no matter 181 144 if that is a combined GPIO+IRQ driver. The basic premise is that gpio_chip and 182 145 irq_chip are orthogonal, and offering their services independent of each ··· 220 169 typically be called in the .startup() and .shutdown() callbacks from the 221 170 irqchip. 222 171 172 + Real-Time compliance for GPIO IRQ chips 173 + --------------------------------------- 174 + 175 + Any provider of irqchips needs to be carefully tailored to support Real Time 176 + preemption. It is desireable that all irqchips in the GPIO subsystem keep this 177 + in mind and does the proper testing to assure they are real time-enabled. 178 + So, pay attention on above " RT_FULL:" notes, please. 179 + The following is a checklist to follow when preparing a driver for real 180 + time-compliance: 181 + 182 + - ensure spinlock_t is not used as part irq_chip implementation; 183 + - ensure that sleepable APIs are not used as part irq_chip implementation. 184 + If sleepable APIs have to be used, these can be done from the .irq_bus_lock() 185 + and .irq_bus_unlock() callbacks; 186 + - Chained GPIO irqchips: ensure spinlock_t or any sleepable APIs are not used 187 + from chained IRQ handler; 188 + - Generic chained GPIO irqchips: take care about generic_handle_irq() calls and 189 + apply corresponding W/A; 190 + - Chained GPIO irqchips: get rid of chained IRQ handler and use generic irq 191 + handler if possible :) 192 + - regmap_mmio: Sry, but you are in trouble :( if MMIO regmap is used as for 193 + GPIO IRQ chip implementation; 194 + - Test your driver with the appropriate in-kernel real time test cases for both 195 + level and edge IRQs. 196 + 223 197 224 198 Requesting self-owned GPIO pins 225 199 ------------------------------- ··· 266 190 These functions must be used with care since they do not affect module use 267 191 count. Do not use the functions to request gpio descriptors not owned by the 268 192 calling driver. 193 + 194 + [1] http://www.spinics.net/lists/linux-omap/msg120425.html 195 + [2] https://lkml.org/lkml/2015/9/25/494 196 + [3] https://lkml.org/lkml/2015/9/25/495
+14
MAINTAINERS
··· 240 240 S: Maintained 241 241 F: drivers/hwmon/abituguru3.c 242 242 243 + ACCES 104-IDIO-16 GPIO DRIVER 244 + M: "William Breathitt Gray" <vilhelm.gray@gmail.com> 245 + L: linux-gpio@vger.kernel.org 246 + S: Maintained 247 + F: drivers/gpio/gpio-104-idio-16.c 248 + 243 249 ACENIC DRIVER 244 250 M: Jes Sorensen <jes@trained-monkey.org> 245 251 L: linux-acenic@sunsite.dk ··· 1785 1779 S: Supported 1786 1780 F: Documentation/aoe/ 1787 1781 F: drivers/block/aoe/ 1782 + 1783 + ATHEROS 71XX/9XXX GPIO DRIVER 1784 + M: Alban Bedel <albeu@free.fr> 1785 + W: https://github.com/AlbanBedel/linux 1786 + T: git git://github.com/AlbanBedel/linux 1787 + S: Maintained 1788 + F: drivers/gpio/gpio-ath79.c 1789 + F: Documentation/devicetree/bindings/gpio/gpio-ath79.txt 1788 1790 1789 1791 ATHEROS ATH GENERIC UTILITIES 1790 1792 M: "Luis R. Rodriguez" <mcgrof@do-not-panic.com>
+103 -93
drivers/gpio/Kconfig
··· 119 119 120 120 If driver is built as a module it will be called gpio-altera. 121 121 122 + config GPIO_AMDPT 123 + tristate "AMD Promontory GPIO support" 124 + depends on ACPI 125 + help 126 + driver for GPIO functionality on Promontory IOHub 127 + Require ACPI ASL code to enumerate as a platform device. 128 + 122 129 config GPIO_BCM_KONA 123 130 bool "Broadcom Kona GPIO" 124 131 depends on OF_GPIO && (ARCH_BCM_MOBILE || COMPILE_TEST) ··· 183 176 help 184 177 Say yes here to support the GPIO controller on Axis ETRAX FS SoCs. 185 178 186 - config GPIO_F7188X 187 - tristate "F71869, F71869A, F71882FG and F71889F GPIO support" 188 - depends on X86 189 - help 190 - This option enables support for GPIOs found on Fintek Super-I/O 191 - chips F71869, F71869A, F71882FG and F71889F. 192 - 193 - To compile this driver as a module, choose M here: the module will 194 - be called f7188x-gpio. 195 - 196 179 config GPIO_GE_FPGA 197 180 bool "GE FPGA based GPIO" 198 181 depends on GE_FPGA ··· 231 234 IOP32X or IOP33X. 232 235 233 236 If unsure, say N. 234 - 235 - config GPIO_IT8761E 236 - tristate "IT8761E GPIO support" 237 - depends on X86 # unconditional access to IO space. 238 - help 239 - Say yes here to support GPIO functionality of IT8761E super I/O chip. 240 237 241 238 config GPIO_LOONGSON 242 239 bool "Loongson-2/3 GPIO support" ··· 287 296 help 288 297 Say Y here if you're going to use hardware that connects to the 289 298 MPC512x/831x/834x/837x/8572/8610 GPIOs. 290 - 291 - config GPIO_MSM_V2 292 - tristate "Qualcomm MSM GPIO v2" 293 - depends on GPIOLIB && OF && ARCH_QCOM 294 - help 295 - Say yes here to support the GPIO interface on ARM v7 based 296 - Qualcomm MSM chips. Most of the pins on the MSM can be 297 - selected for GPIO, and are controlled by this driver. 298 299 299 300 config GPIO_MVEBU 300 301 def_bool y ··· 351 368 Legacy GPIO support. Use only for platforms without support for 352 369 pinctrl. 353 370 354 - config GPIO_SCH 355 - tristate "Intel SCH/TunnelCreek/Centerton/Quark X1000 GPIO" 356 - depends on PCI && X86 357 - select MFD_CORE 358 - select LPC_SCH 359 - help 360 - Say yes here to support GPIO interface on Intel Poulsbo SCH, 361 - Intel Tunnel Creek processor, Intel Centerton processor or 362 - Intel Quark X1000 SoC. 363 - 364 - The Intel SCH contains a total of 14 GPIO pins. Ten GPIOs are 365 - powered by the core power rail and are turned off during sleep 366 - modes (S3 and higher). The remaining four GPIOs are powered by 367 - the Intel SCH suspend power supply. These GPIOs remain 368 - active during S3. The suspend powered GPIOs can be used to wake the 369 - system from the Suspend-to-RAM state. 370 - 371 - The Intel Tunnel Creek processor has 5 GPIOs powered by the 372 - core power rail and 9 from suspend power supply. 373 - 374 - The Intel Centerton processor has a total of 30 GPIO pins. 375 - Twenty-one are powered by the core power rail and 9 from the 376 - suspend power supply. 377 - 378 - The Intel Quark X1000 SoC has 2 GPIOs powered by the core 379 - power well and 6 from the suspend power well. 380 - 381 - config GPIO_SCH311X 382 - tristate "SMSC SCH311x SuperI/O GPIO" 383 - help 384 - Driver to enable the GPIOs found on SMSC SMSC SCH3112, SCH3114 and 385 - SCH3116 "Super I/O" chipsets. 386 - 387 - To compile this driver as a module, choose M here: the module will 388 - be called gpio-sch311x. 389 - 390 371 config GPIO_SPEAR_SPICS 391 372 bool "ST SPEAr13xx SPI Chip Select as GPIO support" 392 373 depends on PLAT_SPEAR ··· 386 439 bool 387 440 select GENERIC_IRQ_CHIP 388 441 select OF_GPIO 389 - 390 - config GPIO_TS5500 391 - tristate "TS-5500 DIO blocks and compatibles" 392 - depends on TS5500 || COMPILE_TEST 393 - help 394 - This driver supports Digital I/O exposed by pin blocks found on some 395 - Technologic Systems platforms. It includes, but is not limited to, 3 396 - blocks of the TS-5500: DIO1, DIO2 and the LCD port, and the TS-5600 397 - LCD port. 398 442 399 443 config GPIO_TZ1090 400 444 bool "Toumaz Xenif TZ1090 GPIO support" ··· 446 508 447 509 config GPIO_XILINX 448 510 tristate "Xilinx GPIO support" 449 - depends on OF_GPIO && (PPC || MICROBLAZE || ARCH_ZYNQ || X86) 511 + depends on OF_GPIO 450 512 help 451 513 Say yes here to support the Xilinx FPGA GPIO device 452 514 453 515 config GPIO_XLP 454 516 tristate "Netlogic XLP GPIO support" 455 - depends on CPU_XLP 517 + depends on CPU_XLP && OF_GPIO 456 518 select GPIOLIB_IRQCHIP 457 519 help 458 520 This driver provides support for GPIO interface on Netlogic XLP MIPS64 ··· 483 545 help 484 546 Say yes here to support Xilinx Zynq GPIO controller. 485 547 548 + config GPIO_ZX 549 + bool "ZTE ZX GPIO support" 550 + select GPIOLIB_IRQCHIP 551 + help 552 + Say yes here to support the GPIO device on ZTE ZX SoCs. 553 + 554 + endmenu 555 + 556 + menu "Port-mapped I/O GPIO drivers" 557 + depends on X86 # Unconditional I/O space access 558 + 559 + config GPIO_104_IDIO_16 560 + tristate "ACCES 104-IDIO-16 GPIO support" 561 + help 562 + Enables GPIO support for the ACCES 104-IDIO-16 family. 563 + 564 + config GPIO_F7188X 565 + tristate "F71869, F71869A, F71882FG and F71889F GPIO support" 566 + help 567 + This option enables support for GPIOs found on Fintek Super-I/O 568 + chips F71869, F71869A, F71882FG and F71889F. 569 + 570 + To compile this driver as a module, choose M here: the module will 571 + be called f7188x-gpio. 572 + 573 + config GPIO_IT87 574 + tristate "IT87xx GPIO support" 575 + help 576 + Say yes here to support GPIO functionality of IT87xx Super I/O chips. 577 + 578 + This driver is tested with ITE IT8728 and IT8732 Super I/O chips, and 579 + supports the IT8761E Super I/O chip as well. 580 + 581 + To compile this driver as a module, choose M here: the module will 582 + be called gpio_it87 583 + 584 + config GPIO_SCH 585 + tristate "Intel SCH/TunnelCreek/Centerton/Quark X1000 GPIO" 586 + depends on PCI 587 + select MFD_CORE 588 + select LPC_SCH 589 + help 590 + Say yes here to support GPIO interface on Intel Poulsbo SCH, 591 + Intel Tunnel Creek processor, Intel Centerton processor or 592 + Intel Quark X1000 SoC. 593 + 594 + The Intel SCH contains a total of 14 GPIO pins. Ten GPIOs are 595 + powered by the core power rail and are turned off during sleep 596 + modes (S3 and higher). The remaining four GPIOs are powered by 597 + the Intel SCH suspend power supply. These GPIOs remain 598 + active during S3. The suspend powered GPIOs can be used to wake the 599 + system from the Suspend-to-RAM state. 600 + 601 + The Intel Tunnel Creek processor has 5 GPIOs powered by the 602 + core power rail and 9 from suspend power supply. 603 + 604 + The Intel Centerton processor has a total of 30 GPIO pins. 605 + Twenty-one are powered by the core power rail and 9 from the 606 + suspend power supply. 607 + 608 + The Intel Quark X1000 SoC has 2 GPIOs powered by the core 609 + power well and 6 from the suspend power well. 610 + 611 + config GPIO_SCH311X 612 + tristate "SMSC SCH311x SuperI/O GPIO" 613 + help 614 + Driver to enable the GPIOs found on SMSC SMSC SCH3112, SCH3114 and 615 + SCH3116 "Super I/O" chipsets. 616 + 617 + To compile this driver as a module, choose M here: the module will 618 + be called gpio-sch311x. 619 + 620 + config GPIO_TS5500 621 + tristate "TS-5500 DIO blocks and compatibles" 622 + depends on TS5500 || COMPILE_TEST 623 + help 624 + This driver supports Digital I/O exposed by pin blocks found on some 625 + Technologic Systems platforms. It includes, but is not limited to, 3 626 + blocks of the TS-5500: DIO1, DIO2 and the LCD port, and the TS-5600 627 + LCD port. 628 + 486 629 endmenu 487 630 488 631 menu "I2C GPIO expanders" ··· 571 552 572 553 config GPIO_ADP5588 573 554 tristate "ADP5588 I2C GPIO expander" 574 - depends on I2C 575 555 help 576 556 This option enables support for 18 GPIOs found 577 557 on Analog Devices ADP5588 GPIO Expanders. ··· 584 566 585 567 config GPIO_ADNP 586 568 tristate "Avionic Design N-bit GPIO expander" 587 - depends on I2C && OF_GPIO 569 + depends on OF_GPIO 588 570 select GPIOLIB_IRQCHIP 589 571 help 590 572 This option enables support for N GPIOs found on Avionic Design ··· 596 578 597 579 config GPIO_MAX7300 598 580 tristate "Maxim MAX7300 GPIO expander" 599 - depends on I2C 600 581 select GPIO_MAX730X 601 582 help 602 583 GPIO driver for Maxim MAX7300 I2C-based GPIO expander. 603 584 604 585 config GPIO_MAX732X 605 586 tristate "MAX7319, MAX7320-7327 I2C Port Expanders" 606 - depends on I2C 607 587 help 608 588 Say yes here to support the MAX7319, MAX7320-7327 series of I2C 609 589 Port Expanders. Each IO port on these chips has a fixed role of ··· 634 618 635 619 config GPIO_PCA953X 636 620 tristate "PCA95[357]x, PCA9698, TCA64xx, and MAX7310 I/O ports" 637 - depends on I2C 638 621 help 639 622 Say yes here to provide access to several register-oriented 640 623 SMBus I/O expanders, made mostly by NXP or TI. Compatible ··· 661 646 662 647 config GPIO_PCF857X 663 648 tristate "PCF857x, PCA{85,96}7x, and MAX732[89] I2C GPIO expanders" 664 - depends on I2C 665 649 select GPIOLIB_IRQCHIP 666 650 select IRQ_DOMAIN 667 651 help ··· 990 976 991 977 config GPIO_74X164 992 978 tristate "74x164 serial-in/parallel-out 8-bits shift register" 993 - depends on SPI_MASTER && OF 979 + depends on OF 994 980 help 995 981 Driver for 74x164 compatible serial-in/parallel-out 8-outputs 996 982 shift registers. This driver can be used to provide access ··· 998 984 999 985 config GPIO_MAX7301 1000 986 tristate "Maxim MAX7301 GPIO expander" 1001 - depends on SPI_MASTER 1002 987 select GPIO_MAX730X 1003 988 help 1004 989 GPIO driver for Maxim MAX7301 SPI-based GPIO expander. 1005 990 991 + config GPIO_MC33880 992 + tristate "Freescale MC33880 high-side/low-side switch" 993 + help 994 + SPI driver for Freescale MC33880 high-side/low-side switch. 995 + This provides GPIO interface supporting inputs and outputs. 996 + 997 + endmenu 998 + 999 + menu "SPI or I2C GPIO expanders" 1000 + depends on (SPI_MASTER && !I2C) || I2C 1001 + 1006 1002 config GPIO_MCP23S08 1007 1003 tristate "Microchip MCP23xxx I/O expander" 1008 - depends on (SPI_MASTER && !I2C) || I2C 1009 1004 help 1010 1005 SPI/I2C driver for Microchip MCP23S08/MCP23S17/MCP23008/MCP23017 1011 1006 I/O expanders. 1012 1007 This provides a GPIO interface supporting inputs and outputs. 1013 1008 The I2C versions of the chips can be used as interrupt-controller. 1014 - 1015 - config GPIO_MC33880 1016 - tristate "Freescale MC33880 high-side/low-side switch" 1017 - depends on SPI_MASTER 1018 - help 1019 - SPI driver for Freescale MC33880 high-side/low-side switch. 1020 - This provides GPIO interface supporting inputs and outputs. 1021 - 1022 - config GPIO_ZX 1023 - bool "ZTE ZX GPIO support" 1024 - select GPIOLIB_IRQCHIP 1025 - help 1026 - Say yes here to support the GPIO device on ZTE ZX SoCs. 1027 1009 1028 1010 endmenu 1029 1011
+3 -2
drivers/gpio/Makefile
··· 12 12 # Device drivers. Generally keep list sorted alphabetically 13 13 obj-$(CONFIG_GPIO_GENERIC) += gpio-generic.o 14 14 15 + obj-$(CONFIG_GPIO_104_IDIO_16) += gpio-104-idio-16.o 15 16 obj-$(CONFIG_GPIO_74X164) += gpio-74x164.o 16 17 obj-$(CONFIG_GPIO_74XX_MMIO) += gpio-74xx-mmio.o 17 18 obj-$(CONFIG_GPIO_ADNP) += gpio-adnp.o ··· 20 19 obj-$(CONFIG_GPIO_ADP5588) += gpio-adp5588.o 21 20 obj-$(CONFIG_GPIO_ALTERA) += gpio-altera.o 22 21 obj-$(CONFIG_GPIO_AMD8111) += gpio-amd8111.o 22 + obj-$(CONFIG_GPIO_AMDPT) += gpio-amdpt.o 23 23 obj-$(CONFIG_GPIO_ARIZONA) += gpio-arizona.o 24 24 obj-$(CONFIG_ATH79) += gpio-ath79.o 25 25 obj-$(CONFIG_GPIO_BCM_KONA) += gpio-bcm-kona.o ··· 42 40 obj-$(CONFIG_GPIO_GRGPIO) += gpio-grgpio.o 43 41 obj-$(CONFIG_GPIO_ICH) += gpio-ich.o 44 42 obj-$(CONFIG_GPIO_IOP) += gpio-iop.o 45 - obj-$(CONFIG_GPIO_IT8761E) += gpio-it8761e.o 43 + obj-$(CONFIG_GPIO_IT87) += gpio-it87.o 46 44 obj-$(CONFIG_GPIO_JANZ_TTL) += gpio-janz-ttl.o 47 45 obj-$(CONFIG_GPIO_KEMPLD) += gpio-kempld.o 48 46 obj-$(CONFIG_ARCH_KS8695) += gpio-ks8695.o ··· 66 64 obj-$(CONFIG_GPIO_MPC5200) += gpio-mpc5200.o 67 65 obj-$(CONFIG_GPIO_MPC8XXX) += gpio-mpc8xxx.o 68 66 obj-$(CONFIG_GPIO_MSIC) += gpio-msic.o 69 - obj-$(CONFIG_GPIO_MSM_V2) += gpio-msm-v2.o 70 67 obj-$(CONFIG_GPIO_MVEBU) += gpio-mvebu.o 71 68 obj-$(CONFIG_GPIO_MXC) += gpio-mxc.o 72 69 obj-$(CONFIG_GPIO_MXS) += gpio-mxs.o
+216
drivers/gpio/gpio-104-idio-16.c
··· 1 + /* 2 + * GPIO driver for the ACCES 104-IDIO-16 family 3 + * Copyright (C) 2015 William Breathitt Gray 4 + * 5 + * This program is free software; you can redistribute it and/or modify 6 + * it under the terms of the GNU General Public License, version 2, as 7 + * published by the Free Software Foundation. 8 + * 9 + * This program is distributed in the hope that it will be useful, but 10 + * WITHOUT ANY WARRANTY; without even the implied warranty of 11 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 + * General Public License for more details. 13 + */ 14 + #include <linux/device.h> 15 + #include <linux/errno.h> 16 + #include <linux/gpio/driver.h> 17 + #include <linux/io.h> 18 + #include <linux/ioport.h> 19 + #include <linux/kernel.h> 20 + #include <linux/module.h> 21 + #include <linux/moduleparam.h> 22 + #include <linux/platform_device.h> 23 + #include <linux/spinlock.h> 24 + 25 + static unsigned idio_16_base; 26 + module_param(idio_16_base, uint, 0); 27 + MODULE_PARM_DESC(idio_16_base, "ACCES 104-IDIO-16 base address"); 28 + 29 + /** 30 + * struct idio_16_gpio - GPIO device private data structure 31 + * @chip: instance of the gpio_chip 32 + * @lock: synchronization lock to prevent gpio_set race conditions 33 + * @base: base port address of the GPIO device 34 + * @extent: extent of port address region of the GPIO device 35 + * @out_state: output bits state 36 + */ 37 + struct idio_16_gpio { 38 + struct gpio_chip chip; 39 + spinlock_t lock; 40 + unsigned base; 41 + unsigned extent; 42 + unsigned out_state; 43 + }; 44 + 45 + static int idio_16_gpio_get_direction(struct gpio_chip *chip, unsigned offset) 46 + { 47 + if (offset > 15) 48 + return 1; 49 + 50 + return 0; 51 + } 52 + 53 + static int idio_16_gpio_direction_input(struct gpio_chip *chip, unsigned offset) 54 + { 55 + return 0; 56 + } 57 + 58 + static int idio_16_gpio_direction_output(struct gpio_chip *chip, 59 + unsigned offset, int value) 60 + { 61 + chip->set(chip, offset, value); 62 + return 0; 63 + } 64 + 65 + static struct idio_16_gpio *to_idio16gpio(struct gpio_chip *gc) 66 + { 67 + return container_of(gc, struct idio_16_gpio, chip); 68 + } 69 + 70 + static int idio_16_gpio_get(struct gpio_chip *chip, unsigned offset) 71 + { 72 + struct idio_16_gpio *const idio16gpio = to_idio16gpio(chip); 73 + const unsigned BIT_MASK = 1U << (offset-16); 74 + 75 + if (offset < 16) 76 + return -EINVAL; 77 + 78 + if (offset < 24) 79 + return !!(inb(idio16gpio->base + 1) & BIT_MASK); 80 + 81 + return !!(inb(idio16gpio->base + 5) & (BIT_MASK>>8)); 82 + } 83 + 84 + static void idio_16_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 85 + { 86 + struct idio_16_gpio *const idio16gpio = to_idio16gpio(chip); 87 + const unsigned BIT_MASK = 1U << offset; 88 + unsigned long flags; 89 + 90 + if (offset > 15) 91 + return; 92 + 93 + spin_lock_irqsave(&idio16gpio->lock, flags); 94 + 95 + if (value) 96 + idio16gpio->out_state |= BIT_MASK; 97 + else 98 + idio16gpio->out_state &= ~BIT_MASK; 99 + 100 + if (offset > 7) 101 + outb(idio16gpio->out_state >> 8, idio16gpio->base + 4); 102 + else 103 + outb(idio16gpio->out_state, idio16gpio->base); 104 + 105 + spin_unlock_irqrestore(&idio16gpio->lock, flags); 106 + } 107 + 108 + static int __init idio_16_probe(struct platform_device *pdev) 109 + { 110 + struct device *dev = &pdev->dev; 111 + struct idio_16_gpio *idio16gpio; 112 + int err; 113 + 114 + const unsigned BASE = idio_16_base; 115 + const unsigned EXTENT = 8; 116 + const char *const NAME = dev_name(dev); 117 + 118 + idio16gpio = devm_kzalloc(dev, sizeof(*idio16gpio), GFP_KERNEL); 119 + if (!idio16gpio) 120 + return -ENOMEM; 121 + 122 + if (!request_region(BASE, EXTENT, NAME)) { 123 + dev_err(dev, "Unable to lock %s port addresses (0x%X-0x%X)\n", 124 + NAME, BASE, BASE + EXTENT); 125 + err = -EBUSY; 126 + goto err_lock_io_port; 127 + } 128 + 129 + idio16gpio->chip.label = NAME; 130 + idio16gpio->chip.dev = dev; 131 + idio16gpio->chip.owner = THIS_MODULE; 132 + idio16gpio->chip.base = -1; 133 + idio16gpio->chip.ngpio = 32; 134 + idio16gpio->chip.get_direction = idio_16_gpio_get_direction; 135 + idio16gpio->chip.direction_input = idio_16_gpio_direction_input; 136 + idio16gpio->chip.direction_output = idio_16_gpio_direction_output; 137 + idio16gpio->chip.get = idio_16_gpio_get; 138 + idio16gpio->chip.set = idio_16_gpio_set; 139 + idio16gpio->base = BASE; 140 + idio16gpio->extent = EXTENT; 141 + idio16gpio->out_state = 0xFFFF; 142 + 143 + spin_lock_init(&idio16gpio->lock); 144 + 145 + dev_set_drvdata(dev, idio16gpio); 146 + 147 + err = gpiochip_add(&idio16gpio->chip); 148 + if (err) { 149 + dev_err(dev, "GPIO registering failed (%d)\n", err); 150 + goto err_gpio_register; 151 + } 152 + 153 + return 0; 154 + 155 + err_gpio_register: 156 + release_region(BASE, EXTENT); 157 + err_lock_io_port: 158 + return err; 159 + } 160 + 161 + static int idio_16_remove(struct platform_device *pdev) 162 + { 163 + struct idio_16_gpio *const idio16gpio = platform_get_drvdata(pdev); 164 + 165 + gpiochip_remove(&idio16gpio->chip); 166 + release_region(idio16gpio->base, idio16gpio->extent); 167 + 168 + return 0; 169 + } 170 + 171 + static struct platform_device *idio_16_device; 172 + 173 + static struct platform_driver idio_16_driver = { 174 + .driver = { 175 + .name = "104-idio-16" 176 + }, 177 + .remove = idio_16_remove 178 + }; 179 + 180 + static void __exit idio_16_exit(void) 181 + { 182 + platform_device_unregister(idio_16_device); 183 + platform_driver_unregister(&idio_16_driver); 184 + } 185 + 186 + static int __init idio_16_init(void) 187 + { 188 + int err; 189 + 190 + idio_16_device = platform_device_alloc(idio_16_driver.driver.name, -1); 191 + if (!idio_16_device) 192 + return -ENOMEM; 193 + 194 + err = platform_device_add(idio_16_device); 195 + if (err) 196 + goto err_platform_device; 197 + 198 + err = platform_driver_probe(&idio_16_driver, idio_16_probe); 199 + if (err) 200 + goto err_platform_driver; 201 + 202 + return 0; 203 + 204 + err_platform_driver: 205 + platform_device_del(idio_16_device); 206 + err_platform_device: 207 + platform_device_put(idio_16_device); 208 + return err; 209 + } 210 + 211 + module_init(idio_16_init); 212 + module_exit(idio_16_exit); 213 + 214 + MODULE_AUTHOR("William Breathitt Gray <vilhelm.gray@gmail.com>"); 215 + MODULE_DESCRIPTION("ACCES 104-IDIO-16 GPIO driver"); 216 + MODULE_LICENSE("GPL");
+10 -5
drivers/gpio/gpio-altera.c
··· 42 42 int mapped_irq; 43 43 }; 44 44 45 + static struct altera_gpio_chip *to_altera(struct gpio_chip *gc) 46 + { 47 + return container_of(gc, struct altera_gpio_chip, mmchip.gc); 48 + } 49 + 45 50 static void altera_gpio_irq_unmask(struct irq_data *d) 46 51 { 47 52 struct altera_gpio_chip *altera_gc; ··· 54 49 unsigned long flags; 55 50 u32 intmask; 56 51 57 - altera_gc = irq_data_get_irq_chip_data(d); 52 + altera_gc = to_altera(irq_data_get_irq_chip_data(d)); 58 53 mm_gc = &altera_gc->mmchip; 59 54 60 55 spin_lock_irqsave(&altera_gc->gpio_lock, flags); ··· 72 67 unsigned long flags; 73 68 u32 intmask; 74 69 75 - altera_gc = irq_data_get_irq_chip_data(d); 70 + altera_gc = to_altera(irq_data_get_irq_chip_data(d)); 76 71 mm_gc = &altera_gc->mmchip; 77 72 78 73 spin_lock_irqsave(&altera_gc->gpio_lock, flags); ··· 92 87 { 93 88 struct altera_gpio_chip *altera_gc; 94 89 95 - altera_gc = irq_data_get_irq_chip_data(d); 90 + altera_gc = to_altera(irq_data_get_irq_chip_data(d)); 96 91 97 92 if (type == IRQ_TYPE_NONE) 98 93 return 0; ··· 215 210 unsigned long status; 216 211 int i; 217 212 218 - altera_gc = irq_desc_get_handler_data(desc); 213 + altera_gc = to_altera(irq_desc_get_handler_data(desc)); 219 214 chip = irq_desc_get_chip(desc); 220 215 mm_gc = &altera_gc->mmchip; 221 216 irqdomain = altera_gc->mmchip.gc.irqdomain; ··· 244 239 unsigned long status; 245 240 int i; 246 241 247 - altera_gc = irq_desc_get_handler_data(desc); 242 + altera_gc = to_altera(irq_desc_get_handler_data(desc)); 248 243 chip = irq_desc_get_chip(desc); 249 244 mm_gc = &altera_gc->mmchip; 250 245 irqdomain = altera_gc->mmchip.gc.irqdomain;
+261
drivers/gpio/gpio-amdpt.c
··· 1 + /* 2 + * AMD Promontory GPIO driver 3 + * 4 + * Copyright (C) 2015 ASMedia Technology Inc. 5 + * Author: YD Tseng <yd_tseng@asmedia.com.tw> 6 + * 7 + * This program is free software; you can redistribute it and/or modify 8 + * it under the terms of the GNU General Public License version 2 as 9 + * published by the Free Software Foundation. 10 + */ 11 + 12 + #include <linux/kernel.h> 13 + #include <linux/module.h> 14 + #include <linux/gpio/driver.h> 15 + #include <linux/spinlock.h> 16 + #include <linux/acpi.h> 17 + #include <linux/platform_device.h> 18 + 19 + #define PT_TOTAL_GPIO 8 20 + 21 + /* PCI-E MMIO register offsets */ 22 + #define PT_DIRECTION_REG 0x00 23 + #define PT_INPUTDATA_REG 0x04 24 + #define PT_OUTPUTDATA_REG 0x08 25 + #define PT_CLOCKRATE_REG 0x0C 26 + #define PT_SYNC_REG 0x28 27 + 28 + struct pt_gpio_chip { 29 + struct gpio_chip gc; 30 + void __iomem *reg_base; 31 + spinlock_t lock; 32 + }; 33 + 34 + #define to_pt_gpio(c) container_of(c, struct pt_gpio_chip, gc) 35 + 36 + static int pt_gpio_request(struct gpio_chip *gc, unsigned offset) 37 + { 38 + struct pt_gpio_chip *pt_gpio = to_pt_gpio(gc); 39 + unsigned long flags; 40 + u32 using_pins; 41 + 42 + dev_dbg(gc->dev, "pt_gpio_request offset=%x\n", offset); 43 + 44 + spin_lock_irqsave(&pt_gpio->lock, flags); 45 + 46 + using_pins = readl(pt_gpio->reg_base + PT_SYNC_REG); 47 + if (using_pins & BIT(offset)) { 48 + dev_warn(gc->dev, "PT GPIO pin %x reconfigured\n", 49 + offset); 50 + spin_unlock_irqrestore(&pt_gpio->lock, flags); 51 + return -EINVAL; 52 + } 53 + 54 + writel(using_pins | BIT(offset), pt_gpio->reg_base + PT_SYNC_REG); 55 + 56 + spin_unlock_irqrestore(&pt_gpio->lock, flags); 57 + 58 + return 0; 59 + } 60 + 61 + static void pt_gpio_free(struct gpio_chip *gc, unsigned offset) 62 + { 63 + struct pt_gpio_chip *pt_gpio = to_pt_gpio(gc); 64 + unsigned long flags; 65 + u32 using_pins; 66 + 67 + spin_lock_irqsave(&pt_gpio->lock, flags); 68 + 69 + using_pins = readl(pt_gpio->reg_base + PT_SYNC_REG); 70 + using_pins &= ~BIT(offset); 71 + writel(using_pins, pt_gpio->reg_base + PT_SYNC_REG); 72 + 73 + spin_unlock_irqrestore(&pt_gpio->lock, flags); 74 + 75 + dev_dbg(gc->dev, "pt_gpio_free offset=%x\n", offset); 76 + } 77 + 78 + static void pt_gpio_set_value(struct gpio_chip *gc, unsigned offset, int value) 79 + { 80 + struct pt_gpio_chip *pt_gpio = to_pt_gpio(gc); 81 + unsigned long flags; 82 + u32 data; 83 + 84 + dev_dbg(gc->dev, "pt_gpio_set_value offset=%x, value=%x\n", 85 + offset, value); 86 + 87 + spin_lock_irqsave(&pt_gpio->lock, flags); 88 + 89 + data = readl(pt_gpio->reg_base + PT_OUTPUTDATA_REG); 90 + data &= ~BIT(offset); 91 + if (value) 92 + data |= BIT(offset); 93 + writel(data, pt_gpio->reg_base + PT_OUTPUTDATA_REG); 94 + 95 + spin_unlock_irqrestore(&pt_gpio->lock, flags); 96 + } 97 + 98 + static int pt_gpio_get_value(struct gpio_chip *gc, unsigned offset) 99 + { 100 + struct pt_gpio_chip *pt_gpio = to_pt_gpio(gc); 101 + unsigned long flags; 102 + u32 data; 103 + 104 + spin_lock_irqsave(&pt_gpio->lock, flags); 105 + 106 + data = readl(pt_gpio->reg_base + PT_DIRECTION_REG); 107 + 108 + /* configure as output */ 109 + if (data & BIT(offset)) 110 + data = readl(pt_gpio->reg_base + PT_OUTPUTDATA_REG); 111 + else /* configure as input */ 112 + data = readl(pt_gpio->reg_base + PT_INPUTDATA_REG); 113 + 114 + spin_unlock_irqrestore(&pt_gpio->lock, flags); 115 + 116 + data >>= offset; 117 + data &= 1; 118 + 119 + dev_dbg(gc->dev, "pt_gpio_get_value offset=%x, value=%x\n", 120 + offset, data); 121 + 122 + return data; 123 + } 124 + 125 + static int pt_gpio_direction_input(struct gpio_chip *gc, unsigned offset) 126 + { 127 + struct pt_gpio_chip *pt_gpio = to_pt_gpio(gc); 128 + unsigned long flags; 129 + u32 data; 130 + 131 + dev_dbg(gc->dev, "pt_gpio_dirction_input offset=%x\n", offset); 132 + 133 + spin_lock_irqsave(&pt_gpio->lock, flags); 134 + 135 + data = readl(pt_gpio->reg_base + PT_DIRECTION_REG); 136 + data &= ~BIT(offset); 137 + writel(data, pt_gpio->reg_base + PT_DIRECTION_REG); 138 + 139 + spin_unlock_irqrestore(&pt_gpio->lock, flags); 140 + 141 + return 0; 142 + } 143 + 144 + static int pt_gpio_direction_output(struct gpio_chip *gc, 145 + unsigned offset, int value) 146 + { 147 + struct pt_gpio_chip *pt_gpio = to_pt_gpio(gc); 148 + unsigned long flags; 149 + u32 data; 150 + 151 + dev_dbg(gc->dev, "pt_gpio_direction_output offset=%x, value=%x\n", 152 + offset, value); 153 + 154 + spin_lock_irqsave(&pt_gpio->lock, flags); 155 + 156 + data = readl(pt_gpio->reg_base + PT_OUTPUTDATA_REG); 157 + if (value) 158 + data |= BIT(offset); 159 + else 160 + data &= ~BIT(offset); 161 + writel(data, pt_gpio->reg_base + PT_OUTPUTDATA_REG); 162 + 163 + data = readl(pt_gpio->reg_base + PT_DIRECTION_REG); 164 + data |= BIT(offset); 165 + writel(data, pt_gpio->reg_base + PT_DIRECTION_REG); 166 + 167 + spin_unlock_irqrestore(&pt_gpio->lock, flags); 168 + 169 + return 0; 170 + } 171 + 172 + static int pt_gpio_probe(struct platform_device *pdev) 173 + { 174 + struct device *dev = &pdev->dev; 175 + struct acpi_device *acpi_dev; 176 + acpi_handle handle = ACPI_HANDLE(dev); 177 + struct pt_gpio_chip *pt_gpio; 178 + struct resource *res_mem; 179 + int ret = 0; 180 + 181 + if (acpi_bus_get_device(handle, &acpi_dev)) { 182 + dev_err(dev, "PT GPIO device node not found\n"); 183 + return -ENODEV; 184 + } 185 + 186 + pt_gpio = devm_kzalloc(dev, sizeof(struct pt_gpio_chip), GFP_KERNEL); 187 + if (!pt_gpio) 188 + return -ENOMEM; 189 + 190 + res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 191 + if (!res_mem) { 192 + dev_err(&pdev->dev, "Failed to get MMIO resource for PT GPIO.\n"); 193 + return -EINVAL; 194 + } 195 + pt_gpio->reg_base = devm_ioremap_resource(dev, res_mem); 196 + if (IS_ERR(pt_gpio->reg_base)) { 197 + dev_err(&pdev->dev, "Failed to map MMIO resource for PT GPIO.\n"); 198 + return PTR_ERR(pt_gpio->reg_base); 199 + } 200 + 201 + spin_lock_init(&pt_gpio->lock); 202 + 203 + pt_gpio->gc.label = pdev->name; 204 + pt_gpio->gc.owner = THIS_MODULE; 205 + pt_gpio->gc.dev = dev; 206 + pt_gpio->gc.request = pt_gpio_request; 207 + pt_gpio->gc.free = pt_gpio_free; 208 + pt_gpio->gc.direction_input = pt_gpio_direction_input; 209 + pt_gpio->gc.direction_output = pt_gpio_direction_output; 210 + pt_gpio->gc.get = pt_gpio_get_value; 211 + pt_gpio->gc.set = pt_gpio_set_value; 212 + pt_gpio->gc.base = -1; 213 + pt_gpio->gc.ngpio = PT_TOTAL_GPIO; 214 + #if defined(CONFIG_OF_GPIO) 215 + pt_gpio->gc.of_node = pdev->dev.of_node; 216 + #endif 217 + ret = gpiochip_add(&pt_gpio->gc); 218 + if (ret) { 219 + dev_err(&pdev->dev, "Failed to register GPIO lib\n"); 220 + return ret; 221 + } 222 + 223 + platform_set_drvdata(pdev, pt_gpio); 224 + 225 + /* initialize register setting */ 226 + writel(0, pt_gpio->reg_base + PT_SYNC_REG); 227 + writel(0, pt_gpio->reg_base + PT_CLOCKRATE_REG); 228 + 229 + dev_dbg(&pdev->dev, "PT GPIO driver loaded\n"); 230 + return ret; 231 + } 232 + 233 + static int pt_gpio_remove(struct platform_device *pdev) 234 + { 235 + struct pt_gpio_chip *pt_gpio = platform_get_drvdata(pdev); 236 + 237 + gpiochip_remove(&pt_gpio->gc); 238 + 239 + return 0; 240 + } 241 + 242 + static const struct acpi_device_id pt_gpio_acpi_match[] = { 243 + { "AMDF030", 0 }, 244 + { }, 245 + }; 246 + MODULE_DEVICE_TABLE(acpi, pt_gpio_acpi_match); 247 + 248 + static struct platform_driver pt_gpio_driver = { 249 + .driver = { 250 + .name = "pt-gpio", 251 + .acpi_match_table = ACPI_PTR(pt_gpio_acpi_match), 252 + }, 253 + .probe = pt_gpio_probe, 254 + .remove = pt_gpio_remove, 255 + }; 256 + 257 + module_platform_driver(pt_gpio_driver); 258 + 259 + MODULE_LICENSE("GPL"); 260 + MODULE_AUTHOR("YD Tseng <yd_tseng@asmedia.com.tw>"); 261 + MODULE_DESCRIPTION("AMD Promontory GPIO Driver");
+2
drivers/gpio/gpio-arizona.c
··· 118 118 case WM5110: 119 119 case WM8280: 120 120 case WM8997: 121 + case WM8998: 122 + case WM1814: 121 123 arizona_gpio->gpio_chip.ngpio = 5; 122 124 break; 123 125 default:
+65 -64
drivers/gpio/gpio-ath79.c
··· 12 12 * by the Free Software Foundation. 13 13 */ 14 14 15 - #include <linux/kernel.h> 16 - #include <linux/init.h> 17 - #include <linux/module.h> 18 - #include <linux/types.h> 19 - #include <linux/spinlock.h> 20 - #include <linux/io.h> 21 - #include <linux/ioport.h> 22 - #include <linux/gpio.h> 15 + #include <linux/gpio/driver.h> 23 16 #include <linux/platform_data/gpio-ath79.h> 24 17 #include <linux/of_device.h> 25 18 26 19 #include <asm/mach-ath79/ar71xx_regs.h> 27 20 28 - static void __iomem *ath79_gpio_base; 29 - static u32 ath79_gpio_count; 30 - static DEFINE_SPINLOCK(ath79_gpio_lock); 21 + struct ath79_gpio_ctrl { 22 + struct gpio_chip chip; 23 + void __iomem *base; 24 + spinlock_t lock; 25 + }; 31 26 32 - static void __ath79_gpio_set_value(unsigned gpio, int value) 33 - { 34 - void __iomem *base = ath79_gpio_base; 35 - 36 - if (value) 37 - __raw_writel(1 << gpio, base + AR71XX_GPIO_REG_SET); 38 - else 39 - __raw_writel(1 << gpio, base + AR71XX_GPIO_REG_CLEAR); 40 - } 41 - 42 - static int __ath79_gpio_get_value(unsigned gpio) 43 - { 44 - return (__raw_readl(ath79_gpio_base + AR71XX_GPIO_REG_IN) >> gpio) & 1; 45 - } 46 - 47 - static int ath79_gpio_get_value(struct gpio_chip *chip, unsigned offset) 48 - { 49 - return __ath79_gpio_get_value(offset); 50 - } 27 + #define to_ath79_gpio_ctrl(c) container_of(c, struct ath79_gpio_ctrl, chip) 51 28 52 29 static void ath79_gpio_set_value(struct gpio_chip *chip, 53 - unsigned offset, int value) 30 + unsigned gpio, int value) 54 31 { 55 - __ath79_gpio_set_value(offset, value); 32 + struct ath79_gpio_ctrl *ctrl = to_ath79_gpio_ctrl(chip); 33 + 34 + if (value) 35 + __raw_writel(BIT(gpio), ctrl->base + AR71XX_GPIO_REG_SET); 36 + else 37 + __raw_writel(BIT(gpio), ctrl->base + AR71XX_GPIO_REG_CLEAR); 38 + } 39 + 40 + static int ath79_gpio_get_value(struct gpio_chip *chip, unsigned gpio) 41 + { 42 + struct ath79_gpio_ctrl *ctrl = to_ath79_gpio_ctrl(chip); 43 + 44 + return (__raw_readl(ctrl->base + AR71XX_GPIO_REG_IN) >> gpio) & 1; 56 45 } 57 46 58 47 static int ath79_gpio_direction_input(struct gpio_chip *chip, 59 48 unsigned offset) 60 49 { 61 - void __iomem *base = ath79_gpio_base; 50 + struct ath79_gpio_ctrl *ctrl = to_ath79_gpio_ctrl(chip); 62 51 unsigned long flags; 63 52 64 - spin_lock_irqsave(&ath79_gpio_lock, flags); 53 + spin_lock_irqsave(&ctrl->lock, flags); 65 54 66 - __raw_writel(__raw_readl(base + AR71XX_GPIO_REG_OE) & ~(1 << offset), 67 - base + AR71XX_GPIO_REG_OE); 55 + __raw_writel( 56 + __raw_readl(ctrl->base + AR71XX_GPIO_REG_OE) & ~BIT(offset), 57 + ctrl->base + AR71XX_GPIO_REG_OE); 68 58 69 - spin_unlock_irqrestore(&ath79_gpio_lock, flags); 59 + spin_unlock_irqrestore(&ctrl->lock, flags); 70 60 71 61 return 0; 72 62 } ··· 64 74 static int ath79_gpio_direction_output(struct gpio_chip *chip, 65 75 unsigned offset, int value) 66 76 { 67 - void __iomem *base = ath79_gpio_base; 77 + struct ath79_gpio_ctrl *ctrl = to_ath79_gpio_ctrl(chip); 68 78 unsigned long flags; 69 79 70 - spin_lock_irqsave(&ath79_gpio_lock, flags); 80 + spin_lock_irqsave(&ctrl->lock, flags); 71 81 72 82 if (value) 73 - __raw_writel(1 << offset, base + AR71XX_GPIO_REG_SET); 83 + __raw_writel(BIT(offset), ctrl->base + AR71XX_GPIO_REG_SET); 74 84 else 75 - __raw_writel(1 << offset, base + AR71XX_GPIO_REG_CLEAR); 85 + __raw_writel(BIT(offset), ctrl->base + AR71XX_GPIO_REG_CLEAR); 76 86 77 - __raw_writel(__raw_readl(base + AR71XX_GPIO_REG_OE) | (1 << offset), 78 - base + AR71XX_GPIO_REG_OE); 87 + __raw_writel( 88 + __raw_readl(ctrl->base + AR71XX_GPIO_REG_OE) | BIT(offset), 89 + ctrl->base + AR71XX_GPIO_REG_OE); 79 90 80 - spin_unlock_irqrestore(&ath79_gpio_lock, flags); 91 + spin_unlock_irqrestore(&ctrl->lock, flags); 81 92 82 93 return 0; 83 94 } 84 95 85 96 static int ar934x_gpio_direction_input(struct gpio_chip *chip, unsigned offset) 86 97 { 87 - void __iomem *base = ath79_gpio_base; 98 + struct ath79_gpio_ctrl *ctrl = to_ath79_gpio_ctrl(chip); 88 99 unsigned long flags; 89 100 90 - spin_lock_irqsave(&ath79_gpio_lock, flags); 101 + spin_lock_irqsave(&ctrl->lock, flags); 91 102 92 - __raw_writel(__raw_readl(base + AR71XX_GPIO_REG_OE) | (1 << offset), 93 - base + AR71XX_GPIO_REG_OE); 103 + __raw_writel( 104 + __raw_readl(ctrl->base + AR71XX_GPIO_REG_OE) | BIT(offset), 105 + ctrl->base + AR71XX_GPIO_REG_OE); 94 106 95 - spin_unlock_irqrestore(&ath79_gpio_lock, flags); 107 + spin_unlock_irqrestore(&ctrl->lock, flags); 96 108 97 109 return 0; 98 110 } ··· 102 110 static int ar934x_gpio_direction_output(struct gpio_chip *chip, unsigned offset, 103 111 int value) 104 112 { 105 - void __iomem *base = ath79_gpio_base; 113 + struct ath79_gpio_ctrl *ctrl = to_ath79_gpio_ctrl(chip); 106 114 unsigned long flags; 107 115 108 - spin_lock_irqsave(&ath79_gpio_lock, flags); 116 + spin_lock_irqsave(&ctrl->lock, flags); 109 117 110 118 if (value) 111 - __raw_writel(1 << offset, base + AR71XX_GPIO_REG_SET); 119 + __raw_writel(BIT(offset), ctrl->base + AR71XX_GPIO_REG_SET); 112 120 else 113 - __raw_writel(1 << offset, base + AR71XX_GPIO_REG_CLEAR); 121 + __raw_writel(BIT(offset), ctrl->base + AR71XX_GPIO_REG_CLEAR); 114 122 115 - __raw_writel(__raw_readl(base + AR71XX_GPIO_REG_OE) & ~(1 << offset), 116 - base + AR71XX_GPIO_REG_OE); 123 + __raw_writel( 124 + __raw_readl(ctrl->base + AR71XX_GPIO_REG_OE) & BIT(offset), 125 + ctrl->base + AR71XX_GPIO_REG_OE); 117 126 118 - spin_unlock_irqrestore(&ath79_gpio_lock, flags); 127 + spin_unlock_irqrestore(&ctrl->lock, flags); 119 128 120 129 return 0; 121 130 } 122 131 123 - static struct gpio_chip ath79_gpio_chip = { 132 + static const struct gpio_chip ath79_gpio_chip = { 124 133 .label = "ath79", 125 134 .get = ath79_gpio_get_value, 126 135 .set = ath79_gpio_set_value, ··· 140 147 { 141 148 struct ath79_gpio_platform_data *pdata = pdev->dev.platform_data; 142 149 struct device_node *np = pdev->dev.of_node; 150 + struct ath79_gpio_ctrl *ctrl; 143 151 struct resource *res; 152 + u32 ath79_gpio_count; 144 153 bool oe_inverted; 145 154 int err; 155 + 156 + ctrl = devm_kzalloc(&pdev->dev, sizeof(*ctrl), GFP_KERNEL); 157 + if (!ctrl) 158 + return -ENOMEM; 146 159 147 160 if (np) { 148 161 err = of_property_read_u32(np, "ngpios", &ath79_gpio_count); ··· 170 171 } 171 172 172 173 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 173 - ath79_gpio_base = devm_ioremap_nocache( 174 + ctrl->base = devm_ioremap_nocache( 174 175 &pdev->dev, res->start, resource_size(res)); 175 - if (!ath79_gpio_base) 176 + if (!ctrl->base) 176 177 return -ENOMEM; 177 178 178 - ath79_gpio_chip.dev = &pdev->dev; 179 - ath79_gpio_chip.ngpio = ath79_gpio_count; 179 + spin_lock_init(&ctrl->lock); 180 + memcpy(&ctrl->chip, &ath79_gpio_chip, sizeof(ctrl->chip)); 181 + ctrl->chip.dev = &pdev->dev; 182 + ctrl->chip.ngpio = ath79_gpio_count; 180 183 if (oe_inverted) { 181 - ath79_gpio_chip.direction_input = ar934x_gpio_direction_input; 182 - ath79_gpio_chip.direction_output = ar934x_gpio_direction_output; 184 + ctrl->chip.direction_input = ar934x_gpio_direction_input; 185 + ctrl->chip.direction_output = ar934x_gpio_direction_output; 183 186 } 184 187 185 - err = gpiochip_add(&ath79_gpio_chip); 188 + err = gpiochip_add(&ctrl->chip); 186 189 if (err) { 187 190 dev_err(&pdev->dev, 188 191 "cannot add AR71xx GPIO chip, error=%d", err);
+17 -6
drivers/gpio/gpio-etraxfs.c
··· 176 176 .rw_intr_pins = ARTPEC3_rw_intr_pins, 177 177 }; 178 178 179 + static struct etraxfs_gpio_chip *to_etraxfs(struct gpio_chip *gc) 180 + { 181 + return container_of(gc, struct etraxfs_gpio_chip, bgc.gc); 182 + } 183 + 179 184 static unsigned int etraxfs_gpio_chip_to_port(struct gpio_chip *gc) 180 185 { 181 186 return gc->label[0] - 'A'; ··· 225 220 226 221 static void etraxfs_gpio_irq_ack(struct irq_data *d) 227 222 { 228 - struct etraxfs_gpio_chip *chip = irq_data_get_irq_chip_data(d); 223 + struct etraxfs_gpio_chip *chip = 224 + to_etraxfs(irq_data_get_irq_chip_data(d)); 229 225 struct etraxfs_gpio_block *block = chip->block; 230 226 unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq); 231 227 ··· 235 229 236 230 static void etraxfs_gpio_irq_mask(struct irq_data *d) 237 231 { 238 - struct etraxfs_gpio_chip *chip = irq_data_get_irq_chip_data(d); 232 + struct etraxfs_gpio_chip *chip = 233 + to_etraxfs(irq_data_get_irq_chip_data(d)); 239 234 struct etraxfs_gpio_block *block = chip->block; 240 235 unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq); 241 236 ··· 248 241 249 242 static void etraxfs_gpio_irq_unmask(struct irq_data *d) 250 243 { 251 - struct etraxfs_gpio_chip *chip = irq_data_get_irq_chip_data(d); 244 + struct etraxfs_gpio_chip *chip = 245 + to_etraxfs(irq_data_get_irq_chip_data(d)); 252 246 struct etraxfs_gpio_block *block = chip->block; 253 247 unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq); 254 248 ··· 261 253 262 254 static int etraxfs_gpio_irq_set_type(struct irq_data *d, u32 type) 263 255 { 264 - struct etraxfs_gpio_chip *chip = irq_data_get_irq_chip_data(d); 256 + struct etraxfs_gpio_chip *chip = 257 + to_etraxfs(irq_data_get_irq_chip_data(d)); 265 258 struct etraxfs_gpio_block *block = chip->block; 266 259 unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq); 267 260 u32 cfg; ··· 298 289 299 290 static int etraxfs_gpio_irq_request_resources(struct irq_data *d) 300 291 { 301 - struct etraxfs_gpio_chip *chip = irq_data_get_irq_chip_data(d); 292 + struct etraxfs_gpio_chip *chip = 293 + to_etraxfs(irq_data_get_irq_chip_data(d)); 302 294 struct etraxfs_gpio_block *block = chip->block; 303 295 unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq); 304 296 int ret = -EBUSY; ··· 329 319 330 320 static void etraxfs_gpio_irq_release_resources(struct irq_data *d) 331 321 { 332 - struct etraxfs_gpio_chip *chip = irq_data_get_irq_chip_data(d); 322 + struct etraxfs_gpio_chip *chip = 323 + to_etraxfs(irq_data_get_irq_chip_data(d)); 333 324 struct etraxfs_gpio_block *block = chip->block; 334 325 unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq); 335 326
+19 -39
drivers/gpio/gpio-generic.c
··· 579 579 580 580 static void __iomem *bgpio_map(struct platform_device *pdev, 581 581 const char *name, 582 - resource_size_t sane_sz, 583 - int *err) 582 + resource_size_t sane_sz) 584 583 { 585 - struct device *dev = &pdev->dev; 586 584 struct resource *r; 587 - resource_size_t start; 588 585 resource_size_t sz; 589 - void __iomem *ret; 590 - 591 - *err = 0; 592 586 593 587 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, name); 594 588 if (!r) 595 589 return NULL; 596 590 597 591 sz = resource_size(r); 598 - if (sz != sane_sz) { 599 - *err = -EINVAL; 600 - return NULL; 601 - } 592 + if (sz != sane_sz) 593 + return IOMEM_ERR_PTR(-EINVAL); 602 594 603 - start = r->start; 604 - if (!devm_request_mem_region(dev, start, sz, r->name)) { 605 - *err = -EBUSY; 606 - return NULL; 607 - } 608 - 609 - ret = devm_ioremap(dev, start, sz); 610 - if (!ret) { 611 - *err = -ENOMEM; 612 - return NULL; 613 - } 614 - 615 - return ret; 595 + return devm_ioremap_resource(&pdev->dev, r); 616 596 } 617 597 618 598 static int bgpio_pdev_probe(struct platform_device *pdev) ··· 616 636 617 637 sz = resource_size(r); 618 638 619 - dat = bgpio_map(pdev, "dat", sz, &err); 620 - if (!dat) 621 - return err ? err : -EINVAL; 639 + dat = bgpio_map(pdev, "dat", sz); 640 + if (IS_ERR(dat)) 641 + return PTR_ERR(dat); 622 642 623 - set = bgpio_map(pdev, "set", sz, &err); 624 - if (err) 625 - return err; 643 + set = bgpio_map(pdev, "set", sz); 644 + if (IS_ERR(set)) 645 + return PTR_ERR(set); 626 646 627 - clr = bgpio_map(pdev, "clr", sz, &err); 628 - if (err) 629 - return err; 647 + clr = bgpio_map(pdev, "clr", sz); 648 + if (IS_ERR(clr)) 649 + return PTR_ERR(clr); 630 650 631 - dirout = bgpio_map(pdev, "dirout", sz, &err); 632 - if (err) 633 - return err; 651 + dirout = bgpio_map(pdev, "dirout", sz); 652 + if (IS_ERR(dirout)) 653 + return PTR_ERR(dirout); 634 654 635 - dirin = bgpio_map(pdev, "dirin", sz, &err); 636 - if (err) 637 - return err; 655 + dirin = bgpio_map(pdev, "dirin", sz); 656 + if (IS_ERR(dirin)) 657 + return PTR_ERR(dirin); 638 658 639 659 bgc = devm_kzalloc(&pdev->dev, sizeof(*bgc), GFP_KERNEL); 640 660 if (!bgc)
+411
drivers/gpio/gpio-it87.c
··· 1 + /* 2 + * GPIO interface for IT87xx Super I/O chips 3 + * 4 + * Author: Diego Elio Pettenò <flameeyes@flameeyes.eu> 5 + * 6 + * Based on it87_wdt.c by Oliver Schuster 7 + * gpio-it8761e.c by Denis Turischev 8 + * gpio-stmpe.c by Rabin Vincent 9 + * 10 + * This program is free software; you can redistribute it and/or modify 11 + * it under the terms of the GNU General Public License 2 as published 12 + * by the Free Software Foundation. 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; see the file COPYING. If not, write to 21 + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 22 + */ 23 + 24 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 25 + 26 + #include <linux/init.h> 27 + #include <linux/kernel.h> 28 + #include <linux/module.h> 29 + #include <linux/io.h> 30 + #include <linux/errno.h> 31 + #include <linux/ioport.h> 32 + #include <linux/slab.h> 33 + #include <linux/gpio.h> 34 + 35 + /* Chip Id numbers */ 36 + #define NO_DEV_ID 0xffff 37 + #define IT8728_ID 0x8728 38 + #define IT8732_ID 0x8732 39 + #define IT8761_ID 0x8761 40 + 41 + /* IO Ports */ 42 + #define REG 0x2e 43 + #define VAL 0x2f 44 + 45 + /* Logical device Numbers LDN */ 46 + #define GPIO 0x07 47 + 48 + /* Configuration Registers and Functions */ 49 + #define LDNREG 0x07 50 + #define CHIPID 0x20 51 + #define CHIPREV 0x22 52 + 53 + /** 54 + * struct it87_gpio - it87-specific GPIO chip 55 + * @chip the underlying gpio_chip structure 56 + * @lock a lock to avoid races between operations 57 + * @io_base base address for gpio ports 58 + * @io_size size of the port rage starting from io_base. 59 + * @output_base Super I/O register address for Output Enable register 60 + * @simple_base Super I/O 'Simple I/O' Enable register 61 + * @simple_size Super IO 'Simple I/O' Enable register size; this is 62 + * required because IT87xx chips might only provide Simple I/O 63 + * switches on a subset of lines, whereas the others keep the 64 + * same status all time. 65 + */ 66 + struct it87_gpio { 67 + struct gpio_chip chip; 68 + spinlock_t lock; 69 + u16 io_base; 70 + u16 io_size; 71 + u8 output_base; 72 + u8 simple_base; 73 + u8 simple_size; 74 + }; 75 + 76 + static struct it87_gpio it87_gpio_chip = { 77 + .lock = __SPIN_LOCK_UNLOCKED(it87_gpio_chip.lock), 78 + }; 79 + 80 + static inline struct it87_gpio *to_it87_gpio(struct gpio_chip *chip) 81 + { 82 + return container_of(chip, struct it87_gpio, chip); 83 + } 84 + 85 + /* Superio chip access functions; copied from wdt_it87 */ 86 + 87 + static inline int superio_enter(void) 88 + { 89 + /* 90 + * Try to reserve REG and REG + 1 for exclusive access. 91 + */ 92 + if (!request_muxed_region(REG, 2, KBUILD_MODNAME)) 93 + return -EBUSY; 94 + 95 + outb(0x87, REG); 96 + outb(0x01, REG); 97 + outb(0x55, REG); 98 + outb(0x55, REG); 99 + return 0; 100 + } 101 + 102 + static inline void superio_exit(void) 103 + { 104 + outb(0x02, REG); 105 + outb(0x02, VAL); 106 + release_region(REG, 2); 107 + } 108 + 109 + static inline void superio_select(int ldn) 110 + { 111 + outb(LDNREG, REG); 112 + outb(ldn, VAL); 113 + } 114 + 115 + static inline int superio_inb(int reg) 116 + { 117 + outb(reg, REG); 118 + return inb(VAL); 119 + } 120 + 121 + static inline void superio_outb(int val, int reg) 122 + { 123 + outb(reg, REG); 124 + outb(val, VAL); 125 + } 126 + 127 + static inline int superio_inw(int reg) 128 + { 129 + int val; 130 + 131 + outb(reg++, REG); 132 + val = inb(VAL) << 8; 133 + outb(reg, REG); 134 + val |= inb(VAL); 135 + return val; 136 + } 137 + 138 + static inline void superio_outw(int val, int reg) 139 + { 140 + outb(reg++, REG); 141 + outb(val >> 8, VAL); 142 + outb(reg, REG); 143 + outb(val, VAL); 144 + } 145 + 146 + static inline void superio_set_mask(int mask, int reg) 147 + { 148 + u8 curr_val = superio_inb(reg); 149 + u8 new_val = curr_val | mask; 150 + 151 + if (curr_val != new_val) 152 + superio_outb(new_val, reg); 153 + } 154 + 155 + static inline void superio_clear_mask(int mask, int reg) 156 + { 157 + u8 curr_val = superio_inb(reg); 158 + u8 new_val = curr_val & ~mask; 159 + 160 + if (curr_val != new_val) 161 + superio_outb(new_val, reg); 162 + } 163 + 164 + static int it87_gpio_request(struct gpio_chip *chip, unsigned gpio_num) 165 + { 166 + u8 mask, group; 167 + int rc = 0; 168 + struct it87_gpio *it87_gpio = to_it87_gpio(chip); 169 + 170 + mask = 1 << (gpio_num % 8); 171 + group = (gpio_num / 8); 172 + 173 + spin_lock(&it87_gpio->lock); 174 + 175 + rc = superio_enter(); 176 + if (rc) 177 + goto exit; 178 + 179 + /* not all the IT87xx chips support Simple I/O and not all of 180 + * them allow all the lines to be set/unset to Simple I/O. 181 + */ 182 + if (group < it87_gpio->simple_size) 183 + superio_set_mask(mask, group + it87_gpio->simple_base); 184 + 185 + /* clear output enable, setting the pin to input, as all the 186 + * newly-exported GPIO interfaces are set to input. 187 + */ 188 + superio_clear_mask(mask, group + it87_gpio->output_base); 189 + 190 + superio_exit(); 191 + 192 + exit: 193 + spin_unlock(&it87_gpio->lock); 194 + return rc; 195 + } 196 + 197 + static int it87_gpio_get(struct gpio_chip *chip, unsigned gpio_num) 198 + { 199 + u16 reg; 200 + u8 mask; 201 + struct it87_gpio *it87_gpio = to_it87_gpio(chip); 202 + 203 + mask = 1 << (gpio_num % 8); 204 + reg = (gpio_num / 8) + it87_gpio->io_base; 205 + 206 + return !!(inb(reg) & mask); 207 + } 208 + 209 + static int it87_gpio_direction_in(struct gpio_chip *chip, unsigned gpio_num) 210 + { 211 + u8 mask, group; 212 + int rc = 0; 213 + struct it87_gpio *it87_gpio = to_it87_gpio(chip); 214 + 215 + mask = 1 << (gpio_num % 8); 216 + group = (gpio_num / 8); 217 + 218 + spin_lock(&it87_gpio->lock); 219 + 220 + rc = superio_enter(); 221 + if (rc) 222 + goto exit; 223 + 224 + /* clear the output enable bit */ 225 + superio_clear_mask(mask, group + it87_gpio->output_base); 226 + 227 + superio_exit(); 228 + 229 + exit: 230 + spin_unlock(&it87_gpio->lock); 231 + return rc; 232 + } 233 + 234 + static void it87_gpio_set(struct gpio_chip *chip, 235 + unsigned gpio_num, int val) 236 + { 237 + u8 mask, curr_vals; 238 + u16 reg; 239 + struct it87_gpio *it87_gpio = to_it87_gpio(chip); 240 + 241 + mask = 1 << (gpio_num % 8); 242 + reg = (gpio_num / 8) + it87_gpio->io_base; 243 + 244 + curr_vals = inb(reg); 245 + if (val) 246 + outb(curr_vals | mask, reg); 247 + else 248 + outb(curr_vals & ~mask, reg); 249 + } 250 + 251 + static int it87_gpio_direction_out(struct gpio_chip *chip, 252 + unsigned gpio_num, int val) 253 + { 254 + u8 mask, group; 255 + int rc = 0; 256 + struct it87_gpio *it87_gpio = to_it87_gpio(chip); 257 + 258 + mask = 1 << (gpio_num % 8); 259 + group = (gpio_num / 8); 260 + 261 + spin_lock(&it87_gpio->lock); 262 + 263 + rc = superio_enter(); 264 + if (rc) 265 + goto exit; 266 + 267 + /* set the output enable bit */ 268 + superio_set_mask(mask, group + it87_gpio->output_base); 269 + 270 + it87_gpio_set(chip, gpio_num, val); 271 + 272 + superio_exit(); 273 + 274 + exit: 275 + spin_unlock(&it87_gpio->lock); 276 + return rc; 277 + } 278 + 279 + static struct gpio_chip it87_template_chip = { 280 + .label = KBUILD_MODNAME, 281 + .owner = THIS_MODULE, 282 + .request = it87_gpio_request, 283 + .get = it87_gpio_get, 284 + .direction_input = it87_gpio_direction_in, 285 + .set = it87_gpio_set, 286 + .direction_output = it87_gpio_direction_out, 287 + .base = -1 288 + }; 289 + 290 + static int __init it87_gpio_init(void) 291 + { 292 + int rc = 0, i; 293 + u16 chip_type; 294 + u8 chip_rev, gpio_ba_reg; 295 + char *labels, **labels_table; 296 + 297 + struct it87_gpio *it87_gpio = &it87_gpio_chip; 298 + 299 + rc = superio_enter(); 300 + if (rc) 301 + return rc; 302 + 303 + chip_type = superio_inw(CHIPID); 304 + chip_rev = superio_inb(CHIPREV) & 0x0f; 305 + superio_exit(); 306 + 307 + it87_gpio->chip = it87_template_chip; 308 + 309 + switch (chip_type) { 310 + case IT8728_ID: 311 + case IT8732_ID: 312 + gpio_ba_reg = 0x62; 313 + it87_gpio->io_size = 8; 314 + it87_gpio->output_base = 0xc8; 315 + it87_gpio->simple_base = 0xc0; 316 + it87_gpio->simple_size = 5; 317 + it87_gpio->chip.ngpio = 64; 318 + break; 319 + case IT8761_ID: 320 + gpio_ba_reg = 0x60; 321 + it87_gpio->io_size = 4; 322 + it87_gpio->output_base = 0xf0; 323 + it87_gpio->simple_size = 0; 324 + it87_gpio->chip.ngpio = 16; 325 + break; 326 + case NO_DEV_ID: 327 + pr_err("no device\n"); 328 + return -ENODEV; 329 + default: 330 + pr_err("Unknown Chip found, Chip %04x Revision %x\n", 331 + chip_type, chip_rev); 332 + return -ENODEV; 333 + } 334 + 335 + rc = superio_enter(); 336 + if (rc) 337 + return rc; 338 + 339 + superio_select(GPIO); 340 + 341 + /* fetch GPIO base address */ 342 + it87_gpio->io_base = superio_inw(gpio_ba_reg); 343 + 344 + superio_exit(); 345 + 346 + pr_info("Found Chip IT%04x rev %x. %u GPIO lines starting at %04xh\n", 347 + chip_type, chip_rev, it87_gpio->chip.ngpio, 348 + it87_gpio->io_base); 349 + 350 + if (!request_region(it87_gpio->io_base, it87_gpio->io_size, 351 + KBUILD_MODNAME)) 352 + return -EBUSY; 353 + 354 + /* Set up aliases for the GPIO connection. 355 + * 356 + * ITE documentation for recent chips such as the IT8728F 357 + * refers to the GPIO lines as GPxy, with a coordinates system 358 + * where x is the GPIO group (starting from 1) and y is the 359 + * bit within the group. 360 + * 361 + * By creating these aliases, we make it easier to understand 362 + * to which GPIO pin we're referring to. 363 + */ 364 + labels = kcalloc(it87_gpio->chip.ngpio, sizeof("it87_gpXY"), 365 + GFP_KERNEL); 366 + labels_table = kcalloc(it87_gpio->chip.ngpio, sizeof(const char *), 367 + GFP_KERNEL); 368 + 369 + if (!labels || !labels_table) { 370 + rc = -ENOMEM; 371 + goto labels_free; 372 + } 373 + 374 + for (i = 0; i < it87_gpio->chip.ngpio; i++) { 375 + char *label = &labels[i * sizeof("it87_gpXY")]; 376 + 377 + sprintf(label, "it87_gp%u%u", 1+(i/8), i%8); 378 + labels_table[i] = label; 379 + } 380 + 381 + it87_gpio->chip.names = (const char *const*)labels_table; 382 + 383 + rc = gpiochip_add(&it87_gpio->chip); 384 + if (rc) 385 + goto labels_free; 386 + 387 + return 0; 388 + 389 + labels_free: 390 + kfree(labels_table); 391 + kfree(labels); 392 + release_region(it87_gpio->io_base, it87_gpio->io_size); 393 + return rc; 394 + } 395 + 396 + static void __exit it87_gpio_exit(void) 397 + { 398 + struct it87_gpio *it87_gpio = &it87_gpio_chip; 399 + 400 + gpiochip_remove(&it87_gpio->chip); 401 + release_region(it87_gpio->io_base, it87_gpio->io_size); 402 + kfree(it87_gpio->chip.names[0]); 403 + kfree(it87_gpio->chip.names); 404 + } 405 + 406 + module_init(it87_gpio_init); 407 + module_exit(it87_gpio_exit); 408 + 409 + MODULE_AUTHOR("Diego Elio Pettenò <flameeyes@flameeyes.eu>"); 410 + MODULE_DESCRIPTION("GPIO interface for IT87xx Super I/O chips"); 411 + MODULE_LICENSE("GPL");
-230
drivers/gpio/gpio-it8761e.c
··· 1 - /* 2 - * GPIO interface for IT8761E Super I/O chip 3 - * 4 - * Author: Denis Turischev <denis@compulab.co.il> 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 2 as published 8 - * 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; see the file COPYING. If not, write to 17 - * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 18 - */ 19 - 20 - #include <linux/init.h> 21 - #include <linux/kernel.h> 22 - #include <linux/module.h> 23 - #include <linux/io.h> 24 - #include <linux/errno.h> 25 - #include <linux/ioport.h> 26 - 27 - #include <linux/gpio.h> 28 - 29 - #define SIO_CHIP_ID 0x8761 30 - #define CHIP_ID_HIGH_BYTE 0x20 31 - #define CHIP_ID_LOW_BYTE 0x21 32 - 33 - static u8 ports[2] = { 0x2e, 0x4e }; 34 - static u8 port; 35 - 36 - static DEFINE_SPINLOCK(sio_lock); 37 - 38 - #define GPIO_NAME "it8761-gpio" 39 - #define GPIO_BA_HIGH_BYTE 0x60 40 - #define GPIO_BA_LOW_BYTE 0x61 41 - #define GPIO_IOSIZE 4 42 - #define GPIO1X_IO 0xf0 43 - #define GPIO2X_IO 0xf1 44 - 45 - static u16 gpio_ba; 46 - 47 - static u8 read_reg(u8 addr, u8 port) 48 - { 49 - outb(addr, port); 50 - return inb(port + 1); 51 - } 52 - 53 - static void write_reg(u8 data, u8 addr, u8 port) 54 - { 55 - outb(addr, port); 56 - outb(data, port + 1); 57 - } 58 - 59 - static void enter_conf_mode(u8 port) 60 - { 61 - outb(0x87, port); 62 - outb(0x61, port); 63 - outb(0x55, port); 64 - outb((port == 0x2e) ? 0x55 : 0xaa, port); 65 - } 66 - 67 - static void exit_conf_mode(u8 port) 68 - { 69 - outb(0x2, port); 70 - outb(0x2, port + 1); 71 - } 72 - 73 - static void enter_gpio_mode(u8 port) 74 - { 75 - write_reg(0x2, 0x7, port); 76 - } 77 - 78 - static int it8761e_gpio_get(struct gpio_chip *gc, unsigned gpio_num) 79 - { 80 - u16 reg; 81 - u8 bit; 82 - 83 - bit = gpio_num % 8; 84 - reg = (gpio_num >= 8) ? gpio_ba + 1 : gpio_ba; 85 - 86 - return !!(inb(reg) & (1 << bit)); 87 - } 88 - 89 - static int it8761e_gpio_direction_in(struct gpio_chip *gc, unsigned gpio_num) 90 - { 91 - u8 curr_dirs; 92 - u8 io_reg, bit; 93 - 94 - bit = gpio_num % 8; 95 - io_reg = (gpio_num >= 8) ? GPIO2X_IO : GPIO1X_IO; 96 - 97 - spin_lock(&sio_lock); 98 - 99 - enter_conf_mode(port); 100 - enter_gpio_mode(port); 101 - 102 - curr_dirs = read_reg(io_reg, port); 103 - 104 - if (curr_dirs & (1 << bit)) 105 - write_reg(curr_dirs & ~(1 << bit), io_reg, port); 106 - 107 - exit_conf_mode(port); 108 - 109 - spin_unlock(&sio_lock); 110 - return 0; 111 - } 112 - 113 - static void it8761e_gpio_set(struct gpio_chip *gc, 114 - unsigned gpio_num, int val) 115 - { 116 - u8 curr_vals, bit; 117 - u16 reg; 118 - 119 - bit = gpio_num % 8; 120 - reg = (gpio_num >= 8) ? gpio_ba + 1 : gpio_ba; 121 - 122 - spin_lock(&sio_lock); 123 - 124 - curr_vals = inb(reg); 125 - if (val) 126 - outb(curr_vals | (1 << bit), reg); 127 - else 128 - outb(curr_vals & ~(1 << bit), reg); 129 - 130 - spin_unlock(&sio_lock); 131 - } 132 - 133 - static int it8761e_gpio_direction_out(struct gpio_chip *gc, 134 - unsigned gpio_num, int val) 135 - { 136 - u8 curr_dirs, io_reg, bit; 137 - 138 - bit = gpio_num % 8; 139 - io_reg = (gpio_num >= 8) ? GPIO2X_IO : GPIO1X_IO; 140 - 141 - it8761e_gpio_set(gc, gpio_num, val); 142 - 143 - spin_lock(&sio_lock); 144 - 145 - enter_conf_mode(port); 146 - enter_gpio_mode(port); 147 - 148 - curr_dirs = read_reg(io_reg, port); 149 - 150 - if (!(curr_dirs & (1 << bit))) 151 - write_reg(curr_dirs | (1 << bit), io_reg, port); 152 - 153 - exit_conf_mode(port); 154 - 155 - spin_unlock(&sio_lock); 156 - return 0; 157 - } 158 - 159 - static struct gpio_chip it8761e_gpio_chip = { 160 - .label = GPIO_NAME, 161 - .owner = THIS_MODULE, 162 - .get = it8761e_gpio_get, 163 - .direction_input = it8761e_gpio_direction_in, 164 - .set = it8761e_gpio_set, 165 - .direction_output = it8761e_gpio_direction_out, 166 - }; 167 - 168 - static int __init it8761e_gpio_init(void) 169 - { 170 - int i, id, err; 171 - 172 - /* chip and port detection */ 173 - for (i = 0; i < ARRAY_SIZE(ports); i++) { 174 - spin_lock(&sio_lock); 175 - enter_conf_mode(ports[i]); 176 - 177 - id = (read_reg(CHIP_ID_HIGH_BYTE, ports[i]) << 8) + 178 - read_reg(CHIP_ID_LOW_BYTE, ports[i]); 179 - 180 - exit_conf_mode(ports[i]); 181 - spin_unlock(&sio_lock); 182 - 183 - if (id == SIO_CHIP_ID) { 184 - port = ports[i]; 185 - break; 186 - } 187 - } 188 - 189 - if (!port) 190 - return -ENODEV; 191 - 192 - /* fetch GPIO base address */ 193 - enter_conf_mode(port); 194 - enter_gpio_mode(port); 195 - gpio_ba = (read_reg(GPIO_BA_HIGH_BYTE, port) << 8) + 196 - read_reg(GPIO_BA_LOW_BYTE, port); 197 - exit_conf_mode(port); 198 - 199 - if (!request_region(gpio_ba, GPIO_IOSIZE, GPIO_NAME)) 200 - return -EBUSY; 201 - 202 - it8761e_gpio_chip.base = -1; 203 - it8761e_gpio_chip.ngpio = 16; 204 - 205 - err = gpiochip_add(&it8761e_gpio_chip); 206 - if (err < 0) 207 - goto gpiochip_add_err; 208 - 209 - return 0; 210 - 211 - gpiochip_add_err: 212 - release_region(gpio_ba, GPIO_IOSIZE); 213 - gpio_ba = 0; 214 - return err; 215 - } 216 - 217 - static void __exit it8761e_gpio_exit(void) 218 - { 219 - if (gpio_ba) { 220 - gpiochip_remove(&it8761e_gpio_chip); 221 - release_region(gpio_ba, GPIO_IOSIZE); 222 - gpio_ba = 0; 223 - } 224 - } 225 - module_init(it8761e_gpio_init); 226 - module_exit(it8761e_gpio_exit); 227 - 228 - MODULE_AUTHOR("Denis Turischev <denis@compulab.co.il>"); 229 - MODULE_DESCRIPTION("GPIO interface for IT8761E Super I/O chip"); 230 - MODULE_LICENSE("GPL");
+2 -12
drivers/gpio/gpio-lpc18xx.c
··· 36 36 return container_of(chip, struct lpc18xx_gpio_chip, gpio); 37 37 } 38 38 39 - static int lpc18xx_gpio_request(struct gpio_chip *chip, unsigned offset) 40 - { 41 - return pinctrl_request_gpio(offset); 42 - } 43 - 44 - static void lpc18xx_gpio_free(struct gpio_chip *chip, unsigned offset) 45 - { 46 - pinctrl_free_gpio(offset); 47 - } 48 - 49 39 static void lpc18xx_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 50 40 { 51 41 struct lpc18xx_gpio_chip *gc = to_lpc18xx_gpio(chip); ··· 85 95 86 96 static struct gpio_chip lpc18xx_chip = { 87 97 .label = "lpc18xx/43xx-gpio", 88 - .request = lpc18xx_gpio_request, 89 - .free = lpc18xx_gpio_free, 98 + .request = gpiochip_generic_request, 99 + .free = gpiochip_generic_free, 90 100 .direction_input = lpc18xx_gpio_direction_input, 91 101 .direction_output = lpc18xx_gpio_direction_output, 92 102 .set = lpc18xx_gpio_set,
-1
drivers/gpio/gpio-max730x.c
··· 236 236 ts->write(dev, 0x04, 0x00); 237 237 gpiochip_remove(&ts->chip); 238 238 mutex_destroy(&ts->lock); 239 - kfree(ts); 240 239 return 0; 241 240 } 242 241 EXPORT_SYMBOL_GPL(__max730x_remove);
+2 -12
drivers/gpio/gpio-moxart.c
··· 29 29 #define GPIO_DATA_IN 0x04 30 30 #define GPIO_PIN_DIRECTION 0x08 31 31 32 - static int moxart_gpio_request(struct gpio_chip *chip, unsigned offset) 33 - { 34 - return pinctrl_request_gpio(offset); 35 - } 36 - 37 - static void moxart_gpio_free(struct gpio_chip *chip, unsigned offset) 38 - { 39 - pinctrl_free_gpio(offset); 40 - } 41 - 42 32 static int moxart_gpio_probe(struct platform_device *pdev) 43 33 { 44 34 struct device *dev = &pdev->dev; ··· 56 66 } 57 67 58 68 bgc->gc.label = "moxart-gpio"; 59 - bgc->gc.request = moxart_gpio_request; 60 - bgc->gc.free = moxart_gpio_free; 69 + bgc->gc.request = gpiochip_generic_request; 70 + bgc->gc.free = gpiochip_generic_free; 61 71 bgc->data = bgc->read_reg(bgc->reg_set); 62 72 bgc->gc.base = 0; 63 73 bgc->gc.ngpio = 32;
-453
drivers/gpio/gpio-msm-v2.c
··· 1 - /* Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved. 2 - * 3 - * This program is free software; you can redistribute it and/or modify 4 - * it under the terms of the GNU General Public License version 2 and 5 - * only version 2 as published by the Free Software Foundation. 6 - * 7 - * This program is distributed in the hope that it will be useful, 8 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 - * GNU General Public License for more details. 11 - * 12 - * You should have received a copy of the GNU General Public License 13 - * along with this program; if not, write to the Free Software 14 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 15 - * 02110-1301, USA. 16 - * 17 - */ 18 - #define pr_fmt(fmt) "%s: " fmt, __func__ 19 - 20 - #include <linux/bitmap.h> 21 - #include <linux/bitops.h> 22 - #include <linux/err.h> 23 - #include <linux/gpio.h> 24 - #include <linux/init.h> 25 - #include <linux/interrupt.h> 26 - #include <linux/io.h> 27 - #include <linux/irqchip/chained_irq.h> 28 - #include <linux/irq.h> 29 - #include <linux/irqdomain.h> 30 - #include <linux/module.h> 31 - #include <linux/of_address.h> 32 - #include <linux/platform_device.h> 33 - #include <linux/spinlock.h> 34 - #include <linux/slab.h> 35 - 36 - #define MAX_NR_GPIO 300 37 - 38 - /* Bits of interest in the GPIO_IN_OUT register. 39 - */ 40 - enum { 41 - GPIO_IN = 0, 42 - GPIO_OUT = 1 43 - }; 44 - 45 - /* Bits of interest in the GPIO_INTR_STATUS register. 46 - */ 47 - enum { 48 - INTR_STATUS = 0, 49 - }; 50 - 51 - /* Bits of interest in the GPIO_CFG register. 52 - */ 53 - enum { 54 - GPIO_OE = 9, 55 - }; 56 - 57 - /* Bits of interest in the GPIO_INTR_CFG register. 58 - * When a GPIO triggers, two separate decisions are made, controlled 59 - * by two separate flags. 60 - * 61 - * - First, INTR_RAW_STATUS_EN controls whether or not the GPIO_INTR_STATUS 62 - * register for that GPIO will be updated to reflect the triggering of that 63 - * gpio. If this bit is 0, this register will not be updated. 64 - * - Second, INTR_ENABLE controls whether an interrupt is triggered. 65 - * 66 - * If INTR_ENABLE is set and INTR_RAW_STATUS_EN is NOT set, an interrupt 67 - * can be triggered but the status register will not reflect it. 68 - */ 69 - enum { 70 - INTR_ENABLE = 0, 71 - INTR_POL_CTL = 1, 72 - INTR_DECT_CTL = 2, 73 - INTR_RAW_STATUS_EN = 3, 74 - }; 75 - 76 - /* Codes of interest in GPIO_INTR_CFG_SU. 77 - */ 78 - enum { 79 - TARGET_PROC_SCORPION = 4, 80 - TARGET_PROC_NONE = 7, 81 - }; 82 - 83 - /** 84 - * struct msm_gpio_dev: the MSM8660 SoC GPIO device structure 85 - * 86 - * @enabled_irqs: a bitmap used to optimize the summary-irq handler. By 87 - * keeping track of which gpios are unmasked as irq sources, we avoid 88 - * having to do readl calls on hundreds of iomapped registers each time 89 - * the summary interrupt fires in order to locate the active interrupts. 90 - * 91 - * @wake_irqs: a bitmap for tracking which interrupt lines are enabled 92 - * as wakeup sources. When the device is suspended, interrupts which are 93 - * not wakeup sources are disabled. 94 - * 95 - * @dual_edge_irqs: a bitmap used to track which irqs are configured 96 - * as dual-edge, as this is not supported by the hardware and requires 97 - * some special handling in the driver. 98 - */ 99 - struct msm_gpio_dev { 100 - struct gpio_chip gpio_chip; 101 - DECLARE_BITMAP(enabled_irqs, MAX_NR_GPIO); 102 - DECLARE_BITMAP(wake_irqs, MAX_NR_GPIO); 103 - DECLARE_BITMAP(dual_edge_irqs, MAX_NR_GPIO); 104 - struct irq_domain *domain; 105 - int summary_irq; 106 - void __iomem *msm_tlmm_base; 107 - }; 108 - 109 - static struct msm_gpio_dev msm_gpio; 110 - 111 - #define GPIO_INTR_CFG_SU(gpio) (msm_gpio.msm_tlmm_base + 0x0400 + \ 112 - (0x04 * (gpio))) 113 - #define GPIO_CONFIG(gpio) (msm_gpio.msm_tlmm_base + 0x1000 + \ 114 - (0x10 * (gpio))) 115 - #define GPIO_IN_OUT(gpio) (msm_gpio.msm_tlmm_base + 0x1004 + \ 116 - (0x10 * (gpio))) 117 - #define GPIO_INTR_CFG(gpio) (msm_gpio.msm_tlmm_base + 0x1008 + \ 118 - (0x10 * (gpio))) 119 - #define GPIO_INTR_STATUS(gpio) (msm_gpio.msm_tlmm_base + 0x100c + \ 120 - (0x10 * (gpio))) 121 - 122 - static DEFINE_SPINLOCK(tlmm_lock); 123 - 124 - static inline struct msm_gpio_dev *to_msm_gpio_dev(struct gpio_chip *chip) 125 - { 126 - return container_of(chip, struct msm_gpio_dev, gpio_chip); 127 - } 128 - 129 - static inline void set_gpio_bits(unsigned n, void __iomem *reg) 130 - { 131 - writel(readl(reg) | n, reg); 132 - } 133 - 134 - static inline void clear_gpio_bits(unsigned n, void __iomem *reg) 135 - { 136 - writel(readl(reg) & ~n, reg); 137 - } 138 - 139 - static int msm_gpio_get(struct gpio_chip *chip, unsigned offset) 140 - { 141 - return readl(GPIO_IN_OUT(offset)) & BIT(GPIO_IN); 142 - } 143 - 144 - static void msm_gpio_set(struct gpio_chip *chip, unsigned offset, int val) 145 - { 146 - writel(val ? BIT(GPIO_OUT) : 0, GPIO_IN_OUT(offset)); 147 - } 148 - 149 - static int msm_gpio_direction_input(struct gpio_chip *chip, unsigned offset) 150 - { 151 - unsigned long irq_flags; 152 - 153 - spin_lock_irqsave(&tlmm_lock, irq_flags); 154 - clear_gpio_bits(BIT(GPIO_OE), GPIO_CONFIG(offset)); 155 - spin_unlock_irqrestore(&tlmm_lock, irq_flags); 156 - return 0; 157 - } 158 - 159 - static int msm_gpio_direction_output(struct gpio_chip *chip, 160 - unsigned offset, 161 - int val) 162 - { 163 - unsigned long irq_flags; 164 - 165 - spin_lock_irqsave(&tlmm_lock, irq_flags); 166 - msm_gpio_set(chip, offset, val); 167 - set_gpio_bits(BIT(GPIO_OE), GPIO_CONFIG(offset)); 168 - spin_unlock_irqrestore(&tlmm_lock, irq_flags); 169 - return 0; 170 - } 171 - 172 - static int msm_gpio_request(struct gpio_chip *chip, unsigned offset) 173 - { 174 - return 0; 175 - } 176 - 177 - static void msm_gpio_free(struct gpio_chip *chip, unsigned offset) 178 - { 179 - return; 180 - } 181 - 182 - static int msm_gpio_to_irq(struct gpio_chip *chip, unsigned offset) 183 - { 184 - struct msm_gpio_dev *g_dev = to_msm_gpio_dev(chip); 185 - struct irq_domain *domain = g_dev->domain; 186 - 187 - return irq_create_mapping(domain, offset); 188 - } 189 - 190 - /* For dual-edge interrupts in software, since the hardware has no 191 - * such support: 192 - * 193 - * At appropriate moments, this function may be called to flip the polarity 194 - * settings of both-edge irq lines to try and catch the next edge. 195 - * 196 - * The attempt is considered successful if: 197 - * - the status bit goes high, indicating that an edge was caught, or 198 - * - the input value of the gpio doesn't change during the attempt. 199 - * If the value changes twice during the process, that would cause the first 200 - * test to fail but would force the second, as two opposite 201 - * transitions would cause a detection no matter the polarity setting. 202 - * 203 - * The do-loop tries to sledge-hammer closed the timing hole between 204 - * the initial value-read and the polarity-write - if the line value changes 205 - * during that window, an interrupt is lost, the new polarity setting is 206 - * incorrect, and the first success test will fail, causing a retry. 207 - * 208 - * Algorithm comes from Google's msmgpio driver, see mach-msm/gpio.c. 209 - */ 210 - static void msm_gpio_update_dual_edge_pos(unsigned gpio) 211 - { 212 - int loop_limit = 100; 213 - unsigned val, val2, intstat; 214 - 215 - do { 216 - val = readl(GPIO_IN_OUT(gpio)) & BIT(GPIO_IN); 217 - if (val) 218 - clear_gpio_bits(BIT(INTR_POL_CTL), GPIO_INTR_CFG(gpio)); 219 - else 220 - set_gpio_bits(BIT(INTR_POL_CTL), GPIO_INTR_CFG(gpio)); 221 - val2 = readl(GPIO_IN_OUT(gpio)) & BIT(GPIO_IN); 222 - intstat = readl(GPIO_INTR_STATUS(gpio)) & BIT(INTR_STATUS); 223 - if (intstat || val == val2) 224 - return; 225 - } while (loop_limit-- > 0); 226 - pr_err("%s: dual-edge irq failed to stabilize, " 227 - "interrupts dropped. %#08x != %#08x\n", 228 - __func__, val, val2); 229 - } 230 - 231 - static void msm_gpio_irq_ack(struct irq_data *d) 232 - { 233 - int gpio = d->hwirq; 234 - 235 - writel(BIT(INTR_STATUS), GPIO_INTR_STATUS(gpio)); 236 - if (test_bit(gpio, msm_gpio.dual_edge_irqs)) 237 - msm_gpio_update_dual_edge_pos(gpio); 238 - } 239 - 240 - static void msm_gpio_irq_mask(struct irq_data *d) 241 - { 242 - unsigned long irq_flags; 243 - int gpio = d->hwirq; 244 - 245 - spin_lock_irqsave(&tlmm_lock, irq_flags); 246 - writel(TARGET_PROC_NONE, GPIO_INTR_CFG_SU(gpio)); 247 - clear_gpio_bits(BIT(INTR_RAW_STATUS_EN) | BIT(INTR_ENABLE), GPIO_INTR_CFG(gpio)); 248 - __clear_bit(gpio, msm_gpio.enabled_irqs); 249 - spin_unlock_irqrestore(&tlmm_lock, irq_flags); 250 - } 251 - 252 - static void msm_gpio_irq_unmask(struct irq_data *d) 253 - { 254 - unsigned long irq_flags; 255 - int gpio = d->hwirq; 256 - 257 - spin_lock_irqsave(&tlmm_lock, irq_flags); 258 - __set_bit(gpio, msm_gpio.enabled_irqs); 259 - set_gpio_bits(BIT(INTR_RAW_STATUS_EN) | BIT(INTR_ENABLE), GPIO_INTR_CFG(gpio)); 260 - writel(TARGET_PROC_SCORPION, GPIO_INTR_CFG_SU(gpio)); 261 - spin_unlock_irqrestore(&tlmm_lock, irq_flags); 262 - } 263 - 264 - static int msm_gpio_irq_set_type(struct irq_data *d, unsigned int flow_type) 265 - { 266 - unsigned long irq_flags; 267 - int gpio = d->hwirq; 268 - uint32_t bits; 269 - 270 - spin_lock_irqsave(&tlmm_lock, irq_flags); 271 - 272 - bits = readl(GPIO_INTR_CFG(gpio)); 273 - 274 - if (flow_type & IRQ_TYPE_EDGE_BOTH) { 275 - bits |= BIT(INTR_DECT_CTL); 276 - irq_set_handler_locked(d, handle_edge_irq); 277 - if ((flow_type & IRQ_TYPE_EDGE_BOTH) == IRQ_TYPE_EDGE_BOTH) 278 - __set_bit(gpio, msm_gpio.dual_edge_irqs); 279 - else 280 - __clear_bit(gpio, msm_gpio.dual_edge_irqs); 281 - } else { 282 - bits &= ~BIT(INTR_DECT_CTL); 283 - irq_set_handler_locked(d, handle_level_irq); 284 - __clear_bit(gpio, msm_gpio.dual_edge_irqs); 285 - } 286 - 287 - if (flow_type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_LEVEL_HIGH)) 288 - bits |= BIT(INTR_POL_CTL); 289 - else 290 - bits &= ~BIT(INTR_POL_CTL); 291 - 292 - writel(bits, GPIO_INTR_CFG(gpio)); 293 - 294 - if ((flow_type & IRQ_TYPE_EDGE_BOTH) == IRQ_TYPE_EDGE_BOTH) 295 - msm_gpio_update_dual_edge_pos(gpio); 296 - 297 - spin_unlock_irqrestore(&tlmm_lock, irq_flags); 298 - 299 - return 0; 300 - } 301 - 302 - /* 303 - * When the summary IRQ is raised, any number of GPIO lines may be high. 304 - * It is the job of the summary handler to find all those GPIO lines 305 - * which have been set as summary IRQ lines and which are triggered, 306 - * and to call their interrupt handlers. 307 - */ 308 - static void msm_summary_irq_handler(struct irq_desc *desc) 309 - { 310 - unsigned long i; 311 - struct irq_chip *chip = irq_desc_get_chip(desc); 312 - 313 - chained_irq_enter(chip, desc); 314 - 315 - for_each_set_bit(i, msm_gpio.enabled_irqs, MAX_NR_GPIO) { 316 - if (readl(GPIO_INTR_STATUS(i)) & BIT(INTR_STATUS)) 317 - generic_handle_irq(irq_find_mapping(msm_gpio.domain, 318 - i)); 319 - } 320 - 321 - chained_irq_exit(chip, desc); 322 - } 323 - 324 - static int msm_gpio_irq_set_wake(struct irq_data *d, unsigned int on) 325 - { 326 - int gpio = d->hwirq; 327 - 328 - if (on) { 329 - if (bitmap_empty(msm_gpio.wake_irqs, MAX_NR_GPIO)) 330 - irq_set_irq_wake(msm_gpio.summary_irq, 1); 331 - set_bit(gpio, msm_gpio.wake_irqs); 332 - } else { 333 - clear_bit(gpio, msm_gpio.wake_irqs); 334 - if (bitmap_empty(msm_gpio.wake_irqs, MAX_NR_GPIO)) 335 - irq_set_irq_wake(msm_gpio.summary_irq, 0); 336 - } 337 - 338 - return 0; 339 - } 340 - 341 - static struct irq_chip msm_gpio_irq_chip = { 342 - .name = "msmgpio", 343 - .irq_mask = msm_gpio_irq_mask, 344 - .irq_unmask = msm_gpio_irq_unmask, 345 - .irq_ack = msm_gpio_irq_ack, 346 - .irq_set_type = msm_gpio_irq_set_type, 347 - .irq_set_wake = msm_gpio_irq_set_wake, 348 - }; 349 - 350 - static struct lock_class_key msm_gpio_lock_class; 351 - 352 - static int msm_gpio_irq_domain_map(struct irq_domain *d, unsigned int irq, 353 - irq_hw_number_t hwirq) 354 - { 355 - irq_set_lockdep_class(irq, &msm_gpio_lock_class); 356 - irq_set_chip_and_handler(irq, &msm_gpio_irq_chip, 357 - handle_level_irq); 358 - 359 - return 0; 360 - } 361 - 362 - static const struct irq_domain_ops msm_gpio_irq_domain_ops = { 363 - .xlate = irq_domain_xlate_twocell, 364 - .map = msm_gpio_irq_domain_map, 365 - }; 366 - 367 - static int msm_gpio_probe(struct platform_device *pdev) 368 - { 369 - int ret, ngpio; 370 - struct resource *res; 371 - 372 - if (of_property_read_u32(pdev->dev.of_node, "ngpio", &ngpio)) { 373 - dev_err(&pdev->dev, "%s: ngpio property missing\n", __func__); 374 - return -EINVAL; 375 - } 376 - 377 - if (ngpio > MAX_NR_GPIO) 378 - WARN(1, "ngpio exceeds the MAX_NR_GPIO. Increase MAX_NR_GPIO\n"); 379 - 380 - bitmap_zero(msm_gpio.enabled_irqs, MAX_NR_GPIO); 381 - bitmap_zero(msm_gpio.wake_irqs, MAX_NR_GPIO); 382 - bitmap_zero(msm_gpio.dual_edge_irqs, MAX_NR_GPIO); 383 - 384 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 385 - msm_gpio.msm_tlmm_base = devm_ioremap_resource(&pdev->dev, res); 386 - if (IS_ERR(msm_gpio.msm_tlmm_base)) 387 - return PTR_ERR(msm_gpio.msm_tlmm_base); 388 - 389 - msm_gpio.gpio_chip.ngpio = ngpio; 390 - msm_gpio.gpio_chip.label = pdev->name; 391 - msm_gpio.gpio_chip.dev = &pdev->dev; 392 - msm_gpio.gpio_chip.base = 0; 393 - msm_gpio.gpio_chip.direction_input = msm_gpio_direction_input; 394 - msm_gpio.gpio_chip.direction_output = msm_gpio_direction_output; 395 - msm_gpio.gpio_chip.get = msm_gpio_get; 396 - msm_gpio.gpio_chip.set = msm_gpio_set; 397 - msm_gpio.gpio_chip.to_irq = msm_gpio_to_irq; 398 - msm_gpio.gpio_chip.request = msm_gpio_request; 399 - msm_gpio.gpio_chip.free = msm_gpio_free; 400 - 401 - ret = gpiochip_add(&msm_gpio.gpio_chip); 402 - if (ret < 0) { 403 - dev_err(&pdev->dev, "gpiochip_add failed with error %d\n", ret); 404 - return ret; 405 - } 406 - 407 - msm_gpio.summary_irq = platform_get_irq(pdev, 0); 408 - if (msm_gpio.summary_irq < 0) { 409 - dev_err(&pdev->dev, "No Summary irq defined for msmgpio\n"); 410 - return msm_gpio.summary_irq; 411 - } 412 - 413 - msm_gpio.domain = irq_domain_add_linear(pdev->dev.of_node, ngpio, 414 - &msm_gpio_irq_domain_ops, 415 - &msm_gpio); 416 - if (!msm_gpio.domain) 417 - return -ENODEV; 418 - 419 - irq_set_chained_handler(msm_gpio.summary_irq, msm_summary_irq_handler); 420 - 421 - return 0; 422 - } 423 - 424 - static const struct of_device_id msm_gpio_of_match[] = { 425 - { .compatible = "qcom,msm-gpio", }, 426 - { }, 427 - }; 428 - MODULE_DEVICE_TABLE(of, msm_gpio_of_match); 429 - 430 - static int msm_gpio_remove(struct platform_device *dev) 431 - { 432 - gpiochip_remove(&msm_gpio.gpio_chip); 433 - 434 - irq_set_handler(msm_gpio.summary_irq, NULL); 435 - 436 - return 0; 437 - } 438 - 439 - static struct platform_driver msm_gpio_driver = { 440 - .probe = msm_gpio_probe, 441 - .remove = msm_gpio_remove, 442 - .driver = { 443 - .name = "msmgpio", 444 - .of_match_table = msm_gpio_of_match, 445 - }, 446 - }; 447 - 448 - module_platform_driver(msm_gpio_driver) 449 - 450 - MODULE_AUTHOR("Gregory Bean <gbean@codeaurora.org>"); 451 - MODULE_DESCRIPTION("Driver for Qualcomm MSM TLMMv2 SoC GPIOs"); 452 - MODULE_LICENSE("GPL v2"); 453 - MODULE_ALIAS("platform:msmgpio");
+2 -12
drivers/gpio/gpio-mvebu.c
··· 185 185 * Functions implementing the gpio_chip methods 186 186 */ 187 187 188 - static int mvebu_gpio_request(struct gpio_chip *chip, unsigned pin) 189 - { 190 - return pinctrl_request_gpio(chip->base + pin); 191 - } 192 - 193 - static void mvebu_gpio_free(struct gpio_chip *chip, unsigned pin) 194 - { 195 - pinctrl_free_gpio(chip->base + pin); 196 - } 197 - 198 188 static void mvebu_gpio_set(struct gpio_chip *chip, unsigned pin, int value) 199 189 { 200 190 struct mvebu_gpio_chip *mvchip = ··· 699 709 mvchip->soc_variant = soc_variant; 700 710 mvchip->chip.label = dev_name(&pdev->dev); 701 711 mvchip->chip.dev = &pdev->dev; 702 - mvchip->chip.request = mvebu_gpio_request; 703 - mvchip->chip.free = mvebu_gpio_free; 712 + mvchip->chip.request = gpiochip_generic_request; 713 + mvchip->chip.free = gpiochip_generic_free; 704 714 mvchip->chip.direction_input = mvebu_gpio_direction_input; 705 715 mvchip->chip.get = mvebu_gpio_get; 706 716 mvchip->chip.direction_output = mvebu_gpio_direction_output;
+43 -39
drivers/gpio/gpio-omap.c
··· 51 51 struct gpio_bank { 52 52 struct list_head node; 53 53 void __iomem *base; 54 - u16 irq; 54 + int irq; 55 55 u32 non_wakeup_gpios; 56 56 u32 enabled_non_wakeup_gpios; 57 57 struct gpio_regs context; ··· 59 59 u32 level_mask; 60 60 u32 toggle_mask; 61 61 raw_spinlock_t lock; 62 + raw_spinlock_t wa_lock; 62 63 struct gpio_chip chip; 63 64 struct clk *dbck; 64 65 u32 mod_usage; ··· 497 496 (type & (IRQ_TYPE_LEVEL_LOW|IRQ_TYPE_LEVEL_HIGH))) 498 497 return -EINVAL; 499 498 500 - if (!BANK_USED(bank)) 501 - pm_runtime_get_sync(bank->dev); 502 - 503 499 raw_spin_lock_irqsave(&bank->lock, flags); 504 500 retval = omap_set_gpio_triggering(bank, offset, type); 505 501 if (retval) { ··· 519 521 return 0; 520 522 521 523 error: 522 - if (!BANK_USED(bank)) 523 - pm_runtime_put(bank->dev); 524 524 return retval; 525 525 } 526 526 ··· 650 654 { 651 655 struct gpio_bank *bank = omap_irq_data_get_bank(d); 652 656 unsigned offset = d->hwirq; 657 + int ret; 653 658 654 - return omap_set_gpio_wakeup(bank, offset, enable); 659 + ret = omap_set_gpio_wakeup(bank, offset, enable); 660 + if (!ret) 661 + ret = irq_set_irq_wake(bank->irq, enable); 662 + 663 + return ret; 655 664 } 656 665 657 666 static int omap_gpio_request(struct gpio_chip *chip, unsigned offset) ··· 710 709 * line's interrupt handler has been run, we may miss some nested 711 710 * interrupts. 712 711 */ 713 - static void omap_gpio_irq_handler(struct irq_desc *desc) 712 + static irqreturn_t omap_gpio_irq_handler(int irq, void *gpiobank) 714 713 { 715 714 void __iomem *isr_reg = NULL; 716 715 u32 isr; 717 716 unsigned int bit; 718 - struct gpio_bank *bank; 719 - int unmasked = 0; 720 - struct irq_chip *irqchip = irq_desc_get_chip(desc); 721 - struct gpio_chip *chip = irq_desc_get_handler_data(desc); 717 + struct gpio_bank *bank = gpiobank; 718 + unsigned long wa_lock_flags; 722 719 unsigned long lock_flags; 723 720 724 - chained_irq_enter(irqchip, desc); 725 - 726 - bank = container_of(chip, struct gpio_bank, chip); 727 721 isr_reg = bank->base + bank->regs->irqstatus; 728 - pm_runtime_get_sync(bank->dev); 729 - 730 722 if (WARN_ON(!isr_reg)) 731 723 goto exit; 724 + 725 + pm_runtime_get_sync(bank->dev); 732 726 733 727 while (1) { 734 728 u32 isr_saved, level_mask = 0; ··· 746 750 747 751 raw_spin_unlock_irqrestore(&bank->lock, lock_flags); 748 752 749 - /* if there is only edge sensitive GPIO pin interrupts 750 - configured, we could unmask GPIO bank interrupt immediately */ 751 - if (!level_mask && !unmasked) { 752 - unmasked = 1; 753 - chained_irq_exit(irqchip, desc); 754 - } 755 - 756 753 if (!isr) 757 754 break; 758 755 ··· 766 777 767 778 raw_spin_unlock_irqrestore(&bank->lock, lock_flags); 768 779 780 + raw_spin_lock_irqsave(&bank->wa_lock, wa_lock_flags); 781 + 769 782 generic_handle_irq(irq_find_mapping(bank->chip.irqdomain, 770 783 bit)); 784 + 785 + raw_spin_unlock_irqrestore(&bank->wa_lock, 786 + wa_lock_flags); 771 787 } 772 788 } 773 - /* if bank has any level sensitive GPIO pin interrupt 774 - configured, we must unmask the bank interrupt only after 775 - handler(s) are executed in order to avoid spurious bank 776 - interrupt */ 777 789 exit: 778 - if (!unmasked) 779 - chained_irq_exit(irqchip, desc); 780 790 pm_runtime_put(bank->dev); 791 + return IRQ_HANDLED; 781 792 } 782 793 783 794 static unsigned int omap_gpio_irq_startup(struct irq_data *d) ··· 785 796 struct gpio_bank *bank = omap_irq_data_get_bank(d); 786 797 unsigned long flags; 787 798 unsigned offset = d->hwirq; 788 - 789 - if (!BANK_USED(bank)) 790 - pm_runtime_get_sync(bank->dev); 791 799 792 800 raw_spin_lock_irqsave(&bank->lock, flags); 793 801 ··· 801 815 return 0; 802 816 err: 803 817 raw_spin_unlock_irqrestore(&bank->lock, flags); 804 - if (!BANK_USED(bank)) 805 - pm_runtime_put(bank->dev); 806 818 return -EINVAL; 807 819 } 808 820 ··· 819 835 omap_clear_gpio_debounce(bank, offset); 820 836 omap_disable_gpio_module(bank, offset); 821 837 raw_spin_unlock_irqrestore(&bank->lock, flags); 838 + } 839 + 840 + static void omap_gpio_irq_bus_lock(struct irq_data *data) 841 + { 842 + struct gpio_bank *bank = omap_irq_data_get_bank(data); 843 + 844 + if (!BANK_USED(bank)) 845 + pm_runtime_get_sync(bank->dev); 846 + } 847 + 848 + static void gpio_irq_bus_sync_unlock(struct irq_data *data) 849 + { 850 + struct gpio_bank *bank = omap_irq_data_get_bank(data); 822 851 823 852 /* 824 853 * If this is the last IRQ to be freed in the bank, ··· 1129 1132 } 1130 1133 1131 1134 ret = gpiochip_irqchip_add(&bank->chip, irqc, 1132 - irq_base, omap_gpio_irq_handler, 1135 + irq_base, handle_bad_irq, 1133 1136 IRQ_TYPE_NONE); 1134 1137 1135 1138 if (ret) { ··· 1138 1141 return -ENODEV; 1139 1142 } 1140 1143 1141 - gpiochip_set_chained_irqchip(&bank->chip, irqc, 1142 - bank->irq, omap_gpio_irq_handler); 1144 + gpiochip_set_chained_irqchip(&bank->chip, irqc, bank->irq, NULL); 1143 1145 1144 - return 0; 1146 + ret = devm_request_irq(bank->dev, bank->irq, omap_gpio_irq_handler, 1147 + 0, dev_name(bank->dev), bank); 1148 + if (ret) 1149 + gpiochip_remove(&bank->chip); 1150 + 1151 + return ret; 1145 1152 } 1146 1153 1147 1154 static const struct of_device_id omap_gpio_match[]; ··· 1184 1183 irqc->irq_unmask = omap_gpio_unmask_irq, 1185 1184 irqc->irq_set_type = omap_gpio_irq_type, 1186 1185 irqc->irq_set_wake = omap_gpio_wake_enable, 1186 + irqc->irq_bus_lock = omap_gpio_irq_bus_lock, 1187 + irqc->irq_bus_sync_unlock = gpio_irq_bus_sync_unlock, 1187 1188 irqc->name = dev_name(&pdev->dev); 1188 1189 1189 1190 bank->irq = platform_get_irq(pdev, 0); ··· 1227 1224 bank->set_dataout = omap_set_gpio_dataout_mask; 1228 1225 1229 1226 raw_spin_lock_init(&bank->lock); 1227 + raw_spin_lock_init(&bank->wa_lock); 1230 1228 1231 1229 /* Static mapping, never released */ 1232 1230 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+36 -9
drivers/gpio/gpio-pca953x.c
··· 21 21 #ifdef CONFIG_OF_GPIO 22 22 #include <linux/of_platform.h> 23 23 #endif 24 + #include <linux/acpi.h> 24 25 25 26 #define PCA953X_INPUT 0 26 27 #define PCA953X_OUTPUT 1 ··· 43 42 #define PCA_INT 0x0100 44 43 #define PCA953X_TYPE 0x1000 45 44 #define PCA957X_TYPE 0x2000 45 + #define PCA_TYPE_MASK 0xF000 46 + 47 + #define PCA_CHIP_TYPE(x) ((x) & PCA_TYPE_MASK) 46 48 47 49 static const struct i2c_device_id pca953x_id[] = { 48 50 { "pca9505", 40 | PCA953X_TYPE | PCA_INT, }, ··· 71 67 { "tca6408", 8 | PCA953X_TYPE | PCA_INT, }, 72 68 { "tca6416", 16 | PCA953X_TYPE | PCA_INT, }, 73 69 { "tca6424", 24 | PCA953X_TYPE | PCA_INT, }, 70 + { "tca9539", 16 | PCA953X_TYPE | PCA_INT, }, 74 71 { "xra1202", 8 | PCA953X_TYPE }, 75 72 { } 76 73 }; 77 74 MODULE_DEVICE_TABLE(i2c, pca953x_id); 75 + 76 + static const struct acpi_device_id pca953x_acpi_ids[] = { 77 + { "INT3491", 16 | PCA953X_TYPE | PCA_INT, }, 78 + { } 79 + }; 80 + MODULE_DEVICE_TABLE(acpi, pca953x_acpi_ids); 78 81 79 82 #define MAX_BANK 5 80 83 #define BANK_SZ 8 ··· 106 95 struct gpio_chip gpio_chip; 107 96 const char *const *names; 108 97 int chip_type; 98 + unsigned long driver_data; 109 99 }; 110 100 111 101 static inline struct pca953x_chip *to_pca(struct gpio_chip *gc) ··· 529 517 } 530 518 531 519 static int pca953x_irq_setup(struct pca953x_chip *chip, 532 - const struct i2c_device_id *id, 533 520 int irq_base) 534 521 { 535 522 struct i2c_client *client = chip->client; 536 523 int ret, i, offset = 0; 537 524 538 525 if (client->irq && irq_base != -1 539 - && (id->driver_data & PCA_INT)) { 526 + && (chip->driver_data & PCA_INT)) { 540 527 541 528 switch (chip->chip_type) { 542 529 case PCA953X_TYPE: ··· 592 581 593 582 #else /* CONFIG_GPIO_PCA953X_IRQ */ 594 583 static int pca953x_irq_setup(struct pca953x_chip *chip, 595 - const struct i2c_device_id *id, 596 584 int irq_base) 597 585 { 598 586 struct i2c_client *client = chip->client; 599 587 600 - if (irq_base != -1 && (id->driver_data & PCA_INT)) 588 + if (irq_base != -1 && (chip->driver_data & PCA_INT)) 601 589 dev_warn(&client->dev, "interrupt support not compiled in\n"); 602 590 603 591 return 0; ··· 645 635 memset(val, 0xFF, NBANK(chip)); 646 636 else 647 637 memset(val, 0, NBANK(chip)); 648 - pca953x_write_regs(chip, PCA957X_INVRT, val); 638 + ret = pca953x_write_regs(chip, PCA957X_INVRT, val); 639 + if (ret) 640 + goto out; 649 641 650 642 /* To enable register 6, 7 to control pull up and pull down */ 651 643 memset(val, 0x02, NBANK(chip)); 652 - pca953x_write_regs(chip, PCA957X_BKEN, val); 644 + ret = pca953x_write_regs(chip, PCA957X_BKEN, val); 645 + if (ret) 646 + goto out; 653 647 654 648 return 0; 655 649 out: ··· 687 673 688 674 chip->client = client; 689 675 690 - chip->chip_type = id->driver_data & (PCA953X_TYPE | PCA957X_TYPE); 676 + if (id) { 677 + chip->driver_data = id->driver_data; 678 + } else { 679 + const struct acpi_device_id *id; 680 + 681 + id = acpi_match_device(pca953x_acpi_ids, &client->dev); 682 + if (!id) 683 + return -ENODEV; 684 + 685 + chip->driver_data = id->driver_data; 686 + } 687 + 688 + chip->chip_type = PCA_CHIP_TYPE(chip->driver_data); 691 689 692 690 mutex_init(&chip->i2c_lock); 693 691 694 692 /* initialize cached registers from their original values. 695 693 * we can't share this chip with another i2c master. 696 694 */ 697 - pca953x_setup_gpio(chip, id->driver_data & PCA_GPIO_MASK); 695 + pca953x_setup_gpio(chip, chip->driver_data & PCA_GPIO_MASK); 698 696 699 697 if (chip->chip_type == PCA953X_TYPE) 700 698 ret = device_pca953x_init(chip, invert); ··· 719 693 if (ret) 720 694 return ret; 721 695 722 - ret = pca953x_irq_setup(chip, id, irq_base); 696 + ret = pca953x_irq_setup(chip, irq_base); 723 697 if (ret) 724 698 return ret; 725 699 ··· 791 765 .driver = { 792 766 .name = "pca953x", 793 767 .of_match_table = pca953x_dt_ids, 768 + .acpi_match_table = ACPI_PTR(pca953x_acpi_ids), 794 769 }, 795 770 .probe = pca953x_probe, 796 771 .remove = pca953x_remove,
+74 -38
drivers/gpio/gpio-pl061.c
··· 52 52 53 53 void __iomem *base; 54 54 struct gpio_chip gc; 55 - bool uses_pinctrl; 56 55 57 56 #ifdef CONFIG_PM 58 57 struct pl061_context_save_regs csave_regs; 59 58 #endif 60 59 }; 61 - 62 - static int pl061_gpio_request(struct gpio_chip *gc, unsigned offset) 63 - { 64 - /* 65 - * Map back to global GPIO space and request muxing, the direction 66 - * parameter does not matter for this controller. 67 - */ 68 - struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc); 69 - int gpio = gc->base + offset; 70 - 71 - if (chip->uses_pinctrl) 72 - return pinctrl_request_gpio(gpio); 73 - return 0; 74 - } 75 - 76 - static void pl061_gpio_free(struct gpio_chip *gc, unsigned offset) 77 - { 78 - struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc); 79 - int gpio = gc->base + offset; 80 - 81 - if (chip->uses_pinctrl) 82 - pinctrl_free_gpio(gpio); 83 - } 84 60 85 61 static int pl061_direction_input(struct gpio_chip *gc, unsigned offset) 86 62 { ··· 128 152 if (offset < 0 || offset >= PL061_GPIO_NR) 129 153 return -EINVAL; 130 154 155 + if ((trigger & (IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) && 156 + (trigger & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))) 157 + { 158 + dev_err(gc->dev, 159 + "trying to configure line %d for both level and edge " 160 + "detection, choose one!\n", 161 + offset); 162 + return -EINVAL; 163 + } 164 + 165 + 131 166 spin_lock_irqsave(&chip->lock, flags); 132 167 133 168 gpioiev = readb(chip->base + GPIOIEV); ··· 146 159 gpioibe = readb(chip->base + GPIOIBE); 147 160 148 161 if (trigger & (IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) { 162 + bool polarity = trigger & IRQ_TYPE_LEVEL_HIGH; 163 + 164 + /* Disable edge detection */ 165 + gpioibe &= ~bit; 166 + /* Enable level detection */ 149 167 gpiois |= bit; 150 - if (trigger & IRQ_TYPE_LEVEL_HIGH) 168 + /* Select polarity */ 169 + if (polarity) 151 170 gpioiev |= bit; 152 171 else 153 172 gpioiev &= ~bit; 154 - } else 173 + irq_set_handler_locked(d, handle_level_irq); 174 + dev_dbg(gc->dev, "line %d: IRQ on %s level\n", 175 + offset, 176 + polarity ? "HIGH" : "LOW"); 177 + } else if ((trigger & IRQ_TYPE_EDGE_BOTH) == IRQ_TYPE_EDGE_BOTH) { 178 + /* Disable level detection */ 155 179 gpiois &= ~bit; 156 - 157 - if ((trigger & IRQ_TYPE_EDGE_BOTH) == IRQ_TYPE_EDGE_BOTH) 158 - /* Setting this makes GPIOEV be ignored */ 180 + /* Select both edges, setting this makes GPIOEV be ignored */ 159 181 gpioibe |= bit; 160 - else { 182 + irq_set_handler_locked(d, handle_edge_irq); 183 + dev_dbg(gc->dev, "line %d: IRQ on both edges\n", offset); 184 + } else if ((trigger & IRQ_TYPE_EDGE_RISING) || 185 + (trigger & IRQ_TYPE_EDGE_FALLING)) { 186 + bool rising = trigger & IRQ_TYPE_EDGE_RISING; 187 + 188 + /* Disable level detection */ 189 + gpiois &= ~bit; 190 + /* Clear detection on both edges */ 161 191 gpioibe &= ~bit; 162 - if (trigger & IRQ_TYPE_EDGE_RISING) 192 + /* Select edge */ 193 + if (rising) 163 194 gpioiev |= bit; 164 - else if (trigger & IRQ_TYPE_EDGE_FALLING) 195 + else 165 196 gpioiev &= ~bit; 197 + irq_set_handler_locked(d, handle_edge_irq); 198 + dev_dbg(gc->dev, "line %d: IRQ on %s edge\n", 199 + offset, 200 + rising ? "RISING" : "FALLING"); 201 + } else { 202 + /* No trigger: disable everything */ 203 + gpiois &= ~bit; 204 + gpioibe &= ~bit; 205 + gpioiev &= ~bit; 206 + irq_set_handler_locked(d, handle_bad_irq); 207 + dev_warn(gc->dev, "no trigger selected for line %d\n", 208 + offset); 166 209 } 167 210 168 211 writeb(gpiois, chip->base + GPIOIS); ··· 215 198 chained_irq_enter(irqchip, desc); 216 199 217 200 pending = readb(chip->base + GPIOMIS); 218 - writeb(pending, chip->base + GPIOIC); 219 201 if (pending) { 220 202 for_each_set_bit(offset, &pending, PL061_GPIO_NR) 221 203 generic_handle_irq(irq_find_mapping(gc->irqdomain, ··· 250 234 spin_unlock(&chip->lock); 251 235 } 252 236 237 + /** 238 + * pl061_irq_ack() - ACK an edge IRQ 239 + * @d: IRQ data for this IRQ 240 + * 241 + * This gets called from the edge IRQ handler to ACK the edge IRQ 242 + * in the GPIOIC (interrupt-clear) register. For level IRQs this is 243 + * not needed: these go away when the level signal goes away. 244 + */ 245 + static void pl061_irq_ack(struct irq_data *d) 246 + { 247 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 248 + struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc); 249 + u8 mask = BIT(irqd_to_hwirq(d) % PL061_GPIO_NR); 250 + 251 + spin_lock(&chip->lock); 252 + writeb(mask, chip->base + GPIOIC); 253 + spin_unlock(&chip->lock); 254 + } 255 + 253 256 static struct irq_chip pl061_irqchip = { 254 257 .name = "pl061", 258 + .irq_ack = pl061_irq_ack, 255 259 .irq_mask = pl061_irq_mask, 256 260 .irq_unmask = pl061_irq_unmask, 257 261 .irq_set_type = pl061_irq_type, ··· 305 269 return PTR_ERR(chip->base); 306 270 307 271 spin_lock_init(&chip->lock); 308 - if (of_property_read_bool(dev->of_node, "gpio-ranges")) 309 - chip->uses_pinctrl = true; 272 + if (of_property_read_bool(dev->of_node, "gpio-ranges")) { 273 + chip->gc.request = gpiochip_generic_request; 274 + chip->gc.free = gpiochip_generic_free; 275 + } 310 276 311 - chip->gc.request = pl061_gpio_request; 312 - chip->gc.free = pl061_gpio_free; 313 277 chip->gc.direction_input = pl061_direction_input; 314 278 chip->gc.direction_output = pl061_direction_output; 315 279 chip->gc.get = pl061_get_value; ··· 334 298 } 335 299 336 300 ret = gpiochip_irqchip_add(&chip->gc, &pl061_irqchip, 337 - irq_base, handle_simple_irq, 301 + irq_base, handle_bad_irq, 338 302 IRQ_TYPE_NONE); 339 303 if (ret) { 340 304 dev_info(&adev->dev, "could not add irqchip\n");
+14 -17
drivers/gpio/gpio-sx150x.c
··· 160 160 }; 161 161 MODULE_DEVICE_TABLE(of, sx150x_of_match); 162 162 163 + struct sx150x_chip *to_sx150x(struct gpio_chip *gc) 164 + { 165 + return container_of(gc, struct sx150x_chip, gpio_chip); 166 + } 167 + 163 168 static s32 sx150x_i2c_write(struct i2c_client *client, u8 reg, u8 val) 164 169 { 165 170 s32 err = i2c_smbus_write_byte_data(client, reg, val); ··· 301 296 302 297 static int sx150x_gpio_get(struct gpio_chip *gc, unsigned offset) 303 298 { 304 - struct sx150x_chip *chip; 299 + struct sx150x_chip *chip = to_sx150x(gc); 305 300 int status = -EINVAL; 306 - 307 - chip = container_of(gc, struct sx150x_chip, gpio_chip); 308 301 309 302 if (!offset_is_oscio(chip, offset)) { 310 303 mutex_lock(&chip->lock); ··· 315 312 316 313 static void sx150x_gpio_set(struct gpio_chip *gc, unsigned offset, int val) 317 314 { 318 - struct sx150x_chip *chip; 319 - 320 - chip = container_of(gc, struct sx150x_chip, gpio_chip); 315 + struct sx150x_chip *chip = to_sx150x(gc); 321 316 322 317 mutex_lock(&chip->lock); 323 318 if (offset_is_oscio(chip, offset)) ··· 327 326 328 327 static int sx150x_gpio_direction_input(struct gpio_chip *gc, unsigned offset) 329 328 { 330 - struct sx150x_chip *chip; 329 + struct sx150x_chip *chip = to_sx150x(gc); 331 330 int status = -EINVAL; 332 - 333 - chip = container_of(gc, struct sx150x_chip, gpio_chip); 334 331 335 332 if (!offset_is_oscio(chip, offset)) { 336 333 mutex_lock(&chip->lock); ··· 342 343 unsigned offset, 343 344 int val) 344 345 { 345 - struct sx150x_chip *chip; 346 + struct sx150x_chip *chip = to_sx150x(gc); 346 347 int status = 0; 347 - 348 - chip = container_of(gc, struct sx150x_chip, gpio_chip); 349 348 350 349 if (!offset_is_oscio(chip, offset)) { 351 350 mutex_lock(&chip->lock); ··· 355 358 356 359 static void sx150x_irq_mask(struct irq_data *d) 357 360 { 358 - struct sx150x_chip *chip = irq_data_get_irq_chip_data(d); 361 + struct sx150x_chip *chip = to_sx150x(irq_data_get_irq_chip_data(d)); 359 362 unsigned n = d->hwirq; 360 363 361 364 chip->irq_masked |= (1 << n); ··· 364 367 365 368 static void sx150x_irq_unmask(struct irq_data *d) 366 369 { 367 - struct sx150x_chip *chip = irq_data_get_irq_chip_data(d); 370 + struct sx150x_chip *chip = to_sx150x(irq_data_get_irq_chip_data(d)); 368 371 unsigned n = d->hwirq; 369 372 370 373 chip->irq_masked &= ~(1 << n); ··· 373 376 374 377 static int sx150x_irq_set_type(struct irq_data *d, unsigned int flow_type) 375 378 { 376 - struct sx150x_chip *chip = irq_data_get_irq_chip_data(d); 379 + struct sx150x_chip *chip = to_sx150x(irq_data_get_irq_chip_data(d)); 377 380 unsigned n, val = 0; 378 381 379 382 if (flow_type & (IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) ··· 428 431 429 432 static void sx150x_irq_bus_lock(struct irq_data *d) 430 433 { 431 - struct sx150x_chip *chip = irq_data_get_irq_chip_data(d); 434 + struct sx150x_chip *chip = to_sx150x(irq_data_get_irq_chip_data(d)); 432 435 433 436 mutex_lock(&chip->lock); 434 437 } 435 438 436 439 static void sx150x_irq_bus_sync_unlock(struct irq_data *d) 437 440 { 438 - struct sx150x_chip *chip = irq_data_get_irq_chip_data(d); 441 + struct sx150x_chip *chip = to_sx150x(irq_data_get_irq_chip_data(d)); 439 442 unsigned n; 440 443 441 444 if (chip->irq_update == NO_UPDATE_PENDING)
+2 -12
drivers/gpio/gpio-tb10x.c
··· 138 138 return 0; 139 139 } 140 140 141 - static int tb10x_gpio_request(struct gpio_chip *chip, unsigned offset) 142 - { 143 - return pinctrl_request_gpio(chip->base + offset); 144 - } 145 - 146 - static void tb10x_gpio_free(struct gpio_chip *chip, unsigned offset) 147 - { 148 - pinctrl_free_gpio(chip->base + offset); 149 - } 150 - 151 141 static int tb10x_gpio_to_irq(struct gpio_chip *chip, unsigned offset) 152 142 { 153 143 struct tb10x_gpio *tb10x_gpio = to_tb10x_gpio(chip); ··· 203 213 tb10x_gpio->gc.get = tb10x_gpio_get; 204 214 tb10x_gpio->gc.direction_output = tb10x_gpio_direction_out; 205 215 tb10x_gpio->gc.set = tb10x_gpio_set; 206 - tb10x_gpio->gc.request = tb10x_gpio_request; 207 - tb10x_gpio->gc.free = tb10x_gpio_free; 216 + tb10x_gpio->gc.request = gpiochip_generic_request; 217 + tb10x_gpio->gc.free = gpiochip_generic_free; 208 218 tb10x_gpio->gc.base = -1; 209 219 tb10x_gpio->gc.ngpio = ngpio; 210 220 tb10x_gpio->gc.can_sleep = false;
+2 -12
drivers/gpio/gpio-tz1090-pdc.c
··· 137 137 __global_unlock2(lstat); 138 138 } 139 139 140 - static int tz1090_pdc_gpio_request(struct gpio_chip *chip, unsigned int offset) 141 - { 142 - return pinctrl_request_gpio(chip->base + offset); 143 - } 144 - 145 - static void tz1090_pdc_gpio_free(struct gpio_chip *chip, unsigned int offset) 146 - { 147 - pinctrl_free_gpio(chip->base + offset); 148 - } 149 - 150 140 static int tz1090_pdc_gpio_to_irq(struct gpio_chip *chip, unsigned int offset) 151 141 { 152 142 struct tz1090_pdc_gpio *priv = to_pdc(chip); ··· 193 203 priv->chip.direction_output = tz1090_pdc_gpio_direction_output; 194 204 priv->chip.get = tz1090_pdc_gpio_get; 195 205 priv->chip.set = tz1090_pdc_gpio_set; 196 - priv->chip.free = tz1090_pdc_gpio_free; 197 - priv->chip.request = tz1090_pdc_gpio_request; 206 + priv->chip.free = gpiochip_generic_free; 207 + priv->chip.request = gpiochip_generic_request; 198 208 priv->chip.to_irq = tz1090_pdc_gpio_to_irq; 199 209 priv->chip.of_node = np; 200 210
+21 -22
drivers/gpio/gpio-vf610.c
··· 62 62 63 63 static struct irq_chip vf610_gpio_irq_chip; 64 64 65 + static struct vf610_gpio_port *to_vf610_gp(struct gpio_chip *gc) 66 + { 67 + return container_of(gc, struct vf610_gpio_port, gc); 68 + } 69 + 65 70 static const struct of_device_id vf610_gpio_dt_ids[] = { 66 71 { .compatible = "fsl,vf610-gpio" }, 67 72 { /* sentinel */ } ··· 82 77 return readl_relaxed(reg); 83 78 } 84 79 85 - static int vf610_gpio_request(struct gpio_chip *chip, unsigned offset) 86 - { 87 - return pinctrl_request_gpio(chip->base + offset); 88 - } 89 - 90 - static void vf610_gpio_free(struct gpio_chip *chip, unsigned offset) 91 - { 92 - pinctrl_free_gpio(chip->base + offset); 93 - } 94 - 95 80 static int vf610_gpio_get(struct gpio_chip *gc, unsigned int gpio) 96 81 { 97 - struct vf610_gpio_port *port = 98 - container_of(gc, struct vf610_gpio_port, gc); 82 + struct vf610_gpio_port *port = to_vf610_gp(gc); 99 83 100 84 return !!(vf610_gpio_readl(port->gpio_base + GPIO_PDIR) & BIT(gpio)); 101 85 } 102 86 103 87 static void vf610_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val) 104 88 { 105 - struct vf610_gpio_port *port = 106 - container_of(gc, struct vf610_gpio_port, gc); 89 + struct vf610_gpio_port *port = to_vf610_gp(gc); 107 90 unsigned long mask = BIT(gpio); 108 91 109 92 if (val) ··· 115 122 116 123 static void vf610_gpio_irq_handler(struct irq_desc *desc) 117 124 { 118 - struct vf610_gpio_port *port = irq_desc_get_handler_data(desc); 125 + struct vf610_gpio_port *port = 126 + to_vf610_gp(irq_desc_get_handler_data(desc)); 119 127 struct irq_chip *chip = irq_desc_get_chip(desc); 120 128 int pin; 121 129 unsigned long irq_isfr; ··· 136 142 137 143 static void vf610_gpio_irq_ack(struct irq_data *d) 138 144 { 139 - struct vf610_gpio_port *port = irq_data_get_irq_chip_data(d); 145 + struct vf610_gpio_port *port = 146 + to_vf610_gp(irq_data_get_irq_chip_data(d)); 140 147 int gpio = d->hwirq; 141 148 142 149 vf610_gpio_writel(BIT(gpio), port->base + PORT_ISFR); ··· 145 150 146 151 static int vf610_gpio_irq_set_type(struct irq_data *d, u32 type) 147 152 { 148 - struct vf610_gpio_port *port = irq_data_get_irq_chip_data(d); 153 + struct vf610_gpio_port *port = 154 + to_vf610_gp(irq_data_get_irq_chip_data(d)); 149 155 u8 irqc; 150 156 151 157 switch (type) { ··· 181 185 182 186 static void vf610_gpio_irq_mask(struct irq_data *d) 183 187 { 184 - struct vf610_gpio_port *port = irq_data_get_irq_chip_data(d); 188 + struct vf610_gpio_port *port = 189 + to_vf610_gp(irq_data_get_irq_chip_data(d)); 185 190 void __iomem *pcr_base = port->base + PORT_PCR(d->hwirq); 186 191 187 192 vf610_gpio_writel(0, pcr_base); ··· 190 193 191 194 static void vf610_gpio_irq_unmask(struct irq_data *d) 192 195 { 193 - struct vf610_gpio_port *port = irq_data_get_irq_chip_data(d); 196 + struct vf610_gpio_port *port = 197 + to_vf610_gp(irq_data_get_irq_chip_data(d)); 194 198 void __iomem *pcr_base = port->base + PORT_PCR(d->hwirq); 195 199 196 200 vf610_gpio_writel(port->irqc[d->hwirq] << PORT_PCR_IRQC_OFFSET, ··· 200 202 201 203 static int vf610_gpio_irq_set_wake(struct irq_data *d, u32 enable) 202 204 { 203 - struct vf610_gpio_port *port = irq_data_get_irq_chip_data(d); 205 + struct vf610_gpio_port *port = 206 + to_vf610_gp(irq_data_get_irq_chip_data(d)); 204 207 205 208 if (enable) 206 209 enable_irq_wake(port->irq); ··· 254 255 gc->ngpio = VF610_GPIO_PER_PORT; 255 256 gc->base = of_alias_get_id(np, "gpio") * VF610_GPIO_PER_PORT; 256 257 257 - gc->request = vf610_gpio_request; 258 - gc->free = vf610_gpio_free; 258 + gc->request = gpiochip_generic_request; 259 + gc->free = gpiochip_generic_free; 259 260 gc->direction_input = vf610_gpio_direction_input; 260 261 gc->get = vf610_gpio_get; 261 262 gc->direction_output = vf610_gpio_direction_output;
+11 -10
drivers/gpio/gpio-xlp.c
··· 18 18 #include <linux/module.h> 19 19 #include <linux/irq.h> 20 20 #include <linux/interrupt.h> 21 + #include <linux/irqchip/chained_irq.h> 21 22 22 23 /* 23 24 * XLP GPIO has multiple 32 bit registers for each feature where each register ··· 209 208 .flags = IRQCHIP_ONESHOT_SAFE, 210 209 }; 211 210 212 - static irqreturn_t xlp_gpio_generic_handler(int irq, void *data) 211 + static void xlp_gpio_generic_handler(struct irq_desc *desc) 213 212 { 214 - struct xlp_gpio_priv *priv = data; 213 + struct xlp_gpio_priv *priv = irq_desc_get_handler_data(desc); 214 + struct irq_chip *irqchip = irq_desc_get_chip(desc); 215 215 int gpio, regoff; 216 216 u32 gpio_stat; 217 217 218 218 regoff = -1; 219 219 gpio_stat = 0; 220 + 221 + chained_irq_enter(irqchip, desc); 220 222 for_each_set_bit(gpio, priv->gpio_enabled_mask, XLP_MAX_NR_GPIO) { 221 223 if (regoff != gpio / XLP_GPIO_REGSZ) { 222 224 regoff = gpio / XLP_GPIO_REGSZ; 223 225 gpio_stat = readl(priv->gpio_intr_stat + regoff * 4); 224 226 } 227 + 225 228 if (gpio_stat & BIT(gpio % XLP_GPIO_REGSZ)) 226 229 generic_handle_irq(irq_find_mapping( 227 230 priv->chip.irqdomain, gpio)); 228 231 } 229 - 230 - return IRQ_HANDLED; 232 + chained_irq_exit(irqchip, desc); 231 233 } 232 234 233 235 static int xlp_gpio_dir_output(struct gpio_chip *gc, unsigned gpio, int state) ··· 382 378 gc->get = xlp_gpio_get; 383 379 384 380 spin_lock_init(&priv->lock); 385 - 386 - err = devm_request_irq(&pdev->dev, irq, xlp_gpio_generic_handler, 387 - IRQ_TYPE_NONE, pdev->name, priv); 388 - if (err) 389 - return err; 390 - 391 381 irq_base = irq_alloc_descs(-1, XLP_GPIO_IRQ_BASE, gc->ngpio, 0); 392 382 if (irq_base < 0) { 393 383 dev_err(&pdev->dev, "Failed to allocate IRQ numbers\n"); ··· 398 400 dev_err(&pdev->dev, "Could not connect irqchip to gpiochip!\n"); 399 401 goto out_gpio_remove; 400 402 } 403 + 404 + gpiochip_set_chained_irqchip(gc, &xlp_gpio_irq_chip, irq, 405 + xlp_gpio_generic_handler); 401 406 402 407 dev_info(&pdev->dev, "registered %d GPIOs\n", gc->ngpio); 403 408
+4 -24
drivers/gpio/gpio-zx.c
··· 41 41 42 42 void __iomem *base; 43 43 struct gpio_chip gc; 44 - bool uses_pinctrl; 45 44 }; 46 45 47 46 static inline struct zx_gpio *to_zx(struct gpio_chip *gc) 48 47 { 49 48 return container_of(gc, struct zx_gpio, gc); 50 - } 51 - 52 - static int zx_gpio_request(struct gpio_chip *gc, unsigned offset) 53 - { 54 - struct zx_gpio *chip = to_zx(gc); 55 - int gpio = gc->base + offset; 56 - 57 - if (chip->uses_pinctrl) 58 - return pinctrl_request_gpio(gpio); 59 - return 0; 60 - } 61 - 62 - static void zx_gpio_free(struct gpio_chip *gc, unsigned offset) 63 - { 64 - struct zx_gpio *chip = to_zx(gc); 65 - int gpio = gc->base + offset; 66 - 67 - if (chip->uses_pinctrl) 68 - pinctrl_free_gpio(gpio); 69 49 } 70 50 71 51 static int zx_direction_input(struct gpio_chip *gc, unsigned offset) ··· 232 252 return PTR_ERR(chip->base); 233 253 234 254 spin_lock_init(&chip->lock); 235 - if (of_property_read_bool(dev->of_node, "gpio-ranges")) 236 - chip->uses_pinctrl = true; 255 + if (of_property_read_bool(dev->of_node, "gpio-ranges")) { 256 + chip->gc.request = gpiochip_generic_request; 257 + chip->gc.free = gpiochip_generic_free; 258 + } 237 259 238 260 id = of_alias_get_id(dev->of_node, "gpio"); 239 - chip->gc.request = zx_gpio_request; 240 - chip->gc.free = zx_gpio_free; 241 261 chip->gc.direction_input = zx_direction_input; 242 262 chip->gc.direction_output = zx_direction_output; 243 263 chip->gc.get = zx_get_value;
+22 -10
drivers/gpio/gpio-zynq.c
··· 130 130 131 131 static struct irq_chip zynq_gpio_level_irqchip; 132 132 static struct irq_chip zynq_gpio_edge_irqchip; 133 + 134 + static struct zynq_gpio *to_zynq_gpio(struct gpio_chip *gc) 135 + { 136 + return container_of(gc, struct zynq_gpio, chip); 137 + } 138 + 133 139 /** 134 140 * zynq_gpio_get_bank_pin - Get the bank number and pin number within that bank 135 141 * for a given pin in the GPIO device ··· 183 177 { 184 178 u32 data; 185 179 unsigned int bank_num, bank_pin_num; 186 - struct zynq_gpio *gpio = container_of(chip, struct zynq_gpio, chip); 180 + struct zynq_gpio *gpio = to_zynq_gpio(chip); 187 181 188 182 zynq_gpio_get_bank_pin(pin, &bank_num, &bank_pin_num, gpio); 189 183 ··· 207 201 int state) 208 202 { 209 203 unsigned int reg_offset, bank_num, bank_pin_num; 210 - struct zynq_gpio *gpio = container_of(chip, struct zynq_gpio, chip); 204 + struct zynq_gpio *gpio = to_zynq_gpio(chip); 211 205 212 206 zynq_gpio_get_bank_pin(pin, &bank_num, &bank_pin_num, gpio); 213 207 ··· 244 238 { 245 239 u32 reg; 246 240 unsigned int bank_num, bank_pin_num; 247 - struct zynq_gpio *gpio = container_of(chip, struct zynq_gpio, chip); 241 + struct zynq_gpio *gpio = to_zynq_gpio(chip); 248 242 249 243 zynq_gpio_get_bank_pin(pin, &bank_num, &bank_pin_num, gpio); 250 244 ··· 277 271 { 278 272 u32 reg; 279 273 unsigned int bank_num, bank_pin_num; 280 - struct zynq_gpio *gpio = container_of(chip, struct zynq_gpio, chip); 274 + struct zynq_gpio *gpio = to_zynq_gpio(chip); 281 275 282 276 zynq_gpio_get_bank_pin(pin, &bank_num, &bank_pin_num, gpio); 283 277 ··· 307 301 static void zynq_gpio_irq_mask(struct irq_data *irq_data) 308 302 { 309 303 unsigned int device_pin_num, bank_num, bank_pin_num; 310 - struct zynq_gpio *gpio = irq_data_get_irq_chip_data(irq_data); 304 + struct zynq_gpio *gpio = 305 + to_zynq_gpio(irq_data_get_irq_chip_data(irq_data)); 311 306 312 307 device_pin_num = irq_data->hwirq; 313 308 zynq_gpio_get_bank_pin(device_pin_num, &bank_num, &bank_pin_num, gpio); ··· 328 321 static void zynq_gpio_irq_unmask(struct irq_data *irq_data) 329 322 { 330 323 unsigned int device_pin_num, bank_num, bank_pin_num; 331 - struct zynq_gpio *gpio = irq_data_get_irq_chip_data(irq_data); 324 + struct zynq_gpio *gpio = 325 + to_zynq_gpio(irq_data_get_irq_chip_data(irq_data)); 332 326 333 327 device_pin_num = irq_data->hwirq; 334 328 zynq_gpio_get_bank_pin(device_pin_num, &bank_num, &bank_pin_num, gpio); ··· 348 340 static void zynq_gpio_irq_ack(struct irq_data *irq_data) 349 341 { 350 342 unsigned int device_pin_num, bank_num, bank_pin_num; 351 - struct zynq_gpio *gpio = irq_data_get_irq_chip_data(irq_data); 343 + struct zynq_gpio *gpio = 344 + to_zynq_gpio(irq_data_get_irq_chip_data(irq_data)); 352 345 353 346 device_pin_num = irq_data->hwirq; 354 347 zynq_gpio_get_bank_pin(device_pin_num, &bank_num, &bank_pin_num, gpio); ··· 399 390 { 400 391 u32 int_type, int_pol, int_any; 401 392 unsigned int device_pin_num, bank_num, bank_pin_num; 402 - struct zynq_gpio *gpio = irq_data_get_irq_chip_data(irq_data); 393 + struct zynq_gpio *gpio = 394 + to_zynq_gpio(irq_data_get_irq_chip_data(irq_data)); 403 395 404 396 device_pin_num = irq_data->hwirq; 405 397 zynq_gpio_get_bank_pin(device_pin_num, &bank_num, &bank_pin_num, gpio); ··· 463 453 464 454 static int zynq_gpio_set_wake(struct irq_data *data, unsigned int on) 465 455 { 466 - struct zynq_gpio *gpio = irq_data_get_irq_chip_data(data); 456 + struct zynq_gpio *gpio = 457 + to_zynq_gpio(irq_data_get_irq_chip_data(data)); 467 458 468 459 irq_set_irq_wake(gpio->irq, on); 469 460 ··· 529 518 { 530 519 u32 int_sts, int_enb; 531 520 unsigned int bank_num; 532 - struct zynq_gpio *gpio = irq_desc_get_handler_data(desc); 521 + struct zynq_gpio *gpio = 522 + to_zynq_gpio(irq_desc_get_handler_data(desc)); 533 523 struct irq_chip *irqchip = irq_desc_get_chip(desc); 534 524 535 525 chained_irq_enter(irqchip, desc);
+20 -1
drivers/gpio/gpiolib-acpi.c
··· 304 304 if (ACPI_FAILURE(status)) 305 305 return; 306 306 307 - INIT_LIST_HEAD(&acpi_gpio->events); 308 307 acpi_walk_resources(handle, "_AEI", 309 308 acpi_gpiochip_request_interrupt, acpi_gpio); 310 309 } ··· 602 603 break; 603 604 } 604 605 } 606 + 607 + /* 608 + * The same GPIO can be shared between operation region and 609 + * event but only if the access here is ACPI_READ. In that 610 + * case we "borrow" the event GPIO instead. 611 + */ 612 + if (!found && agpio->sharable == ACPI_SHARED && 613 + function == ACPI_READ) { 614 + struct acpi_gpio_event *event; 615 + 616 + list_for_each_entry(event, &achip->events, node) { 617 + if (event->pin == pin) { 618 + desc = event->desc; 619 + found = true; 620 + break; 621 + } 622 + } 623 + } 624 + 605 625 if (!found) { 606 626 desc = gpiochip_request_own_desc(chip, pin, 607 627 "ACPI:OpRegion"); ··· 737 719 } 738 720 739 721 acpi_gpio->chip = chip; 722 + INIT_LIST_HEAD(&acpi_gpio->events); 740 723 741 724 status = acpi_attach_data(handle, acpi_gpio_chip_dh, acpi_gpio); 742 725 if (ACPI_FAILURE(status)) {
+4 -4
drivers/gpio/gpiolib-legacy.c
··· 28 28 if (!desc && gpio_is_valid(gpio)) 29 29 return -EPROBE_DEFER; 30 30 31 - err = gpiod_request(desc, label); 32 - if (err) 33 - return err; 34 - 35 31 if (flags & GPIOF_OPEN_DRAIN) 36 32 set_bit(FLAG_OPEN_DRAIN, &desc->flags); 37 33 ··· 36 40 37 41 if (flags & GPIOF_ACTIVE_LOW) 38 42 set_bit(FLAG_ACTIVE_LOW, &desc->flags); 43 + 44 + err = gpiod_request(desc, label); 45 + if (err) 46 + return err; 39 47 40 48 if (flags & GPIOF_DIR_IN) 41 49 err = gpiod_direction_input(desc);
+10 -10
drivers/gpio/gpiolib-of.c
··· 119 119 EXPORT_SYMBOL(of_get_named_gpio_flags); 120 120 121 121 /** 122 - * of_get_gpio_hog() - Get a GPIO hog descriptor, names and flags for GPIO API 122 + * of_parse_own_gpio() - Get a GPIO hog descriptor, names and flags for GPIO API 123 123 * @np: device node to get GPIO from 124 124 * @name: GPIO line name 125 125 * @lflags: gpio_lookup_flags - returned from of_find_gpio() or 126 - * of_get_gpio_hog() 126 + * of_parse_own_gpio() 127 127 * @dflags: gpiod_flags - optional GPIO initialization flags 128 128 * 129 129 * Returns GPIO descriptor to use with Linux GPIO API, or one of the errno 130 130 * value on the error condition. 131 131 */ 132 - static struct gpio_desc *of_get_gpio_hog(struct device_node *np, 133 - const char **name, 134 - enum gpio_lookup_flags *lflags, 135 - enum gpiod_flags *dflags) 132 + static struct gpio_desc *of_parse_own_gpio(struct device_node *np, 133 + const char **name, 134 + enum gpio_lookup_flags *lflags, 135 + enum gpiod_flags *dflags) 136 136 { 137 137 struct device_node *chip_np; 138 138 enum of_gpio_flags xlate_flags; ··· 196 196 } 197 197 198 198 /** 199 - * of_gpiochip_scan_hogs - Scan gpio-controller and apply GPIO hog as requested 199 + * of_gpiochip_scan_gpios - Scan gpio-controller for gpio definitions 200 200 * @chip: gpio chip to act on 201 201 * 202 202 * This is only used by of_gpiochip_add to request/set GPIO initial 203 203 * configuration. 204 204 */ 205 - static void of_gpiochip_scan_hogs(struct gpio_chip *chip) 205 + static void of_gpiochip_scan_gpios(struct gpio_chip *chip) 206 206 { 207 207 struct gpio_desc *desc = NULL; 208 208 struct device_node *np; ··· 214 214 if (!of_property_read_bool(np, "gpio-hog")) 215 215 continue; 216 216 217 - desc = of_get_gpio_hog(np, &name, &lflags, &dflags); 217 + desc = of_parse_own_gpio(np, &name, &lflags, &dflags); 218 218 if (IS_ERR(desc)) 219 219 continue; 220 220 ··· 440 440 441 441 of_node_get(chip->of_node); 442 442 443 - of_gpiochip_scan_hogs(chip); 443 + of_gpiochip_scan_gpios(chip); 444 444 445 445 return 0; 446 446 }
+152 -23
drivers/gpio/gpiolib.c
··· 15 15 #include <linux/acpi.h> 16 16 #include <linux/gpio/driver.h> 17 17 #include <linux/gpio/machine.h> 18 + #include <linux/pinctrl/consumer.h> 18 19 19 20 #include "gpiolib.h" 20 21 ··· 47 46 * each GPIO's "requested" flag serves as a lock and refcount. 48 47 */ 49 48 DEFINE_SPINLOCK(gpio_lock); 50 - 51 - #define GPIO_OFFSET_VALID(chip, offset) (offset >= 0 && offset < chip->ngpio) 52 49 53 50 static DEFINE_MUTEX(gpio_lookup_lock); 54 51 static LIST_HEAD(gpio_lookup_list); ··· 218 219 } 219 220 220 221 /** 222 + * Convert a GPIO name to its descriptor 223 + */ 224 + static struct gpio_desc *gpio_name_to_desc(const char * const name) 225 + { 226 + struct gpio_chip *chip; 227 + unsigned long flags; 228 + 229 + spin_lock_irqsave(&gpio_lock, flags); 230 + 231 + list_for_each_entry(chip, &gpio_chips, list) { 232 + int i; 233 + 234 + for (i = 0; i != chip->ngpio; ++i) { 235 + struct gpio_desc *gpio = &chip->desc[i]; 236 + 237 + if (!gpio->name) 238 + continue; 239 + 240 + if (!strcmp(gpio->name, name)) { 241 + spin_unlock_irqrestore(&gpio_lock, flags); 242 + return gpio; 243 + } 244 + } 245 + } 246 + 247 + spin_unlock_irqrestore(&gpio_lock, flags); 248 + 249 + return NULL; 250 + } 251 + 252 + /* 253 + * Takes the names from gc->names and checks if they are all unique. If they 254 + * are, they are assigned to their gpio descriptors. 255 + * 256 + * Returns -EEXIST if one of the names is already used for a different GPIO. 257 + */ 258 + static int gpiochip_set_desc_names(struct gpio_chip *gc) 259 + { 260 + int i; 261 + 262 + if (!gc->names) 263 + return 0; 264 + 265 + /* First check all names if they are unique */ 266 + for (i = 0; i != gc->ngpio; ++i) { 267 + struct gpio_desc *gpio; 268 + 269 + gpio = gpio_name_to_desc(gc->names[i]); 270 + if (gpio) 271 + dev_warn(gc->dev, "Detected name collision for " 272 + "GPIO name '%s'\n", 273 + gc->names[i]); 274 + } 275 + 276 + /* Then add all names to the GPIO descriptors */ 277 + for (i = 0; i != gc->ngpio; ++i) 278 + gc->desc[i].name = gc->names[i]; 279 + 280 + return 0; 281 + } 282 + 283 + /** 221 284 * gpiochip_add() - register a gpio_chip 222 285 * @chip: the chip to register, with chip->base initialized 223 286 * Context: potentially before irqs will work ··· 351 290 if (!chip->owner && chip->dev && chip->dev->driver) 352 291 chip->owner = chip->dev->driver->owner; 353 292 293 + status = gpiochip_set_desc_names(chip); 294 + if (status) 295 + goto err_remove_from_list; 296 + 354 297 status = of_gpiochip_add(chip); 355 298 if (status) 356 299 goto err_remove_chip; ··· 375 310 acpi_gpiochip_remove(chip); 376 311 gpiochip_free_hogs(chip); 377 312 of_gpiochip_remove(chip); 313 + err_remove_from_list: 378 314 spin_lock_irqsave(&gpio_lock, flags); 379 315 list_del(&chip->list); 380 316 spin_unlock_irqrestore(&gpio_lock, flags); ··· 746 680 747 681 #endif /* CONFIG_GPIOLIB_IRQCHIP */ 748 682 683 + /** 684 + * gpiochip_generic_request() - request the gpio function for a pin 685 + * @chip: the gpiochip owning the GPIO 686 + * @offset: the offset of the GPIO to request for GPIO function 687 + */ 688 + int gpiochip_generic_request(struct gpio_chip *chip, unsigned offset) 689 + { 690 + return pinctrl_request_gpio(chip->base + offset); 691 + } 692 + EXPORT_SYMBOL_GPL(gpiochip_generic_request); 693 + 694 + /** 695 + * gpiochip_generic_free() - free the gpio function from a pin 696 + * @chip: the gpiochip to request the gpio function for 697 + * @offset: the offset of the GPIO to free from GPIO function 698 + */ 699 + void gpiochip_generic_free(struct gpio_chip *chip, unsigned offset) 700 + { 701 + pinctrl_free_gpio(chip->base + offset); 702 + } 703 + EXPORT_SYMBOL_GPL(gpiochip_generic_free); 704 + 749 705 #ifdef CONFIG_PINCTRL 750 706 751 707 /** ··· 927 839 spin_lock_irqsave(&gpio_lock, flags); 928 840 } 929 841 done: 842 + if (status < 0) { 843 + /* Clear flags that might have been set by the caller before 844 + * requesting the GPIO. 845 + */ 846 + clear_bit(FLAG_ACTIVE_LOW, &desc->flags); 847 + clear_bit(FLAG_OPEN_DRAIN, &desc->flags); 848 + clear_bit(FLAG_OPEN_SOURCE, &desc->flags); 849 + } 930 850 spin_unlock_irqrestore(&gpio_lock, flags); 931 851 return status; 932 852 } ··· 1024 928 { 1025 929 struct gpio_desc *desc; 1026 930 1027 - if (!GPIO_OFFSET_VALID(chip, offset)) 931 + if (offset >= chip->ngpio) 1028 932 return NULL; 1029 933 1030 934 desc = &chip->desc[offset]; ··· 1831 1735 if (of_flags & OF_GPIO_ACTIVE_LOW) 1832 1736 *flags |= GPIO_ACTIVE_LOW; 1833 1737 1738 + if (of_flags & OF_GPIO_SINGLE_ENDED) { 1739 + if (of_flags & OF_GPIO_ACTIVE_LOW) 1740 + *flags |= GPIO_OPEN_DRAIN; 1741 + else 1742 + *flags |= GPIO_OPEN_SOURCE; 1743 + } 1744 + 1834 1745 return desc; 1835 1746 } 1836 1747 ··· 2056 1953 } 2057 1954 EXPORT_SYMBOL_GPL(gpiod_get_optional); 2058 1955 1956 + /** 1957 + * gpiod_parse_flags - helper function to parse GPIO lookup flags 1958 + * @desc: gpio to be setup 1959 + * @lflags: gpio_lookup_flags - returned from of_find_gpio() or 1960 + * of_get_gpio_hog() 1961 + * 1962 + * Set the GPIO descriptor flags based on the given GPIO lookup flags. 1963 + */ 1964 + static void gpiod_parse_flags(struct gpio_desc *desc, unsigned long lflags) 1965 + { 1966 + if (lflags & GPIO_ACTIVE_LOW) 1967 + set_bit(FLAG_ACTIVE_LOW, &desc->flags); 1968 + if (lflags & GPIO_OPEN_DRAIN) 1969 + set_bit(FLAG_OPEN_DRAIN, &desc->flags); 1970 + if (lflags & GPIO_OPEN_SOURCE) 1971 + set_bit(FLAG_OPEN_SOURCE, &desc->flags); 1972 + } 2059 1973 2060 1974 /** 2061 1975 * gpiod_configure_flags - helper function to configure a given GPIO 2062 1976 * @desc: gpio whose value will be assigned 2063 1977 * @con_id: function within the GPIO consumer 2064 - * @lflags: gpio_lookup_flags - returned from of_find_gpio() or 2065 - * of_get_gpio_hog() 2066 1978 * @dflags: gpiod_flags - optional GPIO initialization flags 2067 1979 * 2068 1980 * Return 0 on success, -ENOENT if no GPIO has been assigned to the ··· 2085 1967 * occurred while trying to acquire the GPIO. 2086 1968 */ 2087 1969 static int gpiod_configure_flags(struct gpio_desc *desc, const char *con_id, 2088 - unsigned long lflags, enum gpiod_flags dflags) 1970 + enum gpiod_flags dflags) 2089 1971 { 2090 1972 int status; 2091 - 2092 - if (lflags & GPIO_ACTIVE_LOW) 2093 - set_bit(FLAG_ACTIVE_LOW, &desc->flags); 2094 - if (lflags & GPIO_OPEN_DRAIN) 2095 - set_bit(FLAG_OPEN_DRAIN, &desc->flags); 2096 - if (lflags & GPIO_OPEN_SOURCE) 2097 - set_bit(FLAG_OPEN_SOURCE, &desc->flags); 2098 1973 2099 1974 /* No particular flag request, return here... */ 2100 1975 if (!(dflags & GPIOD_FLAGS_BIT_DIR_SET)) { ··· 2155 2044 return desc; 2156 2045 } 2157 2046 2047 + gpiod_parse_flags(desc, lookupflags); 2048 + 2158 2049 status = gpiod_request(desc, con_id); 2159 2050 if (status < 0) 2160 2051 return ERR_PTR(status); 2161 2052 2162 - status = gpiod_configure_flags(desc, con_id, lookupflags, flags); 2053 + status = gpiod_configure_flags(desc, con_id, flags); 2163 2054 if (status < 0) { 2164 2055 dev_dbg(dev, "setup of GPIO %s failed\n", con_id); 2165 2056 gpiod_put(desc); ··· 2191 2078 { 2192 2079 struct gpio_desc *desc = ERR_PTR(-ENODEV); 2193 2080 bool active_low = false; 2081 + bool single_ended = false; 2194 2082 int ret; 2195 2083 2196 2084 if (!fwnode) ··· 2202 2088 2203 2089 desc = of_get_named_gpiod_flags(to_of_node(fwnode), propname, 0, 2204 2090 &flags); 2205 - if (!IS_ERR(desc)) 2091 + if (!IS_ERR(desc)) { 2206 2092 active_low = flags & OF_GPIO_ACTIVE_LOW; 2093 + single_ended = flags & OF_GPIO_SINGLE_ENDED; 2094 + } 2207 2095 } else if (is_acpi_node(fwnode)) { 2208 2096 struct acpi_gpio_info info; 2209 2097 ··· 2218 2102 if (IS_ERR(desc)) 2219 2103 return desc; 2220 2104 2105 + if (active_low) 2106 + set_bit(FLAG_ACTIVE_LOW, &desc->flags); 2107 + 2108 + if (single_ended) { 2109 + if (active_low) 2110 + set_bit(FLAG_OPEN_DRAIN, &desc->flags); 2111 + else 2112 + set_bit(FLAG_OPEN_SOURCE, &desc->flags); 2113 + } 2114 + 2221 2115 ret = gpiod_request(desc, NULL); 2222 2116 if (ret) 2223 2117 return ERR_PTR(ret); 2224 - 2225 - /* Only value flag can be set from both DT and ACPI is active_low */ 2226 - if (active_low) 2227 - set_bit(FLAG_ACTIVE_LOW, &desc->flags); 2228 2118 2229 2119 return desc; 2230 2120 } ··· 2284 2162 chip = gpiod_to_chip(desc); 2285 2163 hwnum = gpio_chip_hwgpio(desc); 2286 2164 2165 + gpiod_parse_flags(desc, lflags); 2166 + 2287 2167 local_desc = gpiochip_request_own_desc(chip, hwnum, name); 2288 2168 if (IS_ERR(local_desc)) { 2289 2169 pr_err("requesting hog GPIO %s (chip %s, offset %d) failed\n", ··· 2293 2169 return PTR_ERR(local_desc); 2294 2170 } 2295 2171 2296 - status = gpiod_configure_flags(desc, name, lflags, dflags); 2172 + status = gpiod_configure_flags(desc, name, dflags); 2297 2173 if (status < 0) { 2298 2174 pr_err("setup of hog GPIO %s (chip %s, offset %d) failed\n", 2299 2175 name, chip->label, hwnum); ··· 2433 2309 int is_irq; 2434 2310 2435 2311 for (i = 0; i < chip->ngpio; i++, gpio++, gdesc++) { 2436 - if (!test_bit(FLAG_REQUESTED, &gdesc->flags)) 2312 + if (!test_bit(FLAG_REQUESTED, &gdesc->flags)) { 2313 + if (gdesc->name) { 2314 + seq_printf(s, " gpio-%-3d (%-20.20s)\n", 2315 + gpio, gdesc->name); 2316 + } 2437 2317 continue; 2318 + } 2438 2319 2439 2320 gpiod_get_direction(gdesc); 2440 2321 is_out = test_bit(FLAG_IS_OUT, &gdesc->flags); 2441 2322 is_irq = test_bit(FLAG_USED_AS_IRQ, &gdesc->flags); 2442 - seq_printf(s, " gpio-%-3d (%-20.20s) %s %s %s", 2443 - gpio, gdesc->label, 2323 + seq_printf(s, " gpio-%-3d (%-20.20s|%-20.20s) %s %s %s", 2324 + gpio, gdesc->name ? gdesc->name : "", gdesc->label, 2444 2325 is_out ? "out" : "in ", 2445 2326 chip->get 2446 2327 ? (chip->get(chip, i) ? "hi" : "lo")
+3
drivers/gpio/gpiolib.h
··· 89 89 #define FLAG_USED_AS_IRQ 9 /* GPIO is connected to an IRQ */ 90 90 #define FLAG_IS_HOGGED 11 /* GPIO is hogged */ 91 91 92 + /* Connection label */ 92 93 const char *label; 94 + /* Name of the GPIO */ 95 + const char *name; 93 96 }; 94 97 95 98 int gpiod_request(struct gpio_desc *desc, const char *label);
+2 -12
drivers/pinctrl/bcm/pinctrl-bcm2835.c
··· 330 330 bcm2835_gpio_wr(pc, FSEL_REG(pin), val); 331 331 } 332 332 333 - static int bcm2835_gpio_request(struct gpio_chip *chip, unsigned offset) 334 - { 335 - return pinctrl_request_gpio(chip->base + offset); 336 - } 337 - 338 - static void bcm2835_gpio_free(struct gpio_chip *chip, unsigned offset) 339 - { 340 - pinctrl_free_gpio(chip->base + offset); 341 - } 342 - 343 333 static int bcm2835_gpio_direction_input(struct gpio_chip *chip, unsigned offset) 344 334 { 345 335 return pinctrl_gpio_direction_input(chip->base + offset); ··· 365 375 static struct gpio_chip bcm2835_gpio_chip = { 366 376 .label = MODULE_NAME, 367 377 .owner = THIS_MODULE, 368 - .request = bcm2835_gpio_request, 369 - .free = bcm2835_gpio_free, 378 + .request = gpiochip_generic_request, 379 + .free = gpiochip_generic_free, 370 380 .direction_input = bcm2835_gpio_direction_input, 371 381 .direction_output = bcm2835_gpio_direction_output, 372 382 .get = bcm2835_gpio_get,
+2 -12
drivers/pinctrl/intel/pinctrl-cherryview.c
··· 1149 1149 .owner = THIS_MODULE, 1150 1150 }; 1151 1151 1152 - static int chv_gpio_request(struct gpio_chip *chip, unsigned offset) 1153 - { 1154 - return pinctrl_request_gpio(chip->base + offset); 1155 - } 1156 - 1157 - static void chv_gpio_free(struct gpio_chip *chip, unsigned offset) 1158 - { 1159 - pinctrl_free_gpio(chip->base + offset); 1160 - } 1161 - 1162 1152 static unsigned chv_gpio_offset_to_pin(struct chv_pinctrl *pctrl, 1163 1153 unsigned offset) 1164 1154 { ··· 1228 1238 1229 1239 static const struct gpio_chip chv_gpio_chip = { 1230 1240 .owner = THIS_MODULE, 1231 - .request = chv_gpio_request, 1232 - .free = chv_gpio_free, 1241 + .request = gpiochip_generic_request, 1242 + .free = gpiochip_generic_free, 1233 1243 .get_direction = chv_gpio_get_direction, 1234 1244 .direction_input = chv_gpio_direction_input, 1235 1245 .direction_output = chv_gpio_direction_output,
+2 -12
drivers/pinctrl/intel/pinctrl-intel.c
··· 596 596 .owner = THIS_MODULE, 597 597 }; 598 598 599 - static int intel_gpio_request(struct gpio_chip *chip, unsigned offset) 600 - { 601 - return pinctrl_request_gpio(chip->base + offset); 602 - } 603 - 604 - static void intel_gpio_free(struct gpio_chip *chip, unsigned offset) 605 - { 606 - pinctrl_free_gpio(chip->base + offset); 607 - } 608 - 609 599 static int intel_gpio_get(struct gpio_chip *chip, unsigned offset) 610 600 { 611 601 struct intel_pinctrl *pctrl = gpiochip_to_pinctrl(chip); ··· 643 653 644 654 static const struct gpio_chip intel_gpio_chip = { 645 655 .owner = THIS_MODULE, 646 - .request = intel_gpio_request, 647 - .free = intel_gpio_free, 656 + .request = gpiochip_generic_request, 657 + .free = gpiochip_generic_free, 648 658 .direction_input = intel_gpio_direction_input, 649 659 .direction_output = intel_gpio_direction_output, 650 660 .get = intel_gpio_get,
+2 -12
drivers/pinctrl/mediatek/pinctrl-mtk-common.c
··· 723 723 .gpio_set_direction = mtk_pmx_gpio_set_direction, 724 724 }; 725 725 726 - static int mtk_gpio_request(struct gpio_chip *chip, unsigned offset) 727 - { 728 - return pinctrl_request_gpio(chip->base + offset); 729 - } 730 - 731 - static void mtk_gpio_free(struct gpio_chip *chip, unsigned offset) 732 - { 733 - pinctrl_free_gpio(chip->base + offset); 734 - } 735 - 736 726 static int mtk_gpio_direction_input(struct gpio_chip *chip, 737 727 unsigned offset) 738 728 { ··· 995 1005 996 1006 static struct gpio_chip mtk_gpio_chip = { 997 1007 .owner = THIS_MODULE, 998 - .request = mtk_gpio_request, 999 - .free = mtk_gpio_free, 1008 + .request = gpiochip_generic_request, 1009 + .free = gpiochip_generic_free, 1000 1010 .direction_input = mtk_gpio_direction_input, 1001 1011 .direction_output = mtk_gpio_direction_output, 1002 1012 .get = mtk_gpio_get,
+2 -16
drivers/pinctrl/nomadik/pinctrl-abx500.c
··· 654 654 #define abx500_gpio_dbg_show NULL 655 655 #endif 656 656 657 - static int abx500_gpio_request(struct gpio_chip *chip, unsigned offset) 658 - { 659 - int gpio = chip->base + offset; 660 - 661 - return pinctrl_request_gpio(gpio); 662 - } 663 - 664 - static void abx500_gpio_free(struct gpio_chip *chip, unsigned offset) 665 - { 666 - int gpio = chip->base + offset; 667 - 668 - pinctrl_free_gpio(gpio); 669 - } 670 - 671 657 static struct gpio_chip abx500gpio_chip = { 672 658 .label = "abx500-gpio", 673 659 .owner = THIS_MODULE, 674 - .request = abx500_gpio_request, 675 - .free = abx500_gpio_free, 660 + .request = gpiochip_generic_request, 661 + .free = gpiochip_generic_free, 676 662 .direction_input = abx500_gpio_direction_input, 677 663 .get = abx500_gpio_get, 678 664 .direction_output = abx500_gpio_direction_output,
+2 -20
drivers/pinctrl/nomadik/pinctrl-nomadik.c
··· 884 884 885 885 /* I/O Functions */ 886 886 887 - static int nmk_gpio_request(struct gpio_chip *chip, unsigned offset) 888 - { 889 - /* 890 - * Map back to global GPIO space and request muxing, the direction 891 - * parameter does not matter for this controller. 892 - */ 893 - int gpio = chip->base + offset; 894 - 895 - return pinctrl_request_gpio(gpio); 896 - } 897 - 898 - static void nmk_gpio_free(struct gpio_chip *chip, unsigned offset) 899 - { 900 - int gpio = chip->base + offset; 901 - 902 - pinctrl_free_gpio(gpio); 903 - } 904 - 905 887 static int nmk_gpio_make_input(struct gpio_chip *chip, unsigned offset) 906 888 { 907 889 struct nmk_gpio_chip *nmk_chip = ··· 1249 1267 spin_lock_init(&nmk_chip->lock); 1250 1268 1251 1269 chip = &nmk_chip->chip; 1252 - chip->request = nmk_gpio_request; 1253 - chip->free = nmk_gpio_free; 1270 + chip->request = gpiochip_generic_request; 1271 + chip->free = gpiochip_generic_free; 1254 1272 chip->direction_input = nmk_gpio_make_input; 1255 1273 chip->get = nmk_gpio_get_input; 1256 1274 chip->direction_output = nmk_gpio_make_output;
+2 -12
drivers/pinctrl/pinctrl-adi2.c
··· 713 713 .owner = THIS_MODULE, 714 714 }; 715 715 716 - static int adi_gpio_request(struct gpio_chip *chip, unsigned offset) 717 - { 718 - return pinctrl_request_gpio(chip->base + offset); 719 - } 720 - 721 - static void adi_gpio_free(struct gpio_chip *chip, unsigned offset) 722 - { 723 - pinctrl_free_gpio(chip->base + offset); 724 - } 725 - 726 716 static int adi_gpio_direction_input(struct gpio_chip *chip, unsigned offset) 727 717 { 728 718 struct gpio_port *port; ··· 984 994 port->chip.get = adi_gpio_get_value; 985 995 port->chip.direction_output = adi_gpio_direction_output; 986 996 port->chip.set = adi_gpio_set_value; 987 - port->chip.request = adi_gpio_request; 988 - port->chip.free = adi_gpio_free; 997 + port->chip.request = gpiochip_generic_request, 998 + port->chip.free = gpiochip_generic_free, 989 999 port->chip.to_irq = adi_gpio_to_irq; 990 1000 if (pdata->port_gpio_base > 0) 991 1001 port->chip.base = pdata->port_gpio_base;
+2 -12
drivers/pinctrl/pinctrl-as3722.c
··· 536 536 return as3722_irq_get_virq(as_pci->as3722, offset); 537 537 } 538 538 539 - static int as3722_gpio_request(struct gpio_chip *chip, unsigned offset) 540 - { 541 - return pinctrl_request_gpio(chip->base + offset); 542 - } 543 - 544 - static void as3722_gpio_free(struct gpio_chip *chip, unsigned offset) 545 - { 546 - pinctrl_free_gpio(chip->base + offset); 547 - } 548 - 549 539 static const struct gpio_chip as3722_gpio_chip = { 550 540 .label = "as3722-gpio", 551 541 .owner = THIS_MODULE, 552 - .request = as3722_gpio_request, 553 - .free = as3722_gpio_free, 542 + .request = gpiochip_generic_request, 543 + .free = gpiochip_generic_free, 554 544 .get = as3722_gpio_get, 555 545 .set = as3722_gpio_set, 556 546 .direction_input = as3722_gpio_direction_input,
+2 -24
drivers/pinctrl/pinctrl-at91.c
··· 1280 1280 return 0; 1281 1281 } 1282 1282 1283 - static int at91_gpio_request(struct gpio_chip *chip, unsigned offset) 1284 - { 1285 - /* 1286 - * Map back to global GPIO space and request muxing, the direction 1287 - * parameter does not matter for this controller. 1288 - */ 1289 - int gpio = chip->base + offset; 1290 - int bank = chip->base / chip->ngpio; 1291 - 1292 - dev_dbg(chip->dev, "%s:%d pio%c%d(%d)\n", __func__, __LINE__, 1293 - 'A' + bank, offset, gpio); 1294 - 1295 - return pinctrl_request_gpio(gpio); 1296 - } 1297 - 1298 - static void at91_gpio_free(struct gpio_chip *chip, unsigned offset) 1299 - { 1300 - int gpio = chip->base + offset; 1301 - 1302 - pinctrl_free_gpio(gpio); 1303 - } 1304 - 1305 1283 static int at91_gpio_get_direction(struct gpio_chip *chip, unsigned offset) 1306 1284 { 1307 1285 struct at91_gpio_chip *at91_gpio = to_at91_gpio_chip(chip); ··· 1665 1687 1666 1688 /* This structure is replicated for each GPIO block allocated at probe time */ 1667 1689 static struct gpio_chip at91_gpio_template = { 1668 - .request = at91_gpio_request, 1669 - .free = at91_gpio_free, 1690 + .request = gpiochip_generic_request, 1691 + .free = gpiochip_generic_free, 1670 1692 .get_direction = at91_gpio_get_direction, 1671 1693 .direction_input = at91_gpio_direction_input, 1672 1694 .get = at91_gpio_get,
+2 -20
drivers/pinctrl/pinctrl-coh901.c
··· 217 217 return container_of(chip, struct u300_gpio, chip); 218 218 } 219 219 220 - static int u300_gpio_request(struct gpio_chip *chip, unsigned offset) 221 - { 222 - /* 223 - * Map back to global GPIO space and request muxing, the direction 224 - * parameter does not matter for this controller. 225 - */ 226 - int gpio = chip->base + offset; 227 - 228 - return pinctrl_request_gpio(gpio); 229 - } 230 - 231 - static void u300_gpio_free(struct gpio_chip *chip, unsigned offset) 232 - { 233 - int gpio = chip->base + offset; 234 - 235 - pinctrl_free_gpio(gpio); 236 - } 237 - 238 220 static int u300_gpio_get(struct gpio_chip *chip, unsigned offset) 239 221 { 240 222 struct u300_gpio *gpio = to_u300_gpio(chip); ··· 399 417 static struct gpio_chip u300_gpio_chip = { 400 418 .label = "u300-gpio-chip", 401 419 .owner = THIS_MODULE, 402 - .request = u300_gpio_request, 403 - .free = u300_gpio_free, 420 + .request = gpiochip_generic_request, 421 + .free = gpiochip_generic_free, 404 422 .get = u300_gpio_get, 405 423 .set = u300_gpio_set, 406 424 .direction_input = u300_gpio_direction_input,
+2 -12
drivers/pinctrl/pinctrl-digicolor.c
··· 169 169 .gpio_request_enable = dc_pmx_request_gpio, 170 170 }; 171 171 172 - static int dc_gpio_request(struct gpio_chip *chip, unsigned gpio) 173 - { 174 - return pinctrl_request_gpio(chip->base + gpio); 175 - } 176 - 177 - static void dc_gpio_free(struct gpio_chip *chip, unsigned gpio) 178 - { 179 - pinctrl_free_gpio(chip->base + gpio); 180 - } 181 - 182 172 static int dc_gpio_direction_input(struct gpio_chip *chip, unsigned gpio) 183 173 { 184 174 struct dc_pinmap *pmap = container_of(chip, struct dc_pinmap, chip); ··· 245 255 246 256 chip->label = DRIVER_NAME; 247 257 chip->dev = pmap->dev; 248 - chip->request = dc_gpio_request; 249 - chip->free = dc_gpio_free; 258 + chip->request = gpiochip_generic_request; 259 + chip->free = gpiochip_generic_free; 250 260 chip->direction_input = dc_gpio_direction_input; 251 261 chip->direction_output = dc_gpio_direction_output; 252 262 chip->get = dc_gpio_get;
+2 -12
drivers/pinctrl/pinctrl-pistachio.c
··· 1171 1171 .confops = &pistachio_pinconf_ops, 1172 1172 }; 1173 1173 1174 - static int pistachio_gpio_request(struct gpio_chip *chip, unsigned offset) 1175 - { 1176 - return pinctrl_request_gpio(chip->base + offset); 1177 - } 1178 - 1179 - static void pistachio_gpio_free(struct gpio_chip *chip, unsigned offset) 1180 - { 1181 - pinctrl_free_gpio(chip->base + offset); 1182 - } 1183 - 1184 1174 static int pistachio_gpio_get_direction(struct gpio_chip *chip, unsigned offset) 1185 1175 { 1186 1176 struct pistachio_gpio_bank *bank = gc_to_bank(chip); ··· 1322 1332 .npins = _npins, \ 1323 1333 .gpio_chip = { \ 1324 1334 .label = "GPIO" #_bank, \ 1325 - .request = pistachio_gpio_request, \ 1326 - .free = pistachio_gpio_free, \ 1335 + .request = gpiochip_generic_request, \ 1336 + .free = gpiochip_generic_free, \ 1327 1337 .get_direction = pistachio_gpio_get_direction, \ 1328 1338 .direction_input = pistachio_gpio_direction_input, \ 1329 1339 .direction_output = pistachio_gpio_direction_output, \
+2 -12
drivers/pinctrl/pinctrl-rockchip.c
··· 1374 1374 * GPIO handling 1375 1375 */ 1376 1376 1377 - static int rockchip_gpio_request(struct gpio_chip *chip, unsigned offset) 1378 - { 1379 - return pinctrl_request_gpio(chip->base + offset); 1380 - } 1381 - 1382 - static void rockchip_gpio_free(struct gpio_chip *chip, unsigned offset) 1383 - { 1384 - pinctrl_free_gpio(chip->base + offset); 1385 - } 1386 - 1387 1377 static void rockchip_gpio_set(struct gpio_chip *gc, unsigned offset, int value) 1388 1378 { 1389 1379 struct rockchip_pin_bank *bank = gc_to_pin_bank(gc); ··· 1451 1461 } 1452 1462 1453 1463 static const struct gpio_chip rockchip_gpiolib_chip = { 1454 - .request = rockchip_gpio_request, 1455 - .free = rockchip_gpio_free, 1464 + .request = gpiochip_generic_request, 1465 + .free = gpiochip_generic_free, 1456 1466 .set = rockchip_gpio_set, 1457 1467 .get = rockchip_gpio_get, 1458 1468 .direction_input = rockchip_gpio_direction_input,
+2 -12
drivers/pinctrl/pinctrl-st.c
··· 742 742 } 743 743 } 744 744 745 - static int st_gpio_request(struct gpio_chip *chip, unsigned offset) 746 - { 747 - return pinctrl_request_gpio(chip->base + offset); 748 - } 749 - 750 - static void st_gpio_free(struct gpio_chip *chip, unsigned offset) 751 - { 752 - pinctrl_free_gpio(chip->base + offset); 753 - } 754 - 755 745 static int st_gpio_get(struct gpio_chip *chip, unsigned offset) 756 746 { 757 747 struct st_gpio_bank *bank = gpio_chip_to_bank(chip); ··· 1480 1490 } 1481 1491 1482 1492 static struct gpio_chip st_gpio_template = { 1483 - .request = st_gpio_request, 1484 - .free = st_gpio_free, 1493 + .request = gpiochip_generic_request, 1494 + .free = gpiochip_generic_free, 1485 1495 .get = st_gpio_get, 1486 1496 .set = st_gpio_set, 1487 1497 .direction_input = st_gpio_direction_input,
+2 -16
drivers/pinctrl/pinctrl-xway.c
··· 682 682 return 0; 683 683 } 684 684 685 - static int xway_gpio_req(struct gpio_chip *chip, unsigned offset) 686 - { 687 - int gpio = chip->base + offset; 688 - 689 - return pinctrl_request_gpio(gpio); 690 - } 691 - 692 - static void xway_gpio_free(struct gpio_chip *chip, unsigned offset) 693 - { 694 - int gpio = chip->base + offset; 695 - 696 - pinctrl_free_gpio(gpio); 697 - } 698 - 699 685 static struct gpio_chip xway_chip = { 700 686 .label = "gpio-xway", 701 687 .direction_input = xway_gpio_dir_in, 702 688 .direction_output = xway_gpio_dir_out, 703 689 .get = xway_gpio_get, 704 690 .set = xway_gpio_set, 705 - .request = xway_gpio_req, 706 - .free = xway_gpio_free, 691 + .request = gpiochip_generic_request, 692 + .free = gpiochip_generic_free, 707 693 .base = -1, 708 694 }; 709 695
+2 -14
drivers/pinctrl/qcom/pinctrl-msm.c
··· 458 458 spin_unlock_irqrestore(&pctrl->lock, flags); 459 459 } 460 460 461 - static int msm_gpio_request(struct gpio_chip *chip, unsigned offset) 462 - { 463 - int gpio = chip->base + offset; 464 - return pinctrl_request_gpio(gpio); 465 - } 466 - 467 - static void msm_gpio_free(struct gpio_chip *chip, unsigned offset) 468 - { 469 - int gpio = chip->base + offset; 470 - return pinctrl_free_gpio(gpio); 471 - } 472 - 473 461 #ifdef CONFIG_DEBUG_FS 474 462 #include <linux/seq_file.h> 475 463 ··· 515 527 .direction_output = msm_gpio_direction_output, 516 528 .get = msm_gpio_get, 517 529 .set = msm_gpio_set, 518 - .request = msm_gpio_request, 519 - .free = msm_gpio_free, 530 + .request = gpiochip_generic_request, 531 + .free = gpiochip_generic_free, 520 532 .dbg_show = msm_gpio_dbg_show, 521 533 }; 522 534
+2 -12
drivers/pinctrl/qcom/pinctrl-spmi-gpio.c
··· 546 546 pmic_gpio_config_set(state->ctrl, pin, &config, 1); 547 547 } 548 548 549 - static int pmic_gpio_request(struct gpio_chip *chip, unsigned base) 550 - { 551 - return pinctrl_request_gpio(chip->base + base); 552 - } 553 - 554 - static void pmic_gpio_free(struct gpio_chip *chip, unsigned base) 555 - { 556 - pinctrl_free_gpio(chip->base + base); 557 - } 558 - 559 549 static int pmic_gpio_of_xlate(struct gpio_chip *chip, 560 550 const struct of_phandle_args *gpio_desc, 561 551 u32 *flags) ··· 585 595 .direction_output = pmic_gpio_direction_output, 586 596 .get = pmic_gpio_get, 587 597 .set = pmic_gpio_set, 588 - .request = pmic_gpio_request, 589 - .free = pmic_gpio_free, 598 + .request = gpiochip_generic_request, 599 + .free = gpiochip_generic_free, 590 600 .of_xlate = pmic_gpio_of_xlate, 591 601 .to_irq = pmic_gpio_to_irq, 592 602 .dbg_show = pmic_gpio_dbg_show,
+2 -12
drivers/pinctrl/qcom/pinctrl-spmi-mpp.c
··· 604 604 pmic_mpp_config_set(state->ctrl, pin, &config, 1); 605 605 } 606 606 607 - static int pmic_mpp_request(struct gpio_chip *chip, unsigned base) 608 - { 609 - return pinctrl_request_gpio(chip->base + base); 610 - } 611 - 612 - static void pmic_mpp_free(struct gpio_chip *chip, unsigned base) 613 - { 614 - pinctrl_free_gpio(chip->base + base); 615 - } 616 - 617 607 static int pmic_mpp_of_xlate(struct gpio_chip *chip, 618 608 const struct of_phandle_args *gpio_desc, 619 609 u32 *flags) ··· 643 653 .direction_output = pmic_mpp_direction_output, 644 654 .get = pmic_mpp_get, 645 655 .set = pmic_mpp_set, 646 - .request = pmic_mpp_request, 647 - .free = pmic_mpp_free, 656 + .request = gpiochip_generic_request, 657 + .free = gpiochip_generic_free, 648 658 .of_xlate = pmic_mpp_of_xlate, 649 659 .to_irq = pmic_mpp_to_irq, 650 660 .dbg_show = pmic_mpp_dbg_show,
+2 -12
drivers/pinctrl/samsung/pinctrl-samsung.c
··· 888 888 return 0; 889 889 } 890 890 891 - static int samsung_gpio_request(struct gpio_chip *chip, unsigned offset) 892 - { 893 - return pinctrl_request_gpio(chip->base + offset); 894 - } 895 - 896 - static void samsung_gpio_free(struct gpio_chip *chip, unsigned offset) 897 - { 898 - pinctrl_free_gpio(chip->base + offset); 899 - } 900 - 901 891 static const struct gpio_chip samsung_gpiolib_chip = { 902 - .request = samsung_gpio_request, 903 - .free = samsung_gpio_free, 892 + .request = gpiochip_generic_request, 893 + .free = gpiochip_generic_free, 904 894 .set = samsung_gpio_set, 905 895 .get = samsung_gpio_get, 906 896 .direction_input = samsung_gpio_direction_input,
+2 -12
drivers/pinctrl/sunxi/pinctrl-sunxi.c
··· 446 446 .gpio_set_direction = sunxi_pmx_gpio_set_direction, 447 447 }; 448 448 449 - static int sunxi_pinctrl_gpio_request(struct gpio_chip *chip, unsigned offset) 450 - { 451 - return pinctrl_request_gpio(chip->base + offset); 452 - } 453 - 454 - static void sunxi_pinctrl_gpio_free(struct gpio_chip *chip, unsigned offset) 455 - { 456 - pinctrl_free_gpio(chip->base + offset); 457 - } 458 - 459 449 static int sunxi_pinctrl_gpio_direction_input(struct gpio_chip *chip, 460 450 unsigned offset) 461 451 { ··· 946 956 947 957 last_pin = pctl->desc->pins[pctl->desc->npins - 1].pin.number; 948 958 pctl->chip->owner = THIS_MODULE; 949 - pctl->chip->request = sunxi_pinctrl_gpio_request, 950 - pctl->chip->free = sunxi_pinctrl_gpio_free, 959 + pctl->chip->request = gpiochip_generic_request, 960 + pctl->chip->free = gpiochip_generic_free, 951 961 pctl->chip->direction_input = sunxi_pinctrl_gpio_direction_input, 952 962 pctl->chip->direction_output = sunxi_pinctrl_gpio_direction_output, 953 963 pctl->chip->get = sunxi_pinctrl_gpio_get,
+2 -12
drivers/pinctrl/vt8500/pinctrl-wmt.c
··· 486 486 .confops = &wmt_pinconf_ops, 487 487 }; 488 488 489 - static int wmt_gpio_request(struct gpio_chip *chip, unsigned offset) 490 - { 491 - return pinctrl_request_gpio(chip->base + offset); 492 - } 493 - 494 - static void wmt_gpio_free(struct gpio_chip *chip, unsigned offset) 495 - { 496 - pinctrl_free_gpio(chip->base + offset); 497 - } 498 - 499 489 static int wmt_gpio_get_direction(struct gpio_chip *chip, unsigned offset) 500 490 { 501 491 struct wmt_pinctrl_data *data = dev_get_drvdata(chip->dev); ··· 550 560 static struct gpio_chip wmt_gpio_chip = { 551 561 .label = "gpio-wmt", 552 562 .owner = THIS_MODULE, 553 - .request = wmt_gpio_request, 554 - .free = wmt_gpio_free, 563 + .request = gpiochip_generic_request, 564 + .free = gpiochip_generic_free, 555 565 .get_direction = wmt_gpio_get_direction, 556 566 .direction_input = wmt_gpio_direction_input, 557 567 .direction_output = wmt_gpio_direction_output,
+12
include/dt-bindings/gpio/gpio.h
··· 9 9 #ifndef _DT_BINDINGS_GPIO_GPIO_H 10 10 #define _DT_BINDINGS_GPIO_GPIO_H 11 11 12 + /* Bit 0 express polarity */ 12 13 #define GPIO_ACTIVE_HIGH 0 13 14 #define GPIO_ACTIVE_LOW 1 15 + 16 + /* Bit 1 express single-endedness */ 17 + #define GPIO_PUSH_PULL 0 18 + #define GPIO_SINGLE_ENDED 2 19 + 20 + /* 21 + * Open Drain/Collector is the combination of single-ended active low, 22 + * Open Source/Emitter is the combination of single-ended active high. 23 + */ 24 + #define GPIO_OPEN_DRAIN (GPIO_SINGLE_ENDED | GPIO_ACTIVE_LOW) 25 + #define GPIO_OPEN_SOURCE (GPIO_SINGLE_ENDED | GPIO_ACTIVE_HIGH) 14 26 15 27 #endif
+1
include/linux/gpio/consumer.h
··· 400 400 { 401 401 return ERR_PTR(-EINVAL); 402 402 } 403 + 403 404 static inline int desc_to_gpio(const struct gpio_desc *desc) 404 405 { 405 406 /* GPIO can never have been requested */
+3
include/linux/gpio/driver.h
··· 206 206 207 207 #endif /* CONFIG_GPIOLIB_IRQCHIP */ 208 208 209 + int gpiochip_generic_request(struct gpio_chip *chip, unsigned offset); 210 + void gpiochip_generic_free(struct gpio_chip *chip, unsigned offset); 211 + 209 212 #ifdef CONFIG_PINCTRL 210 213 211 214 /**
+1
include/linux/of_gpio.h
··· 29 29 */ 30 30 enum of_gpio_flags { 31 31 OF_GPIO_ACTIVE_LOW = 0x1, 32 + OF_GPIO_SINGLE_ENDED = 0x2, 32 33 }; 33 34 34 35 #ifdef CONFIG_OF_GPIO