ar71xx: wpj588: add missing usb support
[openwrt.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-ew-dorin.c
1 /*
2  *  EW Dorin board support
3  *  (based on Atheros Ref. Design AP121)
4  *  Copyright (C) 2011-2012 Gabor Juhos <juhosg@openwrt.org>
5  *  Copyright (C) 2012 Embedded Wireless GmbH    www.80211.de
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 <asm/mach-ath79/ath79.h>
13 #include <asm/mach-ath79/ar71xx_regs.h>
14
15 #include "dev-eth.h"
16 #include "dev-gpio-buttons.h"
17 #include "dev-leds-gpio.h"
18 #include "dev-m25p80.h"
19 #include "dev-spi.h"
20 #include "dev-usb.h"
21 #include "dev-wmac.h"
22 #include "machtypes.h"
23
24 #define DORIN_KEYS_POLL_INTERVAL        20      /* msecs */
25 #define DORIN_KEYS_DEBOUNCE_INTERVAL    (3 * DORIN_KEYS_POLL_INTERVAL)
26
27 #define DORIN_CALDATA_OFFSET            0x1000
28 #define DORIN_WMAC_MAC_OFFSET           0x1002
29
30 #define DORIN_GPIO_LED_21               21
31 #define DORIN_GPIO_LED_22               22
32
33 #define DORIN_GPIO_BTN_JUMPSTART        11
34 #define DORIN_GPIO_BTN_RESET            6
35
36 static struct gpio_led dorin_leds_gpio[] __initdata = {
37         {
38                 .name           = "dorin:green:led21",
39                 .gpio           = DORIN_GPIO_LED_21,
40                 .active_low     = 1,
41         },
42         {
43                 .name           = "dorin:green:led22",
44                 .gpio           = DORIN_GPIO_LED_22,
45                 .active_low     = 1,
46         },
47 };
48
49 static struct gpio_keys_button dorin_gpio_keys[] __initdata = {
50         {
51                 .desc           = "jumpstart button",
52                 .type           = EV_KEY,
53                 .code           = KEY_WPS_BUTTON,
54                 .debounce_interval = DORIN_KEYS_DEBOUNCE_INTERVAL,
55                 .gpio           = DORIN_GPIO_BTN_JUMPSTART,
56                 .active_low     = 1,
57         },
58         {
59                 .desc           = "reset button",
60                 .type           = EV_KEY,
61                 .code           = KEY_RESTART,
62                 .debounce_interval = DORIN_KEYS_DEBOUNCE_INTERVAL,
63                 .gpio           = DORIN_GPIO_BTN_RESET,
64                 .active_low     = 0,
65         }
66 };
67
68 static void __init ew_dorin_setup(void)
69 {
70         u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
71         static u8 mac[6];
72
73         ath79_register_m25p80(NULL);
74
75         ath79_register_usb();
76
77         if (ar93xx_wmac_read_mac_address(mac)) {
78                 ath79_register_wmac(NULL, NULL);
79         } else {
80                 ath79_register_wmac(art + DORIN_CALDATA_OFFSET,
81                                     art + DORIN_WMAC_MAC_OFFSET);
82                 memcpy(mac, art + DORIN_WMAC_MAC_OFFSET, sizeof(mac));
83         }
84
85         mac[3] |= 0x40;
86         ath79_init_mac(ath79_eth1_data.mac_addr, mac, 0);
87
88         ath79_register_mdio(0, 0x0);
89
90         /* LAN ports */
91         ath79_register_eth(1);
92
93         ath79_register_leds_gpio(-1, ARRAY_SIZE(dorin_leds_gpio),
94                                  dorin_leds_gpio);
95         ath79_register_gpio_keys_polled(-1, DORIN_KEYS_POLL_INTERVAL,
96                                         ARRAY_SIZE(dorin_gpio_keys),
97                                         dorin_gpio_keys);
98 }
99
100 MIPS_MACHINE(ATH79_MACH_EW_DORIN, "EW-DORIN", "EmbWir-Dorin",
101              ew_dorin_setup);
102
103
104 static void __init ew_dorin_router_setup(void)
105 {
106         u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
107         static u8 mac[6];
108
109         ath79_register_m25p80(NULL);
110
111         ath79_register_usb();
112
113         if (ar93xx_wmac_read_mac_address(mac)) {
114                 ath79_register_wmac(NULL, NULL);
115         } else {
116                 ath79_register_wmac(art + DORIN_CALDATA_OFFSET,
117                                     art + DORIN_WMAC_MAC_OFFSET);
118                 memcpy(mac, art + DORIN_WMAC_MAC_OFFSET, sizeof(mac));
119         }
120
121         mac[3] |= 0x40;
122         ath79_init_mac(ath79_eth1_data.mac_addr, mac, 0);
123
124         mac[3] &= 0x3F;
125         ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
126         ath79_setup_ar933x_phy4_switch(true, true);
127
128         ath79_register_mdio(0, 0x0);
129
130         /* LAN ports */
131         ath79_register_eth(1);
132
133         /* WAN port */
134         ath79_register_eth(0);
135
136         ath79_register_leds_gpio(-1, ARRAY_SIZE(dorin_leds_gpio),
137                                  dorin_leds_gpio);
138         ath79_register_gpio_keys_polled(-1, DORIN_KEYS_POLL_INTERVAL,
139                                         ARRAY_SIZE(dorin_gpio_keys),
140                                         dorin_gpio_keys);
141 }
142
143 MIPS_MACHINE(ATH79_MACH_EW_DORIN_ROUTER, "EW-DORIN-ROUTER",
144              "EmbWir-Dorin-Router", ew_dorin_router_setup);