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

Merge tag 'gpio-v4.19-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio

Pull GPIO updates from Linus Walleij:
"This is the bulk of GPIO changes for the v4.19 kernel cycle.

I don't know if anything in particular stands out. Maybe the Aspeed
coprocessor thing from Benji: Aspeed is doing baseboard management
chips (BMC's) for servers etc.

These Aspeed's are ARM processors that exist inside (I guess) Intel
servers, and they are moving forward to using mainline Linux in those.
This is one of the pieces of the puzzle to achive that. They are doing
OpenBMC, it's pretty cool: https://lwn.net/Articles/683320/

Summary:

Core changes:

- Add a new API for explicitly naming GPIO consumers, when needed.

- Don't let userspace set values on input lines. While we do not
think anyone would do this crazy thing we better plug the hole
before someone uses it and think it's a nifty feature.

- Avoid calling chip->request() for unused GPIOs.

New drivers/subdrivers:

- The Mediatek MT7621 is supported which is a big win for OpenWRT and
similar router distributions using this chip, as it seems every
major router manufacturer on the planet has made products using
this chip: https://wikidevi.com/wiki/MediaTek_MT7621

- The Tegra 194 is now supported.

- The IT87 driver now supports IT8786E and IT8718F super-IO chips.

- Add support for Rockchip RK3328 in the syscon GPIO driver.

Driver changes:

- Handle the get/set_multiple() properly on MMIO chips with inverted
direction registers. We didn't have this problem until a new chip
appear that has get/set registers AND inverted direction bits, OK
now we handle it.

- A patch series making more error codes percolate upward properly
for different errors on gpiochip_lock_as_irq().

- Get/set multiple for the OMAP driver, accelerating these multiple
line operations if possible.

- A coprocessor interface for the Aspeed driver. Sometimes a few GPIO
lines need to be grabbed by a co-processor for doing automated
tasks, sometimes they are available as GPIO lines. By adding an
explicit API in this driver we make it possible for the two line
consumers to coexist. (This work was made available on the
ib-aspeed branch, which may be appearing in other pull requests.)

- Implemented .get_direction() and open drain in the SCH311x driver.

- Continuing cleanup of included headers in GPIO drivers"

* tag 'gpio-v4.19-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio: (80 commits)
gpio: it87: Add support for IT8613
gpio: it87: add support for IT8718F Super I/O.
gpiolib: Avoid calling chip->request() for unused gpios
gpio: tegra: Include the right header
gpio: mmio: Fix up inverted direction registers
gpio: xilinx: Use the right include
gpio: timberdale: Include the right header
gpio: tb10x: Use the right include
gpiolib: Fix of_node inconsistency
gpio: vr41xx: Bail out on gpiochip_lock_as_irq() error
gpio: uniphier: Bail out on gpiochip_lock_as_irq() error
gpio: xgene-sb: Don't shadow error code of gpiochip_lock_as_irq()
gpio: em: Don't shadow error code of gpiochip_lock_as_irq()
gpio: dwapb: Don't shadow error code of gpiochip_lock_as_irq()
gpio: bcm-kona: Don't shadow error code of gpiochip_lock_as_irq()
gpiolib: Don't shadow error code of gpiochip_lock_as_irq()
gpio: syscon: rockchip: add GRF GPIO support for rk3328
gpio: omap: Add get/set_multiple() callbacks
gpio: pxa: remove set but not used variable 'gpio_offset'
gpio-it87: add support for IT8786E Super I/O
...

+1482 -275
+3
Documentation/devicetree/bindings/gpio/fsl-imx-gpio.txt
··· 19 19 4 = active high level-sensitive. 20 20 8 = active low level-sensitive. 21 21 22 + Optional properties: 23 + - clocks: the clock for clocking the GPIO silicon 24 + 22 25 Example: 23 26 24 27 gpio0: gpio@73f84000 {
+35
Documentation/devicetree/bindings/gpio/mediatek,mt7621-gpio.txt
··· 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 + };
+4
Documentation/devicetree/bindings/gpio/nvidia,tegra186-gpio.txt
··· 68 68 One of: 69 69 - "nvidia,tegra186-gpio". 70 70 - "nvidia,tegra186-gpio-aon". 71 + - "nvidia,tegra194-gpio". 72 + - "nvidia,tegra194-gpio-aon". 71 73 - reg-names 72 74 Array of strings. 73 75 Contains a list of names for the register spaces described by the reg ··· 93 91 depending on compatible value: 94 92 - "nvidia,tegra186-gpio": 6 entries. 95 93 - "nvidia,tegra186-gpio-aon": 1 entry. 94 + - "nvidia,tegra194-gpio": 6 entries. 95 + - "nvidia,tegra194-gpio-aon": 1 entry. 96 96 - gpio-controller 97 97 Boolean. 98 98 Marks the device node as a GPIO controller/provider.
+1
Documentation/devicetree/bindings/gpio/renesas,gpio-rcar.txt
··· 17 17 - "renesas,gpio-r8a7796": for R8A7796 (R-Car M3-W) compatible GPIO controller. 18 18 - "renesas,gpio-r8a77965": for R8A77965 (R-Car M3-N) compatible GPIO controller. 19 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 21 - "renesas,gpio-r8a77990": for R8A77990 (R-Car E3) compatible GPIO controller. 21 22 - "renesas,gpio-r8a77995": for R8A77995 (R-Car D3) compatible GPIO controller. 22 23 - "renesas,rcar-gen1-gpio": for a generic R-Car Gen1 GPIO controller.
+32
Documentation/devicetree/bindings/gpio/rockchip,rk3328-grf-gpio.txt
··· 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>.
+11 -1
drivers/gpio/Kconfig
··· 359 359 Say Y here if you're going to use hardware that connects to the 360 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 371 config GPIO_MVEBU 363 372 def_bool y 364 373 depends on PLAT_ORION || ARCH_MVEBU ··· 693 684 Say yes here to support GPIO functionality of IT87xx Super I/O chips. 694 685 695 686 This driver is tested with ITE IT8728 and IT8732 Super I/O chips, and 696 - supports the IT8761E, IT8620E and IT8628E Super I/O chip as well. 687 + supports the IT8761E, IT8613, IT8620E, and IT8628E Super I/O chips as 688 + well. 697 689 698 690 To compile this driver as a module, choose M here: the module will 699 691 be called gpio_it87
+1
drivers/gpio/Makefile
··· 88 88 obj-$(CONFIG_GPIO_MPC5200) += gpio-mpc5200.o 89 89 obj-$(CONFIG_GPIO_MPC8XXX) += gpio-mpc8xxx.o 90 90 obj-$(CONFIG_GPIO_MSIC) += gpio-msic.o 91 + obj-$(CONFIG_GPIO_MT7621) += gpio-mt7621.o 91 92 obj-$(CONFIG_GPIO_MVEBU) += gpio-mvebu.o 92 93 obj-$(CONFIG_GPIO_MXC) += gpio-mxc.o 93 94 obj-$(CONFIG_GPIO_MXS) += gpio-mxs.o
+369 -59
drivers/gpio/gpio-aspeed.c
··· 12 12 #include <asm/div64.h> 13 13 #include <linux/clk.h> 14 14 #include <linux/gpio/driver.h> 15 + #include <linux/gpio/aspeed.h> 15 16 #include <linux/hashtable.h> 16 17 #include <linux/init.h> 17 18 #include <linux/io.h> ··· 22 21 #include <linux/platform_device.h> 23 22 #include <linux/spinlock.h> 24 23 #include <linux/string.h> 24 + 25 + /* 26 + * These two headers aren't meant to be used by GPIO drivers. We need 27 + * them in order to access gpio_chip_hwgpio() which we need to implement 28 + * the aspeed specific API which allows the coprocessor to request 29 + * access to some GPIOs and to arbitrate between coprocessor and ARM. 30 + */ 31 + #include <linux/gpio/consumer.h> 32 + #include "gpiolib.h" 25 33 26 34 struct aspeed_bank_props { 27 35 unsigned int bank; ··· 66 56 struct clk *clk; 67 57 68 58 u32 *dcache; 59 + u8 *cf_copro_bankmap; 69 60 }; 70 61 71 62 struct aspeed_gpio_bank { 72 - uint16_t val_regs; 63 + uint16_t val_regs; /* +0: Rd: read input value, Wr: set write latch 64 + * +4: Rd/Wr: Direction (0=in, 1=out) 65 + */ 66 + uint16_t rdata_reg; /* Rd: read write latch, Wr: <none> */ 73 67 uint16_t irq_regs; 74 68 uint16_t debounce_regs; 75 69 uint16_t tolerance_regs; 70 + uint16_t cmdsrc_regs; 76 71 const char names[4][3]; 77 72 }; 78 73 74 + /* 75 + * Note: The "value" register returns the input value sampled on the 76 + * line even when the GPIO is configured as an output. Since 77 + * that input goes through synchronizers, writing, then reading 78 + * back may not return the written value right away. 79 + * 80 + * The "rdata" register returns the content of the write latch 81 + * and thus can be used to read back what was last written 82 + * reliably. 83 + */ 84 + 79 85 static const int debounce_timers[4] = { 0x00, 0x50, 0x54, 0x58 }; 86 + 87 + static const struct aspeed_gpio_copro_ops *copro_ops; 88 + static void *copro_data; 80 89 81 90 static const struct aspeed_gpio_bank aspeed_gpio_banks[] = { 82 91 { 83 92 .val_regs = 0x0000, 93 + .rdata_reg = 0x00c0, 84 94 .irq_regs = 0x0008, 85 95 .debounce_regs = 0x0040, 86 96 .tolerance_regs = 0x001c, 97 + .cmdsrc_regs = 0x0060, 87 98 .names = { "A", "B", "C", "D" }, 88 99 }, 89 100 { 90 101 .val_regs = 0x0020, 102 + .rdata_reg = 0x00c4, 91 103 .irq_regs = 0x0028, 92 104 .debounce_regs = 0x0048, 93 105 .tolerance_regs = 0x003c, 106 + .cmdsrc_regs = 0x0068, 94 107 .names = { "E", "F", "G", "H" }, 95 108 }, 96 109 { 97 110 .val_regs = 0x0070, 111 + .rdata_reg = 0x00c8, 98 112 .irq_regs = 0x0098, 99 113 .debounce_regs = 0x00b0, 100 114 .tolerance_regs = 0x00ac, 115 + .cmdsrc_regs = 0x0090, 101 116 .names = { "I", "J", "K", "L" }, 102 117 }, 103 118 { 104 119 .val_regs = 0x0078, 120 + .rdata_reg = 0x00cc, 105 121 .irq_regs = 0x00e8, 106 122 .debounce_regs = 0x0100, 107 123 .tolerance_regs = 0x00fc, 124 + .cmdsrc_regs = 0x00e0, 108 125 .names = { "M", "N", "O", "P" }, 109 126 }, 110 127 { 111 128 .val_regs = 0x0080, 129 + .rdata_reg = 0x00d0, 112 130 .irq_regs = 0x0118, 113 131 .debounce_regs = 0x0130, 114 132 .tolerance_regs = 0x012c, 133 + .cmdsrc_regs = 0x0110, 115 134 .names = { "Q", "R", "S", "T" }, 116 135 }, 117 136 { 118 137 .val_regs = 0x0088, 138 + .rdata_reg = 0x00d4, 119 139 .irq_regs = 0x0148, 120 140 .debounce_regs = 0x0160, 121 141 .tolerance_regs = 0x015c, 142 + .cmdsrc_regs = 0x0140, 122 143 .names = { "U", "V", "W", "X" }, 123 144 }, 124 145 { 125 146 .val_regs = 0x01E0, 147 + .rdata_reg = 0x00d8, 126 148 .irq_regs = 0x0178, 127 149 .debounce_regs = 0x0190, 128 150 .tolerance_regs = 0x018c, 151 + .cmdsrc_regs = 0x0170, 129 152 .names = { "Y", "Z", "AA", "AB" }, 130 153 }, 131 154 { 132 155 .val_regs = 0x01e8, 156 + .rdata_reg = 0x00dc, 133 157 .irq_regs = 0x01a8, 134 158 .debounce_regs = 0x01c0, 135 159 .tolerance_regs = 0x01bc, 160 + .cmdsrc_regs = 0x01a0, 136 161 .names = { "AC", "", "", "" }, 137 162 }, 138 163 }; 139 164 140 - #define GPIO_BANK(x) ((x) >> 5) 141 - #define GPIO_OFFSET(x) ((x) & 0x1f) 142 - #define GPIO_BIT(x) BIT(GPIO_OFFSET(x)) 165 + enum aspeed_gpio_reg { 166 + reg_val, 167 + reg_rdata, 168 + reg_dir, 169 + reg_irq_enable, 170 + reg_irq_type0, 171 + reg_irq_type1, 172 + reg_irq_type2, 173 + reg_irq_status, 174 + reg_debounce_sel1, 175 + reg_debounce_sel2, 176 + reg_tolerance, 177 + reg_cmdsrc0, 178 + reg_cmdsrc1, 179 + }; 143 180 144 - #define GPIO_DATA 0x00 145 - #define GPIO_DIR 0x04 181 + #define GPIO_VAL_VALUE 0x00 182 + #define GPIO_VAL_DIR 0x04 146 183 147 184 #define GPIO_IRQ_ENABLE 0x00 148 185 #define GPIO_IRQ_TYPE0 0x04 ··· 199 142 200 143 #define GPIO_DEBOUNCE_SEL1 0x00 201 144 #define GPIO_DEBOUNCE_SEL2 0x04 145 + 146 + #define GPIO_CMDSRC_0 0x00 147 + #define GPIO_CMDSRC_1 0x04 148 + #define GPIO_CMDSRC_ARM 0 149 + #define GPIO_CMDSRC_LPC 1 150 + #define GPIO_CMDSRC_COLDFIRE 2 151 + #define GPIO_CMDSRC_RESERVED 3 152 + 153 + /* This will be resolved at compile time */ 154 + static inline void __iomem *bank_reg(struct aspeed_gpio *gpio, 155 + const struct aspeed_gpio_bank *bank, 156 + const enum aspeed_gpio_reg reg) 157 + { 158 + switch (reg) { 159 + case reg_val: 160 + return gpio->base + bank->val_regs + GPIO_VAL_VALUE; 161 + case reg_rdata: 162 + return gpio->base + bank->rdata_reg; 163 + case reg_dir: 164 + return gpio->base + bank->val_regs + GPIO_VAL_DIR; 165 + case reg_irq_enable: 166 + return gpio->base + bank->irq_regs + GPIO_IRQ_ENABLE; 167 + case reg_irq_type0: 168 + return gpio->base + bank->irq_regs + GPIO_IRQ_TYPE0; 169 + case reg_irq_type1: 170 + return gpio->base + bank->irq_regs + GPIO_IRQ_TYPE1; 171 + case reg_irq_type2: 172 + return gpio->base + bank->irq_regs + GPIO_IRQ_TYPE2; 173 + case reg_irq_status: 174 + return gpio->base + bank->irq_regs + GPIO_IRQ_STATUS; 175 + case reg_debounce_sel1: 176 + return gpio->base + bank->debounce_regs + GPIO_DEBOUNCE_SEL1; 177 + case reg_debounce_sel2: 178 + return gpio->base + bank->debounce_regs + GPIO_DEBOUNCE_SEL2; 179 + case reg_tolerance: 180 + return gpio->base + bank->tolerance_regs; 181 + case reg_cmdsrc0: 182 + return gpio->base + bank->cmdsrc_regs + GPIO_CMDSRC_0; 183 + case reg_cmdsrc1: 184 + return gpio->base + bank->cmdsrc_regs + GPIO_CMDSRC_1; 185 + } 186 + BUG(); 187 + } 188 + 189 + #define GPIO_BANK(x) ((x) >> 5) 190 + #define GPIO_OFFSET(x) ((x) & 0x1f) 191 + #define GPIO_BIT(x) BIT(GPIO_OFFSET(x)) 202 192 203 193 #define _GPIO_SET_DEBOUNCE(t, o, i) ((!!((t) & BIT(i))) << GPIO_OFFSET(o)) 204 194 #define GPIO_SET_DEBOUNCE1(t, o) _GPIO_SET_DEBOUNCE(t, o, 1) ··· 305 201 return !props || (props->output & GPIO_BIT(offset)); 306 202 } 307 203 308 - static void __iomem *bank_val_reg(struct aspeed_gpio *gpio, 309 - const struct aspeed_gpio_bank *bank, 310 - unsigned int reg) 204 + static void aspeed_gpio_change_cmd_source(struct aspeed_gpio *gpio, 205 + const struct aspeed_gpio_bank *bank, 206 + int bindex, int cmdsrc) 311 207 { 312 - return gpio->base + bank->val_regs + reg; 208 + void __iomem *c0 = bank_reg(gpio, bank, reg_cmdsrc0); 209 + void __iomem *c1 = bank_reg(gpio, bank, reg_cmdsrc1); 210 + u32 bit, reg; 211 + 212 + /* 213 + * Each register controls 4 banks, so take the bottom 2 214 + * bits of the bank index, and use them to select the 215 + * right control bit (0, 8, 16 or 24). 216 + */ 217 + bit = BIT((bindex & 3) << 3); 218 + 219 + /* Source 1 first to avoid illegal 11 combination */ 220 + reg = ioread32(c1); 221 + if (cmdsrc & 2) 222 + reg |= bit; 223 + else 224 + reg &= ~bit; 225 + iowrite32(reg, c1); 226 + 227 + /* Then Source 0 */ 228 + reg = ioread32(c0); 229 + if (cmdsrc & 1) 230 + reg |= bit; 231 + else 232 + reg &= ~bit; 233 + iowrite32(reg, c0); 313 234 } 314 235 315 - static void __iomem *bank_irq_reg(struct aspeed_gpio *gpio, 316 - const struct aspeed_gpio_bank *bank, 317 - unsigned int reg) 236 + static bool aspeed_gpio_copro_request(struct aspeed_gpio *gpio, 237 + unsigned int offset) 318 238 { 319 - return gpio->base + bank->irq_regs + reg; 239 + const struct aspeed_gpio_bank *bank = to_bank(offset); 240 + 241 + if (!copro_ops || !gpio->cf_copro_bankmap) 242 + return false; 243 + if (!gpio->cf_copro_bankmap[offset >> 3]) 244 + return false; 245 + if (!copro_ops->request_access) 246 + return false; 247 + 248 + /* Pause the coprocessor */ 249 + copro_ops->request_access(copro_data); 250 + 251 + /* Change command source back to ARM */ 252 + aspeed_gpio_change_cmd_source(gpio, bank, offset >> 3, GPIO_CMDSRC_ARM); 253 + 254 + /* Update cache */ 255 + gpio->dcache[GPIO_BANK(offset)] = ioread32(bank_reg(gpio, bank, reg_rdata)); 256 + 257 + return true; 258 + } 259 + 260 + static void aspeed_gpio_copro_release(struct aspeed_gpio *gpio, 261 + unsigned int offset) 262 + { 263 + const struct aspeed_gpio_bank *bank = to_bank(offset); 264 + 265 + if (!copro_ops || !gpio->cf_copro_bankmap) 266 + return; 267 + if (!gpio->cf_copro_bankmap[offset >> 3]) 268 + return; 269 + if (!copro_ops->release_access) 270 + return; 271 + 272 + /* Change command source back to ColdFire */ 273 + aspeed_gpio_change_cmd_source(gpio, bank, offset >> 3, 274 + GPIO_CMDSRC_COLDFIRE); 275 + 276 + /* Restart the coprocessor */ 277 + copro_ops->release_access(copro_data); 320 278 } 321 279 322 280 static int aspeed_gpio_get(struct gpio_chip *gc, unsigned int offset) ··· 386 220 struct aspeed_gpio *gpio = gpiochip_get_data(gc); 387 221 const struct aspeed_gpio_bank *bank = to_bank(offset); 388 222 389 - return !!(ioread32(bank_val_reg(gpio, bank, GPIO_DATA)) 390 - & GPIO_BIT(offset)); 223 + return !!(ioread32(bank_reg(gpio, bank, reg_val)) & GPIO_BIT(offset)); 391 224 } 392 225 393 226 static void __aspeed_gpio_set(struct gpio_chip *gc, unsigned int offset, ··· 397 232 void __iomem *addr; 398 233 u32 reg; 399 234 400 - addr = bank_val_reg(gpio, bank, GPIO_DATA); 235 + addr = bank_reg(gpio, bank, reg_val); 401 236 reg = gpio->dcache[GPIO_BANK(offset)]; 402 237 403 238 if (val) ··· 414 249 { 415 250 struct aspeed_gpio *gpio = gpiochip_get_data(gc); 416 251 unsigned long flags; 252 + bool copro; 417 253 418 254 spin_lock_irqsave(&gpio->lock, flags); 255 + copro = aspeed_gpio_copro_request(gpio, offset); 419 256 420 257 __aspeed_gpio_set(gc, offset, val); 421 258 259 + if (copro) 260 + aspeed_gpio_copro_release(gpio, offset); 422 261 spin_unlock_irqrestore(&gpio->lock, flags); 423 262 } 424 263 ··· 430 261 { 431 262 struct aspeed_gpio *gpio = gpiochip_get_data(gc); 432 263 const struct aspeed_gpio_bank *bank = to_bank(offset); 264 + void __iomem *addr = bank_reg(gpio, bank, reg_dir); 433 265 unsigned long flags; 266 + bool copro; 434 267 u32 reg; 435 268 436 269 if (!have_input(gpio, offset)) ··· 440 269 441 270 spin_lock_irqsave(&gpio->lock, flags); 442 271 443 - reg = ioread32(bank_val_reg(gpio, bank, GPIO_DIR)); 444 - iowrite32(reg & ~GPIO_BIT(offset), bank_val_reg(gpio, bank, GPIO_DIR)); 272 + reg = ioread32(addr); 273 + reg &= ~GPIO_BIT(offset); 274 + 275 + copro = aspeed_gpio_copro_request(gpio, offset); 276 + iowrite32(reg, addr); 277 + if (copro) 278 + aspeed_gpio_copro_release(gpio, offset); 445 279 446 280 spin_unlock_irqrestore(&gpio->lock, flags); 447 281 ··· 458 282 { 459 283 struct aspeed_gpio *gpio = gpiochip_get_data(gc); 460 284 const struct aspeed_gpio_bank *bank = to_bank(offset); 285 + void __iomem *addr = bank_reg(gpio, bank, reg_dir); 461 286 unsigned long flags; 287 + bool copro; 462 288 u32 reg; 463 289 464 290 if (!have_output(gpio, offset)) ··· 468 290 469 291 spin_lock_irqsave(&gpio->lock, flags); 470 292 471 - __aspeed_gpio_set(gc, offset, val); 472 - reg = ioread32(bank_val_reg(gpio, bank, GPIO_DIR)); 473 - iowrite32(reg | GPIO_BIT(offset), bank_val_reg(gpio, bank, GPIO_DIR)); 293 + reg = ioread32(addr); 294 + reg |= GPIO_BIT(offset); 474 295 296 + copro = aspeed_gpio_copro_request(gpio, offset); 297 + __aspeed_gpio_set(gc, offset, val); 298 + iowrite32(reg, addr); 299 + 300 + if (copro) 301 + aspeed_gpio_copro_release(gpio, offset); 475 302 spin_unlock_irqrestore(&gpio->lock, flags); 476 303 477 304 return 0; ··· 497 314 498 315 spin_lock_irqsave(&gpio->lock, flags); 499 316 500 - val = ioread32(bank_val_reg(gpio, bank, GPIO_DIR)) & GPIO_BIT(offset); 317 + val = ioread32(bank_reg(gpio, bank, reg_dir)) & GPIO_BIT(offset); 501 318 502 319 spin_unlock_irqrestore(&gpio->lock, flags); 503 320 ··· 506 323 } 507 324 508 325 static inline int irqd_to_aspeed_gpio_data(struct irq_data *d, 509 - struct aspeed_gpio **gpio, 510 - const struct aspeed_gpio_bank **bank, 511 - u32 *bit) 326 + struct aspeed_gpio **gpio, 327 + const struct aspeed_gpio_bank **bank, 328 + u32 *bit, int *offset) 512 329 { 513 - int offset; 514 330 struct aspeed_gpio *internal; 515 331 516 - offset = irqd_to_hwirq(d); 332 + *offset = irqd_to_hwirq(d); 517 333 518 334 internal = irq_data_get_irq_chip_data(d); 519 335 520 336 /* This might be a bit of a questionable place to check */ 521 - if (!have_irq(internal, offset)) 337 + if (!have_irq(internal, *offset)) 522 338 return -ENOTSUPP; 523 339 524 340 *gpio = internal; 525 - *bank = to_bank(offset); 526 - *bit = GPIO_BIT(offset); 341 + *bank = to_bank(*offset); 342 + *bit = GPIO_BIT(*offset); 527 343 528 344 return 0; 529 345 } ··· 533 351 struct aspeed_gpio *gpio; 534 352 unsigned long flags; 535 353 void __iomem *status_addr; 354 + int rc, offset; 355 + bool copro; 536 356 u32 bit; 537 - int rc; 538 357 539 - rc = irqd_to_aspeed_gpio_data(d, &gpio, &bank, &bit); 358 + rc = irqd_to_aspeed_gpio_data(d, &gpio, &bank, &bit, &offset); 540 359 if (rc) 541 360 return; 542 361 543 - status_addr = bank_irq_reg(gpio, bank, GPIO_IRQ_STATUS); 362 + status_addr = bank_reg(gpio, bank, reg_irq_status); 544 363 545 364 spin_lock_irqsave(&gpio->lock, flags); 365 + copro = aspeed_gpio_copro_request(gpio, offset); 366 + 546 367 iowrite32(bit, status_addr); 368 + 369 + if (copro) 370 + aspeed_gpio_copro_release(gpio, offset); 547 371 spin_unlock_irqrestore(&gpio->lock, flags); 548 372 } 549 373 ··· 560 372 unsigned long flags; 561 373 u32 reg, bit; 562 374 void __iomem *addr; 563 - int rc; 375 + int rc, offset; 376 + bool copro; 564 377 565 - rc = irqd_to_aspeed_gpio_data(d, &gpio, &bank, &bit); 378 + rc = irqd_to_aspeed_gpio_data(d, &gpio, &bank, &bit, &offset); 566 379 if (rc) 567 380 return; 568 381 569 - addr = bank_irq_reg(gpio, bank, GPIO_IRQ_ENABLE); 382 + addr = bank_reg(gpio, bank, reg_irq_enable); 570 383 571 384 spin_lock_irqsave(&gpio->lock, flags); 385 + copro = aspeed_gpio_copro_request(gpio, offset); 572 386 573 387 reg = ioread32(addr); 574 388 if (set) ··· 579 389 reg &= ~bit; 580 390 iowrite32(reg, addr); 581 391 392 + if (copro) 393 + aspeed_gpio_copro_release(gpio, offset); 582 394 spin_unlock_irqrestore(&gpio->lock, flags); 583 395 } 584 396 ··· 605 413 struct aspeed_gpio *gpio; 606 414 unsigned long flags; 607 415 void __iomem *addr; 608 - int rc; 416 + int rc, offset; 417 + bool copro; 609 418 610 - rc = irqd_to_aspeed_gpio_data(d, &gpio, &bank, &bit); 419 + rc = irqd_to_aspeed_gpio_data(d, &gpio, &bank, &bit, &offset); 611 420 if (rc) 612 421 return -EINVAL; 613 422 ··· 634 441 } 635 442 636 443 spin_lock_irqsave(&gpio->lock, flags); 444 + copro = aspeed_gpio_copro_request(gpio, offset); 637 445 638 - addr = bank_irq_reg(gpio, bank, GPIO_IRQ_TYPE0); 446 + addr = bank_reg(gpio, bank, reg_irq_type0); 639 447 reg = ioread32(addr); 640 448 reg = (reg & ~bit) | type0; 641 449 iowrite32(reg, addr); 642 450 643 - addr = bank_irq_reg(gpio, bank, GPIO_IRQ_TYPE1); 451 + addr = bank_reg(gpio, bank, reg_irq_type1); 644 452 reg = ioread32(addr); 645 453 reg = (reg & ~bit) | type1; 646 454 iowrite32(reg, addr); 647 455 648 - addr = bank_irq_reg(gpio, bank, GPIO_IRQ_TYPE2); 456 + addr = bank_reg(gpio, bank, reg_irq_type2); 649 457 reg = ioread32(addr); 650 458 reg = (reg & ~bit) | type2; 651 459 iowrite32(reg, addr); 652 460 461 + if (copro) 462 + aspeed_gpio_copro_release(gpio, offset); 653 463 spin_unlock_irqrestore(&gpio->lock, flags); 654 464 655 465 irq_set_handler_locked(d, handler); ··· 673 477 for (i = 0; i < ARRAY_SIZE(aspeed_gpio_banks); i++) { 674 478 const struct aspeed_gpio_bank *bank = &aspeed_gpio_banks[i]; 675 479 676 - reg = ioread32(bank_irq_reg(data, bank, GPIO_IRQ_STATUS)); 480 + reg = ioread32(bank_reg(data, bank, reg_irq_status)); 677 481 678 482 for_each_set_bit(p, &reg, 32) { 679 483 girq = irq_find_mapping(gc->irq.domain, i * 32 + p); ··· 745 549 unsigned int offset, bool enable) 746 550 { 747 551 struct aspeed_gpio *gpio = gpiochip_get_data(chip); 748 - const struct aspeed_gpio_bank *bank; 749 552 unsigned long flags; 553 + void __iomem *treg; 554 + bool copro; 750 555 u32 val; 751 556 752 - bank = to_bank(offset); 557 + treg = bank_reg(gpio, to_bank(offset), reg_tolerance); 753 558 754 559 spin_lock_irqsave(&gpio->lock, flags); 755 - val = readl(gpio->base + bank->tolerance_regs); 560 + copro = aspeed_gpio_copro_request(gpio, offset); 561 + 562 + val = readl(treg); 756 563 757 564 if (enable) 758 565 val |= GPIO_BIT(offset); 759 566 else 760 567 val &= ~GPIO_BIT(offset); 761 568 762 - writel(val, gpio->base + bank->tolerance_regs); 569 + writel(val, treg); 570 + 571 + if (copro) 572 + aspeed_gpio_copro_release(gpio, offset); 763 573 spin_unlock_irqrestore(&gpio->lock, flags); 764 574 765 575 return 0; ··· 782 580 static void aspeed_gpio_free(struct gpio_chip *chip, unsigned int offset) 783 581 { 784 582 pinctrl_gpio_free(chip->base + offset); 785 - } 786 - 787 - static inline void __iomem *bank_debounce_reg(struct aspeed_gpio *gpio, 788 - const struct aspeed_gpio_bank *bank, 789 - unsigned int reg) 790 - { 791 - return gpio->base + bank->debounce_regs + reg; 792 583 } 793 584 794 585 static int usecs_to_cycles(struct aspeed_gpio *gpio, unsigned long usecs, ··· 861 666 void __iomem *addr; 862 667 u32 val; 863 668 864 - addr = bank_debounce_reg(gpio, bank, GPIO_DEBOUNCE_SEL1); 669 + /* Note: Debounce timer isn't under control of the command 670 + * source registers, so no need to sync with the coprocessor 671 + */ 672 + addr = bank_reg(gpio, bank, reg_debounce_sel1); 865 673 val = ioread32(addr); 866 674 iowrite32((val & ~mask) | GPIO_SET_DEBOUNCE1(timer, offset), addr); 867 675 868 - addr = bank_debounce_reg(gpio, bank, GPIO_DEBOUNCE_SEL2); 676 + addr = bank_reg(gpio, bank, reg_debounce_sel2); 869 677 val = ioread32(addr); 870 678 iowrite32((val & ~mask) | GPIO_SET_DEBOUNCE2(timer, offset), addr); 871 679 } ··· 1010 812 return -ENOTSUPP; 1011 813 } 1012 814 815 + /** 816 + * aspeed_gpio_copro_set_ops - Sets the callbacks used for handhsaking with 817 + * the coprocessor for shared GPIO banks 818 + * @ops: The callbacks 819 + * @data: Pointer passed back to the callbacks 820 + */ 821 + int aspeed_gpio_copro_set_ops(const struct aspeed_gpio_copro_ops *ops, void *data) 822 + { 823 + copro_data = data; 824 + copro_ops = ops; 825 + 826 + return 0; 827 + } 828 + EXPORT_SYMBOL_GPL(aspeed_gpio_copro_set_ops); 829 + 830 + /** 831 + * aspeed_gpio_copro_grab_gpio - Mark a GPIO used by the coprocessor. The entire 832 + * bank gets marked and any access from the ARM will 833 + * result in handshaking via callbacks. 834 + * @desc: The GPIO to be marked 835 + * @vreg_offset: If non-NULL, returns the value register offset in the GPIO space 836 + * @dreg_offset: If non-NULL, returns the data latch register offset in the GPIO space 837 + * @bit: If non-NULL, returns the bit number of the GPIO in the registers 838 + */ 839 + int aspeed_gpio_copro_grab_gpio(struct gpio_desc *desc, 840 + u16 *vreg_offset, u16 *dreg_offset, u8 *bit) 841 + { 842 + struct gpio_chip *chip = gpiod_to_chip(desc); 843 + struct aspeed_gpio *gpio = gpiochip_get_data(chip); 844 + int rc = 0, bindex, offset = gpio_chip_hwgpio(desc); 845 + const struct aspeed_gpio_bank *bank = to_bank(offset); 846 + unsigned long flags; 847 + 848 + if (!gpio->cf_copro_bankmap) 849 + gpio->cf_copro_bankmap = kzalloc(gpio->config->nr_gpios >> 3, GFP_KERNEL); 850 + if (!gpio->cf_copro_bankmap) 851 + return -ENOMEM; 852 + if (offset < 0 || offset > gpio->config->nr_gpios) 853 + return -EINVAL; 854 + bindex = offset >> 3; 855 + 856 + spin_lock_irqsave(&gpio->lock, flags); 857 + 858 + /* Sanity check, this shouldn't happen */ 859 + if (gpio->cf_copro_bankmap[bindex] == 0xff) { 860 + rc = -EIO; 861 + goto bail; 862 + } 863 + gpio->cf_copro_bankmap[bindex]++; 864 + 865 + /* Switch command source */ 866 + if (gpio->cf_copro_bankmap[bindex] == 1) 867 + aspeed_gpio_change_cmd_source(gpio, bank, bindex, 868 + GPIO_CMDSRC_COLDFIRE); 869 + 870 + if (vreg_offset) 871 + *vreg_offset = bank->val_regs; 872 + if (dreg_offset) 873 + *dreg_offset = bank->rdata_reg; 874 + if (bit) 875 + *bit = GPIO_OFFSET(offset); 876 + bail: 877 + spin_unlock_irqrestore(&gpio->lock, flags); 878 + return rc; 879 + } 880 + EXPORT_SYMBOL_GPL(aspeed_gpio_copro_grab_gpio); 881 + 882 + /** 883 + * aspeed_gpio_copro_release_gpio - Unmark a GPIO used by the coprocessor. 884 + * @desc: The GPIO to be marked 885 + */ 886 + int aspeed_gpio_copro_release_gpio(struct gpio_desc *desc) 887 + { 888 + struct gpio_chip *chip = gpiod_to_chip(desc); 889 + struct aspeed_gpio *gpio = gpiochip_get_data(chip); 890 + int rc = 0, bindex, offset = gpio_chip_hwgpio(desc); 891 + const struct aspeed_gpio_bank *bank = to_bank(offset); 892 + unsigned long flags; 893 + 894 + if (!gpio->cf_copro_bankmap) 895 + return -ENXIO; 896 + 897 + if (offset < 0 || offset > gpio->config->nr_gpios) 898 + return -EINVAL; 899 + bindex = offset >> 3; 900 + 901 + spin_lock_irqsave(&gpio->lock, flags); 902 + 903 + /* Sanity check, this shouldn't happen */ 904 + if (gpio->cf_copro_bankmap[bindex] == 0) { 905 + rc = -EIO; 906 + goto bail; 907 + } 908 + gpio->cf_copro_bankmap[bindex]--; 909 + 910 + /* Switch command source */ 911 + if (gpio->cf_copro_bankmap[bindex] == 0) 912 + aspeed_gpio_change_cmd_source(gpio, bank, bindex, 913 + GPIO_CMDSRC_ARM); 914 + bail: 915 + spin_unlock_irqrestore(&gpio->lock, flags); 916 + return rc; 917 + } 918 + EXPORT_SYMBOL_GPL(aspeed_gpio_copro_release_gpio); 919 + 1013 920 /* 1014 921 * Any banks not specified in a struct aspeed_bank_props array are assumed to 1015 922 * have the properties: ··· 1205 902 if (!gpio->dcache) 1206 903 return -ENOMEM; 1207 904 1208 - /* Populate it with initial values read from the HW */ 905 + /* 906 + * Populate it with initial values read from the HW and switch 907 + * all command sources to the ARM by default 908 + */ 1209 909 for (i = 0; i < banks; i++) { 1210 910 const struct aspeed_gpio_bank *bank = &aspeed_gpio_banks[i]; 1211 - gpio->dcache[i] = ioread32(gpio->base + bank->val_regs + 1212 - GPIO_DATA); 911 + void __iomem *addr = bank_reg(gpio, bank, reg_rdata); 912 + gpio->dcache[i] = ioread32(addr); 913 + aspeed_gpio_change_cmd_source(gpio, bank, 0, GPIO_CMDSRC_ARM); 914 + aspeed_gpio_change_cmd_source(gpio, bank, 1, GPIO_CMDSRC_ARM); 915 + aspeed_gpio_change_cmd_source(gpio, bank, 2, GPIO_CMDSRC_ARM); 916 + aspeed_gpio_change_cmd_source(gpio, bank, 3, GPIO_CMDSRC_ARM); 1213 917 } 1214 918 1215 919 rc = devm_gpiochip_add_data(&pdev->dev, &gpio->chip, gpio);
+1 -1
drivers/gpio/gpio-ath79.c
··· 51 51 static void ath79_gpio_write(struct ath79_gpio_ctrl *ctrl, 52 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 57 static bool ath79_gpio_update_bits(
+4 -2
drivers/gpio/gpio-bcm-kona.c
··· 485 485 static int bcm_kona_gpio_irq_reqres(struct irq_data *d) 486 486 { 487 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 492 dev_err(kona_gpio->gpio_chip.parent, 491 493 "unable to lock HW IRQ %lu for IRQ\n", 492 494 d->hwirq); 493 - return -EINVAL; 495 + return ret; 494 496 } 495 497 return 0; 496 498 }
+42 -28
drivers/gpio/gpio-davinci.c
··· 167 167 static int davinci_gpio_probe(struct platform_device *pdev) 168 168 { 169 169 static int ctrl_num, bank_base; 170 - int gpio, bank, ret = 0; 171 - unsigned ngpio, nbank; 170 + int gpio, bank, i, ret = 0; 171 + unsigned int ngpio, nbank, nirq; 172 172 struct davinci_gpio_controller *chips; 173 173 struct davinci_gpio_platform_data *pdata; 174 174 struct device *dev = &pdev->dev; ··· 197 197 if (WARN_ON(ARCH_NR_GPIOS < ngpio)) 198 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 210 nbank = DIV_ROUND_UP(ngpio, 32); 201 211 chips = devm_kcalloc(dev, 202 212 nbank, sizeof(struct davinci_gpio_controller), ··· 218 208 gpio_base = devm_ioremap_resource(dev, res); 219 209 if (IS_ERR(gpio_base)) 220 210 return PTR_ERR(gpio_base); 211 + 212 + for (i = 0; i < nirq; i++) { 213 + chips->irqs[i] = platform_get_irq(pdev, i); 214 + if (chips->irqs[i] < 0) { 215 + dev_info(dev, "IRQ not populated, err = %d\n", 216 + chips->irqs[i]); 217 + return chips->irqs[i]; 218 + } 219 + } 221 220 222 221 snprintf(label, MAX_LABEL_SIZE, "davinci_gpio.%d", ctrl_num++); 223 222 chips->chip.label = devm_kstrdup(dev, label, GFP_KERNEL); ··· 396 377 * can provide direct-mapped IRQs to AINTC (up to 32 GPIOs). 397 378 */ 398 379 if (offset < d->gpio_unbanked) 399 - return d->base_irq + offset; 380 + return d->irqs[offset]; 400 381 else 401 382 return -ENODEV; 402 383 } ··· 405 386 { 406 387 struct davinci_gpio_controller *d; 407 388 struct davinci_gpio_regs __iomem *g; 408 - u32 mask; 389 + u32 mask, i; 409 390 410 391 d = (struct davinci_gpio_controller *)irq_data_get_irq_handler_data(data); 411 392 g = (struct davinci_gpio_regs __iomem *)d->regs[0]; 412 - mask = __gpio_mask(data->irq - d->base_irq); 393 + for (i = 0; i < MAX_INT_PER_BANK; i++) 394 + if (data->irq == d->irqs[i]) 395 + break; 396 + 397 + if (i == MAX_INT_PER_BANK) 398 + return -EINVAL; 399 + 400 + mask = __gpio_mask(i); 413 401 414 402 if (trigger & ~(IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING)) 415 403 return -EINVAL; ··· 485 459 int ret; 486 460 struct clk *clk; 487 461 u32 binten = 0; 488 - unsigned ngpio, bank_irq; 462 + unsigned ngpio; 489 463 struct device *dev = &pdev->dev; 490 - struct resource *res; 491 464 struct davinci_gpio_controller *chips = platform_get_drvdata(pdev); 492 465 struct davinci_gpio_platform_data *pdata = dev->platform_data; 493 466 struct davinci_gpio_regs __iomem *g; ··· 506 481 gpio_get_irq_chip = (gpio_get_irq_chip_cb_t)match->data; 507 482 508 483 ngpio = pdata->ngpio; 509 - res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 510 - if (!res) { 511 - dev_err(dev, "Invalid IRQ resource\n"); 512 - return -EBUSY; 513 - } 514 - 515 - bank_irq = res->start; 516 - 517 - if (!bank_irq) { 518 - dev_err(dev, "Invalid IRQ resource\n"); 519 - return -ENODEV; 520 - } 521 484 522 485 clk = devm_clk_get(dev, "gpio"); 523 486 if (IS_ERR(clk)) { 524 487 dev_err(dev, "Error %ld getting gpio clock\n", PTR_ERR(clk)); 525 488 return PTR_ERR(clk); 526 489 } 490 + 527 491 ret = clk_prepare_enable(clk); 528 492 if (ret) 529 493 return ret; ··· 552 538 if (pdata->gpio_unbanked) { 553 539 /* pass "bank 0" GPIO IRQs to AINTC */ 554 540 chips->chip.to_irq = gpio_to_irq_unbanked; 555 - chips->base_irq = bank_irq; 556 541 chips->gpio_unbanked = pdata->gpio_unbanked; 557 542 binten = GENMASK(pdata->gpio_unbanked / 16, 0); 558 543 559 544 /* AINTC handles mask/unmask; GPIO handles triggering */ 560 - irq = bank_irq; 545 + irq = chips->irqs[0]; 561 546 irq_chip = gpio_get_irq_chip(irq); 562 547 irq_chip->name = "GPIO-AINTC"; 563 548 irq_chip->irq_set_type = gpio_irq_type_unbanked; ··· 567 554 writel_relaxed(~0, &g->set_rising); 568 555 569 556 /* set the direct IRQs up to use that irqchip */ 570 - for (gpio = 0; gpio < pdata->gpio_unbanked; gpio++, irq++) { 571 - irq_set_chip(irq, irq_chip); 572 - irq_set_handler_data(irq, chips); 573 - irq_set_status_flags(irq, IRQ_TYPE_EDGE_BOTH); 557 + for (gpio = 0; gpio < pdata->gpio_unbanked; gpio++) { 558 + irq_set_chip(chips->irqs[gpio], irq_chip); 559 + irq_set_handler_data(chips->irqs[gpio], chips); 560 + irq_set_status_flags(chips->irqs[gpio], 561 + IRQ_TYPE_EDGE_BOTH); 574 562 } 575 563 576 564 goto done; ··· 581 567 * Or, AINTC can handle IRQs for banks of 16 GPIO IRQs, which we 582 568 * then chain through our own handler. 583 569 */ 584 - for (gpio = 0, bank = 0; gpio < ngpio; bank++, bank_irq++, gpio += 16) { 570 + for (gpio = 0, bank = 0; gpio < ngpio; bank++, gpio += 16) { 585 571 /* disabled by default, enabled only as needed 586 572 * There are register sets for 32 GPIOs. 2 banks of 16 587 573 * GPIOs are covered by each set of registers hence divide by 2 ··· 608 594 irqdata->bank_num = bank; 609 595 irqdata->chip = chips; 610 596 611 - irq_set_chained_handler_and_data(bank_irq, gpio_irq_handler, 612 - irqdata); 597 + irq_set_chained_handler_and_data(chips->irqs[bank], 598 + gpio_irq_handler, irqdata); 613 599 614 600 binten |= BIT(bank); 615 601 }
+4 -2
drivers/gpio/gpio-dwapb.c
··· 255 255 struct irq_chip_generic *igc = irq_data_get_irq_chip_data(d); 256 256 struct dwapb_gpio *gpio = igc->private; 257 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 262 dev_err(gpio->dev, "unable to lock HW IRQ %lu for IRQ\n", 261 263 irqd_to_hwirq(d)); 262 - return -EINVAL; 264 + return ret; 263 265 } 264 266 return 0; 265 267 }
+4 -2
drivers/gpio/gpio-em.c
··· 101 101 static int em_gio_irq_reqres(struct irq_data *d) 102 102 { 103 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 108 dev_err(p->gpio_chip.parent, 107 109 "unable to lock HW IRQ %lu for IRQ\n", 108 110 irqd_to_hwirq(d)); 109 - return -EINVAL; 111 + return ret; 110 112 } 111 113 return 0; 112 114 }
+13
drivers/gpio/gpio-it87.c
··· 35 35 36 36 /* Chip Id numbers */ 37 37 #define NO_DEV_ID 0xffff 38 + #define IT8613_ID 0x8613 38 39 #define IT8620_ID 0x8620 39 40 #define IT8628_ID 0x8628 41 + #define IT8718_ID 0x8718 40 42 #define IT8728_ID 0x8728 41 43 #define IT8732_ID 0x8732 42 44 #define IT8761_ID 0x8761 43 45 #define IT8772_ID 0x8772 46 + #define IT8786_ID 0x8786 44 47 45 48 /* IO Ports */ 46 49 #define REG 0x2e ··· 309 306 it87_gpio->chip = it87_template_chip; 310 307 311 308 switch (chip_type) { 309 + case IT8613_ID: 310 + gpio_ba_reg = 0x62; 311 + it87_gpio->io_size = 8; /* it8613 only needs 6, use 8 for alignment */ 312 + it87_gpio->output_base = 0xc8; 313 + it87_gpio->simple_base = 0xc0; 314 + it87_gpio->simple_size = 6; 315 + it87_gpio->chip.ngpio = 64; /* has 48, use 64 for convenient calc */ 316 + break; 312 317 case IT8620_ID: 313 318 case IT8628_ID: 314 319 gpio_ba_reg = 0x62; ··· 325 314 it87_gpio->simple_size = 0; 326 315 it87_gpio->chip.ngpio = 64; 327 316 break; 317 + case IT8718_ID: 328 318 case IT8728_ID: 329 319 case IT8732_ID: 330 320 case IT8772_ID: 321 + case IT8786_ID: 331 322 gpio_ba_reg = 0x62; 332 323 it87_gpio->io_size = 8; 333 324 it87_gpio->output_base = 0xc8;
+12
drivers/gpio/gpio-max732x.c
··· 653 653 chip->client_group_a = client; 654 654 if (nr_port > 8) { 655 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 662 chip->client_group_b = chip->client_dummy = c; 657 663 } 658 664 break; ··· 666 660 chip->client_group_b = client; 667 661 if (nr_port > 8) { 668 662 c = i2c_new_dummy(client->adapter, addr_a); 663 + if (!c) { 664 + dev_err(&client->dev, 665 + "Failed to allocate I2C device\n"); 666 + ret = -ENODEV; 667 + goto out_failed; 668 + } 669 669 chip->client_group_a = chip->client_dummy = c; 670 670 } 671 671 break;
+2 -2
drivers/gpio/gpio-menz127.c
··· 56 56 rnd = fls(debounce) - 1; 57 57 58 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 60 else 61 - debounce = round_down(debounce, MEN_Z127_DB_MIN_US); 61 + debounce = rounddown(debounce, MEN_Z127_DB_MIN_US); 62 62 63 63 if (debounce > MEN_Z127_DB_MAX_US) 64 64 debounce = MEN_Z127_DB_MAX_US;
+2 -1
drivers/gpio/gpio-ml-ioh.c
··· 496 496 return 0; 497 497 498 498 err_gpiochip_add: 499 + chip = chip_save; 499 500 while (--i >= 0) { 500 - chip--; 501 501 gpiochip_remove(&chip->gpio); 502 + chip++; 502 503 } 503 504 kfree(chip_save); 504 505
+63 -45
drivers/gpio/gpio-mmio.c
··· 136 136 static int bgpio_get_set(struct gpio_chip *gc, unsigned int gpio) 137 137 { 138 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 153 return !!(gc->read_reg(gc->reg_set) & pinmask); 142 154 else 143 155 return !!(gc->read_reg(gc->reg_dat) & pinmask); ··· 169 157 *bits &= ~*mask; 170 158 171 159 /* Exploit the fact that we know which directions are set */ 172 - set_mask = *mask & gc->bgpio_dir; 173 - get_mask = *mask & ~gc->bgpio_dir; 160 + if (gc->bgpio_dir_inverted) { 161 + set_mask = *mask & ~gc->bgpio_dir; 162 + get_mask = *mask & gc->bgpio_dir; 163 + } else { 164 + set_mask = *mask & gc->bgpio_dir; 165 + get_mask = *mask & ~gc->bgpio_dir; 166 + } 174 167 175 168 if (set_mask) 176 169 *bits |= gc->read_reg(gc->reg_set) & set_mask; ··· 376 359 377 360 spin_lock_irqsave(&gc->bgpio_lock, flags); 378 361 379 - gc->bgpio_dir &= ~bgpio_line2mask(gc, gpio); 362 + if (gc->bgpio_dir_inverted) 363 + gc->bgpio_dir |= bgpio_line2mask(gc, gpio); 364 + else 365 + gc->bgpio_dir &= ~bgpio_line2mask(gc, gpio); 380 366 gc->write_reg(gc->reg_dir, gc->bgpio_dir); 381 367 382 368 spin_unlock_irqrestore(&gc->bgpio_lock, flags); ··· 390 370 static int bgpio_get_dir(struct gpio_chip *gc, unsigned int gpio) 391 371 { 392 372 /* Return 0 if output, 1 of input */ 393 - return !(gc->read_reg(gc->reg_dir) & bgpio_line2mask(gc, gpio)); 373 + if (gc->bgpio_dir_inverted) 374 + return !!(gc->read_reg(gc->reg_dir) & bgpio_line2mask(gc, gpio)); 375 + else 376 + return !(gc->read_reg(gc->reg_dir) & bgpio_line2mask(gc, gpio)); 394 377 } 395 378 396 379 static int bgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val) ··· 404 381 405 382 spin_lock_irqsave(&gc->bgpio_lock, flags); 406 383 407 - gc->bgpio_dir |= bgpio_line2mask(gc, gpio); 384 + if (gc->bgpio_dir_inverted) 385 + gc->bgpio_dir &= ~bgpio_line2mask(gc, gpio); 386 + else 387 + gc->bgpio_dir |= bgpio_line2mask(gc, gpio); 408 388 gc->write_reg(gc->reg_dir, gc->bgpio_dir); 409 389 410 390 spin_unlock_irqrestore(&gc->bgpio_lock, flags); 411 391 412 392 return 0; 413 - } 414 - 415 - static int bgpio_dir_in_inv(struct gpio_chip *gc, unsigned int gpio) 416 - { 417 - unsigned long flags; 418 - 419 - spin_lock_irqsave(&gc->bgpio_lock, flags); 420 - 421 - gc->bgpio_dir |= bgpio_line2mask(gc, gpio); 422 - gc->write_reg(gc->reg_dir, gc->bgpio_dir); 423 - 424 - spin_unlock_irqrestore(&gc->bgpio_lock, flags); 425 - 426 - return 0; 427 - } 428 - 429 - static int bgpio_dir_out_inv(struct gpio_chip *gc, unsigned int gpio, int val) 430 - { 431 - unsigned long flags; 432 - 433 - gc->set(gc, gpio, val); 434 - 435 - spin_lock_irqsave(&gc->bgpio_lock, flags); 436 - 437 - gc->bgpio_dir &= ~bgpio_line2mask(gc, gpio); 438 - gc->write_reg(gc->reg_dir, gc->bgpio_dir); 439 - 440 - spin_unlock_irqrestore(&gc->bgpio_lock, flags); 441 - 442 - return 0; 443 - } 444 - 445 - static int bgpio_get_dir_inv(struct gpio_chip *gc, unsigned int gpio) 446 - { 447 - /* Return 0 if output, 1 if input */ 448 - return !!(gc->read_reg(gc->reg_dir) & bgpio_line2mask(gc, gpio)); 449 393 } 450 394 451 395 static int bgpio_setup_accessors(struct device *dev, ··· 550 560 gc->get_direction = bgpio_get_dir; 551 561 } else if (dirin) { 552 562 gc->reg_dir = dirin; 553 - gc->direction_output = bgpio_dir_out_inv; 554 - gc->direction_input = bgpio_dir_in_inv; 555 - gc->get_direction = bgpio_get_dir_inv; 563 + gc->direction_output = bgpio_dir_out; 564 + gc->direction_input = bgpio_dir_in; 565 + gc->get_direction = bgpio_get_dir; 566 + gc->bgpio_dir_inverted = true; 556 567 } else { 557 568 if (flags & BGPIOF_NO_OUTPUT) 558 569 gc->direction_output = bgpio_dir_out_err; ··· 573 582 return -EINVAL; 574 583 } 575 584 585 + /** 586 + * bgpio_init() - Initialize generic GPIO accessor functions 587 + * @gc: the GPIO chip to set up 588 + * @dev: the parent device of the new GPIO chip (compulsory) 589 + * @sz: the size (width) of the MMIO registers in bytes, typically 1, 2 or 4 590 + * @dat: MMIO address for the register to READ the value of the GPIO lines, it 591 + * is expected that a 1 in the corresponding bit in this register means the 592 + * line is asserted 593 + * @set: MMIO address for the register to SET the value of the GPIO lines, it is 594 + * expected that we write the line with 1 in this register to drive the GPIO line 595 + * high. 596 + * @clr: MMIO address for the register to CLEAR the value of the GPIO lines, it is 597 + * expected that we write the line with 1 in this register to drive the GPIO line 598 + * low. It is allowed to leave this address as NULL, in that case the SET register 599 + * will be assumed to also clear the GPIO lines, by actively writing the line 600 + * with 0. 601 + * @dirout: MMIO address for the register to set the line as OUTPUT. It is assumed 602 + * that setting a line to 1 in this register will turn that line into an 603 + * output line. Conversely, setting the line to 0 will turn that line into 604 + * an input. Either this or @dirin can be defined, but never both. 605 + * @dirin: MMIO address for the register to set this line as INPUT. It is assumed 606 + * that setting a line to 1 in this register will turn that line into an 607 + * input line. Conversely, setting the line to 0 will turn that line into 608 + * an output. Either this or @dirout can be defined, but never both. 609 + * @flags: Different flags that will affect the behaviour of the device, such as 610 + * endianness etc. 611 + */ 576 612 int bgpio_init(struct gpio_chip *gc, struct device *dev, 577 613 unsigned long sz, void __iomem *dat, void __iomem *set, 578 614 void __iomem *clr, void __iomem *dirout, void __iomem *dirin,
+332
drivers/gpio/gpio-mt7621.c
··· 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);
+73
drivers/gpio/gpio-mxc.c
··· 45 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 57 struct mxc_gpio_port { 49 58 struct list_head node; 50 59 void __iomem *base; ··· 64 55 struct gpio_chip gc; 65 56 struct device *dev; 66 57 u32 both_edges; 58 + struct mxc_gpio_reg_saved gpio_saved_reg; 59 + bool power_off; 67 60 }; 68 61 69 62 static struct mxc_gpio_hwdata imx1_imx21_gpio_hwdata = { ··· 154 143 { .compatible = "fsl,imx21-gpio", .data = &mxc_gpio_devtype[IMX21_GPIO], }, 155 144 { .compatible = "fsl,imx31-gpio", .data = &mxc_gpio_devtype[IMX31_GPIO], }, 156 145 { .compatible = "fsl,imx35-gpio", .data = &mxc_gpio_devtype[IMX35_GPIO], }, 146 + { .compatible = "fsl,imx7d-gpio", .data = &mxc_gpio_devtype[IMX35_GPIO], }, 157 147 { /* sentinel */ } 158 148 }; 159 149 ··· 446 434 return err; 447 435 } 448 436 437 + if (of_device_is_compatible(np, "fsl,imx7d-gpio")) 438 + port->power_off = true; 439 + 449 440 /* disable the interrupt and clear the status */ 450 441 writel(0, port->base + GPIO_IMR); 451 442 writel(~0, port->base + GPIO_ISR); ··· 512 497 513 498 list_add_tail(&port->node, &mxc_gpio_ports); 514 499 500 + platform_set_drvdata(pdev, port); 501 + 515 502 return 0; 516 503 517 504 out_irqdomain_remove: ··· 524 507 return err; 525 508 } 526 509 510 + static void mxc_gpio_save_regs(struct mxc_gpio_port *port) 511 + { 512 + if (!port->power_off) 513 + return; 514 + 515 + port->gpio_saved_reg.icr1 = readl(port->base + GPIO_ICR1); 516 + port->gpio_saved_reg.icr2 = readl(port->base + GPIO_ICR2); 517 + port->gpio_saved_reg.imr = readl(port->base + GPIO_IMR); 518 + port->gpio_saved_reg.gdir = readl(port->base + GPIO_GDIR); 519 + port->gpio_saved_reg.edge_sel = readl(port->base + GPIO_EDGE_SEL); 520 + port->gpio_saved_reg.dr = readl(port->base + GPIO_DR); 521 + } 522 + 523 + static void mxc_gpio_restore_regs(struct mxc_gpio_port *port) 524 + { 525 + if (!port->power_off) 526 + return; 527 + 528 + writel(port->gpio_saved_reg.icr1, port->base + GPIO_ICR1); 529 + writel(port->gpio_saved_reg.icr2, port->base + GPIO_ICR2); 530 + writel(port->gpio_saved_reg.imr, port->base + GPIO_IMR); 531 + writel(port->gpio_saved_reg.gdir, port->base + GPIO_GDIR); 532 + writel(port->gpio_saved_reg.edge_sel, port->base + GPIO_EDGE_SEL); 533 + writel(port->gpio_saved_reg.dr, port->base + GPIO_DR); 534 + } 535 + 536 + static int __maybe_unused mxc_gpio_noirq_suspend(struct device *dev) 537 + { 538 + struct platform_device *pdev = to_platform_device(dev); 539 + struct mxc_gpio_port *port = platform_get_drvdata(pdev); 540 + 541 + mxc_gpio_save_regs(port); 542 + clk_disable_unprepare(port->clk); 543 + 544 + return 0; 545 + } 546 + 547 + static int __maybe_unused mxc_gpio_noirq_resume(struct device *dev) 548 + { 549 + struct platform_device *pdev = to_platform_device(dev); 550 + struct mxc_gpio_port *port = platform_get_drvdata(pdev); 551 + int ret; 552 + 553 + ret = clk_prepare_enable(port->clk); 554 + if (ret) 555 + return ret; 556 + mxc_gpio_restore_regs(port); 557 + 558 + return 0; 559 + } 560 + 561 + static const struct dev_pm_ops mxc_gpio_dev_pm_ops = { 562 + SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(mxc_gpio_noirq_suspend, mxc_gpio_noirq_resume) 563 + }; 564 + 527 565 static struct platform_driver mxc_gpio_driver = { 528 566 .driver = { 529 567 .name = "gpio-mxc", 530 568 .of_match_table = mxc_gpio_dt_ids, 531 569 .suppress_bind_attrs = true, 570 + .pm = &mxc_gpio_dev_pm_ops, 532 571 }, 533 572 .probe = mxc_gpio_probe, 534 573 .id_table = mxc_gpio_devtype,
+1 -2
drivers/gpio/gpio-mxs.c
··· 126 126 else 127 127 writel(pin_mask, pin_addr + MXS_CLR); 128 128 129 - writel(pin_mask, 130 - port->base + PINCTRL_IRQSTAT(port) + MXS_CLR); 129 + writel(pin_mask, port->base + PINCTRL_IRQSTAT(port) + MXS_CLR); 131 130 132 131 return 0; 133 132 }
+86 -2
drivers/gpio/gpio-omap.c
··· 77 77 bool workaround_enabled; 78 78 79 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 82 int (*get_context_loss_count)(struct device *dev); 81 83 82 84 struct omap_gpio_reg_offs *regs; ··· 161 159 void __iomem *reg = bank->base + bank->regs->dataout; 162 160 163 161 return (readl_relaxed(reg) & (BIT(offset))) != 0; 162 + } 163 + 164 + /* set multiple data out values using dedicate set/clear register */ 165 + static void omap_set_gpio_dataout_reg_multiple(struct gpio_bank *bank, 166 + unsigned long *mask, 167 + unsigned long *bits) 168 + { 169 + void __iomem *reg = bank->base; 170 + u32 l; 171 + 172 + l = *bits & *mask; 173 + writel_relaxed(l, reg + bank->regs->set_dataout); 174 + bank->context.dataout |= l; 175 + 176 + l = ~*bits & *mask; 177 + writel_relaxed(l, reg + bank->regs->clr_dataout); 178 + bank->context.dataout &= ~l; 179 + } 180 + 181 + /* set multiple data out values using mask register */ 182 + static void omap_set_gpio_dataout_mask_multiple(struct gpio_bank *bank, 183 + unsigned long *mask, 184 + unsigned long *bits) 185 + { 186 + void __iomem *reg = bank->base + bank->regs->dataout; 187 + u32 l = (readl_relaxed(reg) & ~*mask) | (*bits & *mask); 188 + 189 + writel_relaxed(l, reg); 190 + bank->context.dataout = l; 191 + } 192 + 193 + static unsigned long omap_get_gpio_datain_multiple(struct gpio_bank *bank, 194 + unsigned long *mask) 195 + { 196 + void __iomem *reg = bank->base + bank->regs->datain; 197 + 198 + return readl_relaxed(reg) & *mask; 199 + } 200 + 201 + static unsigned long omap_get_gpio_dataout_multiple(struct gpio_bank *bank, 202 + unsigned long *mask) 203 + { 204 + void __iomem *reg = bank->base + bank->regs->dataout; 205 + 206 + return readl_relaxed(reg) & *mask; 164 207 } 165 208 166 209 static inline void omap_gpio_rmw(void __iomem *base, u32 reg, u32 mask, bool set) ··· 1015 968 return 0; 1016 969 } 1017 970 971 + static int omap_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask, 972 + unsigned long *bits) 973 + { 974 + struct gpio_bank *bank = gpiochip_get_data(chip); 975 + void __iomem *reg = bank->base + bank->regs->direction; 976 + unsigned long in = readl_relaxed(reg), l; 977 + 978 + *bits = 0; 979 + 980 + l = in & *mask; 981 + if (l) 982 + *bits |= omap_get_gpio_datain_multiple(bank, &l); 983 + 984 + l = ~in & *mask; 985 + if (l) 986 + *bits |= omap_get_gpio_dataout_multiple(bank, &l); 987 + 988 + return 0; 989 + } 990 + 1018 991 static int omap_gpio_debounce(struct gpio_chip *chip, unsigned offset, 1019 992 unsigned debounce) 1020 993 { ··· 1076 1009 bank = gpiochip_get_data(chip); 1077 1010 raw_spin_lock_irqsave(&bank->lock, flags); 1078 1011 bank->set_dataout(bank, offset, value); 1012 + raw_spin_unlock_irqrestore(&bank->lock, flags); 1013 + } 1014 + 1015 + static void omap_gpio_set_multiple(struct gpio_chip *chip, unsigned long *mask, 1016 + unsigned long *bits) 1017 + { 1018 + struct gpio_bank *bank = gpiochip_get_data(chip); 1019 + unsigned long flags; 1020 + 1021 + raw_spin_lock_irqsave(&bank->lock, flags); 1022 + bank->set_dataout_multiple(bank, mask, bits); 1079 1023 raw_spin_unlock_irqrestore(&bank->lock, flags); 1080 1024 } 1081 1025 ··· 1151 1073 bank->chip.get_direction = omap_gpio_get_direction; 1152 1074 bank->chip.direction_input = omap_gpio_input; 1153 1075 bank->chip.get = omap_gpio_get; 1076 + bank->chip.get_multiple = omap_gpio_get_multiple; 1154 1077 bank->chip.direction_output = omap_gpio_output; 1155 1078 bank->chip.set_config = omap_gpio_set_config; 1156 1079 bank->chip.set = omap_gpio_set; 1080 + bank->chip.set_multiple = omap_gpio_set_multiple; 1157 1081 if (bank->is_mpuio) { 1158 1082 bank->chip.label = "mpuio"; 1159 1083 if (bank->regs->wkup_en) ··· 1289 1209 pdata->get_context_loss_count; 1290 1210 } 1291 1211 1292 - if (bank->regs->set_dataout && bank->regs->clr_dataout) 1212 + if (bank->regs->set_dataout && bank->regs->clr_dataout) { 1293 1213 bank->set_dataout = omap_set_gpio_dataout_reg; 1294 - else 1214 + bank->set_dataout_multiple = omap_set_gpio_dataout_reg_multiple; 1215 + } else { 1295 1216 bank->set_dataout = omap_set_gpio_dataout_mask; 1217 + bank->set_dataout_multiple = 1218 + omap_set_gpio_dataout_mask_multiple; 1219 + } 1296 1220 1297 1221 raw_spin_lock_init(&bank->lock); 1298 1222 raw_spin_lock_init(&bank->wa_lock);
+1 -1
drivers/gpio/gpio-pca953x.c
··· 708 708 { 709 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 712 dev_warn(&client->dev, "interrupt support not compiled in\n"); 713 713 714 714 return 0;
+22
drivers/gpio/gpio-pisosr.c
··· 12 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 17 #include <linux/delay.h> 16 18 #include <linux/gpio/consumer.h> 17 19 #include <linux/gpio/driver.h> ··· 92 90 return (gpio->buffer[offset / 8] >> (offset % 8)) & 0x1; 93 91 } 94 92 93 + static int pisosr_gpio_get_multiple(struct gpio_chip *chip, 94 + unsigned long *mask, unsigned long *bits) 95 + { 96 + struct pisosr_gpio *gpio = gpiochip_get_data(chip); 97 + unsigned int nbytes = DIV_ROUND_UP(chip->ngpio, 8); 98 + unsigned int i, j; 99 + 100 + pisosr_gpio_refresh(gpio); 101 + 102 + bitmap_zero(bits, chip->ngpio); 103 + for (i = 0; i < nbytes; i++) { 104 + j = i / sizeof(unsigned long); 105 + bits[j] |= ((unsigned long) gpio->buffer[i]) 106 + << (8 * (i % sizeof(unsigned long))); 107 + } 108 + 109 + return 0; 110 + } 111 + 95 112 static const struct gpio_chip template_chip = { 96 113 .label = "pisosr-gpio", 97 114 .owner = THIS_MODULE, ··· 118 97 .direction_input = pisosr_gpio_direction_input, 119 98 .direction_output = pisosr_gpio_direction_output, 120 99 .get = pisosr_gpio_get, 100 + .get_multiple = pisosr_gpio_get_multiple, 121 101 .base = -1, 122 102 .ngpio = DEFAULT_NGPIO, 123 103 .can_sleep = true,
+30 -12
drivers/gpio/gpio-pxa.c
··· 241 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 255 static int pxa_gpio_to_irq(struct gpio_chip *chip, unsigned offset) 245 256 { 246 257 struct pxa_gpio_chip *pchip = chip_to_pxachip(chip); ··· 266 255 unsigned long flags; 267 256 int ret; 268 257 269 - ret = pinctrl_gpio_direction_input(chip->base + offset); 270 - if (!ret) 271 - return 0; 258 + if (pxa_gpio_has_pinctrl()) { 259 + ret = pinctrl_gpio_direction_input(chip->base + offset); 260 + if (!ret) 261 + return 0; 262 + } 272 263 273 264 spin_lock_irqsave(&gpio_lock, flags); 274 265 ··· 295 282 296 283 writel_relaxed(mask, base + (value ? GPSR_OFFSET : GPCR_OFFSET)); 297 284 298 - ret = pinctrl_gpio_direction_output(chip->base + offset); 299 - if (ret) 300 - return ret; 285 + if (pxa_gpio_has_pinctrl()) { 286 + ret = pinctrl_gpio_direction_output(chip->base + offset); 287 + if (ret) 288 + return ret; 289 + } 301 290 302 291 spin_lock_irqsave(&gpio_lock, flags); 303 292 ··· 363 348 pchip->chip.set = pxa_gpio_set; 364 349 pchip->chip.to_irq = pxa_gpio_to_irq; 365 350 pchip->chip.ngpio = ngpio; 366 - pchip->chip.request = gpiochip_generic_request; 367 - pchip->chip.free = gpiochip_generic_free; 351 + 352 + if (pxa_gpio_has_pinctrl()) { 353 + pchip->chip.request = gpiochip_generic_request; 354 + pchip->chip.free = gpiochip_generic_free; 355 + } 356 + 368 357 #ifdef CONFIG_OF_GPIO 369 358 pchip->chip.of_node = np; 370 359 pchip->chip.of_xlate = pxa_gpio_of_xlate; ··· 626 607 struct pxa_gpio_platform_data *info; 627 608 void __iomem *gpio_reg_base; 628 609 int gpio, ret; 629 - int irq0 = 0, irq1 = 0, irq_mux, gpio_offset = 0; 610 + int irq0 = 0, irq1 = 0, irq_mux; 630 611 631 612 pchip = devm_kzalloc(&pdev->dev, sizeof(*pchip), GFP_KERNEL); 632 613 if (!pchip) ··· 665 646 pchip->irq0 = irq0; 666 647 pchip->irq1 = irq1; 667 648 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 649 + if (!res) 650 + return -EINVAL; 668 651 gpio_reg_base = devm_ioremap(&pdev->dev, res->start, 669 652 resource_size(res)); 670 653 if (!gpio_reg_base) 671 654 return -EINVAL; 672 - 673 - if (irq0 > 0) 674 - gpio_offset = 2; 675 655 676 656 clk = clk_get(&pdev->dev, NULL); 677 657 if (IS_ERR(clk)) {
+1 -1
drivers/gpio/gpio-rc5t583.c
··· 25 25 #include <linux/slab.h> 26 26 #include <linux/platform_device.h> 27 27 #include <linux/device.h> 28 - #include <linux/gpio.h> 28 + #include <linux/gpio/driver.h> 29 29 #include <linux/mfd/rc5t583.h> 30 30 31 31 struct rc5t583_gpio {
+9 -1
drivers/gpio/gpio-rcar.c
··· 15 15 */ 16 16 17 17 #include <linux/err.h> 18 - #include <linux/gpio.h> 18 + #include <linux/gpio/driver.h> 19 19 #include <linux/init.h> 20 20 #include <linux/interrupt.h> 21 21 #include <linux/io.h> ··· 278 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 288 static int gpio_rcar_direction_input(struct gpio_chip *chip, unsigned offset) 282 289 { 283 290 gpio_rcar_config_general_input_output_mode(chip, offset, false); ··· 468 461 gpio_chip = &p->gpio_chip; 469 462 gpio_chip->request = gpio_rcar_request; 470 463 gpio_chip->free = gpio_rcar_free; 464 + gpio_chip->get_direction = gpio_rcar_get_direction; 471 465 gpio_chip->direction_input = gpio_rcar_direction_input; 472 466 gpio_chip->get = gpio_rcar_get; 473 467 gpio_chip->direction_output = gpio_rcar_direction_output;
+1 -1
drivers/gpio/gpio-rdc321x.c
··· 25 25 #include <linux/spinlock.h> 26 26 #include <linux/platform_device.h> 27 27 #include <linux/pci.h> 28 - #include <linux/gpio.h> 28 + #include <linux/gpio/driver.h> 29 29 #include <linux/mfd/rdc321x.h> 30 30 #include <linux/slab.h> 31 31
+1 -1
drivers/gpio/gpio-sa1100.c
··· 7 7 * it under the terms of the GNU General Public License version 2 as 8 8 * published by the Free Software Foundation. 9 9 */ 10 - #include <linux/gpio.h> 10 + #include <linux/gpio/driver.h> 11 11 #include <linux/init.h> 12 12 #include <linux/module.h> 13 13 #include <linux/io.h>
+9 -2
drivers/gpio/gpio-sch.c
··· 26 26 #include <linux/acpi.h> 27 27 #include <linux/platform_device.h> 28 28 #include <linux/pci_ids.h> 29 - 30 - #include <linux/gpio.h> 29 + #include <linux/gpio/driver.h> 31 30 32 31 #define GEN 0x00 33 32 #define GIO 0x04 ··· 137 138 return 0; 138 139 } 139 140 141 + static int sch_gpio_get_direction(struct gpio_chip *gc, unsigned gpio_num) 142 + { 143 + struct sch_gpio *sch = gpiochip_get_data(gc); 144 + 145 + return sch_gpio_reg_get(sch, gpio_num, GIO); 146 + } 147 + 140 148 static const struct gpio_chip sch_gpio_chip = { 141 149 .label = "sch_gpio", 142 150 .owner = THIS_MODULE, ··· 151 145 .get = sch_gpio_get, 152 146 .direction_output = sch_gpio_direction_out, 153 147 .set = sch_gpio_set, 148 + .get_direction = sch_gpio_get_direction, 154 149 }; 155 150 156 151 static int sch_gpio_probe(struct platform_device *pdev)
+57 -13
drivers/gpio/gpio-sch311x.c
··· 17 17 #include <linux/kernel.h> 18 18 #include <linux/init.h> 19 19 #include <linux/platform_device.h> 20 - #include <linux/gpio.h> 20 + #include <linux/gpio/driver.h> 21 21 #include <linux/bitops.h> 22 22 #include <linux/io.h> 23 23 24 24 #define DRV_NAME "gpio-sch311x" 25 25 26 - #define SCH311X_GPIO_CONF_OUT 0x00 27 - #define SCH311X_GPIO_CONF_IN 0x01 28 - #define SCH311X_GPIO_CONF_INVERT 0x02 29 - #define SCH311X_GPIO_CONF_OPEN_DRAIN 0x80 26 + #define SCH311X_GPIO_CONF_DIR BIT(0) 27 + #define SCH311X_GPIO_CONF_INVERT BIT(1) 28 + #define SCH311X_GPIO_CONF_OPEN_DRAIN BIT(7) 30 29 31 30 #define SIO_CONFIG_KEY_ENTER 0x55 32 31 #define SIO_CONFIG_KEY_EXIT 0xaa ··· 162 163 static int sch311x_gpio_get(struct gpio_chip *chip, unsigned offset) 163 164 { 164 165 struct sch311x_gpio_block *block = gpiochip_get_data(chip); 165 - unsigned char data; 166 + u8 data; 166 167 167 168 spin_lock(&block->lock); 168 169 data = inb(block->runtime_reg + block->data_reg); ··· 174 175 static void __sch311x_gpio_set(struct sch311x_gpio_block *block, 175 176 unsigned offset, int value) 176 177 { 177 - unsigned char data = inb(block->runtime_reg + block->data_reg); 178 + u8 data = inb(block->runtime_reg + block->data_reg); 178 179 if (value) 179 180 data |= BIT(offset); 180 181 else ··· 195 196 static int sch311x_gpio_direction_in(struct gpio_chip *chip, unsigned offset) 196 197 { 197 198 struct sch311x_gpio_block *block = gpiochip_get_data(chip); 199 + u8 data; 198 200 199 201 spin_lock(&block->lock); 200 - outb(SCH311X_GPIO_CONF_IN, block->runtime_reg + 201 - block->config_regs[offset]); 202 + data = inb(block->runtime_reg + block->config_regs[offset]); 203 + data |= SCH311X_GPIO_CONF_DIR; 204 + outb(data, block->runtime_reg + block->config_regs[offset]); 202 205 spin_unlock(&block->lock); 203 206 204 207 return 0; ··· 210 209 int value) 211 210 { 212 211 struct sch311x_gpio_block *block = gpiochip_get_data(chip); 212 + u8 data; 213 213 214 214 spin_lock(&block->lock); 215 215 216 - outb(SCH311X_GPIO_CONF_OUT, block->runtime_reg + 217 - block->config_regs[offset]); 218 - 216 + data = inb(block->runtime_reg + block->config_regs[offset]); 217 + data &= ~SCH311X_GPIO_CONF_DIR; 218 + outb(data, block->runtime_reg + block->config_regs[offset]); 219 219 __sch311x_gpio_set(block, offset, value); 220 220 221 221 spin_unlock(&block->lock); 222 222 return 0; 223 + } 224 + 225 + static int sch311x_gpio_get_direction(struct gpio_chip *chip, unsigned offset) 226 + { 227 + struct sch311x_gpio_block *block = gpiochip_get_data(chip); 228 + u8 data; 229 + 230 + spin_lock(&block->lock); 231 + data = inb(block->runtime_reg + block->config_regs[offset]); 232 + spin_unlock(&block->lock); 233 + 234 + return !!(data & SCH311X_GPIO_CONF_DIR); 235 + } 236 + 237 + static int sch311x_gpio_set_config(struct gpio_chip *chip, unsigned offset, 238 + unsigned long config) 239 + { 240 + struct sch311x_gpio_block *block = gpiochip_get_data(chip); 241 + enum pin_config_param param = pinconf_to_config_param(config); 242 + u8 data; 243 + 244 + switch (param) { 245 + case PIN_CONFIG_DRIVE_OPEN_DRAIN: 246 + spin_lock(&block->lock); 247 + data = inb(block->runtime_reg + block->config_regs[offset]); 248 + data |= SCH311X_GPIO_CONF_OPEN_DRAIN; 249 + outb(data, block->runtime_reg + block->config_regs[offset]); 250 + spin_unlock(&block->lock); 251 + return 0; 252 + case PIN_CONFIG_DRIVE_PUSH_PULL: 253 + spin_lock(&block->lock); 254 + data = inb(block->runtime_reg + block->config_regs[offset]); 255 + data &= ~SCH311X_GPIO_CONF_OPEN_DRAIN; 256 + outb(data, block->runtime_reg + block->config_regs[offset]); 257 + spin_unlock(&block->lock); 258 + return 0; 259 + default: 260 + break; 261 + } 262 + return -ENOTSUPP; 223 263 } 224 264 225 265 static int sch311x_gpio_probe(struct platform_device *pdev) ··· 295 253 block->chip.free = sch311x_gpio_free; 296 254 block->chip.direction_input = sch311x_gpio_direction_in; 297 255 block->chip.direction_output = sch311x_gpio_direction_out; 256 + block->chip.get_direction = sch311x_gpio_get_direction; 257 + block->chip.set_config = sch311x_gpio_set_config; 298 258 block->chip.get = sch311x_gpio_get; 299 259 block->chip.set = sch311x_gpio_set; 300 260 block->chip.ngpio = 8; ··· 353 309 { 354 310 int err = 0, reg; 355 311 unsigned short base_addr; 356 - unsigned char dev_id; 312 + u8 dev_id; 357 313 358 314 err = sch311x_sio_enter(sio_config_port); 359 315 if (err)
+1 -1
drivers/gpio/gpio-spear-spics.c
··· 10 10 */ 11 11 12 12 #include <linux/err.h> 13 - #include <linux/gpio.h> 13 + #include <linux/gpio/driver.h> 14 14 #include <linux/io.h> 15 15 #include <linux/init.h> 16 16 #include <linux/of.h>
+16 -25
drivers/gpio/gpio-sta2x11.c
··· 23 23 #include <linux/init.h> 24 24 #include <linux/kernel.h> 25 25 #include <linux/slab.h> 26 - #include <linux/gpio.h> 26 + #include <linux/gpio/driver.h> 27 + #include <linux/bitops.h> 27 28 #include <linux/interrupt.h> 28 29 #include <linux/irq.h> 29 30 #include <linux/pci.h> ··· 59 58 unsigned irq_type[GSTA_NR_GPIO]; 60 59 }; 61 60 62 - static inline struct gsta_regs __iomem *__regs(struct gsta_gpio *chip, int nr) 63 - { 64 - return chip->regs[nr / GSTA_GPIO_PER_BLOCK]; 65 - } 66 - 67 - static inline u32 __bit(int nr) 68 - { 69 - return 1U << (nr % GSTA_GPIO_PER_BLOCK); 70 - } 71 - 72 61 /* 73 62 * gpio methods 74 63 */ ··· 66 75 static void gsta_gpio_set(struct gpio_chip *gpio, unsigned nr, int val) 67 76 { 68 77 struct gsta_gpio *chip = gpiochip_get_data(gpio); 69 - struct gsta_regs __iomem *regs = __regs(chip, nr); 70 - u32 bit = __bit(nr); 78 + struct gsta_regs __iomem *regs = chip->regs[nr / GSTA_GPIO_PER_BLOCK]; 79 + u32 bit = BIT(nr % GSTA_GPIO_PER_BLOCK); 71 80 72 81 if (val) 73 82 writel(bit, &regs->dats); ··· 78 87 static int gsta_gpio_get(struct gpio_chip *gpio, unsigned nr) 79 88 { 80 89 struct gsta_gpio *chip = gpiochip_get_data(gpio); 81 - struct gsta_regs __iomem *regs = __regs(chip, nr); 82 - u32 bit = __bit(nr); 90 + struct gsta_regs __iomem *regs = chip->regs[nr / GSTA_GPIO_PER_BLOCK]; 91 + u32 bit = BIT(nr % GSTA_GPIO_PER_BLOCK); 83 92 84 93 return !!(readl(&regs->dat) & bit); 85 94 } ··· 88 97 int val) 89 98 { 90 99 struct gsta_gpio *chip = gpiochip_get_data(gpio); 91 - struct gsta_regs __iomem *regs = __regs(chip, nr); 92 - u32 bit = __bit(nr); 100 + struct gsta_regs __iomem *regs = chip->regs[nr / GSTA_GPIO_PER_BLOCK]; 101 + u32 bit = BIT(nr % GSTA_GPIO_PER_BLOCK); 93 102 94 103 writel(bit, &regs->dirs); 95 104 /* Data register after direction, otherwise pullup/down is selected */ ··· 103 112 static int gsta_gpio_direction_input(struct gpio_chip *gpio, unsigned nr) 104 113 { 105 114 struct gsta_gpio *chip = gpiochip_get_data(gpio); 106 - struct gsta_regs __iomem *regs = __regs(chip, nr); 107 - u32 bit = __bit(nr); 115 + struct gsta_regs __iomem *regs = chip->regs[nr / GSTA_GPIO_PER_BLOCK]; 116 + u32 bit = BIT(nr % GSTA_GPIO_PER_BLOCK); 108 117 109 118 writel(bit, &regs->dirc); 110 119 return 0; ··· 156 165 */ 157 166 static void gsta_set_config(struct gsta_gpio *chip, int nr, unsigned cfg) 158 167 { 159 - struct gsta_regs __iomem *regs = __regs(chip, nr); 168 + struct gsta_regs __iomem *regs = chip->regs[nr / GSTA_GPIO_PER_BLOCK]; 160 169 unsigned long flags; 161 - u32 bit = __bit(nr); 170 + u32 bit = BIT(nr % GSTA_GPIO_PER_BLOCK); 162 171 u32 val; 163 172 int err = 0; 164 173 ··· 225 234 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(data); 226 235 struct gsta_gpio *chip = gc->private; 227 236 int nr = data->irq - chip->irq_base; 228 - struct gsta_regs __iomem *regs = __regs(chip, nr); 229 - u32 bit = __bit(nr); 237 + struct gsta_regs __iomem *regs = chip->regs[nr / GSTA_GPIO_PER_BLOCK]; 238 + u32 bit = BIT(nr % GSTA_GPIO_PER_BLOCK); 230 239 u32 val; 231 240 unsigned long flags; 232 241 ··· 248 257 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(data); 249 258 struct gsta_gpio *chip = gc->private; 250 259 int nr = data->irq - chip->irq_base; 251 - struct gsta_regs __iomem *regs = __regs(chip, nr); 252 - u32 bit = __bit(nr); 260 + struct gsta_regs __iomem *regs = chip->regs[nr / GSTA_GPIO_PER_BLOCK]; 261 + u32 bit = BIT(nr % GSTA_GPIO_PER_BLOCK); 253 262 u32 val; 254 263 int type; 255 264 unsigned long flags;
+1 -1
drivers/gpio/gpio-stmpe.c
··· 8 8 #include <linux/init.h> 9 9 #include <linux/platform_device.h> 10 10 #include <linux/slab.h> 11 - #include <linux/gpio.h> 11 + #include <linux/gpio/driver.h> 12 12 #include <linux/interrupt.h> 13 13 #include <linux/of.h> 14 14 #include <linux/mfd/stmpe.h>
+16 -2
drivers/gpio/gpio-stp-xway.c
··· 13 13 #include <linux/types.h> 14 14 #include <linux/of_platform.h> 15 15 #include <linux/mutex.h> 16 - #include <linux/gpio.h> 16 + #include <linux/gpio/driver.h> 17 17 #include <linux/io.h> 18 - #include <linux/of_gpio.h> 19 18 #include <linux/clk.h> 20 19 #include <linux/err.h> 21 20 ··· 88 89 u8 phy2; /* 3 bits can be driven by phy2 */ 89 90 u8 reserved; /* mask out the hw driven bits in gpio_request */ 90 91 }; 92 + 93 + /** 94 + * xway_stp_get() - gpio_chip->get - get gpios. 95 + * @gc: Pointer to gpio_chip device structure. 96 + * @gpio: GPIO signal number. 97 + * 98 + * Gets the shadow value. 99 + */ 100 + static int xway_stp_get(struct gpio_chip *gc, unsigned int gpio) 101 + { 102 + struct xway_stp *chip = gpiochip_get_data(gc); 103 + 104 + return (xway_stp_r32(chip->virt, XWAY_STP_CPU0) & BIT(gpio)); 105 + } 91 106 92 107 /** 93 108 * xway_stp_set() - gpio_chip->set - set gpios. ··· 228 215 chip->gc.parent = &pdev->dev; 229 216 chip->gc.label = "stp-xway"; 230 217 chip->gc.direction_output = xway_stp_dir_out; 218 + chip->gc.get = xway_stp_get; 231 219 chip->gc.set = xway_stp_set; 232 220 chip->gc.request = xway_stp_request; 233 221 chip->gc.base = -1;
+32 -1
drivers/gpio/gpio-syscon.c
··· 10 10 */ 11 11 12 12 #include <linux/err.h> 13 - #include <linux/gpio.h> 13 + #include <linux/gpio/driver.h> 14 14 #include <linux/module.h> 15 15 #include <linux/of.h> 16 16 #include <linux/of_device.h> ··· 135 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 165 #define KEYSTONE_LOCK_BIT BIT(0) 139 166 140 167 static void keystone_gpio_set(struct gpio_chip *chip, unsigned offset, int val) ··· 201 174 { 202 175 .compatible = "ti,keystone-dsp-gpio", 203 176 .data = &keystone_dsp_gpio, 177 + }, 178 + { 179 + .compatible = "rockchip,rk3328-grf-gpio", 180 + .data = &rockchip_rk3328_gpio_mute, 204 181 }, 205 182 { } 206 183 };
+1 -2
drivers/gpio/gpio-tb10x.c
··· 22 22 #include <linux/kernel.h> 23 23 #include <linux/module.h> 24 24 #include <linux/platform_device.h> 25 - #include <linux/gpio.h> 25 + #include <linux/gpio/driver.h> 26 26 #include <linux/slab.h> 27 27 #include <linux/irq.h> 28 28 #include <linux/irqdomain.h> ··· 30 30 #include <linux/io.h> 31 31 #include <linux/of.h> 32 32 #include <linux/of_platform.h> 33 - #include <linux/of_gpio.h> 34 33 #include <linux/spinlock.h> 35 34 #include <linux/bitops.h> 36 35 #include <linux/pinctrl/consumer.h>
+10 -18
drivers/gpio/gpio-tegra.c
··· 22 22 #include <linux/irq.h> 23 23 #include <linux/interrupt.h> 24 24 #include <linux/io.h> 25 - #include <linux/gpio.h> 25 + #include <linux/gpio/driver.h> 26 26 #include <linux/of_device.h> 27 27 #include <linux/platform_device.h> 28 28 #include <linux/module.h> ··· 207 207 208 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 213 static int tegra_gpio_set_debounce(struct gpio_chip *chip, unsigned int offset, ··· 323 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 326 spin_lock_irqsave(&bank->lvl_lock[port], flags); 334 327 335 328 val = tegra_gpio_readl(tgi, GPIO_INT_LVL(tgi, gpio)); ··· 334 341 335 342 tegra_gpio_mask_write(tgi, GPIO_MSK_OE(tgi, gpio), gpio, 0); 336 343 tegra_gpio_enable(tgi, gpio); 344 + 345 + ret = gpiochip_lock_as_irq(&tgi->gc, gpio); 346 + if (ret) { 347 + dev_err(tgi->dev, 348 + "unable to lock Tegra GPIO %u as IRQ\n", gpio); 349 + tegra_gpio_disable(tgi, gpio); 350 + return ret; 351 + } 337 352 338 353 if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH)) 339 354 irq_set_handler_locked(d, handle_level_irq); ··· 551 550 SET_SYSTEM_SLEEP_PM_OPS(tegra_gpio_suspend, tegra_gpio_resume) 552 551 }; 553 552 554 - /* 555 - * This lock class tells lockdep that GPIO irqs are in a different category 556 - * than their parents, so it won't report false recursion. 557 - */ 558 - static struct lock_class_key gpio_lock_class; 559 - static struct lock_class_key gpio_request_class; 560 - 561 553 static int tegra_gpio_probe(struct platform_device *pdev) 562 554 { 563 555 struct tegra_gpio_info *tgi; ··· 655 661 656 662 bank = &tgi->bank_info[GPIO_BANK(gpio)]; 657 663 658 - irq_set_lockdep_class(irq, &gpio_lock_class, 659 - &gpio_request_class); 660 664 irq_set_chip_data(irq, bank); 661 665 irq_set_chip_and_handler(irq, &tgi->ic, handle_simple_irq); 662 666 }
+74
drivers/gpio/gpio-tegra186.c
··· 16 16 #include <linux/platform_device.h> 17 17 18 18 #include <dt-bindings/gpio/tegra186-gpio.h> 19 + #include <dt-bindings/gpio/tegra194-gpio.h> 19 20 20 21 #define TEGRA186_GPIO_ENABLE_CONFIG 0x00 21 22 #define TEGRA186_GPIO_ENABLE_CONFIG_ENABLE BIT(0) ··· 594 593 .name = "tegra186-gpio-aon", 595 594 }; 596 595 596 + #define TEGRA194_MAIN_GPIO_PORT(port, base, count, controller) \ 597 + [TEGRA194_MAIN_GPIO_PORT_##port] = { \ 598 + .name = #port, \ 599 + .offset = base, \ 600 + .pins = count, \ 601 + .irq = controller, \ 602 + } 603 + 604 + static const struct tegra_gpio_port tegra194_main_ports[] = { 605 + TEGRA194_MAIN_GPIO_PORT( A, 0x1400, 8, 1), 606 + TEGRA194_MAIN_GPIO_PORT( B, 0x4e00, 2, 4), 607 + TEGRA194_MAIN_GPIO_PORT( C, 0x4600, 8, 4), 608 + TEGRA194_MAIN_GPIO_PORT( D, 0x4800, 4, 4), 609 + TEGRA194_MAIN_GPIO_PORT( E, 0x4a00, 8, 4), 610 + TEGRA194_MAIN_GPIO_PORT( F, 0x4c00, 6, 4), 611 + TEGRA194_MAIN_GPIO_PORT( G, 0x4000, 8, 4), 612 + TEGRA194_MAIN_GPIO_PORT( H, 0x4200, 8, 4), 613 + TEGRA194_MAIN_GPIO_PORT( I, 0x4400, 5, 4), 614 + TEGRA194_MAIN_GPIO_PORT( J, 0x5200, 6, 5), 615 + TEGRA194_MAIN_GPIO_PORT( K, 0x3000, 8, 3), 616 + TEGRA194_MAIN_GPIO_PORT( L, 0x3200, 4, 3), 617 + TEGRA194_MAIN_GPIO_PORT( M, 0x2600, 8, 2), 618 + TEGRA194_MAIN_GPIO_PORT( N, 0x2800, 3, 2), 619 + TEGRA194_MAIN_GPIO_PORT( O, 0x5000, 6, 5), 620 + TEGRA194_MAIN_GPIO_PORT( P, 0x2a00, 8, 2), 621 + TEGRA194_MAIN_GPIO_PORT( Q, 0x2c00, 8, 2), 622 + TEGRA194_MAIN_GPIO_PORT( R, 0x2e00, 6, 2), 623 + TEGRA194_MAIN_GPIO_PORT( S, 0x3600, 8, 3), 624 + TEGRA194_MAIN_GPIO_PORT( T, 0x3800, 8, 3), 625 + TEGRA194_MAIN_GPIO_PORT( U, 0x3a00, 1, 3), 626 + TEGRA194_MAIN_GPIO_PORT( V, 0x1000, 8, 1), 627 + TEGRA194_MAIN_GPIO_PORT( W, 0x1200, 2, 1), 628 + TEGRA194_MAIN_GPIO_PORT( X, 0x2000, 8, 2), 629 + TEGRA194_MAIN_GPIO_PORT( Y, 0x2200, 8, 2), 630 + TEGRA194_MAIN_GPIO_PORT( Z, 0x2400, 8, 2), 631 + TEGRA194_MAIN_GPIO_PORT(FF, 0x3400, 2, 3), 632 + TEGRA194_MAIN_GPIO_PORT(GG, 0x0000, 2, 0) 633 + }; 634 + 635 + static const struct tegra_gpio_soc tegra194_main_soc = { 636 + .num_ports = ARRAY_SIZE(tegra194_main_ports), 637 + .ports = tegra194_main_ports, 638 + .name = "tegra194-gpio", 639 + }; 640 + 641 + #define TEGRA194_AON_GPIO_PORT(port, base, count, controller) \ 642 + [TEGRA194_AON_GPIO_PORT_##port] = { \ 643 + .name = #port, \ 644 + .offset = base, \ 645 + .pins = count, \ 646 + .irq = controller, \ 647 + } 648 + 649 + static const struct tegra_gpio_port tegra194_aon_ports[] = { 650 + TEGRA194_AON_GPIO_PORT(AA, 0x0600, 8, 0), 651 + TEGRA194_AON_GPIO_PORT(BB, 0x0800, 4, 0), 652 + TEGRA194_AON_GPIO_PORT(CC, 0x0200, 8, 0), 653 + TEGRA194_AON_GPIO_PORT(DD, 0x0400, 3, 0), 654 + TEGRA194_AON_GPIO_PORT(EE, 0x0000, 7, 0) 655 + }; 656 + 657 + static const struct tegra_gpio_soc tegra194_aon_soc = { 658 + .num_ports = ARRAY_SIZE(tegra194_aon_ports), 659 + .ports = tegra194_aon_ports, 660 + .name = "tegra194-gpio-aon", 661 + }; 662 + 597 663 static const struct of_device_id tegra186_gpio_of_match[] = { 598 664 { 599 665 .compatible = "nvidia,tegra186-gpio", ··· 668 600 }, { 669 601 .compatible = "nvidia,tegra186-gpio-aon", 670 602 .data = &tegra186_aon_soc 603 + }, { 604 + .compatible = "nvidia,tegra194-gpio", 605 + .data = &tegra194_main_soc 606 + }, { 607 + .compatible = "nvidia,tegra194-gpio-aon", 608 + .data = &tegra194_aon_soc 671 609 }, { 672 610 /* sentinel */ 673 611 }
+1 -1
drivers/gpio/gpio-timberdale.c
··· 22 22 */ 23 23 24 24 #include <linux/init.h> 25 - #include <linux/gpio.h> 25 + #include <linux/gpio/driver.h> 26 26 #include <linux/platform_device.h> 27 27 #include <linux/irq.h> 28 28 #include <linux/io.h>
+1 -2
drivers/gpio/gpio-uniphier.c
··· 310 310 struct uniphier_gpio_priv *priv = domain->host_data; 311 311 struct gpio_chip *chip = &priv->chip; 312 312 313 - gpiochip_lock_as_irq(chip, data->hwirq + UNIPHIER_GPIO_IRQ_OFFSET); 314 - return 0; 313 + return gpiochip_lock_as_irq(chip, data->hwirq + UNIPHIER_GPIO_IRQ_OFFSET); 315 314 } 316 315 317 316 static void uniphier_gpio_irq_domain_deactivate(struct irq_domain *domain,
+7 -1
drivers/gpio/gpio-vr41xx.c
··· 138 138 139 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 145 dev_err(vr41xx_gpio_chip.parent, 143 146 "unable to lock HW IRQ %lu for IRQ\n", 144 147 data->hwirq); 148 + return ret; 149 + } 150 + 145 151 /* Satisfy the .enable semantics by unmasking the line */ 146 152 unmask_giuint_low(data); 147 153 return 0;
+4 -2
drivers/gpio/gpio-xgene-sb.c
··· 143 143 { 144 144 struct xgene_gpio_sb *priv = d->host_data; 145 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 150 dev_err(priv->gc.parent, 149 151 "Unable to configure XGene GPIO standby pin %d as IRQ\n", 150 152 gpio); 151 - return -ENOSPC; 153 + return ret; 152 154 } 153 155 154 156 xgene_gpio_set_bit(&priv->gc, priv->regs + MPA_GPIO_SEL_LO,
+1 -1
drivers/gpio/gpio-xilinx.c
··· 20 20 #include <linux/of_platform.h> 21 21 #include <linux/of_gpio.h> 22 22 #include <linux/io.h> 23 - #include <linux/gpio.h> 23 + #include <linux/gpio/driver.h> 24 24 #include <linux/slab.h> 25 25 26 26 /* Register Offset Definitions */
-3
drivers/gpio/gpiolib-of.c
··· 621 621 { 622 622 int status; 623 623 624 - if ((!chip->of_node) && (chip->parent)) 625 - chip->of_node = chip->parent->of_node; 626 - 627 624 if (!chip->of_node) 628 625 return 0; 629 626
+57 -25
drivers/gpio/gpiolib.c
··· 431 431 int i; 432 432 433 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 435 int ret = gpiod_get_array_value_complex(false, 436 436 true, 437 437 lh->numdescs, ··· 449 449 450 450 return 0; 451 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 459 if (copy_from_user(&ghd, ip, sizeof(ghd))) 454 460 return -EFAULT; 455 461 ··· 1262 1256 /* If the gpiochip has an assigned OF node this takes precedence */ 1263 1257 if (chip->of_node) 1264 1258 gdev->dev.of_node = chip->of_node; 1259 + else 1260 + chip->of_node = gdev->dev.of_node; 1265 1261 #endif 1266 1262 1267 1263 gdev->id = ida_simple_get(&gpio_ida, 0, 0, GFP_KERNEL); ··· 1416 1408 err_free_gdev: 1417 1409 ida_simple_remove(&gpio_ida, gdev->id); 1418 1410 /* failures here can mean systems won't boot... */ 1419 - pr_err("%s: GPIOs %d..%d (%s) failed to register\n", __func__, 1411 + pr_err("%s: GPIOs %d..%d (%s) failed to register, %d\n", __func__, 1420 1412 gdev->base, gdev->base + gdev->ngpio - 1, 1421 - chip->label ? : "generic"); 1413 + chip->label ? : "generic", status); 1422 1414 kfree(gdev); 1423 1415 return status; 1424 1416 } ··· 1672 1664 if (parent_handler) { 1673 1665 if (gpiochip->can_sleep) { 1674 1666 chip_err(gpiochip, 1675 - "you cannot have chained interrupts on a " 1676 - "chip that may sleep\n"); 1667 + "you cannot have chained interrupts on a chip that may sleep\n"); 1677 1668 return; 1678 1669 } 1679 1670 /* ··· 1807 1800 static int gpiochip_irq_reqres(struct irq_data *d) 1808 1801 { 1809 1802 struct gpio_chip *chip = irq_data_get_irq_chip_data(d); 1803 + int ret; 1810 1804 1811 1805 if (!try_module_get(chip->gpiodev->owner)) 1812 1806 return -ENODEV; 1813 1807 1814 - if (gpiochip_lock_as_irq(chip, d->hwirq)) { 1808 + ret = gpiochip_lock_as_irq(chip, d->hwirq); 1809 + if (ret) { 1815 1810 chip_err(chip, 1816 1811 "unable to lock HW IRQ %lu for IRQ\n", 1817 1812 d->hwirq); 1818 1813 module_put(chip->gpiodev->owner); 1819 - return -EINVAL; 1814 + return ret; 1820 1815 } 1821 1816 return 0; 1822 1817 } ··· 1859 1850 return 0; 1860 1851 1861 1852 if (gpiochip->irq.parent_handler && gpiochip->can_sleep) { 1862 - chip_err(gpiochip, "you cannot have chained interrupts on a " 1863 - "chip that may sleep\n"); 1853 + chip_err(gpiochip, "you cannot have chained interrupts on a chip that may sleep\n"); 1864 1854 return -EINVAL; 1865 1855 } 1866 1856 ··· 2267 2259 struct gpio_chip *chip = desc->gdev->chip; 2268 2260 int status; 2269 2261 unsigned long flags; 2262 + unsigned offset; 2270 2263 2271 2264 spin_lock_irqsave(&gpio_lock, flags); 2272 2265 ··· 2286 2277 if (chip->request) { 2287 2278 /* chip->request may sleep */ 2288 2279 spin_unlock_irqrestore(&gpio_lock, flags); 2289 - status = chip->request(chip, gpio_chip_hwgpio(desc)); 2280 + offset = gpio_chip_hwgpio(desc); 2281 + if (gpiochip_line_is_valid(chip, offset)) 2282 + status = chip->request(chip, offset); 2283 + else 2284 + status = -EINVAL; 2290 2285 spin_lock_irqsave(&gpio_lock, flags); 2291 2286 2292 2287 if (status < 0) { ··· 3207 3194 EXPORT_SYMBOL_GPL(gpiod_cansleep); 3208 3195 3209 3196 /** 3197 + * gpiod_set_consumer_name() - set the consumer name for the descriptor 3198 + * @desc: gpio to set the consumer name on 3199 + * @name: the new consumer name 3200 + */ 3201 + void gpiod_set_consumer_name(struct gpio_desc *desc, const char *name) 3202 + { 3203 + VALIDATE_DESC_VOID(desc); 3204 + /* Just overwrite whatever the previous name was */ 3205 + desc->label = name; 3206 + } 3207 + EXPORT_SYMBOL_GPL(gpiod_set_consumer_name); 3208 + 3209 + /** 3210 3210 * gpiod_to_irq() - return the IRQ corresponding to a GPIO 3211 3211 * @desc: gpio whose IRQ will be returned (already requested) 3212 3212 * ··· 3275 3249 * behind our back 3276 3250 */ 3277 3251 if (!chip->can_sleep && chip->get_direction) { 3278 - int dir = chip->get_direction(chip, offset); 3252 + int dir = gpiod_get_direction(desc); 3279 3253 3280 - if (dir) 3281 - clear_bit(FLAG_IS_OUT, &desc->flags); 3282 - else 3283 - set_bit(FLAG_IS_OUT, &desc->flags); 3254 + if (dir < 0) { 3255 + chip_err(chip, "%s: cannot get GPIO direction\n", 3256 + __func__); 3257 + return dir; 3258 + } 3284 3259 } 3285 3260 3286 3261 if (test_bit(FLAG_IS_OUT, &desc->flags)) { 3287 3262 chip_err(chip, 3288 - "%s: tried to flag a GPIO set as output for IRQ\n", 3289 - __func__); 3263 + "%s: tried to flag a GPIO set as output for IRQ\n", 3264 + __func__); 3290 3265 return -EIO; 3291 3266 } 3292 3267 ··· 3666 3639 chip = find_chip_by_name(p->chip_label); 3667 3640 3668 3641 if (!chip) { 3669 - dev_err(dev, "cannot find GPIO chip %s\n", 3670 - p->chip_label); 3671 - return ERR_PTR(-ENODEV); 3642 + /* 3643 + * As the lookup table indicates a chip with 3644 + * p->chip_label should exist, assume it may 3645 + * still appear later and let the interested 3646 + * consumer be probed again or let the Deferred 3647 + * Probe infrastructure handle the error. 3648 + */ 3649 + dev_warn(dev, "cannot find GPIO chip %s, deferring\n", 3650 + p->chip_label); 3651 + return ERR_PTR(-EPROBE_DEFER); 3672 3652 } 3673 3653 3674 3654 if (chip->ngpio <= p->chip_hwnum) { ··· 4249 4215 int ret; 4250 4216 4251 4217 /* Register GPIO sysfs bus */ 4252 - ret = bus_register(&gpio_bus_type); 4218 + ret = bus_register(&gpio_bus_type); 4253 4219 if (ret < 0) { 4254 4220 pr_err("gpiolib: could not register GPIO bus type\n"); 4255 4221 return ret; ··· 4293 4259 seq_printf(s, " gpio-%-3d (%-20.20s|%-20.20s) %s %s %s", 4294 4260 gpio, gdesc->name ? gdesc->name : "", gdesc->label, 4295 4261 is_out ? "out" : "in ", 4296 - chip->get 4297 - ? (chip->get(chip, i) ? "hi" : "lo") 4298 - : "? ", 4262 + chip->get ? (chip->get(chip, i) ? "hi" : "lo") : "? ", 4299 4263 is_irq ? "IRQ" : " "); 4300 4264 seq_printf(s, "\n"); 4301 4265 }
+1 -1
drivers/gpio/gpiolib.h
··· 92 92 }; 93 93 94 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 97 #ifdef CONFIG_OF_GPIO 98 98 struct gpio_desc *of_find_gpio(struct device *dev,
+1 -1
drivers/w1/masters/Kconfig
··· 49 49 50 50 config W1_MASTER_GPIO 51 51 tristate "GPIO 1-wire busmaster" 52 - depends on GPIOLIB 52 + depends on GPIOLIB || COMPILE_TEST 53 53 help 54 54 Say Y here if you want to communicate with your 1-wire devices using 55 55 GPIO pins. This driver uses the GPIO API to control the wire.
+15
include/linux/gpio/aspeed.h
··· 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 */
+9 -5
include/linux/gpio/consumer.h
··· 41 41 GPIOD_OUT_LOW = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT, 42 42 GPIOD_OUT_HIGH = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT | 43 43 GPIOD_FLAGS_BIT_DIR_VAL, 44 - GPIOD_OUT_LOW_OPEN_DRAIN = GPIOD_FLAGS_BIT_DIR_SET | 45 - GPIOD_FLAGS_BIT_DIR_OUT | 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, 44 + GPIOD_OUT_LOW_OPEN_DRAIN = GPIOD_OUT_LOW | GPIOD_FLAGS_BIT_OPEN_DRAIN, 45 + GPIOD_OUT_HIGH_OPEN_DRAIN = GPIOD_OUT_HIGH | GPIOD_FLAGS_BIT_OPEN_DRAIN, 49 46 }; 50 47 51 48 #ifdef CONFIG_GPIOLIB ··· 142 145 int gpiod_cansleep(const struct gpio_desc *desc); 143 146 144 147 int gpiod_to_irq(const struct gpio_desc *desc); 148 + void gpiod_set_consumer_name(struct gpio_desc *desc, const char *name); 145 149 146 150 /* Convert between the old gpio_ and new gpiod_ interfaces */ 147 151 struct gpio_desc *gpio_to_desc(unsigned gpio); ··· 463 465 /* GPIO can never have been requested */ 464 466 WARN_ON(1); 465 467 return -EINVAL; 468 + } 469 + 470 + static inline void gpiod_set_consumer_name(struct gpio_desc *desc, const char *name) 471 + { 472 + /* GPIO can never have been requested */ 473 + WARN_ON(1); 466 474 } 467 475 468 476 static inline struct gpio_desc *gpio_to_desc(unsigned gpio)
+3
include/linux/gpio/driver.h
··· 201 201 * @reg_set: output set register (out=high) for generic GPIO 202 202 * @reg_clr: output clear register (out=low) for generic GPIO 203 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 206 * @bgpio_bits: number of register bits used for a generic GPIO i.e. 205 207 * <register width> * 8 206 208 * @bgpio_lock: used to lock chip->bgpio_data. Also, this is needed to keep ··· 269 267 void __iomem *reg_set; 270 268 void __iomem *reg_clr; 271 269 void __iomem *reg_dir; 270 + bool bgpio_dir_inverted; 272 271 int bgpio_bits; 273 272 spinlock_t bgpio_lock; 274 273 unsigned long bgpio_data;
+2 -1
include/linux/platform_data/gpio-davinci.h
··· 22 22 #include <asm-generic/gpio.h> 23 23 24 24 #define MAX_REGS_BANKS 5 25 + #define MAX_INT_PER_BANK 32 25 26 26 27 struct davinci_gpio_platform_data { 27 28 u32 ngpio; ··· 42 41 spinlock_t lock; 43 42 void __iomem *regs[MAX_REGS_BANKS]; 44 43 int gpio_unbanked; 45 - unsigned int base_irq; 44 + int irqs[MAX_INT_PER_BANK]; 46 45 unsigned int base; 47 46 }; 48 47
+3 -3
tools/testing/selftests/gpio/gpio-mockup-chardev.c
··· 225 225 if (flag & GPIOHANDLE_REQUEST_ACTIVE_LOW) 226 226 debugfs_value = !debugfs_value; 227 227 228 - if (!(debugfs_dir == OUT && value == debugfs_value)) 228 + if (!(debugfs_dir == OUT && value == debugfs_value)) { 229 229 errno = -EINVAL; 230 - ret = -errno; 231 - 230 + ret = -errno; 231 + } 232 232 } 233 233 gpiotools_release_linehandle(fd); 234 234