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