| Haavard Skinnemoen | 9ca20a8 | 2007-04-12 17:26:57 +0200 | [diff] [blame] | 1 | /* | 
 | 2 |  * Board-specific setup code for the ATNGW100 Network Gateway | 
 | 3 |  * | 
 | 4 |  * Copyright (C) 2005-2006 Atmel Corporation | 
 | 5 |  * | 
 | 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. | 
 | 9 |  */ | 
 | 10 | #include <linux/clk.h> | 
 | 11 | #include <linux/etherdevice.h> | 
| Haavard Skinnemoen | 54bb69e | 2007-07-12 16:36:34 +0200 | [diff] [blame] | 12 | #include <linux/i2c-gpio.h> | 
| Haavard Skinnemoen | 9ca20a8 | 2007-04-12 17:26:57 +0200 | [diff] [blame] | 13 | #include <linux/init.h> | 
 | 14 | #include <linux/linkage.h> | 
 | 15 | #include <linux/platform_device.h> | 
 | 16 | #include <linux/types.h> | 
| David Brownell | f9f451d | 2007-07-08 11:49:53 +0100 | [diff] [blame] | 17 | #include <linux/leds.h> | 
| Haavard Skinnemoen | 9ca20a8 | 2007-04-12 17:26:57 +0200 | [diff] [blame] | 18 | #include <linux/spi/spi.h> | 
 | 19 |  | 
 | 20 | #include <asm/io.h> | 
 | 21 | #include <asm/setup.h> | 
 | 22 |  | 
| Haavard Skinnemoen | 438ff3f | 2007-10-29 15:28:07 +0100 | [diff] [blame] | 23 | #include <asm/arch/at32ap700x.h> | 
| Haavard Skinnemoen | 9ca20a8 | 2007-04-12 17:26:57 +0200 | [diff] [blame] | 24 | #include <asm/arch/board.h> | 
 | 25 | #include <asm/arch/init.h> | 
| David Brownell | f9f451d | 2007-07-08 11:49:53 +0100 | [diff] [blame] | 26 | #include <asm/arch/portmux.h> | 
| Haavard Skinnemoen | 9ca20a8 | 2007-04-12 17:26:57 +0200 | [diff] [blame] | 27 |  | 
 | 28 | /* Initialized by bootloader-specific startup code. */ | 
 | 29 | struct tag *bootloader_tags __initdata; | 
 | 30 |  | 
 | 31 | struct eth_addr { | 
 | 32 | 	u8 addr[6]; | 
 | 33 | }; | 
 | 34 | static struct eth_addr __initdata hw_addr[2]; | 
 | 35 | static struct eth_platform_data __initdata eth_data[2]; | 
 | 36 |  | 
 | 37 | static struct spi_board_info spi0_board_info[] __initdata = { | 
 | 38 | 	{ | 
 | 39 | 		.modalias	= "mtd_dataflash", | 
 | 40 | 		.max_speed_hz	= 10000000, | 
 | 41 | 		.chip_select	= 0, | 
 | 42 | 	}, | 
 | 43 | }; | 
 | 44 |  | 
 | 45 | /* | 
 | 46 |  * The next two functions should go away as the boot loader is | 
 | 47 |  * supposed to initialize the macb address registers with a valid | 
 | 48 |  * ethernet address. But we need to keep it around for a while until | 
 | 49 |  * we can be reasonably sure the boot loader does this. | 
 | 50 |  * | 
 | 51 |  * The phy_id is ignored as the driver will probe for it. | 
 | 52 |  */ | 
 | 53 | static int __init parse_tag_ethernet(struct tag *tag) | 
 | 54 | { | 
 | 55 | 	int i; | 
 | 56 |  | 
 | 57 | 	i = tag->u.ethernet.mac_index; | 
 | 58 | 	if (i < ARRAY_SIZE(hw_addr)) | 
 | 59 | 		memcpy(hw_addr[i].addr, tag->u.ethernet.hw_address, | 
 | 60 | 		       sizeof(hw_addr[i].addr)); | 
 | 61 |  | 
 | 62 | 	return 0; | 
 | 63 | } | 
 | 64 | __tagtable(ATAG_ETHERNET, parse_tag_ethernet); | 
 | 65 |  | 
 | 66 | static void __init set_hw_addr(struct platform_device *pdev) | 
 | 67 | { | 
 | 68 | 	struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 
 | 69 | 	const u8 *addr; | 
 | 70 | 	void __iomem *regs; | 
 | 71 | 	struct clk *pclk; | 
 | 72 |  | 
 | 73 | 	if (!res) | 
 | 74 | 		return; | 
 | 75 | 	if (pdev->id >= ARRAY_SIZE(hw_addr)) | 
 | 76 | 		return; | 
 | 77 |  | 
 | 78 | 	addr = hw_addr[pdev->id].addr; | 
 | 79 | 	if (!is_valid_ether_addr(addr)) | 
 | 80 | 		return; | 
 | 81 |  | 
 | 82 | 	/* | 
 | 83 | 	 * Since this is board-specific code, we'll cheat and use the | 
 | 84 | 	 * physical address directly as we happen to know that it's | 
 | 85 | 	 * the same as the virtual address. | 
 | 86 | 	 */ | 
 | 87 | 	regs = (void __iomem __force *)res->start; | 
 | 88 | 	pclk = clk_get(&pdev->dev, "pclk"); | 
 | 89 | 	if (!pclk) | 
 | 90 | 		return; | 
 | 91 |  | 
 | 92 | 	clk_enable(pclk); | 
 | 93 | 	__raw_writel((addr[3] << 24) | (addr[2] << 16) | 
 | 94 | 		     | (addr[1] << 8) | addr[0], regs + 0x98); | 
 | 95 | 	__raw_writel((addr[5] << 8) | addr[4], regs + 0x9c); | 
 | 96 | 	clk_disable(pclk); | 
 | 97 | 	clk_put(pclk); | 
 | 98 | } | 
 | 99 |  | 
| Haavard Skinnemoen | 9ca20a8 | 2007-04-12 17:26:57 +0200 | [diff] [blame] | 100 | void __init setup_board(void) | 
 | 101 | { | 
 | 102 | 	at32_map_usart(1, 0);	/* USART 1: /dev/ttyS0, DB9 */ | 
 | 103 | 	at32_setup_serial_console(0); | 
 | 104 | } | 
 | 105 |  | 
| David Brownell | f9f451d | 2007-07-08 11:49:53 +0100 | [diff] [blame] | 106 | static const struct gpio_led ngw_leds[] = { | 
 | 107 | 	{ .name = "sys", .gpio = GPIO_PIN_PA(16), .active_low = 1, | 
 | 108 | 		.default_trigger = "heartbeat", | 
 | 109 | 	}, | 
 | 110 | 	{ .name = "a", .gpio = GPIO_PIN_PA(19), .active_low = 1, }, | 
 | 111 | 	{ .name = "b", .gpio = GPIO_PIN_PE(19), .active_low = 1, }, | 
 | 112 | }; | 
 | 113 |  | 
 | 114 | static const struct gpio_led_platform_data ngw_led_data = { | 
 | 115 | 	.num_leds =	ARRAY_SIZE(ngw_leds), | 
 | 116 | 	.leds =		(void *) ngw_leds, | 
 | 117 | }; | 
 | 118 |  | 
 | 119 | static struct platform_device ngw_gpio_leds = { | 
 | 120 | 	.name =		"leds-gpio", | 
 | 121 | 	.id =		-1, | 
 | 122 | 	.dev = { | 
 | 123 | 		.platform_data = (void *) &ngw_led_data, | 
 | 124 | 	} | 
 | 125 | }; | 
 | 126 |  | 
| Haavard Skinnemoen | 54bb69e | 2007-07-12 16:36:34 +0200 | [diff] [blame] | 127 | static struct i2c_gpio_platform_data i2c_gpio_data = { | 
| David Brownell | 82c54f8 | 2007-09-25 07:17:48 -0700 | [diff] [blame] | 128 | 	.sda_pin		= GPIO_PIN_PA(6), | 
 | 129 | 	.scl_pin		= GPIO_PIN_PA(7), | 
 | 130 | 	.sda_is_open_drain	= 1, | 
 | 131 | 	.scl_is_open_drain	= 1, | 
 | 132 | 	.udelay			= 2,	/* close to 100 kHz */ | 
| Haavard Skinnemoen | 54bb69e | 2007-07-12 16:36:34 +0200 | [diff] [blame] | 133 | }; | 
 | 134 |  | 
 | 135 | static struct platform_device i2c_gpio_device = { | 
 | 136 | 	.name		= "i2c-gpio", | 
 | 137 | 	.id		= 0, | 
 | 138 | 	.dev		= { | 
 | 139 | 		.platform_data	= &i2c_gpio_data, | 
 | 140 | 	}, | 
 | 141 | }; | 
 | 142 |  | 
| Haavard Skinnemoen | 9ca20a8 | 2007-04-12 17:26:57 +0200 | [diff] [blame] | 143 | static int __init atngw100_init(void) | 
 | 144 | { | 
| David Brownell | f9f451d | 2007-07-08 11:49:53 +0100 | [diff] [blame] | 145 | 	unsigned	i; | 
 | 146 |  | 
| Haavard Skinnemoen | 9ca20a8 | 2007-04-12 17:26:57 +0200 | [diff] [blame] | 147 | 	/* | 
 | 148 | 	 * ATNGW100 uses 16-bit SDRAM interface, so we don't need to | 
 | 149 | 	 * reserve any pins for it. | 
 | 150 | 	 */ | 
 | 151 |  | 
 | 152 | 	at32_add_system_devices(); | 
 | 153 |  | 
 | 154 | 	at32_add_device_usart(0); | 
 | 155 |  | 
 | 156 | 	set_hw_addr(at32_add_device_eth(0, ð_data[0])); | 
 | 157 | 	set_hw_addr(at32_add_device_eth(1, ð_data[1])); | 
 | 158 |  | 
 | 159 | 	at32_add_device_spi(0, spi0_board_info, ARRAY_SIZE(spi0_board_info)); | 
| Haavard Skinnemoen | 6fcf061 | 2007-06-14 17:37:31 +0200 | [diff] [blame] | 160 | 	at32_add_device_usba(0, NULL); | 
| Haavard Skinnemoen | 9ca20a8 | 2007-04-12 17:26:57 +0200 | [diff] [blame] | 161 |  | 
| David Brownell | f9f451d | 2007-07-08 11:49:53 +0100 | [diff] [blame] | 162 | 	for (i = 0; i < ARRAY_SIZE(ngw_leds); i++) { | 
 | 163 | 		at32_select_gpio(ngw_leds[i].gpio, | 
 | 164 | 				AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH); | 
 | 165 | 	} | 
 | 166 | 	platform_device_register(&ngw_gpio_leds); | 
 | 167 |  | 
| David Brownell | 82c54f8 | 2007-09-25 07:17:48 -0700 | [diff] [blame] | 168 | 	at32_select_gpio(i2c_gpio_data.sda_pin, | 
 | 169 | 		AT32_GPIOF_MULTIDRV | AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH); | 
 | 170 | 	at32_select_gpio(i2c_gpio_data.scl_pin, | 
 | 171 | 		AT32_GPIOF_MULTIDRV | AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH); | 
| Haavard Skinnemoen | 54bb69e | 2007-07-12 16:36:34 +0200 | [diff] [blame] | 172 | 	platform_device_register(&i2c_gpio_device); | 
 | 173 |  | 
| Haavard Skinnemoen | 9ca20a8 | 2007-04-12 17:26:57 +0200 | [diff] [blame] | 174 | 	return 0; | 
 | 175 | } | 
 | 176 | postcore_initcall(atngw100_init); |