blob: 7c756fb189f713f3fd9d0b06de43530cb60833c1 [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>
David Brownell96706602008-09-06 20:19:02 -070012#include <linux/gpio.h>
David Brownell7ef31e92008-06-12 12:18:05 -070013#include <linux/irq.h>
14#include <linux/i2c.h>
Haavard Skinnemoen54bb69e2007-07-12 16:36:34 +020015#include <linux/i2c-gpio.h>
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +020016#include <linux/init.h>
17#include <linux/linkage.h>
18#include <linux/platform_device.h>
19#include <linux/types.h>
David Brownellf9f451d2007-07-08 11:49:53 +010020#include <linux/leds.h>
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +020021#include <linux/spi/spi.h>
Nicolas Ferrec42aa772008-11-20 15:59:12 +010022#include <linux/atmel-mci.h>
Hans-Christian Egtvedt3550b932009-12-03 14:58:20 +010023#include <linux/usb/atmel_usba_udc.h>
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +020024
25#include <asm/io.h>
26#include <asm/setup.h>
27
Haavard Skinnemoen3663b732008-08-05 13:57:38 +020028#include <mach/at32ap700x.h>
29#include <mach/board.h>
30#include <mach/init.h>
31#include <mach/portmux.h>
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +020032
Alex60ed7952008-03-17 14:55:06 +010033/* Oscillator frequencies. These are board-specific */
34unsigned long at32_board_osc_rates[3] = {
35 [0] = 32768, /* 32.768 kHz on RTC osc */
36 [1] = 20000000, /* 20 MHz on osc0 */
37 [2] = 12000000, /* 12 MHz on osc1 */
38};
39
Hans-Christian Egtvedt3550b932009-12-03 14:58:20 +010040/*
41 * The ATNGW100 mkII is very similar to the ATNGW100. Both have the AT32AP7000
42 * chip on board; the difference is that the ATNGW100 mkII has 128 MB 32-bit
43 * SDRAM (the ATNGW100 has 32 MB 16-bit SDRAM) and 256 MB 16-bit NAND flash
44 * (the ATNGW100 has none.)
45 *
46 * The RAM difference is handled by the boot loader, so the only difference we
47 * end up handling here is the NAND flash, EBI pin reservation and if LCDC or
48 * MACB1 should be enabled.
49 */
50#ifdef CONFIG_BOARD_ATNGW100_MKII
51#include <linux/mtd/partitions.h>
52#include <mach/smc.h>
53
54static struct smc_timing nand_timing __initdata = {
55 .ncs_read_setup = 0,
56 .nrd_setup = 10,
57 .ncs_write_setup = 0,
58 .nwe_setup = 10,
59
60 .ncs_read_pulse = 30,
61 .nrd_pulse = 15,
62 .ncs_write_pulse = 30,
63 .nwe_pulse = 15,
64
65 .read_cycle = 30,
66 .write_cycle = 30,
67
68 .ncs_read_recover = 0,
69 .nrd_recover = 15,
70 .ncs_write_recover = 0,
71 /* WE# high -> RE# low min 60 ns */
72 .nwe_recover = 50,
73};
74
75static struct smc_config nand_config __initdata = {
76 .bus_width = 2,
77 .nrd_controlled = 1,
78 .nwe_controlled = 1,
79 .nwait_mode = 0,
80 .byte_write = 0,
81 .tdf_cycles = 2,
82 .tdf_mode = 0,
83};
84
85static struct mtd_partition nand_partitions[] = {
86 {
87 .name = "main",
88 .offset = 0x00000000,
89 .size = MTDPART_SIZ_FULL,
90 },
91};
92
Hans-Christian Egtvedt3550b932009-12-03 14:58:20 +010093
94static struct atmel_nand_data atngw100mkii_nand_data __initdata = {
95 .cle = 21,
96 .ale = 22,
97 .rdy_pin = GPIO_PIN_PB(28),
98 .enable_pin = GPIO_PIN_PE(23),
99 .bus_width_16 = true,
Dmitry Eremin-Solenikov1754aab2011-05-29 17:49:22 +0400100 .parts = nand_partitions,
101 .num_parts = ARRAY_SIZE(nand_partitions),
Hans-Christian Egtvedt3550b932009-12-03 14:58:20 +0100102};
103#endif
104
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +0200105/* Initialized by bootloader-specific startup code. */
106struct tag *bootloader_tags __initdata;
107
108struct eth_addr {
109 u8 addr[6];
110};
111static struct eth_addr __initdata hw_addr[2];
Jamie Iles84e0cdb2011-03-08 20:17:06 +0000112static struct macb_platform_data __initdata eth_data[2];
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +0200113
114static struct spi_board_info spi0_board_info[] __initdata = {
115 {
116 .modalias = "mtd_dataflash",
Haavard Skinnemoen0fe94972008-08-01 17:06:01 +0200117 .max_speed_hz = 8000000,
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +0200118 .chip_select = 0,
119 },
120};
121
Haavard Skinnemoen7d2be072008-06-30 18:35:03 +0200122static struct mci_platform_data __initdata mci0_data = {
Haavard Skinnemoen6b918652008-08-07 14:08:49 +0200123 .slot[0] = {
124 .bus_width = 4,
Hans-Christian Egtvedt3550b932009-12-03 14:58:20 +0100125#if defined(CONFIG_BOARD_ATNGW100_MKII)
126 .detect_pin = GPIO_PIN_PC(25),
127 .wp_pin = GPIO_PIN_PE(22),
128#else
Haavard Skinnemoen6b918652008-08-07 14:08:49 +0200129 .detect_pin = GPIO_PIN_PC(25),
130 .wp_pin = GPIO_PIN_PE(0),
Hans-Christian Egtvedt3550b932009-12-03 14:58:20 +0100131#endif
Haavard Skinnemoen6b918652008-08-07 14:08:49 +0200132 },
Haavard Skinnemoen7d2be072008-06-30 18:35:03 +0200133};
134
Hans-Christian Egtvedt3550b932009-12-03 14:58:20 +0100135static struct usba_platform_data atngw100_usba_data __initdata = {
136#if defined(CONFIG_BOARD_ATNGW100_MKII)
137 .vbus_pin = GPIO_PIN_PE(26),
138#else
139 .vbus_pin = -ENODEV,
140#endif
141};
142
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +0200143/*
144 * The next two functions should go away as the boot loader is
145 * supposed to initialize the macb address registers with a valid
146 * ethernet address. But we need to keep it around for a while until
147 * we can be reasonably sure the boot loader does this.
148 *
149 * The phy_id is ignored as the driver will probe for it.
150 */
151static int __init parse_tag_ethernet(struct tag *tag)
152{
153 int i;
154
155 i = tag->u.ethernet.mac_index;
156 if (i < ARRAY_SIZE(hw_addr))
157 memcpy(hw_addr[i].addr, tag->u.ethernet.hw_address,
158 sizeof(hw_addr[i].addr));
159
160 return 0;
161}
162__tagtable(ATAG_ETHERNET, parse_tag_ethernet);
163
164static void __init set_hw_addr(struct platform_device *pdev)
165{
166 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
167 const u8 *addr;
168 void __iomem *regs;
169 struct clk *pclk;
170
171 if (!res)
172 return;
173 if (pdev->id >= ARRAY_SIZE(hw_addr))
174 return;
175
176 addr = hw_addr[pdev->id].addr;
177 if (!is_valid_ether_addr(addr))
178 return;
179
180 /*
181 * Since this is board-specific code, we'll cheat and use the
182 * physical address directly as we happen to know that it's
183 * the same as the virtual address.
184 */
185 regs = (void __iomem __force *)res->start;
186 pclk = clk_get(&pdev->dev, "pclk");
Vasiliy Kulikov36b471e2010-11-26 20:06:12 +0300187 if (IS_ERR(pclk))
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +0200188 return;
189
190 clk_enable(pclk);
191 __raw_writel((addr[3] << 24) | (addr[2] << 16)
192 | (addr[1] << 8) | addr[0], regs + 0x98);
193 __raw_writel((addr[5] << 8) | addr[4], regs + 0x9c);
194 clk_disable(pclk);
195 clk_put(pclk);
196}
197
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +0200198void __init setup_board(void)
199{
Peter Mabf4861c2009-03-31 10:31:02 -0700200 at32_map_usart(1, 0, 0); /* USART 1: /dev/ttyS0, DB9 */
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +0200201 at32_setup_serial_console(0);
202}
203
David Brownellf9f451d2007-07-08 11:49:53 +0100204static const struct gpio_led ngw_leds[] = {
205 { .name = "sys", .gpio = GPIO_PIN_PA(16), .active_low = 1,
206 .default_trigger = "heartbeat",
207 },
208 { .name = "a", .gpio = GPIO_PIN_PA(19), .active_low = 1, },
209 { .name = "b", .gpio = GPIO_PIN_PE(19), .active_low = 1, },
210};
211
212static const struct gpio_led_platform_data ngw_led_data = {
213 .num_leds = ARRAY_SIZE(ngw_leds),
214 .leds = (void *) ngw_leds,
215};
216
217static struct platform_device ngw_gpio_leds = {
218 .name = "leds-gpio",
219 .id = -1,
220 .dev = {
221 .platform_data = (void *) &ngw_led_data,
222 }
223};
224
Haavard Skinnemoen54bb69e2007-07-12 16:36:34 +0200225static struct i2c_gpio_platform_data i2c_gpio_data = {
David Brownell82c54f82007-09-25 07:17:48 -0700226 .sda_pin = GPIO_PIN_PA(6),
227 .scl_pin = GPIO_PIN_PA(7),
228 .sda_is_open_drain = 1,
229 .scl_is_open_drain = 1,
230 .udelay = 2, /* close to 100 kHz */
Haavard Skinnemoen54bb69e2007-07-12 16:36:34 +0200231};
232
233static struct platform_device i2c_gpio_device = {
234 .name = "i2c-gpio",
235 .id = 0,
236 .dev = {
237 .platform_data = &i2c_gpio_data,
238 },
239};
240
David Brownell7ef31e92008-06-12 12:18:05 -0700241static struct i2c_board_info __initdata i2c_info[] = {
242 /* NOTE: original ATtiny24 firmware is at address 0x0b */
243};
244
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +0200245static int __init atngw100_init(void)
246{
David Brownellf9f451d2007-07-08 11:49:53 +0100247 unsigned i;
248
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +0200249 /*
Hans-Christian Egtvedt3550b932009-12-03 14:58:20 +0100250 * ATNGW100 mkII uses 32-bit SDRAM interface. Reserve the
251 * SDRAM-specific pins so that nobody messes with them.
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +0200252 */
Hans-Christian Egtvedt3550b932009-12-03 14:58:20 +0100253#ifdef CONFIG_BOARD_ATNGW100_MKII
254 at32_reserve_pin(GPIO_PIOE_BASE, ATMEL_EBI_PE_DATA_ALL);
255
256 smc_set_timing(&nand_config, &nand_timing);
257 smc_set_configuration(3, &nand_config);
258 at32_add_device_nand(0, &atngw100mkii_nand_data);
259#endif
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +0200260
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +0200261 at32_add_device_usart(0);
262
263 set_hw_addr(at32_add_device_eth(0, &eth_data[0]));
Hans-Christian Egtvedt3550b932009-12-03 14:58:20 +0100264#ifndef CONFIG_BOARD_ATNGW100_MKII_LCD
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +0200265 set_hw_addr(at32_add_device_eth(1, &eth_data[1]));
Hans-Christian Egtvedt3550b932009-12-03 14:58:20 +0100266#endif
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +0200267
268 at32_add_device_spi(0, spi0_board_info, ARRAY_SIZE(spi0_board_info));
Haavard Skinnemoen7d2be072008-06-30 18:35:03 +0200269 at32_add_device_mci(0, &mci0_data);
Hans-Christian Egtvedt3550b932009-12-03 14:58:20 +0100270 at32_add_device_usba(0, &atngw100_usba_data);
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +0200271
David Brownellf9f451d2007-07-08 11:49:53 +0100272 for (i = 0; i < ARRAY_SIZE(ngw_leds); i++) {
273 at32_select_gpio(ngw_leds[i].gpio,
274 AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
275 }
276 platform_device_register(&ngw_gpio_leds);
277
David Brownell7ef31e92008-06-12 12:18:05 -0700278 /* all these i2c/smbus pins should have external pullups for
279 * open-drain sharing among all I2C devices. SDA and SCL do;
Hans-Christian Egtvedt3550b932009-12-03 14:58:20 +0100280 * PB28/EXTINT3 (ATNGW100) and PE21 (ATNGW100 mkII) doesn't; it should
281 * be SMBALERT# (for PMBus), but it's not available off-board.
David Brownell7ef31e92008-06-12 12:18:05 -0700282 */
Hans-Christian Egtvedt3550b932009-12-03 14:58:20 +0100283#ifdef CONFIG_BOARD_ATNGW100_MKII
284 at32_select_periph(GPIO_PIOE_BASE, 1 << 21, 0, AT32_GPIOF_PULLUP);
285#else
Julien Maycaf18f12008-09-24 10:30:47 +0200286 at32_select_periph(GPIO_PIOB_BASE, 1 << 28, 0, AT32_GPIOF_PULLUP);
Hans-Christian Egtvedt3550b932009-12-03 14:58:20 +0100287#endif
David Brownell82c54f82007-09-25 07:17:48 -0700288 at32_select_gpio(i2c_gpio_data.sda_pin,
289 AT32_GPIOF_MULTIDRV | AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
290 at32_select_gpio(i2c_gpio_data.scl_pin,
291 AT32_GPIOF_MULTIDRV | AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
Haavard Skinnemoen54bb69e2007-07-12 16:36:34 +0200292 platform_device_register(&i2c_gpio_device);
David Brownell7ef31e92008-06-12 12:18:05 -0700293 i2c_register_board_info(0, i2c_info, ARRAY_SIZE(i2c_info));
Haavard Skinnemoen54bb69e2007-07-12 16:36:34 +0200294
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +0200295 return 0;
296}
297postcore_initcall(atngw100_init);
David Brownell7ef31e92008-06-12 12:18:05 -0700298
299static int __init atngw100_arch_init(void)
300{
Hans-Christian Egtvedt3550b932009-12-03 14:58:20 +0100301 /* PB30 (ATNGW100) and PE30 (ATNGW100 mkII) is the otherwise unused
302 * jumper on the mainboard, with an external pullup; the jumper grounds
303 * it. Use it however you like, including letting U-Boot or Linux tweak
304 * boot sequences.
David Brownell96706602008-09-06 20:19:02 -0700305 */
Hans-Christian Egtvedt3550b932009-12-03 14:58:20 +0100306#ifdef CONFIG_BOARD_ATNGW100_MKII
307 at32_select_gpio(GPIO_PIN_PE(30), 0);
308 gpio_request(GPIO_PIN_PE(30), "j15");
309 gpio_direction_input(GPIO_PIN_PE(30));
310 gpio_export(GPIO_PIN_PE(30), false);
311#else
David Brownell96706602008-09-06 20:19:02 -0700312 at32_select_gpio(GPIO_PIN_PB(30), 0);
313 gpio_request(GPIO_PIN_PB(30), "j15");
314 gpio_direction_input(GPIO_PIN_PB(30));
315 gpio_export(GPIO_PIN_PB(30), false);
Hans-Christian Egtvedt3550b932009-12-03 14:58:20 +0100316#endif
David Brownell96706602008-09-06 20:19:02 -0700317
David Brownell7ef31e92008-06-12 12:18:05 -0700318 /* set_irq_type() after the arch_initcall for EIC has run, and
319 * before the I2C subsystem could try using this IRQ.
320 */
Thomas Gleixnerd75f1bf2011-03-24 16:39:32 +0100321 return irq_set_irq_type(AT32_EXTINT(3), IRQ_TYPE_EDGE_FALLING);
David Brownell7ef31e92008-06-12 12:18:05 -0700322}
323arch_initcall(atngw100_arch_init);