backfire: ar71xx: fixes some stuffs for TP-LINK TL-MR3420
[openwrt-10.03/.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-pci.h"
21 #include "dev-gpio-buttons.h"
22 #include "dev-leds-gpio.h"
23 #include "dev-usb.h"
24
25 #define TL_MR3420_GPIO_LED_QSS          0
26 #define TL_MR3420_GPIO_LED_SYSTEM       1
27 #define TL_MR3420_GPIO_LED_3G           8
28
29 #define TL_MR3420_GPIO_BTN_RESET        11
30 #define TL_MR3420_GPIO_BTN_QSS          12
31
32 #define TL_MR3420_GPIO_USB_POWER        6
33
34 #define TL_MR3420_BUTTONS_POLL_INTERVAL 20
35
36 #ifdef CONFIG_MTD_PARTITIONS
37 static struct mtd_partition tl_mr3420_partitions[] = {
38         {
39                 .name           = "u-boot",
40                 .offset         = 0,
41                 .size           = 0x020000,
42                 .mask_flags     = MTD_WRITEABLE,
43         }, {
44                 .name           = "kernel",
45                 .offset         = 0x020000,
46                 .size           = 0x140000,
47         }, {
48                 .name           = "rootfs",
49                 .offset         = 0x160000,
50                 .size           = 0x290000,
51         }, {
52                 .name           = "art",
53                 .offset         = 0x3f0000,
54                 .size           = 0x010000,
55                 .mask_flags     = MTD_WRITEABLE,
56         }, {
57                 .name           = "firmware",
58                 .offset         = 0x020000,
59                 .size           = 0x3d0000,
60         }
61 };
62 #define tl_mr3420_num_partitions        ARRAY_SIZE(tl_mr3420_partitions)
63 #else
64 #define tl_mr3420_partitions            NULL
65 #define tl_mr3420_num_partitions        0
66 #endif /* CONFIG_MTD_PARTITIONS */
67
68 static struct flash_platform_data tl_mr3420_flash_data = {
69         .parts          = tl_mr3420_partitions,
70         .nr_parts       = tl_mr3420_num_partitions,
71 };
72
73 static struct gpio_led tl_mr3420_leds_gpio[] __initdata = {
74         {
75                 .name           = "tl-mr3420:green:system",
76                 .gpio           = TL_MR3420_GPIO_LED_SYSTEM,
77                 .active_low     = 1,
78         }, {
79                 .name           = "tl-mr3420:green:qss",
80                 .gpio           = TL_MR3420_GPIO_LED_QSS,
81                 .active_low     = 1,
82         }, {
83                 .name           = "tl-mr3420:green:3g",
84                 .gpio           = TL_MR3420_GPIO_LED_3G,
85                 .active_low     = 1,
86         }
87 };
88
89 static struct gpio_button tl_mr3420_gpio_buttons[] __initdata = {
90         {
91                 .desc           = "reset",
92                 .type           = EV_KEY,
93                 .code           = BTN_0,
94                 .threshold      = 3,
95                 .gpio           = TL_MR3420_GPIO_BTN_RESET,
96                 .active_low     = 1,
97         }, {
98                 .desc           = "qss",
99                 .type           = EV_KEY,
100                 .code           = BTN_1,
101                 .threshold      = 3,
102                 .gpio           = TL_MR3420_GPIO_BTN_QSS,
103                 .active_low     = 1,
104         }
105 };
106
107 static void __init tl_mr3420_setup(void)
108 {
109         u8 *mac = (u8 *) KSEG1ADDR(0x1f01fc00);
110         u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
111
112         /* enable power for the USB port */
113         gpio_request(TL_MR3420_GPIO_USB_POWER, "USB power");
114         gpio_direction_output(TL_MR3420_GPIO_USB_POWER, 1);
115
116         ar71xx_add_device_m25p80(&tl_mr3420_flash_data);
117
118         ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(tl_mr3420_leds_gpio),
119                                         tl_mr3420_leds_gpio);
120
121         ar71xx_add_device_gpio_buttons(-1, TL_MR3420_BUTTONS_POLL_INTERVAL,
122                                         ARRAY_SIZE(tl_mr3420_gpio_buttons),
123                                         tl_mr3420_gpio_buttons);
124
125         ar71xx_eth1_data.has_ar7240_switch = 1;
126         ar71xx_set_mac_base(mac);
127
128         /* WAN port */
129         ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
130         ar71xx_eth0_data.speed = SPEED_100;
131         ar71xx_eth0_data.duplex = DUPLEX_FULL;
132         ar71xx_eth0_data.phy_mask = BIT(4);
133
134         /* LAN ports */
135         ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
136         ar71xx_eth1_data.speed = SPEED_1000;
137         ar71xx_eth1_data.duplex = DUPLEX_FULL;
138
139         ar71xx_add_device_mdio(0x0);
140         ar71xx_add_device_eth(1);
141         ar71xx_add_device_eth(0);
142
143         ar71xx_add_device_usb();
144
145         ap91_pci_setup_wmac_led_pin(0);
146
147         ap91_pci_init(ee, mac);
148 }
149
150 MIPS_MACHINE(AR71XX_MACH_TL_MR3420, "TL-MR3420", "TP-LINK TL-MR3420",
151              tl_mr3420_setup);