1 /***************************************************************************/
4 * linux/arch/m68knommu/platform/520x/config.c
6 * Copyright (C) 2005, Freescale (www.freescale.com)
7 * Copyright (C) 2005, Intec Automation (mike@steroidmicros.com)
8 * Copyright (C) 1999-2007, Greg Ungerer (gerg@snapgear.com)
9 * Copyright (C) 2001-2003, SnapGear Inc. (www.snapgear.com)
12 /***************************************************************************/
14 #include <linux/kernel.h>
15 #include <linux/param.h>
16 #include <linux/init.h>
18 #include <linux/spi/spi.h>
19 #include <linux/gpio.h>
20 #include <asm/machdep.h>
21 #include <asm/coldfire.h>
22 #include <asm/mcfsim.h>
23 #include <asm/mcfuart.h>
24 #include <asm/mcfqspi.h>
26 /***************************************************************************/
28 static struct mcf_platform_uart m520x_uart_platform
[] = {
30 .mapbase
= MCFUART_BASE1
,
31 .irq
= MCFINT_VECBASE
+ MCFINT_UART0
,
34 .mapbase
= MCFUART_BASE2
,
35 .irq
= MCFINT_VECBASE
+ MCFINT_UART1
,
38 .mapbase
= MCFUART_BASE3
,
39 .irq
= MCFINT_VECBASE
+ MCFINT_UART2
,
44 static struct platform_device m520x_uart
= {
47 .dev
.platform_data
= m520x_uart_platform
,
50 static struct resource m520x_fec_resources
[] = {
53 .end
= MCFFEC_BASE
+ MCFFEC_SIZE
- 1,
54 .flags
= IORESOURCE_MEM
,
59 .flags
= IORESOURCE_IRQ
,
64 .flags
= IORESOURCE_IRQ
,
69 .flags
= IORESOURCE_IRQ
,
73 static struct platform_device m520x_fec
= {
76 .num_resources
= ARRAY_SIZE(m520x_fec_resources
),
77 .resource
= m520x_fec_resources
,
80 #if defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE)
81 static struct resource m520x_qspi_resources
[] = {
83 .start
= MCFQSPI_IOBASE
,
84 .end
= MCFQSPI_IOBASE
+ MCFQSPI_IOSIZE
- 1,
85 .flags
= IORESOURCE_MEM
,
88 .start
= MCFINT_VECBASE
+ MCFINT_QSPI
,
89 .end
= MCFINT_VECBASE
+ MCFINT_QSPI
,
90 .flags
= IORESOURCE_IRQ
,
94 #define MCFQSPI_CS0 46
95 #define MCFQSPI_CS1 47
96 #define MCFQSPI_CS2 27
98 static int m520x_cs_setup(struct mcfqspi_cs_control
*cs_control
)
102 status
= gpio_request(MCFQSPI_CS0
, "MCFQSPI_CS0");
104 pr_debug("gpio_request for MCFQSPI_CS0 failed\n");
107 status
= gpio_direction_output(MCFQSPI_CS0
, 1);
109 pr_debug("gpio_direction_output for MCFQSPI_CS0 failed\n");
113 status
= gpio_request(MCFQSPI_CS1
, "MCFQSPI_CS1");
115 pr_debug("gpio_request for MCFQSPI_CS1 failed\n");
118 status
= gpio_direction_output(MCFQSPI_CS1
, 1);
120 pr_debug("gpio_direction_output for MCFQSPI_CS1 failed\n");
124 status
= gpio_request(MCFQSPI_CS2
, "MCFQSPI_CS2");
126 pr_debug("gpio_request for MCFQSPI_CS2 failed\n");
129 status
= gpio_direction_output(MCFQSPI_CS2
, 1);
131 pr_debug("gpio_direction_output for MCFQSPI_CS2 failed\n");
138 gpio_free(MCFQSPI_CS2
);
140 gpio_free(MCFQSPI_CS1
);
142 gpio_free(MCFQSPI_CS0
);
147 static void m520x_cs_teardown(struct mcfqspi_cs_control
*cs_control
)
149 gpio_free(MCFQSPI_CS2
);
150 gpio_free(MCFQSPI_CS1
);
151 gpio_free(MCFQSPI_CS0
);
154 static void m520x_cs_select(struct mcfqspi_cs_control
*cs_control
,
155 u8 chip_select
, bool cs_high
)
157 switch (chip_select
) {
159 gpio_set_value(MCFQSPI_CS0
, cs_high
);
162 gpio_set_value(MCFQSPI_CS1
, cs_high
);
165 gpio_set_value(MCFQSPI_CS2
, cs_high
);
170 static void m520x_cs_deselect(struct mcfqspi_cs_control
*cs_control
,
171 u8 chip_select
, bool cs_high
)
173 switch (chip_select
) {
175 gpio_set_value(MCFQSPI_CS0
, !cs_high
);
178 gpio_set_value(MCFQSPI_CS1
, !cs_high
);
181 gpio_set_value(MCFQSPI_CS2
, !cs_high
);
186 static struct mcfqspi_cs_control m520x_cs_control
= {
187 .setup
= m520x_cs_setup
,
188 .teardown
= m520x_cs_teardown
,
189 .select
= m520x_cs_select
,
190 .deselect
= m520x_cs_deselect
,
193 static struct mcfqspi_platform_data m520x_qspi_data
= {
196 .cs_control
= &m520x_cs_control
,
199 static struct platform_device m520x_qspi
= {
202 .num_resources
= ARRAY_SIZE(m520x_qspi_resources
),
203 .resource
= m520x_qspi_resources
,
204 .dev
.platform_data
= &m520x_qspi_data
,
207 static void __init
m520x_qspi_init(void)
210 /* setup Port QS for QSPI with gpio CS control */
211 writeb(0x3f, MCF_GPIO_PAR_QSPI
);
212 /* make U1CTS and U2RTS gpio for cs_control */
213 par
= readw(MCF_GPIO_PAR_UART
);
215 writew(par
, MCF_GPIO_PAR_UART
);
217 #endif /* defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE) */
220 static struct platform_device
*m520x_devices
[] __initdata
= {
223 #if defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE)
228 /***************************************************************************/
230 static void __init
m520x_uart_init_line(int line
, int irq
)
237 par
= readw(MCF_GPIO_PAR_UART
);
238 par
|= MCF_GPIO_PAR_UART_PAR_UTXD0
|
239 MCF_GPIO_PAR_UART_PAR_URXD0
;
240 writew(par
, MCF_GPIO_PAR_UART
);
243 par
= readw(MCF_GPIO_PAR_UART
);
244 par
|= MCF_GPIO_PAR_UART_PAR_UTXD1
|
245 MCF_GPIO_PAR_UART_PAR_URXD1
;
246 writew(par
, MCF_GPIO_PAR_UART
);
249 par2
= readb(MCF_GPIO_PAR_FECI2C
);
251 par2
|= MCF_GPIO_PAR_FECI2C_PAR_SCL_UTXD2
|
252 MCF_GPIO_PAR_FECI2C_PAR_SDA_URXD2
;
253 writeb(par2
, MCF_GPIO_PAR_FECI2C
);
258 static void __init
m520x_uarts_init(void)
260 const int nrlines
= ARRAY_SIZE(m520x_uart_platform
);
263 for (line
= 0; (line
< nrlines
); line
++)
264 m520x_uart_init_line(line
, m520x_uart_platform
[line
].irq
);
267 /***************************************************************************/
269 static void __init
m520x_fec_init(void)
273 /* Set multi-function pins to ethernet mode */
274 v
= readb(MCF_GPIO_PAR_FEC
);
275 writeb(v
| 0xf0, MCF_GPIO_PAR_FEC
);
277 v
= readb(MCF_GPIO_PAR_FECI2C
);
278 writeb(v
| 0x0f, MCF_GPIO_PAR_FECI2C
);
281 /***************************************************************************/
283 static void m520x_cpu_reset(void)
286 __raw_writeb(MCF_RCR_SWRESET
, MCF_RCR
);
289 /***************************************************************************/
291 void __init
config_BSP(char *commandp
, int size
)
293 mach_reset
= m520x_cpu_reset
;
296 #if defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE)
301 /***************************************************************************/
303 static int __init
init_BSP(void)
305 platform_add_devices(m520x_devices
, ARRAY_SIZE(m520x_devices
));
309 arch_initcall(init_BSP
);
311 /***************************************************************************/