mx31moboard: support for usbh1 and usbh2
[linux-2.6-block.git] / arch / arm / mach-mx3 / mx31moboard-devboard.c
CommitLineData
e00f0b4a
VL
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.
13 *
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
17 */
18
45b131a7 19#include <linux/gpio.h>
e00f0b4a 20#include <linux/init.h>
45b131a7 21#include <linux/interrupt.h>
e00f0b4a 22#include <linux/platform_device.h>
220bbcea 23#include <linux/types.h>
e00f0b4a 24
d67d1075
VL
25#include <linux/usb/otg.h>
26
e00f0b4a
VL
27#include <mach/common.h>
28#include <mach/imx-uart.h>
29#include <mach/iomux-mx3.h>
220bbcea 30#include <mach/hardware.h>
45b131a7 31#include <mach/mmc.h>
d67d1075
VL
32#include <mach/mxc_ehci.h>
33#include <mach/ulpi.h>
e00f0b4a
VL
34
35#include "devices.h"
36
220bbcea
VL
37static unsigned int devboard_pins[] = {
38 /* UART1 */
e00f0b4a
VL
39 MX31_PIN_CTS2__CTS2, MX31_PIN_RTS2__RTS2,
40 MX31_PIN_TXD2__TXD2, MX31_PIN_RXD2__RXD2,
56c7a45b
VL
41 /* SDHC2 */
42 MX31_PIN_PC_PWRON__SD2_DATA3, MX31_PIN_PC_VS1__SD2_DATA2,
43 MX31_PIN_PC_READY__SD2_DATA1, MX31_PIN_PC_WAIT_B__SD2_DATA0,
44 MX31_PIN_PC_CD2_B__SD2_CLK, MX31_PIN_PC_CD1_B__SD2_CMD,
45 MX31_PIN_ATA_DIOR__GPIO3_28, MX31_PIN_ATA_DIOW__GPIO3_29,
d67d1075
VL
46 /* USB H1 */
47 MX31_PIN_CSPI1_MISO__USBH1_RXDP, MX31_PIN_CSPI1_MOSI__USBH1_RXDM,
48 MX31_PIN_CSPI1_SS0__USBH1_TXDM, MX31_PIN_CSPI1_SS1__USBH1_TXDP,
49 MX31_PIN_CSPI1_SS2__USBH1_RCV, MX31_PIN_CSPI1_SCLK__USBH1_OEB,
50 MX31_PIN_CSPI1_SPI_RDY__USBH1_FS, MX31_PIN_SFS6__USBH1_SUSPEND,
51 MX31_PIN_NFRE_B__GPIO1_11, MX31_PIN_NFALE__GPIO1_12,
e00f0b4a
VL
52};
53
220bbcea
VL
54static struct imxuart_platform_data uart_pdata = {
55 .flags = IMXUART_HAVE_RTSCTS,
56};
57
45b131a7
VL
58#define SDHC2_CD IOMUX_TO_GPIO(MX31_PIN_ATA_DIOR)
59#define SDHC2_WP IOMUX_TO_GPIO(MX31_PIN_ATA_DIOW)
60
61static int devboard_sdhc2_get_ro(struct device *dev)
62{
563abb4b 63 return !gpio_get_value(SDHC2_WP);
45b131a7
VL
64}
65
66static int devboard_sdhc2_init(struct device *dev, irq_handler_t detect_irq,
67 void *data)
68{
4f163eb8
SH
69 int ret;
70
71 ret = gpio_request(SDHC2_CD, "sdhc-detect");
72 if (ret)
73 return ret;
74
75 gpio_direction_input(SDHC2_CD);
76
77 ret = gpio_request(SDHC2_WP, "sdhc-wp");
78 if (ret)
79 goto err_gpio_free;
80 gpio_direction_input(SDHC2_WP);
81
82 ret = request_irq(gpio_to_irq(SDHC2_CD), detect_irq,
45b131a7
VL
83 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
84 "sdhc2-card-detect", data);
4f163eb8
SH
85 if (ret)
86 goto err_gpio_free_2;
87
88 return 0;
89
90err_gpio_free_2:
91 gpio_free(SDHC2_WP);
92err_gpio_free:
93 gpio_free(SDHC2_CD);
94
95 return ret;
45b131a7
VL
96}
97
98static void devboard_sdhc2_exit(struct device *dev, void *data)
99{
100 free_irq(gpio_to_irq(SDHC2_CD), data);
4f163eb8
SH
101 gpio_free(SDHC2_WP);
102 gpio_free(SDHC2_CD);
45b131a7
VL
103}
104
105static struct imxmmc_platform_data sdhc2_pdata = {
106 .get_ro = devboard_sdhc2_get_ro,
107 .init = devboard_sdhc2_init,
108 .exit = devboard_sdhc2_exit,
109};
110
d67d1075
VL
111#define USB_PAD_CFG (PAD_CTL_DRV_MAX | PAD_CTL_SRE_FAST | PAD_CTL_HYS_CMOS | \
112 PAD_CTL_ODE_CMOS | PAD_CTL_100K_PU)
113
114static int devboard_usbh1_hw_init(struct platform_device *pdev)
115{
116 mxc_iomux_set_gpr(MUX_PGP_USB_SUSPEND, true);
117
118 mxc_iomux_set_pad(MX31_PIN_CSPI1_MISO, USB_PAD_CFG);
119 mxc_iomux_set_pad(MX31_PIN_CSPI1_MOSI, USB_PAD_CFG);
120 mxc_iomux_set_pad(MX31_PIN_CSPI1_SS0, USB_PAD_CFG);
121 mxc_iomux_set_pad(MX31_PIN_CSPI1_SS1, USB_PAD_CFG);
122 mxc_iomux_set_pad(MX31_PIN_CSPI1_SS2, USB_PAD_CFG);
123 mxc_iomux_set_pad(MX31_PIN_CSPI1_SCLK, USB_PAD_CFG);
124 mxc_iomux_set_pad(MX31_PIN_CSPI1_SPI_RDY, USB_PAD_CFG);
125 mxc_iomux_set_pad(MX31_PIN_SFS6, USB_PAD_CFG);
126
127 return 0;
128}
129
130#define USBH1_VBUSEN_B IOMUX_TO_GPIO(MX31_PIN_NFRE_B)
131#define USBH1_MODE IOMUX_TO_GPIO(MX31_PIN_NFALE)
132
133static int devboard_isp1105_init(struct otg_transceiver *otg)
134{
135 int ret = gpio_request(USBH1_MODE, "usbh1-mode");
136 if (ret)
137 return ret;
138 /* single ended */
139 gpio_direction_output(USBH1_MODE, 0);
140
141 ret = gpio_request(USBH1_VBUSEN_B, "usbh1-vbusen");
142 if (ret) {
143 gpio_free(USBH1_MODE);
144 return ret;
145 }
146 gpio_direction_output(USBH1_VBUSEN_B, 1);
147
148 return 0;
149}
150
151
152static int devboard_isp1105_set_vbus(struct otg_transceiver *otg, bool on)
153{
154 if (on)
155 gpio_set_value(USBH1_VBUSEN_B, 0);
156 else
157 gpio_set_value(USBH1_VBUSEN_B, 1);
158
159 return 0;
160}
161
162static struct mxc_usbh_platform_data usbh1_pdata = {
163 .init = devboard_usbh1_hw_init,
164 .portsc = MXC_EHCI_MODE_UTMI | MXC_EHCI_SERIAL,
165 .flags = MXC_EHCI_POWER_PINS_ENABLED | MXC_EHCI_INTERFACE_SINGLE_UNI,
166};
167
168static int __init devboard_usbh1_init(void)
169{
170 struct otg_transceiver *otg;
171
172 otg = kzalloc(sizeof(*otg), GFP_KERNEL);
173 if (!otg)
174 return -ENOMEM;
175
176 otg->label = "ISP1105";
177 otg->init = devboard_isp1105_init;
178 otg->set_vbus = devboard_isp1105_set_vbus;
179
180 usbh1_pdata.otg = otg;
181
182 return mxc_register_device(&mx31_usbh1, &usbh1_pdata);
183}
184
e00f0b4a
VL
185/*
186 * system init for baseboard usage. Will be called by mx31moboard init.
187 */
188void __init mx31moboard_devboard_init(void)
189{
190 printk(KERN_INFO "Initializing mx31devboard peripherals\n");
220bbcea
VL
191
192 mxc_iomux_setup_multiple_pins(devboard_pins, ARRAY_SIZE(devboard_pins),
193 "devboard");
194
e00f0b4a 195 mxc_register_device(&mxc_uart_device1, &uart_pdata);
45b131a7
VL
196
197 mxc_register_device(&mxcsdhc_device1, &sdhc2_pdata);
d67d1075
VL
198
199 devboard_usbh1_init();
e00f0b4a 200}