ar71xx: add support for TP-Link TL-MR11U
[openwrt.git] / target / linux / ar71xx / files-2.6.39 / arch / mips / ar71xx / mach-tew-632brp.c
1 /*
2  *  TrendNET TEW-632BRP board support
3  *
4  *  Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
5  *  Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
6  *
7  *  This program is free software; you can redistribute it and/or modify it
8  *  under the terms of the GNU General Public License version 2 as published
9  *  by the Free Software Foundation.
10  */
11
12 #include <linux/mtd/mtd.h>
13 #include <linux/mtd/partitions.h>
14
15 #include <asm/mach-ar71xx/ar71xx.h>
16
17 #include "machtype.h"
18 #include "devices.h"
19 #include "dev-m25p80.h"
20 #include "dev-ar9xxx-wmac.h"
21 #include "dev-gpio-buttons.h"
22 #include "dev-leds-gpio.h"
23 #include "nvram.h"
24
25 #define TEW_632BRP_GPIO_LED_STATUS      1
26 #define TEW_632BRP_GPIO_LED_WPS         3
27 #define TEW_632BRP_GPIO_LED_WLAN        6
28 #define TEW_632BRP_GPIO_BTN_WPS         12
29 #define TEW_632BRP_GPIO_BTN_RESET       21
30
31 #define TEW_632BRP_KEYS_POLL_INTERVAL   20      /* msecs */
32 #define TEW_632BRP_KEYS_DEBOUNCE_INTERVAL (3 * TEW_632BRP_KEYS_POLL_INTERVAL)
33
34 #define TEW_632BRP_CONFIG_ADDR  0x1f020000
35 #define TEW_632BRP_CONFIG_SIZE  0x10000
36
37 #ifdef CONFIG_MTD_PARTITIONS
38 static struct mtd_partition tew_632brp_partitions[] = {
39         {
40                 .name           = "u-boot",
41                 .offset         = 0,
42                 .size           = 0x020000,
43                 .mask_flags     = MTD_WRITEABLE,
44         }, {
45                 .name           = "config",
46                 .offset         = 0x020000,
47                 .size           = 0x010000,
48         }, {
49                 .name           = "kernel",
50                 .offset         = 0x030000,
51                 .size           = 0x0e0000,
52         }, {
53                 .name           = "rootfs",
54                 .offset         = 0x110000,
55                 .size           = 0x2e0000,
56         }, {
57                 .name           = "art",
58                 .offset         = 0x3f0000,
59                 .size           = 0x010000,
60                 .mask_flags     = MTD_WRITEABLE,
61         }, {
62                 .name           = "firmware",
63                 .offset         = 0x030000,
64                 .size           = 0x3c0000,
65         }
66 };
67 #endif /* CONFIG_MTD_PARTITIONS */
68
69 static struct flash_platform_data tew_632brp_flash_data = {
70 #ifdef CONFIG_MTD_PARTITIONS
71         .parts          = tew_632brp_partitions,
72         .nr_parts       = ARRAY_SIZE(tew_632brp_partitions),
73 #endif
74 };
75
76 static struct gpio_led tew_632brp_leds_gpio[] __initdata = {
77         {
78                 .name           = "tew-632brp:green:status",
79                 .gpio           = TEW_632BRP_GPIO_LED_STATUS,
80                 .active_low     = 1,
81         }, {
82                 .name           = "tew-632brp:blue:wps",
83                 .gpio           = TEW_632BRP_GPIO_LED_WPS,
84                 .active_low     = 1,
85         }, {
86                 .name           = "tew-632brp:green:wlan",
87                 .gpio           = TEW_632BRP_GPIO_LED_WLAN,
88                 .active_low     = 1,
89         }
90 };
91
92 static struct gpio_keys_button tew_632brp_gpio_keys[] __initdata = {
93         {
94                 .desc           = "reset",
95                 .type           = EV_KEY,
96                 .code           = KEY_RESTART,
97                 .debounce_interval = TEW_632BRP_KEYS_DEBOUNCE_INTERVAL,
98                 .gpio           = TEW_632BRP_GPIO_BTN_RESET,
99         }, {
100                 .desc           = "wps",
101                 .type           = EV_KEY,
102                 .code           = KEY_WPS_BUTTON,
103                 .debounce_interval = TEW_632BRP_KEYS_DEBOUNCE_INTERVAL,
104                 .gpio           = TEW_632BRP_GPIO_BTN_WPS,
105         }
106 };
107
108 #define TEW_632BRP_LAN_PHYMASK  BIT(0)
109 #define TEW_632BRP_WAN_PHYMASK  BIT(4)
110 #define TEW_632BRP_MDIO_MASK    (~(TEW_632BRP_LAN_PHYMASK | \
111                                    TEW_632BRP_WAN_PHYMASK))
112
113 static void __init tew_632brp_setup(void)
114 {
115         const char *config = (char *) KSEG1ADDR(TEW_632BRP_CONFIG_ADDR);
116         u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
117         u8 mac[6];
118         u8 *wlan_mac = NULL;
119
120         if (nvram_parse_mac_addr(config, TEW_632BRP_CONFIG_SIZE,
121                                 "lan_mac=", mac) == 0) {
122                 ar71xx_init_mac(ar71xx_eth0_data.mac_addr, mac, 0);
123                 ar71xx_init_mac(ar71xx_eth1_data.mac_addr, mac, 1);
124                 wlan_mac = mac;
125         }
126
127         ar71xx_add_device_mdio(0, TEW_632BRP_MDIO_MASK);
128
129         ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
130         ar71xx_eth0_data.phy_mask = TEW_632BRP_LAN_PHYMASK;
131
132         ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
133         ar71xx_eth1_data.phy_mask = TEW_632BRP_WAN_PHYMASK;
134
135         ar71xx_add_device_eth(0);
136         ar71xx_add_device_eth(1);
137
138         ar71xx_add_device_m25p80(&tew_632brp_flash_data);
139
140         ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(tew_632brp_leds_gpio),
141                                         tew_632brp_leds_gpio);
142
143         ar71xx_register_gpio_keys_polled(-1, TEW_632BRP_KEYS_POLL_INTERVAL,
144                                          ARRAY_SIZE(tew_632brp_gpio_keys),
145                                          tew_632brp_gpio_keys);
146
147         ar9xxx_add_device_wmac(eeprom, wlan_mac);
148 }
149
150 MIPS_MACHINE(AR71XX_MACH_TEW_632BRP, "TEW-632BRP", "TRENDnet TEW-632BRP",
151              tew_632brp_setup);