Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/sparc
[pandora-kernel.git] / arch / arm / mach-at91 / board-sam9m10g45ek.c
1 /*
2  *  Board-specific setup code for the AT91SAM9M10G45 Evaluation Kit family
3  *
4  *  Covers: * AT91SAM9G45-EKES  board
5  *          * AT91SAM9M10G45-EK board
6  *
7  *  Copyright (C) 2009 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  */
15
16 #include <linux/types.h>
17 #include <linux/gpio.h>
18 #include <linux/init.h>
19 #include <linux/mm.h>
20 #include <linux/module.h>
21 #include <linux/platform_device.h>
22 #include <linux/spi/spi.h>
23 #include <linux/fb.h>
24 #include <linux/gpio_keys.h>
25 #include <linux/input.h>
26 #include <linux/leds.h>
27 #include <linux/atmel-mci.h>
28 #include <linux/delay.h>
29 #include <linux/pwm.h>
30 #include <linux/leds_pwm.h>
31
32 #include <linux/platform_data/at91_adc.h>
33
34 #include <mach/hardware.h>
35 #include <video/atmel_lcdc.h>
36 #include <media/soc_camera.h>
37 #include <media/atmel-isi.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/at91sam9_smc.h>
48 #include <mach/system_rev.h>
49
50 #include "at91_aic.h"
51 #include "at91_shdwc.h"
52 #include "board.h"
53 #include "sam9_smc.h"
54 #include "generic.h"
55 #include "gpio.h"
56
57
58 static void __init ek_init_early(void)
59 {
60         /* Initialize processor: 12.000 MHz crystal */
61         at91_initialize(12000000);
62 }
63
64 /*
65  * USB HS Host port (common to OHCI & EHCI)
66  */
67 static struct at91_usbh_data __initdata ek_usbh_hs_data = {
68         .ports          = 2,
69         .vbus_pin       = {AT91_PIN_PD1, AT91_PIN_PD3},
70         .vbus_pin_active_low = {1, 1},
71         .overcurrent_pin= {-EINVAL, -EINVAL},
72 };
73
74
75 /*
76  * USB HS Device port
77  */
78 static struct usba_platform_data __initdata ek_usba_udc_data = {
79         .vbus_pin       = AT91_PIN_PB19,
80 };
81
82
83 /*
84  * SPI devices.
85  */
86 static struct spi_board_info ek_spi_devices[] = {
87         {       /* DataFlash chip */
88                 .modalias       = "mtd_dataflash",
89                 .chip_select    = 0,
90                 .max_speed_hz   = 15 * 1000 * 1000,
91                 .bus_num        = 0,
92         },
93 };
94
95
96 /*
97  * MCI (SD/MMC)
98  */
99 static struct mci_platform_data __initdata mci0_data = {
100         .slot[0] = {
101                 .bus_width      = 4,
102                 .detect_pin     = AT91_PIN_PD10,
103                 .wp_pin         = -EINVAL,
104         },
105 };
106
107 static struct mci_platform_data __initdata mci1_data = {
108         .slot[0] = {
109                 .bus_width      = 4,
110                 .detect_pin     = AT91_PIN_PD11,
111                 .wp_pin         = AT91_PIN_PD29,
112         },
113 };
114
115
116 /*
117  * MACB Ethernet device
118  */
119 static struct macb_platform_data __initdata ek_macb_data = {
120         .phy_irq_pin    = AT91_PIN_PD5,
121         .is_rmii        = 1,
122 };
123
124
125 /*
126  * NAND flash
127  */
128 static struct mtd_partition __initdata ek_nand_partition[] = {
129         {
130                 .name   = "Partition 1",
131                 .offset = 0,
132                 .size   = SZ_64M,
133         },
134         {
135                 .name   = "Partition 2",
136                 .offset = MTDPART_OFS_NXTBLK,
137                 .size   = MTDPART_SIZ_FULL,
138         },
139 };
140
141 /* det_pin is not connected */
142 static struct atmel_nand_data __initdata ek_nand_data = {
143         .ale            = 21,
144         .cle            = 22,
145         .rdy_pin        = AT91_PIN_PC8,
146         .enable_pin     = AT91_PIN_PC14,
147         .det_pin        = -EINVAL,
148         .ecc_mode       = NAND_ECC_SOFT,
149         .on_flash_bbt   = 1,
150         .parts          = ek_nand_partition,
151         .num_parts      = ARRAY_SIZE(ek_nand_partition),
152 };
153
154 static struct sam9_smc_config __initdata ek_nand_smc_config = {
155         .ncs_read_setup         = 0,
156         .nrd_setup              = 2,
157         .ncs_write_setup        = 0,
158         .nwe_setup              = 2,
159
160         .ncs_read_pulse         = 4,
161         .nrd_pulse              = 4,
162         .ncs_write_pulse        = 4,
163         .nwe_pulse              = 4,
164
165         .read_cycle             = 7,
166         .write_cycle            = 7,
167
168         .mode                   = AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE,
169         .tdf_cycles             = 3,
170 };
171
172 static void __init ek_add_device_nand(void)
173 {
174         ek_nand_data.bus_width_16 = board_have_nand_16bit();
175         /* setup bus-width (8 or 16) */
176         if (ek_nand_data.bus_width_16)
177                 ek_nand_smc_config.mode |= AT91_SMC_DBW_16;
178         else
179                 ek_nand_smc_config.mode |= AT91_SMC_DBW_8;
180
181         /* configure chip-select 3 (NAND) */
182         sam9_smc_configure(0, 3, &ek_nand_smc_config);
183
184         at91_add_device_nand(&ek_nand_data);
185 }
186
187
188 /*
189  *  ISI
190  */
191 static struct isi_platform_data __initdata isi_data = {
192         .frate                  = ISI_CFG1_FRATE_CAPTURE_ALL,
193         /* to use codec and preview path simultaneously */
194         .full_mode              = 1,
195         .data_width_flags       = ISI_DATAWIDTH_8 | ISI_DATAWIDTH_10,
196         /* ISI_MCK is provided by programmable clock or external clock */
197         .mck_hz                 = 25000000,
198 };
199
200
201 /*
202  * soc-camera OV2640
203  */
204 #if defined(CONFIG_SOC_CAMERA_OV2640) || \
205         defined(CONFIG_SOC_CAMERA_OV2640_MODULE)
206 static unsigned long isi_camera_query_bus_param(struct soc_camera_link *link)
207 {
208         /* ISI board for ek using default 8-bits connection */
209         return SOCAM_DATAWIDTH_8;
210 }
211
212 static int i2c_camera_power(struct device *dev, int on)
213 {
214         /* enable or disable the camera */
215         pr_debug("%s: %s the camera\n", __func__, on ? "ENABLE" : "DISABLE");
216         at91_set_gpio_output(AT91_PIN_PD13, !on);
217
218         if (!on)
219                 goto out;
220
221         /* If enabled, give a reset impulse */
222         at91_set_gpio_output(AT91_PIN_PD12, 0);
223         msleep(20);
224         at91_set_gpio_output(AT91_PIN_PD12, 1);
225         msleep(100);
226
227 out:
228         return 0;
229 }
230
231 static struct i2c_board_info i2c_camera = {
232         I2C_BOARD_INFO("ov2640", 0x30),
233 };
234
235 static struct soc_camera_link iclink_ov2640 = {
236         .bus_id                 = 0,
237         .board_info             = &i2c_camera,
238         .i2c_adapter_id         = 0,
239         .power                  = i2c_camera_power,
240         .query_bus_param        = isi_camera_query_bus_param,
241 };
242
243 static struct platform_device isi_ov2640 = {
244         .name   = "soc-camera-pdrv",
245         .id     = 0,
246         .dev    = {
247                 .platform_data = &iclink_ov2640,
248         },
249 };
250 #endif
251
252
253 /*
254  * LCD Controller
255  */
256 #if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE)
257 static struct fb_videomode at91_tft_vga_modes[] = {
258         {
259                 .name           = "LG",
260                 .refresh        = 60,
261                 .xres           = 480,          .yres           = 272,
262                 .pixclock       = KHZ2PICOS(9000),
263
264                 .left_margin    = 1,            .right_margin   = 1,
265                 .upper_margin   = 40,           .lower_margin   = 1,
266                 .hsync_len      = 45,           .vsync_len      = 1,
267
268                 .sync           = 0,
269                 .vmode          = FB_VMODE_NONINTERLACED,
270         },
271 };
272
273 static struct fb_monspecs at91fb_default_monspecs = {
274         .manufacturer   = "LG",
275         .monitor        = "LB043WQ1",
276
277         .modedb         = at91_tft_vga_modes,
278         .modedb_len     = ARRAY_SIZE(at91_tft_vga_modes),
279         .hfmin          = 15000,
280         .hfmax          = 17640,
281         .vfmin          = 57,
282         .vfmax          = 67,
283 };
284
285 #define AT91SAM9G45_DEFAULT_LCDCON2     (ATMEL_LCDC_MEMOR_LITTLE \
286                                         | ATMEL_LCDC_DISTYPE_TFT \
287                                         | ATMEL_LCDC_CLKMOD_ALWAYSACTIVE)
288
289 /* Driver datas */
290 static struct atmel_lcdfb_pdata __initdata ek_lcdc_data = {
291         .lcdcon_is_backlight            = true,
292         .default_bpp                    = 32,
293         .default_dmacon                 = ATMEL_LCDC_DMAEN,
294         .default_lcdcon2                = AT91SAM9G45_DEFAULT_LCDCON2,
295         .default_monspecs               = &at91fb_default_monspecs,
296         .guard_time                     = 9,
297         .lcd_wiring_mode                = ATMEL_LCDC_WIRING_RGB,
298 };
299
300 #else
301 static struct atmel_lcdfb_pdata __initdata ek_lcdc_data;
302 #endif
303
304
305 /*
306  * ADCs and touchscreen
307  */
308 static struct at91_adc_data ek_adc_data = {
309         .channels_used = BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(5) | BIT(6) | BIT(7),
310         .use_external_triggers = true,
311         .vref = 3300,
312         .touchscreen_type = ATMEL_ADC_TOUCHSCREEN_4WIRE,
313 };
314
315 /*
316  * GPIO Buttons
317  */
318 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
319 static struct gpio_keys_button ek_buttons[] = {
320         {       /* BP1, "leftclic" */
321                 .code           = BTN_LEFT,
322                 .gpio           = AT91_PIN_PB6,
323                 .active_low     = 1,
324                 .desc           = "left_click",
325                 .wakeup         = 1,
326         },
327         {       /* BP2, "rightclic" */
328                 .code           = BTN_RIGHT,
329                 .gpio           = AT91_PIN_PB7,
330                 .active_low     = 1,
331                 .desc           = "right_click",
332                 .wakeup         = 1,
333         },
334                 /* BP3, "joystick" */
335         {
336                 .code           = KEY_LEFT,
337                 .gpio           = AT91_PIN_PB14,
338                 .active_low     = 1,
339                 .desc           = "Joystick Left",
340         },
341         {
342                 .code           = KEY_RIGHT,
343                 .gpio           = AT91_PIN_PB15,
344                 .active_low     = 1,
345                 .desc           = "Joystick Right",
346         },
347         {
348                 .code           = KEY_UP,
349                 .gpio           = AT91_PIN_PB16,
350                 .active_low     = 1,
351                 .desc           = "Joystick Up",
352         },
353         {
354                 .code           = KEY_DOWN,
355                 .gpio           = AT91_PIN_PB17,
356                 .active_low     = 1,
357                 .desc           = "Joystick Down",
358         },
359         {
360                 .code           = KEY_ENTER,
361                 .gpio           = AT91_PIN_PB18,
362                 .active_low     = 1,
363                 .desc           = "Joystick Press",
364         },
365 };
366
367 static struct gpio_keys_platform_data ek_button_data = {
368         .buttons        = ek_buttons,
369         .nbuttons       = ARRAY_SIZE(ek_buttons),
370 };
371
372 static struct platform_device ek_button_device = {
373         .name           = "gpio-keys",
374         .id             = -1,
375         .num_resources  = 0,
376         .dev            = {
377                 .platform_data  = &ek_button_data,
378         }
379 };
380
381 static void __init ek_add_device_buttons(void)
382 {
383         int i;
384
385         for (i = 0; i < ARRAY_SIZE(ek_buttons); i++) {
386                 at91_set_GPIO_periph(ek_buttons[i].gpio, 1);
387                 at91_set_deglitch(ek_buttons[i].gpio, 1);
388         }
389
390         platform_device_register(&ek_button_device);
391 }
392 #else
393 static void __init ek_add_device_buttons(void) {}
394 #endif
395
396
397 /*
398  * AC97
399  * reset_pin is not connected: NRST
400  */
401 static struct ac97c_platform_data ek_ac97_data = {
402         .reset_pin      = -EINVAL,
403 };
404
405
406 /*
407  * LEDs ... these could all be PWM-driven, for variable brightness
408  */
409 static struct gpio_led ek_leds[] = {
410         {       /* "top" led, red, powerled */
411                 .name                   = "d8",
412                 .gpio                   = AT91_PIN_PD30,
413                 .default_trigger        = "heartbeat",
414         },
415         {       /* "left" led, green, userled2, pwm3 */
416                 .name                   = "d6",
417                 .gpio                   = AT91_PIN_PD0,
418                 .active_low             = 1,
419                 .default_trigger        = "nand-disk",
420         },
421 #if !IS_ENABLED(CONFIG_LEDS_PWM)
422         {       /* "right" led, green, userled1, pwm1 */
423                 .name                   = "d7",
424                 .gpio                   = AT91_PIN_PD31,
425                 .active_low             = 1,
426                 .default_trigger        = "mmc0",
427         },
428 #endif
429 };
430
431
432 /*
433  * PWM Leds
434  */
435 static struct pwm_lookup pwm_lookup[] = {
436         PWM_LOOKUP("at91sam9rl-pwm", 1, "leds_pwm", "d7",
437                    5000, PWM_POLARITY_INVERSED),
438 };
439
440 #if IS_ENABLED(CONFIG_LEDS_PWM)
441 static struct led_pwm pwm_leds[] = {
442         {       /* "right" led, green, userled1, pwm1 */
443                 .name = "d7",
444                 .max_brightness = 255,
445         },
446 };
447
448 static struct led_pwm_platform_data pwm_data = {
449         .num_leds       = ARRAY_SIZE(pwm_leds),
450         .leds           = pwm_leds,
451 };
452
453 static struct platform_device leds_pwm = {
454         .name   = "leds_pwm",
455         .id     = -1,
456         .dev    = {
457                 .platform_data = &pwm_data,
458         },
459 };
460 #endif
461
462 static struct platform_device *devices[] __initdata = {
463 #if defined(CONFIG_SOC_CAMERA_OV2640) || \
464         defined(CONFIG_SOC_CAMERA_OV2640_MODULE)
465         &isi_ov2640,
466 #endif
467 #if IS_ENABLED(CONFIG_LEDS_PWM)
468         &leds_pwm,
469 #endif
470 };
471
472 static void __init ek_board_init(void)
473 {
474         /* Serial */
475         /* DGBU on ttyS0. (Rx & Tx only) */
476         at91_register_uart(0, 0, 0);
477
478         /* USART0 not connected on the -EK board */
479         /* USART1 on ttyS2. (Rx, Tx, RTS, CTS) */
480         at91_register_uart(AT91SAM9G45_ID_US1, 2, ATMEL_UART_CTS | ATMEL_UART_RTS);
481         at91_add_device_serial();
482         /* USB HS Host */
483         at91_add_device_usbh_ohci(&ek_usbh_hs_data);
484         at91_add_device_usbh_ehci(&ek_usbh_hs_data);
485         /* USB HS Device */
486         at91_add_device_usba(&ek_usba_udc_data);
487         /* SPI */
488         at91_add_device_spi(ek_spi_devices, ARRAY_SIZE(ek_spi_devices));
489         /* MMC */
490         at91_add_device_mci(0, &mci0_data);
491         at91_add_device_mci(1, &mci1_data);
492         /* Ethernet */
493         at91_add_device_eth(&ek_macb_data);
494         /* NAND */
495         ek_add_device_nand();
496         /* I2C */
497         at91_add_device_i2c(0, NULL, 0);
498         /* ISI, using programmable clock as ISI_MCK */
499         at91_add_device_isi(&isi_data, true);
500         /* LCD Controller */
501         at91_add_device_lcdc(&ek_lcdc_data);
502         /* ADC and touchscreen */
503         at91_add_device_adc(&ek_adc_data);
504         /* Push Buttons */
505         ek_add_device_buttons();
506         /* AC97 */
507         at91_add_device_ac97(&ek_ac97_data);
508         /* LEDs */
509         at91_gpio_leds(ek_leds, ARRAY_SIZE(ek_leds));
510         pwm_add_table(pwm_lookup, ARRAY_SIZE(pwm_lookup));
511 #if IS_ENABLED(CONFIG_LEDS_PWM)
512         at91_add_device_pwm(1 << AT91_PWM1);
513 #endif
514         /* Other platform devices */
515         platform_add_devices(devices, ARRAY_SIZE(devices));
516 }
517
518 MACHINE_START(AT91SAM9M10G45EK, "Atmel AT91SAM9M10G45-EK")
519         /* Maintainer: Atmel */
520         .init_time      = at91sam926x_pit_init,
521         .map_io         = at91_map_io,
522         .handle_irq     = at91_aic_handle_irq,
523         .init_early     = ek_init_early,
524         .init_irq       = at91_init_irq_default,
525         .init_machine   = ek_board_init,
526 MACHINE_END