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_ORANGE 15
46 #define DIR869A1_GPIO_LED_WHITE 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 .name
= "d-link:white:status",
63 .gpio
= DIR869A1_GPIO_LED_WHITE
,
67 .name
= "d-link:orange:status",
68 .gpio
= DIR869A1_GPIO_LED_ORANGE
,
73 static struct gpio_keys_button dir869a1_gpio_keys
[] __initdata
= {
78 .debounce_interval
= DIR869A1_KEYS_DEBOUNCE_INTERVAL
,
79 .gpio
= DIR869A1_GPIO_BTN_RESET
,
85 .code
= KEY_WPS_BUTTON
,
86 .debounce_interval
= DIR869A1_KEYS_DEBOUNCE_INTERVAL
,
87 .gpio
= DIR869A1_GPIO_BTN_WPS
,
94 .debounce_interval
= DIR869A1_KEYS_DEBOUNCE_INTERVAL
,
95 .gpio
= DIR869A1_GPIO_SWITCH_MODE
,
101 static struct ar8327_pad_cfg dir869a1_ar8327_pad0_cfg
= {
102 .mode
= AR8327_PAD_MAC_SGMII
,
103 .sgmii_delay_en
= true,
106 static struct ar8327_platform_data dir869a1_ar8327_data
= {
107 .pad0_cfg
= &dir869a1_ar8327_pad0_cfg
,
110 .speed
= AR8327_PORT_SPEED_1000
,
118 static struct mdio_board_info dir869a1_mdio0_info
[] = {
120 .bus_id
= "ag71xx-mdio.0",
122 .platform_data
= &dir869a1_ar8327_data
,
127 static void dir869a1_get_mac(const char *name
, char *mac
)
129 u8
*nvram
= (u8
*) KSEG1ADDR(DIR869A1_DEVDATA_ADDR
);
132 err
= ath79_nvram_parse_mac_addr(nvram
, DIR869A1_DEVDATA_SIZE
,
135 pr_err("no MAC address found for %s\n", name
);
138 static void __init
dir869a1_setup(void)
140 u8
*eeprom
= (u8
*) KSEG1ADDR(DIR869A1_EEPROM_ADDR
);
141 u8 wlan24mac
[ETH_ALEN
] = {}, wlan5mac
[ETH_ALEN
] = {};
143 ath79_register_m25p80(NULL
);
145 gpio_request_one(DIR869A1_GPIO_ENABLE_SWITCH
,
146 GPIOF_OUT_INIT_HIGH
| GPIOF_EXPORT_DIR_FIXED
,
149 dir869a1_get_mac("lanmac=", ath79_eth0_data
.mac_addr
);
150 ath79_eth0_data
.phy_if_mode
= PHY_INTERFACE_MODE_SGMII
;
151 ath79_eth0_data
.mii_bus_dev
= &ath79_mdio0_device
.dev
;
152 ath79_eth0_data
.phy_mask
= BIT(0);
154 mdiobus_register_board_info(dir869a1_mdio0_info
,
155 ARRAY_SIZE(dir869a1_mdio0_info
));
157 ath79_register_mdio(0, 0);
158 ath79_register_eth(0);
160 dir869a1_get_mac("wlan24mac=", wlan24mac
);
161 ath79_register_wmac(eeprom
+ DIR869A1_WMAC_CALDATA_OFFSET
, wlan24mac
);
163 dir869a1_get_mac("wlan5mac=", wlan5mac
);
164 ap91_pci_init(eeprom
+ DIR869A1_PCI_CALDATA_OFFSET
, wlan5mac
);
166 ath79_register_leds_gpio(-1, ARRAY_SIZE(dir869a1_leds_gpio
),
169 ath79_register_gpio_keys_polled(-1, DIR869A1_KEYS_POLL_INTERVAL
,
170 ARRAY_SIZE(dir869a1_gpio_keys
),
174 MIPS_MACHINE(ATH79_MACH_DIR_869_A1
, "DIR-869-A1", "D-Link DIR-869 rev. A1",