Merge git://git.kernel.org/pub/scm/linux/kernel/git/mason/btrfs-unstable
[pandora-kernel.git] / arch / m68knommu / platform / 528x / config.c
1 /***************************************************************************/
2
3 /*
4  *      linux/arch/m68knommu/platform/528x/config.c
5  *
6  *      Sub-architcture dependant initialization code for the Motorola
7  *      5280 and 5282 CPUs.
8  *
9  *      Copyright (C) 1999-2003, Greg Ungerer (gerg@snapgear.com)
10  *      Copyright (C) 2001-2003, SnapGear Inc. (www.snapgear.com)
11  */
12
13 /***************************************************************************/
14
15 #include <linux/kernel.h>
16 #include <linux/param.h>
17 #include <linux/init.h>
18 #include <linux/interrupt.h>
19 #include <linux/platform_device.h>
20 #include <linux/spi/spi.h>
21 #include <linux/spi/flash.h>
22 #include <linux/io.h>
23 #include <asm/machdep.h>
24 #include <asm/coldfire.h>
25 #include <asm/mcfsim.h>
26 #include <asm/mcfuart.h>
27
28 #ifdef CONFIG_MTD_PARTITIONS
29 #include <linux/mtd/partitions.h>
30 #endif
31
32 /***************************************************************************/
33
34 void coldfire_reset(void);
35
36 /***************************************************************************/
37
38 static struct mcf_platform_uart m528x_uart_platform[] = {
39         {
40                 .mapbase        = MCF_MBAR + MCFUART_BASE1,
41                 .irq            = MCFINT_VECBASE + MCFINT_UART0,
42         },
43         {
44                 .mapbase        = MCF_MBAR + MCFUART_BASE2,
45                 .irq            = MCFINT_VECBASE + MCFINT_UART0 + 1,
46         },
47         {
48                 .mapbase        = MCF_MBAR + MCFUART_BASE3,
49                 .irq            = MCFINT_VECBASE + MCFINT_UART0 + 2,
50         },
51         { },
52 };
53
54 static struct platform_device m528x_uart = {
55         .name                   = "mcfuart",
56         .id                     = 0,
57         .dev.platform_data      = m528x_uart_platform,
58 };
59
60 static struct resource m528x_fec_resources[] = {
61         {
62                 .start          = MCF_MBAR + 0x1000,
63                 .end            = MCF_MBAR + 0x1000 + 0x7ff,
64                 .flags          = IORESOURCE_MEM,
65         },
66         {
67                 .start          = 64 + 23,
68                 .end            = 64 + 23,
69                 .flags          = IORESOURCE_IRQ,
70         },
71         {
72                 .start          = 64 + 27,
73                 .end            = 64 + 27,
74                 .flags          = IORESOURCE_IRQ,
75         },
76         {
77                 .start          = 64 + 29,
78                 .end            = 64 + 29,
79                 .flags          = IORESOURCE_IRQ,
80         },
81 };
82
83 static struct platform_device m528x_fec = {
84         .name                   = "fec",
85         .id                     = 0,
86         .num_resources          = ARRAY_SIZE(m528x_fec_resources),
87         .resource               = m528x_fec_resources,
88 };
89
90
91 static struct platform_device *m528x_devices[] __initdata = {
92         &m528x_uart,
93         &m528x_fec,
94 };
95
96 /***************************************************************************/
97
98 #define INTC0   (MCF_MBAR + MCFICM_INTC0)
99
100 static void __init m528x_uart_init_line(int line, int irq)
101 {
102         u8 port;
103         u32 imr;
104
105         if ((line < 0) || (line > 2))
106                 return;
107
108         /* level 6, line based priority */
109         writeb(0x30+line, INTC0 + MCFINTC_ICR0 + MCFINT_UART0 + line);
110
111         imr = readl(INTC0 + MCFINTC_IMRL);
112         imr &= ~((1 << (irq - MCFINT_VECBASE)) | 1);
113         writel(imr, INTC0 + MCFINTC_IMRL);
114
115         /* make sure PUAPAR is set for UART0 and UART1 */
116         if (line < 2) {
117                 port = readb(MCF_MBAR + MCF5282_GPIO_PUAPAR);
118                 port |= (0x03 << (line * 2));
119                 writeb(port, MCF_MBAR + MCF5282_GPIO_PUAPAR);
120         }
121 }
122
123 static void __init m528x_uarts_init(void)
124 {
125         const int nrlines = ARRAY_SIZE(m528x_uart_platform);
126         int line;
127
128         for (line = 0; (line < nrlines); line++)
129                 m528x_uart_init_line(line, m528x_uart_platform[line].irq);
130 }
131
132 /***************************************************************************/
133
134 static void __init m528x_fec_init(void)
135 {
136         u32 imr;
137         u16 v16;
138
139         /* Unmask FEC interrupts at ColdFire interrupt controller */
140         writeb(0x28, MCF_IPSBAR + MCFICM_INTC0 + MCFINTC_ICR0 + 23);
141         writeb(0x27, MCF_IPSBAR + MCFICM_INTC0 + MCFINTC_ICR0 + 27);
142         writeb(0x26, MCF_IPSBAR + MCFICM_INTC0 + MCFINTC_ICR0 + 29);
143
144         imr = readl(MCF_IPSBAR + MCFICM_INTC0 + MCFINTC_IMRH);
145         imr &= ~0xf;
146         writel(imr, MCF_IPSBAR + MCFICM_INTC0 + MCFINTC_IMRH);
147         imr = readl(MCF_IPSBAR + MCFICM_INTC0 + MCFINTC_IMRL);
148         imr &= ~0xff800001;
149         writel(imr, MCF_IPSBAR + MCFICM_INTC0 + MCFINTC_IMRL);
150
151         /* Set multi-function pins to ethernet mode for fec0 */
152         v16 = readw(MCF_IPSBAR + 0x100056);
153         writew(v16 | 0xf00, MCF_IPSBAR + 0x100056);
154         writeb(0xc0, MCF_IPSBAR + 0x100058);
155 }
156
157 /***************************************************************************/
158
159 void mcf_disableall(void)
160 {
161         *((volatile unsigned long *) (MCF_IPSBAR + MCFICM_INTC0 + MCFINTC_IMRH)) = 0xffffffff;
162         *((volatile unsigned long *) (MCF_IPSBAR + MCFICM_INTC0 + MCFINTC_IMRL)) = 0xffffffff;
163 }
164
165 /***************************************************************************/
166
167 void mcf_autovector(unsigned int vec)
168 {
169         /* Everything is auto-vectored on the 5272 */
170 }
171
172 /***************************************************************************/
173
174 #ifdef CONFIG_WILDFIRE
175 void wildfire_halt(void)
176 {
177         writeb(0, 0x30000007);
178         writeb(0x2, 0x30000007);
179 }
180 #endif
181
182 #ifdef CONFIG_WILDFIREMOD
183 void wildfiremod_halt(void)
184 {
185         printk(KERN_INFO "WildFireMod hibernating...\n");
186
187         /* Set portE.5 to Digital IO */
188         MCF5282_GPIO_PEPAR &= ~(1 << (5 * 2));
189
190         /* Make portE.5 an output */
191         MCF5282_GPIO_DDRE |= (1 << 5);
192
193         /* Now toggle portE.5 from low to high */
194         MCF5282_GPIO_PORTE &= ~(1 << 5);
195         MCF5282_GPIO_PORTE |= (1 << 5);
196
197         printk(KERN_EMERG "Failed to hibernate. Halting!\n");
198 }
199 #endif
200
201 void __init config_BSP(char *commandp, int size)
202 {
203         mcf_disableall();
204
205 #ifdef CONFIG_WILDFIRE
206         mach_halt = wildfire_halt;
207 #endif
208 #ifdef CONFIG_WILDFIREMOD
209         mach_halt = wildfiremod_halt;
210 #endif
211 }
212
213 /***************************************************************************/
214
215 static int __init init_BSP(void)
216 {
217         m528x_uarts_init();
218         m528x_fec_init();
219         platform_add_devices(m528x_devices, ARRAY_SIZE(m528x_devices));
220         return 0;
221 }
222
223 arch_initcall(init_BSP);
224
225 /***************************************************************************/