1 /***************************************************************************/
4 * linux/arch/m68knommu/platform/5249/config.c
6 * Copyright (C) 2002, Greg Ungerer (gerg@snapgear.com)
9 /***************************************************************************/
11 #include <linux/kernel.h>
12 #include <linux/param.h>
13 #include <linux/init.h>
15 #include <linux/spi/spi.h>
16 #include <linux/gpio.h>
17 #include <asm/machdep.h>
18 #include <asm/coldfire.h>
19 #include <asm/mcfsim.h>
20 #include <asm/mcfuart.h>
21 #include <asm/mcfqspi.h>
23 /***************************************************************************/
25 static struct mcf_platform_uart m5249_uart_platform[] = {
27 .mapbase = MCF_MBAR + MCFUART_BASE1,
31 .mapbase = MCF_MBAR + MCFUART_BASE2,
37 static struct platform_device m5249_uart = {
40 .dev.platform_data = m5249_uart_platform,
43 #if defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE)
44 static struct resource m5249_qspi_resources[] = {
46 .start = MCFQSPI_IOBASE,
47 .end = MCFQSPI_IOBASE + MCFQSPI_IOSIZE - 1,
48 .flags = IORESOURCE_MEM,
51 .start = MCF_IRQ_QSPI,
53 .flags = IORESOURCE_IRQ,
57 #define MCFQSPI_CS0 29
58 #define MCFQSPI_CS1 24
59 #define MCFQSPI_CS2 21
60 #define MCFQSPI_CS3 22
62 static int m5249_cs_setup(struct mcfqspi_cs_control *cs_control)
66 status = gpio_request(MCFQSPI_CS0, "MCFQSPI_CS0");
68 pr_debug("gpio_request for MCFQSPI_CS0 failed\n");
71 status = gpio_direction_output(MCFQSPI_CS0, 1);
73 pr_debug("gpio_direction_output for MCFQSPI_CS0 failed\n");
77 status = gpio_request(MCFQSPI_CS1, "MCFQSPI_CS1");
79 pr_debug("gpio_request for MCFQSPI_CS1 failed\n");
82 status = gpio_direction_output(MCFQSPI_CS1, 1);
84 pr_debug("gpio_direction_output for MCFQSPI_CS1 failed\n");
88 status = gpio_request(MCFQSPI_CS2, "MCFQSPI_CS2");
90 pr_debug("gpio_request for MCFQSPI_CS2 failed\n");
93 status = gpio_direction_output(MCFQSPI_CS2, 1);
95 pr_debug("gpio_direction_output for MCFQSPI_CS2 failed\n");
99 status = gpio_request(MCFQSPI_CS3, "MCFQSPI_CS3");
101 pr_debug("gpio_request for MCFQSPI_CS3 failed\n");
104 status = gpio_direction_output(MCFQSPI_CS3, 1);
106 pr_debug("gpio_direction_output for MCFQSPI_CS3 failed\n");
113 gpio_free(MCFQSPI_CS3);
115 gpio_free(MCFQSPI_CS2);
117 gpio_free(MCFQSPI_CS1);
119 gpio_free(MCFQSPI_CS0);
124 static void m5249_cs_teardown(struct mcfqspi_cs_control *cs_control)
126 gpio_free(MCFQSPI_CS3);
127 gpio_free(MCFQSPI_CS2);
128 gpio_free(MCFQSPI_CS1);
129 gpio_free(MCFQSPI_CS0);
132 static void m5249_cs_select(struct mcfqspi_cs_control *cs_control,
133 u8 chip_select, bool cs_high)
135 switch (chip_select) {
137 gpio_set_value(MCFQSPI_CS0, cs_high);
140 gpio_set_value(MCFQSPI_CS1, cs_high);
143 gpio_set_value(MCFQSPI_CS2, cs_high);
146 gpio_set_value(MCFQSPI_CS3, cs_high);
151 static void m5249_cs_deselect(struct mcfqspi_cs_control *cs_control,
152 u8 chip_select, bool cs_high)
154 switch (chip_select) {
156 gpio_set_value(MCFQSPI_CS0, !cs_high);
159 gpio_set_value(MCFQSPI_CS1, !cs_high);
162 gpio_set_value(MCFQSPI_CS2, !cs_high);
165 gpio_set_value(MCFQSPI_CS3, !cs_high);
170 static struct mcfqspi_cs_control m5249_cs_control = {
171 .setup = m5249_cs_setup,
172 .teardown = m5249_cs_teardown,
173 .select = m5249_cs_select,
174 .deselect = m5249_cs_deselect,
177 static struct mcfqspi_platform_data m5249_qspi_data = {
180 .cs_control = &m5249_cs_control,
183 static struct platform_device m5249_qspi = {
186 .num_resources = ARRAY_SIZE(m5249_qspi_resources),
187 .resource = m5249_qspi_resources,
188 .dev.platform_data = &m5249_qspi_data,
191 static void __init m5249_qspi_init(void)
194 writeb(MCFSIM_ICR_AUTOVEC | MCFSIM_ICR_LEVEL4 | MCFSIM_ICR_PRI0,
195 MCF_MBAR + MCFSIM_QSPIICR);
196 mcf_mapirq2imr(MCF_IRQ_QSPI, MCFINTC_QSPI);
198 #endif /* defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE) */
201 static struct platform_device *m5249_devices[] __initdata = {
203 #if defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE)
208 /***************************************************************************/
210 static void __init m5249_uart_init_line(int line, int irq)
213 writeb(MCFSIM_ICR_LEVEL6 | MCFSIM_ICR_PRI1, MCF_MBAR + MCFSIM_UART1ICR);
214 writeb(irq, MCF_MBAR + MCFUART_BASE1 + MCFUART_UIVR);
215 mcf_mapirq2imr(irq, MCFINTC_UART0);
216 } else if (line == 1) {
217 writeb(MCFSIM_ICR_LEVEL6 | MCFSIM_ICR_PRI2, MCF_MBAR + MCFSIM_UART2ICR);
218 writeb(irq, MCF_MBAR + MCFUART_BASE2 + MCFUART_UIVR);
219 mcf_mapirq2imr(irq, MCFINTC_UART1);
223 static void __init m5249_uarts_init(void)
225 const int nrlines = ARRAY_SIZE(m5249_uart_platform);
228 for (line = 0; (line < nrlines); line++)
229 m5249_uart_init_line(line, m5249_uart_platform[line].irq);
232 /***************************************************************************/
234 static void __init m5249_timers_init(void)
236 /* Timer1 is always used as system timer */
237 writeb(MCFSIM_ICR_AUTOVEC | MCFSIM_ICR_LEVEL6 | MCFSIM_ICR_PRI3,
238 MCF_MBAR + MCFSIM_TIMER1ICR);
239 mcf_mapirq2imr(MCF_IRQ_TIMER, MCFINTC_TIMER1);
241 #ifdef CONFIG_HIGHPROFILE
242 /* Timer2 is to be used as a high speed profile timer */
243 writeb(MCFSIM_ICR_AUTOVEC | MCFSIM_ICR_LEVEL7 | MCFSIM_ICR_PRI3,
244 MCF_MBAR + MCFSIM_TIMER2ICR);
245 mcf_mapirq2imr(MCF_IRQ_PROFILER, MCFINTC_TIMER2);
249 /***************************************************************************/
251 void m5249_cpu_reset(void)
254 /* Set watchdog to soft reset, and enabled */
255 __raw_writeb(0xc0, MCF_MBAR + MCFSIM_SYPCR);
257 /* wait for watchdog to timeout */;
260 /***************************************************************************/
262 void __init config_BSP(char *commandp, int size)
264 mach_reset = m5249_cpu_reset;
267 #if defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE)
272 /***************************************************************************/
274 static int __init init_BSP(void)
276 platform_add_devices(m5249_devices, ARRAY_SIZE(m5249_devices));
280 arch_initcall(init_BSP);
282 /***************************************************************************/