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>
35 #include <asm/ifxmips/ifxmips_mii0.h>
37 #define MAX_BOARD_NAME_LEN 32
38 #define MAX_IFXMIPS_DEVS 9
40 #define SYSTEM_DANUBE "Danube"
41 #define SYSTEM_DANUBE_CHIPID1 0x10129083
42 #define SYSTEM_DANUBE_CHIPID2 0x3012B083
44 #define SYSTEM_TWINPASS "Twinpass"
45 #define SYSTEM_TWINPASS_CHIPID 0x3012D083
47 extern int ifxmips_pci_external_clock
;
49 static unsigned int chiprev
;
50 static int cmdline_mac
= 0;
51 char board_name
[MAX_BOARD_NAME_LEN
+ 1] = { 0 };
53 struct ifxmips_board
{
55 unsigned int system_type
;
56 struct platform_device
*devs
[MAX_IFXMIPS_DEVS
];
57 struct resource reset_resource
;
58 struct resource gpiodev_resource
;
59 int pci_external_clock
;
63 spinlock_t ebu_lock
= SPIN_LOCK_UNLOCKED
;
64 EXPORT_SYMBOL_GPL(ebu_lock
);
66 static struct ifxmips_mac ifxmips_mii_mac
;
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
.mac
[i
] = simple_strtoul(&str
[3 * i
], NULL
, 16);
177 if(is_valid_ether_addr(ifxmips_mii_mac
.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,
260 struct ifxmips_board
* ifxmips_find_board(void)
265 for(i
= 0; i
< ARRAY_SIZE(boards
); i
++)
266 if((boards
[i
].system_type
== chiprev
) && (!strcmp(boards
[i
].name
, board_name
)))
272 ifxmips_init_devices(void)
274 struct ifxmips_board
*board
= ifxmips_find_board();
276 chiprev
= ifxmips_r32(IFXMIPS_MPS_CHIPID
);
279 random_ether_addr(ifxmips_mii_mac
.mac
);
285 case SYSTEM_DANUBE_CHIPID1
:
286 case SYSTEM_DANUBE_CHIPID2
:
289 case SYSTEM_TWINPASS_CHIPID
:
294 ifxmips_gpio
.resource
= &board
->reset_resource
;
295 ifxmips_gpio_dev
.resource
= &board
->gpiodev_resource
;
296 if(board
->pci_external_clock
)
297 ifxmips_pci_external_clock
= 1;
298 printk("using board definition %s\n", board
->name
);
299 return platform_add_devices(board
->devs
, board
->num_devs
);
302 arch_initcall(ifxmips_init_devices
);