e3b6aabeb0bc0c1d0b03d5492ea11332ec4776a9
[openwrt-10.03/.git] / target / linux / ar71xx / files / arch / mips / ar71xx / mach-dir-615-c1.c
1 /*
2  *  D-Link DIR-615 rev C1 board support
3  *
4  *  Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
5  *  Copyright (C) 2008 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-m25p80.h"
20 #include "dev-ar913x-wmac.h"
21 #include "dev-gpio-buttons.h"
22 #include "dev-leds-gpio.h"
23 #include "nvram.h"
24
25 #define DIR_615C1_GPIO_LED_ORANGE_STATUS 1      /* ORANGE:STATUS:TRICOLOR */
26 #define DIR_615C1_GPIO_LED_BLUE_WPS     3       /* BLUE:WPS */
27 #define DIR_615C1_GPIO_LED_GREEN_WAN    4       /* GREEN:WAN:TRICOLOR */
28 #define DIR_615C1_GPIO_LED_GREEN_WANCPU 5       /* GREEN:WAN:CPU:TRICOLOR */
29 #define DIR_615C1_GPIO_LED_GREEN_WLAN   6       /* GREEN:WLAN */
30 #define DIR_615C1_GPIO_LED_GREEN_STATUS 14      /* GREEN:STATUS:TRICOLOR */
31 #define DIR_615C1_GPIO_LED_ORANGE_WAN   15      /* ORANGE:WAN:TRICOLOR */
32
33 /* buttons may need refinement */
34
35 #define DIR_615C1_GPIO_BTN_WPS          12
36 #define DIR_615C1_GPIO_BTN_RESET        21
37
38 #define DIR_615C1_BUTTONS_POLL_INTERVAL 20
39
40 #define DIR_615C1_CONFIG_ADDR           0x1f020000
41 #define DIR_615C1_CONFIG_SIZE           0x10000
42
43 #ifdef CONFIG_MTD_PARTITIONS
44 static struct mtd_partition dir_615c1_partitions[] = {
45         {
46                 .name           = "u-boot",
47                 .offset         = 0,
48                 .size           = 0x020000,
49                 .mask_flags     = MTD_WRITEABLE,
50         } , {
51                 .name           = "config",
52                 .offset         = 0x020000,
53                 .size           = 0x010000,
54         } , {
55                 .name           = "kernel",
56                 .offset         = 0x030000,
57                 .size           = 0x0d0000,
58         } , {
59                 .name           = "rootfs",
60                 .offset         = 0x100000,
61                 .size           = 0x2f0000,
62         } , {
63                 .name           = "art",
64                 .offset         = 0x3f0000,
65                 .size           = 0x010000,
66                 .mask_flags     = MTD_WRITEABLE,
67         } , {
68                 .name           = "firmware",
69                 .offset         = 0x030000,
70                 .size           = 0x3c0000,
71         }
72 };
73 #endif /* CONFIG_MTD_PARTITIONS */
74
75 static struct flash_platform_data dir_615c1_flash_data = {
76 #ifdef CONFIG_MTD_PARTITIONS
77         .parts          = dir_615c1_partitions,
78         .nr_parts       = ARRAY_SIZE(dir_615c1_partitions),
79 #endif
80 };
81
82 static struct gpio_led dir_615c1_leds_gpio[] __initdata = {
83         {
84                 .name           = "dir-615c1:orange:status",
85                 .gpio           = DIR_615C1_GPIO_LED_ORANGE_STATUS,
86                 .active_low     = 1,
87         }, {
88                 .name           = "dir-615c1:blue:wps",
89                 .gpio           = DIR_615C1_GPIO_LED_BLUE_WPS,
90                 .active_low     = 1,
91         }, {
92                 .name           = "dir-615c1:green:wan",
93                 .gpio           = DIR_615C1_GPIO_LED_GREEN_WAN,
94                 .active_low     = 1,
95         }, {
96                 .name           = "dir-615c1:green:wancpu",
97                 .gpio           = DIR_615C1_GPIO_LED_GREEN_WANCPU,
98                 .active_low     = 1,
99         }, {
100                 .name           = "dir-615c1:green:wlan",
101                 .gpio           = DIR_615C1_GPIO_LED_GREEN_WLAN,
102                 .active_low     = 1,
103         }, {
104                 .name           = "dir-615c1:green:status",
105                 .gpio           = DIR_615C1_GPIO_LED_GREEN_STATUS,
106                 .active_low     = 1,
107         }, {
108                 .name           = "dir-615c1:orange:wan",
109                 .gpio           = DIR_615C1_GPIO_LED_ORANGE_WAN,
110                 .active_low     = 1,
111         }
112
113 };
114
115 static struct gpio_button dir_615c1_gpio_buttons[] __initdata = {
116         {
117                 .desc           = "reset",
118                 .type           = EV_KEY,
119                 .code           = BTN_0,
120                 .threshold      = 5,
121                 .gpio           = DIR_615C1_GPIO_BTN_RESET,
122         }, {
123                 .desc           = "wps",
124                 .type           = EV_KEY,
125                 .code           = BTN_1,
126                 .threshold      = 5,
127                 .gpio           = DIR_615C1_GPIO_BTN_WPS,
128         }
129 };
130
131 static void __init dir_615c1_setup(void)
132 {
133         const char *config = (char *) KSEG1ADDR(DIR_615C1_CONFIG_ADDR);
134         u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
135         u8 mac[6];
136         u8 *wlan_mac = NULL;
137
138         if (nvram_parse_mac_addr(config, DIR_615C1_CONFIG_SIZE,
139                                  "lan_mac=", mac) == 0) {
140                 ar71xx_set_mac_base(mac);
141                 wlan_mac = mac;
142         }
143
144         ar71xx_add_device_mdio(0x0);
145
146         ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
147         ar71xx_eth0_data.phy_mask = 0xf;
148         ar71xx_eth0_data.speed = SPEED_100;
149         ar71xx_eth0_data.duplex = DUPLEX_FULL;
150
151         ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
152         ar71xx_eth1_data.phy_mask = 0x10;
153
154         ar71xx_add_device_eth(0);
155         ar71xx_add_device_eth(1);
156
157         ar71xx_add_device_m25p80(&dir_615c1_flash_data);
158
159         ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(dir_615c1_leds_gpio),
160                                         dir_615c1_leds_gpio);
161
162         ar71xx_add_device_gpio_buttons(-1, DIR_615C1_BUTTONS_POLL_INTERVAL,
163                                         ARRAY_SIZE(dir_615c1_gpio_buttons),
164                                         dir_615c1_gpio_buttons);
165
166         ar913x_add_device_wmac(eeprom, wlan_mac);
167 }
168
169 MIPS_MACHINE(AR71XX_MACH_DIR_615_C1, "D-Link DIR-615 rev. C1", dir_615c1_setup);