ar71xx: Fix LED polarity for the TP-LINK TL-MR13U.
[openwrt.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-tube2h.c
1 /*
2  *  ALFA NETWORK Tube2H board support
3  *
4  *  Copyright (C) 2014 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-ath79/ath79.h>
14 #include <asm/mach-ath79/ar71xx_regs.h>
15
16 #include "common.h"
17 #include "dev-eth.h"
18 #include "dev-gpio-buttons.h"
19 #include "dev-leds-gpio.h"
20 #include "dev-m25p80.h"
21 #include "dev-wmac.h"
22 #include "machtypes.h"
23
24 #define TUBE2H_GPIO_LED_SIGNAL4         0
25 #define TUBE2H_GPIO_LED_SIGNAL3         1
26 #define TUBE2H_GPIO_LED_SIGNAL2         13
27 #define TUBE2H_GPIO_LED_LAN             17
28 #define TUBE2H_GPIO_LED_SIGNAL1         27
29
30 #define TUBE2H_GPIO_BTN_RESET           12
31
32 #define TUBE2H_KEYS_POLL_INTERVAL       20      /* msecs */
33 #define TUBE2H_KEYS_DEBOUNCE_INTERVAL   (3 * TUBE2H_KEYS_POLL_INTERVAL)
34
35 #define TUBE2H_ART_ADDRESS              0x1f7f0000
36 #define TUBE2H_LAN_MAC_OFFSET           0x06
37 #define TUBE2H_CALDATA_OFFSET           0x1000
38
39 static struct gpio_led tube2h_leds_gpio[] __initdata = {
40         {
41                 .name           = "alfa:blue:lan",
42                 .gpio           = TUBE2H_GPIO_LED_LAN,
43                 .active_low     = 1,
44         },
45         {
46                 .name           = "alfa:red:signal1",
47                 .gpio           = TUBE2H_GPIO_LED_SIGNAL1,
48                 .active_low     = 1,
49         },
50         {
51                 .name           = "alfa:orange:signal2",
52                 .gpio           = TUBE2H_GPIO_LED_SIGNAL2,
53                 .active_low     = 0,
54         },
55         {
56                 .name           = "alfa:green:signal3",
57                 .gpio           = TUBE2H_GPIO_LED_SIGNAL3,
58                 .active_low     = 0,
59         },
60         {
61                 .name           = "alfa:green:signal4",
62                 .gpio           = TUBE2H_GPIO_LED_SIGNAL4,
63                 .active_low     = 0,
64         },
65 };
66
67 static struct gpio_keys_button tube2h_gpio_keys[] __initdata = {
68         {
69                 .desc           = "Reset button",
70                 .type           = EV_KEY,
71                 .code           = KEY_RESTART,
72                 .debounce_interval = TUBE2H_KEYS_DEBOUNCE_INTERVAL,
73                 .gpio           = TUBE2H_GPIO_BTN_RESET,
74                 .active_low     = 1,
75         },
76 };
77
78 static void __init tube2h_setup(void)
79 {
80         u8 *art = (u8 *) KSEG1ADDR(TUBE2H_ART_ADDRESS);
81         u32 t;
82
83         ath79_gpio_function_disable(AR933X_GPIO_FUNC_JTAG_DISABLE |
84                                     AR933X_GPIO_FUNC_ETH_SWITCH_LED0_EN |
85                                     AR933X_GPIO_FUNC_ETH_SWITCH_LED1_EN |
86                                     AR933X_GPIO_FUNC_ETH_SWITCH_LED2_EN |
87                                     AR933X_GPIO_FUNC_ETH_SWITCH_LED3_EN |
88                                     AR933X_GPIO_FUNC_ETH_SWITCH_LED4_EN);
89
90         /* Ensure that GPIO26 and GPIO27 are controllable by software */
91         t = ath79_reset_rr(AR933X_RESET_REG_BOOTSTRAP);
92         t |= AR933X_BOOTSTRAP_MDIO_GPIO_EN;
93         ath79_reset_wr(AR933X_RESET_REG_BOOTSTRAP, t);
94
95         ath79_register_wmac(art + TUBE2H_CALDATA_OFFSET, NULL);
96
97         ath79_register_m25p80(NULL);
98
99         ath79_register_leds_gpio(-1, ARRAY_SIZE(tube2h_leds_gpio),
100                                  tube2h_leds_gpio);
101         ath79_register_gpio_keys_polled(-1, TUBE2H_KEYS_POLL_INTERVAL,
102                                         ARRAY_SIZE(tube2h_gpio_keys),
103                                         tube2h_gpio_keys);
104
105         ath79_init_mac(ath79_eth0_data.mac_addr,
106                        art + TUBE2H_LAN_MAC_OFFSET, 0);
107         ath79_register_mdio(0, 0x0);
108         ath79_register_eth(0);
109 }
110
111 MIPS_MACHINE(ATH79_MACH_TUBE2H, "TUBE2H", "ALFA NETWORK Tube2H",
112              tube2h_setup);
113