static int clps711x_gpio_probe(struct platform_device *pdev) { struct device_node *np = pdev->dev.of_node; void __iomem *dat, *dir; struct gpio_chip *gc; struct resource *res; int err, id; if (!np) return -ENODEV; id = of_alias_get_id(np, "gpio"); if ((id < 0) || (id > 4)) return -ENODEV; gc = devm_kzalloc(&pdev->dev, sizeof(*gc), GFP_KERNEL); if (!gc) return -ENOMEM; res = platform_get_resource(pdev, IORESOURCE_MEM, 0); dat = devm_ioremap_resource(&pdev->dev, res); if (IS_ERR(dat)) return PTR_ERR(dat); res = platform_get_resource(pdev, IORESOURCE_MEM, 1); dir = devm_ioremap_resource(&pdev->dev, res); if (IS_ERR(dir)) return PTR_ERR(dir); switch (id) { case 3: /* PORTD is inverted logic for direction register */ err = bgpio_init(gc, &pdev->dev, 1, dat, NULL, NULL, NULL, dir, 0); break; default: err = bgpio_init(gc, &pdev->dev, 1, dat, NULL, NULL, dir, NULL, 0); break; } if (err) return err; switch (id) { case 4: /* PORTE is 3 lines only */ gc->ngpio = 3; break; default: break; } gc->base = -1; gc->owner = THIS_MODULE; platform_set_drvdata(pdev, gc); return devm_gpiochip_add_data(&pdev->dev, gc, NULL); }
static int bgpio_dev_probe(struct device_d *dev) { struct resource *r; void __iomem *dat; void __iomem *set; void __iomem *clr; void __iomem *dirout; void __iomem *dirin; unsigned int sz; unsigned long flags = 0; int err; struct bgpio_chip *bgc; struct bgpio_pdata *pdata = dev->platform_data; r = dev_get_resource_by_name(dev, IORESOURCE_MEM, "dat"); if (IS_ERR(r)) return PTR_ERR(r); sz = resource_size(r); dat = bgpio_map(dev, "dat", sz, &err); if (!dat) return err ? err : -EINVAL; set = bgpio_map(dev, "set", sz, &err); if (err) return err; clr = bgpio_map(dev, "clr", sz, &err); if (err) return err; dirout = bgpio_map(dev, "dirout", sz, &err); if (err) return err; dirin = bgpio_map(dev, "dirin", sz, &err); if (err) return err; dev_get_drvdata(dev, (const void **)&flags); bgc = xzalloc(sizeof(struct bgpio_chip)); err = bgpio_init(bgc, dev, sz, dat, set, clr, dirout, dirin, flags); if (err) return err; if (pdata) { bgc->gc.base = pdata->base; if (pdata->ngpio > 0) bgc->gc.ngpio = pdata->ngpio; } dev->priv = bgc; return gpiochip_add(&bgc->gc); }
static int clps711x_gpio_probe(struct device_d *dev) { struct resource *iores; int err, id = dev->id; void __iomem *dat, *dir = NULL, *dir_inv = NULL; struct bgpio_chip *bgc; if (dev->device_node) id = of_alias_get_id(dev->device_node, "gpio"); if (id < 0 || id > 4) return -ENODEV; iores = dev_request_mem_resource(dev, 0); if (IS_ERR(iores)) return PTR_ERR(iores); dat = IOMEM(iores->start); switch (id) { case 3: iores = dev_request_mem_resource(dev, 1); if (IS_ERR(iores)) return PTR_ERR(iores); dir_inv = IOMEM(iores->start); break; default: iores = dev_request_mem_resource(dev, 1); if (IS_ERR(iores)) return PTR_ERR(iores); dir = IOMEM(iores->start); break; } bgc = xzalloc(sizeof(struct bgpio_chip)); err = bgpio_init(bgc, dev, 1, dat, NULL, NULL, dir, dir_inv, 0); if (err) goto out_err; bgc->gc.base = id * 8; switch (id) { case 4: bgc->gc.ngpio = 3; break; default: break; } err = gpiochip_add(&bgc->gc); out_err: if (err) free(bgc); return err; }
static int bgpio_pdev_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct resource *r; void __iomem *dat; void __iomem *set; void __iomem *clr; void __iomem *dirout; void __iomem *dirin; unsigned long sz; unsigned long flags = pdev->id_entry->driver_data; int err; struct bgpio_chip *bgc; struct bgpio_pdata *pdata = dev_get_platdata(dev); r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dat"); if (!r) return -EINVAL; sz = resource_size(r); dat = bgpio_map(pdev, "dat", sz); if (IS_ERR(dat)) return PTR_ERR(dat); set = bgpio_map(pdev, "set", sz); if (IS_ERR(set)) return PTR_ERR(set); clr = bgpio_map(pdev, "clr", sz); if (IS_ERR(clr)) return PTR_ERR(clr); dirout = bgpio_map(pdev, "dirout", sz); if (IS_ERR(dirout)) return PTR_ERR(dirout); dirin = bgpio_map(pdev, "dirin", sz); if (IS_ERR(dirin)) return PTR_ERR(dirin); bgc = devm_kzalloc(&pdev->dev, sizeof(*bgc), GFP_KERNEL); if (!bgc) return -ENOMEM; err = bgpio_init(bgc, dev, sz, dat, set, clr, dirout, dirin, flags); if (err) return err; if (pdata) { if (pdata->label) bgc->gc.label = pdata->label; bgc->gc.base = pdata->base;
static int __init gef_gpio_probe(struct platform_device *pdev) { const struct of_device_id *of_id = of_match_device(gef_gpio_ids, &pdev->dev); struct gpio_chip *gc; void __iomem *regs; int ret; gc = devm_kzalloc(&pdev->dev, sizeof(*gc), GFP_KERNEL); if (!gc) return -ENOMEM; regs = of_iomap(pdev->dev.of_node, 0); if (!regs) return -ENOMEM; ret = bgpio_init(gc, &pdev->dev, 4, regs + GEF_GPIO_IN, regs + GEF_GPIO_OUT, NULL, NULL, regs + GEF_GPIO_DIRECT, BGPIOF_BIG_ENDIAN_BYTE_ORDER); if (ret) { dev_err(&pdev->dev, "bgpio_init failed\n"); goto err0; } /* Setup pointers to chip functions */ gc->label = devm_kstrdup(&pdev->dev, pdev->dev.of_node->full_name, GFP_KERNEL); if (!gc->label) { ret = -ENOMEM; goto err0; } gc->base = -1; gc->ngpio = (u16)(uintptr_t)of_id->data; gc->of_gpio_n_cells = 2; gc->of_node = pdev->dev.of_node; /* This function adds a memory mapped GPIO chip */ ret = devm_gpiochip_add_data(&pdev->dev, gc, NULL); if (ret) goto err0; return 0; err0: iounmap(regs); pr_err("%s: GPIO chip registration failed\n", pdev->dev.of_node->full_name); return ret; };
static int moxart_gpio_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct resource *res; struct bgpio_chip *bgc; void __iomem *base; int ret; bgc = devm_kzalloc(dev, sizeof(*bgc), GFP_KERNEL); if (!bgc) return -ENOMEM; res = platform_get_resource(pdev, IORESOURCE_MEM, 0); base = devm_ioremap_resource(dev, res); if (IS_ERR(base)) return PTR_ERR(base); ret = bgpio_init(bgc, dev, 4, base + GPIO_DATA_IN, base + GPIO_DATA_OUT, NULL, base + GPIO_PIN_DIRECTION, NULL, BGPIOF_READ_OUTPUT_REG_SET); if (ret) { dev_err(&pdev->dev, "bgpio_init failed\n"); return ret; } bgc->gc.label = "moxart-gpio"; bgc->gc.request = moxart_gpio_request; bgc->gc.free = moxart_gpio_free; bgc->data = bgc->read_reg(bgc->reg_set); bgc->gc.base = 0; bgc->gc.ngpio = 32; bgc->gc.dev = dev; bgc->gc.owner = THIS_MODULE; ret = gpiochip_add(&bgc->gc); if (ret) { dev_err(dev, "%s: gpiochip_add failed\n", dev->of_node->full_name); return ret; } return ret; }
static int ep93xx_gpio_add_bank(struct bgpio_chip *bgc, struct device *dev, void __iomem *mmio_base, struct ep93xx_gpio_bank *bank) { void __iomem *data = mmio_base + bank->data; void __iomem *dir = mmio_base + bank->dir; int err; err = bgpio_init(bgc, dev, 1, data, NULL, NULL, dir, NULL, 0); if (err) return err; bgc->gc.label = bank->label; bgc->gc.base = bank->base; if (bank->has_debounce) { bgc->gc.set_debounce = ep93xx_gpio_set_debounce; bgc->gc.to_irq = ep93xx_gpio_to_irq; } return gpiochip_add(&bgc->gc); }
static int mlxbf_gpio_probe(struct platform_device *pdev) { struct mlxbf_gpio_state *gs; struct device *dev = &pdev->dev; struct gpio_chip *gc; int ret; gs = devm_kzalloc(&pdev->dev, sizeof(*gs), GFP_KERNEL); if (!gs) return -ENOMEM; gs->base = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(gs->base)) return PTR_ERR(gs->base); gc = &gs->gc; ret = bgpio_init(gc, dev, 8, gs->base + MLXBF_GPIO_PIN_STATE, NULL, NULL, gs->base + MLXBF_GPIO_PIN_DIR_O, gs->base + MLXBF_GPIO_PIN_DIR_I, 0); if (ret) return -ENODEV; gc->owner = THIS_MODULE; gc->ngpio = MLXBF_GPIO_NR; ret = devm_gpiochip_add_data(dev, &gs->gc, gs); if (ret) { dev_err(&pdev->dev, "Failed adding memory mapped gpiochip\n"); return ret; } platform_set_drvdata(pdev, gs); dev_info(&pdev->dev, "registered Mellanox BlueField GPIO"); return 0; }
static int __devinit bgpio_pdev_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct resource *r; void __iomem *dat; void __iomem *set; void __iomem *clr; void __iomem *dirout; void __iomem *dirin; unsigned long sz; bool be; int err; struct bgpio_chip *bgc; struct bgpio_pdata *pdata = dev_get_platdata(dev); r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dat"); if (!r) return -EINVAL; sz = resource_size(r); dat = bgpio_map(pdev, "dat", sz, &err); if (!dat) return err ? err : -EINVAL; set = bgpio_map(pdev, "set", sz, &err); if (err) return err; clr = bgpio_map(pdev, "clr", sz, &err); if (err) return err; dirout = bgpio_map(pdev, "dirout", sz, &err); if (err) return err; dirin = bgpio_map(pdev, "dirin", sz, &err); if (err) return err; be = !strcmp(platform_get_device_id(pdev)->name, "basic-mmio-gpio-be"); bgc = devm_kzalloc(&pdev->dev, sizeof(*bgc), GFP_KERNEL); if (!bgc) return -ENOMEM; err = bgpio_init(bgc, dev, sz, dat, set, clr, dirout, dirin, be); if (err) return err; if (pdata) { bgc->gc.base = pdata->base; if (pdata->ngpio > 0) bgc->gc.ngpio = pdata->ngpio; } platform_set_drvdata(pdev, bgc); return gpiochip_add(&bgc->gc); }
static int pt_gpio_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct acpi_device *acpi_dev; acpi_handle handle = ACPI_HANDLE(dev); struct pt_gpio_chip *pt_gpio; struct resource *res_mem; int ret = 0; if (acpi_bus_get_device(handle, &acpi_dev)) { dev_err(dev, "PT GPIO device node not found\n"); return -ENODEV; } pt_gpio = devm_kzalloc(dev, sizeof(struct pt_gpio_chip), GFP_KERNEL); if (!pt_gpio) return -ENOMEM; res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!res_mem) { dev_err(&pdev->dev, "Failed to get MMIO resource for PT GPIO.\n"); return -EINVAL; } pt_gpio->reg_base = devm_ioremap_resource(dev, res_mem); if (IS_ERR(pt_gpio->reg_base)) { dev_err(&pdev->dev, "Failed to map MMIO resource for PT GPIO.\n"); return PTR_ERR(pt_gpio->reg_base); } ret = bgpio_init(&pt_gpio->gc, dev, 4, pt_gpio->reg_base + PT_INPUTDATA_REG, pt_gpio->reg_base + PT_OUTPUTDATA_REG, NULL, pt_gpio->reg_base + PT_DIRECTION_REG, NULL, BGPIOF_READ_OUTPUT_REG_SET); if (ret) { dev_err(&pdev->dev, "bgpio_init failed\n"); return ret; } pt_gpio->gc.owner = THIS_MODULE; pt_gpio->gc.request = pt_gpio_request; pt_gpio->gc.free = pt_gpio_free; pt_gpio->gc.ngpio = PT_TOTAL_GPIO; #if defined(CONFIG_OF_GPIO) pt_gpio->gc.of_node = pdev->dev.of_node; #endif ret = gpiochip_add_data(&pt_gpio->gc, pt_gpio); if (ret) { dev_err(&pdev->dev, "Failed to register GPIO lib\n"); return ret; } platform_set_drvdata(pdev, pt_gpio); /* initialize register setting */ writel(0, pt_gpio->reg_base + PT_SYNC_REG); writel(0, pt_gpio->reg_base + PT_CLOCKRATE_REG); dev_dbg(&pdev->dev, "PT GPIO driver loaded\n"); return ret; }
static int xgene_gpio_sb_probe(struct platform_device *pdev) { struct xgene_gpio_sb *priv; int ret; struct resource *res; void __iomem *regs; struct irq_domain *parent_domain = NULL; struct fwnode_handle *fwnode; u32 val32; priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); if (!priv) return -ENOMEM; res = platform_get_resource(pdev, IORESOURCE_MEM, 0); regs = devm_ioremap_resource(&pdev->dev, res); if (IS_ERR(regs)) return PTR_ERR(regs); priv->regs = regs; ret = platform_get_irq(pdev, 0); if (ret > 0) { priv->parent_irq_base = irq_get_irq_data(ret)->hwirq; parent_domain = irq_get_irq_data(ret)->domain; } if (!parent_domain) { dev_err(&pdev->dev, "unable to obtain parent domain\n"); return -ENODEV; } ret = bgpio_init(&priv->gc, &pdev->dev, 4, regs + MPA_GPIO_IN_ADDR, regs + MPA_GPIO_OUT_ADDR, NULL, regs + MPA_GPIO_OE_ADDR, NULL, 0); if (ret) return ret; priv->gc.to_irq = xgene_gpio_sb_to_irq; /* Retrieve start irq pin, use default if property not found */ priv->irq_start = XGENE_DFLT_IRQ_START_PIN; if (!device_property_read_u32(&pdev->dev, XGENE_IRQ_START_PROPERTY, &val32)) priv->irq_start = val32; /* Retrieve number irqs, use default if property not found */ priv->nirq = XGENE_DFLT_MAX_NIRQ; if (!device_property_read_u32(&pdev->dev, XGENE_NIRQ_PROPERTY, &val32)) priv->nirq = val32; /* Retrieve number gpio, use default if property not found */ priv->gc.ngpio = XGENE_DFLT_MAX_NGPIO; if (!device_property_read_u32(&pdev->dev, XGENE_NGPIO_PROPERTY, &val32)) priv->gc.ngpio = val32; dev_info(&pdev->dev, "Support %d gpios, %d irqs start from pin %d\n", priv->gc.ngpio, priv->nirq, priv->irq_start); platform_set_drvdata(pdev, priv); if (pdev->dev.of_node) fwnode = of_node_to_fwnode(pdev->dev.of_node); else fwnode = pdev->dev.fwnode; priv->irq_domain = irq_domain_create_hierarchy(parent_domain, 0, priv->nirq, fwnode, &xgene_gpio_sb_domain_ops, priv); if (!priv->irq_domain) return -ENODEV; priv->gc.irqdomain = priv->irq_domain; ret = devm_gpiochip_add_data(&pdev->dev, &priv->gc, priv); if (ret) { dev_err(&pdev->dev, "failed to register X-Gene GPIO Standby driver\n"); irq_domain_remove(priv->irq_domain); return ret; } dev_info(&pdev->dev, "X-Gene GPIO Standby driver registered\n"); if (priv->nirq > 0) { /* Register interrupt handlers for gpio signaled acpi events */ acpi_gpiochip_request_interrupts(&priv->gc); } return ret; }
static int ftgpio_gpio_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct resource *res; struct ftgpio_gpio *g; int irq; int ret; g = devm_kzalloc(dev, sizeof(*g), GFP_KERNEL); if (!g) return -ENOMEM; g->dev = dev; res = platform_get_resource(pdev, IORESOURCE_MEM, 0); g->base = devm_ioremap_resource(dev, res); if (IS_ERR(g->base)) return PTR_ERR(g->base); irq = platform_get_irq(pdev, 0); if (irq <= 0) return irq ? irq : -EINVAL; ret = bgpio_init(&g->gc, dev, 4, g->base + GPIO_DATA_IN, g->base + GPIO_DATA_SET, g->base + GPIO_DATA_CLR, g->base + GPIO_DIR, NULL, 0); if (ret) { dev_err(dev, "unable to init generic GPIO\n"); return ret; } g->gc.label = "FTGPIO010"; g->gc.base = -1; g->gc.parent = dev; g->gc.owner = THIS_MODULE; /* ngpio is set by bgpio_init() */ ret = devm_gpiochip_add_data(dev, &g->gc, g); if (ret) return ret; /* Disable, unmask and clear all interrupts */ writel(0x0, g->base + GPIO_INT_EN); writel(0x0, g->base + GPIO_INT_MASK); writel(~0x0, g->base + GPIO_INT_CLR); ret = gpiochip_irqchip_add(&g->gc, &ftgpio_gpio_irqchip, 0, handle_bad_irq, IRQ_TYPE_NONE); if (ret) { dev_info(dev, "could not add irqchip\n"); return ret; } gpiochip_set_chained_irqchip(&g->gc, &ftgpio_gpio_irqchip, irq, ftgpio_gpio_irq_handler); dev_info(dev, "FTGPIO010 @%p registered\n", g->base); return 0; }
static int bgpio_pdev_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct resource *r; void __iomem *dat; void __iomem *set; void __iomem *clr; void __iomem *dirout; void __iomem *dirin; unsigned long sz; unsigned long flags = 0; int err; struct gpio_chip *gc; struct bgpio_pdata *pdata; pdata = bgpio_parse_dt(pdev, &flags); if (IS_ERR(pdata)) return PTR_ERR(pdata); if (!pdata) { pdata = dev_get_platdata(dev); flags = pdev->id_entry->driver_data; } r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dat"); if (!r) return -EINVAL; sz = resource_size(r); dat = bgpio_map(pdev, "dat", sz); if (IS_ERR(dat)) return PTR_ERR(dat); set = bgpio_map(pdev, "set", sz); if (IS_ERR(set)) return PTR_ERR(set); clr = bgpio_map(pdev, "clr", sz); if (IS_ERR(clr)) return PTR_ERR(clr); dirout = bgpio_map(pdev, "dirout", sz); if (IS_ERR(dirout)) return PTR_ERR(dirout); dirin = bgpio_map(pdev, "dirin", sz); if (IS_ERR(dirin)) return PTR_ERR(dirin); gc = devm_kzalloc(&pdev->dev, sizeof(*gc), GFP_KERNEL); if (!gc) return -ENOMEM; err = bgpio_init(gc, dev, sz, dat, set, clr, dirout, dirin, flags); if (err) return err; if (pdata) { if (pdata->label) gc->label = pdata->label; gc->base = pdata->base; if (pdata->ngpio > 0) gc->ngpio = pdata->ngpio; } platform_set_drvdata(pdev, gc); return devm_gpiochip_add_data(&pdev->dev, gc, NULL); }