Valentin Longchamp | e335c75 | 2010-02-09 18:13:36 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 Valentin Longchamp, EPFL Mobots group |
| 3 | * |
| 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. |
| 8 | * |
| 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. |
Valentin Longchamp | e335c75 | 2010-02-09 18:13:36 +0100 | [diff] [blame] | 13 | */ |
| 14 | |
| 15 | #include <linux/delay.h> |
| 16 | #include <linux/gpio.h> |
| 17 | #include <linux/init.h> |
| 18 | #include <linux/interrupt.h> |
| 19 | #include <linux/i2c.h> |
| 20 | #include <linux/platform_device.h> |
| 21 | #include <linux/types.h> |
| 22 | |
Philippe Rétornaz | 3a47b1a | 2010-05-11 16:57:51 +0200 | [diff] [blame] | 23 | #include <linux/usb/otg.h> |
| 24 | #include <linux/usb/ulpi.h> |
| 25 | |
Shawn Guo | 3ed0bcb | 2012-09-13 09:37:49 +0800 | [diff] [blame] | 26 | #include "board-mx31moboard.h" |
Shawn Guo | e337247 | 2012-09-13 21:01:00 +0800 | [diff] [blame] | 27 | #include "common.h" |
Uwe Kleine-König | 16cf5c4 | 2010-06-23 11:46:16 +0200 | [diff] [blame] | 28 | #include "devices-imx31.h" |
Shawn Guo | 641dfe8 | 2014-05-19 20:41:52 +0800 | [diff] [blame] | 29 | #include "ehci.h" |
Shawn Guo | 50f2de6 | 2012-09-14 14:14:45 +0800 | [diff] [blame] | 30 | #include "hardware.h" |
Shawn Guo | 267dd34 | 2012-09-13 13:26:00 +0800 | [diff] [blame] | 31 | #include "iomux-mx3.h" |
Shawn Guo | 39ef634 | 2012-09-13 21:46:09 +0800 | [diff] [blame] | 32 | #include "ulpi.h" |
Valentin Longchamp | e335c75 | 2010-02-09 18:13:36 +0100 | [diff] [blame] | 33 | |
| 34 | static unsigned int smartbot_pins[] = { |
| 35 | /* UART1 */ |
| 36 | MX31_PIN_CTS2__CTS2, MX31_PIN_RTS2__RTS2, |
| 37 | MX31_PIN_TXD2__TXD2, MX31_PIN_RXD2__RXD2, |
Valentin Longchamp | e335c75 | 2010-02-09 18:13:36 +0100 | [diff] [blame] | 38 | /* ENABLES */ |
| 39 | MX31_PIN_DTR_DCE1__GPIO2_8, MX31_PIN_DSR_DCE1__GPIO2_9, |
| 40 | MX31_PIN_RI_DCE1__GPIO2_10, MX31_PIN_DCD_DCE1__GPIO2_11, |
| 41 | }; |
| 42 | |
Uwe Kleine-König | 16cf5c4 | 2010-06-23 11:46:16 +0200 | [diff] [blame] | 43 | static const struct imxuart_platform_data uart_pdata __initconst = { |
Valentin Longchamp | e335c75 | 2010-02-09 18:13:36 +0100 | [diff] [blame] | 44 | .flags = IMXUART_HAVE_RTSCTS, |
| 45 | }; |
| 46 | |
Uwe Kleine-König | 9e1dde3 | 2010-11-12 16:40:06 +0100 | [diff] [blame] | 47 | static const struct fsl_usb2_platform_data usb_pdata __initconst = { |
Philippe Rétornaz | 66c202a | 2010-05-11 16:57:50 +0200 | [diff] [blame] | 48 | .operating_mode = FSL_USB2_DR_DEVICE, |
| 49 | .phy_mode = FSL_USB2_PHY_ULPI, |
| 50 | }; |
| 51 | |
Philippe Rétornaz | 3a47b1a | 2010-05-11 16:57:51 +0200 | [diff] [blame] | 52 | #if defined(CONFIG_USB_ULPI) |
| 53 | |
Sascha Hauer | 4bd597b | 2011-01-03 11:30:28 +0100 | [diff] [blame] | 54 | static int smartbot_otg_init(struct platform_device *pdev) |
| 55 | { |
| 56 | return mx31_initialize_usb_hw(pdev->id, MXC_EHCI_POWER_PINS_ENABLED); |
| 57 | } |
| 58 | |
Uwe Kleine-König | 2d58de2 | 2010-11-15 11:57:49 +0100 | [diff] [blame] | 59 | static struct mxc_usbh_platform_data otg_host_pdata __initdata = { |
Sascha Hauer | 4bd597b | 2011-01-03 11:30:28 +0100 | [diff] [blame] | 60 | .init = smartbot_otg_init, |
Philippe Rétornaz | 3a47b1a | 2010-05-11 16:57:51 +0200 | [diff] [blame] | 61 | .portsc = MXC_EHCI_MODE_ULPI | MXC_EHCI_UTMI_8BIT, |
Philippe Rétornaz | 3a47b1a | 2010-05-11 16:57:51 +0200 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | static int __init smartbot_otg_host_init(void) |
| 65 | { |
Uwe Kleine-König | 2d58de2 | 2010-11-15 11:57:49 +0100 | [diff] [blame] | 66 | struct platform_device *pdev; |
| 67 | |
Sascha Hauer | 48f6b09 | 2011-03-02 09:27:42 +0100 | [diff] [blame] | 68 | otg_host_pdata.otg = imx_otg_ulpi_create(ULPI_OTG_DRVVBUS | |
| 69 | ULPI_OTG_DRVVBUS_EXT); |
| 70 | if (!otg_host_pdata.otg) |
| 71 | return -ENODEV; |
Philippe Rétornaz | 3a47b1a | 2010-05-11 16:57:51 +0200 | [diff] [blame] | 72 | |
Uwe Kleine-König | 2d58de2 | 2010-11-15 11:57:49 +0100 | [diff] [blame] | 73 | pdev = imx31_add_mxc_ehci_otg(&otg_host_pdata); |
Uwe Kleine-König | 2d58de2 | 2010-11-15 11:57:49 +0100 | [diff] [blame] | 74 | |
Fabian Frederick | d3a2244 | 2014-07-04 21:03:10 +0200 | [diff] [blame] | 75 | return PTR_ERR_OR_ZERO(pdev); |
Philippe Rétornaz | 3a47b1a | 2010-05-11 16:57:51 +0200 | [diff] [blame] | 76 | } |
| 77 | #else |
| 78 | static inline int smartbot_otg_host_init(void) { return 0; } |
| 79 | #endif |
| 80 | |
Valentin Longchamp | e335c75 | 2010-02-09 18:13:36 +0100 | [diff] [blame] | 81 | #define POWER_EN IOMUX_TO_GPIO(MX31_PIN_DTR_DCE1) |
| 82 | #define DSPIC_RST_B IOMUX_TO_GPIO(MX31_PIN_DSR_DCE1) |
| 83 | #define TRSLAT_RST_B IOMUX_TO_GPIO(MX31_PIN_RI_DCE1) |
Valentin Longchamp | 7176441 | 2010-05-05 11:34:21 +0200 | [diff] [blame] | 84 | #define TRSLAT_SRC_CHOICE IOMUX_TO_GPIO(MX31_PIN_DCD_DCE1) |
Valentin Longchamp | e335c75 | 2010-02-09 18:13:36 +0100 | [diff] [blame] | 85 | |
| 86 | static void smartbot_resets_init(void) |
| 87 | { |
| 88 | if (!gpio_request(POWER_EN, "power-enable")) { |
| 89 | gpio_direction_output(POWER_EN, 0); |
| 90 | gpio_export(POWER_EN, false); |
| 91 | } |
| 92 | |
| 93 | if (!gpio_request(DSPIC_RST_B, "dspic-rst")) { |
| 94 | gpio_direction_output(DSPIC_RST_B, 0); |
| 95 | gpio_export(DSPIC_RST_B, false); |
| 96 | } |
| 97 | |
| 98 | if (!gpio_request(TRSLAT_RST_B, "translator-rst")) { |
| 99 | gpio_direction_output(TRSLAT_RST_B, 0); |
| 100 | gpio_export(TRSLAT_RST_B, false); |
| 101 | } |
| 102 | |
Valentin Longchamp | 7176441 | 2010-05-05 11:34:21 +0200 | [diff] [blame] | 103 | if (!gpio_request(TRSLAT_SRC_CHOICE, "translator-src-choice")) { |
| 104 | gpio_direction_output(TRSLAT_SRC_CHOICE, 0); |
| 105 | gpio_export(TRSLAT_SRC_CHOICE, false); |
Valentin Longchamp | e335c75 | 2010-02-09 18:13:36 +0100 | [diff] [blame] | 106 | } |
| 107 | } |
| 108 | /* |
| 109 | * system init for baseboard usage. Will be called by mx31moboard init. |
| 110 | */ |
Philippe Rétornaz | 3a47b1a | 2010-05-11 16:57:51 +0200 | [diff] [blame] | 111 | void __init mx31moboard_smartbot_init(int board) |
Valentin Longchamp | e335c75 | 2010-02-09 18:13:36 +0100 | [diff] [blame] | 112 | { |
| 113 | printk(KERN_INFO "Initializing mx31smartbot peripherals\n"); |
| 114 | |
| 115 | mxc_iomux_setup_multiple_pins(smartbot_pins, ARRAY_SIZE(smartbot_pins), |
| 116 | "smartbot"); |
| 117 | |
Uwe Kleine-König | 16cf5c4 | 2010-06-23 11:46:16 +0200 | [diff] [blame] | 118 | imx31_add_imx_uart1(&uart_pdata); |
Philippe Rétornaz | 3a47b1a | 2010-05-11 16:57:51 +0200 | [diff] [blame] | 119 | |
| 120 | switch (board) { |
| 121 | case MX31SMARTBOT: |
Uwe Kleine-König | 9e1dde3 | 2010-11-12 16:40:06 +0100 | [diff] [blame] | 122 | imx31_add_fsl_usb2_udc(&usb_pdata); |
Philippe Rétornaz | 3a47b1a | 2010-05-11 16:57:51 +0200 | [diff] [blame] | 123 | break; |
| 124 | case MX31EYEBOT: |
| 125 | smartbot_otg_host_init(); |
| 126 | break; |
| 127 | default: |
| 128 | printk(KERN_WARNING "Unknown board %d, USB OTG not initialized", |
| 129 | board); |
| 130 | } |
Philippe Rétornaz | 66c202a | 2010-05-11 16:57:50 +0200 | [diff] [blame] | 131 | |
Valentin Longchamp | e335c75 | 2010-02-09 18:13:36 +0100 | [diff] [blame] | 132 | smartbot_resets_init(); |
Valentin Longchamp | e335c75 | 2010-02-09 18:13:36 +0100 | [diff] [blame] | 133 | } |