wireguard-tools: add tunlink option for hostroute
[openwrt/openwrt.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-jwap230.c
1 /*
2 * jjPlus JWAP230 board support
3 *
4 * Copyright (C) 2016 Piotr Dymacz <pepe2k@gmail.com>
5 *
6 * Based on mach-wpj558.c and mach-tl-wr1043nd-v2.c
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 2 as published
10 * by the Free Software Foundation.
11 */
12
13 #include <linux/pci.h>
14 #include <linux/phy.h>
15 #include <linux/gpio.h>
16 #include <linux/platform_device.h>
17 #include <linux/ar8216_platform.h>
18
19 #include <asm/mach-ath79/ath79.h>
20 #include <asm/mach-ath79/ar71xx_regs.h>
21
22 #include "common.h"
23 #include "dev-ap9x-pci.h"
24 #include "dev-eth.h"
25 #include "dev-leds-gpio.h"
26 #include "dev-m25p80.h"
27 #include "dev-usb.h"
28 #include "dev-wmac.h"
29 #include "machtypes.h"
30 #include "pci.h"
31
32 #define JWAP230_GPIO_LED_LED1 23
33 #define JWAP230_GPIO_LED_LED2 22
34 #define JWAP230_GPIO_LED_LED3 21
35
36 #define JWAP230_MAC0_OFFSET 0x0
37 #define JWAP230_MAC1_OFFSET 0x6
38 #define JWAP230_WMAC_CALDATA_OFFSET 0x1000
39
40 static struct gpio_led jwap230_leds_gpio[] __initdata = {
41 {
42 .name = "jwap230:green:led1",
43 .gpio = JWAP230_GPIO_LED_LED1,
44 .active_low = 1,
45 },
46 {
47 .name = "jwap230:green:led2",
48 .gpio = JWAP230_GPIO_LED_LED2,
49 .active_low = 1,
50 },
51 {
52 .name = "jwap230:green:led3",
53 .gpio = JWAP230_GPIO_LED_LED3,
54 .active_low = 1,
55 }
56 };
57
58 static const struct ar8327_led_info jwap230_leds_qca8337[] = {
59 AR8327_LED_INFO(PHY0_0, HW, "jwap230:green:lan"),
60 AR8327_LED_INFO(PHY4_0, HW, "jwap230:green:wan"),
61 };
62
63 /* Blink rate: 1 Gbps -> 8 hz, 100 Mbs -> 4 Hz, 10 Mbps -> 2 Hz */
64 static struct ar8327_led_cfg jwap230_qca8337_led_cfg = {
65 .led_ctrl0 = 0xcf37cf37,
66 .led_ctrl1 = 0xcf37cf37,
67 .led_ctrl2 = 0xcf37cf37,
68 .led_ctrl3 = 0x0,
69 .open_drain = true,
70 };
71
72 /* QCA8337 GMAC0 is connected with QCA9558 over RGMII */
73 static struct ar8327_pad_cfg jwap230_qca8337_pad0_cfg = {
74 .mode = AR8327_PAD_MAC_RGMII,
75 .txclk_delay_en = true,
76 .rxclk_delay_en = true,
77 .txclk_delay_sel = AR8327_CLK_DELAY_SEL1,
78 .rxclk_delay_sel = AR8327_CLK_DELAY_SEL2,
79 .mac06_exchange_dis = true,
80 };
81
82 /* QCA8337 GMAC6 is connected with QCA9558 over SGMII */
83 static struct ar8327_pad_cfg jwap230_qca8337_pad6_cfg = {
84 .mode = AR8327_PAD_MAC_SGMII,
85 .sgmii_delay_en = true,
86 .rxclk_delay_sel = AR8327_CLK_DELAY_SEL0,
87 };
88
89 static struct ar8327_platform_data jwap230_qca8337_data = {
90 .pad0_cfg = &jwap230_qca8337_pad0_cfg,
91 .pad6_cfg = &jwap230_qca8337_pad6_cfg,
92 .port0_cfg = {
93 .force_link = 1,
94 .speed = AR8327_PORT_SPEED_1000,
95 .duplex = 1,
96 .txpause = 1,
97 .rxpause = 1,
98 },
99 .port6_cfg = {
100 .force_link = 1,
101 .speed = AR8327_PORT_SPEED_1000,
102 .duplex = 1,
103 .txpause = 1,
104 .rxpause = 1,
105 },
106 .led_cfg = &jwap230_qca8337_led_cfg,
107 .num_leds = ARRAY_SIZE(jwap230_leds_qca8337),
108 .leds = jwap230_leds_qca8337,
109 };
110
111 static struct mdio_board_info jwap230_mdio0_info[] = {
112 {
113 .bus_id = "ag71xx-mdio.0",
114 .mdio_addr = 0,
115 .platform_data = &jwap230_qca8337_data,
116 },
117 };
118
119 static void __init jwap230_setup(void)
120 {
121 u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
122
123 ath79_register_m25p80(NULL);
124
125 ath79_register_leds_gpio(-1, ARRAY_SIZE(jwap230_leds_gpio),
126 jwap230_leds_gpio);
127
128 mdiobus_register_board_info(jwap230_mdio0_info,
129 ARRAY_SIZE(jwap230_mdio0_info));
130 ath79_register_mdio(0, 0x0);
131
132 ath79_setup_qca955x_eth_cfg(QCA955X_ETH_CFG_RGMII_EN);
133
134 /* QCA9558 GMAC0 is connected to RMGII interface */
135 ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
136 ath79_eth0_data.phy_mask = BIT(0);
137 ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev;
138 ath79_eth0_pll_data.pll_1000 = 0xa6000000;
139
140 ath79_init_mac(ath79_eth0_data.mac_addr, art + JWAP230_MAC0_OFFSET, 0);
141 ath79_register_eth(0);
142
143 /* QCA9558 GMAC1 is connected to SGMII interface */
144 ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_SGMII;
145 ath79_eth1_data.speed = SPEED_1000;
146 ath79_eth1_data.duplex = DUPLEX_FULL;
147 ath79_eth1_pll_data.pll_1000 = 0x03000101;
148
149 ath79_init_mac(ath79_eth1_data.mac_addr, art + JWAP230_MAC1_OFFSET, 0);
150 ath79_register_eth(1);
151
152 ath79_register_wmac(art + JWAP230_WMAC_CALDATA_OFFSET, NULL);
153
154 ath79_register_pci();
155 ath79_register_usb();
156 }
157
158 MIPS_MACHINE(ATH79_MACH_JWAP230, "JWAP230", "jjPlus JWAP230", jwap230_setup);