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