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 <linux/leds.h>
29 #include <linux/etherdevice.h>
30 #include <linux/reboot.h>
31 #include <linux/time.h>
33 #include <linux/gpio.h>
35 #include <asm/bootinfo.h>
39 #include <ifxmips_irq.h>
41 #define MAX_BOARD_NAME_LEN 32
42 #define MAX_IFXMIPS_DEVS 9
44 #define SYSTEM_DANUBE "Danube"
45 #define SYSTEM_DANUBE_CHIPID1 0x00129083
46 #define SYSTEM_DANUBE_CHIPID2 0x0012B083
48 #define SYSTEM_TWINPASS "Twinpass"
49 #define SYSTEM_TWINPASS_CHIPID 0x0012D083
57 extern int ifxmips_pci_external_clock
;
59 static unsigned int chiprev
;
60 static int cmdline_mac
;
61 char board_name
[MAX_BOARD_NAME_LEN
+ 1] = { 0 };
63 struct ifxmips_board
{
66 unsigned int system_type
;
67 struct platform_device
**devs
;
68 struct resource reset_resource
;
69 struct resource gpiodev_resource
;
70 struct gpio_led
*ifxmips_leds
;
71 struct gpio_led
*gpio_leds
;
72 int pci_external_clock
;
76 DEFINE_SPINLOCK(ebu_lock
);
77 EXPORT_SYMBOL_GPL(ebu_lock
);
79 static unsigned char ifxmips_ethaddr
[6];
80 static int ifxmips_brn
;
82 static struct gpio_led_platform_data ifxmips_led_data
;
84 static struct platform_device ifxmips_led
= {
86 .name
= "ifxmips_led",
88 .platform_data
= (void *) &ifxmips_led_data
,
92 static struct platform_device ifxmips_gpio
= {
94 .name
= "ifxmips_gpio",
98 static struct platform_device ifxmips_mii
= {
100 .name
= "ifxmips_mii0",
102 .platform_data
= ifxmips_ethaddr
,
106 static struct platform_device ifxmips_wdt
= {
108 .name
= "ifxmips_wdt",
111 static struct resource ifxmips_mtd_resource
= {
112 .start
= IFXMIPS_FLASH_START
,
113 .end
= IFXMIPS_FLASH_START
+ IFXMIPS_FLASH_MAX
- 1,
114 .flags
= IORESOURCE_MEM
,
117 static struct platform_device ifxmips_mtd
= {
119 .name
= "ifxmips_mtd",
121 .resource
= &ifxmips_mtd_resource
,
124 static struct platform_device ifxmips_gpio_dev
= {
130 #ifdef CONFIG_LEDS_GPIO
131 static struct gpio_led arv4519_gpio_leds
[] = {
132 { .name
= "ifx:green:power", .gpio
= 3, .active_low
= 1, },
133 { .name
= "ifx:red:power", .gpio
= 7, .active_low
= 1, },
134 { .name
= "ifx:green:adsl", .gpio
= 4, .active_low
= 1, },
135 { .name
= "ifx:green:internet", .gpio
= 5, .active_low
= 1, },
136 { .name
= "ifx:red:internet", .gpio
= 8, .active_low
= 1, },
137 { .name
= "ifx:green:wlan", .gpio
= 6, .active_low
= 1, },
138 { .name
= "ifx:green:usbpwr", .gpio
= 14, .active_low
= 1, },
139 { .name
= "ifx:green:usb", .gpio
= 19, .active_low
= 1, },
142 static struct gpio_led_platform_data ifxmips_gpio_led_data
;
144 static struct platform_device ifxmips_gpio_leds
= {
148 .platform_data
= (void *) &ifxmips_gpio_led_data
,
153 static struct resource dwc_usb_res
[] = {
155 .name
= "dwc_usb_membase",
156 .flags
= IORESOURCE_MEM
,
161 .name
= "dwc_usb_irq",
162 .flags
= IORESOURCE_IRQ
,
163 .start
= IFXMIPS_USB_INT
,
167 static struct platform_device dwc_usb
=
171 .resource
= dwc_usb_res
,
172 .num_resources
= ARRAY_SIZE(dwc_usb_res
),
175 struct platform_device
*easy50712_devs
[] = {
176 &ifxmips_led
, &ifxmips_gpio
, &ifxmips_mii
,
177 &ifxmips_mtd
, &ifxmips_wdt
, &ifxmips_gpio_dev
, &dwc_usb
180 struct platform_device
*easy4010_devs
[] = {
181 &ifxmips_led
, &ifxmips_gpio
, &ifxmips_mii
,
182 &ifxmips_mtd
, &ifxmips_wdt
, &ifxmips_gpio_dev
, &dwc_usb
185 struct platform_device
*arv5419_devs
[] = {
186 &ifxmips_gpio
, &ifxmips_mii
, &ifxmips_mtd
,
187 &ifxmips_gpio_dev
, &ifxmips_wdt
, &dwc_usb
,
188 #ifdef CONFIG_LEDS_GPIO
193 static struct gpio_led easy50712_leds
[] = {
194 { .name
= "ifx:green:test0", .gpio
= 0,},
195 { .name
= "ifx:green:test1", .gpio
= 1,},
196 { .name
= "ifx:green:test2", .gpio
= 2,},
197 { .name
= "ifx:green:test3", .gpio
= 3,},
200 static struct gpio_led easy4010_leds
[] = {
201 { .name
= "ifx:green:test0", .gpio
= 0,},
202 { .name
= "ifx:green:test1", .gpio
= 1,},
203 { .name
= "ifx:green:test2", .gpio
= 2,},
204 { .name
= "ifx:green:test3", .gpio
= 3,},
207 static struct ifxmips_board boards
[] = {
209 /* infineon eval kit */
212 .system_type
= SYSTEM_DANUBE_CHIPID1
,
213 .devs
= easy50712_devs
,
214 .reset_resource
= {.name
= "reset", .start
= 1, .end
= 15,},
215 .gpiodev_resource
= { .name
= "gpio",
216 .start
= (1 << 0) | (1 << 1),
217 .end
= (1 << 0) | (1 << 1)},
218 .ifxmips_leds
= easy50712_leds
,
220 /* infineon eval kit */
223 .system_type
= SYSTEM_TWINPASS_CHIPID
,
224 .devs
= easy4010_devs
,
225 .reset_resource
= {.name
= "reset", .start
= 1, .end
= 15},
226 .gpiodev_resource
= { .name
= "gpio",
227 .start
= (1 << 0) | (1 << 1),
228 .end
= (1 << 0) | (1 << 1)},
229 .ifxmips_leds
= easy4010_leds
,
231 /* arcaydian annex-a board used by thompson, airties, ... */
234 .system_type
= SYSTEM_DANUBE_CHIPID2
,
235 .devs
= arv5419_devs
,
236 .reset_resource
= {.name
= "reset", .start
= 1, .end
= 14},
237 .pci_external_clock
= 1,
238 .gpio_leds
= arv4519_gpio_leds
,
242 const char *get_system_type(void)
244 chiprev
= (ifxmips_r32(IFXMIPS_MPS_CHIPID
) & 0x0FFFFFFF);
247 case SYSTEM_DANUBE_CHIPID1
:
248 case SYSTEM_DANUBE_CHIPID2
:
249 return SYSTEM_DANUBE
;
251 case SYSTEM_TWINPASS_CHIPID
:
252 return SYSTEM_TWINPASS
;
255 return BOARD_SYSTEM_TYPE
;
258 static int __init
ifxmips_set_board_type(char *str
)
260 str
= strchr(str
, '=');
264 if (strlen(str
) > MAX_BOARD_NAME_LEN
)
266 strncpy(board_name
, str
, MAX_BOARD_NAME_LEN
);
267 printk(KERN_INFO
"bootloader told us, that this is a %s board\n",
272 __setup("ifxmips_board", ifxmips_set_board_type
);
274 static int __init
ifxmips_set_ethaddr(char *str
)
277 (((x >= '0' && x <= '9') || (x >= 'a' && x <= 'f') \
278 || (x >= 'A' && x <= 'F')) ? (1) : (0))
280 str
= strchr(str
, '=');
284 if (strlen(str
) != 17)
286 for (i
= 0; i
< 6; i
++) {
287 if (!IS_HEX(str
[3 * i
]) || !IS_HEX(str
[(3 * i
) + 1]))
289 if ((i
!= 5) && (str
[(3 * i
) + 2] != ':'))
291 ifxmips_ethaddr
[i
] = simple_strtoul(&str
[3 * i
], NULL
, 16);
293 if (is_valid_ether_addr(ifxmips_ethaddr
))
298 __setup("ethaddr", ifxmips_set_ethaddr
);
300 int ifxmips_find_brn_block(void)
302 unsigned char temp
[8];
304 (void *)KSEG1ADDR(IFXMIPS_FLASH_START
+ 0x800000 - 0x10000), 8);
305 if (memcmp(temp
, "BRN-BOOT", 8) == 0) {
307 memcpy_fromio(ifxmips_ethaddr
,
308 (void *)KSEG1ADDR(IFXMIPS_FLASH_START
+
309 0x800000 - 0x10000 + 0x16), 6);
310 if (is_valid_ether_addr(ifxmips_ethaddr
))
318 int ifxmips_has_brn_block(void)
322 EXPORT_SYMBOL(ifxmips_has_brn_block
);
324 struct ifxmips_board
*ifxmips_find_board(void)
329 for (i
= 0; i
< ARRAY_SIZE(boards
); i
++)
330 if ((boards
[i
].system_type
== chiprev
) &&
331 (!strcmp(boards
[i
].name
, board_name
)))
336 int __init
ifxmips_init_devices(void)
338 struct ifxmips_board
*board
= ifxmips_find_board();
340 chiprev
= (ifxmips_r32(IFXMIPS_MPS_CHIPID
) & 0x0FFFFFFF);
341 ifxmips_brn
= ifxmips_find_brn_block();
344 random_ether_addr(ifxmips_ethaddr
);
348 case SYSTEM_DANUBE_CHIPID1
:
349 case SYSTEM_DANUBE_CHIPID2
:
353 case SYSTEM_TWINPASS_CHIPID
:
359 switch (board
->type
) {
361 board
->num_devs
= ARRAY_SIZE(easy50712_devs
);
362 ifxmips_led_data
.num_leds
= ARRAY_SIZE(easy50712_leds
);
365 board
->num_devs
= ARRAY_SIZE(easy4010_devs
);
366 ifxmips_led_data
.num_leds
= ARRAY_SIZE(easy4010_leds
);
369 /* set some sane defaults for the gpios */
370 gpio_set_value(3, 0);
371 gpio_set_value(4, 0);
372 gpio_set_value(5, 0);
373 gpio_set_value(6, 0);
374 gpio_set_value(7, 1);
375 gpio_set_value(8, 1);
376 gpio_set_value(19, 0);
377 board
->num_devs
= ARRAY_SIZE(arv5419_devs
);
378 #ifdef CONFIG_LEDS_GPIO
379 ifxmips_gpio_led_data
.num_leds
= ARRAY_SIZE(arv4519_gpio_leds
);
383 #ifdef CONFIG_LEDS_GPIO
384 ifxmips_gpio_led_data
.leds
= board
->gpio_leds
;
386 ifxmips_led_data
.leds
= board
->ifxmips_leds
;
388 printk(KERN_INFO
"%s: adding %d devs\n",
389 __func__
, board
->num_devs
);
391 ifxmips_gpio
.resource
= &board
->reset_resource
;
392 ifxmips_gpio_dev
.resource
= &board
->gpiodev_resource
;
393 if (board
->pci_external_clock
)
394 ifxmips_pci_external_clock
= 1;
395 printk(KERN_INFO
"using board definition %s\n", board
->name
);
396 return platform_add_devices(board
->devs
, board
->num_devs
);
399 arch_initcall(ifxmips_init_devices
);