Thomas Gleixner | a912e80 | 2019-05-27 08:55:00 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Lars-Peter Clausen | 9869848 | 2010-07-17 11:08:43 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2009-2010, Lars-Peter Clausen <lars@metafoo.de> |
Zhou Yanjie | b8b0145 | 2019-10-02 19:25:25 +0800 | [diff] [blame] | 4 | * Ingenic XBurst platform IRQ support |
Lars-Peter Clausen | 9869848 | 2010-07-17 11:08:43 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <linux/errno.h> |
| 8 | #include <linux/init.h> |
| 9 | #include <linux/types.h> |
| 10 | #include <linux/interrupt.h> |
| 11 | #include <linux/ioport.h> |
Joel Porquet | 41a83e06 | 2015-07-07 17:11:46 -0400 | [diff] [blame] | 12 | #include <linux/irqchip.h> |
Paul Burton | 3aa9459 | 2015-05-24 16:11:28 +0100 | [diff] [blame] | 13 | #include <linux/of_address.h> |
Paul Burton | adbdce7 | 2015-05-24 16:11:21 +0100 | [diff] [blame] | 14 | #include <linux/of_irq.h> |
Lars-Peter Clausen | 9869848 | 2010-07-17 11:08:43 +0000 | [diff] [blame] | 15 | #include <linux/timex.h> |
| 16 | #include <linux/slab.h> |
| 17 | #include <linux/delay.h> |
| 18 | |
Lars-Peter Clausen | 9869848 | 2010-07-17 11:08:43 +0000 | [diff] [blame] | 19 | #include <asm/io.h> |
Brian Norris | 942e22d | 2014-12-17 18:39:01 -0800 | [diff] [blame] | 20 | |
Paul Burton | fe778ec | 2015-05-24 16:11:25 +0100 | [diff] [blame] | 21 | struct ingenic_intc_data { |
| 22 | void __iomem *base; |
Paul Cercueil | 208caad | 2019-10-02 19:25:23 +0800 | [diff] [blame] | 23 | struct irq_domain *domain; |
Paul Burton | 943d69c | 2015-05-24 16:11:26 +0100 | [diff] [blame] | 24 | unsigned num_chips; |
Paul Burton | fe778ec | 2015-05-24 16:11:25 +0100 | [diff] [blame] | 25 | }; |
Lars-Peter Clausen | 9869848 | 2010-07-17 11:08:43 +0000 | [diff] [blame] | 26 | |
| 27 | #define JZ_REG_INTC_STATUS 0x00 |
| 28 | #define JZ_REG_INTC_MASK 0x04 |
| 29 | #define JZ_REG_INTC_SET_MASK 0x08 |
| 30 | #define JZ_REG_INTC_CLEAR_MASK 0x0c |
| 31 | #define JZ_REG_INTC_PENDING 0x10 |
Paul Burton | 943d69c | 2015-05-24 16:11:26 +0100 | [diff] [blame] | 32 | #define CHIP_SIZE 0x20 |
Lars-Peter Clausen | 9869848 | 2010-07-17 11:08:43 +0000 | [diff] [blame] | 33 | |
Paul Burton | 2da0188 | 2015-05-24 16:11:29 +0100 | [diff] [blame] | 34 | static irqreturn_t intc_cascade(int irq, void *data) |
Lars-Peter Clausen | 9869848 | 2010-07-17 11:08:43 +0000 | [diff] [blame] | 35 | { |
Paul Burton | fe778ec | 2015-05-24 16:11:25 +0100 | [diff] [blame] | 36 | struct ingenic_intc_data *intc = irq_get_handler_data(irq); |
Paul Cercueil | 208caad | 2019-10-02 19:25:23 +0800 | [diff] [blame] | 37 | struct irq_domain *domain = intc->domain; |
Paul Cercueil | 8bc7464 | 2019-10-02 19:25:24 +0800 | [diff] [blame] | 38 | struct irq_chip_generic *gc; |
Zhou Yanjie | b8b0145 | 2019-10-02 19:25:25 +0800 | [diff] [blame] | 39 | uint32_t pending; |
Paul Burton | 943d69c | 2015-05-24 16:11:26 +0100 | [diff] [blame] | 40 | unsigned i; |
Lars-Peter Clausen | 9869848 | 2010-07-17 11:08:43 +0000 | [diff] [blame] | 41 | |
Paul Burton | 943d69c | 2015-05-24 16:11:26 +0100 | [diff] [blame] | 42 | for (i = 0; i < intc->num_chips; i++) { |
Paul Cercueil | 8bc7464 | 2019-10-02 19:25:24 +0800 | [diff] [blame] | 43 | gc = irq_get_domain_generic_chip(domain, i * 32); |
| 44 | |
Zhou Yanjie | b8b0145 | 2019-10-02 19:25:25 +0800 | [diff] [blame] | 45 | pending = irq_reg_readl(gc, JZ_REG_INTC_PENDING); |
| 46 | if (!pending) |
Paul Burton | 943d69c | 2015-05-24 16:11:26 +0100 | [diff] [blame] | 47 | continue; |
Lars-Peter Clausen | 9869848 | 2010-07-17 11:08:43 +0000 | [diff] [blame] | 48 | |
Zhou Yanjie | b8b0145 | 2019-10-02 19:25:25 +0800 | [diff] [blame] | 49 | while (pending) { |
| 50 | int bit = __fls(pending); |
| 51 | |
Marc Zyngier | 046a6ee | 2021-05-04 17:42:18 +0100 | [diff] [blame] | 52 | generic_handle_domain_irq(domain, bit + (i * 32)); |
Zhou Yanjie | b8b0145 | 2019-10-02 19:25:25 +0800 | [diff] [blame] | 53 | pending &= ~BIT(bit); |
| 54 | } |
Paul Burton | 943d69c | 2015-05-24 16:11:26 +0100 | [diff] [blame] | 55 | } |
Lars-Peter Clausen | 9869848 | 2010-07-17 11:08:43 +0000 | [diff] [blame] | 56 | |
| 57 | return IRQ_HANDLED; |
| 58 | } |
| 59 | |
Paul Burton | 943d69c | 2015-05-24 16:11:26 +0100 | [diff] [blame] | 60 | static int __init ingenic_intc_of_init(struct device_node *node, |
| 61 | unsigned num_chips) |
Lars-Peter Clausen | 9869848 | 2010-07-17 11:08:43 +0000 | [diff] [blame] | 62 | { |
Paul Burton | fe778ec | 2015-05-24 16:11:25 +0100 | [diff] [blame] | 63 | struct ingenic_intc_data *intc; |
Lars-Peter Clausen | 83bc769 | 2011-09-24 02:29:46 +0200 | [diff] [blame] | 64 | struct irq_chip_generic *gc; |
| 65 | struct irq_chip_type *ct; |
Paul Burton | 638c885 | 2015-05-24 16:11:23 +0100 | [diff] [blame] | 66 | struct irq_domain *domain; |
Paul Burton | fe778ec | 2015-05-24 16:11:25 +0100 | [diff] [blame] | 67 | int parent_irq, err = 0; |
Paul Burton | 943d69c | 2015-05-24 16:11:26 +0100 | [diff] [blame] | 68 | unsigned i; |
Paul Burton | fe778ec | 2015-05-24 16:11:25 +0100 | [diff] [blame] | 69 | |
| 70 | intc = kzalloc(sizeof(*intc), GFP_KERNEL); |
| 71 | if (!intc) { |
| 72 | err = -ENOMEM; |
| 73 | goto out_err; |
| 74 | } |
Paul Burton | 69ce4b2 | 2015-05-24 16:11:22 +0100 | [diff] [blame] | 75 | |
| 76 | parent_irq = irq_of_parse_and_map(node, 0); |
Paul Burton | fe778ec | 2015-05-24 16:11:25 +0100 | [diff] [blame] | 77 | if (!parent_irq) { |
| 78 | err = -EINVAL; |
| 79 | goto out_free; |
| 80 | } |
Lars-Peter Clausen | 83bc769 | 2011-09-24 02:29:46 +0200 | [diff] [blame] | 81 | |
Paul Burton | fe778ec | 2015-05-24 16:11:25 +0100 | [diff] [blame] | 82 | err = irq_set_handler_data(parent_irq, intc); |
| 83 | if (err) |
| 84 | goto out_unmap_irq; |
| 85 | |
Paul Burton | 943d69c | 2015-05-24 16:11:26 +0100 | [diff] [blame] | 86 | intc->num_chips = num_chips; |
Paul Burton | 3aa9459 | 2015-05-24 16:11:28 +0100 | [diff] [blame] | 87 | intc->base = of_iomap(node, 0); |
| 88 | if (!intc->base) { |
| 89 | err = -ENODEV; |
| 90 | goto out_unmap_irq; |
| 91 | } |
Lars-Peter Clausen | 9869848 | 2010-07-17 11:08:43 +0000 | [diff] [blame] | 92 | |
Paul Cercueil | 1fd224e | 2020-01-13 13:33:29 -0300 | [diff] [blame] | 93 | domain = irq_domain_add_linear(node, num_chips * 32, |
Paul Cercueil | 8bc7464 | 2019-10-02 19:25:24 +0800 | [diff] [blame] | 94 | &irq_generic_chip_ops, NULL); |
Paul Cercueil | 52ecc87 | 2019-10-02 19:25:22 +0800 | [diff] [blame] | 95 | if (!domain) { |
| 96 | err = -ENOMEM; |
| 97 | goto out_unmap_base; |
| 98 | } |
| 99 | |
Paul Cercueil | 208caad | 2019-10-02 19:25:23 +0800 | [diff] [blame] | 100 | intc->domain = domain; |
| 101 | |
Paul Cercueil | 8bc7464 | 2019-10-02 19:25:24 +0800 | [diff] [blame] | 102 | err = irq_alloc_domain_generic_chips(domain, 32, 1, "INTC", |
| 103 | handle_level_irq, 0, |
| 104 | IRQ_NOPROBE | IRQ_LEVEL, 0); |
| 105 | if (err) |
| 106 | goto out_domain_remove; |
Thomas Gleixner | 42b64f3 | 2011-03-23 21:08:53 +0000 | [diff] [blame] | 107 | |
Paul Cercueil | 8bc7464 | 2019-10-02 19:25:24 +0800 | [diff] [blame] | 108 | for (i = 0; i < num_chips; i++) { |
| 109 | gc = irq_get_domain_generic_chip(domain, i * 32); |
Lars-Peter Clausen | 83bc769 | 2011-09-24 02:29:46 +0200 | [diff] [blame] | 110 | |
Paul Burton | 943d69c | 2015-05-24 16:11:26 +0100 | [diff] [blame] | 111 | gc->wake_enabled = IRQ_MSK(32); |
Paul Cercueil | 8bc7464 | 2019-10-02 19:25:24 +0800 | [diff] [blame] | 112 | gc->reg_base = intc->base + (i * CHIP_SIZE); |
Lars-Peter Clausen | 83bc769 | 2011-09-24 02:29:46 +0200 | [diff] [blame] | 113 | |
Paul Burton | 943d69c | 2015-05-24 16:11:26 +0100 | [diff] [blame] | 114 | ct = gc->chip_types; |
| 115 | ct->regs.enable = JZ_REG_INTC_CLEAR_MASK; |
| 116 | ct->regs.disable = JZ_REG_INTC_SET_MASK; |
| 117 | ct->chip.irq_unmask = irq_gc_unmask_enable_reg; |
| 118 | ct->chip.irq_mask = irq_gc_mask_disable_reg; |
| 119 | ct->chip.irq_mask_ack = irq_gc_mask_disable_reg; |
| 120 | ct->chip.irq_set_wake = irq_gc_set_wake; |
Paul Cercueil | 20b44b4 | 2019-10-02 19:25:21 +0800 | [diff] [blame] | 121 | ct->chip.flags = IRQCHIP_MASK_ON_SUSPEND; |
Lars-Peter Clausen | 83bc769 | 2011-09-24 02:29:46 +0200 | [diff] [blame] | 122 | |
Paul Cercueil | 8bc7464 | 2019-10-02 19:25:24 +0800 | [diff] [blame] | 123 | /* Mask all irqs */ |
| 124 | irq_reg_writel(gc, IRQ_MSK(32), JZ_REG_INTC_SET_MASK); |
Paul Burton | 943d69c | 2015-05-24 16:11:26 +0100 | [diff] [blame] | 125 | } |
Lars-Peter Clausen | 9869848 | 2010-07-17 11:08:43 +0000 | [diff] [blame] | 126 | |
Paul Cercueil | 821fc9e | 2020-08-19 20:06:02 +0200 | [diff] [blame] | 127 | if (request_irq(parent_irq, intc_cascade, IRQF_NO_SUSPEND, |
afzal mohammed | 2ef1cb7 | 2020-03-04 06:18:38 +0530 | [diff] [blame] | 128 | "SoC intc cascade interrupt", NULL)) |
| 129 | pr_err("Failed to register SoC intc cascade interrupt\n"); |
Paul Burton | adbdce7 | 2015-05-24 16:11:21 +0100 | [diff] [blame] | 130 | return 0; |
Paul Burton | fe778ec | 2015-05-24 16:11:25 +0100 | [diff] [blame] | 131 | |
Paul Cercueil | 8bc7464 | 2019-10-02 19:25:24 +0800 | [diff] [blame] | 132 | out_domain_remove: |
| 133 | irq_domain_remove(domain); |
Paul Cercueil | 52ecc87 | 2019-10-02 19:25:22 +0800 | [diff] [blame] | 134 | out_unmap_base: |
| 135 | iounmap(intc->base); |
Paul Burton | fe778ec | 2015-05-24 16:11:25 +0100 | [diff] [blame] | 136 | out_unmap_irq: |
| 137 | irq_dispose_mapping(parent_irq); |
| 138 | out_free: |
| 139 | kfree(intc); |
| 140 | out_err: |
| 141 | return err; |
Lars-Peter Clausen | 9869848 | 2010-07-17 11:08:43 +0000 | [diff] [blame] | 142 | } |
Paul Burton | 943d69c | 2015-05-24 16:11:26 +0100 | [diff] [blame] | 143 | |
| 144 | static int __init intc_1chip_of_init(struct device_node *node, |
| 145 | struct device_node *parent) |
| 146 | { |
| 147 | return ingenic_intc_of_init(node, 1); |
| 148 | } |
| 149 | IRQCHIP_DECLARE(jz4740_intc, "ingenic,jz4740-intc", intc_1chip_of_init); |
Paul Cercueil | 1047557 | 2018-07-13 16:49:09 +0200 | [diff] [blame] | 150 | IRQCHIP_DECLARE(jz4725b_intc, "ingenic,jz4725b-intc", intc_1chip_of_init); |
Paul Burton | 24ccfa0 | 2015-05-24 16:11:30 +0100 | [diff] [blame] | 151 | |
| 152 | static int __init intc_2chip_of_init(struct device_node *node, |
| 153 | struct device_node *parent) |
| 154 | { |
| 155 | return ingenic_intc_of_init(node, 2); |
| 156 | } |
Paul Cercueil | 5fbecd2 | 2021-03-07 17:20:14 +0000 | [diff] [blame] | 157 | IRQCHIP_DECLARE(jz4760_intc, "ingenic,jz4760-intc", intc_2chip_of_init); |
Paul Burton | 24ccfa0 | 2015-05-24 16:11:30 +0100 | [diff] [blame] | 158 | IRQCHIP_DECLARE(jz4770_intc, "ingenic,jz4770-intc", intc_2chip_of_init); |
| 159 | IRQCHIP_DECLARE(jz4775_intc, "ingenic,jz4775-intc", intc_2chip_of_init); |
| 160 | IRQCHIP_DECLARE(jz4780_intc, "ingenic,jz4780-intc", intc_2chip_of_init); |