ramips: use gpio-keys-polled instead of gpio-buttons
[librecmc/librecmc.git] / target / linux / ramips / files / arch / mips / ralink / rt288x / mach-wli-tx4-ag300n.c
1 /*
2  *  Buffalo WLI-TX4-AG300N board support
3  *
4  *  Copyright (C) 2011 Gabor Juhos <juhosg@openwrt.org>
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/ethtool.h>
13 #include <linux/platform_device.h>
14 #include <linux/mtd/mtd.h>
15 #include <linux/mtd/partitions.h>
16 #include <linux/mtd/physmap.h>
17
18 #include <asm/mach-ralink/machine.h>
19 #include <asm/mach-ralink/dev-gpio-buttons.h>
20 #include <asm/mach-ralink/dev-gpio-leds.h>
21 #include <asm/mach-ralink/rt288x.h>
22 #include <asm/mach-ralink/rt288x_regs.h>
23 #include <asm/mach-ralink/ramips_eth_platform.h>
24
25 #include "devices.h"
26
27 #define WLI_TX4_AG300N_GPIO_LED_DIAG            10
28 #define WLI_TX4_AG300N_GPIO_LED_POWER           12
29 #define WLI_TX4_AG300N_GPIO_LED_SECURITY        13
30
31 #define WLI_TX4_AG300N_GPIO_BUTTON_AOSS         0
32 #define WLI_TX4_AG300N_GPIO_BUTTON_BW_SWITCH    8
33 #define WLI_TX4_AG300N_GPIO_BUTTON_RESET        9
34
35 #define WLI_TX4_AG300N_KEYS_POLL_INTERVAL       20
36 #define WLI_TX4_AG300N_KEYS_DEBOUNCE_INTERVAL   (3 * WLI_TX4_AG300N_KEYS_POLL_INTERVAL)
37
38 static struct mtd_partition wli_tx4_ag300n_partitions[] = {
39         {
40                 .name   = "u-boot",
41                 .offset = 0,
42                 .size   = 0x030000,
43                 .mask_flags = MTD_WRITEABLE,
44         },
45         {
46                 .name   = "u-boot-env",
47                 .offset = 0x030000,
48                 .size   = 0x010000,
49                 .mask_flags = MTD_WRITEABLE,
50         },
51         {
52                 .name   = "factory",
53                 .offset = 0x040000,
54                 .size   = 0x010000,
55                 .mask_flags = MTD_WRITEABLE,
56         },
57         {
58                 .name   = "kernel",
59                 .offset = 0x050000,
60                 .size   = 0x0d0000,
61         },
62         {
63                 .name   = "rootfs",
64                 .offset = 0x120000,
65                 .size   = 0x2d0000,
66         },
67         {
68                 .name   = "user",
69                 .offset = 0x3f0000,
70                 .size   = 0x010000,
71         },
72         {
73                 .name   = "firmware",
74                 .offset = 0x050000,
75                 .size   = 0x3a0000,
76         },
77 };
78
79 static struct physmap_flash_data wli_tx4_ag300n_flash_data = {
80         .nr_parts       = ARRAY_SIZE(wli_tx4_ag300n_partitions),
81         .parts          = wli_tx4_ag300n_partitions,
82 };
83
84 static struct gpio_led wli_tx4_ag300n_leds_gpio[] __initdata = {
85         {
86                 .name           = "buffalo:blue:power",
87                 .gpio           = WLI_TX4_AG300N_GPIO_LED_POWER,
88                 .active_low     = 1,
89         },
90         {
91                 .name           = "buffalo:red:diag",
92                 .gpio           = WLI_TX4_AG300N_GPIO_LED_DIAG,
93                 .active_low     = 1,
94         },
95         {
96                 .name           = "buffalo:blue:security",
97                 .gpio           = WLI_TX4_AG300N_GPIO_LED_SECURITY,
98                 .active_low     = 0,
99         },
100 };
101
102 static struct gpio_keys_button wli_tx4_ag300n_gpio_buttons[] __initdata = {
103         {
104                 .desc           = "Reset button",
105                 .type           = EV_KEY,
106                 .code           = KEY_RESTART,
107                 .debounce_interval = WLI_TX4_AG300N_KEYS_DEBOUNCE_INTERVAL,
108                 .gpio           = WLI_TX4_AG300N_GPIO_BUTTON_RESET,
109                 .active_low     = 1,
110         },
111         {
112                 .desc           = "AOSS button",
113                 .type           = EV_KEY,
114                 .code           = KEY_WPS_BUTTON,
115                 .debounce_interval = WLI_TX4_AG300N_KEYS_DEBOUNCE_INTERVAL,
116                 .gpio           = WLI_TX4_AG300N_GPIO_BUTTON_AOSS,
117                 .active_low     = 1,
118         },
119         {
120                 .desc           = "Bandwidth switch",
121                 .type           = EV_KEY,
122                 .code           = BTN_0,
123                 .debounce_interval = WLI_TX4_AG300N_KEYS_DEBOUNCE_INTERVAL,
124                 .gpio           = WLI_TX4_AG300N_GPIO_BUTTON_BW_SWITCH,
125                 .active_low     = 0,
126         },
127 };
128
129 static void __init wli_tx4_ag300n_init(void)
130 {
131         rt288x_gpio_init(RT2880_GPIO_MODE_UART0);
132
133         ramips_register_gpio_leds(-1, ARRAY_SIZE(wli_tx4_ag300n_leds_gpio),
134                                   wli_tx4_ag300n_leds_gpio);
135         ramips_register_gpio_buttons(-1, WLI_TX4_AG300N_KEYS_POLL_INTERVAL,
136                                      ARRAY_SIZE(wli_tx4_ag300n_gpio_buttons),
137                                      wli_tx4_ag300n_gpio_buttons);
138
139         rt288x_register_flash(0, &wli_tx4_ag300n_flash_data);
140         rt288x_register_wifi();
141         rt288x_register_wdt();
142
143         rt288x_eth_data.speed = SPEED_100;
144         rt288x_eth_data.duplex = DUPLEX_FULL;
145         rt288x_eth_data.tx_fc = 1;
146         rt288x_eth_data.rx_fc = 1;
147         rt288x_register_ethernet();
148 }
149
150 MIPS_MACHINE(RAMIPS_MACH_WLI_TX4_AG300N, "WLI-TX4-AG300N",
151              "Buffalo WLI-TX4-AG300N", wli_tx4_ag300n_init);