ARM: 7342/2: sa1100: prepare for sparse irq conversion
[cascardo/linux.git] / arch / arm / mach-sa1100 / badge4.c
1 /*
2  * linux/arch/arm/mach-sa1100/badge4.c
3  *
4  * BadgePAD 4 specific initialization
5  *
6  *   Tim Connors <connors@hpl.hp.com>
7  *   Christopher Hoover <ch@hpl.hp.com>
8  *
9  * Copyright (C) 2002 Hewlett-Packard Company
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License version 2 as
13  * published by the Free Software Foundation.
14  *
15  */
16 #include <linux/module.h>
17 #include <linux/init.h>
18 #include <linux/kernel.h>
19 #include <linux/platform_device.h>
20 #include <linux/delay.h>
21 #include <linux/tty.h>
22 #include <linux/mtd/mtd.h>
23 #include <linux/mtd/partitions.h>
24 #include <linux/errno.h>
25
26 #include <mach/hardware.h>
27 #include <asm/mach-types.h>
28 #include <asm/setup.h>
29 #include <mach/irqs.h>
30
31 #include <asm/mach/arch.h>
32 #include <asm/mach/flash.h>
33 #include <asm/mach/map.h>
34 #include <asm/hardware/sa1111.h>
35 #include <asm/mach/serial_sa1100.h>
36
37 #include <mach/badge4.h>
38
39 #include "generic.h"
40
41 static struct resource sa1111_resources[] = {
42         [0] = DEFINE_RES_MEM(BADGE4_SA1111_BASE, 0x2000),
43         [1] = DEFINE_RES_IRQ(BADGE4_IRQ_GPIO_SA1111),
44 };
45
46 static int badge4_sa1111_enable(void *data, unsigned devid)
47 {
48         if (devid == SA1111_DEVID_USB)
49                 badge4_set_5V(BADGE4_5V_USB, 1);
50         return 0;
51 }
52
53 static void badge4_sa1111_disable(void *data, unsigned devid)
54 {
55         if (devid == SA1111_DEVID_USB)
56                 badge4_set_5V(BADGE4_5V_USB, 0);
57 }
58
59 static struct sa1111_platform_data sa1111_info = {
60         .irq_base       = IRQ_BOARD_END,
61         .disable_devs   = SA1111_DEVID_PS2_MSE,
62         .enable         = badge4_sa1111_enable,
63         .disable        = badge4_sa1111_disable,
64 };
65
66 static u64 sa1111_dmamask = 0xffffffffUL;
67
68 static struct platform_device sa1111_device = {
69         .name           = "sa1111",
70         .id             = 0,
71         .dev            = {
72                 .dma_mask = &sa1111_dmamask,
73                 .coherent_dma_mask = 0xffffffff,
74                 .platform_data = &sa1111_info,
75         },
76         .num_resources  = ARRAY_SIZE(sa1111_resources),
77         .resource       = sa1111_resources,
78 };
79
80 static struct platform_device *devices[] __initdata = {
81         &sa1111_device,
82 };
83
84 static int __init badge4_sa1111_init(void)
85 {
86         /*
87          * Ensure that the memory bus request/grant signals are setup,
88          * and the grant is held in its inactive state
89          */
90         sa1110_mb_disable();
91
92         /*
93          * Probe for SA1111.
94          */
95         return platform_add_devices(devices, ARRAY_SIZE(devices));
96 }
97
98
99 /*
100  * 1 x Intel 28F320C3 Advanced+ Boot Block Flash (32 Mi bit)
101  *   Eight 4 KiW Parameter Bottom Blocks (64 KiB)
102  *   Sixty-three 32 KiW Main Blocks (4032 Ki b)
103  *
104  * <or>
105  *
106  * 1 x Intel 28F640C3 Advanced+ Boot Block Flash (64 Mi bit)
107  *   Eight 4 KiW Parameter Bottom Blocks (64 KiB)
108  *   One-hundred-twenty-seven 32 KiW Main Blocks (8128 Ki b)
109  */
110 static struct mtd_partition badge4_partitions[] = {
111         {
112                 .name   = "BLOB boot loader",
113                 .offset = 0,
114                 .size   = 0x0000A000
115         }, {
116                 .name   = "params",
117                 .offset = MTDPART_OFS_APPEND,
118                 .size   = 0x00006000
119         }, {
120                 .name   = "root",
121                 .offset = MTDPART_OFS_APPEND,
122                 .size   = MTDPART_SIZ_FULL
123         }
124 };
125
126 static struct flash_platform_data badge4_flash_data = {
127         .map_name       = "cfi_probe",
128         .parts          = badge4_partitions,
129         .nr_parts       = ARRAY_SIZE(badge4_partitions),
130 };
131
132 static struct resource badge4_flash_resource =
133         DEFINE_RES_MEM(SA1100_CS0_PHYS, SZ_64M);
134
135 static int five_v_on __initdata = 0;
136
137 static int __init five_v_on_setup(char *ignore)
138 {
139         five_v_on = 1;
140         return 1;
141 }
142 __setup("five_v_on", five_v_on_setup);
143
144
145 static int __init badge4_init(void)
146 {
147         int ret;
148
149         if (!machine_is_badge4())
150                 return -ENODEV;
151
152         /* LCD */
153         GPCR  = (BADGE4_GPIO_LGP2 | BADGE4_GPIO_LGP3 |
154                  BADGE4_GPIO_LGP4 | BADGE4_GPIO_LGP5 |
155                  BADGE4_GPIO_LGP6 | BADGE4_GPIO_LGP7 |
156                  BADGE4_GPIO_LGP8 | BADGE4_GPIO_LGP9 |
157                  BADGE4_GPIO_GPA_VID | BADGE4_GPIO_GPB_VID |
158                  BADGE4_GPIO_GPC_VID);
159         GPDR &= ~BADGE4_GPIO_INT_VID;
160         GPDR |= (BADGE4_GPIO_LGP2 | BADGE4_GPIO_LGP3 |
161                  BADGE4_GPIO_LGP4 | BADGE4_GPIO_LGP5 |
162                  BADGE4_GPIO_LGP6 | BADGE4_GPIO_LGP7 |
163                  BADGE4_GPIO_LGP8 | BADGE4_GPIO_LGP9 |
164                  BADGE4_GPIO_GPA_VID | BADGE4_GPIO_GPB_VID |
165                  BADGE4_GPIO_GPC_VID);
166
167         /* SDRAM SPD i2c */
168         GPCR  = (BADGE4_GPIO_SDSDA | BADGE4_GPIO_SDSCL);
169         GPDR |= (BADGE4_GPIO_SDSDA | BADGE4_GPIO_SDSCL);
170
171         /* uart */
172         GPCR  = (BADGE4_GPIO_UART_HS1 | BADGE4_GPIO_UART_HS2);
173         GPDR |= (BADGE4_GPIO_UART_HS1 | BADGE4_GPIO_UART_HS2);
174
175         /* CPLD muxsel0 input for mux/adc chip select */
176         GPCR  = BADGE4_GPIO_MUXSEL0;
177         GPDR |= BADGE4_GPIO_MUXSEL0;
178
179         /* test points: J5, J6 as inputs, J7 outputs */
180         GPDR &= ~(BADGE4_GPIO_TESTPT_J5 | BADGE4_GPIO_TESTPT_J6);
181         GPCR  = BADGE4_GPIO_TESTPT_J7;
182         GPDR |= BADGE4_GPIO_TESTPT_J7;
183
184         /* 5V supply rail. */
185         GPCR  = BADGE4_GPIO_PCMEN5V;            /* initially off */
186         GPDR |= BADGE4_GPIO_PCMEN5V;
187
188         /* CPLD sdram type inputs; set up by blob */
189         //GPDR |= (BADGE4_GPIO_SDTYP1 | BADGE4_GPIO_SDTYP0);
190         printk(KERN_DEBUG __FILE__ ": SDRAM CPLD typ1=%d typ0=%d\n",
191                 !!(GPLR & BADGE4_GPIO_SDTYP1),
192                 !!(GPLR & BADGE4_GPIO_SDTYP0));
193
194         /* SA1111 reset pin; set up by blob */
195         //GPSR  = BADGE4_GPIO_SA1111_NRST;
196         //GPDR |= BADGE4_GPIO_SA1111_NRST;
197
198
199         /* power management cruft */
200         PGSR = 0;
201         PWER = 0;
202         PCFR = 0;
203         PSDR = 0;
204
205         PWER |= PWER_GPIO26;    /* wake up on an edge from TESTPT_J5 */
206         PWER |= PWER_RTC;       /* wake up if rtc fires */
207
208         /* drive sa1111_nrst during sleep */
209         PGSR |= BADGE4_GPIO_SA1111_NRST;
210         /* drive CPLD as is during sleep */
211         PGSR |= (GPLR & (BADGE4_GPIO_SDTYP0|BADGE4_GPIO_SDTYP1));
212
213
214         /* Now bring up the SA-1111. */
215         ret = badge4_sa1111_init();
216         if (ret < 0)
217                 printk(KERN_ERR
218                         "%s: SA-1111 initialization failed (%d)\n",
219                         __func__, ret);
220
221
222         /* maybe turn on 5v0 from the start */
223         badge4_set_5V(BADGE4_5V_INITIALLY, five_v_on);
224
225         sa11x0_register_mtd(&badge4_flash_data, &badge4_flash_resource, 1);
226
227         return 0;
228 }
229
230 arch_initcall(badge4_init);
231
232
233 static unsigned badge4_5V_bitmap = 0;
234
235 void badge4_set_5V(unsigned subsystem, int on)
236 {
237         unsigned long flags;
238         unsigned old_5V_bitmap;
239
240         local_irq_save(flags);
241
242         old_5V_bitmap = badge4_5V_bitmap;
243
244         if (on) {
245                 badge4_5V_bitmap |= subsystem;
246         } else {
247                 badge4_5V_bitmap &= ~subsystem;
248         }
249
250         /* detect on->off and off->on transitions */
251         if ((!old_5V_bitmap) && (badge4_5V_bitmap)) {
252                 /* was off, now on */
253                 printk(KERN_INFO "%s: enabling 5V supply rail\n", __func__);
254                 GPSR = BADGE4_GPIO_PCMEN5V;
255         } else if ((old_5V_bitmap) && (!badge4_5V_bitmap)) {
256                 /* was on, now off */
257                 printk(KERN_INFO "%s: disabling 5V supply rail\n", __func__);
258                 GPCR = BADGE4_GPIO_PCMEN5V;
259         }
260
261         local_irq_restore(flags);
262 }
263 EXPORT_SYMBOL(badge4_set_5V);
264
265
266 static struct map_desc badge4_io_desc[] __initdata = {
267         {       /* SRAM  bank 1 */
268                 .virtual        = 0xf1000000,
269                 .pfn            = __phys_to_pfn(0x08000000),
270                 .length         = 0x00100000,
271                 .type           = MT_DEVICE
272         }, {    /* SRAM  bank 2 */
273                 .virtual        = 0xf2000000,
274                 .pfn            = __phys_to_pfn(0x10000000),
275                 .length         = 0x00100000,
276                 .type           = MT_DEVICE
277         }
278 };
279
280 static void
281 badge4_uart_pm(struct uart_port *port, u_int state, u_int oldstate)
282 {
283         if (!state) {
284                 Ser1SDCR0 |= SDCR0_UART;
285         }
286 }
287
288 static struct sa1100_port_fns badge4_port_fns __initdata = {
289         //.get_mctrl    = badge4_get_mctrl,
290         //.set_mctrl    = badge4_set_mctrl,
291         .pm             = badge4_uart_pm,
292 };
293
294 static void __init badge4_map_io(void)
295 {
296         sa1100_map_io();
297         iotable_init(badge4_io_desc, ARRAY_SIZE(badge4_io_desc));
298
299         sa1100_register_uart_fns(&badge4_port_fns);
300         sa1100_register_uart(0, 3);
301         sa1100_register_uart(1, 1);
302 }
303
304 MACHINE_START(BADGE4, "Hewlett-Packard Laboratories BadgePAD 4")
305         .atag_offset    = 0x100,
306         .map_io         = badge4_map_io,
307         .nr_irqs        = SA1100_NR_IRQS,
308         .init_irq       = sa1100_init_irq,
309         .timer          = &sa1100_timer,
310 #ifdef CONFIG_SA1111
311         .dma_zone_size  = SZ_1M,
312 #endif
313         .restart        = sa11x0_restart,
314 MACHINE_END