blob: ba648da0932daec3fc71da4feec67ac660a31e12 [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>
Jiri Slaby1977f032007-10-18 23:40:25 -070020#include <linux/bitops.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
22#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <asm/delay.h>
24#include <asm/irq.h>
25#include <asm/irc-regs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <asm/mb93493-irqs.h>
David Howells1bcbba32006-09-25 23:32:04 -070027#include <asm/mb93493-regs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
David Howells1bcbba32006-09-25 23:32:04 -070029#define IRQ_ROUTE_ONE(X) (X##_ROUTE << (X - IRQ_BASE_MB93493))
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
David Howells1bcbba32006-09-25 23:32:04 -070031#define IRQ_ROUTING \
32 (IRQ_ROUTE_ONE(IRQ_MB93493_VDC) | \
33 IRQ_ROUTE_ONE(IRQ_MB93493_VCC) | \
34 IRQ_ROUTE_ONE(IRQ_MB93493_AUDIO_OUT) | \
35 IRQ_ROUTE_ONE(IRQ_MB93493_I2C_0) | \
36 IRQ_ROUTE_ONE(IRQ_MB93493_I2C_1) | \
37 IRQ_ROUTE_ONE(IRQ_MB93493_USB) | \
38 IRQ_ROUTE_ONE(IRQ_MB93493_LOCAL_BUS) | \
39 IRQ_ROUTE_ONE(IRQ_MB93493_PCMCIA) | \
40 IRQ_ROUTE_ONE(IRQ_MB93493_GPIO) | \
41 IRQ_ROUTE_ONE(IRQ_MB93493_AUDIO_IN))
42
Linus Torvalds1da177e2005-04-16 15:20:36 -070043/*
David Howells1bcbba32006-09-25 23:32:04 -070044 * daughter board PIC operations
David Howells88d6e192006-09-25 23:32:06 -070045 * - there is no way to ACK interrupts in the MB93493 chip
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 */
Thomas Gleixnera55174f2011-02-06 20:20:37 +010047static void frv_mb93493_mask(struct irq_data *d)
David Howells1bcbba32006-09-25 23:32:04 -070048{
49 uint32_t iqsr;
50 volatile void *piqsr;
51
Thomas Gleixnera55174f2011-02-06 20:20:37 +010052 if (IRQ_ROUTING & (1 << (d->irq - IRQ_BASE_MB93493)))
David Howells1bcbba32006-09-25 23:32:04 -070053 piqsr = __addr_MB93493_IQSR(1);
54 else
55 piqsr = __addr_MB93493_IQSR(0);
56
57 iqsr = readl(piqsr);
Thomas Gleixnera55174f2011-02-06 20:20:37 +010058 iqsr &= ~(1 << (d->irq - IRQ_BASE_MB93493 + 16));
David Howells1bcbba32006-09-25 23:32:04 -070059 writel(iqsr, piqsr);
60}
61
Thomas Gleixnera55174f2011-02-06 20:20:37 +010062static void frv_mb93493_ack(struct irq_data *d)
David Howells1bcbba32006-09-25 23:32:04 -070063{
64}
65
Thomas Gleixnera55174f2011-02-06 20:20:37 +010066static void frv_mb93493_unmask(struct irq_data *d)
David Howells1bcbba32006-09-25 23:32:04 -070067{
David Howells88d6e192006-09-25 23:32:06 -070068 uint32_t iqsr;
69 volatile void *piqsr;
70
Thomas Gleixnera55174f2011-02-06 20:20:37 +010071 if (IRQ_ROUTING & (1 << (d->irq - IRQ_BASE_MB93493)))
David Howells88d6e192006-09-25 23:32:06 -070072 piqsr = __addr_MB93493_IQSR(1);
73 else
74 piqsr = __addr_MB93493_IQSR(0);
75
76 iqsr = readl(piqsr);
Thomas Gleixnera55174f2011-02-06 20:20:37 +010077 iqsr |= 1 << (d->irq - IRQ_BASE_MB93493 + 16);
David Howells88d6e192006-09-25 23:32:06 -070078 writel(iqsr, piqsr);
David Howells1bcbba32006-09-25 23:32:04 -070079}
80
81static struct irq_chip frv_mb93493_pic = {
82 .name = "mb93093",
Thomas Gleixnera55174f2011-02-06 20:20:37 +010083 .irq_ack = frv_mb93493_ack,
84 .irq_mask = frv_mb93493_mask,
85 .irq_mask_ack = frv_mb93493_mask,
86 .irq_unmask = frv_mb93493_unmask,
Linus Torvalds1da177e2005-04-16 15:20:36 -070087};
88
David Howells1bcbba32006-09-25 23:32:04 -070089/*
90 * MB93493 PIC interrupt handler
91 */
David Howells7d12e782006-10-05 14:55:46 +010092static irqreturn_t mb93493_interrupt(int irq, void *_piqsr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070093{
David Howells1bcbba32006-09-25 23:32:04 -070094 volatile void *piqsr = _piqsr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 uint32_t iqsr;
96
David Howells1bcbba32006-09-25 23:32:04 -070097 iqsr = readl(piqsr);
98 iqsr = iqsr & (iqsr >> 16) & 0xffff;
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
David Howells1bcbba32006-09-25 23:32:04 -0700100 /* poll all the triggered IRQs */
101 while (iqsr) {
102 int irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
David Howells1bcbba32006-09-25 23:32:04 -0700104 asm("scan %1,gr0,%0" : "=r"(irq) : "r"(iqsr));
105 irq = 31 - irq;
106 iqsr &= ~(1 << irq);
107
David Howells7d12e782006-10-05 14:55:46 +0100108 generic_handle_irq(IRQ_BASE_MB93493 + irq);
David Howells1bcbba32006-09-25 23:32:04 -0700109 }
110
David Howells88d6e192006-09-25 23:32:06 -0700111 return IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112}
113
David Howells1bcbba32006-09-25 23:32:04 -0700114/*
115 * define an interrupt action for each MB93493 PIC output
116 * - use dev_id to indicate the MB93493 PIC input to output mappings
117 */
118static struct irqaction mb93493_irq[2] = {
119 [0] = {
120 .handler = mb93493_interrupt,
121 .flags = IRQF_DISABLED | IRQF_SHARED,
David Howells1bcbba32006-09-25 23:32:04 -0700122 .name = "mb93493.0",
123 .dev_id = (void *) __addr_MB93493_IQSR(0),
124 },
125 [1] = {
126 .handler = mb93493_interrupt,
127 .flags = IRQF_DISABLED | IRQF_SHARED,
David Howells1bcbba32006-09-25 23:32:04 -0700128 .name = "mb93493.1",
129 .dev_id = (void *) __addr_MB93493_IQSR(1),
130 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131};
132
David Howells1bcbba32006-09-25 23:32:04 -0700133/*
134 * initialise the motherboard MB93493's PIC
135 */
136void __init mb93493_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137{
David Howells1bcbba32006-09-25 23:32:04 -0700138 int irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
David Howells1bcbba32006-09-25 23:32:04 -0700140 for (irq = IRQ_BASE_MB93493 + 0; irq <= IRQ_BASE_MB93493 + 10; irq++)
Thomas Gleixnerde2e95a2011-03-24 16:38:49 +0100141 irq_set_chip_and_handler(irq, &frv_mb93493_pic,
142 handle_edge_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
David Howells1bcbba32006-09-25 23:32:04 -0700144 /* the MB93493 drives external IRQ inputs on the CPU PIC */
145 setup_irq(IRQ_CPU_MB93493_0, &mb93493_irq[0]);
146 setup_irq(IRQ_CPU_MB93493_1, &mb93493_irq[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147}