1af0eb2d4bd9b4308dff8cf46555e5a393870d71
[librecmc/librecmc.git] / target / linux / adm5120 / files / arch / mips / adm5120 / boards / compex.c
1 /*
2  *  $Id$
3  *
4  *  Compex boards
5  *
6  *  Copyright (C) 2007-2008 OpenWrt.org
7  *  Copyright (C) 2007-2008 Gabor Juhos <juhosg at openwrt.org>
8  *
9  *  This program is free software; you can redistribute it and/or modify it
10  *  under the terms of the GNU General Public License version 2 as published
11  *  by the Free Software Foundation.
12  *
13  */
14
15 #include <linux/kernel.h>
16 #include <linux/init.h>
17
18 #include <asm/bootinfo.h>
19 #include <asm/gpio.h>
20
21 #include <adm5120_board.h>
22 #include <adm5120_platform.h>
23 #include <adm5120_irq.h>
24
25 static struct adm5120_pci_irq wp54_pci_irqs[] __initdata = {
26         PCIIRQ(2, 0, 1, ADM5120_IRQ_PCI0),
27 };
28
29 static struct adm5120_pci_irq np28g_pci_irqs[] __initdata = {
30         PCIIRQ(2, 0, 1, ADM5120_IRQ_PCI0),
31         PCIIRQ(3, 0, 1, ADM5120_IRQ_PCI0),
32         PCIIRQ(3, 1, 2, ADM5120_IRQ_PCI1),
33         PCIIRQ(3, 2, 3, ADM5120_IRQ_PCI2)
34 };
35
36 static struct mtd_partition wp54g_wrt_partitions[] = {
37         {
38                 .name   = "cfe",
39                 .offset = 0,
40                 .size   = 0x050000,
41                 .mask_flags = MTD_WRITEABLE,
42         } , {
43                 .name   = "trx",
44                 .offset = MTDPART_OFS_APPEND,
45                 .size   = 0x3A0000,
46         } , {
47                 .name   = "nvram",
48                 .offset = MTDPART_OFS_APPEND,
49                 .size   = 0x010000,
50         }
51 };
52
53 static struct platform_device *np2xg_devices[] __initdata = {
54         &adm5120_flash0_device,
55         &adm5120_hcd_device,
56 };
57
58 static struct platform_device *wp54_devices[] __initdata = {
59         &adm5120_flash0_device,
60         &adm5120_buttons_device,
61 };
62
63 unsigned char np27g_vlans[6] __initdata = {
64         /* FIXME: untested */
65         0x41, 0x42, 0x44, 0x48, 0x50, 0x00
66 };
67
68 unsigned char np28g_vlans[6] __initdata = {
69         0x50, 0x42, 0x44, 0x48, 0x00, 0x00
70 };
71
72 unsigned char wp54_vlans[6] __initdata = {
73         0x41, 0x42, 0x00, 0x00, 0x00, 0x00
74 };
75
76 /*--------------------------------------------------------------------------*/
77
78 static void switch_bank_gpio5(unsigned bank)
79 {
80         switch (bank) {
81         case 0:
82                 gpio_set_value(ADM5120_GPIO_PIN5, 0);
83                 break;
84         case 1:
85                 gpio_set_value(ADM5120_GPIO_PIN5, 1);
86                 break;
87         }
88 }
89
90 static void wp54_reset(void)
91 {
92         gpio_set_value(ADM5120_GPIO_PIN3, 0);
93 }
94
95 static void np28g_reset(void)
96 {
97         gpio_set_value(ADM5120_GPIO_PIN4, 0);
98 }
99
100 static void __init np27g_setup(void)
101 {
102         gpio_request(ADM5120_GPIO_PIN5, NULL); /* for flash A20 line */
103         gpio_direction_output(ADM5120_GPIO_PIN5, 0);
104
105         /* setup data for flash0 device */
106         adm5120_flash0_data.switch_bank = switch_bank_gpio5;
107
108         /* TODO: setup mac address */
109 }
110
111 static void __init np28g_setup(void)
112 {
113         gpio_request(ADM5120_GPIO_PIN5, NULL); /* for flash A20 line */
114         gpio_direction_output(ADM5120_GPIO_PIN5, 0);
115
116         gpio_request(ADM5120_GPIO_PIN4, NULL); /* for system reset */
117         gpio_direction_output(ADM5120_GPIO_PIN4, 1);
118
119         /* setup data for flash0 device */
120         adm5120_flash0_data.switch_bank = switch_bank_gpio5;
121
122         /* TODO: setup mac address */
123 }
124
125 static void __init wp54_setup(void)
126 {
127         gpio_request(ADM5120_GPIO_PIN5, NULL); /* for flash A20 line */
128         gpio_direction_output(ADM5120_GPIO_PIN5, 0);
129
130         gpio_request(ADM5120_GPIO_PIN3, NULL); /* for system reset */
131         gpio_direction_output(ADM5120_GPIO_PIN3, 1);
132
133         /* setup data for flash0 device */
134         adm5120_flash0_data.switch_bank = switch_bank_gpio5;
135
136         adm5120_buttons_data.nbuttons = 1;
137         adm5120_buttons[0].desc = "reset button";
138         adm5120_buttons[0].gpio = ADM5120_GPIO_PIN2;
139
140         /* TODO: setup mac address */
141 }
142
143 static void __init wp54_wrt_setup(void)
144 {
145         wp54_setup();
146
147         adm5120_flash0_data.nr_parts = ARRAY_SIZE(wp54g_wrt_partitions);
148         adm5120_flash0_data.parts = wp54g_wrt_partitions;
149
150         /* TODO: setup mac address */
151 }
152
153 /*--------------------------------------------------------------------------*/
154
155 ADM5120_BOARD_START(NP27G, "Compex NetPassage 27G")
156         .board_setup    = np27g_setup,
157         .eth_num_ports  = 5,
158         .eth_vlans      = np27g_vlans,
159         .num_devices    = ARRAY_SIZE(np2xg_devices),
160         .devices        = np2xg_devices,
161         /* TODO: add PCI IRQ map */
162 ADM5120_BOARD_END
163
164 ADM5120_BOARD_START(NP28G, "Compex NetPassage 28G")
165         .board_setup    = np28g_setup,
166         .board_reset    = np28g_reset,
167         .eth_num_ports  = 4,
168         .eth_vlans      = np28g_vlans,
169         .num_devices    = ARRAY_SIZE(np2xg_devices),
170         .devices        = np2xg_devices,
171         .pci_nr_irqs    = ARRAY_SIZE(np28g_pci_irqs),
172         .pci_irq_map    = np28g_pci_irqs,
173 ADM5120_BOARD_END
174
175 ADM5120_BOARD_START(WP54AG, "Compex WP54AG")
176         .board_setup    = wp54_setup,
177         .board_reset    = wp54_reset,
178         .eth_num_ports  = 2,
179         .eth_vlans      = wp54_vlans,
180         .num_devices    = ARRAY_SIZE(wp54_devices),
181         .devices        = wp54_devices,
182         .pci_nr_irqs    = ARRAY_SIZE(wp54_pci_irqs),
183         .pci_irq_map    = wp54_pci_irqs,
184 ADM5120_BOARD_END
185
186 ADM5120_BOARD_START(WP54G, "Compex WP54G")
187         .board_setup    = wp54_setup,
188         .board_reset    = wp54_reset,
189         .eth_num_ports  = 2,
190         .eth_vlans      = wp54_vlans,
191         .num_devices    = ARRAY_SIZE(wp54_devices),
192         .devices        = wp54_devices,
193         .pci_nr_irqs    = ARRAY_SIZE(wp54_pci_irqs),
194         .pci_irq_map    = wp54_pci_irqs,
195 ADM5120_BOARD_END
196
197 ADM5120_BOARD_START(WP54G_WRT, "Compex WP54G-WRT")
198         .board_setup    = wp54_wrt_setup,
199         .board_reset    = wp54_reset,
200         .eth_num_ports  = 2,
201         .eth_vlans      = wp54_vlans,
202         .num_devices    = ARRAY_SIZE(wp54_devices),
203         .devices        = wp54_devices,
204         .pci_nr_irqs    = ARRAY_SIZE(wp54_pci_irqs),
205         .pci_irq_map    = wp54_pci_irqs,
206 ADM5120_BOARD_END
207
208 ADM5120_BOARD_START(WPP54AG, "Compex WPP54AG")
209         .board_setup    = wp54_setup,
210         .board_reset    = wp54_reset,
211         .eth_num_ports  = 2,
212         .eth_vlans      = wp54_vlans,
213         .num_devices    = ARRAY_SIZE(wp54_devices),
214         .devices        = wp54_devices,
215         .pci_nr_irqs    = ARRAY_SIZE(wp54_pci_irqs),
216         .pci_irq_map    = wp54_pci_irqs,
217 ADM5120_BOARD_END
218
219 ADM5120_BOARD_START(WPP54G, "Compex WPP54G")
220         .board_setup    = wp54_setup,
221         .board_reset    = wp54_reset,
222         .eth_num_ports  = 2,
223         .eth_vlans      = wp54_vlans,
224         .num_devices    = ARRAY_SIZE(wp54_devices),
225         .devices        = wp54_devices,
226         .pci_nr_irqs    = ARRAY_SIZE(wp54_pci_irqs),
227         .pci_irq_map    = wp54_pci_irqs,
228 ADM5120_BOARD_END