ar71xx: use KEY_RESTART and KEY_WPS_BUTTON code for the appropriate buttons
[openwrt/svn-archive/archive.git] / target / linux / ar71xx / files / arch / mips / ar71xx / mach-wrt400n.c
1 /*
2 * Linksys WRT400N board support
3 *
4 * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
5 * Copyright (C) 2009 Imre Kaloz <kaloz@openwrt.org>
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/mtd/mtd.h>
13 #include <linux/mtd/partitions.h>
14
15 #include <asm/mach-ar71xx/ar71xx.h>
16
17 #include "machtype.h"
18 #include "devices.h"
19 #include "dev-ap94-pci.h"
20 #include "dev-m25p80.h"
21 #include "dev-gpio-buttons.h"
22 #include "dev-leds-gpio.h"
23
24 #define WRT400N_GPIO_LED_ORANGE 5
25 #define WRT400N_GPIO_LED_GREEN 4
26 #define WRT400N_GPIO_LED_POWER 1
27 #define WRT400N_GPIO_LED_WLAN 0
28
29 #define WRT400N_GPIO_BTN_RESET 8
30 #define WRT400N_GPIO_BTN_WLSEC 3
31
32 #define WRT400N_BUTTONS_POLL_INTERVAL 20
33
34 #define WRT400N_MAC_ADDR_OFFSET 0x120c
35 #define WRT400N_CALDATA0_OFFSET 0x1000
36 #define WRT400N_CALDATA1_OFFSET 0x5000
37
38 #ifdef CONFIG_MTD_PARTITIONS
39 static struct mtd_partition wrt400n_partitions[] = {
40 {
41 .name = "uboot",
42 .offset = 0,
43 .size = 0x030000,
44 .mask_flags = MTD_WRITEABLE,
45 } , {
46 .name = "env",
47 .offset = 0x030000,
48 .size = 0x010000,
49 .mask_flags = MTD_WRITEABLE,
50 } , {
51 .name = "linux",
52 .offset = 0x040000,
53 .size = 0x140000,
54 } , {
55 .name = "rootfs",
56 .offset = 0x180000,
57 .size = 0x630000,
58 } , {
59 .name = "nvram",
60 .offset = 0x7b0000,
61 .size = 0x010000,
62 .mask_flags = MTD_WRITEABLE,
63 } , {
64 .name = "factory",
65 .offset = 0x7c0000,
66 .size = 0x010000,
67 .mask_flags = MTD_WRITEABLE,
68 } , {
69 .name = "language",
70 .offset = 0x7d0000,
71 .size = 0x020000,
72 .mask_flags = MTD_WRITEABLE,
73 } , {
74 .name = "caldata",
75 .offset = 0x7f0000,
76 .size = 0x010000,
77 .mask_flags = MTD_WRITEABLE,
78 } , {
79 .name = "firmware",
80 .offset = 0x040000,
81 .size = 0x770000,
82 }
83 };
84 #endif /* CONFIG_MTD_PARTITIONS */
85
86 static struct flash_platform_data wrt400n_flash_data = {
87 #ifdef CONFIG_MTD_PARTITIONS
88 .parts = wrt400n_partitions,
89 .nr_parts = ARRAY_SIZE(wrt400n_partitions),
90 #endif
91 };
92
93 static struct gpio_led wrt400n_leds_gpio[] __initdata = {
94 {
95 .name = "wrt400n:green:status",
96 .gpio = WRT400N_GPIO_LED_GREEN,
97 .active_low = 1,
98 }, {
99 .name = "wrt400n:amber:aoss",
100 .gpio = WRT400N_GPIO_LED_ORANGE,
101 .active_low = 1,
102 }, {
103 .name = "wrt400n:green:wlan",
104 .gpio = WRT400N_GPIO_LED_WLAN,
105 .active_low = 1,
106 }, {
107 .name = "wrt400n:green:power",
108 .gpio = WRT400N_GPIO_LED_POWER,
109 .active_low = 1,
110 }
111 };
112
113 static struct gpio_button wrt400n_gpio_buttons[] __initdata = {
114 {
115 .desc = "reset",
116 .type = EV_KEY,
117 .code = KEY_RESTART,
118 .threshold = 3,
119 .gpio = WRT400N_GPIO_BTN_RESET,
120 .active_low = 1,
121 } , {
122 .desc = "wlsec",
123 .type = EV_KEY,
124 .code = KEY_WPS_BUTTON,
125 .threshold = 3,
126 .gpio = WRT400N_GPIO_BTN_WLSEC,
127 .active_low = 1,
128 }
129 };
130
131 static void __init wrt400n_setup(void)
132 {
133 u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
134 u8 mac[6];
135 int i;
136
137 memcpy(mac, art + WRT400N_MAC_ADDR_OFFSET, 6);
138 for (i = 5; i >= 3; i--)
139 if (++mac[i] != 0x00) break;
140
141 ar71xx_set_mac_base(mac);
142
143 ar71xx_add_device_mdio(0x0);
144
145 ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
146 ar71xx_eth0_data.speed = SPEED_100;
147 ar71xx_eth0_data.duplex = DUPLEX_FULL;
148
149 ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
150 ar71xx_eth1_data.phy_mask = 0x10;
151
152 ar71xx_add_device_eth(0);
153 ar71xx_add_device_eth(1);
154
155 ar71xx_add_device_m25p80(&wrt400n_flash_data);
156
157 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(wrt400n_leds_gpio),
158 wrt400n_leds_gpio);
159
160 ar71xx_add_device_gpio_buttons(-1, WRT400N_BUTTONS_POLL_INTERVAL,
161 ARRAY_SIZE(wrt400n_gpio_buttons),
162 wrt400n_gpio_buttons);
163
164 ap94_pci_init(art + WRT400N_CALDATA0_OFFSET, NULL,
165 art + WRT400N_CALDATA1_OFFSET, NULL);
166 }
167
168 MIPS_MACHINE(AR71XX_MACH_WRT400N, "WRT400N", "Linksys WRT400N", wrt400n_setup);