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/gpio.h>
24 #include <linux/init.h>
25 #include <linux/mm.h>
26 #include <linux/module.h>
27 #include <linux/platform_device.h>
28 #include <linux/spi/spi.h>
29 #include <linux/spi/ads7846.h>
30 #include <linux/spi/at73c213.h>
31 #include <linux/clk.h>
32 #include <linux/dm9000.h>
33 #include <linux/fb.h>
34 #include <linux/gpio_keys.h>
35 #include <linux/input.h>
36 
37 #include <video/atmel_lcdc.h>
38 
39 #include <asm/setup.h>
40 #include <asm/mach-types.h>
41 #include <asm/irq.h>
42 
43 #include <asm/mach/arch.h>
44 #include <asm/mach/map.h>
45 #include <asm/mach/irq.h>
46 
47 #include <mach/hardware.h>
48 #include <mach/board.h>
49 #include <mach/at91sam9_smc.h>
50 #include <mach/at91_shdwc.h>
51 #include <mach/system_rev.h>
52 
53 #include "sam9_smc.h"
54 #include "generic.h"
55 
56 
ek_init_early(void)57 static void __init ek_init_early(void)
58 {
59 	/* Initialize processor: 18.432 MHz crystal */
60 	at91_initialize(18432000);
61 
62 	/* Setup the LEDs */
63 	at91_init_leds(AT91_PIN_PA13, AT91_PIN_PA14);
64 
65 	/* DBGU on ttyS0. (Rx & Tx only) */
66 	at91_register_uart(0, 0, 0);
67 
68 	/* set serial console to ttyS0 (ie, DBGU) */
69 	at91_set_serial_console(0);
70 }
71 
72 /*
73  * DM9000 ethernet device
74  */
75 #if defined(CONFIG_DM9000)
76 static struct resource dm9000_resource[] = {
77 	[0] = {
78 		.start	= AT91_CHIPSELECT_2,
79 		.end	= AT91_CHIPSELECT_2 + 3,
80 		.flags	= IORESOURCE_MEM
81 	},
82 	[1] = {
83 		.start	= AT91_CHIPSELECT_2 + 0x44,
84 		.end	= AT91_CHIPSELECT_2 + 0xFF,
85 		.flags	= IORESOURCE_MEM
86 	},
87 	[2] = {
88 		.start	= AT91_PIN_PC11,
89 		.end	= AT91_PIN_PC11,
90 		.flags	= IORESOURCE_IRQ
91 			| IORESOURCE_IRQ_LOWEDGE | IORESOURCE_IRQ_HIGHEDGE,
92 	}
93 };
94 
95 static struct dm9000_plat_data dm9000_platdata = {
96 	.flags		= DM9000_PLATF_16BITONLY | DM9000_PLATF_NO_EEPROM,
97 };
98 
99 static struct platform_device dm9000_device = {
100 	.name		= "dm9000",
101 	.id		= 0,
102 	.num_resources	= ARRAY_SIZE(dm9000_resource),
103 	.resource	= dm9000_resource,
104 	.dev		= {
105 		.platform_data	= &dm9000_platdata,
106 	}
107 };
108 
109 /*
110  * SMC timings for the DM9000.
111  * Note: These timings were calculated for MASTER_CLOCK = 100000000 according to the DM9000 timings.
112  */
113 static struct sam9_smc_config __initdata dm9000_smc_config = {
114 	.ncs_read_setup		= 0,
115 	.nrd_setup		= 2,
116 	.ncs_write_setup	= 0,
117 	.nwe_setup		= 2,
118 
119 	.ncs_read_pulse		= 8,
120 	.nrd_pulse		= 4,
121 	.ncs_write_pulse	= 8,
122 	.nwe_pulse		= 4,
123 
124 	.read_cycle		= 16,
125 	.write_cycle		= 16,
126 
127 	.mode			= AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_BAT_WRITE | AT91_SMC_DBW_16,
128 	.tdf_cycles		= 1,
129 };
130 
ek_add_device_dm9000(void)131 static void __init ek_add_device_dm9000(void)
132 {
133 	/* Configure chip-select 2 (DM9000) */
134 	sam9_smc_configure(0, 2, &dm9000_smc_config);
135 
136 	/* Configure Reset signal as output */
137 	at91_set_gpio_output(AT91_PIN_PC10, 0);
138 
139 	/* Configure Interrupt pin as input, no pull-up */
140 	at91_set_gpio_input(AT91_PIN_PC11, 0);
141 
142 	platform_device_register(&dm9000_device);
143 }
144 #else
ek_add_device_dm9000(void)145 static void __init ek_add_device_dm9000(void) {}
146 #endif /* CONFIG_DM9000 */
147 
148 
149 /*
150  * USB Host Port
151  */
152 static struct at91_usbh_data __initdata ek_usbh_data = {
153 	.ports		= 2,
154 	.vbus_pin	= {-EINVAL, -EINVAL},
155 	.overcurrent_pin= {-EINVAL, -EINVAL},
156 };
157 
158 
159 /*
160  * USB Device Port
161  */
162 static struct at91_udc_data __initdata ek_udc_data = {
163 	.vbus_pin	= AT91_PIN_PB29,
164 	.pullup_pin	= -EINVAL,		/* pull-up driven by UDC */
165 };
166 
167 
168 /*
169  * NAND flash
170  */
171 static struct mtd_partition __initdata ek_nand_partition[] = {
172 	{
173 		.name	= "Partition 1",
174 		.offset	= 0,
175 		.size	= SZ_256K,
176 	},
177 	{
178 		.name	= "Partition 2",
179 		.offset	= MTDPART_OFS_NXTBLK,
180 		.size	= MTDPART_SIZ_FULL,
181 	},
182 };
183 
184 static struct atmel_nand_data __initdata ek_nand_data = {
185 	.ale		= 22,
186 	.cle		= 21,
187 	.det_pin	= -EINVAL,
188 	.rdy_pin	= AT91_PIN_PC15,
189 	.enable_pin	= AT91_PIN_PC14,
190 	.parts		= ek_nand_partition,
191 	.num_parts	= ARRAY_SIZE(ek_nand_partition),
192 };
193 
194 static struct sam9_smc_config __initdata ek_nand_smc_config = {
195 	.ncs_read_setup		= 0,
196 	.nrd_setup		= 1,
197 	.ncs_write_setup	= 0,
198 	.nwe_setup		= 1,
199 
200 	.ncs_read_pulse		= 3,
201 	.nrd_pulse		= 3,
202 	.ncs_write_pulse	= 3,
203 	.nwe_pulse		= 3,
204 
205 	.read_cycle		= 5,
206 	.write_cycle		= 5,
207 
208 	.mode			= AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE,
209 	.tdf_cycles		= 2,
210 };
211 
ek_add_device_nand(void)212 static void __init ek_add_device_nand(void)
213 {
214 	ek_nand_data.bus_width_16 = board_have_nand_16bit();
215 	/* setup bus-width (8 or 16) */
216 	if (ek_nand_data.bus_width_16)
217 		ek_nand_smc_config.mode |= AT91_SMC_DBW_16;
218 	else
219 		ek_nand_smc_config.mode |= AT91_SMC_DBW_8;
220 
221 	/* configure chip-select 3 (NAND) */
222 	sam9_smc_configure(0, 3, &ek_nand_smc_config);
223 
224 	at91_add_device_nand(&ek_nand_data);
225 }
226 
227 /*
228  * SPI related devices
229  */
230 #if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
231 
232 /*
233  * ADS7846 Touchscreen
234  */
235 #if defined(CONFIG_TOUCHSCREEN_ADS7846) || defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
236 
ads7843_pendown_state(void)237 static int ads7843_pendown_state(void)
238 {
239 	return !at91_get_gpio_value(AT91_PIN_PC2);	/* Touchscreen PENIRQ */
240 }
241 
242 static struct ads7846_platform_data ads_info = {
243 	.model			= 7843,
244 	.x_min			= 150,
245 	.x_max			= 3830,
246 	.y_min			= 190,
247 	.y_max			= 3830,
248 	.vref_delay_usecs	= 100,
249 	.x_plate_ohms		= 450,
250 	.y_plate_ohms		= 250,
251 	.pressure_max		= 15000,
252 	.debounce_max		= 1,
253 	.debounce_rep		= 0,
254 	.debounce_tol		= (~0),
255 	.get_pendown_state	= ads7843_pendown_state,
256 };
257 
ek_add_device_ts(void)258 static void __init ek_add_device_ts(void)
259 {
260 	at91_set_B_periph(AT91_PIN_PC2, 1);	/* External IRQ0, with pullup */
261 	at91_set_gpio_input(AT91_PIN_PA11, 1);	/* Touchscreen BUSY signal */
262 }
263 #else
ek_add_device_ts(void)264 static void __init ek_add_device_ts(void) {}
265 #endif
266 
267 /*
268  * Audio
269  */
270 static struct at73c213_board_info at73c213_data = {
271 	.ssc_id		= 1,
272 #if defined(CONFIG_MACH_AT91SAM9261EK)
273 	.shortname	= "AT91SAM9261-EK external DAC",
274 #else
275 	.shortname	= "AT91SAM9G10-EK external DAC",
276 #endif
277 };
278 
279 #if defined(CONFIG_SND_AT73C213) || defined(CONFIG_SND_AT73C213_MODULE)
at73c213_set_clk(struct at73c213_board_info * info)280 static void __init at73c213_set_clk(struct at73c213_board_info *info)
281 {
282 	struct clk *pck2;
283 	struct clk *plla;
284 
285 	pck2 = clk_get(NULL, "pck2");
286 	plla = clk_get(NULL, "plla");
287 
288 	/* AT73C213 MCK Clock */
289 	at91_set_B_periph(AT91_PIN_PB31, 0);	/* PCK2 */
290 
291 	clk_set_parent(pck2, plla);
292 	clk_put(plla);
293 
294 	info->dac_clk = pck2;
295 }
296 #else
at73c213_set_clk(struct at73c213_board_info * info)297 static void __init at73c213_set_clk(struct at73c213_board_info *info) {}
298 #endif
299 
300 /*
301  * SPI devices
302  */
303 static struct spi_board_info ek_spi_devices[] = {
304 	{	/* DataFlash chip */
305 		.modalias	= "mtd_dataflash",
306 		.chip_select	= 0,
307 		.max_speed_hz	= 15 * 1000 * 1000,
308 		.bus_num	= 0,
309 	},
310 #if defined(CONFIG_TOUCHSCREEN_ADS7846) || defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
311 	{
312 		.modalias	= "ads7846",
313 		.chip_select	= 2,
314 		.max_speed_hz	= 125000 * 26,	/* (max sample rate @ 3V) * (cmd + data + overhead) */
315 		.bus_num	= 0,
316 		.platform_data	= &ads_info,
317 		.irq		= AT91SAM9261_ID_IRQ0,
318 		.controller_data = (void *) AT91_PIN_PA28,	/* CS pin */
319 	},
320 #endif
321 #if defined(CONFIG_MTD_AT91_DATAFLASH_CARD)
322 	{	/* DataFlash card - jumper (J12) configurable to CS3 or CS0 */
323 		.modalias	= "mtd_dataflash",
324 		.chip_select	= 3,
325 		.max_speed_hz	= 15 * 1000 * 1000,
326 		.bus_num	= 0,
327 	},
328 #elif defined(CONFIG_SND_AT73C213) || defined(CONFIG_SND_AT73C213_MODULE)
329 	{	/* AT73C213 DAC */
330 		.modalias	= "at73c213",
331 		.chip_select	= 3,
332 		.max_speed_hz	= 10 * 1000 * 1000,
333 		.bus_num	= 0,
334 		.mode		= SPI_MODE_1,
335 		.platform_data	= &at73c213_data,
336 		.controller_data = (void*) AT91_PIN_PA29,	/* default for CS3 is PA6, but it must be PA29 */
337 	},
338 #endif
339 };
340 
341 #else /* CONFIG_SPI_ATMEL_* */
342 /* spi0 and mmc/sd share the same PIO pins: cannot be used at the same time */
343 
344 /*
345  * MCI (SD/MMC)
346  * det_pin, wp_pin and vcc_pin are not connected
347  */
348 static struct at91_mmc_data __initdata ek_mmc_data = {
349 	.wire4		= 1,
350 	.det_pin	= -EINVAL,
351 	.wp_pin		= -EINVAL,
352 	.vcc_pin	= -EINVAL,
353 };
354 
355 #endif /* CONFIG_SPI_ATMEL_* */
356 
357 
358 /*
359  * LCD Controller
360  */
361 #if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE)
362 
363 #if defined(CONFIG_FB_ATMEL_STN)
364 
365 /* STN */
366 static struct fb_videomode at91_stn_modes[] = {
367         {
368 		.name           = "SP06Q002 @ 75",
369 		.refresh        = 75,
370 		.xres           = 320,          .yres           = 240,
371 		.pixclock       = KHZ2PICOS(1440),
372 
373 		.left_margin    = 1,            .right_margin   = 1,
374 		.upper_margin   = 0,            .lower_margin   = 0,
375 		.hsync_len      = 1,            .vsync_len      = 1,
376 
377 		.sync		= FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
378 		.vmode          = FB_VMODE_NONINTERLACED,
379         },
380 };
381 
382 static struct fb_monspecs at91fb_default_stn_monspecs = {
383         .manufacturer   = "HIT",
384         .monitor        = "SP06Q002",
385 
386         .modedb         = at91_stn_modes,
387         .modedb_len     = ARRAY_SIZE(at91_stn_modes),
388         .hfmin          = 15000,
389         .hfmax          = 64000,
390         .vfmin          = 50,
391         .vfmax          = 150,
392 };
393 
394 #define AT91SAM9261_DEFAULT_STN_LCDCON2	(ATMEL_LCDC_MEMOR_LITTLE \
395 					| ATMEL_LCDC_DISTYPE_STNMONO \
396 					| ATMEL_LCDC_CLKMOD_ALWAYSACTIVE \
397 					| ATMEL_LCDC_IFWIDTH_4 \
398 					| ATMEL_LCDC_SCANMOD_SINGLE)
399 
at91_lcdc_stn_power_control(int on)400 static void at91_lcdc_stn_power_control(int on)
401 {
402 	/* backlight */
403 	if (on) {	/* power up */
404 		at91_set_gpio_value(AT91_PIN_PC14, 0);
405 		at91_set_gpio_value(AT91_PIN_PC15, 0);
406 	} else {	/* power down */
407 		at91_set_gpio_value(AT91_PIN_PC14, 1);
408 		at91_set_gpio_value(AT91_PIN_PC15, 1);
409 	}
410 }
411 
412 static struct atmel_lcdfb_info __initdata ek_lcdc_data = {
413 	.default_bpp			= 1,
414 	.default_dmacon			= ATMEL_LCDC_DMAEN,
415 	.default_lcdcon2		= AT91SAM9261_DEFAULT_STN_LCDCON2,
416 	.default_monspecs		= &at91fb_default_stn_monspecs,
417 	.atmel_lcdfb_power_control	= at91_lcdc_stn_power_control,
418 	.guard_time			= 1,
419 #if defined(CONFIG_MACH_AT91SAM9G10EK)
420 	.lcd_wiring_mode		= ATMEL_LCDC_WIRING_RGB,
421 #endif
422 };
423 
424 #else
425 
426 /* TFT */
427 static struct fb_videomode at91_tft_vga_modes[] = {
428 	{
429 	        .name           = "TX09D50VM1CCA @ 60",
430 		.refresh	= 60,
431 		.xres		= 240,		.yres		= 320,
432 		.pixclock	= KHZ2PICOS(4965),
433 
434 		.left_margin	= 1,		.right_margin	= 33,
435 		.upper_margin	= 1,		.lower_margin	= 0,
436 		.hsync_len	= 5,		.vsync_len	= 1,
437 
438 		.sync		= FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
439 		.vmode		= FB_VMODE_NONINTERLACED,
440 	},
441 };
442 
443 static struct fb_monspecs at91fb_default_tft_monspecs = {
444 	.manufacturer	= "HIT",
445 	.monitor        = "TX09D50VM1CCA",
446 
447 	.modedb		= at91_tft_vga_modes,
448 	.modedb_len	= ARRAY_SIZE(at91_tft_vga_modes),
449 	.hfmin		= 15000,
450 	.hfmax		= 64000,
451 	.vfmin		= 50,
452 	.vfmax		= 150,
453 };
454 
455 #define AT91SAM9261_DEFAULT_TFT_LCDCON2	(ATMEL_LCDC_MEMOR_LITTLE \
456 					| ATMEL_LCDC_DISTYPE_TFT    \
457 					| ATMEL_LCDC_CLKMOD_ALWAYSACTIVE)
458 
at91_lcdc_tft_power_control(int on)459 static void at91_lcdc_tft_power_control(int on)
460 {
461 	if (on)
462 		at91_set_gpio_value(AT91_PIN_PA12, 0);	/* power up */
463 	else
464 		at91_set_gpio_value(AT91_PIN_PA12, 1);	/* power down */
465 }
466 
467 static struct atmel_lcdfb_info __initdata ek_lcdc_data = {
468 	.lcdcon_is_backlight		= true,
469 	.default_bpp			= 16,
470 	.default_dmacon			= ATMEL_LCDC_DMAEN,
471 	.default_lcdcon2		= AT91SAM9261_DEFAULT_TFT_LCDCON2,
472 	.default_monspecs		= &at91fb_default_tft_monspecs,
473 	.atmel_lcdfb_power_control	= at91_lcdc_tft_power_control,
474 	.guard_time			= 1,
475 #if defined(CONFIG_MACH_AT91SAM9G10EK)
476 	.lcd_wiring_mode		= ATMEL_LCDC_WIRING_RGB,
477 #endif
478 };
479 #endif
480 
481 #else
482 static struct atmel_lcdfb_info __initdata ek_lcdc_data;
483 #endif
484 
485 
486 /*
487  * GPIO Buttons
488  */
489 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
490 static struct gpio_keys_button ek_buttons[] = {
491 	{
492 		.gpio		= AT91_PIN_PA27,
493 		.code		= BTN_0,
494 		.desc		= "Button 0",
495 		.active_low	= 1,
496 		.wakeup		= 1,
497 	},
498 	{
499 		.gpio		= AT91_PIN_PA26,
500 		.code		= BTN_1,
501 		.desc		= "Button 1",
502 		.active_low	= 1,
503 		.wakeup		= 1,
504 	},
505 	{
506 		.gpio		= AT91_PIN_PA25,
507 		.code		= BTN_2,
508 		.desc		= "Button 2",
509 		.active_low	= 1,
510 		.wakeup		= 1,
511 	},
512 	{
513 		.gpio		= AT91_PIN_PA24,
514 		.code		= BTN_3,
515 		.desc		= "Button 3",
516 		.active_low	= 1,
517 		.wakeup		= 1,
518 	}
519 };
520 
521 static struct gpio_keys_platform_data ek_button_data = {
522 	.buttons	= ek_buttons,
523 	.nbuttons	= ARRAY_SIZE(ek_buttons),
524 };
525 
526 static struct platform_device ek_button_device = {
527 	.name		= "gpio-keys",
528 	.id		= -1,
529 	.num_resources	= 0,
530 	.dev		= {
531 		.platform_data	= &ek_button_data,
532 	}
533 };
534 
ek_add_device_buttons(void)535 static void __init ek_add_device_buttons(void)
536 {
537 	at91_set_gpio_input(AT91_PIN_PA27, 1);	/* btn0 */
538 	at91_set_deglitch(AT91_PIN_PA27, 1);
539 	at91_set_gpio_input(AT91_PIN_PA26, 1);	/* btn1 */
540 	at91_set_deglitch(AT91_PIN_PA26, 1);
541 	at91_set_gpio_input(AT91_PIN_PA25, 1);	/* btn2 */
542 	at91_set_deglitch(AT91_PIN_PA25, 1);
543 	at91_set_gpio_input(AT91_PIN_PA24, 1);	/* btn3 */
544 	at91_set_deglitch(AT91_PIN_PA24, 1);
545 
546 	platform_device_register(&ek_button_device);
547 }
548 #else
ek_add_device_buttons(void)549 static void __init ek_add_device_buttons(void) {}
550 #endif
551 
552 /*
553  * LEDs
554  */
555 static struct gpio_led ek_leds[] = {
556 	{	/* "bottom" led, green, userled1 to be defined */
557 		.name			= "ds7",
558 		.gpio			= AT91_PIN_PA14,
559 		.active_low		= 1,
560 		.default_trigger	= "none",
561 	},
562 	{	/* "top" led, green, userled2 to be defined */
563 		.name			= "ds8",
564 		.gpio			= AT91_PIN_PA13,
565 		.active_low		= 1,
566 		.default_trigger	= "none",
567 	},
568 	{	/* "power" led, yellow */
569 		.name			= "ds1",
570 		.gpio			= AT91_PIN_PA23,
571 		.default_trigger	= "heartbeat",
572 	}
573 };
574 
ek_board_init(void)575 static void __init ek_board_init(void)
576 {
577 	/* Serial */
578 	at91_add_device_serial();
579 	/* USB Host */
580 	at91_add_device_usbh(&ek_usbh_data);
581 	/* USB Device */
582 	at91_add_device_udc(&ek_udc_data);
583 	/* I2C */
584 	at91_add_device_i2c(NULL, 0);
585 	/* NAND */
586 	ek_add_device_nand();
587 	/* DM9000 ethernet */
588 	ek_add_device_dm9000();
589 
590 	/* spi0 and mmc/sd share the same PIO pins */
591 #if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
592 	/* SPI */
593 	at91_add_device_spi(ek_spi_devices, ARRAY_SIZE(ek_spi_devices));
594 	/* Touchscreen */
595 	ek_add_device_ts();
596 	/* SSC (to AT73C213) */
597 	at73c213_set_clk(&at73c213_data);
598 	at91_add_device_ssc(AT91SAM9261_ID_SSC1, ATMEL_SSC_TX);
599 #else
600 	/* MMC */
601 	at91_add_device_mmc(0, &ek_mmc_data);
602 #endif
603 	/* LCD Controller */
604 	at91_add_device_lcdc(&ek_lcdc_data);
605 	/* Push Buttons */
606 	ek_add_device_buttons();
607 	/* LEDs */
608 	at91_gpio_leds(ek_leds, ARRAY_SIZE(ek_leds));
609 }
610 
611 #if defined(CONFIG_MACH_AT91SAM9261EK)
612 MACHINE_START(AT91SAM9261EK, "Atmel AT91SAM9261-EK")
613 #else
614 MACHINE_START(AT91SAM9G10EK, "Atmel AT91SAM9G10-EK")
615 #endif
616 	/* Maintainer: Atmel */
617 	.timer		= &at91sam926x_timer,
618 	.map_io		= at91_map_io,
619 	.init_early	= ek_init_early,
620 	.init_irq	= at91_init_irq_default,
621 	.init_machine	= ek_board_init,
622 MACHINE_END
623