ar71xx: fix phy_mask for the RB450
[openwrt.git] / target / linux / ar71xx / files / arch / mips / ar71xx / mach-rb4xx.c
1 /*
2  *  MikroTik RouterBOARD 4xx series support
3  *
4  *  Copyright (C) 2008 Gabor Juhos <juhosg@openwrt.org>
5  *  Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
6  *
7  *  This program is free software; you can redistribute it and/or modify it
8  *  under the terms of the GNU General Public License version 2 as published
9  *  by the Free Software Foundation.
10  */
11
12 #include <linux/platform_device.h>
13 #include <linux/irq.h>
14 #include <linux/mmc/host.h>
15 #include <linux/spi/spi.h>
16 #include <linux/spi/flash.h>
17 #include <linux/spi/mmc_spi.h>
18
19 #include <asm/mach-ar71xx/ar71xx.h>
20 #include <asm/mach-ar71xx/pci.h>
21
22 #include "machtype.h"
23 #include "devices.h"
24 #include "dev-gpio-buttons.h"
25 #include "dev-leds-gpio.h"
26 #include "dev-usb.h"
27
28 #define RB4XX_GPIO_USER_LED     4
29 #define RB4XX_GPIO_RESET_SWITCH 7
30
31 #define RB4XX_BUTTONS_POLL_INTERVAL     20
32
33 static struct gpio_led rb4xx_leds_gpio[] __initdata = {
34         {
35                 .name           = "rb4xx:yellow:user",
36                 .gpio           = RB4XX_GPIO_USER_LED,
37                 .active_low     = 0,
38         },
39 };
40
41 static struct gpio_button rb4xx_gpio_buttons[] __initdata = {
42         {
43                 .desc           = "reset_switch",
44                 .type           = EV_KEY,
45                 .code           = KEY_RESTART,
46                 .threshold      = 3,
47                 .gpio           = RB4XX_GPIO_RESET_SWITCH,
48                 .active_low     = 1,
49         }
50 };
51
52 static struct platform_device rb4xx_nand_device = {
53         .name   = "rb4xx-nand",
54         .id     = -1,
55 };
56
57 static struct ar71xx_pci_irq rb4xx_pci_irqs[] __initdata = {
58         {
59                 .slot   = 0,
60                 .pin    = 1,
61                 .irq    = AR71XX_PCI_IRQ_DEV2,
62         }, {
63                 .slot   = 1,
64                 .pin    = 1,
65                 .irq    = AR71XX_PCI_IRQ_DEV0,
66         }, {
67                 .slot   = 1,
68                 .pin    = 2,
69                 .irq    = AR71XX_PCI_IRQ_DEV1,
70         }, {
71                 .slot   = 2,
72                 .pin    = 1,
73                 .irq    = AR71XX_PCI_IRQ_DEV1,
74         }, {
75                 .slot   = 3,
76                 .pin    = 1,
77                 .irq    = AR71XX_PCI_IRQ_DEV2,
78         }
79 };
80
81 #if 0
82 /*
83  * SPI device support is experimental
84  */
85 static struct flash_platform_data rb4xx_flash_data = {
86         .type   = "pm25lv512",
87 };
88
89 static struct spi_board_info rb4xx_spi_info[] = {
90         {
91                 .bus_num        = 0,
92                 .chip_select    = 0,
93                 .max_speed_hz   = 25000000,
94                 .modalias       = "m25p80",
95                 .platform_data  = &rb4xx_flash_data,
96         }
97 };
98
99 static struct mmc_spi_platform_data rb433_mmc_data = {
100         .ocr_mask       = MMC_VDD_32_33 | MMC_VDD_33_34,
101 };
102
103 static struct spi_board_info rb433_spi_info[] = {
104         {
105                 .bus_num        = 0,
106                 .chip_select    = 0,
107                 .max_speed_hz   = 25000000,
108                 .modalias       = "m25p80",
109                 .platform_data  = &rb433_flash_data,
110         }, {
111                 .bus_num        = 0,
112                 .chip_select    = 2,
113                 .max_speed_hz   = 25000000,
114                 .modalias       = "mmc_spi",
115                 .platform_data  = &rb433_mmc_data,
116         }
117 };
118
119 static u32 rb433_spi_get_ioc_base(u8 chip_select, int cs_high, int is_on)
120 {
121         u32 ret;
122
123         if (is_on == AR71XX_SPI_CS_INACTIVE) {
124                 ret = SPI_IOC_CS0 | SPI_IOC_CS1;
125         } else {
126                 if (cs_high) {
127                         ret = SPI_IOC_CS0 | SPI_IOC_CS1;
128                 } else {
129                         if ((chip_select ^ 2) == 0)
130                                 ret = SPI_IOC_CS1 ^ (SPI_IOC_CS0 | SPI_IOC_CS1);
131                         else
132                                 ret = SPI_IOC_CS0 ^ (SPI_IOC_CS0 | SPI_IOC_CS1);
133                 }
134         }
135
136         return ret;
137 }
138
139 struct ar71xx_spi_platform_data rb433_spi_data = {
140         .bus_num                = 0,
141         .num_chipselect         = 3,
142         .get_ioc_base           = rb433_spi_get_ioc_base,
143 };
144
145 static void rb4xx_add_device_spi(void)
146 {
147         ar71xx_add_device_spi(NULL, rb4xx_spi_info, ARRAY_SIZE(rb4xx_spi_info));
148 }
149
150 static void rb433_add_device_spi(void)
151 {
152         ar71xx_add_device_spi(&rb433_spi_data, rb433_spi_info,
153                                 ARRAY_SIZE(rb433_spi_info));
154 }
155 #else
156 static inline void rb4xx_add_device_spi(void) {}
157 static inline void rb433_add_device_spi(void) {}
158 #endif
159
160 static void __init rb4xx_generic_setup(void)
161 {
162         ar71xx_gpio_function_enable(AR71XX_GPIO_FUNC_SPI_CS1_EN |
163                                     AR71XX_GPIO_FUNC_SPI_CS2_EN);
164
165         ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(rb4xx_leds_gpio),
166                                         rb4xx_leds_gpio);
167
168         ar71xx_add_device_gpio_buttons(-1, RB4XX_BUTTONS_POLL_INTERVAL,
169                                         ARRAY_SIZE(rb4xx_gpio_buttons),
170                                         rb4xx_gpio_buttons);
171
172         platform_device_register(&rb4xx_nand_device);
173 }
174
175 static void __init rb411_setup(void)
176 {
177         rb4xx_generic_setup();
178         rb4xx_add_device_spi();
179
180         ar71xx_add_device_mdio(0xfffffffc);
181
182         ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
183         ar71xx_eth0_data.phy_mask = 0x00000003;
184
185         ar71xx_add_device_eth(0);
186
187         ar71xx_pci_init(ARRAY_SIZE(rb4xx_pci_irqs), rb4xx_pci_irqs);
188 }
189
190 MIPS_MACHINE(AR71XX_MACH_RB_411, "411", "MikroTik RouterBOARD 411/A/AH",
191              rb411_setup);
192
193 static void __init rb411u_setup(void)
194 {
195         rb411_setup();
196         ar71xx_add_device_usb();
197 }
198
199 MIPS_MACHINE(AR71XX_MACH_RB_411U, "411U", "MikroTik RouterBOARD 411U",
200              rb411u_setup);
201
202 #define RB433_LAN_PHYMASK       BIT(0)
203 #define RB433_WAN_PHYMASK       BIT(4)
204 #define RB433_MDIO_PHYMASK      (RB433_LAN_PHYMASK | RB433_WAN_PHYMASK)
205
206 static void __init rb433_setup(void)
207 {
208         rb4xx_generic_setup();
209         rb433_add_device_spi();
210
211         ar71xx_add_device_mdio(~RB433_MDIO_PHYMASK);
212
213         ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
214         ar71xx_eth0_data.phy_mask = RB433_LAN_PHYMASK;
215
216         ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
217         ar71xx_eth1_data.phy_mask = RB433_WAN_PHYMASK;
218
219         ar71xx_add_device_eth(1);
220         ar71xx_add_device_eth(0);
221
222         ar71xx_pci_init(ARRAY_SIZE(rb4xx_pci_irqs), rb4xx_pci_irqs);
223 }
224
225 MIPS_MACHINE(AR71XX_MACH_RB_433, "433", "MikroTik RouterBOARD 433/AH",
226              rb433_setup);
227
228 static void __init rb433u_setup(void)
229 {
230         rb433_setup();
231         ar71xx_add_device_usb();
232 }
233
234 MIPS_MACHINE(AR71XX_MACH_RB_433U, "433U", "MikroTik RouterBOARD 433UAH",
235              rb433u_setup);
236
237 #define RB450_LAN_PHYMASK       BIT(0)
238 #define RB450_WAN_PHYMASK       BIT(4)
239 #define RB450_MDIO_PHYMASK      (RB450_LAN_PHYMASK | RB450_WAN_PHYMASK)
240
241 static void __init rb450_generic_setup(int gige)
242 {
243         rb4xx_generic_setup();
244         rb4xx_add_device_spi();
245
246         ar71xx_add_device_mdio(~RB450_MDIO_PHYMASK);
247
248         ar71xx_eth0_data.phy_if_mode = (gige) ? PHY_INTERFACE_MODE_RGMII : PHY_INTERFACE_MODE_MII;
249         ar71xx_eth0_data.phy_mask = RB450_LAN_PHYMASK;
250
251         ar71xx_eth1_data.phy_if_mode = (gige) ? PHY_INTERFACE_MODE_RGMII : PHY_INTERFACE_MODE_RMII;
252         ar71xx_eth1_data.phy_mask = RB450_WAN_PHYMASK;
253
254         ar71xx_add_device_eth(1);
255         ar71xx_add_device_eth(0);
256 }
257
258 static void __init rb450_setup(void)
259 {
260         rb450_generic_setup(0);
261 }
262
263 MIPS_MACHINE(AR71XX_MACH_RB_450, "450", "MikroTik RouterBOARD 450",
264              rb450_setup);
265
266 static void __init rb450g_setup(void)
267 {
268         rb450_generic_setup(1);
269 }
270
271 MIPS_MACHINE(AR71XX_MACH_RB_450G, "450G", "MikroTik RouterBOARD 450G",
272              rb450g_setup);
273
274 static void __init rb493_setup(void)
275 {
276         rb4xx_generic_setup();
277         rb4xx_add_device_spi();
278
279         ar71xx_add_device_mdio(0x3fffff00);
280
281         ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
282         ar71xx_eth0_data.speed = SPEED_100;
283         ar71xx_eth0_data.duplex = DUPLEX_FULL;
284
285         ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
286         ar71xx_eth1_data.phy_mask = 0x00000001;
287
288         ar71xx_add_device_eth(0);
289         ar71xx_add_device_eth(1);
290
291         ar71xx_pci_init(ARRAY_SIZE(rb4xx_pci_irqs), rb4xx_pci_irqs);
292 }
293
294 MIPS_MACHINE(AR71XX_MACH_RB_493, "493", "MikroTik RouterBOARD 493/AH",
295              rb493_setup);