1599dce05ff01e6952357b04e189ea97de3a7181
[10.03/openwrt.git] / target / linux / ar71xx / files / arch / mips / ar71xx / mach-wndr3700.c
1 /*
2  *  Netgear WNDR3700 board support
3  *
4  *  Copyright (C) 2009 Marco Porsch
5  *  Copyright (C) 2009 Gabor Juhos <juhosg@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 #include <linux/spi/spi.h>
16 #include <linux/spi/flash.h>
17 #include <linux/input.h>
18
19 #include <asm/mips_machine.h>
20 #include <asm/mach-ar71xx/ar71xx.h>
21 #include <asm/mach-ar71xx/pci.h>
22
23 #include "devices.h"
24
25 #define WNDR3700_GPIO_LED_WPS_ORANGE    0
26 #define WNDR3700_GPIO_LED_POWER_ORANGE  1
27 #define WNDR3700_GPIO_LED_POWER_GREEN   2
28 #define WNDR3700_GPIO_LED_WPS_GREEN     4
29
30 #define WNDR3700_GPIO_BTN_WPS           3
31 #define WNDR3700_GPIO_BTN_RESET         8
32 #define WNDR3700_GPIO_BTN_WIFI          11
33
34 #define WNDR3700_BUTTONS_POLL_INTERVAL    20
35
36 #ifdef CONFIG_MTD_PARTITIONS
37 static struct mtd_partition wndr3700_partitions[] = {
38         {
39                 .name           = "uboot",
40                 .offset         = 0,
41                 .size           = 0x050000,
42                 .mask_flags     = MTD_WRITEABLE,
43         } , {
44                 .name           = "env",
45                 .offset         = 0x050000,
46                 .size           = 0x020000,
47                 .mask_flags     = MTD_WRITEABLE,
48         } , {
49                 .name           = "rootfs",
50                 .offset         = 0x070000,
51                 .size           = 0x720000,
52         } , {
53                 .name           = "config",
54                 .offset         = 0x790000,
55                 .size           = 0x010000,
56                 .mask_flags     = MTD_WRITEABLE,
57         } , {
58                 .name           = "config_bak",
59                 .offset         = 0x7a0000,
60                 .size           = 0x010000,
61                 .mask_flags     = MTD_WRITEABLE,
62         } , {
63                 .name           = "pot",
64                 .offset         = 0x7b0000,
65                 .size           = 0x010000,
66                 .mask_flags     = MTD_WRITEABLE,
67         } , {
68                 .name           = "traffic_meter",
69                 .offset         = 0x7c0000,
70                 .size           = 0x010000,
71                 .mask_flags     = MTD_WRITEABLE,
72         } , {
73                 .name           = "language",
74                 .offset         = 0x7d0000,
75                 .size           = 0x020000,
76                 .mask_flags     = MTD_WRITEABLE,
77         } , {
78                 .name           = "caldata",
79                 .offset         = 0x7f0000,
80                 .size           = 0x010000,
81                 .mask_flags     = MTD_WRITEABLE,
82         }
83 };
84 #endif /* CONFIG_MTD_PARTITIONS */
85
86 static struct flash_platform_data wndr3700_flash_data = {
87 #ifdef CONFIG_MTD_PARTITIONS
88         .parts          = wndr3700_partitions,
89         .nr_parts       = ARRAY_SIZE(wndr3700_partitions),
90 #endif
91 };
92
93 static struct ar71xx_pci_irq wndr3700_pci_irqs[] __initdata = {
94         {
95                 .slot   = 0,
96                 .pin    = 1,
97                 .irq    = AR71XX_PCI_IRQ_DEV0,
98         }, {
99                 .slot   = 1,
100                 .pin    = 1,
101                 .irq    = AR71XX_PCI_IRQ_DEV1,
102         }
103 };
104
105 static struct spi_board_info wndr3700_spi_info[] = {
106         {
107                 .bus_num        = 0,
108                 .chip_select    = 0,
109                 .max_speed_hz   = 25000000,
110                 .modalias       = "m25p80",
111                 .platform_data  = &wndr3700_flash_data,
112         }
113 };
114
115 static struct gpio_led wndr3700_leds_gpio[] __initdata = {
116         {
117                 .name           = "wndr3700:green:power",
118                 .gpio           = WNDR3700_GPIO_LED_POWER_GREEN,
119                 .active_low     = 1,
120         }, {
121                 .name           = "wndr3700:orange:power",
122                 .gpio           = WNDR3700_GPIO_LED_POWER_ORANGE,
123                 .active_low     = 1,
124         }, {
125                 .name           = "wndr3700:green:wps",
126                 .gpio           = WNDR3700_GPIO_LED_WPS_GREEN,
127                 .active_low     = 1,
128         }, {
129                 .name           = "wndr3700:orange:wps",
130                 .gpio           = WNDR3700_GPIO_LED_WPS_ORANGE,
131                 .active_low     = 1,
132         }
133 };
134
135 static struct gpio_button wndr3700_gpio_buttons[] __initdata = {
136         {
137                 .desc           = "reset",
138                 .type           = EV_KEY,
139                 .code           = BTN_0,
140                 .threshold      = 5,
141                 .gpio           = WNDR3700_GPIO_BTN_RESET,
142         }, {
143                 .desc           = "wps",
144                 .type           = EV_KEY,
145                 .code           = BTN_1,
146                 .threshold      = 5,
147                 .gpio           = WNDR3700_GPIO_BTN_WPS,
148         } , {
149                 .desc           = "wifi",
150                 .type           = EV_KEY,
151                 .code           = BTN_2,
152                 .threshold      = 5,
153                 .gpio           = WNDR3700_GPIO_BTN_WIFI,
154         }
155 };
156
157 static void __init wndr3700_setup(void)
158 {
159         u8 *mac = (u8 *) KSEG1ADDR(0x1fff0000);
160
161         ar71xx_set_mac_base(mac);
162         ar71xx_add_device_mdio(0x0);
163
164         ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
165         ar71xx_eth0_data.phy_mask = 0xf;
166         ar71xx_eth0_data.speed = SPEED_1000;
167         ar71xx_eth0_data.duplex = DUPLEX_FULL;
168
169         ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
170         ar71xx_eth1_data.phy_mask = 0x10;
171
172         ar71xx_add_device_eth(0);
173         ar71xx_add_device_eth(1);
174
175         ar71xx_add_device_usb();
176
177         ar71xx_pci_init(ARRAY_SIZE(wndr3700_pci_irqs), wndr3700_pci_irqs);
178
179         ar71xx_add_device_spi(NULL, wndr3700_spi_info,
180                               ARRAY_SIZE(wndr3700_spi_info));
181
182         ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(wndr3700_leds_gpio),
183                                     wndr3700_leds_gpio);
184
185         ar71xx_add_device_gpio_buttons(-1, WNDR3700_BUTTONS_POLL_INTERVAL,
186                                       ARRAY_SIZE(wndr3700_gpio_buttons),
187                                       wndr3700_gpio_buttons);
188 }
189
190 MIPS_MACHINE(AR71XX_MACH_WNDR3700, "NETGEAR WNDR3700", wndr3700_setup);