[ar71xx] mzk-w04nu: fetch MAC address from the flash
[openwrt-10.03/.git] / target / linux / ar71xx / files / arch / mips / ar71xx / mach-mzk-w04nu.c
1 /*
2  *  Planex MZK-W04NU board support
3  *
4  *  Copyright (C) 2009 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/platform_device.h>
12 #include <linux/mtd/mtd.h>
13 #include <linux/mtd/partitions.h>
14 #include <linux/spi/spi.h>
15 #include <linux/spi/flash.h>
16 #include <linux/input.h>
17
18 #include <asm/mips_machine.h>
19
20 #include <asm/mach-ar71xx/ar71xx.h>
21 #include <asm/mach-ar71xx/platform.h>
22
23 #define MZK_W04NU_GPIO_LED_USB          0
24 #define MZK_W04NU_GPIO_LED_STATUS       1
25 #define MZK_W04NU_GPIO_LED_WPS          3
26 #define MZK_W04NU_GPIO_LED_WLAN         6
27 #define MZK_W04NU_GPIO_LED_AP           15
28 #define MZK_W04NU_GPIO_LED_ROUTER       16
29
30 #define MZK_W04NU_GPIO_BTN_APROUTER     5
31 #define MZK_W04NU_GPIO_BTN_WPS          12
32 #define MZK_W04NU_GPIO_BTN_RESET        21
33
34 #define MZK_W04NU_BUTTONS_POLL_INTERVAL 20
35
36 #ifdef CONFIG_MTD_PARTITIONS
37 static struct mtd_partition mzk_w04nu_partitions[] = {
38         {
39                 .name           = "u-boot",
40                 .offset         = 0,
41                 .size           = 0x040000,
42                 .mask_flags     = MTD_WRITEABLE,
43         } , {
44                 .name           = "u-boot-env",
45                 .offset         = 0x040000,
46                 .size           = 0x010000,
47         } , {
48                 .name           = "uImage",
49                 .offset         = 0x050000,
50                 .size           = 0x160000,
51         } , {
52                 .name           = "rootfs",
53                 .offset         = 0x1b0000,
54                 .size           = 0x610000,
55         } , {
56                 .name           = "config",
57                 .offset         = 0x7c0000,
58                 .size           = 0x020000,
59         } , {
60                 .name           = "art",
61                 .offset         = 0x7e0000,
62                 .size           = 0x020000,
63                 .mask_flags     = MTD_WRITEABLE,
64         }
65 };
66 #endif /* CONFIG_MTD_PARTITIONS */
67
68 static struct flash_platform_data mzk_w04nu_flash_data = {
69 #ifdef CONFIG_MTD_PARTITIONS
70         .parts          = mzk_w04nu_partitions,
71         .nr_parts       = ARRAY_SIZE(mzk_w04nu_partitions),
72 #endif
73 };
74
75 static struct spi_board_info mzk_w04nu_spi_info[] = {
76         {
77                 .bus_num        = 0,
78                 .chip_select    = 0,
79                 .max_speed_hz   = 25000000,
80                 .modalias       = "m25p80",
81                 .platform_data  = &mzk_w04nu_flash_data,
82         }
83 };
84
85 static struct gpio_led mzk_w04nu_leds_gpio[] __initdata = {
86         {
87                 .name           = "mzk-w04nu:green:status",
88                 .gpio           = MZK_W04NU_GPIO_LED_STATUS,
89                 .active_low     = 1,
90         }, {
91                 .name           = "mzk-w04nu:blue:wps",
92                 .gpio           = MZK_W04NU_GPIO_LED_WPS,
93                 .active_low     = 1,
94         }, {
95                 .name           = "mzk-w04nu:green:wlan",
96                 .gpio           = MZK_W04NU_GPIO_LED_WLAN,
97                 .active_low     = 1,
98         }, {
99                 .name           = "mzk-w04nu:green:usb",
100                 .gpio           = MZK_W04NU_GPIO_LED_USB,
101                 .active_low     = 1,
102         }, {
103                 .name           = "mzk-w04nu:green:ap",
104                 .gpio           = MZK_W04NU_GPIO_LED_AP,
105                 .active_low     = 1,
106         }, {
107                 .name           = "mzk-w04nu:green:router",
108                 .gpio           = MZK_W04NU_GPIO_LED_ROUTER,
109                 .active_low     = 1,
110         }
111 };
112
113 static struct gpio_button mzk_w04nu_gpio_buttons[] __initdata = {
114         {
115                 .desc           = "reset",
116                 .type           = EV_KEY,
117                 .code           = BTN_0,
118                 .threshold      = 5,
119                 .gpio           = MZK_W04NU_GPIO_BTN_RESET,
120                 .active_low     = 1,
121         }, {
122                 .desc           = "wps",
123                 .type           = EV_KEY,
124                 .code           = BTN_1,
125                 .threshold      = 5,
126                 .gpio           = MZK_W04NU_GPIO_BTN_WPS,
127                 .active_low     = 1,
128         }, {
129                 .desc           = "aprouter",
130                 .type           = EV_KEY,
131                 .code           = BTN_2,
132                 .threshold      = 5,
133                 .gpio           = MZK_W04NU_GPIO_BTN_APROUTER,
134                 .active_low     = 0,
135         }
136 };
137
138 static void __init mzk_w04nu_setup(void)
139 {
140         u8 *mac = (u8 *) KSEG1ADDR(0x1fff1000);
141
142         ar71xx_set_mac_base(mac);
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_spi(NULL, mzk_w04nu_spi_info,
158                                         ARRAY_SIZE(mzk_w04nu_spi_info));
159
160         ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(mzk_w04nu_leds_gpio),
161                                         mzk_w04nu_leds_gpio);
162
163         ar71xx_add_device_gpio_buttons(-1, MZK_W04NU_BUTTONS_POLL_INTERVAL,
164                                         ARRAY_SIZE(mzk_w04nu_gpio_buttons),
165                                         mzk_w04nu_gpio_buttons);
166         ar71xx_add_device_usb();
167
168         ar91xx_add_device_wmac();
169 }
170
171 MIPS_MACHINE(AR71XX_MACH_MZK_W04NU, "Planex MZK-W04NU", mzk_w04nu_setup);