ar71xx: add support for the TL-MR3420 v1 board
[openwrt.git] / target / linux / ar71xx / files / arch / mips / ar71xx / mach-tl-mr3420.c
1 /*
2  *  TP-LINK TL-MR3420 board support
3  *
4  *  Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org>
5  *
6  *  This program is free software; you can redistribute it and/or modify it
7  *  under the terms of the GNU General Public License version 2 as published
8  *  by the Free Software Foundation.
9  */
10
11 #include <linux/gpio.h>
12 #include <linux/mtd/mtd.h>
13 #include <linux/mtd/partitions.h>
14
15 #include <asm/mach-ar71xx/ar71xx.h>
16
17 #include "machtype.h"
18 #include "devices.h"
19 #include "dev-m25p80.h"
20 #include "dev-ap91-eth.h"
21 #include "dev-ap91-pci.h"
22 #include "dev-gpio-buttons.h"
23 #include "dev-leds-gpio.h"
24 #include "dev-usb.h"
25
26 #define TL_MR3420_GPIO_LED_QSS          0
27 #define TL_MR3420_GPIO_LED_SYSTEM       1
28 #define TL_MR3420_GPIO_LED_3G           8
29
30 #define TL_MR3420_GPIO_BTN_RESET        11
31 #define TL_MR3420_GPIO_BTN_QSS          12
32
33 #define TL_MR3420_GPIO_USB_POWER        6
34
35 #define TL_MR3420_BUTTONS_POLL_INTERVAL 20
36
37 #ifdef CONFIG_MTD_PARTITIONS
38 static struct mtd_partition tl_mr3420_partitions[] = {
39         {
40                 .name           = "u-boot",
41                 .offset         = 0,
42                 .size           = 0x020000,
43                 .mask_flags     = MTD_WRITEABLE,
44         } , {
45                 .name           = "kernel",
46                 .offset         = 0x020000,
47                 .size           = 0x140000,
48         } , {
49                 .name           = "rootfs",
50                 .offset         = 0x160000,
51                 .size           = 0x290000,
52         } , {
53                 .name           = "art",
54                 .offset         = 0x3f0000,
55                 .size           = 0x010000,
56                 .mask_flags     = MTD_WRITEABLE,
57         } , {
58                 .name           = "firmware",
59                 .offset         = 0x020000,
60                 .size           = 0x3d0000,
61         }
62 };
63 #define tl_mr3420_num_partitions        ARRAY_SIZE(tl_mr3420_partitions)
64 #else
65 #define tl_mr3420_partitions            NULL
66 #define tl_mr3420_num_partitions        0
67 #endif /* CONFIG_MTD_PARTITIONS */
68
69 static struct flash_platform_data tl_mr3420_flash_data = {
70         .parts          = tl_mr3420_partitions,
71         .nr_parts       = tl_mr3420_num_partitions,
72 };
73
74 static struct gpio_led tl_mr3420_leds_gpio[] __initdata = {
75         {
76                 .name           = "tl-mr3420:green:system",
77                 .gpio           = TL_MR3420_GPIO_LED_SYSTEM,
78                 .active_low     = 1,
79         }, {
80                 .name           = "tl-mr3420:green:qss",
81                 .gpio           = TL_MR3420_GPIO_LED_QSS,
82                 .active_low     = 1,
83         }, {
84                 .name           = "tl-mr3420:green:3g",
85                 .gpio           = TL_MR3420_GPIO_LED_3G,
86                 .active_low     = 1,
87         }
88 };
89
90 static struct gpio_button tl_mr3420_gpio_buttons[] __initdata = {
91         {
92                 .desc           = "reset",
93                 .type           = EV_KEY,
94                 .code           = KEY_RESTART,
95                 .threshold      = 3,
96                 .gpio           = TL_MR3420_GPIO_BTN_RESET,
97                 .active_low     = 1,
98         }, {
99                 .desc           = "qss",
100                 .type           = EV_KEY,
101                 .code           = KEY_WPS_BUTTON,
102                 .threshold      = 3,
103                 .gpio           = TL_MR3420_GPIO_BTN_QSS,
104                 .active_low     = 1,
105         }
106 };
107
108 static void __init tl_mr3420_setup(void)
109 {
110         u8 *mac = (u8 *) KSEG1ADDR(0x1f01fc00);
111         u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
112
113         /* enable power for the USB port */
114         gpio_request(TL_MR3420_GPIO_USB_POWER,"USB power");
115         gpio_direction_output(TL_MR3420_GPIO_USB_POWER, 1);
116
117         ar71xx_add_device_m25p80(&tl_mr3420_flash_data);
118
119         ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(tl_mr3420_leds_gpio),
120                                         tl_mr3420_leds_gpio);
121
122         ar71xx_add_device_gpio_buttons(-1, TL_MR3420_BUTTONS_POLL_INTERVAL,
123                                         ARRAY_SIZE(tl_mr3420_gpio_buttons),
124                                         tl_mr3420_gpio_buttons);
125
126         ar71xx_eth1_data.has_ar7240_switch = 1;
127         ar71xx_init_mac(ar71xx_eth0_data.mac_addr, mac, 0);
128         ar71xx_init_mac(ar71xx_eth1_data.mac_addr, mac, 1);
129
130         /* WAN port */
131         ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
132         ar71xx_eth0_data.speed = SPEED_100;
133         ar71xx_eth0_data.duplex = DUPLEX_FULL;
134
135         /* LAN ports */
136         ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
137         ar71xx_eth1_data.speed = SPEED_1000;
138         ar71xx_eth1_data.duplex = DUPLEX_FULL;
139
140         ar71xx_add_device_mdio(0x0);
141         ar71xx_add_device_eth(1);
142         ar71xx_add_device_eth(0);
143
144         ar71xx_add_device_usb();
145
146         ap91_pci_init(ee, mac);
147 }
148 MIPS_MACHINE(AR71XX_MACH_TL_MR3420, "TL-MR3420", "TP-LINK TL-MR3420",
149              tl_mr3420_setup);