add feature gpio
[openwrt/openwrt.git] / target / linux / ramips / files / arch / mips / ralink / rt305x / mach-mzk-w300nh2.c
1 /*
2 * Planex MZK-W300NH2 board support
3 *
4 * Copyright (C) 2012 Samir Ibradžić <sibradzic@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/init.h>
12 #include <linux/platform_device.h>
13
14 #include <asm/mach-ralink/machine.h>
15 #include <asm/mach-ralink/dev-gpio-buttons.h>
16 #include <asm/mach-ralink/dev-gpio-leds.h>
17 #include <asm/mach-ralink/rt305x.h>
18 #include <asm/mach-ralink/rt305x_regs.h>
19
20 #include "devices.h"
21
22 #define MZKW300NH2_GPIO_BUTTON_RESET 0 /* active low */
23 #define MZKW300NH2_GPIO_BUTTON_WPS 12 /* active low */
24 #define MZKW300NH2_GPIO_SWITCH_MODE_RT 13 /* active low */
25
26 #define MZKW300NH2_GPIO_LED_POWER 9
27 #define MZKW300NH2_GPIO_LED_WLAN 14
28 #define MZKW300NH2_GPIO_LED_WPS 11
29
30 #define MZKW300NH2_KEYS_POLL_INTERVAL 20
31 #define MZKW300NH2_KEYS_DEBOUNCE_INTERVAL (3 * MZKW300NH2_KEYS_POLL_INTERVAL)
32
33 static struct gpio_led mzkw300nh2_leds_gpio[] __initdata = {
34 {
35 .name = "mzkw300nh2:green:power",
36 .gpio = MZKW300NH2_GPIO_LED_POWER,
37 .active_low = 1,
38 }, {
39 .name = "mzkw300nh2:amber:wlan",
40 .gpio = MZKW300NH2_GPIO_LED_WLAN,
41 .active_low = 1,
42 }, {
43 .name = "mzkw300nh2:amber:wps",
44 .gpio = MZKW300NH2_GPIO_LED_WPS,
45 .active_low = 1,
46 }
47 };
48
49 static struct gpio_keys_button mzkw300nh2_gpio_buttons[] __initdata = {
50 {
51 .desc = "wps",
52 .type = EV_KEY,
53 .code = KEY_WPS_BUTTON,
54 .debounce_interval = MZKW300NH2_KEYS_DEBOUNCE_INTERVAL,
55 .gpio = MZKW300NH2_GPIO_BUTTON_WPS,
56 .active_low = 1,
57 }, {
58 .desc = "reset",
59 .type = EV_KEY,
60 .code = KEY_RESTART,
61 .debounce_interval = MZKW300NH2_KEYS_DEBOUNCE_INTERVAL,
62 .gpio = MZKW300NH2_GPIO_BUTTON_RESET,
63 .active_low = 1,
64 }, {
65 .desc = "rt",
66 .type = EV_KEY,
67 .code = BTN_0,
68 .debounce_interval = MZKW300NH2_KEYS_DEBOUNCE_INTERVAL,
69 .gpio = MZKW300NH2_GPIO_SWITCH_MODE_RT,
70 .active_low = 1,
71 }
72 };
73
74 static void __init mzkw300nh2_init(void)
75 {
76 rt305x_gpio_init(RT305X_GPIO_MODE_UART0(RT305X_GPIO_MODE_GPIO) |
77 RT305X_GPIO_MODE_I2C |
78 RT305X_GPIO_MODE_SPI |
79 RT305X_GPIO_MODE_JTAG);
80
81 rt305x_register_flash(0);
82 rt305x_esw_data.vlan_config = RT305X_ESW_VLAN_CONFIG_LLLLW;
83 rt305x_register_ethernet();
84 ramips_register_gpio_leds(-1, ARRAY_SIZE(mzkw300nh2_leds_gpio),
85 mzkw300nh2_leds_gpio);
86 ramips_register_gpio_buttons(-1, MZKW300NH2_KEYS_POLL_INTERVAL,
87 ARRAY_SIZE(mzkw300nh2_gpio_buttons),
88 mzkw300nh2_gpio_buttons);
89 rt305x_register_wifi();
90 rt305x_register_wdt();
91 }
92
93 MIPS_MACHINE(RAMIPS_MACH_MZKW300NH2, "MZK-W300NH2", "Planex MZK-W300NH2",
94 mzkw300nh2_init);