Lars-Peter Clausen | 9869848 | 2010-07-17 11:08:43 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009-2010, Lars-Peter Clausen <lars@metafoo.de> |
| 3 | * JZ4740 platform IRQ support |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 6 | * under the terms of the GNU General Public License as published by the |
Lars-Peter Clausen | 9869848 | 2010-07-17 11:08:43 +0000 | [diff] [blame] | 7 | * Free Software Foundation; either version 2 of the License, or (at your |
| 8 | * option) any later version. |
| 9 | * |
| 10 | * You should have received a copy of the GNU General Public License along |
| 11 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 12 | * 675 Mass Ave, Cambridge, MA 02139, USA. |
| 13 | * |
| 14 | */ |
| 15 | |
| 16 | #include <linux/errno.h> |
| 17 | #include <linux/init.h> |
| 18 | #include <linux/types.h> |
| 19 | #include <linux/interrupt.h> |
| 20 | #include <linux/ioport.h> |
Paul Burton | adbdce7 | 2015-05-24 16:11:21 +0100 | [diff] [blame] | 21 | #include <linux/of_irq.h> |
Lars-Peter Clausen | 9869848 | 2010-07-17 11:08:43 +0000 | [diff] [blame] | 22 | #include <linux/timex.h> |
| 23 | #include <linux/slab.h> |
| 24 | #include <linux/delay.h> |
| 25 | |
Lars-Peter Clausen | 9869848 | 2010-07-17 11:08:43 +0000 | [diff] [blame] | 26 | #include <asm/io.h> |
Lars-Peter Clausen | 9869848 | 2010-07-17 11:08:43 +0000 | [diff] [blame] | 27 | |
| 28 | #include <asm/mach-jz4740/base.h> |
Brian Norris | 942e22d | 2014-12-17 18:39:01 -0800 | [diff] [blame] | 29 | #include <asm/mach-jz4740/irq.h> |
| 30 | |
| 31 | #include "irq.h" |
Lars-Peter Clausen | 9869848 | 2010-07-17 11:08:43 +0000 | [diff] [blame] | 32 | |
Paul Burton | adbdce7 | 2015-05-24 16:11:21 +0100 | [diff] [blame] | 33 | #include "../../drivers/irqchip/irqchip.h" |
| 34 | |
Paul Burton | fe778ec | 2015-05-24 16:11:25 +0100 | [diff] [blame] | 35 | struct ingenic_intc_data { |
| 36 | void __iomem *base; |
Paul Burton | 943d69c | 2015-05-24 16:11:26 +0100 | [diff] [blame^] | 37 | unsigned num_chips; |
Paul Burton | fe778ec | 2015-05-24 16:11:25 +0100 | [diff] [blame] | 38 | }; |
Lars-Peter Clausen | 9869848 | 2010-07-17 11:08:43 +0000 | [diff] [blame] | 39 | |
| 40 | #define JZ_REG_INTC_STATUS 0x00 |
| 41 | #define JZ_REG_INTC_MASK 0x04 |
| 42 | #define JZ_REG_INTC_SET_MASK 0x08 |
| 43 | #define JZ_REG_INTC_CLEAR_MASK 0x0c |
| 44 | #define JZ_REG_INTC_PENDING 0x10 |
Paul Burton | 943d69c | 2015-05-24 16:11:26 +0100 | [diff] [blame^] | 45 | #define CHIP_SIZE 0x20 |
Lars-Peter Clausen | 9869848 | 2010-07-17 11:08:43 +0000 | [diff] [blame] | 46 | |
Lars-Peter Clausen | 9869848 | 2010-07-17 11:08:43 +0000 | [diff] [blame] | 47 | static irqreturn_t jz4740_cascade(int irq, void *data) |
| 48 | { |
Paul Burton | fe778ec | 2015-05-24 16:11:25 +0100 | [diff] [blame] | 49 | struct ingenic_intc_data *intc = irq_get_handler_data(irq); |
Lars-Peter Clausen | 9869848 | 2010-07-17 11:08:43 +0000 | [diff] [blame] | 50 | uint32_t irq_reg; |
Paul Burton | 943d69c | 2015-05-24 16:11:26 +0100 | [diff] [blame^] | 51 | unsigned i; |
Lars-Peter Clausen | 9869848 | 2010-07-17 11:08:43 +0000 | [diff] [blame] | 52 | |
Paul Burton | 943d69c | 2015-05-24 16:11:26 +0100 | [diff] [blame^] | 53 | for (i = 0; i < intc->num_chips; i++) { |
| 54 | irq_reg = readl(intc->base + (i * CHIP_SIZE) + |
| 55 | JZ_REG_INTC_PENDING); |
| 56 | if (!irq_reg) |
| 57 | continue; |
Lars-Peter Clausen | 9869848 | 2010-07-17 11:08:43 +0000 | [diff] [blame] | 58 | |
Paul Burton | 943d69c | 2015-05-24 16:11:26 +0100 | [diff] [blame^] | 59 | generic_handle_irq(__fls(irq_reg) + (i * 32) + JZ4740_IRQ_BASE); |
| 60 | } |
Lars-Peter Clausen | 9869848 | 2010-07-17 11:08:43 +0000 | [diff] [blame] | 61 | |
| 62 | return IRQ_HANDLED; |
| 63 | } |
| 64 | |
Lars-Peter Clausen | 83bc769 | 2011-09-24 02:29:46 +0200 | [diff] [blame] | 65 | static void jz4740_irq_set_mask(struct irq_chip_generic *gc, uint32_t mask) |
| 66 | { |
| 67 | struct irq_chip_regs *regs = &gc->chip_types->regs; |
| 68 | |
| 69 | writel(mask, gc->reg_base + regs->enable); |
| 70 | writel(~mask, gc->reg_base + regs->disable); |
| 71 | } |
| 72 | |
| 73 | void jz4740_irq_suspend(struct irq_data *data) |
| 74 | { |
| 75 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(data); |
| 76 | jz4740_irq_set_mask(gc, gc->wake_active); |
| 77 | } |
| 78 | |
| 79 | void jz4740_irq_resume(struct irq_data *data) |
| 80 | { |
| 81 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(data); |
| 82 | jz4740_irq_set_mask(gc, gc->mask_cache); |
| 83 | } |
| 84 | |
Lars-Peter Clausen | 9869848 | 2010-07-17 11:08:43 +0000 | [diff] [blame] | 85 | static struct irqaction jz4740_cascade_action = { |
| 86 | .handler = jz4740_cascade, |
| 87 | .name = "JZ4740 cascade interrupt", |
| 88 | }; |
| 89 | |
Paul Burton | 943d69c | 2015-05-24 16:11:26 +0100 | [diff] [blame^] | 90 | static int __init ingenic_intc_of_init(struct device_node *node, |
| 91 | unsigned num_chips) |
Lars-Peter Clausen | 9869848 | 2010-07-17 11:08:43 +0000 | [diff] [blame] | 92 | { |
Paul Burton | fe778ec | 2015-05-24 16:11:25 +0100 | [diff] [blame] | 93 | struct ingenic_intc_data *intc; |
Lars-Peter Clausen | 83bc769 | 2011-09-24 02:29:46 +0200 | [diff] [blame] | 94 | struct irq_chip_generic *gc; |
| 95 | struct irq_chip_type *ct; |
Paul Burton | 638c885 | 2015-05-24 16:11:23 +0100 | [diff] [blame] | 96 | struct irq_domain *domain; |
Paul Burton | fe778ec | 2015-05-24 16:11:25 +0100 | [diff] [blame] | 97 | int parent_irq, err = 0; |
Paul Burton | 943d69c | 2015-05-24 16:11:26 +0100 | [diff] [blame^] | 98 | unsigned i; |
Paul Burton | fe778ec | 2015-05-24 16:11:25 +0100 | [diff] [blame] | 99 | |
| 100 | intc = kzalloc(sizeof(*intc), GFP_KERNEL); |
| 101 | if (!intc) { |
| 102 | err = -ENOMEM; |
| 103 | goto out_err; |
| 104 | } |
Paul Burton | 69ce4b2 | 2015-05-24 16:11:22 +0100 | [diff] [blame] | 105 | |
| 106 | parent_irq = irq_of_parse_and_map(node, 0); |
Paul Burton | fe778ec | 2015-05-24 16:11:25 +0100 | [diff] [blame] | 107 | if (!parent_irq) { |
| 108 | err = -EINVAL; |
| 109 | goto out_free; |
| 110 | } |
Lars-Peter Clausen | 83bc769 | 2011-09-24 02:29:46 +0200 | [diff] [blame] | 111 | |
Paul Burton | fe778ec | 2015-05-24 16:11:25 +0100 | [diff] [blame] | 112 | err = irq_set_handler_data(parent_irq, intc); |
| 113 | if (err) |
| 114 | goto out_unmap_irq; |
| 115 | |
Paul Burton | 943d69c | 2015-05-24 16:11:26 +0100 | [diff] [blame^] | 116 | intc->num_chips = num_chips; |
Paul Burton | fe778ec | 2015-05-24 16:11:25 +0100 | [diff] [blame] | 117 | intc->base = ioremap(JZ4740_INTC_BASE_ADDR, 0x14); |
Lars-Peter Clausen | 9869848 | 2010-07-17 11:08:43 +0000 | [diff] [blame] | 118 | |
Paul Burton | 943d69c | 2015-05-24 16:11:26 +0100 | [diff] [blame^] | 119 | for (i = 0; i < num_chips; i++) { |
| 120 | /* Mask all irqs */ |
| 121 | writel(0xffffffff, intc->base + (i * CHIP_SIZE) + |
| 122 | JZ_REG_INTC_SET_MASK); |
Thomas Gleixner | 42b64f3 | 2011-03-23 21:08:53 +0000 | [diff] [blame] | 123 | |
Paul Burton | 943d69c | 2015-05-24 16:11:26 +0100 | [diff] [blame^] | 124 | gc = irq_alloc_generic_chip("INTC", 1, |
| 125 | JZ4740_IRQ_BASE + (i * 32), |
| 126 | intc->base + (i * CHIP_SIZE), |
| 127 | handle_level_irq); |
Lars-Peter Clausen | 83bc769 | 2011-09-24 02:29:46 +0200 | [diff] [blame] | 128 | |
Paul Burton | 943d69c | 2015-05-24 16:11:26 +0100 | [diff] [blame^] | 129 | gc->wake_enabled = IRQ_MSK(32); |
Lars-Peter Clausen | 83bc769 | 2011-09-24 02:29:46 +0200 | [diff] [blame] | 130 | |
Paul Burton | 943d69c | 2015-05-24 16:11:26 +0100 | [diff] [blame^] | 131 | ct = gc->chip_types; |
| 132 | ct->regs.enable = JZ_REG_INTC_CLEAR_MASK; |
| 133 | ct->regs.disable = JZ_REG_INTC_SET_MASK; |
| 134 | ct->chip.irq_unmask = irq_gc_unmask_enable_reg; |
| 135 | ct->chip.irq_mask = irq_gc_mask_disable_reg; |
| 136 | ct->chip.irq_mask_ack = irq_gc_mask_disable_reg; |
| 137 | ct->chip.irq_set_wake = irq_gc_set_wake; |
| 138 | ct->chip.irq_suspend = jz4740_irq_suspend; |
| 139 | ct->chip.irq_resume = jz4740_irq_resume; |
Lars-Peter Clausen | 83bc769 | 2011-09-24 02:29:46 +0200 | [diff] [blame] | 140 | |
Paul Burton | 943d69c | 2015-05-24 16:11:26 +0100 | [diff] [blame^] | 141 | irq_setup_generic_chip(gc, IRQ_MSK(32), 0, 0, |
| 142 | IRQ_NOPROBE | IRQ_LEVEL); |
| 143 | } |
Lars-Peter Clausen | 9869848 | 2010-07-17 11:08:43 +0000 | [diff] [blame] | 144 | |
Paul Burton | 638c885 | 2015-05-24 16:11:23 +0100 | [diff] [blame] | 145 | domain = irq_domain_add_legacy(node, num_chips * 32, JZ4740_IRQ_BASE, 0, |
| 146 | &irq_domain_simple_ops, NULL); |
| 147 | if (!domain) |
| 148 | pr_warn("unable to register IRQ domain\n"); |
| 149 | |
Paul Burton | 69ce4b2 | 2015-05-24 16:11:22 +0100 | [diff] [blame] | 150 | setup_irq(parent_irq, &jz4740_cascade_action); |
Paul Burton | adbdce7 | 2015-05-24 16:11:21 +0100 | [diff] [blame] | 151 | return 0; |
Paul Burton | fe778ec | 2015-05-24 16:11:25 +0100 | [diff] [blame] | 152 | |
| 153 | out_unmap_irq: |
| 154 | irq_dispose_mapping(parent_irq); |
| 155 | out_free: |
| 156 | kfree(intc); |
| 157 | out_err: |
| 158 | return err; |
Lars-Peter Clausen | 9869848 | 2010-07-17 11:08:43 +0000 | [diff] [blame] | 159 | } |
Paul Burton | 943d69c | 2015-05-24 16:11:26 +0100 | [diff] [blame^] | 160 | |
| 161 | static int __init intc_1chip_of_init(struct device_node *node, |
| 162 | struct device_node *parent) |
| 163 | { |
| 164 | return ingenic_intc_of_init(node, 1); |
| 165 | } |
| 166 | IRQCHIP_DECLARE(jz4740_intc, "ingenic,jz4740-intc", intc_1chip_of_init); |