[ar71xx] ethernet driver updates
[openwrt/svn-archive/archive.git] / target / linux / ar71xx / files / arch / mips / ar71xx / mach-rb-4xx.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 #include <linux/leds.h>
19
20 #include <asm/mips_machine.h>
21 #include <asm/mach-ar71xx/ar71xx.h>
22 #include <asm/mach-ar71xx/pci.h>
23 #include <asm/mach-ar71xx/platform.h>
24
25 #define RB4XX_GPIO_USER_LED 4
26
27 static struct gpio_led rb4xx_leds_gpio[] = {
28 {
29 .name = "rb4xx:yellow:user",
30 .gpio = RB4XX_GPIO_USER_LED,
31 .active_low = 0,
32 },
33 };
34
35 static struct gpio_led_platform_data rb4xx_leds_gpio_data = {
36 .leds = rb4xx_leds_gpio,
37 .num_leds = ARRAY_SIZE(rb4xx_leds_gpio),
38 };
39
40 static struct platform_device rb4xx_leds_gpio_device = {
41 .name = "leds-gpio",
42 .id = -1,
43 .dev = {
44 .platform_data = &rb4xx_leds_gpio_data,
45 }
46 };
47
48 static struct platform_device rb4xx_nand_device = {
49 .name = "rb4xx-nand",
50 .id = -1,
51 };
52
53 static struct ar71xx_pci_irq rb4xx_pci_irqs[] __initdata = {
54 {
55 .slot = 1,
56 .pin = 1,
57 .irq = AR71XX_PCI_IRQ_DEV0,
58 }, {
59 .slot = 1,
60 .pin = 2,
61 .irq = AR71XX_PCI_IRQ_DEV1,
62 }, {
63 .slot = 2,
64 .pin = 1,
65 .irq = AR71XX_PCI_IRQ_DEV1,
66 }, {
67 .slot = 3,
68 .pin = 1,
69 .irq = AR71XX_PCI_IRQ_DEV2,
70 }
71 };
72
73 #if 0
74 /*
75 * SPI device support is experimental
76 */
77 static struct flash_platform_data rb4xx_flash_data = {
78 .type = "pm25lv512",
79 };
80
81 static struct spi_board_info rb4xx_spi_info[] = {
82 {
83 .bus_num = 0,
84 .chip_select = 0,
85 .max_speed_hz = 25000000,
86 .modalias = "m25p80",
87 .platform_data = &rb4xx_flash_data,
88 }
89 };
90
91 static struct mmc_spi_platform_data rb433_mmc_data = {
92 .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
93 };
94
95 static struct spi_board_info rb433_spi_info[] = {
96 {
97 .bus_num = 0,
98 .chip_select = 0,
99 .max_speed_hz = 25000000,
100 .modalias = "m25p80",
101 .platform_data = &rb433_flash_data,
102 }, {
103 .bus_num = 0,
104 .chip_select = 2,
105 .max_speed_hz = 25000000,
106 .modalias = "mmc_spi",
107 .platform_data = &rb433_mmc_data,
108 }
109 };
110
111 static u32 rb433_spi_get_ioc_base(u8 chip_select, int cs_high, int is_on)
112 {
113 u32 ret;
114
115 if (is_on == AR71XX_SPI_CS_INACTIVE) {
116 ret = SPI_IOC_CS0 | SPI_IOC_CS1;
117 } else {
118 if (cs_high) {
119 ret = SPI_IOC_CS0 | SPI_IOC_CS1;
120 } else {
121 if ((chip_select ^ 2) == 0)
122 ret = SPI_IOC_CS1 ^ (SPI_IOC_CS0 | SPI_IOC_CS1);
123 else
124 ret = SPI_IOC_CS0 ^ (SPI_IOC_CS0 | SPI_IOC_CS1);
125 }
126 }
127
128 return ret;
129 }
130
131 struct ar71xx_spi_platform_data rb433_spi_data = {
132 .bus_num = 0,
133 .num_chipselect = 3,
134 .get_ioc_base = rb433_spi_get_ioc_base,
135 };
136
137 static void rb4xx_add_device_spi(void)
138 {
139 ar71xx_add_device_spi(NULL, rb4xx_spi_info, ARRAY_SIZE(rb4xx_spi_info));
140 }
141
142 static void rb433_add_device_spi(void)
143 {
144 ar71xx_add_device_spi(&rb433_spi_data, rb433_spi_info,
145 ARRAY_SIZE(rb433_spi_info));
146 }
147 #else
148 static inline void rb4xx_add_device_spi(void) {}
149 static inline void rb433_add_device_spi(void) {}
150 #endif
151
152 static void __init rb411_setup(void)
153 {
154 rb4xx_add_device_spi();
155
156 ar71xx_add_device_mdio(0xfffffffe);
157 ar71xx_add_device_eth(0, PHY_INTERFACE_MODE_MII, 0x00000001);
158
159 platform_device_register(&rb4xx_leds_gpio_device);
160 platform_device_register(&rb4xx_nand_device);
161
162 ar71xx_pci_init(ARRAY_SIZE(rb4xx_pci_irqs), rb4xx_pci_irqs);
163 }
164
165 MIPS_MACHINE(MACH_AR71XX_RB_411, "MikroTik RouterBOARD 411/A/AH", rb411_setup);
166
167 static void __init rb433_setup(void)
168 {
169 rb433_add_device_spi();
170
171 ar71xx_add_device_mdio(0xffffffec);
172 ar71xx_add_device_eth(1, PHY_INTERFACE_MODE_RMII, 0x00000010);
173 ar71xx_add_device_eth(0, PHY_INTERFACE_MODE_MII, 0x00000003);
174
175 platform_device_register(&rb4xx_leds_gpio_device);
176 platform_device_register(&rb4xx_nand_device);
177
178 ar71xx_pci_init(ARRAY_SIZE(rb4xx_pci_irqs), rb4xx_pci_irqs);
179 }
180
181 MIPS_MACHINE(MACH_AR71XX_RB_433, "MikroTik RouterBOARD 433/AH", rb433_setup);
182
183 static void __init rb450_setup(void)
184 {
185 rb4xx_add_device_spi();
186
187 ar71xx_add_device_mdio(0xffffffe0);
188 ar71xx_add_device_eth(1, PHY_INTERFACE_MODE_RMII, 0x00000010);
189 ar71xx_add_device_eth(0, PHY_INTERFACE_MODE_MII, 0x0000000f);
190
191 platform_device_register(&rb4xx_leds_gpio_device);
192 platform_device_register(&rb4xx_nand_device);
193 }
194
195 MIPS_MACHINE(MACH_AR71XX_RB_450, "MikroTik RouterBOARD 450", rb450_setup);