2 * Copyright (C) 2008 Sascha Hauer, Pengutronix
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
15 #include <linux/types.h>
16 #include <linux/init.h>
17 #include <linux/dma-mapping.h>
18 #include <linux/platform_device.h>
19 #include <linux/mtd/physmap.h>
20 #include <linux/mtd/plat-ram.h>
21 #include <linux/memory.h>
22 #include <linux/gpio.h>
23 #include <linux/smsc911x.h>
24 #include <linux/interrupt.h>
25 #include <linux/i2c.h>
26 #include <linux/i2c/at24.h>
27 #include <linux/delay.h>
28 #include <linux/spi/spi.h>
29 #include <linux/irq.h>
30 #include <linux/can/platform/sja1000.h>
31 #include <linux/usb/otg.h>
32 #include <linux/usb/ulpi.h>
33 #include <linux/gfp.h>
35 #include <media/soc_camera.h>
37 #include <asm/mach-types.h>
38 #include <asm/mach/arch.h>
39 #include <asm/mach/time.h>
40 #include <asm/mach/map.h>
41 #include <mach/common.h>
42 #include <mach/hardware.h>
43 #include <mach/iomux-mx3.h>
45 #include <mach/mx3_camera.h>
46 #include <mach/mx3fb.h>
47 #include <mach/ulpi.h>
49 #include "devices-imx31.h"
53 static enum pcm037_board_variant pcm037_instance = PCM037_PCM970;
55 static int __init pcm037_variant_setup(char *str)
57 if (!strcmp("eet", str))
58 pcm037_instance = PCM037_EET;
59 else if (strcmp("pcm970", str))
60 pr_warning("Unknown pcm037 baseboard variant %s\n", str);
65 /* Supported values: "pcm970" (default) and "eet" */
66 __setup("pcm037_variant=", pcm037_variant_setup);
68 enum pcm037_board_variant pcm037_variant(void)
70 return pcm037_instance;
73 /* UART1 with RTS/CTS handshake signals */
74 static unsigned int pcm037_uart1_handshake_pins[] = {
81 /* UART1 without RTS/CTS handshake signals */
82 static unsigned int pcm037_uart1_pins[] = {
87 static unsigned int pcm037_pins[] = {
89 MX31_PIN_CSPI2_MOSI__SCL,
90 MX31_PIN_CSPI2_MISO__SDA,
91 MX31_PIN_CSPI2_SS2__I2C3_SDA,
92 MX31_PIN_CSPI2_SCLK__I2C3_SCL,
94 MX31_PIN_SD1_DATA3__SD1_DATA3,
95 MX31_PIN_SD1_DATA2__SD1_DATA2,
96 MX31_PIN_SD1_DATA1__SD1_DATA1,
97 MX31_PIN_SD1_DATA0__SD1_DATA0,
98 MX31_PIN_SD1_CLK__SD1_CLK,
99 MX31_PIN_SD1_CMD__SD1_CMD,
100 IOMUX_MODE(MX31_PIN_SCK6, IOMUX_CONFIG_GPIO), /* card detect */
101 IOMUX_MODE(MX31_PIN_SFS6, IOMUX_CONFIG_GPIO), /* write protect */
103 MX31_PIN_CSPI1_MOSI__MOSI,
104 MX31_PIN_CSPI1_MISO__MISO,
105 MX31_PIN_CSPI1_SCLK__SCLK,
106 MX31_PIN_CSPI1_SPI_RDY__SPI_RDY,
107 MX31_PIN_CSPI1_SS0__SS0,
108 MX31_PIN_CSPI1_SS1__SS1,
109 MX31_PIN_CSPI1_SS2__SS2,
116 MX31_PIN_CSPI3_MOSI__RXD3,
117 MX31_PIN_CSPI3_MISO__TXD3,
118 MX31_PIN_CSPI3_SCLK__RTS3,
119 MX31_PIN_CSPI3_SPI_RDY__CTS3,
120 /* LAN9217 irq pin */
121 IOMUX_MODE(MX31_PIN_GPIO3_1, IOMUX_CONFIG_GPIO),
123 MX31_PIN_BATT_LINE__OWIRE,
143 MX31_PIN_VSYNC3__VSYNC3,
144 MX31_PIN_HSYNC__HSYNC,
145 MX31_PIN_FPSHIFT__FPSHIFT,
146 MX31_PIN_DRDY0__DRDY0,
147 MX31_PIN_D3_REV__D3_REV,
148 MX31_PIN_CONTRAST__CONTRAST,
149 MX31_PIN_D3_SPL__D3_SPL,
150 MX31_PIN_D3_CLS__D3_CLS,
151 MX31_PIN_LCS0__GPI03_23,
153 IOMUX_MODE(MX31_PIN_CSI_D5, IOMUX_CONFIG_GPIO),
154 MX31_PIN_CSI_D6__CSI_D6,
155 MX31_PIN_CSI_D7__CSI_D7,
156 MX31_PIN_CSI_D8__CSI_D8,
157 MX31_PIN_CSI_D9__CSI_D9,
158 MX31_PIN_CSI_D10__CSI_D10,
159 MX31_PIN_CSI_D11__CSI_D11,
160 MX31_PIN_CSI_D12__CSI_D12,
161 MX31_PIN_CSI_D13__CSI_D13,
162 MX31_PIN_CSI_D14__CSI_D14,
163 MX31_PIN_CSI_D15__CSI_D15,
164 MX31_PIN_CSI_HSYNC__CSI_HSYNC,
165 MX31_PIN_CSI_MCLK__CSI_MCLK,
166 MX31_PIN_CSI_PIXCLK__CSI_PIXCLK,
167 MX31_PIN_CSI_VSYNC__CSI_VSYNC,
169 IOMUX_MODE(MX31_PIN_ATA_DMACK, IOMUX_CONFIG_GPIO),
171 MX31_PIN_USBOTG_DATA0__USBOTG_DATA0,
172 MX31_PIN_USBOTG_DATA1__USBOTG_DATA1,
173 MX31_PIN_USBOTG_DATA2__USBOTG_DATA2,
174 MX31_PIN_USBOTG_DATA3__USBOTG_DATA3,
175 MX31_PIN_USBOTG_DATA4__USBOTG_DATA4,
176 MX31_PIN_USBOTG_DATA5__USBOTG_DATA5,
177 MX31_PIN_USBOTG_DATA6__USBOTG_DATA6,
178 MX31_PIN_USBOTG_DATA7__USBOTG_DATA7,
179 MX31_PIN_USBOTG_CLK__USBOTG_CLK,
180 MX31_PIN_USBOTG_DIR__USBOTG_DIR,
181 MX31_PIN_USBOTG_NXT__USBOTG_NXT,
182 MX31_PIN_USBOTG_STP__USBOTG_STP,
184 IOMUX_MODE(MX31_PIN_USBH2_CLK, IOMUX_CONFIG_FUNC),
185 IOMUX_MODE(MX31_PIN_USBH2_DIR, IOMUX_CONFIG_FUNC),
186 IOMUX_MODE(MX31_PIN_USBH2_NXT, IOMUX_CONFIG_FUNC),
187 IOMUX_MODE(MX31_PIN_USBH2_STP, IOMUX_CONFIG_FUNC),
188 IOMUX_MODE(MX31_PIN_USBH2_DATA0, IOMUX_CONFIG_FUNC),
189 IOMUX_MODE(MX31_PIN_USBH2_DATA1, IOMUX_CONFIG_FUNC),
190 IOMUX_MODE(MX31_PIN_STXD3, IOMUX_CONFIG_FUNC),
191 IOMUX_MODE(MX31_PIN_SRXD3, IOMUX_CONFIG_FUNC),
192 IOMUX_MODE(MX31_PIN_SCK3, IOMUX_CONFIG_FUNC),
193 IOMUX_MODE(MX31_PIN_SFS3, IOMUX_CONFIG_FUNC),
194 IOMUX_MODE(MX31_PIN_STXD6, IOMUX_CONFIG_FUNC),
195 IOMUX_MODE(MX31_PIN_SRXD6, IOMUX_CONFIG_FUNC),
198 static struct physmap_flash_data pcm037_flash_data = {
202 static struct resource pcm037_flash_resource = {
205 .flags = IORESOURCE_MEM,
208 static struct platform_device pcm037_flash = {
209 .name = "physmap-flash",
212 .platform_data = &pcm037_flash_data,
214 .resource = &pcm037_flash_resource,
218 static const struct imxuart_platform_data uart_pdata __initconst = {
219 .flags = IMXUART_HAVE_RTSCTS,
222 static struct resource smsc911x_resources[] = {
224 .start = MX31_CS1_BASE_ADDR + 0x300,
225 .end = MX31_CS1_BASE_ADDR + 0x300 + SZ_64K - 1,
226 .flags = IORESOURCE_MEM,
228 .start = IOMUX_TO_IRQ(MX31_PIN_GPIO3_1),
229 .end = IOMUX_TO_IRQ(MX31_PIN_GPIO3_1),
230 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
234 static struct smsc911x_platform_config smsc911x_info = {
235 .flags = SMSC911X_USE_32BIT | SMSC911X_FORCE_INTERNAL_PHY |
236 SMSC911X_SAVE_MAC_ADDRESS,
237 .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
238 .irq_type = SMSC911X_IRQ_TYPE_OPEN_DRAIN,
239 .phy_interface = PHY_INTERFACE_MODE_MII,
242 static struct platform_device pcm037_eth = {
245 .num_resources = ARRAY_SIZE(smsc911x_resources),
246 .resource = smsc911x_resources,
248 .platform_data = &smsc911x_info,
252 static struct platdata_mtd_ram pcm038_sram_data = {
256 static struct resource pcm038_sram_resource = {
257 .start = MX31_CS4_BASE_ADDR,
258 .end = MX31_CS4_BASE_ADDR + 512 * 1024 - 1,
259 .flags = IORESOURCE_MEM,
262 static struct platform_device pcm037_sram_device = {
266 .platform_data = &pcm038_sram_data,
269 .resource = &pcm038_sram_resource,
272 static const struct mxc_nand_platform_data
273 pcm037_nand_board_info __initconst = {
278 static const struct imxi2c_platform_data pcm037_i2c1_data __initconst = {
282 static const struct imxi2c_platform_data pcm037_i2c2_data __initconst = {
286 static struct at24_platform_data board_eeprom = {
289 .flags = AT24_FLAG_ADDR16,
292 static int pcm037_camera_power(struct device *dev, int on)
294 /* disable or enable the camera in X7 or X8 PCM970 connector */
295 gpio_set_value(IOMUX_TO_GPIO(MX31_PIN_CSI_D5), !on);
299 static struct i2c_board_info pcm037_i2c_camera[] = {
301 I2C_BOARD_INFO("mt9t031", 0x5d),
303 I2C_BOARD_INFO("mt9v022", 0x48),
307 static struct soc_camera_link iclink_mt9v022 = {
308 .bus_id = 0, /* Must match with the camera ID */
309 .board_info = &pcm037_i2c_camera[1],
313 static struct soc_camera_link iclink_mt9t031 = {
314 .bus_id = 0, /* Must match with the camera ID */
315 .power = pcm037_camera_power,
316 .board_info = &pcm037_i2c_camera[0],
320 static struct i2c_board_info pcm037_i2c_devices[] = {
322 I2C_BOARD_INFO("at24", 0x52), /* E0=0, E1=1, E2=0 */
323 .platform_data = &board_eeprom,
325 I2C_BOARD_INFO("pcf8563", 0x51),
329 static struct platform_device pcm037_mt9t031 = {
330 .name = "soc-camera-pdrv",
333 .platform_data = &iclink_mt9t031,
337 static struct platform_device pcm037_mt9v022 = {
338 .name = "soc-camera-pdrv",
341 .platform_data = &iclink_mt9v022,
345 /* Not connected by default */
346 #ifdef PCM970_SDHC_RW_SWITCH
347 static int pcm970_sdhc1_get_ro(struct device *dev)
349 return gpio_get_value(IOMUX_TO_GPIO(MX31_PIN_SFS6));
353 #define SDHC1_GPIO_WP IOMUX_TO_GPIO(MX31_PIN_SFS6)
354 #define SDHC1_GPIO_DET IOMUX_TO_GPIO(MX31_PIN_SCK6)
356 static int pcm970_sdhc1_init(struct device *dev, irq_handler_t detect_irq,
361 ret = gpio_request(SDHC1_GPIO_DET, "sdhc-detect");
365 gpio_direction_input(SDHC1_GPIO_DET);
367 #ifdef PCM970_SDHC_RW_SWITCH
368 ret = gpio_request(SDHC1_GPIO_WP, "sdhc-wp");
371 gpio_direction_input(SDHC1_GPIO_WP);
374 ret = request_irq(IOMUX_TO_IRQ(MX31_PIN_SCK6), detect_irq,
375 IRQF_DISABLED | IRQF_TRIGGER_FALLING,
376 "sdhc-detect", data);
378 goto err_gpio_free_2;
383 #ifdef PCM970_SDHC_RW_SWITCH
384 gpio_free(SDHC1_GPIO_WP);
387 gpio_free(SDHC1_GPIO_DET);
392 static void pcm970_sdhc1_exit(struct device *dev, void *data)
394 free_irq(IOMUX_TO_IRQ(MX31_PIN_SCK6), data);
395 gpio_free(SDHC1_GPIO_DET);
396 gpio_free(SDHC1_GPIO_WP);
399 static const struct imxmmc_platform_data sdhc_pdata __initconst = {
400 #ifdef PCM970_SDHC_RW_SWITCH
401 .get_ro = pcm970_sdhc1_get_ro,
403 .init = pcm970_sdhc1_init,
404 .exit = pcm970_sdhc1_exit,
407 struct mx3_camera_pdata camera_pdata = {
408 .dma_dev = &mx3_ipu.dev,
409 .flags = MX3_CAMERA_DATAWIDTH_8 | MX3_CAMERA_DATAWIDTH_10,
413 static int __init pcm037_camera_alloc_dma(const size_t buf_size)
415 dma_addr_t dma_handle;
419 if (buf_size < 2 * 1024 * 1024)
422 buf = dma_alloc_coherent(NULL, buf_size, &dma_handle, GFP_KERNEL);
424 pr_err("%s: cannot allocate camera buffer-memory\n", __func__);
428 memset(buf, 0, buf_size);
430 dma = dma_declare_coherent_memory(&mx3_camera.dev,
431 dma_handle, dma_handle, buf_size,
432 DMA_MEMORY_MAP | DMA_MEMORY_EXCLUSIVE);
434 /* The way we call dma_declare_coherent_memory only a malloc can fail */
435 return dma & DMA_MEMORY_MAP ? 0 : -ENOMEM;
438 static struct platform_device *devices[] __initdata = {
445 static struct ipu_platform_data mx3_ipu_data = {
446 .irq_base = MXC_IPU_IRQ_START,
449 static const struct fb_videomode fb_modedb[] = {
451 /* 240x320 @ 60 Hz Sharp */
452 .name = "Sharp-LQ035Q7DH06-QVGA",
463 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_SHARP_MODE |
464 FB_SYNC_CLK_INVERT | FB_SYNC_CLK_IDLE_EN,
465 .vmode = FB_VMODE_NONINTERLACED,
468 /* 240x320 @ 60 Hz */
480 .sync = FB_SYNC_VERT_HIGH_ACT | FB_SYNC_OE_ACT_HIGH,
481 .vmode = FB_VMODE_NONINTERLACED,
484 /* 240x320 @ 60 Hz */
496 .sync = FB_SYNC_OE_ACT_HIGH | FB_SYNC_CLK_INVERT,
497 .vmode = FB_VMODE_NONINTERLACED,
502 static struct mx3fb_platform_data mx3fb_pdata = {
503 .dma_dev = &mx3_ipu.dev,
504 .name = "Sharp-LQ035Q7DH06-QVGA",
506 .num_modes = ARRAY_SIZE(fb_modedb),
509 static struct resource pcm970_sja1000_resources[] = {
511 .start = MX31_CS5_BASE_ADDR,
512 .end = MX31_CS5_BASE_ADDR + 0x100 - 1,
513 .flags = IORESOURCE_MEM,
515 .start = IOMUX_TO_IRQ(IOMUX_PIN(48, 105)),
516 .end = IOMUX_TO_IRQ(IOMUX_PIN(48, 105)),
517 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWEDGE,
521 struct sja1000_platform_data pcm970_sja1000_platform_data = {
522 .osc_freq = 16000000,
523 .ocr = OCR_TX1_PULLDOWN | OCR_TX0_PUSHPULL,
527 static struct platform_device pcm970_sja1000 = {
528 .name = "sja1000_platform",
530 .platform_data = &pcm970_sja1000_platform_data,
532 .resource = pcm970_sja1000_resources,
533 .num_resources = ARRAY_SIZE(pcm970_sja1000_resources),
536 static int pcm037_otg_init(struct platform_device *pdev)
538 return mx31_initialize_usb_hw(pdev->id, MXC_EHCI_INTERFACE_DIFF_UNI);
541 static struct mxc_usbh_platform_data otg_pdata __initdata = {
542 .init = pcm037_otg_init,
543 .portsc = MXC_EHCI_MODE_ULPI,
546 static int pcm037_usbh2_init(struct platform_device *pdev)
548 return mx31_initialize_usb_hw(pdev->id, MXC_EHCI_INTERFACE_DIFF_UNI);
551 static struct mxc_usbh_platform_data usbh2_pdata __initdata = {
552 .init = pcm037_usbh2_init,
553 .portsc = MXC_EHCI_MODE_ULPI,
556 static const struct fsl_usb2_platform_data otg_device_pdata __initconst = {
557 .operating_mode = FSL_USB2_DR_DEVICE,
558 .phy_mode = FSL_USB2_PHY_ULPI,
561 static int otg_mode_host;
563 static int __init pcm037_otg_mode(char *options)
565 if (!strcmp(options, "host"))
567 else if (!strcmp(options, "device"))
570 pr_info("otg_mode neither \"host\" nor \"device\". "
571 "Defaulting to device\n");
574 __setup("otg_mode=", pcm037_otg_mode);
577 * Board specific initialization.
579 static void __init pcm037_init(void)
583 mxc_iomux_set_gpr(MUX_PGP_UH2, 1);
585 mxc_iomux_setup_multiple_pins(pcm037_pins, ARRAY_SIZE(pcm037_pins),
588 #define H2_PAD_CFG (PAD_CTL_DRV_MAX | PAD_CTL_SRE_FAST | PAD_CTL_HYS_CMOS \
589 | PAD_CTL_ODE_CMOS | PAD_CTL_100K_PU)
591 mxc_iomux_set_pad(MX31_PIN_USBH2_CLK, H2_PAD_CFG);
592 mxc_iomux_set_pad(MX31_PIN_USBH2_DIR, H2_PAD_CFG);
593 mxc_iomux_set_pad(MX31_PIN_USBH2_NXT, H2_PAD_CFG);
594 mxc_iomux_set_pad(MX31_PIN_USBH2_STP, H2_PAD_CFG);
595 mxc_iomux_set_pad(MX31_PIN_USBH2_DATA0, H2_PAD_CFG); /* USBH2_DATA0 */
596 mxc_iomux_set_pad(MX31_PIN_USBH2_DATA1, H2_PAD_CFG); /* USBH2_DATA1 */
597 mxc_iomux_set_pad(MX31_PIN_SRXD6, H2_PAD_CFG); /* USBH2_DATA2 */
598 mxc_iomux_set_pad(MX31_PIN_STXD6, H2_PAD_CFG); /* USBH2_DATA3 */
599 mxc_iomux_set_pad(MX31_PIN_SFS3, H2_PAD_CFG); /* USBH2_DATA4 */
600 mxc_iomux_set_pad(MX31_PIN_SCK3, H2_PAD_CFG); /* USBH2_DATA5 */
601 mxc_iomux_set_pad(MX31_PIN_SRXD3, H2_PAD_CFG); /* USBH2_DATA6 */
602 mxc_iomux_set_pad(MX31_PIN_STXD3, H2_PAD_CFG); /* USBH2_DATA7 */
604 if (pcm037_variant() == PCM037_EET)
605 mxc_iomux_setup_multiple_pins(pcm037_uart1_pins,
606 ARRAY_SIZE(pcm037_uart1_pins), "pcm037_uart1");
608 mxc_iomux_setup_multiple_pins(pcm037_uart1_handshake_pins,
609 ARRAY_SIZE(pcm037_uart1_handshake_pins),
612 platform_add_devices(devices, ARRAY_SIZE(devices));
614 imx31_add_imx2_wdt(NULL);
615 imx31_add_imx_uart0(&uart_pdata);
616 /* XXX: should't this have .flags = 0 (i.e. no RTSCTS) on PCM037_EET? */
617 imx31_add_imx_uart1(&uart_pdata);
618 imx31_add_imx_uart2(&uart_pdata);
620 imx31_add_mxc_w1(NULL);
622 /* LAN9217 IRQ pin */
623 ret = gpio_request(IOMUX_TO_GPIO(MX31_PIN_GPIO3_1), "lan9217-irq");
625 pr_warning("could not get LAN irq gpio\n");
627 gpio_direction_input(IOMUX_TO_GPIO(MX31_PIN_GPIO3_1));
628 platform_device_register(&pcm037_eth);
632 /* I2C adapters and devices */
633 i2c_register_board_info(1, pcm037_i2c_devices,
634 ARRAY_SIZE(pcm037_i2c_devices));
636 imx31_add_imx_i2c1(&pcm037_i2c1_data);
637 imx31_add_imx_i2c2(&pcm037_i2c2_data);
639 imx31_add_mxc_nand(&pcm037_nand_board_info);
640 imx31_add_mxc_mmc(0, &sdhc_pdata);
641 mxc_register_device(&mx3_ipu, &mx3_ipu_data);
642 mxc_register_device(&mx3_fb, &mx3fb_pdata);
645 /* Camera power: default - off */
646 ret = gpio_request(IOMUX_TO_GPIO(MX31_PIN_CSI_D5), "mt9t031-power");
648 gpio_direction_output(IOMUX_TO_GPIO(MX31_PIN_CSI_D5), 1);
650 iclink_mt9t031.power = NULL;
652 if (!pcm037_camera_alloc_dma(4 * 1024 * 1024))
653 mxc_register_device(&mx3_camera, &camera_pdata);
655 platform_device_register(&pcm970_sja1000);
658 otg_pdata.otg = imx_otg_ulpi_create(ULPI_OTG_DRVVBUS |
659 ULPI_OTG_DRVVBUS_EXT);
661 imx31_add_mxc_ehci_otg(&otg_pdata);
664 usbh2_pdata.otg = imx_otg_ulpi_create(ULPI_OTG_DRVVBUS |
665 ULPI_OTG_DRVVBUS_EXT);
667 imx31_add_mxc_ehci_hs(2, &usbh2_pdata);
670 imx31_add_fsl_usb2_udc(&otg_device_pdata);
674 static void __init pcm037_timer_init(void)
676 mx31_clocks_init(26000000);
679 struct sys_timer pcm037_timer = {
680 .init = pcm037_timer_init,
683 MACHINE_START(PCM037, "Phytec Phycore pcm037")
684 /* Maintainer: Pengutronix */
685 .boot_params = MX3x_PHYS_OFFSET + 0x100,
686 .map_io = mx31_map_io,
687 .init_early = imx31_init_early,
688 .init_irq = mx31_init_irq,
689 .timer = &pcm037_timer,
690 .init_machine = pcm037_init,