Root/target/linux/ramips/files/arch/mips/ralink/rt305x/mach-wr512-3gn.c

1/*
2 * Unbranded router from DX board support
3 * Also known as *WR512*-3GN by local vendors
4 * e.g. WS-WR512N1, Sin Hon SH-WR512NU, and etc
5 * (http://www.dealextreme.com/p/portable-wireless-n-3g-router-cdma2000-evdo-td-scdma-hspa-wcdma-45639)
6 * This router is also known to be rebranded and sold by a number of local
7 * vendors in several countries.
8 *
9 * Copyright (C) 2011 Andrew Andrianov <necromant@necromant.ath.cx>
10 * Based on MOFI3500-3N code by
11 * Copyright (C) 2011 Layne Edwards <ledwards76@gmail.com>
12 *
13 *
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License version 2 as published
16 * by the Free Software Foundation.
17 */
18
19#include <linux/init.h>
20#include <linux/platform_device.h>
21#include <linux/mtd/mtd.h>
22#include <linux/mtd/partitions.h>
23#include <linux/mtd/physmap.h>
24
25#include <asm/mach-ralink/machine.h>
26#include <asm/mach-ralink/dev-gpio-buttons.h>
27#include <asm/mach-ralink/dev-gpio-leds.h>
28#include <asm/mach-ralink/rt305x.h>
29#include <asm/mach-ralink/rt305x_regs.h>
30
31#include "devices.h"
32
33
34#define WR512_3GN_GPIO_LED_3G 9
35#define WR512_3GN_GPIO_LED_GATEWAY 11
36#define WR512_3GN_GPIO_LED_AP 12
37#define WR512_3GN_GPIO_LED_STATION 13
38#define WR512_3GN_GPIO_LED_WPS 14
39
40#define WR512_3GN_GPIO_BUTTON_RESET 10
41#define WR512_3GN_GPIO_BUTTON_CONNECT 7
42#define WR512_3GN_GPIO_BUTTON_WPS 0
43#define WR512_3GN_GPIO_BUTTON_WPS2 8
44
45#define WR512_3GN_BUTTONS_POLL_INTERVAL 20
46
47#ifdef CONFIG_MTD_PARTITIONS
48
49static struct mtd_partition wr512_3gn_partitions[] = {
50    {
51        .name = "u-boot",
52        .offset = 0,
53        .size = 0x030000,
54        .mask_flags = MTD_WRITEABLE,
55    }, {
56        .name = "devdata",
57        .offset = 0x030000,
58        .size = 0x010000,
59        .mask_flags = MTD_WRITEABLE,
60    }, {
61        .name = "devconf",
62        .offset = 0x040000,
63        .size = 0x010000,
64        .mask_flags = MTD_WRITEABLE,
65    }, {
66        .name = "kernel",
67        .offset = 0x050000,
68        .size = 0x0d0000,
69    }, {
70        .name = "rootfs",
71        .offset = 0x120000,
72        .size = 0x2e0000,
73    }, {
74        .name = "firmware",
75        .offset = 0x050000,
76        .size = 0x3b0000,
77    }
78};
79
80#endif /* CONFIG_MTD_PARTITIONS */
81
82static struct physmap_flash_data wr512_3gn_flash_data = {
83#ifdef CONFIG_MTD_PARTITIONS
84    .nr_parts = ARRAY_SIZE(wr512_3gn_partitions),
85    .parts = wr512_3gn_partitions,
86#endif
87};
88
89static struct gpio_led wr512_3gn_leds_gpio[] __initdata = {
90    {
91        .name = "wr512:green:3g",
92        .gpio = WR512_3GN_GPIO_LED_3G,
93        .active_low = 1,
94    }, {
95        .name = "wr512:green:gateway",
96        .gpio = WR512_3GN_GPIO_LED_GATEWAY,
97        .active_low = 1,
98    }, {
99        .name = "wr512:green:ap",
100        .gpio = WR512_3GN_GPIO_LED_AP,
101        .active_low = 1,
102    }, {
103        .name = "wr512:green:wps",
104        .gpio = WR512_3GN_GPIO_LED_WPS,
105        .active_low = 1,
106    }, {
107        .name = "wr512:green:station",
108        .gpio = WR512_3GN_GPIO_LED_STATION,
109        .active_low = 1,
110    }
111};
112
113static struct gpio_button wr512_3gn_gpio_buttons[] __initdata = {
114    {
115        .desc = "reset_wps",
116        .type = EV_KEY,
117        .code = KEY_RESTART,
118        .threshold = 3,
119        .gpio = WR512_3GN_GPIO_BUTTON_RESET,
120        .active_low = 1,
121    }, {
122        .desc = "mode",
123        .type = EV_KEY,
124        .code = KEY_M,
125        .threshold = 3,
126        .gpio = WR512_3GN_GPIO_BUTTON_CONNECT,
127        .active_low = 1,
128    }
129};
130
131#define WR512_3GN_GPIO_MODE \
132    ((RT305X_GPIO_MODE_GPIO << RT305X_GPIO_MODE_UART0_SHIFT) | \
133     RT305X_GPIO_MODE_MDIO)
134
135static void __init wr512_3gn_init(void)
136{
137    rt305x_gpio_init(WR512_3GN_GPIO_MODE);
138
139    rt305x_register_flash(0, &wr512_3gn_flash_data);
140    rt305x_esw_data.vlan_config = RT305X_ESW_VLAN_CONFIG_LLLLW;
141    rt305x_register_ethernet();
142    ramips_register_gpio_leds(-1, ARRAY_SIZE(wr512_3gn_leds_gpio),
143                  wr512_3gn_leds_gpio);
144    ramips_register_gpio_buttons(-1, WR512_3GN_BUTTONS_POLL_INTERVAL,
145                     ARRAY_SIZE(wr512_3gn_gpio_buttons),
146                     wr512_3gn_gpio_buttons);
147    rt305x_register_wifi();
148    rt305x_register_wdt();
149    rt305x_register_usb();
150}
151
152MIPS_MACHINE(RAMIPS_MACH_WR512_3GN, "WR512-3GN", "WR512-3GN-like router",
153          wr512_3gn_init);
154

Archive Download this file



interactive