adm5120: add 3.18 support
[openwrt/svn-archive/archive.git] / target / linux / adm5120 / files-3.18 / 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 #define RB1XX_KEYS_POLL_INTERVAL 20
23 #define RB1XX_KEYS_DEBOUNCE_INTERVAL (3 * RB1XX_KEYS_POLL_INTERVAL)
24
25 static struct adm5120_pci_irq rb1xx_pci_irqs[] __initdata = {
26 PCIIRQ(1, 0, 1, ADM5120_IRQ_PCI0),
27 PCIIRQ(2, 0, 1, ADM5120_IRQ_PCI1),
28 PCIIRQ(3, 0, 1, ADM5120_IRQ_PCI2)
29 };
30
31 static struct mtd_partition rb1xx_nor_parts[] = {
32 {
33 .name = "booter",
34 .offset = 0,
35 .size = 64*1024,
36 .mask_flags = MTD_WRITEABLE,
37 } , {
38 .name = "firmware",
39 .offset = MTDPART_OFS_APPEND,
40 .size = MTDPART_SIZ_FULL,
41 }
42 };
43
44 static struct mtd_partition rb1xx_nand_parts[] = {
45 {
46 .name = "kernel",
47 .offset = 0,
48 .size = 4 * 1024 * 1024,
49 } , {
50 .name = "rootfs",
51 .offset = MTDPART_OFS_NXTBLK,
52 .size = MTDPART_SIZ_FULL
53 }
54 };
55
56 /*
57 * We need to use the OLD Yaffs-1 OOB layout, otherwise the RB bootloader
58 * will not be able to find the kernel that we load. So set the oobinfo
59 * when creating the partitions
60 */
61 static struct nand_ecclayout rb1xx_nand_ecclayout = {
62 .eccbytes = 6,
63 .eccpos = { 8, 9, 10, 13, 14, 15 },
64 .oobavail = 9,
65 .oobfree = { { 0, 4 }, { 6, 2 }, { 11, 2 }, { 4, 1 } }
66 };
67
68 /*--------------------------------------------------------------------------*/
69
70 static int rb1xx_nand_fixup(struct mtd_info *mtd)
71 {
72 struct nand_chip *chip = mtd->priv;
73
74 if (mtd->writesize == 512)
75 chip->ecc.layout = &rb1xx_nand_ecclayout;
76
77 return 0;
78 }
79
80 struct platform_nand_data rb1xx_nand_data __initdata = {
81 .chip = {
82 .nr_chips = 1,
83 .nr_partitions = ARRAY_SIZE(rb1xx_nand_parts),
84 .partitions = rb1xx_nand_parts,
85 .chip_delay = RB1XX_NAND_CHIP_DELAY,
86 .chip_fixup = rb1xx_nand_fixup,
87 },
88 };
89
90 struct gpio_keys_button rb1xx_gpio_buttons[] __initdata = {
91 {
92 .desc = "reset_button",
93 .type = EV_KEY,
94 .code = KEY_RESTART,
95 .debounce_interval = RB1XX_KEYS_DEBOUNCE_INTERVAL,
96 .gpio = ADM5120_GPIO_PIN7,
97 }
98 };
99
100 static void __init rb1xx_mac_setup(void)
101 {
102 if (rb_hs.mac_base != NULL && is_valid_ether_addr(rb_hs.mac_base)) {
103 adm5120_setup_eth_macs(rb_hs.mac_base);
104 } else {
105 u8 mac[ETH_ALEN];
106
107 random_ether_addr(mac);
108 adm5120_setup_eth_macs(mac);
109 }
110 }
111
112 void __init rb1xx_add_device_flash(void)
113 {
114 /* setup data for flash0 device */
115 adm5120_flash0_data.nr_parts = ARRAY_SIZE(rb1xx_nor_parts);
116 adm5120_flash0_data.parts = rb1xx_nor_parts;
117 adm5120_flash0_data.window_size = 128*1024;
118
119 adm5120_add_device_flash(0);
120 }
121
122 void __init rb1xx_add_device_nand(void)
123 {
124 /* enable NAND flash interface */
125 adm5120_nand_enable();
126
127 /* initialize NAND chip */
128 adm5120_nand_set_spn(1);
129 adm5120_nand_set_wpn(0);
130
131 adm5120_add_device_nand(&rb1xx_nand_data);
132 }
133
134 void __init rb1xx_generic_setup(void)
135 {
136 if (adm5120_package_bga())
137 adm5120_pci_set_irq_map(ARRAY_SIZE(rb1xx_pci_irqs),
138 rb1xx_pci_irqs);
139
140 adm5120_add_device_uart(0);
141 adm5120_add_device_uart(1);
142
143 adm5120_register_gpio_buttons(-1, RB1XX_KEYS_POLL_INTERVAL,
144 ARRAY_SIZE(rb1xx_gpio_buttons),
145 rb1xx_gpio_buttons);
146
147 rb1xx_add_device_flash();
148 rb1xx_mac_setup();
149 }