blob: 209fa5c65d4cee50bafa54e6a5d38b120472c33d [file] [log] [blame]
Hans J. Koche9268ef2010-09-17 18:16:29 +02001/*
2 * Copyright (C) Telechips, Inc.
3 * Copyright (C) 2009-2010 Hans J. Koch <hjk@linutronix.de>
4 *
5 * Licensed under the terms of the GNU GPL version 2.
6 */
7
8#include <linux/init.h>
9#include <linux/interrupt.h>
10#include <linux/io.h>
11
12#include <asm/irq.h>
13#include <asm/mach/irq.h>
14
15#include <mach/tcc8k-regs.h>
16#include <mach/irqs.h>
17
18#include "common.h"
19
20/* Disable IRQ */
Lennert Buytenhek76fbec82010-11-29 11:14:16 +010021static void tcc8000_mask_ack_irq0(struct irq_data *d)
Hans J. Koche9268ef2010-09-17 18:16:29 +020022{
Lennert Buytenhek76fbec82010-11-29 11:14:16 +010023 PIC0_IEN &= ~(1 << d->irq);
24 PIC0_CREQ |= (1 << d->irq);
Hans J. Koche9268ef2010-09-17 18:16:29 +020025}
26
Lennert Buytenhek76fbec82010-11-29 11:14:16 +010027static void tcc8000_mask_ack_irq1(struct irq_data *d)
Hans J. Koche9268ef2010-09-17 18:16:29 +020028{
Lennert Buytenhek76fbec82010-11-29 11:14:16 +010029 PIC1_IEN &= ~(1 << (d->irq - 32));
30 PIC1_CREQ |= (1 << (d->irq - 32));
Hans J. Koche9268ef2010-09-17 18:16:29 +020031}
32
Lennert Buytenhek76fbec82010-11-29 11:14:16 +010033static void tcc8000_mask_irq0(struct irq_data *d)
Hans J. Koche9268ef2010-09-17 18:16:29 +020034{
Lennert Buytenhek76fbec82010-11-29 11:14:16 +010035 PIC0_IEN &= ~(1 << d->irq);
Hans J. Koche9268ef2010-09-17 18:16:29 +020036}
37
Lennert Buytenhek76fbec82010-11-29 11:14:16 +010038static void tcc8000_mask_irq1(struct irq_data *d)
Hans J. Koche9268ef2010-09-17 18:16:29 +020039{
Lennert Buytenhek76fbec82010-11-29 11:14:16 +010040 PIC1_IEN &= ~(1 << (d->irq - 32));
Hans J. Koche9268ef2010-09-17 18:16:29 +020041}
42
Lennert Buytenhek76fbec82010-11-29 11:14:16 +010043static void tcc8000_ack_irq0(struct irq_data *d)
Hans J. Koche9268ef2010-09-17 18:16:29 +020044{
Lennert Buytenhek76fbec82010-11-29 11:14:16 +010045 PIC0_CREQ |= (1 << d->irq);
Hans J. Koche9268ef2010-09-17 18:16:29 +020046}
47
Lennert Buytenhek76fbec82010-11-29 11:14:16 +010048static void tcc8000_ack_irq1(struct irq_data *d)
Hans J. Koche9268ef2010-09-17 18:16:29 +020049{
Lennert Buytenhek76fbec82010-11-29 11:14:16 +010050 PIC1_CREQ |= (1 << (d->irq - 32));
Hans J. Koche9268ef2010-09-17 18:16:29 +020051}
52
53/* Enable IRQ */
Lennert Buytenhek76fbec82010-11-29 11:14:16 +010054static void tcc8000_unmask_irq0(struct irq_data *d)
Hans J. Koche9268ef2010-09-17 18:16:29 +020055{
Lennert Buytenhek76fbec82010-11-29 11:14:16 +010056 PIC0_IEN |= (1 << d->irq);
57 PIC0_INTOEN |= (1 << d->irq);
Hans J. Koche9268ef2010-09-17 18:16:29 +020058}
59
Lennert Buytenhek76fbec82010-11-29 11:14:16 +010060static void tcc8000_unmask_irq1(struct irq_data *d)
Hans J. Koche9268ef2010-09-17 18:16:29 +020061{
Lennert Buytenhek76fbec82010-11-29 11:14:16 +010062 PIC1_IEN |= (1 << (d->irq - 32));
63 PIC1_INTOEN |= (1 << (d->irq - 32));
Hans J. Koche9268ef2010-09-17 18:16:29 +020064}
65
66static struct irq_chip tcc8000_irq_chip0 = {
67 .name = "tcc_irq0",
Lennert Buytenhek76fbec82010-11-29 11:14:16 +010068 .irq_mask = tcc8000_mask_irq0,
69 .irq_ack = tcc8000_ack_irq0,
70 .irq_mask_ack = tcc8000_mask_ack_irq0,
71 .irq_unmask = tcc8000_unmask_irq0,
Hans J. Koche9268ef2010-09-17 18:16:29 +020072};
73
74static struct irq_chip tcc8000_irq_chip1 = {
75 .name = "tcc_irq1",
Lennert Buytenhek76fbec82010-11-29 11:14:16 +010076 .irq_mask = tcc8000_mask_irq1,
77 .irq_ack = tcc8000_ack_irq1,
78 .irq_mask_ack = tcc8000_mask_ack_irq1,
79 .irq_unmask = tcc8000_unmask_irq1,
Hans J. Koche9268ef2010-09-17 18:16:29 +020080};
81
82void __init tcc8k_init_irq(void)
83{
84 int irqno;
85
86 /* Mask and clear all interrupts */
87 PIC0_IEN = 0x00000000;
88 PIC0_CREQ = 0xffffffff;
89 PIC1_IEN = 0x00000000;
90 PIC1_CREQ = 0xffffffff;
91
92 PIC0_MEN0 = 0x00000003;
93 PIC1_MEN1 = 0x00000003;
94 PIC1_MEN = 0x00000003;
95
96 /* let all IRQs be level triggered */
97 PIC0_TMODE = 0xffffffff;
98 PIC1_TMODE = 0xffffffff;
99 /* all IRQs are IRQs (not FIQs) */
100 PIC0_IRQSEL = 0xffffffff;
101 PIC1_IRQSEL = 0xffffffff;
102
103 for (irqno = 0; irqno < NR_IRQS; irqno++) {
104 if (irqno < 32)
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100105 irq_set_chip(irqno, &tcc8000_irq_chip0);
Hans J. Koche9268ef2010-09-17 18:16:29 +0200106 else
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100107 irq_set_chip(irqno, &tcc8000_irq_chip1);
108 irq_set_handler(irqno, handle_level_irq);
Hans J. Koche9268ef2010-09-17 18:16:29 +0200109 set_irq_flags(irqno, IRQF_VALID);
110 }
111}