Merge branch 'v6v7' into devel
[linux/fpc-iii.git] / arch / arm / mach-mx3 / mach-armadillo5x0.c
blob28b6f414b5d58508172dc26b084db1fdff50b9b2
1 /*
2 * armadillo5x0.c
4 * Copyright 2009 Alberto Panizzo <maramaopercheseimorto@gmail.com>
5 * updates in http://alberdroid.blogspot.com/
7 * Based on Atmark Techno, Inc. armadillo 500 BSP 2008
8 * Based on mx31ads.c and pcm037.c Great Work!
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
23 * MA 02110-1301, USA.
26 #include <linux/types.h>
27 #include <linux/init.h>
28 #include <linux/clk.h>
29 #include <linux/platform_device.h>
30 #include <linux/gpio.h>
31 #include <linux/smsc911x.h>
32 #include <linux/interrupt.h>
33 #include <linux/irq.h>
34 #include <linux/mtd/physmap.h>
35 #include <linux/io.h>
36 #include <linux/input.h>
37 #include <linux/gpio_keys.h>
38 #include <linux/i2c.h>
39 #include <linux/usb/otg.h>
40 #include <linux/usb/ulpi.h>
41 #include <linux/delay.h>
43 #include <mach/hardware.h>
44 #include <asm/mach-types.h>
45 #include <asm/mach/arch.h>
46 #include <asm/mach/time.h>
47 #include <asm/memory.h>
48 #include <asm/mach/map.h>
50 #include <mach/common.h>
51 #include <mach/iomux-mx3.h>
52 #include <mach/ipu.h>
53 #include <mach/mx3fb.h>
54 #include <mach/ulpi.h>
56 #include "devices-imx31.h"
57 #include "devices.h"
58 #include "crm_regs.h"
60 static int armadillo5x0_pins[] = {
61 /* UART1 */
62 MX31_PIN_CTS1__CTS1,
63 MX31_PIN_RTS1__RTS1,
64 MX31_PIN_TXD1__TXD1,
65 MX31_PIN_RXD1__RXD1,
66 /* UART2 */
67 MX31_PIN_CTS2__CTS2,
68 MX31_PIN_RTS2__RTS2,
69 MX31_PIN_TXD2__TXD2,
70 MX31_PIN_RXD2__RXD2,
71 /* LAN9118_IRQ */
72 IOMUX_MODE(MX31_PIN_GPIO1_0, IOMUX_CONFIG_GPIO),
73 /* SDHC1 */
74 MX31_PIN_SD1_DATA3__SD1_DATA3,
75 MX31_PIN_SD1_DATA2__SD1_DATA2,
76 MX31_PIN_SD1_DATA1__SD1_DATA1,
77 MX31_PIN_SD1_DATA0__SD1_DATA0,
78 MX31_PIN_SD1_CLK__SD1_CLK,
79 MX31_PIN_SD1_CMD__SD1_CMD,
80 /* Framebuffer */
81 MX31_PIN_LD0__LD0,
82 MX31_PIN_LD1__LD1,
83 MX31_PIN_LD2__LD2,
84 MX31_PIN_LD3__LD3,
85 MX31_PIN_LD4__LD4,
86 MX31_PIN_LD5__LD5,
87 MX31_PIN_LD6__LD6,
88 MX31_PIN_LD7__LD7,
89 MX31_PIN_LD8__LD8,
90 MX31_PIN_LD9__LD9,
91 MX31_PIN_LD10__LD10,
92 MX31_PIN_LD11__LD11,
93 MX31_PIN_LD12__LD12,
94 MX31_PIN_LD13__LD13,
95 MX31_PIN_LD14__LD14,
96 MX31_PIN_LD15__LD15,
97 MX31_PIN_LD16__LD16,
98 MX31_PIN_LD17__LD17,
99 MX31_PIN_VSYNC3__VSYNC3,
100 MX31_PIN_HSYNC__HSYNC,
101 MX31_PIN_FPSHIFT__FPSHIFT,
102 MX31_PIN_DRDY0__DRDY0,
103 IOMUX_MODE(MX31_PIN_LCS1, IOMUX_CONFIG_GPIO), /*ADV7125_PSAVE*/
104 /* I2C2 */
105 MX31_PIN_CSPI2_MOSI__SCL,
106 MX31_PIN_CSPI2_MISO__SDA,
107 /* OTG */
108 MX31_PIN_USBOTG_DATA0__USBOTG_DATA0,
109 MX31_PIN_USBOTG_DATA1__USBOTG_DATA1,
110 MX31_PIN_USBOTG_DATA2__USBOTG_DATA2,
111 MX31_PIN_USBOTG_DATA3__USBOTG_DATA3,
112 MX31_PIN_USBOTG_DATA4__USBOTG_DATA4,
113 MX31_PIN_USBOTG_DATA5__USBOTG_DATA5,
114 MX31_PIN_USBOTG_DATA6__USBOTG_DATA6,
115 MX31_PIN_USBOTG_DATA7__USBOTG_DATA7,
116 MX31_PIN_USBOTG_CLK__USBOTG_CLK,
117 MX31_PIN_USBOTG_DIR__USBOTG_DIR,
118 MX31_PIN_USBOTG_NXT__USBOTG_NXT,
119 MX31_PIN_USBOTG_STP__USBOTG_STP,
120 /* USB host 2 */
121 IOMUX_MODE(MX31_PIN_USBH2_CLK, IOMUX_CONFIG_FUNC),
122 IOMUX_MODE(MX31_PIN_USBH2_DIR, IOMUX_CONFIG_FUNC),
123 IOMUX_MODE(MX31_PIN_USBH2_NXT, IOMUX_CONFIG_FUNC),
124 IOMUX_MODE(MX31_PIN_USBH2_STP, IOMUX_CONFIG_FUNC),
125 IOMUX_MODE(MX31_PIN_USBH2_DATA0, IOMUX_CONFIG_FUNC),
126 IOMUX_MODE(MX31_PIN_USBH2_DATA1, IOMUX_CONFIG_FUNC),
127 IOMUX_MODE(MX31_PIN_STXD3, IOMUX_CONFIG_FUNC),
128 IOMUX_MODE(MX31_PIN_SRXD3, IOMUX_CONFIG_FUNC),
129 IOMUX_MODE(MX31_PIN_SCK3, IOMUX_CONFIG_FUNC),
130 IOMUX_MODE(MX31_PIN_SFS3, IOMUX_CONFIG_FUNC),
131 IOMUX_MODE(MX31_PIN_STXD6, IOMUX_CONFIG_FUNC),
132 IOMUX_MODE(MX31_PIN_SRXD6, IOMUX_CONFIG_FUNC),
135 /* USB */
136 #if defined(CONFIG_USB_ULPI)
138 #define OTG_RESET IOMUX_TO_GPIO(MX31_PIN_STXD4)
139 #define USBH2_RESET IOMUX_TO_GPIO(MX31_PIN_SCK6)
140 #define USBH2_CS IOMUX_TO_GPIO(MX31_PIN_GPIO1_3)
142 #define USB_PAD_CFG (PAD_CTL_DRV_MAX | PAD_CTL_SRE_FAST | PAD_CTL_HYS_CMOS | \
143 PAD_CTL_ODE_CMOS | PAD_CTL_100K_PU)
145 static int usbotg_init(struct platform_device *pdev)
147 int err;
149 mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA0, USB_PAD_CFG);
150 mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA1, USB_PAD_CFG);
151 mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA2, USB_PAD_CFG);
152 mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA3, USB_PAD_CFG);
153 mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA4, USB_PAD_CFG);
154 mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA5, USB_PAD_CFG);
155 mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA6, USB_PAD_CFG);
156 mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA7, USB_PAD_CFG);
157 mxc_iomux_set_pad(MX31_PIN_USBOTG_CLK, USB_PAD_CFG);
158 mxc_iomux_set_pad(MX31_PIN_USBOTG_DIR, USB_PAD_CFG);
159 mxc_iomux_set_pad(MX31_PIN_USBOTG_NXT, USB_PAD_CFG);
160 mxc_iomux_set_pad(MX31_PIN_USBOTG_STP, USB_PAD_CFG);
162 /* Chip already enabled by hardware */
163 /* OTG phy reset*/
164 err = gpio_request(OTG_RESET, "USB-OTG-RESET");
165 if (err) {
166 pr_err("Failed to request the usb otg reset gpio\n");
167 return err;
170 err = gpio_direction_output(OTG_RESET, 1/*HIGH*/);
171 if (err) {
172 pr_err("Failed to reset the usb otg phy\n");
173 goto otg_free_reset;
176 gpio_set_value(OTG_RESET, 0/*LOW*/);
177 mdelay(5);
178 gpio_set_value(OTG_RESET, 1/*HIGH*/);
180 return 0;
182 otg_free_reset:
183 gpio_free(OTG_RESET);
184 return err;
187 static int usbh2_init(struct platform_device *pdev)
189 int err;
191 mxc_iomux_set_pad(MX31_PIN_USBH2_CLK, USB_PAD_CFG);
192 mxc_iomux_set_pad(MX31_PIN_USBH2_DIR, USB_PAD_CFG);
193 mxc_iomux_set_pad(MX31_PIN_USBH2_NXT, USB_PAD_CFG);
194 mxc_iomux_set_pad(MX31_PIN_USBH2_STP, USB_PAD_CFG);
195 mxc_iomux_set_pad(MX31_PIN_USBH2_DATA0, USB_PAD_CFG);
196 mxc_iomux_set_pad(MX31_PIN_USBH2_DATA1, USB_PAD_CFG);
197 mxc_iomux_set_pad(MX31_PIN_SRXD6, USB_PAD_CFG);
198 mxc_iomux_set_pad(MX31_PIN_STXD6, USB_PAD_CFG);
199 mxc_iomux_set_pad(MX31_PIN_SFS3, USB_PAD_CFG);
200 mxc_iomux_set_pad(MX31_PIN_SCK3, USB_PAD_CFG);
201 mxc_iomux_set_pad(MX31_PIN_SRXD3, USB_PAD_CFG);
202 mxc_iomux_set_pad(MX31_PIN_STXD3, USB_PAD_CFG);
204 mxc_iomux_set_gpr(MUX_PGP_UH2, true);
207 /* Enable the chip */
208 err = gpio_request(USBH2_CS, "USB-H2-CS");
209 if (err) {
210 pr_err("Failed to request the usb host 2 CS gpio\n");
211 return err;
214 err = gpio_direction_output(USBH2_CS, 0/*Enabled*/);
215 if (err) {
216 pr_err("Failed to drive the usb host 2 CS gpio\n");
217 goto h2_free_cs;
220 /* H2 phy reset*/
221 err = gpio_request(USBH2_RESET, "USB-H2-RESET");
222 if (err) {
223 pr_err("Failed to request the usb host 2 reset gpio\n");
224 goto h2_free_cs;
227 err = gpio_direction_output(USBH2_RESET, 1/*HIGH*/);
228 if (err) {
229 pr_err("Failed to reset the usb host 2 phy\n");
230 goto h2_free_reset;
233 gpio_set_value(USBH2_RESET, 0/*LOW*/);
234 mdelay(5);
235 gpio_set_value(USBH2_RESET, 1/*HIGH*/);
237 return 0;
239 h2_free_reset:
240 gpio_free(USBH2_RESET);
241 h2_free_cs:
242 gpio_free(USBH2_CS);
243 return err;
246 static struct mxc_usbh_platform_data usbotg_pdata __initdata = {
247 .init = usbotg_init,
248 .portsc = MXC_EHCI_MODE_ULPI | MXC_EHCI_UTMI_8BIT,
249 .flags = MXC_EHCI_POWER_PINS_ENABLED | MXC_EHCI_INTERFACE_DIFF_UNI,
252 static struct mxc_usbh_platform_data usbh2_pdata __initdata = {
253 .init = usbh2_init,
254 .portsc = MXC_EHCI_MODE_ULPI | MXC_EHCI_UTMI_8BIT,
255 .flags = MXC_EHCI_POWER_PINS_ENABLED | MXC_EHCI_INTERFACE_DIFF_UNI,
257 #endif /* CONFIG_USB_ULPI */
259 /* RTC over I2C*/
260 #define ARMADILLO5X0_RTC_GPIO IOMUX_TO_GPIO(MX31_PIN_SRXD4)
262 static struct i2c_board_info armadillo5x0_i2c_rtc = {
263 I2C_BOARD_INFO("s35390a", 0x30),
266 /* GPIO BUTTONS */
267 static struct gpio_keys_button armadillo5x0_buttons[] = {
269 .code = KEY_ENTER, /*28*/
270 .gpio = IOMUX_TO_GPIO(MX31_PIN_SCLK0),
271 .active_low = 1,
272 .desc = "menu",
273 .wakeup = 1,
274 }, {
275 .code = KEY_BACK, /*158*/
276 .gpio = IOMUX_TO_GPIO(MX31_PIN_SRST0),
277 .active_low = 1,
278 .desc = "back",
279 .wakeup = 1,
283 static struct gpio_keys_platform_data armadillo5x0_button_data = {
284 .buttons = armadillo5x0_buttons,
285 .nbuttons = ARRAY_SIZE(armadillo5x0_buttons),
288 static struct platform_device armadillo5x0_button_device = {
289 .name = "gpio-keys",
290 .id = -1,
291 .num_resources = 0,
292 .dev = {
293 .platform_data = &armadillo5x0_button_data,
298 * NAND Flash
300 static const struct mxc_nand_platform_data
301 armadillo5x0_nand_board_info __initconst = {
302 .width = 1,
303 .hw_ecc = 1,
307 * MTD NOR Flash
309 static struct mtd_partition armadillo5x0_nor_flash_partitions[] = {
311 .name = "nor.bootloader",
312 .offset = 0x00000000,
313 .size = 4*32*1024,
314 }, {
315 .name = "nor.kernel",
316 .offset = MTDPART_OFS_APPEND,
317 .size = 16*128*1024,
318 }, {
319 .name = "nor.userland",
320 .offset = MTDPART_OFS_APPEND,
321 .size = 110*128*1024,
322 }, {
323 .name = "nor.config",
324 .offset = MTDPART_OFS_APPEND,
325 .size = 1*128*1024,
329 static struct physmap_flash_data armadillo5x0_nor_flash_pdata = {
330 .width = 2,
331 .parts = armadillo5x0_nor_flash_partitions,
332 .nr_parts = ARRAY_SIZE(armadillo5x0_nor_flash_partitions),
335 static struct resource armadillo5x0_nor_flash_resource = {
336 .flags = IORESOURCE_MEM,
337 .start = MX31_CS0_BASE_ADDR,
338 .end = MX31_CS0_BASE_ADDR + SZ_64M - 1,
341 static struct platform_device armadillo5x0_nor_flash = {
342 .name = "physmap-flash",
343 .id = -1,
344 .num_resources = 1,
345 .resource = &armadillo5x0_nor_flash_resource,
349 * FB support
351 static const struct fb_videomode fb_modedb[] = {
352 { /* 640x480 @ 60 Hz */
353 .name = "CRT-VGA",
354 .refresh = 60,
355 .xres = 640,
356 .yres = 480,
357 .pixclock = 39721,
358 .left_margin = 35,
359 .right_margin = 115,
360 .upper_margin = 43,
361 .lower_margin = 1,
362 .hsync_len = 10,
363 .vsync_len = 1,
364 .sync = FB_SYNC_OE_ACT_HIGH,
365 .vmode = FB_VMODE_NONINTERLACED,
366 .flag = 0,
367 }, {/* 800x600 @ 56 Hz */
368 .name = "CRT-SVGA",
369 .refresh = 56,
370 .xres = 800,
371 .yres = 600,
372 .pixclock = 30000,
373 .left_margin = 30,
374 .right_margin = 108,
375 .upper_margin = 13,
376 .lower_margin = 10,
377 .hsync_len = 10,
378 .vsync_len = 1,
379 .sync = FB_SYNC_OE_ACT_HIGH | FB_SYNC_HOR_HIGH_ACT |
380 FB_SYNC_VERT_HIGH_ACT,
381 .vmode = FB_VMODE_NONINTERLACED,
382 .flag = 0,
386 static struct ipu_platform_data mx3_ipu_data = {
387 .irq_base = MXC_IPU_IRQ_START,
390 static struct mx3fb_platform_data mx3fb_pdata = {
391 .dma_dev = &mx3_ipu.dev,
392 .name = "CRT-VGA",
393 .mode = fb_modedb,
394 .num_modes = ARRAY_SIZE(fb_modedb),
398 * SDHC 1
399 * MMC support
401 static int armadillo5x0_sdhc1_get_ro(struct device *dev)
403 return gpio_get_value(IOMUX_TO_GPIO(MX31_PIN_ATA_RESET_B));
406 static int armadillo5x0_sdhc1_init(struct device *dev,
407 irq_handler_t detect_irq, void *data)
409 int ret;
410 int gpio_det, gpio_wp;
412 gpio_det = IOMUX_TO_GPIO(MX31_PIN_ATA_DMACK);
413 gpio_wp = IOMUX_TO_GPIO(MX31_PIN_ATA_RESET_B);
415 ret = gpio_request(gpio_det, "sdhc-card-detect");
416 if (ret)
417 return ret;
419 gpio_direction_input(gpio_det);
421 ret = gpio_request(gpio_wp, "sdhc-write-protect");
422 if (ret)
423 goto err_gpio_free;
425 gpio_direction_input(gpio_wp);
427 /* When supported the trigger type have to be BOTH */
428 ret = request_irq(IOMUX_TO_IRQ(MX31_PIN_ATA_DMACK), detect_irq,
429 IRQF_DISABLED | IRQF_TRIGGER_FALLING,
430 "sdhc-detect", data);
432 if (ret)
433 goto err_gpio_free_2;
435 return 0;
437 err_gpio_free_2:
438 gpio_free(gpio_wp);
440 err_gpio_free:
441 gpio_free(gpio_det);
443 return ret;
447 static void armadillo5x0_sdhc1_exit(struct device *dev, void *data)
449 free_irq(IOMUX_TO_IRQ(MX31_PIN_ATA_DMACK), data);
450 gpio_free(IOMUX_TO_GPIO(MX31_PIN_ATA_DMACK));
451 gpio_free(IOMUX_TO_GPIO(MX31_PIN_ATA_RESET_B));
454 static const struct imxmmc_platform_data sdhc_pdata __initconst = {
455 .get_ro = armadillo5x0_sdhc1_get_ro,
456 .init = armadillo5x0_sdhc1_init,
457 .exit = armadillo5x0_sdhc1_exit,
461 * SMSC 9118
462 * Network support
464 static struct resource armadillo5x0_smc911x_resources[] = {
466 .start = MX31_CS3_BASE_ADDR,
467 .end = MX31_CS3_BASE_ADDR + SZ_32M - 1,
468 .flags = IORESOURCE_MEM,
469 }, {
470 .start = IOMUX_TO_IRQ(MX31_PIN_GPIO1_0),
471 .end = IOMUX_TO_IRQ(MX31_PIN_GPIO1_0),
472 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
476 static struct smsc911x_platform_config smsc911x_info = {
477 .flags = SMSC911X_USE_16BIT,
478 .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
479 .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
482 static struct platform_device armadillo5x0_smc911x_device = {
483 .name = "smsc911x",
484 .id = -1,
485 .num_resources = ARRAY_SIZE(armadillo5x0_smc911x_resources),
486 .resource = armadillo5x0_smc911x_resources,
487 .dev = {
488 .platform_data = &smsc911x_info,
492 /* UART device data */
493 static const struct imxuart_platform_data uart_pdata __initconst = {
494 .flags = IMXUART_HAVE_RTSCTS,
497 static struct platform_device *devices[] __initdata = {
498 &armadillo5x0_smc911x_device,
499 &armadillo5x0_button_device,
503 * Perform board specific initializations
505 static void __init armadillo5x0_init(void)
507 mxc_iomux_setup_multiple_pins(armadillo5x0_pins,
508 ARRAY_SIZE(armadillo5x0_pins), "armadillo5x0");
510 platform_add_devices(devices, ARRAY_SIZE(devices));
511 imx31_add_imx_i2c1(NULL);
513 /* Register UART */
514 imx31_add_imx_uart0(&uart_pdata);
515 imx31_add_imx_uart1(&uart_pdata);
517 /* SMSC9118 IRQ pin */
518 gpio_direction_input(MX31_PIN_GPIO1_0);
520 /* Register SDHC */
521 imx31_add_mxc_mmc(0, &sdhc_pdata);
523 /* Register FB */
524 mxc_register_device(&mx3_ipu, &mx3_ipu_data);
525 mxc_register_device(&mx3_fb, &mx3fb_pdata);
527 /* Register NOR Flash */
528 mxc_register_device(&armadillo5x0_nor_flash,
529 &armadillo5x0_nor_flash_pdata);
531 /* Register NAND Flash */
532 imx31_add_mxc_nand(&armadillo5x0_nand_board_info);
534 /* set NAND page size to 2k if not configured via boot mode pins */
535 __raw_writel(__raw_readl(MXC_CCM_RCSR) | (1 << 30), MXC_CCM_RCSR);
537 /* RTC */
538 /* Get RTC IRQ and register the chip */
539 if (gpio_request(ARMADILLO5X0_RTC_GPIO, "rtc") == 0) {
540 if (gpio_direction_input(ARMADILLO5X0_RTC_GPIO) == 0)
541 armadillo5x0_i2c_rtc.irq = gpio_to_irq(ARMADILLO5X0_RTC_GPIO);
542 else
543 gpio_free(ARMADILLO5X0_RTC_GPIO);
545 if (armadillo5x0_i2c_rtc.irq == 0)
546 pr_warning("armadillo5x0_init: failed to get RTC IRQ\n");
547 i2c_register_board_info(1, &armadillo5x0_i2c_rtc, 1);
549 /* USB */
550 #if defined(CONFIG_USB_ULPI)
551 usbotg_pdata.otg = otg_ulpi_create(&mxc_ulpi_access_ops,
552 ULPI_OTG_DRVVBUS | ULPI_OTG_DRVVBUS_EXT);
553 usbh2_pdata.otg = otg_ulpi_create(&mxc_ulpi_access_ops,
554 ULPI_OTG_DRVVBUS | ULPI_OTG_DRVVBUS_EXT);
556 imx31_add_mxc_ehci_otg(&usbotg_pdata);
557 imx31_add_mxc_ehci_hs(2, &usbh2_pdata);
558 #endif
561 static void __init armadillo5x0_timer_init(void)
563 mx31_clocks_init(26000000);
566 static struct sys_timer armadillo5x0_timer = {
567 .init = armadillo5x0_timer_init,
570 MACHINE_START(ARMADILLO5X0, "Armadillo-500")
571 /* Maintainer: Alberto Panizzo */
572 .boot_params = MX3x_PHYS_OFFSET + 0x100,
573 .map_io = mx31_map_io,
574 .init_irq = mx31_init_irq,
575 .timer = &armadillo5x0_timer,
576 .init_machine = armadillo5x0_init,
577 MACHINE_END