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
58 extern int ifxmips_pci_external_clock
;
59 extern int ifxmips_pci_req_mask
;
61 static unsigned int chiprev
;
62 static int cmdline_mac
;
63 char board_name
[MAX_BOARD_NAME_LEN
+ 1] = { 0 };
65 struct ifxmips_board
{
68 unsigned int system_type
;
69 struct platform_device
**devs
;
70 struct resource reset_resource
;
71 struct resource gpiodev_resource
;
72 struct gpio_led
*ifxmips_leds
;
73 struct gpio_led
*gpio_leds
;
74 int pci_external_clock
;
79 DEFINE_SPINLOCK(ebu_lock
);
80 EXPORT_SYMBOL_GPL(ebu_lock
);
82 extern unsigned char ifxmips_ethaddr
[6];
83 static int ifxmips_brn
;
85 static struct gpio_led_platform_data ifxmips_led_data
;
87 static struct platform_device ifxmips_led
= {
89 .name
= "ifxmips_led",
91 .platform_data
= (void *) &ifxmips_led_data
,
95 static struct platform_device ifxmips_gpio
= {
97 .name
= "ifxmips_gpio",
101 static struct platform_device ifxmips_mii
= {
103 .name
= "ifxmips_mii0",
105 .platform_data
= ifxmips_ethaddr
,
109 static struct platform_device ifxmips_wdt
= {
111 .name
= "ifxmips_wdt",
114 static struct platform_device ifxmips_ebu
= {
116 .name
= "ifxmips_ebu",
119 static struct resource ifxmips_mtd_resource
= {
120 .start
= IFXMIPS_FLASH_START
,
121 .end
= IFXMIPS_FLASH_START
+ IFXMIPS_FLASH_MAX
- 1,
122 .flags
= IORESOURCE_MEM
,
125 static struct platform_device ifxmips_mtd
= {
127 .name
= "ifxmips_mtd",
129 .resource
= &ifxmips_mtd_resource
,
132 static struct platform_device ifxmips_gpio_dev
= {
138 #ifdef CONFIG_LEDS_GPIO
139 static struct gpio_led arv4519_gpio_leds
[] = {
140 { .name
= "ifx:green:power", .gpio
= 3, .active_low
= 1, },
141 { .name
= "ifx:red:power", .gpio
= 7, .active_low
= 1, },
142 { .name
= "ifx:green:adsl", .gpio
= 4, .active_low
= 1, },
143 { .name
= "ifx:green:internet", .gpio
= 5, .active_low
= 1, },
144 { .name
= "ifx:red:internet", .gpio
= 8, .active_low
= 1, },
145 { .name
= "ifx:green:wlan", .gpio
= 6, .active_low
= 1, },
146 { .name
= "ifx:green:usbpwr", .gpio
= 14, .active_low
= 1, },
147 { .name
= "ifx:green:usb", .gpio
= 19, .active_low
= 1, },
150 static struct gpio_led arv452_gpio_leds
[] = {
151 { .name
= "ifx:blue:power", .gpio
= 3, .active_low
= 1, },
152 { .name
= "ifx:blue:adsl", .gpio
= 4, .active_low
= 1, },
153 { .name
= "ifx:blue:internet", .gpio
= 5, .active_low
= 1, },
154 { .name
= "ifx:red:power", .gpio
= 6, .active_low
= 1, },
155 { .name
= "ifx:yello:wps", .gpio
= 7, .active_low
= 1, },
156 { .name
= "ifx:red:wps", .gpio
= 9, .active_low
= 1, },
157 { .name
= "ifx:blue:voip", .gpio
= 32, .active_low
= 1, },
158 { .name
= "ifx:blue:fxs1", .gpio
= 33, .active_low
= 1, },
159 { .name
= "ifx:blue:fxs2", .gpio
= 34, .active_low
= 1, },
160 { .name
= "ifx:blue:fxo", .gpio
= 35, .active_low
= 1, },
161 { .name
= "ifx:blue:voice", .gpio
= 36, .active_low
= 1, },
162 { .name
= "ifx:blue:usb", .gpio
= 37, .active_low
= 1, },
163 { .name
= "ifx:blue:wlan", .gpio
= 38, .active_low
= 1, },
164 { .name
= "ifx:red:internet", .gpio
= 41, .active_low
= 1, },
167 static struct gpio_led_platform_data ifxmips_gpio_led_data
;
169 static struct platform_device ifxmips_gpio_leds
= {
173 .platform_data
= (void *) &ifxmips_gpio_led_data
,
178 static struct resource dwc_usb_res
[] = {
180 .name
= "dwc3884_membase",
181 .flags
= IORESOURCE_MEM
,
186 .name
= "dwc3884_irq",
187 .flags
= IORESOURCE_IRQ
,
188 .start
= IFXMIPS_USB_INT
,
192 static struct platform_device dwc_usb
=
195 .name
= "dwc3884-hcd",
196 .resource
= dwc_usb_res
,
197 .num_resources
= ARRAY_SIZE(dwc_usb_res
),
200 struct platform_device
*easy50712_devs
[] = {
201 &ifxmips_led
, &ifxmips_gpio
, &ifxmips_mii
,
202 &ifxmips_mtd
, &ifxmips_wdt
, &ifxmips_gpio_dev
, &dwc_usb
205 struct platform_device
*easy4010_devs
[] = {
206 &ifxmips_led
, &ifxmips_gpio
, &ifxmips_mii
,
207 &ifxmips_mtd
, &ifxmips_wdt
, &ifxmips_gpio_dev
, &dwc_usb
210 struct platform_device
*arv5419_devs
[] = {
211 &ifxmips_gpio
, &ifxmips_mii
, &ifxmips_mtd
,
212 &ifxmips_gpio_dev
, &ifxmips_wdt
, &dwc_usb
,
213 #ifdef CONFIG_LEDS_GPIO
218 struct platform_device
*arv452_devs
[] = {
219 &ifxmips_gpio
, &ifxmips_mii
, &ifxmips_mtd
,
220 &ifxmips_gpio_dev
, &ifxmips_wdt
, &dwc_usb
,
222 #ifdef CONFIG_LEDS_GPIO
227 static struct gpio_led easy50712_leds
[] = {
228 { .name
= "ifx:green:test0", .gpio
= 0,},
229 { .name
= "ifx:green:test1", .gpio
= 1,},
230 { .name
= "ifx:green:test2", .gpio
= 2,},
231 { .name
= "ifx:green:test3", .gpio
= 3,},
234 static struct gpio_led easy4010_leds
[] = {
235 { .name
= "ifx:green:test0", .gpio
= 0,},
236 { .name
= "ifx:green:test1", .gpio
= 1,},
237 { .name
= "ifx:green:test2", .gpio
= 2,},
238 { .name
= "ifx:green:test3", .gpio
= 3,},
241 static struct ifxmips_board boards
[] = {
243 /* infineon eval kit */
246 .system_type
= SYSTEM_DANUBE_CHIPID1
,
247 .devs
= easy50712_devs
,
248 .reset_resource
= {.name
= "reset", .start
= 1, .end
= 15,},
249 .gpiodev_resource
= { .name
= "gpio",
250 .start
= (1 << 0) | (1 << 1),
251 .end
= (1 << 0) | (1 << 1)},
252 .ifxmips_leds
= easy50712_leds
,
254 /* infineon eval kit */
257 .system_type
= SYSTEM_TWINPASS_CHIPID
,
258 .devs
= easy4010_devs
,
259 .reset_resource
= {.name
= "reset", .start
= 1, .end
= 15},
260 .gpiodev_resource
= { .name
= "gpio",
261 .start
= (1 << 0) | (1 << 1),
262 .end
= (1 << 0) | (1 << 1)},
263 .ifxmips_leds
= easy4010_leds
,
265 /* arcaydian annex-a board used by thompson, airties, ... */
268 .system_type
= SYSTEM_DANUBE_CHIPID2
,
269 .devs
= arv5419_devs
,
270 .reset_resource
= {.name
= "reset", .start
= 1, .end
= 14},
271 .pci_external_clock
= 1,
272 #ifdef CONFIG_LEDS_GPIO
273 .gpio_leds
= arv4519_gpio_leds
,
276 /* arcaydian annex-b board used by airties, arcor */
279 .system_type
= SYSTEM_DANUBE_CHIPID2
,
281 .reset_resource
= {.name
= "reset", .start
= 1, .end
= 14},
282 .pci_external_clock
= 1,
283 #ifdef CONFIG_LEDS_GPIO
284 .gpio_leds
= arv452_gpio_leds
,
289 const char *get_system_type(void)
291 chiprev
= (ifxmips_r32(IFXMIPS_MPS_CHIPID
) & 0x0FFFFFFF);
294 case SYSTEM_DANUBE_CHIPID1
:
295 case SYSTEM_DANUBE_CHIPID2
:
296 return SYSTEM_DANUBE
;
298 case SYSTEM_TWINPASS_CHIPID
:
299 return SYSTEM_TWINPASS
;
302 return BOARD_SYSTEM_TYPE
;
305 static int __init
ifxmips_set_board_type(char *str
)
307 str
= strchr(str
, '=');
311 if (strlen(str
) > MAX_BOARD_NAME_LEN
)
313 strncpy(board_name
, str
, MAX_BOARD_NAME_LEN
);
314 printk(KERN_INFO
"bootloader told us, that this is a %s board\n",
319 __setup("ifxmips_board", ifxmips_set_board_type
);
321 static int __init
ifxmips_set_ethaddr(char *str
)
324 (((x >= '0' && x <= '9') || (x >= 'a' && x <= 'f') \
325 || (x >= 'A' && x <= 'F')) ? (1) : (0))
327 str
= strchr(str
, '=');
331 if (strlen(str
) != 17)
333 for (i
= 0; i
< 6; i
++) {
334 if (!IS_HEX(str
[3 * i
]) || !IS_HEX(str
[(3 * i
) + 1]))
336 if ((i
!= 5) && (str
[(3 * i
) + 2] != ':'))
338 ifxmips_ethaddr
[i
] = simple_strtoul(&str
[3 * i
], NULL
, 16);
340 if (is_valid_ether_addr(ifxmips_ethaddr
))
345 __setup("ethaddr", ifxmips_set_ethaddr
);
347 int ifxmips_find_brn_block(void)
349 unsigned char temp
[8];
351 (void *)KSEG1ADDR(IFXMIPS_FLASH_START
+ 0x800000 - 0x10000), 8);
352 if (memcmp(temp
, "BRN-BOOT", 8) == 0) {
354 memcpy_fromio(ifxmips_ethaddr
,
355 (void *)KSEG1ADDR(IFXMIPS_FLASH_START
+
356 0x800000 - 0x10000 + 0x16), 6);
357 if (is_valid_ether_addr(ifxmips_ethaddr
))
365 int ifxmips_has_brn_block(void)
369 EXPORT_SYMBOL(ifxmips_has_brn_block
);
371 struct ifxmips_board
*ifxmips_find_board(void)
376 for (i
= 0; i
< ARRAY_SIZE(boards
); i
++)
377 if ((boards
[i
].system_type
== chiprev
) &&
378 (!strcmp(boards
[i
].name
, board_name
)))
383 int __init
ifxmips_init_devices(void)
385 struct ifxmips_board
*board
;
387 chiprev
= (ifxmips_r32(IFXMIPS_MPS_CHIPID
) & 0x0FFFFFFF);
388 board
= ifxmips_find_board();
389 ifxmips_brn
= ifxmips_find_brn_block();
392 random_ether_addr(ifxmips_ethaddr
);
396 case SYSTEM_DANUBE_CHIPID1
:
397 case SYSTEM_DANUBE_CHIPID2
:
401 case SYSTEM_TWINPASS_CHIPID
:
407 switch (board
->type
) {
409 board
->num_devs
= ARRAY_SIZE(easy50712_devs
);
410 ifxmips_led_data
.num_leds
= ARRAY_SIZE(easy50712_leds
);
413 board
->num_devs
= ARRAY_SIZE(easy4010_devs
);
414 ifxmips_led_data
.num_leds
= ARRAY_SIZE(easy4010_leds
);
417 /* set some sane defaults for the gpios */
418 gpio_set_value(3, 0);
419 gpio_set_value(4, 0);
420 gpio_set_value(5, 0);
421 gpio_set_value(6, 0);
422 gpio_set_value(7, 1);
423 gpio_set_value(8, 1);
424 gpio_set_value(19, 0);
425 board
->num_devs
= ARRAY_SIZE(arv5419_devs
);
426 #ifdef CONFIG_LEDS_GPIO
427 ifxmips_gpio_led_data
.num_leds
= ARRAY_SIZE(arv4519_gpio_leds
);
431 /* set some sane defaults for the gpios */
432 board
->num_devs
= ARRAY_SIZE(arv452_devs
);
433 ifxmips_w32(0x8001e7ff, IFXMIPS_EBU_BUSCON1
);
434 #ifdef CONFIG_LEDS_GPIO
435 ifxmips_gpio_led_data
.num_leds
= ARRAY_SIZE(arv452_gpio_leds
);
439 #ifdef CONFIG_LEDS_GPIO
440 ifxmips_gpio_led_data
.leds
= board
->gpio_leds
;
442 ifxmips_led_data
.leds
= board
->ifxmips_leds
;
444 printk(KERN_INFO
"%s: adding %d devs\n",
445 __func__
, board
->num_devs
);
447 ifxmips_gpio
.resource
= &board
->reset_resource
;
448 ifxmips_gpio_dev
.resource
= &board
->gpiodev_resource
;
449 if (board
->pci_external_clock
)
450 ifxmips_pci_external_clock
= 1;
451 if (board
->pci_req_mask
)
452 ifxmips_pci_req_mask
= board
->pci_req_mask
;
453 printk(KERN_INFO
"using board definition %s\n", board
->name
);
454 return platform_add_devices(board
->devs
, board
->num_devs
);
457 arch_initcall(ifxmips_init_devices
);