ar71xx: Add support for the OMYlink OMY-X1
[openwrt/openwrt.git] / target / linux / ar71xx / files / arch / mips / ath79 / 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/delay.h>
14 #include <linux/i2c.h>
15 #include <linux/i2c-algo-bit.h>
16 #include <linux/i2c-gpio.h>
17 #include <linux/mtd/mtd.h>
18 #include <linux/mtd/partitions.h>
19 #include <linux/platform_device.h>
20 #include <linux/rtl8366.h>
21
22 #include <asm/mach-ath79/ath79.h>
23
24 #include "dev-eth.h"
25 #include "dev-gpio-buttons.h"
26 #include "dev-leds-gpio.h"
27 #include "dev-m25p80.h"
28 #include "dev-wmac.h"
29 #include "machtypes.h"
30
31 /* LEDs */
32 #define NBG460N_GPIO_LED_WPS 3
33 #define NBG460N_GPIO_LED_WAN 6
34 #define NBG460N_GPIO_LED_POWER 14
35 #define NBG460N_GPIO_LED_WLAN 15
36
37 /* Buttons */
38 #define NBG460N_GPIO_BTN_WPS 12
39 #define NBG460N_GPIO_BTN_RESET 21
40
41 #define NBG460N_KEYS_POLL_INTERVAL 20 /* msecs */
42 #define NBG460N_KEYS_DEBOUNCE_INTERVAL (3 * NBG460N_KEYS_POLL_INTERVAL)
43
44 /* RTC chip PCF8563 I2C interface */
45 #define NBG460N_GPIO_PCF8563_SDA 8
46 #define NBG460N_GPIO_PCF8563_SCK 7
47
48 /* Switch configuration I2C interface */
49 #define NBG460N_GPIO_RTL8366_SDA 16
50 #define NBG460N_GPIO_RTL8366_SCK 18
51
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
86 static struct flash_platform_data nbg460n_flash_data = {
87 .parts = nbg460n_partitions,
88 .nr_parts = ARRAY_SIZE(nbg460n_partitions),
89 };
90
91 static struct gpio_led nbg460n_leds_gpio[] __initdata = {
92 {
93 .name = "nbg460n:green:power",
94 .gpio = NBG460N_GPIO_LED_POWER,
95 .active_low = 0,
96 .default_trigger = "default-on",
97 }, {
98 .name = "nbg460n:green:wps",
99 .gpio = NBG460N_GPIO_LED_WPS,
100 .active_low = 0,
101 }, {
102 .name = "nbg460n:green:wlan",
103 .gpio = NBG460N_GPIO_LED_WLAN,
104 .active_low = 0,
105 }, {
106 /* Not really for controlling the LED,
107 when set low the LED blinks uncontrollable */
108 .name = "nbg460n:green:wan",
109 .gpio = NBG460N_GPIO_LED_WAN,
110 .active_low = 0,
111 }
112 };
113
114 static struct gpio_keys_button nbg460n_gpio_keys[] __initdata = {
115 {
116 .desc = "reset",
117 .type = EV_KEY,
118 .code = KEY_RESTART,
119 .debounce_interval = NBG460N_KEYS_DEBOUNCE_INTERVAL,
120 .gpio = NBG460N_GPIO_BTN_RESET,
121 .active_low = 1,
122 }, {
123 .desc = "wps",
124 .type = EV_KEY,
125 .code = KEY_WPS_BUTTON,
126 .debounce_interval = NBG460N_KEYS_DEBOUNCE_INTERVAL,
127 .gpio = NBG460N_GPIO_BTN_WPS,
128 .active_low = 1,
129 }
130 };
131
132 static struct i2c_gpio_platform_data nbg460n_i2c_device_platdata = {
133 .sda_pin = NBG460N_GPIO_PCF8563_SDA,
134 .scl_pin = NBG460N_GPIO_PCF8563_SCK,
135 .udelay = 10,
136 };
137
138 static struct platform_device nbg460n_i2c_device = {
139 .name = "i2c-gpio",
140 .id = -1,
141 .num_resources = 0,
142 .resource = NULL,
143 .dev = {
144 .platform_data = &nbg460n_i2c_device_platdata,
145 },
146 };
147
148 static struct i2c_board_info nbg460n_i2c_devs[] __initdata = {
149 {
150 I2C_BOARD_INFO("pcf8563", 0x51),
151 },
152 };
153
154 static void nbg460n_i2c_init(void)
155 {
156 /* The gpio interface */
157 platform_device_register(&nbg460n_i2c_device);
158 /* I2C devices */
159 i2c_register_board_info(0, nbg460n_i2c_devs,
160 ARRAY_SIZE(nbg460n_i2c_devs));
161 }
162
163
164 static struct rtl8366_platform_data nbg460n_rtl8366s_data = {
165 .gpio_sda = NBG460N_GPIO_RTL8366_SDA,
166 .gpio_sck = NBG460N_GPIO_RTL8366_SCK,
167 };
168
169 static struct platform_device nbg460n_rtl8366s_device = {
170 .name = RTL8366S_DRIVER_NAME,
171 .id = -1,
172 .dev = {
173 .platform_data = &nbg460n_rtl8366s_data,
174 }
175 };
176
177 static void __init nbg460n_setup(void)
178 {
179 /* end of bootloader sector contains mac address */
180 u8 *mac = (u8 *) KSEG1ADDR(0x1fc0fff8);
181 /* last sector contains wlan calib data */
182 u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
183
184 /* LAN Port */
185 ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
186 ath79_eth0_data.mii_bus_dev = &nbg460n_rtl8366s_device.dev;
187 ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
188 ath79_eth0_data.speed = SPEED_1000;
189 ath79_eth0_data.duplex = DUPLEX_FULL;
190
191 /* WAN Port */
192 ath79_init_mac(ath79_eth1_data.mac_addr, mac, 1);
193 ath79_eth1_data.mii_bus_dev = &nbg460n_rtl8366s_device.dev;
194 ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
195 ath79_eth1_data.phy_mask = 0x10;
196
197 ath79_register_eth(0);
198 ath79_register_eth(1);
199
200 /* register the switch phy */
201 platform_device_register(&nbg460n_rtl8366s_device);
202
203 /* register flash */
204 ath79_register_m25p80(&nbg460n_flash_data);
205
206 ath79_register_wmac(eeprom, mac);
207
208 /* register RTC chip */
209 nbg460n_i2c_init();
210
211 ath79_register_leds_gpio(-1, ARRAY_SIZE(nbg460n_leds_gpio),
212 nbg460n_leds_gpio);
213
214 ath79_register_gpio_keys_polled(-1, NBG460N_KEYS_POLL_INTERVAL,
215 ARRAY_SIZE(nbg460n_gpio_keys),
216 nbg460n_gpio_keys);
217 }
218
219 MIPS_MACHINE(ATH79_MACH_NBG460N, "NBG460N", "Zyxel NBG460N/550N/550NH",
220 nbg460n_setup);