Commit | Line | Data |
---|---|---|
022cbd73 | 1 | /* |
d0760b3b | 2 | * linux/arch/arm/mach-at91/board-sam9261ek.c |
022cbd73 AV |
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> | |
23522728 | 28 | #include <linux/spi/ads7846.h> |
022cbd73 | 29 | #include <linux/dm9000.h> |
cdf95c73 | 30 | #include <linux/fb.h> |
d0f9b55e AV |
31 | #include <linux/gpio_keys.h> |
32 | #include <linux/input.h> | |
cdf95c73 AV |
33 | |
34 | #include <video/atmel_lcdc.h> | |
022cbd73 AV |
35 | |
36 | #include <asm/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 <asm/arch/board.h> | |
46 | #include <asm/arch/gpio.h> | |
b78eabde | 47 | #include <asm/arch/at91sam9_smc.h> |
022cbd73 AV |
48 | |
49 | #include "generic.h" | |
50 | ||
51 | ||
52 | /* | |
53 | * Serial port configuration. | |
54 | * 0 .. 2 = USART0 .. USART2 | |
55 | * 3 = DBGU | |
56 | */ | |
57 | static struct at91_uart_config __initdata ek_uart_config = { | |
58 | .console_tty = 0, /* ttyS0 */ | |
59 | .nr_tty = 1, | |
60 | .tty_map = { 3, -1, -1, -1 } /* ttyS0, ..., ttyS3 */ | |
61 | }; | |
62 | ||
63 | static void __init ek_map_io(void) | |
64 | { | |
65 | /* Initialize processor: 18.432 MHz crystal */ | |
66 | at91sam9261_initialize(18432000); | |
67 | ||
302c0ef7 AV |
68 | /* Setup the LEDs */ |
69 | at91_init_leds(AT91_PIN_PA13, AT91_PIN_PA14); | |
70 | ||
022cbd73 AV |
71 | /* Setup the serial ports and console */ |
72 | at91_init_serial(&ek_uart_config); | |
73 | } | |
74 | ||
75 | static void __init ek_init_irq(void) | |
76 | { | |
77 | at91sam9261_init_interrupts(NULL); | |
78 | } | |
79 | ||
80 | ||
81 | /* | |
82 | * DM9000 ethernet device | |
83 | */ | |
84 | #if defined(CONFIG_DM9000) | |
85 | static struct resource at91sam9261_dm9000_resource[] = { | |
86 | [0] = { | |
87 | .start = AT91_CHIPSELECT_2, | |
88 | .end = AT91_CHIPSELECT_2 + 3, | |
89 | .flags = IORESOURCE_MEM | |
90 | }, | |
91 | [1] = { | |
92 | .start = AT91_CHIPSELECT_2 + 0x44, | |
93 | .end = AT91_CHIPSELECT_2 + 0xFF, | |
94 | .flags = IORESOURCE_MEM | |
95 | }, | |
96 | [2] = { | |
97 | .start = AT91_PIN_PC11, | |
98 | .end = AT91_PIN_PC11, | |
99 | .flags = IORESOURCE_IRQ | |
100 | } | |
101 | }; | |
102 | ||
103 | static struct dm9000_plat_data dm9000_platdata = { | |
104 | .flags = DM9000_PLATF_16BITONLY, | |
105 | }; | |
106 | ||
107 | static struct platform_device at91sam9261_dm9000_device = { | |
108 | .name = "dm9000", | |
109 | .id = 0, | |
110 | .num_resources = ARRAY_SIZE(at91sam9261_dm9000_resource), | |
111 | .resource = at91sam9261_dm9000_resource, | |
112 | .dev = { | |
113 | .platform_data = &dm9000_platdata, | |
114 | } | |
115 | }; | |
116 | ||
117 | static void __init ek_add_device_dm9000(void) | |
118 | { | |
119 | /* | |
120 | * Configure Chip-Select 2 on SMC for the DM9000. | |
121 | * Note: These timings were calculated for MASTER_CLOCK = 100000000 | |
122 | * according to the DM9000 timings. | |
123 | */ | |
124 | 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)); | |
125 | 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)); | |
126 | at91_sys_write(AT91_SMC_CYCLE(2), AT91_SMC_NWECYCLE_(16) | AT91_SMC_NRDCYCLE_(16)); | |
127 | 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)); | |
128 | ||
129 | /* Configure Reset signal as output */ | |
130 | at91_set_gpio_output(AT91_PIN_PC10, 0); | |
131 | ||
132 | /* Configure Interrupt pin as input, no pull-up */ | |
133 | at91_set_gpio_input(AT91_PIN_PC11, 0); | |
134 | ||
135 | platform_device_register(&at91sam9261_dm9000_device); | |
136 | } | |
137 | #else | |
138 | static void __init ek_add_device_dm9000(void) {} | |
139 | #endif /* CONFIG_DM9000 */ | |
140 | ||
141 | ||
142 | /* | |
143 | * USB Host Port | |
144 | */ | |
145 | static struct at91_usbh_data __initdata ek_usbh_data = { | |
146 | .ports = 2, | |
147 | }; | |
148 | ||
149 | ||
150 | /* | |
151 | * USB Device Port | |
152 | */ | |
153 | static struct at91_udc_data __initdata ek_udc_data = { | |
154 | .vbus_pin = AT91_PIN_PB29, | |
155 | .pullup_pin = 0, /* pull-up driven by UDC */ | |
156 | }; | |
157 | ||
158 | ||
159 | /* | |
160 | * MCI (SD/MMC) | |
161 | */ | |
162 | static struct at91_mmc_data __initdata ek_mmc_data = { | |
163 | .wire4 = 1, | |
164 | // .det_pin = ... not connected | |
165 | // .wp_pin = ... not connected | |
166 | // .vcc_pin = ... not connected | |
167 | }; | |
168 | ||
169 | ||
170 | /* | |
171 | * NAND flash | |
172 | */ | |
173 | static struct mtd_partition __initdata ek_nand_partition[] = { | |
174 | { | |
175 | .name = "Partition 1", | |
176 | .offset = 0, | |
177 | .size = 256 * 1024, | |
178 | }, | |
179 | { | |
180 | .name = "Partition 2", | |
181 | .offset = 256 * 1024 , | |
182 | .size = MTDPART_SIZ_FULL, | |
183 | }, | |
184 | }; | |
185 | ||
cdea4606 | 186 | static struct mtd_partition * __init nand_partitions(int size, int *num_partitions) |
022cbd73 AV |
187 | { |
188 | *num_partitions = ARRAY_SIZE(ek_nand_partition); | |
189 | return ek_nand_partition; | |
190 | } | |
191 | ||
192 | static struct at91_nand_data __initdata ek_nand_data = { | |
193 | .ale = 22, | |
194 | .cle = 21, | |
195 | // .det_pin = ... not connected | |
196 | .rdy_pin = AT91_PIN_PC15, | |
197 | .enable_pin = AT91_PIN_PC14, | |
198 | .partition_info = nand_partitions, | |
199 | #if defined(CONFIG_MTD_NAND_AT91_BUSWIDTH_16) | |
200 | .bus_width_16 = 1, | |
201 | #else | |
202 | .bus_width_16 = 0, | |
203 | #endif | |
204 | }; | |
205 | ||
23522728 AV |
206 | /* |
207 | * ADS7846 Touchscreen | |
208 | */ | |
209 | #if defined(CONFIG_TOUCHSCREEN_ADS7846) || defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE) | |
210 | ||
211 | static int ads7843_pendown_state(void) | |
212 | { | |
213 | return !at91_get_gpio_value(AT91_PIN_PC2); /* Touchscreen PENIRQ */ | |
214 | } | |
215 | ||
216 | static struct ads7846_platform_data ads_info = { | |
217 | .model = 7843, | |
218 | .x_min = 150, | |
219 | .x_max = 3830, | |
220 | .y_min = 190, | |
221 | .y_max = 3830, | |
222 | .vref_delay_usecs = 100, | |
223 | .x_plate_ohms = 450, | |
224 | .y_plate_ohms = 250, | |
225 | .pressure_max = 15000, | |
226 | .debounce_max = 1, | |
227 | .debounce_rep = 0, | |
228 | .debounce_tol = (~0), | |
229 | .get_pendown_state = ads7843_pendown_state, | |
230 | }; | |
231 | ||
232 | static void __init ek_add_device_ts(void) | |
233 | { | |
234 | at91_set_B_periph(AT91_PIN_PC2, 1); /* External IRQ0, with pullup */ | |
235 | at91_set_gpio_input(AT91_PIN_PA11, 1); /* Touchscreen BUSY signal */ | |
236 | } | |
237 | #else | |
238 | static void __init ek_add_device_ts(void) {} | |
239 | #endif | |
240 | ||
022cbd73 AV |
241 | /* |
242 | * SPI devices | |
243 | */ | |
244 | static struct spi_board_info ek_spi_devices[] = { | |
245 | { /* DataFlash chip */ | |
246 | .modalias = "mtd_dataflash", | |
247 | .chip_select = 0, | |
248 | .max_speed_hz = 15 * 1000 * 1000, | |
249 | .bus_num = 0, | |
250 | }, | |
23522728 AV |
251 | #if defined(CONFIG_TOUCHSCREEN_ADS7846) || defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE) |
252 | { | |
253 | .modalias = "ads7846", | |
254 | .chip_select = 2, | |
255 | .max_speed_hz = 125000 * 26, /* (max sample rate @ 3V) * (cmd + data + overhead) */ | |
256 | .bus_num = 0, | |
257 | .platform_data = &ads_info, | |
258 | .irq = AT91SAM9261_ID_IRQ0, | |
259 | }, | |
260 | #endif | |
022cbd73 AV |
261 | #if defined(CONFIG_MTD_AT91_DATAFLASH_CARD) |
262 | { /* DataFlash card - jumper (J12) configurable to CS3 or CS0 */ | |
263 | .modalias = "mtd_dataflash", | |
264 | .chip_select = 3, | |
265 | .max_speed_hz = 15 * 1000 * 1000, | |
266 | .bus_num = 0, | |
267 | }, | |
23522728 | 268 | #elif defined(CONFIG_SND_AT73C213) || defined(CONFIG_SND_AT73C213_MODULE) |
022cbd73 | 269 | { /* AT73C213 DAC */ |
23522728 | 270 | .modalias = "at73c213", |
022cbd73 AV |
271 | .chip_select = 3, |
272 | .max_speed_hz = 10 * 1000 * 1000, | |
273 | .bus_num = 0, | |
274 | }, | |
275 | #endif | |
276 | }; | |
277 | ||
278 | ||
cdf95c73 AV |
279 | /* |
280 | * LCD Controller | |
281 | */ | |
282 | #if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE) | |
51708748 AV |
283 | |
284 | #if defined(CONFIG_FB_ATMEL_STN) | |
285 | ||
286 | /* STN */ | |
287 | static struct fb_videomode at91_stn_modes[] = { | |
288 | { | |
289 | .name = "SP06Q002 @ 75", | |
290 | .refresh = 75, | |
291 | .xres = 320, .yres = 240, | |
292 | .pixclock = KHZ2PICOS(1440), | |
293 | ||
294 | .left_margin = 1, .right_margin = 1, | |
295 | .upper_margin = 0, .lower_margin = 0, | |
296 | .hsync_len = 1, .vsync_len = 1, | |
297 | ||
298 | .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, | |
299 | .vmode = FB_VMODE_NONINTERLACED, | |
300 | }, | |
301 | }; | |
302 | ||
303 | static struct fb_monspecs at91fb_default_stn_monspecs = { | |
304 | .manufacturer = "HIT", | |
305 | .monitor = "SP06Q002", | |
306 | ||
307 | .modedb = at91_stn_modes, | |
308 | .modedb_len = ARRAY_SIZE(at91_stn_modes), | |
309 | .hfmin = 15000, | |
310 | .hfmax = 64000, | |
311 | .vfmin = 50, | |
312 | .vfmax = 150, | |
313 | }; | |
314 | ||
315 | #define AT91SAM9261_DEFAULT_STN_LCDCON2 (ATMEL_LCDC_MEMOR_LITTLE \ | |
316 | | ATMEL_LCDC_DISTYPE_STNMONO \ | |
317 | | ATMEL_LCDC_CLKMOD_ALWAYSACTIVE \ | |
318 | | ATMEL_LCDC_IFWIDTH_4 \ | |
319 | | ATMEL_LCDC_SCANMOD_SINGLE) | |
320 | ||
321 | static void at91_lcdc_stn_power_control(int on) | |
322 | { | |
323 | /* backlight */ | |
324 | if (on) { /* power up */ | |
325 | at91_set_gpio_value(AT91_PIN_PC14, 0); | |
326 | at91_set_gpio_value(AT91_PIN_PC15, 0); | |
327 | } else { /* power down */ | |
328 | at91_set_gpio_value(AT91_PIN_PC14, 1); | |
329 | at91_set_gpio_value(AT91_PIN_PC15, 1); | |
330 | } | |
331 | } | |
332 | ||
333 | static struct atmel_lcdfb_info __initdata ek_lcdc_data = { | |
334 | .default_bpp = 1, | |
335 | .default_dmacon = ATMEL_LCDC_DMAEN, | |
336 | .default_lcdcon2 = AT91SAM9261_DEFAULT_STN_LCDCON2, | |
337 | .default_monspecs = &at91fb_default_stn_monspecs, | |
338 | .atmel_lcdfb_power_control = at91_lcdc_stn_power_control, | |
339 | .guard_time = 1, | |
340 | }; | |
341 | ||
342 | #else | |
343 | ||
344 | /* TFT */ | |
cdf95c73 AV |
345 | static struct fb_videomode at91_tft_vga_modes[] = { |
346 | { | |
347 | .name = "TX09D50VM1CCA @ 60", | |
348 | .refresh = 60, | |
349 | .xres = 240, .yres = 320, | |
350 | .pixclock = KHZ2PICOS(4965), | |
351 | ||
352 | .left_margin = 1, .right_margin = 33, | |
353 | .upper_margin = 1, .lower_margin = 0, | |
354 | .hsync_len = 5, .vsync_len = 1, | |
355 | ||
356 | .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, | |
357 | .vmode = FB_VMODE_NONINTERLACED, | |
358 | }, | |
359 | }; | |
360 | ||
51708748 | 361 | static struct fb_monspecs at91fb_default_tft_monspecs = { |
cdf95c73 AV |
362 | .manufacturer = "HIT", |
363 | .monitor = "TX09D50VM1CCA", | |
364 | ||
365 | .modedb = at91_tft_vga_modes, | |
366 | .modedb_len = ARRAY_SIZE(at91_tft_vga_modes), | |
367 | .hfmin = 15000, | |
368 | .hfmax = 64000, | |
369 | .vfmin = 50, | |
370 | .vfmax = 150, | |
371 | }; | |
372 | ||
51708748 | 373 | #define AT91SAM9261_DEFAULT_TFT_LCDCON2 (ATMEL_LCDC_MEMOR_LITTLE \ |
cdf95c73 AV |
374 | | ATMEL_LCDC_DISTYPE_TFT \ |
375 | | ATMEL_LCDC_CLKMOD_ALWAYSACTIVE) | |
376 | ||
51708748 | 377 | static void at91_lcdc_tft_power_control(int on) |
cdf95c73 AV |
378 | { |
379 | if (on) | |
380 | at91_set_gpio_value(AT91_PIN_PA12, 0); /* power up */ | |
381 | else | |
382 | at91_set_gpio_value(AT91_PIN_PA12, 1); /* power down */ | |
383 | } | |
384 | ||
cdf95c73 | 385 | static struct atmel_lcdfb_info __initdata ek_lcdc_data = { |
a9a84c37 | 386 | .lcdcon_is_backlight = true, |
cdf95c73 AV |
387 | .default_bpp = 16, |
388 | .default_dmacon = ATMEL_LCDC_DMAEN, | |
51708748 AV |
389 | .default_lcdcon2 = AT91SAM9261_DEFAULT_TFT_LCDCON2, |
390 | .default_monspecs = &at91fb_default_tft_monspecs, | |
391 | .atmel_lcdfb_power_control = at91_lcdc_tft_power_control, | |
cdf95c73 AV |
392 | .guard_time = 1, |
393 | }; | |
51708748 | 394 | #endif |
cdf95c73 AV |
395 | |
396 | #else | |
397 | static struct atmel_lcdfb_info __initdata ek_lcdc_data; | |
398 | #endif | |
399 | ||
400 | ||
d0f9b55e AV |
401 | /* |
402 | * GPIO Buttons | |
403 | */ | |
404 | #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE) | |
405 | static struct gpio_keys_button ek_buttons[] = { | |
406 | { | |
407 | .gpio = AT91_PIN_PA27, | |
eaf858a9 | 408 | .code = BTN_0, |
d0f9b55e AV |
409 | .desc = "Button 0", |
410 | .active_low = 1, | |
411 | }, | |
412 | { | |
413 | .gpio = AT91_PIN_PA26, | |
eaf858a9 | 414 | .code = BTN_1, |
d0f9b55e AV |
415 | .desc = "Button 1", |
416 | .active_low = 1, | |
417 | }, | |
418 | { | |
419 | .gpio = AT91_PIN_PA25, | |
eaf858a9 | 420 | .code = BTN_2, |
d0f9b55e AV |
421 | .desc = "Button 2", |
422 | .active_low = 1, | |
423 | }, | |
424 | { | |
425 | .gpio = AT91_PIN_PA24, | |
eaf858a9 | 426 | .code = BTN_3, |
d0f9b55e AV |
427 | .desc = "Button 3", |
428 | .active_low = 1, | |
429 | } | |
430 | }; | |
431 | ||
432 | static struct gpio_keys_platform_data ek_button_data = { | |
433 | .buttons = ek_buttons, | |
434 | .nbuttons = ARRAY_SIZE(ek_buttons), | |
435 | }; | |
436 | ||
437 | static struct platform_device ek_button_device = { | |
438 | .name = "gpio-keys", | |
439 | .id = -1, | |
440 | .num_resources = 0, | |
441 | .dev = { | |
442 | .platform_data = &ek_button_data, | |
443 | } | |
444 | }; | |
445 | ||
446 | static void __init ek_add_device_buttons(void) | |
447 | { | |
302edfd0 AV |
448 | at91_set_gpio_input(AT91_PIN_PA27, 0); /* btn0 */ |
449 | at91_set_deglitch(AT91_PIN_PA27, 1); | |
450 | at91_set_gpio_input(AT91_PIN_PA26, 0); /* btn1 */ | |
451 | at91_set_deglitch(AT91_PIN_PA26, 1); | |
452 | at91_set_gpio_input(AT91_PIN_PA25, 0); /* btn2 */ | |
453 | at91_set_deglitch(AT91_PIN_PA25, 1); | |
454 | at91_set_gpio_input(AT91_PIN_PA24, 0); /* btn3 */ | |
455 | at91_set_deglitch(AT91_PIN_PA24, 1); | |
d0f9b55e AV |
456 | |
457 | platform_device_register(&ek_button_device); | |
458 | } | |
459 | #else | |
460 | static void __init ek_add_device_buttons(void) {} | |
461 | #endif | |
462 | ||
022cbd73 AV |
463 | static void __init ek_board_init(void) |
464 | { | |
465 | /* Serial */ | |
466 | at91_add_device_serial(); | |
467 | /* USB Host */ | |
468 | at91_add_device_usbh(&ek_usbh_data); | |
469 | /* USB Device */ | |
470 | at91_add_device_udc(&ek_udc_data); | |
471 | /* I2C */ | |
f230d3f5 | 472 | at91_add_device_i2c(NULL, 0); |
022cbd73 AV |
473 | /* NAND */ |
474 | at91_add_device_nand(&ek_nand_data); | |
475 | /* DM9000 ethernet */ | |
476 | ek_add_device_dm9000(); | |
477 | ||
478 | /* spi0 and mmc/sd share the same PIO pins */ | |
479 | #if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE) | |
480 | /* SPI */ | |
481 | at91_add_device_spi(ek_spi_devices, ARRAY_SIZE(ek_spi_devices)); | |
23522728 AV |
482 | /* Touchscreen */ |
483 | ek_add_device_ts(); | |
022cbd73 AV |
484 | #else |
485 | /* MMC */ | |
d0760b3b | 486 | at91_add_device_mmc(0, &ek_mmc_data); |
022cbd73 | 487 | #endif |
cdf95c73 AV |
488 | /* LCD Controller */ |
489 | at91_add_device_lcdc(&ek_lcdc_data); | |
d0f9b55e AV |
490 | /* Push Buttons */ |
491 | ek_add_device_buttons(); | |
022cbd73 AV |
492 | } |
493 | ||
494 | MACHINE_START(AT91SAM9261EK, "Atmel AT91SAM9261-EK") | |
495 | /* Maintainer: Atmel */ | |
496 | .phys_io = AT91_BASE_SYS, | |
497 | .io_pg_offst = (AT91_VA_BASE_SYS >> 18) & 0xfffc, | |
498 | .boot_params = AT91_SDRAM_BASE + 0x100, | |
499 | .timer = &at91sam926x_timer, | |
500 | .map_io = ek_map_io, | |
501 | .init_irq = ek_init_irq, | |
502 | .init_machine = ek_board_init, | |
503 | MACHINE_END |