blob: 7ad6688f371b95258343ede2a1de9454f3b52355 [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 Burtonadbdce72015-05-24 16:11:21 +010021#include <linux/of_irq.h>
Lars-Peter Clausen98698482010-07-17 11:08:43 +000022#include <linux/timex.h>
23#include <linux/slab.h>
24#include <linux/delay.h>
25
Lars-Peter Clausen98698482010-07-17 11:08:43 +000026#include <asm/io.h>
Lars-Peter Clausen98698482010-07-17 11:08:43 +000027
28#include <asm/mach-jz4740/base.h>
Brian Norris942e22d2014-12-17 18:39:01 -080029#include <asm/mach-jz4740/irq.h>
30
31#include "irq.h"
Lars-Peter Clausen98698482010-07-17 11:08:43 +000032
Paul Burtonadbdce72015-05-24 16:11:21 +010033#include "../../drivers/irqchip/irqchip.h"
34
Paul Burtonfe778ec2015-05-24 16:11:25 +010035struct ingenic_intc_data {
36 void __iomem *base;
Paul Burton943d69c2015-05-24 16:11:26 +010037 unsigned num_chips;
Paul Burtonfe778ec2015-05-24 16:11:25 +010038};
Lars-Peter Clausen98698482010-07-17 11:08:43 +000039
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 Burton943d69c2015-05-24 16:11:26 +010045#define CHIP_SIZE 0x20
Lars-Peter Clausen98698482010-07-17 11:08:43 +000046
Lars-Peter Clausen98698482010-07-17 11:08:43 +000047static irqreturn_t jz4740_cascade(int irq, void *data)
48{
Paul Burtonfe778ec2015-05-24 16:11:25 +010049 struct ingenic_intc_data *intc = irq_get_handler_data(irq);
Lars-Peter Clausen98698482010-07-17 11:08:43 +000050 uint32_t irq_reg;
Paul Burton943d69c2015-05-24 16:11:26 +010051 unsigned i;
Lars-Peter Clausen98698482010-07-17 11:08:43 +000052
Paul Burton943d69c2015-05-24 16:11:26 +010053 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 Clausen98698482010-07-17 11:08:43 +000058
Paul Burton943d69c2015-05-24 16:11:26 +010059 generic_handle_irq(__fls(irq_reg) + (i * 32) + JZ4740_IRQ_BASE);
60 }
Lars-Peter Clausen98698482010-07-17 11:08:43 +000061
62 return IRQ_HANDLED;
63}
64
Lars-Peter Clausen83bc7692011-09-24 02:29:46 +020065static 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
73void 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
79void 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 Clausen98698482010-07-17 11:08:43 +000085static struct irqaction jz4740_cascade_action = {
86 .handler = jz4740_cascade,
87 .name = "JZ4740 cascade interrupt",
88};
89
Paul Burton943d69c2015-05-24 16:11:26 +010090static int __init ingenic_intc_of_init(struct device_node *node,
91 unsigned num_chips)
Lars-Peter Clausen98698482010-07-17 11:08:43 +000092{
Paul Burtonfe778ec2015-05-24 16:11:25 +010093 struct ingenic_intc_data *intc;
Lars-Peter Clausen83bc7692011-09-24 02:29:46 +020094 struct irq_chip_generic *gc;
95 struct irq_chip_type *ct;
Paul Burton638c8852015-05-24 16:11:23 +010096 struct irq_domain *domain;
Paul Burtonfe778ec2015-05-24 16:11:25 +010097 int parent_irq, err = 0;
Paul Burton943d69c2015-05-24 16:11:26 +010098 unsigned i;
Paul Burtonfe778ec2015-05-24 16:11:25 +010099
100 intc = kzalloc(sizeof(*intc), GFP_KERNEL);
101 if (!intc) {
102 err = -ENOMEM;
103 goto out_err;
104 }
Paul Burton69ce4b22015-05-24 16:11:22 +0100105
106 parent_irq = irq_of_parse_and_map(node, 0);
Paul Burtonfe778ec2015-05-24 16:11:25 +0100107 if (!parent_irq) {
108 err = -EINVAL;
109 goto out_free;
110 }
Lars-Peter Clausen83bc7692011-09-24 02:29:46 +0200111
Paul Burtonfe778ec2015-05-24 16:11:25 +0100112 err = irq_set_handler_data(parent_irq, intc);
113 if (err)
114 goto out_unmap_irq;
115
Paul Burton943d69c2015-05-24 16:11:26 +0100116 intc->num_chips = num_chips;
Paul Burtonfe778ec2015-05-24 16:11:25 +0100117 intc->base = ioremap(JZ4740_INTC_BASE_ADDR, 0x14);
Lars-Peter Clausen98698482010-07-17 11:08:43 +0000118
Paul Burton943d69c2015-05-24 16:11:26 +0100119 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 Gleixner42b64f32011-03-23 21:08:53 +0000123
Paul Burton943d69c2015-05-24 16:11:26 +0100124 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 Clausen83bc7692011-09-24 02:29:46 +0200128
Paul Burton943d69c2015-05-24 16:11:26 +0100129 gc->wake_enabled = IRQ_MSK(32);
Lars-Peter Clausen83bc7692011-09-24 02:29:46 +0200130
Paul Burton943d69c2015-05-24 16:11:26 +0100131 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 Clausen83bc7692011-09-24 02:29:46 +0200140
Paul Burton943d69c2015-05-24 16:11:26 +0100141 irq_setup_generic_chip(gc, IRQ_MSK(32), 0, 0,
142 IRQ_NOPROBE | IRQ_LEVEL);
143 }
Lars-Peter Clausen98698482010-07-17 11:08:43 +0000144
Paul Burton638c8852015-05-24 16:11:23 +0100145 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 Burton69ce4b22015-05-24 16:11:22 +0100150 setup_irq(parent_irq, &jz4740_cascade_action);
Paul Burtonadbdce72015-05-24 16:11:21 +0100151 return 0;
Paul Burtonfe778ec2015-05-24 16:11:25 +0100152
153out_unmap_irq:
154 irq_dispose_mapping(parent_irq);
155out_free:
156 kfree(intc);
157out_err:
158 return err;
Lars-Peter Clausen98698482010-07-17 11:08:43 +0000159}
Paul Burton943d69c2015-05-24 16:11:26 +0100160
161static 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}
166IRQCHIP_DECLARE(jz4740_intc, "ingenic,jz4740-intc", intc_1chip_of_init);