blob: a11b6184026ee2116e1409bf4e198a4e033787a4 [file] [log] [blame]
Shawn Guo289569f2010-12-18 21:39:28 +08001/*
2 * Copyright (C) 2009-2010 Freescale Semiconductor, Inc. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19#include <linux/kernel.h>
20#include <linux/init.h>
21#include <linux/irq.h>
22#include <linux/io.h>
Shawn Guo4e0a1b82012-08-20 10:14:56 +080023#include <asm/exception.h>
Shawn Guo289569f2010-12-18 21:39:28 +080024#include <mach/mxs.h>
25#include <mach/common.h>
26
27#define HW_ICOLL_VECTOR 0x0000
28#define HW_ICOLL_LEVELACK 0x0010
29#define HW_ICOLL_CTRL 0x0020
Shawn Guo4e0a1b82012-08-20 10:14:56 +080030#define HW_ICOLL_STAT_OFFSET 0x0070
Shawn Guo289569f2010-12-18 21:39:28 +080031#define HW_ICOLL_INTERRUPTn_SET(n) (0x0124 + (n) * 0x10)
32#define HW_ICOLL_INTERRUPTn_CLR(n) (0x0128 + (n) * 0x10)
33#define BM_ICOLL_INTERRUPTn_ENABLE 0x00000004
34#define BV_ICOLL_LEVELACK_IRQLEVELACK__LEVEL0 0x1
35
36static void __iomem *icoll_base = MXS_IO_ADDRESS(MXS_ICOLL_BASE_ADDR);
37
Uwe Kleine-Königbf0c11182011-02-18 21:31:41 +010038static void icoll_ack_irq(struct irq_data *d)
Shawn Guo289569f2010-12-18 21:39:28 +080039{
40 /*
41 * The Interrupt Collector is able to prioritize irqs.
42 * Currently only level 0 is used. So acking can use
43 * BV_ICOLL_LEVELACK_IRQLEVELACK__LEVEL0 unconditionally.
44 */
45 __raw_writel(BV_ICOLL_LEVELACK_IRQLEVELACK__LEVEL0,
46 icoll_base + HW_ICOLL_LEVELACK);
47}
48
Uwe Kleine-Königbf0c11182011-02-18 21:31:41 +010049static void icoll_mask_irq(struct irq_data *d)
Shawn Guo289569f2010-12-18 21:39:28 +080050{
51 __raw_writel(BM_ICOLL_INTERRUPTn_ENABLE,
Uwe Kleine-Königbf0c11182011-02-18 21:31:41 +010052 icoll_base + HW_ICOLL_INTERRUPTn_CLR(d->irq));
Shawn Guo289569f2010-12-18 21:39:28 +080053}
54
Uwe Kleine-Königbf0c11182011-02-18 21:31:41 +010055static void icoll_unmask_irq(struct irq_data *d)
Shawn Guo289569f2010-12-18 21:39:28 +080056{
57 __raw_writel(BM_ICOLL_INTERRUPTn_ENABLE,
Uwe Kleine-Königbf0c11182011-02-18 21:31:41 +010058 icoll_base + HW_ICOLL_INTERRUPTn_SET(d->irq));
Shawn Guo289569f2010-12-18 21:39:28 +080059}
60
61static struct irq_chip mxs_icoll_chip = {
Uwe Kleine-Königbf0c11182011-02-18 21:31:41 +010062 .irq_ack = icoll_ack_irq,
63 .irq_mask = icoll_mask_irq,
64 .irq_unmask = icoll_unmask_irq,
Shawn Guo289569f2010-12-18 21:39:28 +080065};
66
Shawn Guo4e0a1b82012-08-20 10:14:56 +080067asmlinkage void __exception_irq_entry icoll_handle_irq(struct pt_regs *regs)
68{
69 u32 irqnr;
70
71 do {
72 irqnr = __raw_readl(icoll_base + HW_ICOLL_STAT_OFFSET);
73 if (irqnr != 0x7f) {
74 __raw_writel(irqnr, icoll_base + HW_ICOLL_VECTOR);
75 handle_IRQ(irqnr, regs);
76 continue;
77 }
78 break;
79 } while (1);
80}
81
Shawn Guo289569f2010-12-18 21:39:28 +080082void __init icoll_init_irq(void)
83{
84 int i;
85
86 /*
87 * Interrupt Collector reset, which initializes the priority
88 * for each irq to level 0.
89 */
90 mxs_reset_block(icoll_base + HW_ICOLL_CTRL);
91
92 for (i = 0; i < MXS_INTERNAL_IRQS; i++) {
Thomas Gleixnerf38c02f2011-03-24 13:35:09 +010093 irq_set_chip_and_handler(i, &mxs_icoll_chip, handle_level_irq);
Shawn Guo289569f2010-12-18 21:39:28 +080094 set_irq_flags(i, IRQF_VALID);
95 }
96}