1d0cc66189c05c4978a8719d8530b8bd0c9186c8
[openwrt/svn-archive/archive.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 #define PFX "adm5120: "
41
42 static LIST_HEAD(adm5120_boards);
43 static char adm5120_board_name[ADM5120_BOARD_NAMELEN];
44
45 const char *get_system_type(void)
46 {
47 return adm5120_board_name;
48 }
49
50 static struct adm5120_board * __init adm5120_board_find(unsigned long machtype)
51 {
52 struct list_head *this;
53 struct adm5120_board *board;
54 void *ret;
55
56 ret = NULL;
57 list_for_each(this, &adm5120_boards) {
58 board = list_entry(this, struct adm5120_board, list);
59 if (board->mach_type == machtype) {
60 ret = board;
61 break;
62 }
63 }
64
65 return ret;
66 }
67
68 static int __init adm5120_board_setup(void)
69 {
70 struct adm5120_board *board;
71 int err;
72
73 board = adm5120_board_find(mips_machtype);
74 if (board == NULL) {
75 printk(KERN_ALERT PFX"no board registered for "
76 "machtype %lu, trying generic\n", mips_machtype);
77 board = adm5120_board_find(MACH_ADM5120_GENERIC);
78 if (board == NULL)
79 panic(PFX "unsupported board\n");
80 }
81
82 printk(KERN_INFO PFX "setting up board '%s'\n", board->name);
83
84 memcpy(&adm5120_board_name, board->name, ADM5120_BOARD_NAMELEN);
85
86 adm5120_board_reset = board->board_reset;
87 if (board->eth_num_ports > 0)
88 adm5120_eth_num_ports = board->eth_num_ports;
89
90 if (board->eth_vlans)
91 memcpy(adm5120_eth_vlans, board->eth_vlans,
92 sizeof(adm5120_eth_vlans));
93
94 if (board->board_setup)
95 board->board_setup();
96
97 /* register UARTs */
98 amba_device_register(&adm5120_uart0_device, &iomem_resource);
99 amba_device_register(&adm5120_uart1_device, &iomem_resource);
100
101 /* setup PCI irq map */
102 adm5120_pci_set_irq_map(board->pci_nr_irqs, board->pci_irq_map);
103
104 /* register board devices */
105 if (board->num_devices > 0 && board->devices != NULL) {
106 err = platform_add_devices(board->devices, board->num_devices);
107 if (err)
108 printk(KERN_ALERT PFX "adding board devices failed\n");
109 }
110
111 return 0;
112 }
113 arch_initcall(adm5120_board_setup);
114
115 void __init adm5120_board_register(struct adm5120_board *board)
116 {
117 list_add(&board->list, &adm5120_boards);
118 printk(KERN_INFO PFX "registered board '%s'\n", board->name);
119 }
120
121 void __init adm5120_register_boards(struct adm5120_board **boards,
122 int num)
123 {
124 int i;
125
126 for (i = 0; i < num; i++)
127 adm5120_board_register(boards[i]);
128 }
129