blob: c157eeff871d218348e12bcb48f2c3b951e1eaef [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* irq-mb93493.c: MB93493 companion chip interrupt handler
2 *
David Howells1bcbba32006-09-25 23:32:04 -07003 * Copyright (C) 2006 Red Hat, Inc. All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * Written by David Howells (dhowells@redhat.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/ptrace.h>
13#include <linux/errno.h>
14#include <linux/signal.h>
15#include <linux/sched.h>
16#include <linux/ioport.h>
17#include <linux/interrupt.h>
18#include <linux/init.h>
19#include <linux/irq.h>
20
21#include <asm/io.h>
22#include <asm/system.h>
23#include <asm/bitops.h>
24#include <asm/delay.h>
25#include <asm/irq.h>
26#include <asm/irc-regs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <asm/mb93493-irqs.h>
David Howells1bcbba32006-09-25 23:32:04 -070028#include <asm/mb93493-regs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
David Howells1bcbba32006-09-25 23:32:04 -070030#define IRQ_ROUTE_ONE(X) (X##_ROUTE << (X - IRQ_BASE_MB93493))
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
David Howells1bcbba32006-09-25 23:32:04 -070032#define IRQ_ROUTING \
33 (IRQ_ROUTE_ONE(IRQ_MB93493_VDC) | \
34 IRQ_ROUTE_ONE(IRQ_MB93493_VCC) | \
35 IRQ_ROUTE_ONE(IRQ_MB93493_AUDIO_OUT) | \
36 IRQ_ROUTE_ONE(IRQ_MB93493_I2C_0) | \
37 IRQ_ROUTE_ONE(IRQ_MB93493_I2C_1) | \
38 IRQ_ROUTE_ONE(IRQ_MB93493_USB) | \
39 IRQ_ROUTE_ONE(IRQ_MB93493_LOCAL_BUS) | \
40 IRQ_ROUTE_ONE(IRQ_MB93493_PCMCIA) | \
41 IRQ_ROUTE_ONE(IRQ_MB93493_GPIO) | \
42 IRQ_ROUTE_ONE(IRQ_MB93493_AUDIO_IN))
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044/*
David Howells1bcbba32006-09-25 23:32:04 -070045 * daughter board PIC operations
David Howells88d6e192006-09-25 23:32:06 -070046 * - there is no way to ACK interrupts in the MB93493 chip
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 */
David Howells88d6e192006-09-25 23:32:06 -070048static void frv_mb93493_mask(unsigned int irq)
David Howells1bcbba32006-09-25 23:32:04 -070049{
50 uint32_t iqsr;
51 volatile void *piqsr;
52
53 if (IRQ_ROUTING & (1 << (irq - IRQ_BASE_MB93493)))
54 piqsr = __addr_MB93493_IQSR(1);
55 else
56 piqsr = __addr_MB93493_IQSR(0);
57
58 iqsr = readl(piqsr);
59 iqsr &= ~(1 << (irq - IRQ_BASE_MB93493 + 16));
60 writel(iqsr, piqsr);
61}
62
63static void frv_mb93493_ack(unsigned int irq)
64{
65}
66
David Howells88d6e192006-09-25 23:32:06 -070067static void frv_mb93493_unmask(unsigned int irq)
David Howells1bcbba32006-09-25 23:32:04 -070068{
David Howells88d6e192006-09-25 23:32:06 -070069 uint32_t iqsr;
70 volatile void *piqsr;
71
72 if (IRQ_ROUTING & (1 << (irq - IRQ_BASE_MB93493)))
73 piqsr = __addr_MB93493_IQSR(1);
74 else
75 piqsr = __addr_MB93493_IQSR(0);
76
77 iqsr = readl(piqsr);
78 iqsr |= 1 << (irq - IRQ_BASE_MB93493 + 16);
79 writel(iqsr, piqsr);
David Howells1bcbba32006-09-25 23:32:04 -070080}
81
82static struct irq_chip frv_mb93493_pic = {
83 .name = "mb93093",
David Howells1bcbba32006-09-25 23:32:04 -070084 .ack = frv_mb93493_ack,
David Howells88d6e192006-09-25 23:32:06 -070085 .mask = frv_mb93493_mask,
86 .mask_ack = frv_mb93493_mask,
87 .unmask = frv_mb93493_unmask,
Linus Torvalds1da177e2005-04-16 15:20:36 -070088};
89
David Howells1bcbba32006-09-25 23:32:04 -070090/*
91 * MB93493 PIC interrupt handler
92 */
David Howells7d12e782006-10-05 14:55:46 +010093static irqreturn_t mb93493_interrupt(int irq, void *_piqsr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070094{
David Howells1bcbba32006-09-25 23:32:04 -070095 volatile void *piqsr = _piqsr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 uint32_t iqsr;
97
David Howells1bcbba32006-09-25 23:32:04 -070098 iqsr = readl(piqsr);
99 iqsr = iqsr & (iqsr >> 16) & 0xffff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
David Howells1bcbba32006-09-25 23:32:04 -0700101 /* poll all the triggered IRQs */
102 while (iqsr) {
103 int irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
David Howells1bcbba32006-09-25 23:32:04 -0700105 asm("scan %1,gr0,%0" : "=r"(irq) : "r"(iqsr));
106 irq = 31 - irq;
107 iqsr &= ~(1 << irq);
108
David Howells7d12e782006-10-05 14:55:46 +0100109 generic_handle_irq(IRQ_BASE_MB93493 + irq);
David Howells1bcbba32006-09-25 23:32:04 -0700110 }
111
David Howells88d6e192006-09-25 23:32:06 -0700112 return IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113}
114
David Howells1bcbba32006-09-25 23:32:04 -0700115/*
116 * define an interrupt action for each MB93493 PIC output
117 * - use dev_id to indicate the MB93493 PIC input to output mappings
118 */
119static struct irqaction mb93493_irq[2] = {
120 [0] = {
121 .handler = mb93493_interrupt,
122 .flags = IRQF_DISABLED | IRQF_SHARED,
123 .mask = CPU_MASK_NONE,
124 .name = "mb93493.0",
125 .dev_id = (void *) __addr_MB93493_IQSR(0),
126 },
127 [1] = {
128 .handler = mb93493_interrupt,
129 .flags = IRQF_DISABLED | IRQF_SHARED,
130 .mask = CPU_MASK_NONE,
131 .name = "mb93493.1",
132 .dev_id = (void *) __addr_MB93493_IQSR(1),
133 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134};
135
David Howells1bcbba32006-09-25 23:32:04 -0700136/*
137 * initialise the motherboard MB93493's PIC
138 */
139void __init mb93493_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140{
David Howells1bcbba32006-09-25 23:32:04 -0700141 int irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
David Howells1bcbba32006-09-25 23:32:04 -0700143 for (irq = IRQ_BASE_MB93493 + 0; irq <= IRQ_BASE_MB93493 + 10; irq++)
144 set_irq_chip_and_handler(irq, &frv_mb93493_pic, handle_edge_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
David Howells1bcbba32006-09-25 23:32:04 -0700146 /* the MB93493 drives external IRQ inputs on the CPU PIC */
147 setup_irq(IRQ_CPU_MB93493_0, &mb93493_irq[0]);
148 setup_irq(IRQ_CPU_MB93493_1, &mb93493_irq[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149}