blob: 5b362da2dc09e391d0ce477831940c32876fa7f1 [file] [log] [blame]
Thomas Gleixnerc942fdd2019-05-27 08:55:06 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Ilya Yanok148854c2009-03-11 03:22:00 +03002/*
3 * Copyright (C) 2009 Ilya Yanok, Emcraft Systems Ltd, <yanok@emcraft.com>
Ilya Yanok148854c2009-03-11 03:22:00 +03004 */
5
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>
Boris Brezillonc7921bb2018-09-07 00:38:46 +020012#include <linux/mtd/platnand.h>
Ilya Yanok148854c2009-03-11 03:22:00 +030013#include <linux/gpio.h>
14
Ilya Yanok148854c2009-03-11 03:22:00 +030015#include <asm/mach-types.h>
16#include <asm/mach/arch.h>
17#include <asm/mach/time.h>
18#include <asm/mach/map.h>
Ilya Yanok148854c2009-03-11 03:22:00 +030019#include <asm/page.h>
20#include <asm/setup.h>
Uwe Kleine-König16cf5c42010-06-23 11:46:16 +020021
Shawn Guoe3372472012-09-13 21:01:00 +080022#include "common.h"
Uwe Kleine-König16cf5c42010-06-23 11:46:16 +020023#include "devices-imx31.h"
Shawn Guo50f2de62012-09-14 14:14:45 +080024#include "hardware.h"
Shawn Guo267dd342012-09-13 13:26:00 +080025#include "iomux-mx3.h"
Ilya Yanok148854c2009-03-11 03:22:00 +030026
27/* FPGA defines */
28#define QONG_FPGA_VERSION(major, minor, rev) \
29 (((major & 0xF) << 12) | ((minor & 0xF) << 8) | (rev & 0xFF))
30
Uwe Kleine-König27ad4bf2011-03-17 09:40:29 +010031#define QONG_FPGA_BASEADDR MX31_CS1_BASE_ADDR
32#define QONG_FPGA_PERIPH_SIZE (1 << 24)
Ilya Yanok148854c2009-03-11 03:22:00 +030033
34#define QONG_FPGA_CTRL_BASEADDR QONG_FPGA_BASEADDR
Uwe Kleine-König27ad4bf2011-03-17 09:40:29 +010035#define QONG_FPGA_CTRL_SIZE 0x10
Ilya Yanok148854c2009-03-11 03:22:00 +030036/* FPGA control registers */
37#define QONG_FPGA_CTRL_VERSION 0x00
38
39#define QONG_DNET_ID 1
40#define QONG_DNET_BASEADDR \
41 (QONG_FPGA_BASEADDR + QONG_DNET_ID * QONG_FPGA_PERIPH_SIZE)
Uwe Kleine-König27ad4bf2011-03-17 09:40:29 +010042#define QONG_DNET_SIZE 0x00001000
Ilya Yanok148854c2009-03-11 03:22:00 +030043
Uwe Kleine-König16cf5c42010-06-23 11:46:16 +020044static const struct imxuart_platform_data uart_pdata __initconst = {
Ilya Yanok148854c2009-03-11 03:22:00 +030045 .flags = IMXUART_HAVE_RTSCTS,
46};
47
48static int uart_pins[] = {
49 MX31_PIN_CTS1__CTS1,
50 MX31_PIN_RTS1__RTS1,
51 MX31_PIN_TXD1__TXD1,
52 MX31_PIN_RXD1__RXD1
53};
54
Uwe Kleine-König16cf5c42010-06-23 11:46:16 +020055static inline void __init mxc_init_imx_uart(void)
Ilya Yanok148854c2009-03-11 03:22:00 +030056{
57 mxc_iomux_setup_multiple_pins(uart_pins, ARRAY_SIZE(uart_pins),
58 "uart-0");
Uwe Kleine-König16cf5c42010-06-23 11:46:16 +020059 imx31_add_imx_uart0(&uart_pdata);
Ilya Yanok148854c2009-03-11 03:22:00 +030060}
61
62static struct resource dnet_resources[] = {
Sascha Hauer3f4f54b2009-06-23 12:12:00 +020063 {
Ilya Yanok148854c2009-03-11 03:22:00 +030064 .name = "dnet-memory",
65 .start = QONG_DNET_BASEADDR,
66 .end = QONG_DNET_BASEADDR + QONG_DNET_SIZE - 1,
67 .flags = IORESOURCE_MEM,
Sascha Hauer3f4f54b2009-06-23 12:12:00 +020068 }, {
Shawn Guoed175342011-12-02 20:00:33 +080069 /* irq number is run-time assigned */
Ilya Yanok148854c2009-03-11 03:22:00 +030070 .flags = IORESOURCE_IRQ,
71 },
72};
73
74static struct platform_device dnet_device = {
75 .name = "dnet",
76 .id = -1,
77 .num_resources = ARRAY_SIZE(dnet_resources),
78 .resource = dnet_resources,
79};
80
81static int __init qong_init_dnet(void)
82{
83 int ret;
84
Shawn Guoed175342011-12-02 20:00:33 +080085 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));
Ilya Yanok148854c2009-03-11 03:22:00 +030089 ret = platform_device_register(&dnet_device);
90 return ret;
91}
92
93/* MTD NOR flash */
94
95static struct physmap_flash_data qong_flash_data = {
96 .width = 2,
97};
98
99static struct resource qong_flash_resource = {
Uwe Kleine-Königf568dd72009-12-09 11:57:21 +0100100 .start = MX31_CS0_BASE_ADDR,
Uwe Kleine-Königd57351a2010-03-08 16:11:51 +0100101 .end = MX31_CS0_BASE_ADDR + SZ_128M - 1,
Ilya Yanok148854c2009-03-11 03:22:00 +0300102 .flags = IORESOURCE_MEM,
103};
104
105static struct platform_device qong_nor_mtd_device = {
106 .name = "physmap-flash",
107 .id = 0,
108 .dev = {
109 .platform_data = &qong_flash_data,
110 },
111 .resource = &qong_flash_resource,
112 .num_resources = 1,
113};
114
115static void qong_init_nor_mtd(void)
116{
117 (void)platform_device_register(&qong_nor_mtd_device);
118}
119
120/*
121 * Hardware specific access to control-lines
122 */
Boris Brezillon47bd59e2018-09-06 14:05:13 +0200123static void qong_nand_cmd_ctrl(struct nand_chip *nand_chip, int cmd,
124 unsigned int ctrl)
Ilya Yanok148854c2009-03-11 03:22:00 +0300125{
Ilya Yanok148854c2009-03-11 03:22:00 +0300126 if (cmd == NAND_CMD_NONE)
127 return;
128
129 if (ctrl & NAND_CLE)
Boris Brezillon82fc5092018-09-07 00:38:34 +0200130 writeb(cmd, nand_chip->legacy.IO_ADDR_W + (1 << 24));
Ilya Yanok148854c2009-03-11 03:22:00 +0300131 else
Boris Brezillon82fc5092018-09-07 00:38:34 +0200132 writeb(cmd, nand_chip->legacy.IO_ADDR_W + (1 << 23));
Ilya Yanok148854c2009-03-11 03:22:00 +0300133}
134
135/*
136 * Read the Device Ready pin.
137 */
Boris Brezillon47bd59e2018-09-06 14:05:13 +0200138static int qong_nand_device_ready(struct nand_chip *chip)
Ilya Yanok148854c2009-03-11 03:22:00 +0300139{
140 return gpio_get_value(IOMUX_TO_GPIO(MX31_PIN_NFRB));
141}
142
Boris Brezillon47bd59e2018-09-06 14:05:13 +0200143static void qong_nand_select_chip(struct nand_chip *chip, int cs)
Ilya Yanok148854c2009-03-11 03:22:00 +0300144{
Boris Brezillon47bd59e2018-09-06 14:05:13 +0200145 if (cs >= 0)
Ilya Yanok148854c2009-03-11 03:22:00 +0300146 gpio_set_value(IOMUX_TO_GPIO(MX31_PIN_NFCE_B), 0);
147 else
148 gpio_set_value(IOMUX_TO_GPIO(MX31_PIN_NFCE_B), 1);
149}
150
151static struct platform_nand_data qong_nand_data = {
152 .chip = {
Marek Vasutef077172010-08-12 02:14:54 +0100153 .nr_chips = 1,
Ilya Yanok148854c2009-03-11 03:22:00 +0300154 .chip_delay = 20,
155 .options = 0,
156 },
157 .ctrl = {
Uwe Kleine-König27ad4bf2011-03-17 09:40:29 +0100158 .cmd_ctrl = qong_nand_cmd_ctrl,
Ilya Yanok148854c2009-03-11 03:22:00 +0300159 .dev_ready = qong_nand_device_ready,
160 .select_chip = qong_nand_select_chip,
161 }
162};
163
164static struct resource qong_nand_resource = {
Uwe Kleine-König27ad4bf2011-03-17 09:40:29 +0100165 .start = MX31_CS3_BASE_ADDR,
166 .end = MX31_CS3_BASE_ADDR + SZ_32M - 1,
Ilya Yanok148854c2009-03-11 03:22:00 +0300167 .flags = IORESOURCE_MEM,
168};
169
170static struct platform_device qong_nand_device = {
171 .name = "gen_nand",
172 .id = -1,
173 .dev = {
174 .platform_data = &qong_nand_data,
175 },
176 .num_resources = 1,
177 .resource = &qong_nand_resource,
178};
179
180static void __init qong_init_nand_mtd(void)
181{
182 /* init CS */
Johannes Bergc5531382016-01-27 17:59:35 +0100183 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)));
Shawn Guof16fcb62011-10-17 14:15:06 +0800186
Ilya Yanok148854c2009-03-11 03:22:00 +0300187 mxc_iomux_set_gpr(MUX_SDCTL_CSD1_SEL, true);
188
189 /* enable pin */
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);
193
194 /* ready/busy pin */
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));
198
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));
203
204 platform_device_register(&qong_nand_device);
205}
206
207static void __init qong_init_fpga(void)
208{
209 void __iomem *regs;
210 u32 fpga_ver;
211
212 regs = ioremap(QONG_FPGA_CTRL_BASEADDR, QONG_FPGA_CTRL_SIZE);
213 if (!regs) {
214 printk(KERN_ERR "%s: failed to map registers, aborting.\n",
215 __func__);
216 return;
217 }
218
219 fpga_ver = readl(regs + QONG_FPGA_CTRL_VERSION);
220 iounmap(regs);
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");
227 return;
228 }
229
230 /* register FPGA-based devices */
231 qong_init_nand_mtd();
232 qong_init_dnet();
233}
234
235/*
Ilya Yanok148854c2009-03-11 03:22:00 +0300236 * Board specific initialization.
237 */
Uwe Kleine-Könige134fb22011-02-11 10:23:19 +0100238static void __init qong_init(void)
Ilya Yanok148854c2009-03-11 03:22:00 +0300239{
Shawn Guob78d8e52011-06-06 00:07:55 +0800240 imx31_soc_init();
241
Ilya Yanok148854c2009-03-11 03:22:00 +0300242 mxc_init_imx_uart();
243 qong_init_nor_mtd();
Benoît Thébaudeaubec31a82012-07-04 16:35:54 +0200244 imx31_add_imx2_wdt();
Ilya Yanok148854c2009-03-11 03:22:00 +0300245}
246
247static void __init qong_timer_init(void)
248{
249 mx31_clocks_init(26000000);
250}
251
Ilya Yanok148854c2009-03-11 03:22:00 +0300252MACHINE_START(QONG, "Dave/DENX QongEVB-LITE")
253 /* Maintainer: DENX Software Engineering GmbH */
Nicolas Pitredc8f1902011-07-05 22:38:12 -0400254 .atag_offset = 0x100,
Uwe Kleine-König97976e22011-02-07 16:35:20 +0100255 .map_io = mx31_map_io,
256 .init_early = imx31_init_early,
257 .init_irq = mx31_init_irq,
Stephen Warren6bb27d72012-11-08 12:40:59 -0700258 .init_time = qong_timer_init,
Uwe Kleine-Könige134fb22011-02-11 10:23:19 +0100259 .init_machine = qong_init,
Vladimir Zapolskiyc5f9cfe2016-09-19 04:37:19 +0300260 .init_late = qong_init_fpga,
Russell King65ea7882011-11-06 17:12:08 +0000261 .restart = mxc_restart,
Ilya Yanok148854c2009-03-11 03:22:00 +0300262MACHINE_END