a4643837c3e929d07bb18b162ef1dd014962290c
[openwrt/svn-archive/archive.git] / target / linux / adm5120-2.6 / 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@freemail.hu>
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 <asm/mach-adm5120/adm5120_info.h>
35 #include <asm/mach-adm5120/adm5120_defs.h>
36 #include <asm/mach-adm5120/adm5120_board.h>
37 #include <asm/mach-adm5120/adm5120_platform.h>
38
39 static LIST_HEAD(adm5120_boards);
40 static char adm5120_board_name[ADM5120_BOARD_NAMELEN];
41
42 const char *get_system_type(void)
43 {
44 return adm5120_board_name;
45 }
46
47 static struct adm5120_board * __init adm5120_board_find(unsigned long machtype)
48 {
49 struct list_head *this;
50 struct adm5120_board *board;
51 void *ret;
52
53 ret = NULL;
54 list_for_each(this, &adm5120_boards) {
55 board = list_entry(this, struct adm5120_board, list);
56 if (board->mach_type == machtype) {
57 ret = board;
58 break;
59 }
60 }
61
62 return ret;
63 }
64
65 static int __init adm5120_board_setup(void)
66 {
67 struct adm5120_board *board;
68 int err;
69
70 board = adm5120_board_find(mips_machtype);
71 if (board == NULL) {
72 printk(KERN_ALERT "adm5120: no board registered for machtype %lu"
73 ", trying generic\n", mips_machtype);
74 board = adm5120_board_find(MACH_ADM5120_GENERIC);
75 if (board == NULL)
76 panic("adm5120: unsupported board\n");
77 }
78
79 printk(KERN_INFO "adm5120: setting up board '%s'\n", board->name);
80
81 memcpy(&adm5120_board_name, board->name, ADM5120_BOARD_NAMELEN);
82
83 adm5120_board_reset = board->board_reset;
84 if (board->num_eth_ports > 0)
85 adm5120_eth_num_ports = board->num_eth_ports;
86
87 if (board->board_setup)
88 board->board_setup();
89
90 /* register PCI controller */
91 if (adm5120_package_bga())
92 platform_device_register(&adm5120_pci_device);
93
94 /* register board devices */
95 if (board->num_devices > 0 && board->devices != NULL ) {
96 err = platform_add_devices(board->devices, board->num_devices);
97 if (err)
98 printk(KERN_ALERT "adm5120: adding board devices failed\n");
99 }
100
101 return 0;
102 }
103
104 void __init adm5120_board_register(struct adm5120_board *board)
105 {
106 list_add(&board->list, &adm5120_boards);
107 printk(KERN_INFO "adm5120: registered board '%s'\n", board->name);
108 }
109
110 void __init adm5120_register_boards(struct adm5120_board **boards,
111 int num)
112 {
113 int i;
114
115 for (i=0; i<num; i++)
116 adm5120_board_register(boards[i]);
117 }
118
119 arch_initcall(adm5120_board_setup);