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

Archive Download this file



interactive