ar71xx: WNR2000v3: fix for random WLAN MAC
[openwrt/svn-archive/archive.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-ap152.c
1
2 /*
3 * Qualcomm Atheros AP152 reference board support
4 *
5 * Copyright (c) 2015 Qualcomm Atheros
6 * Copyright (c) 2012 Gabor Juhos <juhosg@openwrt.org>
7 *
8 * Permission to use, copy, modify, and/or distribute this software for any
9 * purpose with or without fee is hereby granted, provided that the above
10 * copyright notice and this permission notice appear in all copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 *
20 */
21
22 #include <linux/platform_device.h>
23 #include <linux/ath9k_platform.h>
24 #include <linux/ar8216_platform.h>
25 #include <asm/mach-ath79/ar71xx_regs.h>
26
27 #include "common.h"
28 #include "dev-m25p80.h"
29 #include "machtypes.h"
30 #include "pci.h"
31 #include "dev-eth.h"
32 #include "dev-gpio-buttons.h"
33 #include "dev-leds-gpio.h"
34 #include "dev-spi.h"
35 #include "dev-usb.h"
36 #include "dev-wmac.h"
37
38 #define AP152_GPIO_LED_USB0 7
39 #define AP152_GPIO_LED_USB1 8
40
41 #define AP152_GPIO_BTN_RESET 2
42 #define AP152_GPIO_BTN_WPS 1
43 #define AP152_KEYS_POLL_INTERVAL 20 /* msecs */
44 #define AP152_KEYS_DEBOUNCE_INTERVAL (3 * AP152_KEYS_POLL_INTERVAL)
45
46 #define AP152_MAC0_OFFSET 0
47 #define AP152_WMAC_CALDATA_OFFSET 0x1000
48
49 static struct gpio_led ap152_leds_gpio[] __initdata = {
50 {
51 .name = "ap152:green:usb0",
52 .gpio = AP152_GPIO_LED_USB0,
53 .active_low = 1,
54 },
55 {
56 .name = "ap152:green:usb1",
57 .gpio = AP152_GPIO_LED_USB1,
58 .active_low = 1,
59 },
60 };
61
62 static struct gpio_keys_button ap152_gpio_keys[] __initdata = {
63 {
64 .desc = "WPS button",
65 .type = EV_KEY,
66 .code = KEY_WPS_BUTTON,
67 .debounce_interval = AP152_KEYS_DEBOUNCE_INTERVAL,
68 .gpio = AP152_GPIO_BTN_WPS,
69 .active_low = 1,
70 },
71 {
72 .desc = "Reset button",
73 .type = EV_KEY,
74 .code = KEY_RESTART,
75 .debounce_interval = AP152_KEYS_DEBOUNCE_INTERVAL,
76 .gpio = AP152_GPIO_BTN_RESET,
77 .active_low = 1,
78 },
79 };
80
81 static struct ar8327_pad_cfg ap152_ar8337_pad0_cfg = {
82 .mode = AR8327_PAD_MAC_SGMII,
83 .sgmii_delay_en = true,
84 };
85
86 static struct ar8327_platform_data ap152_ar8337_data = {
87 .pad0_cfg = &ap152_ar8337_pad0_cfg,
88 .port0_cfg = {
89 .force_link = 1,
90 .speed = AR8327_PORT_SPEED_1000,
91 .duplex = 1,
92 .txpause = 1,
93 .rxpause = 1,
94 },
95 };
96
97 static struct mdio_board_info ap152_mdio0_info[] = {
98 {
99 .bus_id = "ag71xx-mdio.0",
100 .phy_addr = 0,
101 .platform_data = &ap152_ar8337_data,
102 },
103 };
104
105 static void __init ap152_setup(void)
106 {
107 u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
108
109 ath79_register_m25p80(NULL);
110
111 ath79_register_leds_gpio(-1, ARRAY_SIZE(ap152_leds_gpio),
112 ap152_leds_gpio);
113 ath79_register_gpio_keys_polled(-1, AP152_KEYS_POLL_INTERVAL,
114 ARRAY_SIZE(ap152_gpio_keys),
115 ap152_gpio_keys);
116
117 ath79_register_usb();
118
119 platform_device_register(&ath79_mdio0_device);
120
121 mdiobus_register_board_info(ap152_mdio0_info,
122 ARRAY_SIZE(ap152_mdio0_info));
123
124 ath79_register_wmac(art + AP152_WMAC_CALDATA_OFFSET, NULL);
125 ath79_register_pci();
126
127 ath79_init_mac(ath79_eth0_data.mac_addr, art + AP152_MAC0_OFFSET, 0);
128
129 /* GMAC0 is connected to an AR8337 switch */
130 ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_SGMII;
131 ath79_eth0_data.speed = SPEED_1000;
132 ath79_eth0_data.duplex = DUPLEX_FULL;
133 ath79_eth0_data.phy_mask = BIT(0);
134 ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev;
135
136 ath79_register_eth(0);
137 }
138
139 MIPS_MACHINE(ATH79_MACH_AP152, "AP152", "Qualcomm Atheros AP152 reference board",
140 ap152_setup);