blob: 020852d3bdd8bd002710e79aba3e036074fefd55 [file] [log] [blame]
Paulius Zaleckas59d3a192009-03-26 10:06:08 +02001/*
2 * Interrupt routines for Gemini
3 *
4 * Copyright (C) 2001-2006 Storlink, Corp.
5 * Copyright (C) 2008-2009 Paulius Zaleckas <paulius.zaleckas@teltonika.lt>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 */
12#include <linux/init.h>
13#include <linux/io.h>
14#include <linux/ioport.h>
15#include <linux/stddef.h>
16#include <linux/list.h>
17#include <linux/sched.h>
18#include <asm/irq.h>
19#include <asm/mach/irq.h>
Linus Walleije829c662012-08-30 19:22:36 +020020#include <asm/system_misc.h>
Paulius Zaleckas59d3a192009-03-26 10:06:08 +020021#include <mach/hardware.h>
22
23#define IRQ_SOURCE(base_addr) (base_addr + 0x00)
24#define IRQ_MASK(base_addr) (base_addr + 0x04)
25#define IRQ_CLEAR(base_addr) (base_addr + 0x08)
26#define IRQ_TMODE(base_addr) (base_addr + 0x0C)
27#define IRQ_TLEVEL(base_addr) (base_addr + 0x10)
28#define IRQ_STATUS(base_addr) (base_addr + 0x14)
29#define FIQ_SOURCE(base_addr) (base_addr + 0x20)
30#define FIQ_MASK(base_addr) (base_addr + 0x24)
31#define FIQ_CLEAR(base_addr) (base_addr + 0x28)
32#define FIQ_TMODE(base_addr) (base_addr + 0x2C)
33#define FIQ_LEVEL(base_addr) (base_addr + 0x30)
34#define FIQ_STATUS(base_addr) (base_addr + 0x34)
35
Lennert Buytenhek413802b2010-11-29 10:30:40 +010036static void gemini_ack_irq(struct irq_data *d)
Paulius Zaleckas59d3a192009-03-26 10:06:08 +020037{
Lennert Buytenhek413802b2010-11-29 10:30:40 +010038 __raw_writel(1 << d->irq, IRQ_CLEAR(IO_ADDRESS(GEMINI_INTERRUPT_BASE)));
Paulius Zaleckas59d3a192009-03-26 10:06:08 +020039}
40
Lennert Buytenhek413802b2010-11-29 10:30:40 +010041static void gemini_mask_irq(struct irq_data *d)
Paulius Zaleckas59d3a192009-03-26 10:06:08 +020042{
43 unsigned int mask;
44
45 mask = __raw_readl(IRQ_MASK(IO_ADDRESS(GEMINI_INTERRUPT_BASE)));
Lennert Buytenhek413802b2010-11-29 10:30:40 +010046 mask &= ~(1 << d->irq);
Paulius Zaleckas59d3a192009-03-26 10:06:08 +020047 __raw_writel(mask, IRQ_MASK(IO_ADDRESS(GEMINI_INTERRUPT_BASE)));
48}
49
Lennert Buytenhek413802b2010-11-29 10:30:40 +010050static void gemini_unmask_irq(struct irq_data *d)
Paulius Zaleckas59d3a192009-03-26 10:06:08 +020051{
52 unsigned int mask;
53
54 mask = __raw_readl(IRQ_MASK(IO_ADDRESS(GEMINI_INTERRUPT_BASE)));
Lennert Buytenhek413802b2010-11-29 10:30:40 +010055 mask |= (1 << d->irq);
Paulius Zaleckas59d3a192009-03-26 10:06:08 +020056 __raw_writel(mask, IRQ_MASK(IO_ADDRESS(GEMINI_INTERRUPT_BASE)));
57}
58
59static struct irq_chip gemini_irq_chip = {
Lennert Buytenhek413802b2010-11-29 10:30:40 +010060 .name = "INTC",
61 .irq_ack = gemini_ack_irq,
62 .irq_mask = gemini_mask_irq,
63 .irq_unmask = gemini_unmask_irq,
Paulius Zaleckas59d3a192009-03-26 10:06:08 +020064};
65
66static struct resource irq_resource = {
67 .name = "irq_handler",
68 .start = IO_ADDRESS(GEMINI_INTERRUPT_BASE),
69 .end = IO_ADDRESS(FIQ_STATUS(GEMINI_INTERRUPT_BASE)) + 4,
70};
71
72void __init gemini_init_irq(void)
73{
74 unsigned int i, mode = 0, level = 0;
75
76 /*
Nicolas Pitre8925b0f2011-08-03 06:29:42 -040077 * Disable the idle handler by default since it is buggy
78 * For more info see arch/arm/mach-gemini/idle.c
Paulius Zaleckas59d3a192009-03-26 10:06:08 +020079 */
80 disable_hlt();
81
82 request_resource(&iomem_resource, &irq_resource);
83
84 for (i = 0; i < NR_IRQS; i++) {
Thomas Gleixner6845664a2011-03-24 13:25:22 +010085 irq_set_chip(i, &gemini_irq_chip);
Paulius Zaleckas59d3a192009-03-26 10:06:08 +020086 if((i >= IRQ_TIMER1 && i <= IRQ_TIMER3) || (i >= IRQ_SERIRQ0 && i <= IRQ_SERIRQ1)) {
Thomas Gleixner6845664a2011-03-24 13:25:22 +010087 irq_set_handler(i, handle_edge_irq);
Paulius Zaleckas59d3a192009-03-26 10:06:08 +020088 mode |= 1 << i;
89 level |= 1 << i;
90 } else {
Thomas Gleixner6845664a2011-03-24 13:25:22 +010091 irq_set_handler(i, handle_level_irq);
Paulius Zaleckas59d3a192009-03-26 10:06:08 +020092 }
93 set_irq_flags(i, IRQF_VALID | IRQF_PROBE);
94 }
95
96 /* Disable all interrupts */
97 __raw_writel(0, IRQ_MASK(IO_ADDRESS(GEMINI_INTERRUPT_BASE)));
98 __raw_writel(0, FIQ_MASK(IO_ADDRESS(GEMINI_INTERRUPT_BASE)));
99
100 /* Set interrupt mode */
101 __raw_writel(mode, IRQ_TMODE(IO_ADDRESS(GEMINI_INTERRUPT_BASE)));
102 __raw_writel(level, IRQ_TLEVEL(IO_ADDRESS(GEMINI_INTERRUPT_BASE)));
103}