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

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

Pull gpio updates from Bartosz Golaszewski:
"A rather small update, there are no new drivers, just improvements and
refactoring in existing ones.

Thanks to migrating of several drivers to using generalized APIs and
dropping of OF interfaces in favor of using software nodes we're
actually removing more code than we're adding.

Core GPIOLIB:
- drop several OF interfaces after moving a significant part of the
code to using software nodes
- remove more interfaces referring to the global GPIO numberspace
that we're getting rid of
- improvements in the gpio-regmap library
- add helper for GPIO device reference counting
- remove unused APIs
- minor tweaks like sorting headers alphabetically

Extended support in existing drivers:
- add support for Tegra 234 PMC to gpio-tegra186

Driver improvements:
- migrate the 104-dio/idi family of drivers to using the regmap-irq
API
- migrate gpio-i8255 and gpio-mm to the GPIO regmap API
- clean-ups in gpio-pca953x
- remove duplicate assignments of of_gpio_n_cells in gpio-davinci,
gpio-ge, gpio-xilinx, gpio-zevio and gpio-wcd934x
- improvements to gpio-pcf857x: implement get/set_multiple callbacks,
use generic device properties instead of OF + minor tweaks
- fix OF-related header includes and Kconfig dependencies in
gpio-zevio
- dynamically allocate the GPIO base in gpio-omap
- use a dedicated printf specifier for printing fwnode info in
gpio-sim
- use dev_name() for the GPIO chip label in gpio-vf610
- other minor tweaks and fixes

Documentation:
- remove mentions of legacy API from comments in various places
- convert the DT binding documents to YAML schema for Fujitsu
MB86S7x, Unisoc GPIO and Unisoc EIC
- document the Unisoc UMS512 controller in DT bindings"

* tag 'gpio-updates-for-v6.3' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux: (54 commits)
gpio: sim: Use %pfwP specifier instead of calling fwnode API directly
gpio: tegra186: remove unneeded loop in tegra186_gpio_init_route_mapping()
gpiolib: of: Move enum of_gpio_flags to its only user
gpio: mvebu: Use IS_REACHABLE instead of IS_ENABLED for CONFIG_PWM
gpio: zevio: Add missing header
gpio: Get rid of gpio_to_chip()
gpio: pcf857x: Drop unneeded explicit casting
gpio: pcf857x: Make use of device properties
gpio: pcf857x: Get rid of legacy platform data
gpio: rockchip: Do not mention legacy API in the code
gpio: wcd934x: Remove duplicate assignment of of_gpio_n_cells
gpio: zevio: Use proper headers and drop OF_GPIO dependency
gpio: zevio: Remove duplicate assignment of of_gpio_n_cells
gpio: xilinx: Remove duplicate assignment of of_gpio_n_cells
dt-bindings: gpio: Add compatible string for Unisoc UMS512
dt-bindings: gpio: Convert Unisoc EIC controller binding to yaml
dt-bindings: gpio: Convert Unisoc GPIO controller binding to yaml
gpio: ge: Remove duplicate assignment of of_gpio_n_cells
gpio: davinci: Remove duplicate assignment of of_gpio_n_cells
gpio: omap: use dynamic allocation of base
...

+875 -1679
-20
Documentation/devicetree/bindings/gpio/fujitsu,mb86s70-gpio.txt
··· 1 - Fujitsu MB86S7x GPIO Controller 2 - ------------------------------- 3 - 4 - Required properties: 5 - - compatible: Should be "fujitsu,mb86s70-gpio" 6 - - reg: Base address and length of register space 7 - - clocks: Specify the clock 8 - - gpio-controller: Marks the device node as a gpio controller. 9 - - #gpio-cells: Should be <2>. The first cell is the pin number and the 10 - second cell is used to specify optional parameters: 11 - - bit 0 specifies polarity (0 for normal, 1 for inverted). 12 - 13 - Examples: 14 - gpio0: gpio@31000000 { 15 - compatible = "fujitsu,mb86s70-gpio"; 16 - reg = <0 0x31000000 0x10000>; 17 - gpio-controller; 18 - #gpio-cells = <2>; 19 - clocks = <&clk 0 2 1>; 20 - };
+50
Documentation/devicetree/bindings/gpio/fujitsu,mb86s70-gpio.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/gpio/fujitsu,mb86s70-gpio.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Fujitsu MB86S7x GPIO Controller 8 + 9 + maintainers: 10 + - Jassi Brar <jaswinder.singh@linaro.org> 11 + 12 + properties: 13 + compatible: 14 + oneOf: 15 + - items: 16 + - const: socionext,synquacer-gpio 17 + - const: fujitsu,mb86s70-gpio 18 + - const: fujitsu,mb86s70-gpio 19 + 20 + reg: 21 + maxItems: 1 22 + 23 + '#gpio-cells': 24 + const: 2 25 + 26 + gpio-controller: true 27 + gpio-line-names: true 28 + 29 + clocks: 30 + maxItems: 1 31 + 32 + required: 33 + - compatible 34 + - reg 35 + - '#gpio-cells' 36 + - gpio-controller 37 + - clocks 38 + 39 + additionalProperties: false 40 + 41 + examples: 42 + - | 43 + gpio@31000000 { 44 + compatible = "fujitsu,mb86s70-gpio"; 45 + reg = <0x31000000 0x10000>; 46 + gpio-controller; 47 + #gpio-cells = <2>; 48 + clocks = <&clk 0 2 1>; 49 + }; 50 + ...
-97
Documentation/devicetree/bindings/gpio/gpio-eic-sprd.txt
··· 1 - Spreadtrum EIC controller bindings 2 - 3 - The EIC is the abbreviation of external interrupt controller, which can 4 - be used only in input mode. The Spreadtrum platform has 2 EIC controllers, 5 - one is in digital chip, and another one is in PMIC. The digital chip EIC 6 - controller contains 4 sub-modules: EIC-debounce, EIC-latch, EIC-async and 7 - EIC-sync. But the PMIC EIC controller contains only one EIC-debounce sub- 8 - module. 9 - 10 - The EIC-debounce sub-module provides up to 8 source input signal 11 - connections. A debounce mechanism is used to capture the input signals' 12 - stable status (millisecond resolution) and a single-trigger mechanism 13 - is introduced into this sub-module to enhance the input event detection 14 - reliability. In addition, this sub-module's clock can be shut off 15 - automatically to reduce power dissipation. Moreover the debounce range 16 - is from 1ms to 4s with a step size of 1ms. The input signal will be 17 - ignored if it is asserted for less than 1 ms. 18 - 19 - The EIC-latch sub-module is used to latch some special power down signals 20 - and generate interrupts, since the EIC-latch does not depend on the APB 21 - clock to capture signals. 22 - 23 - The EIC-async sub-module uses a 32kHz clock to capture the short signals 24 - (microsecond resolution) to generate interrupts by level or edge trigger. 25 - 26 - The EIC-sync is similar with GPIO's input function, which is a synchronized 27 - signal input register. It can generate interrupts by level or edge trigger 28 - when detecting input signals. 29 - 30 - Required properties: 31 - - compatible: Should be one of the following: 32 - "sprd,sc9860-eic-debounce", 33 - "sprd,sc9860-eic-latch", 34 - "sprd,sc9860-eic-async", 35 - "sprd,sc9860-eic-sync", 36 - "sprd,sc2731-eic". 37 - - reg: Define the base and range of the I/O address space containing 38 - the GPIO controller registers. 39 - - gpio-controller: Marks the device node as a GPIO controller. 40 - - #gpio-cells: Should be <2>. The first cell is the gpio number and 41 - the second cell is used to specify optional parameters. 42 - - interrupt-controller: Marks the device node as an interrupt controller. 43 - - #interrupt-cells: Should be <2>. Specifies the number of cells needed 44 - to encode interrupt source. 45 - - interrupts: Should be the port interrupt shared by all the gpios. 46 - 47 - Example: 48 - eic_debounce: gpio@40210000 { 49 - compatible = "sprd,sc9860-eic-debounce"; 50 - reg = <0 0x40210000 0 0x80>; 51 - gpio-controller; 52 - #gpio-cells = <2>; 53 - interrupt-controller; 54 - #interrupt-cells = <2>; 55 - interrupts = <GIC_SPI 52 IRQ_TYPE_LEVEL_HIGH>; 56 - }; 57 - 58 - eic_latch: gpio@40210080 { 59 - compatible = "sprd,sc9860-eic-latch"; 60 - reg = <0 0x40210080 0 0x20>; 61 - gpio-controller; 62 - #gpio-cells = <2>; 63 - interrupt-controller; 64 - #interrupt-cells = <2>; 65 - interrupts = <GIC_SPI 52 IRQ_TYPE_LEVEL_HIGH>; 66 - }; 67 - 68 - eic_async: gpio@402100a0 { 69 - compatible = "sprd,sc9860-eic-async"; 70 - reg = <0 0x402100a0 0 0x20>; 71 - gpio-controller; 72 - #gpio-cells = <2>; 73 - interrupt-controller; 74 - #interrupt-cells = <2>; 75 - interrupts = <GIC_SPI 52 IRQ_TYPE_LEVEL_HIGH>; 76 - }; 77 - 78 - eic_sync: gpio@402100c0 { 79 - compatible = "sprd,sc9860-eic-sync"; 80 - reg = <0 0x402100c0 0 0x20>; 81 - gpio-controller; 82 - #gpio-cells = <2>; 83 - interrupt-controller; 84 - #interrupt-cells = <2>; 85 - interrupts = <GIC_SPI 52 IRQ_TYPE_LEVEL_HIGH>; 86 - }; 87 - 88 - pmic_eic: gpio@300 { 89 - compatible = "sprd,sc2731-eic"; 90 - reg = <0x300>; 91 - interrupt-parent = <&sc2731_pmic>; 92 - interrupts = <5 IRQ_TYPE_LEVEL_HIGH>; 93 - gpio-controller; 94 - #gpio-cells = <2>; 95 - interrupt-controller; 96 - #interrupt-cells = <2>; 97 - };
-28
Documentation/devicetree/bindings/gpio/gpio-sprd.txt
··· 1 - Spreadtrum GPIO controller bindings 2 - 3 - The controller's registers are organized as sets of sixteen 16-bit 4 - registers with each set controlling a bank of up to 16 pins. A single 5 - interrupt is shared for all of the banks handled by the controller. 6 - 7 - Required properties: 8 - - compatible: Should be "sprd,sc9860-gpio". 9 - - reg: Define the base and range of the I/O address space containing 10 - the GPIO controller registers. 11 - - gpio-controller: Marks the device node as a GPIO controller. 12 - - #gpio-cells: Should be <2>. The first cell is the gpio number and 13 - the second cell is used to specify optional parameters. 14 - - interrupt-controller: Marks the device node as an interrupt controller. 15 - - #interrupt-cells: Should be <2>. Specifies the number of cells needed 16 - to encode interrupt source. 17 - - interrupts: Should be the port interrupt shared by all the gpios. 18 - 19 - Example: 20 - ap_gpio: gpio@40280000 { 21 - compatible = "sprd,sc9860-gpio"; 22 - reg = <0 0x40280000 0 0x1000>; 23 - gpio-controller; 24 - #gpio-cells = <2>; 25 - interrupt-controller; 26 - #interrupt-cells = <2>; 27 - interrupts = <GIC_SPI 50 IRQ_TYPE_LEVEL_HIGH>; 28 - };
+124
Documentation/devicetree/bindings/gpio/sprd,gpio-eic.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + # Copyright 2022 Unisoc Inc. 3 + %YAML 1.2 4 + --- 5 + $id: http://devicetree.org/schemas/gpio/sprd,gpio-eic.yaml# 6 + $schema: http://devicetree.org/meta-schemas/core.yaml# 7 + 8 + title: Unisoc EIC controller 9 + 10 + maintainers: 11 + - Orson Zhai <orsonzhai@gmail.com> 12 + - Baolin Wang <baolin.wang7@gmail.com> 13 + - Chunyan Zhang <zhang.lyra@gmail.com> 14 + 15 + description: | 16 + The EIC is the abbreviation of external interrupt controller, which can 17 + be used only in input mode. The Spreadtrum platform has 2 EIC controllers, 18 + one is in digital chip, and another one is in PMIC. The digital chip EIC 19 + controller contains 4 sub-modules, i.e. EIC-debounce, EIC-latch, EIC-async and 20 + EIC-sync. But the PMIC EIC controller contains only one EIC-debounce sub- 21 + module. 22 + 23 + The EIC-debounce sub-module provides up to 8 source input signal 24 + connections. A debounce mechanism is used to capture the input signals' 25 + stable status (millisecond resolution) and a single-trigger mechanism 26 + is introduced into this sub-module to enhance the input event detection 27 + reliability. In addition, this sub-module's clock can be shut off 28 + automatically to reduce power dissipation. Moreover the debounce range 29 + is from 1ms to 4s with a step size of 1ms. The input signal will be 30 + ignored if it is asserted for less than 1 ms. 31 + 32 + The EIC-latch sub-module is used to latch some special power down signals 33 + and generate interrupts, since the EIC-latch does not depend on the APB 34 + clock to capture signals. 35 + 36 + The EIC-async sub-module uses a 32kHz clock to capture the short signals 37 + (microsecond resolution) to generate interrupts by level or edge trigger. 38 + 39 + The EIC-sync is similar with GPIO's input function, which is a synchronized 40 + signal input register. It can generate interrupts by level or edge trigger 41 + when detecting input signals. 42 + 43 + properties: 44 + compatible: 45 + oneOf: 46 + - enum: 47 + - sprd,sc9860-eic-debounce 48 + - sprd,sc9860-eic-latch 49 + - sprd,sc9860-eic-async 50 + - sprd,sc9860-eic-sync 51 + - sprd,sc2731-eic 52 + - items: 53 + - enum: 54 + - sprd,ums512-eic-debounce 55 + - const: sprd,sc9860-eic-debounce 56 + - items: 57 + - enum: 58 + - sprd,ums512-eic-latch 59 + - const: sprd,sc9860-eic-latch 60 + - items: 61 + - enum: 62 + - sprd,ums512-eic-async 63 + - const: sprd,sc9860-eic-async 64 + - items: 65 + - enum: 66 + - sprd,ums512-eic-sync 67 + - const: sprd,sc9860-eic-sync 68 + - items: 69 + - enum: 70 + - sprd,sc2730-eic 71 + - const: sprd,sc2731-eic 72 + 73 + reg: 74 + minItems: 1 75 + maxItems: 3 76 + description: 77 + EIC controller can support maximum 3 banks which has its own 78 + address base. 79 + 80 + gpio-controller: true 81 + 82 + "#gpio-cells": 83 + const: 2 84 + 85 + interrupt-controller: true 86 + 87 + "#interrupt-cells": 88 + const: 2 89 + 90 + interrupts: 91 + maxItems: 1 92 + description: 93 + The interrupt shared by all GPIO lines for this controller. 94 + 95 + required: 96 + - compatible 97 + - reg 98 + - gpio-controller 99 + - "#gpio-cells" 100 + - interrupt-controller 101 + - "#interrupt-cells" 102 + - interrupts 103 + 104 + additionalProperties: false 105 + 106 + examples: 107 + - | 108 + #include <dt-bindings/interrupt-controller/arm-gic.h> 109 + 110 + soc { 111 + #address-cells = <2>; 112 + #size-cells = <2>; 113 + 114 + eic_debounce: gpio@40210000 { 115 + compatible = "sprd,sc9860-eic-debounce"; 116 + reg = <0 0x40210000 0 0x80>; 117 + gpio-controller; 118 + #gpio-cells = <2>; 119 + interrupt-controller; 120 + #interrupt-cells = <2>; 121 + interrupts = <GIC_SPI 52 IRQ_TYPE_LEVEL_HIGH>; 122 + }; 123 + }; 124 + ...
+75
Documentation/devicetree/bindings/gpio/sprd,gpio.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + # Copyright 2022 Unisoc Inc. 3 + %YAML 1.2 4 + --- 5 + $id: http://devicetree.org/schemas/gpio/sprd,gpio.yaml# 6 + $schema: http://devicetree.org/meta-schemas/core.yaml# 7 + 8 + title: Unisoc GPIO controller 9 + 10 + maintainers: 11 + - Orson Zhai <orsonzhai@gmail.com> 12 + - Baolin Wang <baolin.wang7@gmail.com> 13 + - Chunyan Zhang <zhang.lyra@gmail.com> 14 + 15 + description: | 16 + The controller's registers are organized as sets of sixteen 16-bit 17 + registers with each set controlling a bank of up to 16 pins. A single 18 + interrupt is shared for all of the banks handled by the controller. 19 + 20 + properties: 21 + compatible: 22 + oneOf: 23 + - const: sprd,sc9860-gpio 24 + - items: 25 + - enum: 26 + - sprd,ums512-gpio 27 + - const: sprd,sc9860-gpio 28 + 29 + reg: 30 + maxItems: 1 31 + 32 + gpio-controller: true 33 + 34 + "#gpio-cells": 35 + const: 2 36 + 37 + interrupt-controller: true 38 + 39 + "#interrupt-cells": 40 + const: 2 41 + 42 + interrupts: 43 + maxItems: 1 44 + description: The interrupt shared by all GPIO lines for this controller. 45 + 46 + required: 47 + - compatible 48 + - reg 49 + - gpio-controller 50 + - "#gpio-cells" 51 + - interrupt-controller 52 + - "#interrupt-cells" 53 + - interrupts 54 + 55 + additionalProperties: false 56 + 57 + examples: 58 + - | 59 + #include <dt-bindings/interrupt-controller/arm-gic.h> 60 + 61 + soc { 62 + #address-cells = <2>; 63 + #size-cells = <2>; 64 + 65 + ap_gpio: gpio@40280000 { 66 + compatible = "sprd,sc9860-gpio"; 67 + reg = <0 0x40280000 0 0x1000>; 68 + gpio-controller; 69 + #gpio-cells = <2>; 70 + interrupt-controller; 71 + #interrupt-cells = <2>; 72 + interrupts = <GIC_SPI 50 IRQ_TYPE_LEVEL_HIGH>; 73 + }; 74 + }; 75 + ...
-17
Documentation/driver-api/gpio/legacy.rst
··· 387 387 /* map GPIO numbers to IRQ numbers */ 388 388 int gpio_to_irq(unsigned gpio); 389 389 390 - /* map IRQ numbers to GPIO numbers (avoid using this) */ 391 - int irq_to_gpio(unsigned irq); 392 - 393 390 Those return either the corresponding number in the other namespace, or 394 391 else a negative errno code if the mapping can't be done. (For example, 395 392 some GPIOs can't be used as IRQs.) It is an unchecked error to use a GPIO ··· 401 404 devices, by the board-specific initialization code. Note that IRQ trigger 402 405 options are part of the IRQ interface, e.g. IRQF_TRIGGER_FALLING, as are 403 406 system wakeup capabilities. 404 - 405 - Non-error values returned from irq_to_gpio() would most commonly be used 406 - with gpio_get_value(), for example to initialize or update driver state 407 - when the IRQ is edge-triggered. Note that some platforms don't support 408 - this reverse mapping, so you should avoid using it. 409 407 410 408 411 409 Emulating Open Drain Signals ··· 727 735 /* reverse gpio_export() */ 728 736 void gpio_unexport(); 729 737 730 - /* create a sysfs link to an exported GPIO node */ 731 - int gpio_export_link(struct device *dev, const char *name, 732 - unsigned gpio) 733 - 734 738 After a kernel driver requests a GPIO, it may only be made available in 735 739 the sysfs interface by gpio_export(). The driver can control whether the 736 740 signal direction may change. This helps drivers prevent userspace code ··· 735 747 This explicit exporting can help with debugging (by making some kinds 736 748 of experiments easier), or can provide an always-there interface that's 737 749 suitable for documenting as part of a board support package. 738 - 739 - After the GPIO has been exported, gpio_export_link() allows creating 740 - symlinks from elsewhere in sysfs to the GPIO sysfs node. Drivers can 741 - use this to provide the interface under their own device in sysfs with 742 - a descriptive name. 743 750 744 751 745 752 API Reference
-15
Documentation/translations/zh_CN/driver-api/gpio/legacy.rst
··· 358 358 /* 映射 GPIO 编号到 IRQ 编号 */ 359 359 int gpio_to_irq(unsigned gpio); 360 360 361 - /* 映射 IRQ 编号到 GPIO 编号 (尽量避免使用) */ 362 - int irq_to_gpio(unsigned irq); 363 - 364 361 它们的返回值为对应命名空间的相关编号,或是负的错误代码(如果无法映射)。 365 362 (例如,某些 GPIO 无法做为 IRQ 使用。)以下的编号错误是未经检测的:使用一个 366 363 未通过 gpio_direction_input()配置为输入的 GPIO 编号,或者使用一个 ··· 369 372 它们通常通过板级特定的初始化代码存放到平台设备的 IRQ 资源中。注意:IRQ 370 373 触发选项是 IRQ 接口的一部分,如 IRQF_TRIGGER_FALLING,系统唤醒能力 371 374 也是如此。 372 - 373 - irq_to_gpio()返回的非错误值大多数通常可以被 gpio_get_value()所使用, 374 - 比如在 IRQ 是沿触发时初始化或更新驱动状态。注意某些平台不支持反映射,所以 375 - 你应该尽量避免使用它。 376 375 377 376 378 377 模拟开漏信号 ··· 665 672 /* gpio_export()的逆操作 */ 666 673 void gpio_unexport(); 667 674 668 - /* 创建一个 sysfs 连接到已导出的 GPIO 节点 */ 669 - int gpio_export_link(struct device *dev, const char *name, 670 - unsigned gpio) 671 - 672 675 在一个内核驱动申请一个 GPIO 之后,它可以通过 gpio_export()使其在 sysfs 673 676 接口中可见。该驱动可以控制信号方向是否可修改。这有助于防止用户空间代码无意间 674 677 破坏重要的系统状态。 675 678 676 679 这个明确的导出有助于(通过使某些实验更容易来)调试,也可以提供一个始终存在的接口, 677 680 与文档配合作为板级支持包的一部分。 678 - 679 - 在 GPIO 被导出之后,gpio_export_link()允许在 sysfs 文件系统的任何地方 680 - 创建一个到这个 GPIO sysfs 节点的符号链接。这样驱动就可以通过一个描述性的 681 - 名字,在 sysfs 中他们所拥有的设备下提供一个(到这个 GPIO sysfs 节点的)接口。 682 681 683 682 684 683 API参考
-16
Documentation/translations/zh_TW/gpio.txt
··· 363 363 /* 映射 GPIO 編號到 IRQ 編號 */ 364 364 int gpio_to_irq(unsigned gpio); 365 365 366 - /* 映射 IRQ 編號到 GPIO 編號 (儘量避免使用) */ 367 - int irq_to_gpio(unsigned irq); 368 - 369 366 它們的返回值爲對應命名空間的相關編號,或是負的錯誤代碼(如果無法映射)。 370 367 (例如,某些 GPIO 無法做爲 IRQ 使用。)以下的編號錯誤是未經檢測的:使用一個 371 368 未通過 gpio_direction_input()配置爲輸入的 GPIO 編號,或者使用一個 ··· 374 377 它們通常通過板級特定的初始化代碼存放到平台設備的 IRQ 資源中。注意:IRQ 375 378 觸發選項是 IRQ 接口的一部分,如 IRQF_TRIGGER_FALLING,系統喚醒能力 376 379 也是如此。 377 - 378 - irq_to_gpio()返回的非錯誤值大多數通常可以被 gpio_get_value()所使用, 379 - 比如在 IRQ 是沿觸發時初始化或更新驅動狀態。注意某些平台不支持反映射,所以 380 - 你應該儘量避免使用它。 381 380 382 381 383 382 模擬開漏信號 ··· 627 634 /* gpio_export()的逆操作 */ 628 635 void gpio_unexport(); 629 636 630 - /* 創建一個 sysfs 連接到已導出的 GPIO 節點 */ 631 - int gpio_export_link(struct device *dev, const char *name, 632 - unsigned gpio) 633 - 634 637 在一個內核驅動申請一個 GPIO 之後,它可以通過 gpio_export()使其在 sysfs 635 638 接口中可見。該驅動可以控制信號方向是否可修改。這有助於防止用戶空間代碼無意間 636 639 破壞重要的系統狀態。 637 640 638 641 這個明確的導出有助於(通過使某些實驗更容易來)調試,也可以提供一個始終存在的接口, 639 642 與文檔配合作爲板級支持包的一部分。 640 - 641 - 在 GPIO 被導出之後,gpio_export_link()允許在 sysfs 文件系統的任何地方 642 - 創建一個到這個 GPIO sysfs 節點的符號連結。這樣驅動就可以通過一個描述性的 643 - 名字,在 sysfs 中他們所擁有的設備下提供一個(到這個 GPIO sysfs 節點的)接口。 644 -
-7
arch/m68k/include/asm/gpio.h
··· 66 66 return __gpio_to_irq(gpio); 67 67 } 68 68 69 - static inline int irq_to_gpio(unsigned irq) 70 - { 71 - return (irq >= MCFGPIO_IRQ_VECBASE && 72 - irq < (MCFGPIO_IRQ_VECBASE + MCFGPIO_IRQ_MAX)) ? 73 - irq - MCFGPIO_IRQ_VECBASE : -ENXIO; 74 - } 75 - 76 69 static inline int gpio_cansleep(unsigned gpio) 77 70 { 78 71 return gpio < MCFGPIO_PIN_MAX ? 0 : __gpio_cansleep(gpio);
-5
arch/sh/include/asm/gpio.h
··· 40 40 return __gpio_to_irq(gpio); 41 41 } 42 42 43 - static inline int irq_to_gpio(unsigned int irq) 44 - { 45 - return -ENOSYS; 46 - } 47 - 48 43 #endif /* CONFIG_GPIOLIB */ 49 44 50 45 #endif /* __ASM_SH_GPIO_H */
+8 -2
drivers/gpio/Kconfig
··· 752 752 753 753 config GPIO_ZEVIO 754 754 bool "LSI ZEVIO SoC memory mapped GPIOs" 755 - depends on ARM && OF_GPIO 755 + depends on ARM 756 756 help 757 757 Say yes here to support the GPIO controller in LSI ZEVIO SoCs. 758 758 ··· 821 821 822 822 config GPIO_I8255 823 823 tristate 824 + select GPIO_REGMAP 824 825 help 825 826 Enables support for the i8255 interface library functions. The i8255 826 827 interface library provides functions to facilitate communication with ··· 836 835 tristate "ACCES 104-DIO-48E GPIO support" 837 836 depends on PC104 838 837 select ISA_BUS_API 838 + select REGMAP_MMIO 839 + select REGMAP_IRQ 839 840 select GPIOLIB_IRQCHIP 840 841 select GPIO_I8255 841 842 help ··· 863 860 tristate "ACCES 104-IDI-48 GPIO support" 864 861 depends on PC104 865 862 select ISA_BUS_API 863 + select REGMAP_MMIO 864 + select REGMAP_IRQ 866 865 select GPIOLIB_IRQCHIP 867 - select GPIO_I8255 866 + select GPIO_REGMAP 868 867 help 869 868 Enables GPIO support for the ACCES 104-IDI-48 family (104-IDI-48A, 870 869 104-IDI-48AC, 104-IDI-48B, 104-IDI-48BC). The base port addresses for ··· 888 883 tristate "Diamond Systems GPIO-MM GPIO support" 889 884 depends on PC104 890 885 select ISA_BUS_API 886 + select REGMAP_MMIO 891 887 select GPIO_I8255 892 888 help 893 889 Enables GPIO support for the Diamond Systems GPIO-MM and GPIO-MM-12.
+2 -2
drivers/gpio/TODO
··· 61 61 62 62 - Get rid of struct of_mm_gpio_chip altogether: use the generic MMIO 63 63 GPIO for all current users (see below). Delete struct of_mm_gpio_chip, 64 - to_of_mm_gpio_chip(), of_mm_gpiochip_add_data(), of_mm_gpiochip_add() 65 - of_mm_gpiochip_remove() from the kernel. 64 + to_of_mm_gpio_chip(), of_mm_gpiochip_add_data(), of_mm_gpiochip_remove() 65 + from the kernel. 66 66 67 67 - Change all consumer drivers that #include <linux/of_gpio.h> to 68 68 #include <linux/gpio/consumer.h> and stop doing custom parsing of the
+130 -262
drivers/gpio/gpio-104-dio-48e.c
··· 8 8 */ 9 9 #include <linux/bits.h> 10 10 #include <linux/device.h> 11 - #include <linux/errno.h> 12 - #include <linux/gpio/driver.h> 13 - #include <linux/io.h> 11 + #include <linux/err.h> 14 12 #include <linux/ioport.h> 15 - #include <linux/interrupt.h> 16 - #include <linux/irqdesc.h> 13 + #include <linux/irq.h> 17 14 #include <linux/isa.h> 18 15 #include <linux/kernel.h> 19 16 #include <linux/module.h> 20 17 #include <linux/moduleparam.h> 21 - #include <linux/spinlock.h> 18 + #include <linux/regmap.h> 22 19 #include <linux/types.h> 23 20 24 21 #include "gpio-i8255.h" ··· 35 38 module_param_hw_array(irq, uint, irq, &num_irq, 0); 36 39 MODULE_PARM_DESC(irq, "ACCES 104-DIO-48E interrupt line numbers"); 37 40 41 + #define DIO48E_ENABLE_INTERRUPT 0xB 42 + #define DIO48E_DISABLE_INTERRUPT DIO48E_ENABLE_INTERRUPT 43 + #define DIO48E_CLEAR_INTERRUPT 0xF 44 + 38 45 #define DIO48E_NUM_PPI 2 39 46 40 - /** 41 - * struct dio48e_reg - device register structure 42 - * @ppi: Programmable Peripheral Interface groups 43 - * @enable_buffer: Enable/Disable Buffer groups 44 - * @unused1: Unused 45 - * @enable_interrupt: Write: Enable Interrupt 46 - * Read: Disable Interrupt 47 - * @unused2: Unused 48 - * @enable_counter: Write: Enable Counter/Timer Addressing 49 - * Read: Disable Counter/Timer Addressing 50 - * @unused3: Unused 51 - * @clear_interrupt: Clear Interrupt 52 - */ 53 - struct dio48e_reg { 54 - struct i8255 ppi[DIO48E_NUM_PPI]; 55 - u8 enable_buffer[DIO48E_NUM_PPI]; 56 - u8 unused1; 57 - u8 enable_interrupt; 58 - u8 unused2; 59 - u8 enable_counter; 60 - u8 unused3; 61 - u8 clear_interrupt; 47 + static const struct regmap_range dio48e_wr_ranges[] = { 48 + regmap_reg_range(0x0, 0x9), regmap_reg_range(0xB, 0xB), 49 + regmap_reg_range(0xD, 0xD), regmap_reg_range(0xF, 0xF), 50 + }; 51 + static const struct regmap_range dio48e_rd_ranges[] = { 52 + regmap_reg_range(0x0, 0x2), regmap_reg_range(0x4, 0x6), 53 + regmap_reg_range(0xB, 0xB), regmap_reg_range(0xD, 0xD), 54 + regmap_reg_range(0xF, 0xF), 55 + }; 56 + static const struct regmap_range dio48e_volatile_ranges[] = { 57 + i8255_volatile_regmap_range(0x0), i8255_volatile_regmap_range(0x4), 58 + regmap_reg_range(0xB, 0xB), regmap_reg_range(0xD, 0xD), 59 + regmap_reg_range(0xF, 0xF), 60 + }; 61 + static const struct regmap_range dio48e_precious_ranges[] = { 62 + regmap_reg_range(0xB, 0xB), regmap_reg_range(0xD, 0xD), 63 + regmap_reg_range(0xF, 0xF), 64 + }; 65 + static const struct regmap_access_table dio48e_wr_table = { 66 + .yes_ranges = dio48e_wr_ranges, 67 + .n_yes_ranges = ARRAY_SIZE(dio48e_wr_ranges), 68 + }; 69 + static const struct regmap_access_table dio48e_rd_table = { 70 + .yes_ranges = dio48e_rd_ranges, 71 + .n_yes_ranges = ARRAY_SIZE(dio48e_rd_ranges), 72 + }; 73 + static const struct regmap_access_table dio48e_volatile_table = { 74 + .yes_ranges = dio48e_volatile_ranges, 75 + .n_yes_ranges = ARRAY_SIZE(dio48e_volatile_ranges), 76 + }; 77 + static const struct regmap_access_table dio48e_precious_table = { 78 + .yes_ranges = dio48e_precious_ranges, 79 + .n_yes_ranges = ARRAY_SIZE(dio48e_precious_ranges), 80 + }; 81 + static const struct regmap_config dio48e_regmap_config = { 82 + .reg_bits = 8, 83 + .reg_stride = 1, 84 + .val_bits = 8, 85 + .io_port = true, 86 + .max_register = 0xF, 87 + .wr_table = &dio48e_wr_table, 88 + .rd_table = &dio48e_rd_table, 89 + .volatile_table = &dio48e_volatile_table, 90 + .precious_table = &dio48e_precious_table, 91 + .cache_type = REGCACHE_FLAT, 62 92 }; 63 93 64 - /** 65 - * struct dio48e_gpio - GPIO device private data structure 66 - * @chip: instance of the gpio_chip 67 - * @ppi_state: PPI device states 68 - * @lock: synchronization lock to prevent I/O race conditions 69 - * @reg: I/O address offset for the device registers 70 - * @irq_mask: I/O bits affected by interrupts 71 - */ 72 - struct dio48e_gpio { 73 - struct gpio_chip chip; 74 - struct i8255_state ppi_state[DIO48E_NUM_PPI]; 75 - raw_spinlock_t lock; 76 - struct dio48e_reg __iomem *reg; 77 - unsigned char irq_mask; 78 - }; 79 - 80 - static int dio48e_gpio_get_direction(struct gpio_chip *chip, unsigned int offset) 81 - { 82 - struct dio48e_gpio *const dio48egpio = gpiochip_get_data(chip); 83 - 84 - if (i8255_get_direction(dio48egpio->ppi_state, offset)) 85 - return GPIO_LINE_DIRECTION_IN; 86 - 87 - return GPIO_LINE_DIRECTION_OUT; 88 - } 89 - 90 - static int dio48e_gpio_direction_input(struct gpio_chip *chip, unsigned int offset) 91 - { 92 - struct dio48e_gpio *const dio48egpio = gpiochip_get_data(chip); 93 - 94 - i8255_direction_input(dio48egpio->reg->ppi, dio48egpio->ppi_state, 95 - offset); 96 - 97 - return 0; 98 - } 99 - 100 - static int dio48e_gpio_direction_output(struct gpio_chip *chip, unsigned int offset, 101 - int value) 102 - { 103 - struct dio48e_gpio *const dio48egpio = gpiochip_get_data(chip); 104 - 105 - i8255_direction_output(dio48egpio->reg->ppi, dio48egpio->ppi_state, 106 - offset, value); 107 - 108 - return 0; 109 - } 110 - 111 - static int dio48e_gpio_get(struct gpio_chip *chip, unsigned int offset) 112 - { 113 - struct dio48e_gpio *const dio48egpio = gpiochip_get_data(chip); 114 - 115 - return i8255_get(dio48egpio->reg->ppi, offset); 116 - } 117 - 118 - static int dio48e_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask, 119 - unsigned long *bits) 120 - { 121 - struct dio48e_gpio *const dio48egpio = gpiochip_get_data(chip); 122 - 123 - i8255_get_multiple(dio48egpio->reg->ppi, mask, bits, chip->ngpio); 124 - 125 - return 0; 126 - } 127 - 128 - static void dio48e_gpio_set(struct gpio_chip *chip, unsigned int offset, int value) 129 - { 130 - struct dio48e_gpio *const dio48egpio = gpiochip_get_data(chip); 131 - 132 - i8255_set(dio48egpio->reg->ppi, dio48egpio->ppi_state, offset, value); 133 - } 134 - 135 - static void dio48e_gpio_set_multiple(struct gpio_chip *chip, 136 - unsigned long *mask, unsigned long *bits) 137 - { 138 - struct dio48e_gpio *const dio48egpio = gpiochip_get_data(chip); 139 - 140 - i8255_set_multiple(dio48egpio->reg->ppi, dio48egpio->ppi_state, mask, 141 - bits, chip->ngpio); 142 - } 143 - 144 - static void dio48e_irq_ack(struct irq_data *data) 145 - { 146 - } 147 - 148 - static void dio48e_irq_mask(struct irq_data *data) 149 - { 150 - struct gpio_chip *chip = irq_data_get_irq_chip_data(data); 151 - struct dio48e_gpio *const dio48egpio = gpiochip_get_data(chip); 152 - const unsigned long offset = irqd_to_hwirq(data); 153 - unsigned long flags; 154 - 155 - /* only bit 3 on each respective Port C supports interrupts */ 156 - if (offset != 19 && offset != 43) 157 - return; 158 - 159 - raw_spin_lock_irqsave(&dio48egpio->lock, flags); 160 - 161 - if (offset == 19) 162 - dio48egpio->irq_mask &= ~BIT(0); 163 - else 164 - dio48egpio->irq_mask &= ~BIT(1); 165 - gpiochip_disable_irq(chip, offset); 166 - 167 - if (!dio48egpio->irq_mask) 168 - /* disable interrupts */ 169 - ioread8(&dio48egpio->reg->enable_interrupt); 170 - 171 - raw_spin_unlock_irqrestore(&dio48egpio->lock, flags); 172 - } 173 - 174 - static void dio48e_irq_unmask(struct irq_data *data) 175 - { 176 - struct gpio_chip *chip = irq_data_get_irq_chip_data(data); 177 - struct dio48e_gpio *const dio48egpio = gpiochip_get_data(chip); 178 - const unsigned long offset = irqd_to_hwirq(data); 179 - unsigned long flags; 180 - 181 - /* only bit 3 on each respective Port C supports interrupts */ 182 - if (offset != 19 && offset != 43) 183 - return; 184 - 185 - raw_spin_lock_irqsave(&dio48egpio->lock, flags); 186 - 187 - if (!dio48egpio->irq_mask) { 188 - /* enable interrupts */ 189 - iowrite8(0x00, &dio48egpio->reg->clear_interrupt); 190 - iowrite8(0x00, &dio48egpio->reg->enable_interrupt); 94 + /* only bit 3 on each respective Port C supports interrupts */ 95 + #define DIO48E_REGMAP_IRQ(_ppi) \ 96 + [19 + (_ppi) * 24] = { \ 97 + .mask = BIT(_ppi), \ 98 + .type = { .types_supported = IRQ_TYPE_EDGE_RISING }, \ 191 99 } 192 100 193 - gpiochip_enable_irq(chip, offset); 194 - if (offset == 19) 195 - dio48egpio->irq_mask |= BIT(0); 196 - else 197 - dio48egpio->irq_mask |= BIT(1); 198 - 199 - raw_spin_unlock_irqrestore(&dio48egpio->lock, flags); 200 - } 201 - 202 - static int dio48e_irq_set_type(struct irq_data *data, unsigned int flow_type) 203 - { 204 - const unsigned long offset = irqd_to_hwirq(data); 205 - 206 - /* only bit 3 on each respective Port C supports interrupts */ 207 - if (offset != 19 && offset != 43) 208 - return -EINVAL; 209 - 210 - if (flow_type != IRQ_TYPE_NONE && flow_type != IRQ_TYPE_EDGE_RISING) 211 - return -EINVAL; 212 - 213 - return 0; 214 - } 215 - 216 - static const struct irq_chip dio48e_irqchip = { 217 - .name = "104-dio-48e", 218 - .irq_ack = dio48e_irq_ack, 219 - .irq_mask = dio48e_irq_mask, 220 - .irq_unmask = dio48e_irq_unmask, 221 - .irq_set_type = dio48e_irq_set_type, 222 - .flags = IRQCHIP_IMMUTABLE, 223 - GPIOCHIP_IRQ_RESOURCE_HELPERS, 101 + static const struct regmap_irq dio48e_regmap_irqs[] = { 102 + DIO48E_REGMAP_IRQ(0), DIO48E_REGMAP_IRQ(1), 224 103 }; 225 104 226 - static irqreturn_t dio48e_irq_handler(int irq, void *dev_id) 105 + static int dio48e_handle_mask_sync(struct regmap *const map, const int index, 106 + const unsigned int mask_buf_def, 107 + const unsigned int mask_buf, 108 + void *const irq_drv_data) 227 109 { 228 - struct dio48e_gpio *const dio48egpio = dev_id; 229 - struct gpio_chip *const chip = &dio48egpio->chip; 230 - const unsigned long irq_mask = dio48egpio->irq_mask; 231 - unsigned long gpio; 110 + unsigned int *const irq_mask = irq_drv_data; 111 + const unsigned int prev_mask = *irq_mask; 112 + const unsigned int all_masked = GENMASK(1, 0); 113 + int err; 114 + unsigned int val; 232 115 233 - for_each_set_bit(gpio, &irq_mask, 2) 234 - generic_handle_domain_irq(chip->irq.domain, 235 - 19 + gpio*24); 116 + /* exit early if no change since the previous mask */ 117 + if (mask_buf == prev_mask) 118 + return 0; 236 119 237 - raw_spin_lock(&dio48egpio->lock); 120 + /* remember the current mask for the next mask sync */ 121 + *irq_mask = mask_buf; 238 122 239 - iowrite8(0x00, &dio48egpio->reg->clear_interrupt); 123 + /* if all previously masked, enable interrupts when unmasking */ 124 + if (prev_mask == all_masked) { 125 + err = regmap_write(map, DIO48E_CLEAR_INTERRUPT, 0x00); 126 + if (err) 127 + return err; 128 + return regmap_write(map, DIO48E_ENABLE_INTERRUPT, 0x00); 129 + } 240 130 241 - raw_spin_unlock(&dio48egpio->lock); 131 + /* if all are currently masked, disable interrupts */ 132 + if (mask_buf == all_masked) 133 + return regmap_read(map, DIO48E_DISABLE_INTERRUPT, &val); 242 134 243 - return IRQ_HANDLED; 135 + return 0; 244 136 } 245 137 246 138 #define DIO48E_NGPIO 48 ··· 152 266 "PPI Group 1 Port C 5", "PPI Group 1 Port C 6", "PPI Group 1 Port C 7" 153 267 }; 154 268 155 - static int dio48e_irq_init_hw(struct gpio_chip *gc) 269 + static int dio48e_irq_init_hw(struct regmap *const map) 156 270 { 157 - struct dio48e_gpio *const dio48egpio = gpiochip_get_data(gc); 271 + unsigned int val; 158 272 159 273 /* Disable IRQ by default */ 160 - ioread8(&dio48egpio->reg->enable_interrupt); 161 - 162 - return 0; 163 - } 164 - 165 - static void dio48e_init_ppi(struct i8255 __iomem *const ppi, 166 - struct i8255_state *const ppi_state) 167 - { 168 - const unsigned long ngpio = 24; 169 - const unsigned long mask = GENMASK(ngpio - 1, 0); 170 - const unsigned long bits = 0; 171 - unsigned long i; 172 - 173 - /* Initialize all GPIO to output 0 */ 174 - for (i = 0; i < DIO48E_NUM_PPI; i++) { 175 - i8255_mode0_output(&ppi[i]); 176 - i8255_set_multiple(&ppi[i], &ppi_state[i], &mask, &bits, ngpio); 177 - } 274 + return regmap_read(map, DIO48E_DISABLE_INTERRUPT, &val); 178 275 } 179 276 180 277 static int dio48e_probe(struct device *dev, unsigned int id) 181 278 { 182 - struct dio48e_gpio *dio48egpio; 183 279 const char *const name = dev_name(dev); 184 - struct gpio_irq_chip *girq; 280 + struct i8255_regmap_config config = {}; 281 + void __iomem *regs; 282 + struct regmap *map; 185 283 int err; 186 - 187 - dio48egpio = devm_kzalloc(dev, sizeof(*dio48egpio), GFP_KERNEL); 188 - if (!dio48egpio) 189 - return -ENOMEM; 284 + struct regmap_irq_chip *chip; 285 + unsigned int irq_mask; 286 + struct regmap_irq_chip_data *chip_data; 190 287 191 288 if (!devm_request_region(dev, base[id], DIO48E_EXTENT, name)) { 192 289 dev_err(dev, "Unable to lock port addresses (0x%X-0x%X)\n", ··· 177 308 return -EBUSY; 178 309 } 179 310 180 - dio48egpio->reg = devm_ioport_map(dev, base[id], DIO48E_EXTENT); 181 - if (!dio48egpio->reg) 311 + regs = devm_ioport_map(dev, base[id], DIO48E_EXTENT); 312 + if (!regs) 182 313 return -ENOMEM; 183 314 184 - dio48egpio->chip.label = name; 185 - dio48egpio->chip.parent = dev; 186 - dio48egpio->chip.owner = THIS_MODULE; 187 - dio48egpio->chip.base = -1; 188 - dio48egpio->chip.ngpio = DIO48E_NGPIO; 189 - dio48egpio->chip.names = dio48e_names; 190 - dio48egpio->chip.get_direction = dio48e_gpio_get_direction; 191 - dio48egpio->chip.direction_input = dio48e_gpio_direction_input; 192 - dio48egpio->chip.direction_output = dio48e_gpio_direction_output; 193 - dio48egpio->chip.get = dio48e_gpio_get; 194 - dio48egpio->chip.get_multiple = dio48e_gpio_get_multiple; 195 - dio48egpio->chip.set = dio48e_gpio_set; 196 - dio48egpio->chip.set_multiple = dio48e_gpio_set_multiple; 315 + map = devm_regmap_init_mmio(dev, regs, &dio48e_regmap_config); 316 + if (IS_ERR(map)) 317 + return dev_err_probe(dev, PTR_ERR(map), 318 + "Unable to initialize register map\n"); 197 319 198 - girq = &dio48egpio->chip.irq; 199 - gpio_irq_chip_set_chip(girq, &dio48e_irqchip); 200 - /* This will let us handle the parent IRQ in the driver */ 201 - girq->parent_handler = NULL; 202 - girq->num_parents = 0; 203 - girq->parents = NULL; 204 - girq->default_type = IRQ_TYPE_NONE; 205 - girq->handler = handle_edge_irq; 206 - girq->init_hw = dio48e_irq_init_hw; 320 + chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); 321 + if (!chip) 322 + return -ENOMEM; 207 323 208 - raw_spin_lock_init(&dio48egpio->lock); 324 + chip->irq_drv_data = devm_kzalloc(dev, sizeof(irq_mask), GFP_KERNEL); 325 + if (!chip->irq_drv_data) 326 + return -ENOMEM; 209 327 210 - i8255_state_init(dio48egpio->ppi_state, DIO48E_NUM_PPI); 211 - dio48e_init_ppi(dio48egpio->reg->ppi, dio48egpio->ppi_state); 328 + chip->name = name; 329 + /* No IRQ status register so use CLEAR_INTERRUPT register instead */ 330 + chip->status_base = DIO48E_CLEAR_INTERRUPT; 331 + chip->mask_base = DIO48E_ENABLE_INTERRUPT; 332 + chip->ack_base = DIO48E_CLEAR_INTERRUPT; 333 + /* CLEAR_INTERRUPT doubles as status register so we need it cleared */ 334 + chip->clear_ack = true; 335 + chip->status_invert = true; 336 + chip->num_regs = 1; 337 + chip->irqs = dio48e_regmap_irqs; 338 + chip->num_irqs = ARRAY_SIZE(dio48e_regmap_irqs); 339 + chip->handle_mask_sync = dio48e_handle_mask_sync; 212 340 213 - err = devm_gpiochip_add_data(dev, &dio48egpio->chip, dio48egpio); 214 - if (err) { 215 - dev_err(dev, "GPIO registering failed (%d)\n", err); 341 + /* Initialize to prevent spurious interrupts before we're ready */ 342 + err = dio48e_irq_init_hw(map); 343 + if (err) 216 344 return err; 217 - } 218 345 219 - err = devm_request_irq(dev, irq[id], dio48e_irq_handler, 0, name, 220 - dio48egpio); 221 - if (err) { 222 - dev_err(dev, "IRQ handler registering failed (%d)\n", err); 223 - return err; 224 - } 346 + err = devm_regmap_add_irq_chip(dev, map, irq[id], 0, 0, chip, &chip_data); 347 + if (err) 348 + return dev_err_probe(dev, err, "IRQ registration failed\n"); 225 349 226 - return 0; 350 + config.parent = dev; 351 + config.map = map; 352 + config.num_ppi = DIO48E_NUM_PPI; 353 + config.names = dio48e_names; 354 + config.domain = regmap_irq_get_domain(chip_data); 355 + 356 + return devm_i8255_regmap_register(dev, &config); 227 357 } 228 358 229 359 static struct isa_driver dio48e_driver = {
+106 -230
drivers/gpio/gpio-104-idi-48.c
··· 8 8 */ 9 9 #include <linux/bits.h> 10 10 #include <linux/device.h> 11 - #include <linux/errno.h> 12 - #include <linux/gpio/driver.h> 13 - #include <linux/io.h> 14 - #include <linux/ioport.h> 11 + #include <linux/err.h> 12 + #include <linux/gpio/regmap.h> 15 13 #include <linux/interrupt.h> 16 - #include <linux/irqdesc.h> 14 + #include <linux/ioport.h> 15 + #include <linux/irq.h> 17 16 #include <linux/isa.h> 18 17 #include <linux/kernel.h> 19 18 #include <linux/module.h> 20 19 #include <linux/moduleparam.h> 21 - #include <linux/spinlock.h> 20 + #include <linux/regmap.h> 22 21 #include <linux/types.h> 23 - 24 - #include "gpio-i8255.h" 25 - 26 - MODULE_IMPORT_NS(I8255); 27 22 28 23 #define IDI_48_EXTENT 8 29 24 #define MAX_NUM_IDI_48 max_num_isa_dev(IDI_48_EXTENT) ··· 33 38 module_param_hw_array(irq, uint, irq, &num_irq, 0); 34 39 MODULE_PARM_DESC(irq, "ACCES 104-IDI-48 interrupt line numbers"); 35 40 36 - /** 37 - * struct idi_48_reg - device register structure 38 - * @port0: Port 0 Inputs 39 - * @unused: Unused 40 - * @port1: Port 1 Inputs 41 - * @irq: Read: IRQ Status Register/IRQ Clear 42 - * Write: IRQ Enable/Disable 43 - */ 44 - struct idi_48_reg { 45 - u8 port0[3]; 46 - u8 unused; 47 - u8 port1[3]; 48 - u8 irq; 49 - }; 41 + #define IDI48_IRQ_STATUS 0x7 42 + #define IDI48_IRQ_ENABLE IDI48_IRQ_STATUS 50 43 51 - /** 52 - * struct idi_48_gpio - GPIO device private data structure 53 - * @chip: instance of the gpio_chip 54 - * @lock: synchronization lock to prevent I/O race conditions 55 - * @irq_mask: input bits affected by interrupts 56 - * @reg: I/O address offset for the device registers 57 - * @cos_enb: Change-Of-State IRQ enable boundaries mask 58 - */ 59 - struct idi_48_gpio { 60 - struct gpio_chip chip; 61 - spinlock_t lock; 62 - unsigned char irq_mask[6]; 63 - struct idi_48_reg __iomem *reg; 64 - unsigned char cos_enb; 65 - }; 66 - 67 - static int idi_48_gpio_get_direction(struct gpio_chip *chip, unsigned int offset) 44 + static int idi_48_reg_mask_xlate(struct gpio_regmap *gpio, unsigned int base, 45 + unsigned int offset, unsigned int *reg, 46 + unsigned int *mask) 68 47 { 69 - return GPIO_LINE_DIRECTION_IN; 70 - } 48 + const unsigned int line = offset % 8; 49 + const unsigned int stride = offset / 8; 50 + const unsigned int port = (stride / 3) * 4; 51 + const unsigned int port_stride = stride % 3; 71 52 72 - static int idi_48_gpio_direction_input(struct gpio_chip *chip, unsigned int offset) 73 - { 74 - return 0; 75 - } 76 - 77 - static int idi_48_gpio_get(struct gpio_chip *chip, unsigned int offset) 78 - { 79 - struct idi_48_gpio *const idi48gpio = gpiochip_get_data(chip); 80 - void __iomem *const ppi = idi48gpio->reg; 81 - 82 - return i8255_get(ppi, offset); 83 - } 84 - 85 - static int idi_48_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask, 86 - unsigned long *bits) 87 - { 88 - struct idi_48_gpio *const idi48gpio = gpiochip_get_data(chip); 89 - void __iomem *const ppi = idi48gpio->reg; 90 - 91 - i8255_get_multiple(ppi, mask, bits, chip->ngpio); 53 + *reg = base + port + port_stride; 54 + *mask = BIT(line); 92 55 93 56 return 0; 94 57 } 95 58 96 - static void idi_48_irq_ack(struct irq_data *data) 97 - { 98 - } 99 - 100 - static void idi_48_irq_mask(struct irq_data *data) 101 - { 102 - struct gpio_chip *chip = irq_data_get_irq_chip_data(data); 103 - struct idi_48_gpio *const idi48gpio = gpiochip_get_data(chip); 104 - const unsigned int offset = irqd_to_hwirq(data); 105 - const unsigned long boundary = offset / 8; 106 - const unsigned long mask = BIT(offset % 8); 107 - unsigned long flags; 108 - 109 - spin_lock_irqsave(&idi48gpio->lock, flags); 110 - 111 - idi48gpio->irq_mask[boundary] &= ~mask; 112 - gpiochip_disable_irq(chip, offset); 113 - 114 - /* Exit early if there are still input lines with IRQ unmasked */ 115 - if (idi48gpio->irq_mask[boundary]) 116 - goto exit; 117 - 118 - idi48gpio->cos_enb &= ~BIT(boundary); 119 - 120 - iowrite8(idi48gpio->cos_enb, &idi48gpio->reg->irq); 121 - 122 - exit: 123 - spin_unlock_irqrestore(&idi48gpio->lock, flags); 124 - } 125 - 126 - static void idi_48_irq_unmask(struct irq_data *data) 127 - { 128 - struct gpio_chip *chip = irq_data_get_irq_chip_data(data); 129 - struct idi_48_gpio *const idi48gpio = gpiochip_get_data(chip); 130 - const unsigned int offset = irqd_to_hwirq(data); 131 - const unsigned long boundary = offset / 8; 132 - const unsigned long mask = BIT(offset % 8); 133 - unsigned int prev_irq_mask; 134 - unsigned long flags; 135 - 136 - spin_lock_irqsave(&idi48gpio->lock, flags); 137 - 138 - prev_irq_mask = idi48gpio->irq_mask[boundary]; 139 - 140 - gpiochip_enable_irq(chip, offset); 141 - idi48gpio->irq_mask[boundary] |= mask; 142 - 143 - /* Exit early if IRQ was already unmasked for this boundary */ 144 - if (prev_irq_mask) 145 - goto exit; 146 - 147 - idi48gpio->cos_enb |= BIT(boundary); 148 - 149 - iowrite8(idi48gpio->cos_enb, &idi48gpio->reg->irq); 150 - 151 - exit: 152 - spin_unlock_irqrestore(&idi48gpio->lock, flags); 153 - } 154 - 155 - static int idi_48_irq_set_type(struct irq_data *data, unsigned int flow_type) 156 - { 157 - /* The only valid irq types are none and both-edges */ 158 - if (flow_type != IRQ_TYPE_NONE && 159 - (flow_type & IRQ_TYPE_EDGE_BOTH) != IRQ_TYPE_EDGE_BOTH) 160 - return -EINVAL; 161 - 162 - return 0; 163 - } 164 - 165 - static const struct irq_chip idi_48_irqchip = { 166 - .name = "104-idi-48", 167 - .irq_ack = idi_48_irq_ack, 168 - .irq_mask = idi_48_irq_mask, 169 - .irq_unmask = idi_48_irq_unmask, 170 - .irq_set_type = idi_48_irq_set_type, 171 - .flags = IRQCHIP_IMMUTABLE, 172 - GPIOCHIP_IRQ_RESOURCE_HELPERS, 59 + static const struct regmap_range idi_48_wr_ranges[] = { 60 + regmap_reg_range(0x0, 0x6), 173 61 }; 174 - 175 - static irqreturn_t idi_48_irq_handler(int irq, void *dev_id) 176 - { 177 - struct idi_48_gpio *const idi48gpio = dev_id; 178 - unsigned long cos_status; 179 - unsigned long boundary; 180 - unsigned long irq_mask; 181 - unsigned long bit_num; 182 - unsigned long gpio; 183 - struct gpio_chip *const chip = &idi48gpio->chip; 184 - 185 - spin_lock(&idi48gpio->lock); 186 - 187 - cos_status = ioread8(&idi48gpio->reg->irq); 188 - 189 - /* IRQ Status (bit 6) is active low (0 = IRQ generated by device) */ 190 - if (cos_status & BIT(6)) { 191 - spin_unlock(&idi48gpio->lock); 192 - return IRQ_NONE; 193 - } 194 - 195 - /* Bit 0-5 indicate which Change-Of-State boundary triggered the IRQ */ 196 - cos_status &= 0x3F; 197 - 198 - for_each_set_bit(boundary, &cos_status, 6) { 199 - irq_mask = idi48gpio->irq_mask[boundary]; 200 - 201 - for_each_set_bit(bit_num, &irq_mask, 8) { 202 - gpio = bit_num + boundary * 8; 203 - 204 - generic_handle_domain_irq(chip->irq.domain, 205 - gpio); 206 - } 207 - } 208 - 209 - spin_unlock(&idi48gpio->lock); 210 - 211 - return IRQ_HANDLED; 212 - } 62 + static const struct regmap_range idi_48_rd_ranges[] = { 63 + regmap_reg_range(0x0, 0x2), regmap_reg_range(0x4, 0x7), 64 + }; 65 + static const struct regmap_range idi_48_precious_ranges[] = { 66 + regmap_reg_range(0x7, 0x7), 67 + }; 68 + static const struct regmap_access_table idi_48_wr_table = { 69 + .no_ranges = idi_48_wr_ranges, 70 + .n_no_ranges = ARRAY_SIZE(idi_48_wr_ranges), 71 + }; 72 + static const struct regmap_access_table idi_48_rd_table = { 73 + .yes_ranges = idi_48_rd_ranges, 74 + .n_yes_ranges = ARRAY_SIZE(idi_48_rd_ranges), 75 + }; 76 + static const struct regmap_access_table idi_48_precious_table = { 77 + .yes_ranges = idi_48_precious_ranges, 78 + .n_yes_ranges = ARRAY_SIZE(idi_48_precious_ranges), 79 + }; 80 + static const struct regmap_config idi48_regmap_config = { 81 + .reg_bits = 8, 82 + .reg_stride = 1, 83 + .val_bits = 8, 84 + .io_port = true, 85 + .max_register = 0x6, 86 + .wr_table = &idi_48_wr_table, 87 + .rd_table = &idi_48_rd_table, 88 + .precious_table = &idi_48_precious_table, 89 + }; 213 90 214 91 #define IDI48_NGPIO 48 92 + 93 + #define IDI48_REGMAP_IRQ(_id) \ 94 + [_id] = { \ 95 + .mask = BIT((_id) / 8), \ 96 + .type = { .types_supported = IRQ_TYPE_EDGE_BOTH }, \ 97 + } 98 + 99 + static const struct regmap_irq idi48_regmap_irqs[IDI48_NGPIO] = { 100 + IDI48_REGMAP_IRQ(0), IDI48_REGMAP_IRQ(1), IDI48_REGMAP_IRQ(2), /* 0-2 */ 101 + IDI48_REGMAP_IRQ(3), IDI48_REGMAP_IRQ(4), IDI48_REGMAP_IRQ(5), /* 3-5 */ 102 + IDI48_REGMAP_IRQ(6), IDI48_REGMAP_IRQ(7), IDI48_REGMAP_IRQ(8), /* 6-8 */ 103 + IDI48_REGMAP_IRQ(9), IDI48_REGMAP_IRQ(10), IDI48_REGMAP_IRQ(11), /* 9-11 */ 104 + IDI48_REGMAP_IRQ(12), IDI48_REGMAP_IRQ(13), IDI48_REGMAP_IRQ(14), /* 12-14 */ 105 + IDI48_REGMAP_IRQ(15), IDI48_REGMAP_IRQ(16), IDI48_REGMAP_IRQ(17), /* 15-17 */ 106 + IDI48_REGMAP_IRQ(18), IDI48_REGMAP_IRQ(19), IDI48_REGMAP_IRQ(20), /* 18-20 */ 107 + IDI48_REGMAP_IRQ(21), IDI48_REGMAP_IRQ(22), IDI48_REGMAP_IRQ(23), /* 21-23 */ 108 + IDI48_REGMAP_IRQ(24), IDI48_REGMAP_IRQ(25), IDI48_REGMAP_IRQ(26), /* 24-26 */ 109 + IDI48_REGMAP_IRQ(27), IDI48_REGMAP_IRQ(28), IDI48_REGMAP_IRQ(29), /* 27-29 */ 110 + IDI48_REGMAP_IRQ(30), IDI48_REGMAP_IRQ(31), IDI48_REGMAP_IRQ(32), /* 30-32 */ 111 + IDI48_REGMAP_IRQ(33), IDI48_REGMAP_IRQ(34), IDI48_REGMAP_IRQ(35), /* 33-35 */ 112 + IDI48_REGMAP_IRQ(36), IDI48_REGMAP_IRQ(37), IDI48_REGMAP_IRQ(38), /* 36-38 */ 113 + IDI48_REGMAP_IRQ(39), IDI48_REGMAP_IRQ(40), IDI48_REGMAP_IRQ(41), /* 39-41 */ 114 + IDI48_REGMAP_IRQ(42), IDI48_REGMAP_IRQ(43), IDI48_REGMAP_IRQ(44), /* 42-44 */ 115 + IDI48_REGMAP_IRQ(45), IDI48_REGMAP_IRQ(46), IDI48_REGMAP_IRQ(47), /* 45-47 */ 116 + }; 117 + 215 118 static const char *idi48_names[IDI48_NGPIO] = { 216 119 "Bit 0 A", "Bit 1 A", "Bit 2 A", "Bit 3 A", "Bit 4 A", "Bit 5 A", 217 120 "Bit 6 A", "Bit 7 A", "Bit 8 A", "Bit 9 A", "Bit 10 A", "Bit 11 A", ··· 121 228 "Bit 18 B", "Bit 19 B", "Bit 20 B", "Bit 21 B", "Bit 22 B", "Bit 23 B" 122 229 }; 123 230 124 - static int idi_48_irq_init_hw(struct gpio_chip *gc) 125 - { 126 - struct idi_48_gpio *const idi48gpio = gpiochip_get_data(gc); 127 - 128 - /* Disable IRQ by default */ 129 - iowrite8(0, &idi48gpio->reg->irq); 130 - ioread8(&idi48gpio->reg->irq); 131 - 132 - return 0; 133 - } 134 - 135 231 static int idi_48_probe(struct device *dev, unsigned int id) 136 232 { 137 - struct idi_48_gpio *idi48gpio; 138 233 const char *const name = dev_name(dev); 139 - struct gpio_irq_chip *girq; 234 + struct gpio_regmap_config config = {}; 235 + void __iomem *regs; 236 + struct regmap *map; 237 + struct regmap_irq_chip *chip; 238 + struct regmap_irq_chip_data *chip_data; 140 239 int err; 141 - 142 - idi48gpio = devm_kzalloc(dev, sizeof(*idi48gpio), GFP_KERNEL); 143 - if (!idi48gpio) 144 - return -ENOMEM; 145 240 146 241 if (!devm_request_region(dev, base[id], IDI_48_EXTENT, name)) { 147 242 dev_err(dev, "Unable to lock port addresses (0x%X-0x%X)\n", ··· 137 256 return -EBUSY; 138 257 } 139 258 140 - idi48gpio->reg = devm_ioport_map(dev, base[id], IDI_48_EXTENT); 141 - if (!idi48gpio->reg) 259 + regs = devm_ioport_map(dev, base[id], IDI_48_EXTENT); 260 + if (!regs) 142 261 return -ENOMEM; 143 262 144 - idi48gpio->chip.label = name; 145 - idi48gpio->chip.parent = dev; 146 - idi48gpio->chip.owner = THIS_MODULE; 147 - idi48gpio->chip.base = -1; 148 - idi48gpio->chip.ngpio = IDI48_NGPIO; 149 - idi48gpio->chip.names = idi48_names; 150 - idi48gpio->chip.get_direction = idi_48_gpio_get_direction; 151 - idi48gpio->chip.direction_input = idi_48_gpio_direction_input; 152 - idi48gpio->chip.get = idi_48_gpio_get; 153 - idi48gpio->chip.get_multiple = idi_48_gpio_get_multiple; 263 + map = devm_regmap_init_mmio(dev, regs, &idi48_regmap_config); 264 + if (IS_ERR(map)) 265 + return dev_err_probe(dev, PTR_ERR(map), 266 + "Unable to initialize register map\n"); 154 267 155 - girq = &idi48gpio->chip.irq; 156 - gpio_irq_chip_set_chip(girq, &idi_48_irqchip); 157 - /* This will let us handle the parent IRQ in the driver */ 158 - girq->parent_handler = NULL; 159 - girq->num_parents = 0; 160 - girq->parents = NULL; 161 - girq->default_type = IRQ_TYPE_NONE; 162 - girq->handler = handle_edge_irq; 163 - girq->init_hw = idi_48_irq_init_hw; 268 + chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); 269 + if (!chip) 270 + return -ENOMEM; 164 271 165 - spin_lock_init(&idi48gpio->lock); 272 + chip->name = name; 273 + chip->status_base = IDI48_IRQ_STATUS; 274 + chip->unmask_base = IDI48_IRQ_ENABLE; 275 + chip->clear_on_unmask = true; 276 + chip->num_regs = 1; 277 + chip->irqs = idi48_regmap_irqs; 278 + chip->num_irqs = ARRAY_SIZE(idi48_regmap_irqs); 166 279 167 - err = devm_gpiochip_add_data(dev, &idi48gpio->chip, idi48gpio); 168 - if (err) { 169 - dev_err(dev, "GPIO registering failed (%d)\n", err); 170 - return err; 171 - } 280 + err = devm_regmap_add_irq_chip(dev, map, irq[id], IRQF_SHARED, 0, chip, 281 + &chip_data); 282 + if (err) 283 + return dev_err_probe(dev, err, "IRQ registration failed\n"); 172 284 173 - err = devm_request_irq(dev, irq[id], idi_48_irq_handler, IRQF_SHARED, 174 - name, idi48gpio); 175 - if (err) { 176 - dev_err(dev, "IRQ handler registering failed (%d)\n", err); 177 - return err; 178 - } 285 + config.parent = dev; 286 + config.regmap = map; 287 + config.ngpio = IDI48_NGPIO; 288 + config.names = idi48_names; 289 + config.reg_dat_base = GPIO_REGMAP_ADDR(0x0); 290 + config.ngpio_per_reg = 8; 291 + config.reg_mask_xlate = idi_48_reg_mask_xlate; 292 + config.irq_domain = regmap_irq_get_domain(chip_data); 179 293 180 - return 0; 294 + return PTR_ERR_OR_ZERO(devm_gpio_regmap_register(dev, &config)); 181 295 } 182 296 183 297 static struct isa_driver idi_48_driver = {
+1 -2
drivers/gpio/gpio-davinci.c
··· 252 252 chips->chip.base = pdata->no_auto_base ? pdata->base : -1; 253 253 254 254 #ifdef CONFIG_OF_GPIO 255 - chips->chip.of_gpio_n_cells = 2; 256 255 chips->chip.parent = dev; 257 256 chips->chip.request = gpiochip_generic_request; 258 257 chips->chip.free = gpiochip_generic_free; ··· 533 534 } 534 535 535 536 /* 536 - * Arrange gpio_to_irq() support, handling either direct IRQs or 537 + * Arrange gpiod_to_irq() support, handling either direct IRQs or 537 538 * banked IRQs. Having GPIOs in the first GPIO bank use direct 538 539 * IRQs, while the others use banked IRQs, would need some setup 539 540 * tweaks to recognize hardware which can do that.
-1
drivers/gpio/gpio-ge.c
··· 81 81 82 82 gc->base = -1; 83 83 gc->ngpio = (u16)(uintptr_t)of_device_get_match_data(&pdev->dev); 84 - gc->of_gpio_n_cells = 2; 85 84 86 85 /* This function adds a memory mapped GPIO chip */ 87 86 ret = devm_gpiochip_add_data(&pdev->dev, gc, NULL);
+29 -123
drivers/gpio/gpio-gpio-mm.c
··· 8 8 */ 9 9 #include <linux/device.h> 10 10 #include <linux/errno.h> 11 - #include <linux/gpio/driver.h> 12 - #include <linux/io.h> 13 11 #include <linux/ioport.h> 14 12 #include <linux/isa.h> 15 13 #include <linux/kernel.h> 16 14 #include <linux/module.h> 17 15 #include <linux/moduleparam.h> 16 + #include <linux/regmap.h> 17 + #include <linux/types.h> 18 18 19 19 #include "gpio-i8255.h" 20 20 ··· 30 30 31 31 #define GPIOMM_NUM_PPI 2 32 32 33 - /** 34 - * struct gpiomm_gpio - GPIO device private data structure 35 - * @chip: instance of the gpio_chip 36 - * @ppi_state: Programmable Peripheral Interface group states 37 - * @ppi: Programmable Peripheral Interface groups 38 - */ 39 - struct gpiomm_gpio { 40 - struct gpio_chip chip; 41 - struct i8255_state ppi_state[GPIOMM_NUM_PPI]; 42 - struct i8255 __iomem *ppi; 33 + static const struct regmap_range gpiomm_volatile_ranges[] = { 34 + i8255_volatile_regmap_range(0x0), i8255_volatile_regmap_range(0x4), 43 35 }; 44 - 45 - static int gpiomm_gpio_get_direction(struct gpio_chip *chip, 46 - unsigned int offset) 47 - { 48 - struct gpiomm_gpio *const gpiommgpio = gpiochip_get_data(chip); 49 - 50 - if (i8255_get_direction(gpiommgpio->ppi_state, offset)) 51 - return GPIO_LINE_DIRECTION_IN; 52 - 53 - return GPIO_LINE_DIRECTION_OUT; 54 - } 55 - 56 - static int gpiomm_gpio_direction_input(struct gpio_chip *chip, 57 - unsigned int offset) 58 - { 59 - struct gpiomm_gpio *const gpiommgpio = gpiochip_get_data(chip); 60 - 61 - i8255_direction_input(gpiommgpio->ppi, gpiommgpio->ppi_state, offset); 62 - 63 - return 0; 64 - } 65 - 66 - static int gpiomm_gpio_direction_output(struct gpio_chip *chip, 67 - unsigned int offset, int value) 68 - { 69 - struct gpiomm_gpio *const gpiommgpio = gpiochip_get_data(chip); 70 - 71 - i8255_direction_output(gpiommgpio->ppi, gpiommgpio->ppi_state, offset, 72 - value); 73 - 74 - return 0; 75 - } 76 - 77 - static int gpiomm_gpio_get(struct gpio_chip *chip, unsigned int offset) 78 - { 79 - struct gpiomm_gpio *const gpiommgpio = gpiochip_get_data(chip); 80 - 81 - return i8255_get(gpiommgpio->ppi, offset); 82 - } 83 - 84 - static int gpiomm_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask, 85 - unsigned long *bits) 86 - { 87 - struct gpiomm_gpio *const gpiommgpio = gpiochip_get_data(chip); 88 - 89 - i8255_get_multiple(gpiommgpio->ppi, mask, bits, chip->ngpio); 90 - 91 - return 0; 92 - } 93 - 94 - static void gpiomm_gpio_set(struct gpio_chip *chip, unsigned int offset, 95 - int value) 96 - { 97 - struct gpiomm_gpio *const gpiommgpio = gpiochip_get_data(chip); 98 - 99 - i8255_set(gpiommgpio->ppi, gpiommgpio->ppi_state, offset, value); 100 - } 101 - 102 - static void gpiomm_gpio_set_multiple(struct gpio_chip *chip, 103 - unsigned long *mask, unsigned long *bits) 104 - { 105 - struct gpiomm_gpio *const gpiommgpio = gpiochip_get_data(chip); 106 - 107 - i8255_set_multiple(gpiommgpio->ppi, gpiommgpio->ppi_state, mask, bits, 108 - chip->ngpio); 109 - } 36 + static const struct regmap_access_table gpiomm_volatile_table = { 37 + .yes_ranges = gpiomm_volatile_ranges, 38 + .n_yes_ranges = ARRAY_SIZE(gpiomm_volatile_ranges), 39 + }; 40 + static const struct regmap_config gpiomm_regmap_config = { 41 + .reg_bits = 8, 42 + .reg_stride = 1, 43 + .val_bits = 8, 44 + .io_port = true, 45 + .max_register = 0x7, 46 + .volatile_table = &gpiomm_volatile_table, 47 + .cache_type = REGCACHE_FLAT, 48 + }; 110 49 111 50 #define GPIOMM_NGPIO 48 112 51 static const char *gpiomm_names[GPIOMM_NGPIO] = { ··· 59 120 "Port 2C2", "Port 2C3", "Port 2C4", "Port 2C5", "Port 2C6", "Port 2C7", 60 121 }; 61 122 62 - static void gpiomm_init_dio(struct i8255 __iomem *const ppi, 63 - struct i8255_state *const ppi_state) 64 - { 65 - const unsigned long ngpio = 24; 66 - const unsigned long mask = GENMASK(ngpio - 1, 0); 67 - const unsigned long bits = 0; 68 - unsigned long i; 69 - 70 - /* Initialize all GPIO to output 0 */ 71 - for (i = 0; i < GPIOMM_NUM_PPI; i++) { 72 - i8255_mode0_output(&ppi[i]); 73 - i8255_set_multiple(&ppi[i], &ppi_state[i], &mask, &bits, ngpio); 74 - } 75 - } 76 - 77 123 static int gpiomm_probe(struct device *dev, unsigned int id) 78 124 { 79 - struct gpiomm_gpio *gpiommgpio; 80 125 const char *const name = dev_name(dev); 81 - int err; 82 - 83 - gpiommgpio = devm_kzalloc(dev, sizeof(*gpiommgpio), GFP_KERNEL); 84 - if (!gpiommgpio) 85 - return -ENOMEM; 126 + struct i8255_regmap_config config = {}; 127 + void __iomem *regs; 86 128 87 129 if (!devm_request_region(dev, base[id], GPIOMM_EXTENT, name)) { 88 130 dev_err(dev, "Unable to lock port addresses (0x%X-0x%X)\n", ··· 71 151 return -EBUSY; 72 152 } 73 153 74 - gpiommgpio->ppi = devm_ioport_map(dev, base[id], GPIOMM_EXTENT); 75 - if (!gpiommgpio->ppi) 154 + regs = devm_ioport_map(dev, base[id], GPIOMM_EXTENT); 155 + if (!regs) 76 156 return -ENOMEM; 77 157 78 - gpiommgpio->chip.label = name; 79 - gpiommgpio->chip.parent = dev; 80 - gpiommgpio->chip.owner = THIS_MODULE; 81 - gpiommgpio->chip.base = -1; 82 - gpiommgpio->chip.ngpio = GPIOMM_NGPIO; 83 - gpiommgpio->chip.names = gpiomm_names; 84 - gpiommgpio->chip.get_direction = gpiomm_gpio_get_direction; 85 - gpiommgpio->chip.direction_input = gpiomm_gpio_direction_input; 86 - gpiommgpio->chip.direction_output = gpiomm_gpio_direction_output; 87 - gpiommgpio->chip.get = gpiomm_gpio_get; 88 - gpiommgpio->chip.get_multiple = gpiomm_gpio_get_multiple; 89 - gpiommgpio->chip.set = gpiomm_gpio_set; 90 - gpiommgpio->chip.set_multiple = gpiomm_gpio_set_multiple; 158 + config.map = devm_regmap_init_mmio(dev, regs, &gpiomm_regmap_config); 159 + if (IS_ERR(config.map)) 160 + return dev_err_probe(dev, PTR_ERR(config.map), 161 + "Unable to initialize register map\n"); 91 162 92 - i8255_state_init(gpiommgpio->ppi_state, GPIOMM_NUM_PPI); 93 - gpiomm_init_dio(gpiommgpio->ppi, gpiommgpio->ppi_state); 163 + config.parent = dev; 164 + config.num_ppi = GPIOMM_NUM_PPI; 165 + config.names = gpiomm_names; 94 166 95 - err = devm_gpiochip_add_data(dev, &gpiommgpio->chip, gpiommgpio); 96 - if (err) { 97 - dev_err(dev, "GPIO registering failed (%d)\n", err); 98 - return err; 99 - } 100 - 101 - return 0; 167 + return devm_i8255_regmap_register(dev, &config); 102 168 } 103 169 104 170 static struct isa_driver gpiomm_driver = {
+82 -228
drivers/gpio/gpio-i8255.c
··· 3 3 * Intel 8255 Programmable Peripheral Interface 4 4 * Copyright (C) 2022 William Breathitt Gray 5 5 */ 6 - #include <linux/bitmap.h> 6 + #include <linux/bits.h> 7 + #include <linux/device.h> 7 8 #include <linux/err.h> 8 9 #include <linux/export.h> 9 - #include <linux/io.h> 10 + #include <linux/gpio/regmap.h> 10 11 #include <linux/module.h> 11 - #include <linux/spinlock.h> 12 - #include <linux/types.h> 12 + #include <linux/regmap.h> 13 13 14 14 #include "gpio-i8255.h" 15 15 16 + #define I8255_NGPIO 24 17 + #define I8255_NGPIO_PER_REG 8 16 18 #define I8255_CONTROL_PORTC_LOWER_DIRECTION BIT(0) 17 19 #define I8255_CONTROL_PORTB_DIRECTION BIT(1) 18 20 #define I8255_CONTROL_PORTC_UPPER_DIRECTION BIT(3) 19 21 #define I8255_CONTROL_PORTA_DIRECTION BIT(4) 20 22 #define I8255_CONTROL_MODE_SET BIT(7) 21 - #define I8255_PORTA 0 22 - #define I8255_PORTB 1 23 - #define I8255_PORTC 2 23 + #define I8255_PORTA 0x0 24 + #define I8255_PORTB 0x1 25 + #define I8255_PORTC 0x2 26 + #define I8255_CONTROL 0x3 27 + #define I8255_REG_DAT_BASE I8255_PORTA 28 + #define I8255_REG_DIR_IN_BASE I8255_CONTROL 24 29 25 - static int i8255_get_port(struct i8255 __iomem *const ppi, 26 - const unsigned long io_port, const unsigned long mask) 30 + static int i8255_direction_mask(const unsigned int offset) 27 31 { 28 - const unsigned long bank = io_port / 3; 29 - const unsigned long ppi_port = io_port % 3; 32 + const unsigned int stride = offset / I8255_NGPIO_PER_REG; 33 + const unsigned int line = offset % I8255_NGPIO_PER_REG; 30 34 31 - return ioread8(&ppi[bank].port[ppi_port]) & mask; 32 - } 33 - 34 - static u8 i8255_direction_mask(const unsigned long offset) 35 - { 36 - const unsigned long port_offset = offset % 8; 37 - const unsigned long io_port = offset / 8; 38 - const unsigned long ppi_port = io_port % 3; 39 - 40 - switch (ppi_port) { 35 + switch (stride) { 41 36 case I8255_PORTA: 42 37 return I8255_CONTROL_PORTA_DIRECTION; 43 38 case I8255_PORTB: 44 39 return I8255_CONTROL_PORTB_DIRECTION; 45 40 case I8255_PORTC: 46 41 /* Port C can be configured by nibble */ 47 - if (port_offset >= 4) 42 + if (line >= 4) 48 43 return I8255_CONTROL_PORTC_UPPER_DIRECTION; 49 44 return I8255_CONTROL_PORTC_LOWER_DIRECTION; 50 45 default: ··· 48 53 } 49 54 } 50 55 51 - static void i8255_set_port(struct i8255 __iomem *const ppi, 52 - struct i8255_state *const state, 53 - const unsigned long io_port, 54 - const unsigned long mask, const unsigned long bits) 56 + static int i8255_ppi_init(struct regmap *const map, const unsigned int base) 55 57 { 56 - const unsigned long bank = io_port / 3; 57 - const unsigned long ppi_port = io_port % 3; 58 - unsigned long flags; 59 - unsigned long out_state; 58 + int err; 60 59 61 - spin_lock_irqsave(&state[bank].lock, flags); 60 + /* Configure all ports to MODE 0 output mode */ 61 + err = regmap_write(map, base + I8255_CONTROL, I8255_CONTROL_MODE_SET); 62 + if (err) 63 + return err; 62 64 63 - out_state = ioread8(&ppi[bank].port[ppi_port]); 64 - out_state = (out_state & ~mask) | (bits & mask); 65 - iowrite8(out_state, &ppi[bank].port[ppi_port]); 66 - 67 - spin_unlock_irqrestore(&state[bank].lock, flags); 65 + /* Initialize all GPIO to output 0 */ 66 + err = regmap_write(map, base + I8255_PORTA, 0x00); 67 + if (err) 68 + return err; 69 + err = regmap_write(map, base + I8255_PORTB, 0x00); 70 + if (err) 71 + return err; 72 + return regmap_write(map, base + I8255_PORTC, 0x00); 68 73 } 69 74 70 - /** 71 - * i8255_direction_input - configure signal offset as input 72 - * @ppi: Intel 8255 Programmable Peripheral Interface banks 73 - * @state: devices states of the respective PPI banks 74 - * @offset: signal offset to configure as input 75 - * 76 - * Configures a signal @offset as input for the respective Intel 8255 77 - * Programmable Peripheral Interface (@ppi) banks. The @state control_state 78 - * values are updated to reflect the new configuration. 79 - */ 80 - void i8255_direction_input(struct i8255 __iomem *const ppi, 81 - struct i8255_state *const state, 82 - const unsigned long offset) 75 + static int i8255_reg_mask_xlate(struct gpio_regmap *gpio, unsigned int base, 76 + unsigned int offset, unsigned int *reg, 77 + unsigned int *mask) 83 78 { 84 - const unsigned long io_port = offset / 8; 85 - const unsigned long bank = io_port / 3; 86 - unsigned long flags; 79 + const unsigned int ppi = offset / I8255_NGPIO; 80 + const unsigned int ppi_offset = offset % I8255_NGPIO; 81 + const unsigned int stride = ppi_offset / I8255_NGPIO_PER_REG; 82 + const unsigned int line = ppi_offset % I8255_NGPIO_PER_REG; 87 83 88 - spin_lock_irqsave(&state[bank].lock, flags); 89 - 90 - state[bank].control_state |= I8255_CONTROL_MODE_SET; 91 - state[bank].control_state |= i8255_direction_mask(offset); 92 - 93 - iowrite8(state[bank].control_state, &ppi[bank].control); 94 - 95 - spin_unlock_irqrestore(&state[bank].lock, flags); 96 - } 97 - EXPORT_SYMBOL_NS_GPL(i8255_direction_input, I8255); 98 - 99 - /** 100 - * i8255_direction_output - configure signal offset as output 101 - * @ppi: Intel 8255 Programmable Peripheral Interface banks 102 - * @state: devices states of the respective PPI banks 103 - * @offset: signal offset to configure as output 104 - * @value: signal value to output 105 - * 106 - * Configures a signal @offset as output for the respective Intel 8255 107 - * Programmable Peripheral Interface (@ppi) banks and sets the respective signal 108 - * output to the desired @value. The @state control_state values are updated to 109 - * reflect the new configuration. 110 - */ 111 - void i8255_direction_output(struct i8255 __iomem *const ppi, 112 - struct i8255_state *const state, 113 - const unsigned long offset, 114 - const unsigned long value) 115 - { 116 - const unsigned long io_port = offset / 8; 117 - const unsigned long bank = io_port / 3; 118 - unsigned long flags; 119 - 120 - spin_lock_irqsave(&state[bank].lock, flags); 121 - 122 - state[bank].control_state |= I8255_CONTROL_MODE_SET; 123 - state[bank].control_state &= ~i8255_direction_mask(offset); 124 - 125 - iowrite8(state[bank].control_state, &ppi[bank].control); 126 - 127 - spin_unlock_irqrestore(&state[bank].lock, flags); 128 - 129 - i8255_set(ppi, state, offset, value); 130 - } 131 - EXPORT_SYMBOL_NS_GPL(i8255_direction_output, I8255); 132 - 133 - /** 134 - * i8255_get - get signal value at signal offset 135 - * @ppi: Intel 8255 Programmable Peripheral Interface banks 136 - * @offset: offset of signal to get 137 - * 138 - * Returns the signal value (0=low, 1=high) for the signal at @offset for the 139 - * respective Intel 8255 Programmable Peripheral Interface (@ppi) banks. 140 - */ 141 - int i8255_get(struct i8255 __iomem *const ppi, const unsigned long offset) 142 - { 143 - const unsigned long io_port = offset / 8; 144 - const unsigned long offset_mask = BIT(offset % 8); 145 - 146 - return !!i8255_get_port(ppi, io_port, offset_mask); 147 - } 148 - EXPORT_SYMBOL_NS_GPL(i8255_get, I8255); 149 - 150 - /** 151 - * i8255_get_direction - get the I/O direction for a signal offset 152 - * @state: devices states of the respective PPI banks 153 - * @offset: offset of signal to get direction 154 - * 155 - * Returns the signal direction (0=output, 1=input) for the signal at @offset. 156 - */ 157 - int i8255_get_direction(const struct i8255_state *const state, 158 - const unsigned long offset) 159 - { 160 - const unsigned long io_port = offset / 8; 161 - const unsigned long bank = io_port / 3; 162 - 163 - return !!(state[bank].control_state & i8255_direction_mask(offset)); 164 - } 165 - EXPORT_SYMBOL_NS_GPL(i8255_get_direction, I8255); 166 - 167 - /** 168 - * i8255_get_multiple - get multiple signal values at multiple signal offsets 169 - * @ppi: Intel 8255 Programmable Peripheral Interface banks 170 - * @mask: mask of signals to get 171 - * @bits: bitmap to store signal values 172 - * @ngpio: number of GPIO signals of the respective PPI banks 173 - * 174 - * Stores in @bits the values (0=low, 1=high) for the signals defined by @mask 175 - * for the respective Intel 8255 Programmable Peripheral Interface (@ppi) banks. 176 - */ 177 - void i8255_get_multiple(struct i8255 __iomem *const ppi, 178 - const unsigned long *const mask, 179 - unsigned long *const bits, const unsigned long ngpio) 180 - { 181 - unsigned long offset; 182 - unsigned long port_mask; 183 - unsigned long io_port; 184 - unsigned long port_state; 185 - 186 - bitmap_zero(bits, ngpio); 187 - 188 - for_each_set_clump8(offset, port_mask, mask, ngpio) { 189 - io_port = offset / 8; 190 - port_state = i8255_get_port(ppi, io_port, port_mask); 191 - 192 - bitmap_set_value8(bits, port_state, offset); 84 + switch (base) { 85 + case I8255_REG_DAT_BASE: 86 + *reg = base + stride + ppi * 4; 87 + *mask = BIT(line); 88 + return 0; 89 + case I8255_REG_DIR_IN_BASE: 90 + *reg = base + ppi * 4; 91 + *mask = i8255_direction_mask(ppi_offset); 92 + return 0; 93 + default: 94 + /* Should never reach this path */ 95 + return -EINVAL; 193 96 } 194 97 } 195 - EXPORT_SYMBOL_NS_GPL(i8255_get_multiple, I8255); 196 98 197 99 /** 198 - * i8255_mode0_output - configure all PPI ports to MODE 0 output mode 199 - * @ppi: Intel 8255 Programmable Peripheral Interface bank 100 + * devm_i8255_regmap_register - Register an i8255 GPIO controller 101 + * @dev: device that is registering this i8255 GPIO device 102 + * @config: configuration for i8255_regmap_config 200 103 * 201 - * Configures all Intel 8255 Programmable Peripheral Interface (@ppi) ports to 202 - * MODE 0 (Basic Input/Output) output mode. 104 + * Registers an Intel 8255 Programmable Peripheral Interface GPIO controller. 105 + * Returns 0 on success and negative error number on failure. 203 106 */ 204 - void i8255_mode0_output(struct i8255 __iomem *const ppi) 107 + int devm_i8255_regmap_register(struct device *const dev, 108 + const struct i8255_regmap_config *const config) 205 109 { 206 - iowrite8(I8255_CONTROL_MODE_SET, &ppi->control); 207 - } 208 - EXPORT_SYMBOL_NS_GPL(i8255_mode0_output, I8255); 110 + struct gpio_regmap_config gpio_config = {0}; 111 + unsigned long i; 112 + int err; 209 113 210 - /** 211 - * i8255_set - set signal value at signal offset 212 - * @ppi: Intel 8255 Programmable Peripheral Interface banks 213 - * @state: devices states of the respective PPI banks 214 - * @offset: offset of signal to set 215 - * @value: value of signal to set 216 - * 217 - * Assigns output @value for the signal at @offset for the respective Intel 8255 218 - * Programmable Peripheral Interface (@ppi) banks. 219 - */ 220 - void i8255_set(struct i8255 __iomem *const ppi, struct i8255_state *const state, 221 - const unsigned long offset, const unsigned long value) 222 - { 223 - const unsigned long io_port = offset / 8; 224 - const unsigned long port_offset = offset % 8; 225 - const unsigned long mask = BIT(port_offset); 226 - const unsigned long bits = value << port_offset; 114 + if (!config->parent) 115 + return -EINVAL; 227 116 228 - i8255_set_port(ppi, state, io_port, mask, bits); 229 - } 230 - EXPORT_SYMBOL_NS_GPL(i8255_set, I8255); 117 + if (!config->map) 118 + return -EINVAL; 231 119 232 - /** 233 - * i8255_set_multiple - set signal values at multiple signal offsets 234 - * @ppi: Intel 8255 Programmable Peripheral Interface banks 235 - * @state: devices states of the respective PPI banks 236 - * @mask: mask of signals to set 237 - * @bits: bitmap of signal output values 238 - * @ngpio: number of GPIO signals of the respective PPI banks 239 - * 240 - * Assigns output values defined by @bits for the signals defined by @mask for 241 - * the respective Intel 8255 Programmable Peripheral Interface (@ppi) banks. 242 - */ 243 - void i8255_set_multiple(struct i8255 __iomem *const ppi, 244 - struct i8255_state *const state, 245 - const unsigned long *const mask, 246 - const unsigned long *const bits, 247 - const unsigned long ngpio) 248 - { 249 - unsigned long offset; 250 - unsigned long port_mask; 251 - unsigned long io_port; 252 - unsigned long value; 120 + if (!config->num_ppi) 121 + return -EINVAL; 253 122 254 - for_each_set_clump8(offset, port_mask, mask, ngpio) { 255 - io_port = offset / 8; 256 - value = bitmap_get_value8(bits, offset); 257 - i8255_set_port(ppi, state, io_port, port_mask, value); 123 + for (i = 0; i < config->num_ppi; i++) { 124 + err = i8255_ppi_init(config->map, i * 4); 125 + if (err) 126 + return err; 258 127 } 259 - } 260 - EXPORT_SYMBOL_NS_GPL(i8255_set_multiple, I8255); 261 128 262 - /** 263 - * i8255_state_init - initialize i8255_state structure 264 - * @state: devices states of the respective PPI banks 265 - * @nbanks: number of Intel 8255 Programmable Peripheral Interface banks 266 - * 267 - * Initializes the @state of each Intel 8255 Programmable Peripheral Interface 268 - * bank for use in i8255 library functions. 269 - */ 270 - void i8255_state_init(struct i8255_state *const state, 271 - const unsigned long nbanks) 272 - { 273 - unsigned long bank; 129 + gpio_config.parent = config->parent; 130 + gpio_config.regmap = config->map; 131 + gpio_config.ngpio = I8255_NGPIO * config->num_ppi; 132 + gpio_config.names = config->names; 133 + gpio_config.reg_dat_base = GPIO_REGMAP_ADDR(I8255_REG_DAT_BASE); 134 + gpio_config.reg_set_base = GPIO_REGMAP_ADDR(I8255_REG_DAT_BASE); 135 + gpio_config.reg_dir_in_base = GPIO_REGMAP_ADDR(I8255_REG_DIR_IN_BASE); 136 + gpio_config.ngpio_per_reg = I8255_NGPIO_PER_REG; 137 + gpio_config.irq_domain = config->domain; 138 + gpio_config.reg_mask_xlate = i8255_reg_mask_xlate; 274 139 275 - for (bank = 0; bank < nbanks; bank++) 276 - spin_lock_init(&state[bank].lock); 140 + return PTR_ERR_OR_ZERO(devm_gpio_regmap_register(dev, &gpio_config)); 277 141 } 278 - EXPORT_SYMBOL_NS_GPL(i8255_state_init, I8255); 142 + EXPORT_SYMBOL_NS_GPL(devm_i8255_regmap_register, I8255); 279 143 280 144 MODULE_AUTHOR("William Breathitt Gray"); 281 145 MODULE_DESCRIPTION("Intel 8255 Programmable Peripheral Interface");
+22 -34
drivers/gpio/gpio-i8255.h
··· 3 3 #ifndef _I8255_H_ 4 4 #define _I8255_H_ 5 5 6 - #include <linux/spinlock.h> 7 - #include <linux/types.h> 6 + struct device; 7 + struct irq_domain; 8 + struct regmap; 9 + 10 + #define i8255_volatile_regmap_range(_base) regmap_reg_range(_base, _base + 0x2) 8 11 9 12 /** 10 - * struct i8255 - Intel 8255 register structure 11 - * @port: Port A, B, and C 12 - * @control: Control register 13 + * struct i8255_regmap_config - Configuration for the register map of an i8255 14 + * @parent: parent device 15 + * @map: regmap for the i8255 16 + * @num_ppi: number of i8255 Programmable Peripheral Interface 17 + * @names: (optional) array of names for gpios 18 + * @domain: (optional) IRQ domain if the controller is interrupt-capable 19 + * 20 + * Note: The regmap is expected to have cache enabled and i8255 control 21 + * registers not marked as volatile. 13 22 */ 14 - struct i8255 { 15 - u8 port[3]; 16 - u8 control; 23 + struct i8255_regmap_config { 24 + struct device *parent; 25 + struct regmap *map; 26 + int num_ppi; 27 + const char *const *names; 28 + struct irq_domain *domain; 17 29 }; 18 30 19 - /** 20 - * struct i8255_state - Intel 8255 state structure 21 - * @lock: synchronization lock for accessing device state 22 - * @control_state: Control register state 23 - */ 24 - struct i8255_state { 25 - spinlock_t lock; 26 - u8 control_state; 27 - }; 28 - 29 - void i8255_direction_input(struct i8255 __iomem *ppi, struct i8255_state *state, 30 - unsigned long offset); 31 - void i8255_direction_output(struct i8255 __iomem *ppi, 32 - struct i8255_state *state, unsigned long offset, 33 - unsigned long value); 34 - int i8255_get(struct i8255 __iomem *ppi, unsigned long offset); 35 - int i8255_get_direction(const struct i8255_state *state, unsigned long offset); 36 - void i8255_get_multiple(struct i8255 __iomem *ppi, const unsigned long *mask, 37 - unsigned long *bits, unsigned long ngpio); 38 - void i8255_mode0_output(struct i8255 __iomem *const ppi); 39 - void i8255_set(struct i8255 __iomem *ppi, struct i8255_state *state, 40 - unsigned long offset, unsigned long value); 41 - void i8255_set_multiple(struct i8255 __iomem *ppi, struct i8255_state *state, 42 - const unsigned long *mask, const unsigned long *bits, 43 - unsigned long ngpio); 44 - void i8255_state_init(struct i8255_state *const state, unsigned long nbanks); 31 + int devm_i8255_regmap_register(struct device *dev, 32 + const struct i8255_regmap_config *config); 45 33 46 34 #endif /* _I8255_H_ */
-6
drivers/gpio/gpio-msc313.c
··· 655 655 return devm_gpiochip_add_data(dev, gpiochip, gpio); 656 656 } 657 657 658 - static int msc313_gpio_remove(struct platform_device *pdev) 659 - { 660 - return 0; 661 - } 662 - 663 658 static const struct of_device_id msc313_gpio_of_match[] = { 664 659 #ifdef CONFIG_MACH_INFINITY 665 660 { ··· 705 710 .pm = &msc313_gpio_ops, 706 711 }, 707 712 .probe = msc313_gpio_probe, 708 - .remove = msc313_gpio_remove, 709 713 }; 710 714 builtin_platform_driver(msc313_gpio_driver);
+3 -3
drivers/gpio/gpio-mvebu.c
··· 1002 1002 BUG(); 1003 1003 } 1004 1004 1005 - if (IS_ENABLED(CONFIG_PWM)) 1005 + if (IS_REACHABLE(CONFIG_PWM)) 1006 1006 mvebu_pwm_suspend(mvchip); 1007 1007 1008 1008 return 0; ··· 1054 1054 BUG(); 1055 1055 } 1056 1056 1057 - if (IS_ENABLED(CONFIG_PWM)) 1057 + if (IS_REACHABLE(CONFIG_PWM)) 1058 1058 mvebu_pwm_resume(mvchip); 1059 1059 1060 1060 return 0; ··· 1228 1228 devm_gpiochip_add_data(&pdev->dev, &mvchip->chip, mvchip); 1229 1229 1230 1230 /* Some MVEBU SoCs have simple PWM support for GPIO lines */ 1231 - if (IS_ENABLED(CONFIG_PWM)) { 1231 + if (IS_REACHABLE(CONFIG_PWM)) { 1232 1232 err = mvebu_pwm_probe(pdev, mvchip, id); 1233 1233 if (err) 1234 1234 return err;
+1 -1
drivers/gpio/gpio-omap.c
··· 1020 1020 if (!label) 1021 1021 return -ENOMEM; 1022 1022 bank->chip.label = label; 1023 - bank->chip.base = gpio; 1023 + bank->chip.base = -1; 1024 1024 } 1025 1025 bank->chip.ngpio = bank->width; 1026 1026
+15 -19
drivers/gpio/gpio-pca953x.c
··· 306 306 static bool pcal6534_check_register(struct pca953x_chip *chip, unsigned int reg, 307 307 u32 checkbank) 308 308 { 309 + int bank_shift; 309 310 int bank; 310 311 int offset; 311 312 312 - if (reg >= 0x30) { 313 - /* 314 - * Reserved block between 14h and 2Fh does not align on 315 - * expected bank boundaries like other devices. 316 - */ 317 - int temp = reg - 0x30; 318 - 319 - bank = temp / NBANK(chip); 320 - offset = temp - (bank * NBANK(chip)); 321 - bank += 8; 322 - } else if (reg >= 0x54) { 313 + if (reg >= 0x54) { 323 314 /* 324 315 * Handle lack of reserved registers after output port 325 316 * configuration register to form a bank. 326 317 */ 327 - int temp = reg - 0x54; 328 - 329 - bank = temp / NBANK(chip); 330 - offset = temp - (bank * NBANK(chip)); 331 - bank += 16; 318 + reg -= 0x54; 319 + bank_shift = 16; 320 + } else if (reg >= 0x30) { 321 + /* 322 + * Reserved block between 14h and 2Fh does not align on 323 + * expected bank boundaries like other devices. 324 + */ 325 + reg -= 0x30; 326 + bank_shift = 8; 332 327 } else { 333 - bank = reg / NBANK(chip); 334 - offset = reg - (bank * NBANK(chip)); 328 + bank_shift = 0; 335 329 } 330 + 331 + bank = bank_shift + reg / NBANK(chip); 332 + offset = reg % NBANK(chip); 336 333 337 334 /* Register is not in the matching bank. */ 338 335 if (!(BIT(bank) & checkbank)) ··· 461 464 case PCAL953X_PULL_SEL: 462 465 case PCAL953X_INT_MASK: 463 466 case PCAL953X_INT_STAT: 464 - case PCAL953X_OUT_CONF: 465 467 pinctrl = ((reg & PCAL_PINCTRL_MASK) >> 1) + 0x20; 466 468 break; 467 469 case PCAL6524_INT_EDGE:
+12 -12
drivers/gpio/gpio-pca9570.c
··· 18 18 #define SLG7XL45106_GPO_REG 0xDB 19 19 20 20 /** 21 - * struct pca9570_platform_data - GPIO platformdata 21 + * struct pca9570_chip_data - GPIO platformdata 22 22 * @ngpio: no of gpios 23 23 * @command: Command to be sent 24 24 */ 25 - struct pca9570_platform_data { 25 + struct pca9570_chip_data { 26 26 u16 ngpio; 27 27 u32 command; 28 28 }; ··· 36 36 */ 37 37 struct pca9570 { 38 38 struct gpio_chip chip; 39 - const struct pca9570_platform_data *p_data; 39 + const struct pca9570_chip_data *chip_data; 40 40 struct mutex lock; 41 41 u8 out; 42 42 }; ··· 46 46 struct i2c_client *client = to_i2c_client(gpio->chip.parent); 47 47 int ret; 48 48 49 - if (gpio->p_data->command != 0) 50 - ret = i2c_smbus_read_byte_data(client, gpio->p_data->command); 49 + if (gpio->chip_data->command != 0) 50 + ret = i2c_smbus_read_byte_data(client, gpio->chip_data->command); 51 51 else 52 52 ret = i2c_smbus_read_byte(client); 53 53 ··· 62 62 { 63 63 struct i2c_client *client = to_i2c_client(gpio->chip.parent); 64 64 65 - if (gpio->p_data->command != 0) 66 - return i2c_smbus_write_byte_data(client, gpio->p_data->command, value); 65 + if (gpio->chip_data->command != 0) 66 + return i2c_smbus_write_byte_data(client, gpio->chip_data->command, value); 67 67 68 68 return i2c_smbus_write_byte(client, value); 69 69 } ··· 127 127 gpio->chip.get = pca9570_get; 128 128 gpio->chip.set = pca9570_set; 129 129 gpio->chip.base = -1; 130 - gpio->p_data = device_get_match_data(&client->dev); 131 - gpio->chip.ngpio = gpio->p_data->ngpio; 130 + gpio->chip_data = device_get_match_data(&client->dev); 131 + gpio->chip.ngpio = gpio->chip_data->ngpio; 132 132 gpio->chip.can_sleep = true; 133 133 134 134 mutex_init(&gpio->lock); ··· 141 141 return devm_gpiochip_add_data(&client->dev, &gpio->chip, gpio); 142 142 } 143 143 144 - static const struct pca9570_platform_data pca9570_gpio = { 144 + static const struct pca9570_chip_data pca9570_gpio = { 145 145 .ngpio = 4, 146 146 }; 147 147 148 - static const struct pca9570_platform_data pca9571_gpio = { 148 + static const struct pca9570_chip_data pca9571_gpio = { 149 149 .ngpio = 8, 150 150 }; 151 151 152 - static const struct pca9570_platform_data slg7xl45106_gpio = { 152 + static const struct pca9570_chip_data slg7xl45106_gpio = { 153 153 .ngpio = 8, 154 154 .command = SLG7XL45106_GPO_REG, 155 155 };
+56 -60
drivers/gpio/gpio-pcf857x.c
··· 7 7 8 8 #include <linux/gpio/driver.h> 9 9 #include <linux/i2c.h> 10 - #include <linux/platform_data/pcf857x.h> 11 10 #include <linux/interrupt.h> 12 11 #include <linux/irq.h> 13 12 #include <linux/irqdomain.h> 14 13 #include <linux/kernel.h> 14 + #include <linux/mod_devicetable.h> 15 15 #include <linux/module.h> 16 - #include <linux/of.h> 17 - #include <linux/of_device.h> 16 + #include <linux/property.h> 18 17 #include <linux/slab.h> 19 18 #include <linux/spinlock.h> 20 - 21 19 22 20 static const struct i2c_device_id pcf857x_id[] = { 23 21 { "pcf8574", 8 }, ··· 35 37 }; 36 38 MODULE_DEVICE_TABLE(i2c, pcf857x_id); 37 39 38 - #ifdef CONFIG_OF 39 40 static const struct of_device_id pcf857x_of_table[] = { 40 41 { .compatible = "nxp,pcf8574" }, 41 42 { .compatible = "nxp,pcf8574a" }, ··· 52 55 { } 53 56 }; 54 57 MODULE_DEVICE_TABLE(of, pcf857x_of_table); 55 - #endif 56 58 57 59 /* 58 60 * The pcf857x, pca857x, and pca967x chips only expose one read and one ··· 69 73 struct gpio_chip chip; 70 74 struct i2c_client *client; 71 75 struct mutex lock; /* protect 'out' */ 72 - unsigned out; /* software latch */ 73 - unsigned status; /* current status */ 74 - unsigned irq_enabled; /* enabled irqs */ 76 + unsigned int out; /* software latch */ 77 + unsigned int status; /* current status */ 78 + unsigned int irq_enabled; /* enabled irqs */ 75 79 76 - int (*write)(struct i2c_client *client, unsigned data); 80 + int (*write)(struct i2c_client *client, unsigned int data); 77 81 int (*read)(struct i2c_client *client); 78 82 }; 79 83 ··· 81 85 82 86 /* Talk to 8-bit I/O expander */ 83 87 84 - static int i2c_write_le8(struct i2c_client *client, unsigned data) 88 + static int i2c_write_le8(struct i2c_client *client, unsigned int data) 85 89 { 86 90 return i2c_smbus_write_byte(client, data); 87 91 } 88 92 89 93 static int i2c_read_le8(struct i2c_client *client) 90 94 { 91 - return (int)i2c_smbus_read_byte(client); 95 + return i2c_smbus_read_byte(client); 92 96 } 93 97 94 98 /* Talk to 16-bit I/O expander */ 95 99 96 - static int i2c_write_le16(struct i2c_client *client, unsigned word) 100 + static int i2c_write_le16(struct i2c_client *client, unsigned int word) 97 101 { 98 102 u8 buf[2] = { word & 0xff, word >> 8, }; 99 103 int status; ··· 115 119 116 120 /*-------------------------------------------------------------------------*/ 117 121 118 - static int pcf857x_input(struct gpio_chip *chip, unsigned offset) 122 + static int pcf857x_input(struct gpio_chip *chip, unsigned int offset) 119 123 { 120 - struct pcf857x *gpio = gpiochip_get_data(chip); 121 - int status; 124 + struct pcf857x *gpio = gpiochip_get_data(chip); 125 + int status; 122 126 123 127 mutex_lock(&gpio->lock); 124 128 gpio->out |= (1 << offset); ··· 128 132 return status; 129 133 } 130 134 131 - static int pcf857x_get(struct gpio_chip *chip, unsigned offset) 135 + static int pcf857x_get(struct gpio_chip *chip, unsigned int offset) 132 136 { 133 - struct pcf857x *gpio = gpiochip_get_data(chip); 134 - int value; 137 + struct pcf857x *gpio = gpiochip_get_data(chip); 138 + int value; 135 139 136 140 value = gpio->read(gpio->client); 137 141 return (value < 0) ? value : !!(value & (1 << offset)); 138 142 } 139 143 140 - static int pcf857x_output(struct gpio_chip *chip, unsigned offset, int value) 144 + static int pcf857x_get_multiple(struct gpio_chip *chip, unsigned long *mask, 145 + unsigned long *bits) 141 146 { 142 - struct pcf857x *gpio = gpiochip_get_data(chip); 143 - unsigned bit = 1 << offset; 144 - int status; 147 + struct pcf857x *gpio = gpiochip_get_data(chip); 148 + int value = gpio->read(gpio->client); 149 + 150 + if (value < 0) 151 + return value; 152 + 153 + *bits &= ~*mask; 154 + *bits |= value & *mask; 155 + 156 + return 0; 157 + } 158 + 159 + static int pcf857x_output(struct gpio_chip *chip, unsigned int offset, int value) 160 + { 161 + struct pcf857x *gpio = gpiochip_get_data(chip); 162 + unsigned int bit = 1 << offset; 163 + int status; 145 164 146 165 mutex_lock(&gpio->lock); 147 166 if (value) ··· 169 158 return status; 170 159 } 171 160 172 - static void pcf857x_set(struct gpio_chip *chip, unsigned offset, int value) 161 + static void pcf857x_set(struct gpio_chip *chip, unsigned int offset, int value) 173 162 { 174 163 pcf857x_output(chip, offset, value); 164 + } 165 + 166 + static void pcf857x_set_multiple(struct gpio_chip *chip, unsigned long *mask, 167 + unsigned long *bits) 168 + { 169 + struct pcf857x *gpio = gpiochip_get_data(chip); 170 + 171 + mutex_lock(&gpio->lock); 172 + gpio->out &= ~*mask; 173 + gpio->out |= *bits & *mask; 174 + gpio->write(gpio->client, gpio->out); 175 + mutex_unlock(&gpio->lock); 175 176 } 176 177 177 178 /*-------------------------------------------------------------------------*/ 178 179 179 180 static irqreturn_t pcf857x_irq(int irq, void *data) 180 181 { 181 - struct pcf857x *gpio = data; 182 + struct pcf857x *gpio = data; 182 183 unsigned long change, i, status; 183 184 184 185 status = gpio->read(gpio->client); ··· 273 250 static int pcf857x_probe(struct i2c_client *client) 274 251 { 275 252 const struct i2c_device_id *id = i2c_client_get_device_id(client); 276 - struct pcf857x_platform_data *pdata = dev_get_platdata(&client->dev); 277 - struct device_node *np = client->dev.of_node; 278 - struct pcf857x *gpio; 279 - unsigned int n_latch = 0; 280 - int status; 253 + struct pcf857x *gpio; 254 + unsigned int n_latch = 0; 255 + int status; 281 256 282 - if (IS_ENABLED(CONFIG_OF) && np) 283 - of_property_read_u32(np, "lines-initial-states", &n_latch); 284 - else if (pdata) 285 - n_latch = pdata->n_latch; 286 - else 287 - dev_dbg(&client->dev, "no platform data\n"); 257 + device_property_read_u32(&client->dev, "lines-initial-states", &n_latch); 288 258 289 259 /* Allocate, initialize, and register this gpio_chip. */ 290 260 gpio = devm_kzalloc(&client->dev, sizeof(*gpio), GFP_KERNEL); ··· 286 270 287 271 mutex_init(&gpio->lock); 288 272 289 - gpio->chip.base = pdata ? pdata->gpio_base : -1; 273 + gpio->chip.base = -1; 290 274 gpio->chip.can_sleep = true; 291 275 gpio->chip.parent = &client->dev; 292 276 gpio->chip.owner = THIS_MODULE; 293 277 gpio->chip.get = pcf857x_get; 278 + gpio->chip.get_multiple = pcf857x_get_multiple; 294 279 gpio->chip.set = pcf857x_set; 280 + gpio->chip.set_multiple = pcf857x_set_multiple; 295 281 gpio->chip.direction_input = pcf857x_input; 296 282 gpio->chip.direction_output = pcf857x_output; 297 283 gpio->chip.ngpio = id->driver_data; ··· 395 377 if (status < 0) 396 378 goto fail; 397 379 398 - /* Let platform code set up the GPIOs and their users. 399 - * Now is the first time anyone could use them. 400 - */ 401 - if (pdata && pdata->setup) { 402 - status = pdata->setup(client, 403 - gpio->chip.base, gpio->chip.ngpio, 404 - pdata->context); 405 - if (status < 0) 406 - dev_warn(&client->dev, "setup --> %d\n", status); 407 - } 408 - 409 380 dev_info(&client->dev, "probed\n"); 410 381 411 382 return 0; ··· 404 397 client->name); 405 398 406 399 return status; 407 - } 408 - 409 - static void pcf857x_remove(struct i2c_client *client) 410 - { 411 - struct pcf857x_platform_data *pdata = dev_get_platdata(&client->dev); 412 - struct pcf857x *gpio = i2c_get_clientdata(client); 413 - 414 - if (pdata && pdata->teardown) 415 - pdata->teardown(client, gpio->chip.base, gpio->chip.ngpio, 416 - pdata->context); 417 400 } 418 401 419 402 static void pcf857x_shutdown(struct i2c_client *client) ··· 417 420 static struct i2c_driver pcf857x_driver = { 418 421 .driver = { 419 422 .name = "pcf857x", 420 - .of_match_table = of_match_ptr(pcf857x_of_table), 423 + .of_match_table = pcf857x_of_table, 421 424 }, 422 425 .probe_new = pcf857x_probe, 423 - .remove = pcf857x_remove, 424 426 .shutdown = pcf857x_shutdown, 425 427 .id_table = pcf857x_id, 426 428 };
+7 -10
drivers/gpio/gpio-regmap.c
··· 111 111 unsigned int base, val, reg, mask; 112 112 int invert, ret; 113 113 114 + if (gpio->reg_dat_base && !gpio->reg_set_base) 115 + return GPIO_LINE_DIRECTION_IN; 116 + if (gpio->reg_set_base && !gpio->reg_dat_base) 117 + return GPIO_LINE_DIRECTION_OUT; 118 + 114 119 if (gpio->reg_dir_out_base) { 115 120 base = gpio_regmap_addr(gpio->reg_dir_out_base); 116 121 invert = 0; ··· 254 249 chip->ngpio = config->ngpio; 255 250 chip->names = config->names; 256 251 chip->label = config->label ?: dev_name(config->parent); 257 - 258 - /* 259 - * If our regmap is fast_io we should probably set can_sleep to false. 260 - * Right now, the regmap doesn't save this property, nor is there any 261 - * access function for it. 262 - * The only regmap type which uses fast_io is regmap-mmio. For now, 263 - * assume a safe default of true here. 264 - */ 265 - chip->can_sleep = true; 252 + chip->can_sleep = regmap_might_sleep(config->regmap); 266 253 267 254 chip->get = gpio_regmap_get; 268 255 if (gpio->reg_set_base && gpio->reg_clr_base) ··· 262 265 else if (gpio->reg_set_base) 263 266 chip->set = gpio_regmap_set; 264 267 268 + chip->get_direction = gpio_regmap_get_direction; 265 269 if (gpio->reg_dir_in_base || gpio->reg_dir_out_base) { 266 - chip->get_direction = gpio_regmap_get_direction; 267 270 chip->direction_input = gpio_regmap_direction_input; 268 271 chip->direction_output = gpio_regmap_direction_output; 269 272 }
+1 -1
drivers/gpio/gpio-rockchip.c
··· 299 299 } 300 300 301 301 /* 302 - * gpiolib gpio_to_irq callback function. Creates a mapping between a GPIO pin 302 + * gpiod_to_irq() callback function. Creates a mapping between a GPIO pin 303 303 * and a virtual IRQ, if not already present. 304 304 */ 305 305 static int rockchip_gpio_to_irq(struct gpio_chip *gc, unsigned int offset)
+4 -5
drivers/gpio/gpio-sim.c
··· 377 377 378 378 ret = fwnode_property_read_string(swnode, "gpio-sim,label", &label); 379 379 if (ret) { 380 - label = devm_kasprintf(dev, GFP_KERNEL, "%s-%s", 381 - dev_name(dev), fwnode_get_name(swnode)); 380 + label = devm_kasprintf(dev, GFP_KERNEL, "%s-%pfwP", 381 + dev_name(dev), swnode); 382 382 if (!label) 383 383 return -ENOMEM; 384 384 } ··· 784 784 GFP_KERNEL); 785 785 else 786 786 hog->chip_label = kasprintf(GFP_KERNEL, 787 - "gpio-sim.%u-%s", 787 + "gpio-sim.%u-%pfwP", 788 788 dev->id, 789 - fwnode_get_name( 790 - bank->swnode)); 789 + bank->swnode); 791 790 if (!hog->chip_label) { 792 791 gpio_sim_remove_hogs(dev); 793 792 return -ENOMEM;
+17 -20
drivers/gpio/gpio-tegra186.c
··· 670 670 static const struct of_device_id tegra186_pmc_of_match[] = { 671 671 { .compatible = "nvidia,tegra186-pmc" }, 672 672 { .compatible = "nvidia,tegra194-pmc" }, 673 + { .compatible = "nvidia,tegra234-pmc" }, 673 674 { /* sentinel */ } 674 675 }; 675 676 676 677 static void tegra186_gpio_init_route_mapping(struct tegra_gpio *gpio) 677 678 { 678 679 struct device *dev = gpio->gpio.parent; 679 - unsigned int i, j; 680 + unsigned int i; 680 681 u32 value; 681 682 682 683 for (i = 0; i < gpio->soc->num_ports; i++) { ··· 699 698 * On Tegra194 and later, each pin can be routed to one or more 700 699 * interrupts. 701 700 */ 702 - for (j = 0; j < gpio->num_irqs_per_bank; j++) { 703 - dev_dbg(dev, "programming default interrupt routing for port %s\n", 704 - port->name); 701 + dev_dbg(dev, "programming default interrupt routing for port %s\n", 702 + port->name); 705 703 706 - offset = TEGRA186_GPIO_INT_ROUTE_MAPPING(p, j); 704 + offset = TEGRA186_GPIO_INT_ROUTE_MAPPING(p, 0); 707 705 708 - /* 709 - * By default we only want to route GPIO pins to IRQ 0. This works 710 - * only under the assumption that we're running as the host kernel 711 - * and hence all GPIO pins are owned by Linux. 712 - * 713 - * For cases where Linux is the guest OS, the hypervisor will have 714 - * to configure the interrupt routing and pass only the valid 715 - * interrupts via device tree. 716 - */ 717 - if (j == 0) { 718 - value = readl(base + offset); 719 - value = BIT(port->pins) - 1; 720 - writel(value, base + offset); 721 - } 722 - } 706 + /* 707 + * By default we only want to route GPIO pins to IRQ 0. This works 708 + * only under the assumption that we're running as the host kernel 709 + * and hence all GPIO pins are owned by Linux. 710 + * 711 + * For cases where Linux is the guest OS, the hypervisor will have 712 + * to configure the interrupt routing and pass only the valid 713 + * interrupts via device tree. 714 + */ 715 + value = readl(base + offset); 716 + value = BIT(port->pins) - 1; 717 + writel(value, base + offset); 723 718 } 724 719 } 725 720 }
+1 -1
drivers/gpio/gpio-vf610.c
··· 317 317 318 318 gc = &port->gc; 319 319 gc->parent = dev; 320 - gc->label = "vf610-gpio"; 320 + gc->label = dev_name(dev); 321 321 gc->ngpio = VF610_GPIO_PER_PORT; 322 322 gc->base = of_alias_get_id(np, "gpio") * VF610_GPIO_PER_PORT; 323 323
-1
drivers/gpio/gpio-wcd934x.c
··· 98 98 chip->base = -1; 99 99 chip->ngpio = WCD934X_NPINS; 100 100 chip->label = dev_name(dev); 101 - chip->of_gpio_n_cells = 2; 102 101 chip->can_sleep = false; 103 102 104 103 return devm_gpiochip_add_data(dev, chip, data);
-11
drivers/gpio/gpio-xilinx.c
··· 558 558 int status = 0; 559 559 struct device_node *np = pdev->dev.of_node; 560 560 u32 is_dual = 0; 561 - u32 cells = 2; 562 561 u32 width[2]; 563 562 u32 state[2]; 564 563 u32 dir[2]; ··· 590 591 591 592 bitmap_from_arr32(chip->dir, dir, 64); 592 593 593 - /* Update cells with gpio-cells value */ 594 - if (of_property_read_u32(np, "#gpio-cells", &cells)) 595 - dev_dbg(&pdev->dev, "Missing gpio-cells property\n"); 596 - 597 - if (cells != 2) { 598 - dev_err(&pdev->dev, "#gpio-cells mismatch\n"); 599 - return -EINVAL; 600 - } 601 - 602 594 /* 603 595 * Check device node and parent device node for device width 604 596 * and assume default width of 32 ··· 620 630 chip->gc.parent = &pdev->dev; 621 631 chip->gc.direction_input = xgpio_dir_in; 622 632 chip->gc.direction_output = xgpio_dir_out; 623 - chip->gc.of_gpio_n_cells = cells; 624 633 chip->gc.get = xgpio_get; 625 634 chip->gc.set = xgpio_set; 626 635 chip->gc.request = xgpio_request;
+5 -4
drivers/gpio/gpio-zevio.c
··· 5 5 * Author: Fabian Vogt <fabian@ritter-vogt.de> 6 6 */ 7 7 8 - #include <linux/spinlock.h> 8 + #include <linux/bitops.h> 9 9 #include <linux/errno.h> 10 10 #include <linux/init.h> 11 - #include <linux/bitops.h> 12 11 #include <linux/io.h> 13 - #include <linux/of_device.h> 12 + #include <linux/mod_devicetable.h> 13 + #include <linux/platform_device.h> 14 14 #include <linux/slab.h> 15 + #include <linux/spinlock.h> 16 + 15 17 #include <linux/gpio/driver.h> 16 18 17 19 /* ··· 164 162 .base = 0, 165 163 .owner = THIS_MODULE, 166 164 .ngpio = 32, 167 - .of_gpio_n_cells = 2, 168 165 }; 169 166 170 167 /* Initialization */
-10
drivers/gpio/gpiolib-acpi.c
··· 1388 1388 kfree(acpi_gpio); 1389 1389 } 1390 1390 1391 - void acpi_gpio_dev_init(struct gpio_chip *gc, struct gpio_device *gdev) 1392 - { 1393 - /* Set default fwnode to parent's one if present */ 1394 - if (gc->parent) 1395 - ACPI_COMPANION_SET(&gdev->dev, ACPI_COMPANION(gc->parent)); 1396 - 1397 - if (gc->fwnode) 1398 - device_set_node(&gdev->dev, gc->fwnode); 1399 - } 1400 - 1401 1391 static int acpi_gpio_package_count(const union acpi_object *obj) 1402 1392 { 1403 1393 const union acpi_object *element = obj->package.elements;
-4
drivers/gpio/gpiolib-acpi.h
··· 25 25 void acpi_gpiochip_add(struct gpio_chip *chip); 26 26 void acpi_gpiochip_remove(struct gpio_chip *chip); 27 27 28 - void acpi_gpio_dev_init(struct gpio_chip *gc, struct gpio_device *gdev); 29 - 30 28 void acpi_gpiochip_request_interrupts(struct gpio_chip *chip); 31 29 void acpi_gpiochip_free_interrupts(struct gpio_chip *chip); 32 30 ··· 38 40 #else 39 41 static inline void acpi_gpiochip_add(struct gpio_chip *chip) { } 40 42 static inline void acpi_gpiochip_remove(struct gpio_chip *chip) { } 41 - 42 - static inline void acpi_gpio_dev_init(struct gpio_chip *gc, struct gpio_device *gdev) { } 43 43 44 44 static inline void 45 45 acpi_gpiochip_request_interrupts(struct gpio_chip *chip) { }
+9 -12
drivers/gpio/gpiolib-cdev.c
··· 321 321 if (lh->descs[i]) 322 322 gpiod_free(lh->descs[i]); 323 323 kfree(lh->label); 324 - put_device(&lh->gdev->dev); 324 + gpio_device_put(lh->gdev); 325 325 kfree(lh); 326 326 } 327 327 ··· 363 363 lh = kzalloc(sizeof(*lh), GFP_KERNEL); 364 364 if (!lh) 365 365 return -ENOMEM; 366 - lh->gdev = gdev; 367 - get_device(&gdev->dev); 366 + lh->gdev = gpio_device_get(gdev); 368 367 369 368 if (handlereq.consumer_label[0] != '\0') { 370 369 /* label is only initialized if consumer_label is set */ ··· 1575 1576 } 1576 1577 kfifo_free(&lr->events); 1577 1578 kfree(lr->label); 1578 - put_device(&lr->gdev->dev); 1579 + gpio_device_put(lr->gdev); 1579 1580 kfree(lr); 1580 1581 } 1581 1582 ··· 1645 1646 if (!lr) 1646 1647 return -ENOMEM; 1647 1648 1648 - lr->gdev = gdev; 1649 - get_device(&gdev->dev); 1649 + lr->gdev = gpio_device_get(gdev); 1650 1650 1651 1651 for (i = 0; i < ulr.num_lines; i++) { 1652 1652 lr->lines[i].req = lr; ··· 1914 1916 if (le->desc) 1915 1917 gpiod_free(le->desc); 1916 1918 kfree(le->label); 1917 - put_device(&le->gdev->dev); 1919 + gpio_device_put(le->gdev); 1918 1920 kfree(le); 1919 1921 } 1920 1922 ··· 2092 2094 le = kzalloc(sizeof(*le), GFP_KERNEL); 2093 2095 if (!le) 2094 2096 return -ENOMEM; 2095 - le->gdev = gdev; 2096 - get_device(&gdev->dev); 2097 + le->gdev = gpio_device_get(gdev); 2097 2098 2098 2099 if (eventreq.consumer_label[0] != '\0') { 2099 2100 /* label is only initialized if consumer_label is set */ ··· 2668 2671 2669 2672 init_waitqueue_head(&cdev->wait); 2670 2673 INIT_KFIFO(cdev->events); 2671 - cdev->gdev = gdev; 2674 + cdev->gdev = gpio_device_get(gdev); 2672 2675 2673 2676 cdev->lineinfo_changed_nb.notifier_call = lineinfo_changed_notify; 2674 2677 ret = blocking_notifier_chain_register(&gdev->notifier, ··· 2676 2679 if (ret) 2677 2680 goto out_free_bitmap; 2678 2681 2679 - get_device(&gdev->dev); 2680 2682 file->private_data = cdev; 2681 2683 2682 2684 ret = nonseekable_open(inode, file); ··· 2690 2694 blocking_notifier_chain_unregister(&gdev->notifier, 2691 2695 &cdev->lineinfo_changed_nb); 2692 2696 out_free_bitmap: 2697 + gpio_device_put(gdev); 2693 2698 bitmap_free(cdev->watched_lines); 2694 2699 out_free_cdev: 2695 2700 kfree(cdev); ··· 2713 2716 bitmap_free(cdev->watched_lines); 2714 2717 blocking_notifier_chain_unregister(&gdev->notifier, 2715 2718 &cdev->lineinfo_changed_nb); 2716 - put_device(&gdev->dev); 2719 + gpio_device_put(gdev); 2717 2720 kfree(cdev); 2718 2721 2719 2722 return 0;
-55
drivers/gpio/gpiolib-devres.c
··· 130 130 EXPORT_SYMBOL_GPL(devm_gpiod_get_index); 131 131 132 132 /** 133 - * devm_gpiod_get_from_of_node() - obtain a GPIO from an OF node 134 - * @dev: device for lifecycle management 135 - * @node: handle of the OF node 136 - * @propname: name of the DT property representing the GPIO 137 - * @index: index of the GPIO to obtain for the consumer 138 - * @dflags: GPIO initialization flags 139 - * @label: label to attach to the requested GPIO 140 - * 141 - * Returns: 142 - * On successful request the GPIO pin is configured in accordance with 143 - * provided @dflags. 144 - * 145 - * In case of error an ERR_PTR() is returned. 146 - */ 147 - struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev, 148 - const struct device_node *node, 149 - const char *propname, int index, 150 - enum gpiod_flags dflags, 151 - const char *label) 152 - { 153 - struct gpio_desc **dr; 154 - struct gpio_desc *desc; 155 - 156 - desc = gpiod_get_from_of_node(node, propname, index, dflags, label); 157 - if (IS_ERR(desc)) 158 - return desc; 159 - 160 - /* 161 - * For non-exclusive GPIO descriptors, check if this descriptor is 162 - * already under resource management by this device. 163 - */ 164 - if (dflags & GPIOD_FLAGS_BIT_NONEXCLUSIVE) { 165 - struct devres *dres; 166 - 167 - dres = devres_find(dev, devm_gpiod_release, 168 - devm_gpiod_match, &desc); 169 - if (dres) 170 - return desc; 171 - } 172 - 173 - dr = devres_alloc(devm_gpiod_release, sizeof(struct gpio_desc *), 174 - GFP_KERNEL); 175 - if (!dr) { 176 - gpiod_put(desc); 177 - return ERR_PTR(-ENOMEM); 178 - } 179 - 180 - *dr = desc; 181 - devres_add(dev, dr); 182 - 183 - return desc; 184 - } 185 - EXPORT_SYMBOL_GPL(devm_gpiod_get_from_of_node); 186 - 187 - /** 188 133 * devm_fwnode_gpiod_get_index - get a GPIO descriptor from a given node 189 134 * @dev: GPIO consumer 190 135 * @fwnode: firmware node containing GPIO reference
+59 -76
drivers/gpio/gpiolib-of.c
··· 23 23 #include "gpiolib.h" 24 24 #include "gpiolib-of.h" 25 25 26 + /* 27 + * This is Linux-specific flags. By default controllers' and Linux' mapping 28 + * match, but GPIO controllers are free to translate their own flags to 29 + * Linux-specific in their .xlate callback. Though, 1:1 mapping is recommended. 30 + */ 31 + enum of_gpio_flags { 32 + OF_GPIO_ACTIVE_LOW = 0x1, 33 + OF_GPIO_SINGLE_ENDED = 0x2, 34 + OF_GPIO_OPEN_DRAIN = 0x4, 35 + OF_GPIO_TRANSITORY = 0x8, 36 + OF_GPIO_PULL_UP = 0x10, 37 + OF_GPIO_PULL_DOWN = 0x20, 38 + OF_GPIO_PULL_DISABLE = 0x40, 39 + }; 40 + 41 + /** 42 + * of_gpio_named_count() - Count GPIOs for a device 43 + * @np: device node to count GPIOs for 44 + * @propname: property name containing gpio specifier(s) 45 + * 46 + * The function returns the count of GPIOs specified for a node. 47 + * Note that the empty GPIO specifiers count too. Returns either 48 + * Number of gpios defined in property, 49 + * -EINVAL for an incorrectly formed gpios property, or 50 + * -ENOENT for a missing gpios property 51 + * 52 + * Example: 53 + * gpios = <0 54 + * &gpio1 1 2 55 + * 0 56 + * &gpio2 3 4>; 57 + * 58 + * The above example defines four GPIOs, two of which are not specified. 59 + * This function will return '4' 60 + */ 61 + static int of_gpio_named_count(const struct device_node *np, 62 + const char *propname) 63 + { 64 + return of_count_phandle_with_args(np, propname, "#gpio-cells"); 65 + } 66 + 26 67 /** 27 68 * of_gpio_spi_cs_get_count() - special GPIO counting for SPI 28 69 * @dev: Consuming device ··· 91 50 return of_gpio_named_count(np, "gpios"); 92 51 } 93 52 94 - /* 95 - * This is used by external users of of_gpio_count() from <linux/of_gpio.h> 96 - * 97 - * FIXME: get rid of those external users by converting them to GPIO 98 - * descriptors and let them all use gpiod_count() 99 - */ 100 53 int of_gpio_get_count(struct device *dev, const char *con_id) 101 54 { 102 55 int ret; ··· 380 345 return desc; 381 346 } 382 347 383 - int of_get_named_gpio_flags(const struct device_node *np, const char *list_name, 384 - int index, enum of_gpio_flags *flags) 348 + /** 349 + * of_get_named_gpio() - Get a GPIO number to use with GPIO API 350 + * @np: device node to get GPIO from 351 + * @propname: Name of property containing gpio specifier(s) 352 + * @index: index of the GPIO 353 + * 354 + * Returns GPIO number to use with Linux generic GPIO API, or one of the errno 355 + * value on the error condition. 356 + */ 357 + int of_get_named_gpio(const struct device_node *np, const char *propname, 358 + int index) 385 359 { 386 360 struct gpio_desc *desc; 387 361 388 - desc = of_get_named_gpiod_flags(np, list_name, index, flags); 362 + desc = of_get_named_gpiod_flags(np, propname, index, NULL); 389 363 390 364 if (IS_ERR(desc)) 391 365 return PTR_ERR(desc); 392 366 else 393 367 return desc_to_gpio(desc); 394 368 } 395 - EXPORT_SYMBOL_GPL(of_get_named_gpio_flags); 369 + EXPORT_SYMBOL_GPL(of_get_named_gpio); 396 370 397 371 /* Converts gpio_lookup_flags into bitmask of GPIO_* values */ 398 372 static unsigned long of_convert_gpio_flags(enum of_gpio_flags flags) ··· 432 388 433 389 return lflags; 434 390 } 435 - 436 - /** 437 - * gpiod_get_from_of_node() - obtain a GPIO from an OF node 438 - * @node: handle of the OF node 439 - * @propname: name of the DT property representing the GPIO 440 - * @index: index of the GPIO to obtain for the consumer 441 - * @dflags: GPIO initialization flags 442 - * @label: label to attach to the requested GPIO 443 - * 444 - * Returns: 445 - * On successful request the GPIO pin is configured in accordance with 446 - * provided @dflags. 447 - * 448 - * In case of error an ERR_PTR() is returned. 449 - */ 450 - struct gpio_desc *gpiod_get_from_of_node(const struct device_node *node, 451 - const char *propname, int index, 452 - enum gpiod_flags dflags, 453 - const char *label) 454 - { 455 - unsigned long lflags; 456 - struct gpio_desc *desc; 457 - enum of_gpio_flags of_flags; 458 - int ret; 459 - 460 - desc = of_get_named_gpiod_flags(node, propname, index, &of_flags); 461 - if (!desc || IS_ERR(desc)) 462 - return desc; 463 - 464 - ret = gpiod_request(desc, label); 465 - if (ret == -EBUSY && (dflags & GPIOD_FLAGS_BIT_NONEXCLUSIVE)) 466 - return desc; 467 - if (ret) 468 - return ERR_PTR(ret); 469 - 470 - lflags = of_convert_gpio_flags(of_flags); 471 - 472 - ret = gpiod_configure_flags(desc, propname, lflags, dflags); 473 - if (ret < 0) { 474 - gpiod_put(desc); 475 - return ERR_PTR(ret); 476 - } 477 - 478 - return desc; 479 - } 480 - EXPORT_SYMBOL_GPL(gpiod_get_from_of_node); 481 391 482 392 static struct gpio_desc *of_find_gpio_rename(struct device_node *np, 483 393 const char *con_id, ··· 666 668 u32 tmp; 667 669 int ret; 668 670 669 - chip_np = chip->of_node; 671 + chip_np = dev_of_node(&chip->gpiodev->dev); 670 672 if (!chip_np) 671 673 return ERR_PTR(-EINVAL); 672 674 ··· 758 760 struct device_node *np; 759 761 int ret; 760 762 761 - for_each_available_child_of_node(chip->of_node, np) { 763 + for_each_available_child_of_node(dev_of_node(&chip->gpiodev->dev), np) { 762 764 if (!of_property_read_bool(np, "gpio-hog")) 763 765 continue; 764 766 ··· 968 970 #ifdef CONFIG_PINCTRL 969 971 static int of_gpiochip_add_pin_range(struct gpio_chip *chip) 970 972 { 971 - struct device_node *np = chip->of_node; 972 973 struct of_phandle_args pinspec; 973 974 struct pinctrl_dev *pctldev; 975 + struct device_node *np; 974 976 int index = 0, ret; 975 977 const char *name; 976 978 static const char group_names_propname[] = "gpio-ranges-group-names"; 977 979 struct property *group_names; 978 980 981 + np = dev_of_node(&chip->gpiodev->dev); 979 982 if (!np) 980 983 return 0; 981 984 ··· 1062 1063 struct device_node *np; 1063 1064 int ret; 1064 1065 1065 - np = to_of_node(dev_fwnode(&chip->gpiodev->dev)); 1066 + np = dev_of_node(&chip->gpiodev->dev); 1066 1067 if (!np) 1067 1068 return 0; 1068 1069 ··· 1090 1091 void of_gpiochip_remove(struct gpio_chip *chip) 1091 1092 { 1092 1093 fwnode_handle_put(chip->fwnode); 1093 - } 1094 - 1095 - void of_gpio_dev_init(struct gpio_chip *gc, struct gpio_device *gdev) 1096 - { 1097 - /* Set default OF node to parent's one if present */ 1098 - if (gc->parent) 1099 - gdev->dev.of_node = gc->parent->of_node; 1100 - 1101 - if (gc->fwnode) 1102 - gc->of_node = to_of_node(gc->fwnode); 1103 - 1104 - /* If the gpiochip has an assigned OF node this takes precedence */ 1105 - if (gc->of_node) 1106 - gdev->dev.of_node = gc->of_node; 1107 - else 1108 - gc->of_node = gdev->dev.of_node; 1109 1094 }
-5
drivers/gpio/gpiolib-of.h
··· 23 23 int of_gpiochip_add(struct gpio_chip *gc); 24 24 void of_gpiochip_remove(struct gpio_chip *gc); 25 25 int of_gpio_get_count(struct device *dev, const char *con_id); 26 - void of_gpio_dev_init(struct gpio_chip *gc, struct gpio_device *gdev); 27 26 #else 28 27 static inline struct gpio_desc *of_find_gpio(struct device_node *np, 29 28 const char *con_id, ··· 36 37 static inline int of_gpio_get_count(struct device *dev, const char *con_id) 37 38 { 38 39 return 0; 39 - } 40 - static inline void of_gpio_dev_init(struct gpio_chip *gc, 41 - struct gpio_device *gdev) 42 - { 43 40 } 44 41 #endif /* CONFIG_OF_GPIO */ 45 42
+29 -41
drivers/gpio/gpiolib.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 3 + #include <linux/acpi.h> 3 4 #include <linux/bitmap.h> 4 - #include <linux/kernel.h> 5 - #include <linux/module.h> 6 - #include <linux/interrupt.h> 7 - #include <linux/irq.h> 8 - #include <linux/spinlock.h> 9 - #include <linux/list.h> 5 + #include <linux/compat.h> 6 + #include <linux/debugfs.h> 10 7 #include <linux/device.h> 11 8 #include <linux/err.h> 12 - #include <linux/debugfs.h> 13 - #include <linux/seq_file.h> 9 + #include <linux/file.h> 10 + #include <linux/fs.h> 14 11 #include <linux/gpio.h> 15 - #include <linux/idr.h> 16 - #include <linux/slab.h> 17 - #include <linux/acpi.h> 18 12 #include <linux/gpio/driver.h> 19 13 #include <linux/gpio/machine.h> 14 + #include <linux/idr.h> 15 + #include <linux/interrupt.h> 16 + #include <linux/irq.h> 17 + #include <linux/kernel.h> 18 + #include <linux/list.h> 19 + #include <linux/module.h> 20 20 #include <linux/pinctrl/consumer.h> 21 - #include <linux/fs.h> 22 - #include <linux/compat.h> 23 - #include <linux/file.h> 21 + #include <linux/seq_file.h> 22 + #include <linux/slab.h> 23 + #include <linux/spinlock.h> 24 + 24 25 #include <uapi/linux/gpio.h> 25 26 26 - #include "gpiolib.h" 27 - #include "gpiolib-of.h" 28 27 #include "gpiolib-acpi.h" 29 - #include "gpiolib-swnode.h" 30 28 #include "gpiolib-cdev.h" 29 + #include "gpiolib-of.h" 30 + #include "gpiolib-swnode.h" 31 31 #include "gpiolib-sysfs.h" 32 + #include "gpiolib.h" 32 33 33 34 #define CREATE_TRACE_POINTS 34 35 #include <trace/events/gpio.h> ··· 660 659 int base = 0; 661 660 int ret = 0; 662 661 662 + /* If the calling driver did not initialize firmware node, do it here */ 663 663 if (gc->fwnode) 664 664 fwnode = gc->fwnode; 665 665 else if (gc->parent) 666 666 fwnode = dev_fwnode(gc->parent); 667 + gc->fwnode = fwnode; 667 668 668 669 /* 669 670 * First: allocate and populate the internal stat container, and ··· 679 676 gdev->chip = gc; 680 677 gc->gpiodev = gdev; 681 678 682 - of_gpio_dev_init(gc, gdev); 683 - acpi_gpio_dev_init(gc, gdev); 684 - 685 - /* 686 - * Assign fwnode depending on the result of the previous calls, 687 - * if none of them succeed, assign it to the parent's one. 688 - */ 689 - gc->fwnode = gdev->dev.fwnode = dev_fwnode(&gdev->dev) ?: fwnode; 679 + device_set_node(&gdev->dev, gc->fwnode); 690 680 691 681 gdev->id = ida_alloc(&gpio_ida, GFP_KERNEL); 692 682 if (gdev->id < 0) { ··· 878 882 gpiochip_free_valid_mask(gc); 879 883 if (gdev->dev.release) { 880 884 /* release() has been registered by gpiochip_setup_dev() */ 881 - put_device(&gdev->dev); 885 + gpio_device_put(gdev); 882 886 goto err_print_message; 883 887 } 884 888 err_remove_from_list: ··· 968 972 */ 969 973 gcdev_unregister(gdev); 970 974 up_write(&gdev->sem); 971 - put_device(&gdev->dev); 975 + gpio_device_put(gdev); 972 976 } 973 977 EXPORT_SYMBOL_GPL(gpiochip_remove); 974 978 ··· 1122 1126 /* Just pick something */ 1123 1127 fwspec.param[1] = IRQ_TYPE_EDGE_RISING; 1124 1128 fwspec.param_count = 2; 1125 - ret = __irq_domain_alloc_irqs(gc->irq.domain, 1126 - /* just pick something */ 1127 - -1, 1128 - 1, 1129 - NUMA_NO_NODE, 1130 - &fwspec, 1131 - false, 1132 - NULL); 1129 + ret = irq_domain_alloc_irqs(gc->irq.domain, 1, 1130 + NUMA_NO_NODE, &fwspec); 1133 1131 if (ret < 0) { 1134 1132 chip_err(gc, 1135 1133 "can not allocate irq for GPIO line %d parent hwirq %d in hierarchy domain: %d\n", ··· 2053 2063 int gpiod_request(struct gpio_desc *desc, const char *label) 2054 2064 { 2055 2065 int ret = -EPROBE_DEFER; 2056 - struct gpio_device *gdev; 2057 2066 2058 2067 VALIDATE_DESC(desc); 2059 - gdev = desc->gdev; 2060 2068 2061 - if (try_module_get(gdev->owner)) { 2069 + if (try_module_get(desc->gdev->owner)) { 2062 2070 ret = gpiod_request_commit(desc, label); 2063 2071 if (ret) 2064 - module_put(gdev->owner); 2072 + module_put(desc->gdev->owner); 2065 2073 else 2066 - get_device(&gdev->dev); 2074 + gpio_device_get(desc->gdev); 2067 2075 } 2068 2076 2069 2077 if (ret) ··· 2122 2134 { 2123 2135 if (desc && desc->gdev && gpiod_free_commit(desc)) { 2124 2136 module_put(desc->gdev->owner); 2125 - put_device(&desc->gdev->dev); 2137 + gpio_device_put(desc->gdev); 2126 2138 } else { 2127 2139 WARN_ON(extra_checks); 2128 2140 }
+10
drivers/gpio/gpiolib.h
··· 82 82 return container_of(dev, struct gpio_device, dev); 83 83 } 84 84 85 + static inline struct gpio_device *gpio_device_get(struct gpio_device *gdev) 86 + { 87 + return to_gpio_device(get_device(&gdev->dev)); 88 + } 89 + 90 + static inline void gpio_device_put(struct gpio_device *gdev) 91 + { 92 + put_device(&gdev->dev); 93 + } 94 + 85 95 /* gpio suffixes used for ACPI and device tree lookup */ 86 96 static __maybe_unused const char * const gpio_suffixes[] = { "gpios", "gpio" }; 87 97
+12 -2
drivers/pinctrl/core.c
··· 325 325 { 326 326 struct pinctrl_dev *pctldev; 327 327 struct pinctrl_gpio_range *range = NULL; 328 - struct gpio_chip *chip = gpio_to_chip(gpio); 328 + /* 329 + * FIXME: "gpio" here is a number in the global GPIO numberspace. 330 + * get rid of this from the ranges eventually and get the GPIO 331 + * descriptor from the gpio_chip. 332 + */ 333 + struct gpio_chip *chip = gpiod_to_chip(gpio_to_desc(gpio)); 329 334 330 335 if (WARN(!chip, "no gpio_chip for gpio%i?", gpio)) 331 336 return false; ··· 1662 1657 } 1663 1658 } 1664 1659 if (gpio_num >= 0) 1665 - chip = gpio_to_chip(gpio_num); 1660 + /* 1661 + * FIXME: gpio_num comes from the global GPIO numberspace. 1662 + * we need to get rid of the range->base eventually and 1663 + * get the descriptor directly from the gpio_chip. 1664 + */ 1665 + chip = gpiod_to_chip(gpio_to_desc(gpio_num)); 1666 1666 else 1667 1667 chip = NULL; 1668 1668 if (chip)
-12
include/asm-generic/gpio.h
··· 31 31 struct device_node; 32 32 struct gpio_desc; 33 33 34 - /* caller holds gpio_lock *OR* gpio is marked as requested */ 35 - static inline struct gpio_chip *gpio_to_chip(unsigned gpio) 36 - { 37 - return gpiod_to_chip(gpio_to_desc(gpio)); 38 - } 39 - 40 34 /* Always use the library code for GPIO management calls, 41 35 * or when sleeping may be involved. 42 36 */ ··· 95 101 static inline int gpio_export(unsigned gpio, bool direction_may_change) 96 102 { 97 103 return gpiod_export(gpio_to_desc(gpio), direction_may_change); 98 - } 99 - 100 - static inline int gpio_export_link(struct device *dev, const char *name, 101 - unsigned gpio) 102 - { 103 - return gpiod_export_link(dev, name, gpio_to_desc(gpio)); 104 104 } 105 105 106 106 static inline void gpio_unexport(unsigned gpio)
-20
include/linux/gpio.h
··· 81 81 return __gpio_to_irq(gpio); 82 82 } 83 83 84 - static inline int irq_to_gpio(unsigned int irq) 85 - { 86 - return -EINVAL; 87 - } 88 - 89 84 #endif /* ! CONFIG_ARCH_HAVE_CUSTOM_GPIO_H */ 90 85 91 86 /* CONFIG_GPIOLIB: bindings for managed devices that want to request gpios */ ··· 192 197 return -EINVAL; 193 198 } 194 199 195 - static inline int gpio_export_link(struct device *dev, const char *name, 196 - unsigned gpio) 197 - { 198 - /* GPIO can never have been exported */ 199 - WARN_ON(1); 200 - return -EINVAL; 201 - } 202 - 203 200 static inline void gpio_unexport(unsigned gpio) 204 201 { 205 202 /* GPIO can never have been exported */ ··· 201 214 static inline int gpio_to_irq(unsigned gpio) 202 215 { 203 216 /* GPIO can never have been requested or set as input */ 204 - WARN_ON(1); 205 - return -EINVAL; 206 - } 207 - 208 - static inline int irq_to_gpio(unsigned irq) 209 - { 210 - /* irq can never have been returned from gpio_to_irq() */ 211 217 WARN_ON(1); 212 218 return -EINVAL; 213 219 }
-48
include/linux/gpio/consumer.h
··· 581 581 flags, label); 582 582 } 583 583 584 - #if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_OF_GPIO) 585 - struct device_node; 586 - 587 - struct gpio_desc *gpiod_get_from_of_node(const struct device_node *node, 588 - const char *propname, int index, 589 - enum gpiod_flags dflags, 590 - const char *label); 591 - 592 - #else /* CONFIG_GPIOLIB && CONFIG_OF_GPIO */ 593 - 594 - struct device_node; 595 - 596 - static inline 597 - struct gpio_desc *gpiod_get_from_of_node(const struct device_node *node, 598 - const char *propname, int index, 599 - enum gpiod_flags dflags, 600 - const char *label) 601 - { 602 - return ERR_PTR(-ENOSYS); 603 - } 604 - 605 - #endif /* CONFIG_GPIOLIB && CONFIG_OF_GPIO */ 606 - 607 - #ifdef CONFIG_GPIOLIB 608 - struct device_node; 609 - 610 - struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev, 611 - const struct device_node *node, 612 - const char *propname, int index, 613 - enum gpiod_flags dflags, 614 - const char *label); 615 - 616 - #else /* CONFIG_GPIOLIB */ 617 - 618 - struct device_node; 619 - 620 - static inline 621 - struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev, 622 - const struct device_node *node, 623 - const char *propname, int index, 624 - enum gpiod_flags dflags, 625 - const char *label) 626 - { 627 - return ERR_PTR(-ENOSYS); 628 - } 629 - 630 - #endif /* CONFIG_GPIOLIB */ 631 - 632 584 struct acpi_gpio_params { 633 585 unsigned int crs_entry_index; 634 586 unsigned int line_index;
+1 -8
include/linux/gpio/driver.h
··· 336 336 * @set_multiple: assigns output values for multiple signals defined by "mask" 337 337 * @set_config: optional hook for all kinds of settings. Uses the same 338 338 * packed config format as generic pinconf. 339 - * @to_irq: optional hook supporting non-static gpio_to_irq() mappings; 339 + * @to_irq: optional hook supporting non-static gpiod_to_irq() mappings; 340 340 * implementation may not sleep 341 341 * @dbg_show: optional routine to show contents in debugfs; default code 342 342 * will be used when this is omitted, but custom code can show extra ··· 502 502 * If CONFIG_OF_GPIO is enabled, then all GPIO controllers described in 503 503 * the device tree automatically may have an OF translation 504 504 */ 505 - 506 - /** 507 - * @of_node: 508 - * 509 - * Pointer to a device tree node representing this GPIO controller. 510 - */ 511 - struct device_node *of_node; 512 505 513 506 /** 514 507 * @of_gpio_n_cells:
+4 -98
include/linux/of_gpio.h
··· 17 17 18 18 struct device_node; 19 19 20 - /* 21 - * This is Linux-specific flags. By default controllers' and Linux' mapping 22 - * match, but GPIO controllers are free to translate their own flags to 23 - * Linux-specific in their .xlate callback. Though, 1:1 mapping is recommended. 24 - */ 25 - enum of_gpio_flags { 26 - OF_GPIO_ACTIVE_LOW = 0x1, 27 - OF_GPIO_SINGLE_ENDED = 0x2, 28 - OF_GPIO_OPEN_DRAIN = 0x4, 29 - OF_GPIO_TRANSITORY = 0x8, 30 - OF_GPIO_PULL_UP = 0x10, 31 - OF_GPIO_PULL_DOWN = 0x20, 32 - OF_GPIO_PULL_DISABLE = 0x40, 33 - }; 34 - 35 20 #ifdef CONFIG_OF_GPIO 36 21 37 22 #include <linux/container_of.h> ··· 35 50 return container_of(gc, struct of_mm_gpio_chip, gc); 36 51 } 37 52 38 - extern int of_get_named_gpio_flags(const struct device_node *np, 39 - const char *list_name, int index, enum of_gpio_flags *flags); 53 + extern int of_get_named_gpio(const struct device_node *np, 54 + const char *list_name, int index); 40 55 41 56 extern int of_mm_gpiochip_add_data(struct device_node *np, 42 57 struct of_mm_gpio_chip *mm_gc, 43 58 void *data); 44 - static inline int of_mm_gpiochip_add(struct device_node *np, 45 - struct of_mm_gpio_chip *mm_gc) 46 - { 47 - return of_mm_gpiochip_add_data(np, mm_gc, NULL); 48 - } 49 59 extern void of_mm_gpiochip_remove(struct of_mm_gpio_chip *mm_gc); 50 60 51 61 #else /* CONFIG_OF_GPIO */ ··· 48 68 #include <linux/errno.h> 49 69 50 70 /* Drivers may not strictly depend on the GPIO support, so let them link. */ 51 - static inline int of_get_named_gpio_flags(const struct device_node *np, 52 - const char *list_name, int index, enum of_gpio_flags *flags) 71 + static inline int of_get_named_gpio(const struct device_node *np, 72 + const char *propname, int index) 53 73 { 54 - if (flags) 55 - *flags = 0; 56 - 57 74 return -ENOSYS; 58 75 } 59 76 60 77 #endif /* CONFIG_OF_GPIO */ 61 - 62 - /** 63 - * of_gpio_named_count() - Count GPIOs for a device 64 - * @np: device node to count GPIOs for 65 - * @propname: property name containing gpio specifier(s) 66 - * 67 - * The function returns the count of GPIOs specified for a node. 68 - * Note that the empty GPIO specifiers count too. Returns either 69 - * Number of gpios defined in property, 70 - * -EINVAL for an incorrectly formed gpios property, or 71 - * -ENOENT for a missing gpios property 72 - * 73 - * Example: 74 - * gpios = <0 75 - * &gpio1 1 2 76 - * 0 77 - * &gpio2 3 4>; 78 - * 79 - * The above example defines four GPIOs, two of which are not specified. 80 - * This function will return '4' 81 - */ 82 - static inline int of_gpio_named_count(const struct device_node *np, 83 - const char *propname) 84 - { 85 - return of_count_phandle_with_args(np, propname, "#gpio-cells"); 86 - } 87 - 88 - /** 89 - * of_gpio_count() - Count GPIOs for a device 90 - * @np: device node to count GPIOs for 91 - * 92 - * Same as of_gpio_named_count, but hard coded to use the 'gpios' property 93 - */ 94 - static inline int of_gpio_count(const struct device_node *np) 95 - { 96 - return of_gpio_named_count(np, "gpios"); 97 - } 98 - 99 - static inline int of_get_gpio_flags(const struct device_node *np, int index, 100 - enum of_gpio_flags *flags) 101 - { 102 - return of_get_named_gpio_flags(np, "gpios", index, flags); 103 - } 104 - 105 - /** 106 - * of_get_named_gpio() - Get a GPIO number to use with GPIO API 107 - * @np: device node to get GPIO from 108 - * @propname: Name of property containing gpio specifier(s) 109 - * @index: index of the GPIO 110 - * 111 - * Returns GPIO number to use with Linux generic GPIO API, or one of the errno 112 - * value on the error condition. 113 - */ 114 - static inline int of_get_named_gpio(const struct device_node *np, 115 - const char *propname, int index) 116 - { 117 - return of_get_named_gpio_flags(np, propname, index, NULL); 118 - } 119 - 120 - /** 121 - * of_get_gpio() - Get a GPIO number to use with GPIO API 122 - * @np: device node to get GPIO from 123 - * @index: index of the GPIO 124 - * 125 - * Returns GPIO number to use with Linux generic GPIO API, or one of the errno 126 - * value on the error condition. 127 - */ 128 - static inline int of_get_gpio(const struct device_node *np, int index) 129 - { 130 - return of_get_gpio_flags(np, index, NULL); 131 - } 132 78 133 79 #endif /* __LINUX_OF_GPIO_H */
-45
include/linux/platform_data/pcf857x.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0 */ 2 - #ifndef __LINUX_PCF857X_H 3 - #define __LINUX_PCF857X_H 4 - 5 - /** 6 - * struct pcf857x_platform_data - data to set up pcf857x driver 7 - * @gpio_base: number of the chip's first GPIO 8 - * @n_latch: optional bit-inverse of initial register value; if 9 - * you leave this initialized to zero the driver will act 10 - * like the chip was just reset 11 - * @setup: optional callback issued once the GPIOs are valid 12 - * @teardown: optional callback issued before the GPIOs are invalidated 13 - * @context: optional parameter passed to setup() and teardown() 14 - * 15 - * In addition to the I2C_BOARD_INFO() state appropriate to each chip, 16 - * the i2c_board_info used with the pcf875x driver must provide its 17 - * platform_data (pointer to one of these structures) with at least 18 - * the gpio_base value initialized. 19 - * 20 - * The @setup callback may be used with the kind of board-specific glue 21 - * which hands the (now-valid) GPIOs to other drivers, or which puts 22 - * devices in their initial states using these GPIOs. 23 - * 24 - * These GPIO chips are only "quasi-bidirectional"; read the chip specs 25 - * to understand the behavior. They don't have separate registers to 26 - * record which pins are used for input or output, record which output 27 - * values are driven, or provide access to input values. That must be 28 - * inferred by reading the chip's value and knowing the last value written 29 - * to it. If you leave n_latch initialized to zero, that last written 30 - * value is presumed to be all ones (as if the chip were just reset). 31 - */ 32 - struct pcf857x_platform_data { 33 - unsigned gpio_base; 34 - unsigned n_latch; 35 - 36 - int (*setup)(struct i2c_client *client, 37 - int gpio, unsigned ngpio, 38 - void *context); 39 - void (*teardown)(struct i2c_client *client, 40 - int gpio, unsigned ngpio, 41 - void *context); 42 - void *context; 43 - }; 44 - 45 - #endif /* __LINUX_PCF857X_H */