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

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

Pull GPIO updates from Linus Walleij:
"This is the bulk of GPIO changes for the v4.12 kernel cycle.

Core changes:

- Return NULL from gpiod_get_optional() when GPIOLIB is disabled.
This was a much discussed change. It affects use cases where people
write drivers that might or might not be using GPIO resources. I
have decided that this is the lesser evil right now.

- Make gpiod_count() behave consistently across different hardware
descriptions.

- Fix the syntax around open drain/open source to not infer active
high/low semantics.

New drivers:

- A new single-register fixed-direction framework driver for hardware
that have lines controlled by a single register that just work in
one direction (out or in), including IRQ support.

- Support the Fintek F71889A GPIO SuperIO controller.

- Support the National NI 169445 MMIO GPIO.

- Support for the X-Gene derivative of the DWC GPIO controller

- Support for the Rohm BD9571MWV-M PMIC GPIO controller.

- Refactor the Gemini GPIO driver to a generic Faraday FTGPIO driver
and replace both the Gemini and the Moxa ART custom drivers with
this driver.

Driver improvements:

- A whole slew of drivers have their spinlocks chaned to raw
spinlocks as they provide irqchips, and thus we are progressing on
realtime compliance.

- Use devm_irq_alloc_descs() in a slew of drivers, getting managed
resources.

- Support for the embedded PWM controller inside the MVEBU driver.

- Debounce, open source and open drain support for the Aspeed driver.

- Misc smaller fixes like spelling and syntax and whatnot"

* tag 'gpio-v4.12-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio: (77 commits)
gpio: f7188x: Add a missing break
gpio: omap: return error if requested debounce time is not possible
gpio: Add ROHM BD9571MWV-M PMIC GPIO driver
gpio: gpio-wcove: fix GPIO IRQ status mask
gpio: DT bindings, move tca9554 from pcf857x to pca953x
gpio: move tca9554 from pcf857x to pca953x
gpio: arizona: Correct check whether the pin is an input
gpio: Add XRA1403 DTS binding documentation
dt-bindings: add exar to vendor prefixes list
gpio: gpio-wcove: fix irq pending status bit width
gpio: dwapb: use dwapb_read instead of readl_relaxed
gpio: aspeed: Add open-source and open-drain support
gpio: aspeed: Add debounce support
gpio: aspeed: dt: Add optional clocks property
gpio: aspeed: dt: Fix description alignment in bindings document
gpio: mvebu: Add limited PWM support
gpio: Use unsigned int for interrupt numbers
gpio: f7188x: Add F71889A GPIO support.
gpio: core: Decouple open drain/source flag with active low/high
gpio: arizona: Correct handling for reading input GPIOs
...

+1863 -651
+6 -3
Documentation/devicetree/bindings/gpio/cortina,gemini-gpio.txt Documentation/devicetree/bindings/gpio/faraday,ftgpio010.txt
··· 1 - Cortina Systems Gemini GPIO Controller 1 + Faraday Technology FTGPIO010 GPIO Controller 2 2 3 3 Required properties: 4 4 5 - - compatible : Must be "cortina,gemini-gpio" 5 + - compatible : Should be one of 6 + "cortina,gemini-gpio", "faraday,ftgpio010" 7 + "moxa,moxart-gpio", "faraday,ftgpio010" 8 + "faraday,ftgpio010" 6 9 - reg : Should contain registers location and length 7 10 - interrupts : Should contain the interrupt line for the GPIO block 8 11 - gpio-controller : marks this as a GPIO controller ··· 17 14 Example: 18 15 19 16 gpio@4d000000 { 20 - compatible = "cortina,gemini-gpio"; 17 + compatible = "cortina,gemini-gpio", "faraday,ftgpio010"; 21 18 reg = <0x4d000000 0x100>; 22 19 interrupts = <22 IRQ_TYPE_LEVEL_HIGH>; 23 20 gpio-controller;
+2 -1
Documentation/devicetree/bindings/gpio/gpio-aspeed.txt
··· 17 17 18 18 Optional properties: 19 19 20 - - interrupt-parent : The parent interrupt controller, optional if inherited 20 + - interrupt-parent : The parent interrupt controller, optional if inherited 21 + - clocks : A phandle to the HPLL clock node for debounce timings 21 22 22 23 The gpio and interrupt properties are further described in their respective 23 24 bindings documentation:
+32
Documentation/devicetree/bindings/gpio/gpio-mvebu.txt
··· 38 38 - #gpio-cells: Should be two. The first cell is the pin number. The 39 39 second cell is reserved for flags, unused at the moment. 40 40 41 + Optional properties: 42 + 43 + In order to use the GPIO lines in PWM mode, some additional optional 44 + properties are required. Only Armada 370 and XP support these properties. 45 + 46 + - compatible: Must contain "marvell,armada-370-xp-gpio" 47 + 48 + - reg: an additional register set is needed, for the GPIO Blink 49 + Counter on/off registers. 50 + 51 + - reg-names: Must contain an entry "pwm" corresponding to the 52 + additional register range needed for PWM operation. 53 + 54 + - #pwm-cells: Should be two. The first cell is the GPIO line number. The 55 + second cell is the period in nanoseconds. 56 + 57 + - clocks: Must be a phandle to the clock for the GPIO controller. 58 + 41 59 Example: 42 60 43 61 gpio0: gpio@d0018100 { ··· 68 50 interrupt-controller; 69 51 #interrupt-cells = <2>; 70 52 interrupts = <16>, <17>, <18>, <19>; 53 + }; 54 + 55 + gpio1: gpio@18140 { 56 + compatible = "marvell,armada-370-xp-gpio"; 57 + reg = <0x18140 0x40>, <0x181c8 0x08>; 58 + reg-names = "gpio", "pwm"; 59 + ngpios = <17>; 60 + gpio-controller; 61 + #gpio-cells = <2>; 62 + #pwm-cells = <2>; 63 + interrupt-controller; 64 + #interrupt-cells = <2>; 65 + interrupts = <87>, <88>, <89>; 66 + clocks = <&coreclk 0>; 71 67 };
+1
Documentation/devicetree/bindings/gpio/gpio-pca953x.txt
··· 26 26 ti,tca6416 27 27 ti,tca6424 28 28 ti,tca9539 29 + ti,tca9554 29 30 onsemi,pca9654 30 31 exar,xra1202 31 32
-1
Documentation/devicetree/bindings/gpio/gpio-pcf857x.txt
··· 25 25 - "nxp,pcf8574": For the NXP PCF8574 26 26 - "nxp,pcf8574a": For the NXP PCF8574A 27 27 - "nxp,pcf8575": For the NXP PCF8575 28 - - "ti,tca9554": For the TI TCA9554 29 28 30 29 - reg: I2C slave address. 31 30
+27
Documentation/devicetree/bindings/gpio/gpio-thunderx.txt
··· 1 + Cavium ThunderX/OCTEON-TX GPIO controller bindings 2 + 3 + Required Properties: 4 + - reg: The controller bus address. 5 + - gpio-controller: Marks the device node as a GPIO controller. 6 + - #gpio-cells: Must be 2. 7 + - First cell is the GPIO pin number relative to the controller. 8 + - Second cell is a standard generic flag bitfield as described in gpio.txt. 9 + 10 + Optional Properties: 11 + - compatible: "cavium,thunder-8890-gpio", unused as PCI driver binding is used. 12 + - interrupt-controller: Marks the device node as an interrupt controller. 13 + - #interrupt-cells: Must be present and have value of 2 if 14 + "interrupt-controller" is present. 15 + - First cell is the GPIO pin number relative to the controller. 16 + - Second cell is triggering flags as defined in interrupts.txt. 17 + 18 + Example: 19 + 20 + gpio_6_0: gpio@6,0 { 21 + compatible = "cavium,thunder-8890-gpio"; 22 + reg = <0x3000 0 0 0 0>; /* DEVFN = 0x30 (6:0) */ 23 + gpio-controller; 24 + #gpio-cells = <2>; 25 + interrupt-controller; 26 + #interrupt-cells = <2>; 27 + };
+46
Documentation/devicetree/bindings/gpio/gpio-xra1403.txt
··· 1 + GPIO Driver for XRA1403 16-BIT GPIO Expander With Reset Input from EXAR 2 + 3 + The XRA1403 is an 16-bit GPIO expander with an SPI interface. Features available: 4 + - Individually programmable inputs: 5 + - Internal pull-up resistors 6 + - Polarity inversion 7 + - Individual interrupt enable 8 + - Rising edge and/or Falling edge interrupt 9 + - Input filter 10 + - Individually programmable outputs 11 + - Output Level Control 12 + - Output Three-State Control 13 + 14 + Properties 15 + ---------- 16 + Check documentation for SPI and GPIO controllers regarding properties needed to configure the node. 17 + 18 + - compatible = "exar,xra1403". 19 + - reg - SPI id of the device. 20 + - gpio-controller - marks the node as gpio. 21 + - #gpio-cells - should be two where the first cell is the pin number 22 + and the second one is used for optional parameters. 23 + 24 + Optional properties: 25 + ------------------- 26 + - reset-gpios: in case available used to control the device reset line. 27 + - interrupt-controller - marks the node as interrupt controller. 28 + - #interrupt-cells - should be two and represents the number of cells 29 + needed to encode interrupt source. 30 + 31 + Example 32 + -------- 33 + 34 + gpioxra0: gpio@2 { 35 + compatible = "exar,xra1403"; 36 + reg = <2>; 37 + 38 + gpio-controller; 39 + #gpio-cells = <2>; 40 + 41 + interrupt-controller; 42 + #interrupt-cells = <2>; 43 + 44 + reset-gpios = <&gpio3 6 GPIO_ACTIVE_LOW>; 45 + spi-max-frequency = <1000000>; 46 + };
-19
Documentation/devicetree/bindings/gpio/moxa,moxart-gpio.txt
··· 1 - MOXA ART GPIO Controller 2 - 3 - Required properties: 4 - 5 - - #gpio-cells : Should be 2, The first cell is the pin number, 6 - the second cell is used to specify polarity: 7 - 0 = active high 8 - 1 = active low 9 - - compatible : Must be "moxa,moxart-gpio" 10 - - reg : Should contain registers location and length 11 - 12 - Example: 13 - 14 - gpio: gpio@98700000 { 15 - gpio-controller; 16 - #gpio-cells = <2>; 17 - compatible = "moxa,moxart-gpio"; 18 - reg = <0x98700000 0xC>; 19 - };
+38
Documentation/devicetree/bindings/gpio/ni,169445-nand-gpio.txt
··· 1 + Bindings for the National Instruments 169445 GPIO NAND controller 2 + 3 + The 169445 GPIO NAND controller has two memory mapped GPIO registers, one 4 + for input (the ready signal) and one for output (control signals). It is 5 + intended to be used with the GPIO NAND driver. 6 + 7 + Required properties: 8 + - compatible: should be "ni,169445-nand-gpio" 9 + - reg-names: must contain 10 + "dat" - data register 11 + - reg: address + size pairs describing the GPIO register sets; 12 + order must correspond with the order of entries in reg-names 13 + - #gpio-cells: must be set to 2. The first cell is the pin number and 14 + the second cell is used to specify the gpio polarity: 15 + 0 = active high 16 + 1 = active low 17 + - gpio-controller: Marks the device node as a gpio controller. 18 + 19 + Optional properties: 20 + - no-output: disables driving output on the pins 21 + 22 + Examples: 23 + gpio1: nand-gpio-out@1f300010 { 24 + compatible = "ni,169445-nand-gpio"; 25 + reg = <0x1f300010 0x4>; 26 + reg-names = "dat"; 27 + gpio-controller; 28 + #gpio-cells = <2>; 29 + }; 30 + 31 + gpio2: nand-gpio-in@1f300014 { 32 + compatible = "ni,169445-nand-gpio"; 33 + reg = <0x1f300014 0x4>; 34 + reg-names = "dat"; 35 + gpio-controller; 36 + #gpio-cells = <2>; 37 + no-output; 38 + };
+1
Documentation/devicetree/bindings/vendor-prefixes.txt
··· 103 103 eukrea Eukréa Electromatique 104 104 everest Everest Semiconductor Co. Ltd. 105 105 everspin Everspin Technologies, Inc. 106 + exar Exar Corporation 106 107 excito Excito 107 108 ezchip EZchip Semiconductor 108 109 faraday Faraday Technology Corporation
+6
Documentation/gpio/consumer.txt
··· 70 70 unsigned int index, 71 71 enum gpiod_flags flags) 72 72 73 + Note that gpio_get*_optional() functions (and their managed variants), unlike 74 + the rest of gpiolib API, also return NULL when gpiolib support is disabled. 75 + This is helpful to driver authors, since they do not need to special case 76 + -ENOSYS return codes. System integrators should however be careful to enable 77 + gpiolib on systems that need it. 78 + 73 79 For a function using multiple GPIOs all of those can be obtained with one call: 74 80 75 81 struct gpio_descs *gpiod_get_array(struct device *dev,
+2
MAINTAINERS
··· 10315 10315 F: drivers/pwm/ 10316 10316 F: drivers/video/backlight/pwm_bl.c 10317 10317 F: include/linux/pwm_backlight.h 10318 + F: drivers/gpio/gpio-mvebu.c 10319 + F: Documentation/devicetree/bindings/gpio/gpio-mvebu.txt 10318 10320 10319 10321 PXA2xx/PXA3xx SUPPORT 10320 10322 M: Daniel Mack <daniel@zonque.org>
+28 -18
drivers/gpio/Kconfig
··· 204 204 and write pin state) for GPIO implemented in a number of GE single 205 205 board computers. 206 206 207 - config GPIO_GEMINI 208 - bool "Gemini GPIO" 209 - depends on ARCH_GEMINI 207 + config GPIO_FTGPIO010 208 + bool "Faraday FTGPIO010 GPIO" 210 209 depends on OF_GPIO 211 210 select GPIO_GENERIC 212 211 select GPIOLIB_IRQCHIP 212 + default (ARCH_GEMINI || ARCH_MOXART) 213 213 help 214 - Support for common GPIOs found in Cortina systems Gemini platforms. 214 + Support for common GPIOs from the Faraday FTGPIO010 IP core, found in 215 + Cortina systems Gemini platforms, Moxa ART and others. 215 216 216 217 config GPIO_GENERIC_PLATFORM 217 218 tristate "Generic memory-mapped GPIO controller support (MMIO platform device)" ··· 309 308 tools/testing/selftests/gpio/gpio-mockup.sh. Reference the usage in 310 309 it. 311 310 312 - config GPIO_MOXART 313 - bool "MOXART GPIO support" 314 - depends on ARCH_MOXART || COMPILE_TEST 315 - select GPIO_GENERIC 316 - help 317 - Select this option to enable GPIO driver for 318 - MOXA ART SoC devices. 319 - 320 311 config GPIO_MPC5200 321 312 def_bool y 322 313 depends on PPC_MPC52xx ··· 379 386 select GPIOLIB_IRQCHIP 380 387 help 381 388 Say yes here to support GPIO on Renesas R-Car SoCs. 389 + 390 + config GPIO_REG 391 + bool 392 + help 393 + A 32-bit single register GPIO fixed in/out implementation. This 394 + can be used to represent any register as a set of GPIO signals. 382 395 383 396 config GPIO_SPEAR_SPICS 384 397 bool "ST SPEAr13xx SPI Chip Select as GPIO support" ··· 504 505 505 506 config GPIO_XLP 506 507 tristate "Netlogic XLP GPIO support" 507 - depends on OF_GPIO && (CPU_XLP || ARCH_VULCAN || COMPILE_TEST) 508 + depends on OF_GPIO && (CPU_XLP || ARCH_VULCAN || ARCH_THUNDER2 || COMPILE_TEST) 508 509 select GPIOLIB_IRQCHIP 509 510 help 510 511 This driver provides support for GPIO interface on Netlogic XLP MIPS64 ··· 556 557 557 558 config GPIO_104_DIO_48E 558 559 tristate "ACCES 104-DIO-48E GPIO support" 559 - depends on ISA_BUS_API 560 + depends on PC104 && ISA_BUS_API 560 561 select GPIOLIB_IRQCHIP 561 562 help 562 563 Enables GPIO support for the ACCES 104-DIO-48E series (104-DIO-48E, ··· 566 567 567 568 config GPIO_104_IDIO_16 568 569 tristate "ACCES 104-IDIO-16 GPIO support" 569 - depends on ISA_BUS_API 570 + depends on PC104 && ISA_BUS_API 570 571 select GPIOLIB_IRQCHIP 571 572 help 572 573 Enables GPIO support for the ACCES 104-IDIO-16 family (104-IDIO-16, ··· 577 578 578 579 config GPIO_104_IDI_48 579 580 tristate "ACCES 104-IDI-48 GPIO support" 580 - depends on ISA_BUS_API 581 + depends on PC104 && ISA_BUS_API 581 582 select GPIOLIB_IRQCHIP 582 583 help 583 584 Enables GPIO support for the ACCES 104-IDI-48 family (104-IDI-48A, ··· 597 598 598 599 config GPIO_GPIO_MM 599 600 tristate "Diamond Systems GPIO-MM GPIO support" 600 - depends on ISA_BUS_API 601 + depends on PC104 && ISA_BUS_API 601 602 help 602 603 Enables GPIO support for the Diamond Systems GPIO-MM and GPIO-MM-12. 603 604 ··· 752 753 4 bits: pca9536, pca9537 753 754 754 755 8 bits: max7310, max7315, pca6107, pca9534, pca9538, pca9554, 755 - pca9556, pca9557, pca9574, tca6408, xra1202 756 + pca9556, pca9557, pca9574, tca6408, tca9554, xra1202 756 757 757 758 16 bits: max7312, max7313, pca9535, pca9539, pca9555, pca9575, 758 759 tca6416 ··· 843 844 depends on MFD_ARIZONA 844 845 help 845 846 Support for GPIOs on Wolfson Arizona class devices. 847 + 848 + config GPIO_BD9571MWV 849 + tristate "ROHM BD9571 GPIO support" 850 + depends on MFD_BD9571MWV 851 + help 852 + Support for GPIOs on ROHM BD9571 PMIC. There are two GPIOs 853 + available on the ROHM PMIC in total, both of which can also 854 + generate interrupts. 855 + 856 + This driver can also be built as a module. If so, the module 857 + will be called gpio-bd9571mwv. 846 858 847 859 config GPIO_CRYSTAL_COVE 848 860 tristate "GPIO support for Crystal Cove PMIC"
+3 -2
drivers/gpio/Makefile
··· 33 33 obj-$(CONFIG_GPIO_ASPEED) += gpio-aspeed.o 34 34 obj-$(CONFIG_GPIO_AXP209) += gpio-axp209.o 35 35 obj-$(CONFIG_GPIO_BCM_KONA) += gpio-bcm-kona.o 36 + obj-$(CONFIG_GPIO_BD9571MWV) += gpio-bd9571mwv.o 36 37 obj-$(CONFIG_GPIO_BRCMSTB) += gpio-brcmstb.o 37 38 obj-$(CONFIG_GPIO_BT8XX) += gpio-bt8xx.o 38 39 obj-$(CONFIG_GPIO_CLPS711X) += gpio-clps711x.o ··· 49 48 obj-$(CONFIG_GPIO_ETRAXFS) += gpio-etraxfs.o 50 49 obj-$(CONFIG_GPIO_EXAR) += gpio-exar.o 51 50 obj-$(CONFIG_GPIO_F7188X) += gpio-f7188x.o 51 + obj-$(CONFIG_GPIO_FTGPIO010) += gpio-ftgpio010.o 52 52 obj-$(CONFIG_GPIO_GE_FPGA) += gpio-ge.o 53 - obj-$(CONFIG_GPIO_GEMINI) += gpio-gemini.o 54 53 obj-$(CONFIG_GPIO_GPIO_MM) += gpio-gpio-mm.o 55 54 obj-$(CONFIG_GPIO_GRGPIO) += gpio-grgpio.o 56 55 obj-$(CONFIG_HTC_EGPIO) += gpio-htc-egpio.o ··· 81 80 obj-$(CONFIG_GPIO_ML_IOH) += gpio-ml-ioh.o 82 81 obj-$(CONFIG_GPIO_MM_LANTIQ) += gpio-mm-lantiq.o 83 82 obj-$(CONFIG_GPIO_MOCKUP) += gpio-mockup.o 84 - obj-$(CONFIG_GPIO_MOXART) += gpio-moxart.o 85 83 obj-$(CONFIG_GPIO_MPC5200) += gpio-mpc5200.o 86 84 obj-$(CONFIG_GPIO_MPC8XXX) += gpio-mpc8xxx.o 87 85 obj-$(CONFIG_GPIO_MSIC) += gpio-msic.o ··· 99 99 obj-$(CONFIG_GPIO_RC5T583) += gpio-rc5t583.o 100 100 obj-$(CONFIG_GPIO_RDC321X) += gpio-rdc321x.o 101 101 obj-$(CONFIG_GPIO_RCAR) += gpio-rcar.o 102 + obj-$(CONFIG_GPIO_REG) += gpio-reg.o 102 103 obj-$(CONFIG_ARCH_SA1100) += gpio-sa1100.o 103 104 obj-$(CONFIG_GPIO_SCH) += gpio-sch.o 104 105 obj-$(CONFIG_GPIO_SCH311X) += gpio-sch311x.o
+1 -1
drivers/gpio/devres.c
··· 136 136 * GPIO descriptors returned from this function are automatically disposed on 137 137 * driver detach. 138 138 * 139 - * On successfull request the GPIO pin is configured in accordance with 139 + * On successful request the GPIO pin is configured in accordance with 140 140 * provided @flags. 141 141 */ 142 142 struct gpio_desc *devm_fwnode_get_index_gpiod_from_child(struct device *dev,
+19 -19
drivers/gpio/gpio-104-dio-48e.c
··· 55 55 unsigned char io_state[6]; 56 56 unsigned char out_state[6]; 57 57 unsigned char control[2]; 58 - spinlock_t lock; 58 + raw_spinlock_t lock; 59 59 unsigned base; 60 60 unsigned char irq_mask; 61 61 }; ··· 78 78 unsigned long flags; 79 79 unsigned control; 80 80 81 - spin_lock_irqsave(&dio48egpio->lock, flags); 81 + raw_spin_lock_irqsave(&dio48egpio->lock, flags); 82 82 83 83 /* Check if configuring Port C */ 84 84 if (io_port == 2 || io_port == 5) { ··· 103 103 control &= ~BIT(7); 104 104 outb(control, control_addr); 105 105 106 - spin_unlock_irqrestore(&dio48egpio->lock, flags); 106 + raw_spin_unlock_irqrestore(&dio48egpio->lock, flags); 107 107 108 108 return 0; 109 109 } ··· 120 120 unsigned long flags; 121 121 unsigned control; 122 122 123 - spin_lock_irqsave(&dio48egpio->lock, flags); 123 + raw_spin_lock_irqsave(&dio48egpio->lock, flags); 124 124 125 125 /* Check if configuring Port C */ 126 126 if (io_port == 2 || io_port == 5) { ··· 153 153 control &= ~BIT(7); 154 154 outb(control, control_addr); 155 155 156 - spin_unlock_irqrestore(&dio48egpio->lock, flags); 156 + raw_spin_unlock_irqrestore(&dio48egpio->lock, flags); 157 157 158 158 return 0; 159 159 } ··· 167 167 unsigned long flags; 168 168 unsigned port_state; 169 169 170 - spin_lock_irqsave(&dio48egpio->lock, flags); 170 + raw_spin_lock_irqsave(&dio48egpio->lock, flags); 171 171 172 172 /* ensure that GPIO is set for input */ 173 173 if (!(dio48egpio->io_state[port] & mask)) { 174 - spin_unlock_irqrestore(&dio48egpio->lock, flags); 174 + raw_spin_unlock_irqrestore(&dio48egpio->lock, flags); 175 175 return -EINVAL; 176 176 } 177 177 178 178 port_state = inb(dio48egpio->base + in_port); 179 179 180 - spin_unlock_irqrestore(&dio48egpio->lock, flags); 180 + raw_spin_unlock_irqrestore(&dio48egpio->lock, flags); 181 181 182 182 return !!(port_state & mask); 183 183 } ··· 190 190 const unsigned out_port = (port > 2) ? port + 1 : port; 191 191 unsigned long flags; 192 192 193 - spin_lock_irqsave(&dio48egpio->lock, flags); 193 + raw_spin_lock_irqsave(&dio48egpio->lock, flags); 194 194 195 195 if (value) 196 196 dio48egpio->out_state[port] |= mask; ··· 199 199 200 200 outb(dio48egpio->out_state[port], dio48egpio->base + out_port); 201 201 202 - spin_unlock_irqrestore(&dio48egpio->lock, flags); 202 + raw_spin_unlock_irqrestore(&dio48egpio->lock, flags); 203 203 } 204 204 205 205 static void dio48e_gpio_set_multiple(struct gpio_chip *chip, ··· 225 225 out_port = (port > 2) ? port + 1 : port; 226 226 bitmask = mask[BIT_WORD(i)] & bits[BIT_WORD(i)]; 227 227 228 - spin_lock_irqsave(&dio48egpio->lock, flags); 228 + raw_spin_lock_irqsave(&dio48egpio->lock, flags); 229 229 230 230 /* update output state data and set device gpio register */ 231 231 dio48egpio->out_state[port] &= ~mask[BIT_WORD(i)]; 232 232 dio48egpio->out_state[port] |= bitmask; 233 233 outb(dio48egpio->out_state[port], dio48egpio->base + out_port); 234 234 235 - spin_unlock_irqrestore(&dio48egpio->lock, flags); 235 + raw_spin_unlock_irqrestore(&dio48egpio->lock, flags); 236 236 237 237 /* prepare for next gpio register set */ 238 238 mask[BIT_WORD(i)] >>= gpio_reg_size; ··· 255 255 if (offset != 19 && offset != 43) 256 256 return; 257 257 258 - spin_lock_irqsave(&dio48egpio->lock, flags); 258 + raw_spin_lock_irqsave(&dio48egpio->lock, flags); 259 259 260 260 if (offset == 19) 261 261 dio48egpio->irq_mask &= ~BIT(0); ··· 266 266 /* disable interrupts */ 267 267 inb(dio48egpio->base + 0xB); 268 268 269 - spin_unlock_irqrestore(&dio48egpio->lock, flags); 269 + raw_spin_unlock_irqrestore(&dio48egpio->lock, flags); 270 270 } 271 271 272 272 static void dio48e_irq_unmask(struct irq_data *data) ··· 280 280 if (offset != 19 && offset != 43) 281 281 return; 282 282 283 - spin_lock_irqsave(&dio48egpio->lock, flags); 283 + raw_spin_lock_irqsave(&dio48egpio->lock, flags); 284 284 285 285 if (!dio48egpio->irq_mask) { 286 286 /* enable interrupts */ ··· 293 293 else 294 294 dio48egpio->irq_mask |= BIT(1); 295 295 296 - spin_unlock_irqrestore(&dio48egpio->lock, flags); 296 + raw_spin_unlock_irqrestore(&dio48egpio->lock, flags); 297 297 } 298 298 299 299 static int dio48e_irq_set_type(struct irq_data *data, unsigned flow_type) ··· 329 329 generic_handle_irq(irq_find_mapping(chip->irqdomain, 330 330 19 + gpio*24)); 331 331 332 - spin_lock(&dio48egpio->lock); 332 + raw_spin_lock(&dio48egpio->lock); 333 333 334 334 outb(0x00, dio48egpio->base + 0xF); 335 335 336 - spin_unlock(&dio48egpio->lock); 336 + raw_spin_unlock(&dio48egpio->lock); 337 337 338 338 return IRQ_HANDLED; 339 339 } ··· 388 388 dio48egpio->chip.set_multiple = dio48e_gpio_set_multiple; 389 389 dio48egpio->base = base[id]; 390 390 391 - spin_lock_init(&dio48egpio->lock); 391 + raw_spin_lock_init(&dio48egpio->lock); 392 392 393 393 err = devm_gpiochip_add_data(dev, &dio48egpio->chip, dio48egpio); 394 394 if (err) {
+10 -8
drivers/gpio/gpio-104-idi-48.c
··· 51 51 */ 52 52 struct idi_48_gpio { 53 53 struct gpio_chip chip; 54 - spinlock_t lock; 54 + raw_spinlock_t lock; 55 55 spinlock_t ack_lock; 56 56 unsigned char irq_mask[6]; 57 57 unsigned base; ··· 112 112 if (!idi48gpio->irq_mask[boundary]) { 113 113 idi48gpio->cos_enb &= ~BIT(boundary); 114 114 115 - spin_lock_irqsave(&idi48gpio->lock, flags); 115 + raw_spin_lock_irqsave(&idi48gpio->lock, flags); 116 116 117 117 outb(idi48gpio->cos_enb, idi48gpio->base + 7); 118 118 119 - spin_unlock_irqrestore(&idi48gpio->lock, flags); 119 + raw_spin_unlock_irqrestore(&idi48gpio->lock, 120 + flags); 120 121 } 121 122 122 123 return; ··· 146 145 if (!prev_irq_mask) { 147 146 idi48gpio->cos_enb |= BIT(boundary); 148 147 149 - spin_lock_irqsave(&idi48gpio->lock, flags); 148 + raw_spin_lock_irqsave(&idi48gpio->lock, flags); 150 149 151 150 outb(idi48gpio->cos_enb, idi48gpio->base + 7); 152 151 153 - spin_unlock_irqrestore(&idi48gpio->lock, flags); 152 + raw_spin_unlock_irqrestore(&idi48gpio->lock, 153 + flags); 154 154 } 155 155 156 156 return; ··· 188 186 189 187 spin_lock(&idi48gpio->ack_lock); 190 188 191 - spin_lock(&idi48gpio->lock); 189 + raw_spin_lock(&idi48gpio->lock); 192 190 193 191 cos_status = inb(idi48gpio->base + 7); 194 192 195 - spin_unlock(&idi48gpio->lock); 193 + raw_spin_unlock(&idi48gpio->lock); 196 194 197 195 /* IRQ Status (bit 6) is active low (0 = IRQ generated by device) */ 198 196 if (cos_status & BIT(6)) { ··· 258 256 idi48gpio->chip.get = idi_48_gpio_get; 259 257 idi48gpio->base = base[id]; 260 258 261 - spin_lock_init(&idi48gpio->lock); 259 + raw_spin_lock_init(&idi48gpio->lock); 262 260 spin_lock_init(&idi48gpio->ack_lock); 263 261 264 262 err = devm_gpiochip_add_data(dev, &idi48gpio->chip, idi48gpio);
+12 -12
drivers/gpio/gpio-104-idio-16.c
··· 50 50 */ 51 51 struct idio_16_gpio { 52 52 struct gpio_chip chip; 53 - spinlock_t lock; 53 + raw_spinlock_t lock; 54 54 unsigned long irq_mask; 55 55 unsigned base; 56 56 unsigned out_state; ··· 99 99 if (offset > 15) 100 100 return; 101 101 102 - spin_lock_irqsave(&idio16gpio->lock, flags); 102 + raw_spin_lock_irqsave(&idio16gpio->lock, flags); 103 103 104 104 if (value) 105 105 idio16gpio->out_state |= mask; ··· 111 111 else 112 112 outb(idio16gpio->out_state, idio16gpio->base); 113 113 114 - spin_unlock_irqrestore(&idio16gpio->lock, flags); 114 + raw_spin_unlock_irqrestore(&idio16gpio->lock, flags); 115 115 } 116 116 117 117 static void idio_16_gpio_set_multiple(struct gpio_chip *chip, ··· 120 120 struct idio_16_gpio *const idio16gpio = gpiochip_get_data(chip); 121 121 unsigned long flags; 122 122 123 - spin_lock_irqsave(&idio16gpio->lock, flags); 123 + raw_spin_lock_irqsave(&idio16gpio->lock, flags); 124 124 125 125 idio16gpio->out_state &= ~*mask; 126 126 idio16gpio->out_state |= *mask & *bits; ··· 130 130 if ((*mask >> 8) & 0xFF) 131 131 outb(idio16gpio->out_state >> 8, idio16gpio->base + 4); 132 132 133 - spin_unlock_irqrestore(&idio16gpio->lock, flags); 133 + raw_spin_unlock_irqrestore(&idio16gpio->lock, flags); 134 134 } 135 135 136 136 static void idio_16_irq_ack(struct irq_data *data) ··· 147 147 idio16gpio->irq_mask &= ~mask; 148 148 149 149 if (!idio16gpio->irq_mask) { 150 - spin_lock_irqsave(&idio16gpio->lock, flags); 150 + raw_spin_lock_irqsave(&idio16gpio->lock, flags); 151 151 152 152 outb(0, idio16gpio->base + 2); 153 153 154 - spin_unlock_irqrestore(&idio16gpio->lock, flags); 154 + raw_spin_unlock_irqrestore(&idio16gpio->lock, flags); 155 155 } 156 156 } 157 157 ··· 166 166 idio16gpio->irq_mask |= mask; 167 167 168 168 if (!prev_irq_mask) { 169 - spin_lock_irqsave(&idio16gpio->lock, flags); 169 + raw_spin_lock_irqsave(&idio16gpio->lock, flags); 170 170 171 171 inb(idio16gpio->base + 2); 172 172 173 - spin_unlock_irqrestore(&idio16gpio->lock, flags); 173 + raw_spin_unlock_irqrestore(&idio16gpio->lock, flags); 174 174 } 175 175 } 176 176 ··· 201 201 for_each_set_bit(gpio, &idio16gpio->irq_mask, chip->ngpio) 202 202 generic_handle_irq(irq_find_mapping(chip->irqdomain, gpio)); 203 203 204 - spin_lock(&idio16gpio->lock); 204 + raw_spin_lock(&idio16gpio->lock); 205 205 206 206 outb(0, idio16gpio->base + 1); 207 207 208 - spin_unlock(&idio16gpio->lock); 208 + raw_spin_unlock(&idio16gpio->lock); 209 209 210 210 return IRQ_HANDLED; 211 211 } ··· 249 249 idio16gpio->base = base[id]; 250 250 idio16gpio->out_state = 0xFFFF; 251 251 252 - spin_lock_init(&idio16gpio->lock); 252 + raw_spin_lock_init(&idio16gpio->lock); 253 253 254 254 err = devm_gpiochip_add_data(dev, &idio16gpio->chip, idio16gpio); 255 255 if (err) {
+12 -12
drivers/gpio/gpio-altera.c
··· 38 38 */ 39 39 struct altera_gpio_chip { 40 40 struct of_mm_gpio_chip mmchip; 41 - spinlock_t gpio_lock; 41 + raw_spinlock_t gpio_lock; 42 42 int interrupt_trigger; 43 43 int mapped_irq; 44 44 }; ··· 53 53 altera_gc = gpiochip_get_data(irq_data_get_irq_chip_data(d)); 54 54 mm_gc = &altera_gc->mmchip; 55 55 56 - spin_lock_irqsave(&altera_gc->gpio_lock, flags); 56 + raw_spin_lock_irqsave(&altera_gc->gpio_lock, flags); 57 57 intmask = readl(mm_gc->regs + ALTERA_GPIO_IRQ_MASK); 58 58 /* Set ALTERA_GPIO_IRQ_MASK bit to unmask */ 59 59 intmask |= BIT(irqd_to_hwirq(d)); 60 60 writel(intmask, mm_gc->regs + ALTERA_GPIO_IRQ_MASK); 61 - spin_unlock_irqrestore(&altera_gc->gpio_lock, flags); 61 + raw_spin_unlock_irqrestore(&altera_gc->gpio_lock, flags); 62 62 } 63 63 64 64 static void altera_gpio_irq_mask(struct irq_data *d) ··· 71 71 altera_gc = gpiochip_get_data(irq_data_get_irq_chip_data(d)); 72 72 mm_gc = &altera_gc->mmchip; 73 73 74 - spin_lock_irqsave(&altera_gc->gpio_lock, flags); 74 + raw_spin_lock_irqsave(&altera_gc->gpio_lock, flags); 75 75 intmask = readl(mm_gc->regs + ALTERA_GPIO_IRQ_MASK); 76 76 /* Clear ALTERA_GPIO_IRQ_MASK bit to mask */ 77 77 intmask &= ~BIT(irqd_to_hwirq(d)); 78 78 writel(intmask, mm_gc->regs + ALTERA_GPIO_IRQ_MASK); 79 - spin_unlock_irqrestore(&altera_gc->gpio_lock, flags); 79 + raw_spin_unlock_irqrestore(&altera_gc->gpio_lock, flags); 80 80 } 81 81 82 82 /** ··· 140 140 mm_gc = to_of_mm_gpio_chip(gc); 141 141 chip = gpiochip_get_data(gc); 142 142 143 - spin_lock_irqsave(&chip->gpio_lock, flags); 143 + raw_spin_lock_irqsave(&chip->gpio_lock, flags); 144 144 data_reg = readl(mm_gc->regs + ALTERA_GPIO_DATA); 145 145 if (value) 146 146 data_reg |= BIT(offset); 147 147 else 148 148 data_reg &= ~BIT(offset); 149 149 writel(data_reg, mm_gc->regs + ALTERA_GPIO_DATA); 150 - spin_unlock_irqrestore(&chip->gpio_lock, flags); 150 + raw_spin_unlock_irqrestore(&chip->gpio_lock, flags); 151 151 } 152 152 153 153 static int altera_gpio_direction_input(struct gpio_chip *gc, unsigned offset) ··· 160 160 mm_gc = to_of_mm_gpio_chip(gc); 161 161 chip = gpiochip_get_data(gc); 162 162 163 - spin_lock_irqsave(&chip->gpio_lock, flags); 163 + raw_spin_lock_irqsave(&chip->gpio_lock, flags); 164 164 /* Set pin as input, assumes software controlled IP */ 165 165 gpio_ddr = readl(mm_gc->regs + ALTERA_GPIO_DIR); 166 166 gpio_ddr &= ~BIT(offset); 167 167 writel(gpio_ddr, mm_gc->regs + ALTERA_GPIO_DIR); 168 - spin_unlock_irqrestore(&chip->gpio_lock, flags); 168 + raw_spin_unlock_irqrestore(&chip->gpio_lock, flags); 169 169 170 170 return 0; 171 171 } ··· 181 181 mm_gc = to_of_mm_gpio_chip(gc); 182 182 chip = gpiochip_get_data(gc); 183 183 184 - spin_lock_irqsave(&chip->gpio_lock, flags); 184 + raw_spin_lock_irqsave(&chip->gpio_lock, flags); 185 185 /* Sets the GPIO value */ 186 186 data_reg = readl(mm_gc->regs + ALTERA_GPIO_DATA); 187 187 if (value) ··· 194 194 gpio_ddr = readl(mm_gc->regs + ALTERA_GPIO_DIR); 195 195 gpio_ddr |= BIT(offset); 196 196 writel(gpio_ddr, mm_gc->regs + ALTERA_GPIO_DIR); 197 - spin_unlock_irqrestore(&chip->gpio_lock, flags); 197 + raw_spin_unlock_irqrestore(&chip->gpio_lock, flags); 198 198 199 199 return 0; 200 200 } ··· 262 262 if (!altera_gc) 263 263 return -ENOMEM; 264 264 265 - spin_lock_init(&altera_gc->gpio_lock); 265 + raw_spin_lock_init(&altera_gc->gpio_lock); 266 266 267 267 if (of_property_read_u32(node, "altr,ngpio", &reg)) 268 268 /* By default assume maximum ngpio */
+28 -2
drivers/gpio/gpio-arizona.c
··· 17 17 #include <linux/module.h> 18 18 #include <linux/gpio.h> 19 19 #include <linux/platform_device.h> 20 + #include <linux/pm_runtime.h> 20 21 #include <linux/seq_file.h> 21 22 22 23 #include <linux/mfd/arizona/core.h> ··· 42 41 { 43 42 struct arizona_gpio *arizona_gpio = gpiochip_get_data(chip); 44 43 struct arizona *arizona = arizona_gpio->arizona; 45 - unsigned int val; 44 + unsigned int reg, val; 46 45 int ret; 47 46 48 - ret = regmap_read(arizona->regmap, ARIZONA_GPIO1_CTRL + offset, &val); 47 + reg = ARIZONA_GPIO1_CTRL + offset; 48 + ret = regmap_read(arizona->regmap, reg, &val); 49 49 if (ret < 0) 50 50 return ret; 51 + 52 + /* Resume to read actual registers for input pins */ 53 + if (val & ARIZONA_GPN_DIR) { 54 + ret = pm_runtime_get_sync(chip->parent); 55 + if (ret < 0) { 56 + dev_err(chip->parent, "Failed to resume: %d\n", ret); 57 + return ret; 58 + } 59 + 60 + /* Register is cached, drop it to ensure a physical read */ 61 + ret = regcache_drop_region(arizona->regmap, reg, reg); 62 + if (ret < 0) { 63 + dev_err(chip->parent, "Failed to drop cache: %d\n", 64 + ret); 65 + return ret; 66 + } 67 + 68 + ret = regmap_read(arizona->regmap, reg, &val); 69 + if (ret < 0) 70 + return ret; 71 + 72 + pm_runtime_mark_last_busy(chip->parent); 73 + pm_runtime_put_autosuspend(chip->parent); 74 + } 51 75 52 76 if (val & ARIZONA_GPN_LVL) 53 77 return 1;
+280 -5
drivers/gpio/gpio-aspeed.c
··· 9 9 * 2 of the License, or (at your option) any later version. 10 10 */ 11 11 12 - #include <linux/module.h> 13 - #include <linux/kernel.h> 12 + #include <asm/div64.h> 13 + #include <linux/clk.h> 14 + #include <linux/gpio/driver.h> 15 + #include <linux/hashtable.h> 14 16 #include <linux/init.h> 15 17 #include <linux/io.h> 16 - #include <linux/spinlock.h> 17 - #include <linux/platform_device.h> 18 - #include <linux/gpio/driver.h> 18 + #include <linux/kernel.h> 19 + #include <linux/module.h> 19 20 #include <linux/pinctrl/consumer.h> 21 + #include <linux/platform_device.h> 22 + #include <linux/spinlock.h> 23 + #include <linux/string.h> 20 24 21 25 struct aspeed_bank_props { 22 26 unsigned int bank; ··· 33 29 const struct aspeed_bank_props *props; 34 30 }; 35 31 32 + /* 33 + * @offset_timer: Maps an offset to an @timer_users index, or zero if disabled 34 + * @timer_users: Tracks the number of users for each timer 35 + * 36 + * The @timer_users has four elements but the first element is unused. This is 37 + * to simplify accounting and indexing, as a zero value in @offset_timer 38 + * represents disabled debouncing for the GPIO. Any other value for an element 39 + * of @offset_timer is used as an index into @timer_users. This behaviour of 40 + * the zero value aligns with the behaviour of zero built from the timer 41 + * configuration registers (i.e. debouncing is disabled). 42 + */ 36 43 struct aspeed_gpio { 37 44 struct gpio_chip chip; 38 45 spinlock_t lock; 39 46 void __iomem *base; 40 47 int irq; 41 48 const struct aspeed_gpio_config *config; 49 + 50 + u8 *offset_timer; 51 + unsigned int timer_users[4]; 52 + struct clk *clk; 42 53 }; 43 54 44 55 struct aspeed_gpio_bank { 45 56 uint16_t val_regs; 46 57 uint16_t irq_regs; 58 + uint16_t debounce_regs; 47 59 const char names[4][3]; 48 60 }; 61 + 62 + static const int debounce_timers[4] = { 0x00, 0x50, 0x54, 0x58 }; 49 63 50 64 static const struct aspeed_gpio_bank aspeed_gpio_banks[] = { 51 65 { 52 66 .val_regs = 0x0000, 53 67 .irq_regs = 0x0008, 68 + .debounce_regs = 0x0040, 54 69 .names = { "A", "B", "C", "D" }, 55 70 }, 56 71 { 57 72 .val_regs = 0x0020, 58 73 .irq_regs = 0x0028, 74 + .debounce_regs = 0x0048, 59 75 .names = { "E", "F", "G", "H" }, 60 76 }, 61 77 { 62 78 .val_regs = 0x0070, 63 79 .irq_regs = 0x0098, 80 + .debounce_regs = 0x00b0, 64 81 .names = { "I", "J", "K", "L" }, 65 82 }, 66 83 { 67 84 .val_regs = 0x0078, 68 85 .irq_regs = 0x00e8, 86 + .debounce_regs = 0x0100, 69 87 .names = { "M", "N", "O", "P" }, 70 88 }, 71 89 { 72 90 .val_regs = 0x0080, 73 91 .irq_regs = 0x0118, 92 + .debounce_regs = 0x0130, 74 93 .names = { "Q", "R", "S", "T" }, 75 94 }, 76 95 { 77 96 .val_regs = 0x0088, 78 97 .irq_regs = 0x0148, 98 + .debounce_regs = 0x0160, 79 99 .names = { "U", "V", "W", "X" }, 80 100 }, 81 101 { 82 102 .val_regs = 0x01E0, 83 103 .irq_regs = 0x0178, 104 + .debounce_regs = 0x0190, 84 105 .names = { "Y", "Z", "AA", "AB" }, 85 106 }, 86 107 { 87 108 .val_regs = 0x01E8, 88 109 .irq_regs = 0x01A8, 110 + .debounce_regs = 0x01c0, 89 111 .names = { "AC", "", "", "" }, 90 112 }, 91 113 }; ··· 128 98 #define GPIO_IRQ_TYPE1 0x08 129 99 #define GPIO_IRQ_TYPE2 0x0c 130 100 #define GPIO_IRQ_STATUS 0x10 101 + 102 + #define GPIO_DEBOUNCE_SEL1 0x00 103 + #define GPIO_DEBOUNCE_SEL2 0x04 104 + 105 + #define _GPIO_SET_DEBOUNCE(t, o, i) ((!!((t) & BIT(i))) << GPIO_OFFSET(o)) 106 + #define GPIO_SET_DEBOUNCE1(t, o) _GPIO_SET_DEBOUNCE(t, o, 1) 107 + #define GPIO_SET_DEBOUNCE2(t, o) _GPIO_SET_DEBOUNCE(t, o, 0) 131 108 132 109 static const struct aspeed_gpio_bank *to_bank(unsigned int offset) 133 110 { ··· 181 144 } 182 145 183 146 #define have_irq(g, o) have_input((g), (o)) 147 + #define have_debounce(g, o) have_input((g), (o)) 184 148 185 149 static inline bool have_output(struct aspeed_gpio *gpio, unsigned int offset) 186 150 { ··· 544 506 pinctrl_free_gpio(chip->base + offset); 545 507 } 546 508 509 + static inline void __iomem *bank_debounce_reg(struct aspeed_gpio *gpio, 510 + const struct aspeed_gpio_bank *bank, 511 + unsigned int reg) 512 + { 513 + return gpio->base + bank->debounce_regs + reg; 514 + } 515 + 516 + static int usecs_to_cycles(struct aspeed_gpio *gpio, unsigned long usecs, 517 + u32 *cycles) 518 + { 519 + u64 rate; 520 + u64 n; 521 + u32 r; 522 + 523 + rate = clk_get_rate(gpio->clk); 524 + if (!rate) 525 + return -ENOTSUPP; 526 + 527 + n = rate * usecs; 528 + r = do_div(n, 1000000); 529 + 530 + if (n >= U32_MAX) 531 + return -ERANGE; 532 + 533 + /* At least as long as the requested time */ 534 + *cycles = n + (!!r); 535 + 536 + return 0; 537 + } 538 + 539 + /* Call under gpio->lock */ 540 + static int register_allocated_timer(struct aspeed_gpio *gpio, 541 + unsigned int offset, unsigned int timer) 542 + { 543 + if (WARN(gpio->offset_timer[offset] != 0, 544 + "Offset %d already allocated timer %d\n", 545 + offset, gpio->offset_timer[offset])) 546 + return -EINVAL; 547 + 548 + if (WARN(gpio->timer_users[timer] == UINT_MAX, 549 + "Timer user count would overflow\n")) 550 + return -EPERM; 551 + 552 + gpio->offset_timer[offset] = timer; 553 + gpio->timer_users[timer]++; 554 + 555 + return 0; 556 + } 557 + 558 + /* Call under gpio->lock */ 559 + static int unregister_allocated_timer(struct aspeed_gpio *gpio, 560 + unsigned int offset) 561 + { 562 + if (WARN(gpio->offset_timer[offset] == 0, 563 + "No timer allocated to offset %d\n", offset)) 564 + return -EINVAL; 565 + 566 + if (WARN(gpio->timer_users[gpio->offset_timer[offset]] == 0, 567 + "No users recorded for timer %d\n", 568 + gpio->offset_timer[offset])) 569 + return -EINVAL; 570 + 571 + gpio->timer_users[gpio->offset_timer[offset]]--; 572 + gpio->offset_timer[offset] = 0; 573 + 574 + return 0; 575 + } 576 + 577 + /* Call under gpio->lock */ 578 + static inline bool timer_allocation_registered(struct aspeed_gpio *gpio, 579 + unsigned int offset) 580 + { 581 + return gpio->offset_timer[offset] > 0; 582 + } 583 + 584 + /* Call under gpio->lock */ 585 + static void configure_timer(struct aspeed_gpio *gpio, unsigned int offset, 586 + unsigned int timer) 587 + { 588 + const struct aspeed_gpio_bank *bank = to_bank(offset); 589 + const u32 mask = GPIO_BIT(offset); 590 + void __iomem *addr; 591 + u32 val; 592 + 593 + addr = bank_debounce_reg(gpio, bank, GPIO_DEBOUNCE_SEL1); 594 + val = ioread32(addr); 595 + iowrite32((val & ~mask) | GPIO_SET_DEBOUNCE1(timer, offset), addr); 596 + 597 + addr = bank_debounce_reg(gpio, bank, GPIO_DEBOUNCE_SEL2); 598 + val = ioread32(addr); 599 + iowrite32((val & ~mask) | GPIO_SET_DEBOUNCE2(timer, offset), addr); 600 + } 601 + 602 + static int enable_debounce(struct gpio_chip *chip, unsigned int offset, 603 + unsigned long usecs) 604 + { 605 + struct aspeed_gpio *gpio = gpiochip_get_data(chip); 606 + u32 requested_cycles; 607 + unsigned long flags; 608 + int rc; 609 + int i; 610 + 611 + rc = usecs_to_cycles(gpio, usecs, &requested_cycles); 612 + if (rc < 0) { 613 + dev_warn(chip->parent, "Failed to convert %luus to cycles at %luHz: %d\n", 614 + usecs, clk_get_rate(gpio->clk), rc); 615 + return rc; 616 + } 617 + 618 + spin_lock_irqsave(&gpio->lock, flags); 619 + 620 + if (timer_allocation_registered(gpio, offset)) { 621 + rc = unregister_allocated_timer(gpio, offset); 622 + if (rc < 0) 623 + goto out; 624 + } 625 + 626 + /* Try to find a timer already configured for the debounce period */ 627 + for (i = 1; i < ARRAY_SIZE(debounce_timers); i++) { 628 + u32 cycles; 629 + 630 + cycles = ioread32(gpio->base + debounce_timers[i]); 631 + if (requested_cycles == cycles) 632 + break; 633 + } 634 + 635 + if (i == ARRAY_SIZE(debounce_timers)) { 636 + int j; 637 + 638 + /* 639 + * As there are no timers configured for the requested debounce 640 + * period, find an unused timer instead 641 + */ 642 + for (j = 1; j < ARRAY_SIZE(gpio->timer_users); j++) { 643 + if (gpio->timer_users[j] == 0) 644 + break; 645 + } 646 + 647 + if (j == ARRAY_SIZE(gpio->timer_users)) { 648 + dev_warn(chip->parent, 649 + "Debounce timers exhausted, cannot debounce for period %luus\n", 650 + usecs); 651 + 652 + rc = -EPERM; 653 + 654 + /* 655 + * We already adjusted the accounting to remove @offset 656 + * as a user of its previous timer, so also configure 657 + * the hardware so @offset has timers disabled for 658 + * consistency. 659 + */ 660 + configure_timer(gpio, offset, 0); 661 + goto out; 662 + } 663 + 664 + i = j; 665 + 666 + iowrite32(requested_cycles, gpio->base + debounce_timers[i]); 667 + } 668 + 669 + if (WARN(i == 0, "Cannot register index of disabled timer\n")) { 670 + rc = -EINVAL; 671 + goto out; 672 + } 673 + 674 + register_allocated_timer(gpio, offset, i); 675 + configure_timer(gpio, offset, i); 676 + 677 + out: 678 + spin_unlock_irqrestore(&gpio->lock, flags); 679 + 680 + return rc; 681 + } 682 + 683 + static int disable_debounce(struct gpio_chip *chip, unsigned int offset) 684 + { 685 + struct aspeed_gpio *gpio = gpiochip_get_data(chip); 686 + unsigned long flags; 687 + int rc; 688 + 689 + spin_lock_irqsave(&gpio->lock, flags); 690 + 691 + rc = unregister_allocated_timer(gpio, offset); 692 + if (!rc) 693 + configure_timer(gpio, offset, 0); 694 + 695 + spin_unlock_irqrestore(&gpio->lock, flags); 696 + 697 + return rc; 698 + } 699 + 700 + static int set_debounce(struct gpio_chip *chip, unsigned int offset, 701 + unsigned long usecs) 702 + { 703 + struct aspeed_gpio *gpio = gpiochip_get_data(chip); 704 + 705 + if (!have_debounce(gpio, offset)) 706 + return -ENOTSUPP; 707 + 708 + if (usecs) 709 + return enable_debounce(chip, offset, usecs); 710 + 711 + return disable_debounce(chip, offset); 712 + } 713 + 714 + static int aspeed_gpio_set_config(struct gpio_chip *chip, unsigned int offset, 715 + unsigned long config) 716 + { 717 + unsigned long param = pinconf_to_config_param(config); 718 + u32 arg = pinconf_to_config_argument(config); 719 + 720 + if (param == PIN_CONFIG_INPUT_DEBOUNCE) 721 + return set_debounce(chip, offset, arg); 722 + else if (param == PIN_CONFIG_BIAS_DISABLE || 723 + param == PIN_CONFIG_BIAS_PULL_DOWN || 724 + param == PIN_CONFIG_DRIVE_STRENGTH) 725 + return pinctrl_gpio_set_config(offset, config); 726 + else if (param == PIN_CONFIG_DRIVE_OPEN_DRAIN || 727 + param == PIN_CONFIG_DRIVE_OPEN_SOURCE) 728 + /* Return -ENOTSUPP to trigger emulation, as per datasheet */ 729 + return -ENOTSUPP; 730 + 731 + return -ENOTSUPP; 732 + } 733 + 547 734 /* 548 735 * Any banks not specified in a struct aspeed_bank_props array are assumed to 549 736 * have the properties: ··· 828 565 if (!gpio_id) 829 566 return -EINVAL; 830 567 568 + gpio->clk = of_clk_get(pdev->dev.of_node, 0); 569 + if (IS_ERR(gpio->clk)) { 570 + dev_warn(&pdev->dev, 571 + "No HPLL clock phandle provided, debouncing disabled\n"); 572 + gpio->clk = NULL; 573 + } 574 + 831 575 gpio->config = gpio_id->data; 832 576 577 + gpio->chip.parent = &pdev->dev; 833 578 gpio->chip.ngpio = gpio->config->nr_gpios; 834 579 gpio->chip.parent = &pdev->dev; 835 580 gpio->chip.direction_input = aspeed_gpio_dir_in; ··· 847 576 gpio->chip.free = aspeed_gpio_free; 848 577 gpio->chip.get = aspeed_gpio_get; 849 578 gpio->chip.set = aspeed_gpio_set; 579 + gpio->chip.set_config = aspeed_gpio_set_config; 850 580 gpio->chip.label = dev_name(&pdev->dev); 851 581 gpio->chip.base = -1; 852 582 gpio->chip.irq_need_valid_mask = true; ··· 855 583 rc = devm_gpiochip_add_data(&pdev->dev, &gpio->chip, gpio); 856 584 if (rc < 0) 857 585 return rc; 586 + 587 + gpio->offset_timer = 588 + devm_kzalloc(&pdev->dev, gpio->chip.ngpio, GFP_KERNEL); 858 589 859 590 return aspeed_gpio_setup_irqs(gpio, pdev); 860 591 }
+14 -14
drivers/gpio/gpio-ath79.c
··· 32 32 struct ath79_gpio_ctrl { 33 33 struct gpio_chip gc; 34 34 void __iomem *base; 35 - spinlock_t lock; 35 + raw_spinlock_t lock; 36 36 unsigned long both_edges; 37 37 }; 38 38 ··· 74 74 u32 mask = BIT(irqd_to_hwirq(data)); 75 75 unsigned long flags; 76 76 77 - spin_lock_irqsave(&ctrl->lock, flags); 77 + raw_spin_lock_irqsave(&ctrl->lock, flags); 78 78 ath79_gpio_update_bits(ctrl, AR71XX_GPIO_REG_INT_MASK, mask, mask); 79 - spin_unlock_irqrestore(&ctrl->lock, flags); 79 + raw_spin_unlock_irqrestore(&ctrl->lock, flags); 80 80 } 81 81 82 82 static void ath79_gpio_irq_mask(struct irq_data *data) ··· 85 85 u32 mask = BIT(irqd_to_hwirq(data)); 86 86 unsigned long flags; 87 87 88 - spin_lock_irqsave(&ctrl->lock, flags); 88 + raw_spin_lock_irqsave(&ctrl->lock, flags); 89 89 ath79_gpio_update_bits(ctrl, AR71XX_GPIO_REG_INT_MASK, mask, 0); 90 - spin_unlock_irqrestore(&ctrl->lock, flags); 90 + raw_spin_unlock_irqrestore(&ctrl->lock, flags); 91 91 } 92 92 93 93 static void ath79_gpio_irq_enable(struct irq_data *data) ··· 96 96 u32 mask = BIT(irqd_to_hwirq(data)); 97 97 unsigned long flags; 98 98 99 - spin_lock_irqsave(&ctrl->lock, flags); 99 + raw_spin_lock_irqsave(&ctrl->lock, flags); 100 100 ath79_gpio_update_bits(ctrl, AR71XX_GPIO_REG_INT_ENABLE, mask, mask); 101 101 ath79_gpio_update_bits(ctrl, AR71XX_GPIO_REG_INT_MASK, mask, mask); 102 - spin_unlock_irqrestore(&ctrl->lock, flags); 102 + raw_spin_unlock_irqrestore(&ctrl->lock, flags); 103 103 } 104 104 105 105 static void ath79_gpio_irq_disable(struct irq_data *data) ··· 108 108 u32 mask = BIT(irqd_to_hwirq(data)); 109 109 unsigned long flags; 110 110 111 - spin_lock_irqsave(&ctrl->lock, flags); 111 + raw_spin_lock_irqsave(&ctrl->lock, flags); 112 112 ath79_gpio_update_bits(ctrl, AR71XX_GPIO_REG_INT_MASK, mask, 0); 113 113 ath79_gpio_update_bits(ctrl, AR71XX_GPIO_REG_INT_ENABLE, mask, 0); 114 - spin_unlock_irqrestore(&ctrl->lock, flags); 114 + raw_spin_unlock_irqrestore(&ctrl->lock, flags); 115 115 } 116 116 117 117 static int ath79_gpio_irq_set_type(struct irq_data *data, ··· 140 140 return -EINVAL; 141 141 } 142 142 143 - spin_lock_irqsave(&ctrl->lock, flags); 143 + raw_spin_lock_irqsave(&ctrl->lock, flags); 144 144 145 145 if (flow_type == IRQ_TYPE_EDGE_BOTH) { 146 146 ctrl->both_edges |= mask; ··· 165 165 ath79_gpio_update_bits( 166 166 ctrl, AR71XX_GPIO_REG_INT_ENABLE, mask, mask); 167 167 168 - spin_unlock_irqrestore(&ctrl->lock, flags); 168 + raw_spin_unlock_irqrestore(&ctrl->lock, flags); 169 169 170 170 return 0; 171 171 } ··· 191 191 192 192 chained_irq_enter(irqchip, desc); 193 193 194 - spin_lock_irqsave(&ctrl->lock, flags); 194 + raw_spin_lock_irqsave(&ctrl->lock, flags); 195 195 196 196 pending = ath79_gpio_read(ctrl, AR71XX_GPIO_REG_INT_PENDING); 197 197 ··· 203 203 both_edges, ~state); 204 204 } 205 205 206 - spin_unlock_irqrestore(&ctrl->lock, flags); 206 + raw_spin_unlock_irqrestore(&ctrl->lock, flags); 207 207 208 208 if (pending) { 209 209 for_each_set_bit(irq, &pending, gc->ngpio) ··· 262 262 if (!ctrl->base) 263 263 return -ENOMEM; 264 264 265 - spin_lock_init(&ctrl->lock); 265 + raw_spin_lock_init(&ctrl->lock); 266 266 err = bgpio_init(&ctrl->gc, &pdev->dev, 4, 267 267 ctrl->base + AR71XX_GPIO_REG_IN, 268 268 ctrl->base + AR71XX_GPIO_REG_SET,
+24 -24
drivers/gpio/gpio-bcm-kona.c
··· 67 67 struct bcm_kona_gpio { 68 68 void __iomem *reg_base; 69 69 int num_bank; 70 - spinlock_t lock; 70 + raw_spinlock_t lock; 71 71 struct gpio_chip gpio_chip; 72 72 struct irq_domain *irq_domain; 73 73 struct bcm_kona_gpio_bank *banks; ··· 95 95 unsigned long flags; 96 96 int bank_id = GPIO_BANK(gpio); 97 97 98 - spin_lock_irqsave(&kona_gpio->lock, flags); 98 + raw_spin_lock_irqsave(&kona_gpio->lock, flags); 99 99 100 100 val = readl(kona_gpio->reg_base + GPIO_PWD_STATUS(bank_id)); 101 101 val |= BIT(gpio); 102 102 bcm_kona_gpio_write_lock_regs(kona_gpio->reg_base, bank_id, val); 103 103 104 - spin_unlock_irqrestore(&kona_gpio->lock, flags); 104 + raw_spin_unlock_irqrestore(&kona_gpio->lock, flags); 105 105 } 106 106 107 107 static void bcm_kona_gpio_unlock_gpio(struct bcm_kona_gpio *kona_gpio, ··· 111 111 unsigned long flags; 112 112 int bank_id = GPIO_BANK(gpio); 113 113 114 - spin_lock_irqsave(&kona_gpio->lock, flags); 114 + raw_spin_lock_irqsave(&kona_gpio->lock, flags); 115 115 116 116 val = readl(kona_gpio->reg_base + GPIO_PWD_STATUS(bank_id)); 117 117 val &= ~BIT(gpio); 118 118 bcm_kona_gpio_write_lock_regs(kona_gpio->reg_base, bank_id, val); 119 119 120 - spin_unlock_irqrestore(&kona_gpio->lock, flags); 120 + raw_spin_unlock_irqrestore(&kona_gpio->lock, flags); 121 121 } 122 122 123 123 static int bcm_kona_gpio_get_dir(struct gpio_chip *chip, unsigned gpio) ··· 141 141 142 142 kona_gpio = gpiochip_get_data(chip); 143 143 reg_base = kona_gpio->reg_base; 144 - spin_lock_irqsave(&kona_gpio->lock, flags); 144 + raw_spin_lock_irqsave(&kona_gpio->lock, flags); 145 145 146 146 /* this function only applies to output pin */ 147 147 if (bcm_kona_gpio_get_dir(chip, gpio) == GPIOF_DIR_IN) ··· 154 154 writel(val, reg_base + reg_offset); 155 155 156 156 out: 157 - spin_unlock_irqrestore(&kona_gpio->lock, flags); 157 + raw_spin_unlock_irqrestore(&kona_gpio->lock, flags); 158 158 } 159 159 160 160 static int bcm_kona_gpio_get(struct gpio_chip *chip, unsigned gpio) ··· 168 168 169 169 kona_gpio = gpiochip_get_data(chip); 170 170 reg_base = kona_gpio->reg_base; 171 - spin_lock_irqsave(&kona_gpio->lock, flags); 171 + raw_spin_lock_irqsave(&kona_gpio->lock, flags); 172 172 173 173 if (bcm_kona_gpio_get_dir(chip, gpio) == GPIOF_DIR_IN) 174 174 reg_offset = GPIO_IN_STATUS(bank_id); ··· 178 178 /* read the GPIO bank status */ 179 179 val = readl(reg_base + reg_offset); 180 180 181 - spin_unlock_irqrestore(&kona_gpio->lock, flags); 181 + raw_spin_unlock_irqrestore(&kona_gpio->lock, flags); 182 182 183 183 /* return the specified bit status */ 184 184 return !!(val & BIT(bit)); ··· 208 208 209 209 kona_gpio = gpiochip_get_data(chip); 210 210 reg_base = kona_gpio->reg_base; 211 - spin_lock_irqsave(&kona_gpio->lock, flags); 211 + raw_spin_lock_irqsave(&kona_gpio->lock, flags); 212 212 213 213 val = readl(reg_base + GPIO_CONTROL(gpio)); 214 214 val &= ~GPIO_GPCTR0_IOTR_MASK; 215 215 val |= GPIO_GPCTR0_IOTR_CMD_INPUT; 216 216 writel(val, reg_base + GPIO_CONTROL(gpio)); 217 217 218 - spin_unlock_irqrestore(&kona_gpio->lock, flags); 218 + raw_spin_unlock_irqrestore(&kona_gpio->lock, flags); 219 219 220 220 return 0; 221 221 } ··· 232 232 233 233 kona_gpio = gpiochip_get_data(chip); 234 234 reg_base = kona_gpio->reg_base; 235 - spin_lock_irqsave(&kona_gpio->lock, flags); 235 + raw_spin_lock_irqsave(&kona_gpio->lock, flags); 236 236 237 237 val = readl(reg_base + GPIO_CONTROL(gpio)); 238 238 val &= ~GPIO_GPCTR0_IOTR_MASK; ··· 244 244 val |= BIT(bit); 245 245 writel(val, reg_base + reg_offset); 246 246 247 - spin_unlock_irqrestore(&kona_gpio->lock, flags); 247 + raw_spin_unlock_irqrestore(&kona_gpio->lock, flags); 248 248 249 249 return 0; 250 250 } ··· 288 288 } 289 289 290 290 /* spin lock for read-modify-write of the GPIO register */ 291 - spin_lock_irqsave(&kona_gpio->lock, flags); 291 + raw_spin_lock_irqsave(&kona_gpio->lock, flags); 292 292 293 293 val = readl(reg_base + GPIO_CONTROL(gpio)); 294 294 val &= ~GPIO_GPCTR0_DBR_MASK; ··· 303 303 304 304 writel(val, reg_base + GPIO_CONTROL(gpio)); 305 305 306 - spin_unlock_irqrestore(&kona_gpio->lock, flags); 306 + raw_spin_unlock_irqrestore(&kona_gpio->lock, flags); 307 307 308 308 return 0; 309 309 } ··· 347 347 348 348 kona_gpio = irq_data_get_irq_chip_data(d); 349 349 reg_base = kona_gpio->reg_base; 350 - spin_lock_irqsave(&kona_gpio->lock, flags); 350 + raw_spin_lock_irqsave(&kona_gpio->lock, flags); 351 351 352 352 val = readl(reg_base + GPIO_INT_STATUS(bank_id)); 353 353 val |= BIT(bit); 354 354 writel(val, reg_base + GPIO_INT_STATUS(bank_id)); 355 355 356 - spin_unlock_irqrestore(&kona_gpio->lock, flags); 356 + raw_spin_unlock_irqrestore(&kona_gpio->lock, flags); 357 357 } 358 358 359 359 static void bcm_kona_gpio_irq_mask(struct irq_data *d) ··· 368 368 369 369 kona_gpio = irq_data_get_irq_chip_data(d); 370 370 reg_base = kona_gpio->reg_base; 371 - spin_lock_irqsave(&kona_gpio->lock, flags); 371 + raw_spin_lock_irqsave(&kona_gpio->lock, flags); 372 372 373 373 val = readl(reg_base + GPIO_INT_MASK(bank_id)); 374 374 val |= BIT(bit); 375 375 writel(val, reg_base + GPIO_INT_MASK(bank_id)); 376 376 377 - spin_unlock_irqrestore(&kona_gpio->lock, flags); 377 + raw_spin_unlock_irqrestore(&kona_gpio->lock, flags); 378 378 } 379 379 380 380 static void bcm_kona_gpio_irq_unmask(struct irq_data *d) ··· 389 389 390 390 kona_gpio = irq_data_get_irq_chip_data(d); 391 391 reg_base = kona_gpio->reg_base; 392 - spin_lock_irqsave(&kona_gpio->lock, flags); 392 + raw_spin_lock_irqsave(&kona_gpio->lock, flags); 393 393 394 394 val = readl(reg_base + GPIO_INT_MSKCLR(bank_id)); 395 395 val |= BIT(bit); 396 396 writel(val, reg_base + GPIO_INT_MSKCLR(bank_id)); 397 397 398 - spin_unlock_irqrestore(&kona_gpio->lock, flags); 398 + raw_spin_unlock_irqrestore(&kona_gpio->lock, flags); 399 399 } 400 400 401 401 static int bcm_kona_gpio_irq_set_type(struct irq_data *d, unsigned int type) ··· 431 431 return -EINVAL; 432 432 } 433 433 434 - spin_lock_irqsave(&kona_gpio->lock, flags); 434 + raw_spin_lock_irqsave(&kona_gpio->lock, flags); 435 435 436 436 val = readl(reg_base + GPIO_CONTROL(gpio)); 437 437 val &= ~GPIO_GPCTR0_ITR_MASK; 438 438 val |= lvl_type << GPIO_GPCTR0_ITR_SHIFT; 439 439 writel(val, reg_base + GPIO_CONTROL(gpio)); 440 440 441 - spin_unlock_irqrestore(&kona_gpio->lock, flags); 441 + raw_spin_unlock_irqrestore(&kona_gpio->lock, flags); 442 442 443 443 return 0; 444 444 } ··· 655 655 bank); 656 656 } 657 657 658 - spin_lock_init(&kona_gpio->lock); 658 + raw_spin_lock_init(&kona_gpio->lock); 659 659 660 660 return 0; 661 661
+144
drivers/gpio/gpio-bd9571mwv.c
··· 1 + /* 2 + * ROHM BD9571MWV-M GPIO driver 3 + * 4 + * Copyright (C) 2017 Marek Vasut <marek.vasut+renesas@gmail.com> 5 + * 6 + * This program is free software; you can redistribute it and/or 7 + * modify it under the terms of the GNU General Public License version 2 as 8 + * published by the Free Software Foundation. 9 + * 10 + * This program is distributed "as is" WITHOUT ANY WARRANTY of any 11 + * kind, whether expressed or implied; without even the implied warranty 12 + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 + * GNU General Public License version 2 for more details. 14 + * 15 + * Based on the TPS65086 driver 16 + * 17 + * NOTE: Interrupts are not supported yet. 18 + */ 19 + 20 + #include <linux/gpio/driver.h> 21 + #include <linux/module.h> 22 + #include <linux/platform_device.h> 23 + 24 + #include <linux/mfd/bd9571mwv.h> 25 + 26 + struct bd9571mwv_gpio { 27 + struct gpio_chip chip; 28 + struct bd9571mwv *bd; 29 + }; 30 + 31 + static int bd9571mwv_gpio_get_direction(struct gpio_chip *chip, 32 + unsigned int offset) 33 + { 34 + struct bd9571mwv_gpio *gpio = gpiochip_get_data(chip); 35 + int ret, val; 36 + 37 + ret = regmap_read(gpio->bd->regmap, BD9571MWV_GPIO_DIR, &val); 38 + if (ret < 0) 39 + return ret; 40 + 41 + return val & BIT(offset); 42 + } 43 + 44 + static int bd9571mwv_gpio_direction_input(struct gpio_chip *chip, 45 + unsigned int offset) 46 + { 47 + struct bd9571mwv_gpio *gpio = gpiochip_get_data(chip); 48 + 49 + regmap_update_bits(gpio->bd->regmap, BD9571MWV_GPIO_DIR, 50 + BIT(offset), 0); 51 + 52 + return 0; 53 + } 54 + 55 + static int bd9571mwv_gpio_direction_output(struct gpio_chip *chip, 56 + unsigned int offset, int value) 57 + { 58 + struct bd9571mwv_gpio *gpio = gpiochip_get_data(chip); 59 + 60 + /* Set the initial value */ 61 + regmap_update_bits(gpio->bd->regmap, BD9571MWV_GPIO_OUT, 62 + BIT(offset), value ? BIT(offset) : 0); 63 + regmap_update_bits(gpio->bd->regmap, BD9571MWV_GPIO_DIR, 64 + BIT(offset), BIT(offset)); 65 + 66 + return 0; 67 + } 68 + 69 + static int bd9571mwv_gpio_get(struct gpio_chip *chip, unsigned int offset) 70 + { 71 + struct bd9571mwv_gpio *gpio = gpiochip_get_data(chip); 72 + int ret, val; 73 + 74 + ret = regmap_read(gpio->bd->regmap, BD9571MWV_GPIO_IN, &val); 75 + if (ret < 0) 76 + return ret; 77 + 78 + return val & BIT(offset); 79 + } 80 + 81 + static void bd9571mwv_gpio_set(struct gpio_chip *chip, unsigned int offset, 82 + int value) 83 + { 84 + struct bd9571mwv_gpio *gpio = gpiochip_get_data(chip); 85 + 86 + regmap_update_bits(gpio->bd->regmap, BD9571MWV_GPIO_OUT, 87 + BIT(offset), value ? BIT(offset) : 0); 88 + } 89 + 90 + static const struct gpio_chip template_chip = { 91 + .label = "bd9571mwv-gpio", 92 + .owner = THIS_MODULE, 93 + .get_direction = bd9571mwv_gpio_get_direction, 94 + .direction_input = bd9571mwv_gpio_direction_input, 95 + .direction_output = bd9571mwv_gpio_direction_output, 96 + .get = bd9571mwv_gpio_get, 97 + .set = bd9571mwv_gpio_set, 98 + .base = -1, 99 + .ngpio = 2, 100 + .can_sleep = true, 101 + }; 102 + 103 + static int bd9571mwv_gpio_probe(struct platform_device *pdev) 104 + { 105 + struct bd9571mwv_gpio *gpio; 106 + int ret; 107 + 108 + gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL); 109 + if (!gpio) 110 + return -ENOMEM; 111 + 112 + platform_set_drvdata(pdev, gpio); 113 + 114 + gpio->bd = dev_get_drvdata(pdev->dev.parent); 115 + gpio->chip = template_chip; 116 + gpio->chip.parent = gpio->bd->dev; 117 + 118 + ret = devm_gpiochip_add_data(&pdev->dev, &gpio->chip, gpio); 119 + if (ret < 0) { 120 + dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret); 121 + return ret; 122 + } 123 + 124 + return 0; 125 + } 126 + 127 + static const struct platform_device_id bd9571mwv_gpio_id_table[] = { 128 + { "bd9571mwv-gpio", }, 129 + { /* sentinel */ } 130 + }; 131 + MODULE_DEVICE_TABLE(platform, bd9571mwv_gpio_id_table); 132 + 133 + static struct platform_driver bd9571mwv_gpio_driver = { 134 + .driver = { 135 + .name = "bd9571mwv-gpio", 136 + }, 137 + .probe = bd9571mwv_gpio_probe, 138 + .id_table = bd9571mwv_gpio_id_table, 139 + }; 140 + module_platform_driver(bd9571mwv_gpio_driver); 141 + 142 + MODULE_AUTHOR("Marek Vasut <marek.vasut+renesas@gmail.com>"); 143 + MODULE_DESCRIPTION("BD9571MWV GPIO driver"); 144 + MODULE_LICENSE("GPL v2");
+1 -1
drivers/gpio/gpio-davinci.c
··· 483 483 clk_prepare_enable(clk); 484 484 485 485 if (!pdata->gpio_unbanked) { 486 - irq = irq_alloc_descs(-1, 0, ngpio, 0); 486 + irq = devm_irq_alloc_descs(dev, -1, 0, ngpio, 0); 487 487 if (irq < 0) { 488 488 dev_err(dev, "Couldn't allocate IRQ numbers\n"); 489 489 return irq;
+75 -18
drivers/gpio/gpio-dwapb.c
··· 21 21 #include <linux/module.h> 22 22 #include <linux/of.h> 23 23 #include <linux/of_address.h> 24 + #include <linux/of_device.h> 24 25 #include <linux/of_irq.h> 25 26 #include <linux/platform_device.h> 26 27 #include <linux/property.h> ··· 56 55 #define GPIO_SWPORT_DR_SIZE (GPIO_SWPORTB_DR - GPIO_SWPORTA_DR) 57 56 #define GPIO_SWPORT_DDR_SIZE (GPIO_SWPORTB_DDR - GPIO_SWPORTA_DDR) 58 57 58 + #define GPIO_REG_OFFSET_V2 1 59 + 60 + #define GPIO_INTMASK_V2 0x44 61 + #define GPIO_INTTYPE_LEVEL_V2 0x34 62 + #define GPIO_INT_POLARITY_V2 0x38 63 + #define GPIO_INTSTATUS_V2 0x3c 64 + #define GPIO_PORTA_EOI_V2 0x40 65 + 59 66 struct dwapb_gpio; 60 67 61 68 #ifdef CONFIG_PM_SLEEP ··· 96 87 struct dwapb_gpio_port *ports; 97 88 unsigned int nr_ports; 98 89 struct irq_domain *domain; 90 + unsigned int flags; 99 91 }; 92 + 93 + static inline u32 gpio_reg_v2_convert(unsigned int offset) 94 + { 95 + switch (offset) { 96 + case GPIO_INTMASK: 97 + return GPIO_INTMASK_V2; 98 + case GPIO_INTTYPE_LEVEL: 99 + return GPIO_INTTYPE_LEVEL_V2; 100 + case GPIO_INT_POLARITY: 101 + return GPIO_INT_POLARITY_V2; 102 + case GPIO_INTSTATUS: 103 + return GPIO_INTSTATUS_V2; 104 + case GPIO_PORTA_EOI: 105 + return GPIO_PORTA_EOI_V2; 106 + } 107 + 108 + return offset; 109 + } 110 + 111 + static inline u32 gpio_reg_convert(struct dwapb_gpio *gpio, unsigned int offset) 112 + { 113 + if (gpio->flags & GPIO_REG_OFFSET_V2) 114 + return gpio_reg_v2_convert(offset); 115 + 116 + return offset; 117 + } 100 118 101 119 static inline u32 dwapb_read(struct dwapb_gpio *gpio, unsigned int offset) 102 120 { 103 121 struct gpio_chip *gc = &gpio->ports[0].gc; 104 122 void __iomem *reg_base = gpio->regs; 105 123 106 - return gc->read_reg(reg_base + offset); 124 + return gc->read_reg(reg_base + gpio_reg_convert(gpio, offset)); 107 125 } 108 126 109 127 static inline void dwapb_write(struct dwapb_gpio *gpio, unsigned int offset, ··· 139 103 struct gpio_chip *gc = &gpio->ports[0].gc; 140 104 void __iomem *reg_base = gpio->regs; 141 105 142 - gc->write_reg(reg_base + offset, val); 106 + gc->write_reg(reg_base + gpio_reg_convert(gpio, offset), val); 143 107 } 144 108 145 109 static int dwapb_gpio_to_irq(struct gpio_chip *gc, unsigned offset) ··· 164 128 165 129 static u32 dwapb_do_irq(struct dwapb_gpio *gpio) 166 130 { 167 - u32 irq_status = readl_relaxed(gpio->regs + GPIO_INTSTATUS); 131 + u32 irq_status = dwapb_read(gpio, GPIO_INTSTATUS); 168 132 u32 ret = irq_status; 169 133 170 134 while (irq_status) { ··· 384 348 ct->chip.irq_disable = dwapb_irq_disable; 385 349 ct->chip.irq_request_resources = dwapb_irq_reqres; 386 350 ct->chip.irq_release_resources = dwapb_irq_relres; 387 - ct->regs.ack = GPIO_PORTA_EOI; 388 - ct->regs.mask = GPIO_INTMASK; 351 + ct->regs.ack = gpio_reg_convert(gpio, GPIO_PORTA_EOI); 352 + ct->regs.mask = gpio_reg_convert(gpio, GPIO_INTMASK); 389 353 ct->type = IRQ_TYPE_LEVEL_MASK; 390 354 } 391 355 ··· 568 532 return pdata; 569 533 } 570 534 535 + static const struct of_device_id dwapb_of_match[] = { 536 + { .compatible = "snps,dw-apb-gpio", .data = (void *)0}, 537 + { .compatible = "apm,xgene-gpio-v2", .data = (void *)GPIO_REG_OFFSET_V2}, 538 + { /* Sentinel */ } 539 + }; 540 + MODULE_DEVICE_TABLE(of, dwapb_of_match); 541 + 542 + static const struct acpi_device_id dwapb_acpi_match[] = { 543 + {"HISI0181", 0}, 544 + {"APMC0D07", 0}, 545 + {"APMC0D81", GPIO_REG_OFFSET_V2}, 546 + { } 547 + }; 548 + MODULE_DEVICE_TABLE(acpi, dwapb_acpi_match); 549 + 571 550 static int dwapb_gpio_probe(struct platform_device *pdev) 572 551 { 573 552 unsigned int i; ··· 618 567 if (IS_ERR(gpio->regs)) 619 568 return PTR_ERR(gpio->regs); 620 569 570 + gpio->flags = 0; 571 + if (dev->of_node) { 572 + const struct of_device_id *of_devid; 573 + 574 + of_devid = of_match_device(dwapb_of_match, dev); 575 + if (of_devid) { 576 + if (of_devid->data) 577 + gpio->flags = (uintptr_t)of_devid->data; 578 + } 579 + } else if (has_acpi_companion(dev)) { 580 + const struct acpi_device_id *acpi_id; 581 + 582 + acpi_id = acpi_match_device(dwapb_acpi_match, dev); 583 + if (acpi_id) { 584 + if (acpi_id->driver_data) 585 + gpio->flags = acpi_id->driver_data; 586 + } 587 + } 588 + 621 589 for (i = 0; i < gpio->nr_ports; i++) { 622 590 err = dwapb_gpio_add_port(gpio, &pdata->properties[i], i); 623 591 if (err) ··· 662 592 663 593 return 0; 664 594 } 665 - 666 - static const struct of_device_id dwapb_of_match[] = { 667 - { .compatible = "snps,dw-apb-gpio" }, 668 - { /* Sentinel */ } 669 - }; 670 - MODULE_DEVICE_TABLE(of, dwapb_of_match); 671 - 672 - static const struct acpi_device_id dwapb_acpi_match[] = { 673 - {"HISI0181", 0}, 674 - {"APMC0D07", 0}, 675 - { } 676 - }; 677 - MODULE_DEVICE_TABLE(acpi, dwapb_acpi_match); 678 595 679 596 #ifdef CONFIG_PM_SLEEP 680 597 static int dwapb_gpio_suspend(struct device *dev)
+12 -12
drivers/gpio/gpio-etraxfs.c
··· 54 54 struct etraxfs_gpio_info; 55 55 56 56 struct etraxfs_gpio_block { 57 - spinlock_t lock; 57 + raw_spinlock_t lock; 58 58 u32 mask; 59 59 u32 cfg; 60 60 u32 pins; ··· 233 233 struct etraxfs_gpio_block *block = chip->block; 234 234 unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq); 235 235 236 - spin_lock(&block->lock); 236 + raw_spin_lock(&block->lock); 237 237 block->mask &= ~BIT(grpirq); 238 238 writel(block->mask, block->regs + block->info->rw_intr_mask); 239 - spin_unlock(&block->lock); 239 + raw_spin_unlock(&block->lock); 240 240 } 241 241 242 242 static void etraxfs_gpio_irq_unmask(struct irq_data *d) ··· 246 246 struct etraxfs_gpio_block *block = chip->block; 247 247 unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq); 248 248 249 - spin_lock(&block->lock); 249 + raw_spin_lock(&block->lock); 250 250 block->mask |= BIT(grpirq); 251 251 writel(block->mask, block->regs + block->info->rw_intr_mask); 252 - spin_unlock(&block->lock); 252 + raw_spin_unlock(&block->lock); 253 253 } 254 254 255 255 static int etraxfs_gpio_irq_set_type(struct irq_data *d, u32 type) ··· 280 280 return -EINVAL; 281 281 } 282 282 283 - spin_lock(&block->lock); 283 + raw_spin_lock(&block->lock); 284 284 block->cfg &= ~(0x7 << (grpirq * 3)); 285 285 block->cfg |= (cfg << (grpirq * 3)); 286 286 writel(block->cfg, block->regs + block->info->rw_intr_cfg); 287 - spin_unlock(&block->lock); 287 + raw_spin_unlock(&block->lock); 288 288 289 289 return 0; 290 290 } ··· 297 297 unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq); 298 298 int ret = -EBUSY; 299 299 300 - spin_lock(&block->lock); 300 + raw_spin_lock(&block->lock); 301 301 if (block->group[grpirq]) 302 302 goto out; 303 303 ··· 316 316 } 317 317 318 318 out: 319 - spin_unlock(&block->lock); 319 + raw_spin_unlock(&block->lock); 320 320 return ret; 321 321 } 322 322 ··· 327 327 struct etraxfs_gpio_block *block = chip->block; 328 328 unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq); 329 329 330 - spin_lock(&block->lock); 330 + raw_spin_lock(&block->lock); 331 331 block->group[grpirq] = 0; 332 332 gpiochip_unlock_as_irq(&chip->gc, d->hwirq); 333 - spin_unlock(&block->lock); 333 + raw_spin_unlock(&block->lock); 334 334 } 335 335 336 336 static struct irq_chip etraxfs_gpio_irq_chip = { ··· 391 391 if (!block) 392 392 return -ENOMEM; 393 393 394 - spin_lock_init(&block->lock); 394 + raw_spin_lock_init(&block->lock); 395 395 396 396 block->regs = regs; 397 397 block->info = info;
+12 -11
drivers/gpio/gpio-exar.c
··· 59 59 return 0; 60 60 } 61 61 62 - static int exar_direction_output(struct gpio_chip *chip, unsigned int offset, 63 - int value) 64 - { 65 - return exar_set_direction(chip, 0, offset); 66 - } 67 - 68 - static int exar_direction_input(struct gpio_chip *chip, unsigned int offset) 69 - { 70 - return exar_set_direction(chip, 1, offset); 71 - } 72 - 73 62 static int exar_get(struct gpio_chip *chip, unsigned int reg) 74 63 { 75 64 struct exar_gpio_chip *exar_gpio = gpiochip_get_data(chip); ··· 103 114 104 115 addr = bank ? EXAR_OFFSET_MPIOLVL_HI : EXAR_OFFSET_MPIOLVL_LO; 105 116 exar_update(chip, addr, value, offset % 8); 117 + } 118 + 119 + static int exar_direction_output(struct gpio_chip *chip, unsigned int offset, 120 + int value) 121 + { 122 + exar_set_value(chip, offset, value); 123 + return exar_set_direction(chip, 0, offset); 124 + } 125 + 126 + static int exar_direction_input(struct gpio_chip *chip, unsigned int offset) 127 + { 128 + return exar_set_direction(chip, 1, offset); 106 129 } 107 130 108 131 static int gpio_exar_probe(struct platform_device *pdev)
+22 -2
drivers/gpio/gpio-f7188x.c
··· 37 37 #define SIO_F71869A_ID 0x1007 /* F71869A chipset ID */ 38 38 #define SIO_F71882_ID 0x0541 /* F71882 chipset ID */ 39 39 #define SIO_F71889_ID 0x0909 /* F71889 chipset ID */ 40 + #define SIO_F71889A_ID 0x1005 /* F71889A chipset ID */ 40 41 #define SIO_F81866_ID 0x1010 /* F81866 chipset ID */ 41 42 42 - enum chips { f71869, f71869a, f71882fg, f71889f, f81866 }; 43 + enum chips { f71869, f71869a, f71882fg, f71889a, f71889f, f81866 }; 43 44 44 45 static const char * const f7188x_names[] = { 45 46 "f71869", 46 47 "f71869a", 47 48 "f71882fg", 49 + "f71889a", 48 50 "f71889f", 49 51 "f81866", 50 52 }; ··· 187 185 F7188X_GPIO_BANK(20, 8, 0xD0), 188 186 F7188X_GPIO_BANK(30, 4, 0xC0), 189 187 F7188X_GPIO_BANK(40, 4, 0xB0), 188 + }; 189 + 190 + static struct f7188x_gpio_bank f71889a_gpio_bank[] = { 191 + F7188X_GPIO_BANK(0, 7, 0xF0), 192 + F7188X_GPIO_BANK(10, 7, 0xE0), 193 + F7188X_GPIO_BANK(20, 8, 0xD0), 194 + F7188X_GPIO_BANK(30, 8, 0xC0), 195 + F7188X_GPIO_BANK(40, 8, 0xB0), 196 + F7188X_GPIO_BANK(50, 5, 0xA0), 197 + F7188X_GPIO_BANK(60, 8, 0x90), 198 + F7188X_GPIO_BANK(70, 8, 0x80), 190 199 }; 191 200 192 201 static struct f7188x_gpio_bank f71889_gpio_bank[] = { ··· 395 382 data->nr_bank = ARRAY_SIZE(f71882_gpio_bank); 396 383 data->bank = f71882_gpio_bank; 397 384 break; 385 + case f71889a: 386 + data->nr_bank = ARRAY_SIZE(f71889a_gpio_bank); 387 + data->bank = f71889a_gpio_bank; 388 + break; 398 389 case f71889f: 399 390 data->nr_bank = ARRAY_SIZE(f71889_gpio_bank); 400 391 data->bank = f71889_gpio_bank; ··· 459 442 break; 460 443 case SIO_F71882_ID: 461 444 sio->type = f71882fg; 445 + break; 446 + case SIO_F71889A_ID: 447 + sio->type = f71889a; 462 448 break; 463 449 case SIO_F71889_ID: 464 450 sio->type = f71889f; ··· 558 538 } 559 539 module_exit(f7188x_gpio_exit); 560 540 561 - MODULE_DESCRIPTION("GPIO driver for Super-I/O chips F71869, F71869A, F71882FG, F71889F and F81866"); 541 + MODULE_DESCRIPTION("GPIO driver for Super-I/O chips F71869, F71869A, F71882FG, F71889A, F71889F and F81866"); 562 542 MODULE_AUTHOR("Simon Guinot <simon.guinot@sequanux.org>"); 563 543 MODULE_LICENSE("GPL");
+39 -33
drivers/gpio/gpio-gemini.c drivers/gpio/gpio-ftgpio010.c
··· 1 1 /* 2 - * Gemini gpiochip and interrupt routines 2 + * Faraday Technolog FTGPIO010 gpiochip and interrupt routines 3 3 * Copyright (C) 2017 Linus Walleij <linus.walleij@linaro.org> 4 4 * 5 5 * Based on arch/arm/mach-gemini/gpio.c: ··· 35 35 #define GPIO_DEBOUNCE_PRESCALE 0x44 36 36 37 37 /** 38 - * struct gemini_gpio - Gemini GPIO state container 38 + * struct ftgpio_gpio - Gemini GPIO state container 39 39 * @dev: containing device for this instance 40 40 * @gc: gpiochip for this instance 41 41 */ 42 - struct gemini_gpio { 42 + struct ftgpio_gpio { 43 43 struct device *dev; 44 44 struct gpio_chip gc; 45 45 void __iomem *base; 46 46 }; 47 47 48 - static void gemini_gpio_ack_irq(struct irq_data *d) 48 + static void ftgpio_gpio_ack_irq(struct irq_data *d) 49 49 { 50 50 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 51 - struct gemini_gpio *g = gpiochip_get_data(gc); 51 + struct ftgpio_gpio *g = gpiochip_get_data(gc); 52 52 53 53 writel(BIT(irqd_to_hwirq(d)), g->base + GPIO_INT_CLR); 54 54 } 55 55 56 - static void gemini_gpio_mask_irq(struct irq_data *d) 56 + static void ftgpio_gpio_mask_irq(struct irq_data *d) 57 57 { 58 58 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 59 - struct gemini_gpio *g = gpiochip_get_data(gc); 59 + struct ftgpio_gpio *g = gpiochip_get_data(gc); 60 60 u32 val; 61 61 62 62 val = readl(g->base + GPIO_INT_EN); ··· 64 64 writel(val, g->base + GPIO_INT_EN); 65 65 } 66 66 67 - static void gemini_gpio_unmask_irq(struct irq_data *d) 67 + static void ftgpio_gpio_unmask_irq(struct irq_data *d) 68 68 { 69 69 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 70 - struct gemini_gpio *g = gpiochip_get_data(gc); 70 + struct ftgpio_gpio *g = gpiochip_get_data(gc); 71 71 u32 val; 72 72 73 73 val = readl(g->base + GPIO_INT_EN); ··· 75 75 writel(val, g->base + GPIO_INT_EN); 76 76 } 77 77 78 - static int gemini_gpio_set_irq_type(struct irq_data *d, unsigned int type) 78 + static int ftgpio_gpio_set_irq_type(struct irq_data *d, unsigned int type) 79 79 { 80 80 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 81 - struct gemini_gpio *g = gpiochip_get_data(gc); 81 + struct ftgpio_gpio *g = gpiochip_get_data(gc); 82 82 u32 mask = BIT(irqd_to_hwirq(d)); 83 83 u32 reg_both, reg_level, reg_type; 84 84 ··· 123 123 writel(reg_level, g->base + GPIO_INT_LEVEL); 124 124 writel(reg_both, g->base + GPIO_INT_BOTH_EDGE); 125 125 126 - gemini_gpio_ack_irq(d); 126 + ftgpio_gpio_ack_irq(d); 127 127 128 128 return 0; 129 129 } 130 130 131 - static struct irq_chip gemini_gpio_irqchip = { 132 - .name = "GPIO", 133 - .irq_ack = gemini_gpio_ack_irq, 134 - .irq_mask = gemini_gpio_mask_irq, 135 - .irq_unmask = gemini_gpio_unmask_irq, 136 - .irq_set_type = gemini_gpio_set_irq_type, 131 + static struct irq_chip ftgpio_gpio_irqchip = { 132 + .name = "FTGPIO010", 133 + .irq_ack = ftgpio_gpio_ack_irq, 134 + .irq_mask = ftgpio_gpio_mask_irq, 135 + .irq_unmask = ftgpio_gpio_unmask_irq, 136 + .irq_set_type = ftgpio_gpio_set_irq_type, 137 137 }; 138 138 139 - static void gemini_gpio_irq_handler(struct irq_desc *desc) 139 + static void ftgpio_gpio_irq_handler(struct irq_desc *desc) 140 140 { 141 141 struct gpio_chip *gc = irq_desc_get_handler_data(desc); 142 - struct gemini_gpio *g = gpiochip_get_data(gc); 142 + struct ftgpio_gpio *g = gpiochip_get_data(gc); 143 143 struct irq_chip *irqchip = irq_desc_get_chip(desc); 144 144 int offset; 145 145 unsigned long stat; ··· 155 155 chained_irq_exit(irqchip, desc); 156 156 } 157 157 158 - static int gemini_gpio_probe(struct platform_device *pdev) 158 + static int ftgpio_gpio_probe(struct platform_device *pdev) 159 159 { 160 160 struct device *dev = &pdev->dev; 161 161 struct resource *res; 162 - struct gemini_gpio *g; 162 + struct ftgpio_gpio *g; 163 163 int irq; 164 164 int ret; 165 165 ··· 189 189 dev_err(dev, "unable to init generic GPIO\n"); 190 190 return ret; 191 191 } 192 - g->gc.label = "Gemini"; 192 + g->gc.label = "FTGPIO010"; 193 193 g->gc.base = -1; 194 194 g->gc.parent = dev; 195 195 g->gc.owner = THIS_MODULE; ··· 204 204 writel(0x0, g->base + GPIO_INT_MASK); 205 205 writel(~0x0, g->base + GPIO_INT_CLR); 206 206 207 - ret = gpiochip_irqchip_add(&g->gc, &gemini_gpio_irqchip, 207 + ret = gpiochip_irqchip_add(&g->gc, &ftgpio_gpio_irqchip, 208 208 0, handle_bad_irq, 209 209 IRQ_TYPE_NONE); 210 210 if (ret) { 211 211 dev_info(dev, "could not add irqchip\n"); 212 212 return ret; 213 213 } 214 - gpiochip_set_chained_irqchip(&g->gc, &gemini_gpio_irqchip, 215 - irq, gemini_gpio_irq_handler); 214 + gpiochip_set_chained_irqchip(&g->gc, &ftgpio_gpio_irqchip, 215 + irq, ftgpio_gpio_irq_handler); 216 216 217 - dev_info(dev, "Gemini GPIO @%p registered\n", g->base); 217 + dev_info(dev, "FTGPIO010 @%p registered\n", g->base); 218 218 219 219 return 0; 220 220 } 221 221 222 - static const struct of_device_id gemini_gpio_of_match[] = { 222 + static const struct of_device_id ftgpio_gpio_of_match[] = { 223 223 { 224 224 .compatible = "cortina,gemini-gpio", 225 + }, 226 + { 227 + .compatible = "moxa,moxart-gpio", 228 + }, 229 + { 230 + .compatible = "faraday,ftgpio010", 225 231 }, 226 232 {}, 227 233 }; 228 234 229 - static struct platform_driver gemini_gpio_driver = { 235 + static struct platform_driver ftgpio_gpio_driver = { 230 236 .driver = { 231 - .name = "gemini-gpio", 232 - .of_match_table = of_match_ptr(gemini_gpio_of_match), 237 + .name = "ftgpio010-gpio", 238 + .of_match_table = of_match_ptr(ftgpio_gpio_of_match), 233 239 }, 234 - .probe = gemini_gpio_probe, 240 + .probe = ftgpio_gpio_probe, 235 241 }; 236 - builtin_platform_driver(gemini_gpio_driver); 242 + builtin_platform_driver(ftgpio_gpio_driver);
+1 -1
drivers/gpio/gpio-merrifield.c
··· 166 166 { 167 167 void __iomem *gpdr = gpio_reg(chip, offset, GPDR); 168 168 169 - return (readl(gpdr) & BIT(offset % 32)) ? GPIOF_DIR_OUT : GPIOF_DIR_IN; 169 + return !(readl(gpdr) & BIT(offset % 32)); 170 170 } 171 171 172 172 static int mrfld_gpio_set_debounce(struct gpio_chip *chip, unsigned int offset,
+7 -21
drivers/gpio/gpio-ml-ioh.c
··· 459 459 460 460 chip = chip_save; 461 461 for (j = 0; j < 8; j++, chip++) { 462 - irq_base = irq_alloc_descs(-1, IOH_IRQ_BASE, num_ports[j], 463 - NUMA_NO_NODE); 462 + irq_base = devm_irq_alloc_descs(&pdev->dev, -1, IOH_IRQ_BASE, 463 + num_ports[j], NUMA_NO_NODE); 464 464 if (irq_base < 0) { 465 465 dev_warn(&pdev->dev, 466 466 "ml_ioh_gpio: Failed to get IRQ base num\n"); 467 - chip->irq_base = -1; 468 467 ret = irq_base; 469 - goto err_irq_alloc_descs; 468 + goto err_gpiochip_add; 470 469 } 471 470 chip->irq_base = irq_base; 472 471 ioh_gpio_alloc_generic_chip(chip, irq_base, num_ports[j]); 473 472 } 474 473 475 474 chip = chip_save; 476 - ret = request_irq(pdev->irq, ioh_gpio_handler, 477 - IRQF_SHARED, KBUILD_MODNAME, chip); 475 + ret = devm_request_irq(&pdev->dev, pdev->irq, ioh_gpio_handler, 476 + IRQF_SHARED, KBUILD_MODNAME, chip); 478 477 if (ret != 0) { 479 478 dev_err(&pdev->dev, 480 479 "%s request_irq failed\n", __func__); 481 - goto err_request_irq; 480 + goto err_gpiochip_add; 482 481 } 483 482 484 483 pci_set_drvdata(pdev, chip); 485 484 486 485 return 0; 487 486 488 - err_request_irq: 489 - chip = chip_save; 490 - err_irq_alloc_descs: 491 - while (--j >= 0) { 492 - chip--; 493 - irq_free_descs(chip->irq_base, num_ports[j]); 494 - } 495 - 496 - chip = chip_save; 497 487 err_gpiochip_add: 498 488 while (--i >= 0) { 499 489 chip--; ··· 514 524 515 525 chip_save = chip; 516 526 517 - free_irq(pdev->irq, chip); 518 - 519 - for (i = 0; i < 8; i++, chip++) { 520 - irq_free_descs(chip->irq_base, num_ports[i]); 527 + for (i = 0; i < 8; i++, chip++) 521 528 gpiochip_remove(&chip->gpio); 522 - } 523 529 524 530 chip = chip_save; 525 531 pci_iounmap(pdev, chip->base);
+1
drivers/gpio/gpio-mmio.c
··· 575 575 static const struct of_device_id bgpio_of_match[] = { 576 576 { .compatible = "brcm,bcm6345-gpio" }, 577 577 { .compatible = "wd,mbl-gpio" }, 578 + { .compatible = "ni,169445-nand-gpio" }, 578 579 { } 579 580 }; 580 581 MODULE_DEVICE_TABLE(of, bgpio_of_match);
+1 -15
drivers/gpio/gpio-mockup.c
··· 169 169 struct gpio_chip *gc = &chip->gc; 170 170 int irq_base, i; 171 171 172 - irq_base = irq_alloc_descs(-1, 0, gc->ngpio, 0); 172 + irq_base = devm_irq_alloc_descs(dev, -1, 0, gc->ngpio, 0); 173 173 if (irq_base < 0) 174 174 return irq_base; 175 175 ··· 372 372 return 0; 373 373 } 374 374 375 - static int gpio_mockup_remove(struct platform_device *pdev) 376 - { 377 - struct gpio_mockup_chip *chips; 378 - int i; 379 - 380 - chips = platform_get_drvdata(pdev); 381 - 382 - for (i = 0; i < gpio_mockup_params_nr >> 1; i++) 383 - irq_free_descs(chips[i].gc.irq_base, chips[i].gc.ngpio); 384 - 385 - return 0; 386 - } 387 - 388 375 static struct platform_driver gpio_mockup_driver = { 389 376 .driver = { 390 377 .name = GPIO_MOCKUP_NAME, 391 378 }, 392 379 .probe = gpio_mockup_probe, 393 - .remove = gpio_mockup_remove, 394 380 }; 395 381 396 382 static struct platform_device *pdev;
-84
drivers/gpio/gpio-moxart.c
··· 1 - /* 2 - * MOXA ART SoCs GPIO driver. 3 - * 4 - * Copyright (C) 2013 Jonas Jensen 5 - * 6 - * Jonas Jensen <jonas.jensen@gmail.com> 7 - * 8 - * This file is licensed under the terms of the GNU General Public 9 - * License version 2. This program is licensed "as is" without any 10 - * warranty of any kind, whether express or implied. 11 - */ 12 - 13 - #include <linux/err.h> 14 - #include <linux/init.h> 15 - #include <linux/irq.h> 16 - #include <linux/io.h> 17 - #include <linux/platform_device.h> 18 - #include <linux/of_address.h> 19 - #include <linux/of_gpio.h> 20 - #include <linux/pinctrl/consumer.h> 21 - #include <linux/delay.h> 22 - #include <linux/timer.h> 23 - #include <linux/bitops.h> 24 - #include <linux/gpio/driver.h> 25 - 26 - #define GPIO_DATA_OUT 0x00 27 - #define GPIO_DATA_IN 0x04 28 - #define GPIO_PIN_DIRECTION 0x08 29 - 30 - static int moxart_gpio_probe(struct platform_device *pdev) 31 - { 32 - struct device *dev = &pdev->dev; 33 - struct resource *res; 34 - struct gpio_chip *gc; 35 - void __iomem *base; 36 - int ret; 37 - 38 - gc = devm_kzalloc(dev, sizeof(*gc), GFP_KERNEL); 39 - if (!gc) 40 - return -ENOMEM; 41 - 42 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 43 - base = devm_ioremap_resource(dev, res); 44 - if (IS_ERR(base)) 45 - return PTR_ERR(base); 46 - 47 - ret = bgpio_init(gc, dev, 4, base + GPIO_DATA_IN, 48 - base + GPIO_DATA_OUT, NULL, 49 - base + GPIO_PIN_DIRECTION, NULL, 50 - BGPIOF_READ_OUTPUT_REG_SET); 51 - if (ret) { 52 - dev_err(&pdev->dev, "bgpio_init failed\n"); 53 - return ret; 54 - } 55 - 56 - gc->label = "moxart-gpio"; 57 - gc->request = gpiochip_generic_request; 58 - gc->free = gpiochip_generic_free; 59 - gc->base = 0; 60 - gc->owner = THIS_MODULE; 61 - 62 - ret = devm_gpiochip_add_data(dev, gc, NULL); 63 - if (ret) { 64 - dev_err(dev, "%s: gpiochip_add failed\n", 65 - dev->of_node->full_name); 66 - return ret; 67 - } 68 - 69 - return ret; 70 - } 71 - 72 - static const struct of_device_id moxart_gpio_match[] = { 73 - { .compatible = "moxa,moxart-gpio" }, 74 - { } 75 - }; 76 - 77 - static struct platform_driver moxart_gpio_driver = { 78 - .driver = { 79 - .name = "moxart-gpio", 80 - .of_match_table = moxart_gpio_match, 81 - }, 82 - .probe = moxart_gpio_probe, 83 - }; 84 - builtin_platform_driver(moxart_gpio_driver);
+373 -62
drivers/gpio/gpio-mvebu.c
··· 42 42 #include <linux/io.h> 43 43 #include <linux/of_irq.h> 44 44 #include <linux/of_device.h> 45 + #include <linux/pwm.h> 45 46 #include <linux/clk.h> 46 47 #include <linux/pinctrl/consumer.h> 47 48 #include <linux/irqchip/chained_irq.h> 49 + #include <linux/platform_device.h> 50 + #include <linux/bitops.h> 51 + 52 + #include "gpiolib.h" 48 53 49 54 /* 50 55 * GPIO unit register offsets. 51 56 */ 52 - #define GPIO_OUT_OFF 0x0000 53 - #define GPIO_IO_CONF_OFF 0x0004 54 - #define GPIO_BLINK_EN_OFF 0x0008 55 - #define GPIO_IN_POL_OFF 0x000c 56 - #define GPIO_DATA_IN_OFF 0x0010 57 - #define GPIO_EDGE_CAUSE_OFF 0x0014 58 - #define GPIO_EDGE_MASK_OFF 0x0018 59 - #define GPIO_LEVEL_MASK_OFF 0x001c 57 + #define GPIO_OUT_OFF 0x0000 58 + #define GPIO_IO_CONF_OFF 0x0004 59 + #define GPIO_BLINK_EN_OFF 0x0008 60 + #define GPIO_IN_POL_OFF 0x000c 61 + #define GPIO_DATA_IN_OFF 0x0010 62 + #define GPIO_EDGE_CAUSE_OFF 0x0014 63 + #define GPIO_EDGE_MASK_OFF 0x0018 64 + #define GPIO_LEVEL_MASK_OFF 0x001c 65 + #define GPIO_BLINK_CNT_SELECT_OFF 0x0020 66 + 67 + /* 68 + * PWM register offsets. 69 + */ 70 + #define PWM_BLINK_ON_DURATION_OFF 0x0 71 + #define PWM_BLINK_OFF_DURATION_OFF 0x4 72 + 60 73 61 74 /* The MV78200 has per-CPU registers for edge mask and level mask */ 62 75 #define GPIO_EDGE_MASK_MV78200_OFF(cpu) ((cpu) ? 0x30 : 0x18) 63 76 #define GPIO_LEVEL_MASK_MV78200_OFF(cpu) ((cpu) ? 0x34 : 0x1C) 64 77 65 - /* The Armada XP has per-CPU registers for interrupt cause, interrupt 78 + /* 79 + * The Armada XP has per-CPU registers for interrupt cause, interrupt 66 80 * mask and interrupt level mask. Those are relative to the 67 - * percpu_membase. */ 81 + * percpu_membase. 82 + */ 68 83 #define GPIO_EDGE_CAUSE_ARMADAXP_OFF(cpu) ((cpu) * 0x4) 69 84 #define GPIO_EDGE_MASK_ARMADAXP_OFF(cpu) (0x10 + (cpu) * 0x4) 70 85 #define GPIO_LEVEL_MASK_ARMADAXP_OFF(cpu) (0x20 + (cpu) * 0x4) ··· 90 75 91 76 #define MVEBU_MAX_GPIO_PER_BANK 32 92 77 78 + struct mvebu_pwm { 79 + void __iomem *membase; 80 + unsigned long clk_rate; 81 + struct gpio_desc *gpiod; 82 + struct pwm_chip chip; 83 + spinlock_t lock; 84 + struct mvebu_gpio_chip *mvchip; 85 + 86 + /* Used to preserve GPIO/PWM registers across suspend/resume */ 87 + u32 blink_select; 88 + u32 blink_on_duration; 89 + u32 blink_off_duration; 90 + }; 91 + 93 92 struct mvebu_gpio_chip { 94 93 struct gpio_chip chip; 95 94 spinlock_t lock; ··· 113 84 struct irq_domain *domain; 114 85 int soc_variant; 115 86 87 + /* Used for PWM support */ 88 + struct clk *clk; 89 + struct mvebu_pwm *mvpwm; 90 + 116 91 /* Used to preserve GPIO registers across suspend/resume */ 117 - u32 out_reg; 118 - u32 io_conf_reg; 119 - u32 blink_en_reg; 120 - u32 in_pol_reg; 121 - u32 edge_mask_regs[4]; 122 - u32 level_mask_regs[4]; 92 + u32 out_reg; 93 + u32 io_conf_reg; 94 + u32 blink_en_reg; 95 + u32 in_pol_reg; 96 + u32 edge_mask_regs[4]; 97 + u32 level_mask_regs[4]; 123 98 }; 124 99 125 100 /* 126 101 * Functions returning addresses of individual registers for a given 127 102 * GPIO controller. 128 103 */ 129 - static inline void __iomem *mvebu_gpioreg_out(struct mvebu_gpio_chip *mvchip) 104 + static void __iomem *mvebu_gpioreg_out(struct mvebu_gpio_chip *mvchip) 130 105 { 131 106 return mvchip->membase + GPIO_OUT_OFF; 132 107 } 133 108 134 - static inline void __iomem *mvebu_gpioreg_blink(struct mvebu_gpio_chip *mvchip) 109 + static void __iomem *mvebu_gpioreg_blink(struct mvebu_gpio_chip *mvchip) 135 110 { 136 111 return mvchip->membase + GPIO_BLINK_EN_OFF; 137 112 } 138 113 139 - static inline void __iomem * 140 - mvebu_gpioreg_io_conf(struct mvebu_gpio_chip *mvchip) 114 + static void __iomem *mvebu_gpioreg_blink_counter_select(struct mvebu_gpio_chip 115 + *mvchip) 116 + { 117 + return mvchip->membase + GPIO_BLINK_CNT_SELECT_OFF; 118 + } 119 + 120 + static void __iomem *mvebu_gpioreg_io_conf(struct mvebu_gpio_chip *mvchip) 141 121 { 142 122 return mvchip->membase + GPIO_IO_CONF_OFF; 143 123 } 144 124 145 - static inline void __iomem *mvebu_gpioreg_in_pol(struct mvebu_gpio_chip *mvchip) 125 + static void __iomem *mvebu_gpioreg_in_pol(struct mvebu_gpio_chip *mvchip) 146 126 { 147 127 return mvchip->membase + GPIO_IN_POL_OFF; 148 128 } 149 129 150 - static inline void __iomem * 151 - mvebu_gpioreg_data_in(struct mvebu_gpio_chip *mvchip) 130 + static void __iomem *mvebu_gpioreg_data_in(struct mvebu_gpio_chip *mvchip) 152 131 { 153 132 return mvchip->membase + GPIO_DATA_IN_OFF; 154 133 } 155 134 156 - static inline void __iomem * 157 - mvebu_gpioreg_edge_cause(struct mvebu_gpio_chip *mvchip) 135 + static void __iomem *mvebu_gpioreg_edge_cause(struct mvebu_gpio_chip *mvchip) 158 136 { 159 137 int cpu; 160 138 ··· 178 142 } 179 143 } 180 144 181 - static inline void __iomem * 182 - mvebu_gpioreg_edge_mask(struct mvebu_gpio_chip *mvchip) 145 + static void __iomem *mvebu_gpioreg_edge_mask(struct mvebu_gpio_chip *mvchip) 183 146 { 184 147 int cpu; 185 148 ··· 217 182 } 218 183 219 184 /* 185 + * Functions returning addresses of individual registers for a given 186 + * PWM controller. 187 + */ 188 + static void __iomem *mvebu_pwmreg_blink_on_duration(struct mvebu_pwm *mvpwm) 189 + { 190 + return mvpwm->membase + PWM_BLINK_ON_DURATION_OFF; 191 + } 192 + 193 + static void __iomem *mvebu_pwmreg_blink_off_duration(struct mvebu_pwm *mvpwm) 194 + { 195 + return mvpwm->membase + PWM_BLINK_OFF_DURATION_OFF; 196 + } 197 + 198 + /* 220 199 * Functions implementing the gpio_chip methods 221 200 */ 222 - 223 - static void mvebu_gpio_set(struct gpio_chip *chip, unsigned pin, int value) 201 + static void mvebu_gpio_set(struct gpio_chip *chip, unsigned int pin, int value) 224 202 { 225 203 struct mvebu_gpio_chip *mvchip = gpiochip_get_data(chip); 226 204 unsigned long flags; ··· 242 194 spin_lock_irqsave(&mvchip->lock, flags); 243 195 u = readl_relaxed(mvebu_gpioreg_out(mvchip)); 244 196 if (value) 245 - u |= 1 << pin; 197 + u |= BIT(pin); 246 198 else 247 - u &= ~(1 << pin); 199 + u &= ~BIT(pin); 248 200 writel_relaxed(u, mvebu_gpioreg_out(mvchip)); 249 201 spin_unlock_irqrestore(&mvchip->lock, flags); 250 202 } 251 203 252 - static int mvebu_gpio_get(struct gpio_chip *chip, unsigned pin) 204 + static int mvebu_gpio_get(struct gpio_chip *chip, unsigned int pin) 253 205 { 254 206 struct mvebu_gpio_chip *mvchip = gpiochip_get_data(chip); 255 207 u32 u; 256 208 257 - if (readl_relaxed(mvebu_gpioreg_io_conf(mvchip)) & (1 << pin)) { 209 + if (readl_relaxed(mvebu_gpioreg_io_conf(mvchip)) & BIT(pin)) { 258 210 u = readl_relaxed(mvebu_gpioreg_data_in(mvchip)) ^ 259 211 readl_relaxed(mvebu_gpioreg_in_pol(mvchip)); 260 212 } else { ··· 264 216 return (u >> pin) & 1; 265 217 } 266 218 267 - static void mvebu_gpio_blink(struct gpio_chip *chip, unsigned pin, int value) 219 + static void mvebu_gpio_blink(struct gpio_chip *chip, unsigned int pin, 220 + int value) 268 221 { 269 222 struct mvebu_gpio_chip *mvchip = gpiochip_get_data(chip); 270 223 unsigned long flags; ··· 274 225 spin_lock_irqsave(&mvchip->lock, flags); 275 226 u = readl_relaxed(mvebu_gpioreg_blink(mvchip)); 276 227 if (value) 277 - u |= 1 << pin; 228 + u |= BIT(pin); 278 229 else 279 - u &= ~(1 << pin); 230 + u &= ~BIT(pin); 280 231 writel_relaxed(u, mvebu_gpioreg_blink(mvchip)); 281 232 spin_unlock_irqrestore(&mvchip->lock, flags); 282 233 } 283 234 284 - static int mvebu_gpio_direction_input(struct gpio_chip *chip, unsigned pin) 235 + static int mvebu_gpio_direction_input(struct gpio_chip *chip, unsigned int pin) 285 236 { 286 237 struct mvebu_gpio_chip *mvchip = gpiochip_get_data(chip); 287 238 unsigned long flags; 288 239 int ret; 289 240 u32 u; 290 241 291 - /* Check with the pinctrl driver whether this pin is usable as 292 - * an input GPIO */ 242 + /* 243 + * Check with the pinctrl driver whether this pin is usable as 244 + * an input GPIO 245 + */ 293 246 ret = pinctrl_gpio_direction_input(chip->base + pin); 294 247 if (ret) 295 248 return ret; 296 249 297 250 spin_lock_irqsave(&mvchip->lock, flags); 298 251 u = readl_relaxed(mvebu_gpioreg_io_conf(mvchip)); 299 - u |= 1 << pin; 252 + u |= BIT(pin); 300 253 writel_relaxed(u, mvebu_gpioreg_io_conf(mvchip)); 301 254 spin_unlock_irqrestore(&mvchip->lock, flags); 302 255 303 256 return 0; 304 257 } 305 258 306 - static int mvebu_gpio_direction_output(struct gpio_chip *chip, unsigned pin, 259 + static int mvebu_gpio_direction_output(struct gpio_chip *chip, unsigned int pin, 307 260 int value) 308 261 { 309 262 struct mvebu_gpio_chip *mvchip = gpiochip_get_data(chip); ··· 313 262 int ret; 314 263 u32 u; 315 264 316 - /* Check with the pinctrl driver whether this pin is usable as 317 - * an output GPIO */ 265 + /* 266 + * Check with the pinctrl driver whether this pin is usable as 267 + * an output GPIO 268 + */ 318 269 ret = pinctrl_gpio_direction_output(chip->base + pin); 319 270 if (ret) 320 271 return ret; ··· 326 273 327 274 spin_lock_irqsave(&mvchip->lock, flags); 328 275 u = readl_relaxed(mvebu_gpioreg_io_conf(mvchip)); 329 - u &= ~(1 << pin); 276 + u &= ~BIT(pin); 330 277 writel_relaxed(u, mvebu_gpioreg_io_conf(mvchip)); 331 278 spin_unlock_irqrestore(&mvchip->lock, flags); 332 279 333 280 return 0; 334 281 } 335 282 336 - static int mvebu_gpio_to_irq(struct gpio_chip *chip, unsigned pin) 283 + static int mvebu_gpio_to_irq(struct gpio_chip *chip, unsigned int pin) 337 284 { 338 285 struct mvebu_gpio_chip *mvchip = gpiochip_get_data(chip); 286 + 339 287 return irq_create_mapping(mvchip->domain, pin); 340 288 } 341 289 ··· 443 389 444 390 pin = d->hwirq; 445 391 446 - u = readl_relaxed(mvebu_gpioreg_io_conf(mvchip)) & (1 << pin); 392 + u = readl_relaxed(mvebu_gpioreg_io_conf(mvchip)) & BIT(pin); 447 393 if (!u) 448 394 return -EINVAL; 449 395 ··· 463 409 case IRQ_TYPE_EDGE_RISING: 464 410 case IRQ_TYPE_LEVEL_HIGH: 465 411 u = readl_relaxed(mvebu_gpioreg_in_pol(mvchip)); 466 - u &= ~(1 << pin); 412 + u &= ~BIT(pin); 467 413 writel_relaxed(u, mvebu_gpioreg_in_pol(mvchip)); 468 414 break; 469 415 case IRQ_TYPE_EDGE_FALLING: 470 416 case IRQ_TYPE_LEVEL_LOW: 471 417 u = readl_relaxed(mvebu_gpioreg_in_pol(mvchip)); 472 - u |= 1 << pin; 418 + u |= BIT(pin); 473 419 writel_relaxed(u, mvebu_gpioreg_in_pol(mvchip)); 474 420 break; 475 421 case IRQ_TYPE_EDGE_BOTH: { ··· 482 428 * set initial polarity based on current input level 483 429 */ 484 430 u = readl_relaxed(mvebu_gpioreg_in_pol(mvchip)); 485 - if (v & (1 << pin)) 486 - u |= 1 << pin; /* falling */ 431 + if (v & BIT(pin)) 432 + u |= BIT(pin); /* falling */ 487 433 else 488 - u &= ~(1 << pin); /* rising */ 434 + u &= ~BIT(pin); /* rising */ 489 435 writel_relaxed(u, mvebu_gpioreg_in_pol(mvchip)); 490 436 break; 491 437 } ··· 515 461 516 462 irq = irq_find_mapping(mvchip->domain, i); 517 463 518 - if (!(cause & (1 << i))) 464 + if (!(cause & BIT(i))) 519 465 continue; 520 466 521 467 type = irq_get_trigger_type(irq); ··· 524 470 u32 polarity; 525 471 526 472 polarity = readl_relaxed(mvebu_gpioreg_in_pol(mvchip)); 527 - polarity ^= 1 << i; 473 + polarity ^= BIT(i); 528 474 writel_relaxed(polarity, mvebu_gpioreg_in_pol(mvchip)); 529 475 } 530 476 ··· 532 478 } 533 479 534 480 chained_irq_exit(chip, desc); 481 + } 482 + 483 + /* 484 + * Functions implementing the pwm_chip methods 485 + */ 486 + static struct mvebu_pwm *to_mvebu_pwm(struct pwm_chip *chip) 487 + { 488 + return container_of(chip, struct mvebu_pwm, chip); 489 + } 490 + 491 + static int mvebu_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm) 492 + { 493 + struct mvebu_pwm *mvpwm = to_mvebu_pwm(chip); 494 + struct mvebu_gpio_chip *mvchip = mvpwm->mvchip; 495 + struct gpio_desc *desc; 496 + unsigned long flags; 497 + int ret = 0; 498 + 499 + spin_lock_irqsave(&mvpwm->lock, flags); 500 + 501 + if (mvpwm->gpiod) { 502 + ret = -EBUSY; 503 + } else { 504 + desc = gpio_to_desc(mvchip->chip.base + pwm->hwpwm); 505 + if (!desc) { 506 + ret = -ENODEV; 507 + goto out; 508 + } 509 + 510 + ret = gpiod_request(desc, "mvebu-pwm"); 511 + if (ret) 512 + goto out; 513 + 514 + ret = gpiod_direction_output(desc, 0); 515 + if (ret) { 516 + gpiod_free(desc); 517 + goto out; 518 + } 519 + 520 + mvpwm->gpiod = desc; 521 + } 522 + out: 523 + spin_unlock_irqrestore(&mvpwm->lock, flags); 524 + return ret; 525 + } 526 + 527 + static void mvebu_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm) 528 + { 529 + struct mvebu_pwm *mvpwm = to_mvebu_pwm(chip); 530 + unsigned long flags; 531 + 532 + spin_lock_irqsave(&mvpwm->lock, flags); 533 + gpiod_free(mvpwm->gpiod); 534 + mvpwm->gpiod = NULL; 535 + spin_unlock_irqrestore(&mvpwm->lock, flags); 536 + } 537 + 538 + static void mvebu_pwm_get_state(struct pwm_chip *chip, 539 + struct pwm_device *pwm, 540 + struct pwm_state *state) { 541 + 542 + struct mvebu_pwm *mvpwm = to_mvebu_pwm(chip); 543 + struct mvebu_gpio_chip *mvchip = mvpwm->mvchip; 544 + unsigned long long val; 545 + unsigned long flags; 546 + u32 u; 547 + 548 + spin_lock_irqsave(&mvpwm->lock, flags); 549 + 550 + val = (unsigned long long) 551 + readl_relaxed(mvebu_pwmreg_blink_on_duration(mvpwm)); 552 + val *= NSEC_PER_SEC; 553 + do_div(val, mvpwm->clk_rate); 554 + if (val > UINT_MAX) 555 + state->duty_cycle = UINT_MAX; 556 + else if (val) 557 + state->duty_cycle = val; 558 + else 559 + state->duty_cycle = 1; 560 + 561 + val = (unsigned long long) 562 + readl_relaxed(mvebu_pwmreg_blink_off_duration(mvpwm)); 563 + val *= NSEC_PER_SEC; 564 + do_div(val, mvpwm->clk_rate); 565 + if (val < state->duty_cycle) { 566 + state->period = 1; 567 + } else { 568 + val -= state->duty_cycle; 569 + if (val > UINT_MAX) 570 + state->period = UINT_MAX; 571 + else if (val) 572 + state->period = val; 573 + else 574 + state->period = 1; 575 + } 576 + 577 + u = readl_relaxed(mvebu_gpioreg_blink(mvchip)); 578 + if (u) 579 + state->enabled = true; 580 + else 581 + state->enabled = false; 582 + 583 + spin_unlock_irqrestore(&mvpwm->lock, flags); 584 + } 585 + 586 + static int mvebu_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, 587 + struct pwm_state *state) 588 + { 589 + struct mvebu_pwm *mvpwm = to_mvebu_pwm(chip); 590 + struct mvebu_gpio_chip *mvchip = mvpwm->mvchip; 591 + unsigned long long val; 592 + unsigned long flags; 593 + unsigned int on, off; 594 + 595 + val = (unsigned long long) mvpwm->clk_rate * state->duty_cycle; 596 + do_div(val, NSEC_PER_SEC); 597 + if (val > UINT_MAX) 598 + return -EINVAL; 599 + if (val) 600 + on = val; 601 + else 602 + on = 1; 603 + 604 + val = (unsigned long long) mvpwm->clk_rate * 605 + (state->period - state->duty_cycle); 606 + do_div(val, NSEC_PER_SEC); 607 + if (val > UINT_MAX) 608 + return -EINVAL; 609 + if (val) 610 + off = val; 611 + else 612 + off = 1; 613 + 614 + spin_lock_irqsave(&mvpwm->lock, flags); 615 + 616 + writel_relaxed(on, mvebu_pwmreg_blink_on_duration(mvpwm)); 617 + writel_relaxed(off, mvebu_pwmreg_blink_off_duration(mvpwm)); 618 + if (state->enabled) 619 + mvebu_gpio_blink(&mvchip->chip, pwm->hwpwm, 1); 620 + else 621 + mvebu_gpio_blink(&mvchip->chip, pwm->hwpwm, 0); 622 + 623 + spin_unlock_irqrestore(&mvpwm->lock, flags); 624 + 625 + return 0; 626 + } 627 + 628 + static const struct pwm_ops mvebu_pwm_ops = { 629 + .request = mvebu_pwm_request, 630 + .free = mvebu_pwm_free, 631 + .get_state = mvebu_pwm_get_state, 632 + .apply = mvebu_pwm_apply, 633 + .owner = THIS_MODULE, 634 + }; 635 + 636 + static void __maybe_unused mvebu_pwm_suspend(struct mvebu_gpio_chip *mvchip) 637 + { 638 + struct mvebu_pwm *mvpwm = mvchip->mvpwm; 639 + 640 + mvpwm->blink_select = 641 + readl_relaxed(mvebu_gpioreg_blink_counter_select(mvchip)); 642 + mvpwm->blink_on_duration = 643 + readl_relaxed(mvebu_pwmreg_blink_on_duration(mvpwm)); 644 + mvpwm->blink_off_duration = 645 + readl_relaxed(mvebu_pwmreg_blink_off_duration(mvpwm)); 646 + } 647 + 648 + static void __maybe_unused mvebu_pwm_resume(struct mvebu_gpio_chip *mvchip) 649 + { 650 + struct mvebu_pwm *mvpwm = mvchip->mvpwm; 651 + 652 + writel_relaxed(mvpwm->blink_select, 653 + mvebu_gpioreg_blink_counter_select(mvchip)); 654 + writel_relaxed(mvpwm->blink_on_duration, 655 + mvebu_pwmreg_blink_on_duration(mvpwm)); 656 + writel_relaxed(mvpwm->blink_off_duration, 657 + mvebu_pwmreg_blink_off_duration(mvpwm)); 658 + } 659 + 660 + static int mvebu_pwm_probe(struct platform_device *pdev, 661 + struct mvebu_gpio_chip *mvchip, 662 + int id) 663 + { 664 + struct device *dev = &pdev->dev; 665 + struct mvebu_pwm *mvpwm; 666 + struct resource *res; 667 + u32 set; 668 + 669 + if (!of_device_is_compatible(mvchip->chip.of_node, 670 + "marvell,armada-370-xp-gpio")) 671 + return 0; 672 + 673 + if (IS_ERR(mvchip->clk)) 674 + return PTR_ERR(mvchip->clk); 675 + 676 + /* 677 + * There are only two sets of PWM configuration registers for 678 + * all the GPIO lines on those SoCs which this driver reserves 679 + * for the first two GPIO chips. So if the resource is missing 680 + * we can't treat it as an error. 681 + */ 682 + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pwm"); 683 + if (!res) 684 + return 0; 685 + 686 + /* 687 + * Use set A for lines of GPIO chip with id 0, B for GPIO chip 688 + * with id 1. Don't allow further GPIO chips to be used for PWM. 689 + */ 690 + if (id == 0) 691 + set = 0; 692 + else if (id == 1) 693 + set = U32_MAX; 694 + else 695 + return -EINVAL; 696 + writel_relaxed(0, mvebu_gpioreg_blink_counter_select(mvchip)); 697 + 698 + mvpwm = devm_kzalloc(dev, sizeof(struct mvebu_pwm), GFP_KERNEL); 699 + if (!mvpwm) 700 + return -ENOMEM; 701 + mvchip->mvpwm = mvpwm; 702 + mvpwm->mvchip = mvchip; 703 + 704 + mvpwm->membase = devm_ioremap_resource(dev, res); 705 + if (IS_ERR(mvpwm->membase)) 706 + return PTR_ERR(mvpwm->membase); 707 + 708 + mvpwm->clk_rate = clk_get_rate(mvchip->clk); 709 + if (!mvpwm->clk_rate) { 710 + dev_err(dev, "failed to get clock rate\n"); 711 + return -EINVAL; 712 + } 713 + 714 + mvpwm->chip.dev = dev; 715 + mvpwm->chip.ops = &mvebu_pwm_ops; 716 + mvpwm->chip.npwm = mvchip->chip.ngpio; 717 + 718 + spin_lock_init(&mvpwm->lock); 719 + 720 + return pwmchip_add(&mvpwm->chip); 535 721 } 536 722 537 723 #ifdef CONFIG_DEBUG_FS ··· 801 507 if (!label) 802 508 continue; 803 509 804 - msk = 1 << i; 510 + msk = BIT(i); 805 511 is_out = !(io_conf & msk); 806 512 807 513 seq_printf(s, " gpio-%-3d (%-20.20s)", chip->base + i, label); ··· 843 549 { 844 550 .compatible = "marvell,armadaxp-gpio", 845 551 .data = (void *) MVEBU_GPIO_SOC_VARIANT_ARMADAXP, 552 + }, 553 + { 554 + .compatible = "marvell,armada-370-xp-gpio", 555 + .data = (void *) MVEBU_GPIO_SOC_VARIANT_ORION, 846 556 }, 847 557 { 848 558 /* sentinel */ ··· 894 596 BUG(); 895 597 } 896 598 599 + if (IS_ENABLED(CONFIG_PWM)) 600 + mvebu_pwm_suspend(mvchip); 601 + 897 602 return 0; 898 603 } 899 604 ··· 940 639 BUG(); 941 640 } 942 641 642 + if (IS_ENABLED(CONFIG_PWM)) 643 + mvebu_pwm_resume(mvchip); 644 + 943 645 return 0; 944 646 } 945 647 ··· 954 650 struct resource *res; 955 651 struct irq_chip_generic *gc; 956 652 struct irq_chip_type *ct; 957 - struct clk *clk; 958 653 unsigned int ngpios; 959 654 bool have_irqs; 960 655 int soc_variant; ··· 987 684 return id; 988 685 } 989 686 990 - clk = devm_clk_get(&pdev->dev, NULL); 687 + mvchip->clk = devm_clk_get(&pdev->dev, NULL); 991 688 /* Not all SoCs require a clock.*/ 992 - if (!IS_ERR(clk)) 993 - clk_prepare_enable(clk); 689 + if (!IS_ERR(mvchip->clk)) 690 + clk_prepare_enable(mvchip->clk); 994 691 995 692 mvchip->soc_variant = soc_variant; 996 693 mvchip->chip.label = dev_name(&pdev->dev); ··· 1015 712 if (IS_ERR(mvchip->membase)) 1016 713 return PTR_ERR(mvchip->membase); 1017 714 1018 - /* The Armada XP has a second range of registers for the 1019 - * per-CPU registers */ 715 + /* 716 + * The Armada XP has a second range of registers for the 717 + * per-CPU registers 718 + */ 1020 719 if (soc_variant == MVEBU_GPIO_SOC_VARIANT_ARMADAXP) { 1021 720 res = platform_get_resource(pdev, IORESOURCE_MEM, 1); 1022 721 mvchip->percpu_membase = devm_ioremap_resource(&pdev->dev, ··· 1085 780 goto err_domain; 1086 781 } 1087 782 1088 - /* NOTE: The common accessors cannot be used because of the percpu 783 + /* 784 + * NOTE: The common accessors cannot be used because of the percpu 1089 785 * access to the mask registers 1090 786 */ 1091 787 gc = irq_get_domain_generic_chip(mvchip->domain, 0); ··· 1107 801 ct->handler = handle_edge_irq; 1108 802 ct->chip.name = mvchip->chip.label; 1109 803 1110 - /* Setup the interrupt handlers. Each chip can have up to 4 804 + /* 805 + * Setup the interrupt handlers. Each chip can have up to 4 1111 806 * interrupt handlers, with each handler dealing with 8 GPIO 1112 807 * pins. 1113 808 */ ··· 1120 813 irq_set_chained_handler_and_data(irq, mvebu_gpio_irq_handler, 1121 814 mvchip); 1122 815 } 816 + 817 + /* Armada 370/XP has simple PWM support for GPIO lines */ 818 + if (IS_ENABLED(CONFIG_PWM)) 819 + return mvebu_pwm_probe(pdev, mvchip, id); 1123 820 1124 821 return 0; 1125 822
+2 -4
drivers/gpio/gpio-mxc.c
··· 471 471 if (err) 472 472 goto out_bgio; 473 473 474 - irq_base = irq_alloc_descs(-1, 0, 32, numa_node_id()); 474 + irq_base = devm_irq_alloc_descs(&pdev->dev, -1, 0, 32, numa_node_id()); 475 475 if (irq_base < 0) { 476 476 err = irq_base; 477 477 goto out_bgio; ··· 481 481 &irq_domain_simple_ops, NULL); 482 482 if (!port->domain) { 483 483 err = -ENODEV; 484 - goto out_irqdesc_free; 484 + goto out_bgio; 485 485 } 486 486 487 487 /* gpio-mxc can be a generic irq chip */ ··· 495 495 496 496 out_irqdomain_remove: 497 497 irq_domain_remove(port->domain); 498 - out_irqdesc_free: 499 - irq_free_descs(irq_base, 32); 500 498 out_bgio: 501 499 dev_info(&pdev->dev, "%s failed with errno %d\n", __func__, err); 502 500 return err;
+2 -4
drivers/gpio/gpio-mxs.c
··· 328 328 /* clear address has to be used to clear IRQSTAT bits */ 329 329 writel(~0U, port->base + PINCTRL_IRQSTAT(port) + MXS_CLR); 330 330 331 - irq_base = irq_alloc_descs(-1, 0, 32, numa_node_id()); 331 + irq_base = devm_irq_alloc_descs(&pdev->dev, -1, 0, 32, numa_node_id()); 332 332 if (irq_base < 0) { 333 333 err = irq_base; 334 334 goto out_iounmap; ··· 338 338 &irq_domain_simple_ops, NULL); 339 339 if (!port->domain) { 340 340 err = -ENODEV; 341 - goto out_irqdesc_free; 341 + goto out_iounmap; 342 342 } 343 343 344 344 /* gpio-mxs can be a generic irq chip */ ··· 370 370 371 371 out_irqdomain_remove: 372 372 irq_domain_remove(port->domain); 373 - out_irqdesc_free: 374 - irq_free_descs(irq_base, 32); 375 373 out_iounmap: 376 374 iounmap(port->base); 377 375 return err;
+19 -7
drivers/gpio/gpio-omap.c
··· 208 208 * OMAP's debounce time is in 31us steps 209 209 * <debounce time> = (GPIO_DEBOUNCINGTIME[7:0].DEBOUNCETIME + 1) x 31 210 210 * so we need to convert and round up to the closest unit. 211 + * 212 + * Return: 0 on success, negative error otherwise. 211 213 */ 212 - static void omap2_set_gpio_debounce(struct gpio_bank *bank, unsigned offset, 213 - unsigned debounce) 214 + static int omap2_set_gpio_debounce(struct gpio_bank *bank, unsigned offset, 215 + unsigned debounce) 214 216 { 215 217 void __iomem *reg; 216 218 u32 val; ··· 220 218 bool enable = !!debounce; 221 219 222 220 if (!bank->dbck_flag) 223 - return; 221 + return -ENOTSUPP; 224 222 225 223 if (enable) { 226 224 debounce = DIV_ROUND_UP(debounce, 31) - 1; 227 - debounce &= OMAP4_GPIO_DEBOUNCINGTIME_MASK; 225 + if ((debounce & OMAP4_GPIO_DEBOUNCINGTIME_MASK) != debounce) 226 + return -EINVAL; 228 227 } 229 228 230 229 l = BIT(offset); ··· 258 255 bank->context.debounce = debounce; 259 256 bank->context.debounce_en = val; 260 257 } 258 + 259 + return 0; 261 260 } 262 261 263 262 /** ··· 969 964 { 970 965 struct gpio_bank *bank; 971 966 unsigned long flags; 967 + int ret; 972 968 973 969 bank = gpiochip_get_data(chip); 974 970 975 971 raw_spin_lock_irqsave(&bank->lock, flags); 976 - omap2_set_gpio_debounce(bank, offset, debounce); 972 + ret = omap2_set_gpio_debounce(bank, offset, debounce); 977 973 raw_spin_unlock_irqrestore(&bank->lock, flags); 978 974 979 - return 0; 975 + if (ret) 976 + dev_info(chip->parent, 977 + "Could not set line %u debounce to %u microseconds (%d)", 978 + offset, debounce, ret); 979 + 980 + return ret; 980 981 } 981 982 982 983 static int omap_gpio_set_config(struct gpio_chip *chip, unsigned offset, ··· 1096 1085 * REVISIT: Once we have OMAP1 supporting SPARSE_IRQ, we can drop 1097 1086 * irq_alloc_descs() since a base IRQ offset will no longer be needed. 1098 1087 */ 1099 - irq_base = irq_alloc_descs(-1, 0, bank->width, 0); 1088 + irq_base = devm_irq_alloc_descs(bank->chip.parent, 1089 + -1, 0, bank->width, 0); 1100 1090 if (irq_base < 0) { 1101 1091 dev_err(bank->chip.parent, "Couldn't allocate IRQ numbers\n"); 1102 1092 return -ENODEV;
+32 -8
drivers/gpio/gpio-pca953x.c
··· 11 11 * the Free Software Foundation; version 2 of the License. 12 12 */ 13 13 14 - #include <linux/module.h> 15 - #include <linux/init.h> 14 + #include <linux/acpi.h> 16 15 #include <linux/gpio.h> 17 16 #include <linux/gpio/consumer.h> 18 - #include <linux/interrupt.h> 19 17 #include <linux/i2c.h> 20 - #include <linux/platform_data/pca953x.h> 21 - #include <linux/slab.h> 22 - #include <asm/unaligned.h> 18 + #include <linux/init.h> 19 + #include <linux/interrupt.h> 20 + #include <linux/module.h> 23 21 #include <linux/of_platform.h> 24 - #include <linux/acpi.h> 22 + #include <linux/platform_data/pca953x.h> 25 23 #include <linux/regulator/consumer.h> 24 + #include <linux/slab.h> 25 + 26 + #include <asm/unaligned.h> 26 27 27 28 #define PCA953X_INPUT 0 28 29 #define PCA953X_OUTPUT 1 ··· 82 81 { "tca6416", 16 | PCA953X_TYPE | PCA_INT, }, 83 82 { "tca6424", 24 | PCA953X_TYPE | PCA_INT, }, 84 83 { "tca9539", 16 | PCA953X_TYPE | PCA_INT, }, 84 + { "tca9554", 8 | PCA953X_TYPE | PCA_INT, }, 85 85 { "xra1202", 8 | PCA953X_TYPE }, 86 86 { } 87 87 }; ··· 365 363 mutex_unlock(&chip->i2c_lock); 366 364 } 367 365 366 + static int pca953x_gpio_get_direction(struct gpio_chip *gc, unsigned off) 367 + { 368 + struct pca953x_chip *chip = gpiochip_get_data(gc); 369 + u32 reg_val; 370 + int ret; 371 + 372 + mutex_lock(&chip->i2c_lock); 373 + ret = pca953x_read_single(chip, chip->regs->direction, &reg_val, off); 374 + mutex_unlock(&chip->i2c_lock); 375 + if (ret < 0) 376 + return ret; 377 + 378 + return !!(reg_val & (1u << (off % BANK_SZ))); 379 + } 380 + 368 381 static void pca953x_gpio_set_multiple(struct gpio_chip *gc, 369 382 unsigned long *mask, unsigned long *bits) 370 383 { ··· 425 408 gc->direction_output = pca953x_gpio_direction_output; 426 409 gc->get = pca953x_gpio_get_value; 427 410 gc->set = pca953x_gpio_set_value; 411 + gc->get_direction = pca953x_gpio_get_direction; 428 412 gc->set_multiple = pca953x_gpio_set_multiple; 429 413 gc->can_sleep = true; 430 414 ··· 778 760 chip->gpio_start = -1; 779 761 irq_base = 0; 780 762 781 - /* See if we need to de-assert a reset pin */ 763 + /* 764 + * See if we need to de-assert a reset pin. 765 + * 766 + * There is no known ACPI-enabled platforms that are 767 + * using "reset" GPIO. Otherwise any of those platform 768 + * must use _DSD method with corresponding property. 769 + */ 782 770 reset_gpio = devm_gpiod_get_optional(&client->dev, "reset", 783 771 GPIOD_OUT_LOW); 784 772 if (IS_ERR(reset_gpio))
-2
drivers/gpio/gpio-pcf857x.c
··· 46 46 { "pca9675", 16 }, 47 47 { "max7328", 8 }, 48 48 { "max7329", 8 }, 49 - { "tca9554", 8 }, 50 49 { } 51 50 }; 52 51 MODULE_DEVICE_TABLE(i2c, pcf857x_id); ··· 65 66 { .compatible = "nxp,pca9675" }, 66 67 { .compatible = "maxim,max7328" }, 67 68 { .compatible = "maxim,max7329" }, 68 - { .compatible = "ti,tca9554" }, 69 69 { } 70 70 }; 71 71 MODULE_DEVICE_TABLE(of, pcf857x_of_table);
+4 -10
drivers/gpio/gpio-pch.c
··· 403 403 goto err_gpiochip_add; 404 404 } 405 405 406 - irq_base = irq_alloc_descs(-1, 0, gpio_pins[chip->ioh], NUMA_NO_NODE); 406 + irq_base = devm_irq_alloc_descs(&pdev->dev, -1, 0, 407 + gpio_pins[chip->ioh], NUMA_NO_NODE); 407 408 if (irq_base < 0) { 408 409 dev_warn(&pdev->dev, "PCH gpio: Failed to get IRQ base num\n"); 409 410 chip->irq_base = -1; ··· 417 416 iowrite32(msk, &chip->reg->imask); 418 417 iowrite32(msk, &chip->reg->ien); 419 418 420 - ret = request_irq(pdev->irq, pch_gpio_handler, 421 - IRQF_SHARED, KBUILD_MODNAME, chip); 419 + ret = devm_request_irq(&pdev->dev, pdev->irq, pch_gpio_handler, 420 + IRQF_SHARED, KBUILD_MODNAME, chip); 422 421 if (ret != 0) { 423 422 dev_err(&pdev->dev, 424 423 "%s request_irq failed\n", __func__); ··· 431 430 return 0; 432 431 433 432 err_request_irq: 434 - irq_free_descs(irq_base, gpio_pins[chip->ioh]); 435 433 gpiochip_remove(&chip->gpio); 436 434 437 435 err_gpiochip_add: ··· 451 451 static void pch_gpio_remove(struct pci_dev *pdev) 452 452 { 453 453 struct pch_gpio *chip = pci_get_drvdata(pdev); 454 - 455 - if (chip->irq_base != -1) { 456 - free_irq(pdev->irq, chip); 457 - 458 - irq_free_descs(chip->irq_base, gpio_pins[chip->ioh]); 459 - } 460 454 461 455 gpiochip_remove(&chip->gpio); 462 456 pci_iounmap(pdev, chip->base);
+14 -14
drivers/gpio/gpio-pci-idio-16.c
··· 59 59 */ 60 60 struct idio_16_gpio { 61 61 struct gpio_chip chip; 62 - spinlock_t lock; 62 + raw_spinlock_t lock; 63 63 struct idio_16_gpio_reg __iomem *reg; 64 64 unsigned long irq_mask; 65 65 }; ··· 121 121 } else 122 122 base = &idio16gpio->reg->out0_7; 123 123 124 - spin_lock_irqsave(&idio16gpio->lock, flags); 124 + raw_spin_lock_irqsave(&idio16gpio->lock, flags); 125 125 126 126 if (value) 127 127 out_state = ioread8(base) | mask; ··· 130 130 131 131 iowrite8(out_state, base); 132 132 133 - spin_unlock_irqrestore(&idio16gpio->lock, flags); 133 + raw_spin_unlock_irqrestore(&idio16gpio->lock, flags); 134 134 } 135 135 136 136 static void idio_16_gpio_set_multiple(struct gpio_chip *chip, ··· 140 140 unsigned long flags; 141 141 unsigned int out_state; 142 142 143 - spin_lock_irqsave(&idio16gpio->lock, flags); 143 + raw_spin_lock_irqsave(&idio16gpio->lock, flags); 144 144 145 145 /* process output lines 0-7 */ 146 146 if (*mask & 0xFF) { ··· 160 160 iowrite8(out_state, &idio16gpio->reg->out8_15); 161 161 } 162 162 163 - spin_unlock_irqrestore(&idio16gpio->lock, flags); 163 + raw_spin_unlock_irqrestore(&idio16gpio->lock, flags); 164 164 } 165 165 166 166 static void idio_16_irq_ack(struct irq_data *data) ··· 177 177 idio16gpio->irq_mask &= ~mask; 178 178 179 179 if (!idio16gpio->irq_mask) { 180 - spin_lock_irqsave(&idio16gpio->lock, flags); 180 + raw_spin_lock_irqsave(&idio16gpio->lock, flags); 181 181 182 182 iowrite8(0, &idio16gpio->reg->irq_ctl); 183 183 184 - spin_unlock_irqrestore(&idio16gpio->lock, flags); 184 + raw_spin_unlock_irqrestore(&idio16gpio->lock, flags); 185 185 } 186 186 } 187 187 ··· 196 196 idio16gpio->irq_mask |= mask; 197 197 198 198 if (!prev_irq_mask) { 199 - spin_lock_irqsave(&idio16gpio->lock, flags); 199 + raw_spin_lock_irqsave(&idio16gpio->lock, flags); 200 200 201 201 ioread8(&idio16gpio->reg->irq_ctl); 202 202 203 - spin_unlock_irqrestore(&idio16gpio->lock, flags); 203 + raw_spin_unlock_irqrestore(&idio16gpio->lock, flags); 204 204 } 205 205 } 206 206 ··· 229 229 struct gpio_chip *const chip = &idio16gpio->chip; 230 230 int gpio; 231 231 232 - spin_lock(&idio16gpio->lock); 232 + raw_spin_lock(&idio16gpio->lock); 233 233 234 234 irq_status = ioread8(&idio16gpio->reg->irq_status); 235 235 236 - spin_unlock(&idio16gpio->lock); 236 + raw_spin_unlock(&idio16gpio->lock); 237 237 238 238 /* Make sure our device generated IRQ */ 239 239 if (!(irq_status & 0x3) || !(irq_status & 0x4)) ··· 242 242 for_each_set_bit(gpio, &idio16gpio->irq_mask, chip->ngpio) 243 243 generic_handle_irq(irq_find_mapping(chip->irqdomain, gpio)); 244 244 245 - spin_lock(&idio16gpio->lock); 245 + raw_spin_lock(&idio16gpio->lock); 246 246 247 247 /* Clear interrupt */ 248 248 iowrite8(0, &idio16gpio->reg->in0_7); 249 249 250 - spin_unlock(&idio16gpio->lock); 250 + raw_spin_unlock(&idio16gpio->lock); 251 251 252 252 return IRQ_HANDLED; 253 253 } ··· 302 302 idio16gpio->chip.set = idio_16_gpio_set; 303 303 idio16gpio->chip.set_multiple = idio_16_gpio_set_multiple; 304 304 305 - spin_lock_init(&idio16gpio->lock); 305 + raw_spin_lock_init(&idio16gpio->lock); 306 306 307 307 err = devm_gpiochip_add_data(dev, &idio16gpio->chip, idio16gpio); 308 308 if (err) {
+14 -14
drivers/gpio/gpio-pl061.c
··· 50 50 #endif 51 51 52 52 struct pl061 { 53 - spinlock_t lock; 53 + raw_spinlock_t lock; 54 54 55 55 void __iomem *base; 56 56 struct gpio_chip gc; ··· 74 74 unsigned long flags; 75 75 unsigned char gpiodir; 76 76 77 - spin_lock_irqsave(&pl061->lock, flags); 77 + raw_spin_lock_irqsave(&pl061->lock, flags); 78 78 gpiodir = readb(pl061->base + GPIODIR); 79 79 gpiodir &= ~(BIT(offset)); 80 80 writeb(gpiodir, pl061->base + GPIODIR); 81 - spin_unlock_irqrestore(&pl061->lock, flags); 81 + raw_spin_unlock_irqrestore(&pl061->lock, flags); 82 82 83 83 return 0; 84 84 } ··· 90 90 unsigned long flags; 91 91 unsigned char gpiodir; 92 92 93 - spin_lock_irqsave(&pl061->lock, flags); 93 + raw_spin_lock_irqsave(&pl061->lock, flags); 94 94 writeb(!!value << offset, pl061->base + (BIT(offset + 2))); 95 95 gpiodir = readb(pl061->base + GPIODIR); 96 96 gpiodir |= BIT(offset); ··· 101 101 * a gpio pin before configuring it in OUT mode. 102 102 */ 103 103 writeb(!!value << offset, pl061->base + (BIT(offset + 2))); 104 - spin_unlock_irqrestore(&pl061->lock, flags); 104 + raw_spin_unlock_irqrestore(&pl061->lock, flags); 105 105 106 106 return 0; 107 107 } ··· 143 143 } 144 144 145 145 146 - spin_lock_irqsave(&pl061->lock, flags); 146 + raw_spin_lock_irqsave(&pl061->lock, flags); 147 147 148 148 gpioiev = readb(pl061->base + GPIOIEV); 149 149 gpiois = readb(pl061->base + GPIOIS); ··· 203 203 writeb(gpioibe, pl061->base + GPIOIBE); 204 204 writeb(gpioiev, pl061->base + GPIOIEV); 205 205 206 - spin_unlock_irqrestore(&pl061->lock, flags); 206 + raw_spin_unlock_irqrestore(&pl061->lock, flags); 207 207 208 208 return 0; 209 209 } ··· 235 235 u8 mask = BIT(irqd_to_hwirq(d) % PL061_GPIO_NR); 236 236 u8 gpioie; 237 237 238 - spin_lock(&pl061->lock); 238 + raw_spin_lock(&pl061->lock); 239 239 gpioie = readb(pl061->base + GPIOIE) & ~mask; 240 240 writeb(gpioie, pl061->base + GPIOIE); 241 - spin_unlock(&pl061->lock); 241 + raw_spin_unlock(&pl061->lock); 242 242 } 243 243 244 244 static void pl061_irq_unmask(struct irq_data *d) ··· 248 248 u8 mask = BIT(irqd_to_hwirq(d) % PL061_GPIO_NR); 249 249 u8 gpioie; 250 250 251 - spin_lock(&pl061->lock); 251 + raw_spin_lock(&pl061->lock); 252 252 gpioie = readb(pl061->base + GPIOIE) | mask; 253 253 writeb(gpioie, pl061->base + GPIOIE); 254 - spin_unlock(&pl061->lock); 254 + raw_spin_unlock(&pl061->lock); 255 255 } 256 256 257 257 /** ··· 268 268 struct pl061 *pl061 = gpiochip_get_data(gc); 269 269 u8 mask = BIT(irqd_to_hwirq(d) % PL061_GPIO_NR); 270 270 271 - spin_lock(&pl061->lock); 271 + raw_spin_lock(&pl061->lock); 272 272 writeb(mask, pl061->base + GPIOIC); 273 - spin_unlock(&pl061->lock); 273 + raw_spin_unlock(&pl061->lock); 274 274 } 275 275 276 276 static int pl061_irq_set_wake(struct irq_data *d, unsigned int state) ··· 304 304 if (IS_ERR(pl061->base)) 305 305 return PTR_ERR(pl061->base); 306 306 307 - spin_lock_init(&pl061->lock); 307 + raw_spin_lock_init(&pl061->lock); 308 308 if (of_property_read_bool(dev->of_node, "gpio-ranges")) { 309 309 pl061->gc.request = gpiochip_generic_request; 310 310 pl061->gc.free = gpiochip_generic_free;
+1 -1
drivers/gpio/gpio-pxa.c
··· 601 601 nr_gpios = gpio_id->gpio_nums; 602 602 pxa_last_gpio = nr_gpios - 1; 603 603 604 - irq_base = irq_alloc_descs(-1, 0, nr_gpios, 0); 604 + irq_base = devm_irq_alloc_descs(&pdev->dev, -1, 0, nr_gpios, 0); 605 605 if (irq_base < 0) { 606 606 dev_err(&pdev->dev, "Failed to allocate IRQ numbers\n"); 607 607 return irq_base;
+185
drivers/gpio/gpio-reg.c
··· 1 + /* 2 + * gpio-reg: single register individually fixed-direction GPIOs 3 + * 4 + * Copyright (C) 2016 Russell King 5 + * 6 + * This software is licensed under the terms of the GNU General Public 7 + * License version 2, as published by the Free Software Foundation, and 8 + * may be copied, distributed, and modified under those terms. 9 + */ 10 + #include <linux/gpio/driver.h> 11 + #include <linux/gpio/gpio-reg.h> 12 + #include <linux/io.h> 13 + #include <linux/slab.h> 14 + #include <linux/spinlock.h> 15 + 16 + struct gpio_reg { 17 + struct gpio_chip gc; 18 + spinlock_t lock; 19 + u32 direction; 20 + u32 out; 21 + void __iomem *reg; 22 + struct irq_domain *irqdomain; 23 + const int *irqs; 24 + }; 25 + 26 + #define to_gpio_reg(x) container_of(x, struct gpio_reg, gc) 27 + 28 + static int gpio_reg_get_direction(struct gpio_chip *gc, unsigned offset) 29 + { 30 + struct gpio_reg *r = to_gpio_reg(gc); 31 + 32 + return r->direction & BIT(offset) ? 1 : 0; 33 + } 34 + 35 + static int gpio_reg_direction_output(struct gpio_chip *gc, unsigned offset, 36 + int value) 37 + { 38 + struct gpio_reg *r = to_gpio_reg(gc); 39 + 40 + if (r->direction & BIT(offset)) 41 + return -ENOTSUPP; 42 + 43 + gc->set(gc, offset, value); 44 + return 0; 45 + } 46 + 47 + static int gpio_reg_direction_input(struct gpio_chip *gc, unsigned offset) 48 + { 49 + struct gpio_reg *r = to_gpio_reg(gc); 50 + 51 + return r->direction & BIT(offset) ? 0 : -ENOTSUPP; 52 + } 53 + 54 + static void gpio_reg_set(struct gpio_chip *gc, unsigned offset, int value) 55 + { 56 + struct gpio_reg *r = to_gpio_reg(gc); 57 + unsigned long flags; 58 + u32 val, mask = BIT(offset); 59 + 60 + spin_lock_irqsave(&r->lock, flags); 61 + val = r->out; 62 + if (value) 63 + val |= mask; 64 + else 65 + val &= ~mask; 66 + r->out = val; 67 + writel_relaxed(val, r->reg); 68 + spin_unlock_irqrestore(&r->lock, flags); 69 + } 70 + 71 + static int gpio_reg_get(struct gpio_chip *gc, unsigned offset) 72 + { 73 + struct gpio_reg *r = to_gpio_reg(gc); 74 + u32 val, mask = BIT(offset); 75 + 76 + if (r->direction & mask) { 77 + /* 78 + * double-read the value, some registers latch after the 79 + * first read. 80 + */ 81 + readl_relaxed(r->reg); 82 + val = readl_relaxed(r->reg); 83 + } else { 84 + val = r->out; 85 + } 86 + return !!(val & mask); 87 + } 88 + 89 + static void gpio_reg_set_multiple(struct gpio_chip *gc, unsigned long *mask, 90 + unsigned long *bits) 91 + { 92 + struct gpio_reg *r = to_gpio_reg(gc); 93 + unsigned long flags; 94 + 95 + spin_lock_irqsave(&r->lock, flags); 96 + r->out = (r->out & ~*mask) | (*bits & *mask); 97 + writel_relaxed(r->out, r->reg); 98 + spin_unlock_irqrestore(&r->lock, flags); 99 + } 100 + 101 + static int gpio_reg_to_irq(struct gpio_chip *gc, unsigned offset) 102 + { 103 + struct gpio_reg *r = to_gpio_reg(gc); 104 + int irq = r->irqs[offset]; 105 + 106 + if (irq >= 0 && r->irqdomain) 107 + irq = irq_find_mapping(r->irqdomain, irq); 108 + 109 + return irq; 110 + } 111 + 112 + /** 113 + * gpio_reg_init - add a fixed in/out register as gpio 114 + * @dev: optional struct device associated with this register 115 + * @base: start gpio number, or -1 to allocate 116 + * @num: number of GPIOs, maximum 32 117 + * @label: GPIO chip label 118 + * @direction: bitmask of fixed direction, one per GPIO signal, 1 = in 119 + * @def_out: initial GPIO output value 120 + * @names: array of %num strings describing each GPIO signal or %NULL 121 + * @irqdom: irq domain or %NULL 122 + * @irqs: array of %num ints describing the interrupt mapping for each 123 + * GPIO signal, or %NULL. If @irqdom is %NULL, then this 124 + * describes the Linux interrupt number, otherwise it describes 125 + * the hardware interrupt number in the specified irq domain. 126 + * 127 + * Add a single-register GPIO device containing up to 32 GPIO signals, 128 + * where each GPIO has a fixed input or output configuration. Only 129 + * input GPIOs are assumed to be readable from the register, and only 130 + * then after a double-read. Output values are assumed not to be 131 + * readable. 132 + */ 133 + struct gpio_chip *gpio_reg_init(struct device *dev, void __iomem *reg, 134 + int base, int num, const char *label, u32 direction, u32 def_out, 135 + const char *const *names, struct irq_domain *irqdom, const int *irqs) 136 + { 137 + struct gpio_reg *r; 138 + int ret; 139 + 140 + if (dev) 141 + r = devm_kzalloc(dev, sizeof(*r), GFP_KERNEL); 142 + else 143 + r = kzalloc(sizeof(*r), GFP_KERNEL); 144 + 145 + if (!r) 146 + return ERR_PTR(-ENOMEM); 147 + 148 + spin_lock_init(&r->lock); 149 + 150 + r->gc.label = label; 151 + r->gc.get_direction = gpio_reg_get_direction; 152 + r->gc.direction_input = gpio_reg_direction_input; 153 + r->gc.direction_output = gpio_reg_direction_output; 154 + r->gc.set = gpio_reg_set; 155 + r->gc.get = gpio_reg_get; 156 + r->gc.set_multiple = gpio_reg_set_multiple; 157 + if (irqs) 158 + r->gc.to_irq = gpio_reg_to_irq; 159 + r->gc.base = base; 160 + r->gc.ngpio = num; 161 + r->gc.names = names; 162 + r->direction = direction; 163 + r->out = def_out; 164 + r->reg = reg; 165 + r->irqs = irqs; 166 + 167 + if (dev) 168 + ret = devm_gpiochip_add_data(dev, &r->gc, r); 169 + else 170 + ret = gpiochip_add_data(&r->gc, r); 171 + 172 + return ret ? ERR_PTR(ret) : &r->gc; 173 + } 174 + 175 + int gpio_reg_resume(struct gpio_chip *gc) 176 + { 177 + struct gpio_reg *r = to_gpio_reg(gc); 178 + unsigned long flags; 179 + 180 + spin_lock_irqsave(&r->lock, flags); 181 + writel_relaxed(r->out, r->reg); 182 + spin_unlock_irqrestore(&r->lock, flags); 183 + 184 + return 0; 185 + }
+140 -78
drivers/gpio/gpio-sa1100.c
··· 12 12 #include <linux/module.h> 13 13 #include <linux/io.h> 14 14 #include <linux/syscore_ops.h> 15 + #include <soc/sa1100/pwer.h> 15 16 #include <mach/hardware.h> 16 17 #include <mach/irqs.h> 17 18 19 + struct sa1100_gpio_chip { 20 + struct gpio_chip chip; 21 + void __iomem *membase; 22 + int irqbase; 23 + u32 irqmask; 24 + u32 irqrising; 25 + u32 irqfalling; 26 + u32 irqwake; 27 + }; 28 + 29 + #define sa1100_gpio_chip(x) container_of(x, struct sa1100_gpio_chip, chip) 30 + 31 + enum { 32 + R_GPLR = 0x00, 33 + R_GPDR = 0x04, 34 + R_GPSR = 0x08, 35 + R_GPCR = 0x0c, 36 + R_GRER = 0x10, 37 + R_GFER = 0x14, 38 + R_GEDR = 0x18, 39 + R_GAFR = 0x1c, 40 + }; 41 + 18 42 static int sa1100_gpio_get(struct gpio_chip *chip, unsigned offset) 19 43 { 20 - return !!(GPLR & GPIO_GPIO(offset)); 44 + return readl_relaxed(sa1100_gpio_chip(chip)->membase + R_GPLR) & 45 + BIT(offset); 21 46 } 22 47 23 48 static void sa1100_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 24 49 { 25 - if (value) 26 - GPSR = GPIO_GPIO(offset); 27 - else 28 - GPCR = GPIO_GPIO(offset); 50 + int reg = value ? R_GPSR : R_GPCR; 51 + 52 + writel_relaxed(BIT(offset), sa1100_gpio_chip(chip)->membase + reg); 53 + } 54 + 55 + static int sa1100_get_direction(struct gpio_chip *chip, unsigned offset) 56 + { 57 + void __iomem *gpdr = sa1100_gpio_chip(chip)->membase + R_GPDR; 58 + 59 + return !(readl_relaxed(gpdr) & BIT(offset)); 29 60 } 30 61 31 62 static int sa1100_direction_input(struct gpio_chip *chip, unsigned offset) 32 63 { 64 + void __iomem *gpdr = sa1100_gpio_chip(chip)->membase + R_GPDR; 33 65 unsigned long flags; 34 66 35 67 local_irq_save(flags); 36 - GPDR &= ~GPIO_GPIO(offset); 68 + writel_relaxed(readl_relaxed(gpdr) & ~BIT(offset), gpdr); 37 69 local_irq_restore(flags); 70 + 38 71 return 0; 39 72 } 40 73 41 74 static int sa1100_direction_output(struct gpio_chip *chip, unsigned offset, int value) 42 75 { 76 + void __iomem *gpdr = sa1100_gpio_chip(chip)->membase + R_GPDR; 43 77 unsigned long flags; 44 78 45 79 local_irq_save(flags); 46 80 sa1100_gpio_set(chip, offset, value); 47 - GPDR |= GPIO_GPIO(offset); 81 + writel_relaxed(readl_relaxed(gpdr) | BIT(offset), gpdr); 48 82 local_irq_restore(flags); 83 + 49 84 return 0; 50 85 } 51 86 52 87 static int sa1100_to_irq(struct gpio_chip *chip, unsigned offset) 53 88 { 54 - return IRQ_GPIO0 + offset; 89 + return sa1100_gpio_chip(chip)->irqbase + offset; 55 90 } 56 91 57 - static struct gpio_chip sa1100_gpio_chip = { 58 - .label = "gpio", 59 - .direction_input = sa1100_direction_input, 60 - .direction_output = sa1100_direction_output, 61 - .set = sa1100_gpio_set, 62 - .get = sa1100_gpio_get, 63 - .to_irq = sa1100_to_irq, 64 - .base = 0, 65 - .ngpio = GPIO_MAX + 1, 92 + static struct sa1100_gpio_chip sa1100_gpio_chip = { 93 + .chip = { 94 + .label = "gpio", 95 + .get_direction = sa1100_get_direction, 96 + .direction_input = sa1100_direction_input, 97 + .direction_output = sa1100_direction_output, 98 + .set = sa1100_gpio_set, 99 + .get = sa1100_gpio_get, 100 + .to_irq = sa1100_to_irq, 101 + .base = 0, 102 + .ngpio = GPIO_MAX + 1, 103 + }, 104 + .membase = (void *)&GPLR, 105 + .irqbase = IRQ_GPIO0, 66 106 }; 67 107 68 108 /* ··· 110 70 * IRQs are generated on Falling-Edge, Rising-Edge, or both. 111 71 * Use this instead of directly setting GRER/GFER. 112 72 */ 113 - static int GPIO_IRQ_rising_edge; 114 - static int GPIO_IRQ_falling_edge; 115 - static int GPIO_IRQ_mask; 73 + static void sa1100_update_edge_regs(struct sa1100_gpio_chip *sgc) 74 + { 75 + void *base = sgc->membase; 76 + u32 grer, gfer; 77 + 78 + grer = sgc->irqrising & sgc->irqmask; 79 + gfer = sgc->irqfalling & sgc->irqmask; 80 + 81 + writel_relaxed(grer, base + R_GRER); 82 + writel_relaxed(gfer, base + R_GFER); 83 + } 116 84 117 85 static int sa1100_gpio_type(struct irq_data *d, unsigned int type) 118 86 { 119 - unsigned int mask; 120 - 121 - mask = BIT(d->hwirq); 87 + struct sa1100_gpio_chip *sgc = irq_data_get_irq_chip_data(d); 88 + unsigned int mask = BIT(d->hwirq); 122 89 123 90 if (type == IRQ_TYPE_PROBE) { 124 - if ((GPIO_IRQ_rising_edge | GPIO_IRQ_falling_edge) & mask) 91 + if ((sgc->irqrising | sgc->irqfalling) & mask) 125 92 return 0; 126 93 type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING; 127 94 } 128 95 129 96 if (type & IRQ_TYPE_EDGE_RISING) 130 - GPIO_IRQ_rising_edge |= mask; 97 + sgc->irqrising |= mask; 131 98 else 132 - GPIO_IRQ_rising_edge &= ~mask; 99 + sgc->irqrising &= ~mask; 133 100 if (type & IRQ_TYPE_EDGE_FALLING) 134 - GPIO_IRQ_falling_edge |= mask; 101 + sgc->irqfalling |= mask; 135 102 else 136 - GPIO_IRQ_falling_edge &= ~mask; 103 + sgc->irqfalling &= ~mask; 137 104 138 - GRER = GPIO_IRQ_rising_edge & GPIO_IRQ_mask; 139 - GFER = GPIO_IRQ_falling_edge & GPIO_IRQ_mask; 105 + sa1100_update_edge_regs(sgc); 140 106 141 107 return 0; 142 108 } ··· 152 106 */ 153 107 static void sa1100_gpio_ack(struct irq_data *d) 154 108 { 155 - GEDR = BIT(d->hwirq); 109 + struct sa1100_gpio_chip *sgc = irq_data_get_irq_chip_data(d); 110 + 111 + writel_relaxed(BIT(d->hwirq), sgc->membase + R_GEDR); 156 112 } 157 113 158 114 static void sa1100_gpio_mask(struct irq_data *d) 159 115 { 116 + struct sa1100_gpio_chip *sgc = irq_data_get_irq_chip_data(d); 160 117 unsigned int mask = BIT(d->hwirq); 161 118 162 - GPIO_IRQ_mask &= ~mask; 119 + sgc->irqmask &= ~mask; 163 120 164 - GRER &= ~mask; 165 - GFER &= ~mask; 121 + sa1100_update_edge_regs(sgc); 166 122 } 167 123 168 124 static void sa1100_gpio_unmask(struct irq_data *d) 169 125 { 126 + struct sa1100_gpio_chip *sgc = irq_data_get_irq_chip_data(d); 170 127 unsigned int mask = BIT(d->hwirq); 171 128 172 - GPIO_IRQ_mask |= mask; 129 + sgc->irqmask |= mask; 173 130 174 - GRER = GPIO_IRQ_rising_edge & GPIO_IRQ_mask; 175 - GFER = GPIO_IRQ_falling_edge & GPIO_IRQ_mask; 131 + sa1100_update_edge_regs(sgc); 176 132 } 177 133 178 134 static int sa1100_gpio_wake(struct irq_data *d, unsigned int on) 179 135 { 180 - if (on) 181 - PWER |= BIT(d->hwirq); 182 - else 183 - PWER &= ~BIT(d->hwirq); 184 - return 0; 136 + struct sa1100_gpio_chip *sgc = irq_data_get_irq_chip_data(d); 137 + int ret = sa11x0_gpio_set_wake(d->hwirq, on); 138 + if (!ret) { 139 + if (on) 140 + sgc->irqwake |= BIT(d->hwirq); 141 + else 142 + sgc->irqwake &= ~BIT(d->hwirq); 143 + } 144 + return ret; 185 145 } 186 146 187 147 /* ··· 205 153 static int sa1100_gpio_irqdomain_map(struct irq_domain *d, 206 154 unsigned int irq, irq_hw_number_t hwirq) 207 155 { 208 - irq_set_chip_and_handler(irq, &sa1100_gpio_irq_chip, 209 - handle_edge_irq); 156 + struct sa1100_gpio_chip *sgc = d->host_data; 157 + 158 + irq_set_chip_data(irq, sgc); 159 + irq_set_chip_and_handler(irq, &sa1100_gpio_irq_chip, handle_edge_irq); 210 160 irq_set_probe(irq); 211 161 212 162 return 0; ··· 228 174 */ 229 175 static void sa1100_gpio_handler(struct irq_desc *desc) 230 176 { 177 + struct sa1100_gpio_chip *sgc = irq_desc_get_handler_data(desc); 231 178 unsigned int irq, mask; 179 + void __iomem *gedr = sgc->membase + R_GEDR; 232 180 233 - mask = GEDR; 181 + mask = readl_relaxed(gedr); 234 182 do { 235 183 /* 236 184 * clear down all currently active IRQ sources. 237 185 * We will be processing them all. 238 186 */ 239 - GEDR = mask; 187 + writel_relaxed(mask, gedr); 240 188 241 - irq = IRQ_GPIO0; 189 + irq = sgc->irqbase; 242 190 do { 243 191 if (mask & 1) 244 192 generic_handle_irq(irq); ··· 248 192 irq++; 249 193 } while (mask); 250 194 251 - mask = GEDR; 195 + mask = readl_relaxed(gedr); 252 196 } while (mask); 253 197 } 254 198 255 199 static int sa1100_gpio_suspend(void) 256 200 { 201 + struct sa1100_gpio_chip *sgc = &sa1100_gpio_chip; 202 + 257 203 /* 258 204 * Set the appropriate edges for wakeup. 259 205 */ 260 - GRER = PWER & GPIO_IRQ_rising_edge; 261 - GFER = PWER & GPIO_IRQ_falling_edge; 206 + writel_relaxed(sgc->irqwake & sgc->irqrising, sgc->membase + R_GRER); 207 + writel_relaxed(sgc->irqwake & sgc->irqfalling, sgc->membase + R_GFER); 262 208 263 209 /* 264 210 * Clear any pending GPIO interrupts. 265 211 */ 266 - GEDR = GEDR; 212 + writel_relaxed(readl_relaxed(sgc->membase + R_GEDR), 213 + sgc->membase + R_GEDR); 267 214 268 215 return 0; 269 216 } 270 217 271 218 static void sa1100_gpio_resume(void) 272 219 { 273 - GRER = GPIO_IRQ_rising_edge & GPIO_IRQ_mask; 274 - GFER = GPIO_IRQ_falling_edge & GPIO_IRQ_mask; 220 + sa1100_update_edge_regs(&sa1100_gpio_chip); 275 221 } 276 222 277 223 static struct syscore_ops sa1100_gpio_syscore_ops = { ··· 289 231 290 232 device_initcall(sa1100_gpio_init_devicefs); 291 233 234 + static const int sa1100_gpio_irqs[] __initconst = { 235 + /* Install handlers for GPIO 0-10 edge detect interrupts */ 236 + IRQ_GPIO0_SC, 237 + IRQ_GPIO1_SC, 238 + IRQ_GPIO2_SC, 239 + IRQ_GPIO3_SC, 240 + IRQ_GPIO4_SC, 241 + IRQ_GPIO5_SC, 242 + IRQ_GPIO6_SC, 243 + IRQ_GPIO7_SC, 244 + IRQ_GPIO8_SC, 245 + IRQ_GPIO9_SC, 246 + IRQ_GPIO10_SC, 247 + /* Install handler for GPIO 11-27 edge detect interrupts */ 248 + IRQ_GPIO11_27, 249 + }; 250 + 292 251 void __init sa1100_init_gpio(void) 293 252 { 294 - /* clear all GPIO edge detects */ 295 - GFER = 0; 296 - GRER = 0; 297 - GEDR = -1; 253 + struct sa1100_gpio_chip *sgc = &sa1100_gpio_chip; 254 + int i; 298 255 299 - gpiochip_add_data(&sa1100_gpio_chip, NULL); 256 + /* clear all GPIO edge detects */ 257 + writel_relaxed(0, sgc->membase + R_GFER); 258 + writel_relaxed(0, sgc->membase + R_GRER); 259 + writel_relaxed(-1, sgc->membase + R_GEDR); 260 + 261 + gpiochip_add_data(&sa1100_gpio_chip.chip, NULL); 300 262 301 263 sa1100_gpio_irqdomain = irq_domain_add_simple(NULL, 302 264 28, IRQ_GPIO0, 303 - &sa1100_gpio_irqdomain_ops, NULL); 265 + &sa1100_gpio_irqdomain_ops, sgc); 304 266 305 - /* 306 - * Install handlers for GPIO 0-10 edge detect interrupts 307 - */ 308 - irq_set_chained_handler(IRQ_GPIO0_SC, sa1100_gpio_handler); 309 - irq_set_chained_handler(IRQ_GPIO1_SC, sa1100_gpio_handler); 310 - irq_set_chained_handler(IRQ_GPIO2_SC, sa1100_gpio_handler); 311 - irq_set_chained_handler(IRQ_GPIO3_SC, sa1100_gpio_handler); 312 - irq_set_chained_handler(IRQ_GPIO4_SC, sa1100_gpio_handler); 313 - irq_set_chained_handler(IRQ_GPIO5_SC, sa1100_gpio_handler); 314 - irq_set_chained_handler(IRQ_GPIO6_SC, sa1100_gpio_handler); 315 - irq_set_chained_handler(IRQ_GPIO7_SC, sa1100_gpio_handler); 316 - irq_set_chained_handler(IRQ_GPIO8_SC, sa1100_gpio_handler); 317 - irq_set_chained_handler(IRQ_GPIO9_SC, sa1100_gpio_handler); 318 - irq_set_chained_handler(IRQ_GPIO10_SC, sa1100_gpio_handler); 319 - /* 320 - * Install handler for GPIO 11-27 edge detect interrupts 321 - */ 322 - irq_set_chained_handler(IRQ_GPIO11_27, sa1100_gpio_handler); 323 - 267 + for (i = 0; i < ARRAY_SIZE(sa1100_gpio_irqs); i++) 268 + irq_set_chained_handler_and_data(sa1100_gpio_irqs[i], 269 + sa1100_gpio_handler, sgc); 324 270 }
+11 -17
drivers/gpio/gpio-sodaville.c
··· 135 135 struct irq_chip_type *ct; 136 136 int ret; 137 137 138 - sd->irq_base = irq_alloc_descs(-1, 0, SDV_NUM_PUB_GPIOS, -1); 138 + sd->irq_base = devm_irq_alloc_descs(&pdev->dev, -1, 0, 139 + SDV_NUM_PUB_GPIOS, -1); 139 140 if (sd->irq_base < 0) 140 141 return sd->irq_base; 141 142 ··· 144 143 writel(0, sd->gpio_pub_base + GPIO_INT); 145 144 writel((1 << 11) - 1, sd->gpio_pub_base + GPSTR); 146 145 147 - ret = request_irq(pdev->irq, sdv_gpio_pub_irq_handler, IRQF_SHARED, 148 - "sdv_gpio", sd); 146 + ret = devm_request_irq(&pdev->dev, pdev->irq, 147 + sdv_gpio_pub_irq_handler, IRQF_SHARED, 148 + "sdv_gpio", sd); 149 149 if (ret) 150 - goto out_free_desc; 150 + return ret; 151 151 152 152 /* 153 153 * This gpio irq controller latches level irqs. Testing shows that if ··· 157 155 */ 158 156 sd->gc = irq_alloc_generic_chip("sdv-gpio", 1, sd->irq_base, 159 157 sd->gpio_pub_base, handle_fasteoi_irq); 160 - if (!sd->gc) { 161 - ret = -ENOMEM; 162 - goto out_free_irq; 163 - } 158 + if (!sd->gc) 159 + return -ENOMEM; 164 160 165 161 sd->gc->private = sd; 166 162 ct = sd->gc->chip_types; ··· 176 176 177 177 sd->id = irq_domain_add_legacy(pdev->dev.of_node, SDV_NUM_PUB_GPIOS, 178 178 sd->irq_base, 0, &irq_domain_sdv_ops, sd); 179 - if (!sd->id) { 180 - ret = -ENODEV; 181 - goto out_free_irq; 182 - } 179 + if (!sd->id) 180 + return -ENODEV; 181 + 183 182 return 0; 184 - out_free_irq: 185 - free_irq(pdev->irq, sd); 186 - out_free_desc: 187 - irq_free_descs(sd->irq_base, SDV_NUM_PUB_GPIOS); 188 - return ret; 189 183 } 190 184 191 185 static int sdv_gpio_probe(struct pci_dev *pdev,
+6 -11
drivers/gpio/gpio-sta2x11.c
··· 392 392 gsta_set_config(chip, i, gpio_pdata->pinconfig[i]); 393 393 394 394 /* 384 was used in previous code: be compatible for other drivers */ 395 - err = irq_alloc_descs(-1, 384, GSTA_NR_GPIO, NUMA_NO_NODE); 395 + err = devm_irq_alloc_descs(&dev->dev, -1, 384, 396 + GSTA_NR_GPIO, NUMA_NO_NODE); 396 397 if (err < 0) { 397 398 dev_warn(&dev->dev, "sta2x11 gpio: Can't get irq base (%i)\n", 398 399 -err); ··· 402 401 chip->irq_base = err; 403 402 gsta_alloc_irq_chip(chip); 404 403 405 - err = request_irq(pdev->irq, gsta_gpio_handler, 406 - IRQF_SHARED, KBUILD_MODNAME, chip); 404 + err = devm_request_irq(&dev->dev, pdev->irq, gsta_gpio_handler, 405 + IRQF_SHARED, KBUILD_MODNAME, chip); 407 406 if (err < 0) { 408 407 dev_err(&dev->dev, "sta2x11 gpio: Can't request irq (%i)\n", 409 408 -err); 410 - goto err_free_descs; 409 + return err; 411 410 } 412 411 413 412 err = devm_gpiochip_add_data(&dev->dev, &chip->gpio, chip); 414 413 if (err < 0) { 415 414 dev_err(&dev->dev, "sta2x11 gpio: Can't register (%i)\n", 416 415 -err); 417 - goto err_free_irq; 416 + return err; 418 417 } 419 418 420 419 platform_set_drvdata(dev, chip); 421 420 return 0; 422 - 423 - err_free_irq: 424 - free_irq(pdev->irq, chip); 425 - err_free_descs: 426 - irq_free_descs(chip->irq_base, GSTA_NR_GPIO); 427 - return err; 428 421 } 429 422 430 423 static struct platform_driver sta2x11_gpio_platform_driver = {
+2 -1
drivers/gpio/gpio-twl4030.c
··· 485 485 goto no_irqs; 486 486 } 487 487 488 - irq_base = irq_alloc_descs(-1, 0, TWL4030_GPIO_MAX, 0); 488 + irq_base = devm_irq_alloc_descs(&pdev->dev, -1, 489 + 0, TWL4030_GPIO_MAX, 0); 489 490 if (irq_base < 0) { 490 491 dev_err(&pdev->dev, "Failed to alloc irq_descs\n"); 491 492 return irq_base;
+5 -3
drivers/gpio/gpio-wcove.c
··· 51 51 #define GROUP1_NR_IRQS 6 52 52 #define IRQ_MASK_BASE 0x4e19 53 53 #define IRQ_STATUS_BASE 0x4e0b 54 + #define GPIO_IRQ0_MASK GENMASK(6, 0) 55 + #define GPIO_IRQ1_MASK GENMASK(5, 0) 54 56 #define UPDATE_IRQ_TYPE BIT(0) 55 57 #define UPDATE_IRQ_MASK BIT(1) 56 58 ··· 311 309 return IRQ_NONE; 312 310 } 313 311 314 - pending = p[0] | (p[1] << 8); 312 + pending = (p[0] & GPIO_IRQ0_MASK) | ((p[1] & GPIO_IRQ1_MASK) << 7); 315 313 if (!pending) 316 314 return IRQ_NONE; 317 315 ··· 319 317 while (pending) { 320 318 /* One iteration is for all pending bits */ 321 319 for_each_set_bit(gpio, (const unsigned long *)&pending, 322 - GROUP0_NR_IRQS) { 320 + WCOVE_GPIO_NUM) { 323 321 offset = (gpio > GROUP0_NR_IRQS) ? 1 : 0; 324 322 mask = (offset == 1) ? BIT(gpio - GROUP0_NR_IRQS) : 325 323 BIT(gpio); ··· 335 333 break; 336 334 } 337 335 338 - pending = p[0] | (p[1] << 8); 336 + pending = (p[0] & GPIO_IRQ0_MASK) | ((p[1] & GPIO_IRQ1_MASK) << 7); 339 337 } 340 338 341 339 return IRQ_HANDLED;
+23 -23
drivers/gpio/gpio-ws16c48.c
··· 51 51 struct gpio_chip chip; 52 52 unsigned char io_state[6]; 53 53 unsigned char out_state[6]; 54 - spinlock_t lock; 54 + raw_spinlock_t lock; 55 55 unsigned long irq_mask; 56 56 unsigned long flow_mask; 57 57 unsigned base; ··· 73 73 const unsigned mask = BIT(offset % 8); 74 74 unsigned long flags; 75 75 76 - spin_lock_irqsave(&ws16c48gpio->lock, flags); 76 + raw_spin_lock_irqsave(&ws16c48gpio->lock, flags); 77 77 78 78 ws16c48gpio->io_state[port] |= mask; 79 79 ws16c48gpio->out_state[port] &= ~mask; 80 80 outb(ws16c48gpio->out_state[port], ws16c48gpio->base + port); 81 81 82 - spin_unlock_irqrestore(&ws16c48gpio->lock, flags); 82 + raw_spin_unlock_irqrestore(&ws16c48gpio->lock, flags); 83 83 84 84 return 0; 85 85 } ··· 92 92 const unsigned mask = BIT(offset % 8); 93 93 unsigned long flags; 94 94 95 - spin_lock_irqsave(&ws16c48gpio->lock, flags); 95 + raw_spin_lock_irqsave(&ws16c48gpio->lock, flags); 96 96 97 97 ws16c48gpio->io_state[port] &= ~mask; 98 98 if (value) ··· 101 101 ws16c48gpio->out_state[port] &= ~mask; 102 102 outb(ws16c48gpio->out_state[port], ws16c48gpio->base + port); 103 103 104 - spin_unlock_irqrestore(&ws16c48gpio->lock, flags); 104 + raw_spin_unlock_irqrestore(&ws16c48gpio->lock, flags); 105 105 106 106 return 0; 107 107 } ··· 114 114 unsigned long flags; 115 115 unsigned port_state; 116 116 117 - spin_lock_irqsave(&ws16c48gpio->lock, flags); 117 + raw_spin_lock_irqsave(&ws16c48gpio->lock, flags); 118 118 119 119 /* ensure that GPIO is set for input */ 120 120 if (!(ws16c48gpio->io_state[port] & mask)) { 121 - spin_unlock_irqrestore(&ws16c48gpio->lock, flags); 121 + raw_spin_unlock_irqrestore(&ws16c48gpio->lock, flags); 122 122 return -EINVAL; 123 123 } 124 124 125 125 port_state = inb(ws16c48gpio->base + port); 126 126 127 - spin_unlock_irqrestore(&ws16c48gpio->lock, flags); 127 + raw_spin_unlock_irqrestore(&ws16c48gpio->lock, flags); 128 128 129 129 return !!(port_state & mask); 130 130 } ··· 136 136 const unsigned mask = BIT(offset % 8); 137 137 unsigned long flags; 138 138 139 - spin_lock_irqsave(&ws16c48gpio->lock, flags); 139 + raw_spin_lock_irqsave(&ws16c48gpio->lock, flags); 140 140 141 141 /* ensure that GPIO is set for output */ 142 142 if (ws16c48gpio->io_state[port] & mask) { 143 - spin_unlock_irqrestore(&ws16c48gpio->lock, flags); 143 + raw_spin_unlock_irqrestore(&ws16c48gpio->lock, flags); 144 144 return; 145 145 } 146 146 ··· 150 150 ws16c48gpio->out_state[port] &= ~mask; 151 151 outb(ws16c48gpio->out_state[port], ws16c48gpio->base + port); 152 152 153 - spin_unlock_irqrestore(&ws16c48gpio->lock, flags); 153 + raw_spin_unlock_irqrestore(&ws16c48gpio->lock, flags); 154 154 } 155 155 156 156 static void ws16c48_gpio_set_multiple(struct gpio_chip *chip, ··· 178 178 iomask = mask[BIT_WORD(i)] & ~ws16c48gpio->io_state[port]; 179 179 bitmask = iomask & bits[BIT_WORD(i)]; 180 180 181 - spin_lock_irqsave(&ws16c48gpio->lock, flags); 181 + raw_spin_lock_irqsave(&ws16c48gpio->lock, flags); 182 182 183 183 /* update output state data and set device gpio register */ 184 184 ws16c48gpio->out_state[port] &= ~iomask; 185 185 ws16c48gpio->out_state[port] |= bitmask; 186 186 outb(ws16c48gpio->out_state[port], ws16c48gpio->base + port); 187 187 188 - spin_unlock_irqrestore(&ws16c48gpio->lock, flags); 188 + raw_spin_unlock_irqrestore(&ws16c48gpio->lock, flags); 189 189 190 190 /* prepare for next gpio register set */ 191 191 mask[BIT_WORD(i)] >>= gpio_reg_size; ··· 207 207 if (port > 2) 208 208 return; 209 209 210 - spin_lock_irqsave(&ws16c48gpio->lock, flags); 210 + raw_spin_lock_irqsave(&ws16c48gpio->lock, flags); 211 211 212 212 port_state = ws16c48gpio->irq_mask >> (8*port); 213 213 ··· 216 216 outb(port_state | mask, ws16c48gpio->base + 8 + port); 217 217 outb(0xC0, ws16c48gpio->base + 7); 218 218 219 - spin_unlock_irqrestore(&ws16c48gpio->lock, flags); 219 + raw_spin_unlock_irqrestore(&ws16c48gpio->lock, flags); 220 220 } 221 221 222 222 static void ws16c48_irq_mask(struct irq_data *data) ··· 232 232 if (port > 2) 233 233 return; 234 234 235 - spin_lock_irqsave(&ws16c48gpio->lock, flags); 235 + raw_spin_lock_irqsave(&ws16c48gpio->lock, flags); 236 236 237 237 ws16c48gpio->irq_mask &= ~mask; 238 238 ··· 240 240 outb(ws16c48gpio->irq_mask >> (8*port), ws16c48gpio->base + 8 + port); 241 241 outb(0xC0, ws16c48gpio->base + 7); 242 242 243 - spin_unlock_irqrestore(&ws16c48gpio->lock, flags); 243 + raw_spin_unlock_irqrestore(&ws16c48gpio->lock, flags); 244 244 } 245 245 246 246 static void ws16c48_irq_unmask(struct irq_data *data) ··· 256 256 if (port > 2) 257 257 return; 258 258 259 - spin_lock_irqsave(&ws16c48gpio->lock, flags); 259 + raw_spin_lock_irqsave(&ws16c48gpio->lock, flags); 260 260 261 261 ws16c48gpio->irq_mask |= mask; 262 262 ··· 264 264 outb(ws16c48gpio->irq_mask >> (8*port), ws16c48gpio->base + 8 + port); 265 265 outb(0xC0, ws16c48gpio->base + 7); 266 266 267 - spin_unlock_irqrestore(&ws16c48gpio->lock, flags); 267 + raw_spin_unlock_irqrestore(&ws16c48gpio->lock, flags); 268 268 } 269 269 270 270 static int ws16c48_irq_set_type(struct irq_data *data, unsigned flow_type) ··· 280 280 if (port > 2) 281 281 return -EINVAL; 282 282 283 - spin_lock_irqsave(&ws16c48gpio->lock, flags); 283 + raw_spin_lock_irqsave(&ws16c48gpio->lock, flags); 284 284 285 285 switch (flow_type) { 286 286 case IRQ_TYPE_NONE: ··· 292 292 ws16c48gpio->flow_mask &= ~mask; 293 293 break; 294 294 default: 295 - spin_unlock_irqrestore(&ws16c48gpio->lock, flags); 295 + raw_spin_unlock_irqrestore(&ws16c48gpio->lock, flags); 296 296 return -EINVAL; 297 297 } 298 298 ··· 300 300 outb(ws16c48gpio->flow_mask >> (8*port), ws16c48gpio->base + 8 + port); 301 301 outb(0xC0, ws16c48gpio->base + 7); 302 302 303 - spin_unlock_irqrestore(&ws16c48gpio->lock, flags); 303 + raw_spin_unlock_irqrestore(&ws16c48gpio->lock, flags); 304 304 305 305 return 0; 306 306 } ··· 387 387 ws16c48gpio->chip.set_multiple = ws16c48_gpio_set_multiple; 388 388 ws16c48gpio->base = base[id]; 389 389 390 - spin_lock_init(&ws16c48gpio->lock); 390 + raw_spin_lock_init(&ws16c48gpio->lock); 391 391 392 392 err = devm_gpiochip_add_data(dev, &ws16c48gpio->chip, ws16c48gpio); 393 393 if (err) {
+5 -4
drivers/gpio/gpio-xlp.c
··· 404 404 405 405 /* XLP(MIPS) has fixed range for GPIO IRQs, Vulcan(ARM64) does not */ 406 406 if (soc_type != GPIO_VARIANT_VULCAN) { 407 - irq_base = irq_alloc_descs(-1, XLP_GPIO_IRQ_BASE, gc->ngpio, 0); 407 + irq_base = devm_irq_alloc_descs(&pdev->dev, -1, 408 + XLP_GPIO_IRQ_BASE, 409 + gc->ngpio, 0); 408 410 if (irq_base < 0) { 409 411 dev_err(&pdev->dev, "Failed to allocate IRQ numbers\n"); 410 412 return irq_base; ··· 417 415 418 416 err = gpiochip_add_data(gc, priv); 419 417 if (err < 0) 420 - goto out_free_desc; 418 + return err; 421 419 422 420 err = gpiochip_irqchip_add(gc, &xlp_gpio_irq_chip, irq_base, 423 421 handle_level_irq, IRQ_TYPE_NONE); ··· 435 433 436 434 out_gpio_remove: 437 435 gpiochip_remove(gc); 438 - out_free_desc: 439 - irq_free_descs(irq_base, gc->ngpio); 440 436 return err; 441 437 } 442 438 443 439 #ifdef CONFIG_ACPI 444 440 static const struct acpi_device_id xlp_gpio_acpi_match[] = { 445 441 { "BRCM9006", GPIO_VARIANT_VULCAN }, 442 + { "CAV9006", GPIO_VARIANT_VULCAN }, 446 443 {}, 447 444 }; 448 445 MODULE_DEVICE_TABLE(acpi, xlp_gpio_acpi_match);
+12 -12
drivers/gpio/gpio-zx.c
··· 41 41 #define ZX_GPIO_NR 16 42 42 43 43 struct zx_gpio { 44 - spinlock_t lock; 44 + raw_spinlock_t lock; 45 45 46 46 void __iomem *base; 47 47 struct gpio_chip gc; ··· 56 56 if (offset >= gc->ngpio) 57 57 return -EINVAL; 58 58 59 - spin_lock_irqsave(&chip->lock, flags); 59 + raw_spin_lock_irqsave(&chip->lock, flags); 60 60 gpiodir = readw_relaxed(chip->base + ZX_GPIO_DIR); 61 61 gpiodir &= ~BIT(offset); 62 62 writew_relaxed(gpiodir, chip->base + ZX_GPIO_DIR); 63 - spin_unlock_irqrestore(&chip->lock, flags); 63 + raw_spin_unlock_irqrestore(&chip->lock, flags); 64 64 65 65 return 0; 66 66 } ··· 75 75 if (offset >= gc->ngpio) 76 76 return -EINVAL; 77 77 78 - spin_lock_irqsave(&chip->lock, flags); 78 + raw_spin_lock_irqsave(&chip->lock, flags); 79 79 gpiodir = readw_relaxed(chip->base + ZX_GPIO_DIR); 80 80 gpiodir |= BIT(offset); 81 81 writew_relaxed(gpiodir, chip->base + ZX_GPIO_DIR); ··· 84 84 writew_relaxed(BIT(offset), chip->base + ZX_GPIO_DO1); 85 85 else 86 86 writew_relaxed(BIT(offset), chip->base + ZX_GPIO_DO0); 87 - spin_unlock_irqrestore(&chip->lock, flags); 87 + raw_spin_unlock_irqrestore(&chip->lock, flags); 88 88 89 89 return 0; 90 90 } ··· 118 118 if (offset < 0 || offset >= ZX_GPIO_NR) 119 119 return -EINVAL; 120 120 121 - spin_lock_irqsave(&chip->lock, flags); 121 + raw_spin_lock_irqsave(&chip->lock, flags); 122 122 123 123 gpioiev = readw_relaxed(chip->base + ZX_GPIO_IV); 124 124 gpiois = readw_relaxed(chip->base + ZX_GPIO_IVE); ··· 151 151 writew_relaxed(gpioi_epos, chip->base + ZX_GPIO_IEP); 152 152 writew_relaxed(gpioi_eneg, chip->base + ZX_GPIO_IEN); 153 153 writew_relaxed(gpioiev, chip->base + ZX_GPIO_IV); 154 - spin_unlock_irqrestore(&chip->lock, flags); 154 + raw_spin_unlock_irqrestore(&chip->lock, flags); 155 155 156 156 return 0; 157 157 } ··· 184 184 u16 mask = BIT(irqd_to_hwirq(d) % ZX_GPIO_NR); 185 185 u16 gpioie; 186 186 187 - spin_lock(&chip->lock); 187 + raw_spin_lock(&chip->lock); 188 188 gpioie = readw_relaxed(chip->base + ZX_GPIO_IM) | mask; 189 189 writew_relaxed(gpioie, chip->base + ZX_GPIO_IM); 190 190 gpioie = readw_relaxed(chip->base + ZX_GPIO_IE) & ~mask; 191 191 writew_relaxed(gpioie, chip->base + ZX_GPIO_IE); 192 - spin_unlock(&chip->lock); 192 + raw_spin_unlock(&chip->lock); 193 193 } 194 194 195 195 static void zx_irq_unmask(struct irq_data *d) ··· 199 199 u16 mask = BIT(irqd_to_hwirq(d) % ZX_GPIO_NR); 200 200 u16 gpioie; 201 201 202 - spin_lock(&chip->lock); 202 + raw_spin_lock(&chip->lock); 203 203 gpioie = readw_relaxed(chip->base + ZX_GPIO_IM) & ~mask; 204 204 writew_relaxed(gpioie, chip->base + ZX_GPIO_IM); 205 205 gpioie = readw_relaxed(chip->base + ZX_GPIO_IE) | mask; 206 206 writew_relaxed(gpioie, chip->base + ZX_GPIO_IE); 207 - spin_unlock(&chip->lock); 207 + raw_spin_unlock(&chip->lock); 208 208 } 209 209 210 210 static struct irq_chip zx_irqchip = { ··· 230 230 if (IS_ERR(chip->base)) 231 231 return PTR_ERR(chip->base); 232 232 233 - spin_lock_init(&chip->lock); 233 + raw_spin_lock_init(&chip->lock); 234 234 if (of_property_read_bool(dev->of_node, "gpio-ranges")) { 235 235 chip->gc.request = gpiochip_generic_request; 236 236 chip->gc.free = gpiochip_generic_free;
+45 -10
drivers/gpio/gpiolib-acpi.c
··· 368 368 } 369 369 EXPORT_SYMBOL_GPL(acpi_dev_add_driver_gpios); 370 370 371 + static void devm_acpi_dev_release_driver_gpios(struct device *dev, void *res) 372 + { 373 + acpi_dev_remove_driver_gpios(ACPI_COMPANION(dev)); 374 + } 375 + 376 + int devm_acpi_dev_add_driver_gpios(struct device *dev, 377 + const struct acpi_gpio_mapping *gpios) 378 + { 379 + void *res; 380 + int ret; 381 + 382 + res = devres_alloc(devm_acpi_dev_release_driver_gpios, 0, GFP_KERNEL); 383 + if (!res) 384 + return -ENOMEM; 385 + 386 + ret = acpi_dev_add_driver_gpios(ACPI_COMPANION(dev), gpios); 387 + if (ret) { 388 + devres_free(res); 389 + return ret; 390 + } 391 + devres_add(dev, res); 392 + return 0; 393 + } 394 + EXPORT_SYMBOL_GPL(devm_acpi_dev_add_driver_gpios); 395 + 396 + void devm_acpi_dev_remove_driver_gpios(struct device *dev) 397 + { 398 + WARN_ON(devres_release(dev, devm_acpi_dev_release_driver_gpios, NULL, NULL)); 399 + } 400 + EXPORT_SYMBOL_GPL(devm_acpi_dev_remove_driver_gpios); 401 + 371 402 static bool acpi_get_driver_gpio_data(struct acpi_device *adev, 372 403 const char *name, int index, 373 404 struct acpi_reference_args *args) ··· 692 661 { 693 662 int idx, i; 694 663 unsigned int irq_flags; 695 - int ret = -ENOENT; 696 664 697 665 for (i = 0, idx = 0; idx <= index; i++) { 698 666 struct acpi_gpio_info info; 699 667 struct gpio_desc *desc; 700 668 701 669 desc = acpi_get_gpiod_by_index(adev, NULL, i, &info); 702 - if (IS_ERR(desc)) { 703 - ret = PTR_ERR(desc); 704 - break; 705 - } 706 - if (info.gpioint && idx++ == index) { 707 - int irq = gpiod_to_irq(desc); 708 670 671 + /* Ignore -EPROBE_DEFER, it only matters if idx matches */ 672 + if (IS_ERR(desc) && PTR_ERR(desc) != -EPROBE_DEFER) 673 + return PTR_ERR(desc); 674 + 675 + if (info.gpioint && idx++ == index) { 676 + int irq; 677 + 678 + if (IS_ERR(desc)) 679 + return PTR_ERR(desc); 680 + 681 + irq = gpiod_to_irq(desc); 709 682 if (irq < 0) 710 683 return irq; 711 684 ··· 725 690 } 726 691 727 692 } 728 - return ret; 693 + return -ENOENT; 729 694 } 730 695 EXPORT_SYMBOL_GPL(acpi_dev_gpio_irq_get); 731 696 ··· 1110 1075 break; 1111 1076 } 1112 1077 } 1113 - if (count >= 0) 1078 + if (count > 0) 1114 1079 break; 1115 1080 } 1116 1081 ··· 1126 1091 if (crs_count > 0) 1127 1092 count = crs_count; 1128 1093 } 1129 - return count; 1094 + return count ? count : -ENOENT; 1130 1095 } 1131 1096 1132 1097 struct acpi_crs_lookup {
+1 -1
drivers/gpio/gpiolib-of.c
··· 147 147 *flags |= GPIO_ACTIVE_LOW; 148 148 149 149 if (of_flags & OF_GPIO_SINGLE_ENDED) { 150 - if (of_flags & OF_GPIO_ACTIVE_LOW) 150 + if (of_flags & OF_GPIO_OPEN_DRAIN) 151 151 *flags |= GPIO_OPEN_DRAIN; 152 152 else 153 153 *flags |= GPIO_OPEN_SOURCE;
+9 -7
drivers/gpio/gpiolib.c
··· 1522 1522 */ 1523 1523 static void gpiochip_set_cascaded_irqchip(struct gpio_chip *gpiochip, 1524 1524 struct irq_chip *irqchip, 1525 - int parent_irq, 1525 + unsigned int parent_irq, 1526 1526 irq_flow_handler_t parent_handler) 1527 1527 { 1528 1528 unsigned int offset; ··· 1571 1571 */ 1572 1572 void gpiochip_set_chained_irqchip(struct gpio_chip *gpiochip, 1573 1573 struct irq_chip *irqchip, 1574 - int parent_irq, 1574 + unsigned int parent_irq, 1575 1575 irq_flow_handler_t parent_handler) 1576 1576 { 1577 1577 gpiochip_set_cascaded_irqchip(gpiochip, irqchip, parent_irq, ··· 1588 1588 */ 1589 1589 void gpiochip_set_nested_irqchip(struct gpio_chip *gpiochip, 1590 1590 struct irq_chip *irqchip, 1591 - int parent_irq) 1591 + unsigned int parent_irq) 1592 1592 { 1593 1593 if (!gpiochip->irq_nested) { 1594 1594 chip_err(gpiochip, "tried to nest a chained gpiochip\n"); ··· 3122 3122 gpio_suffixes[i]); 3123 3123 3124 3124 ret = of_gpio_named_count(dev->of_node, propname); 3125 - if (ret >= 0) 3125 + if (ret > 0) 3126 3126 break; 3127 3127 } 3128 - return ret; 3128 + return ret ? ret : -ENOENT; 3129 3129 } 3130 3130 3131 3131 static int platform_gpio_count(struct device *dev, const char *con_id) ··· 3326 3326 * underlying firmware interface and then makes sure that the GPIO 3327 3327 * descriptor is requested before it is returned to the caller. 3328 3328 * 3329 - * On successfull request the GPIO pin is configured in accordance with 3329 + * On successful request the GPIO pin is configured in accordance with 3330 3330 * provided @dflags. 3331 3331 * 3332 3332 * In case of error an ERR_PTR() is returned. ··· 3340 3340 unsigned long lflags = 0; 3341 3341 bool active_low = false; 3342 3342 bool single_ended = false; 3343 + bool open_drain = false; 3343 3344 int ret; 3344 3345 3345 3346 if (!fwnode) ··· 3354 3353 if (!IS_ERR(desc)) { 3355 3354 active_low = flags & OF_GPIO_ACTIVE_LOW; 3356 3355 single_ended = flags & OF_GPIO_SINGLE_ENDED; 3356 + open_drain = flags & OF_GPIO_OPEN_DRAIN; 3357 3357 } 3358 3358 } else if (is_acpi_node(fwnode)) { 3359 3359 struct acpi_gpio_info info; ··· 3375 3373 lflags |= GPIO_ACTIVE_LOW; 3376 3374 3377 3375 if (single_ended) { 3378 - if (active_low) 3376 + if (open_drain) 3379 3377 lflags |= GPIO_OPEN_DRAIN; 3380 3378 else 3381 3379 lflags |= GPIO_OPEN_SOURCE;
+3 -2
drivers/input/misc/soc_button_array.c
··· 320 320 button_info = (struct soc_button_info *)id->driver_data; 321 321 } 322 322 323 - if (gpiod_count(dev, NULL) <= 0) { 323 + error = gpiod_count(dev, NULL); 324 + if (error < 0) { 324 325 dev_dbg(dev, "no GPIO attached, ignoring...\n"); 325 - return -ENODEV; 326 + return error; 326 327 } 327 328 328 329 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+3 -2
drivers/platform/x86/surface3_button.c
··· 196 196 strlen(SURFACE_BUTTON_OBJ_NAME))) 197 197 return -ENODEV; 198 198 199 - if (gpiod_count(dev, KBUILD_MODNAME) <= 0) { 199 + error = gpiod_count(dev, NULL); 200 + if (error < 0) { 200 201 dev_dbg(dev, "no GPIO attached, ignoring...\n"); 201 - return -ENODEV; 202 + return error; 202 203 } 203 204 204 205 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+3 -2
drivers/usb/dwc3/dwc3-pci.c
··· 125 125 if (pdev->device == PCI_DEVICE_ID_INTEL_BYT) { 126 126 struct gpio_desc *gpio; 127 127 128 - acpi_dev_add_driver_gpios(ACPI_COMPANION(&pdev->dev), 128 + ret = devm_acpi_dev_add_driver_gpios(&pdev->dev, 129 129 acpi_dwc3_byt_gpios); 130 + if (ret) 131 + dev_dbg(&pdev->dev, "failed to add mapping table\n"); 130 132 131 133 /* 132 134 * These GPIOs will turn on the USB2 PHY. Note that we have to ··· 244 242 245 243 device_init_wakeup(&pci->dev, false); 246 244 pm_runtime_get(&pci->dev); 247 - acpi_dev_remove_driver_gpios(ACPI_COMPANION(&pci->dev)); 248 245 platform_device_unregister(dwc->dwc3); 249 246 } 250 247
+8 -4
include/dt-bindings/gpio/gpio.h
··· 17 17 #define GPIO_PUSH_PULL 0 18 18 #define GPIO_SINGLE_ENDED 2 19 19 20 + /* Bit 2 express Open drain or open source */ 21 + #define GPIO_LINE_OPEN_SOURCE 0 22 + #define GPIO_LINE_OPEN_DRAIN 4 23 + 20 24 /* 21 - * Open Drain/Collector is the combination of single-ended active low, 22 - * Open Source/Emitter is the combination of single-ended active high. 25 + * Open Drain/Collector is the combination of single-ended open drain interface. 26 + * Open Source/Emitter is the combination of single-ended open source interface. 23 27 */ 24 - #define GPIO_OPEN_DRAIN (GPIO_SINGLE_ENDED | GPIO_ACTIVE_LOW) 25 - #define GPIO_OPEN_SOURCE (GPIO_SINGLE_ENDED | GPIO_ACTIVE_HIGH) 28 + #define GPIO_OPEN_DRAIN (GPIO_SINGLE_ENDED | GPIO_LINE_OPEN_DRAIN) 29 + #define GPIO_OPEN_SOURCE (GPIO_SINGLE_ENDED | GPIO_LINE_OPEN_SOURCE) 26 30 27 31 #endif
+11
include/linux/acpi.h
··· 957 957 adev->driver_gpios = NULL; 958 958 } 959 959 960 + int devm_acpi_dev_add_driver_gpios(struct device *dev, 961 + const struct acpi_gpio_mapping *gpios); 962 + void devm_acpi_dev_remove_driver_gpios(struct device *dev); 963 + 960 964 int acpi_dev_gpio_irq_get(struct acpi_device *adev, int index); 961 965 #else 962 966 static inline int acpi_dev_add_driver_gpios(struct acpi_device *adev, ··· 969 965 return -ENXIO; 970 966 } 971 967 static inline void acpi_dev_remove_driver_gpios(struct acpi_device *adev) {} 968 + 969 + static inline int devm_acpi_dev_add_driver_gpios(struct device *dev, 970 + const struct acpi_gpio_mapping *gpios) 971 + { 972 + return -ENXIO; 973 + } 974 + static inline void devm_acpi_dev_remove_driver_gpios(struct device *dev) {} 972 975 973 976 static inline int acpi_dev_gpio_irq_get(struct acpi_device *adev, int index) 974 977 {
+6 -6
include/linux/gpio/consumer.h
··· 170 170 gpiod_get_optional(struct device *dev, const char *con_id, 171 171 enum gpiod_flags flags) 172 172 { 173 - return ERR_PTR(-ENOSYS); 173 + return NULL; 174 174 } 175 175 176 176 static inline struct gpio_desc *__must_check 177 177 gpiod_get_index_optional(struct device *dev, const char *con_id, 178 178 unsigned int index, enum gpiod_flags flags) 179 179 { 180 - return ERR_PTR(-ENOSYS); 180 + return NULL; 181 181 } 182 182 183 183 static inline struct gpio_descs *__must_check ··· 191 191 gpiod_get_array_optional(struct device *dev, const char *con_id, 192 192 enum gpiod_flags flags) 193 193 { 194 - return ERR_PTR(-ENOSYS); 194 + return NULL; 195 195 } 196 196 197 197 static inline void gpiod_put(struct gpio_desc *desc) ··· 231 231 devm_gpiod_get_optional(struct device *dev, const char *con_id, 232 232 enum gpiod_flags flags) 233 233 { 234 - return ERR_PTR(-ENOSYS); 234 + return NULL; 235 235 } 236 236 237 237 static inline struct gpio_desc *__must_check 238 238 devm_gpiod_get_index_optional(struct device *dev, const char *con_id, 239 239 unsigned int index, enum gpiod_flags flags) 240 240 { 241 - return ERR_PTR(-ENOSYS); 241 + return NULL; 242 242 } 243 243 244 244 static inline struct gpio_descs *__must_check ··· 252 252 devm_gpiod_get_array_optional(struct device *dev, const char *con_id, 253 253 enum gpiod_flags flags) 254 254 { 255 - return ERR_PTR(-ENOSYS); 255 + return NULL; 256 256 } 257 257 258 258 static inline void devm_gpiod_put(struct device *dev, struct gpio_desc *desc)
+3 -3
include/linux/gpio/driver.h
··· 168 168 unsigned int irq_base; 169 169 irq_flow_handler_t irq_handler; 170 170 unsigned int irq_default_type; 171 - int irq_chained_parent; 171 + unsigned int irq_chained_parent; 172 172 bool irq_nested; 173 173 bool irq_need_valid_mask; 174 174 unsigned long *irq_valid_mask; ··· 244 244 245 245 void gpiochip_set_chained_irqchip(struct gpio_chip *gpiochip, 246 246 struct irq_chip *irqchip, 247 - int parent_irq, 247 + unsigned int parent_irq, 248 248 irq_flow_handler_t parent_handler); 249 249 250 250 void gpiochip_set_nested_irqchip(struct gpio_chip *gpiochip, 251 251 struct irq_chip *irqchip, 252 - int parent_irq); 252 + unsigned int parent_irq); 253 253 254 254 int gpiochip_irqchip_add_key(struct gpio_chip *gpiochip, 255 255 struct irq_chip *irqchip,
+13
include/linux/gpio/gpio-reg.h
··· 1 + #ifndef GPIO_REG_H 2 + #define GPIO_REG_H 3 + 4 + struct device; 5 + struct irq_domain; 6 + 7 + struct gpio_chip *gpio_reg_init(struct device *dev, void __iomem *reg, 8 + int base, int num, const char *label, u32 direction, u32 def_out, 9 + const char *const *names, struct irq_domain *irqdom, const int *irqs); 10 + 11 + int gpio_reg_resume(struct gpio_chip *gc); 12 + 13 + #endif
+1
include/linux/of_gpio.h
··· 30 30 enum of_gpio_flags { 31 31 OF_GPIO_ACTIVE_LOW = 0x1, 32 32 OF_GPIO_SINGLE_ENDED = 0x2, 33 + OF_GPIO_OPEN_DRAIN = 0x4, 33 34 }; 34 35 35 36 #ifdef CONFIG_OF_GPIO