64c32c6230cc99f26243d3de08939300bb398b30
[openwrt/svn-archive/archive.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
46 #define RB1XX_NAND_CHIP_DELAY 25
47
48 #define RB150_NAND_BASE 0x1FC80000
49 #define RB150_NAND_SIZE 1
50
51 #define RB150_GPIO_NAND_READY ADM5120_GPIO_PIN0
52 #define RB150_GPIO_NAND_NCE ADM5120_GPIO_PIN1
53 #define RB150_GPIO_NAND_CLE ADM5120_GPIO_P2L2
54 #define RB150_GPIO_NAND_ALE ADM5120_GPIO_P3L2
55
56 #define RB150_NAND_DELAY 100
57
58 #define RB150_NAND_WRITE(v) \
59 writeb((v), (void __iomem *)KSEG1ADDR(RB150_NAND_BASE))
60
61 /*--------------------------------------------------------------------------*/
62
63 static struct adm5120_pci_irq rb1xx_pci_irqs[] __initdata = {
64 PCIIRQ(1, 0, 1, ADM5120_IRQ_PCI0),
65 PCIIRQ(2, 0, 1, ADM5120_IRQ_PCI1),
66 PCIIRQ(3, 0, 1, ADM5120_IRQ_PCI2)
67 };
68
69 static struct mtd_partition rb1xx_nor_parts[] = {
70 {
71 .name = "booter",
72 .offset = 0,
73 .size = 64*1024,
74 .mask_flags = MTD_WRITEABLE,
75 } , {
76 .name = "firmware",
77 .offset = MTDPART_OFS_APPEND,
78 .size = MTDPART_SIZ_FULL,
79 }
80 };
81
82 static struct mtd_partition rb1xx_nand_parts[] = {
83 {
84 .name = "kernel",
85 .offset = 0,
86 .size = 4 * 1024 * 1024,
87 } , {
88 .name = "rootfs",
89 .offset = MTDPART_OFS_NXTBLK,
90 .size = MTDPART_SIZ_FULL
91 }
92 };
93
94 static struct platform_device *rb1xx_devices[] __initdata = {
95 &adm5120_flash0_device,
96 &adm5120_nand_device,
97 };
98
99 /*
100 * We need to use the OLD Yaffs-1 OOB layout, otherwise the RB bootloader
101 * will not be able to find the kernel that we load. So set the oobinfo
102 * when creating the partitions
103 */
104 static struct nand_ecclayout rb1xx_nand_ecclayout = {
105 .eccbytes = 6,
106 .eccpos = { 8, 9, 10, 13, 14, 15 },
107 .oobavail = 9,
108 .oobfree = { { 0, 4 }, { 6, 2 }, { 11, 2 }, { 4, 1 } }
109 };
110
111 static struct resource rb150_nand_resource[] = {
112 [0] = {
113 .start = RB150_NAND_BASE,
114 .end = RB150_NAND_BASE + RB150_NAND_SIZE-1,
115 .flags = IORESOURCE_MEM,
116 },
117 };
118
119 #if 0
120 /*
121 * RB1xx boards have bad network performance with the default VLAN matrixes.
122 * Disable it while the ethernet driver gets fixed.
123 */
124 static unsigned char rb11x_vlans[6] __initdata = {
125 /* FIXME: untested */
126 0x41, 0x00, 0x00, 0x00, 0x00, 0x00
127 };
128
129 static unsigned char rb133_vlans[6] __initdata = {
130 /* FIXME: untested */
131 0x44, 0x42, 0x41, 0x00, 0x00, 0x00
132 };
133
134 static unsigned char rb133c_vlans[6] __initdata = {
135 /* FIXME: untested */
136 0x44, 0x00, 0x00, 0x00, 0x00, 0x00
137 };
138
139 static unsigned char rb15x_vlans[6] __initdata = {
140 /* FIXME: untested */
141 0x41, 0x42, 0x44, 0x48, 0x50, 0x00
142
143 static unsigned char rb192_vlans[6] __initdata = {
144 /* FIXME: untested */
145 0x41, 0x50, 0x48, 0x44, 0x42, 0x00
146 };
147 #else
148 static unsigned char rb_vlans[6] __initdata = {
149 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00
150 };
151 #define rb11x_vlans rb_vlans
152 #define rb133_vlans rb_vlans
153 #define rb133c_vlans rb_vlans
154 #define rb15x_vlans rb_vlans
155 #define rb192_vlans rb_vlans
156 #endif
157
158 /*--------------------------------------------------------------------------*/
159
160 static int rb150_nand_ready(struct mtd_info *mtd)
161 {
162 return gpio_get_value(RB150_GPIO_NAND_READY);
163 }
164
165 static void rb150_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
166 unsigned int ctrl)
167 {
168 if (ctrl & NAND_CTRL_CHANGE) {
169 gpio_set_value(RB150_GPIO_NAND_CLE, (ctrl & NAND_CLE) ? 1 : 0);
170 gpio_set_value(RB150_GPIO_NAND_ALE, (ctrl & NAND_ALE) ? 1 : 0);
171 gpio_set_value(RB150_GPIO_NAND_NCE, (ctrl & NAND_NCE) ? 0 : 1);
172 }
173
174 udelay(RB150_NAND_DELAY);
175
176 if (cmd != NAND_CMD_NONE)
177 RB150_NAND_WRITE(cmd);
178 }
179
180 /*--------------------------------------------------------------------------*/
181
182 static void __init rb1xx_mac_setup(void)
183 {
184 /* TODO */
185 }
186
187 static void __init rb1xx_flash_setup(void)
188 {
189 /* setup data for flash0 device */
190 adm5120_flash0_data.nr_parts = ARRAY_SIZE(rb1xx_nor_parts);
191 adm5120_flash0_data.parts = rb1xx_nor_parts;
192
193 /* setup data for NAND device */
194 adm5120_nand_data.chip.nr_chips = 1;
195 adm5120_nand_data.chip.nr_partitions = ARRAY_SIZE(rb1xx_nand_parts);
196 adm5120_nand_data.chip.partitions = rb1xx_nand_parts;
197 adm5120_nand_data.chip.ecclayout = &rb1xx_nand_ecclayout;
198 adm5120_nand_data.chip.chip_delay = RB1XX_NAND_CHIP_DELAY;
199 adm5120_nand_data.chip.options = NAND_NO_AUTOINCR;
200 }
201
202 static void __init rb1xx_setup(void)
203 {
204 /* enable NAND flash interface */
205 adm5120_nand_enable();
206
207 /* initialize NAND chip */
208 adm5120_nand_set_spn(1);
209 adm5120_nand_set_wpn(0);
210
211 rb1xx_flash_setup();
212 rb1xx_mac_setup();
213 }
214
215 static void __init rb150_setup(void)
216 {
217 /* setup GPIO pins for NAND flash chip */
218 gpio_request(RB150_GPIO_NAND_READY, "nand-ready");
219 gpio_direction_input(RB150_GPIO_NAND_READY);
220 gpio_request(RB150_GPIO_NAND_NCE, "nand-nce");
221 gpio_direction_output(RB150_GPIO_NAND_NCE, 1);
222 gpio_request(RB150_GPIO_NAND_CLE, "nand-cle");
223 gpio_direction_output(RB150_GPIO_NAND_CLE, 0);
224 gpio_request(RB150_GPIO_NAND_ALE, "nand-ale");
225 gpio_direction_output(RB150_GPIO_NAND_ALE, 0);
226
227 adm5120_nand_device.num_resources = ARRAY_SIZE(rb150_nand_resource);
228 adm5120_nand_device.resource = rb150_nand_resource;
229 adm5120_nand_data.ctrl.cmd_ctrl = rb150_nand_cmd_ctrl;
230 adm5120_nand_data.ctrl.dev_ready = rb150_nand_ready;
231
232 rb1xx_flash_setup();
233 rb1xx_mac_setup();
234 }
235
236 /*--------------------------------------------------------------------------*/
237
238 static struct adm5120_board rb111_board __initdata = {
239 .mach_type = MACH_ADM5120_RB_111,
240 .name = "Mikrotik RouterBOARD 111",
241 .board_setup = rb1xx_setup,
242 .eth_num_ports = 1,
243 .eth_vlans = rb11x_vlans,
244 .num_devices = ARRAY_SIZE(rb1xx_devices),
245 .devices = rb1xx_devices,
246 .pci_nr_irqs = ARRAY_SIZE(rb1xx_pci_irqs),
247 .pci_irq_map = rb1xx_pci_irqs,
248 };
249
250 static struct adm5120_board rb112_board __initdata = {
251 .mach_type = MACH_ADM5120_RB_112,
252 .name = "Mikrotik RouterBOARD 112",
253 .board_setup = rb1xx_setup,
254 .eth_num_ports = 1,
255 .eth_vlans = rb11x_vlans,
256 .num_devices = ARRAY_SIZE(rb1xx_devices),
257 .devices = rb1xx_devices,
258 .pci_nr_irqs = ARRAY_SIZE(rb1xx_pci_irqs),
259 .pci_irq_map = rb1xx_pci_irqs,
260 };
261
262 static struct adm5120_board rb133_board __initdata = {
263 .mach_type = MACH_ADM5120_RB_133,
264 .name = "Mikrotik RouterBOARD 133",
265 .board_setup = rb1xx_setup,
266 .eth_num_ports = 3,
267 .eth_vlans = rb133_vlans,
268 .num_devices = ARRAY_SIZE(rb1xx_devices),
269 .devices = rb1xx_devices,
270 .pci_nr_irqs = ARRAY_SIZE(rb1xx_pci_irqs),
271 .pci_irq_map = rb1xx_pci_irqs,
272 };
273
274 static struct adm5120_board rb133c_board __initdata = {
275 .mach_type = MACH_ADM5120_RB_133C,
276 .name = "Mikrotik RouterBOARD 133C",
277 .board_setup = rb1xx_setup,
278 .eth_num_ports = 1,
279 .eth_vlans = rb133c_vlans,
280 .num_devices = ARRAY_SIZE(rb1xx_devices),
281 .devices = rb1xx_devices,
282 .pci_nr_irqs = ARRAY_SIZE(rb1xx_pci_irqs),
283 .pci_irq_map = rb1xx_pci_irqs,
284 };
285
286 static struct adm5120_board rb150_board __initdata = {
287 .mach_type = MACH_ADM5120_RB_150,
288 .name = "Mikrotik RouterBOARD 150",
289 .board_setup = rb150_setup,
290 .eth_num_ports = 5,
291 .eth_vlans = rb15x_vlans,
292 .num_devices = ARRAY_SIZE(rb1xx_devices),
293 .devices = rb1xx_devices,
294 };
295
296 static struct adm5120_board rb153_board __initdata = {
297 .mach_type = MACH_ADM5120_RB_153,
298 .name = "Mikrotik RouterBOARD 153",
299 .board_setup = rb1xx_setup,
300 .eth_num_ports = 5,
301 .eth_vlans = rb15x_vlans,
302 .num_devices = ARRAY_SIZE(rb1xx_devices),
303 .devices = rb1xx_devices,
304 .pci_nr_irqs = ARRAY_SIZE(rb1xx_pci_irqs),
305 .pci_irq_map = rb1xx_pci_irqs,
306 };
307
308 static struct adm5120_board rb192_board __initdata = {
309 .mach_type = MACH_ADM5120_RB_192,
310 .name = "Mikrotik RouterBOARD 192",
311 .board_setup = rb1xx_setup,
312 .eth_num_ports = 5,
313 .eth_vlans = rb192_vlans,
314 .num_devices = ARRAY_SIZE(rb1xx_devices),
315 .devices = rb1xx_devices,
316 .pci_nr_irqs = ARRAY_SIZE(rb1xx_pci_irqs),
317 .pci_irq_map = rb1xx_pci_irqs,
318 };
319
320 static int __init register_boards(void)
321 {
322 adm5120_board_register(&rb111_board);
323 adm5120_board_register(&rb112_board);
324 adm5120_board_register(&rb133_board);
325 adm5120_board_register(&rb133c_board);
326 adm5120_board_register(&rb150_board);
327 adm5120_board_register(&rb153_board);
328 adm5120_board_register(&rb192_board);
329 return 0;
330 }
331
332 pure_initcall(register_boards);