[adm5120] add 2.6.26 specific files
[openwrt/svn-archive/archive.git] / target / linux / adm5120 / files-2.6.26 / arch / mips / adm5120 / mikrotik / rb-1xx.c
1 /*
2 * Mikrotik RouterBOARD 1xx series support
3 *
4 * Copyright (C) 2007-2008 Gabor Juhos <juhosg@openwrt.org>
5 *
6 * NAND initialization code was based on a driver for Linux 2.6.19+ which
7 * was derived from the driver for Linux 2.4.xx published by Mikrotik for
8 * their RouterBoard 1xx and 5xx series boards.
9 * Copyright (C) 2007 David Goodenough <david.goodenough@linkchoose.co.uk>
10 * Copyright (C) 2007 Florian Fainelli <florian@openwrt.org>
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License version 2 as published
14 * by the Free Software Foundation.
15 *
16 */
17
18 #include "rb-1xx.h"
19
20 #define RB1XX_NAND_CHIP_DELAY 25
21
22 static struct adm5120_pci_irq rb1xx_pci_irqs[] __initdata = {
23 PCIIRQ(1, 0, 1, ADM5120_IRQ_PCI0),
24 PCIIRQ(2, 0, 1, ADM5120_IRQ_PCI1),
25 PCIIRQ(3, 0, 1, ADM5120_IRQ_PCI2)
26 };
27
28 #ifdef CONFIG_MTD_PARTITIONS
29 static struct mtd_partition rb1xx_nor_parts[] = {
30 {
31 .name = "booter",
32 .offset = 0,
33 .size = 64*1024,
34 .mask_flags = MTD_WRITEABLE,
35 } , {
36 .name = "firmware",
37 .offset = MTDPART_OFS_APPEND,
38 .size = MTDPART_SIZ_FULL,
39 }
40 };
41
42 static struct mtd_partition rb1xx_nand_parts[] = {
43 {
44 .name = "kernel",
45 .offset = 0,
46 .size = 4 * 1024 * 1024,
47 } , {
48 .name = "rootfs",
49 .offset = MTDPART_OFS_NXTBLK,
50 .size = MTDPART_SIZ_FULL
51 }
52 };
53 #endif /* CONFIG_MTD_PARTITIONS */
54
55 /*
56 * We need to use the OLD Yaffs-1 OOB layout, otherwise the RB bootloader
57 * will not be able to find the kernel that we load. So set the oobinfo
58 * when creating the partitions
59 */
60 static struct nand_ecclayout rb1xx_nand_ecclayout = {
61 .eccbytes = 6,
62 .eccpos = { 8, 9, 10, 13, 14, 15 },
63 .oobavail = 9,
64 .oobfree = { { 0, 4 }, { 6, 2 }, { 11, 2 }, { 4, 1 } }
65 };
66
67 /*--------------------------------------------------------------------------*/
68
69 static int rb1xx_nand_fixup(struct mtd_info *mtd)
70 {
71 struct nand_chip *chip = mtd->priv;
72
73 if (mtd->writesize == 512)
74 chip->ecc.layout = &rb1xx_nand_ecclayout;
75
76 return 0;
77 }
78
79 struct platform_nand_data rb1xx_nand_data __initdata = {
80 .chip = {
81 .nr_chips = 1,
82 #ifdef CONFIG_MTD_PARTITIONS
83 .nr_partitions = ARRAY_SIZE(rb1xx_nand_parts),
84 .partitions = rb1xx_nand_parts,
85 #endif /* CONFIG_MTD_PARTITIONS */
86 .chip_delay = RB1XX_NAND_CHIP_DELAY,
87 .options = NAND_NO_AUTOINCR,
88 .chip_fixup = rb1xx_nand_fixup,
89 },
90 };
91
92 struct gpio_button rb1xx_gpio_buttons[] __initdata = {
93 {
94 .desc = "reset_button",
95 .type = EV_KEY,
96 .code = BTN_0,
97 .threshold = 5,
98 .gpio = ADM5120_GPIO_PIN7,
99 }
100 };
101
102 static void __init rb1xx_mac_setup(void)
103 {
104 int i, j;
105
106 if (!rb_hs.mac_base)
107 return;
108
109 for (i = 0; i < 6; i++) {
110 for (j = 0; j < 5; j++)
111 adm5120_eth_macs[i][j] = rb_hs.mac_base[j];
112 adm5120_eth_macs[i][5] = rb_hs.mac_base[5]+i;
113 }
114 }
115
116 void __init rb1xx_add_device_flash(void)
117 {
118 /* setup data for flash0 device */
119 #ifdef CONFIG_MTD_PARTITIONS
120 adm5120_flash0_data.nr_parts = ARRAY_SIZE(rb1xx_nor_parts);
121 adm5120_flash0_data.parts = rb1xx_nor_parts;
122 #endif /* CONFIG_MTD_PARTITIONS */
123 adm5120_flash0_data.window_size = 128*1024;
124
125 adm5120_add_device_flash(0);
126 }
127
128 void __init rb1xx_add_device_nand(void)
129 {
130 /* enable NAND flash interface */
131 adm5120_nand_enable();
132
133 /* initialize NAND chip */
134 adm5120_nand_set_spn(1);
135 adm5120_nand_set_wpn(0);
136
137 adm5120_add_device_nand(&rb1xx_nand_data);
138 }
139
140 void __init rb1xx_generic_setup(void)
141 {
142 if (adm5120_package_bga())
143 adm5120_pci_set_irq_map(ARRAY_SIZE(rb1xx_pci_irqs),
144 rb1xx_pci_irqs);
145
146 adm5120_add_device_gpio_buttons(ARRAY_SIZE(rb1xx_gpio_buttons),
147 rb1xx_gpio_buttons);
148
149 rb1xx_add_device_flash();
150 rb1xx_mac_setup();
151 }