Rebased from upstream / out of band repository.
[librecmc/librecmc.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-r36a.c
1 /*
2  * ALFA Network R36A 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 R36A_GPIO_LED_LAN       4
27 #define R36A_GPIO_LED_STATUS    14
28 #define R36A_GPIO_LED_USB       12
29 #define R36A_GPIO_LED_WAN       16
30 #define R36A_GPIO_LED_WLAN      15
31
32 #define R36A_GPIO_WDT_EN        1
33 #define R36A_GPIO_WDT_IN        0
34 #define R36A_GPIO_USB_PWR       3
35
36 #define R36A_GPIO_BTN_RESET     2
37 #define R36A_GPIO_BTN_RFKILL    17
38
39 #define R36A_KEYS_POLL_INTERVAL         20
40 #define R36A_KEYS_DEBOUNCE_INTERVAL     (3 * R36A_KEYS_POLL_INTERVAL)
41
42 #define R36A_WMAC_CALDATA_OFFSET        0x1000
43
44 static struct gpio_led r36a_leds_gpio[] __initdata = {
45         {
46                 .name           = "r36a:blue:lan",
47                 .gpio           = R36A_GPIO_LED_LAN,
48                 .active_low     = 1,
49         }, {
50                 .name           = "r36a:blue:status",
51                 .gpio           = R36A_GPIO_LED_STATUS,
52                 .active_low     = 1,
53         }, {
54                 .name           = "r36a:blue:usb",
55                 .gpio           = R36A_GPIO_LED_USB,
56                 .active_low     = 1,
57         }, {
58                 .name           = "r36a:blue:wan",
59                 .gpio           = R36A_GPIO_LED_WAN,
60                 .active_low     = 1,
61         }, {
62                 .name           = "r36a:blue:wlan",
63                 .gpio           = R36A_GPIO_LED_WLAN,
64                 .active_low     = 1,
65         },
66 };
67
68 static struct gpio_keys_button r36a_gpio_keys[] __initdata = {
69         {
70                 .desc                   = "reset",
71                 .type                   = EV_KEY,
72                 .code                   = KEY_RESTART,
73                 .debounce_interval      = R36A_KEYS_DEBOUNCE_INTERVAL,
74                 .gpio                   = R36A_GPIO_BTN_RESET,
75                 .active_low             = 1,
76         }, {
77                 .desc                   = "rfkill",
78                 .type                   = EV_KEY,
79                 .code                   = KEY_RFKILL,
80                 .debounce_interval      = R36A_KEYS_DEBOUNCE_INTERVAL,
81                 .gpio                   = R36A_GPIO_BTN_RFKILL,
82                 .active_low             = 1,
83         },
84 };
85
86 static void __init r36a_setup(void)
87 {
88         u8 *art = (u8 *) KSEG1ADDR(0x1f070000);
89
90         ath79_register_m25p80(NULL);
91
92         ath79_setup_ar933x_phy4_switch(false, false);
93
94         ath79_register_mdio(0, 0x0);
95
96         ath79_switch_data.phy4_mii_en = 1;
97         ath79_switch_data.phy_poll_mask = 0xf7;
98
99         /* LAN */
100         ath79_eth0_data.duplex = DUPLEX_FULL;
101         ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
102         ath79_eth0_data.phy_mask = BIT(4);
103         ath79_eth0_data.speed = SPEED_100;
104         ath79_init_mac(ath79_eth0_data.mac_addr, art, 0);
105         ath79_register_eth(0);
106
107         /* WAN */
108         ath79_eth1_data.duplex = DUPLEX_FULL;
109         ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
110         ath79_init_mac(ath79_eth1_data.mac_addr, art, 1);
111         ath79_register_eth(1);
112
113         /* Disable JTAG (enables GPIO0-3) */
114         ath79_gpio_function_enable(AR934X_GPIO_FUNC_JTAG_DISABLE);
115
116         ath79_register_leds_gpio(-1, ARRAY_SIZE(r36a_leds_gpio),
117                                  r36a_leds_gpio);
118
119         ath79_register_gpio_keys_polled(-1, R36A_KEYS_POLL_INTERVAL,
120                                         ARRAY_SIZE(r36a_gpio_keys),
121                                         r36a_gpio_keys);
122
123         gpio_request_one(R36A_GPIO_WDT_IN,
124                          GPIOF_OUT_INIT_LOW | GPIOF_EXPORT_DIR_FIXED,
125                          "WDT input");
126
127         gpio_request_one(R36A_GPIO_WDT_EN,
128                          GPIOF_OUT_INIT_LOW | GPIOF_EXPORT_DIR_FIXED,
129                          "WDT enable");
130
131         gpio_request_one(R36A_GPIO_USB_PWR,
132                          GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
133                          "USB power");
134
135         ath79_register_wmac(art + R36A_WMAC_CALDATA_OFFSET, NULL);
136
137         ath79_register_usb();
138 }
139
140 MIPS_MACHINE(ATH79_MACH_R36A, "R36A", "ALFA Network R36A", r36a_setup);