Merge branch 'master' into upstream
[linux-2.6] / arch / arm / mach-sa1100 / simpad.c
1 /*
2  * linux/arch/arm/mach-sa1100/simpad.c
3  */
4
5 #include <linux/config.h>
6 #include <linux/module.h>
7 #include <linux/init.h>
8 #include <linux/kernel.h>
9 #include <linux/tty.h>
10 #include <linux/proc_fs.h>
11 #include <linux/string.h> 
12 #include <linux/pm.h>
13 #include <linux/platform_device.h>
14 #include <linux/mtd/mtd.h>
15 #include <linux/mtd/partitions.h>
16
17 #include <asm/irq.h>
18 #include <asm/hardware.h>
19 #include <asm/setup.h>
20
21 #include <asm/mach-types.h>
22 #include <asm/mach/arch.h>
23 #include <asm/mach/flash.h>
24 #include <asm/mach/map.h>
25 #include <asm/mach/serial_sa1100.h>
26 #include <asm/arch/mcp.h>
27 #include <asm/arch/simpad.h>
28
29 #include <linux/serial_core.h>
30 #include <linux/ioport.h>
31 #include <asm/io.h>
32
33 #include "generic.h"
34
35 long cs3_shadow;
36
37 long get_cs3_shadow(void)
38 {
39         return cs3_shadow;
40 }
41
42 void set_cs3(long value)
43 {
44         *(CS3BUSTYPE *)(CS3_BASE) = cs3_shadow = value;
45 }
46
47 void set_cs3_bit(int value)
48 {
49         cs3_shadow |= value;
50         *(CS3BUSTYPE *)(CS3_BASE) = cs3_shadow;
51 }
52
53 void clear_cs3_bit(int value)
54 {
55         cs3_shadow &= ~value;
56         *(CS3BUSTYPE *)(CS3_BASE) = cs3_shadow;
57 }
58
59 EXPORT_SYMBOL(set_cs3_bit);
60 EXPORT_SYMBOL(clear_cs3_bit);
61
62 static struct map_desc simpad_io_desc[] __initdata = {
63         {       /* MQ200 */
64                 .virtual        =  0xf2800000,
65                 .pfn            = __phys_to_pfn(0x4b800000),
66                 .length         = 0x00800000,
67                 .type           = MT_DEVICE
68         }, {    /* Paules CS3, write only */
69                 .virtual        =  0xf1000000,
70                 .pfn            = __phys_to_pfn(0x18000000),
71                 .length         = 0x00100000,
72                 .type           = MT_DEVICE
73         },
74 };
75
76
77 static void simpad_uart_pm(struct uart_port *port, u_int state, u_int oldstate)
78 {
79         if (port->mapbase == (u_int)&Ser1UTCR0) {
80                 if (state)
81                 {
82                         clear_cs3_bit(RS232_ON);
83                         clear_cs3_bit(DECT_POWER_ON);
84                 }else
85                 {
86                         set_cs3_bit(RS232_ON);
87                         set_cs3_bit(DECT_POWER_ON);
88                 }
89         }
90 }
91
92 static struct sa1100_port_fns simpad_port_fns __initdata = {
93         .pm        = simpad_uart_pm,
94 };
95
96
97 static struct mtd_partition simpad_partitions[] = {
98         {
99                 .name       = "SIMpad boot firmware",
100                 .size       = 0x00080000,
101                 .offset     = 0,
102                 .mask_flags = MTD_WRITEABLE,
103         }, {
104                 .name       = "SIMpad kernel",
105                 .size       = 0x0010000,
106                 .offset     = MTDPART_OFS_APPEND,
107         }, {
108                 .name       = "SIMpad root jffs2",
109                 .size       = MTDPART_SIZ_FULL,
110                 .offset     = MTDPART_OFS_APPEND,
111         }
112 };
113
114 static struct flash_platform_data simpad_flash_data = {
115         .map_name    = "cfi_probe",
116         .parts       = simpad_partitions,
117         .nr_parts    = ARRAY_SIZE(simpad_partitions),
118 };
119
120
121 static struct resource simpad_flash_resources [] = {
122         {
123                 .start     = SA1100_CS0_PHYS,
124                 .end       = SA1100_CS0_PHYS + SZ_16M -1,
125                 .flags     = IORESOURCE_MEM,
126         }, {
127                 .start     = SA1100_CS1_PHYS,
128                 .end       = SA1100_CS1_PHYS + SZ_16M -1,
129                 .flags     = IORESOURCE_MEM,
130         }
131 };
132
133 static struct mcp_plat_data simpad_mcp_data = {
134         .mccr0          = MCCR0_ADM,
135         .sclk_rate      = 11981000,
136 };
137
138
139
140 static void __init simpad_map_io(void)
141 {
142         sa1100_map_io();
143
144         iotable_init(simpad_io_desc, ARRAY_SIZE(simpad_io_desc));
145
146         set_cs3_bit (EN1 | EN0 | LED2_ON | DISPLAY_ON | RS232_ON |
147                       ENABLE_5V | RESET_SIMCARD | DECT_POWER_ON);
148
149
150         sa1100_register_uart_fns(&simpad_port_fns);
151         sa1100_register_uart(0, 3);  /* serial interface */
152         sa1100_register_uart(1, 1);  /* DECT             */
153
154         // Reassign UART 1 pins
155         GAFR |= GPIO_UART_TXD | GPIO_UART_RXD;
156         GPDR |= GPIO_UART_TXD | GPIO_LDD13 | GPIO_LDD15;
157         GPDR &= ~GPIO_UART_RXD;
158         PPAR |= PPAR_UPR;
159
160         /*
161          * Set up registers for sleep mode.
162          */
163
164
165         PWER = PWER_GPIO0| PWER_RTC;
166         PGSR = 0x818;
167         PCFR = 0;
168         PSDR = 0;
169
170         sa11x0_set_flash_data(&simpad_flash_data, simpad_flash_resources,
171                               ARRAY_SIZE(simpad_flash_resources));
172         sa11x0_set_mcp_data(&simpad_mcp_data);
173 }
174
175 static void simpad_power_off(void)
176 {
177         local_irq_disable(); // was cli
178         set_cs3(0x800);        /* only SD_MEDIAQ */
179
180         /* disable internal oscillator, float CS lines */
181         PCFR = (PCFR_OPDE | PCFR_FP | PCFR_FS);
182         /* enable wake-up on GPIO0 (Assabet...) */
183         PWER = GFER = GRER = 1;
184         /*
185          * set scratchpad to zero, just in case it is used as a
186          * restart address by the bootloader.
187          */
188         PSPR = 0;
189         PGSR = 0;
190         /* enter sleep mode */
191         PMCR = PMCR_SF;
192         while(1);
193
194         local_irq_enable(); /* we won't ever call it */
195
196
197 }
198
199
200 /*
201  * MediaQ Video Device
202  */
203 static struct platform_device simpad_mq200fb = {
204         .name = "simpad-mq200",
205         .id   = 0,
206 };
207
208 static struct platform_device *devices[] __initdata = {
209         &simpad_mq200fb
210 };
211
212
213
214 static int __init simpad_init(void)
215 {
216         int ret;
217
218         pm_power_off = simpad_power_off;
219
220         ret = platform_add_devices(devices, ARRAY_SIZE(devices));
221         if(ret)
222                 printk(KERN_WARNING "simpad: Unable to register mq200 framebuffer device");
223
224         return 0;
225 }
226
227 arch_initcall(simpad_init);
228
229
230 MACHINE_START(SIMPAD, "Simpad")
231         /* Maintainer: Holger Freyther */
232         .phys_io        = 0x80000000,
233         .io_pg_offst    = ((0xf8000000) >> 18) & 0xfffc,
234         .boot_params    = 0xc0000100,
235         .map_io         = simpad_map_io,
236         .init_irq       = sa1100_init_irq,
237         .timer          = &sa1100_timer,
238 MACHINE_END