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,
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>
36 #include <linux/input.h>
37 #include <linux/i2c.h>
38 #include <linux/usb/otg.h>
39 #include <linux/usb/ulpi.h>
40 #include <linux/delay.h>
41 #include <linux/regulator/machine.h>
42 #include <linux/regulator/fixed.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>
51 #include "devices-imx31.h"
52 #include "crmregs-imx3.h"
54 #include "iomux-mx3.h"
57 static int armadillo5x0_pins
[] = {
69 IOMUX_MODE(MX31_PIN_GPIO1_0
, IOMUX_CONFIG_GPIO
),
71 MX31_PIN_SD1_DATA3__SD1_DATA3
,
72 MX31_PIN_SD1_DATA2__SD1_DATA2
,
73 MX31_PIN_SD1_DATA1__SD1_DATA1
,
74 MX31_PIN_SD1_DATA0__SD1_DATA0
,
75 MX31_PIN_SD1_CLK__SD1_CLK
,
76 MX31_PIN_SD1_CMD__SD1_CMD
,
96 MX31_PIN_VSYNC3__VSYNC3
,
97 MX31_PIN_HSYNC__HSYNC
,
98 MX31_PIN_FPSHIFT__FPSHIFT
,
99 MX31_PIN_DRDY0__DRDY0
,
100 IOMUX_MODE(MX31_PIN_LCS1
, IOMUX_CONFIG_GPIO
), /*ADV7125_PSAVE*/
102 MX31_PIN_CSPI2_MOSI__SCL
,
103 MX31_PIN_CSPI2_MISO__SDA
,
105 MX31_PIN_USBOTG_DATA0__USBOTG_DATA0
,
106 MX31_PIN_USBOTG_DATA1__USBOTG_DATA1
,
107 MX31_PIN_USBOTG_DATA2__USBOTG_DATA2
,
108 MX31_PIN_USBOTG_DATA3__USBOTG_DATA3
,
109 MX31_PIN_USBOTG_DATA4__USBOTG_DATA4
,
110 MX31_PIN_USBOTG_DATA5__USBOTG_DATA5
,
111 MX31_PIN_USBOTG_DATA6__USBOTG_DATA6
,
112 MX31_PIN_USBOTG_DATA7__USBOTG_DATA7
,
113 MX31_PIN_USBOTG_CLK__USBOTG_CLK
,
114 MX31_PIN_USBOTG_DIR__USBOTG_DIR
,
115 MX31_PIN_USBOTG_NXT__USBOTG_NXT
,
116 MX31_PIN_USBOTG_STP__USBOTG_STP
,
118 IOMUX_MODE(MX31_PIN_USBH2_CLK
, IOMUX_CONFIG_FUNC
),
119 IOMUX_MODE(MX31_PIN_USBH2_DIR
, IOMUX_CONFIG_FUNC
),
120 IOMUX_MODE(MX31_PIN_USBH2_NXT
, IOMUX_CONFIG_FUNC
),
121 IOMUX_MODE(MX31_PIN_USBH2_STP
, IOMUX_CONFIG_FUNC
),
122 IOMUX_MODE(MX31_PIN_USBH2_DATA0
, IOMUX_CONFIG_FUNC
),
123 IOMUX_MODE(MX31_PIN_USBH2_DATA1
, IOMUX_CONFIG_FUNC
),
124 IOMUX_MODE(MX31_PIN_STXD3
, IOMUX_CONFIG_FUNC
),
125 IOMUX_MODE(MX31_PIN_SRXD3
, IOMUX_CONFIG_FUNC
),
126 IOMUX_MODE(MX31_PIN_SCK3
, IOMUX_CONFIG_FUNC
),
127 IOMUX_MODE(MX31_PIN_SFS3
, IOMUX_CONFIG_FUNC
),
128 IOMUX_MODE(MX31_PIN_STXD6
, IOMUX_CONFIG_FUNC
),
129 IOMUX_MODE(MX31_PIN_SRXD6
, IOMUX_CONFIG_FUNC
),
134 #define OTG_RESET IOMUX_TO_GPIO(MX31_PIN_STXD4)
135 #define USBH2_RESET IOMUX_TO_GPIO(MX31_PIN_SCK6)
136 #define USBH2_CS IOMUX_TO_GPIO(MX31_PIN_GPIO1_3)
138 #define USB_PAD_CFG (PAD_CTL_DRV_MAX | PAD_CTL_SRE_FAST | PAD_CTL_HYS_CMOS | \
139 PAD_CTL_ODE_CMOS | PAD_CTL_100K_PU)
141 static int usbotg_init(struct platform_device
*pdev
)
145 mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA0
, USB_PAD_CFG
);
146 mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA1
, USB_PAD_CFG
);
147 mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA2
, USB_PAD_CFG
);
148 mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA3
, USB_PAD_CFG
);
149 mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA4
, USB_PAD_CFG
);
150 mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA5
, USB_PAD_CFG
);
151 mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA6
, USB_PAD_CFG
);
152 mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA7
, USB_PAD_CFG
);
153 mxc_iomux_set_pad(MX31_PIN_USBOTG_CLK
, USB_PAD_CFG
);
154 mxc_iomux_set_pad(MX31_PIN_USBOTG_DIR
, USB_PAD_CFG
);
155 mxc_iomux_set_pad(MX31_PIN_USBOTG_NXT
, USB_PAD_CFG
);
156 mxc_iomux_set_pad(MX31_PIN_USBOTG_STP
, USB_PAD_CFG
);
158 /* Chip already enabled by hardware */
160 err
= gpio_request(OTG_RESET
, "USB-OTG-RESET");
162 pr_err("Failed to request the usb otg reset gpio\n");
166 err
= gpio_direction_output(OTG_RESET
, 1/*HIGH*/);
168 pr_err("Failed to reset the usb otg phy\n");
172 gpio_set_value(OTG_RESET
, 0/*LOW*/);
174 gpio_set_value(OTG_RESET
, 1/*HIGH*/);
177 return mx31_initialize_usb_hw(pdev
->id
, MXC_EHCI_POWER_PINS_ENABLED
|
178 MXC_EHCI_INTERFACE_DIFF_UNI
);
181 gpio_free(OTG_RESET
);
185 static int usbh2_init(struct platform_device
*pdev
)
189 mxc_iomux_set_pad(MX31_PIN_USBH2_CLK
, USB_PAD_CFG
);
190 mxc_iomux_set_pad(MX31_PIN_USBH2_DIR
, USB_PAD_CFG
);
191 mxc_iomux_set_pad(MX31_PIN_USBH2_NXT
, USB_PAD_CFG
);
192 mxc_iomux_set_pad(MX31_PIN_USBH2_STP
, USB_PAD_CFG
);
193 mxc_iomux_set_pad(MX31_PIN_USBH2_DATA0
, USB_PAD_CFG
);
194 mxc_iomux_set_pad(MX31_PIN_USBH2_DATA1
, USB_PAD_CFG
);
195 mxc_iomux_set_pad(MX31_PIN_SRXD6
, USB_PAD_CFG
);
196 mxc_iomux_set_pad(MX31_PIN_STXD6
, USB_PAD_CFG
);
197 mxc_iomux_set_pad(MX31_PIN_SFS3
, USB_PAD_CFG
);
198 mxc_iomux_set_pad(MX31_PIN_SCK3
, USB_PAD_CFG
);
199 mxc_iomux_set_pad(MX31_PIN_SRXD3
, USB_PAD_CFG
);
200 mxc_iomux_set_pad(MX31_PIN_STXD3
, USB_PAD_CFG
);
202 mxc_iomux_set_gpr(MUX_PGP_UH2
, true);
205 /* Enable the chip */
206 err
= gpio_request(USBH2_CS
, "USB-H2-CS");
208 pr_err("Failed to request the usb host 2 CS gpio\n");
212 err
= gpio_direction_output(USBH2_CS
, 0/*Enabled*/);
214 pr_err("Failed to drive the usb host 2 CS gpio\n");
219 err
= gpio_request(USBH2_RESET
, "USB-H2-RESET");
221 pr_err("Failed to request the usb host 2 reset gpio\n");
225 err
= gpio_direction_output(USBH2_RESET
, 1/*HIGH*/);
227 pr_err("Failed to reset the usb host 2 phy\n");
231 gpio_set_value(USBH2_RESET
, 0/*LOW*/);
233 gpio_set_value(USBH2_RESET
, 1/*HIGH*/);
236 return mx31_initialize_usb_hw(pdev
->id
, MXC_EHCI_POWER_PINS_ENABLED
|
237 MXC_EHCI_INTERFACE_DIFF_UNI
);
240 gpio_free(USBH2_RESET
);
246 static struct mxc_usbh_platform_data usbotg_pdata __initdata
= {
248 .portsc
= MXC_EHCI_MODE_ULPI
| MXC_EHCI_UTMI_8BIT
,
251 static struct mxc_usbh_platform_data usbh2_pdata __initdata
= {
253 .portsc
= MXC_EHCI_MODE_ULPI
| MXC_EHCI_UTMI_8BIT
,
257 #define ARMADILLO5X0_RTC_GPIO IOMUX_TO_GPIO(MX31_PIN_SRXD4)
259 static struct i2c_board_info armadillo5x0_i2c_rtc
= {
260 I2C_BOARD_INFO("s35390a", 0x30),
264 static struct gpio_keys_button armadillo5x0_buttons
[] = {
266 .code
= KEY_ENTER
, /*28*/
267 .gpio
= IOMUX_TO_GPIO(MX31_PIN_SCLK0
),
272 .code
= KEY_BACK
, /*158*/
273 .gpio
= IOMUX_TO_GPIO(MX31_PIN_SRST0
),
280 static const struct gpio_keys_platform_data
281 armadillo5x0_button_data __initconst
= {
282 .buttons
= armadillo5x0_buttons
,
283 .nbuttons
= ARRAY_SIZE(armadillo5x0_buttons
),
289 static const struct mxc_nand_platform_data
290 armadillo5x0_nand_board_info __initconst
= {
298 static struct mtd_partition armadillo5x0_nor_flash_partitions
[] = {
300 .name
= "nor.bootloader",
301 .offset
= 0x00000000,
304 .name
= "nor.kernel",
305 .offset
= MTDPART_OFS_APPEND
,
308 .name
= "nor.userland",
309 .offset
= MTDPART_OFS_APPEND
,
310 .size
= 110*128*1024,
312 .name
= "nor.config",
313 .offset
= MTDPART_OFS_APPEND
,
318 static const struct physmap_flash_data
319 armadillo5x0_nor_flash_pdata __initconst
= {
321 .parts
= armadillo5x0_nor_flash_partitions
,
322 .nr_parts
= ARRAY_SIZE(armadillo5x0_nor_flash_partitions
),
325 static const struct resource armadillo5x0_nor_flash_resource __initconst
= {
326 .flags
= IORESOURCE_MEM
,
327 .start
= MX31_CS0_BASE_ADDR
,
328 .end
= MX31_CS0_BASE_ADDR
+ SZ_64M
- 1,
334 static const struct fb_videomode fb_modedb
[] = {
335 { /* 640x480 @ 60 Hz */
347 .sync
= FB_SYNC_OE_ACT_HIGH
,
348 .vmode
= FB_VMODE_NONINTERLACED
,
350 }, {/* 800x600 @ 56 Hz */
362 .sync
= FB_SYNC_OE_ACT_HIGH
| FB_SYNC_HOR_HIGH_ACT
|
363 FB_SYNC_VERT_HIGH_ACT
,
364 .vmode
= FB_VMODE_NONINTERLACED
,
369 static struct mx3fb_platform_data mx3fb_pdata __initdata
= {
372 .num_modes
= ARRAY_SIZE(fb_modedb
),
379 static int armadillo5x0_sdhc1_get_ro(struct device
*dev
)
381 return gpio_get_value(IOMUX_TO_GPIO(MX31_PIN_ATA_RESET_B
));
384 static int armadillo5x0_sdhc1_init(struct device
*dev
,
385 irq_handler_t detect_irq
, void *data
)
388 int gpio_det
, gpio_wp
;
390 gpio_det
= IOMUX_TO_GPIO(MX31_PIN_ATA_DMACK
);
391 gpio_wp
= IOMUX_TO_GPIO(MX31_PIN_ATA_RESET_B
);
393 ret
= gpio_request(gpio_det
, "sdhc-card-detect");
397 gpio_direction_input(gpio_det
);
399 ret
= gpio_request(gpio_wp
, "sdhc-write-protect");
403 gpio_direction_input(gpio_wp
);
405 /* When supported the trigger type have to be BOTH */
406 ret
= request_irq(gpio_to_irq(IOMUX_TO_GPIO(MX31_PIN_ATA_DMACK
)),
407 detect_irq
, IRQF_TRIGGER_FALLING
,
408 "sdhc-detect", data
);
411 goto err_gpio_free_2
;
425 static void armadillo5x0_sdhc1_exit(struct device
*dev
, void *data
)
427 free_irq(gpio_to_irq(IOMUX_TO_GPIO(MX31_PIN_ATA_DMACK
)), data
);
428 gpio_free(IOMUX_TO_GPIO(MX31_PIN_ATA_DMACK
));
429 gpio_free(IOMUX_TO_GPIO(MX31_PIN_ATA_RESET_B
));
432 static const struct imxmmc_platform_data sdhc_pdata __initconst
= {
433 .get_ro
= armadillo5x0_sdhc1_get_ro
,
434 .init
= armadillo5x0_sdhc1_init
,
435 .exit
= armadillo5x0_sdhc1_exit
,
442 static struct resource armadillo5x0_smc911x_resources
[] = {
444 .start
= MX31_CS3_BASE_ADDR
,
445 .end
= MX31_CS3_BASE_ADDR
+ SZ_32M
- 1,
446 .flags
= IORESOURCE_MEM
,
448 /* irq number is run-time assigned */
449 .flags
= IORESOURCE_IRQ
| IORESOURCE_IRQ_LOWLEVEL
,
453 static struct smsc911x_platform_config smsc911x_info
= {
454 .flags
= SMSC911X_USE_16BIT
,
455 .irq_polarity
= SMSC911X_IRQ_POLARITY_ACTIVE_LOW
,
456 .irq_type
= SMSC911X_IRQ_TYPE_PUSH_PULL
,
459 static struct platform_device armadillo5x0_smc911x_device
= {
462 .num_resources
= ARRAY_SIZE(armadillo5x0_smc911x_resources
),
463 .resource
= armadillo5x0_smc911x_resources
,
465 .platform_data
= &smsc911x_info
,
469 /* UART device data */
470 static const struct imxuart_platform_data uart_pdata __initconst
= {
471 .flags
= IMXUART_HAVE_RTSCTS
,
474 static struct platform_device
*devices
[] __initdata
= {
475 &armadillo5x0_smc911x_device
,
478 static struct regulator_consumer_supply dummy_supplies
[] = {
479 REGULATOR_SUPPLY("vdd33a", "smsc911x"),
480 REGULATOR_SUPPLY("vddvario", "smsc911x"),
484 * Perform board specific initializations
486 static void __init
armadillo5x0_init(void)
490 mxc_iomux_setup_multiple_pins(armadillo5x0_pins
,
491 ARRAY_SIZE(armadillo5x0_pins
), "armadillo5x0");
493 regulator_register_fixed(0, dummy_supplies
, ARRAY_SIZE(dummy_supplies
));
495 armadillo5x0_smc911x_resources
[1].start
=
496 gpio_to_irq(IOMUX_TO_GPIO(MX31_PIN_GPIO1_0
));
497 armadillo5x0_smc911x_resources
[1].end
=
498 gpio_to_irq(IOMUX_TO_GPIO(MX31_PIN_GPIO1_0
));
499 platform_add_devices(devices
, ARRAY_SIZE(devices
));
500 imx_add_gpio_keys(&armadillo5x0_button_data
);
501 imx31_add_imx_i2c1(NULL
);
504 imx31_add_imx_uart0(&uart_pdata
);
505 imx31_add_imx_uart1(&uart_pdata
);
507 /* SMSC9118 IRQ pin */
508 gpio_direction_input(MX31_PIN_GPIO1_0
);
511 imx31_add_mxc_mmc(0, &sdhc_pdata
);
514 imx31_add_ipu_core();
515 imx31_add_mx3_sdc_fb(&mx3fb_pdata
);
517 /* Register NOR Flash */
518 platform_device_register_resndata(NULL
, "physmap-flash", -1,
519 &armadillo5x0_nor_flash_resource
, 1,
520 &armadillo5x0_nor_flash_pdata
,
521 sizeof(armadillo5x0_nor_flash_pdata
));
523 /* Register NAND Flash */
524 imx31_add_mxc_nand(&armadillo5x0_nand_board_info
);
526 /* set NAND page size to 2k if not configured via boot mode pins */
527 __raw_writel(__raw_readl(mx3_ccm_base
+ MXC_CCM_RCSR
) |
528 (1 << 30), mx3_ccm_base
+ MXC_CCM_RCSR
);
531 /* Get RTC IRQ and register the chip */
532 if (gpio_request(ARMADILLO5X0_RTC_GPIO
, "rtc") == 0) {
533 if (gpio_direction_input(ARMADILLO5X0_RTC_GPIO
) == 0)
534 armadillo5x0_i2c_rtc
.irq
= gpio_to_irq(ARMADILLO5X0_RTC_GPIO
);
536 gpio_free(ARMADILLO5X0_RTC_GPIO
);
538 if (armadillo5x0_i2c_rtc
.irq
== 0)
539 pr_warning("armadillo5x0_init: failed to get RTC IRQ\n");
540 i2c_register_board_info(1, &armadillo5x0_i2c_rtc
, 1);
544 usbotg_pdata
.otg
= imx_otg_ulpi_create(ULPI_OTG_DRVVBUS
|
545 ULPI_OTG_DRVVBUS_EXT
);
546 if (usbotg_pdata
.otg
)
547 imx31_add_mxc_ehci_otg(&usbotg_pdata
);
548 usbh2_pdata
.otg
= imx_otg_ulpi_create(ULPI_OTG_DRVVBUS
|
549 ULPI_OTG_DRVVBUS_EXT
);
551 imx31_add_mxc_ehci_hs(2, &usbh2_pdata
);
554 static void __init
armadillo5x0_timer_init(void)
556 mx31_clocks_init(26000000);
559 MACHINE_START(ARMADILLO5X0
, "Armadillo-500")
560 /* Maintainer: Alberto Panizzo */
561 .atag_offset
= 0x100,
562 .map_io
= mx31_map_io
,
563 .init_early
= imx31_init_early
,
564 .init_irq
= mx31_init_irq
,
565 .init_time
= armadillo5x0_timer_init
,
566 .init_machine
= armadillo5x0_init
,
567 .restart
= mxc_restart
,