9c5dd41a4c2a5ceb25fabf3a38e4edfe87330486
[librecmc/librecmc.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 #include <linux/pci.h>
19 #include <linux/ath9k_platform.h>
20
21 #include <asm/mips_machine.h>
22 #include <asm/mach-ar71xx/ar71xx.h>
23 #include <asm/mach-ar71xx/pci.h>
24
25 #include "devices.h"
26
27 #define WNDR3700_GPIO_LED_WPS_ORANGE    0
28 #define WNDR3700_GPIO_LED_POWER_ORANGE  1
29 #define WNDR3700_GPIO_LED_POWER_GREEN   2
30 #define WNDR3700_GPIO_LED_WPS_GREEN     4
31
32 #define WNDR3700_GPIO_BTN_WPS           3
33 #define WNDR3700_GPIO_BTN_RESET         8
34 #define WNDR3700_GPIO_BTN_WIFI          11
35
36 #define WNDR3700_BUTTONS_POLL_INTERVAL    20
37
38 #ifdef CONFIG_MTD_PARTITIONS
39 static struct mtd_partition wndr3700_partitions[] = {
40         {
41                 .name           = "uboot",
42                 .offset         = 0,
43                 .size           = 0x050000,
44                 .mask_flags     = MTD_WRITEABLE,
45         } , {
46                 .name           = "env",
47                 .offset         = 0x050000,
48                 .size           = 0x020000,
49                 .mask_flags     = MTD_WRITEABLE,
50         } , {
51                 .name           = "rootfs",
52                 .offset         = 0x070000,
53                 .size           = 0x720000,
54         } , {
55                 .name           = "config",
56                 .offset         = 0x790000,
57                 .size           = 0x010000,
58                 .mask_flags     = MTD_WRITEABLE,
59         } , {
60                 .name           = "config_bak",
61                 .offset         = 0x7a0000,
62                 .size           = 0x010000,
63                 .mask_flags     = MTD_WRITEABLE,
64         } , {
65                 .name           = "pot",
66                 .offset         = 0x7b0000,
67                 .size           = 0x010000,
68                 .mask_flags     = MTD_WRITEABLE,
69         } , {
70                 .name           = "traffic_meter",
71                 .offset         = 0x7c0000,
72                 .size           = 0x010000,
73                 .mask_flags     = MTD_WRITEABLE,
74         } , {
75                 .name           = "language",
76                 .offset         = 0x7d0000,
77                 .size           = 0x020000,
78                 .mask_flags     = MTD_WRITEABLE,
79         } , {
80                 .name           = "caldata",
81                 .offset         = 0x7f0000,
82                 .size           = 0x010000,
83                 .mask_flags     = MTD_WRITEABLE,
84         }
85 };
86 #endif /* CONFIG_MTD_PARTITIONS */
87
88 static struct flash_platform_data wndr3700_flash_data = {
89 #ifdef CONFIG_MTD_PARTITIONS
90         .parts          = wndr3700_partitions,
91         .nr_parts       = ARRAY_SIZE(wndr3700_partitions),
92 #endif
93 };
94
95 #ifdef CONFIG_PCI
96 static struct ar71xx_pci_irq wndr3700_pci_irqs[] __initdata = {
97         {
98                 .slot   = 0,
99                 .pin    = 1,
100                 .irq    = AR71XX_PCI_IRQ_DEV0,
101         }, {
102                 .slot   = 1,
103                 .pin    = 1,
104                 .irq    = AR71XX_PCI_IRQ_DEV1,
105         }
106 };
107
108 static struct ath9k_platform_data wndr3700_wmac0_data;
109 static struct ath9k_platform_data wndr3700_wmac1_data;
110
111 static int wndr3700_pci_plat_dev_init(struct pci_dev *dev)
112 {
113         switch (PCI_SLOT(dev->devfn)) {
114         case 17:
115                 dev->dev.platform_data = &wndr3700_wmac0_data;
116                 break;
117         case 18:
118                 dev->dev.platform_data = &wndr3700_wmac1_data;
119                 break;
120         }
121
122         return 0;
123 }
124
125 static void __init wndr3700_pci_init(void)
126 {
127         u8 *ee;
128
129         ee = (u8 *) KSEG1ADDR(0x1fff1000);
130         memcpy(wndr3700_wmac0_data.eeprom_data, ee,
131                sizeof(wndr3700_wmac0_data.eeprom_data));
132
133         ee = (u8 *) KSEG1ADDR(0x1fff5000);
134         memcpy(wndr3700_wmac1_data.eeprom_data, ee,
135                sizeof(wndr3700_wmac1_data.eeprom_data));
136
137         ar71xx_pci_plat_dev_init = wndr3700_pci_plat_dev_init;
138         ar71xx_pci_init(ARRAY_SIZE(wndr3700_pci_irqs), wndr3700_pci_irqs);
139 }
140 #else
141 static inline void wndr3700_pci_init(void) { };
142 #endif /* CONFIG_PCI */
143
144 static struct spi_board_info wndr3700_spi_info[] = {
145         {
146                 .bus_num        = 0,
147                 .chip_select    = 0,
148                 .max_speed_hz   = 25000000,
149                 .modalias       = "m25p80",
150                 .platform_data  = &wndr3700_flash_data,
151         }
152 };
153
154 static struct gpio_led wndr3700_leds_gpio[] __initdata = {
155         {
156                 .name           = "wndr3700:green:power",
157                 .gpio           = WNDR3700_GPIO_LED_POWER_GREEN,
158                 .active_low     = 1,
159         }, {
160                 .name           = "wndr3700:orange:power",
161                 .gpio           = WNDR3700_GPIO_LED_POWER_ORANGE,
162                 .active_low     = 1,
163         }, {
164                 .name           = "wndr3700:green:wps",
165                 .gpio           = WNDR3700_GPIO_LED_WPS_GREEN,
166                 .active_low     = 1,
167         }, {
168                 .name           = "wndr3700:orange:wps",
169                 .gpio           = WNDR3700_GPIO_LED_WPS_ORANGE,
170                 .active_low     = 1,
171         }
172 };
173
174 static struct gpio_button wndr3700_gpio_buttons[] __initdata = {
175         {
176                 .desc           = "reset",
177                 .type           = EV_KEY,
178                 .code           = BTN_0,
179                 .threshold      = 5,
180                 .gpio           = WNDR3700_GPIO_BTN_RESET,
181         }, {
182                 .desc           = "wps",
183                 .type           = EV_KEY,
184                 .code           = BTN_1,
185                 .threshold      = 5,
186                 .gpio           = WNDR3700_GPIO_BTN_WPS,
187         } , {
188                 .desc           = "wifi",
189                 .type           = EV_KEY,
190                 .code           = BTN_2,
191                 .threshold      = 5,
192                 .gpio           = WNDR3700_GPIO_BTN_WIFI,
193         }
194 };
195
196 static void __init wndr3700_setup(void)
197 {
198         u8 *mac = (u8 *) KSEG1ADDR(0x1fff0000);
199
200         ar71xx_set_mac_base(mac);
201         ar71xx_add_device_mdio(0x0);
202
203         ar71xx_eth0_pll_data.pll_1000 = 0x11110000;
204         ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
205         ar71xx_eth0_data.phy_mask = 0xf;
206         ar71xx_eth0_data.speed = SPEED_1000;
207         ar71xx_eth0_data.duplex = DUPLEX_FULL;
208
209         ar71xx_eth1_pll_data.pll_1000 = 0x11110000;
210         ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
211         ar71xx_eth1_data.phy_mask = 0x10;
212
213         ar71xx_add_device_eth(0);
214         ar71xx_add_device_eth(1);
215
216         ar71xx_add_device_usb();
217
218         ar71xx_add_device_spi(NULL, wndr3700_spi_info,
219                               ARRAY_SIZE(wndr3700_spi_info));
220
221         ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(wndr3700_leds_gpio),
222                                     wndr3700_leds_gpio);
223
224         ar71xx_add_device_gpio_buttons(-1, WNDR3700_BUTTONS_POLL_INTERVAL,
225                                       ARRAY_SIZE(wndr3700_gpio_buttons),
226                                       wndr3700_gpio_buttons);
227
228         wndr3700_pci_init();
229 }
230
231 MIPS_MACHINE(AR71XX_MACH_WNDR3700, "NETGEAR WNDR3700", wndr3700_setup);