Lines Matching +full:tb10x +full:- +full:gpio

1 // SPDX-License-Identifier: GPL-2.0-only
13 #include <linux/gpio/driver.h>
37 * @domain: IRQ domain of GPIO generated interrupts managed by this controller
39 * @gc: gpio_chip structure associated to this GPIO controller
48 static inline u32 tb10x_reg_read(struct tb10x_gpio *gpio, unsigned int offs) in tb10x_reg_read() argument
50 return ioread32(gpio->base + offs); in tb10x_reg_read()
53 static inline void tb10x_reg_write(struct tb10x_gpio *gpio, unsigned int offs, in tb10x_reg_write() argument
56 iowrite32(val, gpio->base + offs); in tb10x_reg_write()
59 static inline void tb10x_set_bits(struct tb10x_gpio *gpio, unsigned int offs, in tb10x_set_bits() argument
65 raw_spin_lock_irqsave(&gpio->gc.bgpio_lock, flags); in tb10x_set_bits()
67 r = tb10x_reg_read(gpio, offs); in tb10x_set_bits()
70 tb10x_reg_write(gpio, offs, r); in tb10x_set_bits()
72 raw_spin_unlock_irqrestore(&gpio->gc.bgpio_lock, flags); in tb10x_set_bits()
79 return irq_create_mapping(tb10x_gpio->domain, offset); in tb10x_gpio_to_irq()
86 return -EINVAL; in tb10x_gpio_irq_set_type()
103 generic_handle_domain_irq(tb10x_gpio->domain, i); in tb10x_gpio_irq_cascade()
111 struct device *dev = &pdev->dev; in tb10x_gpio_probe()
112 struct device_node *np = dev->of_node; in tb10x_gpio_probe()
113 int ret = -EBUSY; in tb10x_gpio_probe()
117 return -EINVAL; in tb10x_gpio_probe()
120 return -EINVAL; in tb10x_gpio_probe()
124 return -ENOMEM; in tb10x_gpio_probe()
126 tb10x_gpio->base = devm_platform_ioremap_resource(pdev, 0); in tb10x_gpio_probe()
127 if (IS_ERR(tb10x_gpio->base)) in tb10x_gpio_probe()
128 return PTR_ERR(tb10x_gpio->base); in tb10x_gpio_probe()
130 tb10x_gpio->gc.label = in tb10x_gpio_probe()
131 devm_kasprintf(dev, GFP_KERNEL, "%pOF", pdev->dev.of_node); in tb10x_gpio_probe()
132 if (!tb10x_gpio->gc.label) in tb10x_gpio_probe()
133 return -ENOMEM; in tb10x_gpio_probe()
136 * Initialize generic GPIO with one single register for reading and setting in tb10x_gpio_probe()
140 ret = bgpio_init(&tb10x_gpio->gc, dev, 4, in tb10x_gpio_probe()
141 tb10x_gpio->base + OFFSET_TO_REG_DATA, in tb10x_gpio_probe()
144 tb10x_gpio->base + OFFSET_TO_REG_DDR, in tb10x_gpio_probe()
148 dev_err(dev, "unable to init generic GPIO\n"); in tb10x_gpio_probe()
151 tb10x_gpio->gc.base = -1; in tb10x_gpio_probe()
152 tb10x_gpio->gc.parent = dev; in tb10x_gpio_probe()
153 tb10x_gpio->gc.owner = THIS_MODULE; in tb10x_gpio_probe()
156 * callback also overrides the one set up by generic GPIO. in tb10x_gpio_probe()
158 tb10x_gpio->gc.ngpio = ngpio; in tb10x_gpio_probe()
159 tb10x_gpio->gc.request = gpiochip_generic_request; in tb10x_gpio_probe()
160 tb10x_gpio->gc.free = gpiochip_generic_free; in tb10x_gpio_probe()
162 ret = devm_gpiochip_add_data(dev, &tb10x_gpio->gc, tb10x_gpio); in tb10x_gpio_probe()
170 if (of_property_read_bool(np, "interrupt-controller")) { in tb10x_gpio_probe()
177 tb10x_gpio->gc.to_irq = tb10x_gpio_to_irq; in tb10x_gpio_probe()
178 tb10x_gpio->irq = ret; in tb10x_gpio_probe()
186 tb10x_gpio->domain = irq_domain_create_linear(dev_fwnode(dev), tb10x_gpio->gc.ngpio, in tb10x_gpio_probe()
188 if (!tb10x_gpio->domain) { in tb10x_gpio_probe()
189 return -ENOMEM; in tb10x_gpio_probe()
192 ret = irq_alloc_domain_generic_chips(tb10x_gpio->domain, in tb10x_gpio_probe()
193 tb10x_gpio->gc.ngpio, 1, tb10x_gpio->gc.label, in tb10x_gpio_probe()
199 gc = tb10x_gpio->domain->gc->gc[0]; in tb10x_gpio_probe()
200 gc->reg_base = tb10x_gpio->base; in tb10x_gpio_probe()
201 gc->chip_types[0].type = IRQ_TYPE_EDGE_BOTH; in tb10x_gpio_probe()
202 gc->chip_types[0].chip.irq_ack = irq_gc_ack_set_bit; in tb10x_gpio_probe()
203 gc->chip_types[0].chip.irq_mask = irq_gc_mask_clr_bit; in tb10x_gpio_probe()
204 gc->chip_types[0].chip.irq_unmask = irq_gc_mask_set_bit; in tb10x_gpio_probe()
205 gc->chip_types[0].chip.irq_set_type = tb10x_gpio_irq_set_type; in tb10x_gpio_probe()
206 gc->chip_types[0].regs.ack = OFFSET_TO_REG_CHANGE; in tb10x_gpio_probe()
207 gc->chip_types[0].regs.mask = OFFSET_TO_REG_INT_EN; in tb10x_gpio_probe()
213 irq_domain_remove(tb10x_gpio->domain); in tb10x_gpio_probe()
221 if (tb10x_gpio->gc.to_irq) { in tb10x_gpio_remove()
222 irq_remove_generic_chip(tb10x_gpio->domain->gc->gc[0], in tb10x_gpio_remove()
223 BIT(tb10x_gpio->gc.ngpio) - 1, 0, 0); in tb10x_gpio_remove()
224 kfree(tb10x_gpio->domain->gc); in tb10x_gpio_remove()
225 irq_domain_remove(tb10x_gpio->domain); in tb10x_gpio_remove()
230 { .compatible = "abilis,tb10x-gpio" },
239 .name = "tb10x-gpio",
246 MODULE_DESCRIPTION("tb10x gpio.");