1/*
2 * linux/arch/arm/mach-at91/board-sam9261ek.c
3 *
4 *  Copyright (C) 2005 SAN People
5 *  Copyright (C) 2006 Atmel
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20 */
21
22#include <linux/types.h>
23#include <linux/init.h>
24#include <linux/mm.h>
25#include <linux/module.h>
26#include <linux/platform_device.h>
27#include <linux/spi/spi.h>
28#include <linux/spi/ads7846.h>
29#include <linux/dm9000.h>
30
31#include <asm/hardware.h>
32#include <asm/setup.h>
33#include <asm/mach-types.h>
34#include <asm/irq.h>
35
36#include <asm/mach/arch.h>
37#include <asm/mach/map.h>
38#include <asm/mach/irq.h>
39
40#include <asm/arch/board.h>
41#include <asm/arch/gpio.h>
42#include <asm/arch/at91sam926x_mc.h>
43
44#include "generic.h"
45
46
47/*
48 * Serial port configuration.
49 *    0 .. 2 = USART0 .. USART2
50 *    3      = DBGU
51 */
52static struct at91_uart_config __initdata ek_uart_config = {
53	.console_tty	= 0,				/* ttyS0 */
54	.nr_tty		= 1,
55	.tty_map	= { 3, -1, -1, -1 }		/* ttyS0, ..., ttyS3 */
56};
57
58static void __init ek_map_io(void)
59{
60	/* Initialize processor: 18.432 MHz crystal */
61	at91sam9261_initialize(18432000);
62
63	/* Setup the LEDs */
64	at91_init_leds(AT91_PIN_PA13, AT91_PIN_PA14);
65
66	/* Setup the serial ports and console */
67	at91_init_serial(&ek_uart_config);
68}
69
70static void __init ek_init_irq(void)
71{
72	at91sam9261_init_interrupts(NULL);
73}
74
75
76/*
77 * DM9000 ethernet device
78 */
79#if defined(CONFIG_DM9000)
80static struct resource at91sam9261_dm9000_resource[] = {
81	[0] = {
82		.start	= AT91_CHIPSELECT_2,
83		.end	= AT91_CHIPSELECT_2 + 3,
84		.flags	= IORESOURCE_MEM
85	},
86	[1] = {
87		.start	= AT91_CHIPSELECT_2 + 0x44,
88		.end	= AT91_CHIPSELECT_2 + 0xFF,
89		.flags	= IORESOURCE_MEM
90	},
91	[2] = {
92		.start	= AT91_PIN_PC11,
93		.end	= AT91_PIN_PC11,
94		.flags	= IORESOURCE_IRQ
95	}
96};
97
98static struct dm9000_plat_data dm9000_platdata = {
99	.flags		= DM9000_PLATF_16BITONLY,
100};
101
102static struct platform_device at91sam9261_dm9000_device = {
103	.name		= "dm9000",
104	.id		= 0,
105	.num_resources	= ARRAY_SIZE(at91sam9261_dm9000_resource),
106	.resource	= at91sam9261_dm9000_resource,
107	.dev		= {
108		.platform_data	= &dm9000_platdata,
109	}
110};
111
112static void __init ek_add_device_dm9000(void)
113{
114	/*
115	 * Configure Chip-Select 2 on SMC for the DM9000.
116	 * Note: These timings were calculated for MASTER_CLOCK = 100000000
117	 *  according to the DM9000 timings.
118	 */
119	at91_sys_write(AT91_SMC_SETUP(2), AT91_SMC_NWESETUP_(2) | AT91_SMC_NCS_WRSETUP_(0) | AT91_SMC_NRDSETUP_(2) | AT91_SMC_NCS_RDSETUP_(0));
120	at91_sys_write(AT91_SMC_PULSE(2), AT91_SMC_NWEPULSE_(4) | AT91_SMC_NCS_WRPULSE_(8) | AT91_SMC_NRDPULSE_(4) | AT91_SMC_NCS_RDPULSE_(8));
121	at91_sys_write(AT91_SMC_CYCLE(2), AT91_SMC_NWECYCLE_(16) | AT91_SMC_NRDCYCLE_(16));
122	at91_sys_write(AT91_SMC_MODE(2), AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_BAT_WRITE | AT91_SMC_DBW_16 | AT91_SMC_TDF_(1));
123
124	/* Configure Reset signal as output */
125	at91_set_gpio_output(AT91_PIN_PC10, 0);
126
127	/* Configure Interrupt pin as input, no pull-up */
128	at91_set_gpio_input(AT91_PIN_PC11, 0);
129
130	platform_device_register(&at91sam9261_dm9000_device);
131}
132#else
133static void __init ek_add_device_dm9000(void) {}
134#endif /* CONFIG_DM9000 */
135
136
137/*
138 * USB Host Port
139 */
140static struct at91_usbh_data __initdata ek_usbh_data = {
141	.ports		= 2,
142};
143
144
145/*
146 * USB Device Port
147 */
148static struct at91_udc_data __initdata ek_udc_data = {
149	.vbus_pin	= AT91_PIN_PB29,
150	.pullup_pin	= 0,		/* pull-up driven by UDC */
151};
152
153
154/*
155 * MCI (SD/MMC)
156 */
157static struct at91_mmc_data __initdata ek_mmc_data = {
158	.wire4		= 1,
159//	.det_pin	= ... not connected
160//	.wp_pin		= ... not connected
161//	.vcc_pin	= ... not connected
162};
163
164
165/*
166 * NAND flash
167 */
168static struct mtd_partition __initdata ek_nand_partition[] = {
169	{
170		.name	= "Partition 1",
171		.offset	= 0,
172		.size	= 256 * 1024,
173	},
174	{
175		.name	= "Partition 2",
176		.offset	= 256 * 1024 ,
177		.size	= MTDPART_SIZ_FULL,
178	},
179};
180
181static struct mtd_partition * __init nand_partitions(int size, int *num_partitions)
182{
183	*num_partitions = ARRAY_SIZE(ek_nand_partition);
184	return ek_nand_partition;
185}
186
187static struct at91_nand_data __initdata ek_nand_data = {
188	.ale		= 22,
189	.cle		= 21,
190//	.det_pin	= ... not connected
191	.rdy_pin	= AT91_PIN_PC15,
192	.enable_pin	= AT91_PIN_PC14,
193	.partition_info	= nand_partitions,
194#if defined(CONFIG_MTD_NAND_AT91_BUSWIDTH_16)
195	.bus_width_16	= 1,
196#else
197	.bus_width_16	= 0,
198#endif
199};
200
201/*
202 * ADS7846 Touchscreen
203 */
204#if defined(CONFIG_TOUCHSCREEN_ADS7846) || defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
205
206static int ads7843_pendown_state(void)
207{
208	return !at91_get_gpio_value(AT91_PIN_PC2);	/* Touchscreen PENIRQ */
209}
210
211static struct ads7846_platform_data ads_info = {
212	.model			= 7843,
213	.x_min			= 150,
214	.x_max			= 3830,
215	.y_min			= 190,
216	.y_max			= 3830,
217	.vref_delay_usecs	= 100,
218	.x_plate_ohms		= 450,
219	.y_plate_ohms		= 250,
220	.pressure_max		= 15000,
221	.debounce_max		= 1,
222	.debounce_rep		= 0,
223	.debounce_tol		= (~0),
224	.get_pendown_state	= ads7843_pendown_state,
225};
226
227static void __init ek_add_device_ts(void)
228{
229	at91_set_B_periph(AT91_PIN_PC2, 1);	/* External IRQ0, with pullup */
230	at91_set_gpio_input(AT91_PIN_PA11, 1);	/* Touchscreen BUSY signal */
231}
232#else
233static void __init ek_add_device_ts(void) {}
234#endif
235
236/*
237 * SPI devices
238 */
239static struct spi_board_info ek_spi_devices[] = {
240	{	/* DataFlash chip */
241		.modalias	= "mtd_dataflash",
242		.chip_select	= 0,
243		.max_speed_hz	= 15 * 1000 * 1000,
244		.bus_num	= 0,
245	},
246#if defined(CONFIG_TOUCHSCREEN_ADS7846) || defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
247	{
248		.modalias	= "ads7846",
249		.chip_select	= 2,
250		.max_speed_hz	= 125000 * 26,	/* (max sample rate @ 3V) * (cmd + data + overhead) */
251		.bus_num	= 0,
252		.platform_data	= &ads_info,
253		.irq		= AT91SAM9261_ID_IRQ0,
254	},
255#endif
256#if defined(CONFIG_MTD_AT91_DATAFLASH_CARD)
257	{	/* DataFlash card - jumper (J12) configurable to CS3 or CS0 */
258		.modalias	= "mtd_dataflash",
259		.chip_select	= 3,
260		.max_speed_hz	= 15 * 1000 * 1000,
261		.bus_num	= 0,
262	},
263#elif defined(CONFIG_SND_AT73C213) || defined(CONFIG_SND_AT73C213_MODULE)
264	{	/* AT73C213 DAC */
265		.modalias	= "at73c213",
266		.chip_select	= 3,
267		.max_speed_hz	= 10 * 1000 * 1000,
268		.bus_num	= 0,
269	},
270#endif
271};
272
273
274static void __init ek_board_init(void)
275{
276	/* Serial */
277	at91_add_device_serial();
278	/* USB Host */
279	at91_add_device_usbh(&ek_usbh_data);
280	/* USB Device */
281	at91_add_device_udc(&ek_udc_data);
282	/* I2C */
283	at91_add_device_i2c();
284	/* NAND */
285	at91_add_device_nand(&ek_nand_data);
286	/* DM9000 ethernet */
287	ek_add_device_dm9000();
288
289	/* spi0 and mmc/sd share the same PIO pins */
290#if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
291	/* SPI */
292	at91_add_device_spi(ek_spi_devices, ARRAY_SIZE(ek_spi_devices));
293	/* Touchscreen */
294	ek_add_device_ts();
295#else
296	/* MMC */
297	at91_add_device_mmc(0, &ek_mmc_data);
298#endif
299}
300
301MACHINE_START(AT91SAM9261EK, "Atmel AT91SAM9261-EK")
302	/* Maintainer: Atmel */
303	.phys_io	= AT91_BASE_SYS,
304	.io_pg_offst	= (AT91_VA_BASE_SYS >> 18) & 0xfffc,
305	.boot_params	= AT91_SDRAM_BASE + 0x100,
306	.timer		= &at91sam926x_timer,
307	.map_io		= ek_map_io,
308	.init_irq	= ek_init_irq,
309	.init_machine	= ek_board_init,
310MACHINE_END
311