# BRCM_VERSION=3
[bcm963xx.git] / kernel / linux / arch / arm / mach-sa1100 / graphicsmaster.c
1 /*
2  * linux/arch/arm/mach-sa1100/graphicsmaster.c
3  *
4  * Pieces specific to the GraphicsMaster board
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  */
10 #include <linux/kernel.h>
11 #include <linux/init.h>
12 #include <linux/ptrace.h>
13 #include <linux/ioport.h>
14
15 #include <asm/hardware.h>
16 #include <asm/mach-types.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
25 #include "generic.h"
26
27 static struct resource sa1111_resources[] = {
28         [0] = {
29                 .start          = 0x18000000,
30                 .end            = 0x18001fff,
31                 .flags          = IORESOURCE_MEM,
32         },
33         [1] = {
34                 .start          = ADS_EXT_IRQ(0),
35                 .end            = ADS_EXT_IRQ(0),
36                 .flags          = IORESOURCE_IRQ,
37         },
38 };
39
40 static u64 sa1111_dmamask = 0xffffffffUL;
41
42 static struct platform_device sa1111_device = {
43         .name           = "sa1111",
44         .id             = 0,
45         .dev            = {
46                 .dma_mask = &sa1111_dmamask,
47                 .coherent_dma_mask = 0xffffffff,
48         },
49         .num_resources  = ARRAY_SIZE(sa1111_resources),
50         .resource       = sa1111_resources,
51 };
52
53 static struct platform_device *devices[] __initdata = {
54         &sa1111_device,
55 };
56
57 static int __init graphicsmaster_init(void)
58 {
59         int ret;
60
61         if (!machine_is_graphicsmaster())
62                 return -ENODEV;
63
64         /*
65          * Ensure that the memory bus request/grant signals are setup,
66          * and the grant is held in its inactive state
67          */
68         sa1110_mb_disable();
69
70         /*
71          * Probe for SA1111.
72          */
73         ret = platform_add_devices(devices, ARRAY_SIZE(devices));
74         if (ret < 0)
75                 return ret;
76
77         /*
78          * Enable PWM control for LCD
79          */
80         sa1111_enable_device(SKPCR_PWMCLKEN);
81         SKPWM0 = 0x7F;                          // VEE
82         SKPEN0 = 1;
83         SKPWM1 = 0x01;                          // Backlight
84         SKPEN1 = 1;
85
86         return 0;
87 }
88
89 arch_initcall(graphicsmaster_init);
90
91 /*
92  * Handlers for GraphicsMaster's external IRQ logic
93  */
94
95 static void
96 gm_irq_handler(unsigned int irq, struct irqdesc *desc, struct pt_regs *regs)
97 {
98         unsigned int mask;
99
100         while ((mask = ADS_INT_ST1 | (ADS_INT_ST2 << 8))) {
101                 /* clear the parent IRQ */
102                 GEDR = GPIO_GPIO0;
103
104                 irq = ADS_EXT_IRQ(0);
105                 desc = irq_desc + irq;
106
107                 do {
108                         if (mask & 1)
109                                 desc->handle(irq, desc, regs);
110                         mask >>= 1;
111                         irq++;
112                         desc++;
113                 } while (mask);
114         }
115 }
116
117 static void gm_mask_irq1(unsigned int irq)
118 {
119         int mask = (1 << (irq - ADS_EXT_IRQ(0)));
120         ADS_INT_EN1 &= ~mask;
121         ADS_INT_ST1 = mask;
122 }
123
124 static void gm_unmask_irq1(unsigned int irq)
125 {
126         ADS_INT_EN1 |= (1 << (irq - ADS_EXT_IRQ(0)));
127 }
128
129 static struct irqchip gm_irq1_chip = {
130         .ack    = gm_mask_irq1,
131         .mask   = gm_mask_irq1,
132         .unmask = gm_unmask_irq1,
133 };
134
135 static void gm_mask_irq2(unsigned int irq)
136 {
137         int mask = (1 << (irq - ADS_EXT_IRQ(8)));
138         ADS_INT_EN2 &= ~mask;
139         ADS_INT_ST2 = mask;
140 }
141
142 static void gm_unmask_irq2(unsigned int irq)
143 {
144         ADS_INT_EN2 |= (1 << (irq - ADS_EXT_IRQ(8)));
145 }
146
147 static struct irqchip gm_irq2_chip = {
148         .ack    = gm_mask_irq2,
149         .mask   = gm_mask_irq2,
150         .unmask = gm_unmask_irq2,
151 };
152
153 static void __init graphicsmaster_init_irq(void)
154 {
155         unsigned int irq;
156
157         /* First the standard SA1100 IRQs */
158         sa1100_init_irq();
159
160         /* disable all IRQs */
161         ADS_INT_EN1 = 0;
162         ADS_INT_EN2 = 0;
163
164         /* clear all IRQs */
165         ADS_INT_ST1 = 0xff;
166         ADS_INT_ST2 = 0xff;
167
168         for (irq = ADS_EXT_IRQ(0); irq <= ADS_EXT_IRQ(7); irq++) {
169                 set_irq_chip(irq, &gm_irq1_chip);
170                 set_irq_handler(irq, do_level_IRQ);
171                 set_irq_flags(irq, IRQF_PROBE | IRQF_VALID);
172         }
173         for (irq = ADS_EXT_IRQ(8); irq <= ADS_EXT_IRQ(15); irq++) {
174                 set_irq_chip(irq, &gm_irq2_chip);
175                 set_irq_handler(irq, do_level_IRQ);
176                 set_irq_flags(irq, IRQF_PROBE | IRQF_VALID);
177         }
178         set_irq_type(IRQ_GPIO0, IRQT_FALLING);
179         set_irq_chained_handler(IRQ_GPIO0, gm_irq_handler);
180 }
181
182
183 static struct map_desc graphicsmaster_io_desc[] __initdata = {
184  /* virtual     physical    length      type */
185   { 0xf0000000, 0x10000000, 0x00400000, MT_DEVICE }, /* CPLD */
186   { 0xf1000000, 0x40000000, 0x00400000, MT_DEVICE }, /* CAN */
187   { 0xf4000000, 0x18000000, 0x00800000, MT_DEVICE }  /* SA-1111 */
188 };
189
190 #error Old code.  Someone needs to decide what to do about this.
191 #if 0
192 static int graphicsmaster_uart_open(struct uart_port *port, struct uart_info *info)
193 {
194         int     ret = 0;
195
196         if (port->mapbase == _Ser1UTCR0) {
197                 Ser1SDCR0 |= SDCR0_UART;
198                 /* Set RTS Output */
199                 GPSR = GPIO_GPIO15;
200         }
201         else if (port->mapbase == _Ser2UTCR0) {
202                 Ser2UTCR4 = Ser2HSCR0 = 0;
203                 /* Set RTS Output */
204                 GPSR = GPIO_GPIO17;
205         }
206         else if (port->mapbase == _Ser3UTCR0) {
207                 /* Set RTS Output */
208                 GPSR = GPIO_GPIO19;
209         }
210         return ret;
211 }
212 #endif
213
214 static u_int graphicsmaster_get_mctrl(struct uart_port *port)
215 {
216         u_int result = TIOCM_CD | TIOCM_DSR;
217
218         if (port->mapbase == _Ser1UTCR0) {
219                 if (!(GPLR & GPIO_GPIO14))
220                         result |= TIOCM_CTS;
221         } else if (port->mapbase == _Ser2UTCR0) {
222                 if (!(GPLR & GPIO_GPIO16))
223                         result |= TIOCM_CTS;
224         } else if (port->mapbase == _Ser3UTCR0) {
225                 if (!(GPLR & GPIO_GPIO17))
226                         result |= TIOCM_CTS;
227         } else {
228                 result = TIOCM_CTS;
229         }
230
231         return result;
232 }
233
234 static void graphicsmaster_set_mctrl(struct uart_port *port, u_int mctrl)
235 {
236         if (port->mapbase == _Ser1UTCR0) {
237                 if (mctrl & TIOCM_RTS)
238                         GPCR = GPIO_GPIO15;
239                 else
240                         GPSR = GPIO_GPIO15;
241         } else if (port->mapbase == _Ser2UTCR0) {
242                 if (mctrl & TIOCM_RTS)
243                         GPCR = GPIO_GPIO17;
244                 else
245                         GPSR = GPIO_GPIO17;
246         } else if (port->mapbase == _Ser3UTCR0) {
247                 if (mctrl & TIOCM_RTS)
248                         GPCR = GPIO_GPIO19;
249                 else
250                         GPSR = GPIO_GPIO19;
251         }
252 }
253
254 static void
255 graphicsmaster_uart_pm(struct uart_port *port, u_int state, u_int oldstate)
256 {
257         if (!state) {
258                 /* make serial ports work ... */
259                 Ser2UTCR4 = 0;
260                 Ser2HSCR0 = 0; 
261                 Ser1SDCR0 |= SDCR0_UART;
262         }
263 }
264
265 static struct sa1100_port_fns graphicsmaster_port_fns __initdata = {
266         .get_mctrl      = graphicsmaster_get_mctrl,
267         .set_mctrl      = graphicsmaster_set_mctrl,
268         .pm             = graphicsmaster_uart_pm,
269 };
270
271 static void __init graphicsmaster_map_io(void)
272 {
273         sa1100_map_io();
274         iotable_init(graphicsmaster_io_desc, ARRAY_SIZE(graphicsmaster_io_desc));
275
276         sa1100_register_uart_fns(&graphicsmaster_port_fns);
277         sa1100_register_uart(0, 3);
278         sa1100_register_uart(1, 1);
279         sa1100_register_uart(2, 2);
280
281         /* set GPDR now */
282         GPDR |= GPIO_GPIO15 | GPIO_GPIO17 | GPIO_GPIO19;
283         GPDR &= ~(GPIO_GPIO14 | GPIO_GPIO16 | GPIO_GPIO18);
284 }
285
286 MACHINE_START(GRAPHICSMASTER, "ADS GraphicsMaster")
287         BOOT_MEM(0xc0000000, 0x80000000, 0xf8000000)
288         MAPIO(graphicsmaster_map_io)
289         INITIRQ(graphicsmaster_init_irq)
290         INITTIME(sa1100_init_time)
291 MACHINE_END