ar71xx: use KEY_RESTART and KEY_WPS_BUTTON code for the appropriate buttons
[oweals/openwrt.git] / target / linux / ar71xx / files / arch / mips / ar71xx / mach-nbg460n.c
1 /*
2  *  Zyxel NBG 460N/550N/550NH board support
3  *
4  *  Copyright (C) 2010 Michael Kurz <michi.kurz@googlemail.com>
5  *
6  *  based on mach-tl-wr1043nd.c
7  *
8  *  This program is free software; you can redistribute it and/or modify it
9  *  under the terms of the GNU General Public License version 2 as published
10  *  by the Free Software Foundation.
11  */
12
13 #include <linux/platform_device.h>
14 #include <linux/mtd/mtd.h>
15 #include <linux/mtd/partitions.h>
16 #include <linux/delay.h>
17 #include <linux/rtl8366s.h>
18
19 #include <linux/i2c.h>
20 #include <linux/i2c-algo-bit.h>
21 #include <linux/i2c-gpio.h>
22
23 #include <asm/mach-ar71xx/ar71xx.h>
24
25 #include "machtype.h"
26 #include "devices.h"
27 #include "dev-m25p80.h"
28 #include "dev-ar913x-wmac.h"
29 #include "dev-gpio-buttons.h"
30 #include "dev-leds-gpio.h"
31
32 /* LEDs */
33 #define NBG460N_GPIO_LED_WPS            3
34 #define NBG460N_GPIO_LED_WAN            6
35 #define NBG460N_GPIO_LED_POWER          14
36 #define NBG460N_GPIO_LED_WLAN           15
37
38 /* Buttons */
39 #define NBG460N_GPIO_BTN_WPS            12
40 #define NBG460N_GPIO_BTN_RESET          21
41 #define NBG460N_BUTTONS_POLL_INTERVAL   20
42
43 /* RTC chip PCF8563 I2C interface */
44 #define NBG460N_GPIO_PCF8563_SDA        8
45 #define NBG460N_GPIO_PCF8563_SCK        7
46
47 /* Switch configuration I2C interface */
48 #define NBG460N_GPIO_RTL8366_SDA        16
49 #define NBG460N_GPIO_RTL8366_SCK        18
50
51 #ifdef CONFIG_MTD_PARTITIONS
52 static struct mtd_partition nbg460n_partitions[] = {
53         {
54                 .name           = "Bootbase",
55                 .offset         = 0,
56                 .size           = 0x010000,
57         } , {
58                 .name           = "U-Boot Config",
59                 .offset         = 0x010000,
60                 .size           = 0x030000,
61                 .mask_flags     = MTD_WRITEABLE,
62         } , {
63                 .name           = "U-Boot",
64                 .offset         = 0x040000,
65                 .size           = 0x030000,
66                 .mask_flags     = MTD_WRITEABLE,
67         } , {
68                 .name           = "firmware",
69                 .offset         = 0x070000,
70                 .size           = 0x380000,
71                 .mask_flags     = MTD_WRITEABLE,
72         } , {
73                 .name           = "CalibData",
74                 .offset         = 0x3f0000,
75                 .size           = 0x010000,
76         }
77 };
78 #endif /* CONFIG_MTD_PARTITIONS */
79
80 static struct flash_platform_data nbg460n_flash_data = {
81 #ifdef CONFIG_MTD_PARTITIONS
82         .parts          = nbg460n_partitions,
83         .nr_parts       = ARRAY_SIZE(nbg460n_partitions),
84 #endif
85 };
86
87 static struct gpio_led nbg460n_leds_gpio[] __initdata = {
88         {
89                 .name           = "nbg460n:green:power",
90                 .gpio           = NBG460N_GPIO_LED_POWER,
91                 .active_low     = 0,
92                 .default_trigger = "default-on",
93         }, {
94                 .name           = "nbg460n:green:wps",
95                 .gpio           = NBG460N_GPIO_LED_WPS,
96                 .active_low     = 0,
97         }, {
98                 .name           = "nbg460n:green:wlan",
99                 .gpio           = NBG460N_GPIO_LED_WLAN,
100                 .active_low     = 0,
101         }, {
102                 /* Not really for controlling the LED,
103                    when set low the LED blinks uncontrollable  */
104                 .name           = "nbg460n:green:wan",
105                 .gpio           = NBG460N_GPIO_LED_WAN,
106                 .active_low     = 0,
107         }
108 };
109
110 static struct gpio_button nbg460n_gpio_buttons[] __initdata = {
111         {
112                 .desc           = "reset",
113                 .type           = EV_KEY,
114                 .code           = KEY_RESTART,
115                 .threshold      = 5,
116                 .gpio           = NBG460N_GPIO_BTN_RESET,
117                 .active_low     = 1,
118         }, {
119                 .desc           = "wps",
120                 .type           = EV_KEY,
121                 .code           = KEY_WPS_BUTTON,
122                 .threshold      = 5,
123                 .gpio           = NBG460N_GPIO_BTN_WPS,
124                 .active_low     = 1,
125         }
126 };
127
128 static struct i2c_gpio_platform_data nbg460n_i2c_device_platdata = {
129         .sda_pin        = NBG460N_GPIO_PCF8563_SDA,
130         .scl_pin        = NBG460N_GPIO_PCF8563_SCK,
131         .udelay         = 10,
132 };
133
134 static struct platform_device nbg460n_i2c_device = {
135         .name           = "i2c-gpio",
136         .id             = -1,
137         .num_resources  = 0,
138         .resource       = NULL,
139         .dev            = {
140                 .platform_data  = &nbg460n_i2c_device_platdata,
141         },
142 };
143
144 static struct i2c_board_info nbg460n_i2c_devs[] __initdata = {
145         {
146                 I2C_BOARD_INFO("pcf8563", 0x51),
147         },
148 };
149
150 static void __devinit nbg460n_i2c_init(void)
151 {
152         /* The gpio interface */
153         platform_device_register(&nbg460n_i2c_device);
154         /* I2C devices */
155         i2c_register_board_info(0, nbg460n_i2c_devs,
156                                 ARRAY_SIZE(nbg460n_i2c_devs));
157 }
158
159
160 static struct rtl8366s_platform_data nbg460n_rtl8366s_data = {
161         .gpio_sda        = NBG460N_GPIO_RTL8366_SDA,
162         .gpio_sck        = NBG460N_GPIO_RTL8366_SCK,
163 };
164
165 static struct platform_device nbg460n_rtl8366s_device = {
166         .name           = RTL8366S_DRIVER_NAME,
167         .id             = -1,
168         .dev = {
169                 .platform_data  = &nbg460n_rtl8366s_data,
170         }
171 };
172
173 static void __init nbg460n_setup(void)
174 {
175         /* end of bootloader sector contains mac address*/
176         u8 *mac = (u8 *) KSEG1ADDR(0x1fc0fff8);
177         /* last sector contains wlan calib data */
178         u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
179
180         ar71xx_set_mac_base(mac);
181
182         /* LAN Port */
183         ar71xx_eth0_data.mii_bus_dev = &nbg460n_rtl8366s_device.dev;
184         ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
185         ar71xx_eth0_data.speed = SPEED_1000;
186         ar71xx_eth0_data.duplex = DUPLEX_FULL;
187
188         /* WAN Port */
189         ar71xx_eth1_data.mii_bus_dev = &nbg460n_rtl8366s_device.dev;
190         ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
191         ar71xx_eth1_data.phy_mask = 0x10;
192
193         ar71xx_add_device_eth(0);
194         ar71xx_add_device_eth(1);
195
196         /* register the switch phy */
197         platform_device_register(&nbg460n_rtl8366s_device);
198
199         /* register flash */
200         ar71xx_add_device_m25p80(&nbg460n_flash_data);
201
202         ar913x_add_device_wmac(eeprom, mac);
203
204         /* register RTC chip */
205         nbg460n_i2c_init();
206
207         ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(nbg460n_leds_gpio),
208                                         nbg460n_leds_gpio);
209
210         ar71xx_add_device_gpio_buttons(-1, NBG460N_BUTTONS_POLL_INTERVAL,
211                                         ARRAY_SIZE(nbg460n_gpio_buttons),
212                                         nbg460n_gpio_buttons);
213 }
214
215 MIPS_MACHINE(AR71XX_MACH_NBG460N, "NBG460N", "Zyxel NBG460N/550N/550NH", nbg460n_setup);