[ARM] 5290/1: [AT91] Add support for the Adeneo NeoCore 926 board
[safe/jmp/linux-2.6] / arch / arm / mach-at91 / board-cap9adk.c
1 /*
2  * linux/arch/arm/mach-at91/board-cap9adk.c
3  *
4  *  Copyright (C) 2007 Stelian Pop <stelian.pop@leadtechdesign.com>
5  *  Copyright (C) 2007 Lead Tech Design <www.leadtechdesign.com>
6  *  Copyright (C) 2005 SAN People
7  *  Copyright (C) 2007 Atmel Corporation.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23
24 #include <linux/types.h>
25 #include <linux/init.h>
26 #include <linux/mm.h>
27 #include <linux/module.h>
28 #include <linux/platform_device.h>
29 #include <linux/spi/spi.h>
30 #include <linux/spi/ads7846.h>
31 #include <linux/fb.h>
32 #include <linux/mtd/physmap.h>
33
34 #include <video/atmel_lcdc.h>
35
36 #include <mach/hardware.h>
37 #include <asm/setup.h>
38 #include <asm/mach-types.h>
39 #include <asm/irq.h>
40
41 #include <asm/mach/arch.h>
42 #include <asm/mach/map.h>
43 #include <asm/mach/irq.h>
44
45 #include <mach/board.h>
46 #include <mach/gpio.h>
47 #include <mach/at91cap9_matrix.h>
48 #include <mach/at91sam9_smc.h>
49
50 #include "sam9_smc.h"
51 #include "generic.h"
52
53
54 static void __init cap9adk_map_io(void)
55 {
56         /* Initialize processor: 12 MHz crystal */
57         at91cap9_initialize(12000000);
58
59         /* Setup the LEDs: USER1 and USER2 LED for cpu/timer... */
60         at91_init_leds(AT91_PIN_PA10, AT91_PIN_PA11);
61         /* ... POWER LED always on */
62         at91_set_gpio_output(AT91_PIN_PC29, 1);
63
64         /* Setup the serial ports and console */
65         at91_register_uart(0, 0, 0);            /* DBGU = ttyS0 */
66         at91_set_serial_console(0);
67 }
68
69 static void __init cap9adk_init_irq(void)
70 {
71         at91cap9_init_interrupts(NULL);
72 }
73
74
75 /*
76  * USB Host port
77  */
78 static struct at91_usbh_data __initdata cap9adk_usbh_data = {
79         .ports          = 2,
80 };
81
82 /*
83  * USB HS Device port
84  */
85 static struct usba_platform_data __initdata cap9adk_usba_udc_data = {
86         .vbus_pin       = AT91_PIN_PB31,
87 };
88
89 /*
90  * ADS7846 Touchscreen
91  */
92 #if defined(CONFIG_TOUCHSCREEN_ADS7846) || defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
93 static int ads7843_pendown_state(void)
94 {
95         return !at91_get_gpio_value(AT91_PIN_PC4);      /* Touchscreen PENIRQ */
96 }
97
98 static struct ads7846_platform_data ads_info = {
99         .model                  = 7843,
100         .x_min                  = 150,
101         .x_max                  = 3830,
102         .y_min                  = 190,
103         .y_max                  = 3830,
104         .vref_delay_usecs       = 100,
105         .x_plate_ohms           = 450,
106         .y_plate_ohms           = 250,
107         .pressure_max           = 15000,
108         .debounce_max           = 1,
109         .debounce_rep           = 0,
110         .debounce_tol           = (~0),
111         .get_pendown_state      = ads7843_pendown_state,
112 };
113
114 static void __init cap9adk_add_device_ts(void)
115 {
116         at91_set_gpio_input(AT91_PIN_PC4, 1);   /* Touchscreen PENIRQ */
117         at91_set_gpio_input(AT91_PIN_PC5, 1);   /* Touchscreen BUSY */
118 }
119 #else
120 static void __init cap9adk_add_device_ts(void) {}
121 #endif
122
123
124 /*
125  * SPI devices.
126  */
127 static struct spi_board_info cap9adk_spi_devices[] = {
128 #if defined(CONFIG_MTD_AT91_DATAFLASH_CARD)
129         {       /* DataFlash card */
130                 .modalias       = "mtd_dataflash",
131                 .chip_select    = 0,
132                 .max_speed_hz   = 15 * 1000 * 1000,
133                 .bus_num        = 0,
134         },
135 #endif
136 #if defined(CONFIG_TOUCHSCREEN_ADS7846) || defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
137         {
138                 .modalias       = "ads7846",
139                 .chip_select    = 3,            /* can be 2 or 3, depending on J2 jumper */
140                 .max_speed_hz   = 125000 * 26,  /* (max sample rate @ 3V) * (cmd + data + overhead) */
141                 .bus_num        = 0,
142                 .platform_data  = &ads_info,
143                 .irq            = AT91_PIN_PC4,
144         },
145 #endif
146 };
147
148
149 /*
150  * MCI (SD/MMC)
151  */
152 static struct at91_mmc_data __initdata cap9adk_mmc_data = {
153         .wire4          = 1,
154 //      .det_pin        = ... not connected
155 //      .wp_pin         = ... not connected
156 //      .vcc_pin        = ... not connected
157 };
158
159
160 /*
161  * MACB Ethernet device
162  */
163 static struct at91_eth_data __initdata cap9adk_macb_data = {
164         .is_rmii        = 1,
165 };
166
167
168 /*
169  * NAND flash
170  */
171 static struct mtd_partition __initdata cap9adk_nand_partitions[] = {
172         {
173                 .name   = "NAND partition",
174                 .offset = 0,
175                 .size   = MTDPART_SIZ_FULL,
176         },
177 };
178
179 static struct mtd_partition * __init nand_partitions(int size, int *num_partitions)
180 {
181         *num_partitions = ARRAY_SIZE(cap9adk_nand_partitions);
182         return cap9adk_nand_partitions;
183 }
184
185 static struct atmel_nand_data __initdata cap9adk_nand_data = {
186         .ale            = 21,
187         .cle            = 22,
188 //      .det_pin        = ... not connected
189 //      .rdy_pin        = ... not connected
190         .enable_pin     = AT91_PIN_PD15,
191         .partition_info = nand_partitions,
192 #if defined(CONFIG_MTD_NAND_ATMEL_BUSWIDTH_16)
193         .bus_width_16   = 1,
194 #else
195         .bus_width_16   = 0,
196 #endif
197 };
198
199 static struct sam9_smc_config __initdata cap9adk_nand_smc_config = {
200         .ncs_read_setup         = 1,
201         .nrd_setup              = 2,
202         .ncs_write_setup        = 1,
203         .nwe_setup              = 2,
204
205         .ncs_read_pulse         = 6,
206         .nrd_pulse              = 4,
207         .ncs_write_pulse        = 6,
208         .nwe_pulse              = 4,
209
210         .read_cycle             = 8,
211         .write_cycle            = 8,
212
213         .mode                   = AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE,
214         .tdf_cycles             = 1,
215 };
216
217 static void __init cap9adk_add_device_nand(void)
218 {
219         unsigned long csa;
220
221         csa = at91_sys_read(AT91_MATRIX_EBICSA);
222         at91_sys_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_EBI_VDDIOMSEL_3_3V);
223
224         /* setup bus-width (8 or 16) */
225         if (cap9adk_nand_data.bus_width_16)
226                 cap9adk_nand_smc_config.mode |= AT91_SMC_DBW_16;
227         else
228                 cap9adk_nand_smc_config.mode |= AT91_SMC_DBW_8;
229
230         /* configure chip-select 3 (NAND) */
231         sam9_smc_configure(3, &cap9adk_nand_smc_config);
232
233         at91_add_device_nand(&cap9adk_nand_data);
234 }
235
236
237 /*
238  * NOR flash
239  */
240 static struct mtd_partition cap9adk_nor_partitions[] = {
241         {
242                 .name           = "NOR partition",
243                 .offset         = 0,
244                 .size           = MTDPART_SIZ_FULL,
245         },
246 };
247
248 static struct physmap_flash_data cap9adk_nor_data = {
249         .width          = 2,
250         .parts          = cap9adk_nor_partitions,
251         .nr_parts       = ARRAY_SIZE(cap9adk_nor_partitions),
252 };
253
254 #define NOR_BASE        AT91_CHIPSELECT_0
255 #define NOR_SIZE        SZ_8M
256
257 static struct resource nor_flash_resources[] = {
258         {
259                 .start  = NOR_BASE,
260                 .end    = NOR_BASE + NOR_SIZE - 1,
261                 .flags  = IORESOURCE_MEM,
262         }
263 };
264
265 static struct platform_device cap9adk_nor_flash = {
266         .name           = "physmap-flash",
267         .id             = 0,
268         .dev            = {
269                                 .platform_data  = &cap9adk_nor_data,
270         },
271         .resource       = nor_flash_resources,
272         .num_resources  = ARRAY_SIZE(nor_flash_resources),
273 };
274
275 static struct sam9_smc_config __initdata cap9adk_nor_smc_config = {
276         .ncs_read_setup         = 2,
277         .nrd_setup              = 4,
278         .ncs_write_setup        = 2,
279         .nwe_setup              = 4,
280
281         .ncs_read_pulse         = 10,
282         .nrd_pulse              = 8,
283         .ncs_write_pulse        = 10,
284         .nwe_pulse              = 8,
285
286         .read_cycle             = 16,
287         .write_cycle            = 16,
288
289         .mode                   = AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_BAT_WRITE | AT91_SMC_DBW_16,
290         .tdf_cycles             = 1,
291 };
292
293 static __init void cap9adk_add_device_nor(void)
294 {
295         unsigned long csa;
296
297         csa = at91_sys_read(AT91_MATRIX_EBICSA);
298         at91_sys_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_EBI_VDDIOMSEL_3_3V);
299
300         /* configure chip-select 0 (NOR) */
301         sam9_smc_configure(0, &cap9adk_nor_smc_config);
302
303         platform_device_register(&cap9adk_nor_flash);
304 }
305
306
307 /*
308  * LCD Controller
309  */
310 #if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE)
311 static struct fb_videomode at91_tft_vga_modes[] = {
312         {
313                 .name           = "TX09D50VM1CCA @ 60",
314                 .refresh        = 60,
315                 .xres           = 240,          .yres           = 320,
316                 .pixclock       = KHZ2PICOS(4965),
317
318                 .left_margin    = 1,            .right_margin   = 33,
319                 .upper_margin   = 1,            .lower_margin   = 0,
320                 .hsync_len      = 5,            .vsync_len      = 1,
321
322                 .sync           = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
323                 .vmode          = FB_VMODE_NONINTERLACED,
324         },
325 };
326
327 static struct fb_monspecs at91fb_default_monspecs = {
328         .manufacturer   = "HIT",
329         .monitor        = "TX09D70VM1CCA",
330
331         .modedb         = at91_tft_vga_modes,
332         .modedb_len     = ARRAY_SIZE(at91_tft_vga_modes),
333         .hfmin          = 15000,
334         .hfmax          = 64000,
335         .vfmin          = 50,
336         .vfmax          = 150,
337 };
338
339 #define AT91CAP9_DEFAULT_LCDCON2        (ATMEL_LCDC_MEMOR_LITTLE \
340                                         | ATMEL_LCDC_DISTYPE_TFT    \
341                                         | ATMEL_LCDC_CLKMOD_ALWAYSACTIVE)
342
343 static void at91_lcdc_power_control(int on)
344 {
345         if (on)
346                 at91_set_gpio_value(AT91_PIN_PC0, 0);   /* power up */
347         else
348                 at91_set_gpio_value(AT91_PIN_PC0, 1);   /* power down */
349 }
350
351 /* Driver datas */
352 static struct atmel_lcdfb_info __initdata cap9adk_lcdc_data = {
353         .default_bpp                    = 16,
354         .default_dmacon                 = ATMEL_LCDC_DMAEN,
355         .default_lcdcon2                = AT91CAP9_DEFAULT_LCDCON2,
356         .default_monspecs               = &at91fb_default_monspecs,
357         .atmel_lcdfb_power_control      = at91_lcdc_power_control,
358         .guard_time                     = 1,
359 };
360
361 #else
362 static struct atmel_lcdfb_info __initdata cap9adk_lcdc_data;
363 #endif
364
365
366 /*
367  * AC97
368  */
369 static struct atmel_ac97_data cap9adk_ac97_data = {
370 //      .reset_pin      = ... not connected
371 };
372
373
374 static void __init cap9adk_board_init(void)
375 {
376         /* Serial */
377         at91_add_device_serial();
378         /* USB Host */
379         set_irq_type(AT91CAP9_ID_UHP, IRQ_TYPE_LEVEL_HIGH);
380         at91_add_device_usbh(&cap9adk_usbh_data);
381         /* USB HS */
382         set_irq_type(AT91CAP9_ID_UDPHS, IRQ_TYPE_LEVEL_HIGH);
383         at91_add_device_usba(&cap9adk_usba_udc_data);
384         /* SPI */
385         at91_add_device_spi(cap9adk_spi_devices, ARRAY_SIZE(cap9adk_spi_devices));
386         /* Touchscreen */
387         cap9adk_add_device_ts();
388         /* MMC */
389         at91_add_device_mmc(1, &cap9adk_mmc_data);
390         /* Ethernet */
391         at91_add_device_eth(&cap9adk_macb_data);
392         /* NAND */
393         cap9adk_add_device_nand();
394         /* NOR Flash */
395         cap9adk_add_device_nor();
396         /* I2C */
397         at91_add_device_i2c(NULL, 0);
398         /* LCD Controller */
399         set_irq_type(AT91CAP9_ID_LCDC, IRQ_TYPE_LEVEL_HIGH);
400         at91_add_device_lcdc(&cap9adk_lcdc_data);
401         /* AC97 */
402         at91_add_device_ac97(&cap9adk_ac97_data);
403 }
404
405 MACHINE_START(AT91CAP9ADK, "Atmel AT91CAP9A-DK")
406         /* Maintainer: Stelian Pop <stelian.pop@leadtechdesign.com> */
407         .phys_io        = AT91_BASE_SYS,
408         .io_pg_offst    = (AT91_VA_BASE_SYS >> 18) & 0xfffc,
409         .boot_params    = AT91_SDRAM_BASE + 0x100,
410         .timer          = &at91sam926x_timer,
411         .map_io         = cap9adk_map_io,
412         .init_irq       = cap9adk_init_irq,
413         .init_machine   = cap9adk_board_init,
414 MACHINE_END