VServer 1.9.2 (patch-2.6.8.1-vs1.9.2.diff)
[linux-2.6.git] / arch / arm / mach-sa1100 / graphicsclient.c
1 /*
2  * linux/arch/arm/mach-sa1100/graphicsclient.c
3  *
4  * Author: Nicolas Pitre
5  *
6  * Pieces specific to the GraphicsClient board
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as
10  * published by the Free Software Foundation.
11  */
12 #include <linux/kernel.h>
13 #include <linux/init.h>
14 #include <linux/ptrace.h>
15
16 #include <asm/hardware.h>
17 #include <asm/setup.h>
18 #include <asm/irq.h>
19
20 #include <asm/mach/irq.h>
21 #include <asm/mach/arch.h>
22 #include <asm/mach/map.h>
23 #include <asm/mach/serial_sa1100.h>
24 #include <linux/serial_core.h>
25
26 #include "generic.h"
27
28
29 /*
30  * Handlers for GraphicsClient's external IRQ logic
31  */
32
33 static void
34 gc_irq_handler(unsigned int irq, struct irqdesc *desc, struct pt_regs *regs)
35 {
36         unsigned int mask;
37
38         while ((mask = ADS_INT_ST1 | (ADS_INT_ST2 << 8))) {
39                 /* clear the parent IRQ */
40                 GEDR = GPIO_GPIO0;
41
42                 irq = ADS_EXT_IRQ(0);
43                 desc = irq_desc + irq;
44
45                 do {
46                         if (mask & 1)
47                                 desc->handle(irq, desc, regs);
48                         mask >>= 1;
49                         irq++;
50                         desc++;
51                 } while (mask);
52         }
53 }
54
55 static void gc_mask_irq1(unsigned int irq)
56 {
57         int mask = (1 << (irq - ADS_EXT_IRQ(0)));
58         ADS_INT_EN1 &= ~mask;
59         ADS_INT_ST1 = mask;
60 }
61
62 static void gc_unmask_irq1(unsigned int irq)
63 {
64         ADS_INT_EN1 |= (1 << (irq - ADS_EXT_IRQ(0)));
65 }
66
67 static struct irqchip gc_irq1_chip = {
68         .ack    = gc_mask_irq1,
69         .mask   = gc_mask_irq1,
70         .unmask = gc_unmask_irq1,
71 };
72
73 static void gc_mask_irq2(unsigned int irq)
74 {
75         int mask = (1 << (irq - ADS_EXT_IRQ(8)));
76         ADS_INT_EN2 &= ~mask;
77         ADS_INT_ST2 = mask;
78 }
79
80 static void gc_unmask_irq2(unsigned int irq)
81 {
82         ADS_INT_EN2 |= (1 << (irq - ADS_EXT_IRQ(8)));
83 }
84
85 static struct irqchip gc_irq2_chip = {
86         .ack    = gc_mask_irq2,
87         .mask   = gc_mask_irq2,
88         .unmask = gc_unmask_irq2,
89 };
90
91 static void __init graphicsclient_init_irq(void)
92 {
93         unsigned int irq;
94
95         /* First the standard SA1100 IRQs */
96         sa1100_init_irq();
97
98         /* disable all IRQs */
99         ADS_INT_EN1 = 0;
100         ADS_INT_EN2 = 0;
101
102         /* clear all IRQs */
103         ADS_INT_ST1 = 0xff;
104         ADS_INT_ST2 = 0xff;
105
106         for (irq = ADS_EXT_IRQ(0); irq <= ADS_EXT_IRQ(7); irq++) {
107                 set_irq_chip(irq, &gc_irq1_chip);
108                 set_irq_handler(irq, do_level_IRQ);
109                 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
110         }
111         for (irq = ADS_EXT_IRQ(8); irq <= ADS_EXT_IRQ(15); irq++) {
112                 set_irq_chip(irq, &gc_irq2_chip);
113                 set_irq_handler(irq, do_level_IRQ);
114                 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
115         }
116         set_irq_type(IRQ_GPIO0, IRQT_FALLING);
117         set_irq_chained_handler(IRQ_GPIO0, gc_irq_handler);
118 }
119
120
121 static struct map_desc graphicsclient_io_desc[] __initdata = {
122  /* virtual     physical    length      type */
123   { 0xf0000000, 0x10000000, 0x00400000, MT_DEVICE }, /* CPLD */
124   { 0xf1000000, 0x18000000, 0x00400000, MT_DEVICE }  /* CAN */
125 };
126
127 static u_int graphicsclient_get_mctrl(struct uart_port *port)
128 {
129         u_int result = TIOCM_CD | TIOCM_DSR;
130
131         if (port->mapbase == _Ser1UTCR0) {
132                 if (!(GPLR & GPIO_GC_UART0_CTS))
133                         result |= TIOCM_CTS;
134         } else if (port->mapbase == _Ser2UTCR0) {
135                 if (!(GPLR & GPIO_GC_UART1_CTS))
136                         result |= TIOCM_CTS;
137         } else if (port->mapbase == _Ser3UTCR0) {
138                 if (!(GPLR & GPIO_GC_UART2_CTS))
139                         result |= TIOCM_CTS;
140         } else {
141                 result = TIOCM_CTS;
142         }
143
144         return result;
145 }
146
147 static void graphicsclient_set_mctrl(struct uart_port *port, u_int mctrl)
148 {
149         if (port->mapbase == _Ser1UTCR0) {
150                 if (mctrl & TIOCM_RTS)
151                         GPCR = GPIO_GC_UART0_RTS;
152                 else
153                         GPSR = GPIO_GC_UART0_RTS;
154         } else if (port->mapbase == _Ser2UTCR0) {
155                 if (mctrl & TIOCM_RTS)
156                         GPCR = GPIO_GC_UART1_RTS;
157                 else
158                         GPSR = GPIO_GC_UART1_RTS;
159         } else if (port->mapbase == _Ser3UTCR0) {
160                 if (mctrl & TIOCM_RTS)
161                         GPCR = GPIO_GC_UART2_RTS;
162                 else
163                         GPSR = GPIO_GC_UART2_RTS;
164         }
165 }
166
167 static void
168 graphicsclient_uart_pm(struct uart_port *port, u_int state, u_int oldstate)
169 {
170         if (!state) {
171                 /* make serial ports work ... */
172                 Ser2UTCR4 = 0;
173                 Ser2HSCR0 = 0; 
174                 Ser1SDCR0 |= SDCR0_UART;
175         }
176 }
177
178 static struct sa1100_port_fns graphicsclient_port_fns __initdata = {
179         .get_mctrl      = graphicsclient_get_mctrl,
180         .set_mctrl      = graphicsclient_set_mctrl,
181         .pm             = graphicsclient_uart_pm,
182 };
183
184 static void __init graphicsclient_map_io(void)
185 {
186         sa1100_map_io();
187         iotable_init(graphicsclient_io_desc, ARRAY_SIZE(graphicsclient_io_desc));
188
189         sa1100_register_uart_fns(&graphicsclient_port_fns);
190         sa1100_register_uart(0, 3);
191         sa1100_register_uart(1, 1);
192         sa1100_register_uart(2, 2);
193         GPDR |= GPIO_GC_UART0_RTS | GPIO_GC_UART1_RTS | GPIO_GC_UART2_RTS;
194         GPDR &= ~(GPIO_GC_UART0_CTS | GPIO_GC_UART1_RTS | GPIO_GC_UART2_RTS);
195 }
196
197 MACHINE_START(GRAPHICSCLIENT, "ADS GraphicsClient")
198         BOOT_MEM(0xc0000000, 0x80000000, 0xf8000000)
199         MAPIO(graphicsclient_map_io)
200         INITIRQ(graphicsclient_init_irq)
201         INITTIME(sa1100_init_time)
202 MACHINE_END