move pci_irq_map definitions into the board specific files
[openwrt/openwrt.git] / target / linux / adm5120 / files / arch / mips / adm5120 / board.c
1 /*
2 * $Id$
3 *
4 * ADM5120 generic board code
5 *
6 * Copyright (C) 2007 OpenWrt.org
7 * Copyright (C) 2007 Gabor Juhos <juhosg at openwrt.org>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the
21 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
23 *
24 */
25
26 #include <linux/init.h>
27 #include <linux/kernel.h>
28 #include <linux/list.h>
29 #include <linux/device.h>
30 #include <linux/platform_device.h>
31
32 #include <asm/bootinfo.h>
33
34 #include <adm5120_info.h>
35 #include <adm5120_defs.h>
36 #include <adm5120_irq.h>
37 #include <adm5120_board.h>
38 #include <adm5120_platform.h>
39
40 static LIST_HEAD(adm5120_boards);
41 static char adm5120_board_name[ADM5120_BOARD_NAMELEN];
42
43 const char *get_system_type(void)
44 {
45 return adm5120_board_name;
46 }
47
48 static struct adm5120_board * __init adm5120_board_find(unsigned long machtype)
49 {
50 struct list_head *this;
51 struct adm5120_board *board;
52 void *ret;
53
54 ret = NULL;
55 list_for_each(this, &adm5120_boards) {
56 board = list_entry(this, struct adm5120_board, list);
57 if (board->mach_type == machtype) {
58 ret = board;
59 break;
60 }
61 }
62
63 return ret;
64 }
65
66 static int __init adm5120_board_setup(void)
67 {
68 struct adm5120_board *board;
69 int err;
70
71 board = adm5120_board_find(mips_machtype);
72 if (board == NULL) {
73 printk(KERN_ALERT "adm5120: no board registered for machtype %lu"
74 ", trying generic\n", mips_machtype);
75 board = adm5120_board_find(MACH_ADM5120_GENERIC);
76 if (board == NULL)
77 panic("adm5120: unsupported board\n");
78 }
79
80 printk(KERN_INFO "adm5120: setting up board '%s'\n", board->name);
81
82 memcpy(&adm5120_board_name, board->name, ADM5120_BOARD_NAMELEN);
83
84 adm5120_board_reset = board->board_reset;
85 if (board->eth_num_ports > 0)
86 adm5120_eth_num_ports = board->eth_num_ports;
87
88 if (board->eth_vlans)
89 memcpy(adm5120_eth_vlans, board->eth_vlans,
90 sizeof(adm5120_eth_vlans));
91
92 if (board->board_setup)
93 board->board_setup();
94
95 /* register UARTs */
96 amba_device_register(&adm5120_uart0_device, &iomem_resource);
97 amba_device_register(&adm5120_uart1_device, &iomem_resource);
98
99 /* setup PCI irq map */
100 adm5120_pci_set_irq_map(board->pci_nr_irqs, board->pci_irq_map);
101
102 /* register board devices */
103 if (board->num_devices > 0 && board->devices != NULL ) {
104 err = platform_add_devices(board->devices, board->num_devices);
105 if (err)
106 printk(KERN_ALERT "adm5120: adding board devices failed\n");
107 }
108
109 return 0;
110 }
111 postcore_initcall(adm5120_board_setup);
112
113 void __init adm5120_board_register(struct adm5120_board *board)
114 {
115 list_add(&board->list, &adm5120_boards);
116 printk(KERN_INFO "adm5120: registered board '%s'\n", board->name);
117 }
118
119 void __init adm5120_register_boards(struct adm5120_board **boards,
120 int num)
121 {
122 int i;
123
124 for (i=0; i<num; i++)
125 adm5120_board_register(boards[i]);
126 }
127