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