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