experimental gpiodev support (closes #3613)
[openwrt/staging/wigyori.git] / target / linux / adm5120 / files / arch / mips / adm5120 / board.c
1 /*
2 * $Id$
3 *
4 * ADM5120 generic board code
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/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 struct list_head adm5120_boards __initdata =
32 LIST_HEAD_INIT(adm5120_boards);
33 static char adm5120_board_name[ADM5120_BOARD_NAMELEN];
34
35 const char *get_system_type(void)
36 {
37 return adm5120_board_name;
38 }
39
40 static struct adm5120_board * __init adm5120_board_find(unsigned long machtype)
41 {
42 struct list_head *this;
43 struct adm5120_board *board;
44 void *ret;
45
46 ret = NULL;
47 list_for_each(this, &adm5120_boards) {
48 board = list_entry(this, struct adm5120_board, list);
49 if (board->mach_type == machtype) {
50 ret = board;
51 break;
52 }
53 }
54
55 return ret;
56 }
57
58 static int __init adm5120_board_setup(void)
59 {
60 struct adm5120_board *board;
61 int err;
62
63 board = adm5120_board_find(mips_machtype);
64 if (board == NULL) {
65 printk(KERN_ALERT PFX "no board registered for "
66 "machtype %lu, trying generic\n", mips_machtype);
67 board = adm5120_board_find(MACH_ADM5120_GENERIC);
68 if (board == NULL)
69 panic(PFX "unsupported board\n");
70 }
71
72 printk(KERN_INFO PFX "board is '%s'\n", board->name);
73
74 memcpy(&adm5120_board_name, board->name, ADM5120_BOARD_NAMELEN);
75
76 adm5120_gpio_init();
77
78 adm5120_board_reset = board->board_reset;
79 if (board->eth_num_ports > 0)
80 adm5120_eth_num_ports = board->eth_num_ports;
81
82 if (board->eth_vlans)
83 memcpy(adm5120_eth_vlans, board->eth_vlans,
84 sizeof(adm5120_eth_vlans));
85
86 if (board->board_setup)
87 board->board_setup();
88
89 /* register UARTs */
90 amba_device_register(&adm5120_uart0_device, &iomem_resource);
91 amba_device_register(&adm5120_uart1_device, &iomem_resource);
92
93 /* register built-in ethernet switch */
94 platform_device_register(&adm5120_switch_device);
95
96 if (adm5120_package_pqfp())
97 adm5120_gpiodev_resource.start &= ~0xf0;
98
99 platform_device_register(&adm5120_gpiodev_device);
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_tail(&board->list, &adm5120_boards);
118 }