d81e0cf33f003b7fd8146bd0bdeefaf0349b3f96
[openwrt.git] / target / linux / adm5120 / files / arch / mips / adm5120 / boards / mikrotik.c
1 /*
2 * $Id$
3 *
4 * Mikrotik RouterBOARD 1xx series
5 *
6 * Copyright (C) 2007 OpenWrt.org
7 * Copyright (C) 2007 Gabor Juhos <juhosg at openwrt.org>
8 *
9 * NAND initialization code was based on a driver for Linux 2.6.19+ which
10 * was derived from the driver for Linux 2.4.xx published by Mikrotik for
11 * their RouterBoard 1xx and 5xx series boards.
12 * Copyright (C) 2007 David Goodenough <david.goodenough@linkchoose.co.uk>
13 * Copyright (C) 2007 Florian Fainelli <florian@openwrt.org>
14 * The original Mikrotik code seems not to have a license.
15 *
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the
28 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
29 * Boston, MA 02110-1301, USA.
30 *
31 */
32
33 #include <linux/kernel.h>
34 #include <linux/init.h>
35 #include <linux/delay.h>
36
37 #include <asm/bootinfo.h>
38 #include <asm/gpio.h>
39
40 #include <adm5120_defs.h>
41 #include <adm5120_irq.h>
42 #include <adm5120_nand.h>
43 #include <adm5120_board.h>
44 #include <adm5120_platform.h>
45 #include <adm5120_cf.h>
46
47 #define RB1XX_NAND_CHIP_DELAY 25
48
49 #define RB150_NAND_BASE 0x1FC80000
50 #define RB150_NAND_SIZE 1
51
52 #define RB150_GPIO_NAND_READY ADM5120_GPIO_PIN0
53 #define RB150_GPIO_NAND_NCE ADM5120_GPIO_PIN1
54 #define RB150_GPIO_NAND_CLE ADM5120_GPIO_P2L2
55 #define RB150_GPIO_NAND_ALE ADM5120_GPIO_P3L2
56
57 #define RB150_NAND_DELAY 100
58
59 #define RB150_NAND_WRITE(v) \
60 writeb((v), (void __iomem *)KSEG1ADDR(RB150_NAND_BASE))
61
62 #define RB153_GPIO_CF_RDY ADM5120_GPIO_P1L1
63 #define RB153_GPIO_CF_WT ADM5120_GPIO_P0L0
64
65 /*--------------------------------------------------------------------------*/
66
67 static struct adm5120_pci_irq rb1xx_pci_irqs[] __initdata = {
68 PCIIRQ(1, 0, 1, ADM5120_IRQ_PCI0),
69 PCIIRQ(2, 0, 1, ADM5120_IRQ_PCI1),
70 PCIIRQ(3, 0, 1, ADM5120_IRQ_PCI2)
71 };
72
73 static struct mtd_partition rb1xx_nor_parts[] = {
74 {
75 .name = "booter",
76 .offset = 0,
77 .size = 64*1024,
78 .mask_flags = MTD_WRITEABLE,
79 } , {
80 .name = "firmware",
81 .offset = MTDPART_OFS_APPEND,
82 .size = MTDPART_SIZ_FULL,
83 }
84 };
85
86 static struct mtd_partition rb1xx_nand_parts[] = {
87 {
88 .name = "kernel",
89 .offset = 0,
90 .size = 4 * 1024 * 1024,
91 } , {
92 .name = "rootfs",
93 .offset = MTDPART_OFS_NXTBLK,
94 .size = MTDPART_SIZ_FULL
95 }
96 };
97
98 static struct platform_device *rb1xx_devices[] __initdata = {
99 &adm5120_flash0_device,
100 &adm5120_nand_device,
101 };
102
103 /*
104 * We need to use the OLD Yaffs-1 OOB layout, otherwise the RB bootloader
105 * will not be able to find the kernel that we load. So set the oobinfo
106 * when creating the partitions
107 */
108 static struct nand_ecclayout rb1xx_nand_ecclayout = {
109 .eccbytes = 6,
110 .eccpos = { 8, 9, 10, 13, 14, 15 },
111 .oobavail = 9,
112 .oobfree = { { 0, 4 }, { 6, 2 }, { 11, 2 }, { 4, 1 } }
113 };
114
115 static struct resource rb150_nand_resource[] = {
116 [0] = {
117 .start = RB150_NAND_BASE,
118 .end = RB150_NAND_BASE + RB150_NAND_SIZE-1,
119 .flags = IORESOURCE_MEM,
120 },
121 };
122
123 static struct resource rb153_cf_resources[] = {
124 {
125 .name = "cf_membase",
126 .start = ADM5120_EXTIO0_BASE,
127 .end = ADM5120_EXTIO0_BASE + ADM5120_MPMC_SIZE-1 ,
128 .flags = IORESOURCE_MEM
129 }, {
130 .name = "cf_irq",
131 .start = ADM5120_IRQ_GPIO4,
132 .end = ADM5120_IRQ_GPIO4,
133 .flags = IORESOURCE_IRQ
134 }
135 };
136
137 static struct cf_device rb153_cf_data = {
138 .gpio_pin = ADM5120_GPIO_PIN4
139 };
140
141 static struct platform_device rb153_cf_device = {
142 .name = "rb153-cf",
143 .id = -1,
144 .resource = rb153_cf_resources,
145 .num_resources = ARRAY_SIZE(rb153_cf_resources),
146 .dev.platform_data = &rb153_cf_data,
147 };
148
149 static struct platform_device *rb153_devices[] __initdata = {
150 &adm5120_flash0_device,
151 &adm5120_nand_device,
152 &rb153_cf_device,
153 };
154
155 #if 0
156 /*
157 * RB1xx boards have bad network performance with the default VLAN matrixes.
158 * Disable it while the ethernet driver gets fixed.
159 */
160 static unsigned char rb11x_vlans[6] __initdata = {
161 /* FIXME: untested */
162 0x41, 0x00, 0x00, 0x00, 0x00, 0x00
163 };
164
165 static unsigned char rb133_vlans[6] __initdata = {
166 /* FIXME: untested */
167 0x44, 0x42, 0x41, 0x00, 0x00, 0x00
168 };
169
170 static unsigned char rb133c_vlans[6] __initdata = {
171 /* FIXME: untested */
172 0x44, 0x00, 0x00, 0x00, 0x00, 0x00
173 };
174
175 static unsigned char rb15x_vlans[6] __initdata = {
176 /* FIXME: untested */
177 0x41, 0x42, 0x44, 0x48, 0x50, 0x00
178 };
179
180 static unsigned char rb192_vlans[6] __initdata = {
181 /* FIXME: untested */
182 0x41, 0x50, 0x48, 0x44, 0x42, 0x00
183 };
184 #else
185 static unsigned char rb_vlans[6] __initdata = {
186 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00
187 };
188 #define rb11x_vlans rb_vlans
189 #define rb133_vlans rb_vlans
190 #define rb133c_vlans rb_vlans
191 #define rb15x_vlans rb_vlans
192 #define rb192_vlans rb_vlans
193 #endif
194
195 /*--------------------------------------------------------------------------*/
196
197 static int rb150_nand_ready(struct mtd_info *mtd)
198 {
199 return gpio_get_value(RB150_GPIO_NAND_READY);
200 }
201
202 static void rb150_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
203 unsigned int ctrl)
204 {
205 if (ctrl & NAND_CTRL_CHANGE) {
206 gpio_set_value(RB150_GPIO_NAND_CLE, (ctrl & NAND_CLE) ? 1 : 0);
207 gpio_set_value(RB150_GPIO_NAND_ALE, (ctrl & NAND_ALE) ? 1 : 0);
208 gpio_set_value(RB150_GPIO_NAND_NCE, (ctrl & NAND_NCE) ? 0 : 1);
209 }
210
211 udelay(RB150_NAND_DELAY);
212
213 if (cmd != NAND_CMD_NONE)
214 RB150_NAND_WRITE(cmd);
215 }
216
217 /*--------------------------------------------------------------------------*/
218
219 static void __init rb1xx_mac_setup(void)
220 {
221 /* TODO */
222 }
223
224 static void __init rb1xx_flash_setup(void)
225 {
226 /* setup data for flash0 device */
227 adm5120_flash0_data.nr_parts = ARRAY_SIZE(rb1xx_nor_parts);
228 adm5120_flash0_data.parts = rb1xx_nor_parts;
229
230 /* setup data for NAND device */
231 adm5120_nand_data.chip.nr_chips = 1;
232 adm5120_nand_data.chip.nr_partitions = ARRAY_SIZE(rb1xx_nand_parts);
233 adm5120_nand_data.chip.partitions = rb1xx_nand_parts;
234 adm5120_nand_data.chip.ecclayout = &rb1xx_nand_ecclayout;
235 adm5120_nand_data.chip.chip_delay = RB1XX_NAND_CHIP_DELAY;
236 adm5120_nand_data.chip.options = NAND_NO_AUTOINCR;
237 }
238
239 static void __init rb153_cf_setup(void)
240 {
241 gpio_request(RB153_GPIO_CF_RDY, "cf-ready");
242 gpio_direction_input(RB153_GPIO_CF_RDY);
243 gpio_request(RB153_GPIO_CF_WT, "cf-wait");
244 gpio_direction_output(RB153_GPIO_CF_WT, 1);
245 gpio_direction_input(RB153_GPIO_CF_WT);
246 }
247
248 static void __init rb1xx_setup(void)
249 {
250 /* enable NAND flash interface */
251 adm5120_nand_enable();
252
253 /* initialize NAND chip */
254 adm5120_nand_set_spn(1);
255 adm5120_nand_set_wpn(0);
256
257 rb1xx_flash_setup();
258 rb1xx_mac_setup();
259 }
260
261 static void __init rb150_setup(void)
262 {
263 /* setup GPIO pins for NAND flash chip */
264 gpio_request(RB150_GPIO_NAND_READY, "nand-ready");
265 gpio_direction_input(RB150_GPIO_NAND_READY);
266 gpio_request(RB150_GPIO_NAND_NCE, "nand-nce");
267 gpio_direction_output(RB150_GPIO_NAND_NCE, 1);
268 gpio_request(RB150_GPIO_NAND_CLE, "nand-cle");
269 gpio_direction_output(RB150_GPIO_NAND_CLE, 0);
270 gpio_request(RB150_GPIO_NAND_ALE, "nand-ale");
271 gpio_direction_output(RB150_GPIO_NAND_ALE, 0);
272
273 adm5120_nand_device.num_resources = ARRAY_SIZE(rb150_nand_resource);
274 adm5120_nand_device.resource = rb150_nand_resource;
275 adm5120_nand_data.ctrl.cmd_ctrl = rb150_nand_cmd_ctrl;
276 adm5120_nand_data.ctrl.dev_ready = rb150_nand_ready;
277
278 adm5120_flash0_data.window_size = 512*1024;
279
280 rb1xx_flash_setup();
281 rb1xx_mac_setup();
282 }
283
284 static void __init rb153_setup(void)
285 {
286 rb153_cf_setup();
287 rb1xx_setup();
288 }
289
290 /*--------------------------------------------------------------------------*/
291
292 ADM5120_BOARD_START(RB_111, "Mikrotik RouterBOARD 111")
293 .board_setup = rb1xx_setup,
294 .eth_num_ports = 1,
295 .eth_vlans = rb11x_vlans,
296 .num_devices = ARRAY_SIZE(rb1xx_devices),
297 .devices = rb1xx_devices,
298 .pci_nr_irqs = ARRAY_SIZE(rb1xx_pci_irqs),
299 .pci_irq_map = rb1xx_pci_irqs,
300 ADM5120_BOARD_END
301
302 ADM5120_BOARD_START(RB_112, "Mikrotik RouterBOARD 112")
303 .board_setup = rb1xx_setup,
304 .eth_num_ports = 1,
305 .eth_vlans = rb11x_vlans,
306 .num_devices = ARRAY_SIZE(rb1xx_devices),
307 .devices = rb1xx_devices,
308 .pci_nr_irqs = ARRAY_SIZE(rb1xx_pci_irqs),
309 .pci_irq_map = rb1xx_pci_irqs,
310 ADM5120_BOARD_END
311
312 ADM5120_BOARD_START(RB_133, "Mikrotik RouterBOARD 133")
313 .board_setup = rb1xx_setup,
314 .eth_num_ports = 3,
315 .eth_vlans = rb133_vlans,
316 .num_devices = ARRAY_SIZE(rb1xx_devices),
317 .devices = rb1xx_devices,
318 .pci_nr_irqs = ARRAY_SIZE(rb1xx_pci_irqs),
319 .pci_irq_map = rb1xx_pci_irqs,
320 ADM5120_BOARD_END
321
322 ADM5120_BOARD_START(RB_133C, "Mikrotik RouterBOARD 133C")
323 .board_setup = rb1xx_setup,
324 .eth_num_ports = 1,
325 .eth_vlans = rb133c_vlans,
326 .num_devices = ARRAY_SIZE(rb1xx_devices),
327 .devices = rb1xx_devices,
328 .pci_nr_irqs = ARRAY_SIZE(rb1xx_pci_irqs),
329 .pci_irq_map = rb1xx_pci_irqs,
330 ADM5120_BOARD_END
331
332 ADM5120_BOARD_START(RB_150, "Mikrotik RouterBOARD 150")
333 .board_setup = rb150_setup,
334 .eth_num_ports = 5,
335 .eth_vlans = rb15x_vlans,
336 .num_devices = ARRAY_SIZE(rb1xx_devices),
337 .devices = rb1xx_devices,
338 ADM5120_BOARD_END
339
340 ADM5120_BOARD_START(RB_153, "Mikrotik RouterBOARD 153")
341 .board_setup = rb153_setup,
342 .eth_num_ports = 5,
343 .eth_vlans = rb15x_vlans,
344 .num_devices = ARRAY_SIZE(rb153_devices),
345 .devices = rb153_devices,
346 .pci_nr_irqs = ARRAY_SIZE(rb1xx_pci_irqs),
347 .pci_irq_map = rb1xx_pci_irqs,
348 ADM5120_BOARD_END
349
350 ADM5120_BOARD_START(RB_192, "Mikrotik RouterBOARD 192")
351 .board_setup = rb1xx_setup,
352 .eth_num_ports = 5,
353 .eth_vlans = rb192_vlans,
354 .num_devices = ARRAY_SIZE(rb1xx_devices),
355 .devices = rb1xx_devices,
356 .pci_nr_irqs = ARRAY_SIZE(rb1xx_pci_irqs),
357 .pci_irq_map = rb1xx_pci_irqs,
358 ADM5120_BOARD_END
This page took 0.063846 seconds and 3 git commands to generate.