blob: abcb0d9559b15b5bf53d03259936a4396393dd03 [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>
22
Haavard Skinnemoen7d2be072008-06-30 18:35:03 +020023#include <asm/atmel-mci.h>
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +020024#include <asm/io.h>
25#include <asm/setup.h>
26
Haavard Skinnemoen3663b732008-08-05 13:57:38 +020027#include <mach/at32ap700x.h>
28#include <mach/board.h>
29#include <mach/init.h>
30#include <mach/portmux.h>
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +020031
Alex60ed7952008-03-17 14:55:06 +010032/* Oscillator frequencies. These are board-specific */
33unsigned long at32_board_osc_rates[3] = {
34 [0] = 32768, /* 32.768 kHz on RTC osc */
35 [1] = 20000000, /* 20 MHz on osc0 */
36 [2] = 12000000, /* 12 MHz on osc1 */
37};
38
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +020039/* Initialized by bootloader-specific startup code. */
40struct tag *bootloader_tags __initdata;
41
42struct eth_addr {
43 u8 addr[6];
44};
45static struct eth_addr __initdata hw_addr[2];
46static struct eth_platform_data __initdata eth_data[2];
47
48static struct spi_board_info spi0_board_info[] __initdata = {
49 {
50 .modalias = "mtd_dataflash",
Haavard Skinnemoen0fe94972008-08-01 17:06:01 +020051 .max_speed_hz = 8000000,
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +020052 .chip_select = 0,
53 },
54};
55
Haavard Skinnemoen7d2be072008-06-30 18:35:03 +020056static struct mci_platform_data __initdata mci0_data = {
57 .detect_pin = GPIO_PIN_PC(25),
58 .wp_pin = GPIO_PIN_PE(0),
59};
60
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +020061/*
62 * The next two functions should go away as the boot loader is
63 * supposed to initialize the macb address registers with a valid
64 * ethernet address. But we need to keep it around for a while until
65 * we can be reasonably sure the boot loader does this.
66 *
67 * The phy_id is ignored as the driver will probe for it.
68 */
69static int __init parse_tag_ethernet(struct tag *tag)
70{
71 int i;
72
73 i = tag->u.ethernet.mac_index;
74 if (i < ARRAY_SIZE(hw_addr))
75 memcpy(hw_addr[i].addr, tag->u.ethernet.hw_address,
76 sizeof(hw_addr[i].addr));
77
78 return 0;
79}
80__tagtable(ATAG_ETHERNET, parse_tag_ethernet);
81
82static void __init set_hw_addr(struct platform_device *pdev)
83{
84 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
85 const u8 *addr;
86 void __iomem *regs;
87 struct clk *pclk;
88
89 if (!res)
90 return;
91 if (pdev->id >= ARRAY_SIZE(hw_addr))
92 return;
93
94 addr = hw_addr[pdev->id].addr;
95 if (!is_valid_ether_addr(addr))
96 return;
97
98 /*
99 * Since this is board-specific code, we'll cheat and use the
100 * physical address directly as we happen to know that it's
101 * the same as the virtual address.
102 */
103 regs = (void __iomem __force *)res->start;
104 pclk = clk_get(&pdev->dev, "pclk");
105 if (!pclk)
106 return;
107
108 clk_enable(pclk);
109 __raw_writel((addr[3] << 24) | (addr[2] << 16)
110 | (addr[1] << 8) | addr[0], regs + 0x98);
111 __raw_writel((addr[5] << 8) | addr[4], regs + 0x9c);
112 clk_disable(pclk);
113 clk_put(pclk);
114}
115
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +0200116void __init setup_board(void)
117{
118 at32_map_usart(1, 0); /* USART 1: /dev/ttyS0, DB9 */
119 at32_setup_serial_console(0);
120}
121
David Brownellf9f451d2007-07-08 11:49:53 +0100122static const struct gpio_led ngw_leds[] = {
123 { .name = "sys", .gpio = GPIO_PIN_PA(16), .active_low = 1,
124 .default_trigger = "heartbeat",
125 },
126 { .name = "a", .gpio = GPIO_PIN_PA(19), .active_low = 1, },
127 { .name = "b", .gpio = GPIO_PIN_PE(19), .active_low = 1, },
128};
129
130static const struct gpio_led_platform_data ngw_led_data = {
131 .num_leds = ARRAY_SIZE(ngw_leds),
132 .leds = (void *) ngw_leds,
133};
134
135static struct platform_device ngw_gpio_leds = {
136 .name = "leds-gpio",
137 .id = -1,
138 .dev = {
139 .platform_data = (void *) &ngw_led_data,
140 }
141};
142
Haavard Skinnemoen54bb69e2007-07-12 16:36:34 +0200143static struct i2c_gpio_platform_data i2c_gpio_data = {
David Brownell82c54f82007-09-25 07:17:48 -0700144 .sda_pin = GPIO_PIN_PA(6),
145 .scl_pin = GPIO_PIN_PA(7),
146 .sda_is_open_drain = 1,
147 .scl_is_open_drain = 1,
148 .udelay = 2, /* close to 100 kHz */
Haavard Skinnemoen54bb69e2007-07-12 16:36:34 +0200149};
150
151static struct platform_device i2c_gpio_device = {
152 .name = "i2c-gpio",
153 .id = 0,
154 .dev = {
155 .platform_data = &i2c_gpio_data,
156 },
157};
158
David Brownell7ef31e92008-06-12 12:18:05 -0700159static struct i2c_board_info __initdata i2c_info[] = {
160 /* NOTE: original ATtiny24 firmware is at address 0x0b */
161};
162
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +0200163static int __init atngw100_init(void)
164{
David Brownellf9f451d2007-07-08 11:49:53 +0100165 unsigned i;
166
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +0200167 /*
168 * ATNGW100 uses 16-bit SDRAM interface, so we don't need to
169 * reserve any pins for it.
170 */
171
172 at32_add_system_devices();
173
174 at32_add_device_usart(0);
175
176 set_hw_addr(at32_add_device_eth(0, &eth_data[0]));
177 set_hw_addr(at32_add_device_eth(1, &eth_data[1]));
178
179 at32_add_device_spi(0, spi0_board_info, ARRAY_SIZE(spi0_board_info));
Haavard Skinnemoen7d2be072008-06-30 18:35:03 +0200180 at32_add_device_mci(0, &mci0_data);
Haavard Skinnemoen6fcf0612007-06-14 17:37:31 +0200181 at32_add_device_usba(0, NULL);
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +0200182
David Brownellf9f451d2007-07-08 11:49:53 +0100183 for (i = 0; i < ARRAY_SIZE(ngw_leds); i++) {
184 at32_select_gpio(ngw_leds[i].gpio,
185 AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
186 }
187 platform_device_register(&ngw_gpio_leds);
188
David Brownell7ef31e92008-06-12 12:18:05 -0700189 /* all these i2c/smbus pins should have external pullups for
190 * open-drain sharing among all I2C devices. SDA and SCL do;
191 * PB28/EXTINT3 doesn't; it should be SMBALERT# (for PMBus),
192 * but it's not available off-board.
193 */
194 at32_select_periph(GPIO_PIN_PB(28), 0, AT32_GPIOF_PULLUP);
David Brownell82c54f82007-09-25 07:17:48 -0700195 at32_select_gpio(i2c_gpio_data.sda_pin,
196 AT32_GPIOF_MULTIDRV | AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
197 at32_select_gpio(i2c_gpio_data.scl_pin,
198 AT32_GPIOF_MULTIDRV | AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
Haavard Skinnemoen54bb69e2007-07-12 16:36:34 +0200199 platform_device_register(&i2c_gpio_device);
David Brownell7ef31e92008-06-12 12:18:05 -0700200 i2c_register_board_info(0, i2c_info, ARRAY_SIZE(i2c_info));
Haavard Skinnemoen54bb69e2007-07-12 16:36:34 +0200201
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +0200202 return 0;
203}
204postcore_initcall(atngw100_init);
David Brownell7ef31e92008-06-12 12:18:05 -0700205
206static int __init atngw100_arch_init(void)
207{
David Brownell96706602008-09-06 20:19:02 -0700208 /* PB30 is the otherwise unused jumper on the mainboard, with an
209 * external pullup; the jumper grounds it. Use it however you
210 * like, including letting U-Boot or Linux tweak boot sequences.
211 */
212 at32_select_gpio(GPIO_PIN_PB(30), 0);
213 gpio_request(GPIO_PIN_PB(30), "j15");
214 gpio_direction_input(GPIO_PIN_PB(30));
215 gpio_export(GPIO_PIN_PB(30), false);
216
David Brownell7ef31e92008-06-12 12:18:05 -0700217 /* set_irq_type() after the arch_initcall for EIC has run, and
218 * before the I2C subsystem could try using this IRQ.
219 */
220 return set_irq_type(AT32_EXTINT(3), IRQ_TYPE_EDGE_FALLING);
221}
222arch_initcall(atngw100_arch_init);