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.
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.
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.
16 * Copyright (C) 2007 John Crispin <blogic@openwrt.org>
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>
33 #include <linux/etherdevice.h>
34 #include <asm/ifxmips/ifxmips.h>
36 #define MAX_BOARD_NAME_LEN 32
37 #define MAX_IFXMIPS_DEVS 9
39 #define SYSTEM_DANUBE "Danube"
40 #define SYSTEM_DANUBE_CHIPID1 0x10129083
41 #define SYSTEM_DANUBE_CHIPID2 0x3012B083
43 #define SYSTEM_TWINPASS "Twinpass"
44 #define SYSTEM_TWINPASS_CHIPID 0x3012D083
46 extern int ifxmips_pci_external_clock
;
48 static unsigned int chiprev
;
49 static int cmdline_mac
= 0;
50 char board_name
[MAX_BOARD_NAME_LEN
+ 1] = { 0 };
52 struct ifxmips_board
{
54 unsigned int system_type
;
55 struct platform_device
*devs
[MAX_IFXMIPS_DEVS
];
56 struct resource reset_resource
;
57 struct resource gpiodev_resource
;
58 int pci_external_clock
;
62 spinlock_t ebu_lock
= SPIN_LOCK_UNLOCKED
;
63 EXPORT_SYMBOL_GPL(ebu_lock
);
65 static unsigned char ifxmips_mii_mac
[6];
66 static int ifxmips_brn
= 0;
68 static struct platform_device
72 .name
= "ifxmips_led",
75 static struct platform_device
79 .name
= "ifxmips_gpio",
83 static struct platform_device
87 .name
= "ifxmips_mii0",
89 .platform_data
= ifxmips_mii_mac
,
93 static struct platform_device
97 .name
= "ifxmips_wdt",
100 static struct resource
101 ifxmips_mtd_resource
= {
102 .start
= IFXMIPS_FLASH_START
,
103 .end
= IFXMIPS_FLASH_START
+ IFXMIPS_FLASH_MAX
- 1,
104 .flags
= IORESOURCE_MEM
,
107 static struct platform_device
111 .name
= "ifxmips_mtd",
113 .resource
= &ifxmips_mtd_resource
,
116 static struct platform_device
124 get_system_type(void)
126 chiprev
= ifxmips_r32(IFXMIPS_MPS_CHIPID
);
129 case SYSTEM_DANUBE_CHIPID1
:
130 case SYSTEM_DANUBE_CHIPID2
:
131 return SYSTEM_DANUBE
;
133 case SYSTEM_TWINPASS_CHIPID
:
134 return SYSTEM_TWINPASS
;
137 return BOARD_SYSTEM_TYPE
;
141 ifxmips_set_board_type(char *str
)
143 str
= strchr(str
, '=');
147 if(strlen(str
) > MAX_BOARD_NAME_LEN
)
149 strncpy(board_name
, str
, MAX_BOARD_NAME_LEN
);
150 printk("bootloader told us, that this is a %s board\n", board_name
);
154 __setup("ifxmips_board", ifxmips_set_board_type
);
157 (((x >='0' && x <= '9') || (x >='a' && x <= 'f') || (x >='A' && x <= 'F'))?(1):(0))
160 ifxmips_set_mii0_mac(char *str
)
163 str
= strchr(str
, '=');
167 if(strlen(str
) != 17)
169 for(i
= 0; i
< 6; i
++)
171 if(!IS_HEX(str
[3 * i
]) || !IS_HEX(str
[(3 * i
) + 1]))
173 if((i
!= 5) && (str
[(3 * i
) + 2] != ':'))
175 ifxmips_mii_mac
[i
] = simple_strtoul(&str
[3 * i
], NULL
, 16);
177 if(is_valid_ether_addr(ifxmips_mii_mac
))
182 __setup("mii0_mac", ifxmips_set_mii0_mac
);
185 static struct ifxmips_board boards
[] =
189 .system_type
= SYSTEM_DANUBE_CHIPID1
,
192 &ifxmips_led
, &ifxmips_gpio
, &ifxmips_mii
,
193 &ifxmips_mtd
, &ifxmips_wdt
, &ifxmips_gpio_dev
,
204 .start
= (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) |
205 (1 << 4) | (1 << 5) | (1 << 8) | (1 << 9) | (1 << 12),
206 .end
= (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) |
207 (1 << 4) | (1 << 5) | (1 << 8) | (1 << 9) | (1 << 12),
212 .system_type
= SYSTEM_TWINPASS_CHIPID
,
215 &ifxmips_led
, &ifxmips_gpio
, &ifxmips_mii
,
216 &ifxmips_mtd
, &ifxmips_wdt
, &ifxmips_gpio_dev
,
227 .start
= (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) |
228 (1 << 4) | (1 << 5) | (1 << 8) | (1 << 9) | (1 << 12),
229 .end
= (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) |
230 (1 << 4) | (1 << 5) | (1 << 8) | (1 << 9) | (1 << 12),
235 .system_type
= SYSTEM_DANUBE_CHIPID2
,
238 &ifxmips_led
, &ifxmips_gpio
, &ifxmips_mii
,
239 &ifxmips_mtd
, &ifxmips_wdt
, &ifxmips_gpio_dev
,
250 .start
= (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) |
251 (1 << 4) | (1 << 5) | (1 << 8) | (1 << 9) | (1 << 12),
252 .end
= (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) |
253 (1 << 4) | (1 << 5) | (1 << 8) | (1 << 9) | (1 << 12),
255 .pci_external_clock
= 1,
261 ifxmips_find_brn_block(void){
262 unsigned char temp
[0];
263 memcpy_fromio(temp
, (void*)KSEG1ADDR(IFXMIPS_FLASH_START
+ 0x800000 - 0x10000), 8);
264 if(memcmp(temp
, "BRN-BOOT", 8) == 0)
271 ifxmips_has_brn_block(void)
276 struct ifxmips_board
*
277 ifxmips_find_board(void)
282 for(i
= 0; i
< ARRAY_SIZE(boards
); i
++)
283 if((boards
[i
].system_type
== chiprev
) && (!strcmp(boards
[i
].name
, board_name
)))
289 ifxmips_init_devices(void)
291 struct ifxmips_board
*board
= ifxmips_find_board();
293 chiprev
= ifxmips_r32(IFXMIPS_MPS_CHIPID
);
294 ifxmips_brn
= ifxmips_find_brn_block();
297 random_ether_addr(ifxmips_mii_mac
);
303 case SYSTEM_DANUBE_CHIPID1
:
304 case SYSTEM_DANUBE_CHIPID2
:
307 case SYSTEM_TWINPASS_CHIPID
:
312 ifxmips_gpio
.resource
= &board
->reset_resource
;
313 ifxmips_gpio_dev
.resource
= &board
->gpiodev_resource
;
314 if(board
->pci_external_clock
)
315 ifxmips_pci_external_clock
= 1;
316 printk("using board definition %s\n", board
->name
);
317 return platform_add_devices(board
->devs
, board
->num_devs
);
320 arch_initcall(ifxmips_init_devices
);