lots of ifxmips cleanups
[openwrt/openwrt.git] / target / linux / ifxmips / files / arch / mips / ifxmips / board.c
1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
15 *
16 * Copyright (C) 2007 John Crispin <blogic@openwrt.org>
17 */
18
19 #include <linux/autoconf.h>
20 #include <linux/init.h>
21 #include <linux/module.h>
22 #include <linux/types.h>
23 #include <linux/string.h>
24 #include <linux/mtd/physmap.h>
25 #include <linux/kernel.h>
26 #include <linux/reboot.h>
27 #include <linux/platform_device.h>
28 #include <asm/bootinfo.h>
29 #include <asm/reboot.h>
30 #include <asm/time.h>
31 #include <asm/irq.h>
32 #include <asm/io.h>
33 #include <linux/etherdevice.h>
34 #include <asm/ifxmips/ifxmips.h>
35 #include <asm/ifxmips/ifxmips_mii0.h>
36
37 #define MAX_IFXMIPS_DEVS 9
38
39 #define BOARD_DANUBE "Danube"
40 #define BOARD_DANUBE_CHIPID 0x10129083
41
42 #define BOARD_TWINPASS "Twinpass"
43 #define BOARD_TWINPASS_CHIPID 0x3012D083
44
45 static unsigned int chiprev;
46 static struct platform_device *ifxmips_devs[MAX_IFXMIPS_DEVS];
47 static int cmdline_mac = 0;
48
49 spinlock_t ebu_lock = SPIN_LOCK_UNLOCKED;
50 EXPORT_SYMBOL_GPL(ebu_lock);
51
52 static struct ifxmips_mac ifxmips_mii_mac;
53
54 static struct platform_device
55 ifxmips_led[] =
56 {
57 {
58 .id = 0,
59 .name = "ifxmips_led",
60 },
61 };
62
63 static struct platform_device
64 ifxmips_gpio[] =
65 {
66 {
67 .id = 0,
68 .name = "ifxmips_gpio",
69 },
70 };
71
72 static struct platform_device
73 ifxmips_mii[] =
74 {
75 {
76 .id = 0,
77 .name = "ifxmips_mii0",
78 .dev = {
79 .platform_data = &ifxmips_mii_mac,
80 }
81 },
82 };
83
84 static struct platform_device
85 ifxmips_wdt[] =
86 {
87 {
88 .id = 0,
89 .name = "ifxmips_wdt",
90 },
91 };
92
93 static struct resource
94 ifxmips_mtd_resource = {
95 .start = IFXMIPS_FLASH_START,
96 .end = IFXMIPS_FLASH_START + IFXMIPS_FLASH_MAX - 1,
97 .flags = IORESOURCE_MEM,
98 };
99
100 static struct platform_device
101 ifxmips_mtd[] =
102 {
103 {
104 .id = 0,
105 .name = "ifxmips_mtd",
106 .num_resources = 1,
107 .resource = &ifxmips_mtd_resource,
108 },
109 };
110
111 #ifdef CONFIG_GPIO_DEVICE
112 static struct resource
113 ifxmips_gpio_dev_resources[] = {
114 {
115 .name = "gpio",
116 .flags = 0,
117 .start = (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) |
118 (1 << 4) | (1 << 5) | (1 << 8) | (1 << 9) | (1 << 12),
119 .end = (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) |
120 (1 << 4) | (1 << 5) | (1 << 8) | (1 << 9) | (1 << 12),
121 },
122 };
123
124 static struct platform_device
125 ifxmips_gpio_dev[] = {
126 {
127 .name = "GPIODEV",
128 .id = -1,
129 .num_resources = ARRAY_SIZE(ifxmips_gpio_dev_resources),
130 .resource = ifxmips_gpio_dev_resources,
131 }
132 };
133 #endif
134
135 const char*
136 get_system_type(void)
137 {
138 chiprev = ifxmips_r32(IFXMIPS_MPS_CHIPID);
139 switch(chiprev)
140 {
141 case BOARD_DANUBE_CHIPID:
142 return BOARD_DANUBE;
143
144 case BOARD_TWINPASS_CHIPID:
145 return BOARD_TWINPASS;
146 }
147
148 return BOARD_SYSTEM_TYPE;
149 }
150
151 #define IS_HEX(x) (((x >='0' && x <= '9') || (x >='a' && x <= 'f') || (x >='A' && x <= 'F'))?(1):(0))
152 static int __init
153 ifxmips_set_mii0_mac(char *str)
154 {
155 int i;
156 str = strchr(str, '=');
157 if(!str)
158 goto out;
159 str++;
160 if(strlen(str) != 17)
161 goto out;
162 for(i = 0; i < 6; i++)
163 {
164 if(!IS_HEX(str[3 * i]) || !IS_HEX(str[(3 * i) + 1]))
165 goto out;
166 if((i != 5) && (str[(3 * i) + 2] != ':'))
167 goto out;
168 ifxmips_mii_mac.mac[i] = simple_strtoul(&str[3 * i], NULL, 16);
169 }
170 if(is_valid_ether_addr(ifxmips_mii_mac.mac))
171 cmdline_mac = 1;
172 out:
173 return 1;
174 }
175 __setup("mii0_mac", ifxmips_set_mii0_mac);
176
177 int __init
178 ifxmips_init_devices(void)
179 {
180 int dev = 0;
181
182 if(!cmdline_mac)
183 random_ether_addr(ifxmips_mii_mac.mac);
184
185 ifxmips_devs[dev++] = ifxmips_led;
186 ifxmips_devs[dev++] = ifxmips_gpio;
187 ifxmips_devs[dev++] = ifxmips_mii;
188 ifxmips_devs[dev++] = ifxmips_mtd;
189 ifxmips_devs[dev++] = ifxmips_wdt;
190 #ifdef CONFIG_GPIO_DEVICE
191 ifxmips_devs[dev++] = ifxmips_gpio_dev;
192 #endif
193 return platform_add_devices(ifxmips_devs, dev);
194 }
195
196 arch_initcall(ifxmips_init_devices);