ar71xx: fix section mismatch in TP-Link Archer C7 v4 support
[openwrt/openwrt.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-z1.c
1 /*
2 * Cisco Meraki Z1 board support
3 *
4 * Copyright (C) 2016 Chris Blake <chrisrblake93@gmail.com>
5 * Copyright (C) 2016 Christian Lamparter <chunkeey@googlemail.com>
6 *
7 * Based on Cisco Meraki GPL Release r23-20150601 Z1 Device Config
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 #include <linux/platform_device.h>
14 #include <linux/ath9k_platform.h>
15 #include <linux/ar8216_platform.h>
16 #include <linux/platform/ar934x_nfc.h>
17
18 #include <asm/mach-ath79/ath79.h>
19 #include <asm/mach-ath79/ar71xx_regs.h>
20
21 #include <linux/leds-nu801.h>
22 #include <linux/firmware.h>
23 #include <linux/pci.h>
24
25 #include "common.h"
26 #include "dev-eth.h"
27 #include "dev-gpio-buttons.h"
28 #include "dev-leds-gpio.h"
29 #include "dev-nfc.h"
30 #include "dev-usb.h"
31 #include "dev-wmac.h"
32 #include "dev-ap9x-pci.h"
33 #include "machtypes.h"
34
35 #define Z1_GPIO_LED_POWER_ORANGE 17
36
37 #define Z1_GPIO_NU801_CKI 14
38 #define Z1_GPIO_NU801_SDI 15
39
40 #define Z1_GPIO_XLNA0 18
41 #define Z1_GPIO_XLNA1 19
42
43 #define Z1_GPIO_BTN_RESET 12
44 #define Z1_KEYS_POLL_INTERVAL 20 /* msecs */
45 #define Z1_KEYS_DEBOUNCE_INTERVAL (3 * Z1_KEYS_POLL_INTERVAL)
46
47 #define Z1_ETH_SWITCH_PHY 0
48
49 static struct gpio_led Z1_leds_gpio[] __initdata = {
50 {
51 .name = "z1:orange:power",
52 .gpio = Z1_GPIO_LED_POWER_ORANGE,
53 .active_low = 1,
54 },
55 };
56
57 static struct gpio_keys_button Z1_gpio_keys[] __initdata = {
58 {
59 .desc = "reset",
60 .type = EV_KEY,
61 .code = KEY_RESTART,
62 .debounce_interval = Z1_KEYS_DEBOUNCE_INTERVAL,
63 .gpio = Z1_GPIO_BTN_RESET,
64 .active_low = 1,
65 },
66 };
67
68 static struct led_nu801_template tricolor_led_template = {
69 .device_name = "z1",
70 .name = "tricolor",
71 .num_leds = 1,
72 .cki = Z1_GPIO_NU801_CKI,
73 .sdi = Z1_GPIO_NU801_SDI,
74 .lei = -1,
75 .ndelay = 500,
76 .init_brightness = {
77 LED_OFF,
78 LED_OFF,
79 LED_OFF,
80 },
81 .default_trigger = "none",
82 };
83
84 static struct led_nu801_platform_data tricolor_led_data = {
85 .num_controllers = 1,
86 .template = &tricolor_led_template,
87 };
88
89 static struct platform_device tricolor_leds = {
90 .name = "leds-nu801",
91 .id = -1,
92 .dev.platform_data = &tricolor_led_data,
93 };
94
95 static struct ar8327_pad_cfg z1_ar8327_pad0_cfg = {
96 .mode = AR8327_PAD_MAC_RGMII,
97 .txclk_delay_en = true,
98 .rxclk_delay_en = true,
99 .txclk_delay_sel = AR8327_CLK_DELAY_SEL1,
100 .rxclk_delay_sel = AR8327_CLK_DELAY_SEL2,
101 };
102
103 static struct ar8327_platform_data z1_ar8327_data = {
104 .pad0_cfg = &z1_ar8327_pad0_cfg,
105 .port0_cfg = {
106 .force_link = 1,
107 .speed = AR8327_PORT_SPEED_1000,
108 .duplex = 1,
109 .txpause = 1,
110 .rxpause = 1,
111 },
112 };
113
114 static struct mdio_board_info z1_mdio0_info[] = {
115 {
116 .bus_id = "ag71xx-mdio.0",
117 .phy_addr = Z1_ETH_SWITCH_PHY,
118 .platform_data = &z1_ar8327_data,
119 },
120 };
121
122 static void __init z1_setup(void)
123 {
124 /* NAND */
125 ath79_nfc_set_ecc_mode(AR934X_NFC_ECC_SOFT_BCH);
126 ath79_register_nfc();
127
128 /* Eth Config */
129 ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_RGMII_GMAC0 |
130 AR934X_ETH_CFG_SW_ONLY_MODE);
131
132 /* MDIO Interface */
133 ath79_register_mdio(1, 0x0);
134 ath79_register_mdio(0, 0x0);
135 mdiobus_register_board_info(z1_mdio0_info,
136 ARRAY_SIZE(z1_mdio0_info));
137
138 /* GMAC0 is connected to an AR8327 switch */
139 ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
140 ath79_eth0_data.phy_mask = BIT(Z1_ETH_SWITCH_PHY);
141 ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev;
142 ath79_eth0_pll_data.pll_1000 = 0x06000000;
143 ath79_register_eth(0);
144
145 /* XLNA */
146 ath79_wmac_set_ext_lna_gpio(0, Z1_GPIO_XLNA0);
147 ath79_wmac_set_ext_lna_gpio(1, Z1_GPIO_XLNA1);
148
149 /* LEDs and Buttons */
150 platform_device_register(&tricolor_leds);
151 ath79_register_leds_gpio(-1, ARRAY_SIZE(Z1_leds_gpio),
152 Z1_leds_gpio);
153 ath79_register_gpio_keys_polled(-1, Z1_KEYS_POLL_INTERVAL,
154 ARRAY_SIZE(Z1_gpio_keys),
155 Z1_gpio_keys);
156
157 /* USB */
158 ath79_register_usb();
159
160 /* Wireless */
161 ath79_register_wmac_simple();
162 ap91_pci_init_simple();
163 }
164 MIPS_MACHINE(ATH79_MACH_Z1, "Z1", "Meraki Z1", z1_setup);