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

gpio: generic: factor into gpio_chip struct

The separate struct bgpio_chip has been a pain to handle, both
by being confusingly similar in name to struct gpio_chip and
for being contained inside a struct so that struct gpio_chip
is contained in a struct contained in a struct, making several
steps of dereferencing necessary.

Make things simpler: include the fields directly into
<linux/gpio/driver.h>, #ifdef:ed for CONFIG_GENERIC_GPIO, and
get rid of the <linux/basic_mmio_gpio.h> altogether. Prefix
some of the member variables with bgpio_* and add proper
kerneldoc while we're at it.

Modify all users to handle the change and use a struct
gpio_chip directly. And while we're at it: replace all
container_of() dereferencing by gpiochip_get_data() and
registering the gpio_chip with gpiochip_add_data().

Cc: arm@kernel.org
Cc: Alexander Shiyan <shc_work@mail.ru>
Cc: Shawn Guo <shawnguo@kernel.org>
Cc: Sascha Hauer <kernel@pengutronix.de>
Cc: Kukjin Kim <kgene@kernel.org>
Cc: Alexandre Courbot <gnurou@gmail.com>
Cc: Brian Norris <computersforpeace@gmail.com>
Cc: Florian Fainelli <f.fainelli@gmail.com>
Cc: Sudeep Holla <sudeep.holla@arm.com>
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Nicolas Pitre <nicolas.pitre@linaro.org>
Cc: Olof Johansson <olof@lixom.net>
Cc: Vladimir Zapolskiy <vladimir_zapolskiy@mentor.com>
Cc: Rabin Vincent <rabin@rab.in>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-omap@vger.kernel.org
Cc: linux-samsung-soc@vger.kernel.org
Cc: bcm-kernel-feedback-list@broadcom.com
Acked-by: Gregory Fong <gregory.0xf0@gmail.com>
Acked-by: Liviu Dudau <Liviu.Dudau@arm.com>
Acked-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Acked-by: Tony Lindgren <tony@atomide.com>
Acked-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Acked-by: Lee Jones <lee.jones@linaro.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

+442 -552
+1 -1
arch/arm/mach-clps711x/board-autcpu12.c
··· 31 31 #include <linux/mtd/partitions.h> 32 32 #include <linux/mtd/nand-gpio.h> 33 33 #include <linux/platform_device.h> 34 - #include <linux/basic_mmio_gpio.h> 34 + #include <linux/gpio/driver.h> 35 35 36 36 #include <mach/hardware.h> 37 37 #include <asm/sizes.h>
+1 -1
arch/arm/mach-clps711x/board-p720t.c
··· 28 28 #include <linux/leds.h> 29 29 #include <linux/sizes.h> 30 30 #include <linux/backlight.h> 31 - #include <linux/basic_mmio_gpio.h> 31 + #include <linux/gpio/driver.h> 32 32 #include <linux/platform_device.h> 33 33 #include <linux/mtd/partitions.h> 34 34 #include <linux/mtd/nand-gpio.h>
+1 -1
arch/arm/mach-imx/mach-mx21ads.c
··· 17 17 #include <linux/platform_device.h> 18 18 #include <linux/mtd/mtd.h> 19 19 #include <linux/mtd/physmap.h> 20 - #include <linux/basic_mmio_gpio.h> 20 + #include <linux/gpio/driver.h> 21 21 #include <linux/gpio.h> 22 22 #include <linux/regulator/fixed.h> 23 23 #include <linux/regulator/machine.h>
+1 -1
arch/arm/mach-omap1/board-ams-delta.c
··· 11 11 * it under the terms of the GNU General Public License version 2 as 12 12 * published by the Free Software Foundation. 13 13 */ 14 - #include <linux/basic_mmio_gpio.h> 14 + #include <linux/gpio/driver.h> 15 15 #include <linux/gpio.h> 16 16 #include <linux/kernel.h> 17 17 #include <linux/init.h>
+1 -1
arch/arm/mach-s3c64xx/mach-crag6410.c
··· 29 29 #include <linux/pwm_backlight.h> 30 30 #include <linux/dm9000.h> 31 31 #include <linux/gpio_keys.h> 32 - #include <linux/basic_mmio_gpio.h> 32 + #include <linux/gpio/driver.h> 33 33 #include <linux/spi/spi.h> 34 34 35 35 #include <linux/platform_data/pca953x.h>
+15 -22
drivers/gpio/gpio-74xx-mmio.c
··· 10 10 */ 11 11 12 12 #include <linux/err.h> 13 - #include <linux/gpio.h> 14 13 #include <linux/module.h> 15 14 #include <linux/of_device.h> 16 - #include <linux/basic_mmio_gpio.h> 15 + #include <linux/gpio/driver.h> 17 16 #include <linux/platform_device.h> 18 17 19 18 #define MMIO_74XX_DIR_IN (0 << 8) ··· 20 21 #define MMIO_74XX_BIT_CNT(x) ((x) & 0xff) 21 22 22 23 struct mmio_74xx_gpio_priv { 23 - struct bgpio_chip bgc; 24 + struct gpio_chip gc; 24 25 unsigned flags; 25 26 }; 26 27 ··· 77 78 }; 78 79 MODULE_DEVICE_TABLE(of, mmio_74xx_gpio_ids); 79 80 80 - static inline struct mmio_74xx_gpio_priv *to_74xx_gpio(struct gpio_chip *gc) 81 - { 82 - struct bgpio_chip *bgc = to_bgpio_chip(gc); 83 - 84 - return container_of(bgc, struct mmio_74xx_gpio_priv, bgc); 85 - } 86 - 87 81 static int mmio_74xx_get_direction(struct gpio_chip *gc, unsigned offset) 88 82 { 89 - struct mmio_74xx_gpio_priv *priv = to_74xx_gpio(gc); 83 + struct mmio_74xx_gpio_priv *priv = gpiochip_get_data(gc); 90 84 91 - return (priv->flags & MMIO_74XX_DIR_OUT) ? GPIOF_DIR_OUT : GPIOF_DIR_IN; 85 + return !(priv->flags & MMIO_74XX_DIR_OUT); 92 86 } 93 87 94 88 static int mmio_74xx_dir_in(struct gpio_chip *gc, unsigned int gpio) 95 89 { 96 - struct mmio_74xx_gpio_priv *priv = to_74xx_gpio(gc); 90 + struct mmio_74xx_gpio_priv *priv = gpiochip_get_data(gc); 97 91 98 92 return (priv->flags & MMIO_74XX_DIR_OUT) ? -ENOTSUPP : 0; 99 93 } 100 94 101 95 static int mmio_74xx_dir_out(struct gpio_chip *gc, unsigned int gpio, int val) 102 96 { 103 - struct mmio_74xx_gpio_priv *priv = to_74xx_gpio(gc); 97 + struct mmio_74xx_gpio_priv *priv = gpiochip_get_data(gc); 104 98 105 99 if (priv->flags & MMIO_74XX_DIR_OUT) { 106 100 gc->set(gc, gpio, val); ··· 126 134 127 135 priv->flags = (uintptr_t) of_id->data; 128 136 129 - err = bgpio_init(&priv->bgc, &pdev->dev, 137 + err = bgpio_init(&priv->gc, &pdev->dev, 130 138 DIV_ROUND_UP(MMIO_74XX_BIT_CNT(priv->flags), 8), 131 139 dat, NULL, NULL, NULL, NULL, 0); 132 140 if (err) 133 141 return err; 134 142 135 - priv->bgc.gc.direction_input = mmio_74xx_dir_in; 136 - priv->bgc.gc.direction_output = mmio_74xx_dir_out; 137 - priv->bgc.gc.get_direction = mmio_74xx_get_direction; 138 - priv->bgc.gc.ngpio = MMIO_74XX_BIT_CNT(priv->flags); 139 - priv->bgc.gc.owner = THIS_MODULE; 143 + priv->gc.direction_input = mmio_74xx_dir_in; 144 + priv->gc.direction_output = mmio_74xx_dir_out; 145 + priv->gc.get_direction = mmio_74xx_get_direction; 146 + priv->gc.ngpio = MMIO_74XX_BIT_CNT(priv->flags); 147 + priv->gc.owner = THIS_MODULE; 140 148 141 149 platform_set_drvdata(pdev, priv); 142 150 143 - return gpiochip_add(&priv->bgc.gc); 151 + return gpiochip_add_data(&priv->gc, priv); 144 152 } 145 153 146 154 static int mmio_74xx_gpio_remove(struct platform_device *pdev) 147 155 { 148 156 struct mmio_74xx_gpio_priv *priv = platform_get_drvdata(pdev); 149 157 150 - return bgpio_remove(&priv->bgc); 158 + gpiochip_remove(&priv->gc); 159 + return 0; 151 160 } 152 161 153 162 static struct platform_driver mmio_74xx_gpio_driver = {
+34 -46
drivers/gpio/gpio-brcmstb.c
··· 16 16 #include <linux/of_device.h> 17 17 #include <linux/of_irq.h> 18 18 #include <linux/module.h> 19 - #include <linux/basic_mmio_gpio.h> 20 19 #include <linux/irqdomain.h> 21 20 #include <linux/irqchip/chained_irq.h> 22 21 #include <linux/interrupt.h> ··· 34 35 struct brcmstb_gpio_bank { 35 36 struct list_head node; 36 37 int id; 37 - struct bgpio_chip bgc; 38 + struct gpio_chip gc; 38 39 struct brcmstb_gpio_priv *parent_priv; 39 40 u32 width; 40 41 struct irq_chip irq_chip; ··· 56 57 /* assumes MAX_GPIO_PER_BANK is a multiple of 2 */ 57 58 #define GPIO_BIT(gpio) ((gpio) & (MAX_GPIO_PER_BANK - 1)) 58 59 59 - static inline struct brcmstb_gpio_bank * 60 - brcmstb_gpio_gc_to_bank(struct gpio_chip *gc) 61 - { 62 - struct bgpio_chip *bgc = to_bgpio_chip(gc); 63 - return container_of(bgc, struct brcmstb_gpio_bank, bgc); 64 - } 65 - 66 60 static inline struct brcmstb_gpio_priv * 67 61 brcmstb_gpio_gc_to_priv(struct gpio_chip *gc) 68 62 { 69 - struct brcmstb_gpio_bank *bank = brcmstb_gpio_gc_to_bank(gc); 63 + struct brcmstb_gpio_bank *bank = gpiochip_get_data(gc); 70 64 return bank->parent_priv; 71 65 } 72 66 73 67 static void brcmstb_gpio_set_imask(struct brcmstb_gpio_bank *bank, 74 68 unsigned int offset, bool enable) 75 69 { 76 - struct bgpio_chip *bgc = &bank->bgc; 70 + struct gpio_chip *gc = &bank->gc; 77 71 struct brcmstb_gpio_priv *priv = bank->parent_priv; 78 - u32 mask = bgc->pin2mask(bgc, offset); 72 + u32 mask = gc->pin2mask(gc, offset); 79 73 u32 imask; 80 74 unsigned long flags; 81 75 82 - spin_lock_irqsave(&bgc->lock, flags); 83 - imask = bgc->read_reg(priv->reg_base + GIO_MASK(bank->id)); 76 + spin_lock_irqsave(&gc->bgpio_lock, flags); 77 + imask = gc->read_reg(priv->reg_base + GIO_MASK(bank->id)); 84 78 if (enable) 85 79 imask |= mask; 86 80 else 87 81 imask &= ~mask; 88 - bgc->write_reg(priv->reg_base + GIO_MASK(bank->id), imask); 89 - spin_unlock_irqrestore(&bgc->lock, flags); 82 + gc->write_reg(priv->reg_base + GIO_MASK(bank->id), imask); 83 + spin_unlock_irqrestore(&gc->bgpio_lock, flags); 90 84 } 91 85 92 86 /* -------------------- IRQ chip functions -------------------- */ ··· 87 95 static void brcmstb_gpio_irq_mask(struct irq_data *d) 88 96 { 89 97 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 90 - struct brcmstb_gpio_bank *bank = brcmstb_gpio_gc_to_bank(gc); 98 + struct brcmstb_gpio_bank *bank = gpiochip_get_data(gc); 91 99 92 100 brcmstb_gpio_set_imask(bank, d->hwirq, false); 93 101 } ··· 95 103 static void brcmstb_gpio_irq_unmask(struct irq_data *d) 96 104 { 97 105 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 98 - struct brcmstb_gpio_bank *bank = brcmstb_gpio_gc_to_bank(gc); 106 + struct brcmstb_gpio_bank *bank = gpiochip_get_data(gc); 99 107 100 108 brcmstb_gpio_set_imask(bank, d->hwirq, true); 101 109 } ··· 103 111 static int brcmstb_gpio_irq_set_type(struct irq_data *d, unsigned int type) 104 112 { 105 113 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 106 - struct brcmstb_gpio_bank *bank = brcmstb_gpio_gc_to_bank(gc); 114 + struct brcmstb_gpio_bank *bank = gpiochip_get_data(gc); 107 115 struct brcmstb_gpio_priv *priv = bank->parent_priv; 108 116 u32 mask = BIT(d->hwirq); 109 117 u32 edge_insensitive, iedge_insensitive; ··· 141 149 return -EINVAL; 142 150 } 143 151 144 - spin_lock_irqsave(&bank->bgc.lock, flags); 152 + spin_lock_irqsave(&bank->gc.bgpio_lock, flags); 145 153 146 - iedge_config = bank->bgc.read_reg(priv->reg_base + 154 + iedge_config = bank->gc.read_reg(priv->reg_base + 147 155 GIO_EC(bank->id)) & ~mask; 148 - iedge_insensitive = bank->bgc.read_reg(priv->reg_base + 156 + iedge_insensitive = bank->gc.read_reg(priv->reg_base + 149 157 GIO_EI(bank->id)) & ~mask; 150 - ilevel = bank->bgc.read_reg(priv->reg_base + 158 + ilevel = bank->gc.read_reg(priv->reg_base + 151 159 GIO_LEVEL(bank->id)) & ~mask; 152 160 153 - bank->bgc.write_reg(priv->reg_base + GIO_EC(bank->id), 161 + bank->gc.write_reg(priv->reg_base + GIO_EC(bank->id), 154 162 iedge_config | edge_config); 155 - bank->bgc.write_reg(priv->reg_base + GIO_EI(bank->id), 163 + bank->gc.write_reg(priv->reg_base + GIO_EI(bank->id), 156 164 iedge_insensitive | edge_insensitive); 157 - bank->bgc.write_reg(priv->reg_base + GIO_LEVEL(bank->id), 165 + bank->gc.write_reg(priv->reg_base + GIO_LEVEL(bank->id), 158 166 ilevel | level); 159 167 160 - spin_unlock_irqrestore(&bank->bgc.lock, flags); 168 + spin_unlock_irqrestore(&bank->gc.bgpio_lock, flags); 161 169 return 0; 162 170 } 163 171 ··· 202 210 static void brcmstb_gpio_irq_bank_handler(struct brcmstb_gpio_bank *bank) 203 211 { 204 212 struct brcmstb_gpio_priv *priv = bank->parent_priv; 205 - struct irq_domain *irq_domain = bank->bgc.gc.irqdomain; 213 + struct irq_domain *irq_domain = bank->gc.irqdomain; 206 214 void __iomem *reg_base = priv->reg_base; 207 215 unsigned long status; 208 216 unsigned long flags; 209 217 210 - spin_lock_irqsave(&bank->bgc.lock, flags); 211 - while ((status = bank->bgc.read_reg(reg_base + GIO_STAT(bank->id)) & 212 - bank->bgc.read_reg(reg_base + GIO_MASK(bank->id)))) { 218 + spin_lock_irqsave(&bank->gc.bgpio_lock, flags); 219 + while ((status = bank->gc.read_reg(reg_base + GIO_STAT(bank->id)) & 220 + bank->gc.read_reg(reg_base + GIO_MASK(bank->id)))) { 213 221 int bit; 214 222 215 223 for_each_set_bit(bit, &status, 32) { 216 - u32 stat = bank->bgc.read_reg(reg_base + 224 + u32 stat = bank->gc.read_reg(reg_base + 217 225 GIO_STAT(bank->id)); 218 226 if (bit >= bank->width) 219 227 dev_warn(&priv->pdev->dev, 220 228 "IRQ for invalid GPIO (bank=%d, offset=%d)\n", 221 229 bank->id, bit); 222 - bank->bgc.write_reg(reg_base + GIO_STAT(bank->id), 230 + bank->gc.write_reg(reg_base + GIO_STAT(bank->id), 223 231 stat | BIT(bit)); 224 232 generic_handle_irq(irq_find_mapping(irq_domain, bit)); 225 233 } 226 234 } 227 - spin_unlock_irqrestore(&bank->bgc.lock, flags); 235 + spin_unlock_irqrestore(&bank->gc.bgpio_lock, flags); 228 236 } 229 237 230 238 /* Each UPG GIO block has one IRQ for all banks */ ··· 295 303 */ 296 304 list_for_each(pos, &priv->bank_list) { 297 305 bank = list_entry(pos, struct brcmstb_gpio_bank, node); 298 - ret = bgpio_remove(&bank->bgc); 299 - if (ret) 300 - dev_err(&pdev->dev, "gpiochip_remove fail in cleanup\n"); 306 + gpiochip_remove(&bank->gc); 301 307 } 302 308 if (priv->reboot_notifier.notifier_call) { 303 309 ret = unregister_reboot_notifier(&priv->reboot_notifier); ··· 310 320 const struct of_phandle_args *gpiospec, u32 *flags) 311 321 { 312 322 struct brcmstb_gpio_priv *priv = brcmstb_gpio_gc_to_priv(gc); 313 - struct brcmstb_gpio_bank *bank = brcmstb_gpio_gc_to_bank(gc); 323 + struct brcmstb_gpio_bank *bank = gpiochip_get_data(gc); 314 324 int offset; 315 325 316 326 if (gc->of_gpio_n_cells != 2) { ··· 388 398 if (priv->can_wake) 389 399 bank->irq_chip.irq_set_wake = brcmstb_gpio_irq_set_wake; 390 400 391 - gpiochip_irqchip_add(&bank->bgc.gc, &bank->irq_chip, 0, 401 + gpiochip_irqchip_add(&bank->gc, &bank->irq_chip, 0, 392 402 handle_simple_irq, IRQ_TYPE_NONE); 393 - gpiochip_set_chained_irqchip(&bank->bgc.gc, &bank->irq_chip, 403 + gpiochip_set_chained_irqchip(&bank->gc, &bank->irq_chip, 394 404 priv->parent_irq, brcmstb_gpio_irq_handler); 395 405 396 406 return 0; ··· 441 451 of_property_for_each_u32(np, "brcm,gpio-bank-widths", prop, p, 442 452 bank_width) { 443 453 struct brcmstb_gpio_bank *bank; 444 - struct bgpio_chip *bgc; 445 454 struct gpio_chip *gc; 446 455 447 456 bank = devm_kzalloc(dev, sizeof(*bank), GFP_KERNEL); ··· 462 473 * Regs are 4 bytes wide, have data reg, no set/clear regs, 463 474 * and direction bits have 0 = output and 1 = input 464 475 */ 465 - bgc = &bank->bgc; 466 - err = bgpio_init(bgc, dev, 4, 476 + gc = &bank->gc; 477 + err = bgpio_init(gc, dev, 4, 467 478 reg_base + GIO_DATA(bank->id), 468 479 NULL, NULL, NULL, 469 480 reg_base + GIO_IODIR(bank->id), 0); ··· 472 483 goto fail; 473 484 } 474 485 475 - gc = &bgc->gc; 476 486 gc->of_node = np; 477 487 gc->owner = THIS_MODULE; 478 488 gc->label = np->full_name; ··· 485 497 * Mask all interrupts by default, since wakeup interrupts may 486 498 * be retained from S5 cold boot 487 499 */ 488 - bank->bgc.write_reg(reg_base + GIO_MASK(bank->id), 0); 500 + gc->write_reg(reg_base + GIO_MASK(bank->id), 0); 489 501 490 - err = gpiochip_add(gc); 502 + err = gpiochip_add_data(gc, bank); 491 503 if (err) { 492 504 dev_err(dev, "Could not add gpiochip for bank %d\n", 493 505 bank->id);
+14 -14
drivers/gpio/gpio-clps711x.c
··· 10 10 */ 11 11 12 12 #include <linux/err.h> 13 - #include <linux/gpio.h> 14 13 #include <linux/module.h> 15 - #include <linux/basic_mmio_gpio.h> 14 + #include <linux/gpio/driver.h> 16 15 #include <linux/platform_device.h> 17 16 18 17 static int clps711x_gpio_probe(struct platform_device *pdev) 19 18 { 20 19 struct device_node *np = pdev->dev.of_node; 21 20 void __iomem *dat, *dir; 22 - struct bgpio_chip *bgc; 21 + struct gpio_chip *gc; 23 22 struct resource *res; 24 23 int err, id = np ? of_alias_get_id(np, "gpio") : pdev->id; 25 24 26 25 if ((id < 0) || (id > 4)) 27 26 return -ENODEV; 28 27 29 - bgc = devm_kzalloc(&pdev->dev, sizeof(*bgc), GFP_KERNEL); 30 - if (!bgc) 28 + gc = devm_kzalloc(&pdev->dev, sizeof(*gc), GFP_KERNEL); 29 + if (!gc) 31 30 return -ENOMEM; 32 31 33 32 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); ··· 42 43 switch (id) { 43 44 case 3: 44 45 /* PORTD is inverted logic for direction register */ 45 - err = bgpio_init(bgc, &pdev->dev, 1, dat, NULL, NULL, 46 + err = bgpio_init(gc, &pdev->dev, 1, dat, NULL, NULL, 46 47 NULL, dir, 0); 47 48 break; 48 49 default: 49 - err = bgpio_init(bgc, &pdev->dev, 1, dat, NULL, NULL, 50 + err = bgpio_init(gc, &pdev->dev, 1, dat, NULL, NULL, 50 51 dir, NULL, 0); 51 52 break; 52 53 } ··· 57 58 switch (id) { 58 59 case 4: 59 60 /* PORTE is 3 lines only */ 60 - bgc->gc.ngpio = 3; 61 + gc->ngpio = 3; 61 62 break; 62 63 default: 63 64 break; 64 65 } 65 66 66 - bgc->gc.base = id * 8; 67 - bgc->gc.owner = THIS_MODULE; 68 - platform_set_drvdata(pdev, bgc); 67 + gc->base = id * 8; 68 + gc->owner = THIS_MODULE; 69 + platform_set_drvdata(pdev, gc); 69 70 70 - return gpiochip_add(&bgc->gc); 71 + return gpiochip_add_data(gc, NULL); 71 72 } 72 73 73 74 static int clps711x_gpio_remove(struct platform_device *pdev) 74 75 { 75 - struct bgpio_chip *bgc = platform_get_drvdata(pdev); 76 + struct gpio_chip *gc = platform_get_drvdata(pdev); 76 77 77 - return bgpio_remove(bgc); 78 + gpiochip_remove(gc); 79 + return 0; 78 80 } 79 81 80 82 static const struct of_device_id __maybe_unused clps711x_gpio_ids[] = {
+43 -49
drivers/gpio/gpio-dwapb.c
··· 7 7 * 8 8 * All enquiries to support@picochip.com 9 9 */ 10 - #include <linux/basic_mmio_gpio.h> 10 + #include <linux/gpio/driver.h> 11 + /* FIXME: for gpio_get_value(), replace this with direct register read */ 12 + #include <linux/gpio.h> 11 13 #include <linux/err.h> 12 14 #include <linux/init.h> 13 15 #include <linux/interrupt.h> ··· 68 66 #endif 69 67 70 68 struct dwapb_gpio_port { 71 - struct bgpio_chip bgc; 69 + struct gpio_chip gc; 72 70 bool is_registered; 73 71 struct dwapb_gpio *gpio; 74 72 #ifdef CONFIG_PM_SLEEP ··· 85 83 struct irq_domain *domain; 86 84 }; 87 85 88 - static inline struct dwapb_gpio_port * 89 - to_dwapb_gpio_port(struct bgpio_chip *bgc) 90 - { 91 - return container_of(bgc, struct dwapb_gpio_port, bgc); 92 - } 93 - 94 86 static inline u32 dwapb_read(struct dwapb_gpio *gpio, unsigned int offset) 95 87 { 96 - struct bgpio_chip *bgc = &gpio->ports[0].bgc; 88 + struct gpio_chip *gc = &gpio->ports[0].gc; 97 89 void __iomem *reg_base = gpio->regs; 98 90 99 - return bgc->read_reg(reg_base + offset); 91 + return gc->read_reg(reg_base + offset); 100 92 } 101 93 102 94 static inline void dwapb_write(struct dwapb_gpio *gpio, unsigned int offset, 103 95 u32 val) 104 96 { 105 - struct bgpio_chip *bgc = &gpio->ports[0].bgc; 97 + struct gpio_chip *gc = &gpio->ports[0].gc; 106 98 void __iomem *reg_base = gpio->regs; 107 99 108 - bgc->write_reg(reg_base + offset, val); 100 + gc->write_reg(reg_base + offset, val); 109 101 } 110 102 111 103 static int dwapb_gpio_to_irq(struct gpio_chip *gc, unsigned offset) 112 104 { 113 - struct bgpio_chip *bgc = to_bgpio_chip(gc); 114 - struct dwapb_gpio_port *port = to_dwapb_gpio_port(bgc); 105 + struct dwapb_gpio_port *port = gpiochip_get_data(gc); 115 106 struct dwapb_gpio *gpio = port->gpio; 116 107 117 108 return irq_find_mapping(gpio->domain, offset); ··· 114 119 { 115 120 u32 v = dwapb_read(gpio, GPIO_INT_POLARITY); 116 121 117 - if (gpio_get_value(gpio->ports[0].bgc.gc.base + offs)) 122 + if (gpio_get_value(gpio->ports[0].gc.base + offs)) 118 123 v &= ~BIT(offs); 119 124 else 120 125 v |= BIT(offs); ··· 157 162 { 158 163 struct irq_chip_generic *igc = irq_data_get_irq_chip_data(d); 159 164 struct dwapb_gpio *gpio = igc->private; 160 - struct bgpio_chip *bgc = &gpio->ports[0].bgc; 165 + struct gpio_chip *gc = &gpio->ports[0].gc; 161 166 unsigned long flags; 162 167 u32 val; 163 168 164 - spin_lock_irqsave(&bgc->lock, flags); 169 + spin_lock_irqsave(&gc->bgpio_lock, flags); 165 170 val = dwapb_read(gpio, GPIO_INTEN); 166 171 val |= BIT(d->hwirq); 167 172 dwapb_write(gpio, GPIO_INTEN, val); 168 - spin_unlock_irqrestore(&bgc->lock, flags); 173 + spin_unlock_irqrestore(&gc->bgpio_lock, flags); 169 174 } 170 175 171 176 static void dwapb_irq_disable(struct irq_data *d) 172 177 { 173 178 struct irq_chip_generic *igc = irq_data_get_irq_chip_data(d); 174 179 struct dwapb_gpio *gpio = igc->private; 175 - struct bgpio_chip *bgc = &gpio->ports[0].bgc; 180 + struct gpio_chip *gc = &gpio->ports[0].gc; 176 181 unsigned long flags; 177 182 u32 val; 178 183 179 - spin_lock_irqsave(&bgc->lock, flags); 184 + spin_lock_irqsave(&gc->bgpio_lock, flags); 180 185 val = dwapb_read(gpio, GPIO_INTEN); 181 186 val &= ~BIT(d->hwirq); 182 187 dwapb_write(gpio, GPIO_INTEN, val); 183 - spin_unlock_irqrestore(&bgc->lock, flags); 188 + spin_unlock_irqrestore(&gc->bgpio_lock, flags); 184 189 } 185 190 186 191 static int dwapb_irq_reqres(struct irq_data *d) 187 192 { 188 193 struct irq_chip_generic *igc = irq_data_get_irq_chip_data(d); 189 194 struct dwapb_gpio *gpio = igc->private; 190 - struct bgpio_chip *bgc = &gpio->ports[0].bgc; 195 + struct gpio_chip *gc = &gpio->ports[0].gc; 191 196 192 - if (gpiochip_lock_as_irq(&bgc->gc, irqd_to_hwirq(d))) { 197 + if (gpiochip_lock_as_irq(gc, irqd_to_hwirq(d))) { 193 198 dev_err(gpio->dev, "unable to lock HW IRQ %lu for IRQ\n", 194 199 irqd_to_hwirq(d)); 195 200 return -EINVAL; ··· 201 206 { 202 207 struct irq_chip_generic *igc = irq_data_get_irq_chip_data(d); 203 208 struct dwapb_gpio *gpio = igc->private; 204 - struct bgpio_chip *bgc = &gpio->ports[0].bgc; 209 + struct gpio_chip *gc = &gpio->ports[0].gc; 205 210 206 - gpiochip_unlock_as_irq(&bgc->gc, irqd_to_hwirq(d)); 211 + gpiochip_unlock_as_irq(gc, irqd_to_hwirq(d)); 207 212 } 208 213 209 214 static int dwapb_irq_set_type(struct irq_data *d, u32 type) 210 215 { 211 216 struct irq_chip_generic *igc = irq_data_get_irq_chip_data(d); 212 217 struct dwapb_gpio *gpio = igc->private; 213 - struct bgpio_chip *bgc = &gpio->ports[0].bgc; 218 + struct gpio_chip *gc = &gpio->ports[0].gc; 214 219 int bit = d->hwirq; 215 220 unsigned long level, polarity, flags; 216 221 ··· 218 223 IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) 219 224 return -EINVAL; 220 225 221 - spin_lock_irqsave(&bgc->lock, flags); 226 + spin_lock_irqsave(&gc->bgpio_lock, flags); 222 227 level = dwapb_read(gpio, GPIO_INTTYPE_LEVEL); 223 228 polarity = dwapb_read(gpio, GPIO_INT_POLARITY); 224 229 ··· 249 254 250 255 dwapb_write(gpio, GPIO_INTTYPE_LEVEL, level); 251 256 dwapb_write(gpio, GPIO_INT_POLARITY, polarity); 252 - spin_unlock_irqrestore(&bgc->lock, flags); 257 + spin_unlock_irqrestore(&gc->bgpio_lock, flags); 253 258 254 259 return 0; 255 260 } ··· 257 262 static int dwapb_gpio_set_debounce(struct gpio_chip *gc, 258 263 unsigned offset, unsigned debounce) 259 264 { 260 - struct bgpio_chip *bgc = to_bgpio_chip(gc); 261 - struct dwapb_gpio_port *port = to_dwapb_gpio_port(bgc); 265 + struct dwapb_gpio_port *port = gpiochip_get_data(gc); 262 266 struct dwapb_gpio *gpio = port->gpio; 263 267 unsigned long flags, val_deb; 264 - unsigned long mask = bgc->pin2mask(bgc, offset); 268 + unsigned long mask = gc->pin2mask(gc, offset); 265 269 266 - spin_lock_irqsave(&bgc->lock, flags); 270 + spin_lock_irqsave(&gc->bgpio_lock, flags); 267 271 268 272 val_deb = dwapb_read(gpio, GPIO_PORTA_DEBOUNCE); 269 273 if (debounce) ··· 270 276 else 271 277 dwapb_write(gpio, GPIO_PORTA_DEBOUNCE, val_deb & ~mask); 272 278 273 - spin_unlock_irqrestore(&bgc->lock, flags); 279 + spin_unlock_irqrestore(&gc->bgpio_lock, flags); 274 280 275 281 return 0; 276 282 } ··· 289 295 struct dwapb_gpio_port *port, 290 296 struct dwapb_port_property *pp) 291 297 { 292 - struct gpio_chip *gc = &port->bgc.gc; 298 + struct gpio_chip *gc = &port->gc; 293 299 struct device_node *node = pp->node; 294 300 struct irq_chip_generic *irq_gc = NULL; 295 301 unsigned int hwirq, ngpio = gc->ngpio; ··· 363 369 for (hwirq = 0 ; hwirq < ngpio ; hwirq++) 364 370 irq_create_mapping(gpio->domain, hwirq); 365 371 366 - port->bgc.gc.to_irq = dwapb_gpio_to_irq; 372 + port->gc.to_irq = dwapb_gpio_to_irq; 367 373 } 368 374 369 375 static void dwapb_irq_teardown(struct dwapb_gpio *gpio) 370 376 { 371 377 struct dwapb_gpio_port *port = &gpio->ports[0]; 372 - struct gpio_chip *gc = &port->bgc.gc; 378 + struct gpio_chip *gc = &port->gc; 373 379 unsigned int ngpio = gc->ngpio; 374 380 irq_hw_number_t hwirq; 375 381 ··· 406 412 dirout = gpio->regs + GPIO_SWPORTA_DDR + 407 413 (pp->idx * GPIO_SWPORT_DDR_SIZE); 408 414 409 - err = bgpio_init(&port->bgc, gpio->dev, 4, dat, set, NULL, dirout, 415 + err = bgpio_init(&port->gc, gpio->dev, 4, dat, set, NULL, dirout, 410 416 NULL, false); 411 417 if (err) { 412 418 dev_err(gpio->dev, "failed to init gpio chip for %s\n", ··· 415 421 } 416 422 417 423 #ifdef CONFIG_OF_GPIO 418 - port->bgc.gc.of_node = pp->node; 424 + port->gc.of_node = pp->node; 419 425 #endif 420 - port->bgc.gc.ngpio = pp->ngpio; 421 - port->bgc.gc.base = pp->gpio_base; 426 + port->gc.ngpio = pp->ngpio; 427 + port->gc.base = pp->gpio_base; 422 428 423 429 /* Only port A support debounce */ 424 430 if (pp->idx == 0) 425 - port->bgc.gc.set_debounce = dwapb_gpio_set_debounce; 431 + port->gc.set_debounce = dwapb_gpio_set_debounce; 426 432 427 433 if (pp->irq) 428 434 dwapb_configure_irqs(gpio, port, pp); 429 435 430 - err = gpiochip_add(&port->bgc.gc); 436 + err = gpiochip_add_data(&port->gc, port); 431 437 if (err) 432 438 dev_err(gpio->dev, "failed to register gpiochip for %s\n", 433 439 pp->name); ··· 443 449 444 450 for (m = 0; m < gpio->nr_ports; ++m) 445 451 if (gpio->ports[m].is_registered) 446 - gpiochip_remove(&gpio->ports[m].bgc.gc); 452 + gpiochip_remove(&gpio->ports[m].gc); 447 453 } 448 454 449 455 static struct dwapb_platform_data * ··· 585 591 { 586 592 struct platform_device *pdev = to_platform_device(dev); 587 593 struct dwapb_gpio *gpio = platform_get_drvdata(pdev); 588 - struct bgpio_chip *bgc = &gpio->ports[0].bgc; 594 + struct gpio_chip *gc = &gpio->ports[0].gc; 589 595 unsigned long flags; 590 596 int i; 591 597 592 - spin_lock_irqsave(&bgc->lock, flags); 598 + spin_lock_irqsave(&gc->bgpio_lock, flags); 593 599 for (i = 0; i < gpio->nr_ports; i++) { 594 600 unsigned int offset; 595 601 unsigned int idx = gpio->ports[i].idx; ··· 618 624 dwapb_write(gpio, GPIO_INTMASK, 0xffffffff); 619 625 } 620 626 } 621 - spin_unlock_irqrestore(&bgc->lock, flags); 627 + spin_unlock_irqrestore(&gc->bgpio_lock, flags); 622 628 623 629 return 0; 624 630 } ··· 627 633 { 628 634 struct platform_device *pdev = to_platform_device(dev); 629 635 struct dwapb_gpio *gpio = platform_get_drvdata(pdev); 630 - struct bgpio_chip *bgc = &gpio->ports[0].bgc; 636 + struct gpio_chip *gc = &gpio->ports[0].gc; 631 637 unsigned long flags; 632 638 int i; 633 639 634 - spin_lock_irqsave(&bgc->lock, flags); 640 + spin_lock_irqsave(&gc->bgpio_lock, flags); 635 641 for (i = 0; i < gpio->nr_ports; i++) { 636 642 unsigned int offset; 637 643 unsigned int idx = gpio->ports[i].idx; ··· 660 666 dwapb_write(gpio, GPIO_PORTA_EOI, 0xffffffff); 661 667 } 662 668 } 663 - spin_unlock_irqrestore(&bgc->lock, flags); 669 + spin_unlock_irqrestore(&gc->bgpio_lock, flags); 664 670 665 671 return 0; 666 672 }
+13 -12
drivers/gpio/gpio-ep93xx.c
··· 16 16 #include <linux/module.h> 17 17 #include <linux/platform_device.h> 18 18 #include <linux/io.h> 19 - #include <linux/gpio.h> 20 19 #include <linux/irq.h> 21 20 #include <linux/slab.h> 22 - #include <linux/basic_mmio_gpio.h> 21 + #include <linux/gpio/driver.h> 22 + /* FIXME: this is here for gpio_to_irq() - get rid of this! */ 23 + #include <linux/gpio.h> 23 24 24 25 #include <mach/hardware.h> 25 26 #include <mach/gpio-ep93xx.h> ··· 29 28 30 29 struct ep93xx_gpio { 31 30 void __iomem *mmio_base; 32 - struct bgpio_chip bgc[8]; 31 + struct gpio_chip gc[8]; 33 32 }; 34 33 35 34 /************************************************************************* ··· 320 319 return 64 + gpio; 321 320 } 322 321 323 - static int ep93xx_gpio_add_bank(struct bgpio_chip *bgc, struct device *dev, 322 + static int ep93xx_gpio_add_bank(struct gpio_chip *gc, struct device *dev, 324 323 void __iomem *mmio_base, struct ep93xx_gpio_bank *bank) 325 324 { 326 325 void __iomem *data = mmio_base + bank->data; 327 326 void __iomem *dir = mmio_base + bank->dir; 328 327 int err; 329 328 330 - err = bgpio_init(bgc, dev, 1, data, NULL, NULL, dir, NULL, 0); 329 + err = bgpio_init(gc, dev, 1, data, NULL, NULL, dir, NULL, 0); 331 330 if (err) 332 331 return err; 333 332 334 - bgc->gc.label = bank->label; 335 - bgc->gc.base = bank->base; 333 + gc->label = bank->label; 334 + gc->base = bank->base; 336 335 337 336 if (bank->has_debounce) { 338 - bgc->gc.set_debounce = ep93xx_gpio_set_debounce; 339 - bgc->gc.to_irq = ep93xx_gpio_to_irq; 337 + gc->set_debounce = ep93xx_gpio_set_debounce; 338 + gc->to_irq = ep93xx_gpio_to_irq; 340 339 } 341 340 342 - return gpiochip_add(&bgc->gc); 341 + return gpiochip_add_data(gc, NULL); 343 342 } 344 343 345 344 static int ep93xx_gpio_probe(struct platform_device *pdev) ··· 359 358 return PTR_ERR(ep93xx_gpio->mmio_base); 360 359 361 360 for (i = 0; i < ARRAY_SIZE(ep93xx_gpio_banks); i++) { 362 - struct bgpio_chip *bgc = &ep93xx_gpio->bgc[i]; 361 + struct gpio_chip *gc = &ep93xx_gpio->gc[i]; 363 362 struct ep93xx_gpio_bank *bank = &ep93xx_gpio_banks[i]; 364 363 365 - if (ep93xx_gpio_add_bank(bgc, &pdev->dev, 364 + if (ep93xx_gpio_add_bank(gc, &pdev->dev, 366 365 ep93xx_gpio->mmio_base, bank)) 367 366 dev_warn(&pdev->dev, "Unable to add gpio bank %s\n", 368 367 bank->label);
+21 -28
drivers/gpio/gpio-etraxfs.c
··· 1 1 #include <linux/kernel.h> 2 2 #include <linux/init.h> 3 - #include <linux/gpio.h> 4 3 #include <linux/gpio/driver.h> 5 4 #include <linux/of_gpio.h> 6 5 #include <linux/io.h> 7 6 #include <linux/interrupt.h> 8 7 #include <linux/platform_device.h> 9 - #include <linux/basic_mmio_gpio.h> 10 8 11 9 #define ETRAX_FS_rw_pa_dout 0 12 10 #define ETRAX_FS_r_pa_din 4 ··· 65 67 }; 66 68 67 69 struct etraxfs_gpio_chip { 68 - struct bgpio_chip bgc; 70 + struct gpio_chip gc; 69 71 struct etraxfs_gpio_block *block; 70 72 }; 71 73 ··· 174 176 .rw_intr_pins = ARTPEC3_rw_intr_pins, 175 177 }; 176 178 177 - static struct etraxfs_gpio_chip *to_etraxfs(struct gpio_chip *gc) 178 - { 179 - return container_of(gc, struct etraxfs_gpio_chip, bgc.gc); 180 - } 181 - 182 179 static unsigned int etraxfs_gpio_chip_to_port(struct gpio_chip *gc) 183 180 { 184 181 return gc->label[0] - 'A'; ··· 213 220 static unsigned int etraxfs_gpio_to_group_pin(struct etraxfs_gpio_chip *chip, 214 221 unsigned int gpio) 215 222 { 216 - return 4 * etraxfs_gpio_chip_to_port(&chip->bgc.gc) + gpio / 8; 223 + return 4 * etraxfs_gpio_chip_to_port(&chip->gc) + gpio / 8; 217 224 } 218 225 219 226 static void etraxfs_gpio_irq_ack(struct irq_data *d) 220 227 { 221 228 struct etraxfs_gpio_chip *chip = 222 - to_etraxfs(irq_data_get_irq_chip_data(d)); 229 + gpiochip_get_data(irq_data_get_irq_chip_data(d)); 223 230 struct etraxfs_gpio_block *block = chip->block; 224 231 unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq); 225 232 ··· 229 236 static void etraxfs_gpio_irq_mask(struct irq_data *d) 230 237 { 231 238 struct etraxfs_gpio_chip *chip = 232 - to_etraxfs(irq_data_get_irq_chip_data(d)); 239 + gpiochip_get_data(irq_data_get_irq_chip_data(d)); 233 240 struct etraxfs_gpio_block *block = chip->block; 234 241 unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq); 235 242 ··· 242 249 static void etraxfs_gpio_irq_unmask(struct irq_data *d) 243 250 { 244 251 struct etraxfs_gpio_chip *chip = 245 - to_etraxfs(irq_data_get_irq_chip_data(d)); 252 + gpiochip_get_data(irq_data_get_irq_chip_data(d)); 246 253 struct etraxfs_gpio_block *block = chip->block; 247 254 unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq); 248 255 ··· 255 262 static int etraxfs_gpio_irq_set_type(struct irq_data *d, u32 type) 256 263 { 257 264 struct etraxfs_gpio_chip *chip = 258 - to_etraxfs(irq_data_get_irq_chip_data(d)); 265 + gpiochip_get_data(irq_data_get_irq_chip_data(d)); 259 266 struct etraxfs_gpio_block *block = chip->block; 260 267 unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq); 261 268 u32 cfg; ··· 292 299 static int etraxfs_gpio_irq_request_resources(struct irq_data *d) 293 300 { 294 301 struct etraxfs_gpio_chip *chip = 295 - to_etraxfs(irq_data_get_irq_chip_data(d)); 302 + gpiochip_get_data(irq_data_get_irq_chip_data(d)); 296 303 struct etraxfs_gpio_block *block = chip->block; 297 304 unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq); 298 305 int ret = -EBUSY; ··· 301 308 if (block->group[grpirq]) 302 309 goto out; 303 310 304 - ret = gpiochip_lock_as_irq(&chip->bgc.gc, d->hwirq); 311 + ret = gpiochip_lock_as_irq(&chip->gc, d->hwirq); 305 312 if (ret) 306 313 goto out; 307 314 ··· 323 330 static void etraxfs_gpio_irq_release_resources(struct irq_data *d) 324 331 { 325 332 struct etraxfs_gpio_chip *chip = 326 - to_etraxfs(irq_data_get_irq_chip_data(d)); 333 + gpiochip_get_data(irq_data_get_irq_chip_data(d)); 327 334 struct etraxfs_gpio_block *block = chip->block; 328 335 unsigned int grpirq = etraxfs_gpio_to_group_irq(d->hwirq); 329 336 330 337 spin_lock(&block->lock); 331 338 block->group[grpirq] = 0; 332 - gpiochip_unlock_as_irq(&chip->bgc.gc, d->hwirq); 339 + gpiochip_unlock_as_irq(&chip->gc, d->hwirq); 333 340 spin_unlock(&block->lock); 334 341 } 335 342 ··· 412 419 413 420 for (i = 0; i < info->num_ports; i++) { 414 421 struct etraxfs_gpio_chip *chip = &chips[i]; 415 - struct bgpio_chip *bgc = &chip->bgc; 422 + struct gpio_chip *gc = &chip->gc; 416 423 const struct etraxfs_gpio_port *port = &info->ports[i]; 417 424 unsigned long flags = BGPIOF_READ_OUTPUT_REG_SET; 418 425 void __iomem *dat = regs + port->din; ··· 426 433 flags = BGPIOF_NO_OUTPUT; 427 434 } 428 435 429 - ret = bgpio_init(bgc, dev, 4, 436 + ret = bgpio_init(gc, dev, 4, 430 437 dat, set, NULL, dirout, NULL, 431 438 flags); 432 439 if (ret) { ··· 435 442 continue; 436 443 } 437 444 438 - bgc->gc.ngpio = port->ngpio; 439 - bgc->gc.label = port->label; 445 + gc->ngpio = port->ngpio; 446 + gc->label = port->label; 440 447 441 - bgc->gc.of_node = dev->of_node; 442 - bgc->gc.of_gpio_n_cells = 3; 443 - bgc->gc.of_xlate = etraxfs_gpio_of_xlate; 448 + gc->of_node = dev->of_node; 449 + gc->of_gpio_n_cells = 3; 450 + gc->of_xlate = etraxfs_gpio_of_xlate; 444 451 445 - ret = gpiochip_add(&bgc->gc); 452 + ret = gpiochip_add_data(gc, chip); 446 453 if (ret) { 447 454 dev_err(dev, "Unable to register port %s\n", 448 - bgc->gc.label); 455 + gc->label); 449 456 continue; 450 457 } 451 458 452 459 if (i > 0 && !allportsirq) 453 460 continue; 454 461 455 - ret = gpiochip_irqchip_add(&bgc->gc, &etraxfs_gpio_irq_chip, 0, 462 + ret = gpiochip_irqchip_add(gc, &etraxfs_gpio_irq_chip, 0, 456 463 handle_level_irq, IRQ_TYPE_NONE); 457 464 if (ret) { 458 465 dev_err(dev, "Unable to add irqchip to port %s\n", 459 - bgc->gc.label); 466 + gc->label); 460 467 } 461 468 } 462 469
+12 -12
drivers/gpio/gpio-ge.c
··· 24 24 #include <linux/of_gpio.h> 25 25 #include <linux/of_address.h> 26 26 #include <linux/module.h> 27 - #include <linux/basic_mmio_gpio.h> 27 + #include <linux/gpio/driver.h> 28 28 29 29 #define GEF_GPIO_DIRECT 0x00 30 30 #define GEF_GPIO_IN 0x04 ··· 55 55 { 56 56 const struct of_device_id *of_id = 57 57 of_match_device(gef_gpio_ids, &pdev->dev); 58 - struct bgpio_chip *bgc; 58 + struct gpio_chip *gc; 59 59 void __iomem *regs; 60 60 int ret; 61 61 62 - bgc = devm_kzalloc(&pdev->dev, sizeof(*bgc), GFP_KERNEL); 63 - if (!bgc) 62 + gc = devm_kzalloc(&pdev->dev, sizeof(*gc), GFP_KERNEL); 63 + if (!gc) 64 64 return -ENOMEM; 65 65 66 66 regs = of_iomap(pdev->dev.of_node, 0); 67 67 if (!regs) 68 68 return -ENOMEM; 69 69 70 - ret = bgpio_init(bgc, &pdev->dev, 4, regs + GEF_GPIO_IN, 70 + ret = bgpio_init(gc, &pdev->dev, 4, regs + GEF_GPIO_IN, 71 71 regs + GEF_GPIO_OUT, NULL, NULL, 72 72 regs + GEF_GPIO_DIRECT, BGPIOF_BIG_ENDIAN_BYTE_ORDER); 73 73 if (ret) { ··· 76 76 } 77 77 78 78 /* Setup pointers to chip functions */ 79 - bgc->gc.label = devm_kstrdup(&pdev->dev, pdev->dev.of_node->full_name, 79 + gc->label = devm_kstrdup(&pdev->dev, pdev->dev.of_node->full_name, 80 80 GFP_KERNEL); 81 - if (!bgc->gc.label) { 81 + if (!gc->label) { 82 82 ret = -ENOMEM; 83 83 goto err0; 84 84 } 85 85 86 - bgc->gc.base = -1; 87 - bgc->gc.ngpio = (u16)(uintptr_t)of_id->data; 88 - bgc->gc.of_gpio_n_cells = 2; 89 - bgc->gc.of_node = pdev->dev.of_node; 86 + gc->base = -1; 87 + gc->ngpio = (u16)(uintptr_t)of_id->data; 88 + gc->of_gpio_n_cells = 2; 89 + gc->of_node = pdev->dev.of_node; 90 90 91 91 /* This function adds a memory mapped GPIO chip */ 92 - ret = gpiochip_add(&bgc->gc); 92 + ret = gpiochip_add_data(gc, NULL); 93 93 if (ret) 94 94 goto err0; 95 95
+133 -159
drivers/gpio/gpio-generic.c
··· 56 56 #include <linux/log2.h> 57 57 #include <linux/ioport.h> 58 58 #include <linux/io.h> 59 - #include <linux/gpio.h> 59 + #include <linux/gpio/driver.h> 60 60 #include <linux/slab.h> 61 61 #include <linux/bitops.h> 62 62 #include <linux/platform_device.h> 63 63 #include <linux/mod_devicetable.h> 64 - #include <linux/basic_mmio_gpio.h> 65 64 66 65 static void bgpio_write8(void __iomem *reg, unsigned long data) 67 66 { ··· 124 125 return ioread32be(reg); 125 126 } 126 127 127 - static unsigned long bgpio_pin2mask(struct bgpio_chip *bgc, unsigned int pin) 128 + static unsigned long bgpio_pin2mask(struct gpio_chip *gc, unsigned int pin) 128 129 { 129 130 return BIT(pin); 130 131 } 131 132 132 - static unsigned long bgpio_pin2mask_be(struct bgpio_chip *bgc, 133 + static unsigned long bgpio_pin2mask_be(struct gpio_chip *gc, 133 134 unsigned int pin) 134 135 { 135 - return BIT(bgc->bits - 1 - pin); 136 + return BIT(gc->bgpio_bits - 1 - pin); 136 137 } 137 138 138 139 static int bgpio_get_set(struct gpio_chip *gc, unsigned int gpio) 139 140 { 140 - struct bgpio_chip *bgc = to_bgpio_chip(gc); 141 - unsigned long pinmask = bgc->pin2mask(bgc, gpio); 141 + unsigned long pinmask = gc->pin2mask(gc, gpio); 142 142 143 - if (bgc->dir & pinmask) 144 - return !!(bgc->read_reg(bgc->reg_set) & pinmask); 143 + if (gc->bgpio_dir & pinmask) 144 + return !!(gc->read_reg(gc->reg_set) & pinmask); 145 145 else 146 - return !!(bgc->read_reg(bgc->reg_dat) & pinmask); 146 + return !!(gc->read_reg(gc->reg_dat) & pinmask); 147 147 } 148 148 149 149 static int bgpio_get(struct gpio_chip *gc, unsigned int gpio) 150 150 { 151 - struct bgpio_chip *bgc = to_bgpio_chip(gc); 152 - 153 - return !!(bgc->read_reg(bgc->reg_dat) & bgc->pin2mask(bgc, gpio)); 151 + return !!(gc->read_reg(gc->reg_dat) & gc->pin2mask(gc, gpio)); 154 152 } 155 153 156 154 static void bgpio_set_none(struct gpio_chip *gc, unsigned int gpio, int val) ··· 156 160 157 161 static void bgpio_set(struct gpio_chip *gc, unsigned int gpio, int val) 158 162 { 159 - struct bgpio_chip *bgc = to_bgpio_chip(gc); 160 - unsigned long mask = bgc->pin2mask(bgc, gpio); 163 + unsigned long mask = gc->pin2mask(gc, gpio); 161 164 unsigned long flags; 162 165 163 - spin_lock_irqsave(&bgc->lock, flags); 166 + spin_lock_irqsave(&gc->bgpio_lock, flags); 164 167 165 168 if (val) 166 - bgc->data |= mask; 169 + gc->bgpio_data |= mask; 167 170 else 168 - bgc->data &= ~mask; 171 + gc->bgpio_data &= ~mask; 169 172 170 - bgc->write_reg(bgc->reg_dat, bgc->data); 173 + gc->write_reg(gc->reg_dat, gc->bgpio_data); 171 174 172 - spin_unlock_irqrestore(&bgc->lock, flags); 175 + spin_unlock_irqrestore(&gc->bgpio_lock, flags); 173 176 } 174 177 175 178 static void bgpio_set_with_clear(struct gpio_chip *gc, unsigned int gpio, 176 179 int val) 177 180 { 178 - struct bgpio_chip *bgc = to_bgpio_chip(gc); 179 - unsigned long mask = bgc->pin2mask(bgc, gpio); 181 + unsigned long mask = gc->pin2mask(gc, gpio); 180 182 181 183 if (val) 182 - bgc->write_reg(bgc->reg_set, mask); 184 + gc->write_reg(gc->reg_set, mask); 183 185 else 184 - bgc->write_reg(bgc->reg_clr, mask); 186 + gc->write_reg(gc->reg_clr, mask); 185 187 } 186 188 187 189 static void bgpio_set_set(struct gpio_chip *gc, unsigned int gpio, int val) 188 190 { 189 - struct bgpio_chip *bgc = to_bgpio_chip(gc); 190 - unsigned long mask = bgc->pin2mask(bgc, gpio); 191 + unsigned long mask = gc->pin2mask(gc, gpio); 191 192 unsigned long flags; 192 193 193 - spin_lock_irqsave(&bgc->lock, flags); 194 + spin_lock_irqsave(&gc->bgpio_lock, flags); 194 195 195 196 if (val) 196 - bgc->data |= mask; 197 + gc->bgpio_data |= mask; 197 198 else 198 - bgc->data &= ~mask; 199 + gc->bgpio_data &= ~mask; 199 200 200 - bgc->write_reg(bgc->reg_set, bgc->data); 201 + gc->write_reg(gc->reg_set, gc->bgpio_data); 201 202 202 - spin_unlock_irqrestore(&bgc->lock, flags); 203 + spin_unlock_irqrestore(&gc->bgpio_lock, flags); 203 204 } 204 205 205 - static void bgpio_multiple_get_masks(struct bgpio_chip *bgc, 206 + static void bgpio_multiple_get_masks(struct gpio_chip *gc, 206 207 unsigned long *mask, unsigned long *bits, 207 208 unsigned long *set_mask, 208 209 unsigned long *clear_mask) ··· 209 216 *set_mask = 0; 210 217 *clear_mask = 0; 211 218 212 - for (i = 0; i < bgc->bits; i++) { 219 + for (i = 0; i < gc->bgpio_bits; i++) { 213 220 if (*mask == 0) 214 221 break; 215 222 if (__test_and_clear_bit(i, mask)) { 216 223 if (test_bit(i, bits)) 217 - *set_mask |= bgc->pin2mask(bgc, i); 224 + *set_mask |= gc->pin2mask(gc, i); 218 225 else 219 - *clear_mask |= bgc->pin2mask(bgc, i); 226 + *clear_mask |= gc->pin2mask(gc, i); 220 227 } 221 228 } 222 229 } 223 230 224 - static void bgpio_set_multiple_single_reg(struct bgpio_chip *bgc, 231 + static void bgpio_set_multiple_single_reg(struct gpio_chip *gc, 225 232 unsigned long *mask, 226 233 unsigned long *bits, 227 234 void __iomem *reg) ··· 229 236 unsigned long flags; 230 237 unsigned long set_mask, clear_mask; 231 238 232 - spin_lock_irqsave(&bgc->lock, flags); 239 + spin_lock_irqsave(&gc->bgpio_lock, flags); 233 240 234 - bgpio_multiple_get_masks(bgc, mask, bits, &set_mask, &clear_mask); 241 + bgpio_multiple_get_masks(gc, mask, bits, &set_mask, &clear_mask); 235 242 236 - bgc->data |= set_mask; 237 - bgc->data &= ~clear_mask; 243 + gc->bgpio_data |= set_mask; 244 + gc->bgpio_data &= ~clear_mask; 238 245 239 - bgc->write_reg(reg, bgc->data); 246 + gc->write_reg(reg, gc->bgpio_data); 240 247 241 - spin_unlock_irqrestore(&bgc->lock, flags); 248 + spin_unlock_irqrestore(&gc->bgpio_lock, flags); 242 249 } 243 250 244 251 static void bgpio_set_multiple(struct gpio_chip *gc, unsigned long *mask, 245 252 unsigned long *bits) 246 253 { 247 - struct bgpio_chip *bgc = to_bgpio_chip(gc); 248 - 249 - bgpio_set_multiple_single_reg(bgc, mask, bits, bgc->reg_dat); 254 + bgpio_set_multiple_single_reg(gc, mask, bits, gc->reg_dat); 250 255 } 251 256 252 257 static void bgpio_set_multiple_set(struct gpio_chip *gc, unsigned long *mask, 253 258 unsigned long *bits) 254 259 { 255 - struct bgpio_chip *bgc = to_bgpio_chip(gc); 256 - 257 - bgpio_set_multiple_single_reg(bgc, mask, bits, bgc->reg_set); 260 + bgpio_set_multiple_single_reg(gc, mask, bits, gc->reg_set); 258 261 } 259 262 260 263 static void bgpio_set_multiple_with_clear(struct gpio_chip *gc, 261 264 unsigned long *mask, 262 265 unsigned long *bits) 263 266 { 264 - struct bgpio_chip *bgc = to_bgpio_chip(gc); 265 267 unsigned long set_mask, clear_mask; 266 268 267 - bgpio_multiple_get_masks(bgc, mask, bits, &set_mask, &clear_mask); 269 + bgpio_multiple_get_masks(gc, mask, bits, &set_mask, &clear_mask); 268 270 269 271 if (set_mask) 270 - bgc->write_reg(bgc->reg_set, set_mask); 272 + gc->write_reg(gc->reg_set, set_mask); 271 273 if (clear_mask) 272 - bgc->write_reg(bgc->reg_clr, clear_mask); 274 + gc->write_reg(gc->reg_clr, clear_mask); 273 275 } 274 276 275 277 static int bgpio_simple_dir_in(struct gpio_chip *gc, unsigned int gpio) ··· 288 300 289 301 static int bgpio_dir_in(struct gpio_chip *gc, unsigned int gpio) 290 302 { 291 - struct bgpio_chip *bgc = to_bgpio_chip(gc); 292 303 unsigned long flags; 293 304 294 - spin_lock_irqsave(&bgc->lock, flags); 305 + spin_lock_irqsave(&gc->bgpio_lock, flags); 295 306 296 - bgc->dir &= ~bgc->pin2mask(bgc, gpio); 297 - bgc->write_reg(bgc->reg_dir, bgc->dir); 307 + gc->bgpio_dir &= ~gc->pin2mask(gc, gpio); 308 + gc->write_reg(gc->reg_dir, gc->bgpio_dir); 298 309 299 - spin_unlock_irqrestore(&bgc->lock, flags); 310 + spin_unlock_irqrestore(&gc->bgpio_lock, flags); 300 311 301 312 return 0; 302 313 } 303 314 304 315 static int bgpio_get_dir(struct gpio_chip *gc, unsigned int gpio) 305 316 { 306 - struct bgpio_chip *bgc = to_bgpio_chip(gc); 307 - 308 - return (bgc->read_reg(bgc->reg_dir) & bgc->pin2mask(bgc, gpio)) ? 309 - GPIOF_DIR_OUT : GPIOF_DIR_IN; 317 + /* Return 0 if output, 1 of input */ 318 + return !(gc->read_reg(gc->reg_dir) & gc->pin2mask(gc, gpio)); 310 319 } 311 320 312 321 static int bgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val) 313 322 { 314 - struct bgpio_chip *bgc = to_bgpio_chip(gc); 315 323 unsigned long flags; 316 324 317 325 gc->set(gc, gpio, val); 318 326 319 - spin_lock_irqsave(&bgc->lock, flags); 327 + spin_lock_irqsave(&gc->bgpio_lock, flags); 320 328 321 - bgc->dir |= bgc->pin2mask(bgc, gpio); 322 - bgc->write_reg(bgc->reg_dir, bgc->dir); 329 + gc->bgpio_dir |= gc->pin2mask(gc, gpio); 330 + gc->write_reg(gc->reg_dir, gc->bgpio_dir); 323 331 324 - spin_unlock_irqrestore(&bgc->lock, flags); 332 + spin_unlock_irqrestore(&gc->bgpio_lock, flags); 325 333 326 334 return 0; 327 335 } 328 336 329 337 static int bgpio_dir_in_inv(struct gpio_chip *gc, unsigned int gpio) 330 338 { 331 - struct bgpio_chip *bgc = to_bgpio_chip(gc); 332 339 unsigned long flags; 333 340 334 - spin_lock_irqsave(&bgc->lock, flags); 341 + spin_lock_irqsave(&gc->bgpio_lock, flags); 335 342 336 - bgc->dir |= bgc->pin2mask(bgc, gpio); 337 - bgc->write_reg(bgc->reg_dir, bgc->dir); 343 + gc->bgpio_dir |= gc->pin2mask(gc, gpio); 344 + gc->write_reg(gc->reg_dir, gc->bgpio_dir); 338 345 339 - spin_unlock_irqrestore(&bgc->lock, flags); 346 + spin_unlock_irqrestore(&gc->bgpio_lock, flags); 340 347 341 348 return 0; 342 349 } 343 350 344 351 static int bgpio_dir_out_inv(struct gpio_chip *gc, unsigned int gpio, int val) 345 352 { 346 - struct bgpio_chip *bgc = to_bgpio_chip(gc); 347 353 unsigned long flags; 348 354 349 355 gc->set(gc, gpio, val); 350 356 351 - spin_lock_irqsave(&bgc->lock, flags); 357 + spin_lock_irqsave(&gc->bgpio_lock, flags); 352 358 353 - bgc->dir &= ~bgc->pin2mask(bgc, gpio); 354 - bgc->write_reg(bgc->reg_dir, bgc->dir); 359 + gc->bgpio_dir &= ~gc->pin2mask(gc, gpio); 360 + gc->write_reg(gc->reg_dir, gc->bgpio_dir); 355 361 356 - spin_unlock_irqrestore(&bgc->lock, flags); 362 + spin_unlock_irqrestore(&gc->bgpio_lock, flags); 357 363 358 364 return 0; 359 365 } 360 366 361 367 static int bgpio_get_dir_inv(struct gpio_chip *gc, unsigned int gpio) 362 368 { 363 - struct bgpio_chip *bgc = to_bgpio_chip(gc); 364 - 365 - return (bgc->read_reg(bgc->reg_dir) & bgc->pin2mask(bgc, gpio)) ? 366 - GPIOF_DIR_IN : GPIOF_DIR_OUT; 369 + /* Return 0 if output, 1 if input */ 370 + return !!(gc->read_reg(gc->reg_dir) & gc->pin2mask(gc, gpio)); 367 371 } 368 372 369 373 static int bgpio_setup_accessors(struct device *dev, 370 - struct bgpio_chip *bgc, 374 + struct gpio_chip *gc, 371 375 bool bit_be, 372 376 bool byte_be) 373 377 { 374 378 375 - switch (bgc->bits) { 379 + switch (gc->bgpio_bits) { 376 380 case 8: 377 - bgc->read_reg = bgpio_read8; 378 - bgc->write_reg = bgpio_write8; 381 + gc->read_reg = bgpio_read8; 382 + gc->write_reg = bgpio_write8; 379 383 break; 380 384 case 16: 381 385 if (byte_be) { 382 - bgc->read_reg = bgpio_read16be; 383 - bgc->write_reg = bgpio_write16be; 386 + gc->read_reg = bgpio_read16be; 387 + gc->write_reg = bgpio_write16be; 384 388 } else { 385 - bgc->read_reg = bgpio_read16; 386 - bgc->write_reg = bgpio_write16; 389 + gc->read_reg = bgpio_read16; 390 + gc->write_reg = bgpio_write16; 387 391 } 388 392 break; 389 393 case 32: 390 394 if (byte_be) { 391 - bgc->read_reg = bgpio_read32be; 392 - bgc->write_reg = bgpio_write32be; 395 + gc->read_reg = bgpio_read32be; 396 + gc->write_reg = bgpio_write32be; 393 397 } else { 394 - bgc->read_reg = bgpio_read32; 395 - bgc->write_reg = bgpio_write32; 398 + gc->read_reg = bgpio_read32; 399 + gc->write_reg = bgpio_write32; 396 400 } 397 401 break; 398 402 #if BITS_PER_LONG >= 64 ··· 394 414 "64 bit big endian byte order unsupported\n"); 395 415 return -EINVAL; 396 416 } else { 397 - bgc->read_reg = bgpio_read64; 398 - bgc->write_reg = bgpio_write64; 417 + gc->read_reg = bgpio_read64; 418 + gc->write_reg = bgpio_write64; 399 419 } 400 420 break; 401 421 #endif /* BITS_PER_LONG >= 64 */ 402 422 default: 403 - dev_err(dev, "unsupported data width %u bits\n", bgc->bits); 423 + dev_err(dev, "unsupported data width %u bits\n", gc->bgpio_bits); 404 424 return -EINVAL; 405 425 } 406 426 407 - bgc->pin2mask = bit_be ? bgpio_pin2mask_be : bgpio_pin2mask; 427 + gc->pin2mask = bit_be ? bgpio_pin2mask_be : bgpio_pin2mask; 408 428 409 429 return 0; 410 430 } ··· 431 451 * - an input direction register (named "dirin") where a 1 bit indicates 432 452 * the GPIO is an input. 433 453 */ 434 - static int bgpio_setup_io(struct bgpio_chip *bgc, 454 + static int bgpio_setup_io(struct gpio_chip *gc, 435 455 void __iomem *dat, 436 456 void __iomem *set, 437 457 void __iomem *clr, 438 458 unsigned long flags) 439 459 { 440 460 441 - bgc->reg_dat = dat; 442 - if (!bgc->reg_dat) 461 + gc->reg_dat = dat; 462 + if (!gc->reg_dat) 443 463 return -EINVAL; 444 464 445 465 if (set && clr) { 446 - bgc->reg_set = set; 447 - bgc->reg_clr = clr; 448 - bgc->gc.set = bgpio_set_with_clear; 449 - bgc->gc.set_multiple = bgpio_set_multiple_with_clear; 466 + gc->reg_set = set; 467 + gc->reg_clr = clr; 468 + gc->set = bgpio_set_with_clear; 469 + gc->set_multiple = bgpio_set_multiple_with_clear; 450 470 } else if (set && !clr) { 451 - bgc->reg_set = set; 452 - bgc->gc.set = bgpio_set_set; 453 - bgc->gc.set_multiple = bgpio_set_multiple_set; 471 + gc->reg_set = set; 472 + gc->set = bgpio_set_set; 473 + gc->set_multiple = bgpio_set_multiple_set; 454 474 } else if (flags & BGPIOF_NO_OUTPUT) { 455 - bgc->gc.set = bgpio_set_none; 456 - bgc->gc.set_multiple = NULL; 475 + gc->set = bgpio_set_none; 476 + gc->set_multiple = NULL; 457 477 } else { 458 - bgc->gc.set = bgpio_set; 459 - bgc->gc.set_multiple = bgpio_set_multiple; 478 + gc->set = bgpio_set; 479 + gc->set_multiple = bgpio_set_multiple; 460 480 } 461 481 462 482 if (!(flags & BGPIOF_UNREADABLE_REG_SET) && 463 483 (flags & BGPIOF_READ_OUTPUT_REG_SET)) 464 - bgc->gc.get = bgpio_get_set; 484 + gc->get = bgpio_get_set; 465 485 else 466 - bgc->gc.get = bgpio_get; 486 + gc->get = bgpio_get; 467 487 468 488 return 0; 469 489 } 470 490 471 - static int bgpio_setup_direction(struct bgpio_chip *bgc, 491 + static int bgpio_setup_direction(struct gpio_chip *gc, 472 492 void __iomem *dirout, 473 493 void __iomem *dirin, 474 494 unsigned long flags) ··· 476 496 if (dirout && dirin) { 477 497 return -EINVAL; 478 498 } else if (dirout) { 479 - bgc->reg_dir = dirout; 480 - bgc->gc.direction_output = bgpio_dir_out; 481 - bgc->gc.direction_input = bgpio_dir_in; 482 - bgc->gc.get_direction = bgpio_get_dir; 499 + gc->reg_dir = dirout; 500 + gc->direction_output = bgpio_dir_out; 501 + gc->direction_input = bgpio_dir_in; 502 + gc->get_direction = bgpio_get_dir; 483 503 } else if (dirin) { 484 - bgc->reg_dir = dirin; 485 - bgc->gc.direction_output = bgpio_dir_out_inv; 486 - bgc->gc.direction_input = bgpio_dir_in_inv; 487 - bgc->gc.get_direction = bgpio_get_dir_inv; 504 + gc->reg_dir = dirin; 505 + gc->direction_output = bgpio_dir_out_inv; 506 + gc->direction_input = bgpio_dir_in_inv; 507 + gc->get_direction = bgpio_get_dir_inv; 488 508 } else { 489 509 if (flags & BGPIOF_NO_OUTPUT) 490 - bgc->gc.direction_output = bgpio_dir_out_err; 510 + gc->direction_output = bgpio_dir_out_err; 491 511 else 492 - bgc->gc.direction_output = bgpio_simple_dir_out; 493 - bgc->gc.direction_input = bgpio_simple_dir_in; 512 + gc->direction_output = bgpio_simple_dir_out; 513 + gc->direction_input = bgpio_simple_dir_in; 494 514 } 495 515 496 516 return 0; ··· 504 524 return -EINVAL; 505 525 } 506 526 507 - int bgpio_remove(struct bgpio_chip *bgc) 508 - { 509 - gpiochip_remove(&bgc->gc); 510 - return 0; 511 - } 512 - EXPORT_SYMBOL_GPL(bgpio_remove); 513 - 514 - int bgpio_init(struct bgpio_chip *bgc, struct device *dev, 527 + int bgpio_init(struct gpio_chip *gc, struct device *dev, 515 528 unsigned long sz, void __iomem *dat, void __iomem *set, 516 529 void __iomem *clr, void __iomem *dirout, void __iomem *dirin, 517 530 unsigned long flags) ··· 514 541 if (!is_power_of_2(sz)) 515 542 return -EINVAL; 516 543 517 - bgc->bits = sz * 8; 518 - if (bgc->bits > BITS_PER_LONG) 544 + gc->bgpio_bits = sz * 8; 545 + if (gc->bgpio_bits > BITS_PER_LONG) 519 546 return -EINVAL; 520 547 521 - spin_lock_init(&bgc->lock); 522 - bgc->gc.parent = dev; 523 - bgc->gc.label = dev_name(dev); 524 - bgc->gc.base = -1; 525 - bgc->gc.ngpio = bgc->bits; 526 - bgc->gc.request = bgpio_request; 548 + spin_lock_init(&gc->bgpio_lock); 549 + gc->parent = dev; 550 + gc->label = dev_name(dev); 551 + gc->base = -1; 552 + gc->ngpio = gc->bgpio_bits; 553 + gc->request = bgpio_request; 527 554 528 - ret = bgpio_setup_io(bgc, dat, set, clr, flags); 555 + ret = bgpio_setup_io(gc, dat, set, clr, flags); 529 556 if (ret) 530 557 return ret; 531 558 532 - ret = bgpio_setup_accessors(dev, bgc, flags & BGPIOF_BIG_ENDIAN, 559 + ret = bgpio_setup_accessors(dev, gc, flags & BGPIOF_BIG_ENDIAN, 533 560 flags & BGPIOF_BIG_ENDIAN_BYTE_ORDER); 534 561 if (ret) 535 562 return ret; 536 563 537 - ret = bgpio_setup_direction(bgc, dirout, dirin, flags); 564 + ret = bgpio_setup_direction(gc, dirout, dirin, flags); 538 565 if (ret) 539 566 return ret; 540 567 541 - bgc->data = bgc->read_reg(bgc->reg_dat); 542 - if (bgc->gc.set == bgpio_set_set && 568 + gc->bgpio_data = gc->read_reg(gc->reg_dat); 569 + if (gc->set == bgpio_set_set && 543 570 !(flags & BGPIOF_UNREADABLE_REG_SET)) 544 - bgc->data = bgc->read_reg(bgc->reg_set); 545 - if (bgc->reg_dir && !(flags & BGPIOF_UNREADABLE_REG_DIR)) 546 - bgc->dir = bgc->read_reg(bgc->reg_dir); 571 + gc->bgpio_data = gc->read_reg(gc->reg_set); 572 + if (gc->reg_dir && !(flags & BGPIOF_UNREADABLE_REG_DIR)) 573 + gc->bgpio_dir = gc->read_reg(gc->reg_dir); 547 574 548 575 return ret; 549 576 } ··· 581 608 unsigned long sz; 582 609 unsigned long flags = pdev->id_entry->driver_data; 583 610 int err; 584 - struct bgpio_chip *bgc; 611 + struct gpio_chip *gc; 585 612 struct bgpio_pdata *pdata = dev_get_platdata(dev); 586 613 587 614 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dat"); ··· 610 637 if (IS_ERR(dirin)) 611 638 return PTR_ERR(dirin); 612 639 613 - bgc = devm_kzalloc(&pdev->dev, sizeof(*bgc), GFP_KERNEL); 614 - if (!bgc) 640 + gc = devm_kzalloc(&pdev->dev, sizeof(*gc), GFP_KERNEL); 641 + if (!gc) 615 642 return -ENOMEM; 616 643 617 - err = bgpio_init(bgc, dev, sz, dat, set, clr, dirout, dirin, flags); 644 + err = bgpio_init(gc, dev, sz, dat, set, clr, dirout, dirin, flags); 618 645 if (err) 619 646 return err; 620 647 621 648 if (pdata) { 622 649 if (pdata->label) 623 - bgc->gc.label = pdata->label; 624 - bgc->gc.base = pdata->base; 650 + gc->label = pdata->label; 651 + gc->base = pdata->base; 625 652 if (pdata->ngpio > 0) 626 - bgc->gc.ngpio = pdata->ngpio; 653 + gc->ngpio = pdata->ngpio; 627 654 } 628 655 629 - platform_set_drvdata(pdev, bgc); 656 + platform_set_drvdata(pdev, gc); 630 657 631 - return gpiochip_add(&bgc->gc); 658 + return gpiochip_add_data(gc, NULL); 632 659 } 633 660 634 661 static int bgpio_pdev_remove(struct platform_device *pdev) 635 662 { 636 - struct bgpio_chip *bgc = platform_get_drvdata(pdev); 663 + struct gpio_chip *gc = platform_get_drvdata(pdev); 637 664 638 - return bgpio_remove(bgc); 665 + gpiochip_remove(gc); 666 + return 0; 639 667 } 640 668 641 669 static const struct platform_device_id bgpio_id_table[] = {
+32 -41
drivers/gpio/gpio-grgpio.c
··· 31 31 #include <linux/gpio.h> 32 32 #include <linux/slab.h> 33 33 #include <linux/err.h> 34 - #include <linux/basic_mmio_gpio.h> 34 + #include <linux/gpio/driver.h> 35 35 #include <linux/interrupt.h> 36 36 #include <linux/irq.h> 37 37 #include <linux/irqdomain.h> ··· 63 63 }; 64 64 65 65 struct grgpio_priv { 66 - struct bgpio_chip bgc; 66 + struct gpio_chip gc; 67 67 void __iomem *regs; 68 68 struct device *dev; 69 69 ··· 92 92 struct grgpio_lirq lirqs[GRGPIO_MAX_NGPIO]; 93 93 }; 94 94 95 - static inline struct grgpio_priv *grgpio_gc_to_priv(struct gpio_chip *gc) 96 - { 97 - struct bgpio_chip *bgc = to_bgpio_chip(gc); 98 - 99 - return container_of(bgc, struct grgpio_priv, bgc); 100 - } 101 - 102 95 static void grgpio_set_imask(struct grgpio_priv *priv, unsigned int offset, 103 96 int val) 104 97 { 105 - struct bgpio_chip *bgc = &priv->bgc; 106 - unsigned long mask = bgc->pin2mask(bgc, offset); 98 + struct gpio_chip *gc = &priv->gc; 99 + unsigned long mask = gc->pin2mask(gc, offset); 107 100 108 101 if (val) 109 102 priv->imask |= mask; 110 103 else 111 104 priv->imask &= ~mask; 112 - bgc->write_reg(priv->regs + GRGPIO_IMASK, priv->imask); 105 + gc->write_reg(priv->regs + GRGPIO_IMASK, priv->imask); 113 106 } 114 107 115 108 static int grgpio_to_irq(struct gpio_chip *gc, unsigned offset) 116 109 { 117 - struct grgpio_priv *priv = grgpio_gc_to_priv(gc); 110 + struct grgpio_priv *priv = gpiochip_get_data(gc); 118 111 119 112 if (offset >= gc->ngpio) 120 113 return -ENXIO; ··· 151 158 return -EINVAL; 152 159 } 153 160 154 - spin_lock_irqsave(&priv->bgc.lock, flags); 161 + spin_lock_irqsave(&priv->gc.bgpio_lock, flags); 155 162 156 - ipol = priv->bgc.read_reg(priv->regs + GRGPIO_IPOL) & ~mask; 157 - iedge = priv->bgc.read_reg(priv->regs + GRGPIO_IEDGE) & ~mask; 163 + ipol = priv->gc.read_reg(priv->regs + GRGPIO_IPOL) & ~mask; 164 + iedge = priv->gc.read_reg(priv->regs + GRGPIO_IEDGE) & ~mask; 158 165 159 - priv->bgc.write_reg(priv->regs + GRGPIO_IPOL, ipol | pol); 160 - priv->bgc.write_reg(priv->regs + GRGPIO_IEDGE, iedge | edge); 166 + priv->gc.write_reg(priv->regs + GRGPIO_IPOL, ipol | pol); 167 + priv->gc.write_reg(priv->regs + GRGPIO_IEDGE, iedge | edge); 161 168 162 - spin_unlock_irqrestore(&priv->bgc.lock, flags); 169 + spin_unlock_irqrestore(&priv->gc.bgpio_lock, flags); 163 170 164 171 return 0; 165 172 } ··· 170 177 int offset = d->hwirq; 171 178 unsigned long flags; 172 179 173 - spin_lock_irqsave(&priv->bgc.lock, flags); 180 + spin_lock_irqsave(&priv->gc.bgpio_lock, flags); 174 181 175 182 grgpio_set_imask(priv, offset, 0); 176 183 177 - spin_unlock_irqrestore(&priv->bgc.lock, flags); 184 + spin_unlock_irqrestore(&priv->gc.bgpio_lock, flags); 178 185 } 179 186 180 187 static void grgpio_irq_unmask(struct irq_data *d) ··· 183 190 int offset = d->hwirq; 184 191 unsigned long flags; 185 192 186 - spin_lock_irqsave(&priv->bgc.lock, flags); 193 + spin_lock_irqsave(&priv->gc.bgpio_lock, flags); 187 194 188 195 grgpio_set_imask(priv, offset, 1); 189 196 190 - spin_unlock_irqrestore(&priv->bgc.lock, flags); 197 + spin_unlock_irqrestore(&priv->gc.bgpio_lock, flags); 191 198 } 192 199 193 200 static struct irq_chip grgpio_irq_chip = { ··· 200 207 static irqreturn_t grgpio_irq_handler(int irq, void *dev) 201 208 { 202 209 struct grgpio_priv *priv = dev; 203 - int ngpio = priv->bgc.gc.ngpio; 210 + int ngpio = priv->gc.ngpio; 204 211 unsigned long flags; 205 212 int i; 206 213 int match = 0; 207 214 208 - spin_lock_irqsave(&priv->bgc.lock, flags); 215 + spin_lock_irqsave(&priv->gc.bgpio_lock, flags); 209 216 210 217 /* 211 218 * For each gpio line, call its interrupt handler if it its underlying ··· 221 228 } 222 229 } 223 230 224 - spin_unlock_irqrestore(&priv->bgc.lock, flags); 231 + spin_unlock_irqrestore(&priv->gc.bgpio_lock, flags); 225 232 226 233 if (!match) 227 234 dev_warn(priv->dev, "No gpio line matched irq %d\n", irq); ··· 253 260 dev_dbg(priv->dev, "Mapping irq %d for gpio line %d\n", 254 261 irq, offset); 255 262 256 - spin_lock_irqsave(&priv->bgc.lock, flags); 263 + spin_lock_irqsave(&priv->gc.bgpio_lock, flags); 257 264 258 265 /* Request underlying irq if not already requested */ 259 266 lirq->irq = irq; ··· 266 273 "Could not request underlying irq %d\n", 267 274 uirq->uirq); 268 275 269 - spin_unlock_irqrestore(&priv->bgc.lock, flags); 276 + spin_unlock_irqrestore(&priv->gc.bgpio_lock, flags); 270 277 271 278 return ret; 272 279 } 273 280 } 274 281 uirq->refcnt++; 275 282 276 - spin_unlock_irqrestore(&priv->bgc.lock, flags); 283 + spin_unlock_irqrestore(&priv->gc.bgpio_lock, flags); 277 284 278 285 /* Setup irq */ 279 286 irq_set_chip_data(irq, priv); ··· 291 298 struct grgpio_lirq *lirq; 292 299 struct grgpio_uirq *uirq; 293 300 unsigned long flags; 294 - int ngpio = priv->bgc.gc.ngpio; 301 + int ngpio = priv->gc.ngpio; 295 302 int i; 296 303 297 304 irq_set_chip_and_handler(irq, NULL, NULL); 298 305 irq_set_chip_data(irq, NULL); 299 306 300 - spin_lock_irqsave(&priv->bgc.lock, flags); 307 + spin_lock_irqsave(&priv->gc.bgpio_lock, flags); 301 308 302 309 /* Free underlying irq if last user unmapped */ 303 310 index = -1; ··· 319 326 free_irq(uirq->uirq, priv); 320 327 } 321 328 322 - spin_unlock_irqrestore(&priv->bgc.lock, flags); 329 + spin_unlock_irqrestore(&priv->gc.bgpio_lock, flags); 323 330 } 324 331 325 332 static const struct irq_domain_ops grgpio_irq_domain_ops = { ··· 334 341 struct device_node *np = ofdev->dev.of_node; 335 342 void __iomem *regs; 336 343 struct gpio_chip *gc; 337 - struct bgpio_chip *bgc; 338 344 struct grgpio_priv *priv; 339 345 struct resource *res; 340 346 int err; ··· 351 359 if (IS_ERR(regs)) 352 360 return PTR_ERR(regs); 353 361 354 - bgc = &priv->bgc; 355 - err = bgpio_init(bgc, &ofdev->dev, 4, regs + GRGPIO_DATA, 362 + gc = &priv->gc; 363 + err = bgpio_init(gc, &ofdev->dev, 4, regs + GRGPIO_DATA, 356 364 regs + GRGPIO_OUTPUT, NULL, regs + GRGPIO_DIR, NULL, 357 365 BGPIOF_BIG_ENDIAN_BYTE_ORDER); 358 366 if (err) { ··· 361 369 } 362 370 363 371 priv->regs = regs; 364 - priv->imask = bgc->read_reg(regs + GRGPIO_IMASK); 372 + priv->imask = gc->read_reg(regs + GRGPIO_IMASK); 365 373 priv->dev = &ofdev->dev; 366 374 367 - gc = &bgc->gc; 368 375 gc->of_node = np; 369 376 gc->owner = THIS_MODULE; 370 377 gc->to_irq = grgpio_to_irq; ··· 426 435 427 436 platform_set_drvdata(ofdev, priv); 428 437 429 - err = gpiochip_add(gc); 438 + err = gpiochip_add_data(gc, priv); 430 439 if (err) { 431 440 dev_err(&ofdev->dev, "Could not add gpiochip\n"); 432 441 if (priv->domain) ··· 447 456 int i; 448 457 int ret = 0; 449 458 450 - spin_lock_irqsave(&priv->bgc.lock, flags); 459 + spin_lock_irqsave(&priv->gc.bgpio_lock, flags); 451 460 452 461 if (priv->domain) { 453 462 for (i = 0; i < GRGPIO_MAX_NGPIO; i++) { ··· 458 467 } 459 468 } 460 469 461 - gpiochip_remove(&priv->bgc.gc); 470 + gpiochip_remove(&priv->gc); 462 471 463 472 if (priv->domain) 464 473 irq_domain_remove(priv->domain); 465 474 466 475 out: 467 - spin_unlock_irqrestore(&priv->bgc.lock, flags); 476 + spin_unlock_irqrestore(&priv->gc.bgpio_lock, flags); 468 477 469 478 return ret; 470 479 }
+14 -15
drivers/gpio/gpio-moxart.c
··· 14 14 #include <linux/init.h> 15 15 #include <linux/irq.h> 16 16 #include <linux/io.h> 17 - #include <linux/gpio.h> 18 17 #include <linux/platform_device.h> 19 18 #include <linux/module.h> 20 19 #include <linux/of_address.h> ··· 22 23 #include <linux/delay.h> 23 24 #include <linux/timer.h> 24 25 #include <linux/bitops.h> 25 - #include <linux/basic_mmio_gpio.h> 26 + #include <linux/gpio/driver.h> 26 27 27 28 #define GPIO_DATA_OUT 0x00 28 29 #define GPIO_DATA_IN 0x04 ··· 32 33 { 33 34 struct device *dev = &pdev->dev; 34 35 struct resource *res; 35 - struct bgpio_chip *bgc; 36 + struct gpio_chip *gc; 36 37 void __iomem *base; 37 38 int ret; 38 39 39 - bgc = devm_kzalloc(dev, sizeof(*bgc), GFP_KERNEL); 40 - if (!bgc) 40 + gc = devm_kzalloc(dev, sizeof(*gc), GFP_KERNEL); 41 + if (!gc) 41 42 return -ENOMEM; 42 43 43 44 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); ··· 45 46 if (IS_ERR(base)) 46 47 return PTR_ERR(base); 47 48 48 - ret = bgpio_init(bgc, dev, 4, base + GPIO_DATA_IN, 49 + ret = bgpio_init(gc, dev, 4, base + GPIO_DATA_IN, 49 50 base + GPIO_DATA_OUT, NULL, 50 51 base + GPIO_PIN_DIRECTION, NULL, 51 52 BGPIOF_READ_OUTPUT_REG_SET); ··· 54 55 return ret; 55 56 } 56 57 57 - bgc->gc.label = "moxart-gpio"; 58 - bgc->gc.request = gpiochip_generic_request; 59 - bgc->gc.free = gpiochip_generic_free; 60 - bgc->data = bgc->read_reg(bgc->reg_set); 61 - bgc->gc.base = 0; 62 - bgc->gc.ngpio = 32; 63 - bgc->gc.parent = dev; 64 - bgc->gc.owner = THIS_MODULE; 58 + gc->label = "moxart-gpio"; 59 + gc->request = gpiochip_generic_request; 60 + gc->free = gpiochip_generic_free; 61 + gc->bgpio_data = bgc->read_reg(bgc->reg_set); 62 + gc->base = 0; 63 + gc->ngpio = 32; 64 + gc->parent = dev; 65 + gc->owner = THIS_MODULE; 65 66 66 - ret = gpiochip_add(&bgc->gc); 67 + ret = gpiochip_add_data(gc, NULL); 67 68 if (ret) { 68 69 dev_err(dev, "%s: gpiochip_add failed\n", 69 70 dev->of_node->full_name);
+12 -15
drivers/gpio/gpio-mxc.c
··· 26 26 #include <linux/irq.h> 27 27 #include <linux/irqdomain.h> 28 28 #include <linux/irqchip/chained_irq.h> 29 - #include <linux/gpio.h> 30 29 #include <linux/platform_device.h> 31 30 #include <linux/slab.h> 32 - #include <linux/basic_mmio_gpio.h> 31 + #include <linux/gpio/driver.h> 32 + /* FIXME: for gpio_get_value() replace this with direct register read */ 33 + #include <linux/gpio.h> 33 34 #include <linux/of.h> 34 35 #include <linux/of_device.h> 35 36 #include <linux/module.h> ··· 65 64 int irq; 66 65 int irq_high; 67 66 struct irq_domain *domain; 68 - struct bgpio_chip bgc; 67 + struct gpio_chip gc; 69 68 u32 both_edges; 70 69 }; 71 70 ··· 173 172 struct mxc_gpio_port *port = gc->private; 174 173 u32 bit, val; 175 174 u32 gpio_idx = d->hwirq; 176 - u32 gpio = port->bgc.gc.base + gpio_idx; 175 + u32 gpio = port->gc.base + gpio_idx; 177 176 int edge; 178 177 void __iomem *reg = port->base; 179 178 ··· 399 398 400 399 static int mxc_gpio_to_irq(struct gpio_chip *gc, unsigned offset) 401 400 { 402 - struct bgpio_chip *bgc = to_bgpio_chip(gc); 403 - struct mxc_gpio_port *port = 404 - container_of(bgc, struct mxc_gpio_port, bgc); 401 + struct mxc_gpio_port *port = gpiochip_get_data(gc); 405 402 406 403 return irq_find_mapping(port->domain, offset); 407 404 } ··· 450 451 port); 451 452 } 452 453 453 - err = bgpio_init(&port->bgc, &pdev->dev, 4, 454 + err = bgpio_init(&port->gc, &pdev->dev, 4, 454 455 port->base + GPIO_PSR, 455 456 port->base + GPIO_DR, NULL, 456 457 port->base + GPIO_GDIR, NULL, ··· 458 459 if (err) 459 460 goto out_bgio; 460 461 461 - port->bgc.gc.to_irq = mxc_gpio_to_irq; 462 - port->bgc.gc.base = (pdev->id < 0) ? of_alias_get_id(np, "gpio") * 32 : 462 + port->gc.to_irq = mxc_gpio_to_irq; 463 + port->gc.base = (pdev->id < 0) ? of_alias_get_id(np, "gpio") * 32 : 463 464 pdev->id * 32; 464 465 465 - err = gpiochip_add(&port->bgc.gc); 466 + err = gpiochip_add_data(&port->gc, port); 466 467 if (err) 467 - goto out_bgpio_remove; 468 + goto out_bgio; 468 469 469 470 irq_base = irq_alloc_descs(-1, 0, 32, numa_node_id()); 470 471 if (irq_base < 0) { ··· 493 494 out_irqdesc_free: 494 495 irq_free_descs(irq_base, 32); 495 496 out_gpiochip_remove: 496 - gpiochip_remove(&port->bgc.gc); 497 - out_bgpio_remove: 498 - bgpio_remove(&port->bgc); 497 + gpiochip_remove(&port->gc); 499 498 out_bgio: 500 499 dev_info(&pdev->dev, "%s failed with errno %d\n", __func__, err); 501 500 return err;
+14 -19
drivers/gpio/gpio-mxs.c
··· 26 26 #include <linux/io.h> 27 27 #include <linux/irq.h> 28 28 #include <linux/irqdomain.h> 29 - #include <linux/gpio.h> 30 29 #include <linux/of.h> 31 30 #include <linux/of_address.h> 32 31 #include <linux/of_device.h> 33 32 #include <linux/platform_device.h> 34 33 #include <linux/slab.h> 35 - #include <linux/basic_mmio_gpio.h> 34 + #include <linux/gpio/driver.h> 35 + /* FIXME: for gpio_get_value(), replace this by direct register read */ 36 + #include <linux/gpio.h> 36 37 #include <linux/module.h> 37 38 38 39 #define MXS_SET 0x4 ··· 65 64 int id; 66 65 int irq; 67 66 struct irq_domain *domain; 68 - struct bgpio_chip bgc; 67 + struct gpio_chip gc; 69 68 enum mxs_gpio_id devid; 70 69 u32 both_edges; 71 70 }; ··· 94 93 port->both_edges &= ~pin_mask; 95 94 switch (type) { 96 95 case IRQ_TYPE_EDGE_BOTH: 97 - val = gpio_get_value(port->bgc.gc.base + d->hwirq); 96 + val = gpio_get_value(port->gc.base + d->hwirq); 98 97 if (val) 99 98 edge = GPIO_INT_FALL_EDGE; 100 99 else ··· 226 225 227 226 static int mxs_gpio_to_irq(struct gpio_chip *gc, unsigned offset) 228 227 { 229 - struct bgpio_chip *bgc = to_bgpio_chip(gc); 230 - struct mxs_gpio_port *port = 231 - container_of(bgc, struct mxs_gpio_port, bgc); 228 + struct mxs_gpio_port *port = gpiochip_get_data(gc); 232 229 233 230 return irq_find_mapping(port->domain, offset); 234 231 } 235 232 236 233 static int mxs_gpio_get_direction(struct gpio_chip *gc, unsigned offset) 237 234 { 238 - struct bgpio_chip *bgc = to_bgpio_chip(gc); 239 - struct mxs_gpio_port *port = 240 - container_of(bgc, struct mxs_gpio_port, bgc); 235 + struct mxs_gpio_port *port = gpiochip_get_data(gc); 241 236 u32 mask = 1 << offset; 242 237 u32 dir; 243 238 ··· 327 330 irq_set_chained_handler_and_data(port->irq, mxs_gpio_irq_handler, 328 331 port); 329 332 330 - err = bgpio_init(&port->bgc, &pdev->dev, 4, 333 + err = bgpio_init(&port->gc, &pdev->dev, 4, 331 334 port->base + PINCTRL_DIN(port), 332 335 port->base + PINCTRL_DOUT(port) + MXS_SET, 333 336 port->base + PINCTRL_DOUT(port) + MXS_CLR, 334 337 port->base + PINCTRL_DOE(port), NULL, 0); 335 338 if (err) 336 - goto out_irqdesc_free; 339 + goto out_irqdomain_remove; 337 340 338 - port->bgc.gc.to_irq = mxs_gpio_to_irq; 339 - port->bgc.gc.get_direction = mxs_gpio_get_direction; 340 - port->bgc.gc.base = port->id * 32; 341 + port->gc.to_irq = mxs_gpio_to_irq; 342 + port->gc.get_direction = mxs_gpio_get_direction; 343 + port->gc.base = port->id * 32; 341 344 342 - err = gpiochip_add(&port->bgc.gc); 345 + err = gpiochip_add_data(&port->gc, port); 343 346 if (err) 344 - goto out_bgpio_remove; 347 + goto out_irqdomain_remove; 345 348 346 349 return 0; 347 350 348 - out_bgpio_remove: 349 - bgpio_remove(&port->bgc); 350 351 out_irqdomain_remove: 351 352 irq_domain_remove(port->domain); 352 353 out_irqdesc_free:
+6 -7
drivers/gpio/gpio-sodaville.c
··· 10 10 */ 11 11 12 12 #include <linux/errno.h> 13 - #include <linux/gpio.h> 14 13 #include <linux/init.h> 15 14 #include <linux/io.h> 16 15 #include <linux/irq.h> ··· 19 20 #include <linux/pci.h> 20 21 #include <linux/platform_device.h> 21 22 #include <linux/of_irq.h> 22 - #include <linux/basic_mmio_gpio.h> 23 + #include <linux/gpio/driver.h> 23 24 24 25 #define DRV_NAME "sdv_gpio" 25 26 #define SDV_NUM_PUB_GPIOS 12 ··· 42 43 void __iomem *gpio_pub_base; 43 44 struct irq_domain *id; 44 45 struct irq_chip_generic *gc; 45 - struct bgpio_chip bgpio; 46 + struct gpio_chip chip; 46 47 }; 47 48 48 49 static int sdv_gpio_pub_set_type(struct irq_data *d, unsigned int type) ··· 225 226 writel(mux_val, sd->gpio_pub_base + GPMUXCTL); 226 227 } 227 228 228 - ret = bgpio_init(&sd->bgpio, &pdev->dev, 4, 229 + ret = bgpio_init(&sd->chip, &pdev->dev, 4, 229 230 sd->gpio_pub_base + GPINR, sd->gpio_pub_base + GPOUTR, 230 231 NULL, sd->gpio_pub_base + GPOER, NULL, 0); 231 232 if (ret) 232 233 goto unmap; 233 - sd->bgpio.gc.ngpio = SDV_NUM_PUB_GPIOS; 234 + sd->chip.ngpio = SDV_NUM_PUB_GPIOS; 234 235 235 - ret = gpiochip_add(&sd->bgpio.gc); 236 + ret = gpiochip_add_data(&sd->chip, sd); 236 237 if (ret < 0) { 237 238 dev_err(&pdev->dev, "gpiochip_add() failed.\n"); 238 239 goto unmap; ··· 264 265 free_irq(pdev->irq, sd); 265 266 irq_free_descs(sd->irq_base, SDV_NUM_PUB_GPIOS); 266 267 267 - gpiochip_remove(&sd->bgpio.gc); 268 + gpiochip_remove(&sd->chip); 268 269 pci_release_region(pdev, GPIO_BAR); 269 270 iounmap(sd->gpio_pub_base); 270 271 pci_disable_device(pdev);
+16 -24
drivers/gpio/gpio-xgene-sb.c
··· 23 23 #include <linux/io.h> 24 24 #include <linux/platform_device.h> 25 25 #include <linux/of_gpio.h> 26 - #include <linux/gpio.h> 27 26 #include <linux/gpio/driver.h> 28 27 #include <linux/acpi.h> 29 - #include <linux/basic_mmio_gpio.h> 30 28 31 29 #include "gpiolib.h" 32 30 ··· 41 43 42 44 /** 43 45 * struct xgene_gpio_sb - GPIO-Standby private data structure. 44 - * @bgc: memory-mapped GPIO controllers. 46 + * @gc: memory-mapped GPIO controllers. 45 47 * @irq: Mapping GPIO pins and interrupt number 46 48 * nirq: Number of GPIO pins that supports interrupt 47 49 */ 48 50 struct xgene_gpio_sb { 49 - struct bgpio_chip bgc; 51 + struct gpio_chip gc; 50 52 u32 *irq; 51 53 u32 nirq; 52 54 }; 53 55 54 - static inline struct xgene_gpio_sb *to_xgene_gpio_sb(struct gpio_chip *gc) 55 - { 56 - struct bgpio_chip *bgc = to_bgpio_chip(gc); 57 - 58 - return container_of(bgc, struct xgene_gpio_sb, bgc); 59 - } 60 - 61 - static void xgene_gpio_set_bit(struct bgpio_chip *bgc, void __iomem *reg, u32 gpio, int val) 56 + static void xgene_gpio_set_bit(struct gpio_chip *gc, void __iomem *reg, u32 gpio, int val) 62 57 { 63 58 u32 data; 64 59 65 - data = bgc->read_reg(reg); 60 + data = gc->read_reg(reg); 66 61 if (val) 67 62 data |= GPIO_MASK(gpio); 68 63 else 69 64 data &= ~GPIO_MASK(gpio); 70 - bgc->write_reg(reg, data); 65 + gc->write_reg(reg, data); 71 66 } 72 67 73 68 static int apm_gpio_sb_to_irq(struct gpio_chip *gc, u32 gpio) 74 69 { 75 - struct xgene_gpio_sb *priv = to_xgene_gpio_sb(gc); 70 + struct xgene_gpio_sb *priv = gpiochip_get_data(gc); 76 71 77 72 if (priv->irq[gpio]) 78 73 return priv->irq[gpio]; ··· 90 99 if (IS_ERR(regs)) 91 100 return PTR_ERR(regs); 92 101 93 - ret = bgpio_init(&priv->bgc, &pdev->dev, 4, 102 + ret = bgpio_init(&priv->gc, &pdev->dev, 4, 94 103 regs + MPA_GPIO_IN_ADDR, 95 104 regs + MPA_GPIO_OUT_ADDR, NULL, 96 105 regs + MPA_GPIO_OE_ADDR, NULL, 0); 97 106 if (ret) 98 107 return ret; 99 108 100 - priv->bgc.gc.to_irq = apm_gpio_sb_to_irq; 101 - priv->bgc.gc.ngpio = XGENE_MAX_GPIO_DS; 109 + priv->gc.to_irq = apm_gpio_sb_to_irq; 110 + priv->gc.ngpio = XGENE_MAX_GPIO_DS; 102 111 103 112 priv->nirq = XGENE_MAX_GPIO_DS_IRQ; 104 113 ··· 109 118 110 119 for (i = 0; i < priv->nirq; i++) { 111 120 priv->irq[default_lines[i]] = platform_get_irq(pdev, i); 112 - xgene_gpio_set_bit(&priv->bgc, regs + MPA_GPIO_SEL_LO, 121 + xgene_gpio_set_bit(&priv->gc, regs + MPA_GPIO_SEL_LO, 113 122 default_lines[i] * 2, 1); 114 - xgene_gpio_set_bit(&priv->bgc, regs + MPA_GPIO_INT_LVL, i, 1); 123 + xgene_gpio_set_bit(&priv->gc, regs + MPA_GPIO_INT_LVL, i, 1); 115 124 } 116 125 117 126 platform_set_drvdata(pdev, priv); 118 127 119 - ret = gpiochip_add(&priv->bgc.gc); 128 + ret = gpiochip_add_data(&priv->gc, priv); 120 129 if (ret) 121 130 dev_err(&pdev->dev, "failed to register X-Gene GPIO Standby driver\n"); 122 131 else ··· 124 133 125 134 if (priv->nirq > 0) { 126 135 /* Register interrupt handlers for gpio signaled acpi events */ 127 - acpi_gpiochip_request_interrupts(&priv->bgc.gc); 136 + acpi_gpiochip_request_interrupts(&priv->gc); 128 137 } 129 138 130 139 return ret; ··· 135 144 struct xgene_gpio_sb *priv = platform_get_drvdata(pdev); 136 145 137 146 if (priv->nirq > 0) { 138 - acpi_gpiochip_free_interrupts(&priv->bgc.gc); 147 + acpi_gpiochip_free_interrupts(&priv->gc); 139 148 } 140 149 141 - return bgpio_remove(&priv->bgc); 150 + gpiochip_remove(&priv->gc); 151 + return 0; 142 152 } 143 153 144 154 static const struct of_device_id xgene_gpio_sb_of_match[] = {
+4 -4
drivers/mfd/vexpress-sysreg.c
··· 11 11 * Copyright (C) 2012 ARM Limited 12 12 */ 13 13 14 - #include <linux/basic_mmio_gpio.h> 14 + #include <linux/gpio/driver.h> 15 15 #include <linux/err.h> 16 16 #include <linux/io.h> 17 17 #include <linux/mfd/core.h> ··· 164 164 { 165 165 struct resource *mem; 166 166 void __iomem *base; 167 - struct bgpio_chip *mmc_gpio_chip; 167 + struct gpio_chip *mmc_gpio_chip; 168 168 int master; 169 169 u32 dt_hbi; 170 170 ··· 201 201 return -ENOMEM; 202 202 bgpio_init(mmc_gpio_chip, &pdev->dev, 0x4, base + SYS_MCI, 203 203 NULL, NULL, NULL, NULL, 0); 204 - mmc_gpio_chip->gc.ngpio = 2; 205 - gpiochip_add(&mmc_gpio_chip->gc); 204 + mmc_gpio_chip->ngpio = 2; 205 + gpiochip_add(mmc_gpio_chip); 206 206 207 207 return mfd_add_devices(&pdev->dev, PLATFORM_DEVID_AUTO, 208 208 vexpress_sysreg_cells,
-80
include/linux/basic_mmio_gpio.h
··· 1 - /* 2 - * Basic memory-mapped GPIO controllers. 3 - * 4 - * Copyright 2008 MontaVista Software, Inc. 5 - * Copyright 2008,2010 Anton Vorontsov <cbouatmailru@gmail.com> 6 - * 7 - * This program is free software; you can redistribute it and/or modify it 8 - * under the terms of the GNU General Public License as published by the 9 - * Free Software Foundation; either version 2 of the License, or (at your 10 - * option) any later version. 11 - */ 12 - 13 - #ifndef __BASIC_MMIO_GPIO_H 14 - #define __BASIC_MMIO_GPIO_H 15 - 16 - #include <linux/gpio.h> 17 - #include <linux/types.h> 18 - #include <linux/compiler.h> 19 - #include <linux/spinlock_types.h> 20 - 21 - struct bgpio_pdata { 22 - const char *label; 23 - int base; 24 - int ngpio; 25 - }; 26 - 27 - struct device; 28 - 29 - struct bgpio_chip { 30 - struct gpio_chip gc; 31 - 32 - unsigned long (*read_reg)(void __iomem *reg); 33 - void (*write_reg)(void __iomem *reg, unsigned long data); 34 - 35 - void __iomem *reg_dat; 36 - void __iomem *reg_set; 37 - void __iomem *reg_clr; 38 - void __iomem *reg_dir; 39 - 40 - /* Number of bits (GPIOs): <register width> * 8. */ 41 - int bits; 42 - 43 - /* 44 - * Some GPIO controllers work with the big-endian bits notation, 45 - * e.g. in a 8-bits register, GPIO7 is the least significant bit. 46 - */ 47 - unsigned long (*pin2mask)(struct bgpio_chip *bgc, unsigned int pin); 48 - 49 - /* 50 - * Used to lock bgpio_chip->data. Also, this is needed to keep 51 - * shadowed and real data registers writes together. 52 - */ 53 - spinlock_t lock; 54 - 55 - /* Shadowed data register to clear/set bits safely. */ 56 - unsigned long data; 57 - 58 - /* Shadowed direction registers to clear/set direction safely. */ 59 - unsigned long dir; 60 - }; 61 - 62 - static inline struct bgpio_chip *to_bgpio_chip(struct gpio_chip *gc) 63 - { 64 - return container_of(gc, struct bgpio_chip, gc); 65 - } 66 - 67 - int bgpio_remove(struct bgpio_chip *bgc); 68 - int bgpio_init(struct bgpio_chip *bgc, struct device *dev, 69 - unsigned long sz, void __iomem *dat, void __iomem *set, 70 - void __iomem *clr, void __iomem *dirout, void __iomem *dirin, 71 - unsigned long flags); 72 - 73 - #define BGPIOF_BIG_ENDIAN BIT(0) 74 - #define BGPIOF_UNREADABLE_REG_SET BIT(1) /* reg_set is unreadable */ 75 - #define BGPIOF_UNREADABLE_REG_DIR BIT(2) /* reg_dir is unreadable */ 76 - #define BGPIOF_BIG_ENDIAN_BYTE_ORDER BIT(3) 77 - #define BGPIOF_READ_OUTPUT_REG_SET BIT(4) /* reg_set stores output value */ 78 - #define BGPIOF_NO_OUTPUT BIT(5) /* only input */ 79 - 80 - #endif /* __BASIC_MMIO_GPIO_H */
+54
include/linux/gpio/driver.h
··· 8 8 #include <linux/irqdomain.h> 9 9 #include <linux/lockdep.h> 10 10 #include <linux/pinctrl/pinctrl.h> 11 + #include <linux/kconfig.h> 11 12 12 13 struct device; 13 14 struct gpio_desc; ··· 66 65 * registers. 67 66 * @irq_not_threaded: flag must be set if @can_sleep is set but the 68 67 * IRQs don't need to be threaded 68 + * @read_reg: reader function for generic GPIO 69 + * @write_reg: writer function for generic GPIO 70 + * @pin2mask: some generic GPIO controllers work with the big-endian bits 71 + * notation, e.g. in a 8-bits register, GPIO7 is the least significant 72 + * bit. This callback assigns the right bit mask. 73 + * @reg_dat: data (in) register for generic GPIO 74 + * @reg_set: output set register (out=high) for generic GPIO 75 + * @reg_clk: output clear register (out=low) for generic GPIO 76 + * @reg_dir: direction setting register for generic GPIO 77 + * @bgpio_bits: number of register bits used for a generic GPIO i.e. 78 + * <register width> * 8 79 + * @bgpio_lock: used to lock chip->bgpio_data. Also, this is needed to keep 80 + * shadowed and real data registers writes together. 81 + * @bgpio_data: shadowed data register for generic GPIO to clear/set bits 82 + * safely. 83 + * @bgpio_dir: shadowed direction register for generic GPIO to clear/set 84 + * direction safely. 69 85 * @irqchip: GPIO IRQ chip impl, provided by GPIO driver 70 86 * @irqdomain: Interrupt translation domain; responsible for mapping 71 87 * between GPIO hwirq number and linux irq number ··· 146 128 bool can_sleep; 147 129 bool irq_not_threaded; 148 130 131 + #if IS_ENABLED(CONFIG_GPIO_GENERIC) 132 + unsigned long (*read_reg)(void __iomem *reg); 133 + void (*write_reg)(void __iomem *reg, unsigned long data); 134 + unsigned long (*pin2mask)(struct gpio_chip *gc, unsigned int pin); 135 + void __iomem *reg_dat; 136 + void __iomem *reg_set; 137 + void __iomem *reg_clr; 138 + void __iomem *reg_dir; 139 + int bgpio_bits; 140 + spinlock_t bgpio_lock; 141 + unsigned long bgpio_data; 142 + unsigned long bgpio_dir; 143 + #endif 144 + 149 145 #ifdef CONFIG_GPIOLIB_IRQCHIP 150 146 /* 151 147 * With CONFIG_GPIOLIB_IRQCHIP we get an irqchip inside the gpiolib ··· 219 187 } 220 188 221 189 struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc); 190 + 191 + #if IS_ENABLED(CONFIG_GPIO_GENERIC) 192 + 193 + struct bgpio_pdata { 194 + const char *label; 195 + int base; 196 + int ngpio; 197 + }; 198 + 199 + int bgpio_init(struct gpio_chip *gc, struct device *dev, 200 + unsigned long sz, void __iomem *dat, void __iomem *set, 201 + void __iomem *clr, void __iomem *dirout, void __iomem *dirin, 202 + unsigned long flags); 203 + 204 + #define BGPIOF_BIG_ENDIAN BIT(0) 205 + #define BGPIOF_UNREADABLE_REG_SET BIT(1) /* reg_set is unreadable */ 206 + #define BGPIOF_UNREADABLE_REG_DIR BIT(2) /* reg_dir is unreadable */ 207 + #define BGPIOF_BIG_ENDIAN_BYTE_ORDER BIT(3) 208 + #define BGPIOF_READ_OUTPUT_REG_SET BIT(4) /* reg_set stores output value */ 209 + #define BGPIOF_NO_OUTPUT BIT(5) /* only input */ 210 + 211 + #endif 222 212 223 213 #ifdef CONFIG_GPIOLIB_IRQCHIP 224 214