ar71xx: add support for YunCore CPE830
[oweals/openwrt.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-dir-869-a1.c
1 /*
2  *  D-Link DIR-869 A1 support
3  *
4  *  Copyright (C) 2015-2016 P. Wassi <p.wassi at gmx.at>
5  *  Copyright (C) 2016 Matthias Schiffer <mschiffer@universe-factory.net>
6  *
7  *  Derived from: mach-ubnt-unifiac.c
8  *
9  *  This program is free software; you can redistribute it and/or modify it
10  *  under the terms of the GNU General Public License version 2 as published
11  *  by the Free Software Foundation.
12  */
13
14
15 #include <linux/gpio.h>
16 #include <linux/init.h>
17 #include <linux/pci.h>
18 #include <linux/platform_device.h>
19 #include <linux/ath9k_platform.h>
20
21 #include <asm/mach-ath79/ath79.h>
22 #include <asm/mach-ath79/irq.h>
23 #include <asm/mach-ath79/ar71xx_regs.h>
24
25 #include <linux/platform_data/phy-at803x.h>
26 #include <linux/ar8216_platform.h>
27
28 #include "common.h"
29 #include "dev-ap9x-pci.h"
30 #include "dev-eth.h"
31 #include "dev-gpio-buttons.h"
32 #include "dev-leds-gpio.h"
33 #include "dev-m25p80.h"
34 #include "dev-wmac.h"
35 #include "machtypes.h"
36 #include "nvram.h"
37
38
39 #define DIR869A1_GPIO_BTN_RESET         1
40 #define DIR869A1_GPIO_BTN_WPS           2
41 #define DIR869A1_GPIO_SWITCH_MODE       8
42
43 #define DIR869A1_GPIO_ENABLE_SWITCH     11
44
45 #define DIR869A1_GPIO_LED_POWER         15
46 #define DIR869A1_GPIO_LED_ORANGE        16
47
48 #define DIR869A1_KEYS_POLL_INTERVAL     20 /* msecs */
49 #define DIR869A1_KEYS_DEBOUNCE_INTERVAL (3 * DIR869A1_KEYS_POLL_INTERVAL)
50
51
52 #define DIR869A1_DEVDATA_ADDR           0x1f050000
53 #define DIR869A1_DEVDATA_SIZE           0x10000
54
55 #define DIR869A1_EEPROM_ADDR            0x1fff0000
56 #define DIR869A1_WMAC_CALDATA_OFFSET    0x1000
57 #define DIR869A1_PCI_CALDATA_OFFSET     0x5000
58
59
60 static struct gpio_led dir869a1_leds_gpio[] __initdata = {
61         {
62                 /* Actually, this GPIO controls the LED power,
63                  * while d-link:orange:status switches it between
64                  * orange and white */
65                 .name           = "d-link:white:status",
66                 .gpio           = DIR869A1_GPIO_LED_POWER,
67                 .active_low     = 1,
68         },
69         {
70                 .name           = "d-link:orange:status",
71                 .gpio           = DIR869A1_GPIO_LED_ORANGE,
72                 .active_low     = 0,
73         },
74 };
75
76 static struct gpio_keys_button dir869a1_gpio_keys[] __initdata = {
77         {
78                 .desc           = "reset",
79                 .type           = EV_KEY,
80                 .code           = KEY_RESTART,
81                 .debounce_interval = DIR869A1_KEYS_DEBOUNCE_INTERVAL,
82                 .gpio           = DIR869A1_GPIO_BTN_RESET,
83                 .active_low     = 1,
84         },
85         {
86                 .desc           = "wps",
87                 .type           = EV_KEY,
88                 .code           = KEY_WPS_BUTTON,
89                 .debounce_interval = DIR869A1_KEYS_DEBOUNCE_INTERVAL,
90                 .gpio           = DIR869A1_GPIO_BTN_WPS,
91                 .active_low     = 1,
92         },
93         {
94                 .desc           = "mode",
95                 .type           = EV_SW,
96                 .code           = BTN_0,
97                 .debounce_interval = DIR869A1_KEYS_DEBOUNCE_INTERVAL,
98                 .gpio           = DIR869A1_GPIO_SWITCH_MODE,
99                 .active_low     = 0,
100         },
101 };
102
103
104 static struct ar8327_pad_cfg dir869a1_ar8327_pad0_cfg = {
105         .mode = AR8327_PAD_MAC_SGMII,
106         .sgmii_delay_en = true,
107 };
108
109 static struct ar8327_platform_data dir869a1_ar8327_data = {
110         .pad0_cfg = &dir869a1_ar8327_pad0_cfg,
111         .port0_cfg = {
112                 .force_link = 1,
113                 .speed = AR8327_PORT_SPEED_1000,
114                 .duplex = 1,
115                 .txpause = 1,
116                 .rxpause = 1,
117         },
118 };
119
120
121 static struct mdio_board_info dir869a1_mdio0_info[] = {
122         {
123                 .bus_id = "ag71xx-mdio.0",
124                 .phy_addr = 0,
125                 .platform_data = &dir869a1_ar8327_data,
126         },
127 };
128
129
130 static void dir869a1_get_mac(const char *name, char *mac)
131 {
132         u8 *nvram = (u8 *) KSEG1ADDR(DIR869A1_DEVDATA_ADDR);
133         int err;
134
135         err = ath79_nvram_parse_mac_addr(nvram, DIR869A1_DEVDATA_SIZE,
136                                          name, mac);
137         if (err)
138                 pr_err("no MAC address found for %s\n", name);
139 }
140
141 static void __init dir869a1_setup(void)
142 {
143         u8 *eeprom = (u8 *) KSEG1ADDR(DIR869A1_EEPROM_ADDR);
144         u8 wlan24mac[ETH_ALEN] = {}, wlan5mac[ETH_ALEN] = {};
145
146         ath79_register_m25p80(NULL);
147
148         gpio_request_one(DIR869A1_GPIO_ENABLE_SWITCH,
149                          GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
150                          "Switch power");
151
152         dir869a1_get_mac("lanmac=", ath79_eth0_data.mac_addr);
153         ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_SGMII;
154         ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev;
155         ath79_eth0_data.phy_mask = BIT(0);
156
157         mdiobus_register_board_info(dir869a1_mdio0_info,
158                                     ARRAY_SIZE(dir869a1_mdio0_info));
159
160         ath79_register_mdio(0, 0);
161         ath79_register_eth(0);
162
163         dir869a1_get_mac("wlan24mac=", wlan24mac);
164         ath79_register_wmac(eeprom + DIR869A1_WMAC_CALDATA_OFFSET, wlan24mac);
165
166         dir869a1_get_mac("wlan5mac=", wlan5mac);
167         ap91_pci_init(eeprom + DIR869A1_PCI_CALDATA_OFFSET, wlan5mac);
168
169         ath79_register_leds_gpio(-1, ARRAY_SIZE(dir869a1_leds_gpio),
170                                  dir869a1_leds_gpio);
171
172         ath79_register_gpio_keys_polled(-1, DIR869A1_KEYS_POLL_INTERVAL,
173                                         ARRAY_SIZE(dir869a1_gpio_keys),
174                                         dir869a1_gpio_keys);
175 }
176
177 MIPS_MACHINE(ATH79_MACH_DIR_869_A1, "DIR-869-A1", "D-Link DIR-869 rev. A1",
178              dir869a1_setup);