ar71xx: WNR2200: enable control of all LEDs and buttons
[openwrt.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-cpe510.c
1 /*
2  *  TP-LINK CPE210/220/510/520 board support
3  *
4  *  Copyright (C) 2014 Matthias Schiffer <mschiffer@universe-factory.net>
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 #include <linux/platform_device.h>
13
14 #include <asm/mach-ath79/ath79.h>
15 #include <asm/mach-ath79/ar71xx_regs.h>
16
17 #include "common.h"
18 #include "dev-eth.h"
19 #include "dev-gpio-buttons.h"
20 #include "dev-leds-gpio.h"
21 #include "dev-m25p80.h"
22 #include "dev-wmac.h"
23 #include "machtypes.h"
24
25
26 #define CPE510_GPIO_LED_LAN0    11
27 #define CPE510_GPIO_LED_LAN1    12
28 #define CPE510_GPIO_LED_L1      13
29 #define CPE510_GPIO_LED_L2      14
30 #define CPE510_GPIO_LED_L3      15
31 #define CPE510_GPIO_LED_L4      16
32
33 #define CPE510_GPIO_BTN_RESET   4
34
35 #define CPE510_KEYS_POLL_INTERVAL       20 /* msecs */
36 #define CPE510_KEYS_DEBOUNCE_INTERVAL   (3 * CPE510_KEYS_POLL_INTERVAL)
37
38
39 static struct gpio_led cpe510_leds_gpio[] __initdata = {
40         {
41                 .name           = "tp-link:green:lan0",
42                 .gpio           = CPE510_GPIO_LED_LAN0,
43                 .active_low     = 1,
44         }, {
45                 .name           = "tp-link:green:lan1",
46                 .gpio           = CPE510_GPIO_LED_LAN1,
47                 .active_low     = 1,
48         }, {
49                 .name           = "tp-link:green:link1",
50                 .gpio           = CPE510_GPIO_LED_L1,
51                 .active_low     = 1,
52         }, {
53                 .name           = "tp-link:green:link2",
54                 .gpio           = CPE510_GPIO_LED_L2,
55                 .active_low     = 1,
56         }, {
57                 .name           = "tp-link:green:link3",
58                 .gpio           = CPE510_GPIO_LED_L3,
59                 .active_low     = 1,
60         }, {
61                 .name           = "tp-link:green:link4",
62                 .gpio           = CPE510_GPIO_LED_L4,
63                 .active_low     = 1,
64         },
65 };
66
67 static struct gpio_keys_button cpe510_gpio_keys[] __initdata = {
68         {
69                 .desc           = "Reset button",
70                 .type           = EV_KEY,
71                 .code           = KEY_RESTART,
72                 .debounce_interval = CPE510_KEYS_DEBOUNCE_INTERVAL,
73                 .gpio           = CPE510_GPIO_BTN_RESET,
74                 .active_low     = 1,
75         }
76 };
77
78
79 static void __init cpe510_setup(void)
80 {
81         u8 *mac = (u8 *) KSEG1ADDR(0x1f830008);
82         u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
83
84         /* Disable JTAG, enabling GPIOs 0-3 */
85         /* Configure OBS4 line, for GPIO 4*/
86         ath79_gpio_function_setup(AR934X_GPIO_FUNC_JTAG_DISABLE,
87                                   AR934X_GPIO_FUNC_CLK_OBS4_EN);
88
89         ath79_register_leds_gpio(-1, ARRAY_SIZE(cpe510_leds_gpio),
90                                  cpe510_leds_gpio);
91
92         ath79_register_gpio_keys_polled(1, CPE510_KEYS_POLL_INTERVAL,
93                                         ARRAY_SIZE(cpe510_gpio_keys),
94                                         cpe510_gpio_keys);
95
96         ath79_register_m25p80(NULL);
97
98         ath79_register_mdio(1, 0);
99         ath79_init_mac(ath79_eth1_data.mac_addr, mac, 0);
100         ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
101         ath79_register_eth(1);
102
103         ath79_register_wmac(ee, mac);
104 }
105
106 MIPS_MACHINE(ATH79_MACH_CPE510, "CPE510", "TP-LINK CPE210/220/510/520",
107              cpe510_setup);