diff options
53 files changed, 1481 insertions, 274 deletions
diff --git a/Documentation/devicetree/bindings/gpio/fsl-imx-gpio.txt b/Documentation/devicetree/bindings/gpio/fsl-imx-gpio.txt index dbd22e0df21e..b4cd9f906c24 100644 --- a/Documentation/devicetree/bindings/gpio/fsl-imx-gpio.txt +++ b/Documentation/devicetree/bindings/gpio/fsl-imx-gpio.txt | |||
@@ -19,6 +19,9 @@ Required properties: | |||
19 | 4 = active high level-sensitive. | 19 | 4 = active high level-sensitive. |
20 | 8 = active low level-sensitive. | 20 | 8 = active low level-sensitive. |
21 | 21 | ||
22 | Optional properties: | ||
23 | - clocks: the clock for clocking the GPIO silicon | ||
24 | |||
22 | Example: | 25 | Example: |
23 | 26 | ||
24 | gpio0: gpio@73f84000 { | 27 | gpio0: gpio@73f84000 { |
diff --git a/Documentation/devicetree/bindings/gpio/mediatek,mt7621-gpio.txt b/Documentation/devicetree/bindings/gpio/mediatek,mt7621-gpio.txt new file mode 100644 index 000000000000..ba455589f869 --- /dev/null +++ b/Documentation/devicetree/bindings/gpio/mediatek,mt7621-gpio.txt | |||
@@ -0,0 +1,35 @@ | |||
1 | Mediatek MT7621 SoC GPIO controller bindings | ||
2 | |||
3 | The IP core used inside these SoCs has 3 banks of 32 GPIOs each. | ||
4 | The registers of all the banks are interwoven inside one single IO range. | ||
5 | We load one GPIO controller instance per bank. Also the GPIO controller can receive | ||
6 | interrupts on any of the GPIOs, either edge or level. It then interrupts the CPU | ||
7 | using GIC INT12. | ||
8 | |||
9 | Required properties for the top level node: | ||
10 | - #gpio-cells : Should be two. The first cell is the GPIO pin number and the | ||
11 | second cell specifies GPIO flags, as defined in <dt-bindings/gpio/gpio.h>. | ||
12 | Only the GPIO_ACTIVE_HIGH and GPIO_ACTIVE_LOW flags are supported. | ||
13 | - #interrupt-cells : Specifies the number of cells needed to encode an | ||
14 | interrupt. Should be 2. The first cell defines the interrupt number, | ||
15 | the second encodes the triger flags encoded as described in | ||
16 | Documentation/devicetree/bindings/interrupt-controller/interrupts.txt | ||
17 | - compatible: | ||
18 | - "mediatek,mt7621-gpio" for Mediatek controllers | ||
19 | - reg : Physical base address and length of the controller's registers | ||
20 | - interrupt-parent : phandle of the parent interrupt controller. | ||
21 | - interrupts : Interrupt specifier for the controllers interrupt. | ||
22 | - interrupt-controller : Mark the device node as an interrupt controller. | ||
23 | - gpio-controller : Marks the device node as a GPIO controller. | ||
24 | |||
25 | Example: | ||
26 | gpio@600 { | ||
27 | #gpio-cells = <2>; | ||
28 | #interrupt-cells = <2>; | ||
29 | compatible = "mediatek,mt7621-gpio"; | ||
30 | gpio-controller; | ||
31 | interrupt-controller; | ||
32 | reg = <0x600 0x100>; | ||
33 | interrupt-parent = <&gic>; | ||
34 | interrupts = <GIC_SHARED 12 IRQ_TYPE_LEVEL_HIGH>; | ||
35 | }; | ||
diff --git a/Documentation/devicetree/bindings/gpio/nvidia,tegra186-gpio.txt b/Documentation/devicetree/bindings/gpio/nvidia,tegra186-gpio.txt index c82a2e221bc1..adff16c71d21 100644 --- a/Documentation/devicetree/bindings/gpio/nvidia,tegra186-gpio.txt +++ b/Documentation/devicetree/bindings/gpio/nvidia,tegra186-gpio.txt | |||
@@ -68,6 +68,8 @@ Required properties: | |||
68 | One of: | 68 | One of: |
69 | - "nvidia,tegra186-gpio". | 69 | - "nvidia,tegra186-gpio". |
70 | - "nvidia,tegra186-gpio-aon". | 70 | - "nvidia,tegra186-gpio-aon". |
71 | - "nvidia,tegra194-gpio". | ||
72 | - "nvidia,tegra194-gpio-aon". | ||
71 | - reg-names | 73 | - reg-names |
72 | Array of strings. | 74 | Array of strings. |
73 | Contains a list of names for the register spaces described by the reg | 75 | Contains a list of names for the register spaces described by the reg |
@@ -91,6 +93,8 @@ Required properties: | |||
91 | depending on compatible value: | 93 | depending on compatible value: |
92 | - "nvidia,tegra186-gpio": 6 entries. | 94 | - "nvidia,tegra186-gpio": 6 entries. |
93 | - "nvidia,tegra186-gpio-aon": 1 entry. | 95 | - "nvidia,tegra186-gpio-aon": 1 entry. |
96 | - "nvidia,tegra194-gpio": 6 entries. | ||
97 | - "nvidia,tegra194-gpio-aon": 1 entry. | ||
94 | - gpio-controller | 98 | - gpio-controller |
95 | Boolean. | 99 | Boolean. |
96 | Marks the device node as a GPIO controller/provider. | 100 | Marks the device node as a GPIO controller/provider. |
diff --git a/Documentation/devicetree/bindings/gpio/renesas,gpio-rcar.txt b/Documentation/devicetree/bindings/gpio/renesas,gpio-rcar.txt index fe1bf24104d3..4018ee57a6af 100644 --- a/Documentation/devicetree/bindings/gpio/renesas,gpio-rcar.txt +++ b/Documentation/devicetree/bindings/gpio/renesas,gpio-rcar.txt | |||
@@ -17,6 +17,7 @@ Required Properties: | |||
17 | - "renesas,gpio-r8a7796": for R8A7796 (R-Car M3-W) compatible GPIO controller. | 17 | - "renesas,gpio-r8a7796": for R8A7796 (R-Car M3-W) compatible GPIO controller. |
18 | - "renesas,gpio-r8a77965": for R8A77965 (R-Car M3-N) compatible GPIO controller. | 18 | - "renesas,gpio-r8a77965": for R8A77965 (R-Car M3-N) compatible GPIO controller. |
19 | - "renesas,gpio-r8a77970": for R8A77970 (R-Car V3M) compatible GPIO controller. | 19 | - "renesas,gpio-r8a77970": for R8A77970 (R-Car V3M) compatible GPIO controller. |
20 | - "renesas,gpio-r8a77980": for R8A77980 (R-Car V3H) compatible GPIO controller. | ||
20 | - "renesas,gpio-r8a77990": for R8A77990 (R-Car E3) compatible GPIO controller. | 21 | - "renesas,gpio-r8a77990": for R8A77990 (R-Car E3) compatible GPIO controller. |
21 | - "renesas,gpio-r8a77995": for R8A77995 (R-Car D3) compatible GPIO controller. | 22 | - "renesas,gpio-r8a77995": for R8A77995 (R-Car D3) compatible GPIO controller. |
22 | - "renesas,rcar-gen1-gpio": for a generic R-Car Gen1 GPIO controller. | 23 | - "renesas,rcar-gen1-gpio": for a generic R-Car Gen1 GPIO controller. |
diff --git a/Documentation/devicetree/bindings/gpio/rockchip,rk3328-grf-gpio.txt b/Documentation/devicetree/bindings/gpio/rockchip,rk3328-grf-gpio.txt new file mode 100644 index 000000000000..f9231df17c2b --- /dev/null +++ b/Documentation/devicetree/bindings/gpio/rockchip,rk3328-grf-gpio.txt | |||
@@ -0,0 +1,32 @@ | |||
1 | Rockchip RK3328 GRF (General Register Files) GPIO controller. | ||
2 | |||
3 | In Rockchip RK3328, the output only GPIO_MUTE pin, originally for codec mute | ||
4 | control, can also be used for general purpose. It is manipulated by the | ||
5 | GRF_SOC_CON10 register in GRF. Aside from the GPIO_MUTE pin, the HDMI pins can | ||
6 | also be set in the same way. | ||
7 | |||
8 | Currently this GPIO controller only supports the mute pin. If needed in the | ||
9 | future, the HDMI pins support can also be added. | ||
10 | |||
11 | Required properties: | ||
12 | - compatible: Should contain "rockchip,rk3328-grf-gpio". | ||
13 | - gpio-controller: Marks the device node as a gpio controller. | ||
14 | - #gpio-cells: Should be 2. The first cell is the pin number and | ||
15 | the second cell is used to specify the gpio polarity: | ||
16 | 0 = Active high, | ||
17 | 1 = Active low. | ||
18 | |||
19 | Example: | ||
20 | |||
21 | grf: syscon@ff100000 { | ||
22 | compatible = "rockchip,rk3328-grf", "syscon", "simple-mfd"; | ||
23 | |||
24 | grf_gpio: grf-gpio { | ||
25 | compatible = "rockchip,rk3328-grf-gpio"; | ||
26 | gpio-controller; | ||
27 | #gpio-cells = <2>; | ||
28 | }; | ||
29 | }; | ||
30 | |||
31 | Note: The grf_gpio node should be declared as the child of the GRF (General | ||
32 | Register File) node. The GPIO_MUTE pin is referred to as <&grf_gpio 0>. | ||
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index 71c0ab46f216..f7a0f576f918 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig | |||
@@ -359,6 +359,15 @@ config GPIO_MPC8XXX | |||
359 | Say Y here if you're going to use hardware that connects to the | 359 | Say Y here if you're going to use hardware that connects to the |
360 | MPC512x/831x/834x/837x/8572/8610/QorIQ GPIOs. | 360 | MPC512x/831x/834x/837x/8572/8610/QorIQ GPIOs. |
361 | 361 | ||
362 | config GPIO_MT7621 | ||
363 | bool "Mediatek MT7621 GPIO Support" | ||
364 | depends on SOC_MT7620 || SOC_MT7621 || COMPILE_TEST | ||
365 | depends on OF_GPIO | ||
366 | select GPIO_GENERIC | ||
367 | select GPIOLIB_IRQCHIP | ||
368 | help | ||
369 | Say yes here to support the Mediatek MT7621 SoC GPIO device | ||
370 | |||
362 | config GPIO_MVEBU | 371 | config GPIO_MVEBU |
363 | def_bool y | 372 | def_bool y |
364 | depends on PLAT_ORION || ARCH_MVEBU | 373 | depends on PLAT_ORION || ARCH_MVEBU |
@@ -684,7 +693,8 @@ config GPIO_IT87 | |||
684 | Say yes here to support GPIO functionality of IT87xx Super I/O chips. | 693 | Say yes here to support GPIO functionality of IT87xx Super I/O chips. |
685 | 694 | ||
686 | This driver is tested with ITE IT8728 and IT8732 Super I/O chips, and | 695 | This driver is tested with ITE IT8728 and IT8732 Super I/O chips, and |
687 | supports the IT8761E, IT8620E and IT8628E Super I/O chip as well. | 696 | supports the IT8761E, IT8613, IT8620E, and IT8628E Super I/O chips as |
697 | well. | ||
688 | 698 | ||
689 | To compile this driver as a module, choose M here: the module will | 699 | To compile this driver as a module, choose M here: the module will |
690 | be called gpio_it87 | 700 | be called gpio_it87 |
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile index 1324c8f966a7..fc77989371be 100644 --- a/drivers/gpio/Makefile +++ b/drivers/gpio/Makefile | |||
@@ -88,6 +88,7 @@ obj-$(CONFIG_GPIO_MOCKUP) += gpio-mockup.o | |||
88 | obj-$(CONFIG_GPIO_MPC5200) += gpio-mpc5200.o | 88 | obj-$(CONFIG_GPIO_MPC5200) += gpio-mpc5200.o |
89 | obj-$(CONFIG_GPIO_MPC8XXX) += gpio-mpc8xxx.o | 89 | obj-$(CONFIG_GPIO_MPC8XXX) += gpio-mpc8xxx.o |
90 | obj-$(CONFIG_GPIO_MSIC) += gpio-msic.o | 90 | obj-$(CONFIG_GPIO_MSIC) += gpio-msic.o |
91 | obj-$(CONFIG_GPIO_MT7621) += gpio-mt7621.o | ||
91 | obj-$(CONFIG_GPIO_MVEBU) += gpio-mvebu.o | 92 | obj-$(CONFIG_GPIO_MVEBU) += gpio-mvebu.o |
92 | obj-$(CONFIG_GPIO_MXC) += gpio-mxc.o | 93 | obj-$(CONFIG_GPIO_MXC) += gpio-mxc.o |
93 | obj-$(CONFIG_GPIO_MXS) += gpio-mxs.o | 94 | obj-$(CONFIG_GPIO_MXS) += gpio-mxs.o |
diff --git a/drivers/gpio/gpio-aspeed.c b/drivers/gpio/gpio-aspeed.c index b31ae16170e7..2342e154029b 100644 --- a/drivers/gpio/gpio-aspeed.c +++ b/drivers/gpio/gpio-aspeed.c | |||
@@ -12,6 +12,7 @@ | |||
12 | #include <asm/div64.h> | 12 | #include <asm/div64.h> |
13 | #include <linux/clk.h> | 13 | #include <linux/clk.h> |
14 | #include <linux/gpio/driver.h> | 14 | #include <linux/gpio/driver.h> |
15 | #include <linux/gpio/aspeed.h> | ||
15 | #include <linux/hashtable.h> | 16 | #include <linux/hashtable.h> |
16 | #include <linux/init.h> | 17 | #include <linux/init.h> |
17 | #include <linux/io.h> | 18 | #include <linux/io.h> |
@@ -22,6 +23,15 @@ | |||
22 | #include <linux/spinlock.h> | 23 | #include <linux/spinlock.h> |
23 | #include <linux/string.h> | 24 | #include <linux/string.h> |
24 | 25 | ||
26 | /* | ||
27 | * These two headers aren't meant to be used by GPIO drivers. We need | ||
28 | * them in order to access gpio_chip_hwgpio() which we need to implement | ||
29 | * the aspeed specific API which allows the coprocessor to request | ||
30 | * access to some GPIOs and to arbitrate between coprocessor and ARM. | ||
31 | */ | ||
32 | #include <linux/gpio/consumer.h> | ||
33 | #include "gpiolib.h" | ||
34 | |||
25 | struct aspeed_bank_props { | 35 | struct aspeed_bank_props { |
26 | unsigned int bank; | 36 | unsigned int bank; |
27 | u32 input; | 37 | u32 input; |
@@ -56,83 +66,130 @@ struct aspeed_gpio { | |||
56 | struct clk *clk; | 66 | struct clk *clk; |
57 | 67 | ||
58 | u32 *dcache; | 68 | u32 *dcache; |
69 | u8 *cf_copro_bankmap; | ||
59 | }; | 70 | }; |
60 | 71 | ||
61 | struct aspeed_gpio_bank { | 72 | struct aspeed_gpio_bank { |
62 | uint16_t val_regs; | 73 | uint16_t val_regs; /* +0: Rd: read input value, Wr: set write latch |
74 | * +4: Rd/Wr: Direction (0=in, 1=out) | ||
75 | */ | ||
76 | uint16_t rdata_reg; /* Rd: read write latch, Wr: <none> */ | ||
63 | uint16_t irq_regs; | 77 | uint16_t irq_regs; |
64 | uint16_t debounce_regs; | 78 | uint16_t debounce_regs; |
65 | uint16_t tolerance_regs; | 79 | uint16_t tolerance_regs; |
80 | uint16_t cmdsrc_regs; | ||
66 | const char names[4][3]; | 81 | const char names[4][3]; |
67 | }; | 82 | }; |
68 | 83 | ||
84 | /* | ||
85 | * Note: The "value" register returns the input value sampled on the | ||
86 | * line even when the GPIO is configured as an output. Since | ||
87 | * that input goes through synchronizers, writing, then reading | ||
88 | * back may not return the written value right away. | ||
89 | * | ||
90 | * The "rdata" register returns the content of the write latch | ||
91 | * and thus can be used to read back what was last written | ||
92 | * reliably. | ||
93 | */ | ||
94 | |||
69 | static const int debounce_timers[4] = { 0x00, 0x50, 0x54, 0x58 }; | 95 | static const int debounce_timers[4] = { 0x00, 0x50, 0x54, 0x58 }; |
70 | 96 | ||
97 | static const struct aspeed_gpio_copro_ops *copro_ops; | ||
98 | static void *copro_data; | ||
99 | |||
71 | static const struct aspeed_gpio_bank aspeed_gpio_banks[] = { | 100 | static const struct aspeed_gpio_bank aspeed_gpio_banks[] = { |
72 | { | 101 | { |
73 | .val_regs = 0x0000, | 102 | .val_regs = 0x0000, |
103 | .rdata_reg = 0x00c0, | ||
74 | .irq_regs = 0x0008, | 104 | .irq_regs = 0x0008, |
75 | .debounce_regs = 0x0040, | 105 | .debounce_regs = 0x0040, |
76 | .tolerance_regs = 0x001c, | 106 | .tolerance_regs = 0x001c, |
107 | .cmdsrc_regs = 0x0060, | ||
77 | .names = { "A", "B", "C", "D" }, | 108 | .names = { "A", "B", "C", "D" }, |
78 | }, | 109 | }, |
79 | { | 110 | { |
80 | .val_regs = 0x0020, | 111 | .val_regs = 0x0020, |
112 | .rdata_reg = 0x00c4, | ||
81 | .irq_regs = 0x0028, | 113 | .irq_regs = 0x0028, |
82 | .debounce_regs = 0x0048, | 114 | .debounce_regs = 0x0048, |
83 | .tolerance_regs = 0x003c, | 115 | .tolerance_regs = 0x003c, |
116 | .cmdsrc_regs = 0x0068, | ||
84 | .names = { "E", "F", "G", "H" }, | 117 | .names = { "E", "F", "G", "H" }, |
85 | }, | 118 | }, |
86 | { | 119 | { |
87 | .val_regs = 0x0070, | 120 | .val_regs = 0x0070, |
121 | .rdata_reg = 0x00c8, | ||
88 | .irq_regs = 0x0098, | 122 | .irq_regs = 0x0098, |
89 | .debounce_regs = 0x00b0, | 123 | .debounce_regs = 0x00b0, |
90 | .tolerance_regs = 0x00ac, | 124 | .tolerance_regs = 0x00ac, |
125 | .cmdsrc_regs = 0x0090, | ||
91 | .names = { "I", "J", "K", "L" }, | 126 | .names = { "I", "J", "K", "L" }, |
92 | }, | 127 | }, |
93 | { | 128 | { |
94 | .val_regs = 0x0078, | 129 | .val_regs = 0x0078, |
130 | .rdata_reg = 0x00cc, | ||
95 | .irq_regs = 0x00e8, | 131 | .irq_regs = 0x00e8, |
96 | .debounce_regs = 0x0100, | 132 | .debounce_regs = 0x0100, |
97 | .tolerance_regs = 0x00fc, | 133 | .tolerance_regs = 0x00fc, |
134 | .cmdsrc_regs = 0x00e0, | ||
98 | .names = { "M", "N", "O", "P" }, | 135 | .names = { "M", "N", "O", "P" }, |
99 | }, | 136 | }, |
100 | { | 137 | { |
101 | .val_regs = 0x0080, | 138 | .val_regs = 0x0080, |
139 | .rdata_reg = 0x00d0, | ||
102 | .irq_regs = 0x0118, | 140 | .irq_regs = 0x0118, |
103 | .debounce_regs = 0x0130, | 141 | .debounce_regs = 0x0130, |
104 | .tolerance_regs = 0x012c, | 142 | .tolerance_regs = 0x012c, |
143 | .cmdsrc_regs = 0x0110, | ||
105 | .names = { "Q", "R", "S", "T" }, | 144 | .names = { "Q", "R", "S", "T" }, |
106 | }, | 145 | }, |
107 | { | 146 | { |
108 | .val_regs = 0x0088, | 147 | .val_regs = 0x0088, |
148 | .rdata_reg = 0x00d4, | ||
109 | .irq_regs = 0x0148, | 149 | .irq_regs = 0x0148, |
110 | .debounce_regs = 0x0160, | 150 | .debounce_regs = 0x0160, |
111 | .tolerance_regs = 0x015c, | 151 | .tolerance_regs = 0x015c, |
152 | .cmdsrc_regs = 0x0140, | ||
112 | .names = { "U", "V", "W", "X" }, | 153 | .names = { "U", "V", "W", "X" }, |
113 | }, | 154 | }, |
114 | { | 155 | { |
115 | .val_regs = 0x01E0, | 156 | .val_regs = 0x01E0, |
157 | .rdata_reg = 0x00d8, | ||
116 | .irq_regs = 0x0178, | 158 | .irq_regs = 0x0178, |
117 | .debounce_regs = 0x0190, | 159 | .debounce_regs = 0x0190, |
118 | .tolerance_regs = 0x018c, | 160 | .tolerance_regs = 0x018c, |
161 | .cmdsrc_regs = 0x0170, | ||
119 | .names = { "Y", "Z", "AA", "AB" }, | 162 | .names = { "Y", "Z", "AA", "AB" }, |
120 | }, | 163 | }, |
121 | { | 164 | { |
122 | .val_regs = 0x01e8, | 165 | .val_regs = 0x01e8, |
166 | .rdata_reg = 0x00dc, | ||
123 | .irq_regs = 0x01a8, | 167 | .irq_regs = 0x01a8, |
124 | .debounce_regs = 0x01c0, | 168 | .debounce_regs = 0x01c0, |
125 | .tolerance_regs = 0x01bc, | 169 | .tolerance_regs = 0x01bc, |
170 | .cmdsrc_regs = 0x01a0, | ||
126 | .names = { "AC", "", "", "" }, | 171 | .names = { "AC", "", "", "" }, |
127 | }, | 172 | }, |
128 | }; | 173 | }; |
129 | 174 | ||
130 | #define GPIO_BANK(x) ((x) >> 5) | 175 | enum aspeed_gpio_reg { |
131 | #define GPIO_OFFSET(x) ((x) & 0x1f) | 176 | reg_val, |
132 | #define GPIO_BIT(x) BIT(GPIO_OFFSET(x)) | 177 | reg_rdata, |
178 | reg_dir, | ||
179 | reg_irq_enable, | ||
180 | reg_irq_type0, | ||
181 | reg_irq_type1, | ||
182 | reg_irq_type2, | ||
183 | reg_irq_status, | ||
184 | reg_debounce_sel1, | ||
185 | reg_debounce_sel2, | ||
186 | reg_tolerance, | ||
187 | reg_cmdsrc0, | ||
188 | reg_cmdsrc1, | ||
189 | }; | ||
133 | 190 | ||
134 | #define GPIO_DATA 0x00 | 191 | #define GPIO_VAL_VALUE 0x00 |
135 | #define GPIO_DIR 0x04 | 192 | #define GPIO_VAL_DIR 0x04 |
136 | 193 | ||
137 | #define GPIO_IRQ_ENABLE 0x00 | 194 | #define GPIO_IRQ_ENABLE 0x00 |
138 | #define GPIO_IRQ_TYPE0 0x04 | 195 | #define GPIO_IRQ_TYPE0 0x04 |
@@ -143,6 +200,53 @@ static const struct aspeed_gpio_bank aspeed_gpio_banks[] = { | |||
143 | #define GPIO_DEBOUNCE_SEL1 0x00 | 200 | #define GPIO_DEBOUNCE_SEL1 0x00 |
144 | #define GPIO_DEBOUNCE_SEL2 0x04 | 201 | #define GPIO_DEBOUNCE_SEL2 0x04 |
145 | 202 | ||
203 | #define GPIO_CMDSRC_0 0x00 | ||
204 | #define GPIO_CMDSRC_1 0x04 | ||
205 | #define GPIO_CMDSRC_ARM 0 | ||
206 | #define GPIO_CMDSRC_LPC 1 | ||
207 | #define GPIO_CMDSRC_COLDFIRE 2 | ||
208 | #define GPIO_CMDSRC_RESERVED 3 | ||
209 | |||
210 | /* This will be resolved at compile time */ | ||
211 | static inline void __iomem *bank_reg(struct aspeed_gpio *gpio, | ||
212 | const struct aspeed_gpio_bank *bank, | ||
213 | const enum aspeed_gpio_reg reg) | ||
214 | { | ||
215 | switch (reg) { | ||
216 | case reg_val: | ||
217 | return gpio->base + bank->val_regs + GPIO_VAL_VALUE; | ||
218 | case reg_rdata: | ||
219 | return gpio->base + bank->rdata_reg; | ||
220 | case reg_dir: | ||
221 | return gpio->base + bank->val_regs + GPIO_VAL_DIR; | ||
222 | case reg_irq_enable: | ||
223 | return gpio->base + bank->irq_regs + GPIO_IRQ_ENABLE; | ||
224 | case reg_irq_type0: | ||
225 | return gpio->base + bank->irq_regs + GPIO_IRQ_TYPE0; | ||
226 | case reg_irq_type1: | ||
227 | return gpio->base + bank->irq_regs + GPIO_IRQ_TYPE1; | ||
228 | case reg_irq_type2: | ||
229 | return gpio->base + bank->irq_regs + GPIO_IRQ_TYPE2; | ||
230 | case reg_irq_status: | ||
231 | return gpio->base + bank->irq_regs + GPIO_IRQ_STATUS; | ||
232 | case reg_debounce_sel1: | ||
233 | return gpio->base + bank->debounce_regs + GPIO_DEBOUNCE_SEL1; | ||
234 | case reg_debounce_sel2: | ||
235 | return gpio->base + bank->debounce_regs + GPIO_DEBOUNCE_SEL2; | ||
236 | case reg_tolerance: | ||
237 | return gpio->base + bank->tolerance_regs; | ||
238 | case reg_cmdsrc0: | ||
239 | return gpio->base + bank->cmdsrc_regs + GPIO_CMDSRC_0; | ||
240 | case reg_cmdsrc1: | ||
241 | return gpio->base + bank->cmdsrc_regs + GPIO_CMDSRC_1; | ||
242 | } | ||
243 | BUG(); | ||
244 | } | ||
245 | |||
246 | #define GPIO_BANK(x) ((x) >> 5) | ||
247 | #define GPIO_OFFSET(x) ((x) & 0x1f) | ||
248 | #define GPIO_BIT(x) BIT(GPIO_OFFSET(x)) | ||
249 | |||
146 | #define _GPIO_SET_DEBOUNCE(t, o, i) ((!!((t) & BIT(i))) << GPIO_OFFSET(o)) | 250 | #define _GPIO_SET_DEBOUNCE(t, o, i) ((!!((t) & BIT(i))) << GPIO_OFFSET(o)) |
147 | #define GPIO_SET_DEBOUNCE1(t, o) _GPIO_SET_DEBOUNCE(t, o, 1) | 251 | #define GPIO_SET_DEBOUNCE1(t, o) _GPIO_SET_DEBOUNCE(t, o, 1) |
148 | #define GPIO_SET_DEBOUNCE2(t, o) _GPIO_SET_DEBOUNCE(t, o, 0) | 252 | #define GPIO_SET_DEBOUNCE2(t, o) _GPIO_SET_DEBOUNCE(t, o, 0) |
@@ -201,18 +305,80 @@ static inline bool have_output(struct aspeed_gpio *gpio, unsigned int offset) | |||
201 | return !props || (props->output & GPIO_BIT(offset)); | 305 | return !props || (props->output & GPIO_BIT(offset)); |
202 | } | 306 | } |
203 | 307 | ||
204 | static void __iomem *bank_val_reg(struct aspeed_gpio *gpio, | 308 | static void aspeed_gpio_change_cmd_source(struct aspeed_gpio *gpio, |
205 | const struct aspeed_gpio_bank *bank, | 309 | const struct aspeed_gpio_bank *bank, |
206 | unsigned int reg) | 310 | int bindex, int cmdsrc) |
207 | { | 311 | { |
208 | return gpio->base + bank->val_regs + reg; | 312 | void __iomem *c0 = bank_reg(gpio, bank, reg_cmdsrc0); |
313 | void __iomem *c1 = bank_reg(gpio, bank, reg_cmdsrc1); | ||
314 | u32 bit, reg; | ||
315 | |||
316 | /* | ||
317 | * Each register controls 4 banks, so take the bottom 2 | ||
318 | * bits of the bank index, and use them to select the | ||
319 | * right control bit (0, 8, 16 or 24). | ||
320 | */ | ||
321 | bit = BIT((bindex & 3) << 3); | ||
322 | |||
323 | /* Source 1 first to avoid illegal 11 combination */ | ||
324 | reg = ioread32(c1); | ||
325 | if (cmdsrc & 2) | ||
326 | reg |= bit; | ||
327 | else | ||
328 | reg &= ~bit; | ||
329 | iowrite32(reg, c1); | ||
330 | |||
331 | /* Then Source 0 */ | ||
332 | reg = ioread32(c0); | ||
333 | if (cmdsrc & 1) | ||
334 | reg |= bit; | ||
335 | else | ||
336 | reg &= ~bit; | ||
337 | iowrite32(reg, c0); | ||
209 | } | 338 | } |
210 | 339 | ||
211 | static void __iomem *bank_irq_reg(struct aspeed_gpio *gpio, | 340 | static bool aspeed_gpio_copro_request(struct aspeed_gpio *gpio, |
212 | const struct aspeed_gpio_bank *bank, | 341 | unsigned int offset) |
213 | unsigned int reg) | ||
214 | { | 342 | { |
215 | return gpio->base + bank->irq_regs + reg; | 343 | const struct aspeed_gpio_bank *bank = to_bank(offset); |
344 | |||
345 | if (!copro_ops || !gpio->cf_copro_bankmap) | ||
346 | return false; | ||
347 | if (!gpio->cf_copro_bankmap[offset >> 3]) | ||
348 | return false; | ||
349 | if (!copro_ops->request_access) | ||
350 | return false; | ||
351 | |||
352 | /* Pause the coprocessor */ | ||
353 | copro_ops->request_access(copro_data); | ||
354 | |||
355 | /* Change command source back to ARM */ | ||
356 | aspeed_gpio_change_cmd_source(gpio, bank, offset >> 3, GPIO_CMDSRC_ARM); | ||
357 | |||
358 | /* Update cache */ | ||
359 | gpio->dcache[GPIO_BANK(offset)] = ioread32(bank_reg(gpio, bank, reg_rdata)); | ||
360 | |||
361 | return true; | ||
362 | } | ||
363 | |||
364 | static void aspeed_gpio_copro_release(struct aspeed_gpio *gpio, | ||
365 | unsigned int offset) | ||
366 | { | ||
367 | const struct aspeed_gpio_bank *bank = to_bank(offset); | ||
368 | |||
369 | if (!copro_ops || !gpio->cf_copro_bankmap) | ||
370 | return; | ||
371 | if (!gpio->cf_copro_bankmap[offset >> 3]) | ||
372 | return; | ||
373 | if (!copro_ops->release_access) | ||
374 | return; | ||
375 | |||
376 | /* Change command source back to ColdFire */ | ||
377 | aspeed_gpio_change_cmd_source(gpio, bank, offset >> 3, | ||
378 | GPIO_CMDSRC_COLDFIRE); | ||
379 | |||
380 | /* Restart the coprocessor */ | ||
381 | copro_ops->release_access(copro_data); | ||
216 | } | 382 | } |
217 | 383 | ||
218 | static int aspeed_gpio_get(struct gpio_chip *gc, unsigned int offset) | 384 | static int aspeed_gpio_get(struct gpio_chip *gc, unsigned int offset) |
@@ -220,8 +386,7 @@ static int aspeed_gpio_get(struct gpio_chip *gc, unsigned int offset) | |||
220 | struct aspeed_gpio *gpio = gpiochip_get_data(gc); | 386 | struct aspeed_gpio *gpio = gpiochip_get_data(gc); |
221 | const struct aspeed_gpio_bank *bank = to_bank(offset); | 387 | const struct aspeed_gpio_bank *bank = to_bank(offset); |
222 | 388 | ||
223 | return !!(ioread32(bank_val_reg(gpio, bank, GPIO_DATA)) | 389 | return !!(ioread32(bank_reg(gpio, bank, reg_val)) & GPIO_BIT(offset)); |
224 | & GPIO_BIT(offset)); | ||
225 | } | 390 | } |
226 | 391 | ||
227 | static void __aspeed_gpio_set(struct gpio_chip *gc, unsigned int offset, | 392 | static void __aspeed_gpio_set(struct gpio_chip *gc, unsigned int offset, |
@@ -232,7 +397,7 @@ static void __aspeed_gpio_set(struct gpio_chip *gc, unsigned int offset, | |||
232 | void __iomem *addr; | 397 | void __iomem *addr; |
233 | u32 reg; | 398 | u32 reg; |
234 | 399 | ||
235 | addr = bank_val_reg(gpio, bank, GPIO_DATA); | 400 | addr = bank_reg(gpio, bank, reg_val); |
236 | reg = gpio->dcache[GPIO_BANK(offset)]; | 401 | reg = gpio->dcache[GPIO_BANK(offset)]; |
237 | 402 | ||
238 | if (val) | 403 | if (val) |
@@ -249,11 +414,15 @@ static void aspeed_gpio_set(struct gpio_chip *gc, unsigned int offset, | |||
249 | { | 414 | { |
250 | struct aspeed_gpio *gpio = gpiochip_get_data(gc); | 415 | struct aspeed_gpio *gpio = gpiochip_get_data(gc); |
251 | unsigned long flags; | 416 | unsigned long flags; |
417 | bool copro; | ||
252 | 418 | ||
253 | spin_lock_irqsave(&gpio->lock, flags); | 419 | spin_lock_irqsave(&gpio->lock, flags); |
420 | copro = aspeed_gpio_copro_request(gpio, offset); | ||
254 | 421 | ||
255 | __aspeed_gpio_set(gc, offset, val); | 422 | __aspeed_gpio_set(gc, offset, val); |
256 | 423 | ||
424 | if (copro) | ||
425 | aspeed_gpio_copro_release(gpio, offset); | ||
257 | spin_unlock_irqrestore(&gpio->lock, flags); | 426 | spin_unlock_irqrestore(&gpio->lock, flags); |
258 | } | 427 | } |
259 | 428 | ||
@@ -261,7 +430,9 @@ static int aspeed_gpio_dir_in(struct gpio_chip *gc, unsigned int offset) | |||
261 | { | 430 | { |
262 | struct aspeed_gpio *gpio = gpiochip_get_data(gc); | 431 | struct aspeed_gpio *gpio = gpiochip_get_data(gc); |
263 | const struct aspeed_gpio_bank *bank = to_bank(offset); | 432 | const struct aspeed_gpio_bank *bank = to_bank(offset); |
433 | void __iomem *addr = bank_reg(gpio, bank, reg_dir); | ||
264 | unsigned long flags; | 434 | unsigned long flags; |
435 | bool copro; | ||
265 | u32 reg; | 436 | u32 reg; |
266 | 437 | ||
267 | if (!have_input(gpio, offset)) | 438 | if (!have_input(gpio, offset)) |
@@ -269,8 +440,13 @@ static int aspeed_gpio_dir_in(struct gpio_chip *gc, unsigned int offset) | |||
269 | 440 | ||
270 | spin_lock_irqsave(&gpio->lock, flags); | 441 | spin_lock_irqsave(&gpio->lock, flags); |
271 | 442 | ||
272 | reg = ioread32(bank_val_reg(gpio, bank, GPIO_DIR)); | 443 | reg = ioread32(addr); |
273 | iowrite32(reg & ~GPIO_BIT(offset), bank_val_reg(gpio, bank, GPIO_DIR)); | 444 | reg &= ~GPIO_BIT(offset); |
445 | |||
446 | copro = aspeed_gpio_copro_request(gpio, offset); | ||
447 | iowrite32(reg, addr); | ||
448 | if (copro) | ||
449 | aspeed_gpio_copro_release(gpio, offset); | ||
274 | 450 | ||
275 | spin_unlock_irqrestore(&gpio->lock, flags); | 451 | spin_unlock_irqrestore(&gpio->lock, flags); |
276 | 452 | ||
@@ -282,7 +458,9 @@ static int aspeed_gpio_dir_out(struct gpio_chip *gc, | |||
282 | { | 458 | { |
283 | struct aspeed_gpio *gpio = gpiochip_get_data(gc); | 459 | struct aspeed_gpio *gpio = gpiochip_get_data(gc); |
284 | const struct aspeed_gpio_bank *bank = to_bank(offset); | 460 | const struct aspeed_gpio_bank *bank = to_bank(offset); |
461 | void __iomem *addr = bank_reg(gpio, bank, reg_dir); | ||
285 | unsigned long flags; | 462 | unsigned long flags; |
463 | bool copro; | ||
286 | u32 reg; | 464 | u32 reg; |
287 | 465 | ||
288 | if (!have_output(gpio, offset)) | 466 | if (!have_output(gpio, offset)) |
@@ -290,10 +468,15 @@ static int aspeed_gpio_dir_out(struct gpio_chip *gc, | |||
290 | 468 | ||
291 | spin_lock_irqsave(&gpio->lock, flags); | 469 | spin_lock_irqsave(&gpio->lock, flags); |
292 | 470 | ||
471 | reg = ioread32(addr); | ||
472 | reg |= GPIO_BIT(offset); | ||
473 | |||
474 | copro = aspeed_gpio_copro_request(gpio, offset); | ||
293 | __aspeed_gpio_set(gc, offset, val); | 475 | __aspeed_gpio_set(gc, offset, val); |
294 | reg = ioread32(bank_val_reg(gpio, bank, GPIO_DIR)); | 476 | iowrite32(reg, addr); |
295 | iowrite32(reg | GPIO_BIT(offset), bank_val_reg(gpio, bank, GPIO_DIR)); | ||
296 | 477 | ||
478 | if (copro) | ||
479 | aspeed_gpio_copro_release(gpio, offset); | ||
297 | spin_unlock_irqrestore(&gpio->lock, flags); | 480 | spin_unlock_irqrestore(&gpio->lock, flags); |
298 | 481 | ||
299 | return 0; | 482 | return 0; |
@@ -314,7 +497,7 @@ static int aspeed_gpio_get_direction(struct gpio_chip *gc, unsigned int offset) | |||
314 | 497 | ||
315 | spin_lock_irqsave(&gpio->lock, flags); | 498 | spin_lock_irqsave(&gpio->lock, flags); |
316 | 499 | ||
317 | val = ioread32(bank_val_reg(gpio, bank, GPIO_DIR)) & GPIO_BIT(offset); | 500 | val = ioread32(bank_reg(gpio, bank, reg_dir)) & GPIO_BIT(offset); |
318 | 501 | ||
319 | spin_unlock_irqrestore(&gpio->lock, flags); | 502 | spin_unlock_irqrestore(&gpio->lock, flags); |
320 | 503 | ||
@@ -323,24 +506,23 @@ static int aspeed_gpio_get_direction(struct gpio_chip *gc, unsigned int offset) | |||
323 | } | 506 | } |
324 | 507 | ||
325 | static inline int irqd_to_aspeed_gpio_data(struct irq_data *d, | 508 | static inline int irqd_to_aspeed_gpio_data(struct irq_data *d, |
326 | struct aspeed_gpio **gpio, | 509 | struct aspeed_gpio **gpio, |
327 | const struct aspeed_gpio_bank **bank, | 510 | const struct aspeed_gpio_bank **bank, |
328 | u32 *bit) | 511 | u32 *bit, int *offset) |
329 | { | 512 | { |
330 | int offset; | ||
331 | struct aspeed_gpio *internal; | 513 | struct aspeed_gpio *internal; |
332 | 514 | ||
333 | offset = irqd_to_hwirq(d); | 515 | *offset = irqd_to_hwirq(d); |
334 | 516 | ||
335 | internal = irq_data_get_irq_chip_data(d); | 517 | internal = irq_data_get_irq_chip_data(d); |
336 | 518 | ||
337 | /* This might be a bit of a questionable place to check */ | 519 | /* This might be a bit of a questionable place to check */ |
338 | if (!have_irq(internal, offset)) | 520 | if (!have_irq(internal, *offset)) |
339 | return -ENOTSUPP; | 521 | return -ENOTSUPP; |
340 | 522 | ||
341 | *gpio = internal; | 523 | *gpio = internal; |
342 | *bank = to_bank(offset); | 524 | *bank = to_bank(*offset); |
343 | *bit = GPIO_BIT(offset); | 525 | *bit = GPIO_BIT(*offset); |
344 | 526 | ||
345 | return 0; | 527 | return 0; |
346 | } | 528 | } |
@@ -351,17 +533,23 @@ static void aspeed_gpio_irq_ack(struct irq_data *d) | |||
351 | struct aspeed_gpio *gpio; | 533 | struct aspeed_gpio *gpio; |
352 | unsigned long flags; | 534 | unsigned long flags; |
353 | void __iomem *status_addr; | 535 | void __iomem *status_addr; |
536 | int rc, offset; | ||
537 | bool copro; | ||
354 | u32 bit; | 538 | u32 bit; |
355 | int rc; | ||
356 | 539 | ||
357 | rc = irqd_to_aspeed_gpio_data(d, &gpio, &bank, &bit); | 540 | rc = irqd_to_aspeed_gpio_data(d, &gpio, &bank, &bit, &offset); |
358 | if (rc) | 541 | if (rc) |
359 | return; | 542 | return; |
360 | 543 | ||
361 | status_addr = bank_irq_reg(gpio, bank, GPIO_IRQ_STATUS); | 544 | status_addr = bank_reg(gpio, bank, reg_irq_status); |
362 | 545 | ||
363 | spin_lock_irqsave(&gpio->lock, flags); | 546 | spin_lock_irqsave(&gpio->lock, flags); |
547 | copro = aspeed_gpio_copro_request(gpio, offset); | ||
548 | |||
364 | iowrite32(bit, status_addr); | 549 | iowrite32(bit, status_addr); |
550 | |||
551 | if (copro) | ||
552 | aspeed_gpio_copro_release(gpio, offset); | ||
365 | spin_unlock_irqrestore(&gpio->lock, flags); | 553 | spin_unlock_irqrestore(&gpio->lock, flags); |
366 | } | 554 | } |
367 | 555 | ||
@@ -372,15 +560,17 @@ static void aspeed_gpio_irq_set_mask(struct irq_data *d, bool set) | |||
372 | unsigned long flags; | 560 | unsigned long flags; |
373 | u32 reg, bit; | 561 | u32 reg, bit; |
374 | void __iomem *addr; | 562 | void __iomem *addr; |
375 | int rc; | 563 | int rc, offset; |
564 | bool copro; | ||
376 | 565 | ||
377 | rc = irqd_to_aspeed_gpio_data(d, &gpio, &bank, &bit); | 566 | rc = irqd_to_aspeed_gpio_data(d, &gpio, &bank, &bit, &offset); |
378 | if (rc) | 567 | if (rc) |
379 | return; | 568 | return; |
380 | 569 | ||
381 | addr = bank_irq_reg(gpio, bank, GPIO_IRQ_ENABLE); | 570 | addr = bank_reg(gpio, bank, reg_irq_enable); |
382 | 571 | ||
383 | spin_lock_irqsave(&gpio->lock, flags); | 572 | spin_lock_irqsave(&gpio->lock, flags); |
573 | copro = aspeed_gpio_copro_request(gpio, offset); | ||
384 | 574 | ||
385 | reg = ioread32(addr); | 575 | reg = ioread32(addr); |
386 | if (set) | 576 | if (set) |
@@ -389,6 +579,8 @@ static void aspeed_gpio_irq_set_mask(struct irq_data *d, bool set) | |||
389 | reg &= ~bit; | 579 | reg &= ~bit; |
390 | iowrite32(reg, addr); | 580 | iowrite32(reg, addr); |
391 | 581 | ||
582 | if (copro) | ||
583 | aspeed_gpio_copro_release(gpio, offset); | ||
392 | spin_unlock_irqrestore(&gpio->lock, flags); | 584 | spin_unlock_irqrestore(&gpio->lock, flags); |
393 | } | 585 | } |
394 | 586 | ||
@@ -413,9 +605,10 @@ static int aspeed_gpio_set_type(struct irq_data *d, unsigned int type) | |||
413 | struct aspeed_gpio *gpio; | 605 | struct aspeed_gpio *gpio; |
414 | unsigned long flags; | 606 | unsigned long flags; |
415 | void __iomem *addr; | 607 | void __iomem *addr; |
416 | int rc; | 608 | int rc, offset; |
609 | bool copro; | ||
417 | 610 | ||
418 | rc = irqd_to_aspeed_gpio_data(d, &gpio, &bank, &bit); | 611 | rc = irqd_to_aspeed_gpio_data(d, &gpio, &bank, &bit, &offset); |
419 | if (rc) | 612 | if (rc) |
420 | return -EINVAL; | 613 | return -EINVAL; |
421 | 614 | ||
@@ -441,22 +634,25 @@ static int aspeed_gpio_set_type(struct irq_data *d, unsigned int type) | |||
441 | } | 634 | } |
442 | 635 | ||
443 | spin_lock_irqsave(&gpio->lock, flags); | 636 | spin_lock_irqsave(&gpio->lock, flags); |
637 | copro = aspeed_gpio_copro_request(gpio, offset); | ||
444 | 638 | ||
445 | addr = bank_irq_reg(gpio, bank, GPIO_IRQ_TYPE0); | 639 | addr = bank_reg(gpio, bank, reg_irq_type0); |
446 | reg = ioread32(addr); | 640 | reg = ioread32(addr); |
447 | reg = (reg & ~bit) | type0; | 641 | reg = (reg & ~bit) | type0; |
448 | iowrite32(reg, addr); | 642 | iowrite32(reg, addr); |
449 | 643 | ||
450 | addr = bank_irq_reg(gpio, bank, GPIO_IRQ_TYPE1); | 644 | addr = bank_reg(gpio, bank, reg_irq_type1); |
451 | reg = ioread32(addr); | 645 | reg = ioread32(addr); |
452 | reg = (reg & ~bit) | type1; | 646 | reg = (reg & ~bit) | type1; |
453 | iowrite32(reg, addr); | 647 | iowrite32(reg, addr); |
454 | 648 | ||
455 | addr = bank_irq_reg(gpio, bank, GPIO_IRQ_TYPE2); | 649 | addr = bank_reg(gpio, bank, reg_irq_type2); |
456 | reg = ioread32(addr); | 650 | reg = ioread32(addr); |
457 | reg = (reg & ~bit) | type2; | 651 | reg = (reg & ~bit) | type2; |
458 | iowrite32(reg, addr); | 652 | iowrite32(reg, addr); |
459 | 653 | ||
654 | if (copro) | ||
655 | aspeed_gpio_copro_release(gpio, offset); | ||
460 | spin_unlock_irqrestore(&gpio->lock, flags); | 656 | spin_unlock_irqrestore(&gpio->lock, flags); |
461 | 657 | ||
462 | irq_set_handler_locked(d, handler); | 658 | irq_set_handler_locked(d, handler); |
@@ -477,7 +673,7 @@ static void aspeed_gpio_irq_handler(struct irq_desc *desc) | |||
477 | for (i = 0; i < ARRAY_SIZE(aspeed_gpio_banks); i++) { | 673 | for (i = 0; i < ARRAY_SIZE(aspeed_gpio_banks); i++) { |
478 | const struct aspeed_gpio_bank *bank = &aspeed_gpio_banks[i]; | 674 | const struct aspeed_gpio_bank *bank = &aspeed_gpio_banks[i]; |
479 | 675 | ||
480 | reg = ioread32(bank_irq_reg(data, bank, GPIO_IRQ_STATUS)); | 676 | reg = ioread32(bank_reg(data, bank, reg_irq_status)); |
481 | 677 | ||
482 | for_each_set_bit(p, ®, 32) { | 678 | for_each_set_bit(p, ®, 32) { |
483 | girq = irq_find_mapping(gc->irq.domain, i * 32 + p); | 679 | girq = irq_find_mapping(gc->irq.domain, i * 32 + p); |
@@ -549,21 +745,27 @@ static int aspeed_gpio_reset_tolerance(struct gpio_chip *chip, | |||
549 | unsigned int offset, bool enable) | 745 | unsigned int offset, bool enable) |
550 | { | 746 | { |
551 | struct aspeed_gpio *gpio = gpiochip_get_data(chip); | 747 | struct aspeed_gpio *gpio = gpiochip_get_data(chip); |
552 | const struct aspeed_gpio_bank *bank; | ||
553 | unsigned long flags; | 748 | unsigned long flags; |
749 | void __iomem *treg; | ||
750 | bool copro; | ||
554 | u32 val; | 751 | u32 val; |
555 | 752 | ||
556 | bank = to_bank(offset); | 753 | treg = bank_reg(gpio, to_bank(offset), reg_tolerance); |
557 | 754 | ||
558 | spin_lock_irqsave(&gpio->lock, flags); | 755 | spin_lock_irqsave(&gpio->lock, flags); |
559 | val = readl(gpio->base + bank->tolerance_regs); | 756 | copro = aspeed_gpio_copro_request(gpio, offset); |
757 | |||
758 | val = readl(treg); | ||
560 | 759 | ||
561 | if (enable) | 760 | if (enable) |
562 | val |= GPIO_BIT(offset); | 761 | val |= GPIO_BIT(offset); |
563 | else | 762 | else |
564 | val &= ~GPIO_BIT(offset); | 763 | val &= ~GPIO_BIT(offset); |
565 | 764 | ||
566 | writel(val, gpio->base + bank->tolerance_regs); | 765 | writel(val, treg); |
766 | |||
767 | if (copro) | ||
768 | aspeed_gpio_copro_release(gpio, offset); | ||
567 | spin_unlock_irqrestore(&gpio->lock, flags); | 769 | spin_unlock_irqrestore(&gpio->lock, flags); |
568 | 770 | ||
569 | return 0; | 771 | return 0; |
@@ -582,13 +784,6 @@ static void aspeed_gpio_free(struct gpio_chip *chip, unsigned int offset) | |||
582 | pinctrl_gpio_free(chip->base + offset); | 784 | pinctrl_gpio_free(chip->base + offset); |
583 | } | 785 | } |
584 | 786 | ||
585 | static inline void __iomem *bank_debounce_reg(struct aspeed_gpio *gpio, | ||
586 | const struct aspeed_gpio_bank *bank, | ||
587 | unsigned int reg) | ||
588 | { | ||
589 | return gpio->base + bank->debounce_regs + reg; | ||
590 | } | ||
591 | |||
592 | static int usecs_to_cycles(struct aspeed_gpio *gpio, unsigned long usecs, | 787 | static int usecs_to_cycles(struct aspeed_gpio *gpio, unsigned long usecs, |
593 | u32 *cycles) | 788 | u32 *cycles) |
594 | { | 789 | { |
@@ -666,11 +861,14 @@ static void configure_timer(struct aspeed_gpio *gpio, unsigned int offset, | |||
666 | void __iomem *addr; | 861 | void __iomem *addr; |
667 | u32 val; | 862 | u32 val; |
668 | 863 | ||
669 | addr = bank_debounce_reg(gpio, bank, GPIO_DEBOUNCE_SEL1); | 864 | /* Note: Debounce timer isn't under control of the command |
865 | * source registers, so no need to sync with the coprocessor | ||
866 | */ | ||
867 | addr = bank_reg(gpio, bank, reg_debounce_sel1); | ||
670 | val = ioread32(addr); | 868 | val = ioread32(addr); |
671 | iowrite32((val & ~mask) | GPIO_SET_DEBOUNCE1(timer, offset), addr); | 869 | iowrite32((val & ~mask) | GPIO_SET_DEBOUNCE1(timer, offset), addr); |
672 | 870 | ||
673 | addr = bank_debounce_reg(gpio, bank, GPIO_DEBOUNCE_SEL2); | 871 | addr = bank_reg(gpio, bank, reg_debounce_sel2); |
674 | val = ioread32(addr); | 872 | val = ioread32(addr); |
675 | iowrite32((val & ~mask) | GPIO_SET_DEBOUNCE2(timer, offset), addr); | 873 | iowrite32((val & ~mask) | GPIO_SET_DEBOUNCE2(timer, offset), addr); |
676 | } | 874 | } |
@@ -812,6 +1010,111 @@ static int aspeed_gpio_set_config(struct gpio_chip *chip, unsigned int offset, | |||
812 | return -ENOTSUPP; | 1010 | return -ENOTSUPP; |
813 | } | 1011 | } |
814 | 1012 | ||
1013 | /** | ||
1014 | * aspeed_gpio_copro_set_ops - Sets the callbacks used for handhsaking with | ||
1015 | * the coprocessor for shared GPIO banks | ||
1016 | * @ops: The callbacks | ||
1017 | * @data: Pointer passed back to the callbacks | ||
1018 | */ | ||
1019 | int aspeed_gpio_copro_set_ops(const struct aspeed_gpio_copro_ops *ops, void *data) | ||
1020 | { | ||
1021 | copro_data = data; | ||
1022 | copro_ops = ops; | ||
1023 | |||
1024 | return 0; | ||
1025 | } | ||
1026 | EXPORT_SYMBOL_GPL(aspeed_gpio_copro_set_ops); | ||
1027 | |||
1028 | /** | ||
1029 | * aspeed_gpio_copro_grab_gpio - Mark a GPIO used by the coprocessor. The entire | ||
1030 | * bank gets marked and any access from the ARM will | ||
1031 | * result in handshaking via callbacks. | ||
1032 | * @desc: The GPIO to be marked | ||
1033 | * @vreg_offset: If non-NULL, returns the value register offset in the GPIO space | ||
1034 | * @dreg_offset: If non-NULL, returns the data latch register offset in the GPIO space | ||
1035 | * @bit: If non-NULL, returns the bit number of the GPIO in the registers | ||
1036 | */ | ||
1037 | int aspeed_gpio_copro_grab_gpio(struct gpio_desc *desc, | ||
1038 | u16 *vreg_offset, u16 *dreg_offset, u8 *bit) | ||
1039 | { | ||
1040 | struct gpio_chip *chip = gpiod_to_chip(desc); | ||
1041 | struct aspeed_gpio *gpio = gpiochip_get_data(chip); | ||
1042 | int rc = 0, bindex, offset = gpio_chip_hwgpio(desc); | ||
1043 | const struct aspeed_gpio_bank *bank = to_bank(offset); | ||
1044 | unsigned long flags; | ||
1045 | |||
1046 | if (!gpio->cf_copro_bankmap) | ||
1047 | gpio->cf_copro_bankmap = kzalloc(gpio->config->nr_gpios >> 3, GFP_KERNEL); | ||
1048 | if (!gpio->cf_copro_bankmap) | ||
1049 | return -ENOMEM; | ||
1050 | if (offset < 0 || offset > gpio->config->nr_gpios) | ||
1051 | return -EINVAL; | ||
1052 | bindex = offset >> 3; | ||
1053 | |||
1054 | spin_lock_irqsave(&gpio->lock, flags); | ||
1055 | |||
1056 | /* Sanity check, this shouldn't happen */ | ||
1057 | if (gpio->cf_copro_bankmap[bindex] == 0xff) { | ||
1058 | rc = -EIO; | ||
1059 | goto bail; | ||
1060 | } | ||
1061 | gpio->cf_copro_bankmap[bindex]++; | ||
1062 | |||
1063 | /* Switch command source */ | ||
1064 | if (gpio->cf_copro_bankmap[bindex] == 1) | ||
1065 | aspeed_gpio_change_cmd_source(gpio, bank, bindex, | ||
1066 | GPIO_CMDSRC_COLDFIRE); | ||
1067 | |||
1068 | if (vreg_offset) | ||
1069 | *vreg_offset = bank->val_regs; | ||
1070 | if (dreg_offset) | ||
1071 | *dreg_offset = bank->rdata_reg; | ||
1072 | if (bit) | ||
1073 | *bit = GPIO_OFFSET(offset); | ||
1074 | bail: | ||
1075 | spin_unlock_irqrestore(&gpio->lock, flags); | ||
1076 | return rc; | ||
1077 | } | ||
1078 | EXPORT_SYMBOL_GPL(aspeed_gpio_copro_grab_gpio); | ||
1079 | |||
1080 | /** | ||
1081 | * aspeed_gpio_copro_release_gpio - Unmark a GPIO used by the coprocessor. | ||
1082 | * @desc: The GPIO to be marked | ||
1083 | */ | ||
1084 | int aspeed_gpio_copro_release_gpio(struct gpio_desc *desc) | ||
1085 | { | ||
1086 | struct gpio_chip *chip = gpiod_to_chip(desc); | ||
1087 | struct aspeed_gpio *gpio = gpiochip_get_data(chip); | ||
1088 | int rc = 0, bindex, offset = gpio_chip_hwgpio(desc); | ||
1089 | const struct aspeed_gpio_bank *bank = to_bank(offset); | ||
1090 | unsigned long flags; | ||
1091 | |||
1092 | if (!gpio->cf_copro_bankmap) | ||
1093 | return -ENXIO; | ||
1094 | |||
1095 | if (offset < 0 || offset > gpio->config->nr_gpios) | ||
1096 | return -EINVAL; | ||
1097 | bindex = offset >> 3; | ||
1098 | |||
1099 | spin_lock_irqsave(&gpio->lock, flags); | ||
1100 | |||
1101 | /* Sanity check, this shouldn't happen */ | ||
1102 | if (gpio->cf_copro_bankmap[bindex] == 0) { | ||
1103 | rc = -EIO; | ||
1104 | goto bail; | ||
1105 | } | ||
1106 | gpio->cf_copro_bankmap[bindex]--; | ||
1107 | |||
1108 | /* Switch command source */ | ||
1109 | if (gpio->cf_copro_bankmap[bindex] == 0) | ||
1110 | aspeed_gpio_change_cmd_source(gpio, bank, bindex, | ||
1111 | GPIO_CMDSRC_ARM); | ||
1112 | bail: | ||
1113 | spin_unlock_irqrestore(&gpio->lock, flags); | ||
1114 | return rc; | ||
1115 | } | ||
1116 | EXPORT_SYMBOL_GPL(aspeed_gpio_copro_release_gpio); | ||
1117 | |||
815 | /* | 1118 | /* |
816 | * Any banks not specified in a struct aspeed_bank_props array are assumed to | 1119 | * Any banks not specified in a struct aspeed_bank_props array are assumed to |
817 | * have the properties: | 1120 | * have the properties: |
@@ -902,11 +1205,18 @@ static int __init aspeed_gpio_probe(struct platform_device *pdev) | |||
902 | if (!gpio->dcache) | 1205 | if (!gpio->dcache) |
903 | return -ENOMEM; | 1206 | return -ENOMEM; |
904 | 1207 | ||
905 | /* Populate it with initial values read from the HW */ | 1208 | /* |
1209 | * Populate it with initial values read from the HW and switch | ||
1210 | * all command sources to the ARM by default | ||
1211 | */ | ||
906 | for (i = 0; i < banks; i++) { | 1212 | for (i = 0; i < banks; i++) { |
907 | const struct aspeed_gpio_bank *bank = &aspeed_gpio_banks[i]; | 1213 | const struct aspeed_gpio_bank *bank = &aspeed_gpio_banks[i]; |
908 | gpio->dcache[i] = ioread32(gpio->base + bank->val_regs + | 1214 | void __iomem *addr = bank_reg(gpio, bank, reg_rdata); |
909 | GPIO_DATA); | 1215 | gpio->dcache[i] = ioread32(addr); |
1216 | aspeed_gpio_change_cmd_source(gpio, bank, 0, GPIO_CMDSRC_ARM); | ||
1217 | aspeed_gpio_change_cmd_source(gpio, bank, 1, GPIO_CMDSRC_ARM); | ||
1218 | aspeed_gpio_change_cmd_source(gpio, bank, 2, GPIO_CMDSRC_ARM); | ||
1219 | aspeed_gpio_change_cmd_source(gpio, bank, 3, GPIO_CMDSRC_ARM); | ||
910 | } | 1220 | } |
911 | 1221 | ||
912 | rc = devm_gpiochip_add_data(&pdev->dev, &gpio->chip, gpio); | 1222 | rc = devm_gpiochip_add_data(&pdev->dev, &gpio->chip, gpio); |
diff --git a/drivers/gpio/gpio-ath79.c b/drivers/gpio/gpio-ath79.c index 684e9d6d6623..0a553d676042 100644 --- a/drivers/gpio/gpio-ath79.c +++ b/drivers/gpio/gpio-ath79.c | |||
@@ -51,7 +51,7 @@ static u32 ath79_gpio_read(struct ath79_gpio_ctrl *ctrl, unsigned reg) | |||
51 | static void ath79_gpio_write(struct ath79_gpio_ctrl *ctrl, | 51 | static void ath79_gpio_write(struct ath79_gpio_ctrl *ctrl, |
52 | unsigned reg, u32 val) | 52 | unsigned reg, u32 val) |
53 | { | 53 | { |
54 | return writel(val, ctrl->base + reg); | 54 | writel(val, ctrl->base + reg); |
55 | } | 55 | } |
56 | 56 | ||
57 | static bool ath79_gpio_update_bits( | 57 | static bool ath79_gpio_update_bits( |
diff --git a/drivers/gpio/gpio-bcm-kona.c b/drivers/gpio/gpio-bcm-kona.c index 00272fa7cc4f..d0707fc23afd 100644 --- a/drivers/gpio/gpio-bcm-kona.c +++ b/drivers/gpio/gpio-bcm-kona.c | |||
@@ -485,12 +485,14 @@ static void bcm_kona_gpio_irq_handler(struct irq_desc *desc) | |||
485 | static int bcm_kona_gpio_irq_reqres(struct irq_data *d) | 485 | static int bcm_kona_gpio_irq_reqres(struct irq_data *d) |
486 | { | 486 | { |
487 | struct bcm_kona_gpio *kona_gpio = irq_data_get_irq_chip_data(d); | 487 | struct bcm_kona_gpio *kona_gpio = irq_data_get_irq_chip_data(d); |
488 | int ret; | ||
488 | 489 | ||
489 | if (gpiochip_lock_as_irq(&kona_gpio->gpio_chip, d->hwirq)) { | 490 | ret = gpiochip_lock_as_irq(&kona_gpio->gpio_chip, d->hwirq); |
491 | if (ret) { | ||
490 | dev_err(kona_gpio->gpio_chip.parent, | 492 | dev_err(kona_gpio->gpio_chip.parent, |
491 | "unable to lock HW IRQ %lu for IRQ\n", | 493 | "unable to lock HW IRQ %lu for IRQ\n", |
492 | d->hwirq); | 494 | d->hwirq); |
493 | return -EINVAL; | 495 | return ret; |
494 | } | 496 | } |
495 | return 0; | 497 | return 0; |
496 | } | 498 | } |
diff --git a/drivers/gpio/gpio-davinci.c b/drivers/gpio/gpio-davinci.c index 035a454eca43..a5ece8ea79bc 100644 --- a/drivers/gpio/gpio-davinci.c +++ b/drivers/gpio/gpio-davinci.c | |||
@@ -167,8 +167,8 @@ of_err: | |||
167 | static int davinci_gpio_probe(struct platform_device *pdev) | 167 | static int davinci_gpio_probe(struct platform_device *pdev) |
168 | { | 168 | { |
169 | static int ctrl_num, bank_base; | 169 | static int ctrl_num, bank_base; |
170 | int gpio, bank, ret = 0; | 170 | int gpio, bank, i, ret = 0; |
171 | unsigned ngpio, nbank; | 171 | unsigned int ngpio, nbank, nirq; |
172 | struct davinci_gpio_controller *chips; | 172 | struct davinci_gpio_controller *chips; |
173 | struct davinci_gpio_platform_data *pdata; | 173 | struct davinci_gpio_platform_data *pdata; |
174 | struct device *dev = &pdev->dev; | 174 | struct device *dev = &pdev->dev; |
@@ -197,6 +197,16 @@ static int davinci_gpio_probe(struct platform_device *pdev) | |||
197 | if (WARN_ON(ARCH_NR_GPIOS < ngpio)) | 197 | if (WARN_ON(ARCH_NR_GPIOS < ngpio)) |
198 | ngpio = ARCH_NR_GPIOS; | 198 | ngpio = ARCH_NR_GPIOS; |
199 | 199 | ||
200 | /* | ||
201 | * If there are unbanked interrupts then the number of | ||
202 | * interrupts is equal to number of gpios else all are banked so | ||
203 | * number of interrupts is equal to number of banks(each with 16 gpios) | ||
204 | */ | ||
205 | if (pdata->gpio_unbanked) | ||
206 | nirq = pdata->gpio_unbanked; | ||
207 | else | ||
208 | nirq = DIV_ROUND_UP(ngpio, 16); | ||
209 | |||
200 | nbank = DIV_ROUND_UP(ngpio, 32); | 210 | nbank = DIV_ROUND_UP(ngpio, 32); |
201 | chips = devm_kcalloc(dev, | 211 | chips = devm_kcalloc(dev, |
202 | nbank, sizeof(struct davinci_gpio_controller), | 212 | nbank, sizeof(struct davinci_gpio_controller), |
@@ -209,6 +219,15 @@ static int davinci_gpio_probe(struct platform_device *pdev) | |||
209 | if (IS_ERR(gpio_base)) | 219 | if (IS_ERR(gpio_base)) |
210 | return PTR_ERR(gpio_base); | 220 | return PTR_ERR(gpio_base); |
211 | 221 | ||
222 | for (i = 0; i < nirq; i++) { | ||
223 | chips->irqs[i] = platform_get_irq(pdev, i); | ||
224 | if (chips->irqs[i] < 0) { | ||
225 | dev_info(dev, "IRQ not populated, err = %d\n", | ||
226 | chips->irqs[i]); | ||
227 | return chips->irqs[i]; | ||
228 | } | ||
229 | } | ||
230 | |||
212 | snprintf(label, MAX_LABEL_SIZE, "davinci_gpio.%d", ctrl_num++); | 231 | snprintf(label, MAX_LABEL_SIZE, "davinci_gpio.%d", ctrl_num++); |
213 | chips->chip.label = devm_kstrdup(dev, label, GFP_KERNEL); | 232 | chips->chip.label = devm_kstrdup(dev, label, GFP_KERNEL); |
214 | if (!chips->chip.label) | 233 | if (!chips->chip.label) |
@@ -377,7 +396,7 @@ static int gpio_to_irq_unbanked(struct gpio_chip *chip, unsigned offset) | |||
377 | * can provide direct-mapped IRQs to AINTC (up to 32 GPIOs). | 396 | * can provide direct-mapped IRQs to AINTC (up to 32 GPIOs). |
378 | */ | 397 | */ |
379 | if (offset < d->gpio_unbanked) | 398 | if (offset < d->gpio_unbanked) |
380 | return d->base_irq + offset; | 399 | return d->irqs[offset]; |
381 | else | 400 | else |
382 | return -ENODEV; | 401 | return -ENODEV; |
383 | } | 402 | } |
@@ -386,11 +405,18 @@ static int gpio_irq_type_unbanked(struct irq_data *data, unsigned trigger) | |||
386 | { | 405 | { |
387 | struct davinci_gpio_controller *d; | 406 | struct davinci_gpio_controller *d; |
388 | struct davinci_gpio_regs __iomem *g; | 407 | struct davinci_gpio_regs __iomem *g; |
389 | u32 mask; | 408 | u32 mask, i; |
390 | 409 | ||
391 | d = (struct davinci_gpio_controller *)irq_data_get_irq_handler_data(data); | 410 | d = (struct davinci_gpio_controller *)irq_data_get_irq_handler_data(data); |
392 | g = (struct davinci_gpio_regs __iomem *)d->regs[0]; | 411 | g = (struct davinci_gpio_regs __iomem *)d->regs[0]; |
393 | mask = __gpio_mask(data->irq - d->base_irq); | 412 | for (i = 0; i < MAX_INT_PER_BANK; i++) |
413 | if (data->irq == d->irqs[i]) | ||
414 | break; | ||
415 | |||
416 | if (i == MAX_INT_PER_BANK) | ||
417 | return -EINVAL; | ||
418 | |||
419 | mask = __gpio_mask(i); | ||
394 | 420 | ||
395 | if (trigger & ~(IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING)) | 421 | if (trigger & ~(IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING)) |
396 | return -EINVAL; | 422 | return -EINVAL; |
@@ -459,9 +485,8 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev) | |||
459 | int ret; | 485 | int ret; |
460 | struct clk *clk; | 486 | struct clk *clk; |
461 | u32 binten = 0; | 487 | u32 binten = 0; |
462 | unsigned ngpio, bank_irq; | 488 | unsigned ngpio; |
463 | struct device *dev = &pdev->dev; | 489 | struct device *dev = &pdev->dev; |
464 | struct resource *res; | ||
465 | struct davinci_gpio_controller *chips = platform_get_drvdata(pdev); | 490 | struct davinci_gpio_controller *chips = platform_get_drvdata(pdev); |
466 | struct davinci_gpio_platform_data *pdata = dev->platform_data; | 491 | struct davinci_gpio_platform_data *pdata = dev->platform_data; |
467 | struct davinci_gpio_regs __iomem *g; | 492 | struct davinci_gpio_regs __iomem *g; |
@@ -481,24 +506,13 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev) | |||
481 | gpio_get_irq_chip = (gpio_get_irq_chip_cb_t)match->data; | 506 | gpio_get_irq_chip = (gpio_get_irq_chip_cb_t)match->data; |
482 | 507 | ||
483 | ngpio = pdata->ngpio; | 508 | ngpio = pdata->ngpio; |
484 | res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); | ||
485 | if (!res) { | ||
486 | dev_err(dev, "Invalid IRQ resource\n"); | ||
487 | return -EBUSY; | ||
488 | } | ||
489 | |||
490 | bank_irq = res->start; | ||
491 | |||
492 | if (!bank_irq) { | ||
493 | dev_err(dev, "Invalid IRQ resource\n"); | ||
494 | return -ENODEV; | ||
495 | } | ||
496 | 509 | ||
497 | clk = devm_clk_get(dev, "gpio"); | 510 | clk = devm_clk_get(dev, "gpio"); |
498 | if (IS_ERR(clk)) { | 511 | if (IS_ERR(clk)) { |
499 | dev_err(dev, "Error %ld getting gpio clock\n", PTR_ERR(clk)); | 512 | dev_err(dev, "Error %ld getting gpio clock\n", PTR_ERR(clk)); |
500 | return PTR_ERR(clk); | 513 | return PTR_ERR(clk); |
501 | } | 514 | } |
515 | |||
502 | ret = clk_prepare_enable(clk); | 516 | ret = clk_prepare_enable(clk); |
503 | if (ret) | 517 | if (ret) |
504 | return ret; | 518 | return ret; |
@@ -538,12 +552,11 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev) | |||
538 | if (pdata->gpio_unbanked) { | 552 | if (pdata->gpio_unbanked) { |
539 | /* pass "bank 0" GPIO IRQs to AINTC */ | 553 | /* pass "bank 0" GPIO IRQs to AINTC */ |
540 | chips->chip.to_irq = gpio_to_irq_unbanked; | 554 | chips->chip.to_irq = gpio_to_irq_unbanked; |
541 | chips->base_irq = bank_irq; | ||
542 | chips->gpio_unbanked = pdata->gpio_unbanked; | 555 | chips->gpio_unbanked = pdata->gpio_unbanked; |
543 | binten = GENMASK(pdata->gpio_unbanked / 16, 0); | 556 | binten = GENMASK(pdata->gpio_unbanked / 16, 0); |
544 | 557 | ||
545 | /* AINTC handles mask/unmask; GPIO handles triggering */ | 558 | /* AINTC handles mask/unmask; GPIO handles triggering */ |
546 | irq = bank_irq; | 559 | irq = chips->irqs[0]; |
547 | irq_chip = gpio_get_irq_chip(irq); | 560 | irq_chip = gpio_get_irq_chip(irq); |
548 | irq_chip->name = "GPIO-AINTC"; | 561 | irq_chip->name = "GPIO-AINTC"; |
549 | irq_chip->irq_set_type = gpio_irq_type_unbanked; | 562 | irq_chip->irq_set_type = gpio_irq_type_unbanked; |
@@ -554,10 +567,11 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev) | |||
554 | writel_relaxed(~0, &g->set_rising); | 567 | writel_relaxed(~0, &g->set_rising); |
555 | 568 | ||
556 | /* set the direct IRQs up to use that irqchip */ | 569 | /* set the direct IRQs up to use that irqchip */ |
557 | for (gpio = 0; gpio < pdata->gpio_unbanked; gpio++, irq++) { | 570 | for (gpio = 0; gpio < pdata->gpio_unbanked; gpio++) { |
558 | irq_set_chip(irq, irq_chip); | 571 | irq_set_chip(chips->irqs[gpio], irq_chip); |
559 | irq_set_handler_data(irq, chips); | 572 | irq_set_handler_data(chips->irqs[gpio], chips); |
560 | irq_set_status_flags(irq, IRQ_TYPE_EDGE_BOTH); | 573 | irq_set_status_flags(chips->irqs[gpio], |
574 | IRQ_TYPE_EDGE_BOTH); | ||
561 | } | 575 | } |
562 | 576 | ||
563 | goto done; | 577 | goto done; |
@@ -567,7 +581,7 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev) | |||
567 | * Or, AINTC can handle IRQs for banks of 16 GPIO IRQs, which we | 581 | * Or, AINTC can handle IRQs for banks of 16 GPIO IRQs, which we |
568 | * then chain through our own handler. | 582 | * then chain through our own handler. |
569 | */ | 583 | */ |
570 | for (gpio = 0, bank = 0; gpio < ngpio; bank++, bank_irq++, gpio += 16) { | 584 | for (gpio = 0, bank = 0; gpio < ngpio; bank++, gpio += 16) { |
571 | /* disabled by default, enabled only as needed | 585 | /* disabled by default, enabled only as needed |
572 | * There are register sets for 32 GPIOs. 2 banks of 16 | 586 | * There are register sets for 32 GPIOs. 2 banks of 16 |
573 | * GPIOs are covered by each set of registers hence divide by 2 | 587 | * GPIOs are covered by each set of registers hence divide by 2 |
@@ -594,8 +608,8 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev) | |||
594 | irqdata->bank_num = bank; | 608 | irqdata->bank_num = bank; |
595 | irqdata->chip = chips; | 609 | irqdata->chip = chips; |
596 | 610 | ||
597 | irq_set_chained_handler_and_data(bank_irq, gpio_irq_handler, | 611 | irq_set_chained_handler_and_data(chips->irqs[bank], |
598 | irqdata); | 612 | gpio_irq_handler, irqdata); |
599 | 613 | ||
600 | binten |= BIT(bank); | 614 | binten |= BIT(bank); |
601 | } | 615 | } |
diff --git a/drivers/gpio/gpio-dwapb.c b/drivers/gpio/gpio-dwapb.c index 7a2de3de6571..28da700f5f52 100644 --- a/drivers/gpio/gpio-dwapb.c +++ b/drivers/gpio/gpio-dwapb.c | |||
@@ -255,11 +255,13 @@ static int dwapb_irq_reqres(struct irq_data *d) | |||
255 | struct irq_chip_generic *igc = irq_data_get_irq_chip_data(d); | 255 | struct irq_chip_generic *igc = irq_data_get_irq_chip_data(d); |
256 | struct dwapb_gpio *gpio = igc->private; | 256 | struct dwapb_gpio *gpio = igc->private; |
257 | struct gpio_chip *gc = &gpio->ports[0].gc; | 257 | struct gpio_chip *gc = &gpio->ports[0].gc; |
258 | int ret; | ||
258 | 259 | ||
259 | if (gpiochip_lock_as_irq(gc, irqd_to_hwirq(d))) { | 260 | ret = gpiochip_lock_as_irq(gc, irqd_to_hwirq(d)); |
261 | if (ret) { | ||
260 | dev_err(gpio->dev, "unable to lock HW IRQ %lu for IRQ\n", | 262 | dev_err(gpio->dev, "unable to lock HW IRQ %lu for IRQ\n", |
261 | irqd_to_hwirq(d)); | 263 | irqd_to_hwirq(d)); |
262 | return -EINVAL; | 264 | return ret; |
263 | } | 265 | } |
264 | return 0; | 266 | return 0; |
265 | } | 267 | } |
diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c index 2b466b80e70a..982e699a5b81 100644 --- a/drivers/gpio/gpio-em.c +++ b/drivers/gpio/gpio-em.c | |||
@@ -101,12 +101,14 @@ static void em_gio_irq_enable(struct irq_data *d) | |||
101 | static int em_gio_irq_reqres(struct irq_data *d) | 101 | static int em_gio_irq_reqres(struct irq_data *d) |
102 | { | 102 | { |
103 | struct em_gio_priv *p = irq_data_get_irq_chip_data(d); | 103 | struct em_gio_priv *p = irq_data_get_irq_chip_data(d); |
104 | int ret; | ||
104 | 105 | ||
105 | if (gpiochip_lock_as_irq(&p->gpio_chip, irqd_to_hwirq(d))) { | 106 | ret = gpiochip_lock_as_irq(&p->gpio_chip, irqd_to_hwirq(d)); |
107 | if (ret) { | ||
106 | dev_err(p->gpio_chip.parent, | 108 | dev_err(p->gpio_chip.parent, |
107 | "unable to lock HW IRQ %lu for IRQ\n", | 109 | "unable to lock HW IRQ %lu for IRQ\n", |
108 | irqd_to_hwirq(d)); | 110 | irqd_to_hwirq(d)); |
109 | return -EINVAL; | 111 | return ret; |
110 | } | 112 | } |
111 | return 0; | 113 | return 0; |
112 | } | 114 | } |
diff --git a/drivers/gpio/gpio-it87.c b/drivers/gpio/gpio-it87.c index 7cad14d3f127..389ecd8b7d26 100644 --- a/drivers/gpio/gpio-it87.c +++ b/drivers/gpio/gpio-it87.c | |||
@@ -35,12 +35,15 @@ | |||
35 | 35 | ||
36 | /* Chip Id numbers */ | 36 | /* Chip Id numbers */ |
37 | #define NO_DEV_ID 0xffff | 37 | #define NO_DEV_ID 0xffff |
38 | #define IT8613_ID 0x8613 | ||
38 | #define IT8620_ID 0x8620 | 39 | #define IT8620_ID 0x8620 |
39 | #define IT8628_ID 0x8628 | 40 | #define IT8628_ID 0x8628 |
41 | #define IT8718_ID 0x8718 | ||
40 | #define IT8728_ID 0x8728 | 42 | #define IT8728_ID 0x8728 |
41 | #define IT8732_ID 0x8732 | 43 | #define IT8732_ID 0x8732 |
42 | #define IT8761_ID 0x8761 | 44 | #define IT8761_ID 0x8761 |
43 | #define IT8772_ID 0x8772 | 45 | #define IT8772_ID 0x8772 |
46 | #define IT8786_ID 0x8786 | ||
44 | 47 | ||
45 | /* IO Ports */ | 48 | /* IO Ports */ |
46 | #define REG 0x2e | 49 | #define REG 0x2e |
@@ -306,6 +309,14 @@ static int __init it87_gpio_init(void) | |||
306 | it87_gpio->chip = it87_template_chip; | 309 | it87_gpio->chip = it87_template_chip; |
307 | 310 | ||
308 | switch (chip_type) { | 311 | switch (chip_type) { |
312 | case IT8613_ID: | ||
313 | gpio_ba_reg = 0x62; | ||
314 | it87_gpio->io_size = 8; /* it8613 only needs 6, use 8 for alignment */ | ||
315 | it87_gpio->output_base = 0xc8; | ||
316 | it87_gpio->simple_base = 0xc0; | ||
317 | it87_gpio->simple_size = 6; | ||
318 | it87_gpio->chip.ngpio = 64; /* has 48, use 64 for convenient calc */ | ||
319 | break; | ||
309 | case IT8620_ID: | 320 | case IT8620_ID: |
310 | case IT8628_ID: | 321 | case IT8628_ID: |
311 | gpio_ba_reg = 0x62; | 322 | gpio_ba_reg = 0x62; |
@@ -314,9 +325,11 @@ static int __init it87_gpio_init(void) | |||
314 | it87_gpio->simple_size = 0; | 325 | it87_gpio->simple_size = 0; |
315 | it87_gpio->chip.ngpio = 64; | 326 | it87_gpio->chip.ngpio = 64; |
316 | break; | 327 | break; |
328 | case IT8718_ID: | ||
317 | case IT8728_ID: | 329 | case IT8728_ID: |
318 | case IT8732_ID: | 330 | case IT8732_ID: |
319 | case IT8772_ID: | 331 | case IT8772_ID: |
332 | case IT8786_ID: | ||
320 | gpio_ba_reg = 0x62; | 333 | gpio_ba_reg = 0x62; |
321 | it87_gpio->io_size = 8; | 334 | it87_gpio->io_size = 8; |
322 | it87_gpio->output_base = 0xc8; | 335 | it87_gpio->output_base = 0xc8; |
diff --git a/drivers/gpio/gpio-max732x.c b/drivers/gpio/gpio-max732x.c index 9d8bcc69f245..f03cb0ba7726 100644 --- a/drivers/gpio/gpio-max732x.c +++ b/drivers/gpio/gpio-max732x.c | |||
@@ -653,6 +653,12 @@ static int max732x_probe(struct i2c_client *client, | |||
653 | chip->client_group_a = client; | 653 | chip->client_group_a = client; |
654 | if (nr_port > 8) { | 654 | if (nr_port > 8) { |
655 | c = i2c_new_dummy(client->adapter, addr_b); | 655 | c = i2c_new_dummy(client->adapter, addr_b); |
656 | if (!c) { | ||
657 | dev_err(&client->dev, | ||
658 | "Failed to allocate I2C device\n"); | ||
659 | ret = -ENODEV; | ||
660 | goto out_failed; | ||
661 | } | ||
656 | chip->client_group_b = chip->client_dummy = c; | 662 | chip->client_group_b = chip->client_dummy = c; |
657 | } | 663 | } |
658 | break; | 664 | break; |
@@ -660,6 +666,12 @@ static int max732x_probe(struct i2c_client *client, | |||
660 | chip->client_group_b = client; | 666 | chip->client_group_b = client; |
661 | if (nr_port > 8) { | 667 | if (nr_port > 8) { |
662 | c = i2c_new_dummy(client->adapter, addr_a); | 668 | c = i2c_new_dummy(client->adapter, addr_a); |
669 | if (!c) { | ||
670 | dev_err(&client->dev, | ||
671 | "Failed to allocate I2C device\n"); | ||
672 | ret = -ENODEV; | ||
673 | goto out_failed; | ||
674 | } | ||
663 | chip->client_group_a = chip->client_dummy = c; | 675 | chip->client_group_a = chip->client_dummy = c; |
664 | } | 676 | } |
665 | break; | 677 | break; |
diff --git a/drivers/gpio/gpio-menz127.c b/drivers/gpio/gpio-menz127.c index e1037582e34d..b2635326546e 100644 --- a/drivers/gpio/gpio-menz127.c +++ b/drivers/gpio/gpio-menz127.c | |||
@@ -56,9 +56,9 @@ static int men_z127_debounce(struct gpio_chip *gc, unsigned gpio, | |||
56 | rnd = fls(debounce) - 1; | 56 | rnd = fls(debounce) - 1; |
57 | 57 | ||
58 | if (rnd && (debounce & BIT(rnd - 1))) | 58 | if (rnd && (debounce & BIT(rnd - 1))) |
59 | debounce = round_up(debounce, MEN_Z127_DB_MIN_US); | 59 | debounce = roundup(debounce, MEN_Z127_DB_MIN_US); |
60 | else | 60 | else |
61 | debounce = round_down(debounce, MEN_Z127_DB_MIN_US); | 61 | debounce = rounddown(debounce, MEN_Z127_DB_MIN_US); |
62 | 62 | ||
63 | if (debounce > MEN_Z127_DB_MAX_US) | 63 | if (debounce > MEN_Z127_DB_MAX_US) |
64 | debounce = MEN_Z127_DB_MAX_US; | 64 | debounce = MEN_Z127_DB_MAX_US; |
diff --git a/drivers/gpio/gpio-ml-ioh.c b/drivers/gpio/gpio-ml-ioh.c index b23d9a36be1f..51c7d1b84c2e 100644 --- a/drivers/gpio/gpio-ml-ioh.c +++ b/drivers/gpio/gpio-ml-ioh.c | |||
@@ -496,9 +496,10 @@ static int ioh_gpio_probe(struct pci_dev *pdev, | |||
496 | return 0; | 496 | return 0; |
497 | 497 | ||
498 | err_gpiochip_add: | 498 | err_gpiochip_add: |
499 | chip = chip_save; | ||
499 | while (--i >= 0) { | 500 | while (--i >= 0) { |
500 | chip--; | ||
501 | gpiochip_remove(&chip->gpio); | 501 | gpiochip_remove(&chip->gpio); |
502 | chip++; | ||
502 | } | 503 | } |
503 | kfree(chip_save); | 504 | kfree(chip_save); |
504 | 505 | ||
diff --git a/drivers/gpio/gpio-mmio.c b/drivers/gpio/gpio-mmio.c index 7b14d6280e44..935292a30c99 100644 --- a/drivers/gpio/gpio-mmio.c +++ b/drivers/gpio/gpio-mmio.c | |||
@@ -136,8 +136,20 @@ static unsigned long bgpio_line2mask(struct gpio_chip *gc, unsigned int line) | |||
136 | static int bgpio_get_set(struct gpio_chip *gc, unsigned int gpio) | 136 | static int bgpio_get_set(struct gpio_chip *gc, unsigned int gpio) |
137 | { | 137 | { |
138 | unsigned long pinmask = bgpio_line2mask(gc, gpio); | 138 | unsigned long pinmask = bgpio_line2mask(gc, gpio); |
139 | bool dir = !!(gc->bgpio_dir & pinmask); | ||
139 | 140 | ||
140 | if (gc->bgpio_dir & pinmask) | 141 | /* |
142 | * If the direction is OUT we read the value from the SET | ||
143 | * register, and if the direction is IN we read the value | ||
144 | * from the DAT register. | ||
145 | * | ||
146 | * If the direction bits are inverted, naturally this gets | ||
147 | * inverted too. | ||
148 | */ | ||
149 | if (gc->bgpio_dir_inverted) | ||
150 | dir = !dir; | ||
151 | |||
152 | if (dir) | ||
141 | return !!(gc->read_reg(gc->reg_set) & pinmask); | 153 | return !!(gc->read_reg(gc->reg_set) & pinmask); |
142 | else | 154 | else |
143 | return !!(gc->read_reg(gc->reg_dat) & pinmask); | 155 | return !!(gc->read_reg(gc->reg_dat) & pinmask); |
@@ -157,8 +169,13 @@ static int bgpio_get_set_multiple(struct gpio_chip *gc, unsigned long *mask, | |||
157 | *bits &= ~*mask; | 169 | *bits &= ~*mask; |
158 | 170 | ||
159 | /* Exploit the fact that we know which directions are set */ | 171 | /* Exploit the fact that we know which directions are set */ |
160 | set_mask = *mask & gc->bgpio_dir; | 172 | if (gc->bgpio_dir_inverted) { |
161 | get_mask = *mask & ~gc->bgpio_dir; | 173 | set_mask = *mask & ~gc->bgpio_dir; |
174 | get_mask = *mask & gc->bgpio_dir; | ||
175 | } else { | ||
176 | set_mask = *mask & gc->bgpio_dir; | ||
177 | get_mask = *mask & ~gc->bgpio_dir; | ||
178 | } | ||
162 | 179 | ||
163 | if (set_mask) | 180 | if (set_mask) |
164 | *bits |= gc->read_reg(gc->reg_set) & set_mask; | 181 | *bits |= gc->read_reg(gc->reg_set) & set_mask; |
@@ -359,7 +376,10 @@ static int bgpio_dir_in(struct gpio_chip *gc, unsigned int gpio) | |||
359 | 376 | ||
360 | spin_lock_irqsave(&gc->bgpio_lock, flags); | 377 | spin_lock_irqsave(&gc->bgpio_lock, flags); |
361 | 378 | ||
362 | gc->bgpio_dir &= ~bgpio_line2mask(gc, gpio); | 379 | if (gc->bgpio_dir_inverted) |
380 | gc->bgpio_dir |= bgpio_line2mask(gc, gpio); | ||
381 | else | ||
382 | gc->bgpio_dir &= ~bgpio_line2mask(gc, gpio); | ||
363 | gc->write_reg(gc->reg_dir, gc->bgpio_dir); | 383 | gc->write_reg(gc->reg_dir, gc->bgpio_dir); |
364 | 384 | ||
365 | spin_unlock_irqrestore(&gc->bgpio_lock, flags); | 385 | spin_unlock_irqrestore(&gc->bgpio_lock, flags); |
@@ -370,7 +390,10 @@ static int bgpio_dir_in(struct gpio_chip *gc, unsigned int gpio) | |||
370 | static int bgpio_get_dir(struct gpio_chip *gc, unsigned int gpio) | 390 | static int bgpio_get_dir(struct gpio_chip *gc, unsigned int gpio) |
371 | { | 391 | { |
372 | /* Return 0 if output, 1 of input */ | 392 | /* Return 0 if output, 1 of input */ |
373 | return !(gc->read_reg(gc->reg_dir) & bgpio_line2mask(gc, gpio)); | 393 | if (gc->bgpio_dir_inverted) |
394 | return !!(gc->read_reg(gc->reg_dir) & bgpio_line2mask(gc, gpio)); | ||
395 | else | ||
396 | return !(gc->read_reg(gc->reg_dir) & bgpio_line2mask(gc, gpio)); | ||
374 | } | 397 | } |
375 | 398 | ||
376 | static int bgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val) | 399 | static int bgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val) |
@@ -381,37 +404,10 @@ static int bgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val) | |||
381 | 404 | ||
382 | spin_lock_irqsave(&gc->bgpio_lock, flags); | 405 | spin_lock_irqsave(&gc->bgpio_lock, flags); |
383 | 406 | ||
384 | gc->bgpio_dir |= bgpio_line2mask(gc, gpio); | 407 | if (gc->bgpio_dir_inverted) |
385 | gc->write_reg(gc->reg_dir, gc->bgpio_dir); | 408 | gc->bgpio_dir &= ~bgpio_line2mask(gc, gpio); |
386 | 409 | else | |
387 | spin_unlock_irqrestore(&gc->bgpio_lock, flags); | 410 | gc->bgpio_dir |= bgpio_line2mask(gc, gpio); |
388 | |||
389 | return 0; | ||
390 | } | ||
391 | |||
392 | static int bgpio_dir_in_inv(struct gpio_chip *gc, unsigned int gpio) | ||
393 | { | ||
394 | unsigned long flags; | ||
395 | |||
396 | spin_lock_irqsave(&gc->bgpio_lock, flags); | ||
397 | |||
398 | gc->bgpio_dir |= bgpio_line2mask(gc, gpio); | ||
399 | gc->write_reg(gc->reg_dir, gc->bgpio_dir); | ||
400 | |||
401 | spin_unlock_irqrestore(&gc->bgpio_lock, flags); | ||
402 | |||
403 | return 0; | ||
404 | } | ||
405 | |||
406 | static int bgpio_dir_out_inv(struct gpio_chip *gc, unsigned int gpio, int val) | ||
407 | { | ||
408 | unsigned long flags; | ||
409 | |||
410 | gc->set(gc, gpio, val); | ||
411 | |||
412 | spin_lock_irqsave(&gc->bgpio_lock, flags); | ||
413 | |||
414 | gc->bgpio_dir &= ~bgpio_line2mask(gc, gpio); | ||
415 | gc->write_reg(gc->reg_dir, gc->bgpio_dir); | 411 | gc->write_reg(gc->reg_dir, gc->bgpio_dir); |
416 | 412 | ||
417 | spin_unlock_irqrestore(&gc->bgpio_lock, flags); | 413 | spin_unlock_irqrestore(&gc->bgpio_lock, flags); |
@@ -419,12 +415,6 @@ static int bgpio_dir_out_inv(struct gpio_chip *gc, unsigned int gpio, int val) | |||
419 | return 0; | 415 | return 0; |
420 | } | 416 | } |
421 | 417 | ||
422 | static int bgpio_get_dir_inv(struct gpio_chip *gc, unsigned int gpio) | ||
423 | { | ||
424 | /* Return 0 if output, 1 if input */ | ||
425 | return !!(gc->read_reg(gc->reg_dir) & bgpio_line2mask(gc, gpio)); | ||
426 | } | ||
427 | |||
428 | static int bgpio_setup_accessors(struct device *dev, | 418 | static int bgpio_setup_accessors(struct device *dev, |
429 | struct gpio_chip *gc, | 419 | struct gpio_chip *gc, |
430 | bool byte_be) | 420 | bool byte_be) |
@@ -560,9 +550,10 @@ static int bgpio_setup_direction(struct gpio_chip *gc, | |||
560 | gc->get_direction = bgpio_get_dir; | 550 | gc->get_direction = bgpio_get_dir; |
561 | } else if (dirin) { | 551 | } else if (dirin) { |
562 | gc->reg_dir = dirin; | 552 | gc->reg_dir = dirin; |
563 | gc->direction_output = bgpio_dir_out_inv; | 553 | gc->direction_output = bgpio_dir_out; |
564 | gc->direction_input = bgpio_dir_in_inv; | 554 | gc->direction_input = bgpio_dir_in; |
565 | gc->get_direction = bgpio_get_dir_inv; | 555 | gc->get_direction = bgpio_get_dir; |
556 | gc->bgpio_dir_inverted = true; | ||
566 | } else { | 557 | } else { |
567 | if (flags & BGPIOF_NO_OUTPUT) | 558 | if (flags & BGPIOF_NO_OUTPUT) |
568 | gc->direction_output = bgpio_dir_out_err; | 559 | gc->direction_output = bgpio_dir_out_err; |
@@ -582,6 +573,33 @@ static int bgpio_request(struct gpio_chip *chip, unsigned gpio_pin) | |||
582 | return -EINVAL; | 573 | return -EINVAL; |
583 | } | 574 | } |
584 | 575 | ||
576 | /** | ||
577 | * bgpio_init() - Initialize generic GPIO accessor functions | ||
578 | * @gc: the GPIO chip to set up | ||
579 | * @dev: the parent device of the new GPIO chip (compulsory) | ||
580 | * @sz: the size (width) of the MMIO registers in bytes, typically 1, 2 or 4 | ||
581 | * @dat: MMIO address for the register to READ the value of the GPIO lines, it | ||
582 | * is expected that a 1 in the corresponding bit in this register means the | ||
583 | * line is asserted | ||
584 | * @set: MMIO address for the register to SET the value of the GPIO lines, it is | ||
585 | * expected that we write the line with 1 in this register to drive the GPIO line | ||
586 | * high. | ||
587 | * @clr: MMIO address for the register to CLEAR the value of the GPIO lines, it is | ||
588 | * expected that we write the line with 1 in this register to drive the GPIO line | ||
589 | * low. It is allowed to leave this address as NULL, in that case the SET register | ||
590 | * will be assumed to also clear the GPIO lines, by actively writing the line | ||
591 | * with 0. | ||
592 | * @dirout: MMIO address for the register to set the line as OUTPUT. It is assumed | ||
593 | * that setting a line to 1 in this register will turn that line into an | ||
594 | * output line. Conversely, setting the line to 0 will turn that line into | ||
595 | * an input. Either this or @dirin can be defined, but never both. | ||
596 | * @dirin: MMIO address for the register to set this line as INPUT. It is assumed | ||
597 | * that setting a line to 1 in this register will turn that line into an | ||
598 | * input line. Conversely, setting the line to 0 will turn that line into | ||
599 | * an output. Either this or @dirout can be defined, but never both. | ||
600 | * @flags: Different flags that will affect the behaviour of the device, such as | ||
601 | * endianness etc. | ||
602 | */ | ||
585 | int bgpio_init(struct gpio_chip *gc, struct device *dev, | 603 | int bgpio_init(struct gpio_chip *gc, struct device *dev, |
586 | unsigned long sz, void __iomem *dat, void __iomem *set, | 604 | unsigned long sz, void __iomem *dat, void __iomem *set, |
587 | void __iomem *clr, void __iomem *dirout, void __iomem *dirin, | 605 | void __iomem *clr, void __iomem *dirout, void __iomem *dirin, |
diff --git a/drivers/gpio/gpio-mt7621.c b/drivers/gpio/gpio-mt7621.c new file mode 100644 index 000000000000..d72af6f6cdbd --- /dev/null +++ b/drivers/gpio/gpio-mt7621.c | |||
@@ -0,0 +1,332 @@ | |||
1 | // SPDX-License-Identifier: GPL-2.0 | ||
2 | /* | ||
3 | * Copyright (C) 2009-2011 Gabor Juhos <juhosg@openwrt.org> | ||
4 | * Copyright (C) 2013 John Crispin <blogic@openwrt.org> | ||
5 | */ | ||
6 | |||
7 | #include <linux/err.h> | ||
8 | #include <linux/gpio/driver.h> | ||
9 | #include <linux/interrupt.h> | ||
10 | #include <linux/io.h> | ||
11 | #include <linux/module.h> | ||
12 | #include <linux/of_irq.h> | ||
13 | #include <linux/platform_device.h> | ||
14 | #include <linux/spinlock.h> | ||
15 | |||
16 | #define MTK_BANK_CNT 3 | ||
17 | #define MTK_BANK_WIDTH 32 | ||
18 | |||
19 | #define GPIO_BANK_STRIDE 0x04 | ||
20 | #define GPIO_REG_CTRL 0x00 | ||
21 | #define GPIO_REG_POL 0x10 | ||
22 | #define GPIO_REG_DATA 0x20 | ||
23 | #define GPIO_REG_DSET 0x30 | ||
24 | #define GPIO_REG_DCLR 0x40 | ||
25 | #define GPIO_REG_REDGE 0x50 | ||
26 | #define GPIO_REG_FEDGE 0x60 | ||
27 | #define GPIO_REG_HLVL 0x70 | ||
28 | #define GPIO_REG_LLVL 0x80 | ||
29 | #define GPIO_REG_STAT 0x90 | ||
30 | #define GPIO_REG_EDGE 0xA0 | ||
31 | |||
32 | struct mtk_gc { | ||
33 | struct gpio_chip chip; | ||
34 | spinlock_t lock; | ||
35 | int bank; | ||
36 | u32 rising; | ||
37 | u32 falling; | ||
38 | u32 hlevel; | ||
39 | u32 llevel; | ||
40 | }; | ||
41 | |||
42 | /** | ||
43 | * struct mtk - state container for | ||
44 | * data of the platform driver. It is 3 | ||
45 | * separate gpio-chip each one with its | ||
46 | * own irq_chip. | ||
47 | * @dev: device instance | ||
48 | * @base: memory base address | ||
49 | * @gpio_irq: irq number from the device tree | ||
50 | * @gc_map: array of the gpio chips | ||
51 | */ | ||
52 | struct mtk { | ||
53 | struct device *dev; | ||
54 | void __iomem *base; | ||
55 | int gpio_irq; | ||
56 | struct mtk_gc gc_map[MTK_BANK_CNT]; | ||
57 | }; | ||
58 | |||
59 | static inline struct mtk_gc * | ||
60 | to_mediatek_gpio(struct gpio_chip *chip) | ||
61 | { | ||
62 | return container_of(chip, struct mtk_gc, chip); | ||
63 | } | ||
64 | |||
65 | static inline void | ||
66 | mtk_gpio_w32(struct mtk_gc *rg, u32 offset, u32 val) | ||
67 | { | ||
68 | struct gpio_chip *gc = &rg->chip; | ||
69 | struct mtk *mtk = gpiochip_get_data(gc); | ||
70 | |||
71 | offset = (rg->bank * GPIO_BANK_STRIDE) + offset; | ||
72 | gc->write_reg(mtk->base + offset, val); | ||
73 | } | ||
74 | |||
75 | static inline u32 | ||
76 | mtk_gpio_r32(struct mtk_gc *rg, u32 offset) | ||
77 | { | ||
78 | struct gpio_chip *gc = &rg->chip; | ||
79 | struct mtk *mtk = gpiochip_get_data(gc); | ||
80 | |||
81 | offset = (rg->bank * GPIO_BANK_STRIDE) + offset; | ||
82 | return gc->read_reg(mtk->base + offset); | ||
83 | } | ||
84 | |||
85 | static irqreturn_t | ||
86 | mediatek_gpio_irq_handler(int irq, void *data) | ||
87 | { | ||
88 | struct gpio_chip *gc = data; | ||
89 | struct mtk_gc *rg = to_mediatek_gpio(gc); | ||
90 | irqreturn_t ret = IRQ_NONE; | ||
91 | unsigned long pending; | ||
92 | int bit; | ||
93 | |||
94 | pending = mtk_gpio_r32(rg, GPIO_REG_STAT); | ||
95 | |||
96 | for_each_set_bit(bit, &pending, MTK_BANK_WIDTH) { | ||
97 | u32 map = irq_find_mapping(gc->irq.domain, bit); | ||
98 | |||
99 | generic_handle_irq(map); | ||
100 | mtk_gpio_w32(rg, GPIO_REG_STAT, BIT(bit)); | ||
101 | ret |= IRQ_HANDLED; | ||
102 | } | ||
103 | |||
104 | return ret; | ||
105 | } | ||
106 | |||
107 | static void | ||
108 | mediatek_gpio_irq_unmask(struct irq_data *d) | ||
109 | { | ||
110 | struct gpio_chip *gc = irq_data_get_irq_chip_data(d); | ||
111 | struct mtk_gc *rg = to_mediatek_gpio(gc); | ||
112 | int pin = d->hwirq; | ||
113 | unsigned long flags; | ||
114 | u32 rise, fall, high, low; | ||
115 | |||
116 | spin_lock_irqsave(&rg->lock, flags); | ||
117 | rise = mtk_gpio_r32(rg, GPIO_REG_REDGE); | ||
118 | fall = mtk_gpio_r32(rg, GPIO_REG_FEDGE); | ||
119 | high = mtk_gpio_r32(rg, GPIO_REG_HLVL); | ||
120 | low = mtk_gpio_r32(rg, GPIO_REG_LLVL); | ||
121 | mtk_gpio_w32(rg, GPIO_REG_REDGE, rise | (BIT(pin) & rg->rising)); | ||
122 | mtk_gpio_w32(rg, GPIO_REG_FEDGE, fall | (BIT(pin) & rg->falling)); | ||
123 | mtk_gpio_w32(rg, GPIO_REG_HLVL, high | (BIT(pin) & rg->hlevel)); | ||
124 | mtk_gpio_w32(rg, GPIO_REG_LLVL, low | (BIT(pin) & rg->llevel)); | ||
125 | spin_unlock_irqrestore(&rg->lock, flags); | ||
126 | } | ||
127 | |||
128 | static void | ||
129 | mediatek_gpio_irq_mask(struct irq_data *d) | ||
130 | { | ||
131 | struct gpio_chip *gc = irq_data_get_irq_chip_data(d); | ||
132 | struct mtk_gc *rg = to_mediatek_gpio(gc); | ||
133 | int pin = d->hwirq; | ||
134 | unsigned long flags; | ||
135 | u32 rise, fall, high, low; | ||
136 | |||
137 | spin_lock_irqsave(&rg->lock, flags); | ||
138 | rise = mtk_gpio_r32(rg, GPIO_REG_REDGE); | ||
139 | fall = mtk_gpio_r32(rg, GPIO_REG_FEDGE); | ||
140 | high = mtk_gpio_r32(rg, GPIO_REG_HLVL); | ||
141 | low = mtk_gpio_r32(rg, GPIO_REG_LLVL); | ||
142 | mtk_gpio_w32(rg, GPIO_REG_FEDGE, fall & ~BIT(pin)); | ||
143 | mtk_gpio_w32(rg, GPIO_REG_REDGE, rise & ~BIT(pin)); | ||
144 | mtk_gpio_w32(rg, GPIO_REG_HLVL, high & ~BIT(pin)); | ||
145 | mtk_gpio_w32(rg, GPIO_REG_LLVL, low & ~BIT(pin)); | ||
146 | spin_unlock_irqrestore(&rg->lock, flags); | ||
147 | } | ||
148 | |||
149 | static int | ||
150 | mediatek_gpio_irq_type(struct irq_data *d, unsigned int type) | ||
151 | { | ||
152 | struct gpio_chip *gc = irq_data_get_irq_chip_data(d); | ||
153 | struct mtk_gc *rg = to_mediatek_gpio(gc); | ||
154 | int pin = d->hwirq; | ||
155 | u32 mask = BIT(pin); | ||
156 | |||
157 | if (type == IRQ_TYPE_PROBE) { | ||
158 | if ((rg->rising | rg->falling | | ||
159 | rg->hlevel | rg->llevel) & mask) | ||
160 | return 0; | ||
161 | |||
162 | type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING; | ||
163 | } | ||
164 | |||
165 | rg->rising &= ~mask; | ||
166 | rg->falling &= ~mask; | ||
167 | rg->hlevel &= ~mask; | ||
168 | rg->llevel &= ~mask; | ||
169 | |||
170 | switch (type & IRQ_TYPE_SENSE_MASK) { | ||
171 | case IRQ_TYPE_EDGE_BOTH: | ||
172 | rg->rising |= mask; | ||
173 | rg->falling |= mask; | ||
174 | break; | ||
175 | case IRQ_TYPE_EDGE_RISING: | ||
176 | rg->rising |= mask; | ||
177 | break; | ||
178 | case IRQ_TYPE_EDGE_FALLING: | ||
179 | rg->falling |= mask; | ||
180 | break; | ||
181 | case IRQ_TYPE_LEVEL_HIGH: | ||
182 | rg->hlevel |= mask; | ||
183 | break; | ||
184 | case IRQ_TYPE_LEVEL_LOW: | ||
185 | rg->llevel |= mask; | ||
186 | break; | ||
187 | } | ||
188 | |||
189 | return 0; | ||
190 | } | ||
191 | |||
192 | static struct irq_chip mediatek_gpio_irq_chip = { | ||
193 | .irq_unmask = mediatek_gpio_irq_unmask, | ||
194 | .irq_mask = mediatek_gpio_irq_mask, | ||
195 | .irq_mask_ack = mediatek_gpio_irq_mask, | ||
196 | .irq_set_type = mediatek_gpio_irq_type, | ||
197 | }; | ||
198 | |||
199 | static int | ||
200 | mediatek_gpio_xlate(struct gpio_chip *chip, | ||
201 | const struct of_phandle_args *spec, u32 *flags) | ||
202 | { | ||
203 | int gpio = spec->args[0]; | ||
204 | struct mtk_gc *rg = to_mediatek_gpio(chip); | ||
205 | |||
206 | if (rg->bank != gpio / MTK_BANK_WIDTH) | ||
207 | return -EINVAL; | ||
208 | |||
209 | if (flags) | ||
210 | *flags = spec->args[1]; | ||
211 | |||
212 | return gpio % MTK_BANK_WIDTH; | ||
213 | } | ||
214 | |||
215 | static int | ||
216 | mediatek_gpio_bank_probe(struct device *dev, | ||
217 | struct device_node *node, int bank) | ||
218 | { | ||
219 | struct mtk *mtk = dev_get_drvdata(dev); | ||
220 | struct mtk_gc *rg; | ||
221 | void __iomem *dat, *set, *ctrl, *diro; | ||
222 | int ret; | ||
223 | |||
224 | rg = &mtk->gc_map[bank]; | ||
225 | memset(rg, 0, sizeof(*rg)); | ||
226 | |||
227 | spin_lock_init(&rg->lock); | ||
228 | rg->chip.of_node = node; | ||
229 | rg->bank = bank; | ||
230 | |||
231 | dat = mtk->base + GPIO_REG_DATA + (rg->bank * GPIO_BANK_STRIDE); | ||
232 | set = mtk->base + GPIO_REG_DSET + (rg->bank * GPIO_BANK_STRIDE); | ||
233 | ctrl = mtk->base + GPIO_REG_DCLR + (rg->bank * GPIO_BANK_STRIDE); | ||
234 | diro = mtk->base + GPIO_REG_CTRL + (rg->bank * GPIO_BANK_STRIDE); | ||
235 | |||
236 | ret = bgpio_init(&rg->chip, dev, 4, | ||
237 | dat, set, ctrl, diro, NULL, 0); | ||
238 | if (ret) { | ||
239 | dev_err(dev, "bgpio_init() failed\n"); | ||
240 | return ret; | ||
241 | } | ||
242 | |||
243 | rg->chip.of_gpio_n_cells = 2; | ||
244 | rg->chip.of_xlate = mediatek_gpio_xlate; | ||
245 | rg->chip.label = devm_kasprintf(dev, GFP_KERNEL, "%s-bank%d", | ||
246 | dev_name(dev), bank); | ||
247 | |||
248 | ret = devm_gpiochip_add_data(dev, &rg->chip, mtk); | ||
249 | if (ret < 0) { | ||
250 | dev_err(dev, "Could not register gpio %d, ret=%d\n", | ||
251 | rg->chip.ngpio, ret); | ||
252 | return ret; | ||
253 | } | ||
254 | |||
255 | if (mtk->gpio_irq) { | ||
256 | /* | ||
257 | * Manually request the irq here instead of passing | ||
258 | * a flow-handler to gpiochip_set_chained_irqchip, | ||
259 | * because the irq is shared. | ||
260 | */ | ||
261 | ret = devm_request_irq(dev, mtk->gpio_irq, | ||
262 | mediatek_gpio_irq_handler, IRQF_SHARED, | ||
263 | rg->chip.label, &rg->chip); | ||
264 | |||
265 | if (ret) { | ||
266 | dev_err(dev, "Error requesting IRQ %d: %d\n", | ||
267 | mtk->gpio_irq, ret); | ||
268 | return ret; | ||
269 | } | ||
270 | |||
271 | ret = gpiochip_irqchip_add(&rg->chip, &mediatek_gpio_irq_chip, | ||
272 | 0, handle_simple_irq, IRQ_TYPE_NONE); | ||
273 | if (ret) { | ||
274 | dev_err(dev, "failed to add gpiochip_irqchip\n"); | ||
275 | return ret; | ||
276 | } | ||
277 | |||
278 | gpiochip_set_chained_irqchip(&rg->chip, &mediatek_gpio_irq_chip, | ||
279 | mtk->gpio_irq, NULL); | ||
280 | } | ||
281 | |||
282 | /* set polarity to low for all gpios */ | ||
283 | mtk_gpio_w32(rg, GPIO_REG_POL, 0); | ||
284 | |||
285 | dev_info(dev, "registering %d gpios\n", rg->chip.ngpio); | ||
286 | |||
287 | return 0; | ||
288 | } | ||
289 | |||
290 | static int | ||
291 | mediatek_gpio_probe(struct platform_device *pdev) | ||
292 | { | ||
293 | struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
294 | struct device *dev = &pdev->dev; | ||
295 | struct device_node *np = dev->of_node; | ||
296 | struct mtk *mtk; | ||
297 | int i; | ||
298 | |||
299 | mtk = devm_kzalloc(dev, sizeof(*mtk), GFP_KERNEL); | ||
300 | if (!mtk) | ||
301 | return -ENOMEM; | ||
302 | |||
303 | mtk->base = devm_ioremap_resource(dev, res); | ||
304 | if (IS_ERR(mtk->base)) | ||
305 | return PTR_ERR(mtk->base); | ||
306 | |||
307 | mtk->gpio_irq = irq_of_parse_and_map(np, 0); | ||
308 | mtk->dev = dev; | ||
309 | platform_set_drvdata(pdev, mtk); | ||
310 | mediatek_gpio_irq_chip.name = dev_name(dev); | ||
311 | |||
312 | for (i = 0; i < MTK_BANK_CNT; i++) | ||
313 | mediatek_gpio_bank_probe(dev, np, i); | ||
314 | |||
315 | return 0; | ||
316 | } | ||
317 | |||
318 | static const struct of_device_id mediatek_gpio_match[] = { | ||
319 | { .compatible = "mediatek,mt7621-gpio" }, | ||
320 | {}, | ||
321 | }; | ||
322 | MODULE_DEVICE_TABLE(of, mediatek_gpio_match); | ||
323 | |||
324 | static struct platform_driver mediatek_gpio_driver = { | ||
325 | .probe = mediatek_gpio_probe, | ||
326 | .driver = { | ||
327 | .name = "mt7621_gpio", | ||
328 | .of_match_table = mediatek_gpio_match, | ||
329 | }, | ||
330 | }; | ||
331 | |||
332 | builtin_platform_driver(mediatek_gpio_driver); | ||
diff --git a/drivers/gpio/gpio-mxc.c b/drivers/gpio/gpio-mxc.c index 2f2829966d4c..995cf0b9e0b1 100644 --- a/drivers/gpio/gpio-mxc.c +++ b/drivers/gpio/gpio-mxc.c | |||
@@ -45,6 +45,15 @@ struct mxc_gpio_hwdata { | |||
45 | unsigned fall_edge; | 45 | unsigned fall_edge; |
46 | }; | 46 | }; |
47 | 47 | ||
48 | struct mxc_gpio_reg_saved { | ||
49 | u32 icr1; | ||
50 | u32 icr2; | ||
51 | u32 imr; | ||
52 | u32 gdir; | ||
53 | u32 edge_sel; | ||
54 | u32 dr; | ||
55 | }; | ||
56 | |||
48 | struct mxc_gpio_port { | 57 | struct mxc_gpio_port { |
49 | struct list_head node; | 58 | struct list_head node; |
50 | void __iomem *base; | 59 | void __iomem *base; |
@@ -55,6 +64,8 @@ struct mxc_gpio_port { | |||
55 | struct gpio_chip gc; | 64 | struct gpio_chip gc; |
56 | struct device *dev; | 65 | struct device *dev; |
57 | u32 both_edges; | 66 | u32 both_edges; |
67 | struct mxc_gpio_reg_saved gpio_saved_reg; | ||
68 | bool power_off; | ||
58 | }; | 69 | }; |
59 | 70 | ||
60 | static struct mxc_gpio_hwdata imx1_imx21_gpio_hwdata = { | 71 | static struct mxc_gpio_hwdata imx1_imx21_gpio_hwdata = { |
@@ -143,6 +154,7 @@ static const struct of_device_id mxc_gpio_dt_ids[] = { | |||
143 | { .compatible = "fsl,imx21-gpio", .data = &mxc_gpio_devtype[IMX21_GPIO], }, | 154 | { .compatible = "fsl,imx21-gpio", .data = &mxc_gpio_devtype[IMX21_GPIO], }, |
144 | { .compatible = "fsl,imx31-gpio", .data = &mxc_gpio_devtype[IMX31_GPIO], }, | 155 | { .compatible = "fsl,imx31-gpio", .data = &mxc_gpio_devtype[IMX31_GPIO], }, |
145 | { .compatible = "fsl,imx35-gpio", .data = &mxc_gpio_devtype[IMX35_GPIO], }, | 156 | { .compatible = "fsl,imx35-gpio", .data = &mxc_gpio_devtype[IMX35_GPIO], }, |
157 | { .compatible = "fsl,imx7d-gpio", .data = &mxc_gpio_devtype[IMX35_GPIO], }, | ||
146 | { /* sentinel */ } | 158 | { /* sentinel */ } |
147 | }; | 159 | }; |
148 | 160 | ||
@@ -434,6 +446,9 @@ static int mxc_gpio_probe(struct platform_device *pdev) | |||
434 | return err; | 446 | return err; |
435 | } | 447 | } |
436 | 448 | ||
449 | if (of_device_is_compatible(np, "fsl,imx7d-gpio")) | ||
450 | port->power_off = true; | ||
451 | |||
437 | /* disable the interrupt and clear the status */ | 452 | /* disable the interrupt and clear the status */ |
438 | writel(0, port->base + GPIO_IMR); | 453 | writel(0, port->base + GPIO_IMR); |
439 | writel(~0, port->base + GPIO_ISR); | 454 | writel(~0, port->base + GPIO_ISR); |
@@ -497,6 +512,8 @@ static int mxc_gpio_probe(struct platform_device *pdev) | |||
497 | 512 | ||
498 | list_add_tail(&port->node, &mxc_gpio_ports); | 513 | list_add_tail(&port->node, &mxc_gpio_ports); |
499 | 514 | ||
515 | platform_set_drvdata(pdev, port); | ||
516 | |||
500 | return 0; | 517 | return 0; |
501 | 518 | ||
502 | out_irqdomain_remove: | 519 | out_irqdomain_remove: |
@@ -507,11 +524,67 @@ out_bgio: | |||
507 | return err; | 524 | return err; |
508 | } | 525 | } |
509 | 526 | ||
527 | static void mxc_gpio_save_regs(struct mxc_gpio_port *port) | ||
528 | { | ||
529 | if (!port->power_off) | ||
530 | return; | ||
531 | |||
532 | port->gpio_saved_reg.icr1 = readl(port->base + GPIO_ICR1); | ||
533 | port->gpio_saved_reg.icr2 = readl(port->base + GPIO_ICR2); | ||
534 | port->gpio_saved_reg.imr = readl(port->base + GPIO_IMR); | ||
535 | port->gpio_saved_reg.gdir = readl(port->base + GPIO_GDIR); | ||
536 | port->gpio_saved_reg.edge_sel = readl(port->base + GPIO_EDGE_SEL); | ||
537 | port->gpio_saved_reg.dr = readl(port->base + GPIO_DR); | ||
538 | } | ||
539 | |||
540 | static void mxc_gpio_restore_regs(struct mxc_gpio_port *port) | ||
541 | { | ||
542 | if (!port->power_off) | ||
543 | return; | ||
544 | |||
545 | writel(port->gpio_saved_reg.icr1, port->base + GPIO_ICR1); | ||
546 | writel(port->gpio_saved_reg.icr2, port->base + GPIO_ICR2); | ||
547 | writel(port->gpio_saved_reg.imr, port->base + GPIO_IMR); | ||
548 | writel(port->gpio_saved_reg.gdir, port->base + GPIO_GDIR); | ||
549 | writel(port->gpio_saved_reg.edge_sel, port->base + GPIO_EDGE_SEL); | ||
550 | writel(port->gpio_saved_reg.dr, port->base + GPIO_DR); | ||
551 | } | ||
552 | |||
553 | static int __maybe_unused mxc_gpio_noirq_suspend(struct device *dev) | ||
554 | { | ||
555 | struct platform_device *pdev = to_platform_device(dev); | ||
556 | struct mxc_gpio_port *port = platform_get_drvdata(pdev); | ||
557 | |||
558 | mxc_gpio_save_regs(port); | ||
559 | clk_disable_unprepare(port->clk); | ||
560 | |||
561 | return 0; | ||
562 | } | ||
563 | |||
564 | static int __maybe_unused mxc_gpio_noirq_resume(struct device *dev) | ||
565 | { | ||
566 | struct platform_device *pdev = to_platform_device(dev); | ||
567 | struct mxc_gpio_port *port = platform_get_drvdata(pdev); | ||
568 | int ret; | ||
569 | |||
570 | ret = clk_prepare_enable(port->clk); | ||
571 | if (ret) | ||
572 | return ret; | ||
573 | mxc_gpio_restore_regs(port); | ||
574 | |||
575 | return 0; | ||
576 | } | ||
577 | |||
578 | static const struct dev_pm_ops mxc_gpio_dev_pm_ops = { | ||
579 | SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(mxc_gpio_noirq_suspend, mxc_gpio_noirq_resume) | ||
580 | }; | ||
581 | |||
510 | static struct platform_driver mxc_gpio_driver = { | 582 | static struct platform_driver mxc_gpio_driver = { |
511 | .driver = { | 583 | .driver = { |
512 | .name = "gpio-mxc", | 584 | .name = "gpio-mxc", |
513 | .of_match_table = mxc_gpio_dt_ids, | 585 | .of_match_table = mxc_gpio_dt_ids, |
514 | .suppress_bind_attrs = true, | 586 | .suppress_bind_attrs = true, |
587 | .pm = &mxc_gpio_dev_pm_ops, | ||
515 | }, | 588 | }, |
516 | .probe = mxc_gpio_probe, | 589 | .probe = mxc_gpio_probe, |
517 | .id_table = mxc_gpio_devtype, | 590 | .id_table = mxc_gpio_devtype, |
diff --git a/drivers/gpio/gpio-mxs.c b/drivers/gpio/gpio-mxs.c index e2831ee70cdc..df30490da820 100644 --- a/drivers/gpio/gpio-mxs.c +++ b/drivers/gpio/gpio-mxs.c | |||
@@ -126,8 +126,7 @@ static int mxs_gpio_set_irq_type(struct irq_data *d, unsigned int type) | |||
126 | else | 126 | else |
127 | writel(pin_mask, pin_addr + MXS_CLR); | 127 | writel(pin_mask, pin_addr + MXS_CLR); |
128 | 128 | ||
129 | writel(pin_mask, | 129 | writel(pin_mask, port->base + PINCTRL_IRQSTAT(port) + MXS_CLR); |
130 | port->base + PINCTRL_IRQSTAT(port) + MXS_CLR); | ||
131 | 130 | ||
132 | return 0; | 131 | return 0; |
133 | } | 132 | } |
diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c index d1afedf4dcbf..e81008678a38 100644 --- a/drivers/gpio/gpio-omap.c +++ b/drivers/gpio/gpio-omap.c | |||
@@ -77,6 +77,8 @@ struct gpio_bank { | |||
77 | bool workaround_enabled; | 77 | bool workaround_enabled; |
78 | 78 | ||
79 | void (*set_dataout)(struct gpio_bank *bank, unsigned gpio, int enable); | 79 | void (*set_dataout)(struct gpio_bank *bank, unsigned gpio, int enable); |
80 | void (*set_dataout_multiple)(struct gpio_bank *bank, | ||
81 | unsigned long *mask, unsigned long *bits); | ||
80 | int (*get_context_loss_count)(struct device *dev); | 82 | int (*get_context_loss_count)(struct device *dev); |
81 | 83 | ||
82 | struct omap_gpio_reg_offs *regs; | 84 | struct omap_gpio_reg_offs *regs; |
@@ -161,6 +163,51 @@ static int omap_get_gpio_dataout(struct gpio_bank *bank, int offset) | |||
161 | return (readl_relaxed(reg) & (BIT(offset))) != 0; | 163 | return (readl_relaxed(reg) & (BIT(offset))) != 0; |
162 | } | 164 | } |
163 | 165 | ||
166 | /* set multiple data out values using dedicate set/clear register */ | ||
167 | static void omap_set_gpio_dataout_reg_multiple(struct gpio_bank *bank, | ||
168 | unsigned long *mask, | ||
169 | unsigned long *bits) | ||
170 | { | ||
171 | void __iomem *reg = bank->base; | ||
172 | u32 l; | ||
173 | |||
174 | l = *bits & *mask; | ||
175 | writel_relaxed(l, reg + bank->regs->set_dataout); | ||
176 | bank->context.dataout |= l; | ||
177 | |||
178 | l = ~*bits & *mask; | ||
179 | writel_relaxed(l, reg + bank->regs->clr_dataout); | ||
180 | bank->context.dataout &= ~l; | ||
181 | } | ||
182 | |||
183 | /* set multiple data out values using mask register */ | ||
184 | static void omap_set_gpio_dataout_mask_multiple(struct gpio_bank *bank, | ||
185 | unsigned long *mask, | ||
186 | unsigned long *bits) | ||
187 | { | ||
188 | void __iomem *reg = bank->base + bank->regs->dataout; | ||
189 | u32 l = (readl_relaxed(reg) & ~*mask) | (*bits & *mask); | ||
190 | |||
191 | writel_relaxed(l, reg); | ||
192 | bank->context.dataout = l; | ||
193 | } | ||
194 | |||
195 | static unsigned long omap_get_gpio_datain_multiple(struct gpio_bank *bank, | ||
196 | unsigned long *mask) | ||
197 | { | ||
198 | void __iomem *reg = bank->base + bank->regs->datain; | ||
199 | |||
200 | return readl_relaxed(reg) & *mask; | ||
201 | } | ||
202 | |||
203 | static unsigned long omap_get_gpio_dataout_multiple(struct gpio_bank *bank, | ||
204 | unsigned long *mask) | ||
205 | { | ||
206 | void __iomem *reg = bank->base + bank->regs->dataout; | ||
207 | |||
208 | return readl_relaxed(reg) & *mask; | ||
209 | } | ||
210 | |||
164 | static inline void omap_gpio_rmw(void __iomem *base, u32 reg, u32 mask, bool set) | 211 | static inline void omap_gpio_rmw(void __iomem *base, u32 reg, u32 mask, bool set) |
165 | { | 212 | { |
166 | int l = readl_relaxed(base + reg); | 213 | int l = readl_relaxed(base + reg); |
@@ -968,6 +1015,26 @@ static int omap_gpio_output(struct gpio_chip *chip, unsigned offset, int value) | |||
968 | return 0; | 1015 | return 0; |
969 | } | 1016 | } |
970 | 1017 | ||
1018 | static int omap_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask, | ||
1019 | unsigned long *bits) | ||
1020 | { | ||
1021 | struct gpio_bank *bank = gpiochip_get_data(chip); | ||
1022 | void __iomem *reg = bank->base + bank->regs->direction; | ||
1023 | unsigned long in = readl_relaxed(reg), l; | ||
1024 | |||
1025 | *bits = 0; | ||
1026 | |||
1027 | l = in & *mask; | ||
1028 | if (l) | ||
1029 | *bits |= omap_get_gpio_datain_multiple(bank, &l); | ||
1030 | |||
1031 | l = ~in & *mask; | ||
1032 | if (l) | ||
1033 | *bits |= omap_get_gpio_dataout_multiple(bank, &l); | ||
1034 | |||
1035 | return 0; | ||
1036 | } | ||
1037 | |||
971 | static int omap_gpio_debounce(struct gpio_chip *chip, unsigned offset, | 1038 | static int omap_gpio_debounce(struct gpio_chip *chip, unsigned offset, |
972 | unsigned debounce) | 1039 | unsigned debounce) |
973 | { | 1040 | { |
@@ -1012,6 +1079,17 @@ static void omap_gpio_set(struct gpio_chip *chip, unsigned offset, int value) | |||
1012 | raw_spin_unlock_irqrestore(&bank->lock, flags); | 1079 | raw_spin_unlock_irqrestore(&bank->lock, flags); |
1013 | } | 1080 | } |
1014 | 1081 | ||
1082 | static void omap_gpio_set_multiple(struct gpio_chip *chip, unsigned long *mask, | ||
1083 | unsigned long *bits) | ||
1084 | { | ||
1085 | struct gpio_bank *bank = gpiochip_get_data(chip); | ||
1086 | unsigned long flags; | ||
1087 | |||
1088 | raw_spin_lock_irqsave(&bank->lock, flags); | ||
1089 | bank->set_dataout_multiple(bank, mask, bits); | ||
1090 | raw_spin_unlock_irqrestore(&bank->lock, flags); | ||
1091 | } | ||
1092 | |||
1015 | /*---------------------------------------------------------------------*/ | 1093 | /*---------------------------------------------------------------------*/ |
1016 | 1094 | ||
1017 | static void omap_gpio_show_rev(struct gpio_bank *bank) | 1095 | static void omap_gpio_show_rev(struct gpio_bank *bank) |
@@ -1073,9 +1151,11 @@ static int omap_gpio_chip_init(struct gpio_bank *bank, struct irq_chip *irqc) | |||
1073 | bank->chip.get_direction = omap_gpio_get_direction; | 1151 | bank->chip.get_direction = omap_gpio_get_direction; |
1074 | bank->chip.direction_input = omap_gpio_input; | 1152 | bank->chip.direction_input = omap_gpio_input; |
1075 | bank->chip.get = omap_gpio_get; | 1153 | bank->chip.get = omap_gpio_get; |
1154 | bank->chip.get_multiple = omap_gpio_get_multiple; | ||
1076 | bank->chip.direction_output = omap_gpio_output; | 1155 | bank->chip.direction_output = omap_gpio_output; |
1077 | bank->chip.set_config = omap_gpio_set_config; | 1156 | bank->chip.set_config = omap_gpio_set_config; |
1078 | bank->chip.set = omap_gpio_set; | 1157 | bank->chip.set = omap_gpio_set; |
1158 | bank->chip.set_multiple = omap_gpio_set_multiple; | ||
1079 | if (bank->is_mpuio) { | 1159 | if (bank->is_mpuio) { |
1080 | bank->chip.label = "mpuio"; | 1160 | bank->chip.label = "mpuio"; |
1081 | if (bank->regs->wkup_en) | 1161 | if (bank->regs->wkup_en) |
@@ -1209,10 +1289,14 @@ static int omap_gpio_probe(struct platform_device *pdev) | |||
1209 | pdata->get_context_loss_count; | 1289 | pdata->get_context_loss_count; |
1210 | } | 1290 | } |
1211 | 1291 | ||
1212 | if (bank->regs->set_dataout && bank->regs->clr_dataout) | 1292 | if (bank->regs->set_dataout && bank->regs->clr_dataout) { |
1213 | bank->set_dataout = omap_set_gpio_dataout_reg; | 1293 | bank->set_dataout = omap_set_gpio_dataout_reg; |
1214 | else | 1294 | bank->set_dataout_multiple = omap_set_gpio_dataout_reg_multiple; |
1295 | } else { | ||
1215 | bank->set_dataout = omap_set_gpio_dataout_mask; | 1296 | bank->set_dataout = omap_set_gpio_dataout_mask; |
1297 | bank->set_dataout_multiple = | ||
1298 | omap_set_gpio_dataout_mask_multiple; | ||
1299 | } | ||
1216 | 1300 | ||
1217 | raw_spin_lock_init(&bank->lock); | 1301 | raw_spin_lock_init(&bank->lock); |
1218 | raw_spin_lock_init(&bank->wa_lock); | 1302 | raw_spin_lock_init(&bank->wa_lock); |
diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c index c55ad157e820..023a32cfac42 100644 --- a/drivers/gpio/gpio-pca953x.c +++ b/drivers/gpio/gpio-pca953x.c | |||
@@ -708,7 +708,7 @@ static int pca953x_irq_setup(struct pca953x_chip *chip, | |||
708 | { | 708 | { |
709 | struct i2c_client *client = chip->client; | 709 | struct i2c_client *client = chip->client; |
710 | 710 | ||
711 | if (irq_base != -1 && (chip->driver_data & PCA_INT)) | 711 | if (client->irq && irq_base != -1 && (chip->driver_data & PCA_INT)) |
712 | dev_warn(&client->dev, "interrupt support not compiled in\n"); | 712 | dev_warn(&client->dev, "interrupt support not compiled in\n"); |
713 | 713 | ||
714 | return 0; | 714 | return 0; |
diff --git a/drivers/gpio/gpio-pisosr.c b/drivers/gpio/gpio-pisosr.c index f5545049c187..f809a5a8e9eb 100644 --- a/drivers/gpio/gpio-pisosr.c +++ b/drivers/gpio/gpio-pisosr.c | |||
@@ -12,6 +12,8 @@ | |||
12 | * GNU General Public License version 2 for more details. | 12 | * GNU General Public License version 2 for more details. |
13 | */ | 13 | */ |
14 | 14 | ||
15 | #include <linux/bitmap.h> | ||
16 | #include <linux/bitops.h> | ||
15 | #include <linux/delay.h> | 17 | #include <linux/delay.h> |
16 | #include <linux/gpio/consumer.h> | 18 | #include <linux/gpio/consumer.h> |
17 | #include <linux/gpio/driver.h> | 19 | #include <linux/gpio/driver.h> |
@@ -90,6 +92,25 @@ static int pisosr_gpio_get(struct gpio_chip *chip, unsigned offset) | |||
90 | return (gpio->buffer[offset / 8] >> (offset % 8)) & 0x1; | 92 | return (gpio->buffer[offset / 8] >> (offset % 8)) & 0x1; |
91 | } | 93 | } |
92 | 94 | ||
95 | static int pisosr_gpio_get_multiple(struct gpio_chip *chip, | ||
96 | unsigned long *mask, unsigned long *bits) | ||
97 | { | ||
98 | struct pisosr_gpio *gpio = gpiochip_get_data(chip); | ||
99 | unsigned int nbytes = DIV_ROUND_UP(chip->ngpio, 8); | ||
100 | unsigned int i, j; | ||
101 | |||
102 | pisosr_gpio_refresh(gpio); | ||
103 | |||
104 | bitmap_zero(bits, chip->ngpio); | ||
105 | for (i = 0; i < nbytes; i++) { | ||
106 | j = i / sizeof(unsigned long); | ||
107 | bits[j] |= ((unsigned long) gpio->buffer[i]) | ||
108 | << (8 * (i % sizeof(unsigned long))); | ||
109 | } | ||
110 | |||
111 | return 0; | ||
112 | } | ||
113 | |||
93 | static const struct gpio_chip template_chip = { | 114 | static const struct gpio_chip template_chip = { |
94 | .label = "pisosr-gpio", | 115 | .label = "pisosr-gpio", |
95 | .owner = THIS_MODULE, | 116 | .owner = THIS_MODULE, |
@@ -97,6 +118,7 @@ static const struct gpio_chip template_chip = { | |||
97 | .direction_input = pisosr_gpio_direction_input, | 118 | .direction_input = pisosr_gpio_direction_input, |
98 | .direction_output = pisosr_gpio_direction_output, | 119 | .direction_output = pisosr_gpio_direction_output, |
99 | .get = pisosr_gpio_get, | 120 | .get = pisosr_gpio_get, |
121 | .get_multiple = pisosr_gpio_get_multiple, | ||
100 | .base = -1, | 122 | .base = -1, |
101 | .ngpio = DEFAULT_NGPIO, | 123 | .ngpio = DEFAULT_NGPIO, |
102 | .can_sleep = true, | 124 | .can_sleep = true, |
diff --git a/drivers/gpio/gpio-pxa.c b/drivers/gpio/gpio-pxa.c index 1e66f808051c..c18712dabf93 100644 --- a/drivers/gpio/gpio-pxa.c +++ b/drivers/gpio/gpio-pxa.c | |||
@@ -241,6 +241,17 @@ int pxa_irq_to_gpio(int irq) | |||
241 | return irq_gpio0; | 241 | return irq_gpio0; |
242 | } | 242 | } |
243 | 243 | ||
244 | static bool pxa_gpio_has_pinctrl(void) | ||
245 | { | ||
246 | switch (gpio_type) { | ||
247 | case PXA3XX_GPIO: | ||
248 | return false; | ||
249 | |||
250 | default: | ||
251 | return true; | ||
252 | } | ||
253 | } | ||
254 | |||
244 | static int pxa_gpio_to_irq(struct gpio_chip *chip, unsigned offset) | 255 | static int pxa_gpio_to_irq(struct gpio_chip *chip, unsigned offset) |
245 | { | 256 | { |
246 | struct pxa_gpio_chip *pchip = chip_to_pxachip(chip); | 257 | struct pxa_gpio_chip *pchip = chip_to_pxachip(chip); |
@@ -255,9 +266,11 @@ static int pxa_gpio_direction_input(struct gpio_chip *chip, unsigned offset) | |||
255 | unsigned long flags; | 266 | unsigned long flags; |
256 | int ret; | 267 | int ret; |
257 | 268 | ||
258 | ret = pinctrl_gpio_direction_input(chip->base + offset); | 269 | if (pxa_gpio_has_pinctrl()) { |
259 | if (!ret) | 270 | ret = pinctrl_gpio_direction_input(chip->base + offset); |
260 | return 0; | 271 | if (!ret) |
272 | return 0; | ||
273 | } | ||
261 | 274 | ||
262 | spin_lock_irqsave(&gpio_lock, flags); | 275 | spin_lock_irqsave(&gpio_lock, flags); |
263 | 276 | ||
@@ -282,9 +295,11 @@ static int pxa_gpio_direction_output(struct gpio_chip *chip, | |||
282 | 295 | ||
283 | writel_relaxed(mask, base + (value ? GPSR_OFFSET : GPCR_OFFSET)); | 296 | writel_relaxed(mask, base + (value ? GPSR_OFFSET : GPCR_OFFSET)); |
284 | 297 | ||
285 | ret = pinctrl_gpio_direction_output(chip->base + offset); | 298 | if (pxa_gpio_has_pinctrl()) { |
286 | if (ret) | 299 | ret = pinctrl_gpio_direction_output(chip->base + offset); |
287 | return ret; | 300 | if (ret) |
301 | return ret; | ||
302 | } | ||
288 | 303 | ||
289 | spin_lock_irqsave(&gpio_lock, flags); | 304 | spin_lock_irqsave(&gpio_lock, flags); |
290 | 305 | ||
@@ -348,8 +363,12 @@ static int pxa_init_gpio_chip(struct pxa_gpio_chip *pchip, int ngpio, | |||
348 | pchip->chip.set = pxa_gpio_set; | 363 | pchip->chip.set = pxa_gpio_set; |
349 | pchip->chip.to_irq = pxa_gpio_to_irq; | 364 | pchip->chip.to_irq = pxa_gpio_to_irq; |
350 | pchip->chip.ngpio = ngpio; | 365 | pchip->chip.ngpio = ngpio; |
351 | pchip->chip.request = gpiochip_generic_request; | 366 | |
352 | pchip->chip.free = gpiochip_generic_free; | 367 | if (pxa_gpio_has_pinctrl()) { |
368 | pchip->chip.request = gpiochip_generic_request; | ||
369 | pchip->chip.free = gpiochip_generic_free; | ||
370 | } | ||
371 | |||
353 | #ifdef CONFIG_OF_GPIO | 372 | #ifdef CONFIG_OF_GPIO |
354 | pchip->chip.of_node = np; | 373 | pchip->chip.of_node = np; |
355 | pchip->chip.of_xlate = pxa_gpio_of_xlate; | 374 | pchip->chip.of_xlate = pxa_gpio_of_xlate; |
@@ -607,7 +626,7 @@ static int pxa_gpio_probe(struct platform_device *pdev) | |||
607 | struct pxa_gpio_platform_data *info; | 626 | struct pxa_gpio_platform_data *info; |
608 | void __iomem *gpio_reg_base; | 627 | void __iomem *gpio_reg_base; |
609 | int gpio, ret; | 628 | int gpio, ret; |
610 | int irq0 = 0, irq1 = 0, irq_mux, gpio_offset = 0; | 629 | int irq0 = 0, irq1 = 0, irq_mux; |
611 | 630 | ||
612 | pchip = devm_kzalloc(&pdev->dev, sizeof(*pchip), GFP_KERNEL); | 631 | pchip = devm_kzalloc(&pdev->dev, sizeof(*pchip), GFP_KERNEL); |
613 | if (!pchip) | 632 | if (!pchip) |
@@ -646,14 +665,13 @@ static int pxa_gpio_probe(struct platform_device *pdev) | |||
646 | pchip->irq0 = irq0; | 665 | pchip->irq0 = irq0; |
647 | pchip->irq1 = irq1; | 666 | pchip->irq1 = irq1; |
648 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 667 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
668 | if (!res) | ||
669 | return -EINVAL; | ||
649 | gpio_reg_base = devm_ioremap(&pdev->dev, res->start, | 670 | gpio_reg_base = devm_ioremap(&pdev->dev, res->start, |
650 | resource_size(res)); | 671 | resource_size(res)); |
651 | if (!gpio_reg_base) | 672 | if (!gpio_reg_base) |
652 | return -EINVAL; | 673 | return -EINVAL; |
653 | 674 | ||
654 | if (irq0 > 0) | ||
655 | gpio_offset = 2; | ||
656 | |||
657 | clk = clk_get(&pdev->dev, NULL); | 675 | clk = clk_get(&pdev->dev, NULL); |
658 | if (IS_ERR(clk)) { | 676 | if (IS_ERR(clk)) { |
659 | dev_err(&pdev->dev, "Error %ld to get gpio clock\n", | 677 | dev_err(&pdev->dev, "Error %ld to get gpio clock\n", |
diff --git a/drivers/gpio/gpio-rc5t583.c b/drivers/gpio/gpio-rc5t583.c index 3b4dc1a9a68d..a499c633a6c5 100644 --- a/drivers/gpio/gpio-rc5t583.c +++ b/drivers/gpio/gpio-rc5t583.c | |||
@@ -25,7 +25,7 @@ | |||
25 | #include <linux/slab.h> | 25 | #include <linux/slab.h> |
26 | #include <linux/platform_device.h> | 26 | #include <linux/platform_device.h> |
27 | #include <linux/device.h> | 27 | #include <linux/device.h> |
28 | #include <linux/gpio.h> | 28 | #include <linux/gpio/driver.h> |
29 | #include <linux/mfd/rc5t583.h> | 29 | #include <linux/mfd/rc5t583.h> |
30 | 30 | ||
31 | struct rc5t583_gpio { | 31 | struct rc5t583_gpio { |
diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c index 350390c0b290..55cc61086d99 100644 --- a/drivers/gpio/gpio-rcar.c +++ b/drivers/gpio/gpio-rcar.c | |||
@@ -15,7 +15,7 @@ | |||
15 | */ | 15 | */ |
16 | 16 | ||
17 | #include <linux/err.h> | 17 | #include <linux/err.h> |
18 | #include <linux/gpio.h> | 18 | #include <linux/gpio/driver.h> |
19 | #include <linux/init.h> | 19 | #include <linux/init.h> |
20 | #include <linux/interrupt.h> | 20 | #include <linux/interrupt.h> |
21 | #include <linux/io.h> | 21 | #include <linux/io.h> |
@@ -278,6 +278,13 @@ static void gpio_rcar_free(struct gpio_chip *chip, unsigned offset) | |||
278 | pm_runtime_put(&p->pdev->dev); | 278 | pm_runtime_put(&p->pdev->dev); |
279 | } | 279 | } |
280 | 280 | ||
281 | static int gpio_rcar_get_direction(struct gpio_chip *chip, unsigned int offset) | ||
282 | { | ||
283 | struct gpio_rcar_priv *p = gpiochip_get_data(chip); | ||
284 | |||
285 | return !(gpio_rcar_read(p, INOUTSEL) & BIT(offset)); | ||
286 | } | ||
287 | |||
281 | static int gpio_rcar_direction_input(struct gpio_chip *chip, unsigned offset) | 288 | static int gpio_rcar_direction_input(struct gpio_chip *chip, unsigned offset) |
282 | { | 289 | { |
283 | gpio_rcar_config_general_input_output_mode(chip, offset, false); | 290 | gpio_rcar_config_general_input_output_mode(chip, offset, false); |
@@ -461,6 +468,7 @@ static int gpio_rcar_probe(struct platform_device *pdev) | |||
461 | gpio_chip = &p->gpio_chip; | 468 | gpio_chip = &p->gpio_chip; |
462 | gpio_chip->request = gpio_rcar_request; | 469 | gpio_chip->request = gpio_rcar_request; |
463 | gpio_chip->free = gpio_rcar_free; | 470 | gpio_chip->free = gpio_rcar_free; |
471 | gpio_chip->get_direction = gpio_rcar_get_direction; | ||
464 | gpio_chip->direction_input = gpio_rcar_direction_input; | 472 | gpio_chip->direction_input = gpio_rcar_direction_input; |
465 | gpio_chip->get = gpio_rcar_get; | 473 | gpio_chip->get = gpio_rcar_get; |
466 | gpio_chip->direction_output = gpio_rcar_direction_output; | 474 | gpio_chip->direction_output = gpio_rcar_direction_output; |
diff --git a/drivers/gpio/gpio-rdc321x.c b/drivers/gpio/gpio-rdc321x.c index cbf0f9e6465b..2938217566d3 100644 --- a/drivers/gpio/gpio-rdc321x.c +++ b/drivers/gpio/gpio-rdc321x.c | |||
@@ -25,7 +25,7 @@ | |||
25 | #include <linux/spinlock.h> | 25 | #include <linux/spinlock.h> |
26 | #include <linux/platform_device.h> | 26 | #include <linux/platform_device.h> |
27 | #include <linux/pci.h> | 27 | #include <linux/pci.h> |
28 | #include <linux/gpio.h> | 28 | #include <linux/gpio/driver.h> |
29 | #include <linux/mfd/rdc321x.h> | 29 | #include <linux/mfd/rdc321x.h> |
30 | #include <linux/slab.h> | 30 | #include <linux/slab.h> |
31 | 31 | ||
diff --git a/drivers/gpio/gpio-sa1100.c b/drivers/gpio/gpio-sa1100.c index 249f433aa62d..986eb3b231ac 100644 --- a/drivers/gpio/gpio-sa1100.c +++ b/drivers/gpio/gpio-sa1100.c | |||
@@ -7,7 +7,7 @@ | |||
7 | * it under the terms of the GNU General Public License version 2 as | 7 | * it under the terms of the GNU General Public License version 2 as |
8 | * published by the Free Software Foundation. | 8 | * published by the Free Software Foundation. |
9 | */ | 9 | */ |
10 | #include <linux/gpio.h> | 10 | #include <linux/gpio/driver.h> |
11 | #include <linux/init.h> | 11 | #include <linux/init.h> |
12 | #include <linux/module.h> | 12 | #include <linux/module.h> |
13 | #include <linux/io.h> | 13 | #include <linux/io.h> |
diff --git a/drivers/gpio/gpio-sch.c b/drivers/gpio/gpio-sch.c index 545004445846..e9878f6ede67 100644 --- a/drivers/gpio/gpio-sch.c +++ b/drivers/gpio/gpio-sch.c | |||
@@ -26,8 +26,7 @@ | |||
26 | #include <linux/acpi.h> | 26 | #include <linux/acpi.h> |
27 | #include <linux/platform_device.h> | 27 | #include <linux/platform_device.h> |
28 | #include <linux/pci_ids.h> | 28 | #include <linux/pci_ids.h> |
29 | 29 | #include <linux/gpio/driver.h> | |
30 | #include <linux/gpio.h> | ||
31 | 30 | ||
32 | #define GEN 0x00 | 31 | #define GEN 0x00 |
33 | #define GIO 0x04 | 32 | #define GIO 0x04 |
@@ -138,6 +137,13 @@ static int sch_gpio_direction_out(struct gpio_chip *gc, unsigned gpio_num, | |||
138 | return 0; | 137 | return 0; |
139 | } | 138 | } |
140 | 139 | ||
140 | static int sch_gpio_get_direction(struct gpio_chip *gc, unsigned gpio_num) | ||
141 | { | ||
142 | struct sch_gpio *sch = gpiochip_get_data(gc); | ||
143 | |||
144 | return sch_gpio_reg_get(sch, gpio_num, GIO); | ||
145 | } | ||
146 | |||
141 | static const struct gpio_chip sch_gpio_chip = { | 147 | static const struct gpio_chip sch_gpio_chip = { |
142 | .label = "sch_gpio", | 148 | .label = "sch_gpio", |
143 | .owner = THIS_MODULE, | 149 | .owner = THIS_MODULE, |
@@ -145,6 +151,7 @@ static const struct gpio_chip sch_gpio_chip = { | |||
145 | .get = sch_gpio_get, | 151 | .get = sch_gpio_get, |
146 | .direction_output = sch_gpio_direction_out, | 152 | .direction_output = sch_gpio_direction_out, |
147 | .set = sch_gpio_set, | 153 | .set = sch_gpio_set, |
154 | .get_direction = sch_gpio_get_direction, | ||
148 | }; | 155 | }; |
149 | 156 | ||
150 | static int sch_gpio_probe(struct platform_device *pdev) | 157 | static int sch_gpio_probe(struct platform_device *pdev) |
diff --git a/drivers/gpio/gpio-sch311x.c b/drivers/gpio/gpio-sch311x.c index b96990c262a1..5497f0a88cf0 100644 --- a/drivers/gpio/gpio-sch311x.c +++ b/drivers/gpio/gpio-sch311x.c | |||
@@ -17,16 +17,15 @@ | |||
17 | #include <linux/kernel.h> | 17 | #include <linux/kernel.h> |
18 | #include <linux/init.h> | 18 | #include <linux/init.h> |
19 | #include <linux/platform_device.h> | 19 | #include <linux/platform_device.h> |
20 | #include <linux/gpio.h> | 20 | #include <linux/gpio/driver.h> |
21 | #include <linux/bitops.h> | 21 | #include <linux/bitops.h> |
22 | #include <linux/io.h> | 22 | #include <linux/io.h> |
23 | 23 | ||
24 | #define DRV_NAME "gpio-sch311x" | 24 | #define DRV_NAME "gpio-sch311x" |
25 | 25 | ||
26 | #define SCH311X_GPIO_CONF_OUT 0x00 | 26 | #define SCH311X_GPIO_CONF_DIR BIT(0) |
27 | #define SCH311X_GPIO_CONF_IN 0x01 | 27 | #define SCH311X_GPIO_CONF_INVERT BIT(1) |
28 | #define SCH311X_GPIO_CONF_INVERT 0x02 | 28 | #define SCH311X_GPIO_CONF_OPEN_DRAIN BIT(7) |
29 | #define SCH311X_GPIO_CONF_OPEN_DRAIN 0x80 | ||
30 | 29 | ||
31 | #define SIO_CONFIG_KEY_ENTER 0x55 | 30 | #define SIO_CONFIG_KEY_ENTER 0x55 |
32 | #define SIO_CONFIG_KEY_EXIT 0xaa | 31 | #define SIO_CONFIG_KEY_EXIT 0xaa |
@@ -163,7 +162,7 @@ static void sch311x_gpio_free(struct gpio_chip *chip, unsigned offset) | |||
163 | static int sch311x_gpio_get(struct gpio_chip *chip, unsigned offset) | 162 | static int sch311x_gpio_get(struct gpio_chip *chip, unsigned offset) |
164 | { | 163 | { |
165 | struct sch311x_gpio_block *block = gpiochip_get_data(chip); | 164 | struct sch311x_gpio_block *block = gpiochip_get_data(chip); |
166 | unsigned char data; | 165 | u8 data; |
167 | 166 | ||
168 | spin_lock(&block->lock); | 167 | spin_lock(&block->lock); |
169 | data = inb(block->runtime_reg + block->data_reg); | 168 | data = inb(block->runtime_reg + block->data_reg); |
@@ -175,7 +174,7 @@ static int sch311x_gpio_get(struct gpio_chip *chip, unsigned offset) | |||
175 | static void __sch311x_gpio_set(struct sch311x_gpio_block *block, | 174 | static void __sch311x_gpio_set(struct sch311x_gpio_block *block, |
176 | unsigned offset, int value) | 175 | unsigned offset, int value) |
177 | { | 176 | { |
178 | unsigned char data = inb(block->runtime_reg + block->data_reg); | 177 | u8 data = inb(block->runtime_reg + block->data_reg); |
179 | if (value) | 178 | if (value) |
180 | data |= BIT(offset); | 179 | data |= BIT(offset); |
181 | else | 180 | else |
@@ -196,10 +195,12 @@ static void sch311x_gpio_set(struct gpio_chip *chip, unsigned offset, | |||
196 | static int sch311x_gpio_direction_in(struct gpio_chip *chip, unsigned offset) | 195 | static int sch311x_gpio_direction_in(struct gpio_chip *chip, unsigned offset) |
197 | { | 196 | { |
198 | struct sch311x_gpio_block *block = gpiochip_get_data(chip); | 197 | struct sch311x_gpio_block *block = gpiochip_get_data(chip); |
198 | u8 data; | ||
199 | 199 | ||
200 | spin_lock(&block->lock); | 200 | spin_lock(&block->lock); |
201 | outb(SCH311X_GPIO_CONF_IN, block->runtime_reg + | 201 | data = inb(block->runtime_reg + block->config_regs[offset]); |
202 | block->config_regs[offset]); | 202 | data |= SCH311X_GPIO_CONF_DIR; |
203 | outb(data, block->runtime_reg + block->config_regs[offset]); | ||
203 | spin_unlock(&block->lock); | 204 | spin_unlock(&block->lock); |
204 | 205 | ||
205 | return 0; | 206 | return 0; |
@@ -209,18 +210,59 @@ static int sch311x_gpio_direction_out(struct gpio_chip *chip, unsigned offset, | |||
209 | int value) | 210 | int value) |
210 | { | 211 | { |
211 | struct sch311x_gpio_block *block = gpiochip_get_data(chip); | 212 | struct sch311x_gpio_block *block = gpiochip_get_data(chip); |
213 | u8 data; | ||
212 | 214 | ||
213 | spin_lock(&block->lock); | 215 | spin_lock(&block->lock); |
214 | 216 | ||
215 | outb(SCH311X_GPIO_CONF_OUT, block->runtime_reg + | 217 | data = inb(block->runtime_reg + block->config_regs[offset]); |
216 | block->config_regs[offset]); | 218 | data &= ~SCH311X_GPIO_CONF_DIR; |
217 | 219 | outb(data, block->runtime_reg + block->config_regs[offset]); | |
218 | __sch311x_gpio_set(block, offset, value); | 220 | __sch311x_gpio_set(block, offset, value); |
219 | 221 | ||
220 | spin_unlock(&block->lock); | 222 | spin_unlock(&block->lock); |
221 | return 0; | 223 | return 0; |
222 | } | 224 | } |
223 | 225 | ||
226 | static int sch311x_gpio_get_direction(struct gpio_chip *chip, unsigned offset) | ||
227 | { | ||
228 | struct sch311x_gpio_block *block = gpiochip_get_data(chip); | ||
229 | u8 data; | ||
230 | |||
231 | spin_lock(&block->lock); | ||
232 | data = inb(block->runtime_reg + block->config_regs[offset]); | ||
233 | spin_unlock(&block->lock); | ||
234 | |||
235 | return !!(data & SCH311X_GPIO_CONF_DIR); | ||
236 | } | ||
237 | |||
238 | static int sch311x_gpio_set_config(struct gpio_chip *chip, unsigned offset, | ||
239 | unsigned long config) | ||
240 | { | ||
241 | struct sch311x_gpio_block *block = gpiochip_get_data(chip); | ||
242 | enum pin_config_param param = pinconf_to_config_param(config); | ||
243 | u8 data; | ||
244 | |||
245 | switch (param) { | ||
246 | case PIN_CONFIG_DRIVE_OPEN_DRAIN: | ||
247 | spin_lock(&block->lock); | ||
248 | data = inb(block->runtime_reg + block->config_regs[offset]); | ||
249 | data |= SCH311X_GPIO_CONF_OPEN_DRAIN; | ||
250 | outb(data, block->runtime_reg + block->config_regs[offset]); | ||
251 | spin_unlock(&block->lock); | ||
252 | return 0; | ||
253 | case PIN_CONFIG_DRIVE_PUSH_PULL: | ||
254 | spin_lock(&block->lock); | ||
255 | data = inb(block->runtime_reg + block->config_regs[offset]); | ||
256 | data &= ~SCH311X_GPIO_CONF_OPEN_DRAIN; | ||
257 | outb(data, block->runtime_reg + block->config_regs[offset]); | ||
258 | spin_unlock(&block->lock); | ||
259 | return 0; | ||
260 | default: | ||
261 | break; | ||
262 | } | ||
263 | return -ENOTSUPP; | ||
264 | } | ||
265 | |||
224 | static int sch311x_gpio_probe(struct platform_device *pdev) | 266 | static int sch311x_gpio_probe(struct platform_device *pdev) |
225 | { | 267 | { |
226 | struct sch311x_pdev_data *pdata = dev_get_platdata(&pdev->dev); | 268 | struct sch311x_pdev_data *pdata = dev_get_platdata(&pdev->dev); |
@@ -253,6 +295,8 @@ static int sch311x_gpio_probe(struct platform_device *pdev) | |||
253 | block->chip.free = sch311x_gpio_free; | 295 | block->chip.free = sch311x_gpio_free; |
254 | block->chip.direction_input = sch311x_gpio_direction_in; | 296 | block->chip.direction_input = sch311x_gpio_direction_in; |
255 | block->chip.direction_output = sch311x_gpio_direction_out; | 297 | block->chip.direction_output = sch311x_gpio_direction_out; |
298 | block->chip.get_direction = sch311x_gpio_get_direction; | ||
299 | block->chip.set_config = sch311x_gpio_set_config; | ||
256 | block->chip.get = sch311x_gpio_get; | 300 | block->chip.get = sch311x_gpio_get; |
257 | block->chip.set = sch311x_gpio_set; | 301 | block->chip.set = sch311x_gpio_set; |
258 | block->chip.ngpio = 8; | 302 | block->chip.ngpio = 8; |
@@ -309,7 +353,7 @@ static int __init sch311x_detect(int sio_config_port, unsigned short *addr) | |||
309 | { | 353 | { |
310 | int err = 0, reg; | 354 | int err = 0, reg; |
311 | unsigned short base_addr; | 355 | unsigned short base_addr; |
312 | unsigned char dev_id; | 356 | u8 dev_id; |
313 | 357 | ||
314 | err = sch311x_sio_enter(sio_config_port); | 358 | err = sch311x_sio_enter(sio_config_port); |
315 | if (err) | 359 | if (err) |
diff --git a/drivers/gpio/gpio-spear-spics.c b/drivers/gpio/gpio-spear-spics.c index 22267479ba68..ee3039f091f4 100644 --- a/drivers/gpio/gpio-spear-spics.c +++ b/drivers/gpio/gpio-spear-spics.c | |||
@@ -10,7 +10,7 @@ | |||
10 | */ | 10 | */ |
11 | 11 | ||
12 | #include <linux/err.h> | 12 | #include <linux/err.h> |
13 | #include <linux/gpio.h> | 13 | #include <linux/gpio/driver.h> |
14 | #include <linux/io.h> | 14 | #include <linux/io.h> |
15 | #include <linux/init.h> | 15 | #include <linux/init.h> |
16 | #include <linux/of.h> | 16 | #include <linux/of.h> |
diff --git a/drivers/gpio/gpio-sta2x11.c b/drivers/gpio/gpio-sta2x11.c index 407359da08f9..2283c869ad5d 100644 --- a/drivers/gpio/gpio-sta2x11.c +++ b/drivers/gpio/gpio-sta2x11.c | |||
@@ -23,7 +23,8 @@ | |||
23 | #include <linux/init.h> | 23 | #include <linux/init.h> |
24 | #include <linux/kernel.h> | 24 | #include <linux/kernel.h> |
25 | #include <linux/slab.h> | 25 | #include <linux/slab.h> |
26 | #include <linux/gpio.h> | 26 | #include <linux/gpio/driver.h> |
27 | #include <linux/bitops.h> | ||
27 | #include <linux/interrupt.h> | 28 | #include <linux/interrupt.h> |
28 | #include <linux/irq.h> | 29 | #include <linux/irq.h> |
29 | #include <linux/pci.h> | 30 | #include <linux/pci.h> |
@@ -58,16 +59,6 @@ struct gsta_gpio { | |||
58 | unsigned irq_type[GSTA_NR_GPIO]; | 59 | unsigned irq_type[GSTA_NR_GPIO]; |
59 | }; | 60 | }; |
60 | 61 | ||
61 | static inline struct gsta_regs __iomem *__regs(struct gsta_gpio *chip, int nr) | ||
62 | { | ||
63 | return chip->regs[nr / GSTA_GPIO_PER_BLOCK]; | ||
64 | } | ||
65 | |||
66 | static inline u32 __bit(int nr) | ||
67 | { | ||
68 | return 1U << (nr % GSTA_GPIO_PER_BLOCK); | ||
69 | } | ||
70 | |||
71 | /* | 62 | /* |
72 | * gpio methods | 63 | * gpio methods |
73 | */ | 64 | */ |
@@ -75,8 +66,8 @@ static inline u32 __bit(int nr) | |||
75 | static void gsta_gpio_set(struct gpio_chip *gpio, unsigned nr, int val) | 66 | static void gsta_gpio_set(struct gpio_chip *gpio, unsigned nr, int val) |
76 | { | 67 | { |
77 | struct gsta_gpio *chip = gpiochip_get_data(gpio); | 68 | struct gsta_gpio *chip = gpiochip_get_data(gpio); |
78 | struct gsta_regs __iomem *regs = __regs(chip, nr); | 69 | struct gsta_regs __iomem *regs = chip->regs[nr / GSTA_GPIO_PER_BLOCK]; |
79 | u32 bit = __bit(nr); | 70 | u32 bit = BIT(nr % GSTA_GPIO_PER_BLOCK); |
80 | 71 | ||
81 | if (val) | 72 | if (val) |
82 | writel(bit, ®s->dats); | 73 | writel(bit, ®s->dats); |
@@ -87,8 +78,8 @@ static void gsta_gpio_set(struct gpio_chip *gpio, unsigned nr, int val) | |||
87 | static int gsta_gpio_get(struct gpio_chip *gpio, unsigned nr) | 78 | static int gsta_gpio_get(struct gpio_chip *gpio, unsigned nr) |
88 | { | 79 | { |
89 | struct gsta_gpio *chip = gpiochip_get_data(gpio); | 80 | struct gsta_gpio *chip = gpiochip_get_data(gpio); |
90 | struct gsta_regs __iomem *regs = __regs(chip, nr); | 81 | struct gsta_regs __iomem *regs = chip->regs[nr / GSTA_GPIO_PER_BLOCK]; |
91 | u32 bit = __bit(nr); | 82 | u32 bit = BIT(nr % GSTA_GPIO_PER_BLOCK); |
92 | 83 | ||
93 | return !!(readl(®s->dat) & bit); | 84 | return !!(readl(®s->dat) & bit); |
94 | } | 85 | } |
@@ -97,8 +88,8 @@ static int gsta_gpio_direction_output(struct gpio_chip *gpio, unsigned nr, | |||
97 | int val) | 88 | int val) |
98 | { | 89 | { |
99 | struct gsta_gpio *chip = gpiochip_get_data(gpio); | 90 | struct gsta_gpio *chip = gpiochip_get_data(gpio); |
100 | struct gsta_regs __iomem *regs = __regs(chip, nr); | 91 | struct gsta_regs __iomem *regs = chip->regs[nr / GSTA_GPIO_PER_BLOCK]; |
101 | u32 bit = __bit(nr); | 92 | u32 bit = BIT(nr % GSTA_GPIO_PER_BLOCK); |
102 | 93 | ||
103 | writel(bit, ®s->dirs); | 94 | writel(bit, ®s->dirs); |
104 | /* Data register after direction, otherwise pullup/down is selected */ | 95 | /* Data register after direction, otherwise pullup/down is selected */ |
@@ -112,8 +103,8 @@ static int gsta_gpio_direction_output(struct gpio_chip *gpio, unsigned nr, | |||
112 | static int gsta_gpio_direction_input(struct gpio_chip *gpio, unsigned nr) | 103 | static int gsta_gpio_direction_input(struct gpio_chip *gpio, unsigned nr) |
113 | { | 104 | { |
114 | struct gsta_gpio *chip = gpiochip_get_data(gpio); | 105 | struct gsta_gpio *chip = gpiochip_get_data(gpio); |
115 | struct gsta_regs __iomem *regs = __regs(chip, nr); | 106 | struct gsta_regs __iomem *regs = chip->regs[nr / GSTA_GPIO_PER_BLOCK]; |
116 | u32 bit = __bit(nr); | 107 | u32 bit = BIT(nr % GSTA_GPIO_PER_BLOCK); |
117 | 108 | ||
118 | writel(bit, ®s->dirc); | 109 | writel(bit, ®s->dirc); |
119 | return 0; | 110 | return 0; |
@@ -165,9 +156,9 @@ static void gsta_gpio_setup(struct gsta_gpio *chip) /* called from probe */ | |||
165 | */ | 156 | */ |
166 | static void gsta_set_config(struct gsta_gpio *chip, int nr, unsigned cfg) | 157 | static void gsta_set_config(struct gsta_gpio *chip, int nr, unsigned cfg) |
167 | { | 158 | { |
168 | struct gsta_regs __iomem *regs = __regs(chip, nr); | 159 | struct gsta_regs __iomem *regs = chip->regs[nr / GSTA_GPIO_PER_BLOCK]; |
169 | unsigned long flags; | 160 | unsigned long flags; |
170 | u32 bit = __bit(nr); | 161 | u32 bit = BIT(nr % GSTA_GPIO_PER_BLOCK); |
171 | u32 val; | 162 | u32 val; |
172 | int err = 0; | 163 | int err = 0; |
173 | 164 | ||
@@ -234,8 +225,8 @@ static void gsta_irq_disable(struct irq_data *data) | |||
234 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(data); | 225 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(data); |
235 | struct gsta_gpio *chip = gc->private; | 226 | struct gsta_gpio *chip = gc->private; |
236 | int nr = data->irq - chip->irq_base; | 227 | int nr = data->irq - chip->irq_base; |
237 | struct gsta_regs __iomem *regs = __regs(chip, nr); | 228 | struct gsta_regs __iomem *regs = chip->regs[nr / GSTA_GPIO_PER_BLOCK]; |
238 | u32 bit = __bit(nr); | 229 | u32 bit = BIT(nr % GSTA_GPIO_PER_BLOCK); |
239 | u32 val; | 230 | u32 val; |
240 | unsigned long flags; | 231 | unsigned long flags; |
241 | 232 | ||
@@ -257,8 +248,8 @@ static void gsta_irq_enable(struct irq_data *data) | |||
257 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(data); | 248 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(data); |
258 | struct gsta_gpio *chip = gc->private; | 249 | struct gsta_gpio *chip = gc->private; |
259 | int nr = data->irq - chip->irq_base; | 250 | int nr = data->irq - chip->irq_base; |
260 | struct gsta_regs __iomem *regs = __regs(chip, nr); | 251 | struct gsta_regs __iomem *regs = chip->regs[nr / GSTA_GPIO_PER_BLOCK]; |
261 | u32 bit = __bit(nr); | 252 | u32 bit = BIT(nr % GSTA_GPIO_PER_BLOCK); |
262 | u32 val; | 253 | u32 val; |
263 | int type; | 254 | int type; |
264 | unsigned long flags; | 255 | unsigned long flags; |
diff --git a/drivers/gpio/gpio-stmpe.c b/drivers/gpio/gpio-stmpe.c index 8d6a5a7e612d..65a2315f1673 100644 --- a/drivers/gpio/gpio-stmpe.c +++ b/drivers/gpio/gpio-stmpe.c | |||
@@ -8,7 +8,7 @@ | |||
8 | #include <linux/init.h> | 8 | #include <linux/init.h> |
9 | #include <linux/platform_device.h> | 9 | #include <linux/platform_device.h> |
10 | #include <linux/slab.h> | 10 | #include <linux/slab.h> |
11 | #include <linux/gpio.h> | 11 | #include <linux/gpio/driver.h> |
12 | #include <linux/interrupt.h> | 12 | #include <linux/interrupt.h> |
13 | #include <linux/of.h> | 13 | #include <linux/of.h> |
14 | #include <linux/mfd/stmpe.h> | 14 | #include <linux/mfd/stmpe.h> |
diff --git a/drivers/gpio/gpio-stp-xway.c b/drivers/gpio/gpio-stp-xway.c index c07385b71403..19972084c45b 100644 --- a/drivers/gpio/gpio-stp-xway.c +++ b/drivers/gpio/gpio-stp-xway.c | |||
@@ -13,9 +13,8 @@ | |||
13 | #include <linux/types.h> | 13 | #include <linux/types.h> |
14 | #include <linux/of_platform.h> | 14 | #include <linux/of_platform.h> |
15 | #include <linux/mutex.h> | 15 | #include <linux/mutex.h> |
16 | #include <linux/gpio.h> | 16 | #include <linux/gpio/driver.h> |
17 | #include <linux/io.h> | 17 | #include <linux/io.h> |
18 | #include <linux/of_gpio.h> | ||
19 | #include <linux/clk.h> | 18 | #include <linux/clk.h> |
20 | #include <linux/err.h> | 19 | #include <linux/err.h> |
21 | 20 | ||
@@ -91,6 +90,20 @@ struct xway_stp { | |||
91 | }; | 90 | }; |
92 | 91 | ||
93 | /** | 92 | /** |
93 | * xway_stp_get() - gpio_chip->get - get gpios. | ||
94 | * @gc: Pointer to gpio_chip device structure. | ||
95 | * @gpio: GPIO signal number. | ||
96 | * | ||
97 | * Gets the shadow value. | ||
98 | */ | ||
99 | static int xway_stp_get(struct gpio_chip *gc, unsigned int gpio) | ||
100 | { | ||
101 | struct xway_stp *chip = gpiochip_get_data(gc); | ||
102 | |||
103 | return (xway_stp_r32(chip->virt, XWAY_STP_CPU0) & BIT(gpio)); | ||
104 | } | ||
105 | |||
106 | /** | ||
94 | * xway_stp_set() - gpio_chip->set - set gpios. | 107 | * xway_stp_set() - gpio_chip->set - set gpios. |
95 | * @gc: Pointer to gpio_chip device structure. | 108 | * @gc: Pointer to gpio_chip device structure. |
96 | * @gpio: GPIO signal number. | 109 | * @gpio: GPIO signal number. |
@@ -215,6 +228,7 @@ static int xway_stp_probe(struct platform_device *pdev) | |||
215 | chip->gc.parent = &pdev->dev; | 228 | chip->gc.parent = &pdev->dev; |
216 | chip->gc.label = "stp-xway"; | 229 | chip->gc.label = "stp-xway"; |
217 | chip->gc.direction_output = xway_stp_dir_out; | 230 | chip->gc.direction_output = xway_stp_dir_out; |
231 | chip->gc.get = xway_stp_get; | ||
218 | chip->gc.set = xway_stp_set; | 232 | chip->gc.set = xway_stp_set; |
219 | chip->gc.request = xway_stp_request; | 233 | chip->gc.request = xway_stp_request; |
220 | chip->gc.base = -1; | 234 | chip->gc.base = -1; |
diff --git a/drivers/gpio/gpio-syscon.c b/drivers/gpio/gpio-syscon.c index 8b0a69c5ba88..87c18a544513 100644 --- a/drivers/gpio/gpio-syscon.c +++ b/drivers/gpio/gpio-syscon.c | |||
@@ -10,7 +10,7 @@ | |||
10 | */ | 10 | */ |
11 | 11 | ||
12 | #include <linux/err.h> | 12 | #include <linux/err.h> |
13 | #include <linux/gpio.h> | 13 | #include <linux/gpio/driver.h> |
14 | #include <linux/module.h> | 14 | #include <linux/module.h> |
15 | #include <linux/of.h> | 15 | #include <linux/of.h> |
16 | #include <linux/of_device.h> | 16 | #include <linux/of_device.h> |
@@ -135,6 +135,33 @@ static const struct syscon_gpio_data clps711x_mctrl_gpio = { | |||
135 | .dat_bit_offset = 0x40 * 8 + 8, | 135 | .dat_bit_offset = 0x40 * 8 + 8, |
136 | }; | 136 | }; |
137 | 137 | ||
138 | static void rockchip_gpio_set(struct gpio_chip *chip, unsigned int offset, | ||
139 | int val) | ||
140 | { | ||
141 | struct syscon_gpio_priv *priv = gpiochip_get_data(chip); | ||
142 | unsigned int offs; | ||
143 | u8 bit; | ||
144 | u32 data; | ||
145 | int ret; | ||
146 | |||
147 | offs = priv->dreg_offset + priv->data->dat_bit_offset + offset; | ||
148 | bit = offs % SYSCON_REG_BITS; | ||
149 | data = (val ? BIT(bit) : 0) | BIT(bit + 16); | ||
150 | ret = regmap_write(priv->syscon, | ||
151 | (offs / SYSCON_REG_BITS) * SYSCON_REG_SIZE, | ||
152 | data); | ||
153 | if (ret < 0) | ||
154 | dev_err(chip->parent, "gpio write failed ret(%d)\n", ret); | ||
155 | } | ||
156 | |||
157 | static const struct syscon_gpio_data rockchip_rk3328_gpio_mute = { | ||
158 | /* RK3328 GPIO_MUTE is an output only pin at GRF_SOC_CON10[1] */ | ||
159 | .flags = GPIO_SYSCON_FEAT_OUT, | ||
160 | .bit_count = 1, | ||
161 | .dat_bit_offset = 0x0428 * 8 + 1, | ||
162 | .set = rockchip_gpio_set, | ||
163 | }; | ||
164 | |||
138 | #define KEYSTONE_LOCK_BIT BIT(0) | 165 | #define KEYSTONE_LOCK_BIT BIT(0) |
139 | 166 | ||
140 | static void keystone_gpio_set(struct gpio_chip *chip, unsigned offset, int val) | 167 | static void keystone_gpio_set(struct gpio_chip *chip, unsigned offset, int val) |
@@ -175,6 +202,10 @@ static const struct of_device_id syscon_gpio_ids[] = { | |||
175 | .compatible = "ti,keystone-dsp-gpio", | 202 | .compatible = "ti,keystone-dsp-gpio", |
176 | .data = &keystone_dsp_gpio, | 203 | .data = &keystone_dsp_gpio, |
177 | }, | 204 | }, |
205 | { | ||
206 | .compatible = "rockchip,rk3328-grf-gpio", | ||
207 | .data = &rockchip_rk3328_gpio_mute, | ||
208 | }, | ||
178 | { } | 209 | { } |
179 | }; | 210 | }; |
180 | MODULE_DEVICE_TABLE(of, syscon_gpio_ids); | 211 | MODULE_DEVICE_TABLE(of, syscon_gpio_ids); |
diff --git a/drivers/gpio/gpio-tb10x.c b/drivers/gpio/gpio-tb10x.c index ac6f2a9841e5..a12cd0b5c972 100644 --- a/drivers/gpio/gpio-tb10x.c +++ b/drivers/gpio/gpio-tb10x.c | |||
@@ -22,7 +22,7 @@ | |||
22 | #include <linux/kernel.h> | 22 | #include <linux/kernel.h> |
23 | #include <linux/module.h> | 23 | #include <linux/module.h> |
24 | #include <linux/platform_device.h> | 24 | #include <linux/platform_device.h> |
25 | #include <linux/gpio.h> | 25 | #include <linux/gpio/driver.h> |
26 | #include <linux/slab.h> | 26 | #include <linux/slab.h> |
27 | #include <linux/irq.h> | 27 | #include <linux/irq.h> |
28 | #include <linux/irqdomain.h> | 28 | #include <linux/irqdomain.h> |
@@ -30,7 +30,6 @@ | |||
30 | #include <linux/io.h> | 30 | #include <linux/io.h> |
31 | #include <linux/of.h> | 31 | #include <linux/of.h> |
32 | #include <linux/of_platform.h> | 32 | #include <linux/of_platform.h> |
33 | #include <linux/of_gpio.h> | ||
34 | #include <linux/spinlock.h> | 33 | #include <linux/spinlock.h> |
35 | #include <linux/bitops.h> | 34 | #include <linux/bitops.h> |
36 | #include <linux/pinctrl/consumer.h> | 35 | #include <linux/pinctrl/consumer.h> |
diff --git a/drivers/gpio/gpio-tegra.c b/drivers/gpio/gpio-tegra.c index d5d79727c55d..47dbd19751d0 100644 --- a/drivers/gpio/gpio-tegra.c +++ b/drivers/gpio/gpio-tegra.c | |||
@@ -22,7 +22,7 @@ | |||
22 | #include <linux/irq.h> | 22 | #include <linux/irq.h> |
23 | #include <linux/interrupt.h> | 23 | #include <linux/interrupt.h> |
24 | #include <linux/io.h> | 24 | #include <linux/io.h> |
25 | #include <linux/gpio.h> | 25 | #include <linux/gpio/driver.h> |
26 | #include <linux/of_device.h> | 26 | #include <linux/of_device.h> |
27 | #include <linux/platform_device.h> | 27 | #include <linux/platform_device.h> |
28 | #include <linux/module.h> | 28 | #include <linux/module.h> |
@@ -207,7 +207,7 @@ static int tegra_gpio_get_direction(struct gpio_chip *chip, | |||
207 | 207 | ||
208 | oe = tegra_gpio_readl(tgi, GPIO_OE(tgi, offset)); | 208 | oe = tegra_gpio_readl(tgi, GPIO_OE(tgi, offset)); |
209 | 209 | ||
210 | return (oe & pin_mask) ? GPIOF_DIR_OUT : GPIOF_DIR_IN; | 210 | return !(oe & pin_mask); |
211 | } | 211 | } |
212 | 212 | ||
213 | static int tegra_gpio_set_debounce(struct gpio_chip *chip, unsigned int offset, | 213 | static int tegra_gpio_set_debounce(struct gpio_chip *chip, unsigned int offset, |
@@ -323,13 +323,6 @@ static int tegra_gpio_irq_set_type(struct irq_data *d, unsigned int type) | |||
323 | return -EINVAL; | 323 | return -EINVAL; |
324 | } | 324 | } |
325 | 325 | ||
326 | ret = gpiochip_lock_as_irq(&tgi->gc, gpio); | ||
327 | if (ret) { | ||
328 | dev_err(tgi->dev, | ||
329 | "unable to lock Tegra GPIO %u as IRQ\n", gpio); | ||
330 | return ret; | ||
331 | } | ||
332 | |||
333 | spin_lock_irqsave(&bank->lvl_lock[port], flags); | 326 | spin_lock_irqsave(&bank->lvl_lock[port], flags); |
334 | 327 | ||
335 | val = tegra_gpio_readl(tgi, GPIO_INT_LVL(tgi, gpio)); | 328 | val = tegra_gpio_readl(tgi, GPIO_INT_LVL(tgi, gpio)); |
@@ -342,6 +335,14 @@ static int tegra_gpio_irq_set_type(struct irq_data *d, unsigned int type) | |||
342 | tegra_gpio_mask_write(tgi, GPIO_MSK_OE(tgi, gpio), gpio, 0); | 335 | tegra_gpio_mask_write(tgi, GPIO_MSK_OE(tgi, gpio), gpio, 0); |
343 | tegra_gpio_enable(tgi, gpio); | 336 | tegra_gpio_enable(tgi, gpio); |
344 | 337 | ||
338 | ret = gpiochip_lock_as_irq(&tgi->gc, gpio); | ||
339 | if (ret) { | ||
340 | dev_err(tgi->dev, | ||
341 | "unable to lock Tegra GPIO %u as IRQ\n", gpio); | ||
342 | tegra_gpio_disable(tgi, gpio); | ||
343 | return ret; | ||
344 | } | ||
345 | |||
345 | if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH)) | 346 | if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH)) |
346 | irq_set_handler_locked(d, handle_level_irq); | 347 | irq_set_handler_locked(d, handle_level_irq); |
347 | else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING)) | 348 | else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING)) |
@@ -550,13 +551,6 @@ static const struct dev_pm_ops tegra_gpio_pm_ops = { | |||
550 | SET_SYSTEM_SLEEP_PM_OPS(tegra_gpio_suspend, tegra_gpio_resume) | 551 | SET_SYSTEM_SLEEP_PM_OPS(tegra_gpio_suspend, tegra_gpio_resume) |
551 | }; | 552 | }; |
552 | 553 | ||
553 | /* | ||
554 | * This lock class tells lockdep that GPIO irqs are in a different category | ||
555 | * than their parents, so it won't report false recursion. | ||
556 | */ | ||
557 | static struct lock_class_key gpio_lock_class; | ||
558 | static struct lock_class_key gpio_request_class; | ||
559 | |||
560 | static int tegra_gpio_probe(struct platform_device *pdev) | 554 | static int tegra_gpio_probe(struct platform_device *pdev) |
561 | { | 555 | { |
562 | struct tegra_gpio_info *tgi; | 556 | struct tegra_gpio_info *tgi; |
@@ -661,8 +655,6 @@ static int tegra_gpio_probe(struct platform_device *pdev) | |||
661 | 655 | ||
662 | bank = &tgi->bank_info[GPIO_BANK(gpio)]; | 656 | bank = &tgi->bank_info[GPIO_BANK(gpio)]; |
663 | 657 | ||
664 | irq_set_lockdep_class(irq, &gpio_lock_class, | ||
665 | &gpio_request_class); | ||
666 | irq_set_chip_data(irq, bank); | 658 | irq_set_chip_data(irq, bank); |
667 | irq_set_chip_and_handler(irq, &tgi->ic, handle_simple_irq); | 659 | irq_set_chip_and_handler(irq, &tgi->ic, handle_simple_irq); |
668 | } | 660 | } |
diff --git a/drivers/gpio/gpio-tegra186.c b/drivers/gpio/gpio-tegra186.c index 7f1aa4c21e0d..9d0292c8a199 100644 --- a/drivers/gpio/gpio-tegra186.c +++ b/drivers/gpio/gpio-tegra186.c | |||
@@ -16,6 +16,7 @@ | |||
16 | #include <linux/platform_device.h> | 16 | #include <linux/platform_device.h> |
17 | 17 | ||
18 | #include <dt-bindings/gpio/tegra186-gpio.h> | 18 | #include <dt-bindings/gpio/tegra186-gpio.h> |
19 | #include <dt-bindings/gpio/tegra194-gpio.h> | ||
19 | 20 | ||
20 | #define TEGRA186_GPIO_ENABLE_CONFIG 0x00 | 21 | #define TEGRA186_GPIO_ENABLE_CONFIG 0x00 |
21 | #define TEGRA186_GPIO_ENABLE_CONFIG_ENABLE BIT(0) | 22 | #define TEGRA186_GPIO_ENABLE_CONFIG_ENABLE BIT(0) |
@@ -593,6 +594,73 @@ static const struct tegra_gpio_soc tegra186_aon_soc = { | |||
593 | .name = "tegra186-gpio-aon", | 594 | .name = "tegra186-gpio-aon", |
594 | }; | 595 | }; |
595 | 596 | ||
597 | #define TEGRA194_MAIN_GPIO_PORT(port, base, count, controller) \ | ||
598 | [TEGRA194_MAIN_GPIO_PORT_##port] = { \ | ||
599 | .name = #port, \ | ||
600 | .offset = base, \ | ||
601 | .pins = count, \ | ||
602 | .irq = controller, \ | ||
603 | } | ||
604 | |||
605 | static const struct tegra_gpio_port tegra194_main_ports[] = { | ||
606 | TEGRA194_MAIN_GPIO_PORT( A, 0x1400, 8, 1), | ||
607 | TEGRA194_MAIN_GPIO_PORT( B, 0x4e00, 2, 4), | ||
608 | TEGRA194_MAIN_GPIO_PORT( C, 0x4600, 8, 4), | ||
609 | TEGRA194_MAIN_GPIO_PORT( D, 0x4800, 4, 4), | ||
610 | TEGRA194_MAIN_GPIO_PORT( E, 0x4a00, 8, 4), | ||
611 | TEGRA194_MAIN_GPIO_PORT( F, 0x4c00, 6, 4), | ||
612 | TEGRA194_MAIN_GPIO_PORT( G, 0x4000, 8, 4), | ||
613 | TEGRA194_MAIN_GPIO_PORT( H, 0x4200, 8, 4), | ||
614 | TEGRA194_MAIN_GPIO_PORT( I, 0x4400, 5, 4), | ||
615 | TEGRA194_MAIN_GPIO_PORT( J, 0x5200, 6, 5), | ||
616 | TEGRA194_MAIN_GPIO_PORT( K, 0x3000, 8, 3), | ||
617 | TEGRA194_MAIN_GPIO_PORT( L, 0x3200, 4, 3), | ||
618 | TEGRA194_MAIN_GPIO_PORT( M, 0x2600, 8, 2), | ||
619 | TEGRA194_MAIN_GPIO_PORT( N, 0x2800, 3, 2), | ||
620 | TEGRA194_MAIN_GPIO_PORT( O, 0x5000, 6, 5), | ||
621 | TEGRA194_MAIN_GPIO_PORT( P, 0x2a00, 8, 2), | ||
622 | TEGRA194_MAIN_GPIO_PORT( Q, 0x2c00, 8, 2), | ||
623 | TEGRA194_MAIN_GPIO_PORT( R, 0x2e00, 6, 2), | ||
624 | TEGRA194_MAIN_GPIO_PORT( S, 0x3600, 8, 3), | ||
625 | TEGRA194_MAIN_GPIO_PORT( T, 0x3800, 8, 3), | ||
626 | TEGRA194_MAIN_GPIO_PORT( U, 0x3a00, 1, 3), | ||
627 | TEGRA194_MAIN_GPIO_PORT( V, 0x1000, 8, 1), | ||
628 | TEGRA194_MAIN_GPIO_PORT( W, 0x1200, 2, 1), | ||
629 | TEGRA194_MAIN_GPIO_PORT( X, 0x2000, 8, 2), | ||
630 | TEGRA194_MAIN_GPIO_PORT( Y, 0x2200, 8, 2), | ||
631 | TEGRA194_MAIN_GPIO_PORT( Z, 0x2400, 8, 2), | ||
632 | TEGRA194_MAIN_GPIO_PORT(FF, 0x3400, 2, 3), | ||
633 | TEGRA194_MAIN_GPIO_PORT(GG, 0x0000, 2, 0) | ||
634 | }; | ||
635 | |||
636 | static const struct tegra_gpio_soc tegra194_main_soc = { | ||
637 | .num_ports = ARRAY_SIZE(tegra194_main_ports), | ||
638 | .ports = tegra194_main_ports, | ||
639 | .name = "tegra194-gpio", | ||
640 | }; | ||
641 | |||
642 | #define TEGRA194_AON_GPIO_PORT(port, base, count, controller) \ | ||
643 | [TEGRA194_AON_GPIO_PORT_##port] = { \ | ||
644 | .name = #port, \ | ||
645 | .offset = base, \ | ||
646 | .pins = count, \ | ||
647 | .irq = controller, \ | ||
648 | } | ||
649 | |||
650 | static const struct tegra_gpio_port tegra194_aon_ports[] = { | ||
651 | TEGRA194_AON_GPIO_PORT(AA, 0x0600, 8, 0), | ||
652 | TEGRA194_AON_GPIO_PORT(BB, 0x0800, 4, 0), | ||
653 | TEGRA194_AON_GPIO_PORT(CC, 0x0200, 8, 0), | ||
654 | TEGRA194_AON_GPIO_PORT(DD, 0x0400, 3, 0), | ||
655 | TEGRA194_AON_GPIO_PORT(EE, 0x0000, 7, 0) | ||
656 | }; | ||
657 | |||
658 | static const struct tegra_gpio_soc tegra194_aon_soc = { | ||
659 | .num_ports = ARRAY_SIZE(tegra194_aon_ports), | ||
660 | .ports = tegra194_aon_ports, | ||
661 | .name = "tegra194-gpio-aon", | ||
662 | }; | ||
663 | |||
596 | static const struct of_device_id tegra186_gpio_of_match[] = { | 664 | static const struct of_device_id tegra186_gpio_of_match[] = { |
597 | { | 665 | { |
598 | .compatible = "nvidia,tegra186-gpio", | 666 | .compatible = "nvidia,tegra186-gpio", |
@@ -601,6 +669,12 @@ static const struct of_device_id tegra186_gpio_of_match[] = { | |||
601 | .compatible = "nvidia,tegra186-gpio-aon", | 669 | .compatible = "nvidia,tegra186-gpio-aon", |
602 | .data = &tegra186_aon_soc | 670 | .data = &tegra186_aon_soc |
603 | }, { | 671 | }, { |
672 | .compatible = "nvidia,tegra194-gpio", | ||
673 | .data = &tegra194_main_soc | ||
674 | }, { | ||
675 | .compatible = "nvidia,tegra194-gpio-aon", | ||
676 | .data = &tegra194_aon_soc | ||
677 | }, { | ||
604 | /* sentinel */ | 678 | /* sentinel */ |
605 | } | 679 | } |
606 | }; | 680 | }; |
diff --git a/drivers/gpio/gpio-timberdale.c b/drivers/gpio/gpio-timberdale.c index 6520a8475910..314e300d6ba3 100644 --- a/drivers/gpio/gpio-timberdale.c +++ b/drivers/gpio/gpio-timberdale.c | |||
@@ -22,7 +22,7 @@ | |||
22 | */ | 22 | */ |
23 | 23 | ||
24 | #include <linux/init.h> | 24 | #include <linux/init.h> |
25 | #include <linux/gpio.h> | 25 | #include <linux/gpio/driver.h> |
26 | #include <linux/platform_device.h> | 26 | #include <linux/platform_device.h> |
27 | #include <linux/irq.h> | 27 | #include <linux/irq.h> |
28 | #include <linux/io.h> | 28 | #include <linux/io.h> |
diff --git a/drivers/gpio/gpio-uniphier.c b/drivers/gpio/gpio-uniphier.c index 58faeb1cef63..7fdac9060979 100644 --- a/drivers/gpio/gpio-uniphier.c +++ b/drivers/gpio/gpio-uniphier.c | |||
@@ -310,8 +310,7 @@ static int uniphier_gpio_irq_domain_activate(struct irq_domain *domain, | |||
310 | struct uniphier_gpio_priv *priv = domain->host_data; | 310 | struct uniphier_gpio_priv *priv = domain->host_data; |
311 | struct gpio_chip *chip = &priv->chip; | 311 | struct gpio_chip *chip = &priv->chip; |
312 | 312 | ||
313 | gpiochip_lock_as_irq(chip, data->hwirq + UNIPHIER_GPIO_IRQ_OFFSET); | 313 | return gpiochip_lock_as_irq(chip, data->hwirq + UNIPHIER_GPIO_IRQ_OFFSET); |
314 | return 0; | ||
315 | } | 314 | } |
316 | 315 | ||
317 | static void uniphier_gpio_irq_domain_deactivate(struct irq_domain *domain, | 316 | static void uniphier_gpio_irq_domain_deactivate(struct irq_domain *domain, |
diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c index ac8deb01f6f6..027699cec911 100644 --- a/drivers/gpio/gpio-vr41xx.c +++ b/drivers/gpio/gpio-vr41xx.c | |||
@@ -138,10 +138,16 @@ static void unmask_giuint_low(struct irq_data *d) | |||
138 | 138 | ||
139 | static unsigned int startup_giuint(struct irq_data *data) | 139 | static unsigned int startup_giuint(struct irq_data *data) |
140 | { | 140 | { |
141 | if (gpiochip_lock_as_irq(&vr41xx_gpio_chip, data->hwirq)) | 141 | int ret; |
142 | |||
143 | ret = gpiochip_lock_as_irq(&vr41xx_gpio_chip, irqd_to_hwirq(data)); | ||
144 | if (ret) { | ||
142 | dev_err(vr41xx_gpio_chip.parent, | 145 | dev_err(vr41xx_gpio_chip.parent, |
143 | "unable to lock HW IRQ %lu for IRQ\n", | 146 | "unable to lock HW IRQ %lu for IRQ\n", |
144 | data->hwirq); | 147 | data->hwirq); |
148 | return ret; | ||
149 | } | ||
150 | |||
145 | /* Satisfy the .enable semantics by unmasking the line */ | 151 | /* Satisfy the .enable semantics by unmasking the line */ |
146 | unmask_giuint_low(data); | 152 | unmask_giuint_low(data); |
147 | return 0; | 153 | return 0; |
diff --git a/drivers/gpio/gpio-xgene-sb.c b/drivers/gpio/gpio-xgene-sb.c index acd59113e08b..2eb76f35aa7e 100644 --- a/drivers/gpio/gpio-xgene-sb.c +++ b/drivers/gpio/gpio-xgene-sb.c | |||
@@ -143,12 +143,14 @@ static int xgene_gpio_sb_domain_activate(struct irq_domain *d, | |||
143 | { | 143 | { |
144 | struct xgene_gpio_sb *priv = d->host_data; | 144 | struct xgene_gpio_sb *priv = d->host_data; |
145 | u32 gpio = HWIRQ_TO_GPIO(priv, irq_data->hwirq); | 145 | u32 gpio = HWIRQ_TO_GPIO(priv, irq_data->hwirq); |
146 | int ret; | ||
146 | 147 | ||
147 | if (gpiochip_lock_as_irq(&priv->gc, gpio)) { | 148 | ret = gpiochip_lock_as_irq(&priv->gc, gpio); |
149 | if (ret) { | ||
148 | dev_err(priv->gc.parent, | 150 | dev_err(priv->gc.parent, |
149 | "Unable to configure XGene GPIO standby pin %d as IRQ\n", | 151 | "Unable to configure XGene GPIO standby pin %d as IRQ\n", |
150 | gpio); | 152 | gpio); |
151 | return -ENOSPC; | 153 | return ret; |
152 | } | 154 | } |
153 | 155 | ||
154 | xgene_gpio_set_bit(&priv->gc, priv->regs + MPA_GPIO_SEL_LO, | 156 | xgene_gpio_set_bit(&priv->gc, priv->regs + MPA_GPIO_SEL_LO, |
diff --git a/drivers/gpio/gpio-xilinx.c b/drivers/gpio/gpio-xilinx.c index e8ec0e33a0a9..8f24478cc18b 100644 --- a/drivers/gpio/gpio-xilinx.c +++ b/drivers/gpio/gpio-xilinx.c | |||
@@ -20,7 +20,7 @@ | |||
20 | #include <linux/of_platform.h> | 20 | #include <linux/of_platform.h> |
21 | #include <linux/of_gpio.h> | 21 | #include <linux/of_gpio.h> |
22 | #include <linux/io.h> | 22 | #include <linux/io.h> |
23 | #include <linux/gpio.h> | 23 | #include <linux/gpio/driver.h> |
24 | #include <linux/slab.h> | 24 | #include <linux/slab.h> |
25 | 25 | ||
26 | /* Register Offset Definitions */ | 26 | /* Register Offset Definitions */ |
diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index 53a14ee8ad6d..a4f1157d6aa0 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c | |||
@@ -621,9 +621,6 @@ int of_gpiochip_add(struct gpio_chip *chip) | |||
621 | { | 621 | { |
622 | int status; | 622 | int status; |
623 | 623 | ||
624 | if ((!chip->of_node) && (chip->parent)) | ||
625 | chip->of_node = chip->parent->of_node; | ||
626 | |||
627 | if (!chip->of_node) | 624 | if (!chip->of_node) |
628 | return 0; | 625 | return 0; |
629 | 626 | ||
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index e11a3bb03820..e8f8a1999393 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c | |||
@@ -431,7 +431,7 @@ static long linehandle_ioctl(struct file *filep, unsigned int cmd, | |||
431 | int i; | 431 | int i; |
432 | 432 | ||
433 | if (cmd == GPIOHANDLE_GET_LINE_VALUES_IOCTL) { | 433 | if (cmd == GPIOHANDLE_GET_LINE_VALUES_IOCTL) { |
434 | /* TODO: check if descriptors are really input */ | 434 | /* NOTE: It's ok to read values of output lines. */ |
435 | int ret = gpiod_get_array_value_complex(false, | 435 | int ret = gpiod_get_array_value_complex(false, |
436 | true, | 436 | true, |
437 | lh->numdescs, | 437 | lh->numdescs, |
@@ -449,7 +449,13 @@ static long linehandle_ioctl(struct file *filep, unsigned int cmd, | |||
449 | 449 | ||
450 | return 0; | 450 | return 0; |
451 | } else if (cmd == GPIOHANDLE_SET_LINE_VALUES_IOCTL) { | 451 | } else if (cmd == GPIOHANDLE_SET_LINE_VALUES_IOCTL) { |
452 | /* TODO: check if descriptors are really output */ | 452 | /* |
453 | * All line descriptors were created at once with the same | ||
454 | * flags so just check if the first one is really output. | ||
455 | */ | ||
456 | if (!test_bit(FLAG_IS_OUT, &lh->descs[0]->flags)) | ||
457 | return -EPERM; | ||
458 | |||
453 | if (copy_from_user(&ghd, ip, sizeof(ghd))) | 459 | if (copy_from_user(&ghd, ip, sizeof(ghd))) |
454 | return -EFAULT; | 460 | return -EFAULT; |
455 | 461 | ||
@@ -1256,6 +1262,8 @@ int gpiochip_add_data_with_key(struct gpio_chip *chip, void *data, | |||
1256 | /* If the gpiochip has an assigned OF node this takes precedence */ | 1262 | /* If the gpiochip has an assigned OF node this takes precedence */ |
1257 | if (chip->of_node) | 1263 | if (chip->of_node) |
1258 | gdev->dev.of_node = chip->of_node; | 1264 | gdev->dev.of_node = chip->of_node; |
1265 | else | ||
1266 | chip->of_node = gdev->dev.of_node; | ||
1259 | #endif | 1267 | #endif |
1260 | 1268 | ||
1261 | gdev->id = ida_simple_get(&gpio_ida, 0, 0, GFP_KERNEL); | 1269 | gdev->id = ida_simple_get(&gpio_ida, 0, 0, GFP_KERNEL); |
@@ -1408,9 +1416,9 @@ err_free_descs: | |||
1408 | err_free_gdev: | 1416 | err_free_gdev: |
1409 | ida_simple_remove(&gpio_ida, gdev->id); | 1417 | ida_simple_remove(&gpio_ida, gdev->id); |
1410 | /* failures here can mean systems won't boot... */ | 1418 | /* failures here can mean systems won't boot... */ |
1411 | pr_err("%s: GPIOs %d..%d (%s) failed to register\n", __func__, | 1419 | pr_err("%s: GPIOs %d..%d (%s) failed to register, %d\n", __func__, |
1412 | gdev->base, gdev->base + gdev->ngpio - 1, | 1420 | gdev->base, gdev->base + gdev->ngpio - 1, |
1413 | chip->label ? : "generic"); | 1421 | chip->label ? : "generic", status); |
1414 | kfree(gdev); | 1422 | kfree(gdev); |
1415 | return status; | 1423 | return status; |
1416 | } | 1424 | } |
@@ -1664,8 +1672,7 @@ static void gpiochip_set_cascaded_irqchip(struct gpio_chip *gpiochip, | |||
1664 | if (parent_handler) { | 1672 | if (parent_handler) { |
1665 | if (gpiochip->can_sleep) { | 1673 | if (gpiochip->can_sleep) { |
1666 | chip_err(gpiochip, | 1674 | chip_err(gpiochip, |
1667 | "you cannot have chained interrupts on a " | 1675 | "you cannot have chained interrupts on a chip that may sleep\n"); |
1668 | "chip that may sleep\n"); | ||
1669 | return; | 1676 | return; |
1670 | } | 1677 | } |
1671 | /* | 1678 | /* |
@@ -1800,16 +1807,18 @@ static const struct irq_domain_ops gpiochip_domain_ops = { | |||
1800 | static int gpiochip_irq_reqres(struct irq_data *d) | 1807 | static int gpiochip_irq_reqres(struct irq_data *d) |
1801 | { | 1808 | { |
1802 | struct gpio_chip *chip = irq_data_get_irq_chip_data(d); | 1809 | struct gpio_chip *chip = irq_data_get_irq_chip_data(d); |
1810 | int ret; | ||
1803 | 1811 | ||
1804 | if (!try_module_get(chip->gpiodev->owner)) | 1812 | if (!try_module_get(chip->gpiodev->owner)) |
1805 | return -ENODEV; | 1813 | return -ENODEV; |
1806 | 1814 | ||
1807 | if (gpiochip_lock_as_irq(chip, d->hwirq)) { | 1815 | ret = gpiochip_lock_as_irq(chip, d->hwirq); |
1816 | if (ret) { | ||
1808 | chip_err(chip, | 1817 | chip_err(chip, |
1809 | "unable to lock HW IRQ %lu for IRQ\n", | 1818 | "unable to lock HW IRQ %lu for IRQ\n", |
1810 | d->hwirq); | 1819 | d->hwirq); |
1811 | module_put(chip->gpiodev->owner); | 1820 | module_put(chip->gpiodev->owner); |
1812 | return -EINVAL; | 1821 | return ret; |
1813 | } | 1822 | } |
1814 | return 0; | 1823 | return 0; |
1815 | } | 1824 | } |
@@ -1850,8 +1859,7 @@ static int gpiochip_add_irqchip(struct gpio_chip *gpiochip, | |||
1850 | return 0; | 1859 | return 0; |
1851 | 1860 | ||
1852 | if (gpiochip->irq.parent_handler && gpiochip->can_sleep) { | 1861 | if (gpiochip->irq.parent_handler && gpiochip->can_sleep) { |
1853 | chip_err(gpiochip, "you cannot have chained interrupts on a " | 1862 | chip_err(gpiochip, "you cannot have chained interrupts on a chip that may sleep\n"); |
1854 | "chip that may sleep\n"); | ||
1855 | return -EINVAL; | 1863 | return -EINVAL; |
1856 | } | 1864 | } |
1857 | 1865 | ||
@@ -2259,6 +2267,7 @@ static int gpiod_request_commit(struct gpio_desc *desc, const char *label) | |||
2259 | struct gpio_chip *chip = desc->gdev->chip; | 2267 | struct gpio_chip *chip = desc->gdev->chip; |
2260 | int status; | 2268 | int status; |
2261 | unsigned long flags; | 2269 | unsigned long flags; |
2270 | unsigned offset; | ||
2262 | 2271 | ||
2263 | spin_lock_irqsave(&gpio_lock, flags); | 2272 | spin_lock_irqsave(&gpio_lock, flags); |
2264 | 2273 | ||
@@ -2277,7 +2286,11 @@ static int gpiod_request_commit(struct gpio_desc *desc, const char *label) | |||
2277 | if (chip->request) { | 2286 | if (chip->request) { |
2278 | /* chip->request may sleep */ | 2287 | /* chip->request may sleep */ |
2279 | spin_unlock_irqrestore(&gpio_lock, flags); | 2288 | spin_unlock_irqrestore(&gpio_lock, flags); |
2280 | status = chip->request(chip, gpio_chip_hwgpio(desc)); | 2289 | offset = gpio_chip_hwgpio(desc); |
2290 | if (gpiochip_line_is_valid(chip, offset)) | ||
2291 | status = chip->request(chip, offset); | ||
2292 | else | ||
2293 | status = -EINVAL; | ||
2281 | spin_lock_irqsave(&gpio_lock, flags); | 2294 | spin_lock_irqsave(&gpio_lock, flags); |
2282 | 2295 | ||
2283 | if (status < 0) { | 2296 | if (status < 0) { |
@@ -3194,6 +3207,19 @@ int gpiod_cansleep(const struct gpio_desc *desc) | |||
3194 | EXPORT_SYMBOL_GPL(gpiod_cansleep); | 3207 | EXPORT_SYMBOL_GPL(gpiod_cansleep); |
3195 | 3208 | ||
3196 | /** | 3209 | /** |
3210 | * gpiod_set_consumer_name() - set the consumer name for the descriptor | ||
3211 | * @desc: gpio to set the consumer name on | ||
3212 | * @name: the new consumer name | ||
3213 | */ | ||
3214 | void gpiod_set_consumer_name(struct gpio_desc *desc, const char *name) | ||
3215 | { | ||
3216 | VALIDATE_DESC_VOID(desc); | ||
3217 | /* Just overwrite whatever the previous name was */ | ||
3218 | desc->label = name; | ||
3219 | } | ||
3220 | EXPORT_SYMBOL_GPL(gpiod_set_consumer_name); | ||
3221 | |||
3222 | /** | ||
3197 | * gpiod_to_irq() - return the IRQ corresponding to a GPIO | 3223 | * gpiod_to_irq() - return the IRQ corresponding to a GPIO |
3198 | * @desc: gpio whose IRQ will be returned (already requested) | 3224 | * @desc: gpio whose IRQ will be returned (already requested) |
3199 | * | 3225 | * |
@@ -3249,18 +3275,19 @@ int gpiochip_lock_as_irq(struct gpio_chip *chip, unsigned int offset) | |||
3249 | * behind our back | 3275 | * behind our back |
3250 | */ | 3276 | */ |
3251 | if (!chip->can_sleep && chip->get_direction) { | 3277 | if (!chip->can_sleep && chip->get_direction) { |
3252 | int dir = chip->get_direction(chip, offset); | 3278 | int dir = gpiod_get_direction(desc); |
3253 | 3279 | ||
3254 | if (dir) | 3280 | if (dir < 0) { |
3255 | clear_bit(FLAG_IS_OUT, &desc->flags); | 3281 | chip_err(chip, "%s: cannot get GPIO direction\n", |
3256 | else | 3282 | __func__); |
3257 | set_bit(FLAG_IS_OUT, &desc->flags); | 3283 | return dir; |
3284 | } | ||
3258 | } | 3285 | } |
3259 | 3286 | ||
3260 | if (test_bit(FLAG_IS_OUT, &desc->flags)) { | 3287 | if (test_bit(FLAG_IS_OUT, &desc->flags)) { |
3261 | chip_err(chip, | 3288 | chip_err(chip, |
3262 | "%s: tried to flag a GPIO set as output for IRQ\n", | 3289 | "%s: tried to flag a GPIO set as output for IRQ\n", |
3263 | __func__); | 3290 | __func__); |
3264 | return -EIO; | 3291 | return -EIO; |
3265 | } | 3292 | } |
3266 | 3293 | ||
@@ -3639,9 +3666,16 @@ static struct gpio_desc *gpiod_find(struct device *dev, const char *con_id, | |||
3639 | chip = find_chip_by_name(p->chip_label); | 3666 | chip = find_chip_by_name(p->chip_label); |
3640 | 3667 | ||
3641 | if (!chip) { | 3668 | if (!chip) { |
3642 | dev_err(dev, "cannot find GPIO chip %s\n", | 3669 | /* |
3643 | p->chip_label); | 3670 | * As the lookup table indicates a chip with |
3644 | return ERR_PTR(-ENODEV); | 3671 | * p->chip_label should exist, assume it may |
3672 | * still appear later and let the interested | ||
3673 | * consumer be probed again or let the Deferred | ||
3674 | * Probe infrastructure handle the error. | ||
3675 | */ | ||
3676 | dev_warn(dev, "cannot find GPIO chip %s, deferring\n", | ||
3677 | p->chip_label); | ||
3678 | return ERR_PTR(-EPROBE_DEFER); | ||
3645 | } | 3679 | } |
3646 | 3680 | ||
3647 | if (chip->ngpio <= p->chip_hwnum) { | 3681 | if (chip->ngpio <= p->chip_hwnum) { |
@@ -4215,7 +4249,7 @@ static int __init gpiolib_dev_init(void) | |||
4215 | int ret; | 4249 | int ret; |
4216 | 4250 | ||
4217 | /* Register GPIO sysfs bus */ | 4251 | /* Register GPIO sysfs bus */ |
4218 | ret = bus_register(&gpio_bus_type); | 4252 | ret = bus_register(&gpio_bus_type); |
4219 | if (ret < 0) { | 4253 | if (ret < 0) { |
4220 | pr_err("gpiolib: could not register GPIO bus type\n"); | 4254 | pr_err("gpiolib: could not register GPIO bus type\n"); |
4221 | return ret; | 4255 | return ret; |
@@ -4259,9 +4293,7 @@ static void gpiolib_dbg_show(struct seq_file *s, struct gpio_device *gdev) | |||
4259 | seq_printf(s, " gpio-%-3d (%-20.20s|%-20.20s) %s %s %s", | 4293 | seq_printf(s, " gpio-%-3d (%-20.20s|%-20.20s) %s %s %s", |
4260 | gpio, gdesc->name ? gdesc->name : "", gdesc->label, | 4294 | gpio, gdesc->name ? gdesc->name : "", gdesc->label, |
4261 | is_out ? "out" : "in ", | 4295 | is_out ? "out" : "in ", |
4262 | chip->get | 4296 | chip->get ? (chip->get(chip, i) ? "hi" : "lo") : "? ", |
4263 | ? (chip->get(chip, i) ? "hi" : "lo") | ||
4264 | : "? ", | ||
4265 | is_irq ? "IRQ" : " "); | 4297 | is_irq ? "IRQ" : " "); |
4266 | seq_printf(s, "\n"); | 4298 | seq_printf(s, "\n"); |
4267 | } | 4299 | } |
diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h index 1a8e20363861..a7e49fef73d4 100644 --- a/drivers/gpio/gpiolib.h +++ b/drivers/gpio/gpiolib.h | |||
@@ -92,7 +92,7 @@ struct acpi_gpio_info { | |||
92 | }; | 92 | }; |
93 | 93 | ||
94 | /* gpio suffixes used for ACPI and device tree lookup */ | 94 | /* gpio suffixes used for ACPI and device tree lookup */ |
95 | static const char * const gpio_suffixes[] = { "gpios", "gpio" }; | 95 | static __maybe_unused const char * const gpio_suffixes[] = { "gpios", "gpio" }; |
96 | 96 | ||
97 | #ifdef CONFIG_OF_GPIO | 97 | #ifdef CONFIG_OF_GPIO |
98 | struct gpio_desc *of_find_gpio(struct device *dev, | 98 | struct gpio_desc *of_find_gpio(struct device *dev, |
diff --git a/drivers/w1/masters/Kconfig b/drivers/w1/masters/Kconfig index 1708b2300c7a..00827d2897b5 100644 --- a/drivers/w1/masters/Kconfig +++ b/drivers/w1/masters/Kconfig | |||
@@ -49,7 +49,7 @@ config W1_MASTER_DS1WM | |||
49 | 49 | ||
50 | config W1_MASTER_GPIO | 50 | config W1_MASTER_GPIO |
51 | tristate "GPIO 1-wire busmaster" | 51 | tristate "GPIO 1-wire busmaster" |
52 | depends on GPIOLIB | 52 | depends on GPIOLIB || COMPILE_TEST |
53 | help | 53 | help |
54 | Say Y here if you want to communicate with your 1-wire devices using | 54 | Say Y here if you want to communicate with your 1-wire devices using |
55 | GPIO pins. This driver uses the GPIO API to control the wire. | 55 | GPIO pins. This driver uses the GPIO API to control the wire. |
diff --git a/include/linux/gpio/aspeed.h b/include/linux/gpio/aspeed.h new file mode 100644 index 000000000000..1bfb3cdc86d0 --- /dev/null +++ b/include/linux/gpio/aspeed.h | |||
@@ -0,0 +1,15 @@ | |||
1 | #ifndef __GPIO_ASPEED_H | ||
2 | #define __GPIO_ASPEED_H | ||
3 | |||
4 | struct aspeed_gpio_copro_ops { | ||
5 | int (*request_access)(void *data); | ||
6 | int (*release_access)(void *data); | ||
7 | }; | ||
8 | |||
9 | int aspeed_gpio_copro_grab_gpio(struct gpio_desc *desc, | ||
10 | u16 *vreg_offset, u16 *dreg_offset, u8 *bit); | ||
11 | int aspeed_gpio_copro_release_gpio(struct gpio_desc *desc); | ||
12 | int aspeed_gpio_copro_set_ops(const struct aspeed_gpio_copro_ops *ops, void *data); | ||
13 | |||
14 | |||
15 | #endif /* __GPIO_ASPEED_H */ | ||
diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h index 243112c7fa7d..21ddbe440030 100644 --- a/include/linux/gpio/consumer.h +++ b/include/linux/gpio/consumer.h | |||
@@ -41,11 +41,8 @@ enum gpiod_flags { | |||
41 | GPIOD_OUT_LOW = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT, | 41 | GPIOD_OUT_LOW = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT, |
42 | GPIOD_OUT_HIGH = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT | | 42 | GPIOD_OUT_HIGH = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT | |
43 | GPIOD_FLAGS_BIT_DIR_VAL, | 43 | GPIOD_FLAGS_BIT_DIR_VAL, |
44 | GPIOD_OUT_LOW_OPEN_DRAIN = GPIOD_FLAGS_BIT_DIR_SET | | 44 | GPIOD_OUT_LOW_OPEN_DRAIN = GPIOD_OUT_LOW | GPIOD_FLAGS_BIT_OPEN_DRAIN, |
45 | GPIOD_FLAGS_BIT_DIR_OUT | GPIOD_FLAGS_BIT_OPEN_DRAIN, | 45 | GPIOD_OUT_HIGH_OPEN_DRAIN = GPIOD_OUT_HIGH | GPIOD_FLAGS_BIT_OPEN_DRAIN, |
46 | GPIOD_OUT_HIGH_OPEN_DRAIN = GPIOD_FLAGS_BIT_DIR_SET | | ||
47 | GPIOD_FLAGS_BIT_DIR_OUT | GPIOD_FLAGS_BIT_DIR_VAL | | ||
48 | GPIOD_FLAGS_BIT_OPEN_DRAIN, | ||
49 | }; | 46 | }; |
50 | 47 | ||
51 | #ifdef CONFIG_GPIOLIB | 48 | #ifdef CONFIG_GPIOLIB |
@@ -145,6 +142,7 @@ int gpiod_is_active_low(const struct gpio_desc *desc); | |||
145 | int gpiod_cansleep(const struct gpio_desc *desc); | 142 | int gpiod_cansleep(const struct gpio_desc *desc); |
146 | 143 | ||
147 | int gpiod_to_irq(const struct gpio_desc *desc); | 144 | int gpiod_to_irq(const struct gpio_desc *desc); |
145 | void gpiod_set_consumer_name(struct gpio_desc *desc, const char *name); | ||
148 | 146 | ||
149 | /* Convert between the old gpio_ and new gpiod_ interfaces */ | 147 | /* Convert between the old gpio_ and new gpiod_ interfaces */ |
150 | struct gpio_desc *gpio_to_desc(unsigned gpio); | 148 | struct gpio_desc *gpio_to_desc(unsigned gpio); |
@@ -467,6 +465,12 @@ static inline int gpiod_to_irq(const struct gpio_desc *desc) | |||
467 | return -EINVAL; | 465 | return -EINVAL; |
468 | } | 466 | } |
469 | 467 | ||
468 | static inline void gpiod_set_consumer_name(struct gpio_desc *desc, const char *name) | ||
469 | { | ||
470 | /* GPIO can never have been requested */ | ||
471 | WARN_ON(1); | ||
472 | } | ||
473 | |||
470 | static inline struct gpio_desc *gpio_to_desc(unsigned gpio) | 474 | static inline struct gpio_desc *gpio_to_desc(unsigned gpio) |
471 | { | 475 | { |
472 | return ERR_PTR(-EINVAL); | 476 | return ERR_PTR(-EINVAL); |
diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h index 5382b5183b7e..0ea328e71ec9 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h | |||
@@ -201,6 +201,8 @@ static inline struct gpio_irq_chip *to_gpio_irq_chip(struct irq_chip *chip) | |||
201 | * @reg_set: output set register (out=high) for generic GPIO | 201 | * @reg_set: output set register (out=high) for generic GPIO |
202 | * @reg_clr: output clear register (out=low) for generic GPIO | 202 | * @reg_clr: output clear register (out=low) for generic GPIO |
203 | * @reg_dir: direction setting register for generic GPIO | 203 | * @reg_dir: direction setting register for generic GPIO |
204 | * @bgpio_dir_inverted: indicates that the direction register is inverted | ||
205 | * (gpiolib private state variable) | ||
204 | * @bgpio_bits: number of register bits used for a generic GPIO i.e. | 206 | * @bgpio_bits: number of register bits used for a generic GPIO i.e. |
205 | * <register width> * 8 | 207 | * <register width> * 8 |
206 | * @bgpio_lock: used to lock chip->bgpio_data. Also, this is needed to keep | 208 | * @bgpio_lock: used to lock chip->bgpio_data. Also, this is needed to keep |
@@ -267,6 +269,7 @@ struct gpio_chip { | |||
267 | void __iomem *reg_set; | 269 | void __iomem *reg_set; |
268 | void __iomem *reg_clr; | 270 | void __iomem *reg_clr; |
269 | void __iomem *reg_dir; | 271 | void __iomem *reg_dir; |
272 | bool bgpio_dir_inverted; | ||
270 | int bgpio_bits; | 273 | int bgpio_bits; |
271 | spinlock_t bgpio_lock; | 274 | spinlock_t bgpio_lock; |
272 | unsigned long bgpio_data; | 275 | unsigned long bgpio_data; |
diff --git a/include/linux/platform_data/gpio-davinci.h b/include/linux/platform_data/gpio-davinci.h index 90ae19ca828f..57a5a35e0073 100644 --- a/include/linux/platform_data/gpio-davinci.h +++ b/include/linux/platform_data/gpio-davinci.h | |||
@@ -22,6 +22,7 @@ | |||
22 | #include <asm-generic/gpio.h> | 22 | #include <asm-generic/gpio.h> |
23 | 23 | ||
24 | #define MAX_REGS_BANKS 5 | 24 | #define MAX_REGS_BANKS 5 |
25 | #define MAX_INT_PER_BANK 32 | ||
25 | 26 | ||
26 | struct davinci_gpio_platform_data { | 27 | struct davinci_gpio_platform_data { |
27 | u32 ngpio; | 28 | u32 ngpio; |
@@ -41,7 +42,7 @@ struct davinci_gpio_controller { | |||
41 | spinlock_t lock; | 42 | spinlock_t lock; |
42 | void __iomem *regs[MAX_REGS_BANKS]; | 43 | void __iomem *regs[MAX_REGS_BANKS]; |
43 | int gpio_unbanked; | 44 | int gpio_unbanked; |
44 | unsigned int base_irq; | 45 | int irqs[MAX_INT_PER_BANK]; |
45 | unsigned int base; | 46 | unsigned int base; |
46 | }; | 47 | }; |
47 | 48 | ||
diff --git a/tools/testing/selftests/gpio/gpio-mockup-chardev.c b/tools/testing/selftests/gpio/gpio-mockup-chardev.c index 667e916fa7cc..f8d468f54e98 100644 --- a/tools/testing/selftests/gpio/gpio-mockup-chardev.c +++ b/tools/testing/selftests/gpio/gpio-mockup-chardev.c | |||
@@ -225,10 +225,10 @@ int gpio_pin_test(struct gpiochip_info *cinfo, int line, int flag, int value) | |||
225 | if (flag & GPIOHANDLE_REQUEST_ACTIVE_LOW) | 225 | if (flag & GPIOHANDLE_REQUEST_ACTIVE_LOW) |
226 | debugfs_value = !debugfs_value; | 226 | debugfs_value = !debugfs_value; |
227 | 227 | ||
228 | if (!(debugfs_dir == OUT && value == debugfs_value)) | 228 | if (!(debugfs_dir == OUT && value == debugfs_value)) { |
229 | errno = -EINVAL; | 229 | errno = -EINVAL; |
230 | ret = -errno; | 230 | ret = -errno; |
231 | 231 | } | |
232 | } | 232 | } |
233 | gpiotools_release_linehandle(fd); | 233 | gpiotools_release_linehandle(fd); |
234 | 234 | ||