1a912e80bSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later 244e08e70SPaul Burton /* 344e08e70SPaul Burton * Copyright (C) 2009-2010, Lars-Peter Clausen <lars@metafoo.de> 444e08e70SPaul Burton * JZ4740 platform IRQ support 544e08e70SPaul Burton */ 644e08e70SPaul Burton 744e08e70SPaul Burton #include <linux/errno.h> 844e08e70SPaul Burton #include <linux/init.h> 944e08e70SPaul Burton #include <linux/types.h> 1044e08e70SPaul Burton #include <linux/interrupt.h> 1144e08e70SPaul Burton #include <linux/ioport.h> 1241a83e06SJoel Porquet #include <linux/irqchip.h> 1344e08e70SPaul Burton #include <linux/of_address.h> 1444e08e70SPaul Burton #include <linux/of_irq.h> 1544e08e70SPaul Burton #include <linux/timex.h> 1644e08e70SPaul Burton #include <linux/slab.h> 1744e08e70SPaul Burton #include <linux/delay.h> 1844e08e70SPaul Burton 1944e08e70SPaul Burton #include <asm/io.h> 2044e08e70SPaul Burton #include <asm/mach-jz4740/irq.h> 2144e08e70SPaul Burton 2244e08e70SPaul Burton struct ingenic_intc_data { 2344e08e70SPaul Burton void __iomem *base; 2444e08e70SPaul Burton unsigned num_chips; 2544e08e70SPaul Burton }; 2644e08e70SPaul Burton 2744e08e70SPaul Burton #define JZ_REG_INTC_STATUS 0x00 2844e08e70SPaul Burton #define JZ_REG_INTC_MASK 0x04 2944e08e70SPaul Burton #define JZ_REG_INTC_SET_MASK 0x08 3044e08e70SPaul Burton #define JZ_REG_INTC_CLEAR_MASK 0x0c 3144e08e70SPaul Burton #define JZ_REG_INTC_PENDING 0x10 3244e08e70SPaul Burton #define CHIP_SIZE 0x20 3344e08e70SPaul Burton 3444e08e70SPaul Burton static irqreturn_t intc_cascade(int irq, void *data) 3544e08e70SPaul Burton { 3644e08e70SPaul Burton struct ingenic_intc_data *intc = irq_get_handler_data(irq); 3744e08e70SPaul Burton uint32_t irq_reg; 3844e08e70SPaul Burton unsigned i; 3944e08e70SPaul Burton 4044e08e70SPaul Burton for (i = 0; i < intc->num_chips; i++) { 4144e08e70SPaul Burton irq_reg = readl(intc->base + (i * CHIP_SIZE) + 4244e08e70SPaul Burton JZ_REG_INTC_PENDING); 4344e08e70SPaul Burton if (!irq_reg) 4444e08e70SPaul Burton continue; 4544e08e70SPaul Burton 4644e08e70SPaul Burton generic_handle_irq(__fls(irq_reg) + (i * 32) + JZ4740_IRQ_BASE); 4744e08e70SPaul Burton } 4844e08e70SPaul Burton 4944e08e70SPaul Burton return IRQ_HANDLED; 5044e08e70SPaul Burton } 5144e08e70SPaul Burton 5244e08e70SPaul Burton static struct irqaction intc_cascade_action = { 5344e08e70SPaul Burton .handler = intc_cascade, 5444e08e70SPaul Burton .name = "SoC intc cascade interrupt", 5544e08e70SPaul Burton }; 5644e08e70SPaul Burton 5744e08e70SPaul Burton static int __init ingenic_intc_of_init(struct device_node *node, 5844e08e70SPaul Burton unsigned num_chips) 5944e08e70SPaul Burton { 6044e08e70SPaul Burton struct ingenic_intc_data *intc; 6144e08e70SPaul Burton struct irq_chip_generic *gc; 6244e08e70SPaul Burton struct irq_chip_type *ct; 6344e08e70SPaul Burton struct irq_domain *domain; 6444e08e70SPaul Burton int parent_irq, err = 0; 6544e08e70SPaul Burton unsigned i; 6644e08e70SPaul Burton 6744e08e70SPaul Burton intc = kzalloc(sizeof(*intc), GFP_KERNEL); 6844e08e70SPaul Burton if (!intc) { 6944e08e70SPaul Burton err = -ENOMEM; 7044e08e70SPaul Burton goto out_err; 7144e08e70SPaul Burton } 7244e08e70SPaul Burton 7344e08e70SPaul Burton parent_irq = irq_of_parse_and_map(node, 0); 7444e08e70SPaul Burton if (!parent_irq) { 7544e08e70SPaul Burton err = -EINVAL; 7644e08e70SPaul Burton goto out_free; 7744e08e70SPaul Burton } 7844e08e70SPaul Burton 7944e08e70SPaul Burton err = irq_set_handler_data(parent_irq, intc); 8044e08e70SPaul Burton if (err) 8144e08e70SPaul Burton goto out_unmap_irq; 8244e08e70SPaul Burton 8344e08e70SPaul Burton intc->num_chips = num_chips; 8444e08e70SPaul Burton intc->base = of_iomap(node, 0); 8544e08e70SPaul Burton if (!intc->base) { 8644e08e70SPaul Burton err = -ENODEV; 8744e08e70SPaul Burton goto out_unmap_irq; 8844e08e70SPaul Burton } 8944e08e70SPaul Burton 9044e08e70SPaul Burton for (i = 0; i < num_chips; i++) { 9144e08e70SPaul Burton /* Mask all irqs */ 9244e08e70SPaul Burton writel(0xffffffff, intc->base + (i * CHIP_SIZE) + 9344e08e70SPaul Burton JZ_REG_INTC_SET_MASK); 9444e08e70SPaul Burton 9544e08e70SPaul Burton gc = irq_alloc_generic_chip("INTC", 1, 9644e08e70SPaul Burton JZ4740_IRQ_BASE + (i * 32), 9744e08e70SPaul Burton intc->base + (i * CHIP_SIZE), 9844e08e70SPaul Burton handle_level_irq); 9944e08e70SPaul Burton 10044e08e70SPaul Burton gc->wake_enabled = IRQ_MSK(32); 10144e08e70SPaul Burton 10244e08e70SPaul Burton ct = gc->chip_types; 10344e08e70SPaul Burton ct->regs.enable = JZ_REG_INTC_CLEAR_MASK; 10444e08e70SPaul Burton ct->regs.disable = JZ_REG_INTC_SET_MASK; 10544e08e70SPaul Burton ct->chip.irq_unmask = irq_gc_unmask_enable_reg; 10644e08e70SPaul Burton ct->chip.irq_mask = irq_gc_mask_disable_reg; 10744e08e70SPaul Burton ct->chip.irq_mask_ack = irq_gc_mask_disable_reg; 10844e08e70SPaul Burton ct->chip.irq_set_wake = irq_gc_set_wake; 109*20b44b4dSPaul Cercueil ct->chip.flags = IRQCHIP_MASK_ON_SUSPEND; 11044e08e70SPaul Burton 11144e08e70SPaul Burton irq_setup_generic_chip(gc, IRQ_MSK(32), 0, 0, 11244e08e70SPaul Burton IRQ_NOPROBE | IRQ_LEVEL); 11344e08e70SPaul Burton } 11444e08e70SPaul Burton 11544e08e70SPaul Burton domain = irq_domain_add_legacy(node, num_chips * 32, JZ4740_IRQ_BASE, 0, 11644e08e70SPaul Burton &irq_domain_simple_ops, NULL); 11744e08e70SPaul Burton if (!domain) 11844e08e70SPaul Burton pr_warn("unable to register IRQ domain\n"); 11944e08e70SPaul Burton 12044e08e70SPaul Burton setup_irq(parent_irq, &intc_cascade_action); 12144e08e70SPaul Burton return 0; 12244e08e70SPaul Burton 12344e08e70SPaul Burton out_unmap_irq: 12444e08e70SPaul Burton irq_dispose_mapping(parent_irq); 12544e08e70SPaul Burton out_free: 12644e08e70SPaul Burton kfree(intc); 12744e08e70SPaul Burton out_err: 12844e08e70SPaul Burton return err; 12944e08e70SPaul Burton } 13044e08e70SPaul Burton 13144e08e70SPaul Burton static int __init intc_1chip_of_init(struct device_node *node, 13244e08e70SPaul Burton struct device_node *parent) 13344e08e70SPaul Burton { 13444e08e70SPaul Burton return ingenic_intc_of_init(node, 1); 13544e08e70SPaul Burton } 13644e08e70SPaul Burton IRQCHIP_DECLARE(jz4740_intc, "ingenic,jz4740-intc", intc_1chip_of_init); 1371047557cSPaul Cercueil IRQCHIP_DECLARE(jz4725b_intc, "ingenic,jz4725b-intc", intc_1chip_of_init); 13844e08e70SPaul Burton 13944e08e70SPaul Burton static int __init intc_2chip_of_init(struct device_node *node, 14044e08e70SPaul Burton struct device_node *parent) 14144e08e70SPaul Burton { 14244e08e70SPaul Burton return ingenic_intc_of_init(node, 2); 14344e08e70SPaul Burton } 14444e08e70SPaul Burton IRQCHIP_DECLARE(jz4770_intc, "ingenic,jz4770-intc", intc_2chip_of_init); 14544e08e70SPaul Burton IRQCHIP_DECLARE(jz4775_intc, "ingenic,jz4775-intc", intc_2chip_of_init); 14644e08e70SPaul Burton IRQCHIP_DECLARE(jz4780_intc, "ingenic,jz4780-intc", intc_2chip_of_init); 147