1 /***************************************************************************/
4 * linux/arch/m68knommu/platform/528x/config.c
6 * Sub-architcture dependant initialization code for the Freescale
7 * 5280, 5281 and 5282 CPUs.
9 * Copyright (C) 1999-2003, Greg Ungerer (gerg@snapgear.com)
10 * Copyright (C) 2001-2003, SnapGear Inc. (www.snapgear.com)
13 /***************************************************************************/
15 #include <linux/kernel.h>
16 #include <linux/param.h>
17 #include <linux/init.h>
18 #include <linux/platform_device.h>
20 #include <linux/spi/spi.h>
21 #include <linux/gpio.h>
22 #include <asm/machdep.h>
23 #include <asm/coldfire.h>
24 #include <asm/mcfsim.h>
25 #include <asm/mcfuart.h>
26 #include <asm/mcfqspi.h>
28 /***************************************************************************/
30 static struct mcf_platform_uart m528x_uart_platform[] = {
32 .mapbase = MCFUART_BASE1,
33 .irq = MCFINT_VECBASE + MCFINT_UART0,
36 .mapbase = MCFUART_BASE2,
37 .irq = MCFINT_VECBASE + MCFINT_UART0 + 1,
40 .mapbase = MCFUART_BASE3,
41 .irq = MCFINT_VECBASE + MCFINT_UART0 + 2,
46 static struct platform_device m528x_uart = {
49 .dev.platform_data = m528x_uart_platform,
52 static struct resource m528x_fec_resources[] = {
55 .end = MCFFEC_BASE + MCFFEC_SIZE - 1,
56 .flags = IORESOURCE_MEM,
61 .flags = IORESOURCE_IRQ,
66 .flags = IORESOURCE_IRQ,
71 .flags = IORESOURCE_IRQ,
75 static struct platform_device m528x_fec = {
78 .num_resources = ARRAY_SIZE(m528x_fec_resources),
79 .resource = m528x_fec_resources,
82 #if defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE)
83 static struct resource m528x_qspi_resources[] = {
85 .start = MCFQSPI_IOBASE,
86 .end = MCFQSPI_IOBASE + MCFQSPI_IOSIZE - 1,
87 .flags = IORESOURCE_MEM,
90 .start = MCFINT_VECBASE + MCFINT_QSPI,
91 .end = MCFINT_VECBASE + MCFINT_QSPI,
92 .flags = IORESOURCE_IRQ,
96 #define MCFQSPI_CS0 147
97 #define MCFQSPI_CS1 148
98 #define MCFQSPI_CS2 149
99 #define MCFQSPI_CS3 150
101 static int m528x_cs_setup(struct mcfqspi_cs_control *cs_control)
105 status = gpio_request(MCFQSPI_CS0, "MCFQSPI_CS0");
107 pr_debug("gpio_request for MCFQSPI_CS0 failed\n");
110 status = gpio_direction_output(MCFQSPI_CS0, 1);
112 pr_debug("gpio_direction_output for MCFQSPI_CS0 failed\n");
116 status = gpio_request(MCFQSPI_CS1, "MCFQSPI_CS1");
118 pr_debug("gpio_request for MCFQSPI_CS1 failed\n");
121 status = gpio_direction_output(MCFQSPI_CS1, 1);
123 pr_debug("gpio_direction_output for MCFQSPI_CS1 failed\n");
127 status = gpio_request(MCFQSPI_CS2, "MCFQSPI_CS2");
129 pr_debug("gpio_request for MCFQSPI_CS2 failed\n");
132 status = gpio_direction_output(MCFQSPI_CS2, 1);
134 pr_debug("gpio_direction_output for MCFQSPI_CS2 failed\n");
138 status = gpio_request(MCFQSPI_CS3, "MCFQSPI_CS3");
140 pr_debug("gpio_request for MCFQSPI_CS3 failed\n");
143 status = gpio_direction_output(MCFQSPI_CS3, 1);
145 pr_debug("gpio_direction_output for MCFQSPI_CS3 failed\n");
152 gpio_free(MCFQSPI_CS3);
154 gpio_free(MCFQSPI_CS2);
156 gpio_free(MCFQSPI_CS1);
158 gpio_free(MCFQSPI_CS0);
163 static void m528x_cs_teardown(struct mcfqspi_cs_control *cs_control)
165 gpio_free(MCFQSPI_CS3);
166 gpio_free(MCFQSPI_CS2);
167 gpio_free(MCFQSPI_CS1);
168 gpio_free(MCFQSPI_CS0);
171 static void m528x_cs_select(struct mcfqspi_cs_control *cs_control,
172 u8 chip_select, bool cs_high)
174 gpio_set_value(MCFQSPI_CS0 + chip_select, cs_high);
177 static void m528x_cs_deselect(struct mcfqspi_cs_control *cs_control,
178 u8 chip_select, bool cs_high)
180 gpio_set_value(MCFQSPI_CS0 + chip_select, !cs_high);
183 static struct mcfqspi_cs_control m528x_cs_control = {
184 .setup = m528x_cs_setup,
185 .teardown = m528x_cs_teardown,
186 .select = m528x_cs_select,
187 .deselect = m528x_cs_deselect,
190 static struct mcfqspi_platform_data m528x_qspi_data = {
193 .cs_control = &m528x_cs_control,
196 static struct platform_device m528x_qspi = {
199 .num_resources = ARRAY_SIZE(m528x_qspi_resources),
200 .resource = m528x_qspi_resources,
201 .dev.platform_data = &m528x_qspi_data,
204 static void __init m528x_qspi_init(void)
206 /* setup Port QS for QSPI with gpio CS control */
207 __raw_writeb(0x07, MCFGPIO_PQSPAR);
209 #endif /* defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE) */
211 static struct platform_device *m528x_devices[] __initdata = {
214 #if defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE)
219 /***************************************************************************/
221 static void __init m528x_uart_init_line(int line, int irq)
225 if ((line < 0) || (line > 2))
228 /* make sure PUAPAR is set for UART0 and UART1 */
230 port = readb(MCF5282_GPIO_PUAPAR);
231 port |= (0x03 << (line * 2));
232 writeb(port, MCF5282_GPIO_PUAPAR);
236 static void __init m528x_uarts_init(void)
238 const int nrlines = ARRAY_SIZE(m528x_uart_platform);
241 for (line = 0; (line < nrlines); line++)
242 m528x_uart_init_line(line, m528x_uart_platform[line].irq);
245 /***************************************************************************/
247 static void __init m528x_fec_init(void)
251 /* Set multi-function pins to ethernet mode for fec0 */
252 v16 = readw(MCF_IPSBAR + 0x100056);
253 writew(v16 | 0xf00, MCF_IPSBAR + 0x100056);
254 writeb(0xc0, MCF_IPSBAR + 0x100058);
257 /***************************************************************************/
259 static void m528x_cpu_reset(void)
262 __raw_writeb(MCF_RCR_SWRESET, MCF_IPSBAR + MCF_RCR);
265 /***************************************************************************/
267 #ifdef CONFIG_WILDFIRE
268 void wildfire_halt(void)
270 writeb(0, 0x30000007);
271 writeb(0x2, 0x30000007);
275 #ifdef CONFIG_WILDFIREMOD
276 void wildfiremod_halt(void)
278 printk(KERN_INFO "WildFireMod hibernating...\n");
280 /* Set portE.5 to Digital IO */
281 MCF5282_GPIO_PEPAR &= ~(1 << (5 * 2));
283 /* Make portE.5 an output */
284 MCF5282_GPIO_DDRE |= (1 << 5);
286 /* Now toggle portE.5 from low to high */
287 MCF5282_GPIO_PORTE &= ~(1 << 5);
288 MCF5282_GPIO_PORTE |= (1 << 5);
290 printk(KERN_EMERG "Failed to hibernate. Halting!\n");
294 void __init config_BSP(char *commandp, int size)
296 #ifdef CONFIG_WILDFIRE
297 mach_halt = wildfire_halt;
299 #ifdef CONFIG_WILDFIREMOD
300 mach_halt = wildfiremod_halt;
304 /***************************************************************************/
306 static int __init init_BSP(void)
308 mach_reset = m528x_cpu_reset;
311 #if defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE)
314 platform_add_devices(m528x_devices, ARRAY_SIZE(m528x_devices));
318 arch_initcall(init_BSP);
320 /***************************************************************************/