2 * Copyright (C) 2008 Valentin Longchamp, EPFL Mobots group
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.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include <linux/delay.h>
20 #include <linux/dma-mapping.h>
21 #include <linux/fsl_devices.h>
22 #include <linux/gpio.h>
23 #include <linux/init.h>
24 #include <linux/interrupt.h>
25 #include <linux/leds.h>
26 #include <linux/memory.h>
27 #include <linux/mtd/physmap.h>
28 #include <linux/mtd/partitions.h>
29 #include <linux/platform_device.h>
30 #include <linux/regulator/machine.h>
31 #include <linux/mfd/mc13783.h>
32 #include <linux/spi/spi.h>
33 #include <linux/types.h>
35 #include <asm/mach-types.h>
36 #include <asm/mach/arch.h>
37 #include <asm/mach/time.h>
38 #include <asm/mach/map.h>
39 #include <mach/board-mx31moboard.h>
40 #include <mach/common.h>
41 #include <mach/hardware.h>
42 #include <mach/imx-uart.h>
43 #include <mach/iomux-mx3.h>
47 #include <mach/mx3_camera.h>
52 static unsigned int moboard_pins[] = {
54 MX31_PIN_TXD1__TXD1, MX31_PIN_RXD1__RXD1,
55 MX31_PIN_CTS1__GPIO2_7,
57 MX31_PIN_PC_RST__CTS5, MX31_PIN_PC_VS2__RTS5,
58 MX31_PIN_PC_BVD2__TXD5, MX31_PIN_PC_BVD1__RXD5,
60 MX31_PIN_I2C_DAT__I2C1_SDA, MX31_PIN_I2C_CLK__I2C1_SCL,
62 MX31_PIN_DCD_DTE1__I2C2_SDA, MX31_PIN_RI_DTE1__I2C2_SCL,
64 MX31_PIN_SD1_DATA3__SD1_DATA3, MX31_PIN_SD1_DATA2__SD1_DATA2,
65 MX31_PIN_SD1_DATA1__SD1_DATA1, MX31_PIN_SD1_DATA0__SD1_DATA0,
66 MX31_PIN_SD1_CLK__SD1_CLK, MX31_PIN_SD1_CMD__SD1_CMD,
67 MX31_PIN_ATA_CS0__GPIO3_26, MX31_PIN_ATA_CS1__GPIO3_27,
69 MX31_PIN_GPIO1_0__GPIO1_0,
71 MX31_PIN_USBOTG_DATA0__USBOTG_DATA0,
72 MX31_PIN_USBOTG_DATA1__USBOTG_DATA1,
73 MX31_PIN_USBOTG_DATA2__USBOTG_DATA2,
74 MX31_PIN_USBOTG_DATA3__USBOTG_DATA3,
75 MX31_PIN_USBOTG_DATA4__USBOTG_DATA4,
76 MX31_PIN_USBOTG_DATA5__USBOTG_DATA5,
77 MX31_PIN_USBOTG_DATA6__USBOTG_DATA6,
78 MX31_PIN_USBOTG_DATA7__USBOTG_DATA7,
79 MX31_PIN_USBOTG_CLK__USBOTG_CLK, MX31_PIN_USBOTG_DIR__USBOTG_DIR,
80 MX31_PIN_USBOTG_NXT__USBOTG_NXT, MX31_PIN_USBOTG_STP__USBOTG_STP,
81 MX31_PIN_USB_OC__GPIO1_30,
83 MX31_PIN_SVEN0__GPIO2_0, MX31_PIN_STX0__GPIO2_1,
84 MX31_PIN_SRX0__GPIO2_2, MX31_PIN_SIMPD0__GPIO2_3,
86 MX31_PIN_DTR_DCE1__GPIO2_8, MX31_PIN_DSR_DCE1__GPIO2_9,
87 MX31_PIN_RI_DCE1__GPIO2_10, MX31_PIN_DCD_DCE1__GPIO2_11,
89 MX31_PIN_CSPI2_MOSI__MOSI, MX31_PIN_CSPI2_MISO__MISO,
90 MX31_PIN_CSPI2_SCLK__SCLK, MX31_PIN_CSPI2_SPI_RDY__SPI_RDY,
91 MX31_PIN_CSPI2_SS0__SS0, MX31_PIN_CSPI2_SS2__SS2,
93 MX31_PIN_GPIO1_3__GPIO1_3,
95 MX31_PIN_CSPI3_MOSI__MOSI, MX31_PIN_CSPI3_MISO__MISO,
96 MX31_PIN_CSPI3_SCLK__SCLK, MX31_PIN_CSPI3_SPI_RDY__SPI_RDY,
97 MX31_PIN_CSPI2_SS1__CSPI3_SS1,
100 static struct physmap_flash_data mx31moboard_flash_data = {
104 static struct resource mx31moboard_flash_resource = {
107 .flags = IORESOURCE_MEM,
110 static struct platform_device mx31moboard_flash = {
111 .name = "physmap-flash",
114 .platform_data = &mx31moboard_flash_data,
116 .resource = &mx31moboard_flash_resource,
120 static int moboard_uart0_init(struct platform_device *pdev)
122 gpio_request(IOMUX_TO_GPIO(MX31_PIN_CTS1), "uart0-cts-hack");
123 gpio_direction_output(IOMUX_TO_GPIO(MX31_PIN_CTS1), 0);
127 static struct imxuart_platform_data uart0_pdata = {
128 .init = moboard_uart0_init,
131 static struct imxuart_platform_data uart4_pdata = {
132 .flags = IMXUART_HAVE_RTSCTS,
135 static struct imxi2c_platform_data moboard_i2c0_pdata = {
139 static struct imxi2c_platform_data moboard_i2c1_pdata = {
143 static int moboard_spi1_cs[] = {
148 static struct spi_imx_master moboard_spi1_master = {
149 .chipselect = moboard_spi1_cs,
150 .num_chipselect = ARRAY_SIZE(moboard_spi1_cs),
153 static struct regulator_consumer_supply sdhc_consumers[] = {
155 .dev = &mxcsdhc_device0.dev,
156 .supply = "sdhc0_vcc",
159 .dev = &mxcsdhc_device1.dev,
160 .supply = "sdhc1_vcc",
164 static struct regulator_init_data sdhc_vreg_data = {
168 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE |
169 REGULATOR_CHANGE_MODE | REGULATOR_CHANGE_STATUS,
170 .valid_modes_mask = REGULATOR_MODE_NORMAL |
175 .num_consumer_supplies = ARRAY_SIZE(sdhc_consumers),
176 .consumer_supplies = sdhc_consumers,
179 static struct regulator_consumer_supply cam_consumers[] = {
181 .dev = &mx3_camera.dev,
186 static struct regulator_init_data cam_vreg_data = {
190 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE |
191 REGULATOR_CHANGE_MODE | REGULATOR_CHANGE_STATUS,
192 .valid_modes_mask = REGULATOR_MODE_NORMAL |
197 .num_consumer_supplies = ARRAY_SIZE(cam_consumers),
198 .consumer_supplies = cam_consumers,
201 static struct mc13783_regulator_init_data moboard_regulators[] = {
203 .id = MC13783_REGU_VMMC1,
204 .init_data = &sdhc_vreg_data,
207 .id = MC13783_REGU_VCAM,
208 .init_data = &cam_vreg_data,
212 static struct mc13783_platform_data moboard_pmic = {
213 .regulators = moboard_regulators,
214 .num_regulators = ARRAY_SIZE(moboard_regulators),
215 .flags = MC13783_USE_REGULATOR | MC13783_USE_RTC,
218 static struct spi_board_info moboard_spi_board_info[] __initdata = {
220 .modalias = "mc13783",
221 .irq = IOMUX_TO_IRQ(MX31_PIN_GPIO1_3),
222 .max_speed_hz = 300000,
225 .platform_data = &moboard_pmic,
229 .modalias = "spidev",
230 .max_speed_hz = 300000,
232 .chip_select = 1, /* according spi1_cs[] ! */
236 static int moboard_spi2_cs[] = {
240 static struct spi_imx_master moboard_spi2_master = {
241 .chipselect = moboard_spi2_cs,
242 .num_chipselect = ARRAY_SIZE(moboard_spi2_cs),
245 #define SDHC1_CD IOMUX_TO_GPIO(MX31_PIN_ATA_CS0)
246 #define SDHC1_WP IOMUX_TO_GPIO(MX31_PIN_ATA_CS1)
248 static int moboard_sdhc1_get_ro(struct device *dev)
250 return !gpio_get_value(SDHC1_WP);
253 static int moboard_sdhc1_init(struct device *dev, irq_handler_t detect_irq,
258 ret = gpio_request(SDHC1_CD, "sdhc-detect");
262 gpio_direction_input(SDHC1_CD);
264 ret = gpio_request(SDHC1_WP, "sdhc-wp");
267 gpio_direction_input(SDHC1_WP);
269 ret = request_irq(gpio_to_irq(SDHC1_CD), detect_irq,
270 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
271 "sdhc1-card-detect", data);
273 goto err_gpio_free_2;
285 static void moboard_sdhc1_exit(struct device *dev, void *data)
287 free_irq(gpio_to_irq(SDHC1_CD), data);
292 static struct imxmmc_platform_data sdhc1_pdata = {
293 .get_ro = moboard_sdhc1_get_ro,
294 .init = moboard_sdhc1_init,
295 .exit = moboard_sdhc1_exit,
299 * this pin is dedicated for all mx31moboard systems, so we do it here
301 #define USB_RESET_B IOMUX_TO_GPIO(MX31_PIN_GPIO1_0)
303 static void usb_xcvr_reset(void)
305 gpio_request(USB_RESET_B, "usb-reset");
306 gpio_direction_output(USB_RESET_B, 0);
308 gpio_set_value(USB_RESET_B, 1);
311 #define USB_PAD_CFG (PAD_CTL_DRV_MAX | PAD_CTL_SRE_FAST | PAD_CTL_HYS_CMOS | \
312 PAD_CTL_ODE_CMOS | PAD_CTL_100K_PU)
314 #define OTG_EN_B IOMUX_TO_GPIO(MX31_PIN_USB_OC)
316 static void moboard_usbotg_init(void)
318 mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA0, USB_PAD_CFG);
319 mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA1, USB_PAD_CFG);
320 mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA2, USB_PAD_CFG);
321 mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA3, USB_PAD_CFG);
322 mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA4, USB_PAD_CFG);
323 mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA5, USB_PAD_CFG);
324 mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA6, USB_PAD_CFG);
325 mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA7, USB_PAD_CFG);
326 mxc_iomux_set_pad(MX31_PIN_USBOTG_CLK, USB_PAD_CFG);
327 mxc_iomux_set_pad(MX31_PIN_USBOTG_DIR, USB_PAD_CFG);
328 mxc_iomux_set_pad(MX31_PIN_USBOTG_NXT, USB_PAD_CFG);
329 mxc_iomux_set_pad(MX31_PIN_USBOTG_STP, USB_PAD_CFG);
331 gpio_request(OTG_EN_B, "usb-udc-en");
332 gpio_direction_output(OTG_EN_B, 0);
335 static struct fsl_usb2_platform_data usb_pdata = {
336 .operating_mode = FSL_USB2_DR_DEVICE,
337 .phy_mode = FSL_USB2_PHY_ULPI,
340 static struct gpio_led mx31moboard_leds[] = {
342 .name = "coreboard-led-0:red:running",
343 .default_trigger = "heartbeat",
344 .gpio = IOMUX_TO_GPIO(MX31_PIN_SVEN0),
346 .name = "coreboard-led-1:red",
347 .gpio = IOMUX_TO_GPIO(MX31_PIN_STX0),
349 .name = "coreboard-led-2:red",
350 .gpio = IOMUX_TO_GPIO(MX31_PIN_SRX0),
352 .name = "coreboard-led-3:red",
353 .gpio = IOMUX_TO_GPIO(MX31_PIN_SIMPD0),
357 static struct gpio_led_platform_data mx31moboard_led_pdata = {
358 .num_leds = ARRAY_SIZE(mx31moboard_leds),
359 .leds = mx31moboard_leds,
362 static struct platform_device mx31moboard_leds_device = {
366 .platform_data = &mx31moboard_led_pdata,
370 #define SEL0 IOMUX_TO_GPIO(MX31_PIN_DTR_DCE1)
371 #define SEL1 IOMUX_TO_GPIO(MX31_PIN_DSR_DCE1)
372 #define SEL2 IOMUX_TO_GPIO(MX31_PIN_RI_DCE1)
373 #define SEL3 IOMUX_TO_GPIO(MX31_PIN_DCD_DCE1)
375 static void mx31moboard_init_sel_gpios(void)
377 if (!gpio_request(SEL0, "sel0")) {
378 gpio_direction_input(SEL0);
379 gpio_export(SEL0, true);
382 if (!gpio_request(SEL1, "sel1")) {
383 gpio_direction_input(SEL1);
384 gpio_export(SEL1, true);
387 if (!gpio_request(SEL2, "sel2")) {
388 gpio_direction_input(SEL2);
389 gpio_export(SEL2, true);
392 if (!gpio_request(SEL3, "sel3")) {
393 gpio_direction_input(SEL3);
394 gpio_export(SEL3, true);
398 static struct ipu_platform_data mx3_ipu_data = {
399 .irq_base = MXC_IPU_IRQ_START,
402 static struct platform_device *devices[] __initdata = {
404 &mx31moboard_leds_device,
407 static struct mx3_camera_pdata camera_pdata = {
408 .dma_dev = &mx3_ipu.dev,
409 .flags = MX3_CAMERA_DATAWIDTH_8 | MX3_CAMERA_DATAWIDTH_10,
413 #define CAMERA_BUF_SIZE (4*1024*1024)
415 static int __init mx31moboard_cam_alloc_dma(const size_t buf_size)
417 dma_addr_t dma_handle;
421 if (buf_size < 2 * 1024 * 1024)
424 buf = dma_alloc_coherent(NULL, buf_size, &dma_handle, GFP_KERNEL);
426 pr_err("%s: cannot allocate camera buffer-memory\n", __func__);
430 memset(buf, 0, buf_size);
432 dma = dma_declare_coherent_memory(&mx3_camera.dev,
433 dma_handle, dma_handle, buf_size,
434 DMA_MEMORY_MAP | DMA_MEMORY_EXCLUSIVE);
436 /* The way we call dma_declare_coherent_memory only a malloc can fail */
437 return dma & DMA_MEMORY_MAP ? 0 : -ENOMEM;
440 static int mx31moboard_baseboard;
441 core_param(mx31moboard_baseboard, mx31moboard_baseboard, int, 0444);
444 * Board specific initialization.
446 static void __init mxc_board_init(void)
448 mxc_iomux_setup_multiple_pins(moboard_pins, ARRAY_SIZE(moboard_pins),
451 platform_add_devices(devices, ARRAY_SIZE(devices));
453 mxc_register_device(&mxc_uart_device0, &uart0_pdata);
455 mxc_register_device(&mxc_uart_device4, &uart4_pdata);
457 mx31moboard_init_sel_gpios();
459 mxc_register_device(&mxc_i2c_device0, &moboard_i2c0_pdata);
460 mxc_register_device(&mxc_i2c_device1, &moboard_i2c1_pdata);
462 mxc_register_device(&mxc_spi_device1, &moboard_spi1_master);
463 mxc_register_device(&mxc_spi_device2, &moboard_spi2_master);
465 gpio_request(IOMUX_TO_GPIO(MX31_PIN_GPIO1_3), "pmic-irq");
466 gpio_direction_input(IOMUX_TO_GPIO(MX31_PIN_GPIO1_3));
467 spi_register_board_info(moboard_spi_board_info,
468 ARRAY_SIZE(moboard_spi_board_info));
470 mxc_register_device(&mxcsdhc_device0, &sdhc1_pdata);
472 mxc_register_device(&mx3_ipu, &mx3_ipu_data);
473 if (!mx31moboard_cam_alloc_dma(CAMERA_BUF_SIZE))
474 mxc_register_device(&mx3_camera, &camera_pdata);
478 moboard_usbotg_init();
479 mxc_register_device(&mxc_otg_udc_device, &usb_pdata);
481 switch (mx31moboard_baseboard) {
485 mx31moboard_devboard_init();
488 mx31moboard_marxbot_init();
491 printk(KERN_ERR "Illegal mx31moboard_baseboard type %d\n",
492 mx31moboard_baseboard);
496 static void __init mx31moboard_timer_init(void)
498 mx31_clocks_init(26000000);
501 struct sys_timer mx31moboard_timer = {
502 .init = mx31moboard_timer_init,
505 MACHINE_START(MX31MOBOARD, "EPFL Mobots mx31moboard")
506 /* Maintainer: Valentin Longchamp, EPFL Mobots group */
507 .phys_io = AIPS1_BASE_ADDR,
508 .io_pg_offst = ((AIPS1_BASE_ADDR_VIRT) >> 18) & 0xfffc,
509 .boot_params = PHYS_OFFSET + 0x100,
510 .map_io = mx31_map_io,
511 .init_irq = mx31_init_irq,
512 .init_machine = mxc_board_init,
513 .timer = &mx31moboard_timer,