1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Copyright 2009 Alberto Panizzo <maramaopercheseimorto@gmail.com>
6 * updates in http://alberdroid.blogspot.com/
8 * Based on Atmark Techno, Inc. armadillo 500 BSP 2008
9 * Based on mx31ads.c and pcm037.c Great Work!
12 #include <linux/types.h>
13 #include <linux/init.h>
14 #include <linux/clk.h>
15 #include <linux/platform_device.h>
16 #include <linux/gpio.h>
17 #include <linux/smsc911x.h>
18 #include <linux/interrupt.h>
19 #include <linux/irq.h>
20 #include <linux/mtd/physmap.h>
22 #include <linux/input.h>
23 #include <linux/i2c.h>
24 #include <linux/usb/otg.h>
25 #include <linux/usb/ulpi.h>
26 #include <linux/delay.h>
27 #include <linux/regulator/machine.h>
28 #include <linux/regulator/fixed.h>
30 #include <asm/mach-types.h>
31 #include <asm/mach/arch.h>
32 #include <asm/mach/time.h>
33 #include <asm/memory.h>
34 #include <asm/mach/map.h>
37 #include "devices-imx31.h"
38 #include "crmregs-imx3.h"
41 #include "iomux-mx3.h"
44 static int armadillo5x0_pins
[] = {
56 IOMUX_MODE(MX31_PIN_GPIO1_0
, IOMUX_CONFIG_GPIO
),
58 MX31_PIN_SD1_DATA3__SD1_DATA3
,
59 MX31_PIN_SD1_DATA2__SD1_DATA2
,
60 MX31_PIN_SD1_DATA1__SD1_DATA1
,
61 MX31_PIN_SD1_DATA0__SD1_DATA0
,
62 MX31_PIN_SD1_CLK__SD1_CLK
,
63 MX31_PIN_SD1_CMD__SD1_CMD
,
83 MX31_PIN_VSYNC3__VSYNC3
,
84 MX31_PIN_HSYNC__HSYNC
,
85 MX31_PIN_FPSHIFT__FPSHIFT
,
86 MX31_PIN_DRDY0__DRDY0
,
87 IOMUX_MODE(MX31_PIN_LCS1
, IOMUX_CONFIG_GPIO
), /*ADV7125_PSAVE*/
89 MX31_PIN_CSPI2_MOSI__SCL
,
90 MX31_PIN_CSPI2_MISO__SDA
,
92 MX31_PIN_USBOTG_DATA0__USBOTG_DATA0
,
93 MX31_PIN_USBOTG_DATA1__USBOTG_DATA1
,
94 MX31_PIN_USBOTG_DATA2__USBOTG_DATA2
,
95 MX31_PIN_USBOTG_DATA3__USBOTG_DATA3
,
96 MX31_PIN_USBOTG_DATA4__USBOTG_DATA4
,
97 MX31_PIN_USBOTG_DATA5__USBOTG_DATA5
,
98 MX31_PIN_USBOTG_DATA6__USBOTG_DATA6
,
99 MX31_PIN_USBOTG_DATA7__USBOTG_DATA7
,
100 MX31_PIN_USBOTG_CLK__USBOTG_CLK
,
101 MX31_PIN_USBOTG_DIR__USBOTG_DIR
,
102 MX31_PIN_USBOTG_NXT__USBOTG_NXT
,
103 MX31_PIN_USBOTG_STP__USBOTG_STP
,
105 IOMUX_MODE(MX31_PIN_USBH2_CLK
, IOMUX_CONFIG_FUNC
),
106 IOMUX_MODE(MX31_PIN_USBH2_DIR
, IOMUX_CONFIG_FUNC
),
107 IOMUX_MODE(MX31_PIN_USBH2_NXT
, IOMUX_CONFIG_FUNC
),
108 IOMUX_MODE(MX31_PIN_USBH2_STP
, IOMUX_CONFIG_FUNC
),
109 IOMUX_MODE(MX31_PIN_USBH2_DATA0
, IOMUX_CONFIG_FUNC
),
110 IOMUX_MODE(MX31_PIN_USBH2_DATA1
, IOMUX_CONFIG_FUNC
),
111 IOMUX_MODE(MX31_PIN_STXD3
, IOMUX_CONFIG_FUNC
),
112 IOMUX_MODE(MX31_PIN_SRXD3
, IOMUX_CONFIG_FUNC
),
113 IOMUX_MODE(MX31_PIN_SCK3
, IOMUX_CONFIG_FUNC
),
114 IOMUX_MODE(MX31_PIN_SFS3
, IOMUX_CONFIG_FUNC
),
115 IOMUX_MODE(MX31_PIN_STXD6
, IOMUX_CONFIG_FUNC
),
116 IOMUX_MODE(MX31_PIN_SRXD6
, IOMUX_CONFIG_FUNC
),
121 #define OTG_RESET IOMUX_TO_GPIO(MX31_PIN_STXD4)
122 #define USBH2_RESET IOMUX_TO_GPIO(MX31_PIN_SCK6)
123 #define USBH2_CS IOMUX_TO_GPIO(MX31_PIN_GPIO1_3)
125 #define USB_PAD_CFG (PAD_CTL_DRV_MAX | PAD_CTL_SRE_FAST | PAD_CTL_HYS_CMOS | \
126 PAD_CTL_ODE_CMOS | PAD_CTL_100K_PU)
128 static int usbotg_init(struct platform_device
*pdev
)
132 mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA0
, USB_PAD_CFG
);
133 mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA1
, USB_PAD_CFG
);
134 mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA2
, USB_PAD_CFG
);
135 mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA3
, USB_PAD_CFG
);
136 mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA4
, USB_PAD_CFG
);
137 mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA5
, USB_PAD_CFG
);
138 mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA6
, USB_PAD_CFG
);
139 mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA7
, USB_PAD_CFG
);
140 mxc_iomux_set_pad(MX31_PIN_USBOTG_CLK
, USB_PAD_CFG
);
141 mxc_iomux_set_pad(MX31_PIN_USBOTG_DIR
, USB_PAD_CFG
);
142 mxc_iomux_set_pad(MX31_PIN_USBOTG_NXT
, USB_PAD_CFG
);
143 mxc_iomux_set_pad(MX31_PIN_USBOTG_STP
, USB_PAD_CFG
);
145 /* Chip already enabled by hardware */
147 err
= gpio_request(OTG_RESET
, "USB-OTG-RESET");
149 pr_err("Failed to request the usb otg reset gpio\n");
153 err
= gpio_direction_output(OTG_RESET
, 1/*HIGH*/);
155 pr_err("Failed to reset the usb otg phy\n");
159 gpio_set_value(OTG_RESET
, 0/*LOW*/);
161 gpio_set_value(OTG_RESET
, 1/*HIGH*/);
164 return mx31_initialize_usb_hw(pdev
->id
, MXC_EHCI_POWER_PINS_ENABLED
|
165 MXC_EHCI_INTERFACE_DIFF_UNI
);
168 gpio_free(OTG_RESET
);
172 static int usbh2_init(struct platform_device
*pdev
)
176 mxc_iomux_set_pad(MX31_PIN_USBH2_CLK
, USB_PAD_CFG
);
177 mxc_iomux_set_pad(MX31_PIN_USBH2_DIR
, USB_PAD_CFG
);
178 mxc_iomux_set_pad(MX31_PIN_USBH2_NXT
, USB_PAD_CFG
);
179 mxc_iomux_set_pad(MX31_PIN_USBH2_STP
, USB_PAD_CFG
);
180 mxc_iomux_set_pad(MX31_PIN_USBH2_DATA0
, USB_PAD_CFG
);
181 mxc_iomux_set_pad(MX31_PIN_USBH2_DATA1
, USB_PAD_CFG
);
182 mxc_iomux_set_pad(MX31_PIN_SRXD6
, USB_PAD_CFG
);
183 mxc_iomux_set_pad(MX31_PIN_STXD6
, USB_PAD_CFG
);
184 mxc_iomux_set_pad(MX31_PIN_SFS3
, USB_PAD_CFG
);
185 mxc_iomux_set_pad(MX31_PIN_SCK3
, USB_PAD_CFG
);
186 mxc_iomux_set_pad(MX31_PIN_SRXD3
, USB_PAD_CFG
);
187 mxc_iomux_set_pad(MX31_PIN_STXD3
, USB_PAD_CFG
);
189 mxc_iomux_set_gpr(MUX_PGP_UH2
, true);
192 /* Enable the chip */
193 err
= gpio_request(USBH2_CS
, "USB-H2-CS");
195 pr_err("Failed to request the usb host 2 CS gpio\n");
199 err
= gpio_direction_output(USBH2_CS
, 0/*Enabled*/);
201 pr_err("Failed to drive the usb host 2 CS gpio\n");
206 err
= gpio_request(USBH2_RESET
, "USB-H2-RESET");
208 pr_err("Failed to request the usb host 2 reset gpio\n");
212 err
= gpio_direction_output(USBH2_RESET
, 1/*HIGH*/);
214 pr_err("Failed to reset the usb host 2 phy\n");
218 gpio_set_value(USBH2_RESET
, 0/*LOW*/);
220 gpio_set_value(USBH2_RESET
, 1/*HIGH*/);
223 return mx31_initialize_usb_hw(pdev
->id
, MXC_EHCI_POWER_PINS_ENABLED
|
224 MXC_EHCI_INTERFACE_DIFF_UNI
);
227 gpio_free(USBH2_RESET
);
233 static struct mxc_usbh_platform_data usbotg_pdata __initdata
= {
235 .portsc
= MXC_EHCI_MODE_ULPI
| MXC_EHCI_UTMI_8BIT
,
238 static struct mxc_usbh_platform_data usbh2_pdata __initdata
= {
240 .portsc
= MXC_EHCI_MODE_ULPI
| MXC_EHCI_UTMI_8BIT
,
244 #define ARMADILLO5X0_RTC_GPIO IOMUX_TO_GPIO(MX31_PIN_SRXD4)
246 static struct i2c_board_info armadillo5x0_i2c_rtc
= {
247 I2C_BOARD_INFO("s35390a", 0x30),
251 static struct gpio_keys_button armadillo5x0_buttons
[] = {
253 .code
= KEY_ENTER
, /*28*/
254 .gpio
= IOMUX_TO_GPIO(MX31_PIN_SCLK0
),
259 .code
= KEY_BACK
, /*158*/
260 .gpio
= IOMUX_TO_GPIO(MX31_PIN_SRST0
),
267 static const struct gpio_keys_platform_data
268 armadillo5x0_button_data __initconst
= {
269 .buttons
= armadillo5x0_buttons
,
270 .nbuttons
= ARRAY_SIZE(armadillo5x0_buttons
),
276 static const struct mxc_nand_platform_data
277 armadillo5x0_nand_board_info __initconst
= {
285 static struct mtd_partition armadillo5x0_nor_flash_partitions
[] = {
287 .name
= "nor.bootloader",
288 .offset
= 0x00000000,
291 .name
= "nor.kernel",
292 .offset
= MTDPART_OFS_APPEND
,
295 .name
= "nor.userland",
296 .offset
= MTDPART_OFS_APPEND
,
297 .size
= 110*128*1024,
299 .name
= "nor.config",
300 .offset
= MTDPART_OFS_APPEND
,
305 static const struct physmap_flash_data
306 armadillo5x0_nor_flash_pdata __initconst
= {
308 .parts
= armadillo5x0_nor_flash_partitions
,
309 .nr_parts
= ARRAY_SIZE(armadillo5x0_nor_flash_partitions
),
312 static const struct resource armadillo5x0_nor_flash_resource __initconst
= {
313 .flags
= IORESOURCE_MEM
,
314 .start
= MX31_CS0_BASE_ADDR
,
315 .end
= MX31_CS0_BASE_ADDR
+ SZ_64M
- 1,
321 static const struct fb_videomode fb_modedb
[] = {
322 { /* 640x480 @ 60 Hz */
334 .sync
= FB_SYNC_OE_ACT_HIGH
,
335 .vmode
= FB_VMODE_NONINTERLACED
,
337 }, {/* 800x600 @ 56 Hz */
349 .sync
= FB_SYNC_OE_ACT_HIGH
| FB_SYNC_HOR_HIGH_ACT
|
350 FB_SYNC_VERT_HIGH_ACT
,
351 .vmode
= FB_VMODE_NONINTERLACED
,
356 static struct mx3fb_platform_data mx3fb_pdata __initdata
= {
359 .num_modes
= ARRAY_SIZE(fb_modedb
),
366 static int armadillo5x0_sdhc1_get_ro(struct device
*dev
)
368 return gpio_get_value(IOMUX_TO_GPIO(MX31_PIN_ATA_RESET_B
));
371 static int armadillo5x0_sdhc1_init(struct device
*dev
,
372 irq_handler_t detect_irq
, void *data
)
375 int gpio_det
, gpio_wp
;
377 gpio_det
= IOMUX_TO_GPIO(MX31_PIN_ATA_DMACK
);
378 gpio_wp
= IOMUX_TO_GPIO(MX31_PIN_ATA_RESET_B
);
380 ret
= gpio_request(gpio_det
, "sdhc-card-detect");
384 gpio_direction_input(gpio_det
);
386 ret
= gpio_request(gpio_wp
, "sdhc-write-protect");
390 gpio_direction_input(gpio_wp
);
392 /* When supported the trigger type have to be BOTH */
393 ret
= request_irq(gpio_to_irq(IOMUX_TO_GPIO(MX31_PIN_ATA_DMACK
)),
394 detect_irq
, IRQF_TRIGGER_FALLING
,
395 "sdhc-detect", data
);
398 goto err_gpio_free_2
;
412 static void armadillo5x0_sdhc1_exit(struct device
*dev
, void *data
)
414 free_irq(gpio_to_irq(IOMUX_TO_GPIO(MX31_PIN_ATA_DMACK
)), data
);
415 gpio_free(IOMUX_TO_GPIO(MX31_PIN_ATA_DMACK
));
416 gpio_free(IOMUX_TO_GPIO(MX31_PIN_ATA_RESET_B
));
419 static const struct imxmmc_platform_data sdhc_pdata __initconst
= {
420 .get_ro
= armadillo5x0_sdhc1_get_ro
,
421 .init
= armadillo5x0_sdhc1_init
,
422 .exit
= armadillo5x0_sdhc1_exit
,
429 static struct resource armadillo5x0_smc911x_resources
[] = {
431 .start
= MX31_CS3_BASE_ADDR
,
432 .end
= MX31_CS3_BASE_ADDR
+ SZ_32M
- 1,
433 .flags
= IORESOURCE_MEM
,
435 /* irq number is run-time assigned */
436 .flags
= IORESOURCE_IRQ
| IORESOURCE_IRQ_LOWLEVEL
,
440 static struct smsc911x_platform_config smsc911x_info
= {
441 .flags
= SMSC911X_USE_16BIT
,
442 .irq_polarity
= SMSC911X_IRQ_POLARITY_ACTIVE_LOW
,
443 .irq_type
= SMSC911X_IRQ_TYPE_PUSH_PULL
,
446 static struct platform_device armadillo5x0_smc911x_device
= {
449 .num_resources
= ARRAY_SIZE(armadillo5x0_smc911x_resources
),
450 .resource
= armadillo5x0_smc911x_resources
,
452 .platform_data
= &smsc911x_info
,
456 /* UART device data */
457 static const struct imxuart_platform_data uart_pdata __initconst
= {
458 .flags
= IMXUART_HAVE_RTSCTS
,
461 static struct platform_device
*devices
[] __initdata
= {
462 &armadillo5x0_smc911x_device
,
465 static struct regulator_consumer_supply dummy_supplies
[] = {
466 REGULATOR_SUPPLY("vdd33a", "smsc911x"),
467 REGULATOR_SUPPLY("vddvario", "smsc911x"),
471 * Perform board specific initializations
473 static void __init
armadillo5x0_init(void)
477 mxc_iomux_setup_multiple_pins(armadillo5x0_pins
,
478 ARRAY_SIZE(armadillo5x0_pins
), "armadillo5x0");
480 regulator_register_fixed(0, dummy_supplies
, ARRAY_SIZE(dummy_supplies
));
482 imx31_add_imx_i2c1(NULL
);
485 imx31_add_imx_uart0(&uart_pdata
);
486 imx31_add_imx_uart1(&uart_pdata
);
489 imx31_add_ipu_core();
490 imx31_add_mx3_sdc_fb(&mx3fb_pdata
);
492 /* Register NOR Flash */
493 platform_device_register_resndata(NULL
, "physmap-flash", -1,
494 &armadillo5x0_nor_flash_resource
, 1,
495 &armadillo5x0_nor_flash_pdata
,
496 sizeof(armadillo5x0_nor_flash_pdata
));
498 /* Register NAND Flash */
499 imx31_add_mxc_nand(&armadillo5x0_nand_board_info
);
501 /* set NAND page size to 2k if not configured via boot mode pins */
502 imx_writel(imx_readl(mx3_ccm_base
+ MXC_CCM_RCSR
) | (1 << 30),
503 mx3_ccm_base
+ MXC_CCM_RCSR
);
506 static void __init
armadillo5x0_late(void)
508 armadillo5x0_smc911x_resources
[1].start
=
509 gpio_to_irq(IOMUX_TO_GPIO(MX31_PIN_GPIO1_0
));
510 armadillo5x0_smc911x_resources
[1].end
=
511 gpio_to_irq(IOMUX_TO_GPIO(MX31_PIN_GPIO1_0
));
512 platform_add_devices(devices
, ARRAY_SIZE(devices
));
514 imx_add_gpio_keys(&armadillo5x0_button_data
);
516 /* SMSC9118 IRQ pin */
517 gpio_direction_input(MX31_PIN_GPIO1_0
);
520 imx31_add_mxc_mmc(0, &sdhc_pdata
);
523 /* Get RTC IRQ and register the chip */
524 if (!gpio_request(ARMADILLO5X0_RTC_GPIO
, "rtc")) {
525 if (!gpio_direction_input(ARMADILLO5X0_RTC_GPIO
))
526 armadillo5x0_i2c_rtc
.irq
=
527 gpio_to_irq(ARMADILLO5X0_RTC_GPIO
);
529 gpio_free(ARMADILLO5X0_RTC_GPIO
);
532 if (armadillo5x0_i2c_rtc
.irq
== 0)
533 pr_warn("armadillo5x0_init: failed to get RTC IRQ\n");
534 i2c_register_board_info(1, &armadillo5x0_i2c_rtc
, 1);
537 usbotg_pdata
.otg
= imx_otg_ulpi_create(ULPI_OTG_DRVVBUS
|
538 ULPI_OTG_DRVVBUS_EXT
);
539 if (usbotg_pdata
.otg
)
540 imx31_add_mxc_ehci_otg(&usbotg_pdata
);
541 usbh2_pdata
.otg
= imx_otg_ulpi_create(ULPI_OTG_DRVVBUS
|
542 ULPI_OTG_DRVVBUS_EXT
);
544 imx31_add_mxc_ehci_hs(2, &usbh2_pdata
);
547 static void __init
armadillo5x0_timer_init(void)
549 mx31_clocks_init(26000000);
552 MACHINE_START(ARMADILLO5X0
, "Armadillo-500")
553 /* Maintainer: Alberto Panizzo */
554 .atag_offset
= 0x100,
555 .map_io
= mx31_map_io
,
556 .init_early
= imx31_init_early
,
557 .init_irq
= mx31_init_irq
,
558 .init_time
= armadillo5x0_timer_init
,
559 .init_machine
= armadillo5x0_init
,
560 .init_late
= armadillo5x0_late
,
561 .restart
= mxc_restart
,