4 * Mikrotik RouterBOARD 1xx series
6 * Copyright (C) 2007 OpenWrt.org
7 * Copyright (C) 2007 Gabor Juhos <juhosg at openwrt.org>
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.
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.
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.
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.
33 #include <linux/kernel.h>
34 #include <linux/init.h>
35 #include <linux/delay.h>
37 #include <asm/bootinfo.h>
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>
46 #define RB1XX_NAND_CHIP_DELAY 25
48 #define RB150_NAND_BASE 0x1FC80000
49 #define RB150_NAND_SIZE 1
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
56 #define RB150_NAND_DELAY 100
58 #define RB150_NAND_WRITE(v) \
59 writeb((v), (void __iomem *)KSEG1ADDR(RB150_NAND_BASE))
61 /*--------------------------------------------------------------------------*/
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
)
69 static struct mtd_partition rb1xx_nor_parts
[] = {
74 .mask_flags
= MTD_WRITEABLE
,
77 .offset
= MTDPART_OFS_APPEND
,
78 .size
= MTDPART_SIZ_FULL
,
82 static struct mtd_partition rb1xx_nand_parts
[] = {
86 .size
= 4 * 1024 * 1024,
89 .offset
= MTDPART_OFS_NXTBLK
,
90 .size
= MTDPART_SIZ_FULL
94 static struct platform_device
*rb1xx_devices
[] __initdata
= {
95 &adm5120_flash0_device
,
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
104 static struct nand_ecclayout rb1xx_nand_ecclayout
= {
106 .eccpos
= { 8, 9, 10, 13, 14, 15 },
108 .oobfree
= { { 0, 4 }, { 6, 2 }, { 11, 2 }, { 4, 1 } }
111 static struct resource rb150_nand_resource
[] = {
113 .start
= RB150_NAND_BASE
,
114 .end
= RB150_NAND_BASE
+ RB150_NAND_SIZE
-1,
115 .flags
= IORESOURCE_MEM
,
121 * RB1xx boards have bad network performance with the default VLAN matrixes.
122 * Disable it while the ethernet driver gets fixed.
124 static unsigned char rb11x_vlans
[6] __initdata
= {
125 /* FIXME: untested */
126 0x41, 0x00, 0x00, 0x00, 0x00, 0x00
129 static unsigned char rb133_vlans
[6] __initdata
= {
130 /* FIXME: untested */
131 0x44, 0x42, 0x41, 0x00, 0x00, 0x00
134 static unsigned char rb133c_vlans
[6] __initdata
= {
135 /* FIXME: untested */
136 0x44, 0x00, 0x00, 0x00, 0x00, 0x00
139 static unsigned char rb15x_vlans
[6] __initdata
= {
140 /* FIXME: untested */
141 0x41, 0x42, 0x44, 0x48, 0x50, 0x00
143 static unsigned char rb192_vlans
[6] __initdata
= {
144 /* FIXME: untested */
145 0x41, 0x50, 0x48, 0x44, 0x42, 0x00
148 static unsigned char rb_vlans
[6] __initdata
= {
149 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00
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
158 /*--------------------------------------------------------------------------*/
160 static int rb150_nand_ready(struct mtd_info
*mtd
)
162 return gpio_get_value(RB150_GPIO_NAND_READY
);
165 static void rb150_nand_cmd_ctrl(struct mtd_info
*mtd
, int cmd
,
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);
174 udelay(RB150_NAND_DELAY
);
176 if (cmd
!= NAND_CMD_NONE
)
177 RB150_NAND_WRITE(cmd
);
180 /*--------------------------------------------------------------------------*/
182 static void __init
rb1xx_mac_setup(void)
187 static void __init
rb1xx_flash_setup(void)
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
;
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
;
202 static void __init
rb1xx_setup(void)
204 /* enable NAND flash interface */
205 adm5120_nand_enable();
207 /* initialize NAND chip */
208 adm5120_nand_set_spn(1);
209 adm5120_nand_set_wpn(0);
215 static void __init
rb150_setup(void)
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);
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
;
236 /*--------------------------------------------------------------------------*/
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
,
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
,
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
,
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
,
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
,
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
,
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
,
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
,
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
,
291 .eth_vlans
= rb15x_vlans
,
292 .num_devices
= ARRAY_SIZE(rb1xx_devices
),
293 .devices
= rb1xx_devices
,
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
,
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
,
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
,
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
,
320 static int __init
register_boards(void)
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
);
332 pure_initcall(register_boards
);