e48ddd65e7c37d6955824a158aa03316b6b52108
[oweals/openwrt.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-fritz450e.c
1 /*
2  *  AVM FRITZ!WLAN Repeater 450E board support
3  *
4  *  Copyright (C) 2018 David Bauer <mail@david-bauer.net>
5  *
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.
9  */
10
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>
16
17 #include <linux/mtd/mtd.h>
18 #include <linux/mtd/partitions.h>
19 #include <linux/platform_data/mdio-gpio.h>
20 #include <linux/platform_data/phy-at803x.h>
21 #include <linux/spi/spi_gpio.h>
22 #include <linux/spi/74x164.h>
23
24 #include <asm/mach-ath79/ath79.h>
25 #include <asm/mach-ath79/ar71xx_regs.h>
26
27 #include "common.h"
28 #include "dev-eth.h"
29 #include "dev-gpio-buttons.h"
30 #include "dev-leds-gpio.h"
31 #include "dev-m25p80.h"
32 #include "dev-spi.h"
33 #include "dev-wmac.h"
34 #include "machtypes.h"
35
36 #define FRITZ450E_GPIO_LED_POWER                14
37 #define FRITZ450E_GPIO_LED_LAN                  13
38 #define FRITZ450E_GPIO_LED_WLAN                 15
39 #define FRITZ450E_GPIO_LED_RSSI2                        16
40 #define FRITZ450E_GPIO_LED_RSSI3                        17
41 #define FRITZ450E_GPIO_LED_RSSI4                        18
42
43 #define FRITZ450E_GPIO_BTN_WPS                  4
44 #define FRITZ450E_KEYS_POLL_INTERVAL            20 /* msecs */
45 #define FRITZ450E_KEYS_DEBOUNCE_INTERVAL        (3 * FRITZ450E_KEYS_POLL_INTERVAL)
46
47 #define FRITZ450E_PHY_ADDRESS                   0
48 #define FRITZ450E_GPIO_PHY_RESET                11
49 #define FRITZ450E_GPIO_MDIO_CLK         12
50 #define FRITZ450E_GPIO_MDIO_DATA                19
51
52 #define FRITZ450E_OFFSET_URLADER_WIFI_MAC_REVERSE       0x1979
53
54
55 static struct mtd_partition fritz450E_flash_partitions[] = {
56         {
57                 .name           = "urlader",
58                 .offset         = 0,
59                 .size           = 0x0020000,
60                 .mask_flags     = MTD_WRITEABLE,
61         }, {
62                 .name           = "firmware",
63                 .offset         = 0x0020000,
64                 .size           = 0x0EE0000,
65         }, {
66                 .name           = "tffs (1)",
67                 .offset         = 0x0f00000,
68                 .size           = 0x0080000,
69                 .mask_flags     = MTD_WRITEABLE,
70         }, {
71                 .name           = "tffs (2)",
72                 .offset         = 0x0f80000,
73                 .size           = 0x0080000,
74                 .mask_flags     = MTD_WRITEABLE,
75         }
76 };
77
78 static struct flash_platform_data fritz450E_flash_data = {
79         .parts          = fritz450E_flash_partitions,
80         .nr_parts       = ARRAY_SIZE(fritz450E_flash_partitions),
81 };
82
83 static struct gpio_led fritz450E_leds_gpio[] __initdata = {
84         {
85                 .name           = "fritz450e:green:lan",
86                 .gpio           = FRITZ450E_GPIO_LED_LAN,
87                 .active_low     = 1,
88         }, {
89                 .name           = "fritz450e:green:rssi2",
90                 .gpio           = FRITZ450E_GPIO_LED_RSSI2,
91                 .active_low     = 1,
92         }, {
93                 .name           = "fritz450e:green:rssi3",
94                 .gpio           = FRITZ450E_GPIO_LED_RSSI3,
95                 .active_low     = 1,
96         }, {
97                 .name           = "fritz450e:green:rssi4",
98                 .gpio           = FRITZ450E_GPIO_LED_RSSI4,
99                 .active_low     = 1,
100         }, {
101                 .name           = "fritz450e:green:wlan",
102                 .gpio           = FRITZ450E_GPIO_LED_WLAN,
103                 .active_low     = 1,
104         }, {
105                 .name           = "fritz450e:green:power",
106                 .gpio           = FRITZ450E_GPIO_LED_POWER,
107                 .active_low     = 0,
108         },
109 };
110
111 static struct gpio_keys_button fritz450E_gpio_keys[] __initdata = {
112         {
113                 .desc                   = "WPS Button",
114                 .type                   = EV_KEY,
115                 .code                   = KEY_WPS_BUTTON,
116                 .debounce_interval      = FRITZ450E_KEYS_DEBOUNCE_INTERVAL,
117                 .gpio                   = FRITZ450E_GPIO_BTN_WPS,
118                 .active_low             = 1,
119         }
120 };
121
122 static struct at803x_platform_data fritz450E_at803x_data = {
123         .disable_smarteee = 1,
124         .has_reset_gpio = 1,
125         .reset_gpio = FRITZ450E_GPIO_PHY_RESET,
126 };
127
128 static struct mdio_board_info fritz450E_mdio_info[] = {
129         {
130                 .bus_id = "ag71xx-mdio.1",
131                 .phy_addr = FRITZ450E_PHY_ADDRESS,
132                 .platform_data = &fritz450E_at803x_data,
133         },
134 };
135
136 static void __init fritz450E_setup(void) {
137         u8 *urlader = (u8 *) KSEG1ADDR(0x1f000000);
138         u8 wifi_mac[ETH_ALEN];
139
140         ath79_register_m25p80(&fritz450E_flash_data);
141
142         gpio_request_one(FRITZ450E_GPIO_MDIO_CLK, GPIOF_OUT_INIT_HIGH, "MDC Pull-UP");
143         gpio_request_one(FRITZ450E_GPIO_MDIO_DATA, GPIOF_OUT_INIT_HIGH, "MDIO Pull-UP");
144         gpio_request_one(FRITZ450E_GPIO_PHY_RESET, GPIOF_OUT_INIT_HIGH, "PHY reset");
145
146         /* Register PHY device */
147         mdiobus_register_board_info(fritz450E_mdio_info,
148                                     ARRAY_SIZE(fritz450E_mdio_info));
149
150         /* Initialize Ethernet */
151         ath79_extract_mac_reverse(urlader + FRITZ450E_OFFSET_URLADER_WIFI_MAC_REVERSE, wifi_mac);
152         ath79_init_mac(ath79_eth0_data.mac_addr, wifi_mac, -2);
153
154         ath79_register_mdio(1, ~BIT(FRITZ450E_PHY_ADDRESS));
155         ath79_eth0_data.mii_bus_dev = &ath79_mdio1_device.dev;
156         ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_SGMII;
157         ath79_eth0_data.phy_mask = BIT(FRITZ450E_PHY_ADDRESS);
158         ath79_eth0_data.enable_sgmii_fixup = 1;
159         ath79_eth0_pll_data.pll_1000 = 0x03000000;
160         ath79_eth0_pll_data.pll_100 = 0x00000101;
161         ath79_eth0_pll_data.pll_10 = 0x00001313;
162         ath79_register_eth(0);
163
164         /* Initialize 2.4GHz WiFi */
165         ath79_register_wmac_simple();
166
167         /* Register GPIO buttons */
168         ath79_register_gpio_keys_polled(-1, FRITZ450E_KEYS_POLL_INTERVAL,
169                                         ARRAY_SIZE(fritz450E_gpio_keys),
170                                         fritz450E_gpio_keys);
171
172         /* Register LEDs */
173         ath79_register_leds_gpio(-1, ARRAY_SIZE(fritz450E_leds_gpio),
174                                  fritz450E_leds_gpio);
175 }
176
177 MIPS_MACHINE(ATH79_MACH_FRITZ450E, "FRITZ450E",
178              "AVM FRITZ!WLAN Repeater 450E", fritz450E_setup);