2 * D-Link DIR-869 A1 support
4 * Copyright (C) 2015-2016 P. Wassi <p.wassi at gmx.at>
5 * Copyright (C) 2016 Matthias Schiffer <mschiffer@universe-factory.net>
7 * Derived from: mach-ubnt-unifiac.c
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.
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>
21 #include <asm/mach-ath79/ath79.h>
22 #include <asm/mach-ath79/irq.h>
23 #include <asm/mach-ath79/ar71xx_regs.h>
25 #include <linux/platform_data/phy-at803x.h>
26 #include <linux/ar8216_platform.h>
29 #include "dev-ap9x-pci.h"
31 #include "dev-gpio-buttons.h"
32 #include "dev-leds-gpio.h"
33 #include "dev-m25p80.h"
35 #include "machtypes.h"
39 #define DIR869A1_GPIO_BTN_RESET 1
40 #define DIR869A1_GPIO_BTN_WPS 2
41 #define DIR869A1_GPIO_SWITCH_MODE 8
43 #define DIR869A1_GPIO_ENABLE_SWITCH 11
45 #define DIR869A1_GPIO_LED_POWER 15
46 #define DIR869A1_GPIO_LED_ORANGE 16
48 #define DIR869A1_KEYS_POLL_INTERVAL 20 /* msecs */
49 #define DIR869A1_KEYS_DEBOUNCE_INTERVAL (3 * DIR869A1_KEYS_POLL_INTERVAL)
52 #define DIR869A1_DEVDATA_ADDR 0x1f050000
53 #define DIR869A1_DEVDATA_SIZE 0x10000
55 #define DIR869A1_EEPROM_ADDR 0x1fff0000
56 #define DIR869A1_WMAC_CALDATA_OFFSET 0x1000
57 #define DIR869A1_PCI_CALDATA_OFFSET 0x5000
60 static struct gpio_led dir869a1_leds_gpio[] __initdata = {
62 /* Actually, this GPIO controls the LED power,
63 * while d-link:orange:status switches it between
65 .name = "d-link:white:status",
66 .gpio = DIR869A1_GPIO_LED_POWER,
70 .name = "d-link:orange:status",
71 .gpio = DIR869A1_GPIO_LED_ORANGE,
76 static struct gpio_keys_button dir869a1_gpio_keys[] __initdata = {
81 .debounce_interval = DIR869A1_KEYS_DEBOUNCE_INTERVAL,
82 .gpio = DIR869A1_GPIO_BTN_RESET,
88 .code = KEY_WPS_BUTTON,
89 .debounce_interval = DIR869A1_KEYS_DEBOUNCE_INTERVAL,
90 .gpio = DIR869A1_GPIO_BTN_WPS,
97 .debounce_interval = DIR869A1_KEYS_DEBOUNCE_INTERVAL,
98 .gpio = DIR869A1_GPIO_SWITCH_MODE,
104 static struct ar8327_pad_cfg dir869a1_ar8327_pad0_cfg = {
105 .mode = AR8327_PAD_MAC_SGMII,
106 .sgmii_delay_en = true,
109 static struct ar8327_platform_data dir869a1_ar8327_data = {
110 .pad0_cfg = &dir869a1_ar8327_pad0_cfg,
113 .speed = AR8327_PORT_SPEED_1000,
121 static struct mdio_board_info dir869a1_mdio0_info[] = {
123 .bus_id = "ag71xx-mdio.0",
125 .platform_data = &dir869a1_ar8327_data,
130 static void dir869a1_get_mac(const char *name, char *mac)
132 u8 *nvram = (u8 *) KSEG1ADDR(DIR869A1_DEVDATA_ADDR);
135 err = ath79_nvram_parse_mac_addr(nvram, DIR869A1_DEVDATA_SIZE,
138 pr_err("no MAC address found for %s\n", name);
141 static void __init dir869a1_setup(void)
143 u8 *eeprom = (u8 *) KSEG1ADDR(DIR869A1_EEPROM_ADDR);
144 u8 wlan24mac[ETH_ALEN] = {}, wlan5mac[ETH_ALEN] = {};
146 ath79_register_m25p80(NULL);
148 gpio_request_one(DIR869A1_GPIO_ENABLE_SWITCH,
149 GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
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);
157 mdiobus_register_board_info(dir869a1_mdio0_info,
158 ARRAY_SIZE(dir869a1_mdio0_info));
160 ath79_register_mdio(0, 0);
161 ath79_register_eth(0);
163 dir869a1_get_mac("wlan24mac=", wlan24mac);
164 ath79_register_wmac(eeprom + DIR869A1_WMAC_CALDATA_OFFSET, wlan24mac);
166 dir869a1_get_mac("wlan5mac=", wlan5mac);
167 ap91_pci_init(eeprom + DIR869A1_PCI_CALDATA_OFFSET, wlan5mac);
169 ath79_register_leds_gpio(-1, ARRAY_SIZE(dir869a1_leds_gpio),
172 ath79_register_gpio_keys_polled(-1, DIR869A1_KEYS_POLL_INTERVAL,
173 ARRAY_SIZE(dir869a1_gpio_keys),
177 MIPS_MACHINE(ATH79_MACH_DIR_869_A1, "DIR-869-A1", "D-Link DIR-869 rev. A1",