ramips: use gpio-keys-polled instead of gpio-buttons
[librecmc/librecmc.git] / target / linux / ramips / files / arch / mips / ralink / rt305x / mach-wl341v3.c
1 /*
2  *  Sitecom WL341v3 board support
3  *
4  *  Copyright (C) 2012 Marco Antonio Mauro <marcus90@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 #include <linux/mtd/mtd.h>
14 #include <linux/mtd/partitions.h>
15 #include <linux/mtd/physmap.h>
16
17 #include <asm/mach-ralink/machine.h>
18 #include <asm/mach-ralink/dev-gpio-buttons.h>
19 #include <asm/mach-ralink/dev-gpio-leds.h>
20 #include <asm/mach-ralink/rt305x.h>
21 #include <asm/mach-ralink/rt305x_regs.h>
22
23 #include "devices.h"
24
25 #define WL341V3_GPIO_LED_FIRST_AMBER    9
26 #define WL341V3_GPIO_LED_FIRST_BLUE     13
27 #define WL341V3_GPIO_LED_THIRD_AMBER    11
28 #define WL341V3_GPIO_LED_THIRD_BLUE     14
29 #define WL341V3_GPIO_LED_FOURTH_BLUE    10
30 #define WL341V3_GPIO_LED_FIFTH_AMBER    12
31 #define WL341V3_GPIO_LED_FIFTH_BLUE     8
32
33 #define WL341V3_GPIO_BUTTON_WPS         5       /* active low */
34 #define WL341V3_GPIO_BUTTON_RESET       7       /* active low */
35
36 #define WL341V3_KEYS_POLL_INTERVAL      20
37 #define WL341V3_KEYS_DEBOUNCE_INTERVAL  (3 * WL341V3_KEYS_POLL_INTERVAL)
38
39 static struct mtd_partition wl341v3_partitions[] = {
40         {
41                 .name   = "u-boot",
42                 .offset = 0,
43                 .size   = 0x020000,
44                 .mask_flags = MTD_WRITEABLE,
45         }, {
46                 .name   = "board-nvram",
47                 .offset = 0x020000,
48                 .size   = 0x010000,
49                 .mask_flags = MTD_WRITEABLE,
50         }, {
51                 .name   = "u-boot-env",
52                 .offset = 0x030000,
53                 .size   = 0x010000,
54                 .mask_flags = MTD_WRITEABLE,
55         }, {
56                 .name   = "kernel",
57                 .offset = 0x040000,
58                 .size   = 0x0d0000,
59         }, {
60                 .name   = "rootfs",
61                 .offset = 0x110000,
62                 .size   = 0x2e0000,
63         }, {
64                 .name   = "signature-eRcOmM",
65                 .offset = 0x3f0000,
66                 .size   = 0x010000,
67         }, {
68                 .name   = "firmware",
69                 .offset = 0x040000,
70                 .size   = 0x3b0000,
71         }, {
72                 .name   = "fullflash",
73                 .offset = 0x000000,
74                 .size   = 0x400000,
75         }
76 };
77
78 static struct physmap_flash_data wl341v3_flash_data = {
79         .nr_parts       = ARRAY_SIZE(wl341v3_partitions),
80         .parts          = wl341v3_partitions,
81 };
82
83 static struct gpio_led wl341v3_leds_gpio[] __initdata = {
84         {
85                 .name           = "wl341v3:amber:first",
86                 .gpio           = WL341V3_GPIO_LED_FIRST_AMBER,
87                 .active_low     = 1,
88         }, {
89                 .name           = "wl341v3:blue:first",
90                 .gpio           = WL341V3_GPIO_LED_FIRST_BLUE,
91                 .active_low     = 1,
92         }, {
93                 .name           = "wl341v3:amber:third",
94                 .gpio           = WL341V3_GPIO_LED_THIRD_AMBER,
95                 .active_low     = 1,
96         }, {
97                 .name           = "wl341v3:blue:third",
98                 .gpio           = WL341V3_GPIO_LED_THIRD_BLUE,
99                 .active_low     = 1,
100         }, {
101                 .name           = "wl341v3:blue:fourth",
102                 .gpio           = WL341V3_GPIO_LED_FOURTH_BLUE,
103                 .active_low     = 1,
104         }, {
105                 .name           = "wl341v3:amber:fifth",
106                 .gpio           = WL341V3_GPIO_LED_FIFTH_AMBER,
107                 .active_low     = 1,
108         }, {
109                 .name           = "wl341v3:blue:fifth",
110                 .gpio           = WL341V3_GPIO_LED_FIFTH_BLUE,
111                 .active_low     = 1,
112         }
113 };
114
115 static struct gpio_keys_button wl341v3_gpio_buttons[] __initdata = {
116         {
117                 .desc           = "reset",
118                 .type           = EV_KEY,
119                 .code           = KEY_RESTART,
120                 .debounce_interval = WL341V3_KEYS_DEBOUNCE_INTERVAL,
121                 .gpio           = WL341V3_GPIO_BUTTON_RESET,
122                 .active_low     = 1,
123         }, {
124                 .desc           = "wps",
125                 .type           = EV_KEY,
126                 .code           = KEY_WPS_BUTTON,
127                 .debounce_interval = WL341V3_KEYS_DEBOUNCE_INTERVAL,
128                 .gpio           = WL341V3_GPIO_BUTTON_WPS,
129                 .active_low     = 1,
130         }
131 };
132
133 static void __init wl341v3_init(void)
134 {
135         rt305x_gpio_init(RT305X_GPIO_MODE_GPIO << RT305X_GPIO_MODE_UART0_SHIFT);
136
137         rt305x_register_flash(0, &wl341v3_flash_data);
138         rt305x_esw_data.vlan_config = RT305X_ESW_VLAN_CONFIG_WLLLL;
139         rt305x_register_ethernet();
140         ramips_register_gpio_leds(-1, ARRAY_SIZE(wl341v3_leds_gpio),
141                                   wl341v3_leds_gpio);
142         ramips_register_gpio_buttons(-1, WL341V3_KEYS_POLL_INTERVAL,
143                                      ARRAY_SIZE(wl341v3_gpio_buttons),
144                                      wl341v3_gpio_buttons);
145         rt305x_register_wifi();
146         rt305x_register_wdt();
147         rt305x_register_usb();
148 }
149
150 MIPS_MACHINE(RAMIPS_MACH_WL341V3, "WL341V3", "Sitecom WL-341 v3",
151              wl341v3_init);