blob: 8b7df9a581c272676c6d2cad201c1f6a0f26804a [file] [log] [blame]
Lars-Peter Clausen98698482010-07-17 11:08:43 +00001/*
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 Baechle70342282013-01-22 12:59:30 +01006 * under the terms of the GNU General Public License as published by the
Lars-Peter Clausen98698482010-07-17 11:08:43 +00007 * 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 Burton3aa94592015-05-24 16:11:28 +010021#include <linux/of_address.h>
Paul Burtonadbdce72015-05-24 16:11:21 +010022#include <linux/of_irq.h>
Lars-Peter Clausen98698482010-07-17 11:08:43 +000023#include <linux/timex.h>
24#include <linux/slab.h>
25#include <linux/delay.h>
26
Lars-Peter Clausen98698482010-07-17 11:08:43 +000027#include <asm/io.h>
Brian Norris942e22d2014-12-17 18:39:01 -080028#include <asm/mach-jz4740/irq.h>
29
30#include "irq.h"
Lars-Peter Clausen98698482010-07-17 11:08:43 +000031
Paul Burtonadbdce72015-05-24 16:11:21 +010032#include "../../drivers/irqchip/irqchip.h"
33
Paul Burtonfe778ec2015-05-24 16:11:25 +010034struct ingenic_intc_data {
35 void __iomem *base;
Paul Burton943d69c2015-05-24 16:11:26 +010036 unsigned num_chips;
Paul Burtonfe778ec2015-05-24 16:11:25 +010037};
Lars-Peter Clausen98698482010-07-17 11:08:43 +000038
39#define JZ_REG_INTC_STATUS 0x00
40#define JZ_REG_INTC_MASK 0x04
41#define JZ_REG_INTC_SET_MASK 0x08
42#define JZ_REG_INTC_CLEAR_MASK 0x0c
43#define JZ_REG_INTC_PENDING 0x10
Paul Burton943d69c2015-05-24 16:11:26 +010044#define CHIP_SIZE 0x20
Lars-Peter Clausen98698482010-07-17 11:08:43 +000045
Lars-Peter Clausen98698482010-07-17 11:08:43 +000046static irqreturn_t jz4740_cascade(int irq, void *data)
47{
Paul Burtonfe778ec2015-05-24 16:11:25 +010048 struct ingenic_intc_data *intc = irq_get_handler_data(irq);
Lars-Peter Clausen98698482010-07-17 11:08:43 +000049 uint32_t irq_reg;
Paul Burton943d69c2015-05-24 16:11:26 +010050 unsigned i;
Lars-Peter Clausen98698482010-07-17 11:08:43 +000051
Paul Burton943d69c2015-05-24 16:11:26 +010052 for (i = 0; i < intc->num_chips; i++) {
53 irq_reg = readl(intc->base + (i * CHIP_SIZE) +
54 JZ_REG_INTC_PENDING);
55 if (!irq_reg)
56 continue;
Lars-Peter Clausen98698482010-07-17 11:08:43 +000057
Paul Burton943d69c2015-05-24 16:11:26 +010058 generic_handle_irq(__fls(irq_reg) + (i * 32) + JZ4740_IRQ_BASE);
59 }
Lars-Peter Clausen98698482010-07-17 11:08:43 +000060
61 return IRQ_HANDLED;
62}
63
Lars-Peter Clausen83bc7692011-09-24 02:29:46 +020064static void jz4740_irq_set_mask(struct irq_chip_generic *gc, uint32_t mask)
65{
66 struct irq_chip_regs *regs = &gc->chip_types->regs;
67
68 writel(mask, gc->reg_base + regs->enable);
69 writel(~mask, gc->reg_base + regs->disable);
70}
71
72void jz4740_irq_suspend(struct irq_data *data)
73{
74 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(data);
75 jz4740_irq_set_mask(gc, gc->wake_active);
76}
77
78void jz4740_irq_resume(struct irq_data *data)
79{
80 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(data);
81 jz4740_irq_set_mask(gc, gc->mask_cache);
82}
83
Lars-Peter Clausen98698482010-07-17 11:08:43 +000084static struct irqaction jz4740_cascade_action = {
85 .handler = jz4740_cascade,
86 .name = "JZ4740 cascade interrupt",
87};
88
Paul Burton943d69c2015-05-24 16:11:26 +010089static int __init ingenic_intc_of_init(struct device_node *node,
90 unsigned num_chips)
Lars-Peter Clausen98698482010-07-17 11:08:43 +000091{
Paul Burtonfe778ec2015-05-24 16:11:25 +010092 struct ingenic_intc_data *intc;
Lars-Peter Clausen83bc7692011-09-24 02:29:46 +020093 struct irq_chip_generic *gc;
94 struct irq_chip_type *ct;
Paul Burton638c8852015-05-24 16:11:23 +010095 struct irq_domain *domain;
Paul Burtonfe778ec2015-05-24 16:11:25 +010096 int parent_irq, err = 0;
Paul Burton943d69c2015-05-24 16:11:26 +010097 unsigned i;
Paul Burtonfe778ec2015-05-24 16:11:25 +010098
99 intc = kzalloc(sizeof(*intc), GFP_KERNEL);
100 if (!intc) {
101 err = -ENOMEM;
102 goto out_err;
103 }
Paul Burton69ce4b22015-05-24 16:11:22 +0100104
105 parent_irq = irq_of_parse_and_map(node, 0);
Paul Burtonfe778ec2015-05-24 16:11:25 +0100106 if (!parent_irq) {
107 err = -EINVAL;
108 goto out_free;
109 }
Lars-Peter Clausen83bc7692011-09-24 02:29:46 +0200110
Paul Burtonfe778ec2015-05-24 16:11:25 +0100111 err = irq_set_handler_data(parent_irq, intc);
112 if (err)
113 goto out_unmap_irq;
114
Paul Burton943d69c2015-05-24 16:11:26 +0100115 intc->num_chips = num_chips;
Paul Burton3aa94592015-05-24 16:11:28 +0100116 intc->base = of_iomap(node, 0);
117 if (!intc->base) {
118 err = -ENODEV;
119 goto out_unmap_irq;
120 }
Lars-Peter Clausen98698482010-07-17 11:08:43 +0000121
Paul Burton943d69c2015-05-24 16:11:26 +0100122 for (i = 0; i < num_chips; i++) {
123 /* Mask all irqs */
124 writel(0xffffffff, intc->base + (i * CHIP_SIZE) +
125 JZ_REG_INTC_SET_MASK);
Thomas Gleixner42b64f32011-03-23 21:08:53 +0000126
Paul Burton943d69c2015-05-24 16:11:26 +0100127 gc = irq_alloc_generic_chip("INTC", 1,
128 JZ4740_IRQ_BASE + (i * 32),
129 intc->base + (i * CHIP_SIZE),
130 handle_level_irq);
Lars-Peter Clausen83bc7692011-09-24 02:29:46 +0200131
Paul Burton943d69c2015-05-24 16:11:26 +0100132 gc->wake_enabled = IRQ_MSK(32);
Lars-Peter Clausen83bc7692011-09-24 02:29:46 +0200133
Paul Burton943d69c2015-05-24 16:11:26 +0100134 ct = gc->chip_types;
135 ct->regs.enable = JZ_REG_INTC_CLEAR_MASK;
136 ct->regs.disable = JZ_REG_INTC_SET_MASK;
137 ct->chip.irq_unmask = irq_gc_unmask_enable_reg;
138 ct->chip.irq_mask = irq_gc_mask_disable_reg;
139 ct->chip.irq_mask_ack = irq_gc_mask_disable_reg;
140 ct->chip.irq_set_wake = irq_gc_set_wake;
141 ct->chip.irq_suspend = jz4740_irq_suspend;
142 ct->chip.irq_resume = jz4740_irq_resume;
Lars-Peter Clausen83bc7692011-09-24 02:29:46 +0200143
Paul Burton943d69c2015-05-24 16:11:26 +0100144 irq_setup_generic_chip(gc, IRQ_MSK(32), 0, 0,
145 IRQ_NOPROBE | IRQ_LEVEL);
146 }
Lars-Peter Clausen98698482010-07-17 11:08:43 +0000147
Paul Burton638c8852015-05-24 16:11:23 +0100148 domain = irq_domain_add_legacy(node, num_chips * 32, JZ4740_IRQ_BASE, 0,
149 &irq_domain_simple_ops, NULL);
150 if (!domain)
151 pr_warn("unable to register IRQ domain\n");
152
Paul Burton69ce4b22015-05-24 16:11:22 +0100153 setup_irq(parent_irq, &jz4740_cascade_action);
Paul Burtonadbdce72015-05-24 16:11:21 +0100154 return 0;
Paul Burtonfe778ec2015-05-24 16:11:25 +0100155
156out_unmap_irq:
157 irq_dispose_mapping(parent_irq);
158out_free:
159 kfree(intc);
160out_err:
161 return err;
Lars-Peter Clausen98698482010-07-17 11:08:43 +0000162}
Paul Burton943d69c2015-05-24 16:11:26 +0100163
164static int __init intc_1chip_of_init(struct device_node *node,
165 struct device_node *parent)
166{
167 return ingenic_intc_of_init(node, 1);
168}
169IRQCHIP_DECLARE(jz4740_intc, "ingenic,jz4740-intc", intc_1chip_of_init);