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

Merge tag 'gpio-updates-for-v5.12' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux

Pull gpio updates from Bartosz Golaszewski:
"It's been a relatively calm release cycle and we're actually removing
more code than we're adding.

Summary:

- new driver for the Toshiba Visconti platform

- rework of interrupt handling in gpio-tegra

- updates for GPIO selftests: we're now using the character device to
perform the subsystem checks

- support for a new rcar variant + some code refactoring

- refactoring of gpio-ep93xx

- SPDX License identifier has been updated in the uapi header so that
userspace programs bundling it can become fully REUSE-compliant

- improvements to pwm handling in gpio-mvebu

- support for interrupt handling and power management for gpio-xilinx
as well as some code refactoring

- support for a new chip variant in gpio-pca953x

- removal of drivers: zte xs & intel-mid and removal of leftovers
from intel-msic

- impovements to intel drivers pulled from Andy Shevchenko

- improvements to the gpio-aggregator virtual GPIO driver

- and several minor tweaks and fixes to code and documentation all
over the place"

* tag 'gpio-updates-for-v5.12' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux: (71 commits)
gpio: pcf857x: Fix missing first interrupt
gpio: ep93xx: refactor base IRQ number
gpio: ep93xx: refactor ep93xx_gpio_add_bank
gpio: ep93xx: Fix typo s/hierarchial/hierarchical
gpio: ep93xx: drop to_irq binding
gpio: ep93xx: Fix wrong irq numbers in port F
gpio: uapi: use the preferred SPDX license identifier
gpio: gpio-xilinx: Add check if width exceeds 32
gpio: gpio-xilinx: Add support for suspend and resume
gpio: gpio-xilinx: Add interrupt support
gpio: gpio-xilinx: Reduce spinlock array to array
gpio: gpio-xilinx: Simplify with dev_err_probe()
gpio: msic: Drop driver from Makefile
gpio: wcove: Split out to_ireg() helper and deduplicate the code
gpio: wcove: Switch to use regmap_set_bits(), regmap_clear_bits()
gpio: wcove: Get rid of error prone casting in IRQ handler
gpio: intel-mid: Remove driver for deprecated platform
gpio: msic: Remove driver for deprecated platform
gpio: aggregator: Remove trailing comma in terminator entries
gpio: aggregator: Use compound literal from the header
...

+1817 -1403
+8
Documentation/devicetree/bindings/arm/marvell/ap80x-system-controller.txt
··· 80 80 81 81 - offset: offset address inside the syscon block 82 82 83 + Optional properties: 84 + 85 + - marvell,pwm-offset: offset address of PWM duration control registers inside 86 + the syscon block 87 + 83 88 Example: 84 89 ap_syscon: system-controller@6f4000 { 85 90 compatible = "syscon", "simple-mfd"; ··· 106 101 gpio-controller; 107 102 #gpio-cells = <2>; 108 103 gpio-ranges = <&ap_pinctrl 0 0 19>; 104 + marvell,pwm-offset = <0x10c0>; 105 + #pwm-cells = <2>; 106 + clocks = <&ap_clk 3>; 109 107 }; 110 108 }; 111 109
+1
Documentation/devicetree/bindings/gpio/gpio-davinci.txt
··· 7 7 "ti,k2g-gpio", "ti,keystone-gpio": for 66AK2G 8 8 "ti,am654-gpio", "ti,keystone-gpio": for TI K3 AM654 9 9 "ti,j721e-gpio", "ti,keystone-gpio": for J721E SoCs 10 + "ti,am64-gpio", "ti,keystone-gpio": for AM64 SoCs 10 11 11 12 - reg: Physical base address of the controller and the size of memory mapped 12 13 registers.
+2 -1
Documentation/devicetree/bindings/gpio/gpio-pca95xx.yaml
··· 32 32 - maxim,max7327 33 33 - nxp,pca6416 34 34 - nxp,pca9505 35 + - nxp,pca9506 35 36 - nxp,pca9534 36 37 - nxp,pca9535 37 38 - nxp,pca9536 ··· 71 70 72 71 gpio-line-names: 73 72 minItems: 1 74 - maxItems: 32 73 + maxItems: 40 75 74 76 75 interrupts: 77 76 maxItems: 1
+3
Documentation/devicetree/bindings/gpio/renesas,rcar-gpio.yaml
··· 48 48 - renesas,gpio-r8a77995 # R-Car D3 49 49 - const: renesas,rcar-gen3-gpio # R-Car Gen3 or RZ/G2 50 50 51 + - items: 52 + - const: renesas,gpio-r8a779a0 # R-Car V3U 53 + 51 54 reg: 52 55 maxItems: 1 53 56
+70
Documentation/devicetree/bindings/gpio/toshiba,gpio-visconti.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/gpio/toshiba,gpio-visconti.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Toshiba Visconti ARM SoCs GPIO controller 8 + 9 + maintainers: 10 + - Nobuhiro Iwamatsu <nobuhiro1.iwamatsu@toshiba.co.jp> 11 + 12 + properties: 13 + compatible: 14 + items: 15 + - const: toshiba,gpio-tmpv7708 16 + 17 + reg: 18 + maxItems: 1 19 + 20 + "#gpio-cells": 21 + const: 2 22 + 23 + gpio-ranges: true 24 + 25 + gpio-controller: true 26 + 27 + interrupt-controller: true 28 + 29 + "#interrupt-cells": 30 + const: 2 31 + 32 + interrupts: 33 + description: 34 + interrupt mapping one per GPIO. 35 + minItems: 16 36 + maxItems: 16 37 + 38 + required: 39 + - compatible 40 + - reg 41 + - "#gpio-cells" 42 + - gpio-ranges 43 + - gpio-controller 44 + - interrupt-controller 45 + - "#interrupt-cells" 46 + - interrupt-parent 47 + 48 + additionalProperties: false 49 + 50 + examples: 51 + - | 52 + #include <dt-bindings/interrupt-controller/irq.h> 53 + #include <dt-bindings/interrupt-controller/arm-gic.h> 54 + 55 + soc { 56 + #address-cells = <2>; 57 + #size-cells = <2>; 58 + 59 + gpio: gpio@28020000 { 60 + compatible = "toshiba,gpio-tmpv7708"; 61 + reg = <0 0x28020000 0 0x1000>; 62 + #gpio-cells = <0x2>; 63 + gpio-ranges = <&pmux 0 0 32>; 64 + gpio-controller; 65 + interrupt-controller; 66 + #interrupt-cells = <2>; 67 + interrupt-parent = <&gic>; 68 + }; 69 + }; 70 + ...
-24
Documentation/devicetree/bindings/gpio/zx296702-gpio.txt
··· 1 - ZTE ZX296702 GPIO controller 2 - 3 - Required properties: 4 - - compatible : "zte,zx296702-gpio" 5 - - #gpio-cells : Should be two. The first cell is the pin number and the 6 - second cell is used to specify optional parameters: 7 - - bit 0 specifies polarity (0 for normal, 1 for inverted) 8 - - gpio-controller : Marks the device node as a GPIO controller. 9 - - interrupts : Interrupt mapping for GPIO IRQ. 10 - - gpio-ranges : Interaction with the PINCTRL subsystem. 11 - 12 - gpio1: gpio@b008040 { 13 - compatible = "zte,zx296702-gpio"; 14 - reg = <0xb008040 0x40>; 15 - gpio-controller; 16 - #gpio-cells = <2>; 17 - gpio-ranges = < &pmx0 0 54 2 &pmx0 2 59 14>; 18 - interrupts = <GIC_SPI 26 IRQ_TYPE_LEVEL_HIGH>; 19 - interrupt-parent = <&intc>; 20 - interrupt-controller; 21 - #interrupt-cells = <2>; 22 - clock-names = "gpio_pclk"; 23 - clocks = <&lsp0clk ZX296702_GPIO_CLK>; 24 - };
+3 -2
Documentation/driver-api/gpio/consumer.rst
··· 361 361 can be expected. If simultaneous access is not possible the GPIOs will be 362 362 accessed sequentially. 363 363 364 - The functions take three arguments: 364 + The functions take four arguments: 365 + 365 366 * array_size - the number of array elements 366 367 * desc_array - an array of GPIO descriptors 367 368 * array_info - optional information obtained from gpiod_get_array() 368 369 * value_bitmap - a bitmap to store the GPIOs' values (get) or 369 - a bitmap of values to assign to the GPIOs (set) 370 + a bitmap of values to assign to the GPIOs (set) 370 371 371 372 The descriptor array can be obtained using the gpiod_get_array() function 372 373 or one of its variants. If the group of descriptors returned by that function
+4 -4
Documentation/driver-api/gpio/intro.rst
··· 106 106 support it, there's a common idiom you can use to emulate it with any GPIO pin 107 107 that can be used as either an input or an output: 108 108 109 - LOW: gpiod_direction_output(gpio, 0) ... this drives the signal and overrides 110 - the pullup. 109 + **LOW**: ``gpiod_direction_output(gpio, 0)`` ... this drives the signal and 110 + overrides the pullup. 111 111 112 - HIGH: gpiod_direction_input(gpio) ... this turns off the output, so the pullup 113 - (or some other device) controls the signal. 112 + **HIGH**: ``gpiod_direction_input(gpio)`` ... this turns off the output, so 113 + the pullup (or some other device) controls the signal. 114 114 115 115 The same logic can be applied to emulate open source signaling, by driving the 116 116 high signal and configuring the GPIO as input for low. This open drain/open
+2
MAINTAINERS
··· 2609 2609 T: git git://git.kernel.org/pub/scm/linux/kernel/git/iwamatsu/linux-visconti.git 2610 2610 F: Documentation/devicetree/bindings/arm/toshiba.yaml 2611 2611 F: Documentation/devicetree/bindings/net/toshiba,visconti-dwmac.yaml 2612 + F: Documentation/devicetree/bindings/gpio/toshiba,gpio-visconti.yaml 2612 2613 F: Documentation/devicetree/bindings/pinctrl/toshiba,tmpv7700-pinctrl.yaml 2613 2614 F: Documentation/devicetree/bindings/watchdog/toshiba,visconti-wdt.yaml 2614 2615 F: arch/arm64/boot/dts/toshiba/ 2615 2616 F: drivers/net/ethernet/stmicro/stmmac/dwmac-visconti.c 2617 + F: drivers/gpio/gpio-visconti.c 2616 2618 F: drivers/pinctrl/visconti/ 2617 2619 F: drivers/watchdog/visconti_wdt.c 2618 2620 N: visconti
+17 -13
drivers/gpio/Kconfig
··· 487 487 Say yes here to support the PXA GPIO device 488 488 489 489 config GPIO_RCAR 490 - tristate "Renesas R-Car GPIO" 490 + tristate "Renesas R-Car and RZ/G GPIO support" 491 491 depends on ARCH_RENESAS || COMPILE_TEST 492 492 select GPIOLIB_IRQCHIP 493 493 help 494 - Say yes here to support GPIO on Renesas R-Car SoCs. 494 + Say yes here to support GPIO on Renesas R-Car or RZ/G SoCs. 495 495 496 496 config GPIO_RDA 497 497 bool "RDA Micro GPIO controller support" ··· 595 595 select OF_GPIO 596 596 597 597 config GPIO_TEGRA 598 - bool "NVIDIA Tegra GPIO support" 598 + tristate "NVIDIA Tegra GPIO support" 599 599 default ARCH_TEGRA 600 600 depends on ARCH_TEGRA || COMPILE_TEST 601 601 depends on OF_GPIO ··· 648 648 help 649 649 Say yes here to support Vybrid vf610 GPIOs. 650 650 651 + config GPIO_VISCONTI 652 + tristate "Toshiba Visconti GPIO support" 653 + depends on ARCH_VISCONTI || COMPILE_TEST 654 + depends on OF_GPIO 655 + select GPIOLIB_IRQCHIP 656 + select GPIO_GENERIC 657 + select IRQ_DOMAIN_HIERARCHY 658 + help 659 + Say yes here to support GPIO on Tohisba Visconti. 660 + 651 661 config GPIO_VR41XX 652 662 tristate "NEC VR4100 series General-purpose I/O Uint support" 653 663 depends on CPU_VR41XX ··· 680 670 tristate "Qualcomm Technologies Inc WCD9340/WCD9341 gpio controller driver" 681 671 depends on MFD_WCD934X && OF_GPIO 682 672 help 683 - This driver is to supprot GPIO block found on the Qualcomm Technologies 673 + This driver is to support GPIO block found on the Qualcomm Technologies 684 674 Inc WCD9340/WCD9341 Audio Codec. 685 675 686 676 config GPIO_XGENE ··· 704 694 705 695 config GPIO_XILINX 706 696 tristate "Xilinx GPIO support" 697 + select GPIOLIB_IRQCHIP 698 + depends on OF_GPIO 707 699 help 708 700 Say yes here to support the Xilinx FPGA GPIO device 709 701 ··· 742 730 select GPIOLIB_IRQCHIP 743 731 help 744 732 Say yes here to support Xilinx Zynq GPIO controller. 745 - 746 - config GPIO_ZX 747 - bool "ZTE ZX GPIO support" 748 - depends on ARCH_ZX || COMPILE_TEST 749 - select GPIOLIB_IRQCHIP 750 - help 751 - Say yes here to support the GPIO device on ZTE ZX SoCs. 752 733 753 734 config GPIO_LOONGSON1 754 735 tristate "Loongson1 GPIO support" ··· 1628 1623 select IRQ_SIM 1629 1624 help 1630 1625 This enables GPIO Testing driver, which provides a way to test GPIO 1631 - subsystem through sysfs(or char device) and debugfs. GPIO_SYSFS 1632 - must be selected for this test. 1626 + subsystem through sysfs (or char device) and debugfs. 1633 1627 User could use it through the script in 1634 1628 tools/testing/selftests/gpio/gpio-mockup.sh. Reference the usage in 1635 1629 it.
+1 -2
drivers/gpio/Makefile
··· 102 102 obj-$(CONFIG_GPIO_MPC5200) += gpio-mpc5200.o 103 103 obj-$(CONFIG_GPIO_MPC8XXX) += gpio-mpc8xxx.o 104 104 obj-$(CONFIG_GPIO_MSC313) += gpio-msc313.o 105 - obj-$(CONFIG_GPIO_MSIC) += gpio-msic.o 106 105 obj-$(CONFIG_GPIO_MT7621) += gpio-mt7621.o 107 106 obj-$(CONFIG_GPIO_MVEBU) += gpio-mvebu.o 108 107 obj-$(CONFIG_GPIO_MXC) += gpio-mxc.o ··· 162 163 obj-$(CONFIG_GPIO_UNIPHIER) += gpio-uniphier.o 163 164 obj-$(CONFIG_GPIO_VF610) += gpio-vf610.o 164 165 obj-$(CONFIG_GPIO_VIPERBOARD) += gpio-viperboard.o 166 + obj-$(CONFIG_GPIO_VISCONTI) += gpio-visconti.o 165 167 obj-$(CONFIG_GPIO_VR41XX) += gpio-vr41xx.o 166 168 obj-$(CONFIG_GPIO_VX855) += gpio-vx855.o 167 169 obj-$(CONFIG_GPIO_WCD934X) += gpio-wcd934x.o ··· 179 179 obj-$(CONFIG_GPIO_XRA1403) += gpio-xra1403.o 180 180 obj-$(CONFIG_GPIO_XTENSA) += gpio-xtensa.o 181 181 obj-$(CONFIG_GPIO_ZEVIO) += gpio-zevio.o 182 - obj-$(CONFIG_GPIO_ZX) += gpio-zx.o 183 182 obj-$(CONFIG_GPIO_ZYNQ) += gpio-zynq.o
+6 -34
drivers/gpio/gpio-aggregator.c
··· 62 62 return start; 63 63 } 64 64 65 - static bool isrange(const char *s) 66 - { 67 - size_t n; 68 - 69 - if (IS_ERR_OR_NULL(s)) 70 - return false; 71 - 72 - while (1) { 73 - n = strspn(s, "0123456789"); 74 - if (!n) 75 - return false; 76 - 77 - s += n; 78 - 79 - switch (*s++) { 80 - case '\0': 81 - return true; 82 - 83 - case '-': 84 - case ',': 85 - break; 86 - 87 - default: 88 - return false; 89 - } 90 - } 91 - } 92 - 93 65 static int aggr_add_gpio(struct gpio_aggregator *aggr, const char *key, 94 66 int hwnum, unsigned int *n) 95 67 { ··· 72 100 if (!lookups) 73 101 return -ENOMEM; 74 102 75 - lookups->table[*n] = 76 - (struct gpiod_lookup)GPIO_LOOKUP_IDX(key, hwnum, NULL, *n, 0); 103 + lookups->table[*n] = GPIO_LOOKUP_IDX(key, hwnum, NULL, *n, 0); 77 104 78 105 (*n)++; 79 106 memset(&lookups->table[*n], 0, sizeof(lookups->table[*n])); ··· 83 112 84 113 static int aggr_parse(struct gpio_aggregator *aggr) 85 114 { 115 + char *name, *offsets, *p; 86 116 char *args = aggr->args; 87 117 unsigned long *bitmap; 88 118 unsigned int i, n = 0; 89 - char *name, *offsets; 90 119 int error = 0; 91 120 92 121 bitmap = bitmap_alloc(ARCH_NR_GPIOS, GFP_KERNEL); ··· 101 130 goto free_bitmap; 102 131 } 103 132 104 - if (!isrange(offsets)) { 133 + p = get_options(offsets, 0, &error); 134 + if (error == 0 || *p) { 105 135 /* Named GPIO line */ 106 136 error = aggr_add_gpio(aggr, name, U16_MAX, &n); 107 137 if (error) ··· 243 271 static struct attribute *gpio_aggregator_attrs[] = { 244 272 &driver_attr_new_device.attr, 245 273 &driver_attr_delete_device.attr, 246 - NULL, 274 + NULL 247 275 }; 248 276 ATTRIBUTE_GROUPS(gpio_aggregator); 249 277 ··· 517 545 * Add GPIO-operated devices controlled from userspace below, 518 546 * or use "driver_override" in sysfs 519 547 */ 520 - {}, 548 + {} 521 549 }; 522 550 MODULE_DEVICE_TABLE(of, gpio_aggregator_dt_ids); 523 551 #endif
+27 -32
drivers/gpio/gpio-bd70528.c
··· 12 12 #define GPIO_OUT_REG(offset) (BD70528_REG_GPIO1_OUT + (offset) * 2) 13 13 14 14 struct bd70528_gpio { 15 - struct rohm_regmap_dev chip; 15 + struct regmap *regmap; 16 + struct device *dev; 16 17 struct gpio_chip gpio; 17 18 }; 18 19 ··· 36 35 val = BD70528_DEBOUNCE_50MS; 37 36 break; 38 37 default: 39 - dev_err(bdgpio->chip.dev, 38 + dev_err(bdgpio->dev, 40 39 "Invalid debounce value %u\n", debounce); 41 40 return -EINVAL; 42 41 } 43 - return regmap_update_bits(bdgpio->chip.regmap, GPIO_IN_REG(offset), 42 + return regmap_update_bits(bdgpio->regmap, GPIO_IN_REG(offset), 44 43 BD70528_DEBOUNCE_MASK, val); 45 44 } 46 45 ··· 50 49 int val, ret; 51 50 52 51 /* Do we need to do something to IRQs here? */ 53 - ret = regmap_read(bdgpio->chip.regmap, GPIO_OUT_REG(offset), &val); 52 + ret = regmap_read(bdgpio->regmap, GPIO_OUT_REG(offset), &val); 54 53 if (ret) { 55 - dev_err(bdgpio->chip.dev, "Could not read gpio direction\n"); 54 + dev_err(bdgpio->dev, "Could not read gpio direction\n"); 56 55 return ret; 57 56 } 58 57 if (val & BD70528_GPIO_OUT_EN_MASK) ··· 68 67 69 68 switch (pinconf_to_config_param(config)) { 70 69 case PIN_CONFIG_DRIVE_OPEN_DRAIN: 71 - return regmap_update_bits(bdgpio->chip.regmap, 70 + return regmap_update_bits(bdgpio->regmap, 72 71 GPIO_OUT_REG(offset), 73 72 BD70528_GPIO_DRIVE_MASK, 74 73 BD70528_GPIO_OPEN_DRAIN); 75 74 break; 76 75 case PIN_CONFIG_DRIVE_PUSH_PULL: 77 - return regmap_update_bits(bdgpio->chip.regmap, 76 + return regmap_update_bits(bdgpio->regmap, 78 77 GPIO_OUT_REG(offset), 79 78 BD70528_GPIO_DRIVE_MASK, 80 79 BD70528_GPIO_PUSH_PULL); ··· 94 93 struct bd70528_gpio *bdgpio = gpiochip_get_data(chip); 95 94 96 95 /* Do we need to do something to IRQs here? */ 97 - return regmap_update_bits(bdgpio->chip.regmap, GPIO_OUT_REG(offset), 96 + return regmap_update_bits(bdgpio->regmap, GPIO_OUT_REG(offset), 98 97 BD70528_GPIO_OUT_EN_MASK, 99 98 BD70528_GPIO_OUT_DISABLE); 100 99 } ··· 106 105 struct bd70528_gpio *bdgpio = gpiochip_get_data(chip); 107 106 u8 val = (value) ? BD70528_GPIO_OUT_HI : BD70528_GPIO_OUT_LO; 108 107 109 - ret = regmap_update_bits(bdgpio->chip.regmap, GPIO_OUT_REG(offset), 108 + ret = regmap_update_bits(bdgpio->regmap, GPIO_OUT_REG(offset), 110 109 BD70528_GPIO_OUT_MASK, val); 111 110 if (ret) 112 - dev_err(bdgpio->chip.dev, "Could not set gpio to %d\n", value); 111 + dev_err(bdgpio->dev, "Could not set gpio to %d\n", value); 113 112 } 114 113 115 114 static int bd70528_direction_output(struct gpio_chip *chip, unsigned int offset, ··· 118 117 struct bd70528_gpio *bdgpio = gpiochip_get_data(chip); 119 118 120 119 bd70528_gpio_set(chip, offset, value); 121 - return regmap_update_bits(bdgpio->chip.regmap, GPIO_OUT_REG(offset), 120 + return regmap_update_bits(bdgpio->regmap, GPIO_OUT_REG(offset), 122 121 BD70528_GPIO_OUT_EN_MASK, 123 122 BD70528_GPIO_OUT_ENABLE); 124 123 } ··· 130 129 int ret; 131 130 unsigned int val; 132 131 133 - ret = regmap_read(bdgpio->chip.regmap, GPIO_OUT_REG(offset), &val); 132 + ret = regmap_read(bdgpio->regmap, GPIO_OUT_REG(offset), &val); 134 133 if (!ret) 135 134 ret = !!(val & BD70528_GPIO_OUT_MASK); 136 135 else 137 - dev_err(bdgpio->chip.dev, "GPIO (out) state read failed\n"); 136 + dev_err(bdgpio->dev, "GPIO (out) state read failed\n"); 138 137 139 138 return ret; 140 139 } ··· 144 143 unsigned int val; 145 144 int ret; 146 145 147 - ret = regmap_read(bdgpio->chip.regmap, BD70528_REG_GPIO_STATE, &val); 146 + ret = regmap_read(bdgpio->regmap, BD70528_REG_GPIO_STATE, &val); 148 147 149 148 if (!ret) 150 149 ret = !(val & GPIO_IN_STATE_MASK(offset)); 151 150 else 152 - dev_err(bdgpio->chip.dev, "GPIO (in) state read failed\n"); 151 + dev_err(bdgpio->dev, "GPIO (in) state read failed\n"); 153 152 154 153 return ret; 155 154 } ··· 174 173 else if (ret == GPIO_LINE_DIRECTION_IN) 175 174 ret = bd70528_gpio_get_i(bdgpio, offset); 176 175 else 177 - dev_err(bdgpio->chip.dev, "failed to read GPIO direction\n"); 176 + dev_err(bdgpio->dev, "failed to read GPIO direction\n"); 178 177 179 178 return ret; 180 179 } 181 180 182 181 static int bd70528_probe(struct platform_device *pdev) 183 182 { 183 + struct device *dev = &pdev->dev; 184 184 struct bd70528_gpio *bdgpio; 185 - struct rohm_regmap_dev *bd70528; 186 185 int ret; 187 186 188 - bd70528 = dev_get_drvdata(pdev->dev.parent); 189 - if (!bd70528) { 190 - dev_err(&pdev->dev, "No MFD driver data\n"); 191 - return -EINVAL; 192 - } 193 - 194 - bdgpio = devm_kzalloc(&pdev->dev, sizeof(*bdgpio), 195 - GFP_KERNEL); 187 + bdgpio = devm_kzalloc(dev, sizeof(*bdgpio), GFP_KERNEL); 196 188 if (!bdgpio) 197 189 return -ENOMEM; 198 - bdgpio->chip.dev = &pdev->dev; 199 - bdgpio->gpio.parent = pdev->dev.parent; 190 + bdgpio->dev = dev; 191 + bdgpio->gpio.parent = dev->parent; 200 192 bdgpio->gpio.label = "bd70528-gpio"; 201 193 bdgpio->gpio.owner = THIS_MODULE; 202 194 bdgpio->gpio.get_direction = bd70528_get_direction; ··· 202 208 bdgpio->gpio.ngpio = 4; 203 209 bdgpio->gpio.base = -1; 204 210 #ifdef CONFIG_OF_GPIO 205 - bdgpio->gpio.of_node = pdev->dev.parent->of_node; 211 + bdgpio->gpio.of_node = dev->parent->of_node; 206 212 #endif 207 - bdgpio->chip.regmap = bd70528->regmap; 213 + bdgpio->regmap = dev_get_regmap(dev->parent, NULL); 214 + if (!bdgpio->regmap) 215 + return -ENODEV; 208 216 209 - ret = devm_gpiochip_add_data(&pdev->dev, &bdgpio->gpio, 210 - bdgpio); 217 + ret = devm_gpiochip_add_data(dev, &bdgpio->gpio, bdgpio); 211 218 if (ret) 212 - dev_err(&pdev->dev, "gpio_init: Failed to add bd70528-gpio\n"); 219 + dev_err(dev, "gpio_init: Failed to add bd70528-gpio\n"); 213 220 214 221 return ret; 215 222 }
+17 -22
drivers/gpio/gpio-bd71828.c
··· 11 11 #define HALL_GPIO_OFFSET 3 12 12 13 13 struct bd71828_gpio { 14 - struct rohm_regmap_dev chip; 14 + struct regmap *regmap; 15 + struct device *dev; 15 16 struct gpio_chip gpio; 16 17 }; 17 18 ··· 30 29 if (offset == HALL_GPIO_OFFSET) 31 30 return; 32 31 33 - ret = regmap_update_bits(bdgpio->chip.regmap, GPIO_OUT_REG(offset), 32 + ret = regmap_update_bits(bdgpio->regmap, GPIO_OUT_REG(offset), 34 33 BD71828_GPIO_OUT_MASK, val); 35 34 if (ret) 36 - dev_err(bdgpio->chip.dev, "Could not set gpio to %d\n", value); 35 + dev_err(bdgpio->dev, "Could not set gpio to %d\n", value); 37 36 } 38 37 39 38 static int bd71828_gpio_get(struct gpio_chip *chip, unsigned int offset) ··· 43 42 struct bd71828_gpio *bdgpio = gpiochip_get_data(chip); 44 43 45 44 if (offset == HALL_GPIO_OFFSET) 46 - ret = regmap_read(bdgpio->chip.regmap, BD71828_REG_IO_STAT, 45 + ret = regmap_read(bdgpio->regmap, BD71828_REG_IO_STAT, 47 46 &val); 48 47 else 49 - ret = regmap_read(bdgpio->chip.regmap, GPIO_OUT_REG(offset), 48 + ret = regmap_read(bdgpio->regmap, GPIO_OUT_REG(offset), 50 49 &val); 51 50 if (!ret) 52 51 ret = (val & BD71828_GPIO_OUT_MASK); ··· 64 63 65 64 switch (pinconf_to_config_param(config)) { 66 65 case PIN_CONFIG_DRIVE_OPEN_DRAIN: 67 - return regmap_update_bits(bdgpio->chip.regmap, 66 + return regmap_update_bits(bdgpio->regmap, 68 67 GPIO_OUT_REG(offset), 69 68 BD71828_GPIO_DRIVE_MASK, 70 69 BD71828_GPIO_OPEN_DRAIN); 71 70 case PIN_CONFIG_DRIVE_PUSH_PULL: 72 - return regmap_update_bits(bdgpio->chip.regmap, 71 + return regmap_update_bits(bdgpio->regmap, 73 72 GPIO_OUT_REG(offset), 74 73 BD71828_GPIO_DRIVE_MASK, 75 74 BD71828_GPIO_PUSH_PULL); ··· 97 96 98 97 static int bd71828_probe(struct platform_device *pdev) 99 98 { 99 + struct device *dev = &pdev->dev; 100 100 struct bd71828_gpio *bdgpio; 101 - struct rohm_regmap_dev *bd71828; 102 101 103 - bd71828 = dev_get_drvdata(pdev->dev.parent); 104 - if (!bd71828) { 105 - dev_err(&pdev->dev, "No MFD driver data\n"); 106 - return -EINVAL; 107 - } 108 - 109 - bdgpio = devm_kzalloc(&pdev->dev, sizeof(*bdgpio), 110 - GFP_KERNEL); 102 + bdgpio = devm_kzalloc(dev, sizeof(*bdgpio), GFP_KERNEL); 111 103 if (!bdgpio) 112 104 return -ENOMEM; 113 105 114 - bdgpio->chip.dev = &pdev->dev; 115 - bdgpio->gpio.parent = pdev->dev.parent; 106 + bdgpio->dev = dev; 107 + bdgpio->gpio.parent = dev->parent; 116 108 bdgpio->gpio.label = "bd71828-gpio"; 117 109 bdgpio->gpio.owner = THIS_MODULE; 118 110 bdgpio->gpio.get_direction = bd71828_get_direction; ··· 121 127 * "gpio-reserved-ranges" and exclude them from control 122 128 */ 123 129 bdgpio->gpio.ngpio = 4; 124 - bdgpio->gpio.of_node = pdev->dev.parent->of_node; 125 - bdgpio->chip.regmap = bd71828->regmap; 130 + bdgpio->gpio.of_node = dev->parent->of_node; 131 + bdgpio->regmap = dev_get_regmap(dev->parent, NULL); 132 + if (!bdgpio->regmap) 133 + return -ENODEV; 126 134 127 - return devm_gpiochip_add_data(&pdev->dev, &bdgpio->gpio, 128 - bdgpio); 135 + return devm_gpiochip_add_data(dev, &bdgpio->gpio, bdgpio); 129 136 } 130 137 131 138 static struct platform_driver bd71828_gpio = {
+12 -16
drivers/gpio/gpio-ep93xx.c
··· 31 31 /* Maximum value for irq capable line identifiers */ 32 32 #define EP93XX_GPIO_LINE_MAX_IRQ 23 33 33 34 + #define EP93XX_GPIO_A_IRQ_BASE 64 35 + #define EP93XX_GPIO_B_IRQ_BASE 72 34 36 /* 35 37 * Static mapping of GPIO bank F IRQS: 36 38 * F0..F7 (16..24) to irq 80..87. ··· 294 292 295 293 static struct ep93xx_gpio_bank ep93xx_gpio_banks[] = { 296 294 /* Bank A has 8 IRQs */ 297 - EP93XX_GPIO_BANK("A", 0x00, 0x10, 0x90, 0, true, false, 64), 295 + EP93XX_GPIO_BANK("A", 0x00, 0x10, 0x90, 0, true, false, EP93XX_GPIO_A_IRQ_BASE), 298 296 /* Bank B has 8 IRQs */ 299 - EP93XX_GPIO_BANK("B", 0x04, 0x14, 0xac, 8, true, false, 72), 297 + EP93XX_GPIO_BANK("B", 0x04, 0x14, 0xac, 8, true, false, EP93XX_GPIO_B_IRQ_BASE), 300 298 EP93XX_GPIO_BANK("C", 0x08, 0x18, 0x00, 40, false, false, 0), 301 299 EP93XX_GPIO_BANK("D", 0x0c, 0x1c, 0x00, 24, false, false, 0), 302 300 EP93XX_GPIO_BANK("E", 0x20, 0x24, 0x00, 32, false, false, 0), 303 301 /* Bank F has 8 IRQs */ 304 - EP93XX_GPIO_BANK("F", 0x30, 0x34, 0x4c, 16, false, true, 0), 302 + EP93XX_GPIO_BANK("F", 0x30, 0x34, 0x4c, 16, false, true, EP93XX_GPIO_F_IRQ_BASE), 305 303 EP93XX_GPIO_BANK("G", 0x38, 0x3c, 0x00, 48, false, false, 0), 306 304 EP93XX_GPIO_BANK("H", 0x40, 0x44, 0x00, 56, false, false, 0), 307 305 }; ··· 318 316 ep93xx_gpio_int_debounce(gc, offset, debounce ? true : false); 319 317 320 318 return 0; 321 - } 322 - 323 - static int ep93xx_gpio_f_to_irq(struct gpio_chip *gc, unsigned offset) 324 - { 325 - return EP93XX_GPIO_F_IRQ_BASE + offset; 326 319 } 327 320 328 321 static void ep93xx_init_irq_chip(struct device *dev, struct irq_chip *ic) ··· 372 375 373 376 girq->parent_handler = ep93xx_gpio_ab_irq_handler; 374 377 girq->num_parents = 1; 375 - girq->parents = devm_kcalloc(dev, 1, 378 + girq->parents = devm_kcalloc(dev, girq->num_parents, 376 379 sizeof(*girq->parents), 377 380 GFP_KERNEL); 378 381 if (!girq->parents) ··· 390 393 391 394 /* 392 395 * FIXME: convert this to use hierarchical IRQ support! 393 - * this requires fixing the root irqchip to be hierarchial. 396 + * this requires fixing the root irqchip to be hierarchical. 394 397 */ 395 398 girq->parent_handler = ep93xx_gpio_f_irq_handler; 396 399 girq->num_parents = 8; 397 - girq->parents = devm_kcalloc(dev, 8, 400 + girq->parents = devm_kcalloc(dev, girq->num_parents, 398 401 sizeof(*girq->parents), 399 402 GFP_KERNEL); 400 403 if (!girq->parents) 401 404 return -ENOMEM; 402 405 /* Pick resources 1..8 for these IRQs */ 403 - for (i = 1; i <= 8; i++) 404 - girq->parents[i - 1] = platform_get_irq(pdev, i); 405 - for (i = 0; i < 8; i++) { 406 - gpio_irq = EP93XX_GPIO_F_IRQ_BASE + i; 406 + for (i = 0; i < girq->num_parents; i++) { 407 + girq->parents[i] = platform_get_irq(pdev, i + 1); 408 + gpio_irq = bank->irq_base + i; 407 409 irq_set_chip_data(gpio_irq, &epg->gc[5]); 408 410 irq_set_chip_and_handler(gpio_irq, 409 411 girq->chip, ··· 411 415 } 412 416 girq->default_type = IRQ_TYPE_NONE; 413 417 girq->handler = handle_level_irq; 414 - gc->to_irq = ep93xx_gpio_f_to_irq; 418 + girq->first = bank->irq_base; 415 419 } 416 420 417 421 return devm_gpiochip_add_data(dev, gc, epg);
+1 -1
drivers/gpio/gpio-max77620.c
··· 325 325 girq->parents = NULL; 326 326 girq->default_type = IRQ_TYPE_NONE; 327 327 girq->handler = handle_edge_irq; 328 - girq->init_hw = max77620_gpio_irq_init_hw, 328 + girq->init_hw = max77620_gpio_irq_init_hw; 329 329 girq->threaded = true; 330 330 331 331 platform_set_drvdata(pdev, mgpio);
+5
drivers/gpio/gpio-merrifield.c
··· 194 194 { 195 195 u32 debounce; 196 196 197 + if ((pinconf_to_config_param(config) == PIN_CONFIG_BIAS_DISABLE) || 198 + (pinconf_to_config_param(config) == PIN_CONFIG_BIAS_PULL_UP) || 199 + (pinconf_to_config_param(config) == PIN_CONFIG_BIAS_PULL_DOWN)) 200 + return gpiochip_generic_config(chip, offset, config); 201 + 197 202 if (pinconf_to_config_param(config) != PIN_CONFIG_INPUT_DEBOUNCE) 198 203 return -ENOTSUPP; 199 204
+93 -55
drivers/gpio/gpio-mvebu.c
··· 70 70 */ 71 71 #define PWM_BLINK_ON_DURATION_OFF 0x0 72 72 #define PWM_BLINK_OFF_DURATION_OFF 0x4 73 + #define PWM_BLINK_COUNTER_B_OFF 0x8 73 74 75 + /* Armada 8k variant gpios register offsets */ 76 + #define AP80X_GPIO0_OFF_A8K 0x1040 77 + #define CP11X_GPIO0_OFF_A8K 0x100 78 + #define CP11X_GPIO1_OFF_A8K 0x140 74 79 75 80 /* The MV78200 has per-CPU registers for edge mask and level mask */ 76 81 #define GPIO_EDGE_MASK_MV78200_OFF(cpu) ((cpu) ? 0x30 : 0x18) ··· 98 93 99 94 struct mvebu_pwm { 100 95 struct regmap *regs; 96 + u32 offset; 101 97 unsigned long clk_rate; 102 98 struct gpio_desc *gpiod; 103 99 struct pwm_chip chip; ··· 289 283 */ 290 284 static unsigned int mvebu_pwmreg_blink_on_duration(struct mvebu_pwm *mvpwm) 291 285 { 292 - return PWM_BLINK_ON_DURATION_OFF; 286 + return mvpwm->offset + PWM_BLINK_ON_DURATION_OFF; 293 287 } 294 288 295 289 static unsigned int mvebu_pwmreg_blink_off_duration(struct mvebu_pwm *mvpwm) 296 290 { 297 - return PWM_BLINK_OFF_DURATION_OFF; 291 + return mvpwm->offset + PWM_BLINK_OFF_DURATION_OFF; 298 292 } 299 293 300 294 /* ··· 673 667 spin_lock_irqsave(&mvpwm->lock, flags); 674 668 675 669 regmap_read(mvpwm->regs, mvebu_pwmreg_blink_on_duration(mvpwm), &u); 676 - val = (unsigned long long) u * NSEC_PER_SEC; 677 - do_div(val, mvpwm->clk_rate); 678 - if (val > UINT_MAX) 679 - state->duty_cycle = UINT_MAX; 680 - else if (val) 681 - state->duty_cycle = val; 670 + /* Hardware treats zero as 2^32. See mvebu_pwm_apply(). */ 671 + if (u > 0) 672 + val = u; 682 673 else 683 - state->duty_cycle = 1; 674 + val = UINT_MAX + 1ULL; 675 + state->duty_cycle = DIV_ROUND_UP_ULL(val * NSEC_PER_SEC, 676 + mvpwm->clk_rate); 684 677 685 - val = (unsigned long long) u; /* on duration */ 686 678 regmap_read(mvpwm->regs, mvebu_pwmreg_blink_off_duration(mvpwm), &u); 687 - val += (unsigned long long) u; /* period = on + off duration */ 688 - val *= NSEC_PER_SEC; 689 - do_div(val, mvpwm->clk_rate); 690 - if (val > UINT_MAX) 691 - state->period = UINT_MAX; 692 - else if (val) 693 - state->period = val; 679 + /* period = on + off duration */ 680 + if (u > 0) 681 + val += u; 694 682 else 695 - state->period = 1; 683 + val += UINT_MAX + 1ULL; 684 + state->period = DIV_ROUND_UP_ULL(val * NSEC_PER_SEC, mvpwm->clk_rate); 696 685 697 686 regmap_read(mvchip->regs, GPIO_BLINK_EN_OFF + mvchip->offset, &u); 698 687 if (u) ··· 709 708 710 709 val = (unsigned long long) mvpwm->clk_rate * state->duty_cycle; 711 710 do_div(val, NSEC_PER_SEC); 712 - if (val > UINT_MAX) 711 + if (val > UINT_MAX + 1ULL) 713 712 return -EINVAL; 714 - if (val) 713 + /* 714 + * Zero on/off values don't work as expected. Experimentation shows 715 + * that zero value is treated as 2^32. This behavior is not documented. 716 + */ 717 + if (val == UINT_MAX + 1ULL) 718 + on = 0; 719 + else if (val) 715 720 on = val; 716 721 else 717 722 on = 1; 718 723 719 - val = (unsigned long long) mvpwm->clk_rate * 720 - (state->period - state->duty_cycle); 724 + val = (unsigned long long) mvpwm->clk_rate * state->period; 721 725 do_div(val, NSEC_PER_SEC); 722 - if (val > UINT_MAX) 726 + val -= on; 727 + if (val > UINT_MAX + 1ULL) 723 728 return -EINVAL; 724 - if (val) 729 + if (val == UINT_MAX + 1ULL) 730 + off = 0; 731 + else if (val) 725 732 off = val; 726 733 else 727 734 off = 1; ··· 787 778 struct device *dev = &pdev->dev; 788 779 struct mvebu_pwm *mvpwm; 789 780 void __iomem *base; 781 + u32 offset; 790 782 u32 set; 791 783 792 - if (!of_device_is_compatible(mvchip->chip.of_node, 793 - "marvell,armada-370-gpio")) 784 + if (of_device_is_compatible(mvchip->chip.of_node, 785 + "marvell,armada-370-gpio")) { 786 + /* 787 + * There are only two sets of PWM configuration registers for 788 + * all the GPIO lines on those SoCs which this driver reserves 789 + * for the first two GPIO chips. So if the resource is missing 790 + * we can't treat it as an error. 791 + */ 792 + if (!platform_get_resource_byname(pdev, IORESOURCE_MEM, "pwm")) 793 + return 0; 794 + offset = 0; 795 + } else if (mvchip->soc_variant == MVEBU_GPIO_SOC_VARIANT_A8K) { 796 + int ret = of_property_read_u32(dev->of_node, 797 + "marvell,pwm-offset", &offset); 798 + if (ret < 0) 799 + return 0; 800 + } else { 794 801 return 0; 795 - 796 - /* 797 - * There are only two sets of PWM configuration registers for 798 - * all the GPIO lines on those SoCs which this driver reserves 799 - * for the first two GPIO chips. So if the resource is missing 800 - * we can't treat it as an error. 801 - */ 802 - if (!platform_get_resource_byname(pdev, IORESOURCE_MEM, "pwm")) 803 - return 0; 802 + } 804 803 805 804 if (IS_ERR(mvchip->clk)) 806 805 return PTR_ERR(mvchip->clk); 807 - 808 - /* 809 - * Use set A for lines of GPIO chip with id 0, B for GPIO chip 810 - * with id 1. Don't allow further GPIO chips to be used for PWM. 811 - */ 812 - if (id == 0) 813 - set = 0; 814 - else if (id == 1) 815 - set = U32_MAX; 816 - else 817 - return -EINVAL; 818 - regmap_write(mvchip->regs, 819 - GPIO_BLINK_CNT_SELECT_OFF + mvchip->offset, set); 820 806 821 807 mvpwm = devm_kzalloc(dev, sizeof(struct mvebu_pwm), GFP_KERNEL); 822 808 if (!mvpwm) 823 809 return -ENOMEM; 824 810 mvchip->mvpwm = mvpwm; 825 811 mvpwm->mvchip = mvchip; 812 + mvpwm->offset = offset; 826 813 827 - base = devm_platform_ioremap_resource_byname(pdev, "pwm"); 828 - if (IS_ERR(base)) 829 - return PTR_ERR(base); 814 + if (mvchip->soc_variant == MVEBU_GPIO_SOC_VARIANT_A8K) { 815 + mvpwm->regs = mvchip->regs; 830 816 831 - mvpwm->regs = devm_regmap_init_mmio(&pdev->dev, base, 832 - &mvebu_gpio_regmap_config); 833 - if (IS_ERR(mvpwm->regs)) 834 - return PTR_ERR(mvpwm->regs); 817 + switch (mvchip->offset) { 818 + case AP80X_GPIO0_OFF_A8K: 819 + case CP11X_GPIO0_OFF_A8K: 820 + /* Blink counter A */ 821 + set = 0; 822 + break; 823 + case CP11X_GPIO1_OFF_A8K: 824 + /* Blink counter B */ 825 + set = U32_MAX; 826 + mvpwm->offset += PWM_BLINK_COUNTER_B_OFF; 827 + break; 828 + default: 829 + return -EINVAL; 830 + } 831 + } else { 832 + base = devm_platform_ioremap_resource_byname(pdev, "pwm"); 833 + if (IS_ERR(base)) 834 + return PTR_ERR(base); 835 + 836 + mvpwm->regs = devm_regmap_init_mmio(&pdev->dev, base, 837 + &mvebu_gpio_regmap_config); 838 + if (IS_ERR(mvpwm->regs)) 839 + return PTR_ERR(mvpwm->regs); 840 + 841 + /* 842 + * Use set A for lines of GPIO chip with id 0, B for GPIO chip 843 + * with id 1. Don't allow further GPIO chips to be used for PWM. 844 + */ 845 + if (id == 0) 846 + set = 0; 847 + else if (id == 1) 848 + set = U32_MAX; 849 + else 850 + return -EINVAL; 851 + } 852 + 853 + regmap_write(mvchip->regs, 854 + GPIO_BLINK_CNT_SELECT_OFF + mvchip->offset, set); 835 855 836 856 mvpwm->clk_rate = clk_get_rate(mvchip->clk); 837 857 if (!mvpwm->clk_rate) {
+2
drivers/gpio/gpio-pca953x.c
··· 73 73 static const struct i2c_device_id pca953x_id[] = { 74 74 { "pca6416", 16 | PCA953X_TYPE | PCA_INT, }, 75 75 { "pca9505", 40 | PCA953X_TYPE | PCA_INT, }, 76 + { "pca9506", 40 | PCA953X_TYPE | PCA_INT, }, 76 77 { "pca9534", 8 | PCA953X_TYPE | PCA_INT, }, 77 78 { "pca9535", 16 | PCA953X_TYPE | PCA_INT, }, 78 79 { "pca9536", 4 | PCA953X_TYPE, }, ··· 1237 1236 static const struct of_device_id pca953x_dt_ids[] = { 1238 1237 { .compatible = "nxp,pca6416", .data = OF_953X(16, PCA_INT), }, 1239 1238 { .compatible = "nxp,pca9505", .data = OF_953X(40, PCA_INT), }, 1239 + { .compatible = "nxp,pca9506", .data = OF_953X(40, PCA_INT), }, 1240 1240 { .compatible = "nxp,pca9534", .data = OF_953X( 8, PCA_INT), }, 1241 1241 { .compatible = "nxp,pca9535", .data = OF_953X(16, PCA_INT), }, 1242 1242 { .compatible = "nxp,pca9536", .data = OF_953X( 4, 0), },
+1 -1
drivers/gpio/gpio-pcf857x.c
··· 332 332 * reset state. Otherwise it flags pins to be driven low. 333 333 */ 334 334 gpio->out = ~n_latch; 335 - gpio->status = gpio->out; 335 + gpio->status = gpio->read(gpio->client); 336 336 337 337 /* Enable irqchip if we have an interrupt */ 338 338 if (client->irq) {
+54 -31
drivers/gpio/gpio-rcar.c
··· 35 35 struct gpio_rcar_info { 36 36 bool has_outdtsel; 37 37 bool has_both_edge_trigger; 38 + bool has_always_in; 39 + bool has_inen; 38 40 }; 39 41 40 42 struct gpio_rcar_priv { ··· 64 62 #define FILONOFF 0x28 /* Chattering Prevention On/Off Register */ 65 63 #define OUTDTSEL 0x40 /* Output Data Select Register */ 66 64 #define BOTHEDGE 0x4c /* One Edge/Both Edge Select Register */ 65 + #define INEN 0x50 /* General Input Enable Register */ 67 66 68 67 #define RCAR_MAX_GPIO_PER_BANK 32 69 68 ··· 305 302 struct gpio_rcar_priv *p = gpiochip_get_data(chip); 306 303 u32 bit = BIT(offset); 307 304 308 - /* testing on r8a7790 shows that INDT does not show correct pin state 309 - * when configured as output, so use OUTDT in case of output pins */ 310 - if (gpio_rcar_read(p, INOUTSEL) & bit) 305 + /* 306 + * Before R-Car Gen3, INDT does not show correct pin state when 307 + * configured as output, so use OUTDT in case of output pins 308 + */ 309 + if (!p->info.has_always_in && (gpio_rcar_read(p, INOUTSEL) & bit)) 311 310 return !!(gpio_rcar_read(p, OUTDT) & bit); 312 311 else 313 312 return !!(gpio_rcar_read(p, INDT) & bit); ··· 328 323 329 324 if (!bankmask) 330 325 return 0; 326 + 327 + if (p->info.has_always_in) { 328 + bits[0] = gpio_rcar_read(p, INDT) & bankmask; 329 + return 0; 330 + } 331 331 332 332 spin_lock_irqsave(&p->lock, flags); 333 333 outputs = gpio_rcar_read(p, INOUTSEL); ··· 393 383 static const struct gpio_rcar_info gpio_rcar_info_gen1 = { 394 384 .has_outdtsel = false, 395 385 .has_both_edge_trigger = false, 386 + .has_always_in = false, 387 + .has_inen = false, 396 388 }; 397 389 398 390 static const struct gpio_rcar_info gpio_rcar_info_gen2 = { 399 391 .has_outdtsel = true, 400 392 .has_both_edge_trigger = true, 393 + .has_always_in = false, 394 + .has_inen = false, 395 + }; 396 + 397 + static const struct gpio_rcar_info gpio_rcar_info_gen3 = { 398 + .has_outdtsel = true, 399 + .has_both_edge_trigger = true, 400 + .has_always_in = true, 401 + .has_inen = false, 402 + }; 403 + 404 + static const struct gpio_rcar_info gpio_rcar_info_v3u = { 405 + .has_outdtsel = true, 406 + .has_both_edge_trigger = true, 407 + .has_always_in = true, 408 + .has_inen = true, 401 409 }; 402 410 403 411 static const struct of_device_id gpio_rcar_of_table[] = { 404 412 { 405 - .compatible = "renesas,gpio-r8a7743", 406 - /* RZ/G1 GPIO is identical to R-Car Gen2. */ 407 - .data = &gpio_rcar_info_gen2, 408 - }, { 409 - .compatible = "renesas,gpio-r8a7790", 410 - .data = &gpio_rcar_info_gen2, 411 - }, { 412 - .compatible = "renesas,gpio-r8a7791", 413 - .data = &gpio_rcar_info_gen2, 414 - }, { 415 - .compatible = "renesas,gpio-r8a7792", 416 - .data = &gpio_rcar_info_gen2, 417 - }, { 418 - .compatible = "renesas,gpio-r8a7793", 419 - .data = &gpio_rcar_info_gen2, 420 - }, { 421 - .compatible = "renesas,gpio-r8a7794", 422 - .data = &gpio_rcar_info_gen2, 423 - }, { 424 - .compatible = "renesas,gpio-r8a7795", 425 - /* Gen3 GPIO is identical to Gen2. */ 426 - .data = &gpio_rcar_info_gen2, 427 - }, { 428 - .compatible = "renesas,gpio-r8a7796", 429 - /* Gen3 GPIO is identical to Gen2. */ 430 - .data = &gpio_rcar_info_gen2, 413 + .compatible = "renesas,gpio-r8a779a0", 414 + .data = &gpio_rcar_info_v3u, 431 415 }, { 432 416 .compatible = "renesas,rcar-gen1-gpio", 433 417 .data = &gpio_rcar_info_gen1, ··· 430 426 .data = &gpio_rcar_info_gen2, 431 427 }, { 432 428 .compatible = "renesas,rcar-gen3-gpio", 433 - /* Gen3 GPIO is identical to Gen2. */ 434 - .data = &gpio_rcar_info_gen2, 429 + .data = &gpio_rcar_info_gen3, 435 430 }, { 436 431 .compatible = "renesas,gpio-rcar", 437 432 .data = &gpio_rcar_info_gen1, ··· 461 458 } 462 459 463 460 return 0; 461 + } 462 + 463 + static void gpio_rcar_enable_inputs(struct gpio_rcar_priv *p) 464 + { 465 + u32 mask = GENMASK(p->gpio_chip.ngpio - 1, 0); 466 + 467 + /* Select "Input Enable" in INEN */ 468 + if (p->gpio_chip.valid_mask) 469 + mask &= p->gpio_chip.valid_mask[0]; 470 + if (mask) 471 + gpio_rcar_write(p, INEN, gpio_rcar_read(p, INEN) | mask); 464 472 } 465 473 466 474 static int gpio_rcar_probe(struct platform_device *pdev) ··· 563 549 goto err1; 564 550 } 565 551 552 + if (p->info.has_inen) { 553 + pm_runtime_get_sync(p->dev); 554 + gpio_rcar_enable_inputs(p); 555 + pm_runtime_put(p->dev); 556 + } 557 + 566 558 dev_info(dev, "driving %d GPIOs\n", npins); 567 559 568 560 return 0; ··· 643 623 gpio_rcar_write(p, MSKCLR, mask); 644 624 } 645 625 } 626 + 627 + if (p->info.has_inen) 628 + gpio_rcar_enable_inputs(p); 646 629 647 630 return 0; 648 631 }
+2 -2
drivers/gpio/gpio-sl28cpld.c
··· 65 65 if (!irq_chip) 66 66 return -ENOMEM; 67 67 68 - irq_chip->name = "sl28cpld-gpio-irq", 68 + irq_chip->name = "sl28cpld-gpio-irq"; 69 69 irq_chip->irqs = sl28cpld_gpio_irqs; 70 70 irq_chip->num_irqs = ARRAY_SIZE(sl28cpld_gpio_irqs); 71 71 irq_chip->num_regs = 1; 72 72 irq_chip->status_base = base + GPIO_REG_IP; 73 73 irq_chip->mask_base = base + GPIO_REG_IE; 74 - irq_chip->mask_invert = true, 74 + irq_chip->mask_invert = true; 75 75 irq_chip->ack_base = base + GPIO_REG_IP; 76 76 77 77 ret = devm_regmap_add_irq_chip_fwnode(dev, dev_fwnode(dev),
+177 -86
drivers/gpio/gpio-tegra.c
··· 60 60 61 61 struct tegra_gpio_bank { 62 62 unsigned int bank; 63 - unsigned int irq; 64 63 65 64 /* 66 65 * IRQ-core code uses raw locking, and thus, nested locking also ··· 80 81 u32 dbc_enb[4]; 81 82 #endif 82 83 u32 dbc_cnt[4]; 83 - struct tegra_gpio_info *tgi; 84 84 }; 85 85 86 86 struct tegra_gpio_soc_config { ··· 91 93 struct tegra_gpio_info { 92 94 struct device *dev; 93 95 void __iomem *regs; 94 - struct irq_domain *irq_domain; 95 96 struct tegra_gpio_bank *bank_info; 96 97 const struct tegra_gpio_soc_config *soc; 97 98 struct gpio_chip gc; 98 99 struct irq_chip ic; 99 100 u32 bank_count; 101 + unsigned int *irqs; 100 102 }; 101 103 102 104 static inline void tegra_gpio_writel(struct tegra_gpio_info *tgi, ··· 272 274 return tegra_gpio_set_debounce(chip, offset, debounce); 273 275 } 274 276 275 - static int tegra_gpio_to_irq(struct gpio_chip *chip, unsigned int offset) 276 - { 277 - struct tegra_gpio_info *tgi = gpiochip_get_data(chip); 278 - 279 - return irq_find_mapping(tgi->irq_domain, offset); 280 - } 281 - 282 277 static void tegra_gpio_irq_ack(struct irq_data *d) 283 278 { 284 - struct tegra_gpio_bank *bank = irq_data_get_irq_chip_data(d); 285 - struct tegra_gpio_info *tgi = bank->tgi; 279 + struct gpio_chip *chip = irq_data_get_irq_chip_data(d); 280 + struct tegra_gpio_info *tgi = gpiochip_get_data(chip); 286 281 unsigned int gpio = d->hwirq; 287 282 288 283 tegra_gpio_writel(tgi, 1 << GPIO_BIT(gpio), GPIO_INT_CLR(tgi, gpio)); ··· 283 292 284 293 static void tegra_gpio_irq_mask(struct irq_data *d) 285 294 { 286 - struct tegra_gpio_bank *bank = irq_data_get_irq_chip_data(d); 287 - struct tegra_gpio_info *tgi = bank->tgi; 295 + struct gpio_chip *chip = irq_data_get_irq_chip_data(d); 296 + struct tegra_gpio_info *tgi = gpiochip_get_data(chip); 288 297 unsigned int gpio = d->hwirq; 289 298 290 299 tegra_gpio_mask_write(tgi, GPIO_MSK_INT_ENB(tgi, gpio), gpio, 0); ··· 292 301 293 302 static void tegra_gpio_irq_unmask(struct irq_data *d) 294 303 { 295 - struct tegra_gpio_bank *bank = irq_data_get_irq_chip_data(d); 296 - struct tegra_gpio_info *tgi = bank->tgi; 304 + struct gpio_chip *chip = irq_data_get_irq_chip_data(d); 305 + struct tegra_gpio_info *tgi = gpiochip_get_data(chip); 297 306 unsigned int gpio = d->hwirq; 298 307 299 308 tegra_gpio_mask_write(tgi, GPIO_MSK_INT_ENB(tgi, gpio), gpio, 1); ··· 302 311 static int tegra_gpio_irq_set_type(struct irq_data *d, unsigned int type) 303 312 { 304 313 unsigned int gpio = d->hwirq, port = GPIO_PORT(gpio), lvl_type; 305 - struct tegra_gpio_bank *bank = irq_data_get_irq_chip_data(d); 306 - struct tegra_gpio_info *tgi = bank->tgi; 314 + struct gpio_chip *chip = irq_data_get_irq_chip_data(d); 315 + struct tegra_gpio_info *tgi = gpiochip_get_data(chip); 316 + struct tegra_gpio_bank *bank; 307 317 unsigned long flags; 308 - u32 val; 309 318 int ret; 319 + u32 val; 320 + 321 + bank = &tgi->bank_info[GPIO_BANK(d->hwirq)]; 310 322 311 323 switch (type & IRQ_TYPE_SENSE_MASK) { 312 324 case IRQ_TYPE_EDGE_RISING: ··· 361 367 else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING)) 362 368 irq_set_handler_locked(d, handle_edge_irq); 363 369 364 - return 0; 370 + if (d->parent_data) 371 + ret = irq_chip_set_type_parent(d, type); 372 + 373 + return ret; 365 374 } 366 375 367 376 static void tegra_gpio_irq_shutdown(struct irq_data *d) 368 377 { 369 - struct tegra_gpio_bank *bank = irq_data_get_irq_chip_data(d); 370 - struct tegra_gpio_info *tgi = bank->tgi; 378 + struct gpio_chip *chip = irq_data_get_irq_chip_data(d); 379 + struct tegra_gpio_info *tgi = gpiochip_get_data(chip); 371 380 unsigned int gpio = d->hwirq; 372 381 373 382 tegra_gpio_irq_mask(d); ··· 379 382 380 383 static void tegra_gpio_irq_handler(struct irq_desc *desc) 381 384 { 382 - unsigned int port, pin, gpio; 383 - bool unmasked = false; 384 - u32 lvl; 385 - unsigned long sta; 385 + struct tegra_gpio_info *tgi = irq_desc_get_handler_data(desc); 386 386 struct irq_chip *chip = irq_desc_get_chip(desc); 387 - struct tegra_gpio_bank *bank = irq_desc_get_handler_data(desc); 388 - struct tegra_gpio_info *tgi = bank->tgi; 387 + struct irq_domain *domain = tgi->gc.irq.domain; 388 + unsigned int irq = irq_desc_get_irq(desc); 389 + struct tegra_gpio_bank *bank = NULL; 390 + unsigned int port, pin, gpio, i; 391 + bool unmasked = false; 392 + unsigned long sta; 393 + u32 lvl; 394 + 395 + for (i = 0; i < tgi->bank_count; i++) { 396 + if (tgi->irqs[i] == irq) { 397 + bank = &tgi->bank_info[i]; 398 + break; 399 + } 400 + } 401 + 402 + if (WARN_ON(bank == NULL)) 403 + return; 389 404 390 405 chained_irq_enter(chip, desc); 391 406 ··· 420 411 chained_irq_exit(chip, desc); 421 412 } 422 413 423 - generic_handle_irq(irq_find_mapping(tgi->irq_domain, 424 - gpio + pin)); 414 + irq = irq_find_mapping(domain, gpio + pin); 415 + if (WARN_ON(irq == 0)) 416 + continue; 417 + 418 + generic_handle_irq(irq); 425 419 } 426 420 } 427 421 428 422 if (!unmasked) 429 423 chained_irq_exit(chip, desc); 424 + } 430 425 426 + static int tegra_gpio_child_to_parent_hwirq(struct gpio_chip *chip, 427 + unsigned int hwirq, 428 + unsigned int type, 429 + unsigned int *parent_hwirq, 430 + unsigned int *parent_type) 431 + { 432 + *parent_hwirq = chip->irq.child_offset_to_irq(chip, hwirq); 433 + *parent_type = type; 434 + 435 + return 0; 436 + } 437 + 438 + static void *tegra_gpio_populate_parent_fwspec(struct gpio_chip *chip, 439 + unsigned int parent_hwirq, 440 + unsigned int parent_type) 441 + { 442 + struct irq_fwspec *fwspec; 443 + 444 + fwspec = kmalloc(sizeof(*fwspec), GFP_KERNEL); 445 + if (!fwspec) 446 + return NULL; 447 + 448 + fwspec->fwnode = chip->irq.parent_domain->fwnode; 449 + fwspec->param_count = 3; 450 + fwspec->param[0] = 0; 451 + fwspec->param[1] = parent_hwirq; 452 + fwspec->param[2] = parent_type; 453 + 454 + return fwspec; 431 455 } 432 456 433 457 #ifdef CONFIG_PM_SLEEP ··· 539 497 540 498 static int tegra_gpio_irq_set_wake(struct irq_data *d, unsigned int enable) 541 499 { 542 - struct tegra_gpio_bank *bank = irq_data_get_irq_chip_data(d); 500 + struct gpio_chip *chip = irq_data_get_irq_chip_data(d); 501 + struct tegra_gpio_info *tgi = gpiochip_get_data(chip); 502 + struct tegra_gpio_bank *bank; 543 503 unsigned int gpio = d->hwirq; 544 504 u32 port, bit, mask; 545 505 int err; 546 506 547 - err = irq_set_irq_wake(bank->irq, enable); 548 - if (err) 549 - return err; 507 + bank = &tgi->bank_info[GPIO_BANK(d->hwirq)]; 550 508 551 509 port = GPIO_PORT(gpio); 552 510 bit = GPIO_BIT(gpio); 553 511 mask = BIT(bit); 512 + 513 + err = irq_set_irq_wake(tgi->irqs[bank->bank], enable); 514 + if (err) 515 + return err; 516 + 517 + if (d->parent_data) { 518 + err = irq_chip_set_wake_parent(d, enable); 519 + if (err) { 520 + irq_set_irq_wake(tgi->irqs[bank->bank], !enable); 521 + return err; 522 + } 523 + } 554 524 555 525 if (enable) 556 526 bank->wake_enb[port] |= mask; ··· 573 519 } 574 520 #endif 575 521 522 + static int tegra_gpio_irq_set_affinity(struct irq_data *data, 523 + const struct cpumask *dest, 524 + bool force) 525 + { 526 + if (data->parent_data) 527 + return irq_chip_set_affinity_parent(data, dest, force); 528 + 529 + return -EINVAL; 530 + } 531 + 532 + static int tegra_gpio_irq_request_resources(struct irq_data *d) 533 + { 534 + struct gpio_chip *chip = irq_data_get_irq_chip_data(d); 535 + struct tegra_gpio_info *tgi = gpiochip_get_data(chip); 536 + 537 + tegra_gpio_enable(tgi, d->hwirq); 538 + 539 + return gpiochip_reqres_irq(chip, d->hwirq); 540 + } 541 + 542 + static void tegra_gpio_irq_release_resources(struct irq_data *d) 543 + { 544 + struct gpio_chip *chip = irq_data_get_irq_chip_data(d); 545 + struct tegra_gpio_info *tgi = gpiochip_get_data(chip); 546 + 547 + gpiochip_relres_irq(chip, d->hwirq); 548 + tegra_gpio_enable(tgi, d->hwirq); 549 + } 550 + 576 551 #ifdef CONFIG_DEBUG_FS 577 552 578 553 #include <linux/debugfs.h> ··· 609 526 610 527 static int tegra_dbg_gpio_show(struct seq_file *s, void *unused) 611 528 { 612 - struct tegra_gpio_info *tgi = s->private; 529 + struct tegra_gpio_info *tgi = dev_get_drvdata(s->private); 613 530 unsigned int i, j; 614 531 615 532 for (i = 0; i < tgi->bank_count; i++) { ··· 631 548 return 0; 632 549 } 633 550 634 - DEFINE_SHOW_ATTRIBUTE(tegra_dbg_gpio); 635 - 636 551 static void tegra_gpio_debuginit(struct tegra_gpio_info *tgi) 637 552 { 638 - debugfs_create_file("tegra_gpio", 0444, NULL, tgi, 639 - &tegra_dbg_gpio_fops); 553 + debugfs_create_devm_seqfile(tgi->dev, "tegra_gpio", NULL, 554 + tegra_dbg_gpio_show); 640 555 } 641 556 642 557 #else ··· 649 568 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(tegra_gpio_suspend, tegra_gpio_resume) 650 569 }; 651 570 652 - static struct lock_class_key gpio_lock_class; 653 - static struct lock_class_key gpio_request_class; 571 + static const struct of_device_id tegra_pmc_of_match[] = { 572 + { .compatible = "nvidia,tegra210-pmc", }, 573 + { /* sentinel */ }, 574 + }; 654 575 655 576 static int tegra_gpio_probe(struct platform_device *pdev) 656 577 { 657 - struct tegra_gpio_info *tgi; 658 578 struct tegra_gpio_bank *bank; 659 - unsigned int gpio, i, j; 579 + struct tegra_gpio_info *tgi; 580 + struct gpio_irq_chip *irq; 581 + struct device_node *np; 582 + unsigned int i, j; 660 583 int ret; 661 584 662 585 tgi = devm_kzalloc(&pdev->dev, sizeof(*tgi), GFP_KERNEL); ··· 689 604 tgi->gc.direction_output = tegra_gpio_direction_output; 690 605 tgi->gc.set = tegra_gpio_set; 691 606 tgi->gc.get_direction = tegra_gpio_get_direction; 692 - tgi->gc.to_irq = tegra_gpio_to_irq; 693 607 tgi->gc.base = 0; 694 608 tgi->gc.ngpio = tgi->bank_count * 32; 695 609 tgi->gc.parent = &pdev->dev; ··· 703 619 #ifdef CONFIG_PM_SLEEP 704 620 tgi->ic.irq_set_wake = tegra_gpio_irq_set_wake; 705 621 #endif 622 + tgi->ic.irq_request_resources = tegra_gpio_irq_request_resources; 623 + tgi->ic.irq_release_resources = tegra_gpio_irq_release_resources; 706 624 707 625 platform_set_drvdata(pdev, tgi); 708 626 ··· 716 630 if (!tgi->bank_info) 717 631 return -ENOMEM; 718 632 719 - tgi->irq_domain = irq_domain_add_linear(pdev->dev.of_node, 720 - tgi->gc.ngpio, 721 - &irq_domain_simple_ops, NULL); 722 - if (!tgi->irq_domain) 723 - return -ENODEV; 633 + tgi->irqs = devm_kcalloc(&pdev->dev, tgi->bank_count, 634 + sizeof(*tgi->irqs), GFP_KERNEL); 635 + if (!tgi->irqs) 636 + return -ENOMEM; 724 637 725 638 for (i = 0; i < tgi->bank_count; i++) { 726 639 ret = platform_get_irq(pdev, i); ··· 728 643 729 644 bank = &tgi->bank_info[i]; 730 645 bank->bank = i; 731 - bank->irq = ret; 732 - bank->tgi = tgi; 646 + 647 + tgi->irqs[i] = ret; 648 + 649 + for (j = 0; j < 4; j++) { 650 + raw_spin_lock_init(&bank->lvl_lock[j]); 651 + spin_lock_init(&bank->dbc_lock[j]); 652 + } 653 + } 654 + 655 + irq = &tgi->gc.irq; 656 + irq->chip = &tgi->ic; 657 + irq->fwnode = of_node_to_fwnode(pdev->dev.of_node); 658 + irq->child_to_parent_hwirq = tegra_gpio_child_to_parent_hwirq; 659 + irq->populate_parent_alloc_arg = tegra_gpio_populate_parent_fwspec; 660 + irq->handler = handle_simple_irq; 661 + irq->default_type = IRQ_TYPE_NONE; 662 + irq->parent_handler = tegra_gpio_irq_handler; 663 + irq->parent_handler_data = tgi; 664 + irq->num_parents = tgi->bank_count; 665 + irq->parents = tgi->irqs; 666 + 667 + np = of_find_matching_node(NULL, tegra_pmc_of_match); 668 + if (np) { 669 + irq->parent_domain = irq_find_host(np); 670 + of_node_put(np); 671 + 672 + if (!irq->parent_domain) 673 + return -EPROBE_DEFER; 674 + 675 + tgi->ic.irq_set_affinity = tegra_gpio_irq_set_affinity; 733 676 } 734 677 735 678 tgi->regs = devm_platform_ioremap_resource(pdev, 0); ··· 773 660 } 774 661 775 662 ret = devm_gpiochip_add_data(&pdev->dev, &tgi->gc, tgi); 776 - if (ret < 0) { 777 - irq_domain_remove(tgi->irq_domain); 663 + if (ret < 0) 778 664 return ret; 779 - } 780 - 781 - for (gpio = 0; gpio < tgi->gc.ngpio; gpio++) { 782 - int irq = irq_create_mapping(tgi->irq_domain, gpio); 783 - /* No validity check; all Tegra GPIOs are valid IRQs */ 784 - 785 - bank = &tgi->bank_info[GPIO_BANK(gpio)]; 786 - 787 - irq_set_chip_data(irq, bank); 788 - irq_set_lockdep_class(irq, &gpio_lock_class, &gpio_request_class); 789 - irq_set_chip_and_handler(irq, &tgi->ic, handle_simple_irq); 790 - } 791 - 792 - for (i = 0; i < tgi->bank_count; i++) { 793 - bank = &tgi->bank_info[i]; 794 - 795 - irq_set_chained_handler_and_data(bank->irq, 796 - tegra_gpio_irq_handler, bank); 797 - 798 - for (j = 0; j < 4; j++) { 799 - raw_spin_lock_init(&bank->lvl_lock[j]); 800 - spin_lock_init(&bank->dbc_lock[j]); 801 - } 802 - } 803 665 804 666 tegra_gpio_debuginit(tgi); 805 667 ··· 803 715 { .compatible = "nvidia,tegra20-gpio", .data = &tegra20_gpio_config }, 804 716 { }, 805 717 }; 718 + MODULE_DEVICE_TABLE(of, tegra_gpio_of_match); 806 719 807 720 static struct platform_driver tegra_gpio_driver = { 808 - .driver = { 809 - .name = "tegra-gpio", 810 - .pm = &tegra_gpio_pm_ops, 721 + .driver = { 722 + .name = "tegra-gpio", 723 + .pm = &tegra_gpio_pm_ops, 811 724 .of_match_table = tegra_gpio_of_match, 812 725 }, 813 - .probe = tegra_gpio_probe, 726 + .probe = tegra_gpio_probe, 814 727 }; 728 + module_platform_driver(tegra_gpio_driver); 815 729 816 - static int __init tegra_gpio_init(void) 817 - { 818 - return platform_driver_register(&tegra_gpio_driver); 819 - } 820 - subsys_initcall(tegra_gpio_init); 730 + MODULE_DESCRIPTION("NVIDIA Tegra GPIO controller driver"); 731 + MODULE_AUTHOR("Laxman Dewangan <ldewangan@nvidia.com>"); 732 + MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>"); 733 + MODULE_AUTHOR("Thierry Reding <treding@nvidia.com>"); 734 + MODULE_AUTHOR("Erik Gilling <konkers@google.com>"); 735 + MODULE_LICENSE("GPL v2");
+1 -1
drivers/gpio/gpio-tegra186.c
··· 657 657 gpio->gpio.get_direction = tegra186_gpio_get_direction; 658 658 gpio->gpio.direction_input = tegra186_gpio_direction_input; 659 659 gpio->gpio.direction_output = tegra186_gpio_direction_output; 660 - gpio->gpio.get = tegra186_gpio_get, 660 + gpio->gpio.get = tegra186_gpio_get; 661 661 gpio->gpio.set = tegra186_gpio_set; 662 662 gpio->gpio.set_config = tegra186_gpio_set_config; 663 663 gpio->gpio.add_pin_ranges = tegra186_gpio_add_pin_ranges;
+218
drivers/gpio/gpio-visconti.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Toshiba Visconti GPIO Support 4 + * 5 + * (C) Copyright 2020 Toshiba Electronic Devices & Storage Corporation 6 + * (C) Copyright 2020 TOSHIBA CORPORATION 7 + * 8 + * Nobuhiro Iwamatsu <nobuhiro1.iwamatsu@toshiba.co.jp> 9 + */ 10 + 11 + #include <linux/gpio/driver.h> 12 + #include <linux/init.h> 13 + #include <linux/interrupt.h> 14 + #include <linux/module.h> 15 + #include <linux/io.h> 16 + #include <linux/of_irq.h> 17 + #include <linux/platform_device.h> 18 + #include <linux/bitops.h> 19 + 20 + /* register offset */ 21 + #define GPIO_DIR 0x00 22 + #define GPIO_IDATA 0x08 23 + #define GPIO_ODATA 0x10 24 + #define GPIO_OSET 0x18 25 + #define GPIO_OCLR 0x20 26 + #define GPIO_INTMODE 0x30 27 + 28 + #define BASE_HW_IRQ 24 29 + 30 + struct visconti_gpio { 31 + void __iomem *base; 32 + spinlock_t lock; /* protect gpio register */ 33 + struct gpio_chip gpio_chip; 34 + struct irq_chip irq_chip; 35 + }; 36 + 37 + static int visconti_gpio_irq_set_type(struct irq_data *d, unsigned int type) 38 + { 39 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 40 + struct visconti_gpio *priv = gpiochip_get_data(gc); 41 + u32 offset = irqd_to_hwirq(d); 42 + u32 bit = BIT(offset); 43 + u32 intc_type = IRQ_TYPE_EDGE_RISING; 44 + u32 intmode, odata; 45 + int ret = 0; 46 + unsigned long flags; 47 + 48 + spin_lock_irqsave(&priv->lock, flags); 49 + 50 + odata = readl(priv->base + GPIO_ODATA); 51 + intmode = readl(priv->base + GPIO_INTMODE); 52 + 53 + switch (type) { 54 + case IRQ_TYPE_EDGE_RISING: 55 + odata &= ~bit; 56 + intmode &= ~bit; 57 + break; 58 + case IRQ_TYPE_EDGE_FALLING: 59 + odata |= bit; 60 + intmode &= ~bit; 61 + break; 62 + case IRQ_TYPE_EDGE_BOTH: 63 + intmode |= bit; 64 + break; 65 + case IRQ_TYPE_LEVEL_HIGH: 66 + intc_type = IRQ_TYPE_LEVEL_HIGH; 67 + odata &= ~bit; 68 + intmode &= ~bit; 69 + break; 70 + case IRQ_TYPE_LEVEL_LOW: 71 + intc_type = IRQ_TYPE_LEVEL_HIGH; 72 + odata |= bit; 73 + intmode &= ~bit; 74 + break; 75 + default: 76 + ret = -EINVAL; 77 + goto err; 78 + } 79 + 80 + writel(odata, priv->base + GPIO_ODATA); 81 + writel(intmode, priv->base + GPIO_INTMODE); 82 + irq_set_irq_type(offset, intc_type); 83 + 84 + ret = irq_chip_set_type_parent(d, type); 85 + err: 86 + spin_unlock_irqrestore(&priv->lock, flags); 87 + return ret; 88 + } 89 + 90 + static int visconti_gpio_child_to_parent_hwirq(struct gpio_chip *gc, 91 + unsigned int child, 92 + unsigned int child_type, 93 + unsigned int *parent, 94 + unsigned int *parent_type) 95 + { 96 + /* Interrupts 0..15 mapped to interrupts 24..39 on the GIC */ 97 + if (child < 16) { 98 + /* All these interrupts are level high in the CPU */ 99 + *parent_type = IRQ_TYPE_LEVEL_HIGH; 100 + *parent = child + BASE_HW_IRQ; 101 + return 0; 102 + } 103 + return -EINVAL; 104 + } 105 + 106 + static void *visconti_gpio_populate_parent_fwspec(struct gpio_chip *chip, 107 + unsigned int parent_hwirq, 108 + unsigned int parent_type) 109 + { 110 + struct irq_fwspec *fwspec; 111 + 112 + fwspec = kmalloc(sizeof(*fwspec), GFP_KERNEL); 113 + if (!fwspec) 114 + return NULL; 115 + 116 + fwspec->fwnode = chip->irq.parent_domain->fwnode; 117 + fwspec->param_count = 3; 118 + fwspec->param[0] = 0; 119 + fwspec->param[1] = parent_hwirq; 120 + fwspec->param[2] = parent_type; 121 + 122 + return fwspec; 123 + } 124 + 125 + static int visconti_gpio_probe(struct platform_device *pdev) 126 + { 127 + struct device *dev = &pdev->dev; 128 + struct visconti_gpio *priv; 129 + struct irq_chip *irq_chip; 130 + struct gpio_irq_chip *girq; 131 + struct irq_domain *parent; 132 + struct device_node *irq_parent; 133 + struct fwnode_handle *fwnode; 134 + int ret; 135 + 136 + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 137 + if (!priv) 138 + return -ENOMEM; 139 + 140 + spin_lock_init(&priv->lock); 141 + 142 + priv->base = devm_platform_ioremap_resource(pdev, 0); 143 + if (IS_ERR(priv->base)) 144 + return PTR_ERR(priv->base); 145 + 146 + irq_parent = of_irq_find_parent(dev->of_node); 147 + if (!irq_parent) { 148 + dev_err(dev, "No IRQ parent node\n"); 149 + return -ENODEV; 150 + } 151 + 152 + parent = irq_find_host(irq_parent); 153 + if (!parent) { 154 + dev_err(dev, "No IRQ parent domain\n"); 155 + return -ENODEV; 156 + } 157 + 158 + fwnode = of_node_to_fwnode(irq_parent); 159 + of_node_put(irq_parent); 160 + 161 + ret = bgpio_init(&priv->gpio_chip, dev, 4, 162 + priv->base + GPIO_IDATA, 163 + priv->base + GPIO_OSET, 164 + priv->base + GPIO_OCLR, 165 + priv->base + GPIO_DIR, 166 + NULL, 167 + 0); 168 + if (ret) { 169 + dev_err(dev, "unable to init generic GPIO\n"); 170 + return ret; 171 + } 172 + 173 + irq_chip = &priv->irq_chip; 174 + irq_chip->name = dev_name(dev); 175 + irq_chip->irq_mask = irq_chip_mask_parent; 176 + irq_chip->irq_unmask = irq_chip_unmask_parent; 177 + irq_chip->irq_eoi = irq_chip_eoi_parent; 178 + irq_chip->irq_set_type = visconti_gpio_irq_set_type; 179 + irq_chip->flags = IRQCHIP_SET_TYPE_MASKED | IRQCHIP_MASK_ON_SUSPEND; 180 + 181 + girq = &priv->gpio_chip.irq; 182 + girq->chip = irq_chip; 183 + girq->fwnode = fwnode; 184 + girq->parent_domain = parent; 185 + girq->child_to_parent_hwirq = visconti_gpio_child_to_parent_hwirq; 186 + girq->populate_parent_alloc_arg = visconti_gpio_populate_parent_fwspec; 187 + girq->default_type = IRQ_TYPE_NONE; 188 + girq->handler = handle_level_irq; 189 + 190 + ret = devm_gpiochip_add_data(dev, &priv->gpio_chip, priv); 191 + if (ret) { 192 + dev_err(dev, "failed to add GPIO chip\n"); 193 + return ret; 194 + } 195 + 196 + platform_set_drvdata(pdev, priv); 197 + 198 + return ret; 199 + } 200 + 201 + static const struct of_device_id visconti_gpio_of_match[] = { 202 + { .compatible = "toshiba,gpio-tmpv7708", }, 203 + { /* end of table */ } 204 + }; 205 + MODULE_DEVICE_TABLE(of, visconti_gpio_of_match); 206 + 207 + static struct platform_driver visconti_gpio_driver = { 208 + .probe = visconti_gpio_probe, 209 + .driver = { 210 + .name = "visconti_gpio", 211 + .of_match_table = of_match_ptr(visconti_gpio_of_match), 212 + } 213 + }; 214 + module_platform_driver(visconti_gpio_driver); 215 + 216 + MODULE_AUTHOR("Nobuhiro Iwamatsu <nobuhiro1.iwamatsu@toshiba.co.jp>"); 217 + MODULE_DESCRIPTION("Toshiba Visconti GPIO Driver"); 218 + MODULE_LICENSE("GPL v2");
+1 -1
drivers/gpio/gpio-vx855.c
··· 216 216 c->direction_output = vx855gpio_direction_output; 217 217 c->get = vx855gpio_get; 218 218 c->set = vx855gpio_set; 219 - c->set_config = vx855gpio_set_config, 219 + c->set_config = vx855gpio_set_config; 220 220 c->dbg_show = NULL; 221 221 c->base = 0; 222 222 c->ngpio = NR_VX855_GP;
+33 -32
drivers/gpio/gpio-wcove.c
··· 73 73 enum ctrl_register { 74 74 CTRL_IN, 75 75 CTRL_OUT, 76 + IRQ_STATUS, 77 + IRQ_MASK, 76 78 }; 77 79 78 80 /* ··· 114 112 return reg; 115 113 } 116 114 117 - static void wcove_update_irq_mask(struct wcove_gpio *wg, int gpio) 115 + static inline int to_ireg(int gpio, enum ctrl_register type, unsigned int *mask) 118 116 { 119 - unsigned int reg, mask; 117 + unsigned int reg = type == IRQ_STATUS ? IRQ_STATUS_BASE : IRQ_MASK_BASE; 120 118 121 119 if (gpio < GROUP0_NR_IRQS) { 122 - reg = IRQ_MASK_BASE; 123 - mask = BIT(gpio % GROUP0_NR_IRQS); 120 + reg += 0; 121 + *mask = BIT(gpio); 124 122 } else { 125 - reg = IRQ_MASK_BASE + 1; 126 - mask = BIT((gpio - GROUP0_NR_IRQS) % GROUP1_NR_IRQS); 123 + reg += 1; 124 + *mask = BIT(gpio - GROUP0_NR_IRQS); 127 125 } 128 126 127 + return reg; 128 + } 129 + 130 + static void wcove_update_irq_mask(struct wcove_gpio *wg, int gpio) 131 + { 132 + unsigned int mask, reg = to_ireg(gpio, IRQ_MASK, &mask); 133 + 129 134 if (wg->set_irq_mask) 130 - regmap_update_bits(wg->regmap, reg, mask, mask); 135 + regmap_set_bits(wg->regmap, reg, mask); 131 136 else 132 - regmap_update_bits(wg->regmap, reg, mask, 0); 137 + regmap_clear_bits(wg->regmap, reg, mask); 133 138 } 134 139 135 140 static void wcove_update_irq_ctrl(struct wcove_gpio *wg, int gpio) ··· 216 207 return; 217 208 218 209 if (value) 219 - regmap_update_bits(wg->regmap, reg, 1, 1); 210 + regmap_set_bits(wg->regmap, reg, 1); 220 211 else 221 - regmap_update_bits(wg->regmap, reg, 1, 0); 212 + regmap_clear_bits(wg->regmap, reg, 1); 222 213 } 223 214 224 215 static int wcove_gpio_set_config(struct gpio_chip *chip, unsigned int gpio, ··· 333 324 static irqreturn_t wcove_gpio_irq_handler(int irq, void *data) 334 325 { 335 326 struct wcove_gpio *wg = (struct wcove_gpio *)data; 336 - unsigned int pending, virq, gpio, mask, offset; 327 + unsigned int virq, gpio; 328 + unsigned long pending; 337 329 u8 p[2]; 338 330 339 331 if (regmap_bulk_read(wg->regmap, IRQ_STATUS_BASE, p, 2)) { ··· 349 339 /* Iterate until no interrupt is pending */ 350 340 while (pending) { 351 341 /* One iteration is for all pending bits */ 352 - for_each_set_bit(gpio, (const unsigned long *)&pending, 353 - WCOVE_GPIO_NUM) { 354 - offset = (gpio > GROUP0_NR_IRQS) ? 1 : 0; 355 - mask = (offset == 1) ? BIT(gpio - GROUP0_NR_IRQS) : 356 - BIT(gpio); 342 + for_each_set_bit(gpio, &pending, WCOVE_GPIO_NUM) { 343 + unsigned int mask, reg = to_ireg(gpio, IRQ_STATUS, &mask); 344 + 357 345 virq = irq_find_mapping(wg->chip.irq.domain, gpio); 358 346 handle_nested_irq(virq); 359 - regmap_update_bits(wg->regmap, IRQ_STATUS_BASE + offset, 360 - mask, mask); 347 + regmap_set_bits(wg->regmap, reg, mask); 361 348 } 362 349 363 350 /* Next iteration */ ··· 374 367 { 375 368 unsigned int ctlo, ctli, irq_mask, irq_status; 376 369 struct wcove_gpio *wg = gpiochip_get_data(chip); 377 - int gpio, offset, group, ret = 0; 370 + int gpio, mask, ret = 0; 378 371 379 372 for (gpio = 0; gpio < WCOVE_GPIO_NUM; gpio++) { 380 - group = gpio < GROUP0_NR_IRQS ? 0 : 1; 381 373 ret += regmap_read(wg->regmap, to_reg(gpio, CTRL_OUT), &ctlo); 382 374 ret += regmap_read(wg->regmap, to_reg(gpio, CTRL_IN), &ctli); 383 - ret += regmap_read(wg->regmap, IRQ_MASK_BASE + group, 384 - &irq_mask); 385 - ret += regmap_read(wg->regmap, IRQ_STATUS_BASE + group, 386 - &irq_status); 375 + ret += regmap_read(wg->regmap, to_ireg(gpio, IRQ_MASK, &mask), &irq_mask); 376 + ret += regmap_read(wg->regmap, to_ireg(gpio, IRQ_STATUS, &mask), &irq_status); 387 377 if (ret) { 388 378 pr_err("Failed to read registers: ctrl out/in or irq status/mask\n"); 389 379 break; 390 380 } 391 381 392 - offset = gpio % 8; 393 382 seq_printf(s, " gpio-%-2d %s %s %s %s ctlo=%2x,%s %s\n", 394 383 gpio, ctlo & CTLO_DIR_OUT ? "out" : "in ", 395 384 ctli & 0x1 ? "hi" : "lo", 396 385 ctli & CTLI_INTCNT_NE ? "fall" : " ", 397 386 ctli & CTLI_INTCNT_PE ? "rise" : " ", 398 387 ctlo, 399 - irq_mask & BIT(offset) ? "mask " : "unmask", 400 - irq_status & BIT(offset) ? "pending" : " "); 388 + irq_mask & mask ? "mask " : "unmask", 389 + irq_status & mask ? "pending" : " "); 401 390 } 402 391 } 403 392 ··· 437 434 wg->chip.get_direction = wcove_gpio_get_direction; 438 435 wg->chip.get = wcove_gpio_get; 439 436 wg->chip.set = wcove_gpio_set; 440 - wg->chip.set_config = wcove_gpio_set_config, 437 + wg->chip.set_config = wcove_gpio_set_config; 441 438 wg->chip.base = -1; 442 439 wg->chip.ngpio = WCOVE_VGPIO_NUM; 443 440 wg->chip.can_sleep = true; ··· 476 473 } 477 474 478 475 /* Enable GPIO0 interrupts */ 479 - ret = regmap_update_bits(wg->regmap, IRQ_MASK_BASE, GPIO_IRQ0_MASK, 480 - 0x00); 476 + ret = regmap_clear_bits(wg->regmap, IRQ_MASK_BASE + 0, GPIO_IRQ0_MASK); 481 477 if (ret) 482 478 return ret; 483 479 484 480 /* Enable GPIO1 interrupts */ 485 - ret = regmap_update_bits(wg->regmap, IRQ_MASK_BASE + 1, GPIO_IRQ1_MASK, 486 - 0x00); 481 + ret = regmap_clear_bits(wg->regmap, IRQ_MASK_BASE + 1, GPIO_IRQ1_MASK); 487 482 if (ret) 488 483 return ret; 489 484
+347 -22
drivers/gpio/gpio-xilinx.c
··· 10 10 #include <linux/errno.h> 11 11 #include <linux/gpio/driver.h> 12 12 #include <linux/init.h> 13 + #include <linux/interrupt.h> 13 14 #include <linux/io.h> 15 + #include <linux/irq.h> 14 16 #include <linux/module.h> 15 17 #include <linux/of_device.h> 16 18 #include <linux/of_platform.h> 19 + #include <linux/pm_runtime.h> 17 20 #include <linux/slab.h> 18 21 19 22 /* Register Offset Definitions */ ··· 24 21 #define XGPIO_TRI_OFFSET (0x4) /* I/O direction register */ 25 22 26 23 #define XGPIO_CHANNEL_OFFSET 0x8 24 + 25 + #define XGPIO_GIER_OFFSET 0x11c /* Global Interrupt Enable */ 26 + #define XGPIO_GIER_IE BIT(31) 27 + #define XGPIO_IPISR_OFFSET 0x120 /* IP Interrupt Status */ 28 + #define XGPIO_IPIER_OFFSET 0x128 /* IP Interrupt Enable */ 27 29 28 30 /* Read/Write access to the GPIO registers */ 29 31 #if defined(CONFIG_ARCH_ZYNQ) || defined(CONFIG_X86) ··· 44 36 * @gc: GPIO chip 45 37 * @regs: register block 46 38 * @gpio_width: GPIO width for every channel 47 - * @gpio_state: GPIO state shadow register 39 + * @gpio_state: GPIO write state shadow register 40 + * @gpio_last_irq_read: GPIO read state register from last interrupt 48 41 * @gpio_dir: GPIO direction shadow register 49 42 * @gpio_lock: Lock used for synchronization 43 + * @irq: IRQ used by GPIO device 44 + * @irqchip: IRQ chip 45 + * @irq_enable: GPIO IRQ enable/disable bitfield 46 + * @irq_rising_edge: GPIO IRQ rising edge enable/disable bitfield 47 + * @irq_falling_edge: GPIO IRQ falling edge enable/disable bitfield 50 48 * @clk: clock resource for this driver 51 49 */ 52 50 struct xgpio_instance { ··· 60 46 void __iomem *regs; 61 47 unsigned int gpio_width[2]; 62 48 u32 gpio_state[2]; 49 + u32 gpio_last_irq_read[2]; 63 50 u32 gpio_dir[2]; 64 - spinlock_t gpio_lock[2]; 51 + spinlock_t gpio_lock; /* For serializing operations */ 52 + int irq; 53 + struct irq_chip irqchip; 54 + u32 irq_enable[2]; 55 + u32 irq_rising_edge[2]; 56 + u32 irq_falling_edge[2]; 65 57 struct clk *clk; 66 58 }; 67 59 ··· 133 113 int index = xgpio_index(chip, gpio); 134 114 int offset = xgpio_offset(chip, gpio); 135 115 136 - spin_lock_irqsave(&chip->gpio_lock[index], flags); 116 + spin_lock_irqsave(&chip->gpio_lock, flags); 137 117 138 118 /* Write to GPIO signal and set its direction to output */ 139 119 if (val) ··· 144 124 xgpio_writereg(chip->regs + XGPIO_DATA_OFFSET + 145 125 xgpio_regoffset(chip, gpio), chip->gpio_state[index]); 146 126 147 - spin_unlock_irqrestore(&chip->gpio_lock[index], flags); 127 + spin_unlock_irqrestore(&chip->gpio_lock, flags); 148 128 } 149 129 150 130 /** ··· 164 144 int index = xgpio_index(chip, 0); 165 145 int offset, i; 166 146 167 - spin_lock_irqsave(&chip->gpio_lock[index], flags); 147 + spin_lock_irqsave(&chip->gpio_lock, flags); 168 148 169 149 /* Write to GPIO signals */ 170 150 for (i = 0; i < gc->ngpio; i++) { ··· 175 155 xgpio_writereg(chip->regs + XGPIO_DATA_OFFSET + 176 156 index * XGPIO_CHANNEL_OFFSET, 177 157 chip->gpio_state[index]); 178 - spin_unlock_irqrestore(&chip->gpio_lock[index], flags); 158 + spin_unlock_irqrestore(&chip->gpio_lock, flags); 179 159 index = xgpio_index(chip, i); 180 - spin_lock_irqsave(&chip->gpio_lock[index], flags); 160 + spin_lock_irqsave(&chip->gpio_lock, flags); 181 161 } 182 162 if (__test_and_clear_bit(i, mask)) { 183 163 offset = xgpio_offset(chip, i); ··· 191 171 xgpio_writereg(chip->regs + XGPIO_DATA_OFFSET + 192 172 index * XGPIO_CHANNEL_OFFSET, chip->gpio_state[index]); 193 173 194 - spin_unlock_irqrestore(&chip->gpio_lock[index], flags); 174 + spin_unlock_irqrestore(&chip->gpio_lock, flags); 195 175 } 196 176 197 177 /** ··· 210 190 int index = xgpio_index(chip, gpio); 211 191 int offset = xgpio_offset(chip, gpio); 212 192 213 - spin_lock_irqsave(&chip->gpio_lock[index], flags); 193 + spin_lock_irqsave(&chip->gpio_lock, flags); 214 194 215 195 /* Set the GPIO bit in shadow register and set direction as input */ 216 196 chip->gpio_dir[index] |= BIT(offset); 217 197 xgpio_writereg(chip->regs + XGPIO_TRI_OFFSET + 218 198 xgpio_regoffset(chip, gpio), chip->gpio_dir[index]); 219 199 220 - spin_unlock_irqrestore(&chip->gpio_lock[index], flags); 200 + spin_unlock_irqrestore(&chip->gpio_lock, flags); 221 201 222 202 return 0; 223 203 } ··· 241 221 int index = xgpio_index(chip, gpio); 242 222 int offset = xgpio_offset(chip, gpio); 243 223 244 - spin_lock_irqsave(&chip->gpio_lock[index], flags); 224 + spin_lock_irqsave(&chip->gpio_lock, flags); 245 225 246 226 /* Write state of GPIO signal */ 247 227 if (val) ··· 256 236 xgpio_writereg(chip->regs + XGPIO_TRI_OFFSET + 257 237 xgpio_regoffset(chip, gpio), chip->gpio_dir[index]); 258 238 259 - spin_unlock_irqrestore(&chip->gpio_lock[index], flags); 239 + spin_unlock_irqrestore(&chip->gpio_lock, flags); 260 240 261 241 return 0; 262 242 } ··· 279 259 chip->gpio_dir[1]); 280 260 } 281 261 262 + static int xgpio_request(struct gpio_chip *chip, unsigned int offset) 263 + { 264 + int ret; 265 + 266 + ret = pm_runtime_get_sync(chip->parent); 267 + /* 268 + * If the device is already active pm_runtime_get() will return 1 on 269 + * success, but gpio_request still needs to return 0. 270 + */ 271 + return ret < 0 ? ret : 0; 272 + } 273 + 274 + static void xgpio_free(struct gpio_chip *chip, unsigned int offset) 275 + { 276 + pm_runtime_put(chip->parent); 277 + } 278 + 279 + static int __maybe_unused xgpio_suspend(struct device *dev) 280 + { 281 + struct xgpio_instance *gpio = dev_get_drvdata(dev); 282 + struct irq_data *data = irq_get_irq_data(gpio->irq); 283 + 284 + if (!data) { 285 + dev_err(dev, "irq_get_irq_data() failed\n"); 286 + return -EINVAL; 287 + } 288 + 289 + if (!irqd_is_wakeup_set(data)) 290 + return pm_runtime_force_suspend(dev); 291 + 292 + return 0; 293 + } 294 + 282 295 /** 283 296 * xgpio_remove - Remove method for the GPIO device. 284 297 * @pdev: pointer to the platform device ··· 324 271 { 325 272 struct xgpio_instance *gpio = platform_get_drvdata(pdev); 326 273 274 + pm_runtime_get_sync(&pdev->dev); 275 + pm_runtime_put_noidle(&pdev->dev); 276 + pm_runtime_disable(&pdev->dev); 327 277 clk_disable_unprepare(gpio->clk); 328 278 329 279 return 0; 280 + } 281 + 282 + /** 283 + * xgpio_irq_ack - Acknowledge a child GPIO interrupt. 284 + * @irq_data: per IRQ and chip data passed down to chip functions 285 + * This currently does nothing, but irq_ack is unconditionally called by 286 + * handle_edge_irq and therefore must be defined. 287 + */ 288 + static void xgpio_irq_ack(struct irq_data *irq_data) 289 + { 290 + } 291 + 292 + static int __maybe_unused xgpio_resume(struct device *dev) 293 + { 294 + struct xgpio_instance *gpio = dev_get_drvdata(dev); 295 + struct irq_data *data = irq_get_irq_data(gpio->irq); 296 + 297 + if (!data) { 298 + dev_err(dev, "irq_get_irq_data() failed\n"); 299 + return -EINVAL; 300 + } 301 + 302 + if (!irqd_is_wakeup_set(data)) 303 + return pm_runtime_force_resume(dev); 304 + 305 + return 0; 306 + } 307 + 308 + static int __maybe_unused xgpio_runtime_suspend(struct device *dev) 309 + { 310 + struct platform_device *pdev = to_platform_device(dev); 311 + struct xgpio_instance *gpio = platform_get_drvdata(pdev); 312 + 313 + clk_disable(gpio->clk); 314 + 315 + return 0; 316 + } 317 + 318 + static int __maybe_unused xgpio_runtime_resume(struct device *dev) 319 + { 320 + struct platform_device *pdev = to_platform_device(dev); 321 + struct xgpio_instance *gpio = platform_get_drvdata(pdev); 322 + 323 + return clk_enable(gpio->clk); 324 + } 325 + 326 + static const struct dev_pm_ops xgpio_dev_pm_ops = { 327 + SET_SYSTEM_SLEEP_PM_OPS(xgpio_suspend, xgpio_resume) 328 + SET_RUNTIME_PM_OPS(xgpio_runtime_suspend, 329 + xgpio_runtime_resume, NULL) 330 + }; 331 + 332 + /** 333 + * xgpio_irq_mask - Write the specified signal of the GPIO device. 334 + * @irq_data: per IRQ and chip data passed down to chip functions 335 + */ 336 + static void xgpio_irq_mask(struct irq_data *irq_data) 337 + { 338 + unsigned long flags; 339 + struct xgpio_instance *chip = irq_data_get_irq_chip_data(irq_data); 340 + int irq_offset = irqd_to_hwirq(irq_data); 341 + int index = xgpio_index(chip, irq_offset); 342 + int offset = xgpio_offset(chip, irq_offset); 343 + 344 + spin_lock_irqsave(&chip->gpio_lock, flags); 345 + 346 + chip->irq_enable[index] &= ~BIT(offset); 347 + 348 + if (!chip->irq_enable[index]) { 349 + /* Disable per channel interrupt */ 350 + u32 temp = xgpio_readreg(chip->regs + XGPIO_IPIER_OFFSET); 351 + 352 + temp &= ~BIT(index); 353 + xgpio_writereg(chip->regs + XGPIO_IPIER_OFFSET, temp); 354 + } 355 + spin_unlock_irqrestore(&chip->gpio_lock, flags); 356 + } 357 + 358 + /** 359 + * xgpio_irq_unmask - Write the specified signal of the GPIO device. 360 + * @irq_data: per IRQ and chip data passed down to chip functions 361 + */ 362 + static void xgpio_irq_unmask(struct irq_data *irq_data) 363 + { 364 + unsigned long flags; 365 + struct xgpio_instance *chip = irq_data_get_irq_chip_data(irq_data); 366 + int irq_offset = irqd_to_hwirq(irq_data); 367 + int index = xgpio_index(chip, irq_offset); 368 + int offset = xgpio_offset(chip, irq_offset); 369 + u32 old_enable = chip->irq_enable[index]; 370 + 371 + spin_lock_irqsave(&chip->gpio_lock, flags); 372 + 373 + chip->irq_enable[index] |= BIT(offset); 374 + 375 + if (!old_enable) { 376 + /* Clear any existing per-channel interrupts */ 377 + u32 val = xgpio_readreg(chip->regs + XGPIO_IPISR_OFFSET) & 378 + BIT(index); 379 + 380 + if (val) 381 + xgpio_writereg(chip->regs + XGPIO_IPISR_OFFSET, val); 382 + 383 + /* Update GPIO IRQ read data before enabling interrupt*/ 384 + val = xgpio_readreg(chip->regs + XGPIO_DATA_OFFSET + 385 + index * XGPIO_CHANNEL_OFFSET); 386 + chip->gpio_last_irq_read[index] = val; 387 + 388 + /* Enable per channel interrupt */ 389 + val = xgpio_readreg(chip->regs + XGPIO_IPIER_OFFSET); 390 + val |= BIT(index); 391 + xgpio_writereg(chip->regs + XGPIO_IPIER_OFFSET, val); 392 + } 393 + 394 + spin_unlock_irqrestore(&chip->gpio_lock, flags); 395 + } 396 + 397 + /** 398 + * xgpio_set_irq_type - Write the specified signal of the GPIO device. 399 + * @irq_data: Per IRQ and chip data passed down to chip functions 400 + * @type: Interrupt type that is to be set for the gpio pin 401 + * 402 + * Return: 403 + * 0 if interrupt type is supported otherwise -EINVAL 404 + */ 405 + static int xgpio_set_irq_type(struct irq_data *irq_data, unsigned int type) 406 + { 407 + struct xgpio_instance *chip = irq_data_get_irq_chip_data(irq_data); 408 + int irq_offset = irqd_to_hwirq(irq_data); 409 + int index = xgpio_index(chip, irq_offset); 410 + int offset = xgpio_offset(chip, irq_offset); 411 + 412 + /* 413 + * The Xilinx GPIO hardware provides a single interrupt status 414 + * indication for any state change in a given GPIO channel (bank). 415 + * Therefore, only rising edge or falling edge triggers are 416 + * supported. 417 + */ 418 + switch (type & IRQ_TYPE_SENSE_MASK) { 419 + case IRQ_TYPE_EDGE_BOTH: 420 + chip->irq_rising_edge[index] |= BIT(offset); 421 + chip->irq_falling_edge[index] |= BIT(offset); 422 + break; 423 + case IRQ_TYPE_EDGE_RISING: 424 + chip->irq_rising_edge[index] |= BIT(offset); 425 + chip->irq_falling_edge[index] &= ~BIT(offset); 426 + break; 427 + case IRQ_TYPE_EDGE_FALLING: 428 + chip->irq_rising_edge[index] &= ~BIT(offset); 429 + chip->irq_falling_edge[index] |= BIT(offset); 430 + break; 431 + default: 432 + return -EINVAL; 433 + } 434 + 435 + irq_set_handler_locked(irq_data, handle_edge_irq); 436 + return 0; 437 + } 438 + 439 + /** 440 + * xgpio_irqhandler - Gpio interrupt service routine 441 + * @desc: Pointer to interrupt description 442 + */ 443 + static void xgpio_irqhandler(struct irq_desc *desc) 444 + { 445 + struct xgpio_instance *chip = irq_desc_get_handler_data(desc); 446 + struct irq_chip *irqchip = irq_desc_get_chip(desc); 447 + u32 num_channels = chip->gpio_width[1] ? 2 : 1; 448 + u32 offset = 0, index; 449 + u32 status = xgpio_readreg(chip->regs + XGPIO_IPISR_OFFSET); 450 + 451 + xgpio_writereg(chip->regs + XGPIO_IPISR_OFFSET, status); 452 + 453 + chained_irq_enter(irqchip, desc); 454 + for (index = 0; index < num_channels; index++) { 455 + if ((status & BIT(index))) { 456 + unsigned long rising_events, falling_events, all_events; 457 + unsigned long flags; 458 + u32 data, bit; 459 + unsigned int irq; 460 + 461 + spin_lock_irqsave(&chip->gpio_lock, flags); 462 + data = xgpio_readreg(chip->regs + XGPIO_DATA_OFFSET + 463 + index * XGPIO_CHANNEL_OFFSET); 464 + rising_events = data & 465 + ~chip->gpio_last_irq_read[index] & 466 + chip->irq_enable[index] & 467 + chip->irq_rising_edge[index]; 468 + falling_events = ~data & 469 + chip->gpio_last_irq_read[index] & 470 + chip->irq_enable[index] & 471 + chip->irq_falling_edge[index]; 472 + dev_dbg(chip->gc.parent, 473 + "IRQ chan %u rising 0x%lx falling 0x%lx\n", 474 + index, rising_events, falling_events); 475 + all_events = rising_events | falling_events; 476 + chip->gpio_last_irq_read[index] = data; 477 + spin_unlock_irqrestore(&chip->gpio_lock, flags); 478 + 479 + for_each_set_bit(bit, &all_events, 32) { 480 + irq = irq_find_mapping(chip->gc.irq.domain, 481 + offset + bit); 482 + generic_handle_irq(irq); 483 + } 484 + } 485 + offset += chip->gpio_width[index]; 486 + } 487 + 488 + chained_irq_exit(irqchip, desc); 330 489 } 331 490 332 491 /** ··· 554 289 struct xgpio_instance *chip; 555 290 int status = 0; 556 291 struct device_node *np = pdev->dev.of_node; 557 - u32 is_dual; 292 + u32 is_dual = 0; 293 + u32 cells = 2; 294 + struct gpio_irq_chip *girq; 295 + u32 temp; 558 296 559 297 chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL); 560 298 if (!chip) ··· 573 305 if (of_property_read_u32(np, "xlnx,tri-default", &chip->gpio_dir[0])) 574 306 chip->gpio_dir[0] = 0xFFFFFFFF; 575 307 308 + /* Update cells with gpio-cells value */ 309 + if (of_property_read_u32(np, "#gpio-cells", &cells)) 310 + dev_dbg(&pdev->dev, "Missing gpio-cells property\n"); 311 + 312 + if (cells != 2) { 313 + dev_err(&pdev->dev, "#gpio-cells mismatch\n"); 314 + return -EINVAL; 315 + } 316 + 576 317 /* 577 318 * Check device node and parent device node for device width 578 319 * and assume default width of 32 ··· 589 312 if (of_property_read_u32(np, "xlnx,gpio-width", &chip->gpio_width[0])) 590 313 chip->gpio_width[0] = 32; 591 314 592 - spin_lock_init(&chip->gpio_lock[0]); 315 + if (chip->gpio_width[0] > 32) 316 + return -EINVAL; 317 + 318 + spin_lock_init(&chip->gpio_lock); 593 319 594 320 if (of_property_read_u32(np, "xlnx,is-dual", &is_dual)) 595 321 is_dual = 0; ··· 616 336 &chip->gpio_width[1])) 617 337 chip->gpio_width[1] = 32; 618 338 619 - spin_lock_init(&chip->gpio_lock[1]); 339 + if (chip->gpio_width[1] > 32) 340 + return -EINVAL; 620 341 } 621 342 622 343 chip->gc.base = -1; ··· 625 344 chip->gc.parent = &pdev->dev; 626 345 chip->gc.direction_input = xgpio_dir_in; 627 346 chip->gc.direction_output = xgpio_dir_out; 347 + chip->gc.of_gpio_n_cells = cells; 628 348 chip->gc.get = xgpio_get; 629 349 chip->gc.set = xgpio_set; 350 + chip->gc.request = xgpio_request; 351 + chip->gc.free = xgpio_free; 630 352 chip->gc.set_multiple = xgpio_set_multiple; 631 353 632 354 chip->gc.label = dev_name(&pdev->dev); ··· 641 357 } 642 358 643 359 chip->clk = devm_clk_get_optional(&pdev->dev, NULL); 644 - if (IS_ERR(chip->clk)) { 645 - if (PTR_ERR(chip->clk) != -EPROBE_DEFER) 646 - dev_dbg(&pdev->dev, "Input clock not found\n"); 647 - return PTR_ERR(chip->clk); 648 - } 360 + if (IS_ERR(chip->clk)) 361 + return dev_err_probe(&pdev->dev, PTR_ERR(chip->clk), "input clock not found.\n"); 649 362 650 363 status = clk_prepare_enable(chip->clk); 651 364 if (status < 0) { 652 365 dev_err(&pdev->dev, "Failed to prepare clk\n"); 653 366 return status; 654 367 } 368 + pm_runtime_get_noresume(&pdev->dev); 369 + pm_runtime_set_active(&pdev->dev); 370 + pm_runtime_enable(&pdev->dev); 655 371 656 372 xgpio_save_regs(chip); 657 373 374 + chip->irq = platform_get_irq_optional(pdev, 0); 375 + if (chip->irq <= 0) 376 + goto skip_irq; 377 + 378 + chip->irqchip.name = "gpio-xilinx"; 379 + chip->irqchip.irq_ack = xgpio_irq_ack; 380 + chip->irqchip.irq_mask = xgpio_irq_mask; 381 + chip->irqchip.irq_unmask = xgpio_irq_unmask; 382 + chip->irqchip.irq_set_type = xgpio_set_irq_type; 383 + 384 + /* Disable per-channel interrupts */ 385 + xgpio_writereg(chip->regs + XGPIO_IPIER_OFFSET, 0); 386 + /* Clear any existing per-channel interrupts */ 387 + temp = xgpio_readreg(chip->regs + XGPIO_IPISR_OFFSET); 388 + xgpio_writereg(chip->regs + XGPIO_IPISR_OFFSET, temp); 389 + /* Enable global interrupts */ 390 + xgpio_writereg(chip->regs + XGPIO_GIER_OFFSET, XGPIO_GIER_IE); 391 + 392 + girq = &chip->gc.irq; 393 + girq->chip = &chip->irqchip; 394 + girq->parent_handler = xgpio_irqhandler; 395 + girq->num_parents = 1; 396 + girq->parents = devm_kcalloc(&pdev->dev, 1, 397 + sizeof(*girq->parents), 398 + GFP_KERNEL); 399 + if (!girq->parents) { 400 + status = -ENOMEM; 401 + goto err_pm_put; 402 + } 403 + girq->parents[0] = chip->irq; 404 + girq->default_type = IRQ_TYPE_NONE; 405 + girq->handler = handle_bad_irq; 406 + 407 + skip_irq: 658 408 status = devm_gpiochip_add_data(&pdev->dev, &chip->gc, chip); 659 409 if (status) { 660 410 dev_err(&pdev->dev, "failed to add GPIO chip\n"); 661 - clk_disable_unprepare(chip->clk); 662 - return status; 411 + goto err_pm_put; 663 412 } 664 413 414 + pm_runtime_put(&pdev->dev); 665 415 return 0; 416 + 417 + err_pm_put: 418 + pm_runtime_disable(&pdev->dev); 419 + pm_runtime_put_noidle(&pdev->dev); 420 + clk_disable_unprepare(chip->clk); 421 + return status; 666 422 } 667 423 668 424 static const struct of_device_id xgpio_of_match[] = { ··· 718 394 .driver = { 719 395 .name = "gpio-xilinx", 720 396 .of_match_table = xgpio_of_match, 397 + .pm = &xgpio_dev_pm_ops, 721 398 }, 722 399 }; 723 400
-289
drivers/gpio/gpio-zx.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-only 2 - /* 3 - * ZTE ZX296702 GPIO driver 4 - * 5 - * Author: Jun Nie <jun.nie@linaro.org> 6 - * 7 - * Copyright (C) 2015 Linaro Ltd. 8 - */ 9 - #include <linux/bitops.h> 10 - #include <linux/device.h> 11 - #include <linux/errno.h> 12 - #include <linux/gpio/driver.h> 13 - #include <linux/irqchip/chained_irq.h> 14 - #include <linux/init.h> 15 - #include <linux/of.h> 16 - #include <linux/pinctrl/consumer.h> 17 - #include <linux/platform_device.h> 18 - #include <linux/pm.h> 19 - #include <linux/slab.h> 20 - #include <linux/spinlock.h> 21 - 22 - #define ZX_GPIO_DIR 0x00 23 - #define ZX_GPIO_IVE 0x04 24 - #define ZX_GPIO_IV 0x08 25 - #define ZX_GPIO_IEP 0x0C 26 - #define ZX_GPIO_IEN 0x10 27 - #define ZX_GPIO_DI 0x14 28 - #define ZX_GPIO_DO1 0x18 29 - #define ZX_GPIO_DO0 0x1C 30 - #define ZX_GPIO_DO 0x20 31 - 32 - #define ZX_GPIO_IM 0x28 33 - #define ZX_GPIO_IE 0x2C 34 - 35 - #define ZX_GPIO_MIS 0x30 36 - #define ZX_GPIO_IC 0x34 37 - 38 - #define ZX_GPIO_NR 16 39 - 40 - struct zx_gpio { 41 - raw_spinlock_t lock; 42 - 43 - void __iomem *base; 44 - struct gpio_chip gc; 45 - }; 46 - 47 - static int zx_direction_input(struct gpio_chip *gc, unsigned offset) 48 - { 49 - struct zx_gpio *chip = gpiochip_get_data(gc); 50 - unsigned long flags; 51 - u16 gpiodir; 52 - 53 - if (offset >= gc->ngpio) 54 - return -EINVAL; 55 - 56 - raw_spin_lock_irqsave(&chip->lock, flags); 57 - gpiodir = readw_relaxed(chip->base + ZX_GPIO_DIR); 58 - gpiodir &= ~BIT(offset); 59 - writew_relaxed(gpiodir, chip->base + ZX_GPIO_DIR); 60 - raw_spin_unlock_irqrestore(&chip->lock, flags); 61 - 62 - return 0; 63 - } 64 - 65 - static int zx_direction_output(struct gpio_chip *gc, unsigned offset, 66 - int value) 67 - { 68 - struct zx_gpio *chip = gpiochip_get_data(gc); 69 - unsigned long flags; 70 - u16 gpiodir; 71 - 72 - if (offset >= gc->ngpio) 73 - return -EINVAL; 74 - 75 - raw_spin_lock_irqsave(&chip->lock, flags); 76 - gpiodir = readw_relaxed(chip->base + ZX_GPIO_DIR); 77 - gpiodir |= BIT(offset); 78 - writew_relaxed(gpiodir, chip->base + ZX_GPIO_DIR); 79 - 80 - if (value) 81 - writew_relaxed(BIT(offset), chip->base + ZX_GPIO_DO1); 82 - else 83 - writew_relaxed(BIT(offset), chip->base + ZX_GPIO_DO0); 84 - raw_spin_unlock_irqrestore(&chip->lock, flags); 85 - 86 - return 0; 87 - } 88 - 89 - static int zx_get_value(struct gpio_chip *gc, unsigned offset) 90 - { 91 - struct zx_gpio *chip = gpiochip_get_data(gc); 92 - 93 - return !!(readw_relaxed(chip->base + ZX_GPIO_DI) & BIT(offset)); 94 - } 95 - 96 - static void zx_set_value(struct gpio_chip *gc, unsigned offset, int value) 97 - { 98 - struct zx_gpio *chip = gpiochip_get_data(gc); 99 - 100 - if (value) 101 - writew_relaxed(BIT(offset), chip->base + ZX_GPIO_DO1); 102 - else 103 - writew_relaxed(BIT(offset), chip->base + ZX_GPIO_DO0); 104 - } 105 - 106 - static int zx_irq_type(struct irq_data *d, unsigned trigger) 107 - { 108 - struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 109 - struct zx_gpio *chip = gpiochip_get_data(gc); 110 - int offset = irqd_to_hwirq(d); 111 - unsigned long flags; 112 - u16 gpiois, gpioi_epos, gpioi_eneg, gpioiev; 113 - u16 bit = BIT(offset); 114 - 115 - if (offset < 0 || offset >= ZX_GPIO_NR) 116 - return -EINVAL; 117 - 118 - raw_spin_lock_irqsave(&chip->lock, flags); 119 - 120 - gpioiev = readw_relaxed(chip->base + ZX_GPIO_IV); 121 - gpiois = readw_relaxed(chip->base + ZX_GPIO_IVE); 122 - gpioi_epos = readw_relaxed(chip->base + ZX_GPIO_IEP); 123 - gpioi_eneg = readw_relaxed(chip->base + ZX_GPIO_IEN); 124 - 125 - if (trigger & (IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) { 126 - gpiois |= bit; 127 - if (trigger & IRQ_TYPE_LEVEL_HIGH) 128 - gpioiev |= bit; 129 - else 130 - gpioiev &= ~bit; 131 - } else 132 - gpiois &= ~bit; 133 - 134 - if ((trigger & IRQ_TYPE_EDGE_BOTH) == IRQ_TYPE_EDGE_BOTH) { 135 - gpioi_epos |= bit; 136 - gpioi_eneg |= bit; 137 - } else { 138 - if (trigger & IRQ_TYPE_EDGE_RISING) { 139 - gpioi_epos |= bit; 140 - gpioi_eneg &= ~bit; 141 - } else if (trigger & IRQ_TYPE_EDGE_FALLING) { 142 - gpioi_eneg |= bit; 143 - gpioi_epos &= ~bit; 144 - } 145 - } 146 - 147 - writew_relaxed(gpiois, chip->base + ZX_GPIO_IVE); 148 - writew_relaxed(gpioi_epos, chip->base + ZX_GPIO_IEP); 149 - writew_relaxed(gpioi_eneg, chip->base + ZX_GPIO_IEN); 150 - writew_relaxed(gpioiev, chip->base + ZX_GPIO_IV); 151 - raw_spin_unlock_irqrestore(&chip->lock, flags); 152 - 153 - return 0; 154 - } 155 - 156 - static void zx_irq_handler(struct irq_desc *desc) 157 - { 158 - unsigned long pending; 159 - int offset; 160 - struct gpio_chip *gc = irq_desc_get_handler_data(desc); 161 - struct zx_gpio *chip = gpiochip_get_data(gc); 162 - struct irq_chip *irqchip = irq_desc_get_chip(desc); 163 - 164 - chained_irq_enter(irqchip, desc); 165 - 166 - pending = readw_relaxed(chip->base + ZX_GPIO_MIS); 167 - writew_relaxed(pending, chip->base + ZX_GPIO_IC); 168 - if (pending) { 169 - for_each_set_bit(offset, &pending, ZX_GPIO_NR) 170 - generic_handle_irq(irq_find_mapping(gc->irq.domain, 171 - offset)); 172 - } 173 - 174 - chained_irq_exit(irqchip, desc); 175 - } 176 - 177 - static void zx_irq_mask(struct irq_data *d) 178 - { 179 - struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 180 - struct zx_gpio *chip = gpiochip_get_data(gc); 181 - u16 mask = BIT(irqd_to_hwirq(d) % ZX_GPIO_NR); 182 - u16 gpioie; 183 - 184 - raw_spin_lock(&chip->lock); 185 - gpioie = readw_relaxed(chip->base + ZX_GPIO_IM) | mask; 186 - writew_relaxed(gpioie, chip->base + ZX_GPIO_IM); 187 - gpioie = readw_relaxed(chip->base + ZX_GPIO_IE) & ~mask; 188 - writew_relaxed(gpioie, chip->base + ZX_GPIO_IE); 189 - raw_spin_unlock(&chip->lock); 190 - } 191 - 192 - static void zx_irq_unmask(struct irq_data *d) 193 - { 194 - struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 195 - struct zx_gpio *chip = gpiochip_get_data(gc); 196 - u16 mask = BIT(irqd_to_hwirq(d) % ZX_GPIO_NR); 197 - u16 gpioie; 198 - 199 - raw_spin_lock(&chip->lock); 200 - gpioie = readw_relaxed(chip->base + ZX_GPIO_IM) & ~mask; 201 - writew_relaxed(gpioie, chip->base + ZX_GPIO_IM); 202 - gpioie = readw_relaxed(chip->base + ZX_GPIO_IE) | mask; 203 - writew_relaxed(gpioie, chip->base + ZX_GPIO_IE); 204 - raw_spin_unlock(&chip->lock); 205 - } 206 - 207 - static struct irq_chip zx_irqchip = { 208 - .name = "zx-gpio", 209 - .irq_mask = zx_irq_mask, 210 - .irq_unmask = zx_irq_unmask, 211 - .irq_set_type = zx_irq_type, 212 - }; 213 - 214 - static int zx_gpio_probe(struct platform_device *pdev) 215 - { 216 - struct device *dev = &pdev->dev; 217 - struct zx_gpio *chip; 218 - struct gpio_irq_chip *girq; 219 - int irq, id, ret; 220 - 221 - chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); 222 - if (!chip) 223 - return -ENOMEM; 224 - 225 - chip->base = devm_platform_ioremap_resource(pdev, 0); 226 - if (IS_ERR(chip->base)) 227 - return PTR_ERR(chip->base); 228 - 229 - id = of_alias_get_id(dev->of_node, "gpio"); 230 - 231 - raw_spin_lock_init(&chip->lock); 232 - chip->gc.request = gpiochip_generic_request; 233 - chip->gc.free = gpiochip_generic_free; 234 - chip->gc.direction_input = zx_direction_input; 235 - chip->gc.direction_output = zx_direction_output; 236 - chip->gc.get = zx_get_value; 237 - chip->gc.set = zx_set_value; 238 - chip->gc.base = ZX_GPIO_NR * id; 239 - chip->gc.ngpio = ZX_GPIO_NR; 240 - chip->gc.label = dev_name(dev); 241 - chip->gc.parent = dev; 242 - chip->gc.owner = THIS_MODULE; 243 - 244 - /* 245 - * irq_chip support 246 - */ 247 - writew_relaxed(0xffff, chip->base + ZX_GPIO_IM); 248 - writew_relaxed(0, chip->base + ZX_GPIO_IE); 249 - irq = platform_get_irq(pdev, 0); 250 - if (irq < 0) 251 - return irq; 252 - girq = &chip->gc.irq; 253 - girq->chip = &zx_irqchip; 254 - girq->parent_handler = zx_irq_handler; 255 - girq->num_parents = 1; 256 - girq->parents = devm_kcalloc(&pdev->dev, 1, 257 - sizeof(*girq->parents), 258 - GFP_KERNEL); 259 - if (!girq->parents) 260 - return -ENOMEM; 261 - girq->parents[0] = irq; 262 - girq->default_type = IRQ_TYPE_NONE; 263 - girq->handler = handle_simple_irq; 264 - 265 - ret = gpiochip_add_data(&chip->gc, chip); 266 - if (ret) 267 - return ret; 268 - 269 - platform_set_drvdata(pdev, chip); 270 - dev_info(dev, "ZX GPIO chip registered\n"); 271 - 272 - return 0; 273 - } 274 - 275 - static const struct of_device_id zx_gpio_match[] = { 276 - { 277 - .compatible = "zte,zx296702-gpio", 278 - }, 279 - { }, 280 - }; 281 - 282 - static struct platform_driver zx_gpio_driver = { 283 - .probe = zx_gpio_probe, 284 - .driver = { 285 - .name = "zx_gpio", 286 - .of_match_table = of_match_ptr(zx_gpio_match), 287 - }, 288 - }; 289 - builtin_platform_driver(zx_gpio_driver)
+23
drivers/pinctrl/visconti/pinctrl-common.c
··· 245 245 return 0; 246 246 } 247 247 248 + static int visconti_gpio_request_enable(struct pinctrl_dev *pctldev, 249 + struct pinctrl_gpio_range *range, 250 + unsigned int pin) 251 + { 252 + struct visconti_pinctrl *priv = pinctrl_dev_get_drvdata(pctldev); 253 + const struct visconti_mux *gpio_mux = &priv->devdata->gpio_mux[pin]; 254 + unsigned long flags; 255 + unsigned int val; 256 + 257 + dev_dbg(priv->dev, "%s: pin = %d\n", __func__, pin); 258 + 259 + /* update mux */ 260 + spin_lock_irqsave(&priv->lock, flags); 261 + val = readl(priv->base + gpio_mux->offset); 262 + val &= ~gpio_mux->mask; 263 + val |= gpio_mux->val; 264 + writel(val, priv->base + gpio_mux->offset); 265 + spin_unlock_irqrestore(&priv->lock, flags); 266 + 267 + return 0; 268 + } 269 + 248 270 static const struct pinmux_ops visconti_pinmux_ops = { 249 271 .get_functions_count = visconti_get_functions_count, 250 272 .get_function_name = visconti_get_function_name, 251 273 .get_function_groups = visconti_get_function_groups, 252 274 .set_mux = visconti_set_mux, 275 + .gpio_request_enable = visconti_gpio_request_enable, 253 276 .strict = true, 254 277 }; 255 278
+2 -2
include/linux/gpio/machine.h
··· 75 75 * gpiod_get_index() 76 76 */ 77 77 #define GPIO_LOOKUP_IDX(_key, _chip_hwnum, _con_id, _idx, _flags) \ 78 - { \ 78 + (struct gpiod_lookup) { \ 79 79 .key = _key, \ 80 80 .chip_hwnum = _chip_hwnum, \ 81 81 .con_id = _con_id, \ ··· 87 87 * Simple definition of a single GPIO hog in an array. 88 88 */ 89 89 #define GPIO_HOG(_chip_label, _chip_hwnum, _line_name, _lflags, _dflags) \ 90 - { \ 90 + (struct gpiod_hog) { \ 91 91 .chip_label = _chip_label, \ 92 92 .chip_hwnum = _chip_hwnum, \ 93 93 .line_name = _line_name, \
+2 -2
include/uapi/linux/gpio.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 1 + /* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */ 2 2 /* 3 3 * <linux/gpio.h> - userspace ABI for the GPIO character devices 4 4 * ··· 212 212 * @offset: the local offset on this GPIO chip, fill this in when 213 213 * requesting the line information from the kernel 214 214 * @num_attrs: the number of attributes in @attrs 215 - * @flags: flags for the GPIO lines, with values from &enum 215 + * @flags: flags for this GPIO line, with values from &enum 216 216 * gpio_v2_line_flag, such as %GPIO_V2_LINE_FLAG_ACTIVE_LOW, 217 217 * %GPIO_V2_LINE_FLAG_OUTPUT etc, added together. 218 218 * @attrs: the configuration attributes associated with the line
+17 -4
lib/cmdline.c
··· 83 83 * get_options - Parse a string into a list of integers 84 84 * @str: String to be parsed 85 85 * @nints: size of integer array 86 - * @ints: integer array 86 + * @ints: integer array (must have room for at least one element) 87 87 * 88 88 * This function parses a string containing a comma-separated 89 89 * list of integers, a hyphen-separated range of _positive_ integers, 90 90 * or a combination of both. The parse halts when the array is 91 91 * full, or when no more numbers can be retrieved from the 92 92 * string. 93 + * 94 + * When @nints is 0, the function just validates the given @str and 95 + * returns the amount of parseable integers as described below. 96 + * 97 + * Returns: 98 + * 99 + * The first element is filled by the number of collected integers 100 + * in the range. The rest is what was parsed from the @str. 93 101 * 94 102 * Return value is the character in the string which caused 95 103 * the parse to end (typically a null terminator, if @str is ··· 106 98 107 99 char *get_options(const char *str, int nints, int *ints) 108 100 { 101 + bool validate = (nints == 0); 109 102 int res, i = 1; 110 103 111 - while (i < nints) { 112 - res = get_option((char **)&str, ints + i); 104 + while (i < nints || validate) { 105 + int *pint = validate ? ints : ints + i; 106 + 107 + res = get_option((char **)&str, pint); 113 108 if (res == 0) 114 109 break; 115 110 if (res == 3) { 111 + int n = validate ? 0 : nints - i; 116 112 int range_nums; 117 - range_nums = get_range((char **)&str, ints + i, nints - i); 113 + 114 + range_nums = get_range((char **)&str, pint, n); 118 115 if (range_nums < 0) 119 116 break; 120 117 /*
+56
lib/cmdline_kunit.c
··· 18 18 1, 3, 2, 1, 1, 1, 3, 1, 19 19 }; 20 20 21 + static_assert(ARRAY_SIZE(cmdline_test_strings) == ARRAY_SIZE(cmdline_test_values)); 22 + 23 + static const char *cmdline_test_range_strings[] = { 24 + "-7" , "--7" , "-1-2" , "7--9", 25 + "7-" , "-7--9", "7-9," , "9-7" , 26 + "5-a", "a-5" , "5-8" , ",8-5", 27 + "+,1", "-,4" , "-3,0-1,6", "4,-" , 28 + " +2", " -9" , "0-1,-3,6", "- 9" , 29 + }; 30 + 31 + static const int cmdline_test_range_values[][16] = { 32 + { 1, -7, }, { 0, -0, }, { 4, -1, 0, +1, 2, }, { 0, 7, }, 33 + { 0, +7, }, { 0, -7, }, { 3, +7, 8, +9, 0, }, { 0, 9, }, 34 + { 0, +5, }, { 0, -0, }, { 4, +5, 6, +7, 8, }, { 0, 0, }, 35 + { 0, +0, }, { 0, -0, }, { 4, -3, 0, +1, 6, }, { 1, 4, }, 36 + { 0, +0, }, { 0, -0, }, { 4, +0, 1, -3, 6, }, { 0, 0, }, 37 + }; 38 + 39 + static_assert(ARRAY_SIZE(cmdline_test_range_strings) == ARRAY_SIZE(cmdline_test_range_values)); 40 + 21 41 static void cmdline_do_one_test(struct kunit *test, const char *in, int rc, int offset) 22 42 { 23 43 const char *fmt = "Pattern: %s"; ··· 104 84 } while (++i < ARRAY_SIZE(cmdline_test_strings)); 105 85 } 106 86 87 + static void cmdline_do_one_range_test(struct kunit *test, const char *in, 88 + unsigned int n, const int *e) 89 + { 90 + unsigned int i; 91 + int r[16]; 92 + int *p; 93 + 94 + memset(r, 0, sizeof(r)); 95 + get_options(in, ARRAY_SIZE(r), r); 96 + KUNIT_EXPECT_EQ_MSG(test, r[0], e[0], "in test %u (parsed) expected %d numbers, got %d", 97 + n, e[0], r[0]); 98 + for (i = 1; i < ARRAY_SIZE(r); i++) 99 + KUNIT_EXPECT_EQ_MSG(test, r[i], e[i], "in test %u at %u", n, i); 100 + 101 + memset(r, 0, sizeof(r)); 102 + get_options(in, 0, r); 103 + KUNIT_EXPECT_EQ_MSG(test, r[0], e[0], "in test %u (validated) expected %d numbers, got %d", 104 + n, e[0], r[0]); 105 + 106 + p = memchr_inv(&r[1], 0, sizeof(r) - sizeof(r[0])); 107 + KUNIT_EXPECT_PTR_EQ_MSG(test, p, (int *)0, "in test %u at %u out of bound", n, p - r); 108 + } 109 + 110 + static void cmdline_test_range(struct kunit *test) 111 + { 112 + unsigned int i = 0; 113 + 114 + do { 115 + const char *str = cmdline_test_range_strings[i]; 116 + const int *e = cmdline_test_range_values[i]; 117 + 118 + cmdline_do_one_range_test(test, str, i, e); 119 + } while (++i < ARRAY_SIZE(cmdline_test_range_strings)); 120 + } 121 + 107 122 static struct kunit_case cmdline_test_cases[] = { 108 123 KUNIT_CASE(cmdline_test_noint), 109 124 KUNIT_CASE(cmdline_test_lead_int), 110 125 KUNIT_CASE(cmdline_test_tail_int), 126 + KUNIT_CASE(cmdline_test_range), 111 127 {} 112 128 }; 113 129
-89
tools/gpio/gpio-utils.c
··· 32 32 * following api will request gpio lines, do the operation and then 33 33 * release these lines. 34 34 */ 35 - /** 36 - * gpiotools_request_linehandle() - request gpio lines in a gpiochip 37 - * @device_name: The name of gpiochip without prefix "/dev/", 38 - * such as "gpiochip0" 39 - * @lines: An array desired lines, specified by offset 40 - * index for the associated GPIO device. 41 - * @num_lines: The number of lines to request. 42 - * @flag: The new flag for requsted gpio. Reference 43 - * "linux/gpio.h" for the meaning of flag. 44 - * @data: Default value will be set to gpio when flag is 45 - * GPIOHANDLE_REQUEST_OUTPUT. 46 - * @consumer_label: The name of consumer, such as "sysfs", 47 - * "powerkey". This is useful for other users to 48 - * know who is using. 49 - * 50 - * Request gpio lines through the ioctl provided by chardev. User 51 - * could call gpiotools_set_values() and gpiotools_get_values() to 52 - * read and write respectively through the returned fd. Call 53 - * gpiotools_release_linehandle() to release these lines after that. 54 - * 55 - * Return: On success return the fd; 56 - * On failure return the errno. 57 - */ 58 - int gpiotools_request_linehandle(const char *device_name, unsigned int *lines, 59 - unsigned int num_lines, unsigned int flag, 60 - struct gpiohandle_data *data, 61 - const char *consumer_label) 62 - { 63 - struct gpiohandle_request req; 64 - char *chrdev_name; 65 - int fd; 66 - int i; 67 - int ret; 68 - 69 - ret = asprintf(&chrdev_name, "/dev/%s", device_name); 70 - if (ret < 0) 71 - return -ENOMEM; 72 - 73 - fd = open(chrdev_name, 0); 74 - if (fd == -1) { 75 - ret = -errno; 76 - fprintf(stderr, "Failed to open %s, %s\n", 77 - chrdev_name, strerror(errno)); 78 - goto exit_free_name; 79 - } 80 - 81 - for (i = 0; i < num_lines; i++) 82 - req.lineoffsets[i] = lines[i]; 83 - 84 - req.flags = flag; 85 - strcpy(req.consumer_label, consumer_label); 86 - req.lines = num_lines; 87 - if (flag & GPIOHANDLE_REQUEST_OUTPUT) 88 - memcpy(req.default_values, data, sizeof(req.default_values)); 89 - 90 - ret = ioctl(fd, GPIO_GET_LINEHANDLE_IOCTL, &req); 91 - if (ret == -1) { 92 - ret = -errno; 93 - fprintf(stderr, "Failed to issue %s (%d), %s\n", 94 - "GPIO_GET_LINEHANDLE_IOCTL", ret, strerror(errno)); 95 - } 96 - 97 - if (close(fd) == -1) 98 - perror("Failed to close GPIO character device file"); 99 - exit_free_name: 100 - free(chrdev_name); 101 - return ret < 0 ? ret : req.fd; 102 - } 103 35 104 36 /** 105 37 * gpiotools_request_line() - request gpio lines in a gpiochip ··· 142 210 fprintf(stderr, "Failed to issue %s (%d), %s\n", 143 211 "GPIOHANDLE_GET_LINE_VALUES_IOCTL", ret, 144 212 strerror(errno)); 145 - } 146 - 147 - return ret; 148 - } 149 - 150 - /** 151 - * gpiotools_release_linehandle(): Release the line(s) of gpiochip 152 - * @fd: The fd returned by 153 - * gpiotools_request_linehandle(). 154 - * 155 - * Return: On success return 0; 156 - * On failure return the errno. 157 - */ 158 - int gpiotools_release_linehandle(const int fd) 159 - { 160 - int ret; 161 - 162 - ret = close(fd); 163 - if (ret == -1) { 164 - perror("Failed to close GPIO LINEHANDLE device file"); 165 - ret = -errno; 166 213 } 167 214 168 215 return ret;
-6
tools/gpio/gpio-utils.h
··· 24 24 strncmp(str, prefix, strlen(prefix)) == 0; 25 25 } 26 26 27 - int gpiotools_request_linehandle(const char *device_name, unsigned int *lines, 28 - unsigned int num_lines, unsigned int flag, 29 - struct gpiohandle_data *data, 30 - const char *consumer_label); 31 - int gpiotools_release_linehandle(const int fd); 32 - 33 27 int gpiotools_request_line(const char *device_name, 34 28 unsigned int *lines, 35 29 unsigned int num_lines,
-9
tools/testing/selftests/Makefile
··· 126 126 export KSFT_KHDR_INSTALL_DONE := 1 127 127 export BUILD 128 128 129 - # build and run gpio when output directory is the src dir. 130 - # gpio has dependency on tools/gpio and builds tools/gpio 131 - # objects in the src directory in all cases making the src 132 - # repo dirty even when objects are relocated. 133 - ifneq (1,$(DEFAULT_INSTALL_HDR_PATH)) 134 - TMP := $(filter-out gpio, $(TARGETS)) 135 - TARGETS := $(TMP) 136 - endif 137 - 138 129 # set default goal to all, so make without a target runs all, even when 139 130 # all isn't the first target in the file. 140 131 .DEFAULT_GOAL := all
+1 -25
tools/testing/selftests/gpio/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 2 3 - VAR_CFLAGS := $(shell pkg-config --cflags mount 2>/dev/null) 4 - VAR_LDLIBS := $(shell pkg-config --libs mount 2>/dev/null) 5 - ifeq ($(VAR_LDLIBS),) 6 - VAR_LDLIBS := -lmount -I/usr/include/libmount 7 - endif 8 - 9 - CFLAGS += -O2 -g -std=gnu99 -Wall -I../../../../usr/include/ $(VAR_CFLAGS) 10 - LDLIBS += $(VAR_LDLIBS) 11 - 12 3 TEST_PROGS := gpio-mockup.sh 13 4 TEST_FILES := gpio-mockup-sysfs.sh 14 - TEST_GEN_PROGS_EXTENDED := gpio-mockup-chardev 5 + TEST_GEN_PROGS_EXTENDED := gpio-mockup-cdev 15 6 16 - KSFT_KHDR_INSTALL := 1 17 7 include ../lib.mk 18 - 19 - GPIODIR := $(realpath ../../../gpio) 20 - GPIOOUT := $(OUTPUT)/tools-gpio/ 21 - GPIOOBJ := $(GPIOOUT)/gpio-utils.o 22 - 23 - CLEAN += ; $(RM) -rf $(GPIOOUT) 24 - 25 - $(TEST_GEN_PROGS_EXTENDED): $(GPIOOBJ) 26 - 27 - $(GPIOOUT): 28 - mkdir -p $@ 29 - 30 - $(GPIOOBJ): $(GPIOOUT) 31 - $(MAKE) OUTPUT=$(GPIOOUT) -C $(GPIODIR)
+1
tools/testing/selftests/gpio/config
··· 1 1 CONFIG_GPIOLIB=y 2 + CONFIG_GPIO_CDEV=y 2 3 CONFIG_GPIO_MOCKUP=m
+198
tools/testing/selftests/gpio/gpio-mockup-cdev.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * GPIO mockup cdev test helper 4 + * 5 + * Copyright (C) 2020 Kent Gibson 6 + */ 7 + 8 + #include <errno.h> 9 + #include <fcntl.h> 10 + #include <signal.h> 11 + #include <stdint.h> 12 + #include <stdio.h> 13 + #include <stdlib.h> 14 + #include <string.h> 15 + #include <unistd.h> 16 + #include <sys/ioctl.h> 17 + #include <linux/gpio.h> 18 + 19 + #define CONSUMER "gpio-mockup-cdev" 20 + 21 + static int request_line_v2(int cfd, unsigned int offset, 22 + uint64_t flags, unsigned int val) 23 + { 24 + struct gpio_v2_line_request req; 25 + int ret; 26 + 27 + memset(&req, 0, sizeof(req)); 28 + req.num_lines = 1; 29 + req.offsets[0] = offset; 30 + req.config.flags = flags; 31 + strcpy(req.consumer, CONSUMER); 32 + if (flags & GPIO_V2_LINE_FLAG_OUTPUT) { 33 + req.config.num_attrs = 1; 34 + req.config.attrs[0].mask = 1; 35 + req.config.attrs[0].attr.id = GPIO_V2_LINE_ATTR_ID_OUTPUT_VALUES; 36 + if (val) 37 + req.config.attrs[0].attr.values = 1; 38 + } 39 + ret = ioctl(cfd, GPIO_V2_GET_LINE_IOCTL, &req); 40 + if (ret == -1) 41 + return -errno; 42 + return req.fd; 43 + } 44 + 45 + 46 + static int get_value_v2(int lfd) 47 + { 48 + struct gpio_v2_line_values vals; 49 + int ret; 50 + 51 + memset(&vals, 0, sizeof(vals)); 52 + vals.mask = 1; 53 + ret = ioctl(lfd, GPIO_V2_LINE_GET_VALUES_IOCTL, &vals); 54 + if (ret == -1) 55 + return -errno; 56 + return vals.bits & 0x1; 57 + } 58 + 59 + static int request_line_v1(int cfd, unsigned int offset, 60 + uint32_t flags, unsigned int val) 61 + { 62 + struct gpiohandle_request req; 63 + int ret; 64 + 65 + memset(&req, 0, sizeof(req)); 66 + req.lines = 1; 67 + req.lineoffsets[0] = offset; 68 + req.flags = flags; 69 + strcpy(req.consumer_label, CONSUMER); 70 + if (flags & GPIOHANDLE_REQUEST_OUTPUT) 71 + req.default_values[0] = val; 72 + 73 + ret = ioctl(cfd, GPIO_GET_LINEHANDLE_IOCTL, &req); 74 + if (ret == -1) 75 + return -errno; 76 + return req.fd; 77 + } 78 + 79 + static int get_value_v1(int lfd) 80 + { 81 + struct gpiohandle_data vals; 82 + int ret; 83 + 84 + memset(&vals, 0, sizeof(vals)); 85 + ret = ioctl(lfd, GPIOHANDLE_GET_LINE_VALUES_IOCTL, &vals); 86 + if (ret == -1) 87 + return -errno; 88 + return vals.values[0]; 89 + } 90 + 91 + static void usage(char *prog) 92 + { 93 + printf("Usage: %s [-l] [-b <bias>] [-s <value>] [-u <uAPI>] <gpiochip> <offset>\n", prog); 94 + printf(" -b: set line bias to one of pull-down, pull-up, disabled\n"); 95 + printf(" (default is to leave bias unchanged):\n"); 96 + printf(" -l: set line active low (default is active high)\n"); 97 + printf(" -s: set line value (default is to get line value)\n"); 98 + printf(" -u: uAPI version to use (default is 2)\n"); 99 + exit(-1); 100 + } 101 + 102 + static int wait_signal(void) 103 + { 104 + int sig; 105 + sigset_t wset; 106 + 107 + sigemptyset(&wset); 108 + sigaddset(&wset, SIGHUP); 109 + sigaddset(&wset, SIGINT); 110 + sigaddset(&wset, SIGTERM); 111 + sigwait(&wset, &sig); 112 + 113 + return sig; 114 + } 115 + 116 + int main(int argc, char *argv[]) 117 + { 118 + char *chip; 119 + int opt, ret, cfd, lfd; 120 + unsigned int offset, val, abiv; 121 + uint32_t flags_v1; 122 + uint64_t flags_v2; 123 + 124 + abiv = 2; 125 + ret = 0; 126 + flags_v1 = GPIOHANDLE_REQUEST_INPUT; 127 + flags_v2 = GPIO_V2_LINE_FLAG_INPUT; 128 + 129 + while ((opt = getopt(argc, argv, "lb:s:u:")) != -1) { 130 + switch (opt) { 131 + case 'l': 132 + flags_v1 |= GPIOHANDLE_REQUEST_ACTIVE_LOW; 133 + flags_v2 |= GPIO_V2_LINE_FLAG_ACTIVE_LOW; 134 + break; 135 + case 'b': 136 + if (strcmp("pull-up", optarg) == 0) { 137 + flags_v1 |= GPIOHANDLE_REQUEST_BIAS_PULL_UP; 138 + flags_v2 |= GPIO_V2_LINE_FLAG_BIAS_PULL_UP; 139 + } else if (strcmp("pull-down", optarg) == 0) { 140 + flags_v1 |= GPIOHANDLE_REQUEST_BIAS_PULL_DOWN; 141 + flags_v2 |= GPIO_V2_LINE_FLAG_BIAS_PULL_DOWN; 142 + } else if (strcmp("disabled", optarg) == 0) { 143 + flags_v1 |= GPIOHANDLE_REQUEST_BIAS_DISABLE; 144 + flags_v2 |= GPIO_V2_LINE_FLAG_BIAS_DISABLED; 145 + } 146 + break; 147 + case 's': 148 + val = atoi(optarg); 149 + flags_v1 &= ~GPIOHANDLE_REQUEST_INPUT; 150 + flags_v1 |= GPIOHANDLE_REQUEST_OUTPUT; 151 + flags_v2 &= ~GPIO_V2_LINE_FLAG_INPUT; 152 + flags_v2 |= GPIO_V2_LINE_FLAG_OUTPUT; 153 + break; 154 + case 'u': 155 + abiv = atoi(optarg); 156 + break; 157 + default: 158 + usage(argv[0]); 159 + } 160 + } 161 + 162 + if (argc < optind + 2) 163 + usage(argv[0]); 164 + 165 + chip = argv[optind]; 166 + offset = atoi(argv[optind + 1]); 167 + 168 + cfd = open(chip, 0); 169 + if (cfd == -1) { 170 + fprintf(stderr, "Failed to open %s: %s\n", chip, strerror(errno)); 171 + return -errno; 172 + } 173 + 174 + if (abiv == 1) 175 + lfd = request_line_v1(cfd, offset, flags_v1, val); 176 + else 177 + lfd = request_line_v2(cfd, offset, flags_v2, val); 178 + 179 + close(cfd); 180 + 181 + if (lfd < 0) { 182 + fprintf(stderr, "Failed to request %s:%d: %s\n", chip, offset, strerror(-lfd)); 183 + return lfd; 184 + } 185 + 186 + if (flags_v2 & GPIO_V2_LINE_FLAG_OUTPUT) { 187 + wait_signal(); 188 + } else { 189 + if (abiv == 1) 190 + ret = get_value_v1(lfd); 191 + else 192 + ret = get_value_v2(lfd); 193 + } 194 + 195 + close(lfd); 196 + 197 + return ret; 198 + }
-323
tools/testing/selftests/gpio/gpio-mockup-chardev.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-only 2 - /* 3 - * GPIO chardev test helper 4 - * 5 - * Copyright (C) 2016 Bamvor Jian Zhang 6 - */ 7 - 8 - #define _GNU_SOURCE 9 - #include <unistd.h> 10 - #include <stdio.h> 11 - #include <stdlib.h> 12 - #include <errno.h> 13 - #include <string.h> 14 - #include <fcntl.h> 15 - #include <getopt.h> 16 - #include <sys/ioctl.h> 17 - #include <libmount.h> 18 - #include <err.h> 19 - #include <dirent.h> 20 - #include <linux/gpio.h> 21 - #include "../../../gpio/gpio-utils.h" 22 - 23 - #define CONSUMER "gpio-selftest" 24 - #define GC_NUM 10 25 - enum direction { 26 - OUT, 27 - IN 28 - }; 29 - 30 - static int get_debugfs(char **path) 31 - { 32 - struct libmnt_context *cxt; 33 - struct libmnt_table *tb; 34 - struct libmnt_iter *itr = NULL; 35 - struct libmnt_fs *fs; 36 - int found = 0, ret; 37 - 38 - cxt = mnt_new_context(); 39 - if (!cxt) 40 - err(EXIT_FAILURE, "libmount context allocation failed"); 41 - 42 - itr = mnt_new_iter(MNT_ITER_FORWARD); 43 - if (!itr) 44 - err(EXIT_FAILURE, "failed to initialize libmount iterator"); 45 - 46 - if (mnt_context_get_mtab(cxt, &tb)) 47 - err(EXIT_FAILURE, "failed to read mtab"); 48 - 49 - while (mnt_table_next_fs(tb, itr, &fs) == 0) { 50 - const char *type = mnt_fs_get_fstype(fs); 51 - 52 - if (!strcmp(type, "debugfs")) { 53 - found = 1; 54 - break; 55 - } 56 - } 57 - if (found) { 58 - ret = asprintf(path, "%s/gpio", mnt_fs_get_target(fs)); 59 - if (ret < 0) 60 - err(EXIT_FAILURE, "failed to format string"); 61 - } 62 - 63 - mnt_free_iter(itr); 64 - mnt_free_context(cxt); 65 - 66 - if (!found) 67 - return -1; 68 - 69 - return 0; 70 - } 71 - 72 - static int gpio_debugfs_get(const char *consumer, int *dir, int *value) 73 - { 74 - char *debugfs; 75 - FILE *f; 76 - char *line = NULL; 77 - size_t len = 0; 78 - char *cur; 79 - int found = 0; 80 - 81 - if (get_debugfs(&debugfs) != 0) 82 - err(EXIT_FAILURE, "debugfs is not mounted"); 83 - 84 - f = fopen(debugfs, "r"); 85 - if (!f) 86 - err(EXIT_FAILURE, "read from gpio debugfs failed"); 87 - 88 - /* 89 - * gpio-2 ( |gpio-selftest ) in lo 90 - */ 91 - while (getline(&line, &len, f) != -1) { 92 - cur = strstr(line, consumer); 93 - if (cur == NULL) 94 - continue; 95 - 96 - cur = strchr(line, ')'); 97 - if (!cur) 98 - continue; 99 - 100 - cur += 2; 101 - if (!strncmp(cur, "out", 3)) { 102 - *dir = OUT; 103 - cur += 4; 104 - } else if (!strncmp(cur, "in", 2)) { 105 - *dir = IN; 106 - cur += 4; 107 - } 108 - 109 - if (!strncmp(cur, "hi", 2)) 110 - *value = 1; 111 - else if (!strncmp(cur, "lo", 2)) 112 - *value = 0; 113 - 114 - found = 1; 115 - break; 116 - } 117 - free(debugfs); 118 - fclose(f); 119 - free(line); 120 - 121 - if (!found) 122 - return -1; 123 - 124 - return 0; 125 - } 126 - 127 - static struct gpiochip_info *list_gpiochip(const char *gpiochip_name, int *ret) 128 - { 129 - struct gpiochip_info *cinfo; 130 - struct gpiochip_info *current; 131 - const struct dirent *ent; 132 - DIR *dp; 133 - char *chrdev_name; 134 - int fd; 135 - int i = 0; 136 - 137 - cinfo = calloc(sizeof(struct gpiochip_info) * 4, GC_NUM + 1); 138 - if (!cinfo) 139 - err(EXIT_FAILURE, "gpiochip_info allocation failed"); 140 - 141 - current = cinfo; 142 - dp = opendir("/dev"); 143 - if (!dp) { 144 - *ret = -errno; 145 - goto error_out; 146 - } else { 147 - *ret = 0; 148 - } 149 - 150 - while (ent = readdir(dp), ent) { 151 - if (check_prefix(ent->d_name, "gpiochip")) { 152 - *ret = asprintf(&chrdev_name, "/dev/%s", ent->d_name); 153 - if (*ret < 0) 154 - goto error_out; 155 - 156 - fd = open(chrdev_name, 0); 157 - if (fd == -1) { 158 - *ret = -errno; 159 - fprintf(stderr, "Failed to open %s\n", 160 - chrdev_name); 161 - goto error_close_dir; 162 - } 163 - *ret = ioctl(fd, GPIO_GET_CHIPINFO_IOCTL, current); 164 - if (*ret == -1) { 165 - perror("Failed to issue CHIPINFO IOCTL\n"); 166 - goto error_close_dir; 167 - } 168 - close(fd); 169 - if (strcmp(current->label, gpiochip_name) == 0 170 - || check_prefix(current->label, gpiochip_name)) { 171 - *ret = 0; 172 - current++; 173 - i++; 174 - } 175 - } 176 - } 177 - 178 - if ((!*ret && i == 0) || *ret < 0) { 179 - free(cinfo); 180 - cinfo = NULL; 181 - } 182 - if (!*ret && i > 0) { 183 - cinfo = realloc(cinfo, sizeof(struct gpiochip_info) * 4 * i); 184 - *ret = i; 185 - } 186 - 187 - error_close_dir: 188 - closedir(dp); 189 - error_out: 190 - if (*ret < 0) 191 - err(EXIT_FAILURE, "list gpiochip failed: %s", strerror(*ret)); 192 - 193 - return cinfo; 194 - } 195 - 196 - int gpio_pin_test(struct gpiochip_info *cinfo, int line, int flag, int value) 197 - { 198 - struct gpiohandle_data data; 199 - unsigned int lines[] = {line}; 200 - int fd; 201 - int debugfs_dir = IN; 202 - int debugfs_value = 0; 203 - int ret; 204 - 205 - data.values[0] = value; 206 - ret = gpiotools_request_linehandle(cinfo->name, lines, 1, flag, &data, 207 - CONSUMER); 208 - if (ret < 0) 209 - goto fail_out; 210 - else 211 - fd = ret; 212 - 213 - ret = gpio_debugfs_get(CONSUMER, &debugfs_dir, &debugfs_value); 214 - if (ret) { 215 - ret = -EINVAL; 216 - goto fail_out; 217 - } 218 - if (flag & GPIOHANDLE_REQUEST_INPUT) { 219 - if (debugfs_dir != IN) { 220 - errno = -EINVAL; 221 - ret = -errno; 222 - } 223 - } else if (flag & GPIOHANDLE_REQUEST_OUTPUT) { 224 - if (flag & GPIOHANDLE_REQUEST_ACTIVE_LOW) 225 - debugfs_value = !debugfs_value; 226 - 227 - if (!(debugfs_dir == OUT && value == debugfs_value)) { 228 - errno = -EINVAL; 229 - ret = -errno; 230 - } 231 - } 232 - gpiotools_release_linehandle(fd); 233 - 234 - fail_out: 235 - if (ret) 236 - err(EXIT_FAILURE, "gpio<%s> line<%d> test flag<0x%x> value<%d>", 237 - cinfo->name, line, flag, value); 238 - 239 - return ret; 240 - } 241 - 242 - void gpio_pin_tests(struct gpiochip_info *cinfo, unsigned int line) 243 - { 244 - printf("line<%d>", line); 245 - gpio_pin_test(cinfo, line, GPIOHANDLE_REQUEST_OUTPUT, 0); 246 - printf("."); 247 - gpio_pin_test(cinfo, line, GPIOHANDLE_REQUEST_OUTPUT, 1); 248 - printf("."); 249 - gpio_pin_test(cinfo, line, 250 - GPIOHANDLE_REQUEST_OUTPUT | GPIOHANDLE_REQUEST_ACTIVE_LOW, 251 - 0); 252 - printf("."); 253 - gpio_pin_test(cinfo, line, 254 - GPIOHANDLE_REQUEST_OUTPUT | GPIOHANDLE_REQUEST_ACTIVE_LOW, 255 - 1); 256 - printf("."); 257 - gpio_pin_test(cinfo, line, GPIOHANDLE_REQUEST_INPUT, 0); 258 - printf("."); 259 - } 260 - 261 - /* 262 - * ./gpio-mockup-chardev gpio_chip_name_prefix is_valid_gpio_chip 263 - * Return 0 if successful or exit with EXIT_FAILURE if test failed. 264 - * gpio_chip_name_prefix: The prefix of gpiochip you want to test. E.g. 265 - * gpio-mockup 266 - * is_valid_gpio_chip: Whether the gpio_chip is valid. 1 means valid, 267 - * 0 means invalid which could not be found by 268 - * list_gpiochip. 269 - */ 270 - int main(int argc, char *argv[]) 271 - { 272 - char *prefix; 273 - int valid; 274 - struct gpiochip_info *cinfo; 275 - struct gpiochip_info *current; 276 - int i; 277 - int ret; 278 - 279 - if (argc < 3) { 280 - printf("Usage: %s prefix is_valid", argv[0]); 281 - exit(EXIT_FAILURE); 282 - } 283 - 284 - prefix = argv[1]; 285 - valid = strcmp(argv[2], "true") == 0 ? 1 : 0; 286 - 287 - printf("Test gpiochip %s: ", prefix); 288 - cinfo = list_gpiochip(prefix, &ret); 289 - if (!cinfo) { 290 - if (!valid && ret == 0) { 291 - printf("Invalid test successful\n"); 292 - ret = 0; 293 - goto out; 294 - } else { 295 - ret = -EINVAL; 296 - goto out; 297 - } 298 - } else if (cinfo && !valid) { 299 - ret = -EINVAL; 300 - goto out; 301 - } 302 - current = cinfo; 303 - for (i = 0; i < ret; i++) { 304 - gpio_pin_tests(current, 0); 305 - gpio_pin_tests(current, current->lines - 1); 306 - gpio_pin_tests(current, random() % current->lines); 307 - current++; 308 - } 309 - ret = 0; 310 - printf("successful\n"); 311 - 312 - out: 313 - if (ret) 314 - fprintf(stderr, "gpio<%s> test failed\n", prefix); 315 - 316 - if (cinfo) 317 - free(cinfo); 318 - 319 - if (ret) 320 - exit(EXIT_FAILURE); 321 - 322 - return ret; 323 - }
+60 -118
tools/testing/selftests/gpio/gpio-mockup-sysfs.sh
··· 1 1 2 2 # SPDX-License-Identifier: GPL-2.0 3 - is_consistent() 3 + 4 + # Overrides functions in gpio-mockup.sh to test using the GPIO SYSFS uAPI 5 + 6 + SYSFS=`grep -w sysfs /proc/mounts | cut -f2 -d' '` 7 + [ -d "$SYSFS" ] || skip "sysfs is not mounted" 8 + 9 + GPIO_SYSFS="${SYSFS}/class/gpio" 10 + [ -d "$GPIO_SYSFS" ] || skip "CONFIG_GPIO_SYSFS is not selected" 11 + 12 + PLATFORM_SYSFS=$SYSFS/devices/platform 13 + 14 + sysfs_nr= 15 + sysfs_ldir= 16 + 17 + # determine the sysfs GPIO number given the $chip and $offset 18 + # e.g. gpiochip1:32 19 + find_sysfs_nr() 4 20 { 5 - val= 6 - 7 - active_low_sysfs=`cat $GPIO_SYSFS/gpio$nr/active_low` 8 - val_sysfs=`cat $GPIO_SYSFS/gpio$nr/value` 9 - dir_sysfs=`cat $GPIO_SYSFS/gpio$nr/direction` 10 - 11 - gpio_this_debugfs=`cat $GPIO_DEBUGFS |grep "gpio-$nr" | sed "s/(.*)//g"` 12 - dir_debugfs=`echo $gpio_this_debugfs | awk '{print $2}'` 13 - val_debugfs=`echo $gpio_this_debugfs | awk '{print $3}'` 14 - if [ $val_debugfs = "lo" ]; then 15 - val=0 16 - elif [ $val_debugfs = "hi" ]; then 17 - val=1 18 - fi 19 - 20 - if [ $active_low_sysfs = "1" ]; then 21 - if [ $val = "0" ]; then 22 - val="1" 23 - else 24 - val="0" 25 - fi 26 - fi 27 - 28 - if [ $val_sysfs = $val ] && [ $dir_sysfs = $dir_debugfs ]; then 29 - echo -n "." 30 - else 31 - echo "test fail, exit" 32 - die 33 - fi 21 + # e.g. /sys/devices/platform/gpio-mockup.1/gpiochip1 22 + local platform=$(find $PLATFORM_SYSFS -mindepth 2 -maxdepth 2 -type d -name $chip) 23 + [ "$platform" ] || fail "can't find platform of $chip" 24 + # e.g. /sys/devices/platform/gpio-mockup.1/gpio/gpiochip508/base 25 + local base=$(find ${platform%/*}/gpio/ -mindepth 2 -maxdepth 2 -type f -name base) 26 + [ "$base" ] || fail "can't find base of $chip" 27 + sysfs_nr=$(($(< "$base") + $offset)) 28 + sysfs_ldir="$GPIO_SYSFS/gpio$sysfs_nr" 34 29 } 35 30 36 - test_pin_logic() 31 + acquire_line() 37 32 { 38 - nr=$1 39 - direction=$2 40 - active_low=$3 41 - value=$4 42 - 43 - echo $direction > $GPIO_SYSFS/gpio$nr/direction 44 - echo $active_low > $GPIO_SYSFS/gpio$nr/active_low 45 - if [ $direction = "out" ]; then 46 - echo $value > $GPIO_SYSFS/gpio$nr/value 47 - fi 48 - is_consistent $nr 33 + [ "$sysfs_nr" ] && return 34 + find_sysfs_nr 35 + echo "$sysfs_nr" > "$GPIO_SYSFS/export" 49 36 } 50 37 51 - test_one_pin() 38 + # The helpers being overridden... 39 + get_line() 52 40 { 53 - nr=$1 54 - 55 - echo -n "test pin<$nr>" 56 - 57 - echo $nr > $GPIO_SYSFS/export 2>/dev/null 58 - 59 - if [ X$? != X0 ]; then 60 - echo "test GPIO pin $nr failed" 61 - die 62 - fi 63 - 64 - #"Checking if the sysfs is consistent with debugfs: " 65 - is_consistent $nr 66 - 67 - #"Checking the logic of active_low: " 68 - test_pin_logic $nr out 1 1 69 - test_pin_logic $nr out 1 0 70 - test_pin_logic $nr out 0 1 71 - test_pin_logic $nr out 0 0 72 - 73 - #"Checking the logic of direction: " 74 - test_pin_logic $nr in 1 1 75 - test_pin_logic $nr out 1 0 76 - test_pin_logic $nr low 0 1 77 - test_pin_logic $nr high 0 0 78 - 79 - echo $nr > $GPIO_SYSFS/unexport 80 - 81 - echo "successful" 41 + [ -e "$sysfs_ldir/value" ] && echo $(< "$sysfs_ldir/value") 82 42 } 83 43 84 - test_one_pin_fail() 44 + set_line() 85 45 { 86 - nr=$1 46 + acquire_line 87 47 88 - echo $nr > $GPIO_SYSFS/export 2>/dev/null 89 - 90 - if [ X$? != X0 ]; then 91 - echo "test invalid pin $nr successful" 92 - else 93 - echo "test invalid pin $nr failed" 94 - echo $nr > $GPIO_SYSFS/unexport 2>/dev/null 95 - die 96 - fi 48 + for option in $*; do 49 + case $option in 50 + active-high) 51 + echo 0 > "$sysfs_ldir/active_low" 52 + ;; 53 + active-low) 54 + echo 1 > "$sysfs_ldir/active_low" 55 + ;; 56 + input) 57 + echo "in" > "$sysfs_ldir/direction" 58 + ;; 59 + 0) 60 + echo "out" > "$sysfs_ldir/direction" 61 + echo 0 > "$sysfs_ldir/value" 62 + ;; 63 + 1) 64 + echo "out" > "$sysfs_ldir/direction" 65 + echo 1 > "$sysfs_ldir/value" 66 + ;; 67 + esac 68 + done 97 69 } 98 70 99 - list_chip() 71 + release_line() 100 72 { 101 - echo `ls -d $GPIO_DRV_SYSFS/gpiochip* 2>/dev/null` 73 + [ "$sysfs_nr" ] || return 0 74 + echo "$sysfs_nr" > "$GPIO_SYSFS/unexport" 75 + sysfs_nr= 76 + sysfs_ldir= 102 77 } 103 - 104 - test_chip() 105 - { 106 - chip=$1 107 - name=`basename $chip` 108 - base=`cat $chip/base` 109 - ngpio=`cat $chip/ngpio` 110 - printf "%-10s %-5s %-5s\n" $name $base $ngpio 111 - if [ $ngpio = "0" ]; then 112 - echo "number of gpio is zero is not allowed". 113 - fi 114 - test_one_pin $base 115 - test_one_pin $(($base + $ngpio - 1)) 116 - test_one_pin $((( RANDOM % $ngpio ) + $base )) 117 - } 118 - 119 - test_chips_sysfs() 120 - { 121 - gpiochip=`list_chip $module` 122 - if [ X"$gpiochip" = X ]; then 123 - if [ X"$valid" = Xfalse ]; then 124 - echo "successful" 125 - else 126 - echo "fail" 127 - die 128 - fi 129 - else 130 - for chip in $gpiochip; do 131 - test_chip $chip 132 - done 133 - fi 134 - } 135 -
+348 -151
tools/testing/selftests/gpio/gpio-mockup.sh
··· 1 - #!/bin/bash 1 + #!/bin/bash -efu 2 2 # SPDX-License-Identifier: GPL-2.0 3 3 4 4 #exit status 5 - #1: Internal error 6 - #2: sysfs/debugfs not mount 7 - #3: insert module fail when gpio-mockup is a module. 8 - #4: Skip test including run as non-root user. 9 - #5: other reason. 5 + #0: success 6 + #1: fail 7 + #4: skip test - including run as non-root user 10 8 11 - SYSFS= 12 - GPIO_SYSFS= 13 - GPIO_DRV_SYSFS= 9 + BASE=${0%/*} 14 10 DEBUGFS= 15 11 GPIO_DEBUGFS= 16 - dev_type= 17 - module= 12 + dev_type="cdev" 13 + module="gpio-mockup" 14 + verbose= 15 + full_test= 16 + random= 17 + uapi_opt= 18 + active_opt= 19 + bias_opt= 20 + line_set_pid= 18 21 19 - # Kselftest framework requirement - SKIP code is 4. 22 + # Kselftest return codes 23 + ksft_fail=1 20 24 ksft_skip=4 21 25 22 26 usage() 23 27 { 24 28 echo "Usage:" 25 - echo "$0 [-f] [-m name] [-t type]" 26 - echo "-f: full test. It maybe conflict with existence gpio device." 27 - echo "-m: module name, default name is gpio-mockup. It could also test" 28 - echo " other gpio device." 29 - echo "-t: interface type: chardev(char device) and sysfs(being" 30 - echo " deprecated). The first one is default" 31 - echo "" 32 - echo "$0 -h" 33 - echo "This usage" 29 + echo "$0 [-frv] [-t type]" 30 + echo "-f: full test (minimal set run by default)" 31 + echo "-r: test random lines as well as fence posts" 32 + echo "-t: interface type:" 33 + echo " cdev (character device ABI) - default" 34 + echo " cdev_v1 (deprecated character device ABI)" 35 + echo " sysfs (deprecated SYSFS ABI)" 36 + echo "-v: verbose progress reporting" 37 + exit $ksft_fail 38 + } 39 + 40 + skip() 41 + { 42 + echo "$*" >&2 43 + echo "GPIO $module test SKIP" 44 + exit $ksft_skip 34 45 } 35 46 36 47 prerequisite() 37 48 { 38 - msg="skip all tests:" 39 - if [ $UID != 0 ]; then 40 - echo $msg must be run as root >&2 41 - exit $ksft_skip 42 - fi 43 - SYSFS=`mount -t sysfs | head -1 | awk '{ print $3 }'` 44 - if [ ! -d "$SYSFS" ]; then 45 - echo $msg sysfs is not mounted >&2 46 - exit 2 47 - fi 48 - GPIO_SYSFS=`echo $SYSFS/class/gpio` 49 - GPIO_DRV_SYSFS=`echo $SYSFS/devices/platform/$module/gpio` 50 - DEBUGFS=`mount -t debugfs | head -1 | awk '{ print $3 }'` 51 - if [ ! -d "$DEBUGFS" ]; then 52 - echo $msg debugfs is not mounted >&2 53 - exit 2 54 - fi 55 - GPIO_DEBUGFS=`echo $DEBUGFS/gpio` 56 - source gpio-mockup-sysfs.sh 57 - } 49 + [ $(id -u) -eq 0 ] || skip "must be run as root" 58 50 59 - try_insert_module() 60 - { 61 - if [ -d "$GPIO_DRV_SYSFS" ]; then 62 - echo "$GPIO_DRV_SYSFS exist. Skip insert module" 63 - else 64 - modprobe -q $module $1 65 - if [ X$? != X0 ]; then 66 - echo $msg insmod $module failed >&2 67 - exit 3 68 - fi 69 - fi 51 + DEBUGFS=$(grep -w debugfs /proc/mounts | cut -f2 -d' ') 52 + [ -d "$DEBUGFS" ] || skip "debugfs is not mounted" 53 + 54 + GPIO_DEBUGFS=$DEBUGFS/$module 70 55 } 71 56 72 57 remove_module() ··· 59 74 modprobe -r -q $module 60 75 } 61 76 62 - die() 77 + cleanup() 63 78 { 79 + set +e 80 + release_line 64 81 remove_module 65 - exit 5 82 + jobs -p | xargs -r kill > /dev/null 2>&1 66 83 } 67 84 68 - test_chips() 85 + fail() 69 86 { 70 - if [ X$dev_type = Xsysfs ]; then 71 - echo "WARNING: sysfs ABI of gpio is going to deprecated." 72 - test_chips_sysfs $* 73 - else 74 - $BASE/gpio-mockup-chardev $* 87 + echo "test failed: $*" >&2 88 + echo "GPIO $module test FAIL" 89 + exit $ksft_fail 90 + } 91 + 92 + try_insert_module() 93 + { 94 + modprobe -q $module "$1" || fail "insert $module failed with error $?" 95 + } 96 + 97 + log() 98 + { 99 + [ -z "$verbose" ] || echo "$*" 100 + } 101 + 102 + # The following line helpers, release_Line, get_line and set_line, all 103 + # make use of the global $chip and $offset variables. 104 + # 105 + # This implementation drives the GPIO character device (cdev) uAPI. 106 + # Other implementations may override these to test different uAPIs. 107 + 108 + # Release any resources related to the line 109 + release_line() 110 + { 111 + [ "$line_set_pid" ] && kill $line_set_pid && wait $line_set_pid || true 112 + line_set_pid= 113 + } 114 + 115 + # Read the current value of the line 116 + get_line() 117 + { 118 + release_line 119 + 120 + local cdev_opts=${uapi_opt}${active_opt} 121 + $BASE/gpio-mockup-cdev $cdev_opts /dev/$chip $offset 122 + echo $? 123 + } 124 + 125 + # Set the state of the line 126 + # 127 + # Changes to line configuration are provided as parameters. 128 + # The line is assumed to be an output if the line value 0 or 1 is 129 + # specified, else an input. 130 + set_line() 131 + { 132 + local val= 133 + 134 + release_line 135 + 136 + # parse config options... 137 + for option in $*; do 138 + case $option in 139 + active-low) 140 + active_opt="-l " 141 + ;; 142 + active-high) 143 + active_opt= 144 + ;; 145 + bias-none) 146 + bias_opt= 147 + ;; 148 + pull-down) 149 + bias_opt="-bpull-down " 150 + ;; 151 + pull-up) 152 + bias_opt="-bpull-up " 153 + ;; 154 + 0) 155 + val=0 156 + ;; 157 + 1) 158 + val=1 159 + ;; 160 + esac 161 + done 162 + 163 + local cdev_opts=${uapi_opt}${active_opt} 164 + if [ "$val" ]; then 165 + $BASE/gpio-mockup-cdev $cdev_opts -s$val /dev/$chip $offset & 166 + # failure to set is detected by reading mockup and toggling values 167 + line_set_pid=$! 168 + # allow for gpio-mockup-cdev to launch and request line 169 + # (there is limited value in checking if line has been requested) 170 + sleep 0.01 171 + elif [ "$bias_opt" ]; then 172 + cdev_opts=${cdev_opts}${bias_opt} 173 + $BASE/gpio-mockup-cdev $cdev_opts /dev/$chip $offset || true 75 174 fi 76 175 } 77 176 78 - gpio_test() 177 + assert_line() 79 178 { 80 - param=$1 81 - valid=$2 82 - 83 - if [ X"$param" = X ]; then 84 - die 85 - fi 86 - try_insert_module "gpio_mockup_ranges=$param" 87 - echo -n "GPIO $module test with ranges: <" 88 - echo "$param>: " 89 - printf "%-10s %s\n" $param 90 - test_chips $module $valid 91 - remove_module 179 + local val 180 + # don't need any retry here as set_mock allows for propagation 181 + val=$(get_line) 182 + [ "$val" = "$1" ] || fail "line value is ${val:-empty} when $1 was expected" 92 183 } 93 184 94 - BASE=`dirname $0` 185 + # The following mockup helpers all make use of the $mock_line 186 + assert_mock() 187 + { 188 + local backoff_wait=10 189 + local retry=0 190 + local val 191 + # retry allows for set propagation from uAPI to mockup 192 + while true; do 193 + val=$(< $mock_line) 194 + [ "$val" = "$1" ] && break 195 + retry=$((retry + 1)) 196 + [ $retry -lt 5 ] || fail "mockup $mock_line value ${val:-empty} when $1 expected" 197 + sleep $(printf "%0.2f" $((backoff_wait))e-3) 198 + backoff_wait=$((backoff_wait * 2)) 199 + done 200 + } 95 201 96 - dev_type= 97 - TEMP=`getopt -o fhm:t: -n '$0' -- "$@"` 202 + set_mock() 203 + { 204 + echo "$1" > $mock_line 205 + # allow for set propagation - so we won't be in a race with set_line 206 + assert_mock "$1" 207 + } 98 208 99 - if [ "$?" != "0" ]; then 100 - echo "Parameter process failed, Terminating..." >&2 101 - exit 1 102 - fi 209 + # test the functionality of a line 210 + # 211 + # The line is set from the mockup side and is read from the userspace side 212 + # (input), and is set from the userspace side and is read from the mockup side 213 + # (output). 214 + # 215 + # Setting the mockup pull using the userspace interface bias settings is 216 + # tested where supported by the userspace interface (cdev). 217 + test_line() 218 + { 219 + chip=$1 220 + offset=$2 221 + log "test_line $chip $offset" 222 + mock_line=$GPIO_DEBUGFS/$chip/$offset 223 + [ -e "$mock_line" ] || fail "missing line $chip:$offset" 103 224 104 - # Note the quotes around `$TEMP': they are essential! 105 - eval set -- "$TEMP" 225 + # test input active-high 226 + set_mock 1 227 + set_line input active-high 228 + assert_line 1 229 + set_mock 0 230 + assert_line 0 231 + set_mock 1 232 + assert_line 1 106 233 107 - while true; do 108 - case $1 in 109 - -f) 234 + if [ "$full_test" ]; then 235 + if [ "$dev_type" != "sysfs" ]; then 236 + # test pulls 237 + set_mock 0 238 + set_line input pull-up 239 + assert_line 1 240 + set_mock 0 241 + assert_line 0 242 + 243 + set_mock 1 244 + set_line input pull-down 245 + assert_line 0 246 + set_mock 1 247 + assert_line 1 248 + 249 + set_line bias-none 250 + fi 251 + 252 + # test input active-low 253 + set_mock 0 254 + set_line active-low 255 + assert_line 1 256 + set_mock 1 257 + assert_line 0 258 + set_mock 0 259 + assert_line 1 260 + 261 + # test output active-high 262 + set_mock 1 263 + set_line active-high 0 264 + assert_mock 0 265 + set_line 1 266 + assert_mock 1 267 + set_line 0 268 + assert_mock 0 269 + fi 270 + 271 + # test output active-low 272 + set_mock 0 273 + set_line active-low 0 274 + assert_mock 1 275 + set_line 1 276 + assert_mock 0 277 + set_line 0 278 + assert_mock 1 279 + 280 + release_line 281 + } 282 + 283 + test_no_line() 284 + { 285 + log test_no_line "$*" 286 + [ ! -e "$GPIO_DEBUGFS/$1/$2" ] || fail "unexpected line $1:$2" 287 + } 288 + 289 + # Load the module and check that the expected number of gpiochips, with the 290 + # expected number of lines, are created and are functional. 291 + # 292 + # $1 is the gpio_mockup_ranges parameter for the module 293 + # The remaining parameters are the number of lines, n, expected for each of 294 + # the gpiochips expected to be created. 295 + # 296 + # For each gpiochip the fence post lines, 0 and n-1, are tested, and the 297 + # line on the far side of the fence post, n, is tested to not exist. 298 + # 299 + # If the $random flag is set then a random line in the middle of the 300 + # gpiochip is tested as well. 301 + insmod_test() 302 + { 303 + local ranges= 304 + local gc= 305 + local width= 306 + 307 + [ "${1:-}" ] || fail "missing ranges" 308 + ranges=$1 ; shift 309 + try_insert_module "gpio_mockup_ranges=$ranges" 310 + log "GPIO $module test with ranges: <$ranges>:" 311 + # e.g. /sys/kernel/debug/gpio-mockup/gpiochip1 312 + gpiochip=$(find "$DEBUGFS/$module/" -name gpiochip* -type d | sort) 313 + for chip in $gpiochip; do 314 + gc=${chip##*/} 315 + [ "${1:-}" ] || fail "unexpected chip - $gc" 316 + width=$1 ; shift 317 + test_line $gc 0 318 + if [ "$random" -a $width -gt 2 ]; then 319 + test_line $gc $((RANDOM % ($width - 2) + 1)) 320 + fi 321 + test_line $gc $(($width - 1)) 322 + test_no_line $gc $width 323 + done 324 + [ "${1:-}" ] && fail "missing expected chip of width $1" 325 + remove_module || fail "failed to remove module with error $?" 326 + } 327 + 328 + while getopts ":frvt:" opt; do 329 + case $opt in 330 + f) 110 331 full_test=true 111 - shift 112 332 ;; 113 - -h) 114 - usage 115 - exit 333 + r) 334 + random=true 116 335 ;; 117 - -m) 118 - module=$2 119 - shift 2 336 + t) 337 + dev_type=$OPTARG 120 338 ;; 121 - -t) 122 - dev_type=$2 123 - shift 2 124 - ;; 125 - --) 126 - shift 127 - break 339 + v) 340 + verbose=true 128 341 ;; 129 342 *) 130 - echo "Internal error!" 131 - exit 1 343 + usage 132 344 ;; 133 345 esac 134 346 done 347 + shift $((OPTIND - 1)) 135 348 136 - if [ X"$module" = X ]; then 137 - module="gpio-mockup" 138 - fi 139 - 140 - if [ X$dev_type != Xsysfs ]; then 141 - dev_type="chardev" 142 - fi 349 + [ "${1:-}" ] && fail "unknown argument '$1'" 143 350 144 351 prerequisite 145 352 146 - echo "1. Test dynamic allocation of gpio successful means insert gpiochip and" 147 - echo " manipulate gpio pin successful" 148 - gpio_test "-1,32" true 149 - gpio_test "-1,32,-1,32" true 150 - gpio_test "-1,32,-1,32,-1,32" true 151 - if [ X$full_test = Xtrue ]; then 152 - gpio_test "-1,32,32,64" true 153 - gpio_test "-1,32,40,64,-1,5" true 154 - gpio_test "-1,32,32,64,-1,32" true 155 - gpio_test "0,32,32,64,-1,32,-1,32" true 156 - gpio_test "-1,32,-1,32,0,32,32,64" true 157 - echo "2. Do basic test: successful means insert gpiochip and" 158 - echo " manipulate gpio pin successful" 159 - gpio_test "0,32" true 160 - gpio_test "0,32,32,64" true 161 - gpio_test "0,32,40,64,64,96" true 353 + trap 'exit $ksft_fail' SIGTERM SIGINT 354 + trap cleanup EXIT 355 + 356 + case "$dev_type" in 357 + sysfs) 358 + source $BASE/gpio-mockup-sysfs.sh 359 + echo "WARNING: gpio sysfs ABI is deprecated." 360 + ;; 361 + cdev_v1) 362 + echo "WARNING: gpio cdev ABI v1 is deprecated." 363 + uapi_opt="-u1 " 364 + ;; 365 + cdev) 366 + ;; 367 + *) 368 + fail "unknown interface type: $dev_type" 369 + ;; 370 + esac 371 + 372 + remove_module || fail "can't remove existing $module module" 373 + 374 + # manual gpio allocation tests fail if a physical chip already exists 375 + [ "$full_test" -a -e "/dev/gpiochip0" ] && skip "full tests conflict with gpiochip0" 376 + 377 + echo "1. Module load tests" 378 + echo "1.1. dynamic allocation of gpio" 379 + insmod_test "-1,32" 32 380 + insmod_test "-1,23,-1,32" 23 32 381 + insmod_test "-1,23,-1,26,-1,32" 23 26 32 382 + if [ "$full_test" ]; then 383 + echo "1.2. manual allocation of gpio" 384 + insmod_test "0,32" 32 385 + insmod_test "0,32,32,60" 32 28 386 + insmod_test "0,32,40,64,64,96" 32 24 32 387 + echo "1.3. dynamic and manual allocation of gpio" 388 + insmod_test "-1,32,32,62" 32 30 389 + insmod_test "-1,22,-1,23,0,24,32,64" 22 23 24 32 390 + insmod_test "-1,32,32,60,-1,29" 32 28 29 391 + insmod_test "-1,32,40,64,-1,5" 32 24 5 392 + insmod_test "0,32,32,44,-1,22,-1,31" 32 12 22 31 162 393 fi 163 - echo "3. Error test: successful means insert gpiochip failed" 164 - echo "3.1 Test number of gpio overflow" 165 - #Currently: The max number of gpio(1024) is defined in arm architecture. 166 - gpio_test "-1,32,-1,1024" false 167 - if [ X$full_test = Xtrue ]; then 168 - echo "3.2 Test zero line of gpio" 169 - gpio_test "0,0" false 170 - echo "3.3 Test range overlap" 171 - echo "3.3.1 Test corner case" 172 - gpio_test "0,32,0,1" false 173 - gpio_test "0,32,32,64,32,40" false 174 - gpio_test "0,32,35,64,35,45" false 175 - gpio_test "0,32,31,32" false 176 - gpio_test "0,32,32,64,36,37" false 177 - gpio_test "0,32,35,64,34,36" false 178 - echo "3.3.2 Test inserting invalid second gpiochip" 179 - gpio_test "0,32,30,35" false 180 - gpio_test "0,32,1,5" false 181 - gpio_test "10,32,9,14" false 182 - gpio_test "10,32,30,35" false 183 - echo "3.3.3 Test others" 184 - gpio_test "0,32,40,56,39,45" false 185 - gpio_test "0,32,40,56,30,33" false 186 - gpio_test "0,32,40,56,30,41" false 187 - gpio_test "0,32,40,56,20,21" false 394 + echo "2. Module load error tests" 395 + echo "2.1 gpio overflow" 396 + # Currently: The max number of gpio(1024) is defined in arm architecture. 397 + insmod_test "-1,1024" 398 + if [ "$full_test" ]; then 399 + echo "2.2 no lines defined" 400 + insmod_test "0,0" 401 + echo "2.3 ignore range overlap" 402 + insmod_test "0,32,0,1" 32 403 + insmod_test "0,32,1,5" 32 404 + insmod_test "0,32,30,35" 32 405 + insmod_test "0,32,31,32" 32 406 + insmod_test "10,32,30,35" 22 407 + insmod_test "10,32,9,14" 22 408 + insmod_test "0,32,20,21,40,56" 32 16 409 + insmod_test "0,32,32,64,32,40" 32 32 410 + insmod_test "0,32,32,64,36,37" 32 32 411 + insmod_test "0,32,35,64,34,36" 32 29 412 + insmod_test "0,30,35,64,35,45" 30 29 413 + insmod_test "0,32,40,56,30,33" 32 16 414 + insmod_test "0,32,40,56,30,41" 32 16 415 + insmod_test "0,32,40,56,39,45" 32 16 188 416 fi 189 417 190 - echo GPIO test PASS 191 - 418 + echo "GPIO $module test PASS"
+1 -3
tools/testing/selftests/kselftest_deps.sh
··· 129 129 grep -v "VAR_LDLIBS" | awk -F: '{print $1}') 130 130 131 131 # Level 3 132 - # gpio, memfd and others use pkg-config to find mount and fuse libs 132 + # memfd and others use pkg-config to find mount and fuse libs 133 133 # respectively and save it in VAR_LDLIBS. If pkg-config doesn't find 134 134 # any, VAR_LDLIBS set to default. 135 135 # Use the default value and filter out pkg-config for dependency check. 136 136 # e.g: 137 - # gpio/Makefile 138 - # VAR_LDLIBS := $(shell pkg-config --libs mount) 2>/dev/null) 139 137 # memfd/Makefile 140 138 # VAR_LDLIBS := $(shell pkg-config fuse --libs 2>/dev/null) 141 139