2 * Copyright 2009 Freescale Semiconductor, Inc. All Rights Reserved.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
18 * This machine is known as:
19 * - i.MX27 3-Stack Development System
20 * - i.MX27 Platform Development Kit (i.MX27 PDK)
23 #include <linux/platform_device.h>
24 #include <linux/gpio.h>
25 #include <linux/irq.h>
26 #include <linux/usb/otg.h>
27 #include <linux/usb/ulpi.h>
28 #include <linux/delay.h>
29 #include <linux/mfd/mc13783.h>
30 #include <linux/spi/spi.h>
31 #include <linux/regulator/machine.h>
32 #include <linux/spi/l4f00242t03.h>
34 #include <media/soc_camera.h>
36 #include <asm/mach-types.h>
37 #include <asm/mach/arch.h>
38 #include <asm/mach/time.h>
40 #include "3ds_debugboard.h"
42 #include "devices-imx27.h"
45 #include "iomux-mx27.h"
48 #define SD1_EN_GPIO IMX_GPIO_NR(2, 25)
49 #define OTG_PHY_RESET_GPIO IMX_GPIO_NR(2, 23)
50 #define SPI2_SS0 IMX_GPIO_NR(4, 21)
51 #define PMIC_INT IMX_GPIO_NR(3, 14)
52 #define SPI1_SS0 IMX_GPIO_NR(4, 28)
53 #define SD1_CD IMX_GPIO_NR(2, 26)
54 #define LCD_RESET IMX_GPIO_NR(1, 3)
55 #define LCD_ENABLE IMX_GPIO_NR(1, 31)
56 #define CSI_PWRDWN IMX_GPIO_NR(4, 19)
57 #define CSI_RESET IMX_GPIO_NR(3, 6)
59 static const int mx27pdk_pins[] __initconst = {
91 SD1_EN_GPIO | GPIO_GPIO | GPIO_OUT,
93 OTG_PHY_RESET_GPIO | GPIO_GPIO | GPIO_OUT,
100 PC13_PF_USBOTG_DATA3,
105 PE25_PF_USBOTG_DATA7,
111 SPI1_SS0 | GPIO_GPIO | GPIO_OUT,
116 SPI2_SS0 | GPIO_GPIO | GPIO_OUT,
121 PMIC_INT | GPIO_GPIO | GPIO_IN,
145 LCD_ENABLE | GPIO_GPIO | GPIO_OUT,
146 LCD_RESET | GPIO_GPIO | GPIO_OUT,
160 CSI_PWRDWN | GPIO_GPIO | GPIO_OUT,
161 CSI_RESET | GPIO_GPIO | GPIO_OUT,
169 static struct gpio mx27_3ds_camera_gpios[] = {
170 { CSI_PWRDWN, GPIOF_OUT_INIT_HIGH, "camera-power" },
171 { CSI_RESET, GPIOF_OUT_INIT_HIGH, "camera-reset" },
174 static const struct imxuart_platform_data uart_pdata __initconst = {
175 .flags = IMXUART_HAVE_RTSCTS,
182 static const uint32_t mx27_3ds_keymap[] = {
185 KEY(1, 0, KEY_RIGHT),
187 KEY(1, 2, KEY_ENTER),
194 static const struct matrix_keymap_data mx27_3ds_keymap_data __initconst = {
195 .keymap = mx27_3ds_keymap,
196 .keymap_size = ARRAY_SIZE(mx27_3ds_keymap),
199 static int mx27_3ds_sdhc1_init(struct device *dev, irq_handler_t detect_irq,
202 return request_irq(gpio_to_irq(SD1_CD), detect_irq,
203 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING, "sdhc1-card-detect", data);
206 static void mx27_3ds_sdhc1_exit(struct device *dev, void *data)
208 free_irq(gpio_to_irq(SD1_CD), data);
211 static const struct imxmmc_platform_data sdhc1_pdata __initconst = {
212 .init = mx27_3ds_sdhc1_init,
213 .exit = mx27_3ds_sdhc1_exit,
216 static void mx27_3ds_sdhc1_enable_level_translator(void)
218 /* Turn on TXB0108 OE pin */
219 gpio_request(SD1_EN_GPIO, "sd1_enable");
220 gpio_direction_output(SD1_EN_GPIO, 1);
224 static int otg_phy_init(void)
226 gpio_request(OTG_PHY_RESET_GPIO, "usb-otg-reset");
227 gpio_direction_output(OTG_PHY_RESET_GPIO, 0);
229 gpio_set_value(OTG_PHY_RESET_GPIO, 1);
233 static int mx27_3ds_otg_init(struct platform_device *pdev)
235 return mx27_initialize_usb_hw(pdev->id, MXC_EHCI_INTERFACE_DIFF_UNI);
238 static struct mxc_usbh_platform_data otg_pdata __initdata = {
239 .init = mx27_3ds_otg_init,
240 .portsc = MXC_EHCI_MODE_ULPI,
243 static const struct fsl_usb2_platform_data otg_device_pdata __initconst = {
244 .operating_mode = FSL_USB2_DR_DEVICE,
245 .phy_mode = FSL_USB2_PHY_ULPI,
248 static bool otg_mode_host __initdata;
250 static int __init mx27_3ds_otg_mode(char *options)
252 if (!strcmp(options, "host"))
253 otg_mode_host = true;
254 else if (!strcmp(options, "device"))
255 otg_mode_host = false;
257 pr_info("otg_mode neither \"host\" nor \"device\". "
258 "Defaulting to device\n");
261 __setup("otg_mode=", mx27_3ds_otg_mode);
264 static struct regulator_init_data gpo_init = {
271 static struct regulator_consumer_supply vmmc1_consumers[] = {
272 REGULATOR_SUPPLY("vcore", "spi0.0"),
273 REGULATOR_SUPPLY("cmos_2v8", "soc-camera-pdrv.0"),
276 static struct regulator_init_data vmmc1_init = {
281 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE |
282 REGULATOR_CHANGE_STATUS,
284 .num_consumer_supplies = ARRAY_SIZE(vmmc1_consumers),
285 .consumer_supplies = vmmc1_consumers,
288 static struct regulator_consumer_supply vgen_consumers[] = {
289 REGULATOR_SUPPLY("vdd", "spi0.0"),
292 static struct regulator_init_data vgen_init = {
296 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
298 .num_consumer_supplies = ARRAY_SIZE(vgen_consumers),
299 .consumer_supplies = vgen_consumers,
302 static struct regulator_consumer_supply vvib_consumers[] = {
303 REGULATOR_SUPPLY("cmos_vcore", "soc-camera-pdrv.0"),
306 static struct regulator_init_data vvib_init = {
311 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE |
312 REGULATOR_CHANGE_STATUS,
314 .num_consumer_supplies = ARRAY_SIZE(vvib_consumers),
315 .consumer_supplies = vvib_consumers,
318 static struct mc13xxx_regulator_init_data mx27_3ds_regulators[] = {
320 .id = MC13783_REG_VMMC1,
321 .init_data = &vmmc1_init,
323 .id = MC13783_REG_VGEN,
324 .init_data = &vgen_init,
326 .id = MC13783_REG_GPO1, /* Turn on 1.8V */
327 .init_data = &gpo_init,
329 .id = MC13783_REG_GPO3, /* Turn on 3.3V */
330 .init_data = &gpo_init,
332 .id = MC13783_REG_VVIB, /* Power OV2640 */
333 .init_data = &vvib_init,
338 static struct mc13xxx_codec_platform_data mx27_3ds_codec = {
339 .dac_ssi_port = MC13783_SSI1_PORT,
340 .adc_ssi_port = MC13783_SSI1_PORT,
343 static struct mc13xxx_platform_data mc13783_pdata = {
345 .regulators = mx27_3ds_regulators,
346 .num_regulators = ARRAY_SIZE(mx27_3ds_regulators),
349 .flags = MC13XXX_USE_TOUCHSCREEN | MC13XXX_USE_RTC |
351 .codec = &mx27_3ds_codec,
354 static struct imx_ssi_platform_data mx27_3ds_ssi_pdata = {
355 .flags = IMX_SSI_DMA | IMX_SSI_NET,
359 static int spi1_chipselect[] = {SPI1_SS0};
361 static const struct spi_imx_master spi1_pdata __initconst = {
362 .chipselect = spi1_chipselect,
363 .num_chipselect = ARRAY_SIZE(spi1_chipselect),
366 static int spi2_chipselect[] = {SPI2_SS0};
368 static const struct spi_imx_master spi2_pdata __initconst = {
369 .chipselect = spi2_chipselect,
370 .num_chipselect = ARRAY_SIZE(spi2_chipselect),
373 static int mx27_3ds_camera_power(struct device *dev, int on)
375 /* enable or disable the camera */
376 pr_debug("%s: %s the camera\n", __func__, on ? "ENABLE" : "DISABLE");
377 gpio_set_value(CSI_PWRDWN, on ? 0 : 1);
382 /* If enabled, give a reset impulse */
383 gpio_set_value(CSI_RESET, 0);
385 gpio_set_value(CSI_RESET, 1);
392 static struct i2c_board_info mx27_3ds_i2c_camera = {
393 I2C_BOARD_INFO("ov2640", 0x30),
396 static struct regulator_bulk_data mx27_3ds_camera_regs[] = {
397 { .supply = "cmos_vcore" },
398 { .supply = "cmos_2v8" },
401 static struct soc_camera_link iclink_ov2640 = {
403 .board_info = &mx27_3ds_i2c_camera,
405 .power = mx27_3ds_camera_power,
406 .regulators = mx27_3ds_camera_regs,
407 .num_regulators = ARRAY_SIZE(mx27_3ds_camera_regs),
410 static struct platform_device mx27_3ds_ov2640 = {
411 .name = "soc-camera-pdrv",
414 .platform_data = &iclink_ov2640,
418 static struct imx_fb_videomode mx27_3ds_modes[] = {
419 { /* 480x640 @ 60 Hz */
432 .sync = FB_SYNC_OE_ACT_HIGH |
434 .vmode = FB_VMODE_NONINTERLACED,
442 static const struct imx_fb_platform_data mx27_3ds_fb_data __initconst = {
443 .mode = mx27_3ds_modes,
444 .num_modes = ARRAY_SIZE(mx27_3ds_modes),
451 static struct l4f00242t03_pdata mx27_3ds_lcd_pdata = {
452 .reset_gpio = LCD_RESET,
453 .data_enable_gpio = LCD_ENABLE,
456 static struct spi_board_info mx27_3ds_spi_devs[] __initdata = {
458 .modalias = "mc13783",
459 .max_speed_hz = 1000000,
461 .chip_select = 0, /* SS0 */
462 .platform_data = &mc13783_pdata,
463 /* irq number is run-time assigned */
466 .modalias = "l4f00242t03",
467 .max_speed_hz = 5000000,
469 .chip_select = 0, /* SS0 */
470 .platform_data = &mx27_3ds_lcd_pdata,
474 static struct platform_device *devices[] __initdata = {
478 static const struct mx2_camera_platform_data mx27_3ds_cam_pdata __initconst = {
482 static const struct imxi2c_platform_data mx27_3ds_i2c0_data __initconst = {
486 static void __init mx27pdk_init(void)
491 mxc_gpio_setup_multiple_pins(mx27pdk_pins, ARRAY_SIZE(mx27pdk_pins),
493 mx27_3ds_sdhc1_enable_level_translator();
494 imx27_add_imx_uart0(&uart_pdata);
496 imx27_add_imx_keypad(&mx27_3ds_keymap_data);
497 imx27_add_mxc_mmc(0, &sdhc1_pdata);
498 imx27_add_imx2_wdt();
502 otg_pdata.otg = imx_otg_ulpi_create(ULPI_OTG_DRVVBUS |
503 ULPI_OTG_DRVVBUS_EXT);
506 imx27_add_mxc_ehci_otg(&otg_pdata);
510 imx27_add_fsl_usb2_udc(&otg_device_pdata);
512 imx27_add_spi_imx1(&spi2_pdata);
513 imx27_add_spi_imx0(&spi1_pdata);
514 mx27_3ds_spi_devs[0].irq = gpio_to_irq(PMIC_INT);
515 spi_register_board_info(mx27_3ds_spi_devs,
516 ARRAY_SIZE(mx27_3ds_spi_devs));
518 if (mxc_expio_init(MX27_CS5_BASE_ADDR, IMX_GPIO_NR(3, 28)))
519 pr_warn("Init of the debugboard failed, all devices on the debugboard are unusable.\n");
520 imx27_add_imx_i2c(0, &mx27_3ds_i2c0_data);
521 platform_add_devices(devices, ARRAY_SIZE(devices));
522 imx27_add_imx_fb(&mx27_3ds_fb_data);
524 ret = gpio_request_array(mx27_3ds_camera_gpios,
525 ARRAY_SIZE(mx27_3ds_camera_gpios));
527 pr_err("Failed to request camera gpios");
528 iclink_ov2640.power = NULL;
531 imx27_add_mx2_camera(&mx27_3ds_cam_pdata);
532 imx27_add_imx_ssi(0, &mx27_3ds_ssi_pdata);
534 imx_add_platform_device("imx_mc13783", 0, NULL, 0, NULL, 0);
537 static void __init mx27pdk_timer_init(void)
539 mx27_clocks_init(26000000);
542 MACHINE_START(MX27_3DS, "Freescale MX27PDK")
543 /* maintainer: Freescale Semiconductor, Inc. */
544 .atag_offset = 0x100,
545 .map_io = mx27_map_io,
546 .init_early = imx27_init_early,
547 .init_irq = mx27_init_irq,
548 .init_time = mx27pdk_timer_init,
549 .init_machine = mx27pdk_init,
550 .restart = mxc_restart,