0153cce55c1d1f2bb199bfc5977d0a64000f4488
[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 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/init.h>
16 #include <linux/kernel.h>
17 #include <linux/list.h>
18 #include <linux/device.h>
19 #include <linux/platform_device.h>
20
21 #include <asm/bootinfo.h>
22
23 #include <adm5120_info.h>
24 #include <adm5120_defs.h>
25 #include <adm5120_irq.h>
26 #include <adm5120_board.h>
27 #include <adm5120_platform.h>
28
29 #define PFX     "adm5120: "
30
31 static LIST_HEAD(adm5120_boards);
32 static char adm5120_board_name[ADM5120_BOARD_NAMELEN];
33
34 const char *get_system_type(void)
35 {
36         return adm5120_board_name;
37 }
38
39 static struct adm5120_board * __init adm5120_board_find(unsigned long machtype)
40 {
41         struct list_head *this;
42         struct adm5120_board *board;
43         void *ret;
44
45         ret = NULL;
46         list_for_each(this, &adm5120_boards) {
47                 board = list_entry(this, struct adm5120_board, list);
48                 if (board->mach_type == machtype) {
49                         ret = board;
50                         break;
51                 }
52         }
53
54         return ret;
55 }
56
57 static int __init adm5120_board_setup(void)
58 {
59         struct adm5120_board *board;
60         int err;
61
62         board = adm5120_board_find(mips_machtype);
63         if (board == NULL) {
64                 printk(KERN_ALERT PFX"no board registered for "
65                         "machtype %lu, trying generic\n", mips_machtype);
66                 board = adm5120_board_find(MACH_ADM5120_GENERIC);
67                 if (board == NULL)
68                         panic(PFX "unsupported board\n");
69         }
70
71         printk(KERN_INFO PFX "setting up board '%s'\n", board->name);
72
73         memcpy(&adm5120_board_name, board->name, ADM5120_BOARD_NAMELEN);
74
75         adm5120_gpio_init();
76
77         adm5120_board_reset = board->board_reset;
78         if (board->eth_num_ports > 0)
79                 adm5120_eth_num_ports = board->eth_num_ports;
80
81         if (board->eth_vlans)
82                 memcpy(adm5120_eth_vlans, board->eth_vlans,
83                         sizeof(adm5120_eth_vlans));
84
85         if (board->board_setup)
86                 board->board_setup();
87
88         /* register UARTs */
89         amba_device_register(&adm5120_uart0_device, &iomem_resource);
90         amba_device_register(&adm5120_uart1_device, &iomem_resource);
91
92         /* register built-in ethernet switch */
93         platform_device_register(&adm5120_switch_device);
94
95         /* setup PCI irq map */
96         adm5120_pci_set_irq_map(board->pci_nr_irqs, board->pci_irq_map);
97
98         /* register board devices */
99         if (board->num_devices > 0 && board->devices != NULL) {
100                 err = platform_add_devices(board->devices, board->num_devices);
101                 if (err)
102                         printk(KERN_ALERT PFX "adding board devices failed\n");
103         }
104
105         return 0;
106 }
107 arch_initcall(adm5120_board_setup);
108
109 void __init adm5120_board_register(struct adm5120_board *board)
110 {
111         list_add_tail(&board->list, &adm5120_boards);
112         printk(KERN_INFO PFX "registered board '%s'\n", board->name);
113 }