Lines Matching +full:irq +full:- +full:can +full:- +full:wake
1 // SPDX-License-Identifier: GPL-2.0-only
2 // Copyright (C) 2015-2017 Broadcom
60 #define GPIO_BIT(gpio) ((gpio) & (MAX_GPIO_PER_BANK - 1))
66 return bank->parent_priv; in brcmstb_gpio_gc_to_priv()
72 void __iomem *reg_base = bank->parent_priv->reg_base; in __brcmstb_gpio_get_active_irqs()
74 return bank->gc.read_reg(reg_base + GIO_STAT(bank->id)) & in __brcmstb_gpio_get_active_irqs()
75 bank->gc.read_reg(reg_base + GIO_MASK(bank->id)); in __brcmstb_gpio_get_active_irqs()
84 raw_spin_lock_irqsave(&bank->gc.bgpio_lock, flags); in brcmstb_gpio_get_active_irqs()
86 raw_spin_unlock_irqrestore(&bank->gc.bgpio_lock, flags); in brcmstb_gpio_get_active_irqs()
94 return hwirq - bank->gc.offset; in brcmstb_gpio_hwirq_to_offset()
100 struct gpio_chip *gc = &bank->gc; in brcmstb_gpio_set_imask()
101 struct brcmstb_gpio_priv *priv = bank->parent_priv; in brcmstb_gpio_set_imask()
106 raw_spin_lock_irqsave(&gc->bgpio_lock, flags); in brcmstb_gpio_set_imask()
107 imask = gc->read_reg(priv->reg_base + GIO_MASK(bank->id)); in brcmstb_gpio_set_imask()
112 gc->write_reg(priv->reg_base + GIO_MASK(bank->id), imask); in brcmstb_gpio_set_imask()
113 raw_spin_unlock_irqrestore(&gc->bgpio_lock, flags); in brcmstb_gpio_set_imask()
120 int hwirq = offset + gc->offset; in brcmstb_gpio_to_irq()
122 if (hwirq >= priv->num_gpios) in brcmstb_gpio_to_irq()
123 return -ENXIO; in brcmstb_gpio_to_irq()
124 return irq_create_mapping(priv->irq_domain, hwirq); in brcmstb_gpio_to_irq()
127 /* -------------------- IRQ chip functions -------------------- */
134 brcmstb_gpio_set_imask(bank, d->hwirq, false); in brcmstb_gpio_irq_mask()
142 brcmstb_gpio_set_imask(bank, d->hwirq, true); in brcmstb_gpio_irq_unmask()
149 struct brcmstb_gpio_priv *priv = bank->parent_priv; in brcmstb_gpio_irq_ack()
150 u32 mask = BIT(brcmstb_gpio_hwirq_to_offset(d->hwirq, bank)); in brcmstb_gpio_irq_ack()
152 gc->write_reg(priv->reg_base + GIO_STAT(bank->id), mask); in brcmstb_gpio_irq_ack()
159 struct brcmstb_gpio_priv *priv = bank->parent_priv; in brcmstb_gpio_irq_set_type()
160 u32 mask = BIT(brcmstb_gpio_hwirq_to_offset(d->hwirq, bank)); in brcmstb_gpio_irq_set_type()
193 return -EINVAL; in brcmstb_gpio_irq_set_type()
196 raw_spin_lock_irqsave(&bank->gc.bgpio_lock, flags); in brcmstb_gpio_irq_set_type()
198 iedge_config = bank->gc.read_reg(priv->reg_base + in brcmstb_gpio_irq_set_type()
199 GIO_EC(bank->id)) & ~mask; in brcmstb_gpio_irq_set_type()
200 iedge_insensitive = bank->gc.read_reg(priv->reg_base + in brcmstb_gpio_irq_set_type()
201 GIO_EI(bank->id)) & ~mask; in brcmstb_gpio_irq_set_type()
202 ilevel = bank->gc.read_reg(priv->reg_base + in brcmstb_gpio_irq_set_type()
203 GIO_LEVEL(bank->id)) & ~mask; in brcmstb_gpio_irq_set_type()
205 bank->gc.write_reg(priv->reg_base + GIO_EC(bank->id), in brcmstb_gpio_irq_set_type()
207 bank->gc.write_reg(priv->reg_base + GIO_EI(bank->id), in brcmstb_gpio_irq_set_type()
209 bank->gc.write_reg(priv->reg_base + GIO_LEVEL(bank->id), in brcmstb_gpio_irq_set_type()
212 raw_spin_unlock_irqrestore(&bank->gc.bgpio_lock, flags); in brcmstb_gpio_irq_set_type()
222 ret = enable_irq_wake(priv->parent_wake_irq); in brcmstb_gpio_priv_set_wake()
224 ret = disable_irq_wake(priv->parent_wake_irq); in brcmstb_gpio_priv_set_wake()
226 dev_err(&priv->pdev->dev, "failed to %s wake-up interrupt\n", in brcmstb_gpio_priv_set_wake()
235 struct brcmstb_gpio_priv *priv = bank->parent_priv; in brcmstb_gpio_irq_set_wake()
236 u32 mask = BIT(brcmstb_gpio_hwirq_to_offset(d->hwirq, bank)); in brcmstb_gpio_irq_set_wake()
243 bank->wake_active |= mask; in brcmstb_gpio_irq_set_wake()
245 bank->wake_active &= ~mask; in brcmstb_gpio_irq_set_wake()
250 static irqreturn_t brcmstb_gpio_wake_irq_handler(int irq, void *data) in brcmstb_gpio_wake_irq_handler() argument
254 if (!priv || irq != priv->parent_wake_irq) in brcmstb_gpio_wake_irq_handler()
263 struct brcmstb_gpio_priv *priv = bank->parent_priv; in brcmstb_gpio_irq_bank_handler()
264 struct irq_domain *domain = priv->irq_domain; in brcmstb_gpio_irq_bank_handler()
265 int hwbase = bank->gc.offset; in brcmstb_gpio_irq_bank_handler()
272 if (offset >= bank->width) in brcmstb_gpio_irq_bank_handler()
273 dev_warn(&priv->pdev->dev, in brcmstb_gpio_irq_bank_handler()
274 "IRQ for invalid GPIO (bank=%d, offset=%d)\n", in brcmstb_gpio_irq_bank_handler()
275 bank->id, offset); in brcmstb_gpio_irq_bank_handler()
281 /* Each UPG GIO block has one IRQ for all banks */
292 list_for_each_entry(bank, &priv->bank_list, node) in brcmstb_gpio_irq_handler()
304 list_for_each_entry_reverse(bank, &priv->bank_list, node) { in brcmstb_gpio_hwirq_to_bank()
305 i += bank->gc.ngpio; in brcmstb_gpio_hwirq_to_bank()
320 static int brcmstb_gpio_irq_map(struct irq_domain *d, unsigned int irq, in brcmstb_gpio_irq_map() argument
323 struct brcmstb_gpio_priv *priv = d->host_data; in brcmstb_gpio_irq_map()
326 struct platform_device *pdev = priv->pdev; in brcmstb_gpio_irq_map()
330 return -EINVAL; in brcmstb_gpio_irq_map()
332 dev_dbg(&pdev->dev, "Mapping irq %d for gpio line %d (bank %d)\n", in brcmstb_gpio_irq_map()
333 irq, (int)hwirq, bank->id); in brcmstb_gpio_irq_map()
334 ret = irq_set_chip_data(irq, &bank->gc); in brcmstb_gpio_irq_map()
337 irq_set_lockdep_class(irq, &brcmstb_gpio_irq_lock_class, in brcmstb_gpio_irq_map()
339 irq_set_chip_and_handler(irq, &priv->irq_chip, handle_level_irq); in brcmstb_gpio_irq_map()
340 irq_set_noprobe(irq); in brcmstb_gpio_irq_map()
344 static void brcmstb_gpio_irq_unmap(struct irq_domain *d, unsigned int irq) in brcmstb_gpio_irq_unmap() argument
346 irq_set_chip_and_handler(irq, NULL, NULL); in brcmstb_gpio_irq_unmap()
347 irq_set_chip_data(irq, NULL); in brcmstb_gpio_irq_unmap()
362 of_property_count_u32_elems(np, "brcm,gpio-bank-widths"); in brcmstb_gpio_sanity_check_banks()
365 dev_err(dev, "Mismatch in banks: res had %d, bank-widths had %d\n", in brcmstb_gpio_sanity_check_banks()
367 return -EINVAL; in brcmstb_gpio_sanity_check_banks()
379 if (priv->parent_irq > 0) in brcmstb_gpio_remove()
380 irq_set_chained_handler_and_data(priv->parent_irq, NULL, NULL); in brcmstb_gpio_remove()
382 /* Remove all IRQ mappings and delete the domain */ in brcmstb_gpio_remove()
383 if (priv->irq_domain) { in brcmstb_gpio_remove()
384 for (offset = 0; offset < priv->num_gpios; offset++) { in brcmstb_gpio_remove()
385 virq = irq_find_mapping(priv->irq_domain, offset); in brcmstb_gpio_remove()
388 irq_domain_remove(priv->irq_domain); in brcmstb_gpio_remove()
392 * You can lose return values below, but we report all errors, and it's in brcmstb_gpio_remove()
395 list_for_each_entry(bank, &priv->bank_list, node) in brcmstb_gpio_remove()
396 gpiochip_remove(&bank->gc); in brcmstb_gpio_remove()
406 if (gc->of_gpio_n_cells != 2) { in brcmstb_gpio_of_xlate()
408 return -EINVAL; in brcmstb_gpio_of_xlate()
411 if (WARN_ON(gpiospec->args_count < gc->of_gpio_n_cells)) in brcmstb_gpio_of_xlate()
412 return -EINVAL; in brcmstb_gpio_of_xlate()
414 offset = gpiospec->args[0] - bank->gc.offset; in brcmstb_gpio_of_xlate()
415 if (offset >= gc->ngpio || offset < 0) in brcmstb_gpio_of_xlate()
416 return -EINVAL; in brcmstb_gpio_of_xlate()
418 if (unlikely(offset >= bank->width)) { in brcmstb_gpio_of_xlate()
419 dev_warn_ratelimited(&priv->pdev->dev, in brcmstb_gpio_of_xlate()
421 gpiospec->args[0]); in brcmstb_gpio_of_xlate()
425 *flags = gpiospec->args[1]; in brcmstb_gpio_of_xlate()
430 /* priv->parent_irq and priv->num_gpios must be set before calling */
434 struct device *dev = &pdev->dev; in brcmstb_gpio_irq_setup()
435 struct device_node *np = dev->of_node; in brcmstb_gpio_irq_setup()
438 priv->irq_domain = in brcmstb_gpio_irq_setup()
439 irq_domain_add_linear(np, priv->num_gpios, in brcmstb_gpio_irq_setup()
442 if (!priv->irq_domain) { in brcmstb_gpio_irq_setup()
443 dev_err(dev, "Couldn't allocate IRQ domain\n"); in brcmstb_gpio_irq_setup()
444 return -ENXIO; in brcmstb_gpio_irq_setup()
447 if (of_property_read_bool(np, "wakeup-source")) { in brcmstb_gpio_irq_setup()
448 priv->parent_wake_irq = platform_get_irq(pdev, 1); in brcmstb_gpio_irq_setup()
449 if (priv->parent_wake_irq < 0) { in brcmstb_gpio_irq_setup()
450 priv->parent_wake_irq = 0; in brcmstb_gpio_irq_setup()
452 "Couldn't get wake IRQ - GPIOs will not be able to wake from sleep"); in brcmstb_gpio_irq_setup()
455 * Set wakeup capability so we can process boot-time in brcmstb_gpio_irq_setup()
460 err = devm_request_irq(dev, priv->parent_wake_irq, in brcmstb_gpio_irq_setup()
463 "brcmstb-gpio-wake", priv); in brcmstb_gpio_irq_setup()
466 dev_err(dev, "Couldn't request wake IRQ"); in brcmstb_gpio_irq_setup()
472 priv->irq_chip.name = dev_name(dev); in brcmstb_gpio_irq_setup()
473 priv->irq_chip.irq_disable = brcmstb_gpio_irq_mask; in brcmstb_gpio_irq_setup()
474 priv->irq_chip.irq_mask = brcmstb_gpio_irq_mask; in brcmstb_gpio_irq_setup()
475 priv->irq_chip.irq_unmask = brcmstb_gpio_irq_unmask; in brcmstb_gpio_irq_setup()
476 priv->irq_chip.irq_ack = brcmstb_gpio_irq_ack; in brcmstb_gpio_irq_setup()
477 priv->irq_chip.irq_set_type = brcmstb_gpio_irq_set_type; in brcmstb_gpio_irq_setup()
479 if (priv->parent_wake_irq) in brcmstb_gpio_irq_setup()
480 priv->irq_chip.irq_set_wake = brcmstb_gpio_irq_set_wake; in brcmstb_gpio_irq_setup()
482 irq_set_chained_handler_and_data(priv->parent_irq, in brcmstb_gpio_irq_setup()
484 irq_set_status_flags(priv->parent_irq, IRQ_DISABLE_UNLAZY); in brcmstb_gpio_irq_setup()
489 irq_domain_remove(priv->irq_domain); in brcmstb_gpio_irq_setup()
497 struct gpio_chip *gc = &bank->gc; in brcmstb_gpio_bank_save()
501 bank->saved_regs[i] = gc->read_reg(priv->reg_base + in brcmstb_gpio_bank_save()
502 GIO_BANK_OFF(bank->id, i)); in brcmstb_gpio_bank_save()
512 /* disable non-wake interrupt */ in brcmstb_gpio_quiesce()
513 if (priv->parent_irq >= 0) in brcmstb_gpio_quiesce()
514 disable_irq(priv->parent_irq); in brcmstb_gpio_quiesce()
516 list_for_each_entry(bank, &priv->bank_list, node) { in brcmstb_gpio_quiesce()
517 gc = &bank->gc; in brcmstb_gpio_quiesce()
522 /* Unmask GPIOs which have been flagged as wake-up sources */ in brcmstb_gpio_quiesce()
523 if (priv->parent_wake_irq) in brcmstb_gpio_quiesce()
524 imask = bank->wake_active; in brcmstb_gpio_quiesce()
527 gc->write_reg(priv->reg_base + GIO_MASK(bank->id), in brcmstb_gpio_quiesce()
535 brcmstb_gpio_quiesce(&pdev->dev, false); in brcmstb_gpio_shutdown()
542 struct gpio_chip *gc = &bank->gc; in brcmstb_gpio_bank_restore()
546 gc->write_reg(priv->reg_base + GIO_BANK_OFF(bank->id, i), in brcmstb_gpio_bank_restore()
547 bank->saved_regs[i]); in brcmstb_gpio_bank_restore()
562 list_for_each_entry(bank, &priv->bank_list, node) { in brcmstb_gpio_resume()
567 if (priv->parent_wake_irq && need_wakeup_event) in brcmstb_gpio_resume()
570 /* enable non-wake interrupt */ in brcmstb_gpio_resume()
571 if (priv->parent_irq >= 0) in brcmstb_gpio_resume()
572 enable_irq(priv->parent_irq); in brcmstb_gpio_resume()
589 struct device *dev = &pdev->dev; in brcmstb_gpio_probe()
590 struct device_node *np = dev->of_node; in brcmstb_gpio_probe()
603 return -ENOMEM; in brcmstb_gpio_probe()
605 INIT_LIST_HEAD(&priv->bank_list); in brcmstb_gpio_probe()
611 priv->reg_base = reg_base; in brcmstb_gpio_probe()
612 priv->pdev = pdev; in brcmstb_gpio_probe()
614 if (of_property_read_bool(np, "interrupt-controller")) { in brcmstb_gpio_probe()
615 priv->parent_irq = platform_get_irq(pdev, 0); in brcmstb_gpio_probe()
616 if (priv->parent_irq <= 0) in brcmstb_gpio_probe()
617 return -ENOENT; in brcmstb_gpio_probe()
619 priv->parent_irq = -ENOENT; in brcmstb_gpio_probe()
623 return -EINVAL; in brcmstb_gpio_probe()
627 * bus endianness (i.e., big-endian CPU + big endian bus ==> native in brcmstb_gpio_probe()
637 of_property_for_each_u32(np, "brcm,gpio-bank-widths", bank_width) { in brcmstb_gpio_probe()
655 err = -ENOMEM; in brcmstb_gpio_probe()
659 bank->parent_priv = priv; in brcmstb_gpio_probe()
660 bank->id = num_banks; in brcmstb_gpio_probe()
663 err = -EINVAL; in brcmstb_gpio_probe()
666 bank->width = bank_width; in brcmstb_gpio_probe()
673 gc = &bank->gc; in brcmstb_gpio_probe()
675 reg_base + GIO_DATA(bank->id), in brcmstb_gpio_probe()
677 reg_base + GIO_IODIR(bank->id), flags); in brcmstb_gpio_probe()
683 gc->owner = THIS_MODULE; in brcmstb_gpio_probe()
684 gc->label = devm_kasprintf(dev, GFP_KERNEL, "%pOF", np); in brcmstb_gpio_probe()
685 if (!gc->label) { in brcmstb_gpio_probe()
686 err = -ENOMEM; in brcmstb_gpio_probe()
689 gc->of_gpio_n_cells = 2; in brcmstb_gpio_probe()
690 gc->of_xlate = brcmstb_gpio_of_xlate; in brcmstb_gpio_probe()
692 gc->ngpio = MAX_GPIO_PER_BANK; in brcmstb_gpio_probe()
693 gc->offset = bank->id * MAX_GPIO_PER_BANK; in brcmstb_gpio_probe()
694 gc->request = gpiochip_generic_request; in brcmstb_gpio_probe()
695 gc->free = gpiochip_generic_free; in brcmstb_gpio_probe()
696 if (priv->parent_irq > 0) in brcmstb_gpio_probe()
697 gc->to_irq = brcmstb_gpio_to_irq; in brcmstb_gpio_probe()
704 gc->write_reg(reg_base + GIO_MASK(bank->id), 0); in brcmstb_gpio_probe()
709 bank->id); in brcmstb_gpio_probe()
712 num_gpios += gc->ngpio; in brcmstb_gpio_probe()
714 dev_dbg(dev, "bank=%d, base=%d, ngpio=%d, width=%d\n", bank->id, in brcmstb_gpio_probe()
715 gc->base, gc->ngpio, bank->width); in brcmstb_gpio_probe()
718 list_add(&bank->node, &priv->bank_list); in brcmstb_gpio_probe()
723 priv->num_gpios = num_gpios; in brcmstb_gpio_probe()
724 if (priv->parent_irq > 0) { in brcmstb_gpio_probe()
730 if (priv->parent_wake_irq && need_wakeup_event) in brcmstb_gpio_probe()
741 { .compatible = "brcm,brcmstb-gpio" },
749 .name = "brcmstb-gpio",