2 * Copyright (C) 2010 Marek Vasut <marek.vasut@gmail.com>
4 * (C) Copyright 2009 Freescale Semiconductor, Inc.
6 * See file CREDITS for list of people who contributed to this
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28 #include <asm/arch/imx-regs.h>
29 #include <asm/arch/mx5x_pins.h>
30 #include <asm/arch/iomux.h>
32 #include <usb/ehci-fsl.h>
36 #include "../../../drivers/usb/host/ehci.h"
38 /* USB pin configuration */
39 #define USB_PAD_CONFIG (PAD_CTL_PKE_ENABLE | PAD_CTL_SRE_FAST | \
40 PAD_CTL_DRV_HIGH | PAD_CTL_100K_PU | \
41 PAD_CTL_HYS_ENABLE | PAD_CTL_PUE_PULL)
44 * Configure the USB H1 and USB H2 IOMUX
46 void setup_iomux_usb(void)
50 if (machine_is_efikasb())
54 mxc_request_iomux(MX51_PIN_EIM_D27, IOMUX_CONFIG_ALT1);
55 mxc_iomux_set_pad(MX51_PIN_EIM_D27, PAD_CTL_PKE_ENABLE |
56 PAD_CTL_SRE_FAST | PAD_CTL_DRV_HIGH);
59 mxc_request_iomux(MX51_PIN_GPIO1_5, IOMUX_CONFIG_ALT0);
60 mxc_iomux_set_pad(MX51_PIN_GPIO1_5, PAD_CTL_PKE_ENABLE |
61 PAD_CTL_SRE_FAST | PAD_CTL_DRV_HIGH);
63 /* WIFI EN (act low) */
64 mxc_request_iomux(MX51_PIN_EIM_A22, IOMUX_CONFIG_GPIO);
65 mxc_iomux_set_pad(MX51_PIN_EIM_A22, 0);
67 mxc_request_iomux(MX51_PIN_EIM_A16, IOMUX_CONFIG_GPIO);
68 mxc_iomux_set_pad(MX51_PIN_EIM_A16, 0);
70 mxc_request_iomux(MX51_PIN_EIM_A17, IOMUX_CONFIG_GPIO);
71 mxc_iomux_set_pad(MX51_PIN_EIM_A17, 0);
75 * Enable devices connected to USB BUSes
77 static void efika_usb_enable_devices(void)
79 /* Enable Bluetooth */
80 gpio_direction_output(IOMUX_TO_GPIO(MX51_PIN_EIM_A17), 0);
82 gpio_set_value(IOMUX_TO_GPIO(MX51_PIN_EIM_A17), 1);
85 gpio_direction_output(IOMUX_TO_GPIO(MX51_PIN_EIM_A22), 1);
88 /* Reset the WiFi chip */
89 gpio_direction_output(IOMUX_TO_GPIO(MX51_PIN_EIM_A16), 0);
91 gpio_set_value(IOMUX_TO_GPIO(MX51_PIN_EIM_A16), 1);
95 * Reset USB HUB (or HUBs on EfikaSB)
97 static void efika_usb_hub_reset(void)
100 gpio_direction_output(IOMUX_TO_GPIO(MX51_PIN_GPIO1_5), 1);
102 gpio_set_value(IOMUX_TO_GPIO(MX51_PIN_GPIO1_5), 0);
104 gpio_set_value(IOMUX_TO_GPIO(MX51_PIN_GPIO1_5), 1);
108 * Reset USB PHY (or PHYs on EfikaSB)
110 static void efika_usb_phy_reset(void)
112 /* SMSC 3317 PHY reset */
113 gpio_direction_output(IOMUX_TO_GPIO(MX51_PIN_EIM_D27), 0);
115 gpio_set_value(IOMUX_TO_GPIO(MX51_PIN_EIM_D27), 1);
118 static void efika_ehci_init(struct usb_ehci *ehci, uint32_t stp_gpio,
119 uint32_t alt0, uint32_t alt1)
122 struct ulpi_regs *ulpi = (struct ulpi_regs *)0;
123 struct ulpi_viewport ulpi_vp;
125 mxc_request_iomux(stp_gpio, alt0);
126 mxc_iomux_set_pad(stp_gpio, PAD_CTL_DRV_HIGH |
127 PAD_CTL_PKE_ENABLE | PAD_CTL_SRE_FAST);
128 gpio_direction_output(IOMUX_TO_GPIO(stp_gpio), 0);
130 gpio_set_value(IOMUX_TO_GPIO(stp_gpio), 1);
133 mxc_request_iomux(stp_gpio, alt1);
134 mxc_iomux_set_pad(stp_gpio, USB_PAD_CONFIG);
137 ulpi_vp.viewport_addr = (u32)&ehci->ulpi_viewpoint;
138 ulpi_vp.port_num = 0;
140 ret = ulpi_init(&ulpi_vp);
142 printf("Efika USB ULPI initialization failed\n");
147 ulpi_write(&ulpi_vp, &ulpi->otg_ctrl,
148 ULPI_OTG_DP_PULLDOWN | ULPI_OTG_DM_PULLDOWN |
149 ULPI_OTG_EXTVBUSIND);
150 ulpi_write(&ulpi_vp, &ulpi->function_ctrl,
151 ULPI_FC_FULL_SPEED | ULPI_FC_OPMODE_NORMAL |
153 ulpi_write(&ulpi_vp, &ulpi->iface_ctrl, 0);
156 ulpi_write(&ulpi_vp, &ulpi->otg_ctrl_set,
157 ULPI_OTG_DRVVBUS | ULPI_OTG_DRVVBUS_EXT);
162 * NOTE: This violates USB specification, but otherwise, USB on Efika
165 ulpi_write(&ulpi_vp, &ulpi->otg_ctrl_set, ULPI_OTG_CHRGVBUS);
168 int board_ehci_hcd_init(int port)
170 /* Init iMX51 EHCI */
171 efika_usb_phy_reset();
172 efika_usb_hub_reset();
173 efika_usb_enable_devices();
178 void ehci_powerup_fixup(uint32_t *status_reg, uint32_t *reg)
180 uint32_t port = OTG_BASE_ADDR + (0x200 * CONFIG_MXC_USB_PORT);
181 struct usb_ehci *ehci = (struct usb_ehci *)port;
182 struct ulpi_regs *ulpi = (struct ulpi_regs *)0;
183 struct ulpi_viewport ulpi_vp;
185 ulpi_vp.viewport_addr = (u32)&ehci->ulpi_viewpoint;
186 ulpi_vp.port_num = 0;
188 ulpi_write(&ulpi_vp, &ulpi->otg_ctrl_set, ULPI_OTG_CHRGVBUS);
192 /* terminate the reset */
193 *reg = ehci_readl(status_reg);
197 void board_ehci_hcd_postinit(struct usb_ehci *ehci, int port)
202 /* Adjust UTMI PHY frequency to 24MHz */
203 tmp = readl(OTG_BASE_ADDR + 0x80c);
204 tmp = (tmp & ~0x3) | 0x01;
205 writel(tmp, OTG_BASE_ADDR + 0x80c);
206 } else if (port == 1) {
207 efika_ehci_init(ehci, MX51_PIN_USBH1_STP,
208 IOMUX_CONFIG_ALT2, IOMUX_CONFIG_ALT0);
209 } else if ((port == 2) && machine_is_efikasb()) {
210 efika_ehci_init(ehci, MX51_PIN_EIM_A26,
211 IOMUX_CONFIG_ALT1, IOMUX_CONFIG_ALT2);