Rebased from upstream / out of band repository.
[librecmc/librecmc.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-pqi-air-pen.c
1 /*
2  *  PQI Air Pen stick support
3  *
4  *  Copyright (C) 2016 YuheiOKAWA <tochiro.srchack@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
13 #include <asm/mach-ath79/ath79.h>
14
15 #include "common.h"
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 PQI_AIR_PEN_GPIO_LED_WLAN               0
25 #define PQI_AIR_PEN_GPIO_LED_WPS                23
26
27 #define PQI_AIR_PEN_GPIO_BTN_WPS                22
28 #define PQI_AIR_PEN_GPIO_BTN_RESET              12
29
30 #define PQI_AIR_PEN_KEYS_POLL_INTERVAL          20 /* msecs */
31 #define PQI_AIR_PEN_KEYS_DEBOUNCE_INTERVAL      (3 * PQI_AIR_PEN_KEYS_POLL_INTERVAL)
32
33 #define PQI_AIR_PEN_WMAC_CALDATA_OFFSET         0x1000
34 #define PQI_AIR_PEN_LAN_MAC_OFFSET              0x1002
35 #define PQI_AIR_PEN_WMAC_MAC_OFFSET             0x1002
36
37 static struct gpio_led pqi_air_pen_leds_gpio[] __initdata = {
38         {
39                 .name = "pqi-air-pen:blue:wlan",
40                 .gpio = PQI_AIR_PEN_GPIO_LED_WLAN,
41                 .active_low = 0,
42         },
43         {
44                 .name = "pqi-air-pen:blue:wps",
45                 .gpio = PQI_AIR_PEN_GPIO_LED_WPS,
46                 .active_low = 0,
47         },
48 };
49
50 static struct gpio_keys_button pqi_air_pen_gpio_keys[] __initdata = {
51         {
52                 .desc = "wps",
53                 .type = EV_KEY,
54                 .code = KEY_WPS_BUTTON,
55                 .debounce_interval = PQI_AIR_PEN_KEYS_DEBOUNCE_INTERVAL,
56                 .gpio = PQI_AIR_PEN_GPIO_BTN_WPS,
57                 .active_low = 0,
58         },
59         {
60                 .desc = "reset",
61                 .type = EV_KEY,
62                 .code = KEY_RESTART,
63                 .debounce_interval = PQI_AIR_PEN_KEYS_DEBOUNCE_INTERVAL,
64                 .gpio = PQI_AIR_PEN_GPIO_BTN_RESET,
65                 .active_low = 0,
66         },
67 };
68
69 static void __init pqi_air_pen_setup(void)
70 {
71         /* ART base address */
72         u8 *art = (u8 *) KSEG1ADDR(0x9f050000);
73
74         /* register flash. */
75         ath79_register_m25p80(NULL);
76
77         /* register wireless mac with cal data */
78         ath79_register_wmac(art + PQI_AIR_PEN_WMAC_CALDATA_OFFSET, art + PQI_AIR_PEN_WMAC_MAC_OFFSET);
79
80         /* false PHY_SWAP and PHY_ADDR_SWAP bits */
81         ath79_setup_ar933x_phy4_switch(false, false);
82
83         /* register gpio LEDs and keys */
84         ath79_register_leds_gpio(-1, ARRAY_SIZE(pqi_air_pen_leds_gpio),
85                                  pqi_air_pen_leds_gpio);
86         ath79_register_gpio_keys_polled(-1, PQI_AIR_PEN_KEYS_POLL_INTERVAL,
87                                         ARRAY_SIZE(pqi_air_pen_gpio_keys),
88                                         pqi_air_pen_gpio_keys);
89
90         /* enable usb */
91         ath79_register_usb();
92         
93         /* register eth0 as LAN */
94         ath79_init_mac(ath79_eth0_data.mac_addr, art + PQI_AIR_PEN_LAN_MAC_OFFSET, 0);
95         ath79_register_mdio(0, 0x0);
96         ath79_register_eth(0);
97 }
98
99 MIPS_MACHINE(ATH79_MACH_PQI_AIR_PEN, "PQI-AIR-PEN", "PQI Air Pen",pqi_air_pen_setup);