v1.5 branch refresh based upon upstream master @ c8677ca89e53e3be7988d54280fce166cc894a7e
[librecmc/librecmc.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-dap-1330-a1.c
1 /*
2  * D-Link DAP-1330
3  *
4  * Copyright (c) 2013-2015 The Linux Foundation. All rights reserved.
5  * Copyright (c) 2017 Nicolò Veronese <nicveronese@gmail.com>
6  * Copyright (c) 2017 Federico Cappon <dududede371@gmail.com>
7  *
8  * Permission to use, copy, modify, and/or distribute this software for any
9  * purpose with or without fee is hereby granted, provided that the above
10  * copyright notice and this permission notice appear in all copies.
11  *
12  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19  *
20  */
21
22 #include <linux/gpio.h>
23 #include <linux/platform_device.h>
24
25 #include <asm/mach-ath79/ath79.h>
26 #include <asm/mach-ath79/ar71xx_regs.h>
27
28 #include "common.h"
29 #include "dev-eth.h"
30 #include "dev-gpio-buttons.h"
31 #include "dev-leds-gpio.h"
32 #include "dev-m25p80.h"
33 #include "dev-wmac.h"
34 #include "machtypes.h"
35 #include "nvram.h"
36
37 #include <linux/kernel.h>
38 #include <linux/vmalloc.h>
39 #include <linux/errno.h>
40 #include <linux/init.h>
41 #include <linux/string.h>
42
43 #define DAP_1330_GPIO_LED_GREEN_POWER   13
44 #define DAP_1330_GPIO_LED_RED_POWER     3
45 #define DAP_1330_GPIO_LED_GREEN_WIFI    14
46 #define DAP_1330_GPIO_LED_RED_WIFI      11
47 #define DAP_1330_GPIO_LED_SIGNAL1       15
48 #define DAP_1330_GPIO_LED_SIGNAL2       16
49
50 #define DAP_1330_GPIO_BTN_WPS           2
51 #define DAP_1330_GPIO_BTN_RESET         17
52
53 #define DAP_1330_KEYS_POLL_INTERVAL     20      /* msecs */
54 #define DAP_1330_KEYS_DEBOUNCE_INTERVAL (3 * DAP_1330_KEYS_POLL_INTERVAL)
55
56 #define DAP1330_MAC_ADDR                0x1f020001
57
58 #define DAP1330_WMAC_CALDATA_ADDR       0x1f010000
59 #define DAP_1330_WMAC_CALDATA_OFFSET    0x1000
60
61 static struct gpio_led dap_1330_leds_gpio[] __initdata = {
62                 {
63                                 .name           = "d-link:green:power",
64                                 .gpio           = DAP_1330_GPIO_LED_GREEN_POWER,
65                                 .active_low     = 1,
66                 },
67                 {
68                                 .name           = "d-link:red:power",
69                                 .gpio           = DAP_1330_GPIO_LED_RED_POWER,
70                                 .active_low     = 1,
71                 },
72                 {
73                                 .name           = "d-link:green:wifi",
74                                 .gpio           = DAP_1330_GPIO_LED_GREEN_WIFI,
75                                 .active_low     = 1,
76                 },
77                 {
78                                 .name           = "d-link:red:wifi",
79                                 .gpio           = DAP_1330_GPIO_LED_RED_WIFI,
80                                 .active_low     = 1,
81                 },
82                 {
83                                 .name           = "d-link:green:signal1",
84                                 .gpio           = DAP_1330_GPIO_LED_SIGNAL1,
85                                 .active_low     = 1,
86                 },
87                 {
88                                 .name           = "d-link:green:signal2",
89                                 .gpio           = DAP_1330_GPIO_LED_SIGNAL2,
90                                 .active_low     = 1,
91                 }
92 };
93
94 static struct gpio_keys_button dap_1330_gpio_keys[] __initdata = {
95         {
96                 .desc           = "WPS button",
97                 .type           = EV_KEY,
98                 .code           = KEY_WPS_BUTTON,
99                 .debounce_interval = DAP_1330_KEYS_DEBOUNCE_INTERVAL,
100                 .gpio           = DAP_1330_GPIO_BTN_WPS,
101                 .active_low     = 1,
102         },
103         {
104                 .desc           = "Reset button",
105                 .type           = EV_KEY,
106                 .code           = KEY_RESTART,
107                 .debounce_interval = DAP_1330_KEYS_DEBOUNCE_INTERVAL,
108                 .gpio           = DAP_1330_GPIO_BTN_RESET,
109                 .active_low     = 1,
110         }
111 };
112
113 static void __init dap_1330_setup(void)
114 {
115         u8 *art = (u8 *) KSEG1ADDR(DAP1330_WMAC_CALDATA_ADDR);
116         u8 *mac_ptr = (u8 *) KSEG1ADDR(DAP1330_MAC_ADDR);
117         u8 mac[ETH_ALEN];
118
119         ath79_parse_ascii_mac((char *) mac_ptr, mac);
120
121         ath79_register_m25p80(NULL);
122
123         ath79_register_leds_gpio(-1, ARRAY_SIZE(dap_1330_leds_gpio),
124                 dap_1330_leds_gpio);
125
126         ath79_register_gpio_keys_polled(-1, DAP_1330_KEYS_POLL_INTERVAL,
127                         ARRAY_SIZE(dap_1330_gpio_keys),
128                         dap_1330_gpio_keys);
129
130         ath79_register_wmac(art + DAP_1330_WMAC_CALDATA_OFFSET, mac);
131
132         ath79_register_mdio(0, 0x0);
133
134         ath79_init_mac(ath79_eth1_data.mac_addr, mac, 0);
135
136         /* LAN ports */
137         ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
138         ath79_eth1_data.speed = SPEED_1000;
139         ath79_eth1_data.duplex = DUPLEX_FULL;
140         ath79_switch_data.phy_poll_mask |= BIT(4);
141         ath79_switch_data.phy4_mii_en = 1;
142         ath79_register_eth(1);
143 }
144
145 MIPS_MACHINE(ATH79_MACH_DAP_1330_A1, "DAP-1330-A1",
146              "D-Link DAP-1330 Rev. A1", dap_1330_setup);