2 * device.c -- common ColdFire SoC device support
4 * (C) Copyright 2011, Greg Ungerer <gerg@uclinux.org>
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file COPYING in the main directory of this archive
11 #include <linux/kernel.h>
12 #include <linux/init.h>
14 #include <linux/spi/spi.h>
15 #include <linux/gpio.h>
16 #include <linux/fec.h>
17 #include <asm/traps.h>
18 #include <asm/coldfire.h>
19 #include <asm/mcfsim.h>
20 #include <asm/mcfuart.h>
21 #include <asm/mcfqspi.h>
24 * All current ColdFire parts contain from 2, 3, 4 or 10 UARTS.
26 static struct mcf_platform_uart mcf_uart_platform_data
[] = {
28 .mapbase
= MCFUART_BASE0
,
32 .mapbase
= MCFUART_BASE1
,
37 .mapbase
= MCFUART_BASE2
,
43 .mapbase
= MCFUART_BASE3
,
49 .mapbase
= MCFUART_BASE4
,
55 .mapbase
= MCFUART_BASE5
,
61 .mapbase
= MCFUART_BASE6
,
67 .mapbase
= MCFUART_BASE7
,
73 .mapbase
= MCFUART_BASE8
,
79 .mapbase
= MCFUART_BASE9
,
86 static struct platform_device mcf_uart
= {
89 .dev
.platform_data
= mcf_uart_platform_data
,
92 #if IS_ENABLED(CONFIG_FEC)
95 #define FEC_NAME "enet-fec"
96 static struct fec_platform_data fec_pdata
= {
97 .phy
= PHY_INTERFACE_MODE_RMII
,
99 #define FEC_PDATA (&fec_pdata)
101 #define FEC_NAME "fec"
102 #define FEC_PDATA NULL
106 * Some ColdFire cores contain the Fast Ethernet Controller (FEC)
107 * block. It is Freescale's own hardware block. Some ColdFires
110 static struct resource mcf_fec0_resources
[] = {
112 .start
= MCFFEC_BASE0
,
113 .end
= MCFFEC_BASE0
+ MCFFEC_SIZE0
- 1,
114 .flags
= IORESOURCE_MEM
,
117 .start
= MCF_IRQ_FECRX0
,
118 .end
= MCF_IRQ_FECRX0
,
119 .flags
= IORESOURCE_IRQ
,
122 .start
= MCF_IRQ_FECTX0
,
123 .end
= MCF_IRQ_FECTX0
,
124 .flags
= IORESOURCE_IRQ
,
127 .start
= MCF_IRQ_FECENTC0
,
128 .end
= MCF_IRQ_FECENTC0
,
129 .flags
= IORESOURCE_IRQ
,
133 static struct platform_device mcf_fec0
= {
136 .num_resources
= ARRAY_SIZE(mcf_fec0_resources
),
137 .resource
= mcf_fec0_resources
,
138 .dev
.platform_data
= FEC_PDATA
,
142 static struct resource mcf_fec1_resources
[] = {
144 .start
= MCFFEC_BASE1
,
145 .end
= MCFFEC_BASE1
+ MCFFEC_SIZE1
- 1,
146 .flags
= IORESOURCE_MEM
,
149 .start
= MCF_IRQ_FECRX1
,
150 .end
= MCF_IRQ_FECRX1
,
151 .flags
= IORESOURCE_IRQ
,
154 .start
= MCF_IRQ_FECTX1
,
155 .end
= MCF_IRQ_FECTX1
,
156 .flags
= IORESOURCE_IRQ
,
159 .start
= MCF_IRQ_FECENTC1
,
160 .end
= MCF_IRQ_FECENTC1
,
161 .flags
= IORESOURCE_IRQ
,
165 static struct platform_device mcf_fec1
= {
168 .num_resources
= ARRAY_SIZE(mcf_fec1_resources
),
169 .resource
= mcf_fec1_resources
,
170 .dev
.platform_data
= FEC_PDATA
,
172 #endif /* MCFFEC_BASE1 */
173 #endif /* CONFIG_FEC */
175 #if IS_ENABLED(CONFIG_SPI_COLDFIRE_QSPI)
177 * The ColdFire QSPI module is an SPI protocol hardware block used
178 * on a number of different ColdFire CPUs.
180 static struct resource mcf_qspi_resources
[] = {
182 .start
= MCFQSPI_BASE
,
183 .end
= MCFQSPI_BASE
+ MCFQSPI_SIZE
- 1,
184 .flags
= IORESOURCE_MEM
,
187 .start
= MCF_IRQ_QSPI
,
189 .flags
= IORESOURCE_IRQ
,
193 static int mcf_cs_setup(struct mcfqspi_cs_control
*cs_control
)
197 status
= gpio_request(MCFQSPI_CS0
, "MCFQSPI_CS0");
199 pr_debug("gpio_request for MCFQSPI_CS0 failed\n");
202 status
= gpio_direction_output(MCFQSPI_CS0
, 1);
204 pr_debug("gpio_direction_output for MCFQSPI_CS0 failed\n");
208 status
= gpio_request(MCFQSPI_CS1
, "MCFQSPI_CS1");
210 pr_debug("gpio_request for MCFQSPI_CS1 failed\n");
213 status
= gpio_direction_output(MCFQSPI_CS1
, 1);
215 pr_debug("gpio_direction_output for MCFQSPI_CS1 failed\n");
219 status
= gpio_request(MCFQSPI_CS2
, "MCFQSPI_CS2");
221 pr_debug("gpio_request for MCFQSPI_CS2 failed\n");
224 status
= gpio_direction_output(MCFQSPI_CS2
, 1);
226 pr_debug("gpio_direction_output for MCFQSPI_CS2 failed\n");
231 status
= gpio_request(MCFQSPI_CS3
, "MCFQSPI_CS3");
233 pr_debug("gpio_request for MCFQSPI_CS3 failed\n");
236 status
= gpio_direction_output(MCFQSPI_CS3
, 1);
238 pr_debug("gpio_direction_output for MCFQSPI_CS3 failed\n");
239 gpio_free(MCFQSPI_CS3
);
247 gpio_free(MCFQSPI_CS2
);
249 gpio_free(MCFQSPI_CS1
);
251 gpio_free(MCFQSPI_CS0
);
256 static void mcf_cs_teardown(struct mcfqspi_cs_control
*cs_control
)
259 gpio_free(MCFQSPI_CS3
);
261 gpio_free(MCFQSPI_CS2
);
262 gpio_free(MCFQSPI_CS1
);
263 gpio_free(MCFQSPI_CS0
);
266 static void mcf_cs_select(struct mcfqspi_cs_control
*cs_control
,
267 u8 chip_select
, bool cs_high
)
269 switch (chip_select
) {
271 gpio_set_value(MCFQSPI_CS0
, cs_high
);
274 gpio_set_value(MCFQSPI_CS1
, cs_high
);
277 gpio_set_value(MCFQSPI_CS2
, cs_high
);
281 gpio_set_value(MCFQSPI_CS3
, cs_high
);
287 static void mcf_cs_deselect(struct mcfqspi_cs_control
*cs_control
,
288 u8 chip_select
, bool cs_high
)
290 switch (chip_select
) {
292 gpio_set_value(MCFQSPI_CS0
, !cs_high
);
295 gpio_set_value(MCFQSPI_CS1
, !cs_high
);
298 gpio_set_value(MCFQSPI_CS2
, !cs_high
);
302 gpio_set_value(MCFQSPI_CS3
, !cs_high
);
308 static struct mcfqspi_cs_control mcf_cs_control
= {
309 .setup
= mcf_cs_setup
,
310 .teardown
= mcf_cs_teardown
,
311 .select
= mcf_cs_select
,
312 .deselect
= mcf_cs_deselect
,
315 static struct mcfqspi_platform_data mcf_qspi_data
= {
318 .cs_control
= &mcf_cs_control
,
321 static struct platform_device mcf_qspi
= {
324 .num_resources
= ARRAY_SIZE(mcf_qspi_resources
),
325 .resource
= mcf_qspi_resources
,
326 .dev
.platform_data
= &mcf_qspi_data
,
328 #endif /* IS_ENABLED(CONFIG_SPI_COLDFIRE_QSPI) */
330 static struct platform_device
*mcf_devices
[] __initdata
= {
332 #if IS_ENABLED(CONFIG_FEC)
338 #if IS_ENABLED(CONFIG_SPI_COLDFIRE_QSPI)
344 * Some ColdFire UARTs let you set the IRQ line to use.
346 static void __init
mcf_uart_set_irq(void)
349 /* UART0 interrupt setup */
350 writeb(MCFSIM_ICR_LEVEL6
| MCFSIM_ICR_PRI1
, MCFSIM_UART1ICR
);
351 writeb(MCF_IRQ_UART0
, MCFUART_BASE0
+ MCFUART_UIVR
);
352 mcf_mapirq2imr(MCF_IRQ_UART0
, MCFINTC_UART0
);
354 /* UART1 interrupt setup */
355 writeb(MCFSIM_ICR_LEVEL6
| MCFSIM_ICR_PRI2
, MCFSIM_UART2ICR
);
356 writeb(MCF_IRQ_UART1
, MCFUART_BASE1
+ MCFUART_UIVR
);
357 mcf_mapirq2imr(MCF_IRQ_UART1
, MCFINTC_UART1
);
361 static int __init
mcf_init_devices(void)
364 platform_add_devices(mcf_devices
, ARRAY_SIZE(mcf_devices
));
368 arch_initcall(mcf_init_devices
);