blob: e31e8cdcb296bfadc9c6ab2f394e089b4f48ad4b [file] [log] [blame]
Ralf Baechle73b43902008-07-16 16:12:25 +01001/*
2 * RouterBoard 500 Platform devices
3 *
4 * Copyright (C) 2006 Felix Fietkau <nbd@openwrt.org>
5 * Copyright (C) 2007 Florian Fainelli <florian@openwrt.org>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */
17#include <linux/kernel.h>
Paul Gortmakerf9ded562012-02-28 19:24:46 -050018#include <linux/export.h>
Ralf Baechle73b43902008-07-16 16:12:25 +010019#include <linux/init.h>
20#include <linux/ctype.h>
21#include <linux/string.h>
22#include <linux/platform_device.h>
23#include <linux/mtd/nand.h>
24#include <linux/mtd/mtd.h>
25#include <linux/mtd/partitions.h>
26#include <linux/gpio_keys.h>
27#include <linux/input.h>
Phil Sutter1452fc72009-01-15 15:38:38 +010028#include <linux/serial_8250.h>
Ralf Baechle73b43902008-07-16 16:12:25 +010029
30#include <asm/bootinfo.h>
31
32#include <asm/mach-rc32434/rc32434.h>
33#include <asm/mach-rc32434/dma.h>
34#include <asm/mach-rc32434/dma_v.h>
35#include <asm/mach-rc32434/eth.h>
36#include <asm/mach-rc32434/rb.h>
37#include <asm/mach-rc32434/integ.h>
38#include <asm/mach-rc32434/gpio.h>
Florian Fainelli3cd4e062008-08-22 17:00:22 +020039#include <asm/mach-rc32434/irq.h>
Ralf Baechle73b43902008-07-16 16:12:25 +010040
41#define ETH0_RX_DMA_ADDR (DMA0_BASE_ADDR + 0 * DMA_CHAN_OFFSET)
42#define ETH0_TX_DMA_ADDR (DMA0_BASE_ADDR + 1 * DMA_CHAN_OFFSET)
43
Phil Sutter1452fc72009-01-15 15:38:38 +010044extern unsigned int idt_cpu_freq;
45
Phil Sutter36f2db42009-01-19 23:42:52 +010046static struct mpmc_device dev3;
47
48void set_latch_u5(unsigned char or_mask, unsigned char nand_mask)
49{
50 unsigned long flags;
51
52 spin_lock_irqsave(&dev3.lock, flags);
53
54 dev3.state = (dev3.state | or_mask) & ~nand_mask;
55 writeb(dev3.state, dev3.base);
56
57 spin_unlock_irqrestore(&dev3.lock, flags);
58}
59EXPORT_SYMBOL(set_latch_u5);
60
61unsigned char get_latch_u5(void)
62{
63 return dev3.state;
64}
65EXPORT_SYMBOL(get_latch_u5);
66
Ralf Baechle73b43902008-07-16 16:12:25 +010067static struct resource korina_dev0_res[] = {
68 {
69 .name = "korina_regs",
70 .start = ETH0_BASE_ADDR,
71 .end = ETH0_BASE_ADDR + sizeof(struct eth_regs),
72 .flags = IORESOURCE_MEM,
73 }, {
74 .name = "korina_rx",
75 .start = ETH0_DMA_RX_IRQ,
76 .end = ETH0_DMA_RX_IRQ,
77 .flags = IORESOURCE_IRQ
78 }, {
79 .name = "korina_tx",
80 .start = ETH0_DMA_TX_IRQ,
81 .end = ETH0_DMA_TX_IRQ,
82 .flags = IORESOURCE_IRQ
83 }, {
84 .name = "korina_ovr",
85 .start = ETH0_RX_OVR_IRQ,
86 .end = ETH0_RX_OVR_IRQ,
87 .flags = IORESOURCE_IRQ
88 }, {
89 .name = "korina_und",
90 .start = ETH0_TX_UND_IRQ,
91 .end = ETH0_TX_UND_IRQ,
92 .flags = IORESOURCE_IRQ
93 }, {
94 .name = "korina_dma_rx",
95 .start = ETH0_RX_DMA_ADDR,
96 .end = ETH0_RX_DMA_ADDR + DMA_CHAN_OFFSET - 1,
97 .flags = IORESOURCE_MEM,
98 }, {
99 .name = "korina_dma_tx",
100 .start = ETH0_TX_DMA_ADDR,
101 .end = ETH0_TX_DMA_ADDR + DMA_CHAN_OFFSET - 1,
102 .flags = IORESOURCE_MEM,
103 }
104};
105
106static struct korina_device korina_dev0_data = {
107 .name = "korina0",
108 .mac = {0xde, 0xca, 0xff, 0xc0, 0xff, 0xee}
109};
110
111static struct platform_device korina_dev0 = {
Florian Fainellib6e2f582008-08-22 17:03:03 +0200112 .id = -1,
Ralf Baechle73b43902008-07-16 16:12:25 +0100113 .name = "korina",
Ralf Baechle73b43902008-07-16 16:12:25 +0100114 .resource = korina_dev0_res,
115 .num_resources = ARRAY_SIZE(korina_dev0_res),
116};
117
Ralf Baechle73b43902008-07-16 16:12:25 +0100118static struct resource cf_slot0_res[] = {
119 {
120 .name = "cf_membase",
121 .flags = IORESOURCE_MEM
122 }, {
123 .name = "cf_irq",
124 .start = (8 + 4 * 32 + CF_GPIO_NUM), /* 149 */
125 .end = (8 + 4 * 32 + CF_GPIO_NUM),
126 .flags = IORESOURCE_IRQ
127 }
128};
129
130static struct cf_device cf_slot0_data = {
Florian Fainelli3cd4e062008-08-22 17:00:22 +0200131 .gpio_pin = CF_GPIO_NUM
Ralf Baechle73b43902008-07-16 16:12:25 +0100132};
133
134static struct platform_device cf_slot0 = {
Florian Fainellib6e2f582008-08-22 17:03:03 +0200135 .id = -1,
Ralf Baechle73b43902008-07-16 16:12:25 +0100136 .name = "pata-rb532-cf",
137 .dev.platform_data = &cf_slot0_data,
138 .resource = cf_slot0_res,
139 .num_resources = ARRAY_SIZE(cf_slot0_res),
140};
141
142/* Resources and device for NAND */
143static int rb532_dev_ready(struct mtd_info *mtd)
144{
Florian Fainelli1b432842008-10-31 14:24:29 +0100145 return gpio_get_value(GPIO_RDY);
Ralf Baechle73b43902008-07-16 16:12:25 +0100146}
147
148static void rb532_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
149{
150 struct nand_chip *chip = mtd->priv;
151 unsigned char orbits, nandbits;
152
153 if (ctrl & NAND_CTRL_CHANGE) {
154 orbits = (ctrl & NAND_CLE) << 1;
155 orbits |= (ctrl & NAND_ALE) >> 1;
156
157 nandbits = (~ctrl & NAND_CLE) << 1;
158 nandbits |= (~ctrl & NAND_ALE) >> 1;
159
160 set_latch_u5(orbits, nandbits);
161 }
162 if (cmd != NAND_CMD_NONE)
163 writeb(cmd, chip->IO_ADDR_W);
164}
165
166static struct resource nand_slot0_res[] = {
167 [0] = {
168 .name = "nand_membase",
169 .flags = IORESOURCE_MEM
170 }
171};
172
173static struct platform_nand_data rb532_nand_data = {
174 .ctrl.dev_ready = rb532_dev_ready,
175 .ctrl.cmd_ctrl = rb532_cmd_ctrl,
176};
177
178static struct platform_device nand_slot0 = {
179 .name = "gen_nand",
180 .id = -1,
181 .resource = nand_slot0_res,
182 .num_resources = ARRAY_SIZE(nand_slot0_res),
183 .dev.platform_data = &rb532_nand_data,
184};
185
186static struct mtd_partition rb532_partition_info[] = {
187 {
188 .name = "Routerboard NAND boot",
189 .offset = 0,
190 .size = 4 * 1024 * 1024,
191 }, {
192 .name = "rootfs",
193 .offset = MTDPART_OFS_NXTBLK,
194 .size = MTDPART_SIZ_FULL,
195 }
196};
197
198static struct platform_device rb532_led = {
199 .name = "rb532-led",
Florian Fainellib6e2f582008-08-22 17:03:03 +0200200 .id = -1,
Ralf Baechle73b43902008-07-16 16:12:25 +0100201};
202
Ralf Baechle73b43902008-07-16 16:12:25 +0100203static struct platform_device rb532_button = {
Phil Sutterd9bdffd2009-03-04 23:27:15 -0800204 .name = "rb532-button",
Ralf Baechle73b43902008-07-16 16:12:25 +0100205 .id = -1,
Ralf Baechle73b43902008-07-16 16:12:25 +0100206};
207
208static struct resource rb532_wdt_res[] = {
209 {
210 .name = "rb532_wdt_res",
211 .start = INTEG0_BASE_ADDR,
212 .end = INTEG0_BASE_ADDR + sizeof(struct integ),
213 .flags = IORESOURCE_MEM,
214 }
215};
216
217static struct platform_device rb532_wdt = {
Ralf Baechle70342282013-01-22 12:59:30 +0100218 .name = "rc32434_wdt",
219 .id = -1,
220 .resource = rb532_wdt_res,
Ralf Baechle73b43902008-07-16 16:12:25 +0100221 .num_resources = ARRAY_SIZE(rb532_wdt_res),
222};
223
Phil Sutter1452fc72009-01-15 15:38:38 +0100224static struct plat_serial8250_port rb532_uart_res[] = {
225 {
Waldemar Brodkorbf98fd442014-07-03 16:17:53 +0200226 .type = PORT_16550A,
Phil Sutter1452fc72009-01-15 15:38:38 +0100227 .membase = (char *)KSEG1ADDR(REGBASE + UART0BASE),
228 .irq = UART0_IRQ,
229 .regshift = 2,
230 .iotype = UPIO_MEM,
231 .flags = UPF_BOOT_AUTOCONF,
232 },
233 {
234 .flags = 0,
235 }
236};
237
238static struct platform_device rb532_uart = {
Ralf Baechle70342282013-01-22 12:59:30 +0100239 .name = "serial8250",
240 .id = PLAT8250_DEV_PLATFORM,
Phil Sutter1452fc72009-01-15 15:38:38 +0100241 .dev.platform_data = &rb532_uart_res,
242};
243
Ralf Baechle73b43902008-07-16 16:12:25 +0100244static struct platform_device *rb532_devs[] = {
245 &korina_dev0,
246 &nand_slot0,
247 &cf_slot0,
248 &rb532_led,
249 &rb532_button,
Phil Sutter1452fc72009-01-15 15:38:38 +0100250 &rb532_uart,
Ralf Baechle73b43902008-07-16 16:12:25 +0100251 &rb532_wdt
252};
253
Ralf Baechle73b43902008-07-16 16:12:25 +0100254/* NAND definitions */
Ralf Baechle70342282013-01-22 12:59:30 +0100255#define NAND_CHIP_DELAY 25
Ralf Baechle73b43902008-07-16 16:12:25 +0100256
257static void __init rb532_nand_setup(void)
258{
259 switch (mips_machtype) {
260 case MACH_MIKROTIK_RB532A:
261 set_latch_u5(LO_FOFF | LO_CEX,
262 LO_ULED | LO_ALE | LO_CLE | LO_WPX);
263 break;
264 default:
265 set_latch_u5(LO_WPX | LO_FOFF | LO_CEX,
266 LO_ULED | LO_ALE | LO_CLE);
267 break;
268 }
269
270 /* Setup NAND specific settings */
271 rb532_nand_data.chip.nr_chips = 1;
272 rb532_nand_data.chip.nr_partitions = ARRAY_SIZE(rb532_partition_info);
273 rb532_nand_data.chip.partitions = rb532_partition_info;
274 rb532_nand_data.chip.chip_delay = NAND_CHIP_DELAY;
Ralf Baechle73b43902008-07-16 16:12:25 +0100275}
276
277
278static int __init plat_setup_devices(void)
279{
280 /* Look for the CF card reader */
Florian Fainelli1ddfe82d2008-08-05 22:24:18 +0200281 if (!readl(IDT434_REG_BASE + DEV1MASK))
Phil Sutterbc4c4e82008-10-27 02:29:57 +0100282 rb532_devs[2] = NULL; /* disable cf_slot0 at index 2 */
Ralf Baechle73b43902008-07-16 16:12:25 +0100283 else {
284 cf_slot0_res[0].start =
Florian Fainelli1ddfe82d2008-08-05 22:24:18 +0200285 readl(IDT434_REG_BASE + DEV1BASE);
Ralf Baechle73b43902008-07-16 16:12:25 +0100286 cf_slot0_res[0].end = cf_slot0_res[0].start + 0x1000;
287 }
288
289 /* Read the NAND resources from the device controller */
Florian Fainelli1ddfe82d2008-08-05 22:24:18 +0200290 nand_slot0_res[0].start = readl(IDT434_REG_BASE + DEV2BASE);
Ralf Baechle73b43902008-07-16 16:12:25 +0100291 nand_slot0_res[0].end = nand_slot0_res[0].start + 0x1000;
292
Phil Sutter1c4db8e2009-01-19 23:42:54 +0100293 /* Read and map device controller 3 */
294 dev3.base = ioremap_nocache(readl(IDT434_REG_BASE + DEV3BASE), 1);
Phil Sutter36f2db42009-01-19 23:42:52 +0100295
296 if (!dev3.base) {
297 printk(KERN_ERR "rb532: cannot remap device controller 3\n");
298 return -ENXIO;
299 }
300
Ralf Baechle73b43902008-07-16 16:12:25 +0100301 /* Initialise the NAND device */
302 rb532_nand_setup();
303
Phil Sutter1452fc72009-01-15 15:38:38 +0100304 /* set the uart clock to the current cpu frequency */
305 rb532_uart_res[0].uartclk = idt_cpu_freq;
306
Florian Fainelli4e7c81a2009-12-02 13:07:01 +0100307 dev_set_drvdata(&korina_dev0.dev, &korina_dev0_data);
308
Ralf Baechle73b43902008-07-16 16:12:25 +0100309 return platform_add_devices(rb532_devs, ARRAY_SIZE(rb532_devs));
310}
311
312static int __init setup_kmac(char *s)
313{
314 printk(KERN_INFO "korina mac = %s\n", s);
Daniel Walter9e21c7e2014-06-24 12:14:26 +0100315 if (!mac_pton(s, korina_dev0_data.mac)) {
316 printk(KERN_ERR "Invalid mac\n");
317 return -EINVAL;
318 }
Ralf Baechle73b43902008-07-16 16:12:25 +0100319 return 0;
320}
321
322__setup("kmac=", setup_kmac);
323
324arch_initcall(plat_setup_devices);