ar71xx: Add support for the OMYlink OMY-X1
[openwrt/openwrt.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-dlan-hotspot.c
1 /*
2 * devolo dLAN Hotspot board support
3 *
4 * Copyright (C) 2015 Torsten Schnuis <torsten.schnuis@gik.de>
5 * Copyright (C) 2015 devolo AG
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published
9 * by the Free Software Foundation.
10 */
11
12 #include <linux/gpio.h>
13
14 #include <asm/mach-ath79/ath79.h>
15
16 #include "dev-eth.h"
17 #include "dev-gpio-buttons.h"
18 #include "dev-leds-gpio.h"
19 #include "dev-m25p80.h"
20 #include "dev-usb.h"
21 #include "dev-wmac.h"
22 #include "machtypes.h"
23
24 #define DLAN_HOTSPOT_GPIO_LED_WIFI 0
25
26 #define DLAN_HOTSPOT_GPIO_BTN_RESET 11
27 #define DLAN_HOTSPOT_GPIO_BTN_PLC_PAIRING 12
28 #define DLAN_HOTSPOT_GPIO_BTN_WIFI 21
29
30 #define DLAN_HOTSPOT_GPIO_PLC_POWER 22
31 #define DLAN_HOTSPOT_GPIO_PLC_RESET 20
32 #define DLAN_HOTSPOT_GPIO_PLC_DISABLE_LEDS 18
33
34 #define DLAN_HOTSPOT_KEYS_POLL_INTERVAL 20 /* msecs */
35 #define DLAN_HOTSPOT_KEYS_DEBOUNCE_INTERVAL (3 * DLAN_HOTSPOT_KEYS_POLL_INTERVAL)
36
37 #define DLAN_HOTSPOT_ART_ADDRESS 0x1fff0000
38 #define DLAN_HOTSPOT_CALDATA_OFFSET 0x00001000
39 #define DLAN_HOTSPOT_MAC_ADDRESS_OFFSET 0x00001002
40
41 static struct gpio_led dlan_hotspot_leds_gpio[] __initdata = {
42 {
43 .name = "devolo:green:wifi",
44 .gpio = DLAN_HOTSPOT_GPIO_LED_WIFI,
45 .active_low = 0,
46 }
47 };
48
49 static struct gpio_keys_button dlan_hotspot_gpio_keys[] __initdata = {
50 {
51 .desc = "Reset button",
52 .type = EV_KEY,
53 .code = KEY_RESTART,
54 .debounce_interval = DLAN_HOTSPOT_KEYS_DEBOUNCE_INTERVAL,
55 .gpio = DLAN_HOTSPOT_GPIO_BTN_RESET,
56 .active_low = 0,
57 },
58 {
59 .desc = "Pairing button",
60 .type = EV_KEY,
61 .code = BTN_0,
62 .debounce_interval = DLAN_HOTSPOT_KEYS_DEBOUNCE_INTERVAL,
63 .gpio = DLAN_HOTSPOT_GPIO_BTN_PLC_PAIRING,
64 .active_low = 0,
65 },
66 {
67 .desc = "WLAN button",
68 .type = EV_KEY,
69 .code = KEY_WPS_BUTTON,
70 .debounce_interval = DLAN_HOTSPOT_KEYS_DEBOUNCE_INTERVAL,
71 .gpio = DLAN_HOTSPOT_GPIO_BTN_WIFI,
72 .active_low = 0,
73 }
74 };
75
76 static void __init dlan_hotspot_setup(void)
77 {
78 u8 *art = (u8 *) KSEG1ADDR(DLAN_HOTSPOT_ART_ADDRESS);
79 u8 *cal = art + DLAN_HOTSPOT_CALDATA_OFFSET;
80 u8 *wifi_mac = art + DLAN_HOTSPOT_MAC_ADDRESS_OFFSET;
81
82 /* disable PHY_SWAP and PHY_ADDR_SWAP bits */
83 ath79_setup_ar933x_phy4_switch(false, false);
84
85 ath79_register_leds_gpio(-1, ARRAY_SIZE(dlan_hotspot_leds_gpio),
86 dlan_hotspot_leds_gpio);
87
88 ath79_register_gpio_keys_polled(-1, DLAN_HOTSPOT_KEYS_POLL_INTERVAL,
89 ARRAY_SIZE(dlan_hotspot_gpio_keys),
90 dlan_hotspot_gpio_keys);
91
92 gpio_request_one(DLAN_HOTSPOT_GPIO_PLC_POWER,
93 GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
94 "PLC power");
95 gpio_request_one(DLAN_HOTSPOT_GPIO_PLC_RESET,
96 GPIOF_OUT_INIT_LOW | GPIOF_EXPORT_DIR_FIXED,
97 "PLC reset");
98 gpio_request_one(DLAN_HOTSPOT_GPIO_PLC_DISABLE_LEDS,
99 GPIOF_OUT_INIT_LOW | GPIOF_EXPORT_DIR_FIXED,
100 "PLC LEDs");
101
102 ath79_register_usb();
103
104 ath79_register_m25p80(NULL);
105
106 ath79_init_mac(ath79_eth0_data.mac_addr, wifi_mac, 1);
107 ath79_init_mac(ath79_eth1_data.mac_addr, wifi_mac, 2);
108
109 ath79_register_mdio(0, 0x0);
110 ath79_register_eth(0);
111 ath79_register_eth(1);
112
113 ath79_register_wmac(cal, wifi_mac);
114 }
115
116 MIPS_MACHINE(ATH79_MACH_DLAN_HOTSPOT, "dLAN-Hotspot",
117 "dLAN Hotspot", dlan_hotspot_setup);