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

Merge tag 'gpio-v4.14-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 the GPIO changes for the v4.14 cycle.

Not so much changes this time, phew. David Daney and Bartosz
Golaszewski did all the really interesting work in infrastructure
improvement across GPIO and IRQ core, hats off for them and to tglx
and Marc Z for general help with these patch sets.

Core changes:

- Allow the GPIO irqchip to allocate IRQs dynamically. This is an
important change on systems where only a restricted number of IRQs,
lesser than the number of GPIO lines, can be utilized. Now we can
allocate these on a first-come-first-served basis instead of
hogging up valuable IRQ lines.

- Serious fix-up of the kerneldoc documentation and inclusion into
the kerneldoc builds.

- Pulled in the IRQ simulator from the IRQ core tree and use this in
the GPIO mockup driver for exhaustive testing of interrupt
abilities.

New drivers:

- New driver for ThunderX and OCTEON-TX. This is especially
interesting as it picks up improvements from the IRQ core that
allow us to handle fasteoi ACKs upwards in a hierarchy when there
are IRQ flag latches on several levels in a hierarchy. Very
interesting work here.

- New subdriver for Renesas R-Car r8a7745 (RZ/G1E).

Misc:

- Several fixes and improvements for Xilinx Zynq GPIO.

- Support an enablement GPIO for the 74x164 GPIO.

- Switch a bunch of chips to use devres to allocate irq descriptors.

- A bunch of constification fixes"

* tag 'gpio-v4.14-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio: (63 commits)
gpio: mockup: remove unused variable gc
gpio: pl061: constify amba_id
Revert "gpiolib: request the gpio before querying its direction"
gpio: twl6040: remove unneeded forward declaration
gpio: zevio: make gpio_chip const
gpio: add gpio_add_lookup_tables() to add several tables at once
gpio: rcar: Add r8a7745 (RZ/G1E) support
gpio: brcmstb: check return value of gpiochip_irqchip_add()
MAINTAINERS: Add entry for THUNDERX GPIO Driver.
gpio: Add gpio driver support for ThunderX and OCTEON-TX
gpio: mockup: use irq_sim
gpio: mxs: use devres for irq generic chip
gpio: mxc: use devres for irq generic chip
gpio: pch: use devres for irq generic chip
gpio: ml-ioh: use devres for irq generic chip
gpio: sta2x11: use devres for irq generic chip
gpio: sta2x11: disallow unbinding the driver
gpio: mxs: disallow unbinding the driver
gpio: mxc: disallow unbinding the driver
gpio: aspeed: Remove reference to clock name in debounce warning message
...

+1515 -325
+3
Documentation/devicetree/bindings/gpio/gpio-74x164.txt
··· 12 12 1 = active low 13 13 - registers-number: Number of daisy-chained shift registers 14 14 15 + Optional properties: 16 + - enable-gpios: GPIO connected to the OE (Output Enable) pin. 17 + 15 18 Example: 16 19 17 20 gpio5: gpio5@0 {
+1 -1
Documentation/devicetree/bindings/gpio/gpio-aspeed.txt
··· 18 18 Optional properties: 19 19 20 20 - interrupt-parent : The parent interrupt controller, optional if inherited 21 - - clocks : A phandle to the HPLL clock node for debounce timings 21 + - clocks : A phandle to the clock to use for debounce timings 22 22 23 23 The gpio and interrupt properties are further described in their respective 24 24 bindings documentation:
+89 -2
Documentation/devicetree/bindings/gpio/gpio-davinci.txt
··· 1 1 Davinci/Keystone GPIO controller bindings 2 2 3 3 Required Properties: 4 - - compatible: should be "ti,dm6441-gpio", "ti,keystone-gpio" 4 + - compatible: should be "ti,dm6441-gpio": for Davinci da850 SoCs 5 + "ti,keystone-gpio": for Keystone 2 66AK2H/K, 66AK2L, 6 + 66AK2E SoCs 7 + "ti,k2g-gpio", "ti,keystone-gpio": for 66AK2G 5 8 6 9 - reg: Physical base address of the controller and the size of memory mapped 7 10 registers. ··· 23 20 - ti,ngpio: The number of GPIO pins supported. 24 21 25 22 - ti,davinci-gpio-unbanked: The number of GPIOs that have an individual interrupt 26 - line to processor. 23 + line to processor. 24 + 25 + - clocks: Should contain the device's input clock, and should be defined as per 26 + the appropriate clock bindings consumer usage in, 27 + 28 + Documentation/devicetree/bindings/clock/keystone-gate.txt 29 + for 66AK2HK/66AK2L/66AK2E SoCs or, 30 + 31 + Documentation/devicetree/bindings/clock/ti,sci-clk.txt 32 + for 66AK2G SoCs 33 + 34 + - clock-names: Name should be "gpio"; 35 + 36 + Currently clock-names and clocks are needed for all keystone 2 platforms 37 + Davinci platforms do not have DT clocks as of now. 27 38 28 39 The GPIO controller also acts as an interrupt controller. It uses the default 29 40 two cells specifier as described in Documentation/devicetree/bindings/ ··· 76 59 gpios = <&gpio 11 GPIO_ACTIVE_HIGH>; 77 60 ... 78 61 }; 62 + }; 63 + 64 + Example for 66AK2G: 65 + 66 + gpio0: gpio@2603000 { 67 + compatible = "ti,k2g-gpio", "ti,keystone-gpio"; 68 + reg = <0x02603000 0x100>; 69 + gpio-controller; 70 + #gpio-cells = <2>; 71 + interrupts = <GIC_SPI 432 IRQ_TYPE_EDGE_RISING>, 72 + <GIC_SPI 433 IRQ_TYPE_EDGE_RISING>, 73 + <GIC_SPI 434 IRQ_TYPE_EDGE_RISING>, 74 + <GIC_SPI 435 IRQ_TYPE_EDGE_RISING>, 75 + <GIC_SPI 436 IRQ_TYPE_EDGE_RISING>, 76 + <GIC_SPI 437 IRQ_TYPE_EDGE_RISING>, 77 + <GIC_SPI 438 IRQ_TYPE_EDGE_RISING>, 78 + <GIC_SPI 439 IRQ_TYPE_EDGE_RISING>, 79 + <GIC_SPI 440 IRQ_TYPE_EDGE_RISING>; 80 + interrupt-controller; 81 + #interrupt-cells = <2>; 82 + ti,ngpio = <144>; 83 + ti,davinci-gpio-unbanked = <0>; 84 + clocks = <&k2g_clks 0x001b 0x0>; 85 + clock-names = "gpio"; 86 + }; 87 + 88 + Example for 66AK2HK/66AK2L/66AK2E: 89 + 90 + gpio0: gpio@260bf00 { 91 + compatible = "ti,keystone-gpio"; 92 + reg = <0x0260bf00 0x100>; 93 + gpio-controller; 94 + #gpio-cells = <2>; 95 + /* HW Interrupts mapped to GPIO pins */ 96 + interrupts = <GIC_SPI 120 IRQ_TYPE_EDGE_RISING>, 97 + <GIC_SPI 121 IRQ_TYPE_EDGE_RISING>, 98 + <GIC_SPI 122 IRQ_TYPE_EDGE_RISING>, 99 + <GIC_SPI 123 IRQ_TYPE_EDGE_RISING>, 100 + <GIC_SPI 124 IRQ_TYPE_EDGE_RISING>, 101 + <GIC_SPI 125 IRQ_TYPE_EDGE_RISING>, 102 + <GIC_SPI 126 IRQ_TYPE_EDGE_RISING>, 103 + <GIC_SPI 127 IRQ_TYPE_EDGE_RISING>, 104 + <GIC_SPI 128 IRQ_TYPE_EDGE_RISING>, 105 + <GIC_SPI 129 IRQ_TYPE_EDGE_RISING>, 106 + <GIC_SPI 130 IRQ_TYPE_EDGE_RISING>, 107 + <GIC_SPI 131 IRQ_TYPE_EDGE_RISING>, 108 + <GIC_SPI 132 IRQ_TYPE_EDGE_RISING>, 109 + <GIC_SPI 133 IRQ_TYPE_EDGE_RISING>, 110 + <GIC_SPI 134 IRQ_TYPE_EDGE_RISING>, 111 + <GIC_SPI 135 IRQ_TYPE_EDGE_RISING>, 112 + <GIC_SPI 136 IRQ_TYPE_EDGE_RISING>, 113 + <GIC_SPI 137 IRQ_TYPE_EDGE_RISING>, 114 + <GIC_SPI 138 IRQ_TYPE_EDGE_RISING>, 115 + <GIC_SPI 139 IRQ_TYPE_EDGE_RISING>, 116 + <GIC_SPI 140 IRQ_TYPE_EDGE_RISING>, 117 + <GIC_SPI 141 IRQ_TYPE_EDGE_RISING>, 118 + <GIC_SPI 142 IRQ_TYPE_EDGE_RISING>, 119 + <GIC_SPI 143 IRQ_TYPE_EDGE_RISING>, 120 + <GIC_SPI 144 IRQ_TYPE_EDGE_RISING>, 121 + <GIC_SPI 145 IRQ_TYPE_EDGE_RISING>, 122 + <GIC_SPI 146 IRQ_TYPE_EDGE_RISING>, 123 + <GIC_SPI 147 IRQ_TYPE_EDGE_RISING>, 124 + <GIC_SPI 148 IRQ_TYPE_EDGE_RISING>, 125 + <GIC_SPI 149 IRQ_TYPE_EDGE_RISING>, 126 + <GIC_SPI 150 IRQ_TYPE_EDGE_RISING>, 127 + <GIC_SPI 151 IRQ_TYPE_EDGE_RISING>; 128 + clocks = <&clkgpio>; 129 + clock-names = "gpio"; 130 + ti,ngpio = <32>; 131 + ti,davinci-gpio-unbanked = <32>; 79 132 };
+3 -1
Documentation/devicetree/bindings/gpio/gpio-vf610.txt
··· 5 5 each, and each PORT module has its own interrupt. 6 6 7 7 Required properties for GPIO node: 8 - - compatible : Should be "fsl,<soc>-gpio", currently "fsl,vf610-gpio" 8 + - compatible : Should be "fsl,<soc>-gpio", below is supported list: 9 + "fsl,vf610-gpio" 10 + "fsl,imx7ulp-gpio" 9 11 - reg : The first reg tuple represents the PORT module, the second tuple 10 12 the GPIO module. 11 13 - interrupts : Should be the port interrupt shared by all 32 pins.
+12 -4
Documentation/devicetree/bindings/gpio/renesas,gpio-rcar.txt
··· 2 2 3 3 Required Properties: 4 4 5 - - compatible: should contain one of the following. 5 + - compatible: should contain one or more of the following: 6 6 - "renesas,gpio-r8a7743": for R8A7743 (RZ/G1M) compatible GPIO controller. 7 + - "renesas,gpio-r8a7745": for R8A7745 (RZ/G1E) compatible GPIO controller. 7 8 - "renesas,gpio-r8a7778": for R8A7778 (R-Mobile M1) compatible GPIO controller. 8 9 - "renesas,gpio-r8a7779": for R8A7779 (R-Car H1) compatible GPIO controller. 9 10 - "renesas,gpio-r8a7790": for R8A7790 (R-Car H2) compatible GPIO controller. ··· 14 13 - "renesas,gpio-r8a7794": for R8A7794 (R-Car E2) compatible GPIO controller. 15 14 - "renesas,gpio-r8a7795": for R8A7795 (R-Car H3) compatible GPIO controller. 16 15 - "renesas,gpio-r8a7796": for R8A7796 (R-Car M3-W) compatible GPIO controller. 17 - - "renesas,gpio-rcar": for generic R-Car GPIO controller. 16 + - "renesas,rcar-gen1-gpio": for a generic R-Car Gen1 GPIO controller. 17 + - "renesas,rcar-gen2-gpio": for a generic R-Car Gen2 or RZ/G1 GPIO controller. 18 + - "renesas,rcar-gen3-gpio": for a generic R-Car Gen3 GPIO controller. 19 + - "renesas,gpio-rcar": deprecated. 20 + 21 + When compatible with the generic version nodes must list the 22 + SoC-specific version corresponding to the platform first followed by 23 + the generic version. 18 24 19 25 - reg: Base address and length of each memory resource used by the GPIO 20 26 controller hardware module. ··· 51 43 Example: R8A7779 (R-Car H1) GPIO controller nodes 52 44 53 45 gpio0: gpio@ffc40000 { 54 - compatible = "renesas,gpio-r8a7779", "renesas,gpio-rcar"; 46 + compatible = "renesas,gpio-r8a7779", "renesas,rcar-gen1-gpio"; 55 47 reg = <0xffc40000 0x2c>; 56 48 interrupt-parent = <&gic>; 57 49 interrupts = <0 141 0x4>; ··· 63 55 }; 64 56 ... 65 57 gpio6: gpio@ffc46000 { 66 - compatible = "renesas,gpio-r8a7779", "renesas,gpio-rcar"; 58 + compatible = "renesas,gpio-r8a7779", "renesas,rcar-gen1-gpio"; 67 59 reg = <0xffc46000 0x2c>; 68 60 interrupt-parent = <&gic>; 69 61 interrupts = <0 147 0x4>;
+45
Documentation/driver-api/gpio.rst
··· 1 + =================================== 2 + General Purpose Input/Output (GPIO) 3 + =================================== 4 + 5 + Core 6 + ==== 7 + 8 + .. kernel-doc:: include/linux/gpio/driver.h 9 + :internal: 10 + 11 + .. kernel-doc:: drivers/gpio/gpiolib.c 12 + :export: 13 + 14 + Legacy API 15 + ========== 16 + 17 + The functions listed in this section are deprecated. The GPIO descriptor based 18 + API described above should be used in new code. 19 + 20 + .. kernel-doc:: drivers/gpio/gpiolib-legacy.c 21 + :export: 22 + 23 + ACPI support 24 + ============ 25 + 26 + .. kernel-doc:: drivers/gpio/gpiolib-acpi.c 27 + :export: 28 + 29 + Device tree support 30 + =================== 31 + 32 + .. kernel-doc:: drivers/gpio/gpiolib-of.c 33 + :export: 34 + 35 + Device-managed API 36 + ================== 37 + 38 + .. kernel-doc:: drivers/gpio/devres.c 39 + :export: 40 + 41 + sysfs helpers 42 + ============= 43 + 44 + .. kernel-doc:: drivers/gpio/gpiolib-sysfs.c 45 + :export:
+1
Documentation/driver-api/index.rst
··· 44 44 uio-howto 45 45 firmware/index 46 46 pinctl 47 + gpio 47 48 misc_devices 48 49 49 50 .. only:: subproject and html
+5
MAINTAINERS
··· 13018 13018 S: Maintained 13019 13019 F: drivers/thunderbolt/ 13020 13020 13021 + THUNDERX GPIO DRIVER 13022 + M: David Daney <david.daney@cavium.com> 13023 + S: Maintained 13024 + F: drivers/gpio/gpio-thunderx.c 13025 + 13021 13026 TI AM437X VPFE DRIVER 13022 13027 M: "Lad, Prabhakar" <prabhakar.csengg@gmail.com> 13023 13028 L: linux-media@vger.kernel.org
+25 -1
drivers/gpio/Kconfig
··· 311 311 depends on GPIOLIB && SYSFS 312 312 select GPIO_SYSFS 313 313 select GPIOLIB_IRQCHIP 314 - select IRQ_WORK 314 + select IRQ_SIM 315 315 help 316 316 This enables GPIO Testing driver, which provides a way to test GPIO 317 317 subsystem through sysfs(or char device) and debugfs. GPIO_SYSFS ··· 449 449 select GPIO_GENERIC 450 450 help 451 451 This driver support TS-4800 FPGA GPIO controllers. 452 + 453 + config GPIO_THUNDERX 454 + tristate "Cavium ThunderX/OCTEON-TX GPIO" 455 + depends on ARCH_THUNDER || (64BIT && COMPILE_TEST) 456 + depends on PCI_MSI && IRQ_DOMAIN_HIERARCHY 457 + select IRQ_FASTEOI_HIERARCHY_HANDLERS 458 + help 459 + Say yes here to support the on-chip GPIO lines on the ThunderX 460 + and OCTEON-TX families of SoCs. 452 461 453 462 config GPIO_TZ1090 454 463 bool "Toumaz Xenif TZ1090 GPIO support" ··· 1073 1064 depends on MFD_TPS65912 1074 1065 help 1075 1066 This driver supports TPS65912 gpio chip 1067 + 1068 + config GPIO_TPS68470 1069 + bool "TPS68470 GPIO" 1070 + depends on MFD_TPS68470 1071 + help 1072 + Select this option to enable GPIO driver for the TPS68470 1073 + chip family. 1074 + There are 7 GPIOs and few sensor related GPIOs supported 1075 + by the TPS68470. While the 7 GPIOs can be configured as 1076 + input or output as appropriate, the sensor related GPIOs 1077 + are "output only" GPIOs. 1078 + 1079 + This driver config is bool, as the GPIO functionality 1080 + of the TPS68470 must be available before dependent 1081 + drivers are loaded. 1076 1082 1077 1083 config GPIO_TWL4030 1078 1084 tristate "TWL4030, TWL5030, and TPS659x0 GPIOs"
+2
drivers/gpio/Makefile
··· 113 113 obj-$(CONFIG_GPIO_TB10X) += gpio-tb10x.o 114 114 obj-$(CONFIG_GPIO_TC3589X) += gpio-tc3589x.o 115 115 obj-$(CONFIG_GPIO_TEGRA) += gpio-tegra.o 116 + obj-$(CONFIG_GPIO_THUNDERX) += gpio-thunderx.o 116 117 obj-$(CONFIG_GPIO_TIMBERDALE) += gpio-timberdale.o 117 118 obj-$(CONFIG_GPIO_PALMAS) += gpio-palmas.o 118 119 obj-$(CONFIG_GPIO_TPIC2810) += gpio-tpic2810.o ··· 122 121 obj-$(CONFIG_GPIO_TPS6586X) += gpio-tps6586x.o 123 122 obj-$(CONFIG_GPIO_TPS65910) += gpio-tps65910.o 124 123 obj-$(CONFIG_GPIO_TPS65912) += gpio-tps65912.o 124 + obj-$(CONFIG_GPIO_TPS68470) += gpio-tps68470.o 125 125 obj-$(CONFIG_GPIO_TS4800) += gpio-ts4800.o 126 126 obj-$(CONFIG_GPIO_TS4900) += gpio-ts4900.o 127 127 obj-$(CONFIG_GPIO_TS5500) += gpio-ts5500.o
+3
drivers/gpio/devres.c
··· 132 132 * @index: index of the GPIO to obtain in the consumer 133 133 * @child: firmware node (child of @dev) 134 134 * @flags: GPIO initialization flags 135 + * @label: label to attach to the requested GPIO 135 136 * 136 137 * GPIO descriptors returned from this function are automatically disposed on 137 138 * driver detach. ··· 272 271 273 272 /** 274 273 * devm_gpiod_put - Resource-managed gpiod_put() 274 + * @dev: GPIO consumer 275 275 * @desc: GPIO descriptor to dispose of 276 276 * 277 277 * Dispose of a GPIO descriptor obtained with devm_gpiod_get() or ··· 288 286 289 287 /** 290 288 * devm_gpiod_put_array - Resource-managed gpiod_put_array() 289 + * @dev: GPIO consumer 291 290 * @descs: GPIO descriptor array to dispose of 292 291 * 293 292 * Dispose of an array of GPIO descriptors obtained with devm_gpiod_get_array().
+10
drivers/gpio/gpio-74x164.c
··· 9 9 * published by the Free Software Foundation. 10 10 */ 11 11 12 + #include <linux/gpio/consumer.h> 12 13 #include <linux/init.h> 13 14 #include <linux/mutex.h> 14 15 #include <linux/spi/spi.h> ··· 32 31 * numbering, store the bytes in reverse order. 33 32 */ 34 33 u8 buffer[0]; 34 + struct gpio_desc *gpiod_oe; 35 35 }; 36 36 37 37 static int __gen_74x164_write_config(struct gen_74x164_chip *chip) ··· 128 126 if (!chip) 129 127 return -ENOMEM; 130 128 129 + chip->gpiod_oe = devm_gpiod_get_optional(&spi->dev, "enable", 130 + GPIOD_OUT_LOW); 131 + if (IS_ERR(chip->gpiod_oe)) 132 + return PTR_ERR(chip->gpiod_oe); 133 + 134 + gpiod_set_value_cansleep(chip->gpiod_oe, 1); 135 + 131 136 spi_set_drvdata(spi, chip); 132 137 133 138 chip->gpio_chip.label = spi->modalias; ··· 173 164 { 174 165 struct gen_74x164_chip *chip = spi_get_drvdata(spi); 175 166 167 + gpiod_set_value_cansleep(chip->gpiod_oe, 0); 176 168 gpiochip_remove(&chip->gpio_chip); 177 169 mutex_destroy(&chip->lock); 178 170
+1 -1
drivers/gpio/gpio-altera-a10sr.c
··· 71 71 return -EINVAL; 72 72 } 73 73 74 - static struct gpio_chip altr_a10sr_gc = { 74 + static const struct gpio_chip altr_a10sr_gc = { 75 75 .label = "altr_a10sr_gpio", 76 76 .owner = THIS_MODULE, 77 77 .get = altr_a10sr_gpio_get,
+2 -2
drivers/gpio/gpio-altera.c
··· 324 324 return 0; 325 325 teardown: 326 326 of_mm_gpiochip_remove(&altera_gc->mmchip); 327 - pr_err("%s: registration failed with status %d\n", 328 - node->full_name, ret); 327 + pr_err("%pOF: registration failed with status %d\n", 328 + node, ret); 329 329 330 330 return ret; 331 331 }
+1 -1
drivers/gpio/gpio-aspeed.c
··· 834 834 gpio->clk = of_clk_get(pdev->dev.of_node, 0); 835 835 if (IS_ERR(gpio->clk)) { 836 836 dev_warn(&pdev->dev, 837 - "No HPLL clock phandle provided, debouncing disabled\n"); 837 + "Failed to get clock from devicetree, debouncing disabled\n"); 838 838 gpio->clk = NULL; 839 839 } 840 840
+6 -5
drivers/gpio/gpio-brcmstb.c
··· 339 339 struct brcmstb_gpio_priv *priv = bank->parent_priv; 340 340 struct device *dev = &pdev->dev; 341 341 struct device_node *np = dev->of_node; 342 + int err; 342 343 343 344 bank->irq_chip.name = dev_name(dev); 344 345 bank->irq_chip.irq_mask = brcmstb_gpio_irq_mask; ··· 356 355 dev_warn(dev, 357 356 "Couldn't get wake IRQ - GPIOs will not be able to wake from sleep"); 358 357 } else { 359 - int err; 360 - 361 358 /* 362 359 * Set wakeup capability before requesting wakeup 363 360 * interrupt, so we can process boot-time "wakeups" ··· 382 383 if (priv->can_wake) 383 384 bank->irq_chip.irq_set_wake = brcmstb_gpio_irq_set_wake; 384 385 385 - gpiochip_irqchip_add(&bank->gc, &bank->irq_chip, 0, 386 - handle_simple_irq, IRQ_TYPE_NONE); 386 + err = gpiochip_irqchip_add(&bank->gc, &bank->irq_chip, 0, 387 + handle_simple_irq, IRQ_TYPE_NONE); 388 + if (err) 389 + return err; 387 390 gpiochip_set_chained_irqchip(&bank->gc, &bank->irq_chip, 388 391 priv->parent_irq, brcmstb_gpio_irq_handler); 389 392 ··· 484 483 485 484 gc->of_node = np; 486 485 gc->owner = THIS_MODULE; 487 - gc->label = np->full_name; 486 + gc->label = devm_kasprintf(dev, GFP_KERNEL, "%pOF", dev->of_node); 488 487 gc->base = gpio_base; 489 488 gc->of_gpio_n_cells = 2; 490 489 gc->of_xlate = brcmstb_gpio_of_xlate;
+17 -5
drivers/gpio/gpio-davinci.c
··· 166 166 static int davinci_gpio_probe(struct platform_device *pdev) 167 167 { 168 168 static int ctrl_num, bank_base; 169 - int gpio, bank; 169 + int gpio, bank, ret = 0; 170 170 unsigned ngpio, nbank; 171 171 struct davinci_gpio_controller *chips; 172 172 struct davinci_gpio_platform_data *pdata; ··· 232 232 for (gpio = 0, bank = 0; gpio < ngpio; gpio += 32, bank++) 233 233 chips->regs[bank] = gpio_base + offset_array[bank]; 234 234 235 - gpiochip_add_data(&chips->chip, chips); 235 + ret = devm_gpiochip_add_data(dev, &chips->chip, chips); 236 + if (ret) 237 + goto err; 238 + 236 239 platform_set_drvdata(pdev, chips); 237 - davinci_gpio_irq_setup(pdev); 240 + ret = davinci_gpio_irq_setup(pdev); 241 + if (ret) 242 + goto err; 243 + 238 244 return 0; 245 + 246 + err: 247 + /* Revert the static variable increments */ 248 + ctrl_num--; 249 + bank_base -= ngpio; 250 + 251 + return ret; 239 252 } 240 253 241 254 /*--------------------------------------------------------------------------*/ ··· 490 477 491 478 clk = devm_clk_get(dev, "gpio"); 492 479 if (IS_ERR(clk)) { 493 - printk(KERN_ERR "Error %ld getting gpio clock?\n", 494 - PTR_ERR(clk)); 480 + dev_err(dev, "Error %ld getting gpio clock\n", PTR_ERR(clk)); 495 481 return PTR_ERR(clk); 496 482 } 497 483 ret = clk_prepare_enable(clk);
+2 -4
drivers/gpio/gpio-ge.c
··· 76 76 } 77 77 78 78 /* Setup pointers to chip functions */ 79 - gc->label = devm_kstrdup(&pdev->dev, pdev->dev.of_node->full_name, 80 - GFP_KERNEL); 79 + gc->label = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%pOF", pdev->dev.of_node); 81 80 if (!gc->label) { 82 81 ret = -ENOMEM; 83 82 goto err0; ··· 95 96 return 0; 96 97 err0: 97 98 iounmap(regs); 98 - pr_err("%s: GPIO chip registration failed\n", 99 - pdev->dev.of_node->full_name); 99 + pr_err("%pOF: GPIO chip registration failed\n", pdev->dev.of_node); 100 100 return ret; 101 101 }; 102 102
+1 -1
drivers/gpio/gpio-grgpio.c
··· 367 367 gc->of_node = np; 368 368 gc->owner = THIS_MODULE; 369 369 gc->to_irq = grgpio_to_irq; 370 - gc->label = np->full_name; 370 + gc->label = devm_kasprintf(&ofdev->dev, GFP_KERNEL, "%pOF", np); 371 371 gc->base = -1; 372 372 373 373 err = of_property_read_u32(np, "nbits", &prop);
+3
drivers/gpio/gpio-it87.c
··· 2 2 * GPIO interface for IT87xx Super I/O chips 3 3 * 4 4 * Author: Diego Elio Pettenò <flameeyes@flameeyes.eu> 5 + * Copyright (c) 2017 Google, Inc. 5 6 * 6 7 * Based on it87_wdt.c by Oliver Schuster 7 8 * gpio-it8761e.c by Denis Turischev ··· 40 39 #define IT8728_ID 0x8728 41 40 #define IT8732_ID 0x8732 42 41 #define IT8761_ID 0x8761 42 + #define IT8772_ID 0x8772 43 43 44 44 /* IO Ports */ 45 45 #define REG 0x2e ··· 316 314 break; 317 315 case IT8728_ID: 318 316 case IT8732_ID: 317 + case IT8772_ID: 319 318 gpio_ba_reg = 0x62; 320 319 it87_gpio->io_size = 8; 321 320 it87_gpio->output_base = 0xc8;
+1 -1
drivers/gpio/gpio-max77620.c
··· 82 82 }, 83 83 }; 84 84 85 - static struct regmap_irq_chip max77620_gpio_irq_chip = { 85 + static const struct regmap_irq_chip max77620_gpio_irq_chip = { 86 86 .name = "max77620-gpio", 87 87 .irqs = max77620_gpio_irqs, 88 88 .num_irqs = ARRAY_SIZE(max77620_gpio_irqs),
+3 -1
drivers/gpio/gpio-mb86s7x.c
··· 168 168 if (IS_ERR(gchip->clk)) 169 169 return PTR_ERR(gchip->clk); 170 170 171 - clk_prepare_enable(gchip->clk); 171 + ret = clk_prepare_enable(gchip->clk); 172 + if (ret) 173 + return ret; 172 174 173 175 spin_lock_init(&gchip->lock); 174 176
+7 -5
drivers/gpio/gpio-ml-ioh.c
··· 391 391 { 392 392 struct irq_chip_generic *gc; 393 393 struct irq_chip_type *ct; 394 + int rv; 394 395 395 - gc = irq_alloc_generic_chip("ioh_gpio", 1, irq_start, chip->base, 396 - handle_simple_irq); 396 + gc = devm_irq_alloc_generic_chip(chip->dev, "ioh_gpio", 1, irq_start, 397 + chip->base, handle_simple_irq); 397 398 if (!gc) 398 399 return -ENOMEM; 399 400 ··· 407 406 ct->chip.irq_disable = ioh_irq_disable; 408 407 ct->chip.irq_enable = ioh_irq_enable; 409 408 410 - irq_setup_generic_chip(gc, IRQ_MSK(num), IRQ_GC_INIT_MASK_CACHE, 411 - IRQ_NOREQUEST | IRQ_NOPROBE, 0); 409 + rv = devm_irq_setup_generic_chip(chip->dev, gc, IRQ_MSK(num), 410 + IRQ_GC_INIT_MASK_CACHE, 411 + IRQ_NOREQUEST | IRQ_NOPROBE, 0); 412 412 413 - return 0; 413 + return rv; 414 414 } 415 415 416 416 static int ioh_gpio_probe(struct pci_dev *pdev,
+7 -72
drivers/gpio/gpio-mockup.c
··· 20 20 #include <linux/slab.h> 21 21 #include <linux/interrupt.h> 22 22 #include <linux/irq.h> 23 - #include <linux/irq_work.h> 23 + #include <linux/irq_sim.h> 24 24 #include <linux/debugfs.h> 25 25 #include <linux/uaccess.h> 26 26 ··· 47 47 struct gpio_mockup_line_status { 48 48 int dir; 49 49 bool value; 50 - bool irq_enabled; 51 - }; 52 - 53 - struct gpio_mockup_irq_context { 54 - struct irq_work work; 55 - int irq; 56 50 }; 57 51 58 52 struct gpio_mockup_chip { 59 53 struct gpio_chip gc; 60 54 struct gpio_mockup_line_status *lines; 61 - struct gpio_mockup_irq_context irq_ctx; 55 + struct irq_sim irqsim; 62 56 struct dentry *dbg_dir; 63 57 }; 64 58 ··· 138 144 return 0; 139 145 } 140 146 141 - static int gpio_mockup_to_irq(struct gpio_chip *chip, unsigned int offset) 147 + static int gpio_mockup_to_irq(struct gpio_chip *gc, unsigned int offset) 142 148 { 143 - return chip->irq_base + offset; 144 - } 145 - 146 - static void gpio_mockup_irqmask(struct irq_data *data) 147 - { 148 - struct gpio_chip *gc = irq_data_get_irq_chip_data(data); 149 149 struct gpio_mockup_chip *chip = gpiochip_get_data(gc); 150 150 151 - chip->lines[data->irq - gc->irq_base].irq_enabled = false; 152 - } 153 - 154 - static void gpio_mockup_irqunmask(struct irq_data *data) 155 - { 156 - struct gpio_chip *gc = irq_data_get_irq_chip_data(data); 157 - struct gpio_mockup_chip *chip = gpiochip_get_data(gc); 158 - 159 - chip->lines[data->irq - gc->irq_base].irq_enabled = true; 160 - } 161 - 162 - static struct irq_chip gpio_mockup_irqchip = { 163 - .name = GPIO_MOCKUP_NAME, 164 - .irq_mask = gpio_mockup_irqmask, 165 - .irq_unmask = gpio_mockup_irqunmask, 166 - }; 167 - 168 - static void gpio_mockup_handle_irq(struct irq_work *work) 169 - { 170 - struct gpio_mockup_irq_context *irq_ctx; 171 - 172 - irq_ctx = container_of(work, struct gpio_mockup_irq_context, work); 173 - handle_simple_irq(irq_to_desc(irq_ctx->irq)); 174 - } 175 - 176 - static int gpio_mockup_irqchip_setup(struct device *dev, 177 - struct gpio_mockup_chip *chip) 178 - { 179 - struct gpio_chip *gc = &chip->gc; 180 - int irq_base, i; 181 - 182 - irq_base = devm_irq_alloc_descs(dev, -1, 0, gc->ngpio, 0); 183 - if (irq_base < 0) 184 - return irq_base; 185 - 186 - gc->irq_base = irq_base; 187 - gc->irqchip = &gpio_mockup_irqchip; 188 - 189 - for (i = 0; i < gc->ngpio; i++) { 190 - irq_set_chip(irq_base + i, gc->irqchip); 191 - irq_set_chip_data(irq_base + i, gc); 192 - irq_set_handler(irq_base + i, &handle_simple_irq); 193 - irq_modify_status(irq_base + i, 194 - IRQ_NOREQUEST | IRQ_NOAUTOEN, IRQ_NOPROBE); 195 - } 196 - 197 - init_irq_work(&chip->irq_ctx.work, gpio_mockup_handle_irq); 198 - 199 - return 0; 151 + return irq_sim_irqnum(&chip->irqsim, offset); 200 152 } 201 153 202 154 static ssize_t gpio_mockup_event_write(struct file *file, ··· 153 213 struct gpio_mockup_chip *chip; 154 214 struct seq_file *sfile; 155 215 struct gpio_desc *desc; 156 - struct gpio_chip *gc; 157 216 int rv, val; 158 217 159 218 rv = kstrtoint_from_user(usr_buf, size, 0, &val); ··· 165 226 priv = sfile->private; 166 227 desc = priv->desc; 167 228 chip = priv->chip; 168 - gc = &chip->gc; 169 229 170 - if (chip->lines[priv->offset].irq_enabled) { 171 - gpiod_set_value_cansleep(desc, val); 172 - priv->chip->irq_ctx.irq = gc->irq_base + priv->offset; 173 - irq_work_queue(&priv->chip->irq_ctx.work); 174 - } 230 + gpiod_set_value_cansleep(desc, val); 231 + irq_sim_fire(&chip->irqsim, priv->offset); 175 232 176 233 return size; 177 234 } ··· 254 319 return ret; 255 320 } 256 321 257 - ret = gpio_mockup_irqchip_setup(dev, chip); 322 + ret = devm_irq_sim_init(dev, &chip->irqsim, gc->ngpio); 258 323 if (ret) 259 324 return ret; 260 325
+2 -2
drivers/gpio/gpio-mpc8xxx.c
··· 348 348 349 349 ret = gpiochip_add_data(gc, mpc8xxx_gc); 350 350 if (ret) { 351 - pr_err("%s: GPIO chip registration failed with status %d\n", 352 - np->full_name, ret); 351 + pr_err("%pOF: GPIO chip registration failed with status %d\n", 352 + np, ret); 353 353 goto err; 354 354 } 355 355
+2 -2
drivers/gpio/gpio-msic.c
··· 265 265 int i; 266 266 267 267 if (irq < 0) { 268 - dev_err(dev, "no IRQ line\n"); 269 - return -EINVAL; 268 + dev_err(dev, "no IRQ line: %d\n", irq); 269 + return irq; 270 270 } 271 271 272 272 if (!pdata || !pdata->gpio_base) {
+17 -10
drivers/gpio/gpio-mxc.c
··· 66 66 int irq_high; 67 67 struct irq_domain *domain; 68 68 struct gpio_chip gc; 69 + struct device *dev; 69 70 u32 both_edges; 70 71 }; 71 72 ··· 325 324 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); 326 325 struct mxc_gpio_port *port = gc->private; 327 326 u32 gpio_idx = d->hwirq; 327 + int ret; 328 328 329 329 if (enable) { 330 330 if (port->irq_high && (gpio_idx >= 16)) 331 - enable_irq_wake(port->irq_high); 331 + ret = enable_irq_wake(port->irq_high); 332 332 else 333 - enable_irq_wake(port->irq); 333 + ret = enable_irq_wake(port->irq); 334 334 } else { 335 335 if (port->irq_high && (gpio_idx >= 16)) 336 - disable_irq_wake(port->irq_high); 336 + ret = disable_irq_wake(port->irq_high); 337 337 else 338 - disable_irq_wake(port->irq); 338 + ret = disable_irq_wake(port->irq); 339 339 } 340 340 341 - return 0; 341 + return ret; 342 342 } 343 343 344 344 static int mxc_gpio_init_gc(struct mxc_gpio_port *port, int irq_base) 345 345 { 346 346 struct irq_chip_generic *gc; 347 347 struct irq_chip_type *ct; 348 + int rv; 348 349 349 - gc = irq_alloc_generic_chip("gpio-mxc", 1, irq_base, 350 - port->base, handle_level_irq); 350 + gc = devm_irq_alloc_generic_chip(port->dev, "gpio-mxc", 1, irq_base, 351 + port->base, handle_level_irq); 351 352 if (!gc) 352 353 return -ENOMEM; 353 354 gc->private = port; ··· 364 361 ct->regs.ack = GPIO_ISR; 365 362 ct->regs.mask = GPIO_IMR; 366 363 367 - irq_setup_generic_chip(gc, IRQ_MSK(32), IRQ_GC_INIT_NESTED_LOCK, 368 - IRQ_NOREQUEST, 0); 364 + rv = devm_irq_setup_generic_chip(port->dev, gc, IRQ_MSK(32), 365 + IRQ_GC_INIT_NESTED_LOCK, 366 + IRQ_NOREQUEST, 0); 369 367 370 - return 0; 368 + return rv; 371 369 } 372 370 373 371 static void mxc_gpio_get_hw(struct platform_device *pdev) ··· 421 417 port = devm_kzalloc(&pdev->dev, sizeof(*port), GFP_KERNEL); 422 418 if (!port) 423 419 return -ENOMEM; 420 + 421 + port->dev = &pdev->dev; 424 422 425 423 iores = platform_get_resource(pdev, IORESOURCE_MEM, 0); 426 424 port->base = devm_ioremap_resource(&pdev->dev, iores); ··· 513 507 .driver = { 514 508 .name = "gpio-mxc", 515 509 .of_match_table = mxc_gpio_dt_ids, 510 + .suppress_bind_attrs = true, 516 511 }, 517 512 .probe = mxc_gpio_probe, 518 513 .id_table = mxc_gpio_devtype,
+10 -5
drivers/gpio/gpio-mxs.c
··· 66 66 int irq; 67 67 struct irq_domain *domain; 68 68 struct gpio_chip gc; 69 + struct device *dev; 69 70 enum mxs_gpio_id devid; 70 71 u32 both_edges; 71 72 }; ··· 210 209 { 211 210 struct irq_chip_generic *gc; 212 211 struct irq_chip_type *ct; 212 + int rv; 213 213 214 - gc = irq_alloc_generic_chip("gpio-mxs", 2, irq_base, 215 - port->base, handle_level_irq); 214 + gc = devm_irq_alloc_generic_chip(port->dev, "gpio-mxs", 2, irq_base, 215 + port->base, handle_level_irq); 216 216 if (!gc) 217 217 return -ENOMEM; 218 218 ··· 244 242 ct->regs.disable = PINCTRL_IRQEN(port) + MXS_CLR; 245 243 ct->handler = handle_level_irq; 246 244 247 - irq_setup_generic_chip(gc, IRQ_MSK(32), IRQ_GC_INIT_NESTED_LOCK, 248 - IRQ_NOREQUEST, 0); 245 + rv = devm_irq_setup_generic_chip(port->dev, gc, IRQ_MSK(32), 246 + IRQ_GC_INIT_NESTED_LOCK, 247 + IRQ_NOREQUEST, 0); 249 248 250 - return 0; 249 + return rv; 251 250 } 252 251 253 252 static int mxs_gpio_to_irq(struct gpio_chip *gc, unsigned offset) ··· 307 304 if (port->id < 0) 308 305 return port->id; 309 306 port->devid = (enum mxs_gpio_id) of_id->data; 307 + port->dev = &pdev->dev; 310 308 port->irq = platform_get_irq(pdev, 0); 311 309 if (port->irq < 0) 312 310 return port->irq; ··· 383 379 .driver = { 384 380 .name = "gpio-mxs", 385 381 .of_match_table = mxs_gpio_dt_ids, 382 + .suppress_bind_attrs = true, 386 383 }, 387 384 .probe = mxs_gpio_probe, 388 385 .id_table = mxs_gpio_ids,
+2
drivers/gpio/gpio-omap.c
··· 1247 1247 if (ret) { 1248 1248 pm_runtime_put_sync(dev); 1249 1249 pm_runtime_disable(dev); 1250 + if (bank->dbck_flag) 1251 + clk_unprepare(bank->dbck); 1250 1252 return ret; 1251 1253 } 1252 1254
+3 -5
drivers/gpio/gpio-pca953x.c
··· 187 187 188 188 static int pca953x_write_regs_16(struct pca953x_chip *chip, int reg, u8 *val) 189 189 { 190 - __le16 word = cpu_to_le16(get_unaligned((u16 *)val)); 190 + u16 word = get_unaligned((u16 *)val); 191 191 192 - return i2c_smbus_write_word_data(chip->client, 193 - reg << 1, (__force u16)word); 192 + return i2c_smbus_write_word_data(chip->client, reg << 1, word); 194 193 } 195 194 196 195 static int pca957x_write_regs_16(struct pca953x_chip *chip, int reg, u8 *val) ··· 240 241 int ret; 241 242 242 243 ret = i2c_smbus_read_word_data(chip->client, reg << 1); 243 - val[0] = (u16)ret & 0xFF; 244 - val[1] = (u16)ret >> 8; 244 + put_unaligned(ret, (u16 *)val); 245 245 246 246 return ret; 247 247 }
+7 -5
drivers/gpio/gpio-pch.c
··· 337 337 { 338 338 struct irq_chip_generic *gc; 339 339 struct irq_chip_type *ct; 340 + int rv; 340 341 341 - gc = irq_alloc_generic_chip("pch_gpio", 1, irq_start, chip->base, 342 - handle_simple_irq); 342 + gc = devm_irq_alloc_generic_chip(chip->dev, "pch_gpio", 1, irq_start, 343 + chip->base, handle_simple_irq); 343 344 if (!gc) 344 345 return -ENOMEM; 345 346 ··· 352 351 ct->chip.irq_unmask = pch_irq_unmask; 353 352 ct->chip.irq_set_type = pch_irq_type; 354 353 355 - irq_setup_generic_chip(gc, IRQ_MSK(num), IRQ_GC_INIT_MASK_CACHE, 356 - IRQ_NOREQUEST | IRQ_NOPROBE, 0); 354 + rv = devm_irq_setup_generic_chip(chip->dev, gc, IRQ_MSK(num), 355 + IRQ_GC_INIT_MASK_CACHE, 356 + IRQ_NOREQUEST | IRQ_NOPROBE, 0); 357 357 358 - return 0; 358 + return rv; 359 359 } 360 360 361 361 static int pch_gpio_probe(struct pci_dev *pdev,
+1 -1
drivers/gpio/gpio-pl061.c
··· 405 405 }; 406 406 #endif 407 407 408 - static struct amba_id pl061_ids[] = { 408 + static const struct amba_id pl061_ids[] = { 409 409 { 410 410 .id = 0x00041061, 411 411 .mask = 0x000fffff,
+5 -3
drivers/gpio/gpio-pxa.c
··· 451 451 for_each_set_bit(n, &gedr, BITS_PER_LONG) { 452 452 loop = 1; 453 453 454 - generic_handle_irq(gpio_to_irq(gpio + n)); 454 + generic_handle_irq( 455 + irq_find_mapping(pchip->irqdomain, 456 + gpio + n)); 455 457 } 456 458 } 457 459 handled += loop; ··· 467 465 struct pxa_gpio_chip *pchip = d; 468 466 469 467 if (in_irq == pchip->irq0) { 470 - generic_handle_irq(gpio_to_irq(0)); 468 + generic_handle_irq(irq_find_mapping(pchip->irqdomain, 0)); 471 469 } else if (in_irq == pchip->irq1) { 472 - generic_handle_irq(gpio_to_irq(1)); 470 + generic_handle_irq(irq_find_mapping(pchip->irqdomain, 1)); 473 471 } else { 474 472 pr_err("%s() unknown irq %d\n", __func__, in_irq); 475 473 return IRQ_NONE;
+10
drivers/gpio/gpio-rcar.c
··· 371 371 /* Gen3 GPIO is identical to Gen2. */ 372 372 .data = &gpio_rcar_info_gen2, 373 373 }, { 374 + .compatible = "renesas,rcar-gen1-gpio", 375 + .data = &gpio_rcar_info_gen1, 376 + }, { 377 + .compatible = "renesas,rcar-gen2-gpio", 378 + .data = &gpio_rcar_info_gen2, 379 + }, { 380 + .compatible = "renesas,rcar-gen3-gpio", 381 + /* Gen3 GPIO is identical to Gen2. */ 382 + .data = &gpio_rcar_info_gen2, 383 + }, { 374 384 .compatible = "renesas,gpio-rcar", 375 385 .data = &gpio_rcar_info_gen1, 376 386 }, {
+10 -4
drivers/gpio/gpio-sta2x11.c
··· 324 324 { 325 325 struct irq_chip_generic *gc; 326 326 struct irq_chip_type *ct; 327 + int rv; 327 328 328 - gc = irq_alloc_generic_chip(KBUILD_MODNAME, 1, chip->irq_base, 329 - chip->reg_base, handle_simple_irq); 329 + gc = devm_irq_alloc_generic_chip(chip->dev, KBUILD_MODNAME, 1, 330 + chip->irq_base, 331 + chip->reg_base, handle_simple_irq); 330 332 if (!gc) 331 333 return -ENOMEM; 332 334 ··· 340 338 ct->chip.irq_enable = gsta_irq_enable; 341 339 342 340 /* FIXME: this makes at most 32 interrupts. Request 0 by now */ 343 - irq_setup_generic_chip(gc, 0 /* IRQ_MSK(GSTA_GPIO_PER_BLOCK) */, 0, 344 - IRQ_NOREQUEST | IRQ_NOPROBE, 0); 341 + rv = devm_irq_setup_generic_chip(chip->dev, gc, 342 + 0 /* IRQ_MSK(GSTA_GPIO_PER_BLOCK) */, 343 + 0, IRQ_NOREQUEST | IRQ_NOPROBE, 0); 344 + if (rv) 345 + return rv; 345 346 346 347 /* Set up all all 128 interrupts: code from setup_generic_chip */ 347 348 { ··· 437 432 static struct platform_driver sta2x11_gpio_platform_driver = { 438 433 .driver = { 439 434 .name = "sta2x11-gpio", 435 + .suppress_bind_attrs = true, 440 436 }, 441 437 .probe = gsta_probe, 442 438 };
+2 -1
drivers/gpio/gpio-tb10x.c
··· 191 191 if (IS_ERR(tb10x_gpio->base)) 192 192 return PTR_ERR(tb10x_gpio->base); 193 193 194 - tb10x_gpio->gc.label = of_node_full_name(dn); 194 + tb10x_gpio->gc.label = 195 + devm_kasprintf(&pdev->dev, GFP_KERNEL, "%pOF", pdev->dev.of_node); 195 196 tb10x_gpio->gc.parent = &pdev->dev; 196 197 tb10x_gpio->gc.owner = THIS_MODULE; 197 198 tb10x_gpio->gc.direction_input = tb10x_gpio_direction_in;
+61 -68
drivers/gpio/gpio-tegra.c
··· 67 67 struct tegra_gpio_info; 68 68 69 69 struct tegra_gpio_bank { 70 - int bank; 71 - int irq; 70 + unsigned int bank; 71 + unsigned int irq; 72 72 spinlock_t lvl_lock[4]; 73 73 spinlock_t dbc_lock[4]; /* Lock for updating debounce count register */ 74 74 #ifdef CONFIG_PM_SLEEP ··· 112 112 return __raw_readl(tgi->regs + reg); 113 113 } 114 114 115 - static int tegra_gpio_compose(int bank, int port, int bit) 115 + static unsigned int tegra_gpio_compose(unsigned int bank, unsigned int port, 116 + unsigned int bit) 116 117 { 117 118 return (bank << 5) | ((port & 0x3) << 3) | (bit & 0x7); 118 119 } 119 120 120 121 static void tegra_gpio_mask_write(struct tegra_gpio_info *tgi, u32 reg, 121 - int gpio, int value) 122 + unsigned int gpio, u32 value) 122 123 { 123 124 u32 val; 124 125 ··· 129 128 tegra_gpio_writel(tgi, val, reg); 130 129 } 131 130 132 - static void tegra_gpio_enable(struct tegra_gpio_info *tgi, int gpio) 131 + static void tegra_gpio_enable(struct tegra_gpio_info *tgi, unsigned int gpio) 133 132 { 134 133 tegra_gpio_mask_write(tgi, GPIO_MSK_CNF(tgi, gpio), gpio, 1); 135 134 } 136 135 137 - static void tegra_gpio_disable(struct tegra_gpio_info *tgi, int gpio) 136 + static void tegra_gpio_disable(struct tegra_gpio_info *tgi, unsigned int gpio) 138 137 { 139 138 tegra_gpio_mask_write(tgi, GPIO_MSK_CNF(tgi, gpio), gpio, 0); 140 139 } 141 140 142 - static int tegra_gpio_request(struct gpio_chip *chip, unsigned offset) 141 + static int tegra_gpio_request(struct gpio_chip *chip, unsigned int offset) 143 142 { 144 143 return pinctrl_request_gpio(offset); 145 144 } 146 145 147 - static void tegra_gpio_free(struct gpio_chip *chip, unsigned offset) 146 + static void tegra_gpio_free(struct gpio_chip *chip, unsigned int offset) 148 147 { 149 148 struct tegra_gpio_info *tgi = gpiochip_get_data(chip); 150 149 ··· 152 151 tegra_gpio_disable(tgi, offset); 153 152 } 154 153 155 - static void tegra_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 154 + static void tegra_gpio_set(struct gpio_chip *chip, unsigned int offset, 155 + int value) 156 156 { 157 157 struct tegra_gpio_info *tgi = gpiochip_get_data(chip); 158 158 159 159 tegra_gpio_mask_write(tgi, GPIO_MSK_OUT(tgi, offset), offset, value); 160 160 } 161 161 162 - static int tegra_gpio_get(struct gpio_chip *chip, unsigned offset) 162 + static int tegra_gpio_get(struct gpio_chip *chip, unsigned int offset) 163 163 { 164 164 struct tegra_gpio_info *tgi = gpiochip_get_data(chip); 165 - int bval = BIT(GPIO_BIT(offset)); 165 + unsigned int bval = BIT(GPIO_BIT(offset)); 166 166 167 167 /* If gpio is in output mode then read from the out value */ 168 168 if (tegra_gpio_readl(tgi, GPIO_OE(tgi, offset)) & bval) ··· 172 170 return !!(tegra_gpio_readl(tgi, GPIO_IN(tgi, offset)) & bval); 173 171 } 174 172 175 - static int tegra_gpio_direction_input(struct gpio_chip *chip, unsigned offset) 173 + static int tegra_gpio_direction_input(struct gpio_chip *chip, 174 + unsigned int offset) 176 175 { 177 176 struct tegra_gpio_info *tgi = gpiochip_get_data(chip); 178 177 ··· 182 179 return 0; 183 180 } 184 181 185 - static int tegra_gpio_direction_output(struct gpio_chip *chip, unsigned offset, 186 - int value) 182 + static int tegra_gpio_direction_output(struct gpio_chip *chip, 183 + unsigned int offset, 184 + int value) 187 185 { 188 186 struct tegra_gpio_info *tgi = gpiochip_get_data(chip); 189 187 ··· 194 190 return 0; 195 191 } 196 192 197 - static int tegra_gpio_get_direction(struct gpio_chip *chip, unsigned offset) 193 + static int tegra_gpio_get_direction(struct gpio_chip *chip, 194 + unsigned int offset) 198 195 { 199 196 struct tegra_gpio_info *tgi = gpiochip_get_data(chip); 200 197 u32 pin_mask = BIT(GPIO_BIT(offset)); ··· 217 212 struct tegra_gpio_bank *bank = &tgi->bank_info[GPIO_BANK(offset)]; 218 213 unsigned int debounce_ms = DIV_ROUND_UP(debounce, 1000); 219 214 unsigned long flags; 220 - int port; 215 + unsigned int port; 221 216 222 217 if (!debounce_ms) { 223 218 tegra_gpio_mask_write(tgi, GPIO_MSK_DBC_EN(tgi, offset), ··· 255 250 return tegra_gpio_set_debounce(chip, offset, debounce); 256 251 } 257 252 258 - static int tegra_gpio_to_irq(struct gpio_chip *chip, unsigned offset) 253 + static int tegra_gpio_to_irq(struct gpio_chip *chip, unsigned int offset) 259 254 { 260 255 struct tegra_gpio_info *tgi = gpiochip_get_data(chip); 261 256 ··· 266 261 { 267 262 struct tegra_gpio_bank *bank = irq_data_get_irq_chip_data(d); 268 263 struct tegra_gpio_info *tgi = bank->tgi; 269 - int gpio = d->hwirq; 264 + unsigned int gpio = d->hwirq; 270 265 271 266 tegra_gpio_writel(tgi, 1 << GPIO_BIT(gpio), GPIO_INT_CLR(tgi, gpio)); 272 267 } ··· 275 270 { 276 271 struct tegra_gpio_bank *bank = irq_data_get_irq_chip_data(d); 277 272 struct tegra_gpio_info *tgi = bank->tgi; 278 - int gpio = d->hwirq; 273 + unsigned int gpio = d->hwirq; 279 274 280 275 tegra_gpio_mask_write(tgi, GPIO_MSK_INT_ENB(tgi, gpio), gpio, 0); 281 276 } ··· 284 279 { 285 280 struct tegra_gpio_bank *bank = irq_data_get_irq_chip_data(d); 286 281 struct tegra_gpio_info *tgi = bank->tgi; 287 - int gpio = d->hwirq; 282 + unsigned int gpio = d->hwirq; 288 283 289 284 tegra_gpio_mask_write(tgi, GPIO_MSK_INT_ENB(tgi, gpio), gpio, 1); 290 285 } 291 286 292 287 static int tegra_gpio_irq_set_type(struct irq_data *d, unsigned int type) 293 288 { 294 - int gpio = d->hwirq; 289 + unsigned int gpio = d->hwirq, port = GPIO_PORT(gpio), lvl_type; 295 290 struct tegra_gpio_bank *bank = irq_data_get_irq_chip_data(d); 296 291 struct tegra_gpio_info *tgi = bank->tgi; 297 - int port = GPIO_PORT(gpio); 298 - int lvl_type; 299 - int val; 300 292 unsigned long flags; 293 + u32 val; 301 294 int ret; 302 295 303 296 switch (type & IRQ_TYPE_SENSE_MASK) { ··· 326 323 ret = gpiochip_lock_as_irq(&tgi->gc, gpio); 327 324 if (ret) { 328 325 dev_err(tgi->dev, 329 - "unable to lock Tegra GPIO %d as IRQ\n", gpio); 326 + "unable to lock Tegra GPIO %u as IRQ\n", gpio); 330 327 return ret; 331 328 } 332 329 ··· 354 351 { 355 352 struct tegra_gpio_bank *bank = irq_data_get_irq_chip_data(d); 356 353 struct tegra_gpio_info *tgi = bank->tgi; 357 - int gpio = d->hwirq; 354 + unsigned int gpio = d->hwirq; 358 355 359 356 gpiochip_unlock_as_irq(&tgi->gc, gpio); 360 357 } 361 358 362 359 static void tegra_gpio_irq_handler(struct irq_desc *desc) 363 360 { 364 - int port; 365 - int pin; 361 + unsigned int port, pin, gpio; 366 362 bool unmasked = false; 367 - int gpio; 368 363 u32 lvl; 369 364 unsigned long sta; 370 365 struct irq_chip *chip = irq_desc_get_chip(desc); ··· 390 389 chained_irq_exit(chip, desc); 391 390 } 392 391 393 - generic_handle_irq(gpio_to_irq(gpio + pin)); 392 + generic_handle_irq(irq_find_mapping(tgi->irq_domain, 393 + gpio + pin)); 394 394 } 395 395 } 396 396 ··· 406 404 struct platform_device *pdev = to_platform_device(dev); 407 405 struct tegra_gpio_info *tgi = platform_get_drvdata(pdev); 408 406 unsigned long flags; 409 - int b; 410 - int p; 407 + unsigned int b, p; 411 408 412 409 local_irq_save(flags); 413 410 ··· 414 413 struct tegra_gpio_bank *bank = &tgi->bank_info[b]; 415 414 416 415 for (p = 0; p < ARRAY_SIZE(bank->oe); p++) { 417 - unsigned int gpio = (b<<5) | (p<<3); 416 + unsigned int gpio = (b << 5) | (p << 3); 417 + 418 418 tegra_gpio_writel(tgi, bank->cnf[p], 419 419 GPIO_CNF(tgi, gpio)); 420 420 ··· 446 444 struct platform_device *pdev = to_platform_device(dev); 447 445 struct tegra_gpio_info *tgi = platform_get_drvdata(pdev); 448 446 unsigned long flags; 449 - int b; 450 - int p; 447 + unsigned int b, p; 451 448 452 449 local_irq_save(flags); 453 450 for (b = 0; b < tgi->bank_count; b++) { 454 451 struct tegra_gpio_bank *bank = &tgi->bank_info[b]; 455 452 456 453 for (p = 0; p < ARRAY_SIZE(bank->oe); p++) { 457 - unsigned int gpio = (b<<5) | (p<<3); 454 + unsigned int gpio = (b << 5) | (p << 3); 455 + 458 456 bank->cnf[p] = tegra_gpio_readl(tgi, 459 457 GPIO_CNF(tgi, gpio)); 460 458 bank->out[p] = tegra_gpio_readl(tgi, ··· 485 483 static int tegra_gpio_irq_set_wake(struct irq_data *d, unsigned int enable) 486 484 { 487 485 struct tegra_gpio_bank *bank = irq_data_get_irq_chip_data(d); 488 - int gpio = d->hwirq; 486 + unsigned int gpio = d->hwirq; 489 487 u32 port, bit, mask; 490 488 491 489 port = GPIO_PORT(gpio); ··· 509 507 static int dbg_gpio_show(struct seq_file *s, void *unused) 510 508 { 511 509 struct tegra_gpio_info *tgi = s->private; 512 - int i; 513 - int j; 510 + unsigned int i, j; 514 511 515 512 for (i = 0; i < tgi->bank_count; i++) { 516 513 for (j = 0; j < 4; j++) { 517 - int gpio = tegra_gpio_compose(i, j, 0); 514 + unsigned int gpio = tegra_gpio_compose(i, j, 0); 515 + 518 516 seq_printf(s, 519 - "%d:%d %02x %02x %02x %02x %02x %02x %06x\n", 517 + "%u:%u %02x %02x %02x %02x %02x %02x %06x\n", 520 518 i, j, 521 519 tegra_gpio_readl(tgi, GPIO_CNF(tgi, gpio)), 522 520 tegra_gpio_readl(tgi, GPIO_OE(tgi, gpio)), ··· 544 542 545 543 static void tegra_gpio_debuginit(struct tegra_gpio_info *tgi) 546 544 { 547 - (void) debugfs_create_file("tegra_gpio", S_IRUGO, 545 + (void) debugfs_create_file("tegra_gpio", 0444, 548 546 NULL, tgi, &debug_fops); 549 547 } 550 548 ··· 568 566 569 567 static int tegra_gpio_probe(struct platform_device *pdev) 570 568 { 571 - const struct tegra_gpio_soc_config *config; 572 569 struct tegra_gpio_info *tgi; 573 570 struct resource *res; 574 571 struct tegra_gpio_bank *bank; 572 + unsigned int gpio, i, j; 575 573 int ret; 576 - int gpio; 577 - int i; 578 - int j; 579 - 580 - config = of_device_get_match_data(&pdev->dev); 581 - if (!config) { 582 - dev_err(&pdev->dev, "Error: No device match found\n"); 583 - return -ENODEV; 584 - } 585 574 586 575 tgi = devm_kzalloc(&pdev->dev, sizeof(*tgi), GFP_KERNEL); 587 576 if (!tgi) 588 577 return -ENODEV; 589 578 590 - tgi->soc = config; 579 + tgi->soc = of_device_get_match_data(&pdev->dev); 591 580 tgi->dev = &pdev->dev; 592 581 593 - for (;;) { 594 - res = platform_get_resource(pdev, IORESOURCE_IRQ, 595 - tgi->bank_count); 596 - if (!res) 597 - break; 598 - tgi->bank_count++; 599 - } 582 + ret = platform_irq_count(pdev); 583 + if (ret < 0) 584 + return ret; 585 + 586 + tgi->bank_count = ret; 587 + 600 588 if (!tgi->bank_count) { 601 589 dev_err(&pdev->dev, "Missing IRQ resource\n"); 602 590 return -ENODEV; ··· 618 626 619 627 platform_set_drvdata(pdev, tgi); 620 628 621 - if (config->debounce_supported) 629 + if (tgi->soc->debounce_supported) 622 630 tgi->gc.set_config = tegra_gpio_set_config; 623 631 624 - tgi->bank_info = devm_kzalloc(&pdev->dev, tgi->bank_count * 632 + tgi->bank_info = devm_kcalloc(&pdev->dev, tgi->bank_count, 625 633 sizeof(*tgi->bank_info), GFP_KERNEL); 626 634 if (!tgi->bank_info) 627 - return -ENODEV; 635 + return -ENOMEM; 628 636 629 637 tgi->irq_domain = irq_domain_add_linear(pdev->dev.of_node, 630 638 tgi->gc.ngpio, ··· 633 641 return -ENODEV; 634 642 635 643 for (i = 0; i < tgi->bank_count; i++) { 636 - res = platform_get_resource(pdev, IORESOURCE_IRQ, i); 637 - if (!res) { 638 - dev_err(&pdev->dev, "Missing IRQ resource\n"); 639 - return -ENODEV; 644 + ret = platform_get_irq(pdev, i); 645 + if (ret < 0) { 646 + dev_err(&pdev->dev, "Missing IRQ resource: %d\n", ret); 647 + return ret; 640 648 } 641 649 642 650 bank = &tgi->bank_info[i]; 643 651 bank->bank = i; 644 - bank->irq = res->start; 652 + bank->irq = ret; 645 653 bank->tgi = tgi; 646 654 } 647 655 ··· 653 661 for (i = 0; i < tgi->bank_count; i++) { 654 662 for (j = 0; j < 4; j++) { 655 663 int gpio = tegra_gpio_compose(i, j, 0); 664 + 656 665 tegra_gpio_writel(tgi, 0x00, GPIO_INT_ENB(tgi, gpio)); 657 666 } 658 667 }
+639
drivers/gpio/gpio-thunderx.c
··· 1 + /* 2 + * This file is subject to the terms and conditions of the GNU General Public 3 + * License. See the file "COPYING" in the main directory of this archive 4 + * for more details. 5 + * 6 + * Copyright (C) 2016, 2017 Cavium Inc. 7 + */ 8 + 9 + #include <linux/bitops.h> 10 + #include <linux/gpio/driver.h> 11 + #include <linux/interrupt.h> 12 + #include <linux/io.h> 13 + #include <linux/irq.h> 14 + #include <linux/kernel.h> 15 + #include <linux/module.h> 16 + #include <linux/pci.h> 17 + #include <linux/spinlock.h> 18 + 19 + 20 + #define GPIO_RX_DAT 0x0 21 + #define GPIO_TX_SET 0x8 22 + #define GPIO_TX_CLR 0x10 23 + #define GPIO_CONST 0x90 24 + #define GPIO_CONST_GPIOS_MASK 0xff 25 + #define GPIO_BIT_CFG 0x400 26 + #define GPIO_BIT_CFG_TX_OE BIT(0) 27 + #define GPIO_BIT_CFG_PIN_XOR BIT(1) 28 + #define GPIO_BIT_CFG_INT_EN BIT(2) 29 + #define GPIO_BIT_CFG_INT_TYPE BIT(3) 30 + #define GPIO_BIT_CFG_FIL_MASK GENMASK(11, 4) 31 + #define GPIO_BIT_CFG_FIL_CNT_SHIFT 4 32 + #define GPIO_BIT_CFG_FIL_SEL_SHIFT 8 33 + #define GPIO_BIT_CFG_TX_OD BIT(12) 34 + #define GPIO_BIT_CFG_PIN_SEL_MASK GENMASK(25, 16) 35 + #define GPIO_INTR 0x800 36 + #define GPIO_INTR_INTR BIT(0) 37 + #define GPIO_INTR_INTR_W1S BIT(1) 38 + #define GPIO_INTR_ENA_W1C BIT(2) 39 + #define GPIO_INTR_ENA_W1S BIT(3) 40 + #define GPIO_2ND_BANK 0x1400 41 + 42 + #define GLITCH_FILTER_400NS ((4u << GPIO_BIT_CFG_FIL_SEL_SHIFT) | \ 43 + (9u << GPIO_BIT_CFG_FIL_CNT_SHIFT)) 44 + 45 + struct thunderx_gpio; 46 + 47 + struct thunderx_line { 48 + struct thunderx_gpio *txgpio; 49 + unsigned int line; 50 + unsigned int fil_bits; 51 + }; 52 + 53 + struct thunderx_gpio { 54 + struct gpio_chip chip; 55 + u8 __iomem *register_base; 56 + struct irq_domain *irqd; 57 + struct msix_entry *msix_entries; /* per line MSI-X */ 58 + struct thunderx_line *line_entries; /* per line irq info */ 59 + raw_spinlock_t lock; 60 + unsigned long invert_mask[2]; 61 + unsigned long od_mask[2]; 62 + int base_msi; 63 + }; 64 + 65 + static unsigned int bit_cfg_reg(unsigned int line) 66 + { 67 + return 8 * line + GPIO_BIT_CFG; 68 + } 69 + 70 + static unsigned int intr_reg(unsigned int line) 71 + { 72 + return 8 * line + GPIO_INTR; 73 + } 74 + 75 + static bool thunderx_gpio_is_gpio_nowarn(struct thunderx_gpio *txgpio, 76 + unsigned int line) 77 + { 78 + u64 bit_cfg = readq(txgpio->register_base + bit_cfg_reg(line)); 79 + 80 + return (bit_cfg & GPIO_BIT_CFG_PIN_SEL_MASK) == 0; 81 + } 82 + 83 + /* 84 + * Check (and WARN) that the pin is available for GPIO. We will not 85 + * allow modification of the state of non-GPIO pins from this driver. 86 + */ 87 + static bool thunderx_gpio_is_gpio(struct thunderx_gpio *txgpio, 88 + unsigned int line) 89 + { 90 + bool rv = thunderx_gpio_is_gpio_nowarn(txgpio, line); 91 + 92 + WARN_RATELIMIT(!rv, "Pin %d not available for GPIO\n", line); 93 + 94 + return rv; 95 + } 96 + 97 + static int thunderx_gpio_request(struct gpio_chip *chip, unsigned int line) 98 + { 99 + struct thunderx_gpio *txgpio = gpiochip_get_data(chip); 100 + 101 + return thunderx_gpio_is_gpio(txgpio, line) ? 0 : -EIO; 102 + } 103 + 104 + static int thunderx_gpio_dir_in(struct gpio_chip *chip, unsigned int line) 105 + { 106 + struct thunderx_gpio *txgpio = gpiochip_get_data(chip); 107 + 108 + if (!thunderx_gpio_is_gpio(txgpio, line)) 109 + return -EIO; 110 + 111 + raw_spin_lock(&txgpio->lock); 112 + clear_bit(line, txgpio->invert_mask); 113 + clear_bit(line, txgpio->od_mask); 114 + writeq(txgpio->line_entries[line].fil_bits, 115 + txgpio->register_base + bit_cfg_reg(line)); 116 + raw_spin_unlock(&txgpio->lock); 117 + return 0; 118 + } 119 + 120 + static void thunderx_gpio_set(struct gpio_chip *chip, unsigned int line, 121 + int value) 122 + { 123 + struct thunderx_gpio *txgpio = gpiochip_get_data(chip); 124 + int bank = line / 64; 125 + int bank_bit = line % 64; 126 + 127 + void __iomem *reg = txgpio->register_base + 128 + (bank * GPIO_2ND_BANK) + (value ? GPIO_TX_SET : GPIO_TX_CLR); 129 + 130 + writeq(BIT_ULL(bank_bit), reg); 131 + } 132 + 133 + static int thunderx_gpio_dir_out(struct gpio_chip *chip, unsigned int line, 134 + int value) 135 + { 136 + struct thunderx_gpio *txgpio = gpiochip_get_data(chip); 137 + u64 bit_cfg = txgpio->line_entries[line].fil_bits | GPIO_BIT_CFG_TX_OE; 138 + 139 + if (!thunderx_gpio_is_gpio(txgpio, line)) 140 + return -EIO; 141 + 142 + raw_spin_lock(&txgpio->lock); 143 + 144 + thunderx_gpio_set(chip, line, value); 145 + 146 + if (test_bit(line, txgpio->invert_mask)) 147 + bit_cfg |= GPIO_BIT_CFG_PIN_XOR; 148 + 149 + if (test_bit(line, txgpio->od_mask)) 150 + bit_cfg |= GPIO_BIT_CFG_TX_OD; 151 + 152 + writeq(bit_cfg, txgpio->register_base + bit_cfg_reg(line)); 153 + 154 + raw_spin_unlock(&txgpio->lock); 155 + return 0; 156 + } 157 + 158 + static int thunderx_gpio_get_direction(struct gpio_chip *chip, unsigned int line) 159 + { 160 + struct thunderx_gpio *txgpio = gpiochip_get_data(chip); 161 + u64 bit_cfg; 162 + 163 + if (!thunderx_gpio_is_gpio_nowarn(txgpio, line)) 164 + /* 165 + * Say it is input for now to avoid WARNing on 166 + * gpiochip_add_data(). We will WARN if someone 167 + * requests it or tries to use it. 168 + */ 169 + return 1; 170 + 171 + bit_cfg = readq(txgpio->register_base + bit_cfg_reg(line)); 172 + 173 + return !(bit_cfg & GPIO_BIT_CFG_TX_OE); 174 + } 175 + 176 + static int thunderx_gpio_set_config(struct gpio_chip *chip, 177 + unsigned int line, 178 + unsigned long cfg) 179 + { 180 + bool orig_invert, orig_od, orig_dat, new_invert, new_od; 181 + u32 arg, sel; 182 + u64 bit_cfg; 183 + int bank = line / 64; 184 + int bank_bit = line % 64; 185 + int ret = -ENOTSUPP; 186 + struct thunderx_gpio *txgpio = gpiochip_get_data(chip); 187 + void __iomem *reg = txgpio->register_base + (bank * GPIO_2ND_BANK) + GPIO_TX_SET; 188 + 189 + if (!thunderx_gpio_is_gpio(txgpio, line)) 190 + return -EIO; 191 + 192 + raw_spin_lock(&txgpio->lock); 193 + orig_invert = test_bit(line, txgpio->invert_mask); 194 + new_invert = orig_invert; 195 + orig_od = test_bit(line, txgpio->od_mask); 196 + new_od = orig_od; 197 + orig_dat = ((readq(reg) >> bank_bit) & 1) ^ orig_invert; 198 + bit_cfg = readq(txgpio->register_base + bit_cfg_reg(line)); 199 + switch (pinconf_to_config_param(cfg)) { 200 + case PIN_CONFIG_DRIVE_OPEN_DRAIN: 201 + /* 202 + * Weird, setting open-drain mode causes signal 203 + * inversion. Note this so we can compensate in the 204 + * dir_out function. 205 + */ 206 + set_bit(line, txgpio->invert_mask); 207 + new_invert = true; 208 + set_bit(line, txgpio->od_mask); 209 + new_od = true; 210 + ret = 0; 211 + break; 212 + case PIN_CONFIG_DRIVE_PUSH_PULL: 213 + clear_bit(line, txgpio->invert_mask); 214 + new_invert = false; 215 + clear_bit(line, txgpio->od_mask); 216 + new_od = false; 217 + ret = 0; 218 + break; 219 + case PIN_CONFIG_INPUT_DEBOUNCE: 220 + arg = pinconf_to_config_argument(cfg); 221 + if (arg > 1228) { /* 15 * 2^15 * 2.5nS maximum */ 222 + ret = -EINVAL; 223 + break; 224 + } 225 + arg *= 400; /* scale to 2.5nS clocks. */ 226 + sel = 0; 227 + while (arg > 15) { 228 + sel++; 229 + arg++; /* always round up */ 230 + arg >>= 1; 231 + } 232 + txgpio->line_entries[line].fil_bits = 233 + (sel << GPIO_BIT_CFG_FIL_SEL_SHIFT) | 234 + (arg << GPIO_BIT_CFG_FIL_CNT_SHIFT); 235 + bit_cfg &= ~GPIO_BIT_CFG_FIL_MASK; 236 + bit_cfg |= txgpio->line_entries[line].fil_bits; 237 + writeq(bit_cfg, txgpio->register_base + bit_cfg_reg(line)); 238 + ret = 0; 239 + break; 240 + default: 241 + break; 242 + } 243 + raw_spin_unlock(&txgpio->lock); 244 + 245 + /* 246 + * If currently output and OPEN_DRAIN changed, install the new 247 + * settings 248 + */ 249 + if ((new_invert != orig_invert || new_od != orig_od) && 250 + (bit_cfg & GPIO_BIT_CFG_TX_OE)) 251 + ret = thunderx_gpio_dir_out(chip, line, orig_dat ^ new_invert); 252 + 253 + return ret; 254 + } 255 + 256 + static int thunderx_gpio_get(struct gpio_chip *chip, unsigned int line) 257 + { 258 + struct thunderx_gpio *txgpio = gpiochip_get_data(chip); 259 + int bank = line / 64; 260 + int bank_bit = line % 64; 261 + u64 read_bits = readq(txgpio->register_base + (bank * GPIO_2ND_BANK) + GPIO_RX_DAT); 262 + u64 masked_bits = read_bits & BIT_ULL(bank_bit); 263 + 264 + if (test_bit(line, txgpio->invert_mask)) 265 + return masked_bits == 0; 266 + else 267 + return masked_bits != 0; 268 + } 269 + 270 + static void thunderx_gpio_set_multiple(struct gpio_chip *chip, 271 + unsigned long *mask, 272 + unsigned long *bits) 273 + { 274 + int bank; 275 + u64 set_bits, clear_bits; 276 + struct thunderx_gpio *txgpio = gpiochip_get_data(chip); 277 + 278 + for (bank = 0; bank <= chip->ngpio / 64; bank++) { 279 + set_bits = bits[bank] & mask[bank]; 280 + clear_bits = ~bits[bank] & mask[bank]; 281 + writeq(set_bits, txgpio->register_base + (bank * GPIO_2ND_BANK) + GPIO_TX_SET); 282 + writeq(clear_bits, txgpio->register_base + (bank * GPIO_2ND_BANK) + GPIO_TX_CLR); 283 + } 284 + } 285 + 286 + static void thunderx_gpio_irq_ack(struct irq_data *data) 287 + { 288 + struct thunderx_line *txline = irq_data_get_irq_chip_data(data); 289 + 290 + writeq(GPIO_INTR_INTR, 291 + txline->txgpio->register_base + intr_reg(txline->line)); 292 + } 293 + 294 + static void thunderx_gpio_irq_mask(struct irq_data *data) 295 + { 296 + struct thunderx_line *txline = irq_data_get_irq_chip_data(data); 297 + 298 + writeq(GPIO_INTR_ENA_W1C, 299 + txline->txgpio->register_base + intr_reg(txline->line)); 300 + } 301 + 302 + static void thunderx_gpio_irq_mask_ack(struct irq_data *data) 303 + { 304 + struct thunderx_line *txline = irq_data_get_irq_chip_data(data); 305 + 306 + writeq(GPIO_INTR_ENA_W1C | GPIO_INTR_INTR, 307 + txline->txgpio->register_base + intr_reg(txline->line)); 308 + } 309 + 310 + static void thunderx_gpio_irq_unmask(struct irq_data *data) 311 + { 312 + struct thunderx_line *txline = irq_data_get_irq_chip_data(data); 313 + 314 + writeq(GPIO_INTR_ENA_W1S, 315 + txline->txgpio->register_base + intr_reg(txline->line)); 316 + } 317 + 318 + static int thunderx_gpio_irq_set_type(struct irq_data *data, 319 + unsigned int flow_type) 320 + { 321 + struct thunderx_line *txline = irq_data_get_irq_chip_data(data); 322 + struct thunderx_gpio *txgpio = txline->txgpio; 323 + u64 bit_cfg; 324 + 325 + irqd_set_trigger_type(data, flow_type); 326 + 327 + bit_cfg = txline->fil_bits | GPIO_BIT_CFG_INT_EN; 328 + 329 + if (flow_type & IRQ_TYPE_EDGE_BOTH) { 330 + irq_set_handler_locked(data, handle_fasteoi_ack_irq); 331 + bit_cfg |= GPIO_BIT_CFG_INT_TYPE; 332 + } else { 333 + irq_set_handler_locked(data, handle_fasteoi_mask_irq); 334 + } 335 + 336 + raw_spin_lock(&txgpio->lock); 337 + if (flow_type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)) { 338 + bit_cfg |= GPIO_BIT_CFG_PIN_XOR; 339 + set_bit(txline->line, txgpio->invert_mask); 340 + } else { 341 + clear_bit(txline->line, txgpio->invert_mask); 342 + } 343 + clear_bit(txline->line, txgpio->od_mask); 344 + writeq(bit_cfg, txgpio->register_base + bit_cfg_reg(txline->line)); 345 + raw_spin_unlock(&txgpio->lock); 346 + 347 + return IRQ_SET_MASK_OK; 348 + } 349 + 350 + static void thunderx_gpio_irq_enable(struct irq_data *data) 351 + { 352 + irq_chip_enable_parent(data); 353 + thunderx_gpio_irq_unmask(data); 354 + } 355 + 356 + static void thunderx_gpio_irq_disable(struct irq_data *data) 357 + { 358 + thunderx_gpio_irq_mask(data); 359 + irq_chip_disable_parent(data); 360 + } 361 + 362 + static int thunderx_gpio_irq_request_resources(struct irq_data *data) 363 + { 364 + struct thunderx_line *txline = irq_data_get_irq_chip_data(data); 365 + struct thunderx_gpio *txgpio = txline->txgpio; 366 + struct irq_data *parent_data = data->parent_data; 367 + int r; 368 + 369 + r = gpiochip_lock_as_irq(&txgpio->chip, txline->line); 370 + if (r) 371 + return r; 372 + 373 + if (parent_data && parent_data->chip->irq_request_resources) { 374 + r = parent_data->chip->irq_request_resources(parent_data); 375 + if (r) 376 + goto error; 377 + } 378 + 379 + return 0; 380 + error: 381 + gpiochip_unlock_as_irq(&txgpio->chip, txline->line); 382 + return r; 383 + } 384 + 385 + static void thunderx_gpio_irq_release_resources(struct irq_data *data) 386 + { 387 + struct thunderx_line *txline = irq_data_get_irq_chip_data(data); 388 + struct thunderx_gpio *txgpio = txline->txgpio; 389 + struct irq_data *parent_data = data->parent_data; 390 + 391 + if (parent_data && parent_data->chip->irq_release_resources) 392 + parent_data->chip->irq_release_resources(parent_data); 393 + 394 + gpiochip_unlock_as_irq(&txgpio->chip, txline->line); 395 + } 396 + 397 + /* 398 + * Interrupts are chained from underlying MSI-X vectors. We have 399 + * these irq_chip functions to be able to handle level triggering 400 + * semantics and other acknowledgment tasks associated with the GPIO 401 + * mechanism. 402 + */ 403 + static struct irq_chip thunderx_gpio_irq_chip = { 404 + .name = "GPIO", 405 + .irq_enable = thunderx_gpio_irq_enable, 406 + .irq_disable = thunderx_gpio_irq_disable, 407 + .irq_ack = thunderx_gpio_irq_ack, 408 + .irq_mask = thunderx_gpio_irq_mask, 409 + .irq_mask_ack = thunderx_gpio_irq_mask_ack, 410 + .irq_unmask = thunderx_gpio_irq_unmask, 411 + .irq_eoi = irq_chip_eoi_parent, 412 + .irq_set_affinity = irq_chip_set_affinity_parent, 413 + .irq_request_resources = thunderx_gpio_irq_request_resources, 414 + .irq_release_resources = thunderx_gpio_irq_release_resources, 415 + .irq_set_type = thunderx_gpio_irq_set_type, 416 + 417 + .flags = IRQCHIP_SET_TYPE_MASKED 418 + }; 419 + 420 + static int thunderx_gpio_irq_map(struct irq_domain *d, unsigned int irq, 421 + irq_hw_number_t hwirq) 422 + { 423 + struct thunderx_gpio *txgpio = d->host_data; 424 + 425 + if (hwirq >= txgpio->chip.ngpio) 426 + return -EINVAL; 427 + if (!thunderx_gpio_is_gpio_nowarn(txgpio, hwirq)) 428 + return -EPERM; 429 + return 0; 430 + } 431 + 432 + static int thunderx_gpio_irq_translate(struct irq_domain *d, 433 + struct irq_fwspec *fwspec, 434 + irq_hw_number_t *hwirq, 435 + unsigned int *type) 436 + { 437 + struct thunderx_gpio *txgpio = d->host_data; 438 + 439 + if (WARN_ON(fwspec->param_count < 2)) 440 + return -EINVAL; 441 + if (fwspec->param[0] >= txgpio->chip.ngpio) 442 + return -EINVAL; 443 + *hwirq = fwspec->param[0]; 444 + *type = fwspec->param[1] & IRQ_TYPE_SENSE_MASK; 445 + return 0; 446 + } 447 + 448 + static int thunderx_gpio_irq_alloc(struct irq_domain *d, unsigned int virq, 449 + unsigned int nr_irqs, void *arg) 450 + { 451 + struct thunderx_line *txline = arg; 452 + 453 + return irq_domain_set_hwirq_and_chip(d, virq, txline->line, 454 + &thunderx_gpio_irq_chip, txline); 455 + } 456 + 457 + static const struct irq_domain_ops thunderx_gpio_irqd_ops = { 458 + .map = thunderx_gpio_irq_map, 459 + .alloc = thunderx_gpio_irq_alloc, 460 + .translate = thunderx_gpio_irq_translate 461 + }; 462 + 463 + static int thunderx_gpio_to_irq(struct gpio_chip *chip, unsigned int offset) 464 + { 465 + struct thunderx_gpio *txgpio = gpiochip_get_data(chip); 466 + 467 + return irq_find_mapping(txgpio->irqd, offset); 468 + } 469 + 470 + static int thunderx_gpio_probe(struct pci_dev *pdev, 471 + const struct pci_device_id *id) 472 + { 473 + void __iomem * const *tbl; 474 + struct device *dev = &pdev->dev; 475 + struct thunderx_gpio *txgpio; 476 + struct gpio_chip *chip; 477 + int ngpio, i; 478 + int err = 0; 479 + 480 + txgpio = devm_kzalloc(dev, sizeof(*txgpio), GFP_KERNEL); 481 + if (!txgpio) 482 + return -ENOMEM; 483 + 484 + raw_spin_lock_init(&txgpio->lock); 485 + chip = &txgpio->chip; 486 + 487 + pci_set_drvdata(pdev, txgpio); 488 + 489 + err = pcim_enable_device(pdev); 490 + if (err) { 491 + dev_err(dev, "Failed to enable PCI device: err %d\n", err); 492 + goto out; 493 + } 494 + 495 + err = pcim_iomap_regions(pdev, 1 << 0, KBUILD_MODNAME); 496 + if (err) { 497 + dev_err(dev, "Failed to iomap PCI device: err %d\n", err); 498 + goto out; 499 + } 500 + 501 + tbl = pcim_iomap_table(pdev); 502 + txgpio->register_base = tbl[0]; 503 + if (!txgpio->register_base) { 504 + dev_err(dev, "Cannot map PCI resource\n"); 505 + err = -ENOMEM; 506 + goto out; 507 + } 508 + 509 + if (pdev->subsystem_device == 0xa10a) { 510 + /* CN88XX has no GPIO_CONST register*/ 511 + ngpio = 50; 512 + txgpio->base_msi = 48; 513 + } else { 514 + u64 c = readq(txgpio->register_base + GPIO_CONST); 515 + 516 + ngpio = c & GPIO_CONST_GPIOS_MASK; 517 + txgpio->base_msi = (c >> 8) & 0xff; 518 + } 519 + 520 + txgpio->msix_entries = devm_kzalloc(dev, 521 + sizeof(struct msix_entry) * ngpio, 522 + GFP_KERNEL); 523 + if (!txgpio->msix_entries) { 524 + err = -ENOMEM; 525 + goto out; 526 + } 527 + 528 + txgpio->line_entries = devm_kzalloc(dev, 529 + sizeof(struct thunderx_line) * ngpio, 530 + GFP_KERNEL); 531 + if (!txgpio->line_entries) { 532 + err = -ENOMEM; 533 + goto out; 534 + } 535 + 536 + for (i = 0; i < ngpio; i++) { 537 + u64 bit_cfg = readq(txgpio->register_base + bit_cfg_reg(i)); 538 + 539 + txgpio->msix_entries[i].entry = txgpio->base_msi + (2 * i); 540 + txgpio->line_entries[i].line = i; 541 + txgpio->line_entries[i].txgpio = txgpio; 542 + /* 543 + * If something has already programmed the pin, use 544 + * the existing glitch filter settings, otherwise go 545 + * to 400nS. 546 + */ 547 + txgpio->line_entries[i].fil_bits = bit_cfg ? 548 + (bit_cfg & GPIO_BIT_CFG_FIL_MASK) : GLITCH_FILTER_400NS; 549 + 550 + if ((bit_cfg & GPIO_BIT_CFG_TX_OE) && (bit_cfg & GPIO_BIT_CFG_TX_OD)) 551 + set_bit(i, txgpio->od_mask); 552 + if (bit_cfg & GPIO_BIT_CFG_PIN_XOR) 553 + set_bit(i, txgpio->invert_mask); 554 + } 555 + 556 + 557 + /* Enable all MSI-X for interrupts on all possible lines. */ 558 + err = pci_enable_msix_range(pdev, txgpio->msix_entries, ngpio, ngpio); 559 + if (err < 0) 560 + goto out; 561 + 562 + /* 563 + * Push GPIO specific irqdomain on hierarchy created as a side 564 + * effect of the pci_enable_msix() 565 + */ 566 + txgpio->irqd = irq_domain_create_hierarchy(irq_get_irq_data(txgpio->msix_entries[0].vector)->domain, 567 + 0, 0, of_node_to_fwnode(dev->of_node), 568 + &thunderx_gpio_irqd_ops, txgpio); 569 + if (!txgpio->irqd) 570 + goto out; 571 + 572 + /* Push on irq_data and the domain for each line. */ 573 + for (i = 0; i < ngpio; i++) { 574 + err = irq_domain_push_irq(txgpio->irqd, 575 + txgpio->msix_entries[i].vector, 576 + &txgpio->line_entries[i]); 577 + if (err < 0) 578 + dev_err(dev, "irq_domain_push_irq: %d\n", err); 579 + } 580 + 581 + chip->label = KBUILD_MODNAME; 582 + chip->parent = dev; 583 + chip->owner = THIS_MODULE; 584 + chip->request = thunderx_gpio_request; 585 + chip->base = -1; /* System allocated */ 586 + chip->can_sleep = false; 587 + chip->ngpio = ngpio; 588 + chip->get_direction = thunderx_gpio_get_direction; 589 + chip->direction_input = thunderx_gpio_dir_in; 590 + chip->get = thunderx_gpio_get; 591 + chip->direction_output = thunderx_gpio_dir_out; 592 + chip->set = thunderx_gpio_set; 593 + chip->set_multiple = thunderx_gpio_set_multiple; 594 + chip->set_config = thunderx_gpio_set_config; 595 + chip->to_irq = thunderx_gpio_to_irq; 596 + err = devm_gpiochip_add_data(dev, chip, txgpio); 597 + if (err) 598 + goto out; 599 + 600 + dev_info(dev, "ThunderX GPIO: %d lines with base %d.\n", 601 + ngpio, chip->base); 602 + return 0; 603 + out: 604 + pci_set_drvdata(pdev, NULL); 605 + return err; 606 + } 607 + 608 + static void thunderx_gpio_remove(struct pci_dev *pdev) 609 + { 610 + int i; 611 + struct thunderx_gpio *txgpio = pci_get_drvdata(pdev); 612 + 613 + for (i = 0; i < txgpio->chip.ngpio; i++) 614 + irq_domain_pop_irq(txgpio->irqd, 615 + txgpio->msix_entries[i].vector); 616 + 617 + irq_domain_remove(txgpio->irqd); 618 + 619 + pci_set_drvdata(pdev, NULL); 620 + } 621 + 622 + static const struct pci_device_id thunderx_gpio_id_table[] = { 623 + { PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, 0xA00A) }, 624 + { 0, } /* end of table */ 625 + }; 626 + 627 + MODULE_DEVICE_TABLE(pci, thunderx_gpio_id_table); 628 + 629 + static struct pci_driver thunderx_gpio_driver = { 630 + .name = KBUILD_MODNAME, 631 + .id_table = thunderx_gpio_id_table, 632 + .probe = thunderx_gpio_probe, 633 + .remove = thunderx_gpio_remove, 634 + }; 635 + 636 + module_pci_driver(thunderx_gpio_driver); 637 + 638 + MODULE_DESCRIPTION("Cavium Inc. ThunderX/OCTEON-TX GPIO Driver"); 639 + MODULE_LICENSE("GPL");
+176
drivers/gpio/gpio-tps68470.c
··· 1 + /* 2 + * GPIO driver for TPS68470 PMIC 3 + * 4 + * Copyright (C) 2017 Intel Corporation 5 + * 6 + * Authors: 7 + * Antti Laakso <antti.laakso@intel.com> 8 + * Tianshu Qiu <tian.shu.qiu@intel.com> 9 + * Jian Xu Zheng <jian.xu.zheng@intel.com> 10 + * Yuning Pu <yuning.pu@intel.com> 11 + * 12 + * This program is free software; you can redistribute it and/or 13 + * modify it under the terms of the GNU General Public License as 14 + * published by the Free Software Foundation version 2. 15 + * 16 + * This program is distributed "as is" WITHOUT ANY WARRANTY of any 17 + * kind, whether express or implied; without even the implied warranty 18 + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 + * GNU General Public License for more details. 20 + */ 21 + 22 + #include <linux/gpio/driver.h> 23 + #include <linux/mfd/tps68470.h> 24 + #include <linux/module.h> 25 + #include <linux/platform_device.h> 26 + #include <linux/regmap.h> 27 + 28 + #define TPS68470_N_LOGIC_OUTPUT 3 29 + #define TPS68470_N_REGULAR_GPIO 7 30 + #define TPS68470_N_GPIO (TPS68470_N_LOGIC_OUTPUT + TPS68470_N_REGULAR_GPIO) 31 + 32 + struct tps68470_gpio_data { 33 + struct regmap *tps68470_regmap; 34 + struct gpio_chip gc; 35 + }; 36 + 37 + static int tps68470_gpio_get(struct gpio_chip *gc, unsigned int offset) 38 + { 39 + struct tps68470_gpio_data *tps68470_gpio = gpiochip_get_data(gc); 40 + struct regmap *regmap = tps68470_gpio->tps68470_regmap; 41 + unsigned int reg = TPS68470_REG_GPDO; 42 + int val, ret; 43 + 44 + if (offset >= TPS68470_N_REGULAR_GPIO) { 45 + offset -= TPS68470_N_REGULAR_GPIO; 46 + reg = TPS68470_REG_SGPO; 47 + } 48 + 49 + ret = regmap_read(regmap, reg, &val); 50 + if (ret) { 51 + dev_err(tps68470_gpio->gc.parent, "reg 0x%x read failed\n", 52 + TPS68470_REG_SGPO); 53 + return ret; 54 + } 55 + return !!(val & BIT(offset)); 56 + } 57 + 58 + /* Return 0 if output, 1 if input */ 59 + static int tps68470_gpio_get_direction(struct gpio_chip *gc, 60 + unsigned int offset) 61 + { 62 + struct tps68470_gpio_data *tps68470_gpio = gpiochip_get_data(gc); 63 + struct regmap *regmap = tps68470_gpio->tps68470_regmap; 64 + int val, ret; 65 + 66 + /* rest are always outputs */ 67 + if (offset >= TPS68470_N_REGULAR_GPIO) 68 + return 0; 69 + 70 + ret = regmap_read(regmap, TPS68470_GPIO_CTL_REG_A(offset), &val); 71 + if (ret) { 72 + dev_err(tps68470_gpio->gc.parent, "reg 0x%x read failed\n", 73 + TPS68470_GPIO_CTL_REG_A(offset)); 74 + return ret; 75 + } 76 + 77 + val &= TPS68470_GPIO_MODE_MASK; 78 + return val >= TPS68470_GPIO_MODE_OUT_CMOS ? 0 : 1; 79 + } 80 + 81 + static void tps68470_gpio_set(struct gpio_chip *gc, unsigned int offset, 82 + int value) 83 + { 84 + struct tps68470_gpio_data *tps68470_gpio = gpiochip_get_data(gc); 85 + struct regmap *regmap = tps68470_gpio->tps68470_regmap; 86 + unsigned int reg = TPS68470_REG_GPDO; 87 + 88 + if (offset >= TPS68470_N_REGULAR_GPIO) { 89 + reg = TPS68470_REG_SGPO; 90 + offset -= TPS68470_N_REGULAR_GPIO; 91 + } 92 + 93 + regmap_update_bits(regmap, reg, BIT(offset), value ? BIT(offset) : 0); 94 + } 95 + 96 + static int tps68470_gpio_output(struct gpio_chip *gc, unsigned int offset, 97 + int value) 98 + { 99 + struct tps68470_gpio_data *tps68470_gpio = gpiochip_get_data(gc); 100 + struct regmap *regmap = tps68470_gpio->tps68470_regmap; 101 + 102 + /* rest are always outputs */ 103 + if (offset >= TPS68470_N_REGULAR_GPIO) 104 + return 0; 105 + 106 + /* Set the initial value */ 107 + tps68470_gpio_set(gc, offset, value); 108 + 109 + return regmap_update_bits(regmap, TPS68470_GPIO_CTL_REG_A(offset), 110 + TPS68470_GPIO_MODE_MASK, 111 + TPS68470_GPIO_MODE_OUT_CMOS); 112 + } 113 + 114 + static int tps68470_gpio_input(struct gpio_chip *gc, unsigned int offset) 115 + { 116 + struct tps68470_gpio_data *tps68470_gpio = gpiochip_get_data(gc); 117 + struct regmap *regmap = tps68470_gpio->tps68470_regmap; 118 + 119 + /* rest are always outputs */ 120 + if (offset >= TPS68470_N_REGULAR_GPIO) 121 + return -EINVAL; 122 + 123 + return regmap_update_bits(regmap, TPS68470_GPIO_CTL_REG_A(offset), 124 + TPS68470_GPIO_MODE_MASK, 0x00); 125 + } 126 + 127 + static const char *tps68470_names[TPS68470_N_GPIO] = { 128 + "gpio.0", "gpio.1", "gpio.2", "gpio.3", 129 + "gpio.4", "gpio.5", "gpio.6", 130 + "s_enable", "s_idle", "s_resetn", 131 + }; 132 + 133 + static int tps68470_gpio_probe(struct platform_device *pdev) 134 + { 135 + struct tps68470_gpio_data *tps68470_gpio; 136 + int ret; 137 + 138 + tps68470_gpio = devm_kzalloc(&pdev->dev, sizeof(*tps68470_gpio), 139 + GFP_KERNEL); 140 + if (!tps68470_gpio) 141 + return -ENOMEM; 142 + 143 + tps68470_gpio->tps68470_regmap = dev_get_drvdata(pdev->dev.parent); 144 + tps68470_gpio->gc.label = "tps68470-gpio"; 145 + tps68470_gpio->gc.owner = THIS_MODULE; 146 + tps68470_gpio->gc.direction_input = tps68470_gpio_input; 147 + tps68470_gpio->gc.direction_output = tps68470_gpio_output; 148 + tps68470_gpio->gc.get = tps68470_gpio_get; 149 + tps68470_gpio->gc.get_direction = tps68470_gpio_get_direction; 150 + tps68470_gpio->gc.set = tps68470_gpio_set; 151 + tps68470_gpio->gc.can_sleep = true; 152 + tps68470_gpio->gc.names = tps68470_names; 153 + tps68470_gpio->gc.ngpio = TPS68470_N_GPIO; 154 + tps68470_gpio->gc.base = -1; 155 + tps68470_gpio->gc.parent = &pdev->dev; 156 + 157 + ret = devm_gpiochip_add_data(&pdev->dev, &tps68470_gpio->gc, 158 + tps68470_gpio); 159 + if (ret < 0) { 160 + dev_err(&pdev->dev, "Failed to register gpio_chip: %d\n", ret); 161 + return ret; 162 + } 163 + 164 + platform_set_drvdata(pdev, tps68470_gpio); 165 + 166 + return ret; 167 + } 168 + 169 + static struct platform_driver tps68470_gpio_driver = { 170 + .driver = { 171 + .name = "tps68470-gpio", 172 + }, 173 + .probe = tps68470_gpio_probe, 174 + }; 175 + 176 + builtin_platform_driver(tps68470_gpio_driver)
-2
drivers/gpio/gpio-twl6040.c
··· 32 32 33 33 #include <linux/mfd/twl6040.h> 34 34 35 - static struct gpio_chip twl6040gpo_chip; 36 - 37 35 static int twl6040gpo_get(struct gpio_chip *chip, unsigned offset) 38 36 { 39 37 struct twl6040 *twl6040 = dev_get_drvdata(chip->parent->parent);
+4 -6
drivers/gpio/gpio-tz1090.c
··· 527 527 528 528 ret = of_property_read_u32(node, "reg", &addr); 529 529 if (ret) { 530 - dev_err(priv->dev, "invalid reg on %s\n", 531 - node->full_name); 530 + dev_err(priv->dev, "invalid reg on %pOF\n", node); 532 531 continue; 533 532 } 534 533 if (addr >= 3) { 535 - dev_err(priv->dev, "index %u in %s out of range\n", 536 - addr, node->full_name); 534 + dev_err(priv->dev, "index %u in %pOF out of range\n", 535 + addr, node); 537 536 continue; 538 537 } 539 538 ··· 542 543 543 544 ret = tz1090_gpio_bank_probe(&info); 544 545 if (ret) { 545 - dev_err(priv->dev, "failure registering %s\n", 546 - node->full_name); 546 + dev_err(priv->dev, "failure registering %pOF\n", node); 547 547 of_node_put(node); 548 548 continue; 549 549 }
+43 -2
drivers/gpio/gpio-vf610.c
··· 30 30 31 31 #define VF610_GPIO_PER_PORT 32 32 32 33 + struct fsl_gpio_soc_data { 34 + /* SoCs has a Port Data Direction Register (PDDR) */ 35 + bool have_paddr; 36 + }; 37 + 33 38 struct vf610_gpio_port { 34 39 struct gpio_chip gc; 35 40 void __iomem *base; 36 41 void __iomem *gpio_base; 42 + const struct fsl_gpio_soc_data *sdata; 37 43 u8 irqc[VF610_GPIO_PER_PORT]; 38 44 int irq; 39 45 }; ··· 49 43 #define GPIO_PCOR 0x08 50 44 #define GPIO_PTOR 0x0c 51 45 #define GPIO_PDIR 0x10 46 + #define GPIO_PDDR 0x14 52 47 53 48 #define PORT_PCR(n) ((n) * 0x4) 54 49 #define PORT_PCR_IRQC_OFFSET 16 ··· 68 61 69 62 static struct irq_chip vf610_gpio_irq_chip; 70 63 64 + static const struct fsl_gpio_soc_data imx_data = { 65 + .have_paddr = true, 66 + }; 67 + 71 68 static const struct of_device_id vf610_gpio_dt_ids[] = { 72 - { .compatible = "fsl,vf610-gpio" }, 69 + { .compatible = "fsl,vf610-gpio", .data = NULL, }, 70 + { .compatible = "fsl,imx7ulp-gpio", .data = &imx_data, }, 73 71 { /* sentinel */ } 74 72 }; 75 73 ··· 91 79 static int vf610_gpio_get(struct gpio_chip *gc, unsigned int gpio) 92 80 { 93 81 struct vf610_gpio_port *port = gpiochip_get_data(gc); 82 + unsigned long mask = BIT(gpio); 83 + void __iomem *addr; 94 84 95 - return !!(vf610_gpio_readl(port->gpio_base + GPIO_PDIR) & BIT(gpio)); 85 + if (port->sdata && port->sdata->have_paddr) { 86 + mask &= vf610_gpio_readl(port->gpio_base + GPIO_PDDR); 87 + addr = mask ? port->gpio_base + GPIO_PDOR : 88 + port->gpio_base + GPIO_PDIR; 89 + return !!(vf610_gpio_readl(addr) & BIT(gpio)); 90 + } else { 91 + return !!(vf610_gpio_readl(port->gpio_base + GPIO_PDIR) 92 + & BIT(gpio)); 93 + } 96 94 } 97 95 98 96 static void vf610_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val) ··· 118 96 119 97 static int vf610_gpio_direction_input(struct gpio_chip *chip, unsigned gpio) 120 98 { 99 + struct vf610_gpio_port *port = gpiochip_get_data(chip); 100 + unsigned long mask = BIT(gpio); 101 + u32 val; 102 + 103 + if (port->sdata && port->sdata->have_paddr) { 104 + val = vf610_gpio_readl(port->gpio_base + GPIO_PDDR); 105 + val &= ~mask; 106 + vf610_gpio_writel(val, port->gpio_base + GPIO_PDDR); 107 + } 108 + 121 109 return pinctrl_gpio_direction_input(chip->base + gpio); 122 110 } 123 111 124 112 static int vf610_gpio_direction_output(struct gpio_chip *chip, unsigned gpio, 125 113 int value) 126 114 { 115 + struct vf610_gpio_port *port = gpiochip_get_data(chip); 116 + unsigned long mask = BIT(gpio); 117 + 118 + if (port->sdata && port->sdata->have_paddr) 119 + vf610_gpio_writel(mask, port->gpio_base + GPIO_PDDR); 120 + 127 121 vf610_gpio_set(chip, gpio, value); 128 122 129 123 return pinctrl_gpio_direction_output(chip->base + gpio); ··· 254 216 255 217 static int vf610_gpio_probe(struct platform_device *pdev) 256 218 { 219 + const struct of_device_id *of_id = of_match_device(vf610_gpio_dt_ids, 220 + &pdev->dev); 257 221 struct device *dev = &pdev->dev; 258 222 struct device_node *np = dev->of_node; 259 223 struct vf610_gpio_port *port; ··· 267 227 if (!port) 268 228 return -ENOMEM; 269 229 230 + port->sdata = of_id->data; 270 231 iores = platform_get_resource(pdev, IORESOURCE_MEM, 0); 271 232 port->base = devm_ioremap_resource(dev, iores); 272 233 if (IS_ERR(port->base))
+2 -2
drivers/gpio/gpio-xilinx.c
··· 360 360 /* Call the OF gpio helper to setup and register the GPIO device */ 361 361 status = of_mm_gpiochip_add_data(np, &chip->mmchip, chip); 362 362 if (status) { 363 - pr_err("%s: error in probe function with status %d\n", 364 - np->full_name, status); 363 + pr_err("%pOF: error in probe function with status %d\n", 364 + np, status); 365 365 return status; 366 366 } 367 367
+1 -1
drivers/gpio/gpio-zevio.c
··· 156 156 return -ENXIO; 157 157 } 158 158 159 - static struct gpio_chip zevio_gpio_chip = { 159 + static const struct gpio_chip zevio_gpio_chip = { 160 160 .direction_input = zevio_gpio_direction_input, 161 161 .direction_output = zevio_gpio_direction_output, 162 162 .set = zevio_gpio_set,
+136 -24
drivers/gpio/gpio-zynq.c
··· 60 60 #define ZYNQ_GPIO_BANK5_PIN_MAX(str) (ZYNQ_GPIO_BANK5_PIN_MIN(str) + \ 61 61 ZYNQ##str##_GPIO_BANK5_NGPIO - 1) 62 62 63 - 64 63 /* Register offsets for the GPIO device */ 65 64 /* LSW Mask & Data -WO */ 66 65 #define ZYNQ_GPIO_DATA_LSW_OFFSET(BANK) (0x000 + (8 * BANK)) 67 66 /* MSW Mask & Data -WO */ 68 67 #define ZYNQ_GPIO_DATA_MSW_OFFSET(BANK) (0x004 + (8 * BANK)) 69 68 /* Data Register-RW */ 69 + #define ZYNQ_GPIO_DATA_OFFSET(BANK) (0x040 + (4 * BANK)) 70 70 #define ZYNQ_GPIO_DATA_RO_OFFSET(BANK) (0x060 + (4 * BANK)) 71 71 /* Direction mode reg-RW */ 72 72 #define ZYNQ_GPIO_DIRM_OFFSET(BANK) (0x204 + (0x40 * BANK)) ··· 98 98 99 99 /* set to differentiate zynq from zynqmp, 0=zynqmp, 1=zynq */ 100 100 #define ZYNQ_GPIO_QUIRK_IS_ZYNQ BIT(0) 101 + #define GPIO_QUIRK_DATA_RO_BUG BIT(1) 102 + 103 + struct gpio_regs { 104 + u32 datamsw[ZYNQMP_GPIO_MAX_BANK]; 105 + u32 datalsw[ZYNQMP_GPIO_MAX_BANK]; 106 + u32 dirm[ZYNQMP_GPIO_MAX_BANK]; 107 + u32 outen[ZYNQMP_GPIO_MAX_BANK]; 108 + u32 int_en[ZYNQMP_GPIO_MAX_BANK]; 109 + u32 int_dis[ZYNQMP_GPIO_MAX_BANK]; 110 + u32 int_type[ZYNQMP_GPIO_MAX_BANK]; 111 + u32 int_polarity[ZYNQMP_GPIO_MAX_BANK]; 112 + u32 int_any[ZYNQMP_GPIO_MAX_BANK]; 113 + }; 101 114 102 115 /** 103 116 * struct zynq_gpio - gpio device private data structure ··· 119 106 * @clk: clock resource for this controller 120 107 * @irq: interrupt for the GPIO device 121 108 * @p_data: pointer to platform data 109 + * @context: context registers 122 110 */ 123 111 struct zynq_gpio { 124 112 struct gpio_chip chip; ··· 127 113 struct clk *clk; 128 114 int irq; 129 115 const struct zynq_platform_data *p_data; 116 + struct gpio_regs context; 130 117 }; 131 118 132 119 /** 133 120 * struct zynq_platform_data - zynq gpio platform data structure 134 121 * @label: string to store in gpio->label 122 + * @quirks: Flags is used to identify the platform 135 123 * @ngpio: max number of gpio pins 136 124 * @max_bank: maximum number of gpio banks 137 125 * @bank_min: this array represents bank's min pin 138 126 * @bank_max: this array represents bank's max pin 139 - */ 127 + */ 140 128 struct zynq_platform_data { 141 129 const char *label; 142 130 u32 quirks; ··· 163 147 } 164 148 165 149 /** 150 + * gpio_data_ro_bug - test if HW bug exists or not 151 + * @gpio: Pointer to driver data struct 152 + * 153 + * Return: 0 if bug doesnot exist, 1 if bug exists. 154 + */ 155 + static int gpio_data_ro_bug(struct zynq_gpio *gpio) 156 + { 157 + return !!(gpio->p_data->quirks & GPIO_QUIRK_DATA_RO_BUG); 158 + } 159 + 160 + /** 166 161 * zynq_gpio_get_bank_pin - Get the bank number and pin number within that bank 167 162 * for a given pin in the GPIO device 168 163 * @pin_num: gpio pin number within the device ··· 181 154 * pin 182 155 * @bank_pin_num: an output parameter used to return pin number within a bank 183 156 * for the given gpio pin 157 + * @gpio: gpio device data structure 184 158 * 185 159 * Returns the bank number and pin offset within the bank. 186 160 */ ··· 194 166 195 167 for (bank = 0; bank < gpio->p_data->max_bank; bank++) { 196 168 if ((pin_num >= gpio->p_data->bank_min[bank]) && 197 - (pin_num <= gpio->p_data->bank_max[bank])) { 198 - *bank_num = bank; 199 - *bank_pin_num = pin_num - 200 - gpio->p_data->bank_min[bank]; 201 - return; 169 + (pin_num <= gpio->p_data->bank_max[bank])) { 170 + *bank_num = bank; 171 + *bank_pin_num = pin_num - 172 + gpio->p_data->bank_min[bank]; 173 + return; 202 174 } 203 175 } 204 176 ··· 225 197 226 198 zynq_gpio_get_bank_pin(pin, &bank_num, &bank_pin_num, gpio); 227 199 228 - data = readl_relaxed(gpio->base_addr + 229 - ZYNQ_GPIO_DATA_RO_OFFSET(bank_num)); 230 - 200 + if (gpio_data_ro_bug(gpio)) { 201 + if (zynq_gpio_is_zynq(gpio)) { 202 + if (bank_num <= 1) { 203 + data = readl_relaxed(gpio->base_addr + 204 + ZYNQ_GPIO_DATA_RO_OFFSET(bank_num)); 205 + } else { 206 + data = readl_relaxed(gpio->base_addr + 207 + ZYNQ_GPIO_DATA_OFFSET(bank_num)); 208 + } 209 + } else { 210 + if (bank_num <= 2) { 211 + data = readl_relaxed(gpio->base_addr + 212 + ZYNQ_GPIO_DATA_RO_OFFSET(bank_num)); 213 + } else { 214 + data = readl_relaxed(gpio->base_addr + 215 + ZYNQ_GPIO_DATA_OFFSET(bank_num)); 216 + } 217 + } 218 + } else { 219 + data = readl_relaxed(gpio->base_addr + 220 + ZYNQ_GPIO_DATA_RO_OFFSET(bank_num)); 221 + } 231 222 return (data >> bank_pin_num) & 1; 232 223 } 233 224 ··· 310 263 * as inputs. 311 264 */ 312 265 if (zynq_gpio_is_zynq(gpio) && bank_num == 0 && 313 - (bank_pin_num == 7 || bank_pin_num == 8)) 266 + (bank_pin_num == 7 || bank_pin_num == 8)) 314 267 return -EINVAL; 315 268 316 269 /* clear the bit in direction mode reg to set the pin as input */ ··· 511 464 writel_relaxed(int_any, 512 465 gpio->base_addr + ZYNQ_GPIO_INTANY_OFFSET(bank_num)); 513 466 514 - if (type & IRQ_TYPE_LEVEL_MASK) { 467 + if (type & IRQ_TYPE_LEVEL_MASK) 515 468 irq_set_chip_handler_name_locked(irq_data, 516 - &zynq_gpio_level_irqchip, handle_fasteoi_irq, NULL); 517 - } else { 469 + &zynq_gpio_level_irqchip, 470 + handle_fasteoi_irq, NULL); 471 + else 518 472 irq_set_chip_handler_name_locked(irq_data, 519 - &zynq_gpio_edge_irqchip, handle_level_irq, NULL); 520 - } 473 + &zynq_gpio_edge_irqchip, 474 + handle_level_irq, NULL); 521 475 522 476 return 0; 523 477 } ··· 578 530 579 531 /** 580 532 * zynq_gpio_irqhandler - IRQ handler for the gpio banks of a gpio device 581 - * @irq: irq number of the gpio bank where interrupt has occurred 582 533 * @desc: irq descriptor instance of the 'irq' 583 534 * 584 535 * This function reads the Interrupt Status Register of each bank to get the ··· 607 560 chained_irq_exit(irqchip, desc); 608 561 } 609 562 563 + static void zynq_gpio_save_context(struct zynq_gpio *gpio) 564 + { 565 + unsigned int bank_num; 566 + 567 + for (bank_num = 0; bank_num < gpio->p_data->max_bank; bank_num++) { 568 + gpio->context.datalsw[bank_num] = 569 + readl_relaxed(gpio->base_addr + 570 + ZYNQ_GPIO_DATA_LSW_OFFSET(bank_num)); 571 + gpio->context.datamsw[bank_num] = 572 + readl_relaxed(gpio->base_addr + 573 + ZYNQ_GPIO_DATA_MSW_OFFSET(bank_num)); 574 + gpio->context.dirm[bank_num] = readl_relaxed(gpio->base_addr + 575 + ZYNQ_GPIO_DIRM_OFFSET(bank_num)); 576 + gpio->context.int_en[bank_num] = readl_relaxed(gpio->base_addr + 577 + ZYNQ_GPIO_INTMASK_OFFSET(bank_num)); 578 + gpio->context.int_type[bank_num] = 579 + readl_relaxed(gpio->base_addr + 580 + ZYNQ_GPIO_INTTYPE_OFFSET(bank_num)); 581 + gpio->context.int_polarity[bank_num] = 582 + readl_relaxed(gpio->base_addr + 583 + ZYNQ_GPIO_INTPOL_OFFSET(bank_num)); 584 + gpio->context.int_any[bank_num] = 585 + readl_relaxed(gpio->base_addr + 586 + ZYNQ_GPIO_INTANY_OFFSET(bank_num)); 587 + } 588 + } 589 + 590 + static void zynq_gpio_restore_context(struct zynq_gpio *gpio) 591 + { 592 + unsigned int bank_num; 593 + 594 + for (bank_num = 0; bank_num < gpio->p_data->max_bank; bank_num++) { 595 + writel_relaxed(gpio->context.datalsw[bank_num], 596 + gpio->base_addr + 597 + ZYNQ_GPIO_DATA_LSW_OFFSET(bank_num)); 598 + writel_relaxed(gpio->context.datamsw[bank_num], 599 + gpio->base_addr + 600 + ZYNQ_GPIO_DATA_MSW_OFFSET(bank_num)); 601 + writel_relaxed(gpio->context.dirm[bank_num], 602 + gpio->base_addr + 603 + ZYNQ_GPIO_DIRM_OFFSET(bank_num)); 604 + writel_relaxed(gpio->context.int_en[bank_num], 605 + gpio->base_addr + 606 + ZYNQ_GPIO_INTEN_OFFSET(bank_num)); 607 + writel_relaxed(gpio->context.int_type[bank_num], 608 + gpio->base_addr + 609 + ZYNQ_GPIO_INTTYPE_OFFSET(bank_num)); 610 + writel_relaxed(gpio->context.int_polarity[bank_num], 611 + gpio->base_addr + 612 + ZYNQ_GPIO_INTPOL_OFFSET(bank_num)); 613 + writel_relaxed(gpio->context.int_any[bank_num], 614 + gpio->base_addr + 615 + ZYNQ_GPIO_INTANY_OFFSET(bank_num)); 616 + } 617 + } 618 + 610 619 static int __maybe_unused zynq_gpio_suspend(struct device *dev) 611 620 { 612 621 struct platform_device *pdev = to_platform_device(dev); 613 622 int irq = platform_get_irq(pdev, 0); 614 623 struct irq_data *data = irq_get_irq_data(irq); 624 + struct zynq_gpio *gpio = platform_get_drvdata(pdev); 615 625 616 - if (!irqd_is_wakeup_set(data)) 626 + if (!irqd_is_wakeup_set(data)) { 627 + zynq_gpio_save_context(gpio); 617 628 return pm_runtime_force_suspend(dev); 629 + } 618 630 619 631 return 0; 620 632 } ··· 683 577 struct platform_device *pdev = to_platform_device(dev); 684 578 int irq = platform_get_irq(pdev, 0); 685 579 struct irq_data *data = irq_get_irq_data(irq); 580 + struct zynq_gpio *gpio = platform_get_drvdata(pdev); 581 + int ret; 686 582 687 - if (!irqd_is_wakeup_set(data)) 688 - return pm_runtime_force_resume(dev); 583 + if (!irqd_is_wakeup_set(data)) { 584 + ret = pm_runtime_force_resume(dev); 585 + zynq_gpio_restore_context(gpio); 586 + return ret; 587 + } 689 588 690 589 return 0; 691 590 } ··· 713 602 return clk_prepare_enable(gpio->clk); 714 603 } 715 604 716 - static int zynq_gpio_request(struct gpio_chip *chip, unsigned offset) 605 + static int zynq_gpio_request(struct gpio_chip *chip, unsigned int offset) 717 606 { 718 607 int ret; 719 608 ··· 726 615 return ret < 0 ? ret : 0; 727 616 } 728 617 729 - static void zynq_gpio_free(struct gpio_chip *chip, unsigned offset) 618 + static void zynq_gpio_free(struct gpio_chip *chip, unsigned int offset) 730 619 { 731 620 pm_runtime_put(chip->parent); 732 621 } ··· 734 623 static const struct dev_pm_ops zynq_gpio_dev_pm_ops = { 735 624 SET_SYSTEM_SLEEP_PM_OPS(zynq_gpio_suspend, zynq_gpio_resume) 736 625 SET_RUNTIME_PM_OPS(zynq_gpio_runtime_suspend, 737 - zynq_gpio_runtime_resume, NULL) 626 + zynq_gpio_runtime_resume, NULL) 738 627 }; 739 628 740 629 static const struct zynq_platform_data zynqmp_gpio_def = { 741 630 .label = "zynqmp_gpio", 631 + .quirks = GPIO_QUIRK_DATA_RO_BUG, 742 632 .ngpio = ZYNQMP_GPIO_NR_GPIOS, 743 633 .max_bank = ZYNQMP_GPIO_MAX_BANK, 744 634 .bank_min[0] = ZYNQ_GPIO_BANK0_PIN_MIN(MP), ··· 758 646 759 647 static const struct zynq_platform_data zynq_gpio_def = { 760 648 .label = "zynq_gpio", 761 - .quirks = ZYNQ_GPIO_QUIRK_IS_ZYNQ, 649 + .quirks = ZYNQ_GPIO_QUIRK_IS_ZYNQ | GPIO_QUIRK_DATA_RO_BUG, 762 650 .ngpio = ZYNQ_GPIO_NR_GPIOS, 763 651 .max_bank = ZYNQ_GPIO_MAX_BANK, 764 652 .bank_min[0] = ZYNQ_GPIO_BANK0_PIN_MIN(),
+2 -2
drivers/gpio/gpiolib-acpi.c
··· 61 61 #ifdef CONFIG_PINCTRL 62 62 /** 63 63 * acpi_gpiochip_pin_to_gpio_offset() - translates ACPI GPIO to Linux GPIO 64 - * @chip: GPIO chip 64 + * @gdev: GPIO device 65 65 * @pin: ACPI GPIO pin number from GpioIo/GpioInt resource 66 66 * 67 67 * Function takes ACPI GpioIo/GpioInt pin number as a parameter and ··· 763 763 * The function is idempotent, though each time it runs it will configure GPIO 764 764 * pin direction according to the flags in GpioInt resource. 765 765 * 766 - * Return: Linux IRQ number (>%0) on success, negative errno on failure. 766 + * Return: Linux IRQ number (> %0) on success, negative errno on failure. 767 767 */ 768 768 int acpi_dev_gpio_irq_get(struct acpi_device *adev, int index) 769 769 {
+17 -19
drivers/gpio/gpiolib-of.c
··· 78 78 ret = of_parse_phandle_with_args(np, propname, "#gpio-cells", index, 79 79 &gpiospec); 80 80 if (ret) { 81 - pr_debug("%s: can't parse '%s' property of node '%s[%d]'\n", 82 - __func__, propname, np->full_name, index); 81 + pr_debug("%s: can't parse '%s' property of node '%pOF[%d]'\n", 82 + __func__, propname, np, index); 83 83 return ERR_PTR(ret); 84 84 } 85 85 ··· 93 93 if (IS_ERR(desc)) 94 94 goto out; 95 95 96 - pr_debug("%s: parsed '%s' property of node '%s[%d]' - status (%d)\n", 97 - __func__, propname, np->full_name, index, 96 + pr_debug("%s: parsed '%s' property of node '%pOF[%d]' - status (%d)\n", 97 + __func__, propname, np, index, 98 98 PTR_ERR_OR_ZERO(desc)); 99 99 100 100 out: ··· 273 273 } 274 274 275 275 /** 276 - * of_gpio_simple_xlate - translate gpio_spec to the GPIO number and flags 276 + * of_gpio_simple_xlate - translate gpiospec to the GPIO number and flags 277 277 * @gc: pointer to the gpio_chip structure 278 - * @np: device node of the GPIO chip 279 - * @gpio_spec: gpio specifier as found in the device tree 278 + * @gpiospec: GPIO specifier as found in the device tree 280 279 * @flags: a flags pointer to fill in 281 280 * 282 281 * This is simple translation function, suitable for the most 1:1 mapped 283 - * gpio chips. This function performs only one sanity check: whether gpio 282 + * GPIO chips. This function performs only one sanity check: whether GPIO 284 283 * is less than ngpios (that is specified in the gpio_chip). 285 284 */ 286 285 int of_gpio_simple_xlate(struct gpio_chip *gc, ··· 336 337 int ret = -ENOMEM; 337 338 struct gpio_chip *gc = &mm_gc->gc; 338 339 339 - gc->label = kstrdup(np->full_name, GFP_KERNEL); 340 + gc->label = kasprintf(GFP_KERNEL, "%pOF", np); 340 341 if (!gc->label) 341 342 goto err0; 342 343 ··· 361 362 err1: 362 363 kfree(gc->label); 363 364 err0: 364 - pr_err("%s: GPIO chip registration failed with status %d\n", 365 - np->full_name, ret); 365 + pr_err("%pOF: GPIO chip registration failed with status %d\n", np, ret); 366 366 return ret; 367 367 } 368 368 EXPORT_SYMBOL(of_mm_gpiochip_add_data); ··· 416 418 group_names_propname, 417 419 index, &name); 418 420 if (strlen(name)) { 419 - pr_err("%s: Group name of numeric GPIO ranges must be the empty string.\n", 420 - np->full_name); 421 + pr_err("%pOF: Group name of numeric GPIO ranges must be the empty string.\n", 422 + np); 421 423 break; 422 424 } 423 425 } ··· 432 434 } else { 433 435 /* npins == 0: special range */ 434 436 if (pinspec.args[1]) { 435 - pr_err("%s: Illegal gpio-range format.\n", 436 - np->full_name); 437 + pr_err("%pOF: Illegal gpio-range format.\n", 438 + np); 437 439 break; 438 440 } 439 441 440 442 if (!group_names) { 441 - pr_err("%s: GPIO group range requested but no %s property.\n", 442 - np->full_name, group_names_propname); 443 + pr_err("%pOF: GPIO group range requested but no %s property.\n", 444 + np, group_names_propname); 443 445 break; 444 446 } 445 447 ··· 450 452 break; 451 453 452 454 if (!strlen(name)) { 453 - pr_err("%s: Group name of GPIO group range cannot be the empty string.\n", 454 - np->full_name); 455 + pr_err("%pOF: Group name of GPIO group range cannot be the empty string.\n", 456 + np); 455 457 break; 456 458 } 457 459
+4 -4
drivers/gpio/gpiolib-sysfs.c
··· 540 540 541 541 /** 542 542 * gpiod_export - export a GPIO through sysfs 543 - * @gpio: gpio to make available, already requested 544 - * @direction_may_change: true if userspace may change gpio direction 543 + * @desc: GPIO to make available, already requested 544 + * @direction_may_change: true if userspace may change GPIO direction 545 545 * Context: arch_initcall or later 546 546 * 547 547 * When drivers want to make a GPIO accessible to userspace after they ··· 649 649 * gpiod_export_link - create a sysfs link to an exported GPIO node 650 650 * @dev: device under which to create symlink 651 651 * @name: name of the symlink 652 - * @gpio: gpio to create symlink to, already exported 652 + * @desc: GPIO to create symlink to, already exported 653 653 * 654 654 * Set up a symlink from /sys/.../dev/name to /sys/class/gpio/gpioN 655 655 * node. Caller is responsible for unlinking. ··· 680 680 681 681 /** 682 682 * gpiod_unexport - reverse effect of gpiod_export() 683 - * @gpio: gpio to make unavailable 683 + * @desc: GPIO to make unavailable 684 684 * 685 685 * This is implicit on gpiod_free(). 686 686 */
+84 -46
drivers/gpio/gpiolib.c
··· 84 84 } 85 85 86 86 /** 87 - * Convert a GPIO number to its descriptor 87 + * gpio_to_desc - Convert a GPIO number to its descriptor 88 + * @gpio: global GPIO number 89 + * 90 + * Returns: 91 + * The GPIO descriptor associated with the given GPIO, or %NULL if no GPIO 92 + * with the given number exists in the system. 88 93 */ 89 94 struct gpio_desc *gpio_to_desc(unsigned gpio) 90 95 { ··· 116 111 EXPORT_SYMBOL_GPL(gpio_to_desc); 117 112 118 113 /** 119 - * Get the GPIO descriptor corresponding to the given hw number for this chip. 114 + * gpiochip_get_desc - get the GPIO descriptor corresponding to the given 115 + * hardware number for this chip 116 + * @chip: GPIO chip 117 + * @hwnum: hardware number of the GPIO for this chip 118 + * 119 + * Returns: 120 + * A pointer to the GPIO descriptor or %ERR_PTR(-EINVAL) if no GPIO exists 121 + * in the given chip for the specified hardware number. 120 122 */ 121 123 struct gpio_desc *gpiochip_get_desc(struct gpio_chip *chip, 122 124 u16 hwnum) ··· 137 125 } 138 126 139 127 /** 140 - * Convert a GPIO descriptor to the integer namespace. 128 + * desc_to_gpio - convert a GPIO descriptor to the integer namespace 129 + * @desc: GPIO descriptor 130 + * 141 131 * This should disappear in the future but is needed since we still 142 - * use GPIO numbers for error messages and sysfs nodes 132 + * use GPIO numbers for error messages and sysfs nodes. 133 + * 134 + * Returns: 135 + * The global GPIO number for the GPIO specified by its descriptor. 143 136 */ 144 137 int desc_to_gpio(const struct gpio_desc *desc) 145 138 { ··· 271 254 return -EBUSY; 272 255 } 273 256 274 - /** 257 + /* 275 258 * Convert a GPIO name to its descriptor 276 259 */ 277 260 static struct gpio_desc *gpio_name_to_desc(const char * const name) ··· 895 878 return ret; 896 879 } 897 880 898 - /** 881 + /* 899 882 * gpio_ioctl() - ioctl handler for the GPIO chardev 900 883 */ 901 884 static long gpio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) ··· 1094 1077 /** 1095 1078 * gpiochip_add_data() - register a gpio_chip 1096 1079 * @chip: the chip to register, with chip->base initialized 1097 - * Context: potentially before irqs will work 1080 + * @data: driver-private data associated with this chip 1098 1081 * 1099 - * Returns a negative errno if the chip can't be registered, such as 1100 - * because the chip->base is invalid or already associated with a 1101 - * different chip. Otherwise it returns zero as a success code. 1082 + * Context: potentially before irqs will work 1102 1083 * 1103 1084 * When gpiochip_add_data() is called very early during boot, so that GPIOs 1104 1085 * can be freely used, the chip->parent device must be registered before ··· 1108 1093 * 1109 1094 * If chip->base is negative, this requests dynamic assignment of 1110 1095 * a range of valid GPIOs. 1096 + * 1097 + * Returns: 1098 + * A negative errno if the chip can't be registered, such as because the 1099 + * chip->base is invalid or already associated with a different chip. 1100 + * Otherwise it returns zero as a success code. 1111 1101 */ 1112 1102 int gpiochip_add_data(struct gpio_chip *chip, void *data) 1113 1103 { ··· 1307 1287 1308 1288 /** 1309 1289 * gpiochip_get_data() - get per-subdriver data for the chip 1290 + * @chip: GPIO chip 1291 + * 1292 + * Returns: 1293 + * The per-subdriver data for the chip. 1310 1294 */ 1311 1295 void *gpiochip_get_data(struct gpio_chip *chip) 1312 1296 { ··· 1394 1370 * devm_gpiochip_add_data() - Resource manager piochip_add_data() 1395 1371 * @dev: the device pointer on which irq_chip belongs to. 1396 1372 * @chip: the chip to register, with chip->base initialized 1373 + * @data: driver-private data associated with this chip 1374 + * 1397 1375 * Context: potentially before irqs will work 1398 1376 * 1399 - * Returns a negative errno if the chip can't be registered, such as 1400 - * because the chip->base is invalid or already associated with a 1401 - * different chip. Otherwise it returns zero as a success code. 1402 - * 1403 1377 * The gpio chip automatically be released when the device is unbound. 1378 + * 1379 + * Returns: 1380 + * A negative errno if the chip can't be registered, such as because the 1381 + * chip->base is invalid or already associated with a different chip. 1382 + * Otherwise it returns zero as a success code. 1404 1383 */ 1405 1384 int devm_gpiochip_add_data(struct device *dev, struct gpio_chip *chip, 1406 1385 void *data) ··· 1449 1422 /** 1450 1423 * gpiochip_find() - iterator for locating a specific gpio_chip 1451 1424 * @data: data to pass to match function 1452 - * @callback: Callback function to check gpio_chip 1425 + * @match: Callback function to check gpio_chip 1453 1426 * 1454 1427 * Similar to bus_find_device. It returns a reference to a gpio_chip as 1455 1428 * determined by a user supplied @match callback. The callback should return ··· 1631 1604 { 1632 1605 struct gpio_chip *chip = d->host_data; 1633 1606 1607 + if (!gpiochip_irqchip_irq_valid(chip, hwirq)) 1608 + return -ENXIO; 1609 + 1634 1610 irq_set_chip_data(irq, chip); 1635 1611 /* 1636 1612 * This lock class tells lockdep that GPIO irqs are in a different ··· 1700 1670 1701 1671 static int gpiochip_to_irq(struct gpio_chip *chip, unsigned offset) 1702 1672 { 1703 - return irq_find_mapping(chip->irqdomain, offset); 1673 + if (!gpiochip_irqchip_irq_valid(chip, offset)) 1674 + return -ENXIO; 1675 + return irq_create_mapping(chip->irqdomain, offset); 1704 1676 } 1705 1677 1706 1678 /** ··· 1778 1746 struct lock_class_key *lock_key) 1779 1747 { 1780 1748 struct device_node *of_node; 1781 - bool irq_base_set = false; 1782 - unsigned int offset; 1783 - unsigned irq_base = 0; 1784 1749 1785 1750 if (!gpiochip || !irqchip) 1786 1751 return -EINVAL; ··· 1803 1774 * conflicting triggers. Tell the user, and reset to NONE. 1804 1775 */ 1805 1776 if (WARN(of_node && type != IRQ_TYPE_NONE, 1806 - "%s: Ignoring %d default trigger\n", of_node->full_name, type)) 1777 + "%pOF: Ignoring %d default trigger\n", of_node, type)) 1807 1778 type = IRQ_TYPE_NONE; 1808 1779 if (has_acpi_companion(gpiochip->parent) && type != IRQ_TYPE_NONE) { 1809 1780 acpi_handle_warn(ACPI_HANDLE(gpiochip->parent), ··· 1832 1803 !irqchip->irq_release_resources) { 1833 1804 irqchip->irq_request_resources = gpiochip_irq_reqres; 1834 1805 irqchip->irq_release_resources = gpiochip_irq_relres; 1835 - } 1836 - 1837 - /* 1838 - * Prepare the mapping since the irqchip shall be orthogonal to 1839 - * any gpiochip calls. If the first_irq was zero, this is 1840 - * necessary to allocate descriptors for all IRQs. 1841 - */ 1842 - for (offset = 0; offset < gpiochip->ngpio; offset++) { 1843 - if (!gpiochip_irqchip_irq_valid(gpiochip, offset)) 1844 - continue; 1845 - irq_base = irq_create_mapping(gpiochip->irqdomain, offset); 1846 - if (!irq_base_set) { 1847 - /* 1848 - * Store the base into the gpiochip to be used when 1849 - * unmapping the irqs. 1850 - */ 1851 - gpiochip->irq_base = irq_base; 1852 - irq_base_set = true; 1853 - } 1854 1806 } 1855 1807 1856 1808 acpi_gpiochip_request_interrupts(gpiochip); ··· 1940 1930 /** 1941 1931 * gpiochip_add_pin_range() - add a range for GPIO <-> pin mapping 1942 1932 * @chip: the gpiochip to add the range for 1943 - * @pinctrl_name: the dev_name() of the pin controller to map to 1933 + * @pinctl_name: the dev_name() of the pin controller to map to 1944 1934 * @gpio_offset: the start offset in the current gpio_chip number space 1945 1935 * @pin_offset: the start offset in the pin controller number space 1946 1936 * @npins: the number of pins from the offset of each pin space (GPIO and 1947 1937 * pin controller) to accumulate in this range 1938 + * 1939 + * Returns: 1940 + * 0 on success, or a negative error-code on failure. 1948 1941 */ 1949 1942 int gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name, 1950 1943 unsigned int gpio_offset, unsigned int pin_offset, ··· 2192 2179 2193 2180 /** 2194 2181 * gpiochip_request_own_desc - Allow GPIO chip to request its own descriptor 2195 - * @desc: GPIO descriptor to request 2182 + * @chip: GPIO chip 2183 + * @hwnum: hardware number of the GPIO for which to request the descriptor 2196 2184 * @label: label for the GPIO 2197 2185 * 2198 2186 * Function allows GPIO chip drivers to request and use their own GPIO ··· 2201 2187 * function will not increase reference count of the GPIO chip module. This 2202 2188 * allows the GPIO chip module to be unloaded as needed (we assume that the 2203 2189 * GPIO chip driver handles freeing the GPIOs it has requested). 2190 + * 2191 + * Returns: 2192 + * A pointer to the GPIO descriptor, or an ERR_PTR()-encoded negative error 2193 + * code on failure. 2204 2194 */ 2205 2195 struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *chip, u16 hwnum, 2206 2196 const char *label) ··· 2386 2368 EXPORT_SYMBOL_GPL(gpiod_direction_output); 2387 2369 2388 2370 /** 2389 - * gpiod_set_debounce - sets @debounce time for a @gpio 2390 - * @gpio: the gpio to set debounce time 2391 - * @debounce: debounce time is microseconds 2371 + * gpiod_set_debounce - sets @debounce time for a GPIO 2372 + * @desc: descriptor of the GPIO for which to set debounce time 2373 + * @debounce: debounce time in microseconds 2392 2374 * 2393 - * returns -ENOTSUPP if the controller does not support setting 2394 - * debounce. 2375 + * Returns: 2376 + * 0 on success, %-ENOTSUPP if the controller doesn't support setting the 2377 + * debounce time. 2395 2378 */ 2396 2379 int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce) 2397 2380 { ··· 3000 2981 EXPORT_SYMBOL_GPL(gpiod_set_raw_array_value_cansleep); 3001 2982 3002 2983 /** 2984 + * gpiod_add_lookup_tables() - register GPIO device consumers 2985 + * @tables: list of tables of consumers to register 2986 + * @n: number of tables in the list 2987 + */ 2988 + void gpiod_add_lookup_tables(struct gpiod_lookup_table **tables, size_t n) 2989 + { 2990 + unsigned int i; 2991 + 2992 + mutex_lock(&gpio_lookup_lock); 2993 + 2994 + for (i = 0; i < n; i++) 2995 + list_add_tail(&tables[i]->list, &gpio_lookup_list); 2996 + 2997 + mutex_unlock(&gpio_lookup_lock); 2998 + } 2999 + 3000 + /** 3003 3001 * gpiod_set_array_value_cansleep() - assign values to an array of GPIOs 3004 3002 * @array_size: number of elements in the descriptor / value arrays 3005 3003 * @desc_array: array of GPIO descriptors whose values will be assigned ··· 3358 3322 * @propname: name of the firmware property representing the GPIO 3359 3323 * @index: index of the GPIO to obtain in the consumer 3360 3324 * @dflags: GPIO initialization flags 3325 + * @label: label to attach to the requested GPIO 3361 3326 * 3362 3327 * This function can be used for drivers that get their configuration 3363 3328 * from firmware. ··· 3367 3330 * underlying firmware interface and then makes sure that the GPIO 3368 3331 * descriptor is requested before it is returned to the caller. 3369 3332 * 3333 + * Returns: 3370 3334 * On successful request the GPIO pin is configured in accordance with 3371 3335 * provided @dflags. 3372 3336 *
+1 -1
drivers/gpio/gpiolib.h
··· 219 219 /* 220 220 * Return the GPIO number of the passed descriptor relative to its chip 221 221 */ 222 - static int __maybe_unused gpio_chip_hwgpio(const struct gpio_desc *desc) 222 + static inline int gpio_chip_hwgpio(const struct gpio_desc *desc) 223 223 { 224 224 return desc - &desc->gdev->descs[0]; 225 225 }
+21 -3
include/linux/gpio/driver.h
··· 180 180 * If CONFIG_OF is enabled, then all GPIO controllers described in the 181 181 * device tree automatically may have an OF translation 182 182 */ 183 + 184 + /** 185 + * @of_node: 186 + * 187 + * Pointer to a device tree node representing this GPIO controller. 188 + */ 183 189 struct device_node *of_node; 184 - int of_gpio_n_cells; 190 + 191 + /** 192 + * @of_gpio_n_cells: 193 + * 194 + * Number of cells used to form the GPIO specifier. 195 + */ 196 + unsigned int of_gpio_n_cells; 197 + 198 + /** 199 + * @of_xlate: 200 + * 201 + * Callback to translate a device tree GPIO specifier into a chip- 202 + * relative GPIO number and flags. 203 + */ 185 204 int (*of_xlate)(struct gpio_chip *gc, 186 205 const struct of_phandle_args *gpiospec, u32 *flags); 187 206 #endif ··· 346 327 347 328 /** 348 329 * struct gpio_pin_range - pin range controlled by a gpio chip 349 - * @head: list for maintaining set of pin ranges, used internally 330 + * @node: list for maintaining set of pin ranges, used internally 350 331 * @pctldev: pinctrl device which handles corresponding pins 351 332 * @range: actual range of pins controlled by a gpio controller 352 333 */ 353 - 354 334 struct gpio_pin_range { 355 335 struct list_head node; 356 336 struct pinctrl_dev *pctldev;
+3
include/linux/gpio/machine.h
··· 60 60 61 61 #ifdef CONFIG_GPIOLIB 62 62 void gpiod_add_lookup_table(struct gpiod_lookup_table *table); 63 + void gpiod_add_lookup_tables(struct gpiod_lookup_table **tables, size_t n); 63 64 void gpiod_remove_lookup_table(struct gpiod_lookup_table *table); 64 65 #else 65 66 static inline 66 67 void gpiod_add_lookup_table(struct gpiod_lookup_table *table) {} 68 + static inline 69 + void gpiod_add_lookup_tables(struct gpiod_lookup_table **tables, size_t n) {} 67 70 static inline 68 71 void gpiod_remove_lookup_table(struct gpiod_lookup_table *table) {} 69 72 #endif