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