2 * Copyright 2009 Freescale Semiconductor, Inc. All Rights Reserved.
4 * Author: Fabio Estevam <fabio.estevam@freescale.com>
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>
39 #include <mach/hardware.h>
40 #include <mach/common.h>
41 #include <mach/iomux-mx27.h>
42 #include <mach/ulpi.h>
43 #include <mach/irqs.h>
44 #include <mach/3ds_debugboard.h>
46 #include "devices-imx27.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 EXPIO_PARENT_INT gpio_to_irq(IMX_GPIO_NR(3, 28))
52 #define PMIC_INT IMX_GPIO_NR(3, 14)
53 #define SPI1_SS0 IMX_GPIO_NR(4, 28)
54 #define SD1_CD IMX_GPIO_NR(2, 26)
55 #define LCD_RESET IMX_GPIO_NR(1, 3)
56 #define LCD_ENABLE IMX_GPIO_NR(1, 31)
57 #define CSI_PWRDWN IMX_GPIO_NR(4, 19)
58 #define CSI_RESET IMX_GPIO_NR(3, 6)
60 static const int mx27pdk_pins
[] __initconst
= {
92 SD1_EN_GPIO
| GPIO_GPIO
| GPIO_OUT
,
94 OTG_PHY_RESET_GPIO
| GPIO_GPIO
| GPIO_OUT
,
100 PC12_PF_USBOTG_DATA4
,
101 PC13_PF_USBOTG_DATA3
,
106 PE25_PF_USBOTG_DATA7
,
112 SPI1_SS0
| GPIO_GPIO
| GPIO_OUT
,
117 SPI2_SS0
| GPIO_GPIO
| GPIO_OUT
,
122 PMIC_INT
| GPIO_GPIO
| GPIO_IN
,
146 LCD_ENABLE
| GPIO_GPIO
| GPIO_OUT
,
147 LCD_RESET
| GPIO_GPIO
| GPIO_OUT
,
161 CSI_PWRDWN
| GPIO_GPIO
| GPIO_OUT
,
162 CSI_RESET
| GPIO_GPIO
| GPIO_OUT
,
165 static struct gpio mx27_3ds_camera_gpios
[] = {
166 { CSI_PWRDWN
, GPIOF_OUT_INIT_HIGH
, "camera-power" },
167 { CSI_RESET
, GPIOF_OUT_INIT_HIGH
, "camera-reset" },
170 static const struct imxuart_platform_data uart_pdata __initconst
= {
171 .flags
= IMXUART_HAVE_RTSCTS
,
178 static const uint32_t mx27_3ds_keymap
[] = {
181 KEY(1, 0, KEY_RIGHT
),
183 KEY(1, 2, KEY_ENTER
),
190 static const struct matrix_keymap_data mx27_3ds_keymap_data __initconst
= {
191 .keymap
= mx27_3ds_keymap
,
192 .keymap_size
= ARRAY_SIZE(mx27_3ds_keymap
),
195 static int mx27_3ds_sdhc1_init(struct device
*dev
, irq_handler_t detect_irq
,
198 return request_irq(gpio_to_irq(SD1_CD
), detect_irq
,
199 IRQF_TRIGGER_FALLING
| IRQF_TRIGGER_RISING
, "sdhc1-card-detect", data
);
202 static void mx27_3ds_sdhc1_exit(struct device
*dev
, void *data
)
204 free_irq(gpio_to_irq(SD1_CD
), data
);
207 static const struct imxmmc_platform_data sdhc1_pdata __initconst
= {
208 .init
= mx27_3ds_sdhc1_init
,
209 .exit
= mx27_3ds_sdhc1_exit
,
212 static void mx27_3ds_sdhc1_enable_level_translator(void)
214 /* Turn on TXB0108 OE pin */
215 gpio_request(SD1_EN_GPIO
, "sd1_enable");
216 gpio_direction_output(SD1_EN_GPIO
, 1);
220 static int otg_phy_init(void)
222 gpio_request(OTG_PHY_RESET_GPIO
, "usb-otg-reset");
223 gpio_direction_output(OTG_PHY_RESET_GPIO
, 0);
225 gpio_set_value(OTG_PHY_RESET_GPIO
, 1);
229 static int mx27_3ds_otg_init(struct platform_device
*pdev
)
231 return mx27_initialize_usb_hw(pdev
->id
, MXC_EHCI_INTERFACE_DIFF_UNI
);
234 static struct mxc_usbh_platform_data otg_pdata __initdata
= {
235 .init
= mx27_3ds_otg_init
,
236 .portsc
= MXC_EHCI_MODE_ULPI
,
239 static const struct fsl_usb2_platform_data otg_device_pdata __initconst
= {
240 .operating_mode
= FSL_USB2_DR_DEVICE
,
241 .phy_mode
= FSL_USB2_PHY_ULPI
,
244 static int otg_mode_host
;
246 static int __init
mx27_3ds_otg_mode(char *options
)
248 if (!strcmp(options
, "host"))
250 else if (!strcmp(options
, "device"))
253 pr_info("otg_mode neither \"host\" nor \"device\". "
254 "Defaulting to device\n");
257 __setup("otg_mode=", mx27_3ds_otg_mode
);
260 static struct regulator_init_data gpo_init
= {
267 static struct regulator_consumer_supply vmmc1_consumers
[] = {
268 REGULATOR_SUPPLY("vcore", "spi0.0"),
269 REGULATOR_SUPPLY("cmos_2v8", "soc-camera-pdrv.0"),
272 static struct regulator_init_data vmmc1_init
= {
277 .valid_ops_mask
= REGULATOR_CHANGE_VOLTAGE
|
278 REGULATOR_CHANGE_STATUS
,
280 .num_consumer_supplies
= ARRAY_SIZE(vmmc1_consumers
),
281 .consumer_supplies
= vmmc1_consumers
,
284 static struct regulator_consumer_supply vgen_consumers
[] = {
285 REGULATOR_SUPPLY("vdd", "spi0.0"),
288 static struct regulator_init_data vgen_init
= {
292 .valid_ops_mask
= REGULATOR_CHANGE_VOLTAGE
,
294 .num_consumer_supplies
= ARRAY_SIZE(vgen_consumers
),
295 .consumer_supplies
= vgen_consumers
,
298 static struct regulator_consumer_supply vvib_consumers
[] = {
299 REGULATOR_SUPPLY("cmos_vcore", "soc-camera-pdrv.0"),
302 static struct regulator_init_data vvib_init
= {
307 .valid_ops_mask
= REGULATOR_CHANGE_VOLTAGE
|
308 REGULATOR_CHANGE_STATUS
,
310 .num_consumer_supplies
= ARRAY_SIZE(vvib_consumers
),
311 .consumer_supplies
= vvib_consumers
,
314 static struct mc13xxx_regulator_init_data mx27_3ds_regulators
[] = {
316 .id
= MC13783_REG_VMMC1
,
317 .init_data
= &vmmc1_init
,
319 .id
= MC13783_REG_VGEN
,
320 .init_data
= &vgen_init
,
322 .id
= MC13783_REG_GPO1
, /* Turn on 1.8V */
323 .init_data
= &gpo_init
,
325 .id
= MC13783_REG_GPO3
, /* Turn on 3.3V */
326 .init_data
= &gpo_init
,
328 .id
= MC13783_REG_VVIB
, /* Power OV2640 */
329 .init_data
= &vvib_init
,
334 static struct mc13xxx_platform_data mc13783_pdata
= {
336 .regulators
= mx27_3ds_regulators
,
337 .num_regulators
= ARRAY_SIZE(mx27_3ds_regulators
),
340 .flags
= MC13XXX_USE_TOUCHSCREEN
| MC13XXX_USE_RTC
,
344 static int spi1_chipselect
[] = {SPI1_SS0
};
346 static const struct spi_imx_master spi1_pdata __initconst
= {
347 .chipselect
= spi1_chipselect
,
348 .num_chipselect
= ARRAY_SIZE(spi1_chipselect
),
351 static int spi2_chipselect
[] = {SPI2_SS0
};
353 static const struct spi_imx_master spi2_pdata __initconst
= {
354 .chipselect
= spi2_chipselect
,
355 .num_chipselect
= ARRAY_SIZE(spi2_chipselect
),
358 static int mx27_3ds_camera_power(struct device
*dev
, int on
)
360 /* enable or disable the camera */
361 pr_debug("%s: %s the camera\n", __func__
, on
? "ENABLE" : "DISABLE");
362 gpio_set_value(CSI_PWRDWN
, on
? 0 : 1);
367 /* If enabled, give a reset impulse */
368 gpio_set_value(CSI_RESET
, 0);
370 gpio_set_value(CSI_RESET
, 1);
377 static struct i2c_board_info mx27_3ds_i2c_camera
= {
378 I2C_BOARD_INFO("ov2640", 0x30),
381 static struct regulator_bulk_data mx27_3ds_camera_regs
[] = {
382 { .supply
= "cmos_vcore" },
383 { .supply
= "cmos_2v8" },
386 static struct soc_camera_link iclink_ov2640
= {
388 .board_info
= &mx27_3ds_i2c_camera
,
390 .power
= mx27_3ds_camera_power
,
391 .regulators
= mx27_3ds_camera_regs
,
392 .num_regulators
= ARRAY_SIZE(mx27_3ds_camera_regs
),
395 static struct platform_device mx27_3ds_ov2640
= {
396 .name
= "soc-camera-pdrv",
399 .platform_data
= &iclink_ov2640
,
403 static struct imx_fb_videomode mx27_3ds_modes
[] = {
404 { /* 480x640 @ 60 Hz */
417 .sync
= FB_SYNC_OE_ACT_HIGH
|
419 .vmode
= FB_VMODE_NONINTERLACED
,
427 static const struct imx_fb_platform_data mx27_3ds_fb_data __initconst
= {
428 .mode
= mx27_3ds_modes
,
429 .num_modes
= ARRAY_SIZE(mx27_3ds_modes
),
436 static struct l4f00242t03_pdata mx27_3ds_lcd_pdata
= {
437 .reset_gpio
= LCD_RESET
,
438 .data_enable_gpio
= LCD_ENABLE
,
441 static struct spi_board_info mx27_3ds_spi_devs
[] __initdata
= {
443 .modalias
= "mc13783",
444 .max_speed_hz
= 1000000,
446 .chip_select
= 0, /* SS0 */
447 .platform_data
= &mc13783_pdata
,
448 .irq
= IMX_GPIO_TO_IRQ(PMIC_INT
),
451 .modalias
= "l4f00242t03",
452 .max_speed_hz
= 5000000,
454 .chip_select
= 0, /* SS0 */
455 .platform_data
= &mx27_3ds_lcd_pdata
,
459 static struct platform_device
*devices
[] __initdata
= {
463 static const struct mx2_camera_platform_data mx27_3ds_cam_pdata __initconst
= {
467 static const struct imxi2c_platform_data mx27_3ds_i2c0_data __initconst
= {
471 static void __init
mx27pdk_init(void)
476 mxc_gpio_setup_multiple_pins(mx27pdk_pins
, ARRAY_SIZE(mx27pdk_pins
),
478 mx27_3ds_sdhc1_enable_level_translator();
479 imx27_add_imx_uart0(&uart_pdata
);
481 imx27_add_imx_keypad(&mx27_3ds_keymap_data
);
482 imx27_add_mxc_mmc(0, &sdhc1_pdata
);
483 imx27_add_imx2_wdt(NULL
);
487 otg_pdata
.otg
= imx_otg_ulpi_create(ULPI_OTG_DRVVBUS
|
488 ULPI_OTG_DRVVBUS_EXT
);
491 imx27_add_mxc_ehci_otg(&otg_pdata
);
495 imx27_add_fsl_usb2_udc(&otg_device_pdata
);
497 imx27_add_spi_imx1(&spi2_pdata
);
498 imx27_add_spi_imx0(&spi1_pdata
);
499 spi_register_board_info(mx27_3ds_spi_devs
,
500 ARRAY_SIZE(mx27_3ds_spi_devs
));
502 if (mxc_expio_init(MX27_CS5_BASE_ADDR
, EXPIO_PARENT_INT
))
503 pr_warn("Init of the debugboard failed, all devices on the debugboard are unusable.\n");
504 imx27_add_imx_i2c(0, &mx27_3ds_i2c0_data
);
505 platform_add_devices(devices
, ARRAY_SIZE(devices
));
506 imx27_add_imx_fb(&mx27_3ds_fb_data
);
508 ret
= gpio_request_array(mx27_3ds_camera_gpios
,
509 ARRAY_SIZE(mx27_3ds_camera_gpios
));
511 pr_err("Failed to request camera gpios");
512 iclink_ov2640
.power
= NULL
;
515 imx27_add_mx2_camera(&mx27_3ds_cam_pdata
);
518 static void __init
mx27pdk_timer_init(void)
520 mx27_clocks_init(26000000);
523 static struct sys_timer mx27pdk_timer
= {
524 .init
= mx27pdk_timer_init
,
527 MACHINE_START(MX27_3DS
, "Freescale MX27PDK")
528 /* maintainer: Freescale Semiconductor, Inc. */
529 .atag_offset
= 0x100,
530 .map_io
= mx27_map_io
,
531 .init_early
= imx27_init_early
,
532 .init_irq
= mx27_init_irq
,
533 .handle_irq
= imx27_handle_irq
,
534 .timer
= &mx27pdk_timer
,
535 .init_machine
= mx27pdk_init
,
536 .restart
= mxc_restart
,