Lines Matching +full:irq +full:- +full:gpios
1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Copyright (c) 2006-2007 David Brownell
15 #include <linux/irq.h>
42 typedef struct irq_chip *(*gpio_get_irq_chip_cb_t)(unsigned int irq);
44 #define BINTEN 0x8 /* GPIO Interrupt Per-Bank Enable Register */
83 /*--------------------------------------------------------------------------*/
96 g = d->regs[bank]; in __davinci_direction()
97 spin_lock_irqsave(&d->lock, flags); in __davinci_direction()
98 temp = readl_relaxed(&g->dir); in __davinci_direction()
101 writel_relaxed(mask, value ? &g->set_data : &g->clr_data); in __davinci_direction()
105 writel_relaxed(temp, &g->dir); in __davinci_direction()
106 spin_unlock_irqrestore(&d->lock, flags); in __davinci_direction()
135 g = d->regs[bank]; in davinci_gpio_get()
137 return !!(__gpio_mask(offset) & readl_relaxed(&g->in_data)); in davinci_gpio_get()
150 g = d->regs[bank]; in davinci_gpio_set()
153 value ? &g->set_data : &g->clr_data); in davinci_gpio_set()
161 struct device *dev = &pdev->dev; in davinci_gpio_probe()
166 * and "ngpio" is one more than the largest zero-based in davinci_gpio_probe()
171 return dev_err_probe(dev, ret, "Failed to get the number of GPIOs\n"); in davinci_gpio_probe()
173 return dev_err_probe(dev, -EINVAL, "How many GPIOs?\n"); in davinci_gpio_probe()
177 * interrupts is equal to number of gpios else all are banked so in davinci_gpio_probe()
178 * number of interrupts is equal to number of banks(each with 16 gpios) in davinci_gpio_probe()
180 ret = of_property_read_u32(dn, "ti,davinci-gpio-unbanked", in davinci_gpio_probe()
183 return dev_err_probe(dev, ret, "Failed to get the unbanked GPIOs property\n"); in davinci_gpio_probe()
192 return -EINVAL; in davinci_gpio_probe()
197 return -ENOMEM; in davinci_gpio_probe()
204 chips->irqs[i] = platform_get_irq(pdev, i); in davinci_gpio_probe()
205 if (chips->irqs[i] < 0) in davinci_gpio_probe()
206 return chips->irqs[i]; in davinci_gpio_probe()
209 chips->chip.label = dev_name(dev); in davinci_gpio_probe()
211 chips->chip.direction_input = davinci_direction_in; in davinci_gpio_probe()
212 chips->chip.get = davinci_gpio_get; in davinci_gpio_probe()
213 chips->chip.direction_output = davinci_direction_out; in davinci_gpio_probe()
214 chips->chip.set = davinci_gpio_set; in davinci_gpio_probe()
216 chips->chip.ngpio = ngpio; in davinci_gpio_probe()
217 chips->chip.base = -1; in davinci_gpio_probe()
220 chips->chip.parent = dev; in davinci_gpio_probe()
221 chips->chip.request = gpiochip_generic_request; in davinci_gpio_probe()
222 chips->chip.free = gpiochip_generic_free; in davinci_gpio_probe()
224 spin_lock_init(&chips->lock); in davinci_gpio_probe()
226 chips->gpio_unbanked = gpio_unbanked; in davinci_gpio_probe()
230 chips->regs[bank] = gpio_base + offset_array[bank]; in davinci_gpio_probe()
232 ret = devm_gpiochip_add_data(dev, &chips->chip, chips); in davinci_gpio_probe()
244 /*--------------------------------------------------------------------------*/
249 * NOTE: The first few GPIOs also have direct INTC hookups in addition
250 * to their GPIOBNK0 irq, with a bit less overhead.
252 * All those INTC hookups (direct, plus several IRQ banks) can also
261 writel_relaxed(mask, &g->clr_falling); in gpio_irq_mask()
262 writel_relaxed(mask, &g->clr_rising); in gpio_irq_mask()
276 writel_relaxed(mask, &g->set_falling); in gpio_irq_unmask()
278 writel_relaxed(mask, &g->set_rising); in gpio_irq_unmask()
284 return -EINVAL; in gpio_irq_type()
306 bank_num = irqdata->bank_num; in gpio_irq_handler()
307 g = irqdata->regs; in gpio_irq_handler()
308 d = irqdata->chip; in gpio_irq_handler()
314 /* temporarily mask (level sensitive) parent IRQ */ in gpio_irq_handler()
322 status = readl_relaxed(&g->intstat) & mask; in gpio_irq_handler()
325 writel_relaxed(status, &g->intstat); in gpio_irq_handler()
332 /* Max number of gpios per controller is 144 so in gpio_irq_handler()
337 generic_handle_domain_irq(d->irq_domain, hw_irq); in gpio_irq_handler()
341 /* now it may re-trigger */ in gpio_irq_handler()
348 if (d->irq_domain) in gpio_to_irq_banked()
349 return irq_create_mapping(d->irq_domain, offset); in gpio_to_irq_banked()
351 return -ENXIO; in gpio_to_irq_banked()
360 * can provide direct-mapped IRQs to AINTC (up to 32 GPIOs). in gpio_to_irq_unbanked()
362 if (offset < d->gpio_unbanked) in gpio_to_irq_unbanked()
363 return d->irqs[offset]; in gpio_to_irq_unbanked()
365 return -ENODEV; in gpio_to_irq_unbanked()
375 g = (struct davinci_gpio_regs __iomem *)d->regs[0]; in gpio_irq_type_unbanked()
377 if (data->irq == d->irqs[i]) in gpio_irq_type_unbanked()
381 return -EINVAL; in gpio_irq_type_unbanked()
386 return -EINVAL; in gpio_irq_type_unbanked()
389 ? &g->set_falling : &g->clr_falling); in gpio_irq_type_unbanked()
391 ? &g->set_rising : &g->clr_rising); in gpio_irq_type_unbanked()
397 davinci_gpio_irq_map(struct irq_domain *d, unsigned int irq, in davinci_gpio_irq_map() argument
401 (struct davinci_gpio_controller *)d->host_data; in davinci_gpio_irq_map()
402 struct davinci_gpio_regs __iomem *g = chips->regs[hw / 32]; in davinci_gpio_irq_map()
404 irq_set_chip_and_handler_name(irq, &gpio_irqchip, handle_simple_irq, in davinci_gpio_irq_map()
406 irq_set_irq_type(irq, IRQ_TYPE_NONE); in davinci_gpio_irq_map()
407 irq_set_chip_data(irq, (__force void *)g); in davinci_gpio_irq_map()
408 irq_set_handler_data(irq, (void *)(uintptr_t)__gpio_mask(hw)); in davinci_gpio_irq_map()
418 static struct irq_chip *davinci_gpio_get_irq_chip(unsigned int irq) in davinci_gpio_get_irq_chip() argument
422 gpio_unbanked = *irq_data_get_chip_type(irq_get_irq_data(irq)); in davinci_gpio_get_irq_chip()
427 static struct irq_chip *keystone_gpio_get_irq_chip(unsigned int irq) in keystone_gpio_get_irq_chip() argument
431 gpio_unbanked = *irq_get_chip(irq); in keystone_gpio_get_irq_chip()
440 * calls ... so if no gpios are wakeup events the clock can be disabled,
448 int irq; in davinci_gpio_irq_setup() local
452 struct device *dev = &pdev->dev; in davinci_gpio_irq_setup()
464 if (dev->of_node) in davinci_gpio_irq_setup()
467 ngpio = chips->chip.ngpio; in davinci_gpio_irq_setup()
475 if (!chips->gpio_unbanked) { in davinci_gpio_irq_setup()
476 irq = devm_irq_alloc_descs(dev, -1, 0, ngpio, 0); in davinci_gpio_irq_setup()
477 if (irq < 0) { in davinci_gpio_irq_setup()
478 dev_err(dev, "Couldn't allocate IRQ numbers\n"); in davinci_gpio_irq_setup()
479 return irq; in davinci_gpio_irq_setup()
482 irq_domain = irq_domain_add_legacy(dev->of_node, ngpio, irq, 0, in davinci_gpio_irq_setup()
486 dev_err(dev, "Couldn't register an IRQ domain\n"); in davinci_gpio_irq_setup()
487 return -ENODEV; in davinci_gpio_irq_setup()
493 * banked IRQs. Having GPIOs in the first GPIO bank use direct in davinci_gpio_irq_setup()
497 chips->chip.to_irq = gpio_to_irq_banked; in davinci_gpio_irq_setup()
498 chips->irq_domain = irq_domain; in davinci_gpio_irq_setup()
501 * AINTC can handle direct/unbanked IRQs for GPIOs, with the GPIO in davinci_gpio_irq_setup()
503 * IRQ mux conflicts; gpio_irq_type_unbanked() is only for GPIOs. in davinci_gpio_irq_setup()
505 if (chips->gpio_unbanked) { in davinci_gpio_irq_setup()
507 chips->chip.to_irq = gpio_to_irq_unbanked; in davinci_gpio_irq_setup()
509 binten = GENMASK(chips->gpio_unbanked / 16, 0); in davinci_gpio_irq_setup()
512 irq = chips->irqs[0]; in davinci_gpio_irq_setup()
513 irq_chip = gpio_get_irq_chip(irq); in davinci_gpio_irq_setup()
514 irq_chip->name = "GPIO-AINTC"; in davinci_gpio_irq_setup()
515 irq_chip->irq_set_type = gpio_irq_type_unbanked; in davinci_gpio_irq_setup()
518 g = chips->regs[0]; in davinci_gpio_irq_setup()
519 writel_relaxed(~0, &g->set_falling); in davinci_gpio_irq_setup()
520 writel_relaxed(~0, &g->set_rising); in davinci_gpio_irq_setup()
523 for (gpio = 0; gpio < chips->gpio_unbanked; gpio++) { in davinci_gpio_irq_setup()
524 irq_set_chip(chips->irqs[gpio], irq_chip); in davinci_gpio_irq_setup()
525 irq_set_handler_data(chips->irqs[gpio], chips); in davinci_gpio_irq_setup()
526 irq_set_status_flags(chips->irqs[gpio], in davinci_gpio_irq_setup()
539 * There are register sets for 32 GPIOs. 2 banks of 16 in davinci_gpio_irq_setup()
540 * GPIOs are covered by each set of registers hence divide by 2 in davinci_gpio_irq_setup()
542 g = chips->regs[bank / 2]; in davinci_gpio_irq_setup()
543 writel_relaxed(~0, &g->clr_falling); in davinci_gpio_irq_setup()
544 writel_relaxed(~0, &g->clr_rising); in davinci_gpio_irq_setup()
547 * Each chip handles 32 gpios, and each irq bank consists of 16 in davinci_gpio_irq_setup()
548 * gpio irqs. Pass the irq bank's corresponding controller to in davinci_gpio_irq_setup()
549 * the chained irq handler. in davinci_gpio_irq_setup()
551 irqdata = devm_kzalloc(&pdev->dev, in davinci_gpio_irq_setup()
556 return -ENOMEM; in davinci_gpio_irq_setup()
558 irqdata->regs = g; in davinci_gpio_irq_setup()
559 irqdata->bank_num = bank; in davinci_gpio_irq_setup()
560 irqdata->chip = chips; in davinci_gpio_irq_setup()
562 irq_set_chained_handler_and_data(chips->irqs[bank], in davinci_gpio_irq_setup()
570 * BINTEN -- per-bank interrupt enable. genirq would also let these in davinci_gpio_irq_setup()
586 base = chips->regs[0] - offset_array[0]; in davinci_gpio_save_context()
587 chips->binten_context = readl_relaxed(base + BINTEN); in davinci_gpio_save_context()
590 g = chips->regs[bank]; in davinci_gpio_save_context()
591 context = &chips->context[bank]; in davinci_gpio_save_context()
592 context->dir = readl_relaxed(&g->dir); in davinci_gpio_save_context()
593 context->set_data = readl_relaxed(&g->set_data); in davinci_gpio_save_context()
594 context->set_rising = readl_relaxed(&g->set_rising); in davinci_gpio_save_context()
595 context->set_falling = readl_relaxed(&g->set_falling); in davinci_gpio_save_context()
599 writel_relaxed(GENMASK(31, 0), &g->intstat); in davinci_gpio_save_context()
610 base = chips->regs[0] - offset_array[0]; in davinci_gpio_restore_context()
612 if (readl_relaxed(base + BINTEN) != chips->binten_context) in davinci_gpio_restore_context()
613 writel_relaxed(chips->binten_context, base + BINTEN); in davinci_gpio_restore_context()
616 g = chips->regs[bank]; in davinci_gpio_restore_context()
617 context = &chips->context[bank]; in davinci_gpio_restore_context()
618 if (readl_relaxed(&g->dir) != context->dir) in davinci_gpio_restore_context()
619 writel_relaxed(context->dir, &g->dir); in davinci_gpio_restore_context()
620 if (readl_relaxed(&g->set_data) != context->set_data) in davinci_gpio_restore_context()
621 writel_relaxed(context->set_data, &g->set_data); in davinci_gpio_restore_context()
622 if (readl_relaxed(&g->set_rising) != context->set_rising) in davinci_gpio_restore_context()
623 writel_relaxed(context->set_rising, &g->set_rising); in davinci_gpio_restore_context()
624 if (readl_relaxed(&g->set_falling) != context->set_falling) in davinci_gpio_restore_context()
625 writel_relaxed(context->set_falling, &g->set_falling); in davinci_gpio_restore_context()
632 u32 nbank = DIV_ROUND_UP(chips->chip.ngpio, 32); in davinci_gpio_suspend()
642 u32 nbank = DIV_ROUND_UP(chips->chip.ngpio, 32); in davinci_gpio_resume()
653 { .compatible = "ti,keystone-gpio", keystone_gpio_get_irq_chip},
654 { .compatible = "ti,am654-gpio", keystone_gpio_get_irq_chip},
655 { .compatible = "ti,dm6441-gpio", davinci_gpio_get_irq_chip},
688 MODULE_ALIAS("platform:gpio-davinci");