Rebased from upstream / out of band repository.
[librecmc/librecmc.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-wam250.c
1 /*
2  * Samsung WAM250 board support
3  *
4  * Copyright (C) 2018 Piotr Dymacz <pepe2k@gmail.com>
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/gpio.h>
12 #include <linux/platform_device.h>
13
14 #include <asm/mach-ath79/ath79.h>
15 #include <asm/mach-ath79/ar71xx_regs.h>
16
17 #include "common.h"
18 #include "dev-eth.h"
19 #include "dev-gpio-buttons.h"
20 #include "dev-leds-gpio.h"
21 #include "dev-m25p80.h"
22 #include "dev-usb.h"
23 #include "dev-wmac.h"
24 #include "machtypes.h"
25
26 #define WAM250_GPIO_LED_LAN             13
27 #define WAM250_GPIO_LED_POWER           15
28 #define WAM250_GPIO_LED_REPEATER        14
29 #define WAM250_GPIO_LED_WLAN            12
30
31 #define WAM250_GPIO_BTN_RESET           17
32 #define WAM250_GPIO_BTN_SPKADD          1
33
34 #define WAM250_GPIO_EXT_LNA             19
35
36 #define WAM250_MAC_OFFSET               2
37
38 #define WAM250_KEYS_POLL_INTERVAL       20
39 #define WAM250_KEYS_DEBOUNCE_INTERVAL   (3 * WAM250_KEYS_POLL_INTERVAL)
40
41 static struct gpio_led wam250_leds_gpio[] __initdata = {
42         {
43                 .name           = "wam250:white:lan",
44                 .gpio           = WAM250_GPIO_LED_LAN,
45                 .active_low     = 1,
46         }, {
47                 .name           = "wam250:white:power",
48                 .gpio           = WAM250_GPIO_LED_POWER,
49                 .default_state  = LEDS_GPIO_DEFSTATE_KEEP,
50                 .active_low     = 1,
51         }, {
52                 .name           = "wam250:white:repeater",
53                 .gpio           = WAM250_GPIO_LED_REPEATER,
54                 .active_low     = 1,
55         }, {
56                 .name           = "wam250:white:wlan",
57                 .gpio           = WAM250_GPIO_LED_WLAN,
58                 .active_low     = 1,
59         },
60 };
61
62 static struct gpio_keys_button wam250_gpio_keys[] __initdata = {
63         {
64                 .desc                   = "reset",
65                 .type                   = EV_KEY,
66                 .code                   = KEY_RESTART,
67                 .debounce_interval      = WAM250_KEYS_DEBOUNCE_INTERVAL,
68                 .gpio                   = WAM250_GPIO_BTN_RESET,
69                 .active_low             = 1,
70         }, {
71                 .desc                   = "wps",
72                 .type                   = EV_KEY,
73                 .code                   = KEY_WPS_BUTTON,
74                 .debounce_interval      = WAM250_KEYS_DEBOUNCE_INTERVAL,
75                 .gpio                   = WAM250_GPIO_BTN_SPKADD,
76                 .active_low             = 1,
77         },
78 };
79
80 static void __init wam250_setup(void)
81 {
82         u8 *art = (u8 *) KSEG1ADDR(0x1fff1000);
83
84         ath79_register_m25p80(NULL);
85
86         ath79_register_mdio(1, 0x0);
87
88         ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_SW_PHY_SWAP);
89
90         ath79_switch_data.phy4_mii_en = 1;
91         ath79_switch_data.phy_poll_mask = 0xfd;
92
93         /* LAN */
94         ath79_eth1_data.duplex = DUPLEX_FULL;
95         ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
96         ath79_eth1_data.phy_mask = BIT(1);
97         ath79_init_mac(ath79_eth1_data.mac_addr, art + WAM250_MAC_OFFSET, 0);
98         ath79_register_eth(1);
99
100         /* WAN */
101         ath79_eth0_data.duplex = DUPLEX_FULL;
102         ath79_eth0_data.mii_bus_dev = &ath79_mdio1_device.dev;
103         ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
104         ath79_eth0_data.phy_mask = BIT(0);
105         ath79_eth0_data.speed = SPEED_100;
106         ath79_init_mac(ath79_eth0_data.mac_addr, art + WAM250_MAC_OFFSET, 1);
107         ath79_register_eth(0);
108
109         ath79_register_leds_gpio(-1, ARRAY_SIZE(wam250_leds_gpio),
110                                  wam250_leds_gpio);
111
112         ath79_register_gpio_keys_polled(-1, WAM250_KEYS_POLL_INTERVAL,
113                                         ARRAY_SIZE(wam250_gpio_keys),
114                                         wam250_gpio_keys);
115
116         ath79_wmac_set_ext_lna_gpio(0, WAM250_GPIO_EXT_LNA);
117
118         ath79_register_usb();
119         ath79_register_wmac(art, NULL);
120 }
121
122 MIPS_MACHINE(ATH79_MACH_WAM250, "WAM250", "Samsung WAM250", wam250_setup);