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
,
45 static struct resource m5249_smc91x_resources
[] = {
48 .end
= 0xe0000300 + 0x100,
49 .flags
= IORESOURCE_MEM
,
52 .start
= MCFINTC2_GPIOIRQ6
,
53 .end
= MCFINTC2_GPIOIRQ6
,
54 .flags
= IORESOURCE_IRQ
,
58 static struct platform_device m5249_smc91x
= {
61 .num_resources
= ARRAY_SIZE(m5249_smc91x_resources
),
62 .resource
= m5249_smc91x_resources
,
65 #endif /* CONFIG_M5249C3 */
67 #if defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE)
68 static struct resource m5249_qspi_resources
[] = {
70 .start
= MCFQSPI_IOBASE
,
71 .end
= MCFQSPI_IOBASE
+ MCFQSPI_IOSIZE
- 1,
72 .flags
= IORESOURCE_MEM
,
75 .start
= MCF_IRQ_QSPI
,
77 .flags
= IORESOURCE_IRQ
,
81 #define MCFQSPI_CS0 29
82 #define MCFQSPI_CS1 24
83 #define MCFQSPI_CS2 21
84 #define MCFQSPI_CS3 22
86 static int m5249_cs_setup(struct mcfqspi_cs_control
*cs_control
)
90 status
= gpio_request(MCFQSPI_CS0
, "MCFQSPI_CS0");
92 pr_debug("gpio_request for MCFQSPI_CS0 failed\n");
95 status
= gpio_direction_output(MCFQSPI_CS0
, 1);
97 pr_debug("gpio_direction_output for MCFQSPI_CS0 failed\n");
101 status
= gpio_request(MCFQSPI_CS1
, "MCFQSPI_CS1");
103 pr_debug("gpio_request for MCFQSPI_CS1 failed\n");
106 status
= gpio_direction_output(MCFQSPI_CS1
, 1);
108 pr_debug("gpio_direction_output for MCFQSPI_CS1 failed\n");
112 status
= gpio_request(MCFQSPI_CS2
, "MCFQSPI_CS2");
114 pr_debug("gpio_request for MCFQSPI_CS2 failed\n");
117 status
= gpio_direction_output(MCFQSPI_CS2
, 1);
119 pr_debug("gpio_direction_output for MCFQSPI_CS2 failed\n");
123 status
= gpio_request(MCFQSPI_CS3
, "MCFQSPI_CS3");
125 pr_debug("gpio_request for MCFQSPI_CS3 failed\n");
128 status
= gpio_direction_output(MCFQSPI_CS3
, 1);
130 pr_debug("gpio_direction_output for MCFQSPI_CS3 failed\n");
137 gpio_free(MCFQSPI_CS3
);
139 gpio_free(MCFQSPI_CS2
);
141 gpio_free(MCFQSPI_CS1
);
143 gpio_free(MCFQSPI_CS0
);
148 static void m5249_cs_teardown(struct mcfqspi_cs_control
*cs_control
)
150 gpio_free(MCFQSPI_CS3
);
151 gpio_free(MCFQSPI_CS2
);
152 gpio_free(MCFQSPI_CS1
);
153 gpio_free(MCFQSPI_CS0
);
156 static void m5249_cs_select(struct mcfqspi_cs_control
*cs_control
,
157 u8 chip_select
, bool cs_high
)
159 switch (chip_select
) {
161 gpio_set_value(MCFQSPI_CS0
, cs_high
);
164 gpio_set_value(MCFQSPI_CS1
, cs_high
);
167 gpio_set_value(MCFQSPI_CS2
, cs_high
);
170 gpio_set_value(MCFQSPI_CS3
, cs_high
);
175 static void m5249_cs_deselect(struct mcfqspi_cs_control
*cs_control
,
176 u8 chip_select
, bool cs_high
)
178 switch (chip_select
) {
180 gpio_set_value(MCFQSPI_CS0
, !cs_high
);
183 gpio_set_value(MCFQSPI_CS1
, !cs_high
);
186 gpio_set_value(MCFQSPI_CS2
, !cs_high
);
189 gpio_set_value(MCFQSPI_CS3
, !cs_high
);
194 static struct mcfqspi_cs_control m5249_cs_control
= {
195 .setup
= m5249_cs_setup
,
196 .teardown
= m5249_cs_teardown
,
197 .select
= m5249_cs_select
,
198 .deselect
= m5249_cs_deselect
,
201 static struct mcfqspi_platform_data m5249_qspi_data
= {
204 .cs_control
= &m5249_cs_control
,
207 static struct platform_device m5249_qspi
= {
210 .num_resources
= ARRAY_SIZE(m5249_qspi_resources
),
211 .resource
= m5249_qspi_resources
,
212 .dev
.platform_data
= &m5249_qspi_data
,
215 static void __init
m5249_qspi_init(void)
218 writeb(MCFSIM_ICR_AUTOVEC
| MCFSIM_ICR_LEVEL4
| MCFSIM_ICR_PRI0
,
219 MCF_MBAR
+ MCFSIM_QSPIICR
);
220 mcf_mapirq2imr(MCF_IRQ_QSPI
, MCFINTC_QSPI
);
222 #endif /* defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE) */
225 static struct platform_device
*m5249_devices
[] __initdata
= {
227 #ifdef CONFIG_M5249C3
230 #if defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE)
235 /***************************************************************************/
237 static void __init
m5249_uart_init_line(int line
, int irq
)
240 writeb(MCFSIM_ICR_LEVEL6
| MCFSIM_ICR_PRI1
, MCF_MBAR
+ MCFSIM_UART1ICR
);
241 writeb(irq
, MCF_MBAR
+ MCFUART_BASE1
+ MCFUART_UIVR
);
242 mcf_mapirq2imr(irq
, MCFINTC_UART0
);
243 } else if (line
== 1) {
244 writeb(MCFSIM_ICR_LEVEL6
| MCFSIM_ICR_PRI2
, MCF_MBAR
+ MCFSIM_UART2ICR
);
245 writeb(irq
, MCF_MBAR
+ MCFUART_BASE2
+ MCFUART_UIVR
);
246 mcf_mapirq2imr(irq
, MCFINTC_UART1
);
250 static void __init
m5249_uarts_init(void)
252 const int nrlines
= ARRAY_SIZE(m5249_uart_platform
);
255 for (line
= 0; (line
< nrlines
); line
++)
256 m5249_uart_init_line(line
, m5249_uart_platform
[line
].irq
);
259 /***************************************************************************/
261 #ifdef CONFIG_M5249C3
263 static void __init
m5249_smc91x_init(void)
267 /* Set the GPIO line as interrupt source for smc91x device */
268 gpio
= readl(MCF_MBAR2
+ MCFSIM2_GPIOINTENABLE
);
269 writel(gpio
| 0x40, MCF_MBAR2
+ MCFSIM2_GPIOINTENABLE
);
271 gpio
= readl(MCF_MBAR2
+ MCFSIM2_INTLEVEL5
);
272 writel(gpio
| 0x04000000, MCF_MBAR2
+ MCFSIM2_INTLEVEL5
);
275 #endif /* CONFIG_M5249C3 */
277 /***************************************************************************/
279 static void __init
m5249_timers_init(void)
281 /* Timer1 is always used as system timer */
282 writeb(MCFSIM_ICR_AUTOVEC
| MCFSIM_ICR_LEVEL6
| MCFSIM_ICR_PRI3
,
283 MCF_MBAR
+ MCFSIM_TIMER1ICR
);
284 mcf_mapirq2imr(MCF_IRQ_TIMER
, MCFINTC_TIMER1
);
286 #ifdef CONFIG_HIGHPROFILE
287 /* Timer2 is to be used as a high speed profile timer */
288 writeb(MCFSIM_ICR_AUTOVEC
| MCFSIM_ICR_LEVEL7
| MCFSIM_ICR_PRI3
,
289 MCF_MBAR
+ MCFSIM_TIMER2ICR
);
290 mcf_mapirq2imr(MCF_IRQ_PROFILER
, MCFINTC_TIMER2
);
294 /***************************************************************************/
296 void m5249_cpu_reset(void)
299 /* Set watchdog to soft reset, and enabled */
300 __raw_writeb(0xc0, MCF_MBAR
+ MCFSIM_SYPCR
);
302 /* wait for watchdog to timeout */;
305 /***************************************************************************/
307 void __init
config_BSP(char *commandp
, int size
)
309 mach_reset
= m5249_cpu_reset
;
312 #ifdef CONFIG_M5249C3
315 #if defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE)
320 /***************************************************************************/
322 static int __init
init_BSP(void)
324 platform_add_devices(m5249_devices
, ARRAY_SIZE(m5249_devices
));
328 arch_initcall(init_BSP
);
330 /***************************************************************************/