ar71xx: move gpio-buttons support into a spearate file
[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/delay.h>
16 #include <linux/rtl8366_smi.h>
17
18 #include <asm/mips_machine.h>
19 #include <asm/mach-ar71xx/ar71xx.h>
20
21 #include "devices.h"
22 #include "dev-m25p80.h"
23 #include "dev-ap94-pci.h"
24 #include "dev-gpio-buttons.h"
25 #include "dev-leds-gpio.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_GPIO_RTL8366_SDA       5
37 #define WNDR3700_GPIO_RTL8366_SCK       7
38
39 #define WNDR3700_BUTTONS_POLL_INTERVAL    20
40
41 #define WNDR3700_WMAC0_MAC_OFFSET       0
42 #define WNDR3700_WMAC1_MAC_OFFSET       0xc
43 #define WNDR3700_CALDATA0_OFFSET        0x1000
44 #define WNDR3700_CALDATA1_OFFSET        0x5000
45
46 #ifdef CONFIG_MTD_PARTITIONS
47 static struct mtd_partition wndr3700_partitions[] = {
48         {
49                 .name           = "uboot",
50                 .offset         = 0,
51                 .size           = 0x050000,
52                 .mask_flags     = MTD_WRITEABLE,
53         } , {
54                 .name           = "env",
55                 .offset         = 0x050000,
56                 .size           = 0x020000,
57                 .mask_flags     = MTD_WRITEABLE,
58         } , {
59                 .name           = "rootfs",
60                 .offset         = 0x070000,
61                 .size           = 0x720000,
62         } , {
63                 .name           = "config",
64                 .offset         = 0x790000,
65                 .size           = 0x010000,
66                 .mask_flags     = MTD_WRITEABLE,
67         } , {
68                 .name           = "config_bak",
69                 .offset         = 0x7a0000,
70                 .size           = 0x010000,
71                 .mask_flags     = MTD_WRITEABLE,
72         } , {
73                 .name           = "pot",
74                 .offset         = 0x7b0000,
75                 .size           = 0x010000,
76                 .mask_flags     = MTD_WRITEABLE,
77         } , {
78                 .name           = "traffic_meter",
79                 .offset         = 0x7c0000,
80                 .size           = 0x010000,
81                 .mask_flags     = MTD_WRITEABLE,
82         } , {
83                 .name           = "language",
84                 .offset         = 0x7d0000,
85                 .size           = 0x020000,
86                 .mask_flags     = MTD_WRITEABLE,
87         } , {
88                 .name           = "caldata",
89                 .offset         = 0x7f0000,
90                 .size           = 0x010000,
91                 .mask_flags     = MTD_WRITEABLE,
92         }
93 };
94 #endif /* CONFIG_MTD_PARTITIONS */
95
96 static struct flash_platform_data wndr3700_flash_data = {
97 #ifdef CONFIG_MTD_PARTITIONS
98         .parts          = wndr3700_partitions,
99         .nr_parts       = ARRAY_SIZE(wndr3700_partitions),
100 #endif
101 };
102
103 static struct gpio_led wndr3700_leds_gpio[] __initdata = {
104         {
105                 .name           = "wndr3700:green:power",
106                 .gpio           = WNDR3700_GPIO_LED_POWER_GREEN,
107                 .active_low     = 1,
108         }, {
109                 .name           = "wndr3700:orange:power",
110                 .gpio           = WNDR3700_GPIO_LED_POWER_ORANGE,
111                 .active_low     = 1,
112         }, {
113                 .name           = "wndr3700:green:wps",
114                 .gpio           = WNDR3700_GPIO_LED_WPS_GREEN,
115                 .active_low     = 1,
116         }, {
117                 .name           = "wndr3700:orange:wps",
118                 .gpio           = WNDR3700_GPIO_LED_WPS_ORANGE,
119                 .active_low     = 1,
120         }
121 };
122
123 static struct gpio_button wndr3700_gpio_buttons[] __initdata = {
124         {
125                 .desc           = "reset",
126                 .type           = EV_KEY,
127                 .code           = BTN_0,
128                 .threshold      = 5,
129                 .gpio           = WNDR3700_GPIO_BTN_RESET,
130         }, {
131                 .desc           = "wps",
132                 .type           = EV_KEY,
133                 .code           = BTN_1,
134                 .threshold      = 5,
135                 .gpio           = WNDR3700_GPIO_BTN_WPS,
136         } , {
137                 .desc           = "wifi",
138                 .type           = EV_KEY,
139                 .code           = BTN_2,
140                 .threshold      = 5,
141                 .gpio           = WNDR3700_GPIO_BTN_WIFI,
142         }
143 };
144
145 static struct rtl8366_smi_platform_data wndr3700_rtl8366_smi_data = {
146         .gpio_sda        = WNDR3700_GPIO_RTL8366_SDA,
147         .gpio_sck        = WNDR3700_GPIO_RTL8366_SCK,
148 };
149
150 static struct platform_device wndr3700_rtl8366_smi_device = {
151         .name           = "rtl8366-smi",
152         .id             = -1,
153         .dev = {
154                 .platform_data  = &wndr3700_rtl8366_smi_data,
155         }
156 };
157
158 static void __init wndr3700_setup(void)
159 {
160         u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
161
162         ar71xx_set_mac_base(art);
163
164         ar71xx_eth0_pll_data.pll_1000 = 0x11110000;
165         ar71xx_eth0_data.mii_bus_dev = &wndr3700_rtl8366_smi_device.dev;
166         ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
167         ar71xx_eth0_data.phy_mask = 0xf;
168         ar71xx_eth0_data.speed = SPEED_1000;
169         ar71xx_eth0_data.duplex = DUPLEX_FULL;
170
171         ar71xx_eth1_pll_data.pll_1000 = 0x11110000;
172         ar71xx_eth1_data.mii_bus_dev = &wndr3700_rtl8366_smi_device.dev;
173         ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
174         ar71xx_eth1_data.phy_mask = 0x10;
175
176         ar71xx_add_device_eth(0);
177         ar71xx_add_device_eth(1);
178
179         ar71xx_add_device_usb();
180
181         ar71xx_add_device_m25p80(&wndr3700_flash_data);
182
183         ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(wndr3700_leds_gpio),
184                                     wndr3700_leds_gpio);
185
186         ar71xx_add_device_gpio_buttons(-1, WNDR3700_BUTTONS_POLL_INTERVAL,
187                                       ARRAY_SIZE(wndr3700_gpio_buttons),
188                                       wndr3700_gpio_buttons);
189
190         platform_device_register(&wndr3700_rtl8366_smi_device);
191         platform_device_register_simple("wndr3700-led-usb", -1, NULL, 0);
192
193         ap94_pci_init(art + WNDR3700_CALDATA0_OFFSET,
194                       art + WNDR3700_WMAC0_MAC_OFFSET,
195                       art + WNDR3700_CALDATA1_OFFSET,
196                       art + WNDR3700_WMAC1_MAC_OFFSET);
197 }
198
199 MIPS_MACHINE(AR71XX_MACH_WNDR3700, "NETGEAR WNDR3700", wndr3700_setup);