ar71xx: add support for ALFA Network's Hornet-UB board
[openwrt/svn-archive/archive.git] / target / linux / ar71xx / files / arch / mips / ar71xx / mach-hornet-ub.c
1 /*
2 * ALFA NETWORKS Hornet-UB board support
3 *
4 * Copyright (C) 2011 Gabor Juhos <juhosg@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/gpio.h>
12
13 #include <asm/mach-ar71xx/ar71xx.h>
14
15 #include "machtype.h"
16 #include "devices.h"
17 #include "dev-ar9xxx-wmac.h"
18 #include "dev-gpio-buttons.h"
19 #include "dev-leds-gpio.h"
20 #include "dev-m25p80.h"
21 #include "dev-usb.h"
22
23 #define HORNET_UB_GPIO_LED_WLAN 0
24 #define HORNET_UB_GPIO_LED_USB 1
25 #define HORNET_UB_GPIO_LED_LAN 13
26 #define HORNET_UB_GPIO_LED_WAN 17
27 #define HORNET_UB_GPIO_LED_WPS 27
28
29 #define HORNET_UB_GPIO_BTN_RESET 11
30 #define HORNET_UB_GPIO_BTN_WPS 12
31
32 #define HORNET_UB_GPIO_USB_POWER 26
33
34 #define HORNET_UB_KEYS_POLL_INTERVAL 20 /* msecs */
35 #define HORNET_UB_KEYS_DEBOUNCE_INTERVAL (3 * HORNET_UB_KEYS_POLL_INTERVAL)
36
37 #define HORNET_UB_MAC0_OFFSET 0x0000
38 #define HORNET_UB_MAC1_OFFSET 0x0006
39 #define HORNET_UB_CALDATA_OFFSET 0x1000
40
41 static struct gpio_led hornet_ub_leds_gpio[] __initdata = {
42 {
43 .name = "alfa:blue:lan",
44 .gpio = HORNET_UB_GPIO_LED_LAN,
45 .active_low = 0,
46 },
47 {
48 .name = "alfa:blue:usb",
49 .gpio = HORNET_UB_GPIO_LED_USB,
50 .active_low = 0,
51 },
52 {
53 .name = "alfa:blue:wan",
54 .gpio = HORNET_UB_GPIO_LED_WAN,
55 .active_low = 1,
56 },
57 {
58 .name = "alfa:blue:wlan",
59 .gpio = HORNET_UB_GPIO_LED_WLAN,
60 .active_low = 0,
61 },
62 {
63 .name = "alfa:blue:wps",
64 .gpio = HORNET_UB_GPIO_LED_WPS,
65 .active_low = 1,
66 },
67 };
68
69 static struct gpio_keys_button hornet_ub_gpio_keys[] __initdata = {
70 {
71 .desc = "WPS button",
72 .type = EV_KEY,
73 .code = KEY_WPS_BUTTON,
74 .debounce_interval = HORNET_UB_KEYS_DEBOUNCE_INTERVAL,
75 .gpio = HORNET_UB_GPIO_BTN_WPS,
76 .active_low = 1,
77 },
78 {
79 .desc = "Reset button",
80 .type = EV_KEY,
81 .code = KEY_RESTART,
82 .debounce_interval = HORNET_UB_KEYS_DEBOUNCE_INTERVAL,
83 .gpio = HORNET_UB_GPIO_BTN_RESET,
84 .active_low = 0,
85 }
86 };
87
88 static void __init hornet_ub_gpio_setup(void)
89 {
90 u32 t;
91
92 ar71xx_gpio_function_disable(AR933X_GPIO_FUNC_ETH_SWITCH_LED0_EN |
93 AR933X_GPIO_FUNC_ETH_SWITCH_LED1_EN |
94 AR933X_GPIO_FUNC_ETH_SWITCH_LED2_EN |
95 AR933X_GPIO_FUNC_ETH_SWITCH_LED3_EN |
96 AR933X_GPIO_FUNC_ETH_SWITCH_LED4_EN);
97
98 t = ar71xx_reset_rr(AR933X_RESET_REG_BOOTSTRAP);
99 t |= AR933X_BOOTSTRAP_MDIO_GPIO_EN;
100 ar71xx_reset_wr(AR933X_RESET_REG_BOOTSTRAP, t);
101
102 gpio_request(HORNET_UB_GPIO_USB_POWER, "USB power");
103 gpio_direction_output(HORNET_UB_GPIO_USB_POWER, 1);
104 }
105
106 static void __init hornet_ub_setup(void)
107 {
108 u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
109
110 hornet_ub_gpio_setup();
111
112 ar71xx_add_device_m25p80(NULL);
113 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(hornet_ub_leds_gpio),
114 hornet_ub_leds_gpio);
115 ar71xx_register_gpio_keys_polled(-1, HORNET_UB_KEYS_POLL_INTERVAL,
116 ARRAY_SIZE(hornet_ub_gpio_keys),
117 hornet_ub_gpio_keys);
118
119 ar71xx_init_mac(ar71xx_eth1_data.mac_addr,
120 art + HORNET_UB_MAC0_OFFSET, 0);
121 ar71xx_init_mac(ar71xx_eth0_data.mac_addr,
122 art + HORNET_UB_MAC1_OFFSET, 0);
123
124 ar71xx_add_device_mdio(0, 0x0);
125
126 ar71xx_add_device_eth(1);
127 ar71xx_add_device_eth(0);
128
129 ar9xxx_add_device_wmac(art + HORNET_UB_CALDATA_OFFSET, NULL);
130 ar71xx_add_device_usb();
131 }
132
133 MIPS_MACHINE(AR71XX_MACH_HORNET_UB, "HORNET-UB", "ALFA NETWORKS Hornet-UB",
134 hornet_ub_setup);