diff options
57 files changed, 1741 insertions, 678 deletions
diff --git a/Documentation/devicetree/bindings/arm/atmel-sysregs.txt b/Documentation/devicetree/bindings/arm/atmel-sysregs.txt index 4b96608ad692..14f319f694b7 100644 --- a/Documentation/devicetree/bindings/arm/atmel-sysregs.txt +++ b/Documentation/devicetree/bindings/arm/atmel-sysregs.txt | |||
| @@ -158,14 +158,24 @@ Security Module (SECUMOD) | |||
| 158 | 158 | ||
| 159 | The Security Module macrocell provides all necessary secure functions to avoid | 159 | The Security Module macrocell provides all necessary secure functions to avoid |
| 160 | voltage, temperature, frequency and mechanical attacks on the chip. It also | 160 | voltage, temperature, frequency and mechanical attacks on the chip. It also |
| 161 | embeds secure memories that can be scrambled | 161 | embeds secure memories that can be scrambled. |
| 162 | |||
| 163 | The Security Module also offers the PIOBU pins which can be used as GPIO pins. | ||
| 164 | Note that they maintain their voltage during Backup/Self-refresh. | ||
| 162 | 165 | ||
| 163 | required properties: | 166 | required properties: |
| 164 | - compatible: Should be "atmel,<chip>-secumod", "syscon". | 167 | - compatible: Should be "atmel,<chip>-secumod", "syscon". |
| 165 | <chip> can be "sama5d2". | 168 | <chip> can be "sama5d2". |
| 166 | - reg: Should contain registers location and length | 169 | - reg: Should contain registers location and length |
| 170 | - gpio-controller: Marks the port as GPIO controller. | ||
| 171 | - #gpio-cells: There are 2. The pin number is the | ||
| 172 | first, the second represents additional | ||
| 173 | parameters such as GPIO_ACTIVE_HIGH/LOW. | ||
| 174 | |||
| 167 | 175 | ||
| 168 | secumod@fc040000 { | 176 | secumod@fc040000 { |
| 169 | compatible = "atmel,sama5d2-secumod", "syscon"; | 177 | compatible = "atmel,sama5d2-secumod", "syscon"; |
| 170 | reg = <0xfc040000 0x100>; | 178 | reg = <0xfc040000 0x100>; |
| 179 | gpio-controller; | ||
| 180 | #gpio-cells = <2>; | ||
| 171 | }; | 181 | }; |
diff --git a/Documentation/devicetree/bindings/gpio/cdns,gpio.txt b/Documentation/devicetree/bindings/gpio/cdns,gpio.txt new file mode 100644 index 000000000000..706ef00f5c64 --- /dev/null +++ b/Documentation/devicetree/bindings/gpio/cdns,gpio.txt | |||
| @@ -0,0 +1,43 @@ | |||
| 1 | Cadence GPIO controller bindings | ||
| 2 | |||
| 3 | Required properties: | ||
| 4 | - compatible: should be "cdns,gpio-r1p02". | ||
| 5 | - reg: the register base address and size. | ||
| 6 | - #gpio-cells: should be 2. | ||
| 7 | * first cell is the GPIO number. | ||
| 8 | * second cell specifies the GPIO flags, as defined in | ||
| 9 | <dt-bindings/gpio/gpio.h>. Only the GPIO_ACTIVE_HIGH | ||
| 10 | and GPIO_ACTIVE_LOW flags are supported. | ||
| 11 | - gpio-controller: marks the device as a GPIO controller. | ||
| 12 | - clocks: should contain one entry referencing the peripheral clock driving | ||
| 13 | the GPIO controller. | ||
| 14 | |||
| 15 | Optional properties: | ||
| 16 | - ngpios: integer number of gpio lines supported by this controller, up to 32. | ||
| 17 | - interrupts: interrupt specifier for the controllers interrupt. | ||
| 18 | - interrupt-controller: marks the device as an interrupt controller. When | ||
| 19 | defined, interrupts, interrupt-parent and #interrupt-cells | ||
| 20 | are required. | ||
| 21 | - interrupt-cells: should be 2. | ||
| 22 | * first cell is the GPIO number you want to use as an IRQ source. | ||
| 23 | * second cell specifies the IRQ type, as defined in | ||
| 24 | <dt-bindings/interrupt-controller/irq.h>. | ||
| 25 | Currently only level sensitive IRQs are supported. | ||
| 26 | |||
| 27 | |||
| 28 | Example: | ||
| 29 | gpio0: gpio-controller@fd060000 { | ||
| 30 | compatible = "cdns,gpio-r1p02"; | ||
| 31 | reg =<0xfd060000 0x1000>; | ||
| 32 | |||
| 33 | clocks = <&gpio_clk>; | ||
| 34 | |||
| 35 | interrupt-parent = <&gic>; | ||
| 36 | interrupts = <0 5 IRQ_TYPE_LEVEL_HIGH>; | ||
| 37 | |||
| 38 | gpio-controller; | ||
| 39 | #gpio-cells = <2>; | ||
| 40 | |||
| 41 | interrupt-controller; | ||
| 42 | #interrupt-cells = <2>; | ||
| 43 | }; | ||
diff --git a/Documentation/devicetree/bindings/gpio/gpio-vf610.txt b/Documentation/devicetree/bindings/gpio/gpio-vf610.txt index 0ccbae44019c..ae254aadee35 100644 --- a/Documentation/devicetree/bindings/gpio/gpio-vf610.txt +++ b/Documentation/devicetree/bindings/gpio/gpio-vf610.txt | |||
| @@ -24,6 +24,12 @@ Required properties for GPIO node: | |||
| 24 | 4 = active high level-sensitive. | 24 | 4 = active high level-sensitive. |
| 25 | 8 = active low level-sensitive. | 25 | 8 = active low level-sensitive. |
| 26 | 26 | ||
| 27 | Optional properties: | ||
| 28 | -clocks: Must contain an entry for each entry in clock-names. | ||
| 29 | See common clock-bindings.txt for details. | ||
| 30 | -clock-names: A list of clock names. For imx7ulp, it must contain | ||
| 31 | "gpio", "port". | ||
| 32 | |||
| 27 | Note: Each GPIO port should have an alias correctly numbered in "aliases" | 33 | Note: Each GPIO port should have an alias correctly numbered in "aliases" |
| 28 | node. | 34 | node. |
| 29 | 35 | ||
diff --git a/Documentation/devicetree/bindings/gpio/nxp,lpc1850-gpio.txt b/Documentation/devicetree/bindings/gpio/nxp,lpc1850-gpio.txt index eb7cdd69e10b..627efc78ecf2 100644 --- a/Documentation/devicetree/bindings/gpio/nxp,lpc1850-gpio.txt +++ b/Documentation/devicetree/bindings/gpio/nxp,lpc1850-gpio.txt | |||
| @@ -3,12 +3,24 @@ NXP LPC18xx/43xx GPIO controller Device Tree Bindings | |||
| 3 | 3 | ||
| 4 | Required properties: | 4 | Required properties: |
| 5 | - compatible : Should be "nxp,lpc1850-gpio" | 5 | - compatible : Should be "nxp,lpc1850-gpio" |
| 6 | - reg : Address and length of the register set for the device | 6 | - reg : List of addresses and lengths of the GPIO controller |
| 7 | - clocks : Clock specifier (see clock bindings for details) | 7 | register sets |
| 8 | - gpio-controller : Marks the device node as a GPIO controller. | 8 | - reg-names : Should be "gpio", "gpio-pin-ic", "gpio-group0-ic" and |
| 9 | - #gpio-cells : Should be two | 9 | "gpio-gpoup1-ic" |
| 10 | - First cell is the GPIO line number | 10 | - clocks : Phandle and clock specifier pair for GPIO controller |
| 11 | - Second cell is used to specify polarity | 11 | - resets : Phandle and reset specifier pair for GPIO controller |
| 12 | - gpio-controller : Marks the device node as a GPIO controller | ||
| 13 | - #gpio-cells : Should be two: | ||
| 14 | - The first cell is the GPIO line number | ||
| 15 | - The second cell is used to specify polarity | ||
| 16 | - interrupt-controller : Marks the device node as an interrupt controller | ||
| 17 | - #interrupt-cells : Should be two: | ||
| 18 | - The first cell is an interrupt number within | ||
| 19 | 0..9 range, for GPIO pin interrupts it is equal | ||
| 20 | to 'nxp,gpio-pin-interrupt' property value of | ||
| 21 | GPIO pin configuration, 8 is for GPIO GROUP0 | ||
| 22 | interrupt, 9 is for GPIO GROUP1 interrupt | ||
| 23 | - The second cell is used to specify interrupt type | ||
| 12 | 24 | ||
| 13 | Optional properties: | 25 | Optional properties: |
| 14 | - gpio-ranges : Mapping between GPIO and pinctrl | 26 | - gpio-ranges : Mapping between GPIO and pinctrl |
| @@ -19,21 +31,29 @@ Example: | |||
| 19 | 31 | ||
| 20 | gpio: gpio@400f4000 { | 32 | gpio: gpio@400f4000 { |
| 21 | compatible = "nxp,lpc1850-gpio"; | 33 | compatible = "nxp,lpc1850-gpio"; |
| 22 | reg = <0x400f4000 0x4000>; | 34 | reg = <0x400f4000 0x4000>, <0x40087000 0x1000>, |
| 35 | <0x40088000 0x1000>, <0x40089000 0x1000>; | ||
| 36 | reg-names = "gpio", "gpio-pin-ic", | ||
| 37 | "gpio-group0-ic", "gpio-gpoup1-ic"; | ||
| 23 | clocks = <&ccu1 CLK_CPU_GPIO>; | 38 | clocks = <&ccu1 CLK_CPU_GPIO>; |
| 39 | resets = <&rgu 28>; | ||
| 24 | gpio-controller; | 40 | gpio-controller; |
| 25 | #gpio-cells = <2>; | 41 | #gpio-cells = <2>; |
| 42 | interrupt-controller; | ||
| 43 | #interrupt-cells = <2>; | ||
| 26 | gpio-ranges = <&pinctrl LPC_GPIO(0,0) LPC_PIN(0,0) 2>, | 44 | gpio-ranges = <&pinctrl LPC_GPIO(0,0) LPC_PIN(0,0) 2>, |
| 27 | ... | 45 | ... |
| 28 | <&pinctrl LPC_GPIO(7,19) LPC_PIN(f,5) 7>; | 46 | <&pinctrl LPC_GPIO(7,19) LPC_PIN(f,5) 7>; |
| 29 | }; | 47 | }; |
| 30 | 48 | ||
| 31 | gpio_joystick { | 49 | gpio_joystick { |
| 32 | compatible = "gpio-keys-polled"; | 50 | compatible = "gpio-keys"; |
| 33 | ... | 51 | ... |
| 34 | 52 | ||
| 35 | button@0 { | 53 | button0 { |
| 36 | ... | 54 | ... |
| 55 | interrupt-parent = <&gpio>; | ||
| 56 | interrupts = <1 IRQ_TYPE_EDGE_BOTH>; | ||
| 37 | gpios = <&gpio LPC_GPIO(4,8) GPIO_ACTIVE_LOW>; | 57 | gpios = <&gpio LPC_GPIO(4,8) GPIO_ACTIVE_LOW>; |
| 38 | }; | 58 | }; |
| 39 | }; | 59 | }; |
diff --git a/Documentation/devicetree/bindings/gpio/renesas,gpio-rcar.txt b/Documentation/devicetree/bindings/gpio/renesas,gpio-rcar.txt index 2889bbcd7416..f3f2c468c1b6 100644 --- a/Documentation/devicetree/bindings/gpio/renesas,gpio-rcar.txt +++ b/Documentation/devicetree/bindings/gpio/renesas,gpio-rcar.txt | |||
| @@ -8,6 +8,7 @@ Required Properties: | |||
| 8 | - "renesas,gpio-r8a7745": for R8A7745 (RZ/G1E) compatible GPIO controller. | 8 | - "renesas,gpio-r8a7745": for R8A7745 (RZ/G1E) compatible GPIO controller. |
| 9 | - "renesas,gpio-r8a77470": for R8A77470 (RZ/G1C) compatible GPIO controller. | 9 | - "renesas,gpio-r8a77470": for R8A77470 (RZ/G1C) compatible GPIO controller. |
| 10 | - "renesas,gpio-r8a774a1": for R8A774A1 (RZ/G2M) compatible GPIO controller. | 10 | - "renesas,gpio-r8a774a1": for R8A774A1 (RZ/G2M) compatible GPIO controller. |
| 11 | - "renesas,gpio-r8a774c0": for R8A774C0 (RZ/G2E) compatible GPIO controller. | ||
| 11 | - "renesas,gpio-r8a7778": for R8A7778 (R-Car M1) compatible GPIO controller. | 12 | - "renesas,gpio-r8a7778": for R8A7778 (R-Car M1) compatible GPIO controller. |
| 12 | - "renesas,gpio-r8a7779": for R8A7779 (R-Car H1) compatible GPIO controller. | 13 | - "renesas,gpio-r8a7779": for R8A7779 (R-Car H1) compatible GPIO controller. |
| 13 | - "renesas,gpio-r8a7790": for R8A7790 (R-Car H2) compatible GPIO controller. | 14 | - "renesas,gpio-r8a7790": for R8A7790 (R-Car H2) compatible GPIO controller. |
diff --git a/Documentation/devicetree/bindings/gpio/snps-dwapb-gpio.txt b/Documentation/devicetree/bindings/gpio/snps-dwapb-gpio.txt index 7276b50c3506..839dd32ffe11 100644 --- a/Documentation/devicetree/bindings/gpio/snps-dwapb-gpio.txt +++ b/Documentation/devicetree/bindings/gpio/snps-dwapb-gpio.txt | |||
| @@ -43,7 +43,7 @@ gpio: gpio@20000 { | |||
| 43 | #address-cells = <1>; | 43 | #address-cells = <1>; |
| 44 | #size-cells = <0>; | 44 | #size-cells = <0>; |
| 45 | 45 | ||
| 46 | porta: gpio-controller@0 { | 46 | porta: gpio@0 { |
| 47 | compatible = "snps,dw-apb-gpio-port"; | 47 | compatible = "snps,dw-apb-gpio-port"; |
| 48 | gpio-controller; | 48 | gpio-controller; |
| 49 | #gpio-cells = <2>; | 49 | #gpio-cells = <2>; |
| @@ -55,7 +55,7 @@ gpio: gpio@20000 { | |||
| 55 | interrupts = <0>; | 55 | interrupts = <0>; |
| 56 | }; | 56 | }; |
| 57 | 57 | ||
| 58 | portb: gpio-controller@1 { | 58 | portb: gpio@1 { |
| 59 | compatible = "snps,dw-apb-gpio-port"; | 59 | compatible = "snps,dw-apb-gpio-port"; |
| 60 | gpio-controller; | 60 | gpio-controller; |
| 61 | #gpio-cells = <2>; | 61 | #gpio-cells = <2>; |
diff --git a/Documentation/driver-api/gpio/driver.rst b/Documentation/driver-api/gpio/driver.rst index a6c14ff0c54f..a92d8837b62b 100644 --- a/Documentation/driver-api/gpio/driver.rst +++ b/Documentation/driver-api/gpio/driver.rst | |||
| @@ -434,7 +434,9 @@ try_module_get()). A GPIO driver can use the following functions instead | |||
| 434 | to request and free descriptors without being pinned to the kernel forever:: | 434 | to request and free descriptors without being pinned to the kernel forever:: |
| 435 | 435 | ||
| 436 | struct gpio_desc *gpiochip_request_own_desc(struct gpio_desc *desc, | 436 | struct gpio_desc *gpiochip_request_own_desc(struct gpio_desc *desc, |
| 437 | const char *label) | 437 | u16 hwnum, |
| 438 | const char *label, | ||
| 439 | enum gpiod_flags flags) | ||
| 438 | 440 | ||
| 439 | void gpiochip_free_own_desc(struct gpio_desc *desc) | 441 | void gpiochip_free_own_desc(struct gpio_desc *desc) |
| 440 | 442 | ||
diff --git a/Documentation/driver-model/devres.txt b/Documentation/driver-model/devres.txt index fc4cc24dfb97..52a752300e94 100644 --- a/Documentation/driver-model/devres.txt +++ b/Documentation/driver-model/devres.txt | |||
| @@ -256,7 +256,6 @@ GPIO | |||
| 256 | devm_gpiod_put() | 256 | devm_gpiod_put() |
| 257 | devm_gpiod_unhinge() | 257 | devm_gpiod_unhinge() |
| 258 | devm_gpiochip_add_data() | 258 | devm_gpiochip_add_data() |
| 259 | devm_gpiochip_remove() | ||
| 260 | devm_gpio_request() | 259 | devm_gpio_request() |
| 261 | devm_gpio_request_one() | 260 | devm_gpio_request_one() |
| 262 | devm_gpio_free() | 261 | devm_gpio_free() |
diff --git a/MAINTAINERS b/MAINTAINERS index 784c78a4ae7e..966dc329013c 100644 --- a/MAINTAINERS +++ b/MAINTAINERS | |||
| @@ -6412,7 +6412,6 @@ F: drivers/media/rc/gpio-ir-tx.c | |||
| 6412 | 6412 | ||
| 6413 | GPIO MOCKUP DRIVER | 6413 | GPIO MOCKUP DRIVER |
| 6414 | M: Bamvor Jian Zhang <bamv2005@gmail.com> | 6414 | M: Bamvor Jian Zhang <bamv2005@gmail.com> |
| 6415 | R: Bartosz Golaszewski <brgl@bgdev.pl> | ||
| 6416 | L: linux-gpio@vger.kernel.org | 6415 | L: linux-gpio@vger.kernel.org |
| 6417 | S: Maintained | 6416 | S: Maintained |
| 6418 | F: drivers/gpio/gpio-mockup.c | 6417 | F: drivers/gpio/gpio-mockup.c |
| @@ -9933,6 +9932,12 @@ M: Nicolas Ferre <nicolas.ferre@microchip.com> | |||
| 9933 | S: Supported | 9932 | S: Supported |
| 9934 | F: drivers/power/reset/at91-sama5d2_shdwc.c | 9933 | F: drivers/power/reset/at91-sama5d2_shdwc.c |
| 9935 | 9934 | ||
| 9935 | MICROCHIP SAMA5D2-COMPATIBLE PIOBU GPIO | ||
| 9936 | M: Andrei Stefanescu <andrei.stefanescu@microchip.com> | ||
| 9937 | L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) | ||
| 9938 | L: linux-gpio@vger.kernel.org | ||
| 9939 | F: drivers/gpio/gpio-sama5d2-piobu.c | ||
| 9940 | |||
| 9936 | MICROCHIP SPI DRIVER | 9941 | MICROCHIP SPI DRIVER |
| 9937 | M: Nicolas Ferre <nicolas.ferre@microchip.com> | 9942 | M: Nicolas Ferre <nicolas.ferre@microchip.com> |
| 9938 | S: Supported | 9943 | S: Supported |
diff --git a/arch/arm/mach-omap1/ams-delta-fiq.c b/arch/arm/mach-omap1/ams-delta-fiq.c index b0dc7ddf5877..0324d0f209ea 100644 --- a/arch/arm/mach-omap1/ams-delta-fiq.c +++ b/arch/arm/mach-omap1/ams-delta-fiq.c | |||
| @@ -103,7 +103,7 @@ void __init ams_delta_init_fiq(struct gpio_chip *chip, | |||
| 103 | } | 103 | } |
| 104 | 104 | ||
| 105 | for (i = 0; i < ARRAY_SIZE(irq_data); i++) { | 105 | for (i = 0; i < ARRAY_SIZE(irq_data); i++) { |
| 106 | gpiod = gpiochip_request_own_desc(chip, i, pin_name[i]); | 106 | gpiod = gpiochip_request_own_desc(chip, i, pin_name[i], 0); |
| 107 | if (IS_ERR(gpiod)) { | 107 | if (IS_ERR(gpiod)) { |
| 108 | pr_err("%s: failed to get GPIO pin %d (%ld)\n", | 108 | pr_err("%s: failed to get GPIO pin %d (%ld)\n", |
| 109 | __func__, i, PTR_ERR(gpiod)); | 109 | __func__, i, PTR_ERR(gpiod)); |
diff --git a/arch/arm/mach-omap1/board-ams-delta.c b/arch/arm/mach-omap1/board-ams-delta.c index 691a8da13fac..49e3adffbf5b 100644 --- a/arch/arm/mach-omap1/board-ams-delta.c +++ b/arch/arm/mach-omap1/board-ams-delta.c | |||
| @@ -601,7 +601,7 @@ static void __init modem_assign_irq(struct gpio_chip *chip) | |||
| 601 | struct gpio_desc *gpiod; | 601 | struct gpio_desc *gpiod; |
| 602 | 602 | ||
| 603 | gpiod = gpiochip_request_own_desc(chip, AMS_DELTA_GPIO_PIN_MODEM_IRQ, | 603 | gpiod = gpiochip_request_own_desc(chip, AMS_DELTA_GPIO_PIN_MODEM_IRQ, |
| 604 | "modem_irq"); | 604 | "modem_irq", 0); |
| 605 | if (IS_ERR(gpiod)) { | 605 | if (IS_ERR(gpiod)) { |
| 606 | pr_err("%s: modem IRQ GPIO request failed (%ld)\n", __func__, | 606 | pr_err("%s: modem IRQ GPIO request failed (%ld)\n", __func__, |
| 607 | PTR_ERR(gpiod)); | 607 | PTR_ERR(gpiod)); |
| @@ -809,7 +809,7 @@ static void __init ams_delta_led_init(struct gpio_chip *chip) | |||
| 809 | int i; | 809 | int i; |
| 810 | 810 | ||
| 811 | for (i = LATCH1_PIN_LED_CAMERA; i < LATCH1_PIN_DOCKIT1; i++) { | 811 | for (i = LATCH1_PIN_LED_CAMERA; i < LATCH1_PIN_DOCKIT1; i++) { |
| 812 | gpiod = gpiochip_request_own_desc(chip, i, NULL); | 812 | gpiod = gpiochip_request_own_desc(chip, i, "camera-led", 0); |
| 813 | if (IS_ERR(gpiod)) { | 813 | if (IS_ERR(gpiod)) { |
| 814 | pr_warn("%s: %s GPIO %d request failed (%ld)\n", | 814 | pr_warn("%s: %s GPIO %d request failed (%ld)\n", |
| 815 | __func__, LATCH1_LABEL, i, PTR_ERR(gpiod)); | 815 | __func__, LATCH1_LABEL, i, PTR_ERR(gpiod)); |
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index 833a1b51c948..b5a2845347ec 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig | |||
| @@ -160,6 +160,14 @@ config GPIO_BRCMSTB | |||
| 160 | help | 160 | help |
| 161 | Say yes here to enable GPIO support for Broadcom STB (BCM7XXX) SoCs. | 161 | Say yes here to enable GPIO support for Broadcom STB (BCM7XXX) SoCs. |
| 162 | 162 | ||
| 163 | config GPIO_CADENCE | ||
| 164 | tristate "Cadence GPIO support" | ||
| 165 | depends on OF_GPIO | ||
| 166 | select GPIO_GENERIC | ||
| 167 | select GPIOLIB_IRQCHIP | ||
| 168 | help | ||
| 169 | Say yes here to enable support for Cadence GPIO controller. | ||
| 170 | |||
| 163 | config GPIO_CLPS711X | 171 | config GPIO_CLPS711X |
| 164 | tristate "CLPS711X GPIO support" | 172 | tristate "CLPS711X GPIO support" |
| 165 | depends on ARCH_CLPS711X || COMPILE_TEST | 173 | depends on ARCH_CLPS711X || COMPILE_TEST |
| @@ -288,6 +296,7 @@ config GPIO_LPC18XX | |||
| 288 | tristate "NXP LPC18XX/43XX GPIO support" | 296 | tristate "NXP LPC18XX/43XX GPIO support" |
| 289 | default y if ARCH_LPC18XX | 297 | default y if ARCH_LPC18XX |
| 290 | depends on OF_GPIO && (ARCH_LPC18XX || COMPILE_TEST) | 298 | depends on OF_GPIO && (ARCH_LPC18XX || COMPILE_TEST) |
| 299 | select IRQ_DOMAIN_HIERARCHY | ||
| 291 | help | 300 | help |
| 292 | Select this option to enable GPIO driver for | 301 | Select this option to enable GPIO driver for |
| 293 | NXP LPC18XX/43XX devices. | 302 | NXP LPC18XX/43XX devices. |
| @@ -429,6 +438,18 @@ config GPIO_REG | |||
| 429 | A 32-bit single register GPIO fixed in/out implementation. This | 438 | A 32-bit single register GPIO fixed in/out implementation. This |
| 430 | can be used to represent any register as a set of GPIO signals. | 439 | can be used to represent any register as a set of GPIO signals. |
| 431 | 440 | ||
| 441 | config GPIO_SAMA5D2_PIOBU | ||
| 442 | tristate "SAMA5D2 PIOBU GPIO support" | ||
| 443 | depends on MFD_SYSCON | ||
| 444 | depends on OF_GPIO | ||
| 445 | select GPIO_SYSCON | ||
| 446 | help | ||
| 447 | Say yes here to use the PIOBU pins as GPIOs. | ||
| 448 | |||
| 449 | PIOBU pins on the SAMA5D2 can be used as GPIOs. | ||
| 450 | The difference from regular GPIOs is that they | ||
| 451 | maintain their value during backup/self-refresh. | ||
| 452 | |||
| 432 | config GPIO_SIOX | 453 | config GPIO_SIOX |
| 433 | tristate "SIOX GPIO support" | 454 | tristate "SIOX GPIO support" |
| 434 | depends on SIOX | 455 | depends on SIOX |
| @@ -849,6 +870,7 @@ config GPIO_MC9S08DZ60 | |||
| 849 | 870 | ||
| 850 | config GPIO_PCA953X | 871 | config GPIO_PCA953X |
| 851 | tristate "PCA95[357]x, PCA9698, TCA64xx, and MAX7310 I/O ports" | 872 | tristate "PCA95[357]x, PCA9698, TCA64xx, and MAX7310 I/O ports" |
| 873 | select REGMAP_I2C | ||
| 852 | help | 874 | help |
| 853 | Say yes here to provide access to several register-oriented | 875 | Say yes here to provide access to several register-oriented |
| 854 | SMBus I/O expanders, made mostly by NXP or TI. Compatible | 876 | SMBus I/O expanders, made mostly by NXP or TI. Compatible |
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile index 671c4477c951..37628f8dbf70 100644 --- a/drivers/gpio/Makefile +++ b/drivers/gpio/Makefile | |||
| @@ -37,6 +37,7 @@ obj-$(CONFIG_GPIO_BCM_KONA) += gpio-bcm-kona.o | |||
| 37 | obj-$(CONFIG_GPIO_BD9571MWV) += gpio-bd9571mwv.o | 37 | obj-$(CONFIG_GPIO_BD9571MWV) += gpio-bd9571mwv.o |
| 38 | obj-$(CONFIG_GPIO_BRCMSTB) += gpio-brcmstb.o | 38 | obj-$(CONFIG_GPIO_BRCMSTB) += gpio-brcmstb.o |
| 39 | obj-$(CONFIG_GPIO_BT8XX) += gpio-bt8xx.o | 39 | obj-$(CONFIG_GPIO_BT8XX) += gpio-bt8xx.o |
| 40 | obj-$(CONFIG_GPIO_CADENCE) += gpio-cadence.o | ||
| 40 | obj-$(CONFIG_GPIO_CLPS711X) += gpio-clps711x.o | 41 | obj-$(CONFIG_GPIO_CLPS711X) += gpio-clps711x.o |
| 41 | obj-$(CONFIG_GPIO_CS5535) += gpio-cs5535.o | 42 | obj-$(CONFIG_GPIO_CS5535) += gpio-cs5535.o |
| 42 | obj-$(CONFIG_GPIO_CRYSTAL_COVE) += gpio-crystalcove.o | 43 | obj-$(CONFIG_GPIO_CRYSTAL_COVE) += gpio-crystalcove.o |
| @@ -108,6 +109,7 @@ obj-$(CONFIG_GPIO_RDC321X) += gpio-rdc321x.o | |||
| 108 | obj-$(CONFIG_GPIO_RCAR) += gpio-rcar.o | 109 | obj-$(CONFIG_GPIO_RCAR) += gpio-rcar.o |
| 109 | obj-$(CONFIG_GPIO_REG) += gpio-reg.o | 110 | obj-$(CONFIG_GPIO_REG) += gpio-reg.o |
| 110 | obj-$(CONFIG_ARCH_SA1100) += gpio-sa1100.o | 111 | obj-$(CONFIG_ARCH_SA1100) += gpio-sa1100.o |
| 112 | obj-$(CONFIG_GPIO_SAMA5D2_PIOBU) += gpio-sama5d2-piobu.o | ||
| 111 | obj-$(CONFIG_GPIO_SCH) += gpio-sch.o | 113 | obj-$(CONFIG_GPIO_SCH) += gpio-sch.o |
| 112 | obj-$(CONFIG_GPIO_SCH311X) += gpio-sch311x.o | 114 | obj-$(CONFIG_GPIO_SCH311X) += gpio-sch311x.o |
| 113 | obj-$(CONFIG_GPIO_SNPS_CREG) += gpio-creg-snps.o | 115 | obj-$(CONFIG_GPIO_SNPS_CREG) += gpio-creg-snps.o |
diff --git a/drivers/gpio/TODO b/drivers/gpio/TODO new file mode 100644 index 000000000000..19d27c904916 --- /dev/null +++ b/drivers/gpio/TODO | |||
| @@ -0,0 +1,109 @@ | |||
| 1 | This is a place for planning the ongoing long-term work in the GPIO | ||
| 2 | subsystem. | ||
| 3 | |||
| 4 | |||
| 5 | GPIO descriptors | ||
| 6 | |||
| 7 | Starting with commit 79a9becda894 the GPIO subsystem embarked on a journey | ||
| 8 | to move away from the global GPIO numberspace and toward a decriptor-based | ||
| 9 | approach. This means that GPIO consumers, drivers and machine descriptions | ||
| 10 | ideally have no use or idea of the global GPIO numberspace that has/was | ||
| 11 | used in the inception of the GPIO subsystem. | ||
| 12 | |||
| 13 | Work items: | ||
| 14 | |||
| 15 | - Convert all GPIO device drivers to only #include <linux/gpio/driver.h> | ||
| 16 | |||
| 17 | - Convert all consumer drivers to only #include <linux/gpio/consumer.h> | ||
| 18 | |||
| 19 | - Convert all machine descriptors in "boardfiles" to only | ||
| 20 | #include <linux/gpio/machine.h>, the other option being to convert it | ||
| 21 | to a machine description such as device tree, ACPI or fwnode that | ||
| 22 | implicitly does not use global GPIO numbers. | ||
| 23 | |||
| 24 | - When this work is complete (will require some of the items in the | ||
| 25 | following ongoing work as well) we can delete the old global | ||
| 26 | numberspace accessors from <linux/gpio.h> and eventually delete | ||
| 27 | <linux/gpio.h> altogether. | ||
| 28 | |||
| 29 | |||
| 30 | Get rid of <linux/of_gpio.h> | ||
| 31 | |||
| 32 | This header and helpers appeared at one point when there was no proper | ||
| 33 | driver infrastructure for doing simpler MMIO GPIO devices and there was | ||
| 34 | no core support for parsing device tree GPIOs from the core library with | ||
| 35 | the [devm_]gpiod_get() calls we have today that will implicitly go into | ||
| 36 | the device tree back-end. | ||
| 37 | |||
| 38 | Work items: | ||
| 39 | |||
| 40 | - Get rid of struct of_mm_gpio_chip altogether: use the generic MMIO | ||
| 41 | GPIO for all current users (see below). Delete struct of_mm_gpio_chip, | ||
| 42 | to_of_mm_gpio_chip(), of_mm_gpiochip_add_data(), of_mm_gpiochip_add() | ||
| 43 | of_mm_gpiochip_remove() from the kernel. | ||
| 44 | |||
| 45 | - Change all consumer drivers that #include <linux/of_gpio.h> to | ||
| 46 | #include <linux/gpio/consumer.h> and stop doing custom parsing of the | ||
| 47 | GPIO lines from the device tree. This can be tricky and often ivolves | ||
| 48 | changing boardfiles, etc. | ||
| 49 | |||
| 50 | - Pull semantics for legacy device tree (OF) GPIO lookups into | ||
| 51 | gpiolib-of.c: in some cases subsystems are doing custom flags and | ||
| 52 | lookups for polarity inversion, open drain and what not. As we now | ||
| 53 | handle this with generic OF bindings, pull all legacy handling into | ||
| 54 | gpiolib so the library API becomes narrow and deep and handle all | ||
| 55 | legacy bindings internally. (See e.g. commits 6953c57ab172, | ||
| 56 | 6a537d48461d etc) | ||
| 57 | |||
| 58 | - Delete <linux/of_gpio.h> when all the above is complete and everything | ||
| 59 | uses <linux/gpio/consumer.h> or <linux/gpio/driver.h> instead. | ||
| 60 | |||
| 61 | |||
| 62 | Collect drivers | ||
| 63 | |||
| 64 | Collect GPIO drivers from arch/* and other places that should be placed | ||
| 65 | in drivers/gpio/gpio-*. Augment platforms to create platform devices or | ||
| 66 | similar and probe a proper driver in the gpiolib subsystem. | ||
| 67 | |||
| 68 | In some cases it makes sense to create a GPIO chip from the local driver | ||
| 69 | for a few GPIOs. Those should stay where they are. | ||
| 70 | |||
| 71 | |||
| 72 | Generic MMIO GPIO | ||
| 73 | |||
| 74 | The GPIO drivers can utilize the generic MMIO helper library in many | ||
| 75 | cases, and the helper library should be as helpful as possible for MMIO | ||
| 76 | drivers. (drivers/gpio/gpio-mmio.c) | ||
| 77 | |||
| 78 | Work items: | ||
| 79 | |||
| 80 | - Look over and identify any remaining easily converted drivers and | ||
| 81 | dry-code conversions to MMIO GPIO for maintainers to test | ||
| 82 | |||
| 83 | - Expand the MMIO GPIO or write a new library for port-mapped I/O | ||
| 84 | helpers (x86 inb()/outb()) and convert port-mapped I/O drivers to use | ||
| 85 | this with dry-coding and sending to maintainers to test | ||
| 86 | |||
| 87 | |||
| 88 | GPIOLIB irqchip | ||
| 89 | |||
| 90 | The GPIOLIB irqchip is a helper irqchip for "simple cases" that should | ||
| 91 | try to cover any generic kind of irqchip cascaded from a GPIO. | ||
| 92 | |||
| 93 | - Look over and identify any remaining easily converted drivers and | ||
| 94 | dry-code conversions to gpiolib irqchip for maintainers to test | ||
| 95 | |||
| 96 | - Support generic hierarchical GPIO interrupts: these are for the | ||
| 97 | non-cascading case where there is one IRQ per GPIO line, there is | ||
| 98 | currently no common infrastructure for this. | ||
| 99 | |||
| 100 | |||
| 101 | Increase integration with pin control | ||
| 102 | |||
| 103 | There are already ways to use pin control as back-end for GPIO and | ||
| 104 | it may make sense to bring these subsystems closer. One reason for | ||
| 105 | creating pin control as its own subsystem was that we could avoid any | ||
| 106 | use of the global GPIO numbers. Once the above is complete, it may | ||
| 107 | make sense to simply join the subsystems into one and make pin | ||
| 108 | multiplexing, pin configuration, GPIO, etc selectable options in one | ||
| 109 | and the same pin control and GPIO subsystem. | ||
diff --git a/drivers/gpio/gpio-104-dio-48e.c b/drivers/gpio/gpio-104-dio-48e.c index 9c4e07fcb74b..92c8f944bf64 100644 --- a/drivers/gpio/gpio-104-dio-48e.c +++ b/drivers/gpio/gpio-104-dio-48e.c | |||
| @@ -222,7 +222,7 @@ static int dio48e_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask, | |||
| 222 | port_state = inb(dio48egpio->base + ports[i]); | 222 | port_state = inb(dio48egpio->base + ports[i]); |
| 223 | 223 | ||
| 224 | /* store acquired bits at respective bits array offset */ | 224 | /* store acquired bits at respective bits array offset */ |
| 225 | bits[word_index] |= port_state << word_offset; | 225 | bits[word_index] |= (port_state << word_offset) & word_mask; |
| 226 | } | 226 | } |
| 227 | 227 | ||
| 228 | return 0; | 228 | return 0; |
diff --git a/drivers/gpio/gpio-104-idi-48.c b/drivers/gpio/gpio-104-idi-48.c index 2c9738adb3a6..88dc6f2449f6 100644 --- a/drivers/gpio/gpio-104-idi-48.c +++ b/drivers/gpio/gpio-104-idi-48.c | |||
| @@ -128,7 +128,7 @@ static int idi_48_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask, | |||
| 128 | port_state = inb(idi48gpio->base + ports[i]); | 128 | port_state = inb(idi48gpio->base + ports[i]); |
| 129 | 129 | ||
| 130 | /* store acquired bits at respective bits array offset */ | 130 | /* store acquired bits at respective bits array offset */ |
| 131 | bits[word_index] |= port_state << word_offset; | 131 | bits[word_index] |= (port_state << word_offset) & word_mask; |
| 132 | } | 132 | } |
| 133 | 133 | ||
| 134 | return 0; | 134 | return 0; |
diff --git a/drivers/gpio/gpio-aspeed.c b/drivers/gpio/gpio-aspeed.c index 2342e154029b..854bce4fb9e7 100644 --- a/drivers/gpio/gpio-aspeed.c +++ b/drivers/gpio/gpio-aspeed.c | |||
| @@ -1185,7 +1185,6 @@ static int __init aspeed_gpio_probe(struct platform_device *pdev) | |||
| 1185 | 1185 | ||
| 1186 | gpio->chip.parent = &pdev->dev; | 1186 | gpio->chip.parent = &pdev->dev; |
| 1187 | gpio->chip.ngpio = gpio->config->nr_gpios; | 1187 | gpio->chip.ngpio = gpio->config->nr_gpios; |
| 1188 | gpio->chip.parent = &pdev->dev; | ||
| 1189 | gpio->chip.direction_input = aspeed_gpio_dir_in; | 1188 | gpio->chip.direction_input = aspeed_gpio_dir_in; |
| 1190 | gpio->chip.direction_output = aspeed_gpio_dir_out; | 1189 | gpio->chip.direction_output = aspeed_gpio_dir_out; |
| 1191 | gpio->chip.get_direction = aspeed_gpio_get_direction; | 1190 | gpio->chip.get_direction = aspeed_gpio_get_direction; |
diff --git a/drivers/gpio/gpio-cadence.c b/drivers/gpio/gpio-cadence.c new file mode 100644 index 000000000000..aec8d5df9f30 --- /dev/null +++ b/drivers/gpio/gpio-cadence.c | |||
| @@ -0,0 +1,291 @@ | |||
| 1 | // SPDX-License-Identifier: GPL-2.0 | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright 2017-2018 Cadence | ||
| 5 | * | ||
| 6 | * Authors: | ||
| 7 | * Jan Kotas <jank@cadence.com> | ||
| 8 | * Boris Brezillon <boris.brezillon@free-electrons.com> | ||
| 9 | */ | ||
| 10 | |||
| 11 | #include <linux/gpio/driver.h> | ||
| 12 | #include <linux/clk.h> | ||
| 13 | #include <linux/interrupt.h> | ||
| 14 | #include <linux/kernel.h> | ||
| 15 | #include <linux/module.h> | ||
| 16 | #include <linux/platform_device.h> | ||
| 17 | #include <linux/spinlock.h> | ||
| 18 | |||
| 19 | #define CDNS_GPIO_BYPASS_MODE 0x00 | ||
| 20 | #define CDNS_GPIO_DIRECTION_MODE 0x04 | ||
| 21 | #define CDNS_GPIO_OUTPUT_EN 0x08 | ||
| 22 | #define CDNS_GPIO_OUTPUT_VALUE 0x0c | ||
| 23 | #define CDNS_GPIO_INPUT_VALUE 0x10 | ||
| 24 | #define CDNS_GPIO_IRQ_MASK 0x14 | ||
| 25 | #define CDNS_GPIO_IRQ_EN 0x18 | ||
| 26 | #define CDNS_GPIO_IRQ_DIS 0x1c | ||
| 27 | #define CDNS_GPIO_IRQ_STATUS 0x20 | ||
| 28 | #define CDNS_GPIO_IRQ_TYPE 0x24 | ||
| 29 | #define CDNS_GPIO_IRQ_VALUE 0x28 | ||
| 30 | #define CDNS_GPIO_IRQ_ANY_EDGE 0x2c | ||
| 31 | |||
| 32 | struct cdns_gpio_chip { | ||
| 33 | struct gpio_chip gc; | ||
| 34 | struct clk *pclk; | ||
| 35 | void __iomem *regs; | ||
| 36 | u32 bypass_orig; | ||
| 37 | }; | ||
| 38 | |||
| 39 | static int cdns_gpio_request(struct gpio_chip *chip, unsigned int offset) | ||
| 40 | { | ||
| 41 | struct cdns_gpio_chip *cgpio = gpiochip_get_data(chip); | ||
| 42 | unsigned long flags; | ||
| 43 | |||
| 44 | spin_lock_irqsave(&chip->bgpio_lock, flags); | ||
| 45 | |||
| 46 | iowrite32(ioread32(cgpio->regs + CDNS_GPIO_BYPASS_MODE) & ~BIT(offset), | ||
| 47 | cgpio->regs + CDNS_GPIO_BYPASS_MODE); | ||
| 48 | |||
| 49 | spin_unlock_irqrestore(&chip->bgpio_lock, flags); | ||
| 50 | return 0; | ||
| 51 | } | ||
| 52 | |||
| 53 | static void cdns_gpio_free(struct gpio_chip *chip, unsigned int offset) | ||
| 54 | { | ||
| 55 | struct cdns_gpio_chip *cgpio = gpiochip_get_data(chip); | ||
| 56 | unsigned long flags; | ||
| 57 | |||
| 58 | spin_lock_irqsave(&chip->bgpio_lock, flags); | ||
| 59 | |||
| 60 | iowrite32(ioread32(cgpio->regs + CDNS_GPIO_BYPASS_MODE) | | ||
| 61 | (BIT(offset) & cgpio->bypass_orig), | ||
| 62 | cgpio->regs + CDNS_GPIO_BYPASS_MODE); | ||
| 63 | |||
| 64 | spin_unlock_irqrestore(&chip->bgpio_lock, flags); | ||
| 65 | } | ||
| 66 | |||
| 67 | static void cdns_gpio_irq_mask(struct irq_data *d) | ||
| 68 | { | ||
| 69 | struct gpio_chip *chip = irq_data_get_irq_chip_data(d); | ||
| 70 | struct cdns_gpio_chip *cgpio = gpiochip_get_data(chip); | ||
| 71 | |||
| 72 | iowrite32(BIT(d->hwirq), cgpio->regs + CDNS_GPIO_IRQ_DIS); | ||
| 73 | } | ||
| 74 | |||
| 75 | static void cdns_gpio_irq_unmask(struct irq_data *d) | ||
| 76 | { | ||
| 77 | struct gpio_chip *chip = irq_data_get_irq_chip_data(d); | ||
| 78 | struct cdns_gpio_chip *cgpio = gpiochip_get_data(chip); | ||
| 79 | |||
| 80 | iowrite32(BIT(d->hwirq), cgpio->regs + CDNS_GPIO_IRQ_EN); | ||
| 81 | } | ||
| 82 | |||
| 83 | static int cdns_gpio_irq_set_type(struct irq_data *d, unsigned int type) | ||
| 84 | { | ||
| 85 | struct gpio_chip *chip = irq_data_get_irq_chip_data(d); | ||
| 86 | struct cdns_gpio_chip *cgpio = gpiochip_get_data(chip); | ||
| 87 | unsigned long flags; | ||
| 88 | u32 int_value; | ||
| 89 | u32 int_type; | ||
| 90 | u32 mask = BIT(d->hwirq); | ||
| 91 | int ret = 0; | ||
| 92 | |||
| 93 | spin_lock_irqsave(&chip->bgpio_lock, flags); | ||
| 94 | |||
| 95 | int_value = ioread32(cgpio->regs + CDNS_GPIO_IRQ_VALUE) & ~mask; | ||
| 96 | int_type = ioread32(cgpio->regs + CDNS_GPIO_IRQ_TYPE) & ~mask; | ||
| 97 | |||
| 98 | /* | ||
| 99 | * The GPIO controller doesn't have an ACK register. | ||
| 100 | * All interrupt statuses are cleared on a status register read. | ||
| 101 | * Don't support edge interrupts for now. | ||
| 102 | */ | ||
| 103 | |||
| 104 | if (type == IRQ_TYPE_LEVEL_HIGH) { | ||
| 105 | int_type |= mask; | ||
| 106 | int_value |= mask; | ||
| 107 | } else if (type == IRQ_TYPE_LEVEL_LOW) { | ||
| 108 | int_type |= mask; | ||
| 109 | } else { | ||
| 110 | ret = -EINVAL; | ||
| 111 | goto err_irq_type; | ||
| 112 | } | ||
| 113 | |||
| 114 | iowrite32(int_value, cgpio->regs + CDNS_GPIO_IRQ_VALUE); | ||
| 115 | iowrite32(int_type, cgpio->regs + CDNS_GPIO_IRQ_TYPE); | ||
| 116 | |||
| 117 | err_irq_type: | ||
| 118 | spin_unlock_irqrestore(&chip->bgpio_lock, flags); | ||
| 119 | return ret; | ||
| 120 | } | ||
| 121 | |||
| 122 | static void cdns_gpio_irq_handler(struct irq_desc *desc) | ||
| 123 | { | ||
| 124 | struct gpio_chip *chip = irq_desc_get_handler_data(desc); | ||
| 125 | struct cdns_gpio_chip *cgpio = gpiochip_get_data(chip); | ||
| 126 | struct irq_chip *irqchip = irq_desc_get_chip(desc); | ||
| 127 | unsigned long status; | ||
| 128 | int hwirq; | ||
| 129 | |||
| 130 | chained_irq_enter(irqchip, desc); | ||
| 131 | |||
| 132 | status = ioread32(cgpio->regs + CDNS_GPIO_IRQ_STATUS) & | ||
| 133 | ~ioread32(cgpio->regs + CDNS_GPIO_IRQ_MASK); | ||
| 134 | |||
| 135 | for_each_set_bit(hwirq, &status, chip->ngpio) | ||
| 136 | generic_handle_irq(irq_find_mapping(chip->irq.domain, hwirq)); | ||
| 137 | |||
| 138 | chained_irq_exit(irqchip, desc); | ||
| 139 | } | ||
| 140 | |||
| 141 | static struct irq_chip cdns_gpio_irqchip = { | ||
| 142 | .name = "cdns-gpio", | ||
| 143 | .irq_mask = cdns_gpio_irq_mask, | ||
| 144 | .irq_unmask = cdns_gpio_irq_unmask, | ||
| 145 | .irq_set_type = cdns_gpio_irq_set_type | ||
| 146 | }; | ||
| 147 | |||
| 148 | static int cdns_gpio_probe(struct platform_device *pdev) | ||
| 149 | { | ||
| 150 | struct cdns_gpio_chip *cgpio; | ||
| 151 | struct resource *res; | ||
| 152 | int ret, irq; | ||
| 153 | u32 dir_prev; | ||
| 154 | u32 num_gpios = 32; | ||
| 155 | |||
| 156 | cgpio = devm_kzalloc(&pdev->dev, sizeof(*cgpio), GFP_KERNEL); | ||
| 157 | if (!cgpio) | ||
| 158 | return -ENOMEM; | ||
| 159 | |||
| 160 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
| 161 | cgpio->regs = devm_ioremap_resource(&pdev->dev, res); | ||
| 162 | if (IS_ERR(cgpio->regs)) | ||
| 163 | return PTR_ERR(cgpio->regs); | ||
| 164 | |||
| 165 | of_property_read_u32(pdev->dev.of_node, "ngpios", &num_gpios); | ||
| 166 | |||
| 167 | if (num_gpios > 32) { | ||
| 168 | dev_err(&pdev->dev, "ngpios must be less or equal 32\n"); | ||
| 169 | return -EINVAL; | ||
| 170 | } | ||
| 171 | |||
| 172 | /* | ||
| 173 | * Set all pins as inputs by default, otherwise: | ||
| 174 | * gpiochip_lock_as_irq: | ||
| 175 | * tried to flag a GPIO set as output for IRQ | ||
| 176 | * Generic GPIO driver stores the direction value internally, | ||
| 177 | * so it needs to be changed before bgpio_init() is called. | ||
| 178 | */ | ||
| 179 | dir_prev = ioread32(cgpio->regs + CDNS_GPIO_DIRECTION_MODE); | ||
| 180 | iowrite32(GENMASK(num_gpios - 1, 0), | ||
| 181 | cgpio->regs + CDNS_GPIO_DIRECTION_MODE); | ||
| 182 | |||
| 183 | ret = bgpio_init(&cgpio->gc, &pdev->dev, 4, | ||
| 184 | cgpio->regs + CDNS_GPIO_INPUT_VALUE, | ||
| 185 | cgpio->regs + CDNS_GPIO_OUTPUT_VALUE, | ||
| 186 | NULL, | ||
| 187 | NULL, | ||
| 188 | cgpio->regs + CDNS_GPIO_DIRECTION_MODE, | ||
| 189 | BGPIOF_READ_OUTPUT_REG_SET); | ||
| 190 | if (ret) { | ||
| 191 | dev_err(&pdev->dev, "Failed to register generic gpio, %d\n", | ||
| 192 | ret); | ||
| 193 | goto err_revert_dir; | ||
| 194 | } | ||
| 195 | |||
| 196 | cgpio->gc.label = dev_name(&pdev->dev); | ||
| 197 | cgpio->gc.ngpio = num_gpios; | ||
| 198 | cgpio->gc.parent = &pdev->dev; | ||
| 199 | cgpio->gc.base = -1; | ||
| 200 | cgpio->gc.owner = THIS_MODULE; | ||
| 201 | cgpio->gc.request = cdns_gpio_request; | ||
| 202 | cgpio->gc.free = cdns_gpio_free; | ||
| 203 | |||
| 204 | cgpio->pclk = devm_clk_get(&pdev->dev, NULL); | ||
| 205 | if (IS_ERR(cgpio->pclk)) { | ||
| 206 | ret = PTR_ERR(cgpio->pclk); | ||
| 207 | dev_err(&pdev->dev, | ||
| 208 | "Failed to retrieve peripheral clock, %d\n", ret); | ||
| 209 | goto err_revert_dir; | ||
| 210 | } | ||
| 211 | |||
| 212 | ret = clk_prepare_enable(cgpio->pclk); | ||
| 213 | if (ret) { | ||
| 214 | dev_err(&pdev->dev, | ||
| 215 | "Failed to enable the peripheral clock, %d\n", ret); | ||
| 216 | goto err_revert_dir; | ||
| 217 | } | ||
| 218 | |||
| 219 | ret = devm_gpiochip_add_data(&pdev->dev, &cgpio->gc, cgpio); | ||
| 220 | if (ret < 0) { | ||
| 221 | dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret); | ||
| 222 | goto err_disable_clk; | ||
| 223 | } | ||
| 224 | |||
| 225 | /* | ||
| 226 | * irq_chip support | ||
| 227 | */ | ||
| 228 | irq = platform_get_irq(pdev, 0); | ||
| 229 | if (irq >= 0) { | ||
| 230 | ret = gpiochip_irqchip_add(&cgpio->gc, &cdns_gpio_irqchip, | ||
| 231 | 0, handle_level_irq, | ||
| 232 | IRQ_TYPE_NONE); | ||
| 233 | if (ret) { | ||
| 234 | dev_err(&pdev->dev, "Could not add irqchip, %d\n", | ||
| 235 | ret); | ||
| 236 | goto err_disable_clk; | ||
| 237 | } | ||
| 238 | gpiochip_set_chained_irqchip(&cgpio->gc, &cdns_gpio_irqchip, | ||
| 239 | irq, cdns_gpio_irq_handler); | ||
| 240 | } | ||
| 241 | |||
| 242 | cgpio->bypass_orig = ioread32(cgpio->regs + CDNS_GPIO_BYPASS_MODE); | ||
| 243 | |||
| 244 | /* | ||
| 245 | * Enable gpio outputs, ignored for input direction | ||
| 246 | */ | ||
| 247 | iowrite32(GENMASK(num_gpios - 1, 0), | ||
| 248 | cgpio->regs + CDNS_GPIO_OUTPUT_EN); | ||
| 249 | iowrite32(0, cgpio->regs + CDNS_GPIO_BYPASS_MODE); | ||
| 250 | |||
| 251 | platform_set_drvdata(pdev, cgpio); | ||
| 252 | return 0; | ||
| 253 | |||
| 254 | err_disable_clk: | ||
| 255 | clk_disable_unprepare(cgpio->pclk); | ||
| 256 | |||
| 257 | err_revert_dir: | ||
| 258 | iowrite32(dir_prev, cgpio->regs + CDNS_GPIO_DIRECTION_MODE); | ||
| 259 | |||
| 260 | return ret; | ||
| 261 | } | ||
| 262 | |||
| 263 | static int cdns_gpio_remove(struct platform_device *pdev) | ||
| 264 | { | ||
| 265 | struct cdns_gpio_chip *cgpio = platform_get_drvdata(pdev); | ||
| 266 | |||
| 267 | iowrite32(cgpio->bypass_orig, cgpio->regs + CDNS_GPIO_BYPASS_MODE); | ||
| 268 | clk_disable_unprepare(cgpio->pclk); | ||
| 269 | |||
| 270 | return 0; | ||
| 271 | } | ||
| 272 | |||
| 273 | static const struct of_device_id cdns_of_ids[] = { | ||
| 274 | { .compatible = "cdns,gpio-r1p02" }, | ||
| 275 | { /* sentinel */ }, | ||
| 276 | }; | ||
| 277 | |||
| 278 | static struct platform_driver cdns_gpio_driver = { | ||
| 279 | .driver = { | ||
| 280 | .name = "cdns-gpio", | ||
| 281 | .of_match_table = cdns_of_ids, | ||
| 282 | }, | ||
| 283 | .probe = cdns_gpio_probe, | ||
| 284 | .remove = cdns_gpio_remove, | ||
| 285 | }; | ||
| 286 | module_platform_driver(cdns_gpio_driver); | ||
| 287 | |||
| 288 | MODULE_AUTHOR("Jan Kotas <jank@cadence.com>"); | ||
| 289 | MODULE_DESCRIPTION("Cadence GPIO driver"); | ||
| 290 | MODULE_LICENSE("GPL v2"); | ||
| 291 | MODULE_ALIAS("platform:cdns-gpio"); | ||
diff --git a/drivers/gpio/gpio-dwapb.c b/drivers/gpio/gpio-dwapb.c index 044888fd96a1..84ae04402f70 100644 --- a/drivers/gpio/gpio-dwapb.c +++ b/drivers/gpio/gpio-dwapb.c | |||
| @@ -748,8 +748,7 @@ static int dwapb_gpio_remove(struct platform_device *pdev) | |||
| 748 | #ifdef CONFIG_PM_SLEEP | 748 | #ifdef CONFIG_PM_SLEEP |
| 749 | static int dwapb_gpio_suspend(struct device *dev) | 749 | static int dwapb_gpio_suspend(struct device *dev) |
| 750 | { | 750 | { |
| 751 | struct platform_device *pdev = to_platform_device(dev); | 751 | struct dwapb_gpio *gpio = dev_get_drvdata(dev); |
| 752 | struct dwapb_gpio *gpio = platform_get_drvdata(pdev); | ||
| 753 | struct gpio_chip *gc = &gpio->ports[0].gc; | 752 | struct gpio_chip *gc = &gpio->ports[0].gc; |
| 754 | unsigned long flags; | 753 | unsigned long flags; |
| 755 | int i; | 754 | int i; |
| @@ -793,8 +792,7 @@ static int dwapb_gpio_suspend(struct device *dev) | |||
| 793 | 792 | ||
| 794 | static int dwapb_gpio_resume(struct device *dev) | 793 | static int dwapb_gpio_resume(struct device *dev) |
| 795 | { | 794 | { |
| 796 | struct platform_device *pdev = to_platform_device(dev); | 795 | struct dwapb_gpio *gpio = dev_get_drvdata(dev); |
| 797 | struct dwapb_gpio *gpio = platform_get_drvdata(pdev); | ||
| 798 | struct gpio_chip *gc = &gpio->ports[0].gc; | 796 | struct gpio_chip *gc = &gpio->ports[0].gc; |
| 799 | unsigned long flags; | 797 | unsigned long flags; |
| 800 | int i; | 798 | int i; |
diff --git a/drivers/gpio/gpio-gpio-mm.c b/drivers/gpio/gpio-gpio-mm.c index b56ff2efbf36..8c150fd68d9d 100644 --- a/drivers/gpio/gpio-gpio-mm.c +++ b/drivers/gpio/gpio-gpio-mm.c | |||
| @@ -211,7 +211,7 @@ static int gpiomm_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask, | |||
| 211 | port_state = inb(gpiommgpio->base + ports[i]); | 211 | port_state = inb(gpiommgpio->base + ports[i]); |
| 212 | 212 | ||
| 213 | /* store acquired bits at respective bits array offset */ | 213 | /* store acquired bits at respective bits array offset */ |
| 214 | bits[word_index] |= port_state << word_offset; | 214 | bits[word_index] |= (port_state << word_offset) & word_mask; |
| 215 | } | 215 | } |
| 216 | 216 | ||
| 217 | return 0; | 217 | return 0; |
diff --git a/drivers/gpio/gpio-grgpio.c b/drivers/gpio/gpio-grgpio.c index 60a1556c570a..45b8d6a02b87 100644 --- a/drivers/gpio/gpio-grgpio.c +++ b/drivers/gpio/gpio-grgpio.c | |||
| @@ -30,7 +30,6 @@ | |||
| 30 | #include <linux/gpio/driver.h> | 30 | #include <linux/gpio/driver.h> |
| 31 | #include <linux/slab.h> | 31 | #include <linux/slab.h> |
| 32 | #include <linux/err.h> | 32 | #include <linux/err.h> |
| 33 | #include <linux/gpio/driver.h> | ||
| 34 | #include <linux/interrupt.h> | 33 | #include <linux/interrupt.h> |
| 35 | #include <linux/irq.h> | 34 | #include <linux/irq.h> |
| 36 | #include <linux/irqdomain.h> | 35 | #include <linux/irqdomain.h> |
diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c index dba392221042..90bf7742f9b0 100644 --- a/drivers/gpio/gpio-ich.c +++ b/drivers/gpio/gpio-ich.c | |||
| @@ -1,32 +1,18 @@ | |||
| 1 | // SPDX-License-Identifier: GPL-2.0+ | ||
| 1 | /* | 2 | /* |
| 2 | * Intel ICH6-10, Series 5 and 6, Atom C2000 (Avoton/Rangeley) GPIO driver | 3 | * Intel ICH6-10, Series 5 and 6, Atom C2000 (Avoton/Rangeley) GPIO driver |
| 3 | * | 4 | * |
| 4 | * Copyright (C) 2010 Extreme Engineering Solutions. | 5 | * Copyright (C) 2010 Extreme Engineering Solutions. |
| 5 | * | ||
| 6 | * This program is free software; you can redistribute it and/or modify | ||
| 7 | * it under the terms of the GNU General Public License as published by | ||
| 8 | * the Free Software Foundation; either version 2 of the License, or | ||
| 9 | * (at your option) any later version. | ||
| 10 | * | ||
| 11 | * This program is distributed in the hope that it will be useful, | ||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | * GNU General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU General Public License | ||
| 17 | * along with this program; if not, write to the Free Software | ||
| 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
| 19 | */ | 6 | */ |
| 20 | 7 | ||
| 21 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
| 22 | 8 | ||
| 9 | #include <linux/bitops.h> | ||
| 10 | #include <linux/gpio/driver.h> | ||
| 23 | #include <linux/ioport.h> | 11 | #include <linux/ioport.h> |
| 12 | #include <linux/mfd/lpc_ich.h> | ||
| 24 | #include <linux/module.h> | 13 | #include <linux/module.h> |
| 25 | #include <linux/pci.h> | 14 | #include <linux/pci.h> |
| 26 | #include <linux/gpio/driver.h> | ||
| 27 | #include <linux/platform_device.h> | 15 | #include <linux/platform_device.h> |
| 28 | #include <linux/mfd/lpc_ich.h> | ||
| 29 | #include <linux/bitops.h> | ||
| 30 | 16 | ||
| 31 | #define DRV_NAME "gpio_ich" | 17 | #define DRV_NAME "gpio_ich" |
| 32 | 18 | ||
| @@ -100,7 +86,7 @@ struct ichx_desc { | |||
| 100 | 86 | ||
| 101 | static struct { | 87 | static struct { |
| 102 | spinlock_t lock; | 88 | spinlock_t lock; |
| 103 | struct platform_device *dev; | 89 | struct device *dev; |
| 104 | struct gpio_chip chip; | 90 | struct gpio_chip chip; |
| 105 | struct resource *gpio_base; /* GPIO IO base */ | 91 | struct resource *gpio_base; /* GPIO IO base */ |
| 106 | struct resource *pm_base; /* Power Mangagment IO base */ | 92 | struct resource *pm_base; /* Power Mangagment IO base */ |
| @@ -112,8 +98,7 @@ static struct { | |||
| 112 | 98 | ||
| 113 | static int modparam_gpiobase = -1; /* dynamic */ | 99 | static int modparam_gpiobase = -1; /* dynamic */ |
| 114 | module_param_named(gpiobase, modparam_gpiobase, int, 0444); | 100 | module_param_named(gpiobase, modparam_gpiobase, int, 0444); |
| 115 | MODULE_PARM_DESC(gpiobase, "The GPIO number base. -1 means dynamic, " | 101 | MODULE_PARM_DESC(gpiobase, "The GPIO number base. -1 means dynamic, which is the default."); |
| 116 | "which is the default."); | ||
| 117 | 102 | ||
| 118 | static int ichx_write_bit(int reg, unsigned nr, int val, int verify) | 103 | static int ichx_write_bit(int reg, unsigned nr, int val, int verify) |
| 119 | { | 104 | { |
| @@ -121,7 +106,6 @@ static int ichx_write_bit(int reg, unsigned nr, int val, int verify) | |||
| 121 | u32 data, tmp; | 106 | u32 data, tmp; |
| 122 | int reg_nr = nr / 32; | 107 | int reg_nr = nr / 32; |
| 123 | int bit = nr & 0x1f; | 108 | int bit = nr & 0x1f; |
| 124 | int ret = 0; | ||
| 125 | 109 | ||
| 126 | spin_lock_irqsave(&ichx_priv.lock, flags); | 110 | spin_lock_irqsave(&ichx_priv.lock, flags); |
| 127 | 111 | ||
| @@ -142,12 +126,10 @@ static int ichx_write_bit(int reg, unsigned nr, int val, int verify) | |||
| 142 | 126 | ||
| 143 | tmp = ICHX_READ(ichx_priv.desc->regs[reg][reg_nr], | 127 | tmp = ICHX_READ(ichx_priv.desc->regs[reg][reg_nr], |
| 144 | ichx_priv.gpio_base); | 128 | ichx_priv.gpio_base); |
| 145 | if (verify && data != tmp) | ||
| 146 | ret = -EPERM; | ||
| 147 | 129 | ||
| 148 | spin_unlock_irqrestore(&ichx_priv.lock, flags); | 130 | spin_unlock_irqrestore(&ichx_priv.lock, flags); |
| 149 | 131 | ||
| 150 | return ret; | 132 | return (verify && data != tmp) ? -EPERM : 0; |
| 151 | } | 133 | } |
| 152 | 134 | ||
| 153 | static int ichx_read_bit(int reg, unsigned nr) | 135 | static int ichx_read_bit(int reg, unsigned nr) |
| @@ -186,10 +168,7 @@ static int ichx_gpio_direction_input(struct gpio_chip *gpio, unsigned nr) | |||
| 186 | * Try setting pin as an input and verify it worked since many pins | 168 | * Try setting pin as an input and verify it worked since many pins |
| 187 | * are output-only. | 169 | * are output-only. |
| 188 | */ | 170 | */ |
| 189 | if (ichx_write_bit(GPIO_IO_SEL, nr, 1, 1)) | 171 | return ichx_write_bit(GPIO_IO_SEL, nr, 1, 1); |
| 190 | return -EINVAL; | ||
| 191 | |||
| 192 | return 0; | ||
| 193 | } | 172 | } |
| 194 | 173 | ||
| 195 | static int ichx_gpio_direction_output(struct gpio_chip *gpio, unsigned nr, | 174 | static int ichx_gpio_direction_output(struct gpio_chip *gpio, unsigned nr, |
| @@ -206,10 +185,7 @@ static int ichx_gpio_direction_output(struct gpio_chip *gpio, unsigned nr, | |||
| 206 | * Try setting pin as an output and verify it worked since many pins | 185 | * Try setting pin as an output and verify it worked since many pins |
| 207 | * are input-only. | 186 | * are input-only. |
| 208 | */ | 187 | */ |
| 209 | if (ichx_write_bit(GPIO_IO_SEL, nr, 0, 1)) | 188 | return ichx_write_bit(GPIO_IO_SEL, nr, 0, 1); |
| 210 | return -EINVAL; | ||
| 211 | |||
| 212 | return 0; | ||
| 213 | } | 189 | } |
| 214 | 190 | ||
| 215 | static int ichx_gpio_get(struct gpio_chip *chip, unsigned nr) | 191 | static int ichx_gpio_get(struct gpio_chip *chip, unsigned nr) |
| @@ -284,7 +260,7 @@ static void ichx_gpiolib_setup(struct gpio_chip *chip) | |||
| 284 | { | 260 | { |
| 285 | chip->owner = THIS_MODULE; | 261 | chip->owner = THIS_MODULE; |
| 286 | chip->label = DRV_NAME; | 262 | chip->label = DRV_NAME; |
| 287 | chip->parent = &ichx_priv.dev->dev; | 263 | chip->parent = ichx_priv.dev; |
| 288 | 264 | ||
| 289 | /* Allow chip-specific overrides of request()/get() */ | 265 | /* Allow chip-specific overrides of request()/get() */ |
| 290 | chip->request = ichx_priv.desc->request ? | 266 | chip->request = ichx_priv.desc->request ? |
| @@ -407,15 +383,14 @@ static int ichx_gpio_request_regions(struct device *dev, | |||
| 407 | 383 | ||
| 408 | static int ichx_gpio_probe(struct platform_device *pdev) | 384 | static int ichx_gpio_probe(struct platform_device *pdev) |
| 409 | { | 385 | { |
| 386 | struct device *dev = &pdev->dev; | ||
| 387 | struct lpc_ich_info *ich_info = dev_get_platdata(dev); | ||
| 410 | struct resource *res_base, *res_pm; | 388 | struct resource *res_base, *res_pm; |
| 411 | int err; | 389 | int err; |
| 412 | struct lpc_ich_info *ich_info = dev_get_platdata(&pdev->dev); | ||
| 413 | 390 | ||
| 414 | if (!ich_info) | 391 | if (!ich_info) |
| 415 | return -ENODEV; | 392 | return -ENODEV; |
| 416 | 393 | ||
| 417 | ichx_priv.dev = pdev; | ||
| 418 | |||
| 419 | switch (ich_info->gpio_version) { | 394 | switch (ich_info->gpio_version) { |
| 420 | case ICH_I3100_GPIO: | 395 | case ICH_I3100_GPIO: |
| 421 | ichx_priv.desc = &i3100_desc; | 396 | ichx_priv.desc = &i3100_desc; |
| @@ -445,19 +420,21 @@ static int ichx_gpio_probe(struct platform_device *pdev) | |||
| 445 | return -ENODEV; | 420 | return -ENODEV; |
| 446 | } | 421 | } |
| 447 | 422 | ||
| 423 | ichx_priv.dev = dev; | ||
| 448 | spin_lock_init(&ichx_priv.lock); | 424 | spin_lock_init(&ichx_priv.lock); |
| 425 | |||
| 449 | res_base = platform_get_resource(pdev, IORESOURCE_IO, ICH_RES_GPIO); | 426 | res_base = platform_get_resource(pdev, IORESOURCE_IO, ICH_RES_GPIO); |
| 450 | ichx_priv.use_gpio = ich_info->use_gpio; | 427 | err = ichx_gpio_request_regions(dev, res_base, pdev->name, |
| 451 | err = ichx_gpio_request_regions(&pdev->dev, res_base, pdev->name, | 428 | ich_info->use_gpio); |
| 452 | ichx_priv.use_gpio); | ||
| 453 | if (err) | 429 | if (err) |
| 454 | return err; | 430 | return err; |
| 455 | 431 | ||
| 456 | ichx_priv.gpio_base = res_base; | 432 | ichx_priv.gpio_base = res_base; |
| 433 | ichx_priv.use_gpio = ich_info->use_gpio; | ||
| 457 | 434 | ||
| 458 | /* | 435 | /* |
| 459 | * If necessary, determine the I/O address of ACPI/power management | 436 | * If necessary, determine the I/O address of ACPI/power management |
| 460 | * registers which are needed to read the the GPE0 register for GPI pins | 437 | * registers which are needed to read the GPE0 register for GPI pins |
| 461 | * 0 - 15 on some chipsets. | 438 | * 0 - 15 on some chipsets. |
| 462 | */ | 439 | */ |
| 463 | if (!ichx_priv.desc->uses_gpe0) | 440 | if (!ichx_priv.desc->uses_gpe0) |
| @@ -465,13 +442,13 @@ static int ichx_gpio_probe(struct platform_device *pdev) | |||
| 465 | 442 | ||
| 466 | res_pm = platform_get_resource(pdev, IORESOURCE_IO, ICH_RES_GPE0); | 443 | res_pm = platform_get_resource(pdev, IORESOURCE_IO, ICH_RES_GPE0); |
| 467 | if (!res_pm) { | 444 | if (!res_pm) { |
| 468 | pr_warn("ACPI BAR is unavailable, GPI 0 - 15 unavailable\n"); | 445 | dev_warn(dev, "ACPI BAR is unavailable, GPI 0 - 15 unavailable\n"); |
| 469 | goto init; | 446 | goto init; |
| 470 | } | 447 | } |
| 471 | 448 | ||
| 472 | if (!devm_request_region(&pdev->dev, res_pm->start, | 449 | if (!devm_request_region(dev, res_pm->start, resource_size(res_pm), |
| 473 | resource_size(res_pm), pdev->name)) { | 450 | pdev->name)) { |
| 474 | pr_warn("ACPI BAR is busy, GPI 0 - 15 unavailable\n"); | 451 | dev_warn(dev, "ACPI BAR is busy, GPI 0 - 15 unavailable\n"); |
| 475 | goto init; | 452 | goto init; |
| 476 | } | 453 | } |
| 477 | 454 | ||
| @@ -481,12 +458,12 @@ init: | |||
| 481 | ichx_gpiolib_setup(&ichx_priv.chip); | 458 | ichx_gpiolib_setup(&ichx_priv.chip); |
| 482 | err = gpiochip_add_data(&ichx_priv.chip, NULL); | 459 | err = gpiochip_add_data(&ichx_priv.chip, NULL); |
| 483 | if (err) { | 460 | if (err) { |
| 484 | pr_err("Failed to register GPIOs\n"); | 461 | dev_err(dev, "Failed to register GPIOs\n"); |
| 485 | return err; | 462 | return err; |
| 486 | } | 463 | } |
| 487 | 464 | ||
| 488 | pr_info("GPIO from %d to %d on %s\n", ichx_priv.chip.base, | 465 | dev_info(dev, "GPIO from %d to %d\n", ichx_priv.chip.base, |
| 489 | ichx_priv.chip.base + ichx_priv.chip.ngpio - 1, DRV_NAME); | 466 | ichx_priv.chip.base + ichx_priv.chip.ngpio - 1); |
| 490 | 467 | ||
| 491 | return 0; | 468 | return 0; |
| 492 | } | 469 | } |
diff --git a/drivers/gpio/gpio-intel-mid.c b/drivers/gpio/gpio-intel-mid.c index 028d64c2cb1e..4e803baf980e 100644 --- a/drivers/gpio/gpio-intel-mid.c +++ b/drivers/gpio/gpio-intel-mid.c | |||
| @@ -1,16 +1,8 @@ | |||
| 1 | // SPDX-License-Identifier: GPL-2.0 | ||
| 1 | /* | 2 | /* |
| 2 | * Intel MID GPIO driver | 3 | * Intel MID GPIO driver |
| 3 | * | 4 | * |
| 4 | * Copyright (c) 2008-2014,2016 Intel Corporation. | 5 | * Copyright (c) 2008-2014,2016 Intel Corporation. |
| 5 | * | ||
| 6 | * This program is free software; you can redistribute it and/or modify | ||
| 7 | * it under the terms of the GNU General Public License version 2 as | ||
| 8 | * published by the Free Software Foundation. | ||
| 9 | * | ||
| 10 | * This program is distributed in the hope that it will be useful, | ||
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 13 | * GNU General Public License for more details. | ||
| 14 | */ | 6 | */ |
| 15 | 7 | ||
| 16 | /* Supports: | 8 | /* Supports: |
| @@ -20,12 +12,11 @@ | |||
| 20 | */ | 12 | */ |
| 21 | 13 | ||
| 22 | #include <linux/delay.h> | 14 | #include <linux/delay.h> |
| 15 | #include <linux/gpio/driver.h> | ||
| 23 | #include <linux/init.h> | 16 | #include <linux/init.h> |
| 24 | #include <linux/interrupt.h> | 17 | #include <linux/interrupt.h> |
| 25 | #include <linux/io.h> | 18 | #include <linux/io.h> |
| 26 | #include <linux/gpio/driver.h> | ||
| 27 | #include <linux/kernel.h> | 19 | #include <linux/kernel.h> |
| 28 | #include <linux/module.h> | ||
| 29 | #include <linux/pci.h> | 20 | #include <linux/pci.h> |
| 30 | #include <linux/platform_device.h> | 21 | #include <linux/platform_device.h> |
| 31 | #include <linux/pm_runtime.h> | 22 | #include <linux/pm_runtime.h> |
| @@ -273,9 +264,8 @@ static const struct pci_device_id intel_gpio_ids[] = { | |||
| 273 | PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x08f7), | 264 | PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x08f7), |
| 274 | .driver_data = (kernel_ulong_t)&gpio_cloverview_core, | 265 | .driver_data = (kernel_ulong_t)&gpio_cloverview_core, |
| 275 | }, | 266 | }, |
| 276 | { 0 } | 267 | { } |
| 277 | }; | 268 | }; |
| 278 | MODULE_DEVICE_TABLE(pci, intel_gpio_ids); | ||
| 279 | 269 | ||
| 280 | static void intel_mid_irq_handler(struct irq_desc *desc) | 270 | static void intel_mid_irq_handler(struct irq_desc *desc) |
| 281 | { | 271 | { |
diff --git a/drivers/gpio/gpio-ks8695.c b/drivers/gpio/gpio-ks8695.c index 55d562e1278e..d6d6140ffc40 100644 --- a/drivers/gpio/gpio-ks8695.c +++ b/drivers/gpio/gpio-ks8695.c | |||
| @@ -282,22 +282,13 @@ static int ks8695_gpio_show(struct seq_file *s, void *unused) | |||
| 282 | return 0; | 282 | return 0; |
| 283 | } | 283 | } |
| 284 | 284 | ||
| 285 | static int ks8695_gpio_open(struct inode *inode, struct file *file) | 285 | DEFINE_SHOW_ATTRIBUTE(ks8695_gpio); |
| 286 | { | ||
| 287 | return single_open(file, ks8695_gpio_show, NULL); | ||
| 288 | } | ||
| 289 | |||
| 290 | static const struct file_operations ks8695_gpio_operations = { | ||
| 291 | .open = ks8695_gpio_open, | ||
| 292 | .read = seq_read, | ||
| 293 | .llseek = seq_lseek, | ||
| 294 | .release = single_release, | ||
| 295 | }; | ||
| 296 | 286 | ||
| 297 | static int __init ks8695_gpio_debugfs_init(void) | 287 | static int __init ks8695_gpio_debugfs_init(void) |
| 298 | { | 288 | { |
| 299 | /* /sys/kernel/debug/ks8695_gpio */ | 289 | /* /sys/kernel/debug/ks8695_gpio */ |
| 300 | (void) debugfs_create_file("ks8695_gpio", S_IFREG | S_IRUGO, NULL, NULL, &ks8695_gpio_operations); | 290 | debugfs_create_file("ks8695_gpio", S_IFREG | S_IRUGO, NULL, NULL, |
| 291 | &ks8695_gpio_fops); | ||
| 301 | return 0; | 292 | return 0; |
| 302 | } | 293 | } |
| 303 | postcore_initcall(ks8695_gpio_debugfs_init); | 294 | postcore_initcall(ks8695_gpio_debugfs_init); |
diff --git a/drivers/gpio/gpio-lpc18xx.c b/drivers/gpio/gpio-lpc18xx.c index f12e02e1016d..d441dbaed7a3 100644 --- a/drivers/gpio/gpio-lpc18xx.c +++ b/drivers/gpio/gpio-lpc18xx.c | |||
| @@ -1,20 +1,21 @@ | |||
| 1 | // SPDX-License-Identifier: GPL-2.0 | ||
| 1 | /* | 2 | /* |
| 2 | * GPIO driver for NXP LPC18xx/43xx. | 3 | * GPIO driver for NXP LPC18xx/43xx. |
| 3 | * | 4 | * |
| 5 | * Copyright (C) 2018 Vladimir Zapolskiy <vz@mleia.com> | ||
| 4 | * Copyright (C) 2015 Joachim Eastwood <manabian@gmail.com> | 6 | * Copyright (C) 2015 Joachim Eastwood <manabian@gmail.com> |
| 5 | * | 7 | * |
| 6 | * This program is free software; you can redistribute it and/or modify | ||
| 7 | * it under the terms of the GNU General Public License version 2 as | ||
| 8 | * published by the Free Software Foundation. | ||
| 9 | * | ||
| 10 | */ | 8 | */ |
| 11 | 9 | ||
| 12 | #include <linux/clk.h> | 10 | #include <linux/clk.h> |
| 13 | #include <linux/gpio/driver.h> | 11 | #include <linux/gpio/driver.h> |
| 14 | #include <linux/io.h> | 12 | #include <linux/io.h> |
| 13 | #include <linux/irqdomain.h> | ||
| 15 | #include <linux/module.h> | 14 | #include <linux/module.h> |
| 16 | #include <linux/of.h> | 15 | #include <linux/of.h> |
| 16 | #include <linux/of_address.h> | ||
| 17 | #include <linux/of_gpio.h> | 17 | #include <linux/of_gpio.h> |
| 18 | #include <linux/of_irq.h> | ||
| 18 | #include <linux/pinctrl/consumer.h> | 19 | #include <linux/pinctrl/consumer.h> |
| 19 | #include <linux/platform_device.h> | 20 | #include <linux/platform_device.h> |
| 20 | 21 | ||
| @@ -24,13 +25,246 @@ | |||
| 24 | #define LPC18XX_MAX_PORTS 8 | 25 | #define LPC18XX_MAX_PORTS 8 |
| 25 | #define LPC18XX_PINS_PER_PORT 32 | 26 | #define LPC18XX_PINS_PER_PORT 32 |
| 26 | 27 | ||
| 28 | /* LPC18xx GPIO pin interrupt controller register offsets */ | ||
| 29 | #define LPC18XX_GPIO_PIN_IC_ISEL 0x00 | ||
| 30 | #define LPC18XX_GPIO_PIN_IC_IENR 0x04 | ||
| 31 | #define LPC18XX_GPIO_PIN_IC_SIENR 0x08 | ||
| 32 | #define LPC18XX_GPIO_PIN_IC_CIENR 0x0c | ||
| 33 | #define LPC18XX_GPIO_PIN_IC_IENF 0x10 | ||
| 34 | #define LPC18XX_GPIO_PIN_IC_SIENF 0x14 | ||
| 35 | #define LPC18XX_GPIO_PIN_IC_CIENF 0x18 | ||
| 36 | #define LPC18XX_GPIO_PIN_IC_RISE 0x1c | ||
| 37 | #define LPC18XX_GPIO_PIN_IC_FALL 0x20 | ||
| 38 | #define LPC18XX_GPIO_PIN_IC_IST 0x24 | ||
| 39 | |||
| 40 | #define NR_LPC18XX_GPIO_PIN_IC_IRQS 8 | ||
| 41 | |||
| 42 | struct lpc18xx_gpio_pin_ic { | ||
| 43 | void __iomem *base; | ||
| 44 | struct irq_domain *domain; | ||
| 45 | struct raw_spinlock lock; | ||
| 46 | }; | ||
| 47 | |||
| 27 | struct lpc18xx_gpio_chip { | 48 | struct lpc18xx_gpio_chip { |
| 28 | struct gpio_chip gpio; | 49 | struct gpio_chip gpio; |
| 29 | void __iomem *base; | 50 | void __iomem *base; |
| 30 | struct clk *clk; | 51 | struct clk *clk; |
| 52 | struct lpc18xx_gpio_pin_ic *pin_ic; | ||
| 31 | spinlock_t lock; | 53 | spinlock_t lock; |
| 32 | }; | 54 | }; |
| 33 | 55 | ||
| 56 | static inline void lpc18xx_gpio_pin_ic_isel(struct lpc18xx_gpio_pin_ic *ic, | ||
| 57 | u32 pin, bool set) | ||
| 58 | { | ||
| 59 | u32 val = readl_relaxed(ic->base + LPC18XX_GPIO_PIN_IC_ISEL); | ||
| 60 | |||
| 61 | if (set) | ||
| 62 | val &= ~BIT(pin); | ||
| 63 | else | ||
| 64 | val |= BIT(pin); | ||
| 65 | |||
| 66 | writel_relaxed(val, ic->base + LPC18XX_GPIO_PIN_IC_ISEL); | ||
| 67 | } | ||
| 68 | |||
| 69 | static inline void lpc18xx_gpio_pin_ic_set(struct lpc18xx_gpio_pin_ic *ic, | ||
| 70 | u32 pin, u32 reg) | ||
| 71 | { | ||
| 72 | writel_relaxed(BIT(pin), ic->base + reg); | ||
| 73 | } | ||
| 74 | |||
| 75 | static void lpc18xx_gpio_pin_ic_mask(struct irq_data *d) | ||
| 76 | { | ||
| 77 | struct lpc18xx_gpio_pin_ic *ic = d->chip_data; | ||
| 78 | u32 type = irqd_get_trigger_type(d); | ||
| 79 | |||
| 80 | raw_spin_lock(&ic->lock); | ||
| 81 | |||
| 82 | if (type & IRQ_TYPE_LEVEL_MASK || type & IRQ_TYPE_EDGE_RISING) | ||
| 83 | lpc18xx_gpio_pin_ic_set(ic, d->hwirq, | ||
| 84 | LPC18XX_GPIO_PIN_IC_CIENR); | ||
| 85 | |||
| 86 | if (type & IRQ_TYPE_EDGE_FALLING) | ||
| 87 | lpc18xx_gpio_pin_ic_set(ic, d->hwirq, | ||
| 88 | LPC18XX_GPIO_PIN_IC_CIENF); | ||
| 89 | |||
| 90 | raw_spin_unlock(&ic->lock); | ||
| 91 | |||
| 92 | irq_chip_mask_parent(d); | ||
| 93 | } | ||
| 94 | |||
| 95 | static void lpc18xx_gpio_pin_ic_unmask(struct irq_data *d) | ||
| 96 | { | ||
| 97 | struct lpc18xx_gpio_pin_ic *ic = d->chip_data; | ||
| 98 | u32 type = irqd_get_trigger_type(d); | ||
| 99 | |||
| 100 | raw_spin_lock(&ic->lock); | ||
| 101 | |||
| 102 | if (type & IRQ_TYPE_LEVEL_MASK || type & IRQ_TYPE_EDGE_RISING) | ||
| 103 | lpc18xx_gpio_pin_ic_set(ic, d->hwirq, | ||
| 104 | LPC18XX_GPIO_PIN_IC_SIENR); | ||
| 105 | |||
| 106 | if (type & IRQ_TYPE_EDGE_FALLING) | ||
| 107 | lpc18xx_gpio_pin_ic_set(ic, d->hwirq, | ||
| 108 | LPC18XX_GPIO_PIN_IC_SIENF); | ||
| 109 | |||
| 110 | raw_spin_unlock(&ic->lock); | ||
| 111 | |||
| 112 | irq_chip_unmask_parent(d); | ||
| 113 | } | ||
| 114 | |||
| 115 | static void lpc18xx_gpio_pin_ic_eoi(struct irq_data *d) | ||
| 116 | { | ||
| 117 | struct lpc18xx_gpio_pin_ic *ic = d->chip_data; | ||
| 118 | u32 type = irqd_get_trigger_type(d); | ||
| 119 | |||
| 120 | raw_spin_lock(&ic->lock); | ||
| 121 | |||
| 122 | if (type & IRQ_TYPE_EDGE_BOTH) | ||
| 123 | lpc18xx_gpio_pin_ic_set(ic, d->hwirq, | ||
| 124 | LPC18XX_GPIO_PIN_IC_IST); | ||
| 125 | |||
| 126 | raw_spin_unlock(&ic->lock); | ||
| 127 | |||
| 128 | irq_chip_eoi_parent(d); | ||
| 129 | } | ||
| 130 | |||
| 131 | static int lpc18xx_gpio_pin_ic_set_type(struct irq_data *d, unsigned int type) | ||
| 132 | { | ||
| 133 | struct lpc18xx_gpio_pin_ic *ic = d->chip_data; | ||
| 134 | |||
| 135 | raw_spin_lock(&ic->lock); | ||
| 136 | |||
| 137 | if (type & IRQ_TYPE_LEVEL_HIGH) { | ||
| 138 | lpc18xx_gpio_pin_ic_isel(ic, d->hwirq, true); | ||
| 139 | lpc18xx_gpio_pin_ic_set(ic, d->hwirq, | ||
| 140 | LPC18XX_GPIO_PIN_IC_SIENF); | ||
| 141 | } else if (type & IRQ_TYPE_LEVEL_LOW) { | ||
| 142 | lpc18xx_gpio_pin_ic_isel(ic, d->hwirq, true); | ||
| 143 | lpc18xx_gpio_pin_ic_set(ic, d->hwirq, | ||
| 144 | LPC18XX_GPIO_PIN_IC_CIENF); | ||
| 145 | } else { | ||
| 146 | lpc18xx_gpio_pin_ic_isel(ic, d->hwirq, false); | ||
| 147 | } | ||
| 148 | |||
| 149 | raw_spin_unlock(&ic->lock); | ||
| 150 | |||
| 151 | return 0; | ||
| 152 | } | ||
| 153 | |||
| 154 | static struct irq_chip lpc18xx_gpio_pin_ic = { | ||
| 155 | .name = "LPC18xx GPIO pin", | ||
| 156 | .irq_mask = lpc18xx_gpio_pin_ic_mask, | ||
| 157 | .irq_unmask = lpc18xx_gpio_pin_ic_unmask, | ||
| 158 | .irq_eoi = lpc18xx_gpio_pin_ic_eoi, | ||
| 159 | .irq_set_type = lpc18xx_gpio_pin_ic_set_type, | ||
| 160 | .flags = IRQCHIP_SET_TYPE_MASKED, | ||
| 161 | }; | ||
| 162 | |||
| 163 | static int lpc18xx_gpio_pin_ic_domain_alloc(struct irq_domain *domain, | ||
| 164 | unsigned int virq, | ||
| 165 | unsigned int nr_irqs, void *data) | ||
| 166 | { | ||
| 167 | struct irq_fwspec parent_fwspec, *fwspec = data; | ||
| 168 | struct lpc18xx_gpio_pin_ic *ic = domain->host_data; | ||
| 169 | irq_hw_number_t hwirq; | ||
| 170 | int ret; | ||
| 171 | |||
| 172 | if (nr_irqs != 1) | ||
| 173 | return -EINVAL; | ||
| 174 | |||
| 175 | hwirq = fwspec->param[0]; | ||
| 176 | if (hwirq >= NR_LPC18XX_GPIO_PIN_IC_IRQS) | ||
| 177 | return -EINVAL; | ||
| 178 | |||
| 179 | /* | ||
| 180 | * All LPC18xx/LPC43xx GPIO pin hardware interrupts are translated | ||
| 181 | * into edge interrupts 32...39 on parent Cortex-M3/M4 NVIC | ||
| 182 | */ | ||
| 183 | parent_fwspec.fwnode = domain->parent->fwnode; | ||
| 184 | parent_fwspec.param_count = 1; | ||
| 185 | parent_fwspec.param[0] = hwirq + 32; | ||
| 186 | |||
| 187 | ret = irq_domain_alloc_irqs_parent(domain, virq, 1, &parent_fwspec); | ||
| 188 | if (ret < 0) { | ||
| 189 | pr_err("failed to allocate parent irq %u: %d\n", | ||
| 190 | parent_fwspec.param[0], ret); | ||
| 191 | return ret; | ||
| 192 | } | ||
| 193 | |||
| 194 | return irq_domain_set_hwirq_and_chip(domain, virq, hwirq, | ||
| 195 | &lpc18xx_gpio_pin_ic, ic); | ||
| 196 | } | ||
| 197 | |||
| 198 | static const struct irq_domain_ops lpc18xx_gpio_pin_ic_domain_ops = { | ||
| 199 | .alloc = lpc18xx_gpio_pin_ic_domain_alloc, | ||
| 200 | .xlate = irq_domain_xlate_twocell, | ||
| 201 | .free = irq_domain_free_irqs_common, | ||
| 202 | }; | ||
| 203 | |||
| 204 | static int lpc18xx_gpio_pin_ic_probe(struct lpc18xx_gpio_chip *gc) | ||
| 205 | { | ||
| 206 | struct device *dev = gc->gpio.parent; | ||
| 207 | struct irq_domain *parent_domain; | ||
| 208 | struct device_node *parent_node; | ||
| 209 | struct lpc18xx_gpio_pin_ic *ic; | ||
| 210 | struct resource res; | ||
| 211 | int ret, index; | ||
| 212 | |||
| 213 | parent_node = of_irq_find_parent(dev->of_node); | ||
| 214 | if (!parent_node) | ||
| 215 | return -ENXIO; | ||
| 216 | |||
| 217 | parent_domain = irq_find_host(parent_node); | ||
| 218 | of_node_put(parent_node); | ||
| 219 | if (!parent_domain) | ||
| 220 | return -ENXIO; | ||
| 221 | |||
| 222 | ic = devm_kzalloc(dev, sizeof(*ic), GFP_KERNEL); | ||
| 223 | if (!ic) | ||
| 224 | return -ENOMEM; | ||
| 225 | |||
| 226 | index = of_property_match_string(dev->of_node, "reg-names", | ||
| 227 | "gpio-pin-ic"); | ||
| 228 | if (index < 0) { | ||
| 229 | ret = -ENODEV; | ||
| 230 | goto free_ic; | ||
| 231 | } | ||
| 232 | |||
| 233 | ret = of_address_to_resource(dev->of_node, index, &res); | ||
| 234 | if (ret < 0) | ||
| 235 | goto free_ic; | ||
| 236 | |||
| 237 | ic->base = devm_ioremap_resource(dev, &res); | ||
| 238 | if (IS_ERR(ic->base)) { | ||
| 239 | ret = PTR_ERR(ic->base); | ||
| 240 | goto free_ic; | ||
| 241 | } | ||
| 242 | |||
| 243 | raw_spin_lock_init(&ic->lock); | ||
| 244 | |||
| 245 | ic->domain = irq_domain_add_hierarchy(parent_domain, 0, | ||
| 246 | NR_LPC18XX_GPIO_PIN_IC_IRQS, | ||
| 247 | dev->of_node, | ||
| 248 | &lpc18xx_gpio_pin_ic_domain_ops, | ||
| 249 | ic); | ||
| 250 | if (!ic->domain) { | ||
| 251 | pr_err("unable to add irq domain\n"); | ||
| 252 | ret = -ENODEV; | ||
| 253 | goto free_iomap; | ||
| 254 | } | ||
| 255 | |||
| 256 | gc->pin_ic = ic; | ||
| 257 | |||
| 258 | return 0; | ||
| 259 | |||
| 260 | free_iomap: | ||
| 261 | devm_iounmap(dev, ic->base); | ||
| 262 | free_ic: | ||
| 263 | devm_kfree(dev, ic); | ||
| 264 | |||
| 265 | return ret; | ||
| 266 | } | ||
| 267 | |||
| 34 | static void lpc18xx_gpio_set(struct gpio_chip *chip, unsigned offset, int value) | 268 | static void lpc18xx_gpio_set(struct gpio_chip *chip, unsigned offset, int value) |
| 35 | { | 269 | { |
| 36 | struct lpc18xx_gpio_chip *gc = gpiochip_get_data(chip); | 270 | struct lpc18xx_gpio_chip *gc = gpiochip_get_data(chip); |
| @@ -92,45 +326,62 @@ static const struct gpio_chip lpc18xx_chip = { | |||
| 92 | 326 | ||
| 93 | static int lpc18xx_gpio_probe(struct platform_device *pdev) | 327 | static int lpc18xx_gpio_probe(struct platform_device *pdev) |
| 94 | { | 328 | { |
| 329 | struct device *dev = &pdev->dev; | ||
| 95 | struct lpc18xx_gpio_chip *gc; | 330 | struct lpc18xx_gpio_chip *gc; |
| 96 | struct resource *res; | 331 | int index, ret; |
| 97 | int ret; | ||
| 98 | 332 | ||
| 99 | gc = devm_kzalloc(&pdev->dev, sizeof(*gc), GFP_KERNEL); | 333 | gc = devm_kzalloc(dev, sizeof(*gc), GFP_KERNEL); |
| 100 | if (!gc) | 334 | if (!gc) |
| 101 | return -ENOMEM; | 335 | return -ENOMEM; |
| 102 | 336 | ||
| 103 | gc->gpio = lpc18xx_chip; | 337 | gc->gpio = lpc18xx_chip; |
| 104 | platform_set_drvdata(pdev, gc); | 338 | platform_set_drvdata(pdev, gc); |
| 105 | 339 | ||
| 106 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 340 | index = of_property_match_string(dev->of_node, "reg-names", "gpio"); |
| 107 | gc->base = devm_ioremap_resource(&pdev->dev, res); | 341 | if (index < 0) { |
| 342 | /* To support backward compatibility take the first resource */ | ||
| 343 | struct resource *res; | ||
| 344 | |||
| 345 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
| 346 | gc->base = devm_ioremap_resource(dev, res); | ||
| 347 | } else { | ||
| 348 | struct resource res; | ||
| 349 | |||
| 350 | ret = of_address_to_resource(dev->of_node, index, &res); | ||
| 351 | if (ret < 0) | ||
| 352 | return ret; | ||
| 353 | |||
| 354 | gc->base = devm_ioremap_resource(dev, &res); | ||
| 355 | } | ||
| 108 | if (IS_ERR(gc->base)) | 356 | if (IS_ERR(gc->base)) |
| 109 | return PTR_ERR(gc->base); | 357 | return PTR_ERR(gc->base); |
| 110 | 358 | ||
| 111 | gc->clk = devm_clk_get(&pdev->dev, NULL); | 359 | gc->clk = devm_clk_get(dev, NULL); |
| 112 | if (IS_ERR(gc->clk)) { | 360 | if (IS_ERR(gc->clk)) { |
| 113 | dev_err(&pdev->dev, "input clock not found\n"); | 361 | dev_err(dev, "input clock not found\n"); |
| 114 | return PTR_ERR(gc->clk); | 362 | return PTR_ERR(gc->clk); |
| 115 | } | 363 | } |
| 116 | 364 | ||
| 117 | ret = clk_prepare_enable(gc->clk); | 365 | ret = clk_prepare_enable(gc->clk); |
| 118 | if (ret) { | 366 | if (ret) { |
| 119 | dev_err(&pdev->dev, "unable to enable clock\n"); | 367 | dev_err(dev, "unable to enable clock\n"); |
| 120 | return ret; | 368 | return ret; |
| 121 | } | 369 | } |
| 122 | 370 | ||
| 123 | spin_lock_init(&gc->lock); | 371 | spin_lock_init(&gc->lock); |
| 124 | 372 | ||
| 125 | gc->gpio.parent = &pdev->dev; | 373 | gc->gpio.parent = dev; |
| 126 | 374 | ||
| 127 | ret = gpiochip_add_data(&gc->gpio, gc); | 375 | ret = devm_gpiochip_add_data(dev, &gc->gpio, gc); |
| 128 | if (ret) { | 376 | if (ret) { |
| 129 | dev_err(&pdev->dev, "failed to add gpio chip\n"); | 377 | dev_err(dev, "failed to add gpio chip\n"); |
| 130 | clk_disable_unprepare(gc->clk); | 378 | clk_disable_unprepare(gc->clk); |
| 131 | return ret; | 379 | return ret; |
| 132 | } | 380 | } |
| 133 | 381 | ||
| 382 | /* On error GPIO pin interrupt controller just won't be registered */ | ||
| 383 | lpc18xx_gpio_pin_ic_probe(gc); | ||
| 384 | |||
| 134 | return 0; | 385 | return 0; |
| 135 | } | 386 | } |
| 136 | 387 | ||
| @@ -138,7 +389,9 @@ static int lpc18xx_gpio_remove(struct platform_device *pdev) | |||
| 138 | { | 389 | { |
| 139 | struct lpc18xx_gpio_chip *gc = platform_get_drvdata(pdev); | 390 | struct lpc18xx_gpio_chip *gc = platform_get_drvdata(pdev); |
| 140 | 391 | ||
| 141 | gpiochip_remove(&gc->gpio); | 392 | if (gc->pin_ic) |
| 393 | irq_domain_remove(gc->pin_ic->domain); | ||
| 394 | |||
| 142 | clk_disable_unprepare(gc->clk); | 395 | clk_disable_unprepare(gc->clk); |
| 143 | 396 | ||
| 144 | return 0; | 397 | return 0; |
| @@ -161,5 +414,6 @@ static struct platform_driver lpc18xx_gpio_driver = { | |||
| 161 | module_platform_driver(lpc18xx_gpio_driver); | 414 | module_platform_driver(lpc18xx_gpio_driver); |
| 162 | 415 | ||
| 163 | MODULE_AUTHOR("Joachim Eastwood <manabian@gmail.com>"); | 416 | MODULE_AUTHOR("Joachim Eastwood <manabian@gmail.com>"); |
| 417 | MODULE_AUTHOR("Vladimir Zapolskiy <vz@mleia.com>"); | ||
| 164 | MODULE_DESCRIPTION("GPIO driver for LPC18xx/43xx"); | 418 | MODULE_DESCRIPTION("GPIO driver for LPC18xx/43xx"); |
| 165 | MODULE_LICENSE("GPL v2"); | 419 | MODULE_LICENSE("GPL v2"); |
diff --git a/drivers/gpio/gpio-lynxpoint.c b/drivers/gpio/gpio-lynxpoint.c index b5b5e500e72c..31b4a091ab60 100644 --- a/drivers/gpio/gpio-lynxpoint.c +++ b/drivers/gpio/gpio-lynxpoint.c | |||
| @@ -1,36 +1,22 @@ | |||
| 1 | // SPDX-License-Identifier: GPL-2.0 | ||
| 1 | /* | 2 | /* |
| 2 | * GPIO controller driver for Intel Lynxpoint PCH chipset> | 3 | * GPIO controller driver for Intel Lynxpoint PCH chipset> |
| 3 | * Copyright (c) 2012, Intel Corporation. | 4 | * Copyright (c) 2012, Intel Corporation. |
| 4 | * | 5 | * |
| 5 | * Author: Mathias Nyman <mathias.nyman@linux.intel.com> | 6 | * Author: Mathias Nyman <mathias.nyman@linux.intel.com> |
| 6 | * | ||
| 7 | * This program is free software; you can redistribute it and/or modify it | ||
| 8 | * under the terms and conditions of the GNU General Public License, | ||
| 9 | * version 2, as published by the Free Software Foundation. | ||
| 10 | * | ||
| 11 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
| 14 | * more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU General Public License along with | ||
| 17 | * this program; if not, write to the Free Software Foundation, Inc., | ||
| 18 | * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | ||
| 19 | * | ||
| 20 | */ | 7 | */ |
| 21 | 8 | ||
| 22 | #include <linux/kernel.h> | 9 | #include <linux/acpi.h> |
| 23 | #include <linux/module.h> | ||
| 24 | #include <linux/init.h> | ||
| 25 | #include <linux/types.h> | ||
| 26 | #include <linux/bitops.h> | 10 | #include <linux/bitops.h> |
| 27 | #include <linux/interrupt.h> | ||
| 28 | #include <linux/gpio/driver.h> | 11 | #include <linux/gpio/driver.h> |
| 29 | #include <linux/slab.h> | 12 | #include <linux/interrupt.h> |
| 30 | #include <linux/acpi.h> | 13 | #include <linux/io.h> |
| 14 | #include <linux/kernel.h> | ||
| 15 | #include <linux/module.h> | ||
| 31 | #include <linux/platform_device.h> | 16 | #include <linux/platform_device.h> |
| 32 | #include <linux/pm_runtime.h> | 17 | #include <linux/pm_runtime.h> |
| 33 | #include <linux/io.h> | 18 | #include <linux/slab.h> |
| 19 | #include <linux/types.h> | ||
| 34 | 20 | ||
| 35 | /* LynxPoint chipset has support for 94 gpio pins */ | 21 | /* LynxPoint chipset has support for 94 gpio pins */ |
| 36 | 22 | ||
| @@ -240,21 +226,23 @@ static void lp_gpio_irq_handler(struct irq_desc *desc) | |||
| 240 | struct gpio_chip *gc = irq_desc_get_handler_data(desc); | 226 | struct gpio_chip *gc = irq_desc_get_handler_data(desc); |
| 241 | struct lp_gpio *lg = gpiochip_get_data(gc); | 227 | struct lp_gpio *lg = gpiochip_get_data(gc); |
| 242 | struct irq_chip *chip = irq_data_get_irq_chip(data); | 228 | struct irq_chip *chip = irq_data_get_irq_chip(data); |
| 243 | u32 base, pin, mask; | ||
| 244 | unsigned long reg, ena, pending; | 229 | unsigned long reg, ena, pending; |
| 230 | u32 base, pin; | ||
| 245 | 231 | ||
| 246 | /* check from GPIO controller which pin triggered the interrupt */ | 232 | /* check from GPIO controller which pin triggered the interrupt */ |
| 247 | for (base = 0; base < lg->chip.ngpio; base += 32) { | 233 | for (base = 0; base < lg->chip.ngpio; base += 32) { |
| 248 | reg = lp_gpio_reg(&lg->chip, base, LP_INT_STAT); | 234 | reg = lp_gpio_reg(&lg->chip, base, LP_INT_STAT); |
| 249 | ena = lp_gpio_reg(&lg->chip, base, LP_INT_ENABLE); | 235 | ena = lp_gpio_reg(&lg->chip, base, LP_INT_ENABLE); |
| 250 | 236 | ||
| 251 | while ((pending = (inl(reg) & inl(ena)))) { | 237 | /* Only interrupts that are enabled */ |
| 238 | pending = inl(reg) & inl(ena); | ||
| 239 | |||
| 240 | for_each_set_bit(pin, &pending, 32) { | ||
| 252 | unsigned irq; | 241 | unsigned irq; |
| 253 | 242 | ||
| 254 | pin = __ffs(pending); | ||
| 255 | mask = BIT(pin); | ||
| 256 | /* Clear before handling so we don't lose an edge */ | 243 | /* Clear before handling so we don't lose an edge */ |
| 257 | outl(mask, reg); | 244 | outl(BIT(pin), reg); |
| 245 | |||
| 258 | irq = irq_find_mapping(lg->chip.irq.domain, base + pin); | 246 | irq = irq_find_mapping(lg->chip.irq.domain, base + pin); |
| 259 | generic_handle_irq(irq); | 247 | generic_handle_irq(irq); |
| 260 | } | 248 | } |
| @@ -408,8 +396,7 @@ static int lp_gpio_runtime_resume(struct device *dev) | |||
| 408 | 396 | ||
| 409 | static int lp_gpio_resume(struct device *dev) | 397 | static int lp_gpio_resume(struct device *dev) |
| 410 | { | 398 | { |
| 411 | struct platform_device *pdev = to_platform_device(dev); | 399 | struct lp_gpio *lg = dev_get_drvdata(dev); |
| 412 | struct lp_gpio *lg = platform_get_drvdata(pdev); | ||
| 413 | unsigned long reg; | 400 | unsigned long reg; |
| 414 | int i; | 401 | int i; |
| 415 | 402 | ||
| @@ -467,5 +454,5 @@ module_exit(lp_gpio_exit); | |||
| 467 | 454 | ||
| 468 | MODULE_AUTHOR("Mathias Nyman (Intel)"); | 455 | MODULE_AUTHOR("Mathias Nyman (Intel)"); |
| 469 | MODULE_DESCRIPTION("GPIO interface for Intel Lynxpoint"); | 456 | MODULE_DESCRIPTION("GPIO interface for Intel Lynxpoint"); |
| 470 | MODULE_LICENSE("GPL"); | 457 | MODULE_LICENSE("GPL v2"); |
| 471 | MODULE_ALIAS("platform:lp_gpio"); | 458 | MODULE_ALIAS("platform:lp_gpio"); |
diff --git a/drivers/gpio/gpio-merrifield.c b/drivers/gpio/gpio-merrifield.c index 97421bd4a60f..7c659fdaa6d5 100644 --- a/drivers/gpio/gpio-merrifield.c +++ b/drivers/gpio/gpio-merrifield.c | |||
| @@ -1,18 +1,14 @@ | |||
| 1 | // SPDX-License-Identifier: GPL-2.0 | ||
| 1 | /* | 2 | /* |
| 2 | * Intel Merrifield SoC GPIO driver | 3 | * Intel Merrifield SoC GPIO driver |
| 3 | * | 4 | * |
| 4 | * Copyright (c) 2016 Intel Corporation. | 5 | * Copyright (c) 2016 Intel Corporation. |
| 5 | * Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com> | 6 | * Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com> |
| 6 | * | ||
| 7 | * This program is free software; you can redistribute it and/or modify | ||
| 8 | * it under the terms of the GNU General Public License version 2 as | ||
| 9 | * published by the Free Software Foundation. | ||
| 10 | */ | 7 | */ |
| 11 | 8 | ||
| 12 | #include <linux/acpi.h> | 9 | #include <linux/acpi.h> |
| 13 | #include <linux/bitops.h> | 10 | #include <linux/bitops.h> |
| 14 | #include <linux/gpio/driver.h> | 11 | #include <linux/gpio/driver.h> |
| 15 | #include <linux/init.h> | ||
| 16 | #include <linux/interrupt.h> | 12 | #include <linux/interrupt.h> |
| 17 | #include <linux/io.h> | 13 | #include <linux/io.h> |
| 18 | #include <linux/module.h> | 14 | #include <linux/module.h> |
diff --git a/drivers/gpio/gpio-mt7621.c b/drivers/gpio/gpio-mt7621.c index d72af6f6cdbd..00e954f22bc9 100644 --- a/drivers/gpio/gpio-mt7621.c +++ b/drivers/gpio/gpio-mt7621.c | |||
| @@ -244,6 +244,8 @@ mediatek_gpio_bank_probe(struct device *dev, | |||
| 244 | rg->chip.of_xlate = mediatek_gpio_xlate; | 244 | rg->chip.of_xlate = mediatek_gpio_xlate; |
| 245 | rg->chip.label = devm_kasprintf(dev, GFP_KERNEL, "%s-bank%d", | 245 | rg->chip.label = devm_kasprintf(dev, GFP_KERNEL, "%s-bank%d", |
| 246 | dev_name(dev), bank); | 246 | dev_name(dev), bank); |
| 247 | if (!rg->chip.label) | ||
| 248 | return -ENOMEM; | ||
| 247 | 249 | ||
| 248 | ret = devm_gpiochip_add_data(dev, &rg->chip, mtk); | 250 | ret = devm_gpiochip_add_data(dev, &rg->chip, mtk); |
| 249 | if (ret < 0) { | 251 | if (ret < 0) { |
| @@ -295,6 +297,7 @@ mediatek_gpio_probe(struct platform_device *pdev) | |||
| 295 | struct device_node *np = dev->of_node; | 297 | struct device_node *np = dev->of_node; |
| 296 | struct mtk *mtk; | 298 | struct mtk *mtk; |
| 297 | int i; | 299 | int i; |
| 300 | int ret; | ||
| 298 | 301 | ||
| 299 | mtk = devm_kzalloc(dev, sizeof(*mtk), GFP_KERNEL); | 302 | mtk = devm_kzalloc(dev, sizeof(*mtk), GFP_KERNEL); |
| 300 | if (!mtk) | 303 | if (!mtk) |
| @@ -309,8 +312,11 @@ mediatek_gpio_probe(struct platform_device *pdev) | |||
| 309 | platform_set_drvdata(pdev, mtk); | 312 | platform_set_drvdata(pdev, mtk); |
| 310 | mediatek_gpio_irq_chip.name = dev_name(dev); | 313 | mediatek_gpio_irq_chip.name = dev_name(dev); |
| 311 | 314 | ||
| 312 | for (i = 0; i < MTK_BANK_CNT; i++) | 315 | for (i = 0; i < MTK_BANK_CNT; i++) { |
| 313 | mediatek_gpio_bank_probe(dev, np, i); | 316 | ret = mediatek_gpio_bank_probe(dev, np, i); |
| 317 | if (ret) | ||
| 318 | return ret; | ||
| 319 | } | ||
| 314 | 320 | ||
| 315 | return 0; | 321 | return 0; |
| 316 | } | 322 | } |
diff --git a/drivers/gpio/gpio-mvebu.c b/drivers/gpio/gpio-mvebu.c index adc768f908f1..7d5c55494ccd 100644 --- a/drivers/gpio/gpio-mvebu.c +++ b/drivers/gpio/gpio-mvebu.c | |||
| @@ -608,7 +608,7 @@ static int mvebu_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm) | |||
| 608 | ret = -EBUSY; | 608 | ret = -EBUSY; |
| 609 | } else { | 609 | } else { |
| 610 | desc = gpiochip_request_own_desc(&mvchip->chip, | 610 | desc = gpiochip_request_own_desc(&mvchip->chip, |
| 611 | pwm->hwpwm, "mvebu-pwm"); | 611 | pwm->hwpwm, "mvebu-pwm", 0); |
| 612 | if (IS_ERR(desc)) { | 612 | if (IS_ERR(desc)) { |
| 613 | ret = PTR_ERR(desc); | 613 | ret = PTR_ERR(desc); |
| 614 | goto out; | 614 | goto out; |
diff --git a/drivers/gpio/gpio-mxc.c b/drivers/gpio/gpio-mxc.c index 995cf0b9e0b1..2d1dfa1e0745 100644 --- a/drivers/gpio/gpio-mxc.c +++ b/drivers/gpio/gpio-mxc.c | |||
| @@ -17,6 +17,7 @@ | |||
| 17 | #include <linux/irqchip/chained_irq.h> | 17 | #include <linux/irqchip/chained_irq.h> |
| 18 | #include <linux/platform_device.h> | 18 | #include <linux/platform_device.h> |
| 19 | #include <linux/slab.h> | 19 | #include <linux/slab.h> |
| 20 | #include <linux/syscore_ops.h> | ||
| 20 | #include <linux/gpio/driver.h> | 21 | #include <linux/gpio/driver.h> |
| 21 | #include <linux/of.h> | 22 | #include <linux/of.h> |
| 22 | #include <linux/of_device.h> | 23 | #include <linux/of_device.h> |
| @@ -550,33 +551,38 @@ static void mxc_gpio_restore_regs(struct mxc_gpio_port *port) | |||
| 550 | writel(port->gpio_saved_reg.dr, port->base + GPIO_DR); | 551 | writel(port->gpio_saved_reg.dr, port->base + GPIO_DR); |
| 551 | } | 552 | } |
| 552 | 553 | ||
| 553 | static int __maybe_unused mxc_gpio_noirq_suspend(struct device *dev) | 554 | static int mxc_gpio_syscore_suspend(void) |
| 554 | { | 555 | { |
| 555 | struct platform_device *pdev = to_platform_device(dev); | 556 | struct mxc_gpio_port *port; |
| 556 | struct mxc_gpio_port *port = platform_get_drvdata(pdev); | ||
| 557 | 557 | ||
| 558 | mxc_gpio_save_regs(port); | 558 | /* walk through all ports */ |
| 559 | clk_disable_unprepare(port->clk); | 559 | list_for_each_entry(port, &mxc_gpio_ports, node) { |
| 560 | mxc_gpio_save_regs(port); | ||
| 561 | clk_disable_unprepare(port->clk); | ||
| 562 | } | ||
| 560 | 563 | ||
| 561 | return 0; | 564 | return 0; |
| 562 | } | 565 | } |
| 563 | 566 | ||
| 564 | static int __maybe_unused mxc_gpio_noirq_resume(struct device *dev) | 567 | static void mxc_gpio_syscore_resume(void) |
| 565 | { | 568 | { |
| 566 | struct platform_device *pdev = to_platform_device(dev); | 569 | struct mxc_gpio_port *port; |
| 567 | struct mxc_gpio_port *port = platform_get_drvdata(pdev); | ||
| 568 | int ret; | 570 | int ret; |
| 569 | 571 | ||
| 570 | ret = clk_prepare_enable(port->clk); | 572 | /* walk through all ports */ |
| 571 | if (ret) | 573 | list_for_each_entry(port, &mxc_gpio_ports, node) { |
| 572 | return ret; | 574 | ret = clk_prepare_enable(port->clk); |
| 573 | mxc_gpio_restore_regs(port); | 575 | if (ret) { |
| 574 | 576 | pr_err("mxc: failed to enable gpio clock %d\n", ret); | |
| 575 | return 0; | 577 | return; |
| 578 | } | ||
| 579 | mxc_gpio_restore_regs(port); | ||
| 580 | } | ||
| 576 | } | 581 | } |
| 577 | 582 | ||
| 578 | static const struct dev_pm_ops mxc_gpio_dev_pm_ops = { | 583 | static struct syscore_ops mxc_gpio_syscore_ops = { |
| 579 | SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(mxc_gpio_noirq_suspend, mxc_gpio_noirq_resume) | 584 | .suspend = mxc_gpio_syscore_suspend, |
| 585 | .resume = mxc_gpio_syscore_resume, | ||
| 580 | }; | 586 | }; |
| 581 | 587 | ||
| 582 | static struct platform_driver mxc_gpio_driver = { | 588 | static struct platform_driver mxc_gpio_driver = { |
| @@ -584,7 +590,6 @@ static struct platform_driver mxc_gpio_driver = { | |||
| 584 | .name = "gpio-mxc", | 590 | .name = "gpio-mxc", |
| 585 | .of_match_table = mxc_gpio_dt_ids, | 591 | .of_match_table = mxc_gpio_dt_ids, |
| 586 | .suppress_bind_attrs = true, | 592 | .suppress_bind_attrs = true, |
| 587 | .pm = &mxc_gpio_dev_pm_ops, | ||
| 588 | }, | 593 | }, |
| 589 | .probe = mxc_gpio_probe, | 594 | .probe = mxc_gpio_probe, |
| 590 | .id_table = mxc_gpio_devtype, | 595 | .id_table = mxc_gpio_devtype, |
| @@ -592,6 +597,8 @@ static struct platform_driver mxc_gpio_driver = { | |||
| 592 | 597 | ||
| 593 | static int __init gpio_mxc_init(void) | 598 | static int __init gpio_mxc_init(void) |
| 594 | { | 599 | { |
| 600 | register_syscore_ops(&mxc_gpio_syscore_ops); | ||
| 601 | |||
| 595 | return platform_driver_register(&mxc_gpio_driver); | 602 | return platform_driver_register(&mxc_gpio_driver); |
| 596 | } | 603 | } |
| 597 | subsys_initcall(gpio_mxc_init); | 604 | subsys_initcall(gpio_mxc_init); |
diff --git a/drivers/gpio/gpio-mxs.c b/drivers/gpio/gpio-mxs.c index ea874fd033a5..5e5437a2c607 100644 --- a/drivers/gpio/gpio-mxs.c +++ b/drivers/gpio/gpio-mxs.c | |||
| @@ -84,7 +84,7 @@ static int mxs_gpio_set_irq_type(struct irq_data *d, unsigned int type) | |||
| 84 | port->both_edges &= ~pin_mask; | 84 | port->both_edges &= ~pin_mask; |
| 85 | switch (type) { | 85 | switch (type) { |
| 86 | case IRQ_TYPE_EDGE_BOTH: | 86 | case IRQ_TYPE_EDGE_BOTH: |
| 87 | val = port->gc.get(&port->gc, d->hwirq); | 87 | val = readl(port->base + PINCTRL_DIN(port)) & pin_mask; |
| 88 | if (val) | 88 | if (val) |
| 89 | edge = GPIO_INT_FALL_EDGE; | 89 | edge = GPIO_INT_FALL_EDGE; |
| 90 | else | 90 | else |
diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c index 5b3e83cd7137..f4e9921fa966 100644 --- a/drivers/gpio/gpio-omap.c +++ b/drivers/gpio/gpio-omap.c | |||
| @@ -936,8 +936,7 @@ omap2_gpio_disable_level_quirk(struct gpio_bank *bank) | |||
| 936 | 936 | ||
| 937 | static int omap_mpuio_suspend_noirq(struct device *dev) | 937 | static int omap_mpuio_suspend_noirq(struct device *dev) |
| 938 | { | 938 | { |
| 939 | struct platform_device *pdev = to_platform_device(dev); | 939 | struct gpio_bank *bank = dev_get_drvdata(dev); |
| 940 | struct gpio_bank *bank = platform_get_drvdata(pdev); | ||
| 941 | void __iomem *mask_reg = bank->base + | 940 | void __iomem *mask_reg = bank->base + |
| 942 | OMAP_MPUIO_GPIO_MASKIT / bank->stride; | 941 | OMAP_MPUIO_GPIO_MASKIT / bank->stride; |
| 943 | unsigned long flags; | 942 | unsigned long flags; |
| @@ -951,8 +950,7 @@ static int omap_mpuio_suspend_noirq(struct device *dev) | |||
| 951 | 950 | ||
| 952 | static int omap_mpuio_resume_noirq(struct device *dev) | 951 | static int omap_mpuio_resume_noirq(struct device *dev) |
| 953 | { | 952 | { |
| 954 | struct platform_device *pdev = to_platform_device(dev); | 953 | struct gpio_bank *bank = dev_get_drvdata(dev); |
| 955 | struct gpio_bank *bank = platform_get_drvdata(pdev); | ||
| 956 | void __iomem *mask_reg = bank->base + | 954 | void __iomem *mask_reg = bank->base + |
| 957 | OMAP_MPUIO_GPIO_MASKIT / bank->stride; | 955 | OMAP_MPUIO_GPIO_MASKIT / bank->stride; |
| 958 | unsigned long flags; | 956 | unsigned long flags; |
| @@ -1635,8 +1633,7 @@ static void omap_gpio_restore_context(struct gpio_bank *bank) | |||
| 1635 | 1633 | ||
| 1636 | static int __maybe_unused omap_gpio_runtime_suspend(struct device *dev) | 1634 | static int __maybe_unused omap_gpio_runtime_suspend(struct device *dev) |
| 1637 | { | 1635 | { |
| 1638 | struct platform_device *pdev = to_platform_device(dev); | 1636 | struct gpio_bank *bank = dev_get_drvdata(dev); |
| 1639 | struct gpio_bank *bank = platform_get_drvdata(pdev); | ||
| 1640 | unsigned long flags; | 1637 | unsigned long flags; |
| 1641 | int error = 0; | 1638 | int error = 0; |
| 1642 | 1639 | ||
| @@ -1656,8 +1653,7 @@ unlock: | |||
| 1656 | 1653 | ||
| 1657 | static int __maybe_unused omap_gpio_runtime_resume(struct device *dev) | 1654 | static int __maybe_unused omap_gpio_runtime_resume(struct device *dev) |
| 1658 | { | 1655 | { |
| 1659 | struct platform_device *pdev = to_platform_device(dev); | 1656 | struct gpio_bank *bank = dev_get_drvdata(dev); |
| 1660 | struct gpio_bank *bank = platform_get_drvdata(pdev); | ||
| 1661 | unsigned long flags; | 1657 | unsigned long flags; |
| 1662 | int error = 0; | 1658 | int error = 0; |
| 1663 | 1659 | ||
diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c index 540166443c34..83617fdc661d 100644 --- a/drivers/gpio/gpio-pca953x.c +++ b/drivers/gpio/gpio-pca953x.c | |||
| @@ -20,6 +20,7 @@ | |||
| 20 | #include <linux/module.h> | 20 | #include <linux/module.h> |
| 21 | #include <linux/of_platform.h> | 21 | #include <linux/of_platform.h> |
| 22 | #include <linux/platform_data/pca953x.h> | 22 | #include <linux/platform_data/pca953x.h> |
| 23 | #include <linux/regmap.h> | ||
| 23 | #include <linux/regulator/consumer.h> | 24 | #include <linux/regulator/consumer.h> |
| 24 | #include <linux/slab.h> | 25 | #include <linux/slab.h> |
| 25 | 26 | ||
| @@ -30,6 +31,8 @@ | |||
| 30 | #define PCA953X_INVERT 0x02 | 31 | #define PCA953X_INVERT 0x02 |
| 31 | #define PCA953X_DIRECTION 0x03 | 32 | #define PCA953X_DIRECTION 0x03 |
| 32 | 33 | ||
| 34 | #define REG_ADDR_MASK 0x3f | ||
| 35 | #define REG_ADDR_EXT 0x40 | ||
| 33 | #define REG_ADDR_AI 0x80 | 36 | #define REG_ADDR_AI 0x80 |
| 34 | 37 | ||
| 35 | #define PCA957X_IN 0x00 | 38 | #define PCA957X_IN 0x00 |
| @@ -58,7 +61,7 @@ | |||
| 58 | #define PCA_GPIO_MASK 0x00FF | 61 | #define PCA_GPIO_MASK 0x00FF |
| 59 | 62 | ||
| 60 | #define PCAL_GPIO_MASK 0x1f | 63 | #define PCAL_GPIO_MASK 0x1f |
| 61 | #define PCAL_PINCTRL_MASK 0xe0 | 64 | #define PCAL_PINCTRL_MASK 0x60 |
| 62 | 65 | ||
| 63 | #define PCA_INT 0x0100 | 66 | #define PCA_INT 0x0100 |
| 64 | #define PCA_PCAL 0x0200 | 67 | #define PCA_PCAL 0x0200 |
| @@ -119,25 +122,27 @@ struct pca953x_reg_config { | |||
| 119 | int direction; | 122 | int direction; |
| 120 | int output; | 123 | int output; |
| 121 | int input; | 124 | int input; |
| 125 | int invert; | ||
| 122 | }; | 126 | }; |
| 123 | 127 | ||
| 124 | static const struct pca953x_reg_config pca953x_regs = { | 128 | static const struct pca953x_reg_config pca953x_regs = { |
| 125 | .direction = PCA953X_DIRECTION, | 129 | .direction = PCA953X_DIRECTION, |
| 126 | .output = PCA953X_OUTPUT, | 130 | .output = PCA953X_OUTPUT, |
| 127 | .input = PCA953X_INPUT, | 131 | .input = PCA953X_INPUT, |
| 132 | .invert = PCA953X_INVERT, | ||
| 128 | }; | 133 | }; |
| 129 | 134 | ||
| 130 | static const struct pca953x_reg_config pca957x_regs = { | 135 | static const struct pca953x_reg_config pca957x_regs = { |
| 131 | .direction = PCA957X_CFG, | 136 | .direction = PCA957X_CFG, |
| 132 | .output = PCA957X_OUT, | 137 | .output = PCA957X_OUT, |
| 133 | .input = PCA957X_IN, | 138 | .input = PCA957X_IN, |
| 139 | .invert = PCA957X_INVRT, | ||
| 134 | }; | 140 | }; |
| 135 | 141 | ||
| 136 | struct pca953x_chip { | 142 | struct pca953x_chip { |
| 137 | unsigned gpio_start; | 143 | unsigned gpio_start; |
| 138 | u8 reg_output[MAX_BANK]; | ||
| 139 | u8 reg_direction[MAX_BANK]; | ||
| 140 | struct mutex i2c_lock; | 144 | struct mutex i2c_lock; |
| 145 | struct regmap *regmap; | ||
| 141 | 146 | ||
| 142 | #ifdef CONFIG_GPIO_PCA953X_IRQ | 147 | #ifdef CONFIG_GPIO_PCA953X_IRQ |
| 143 | struct mutex irq_lock; | 148 | struct mutex irq_lock; |
| @@ -154,87 +159,177 @@ struct pca953x_chip { | |||
| 154 | struct regulator *regulator; | 159 | struct regulator *regulator; |
| 155 | 160 | ||
| 156 | const struct pca953x_reg_config *regs; | 161 | const struct pca953x_reg_config *regs; |
| 157 | |||
| 158 | int (*write_regs)(struct pca953x_chip *, int, u8 *); | ||
| 159 | int (*read_regs)(struct pca953x_chip *, int, u8 *); | ||
| 160 | }; | 162 | }; |
| 161 | 163 | ||
| 162 | static int pca953x_read_single(struct pca953x_chip *chip, int reg, u32 *val, | 164 | static int pca953x_bank_shift(struct pca953x_chip *chip) |
| 163 | int off) | ||
| 164 | { | 165 | { |
| 165 | int ret; | 166 | return fls((chip->gpio_chip.ngpio - 1) / BANK_SZ); |
| 166 | int bank_shift = fls((chip->gpio_chip.ngpio - 1) / BANK_SZ); | 167 | } |
| 167 | int offset = off / BANK_SZ; | ||
| 168 | 168 | ||
| 169 | ret = i2c_smbus_read_byte_data(chip->client, | 169 | #define PCA953x_BANK_INPUT BIT(0) |
| 170 | (reg << bank_shift) + offset); | 170 | #define PCA953x_BANK_OUTPUT BIT(1) |
| 171 | *val = ret; | 171 | #define PCA953x_BANK_POLARITY BIT(2) |
| 172 | #define PCA953x_BANK_CONFIG BIT(3) | ||
| 172 | 173 | ||
| 173 | if (ret < 0) { | 174 | #define PCA957x_BANK_INPUT BIT(0) |
| 174 | dev_err(&chip->client->dev, "failed reading register\n"); | 175 | #define PCA957x_BANK_POLARITY BIT(1) |
| 175 | return ret; | 176 | #define PCA957x_BANK_BUSHOLD BIT(2) |
| 177 | #define PCA957x_BANK_CONFIG BIT(4) | ||
| 178 | #define PCA957x_BANK_OUTPUT BIT(5) | ||
| 179 | |||
| 180 | #define PCAL9xxx_BANK_IN_LATCH BIT(8 + 2) | ||
| 181 | #define PCAL9xxx_BANK_IRQ_MASK BIT(8 + 5) | ||
| 182 | #define PCAL9xxx_BANK_IRQ_STAT BIT(8 + 6) | ||
| 183 | |||
| 184 | /* | ||
| 185 | * We care about the following registers: | ||
| 186 | * - Standard set, below 0x40, each port can be replicated up to 8 times | ||
| 187 | * - PCA953x standard | ||
| 188 | * Input port 0x00 + 0 * bank_size R | ||
| 189 | * Output port 0x00 + 1 * bank_size RW | ||
| 190 | * Polarity Inversion port 0x00 + 2 * bank_size RW | ||
| 191 | * Configuration port 0x00 + 3 * bank_size RW | ||
| 192 | * - PCA957x with mixed up registers | ||
| 193 | * Input port 0x00 + 0 * bank_size R | ||
| 194 | * Polarity Inversion port 0x00 + 1 * bank_size RW | ||
| 195 | * Bus hold port 0x00 + 2 * bank_size RW | ||
| 196 | * Configuration port 0x00 + 4 * bank_size RW | ||
| 197 | * Output port 0x00 + 5 * bank_size RW | ||
| 198 | * | ||
| 199 | * - Extended set, above 0x40, often chip specific. | ||
| 200 | * - PCAL6524/PCAL9555A with custom PCAL IRQ handling: | ||
| 201 | * Input latch register 0x40 + 2 * bank_size RW | ||
| 202 | * Interrupt mask register 0x40 + 5 * bank_size RW | ||
| 203 | * Interrupt status register 0x40 + 6 * bank_size R | ||
| 204 | * | ||
| 205 | * - Registers with bit 0x80 set, the AI bit | ||
| 206 | * The bit is cleared and the registers fall into one of the | ||
| 207 | * categories above. | ||
| 208 | */ | ||
| 209 | |||
| 210 | static bool pca953x_check_register(struct pca953x_chip *chip, unsigned int reg, | ||
| 211 | u32 checkbank) | ||
| 212 | { | ||
| 213 | int bank_shift = pca953x_bank_shift(chip); | ||
| 214 | int bank = (reg & REG_ADDR_MASK) >> bank_shift; | ||
| 215 | int offset = reg & (BIT(bank_shift) - 1); | ||
| 216 | |||
| 217 | /* Special PCAL extended register check. */ | ||
| 218 | if (reg & REG_ADDR_EXT) { | ||
| 219 | if (!(chip->driver_data & PCA_PCAL)) | ||
| 220 | return false; | ||
| 221 | bank += 8; | ||
| 176 | } | 222 | } |
| 177 | 223 | ||
| 178 | return 0; | 224 | /* Register is not in the matching bank. */ |
| 225 | if (!(BIT(bank) & checkbank)) | ||
| 226 | return false; | ||
| 227 | |||
| 228 | /* Register is not within allowed range of bank. */ | ||
| 229 | if (offset >= NBANK(chip)) | ||
| 230 | return false; | ||
| 231 | |||
| 232 | return true; | ||
| 179 | } | 233 | } |
| 180 | 234 | ||
| 181 | static int pca953x_write_single(struct pca953x_chip *chip, int reg, u32 val, | 235 | static bool pca953x_readable_register(struct device *dev, unsigned int reg) |
| 182 | int off) | ||
| 183 | { | 236 | { |
| 184 | int ret; | 237 | struct pca953x_chip *chip = dev_get_drvdata(dev); |
| 185 | int bank_shift = fls((chip->gpio_chip.ngpio - 1) / BANK_SZ); | 238 | u32 bank; |
| 186 | int offset = off / BANK_SZ; | ||
| 187 | 239 | ||
| 188 | ret = i2c_smbus_write_byte_data(chip->client, | 240 | if (PCA_CHIP_TYPE(chip->driver_data) == PCA953X_TYPE) { |
| 189 | (reg << bank_shift) + offset, val); | 241 | bank = PCA953x_BANK_INPUT | PCA953x_BANK_OUTPUT | |
| 242 | PCA953x_BANK_POLARITY | PCA953x_BANK_CONFIG; | ||
| 243 | } else { | ||
| 244 | bank = PCA957x_BANK_INPUT | PCA957x_BANK_OUTPUT | | ||
| 245 | PCA957x_BANK_POLARITY | PCA957x_BANK_CONFIG | | ||
| 246 | PCA957x_BANK_BUSHOLD; | ||
| 247 | } | ||
| 190 | 248 | ||
| 191 | if (ret < 0) { | 249 | if (chip->driver_data & PCA_PCAL) { |
| 192 | dev_err(&chip->client->dev, "failed writing register\n"); | 250 | bank |= PCAL9xxx_BANK_IN_LATCH | PCAL9xxx_BANK_IRQ_MASK | |
| 193 | return ret; | 251 | PCAL9xxx_BANK_IRQ_STAT; |
| 194 | } | 252 | } |
| 195 | 253 | ||
| 196 | return 0; | 254 | return pca953x_check_register(chip, reg, bank); |
| 197 | } | 255 | } |
| 198 | 256 | ||
| 199 | static int pca953x_write_regs_8(struct pca953x_chip *chip, int reg, u8 *val) | 257 | static bool pca953x_writeable_register(struct device *dev, unsigned int reg) |
| 200 | { | 258 | { |
| 201 | return i2c_smbus_write_byte_data(chip->client, reg, *val); | 259 | struct pca953x_chip *chip = dev_get_drvdata(dev); |
| 202 | } | 260 | u32 bank; |
| 203 | 261 | ||
| 204 | static int pca953x_write_regs_16(struct pca953x_chip *chip, int reg, u8 *val) | 262 | if (PCA_CHIP_TYPE(chip->driver_data) == PCA953X_TYPE) { |
| 205 | { | 263 | bank = PCA953x_BANK_OUTPUT | PCA953x_BANK_POLARITY | |
| 206 | u16 word = get_unaligned((u16 *)val); | 264 | PCA953x_BANK_CONFIG; |
| 265 | } else { | ||
| 266 | bank = PCA957x_BANK_OUTPUT | PCA957x_BANK_POLARITY | | ||
| 267 | PCA957x_BANK_CONFIG | PCA957x_BANK_BUSHOLD; | ||
| 268 | } | ||
| 207 | 269 | ||
| 208 | return i2c_smbus_write_word_data(chip->client, reg << 1, word); | 270 | if (chip->driver_data & PCA_PCAL) |
| 271 | bank |= PCAL9xxx_BANK_IN_LATCH | PCAL9xxx_BANK_IRQ_MASK; | ||
| 272 | |||
| 273 | return pca953x_check_register(chip, reg, bank); | ||
| 209 | } | 274 | } |
| 210 | 275 | ||
| 211 | static int pca957x_write_regs_16(struct pca953x_chip *chip, int reg, u8 *val) | 276 | static bool pca953x_volatile_register(struct device *dev, unsigned int reg) |
| 212 | { | 277 | { |
| 213 | int ret; | 278 | struct pca953x_chip *chip = dev_get_drvdata(dev); |
| 279 | u32 bank; | ||
| 214 | 280 | ||
| 215 | ret = i2c_smbus_write_byte_data(chip->client, reg << 1, val[0]); | 281 | if (PCA_CHIP_TYPE(chip->driver_data) == PCA953X_TYPE) |
| 216 | if (ret < 0) | 282 | bank = PCA953x_BANK_INPUT; |
| 217 | return ret; | 283 | else |
| 284 | bank = PCA957x_BANK_INPUT; | ||
| 285 | |||
| 286 | if (chip->driver_data & PCA_PCAL) | ||
| 287 | bank |= PCAL9xxx_BANK_IRQ_STAT; | ||
| 218 | 288 | ||
| 219 | return i2c_smbus_write_byte_data(chip->client, (reg << 1) + 1, val[1]); | 289 | return pca953x_check_register(chip, reg, bank); |
| 220 | } | 290 | } |
| 221 | 291 | ||
| 222 | static int pca953x_write_regs_24(struct pca953x_chip *chip, int reg, u8 *val) | 292 | const struct regmap_config pca953x_i2c_regmap = { |
| 293 | .reg_bits = 8, | ||
| 294 | .val_bits = 8, | ||
| 295 | |||
| 296 | .readable_reg = pca953x_readable_register, | ||
| 297 | .writeable_reg = pca953x_writeable_register, | ||
| 298 | .volatile_reg = pca953x_volatile_register, | ||
| 299 | |||
| 300 | .cache_type = REGCACHE_RBTREE, | ||
| 301 | .max_register = 0x7f, | ||
| 302 | }; | ||
| 303 | |||
| 304 | static u8 pca953x_recalc_addr(struct pca953x_chip *chip, int reg, int off, | ||
| 305 | bool write, bool addrinc) | ||
| 223 | { | 306 | { |
| 224 | int bank_shift = fls((chip->gpio_chip.ngpio - 1) / BANK_SZ); | 307 | int bank_shift = pca953x_bank_shift(chip); |
| 225 | int addr = (reg & PCAL_GPIO_MASK) << bank_shift; | 308 | int addr = (reg & PCAL_GPIO_MASK) << bank_shift; |
| 226 | int pinctrl = (reg & PCAL_PINCTRL_MASK) << 1; | 309 | int pinctrl = (reg & PCAL_PINCTRL_MASK) << 1; |
| 310 | u8 regaddr = pinctrl | addr | (off / BANK_SZ); | ||
| 311 | |||
| 312 | /* Single byte read doesn't need AI bit set. */ | ||
| 313 | if (!addrinc) | ||
| 314 | return regaddr; | ||
| 315 | |||
| 316 | /* Chips with 24 and more GPIOs always support Auto Increment */ | ||
| 317 | if (write && NBANK(chip) > 2) | ||
| 318 | regaddr |= REG_ADDR_AI; | ||
| 227 | 319 | ||
| 228 | return i2c_smbus_write_i2c_block_data(chip->client, | 320 | /* PCA9575 needs address-increment on multi-byte writes */ |
| 229 | pinctrl | addr | REG_ADDR_AI, | 321 | if (PCA_CHIP_TYPE(chip->driver_data) == PCA957X_TYPE) |
| 230 | NBANK(chip), val); | 322 | regaddr |= REG_ADDR_AI; |
| 323 | |||
| 324 | return regaddr; | ||
| 231 | } | 325 | } |
| 232 | 326 | ||
| 233 | static int pca953x_write_regs(struct pca953x_chip *chip, int reg, u8 *val) | 327 | static int pca953x_write_regs(struct pca953x_chip *chip, int reg, u8 *val) |
| 234 | { | 328 | { |
| 235 | int ret = 0; | 329 | u8 regaddr = pca953x_recalc_addr(chip, reg, 0, true, true); |
| 330 | int ret; | ||
| 236 | 331 | ||
| 237 | ret = chip->write_regs(chip, reg, val); | 332 | ret = regmap_bulk_write(chip->regmap, regaddr, val, NBANK(chip)); |
| 238 | if (ret < 0) { | 333 | if (ret < 0) { |
| 239 | dev_err(&chip->client->dev, "failed writing register\n"); | 334 | dev_err(&chip->client->dev, "failed writing register\n"); |
| 240 | return ret; | 335 | return ret; |
| @@ -243,42 +338,12 @@ static int pca953x_write_regs(struct pca953x_chip *chip, int reg, u8 *val) | |||
| 243 | return 0; | 338 | return 0; |
| 244 | } | 339 | } |
| 245 | 340 | ||
| 246 | static int pca953x_read_regs_8(struct pca953x_chip *chip, int reg, u8 *val) | ||
| 247 | { | ||
| 248 | int ret; | ||
| 249 | |||
| 250 | ret = i2c_smbus_read_byte_data(chip->client, reg); | ||
| 251 | *val = ret; | ||
| 252 | |||
| 253 | return ret; | ||
| 254 | } | ||
| 255 | |||
| 256 | static int pca953x_read_regs_16(struct pca953x_chip *chip, int reg, u8 *val) | ||
| 257 | { | ||
| 258 | int ret; | ||
| 259 | |||
| 260 | ret = i2c_smbus_read_word_data(chip->client, reg << 1); | ||
| 261 | put_unaligned(ret, (u16 *)val); | ||
| 262 | |||
| 263 | return ret; | ||
| 264 | } | ||
| 265 | |||
| 266 | static int pca953x_read_regs_24(struct pca953x_chip *chip, int reg, u8 *val) | ||
| 267 | { | ||
| 268 | int bank_shift = fls((chip->gpio_chip.ngpio - 1) / BANK_SZ); | ||
| 269 | int addr = (reg & PCAL_GPIO_MASK) << bank_shift; | ||
| 270 | int pinctrl = (reg & PCAL_PINCTRL_MASK) << 1; | ||
| 271 | |||
| 272 | return i2c_smbus_read_i2c_block_data(chip->client, | ||
| 273 | pinctrl | addr | REG_ADDR_AI, | ||
| 274 | NBANK(chip), val); | ||
| 275 | } | ||
| 276 | |||
| 277 | static int pca953x_read_regs(struct pca953x_chip *chip, int reg, u8 *val) | 341 | static int pca953x_read_regs(struct pca953x_chip *chip, int reg, u8 *val) |
| 278 | { | 342 | { |
| 343 | u8 regaddr = pca953x_recalc_addr(chip, reg, 0, false, true); | ||
| 279 | int ret; | 344 | int ret; |
| 280 | 345 | ||
| 281 | ret = chip->read_regs(chip, reg, val); | 346 | ret = regmap_bulk_read(chip->regmap, regaddr, val, NBANK(chip)); |
| 282 | if (ret < 0) { | 347 | if (ret < 0) { |
| 283 | dev_err(&chip->client->dev, "failed reading register\n"); | 348 | dev_err(&chip->client->dev, "failed reading register\n"); |
| 284 | return ret; | 349 | return ret; |
| @@ -290,18 +355,13 @@ static int pca953x_read_regs(struct pca953x_chip *chip, int reg, u8 *val) | |||
| 290 | static int pca953x_gpio_direction_input(struct gpio_chip *gc, unsigned off) | 355 | static int pca953x_gpio_direction_input(struct gpio_chip *gc, unsigned off) |
| 291 | { | 356 | { |
| 292 | struct pca953x_chip *chip = gpiochip_get_data(gc); | 357 | struct pca953x_chip *chip = gpiochip_get_data(gc); |
| 293 | u8 reg_val; | 358 | u8 dirreg = pca953x_recalc_addr(chip, chip->regs->direction, off, |
| 359 | true, false); | ||
| 360 | u8 bit = BIT(off % BANK_SZ); | ||
| 294 | int ret; | 361 | int ret; |
| 295 | 362 | ||
| 296 | mutex_lock(&chip->i2c_lock); | 363 | mutex_lock(&chip->i2c_lock); |
| 297 | reg_val = chip->reg_direction[off / BANK_SZ] | (1u << (off % BANK_SZ)); | 364 | ret = regmap_write_bits(chip->regmap, dirreg, bit, bit); |
| 298 | |||
| 299 | ret = pca953x_write_single(chip, chip->regs->direction, reg_val, off); | ||
| 300 | if (ret) | ||
| 301 | goto exit; | ||
| 302 | |||
| 303 | chip->reg_direction[off / BANK_SZ] = reg_val; | ||
| 304 | exit: | ||
| 305 | mutex_unlock(&chip->i2c_lock); | 365 | mutex_unlock(&chip->i2c_lock); |
| 306 | return ret; | 366 | return ret; |
| 307 | } | 367 | } |
| @@ -310,31 +370,21 @@ static int pca953x_gpio_direction_output(struct gpio_chip *gc, | |||
| 310 | unsigned off, int val) | 370 | unsigned off, int val) |
| 311 | { | 371 | { |
| 312 | struct pca953x_chip *chip = gpiochip_get_data(gc); | 372 | struct pca953x_chip *chip = gpiochip_get_data(gc); |
| 313 | u8 reg_val; | 373 | u8 dirreg = pca953x_recalc_addr(chip, chip->regs->direction, off, |
| 374 | true, false); | ||
| 375 | u8 outreg = pca953x_recalc_addr(chip, chip->regs->output, off, | ||
| 376 | true, false); | ||
| 377 | u8 bit = BIT(off % BANK_SZ); | ||
| 314 | int ret; | 378 | int ret; |
| 315 | 379 | ||
| 316 | mutex_lock(&chip->i2c_lock); | 380 | mutex_lock(&chip->i2c_lock); |
| 317 | /* set output level */ | 381 | /* set output level */ |
| 318 | if (val) | 382 | ret = regmap_write_bits(chip->regmap, outreg, bit, val ? bit : 0); |
| 319 | reg_val = chip->reg_output[off / BANK_SZ] | ||
| 320 | | (1u << (off % BANK_SZ)); | ||
| 321 | else | ||
| 322 | reg_val = chip->reg_output[off / BANK_SZ] | ||
| 323 | & ~(1u << (off % BANK_SZ)); | ||
| 324 | |||
| 325 | ret = pca953x_write_single(chip, chip->regs->output, reg_val, off); | ||
| 326 | if (ret) | 383 | if (ret) |
| 327 | goto exit; | 384 | goto exit; |
| 328 | 385 | ||
| 329 | chip->reg_output[off / BANK_SZ] = reg_val; | ||
| 330 | |||
| 331 | /* then direction */ | 386 | /* then direction */ |
| 332 | reg_val = chip->reg_direction[off / BANK_SZ] & ~(1u << (off % BANK_SZ)); | 387 | ret = regmap_write_bits(chip->regmap, dirreg, bit, 0); |
| 333 | ret = pca953x_write_single(chip, chip->regs->direction, reg_val, off); | ||
| 334 | if (ret) | ||
| 335 | goto exit; | ||
| 336 | |||
| 337 | chip->reg_direction[off / BANK_SZ] = reg_val; | ||
| 338 | exit: | 388 | exit: |
| 339 | mutex_unlock(&chip->i2c_lock); | 389 | mutex_unlock(&chip->i2c_lock); |
| 340 | return ret; | 390 | return ret; |
| @@ -343,11 +393,14 @@ exit: | |||
| 343 | static int pca953x_gpio_get_value(struct gpio_chip *gc, unsigned off) | 393 | static int pca953x_gpio_get_value(struct gpio_chip *gc, unsigned off) |
| 344 | { | 394 | { |
| 345 | struct pca953x_chip *chip = gpiochip_get_data(gc); | 395 | struct pca953x_chip *chip = gpiochip_get_data(gc); |
| 396 | u8 inreg = pca953x_recalc_addr(chip, chip->regs->input, off, | ||
| 397 | true, false); | ||
| 398 | u8 bit = BIT(off % BANK_SZ); | ||
| 346 | u32 reg_val; | 399 | u32 reg_val; |
| 347 | int ret; | 400 | int ret; |
| 348 | 401 | ||
| 349 | mutex_lock(&chip->i2c_lock); | 402 | mutex_lock(&chip->i2c_lock); |
| 350 | ret = pca953x_read_single(chip, chip->regs->input, ®_val, off); | 403 | ret = regmap_read(chip->regmap, inreg, ®_val); |
| 351 | mutex_unlock(&chip->i2c_lock); | 404 | mutex_unlock(&chip->i2c_lock); |
| 352 | if (ret < 0) { | 405 | if (ret < 0) { |
| 353 | /* NOTE: diagnostic already emitted; that's all we should | 406 | /* NOTE: diagnostic already emitted; that's all we should |
| @@ -357,45 +410,37 @@ static int pca953x_gpio_get_value(struct gpio_chip *gc, unsigned off) | |||
| 357 | return 0; | 410 | return 0; |
| 358 | } | 411 | } |
| 359 | 412 | ||
| 360 | return (reg_val & (1u << (off % BANK_SZ))) ? 1 : 0; | 413 | return !!(reg_val & bit); |
| 361 | } | 414 | } |
| 362 | 415 | ||
| 363 | static void pca953x_gpio_set_value(struct gpio_chip *gc, unsigned off, int val) | 416 | static void pca953x_gpio_set_value(struct gpio_chip *gc, unsigned off, int val) |
| 364 | { | 417 | { |
| 365 | struct pca953x_chip *chip = gpiochip_get_data(gc); | 418 | struct pca953x_chip *chip = gpiochip_get_data(gc); |
| 366 | u8 reg_val; | 419 | u8 outreg = pca953x_recalc_addr(chip, chip->regs->output, off, |
| 367 | int ret; | 420 | true, false); |
| 421 | u8 bit = BIT(off % BANK_SZ); | ||
| 368 | 422 | ||
| 369 | mutex_lock(&chip->i2c_lock); | 423 | mutex_lock(&chip->i2c_lock); |
| 370 | if (val) | 424 | regmap_write_bits(chip->regmap, outreg, bit, val ? bit : 0); |
| 371 | reg_val = chip->reg_output[off / BANK_SZ] | ||
| 372 | | (1u << (off % BANK_SZ)); | ||
| 373 | else | ||
| 374 | reg_val = chip->reg_output[off / BANK_SZ] | ||
| 375 | & ~(1u << (off % BANK_SZ)); | ||
| 376 | |||
| 377 | ret = pca953x_write_single(chip, chip->regs->output, reg_val, off); | ||
| 378 | if (ret) | ||
| 379 | goto exit; | ||
| 380 | |||
| 381 | chip->reg_output[off / BANK_SZ] = reg_val; | ||
| 382 | exit: | ||
| 383 | mutex_unlock(&chip->i2c_lock); | 425 | mutex_unlock(&chip->i2c_lock); |
| 384 | } | 426 | } |
| 385 | 427 | ||
| 386 | static int pca953x_gpio_get_direction(struct gpio_chip *gc, unsigned off) | 428 | static int pca953x_gpio_get_direction(struct gpio_chip *gc, unsigned off) |
| 387 | { | 429 | { |
| 388 | struct pca953x_chip *chip = gpiochip_get_data(gc); | 430 | struct pca953x_chip *chip = gpiochip_get_data(gc); |
| 431 | u8 dirreg = pca953x_recalc_addr(chip, chip->regs->direction, off, | ||
| 432 | true, false); | ||
| 433 | u8 bit = BIT(off % BANK_SZ); | ||
| 389 | u32 reg_val; | 434 | u32 reg_val; |
| 390 | int ret; | 435 | int ret; |
| 391 | 436 | ||
| 392 | mutex_lock(&chip->i2c_lock); | 437 | mutex_lock(&chip->i2c_lock); |
| 393 | ret = pca953x_read_single(chip, chip->regs->direction, ®_val, off); | 438 | ret = regmap_read(chip->regmap, dirreg, ®_val); |
| 394 | mutex_unlock(&chip->i2c_lock); | 439 | mutex_unlock(&chip->i2c_lock); |
| 395 | if (ret < 0) | 440 | if (ret < 0) |
| 396 | return ret; | 441 | return ret; |
| 397 | 442 | ||
| 398 | return !!(reg_val & (1u << (off % BANK_SZ))); | 443 | return !!(reg_val & bit); |
| 399 | } | 444 | } |
| 400 | 445 | ||
| 401 | static void pca953x_gpio_set_multiple(struct gpio_chip *gc, | 446 | static void pca953x_gpio_set_multiple(struct gpio_chip *gc, |
| @@ -403,14 +448,15 @@ static void pca953x_gpio_set_multiple(struct gpio_chip *gc, | |||
| 403 | { | 448 | { |
| 404 | struct pca953x_chip *chip = gpiochip_get_data(gc); | 449 | struct pca953x_chip *chip = gpiochip_get_data(gc); |
| 405 | unsigned int bank_mask, bank_val; | 450 | unsigned int bank_mask, bank_val; |
| 406 | int bank_shift, bank; | 451 | int bank; |
| 407 | u8 reg_val[MAX_BANK]; | 452 | u8 reg_val[MAX_BANK]; |
| 408 | int ret; | 453 | int ret; |
| 409 | 454 | ||
| 410 | bank_shift = fls((chip->gpio_chip.ngpio - 1) / BANK_SZ); | ||
| 411 | |||
| 412 | mutex_lock(&chip->i2c_lock); | 455 | mutex_lock(&chip->i2c_lock); |
| 413 | memcpy(reg_val, chip->reg_output, NBANK(chip)); | 456 | ret = pca953x_read_regs(chip, chip->regs->output, reg_val); |
| 457 | if (ret) | ||
| 458 | goto exit; | ||
| 459 | |||
| 414 | for (bank = 0; bank < NBANK(chip); bank++) { | 460 | for (bank = 0; bank < NBANK(chip); bank++) { |
| 415 | bank_mask = mask[bank / sizeof(*mask)] >> | 461 | bank_mask = mask[bank / sizeof(*mask)] >> |
| 416 | ((bank % sizeof(*mask)) * 8); | 462 | ((bank % sizeof(*mask)) * 8); |
| @@ -422,13 +468,7 @@ static void pca953x_gpio_set_multiple(struct gpio_chip *gc, | |||
| 422 | } | 468 | } |
| 423 | } | 469 | } |
| 424 | 470 | ||
| 425 | ret = i2c_smbus_write_i2c_block_data(chip->client, | 471 | pca953x_write_regs(chip, chip->regs->output, reg_val); |
| 426 | chip->regs->output << bank_shift, | ||
| 427 | NBANK(chip), reg_val); | ||
| 428 | if (ret) | ||
| 429 | goto exit; | ||
| 430 | |||
| 431 | memcpy(chip->reg_output, reg_val, NBANK(chip)); | ||
| 432 | exit: | 472 | exit: |
| 433 | mutex_unlock(&chip->i2c_lock); | 473 | mutex_unlock(&chip->i2c_lock); |
| 434 | } | 474 | } |
| @@ -487,6 +527,10 @@ static void pca953x_irq_bus_sync_unlock(struct irq_data *d) | |||
| 487 | u8 new_irqs; | 527 | u8 new_irqs; |
| 488 | int level, i; | 528 | int level, i; |
| 489 | u8 invert_irq_mask[MAX_BANK]; | 529 | u8 invert_irq_mask[MAX_BANK]; |
| 530 | int reg_direction[MAX_BANK]; | ||
| 531 | |||
| 532 | regmap_bulk_read(chip->regmap, chip->regs->direction, reg_direction, | ||
| 533 | NBANK(chip)); | ||
| 490 | 534 | ||
| 491 | if (chip->driver_data & PCA_PCAL) { | 535 | if (chip->driver_data & PCA_PCAL) { |
| 492 | /* Enable latch on interrupt-enabled inputs */ | 536 | /* Enable latch on interrupt-enabled inputs */ |
| @@ -502,7 +546,7 @@ static void pca953x_irq_bus_sync_unlock(struct irq_data *d) | |||
| 502 | /* Look for any newly setup interrupt */ | 546 | /* Look for any newly setup interrupt */ |
| 503 | for (i = 0; i < NBANK(chip); i++) { | 547 | for (i = 0; i < NBANK(chip); i++) { |
| 504 | new_irqs = chip->irq_trig_fall[i] | chip->irq_trig_raise[i]; | 548 | new_irqs = chip->irq_trig_fall[i] | chip->irq_trig_raise[i]; |
| 505 | new_irqs &= ~chip->reg_direction[i]; | 549 | new_irqs &= reg_direction[i]; |
| 506 | 550 | ||
| 507 | while (new_irqs) { | 551 | while (new_irqs) { |
| 508 | level = __ffs(new_irqs); | 552 | level = __ffs(new_irqs); |
| @@ -567,6 +611,7 @@ static bool pca953x_irq_pending(struct pca953x_chip *chip, u8 *pending) | |||
| 567 | bool pending_seen = false; | 611 | bool pending_seen = false; |
| 568 | bool trigger_seen = false; | 612 | bool trigger_seen = false; |
| 569 | u8 trigger[MAX_BANK]; | 613 | u8 trigger[MAX_BANK]; |
| 614 | int reg_direction[MAX_BANK]; | ||
| 570 | int ret, i; | 615 | int ret, i; |
| 571 | 616 | ||
| 572 | if (chip->driver_data & PCA_PCAL) { | 617 | if (chip->driver_data & PCA_PCAL) { |
| @@ -597,8 +642,10 @@ static bool pca953x_irq_pending(struct pca953x_chip *chip, u8 *pending) | |||
| 597 | return false; | 642 | return false; |
| 598 | 643 | ||
| 599 | /* Remove output pins from the equation */ | 644 | /* Remove output pins from the equation */ |
| 645 | regmap_bulk_read(chip->regmap, chip->regs->direction, reg_direction, | ||
| 646 | NBANK(chip)); | ||
| 600 | for (i = 0; i < NBANK(chip); i++) | 647 | for (i = 0; i < NBANK(chip); i++) |
| 601 | cur_stat[i] &= chip->reg_direction[i]; | 648 | cur_stat[i] &= reg_direction[i]; |
| 602 | 649 | ||
| 603 | memcpy(old_stat, chip->irq_stat, NBANK(chip)); | 650 | memcpy(old_stat, chip->irq_stat, NBANK(chip)); |
| 604 | 651 | ||
| @@ -652,6 +699,7 @@ static int pca953x_irq_setup(struct pca953x_chip *chip, | |||
| 652 | int irq_base) | 699 | int irq_base) |
| 653 | { | 700 | { |
| 654 | struct i2c_client *client = chip->client; | 701 | struct i2c_client *client = chip->client; |
| 702 | int reg_direction[MAX_BANK]; | ||
| 655 | int ret, i; | 703 | int ret, i; |
| 656 | 704 | ||
| 657 | if (client->irq && irq_base != -1 | 705 | if (client->irq && irq_base != -1 |
| @@ -666,8 +714,10 @@ static int pca953x_irq_setup(struct pca953x_chip *chip, | |||
| 666 | * interrupt. We have to rely on the previous read for | 714 | * interrupt. We have to rely on the previous read for |
| 667 | * this purpose. | 715 | * this purpose. |
| 668 | */ | 716 | */ |
| 717 | regmap_bulk_read(chip->regmap, chip->regs->direction, | ||
| 718 | reg_direction, NBANK(chip)); | ||
| 669 | for (i = 0; i < NBANK(chip); i++) | 719 | for (i = 0; i < NBANK(chip); i++) |
| 670 | chip->irq_stat[i] &= chip->reg_direction[i]; | 720 | chip->irq_stat[i] &= reg_direction[i]; |
| 671 | mutex_init(&chip->irq_lock); | 721 | mutex_init(&chip->irq_lock); |
| 672 | 722 | ||
| 673 | ret = devm_request_threaded_irq(&client->dev, | 723 | ret = devm_request_threaded_irq(&client->dev, |
| @@ -715,20 +765,19 @@ static int pca953x_irq_setup(struct pca953x_chip *chip, | |||
| 715 | } | 765 | } |
| 716 | #endif | 766 | #endif |
| 717 | 767 | ||
| 718 | static int device_pca953x_init(struct pca953x_chip *chip, u32 invert) | 768 | static int device_pca95xx_init(struct pca953x_chip *chip, u32 invert) |
| 719 | { | 769 | { |
| 720 | int ret; | 770 | int ret; |
| 721 | u8 val[MAX_BANK]; | 771 | u8 val[MAX_BANK]; |
| 722 | 772 | ||
| 723 | chip->regs = &pca953x_regs; | 773 | ret = regcache_sync_region(chip->regmap, chip->regs->output, |
| 724 | 774 | chip->regs->output + NBANK(chip)); | |
| 725 | ret = pca953x_read_regs(chip, chip->regs->output, chip->reg_output); | 775 | if (ret != 0) |
| 726 | if (ret) | ||
| 727 | goto out; | 776 | goto out; |
| 728 | 777 | ||
| 729 | ret = pca953x_read_regs(chip, chip->regs->direction, | 778 | ret = regcache_sync_region(chip->regmap, chip->regs->direction, |
| 730 | chip->reg_direction); | 779 | chip->regs->direction + NBANK(chip)); |
| 731 | if (ret) | 780 | if (ret != 0) |
| 732 | goto out; | 781 | goto out; |
| 733 | 782 | ||
| 734 | /* set platform specific polarity inversion */ | 783 | /* set platform specific polarity inversion */ |
| @@ -737,7 +786,7 @@ static int device_pca953x_init(struct pca953x_chip *chip, u32 invert) | |||
| 737 | else | 786 | else |
| 738 | memset(val, 0, NBANK(chip)); | 787 | memset(val, 0, NBANK(chip)); |
| 739 | 788 | ||
| 740 | ret = pca953x_write_regs(chip, PCA953X_INVERT, val); | 789 | ret = pca953x_write_regs(chip, chip->regs->invert, val); |
| 741 | out: | 790 | out: |
| 742 | return ret; | 791 | return ret; |
| 743 | } | 792 | } |
| @@ -747,22 +796,7 @@ static int device_pca957x_init(struct pca953x_chip *chip, u32 invert) | |||
| 747 | int ret; | 796 | int ret; |
| 748 | u8 val[MAX_BANK]; | 797 | u8 val[MAX_BANK]; |
| 749 | 798 | ||
| 750 | chip->regs = &pca957x_regs; | 799 | ret = device_pca95xx_init(chip, invert); |
| 751 | |||
| 752 | ret = pca953x_read_regs(chip, chip->regs->output, chip->reg_output); | ||
| 753 | if (ret) | ||
| 754 | goto out; | ||
| 755 | ret = pca953x_read_regs(chip, chip->regs->direction, | ||
| 756 | chip->reg_direction); | ||
| 757 | if (ret) | ||
| 758 | goto out; | ||
| 759 | |||
| 760 | /* set platform specific polarity inversion */ | ||
| 761 | if (invert) | ||
| 762 | memset(val, 0xFF, NBANK(chip)); | ||
| 763 | else | ||
| 764 | memset(val, 0, NBANK(chip)); | ||
| 765 | ret = pca953x_write_regs(chip, PCA957X_INVRT, val); | ||
| 766 | if (ret) | 800 | if (ret) |
| 767 | goto out; | 801 | goto out; |
| 768 | 802 | ||
| @@ -853,6 +887,16 @@ static int pca953x_probe(struct i2c_client *client, | |||
| 853 | } | 887 | } |
| 854 | } | 888 | } |
| 855 | 889 | ||
| 890 | i2c_set_clientdata(client, chip); | ||
| 891 | |||
| 892 | chip->regmap = devm_regmap_init_i2c(client, &pca953x_i2c_regmap); | ||
| 893 | if (IS_ERR(chip->regmap)) { | ||
| 894 | ret = PTR_ERR(chip->regmap); | ||
| 895 | goto err_exit; | ||
| 896 | } | ||
| 897 | |||
| 898 | regcache_mark_dirty(chip->regmap); | ||
| 899 | |||
| 856 | mutex_init(&chip->i2c_lock); | 900 | mutex_init(&chip->i2c_lock); |
| 857 | /* | 901 | /* |
| 858 | * In case we have an i2c-mux controlled by a GPIO provided by an | 902 | * In case we have an i2c-mux controlled by a GPIO provided by an |
| @@ -878,24 +922,13 @@ static int pca953x_probe(struct i2c_client *client, | |||
| 878 | */ | 922 | */ |
| 879 | pca953x_setup_gpio(chip, chip->driver_data & PCA_GPIO_MASK); | 923 | pca953x_setup_gpio(chip, chip->driver_data & PCA_GPIO_MASK); |
| 880 | 924 | ||
| 881 | if (chip->gpio_chip.ngpio <= 8) { | 925 | if (PCA_CHIP_TYPE(chip->driver_data) == PCA953X_TYPE) { |
| 882 | chip->write_regs = pca953x_write_regs_8; | 926 | chip->regs = &pca953x_regs; |
| 883 | chip->read_regs = pca953x_read_regs_8; | 927 | ret = device_pca95xx_init(chip, invert); |
| 884 | } else if (chip->gpio_chip.ngpio >= 24) { | ||
| 885 | chip->write_regs = pca953x_write_regs_24; | ||
| 886 | chip->read_regs = pca953x_read_regs_24; | ||
| 887 | } else { | 928 | } else { |
| 888 | if (PCA_CHIP_TYPE(chip->driver_data) == PCA953X_TYPE) | 929 | chip->regs = &pca957x_regs; |
| 889 | chip->write_regs = pca953x_write_regs_16; | ||
| 890 | else | ||
| 891 | chip->write_regs = pca957x_write_regs_16; | ||
| 892 | chip->read_regs = pca953x_read_regs_16; | ||
| 893 | } | ||
| 894 | |||
| 895 | if (PCA_CHIP_TYPE(chip->driver_data) == PCA953X_TYPE) | ||
| 896 | ret = device_pca953x_init(chip, invert); | ||
| 897 | else | ||
| 898 | ret = device_pca957x_init(chip, invert); | 930 | ret = device_pca957x_init(chip, invert); |
| 931 | } | ||
| 899 | if (ret) | 932 | if (ret) |
| 900 | goto err_exit; | 933 | goto err_exit; |
| 901 | 934 | ||
| @@ -914,7 +947,6 @@ static int pca953x_probe(struct i2c_client *client, | |||
| 914 | dev_warn(&client->dev, "setup failed, %d\n", ret); | 947 | dev_warn(&client->dev, "setup failed, %d\n", ret); |
| 915 | } | 948 | } |
| 916 | 949 | ||
| 917 | i2c_set_clientdata(client, chip); | ||
| 918 | return 0; | 950 | return 0; |
| 919 | 951 | ||
| 920 | err_exit: | 952 | err_exit: |
| @@ -943,6 +975,91 @@ static int pca953x_remove(struct i2c_client *client) | |||
| 943 | return ret; | 975 | return ret; |
| 944 | } | 976 | } |
| 945 | 977 | ||
| 978 | #ifdef CONFIG_PM_SLEEP | ||
| 979 | static int pca953x_regcache_sync(struct device *dev) | ||
| 980 | { | ||
| 981 | struct pca953x_chip *chip = dev_get_drvdata(dev); | ||
| 982 | int ret; | ||
| 983 | |||
| 984 | /* | ||
| 985 | * The ordering between direction and output is important, | ||
| 986 | * sync these registers first and only then sync the rest. | ||
| 987 | */ | ||
| 988 | ret = regcache_sync_region(chip->regmap, chip->regs->direction, | ||
| 989 | chip->regs->direction + NBANK(chip)); | ||
| 990 | if (ret != 0) { | ||
| 991 | dev_err(dev, "Failed to sync GPIO dir registers: %d\n", ret); | ||
| 992 | return ret; | ||
| 993 | } | ||
| 994 | |||
| 995 | ret = regcache_sync_region(chip->regmap, chip->regs->output, | ||
| 996 | chip->regs->output + NBANK(chip)); | ||
| 997 | if (ret != 0) { | ||
| 998 | dev_err(dev, "Failed to sync GPIO out registers: %d\n", ret); | ||
| 999 | return ret; | ||
| 1000 | } | ||
| 1001 | |||
| 1002 | #ifdef CONFIG_GPIO_PCA953X_IRQ | ||
| 1003 | if (chip->driver_data & PCA_PCAL) { | ||
| 1004 | ret = regcache_sync_region(chip->regmap, PCAL953X_IN_LATCH, | ||
| 1005 | PCAL953X_IN_LATCH + NBANK(chip)); | ||
| 1006 | if (ret != 0) { | ||
| 1007 | dev_err(dev, "Failed to sync INT latch registers: %d\n", | ||
| 1008 | ret); | ||
| 1009 | return ret; | ||
| 1010 | } | ||
| 1011 | |||
| 1012 | ret = regcache_sync_region(chip->regmap, PCAL953X_INT_MASK, | ||
| 1013 | PCAL953X_INT_MASK + NBANK(chip)); | ||
| 1014 | if (ret != 0) { | ||
| 1015 | dev_err(dev, "Failed to sync INT mask registers: %d\n", | ||
| 1016 | ret); | ||
| 1017 | return ret; | ||
| 1018 | } | ||
| 1019 | } | ||
| 1020 | #endif | ||
| 1021 | |||
| 1022 | return 0; | ||
| 1023 | } | ||
| 1024 | |||
| 1025 | static int pca953x_suspend(struct device *dev) | ||
| 1026 | { | ||
| 1027 | struct pca953x_chip *chip = dev_get_drvdata(dev); | ||
| 1028 | |||
| 1029 | regcache_cache_only(chip->regmap, true); | ||
| 1030 | |||
| 1031 | regulator_disable(chip->regulator); | ||
| 1032 | |||
| 1033 | return 0; | ||
| 1034 | } | ||
| 1035 | |||
| 1036 | static int pca953x_resume(struct device *dev) | ||
| 1037 | { | ||
| 1038 | struct pca953x_chip *chip = dev_get_drvdata(dev); | ||
| 1039 | int ret; | ||
| 1040 | |||
| 1041 | ret = regulator_enable(chip->regulator); | ||
| 1042 | if (ret != 0) { | ||
| 1043 | dev_err(dev, "Failed to enable regulator: %d\n", ret); | ||
| 1044 | return 0; | ||
| 1045 | } | ||
| 1046 | |||
| 1047 | regcache_cache_only(chip->regmap, false); | ||
| 1048 | regcache_mark_dirty(chip->regmap); | ||
| 1049 | ret = pca953x_regcache_sync(dev); | ||
| 1050 | if (ret) | ||
| 1051 | return ret; | ||
| 1052 | |||
| 1053 | ret = regcache_sync(chip->regmap); | ||
| 1054 | if (ret != 0) { | ||
| 1055 | dev_err(dev, "Failed to restore register map: %d\n", ret); | ||
| 1056 | return ret; | ||
| 1057 | } | ||
| 1058 | |||
| 1059 | return 0; | ||
| 1060 | } | ||
| 1061 | #endif | ||
| 1062 | |||
| 946 | /* convenience to stop overlong match-table lines */ | 1063 | /* convenience to stop overlong match-table lines */ |
| 947 | #define OF_953X(__nrgpio, __int) (void *)(__nrgpio | PCA953X_TYPE | __int) | 1064 | #define OF_953X(__nrgpio, __int) (void *)(__nrgpio | PCA953X_TYPE | __int) |
| 948 | #define OF_957X(__nrgpio, __int) (void *)(__nrgpio | PCA957X_TYPE | __int) | 1065 | #define OF_957X(__nrgpio, __int) (void *)(__nrgpio | PCA957X_TYPE | __int) |
| @@ -986,9 +1103,12 @@ static const struct of_device_id pca953x_dt_ids[] = { | |||
| 986 | 1103 | ||
| 987 | MODULE_DEVICE_TABLE(of, pca953x_dt_ids); | 1104 | MODULE_DEVICE_TABLE(of, pca953x_dt_ids); |
| 988 | 1105 | ||
| 1106 | static SIMPLE_DEV_PM_OPS(pca953x_pm_ops, pca953x_suspend, pca953x_resume); | ||
| 1107 | |||
| 989 | static struct i2c_driver pca953x_driver = { | 1108 | static struct i2c_driver pca953x_driver = { |
| 990 | .driver = { | 1109 | .driver = { |
| 991 | .name = "pca953x", | 1110 | .name = "pca953x", |
| 1111 | .pm = &pca953x_pm_ops, | ||
| 992 | .of_match_table = pca953x_dt_ids, | 1112 | .of_match_table = pca953x_dt_ids, |
| 993 | .acpi_match_table = ACPI_PTR(pca953x_acpi_ids), | 1113 | .acpi_match_table = ACPI_PTR(pca953x_acpi_ids), |
| 994 | }, | 1114 | }, |
diff --git a/drivers/gpio/gpio-pch.c b/drivers/gpio/gpio-pch.c index ffce0ab912ed..ee79e5f88b5a 100644 --- a/drivers/gpio/gpio-pch.c +++ b/drivers/gpio/gpio-pch.c | |||
| @@ -1,25 +1,13 @@ | |||
| 1 | // SPDX-License-Identifier: GPL-2.0 | ||
| 1 | /* | 2 | /* |
| 2 | * Copyright (C) 2011 LAPIS Semiconductor Co., Ltd. | 3 | * Copyright (C) 2011 LAPIS Semiconductor Co., Ltd. |
| 3 | * | ||
| 4 | * This program is free software; you can redistribute it and/or modify | ||
| 5 | * it under the terms of the GNU General Public License as published by | ||
| 6 | * the Free Software Foundation; version 2 of the License. | ||
| 7 | * | ||
| 8 | * This program is distributed in the hope that it will be useful, | ||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 11 | * GNU General Public License for more details. | ||
| 12 | * | ||
| 13 | * You should have received a copy of the GNU General Public License | ||
| 14 | * along with this program; if not, write to the Free Software | ||
| 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. | ||
| 16 | */ | 4 | */ |
| 17 | #include <linux/module.h> | ||
| 18 | #include <linux/kernel.h> | ||
| 19 | #include <linux/pci.h> | ||
| 20 | #include <linux/gpio/driver.h> | 5 | #include <linux/gpio/driver.h> |
| 21 | #include <linux/interrupt.h> | 6 | #include <linux/interrupt.h> |
| 22 | #include <linux/irq.h> | 7 | #include <linux/irq.h> |
| 8 | #include <linux/kernel.h> | ||
| 9 | #include <linux/module.h> | ||
| 10 | #include <linux/pci.h> | ||
| 23 | #include <linux/slab.h> | 11 | #include <linux/slab.h> |
| 24 | 12 | ||
| 25 | #define PCH_EDGE_FALLING 0 | 13 | #define PCH_EDGE_FALLING 0 |
| @@ -171,11 +159,10 @@ static int pch_gpio_direction_input(struct gpio_chip *gpio, unsigned nr) | |||
| 171 | return 0; | 159 | return 0; |
| 172 | } | 160 | } |
| 173 | 161 | ||
| 174 | #ifdef CONFIG_PM | ||
| 175 | /* | 162 | /* |
| 176 | * Save register configuration and disable interrupts. | 163 | * Save register configuration and disable interrupts. |
| 177 | */ | 164 | */ |
| 178 | static void pch_gpio_save_reg_conf(struct pch_gpio *chip) | 165 | static void __maybe_unused pch_gpio_save_reg_conf(struct pch_gpio *chip) |
| 179 | { | 166 | { |
| 180 | chip->pch_gpio_reg.ien_reg = ioread32(&chip->reg->ien); | 167 | chip->pch_gpio_reg.ien_reg = ioread32(&chip->reg->ien); |
| 181 | chip->pch_gpio_reg.imask_reg = ioread32(&chip->reg->imask); | 168 | chip->pch_gpio_reg.imask_reg = ioread32(&chip->reg->imask); |
| @@ -185,14 +172,13 @@ static void pch_gpio_save_reg_conf(struct pch_gpio *chip) | |||
| 185 | if (chip->ioh == INTEL_EG20T_PCH) | 172 | if (chip->ioh == INTEL_EG20T_PCH) |
| 186 | chip->pch_gpio_reg.im1_reg = ioread32(&chip->reg->im1); | 173 | chip->pch_gpio_reg.im1_reg = ioread32(&chip->reg->im1); |
| 187 | if (chip->ioh == OKISEMI_ML7223n_IOH) | 174 | if (chip->ioh == OKISEMI_ML7223n_IOH) |
| 188 | chip->pch_gpio_reg.gpio_use_sel_reg =\ | 175 | chip->pch_gpio_reg.gpio_use_sel_reg = ioread32(&chip->reg->gpio_use_sel); |
| 189 | ioread32(&chip->reg->gpio_use_sel); | ||
| 190 | } | 176 | } |
| 191 | 177 | ||
| 192 | /* | 178 | /* |
| 193 | * This function restores the register configuration of the GPIO device. | 179 | * This function restores the register configuration of the GPIO device. |
| 194 | */ | 180 | */ |
| 195 | static void pch_gpio_restore_reg_conf(struct pch_gpio *chip) | 181 | static void __maybe_unused pch_gpio_restore_reg_conf(struct pch_gpio *chip) |
| 196 | { | 182 | { |
| 197 | iowrite32(chip->pch_gpio_reg.ien_reg, &chip->reg->ien); | 183 | iowrite32(chip->pch_gpio_reg.ien_reg, &chip->reg->ien); |
| 198 | iowrite32(chip->pch_gpio_reg.imask_reg, &chip->reg->imask); | 184 | iowrite32(chip->pch_gpio_reg.imask_reg, &chip->reg->imask); |
| @@ -204,10 +190,8 @@ static void pch_gpio_restore_reg_conf(struct pch_gpio *chip) | |||
| 204 | if (chip->ioh == INTEL_EG20T_PCH) | 190 | if (chip->ioh == INTEL_EG20T_PCH) |
| 205 | iowrite32(chip->pch_gpio_reg.im1_reg, &chip->reg->im1); | 191 | iowrite32(chip->pch_gpio_reg.im1_reg, &chip->reg->im1); |
| 206 | if (chip->ioh == OKISEMI_ML7223n_IOH) | 192 | if (chip->ioh == OKISEMI_ML7223n_IOH) |
| 207 | iowrite32(chip->pch_gpio_reg.gpio_use_sel_reg, | 193 | iowrite32(chip->pch_gpio_reg.gpio_use_sel_reg, &chip->reg->gpio_use_sel); |
| 208 | &chip->reg->gpio_use_sel); | ||
| 209 | } | 194 | } |
| 210 | #endif | ||
| 211 | 195 | ||
| 212 | static int pch_gpio_to_irq(struct gpio_chip *gpio, unsigned offset) | 196 | static int pch_gpio_to_irq(struct gpio_chip *gpio, unsigned offset) |
| 213 | { | 197 | { |
| @@ -226,7 +210,6 @@ static void pch_gpio_setup(struct pch_gpio *chip) | |||
| 226 | gpio->get = pch_gpio_get; | 210 | gpio->get = pch_gpio_get; |
| 227 | gpio->direction_output = pch_gpio_direction_output; | 211 | gpio->direction_output = pch_gpio_direction_output; |
| 228 | gpio->set = pch_gpio_set; | 212 | gpio->set = pch_gpio_set; |
| 229 | gpio->dbg_show = NULL; | ||
| 230 | gpio->base = -1; | 213 | gpio->base = -1; |
| 231 | gpio->ngpio = gpio_pins[chip->ioh]; | 214 | gpio->ngpio = gpio_pins[chip->ioh]; |
| 232 | gpio->can_sleep = false; | 215 | gpio->can_sleep = false; |
| @@ -250,8 +233,7 @@ static int pch_irq_type(struct irq_data *d, unsigned int type) | |||
| 250 | im_reg = &chip->reg->im1; | 233 | im_reg = &chip->reg->im1; |
| 251 | im_pos = ch - 8; | 234 | im_pos = ch - 8; |
| 252 | } | 235 | } |
| 253 | dev_dbg(chip->dev, "%s:irq=%d type=%d ch=%d pos=%d\n", | 236 | dev_dbg(chip->dev, "irq=%d type=%d ch=%d pos=%d\n", irq, type, ch, im_pos); |
| 254 | __func__, irq, type, ch, im_pos); | ||
| 255 | 237 | ||
| 256 | spin_lock_irqsave(&chip->spinlock, flags); | 238 | spin_lock_irqsave(&chip->spinlock, flags); |
| 257 | 239 | ||
| @@ -317,16 +299,13 @@ static void pch_irq_ack(struct irq_data *d) | |||
| 317 | static irqreturn_t pch_gpio_handler(int irq, void *dev_id) | 299 | static irqreturn_t pch_gpio_handler(int irq, void *dev_id) |
| 318 | { | 300 | { |
| 319 | struct pch_gpio *chip = dev_id; | 301 | struct pch_gpio *chip = dev_id; |
| 320 | u32 reg_val = ioread32(&chip->reg->istatus); | 302 | unsigned long reg_val = ioread32(&chip->reg->istatus); |
| 321 | int i, ret = IRQ_NONE; | 303 | int i, ret = IRQ_NONE; |
| 322 | 304 | ||
| 323 | for (i = 0; i < gpio_pins[chip->ioh]; i++) { | 305 | for_each_set_bit(i, ®_val, gpio_pins[chip->ioh]) { |
| 324 | if (reg_val & BIT(i)) { | 306 | dev_dbg(chip->dev, "[%d]:irq=%d status=0x%lx\n", i, irq, reg_val); |
| 325 | dev_dbg(chip->dev, "%s:[%d]:irq=%d status=0x%x\n", | 307 | generic_handle_irq(chip->irq_base + i); |
| 326 | __func__, i, irq, reg_val); | 308 | ret = IRQ_HANDLED; |
| 327 | generic_handle_irq(chip->irq_base + i); | ||
| 328 | ret = IRQ_HANDLED; | ||
| 329 | } | ||
| 330 | } | 309 | } |
| 331 | return ret; | 310 | return ret; |
| 332 | } | 311 | } |
| @@ -367,29 +346,24 @@ static int pch_gpio_probe(struct pci_dev *pdev, | |||
| 367 | int irq_base; | 346 | int irq_base; |
| 368 | u32 msk; | 347 | u32 msk; |
| 369 | 348 | ||
| 370 | chip = kzalloc(sizeof(*chip), GFP_KERNEL); | 349 | chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL); |
| 371 | if (chip == NULL) | 350 | if (chip == NULL) |
| 372 | return -ENOMEM; | 351 | return -ENOMEM; |
| 373 | 352 | ||
| 374 | chip->dev = &pdev->dev; | 353 | chip->dev = &pdev->dev; |
| 375 | ret = pci_enable_device(pdev); | 354 | ret = pcim_enable_device(pdev); |
| 376 | if (ret) { | 355 | if (ret) { |
| 377 | dev_err(&pdev->dev, "%s : pci_enable_device FAILED", __func__); | 356 | dev_err(&pdev->dev, "pci_enable_device FAILED"); |
| 378 | goto err_pci_enable; | 357 | return ret; |
| 379 | } | 358 | } |
| 380 | 359 | ||
| 381 | ret = pci_request_regions(pdev, KBUILD_MODNAME); | 360 | ret = pcim_iomap_regions(pdev, 1 << 1, KBUILD_MODNAME); |
| 382 | if (ret) { | 361 | if (ret) { |
| 383 | dev_err(&pdev->dev, "pci_request_regions FAILED-%d", ret); | 362 | dev_err(&pdev->dev, "pci_request_regions FAILED-%d", ret); |
| 384 | goto err_request_regions; | 363 | return ret; |
| 385 | } | 364 | } |
| 386 | 365 | ||
| 387 | chip->base = pci_iomap(pdev, 1, 0); | 366 | chip->base = pcim_iomap_table(pdev)[1]; |
| 388 | if (!chip->base) { | ||
| 389 | dev_err(&pdev->dev, "%s : pci_iomap FAILED", __func__); | ||
| 390 | ret = -ENOMEM; | ||
| 391 | goto err_iomap; | ||
| 392 | } | ||
| 393 | 367 | ||
| 394 | if (pdev->device == 0x8803) | 368 | if (pdev->device == 0x8803) |
| 395 | chip->ioh = INTEL_EG20T_PCH; | 369 | chip->ioh = INTEL_EG20T_PCH; |
| @@ -402,13 +376,11 @@ static int pch_gpio_probe(struct pci_dev *pdev, | |||
| 402 | pci_set_drvdata(pdev, chip); | 376 | pci_set_drvdata(pdev, chip); |
| 403 | spin_lock_init(&chip->spinlock); | 377 | spin_lock_init(&chip->spinlock); |
| 404 | pch_gpio_setup(chip); | 378 | pch_gpio_setup(chip); |
| 405 | #ifdef CONFIG_OF_GPIO | 379 | |
| 406 | chip->gpio.of_node = pdev->dev.of_node; | 380 | ret = devm_gpiochip_add_data(&pdev->dev, &chip->gpio, chip); |
| 407 | #endif | ||
| 408 | ret = gpiochip_add_data(&chip->gpio, chip); | ||
| 409 | if (ret) { | 381 | if (ret) { |
| 410 | dev_err(&pdev->dev, "PCH gpio: Failed to register GPIO\n"); | 382 | dev_err(&pdev->dev, "PCH gpio: Failed to register GPIO\n"); |
| 411 | goto err_gpiochip_add; | 383 | return ret; |
| 412 | } | 384 | } |
| 413 | 385 | ||
| 414 | irq_base = devm_irq_alloc_descs(&pdev->dev, -1, 0, | 386 | irq_base = devm_irq_alloc_descs(&pdev->dev, -1, 0, |
| @@ -416,7 +388,7 @@ static int pch_gpio_probe(struct pci_dev *pdev, | |||
| 416 | if (irq_base < 0) { | 388 | if (irq_base < 0) { |
| 417 | dev_warn(&pdev->dev, "PCH gpio: Failed to get IRQ base num\n"); | 389 | dev_warn(&pdev->dev, "PCH gpio: Failed to get IRQ base num\n"); |
| 418 | chip->irq_base = -1; | 390 | chip->irq_base = -1; |
| 419 | goto end; | 391 | return 0; |
| 420 | } | 392 | } |
| 421 | chip->irq_base = irq_base; | 393 | chip->irq_base = irq_base; |
| 422 | 394 | ||
| @@ -427,53 +399,17 @@ static int pch_gpio_probe(struct pci_dev *pdev, | |||
| 427 | 399 | ||
| 428 | ret = devm_request_irq(&pdev->dev, pdev->irq, pch_gpio_handler, | 400 | ret = devm_request_irq(&pdev->dev, pdev->irq, pch_gpio_handler, |
| 429 | IRQF_SHARED, KBUILD_MODNAME, chip); | 401 | IRQF_SHARED, KBUILD_MODNAME, chip); |
| 430 | if (ret != 0) { | 402 | if (ret) { |
| 431 | dev_err(&pdev->dev, | 403 | dev_err(&pdev->dev, "request_irq failed\n"); |
| 432 | "%s request_irq failed\n", __func__); | 404 | return ret; |
| 433 | goto err_request_irq; | ||
| 434 | } | 405 | } |
| 435 | 406 | ||
| 436 | ret = pch_gpio_alloc_generic_chip(chip, irq_base, | 407 | return pch_gpio_alloc_generic_chip(chip, irq_base, gpio_pins[chip->ioh]); |
| 437 | gpio_pins[chip->ioh]); | ||
| 438 | if (ret) | ||
| 439 | goto err_request_irq; | ||
| 440 | |||
| 441 | end: | ||
| 442 | return 0; | ||
| 443 | |||
| 444 | err_request_irq: | ||
| 445 | gpiochip_remove(&chip->gpio); | ||
| 446 | |||
| 447 | err_gpiochip_add: | ||
| 448 | pci_iounmap(pdev, chip->base); | ||
| 449 | |||
| 450 | err_iomap: | ||
| 451 | pci_release_regions(pdev); | ||
| 452 | |||
| 453 | err_request_regions: | ||
| 454 | pci_disable_device(pdev); | ||
| 455 | |||
| 456 | err_pci_enable: | ||
| 457 | kfree(chip); | ||
| 458 | dev_err(&pdev->dev, "%s Failed returns %d\n", __func__, ret); | ||
| 459 | return ret; | ||
| 460 | } | ||
| 461 | |||
| 462 | static void pch_gpio_remove(struct pci_dev *pdev) | ||
| 463 | { | ||
| 464 | struct pch_gpio *chip = pci_get_drvdata(pdev); | ||
| 465 | |||
| 466 | gpiochip_remove(&chip->gpio); | ||
| 467 | pci_iounmap(pdev, chip->base); | ||
| 468 | pci_release_regions(pdev); | ||
| 469 | pci_disable_device(pdev); | ||
| 470 | kfree(chip); | ||
| 471 | } | 408 | } |
| 472 | 409 | ||
| 473 | #ifdef CONFIG_PM | 410 | static int __maybe_unused pch_gpio_suspend(struct device *dev) |
| 474 | static int pch_gpio_suspend(struct pci_dev *pdev, pm_message_t state) | ||
| 475 | { | 411 | { |
| 476 | s32 ret; | 412 | struct pci_dev *pdev = to_pci_dev(dev); |
| 477 | struct pch_gpio *chip = pci_get_drvdata(pdev); | 413 | struct pch_gpio *chip = pci_get_drvdata(pdev); |
| 478 | unsigned long flags; | 414 | unsigned long flags; |
| 479 | 415 | ||
| @@ -481,36 +417,15 @@ static int pch_gpio_suspend(struct pci_dev *pdev, pm_message_t state) | |||
| 481 | pch_gpio_save_reg_conf(chip); | 417 | pch_gpio_save_reg_conf(chip); |
| 482 | spin_unlock_irqrestore(&chip->spinlock, flags); | 418 | spin_unlock_irqrestore(&chip->spinlock, flags); |
| 483 | 419 | ||
| 484 | ret = pci_save_state(pdev); | ||
| 485 | if (ret) { | ||
| 486 | dev_err(&pdev->dev, "pci_save_state Failed-%d\n", ret); | ||
| 487 | return ret; | ||
| 488 | } | ||
| 489 | pci_disable_device(pdev); | ||
| 490 | pci_set_power_state(pdev, PCI_D0); | ||
| 491 | ret = pci_enable_wake(pdev, PCI_D0, 1); | ||
| 492 | if (ret) | ||
| 493 | dev_err(&pdev->dev, "pci_enable_wake Failed -%d\n", ret); | ||
| 494 | |||
| 495 | return 0; | 420 | return 0; |
| 496 | } | 421 | } |
| 497 | 422 | ||
| 498 | static int pch_gpio_resume(struct pci_dev *pdev) | 423 | static int __maybe_unused pch_gpio_resume(struct device *dev) |
| 499 | { | 424 | { |
| 500 | s32 ret; | 425 | struct pci_dev *pdev = to_pci_dev(dev); |
| 501 | struct pch_gpio *chip = pci_get_drvdata(pdev); | 426 | struct pch_gpio *chip = pci_get_drvdata(pdev); |
| 502 | unsigned long flags; | 427 | unsigned long flags; |
| 503 | 428 | ||
| 504 | ret = pci_enable_wake(pdev, PCI_D0, 0); | ||
| 505 | |||
| 506 | pci_set_power_state(pdev, PCI_D0); | ||
| 507 | ret = pci_enable_device(pdev); | ||
| 508 | if (ret) { | ||
| 509 | dev_err(&pdev->dev, "pci_enable_device Failed-%d ", ret); | ||
| 510 | return ret; | ||
| 511 | } | ||
| 512 | pci_restore_state(pdev); | ||
| 513 | |||
| 514 | spin_lock_irqsave(&chip->spinlock, flags); | 429 | spin_lock_irqsave(&chip->spinlock, flags); |
| 515 | iowrite32(0x01, &chip->reg->reset); | 430 | iowrite32(0x01, &chip->reg->reset); |
| 516 | iowrite32(0x00, &chip->reg->reset); | 431 | iowrite32(0x00, &chip->reg->reset); |
| @@ -519,10 +434,8 @@ static int pch_gpio_resume(struct pci_dev *pdev) | |||
| 519 | 434 | ||
| 520 | return 0; | 435 | return 0; |
| 521 | } | 436 | } |
| 522 | #else | 437 | |
| 523 | #define pch_gpio_suspend NULL | 438 | static SIMPLE_DEV_PM_OPS(pch_gpio_pm_ops, pch_gpio_suspend, pch_gpio_resume); |
| 524 | #define pch_gpio_resume NULL | ||
| 525 | #endif | ||
| 526 | 439 | ||
| 527 | #define PCI_VENDOR_ID_ROHM 0x10DB | 440 | #define PCI_VENDOR_ID_ROHM 0x10DB |
| 528 | static const struct pci_device_id pch_gpio_pcidev_id[] = { | 441 | static const struct pci_device_id pch_gpio_pcidev_id[] = { |
| @@ -538,12 +451,12 @@ static struct pci_driver pch_gpio_driver = { | |||
| 538 | .name = "pch_gpio", | 451 | .name = "pch_gpio", |
| 539 | .id_table = pch_gpio_pcidev_id, | 452 | .id_table = pch_gpio_pcidev_id, |
| 540 | .probe = pch_gpio_probe, | 453 | .probe = pch_gpio_probe, |
| 541 | .remove = pch_gpio_remove, | 454 | .driver = { |
| 542 | .suspend = pch_gpio_suspend, | 455 | .pm = &pch_gpio_pm_ops, |
| 543 | .resume = pch_gpio_resume | 456 | }, |
| 544 | }; | 457 | }; |
| 545 | 458 | ||
| 546 | module_pci_driver(pch_gpio_driver); | 459 | module_pci_driver(pch_gpio_driver); |
| 547 | 460 | ||
| 548 | MODULE_DESCRIPTION("PCH GPIO PCI Driver"); | 461 | MODULE_DESCRIPTION("PCH GPIO PCI Driver"); |
| 549 | MODULE_LICENSE("GPL"); | 462 | MODULE_LICENSE("GPL v2"); |
diff --git a/drivers/gpio/gpio-pci-idio-16.c b/drivers/gpio/gpio-pci-idio-16.c index 25d16b2af1c3..6b7349783223 100644 --- a/drivers/gpio/gpio-pci-idio-16.c +++ b/drivers/gpio/gpio-pci-idio-16.c | |||
| @@ -146,7 +146,7 @@ static int idio_16_gpio_get_multiple(struct gpio_chip *chip, | |||
| 146 | port_state = ioread8(ports[i]); | 146 | port_state = ioread8(ports[i]); |
| 147 | 147 | ||
| 148 | /* store acquired bits at respective bits array offset */ | 148 | /* store acquired bits at respective bits array offset */ |
| 149 | bits[word_index] |= port_state << word_offset; | 149 | bits[word_index] |= (port_state << word_offset) & word_mask; |
| 150 | } | 150 | } |
| 151 | 151 | ||
| 152 | return 0; | 152 | return 0; |
diff --git a/drivers/gpio/gpio-pcie-idio-24.c b/drivers/gpio/gpio-pcie-idio-24.c index f953541e7890..52f1647a46fd 100644 --- a/drivers/gpio/gpio-pcie-idio-24.c +++ b/drivers/gpio/gpio-pcie-idio-24.c | |||
| @@ -243,7 +243,7 @@ static int idio_24_gpio_get_multiple(struct gpio_chip *chip, | |||
| 243 | port_state = ioread8(&idio24gpio->reg->ttl_in0_7); | 243 | port_state = ioread8(&idio24gpio->reg->ttl_in0_7); |
| 244 | 244 | ||
| 245 | /* store acquired bits at respective bits array offset */ | 245 | /* store acquired bits at respective bits array offset */ |
| 246 | bits[word_index] |= port_state << word_offset; | 246 | bits[word_index] |= (port_state << word_offset) & word_mask; |
| 247 | } | 247 | } |
| 248 | 248 | ||
| 249 | return 0; | 249 | return 0; |
diff --git a/drivers/gpio/gpio-pl061.c b/drivers/gpio/gpio-pl061.c index 2afd9de84a0d..dc42571e6fdc 100644 --- a/drivers/gpio/gpio-pl061.c +++ b/drivers/gpio/gpio-pl061.c | |||
| @@ -54,6 +54,7 @@ struct pl061 { | |||
| 54 | 54 | ||
| 55 | void __iomem *base; | 55 | void __iomem *base; |
| 56 | struct gpio_chip gc; | 56 | struct gpio_chip gc; |
| 57 | struct irq_chip irq_chip; | ||
| 57 | int parent_irq; | 58 | int parent_irq; |
| 58 | 59 | ||
| 59 | #ifdef CONFIG_PM | 60 | #ifdef CONFIG_PM |
| @@ -281,15 +282,6 @@ static int pl061_irq_set_wake(struct irq_data *d, unsigned int state) | |||
| 281 | return irq_set_irq_wake(pl061->parent_irq, state); | 282 | return irq_set_irq_wake(pl061->parent_irq, state); |
| 282 | } | 283 | } |
| 283 | 284 | ||
| 284 | static struct irq_chip pl061_irqchip = { | ||
| 285 | .name = "pl061", | ||
| 286 | .irq_ack = pl061_irq_ack, | ||
| 287 | .irq_mask = pl061_irq_mask, | ||
| 288 | .irq_unmask = pl061_irq_unmask, | ||
| 289 | .irq_set_type = pl061_irq_type, | ||
| 290 | .irq_set_wake = pl061_irq_set_wake, | ||
| 291 | }; | ||
| 292 | |||
| 293 | static int pl061_probe(struct amba_device *adev, const struct amba_id *id) | 285 | static int pl061_probe(struct amba_device *adev, const struct amba_id *id) |
| 294 | { | 286 | { |
| 295 | struct device *dev = &adev->dev; | 287 | struct device *dev = &adev->dev; |
| @@ -328,6 +320,13 @@ static int pl061_probe(struct amba_device *adev, const struct amba_id *id) | |||
| 328 | /* | 320 | /* |
| 329 | * irq_chip support | 321 | * irq_chip support |
| 330 | */ | 322 | */ |
| 323 | pl061->irq_chip.name = dev_name(dev); | ||
| 324 | pl061->irq_chip.irq_ack = pl061_irq_ack; | ||
| 325 | pl061->irq_chip.irq_mask = pl061_irq_mask; | ||
| 326 | pl061->irq_chip.irq_unmask = pl061_irq_unmask; | ||
| 327 | pl061->irq_chip.irq_set_type = pl061_irq_type; | ||
| 328 | pl061->irq_chip.irq_set_wake = pl061_irq_set_wake; | ||
| 329 | |||
| 331 | writeb(0, pl061->base + GPIOIE); /* disable irqs */ | 330 | writeb(0, pl061->base + GPIOIE); /* disable irqs */ |
| 332 | irq = adev->irq[0]; | 331 | irq = adev->irq[0]; |
| 333 | if (irq < 0) { | 332 | if (irq < 0) { |
| @@ -336,14 +335,14 @@ static int pl061_probe(struct amba_device *adev, const struct amba_id *id) | |||
| 336 | } | 335 | } |
| 337 | pl061->parent_irq = irq; | 336 | pl061->parent_irq = irq; |
| 338 | 337 | ||
| 339 | ret = gpiochip_irqchip_add(&pl061->gc, &pl061_irqchip, | 338 | ret = gpiochip_irqchip_add(&pl061->gc, &pl061->irq_chip, |
| 340 | 0, handle_bad_irq, | 339 | 0, handle_bad_irq, |
| 341 | IRQ_TYPE_NONE); | 340 | IRQ_TYPE_NONE); |
| 342 | if (ret) { | 341 | if (ret) { |
| 343 | dev_info(&adev->dev, "could not add irqchip\n"); | 342 | dev_info(&adev->dev, "could not add irqchip\n"); |
| 344 | return ret; | 343 | return ret; |
| 345 | } | 344 | } |
| 346 | gpiochip_set_chained_irqchip(&pl061->gc, &pl061_irqchip, | 345 | gpiochip_set_chained_irqchip(&pl061->gc, &pl061->irq_chip, |
| 347 | irq, pl061_irq_handler); | 346 | irq, pl061_irq_handler); |
| 348 | 347 | ||
| 349 | amba_set_drvdata(adev, pl061); | 348 | amba_set_drvdata(adev, pl061); |
diff --git a/drivers/gpio/gpio-raspberrypi-exp.c b/drivers/gpio/gpio-raspberrypi-exp.c index d6d36d537e37..b77ea16ffa03 100644 --- a/drivers/gpio/gpio-raspberrypi-exp.c +++ b/drivers/gpio/gpio-raspberrypi-exp.c | |||
| @@ -206,6 +206,7 @@ static int rpi_exp_gpio_probe(struct platform_device *pdev) | |||
| 206 | } | 206 | } |
| 207 | 207 | ||
| 208 | fw = rpi_firmware_get(fw_node); | 208 | fw = rpi_firmware_get(fw_node); |
| 209 | of_node_put(fw_node); | ||
| 209 | if (!fw) | 210 | if (!fw) |
| 210 | return -EPROBE_DEFER; | 211 | return -EPROBE_DEFER; |
| 211 | 212 | ||
diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c index 3c82bb3c2030..068ce25ffd28 100644 --- a/drivers/gpio/gpio-rcar.c +++ b/drivers/gpio/gpio-rcar.c | |||
| @@ -1,17 +1,9 @@ | |||
| 1 | // SPDX-License-Identifier: GPL-2.0 | ||
| 1 | /* | 2 | /* |
| 2 | * Renesas R-Car GPIO Support | 3 | * Renesas R-Car GPIO Support |
| 3 | * | 4 | * |
| 4 | * Copyright (C) 2014 Renesas Electronics Corporation | 5 | * Copyright (C) 2014 Renesas Electronics Corporation |
| 5 | * Copyright (C) 2013 Magnus Damm | 6 | * Copyright (C) 2013 Magnus Damm |
| 6 | * | ||
| 7 | * This program is free software; you can redistribute it and/or modify | ||
| 8 | * it under the terms of the GNU General Public License as published by | ||
| 9 | * the Free Software Foundation; either version 2 of the License | ||
| 10 | * | ||
| 11 | * This program is distributed in the hope that it will be useful, | ||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | * GNU General Public License for more details. | ||
| 15 | */ | 7 | */ |
| 16 | 8 | ||
| 17 | #include <linux/err.h> | 9 | #include <linux/err.h> |
| @@ -43,7 +35,7 @@ struct gpio_rcar_bank_info { | |||
| 43 | struct gpio_rcar_priv { | 35 | struct gpio_rcar_priv { |
| 44 | void __iomem *base; | 36 | void __iomem *base; |
| 45 | spinlock_t lock; | 37 | spinlock_t lock; |
| 46 | struct platform_device *pdev; | 38 | struct device *dev; |
| 47 | struct gpio_chip gpio_chip; | 39 | struct gpio_chip gpio_chip; |
| 48 | struct irq_chip irq_chip; | 40 | struct irq_chip irq_chip; |
| 49 | unsigned int irq_parent; | 41 | unsigned int irq_parent; |
| @@ -148,7 +140,7 @@ static int gpio_rcar_irq_set_type(struct irq_data *d, unsigned int type) | |||
| 148 | struct gpio_rcar_priv *p = gpiochip_get_data(gc); | 140 | struct gpio_rcar_priv *p = gpiochip_get_data(gc); |
| 149 | unsigned int hwirq = irqd_to_hwirq(d); | 141 | unsigned int hwirq = irqd_to_hwirq(d); |
| 150 | 142 | ||
| 151 | dev_dbg(&p->pdev->dev, "sense irq = %d, type = %d\n", hwirq, type); | 143 | dev_dbg(p->dev, "sense irq = %d, type = %d\n", hwirq, type); |
| 152 | 144 | ||
| 153 | switch (type & IRQ_TYPE_SENSE_MASK) { | 145 | switch (type & IRQ_TYPE_SENSE_MASK) { |
| 154 | case IRQ_TYPE_LEVEL_HIGH: | 146 | case IRQ_TYPE_LEVEL_HIGH: |
| @@ -188,8 +180,7 @@ static int gpio_rcar_irq_set_wake(struct irq_data *d, unsigned int on) | |||
| 188 | if (p->irq_parent) { | 180 | if (p->irq_parent) { |
| 189 | error = irq_set_irq_wake(p->irq_parent, on); | 181 | error = irq_set_irq_wake(p->irq_parent, on); |
| 190 | if (error) { | 182 | if (error) { |
| 191 | dev_dbg(&p->pdev->dev, | 183 | dev_dbg(p->dev, "irq %u doesn't support irq_set_wake\n", |
| 192 | "irq %u doesn't support irq_set_wake\n", | ||
| 193 | p->irq_parent); | 184 | p->irq_parent); |
| 194 | p->irq_parent = 0; | 185 | p->irq_parent = 0; |
| 195 | } | 186 | } |
| @@ -252,13 +243,13 @@ static int gpio_rcar_request(struct gpio_chip *chip, unsigned offset) | |||
| 252 | struct gpio_rcar_priv *p = gpiochip_get_data(chip); | 243 | struct gpio_rcar_priv *p = gpiochip_get_data(chip); |
| 253 | int error; | 244 | int error; |
| 254 | 245 | ||
| 255 | error = pm_runtime_get_sync(&p->pdev->dev); | 246 | error = pm_runtime_get_sync(p->dev); |
| 256 | if (error < 0) | 247 | if (error < 0) |
| 257 | return error; | 248 | return error; |
| 258 | 249 | ||
| 259 | error = pinctrl_gpio_request(chip->base + offset); | 250 | error = pinctrl_gpio_request(chip->base + offset); |
| 260 | if (error) | 251 | if (error) |
| 261 | pm_runtime_put(&p->pdev->dev); | 252 | pm_runtime_put(p->dev); |
| 262 | 253 | ||
| 263 | return error; | 254 | return error; |
| 264 | } | 255 | } |
| @@ -275,7 +266,7 @@ static void gpio_rcar_free(struct gpio_chip *chip, unsigned offset) | |||
| 275 | */ | 266 | */ |
| 276 | gpio_rcar_config_general_input_output_mode(chip, offset, false); | 267 | gpio_rcar_config_general_input_output_mode(chip, offset, false); |
| 277 | 268 | ||
| 278 | pm_runtime_put(&p->pdev->dev); | 269 | pm_runtime_put(p->dev); |
| 279 | } | 270 | } |
| 280 | 271 | ||
| 281 | static int gpio_rcar_get_direction(struct gpio_chip *chip, unsigned int offset) | 272 | static int gpio_rcar_get_direction(struct gpio_chip *chip, unsigned int offset) |
| @@ -406,21 +397,20 @@ MODULE_DEVICE_TABLE(of, gpio_rcar_of_table); | |||
| 406 | 397 | ||
| 407 | static int gpio_rcar_parse_dt(struct gpio_rcar_priv *p, unsigned int *npins) | 398 | static int gpio_rcar_parse_dt(struct gpio_rcar_priv *p, unsigned int *npins) |
| 408 | { | 399 | { |
| 409 | struct device_node *np = p->pdev->dev.of_node; | 400 | struct device_node *np = p->dev->of_node; |
| 410 | const struct gpio_rcar_info *info; | 401 | const struct gpio_rcar_info *info; |
| 411 | struct of_phandle_args args; | 402 | struct of_phandle_args args; |
| 412 | int ret; | 403 | int ret; |
| 413 | 404 | ||
| 414 | info = of_device_get_match_data(&p->pdev->dev); | 405 | info = of_device_get_match_data(p->dev); |
| 415 | 406 | ||
| 416 | ret = of_parse_phandle_with_fixed_args(np, "gpio-ranges", 3, 0, &args); | 407 | ret = of_parse_phandle_with_fixed_args(np, "gpio-ranges", 3, 0, &args); |
| 417 | *npins = ret == 0 ? args.args[2] : RCAR_MAX_GPIO_PER_BANK; | 408 | *npins = ret == 0 ? args.args[2] : RCAR_MAX_GPIO_PER_BANK; |
| 418 | p->has_both_edge_trigger = info->has_both_edge_trigger; | 409 | p->has_both_edge_trigger = info->has_both_edge_trigger; |
| 419 | 410 | ||
| 420 | if (*npins == 0 || *npins > RCAR_MAX_GPIO_PER_BANK) { | 411 | if (*npins == 0 || *npins > RCAR_MAX_GPIO_PER_BANK) { |
| 421 | dev_warn(&p->pdev->dev, | 412 | dev_warn(p->dev, "Invalid number of gpio lines %u, using %u\n", |
| 422 | "Invalid number of gpio lines %u, using %u\n", *npins, | 413 | *npins, RCAR_MAX_GPIO_PER_BANK); |
| 423 | RCAR_MAX_GPIO_PER_BANK); | ||
| 424 | *npins = RCAR_MAX_GPIO_PER_BANK; | 414 | *npins = RCAR_MAX_GPIO_PER_BANK; |
| 425 | } | 415 | } |
| 426 | 416 | ||
| @@ -442,7 +432,7 @@ static int gpio_rcar_probe(struct platform_device *pdev) | |||
| 442 | if (!p) | 432 | if (!p) |
| 443 | return -ENOMEM; | 433 | return -ENOMEM; |
| 444 | 434 | ||
| 445 | p->pdev = pdev; | 435 | p->dev = dev; |
| 446 | spin_lock_init(&p->lock); | 436 | spin_lock_init(&p->lock); |
| 447 | 437 | ||
| 448 | /* Get device configuration from DT node */ | 438 | /* Get device configuration from DT node */ |
diff --git a/drivers/gpio/gpio-sama5d2-piobu.c b/drivers/gpio/gpio-sama5d2-piobu.c new file mode 100644 index 000000000000..03a000659fa1 --- /dev/null +++ b/drivers/gpio/gpio-sama5d2-piobu.c | |||
| @@ -0,0 +1,253 @@ | |||
| 1 | // SPDX-License-Identifier: GPL-2.0 | ||
| 2 | /* | ||
| 3 | * SAMA5D2 PIOBU GPIO controller | ||
| 4 | * | ||
| 5 | * Copyright (C) 2018 Microchip Technology Inc. and its subsidiaries | ||
| 6 | * | ||
| 7 | * Author: Andrei Stefanescu <andrei.stefanescu@microchip.com> | ||
| 8 | * | ||
| 9 | */ | ||
| 10 | #include <linux/bits.h> | ||
| 11 | #include <linux/gpio/driver.h> | ||
| 12 | #include <linux/init.h> | ||
| 13 | #include <linux/kernel.h> | ||
| 14 | #include <linux/mfd/syscon.h> | ||
| 15 | #include <linux/module.h> | ||
| 16 | #include <linux/of.h> | ||
| 17 | #include <linux/platform_device.h> | ||
| 18 | #include <linux/regmap.h> | ||
| 19 | |||
| 20 | #define PIOBU_NUM 8 | ||
| 21 | #define PIOBU_REG_SIZE 4 | ||
| 22 | |||
| 23 | /* | ||
| 24 | * backup mode protection register for tamper detection | ||
| 25 | * normal mode protection register for tamper detection | ||
| 26 | * wakeup signal generation | ||
| 27 | */ | ||
| 28 | #define PIOBU_BMPR 0x7C | ||
| 29 | #define PIOBU_NMPR 0x80 | ||
| 30 | #define PIOBU_WKPR 0x90 | ||
| 31 | |||
| 32 | #define PIOBU_BASE 0x18 /* PIOBU offset from SECUMOD base register address. */ | ||
| 33 | |||
| 34 | #define PIOBU_DET_OFFSET 16 | ||
| 35 | |||
| 36 | /* In the datasheet this bit is called OUTPUT */ | ||
| 37 | #define PIOBU_DIRECTION BIT(8) | ||
| 38 | #define PIOBU_OUT BIT(8) | ||
| 39 | #define PIOBU_IN 0 | ||
| 40 | |||
| 41 | #define PIOBU_SOD BIT(9) | ||
| 42 | #define PIOBU_PDS BIT(10) | ||
| 43 | |||
| 44 | #define PIOBU_HIGH BIT(9) | ||
| 45 | #define PIOBU_LOW 0 | ||
| 46 | |||
| 47 | struct sama5d2_piobu { | ||
| 48 | struct gpio_chip chip; | ||
| 49 | struct regmap *regmap; | ||
| 50 | }; | ||
| 51 | |||
| 52 | /** | ||
| 53 | * sama5d2_piobu_setup_pin() - prepares a pin for set_direction call | ||
| 54 | * | ||
| 55 | * Do not consider pin for tamper detection (normal and backup modes) | ||
| 56 | * Do not consider pin as tamper wakeup interrupt source | ||
| 57 | */ | ||
| 58 | static int sama5d2_piobu_setup_pin(struct gpio_chip *chip, unsigned int pin) | ||
| 59 | { | ||
| 60 | int ret; | ||
| 61 | struct sama5d2_piobu *piobu = container_of(chip, struct sama5d2_piobu, | ||
| 62 | chip); | ||
| 63 | unsigned int mask = BIT(PIOBU_DET_OFFSET + pin); | ||
| 64 | |||
| 65 | ret = regmap_update_bits(piobu->regmap, PIOBU_BMPR, mask, 0); | ||
| 66 | if (ret) | ||
| 67 | return ret; | ||
| 68 | |||
| 69 | ret = regmap_update_bits(piobu->regmap, PIOBU_NMPR, mask, 0); | ||
| 70 | if (ret) | ||
| 71 | return ret; | ||
| 72 | |||
| 73 | return regmap_update_bits(piobu->regmap, PIOBU_WKPR, mask, 0); | ||
| 74 | } | ||
| 75 | |||
| 76 | /** | ||
| 77 | * sama5d2_piobu_write_value() - writes value & mask at the pin's PIOBU register | ||
| 78 | */ | ||
| 79 | static int sama5d2_piobu_write_value(struct gpio_chip *chip, unsigned int pin, | ||
| 80 | unsigned int mask, unsigned int value) | ||
| 81 | { | ||
| 82 | int reg; | ||
| 83 | struct sama5d2_piobu *piobu = container_of(chip, struct sama5d2_piobu, | ||
| 84 | chip); | ||
| 85 | |||
| 86 | reg = PIOBU_BASE + pin * PIOBU_REG_SIZE; | ||
| 87 | |||
| 88 | return regmap_update_bits(piobu->regmap, reg, mask, value); | ||
| 89 | } | ||
| 90 | |||
| 91 | /** | ||
| 92 | * sama5d2_piobu_read_value() - read the value with masking from the pin's PIOBU | ||
| 93 | * register | ||
| 94 | */ | ||
| 95 | static int sama5d2_piobu_read_value(struct gpio_chip *chip, unsigned int pin, | ||
| 96 | unsigned int mask) | ||
| 97 | { | ||
| 98 | struct sama5d2_piobu *piobu = container_of(chip, struct sama5d2_piobu, | ||
| 99 | chip); | ||
| 100 | unsigned int val, reg; | ||
| 101 | int ret; | ||
| 102 | |||
| 103 | reg = PIOBU_BASE + pin * PIOBU_REG_SIZE; | ||
| 104 | ret = regmap_read(piobu->regmap, reg, &val); | ||
| 105 | if (ret < 0) | ||
| 106 | return ret; | ||
| 107 | |||
| 108 | return val & mask; | ||
| 109 | } | ||
| 110 | |||
| 111 | /** | ||
| 112 | * sama5d2_piobu_set_direction() - mark pin as input or output | ||
| 113 | */ | ||
| 114 | static int sama5d2_piobu_set_direction(struct gpio_chip *chip, | ||
| 115 | unsigned int direction, | ||
| 116 | unsigned int pin) | ||
| 117 | { | ||
| 118 | return sama5d2_piobu_write_value(chip, pin, PIOBU_DIRECTION, direction); | ||
| 119 | } | ||
| 120 | |||
| 121 | /** | ||
| 122 | * sama5d2_piobu_get_direction() - gpiochip get_direction | ||
| 123 | */ | ||
| 124 | static int sama5d2_piobu_get_direction(struct gpio_chip *chip, | ||
| 125 | unsigned int pin) | ||
| 126 | { | ||
| 127 | int ret = sama5d2_piobu_read_value(chip, pin, PIOBU_DIRECTION); | ||
| 128 | |||
| 129 | if (ret < 0) | ||
| 130 | return ret; | ||
| 131 | |||
| 132 | return (ret == PIOBU_IN) ? 1 : 0; | ||
| 133 | } | ||
| 134 | |||
| 135 | /** | ||
| 136 | * sama5d2_piobu_direction_input() - gpiochip direction_input | ||
| 137 | */ | ||
| 138 | static int sama5d2_piobu_direction_input(struct gpio_chip *chip, | ||
| 139 | unsigned int pin) | ||
| 140 | { | ||
| 141 | return sama5d2_piobu_set_direction(chip, PIOBU_IN, pin); | ||
| 142 | } | ||
| 143 | |||
| 144 | /** | ||
| 145 | * sama5d2_piobu_direction_output() - gpiochip direction_output | ||
| 146 | */ | ||
| 147 | static int sama5d2_piobu_direction_output(struct gpio_chip *chip, | ||
| 148 | unsigned int pin, int value) | ||
| 149 | { | ||
| 150 | return sama5d2_piobu_set_direction(chip, PIOBU_OUT, pin); | ||
| 151 | } | ||
| 152 | |||
| 153 | /** | ||
| 154 | * sama5d2_piobu_get() - gpiochip get | ||
| 155 | */ | ||
| 156 | static int sama5d2_piobu_get(struct gpio_chip *chip, unsigned int pin) | ||
| 157 | { | ||
| 158 | /* if pin is input, read value from PDS else read from SOD */ | ||
| 159 | int ret = sama5d2_piobu_get_direction(chip, pin); | ||
| 160 | |||
| 161 | if (ret == 1) | ||
| 162 | ret = sama5d2_piobu_read_value(chip, pin, PIOBU_PDS); | ||
| 163 | else if (!ret) | ||
| 164 | ret = sama5d2_piobu_read_value(chip, pin, PIOBU_SOD); | ||
| 165 | |||
| 166 | if (ret < 0) | ||
| 167 | return ret; | ||
| 168 | |||
| 169 | return !!ret; | ||
| 170 | } | ||
| 171 | |||
| 172 | /** | ||
| 173 | * sama5d2_piobu_set() - gpiochip set | ||
| 174 | */ | ||
| 175 | static void sama5d2_piobu_set(struct gpio_chip *chip, unsigned int pin, | ||
| 176 | int value) | ||
| 177 | { | ||
| 178 | if (!value) | ||
| 179 | value = PIOBU_LOW; | ||
| 180 | else | ||
| 181 | value = PIOBU_HIGH; | ||
| 182 | |||
| 183 | sama5d2_piobu_write_value(chip, pin, PIOBU_SOD, value); | ||
| 184 | } | ||
| 185 | |||
| 186 | static int sama5d2_piobu_probe(struct platform_device *pdev) | ||
| 187 | { | ||
| 188 | struct sama5d2_piobu *piobu; | ||
| 189 | int ret, i; | ||
| 190 | |||
| 191 | piobu = devm_kzalloc(&pdev->dev, sizeof(*piobu), GFP_KERNEL); | ||
| 192 | if (!piobu) | ||
| 193 | return -ENOMEM; | ||
| 194 | |||
| 195 | platform_set_drvdata(pdev, piobu); | ||
| 196 | piobu->chip.label = pdev->name; | ||
| 197 | piobu->chip.parent = &pdev->dev; | ||
| 198 | piobu->chip.of_node = pdev->dev.of_node; | ||
| 199 | piobu->chip.owner = THIS_MODULE, | ||
| 200 | piobu->chip.get_direction = sama5d2_piobu_get_direction, | ||
| 201 | piobu->chip.direction_input = sama5d2_piobu_direction_input, | ||
| 202 | piobu->chip.direction_output = sama5d2_piobu_direction_output, | ||
| 203 | piobu->chip.get = sama5d2_piobu_get, | ||
| 204 | piobu->chip.set = sama5d2_piobu_set, | ||
| 205 | piobu->chip.base = -1, | ||
| 206 | piobu->chip.ngpio = PIOBU_NUM, | ||
| 207 | piobu->chip.can_sleep = 0, | ||
| 208 | |||
| 209 | piobu->regmap = syscon_node_to_regmap(pdev->dev.of_node); | ||
| 210 | if (IS_ERR(piobu->regmap)) { | ||
| 211 | dev_err(&pdev->dev, "Failed to get syscon regmap %ld\n", | ||
| 212 | PTR_ERR(piobu->regmap)); | ||
| 213 | return PTR_ERR(piobu->regmap); | ||
| 214 | } | ||
| 215 | |||
| 216 | ret = devm_gpiochip_add_data(&pdev->dev, &piobu->chip, piobu); | ||
| 217 | if (ret) { | ||
| 218 | dev_err(&pdev->dev, "Failed to add gpiochip %d\n", ret); | ||
| 219 | return ret; | ||
| 220 | } | ||
| 221 | |||
| 222 | for (i = 0; i < PIOBU_NUM; ++i) { | ||
| 223 | ret = sama5d2_piobu_setup_pin(&piobu->chip, i); | ||
| 224 | if (ret) { | ||
| 225 | dev_err(&pdev->dev, "Failed to setup pin: %d %d\n", | ||
| 226 | i, ret); | ||
| 227 | return ret; | ||
| 228 | } | ||
| 229 | } | ||
| 230 | |||
| 231 | return 0; | ||
| 232 | } | ||
| 233 | |||
| 234 | static const struct of_device_id sama5d2_piobu_ids[] = { | ||
| 235 | { .compatible = "atmel,sama5d2-secumod" }, | ||
| 236 | {}, | ||
| 237 | }; | ||
| 238 | MODULE_DEVICE_TABLE(of, sama5d2_piobu_ids); | ||
| 239 | |||
| 240 | static struct platform_driver sama5d2_piobu_driver = { | ||
| 241 | .driver = { | ||
| 242 | .name = "sama5d2-piobu", | ||
| 243 | .of_match_table = of_match_ptr(sama5d2_piobu_ids) | ||
| 244 | }, | ||
| 245 | .probe = sama5d2_piobu_probe, | ||
| 246 | }; | ||
| 247 | |||
| 248 | module_platform_driver(sama5d2_piobu_driver); | ||
| 249 | |||
| 250 | MODULE_VERSION("1.0"); | ||
| 251 | MODULE_LICENSE("GPL v2"); | ||
| 252 | MODULE_DESCRIPTION("SAMA5D2 PIOBU controller driver"); | ||
| 253 | MODULE_AUTHOR("Andrei Stefanescu <andrei.stefanescu@microchip.com>"); | ||
diff --git a/drivers/gpio/gpio-sch.c b/drivers/gpio/gpio-sch.c index e9878f6ede67..c333046d02b8 100644 --- a/drivers/gpio/gpio-sch.c +++ b/drivers/gpio/gpio-sch.c | |||
| @@ -1,32 +1,19 @@ | |||
| 1 | // SPDX-License-Identifier: GPL-2.0 | ||
| 1 | /* | 2 | /* |
| 2 | * GPIO interface for Intel Poulsbo SCH | 3 | * GPIO interface for Intel Poulsbo SCH |
| 3 | * | 4 | * |
| 4 | * Copyright (c) 2010 CompuLab Ltd | 5 | * Copyright (c) 2010 CompuLab Ltd |
| 5 | * Author: Denis Turischev <denis@compulab.co.il> | 6 | * Author: Denis Turischev <denis@compulab.co.il> |
| 6 | * | ||
| 7 | * This program is free software; you can redistribute it and/or modify | ||
| 8 | * it under the terms of the GNU General Public License 2 as published | ||
| 9 | * by the Free Software Foundation. | ||
| 10 | * | ||
| 11 | * This program is distributed in the hope that it will be useful, | ||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | * GNU General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU General Public License | ||
| 17 | * along with this program; see the file COPYING. If not, write to | ||
| 18 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | ||
| 19 | */ | 7 | */ |
| 20 | 8 | ||
| 21 | #include <linux/init.h> | 9 | #include <linux/acpi.h> |
| 10 | #include <linux/errno.h> | ||
| 11 | #include <linux/gpio/driver.h> | ||
| 12 | #include <linux/io.h> | ||
| 22 | #include <linux/kernel.h> | 13 | #include <linux/kernel.h> |
| 23 | #include <linux/module.h> | 14 | #include <linux/module.h> |
| 24 | #include <linux/io.h> | ||
| 25 | #include <linux/errno.h> | ||
| 26 | #include <linux/acpi.h> | ||
| 27 | #include <linux/platform_device.h> | ||
| 28 | #include <linux/pci_ids.h> | 15 | #include <linux/pci_ids.h> |
| 29 | #include <linux/gpio/driver.h> | 16 | #include <linux/platform_device.h> |
| 30 | 17 | ||
| 31 | #define GEN 0x00 | 18 | #define GEN 0x00 |
| 32 | #define GIO 0x04 | 19 | #define GIO 0x04 |
| @@ -235,5 +222,5 @@ module_platform_driver(sch_gpio_driver); | |||
| 235 | 222 | ||
| 236 | MODULE_AUTHOR("Denis Turischev <denis@compulab.co.il>"); | 223 | MODULE_AUTHOR("Denis Turischev <denis@compulab.co.il>"); |
| 237 | MODULE_DESCRIPTION("GPIO interface for Intel Poulsbo SCH"); | 224 | MODULE_DESCRIPTION("GPIO interface for Intel Poulsbo SCH"); |
| 238 | MODULE_LICENSE("GPL"); | 225 | MODULE_LICENSE("GPL v2"); |
| 239 | MODULE_ALIAS("platform:sch_gpio"); | 226 | MODULE_ALIAS("platform:sch_gpio"); |
diff --git a/drivers/gpio/gpio-sch311x.c b/drivers/gpio/gpio-sch311x.c index 5497f0a88cf0..4df5335469fd 100644 --- a/drivers/gpio/gpio-sch311x.c +++ b/drivers/gpio/gpio-sch311x.c | |||
| @@ -188,7 +188,7 @@ static void sch311x_gpio_set(struct gpio_chip *chip, unsigned offset, | |||
| 188 | struct sch311x_gpio_block *block = gpiochip_get_data(chip); | 188 | struct sch311x_gpio_block *block = gpiochip_get_data(chip); |
| 189 | 189 | ||
| 190 | spin_lock(&block->lock); | 190 | spin_lock(&block->lock); |
| 191 | __sch311x_gpio_set(block, offset, value); | 191 | __sch311x_gpio_set(block, offset, value); |
| 192 | spin_unlock(&block->lock); | 192 | spin_unlock(&block->lock); |
| 193 | } | 193 | } |
| 194 | 194 | ||
diff --git a/drivers/gpio/gpio-sodaville.c b/drivers/gpio/gpio-sodaville.c index f60da83349ef..aed988e78251 100644 --- a/drivers/gpio/gpio-sodaville.c +++ b/drivers/gpio/gpio-sodaville.c | |||
| @@ -1,26 +1,22 @@ | |||
| 1 | // SPDX-License-Identifier: GPL-2.0 | ||
| 1 | /* | 2 | /* |
| 2 | * GPIO interface for Intel Sodaville SoCs. | 3 | * GPIO interface for Intel Sodaville SoCs. |
| 3 | * | 4 | * |
| 4 | * Copyright (c) 2010, 2011 Intel Corporation | 5 | * Copyright (c) 2010, 2011 Intel Corporation |
| 5 | * | 6 | * |
| 6 | * Author: Hans J. Koch <hjk@linutronix.de> | 7 | * Author: Hans J. Koch <hjk@linutronix.de> |
| 7 | * | ||
| 8 | * This program is free software; you can redistribute it and/or modify | ||
| 9 | * it under the terms of the GNU General Public License 2 as published | ||
| 10 | * by the Free Software Foundation. | ||
| 11 | * | ||
| 12 | */ | 8 | */ |
| 13 | 9 | ||
| 14 | #include <linux/errno.h> | 10 | #include <linux/errno.h> |
| 11 | #include <linux/gpio/driver.h> | ||
| 15 | #include <linux/init.h> | 12 | #include <linux/init.h> |
| 13 | #include <linux/interrupt.h> | ||
| 16 | #include <linux/io.h> | 14 | #include <linux/io.h> |
| 17 | #include <linux/irq.h> | 15 | #include <linux/irq.h> |
| 18 | #include <linux/interrupt.h> | ||
| 19 | #include <linux/kernel.h> | 16 | #include <linux/kernel.h> |
| 17 | #include <linux/of_irq.h> | ||
| 20 | #include <linux/pci.h> | 18 | #include <linux/pci.h> |
| 21 | #include <linux/platform_device.h> | 19 | #include <linux/platform_device.h> |
| 22 | #include <linux/of_irq.h> | ||
| 23 | #include <linux/gpio/driver.h> | ||
| 24 | 20 | ||
| 25 | #define DRV_NAME "sdv_gpio" | 21 | #define DRV_NAME "sdv_gpio" |
| 26 | #define SDV_NUM_PUB_GPIOS 12 | 22 | #define SDV_NUM_PUB_GPIOS 12 |
| @@ -80,18 +76,15 @@ static int sdv_gpio_pub_set_type(struct irq_data *d, unsigned int type) | |||
| 80 | static irqreturn_t sdv_gpio_pub_irq_handler(int irq, void *data) | 76 | static irqreturn_t sdv_gpio_pub_irq_handler(int irq, void *data) |
| 81 | { | 77 | { |
| 82 | struct sdv_gpio_chip_data *sd = data; | 78 | struct sdv_gpio_chip_data *sd = data; |
| 83 | u32 irq_stat = readl(sd->gpio_pub_base + GPSTR); | 79 | unsigned long irq_stat = readl(sd->gpio_pub_base + GPSTR); |
| 80 | int irq_bit; | ||
| 84 | 81 | ||
| 85 | irq_stat &= readl(sd->gpio_pub_base + GPIO_INT); | 82 | irq_stat &= readl(sd->gpio_pub_base + GPIO_INT); |
| 86 | if (!irq_stat) | 83 | if (!irq_stat) |
| 87 | return IRQ_NONE; | 84 | return IRQ_NONE; |
| 88 | 85 | ||
| 89 | while (irq_stat) { | 86 | for_each_set_bit(irq_bit, &irq_stat, 32) |
| 90 | u32 irq_bit = __fls(irq_stat); | ||
| 91 | |||
| 92 | irq_stat &= ~BIT(irq_bit); | ||
| 93 | generic_handle_irq(irq_find_mapping(sd->id, irq_bit)); | 87 | generic_handle_irq(irq_find_mapping(sd->id, irq_bit)); |
| 94 | } | ||
| 95 | 88 | ||
| 96 | return IRQ_HANDLED; | 89 | return IRQ_HANDLED; |
| 97 | } | 90 | } |
| @@ -155,8 +148,10 @@ static int sdv_register_irqsupport(struct sdv_gpio_chip_data *sd, | |||
| 155 | * we unmask & ACK the IRQ before the source of the interrupt is gone | 148 | * we unmask & ACK the IRQ before the source of the interrupt is gone |
| 156 | * then the interrupt is active again. | 149 | * then the interrupt is active again. |
| 157 | */ | 150 | */ |
| 158 | sd->gc = irq_alloc_generic_chip("sdv-gpio", 1, sd->irq_base, | 151 | sd->gc = devm_irq_alloc_generic_chip(&pdev->dev, "sdv-gpio", 1, |
| 159 | sd->gpio_pub_base, handle_fasteoi_irq); | 152 | sd->irq_base, |
| 153 | sd->gpio_pub_base, | ||
| 154 | handle_fasteoi_irq); | ||
| 160 | if (!sd->gc) | 155 | if (!sd->gc) |
| 161 | return -ENOMEM; | 156 | return -ENOMEM; |
| 162 | 157 | ||
| @@ -186,70 +181,52 @@ static int sdv_gpio_probe(struct pci_dev *pdev, | |||
| 186 | const struct pci_device_id *pci_id) | 181 | const struct pci_device_id *pci_id) |
| 187 | { | 182 | { |
| 188 | struct sdv_gpio_chip_data *sd; | 183 | struct sdv_gpio_chip_data *sd; |
| 189 | unsigned long addr; | ||
| 190 | const void *prop; | ||
| 191 | int len; | ||
| 192 | int ret; | 184 | int ret; |
| 193 | u32 mux_val; | 185 | u32 mux_val; |
| 194 | 186 | ||
| 195 | sd = kzalloc(sizeof(struct sdv_gpio_chip_data), GFP_KERNEL); | 187 | sd = devm_kzalloc(&pdev->dev, sizeof(*sd), GFP_KERNEL); |
| 196 | if (!sd) | 188 | if (!sd) |
| 197 | return -ENOMEM; | 189 | return -ENOMEM; |
| 198 | ret = pci_enable_device(pdev); | 190 | |
| 191 | ret = pcim_enable_device(pdev); | ||
| 199 | if (ret) { | 192 | if (ret) { |
| 200 | dev_err(&pdev->dev, "can't enable device.\n"); | 193 | dev_err(&pdev->dev, "can't enable device.\n"); |
| 201 | goto done; | 194 | return ret; |
| 202 | } | 195 | } |
| 203 | 196 | ||
| 204 | ret = pci_request_region(pdev, GPIO_BAR, DRV_NAME); | 197 | ret = pcim_iomap_regions(pdev, 1 << GPIO_BAR, DRV_NAME); |
| 205 | if (ret) { | 198 | if (ret) { |
| 206 | dev_err(&pdev->dev, "can't alloc PCI BAR #%d\n", GPIO_BAR); | 199 | dev_err(&pdev->dev, "can't alloc PCI BAR #%d\n", GPIO_BAR); |
| 207 | goto disable_pci; | 200 | return ret; |
| 208 | } | 201 | } |
| 209 | 202 | ||
| 210 | addr = pci_resource_start(pdev, GPIO_BAR); | 203 | sd->gpio_pub_base = pcim_iomap_table(pdev)[GPIO_BAR]; |
| 211 | if (!addr) { | ||
| 212 | ret = -ENODEV; | ||
| 213 | goto release_reg; | ||
| 214 | } | ||
| 215 | sd->gpio_pub_base = ioremap(addr, pci_resource_len(pdev, GPIO_BAR)); | ||
| 216 | 204 | ||
| 217 | prop = of_get_property(pdev->dev.of_node, "intel,muxctl", &len); | 205 | ret = of_property_read_u32(pdev->dev.of_node, "intel,muxctl", &mux_val); |
| 218 | if (prop && len == 4) { | 206 | if (!ret) |
| 219 | mux_val = of_read_number(prop, 1); | ||
| 220 | writel(mux_val, sd->gpio_pub_base + GPMUXCTL); | 207 | writel(mux_val, sd->gpio_pub_base + GPMUXCTL); |
| 221 | } | ||
| 222 | 208 | ||
| 223 | ret = bgpio_init(&sd->chip, &pdev->dev, 4, | 209 | ret = bgpio_init(&sd->chip, &pdev->dev, 4, |
| 224 | sd->gpio_pub_base + GPINR, sd->gpio_pub_base + GPOUTR, | 210 | sd->gpio_pub_base + GPINR, sd->gpio_pub_base + GPOUTR, |
| 225 | NULL, sd->gpio_pub_base + GPOER, NULL, 0); | 211 | NULL, sd->gpio_pub_base + GPOER, NULL, 0); |
| 226 | if (ret) | 212 | if (ret) |
| 227 | goto unmap; | 213 | return ret; |
| 214 | |||
| 228 | sd->chip.ngpio = SDV_NUM_PUB_GPIOS; | 215 | sd->chip.ngpio = SDV_NUM_PUB_GPIOS; |
| 229 | 216 | ||
| 230 | ret = gpiochip_add_data(&sd->chip, sd); | 217 | ret = devm_gpiochip_add_data(&pdev->dev, &sd->chip, sd); |
| 231 | if (ret < 0) { | 218 | if (ret < 0) { |
| 232 | dev_err(&pdev->dev, "gpiochip_add() failed.\n"); | 219 | dev_err(&pdev->dev, "gpiochip_add() failed.\n"); |
| 233 | goto unmap; | 220 | return ret; |
| 234 | } | 221 | } |
| 235 | 222 | ||
| 236 | ret = sdv_register_irqsupport(sd, pdev); | 223 | ret = sdv_register_irqsupport(sd, pdev); |
| 237 | if (ret) | 224 | if (ret) |
| 238 | goto unmap; | 225 | return ret; |
| 239 | 226 | ||
| 240 | pci_set_drvdata(pdev, sd); | 227 | pci_set_drvdata(pdev, sd); |
| 241 | dev_info(&pdev->dev, "Sodaville GPIO driver registered.\n"); | 228 | dev_info(&pdev->dev, "Sodaville GPIO driver registered.\n"); |
| 242 | return 0; | 229 | return 0; |
| 243 | |||
| 244 | unmap: | ||
| 245 | iounmap(sd->gpio_pub_base); | ||
| 246 | release_reg: | ||
| 247 | pci_release_region(pdev, GPIO_BAR); | ||
| 248 | disable_pci: | ||
| 249 | pci_disable_device(pdev); | ||
| 250 | done: | ||
| 251 | kfree(sd); | ||
| 252 | return ret; | ||
| 253 | } | 230 | } |
| 254 | 231 | ||
| 255 | static const struct pci_device_id sdv_gpio_pci_ids[] = { | 232 | static const struct pci_device_id sdv_gpio_pci_ids[] = { |
diff --git a/drivers/gpio/gpio-tegra.c b/drivers/gpio/gpio-tegra.c index 47dbd19751d0..02f6db925fd5 100644 --- a/drivers/gpio/gpio-tegra.c +++ b/drivers/gpio/gpio-tegra.c | |||
| @@ -404,8 +404,7 @@ static void tegra_gpio_irq_handler(struct irq_desc *desc) | |||
| 404 | #ifdef CONFIG_PM_SLEEP | 404 | #ifdef CONFIG_PM_SLEEP |
| 405 | static int tegra_gpio_resume(struct device *dev) | 405 | static int tegra_gpio_resume(struct device *dev) |
| 406 | { | 406 | { |
| 407 | struct platform_device *pdev = to_platform_device(dev); | 407 | struct tegra_gpio_info *tgi = dev_get_drvdata(dev); |
| 408 | struct tegra_gpio_info *tgi = platform_get_drvdata(pdev); | ||
| 409 | unsigned long flags; | 408 | unsigned long flags; |
| 410 | unsigned int b, p; | 409 | unsigned int b, p; |
| 411 | 410 | ||
| @@ -444,8 +443,7 @@ static int tegra_gpio_resume(struct device *dev) | |||
| 444 | 443 | ||
| 445 | static int tegra_gpio_suspend(struct device *dev) | 444 | static int tegra_gpio_suspend(struct device *dev) |
| 446 | { | 445 | { |
| 447 | struct platform_device *pdev = to_platform_device(dev); | 446 | struct tegra_gpio_info *tgi = dev_get_drvdata(dev); |
| 448 | struct tegra_gpio_info *tgi = platform_get_drvdata(pdev); | ||
| 449 | unsigned long flags; | 447 | unsigned long flags; |
| 450 | unsigned int b, p; | 448 | unsigned int b, p; |
| 451 | 449 | ||
diff --git a/drivers/gpio/gpio-tegra186.c b/drivers/gpio/gpio-tegra186.c index 9d0292c8a199..66ec38bb7954 100644 --- a/drivers/gpio/gpio-tegra186.c +++ b/drivers/gpio/gpio-tegra186.c | |||
| @@ -279,7 +279,7 @@ static void tegra186_irq_unmask(struct irq_data *data) | |||
| 279 | writel(value, base + TEGRA186_GPIO_ENABLE_CONFIG); | 279 | writel(value, base + TEGRA186_GPIO_ENABLE_CONFIG); |
| 280 | } | 280 | } |
| 281 | 281 | ||
| 282 | static int tegra186_irq_set_type(struct irq_data *data, unsigned int flow) | 282 | static int tegra186_irq_set_type(struct irq_data *data, unsigned int type) |
| 283 | { | 283 | { |
| 284 | struct tegra_gpio *gpio = irq_data_get_irq_chip_data(data); | 284 | struct tegra_gpio *gpio = irq_data_get_irq_chip_data(data); |
| 285 | void __iomem *base; | 285 | void __iomem *base; |
| @@ -293,7 +293,7 @@ static int tegra186_irq_set_type(struct irq_data *data, unsigned int flow) | |||
| 293 | value &= ~TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_MASK; | 293 | value &= ~TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_MASK; |
| 294 | value &= ~TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_LEVEL; | 294 | value &= ~TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_LEVEL; |
| 295 | 295 | ||
| 296 | switch (flow & IRQ_TYPE_SENSE_MASK) { | 296 | switch (type & IRQ_TYPE_SENSE_MASK) { |
| 297 | case IRQ_TYPE_NONE: | 297 | case IRQ_TYPE_NONE: |
| 298 | break; | 298 | break; |
| 299 | 299 | ||
| @@ -325,7 +325,7 @@ static int tegra186_irq_set_type(struct irq_data *data, unsigned int flow) | |||
| 325 | 325 | ||
| 326 | writel(value, base + TEGRA186_GPIO_ENABLE_CONFIG); | 326 | writel(value, base + TEGRA186_GPIO_ENABLE_CONFIG); |
| 327 | 327 | ||
| 328 | if ((flow & IRQ_TYPE_EDGE_BOTH) == 0) | 328 | if ((type & IRQ_TYPE_EDGE_BOTH) == 0) |
| 329 | irq_set_handler_locked(data, handle_level_irq); | 329 | irq_set_handler_locked(data, handle_level_irq); |
| 330 | else | 330 | else |
| 331 | irq_set_handler_locked(data, handle_edge_irq); | 331 | irq_set_handler_locked(data, handle_edge_irq); |
diff --git a/drivers/gpio/gpio-uniphier.c b/drivers/gpio/gpio-uniphier.c index 74551cbdb2e8..0f662b297a95 100644 --- a/drivers/gpio/gpio-uniphier.c +++ b/drivers/gpio/gpio-uniphier.c | |||
| @@ -1,16 +1,7 @@ | |||
| 1 | /* | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | * Copyright (C) 2017 Socionext Inc. | 2 | // |
| 3 | * Author: Masahiro Yamada <yamada.masahiro@socionext.com> | 3 | // Copyright (C) 2017 Socionext Inc. |
| 4 | * | 4 | // Author: Masahiro Yamada <yamada.masahiro@socionext.com> |
| 5 | * This program is free software; you can redistribute it and/or modify | ||
| 6 | * it under the terms of the GNU General Public License version 2 as | ||
| 7 | * published by the Free Software Foundation. | ||
| 8 | * | ||
| 9 | * This program is distributed in the hope that it will be useful, | ||
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | * GNU General Public License for more details. | ||
| 13 | */ | ||
| 14 | 5 | ||
| 15 | #include <linux/bits.h> | 6 | #include <linux/bits.h> |
| 16 | #include <linux/gpio/driver.h> | 7 | #include <linux/gpio/driver.h> |
diff --git a/drivers/gpio/gpio-vf610.c b/drivers/gpio/gpio-vf610.c index 5960396c8d9a..1b79ebcfce3e 100644 --- a/drivers/gpio/gpio-vf610.c +++ b/drivers/gpio/gpio-vf610.c | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | * Author: Stefan Agner <stefan@agner.ch>. | 7 | * Author: Stefan Agner <stefan@agner.ch>. |
| 8 | */ | 8 | */ |
| 9 | #include <linux/bitops.h> | 9 | #include <linux/bitops.h> |
| 10 | #include <linux/clk.h> | ||
| 10 | #include <linux/err.h> | 11 | #include <linux/err.h> |
| 11 | #include <linux/gpio/driver.h> | 12 | #include <linux/gpio/driver.h> |
| 12 | #include <linux/init.h> | 13 | #include <linux/init.h> |
| @@ -32,6 +33,8 @@ struct vf610_gpio_port { | |||
| 32 | void __iomem *gpio_base; | 33 | void __iomem *gpio_base; |
| 33 | const struct fsl_gpio_soc_data *sdata; | 34 | const struct fsl_gpio_soc_data *sdata; |
| 34 | u8 irqc[VF610_GPIO_PER_PORT]; | 35 | u8 irqc[VF610_GPIO_PER_PORT]; |
| 36 | struct clk *clk_port; | ||
| 37 | struct clk *clk_gpio; | ||
| 35 | int irq; | 38 | int irq; |
| 36 | }; | 39 | }; |
| 37 | 40 | ||
| @@ -271,6 +274,33 @@ static int vf610_gpio_probe(struct platform_device *pdev) | |||
| 271 | if (port->irq < 0) | 274 | if (port->irq < 0) |
| 272 | return port->irq; | 275 | return port->irq; |
| 273 | 276 | ||
| 277 | port->clk_port = devm_clk_get(&pdev->dev, "port"); | ||
| 278 | if (!IS_ERR(port->clk_port)) { | ||
| 279 | ret = clk_prepare_enable(port->clk_port); | ||
| 280 | if (ret) | ||
| 281 | return ret; | ||
| 282 | } else if (port->clk_port == ERR_PTR(-EPROBE_DEFER)) { | ||
| 283 | /* | ||
| 284 | * Percolate deferrals, for anything else, | ||
| 285 | * just live without the clocking. | ||
| 286 | */ | ||
| 287 | return PTR_ERR(port->clk_port); | ||
| 288 | } | ||
| 289 | |||
| 290 | port->clk_gpio = devm_clk_get(&pdev->dev, "gpio"); | ||
| 291 | if (!IS_ERR(port->clk_gpio)) { | ||
| 292 | ret = clk_prepare_enable(port->clk_gpio); | ||
| 293 | if (ret) { | ||
| 294 | clk_disable_unprepare(port->clk_port); | ||
| 295 | return ret; | ||
| 296 | } | ||
| 297 | } else if (port->clk_gpio == ERR_PTR(-EPROBE_DEFER)) { | ||
| 298 | clk_disable_unprepare(port->clk_port); | ||
| 299 | return PTR_ERR(port->clk_gpio); | ||
| 300 | } | ||
| 301 | |||
| 302 | platform_set_drvdata(pdev, port); | ||
| 303 | |||
| 274 | gc = &port->gc; | 304 | gc = &port->gc; |
| 275 | gc->of_node = np; | 305 | gc->of_node = np; |
| 276 | gc->parent = dev; | 306 | gc->parent = dev; |
| @@ -305,12 +335,26 @@ static int vf610_gpio_probe(struct platform_device *pdev) | |||
| 305 | return 0; | 335 | return 0; |
| 306 | } | 336 | } |
| 307 | 337 | ||
| 338 | static int vf610_gpio_remove(struct platform_device *pdev) | ||
| 339 | { | ||
| 340 | struct vf610_gpio_port *port = platform_get_drvdata(pdev); | ||
| 341 | |||
| 342 | gpiochip_remove(&port->gc); | ||
| 343 | if (!IS_ERR(port->clk_port)) | ||
| 344 | clk_disable_unprepare(port->clk_port); | ||
| 345 | if (!IS_ERR(port->clk_gpio)) | ||
| 346 | clk_disable_unprepare(port->clk_gpio); | ||
| 347 | |||
| 348 | return 0; | ||
| 349 | } | ||
| 350 | |||
| 308 | static struct platform_driver vf610_gpio_driver = { | 351 | static struct platform_driver vf610_gpio_driver = { |
| 309 | .driver = { | 352 | .driver = { |
| 310 | .name = "gpio-vf610", | 353 | .name = "gpio-vf610", |
| 311 | .of_match_table = vf610_gpio_dt_ids, | 354 | .of_match_table = vf610_gpio_dt_ids, |
| 312 | }, | 355 | }, |
| 313 | .probe = vf610_gpio_probe, | 356 | .probe = vf610_gpio_probe, |
| 357 | .remove = vf610_gpio_remove, | ||
| 314 | }; | 358 | }; |
| 315 | 359 | ||
| 316 | builtin_platform_driver(vf610_gpio_driver); | 360 | builtin_platform_driver(vf610_gpio_driver); |
diff --git a/drivers/gpio/gpio-ws16c48.c b/drivers/gpio/gpio-ws16c48.c index c7028eb0b8e1..5cf3697bfb15 100644 --- a/drivers/gpio/gpio-ws16c48.c +++ b/drivers/gpio/gpio-ws16c48.c | |||
| @@ -169,7 +169,7 @@ static int ws16c48_gpio_get_multiple(struct gpio_chip *chip, | |||
| 169 | port_state = inb(ws16c48gpio->base + i); | 169 | port_state = inb(ws16c48gpio->base + i); |
| 170 | 170 | ||
| 171 | /* store acquired bits at respective bits array offset */ | 171 | /* store acquired bits at respective bits array offset */ |
| 172 | bits[word_index] |= port_state << word_offset; | 172 | bits[word_index] |= (port_state << word_offset) & word_mask; |
| 173 | } | 173 | } |
| 174 | 174 | ||
| 175 | return 0; | 175 | return 0; |
diff --git a/drivers/gpio/gpio-zynq.c b/drivers/gpio/gpio-zynq.c index 3f5fcdd5a429..b3b4edcdffe0 100644 --- a/drivers/gpio/gpio-zynq.c +++ b/drivers/gpio/gpio-zynq.c | |||
| @@ -358,6 +358,28 @@ static int zynq_gpio_dir_out(struct gpio_chip *chip, unsigned int pin, | |||
| 358 | } | 358 | } |
| 359 | 359 | ||
| 360 | /** | 360 | /** |
| 361 | * zynq_gpio_get_direction - Read the direction of the specified GPIO pin | ||
| 362 | * @chip: gpio_chip instance to be worked on | ||
| 363 | * @pin: gpio pin number within the device | ||
| 364 | * | ||
| 365 | * This function returns the direction of the specified GPIO. | ||
| 366 | * | ||
| 367 | * Return: 0 for output, 1 for input | ||
| 368 | */ | ||
| 369 | static int zynq_gpio_get_direction(struct gpio_chip *chip, unsigned int pin) | ||
| 370 | { | ||
| 371 | u32 reg; | ||
| 372 | unsigned int bank_num, bank_pin_num; | ||
| 373 | struct zynq_gpio *gpio = gpiochip_get_data(chip); | ||
| 374 | |||
| 375 | zynq_gpio_get_bank_pin(pin, &bank_num, &bank_pin_num, gpio); | ||
| 376 | |||
| 377 | reg = readl_relaxed(gpio->base_addr + ZYNQ_GPIO_DIRM_OFFSET(bank_num)); | ||
| 378 | |||
| 379 | return !(reg & BIT(bank_pin_num)); | ||
| 380 | } | ||
| 381 | |||
| 382 | /** | ||
| 361 | * zynq_gpio_irq_mask - Disable the interrupts for a gpio pin | 383 | * zynq_gpio_irq_mask - Disable the interrupts for a gpio pin |
| 362 | * @irq_data: per irq and chip data passed down to chip functions | 384 | * @irq_data: per irq and chip data passed down to chip functions |
| 363 | * | 385 | * |
| @@ -693,8 +715,7 @@ static int __maybe_unused zynq_gpio_resume(struct device *dev) | |||
| 693 | 715 | ||
| 694 | static int __maybe_unused zynq_gpio_runtime_suspend(struct device *dev) | 716 | static int __maybe_unused zynq_gpio_runtime_suspend(struct device *dev) |
| 695 | { | 717 | { |
| 696 | struct platform_device *pdev = to_platform_device(dev); | 718 | struct zynq_gpio *gpio = dev_get_drvdata(dev); |
| 697 | struct zynq_gpio *gpio = platform_get_drvdata(pdev); | ||
| 698 | 719 | ||
| 699 | clk_disable_unprepare(gpio->clk); | 720 | clk_disable_unprepare(gpio->clk); |
| 700 | 721 | ||
| @@ -703,8 +724,7 @@ static int __maybe_unused zynq_gpio_runtime_suspend(struct device *dev) | |||
| 703 | 724 | ||
| 704 | static int __maybe_unused zynq_gpio_runtime_resume(struct device *dev) | 725 | static int __maybe_unused zynq_gpio_runtime_resume(struct device *dev) |
| 705 | { | 726 | { |
| 706 | struct platform_device *pdev = to_platform_device(dev); | 727 | struct zynq_gpio *gpio = dev_get_drvdata(dev); |
| 707 | struct zynq_gpio *gpio = platform_get_drvdata(pdev); | ||
| 708 | 728 | ||
| 709 | return clk_prepare_enable(gpio->clk); | 729 | return clk_prepare_enable(gpio->clk); |
| 710 | } | 730 | } |
| @@ -827,6 +847,7 @@ static int zynq_gpio_probe(struct platform_device *pdev) | |||
| 827 | chip->free = zynq_gpio_free; | 847 | chip->free = zynq_gpio_free; |
| 828 | chip->direction_input = zynq_gpio_dir_in; | 848 | chip->direction_input = zynq_gpio_dir_in; |
| 829 | chip->direction_output = zynq_gpio_dir_out; | 849 | chip->direction_output = zynq_gpio_dir_out; |
| 850 | chip->get_direction = zynq_gpio_get_direction; | ||
| 830 | chip->base = of_alias_get_id(pdev->dev.of_node, "gpio"); | 851 | chip->base = of_alias_get_id(pdev->dev.of_node, "gpio"); |
| 831 | chip->ngpio = gpio->p_data->ngpio; | 852 | chip->ngpio = gpio->p_data->ngpio; |
| 832 | 853 | ||
diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c index 7f93954c58ea..48534bda73d3 100644 --- a/drivers/gpio/gpiolib-acpi.c +++ b/drivers/gpio/gpiolib-acpi.c | |||
| @@ -217,7 +217,7 @@ static acpi_status acpi_gpiochip_alloc_event(struct acpi_resource *ares, | |||
| 217 | if (!handler) | 217 | if (!handler) |
| 218 | return AE_OK; | 218 | return AE_OK; |
| 219 | 219 | ||
| 220 | desc = gpiochip_request_own_desc(chip, pin, "ACPI:Event"); | 220 | desc = gpiochip_request_own_desc(chip, pin, "ACPI:Event", 0); |
| 221 | if (IS_ERR(desc)) { | 221 | if (IS_ERR(desc)) { |
| 222 | dev_err(chip->parent, "Failed to request GPIO\n"); | 222 | dev_err(chip->parent, "Failed to request GPIO\n"); |
| 223 | return AE_ERROR; | 223 | return AE_ERROR; |
| @@ -913,23 +913,15 @@ acpi_gpio_adr_space_handler(u32 function, acpi_physical_address address, | |||
| 913 | if (!found) { | 913 | if (!found) { |
| 914 | enum gpiod_flags flags = acpi_gpio_to_gpiod_flags(agpio); | 914 | enum gpiod_flags flags = acpi_gpio_to_gpiod_flags(agpio); |
| 915 | const char *label = "ACPI:OpRegion"; | 915 | const char *label = "ACPI:OpRegion"; |
| 916 | int err; | ||
| 917 | 916 | ||
| 918 | desc = gpiochip_request_own_desc(chip, pin, label); | 917 | desc = gpiochip_request_own_desc(chip, pin, label, |
| 918 | flags); | ||
| 919 | if (IS_ERR(desc)) { | 919 | if (IS_ERR(desc)) { |
| 920 | status = AE_ERROR; | 920 | status = AE_ERROR; |
| 921 | mutex_unlock(&achip->conn_lock); | 921 | mutex_unlock(&achip->conn_lock); |
| 922 | goto out; | 922 | goto out; |
| 923 | } | 923 | } |
| 924 | 924 | ||
| 925 | err = gpiod_configure_flags(desc, label, 0, flags); | ||
| 926 | if (err < 0) { | ||
| 927 | status = AE_NOT_CONFIGURED; | ||
| 928 | gpiochip_free_own_desc(desc); | ||
| 929 | mutex_unlock(&achip->conn_lock); | ||
| 930 | goto out; | ||
| 931 | } | ||
| 932 | |||
| 933 | conn = kzalloc(sizeof(*conn), GFP_KERNEL); | 925 | conn = kzalloc(sizeof(*conn), GFP_KERNEL); |
| 934 | if (!conn) { | 926 | if (!conn) { |
| 935 | status = AE_NO_MEMORY; | 927 | status = AE_NO_MEMORY; |
diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index 7f1260c78270..a6e1891217e2 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | // SPDX-License-Identifier: GPL-2.0 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* | 2 | /* |
| 3 | * OF helpers for the GPIO API | 3 | * OF helpers for the GPIO API |
| 4 | * | 4 | * |
| @@ -54,10 +54,32 @@ static struct gpio_desc *of_xlate_and_get_gpiod_flags(struct gpio_chip *chip, | |||
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | static void of_gpio_flags_quirks(struct device_node *np, | 56 | static void of_gpio_flags_quirks(struct device_node *np, |
| 57 | const char *propname, | ||
| 57 | enum of_gpio_flags *flags, | 58 | enum of_gpio_flags *flags, |
| 58 | int index) | 59 | int index) |
| 59 | { | 60 | { |
| 60 | /* | 61 | /* |
| 62 | * Handle MMC "cd-inverted" and "wp-inverted" semantics. | ||
| 63 | */ | ||
| 64 | if (IS_ENABLED(CONFIG_MMC)) { | ||
| 65 | /* | ||
| 66 | * Active low is the default according to the | ||
| 67 | * SDHCI specification and the device tree | ||
| 68 | * bindings. However the code in the current | ||
| 69 | * kernel was written such that the phandle | ||
| 70 | * flags were always respected, and "cd-inverted" | ||
| 71 | * would invert the flag from the device phandle. | ||
| 72 | */ | ||
| 73 | if (!strcmp(propname, "cd-gpios")) { | ||
| 74 | if (of_property_read_bool(np, "cd-inverted")) | ||
| 75 | *flags ^= OF_GPIO_ACTIVE_LOW; | ||
| 76 | } | ||
| 77 | if (!strcmp(propname, "wp-gpios")) { | ||
| 78 | if (of_property_read_bool(np, "wp-inverted")) | ||
| 79 | *flags ^= OF_GPIO_ACTIVE_LOW; | ||
| 80 | } | ||
| 81 | } | ||
| 82 | /* | ||
| 61 | * Some GPIO fixed regulator quirks. | 83 | * Some GPIO fixed regulator quirks. |
| 62 | * Note that active low is the default. | 84 | * Note that active low is the default. |
| 63 | */ | 85 | */ |
| @@ -174,7 +196,7 @@ struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np, | |||
| 174 | goto out; | 196 | goto out; |
| 175 | 197 | ||
| 176 | if (flags) | 198 | if (flags) |
| 177 | of_gpio_flags_quirks(np, flags, index); | 199 | of_gpio_flags_quirks(np, propname, flags, index); |
| 178 | 200 | ||
| 179 | pr_debug("%s: parsed '%s' property of node '%pOF[%d]' - status (%d)\n", | 201 | pr_debug("%s: parsed '%s' property of node '%pOF[%d]' - status (%d)\n", |
| 180 | __func__, propname, np, index, | 202 | __func__, propname, np, index, |
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 985c09ce80fb..1651d7f0a303 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c | |||
| @@ -1512,19 +1512,6 @@ static void devm_gpio_chip_release(struct device *dev, void *res) | |||
| 1512 | gpiochip_remove(chip); | 1512 | gpiochip_remove(chip); |
| 1513 | } | 1513 | } |
| 1514 | 1514 | ||
| 1515 | static int devm_gpio_chip_match(struct device *dev, void *res, void *data) | ||
| 1516 | |||
| 1517 | { | ||
| 1518 | struct gpio_chip **r = res; | ||
| 1519 | |||
| 1520 | if (!r || !*r) { | ||
| 1521 | WARN_ON(!r || !*r); | ||
| 1522 | return 0; | ||
| 1523 | } | ||
| 1524 | |||
| 1525 | return *r == data; | ||
| 1526 | } | ||
| 1527 | |||
| 1528 | /** | 1515 | /** |
| 1529 | * devm_gpiochip_add_data() - Resource manager gpiochip_add_data() | 1516 | * devm_gpiochip_add_data() - Resource manager gpiochip_add_data() |
| 1530 | * @dev: pointer to the device that gpio_chip belongs to. | 1517 | * @dev: pointer to the device that gpio_chip belongs to. |
| @@ -1565,23 +1552,6 @@ int devm_gpiochip_add_data(struct device *dev, struct gpio_chip *chip, | |||
| 1565 | EXPORT_SYMBOL_GPL(devm_gpiochip_add_data); | 1552 | EXPORT_SYMBOL_GPL(devm_gpiochip_add_data); |
| 1566 | 1553 | ||
| 1567 | /** | 1554 | /** |
| 1568 | * devm_gpiochip_remove() - Resource manager of gpiochip_remove() | ||
| 1569 | * @dev: device for which which resource was allocated | ||
| 1570 | * @chip: the chip to remove | ||
| 1571 | * | ||
| 1572 | * A gpio_chip with any GPIOs still requested may not be removed. | ||
| 1573 | */ | ||
| 1574 | void devm_gpiochip_remove(struct device *dev, struct gpio_chip *chip) | ||
| 1575 | { | ||
| 1576 | int ret; | ||
| 1577 | |||
| 1578 | ret = devres_release(dev, devm_gpio_chip_release, | ||
| 1579 | devm_gpio_chip_match, chip); | ||
| 1580 | WARN_ON(ret); | ||
| 1581 | } | ||
| 1582 | EXPORT_SYMBOL_GPL(devm_gpiochip_remove); | ||
| 1583 | |||
| 1584 | /** | ||
| 1585 | * gpiochip_find() - iterator for locating a specific gpio_chip | 1555 | * gpiochip_find() - iterator for locating a specific gpio_chip |
| 1586 | * @data: data to pass to match function | 1556 | * @data: data to pass to match function |
| 1587 | * @match: Callback function to check gpio_chip | 1557 | * @match: Callback function to check gpio_chip |
| @@ -2299,6 +2269,12 @@ static int gpiod_request_commit(struct gpio_desc *desc, const char *label) | |||
| 2299 | unsigned long flags; | 2269 | unsigned long flags; |
| 2300 | unsigned offset; | 2270 | unsigned offset; |
| 2301 | 2271 | ||
| 2272 | if (label) { | ||
| 2273 | label = kstrdup_const(label, GFP_KERNEL); | ||
| 2274 | if (!label) | ||
| 2275 | return -ENOMEM; | ||
| 2276 | } | ||
| 2277 | |||
| 2302 | spin_lock_irqsave(&gpio_lock, flags); | 2278 | spin_lock_irqsave(&gpio_lock, flags); |
| 2303 | 2279 | ||
| 2304 | /* NOTE: gpio_request() can be called in early boot, | 2280 | /* NOTE: gpio_request() can be called in early boot, |
| @@ -2309,6 +2285,7 @@ static int gpiod_request_commit(struct gpio_desc *desc, const char *label) | |||
| 2309 | desc_set_label(desc, label ? : "?"); | 2285 | desc_set_label(desc, label ? : "?"); |
| 2310 | status = 0; | 2286 | status = 0; |
| 2311 | } else { | 2287 | } else { |
| 2288 | kfree_const(label); | ||
| 2312 | status = -EBUSY; | 2289 | status = -EBUSY; |
| 2313 | goto done; | 2290 | goto done; |
| 2314 | } | 2291 | } |
| @@ -2325,6 +2302,7 @@ static int gpiod_request_commit(struct gpio_desc *desc, const char *label) | |||
| 2325 | 2302 | ||
| 2326 | if (status < 0) { | 2303 | if (status < 0) { |
| 2327 | desc_set_label(desc, NULL); | 2304 | desc_set_label(desc, NULL); |
| 2305 | kfree_const(label); | ||
| 2328 | clear_bit(FLAG_REQUESTED, &desc->flags); | 2306 | clear_bit(FLAG_REQUESTED, &desc->flags); |
| 2329 | goto done; | 2307 | goto done; |
| 2330 | } | 2308 | } |
| @@ -2420,6 +2398,7 @@ static bool gpiod_free_commit(struct gpio_desc *desc) | |||
| 2420 | chip->free(chip, gpio_chip_hwgpio(desc)); | 2398 | chip->free(chip, gpio_chip_hwgpio(desc)); |
| 2421 | spin_lock_irqsave(&gpio_lock, flags); | 2399 | spin_lock_irqsave(&gpio_lock, flags); |
| 2422 | } | 2400 | } |
| 2401 | kfree_const(desc->label); | ||
| 2423 | desc_set_label(desc, NULL); | 2402 | desc_set_label(desc, NULL); |
| 2424 | clear_bit(FLAG_ACTIVE_LOW, &desc->flags); | 2403 | clear_bit(FLAG_ACTIVE_LOW, &desc->flags); |
| 2425 | clear_bit(FLAG_REQUESTED, &desc->flags); | 2404 | clear_bit(FLAG_REQUESTED, &desc->flags); |
| @@ -2476,6 +2455,7 @@ EXPORT_SYMBOL_GPL(gpiochip_is_requested); | |||
| 2476 | * @chip: GPIO chip | 2455 | * @chip: GPIO chip |
| 2477 | * @hwnum: hardware number of the GPIO for which to request the descriptor | 2456 | * @hwnum: hardware number of the GPIO for which to request the descriptor |
| 2478 | * @label: label for the GPIO | 2457 | * @label: label for the GPIO |
| 2458 | * @flags: flags for this GPIO or 0 if default | ||
| 2479 | * | 2459 | * |
| 2480 | * Function allows GPIO chip drivers to request and use their own GPIO | 2460 | * Function allows GPIO chip drivers to request and use their own GPIO |
| 2481 | * descriptors via gpiolib API. Difference to gpiod_request() is that this | 2461 | * descriptors via gpiolib API. Difference to gpiod_request() is that this |
| @@ -2488,7 +2468,8 @@ EXPORT_SYMBOL_GPL(gpiochip_is_requested); | |||
| 2488 | * code on failure. | 2468 | * code on failure. |
| 2489 | */ | 2469 | */ |
| 2490 | struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *chip, u16 hwnum, | 2470 | struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *chip, u16 hwnum, |
| 2491 | const char *label) | 2471 | const char *label, |
| 2472 | enum gpiod_flags flags) | ||
| 2492 | { | 2473 | { |
| 2493 | struct gpio_desc *desc = gpiochip_get_desc(chip, hwnum); | 2474 | struct gpio_desc *desc = gpiochip_get_desc(chip, hwnum); |
| 2494 | int err; | 2475 | int err; |
| @@ -2502,6 +2483,13 @@ struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *chip, u16 hwnum, | |||
| 2502 | if (err < 0) | 2483 | if (err < 0) |
| 2503 | return ERR_PTR(err); | 2484 | return ERR_PTR(err); |
| 2504 | 2485 | ||
| 2486 | err = gpiod_configure_flags(desc, label, 0, flags); | ||
| 2487 | if (err) { | ||
| 2488 | chip_err(chip, "setup of own GPIO %s failed\n", label); | ||
| 2489 | gpiod_free_commit(desc); | ||
| 2490 | return ERR_PTR(err); | ||
| 2491 | } | ||
| 2492 | |||
| 2505 | return desc; | 2493 | return desc; |
| 2506 | } | 2494 | } |
| 2507 | EXPORT_SYMBOL_GPL(gpiochip_request_own_desc); | 2495 | EXPORT_SYMBOL_GPL(gpiochip_request_own_desc); |
| @@ -3375,11 +3363,19 @@ EXPORT_SYMBOL_GPL(gpiod_cansleep); | |||
| 3375 | * @desc: gpio to set the consumer name on | 3363 | * @desc: gpio to set the consumer name on |
| 3376 | * @name: the new consumer name | 3364 | * @name: the new consumer name |
| 3377 | */ | 3365 | */ |
| 3378 | void gpiod_set_consumer_name(struct gpio_desc *desc, const char *name) | 3366 | int gpiod_set_consumer_name(struct gpio_desc *desc, const char *name) |
| 3379 | { | 3367 | { |
| 3380 | VALIDATE_DESC_VOID(desc); | 3368 | VALIDATE_DESC(desc); |
| 3381 | /* Just overwrite whatever the previous name was */ | 3369 | if (name) { |
| 3382 | desc->label = name; | 3370 | name = kstrdup_const(name, GFP_KERNEL); |
| 3371 | if (!name) | ||
| 3372 | return -ENOMEM; | ||
| 3373 | } | ||
| 3374 | |||
| 3375 | kfree_const(desc->label); | ||
| 3376 | desc_set_label(desc, name); | ||
| 3377 | |||
| 3378 | return 0; | ||
| 3383 | } | 3379 | } |
| 3384 | EXPORT_SYMBOL_GPL(gpiod_set_consumer_name); | 3380 | EXPORT_SYMBOL_GPL(gpiod_set_consumer_name); |
| 3385 | 3381 | ||
| @@ -4348,7 +4344,15 @@ int gpiod_hog(struct gpio_desc *desc, const char *name, | |||
| 4348 | chip = gpiod_to_chip(desc); | 4344 | chip = gpiod_to_chip(desc); |
| 4349 | hwnum = gpio_chip_hwgpio(desc); | 4345 | hwnum = gpio_chip_hwgpio(desc); |
| 4350 | 4346 | ||
| 4351 | local_desc = gpiochip_request_own_desc(chip, hwnum, name); | 4347 | /* |
| 4348 | * FIXME: not very elegant that we call gpiod_configure_flags() | ||
| 4349 | * twice here (once inside gpiochip_request_own_desc() and | ||
| 4350 | * again here), but the gpiochip_request_own_desc() is external | ||
| 4351 | * and cannot really pass the lflags so this is the lesser evil | ||
| 4352 | * at the moment. Pass zero as dflags on this first call so we | ||
| 4353 | * don't screw anything up. | ||
| 4354 | */ | ||
| 4355 | local_desc = gpiochip_request_own_desc(chip, hwnum, name, 0); | ||
| 4352 | if (IS_ERR(local_desc)) { | 4356 | if (IS_ERR(local_desc)) { |
| 4353 | status = PTR_ERR(local_desc); | 4357 | status = PTR_ERR(local_desc); |
| 4354 | pr_err("requesting hog GPIO %s (chip %s, offset %d) failed, %d\n", | 4358 | pr_err("requesting hog GPIO %s (chip %s, offset %d) failed, %d\n", |
diff --git a/drivers/hid/hid-cp2112.c b/drivers/hid/hid-cp2112.c index 271f31461da4..47f65857408d 100644 --- a/drivers/hid/hid-cp2112.c +++ b/drivers/hid/hid-cp2112.c | |||
| @@ -1203,7 +1203,7 @@ static int __maybe_unused cp2112_allocate_irq(struct cp2112_device *dev, | |||
| 1203 | return -EINVAL; | 1203 | return -EINVAL; |
| 1204 | 1204 | ||
| 1205 | dev->desc[pin] = gpiochip_request_own_desc(&dev->gc, pin, | 1205 | dev->desc[pin] = gpiochip_request_own_desc(&dev->gc, pin, |
| 1206 | "HID/I2C:Event"); | 1206 | "HID/I2C:Event", 0); |
| 1207 | if (IS_ERR(dev->desc[pin])) { | 1207 | if (IS_ERR(dev->desc[pin])) { |
| 1208 | dev_err(dev->gc.parent, "Failed to request GPIO\n"); | 1208 | dev_err(dev->gc.parent, "Failed to request GPIO\n"); |
| 1209 | return PTR_ERR(dev->desc[pin]); | 1209 | return PTR_ERR(dev->desc[pin]); |
diff --git a/drivers/memory/omap-gpmc.c b/drivers/memory/omap-gpmc.c index c215287e80cf..e1d91e64e008 100644 --- a/drivers/memory/omap-gpmc.c +++ b/drivers/memory/omap-gpmc.c | |||
| @@ -21,6 +21,7 @@ | |||
| 21 | #include <linux/spinlock.h> | 21 | #include <linux/spinlock.h> |
| 22 | #include <linux/io.h> | 22 | #include <linux/io.h> |
| 23 | #include <linux/gpio/driver.h> | 23 | #include <linux/gpio/driver.h> |
| 24 | #include <linux/gpio/consumer.h> /* GPIO descriptor enum */ | ||
| 24 | #include <linux/interrupt.h> | 25 | #include <linux/interrupt.h> |
| 25 | #include <linux/irqdomain.h> | 26 | #include <linux/irqdomain.h> |
| 26 | #include <linux/platform_device.h> | 27 | #include <linux/platform_device.h> |
| @@ -2170,7 +2171,8 @@ static int gpmc_probe_generic_child(struct platform_device *pdev, | |||
| 2170 | unsigned int wait_pin = gpmc_s.wait_pin; | 2171 | unsigned int wait_pin = gpmc_s.wait_pin; |
| 2171 | 2172 | ||
| 2172 | waitpin_desc = gpiochip_request_own_desc(&gpmc->gpio_chip, | 2173 | waitpin_desc = gpiochip_request_own_desc(&gpmc->gpio_chip, |
| 2173 | wait_pin, "WAITPIN"); | 2174 | wait_pin, "WAITPIN", |
| 2175 | 0); | ||
| 2174 | if (IS_ERR(waitpin_desc)) { | 2176 | if (IS_ERR(waitpin_desc)) { |
| 2175 | dev_err(&pdev->dev, "invalid wait-pin: %d\n", wait_pin); | 2177 | dev_err(&pdev->dev, "invalid wait-pin: %d\n", wait_pin); |
| 2176 | ret = PTR_ERR(waitpin_desc); | 2178 | ret = PTR_ERR(waitpin_desc); |
diff --git a/include/dt-bindings/gpio/tegra186-gpio.h b/include/dt-bindings/gpio/tegra186-gpio.h index 463ad398fe3e..cabc5712e745 100644 --- a/include/dt-bindings/gpio/tegra186-gpio.h +++ b/include/dt-bindings/gpio/tegra186-gpio.h | |||
| @@ -14,6 +14,34 @@ | |||
| 14 | #include <dt-bindings/gpio/gpio.h> | 14 | #include <dt-bindings/gpio/gpio.h> |
| 15 | 15 | ||
| 16 | /* GPIOs implemented by main GPIO controller */ | 16 | /* GPIOs implemented by main GPIO controller */ |
| 17 | #define TEGRA186_MAIN_GPIO_PORT_A 0 | ||
| 18 | #define TEGRA186_MAIN_GPIO_PORT_B 1 | ||
| 19 | #define TEGRA186_MAIN_GPIO_PORT_C 2 | ||
| 20 | #define TEGRA186_MAIN_GPIO_PORT_D 3 | ||
| 21 | #define TEGRA186_MAIN_GPIO_PORT_E 4 | ||
| 22 | #define TEGRA186_MAIN_GPIO_PORT_F 5 | ||
| 23 | #define TEGRA186_MAIN_GPIO_PORT_G 6 | ||
| 24 | #define TEGRA186_MAIN_GPIO_PORT_H 7 | ||
| 25 | #define TEGRA186_MAIN_GPIO_PORT_I 8 | ||
| 26 | #define TEGRA186_MAIN_GPIO_PORT_J 9 | ||
| 27 | #define TEGRA186_MAIN_GPIO_PORT_K 10 | ||
| 28 | #define TEGRA186_MAIN_GPIO_PORT_L 11 | ||
| 29 | #define TEGRA186_MAIN_GPIO_PORT_M 12 | ||
| 30 | #define TEGRA186_MAIN_GPIO_PORT_N 13 | ||
| 31 | #define TEGRA186_MAIN_GPIO_PORT_O 14 | ||
| 32 | #define TEGRA186_MAIN_GPIO_PORT_P 15 | ||
| 33 | #define TEGRA186_MAIN_GPIO_PORT_Q 16 | ||
| 34 | #define TEGRA186_MAIN_GPIO_PORT_R 17 | ||
| 35 | #define TEGRA186_MAIN_GPIO_PORT_T 18 | ||
| 36 | #define TEGRA186_MAIN_GPIO_PORT_X 19 | ||
| 37 | #define TEGRA186_MAIN_GPIO_PORT_Y 20 | ||
| 38 | #define TEGRA186_MAIN_GPIO_PORT_BB 21 | ||
| 39 | #define TEGRA186_MAIN_GPIO_PORT_CC 22 | ||
| 40 | |||
| 41 | #define TEGRA186_MAIN_GPIO(port, offset) \ | ||
| 42 | ((TEGRA186_MAIN_GPIO_PORT_##port * 8) + offset) | ||
| 43 | |||
| 44 | /* need to keep these for backwards-compatibility */ | ||
| 17 | #define TEGRA_MAIN_GPIO_PORT_A 0 | 45 | #define TEGRA_MAIN_GPIO_PORT_A 0 |
| 18 | #define TEGRA_MAIN_GPIO_PORT_B 1 | 46 | #define TEGRA_MAIN_GPIO_PORT_B 1 |
| 19 | #define TEGRA_MAIN_GPIO_PORT_C 2 | 47 | #define TEGRA_MAIN_GPIO_PORT_C 2 |
| @@ -42,6 +70,19 @@ | |||
| 42 | ((TEGRA_MAIN_GPIO_PORT_##port * 8) + offset) | 70 | ((TEGRA_MAIN_GPIO_PORT_##port * 8) + offset) |
| 43 | 71 | ||
| 44 | /* GPIOs implemented by AON GPIO controller */ | 72 | /* GPIOs implemented by AON GPIO controller */ |
| 73 | #define TEGRA186_AON_GPIO_PORT_S 0 | ||
| 74 | #define TEGRA186_AON_GPIO_PORT_U 1 | ||
| 75 | #define TEGRA186_AON_GPIO_PORT_V 2 | ||
| 76 | #define TEGRA186_AON_GPIO_PORT_W 3 | ||
| 77 | #define TEGRA186_AON_GPIO_PORT_Z 4 | ||
| 78 | #define TEGRA186_AON_GPIO_PORT_AA 5 | ||
| 79 | #define TEGRA186_AON_GPIO_PORT_EE 6 | ||
| 80 | #define TEGRA186_AON_GPIO_PORT_FF 7 | ||
| 81 | |||
| 82 | #define TEGRA186_AON_GPIO(port, offset) \ | ||
| 83 | ((TEGRA186_AON_GPIO_PORT_##port * 8) + offset) | ||
| 84 | |||
| 85 | /* need to keep these for backwards-compatibility */ | ||
| 45 | #define TEGRA_AON_GPIO_PORT_S 0 | 86 | #define TEGRA_AON_GPIO_PORT_S 0 |
| 46 | #define TEGRA_AON_GPIO_PORT_U 1 | 87 | #define TEGRA_AON_GPIO_PORT_U 1 |
| 47 | #define TEGRA_AON_GPIO_PORT_V 2 | 88 | #define TEGRA_AON_GPIO_PORT_V 2 |
diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h index 8aebcf822082..9ddcf50a3c59 100644 --- a/include/linux/gpio/consumer.h +++ b/include/linux/gpio/consumer.h | |||
| @@ -163,7 +163,7 @@ int gpiod_is_active_low(const struct gpio_desc *desc); | |||
| 163 | int gpiod_cansleep(const struct gpio_desc *desc); | 163 | int gpiod_cansleep(const struct gpio_desc *desc); |
| 164 | 164 | ||
| 165 | int gpiod_to_irq(const struct gpio_desc *desc); | 165 | int gpiod_to_irq(const struct gpio_desc *desc); |
| 166 | void gpiod_set_consumer_name(struct gpio_desc *desc, const char *name); | 166 | int gpiod_set_consumer_name(struct gpio_desc *desc, const char *name); |
| 167 | 167 | ||
| 168 | /* Convert between the old gpio_ and new gpiod_ interfaces */ | 168 | /* Convert between the old gpio_ and new gpiod_ interfaces */ |
| 169 | struct gpio_desc *gpio_to_desc(unsigned gpio); | 169 | struct gpio_desc *gpio_to_desc(unsigned gpio); |
| @@ -509,15 +509,17 @@ static inline int gpiod_to_irq(const struct gpio_desc *desc) | |||
| 509 | return -EINVAL; | 509 | return -EINVAL; |
| 510 | } | 510 | } |
| 511 | 511 | ||
| 512 | static inline void gpiod_set_consumer_name(struct gpio_desc *desc, const char *name) | 512 | static inline int gpiod_set_consumer_name(struct gpio_desc *desc, |
| 513 | const char *name) | ||
| 513 | { | 514 | { |
| 514 | /* GPIO can never have been requested */ | 515 | /* GPIO can never have been requested */ |
| 515 | WARN_ON(1); | 516 | WARN_ON(1); |
| 517 | return -EINVAL; | ||
| 516 | } | 518 | } |
| 517 | 519 | ||
| 518 | static inline struct gpio_desc *gpio_to_desc(unsigned gpio) | 520 | static inline struct gpio_desc *gpio_to_desc(unsigned gpio) |
| 519 | { | 521 | { |
| 520 | return ERR_PTR(-EINVAL); | 522 | return NULL; |
| 521 | } | 523 | } |
| 522 | 524 | ||
| 523 | static inline int desc_to_gpio(const struct gpio_desc *desc) | 525 | static inline int desc_to_gpio(const struct gpio_desc *desc) |
diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h index 2db62b550b95..07cddbf45186 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h | |||
| @@ -17,6 +17,7 @@ struct device_node; | |||
| 17 | struct seq_file; | 17 | struct seq_file; |
| 18 | struct gpio_device; | 18 | struct gpio_device; |
| 19 | struct module; | 19 | struct module; |
| 20 | enum gpiod_flags; | ||
| 20 | 21 | ||
| 21 | #ifdef CONFIG_GPIOLIB | 22 | #ifdef CONFIG_GPIOLIB |
| 22 | 23 | ||
| @@ -166,11 +167,6 @@ struct gpio_irq_chip { | |||
| 166 | */ | 167 | */ |
| 167 | void (*irq_disable)(struct irq_data *data); | 168 | void (*irq_disable)(struct irq_data *data); |
| 168 | }; | 169 | }; |
| 169 | |||
| 170 | static inline struct gpio_irq_chip *to_gpio_irq_chip(struct irq_chip *chip) | ||
| 171 | { | ||
| 172 | return container_of(chip, struct gpio_irq_chip, chip); | ||
| 173 | } | ||
| 174 | #endif | 170 | #endif |
| 175 | 171 | ||
| 176 | /** | 172 | /** |
| @@ -422,7 +418,6 @@ static inline int gpiochip_add(struct gpio_chip *chip) | |||
| 422 | extern void gpiochip_remove(struct gpio_chip *chip); | 418 | extern void gpiochip_remove(struct gpio_chip *chip); |
| 423 | extern int devm_gpiochip_add_data(struct device *dev, struct gpio_chip *chip, | 419 | extern int devm_gpiochip_add_data(struct device *dev, struct gpio_chip *chip, |
| 424 | void *data); | 420 | void *data); |
| 425 | extern void devm_gpiochip_remove(struct device *dev, struct gpio_chip *chip); | ||
| 426 | 421 | ||
| 427 | extern struct gpio_chip *gpiochip_find(void *data, | 422 | extern struct gpio_chip *gpiochip_find(void *data, |
| 428 | int (*match)(struct gpio_chip *chip, void *data)); | 423 | int (*match)(struct gpio_chip *chip, void *data)); |
| @@ -610,7 +605,8 @@ gpiochip_remove_pin_ranges(struct gpio_chip *chip) | |||
| 610 | #endif /* CONFIG_PINCTRL */ | 605 | #endif /* CONFIG_PINCTRL */ |
| 611 | 606 | ||
| 612 | struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *chip, u16 hwnum, | 607 | struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *chip, u16 hwnum, |
| 613 | const char *label); | 608 | const char *label, |
| 609 | enum gpiod_flags flags); | ||
| 614 | void gpiochip_free_own_desc(struct gpio_desc *desc); | 610 | void gpiochip_free_own_desc(struct gpio_desc *desc); |
| 615 | 611 | ||
| 616 | #else /* CONFIG_GPIOLIB */ | 612 | #else /* CONFIG_GPIOLIB */ |
