ar71xx: add an id argument to ar71xx_add_device_mdio
[lede.git] / target / linux / ar71xx / files / arch / mips / ar71xx / mach-tl-mr3x20.c
1 /*
2  *  TP-LINK TL-MR3220/3420 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_MR3X20_GPIO_LED_QSS          0
26 #define TL_MR3X20_GPIO_LED_SYSTEM       1
27 #define TL_MR3X20_GPIO_LED_3G           8
28
29 #define TL_MR3X20_GPIO_BTN_RESET        11
30 #define TL_MR3X20_GPIO_BTN_QSS          12
31
32 #define TL_MR3X20_GPIO_USB_POWER        6
33
34 #define TL_MR3X20_KEYS_POLL_INTERVAL    20      /* msecs */
35 #define TL_MR3X20_KEYS_DEBOUNCE_INTERVAL (3 * TL_MR3X20_KEYS_POLL_INTERVAL)
36
37 #ifdef CONFIG_MTD_PARTITIONS
38 static struct mtd_partition tl_mr3x20_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_mr3x20_num_partitions        ARRAY_SIZE(tl_mr3x20_partitions)
64 #else
65 #define tl_mr3x20_partitions            NULL
66 #define tl_mr3x20_num_partitions        0
67 #endif /* CONFIG_MTD_PARTITIONS */
68
69 static struct flash_platform_data tl_mr3x20_flash_data = {
70         .parts          = tl_mr3x20_partitions,
71         .nr_parts       = tl_mr3x20_num_partitions,
72 };
73
74 static struct gpio_led tl_mr3x20_leds_gpio[] __initdata = {
75         {
76                 .name           = "tp-link:green:system",
77                 .gpio           = TL_MR3X20_GPIO_LED_SYSTEM,
78                 .active_low     = 1,
79         }, {
80                 .name           = "tp-link:green:qss",
81                 .gpio           = TL_MR3X20_GPIO_LED_QSS,
82                 .active_low     = 1,
83         }, {
84                 .name           = "tp-link:green:3g",
85                 .gpio           = TL_MR3X20_GPIO_LED_3G,
86                 .active_low     = 1,
87         }
88 };
89
90 static struct gpio_keys_button tl_mr3x20_gpio_keys[] __initdata = {
91         {
92                 .desc           = "reset",
93                 .type           = EV_KEY,
94                 .code           = KEY_RESTART,
95                 .debounce_interval = TL_MR3X20_KEYS_DEBOUNCE_INTERVAL,
96                 .gpio           = TL_MR3X20_GPIO_BTN_RESET,
97                 .active_low     = 1,
98         }, {
99                 .desc           = "qss",
100                 .type           = EV_KEY,
101                 .code           = KEY_WPS_BUTTON,
102                 .debounce_interval = TL_MR3X20_KEYS_DEBOUNCE_INTERVAL,
103                 .gpio           = TL_MR3X20_GPIO_BTN_QSS,
104                 .active_low     = 1,
105         }
106 };
107
108 static void __init tl_mr3x20_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_MR3X20_GPIO_USB_POWER, "USB power");
115         gpio_direction_output(TL_MR3X20_GPIO_USB_POWER, 1);
116
117         ar71xx_add_device_m25p80(&tl_mr3x20_flash_data);
118
119         ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(tl_mr3x20_leds_gpio),
120                                         tl_mr3x20_leds_gpio);
121
122         ar71xx_register_gpio_keys_polled(-1, TL_MR3X20_KEYS_POLL_INTERVAL,
123                                          ARRAY_SIZE(tl_mr3x20_gpio_keys),
124                                          tl_mr3x20_gpio_keys);
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         ar71xx_eth0_data.phy_mask = BIT(4);
135
136         /* LAN ports */
137         ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
138         ar71xx_eth1_data.speed = SPEED_1000;
139         ar71xx_eth1_data.duplex = DUPLEX_FULL;
140
141         ar71xx_add_device_mdio(0, 0x0);
142         ar71xx_add_device_eth(1);
143         ar71xx_add_device_eth(0);
144
145         ar71xx_add_device_usb();
146
147         ap91_pci_init(ee, mac);
148 }
149
150 static void __init tl_mr3220_setup(void)
151 {
152         tl_mr3x20_setup();
153         ap91_pci_setup_wmac_led_pin(1);
154 }
155
156 MIPS_MACHINE(AR71XX_MACH_TL_MR3220, "TL-MR3220", "TP-LINK TL-MR3220",
157              tl_mr3220_setup);
158
159 static void __init tl_mr3420_setup(void)
160 {
161         tl_mr3x20_setup();
162         ap91_pci_setup_wmac_led_pin(0);
163 }
164
165 MIPS_MACHINE(AR71XX_MACH_TL_MR3420, "TL-MR3420", "TP-LINK TL-MR3420",
166              tl_mr3420_setup);