1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2009 Ilya Yanok, Emcraft Systems Ltd, <yanok@emcraft.com>
6 #include <linux/types.h>
7 #include <linux/init.h>
8 #include <linux/kernel.h>
9 #include <linux/memory.h>
10 #include <linux/platform_device.h>
11 #include <linux/mtd/physmap.h>
12 #include <linux/mtd/platnand.h>
13 #include <linux/gpio.h>
15 #include <asm/mach-types.h>
16 #include <asm/mach/arch.h>
17 #include <asm/mach/time.h>
18 #include <asm/mach/map.h>
20 #include <asm/setup.h>
23 #include "devices-imx31.h"
25 #include "iomux-mx3.h"
28 #define QONG_FPGA_VERSION(major, minor, rev) \
29 (((major & 0xF) << 12) | ((minor & 0xF) << 8) | (rev & 0xFF))
31 #define QONG_FPGA_BASEADDR MX31_CS1_BASE_ADDR
32 #define QONG_FPGA_PERIPH_SIZE (1 << 24)
34 #define QONG_FPGA_CTRL_BASEADDR QONG_FPGA_BASEADDR
35 #define QONG_FPGA_CTRL_SIZE 0x10
36 /* FPGA control registers */
37 #define QONG_FPGA_CTRL_VERSION 0x00
39 #define QONG_DNET_ID 1
40 #define QONG_DNET_BASEADDR \
41 (QONG_FPGA_BASEADDR + QONG_DNET_ID * QONG_FPGA_PERIPH_SIZE)
42 #define QONG_DNET_SIZE 0x00001000
44 static const struct imxuart_platform_data uart_pdata __initconst
= {
45 .flags
= IMXUART_HAVE_RTSCTS
,
48 static int uart_pins
[] = {
55 static inline void __init
mxc_init_imx_uart(void)
57 mxc_iomux_setup_multiple_pins(uart_pins
, ARRAY_SIZE(uart_pins
),
59 imx31_add_imx_uart0(&uart_pdata
);
62 static struct resource dnet_resources
[] = {
64 .name
= "dnet-memory",
65 .start
= QONG_DNET_BASEADDR
,
66 .end
= QONG_DNET_BASEADDR
+ QONG_DNET_SIZE
- 1,
67 .flags
= IORESOURCE_MEM
,
69 /* irq number is run-time assigned */
70 .flags
= IORESOURCE_IRQ
,
74 static struct platform_device dnet_device
= {
77 .num_resources
= ARRAY_SIZE(dnet_resources
),
78 .resource
= dnet_resources
,
81 static int __init
qong_init_dnet(void)
85 dnet_resources
[1].start
=
86 gpio_to_irq(IOMUX_TO_GPIO(MX31_PIN_DTR_DCE1
));
87 dnet_resources
[1].end
=
88 gpio_to_irq(IOMUX_TO_GPIO(MX31_PIN_DTR_DCE1
));
89 ret
= platform_device_register(&dnet_device
);
95 static struct physmap_flash_data qong_flash_data
= {
99 static struct resource qong_flash_resource
= {
100 .start
= MX31_CS0_BASE_ADDR
,
101 .end
= MX31_CS0_BASE_ADDR
+ SZ_128M
- 1,
102 .flags
= IORESOURCE_MEM
,
105 static struct platform_device qong_nor_mtd_device
= {
106 .name
= "physmap-flash",
109 .platform_data
= &qong_flash_data
,
111 .resource
= &qong_flash_resource
,
115 static void qong_init_nor_mtd(void)
117 (void)platform_device_register(&qong_nor_mtd_device
);
121 * Hardware specific access to control-lines
123 static void qong_nand_cmd_ctrl(struct nand_chip
*nand_chip
, int cmd
,
126 if (cmd
== NAND_CMD_NONE
)
130 writeb(cmd
, nand_chip
->legacy
.IO_ADDR_W
+ (1 << 24));
132 writeb(cmd
, nand_chip
->legacy
.IO_ADDR_W
+ (1 << 23));
136 * Read the Device Ready pin.
138 static int qong_nand_device_ready(struct nand_chip
*chip
)
140 return gpio_get_value(IOMUX_TO_GPIO(MX31_PIN_NFRB
));
143 static void qong_nand_select_chip(struct nand_chip
*chip
, int cs
)
146 gpio_set_value(IOMUX_TO_GPIO(MX31_PIN_NFCE_B
), 0);
148 gpio_set_value(IOMUX_TO_GPIO(MX31_PIN_NFCE_B
), 1);
151 static struct platform_nand_data qong_nand_data
= {
158 .cmd_ctrl
= qong_nand_cmd_ctrl
,
159 .dev_ready
= qong_nand_device_ready
,
160 .select_chip
= qong_nand_select_chip
,
164 static struct resource qong_nand_resource
= {
165 .start
= MX31_CS3_BASE_ADDR
,
166 .end
= MX31_CS3_BASE_ADDR
+ SZ_32M
- 1,
167 .flags
= IORESOURCE_MEM
,
170 static struct platform_device qong_nand_device
= {
174 .platform_data
= &qong_nand_data
,
177 .resource
= &qong_nand_resource
,
180 static void __init
qong_init_nand_mtd(void)
183 imx_writel(0x00004f00, MX31_IO_ADDRESS(MX31_WEIM_CSCRxU(3)));
184 imx_writel(0x20013b31, MX31_IO_ADDRESS(MX31_WEIM_CSCRxL(3)));
185 imx_writel(0x00020800, MX31_IO_ADDRESS(MX31_WEIM_CSCRxA(3)));
187 mxc_iomux_set_gpr(MUX_SDCTL_CSD1_SEL
, true);
190 mxc_iomux_mode(IOMUX_MODE(MX31_PIN_NFCE_B
, IOMUX_CONFIG_GPIO
));
191 if (!gpio_request(IOMUX_TO_GPIO(MX31_PIN_NFCE_B
), "nand_enable"))
192 gpio_direction_output(IOMUX_TO_GPIO(MX31_PIN_NFCE_B
), 0);
195 mxc_iomux_mode(IOMUX_MODE(MX31_PIN_NFRB
, IOMUX_CONFIG_GPIO
));
196 if (!gpio_request(IOMUX_TO_GPIO(MX31_PIN_NFRB
), "nand_rdy"))
197 gpio_direction_input(IOMUX_TO_GPIO(MX31_PIN_NFRB
));
199 /* write protect pin */
200 mxc_iomux_mode(IOMUX_MODE(MX31_PIN_NFWP_B
, IOMUX_CONFIG_GPIO
));
201 if (!gpio_request(IOMUX_TO_GPIO(MX31_PIN_NFWP_B
), "nand_wp"))
202 gpio_direction_input(IOMUX_TO_GPIO(MX31_PIN_NFWP_B
));
204 platform_device_register(&qong_nand_device
);
207 static void __init
qong_init_fpga(void)
212 regs
= ioremap(QONG_FPGA_CTRL_BASEADDR
, QONG_FPGA_CTRL_SIZE
);
214 printk(KERN_ERR
"%s: failed to map registers, aborting.\n",
219 fpga_ver
= readl(regs
+ QONG_FPGA_CTRL_VERSION
);
221 printk(KERN_INFO
"Qong FPGA version %d.%d.%d\n",
222 (fpga_ver
& 0xF000) >> 12,
223 (fpga_ver
& 0x0F00) >> 8, fpga_ver
& 0x00FF);
224 if (fpga_ver
< QONG_FPGA_VERSION(0, 8, 7)) {
225 printk(KERN_ERR
"qong: Unexpected FPGA version, FPGA-based "
226 "devices won't be registered!\n");
230 /* register FPGA-based devices */
231 qong_init_nand_mtd();
236 * Board specific initialization.
238 static void __init
qong_init(void)
244 imx31_add_imx2_wdt();
247 static void __init
qong_timer_init(void)
249 mx31_clocks_init(26000000);
252 MACHINE_START(QONG
, "Dave/DENX QongEVB-LITE")
253 /* Maintainer: DENX Software Engineering GmbH */
254 .atag_offset
= 0x100,
255 .map_io
= mx31_map_io
,
256 .init_early
= imx31_init_early
,
257 .init_irq
= mx31_init_irq
,
258 .init_time
= qong_timer_init
,
259 .init_machine
= qong_init
,
260 .init_late
= qong_init_fpga
,
261 .restart
= mxc_restart
,