ar71xx: mach-rbspi: simplify reset button registration
[oweals/openwrt.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-n5q.c
1 /*
2  * ALFA Network N5Q 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-wmac.h"
23 #include "machtypes.h"
24
25 #define N5Q_GPIO_LED_LAN        19
26 #define N5Q_GPIO_LED_SIGNAL1    0
27 #define N5Q_GPIO_LED_SIGNAL2    1
28 #define N5Q_GPIO_LED_SIGNAL3    2
29 #define N5Q_GPIO_LED_SIGNAL4    3
30 #define N5Q_GPIO_LED_WAN        18
31 #define N5Q_GPIO_LED_WLAN       12
32
33 #define N5Q_GPIO_WDT_EN         16
34 #define N5Q_GPIO_WDT_IN         17
35
36 #define N5Q_GPIO_BTN_RESET      11
37
38 #define N5Q_MAC0_OFFSET         0
39 #define N5Q_MAC1_OFFSET         6
40 #define N5Q_WMAC_CALDATA_OFFSET 0x1000
41
42 #define N5Q_KEYS_POLL_INTERVAL          20
43 #define N5Q_KEYS_DEBOUNCE_INTERVAL      (3 * N5Q_KEYS_POLL_INTERVAL)
44
45 static struct gpio_led n5q_leds_gpio[] __initdata = {
46         {
47                 .name           = "n5q:green:lan",
48                 .gpio           = N5Q_GPIO_LED_LAN,
49                 .active_low     = 1,
50         }, {
51                 .name           = "n5q:red:signal1",
52                 .gpio           = N5Q_GPIO_LED_SIGNAL1,
53                 .active_low     = 1,
54         }, {
55                 .name           = "n5q:orange:signal2",
56                 .gpio           = N5Q_GPIO_LED_SIGNAL2,
57                 .active_low     = 1,
58         }, {
59                 .name           = "n5q:green:signal3",
60                 .gpio           = N5Q_GPIO_LED_SIGNAL3,
61                 .active_low     = 1,
62         }, {
63                 .name           = "n5q:green:signal4",
64                 .gpio           = N5Q_GPIO_LED_SIGNAL4,
65                 .active_low     = 1,
66         }, {
67                 .name           = "n5q:green:wan",
68                 .gpio           = N5Q_GPIO_LED_WAN,
69                 .active_low     = 1,
70         }, {
71                 .name           = "n5q:green:wlan",
72                 .gpio           = N5Q_GPIO_LED_WLAN,
73                 .active_low     = 1,
74         },
75 };
76
77 static struct gpio_keys_button n5q_gpio_keys[] __initdata = {
78         {
79                 .desc                   = "reset",
80                 .type                   = EV_KEY,
81                 .code                   = KEY_RESTART,
82                 .debounce_interval      = N5Q_KEYS_DEBOUNCE_INTERVAL,
83                 .gpio                   = N5Q_GPIO_BTN_RESET,
84                 .active_low             = 1,
85         },
86 };
87
88 static void __init n5q_setup(void)
89 {
90         u8 *art = (u8 *) KSEG1ADDR(0x1f070000);
91
92         ath79_register_m25p80(NULL);
93
94         ath79_register_mdio(1, 0x0);
95
96         ath79_switch_data.phy4_mii_en = 1;
97         ath79_switch_data.phy_poll_mask = 0xf7;
98
99         /* LAN */
100         ath79_eth1_data.duplex = DUPLEX_FULL;
101         ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
102         ath79_init_mac(ath79_eth1_data.mac_addr, art + N5Q_MAC1_OFFSET, 0);
103         ath79_register_eth(1);
104
105         /* WAN */
106         ath79_eth0_data.duplex = DUPLEX_FULL;
107         ath79_eth0_data.mii_bus_dev = &ath79_mdio1_device.dev;
108         ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
109         ath79_eth0_data.phy_mask = BIT(4);
110         ath79_eth0_data.speed = SPEED_100;
111         ath79_init_mac(ath79_eth0_data.mac_addr, art + N5Q_MAC0_OFFSET, 0);
112         ath79_register_eth(0);
113
114         ath79_register_leds_gpio(-1, ARRAY_SIZE(n5q_leds_gpio),
115                                  n5q_leds_gpio);
116
117         ath79_register_gpio_keys_polled(-1, N5Q_KEYS_POLL_INTERVAL,
118                                         ARRAY_SIZE(n5q_gpio_keys),
119                                         n5q_gpio_keys);
120
121         gpio_request_one(N5Q_GPIO_WDT_IN,
122                          GPIOF_OUT_INIT_LOW | GPIOF_EXPORT_DIR_FIXED,
123                          "WDT input");
124
125         gpio_request_one(N5Q_GPIO_WDT_EN,
126                          GPIOF_OUT_INIT_LOW | GPIOF_EXPORT_DIR_FIXED,
127                          "WDT enable");
128
129         ath79_register_wmac(art + N5Q_WMAC_CALDATA_OFFSET, NULL);
130 }
131
132 MIPS_MACHINE(ATH79_MACH_N5Q, "N5Q", "ALFA Network N5Q", n5q_setup);