blob: 00ce961c52a5add473a2839b7fc026ee878fd15e [file] [log] [blame]
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +02001/*
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 Skinnemoen54bb69e2007-07-12 16:36:34 +020012#include <linux/i2c-gpio.h>
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +020013#include <linux/init.h>
14#include <linux/linkage.h>
15#include <linux/platform_device.h>
16#include <linux/types.h>
David Brownellf9f451d2007-07-08 11:49:53 +010017#include <linux/leds.h>
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +020018#include <linux/spi/spi.h>
19
20#include <asm/io.h>
21#include <asm/setup.h>
22
Haavard Skinnemoen438ff3f2007-10-29 15:28:07 +010023#include <asm/arch/at32ap700x.h>
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +020024#include <asm/arch/board.h>
25#include <asm/arch/init.h>
David Brownellf9f451d2007-07-08 11:49:53 +010026#include <asm/arch/portmux.h>
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +020027
Alex60ed7952008-03-17 14:55:06 +010028/* Oscillator frequencies. These are board-specific */
29unsigned long at32_board_osc_rates[3] = {
30 [0] = 32768, /* 32.768 kHz on RTC osc */
31 [1] = 20000000, /* 20 MHz on osc0 */
32 [2] = 12000000, /* 12 MHz on osc1 */
33};
34
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +020035/* Initialized by bootloader-specific startup code. */
36struct tag *bootloader_tags __initdata;
37
38struct eth_addr {
39 u8 addr[6];
40};
41static struct eth_addr __initdata hw_addr[2];
42static struct eth_platform_data __initdata eth_data[2];
43
44static struct spi_board_info spi0_board_info[] __initdata = {
45 {
46 .modalias = "mtd_dataflash",
47 .max_speed_hz = 10000000,
48 .chip_select = 0,
49 },
50};
51
52/*
53 * The next two functions should go away as the boot loader is
54 * supposed to initialize the macb address registers with a valid
55 * ethernet address. But we need to keep it around for a while until
56 * we can be reasonably sure the boot loader does this.
57 *
58 * The phy_id is ignored as the driver will probe for it.
59 */
60static int __init parse_tag_ethernet(struct tag *tag)
61{
62 int i;
63
64 i = tag->u.ethernet.mac_index;
65 if (i < ARRAY_SIZE(hw_addr))
66 memcpy(hw_addr[i].addr, tag->u.ethernet.hw_address,
67 sizeof(hw_addr[i].addr));
68
69 return 0;
70}
71__tagtable(ATAG_ETHERNET, parse_tag_ethernet);
72
73static void __init set_hw_addr(struct platform_device *pdev)
74{
75 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
76 const u8 *addr;
77 void __iomem *regs;
78 struct clk *pclk;
79
80 if (!res)
81 return;
82 if (pdev->id >= ARRAY_SIZE(hw_addr))
83 return;
84
85 addr = hw_addr[pdev->id].addr;
86 if (!is_valid_ether_addr(addr))
87 return;
88
89 /*
90 * Since this is board-specific code, we'll cheat and use the
91 * physical address directly as we happen to know that it's
92 * the same as the virtual address.
93 */
94 regs = (void __iomem __force *)res->start;
95 pclk = clk_get(&pdev->dev, "pclk");
96 if (!pclk)
97 return;
98
99 clk_enable(pclk);
100 __raw_writel((addr[3] << 24) | (addr[2] << 16)
101 | (addr[1] << 8) | addr[0], regs + 0x98);
102 __raw_writel((addr[5] << 8) | addr[4], regs + 0x9c);
103 clk_disable(pclk);
104 clk_put(pclk);
105}
106
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +0200107void __init setup_board(void)
108{
109 at32_map_usart(1, 0); /* USART 1: /dev/ttyS0, DB9 */
110 at32_setup_serial_console(0);
111}
112
David Brownellf9f451d2007-07-08 11:49:53 +0100113static const struct gpio_led ngw_leds[] = {
114 { .name = "sys", .gpio = GPIO_PIN_PA(16), .active_low = 1,
115 .default_trigger = "heartbeat",
116 },
117 { .name = "a", .gpio = GPIO_PIN_PA(19), .active_low = 1, },
118 { .name = "b", .gpio = GPIO_PIN_PE(19), .active_low = 1, },
119};
120
121static const struct gpio_led_platform_data ngw_led_data = {
122 .num_leds = ARRAY_SIZE(ngw_leds),
123 .leds = (void *) ngw_leds,
124};
125
126static struct platform_device ngw_gpio_leds = {
127 .name = "leds-gpio",
128 .id = -1,
129 .dev = {
130 .platform_data = (void *) &ngw_led_data,
131 }
132};
133
Haavard Skinnemoen54bb69e2007-07-12 16:36:34 +0200134static struct i2c_gpio_platform_data i2c_gpio_data = {
David Brownell82c54f82007-09-25 07:17:48 -0700135 .sda_pin = GPIO_PIN_PA(6),
136 .scl_pin = GPIO_PIN_PA(7),
137 .sda_is_open_drain = 1,
138 .scl_is_open_drain = 1,
139 .udelay = 2, /* close to 100 kHz */
Haavard Skinnemoen54bb69e2007-07-12 16:36:34 +0200140};
141
142static struct platform_device i2c_gpio_device = {
143 .name = "i2c-gpio",
144 .id = 0,
145 .dev = {
146 .platform_data = &i2c_gpio_data,
147 },
148};
149
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +0200150static int __init atngw100_init(void)
151{
David Brownellf9f451d2007-07-08 11:49:53 +0100152 unsigned i;
153
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +0200154 /*
155 * ATNGW100 uses 16-bit SDRAM interface, so we don't need to
156 * reserve any pins for it.
157 */
158
159 at32_add_system_devices();
160
161 at32_add_device_usart(0);
162
163 set_hw_addr(at32_add_device_eth(0, &eth_data[0]));
164 set_hw_addr(at32_add_device_eth(1, &eth_data[1]));
165
166 at32_add_device_spi(0, spi0_board_info, ARRAY_SIZE(spi0_board_info));
Haavard Skinnemoen6fcf0612007-06-14 17:37:31 +0200167 at32_add_device_usba(0, NULL);
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +0200168
David Brownellf9f451d2007-07-08 11:49:53 +0100169 for (i = 0; i < ARRAY_SIZE(ngw_leds); i++) {
170 at32_select_gpio(ngw_leds[i].gpio,
171 AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
172 }
173 platform_device_register(&ngw_gpio_leds);
174
David Brownell82c54f82007-09-25 07:17:48 -0700175 at32_select_gpio(i2c_gpio_data.sda_pin,
176 AT32_GPIOF_MULTIDRV | AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
177 at32_select_gpio(i2c_gpio_data.scl_pin,
178 AT32_GPIOF_MULTIDRV | AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
Haavard Skinnemoen54bb69e2007-07-12 16:36:34 +0200179 platform_device_register(&i2c_gpio_device);
180
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +0200181 return 0;
182}
183postcore_initcall(atngw100_init);