surprise :p
[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 #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_eth(0, PHY_INTERFACE_MODE_MII, 0x00000001);
157
158         platform_device_register(&rb4xx_leds_gpio_device);
159         platform_device_register(&rb4xx_nand_device);
160
161         ar71xx_pci_init(ARRAY_SIZE(rb4xx_pci_irqs), rb4xx_pci_irqs);
162 }
163
164 MIPS_MACHINE(MACH_AR71XX_RB_411, "MikroTik RouterBOARD 411/A/AH", rb411_setup);
165
166 static void __init rb433_setup(void)
167 {
168         rb433_add_device_spi();
169
170         ar71xx_add_device_eth(0, PHY_INTERFACE_MODE_MII, 0x00000001);
171         ar71xx_add_device_eth(1, PHY_INTERFACE_MODE_RMII, 0xffffffff);
172
173         platform_device_register(&rb4xx_leds_gpio_device);
174         platform_device_register(&rb4xx_nand_device);
175
176         ar71xx_pci_init(ARRAY_SIZE(rb4xx_pci_irqs), rb4xx_pci_irqs);
177 }
178
179 MIPS_MACHINE(MACH_AR71XX_RB_433, "MikroTik RouterBOARD 433/AH", rb433_setup);
180
181 static void __init rb450_setup(void)
182 {
183         rb4xx_add_device_spi();
184
185         ar71xx_add_device_eth(0, PHY_INTERFACE_MODE_MII, 0x00000001);
186         ar71xx_add_device_eth(1, PHY_INTERFACE_MODE_RMII, 0xffffffff);
187
188         platform_device_register(&rb4xx_leds_gpio_device);
189         platform_device_register(&rb4xx_nand_device);
190 }
191
192 MIPS_MACHINE(MACH_AR71XX_RB_450, "MikroTik RouterBOARD 450", rb450_setup);