import of upstream 2.4.34.4 from kernel.org
[linux-2.4.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
13 #include <linux/init.h>
14 #include <linux/sched.h>
15 #include <linux/interrupt.h>
16 #include <linux/ptrace.h>
17 #include <linux/list.h>
18 #include <linux/timer.h>
19
20 #include <asm/hardware.h>
21 #include <asm/setup.h>
22 #include <asm/irq.h>
23
24 #include <asm/mach/irq.h>
25 #include <asm/mach/arch.h>
26 #include <asm/mach/map.h>
27 #include <asm/mach/serial_sa1100.h>
28 #include <linux/serial_core.h>
29
30 #include <asm/arch/irq.h>
31
32 #include "generic.h"
33
34
35 /*
36  * Handlers for GraphicsClient's external IRQ logic
37  */
38
39 #define GRAPHICSCLIENT_N_IRQ     (IRQ_GRAPHICSCLIENT_END - IRQ_GRAPHICSCLIENT_START)
40 #define GRAPHICSCLIENT_FIRST_IRQ (IRQ_GRAPHICSCLIENT_CAN - IRQ_GRAPHICSCLIENT_START)
41
42 static void ADS_IRQ_demux( int irq, void *dev_id, struct pt_regs *regs )
43 {
44         int i;
45
46         while( (irq = ADS_INT_ST1 | (ADS_INT_ST2 << 8)) ){
47                 for( i = GRAPHICSCLIENT_FIRST_IRQ; i < GRAPHICSCLIENT_N_IRQ; i++ )
48                         if( irq & (1<<i) )
49                                 do_IRQ( IRQ_GRAPHICSCLIENT_START + i, regs );
50         }
51 }
52
53 static struct irqaction ADS_ext_irq = {
54         .name           = "ADS_ext_IRQ",
55         .handler        = ADS_IRQ_demux,
56         .flags          = SA_INTERRUPT
57 };
58
59 static void ADS_mask_and_ack_irq0(unsigned int irq)
60 {
61         int mask = (1 << (irq - IRQ_GRAPHICSCLIENT_START));
62         ADS_INT_EN1 &= ~mask;
63         ADS_INT_ST1 = mask;
64 }
65
66 static void ADS_mask_irq0(unsigned int irq)
67 {
68         ADS_INT_ST1 = (1 << (irq - IRQ_GRAPHICSCLIENT_START));
69 }
70
71 static void ADS_unmask_irq0(unsigned int irq)
72 {
73         ADS_INT_EN1 |= (1 << (irq - IRQ_GRAPHICSCLIENT_START));
74 }
75
76 static void ADS_mask_and_ack_irq1(unsigned int irq)
77 {
78         int mask = (1 << (irq - (IRQ_GRAPHICSCLIENT_UCB1200)));
79         ADS_INT_EN2 &= ~mask;
80         ADS_INT_ST2 = mask;
81 }
82
83 static void ADS_mask_irq1(unsigned int irq)
84 {
85         ADS_INT_ST2 = (1 << (irq - (IRQ_GRAPHICSCLIENT_UCB1200)));
86 }
87
88 static void ADS_unmask_irq1(unsigned int irq)
89 {
90         ADS_INT_EN2 |= (1 << (irq - (IRQ_GRAPHICSCLIENT_UCB1200)));
91 }
92
93 static void __init graphicsclient_init_irq(void)
94 {
95         int irq;
96
97         /* First the standard SA1100 IRQs */
98         sa1100_init_irq();
99
100         /* disable all IRQs */
101         ADS_INT_EN1 = 0;
102         ADS_INT_EN2 = 0;
103         /* clear all IRQs */
104         ADS_INT_ST1 = 0xff;
105         ADS_INT_ST2 = 0xff;
106
107         // Set RTS low during sleep
108         PGSR |= GPIO_GPIO15 | GPIO_GPIO17 | GPIO_GPIO19;
109
110         for (irq = IRQ_GRAPHICSCLIENT_START; irq < IRQ_GRAPHICSCLIENT_UCB1200; irq++) {
111                 irq_desc[irq].valid     = 1;
112                 irq_desc[irq].probe_ok  = 1;
113                 irq_desc[irq].mask_ack  = ADS_mask_and_ack_irq0;
114                 irq_desc[irq].mask      = ADS_mask_irq0;
115                 irq_desc[irq].unmask    = ADS_unmask_irq0;
116         }
117         for (irq = IRQ_GRAPHICSCLIENT_UCB1200; irq < IRQ_GRAPHICSCLIENT_END; irq++) {
118                 irq_desc[irq].valid     = 1;
119                 irq_desc[irq].probe_ok  = 1;
120                 irq_desc[irq].mask_ack  = ADS_mask_and_ack_irq1;
121                 irq_desc[irq].mask      = ADS_mask_irq1;
122                 irq_desc[irq].unmask    = ADS_unmask_irq1;
123         }
124         set_GPIO_IRQ_edge(GPIO_GPIO0, GPIO_FALLING_EDGE);
125         setup_arm_irq( IRQ_GPIO0, &ADS_ext_irq );
126 }
127
128 static struct map_desc graphicsclient_io_desc[] __initdata = {
129  /* virtual     physical    length      domain     r  w  c  b */
130   { 0xe8000000, 0x08000000, 0x02000000, DOMAIN_IO, 0, 1, 0, 0 }, /* Flash bank 1 */
131   { 0xf0000000, 0x10000000, 0x00400000, DOMAIN_IO, 0, 1, 0, 0 }, /* CPLD */
132   { 0xf1000000, 0x18000000, 0x00400000, DOMAIN_IO, 0, 1, 0, 0 }, /* CAN */
133   LAST_DESC
134 };
135
136 static int graphicsclient_uart_open(struct uart_port *port, struct uart_info *info)
137 {
138         int     ret = 0;
139
140         if (port->mapbase == _Ser1UTCR0) {
141                 Ser1SDCR0 |= SDCR0_UART;
142         }
143         else if (port->mapbase == _Ser2UTCR0) {
144                 Ser2UTCR4 = Ser2HSCR0 = 0;
145         }
146         return ret;
147 }
148
149 static u_int graphicsclient_get_mctrl(struct uart_port *port)
150 {
151         u_int result = TIOCM_CD | TIOCM_DSR;
152
153         if (port->mapbase == _Ser1UTCR0) {
154                 if (!(GPLR & GPIO_GPIO14))
155                         result |= TIOCM_CTS;
156         } else if (port->mapbase == _Ser2UTCR0) {
157                 if (!(GPLR & GPIO_GPIO16))
158                         result |= TIOCM_CTS;
159         } else if (port->mapbase == _Ser3UTCR0) {
160                 if (!(GPLR & GPIO_GPIO18))
161                         result |= TIOCM_CTS;
162         } else {
163                 result = TIOCM_CTS;
164         }
165
166         return result;
167 }
168
169 static void graphicsclient_set_mctrl(struct uart_port *port, u_int mctrl)
170 {
171         if (port->mapbase == _Ser1UTCR0) {
172                 if (mctrl & TIOCM_RTS)
173                         GPCR = GPIO_GPIO15;
174                 else
175                         GPSR = GPIO_GPIO15;
176         } else if (port->mapbase == _Ser2UTCR0) {
177                 if (mctrl & TIOCM_RTS)
178                         GPCR = GPIO_GPIO17;
179                 else
180                         GPSR = GPIO_GPIO17;
181         } else if (port->mapbase == _Ser3UTCR0) {
182                 if (mctrl & TIOCM_RTS)
183                         GPCR = GPIO_GPIO19;
184                 else
185                         GPSR = GPIO_GPIO19;
186         }
187 }
188
189 static void
190 graphicsclient_uart_pm(struct uart_port *port, u_int state, u_int oldstate)
191 {
192         // state has ACPI D0-D3
193         // ACPI D0        : resume from suspend
194         // ACPI D1-D3 : enter to a suspend state
195         if (port->mapbase == _Ser1UTCR0) {
196                 if (state) {
197                         // disable uart
198                         Ser1UTCR3 = 0;
199                 }
200         }
201         else if (port->mapbase == _Ser2UTCR0) {
202                 if (state) {
203                         // disable uart
204                         Ser2UTCR3 = 0;
205                         Ser2HSCR0 = 0;
206                 }
207         }
208         else if (port->mapbase == _Ser3UTCR0) {
209                 if (state) {
210                         // disable uart
211                         Ser3UTCR3 = 0;
212                 }
213         }
214 }
215
216 static struct sa1100_port_fns graphicsclient_port_fns __initdata = {
217         .open           = graphicsclient_uart_open,
218         .get_mctrl      = graphicsclient_get_mctrl,
219         .set_mctrl      = graphicsclient_set_mctrl,
220         .pm             = graphicsclient_uart_pm,
221 };
222
223 static void __init graphicsclient_map_io(void)
224 {
225         sa1100_map_io();
226         iotable_init(graphicsclient_io_desc);
227
228         sa1100_register_uart_fns(&graphicsclient_port_fns);
229         sa1100_register_uart(0, 3);
230         sa1100_register_uart(1, 1);
231
232         // don't register if you want to use IRDA
233 #ifndef CONFIG_SA1100_FIR
234         sa1100_register_uart(2, 2);
235 #endif
236
237         /* set GPDR now */
238         GPDR |= GPIO_GPIO15 | GPIO_GPIO17 | GPIO_GPIO19;
239         GPDR &= ~(GPIO_GPIO14 | GPIO_GPIO16 | GPIO_GPIO18);
240 }
241
242 MACHINE_START(GRAPHICSCLIENT, "ADS GraphicsClient")
243         BOOT_PARAMS(0xc000003c)
244         BOOT_MEM(0xc0000000, 0x80000000, 0xf8000000)
245         MAPIO(graphicsclient_map_io)
246         INITIRQ(graphicsclient_init_irq)
247 MACHINE_END