ar71xx: add carambola2 support
[openwrt/svn-archive/archive.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-carambola2.c
1 /*
2 * 8devices Carambola2 board support
3 *
4 * Copyright (C) 2013 Darius Augulis <darius@8devices.com>
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 <asm/mach-ath79/ath79.h>
12 #include <asm/mach-ath79/ar71xx_regs.h>
13 #include "common.h"
14 #include "dev-eth.h"
15 #include "dev-gpio-buttons.h"
16 #include "dev-leds-gpio.h"
17 #include "dev-m25p80.h"
18 #include "dev-spi.h"
19 #include "dev-usb.h"
20 #include "dev-wmac.h"
21 #include "machtypes.h"
22
23 #define CARAMBOLA2_GPIO_LED_WLAN 0
24 #define CARAMBOLA2_GPIO_LED_ETH0 14
25 #define CARAMBOLA2_GPIO_LED_ETH1 13
26
27 #define CARAMBOLA2_GPIO_BTN_JUMPSTART 11
28 #define CARAMBOLA2_GPIO_BTN_RESET 12
29
30 #define CARAMBOLA2_KEYS_POLL_INTERVAL 20 /* msecs */
31 #define CARAMBOLA2_KEYS_DEBOUNCE_INTERVAL (3 * CARAMBOLA2_KEYS_POLL_INTERVAL)
32
33 #define CARAMBOLA2_MAC0_OFFSET 0x0000
34 #define CARAMBOLA2_MAC1_OFFSET 0x0006
35 #define CARAMBOLA2_CALDATA_OFFSET 0x1000
36 #define CARAMBOLA2_WMAC_MAC_OFFSET 0x1002
37
38 static struct gpio_led carambola2_leds_gpio[] __initdata = {
39 {
40 .name = "carambola2:green:wlan",
41 .gpio = CARAMBOLA2_GPIO_LED_WLAN,
42 .active_low = 1,
43 }, {
44 .name = "carambola2:orange:eth0",
45 .gpio = CARAMBOLA2_GPIO_LED_ETH0,
46 .active_low = 0,
47 }, {
48 .name = "carambola2:orange:eth1",
49 .gpio = CARAMBOLA2_GPIO_LED_ETH1,
50 .active_low = 0,
51 }
52 };
53
54 static struct gpio_keys_button carambola2_gpio_keys[] __initdata = {
55 {
56 .desc = "jumpstart button",
57 .type = EV_KEY,
58 .code = KEY_WPS_BUTTON,
59 .debounce_interval = CARAMBOLA2_KEYS_DEBOUNCE_INTERVAL,
60 .gpio = CARAMBOLA2_GPIO_BTN_JUMPSTART,
61 .active_low = 1,
62 },
63 {
64 .desc = "reset button",
65 .type = EV_KEY,
66 .code = KEY_RESTART,
67 .debounce_interval = CARAMBOLA2_KEYS_DEBOUNCE_INTERVAL,
68 .gpio = CARAMBOLA2_GPIO_BTN_RESET,
69 .active_low = 1,
70 }
71 };
72
73 static void __init carambola2_common_setup(void)
74 {
75 u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
76
77 ath79_register_m25p80(NULL);
78 ath79_register_wmac(art + CARAMBOLA2_CALDATA_OFFSET,
79 art + CARAMBOLA2_WMAC_MAC_OFFSET);
80
81 ath79_setup_ar933x_phy4_switch(true, true);
82
83 ath79_init_mac(ath79_eth0_data.mac_addr, art + CARAMBOLA2_MAC0_OFFSET, 0);
84 ath79_init_mac(ath79_eth1_data.mac_addr, art + CARAMBOLA2_MAC1_OFFSET, 0);
85
86 ath79_register_mdio(0, 0x0);
87
88 /* LAN ports */
89 ath79_register_eth(1);
90
91 /* WAN port */
92 ath79_register_eth(0);
93 }
94
95 static void __init carambola2_setup(void)
96 {
97 carambola2_common_setup();
98
99 ath79_gpio_function_disable(AR724X_GPIO_FUNC_ETH_SWITCH_LED0_EN |
100 AR724X_GPIO_FUNC_ETH_SWITCH_LED1_EN |
101 AR724X_GPIO_FUNC_ETH_SWITCH_LED2_EN |
102 AR724X_GPIO_FUNC_ETH_SWITCH_LED3_EN |
103 AR724X_GPIO_FUNC_ETH_SWITCH_LED4_EN);
104
105 ath79_register_leds_gpio(-1, ARRAY_SIZE(carambola2_leds_gpio),
106 carambola2_leds_gpio);
107 ath79_register_gpio_keys_polled(-1, CARAMBOLA2_KEYS_POLL_INTERVAL,
108 ARRAY_SIZE(carambola2_gpio_keys),
109 carambola2_gpio_keys);
110 ath79_register_usb();
111 }
112
113 MIPS_MACHINE(ATH79_MACH_CARAMBOLA2, "CARAMBOLA2", "8devices Carambola2 board",
114 carambola2_setup);