ar71xx: remove CONFIG_MTD_CONCAT ifdefs from the WZR-HP-AG300H code
[oweals/openwrt.git] / target / linux / ar71xx / files / arch / mips / ar71xx / mach-wzr-hp-ag300h.c
1 /*
2  *  Buffalo WZR-HP-AG300H board support
3  *
4  *  Copyright (C) 2011 Felix Fietkau <nbd@openwrt.org>
5  *
6  *  This program is free software; you can redistribute it and/or modify it
7  *  under the terms of the GNU General Public License version 2 as published
8  *  by the Free Software Foundation.
9  */
10
11 #include <linux/platform_device.h>
12 #include <linux/mtd/mtd.h>
13 #include <linux/mtd/partitions.h>
14 #include <linux/mtd/concat.h>
15
16 #include <asm/mips_machine.h>
17 #include <asm/mach-ar71xx/ar71xx.h>
18
19 #include "machtype.h"
20 #include "devices.h"
21 #include "dev-ap94-pci.h"
22 #include "dev-gpio-buttons.h"
23 #include "dev-leds-gpio.h"
24 #include "dev-m25p80.h"
25 #include "dev-usb.h"
26
27 #define WZRHPAG300H_MAC_OFFSET          0x20c
28 #define WZRHPAG300H_KEYS_POLL_INTERVAL     20      /* msecs */
29 #define WZRHPAG300H_KEYS_DEBOUNCE_INTERVAL (3 * WZRHPAG300H_KEYS_POLL_INTERVAL)
30
31 #ifdef CONFIG_MTD_PARTITIONS
32 static struct mtd_partition wzrhpag300h_flash_partitions[] = {
33         {
34                 .name           = "u-boot",
35                 .offset         = 0,
36                 .size           = 0x0040000,
37                 .mask_flags     = MTD_WRITEABLE,
38         }, {
39                 .name           = "u-boot-env",
40                 .offset         = 0x0040000,
41                 .size           = 0x0010000,
42                 .mask_flags     = MTD_WRITEABLE,
43         }, {
44                 .name           = "art",
45                 .offset         = 0x0050000,
46                 .size           = 0x0010000,
47                 .mask_flags     = MTD_WRITEABLE,
48         }, {
49                 .name           = "kernel",
50                 .offset         = 0x0060000,
51                 .size           = 0x0100000,
52         }, {
53                 .name           = "rootfs",
54                 .offset         = 0x0160000,
55                 .size           = 0x1e90000,
56         }, {
57                 .name           = "user_property",
58                 .offset         = 0x1ff0000,
59                 .size           = 0x0010000,
60                 .mask_flags     = MTD_WRITEABLE,
61         }, {
62                 .name           = "firmware",
63                 .offset         = 0x0060000,
64                 .size           = 0x1f90000,
65         }
66 };
67
68 #endif /* CONFIG_MTD_PARTITIONS */
69
70 static struct mtd_info *concat_devs[2] = { NULL, NULL };
71 static struct work_struct mtd_concat_work;
72
73 static void mtd_concat_add_work(struct work_struct *work)
74 {
75         struct mtd_info *mtd;
76
77         mtd = mtd_concat_create(concat_devs, ARRAY_SIZE(concat_devs), "flash");
78
79 #ifdef CONFIG_MTD_PARTITIONS
80         add_mtd_partitions(mtd, wzrhpag300h_flash_partitions,
81                            ARRAY_SIZE(wzrhpag300h_flash_partitions));
82 #else
83         add_mtd_device(mtd);
84 #endif
85 }
86
87 static void mtd_concat_add(struct mtd_info *mtd)
88 {
89         static bool registered = false;
90
91         if (registered)
92                 return;
93
94         if (!strcmp(mtd->name, "spi0.0"))
95                 concat_devs[0] = mtd;
96         else if (!strcmp(mtd->name, "spi0.1"))
97                 concat_devs[1] = mtd;
98         else
99                 return;
100
101         if (!concat_devs[0] || !concat_devs[1])
102                 return;
103
104         registered = true;
105         INIT_WORK(&mtd_concat_work, mtd_concat_add_work);
106         schedule_work(&mtd_concat_work);
107 }
108
109 static void mtd_concat_remove(struct mtd_info *mtd)
110 {
111 }
112
113 static void add_mtd_concat_notifier(void)
114 {
115         static struct mtd_notifier not = {
116                 .add = mtd_concat_add,
117                 .remove = mtd_concat_remove,
118         };
119
120         register_mtd_user(&not);
121 }
122
123 static struct gpio_led wzrhpag300h_leds_gpio[] __initdata = {
124         {
125                 .name           = "wzr-hp-ag300h:red:diag",
126                 .gpio           = 1,
127                 .active_low     = 1,
128         },
129 };
130
131
132 static struct gpio_keys_button wzrhpag300h_gpio_keys[] __initdata = {
133         {
134                 .desc           = "reset",
135                 .type           = EV_KEY,
136                 .code           = KEY_RESTART,
137                 .debounce_interval = WZRHPAG300H_KEYS_DEBOUNCE_INTERVAL,
138                 .gpio           = 11,
139                 .active_low     = 1,
140         }, {
141                 .desc           = "usb",
142                 .type           = EV_KEY,
143                 .code           = BTN_2,
144                 .debounce_interval = WZRHPAG300H_KEYS_DEBOUNCE_INTERVAL,
145                 .gpio           = 3,
146                 .active_low     = 1,
147         }, {
148                 .desc           = "aoss",
149                 .type           = EV_KEY,
150                 .code           = KEY_WPS_BUTTON,
151                 .debounce_interval = WZRHPAG300H_KEYS_DEBOUNCE_INTERVAL,
152                 .gpio           = 5,
153                 .active_low     = 1,
154         }, {
155                 .desc           = "router_auto",
156                 .type           = EV_KEY,
157                 .code           = BTN_6,
158                 .debounce_interval = WZRHPAG300H_KEYS_DEBOUNCE_INTERVAL,
159                 .gpio           = 6,
160                 .active_low     = 1,
161         }, {
162                 .desc           = "router_off",
163                 .type           = EV_KEY,
164                 .code           = BTN_5,
165                 .debounce_interval = WZRHPAG300H_KEYS_DEBOUNCE_INTERVAL,
166                 .gpio           = 7,
167                 .active_low     = 1,
168         }
169 };
170
171 static struct spi_board_info ar71xx_spi_info[] = {
172         {
173                 .bus_num        = 0,
174                 .chip_select    = 0,
175                 .max_speed_hz   = 25000000,
176                 .modalias   = "m25p80",
177         },
178         {
179                 .bus_num        = 0,
180                 .chip_select    = 1,
181                 .max_speed_hz   = 25000000,
182                 .modalias   = "m25p80",
183         }
184 };
185
186 static void __init wzrhpag300h_setup(void)
187 {
188         u8 *eeprom1 = (u8 *) KSEG1ADDR(0x1f051000);
189         u8 *eeprom2 = (u8 *) KSEG1ADDR(0x1f055000);
190         u8 *mac1 = eeprom1 + WZRHPAG300H_MAC_OFFSET;
191         u8 *mac2 = eeprom2 + WZRHPAG300H_MAC_OFFSET;
192
193         ar71xx_init_mac(ar71xx_eth0_data.mac_addr, mac1, 0);
194         ar71xx_init_mac(ar71xx_eth1_data.mac_addr, mac2, 1);
195
196         ar71xx_add_device_mdio(~(BIT(0) | BIT(4)));
197
198         ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
199         ar71xx_eth0_data.speed = SPEED_1000;
200         ar71xx_eth0_data.duplex = DUPLEX_FULL;
201         ar71xx_eth0_data.phy_mask = BIT(0);
202
203         ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
204         ar71xx_eth1_data.phy_mask = BIT(4);
205
206         ar71xx_add_device_eth(0);
207         ar71xx_add_device_eth(1);
208
209         ar71xx_add_device_usb();
210
211         ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(wzrhpag300h_leds_gpio),
212                                         wzrhpag300h_leds_gpio);
213
214         ar71xx_register_gpio_keys_polled(-1, WZRHPAG300H_KEYS_POLL_INTERVAL,
215                                          ARRAY_SIZE(wzrhpag300h_gpio_keys),
216                                          wzrhpag300h_gpio_keys);
217
218         ar71xx_add_device_spi(NULL, ar71xx_spi_info,
219                               ARRAY_SIZE(ar71xx_spi_info));
220
221         add_mtd_concat_notifier();
222
223         ap94_pci_init(eeprom1, mac1, eeprom2, mac2);
224 }
225
226 MIPS_MACHINE(AR71XX_MACH_WZR_HP_AG300H, "WZR-HP-AG300H",
227              "Buffalo WZR-HP-AG300H", wzrhpag300h_setup);
228