blob: f3085208959f13e01162d138dd50fbf496869ab2 [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 Brownell7ef31e92008-06-12 12:18:05 -070012#include <linux/irq.h>
13#include <linux/i2c.h>
Haavard Skinnemoen54bb69e2007-07-12 16:36:34 +020014#include <linux/i2c-gpio.h>
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +020015#include <linux/init.h>
16#include <linux/linkage.h>
17#include <linux/platform_device.h>
18#include <linux/types.h>
David Brownellf9f451d2007-07-08 11:49:53 +010019#include <linux/leds.h>
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +020020#include <linux/spi/spi.h>
21
Haavard Skinnemoen7d2be072008-06-30 18:35:03 +020022#include <asm/atmel-mci.h>
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +020023#include <asm/io.h>
24#include <asm/setup.h>
25
Haavard Skinnemoen3663b732008-08-05 13:57:38 +020026#include <mach/at32ap700x.h>
27#include <mach/board.h>
28#include <mach/init.h>
29#include <mach/portmux.h>
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +020030
Alex60ed7952008-03-17 14:55:06 +010031/* Oscillator frequencies. These are board-specific */
32unsigned long at32_board_osc_rates[3] = {
33 [0] = 32768, /* 32.768 kHz on RTC osc */
34 [1] = 20000000, /* 20 MHz on osc0 */
35 [2] = 12000000, /* 12 MHz on osc1 */
36};
37
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +020038/* Initialized by bootloader-specific startup code. */
39struct tag *bootloader_tags __initdata;
40
41struct eth_addr {
42 u8 addr[6];
43};
44static struct eth_addr __initdata hw_addr[2];
45static struct eth_platform_data __initdata eth_data[2];
46
47static struct spi_board_info spi0_board_info[] __initdata = {
48 {
49 .modalias = "mtd_dataflash",
Haavard Skinnemoen0fe94972008-08-01 17:06:01 +020050 .max_speed_hz = 8000000,
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +020051 .chip_select = 0,
52 },
53};
54
Haavard Skinnemoen7d2be072008-06-30 18:35:03 +020055static struct mci_platform_data __initdata mci0_data = {
Haavard Skinnemoen6b918652008-08-07 14:08:49 +020056 .slot[0] = {
57 .bus_width = 4,
58 .detect_pin = GPIO_PIN_PC(25),
59 .wp_pin = GPIO_PIN_PE(0),
60 },
Haavard Skinnemoen7d2be072008-06-30 18:35:03 +020061};
62
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +020063/*
64 * The next two functions should go away as the boot loader is
65 * supposed to initialize the macb address registers with a valid
66 * ethernet address. But we need to keep it around for a while until
67 * we can be reasonably sure the boot loader does this.
68 *
69 * The phy_id is ignored as the driver will probe for it.
70 */
71static int __init parse_tag_ethernet(struct tag *tag)
72{
73 int i;
74
75 i = tag->u.ethernet.mac_index;
76 if (i < ARRAY_SIZE(hw_addr))
77 memcpy(hw_addr[i].addr, tag->u.ethernet.hw_address,
78 sizeof(hw_addr[i].addr));
79
80 return 0;
81}
82__tagtable(ATAG_ETHERNET, parse_tag_ethernet);
83
84static void __init set_hw_addr(struct platform_device *pdev)
85{
86 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
87 const u8 *addr;
88 void __iomem *regs;
89 struct clk *pclk;
90
91 if (!res)
92 return;
93 if (pdev->id >= ARRAY_SIZE(hw_addr))
94 return;
95
96 addr = hw_addr[pdev->id].addr;
97 if (!is_valid_ether_addr(addr))
98 return;
99
100 /*
101 * Since this is board-specific code, we'll cheat and use the
102 * physical address directly as we happen to know that it's
103 * the same as the virtual address.
104 */
105 regs = (void __iomem __force *)res->start;
106 pclk = clk_get(&pdev->dev, "pclk");
107 if (!pclk)
108 return;
109
110 clk_enable(pclk);
111 __raw_writel((addr[3] << 24) | (addr[2] << 16)
112 | (addr[1] << 8) | addr[0], regs + 0x98);
113 __raw_writel((addr[5] << 8) | addr[4], regs + 0x9c);
114 clk_disable(pclk);
115 clk_put(pclk);
116}
117
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +0200118void __init setup_board(void)
119{
120 at32_map_usart(1, 0); /* USART 1: /dev/ttyS0, DB9 */
121 at32_setup_serial_console(0);
122}
123
David Brownellf9f451d2007-07-08 11:49:53 +0100124static const struct gpio_led ngw_leds[] = {
125 { .name = "sys", .gpio = GPIO_PIN_PA(16), .active_low = 1,
126 .default_trigger = "heartbeat",
127 },
128 { .name = "a", .gpio = GPIO_PIN_PA(19), .active_low = 1, },
129 { .name = "b", .gpio = GPIO_PIN_PE(19), .active_low = 1, },
130};
131
132static const struct gpio_led_platform_data ngw_led_data = {
133 .num_leds = ARRAY_SIZE(ngw_leds),
134 .leds = (void *) ngw_leds,
135};
136
137static struct platform_device ngw_gpio_leds = {
138 .name = "leds-gpio",
139 .id = -1,
140 .dev = {
141 .platform_data = (void *) &ngw_led_data,
142 }
143};
144
Haavard Skinnemoen54bb69e2007-07-12 16:36:34 +0200145static struct i2c_gpio_platform_data i2c_gpio_data = {
David Brownell82c54f82007-09-25 07:17:48 -0700146 .sda_pin = GPIO_PIN_PA(6),
147 .scl_pin = GPIO_PIN_PA(7),
148 .sda_is_open_drain = 1,
149 .scl_is_open_drain = 1,
150 .udelay = 2, /* close to 100 kHz */
Haavard Skinnemoen54bb69e2007-07-12 16:36:34 +0200151};
152
153static struct platform_device i2c_gpio_device = {
154 .name = "i2c-gpio",
155 .id = 0,
156 .dev = {
157 .platform_data = &i2c_gpio_data,
158 },
159};
160
David Brownell7ef31e92008-06-12 12:18:05 -0700161static struct i2c_board_info __initdata i2c_info[] = {
162 /* NOTE: original ATtiny24 firmware is at address 0x0b */
163};
164
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +0200165static int __init atngw100_init(void)
166{
David Brownellf9f451d2007-07-08 11:49:53 +0100167 unsigned i;
168
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +0200169 /*
170 * ATNGW100 uses 16-bit SDRAM interface, so we don't need to
171 * reserve any pins for it.
172 */
173
174 at32_add_system_devices();
175
176 at32_add_device_usart(0);
177
178 set_hw_addr(at32_add_device_eth(0, &eth_data[0]));
179 set_hw_addr(at32_add_device_eth(1, &eth_data[1]));
180
181 at32_add_device_spi(0, spi0_board_info, ARRAY_SIZE(spi0_board_info));
Haavard Skinnemoen7d2be072008-06-30 18:35:03 +0200182 at32_add_device_mci(0, &mci0_data);
Haavard Skinnemoen6fcf0612007-06-14 17:37:31 +0200183 at32_add_device_usba(0, NULL);
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +0200184
David Brownellf9f451d2007-07-08 11:49:53 +0100185 for (i = 0; i < ARRAY_SIZE(ngw_leds); i++) {
186 at32_select_gpio(ngw_leds[i].gpio,
187 AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
188 }
189 platform_device_register(&ngw_gpio_leds);
190
David Brownell7ef31e92008-06-12 12:18:05 -0700191 /* all these i2c/smbus pins should have external pullups for
192 * open-drain sharing among all I2C devices. SDA and SCL do;
193 * PB28/EXTINT3 doesn't; it should be SMBALERT# (for PMBus),
194 * but it's not available off-board.
195 */
196 at32_select_periph(GPIO_PIN_PB(28), 0, AT32_GPIOF_PULLUP);
David Brownell82c54f82007-09-25 07:17:48 -0700197 at32_select_gpio(i2c_gpio_data.sda_pin,
198 AT32_GPIOF_MULTIDRV | AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
199 at32_select_gpio(i2c_gpio_data.scl_pin,
200 AT32_GPIOF_MULTIDRV | AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
Haavard Skinnemoen54bb69e2007-07-12 16:36:34 +0200201 platform_device_register(&i2c_gpio_device);
David Brownell7ef31e92008-06-12 12:18:05 -0700202 i2c_register_board_info(0, i2c_info, ARRAY_SIZE(i2c_info));
Haavard Skinnemoen54bb69e2007-07-12 16:36:34 +0200203
Haavard Skinnemoen9ca20a82007-04-12 17:26:57 +0200204 return 0;
205}
206postcore_initcall(atngw100_init);
David Brownell7ef31e92008-06-12 12:18:05 -0700207
208static int __init atngw100_arch_init(void)
209{
210 /* set_irq_type() after the arch_initcall for EIC has run, and
211 * before the I2C subsystem could try using this IRQ.
212 */
213 return set_irq_type(AT32_EXTINT(3), IRQ_TYPE_EDGE_FALLING);
214}
215arch_initcall(atngw100_arch_init);