Merge master.kernel.org:/pub/scm/linux/kernel/git/davej/agpgart
[sfrench/cifs-2.6.git] / arch / mips / momentum / ocelot_c / uart-irq.c
1 /*
2  * Copyright 2002 Momentum Computer
3  * Author: mdharm@momenco.com
4  *
5  * arch/mips/momentum/ocelot_c/uart-irq.c
6  *     Interrupt routines for UARTs.  Interrupt numbers are assigned from
7  *     80 to 81 (2 interrupt sources).
8  *
9  * This program is free software; you can redistribute  it and/or modify it
10  * under  the terms of  the GNU General  Public License as published by the
11  * Free Software Foundation;  either version 2 of the  License, or (at your
12  * option) any later version.
13  */
14
15 #include <linux/module.h>
16 #include <linux/interrupt.h>
17 #include <linux/irq.h>
18 #include <linux/kernel.h>
19 #include <linux/sched.h>
20 #include <linux/kernel_stat.h>
21 #include <asm/io.h>
22 #include <asm/irq.h>
23 #include "ocelot_c_fpga.h"
24
25 static inline int ls1bit8(unsigned int x)
26 {
27         int b = 7, s;
28
29         s =  4; if (((unsigned char)(x << 4)) == 0) s = 0; b -= s; x <<= s;
30         s =  2; if (((unsigned char)(x << 2)) == 0) s = 0; b -= s; x <<= s;
31         s =  1; if (((unsigned char)(x << 1)) == 0) s = 0; b -= s;
32
33         return b;
34 }
35
36 /* mask off an interrupt -- 0 is enable, 1 is disable */
37 static inline void mask_uart_irq(unsigned int irq)
38 {
39         uint8_t value;
40
41         value = OCELOT_FPGA_READ(UART_INTMASK);
42         value |= 1 << (irq - 74);
43         OCELOT_FPGA_WRITE(value, UART_INTMASK);
44
45         /* read the value back to assure that it's really been written */
46         value = OCELOT_FPGA_READ(UART_INTMASK);
47 }
48
49 /* unmask an interrupt -- 0 is enable, 1 is disable */
50 static inline void unmask_uart_irq(unsigned int irq)
51 {
52         uint8_t value;
53
54         value = OCELOT_FPGA_READ(UART_INTMASK);
55         value &= ~(1 << (irq - 74));
56         OCELOT_FPGA_WRITE(value, UART_INTMASK);
57
58         /* read the value back to assure that it's really been written */
59         value = OCELOT_FPGA_READ(UART_INTMASK);
60 }
61
62 /*
63  * Enables the IRQ in the FPGA
64  */
65 static void enable_uart_irq(unsigned int irq)
66 {
67         unmask_uart_irq(irq);
68 }
69
70 /*
71  * Initialize the IRQ in the FPGA
72  */
73 static unsigned int startup_uart_irq(unsigned int irq)
74 {
75         unmask_uart_irq(irq);
76         return 0;
77 }
78
79 /*
80  * Disables the IRQ in the FPGA
81  */
82 static void disable_uart_irq(unsigned int irq)
83 {
84         mask_uart_irq(irq);
85 }
86
87 /*
88  * Masks and ACKs an IRQ
89  */
90 static void mask_and_ack_uart_irq(unsigned int irq)
91 {
92         mask_uart_irq(irq);
93 }
94
95 /*
96  * End IRQ processing
97  */
98 static void end_uart_irq(unsigned int irq)
99 {
100         if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
101                 unmask_uart_irq(irq);
102 }
103
104 /*
105  * Interrupt handler for interrupts coming from the FPGA chip.
106  */
107 void ll_uart_irq(void)
108 {
109         unsigned int irq_src, irq_mask;
110
111         /* read the interrupt status registers */
112         irq_src = OCELOT_FPGA_READ(UART_INTSTAT);
113         irq_mask = OCELOT_FPGA_READ(UART_INTMASK);
114
115         /* mask for just the interrupts we want */
116         irq_src &= ~irq_mask;
117
118         do_IRQ(ls1bit8(irq_src) + 74);
119 }
120
121 #define shutdown_uart_irq       disable_uart_irq
122
123 struct irq_chip uart_irq_type = {
124         .typename = "UART/FPGA",
125         .startup = startup_uart_irq,
126         .shutdown = shutdown_uart_irq,
127         .enable = enable_uart_irq,
128         .disable = disable_uart_irq,
129         .ack = mask_and_ack_uart_irq,
130         .end = end_uart_irq,
131 };
132
133 void uart_irq_init(void)
134 {
135         /* Reset irq handlers pointers to NULL */
136         irq_desc[80].status = IRQ_DISABLED;
137         irq_desc[80].action = 0;
138         irq_desc[80].depth = 2;
139         irq_desc[80].chip = &uart_irq_type;
140
141         irq_desc[81].status = IRQ_DISABLED;
142         irq_desc[81].action = 0;
143         irq_desc[81].depth = 2;
144         irq_desc[81].chip = &uart_irq_type;
145 }