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;
58 extern int ifxmips_pci_req_mask;
60 static unsigned int chiprev;
61 static int cmdline_mac;
62 char board_name[MAX_BOARD_NAME_LEN + 1] = { 0 };
64 struct ifxmips_board {
67 unsigned int system_type;
68 struct platform_device **devs;
69 struct resource reset_resource;
70 struct resource gpiodev_resource;
71 struct gpio_led *ifxmips_leds;
72 struct gpio_led *gpio_leds;
73 int pci_external_clock;
78 DEFINE_SPINLOCK(ebu_lock);
79 EXPORT_SYMBOL_GPL(ebu_lock);
81 static unsigned char ifxmips_ethaddr[6];
82 static int ifxmips_brn;
84 static struct gpio_led_platform_data ifxmips_led_data;
86 static struct platform_device ifxmips_led = {
88 .name = "ifxmips_led",
90 .platform_data = (void *) &ifxmips_led_data,
94 static struct platform_device ifxmips_gpio = {
96 .name = "ifxmips_gpio",
100 static struct platform_device ifxmips_mii = {
102 .name = "ifxmips_mii0",
104 .platform_data = ifxmips_ethaddr,
108 static struct platform_device ifxmips_wdt = {
110 .name = "ifxmips_wdt",
113 static struct resource ifxmips_mtd_resource = {
114 .start = IFXMIPS_FLASH_START,
115 .end = IFXMIPS_FLASH_START + IFXMIPS_FLASH_MAX - 1,
116 .flags = IORESOURCE_MEM,
119 static struct platform_device ifxmips_mtd = {
121 .name = "ifxmips_mtd",
123 .resource = &ifxmips_mtd_resource,
126 static struct platform_device ifxmips_gpio_dev = {
132 #ifdef CONFIG_LEDS_GPIO
133 static struct gpio_led arv4519_gpio_leds[] = {
134 { .name = "ifx:green:power", .gpio = 3, .active_low = 1, },
135 { .name = "ifx:red:power", .gpio = 7, .active_low = 1, },
136 { .name = "ifx:green:adsl", .gpio = 4, .active_low = 1, },
137 { .name = "ifx:green:internet", .gpio = 5, .active_low = 1, },
138 { .name = "ifx:red:internet", .gpio = 8, .active_low = 1, },
139 { .name = "ifx:green:wlan", .gpio = 6, .active_low = 1, },
140 { .name = "ifx:green:usbpwr", .gpio = 14, .active_low = 1, },
141 { .name = "ifx:green:usb", .gpio = 19, .active_low = 1, },
144 static struct gpio_led_platform_data ifxmips_gpio_led_data;
146 static struct platform_device ifxmips_gpio_leds = {
150 .platform_data = (void *) &ifxmips_gpio_led_data,
155 static struct resource dwc_usb_res[] = {
157 .name = "dwc_usb_membase",
158 .flags = IORESOURCE_MEM,
163 .name = "dwc_usb_irq",
164 .flags = IORESOURCE_IRQ,
165 .start = IFXMIPS_USB_INT,
169 static struct platform_device dwc_usb =
173 .resource = dwc_usb_res,
174 .num_resources = ARRAY_SIZE(dwc_usb_res),
177 struct platform_device *easy50712_devs[] = {
178 &ifxmips_led, &ifxmips_gpio, &ifxmips_mii,
179 &ifxmips_mtd, &ifxmips_wdt, &ifxmips_gpio_dev, &dwc_usb
182 struct platform_device *easy4010_devs[] = {
183 &ifxmips_led, &ifxmips_gpio, &ifxmips_mii,
184 &ifxmips_mtd, &ifxmips_wdt, &ifxmips_gpio_dev, &dwc_usb
187 struct platform_device *arv5419_devs[] = {
188 &ifxmips_gpio, &ifxmips_mii, &ifxmips_mtd,
189 &ifxmips_gpio_dev, &ifxmips_wdt, &dwc_usb,
190 #ifdef CONFIG_LEDS_GPIO
195 static struct gpio_led easy50712_leds[] = {
196 { .name = "ifx:green:test0", .gpio = 0,},
197 { .name = "ifx:green:test1", .gpio = 1,},
198 { .name = "ifx:green:test2", .gpio = 2,},
199 { .name = "ifx:green:test3", .gpio = 3,},
202 static struct gpio_led easy4010_leds[] = {
203 { .name = "ifx:green:test0", .gpio = 0,},
204 { .name = "ifx:green:test1", .gpio = 1,},
205 { .name = "ifx:green:test2", .gpio = 2,},
206 { .name = "ifx:green:test3", .gpio = 3,},
209 static struct ifxmips_board boards[] = {
211 /* infineon eval kit */
214 .system_type = SYSTEM_DANUBE_CHIPID1,
215 .devs = easy50712_devs,
216 .reset_resource = {.name = "reset", .start = 1, .end = 15,},
217 .gpiodev_resource = { .name = "gpio",
218 .start = (1 << 0) | (1 << 1),
219 .end = (1 << 0) | (1 << 1)},
220 .ifxmips_leds = easy50712_leds,
222 /* infineon eval kit */
225 .system_type = SYSTEM_TWINPASS_CHIPID,
226 .devs = easy4010_devs,
227 .reset_resource = {.name = "reset", .start = 1, .end = 15},
228 .gpiodev_resource = { .name = "gpio",
229 .start = (1 << 0) | (1 << 1),
230 .end = (1 << 0) | (1 << 1)},
231 .ifxmips_leds = easy4010_leds,
233 /* arcaydian annex-a board used by thompson, airties, ... */
236 .system_type = SYSTEM_DANUBE_CHIPID2,
237 .devs = arv5419_devs,
238 .reset_resource = {.name = "reset", .start = 1, .end = 14},
239 .pci_external_clock = 1,
240 .gpio_leds = arv4519_gpio_leds,
244 const char *get_system_type(void)
246 chiprev = (ifxmips_r32(IFXMIPS_MPS_CHIPID) & 0x0FFFFFFF);
249 case SYSTEM_DANUBE_CHIPID1:
250 case SYSTEM_DANUBE_CHIPID2:
251 return SYSTEM_DANUBE;
253 case SYSTEM_TWINPASS_CHIPID:
254 return SYSTEM_TWINPASS;
257 return BOARD_SYSTEM_TYPE;
260 static int __init ifxmips_set_board_type(char *str)
262 str = strchr(str, '=');
266 if (strlen(str) > MAX_BOARD_NAME_LEN)
268 strncpy(board_name, str, MAX_BOARD_NAME_LEN);
269 printk(KERN_INFO "bootloader told us, that this is a %s board\n",
274 __setup("ifxmips_board", ifxmips_set_board_type);
276 static int __init ifxmips_set_ethaddr(char *str)
279 (((x >= '0' && x <= '9') || (x >= 'a' && x <= 'f') \
280 || (x >= 'A' && x <= 'F')) ? (1) : (0))
282 str = strchr(str, '=');
286 if (strlen(str) != 17)
288 for (i = 0; i < 6; i++) {
289 if (!IS_HEX(str[3 * i]) || !IS_HEX(str[(3 * i) + 1]))
291 if ((i != 5) && (str[(3 * i) + 2] != ':'))
293 ifxmips_ethaddr[i] = simple_strtoul(&str[3 * i], NULL, 16);
295 if (is_valid_ether_addr(ifxmips_ethaddr))
300 __setup("ethaddr", ifxmips_set_ethaddr);
302 int ifxmips_find_brn_block(void)
304 unsigned char temp[8];
306 (void *)KSEG1ADDR(IFXMIPS_FLASH_START + 0x800000 - 0x10000), 8);
307 if (memcmp(temp, "BRN-BOOT", 8) == 0) {
309 memcpy_fromio(ifxmips_ethaddr,
310 (void *)KSEG1ADDR(IFXMIPS_FLASH_START +
311 0x800000 - 0x10000 + 0x16), 6);
312 if (is_valid_ether_addr(ifxmips_ethaddr))
320 int ifxmips_has_brn_block(void)
324 EXPORT_SYMBOL(ifxmips_has_brn_block);
326 struct ifxmips_board *ifxmips_find_board(void)
331 for (i = 0; i < ARRAY_SIZE(boards); i++)
332 if ((boards[i].system_type == chiprev) &&
333 (!strcmp(boards[i].name, board_name)))
338 int __init ifxmips_init_devices(void)
340 struct ifxmips_board *board;
342 chiprev = (ifxmips_r32(IFXMIPS_MPS_CHIPID) & 0x0FFFFFFF);
343 board = ifxmips_find_board();
344 ifxmips_brn = ifxmips_find_brn_block();
347 random_ether_addr(ifxmips_ethaddr);
351 case SYSTEM_DANUBE_CHIPID1:
352 case SYSTEM_DANUBE_CHIPID2:
356 case SYSTEM_TWINPASS_CHIPID:
362 switch (board->type) {
364 board->num_devs = ARRAY_SIZE(easy50712_devs);
365 ifxmips_led_data.num_leds = ARRAY_SIZE(easy50712_leds);
368 board->num_devs = ARRAY_SIZE(easy4010_devs);
369 ifxmips_led_data.num_leds = ARRAY_SIZE(easy4010_leds);
372 /* set some sane defaults for the gpios */
373 gpio_set_value(3, 0);
374 gpio_set_value(4, 0);
375 gpio_set_value(5, 0);
376 gpio_set_value(6, 0);
377 gpio_set_value(7, 1);
378 gpio_set_value(8, 1);
379 gpio_set_value(19, 0);
380 board->num_devs = ARRAY_SIZE(arv5419_devs);
381 #ifdef CONFIG_LEDS_GPIO
382 ifxmips_gpio_led_data.num_leds = ARRAY_SIZE(arv4519_gpio_leds);
386 #ifdef CONFIG_LEDS_GPIO
387 ifxmips_gpio_led_data.leds = board->gpio_leds;
389 ifxmips_led_data.leds = board->ifxmips_leds;
391 printk(KERN_INFO "%s: adding %d devs\n",
392 __func__, board->num_devs);
394 ifxmips_gpio.resource = &board->reset_resource;
395 ifxmips_gpio_dev.resource = &board->gpiodev_resource;
396 if (board->pci_external_clock)
397 ifxmips_pci_external_clock = 1;
398 if (board->pci_req_mask)
399 ifxmips_pci_req_mask = board->pci_req_mask;
400 printk(KERN_INFO "using board definition %s\n", board->name);
401 return platform_add_devices(board->devs, board->num_devs);
404 arch_initcall(ifxmips_init_devices);