irq.c 2.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
 * Copyright (C) Telechips, Inc.
 * Copyright (C) 2009-2010 Hans J. Koch <hjk@linutronix.de>
 *
 * Licensed under the terms of the GNU GPL version 2.
 */

#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/io.h>

#include <asm/irq.h>
#include <asm/mach/irq.h>

#include <mach/tcc8k-regs.h>
#include <mach/irqs.h>

#include "common.h"

/* Disable IRQ */
21
static void tcc8000_mask_ack_irq0(struct irq_data *d)
22
{
23 24
	PIC0_IEN &= ~(1 << d->irq);
	PIC0_CREQ |=  (1 << d->irq);
25 26
}

27
static void tcc8000_mask_ack_irq1(struct irq_data *d)
28
{
29 30
	PIC1_IEN &= ~(1 << (d->irq - 32));
	PIC1_CREQ |= (1 << (d->irq - 32));
31 32
}

33
static void tcc8000_mask_irq0(struct irq_data *d)
34
{
35
	PIC0_IEN &= ~(1 << d->irq);
36 37
}

38
static void tcc8000_mask_irq1(struct irq_data *d)
39
{
40
	PIC1_IEN &= ~(1 << (d->irq - 32));
41 42
}

43
static void tcc8000_ack_irq0(struct irq_data *d)
44
{
45
	PIC0_CREQ |=  (1 << d->irq);
46 47
}

48
static void tcc8000_ack_irq1(struct irq_data *d)
49
{
50
	PIC1_CREQ |= (1 << (d->irq - 32));
51 52 53
}

/* Enable IRQ */
54
static void tcc8000_unmask_irq0(struct irq_data *d)
55
{
56 57
	PIC0_IEN |= (1 << d->irq);
	PIC0_INTOEN |= (1 << d->irq);
58 59
}

60
static void tcc8000_unmask_irq1(struct irq_data *d)
61
{
62 63
	PIC1_IEN |= (1 << (d->irq - 32));
	PIC1_INTOEN |= (1 << (d->irq - 32));
64 65 66 67
}

static struct irq_chip tcc8000_irq_chip0 = {
	.name		= "tcc_irq0",
68 69 70 71
	.irq_mask	= tcc8000_mask_irq0,
	.irq_ack	= tcc8000_ack_irq0,
	.irq_mask_ack	= tcc8000_mask_ack_irq0,
	.irq_unmask	= tcc8000_unmask_irq0,
72 73 74 75
};

static struct irq_chip tcc8000_irq_chip1 = {
	.name		= "tcc_irq1",
76 77 78 79
	.irq_mask	= tcc8000_mask_irq1,
	.irq_ack	= tcc8000_ack_irq1,
	.irq_mask_ack	= tcc8000_mask_ack_irq1,
	.irq_unmask	= tcc8000_unmask_irq1,
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
};

void __init tcc8k_init_irq(void)
{
	int irqno;

	/* Mask and clear all interrupts */
	PIC0_IEN = 0x00000000;
	PIC0_CREQ = 0xffffffff;
	PIC1_IEN = 0x00000000;
	PIC1_CREQ = 0xffffffff;

	PIC0_MEN0 = 0x00000003;
	PIC1_MEN1 = 0x00000003;
	PIC1_MEN = 0x00000003;

	/* let all IRQs be level triggered */
	PIC0_TMODE = 0xffffffff;
	PIC1_TMODE = 0xffffffff;
	/* all IRQs are IRQs (not FIQs) */
	PIC0_IRQSEL = 0xffffffff;
	PIC1_IRQSEL = 0xffffffff;

	for (irqno = 0; irqno < NR_IRQS; irqno++) {
		if (irqno < 32)
			set_irq_chip(irqno, &tcc8000_irq_chip0);
		else
			set_irq_chip(irqno, &tcc8000_irq_chip1);
		set_irq_handler(irqno, handle_level_irq);
		set_irq_flags(irqno, IRQF_VALID);
	}
}