ar71xx: merge dev-ar9{13,34}x-wmac into dev-ar9xxx-wmac
[openwrt/svn-archive/archive.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-ar9xxx-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 .mask_flags = MTD_WRITEABLE,
58 }, {
59 .name = "U-Boot Config",
60 .offset = 0x010000,
61 .size = 0x030000,
62 }, {
63 .name = "U-Boot",
64 .offset = 0x040000,
65 .size = 0x030000,
66 }, {
67 .name = "linux",
68 .offset = 0x070000,
69 .size = 0x0e0000,
70 }, {
71 .name = "rootfs",
72 .offset = 0x150000,
73 .size = 0x2a0000,
74 }, {
75 .name = "CalibData",
76 .offset = 0x3f0000,
77 .size = 0x010000,
78 .mask_flags = MTD_WRITEABLE,
79 }, {
80 .name = "firmware",
81 .offset = 0x070000,
82 .size = 0x380000,
83 }
84 };
85 #endif /* CONFIG_MTD_PARTITIONS */
86
87 static struct flash_platform_data nbg460n_flash_data = {
88 #ifdef CONFIG_MTD_PARTITIONS
89 .parts = nbg460n_partitions,
90 .nr_parts = ARRAY_SIZE(nbg460n_partitions),
91 #endif
92 };
93
94 static struct gpio_led nbg460n_leds_gpio[] __initdata = {
95 {
96 .name = "nbg460n:green:power",
97 .gpio = NBG460N_GPIO_LED_POWER,
98 .active_low = 0,
99 .default_trigger = "default-on",
100 }, {
101 .name = "nbg460n:green:wps",
102 .gpio = NBG460N_GPIO_LED_WPS,
103 .active_low = 0,
104 }, {
105 .name = "nbg460n:green:wlan",
106 .gpio = NBG460N_GPIO_LED_WLAN,
107 .active_low = 0,
108 }, {
109 /* Not really for controlling the LED,
110 when set low the LED blinks uncontrollable */
111 .name = "nbg460n:green:wan",
112 .gpio = NBG460N_GPIO_LED_WAN,
113 .active_low = 0,
114 }
115 };
116
117 static struct gpio_button nbg460n_gpio_buttons[] __initdata = {
118 {
119 .desc = "reset",
120 .type = EV_KEY,
121 .code = KEY_RESTART,
122 .threshold = 3,
123 .gpio = NBG460N_GPIO_BTN_RESET,
124 .active_low = 1,
125 }, {
126 .desc = "wps",
127 .type = EV_KEY,
128 .code = KEY_WPS_BUTTON,
129 .threshold = 3,
130 .gpio = NBG460N_GPIO_BTN_WPS,
131 .active_low = 1,
132 }
133 };
134
135 static struct i2c_gpio_platform_data nbg460n_i2c_device_platdata = {
136 .sda_pin = NBG460N_GPIO_PCF8563_SDA,
137 .scl_pin = NBG460N_GPIO_PCF8563_SCK,
138 .udelay = 10,
139 };
140
141 static struct platform_device nbg460n_i2c_device = {
142 .name = "i2c-gpio",
143 .id = -1,
144 .num_resources = 0,
145 .resource = NULL,
146 .dev = {
147 .platform_data = &nbg460n_i2c_device_platdata,
148 },
149 };
150
151 static struct i2c_board_info nbg460n_i2c_devs[] __initdata = {
152 {
153 I2C_BOARD_INFO("pcf8563", 0x51),
154 },
155 };
156
157 static void __devinit nbg460n_i2c_init(void)
158 {
159 /* The gpio interface */
160 platform_device_register(&nbg460n_i2c_device);
161 /* I2C devices */
162 i2c_register_board_info(0, nbg460n_i2c_devs,
163 ARRAY_SIZE(nbg460n_i2c_devs));
164 }
165
166
167 static struct rtl8366s_platform_data nbg460n_rtl8366s_data = {
168 .gpio_sda = NBG460N_GPIO_RTL8366_SDA,
169 .gpio_sck = NBG460N_GPIO_RTL8366_SCK,
170 };
171
172 static struct platform_device nbg460n_rtl8366s_device = {
173 .name = RTL8366S_DRIVER_NAME,
174 .id = -1,
175 .dev = {
176 .platform_data = &nbg460n_rtl8366s_data,
177 }
178 };
179
180 static void __init nbg460n_setup(void)
181 {
182 /* end of bootloader sector contains mac address */
183 u8 *mac = (u8 *) KSEG1ADDR(0x1fc0fff8);
184 /* last sector contains wlan calib data */
185 u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
186
187 /* LAN Port */
188 ar71xx_init_mac(ar71xx_eth0_data.mac_addr, mac, 0);
189 ar71xx_eth0_data.mii_bus_dev = &nbg460n_rtl8366s_device.dev;
190 ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
191 ar71xx_eth0_data.speed = SPEED_1000;
192 ar71xx_eth0_data.duplex = DUPLEX_FULL;
193
194 /* WAN Port */
195 ar71xx_init_mac(ar71xx_eth1_data.mac_addr, mac, 1);
196 ar71xx_eth1_data.mii_bus_dev = &nbg460n_rtl8366s_device.dev;
197 ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
198 ar71xx_eth1_data.phy_mask = 0x10;
199
200 ar71xx_add_device_eth(0);
201 ar71xx_add_device_eth(1);
202
203 /* register the switch phy */
204 platform_device_register(&nbg460n_rtl8366s_device);
205
206 /* register flash */
207 ar71xx_add_device_m25p80(&nbg460n_flash_data);
208
209 ar9xxx_add_device_wmac(eeprom, mac);
210
211 /* register RTC chip */
212 nbg460n_i2c_init();
213
214 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(nbg460n_leds_gpio),
215 nbg460n_leds_gpio);
216
217 ar71xx_add_device_gpio_buttons(-1, NBG460N_BUTTONS_POLL_INTERVAL,
218 ARRAY_SIZE(nbg460n_gpio_buttons),
219 nbg460n_gpio_buttons);
220 }
221
222 MIPS_MACHINE(AR71XX_MACH_NBG460N, "NBG460N", "Zyxel NBG460N/550N/550NH",
223 nbg460n_setup);