2 * AVM FRITZ!Box 4020 board support
4 * Copyright (C) 2018 David Bauer <mail@david-bauer.net>
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.
11 #include <linux/init.h>
12 #include <linux/ath9k_platform.h>
13 #include <linux/etherdevice.h>
14 #include <linux/gpio.h>
15 #include <linux/platform_device.h>
17 #include <linux/mtd/mtd.h>
18 #include <linux/mtd/partitions.h>
19 #include <linux/platform_data/mdio-gpio.h>
20 #include <linux/spi/spi_gpio.h>
21 #include <linux/spi/74x164.h>
23 #include <asm/mach-ath79/ath79.h>
24 #include <asm/mach-ath79/ar71xx_regs.h>
28 #include "dev-gpio-buttons.h"
29 #include "dev-leds-gpio.h"
30 #include "dev-m25p80.h"
34 #include "machtypes.h"
37 #define FRITZ4020_GPIO_SHIFT_SER 19 /* DS, Data Serial Input */
38 #define FRITZ4020_GPIO_SHIFT_SRCLK 20 /* SHCP, Shift Reg Clock Input */
40 #define FRITZ4020_SSR_BIT_0 0
41 #define FRITZ4020_SSR_BIT_1 1
42 #define FRITZ4020_SSR_BIT_2 2
43 #define FRITZ4020_SSR_BIT_3 3
44 #define FRITZ4020_SSR_BIT_4 4
45 #define FRITZ4020_SSR_BIT_5 5
46 #define FRITZ4020_SSR_BIT_6 6
47 #define FRITZ4020_SSR_BIT_7 7
49 #define FRITZ4020_74HC_GPIO_BASE 32
50 #define FRITZ4020_74HC_GPIO_LED_LAN (FRITZ4020_74HC_GPIO_BASE + 0)
51 #define FRITZ4020_74HC_GPIO_LED_INFO_RED (FRITZ4020_74HC_GPIO_BASE + 1)
52 #define FRITZ4020_74HC_GPIO_LED_POWER (FRITZ4020_74HC_GPIO_BASE + 2)
53 #define FRITZ4020_74HC_GPIO_LED_WLAN (FRITZ4020_74HC_GPIO_BASE + 3)
54 #define FRITZ4020_74HC_GPIO_LED_WAN (FRITZ4020_74HC_GPIO_BASE + 4)
55 #define FRITZ4020_74HC_GPIO_USB_RST (FRITZ4020_74HC_GPIO_BASE + 5)
56 #define FRITZ4020_74HC_GPIO_LED_INFO (FRITZ4020_74HC_GPIO_BASE + 6)
59 #define FRITZ4020_GPIO_BTN_WPS 2
60 #define FRITZ4020_GPIO_BTN_WLAN 21
61 #define FRITZ4020_KEYS_POLL_INTERVAL 20 /* msecs */
62 #define FRITZ4020_KEYS_DEBOUNCE_INTERVAL (3 * FRITZ4020_KEYS_POLL_INTERVAL)
64 #define FRTIZ4020_OFFSET_URLADER_WIFI_MAC_REVERSE 0x1979
67 static struct spi_gpio_platform_data fritz4020_spi_data
= {
68 .sck
= FRITZ4020_GPIO_SHIFT_SRCLK
,
69 .miso
= SPI_GPIO_NO_MISO
,
70 .mosi
= FRITZ4020_GPIO_SHIFT_SER
,
74 static u8 fritz4020_ssr_initdata
[] = {
75 BIT(FRITZ4020_SSR_BIT_7
) |
76 BIT(FRITZ4020_SSR_BIT_6
) |
77 BIT(FRITZ4020_SSR_BIT_5
) |
78 BIT(FRITZ4020_SSR_BIT_4
) |
79 BIT(FRITZ4020_SSR_BIT_3
) |
80 BIT(FRITZ4020_SSR_BIT_2
) |
81 BIT(FRITZ4020_SSR_BIT_1
)
84 static struct gen_74x164_chip_platform_data fritz4020_ssr_data
= {
85 .base
= FRITZ4020_74HC_GPIO_BASE
,
86 .num_registers
= ARRAY_SIZE(fritz4020_ssr_initdata
),
87 .init_data
= fritz4020_ssr_initdata
,
90 static struct platform_device fritz4020_spi_device
= {
94 .platform_data
= &fritz4020_spi_data
,
98 static struct spi_board_info fritz4020_spi_info
[] = {
102 .max_speed_hz
= 10000000,
103 .modalias
= "74x164",
104 .platform_data
= &fritz4020_ssr_data
,
105 .controller_data
= (void *) 0x0,
109 static struct mtd_partition fritz4020_flash_partitions
[] = {
114 .mask_flags
= MTD_WRITEABLE
,
123 .mask_flags
= MTD_WRITEABLE
,
128 .mask_flags
= MTD_WRITEABLE
,
132 static struct flash_platform_data fritz4020_flash_data
= {
133 .parts
= fritz4020_flash_partitions
,
134 .nr_parts
= ARRAY_SIZE(fritz4020_flash_partitions
),
137 static struct gpio_led fritz4020_leds_gpio
[] __initdata
= {
139 .name
= "fritz4020:green:lan",
140 .gpio
= FRITZ4020_74HC_GPIO_LED_LAN
,
143 .name
= "fritz4020:green:info",
144 .gpio
= FRITZ4020_74HC_GPIO_LED_INFO
,
147 .name
= "fritz4020:red:info",
148 .gpio
= FRITZ4020_74HC_GPIO_LED_INFO_RED
,
151 .name
= "fritz4020:green:power",
152 .gpio
= FRITZ4020_74HC_GPIO_LED_POWER
,
155 .name
= "fritz4020:green:wlan",
156 .gpio
= FRITZ4020_74HC_GPIO_LED_WLAN
,
159 .name
= "fritz4020:green:wan",
160 .gpio
= FRITZ4020_74HC_GPIO_LED_WAN
,
165 static struct gpio_keys_button fritz4020_gpio_keys
[] __initdata
= {
167 .desc
= "RFKILL button",
170 .debounce_interval
= FRITZ4020_KEYS_DEBOUNCE_INTERVAL
,
171 .gpio
= FRITZ4020_GPIO_BTN_WLAN
,
175 .desc
= "WPS button",
177 .code
= KEY_WPS_BUTTON
,
178 .debounce_interval
= FRITZ4020_KEYS_DEBOUNCE_INTERVAL
,
179 .gpio
= FRITZ4020_GPIO_BTN_WPS
,
184 static void __init
fritz4020_setup(void) {
185 u8
*urlader
= (u8
*) KSEG1ADDR(0x1f000000);
186 u8 wifi_mac
[ETH_ALEN
];
188 ath79_register_m25p80(&fritz4020_flash_data
);
190 /* Initialize ethernet */
191 ath79_extract_mac_reverse(urlader
+ FRTIZ4020_OFFSET_URLADER_WIFI_MAC_REVERSE
, wifi_mac
);
192 ath79_setup_qca956x_eth_cfg(QCA956X_ETH_CFG_SW_PHY_SWAP
|
193 QCA956X_ETH_CFG_SW_PHY_ADDR_SWAP
);
195 ath79_register_mdio(0, 0x0);
196 ath79_register_mdio(1, 0x0);
197 ath79_init_mac(ath79_eth0_data
.mac_addr
, wifi_mac
, -1);
198 ath79_init_mac(ath79_eth1_data
.mac_addr
, wifi_mac
, -2);
201 ath79_eth0_data
.phy_if_mode
= PHY_INTERFACE_MODE_MII
;
202 ath79_eth0_data
.speed
= SPEED_100
;
203 ath79_eth0_data
.duplex
= DUPLEX_FULL
;
204 ath79_eth0_data
.phy_mask
= BIT(0);
205 ath79_register_eth(0);
208 ath79_eth1_data
.phy_if_mode
= PHY_INTERFACE_MODE_GMII
;
209 ath79_eth1_data
.speed
= SPEED_1000
;
210 ath79_eth1_data
.duplex
= DUPLEX_FULL
;
211 ath79_switch_data
.phy_poll_mask
|= BIT(0);
212 ath79_switch_data
.phy4_mii_en
= 1;
213 ath79_register_eth(1);
215 /* Initialize 2.4GHz WiFi */
216 ath79_register_wmac_simple();
218 /* Activate USB Power */
219 gpio_request_one(FRITZ4020_74HC_GPIO_USB_RST
,
220 GPIOF_OUT_INIT_HIGH
| GPIOF_EXPORT_DIR_FIXED
,
223 /* Initialize USB port */
224 ath79_register_usb();
226 /* Register LED shift-register */
227 spi_register_board_info(fritz4020_spi_info
,
228 ARRAY_SIZE(fritz4020_spi_info
));
229 platform_device_register(&fritz4020_spi_device
);
231 /* Register GPIO buttons */
232 ath79_register_gpio_keys_polled(-1, FRITZ4020_KEYS_POLL_INTERVAL
,
233 ARRAY_SIZE(fritz4020_gpio_keys
),
234 fritz4020_gpio_keys
);
237 ath79_register_leds_gpio(-1, ARRAY_SIZE(fritz4020_leds_gpio
),
238 fritz4020_leds_gpio
);
241 MIPS_MACHINE(ATH79_MACH_FRITZ4020
, "FRITZ4020",
242 "AVM FRITZ!Box 4020", fritz4020_setup
);