2 * Board-specific setup code for the ATNGW100 Network Gateway
4 * Copyright (C) 2005-2006 Atmel Corporation
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 #include <linux/clk.h>
11 #include <linux/etherdevice.h>
12 #include <linux/init.h>
13 #include <linux/linkage.h>
14 #include <linux/platform_device.h>
15 #include <linux/types.h>
16 #include <linux/leds.h>
17 #include <linux/spi/spi.h>
20 #include <asm/setup.h>
22 #include <asm/arch/at32ap7000.h>
23 #include <asm/arch/board.h>
24 #include <asm/arch/init.h>
25 #include <asm/arch/portmux.h>
27 /* Initialized by bootloader-specific startup code. */
28 struct tag *bootloader_tags __initdata;
33 static struct eth_addr __initdata hw_addr[2];
34 static struct eth_platform_data __initdata eth_data[2];
36 static struct spi_board_info spi0_board_info[] __initdata = {
38 .modalias = "mtd_dataflash",
39 .max_speed_hz = 10000000,
45 * The next two functions should go away as the boot loader is
46 * supposed to initialize the macb address registers with a valid
47 * ethernet address. But we need to keep it around for a while until
48 * we can be reasonably sure the boot loader does this.
50 * The phy_id is ignored as the driver will probe for it.
52 static int __init parse_tag_ethernet(struct tag *tag)
56 i = tag->u.ethernet.mac_index;
57 if (i < ARRAY_SIZE(hw_addr))
58 memcpy(hw_addr[i].addr, tag->u.ethernet.hw_address,
59 sizeof(hw_addr[i].addr));
63 __tagtable(ATAG_ETHERNET, parse_tag_ethernet);
65 static void __init set_hw_addr(struct platform_device *pdev)
67 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
74 if (pdev->id >= ARRAY_SIZE(hw_addr))
77 addr = hw_addr[pdev->id].addr;
78 if (!is_valid_ether_addr(addr))
82 * Since this is board-specific code, we'll cheat and use the
83 * physical address directly as we happen to know that it's
84 * the same as the virtual address.
86 regs = (void __iomem __force *)res->start;
87 pclk = clk_get(&pdev->dev, "pclk");
92 __raw_writel((addr[3] << 24) | (addr[2] << 16)
93 | (addr[1] << 8) | addr[0], regs + 0x98);
94 __raw_writel((addr[5] << 8) | addr[4], regs + 0x9c);
99 void __init setup_board(void)
101 at32_map_usart(1, 0); /* USART 1: /dev/ttyS0, DB9 */
102 at32_setup_serial_console(0);
105 static const struct gpio_led ngw_leds[] = {
106 { .name = "sys", .gpio = GPIO_PIN_PA(16), .active_low = 1,
107 .default_trigger = "heartbeat",
109 { .name = "a", .gpio = GPIO_PIN_PA(19), .active_low = 1, },
110 { .name = "b", .gpio = GPIO_PIN_PE(19), .active_low = 1, },
113 static const struct gpio_led_platform_data ngw_led_data = {
114 .num_leds = ARRAY_SIZE(ngw_leds),
115 .leds = (void *) ngw_leds,
118 static struct platform_device ngw_gpio_leds = {
122 .platform_data = (void *) &ngw_led_data,
126 static int __init atngw100_init(void)
131 * ATNGW100 uses 16-bit SDRAM interface, so we don't need to
132 * reserve any pins for it.
135 at32_add_system_devices();
137 at32_add_device_usart(0);
139 set_hw_addr(at32_add_device_eth(0, ð_data[0]));
140 set_hw_addr(at32_add_device_eth(1, ð_data[1]));
142 at32_add_device_spi(0, spi0_board_info, ARRAY_SIZE(spi0_board_info));
144 for (i = 0; i < ARRAY_SIZE(ngw_leds); i++) {
145 at32_select_gpio(ngw_leds[i].gpio,
146 AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
148 platform_device_register(&ngw_gpio_leds);
152 postcore_initcall(atngw100_init);